clinkx 0.2.0 → 0.2.2

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 (149) hide show
  1. package/clinkx-workflows/dist/artifacts.d.ts +65 -0
  2. package/clinkx-workflows/dist/artifacts.js +268 -0
  3. package/clinkx-workflows/dist/artifacts.js.map +1 -0
  4. package/clinkx-workflows/dist/backend.d.ts +33 -0
  5. package/clinkx-workflows/dist/backend.js +9 -0
  6. package/clinkx-workflows/dist/backend.js.map +1 -0
  7. package/clinkx-workflows/dist/child-env.d.ts +23 -0
  8. package/clinkx-workflows/dist/child-env.js +53 -0
  9. package/clinkx-workflows/dist/child-env.js.map +1 -0
  10. package/clinkx-workflows/dist/clink-client.d.ts +51 -0
  11. package/clinkx-workflows/dist/clink-client.js +216 -0
  12. package/clinkx-workflows/dist/clink-client.js.map +1 -0
  13. package/clinkx-workflows/dist/config.d.ts +126 -0
  14. package/clinkx-workflows/dist/config.js +226 -0
  15. package/clinkx-workflows/dist/config.js.map +1 -0
  16. package/clinkx-workflows/dist/definition-normalizer.d.ts +59 -0
  17. package/clinkx-workflows/dist/definition-normalizer.js +75 -0
  18. package/clinkx-workflows/dist/definition-normalizer.js.map +1 -0
  19. package/clinkx-workflows/dist/engine.d.ts +235 -0
  20. package/clinkx-workflows/dist/engine.js +1044 -0
  21. package/clinkx-workflows/dist/engine.js.map +1 -0
  22. package/clinkx-workflows/dist/errors.d.ts +74 -0
  23. package/clinkx-workflows/dist/errors.js +84 -0
  24. package/clinkx-workflows/dist/errors.js.map +1 -0
  25. package/clinkx-workflows/dist/fidelity.d.ts +112 -0
  26. package/clinkx-workflows/dist/fidelity.js +140 -0
  27. package/clinkx-workflows/dist/fidelity.js.map +1 -0
  28. package/clinkx-workflows/dist/fingerprint.d.ts +69 -0
  29. package/clinkx-workflows/dist/fingerprint.js +143 -0
  30. package/clinkx-workflows/dist/fingerprint.js.map +1 -0
  31. package/clinkx-workflows/dist/index.d.ts +16 -0
  32. package/clinkx-workflows/dist/index.js +42 -0
  33. package/clinkx-workflows/dist/index.js.map +1 -0
  34. package/clinkx-workflows/dist/loader.d.ts +64 -0
  35. package/clinkx-workflows/dist/loader.js +371 -0
  36. package/clinkx-workflows/dist/loader.js.map +1 -0
  37. package/clinkx-workflows/dist/logger.d.ts +16 -0
  38. package/clinkx-workflows/dist/logger.js +31 -0
  39. package/clinkx-workflows/dist/logger.js.map +1 -0
  40. package/clinkx-workflows/dist/path-validation.d.ts +23 -0
  41. package/clinkx-workflows/dist/path-validation.js +73 -0
  42. package/clinkx-workflows/dist/path-validation.js.map +1 -0
  43. package/clinkx-workflows/dist/prompt-budget.d.ts +31 -0
  44. package/clinkx-workflows/dist/prompt-budget.js +78 -0
  45. package/clinkx-workflows/dist/prompt-budget.js.map +1 -0
  46. package/clinkx-workflows/dist/queue.d.ts +16 -0
  47. package/clinkx-workflows/dist/queue.js +46 -0
  48. package/clinkx-workflows/dist/queue.js.map +1 -0
  49. package/clinkx-workflows/dist/ranking-reducer.d.ts +11 -0
  50. package/clinkx-workflows/dist/ranking-reducer.js +245 -0
  51. package/clinkx-workflows/dist/ranking-reducer.js.map +1 -0
  52. package/clinkx-workflows/dist/reducers/index.d.ts +8 -0
  53. package/clinkx-workflows/dist/reducers/index.js +12 -0
  54. package/clinkx-workflows/dist/reducers/index.js.map +1 -0
  55. package/clinkx-workflows/dist/run-id.d.ts +17 -0
  56. package/clinkx-workflows/dist/run-id.js +26 -0
  57. package/clinkx-workflows/dist/run-id.js.map +1 -0
  58. package/clinkx-workflows/dist/run-summary/cards/council-answer.d.ts +8 -0
  59. package/clinkx-workflows/dist/run-summary/cards/council-answer.js +75 -0
  60. package/clinkx-workflows/dist/run-summary/cards/council-answer.js.map +1 -0
  61. package/clinkx-workflows/dist/run-summary/cards/council-code-review.d.ts +13 -0
  62. package/clinkx-workflows/dist/run-summary/cards/council-code-review.js +90 -0
  63. package/clinkx-workflows/dist/run-summary/cards/council-code-review.js.map +1 -0
  64. package/clinkx-workflows/dist/run-summary/cards/council-debug.d.ts +9 -0
  65. package/clinkx-workflows/dist/run-summary/cards/council-debug.js +79 -0
  66. package/clinkx-workflows/dist/run-summary/cards/council-debug.js.map +1 -0
  67. package/clinkx-workflows/dist/run-summary/cards/council-default.d.ts +11 -0
  68. package/clinkx-workflows/dist/run-summary/cards/council-default.js +57 -0
  69. package/clinkx-workflows/dist/run-summary/cards/council-default.js.map +1 -0
  70. package/clinkx-workflows/dist/run-summary/cards/council-discover.d.ts +10 -0
  71. package/clinkx-workflows/dist/run-summary/cards/council-discover.js +79 -0
  72. package/clinkx-workflows/dist/run-summary/cards/council-discover.js.map +1 -0
  73. package/clinkx-workflows/dist/run-summary/cards/generic.d.ts +2 -0
  74. package/clinkx-workflows/dist/run-summary/cards/generic.js +4 -0
  75. package/clinkx-workflows/dist/run-summary/cards/generic.js.map +1 -0
  76. package/clinkx-workflows/dist/run-summary/cards/index.d.ts +6 -0
  77. package/clinkx-workflows/dist/run-summary/cards/index.js +17 -0
  78. package/clinkx-workflows/dist/run-summary/cards/index.js.map +1 -0
  79. package/clinkx-workflows/dist/run-summary/utils.d.ts +6 -0
  80. package/clinkx-workflows/dist/run-summary/utils.js +30 -0
  81. package/clinkx-workflows/dist/run-summary/utils.js.map +1 -0
  82. package/clinkx-workflows/dist/run-summary-derived.d.ts +19 -0
  83. package/clinkx-workflows/dist/run-summary-derived.js +100 -0
  84. package/clinkx-workflows/dist/run-summary-derived.js.map +1 -0
  85. package/clinkx-workflows/dist/run-summary.d.ts +70 -0
  86. package/clinkx-workflows/dist/run-summary.js +125 -0
  87. package/clinkx-workflows/dist/run-summary.js.map +1 -0
  88. package/clinkx-workflows/dist/schema.d.ts +609 -0
  89. package/clinkx-workflows/dist/schema.js +123 -0
  90. package/clinkx-workflows/dist/schema.js.map +1 -0
  91. package/clinkx-workflows/dist/server.d.ts +16 -0
  92. package/clinkx-workflows/dist/server.js +33 -0
  93. package/clinkx-workflows/dist/server.js.map +1 -0
  94. package/clinkx-workflows/dist/shutdown.d.ts +54 -0
  95. package/clinkx-workflows/dist/shutdown.js +120 -0
  96. package/clinkx-workflows/dist/shutdown.js.map +1 -0
  97. package/clinkx-workflows/dist/state-schema.d.ts +141 -0
  98. package/clinkx-workflows/dist/state-schema.js +21 -0
  99. package/clinkx-workflows/dist/state-schema.js.map +1 -0
  100. package/clinkx-workflows/dist/state.d.ts +37 -0
  101. package/clinkx-workflows/dist/state.js +838 -0
  102. package/clinkx-workflows/dist/state.js.map +1 -0
  103. package/clinkx-workflows/dist/template-loader.d.ts +30 -0
  104. package/clinkx-workflows/dist/template-loader.js +77 -0
  105. package/clinkx-workflows/dist/template-loader.js.map +1 -0
  106. package/clinkx-workflows/dist/template.d.ts +54 -0
  107. package/clinkx-workflows/dist/template.js +128 -0
  108. package/clinkx-workflows/dist/template.js.map +1 -0
  109. package/clinkx-workflows/dist/transport.d.ts +91 -0
  110. package/clinkx-workflows/dist/transport.js +249 -0
  111. package/clinkx-workflows/dist/transport.js.map +1 -0
  112. package/clinkx-workflows/dist/types.d.ts +137 -0
  113. package/clinkx-workflows/dist/types.js +11 -0
  114. package/clinkx-workflows/dist/types.js.map +1 -0
  115. package/clinkx-workflows/dist/validators/council.d.ts +1488 -0
  116. package/clinkx-workflows/dist/validators/council.js +509 -0
  117. package/clinkx-workflows/dist/validators/council.js.map +1 -0
  118. package/clinkx-workflows/dist/validators/index.d.ts +40 -0
  119. package/clinkx-workflows/dist/validators/index.js +43 -0
  120. package/clinkx-workflows/dist/validators/index.js.map +1 -0
  121. package/clinkx-workflows/dist/workflow-receipt.d.ts +4 -0
  122. package/clinkx-workflows/dist/workflow-receipt.js +177 -0
  123. package/clinkx-workflows/dist/workflow-receipt.js.map +1 -0
  124. package/clinkx-workflows/dist/workflow-tools.d.ts +77 -0
  125. package/clinkx-workflows/dist/workflow-tools.js +1131 -0
  126. package/clinkx-workflows/dist/workflow-tools.js.map +1 -0
  127. package/clinkx-workflows/dist/workflows/council-default.d.ts +123 -0
  128. package/clinkx-workflows/dist/workflows/council-default.js +141 -0
  129. package/clinkx-workflows/dist/workflows/council-default.js.map +1 -0
  130. package/clinkx-workflows/dist/workflows/index.d.ts +12 -0
  131. package/clinkx-workflows/dist/workflows/index.js +15 -0
  132. package/clinkx-workflows/dist/workflows/index.js.map +1 -0
  133. package/conf/adapters/codex.json +2 -2
  134. package/conf/adapters/hapi/codex.json +2 -2
  135. package/dist/config.d.ts +5 -0
  136. package/dist/config.js +17 -0
  137. package/dist/config.js.map +1 -1
  138. package/dist/parsers/extract.d.ts +2 -0
  139. package/dist/parsers/extract.js +29 -20
  140. package/dist/parsers/extract.js.map +1 -1
  141. package/dist/pipeline.d.ts +2 -4
  142. package/dist/pipeline.js +93 -8
  143. package/dist/pipeline.js.map +1 -1
  144. package/dist/result-contract.d.ts +6 -1
  145. package/dist/result-contract.js +10 -22
  146. package/dist/result-contract.js.map +1 -1
  147. package/dist/runner.js +43 -1
  148. package/dist/runner.js.map +1 -1
  149. package/package.json +12 -5
@@ -0,0 +1,249 @@
1
+ /**
2
+ * ClinkSession — per-run MCP client transport to a ClinkX child process.
3
+ *
4
+ * Spawns ClinkX over STDIO, performs MCP initialize handshake,
5
+ * verifies clink tool availability, and provides callTool/terminate.
6
+ *
7
+ * The SDK's Client.request() already:
8
+ * - Supports timeout via RequestOptions.timeout (ms)
9
+ * - Sends notifications/cancelled on AbortSignal abort
10
+ * So we get 1-7a (deadlines) and 1-8a/b (cancellation) from the SDK.
11
+ */
12
+ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
13
+ import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
14
+ import { logger } from "./logger.js";
15
+ import { buildChildEnv } from "./child-env.js";
16
+ import { getClinkxCmd, resolveWorkspaceRoot, deriveAllowedRoots, getStateDir, getArtifactsDir, } from "./config.js";
17
+ import { CallExecutionError } from "./errors.js";
18
+ /** Default deadline for initialize + tools/list handshake (ms). */
19
+ const DEFAULT_HANDSHAKE_TIMEOUT_MS = 30_000;
20
+ /** Default deadline for tools/call RPCs (ms). */
21
+ const DEFAULT_CALL_TIMEOUT_MS = 600_000;
22
+ /**
23
+ * Per-run MCP session to a ClinkX child process.
24
+ *
25
+ * Lifecycle: create → connect() → callTool() ... → terminate()
26
+ */
27
+ export class ClinkSession {
28
+ client = null;
29
+ transport = null;
30
+ terminated = false;
31
+ childExitedUnexpectedly = false;
32
+ /** Cached cli_name values from tools/list. */
33
+ cliNames = [];
34
+ /** Cached role union from tools/list. */
35
+ roleNames = [];
36
+ runId;
37
+ command;
38
+ args;
39
+ envOverrides;
40
+ handshakeTimeoutMs;
41
+ callTimeoutMs;
42
+ onChildDeath;
43
+ constructor(options) {
44
+ this.runId = options.runId;
45
+ this.command = options.command ?? getClinkxCmd();
46
+ this.args = options.args ?? [];
47
+ this.envOverrides = options.envOverrides ?? {};
48
+ this.handshakeTimeoutMs = options.handshakeTimeoutMs ?? DEFAULT_HANDSHAKE_TIMEOUT_MS;
49
+ this.callTimeoutMs = options.callTimeoutMs ?? DEFAULT_CALL_TIMEOUT_MS;
50
+ this.onChildDeath = options.onChildDeath;
51
+ }
52
+ /**
53
+ * Spawn child, perform MCP handshake, verify clink tool.
54
+ * Throws on failure (handshake timeout, missing clink tool, etc.).
55
+ */
56
+ async connect() {
57
+ const workspaceRoot = resolveWorkspaceRoot();
58
+ const stateDir = getStateDir();
59
+ const artifactsDir = getArtifactsDir();
60
+ const allowedRoots = deriveAllowedRoots(workspaceRoot, stateDir, artifactsDir);
61
+ const childEnv = buildChildEnv({
62
+ allowedRoots,
63
+ ...this.envOverrides,
64
+ });
65
+ const transportArgs = [...this.args];
66
+ this.transport = new StdioClientTransport({
67
+ command: this.command,
68
+ args: transportArgs,
69
+ env: childEnv,
70
+ cwd: workspaceRoot,
71
+ stderr: "pipe",
72
+ });
73
+ // Capture child stderr and re-log with prefix
74
+ this.setupStderrCapture();
75
+ // Monitor for unexpected child death
76
+ this.setupChildDeathHandler();
77
+ this.client = new Client({ name: "clinkx-workflows", version: "0.1.0" }, { capabilities: {} });
78
+ // Connect performs MCP initialize handshake with enforced timeout
79
+ const connectPromise = this.client.connect(this.transport);
80
+ let timeoutHandle;
81
+ const timeoutPromise = new Promise((_, reject) => {
82
+ timeoutHandle = setTimeout(() => {
83
+ reject(new Error(`Handshake timeout: child did not complete MCP initialize within ${String(this.handshakeTimeoutMs)}ms. ` +
84
+ `Check that "${this.command}" is a valid MCP server command.`));
85
+ }, this.handshakeTimeoutMs);
86
+ });
87
+ try {
88
+ await Promise.race([connectPromise, timeoutPromise]);
89
+ }
90
+ catch (err) {
91
+ // Force-terminate on timeout or connect error
92
+ this.terminated = true;
93
+ try {
94
+ if (this.client != null) {
95
+ await this.client.close();
96
+ this.client = null;
97
+ }
98
+ }
99
+ catch { /* best-effort cleanup */ }
100
+ try {
101
+ if (this.transport != null) {
102
+ await this.transport.close();
103
+ this.transport = null;
104
+ }
105
+ }
106
+ catch { /* best-effort cleanup */ }
107
+ const msg = err instanceof Error ? err.message : String(err);
108
+ throw new Error(`ClinkSession connect failed for run ${this.runId}: ${msg}`);
109
+ }
110
+ finally {
111
+ if (timeoutHandle != null) {
112
+ clearTimeout(timeoutHandle);
113
+ }
114
+ }
115
+ logger.info({ run_id: this.runId, server: this.client.getServerVersion() }, "child MCP handshake complete");
116
+ // tools/list — verify clink tool exists
117
+ const toolsResult = await this.client.listTools(undefined, {
118
+ timeout: this.handshakeTimeoutMs,
119
+ });
120
+ const clinkTool = toolsResult.tools.find((t) => t.name === "clink");
121
+ if (clinkTool == null) {
122
+ await this.terminate();
123
+ throw new Error(`ClinkSession: child does not expose "clink" tool. ` +
124
+ `Available: ${toolsResult.tools.map((t) => t.name).join(", ") || "(none)"}`);
125
+ }
126
+ // Cache cli_name enum values if advertised
127
+ const props = clinkTool.inputSchema.properties;
128
+ if (props?.["cli_name"]?.["enum"] != null) {
129
+ const names = props["cli_name"]["enum"];
130
+ if (Array.isArray(names)) {
131
+ this.cliNames.push(...names.filter((n) => typeof n === "string"));
132
+ }
133
+ }
134
+ // Cache role enum values if advertised
135
+ if (props?.["role"]?.["enum"] != null) {
136
+ const roles = props["role"]["enum"];
137
+ if (Array.isArray(roles)) {
138
+ this.roleNames.push(...roles.filter((r) => typeof r === "string"));
139
+ }
140
+ }
141
+ logger.info({
142
+ run_id: this.runId,
143
+ cli_names: this.cliNames,
144
+ role_names: this.roleNames,
145
+ }, "child clink tool verified");
146
+ }
147
+ /**
148
+ * Call the child's clink tool.
149
+ *
150
+ * @param args - Tool arguments (ClinkInput shape)
151
+ * @param options - Optional signal and timeout override
152
+ * @returns Tool call result
153
+ */
154
+ async callTool(args, options) {
155
+ if (this.terminated) {
156
+ throw new Error("ClinkSession: already terminated");
157
+ }
158
+ if (this.client == null) {
159
+ throw new Error("ClinkSession: not connected");
160
+ }
161
+ if (this.childExitedUnexpectedly) {
162
+ throw new CallExecutionError(`Child process died unexpectedly during run ${this.runId}`, "transport", "child_death", "transient");
163
+ }
164
+ const result = await this.client.callTool({ name: "clink", arguments: args }, undefined, {
165
+ timeout: options?.timeoutMs ?? this.callTimeoutMs,
166
+ ...(options?.signal != null ? { signal: options.signal } : {}),
167
+ });
168
+ return result;
169
+ }
170
+ /**
171
+ * Terminate the child session cleanly.
172
+ */
173
+ async terminate() {
174
+ if (this.terminated)
175
+ return;
176
+ this.terminated = true;
177
+ try {
178
+ if (this.client != null) {
179
+ await this.client.close();
180
+ this.client = null;
181
+ }
182
+ }
183
+ catch (err) {
184
+ logger.warn({ run_id: this.runId, err: err instanceof Error ? err.message : String(err) }, "error during child session close");
185
+ }
186
+ this.transport = null;
187
+ logger.info({ run_id: this.runId }, "child session terminated");
188
+ }
189
+ /**
190
+ * Whether the session has been terminated.
191
+ */
192
+ get isTerminated() {
193
+ return this.terminated;
194
+ }
195
+ /**
196
+ * Whether the child died unexpectedly.
197
+ */
198
+ get hasChildDied() {
199
+ return this.childExitedUnexpectedly;
200
+ }
201
+ /**
202
+ * Set up stderr capture from the child process.
203
+ * Prefix each line with [child:<run_id>] and re-log via parent pino.
204
+ */
205
+ setupStderrCapture() {
206
+ if (this.transport == null)
207
+ return;
208
+ const stderrStream = this.transport.stderr;
209
+ if (stderrStream == null)
210
+ return;
211
+ const prefix = `[child:${this.runId}]`;
212
+ let buffer = "";
213
+ stderrStream.on("data", (chunk) => {
214
+ buffer += chunk.toString("utf-8");
215
+ const lines = buffer.split("\n");
216
+ // Keep incomplete last line in buffer
217
+ buffer = lines.pop() ?? "";
218
+ for (const line of lines) {
219
+ if (line.trim().length > 0) {
220
+ logger.debug({ run_id: this.runId }, "%s %s", prefix, line);
221
+ }
222
+ }
223
+ });
224
+ stderrStream.on("end", () => {
225
+ if (buffer.trim().length > 0) {
226
+ logger.debug({ run_id: this.runId }, "%s %s", prefix, buffer);
227
+ }
228
+ });
229
+ }
230
+ /**
231
+ * Monitor for unexpected child death (1-9a).
232
+ * On unexpected death mid-run, mark as transient failure.
233
+ */
234
+ setupChildDeathHandler() {
235
+ if (this.transport == null)
236
+ return;
237
+ // The SDK's StdioClientTransport fires onclose when the child exits
238
+ const originalOnclose = this.transport.onclose;
239
+ this.transport.onclose = () => {
240
+ if (!this.terminated) {
241
+ this.childExitedUnexpectedly = true;
242
+ logger.error({ run_id: this.runId }, "child process died unexpectedly");
243
+ this.onChildDeath?.(null, null);
244
+ }
245
+ originalOnclose?.();
246
+ };
247
+ }
248
+ }
249
+ //# sourceMappingURL=transport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.js","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,aAAa,EAA0B,MAAM,gBAAgB,CAAC;AACvE,OAAO,EACL,YAAY,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YAClC,CAAC;YACD,eAAe,EAAE,EAAE,CAAC;QACtB,CAAC,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,137 @@
1
+ /**
2
+ * Core workflow type definitions for clinkx-workflows.
3
+ *
4
+ * v1 execution model: ORDERED LINEAR STAGES ONLY.
5
+ * - No DAGs, no depends_on, no topological sort.
6
+ * - Stage order = execution order.
7
+ * - Optional parallel fan-out WITHIN a stage; fan-in across stage boundaries.
8
+ * - Final stage MUST contain exactly one call (invariant 0-6a).
9
+ */
10
+ /** Scalar variable types supported in v1. */
11
+ export type VariableType = "string" | "number" | "boolean" | "string[]";
12
+ /** Variable declaration in a workflow definition. */
13
+ export interface Variable {
14
+ readonly type: VariableType;
15
+ readonly required: boolean;
16
+ readonly default?: string | number | boolean | readonly string[] | undefined;
17
+ readonly description?: string | undefined;
18
+ }
19
+ /**
20
+ * A single call to the ClinkX child process.
21
+ *
22
+ * Each call maps to one `tools/call` for the `clink` tool on the child.
23
+ */
24
+ export interface Call {
25
+ /** Unique within its parent stage. Must match [A-Za-z0-9_-]+. */
26
+ readonly id: string;
27
+ /** Which CLI adapter to use (resolved by child's adapter registry). */
28
+ readonly cli_name: string;
29
+ /** Role selector — maps to adapter roles config. */
30
+ readonly role: string;
31
+ /**
32
+ * Exactly ONE of prompt or prompt_template must be set (XOR).
33
+ * prompt: inline prompt text.
34
+ * prompt_template: logical path relative to templates root (e.g. "council/member.txt").
35
+ */
36
+ readonly prompt?: string | undefined;
37
+ readonly prompt_template?: string | undefined;
38
+ /** Built-in reducer function ID. When set, this call runs a deterministic function instead of an LLM. */
39
+ readonly reducer?: string | undefined;
40
+ /** If true, upstream context artifacts are aliased (A.json, B.json, ...) to prevent identity leakage. */
41
+ readonly anonymize_context?: boolean | undefined;
42
+ /** Request timeout override (seconds). Extends above adapter floor, never shortens. */
43
+ readonly timeout_seconds?: number | undefined;
44
+ /** Static file paths to reference. */
45
+ readonly absolute_file_paths?: readonly string[] | undefined;
46
+ /** Variable name for dynamic file paths (resolved at run time). */
47
+ readonly absolute_file_paths_from?: string | undefined;
48
+ /** Static image paths. */
49
+ readonly images?: readonly string[] | undefined;
50
+ /** Variable name for dynamic image paths (resolved at run time). */
51
+ readonly images_from?: string | undefined;
52
+ /**
53
+ * References to prior stage/call outputs.
54
+ * Single ref or array, normalized to array internally.
55
+ * May reference a stage ID (all calls) or "stage.call" (specific call).
56
+ * MUST reference only EARLIER stages — forward references are rejected at load time.
57
+ */
58
+ readonly context_from?: readonly string[] | undefined;
59
+ /**
60
+ * Required for context-producing calls (any call referenced by context_from).
61
+ * Points to a registered zod schema in the ValidatorRegistry.
62
+ */
63
+ readonly validator_schema_id?: string | undefined;
64
+ /**
65
+ * Per-call override for CLINKX_WORKFLOWS_CHILD_MAX_RESPONSE_CHARS.
66
+ * Prevents limitOutput() from mangling structured output on context-producing stages.
67
+ * Task 0-10-2.
68
+ */
69
+ readonly max_response_chars?: number | undefined;
70
+ /**
71
+ * Response contract for structured output.
72
+ * When set to "json", the call is expected to produce valid JSON output.
73
+ */
74
+ readonly response_contract?: "json" | undefined;
75
+ }
76
+ /**
77
+ * Retry configuration for a stage.
78
+ *
79
+ * mode:
80
+ * - "transport_only" (default): retry on child crash, wall timeout, idle timeout, transport death.
81
+ * - "all": retry on any isError: true (legacy behavior).
82
+ *
83
+ * In both modes, child -32602 (InvalidParams) is ALWAYS permanent (no retry).
84
+ */
85
+ export interface RetryConfig {
86
+ readonly mode: "transport_only" | "all";
87
+ readonly max_retries: number;
88
+ readonly backoff_seconds: number;
89
+ readonly max_backoff_seconds: number;
90
+ }
91
+ /**
92
+ * A stage is an ordered group of calls.
93
+ *
94
+ * v1: stages execute in DEFINITION ORDER. No depends_on, no topological sort.
95
+ */
96
+ export interface Stage {
97
+ /** Unique across the workflow. Must match [A-Za-z0-9_-]+. */
98
+ readonly id: string;
99
+ /** If true (default), calls within this stage execute concurrently. */
100
+ readonly parallel: boolean;
101
+ /** Retry policy for calls in this stage. */
102
+ readonly retry: RetryConfig;
103
+ /** Failure policy: abort stops the workflow; continue records and proceeds. */
104
+ readonly on_failure: "abort" | "continue";
105
+ /**
106
+ * Calls in this stage.
107
+ * INVARIANT (0-6a): If this is the FINAL stage in the workflow,
108
+ * it MUST contain exactly one call.
109
+ */
110
+ readonly calls: readonly Call[];
111
+ }
112
+ /** Workflow-level settings. */
113
+ export interface WorkflowSettings {
114
+ readonly timeout_seconds: number;
115
+ readonly max_retries: number;
116
+ }
117
+ /**
118
+ * Complete workflow definition.
119
+ *
120
+ * v1 scope:
121
+ * - Ordered stages only — stage array order = execution order.
122
+ * - No arbitrary DAGs.
123
+ * - Final stage must have exactly one call (0-6a).
124
+ * - Side-effecting workflows rejected at load time (0-5a).
125
+ */
126
+ export interface WorkflowDefinition {
127
+ readonly name: string;
128
+ readonly description: string;
129
+ readonly version: string;
130
+ readonly variables: Readonly<Record<string, Variable>>;
131
+ readonly settings: WorkflowSettings;
132
+ /**
133
+ * Ordered stages. Execution proceeds strictly in array order.
134
+ * The last element is the final stage and must contain exactly one call.
135
+ */
136
+ readonly stages: readonly Stage[];
137
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Core workflow type definitions for clinkx-workflows.
3
+ *
4
+ * v1 execution model: ORDERED LINEAR STAGES ONLY.
5
+ * - No DAGs, no depends_on, no topological sort.
6
+ * - Stage order = execution order.
7
+ * - Optional parallel fan-out WITHIN a stage; fan-in across stage boundaries.
8
+ * - Final stage MUST contain exactly one call (invariant 0-6a).
9
+ */
10
+ export {};
11
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}