Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion docs/workflow-mdbase-type.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion docs/workflow-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 3 additions & 2 deletions src/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/resources/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}.",
Expand Down
2 changes: 1 addition & 1 deletion src/workflowFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? "$",
Expand Down
20 changes: 11 additions & 9 deletions src/workflowNoteCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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<string, unknown>;
// 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");
});
}
15 changes: 14 additions & 1 deletion tests/collection.test.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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<string, string> = { "_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);
});
});
Loading