omkit 0.4.7 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/CHANGELOG.md +153 -0
  2. package/README.md +170 -13
  3. package/dist/actions/browser.d.ts +1 -1
  4. package/dist/actions/browser.js +1 -1
  5. package/dist/actions/chrome-page.d.ts +46 -4
  6. package/dist/actions/chrome-page.js +81 -33
  7. package/dist/actions/drive-page.d.ts +50 -0
  8. package/dist/actions/drive-page.js +68 -0
  9. package/dist/actions/index.d.ts +7 -3
  10. package/dist/actions/index.js +3 -1
  11. package/dist/actions/port-free.d.ts +29 -0
  12. package/dist/actions/port-free.js +78 -0
  13. package/dist/actions/prompt.d.ts +32 -5
  14. package/dist/actions/prompt.js +92 -8
  15. package/dist/cli/commands/help.js +6 -0
  16. package/dist/cli/commands/init.js +1 -1
  17. package/dist/cli/commands/ls.d.ts +11 -4
  18. package/dist/cli/commands/ls.js +35 -15
  19. package/dist/cli/commands/mcp.d.ts +10 -0
  20. package/dist/cli/commands/mcp.js +13 -0
  21. package/dist/cli/commands/skill.d.ts +17 -0
  22. package/dist/cli/commands/skill.js +56 -0
  23. package/dist/cli/index.d.ts +8 -0
  24. package/dist/cli/index.js +71 -29
  25. package/dist/client/discover-child.d.ts +12 -0
  26. package/dist/client/discover-child.js +71 -0
  27. package/dist/client/discovery.d.ts +21 -1
  28. package/dist/client/discovery.js +139 -2
  29. package/dist/client/index.d.ts +2 -1
  30. package/dist/client/index.js +3 -1
  31. package/dist/client/outline.d.ts +35 -0
  32. package/dist/client/outline.js +100 -0
  33. package/dist/client/registry.d.ts +59 -0
  34. package/dist/client/runner.d.ts +12 -0
  35. package/dist/client/runner.js +16 -7
  36. package/dist/client/types.d.ts +9 -1
  37. package/dist/core/ActionRun.d.ts +5 -0
  38. package/dist/core/ActionRun.js +9 -0
  39. package/dist/core/ExecutionTree.d.ts +40 -2
  40. package/dist/core/ExecutionTree.js +66 -2
  41. package/dist/core/action.d.ts +2 -1
  42. package/dist/core/action.js +93 -9
  43. package/dist/core/args.d.ts +50 -0
  44. package/dist/core/args.js +166 -0
  45. package/dist/core/discovery-mode.d.ts +37 -0
  46. package/dist/core/discovery-mode.js +54 -0
  47. package/dist/core/interaction.d.ts +3 -1
  48. package/dist/core/om.d.ts +11 -9
  49. package/dist/core/om.js +182 -13
  50. package/dist/core/schema-hint.d.ts +20 -0
  51. package/dist/core/schema-hint.js +73 -0
  52. package/dist/core/schema-json.d.ts +12 -0
  53. package/dist/core/schema-json.js +12 -0
  54. package/dist/core/types.d.ts +113 -1
  55. package/dist/foundation/LogEntry.d.ts +1 -1
  56. package/dist/foundation/canonicalPath.d.ts +26 -0
  57. package/dist/foundation/canonicalPath.js +34 -0
  58. package/dist/index.d.ts +2 -2
  59. package/dist/index.js +1 -1
  60. package/dist/mcp/action-host.d.ts +1 -0
  61. package/dist/mcp/action-host.js +65 -0
  62. package/dist/mcp/action-identity.d.ts +23 -0
  63. package/dist/mcp/action-identity.js +35 -0
  64. package/dist/mcp/progress.d.ts +61 -0
  65. package/dist/mcp/progress.js +92 -0
  66. package/dist/mcp/resources.d.ts +55 -0
  67. package/dist/mcp/resources.js +208 -0
  68. package/dist/mcp/runs.d.ts +37 -0
  69. package/dist/mcp/runs.js +60 -0
  70. package/dist/mcp/server.d.ts +19 -0
  71. package/dist/mcp/server.js +38 -0
  72. package/dist/mcp/tail.d.ts +37 -0
  73. package/dist/mcp/tail.js +64 -0
  74. package/dist/mcp/tools.d.ts +54 -0
  75. package/dist/mcp/tools.js +374 -0
  76. package/dist/mcp/validate.d.ts +14 -0
  77. package/dist/mcp/validate.js +54 -0
  78. package/dist/mcp/verdict.d.ts +31 -0
  79. package/dist/mcp/verdict.js +47 -0
  80. package/dist/output/artifact/ArtifactStore.d.ts +24 -0
  81. package/dist/output/artifact/ArtifactStore.js +49 -0
  82. package/dist/output/folder/RunFolder.d.ts +23 -1
  83. package/dist/output/folder/RunFolder.js +55 -11
  84. package/dist/output/writers/views.d.ts +10 -0
  85. package/dist/skill/file.d.ts +26 -0
  86. package/dist/skill/file.js +58 -0
  87. package/dist/skill/index.d.ts +11 -0
  88. package/dist/skill/index.js +9 -0
  89. package/dist/skill/model.d.ts +55 -0
  90. package/dist/skill/model.js +116 -0
  91. package/dist/skill/render.d.ts +18 -0
  92. package/dist/skill/render.js +133 -0
  93. package/package.json +5 -2
@@ -1,36 +1,120 @@
1
1
  import { ExecutionTree } from "./ExecutionTree.js";
2
2
  import { callerSite } from "../foundation/callsite.js";
3
+ import { describeSchema } from "./discovery-mode.js";
3
4
  /**
4
- * The builder returned by `action(name)`: declare events (`.emits<…>()`) and/or an
5
- * imperative handle (`.ref<…>()`), then bind the impl with `.run(…)`. `.run` returns a
6
- * callable {@link Action} — **invoking it launches** the action under the ambient current
7
- * node and returns the live {@link Activity}, on which `withCache`/`tag`/… chain.
5
+ * The builder returned by `action(name)`: declare metadata (`.describe(…)`), events
6
+ * (`.emits<…>()`), an imperative handle (`.ref<…>()`), and/or pin the args type
7
+ * (`.args(schema)`), then bind the impl with `.run(…)`. `.run` returns a callable
8
+ * {@link Action} — **invoking it launches** the action under the ambient current node
9
+ * and returns the live {@link Activity}, on which `withCache`/`tag`/… chain.
8
10
  */
9
11
  class Builder {
10
12
  name;
11
- constructor(name) {
13
+ description;
14
+ exposure;
15
+ constructor(name,
16
+ /** Carried across `.emits()`/`.ref()`, which otherwise rebuild the builder. */
17
+ description = undefined,
18
+ /** Carried the same way, for the same reason. */
19
+ exposure = undefined) {
12
20
  this.name = name;
21
+ this.description = description;
22
+ this.exposure = exposure;
23
+ }
24
+ describe(description) {
25
+ this.description = description;
26
+ return this;
27
+ }
28
+ mcp(exposure = {}) {
29
+ // The default is filled here, not at the reader, so every consumer sees one shape.
30
+ this.exposure = { mode: exposure.mode ?? "settling" };
31
+ return this;
13
32
  }
14
33
  emits() {
15
- return new Builder(this.name);
34
+ return new Builder(this.name, this.description, this.exposure);
16
35
  }
17
36
  ref() {
18
- return new Builder(this.name);
37
+ return new Builder(this.name, this.description, this.exposure);
38
+ }
39
+ args(schema) {
40
+ return new ArgsBuilder(this.name, schema, this.description, this.exposure);
19
41
  }
20
42
  run(body) {
21
43
  const name = this.name;
44
+ // Carried onto the definition for `omkit ls` and the MCP server; not read by the runtime.
45
+ const description = this.description;
46
+ const mcp = this.exposure;
22
47
  const definedAt = callerSite(); // the `.run(...)` call site — where this action lives
48
+ // No `.args()` on this path, so there is nothing to describe.
49
+ const describeArgs = () => describeSchema(undefined);
50
+ const exec = body;
51
+ const create = (...args) => {
52
+ const spec = { name, args, tags: [], body: exec, definedAt };
53
+ return ExecutionTree.require().launch(spec);
54
+ };
55
+ return Object.assign(create, {
56
+ actionName: name,
57
+ definedAt,
58
+ description,
59
+ mcp,
60
+ describeArgs,
61
+ });
62
+ }
63
+ }
64
+ /**
65
+ * The builder after `.args(schema)`. The schema pins `.run`'s parameter type; it is not
66
+ * validated here — an action invoked from an om body is passed its args directly in code.
67
+ * (Spec B's MCP server validates before it ever reaches this point.)
68
+ */
69
+ class ArgsBuilder {
70
+ name;
71
+ schema;
72
+ description;
73
+ exposure;
74
+ constructor(name,
75
+ /** Type-level only: `S` pins `.run`'s parameter. Nothing reads the value at runtime. */
76
+ schema, description, exposure) {
77
+ this.name = name;
78
+ this.schema = schema;
79
+ this.description = description;
80
+ this.exposure = exposure;
81
+ }
82
+ describe(description) {
83
+ this.description = description;
84
+ return this;
85
+ }
86
+ mcp(exposure = {}) {
87
+ this.exposure = { mode: exposure.mode ?? "settling" };
88
+ return this;
89
+ }
90
+ run(body) {
91
+ const name = this.name;
92
+ // Carried onto the definition for `omkit ls` and the MCP server; not read by the runtime.
93
+ const description = this.description;
94
+ const mcp = this.exposure;
95
+ const definedAt = callerSite();
96
+ // The schema is captured so the conversion happens in *this* copy of omkit — the one
97
+ // that built it — rather than in whichever copy the discovery child is running.
98
+ const schema = this.schema;
99
+ const describeArgs = () => describeSchema(schema);
23
100
  const exec = body;
24
101
  const create = (...args) => {
25
102
  const spec = { name, args, tags: [], body: exec, definedAt };
26
103
  return ExecutionTree.require().launch(spec);
27
104
  };
28
- return Object.assign(create, { actionName: name, definedAt });
105
+ return Object.assign(create, {
106
+ actionName: name,
107
+ definedAt,
108
+ description,
109
+ mcp,
110
+ describeArgs,
111
+ });
29
112
  }
30
113
  }
31
114
  /**
32
115
  * Define an action. Provide the impl via `.run(…)`, optionally after declaring
33
- * events (`.emits<…>()`) and/or an imperative handle (`.ref<…>()`). Call the result
116
+ * metadata (`.describe(…)`), events (`.emits<…>()`), an imperative handle
117
+ * (`.ref<…>()`), and/or pinning the args type (`.args(schema)`). Call the result
34
118
  * to launch it.
35
119
  */
36
120
  export function action(name) {
@@ -0,0 +1,50 @@
1
+ import type { z } from "zod";
2
+ import { type JsonSchema } from "./schema-json.ts";
3
+ /** Thrown when args cannot be resolved and nobody can be asked. */
4
+ export declare class MissingArgsError extends Error {
5
+ readonly fields: string[];
6
+ /**
7
+ * @param fields Top-level field names that blocked resolution.
8
+ * @param detail Why, when at least one of them *was* supplied — a value that is present
9
+ * but wrong is not missing, and must not be reported as though it were absent.
10
+ */
11
+ constructor(fields: string[], detail?: string);
12
+ }
13
+ /** What the caller must render to get one value from the user. */
14
+ export interface AskSpec {
15
+ /** Dotted path of the field, e.g. `rows` or `config`. */
16
+ readonly path: string;
17
+ readonly kind: "scalar" | "json";
18
+ /** One-line type sketch for the prompt, or `undefined` when the shape cannot be sketched. */
19
+ readonly hint: string | undefined;
20
+ /** The field's JSON Schema, for printing when there is no hint. */
21
+ readonly jsonSchema: JsonSchema;
22
+ }
23
+ export interface ResolveOptions {
24
+ /** Values already supplied (from `OMKIT_ARGS`). */
25
+ readonly supplied: unknown;
26
+ /** False when there is no supervisor and stdin is not a TTY. */
27
+ readonly interactive: boolean;
28
+ readonly ask: (spec: AskSpec) => Promise<string>;
29
+ }
30
+ /**
31
+ * Fill a schema's shape from supplied values, then defaults, then prompting — and fail if
32
+ * that is not enough. Defaults need no work of their own: `safeParse` applies them, so a
33
+ * defaulted field is never blocking and is never asked about.
34
+ *
35
+ * Interactivity is checked **before any prompting**: if nobody can be asked, every blocking
36
+ * field is collected into a single error rather than asking for one and then discovering
37
+ * the second is unanswerable.
38
+ */
39
+ export declare function resolveArgs(schema: z.ZodType, opts: ResolveOptions): Promise<unknown>;
40
+ /**
41
+ * True once a JSON-kind answer is finished. A `{`/`[` opener is a pasted blob and is done
42
+ * when it parses; anything else is a path to a JSON file, and one line is the whole answer.
43
+ *
44
+ * Exported because the prompt that *collects* the answer has to stop on exactly the inputs
45
+ * {@link coerce} knows how to read — `om.ts` passes this as the multiline prompt's `until`.
46
+ * Let the two rules drift apart and the documented file-path answer becomes untypable: a
47
+ * bare path is not JSON, so a JSON-only terminator keeps reading, and a real terminal never
48
+ * reaches the EOF that would otherwise end it.
49
+ */
50
+ export declare function jsonAnswerComplete(text: string): boolean;
@@ -0,0 +1,166 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { toJsonSchema } from "./schema-json.js";
3
+ import { shapeHint } from "./schema-hint.js";
4
+ /** Thrown when args cannot be resolved and nobody can be asked. */
5
+ export class MissingArgsError extends Error {
6
+ fields;
7
+ /**
8
+ * @param fields Top-level field names that blocked resolution.
9
+ * @param detail Why, when at least one of them *was* supplied — a value that is present
10
+ * but wrong is not missing, and must not be reported as though it were absent.
11
+ */
12
+ constructor(fields, detail) {
13
+ super(`could not resolve arg${fields.length === 1 ? "" : "s"}: ${fields.join(", ")} — ` +
14
+ `pass them via OMKIT_ARGS, or run interactively` +
15
+ (detail ? ` (${detail})` : ""));
16
+ this.fields = fields;
17
+ this.name = "MissingArgsError";
18
+ }
19
+ }
20
+ /** How many rounds of asking before resolution gives up. */
21
+ const MAX_ATTEMPTS = 3;
22
+ /**
23
+ * Fill a schema's shape from supplied values, then defaults, then prompting — and fail if
24
+ * that is not enough. Defaults need no work of their own: `safeParse` applies them, so a
25
+ * defaulted field is never blocking and is never asked about.
26
+ *
27
+ * Interactivity is checked **before any prompting**: if nobody can be asked, every blocking
28
+ * field is collected into a single error rather than asking for one and then discovering
29
+ * the second is unanswerable.
30
+ */
31
+ export async function resolveArgs(schema, opts) {
32
+ // Converted lazily, and only once something actually has to be asked. `toJSONSchema`
33
+ // throws for types it cannot represent (`z.date()`, and anything built on it), and only
34
+ // the prompt needs the conversion — a run whose args all arrived supplied or defaulted
35
+ // must not be failed by work it never required.
36
+ let converted;
37
+ const root = () => (converted ??= toJsonSchema(schema));
38
+ let current = asRecord(opts.supplied);
39
+ for (let attempt = 0;; attempt++) {
40
+ const parsed = schema.safeParse(current);
41
+ if (parsed.success)
42
+ return parsed.data;
43
+ const blocking = blockingFields(parsed.error);
44
+ // Nothing nameable to ask for — the schema rejected the object as a whole (a top-level
45
+ // refinement, or a schema that isn't an object at all). No question would make progress,
46
+ // so fail now with the real reason instead of looping silently to the attempt cap.
47
+ if (blocking.length === 0)
48
+ throw new Error(`could not resolve args: ${message(parsed.error)}`);
49
+ if (!opts.interactive) {
50
+ const anySupplied = blocking.some((field) => current[field] !== undefined);
51
+ throw new MissingArgsError(blocking, anySupplied ? message(parsed.error) : undefined);
52
+ }
53
+ if (attempt >= MAX_ATTEMPTS) {
54
+ throw new Error(`could not resolve args after ${MAX_ATTEMPTS} attempts: ${message(parsed.error)}`);
55
+ }
56
+ for (const field of blocking) {
57
+ const fieldSchema = propertySchema(root(), field);
58
+ const kind = isComplex(fieldSchema) ? "json" : "scalar";
59
+ const answer = await opts.ask({
60
+ path: field,
61
+ kind,
62
+ hint: shapeHint(fieldSchema),
63
+ jsonSchema: fieldSchema,
64
+ });
65
+ // An empty answer is *no answer*, not a value. The prompt battery resolves an empty
66
+ // line (and a timeout) to its default (""), and `Number("")` is 0 — so coercing here
67
+ // would silently turn a bare Enter on a required number into a real zero. Leave the
68
+ // field as it was and let the loop re-ask.
69
+ if (answer.trim() === "")
70
+ continue;
71
+ current = { ...current, [field]: coerce(answer, fieldSchema, kind) };
72
+ }
73
+ }
74
+ }
75
+ function asRecord(value) {
76
+ return typeof value === "object" && value !== null ? { ...value } : {};
77
+ }
78
+ /**
79
+ * The top-level field names the error blames, first-seen order, deduplicated. Both an
80
+ * absent field and a present-but-wrong one block resolution and are asked about the same
81
+ * way, so they are one list — whether a field was supplied is read off `current`, which
82
+ * is the direct observation, rather than inferred from zod's issue shape.
83
+ */
84
+ function blockingFields(error) {
85
+ const names = error.issues.map((i) => String(i.path[0] ?? "")).filter((n) => n !== "");
86
+ return [...new Set(names)];
87
+ }
88
+ function message(error) {
89
+ return error.issues.map((i) => `${i.path.join(".") || "(root)"} — ${i.message}`).join("; ");
90
+ }
91
+ function propertySchema(root, field) {
92
+ const properties = root.properties;
93
+ if (typeof properties === "object" && properties !== null) {
94
+ const found = properties[field];
95
+ if (typeof found === "object" && found !== null)
96
+ return found;
97
+ }
98
+ return {};
99
+ }
100
+ function isComplex(schema) {
101
+ return schema.type === "object" || schema.type === "array";
102
+ }
103
+ /**
104
+ * True once a JSON-kind answer is finished. A `{`/`[` opener is a pasted blob and is done
105
+ * when it parses; anything else is a path to a JSON file, and one line is the whole answer.
106
+ *
107
+ * Exported because the prompt that *collects* the answer has to stop on exactly the inputs
108
+ * {@link coerce} knows how to read — `om.ts` passes this as the multiline prompt's `until`.
109
+ * Let the two rules drift apart and the documented file-path answer becomes untypable: a
110
+ * bare path is not JSON, so a JSON-only terminator keeps reading, and a real terminal never
111
+ * reaches the EOF that would otherwise end it.
112
+ */
113
+ export function jsonAnswerComplete(text) {
114
+ const trimmed = text.trim();
115
+ if (trimmed === "")
116
+ return false; // a bare Enter is not an answer — keep reading
117
+ return isJsonBlob(trimmed) ? parsesAsJson(trimmed) : true;
118
+ }
119
+ /** Whether an answer is a pasted JSON blob rather than a path to one. */
120
+ function isJsonBlob(text) {
121
+ return text.startsWith("{") || text.startsWith("[");
122
+ }
123
+ function parsesAsJson(text) {
124
+ try {
125
+ JSON.parse(text);
126
+ return true;
127
+ }
128
+ catch {
129
+ return false;
130
+ }
131
+ }
132
+ /**
133
+ * Turn a prompt answer into a value the schema can accept. Scalars coerce from their
134
+ * string form; complex fields parse as JSON, or are read from a file path when the answer
135
+ * does not start with `{` or `[` — pointing at a file beats pasting a large config.
136
+ */
137
+ function coerce(answer, schema, kind) {
138
+ const text = answer.trim();
139
+ if (kind === "json") {
140
+ try {
141
+ return JSON.parse(isJsonBlob(text) ? text : readFileArg(text));
142
+ }
143
+ catch {
144
+ // Unparseable JSON *or* an unreadable path: hand the raw text back so the schema
145
+ // rejects it and the loop re-asks, naming the field. A mistyped filename must not
146
+ // escape as an ENOENT and take the whole run down.
147
+ return text;
148
+ }
149
+ }
150
+ if (schema.type === "number" || schema.type === "integer") {
151
+ const n = Number(text);
152
+ return Number.isNaN(n) ? text : n;
153
+ }
154
+ if (schema.type === "boolean") {
155
+ if (/^(true|yes|y|1)$/i.test(text))
156
+ return true;
157
+ if (/^(false|no|n|0)$/i.test(text))
158
+ return false;
159
+ return text;
160
+ }
161
+ return text;
162
+ }
163
+ /** Read a JSON file named by an answer; a leading `@` is optional sugar. */
164
+ function readFileArg(pathish) {
165
+ return readFileSync(pathish.replace(/^@/, ""), "utf8");
166
+ }
@@ -0,0 +1,37 @@
1
+ import type { DescribedArgs, OmDescription, ResolvedMcpExposure } from "./types.ts";
2
+ /**
3
+ * What an om reports in discovery mode, posted the moment `.run(...)` is reached.
4
+ *
5
+ * Sent over the fork's IPC channel rather than collected in a module variable: a user's
6
+ * file resolves `"omkit"` to the installed package while the discovery child runs omkit's
7
+ * own module graph, so the two can hold different copies of omkit — and a shared variable
8
+ * would be written in one and read in the other, coming back empty with no error and no
9
+ * clue why. `process.send` is copy-independent.
10
+ */
11
+ export interface OmRegistrationMessage {
12
+ readonly kind: "om-registration";
13
+ readonly name: string;
14
+ /** The defining file — the same input the run's identity hashes. No `:line`. */
15
+ readonly file: string | undefined;
16
+ readonly description: OmDescription | undefined;
17
+ readonly mcp: ResolvedMcpExposure | undefined;
18
+ /** The declared args as JSON Schema; undefined when the om declares none. */
19
+ readonly inputSchema: DescribedArgs["inputSchema"];
20
+ /** Set when `.args(schema)` would not convert — the entry lists as unavailable. */
21
+ readonly schemaError: DescribedArgs["schemaError"];
22
+ }
23
+ export declare function isDiscovering(): boolean;
24
+ /** Test seam: enter or leave discovery mode without forking a child. */
25
+ export declare function setDiscovering(on: boolean): void;
26
+ /** Where a registration goes. */
27
+ export type RegistrationSink = (registration: OmRegistrationMessage) => void;
28
+ /** Test seam: collect registrations in-process. Pass `null` to restore the IPC sink. */
29
+ export declare function setRegistrationSink(next: RegistrationSink | null): void;
30
+ export declare function reportOm(registration: OmRegistrationMessage): void;
31
+ /**
32
+ * Convert a declared schema, never throwing. `z.toJSONSchema` rejects schemas it cannot
33
+ * represent (`z.date()`, `z.custom()`, anything built on them), and one such entry must
34
+ * not take the whole tool list down with it — so the failure is carried as data on that
35
+ * entry alone. `undefined` in (no `.args()`) means nothing to report either way.
36
+ */
37
+ export declare function describeSchema(schema: unknown): DescribedArgs;
@@ -0,0 +1,54 @@
1
+ import { toJsonSchema } from "./schema-json.js";
2
+ /**
3
+ * Discovery mode. The child forked by `discoverRegistrations()` sets `OMKIT_DISCOVER=1`
4
+ * and imports om files purely to read what they declare. In that mode `launch()` posts a
5
+ * registration and returns: no ExecutionTree, no log folder, no body.
6
+ *
7
+ * The flag is read once at import and then deleted from the environment, so a subprocess
8
+ * an om happens to spawn does not inherit it — the same discipline `OMKIT_SUPERVISED` and
9
+ * `OMKIT_ARGS` already follow.
10
+ */
11
+ function detect() {
12
+ const discovering = process.env.OMKIT_DISCOVER === "1";
13
+ delete process.env.OMKIT_DISCOVER;
14
+ return discovering;
15
+ }
16
+ let discovering = detect();
17
+ export function isDiscovering() {
18
+ return discovering;
19
+ }
20
+ /** Test seam: enter or leave discovery mode without forking a child. */
21
+ export function setDiscovering(on) {
22
+ discovering = on;
23
+ }
24
+ /** The real sink: straight up the fork's IPC channel. A no-op with no channel. */
25
+ const ipcSink = (registration) => {
26
+ process.send?.(registration);
27
+ };
28
+ let sink = ipcSink;
29
+ /** Test seam: collect registrations in-process. Pass `null` to restore the IPC sink. */
30
+ export function setRegistrationSink(next) {
31
+ sink = next ?? ipcSink;
32
+ }
33
+ export function reportOm(registration) {
34
+ sink(registration);
35
+ }
36
+ /**
37
+ * Convert a declared schema, never throwing. `z.toJSONSchema` rejects schemas it cannot
38
+ * represent (`z.date()`, `z.custom()`, anything built on them), and one such entry must
39
+ * not take the whole tool list down with it — so the failure is carried as data on that
40
+ * entry alone. `undefined` in (no `.args()`) means nothing to report either way.
41
+ */
42
+ export function describeSchema(schema) {
43
+ if (schema === undefined)
44
+ return { inputSchema: undefined, schemaError: undefined };
45
+ try {
46
+ return { inputSchema: toJsonSchema(schema), schemaError: undefined };
47
+ }
48
+ catch (e) {
49
+ return {
50
+ inputSchema: undefined,
51
+ schemaError: e instanceof Error ? e.message : String(e),
52
+ };
53
+ }
54
+ }
@@ -5,13 +5,15 @@ import type { LogEntry } from "../foundation/LogEntry.ts";
5
5
  * so there is no core→actions import cycle).
6
6
  */
7
7
  export interface PromptSpec {
8
- kind: "input" | "choice";
8
+ kind: "input" | "choice" | "multiline";
9
9
  message: string;
10
10
  default: string;
11
11
  choices?: {
12
12
  label: string;
13
13
  value: string;
14
14
  }[];
15
+ /** A one-line type sketch shown with the message — set for `multiline` JSON prompts. */
16
+ hint?: string;
15
17
  }
16
18
  export type ChildMessage = {
17
19
  kind: "prompt";
package/dist/core/om.d.ts CHANGED
@@ -1,11 +1,13 @@
1
- import type { Awaitable, OmContext } from "./types.ts";
1
+ import type { OmBuilder } from "./types.ts";
2
2
  /**
3
- * Runs a linear orchestration as the root of a fresh {@link ExecutionTree}. The
4
- * required `name` plus the absolute path of the file calling `om()` form the run's
5
- * identity — its log folder is `logs/<name>-<hash8>/…`, so same-named oms defined
6
- * in different files never share a folder. The body runs inside the root node's
7
- * ambient scope, so any action call / `step(...)` / `console.*` it reaches
8
- * attributes correctly. Resolves once the run has torn down and produced its
9
- * artifacts; never rejects (failures are recorded in the tree and set the exit code).
3
+ * Define a run. `om(name)` returns a builder — chain `.describe(…)` and/or `.args(schema)`
4
+ * and finish with `.run(body)`, which launches it as the root of a fresh
5
+ * {@link ExecutionTree}. The name plus the absolute path of the calling file identify the
6
+ * run; its log folder is `logs/<name>-<hash8>/…`, so same-named oms in different files
7
+ * never share a folder.
8
+ *
9
+ * The call site is captured **here**, not in `.run()` (nor in `.args()`): `om(name)` is
10
+ * where a run is defined, so a builder handed to (and run from) another file still hashes
11
+ * to the file that defined it — see the run-folder-identity constraint doc.
10
12
  */
11
- export declare function om(name: string, body: (ctx: OmContext) => Awaitable<void>): Promise<void>;
13
+ export declare function om(name: string): OmBuilder;