From bbf695076b4c16b1f486c70b50983f0d419432a8 Mon Sep 17 00:00:00 2001 From: callumalpass Date: Tue, 17 Nov 2026 20:46:59 +1100 Subject: [PATCH] Keep workflow notes valid under the collection's type key Runtime standard pack 0.2.0's runtime_workflow type pinned `type` and rejected other top-level keys, so the `mdbase_type: runtime_workflow` notes written in TaskNotes v5 collections were invalid mdbase records. Pack 0.2.1 (contract 1.1.0) fixes that upstream. - Use @callumalpass/mdbase-runtime 0.2.1 and pass the record type when validating, instead of relying on a `type` field. - Recognise workflow notes for note cards by the collection's type keys. - Show the runtime-type hint when only the version 1 type is installed. - Document the type key and the 0.2.1 requirement. --- CHANGELOG.md | 4 +++- README.md | 2 +- docs/workflow-mdbase-type.md | 6 +++++- docs/workflow-schema.md | 2 +- main.ts | 3 +++ package-lock.json | 8 ++++---- package.json | 2 +- src/collection.ts | 5 +++-- src/i18n/resources/en.ts | 2 +- src/workflowFormat.ts | 2 +- src/workflowNoteCard.ts | 20 +++++++++++--------- tests/collection.test.ts | 15 ++++++++++++++- 12 files changed, 48 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59ec4c7..9b94581 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,12 +11,14 @@ - Migrate Bases expressions, templates and structured conditions through the reviewed backup/apply/rollback flow. Unsupported conversions disable the workflow with an explanation. Unmigrated v1 files keep the original evaluator; CEL notes open directly for YAML editing. - Store runtime run and action-attempt evidence in plugin configuration storage while retaining the history UI and read-only compatibility with old history. Interrupted work is not replayed. - Add the device-local “Run workflows on this device” setting, enabled by default on desktop and disabled on mobile. Manual runs remain available. Obsidian 1.8.7 is now required for its local-storage API. Turning it off persists across restarts. -- Use stable mdbase interop 0.1.0 and runtime 0.2.0 packages; remove the vendored prerelease archive. Connect to the published `mdbase-sync` plugin and validate API/profile versions. Settings and documentation use “Allow plugin integrations”. +- Use stable mdbase interop 0.1.0 and runtime 0.2.1 packages; remove the vendored prerelease archive. Connect to the published `mdbase-sync` plugin and validate API/profile versions. Settings and documentation use “Allow plugin integrations”. - Preserve TaskNotes v5 task IDs in event data; support stable-ID task reads/mutations and correct the scaffolded time-entry DTO. Metadata-change events use the `mdbase.record.modified` data shape. New/migrated workflows respect collection type keys and suggest the runtime standard pack when its type is missing. - Generate disabled CEL starter workflows and recognize runtime notes in the workflow Base/note cards. ### Fixed +- Workflow notes in collections that declare types with `mdbase_type` (TaskNotes v5) are valid mdbase records and show their workflow card. They need the mdbase runtime standard pack 0.2.1, whose `runtime_workflow` type no longer pins `type`; the runtime-type hint now also appears when only the older type is installed. + - Disabled workflows no longer execute or create skipped-run history on contract events. - Interop step idempotency derives from the run idempotency key, step ID and item index. diff --git a/README.md b/README.md index d080723..d25fd39 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ Automatic execution is controlled by **Run workflows on this device**, a device- Run idempotency reservations persist for seven days; cron/interval downtime coalesces into one firing. Concurrency supports skip, queue, replace, and allow. This client does not provide distributed leases, a transactional event journal, or interrupted-run replay; see the [schema and execution limits](docs/workflow-schema.md). -In an mdbase 0.3 collection, new/migrated notes use its configured explicit type key (including TaskNotes v5's `mdbase_type`). If the runtime type is missing, the plugin suggests installing the **mdbase runtime standard** pack. +In an mdbase 0.3 collection, new/migrated notes use its configured explicit type key (including TaskNotes v5's `mdbase_type`). If the runtime type is missing or older than pack 0.2.1, whose type first accepts keys other than `type`, the plugin suggests installing the **mdbase runtime standard** pack. ## Included Workflows diff --git a/docs/workflow-mdbase-type.md b/docs/workflow-mdbase-type.md index 471a989..aecb3d5 100644 --- a/docs/workflow-mdbase-type.md +++ b/docs/workflow-mdbase-type.md @@ -6,7 +6,11 @@ replacement. Collections that need to index these records should install the `mdbase-runtime` standard pack. The pack owns the type, its JSON Schema, and its contract identity. -The record discriminator is `type: runtime_workflow`. Event and action fields +The record declares `runtime_workflow` under the collection's first explicit +type key: `type: runtime_workflow` by default, `mdbase_type: runtime_workflow` +in a TaskNotes v5 collection. Use pack 0.2.1 or later (contract 1.1.0, type +version 2): the 0.2.0 type pinned `type` and rejected records that declare +their type under another key. Event and action fields are contract requirements with an ID and SemVer range. Runtime admission resolves each requirement to an exact contract digest and declared source or provider. diff --git a/docs/workflow-schema.md b/docs/workflow-schema.md index 6bae86b..67f6c6a 100644 --- a/docs/workflow-schema.md +++ b/docs/workflow-schema.md @@ -40,7 +40,7 @@ x-tasknotes: format_version: 2 ``` -Required fields are `type`, `id`, `version`, `name`, `enabled`, `triggers`, and `steps`. Trigger and step IDs must each be unique. Unknown fields require an `x-` prefix. In an mdbase 0.3 collection, new and migrated files use the first configured `settings.explicit_type_keys` key instead of `type` (for example `mdbase_type` in a new TaskNotes v5 collection). Omitted settings use `type`; an explicitly empty list requires collection configuration before writing workflows. A missing `runtime_workflow` type produces a hint to install the **mdbase runtime standard** pack; the plugin does not install it. +Required fields are the type declaration (`type: runtime_workflow` by default), `id`, `version`, `name`, `enabled`, `triggers`, and `steps`. Trigger and step IDs must each be unique. Unknown fields require an `x-` prefix. In an mdbase 0.3 collection, new and migrated files use the first configured `settings.explicit_type_keys` key instead of `type` (for example `mdbase_type` in a new TaskNotes v5 collection). Omitted settings use `type`; an explicitly empty list requires collection configuration before writing workflows. A missing `runtime_workflow` type, or the version 1 type from pack 0.2.0 (which pinned `type`), produces a hint to install the **mdbase runtime standard** pack 0.2.1 or later; the plugin does not install it. ## Expressions diff --git a/main.ts b/main.ts index 057c90c..4a76a3c 100644 --- a/main.ts +++ b/main.ts @@ -47,6 +47,8 @@ export default class TaskNotesWorkflowsPlugin extends Plugin { runOnThisDevice = true; private migrationNoticeShown = false; private runtimeTypeHintShown = false; + /** The collection's explicit type keys (mdbase.yaml), refreshed on every reload. */ + collectionTypeKeys: string[] = ["type", "types"]; private bridge!: TaskNotesBridge; private engine!: WorkflowEngine; private scheduler!: WorkflowScheduler; @@ -217,6 +219,7 @@ export default class TaskNotesWorkflowsPlugin extends Plugin { new Notice(this.t("notices.celMigration"), 12000); } const collection = await collectionSettings(this.app); + this.collectionTypeKeys = collection?.typeKeys ?? ["type", "types"]; if (!this.runtimeTypeHintShown && collection && !await hasRuntimeType(this.app, collection)) { this.runtimeTypeHintShown = true; this.app.saveLocalStorage("tasknotes-workflows:runtime-type-hint", true); diff --git a/package-lock.json b/package-lock.json index ab3b54b..b1409e3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "MIT", "dependencies": { "@callumalpass/mdbase-interop": "0.1.0", - "@callumalpass/mdbase-runtime": "0.2.0", + "@callumalpass/mdbase-runtime": "0.2.1", "@marcbachmann/cel-js": "8.0.0", "obsidian-bases-expression": "^0.3.0-rc.5", "obsidian-bases-expression-builder": "^0.2.0-rc.3", @@ -149,9 +149,9 @@ } }, "node_modules/@callumalpass/mdbase-runtime": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/@callumalpass/mdbase-runtime/-/mdbase-runtime-0.2.0.tgz", - "integrity": "sha512-H1PveinfgL6yX5ffjiO+kVee5jCT/3svfkezXw46VrpiJ2yMr0dIV8FwM1Q38dX0KMnY7CJ4rJzUIzle5HuY+A==", + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/@callumalpass/mdbase-runtime/-/mdbase-runtime-0.2.1.tgz", + "integrity": "sha512-wHFIXhE1QBfDmOU7tTBCD/zDG30Da8buey7RlpBQLaZbwomd5+cf4YoyqJINMDZFfXmkZGpygagN2Syxh0f4nA==", "license": "MIT", "dependencies": { "ajv": "^8.17.1", diff --git a/package.json b/package.json index c3798f0..c4a3f93 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "license": "MIT", "dependencies": { "@callumalpass/mdbase-interop": "0.1.0", - "@callumalpass/mdbase-runtime": "0.2.0", + "@callumalpass/mdbase-runtime": "0.2.1", "@marcbachmann/cel-js": "8.0.0", "obsidian-bases-expression": "^0.3.0-rc.5", "obsidian-bases-expression-builder": "^0.2.0-rc.3", diff --git a/src/collection.ts b/src/collection.ts index 8696970..68b9b96 100644 --- a/src/collection.ts +++ b/src/collection.ts @@ -34,8 +34,9 @@ export async function hasRuntimeType(app: App, config: CollectionSettings): Prom const text = await app.vault.adapter.read(file); const match = /^---\r?\n([\s\S]*?)\r?\n---/u.exec(text); if (file.endsWith(".md") && !match) continue; - const type = parse(match?.[1] ?? text) as { kind?: string; name?: string } | null; - if (type?.kind === "mdbase.type" && type.name === "runtime_workflow") return true; + const type = parse(match?.[1] ?? text) as { kind?: string; name?: string; version?: unknown } | null; + // Version 1 (runtime pack 0.2.0) pins `type` and rejects other type keys. + if (type?.kind === "mdbase.type" && type.name === "runtime_workflow" && Number(type.version) >= 2) return true; } for (const child of listing.folders) if (await visit(child)) return true; return false; diff --git a/src/i18n/resources/en.ts b/src/i18n/resources/en.ts index 370da47..6b2a6ea 100644 --- a/src/i18n/resources/en.ts +++ b/src/i18n/resources/en.ts @@ -51,7 +51,7 @@ export const en: TranslationTree = { }, notices: { celMigration: "Some workflows still use Bases expressions. Use ‘Review workflow migration’ to review and migrate them to CEL.", - runtimeTypeHint: "Install the ‘mdbase runtime standard’ pack from mdbase to add the runtime_workflow type.", + runtimeTypeHint: "Install or update the ‘mdbase runtime standard’ pack (0.2.1 or later) from mdbase to add the runtime_workflow type.", languageChanged: "Language changed to {language}.", workflowsReloaded: "Workflows reloaded.", defaultFilesCreated: "Created {count} default {fileLabel}.", diff --git a/src/workflowFormat.ts b/src/workflowFormat.ts index 188154c..baebf6d 100644 --- a/src/workflowFormat.ts +++ b/src/workflowFormat.ts @@ -28,7 +28,7 @@ export function detectWorkflowSourceFormat(data: unknown): WorkflowSourceFormat } export function validateRuntimeWorkflowRecord(record: unknown): WorkflowDiagnostic[] { - const validation = validateRuntimeRecord(record); + const validation = validateRuntimeRecord(record, RUNTIME_WORKFLOW_TYPE); return validation.diagnostics.map((diagnostic) => ({ severity: diagnostic.severity === "info" ? "warning" : diagnostic.severity, path: diagnostic.path ?? "$", diff --git a/src/workflowNoteCard.ts b/src/workflowNoteCard.ts index 32dd0d1..438fd88 100644 --- a/src/workflowNoteCard.ts +++ b/src/workflowNoteCard.ts @@ -20,7 +20,7 @@ export function registerWorkflowNoteCards(plugin: TaskNotesWorkflowsPlugin): voi }, 100); plugin.registerMarkdownPostProcessor((_el, ctx) => { - if (!isWorkflowFrontmatter(ctx.frontmatter) && !plugin.workflows.some((loaded) => loaded.file.path === ctx.sourcePath)) return; + if (!isWorkflowFrontmatter(ctx.frontmatter, plugin.collectionTypeKeys) && !plugin.workflows.some((loaded) => loaded.file.path === ctx.sourcePath)) return; scheduleReadingModeWorkflowCards(plugin, ctx.sourcePath); }, -10); @@ -169,7 +169,7 @@ async function loadWorkflow( if (cached) return cached; const metadata = plugin.app.metadataCache.getFileCache(file); - if (!isWorkflowFrontmatter(metadata?.frontmatter)) return null; + if (!isWorkflowFrontmatter(metadata?.frontmatter, plugin.collectionTypeKeys)) return null; return await plugin.repository.loadFile(file); } @@ -289,11 +289,13 @@ function debounce(callback: () => void, delayMs: number): () => void { }; } -function isWorkflowFrontmatter(frontmatter: unknown): boolean { - return ( - frontmatter !== null && - typeof frontmatter === "object" && - "type" in frontmatter && - [WORKFLOW_TYPE, "runtime_workflow", "tasknotes-workflow"].includes(String((frontmatter as { type?: unknown }).type)) - ); +function isWorkflowFrontmatter(frontmatter: unknown, typeKeys: readonly string[]): boolean { + if (frontmatter === null || typeof frontmatter !== "object") return false; + const record = frontmatter as Record; + // Earlier formats always used `type`; runtime workflows use the collection's type keys. + if ([WORKFLOW_TYPE, "runtime_workflow", "tasknotes-workflow"].includes(String(record.type))) return true; + return typeKeys.some((key) => { + const value = record[key]; + return value === "runtime_workflow" || Array.isArray(value) && value.includes("runtime_workflow"); + }); } diff --git a/tests/collection.test.ts b/tests/collection.test.ts index 164cdb9..b647c4e 100644 --- a/tests/collection.test.ts +++ b/tests/collection.test.ts @@ -1,6 +1,7 @@ import { describe, expect, it } from "vitest"; import { parse } from "yaml"; -import { collectionSettings, normalizeWorkflowType, runtimeFrontmatter } from "../src/collection"; +import { validateRuntimeRecord } from "@callumalpass/mdbase-runtime"; +import { collectionSettings, hasRuntimeType, normalizeWorkflowType, runtimeFrontmatter } from "../src/collection"; import { parseWorkflowDefinition } from "../src/workflowParser"; import { workflowToCelRecord } from "../src/migrateExpressions"; import { createWorkflowDefinition } from "../src/workflowScaffolding"; @@ -17,10 +18,22 @@ describe("mdbase 0.3 type keys", () => { if (key !== "type") expect(frontmatter.type).toBeUndefined(); const loaded = parseWorkflowDefinition(normalizeWorkflowType(frontmatter, await collectionSettings(vault)), ""); expect(loaded.runtime?.id).toBe("test"); expect(loaded.diagnostics).toEqual([]); + // The note as written is a valid record under mdbase.runtime.workflow 1.1.0. + const validation = validateRuntimeRecord(frontmatter, "runtime_workflow"); + expect(validation.diagnostics).toEqual([]); }); it("uses type by default and respects an empty explicit type key list", async () => { const record = workflowToCelRecord(createWorkflowDefinition({ id: "test", name: "Test" })); expect(parse(await runtimeFrontmatter(app(undefined), record)).type).toBe("runtime_workflow"); await expect(runtimeFrontmatter(app("settings:\n explicit_type_keys: []"), record)).rejects.toThrow(/explicit_type_keys is empty/); }); + it.each([[1, false], [2, true]])("treats runtime_workflow type version %i as installed: %s", async (version, installed) => { + const files: Record = { "_mdbase/types/workflow.md": `---\nkind: mdbase.type\nname: runtime_workflow\nversion: ${version}\n---\n` }; + const vault = { vault: { adapter: { + exists: async (path: string) => path === "_mdbase/types", + list: async () => ({ files: Object.keys(files), folders: [] }), + read: async (path: string) => files[path], + } } } as never; + expect(await hasRuntimeType(vault, { typeKeys: ["mdbase_type"], typesFolder: "_mdbase/types" })).toBe(installed); + }); });