clinkx 0.2.0 → 0.2.1

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 +11 -5
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Zod schemas for workflow definitions (clinkx-workflows).
3
+ *
4
+ * This is separate from the parent ClinkX schema.ts — these schemas define
5
+ * workflow definition structure, not MCP tool input.
6
+ *
7
+ * Tasks: 2-1a, 2-2a, 2-3a, 2-4a, 2-5a
8
+ */
9
+ import { z } from "zod";
10
+ // ---------------------------------------------------------------------------
11
+ // 2-5a: ID Grammar
12
+ // ---------------------------------------------------------------------------
13
+ /**
14
+ * ID grammar: [A-Za-z0-9_-]+
15
+ * Dots are forbidden because "stage.call" is the reference syntax for context_from.
16
+ */
17
+ const ID_PATTERN = /^[A-Za-z0-9_-]+$/;
18
+ export const IdSchema = z
19
+ .string()
20
+ .min(1)
21
+ .regex(ID_PATTERN, "IDs must match [A-Za-z0-9_-]+ (dots forbidden)");
22
+ // ---------------------------------------------------------------------------
23
+ // 2-2a: VariableSchema
24
+ // ---------------------------------------------------------------------------
25
+ export const VariableTypeSchema = z.enum([
26
+ "string",
27
+ "number",
28
+ "boolean",
29
+ "string[]",
30
+ ]);
31
+ export const VariableSchema = z.object({
32
+ type: VariableTypeSchema,
33
+ required: z.boolean(),
34
+ default: z
35
+ .union([z.string(), z.number(), z.boolean(), z.array(z.string())])
36
+ .optional(),
37
+ description: z.string().optional(),
38
+ });
39
+ // ---------------------------------------------------------------------------
40
+ // 2-3a: StageSchema — RetryConfig
41
+ // ---------------------------------------------------------------------------
42
+ export const RetryConfigSchema = z.object({
43
+ mode: z
44
+ .enum(["transport_only", "all"])
45
+ .default("transport_only"),
46
+ max_retries: z.number().int().min(0).default(0),
47
+ backoff_seconds: z.number().min(0).default(5),
48
+ max_backoff_seconds: z.number().min(0).default(60),
49
+ });
50
+ // ---------------------------------------------------------------------------
51
+ // 2-4a: CallSchema
52
+ // ---------------------------------------------------------------------------
53
+ /**
54
+ * Normalize context_from: accept a single string or array, always produce array.
55
+ */
56
+ const ContextFromSchema = z
57
+ .union([z.string(), z.array(z.string())])
58
+ .transform((val) => (typeof val === "string" ? [val] : val))
59
+ .optional();
60
+ const BaseCallSchema = z.object({
61
+ id: IdSchema,
62
+ cli_name: z.string().min(1),
63
+ role: z.string().min(1),
64
+ reducer: z.string().optional(),
65
+ anonymize_context: z.boolean().optional(),
66
+ timeout_seconds: z.number().positive().optional(),
67
+ absolute_file_paths: z.array(z.string()).optional(),
68
+ absolute_file_paths_from: z.string().optional(),
69
+ images: z.array(z.string()).optional(),
70
+ images_from: z.string().optional(),
71
+ context_from: ContextFromSchema,
72
+ validator_schema_id: z.string().optional(),
73
+ max_response_chars: z.number().int().positive().optional(),
74
+ response_contract: z.enum(["json"]).optional(),
75
+ });
76
+ /**
77
+ * CallSchema: exactly ONE of `prompt` or `prompt_template` (XOR).
78
+ * Uses zod refine for XOR enforcement.
79
+ */
80
+ export const CallSchema = BaseCallSchema
81
+ .extend({
82
+ prompt: z.string().optional(),
83
+ prompt_template: z.string().optional(),
84
+ })
85
+ .refine((c) => {
86
+ const hasPrompt = c.prompt != null && c.prompt !== "";
87
+ const hasTemplate = c.prompt_template != null && c.prompt_template !== "";
88
+ return (hasPrompt && !hasTemplate) || (!hasPrompt && hasTemplate);
89
+ }, {
90
+ message: "Exactly one of 'prompt' or 'prompt_template' must be specified (XOR)",
91
+ path: ["prompt"],
92
+ });
93
+ // ---------------------------------------------------------------------------
94
+ // 2-3a: StageSchema
95
+ // ---------------------------------------------------------------------------
96
+ export const StageSchema = z.object({
97
+ id: IdSchema,
98
+ description: z.string().min(1).optional(),
99
+ parallel: z.boolean().default(true),
100
+ retry: RetryConfigSchema.default({}),
101
+ on_failure: z.enum(["abort", "continue"]).default("abort"),
102
+ calls: z.array(CallSchema).min(1, "Stage must have at least one call"),
103
+ });
104
+ // ---------------------------------------------------------------------------
105
+ // 2-1a: WorkflowDefinitionSchema
106
+ // ---------------------------------------------------------------------------
107
+ export const WorkflowSettingsSchema = z.object({
108
+ timeout_seconds: z.number().positive().default(1800),
109
+ max_retries: z.number().int().min(0).default(0),
110
+ });
111
+ export const WorkflowDefinitionSchema = z.object({
112
+ name: IdSchema,
113
+ description: z.string().min(1),
114
+ version: z.string().min(1),
115
+ stages: z.array(StageSchema).min(1, "Workflow must have at least one stage"),
116
+ variables: z.record(IdSchema, VariableSchema).default({}),
117
+ settings: WorkflowSettingsSchema.default({}),
118
+ });
119
+ // ---------------------------------------------------------------------------
120
+ // Re-export ID regex for use in other modules
121
+ // ---------------------------------------------------------------------------
122
+ export { ID_PATTERN };
123
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,8EAA8E;AAC9E,mBAAmB;AACnB,8EAA8E;AAE9E;;;GAGG;AACH,MAAM,UAAU,GAAG,kBAAkB,CAAC;AAEtC,MAAM,CAAC,MAAM,QAAQ,G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+ *
4
+ * Creates a standalone MCP server with workflow tools backed by a
5
+ * ClinkSession child process. For in-process integration, use
6
+ * registerWorkflowTools() from workflow-tools.ts directly.
7
+ */
8
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
9
+ /**
10
+ * Create the clinkx-workflows MCP server.
11
+ *
12
+ * Registers three tools: run_workflow, resume_workflow, list_workflows.
13
+ * Uses ClinkSession (child process) as the backend.
14
+ * Does NOT connect transport — caller is responsible.
15
+ */
16
+ export declare function createWorkflowServer(): Server;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * MCP STDIO server factory for clinkx-workflows (Phase 6).
3
+ *
4
+ * Creates a standalone MCP server with workflow tools backed by a
5
+ * ClinkSession child process. For in-process integration, use
6
+ * registerWorkflowTools() from workflow-tools.ts directly.
7
+ */
8
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
9
+ import { ClinkSession } from "./transport.js";
10
+ import { registerWorkflowTools } from "./workflow-tools.js";
11
+ // ---------------------------------------------------------------------------
12
+ // Server factory
13
+ // ---------------------------------------------------------------------------
14
+ /**
15
+ * Create the clinkx-workflows MCP server.
16
+ *
17
+ * Registers three tools: run_workflow, resume_workflow, list_workflows.
18
+ * Uses ClinkSession (child process) as the backend.
19
+ * Does NOT connect transport — caller is responsible.
20
+ */
21
+ export function createWorkflowServer() {
22
+ const server = new Server({ name: "clinkx-workflows", version: "0.1.0" }, {
23
+ capabilities: { tools: {} },
24
+ instructions: "Orchestrates multi-stage workflows by delegating calls to CLI subagents via ClinkX. " +
25
+ "Use run_workflow to start a new workflow, resume_workflow to continue a failed run, " +
26
+ "or list_workflows to see available workflows.",
27
+ });
28
+ registerWorkflowTools(server, {
29
+ createBackend: (runId) => new ClinkSession({ runId }),
30
+ });
31
+ return server;
32
+ }
33
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,8EAA8E;AAC9E,iBAAiB;AACjB,8EAA8E;AAE9E;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB;IAClC,MAAM,MAAM,GAAG,IAAI,MAAM,CACvB,EAAE,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE,OAAO,EAAE,EAC9C;QACE,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE;QAC3B,YAAY,EACV,sFAAsF;YACtF,sFAAsF;YACtF,+CAA+C;KAClD,CACF,CAAC;IAEF,qBAAqB,CAAC,MAAM,EAAE;QAC5B,aAAa,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,IAAI,YAAY,CAAC,EAAE,KAAK,EAAE,CAAC;KAC9D,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Shutdown coordinator for clinkx-workflows.
3
+ *
4
+ * Handles:
5
+ * - SIGTERM/SIGINT: cancel in-flight calls, persist state (best-effort),
6
+ * terminate child, exit
7
+ * - MCP cancellation: propagate AbortSignal, cancel calls, persist cancelled,
8
+ * no response
9
+ *
10
+ * Race-tolerant: late child responses remain possible per MCP spec.
11
+ */
12
+ import type { ClinkBackend } from "./backend.js";
13
+ type StatePersister = () => Promise<void>;
14
+ /**
15
+ * Manages graceful shutdown across signal handlers and MCP cancellation.
16
+ */
17
+ export declare class ShutdownCoordinator {
18
+ private state;
19
+ private shuttingDown;
20
+ private signalHandlersInstalled;
21
+ private readonly boundHandleSignal;
22
+ constructor();
23
+ /**
24
+ * Register the active session and abort controller for this run.
25
+ * Call at the start of each workflow run.
26
+ */
27
+ register(session: ClinkBackend, controller: AbortController, persistState: StatePersister): void;
28
+ /**
29
+ * Unregister the current run (on normal completion).
30
+ */
31
+ unregister(): void;
32
+ /**
33
+ * Get the AbortSignal for the current run.
34
+ * Use this to propagate cancellation to in-flight calls.
35
+ */
36
+ get signal(): AbortSignal | undefined;
37
+ /**
38
+ * Cancel the current run (e.g., from MCP notifications/cancelled).
39
+ * Aborts in-flight calls, persists state, terminates child.
40
+ * Does NOT call process.exit — caller decides response behavior.
41
+ */
42
+ cancelRun(): Promise<void>;
43
+ /**
44
+ * Handle SIGTERM/SIGINT.
45
+ * Cancel, persist, terminate, exit.
46
+ */
47
+ private handleSignalShutdown;
48
+ private safePersistState;
49
+ private safeTerminateSession;
50
+ private installSignalHandlers;
51
+ }
52
+ /** Singleton shutdown coordinator. */
53
+ export declare const shutdownCoordinator: ShutdownCoordinator;
54
+ export {};
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Shutdown coordinator for clinkx-workflows.
3
+ *
4
+ * Handles:
5
+ * - SIGTERM/SIGINT: cancel in-flight calls, persist state (best-effort),
6
+ * terminate child, exit
7
+ * - MCP cancellation: propagate AbortSignal, cancel calls, persist cancelled,
8
+ * no response
9
+ *
10
+ * Race-tolerant: late child responses remain possible per MCP spec.
11
+ */
12
+ import { logger } from "./logger.js";
13
+ /**
14
+ * Manages graceful shutdown across signal handlers and MCP cancellation.
15
+ */
16
+ export class ShutdownCoordinator {
17
+ state = {
18
+ session: null,
19
+ controller: null,
20
+ persistState: null,
21
+ };
22
+ shuttingDown = false;
23
+ signalHandlersInstalled = false;
24
+ boundHandleSignal;
25
+ constructor() {
26
+ this.boundHandleSignal = (signal) => {
27
+ void this.handleSignalShutdown(signal);
28
+ };
29
+ }
30
+ /**
31
+ * Register the active session and abort controller for this run.
32
+ * Call at the start of each workflow run.
33
+ */
34
+ register(session, controller, persistState) {
35
+ this.state = { session, controller, persistState };
36
+ this.shuttingDown = false;
37
+ this.installSignalHandlers();
38
+ }
39
+ /**
40
+ * Unregister the current run (on normal completion).
41
+ */
42
+ unregister() {
43
+ this.state = { session: null, controller: null, persistState: null };
44
+ }
45
+ /**
46
+ * Get the AbortSignal for the current run.
47
+ * Use this to propagate cancellation to in-flight calls.
48
+ */
49
+ get signal() {
50
+ return this.state.controller?.signal;
51
+ }
52
+ /**
53
+ * Cancel the current run (e.g., from MCP notifications/cancelled).
54
+ * Aborts in-flight calls, persists state, terminates child.
55
+ * Does NOT call process.exit — caller decides response behavior.
56
+ */
57
+ async cancelRun() {
58
+ if (this.shuttingDown)
59
+ return;
60
+ this.shuttingDown = true;
61
+ logger.info("cancelling current workflow run");
62
+ // 1. Abort in-flight calls
63
+ this.state.controller?.abort(new Error("Workflow cancelled"));
64
+ // 2. Best-effort state persistence
65
+ await this.safePersistState();
66
+ // 3. Terminate child session
67
+ await this.safeTerminateSession();
68
+ }
69
+ /**
70
+ * Handle SIGTERM/SIGINT.
71
+ * Cancel, persist, terminate, exit.
72
+ */
73
+ async handleSignalShutdown(signal) {
74
+ if (this.shuttingDown) {
75
+ logger.warn({ signal }, "duplicate shutdown signal ignored");
76
+ return;
77
+ }
78
+ this.shuttingDown = true;
79
+ logger.info({ signal }, "received shutdown signal");
80
+ // 1. Abort in-flight calls
81
+ this.state.controller?.abort(new Error(`Shutdown: ${signal}`));
82
+ // 2. Best-effort state persistence
83
+ await this.safePersistState();
84
+ // 3. Terminate child session
85
+ await this.safeTerminateSession();
86
+ // 4. Exit
87
+ logger.info({ signal }, "shutdown complete, exiting");
88
+ process.exit(0);
89
+ }
90
+ async safePersistState() {
91
+ if (this.state.persistState == null)
92
+ return;
93
+ try {
94
+ await this.state.persistState();
95
+ }
96
+ catch (err) {
97
+ logger.error({ err: err instanceof Error ? err.message : String(err) }, "failed to persist state during shutdown");
98
+ }
99
+ }
100
+ async safeTerminateSession() {
101
+ if (this.state.session == null)
102
+ return;
103
+ try {
104
+ await this.state.session.terminate();
105
+ }
106
+ catch (err) {
107
+ logger.error({ err: err instanceof Error ? err.message : String(err) }, "failed to terminate child session during shutdown");
108
+ }
109
+ }
110
+ installSignalHandlers() {
111
+ if (this.signalHandlersInstalled)
112
+ return;
113
+ this.signalHandlersInstalled = true;
114
+ process.on("SIGTERM", () => this.boundHandleSignal("SIGTERM"));
115
+ process.on("SIGINT", () => this.boundHandleSignal("SIGINT"));
116
+ }
117
+ }
118
+ /** Singleton shutdown coordinator. */
119
+ export const shutdownCoordinator = new ShutdownCoordinator();
120
+ //# sourceMappingURL=shutdown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shutdown.js","sourceRoot":"","sources":["../src/shutdown.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAWrC;;GAEG;AACH,MAAM,OAAO,mBAAmB;IACtB,KAAK,GAAkB;QAC7B,OAAO,EAAE,IAAI;QACb,UAAU,EAAE,IAAI;QAChB,YAAY,EAAE,IAAI;KACnB,CAAC;IACM,YAAY,GAAG,KAAK,CAAC;IACrB,uBAAuB,GAAG,KAAK,CAAC;IACvB,iBAAiB,CAA2B;IAE7D;QACE,IAAI,CAAC,iBAAiB,GAAG,CAAC,MAAc,EAAE,EAAE;YAC1C,KAAK,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC;QACzC,CAAC,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,QAAQ,CACN,OAAqB,EACrB,UAA2B,EAC3B,YAA4B;QAE5B,IAAI,CAAC,KAAK,GAAG,EAAE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC;QACnD,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;QAC1B,IAAI,CAAC,qBAAqB,EAAE,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,UAAU;QACR,IAAI,CAAC,KAAK,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;IACvE,CAAC;IAED;;;OAGG;IACH,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,MA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*
4
+ * The snapshot directory is THE resume authority; fingerprints are fast-rejection guards.
5
+ *
6
+ * At run start:
7
+ * 1. Persist normalized adapter bundle into <run>/child-config/
8
+ * 2. Hash the bundle as a fingerprint for fast mismatch rejection on resume
9
+ * 3. Persist exact materialized ClinkInput payloads per call before dispatch
10
+ *
11
+ * On resume:
12
+ * - Reuse materialized inputs verbatim (never re-resolve from live configs)
13
+ * - Fail hard on fingerprint mismatch (no override flag in v1)
14
+ * - If snapshot directory is missing/corrupted, run is non-resumable
15
+ *
16
+ * Resume is NOT stable across delegate CLI binary upgrades.
17
+ * Persistent resume requires CLINKX_WORKFLOWS_CHILD_CONFIG_PATH;
18
+ * ambient-config runs are non-resumable.
19
+ */
20
+ import type { ChildFailureMetadata } from "./errors.js";
21
+ import type { FidelityMetadata } from "./fidelity.js";
22
+ /** Call-level state progression. */
23
+ export type CallState = "pending" | "running" | "succeeded" | "failed" | "cancelled";
24
+ /** Run-level state progression. */
25
+ export type RunStatus = "pending" | "running" | "succeeded" | "failed" | "cancelled";
26
+ /** Failure classification for diagnostics and retry decisions. */
27
+ export type FailureClass = "transient" | "permanent";
28
+ /** Per-call state entry in the run state. */
29
+ export interface CallStateEntry {
30
+ readonly callId: string;
31
+ readonly stageId: string;
32
+ readonly state: CallState;
33
+ readonly retryCount: number;
34
+ readonly startedAt?: string | undefined;
35
+ readonly completedAt?: string | undefined;
36
+ readonly durationMs?: number | undefined;
37
+ readonly failureClass?: FailureClass | undefined;
38
+ readonly errorMessage?: string | undefined;
39
+ /**
40
+ * Pointer to output file for large outputs (>10KB).
41
+ * Path relative to run directory: "<stage_id>.<call_id>.output.txt"
42
+ */
43
+ readonly outputPath?: string | undefined;
44
+ /** Inline output for small results. */
45
+ readonly outputInline?: string | undefined;
46
+ /** Persisted exact ClinkInput payload written before dispatch. */
47
+ readonly materializedInputPath?: string | undefined;
48
+ /** Relative path to the validated artifact JSON, when present. */
49
+ readonly artifactPath?: string | undefined;
50
+ /** Whether this call is referenced by downstream context_from. */
51
+ readonly contextProducing?: boolean | undefined;
52
+ /** Persisted fidelity diagnostics for threaded outputs. */
53
+ readonly fidelity?: FidelityMetadata | undefined;
54
+ /** Structured metadata from child _debug block on failure. */
55
+ readonly childDebugMetadata?: ChildFailureMetadata | undefined;
56
+ }
57
+ /** Per-stage state entry. */
58
+ export interface StageStateEntry {
59
+ readonly stageId: string;
60
+ readonly state: CallState;
61
+ readonly startedAt?: string | undefined;
62
+ readonly completedAt?: string | undefined;
63
+ readonly calls: readonly CallStateEntry[];
64
+ }
65
+ /**
66
+ * Normalized adapter bundle — the complete post-load config for referenced adapters.
67
+ *
68
+ * This is the behaviorally-meaningful snapshot:
69
+ * - All CliAdapterConfigSchema fields (command, args, unsafe_args, env, parser, etc.)
70
+ * - Resolved role prompt contents (not just prompt_file paths)
71
+ * - Resolved absolute command paths
72
+ * - Explicit child env controls
73
+ *
74
+ * Raw file hashes don't capture effective behavior because registry.ts normalization
75
+ * (prompt_file resolution, schema defaults, first-wins dedup) transforms configs.
76
+ */
77
+ export interface ChildConfigSnapshot {
78
+ /** Adapter configs keyed by adapter name. Only referenced adapters are included. */
79
+ readonly adapters: Readonly<Record<string, unknown>>;
80
+ /** Resolved role prompt contents keyed by "adapter.role". */
81
+ readonly resolvedPrompts: Readonly<Record<string, string>>;
82
+ /** Explicit child env controls applied at spawn time. */
83
+ readonly childEnv: Readonly<Record<string, string>>;
84
+ }
85
+ /**
86
+ * Fingerprint payload for fast mismatch rejection on resume.
87
+ *
88
+ * The fingerprint is a hash of the ChildConfigSnapshot.
89
+ * If it doesn't match on resume, the run is rejected.
90
+ */
91
+ export interface Fingerprint {
92
+ /** Hash algorithm used. */
93
+ readonly algorithm: "sha256";
94
+ /** Hex-encoded hash of the serialized ChildConfigSnapshot. */
95
+ readonly hash: string;
96
+ /** Timestamp when the fingerprint was computed. */
97
+ readonly computedAt: string;
98
+ }
99
+ /**
100
+ * Complete run state persisted to <run>/state.json.
101
+ *
102
+ * state_version: 1 from day one to enable future migrations without guesswork.
103
+ */
104
+ export interface RunState {
105
+ /** Schema version for forward-compatible migration. Always 1 in v1. */
106
+ readonly state_version: 1;
107
+ /** Caller-supplied run ID. */
108
+ readonly runId: string;
109
+ /** Workflow name from definition. */
110
+ readonly workflowName: string;
111
+ /** Workflow version from definition. */
112
+ readonly workflowVersion: string;
113
+ /** Overall run status. */
114
+ readonly status: RunStatus;
115
+ /** Whether this run is resumable (requires explicit child config). */
116
+ readonly resumable: boolean;
117
+ /** Child config fingerprint for fast mismatch rejection. */
118
+ readonly fingerprint?: Fingerprint | undefined;
119
+ /** Relative path to the immutable workflow snapshot file. */
120
+ readonly workflowSnapshotPath?: string | undefined;
121
+ /** Digest of workflow.snapshot.json for corruption checks. */
122
+ readonly workflowSnapshotHash?: string | undefined;
123
+ /** Relative path to the immutable inputs snapshot file. */
124
+ readonly inputsSnapshotPath?: string | undefined;
125
+ /** Digest of inputs.snapshot.json for corruption checks. */
126
+ readonly inputsSnapshotHash?: string | undefined;
127
+ /** Relative path to the child config snapshot file, when resumable. */
128
+ readonly childConfigSnapshotPath?: string | undefined;
129
+ /** Per-stage state. */
130
+ readonly stages: readonly StageStateEntry[];
131
+ /** Resolved variables snapshot (non-secret only per 0-11a). */
132
+ readonly variables: Readonly<Record<string, unknown>>;
133
+ /** Run-level timing. */
134
+ readonly startedAt?: string | undefined;
135
+ readonly completedAt?: string | undefined;
136
+ /** Error details if run failed. */
137
+ readonly error?: string | undefined;
138
+ readonly failureClass?: FailureClass | undefined;
139
+ /** Retain run directory on success for debugging when true. */
140
+ readonly debugKeepArtifacts?: boolean | undefined;
141
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * State schema for clinkx-workflows resume authority model (0-12a).
3
+ *
4
+ * The snapshot directory is THE resume authority; fingerprints are fast-rejection guards.
5
+ *
6
+ * At run start:
7
+ * 1. Persist normalized adapter bundle into <run>/child-config/
8
+ * 2. Hash the bundle as a fingerprint for fast mismatch rejection on resume
9
+ * 3. Persist exact materialized ClinkInput payloads per call before dispatch
10
+ *
11
+ * On resume:
12
+ * - Reuse materialized inputs verbatim (never re-resolve from live configs)
13
+ * - Fail hard on fingerprint mismatch (no override flag in v1)
14
+ * - If snapshot directory is missing/corrupted, run is non-resumable
15
+ *
16
+ * Resume is NOT stable across delegate CLI binary upgrades.
17
+ * Persistent resume requires CLINKX_WORKFLOWS_CHILD_CONFIG_PATH;
18
+ * ambient-config runs are non-resumable.
19
+ */
20
+ export {};
21
+ //# sourceMappingURL=state-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state-schema.js","sourceRoot":"","sources":["../src/state-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG"}
@@ -0,0 +1,37 @@
1
+ import type { EngineHooks, EngineResumeState } from "./engine.js";
2
+ import type { NormalizedWorkflowDefinition } from "./definition-normalizer.js";
3
+ import type { RunState } from "./state-schema.js";
4
+ export interface CreateWorkflowStateOptions {
5
+ readonly runId: string;
6
+ readonly definition: NormalizedWorkflowDefinition;
7
+ readonly variables: Readonly<Record<string, unknown>>;
8
+ readonly runDir?: string | undefined;
9
+ readonly debugKeepArtifacts?: boolean | undefined;
10
+ }
11
+ export interface ResumeWorkflowStateOptions {
12
+ readonly runId: string;
13
+ readonly runDir?: string | undefined;
14
+ readonly debugKeepArtifacts?: boolean | undefined;
15
+ }
16
+ export declare class WorkflowStateStore {
17
+ readonly runDir: string;
18
+ readonly definition: NormalizedWorkflowDefinition;
19
+ readonly variables: Readonly<Record<string, unknown>>;
20
+ readonly hooks: EngineHooks;
21
+ readonly resume: EngineResumeState;
22
+ private state;
23
+ private readonly lockPath;
24
+ private readonly debugKeepArtifacts;
25
+ private writeChain;
26
+ private lockHeld;
27
+ private constructor();
28
+ static create(options: CreateWorkflowStateOptions): Promise<WorkflowStateStore>;
29
+ static resume(options: ResumeWorkflowStateOptions): Promise<WorkflowStateStore>;
30
+ get runState(): RunState;
31
+ markCancelled(reason?: string): Promise<void>;
32
+ flush(): Promise<void>;
33
+ close(): Promise<void>;
34
+ private applyRetryUpdate;
35
+ private enqueueWrite;
36
+ private writeState;
37
+ }