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,216 @@
1
+ /**
2
+ * Clink client wrapper for clinkx-workflows.
3
+ *
4
+ * Provides callClink() — the typed interface for calling the child's
5
+ * clink tool and parsing its response into output_text + debug_metadata.
6
+ *
7
+ * Key behaviors:
8
+ * - Always sets debug: true on internal calls
9
+ * - Parses MCP text content blocks robustly (no positional assumptions)
10
+ * - Strips host _meta.progressToken from child calls (progress isolation)
11
+ * - Maps child -32602 to InvalidCallError
12
+ * - Maps child isError: true to CallExecutionError
13
+ * - Only output_text is stored/threaded/hashed
14
+ */
15
+ import { InvalidCallError, CallExecutionError } from "./errors.js";
16
+ import { logger } from "./logger.js";
17
+ import { basename } from "node:path";
18
+ /**
19
+ * Build the tool arguments for a child clink call.
20
+ *
21
+ * Ensures debug: true is always set and strips any _meta.progressToken
22
+ * to prevent child from emitting progress to the host.
23
+ */
24
+ export function buildCallArgs(input) {
25
+ // Clone to avoid mutating caller's input
26
+ const args = { ...input };
27
+ // Always enable debug for internal calls
28
+ args["debug"] = true;
29
+ // Strip host _meta.progressToken (1-11a: progress isolation)
30
+ if (args["_meta"] != null && typeof args["_meta"] === "object") {
31
+ const meta = { ...args["_meta"] };
32
+ delete meta["progressToken"];
33
+ // Only keep _meta if it still has keys
34
+ if (Object.keys(meta).length > 0) {
35
+ args["_meta"] = meta;
36
+ }
37
+ else {
38
+ delete args["_meta"];
39
+ }
40
+ }
41
+ return args;
42
+ }
43
+ /**
44
+ * Parse the MCP tool call result into output_text and debug_metadata.
45
+ *
46
+ * Does NOT assume positional ordering — scans all text content blocks
47
+ * and identifies the _debug block by JSON-parsing each one.
48
+ */
49
+ export function parseCallResult(result) {
50
+ const textBlocks = [];
51
+ let debugMetadata = null;
52
+ if (result.content != null) {
53
+ for (const block of result.content) {
54
+ if (block.type === "text" && block.text != null) {
55
+ // Try to identify _debug block
56
+ const text = block.text.trim();
57
+ if (debugMetadata == null && text.startsWith("{")) {
58
+ try {
59
+ const parsed = JSON.parse(text);
60
+ if ("_debug" in parsed && typeof parsed["_debug"] === "object") {
61
+ debugMetadata = parsed["_debug"];
62
+ continue; // Don't include _debug block in output_text
63
+ }
64
+ }
65
+ catch {
66
+ // Not JSON or not _debug — treat as output text
67
+ }
68
+ }
69
+ textBlocks.push(block.text);
70
+ }
71
+ }
72
+ }
73
+ return {
74
+ outputText: textBlocks.join(""),
75
+ debugMetadata,
76
+ };
77
+ }
78
+ function sanitizeDebugMetadataForLog(debug) {
79
+ if (debug == null)
80
+ return null;
81
+ if (typeof debug["adapter_config_path"] !== "string")
82
+ return debug;
83
+ return {
84
+ ...debug,
85
+ adapter_config_path: basename(debug["adapter_config_path"]),
86
+ };
87
+ }
88
+ /**
89
+ * Call the child's clink tool and return parsed output.
90
+ *
91
+ * @param session - Active ClinkBackend
92
+ * @param input - Tool input arguments (ClinkInput shape)
93
+ * @param signal - Optional AbortSignal for cancellation
94
+ * @param context - Stage/call context for error attribution
95
+ * @returns Parsed clink call result
96
+ * @throws InvalidCallError on child -32602
97
+ * @throws CallExecutionError on child isError: true
98
+ */
99
+ export async function callClink(session, input, signal, context, timeoutMs) {
100
+ const args = buildCallArgs(input);
101
+ const stageId = context?.stageId ?? "unknown";
102
+ const callId = context?.callId ?? "unknown";
103
+ let result;
104
+ try {
105
+ result = await session.callTool(args, signal != null || timeoutMs != null
106
+ ? {
107
+ ...(signal != null ? { signal } : {}),
108
+ ...(timeoutMs != null ? { timeoutMs } : {}),
109
+ }
110
+ : undefined);
111
+ }
112
+ catch (err) {
113
+ // Check for MCP -32602 (InvalidParams) error from child
114
+ if (isMcpInvalidParams(err)) {
115
+ throw new InvalidCallError(`Child rejected call as invalid: ${err instanceof Error ? err.message : String(err)}`, stageId, callId);
116
+ }
117
+ throw err;
118
+ }
119
+ // Map child isError: true to CallExecutionError
120
+ if (result.isError === true) {
121
+ const parsed = parseCallResult(result);
122
+ const failureClass = classifyFailure(parsed.debugMetadata);
123
+ const childDebugMetadata = extractChildFailureMetadata(parsed.debugMetadata);
124
+ // Fallback: if pipeline missed the panic class (e.g. wrapper formatting
125
+ // differences), detect the codex-local crash signature in output text.
126
+ let effectiveFailureClass = failureClass;
127
+ let effectiveChildDebugMetadata = childDebugMetadata;
128
+ if (failureClass === "permanent" && parsed.outputText != null) {
129
+ const codexLocalMatch = parsed.outputText.match(/\[codex-local\]:?\s*Local Codex process failed(?::\s*Process exited with code:\s*(\d+))?/);
130
+ if (codexLocalMatch != null) {
131
+ const exitCode = codexLocalMatch[1] != null ? Number(codexLocalMatch[1]) : null;
132
+ const synthesizedClass = exitCode === 101 ? "codex_local_rust_panic" : "codex_local_crash";
133
+ if (TRANSIENT_PANIC_CLASSES.has(synthesizedClass)) {
134
+ effectiveFailureClass = "transient";
135
+ logger.info({ stage_id: stageId, call_id: callId, synthesized_panic_class: synthesizedClass }, "reclassified failure as transient via output-text fallback");
136
+ // Synthesize into childDebugMetadata (readonly fields — create new object)
137
+ if (effectiveChildDebugMetadata != null) {
138
+ effectiveChildDebugMetadata = { ...effectiveChildDebugMetadata, codex_panic_class: synthesizedClass };
139
+ }
140
+ else {
141
+ effectiveChildDebugMetadata = { codex_panic_class: synthesizedClass };
142
+ }
143
+ }
144
+ }
145
+ }
146
+ logger.warn({
147
+ stage_id: stageId,
148
+ call_id: callId,
149
+ failure_class: failureClass,
150
+ effective_failure_class: effectiveFailureClass,
151
+ debug: sanitizeDebugMetadataForLog(parsed.debugMetadata),
152
+ }, "child clink call returned isError");
153
+ throw new CallExecutionError(parsed.outputText || "Child clink call failed", stageId, callId, effectiveFailureClass, effectiveChildDebugMetadata);
154
+ }
155
+ return parseCallResult(result);
156
+ }
157
+ /**
158
+ * Panic classes confirmed as transient (retryable). Only classes with strong
159
+ * evidence of being transport-layer failures belong here. `codex_local_crash`
160
+ * is deliberately excluded — a generic wrapper exit may indicate a permanent
161
+ * failure (OOM, config error, sandbox violation).
162
+ */
163
+ const TRANSIENT_PANIC_CLASSES = new Set([
164
+ "stdout_would_block",
165
+ "stdout_broken_pipe",
166
+ "stdout_write_failure",
167
+ "codex_local_rust_panic",
168
+ ]);
169
+ /**
170
+ * Classify a child failure as transient or permanent based on _debug metadata.
171
+ */
172
+ function classifyFailure(debug) {
173
+ if (debug == null)
174
+ return "permanent";
175
+ const reason = debug["termination_reason"];
176
+ if (reason === "wall" || reason === "idle")
177
+ return "transient";
178
+ const panicClass = debug["codex_panic_class"];
179
+ if (typeof panicClass === "string" && TRANSIENT_PANIC_CLASSES.has(panicClass)) {
180
+ return "transient";
181
+ }
182
+ const exitCode = debug["exit_code"];
183
+ if (exitCode === null || exitCode === undefined)
184
+ return "transient";
185
+ return "permanent";
186
+ }
187
+ /**
188
+ * Extract structured failure metadata from the child's _debug block.
189
+ */
190
+ function extractChildFailureMetadata(debug) {
191
+ if (debug == null)
192
+ return undefined;
193
+ const meta = {
194
+ rejection_reason: typeof debug["rejection_reason"] === "string" ? debug["rejection_reason"] : undefined,
195
+ parse_status: typeof debug["parse_status"] === "string" ? debug["parse_status"] : undefined,
196
+ parse_source: typeof debug["parse_source"] === "string" ? debug["parse_source"] : undefined,
197
+ adapter_config_path: typeof debug["adapter_config_path"] === "string" ? debug["adapter_config_path"] : undefined,
198
+ exit_code: typeof debug["exit_code"] === "number" || debug["exit_code"] === null ? debug["exit_code"] : undefined,
199
+ codex_panic_class: typeof debug["codex_panic_class"] === "string" ? debug["codex_panic_class"] : undefined,
200
+ };
201
+ // Only return if at least one field is present
202
+ const hasContent = meta.rejection_reason != null || meta.parse_status != null ||
203
+ meta.parse_source != null || meta.adapter_config_path != null || meta.exit_code !== undefined ||
204
+ meta.codex_panic_class != null;
205
+ return hasContent ? meta : undefined;
206
+ }
207
+ /**
208
+ * Check if an error is an MCP -32602 (InvalidParams) error.
209
+ */
210
+ function isMcpInvalidParams(err) {
211
+ if (err == null || typeof err !== "object")
212
+ return false;
213
+ const code = err["code"];
214
+ return code === -32602;
215
+ }
216
+ //# sourceMappingURL=clink-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clink-client.js","sourceRoot":"","sources":["../src/clink-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAA6B,MAAM,aAAa,CAAC;AAC9F,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAWrC;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAC3B,KAA8B;IAE9B,yCAAyC;IACzC,MAAM,IAAI,GAA4B,EAAE,GAAG,KAAK,EAAE,CAAC;IAEnD,yCAAyC;IACzC,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;IAErB,6DAA6D;IAC7D,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,IAAI,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;QAC/D,MAAM,IAAI,GAAG,EAAE,GAAI,IAAI,CAAC,OA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AC,CAAC,CAAC,SAAS;KAC3G,CAAC;IAEF,+CAA+C;IAC/C,MAAM,UAAU,GAAG,IAAI,CAAC,gBAAgB,IAAI,IAAI,IAAI,IAAI,CAAC,YAAY,IAAI,IAAI;QAC3E,IAAI,CAAC,YAAY,IAAI,IAAI,IAAI,IAAI,CAAC,mBAAmB,IAAI,IAAI,IAAI,IAAI,CAAC,SAAS,KAAK,SAAS;QAC7F,IAAI,CAAC,iBAAiB,IAAI,IAAI,CAAC;IACjC,OAAO,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;AACvC,CAAC;AAED;;GAEG;AACH,SAAS,kBAAkB,CAAC,GAAY;IACtC,IAAI,GAAG,IAAI,IAAI,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACzD,MAAM,IAAI,GAAI,GAA+B,CAAC,MAAM,CAAC,CAAC;IACtD,OAAO,IAAI,KAAK,CAAC,KAAK,CAAC;AACzB,CAAC"}
@@ -0,0 +1,126 @@
1
+ /**
2
+ * Environment variable definitions and defaults for clinkx-workflows.
3
+ *
4
+ * All workflow-server env vars use the CLINKX_WORKFLOWS_* prefix.
5
+ * Child env vars (CLINKX_*) are scrubbed from the child process environment
6
+ * and re-injected only with explicit workflow-owned values.
7
+ *
8
+ * ## Real vs Dead Knobs (child env)
9
+ *
10
+ * REAL controls (child env CAN control these):
11
+ * - CLINKX_MAX_CONCURRENT: fail-fast semaphore depth (concurrency.ts:3,25-29)
12
+ * - CLINKX_MAX_RESPONSE_CHARS: output truncation ceiling (pipeline.ts env fallback)
13
+ * - CLINKX_MAX_OUTPUT_BYTES: per-stream capture cap (runner.ts::createStreamCapture)
14
+ * - CLINKX_MAX_PROMPT_BYTES: pre-dispatch prompt ceiling (runner.ts)
15
+ * - CLINKX_CONFIG_PATH: adapter config path override
16
+ * - CLINKX_ALLOWED_ROOTS: comma-separated allowed path prefixes
17
+ * - CLINKX_LOG_LEVEL: pino log verbosity
18
+ *
19
+ * DEAD knobs (adapter JSON wins, env has no effect with current shipped adapters):
20
+ * - CLINKX_TIMEOUT_SECONDS: both shipped adapters set timeout_seconds in JSON
21
+ * (codex.json:9 = 3600, claude.json:8 = 3600). Adapter config wins per runner.ts:156-159.
22
+ * - CLINKX_IDLE_TIMEOUT_SECONDS: both shipped adapters set idle_timeout_seconds in JSON.
23
+ * Adapter config wins per runner.ts:164-167.
24
+ * - CLINKX_IDLE_TIMEOUT_STARTUP_SECONDS: both shipped adapters set idle_timeout_startup_seconds.
25
+ * Adapter config wins per runner.ts:168-171. Additionally, result_contract.enabled forces
26
+ * both idle timers to 0 (runner.ts:163-170).
27
+ */
28
+ /** Resolve workspace root: explicit env > process.cwd() with warning. */
29
+ export declare function resolveWorkspaceRoot(): string;
30
+ /** Whether workspace root was explicitly configured. */
31
+ export declare function hasExplicitWorkspaceRoot(): boolean;
32
+ /**
33
+ * Derive CLINKX_ALLOWED_ROOTS for the child process.
34
+ * Union of resolved workspace root + workflow state/artifact roots.
35
+ * Rejects filesystem root (/) as workspace root.
36
+ */
37
+ export declare function deriveAllowedRoots(workspaceRoot: string, stateDir: string, artifactsDir: string): string;
38
+ /** Command to spawn the owned ClinkX child. */
39
+ export declare function getClinkxCmd(): string;
40
+ /** Workflow definition directory. */
41
+ export declare function getWorkflowsPath(): string;
42
+ /** Prompt template root directory (resolved relative to package root). */
43
+ export declare function getTemplatesPath(): string;
44
+ /** Upper bound for concurrent calls within a parallel stage. */
45
+ export declare function getMaxParallel(): number;
46
+ /** Passed to child as CLINKX_MAX_CONCURRENT. */
47
+ export declare function getChildMaxConcurrent(): number;
48
+ /** Passed to child as CLINKX_MAX_RESPONSE_CHARS (200k to avoid silent context truncation). */
49
+ export declare function getChildMaxResponseChars(): number;
50
+ /** Passed to child as CLINKX_MAX_OUTPUT_BYTES. */
51
+ export declare function getChildMaxOutputBytes(): number;
52
+ /** Passed to child as CLINKX_MAX_PROMPT_BYTES. */
53
+ export declare function getChildMaxPromptBytes(): number;
54
+ /** Optional workflow-owned child adapter bundle path. */
55
+ export declare function getChildConfigPath(): string | undefined;
56
+ /**
57
+ * Default workflow-level timeout (seconds).
58
+ *
59
+ * This is the hard wall clock ceiling for an entire workflow run. The engine
60
+ * creates an AbortController with this deadline; when exceeded, remaining
61
+ * stages are aborted. Overridden by `settings.timeout_seconds` in the
62
+ * workflow definition.
63
+ *
64
+ * This is the workflow-server-level timeout (Layer 1 in the timeout ownership
65
+ * model). It is distinct from:
66
+ * - Per-call timeout_seconds in workflow definitions (Layer 2, upward extension only)
67
+ * - Child-side adapter timeouts in adapter JSON (Layer 3, adapter-owned)
68
+ *
69
+ * See engine.ts module comment for the full timeout ownership model.
70
+ */
71
+ export declare function getWorkflowTimeout(): number;
72
+ /** Pre-dispatch UTF-8 prompt/context ceiling (bytes). */
73
+ export declare function getMaxPromptBytes(): number;
74
+ /** Workflow server log level. */
75
+ export declare function getLogLevel(): string;
76
+ /** Persistent workflow state directory. */
77
+ export declare function getStateDir(): string;
78
+ /** Base directory containing persistent run state directories. */
79
+ export declare function getRunsDir(): string;
80
+ /** Persistent state directory for a specific run. */
81
+ export declare function getRunStateDir(runId: string): string;
82
+ /** Disposable per-run artifacts directory. */
83
+ export declare function getArtifactsDir(): string;
84
+ /**
85
+ * CLINKX_* env vars to scrub from child process environment before re-injection.
86
+ * All CLINKX_* vars are scrubbed; only explicit workflow-owned values are re-injected.
87
+ */
88
+ export declare const CHILD_ENV_SCRUB_PREFIX = "CLINKX_";
89
+ /**
90
+ * Config-discovery vars to also scrub (prevent child from inheriting parent's
91
+ * config resolution path, which would bypass workflow-owned adapter bundles).
92
+ */
93
+ export declare const CHILD_ENV_SCRUB_EXTRA: readonly ["XDG_CONFIG_HOME"];
94
+ /**
95
+ * Child env vars that are re-injected with workflow-owned values.
96
+ * Maps from workflow config key to child env var name.
97
+ */
98
+ export declare const CHILD_ENV_REINJECT_MAP: {
99
+ readonly maxConcurrent: "CLINKX_MAX_CONCURRENT";
100
+ readonly maxResponseChars: "CLINKX_MAX_RESPONSE_CHARS";
101
+ readonly maxOutputBytes: "CLINKX_MAX_OUTPUT_BYTES";
102
+ readonly maxPromptBytes: "CLINKX_MAX_PROMPT_BYTES";
103
+ readonly configPath: "CLINKX_CONFIG_PATH";
104
+ readonly allowedRoots: "CLINKX_ALLOWED_ROOTS";
105
+ readonly logLevel: "CLINKX_LOG_LEVEL";
106
+ };
107
+ /**
108
+ * Baseline OS env vars that are NEVER scrubbed from child.
109
+ * ClinkX's internal env.ts::buildEnv handles delegate subprocess sanitization.
110
+ */
111
+ export declare const CHILD_ENV_BASELINE: readonly ["PATH", "HOME", "USER", "LANG", "TMPDIR"];
112
+ /**
113
+ * DEAD KNOBS: these env vars have no effect with current shipped adapters
114
+ * because adapter JSON config wins (runner.ts:156-171). Both shipped adapters
115
+ * set timeout_seconds in JSON (codex.json:9 = 3600, claude.json:8 = 3600).
116
+ *
117
+ * These are Layer 3 (child-side) timeout controls. The workflow engine does
118
+ * NOT attempt to control child-side timeouts via env vars. Instead, use
119
+ * CLINKX_WORKFLOWS_CHILD_CONFIG_PATH to point at a workflow-specific adapter
120
+ * bundle with the desired timeout floors.
121
+ *
122
+ * See engine.ts module comment for the full timeout ownership model.
123
+ *
124
+ * Do NOT set these in the child env — they create a false sense of control.
125
+ */
126
+ export declare const DEAD_KNOBS: readonly ["CLINKX_TIMEOUT_SECONDS", "CLINKX_IDLE_TIMEOUT_SECONDS", "CLINKX_IDLE_TIMEOUT_STARTUP_SECONDS"];
@@ -0,0 +1,226 @@
1
+ /**
2
+ * Environment variable definitions and defaults for clinkx-workflows.
3
+ *
4
+ * All workflow-server env vars use the CLINKX_WORKFLOWS_* prefix.
5
+ * Child env vars (CLINKX_*) are scrubbed from the child process environment
6
+ * and re-injected only with explicit workflow-owned values.
7
+ *
8
+ * ## Real vs Dead Knobs (child env)
9
+ *
10
+ * REAL controls (child env CAN control these):
11
+ * - CLINKX_MAX_CONCURRENT: fail-fast semaphore depth (concurrency.ts:3,25-29)
12
+ * - CLINKX_MAX_RESPONSE_CHARS: output truncation ceiling (pipeline.ts env fallback)
13
+ * - CLINKX_MAX_OUTPUT_BYTES: per-stream capture cap (runner.ts::createStreamCapture)
14
+ * - CLINKX_MAX_PROMPT_BYTES: pre-dispatch prompt ceiling (runner.ts)
15
+ * - CLINKX_CONFIG_PATH: adapter config path override
16
+ * - CLINKX_ALLOWED_ROOTS: comma-separated allowed path prefixes
17
+ * - CLINKX_LOG_LEVEL: pino log verbosity
18
+ *
19
+ * DEAD knobs (adapter JSON wins, env has no effect with current shipped adapters):
20
+ * - CLINKX_TIMEOUT_SECONDS: both shipped adapters set timeout_seconds in JSON
21
+ * (codex.json:9 = 3600, claude.json:8 = 3600). Adapter config wins per runner.ts:156-159.
22
+ * - CLINKX_IDLE_TIMEOUT_SECONDS: both shipped adapters set idle_timeout_seconds in JSON.
23
+ * Adapter config wins per runner.ts:164-167.
24
+ * - CLINKX_IDLE_TIMEOUT_STARTUP_SECONDS: both shipped adapters set idle_timeout_startup_seconds.
25
+ * Adapter config wins per runner.ts:168-171. Additionally, result_contract.enabled forces
26
+ * both idle timers to 0 (runner.ts:163-170).
27
+ */
28
+ import { realpathSync } from "node:fs";
29
+ import { join, resolve } from "node:path";
30
+ // ---------------------------------------------------------------------------
31
+ // Workflow server env vars (CLINKX_WORKFLOWS_*)
32
+ // ---------------------------------------------------------------------------
33
+ function envStr(key, fallback) {
34
+ const v = process.env[key];
35
+ return v != null && v !== "" ? v : fallback;
36
+ }
37
+ function envInt(key, fallback) {
38
+ const v = process.env[key];
39
+ if (v == null || v === "")
40
+ return fallback;
41
+ const n = Number(v);
42
+ return Number.isFinite(n) && n > 0 ? n : fallback;
43
+ }
44
+ /** Resolve workspace root: explicit env > process.cwd() with warning. */
45
+ export function resolveWorkspaceRoot() {
46
+ const explicit = process.env["CLINKX_WORKFLOWS_WORKSPACE_ROOT"];
47
+ if (explicit != null && explicit !== "") {
48
+ try {
49
+ return realpathSync(resolve(explicit));
50
+ }
51
+ catch {
52
+ return resolve(explicit);
53
+ }
54
+ }
55
+ // Fallback with warning — caller should log this
56
+ return resolve(process.cwd());
57
+ }
58
+ /** Whether workspace root was explicitly configured. */
59
+ export function hasExplicitWorkspaceRoot() {
60
+ const v = process.env["CLINKX_WORKFLOWS_WORKSPACE_ROOT"];
61
+ return v != null && v !== "";
62
+ }
63
+ /**
64
+ * Derive CLINKX_ALLOWED_ROOTS for the child process.
65
+ * Union of resolved workspace root + workflow state/artifact roots.
66
+ * Rejects filesystem root (/) as workspace root.
67
+ */
68
+ export function deriveAllowedRoots(workspaceRoot, stateDir, artifactsDir) {
69
+ const roots = [workspaceRoot, stateDir, artifactsDir];
70
+ return roots.join(",");
71
+ }
72
+ // ---------------------------------------------------------------------------
73
+ // Config accessors
74
+ // ---------------------------------------------------------------------------
75
+ /** Command to spawn the owned ClinkX child. */
76
+ export function getClinkxCmd() {
77
+ return envStr("CLINKX_WORKFLOWS_CLINKX_CMD", "clinkx");
78
+ }
79
+ /**
80
+ * Resolve a path relative to the package root (two levels up from dist/src/).
81
+ * If the path is absolute, return as-is.
82
+ */
83
+ function resolvePackageRelative(raw) {
84
+ if (raw.startsWith("/")) {
85
+ return raw;
86
+ }
87
+ const packageRoot = resolve(import.meta.dirname, "..");
88
+ return resolve(packageRoot, raw);
89
+ }
90
+ /** Workflow definition directory. */
91
+ export function getWorkflowsPath() {
92
+ return envStr("CLINKX_WORKFLOWS_PATH", "workflows/");
93
+ }
94
+ /** Prompt template root directory (resolved relative to package root). */
95
+ export function getTemplatesPath() {
96
+ return resolvePackageRelative(envStr("CLINKX_WORKFLOWS_TEMPLATES_PATH", "templates/"));
97
+ }
98
+ /** Upper bound for concurrent calls within a parallel stage. */
99
+ export function getMaxParallel() {
100
+ return envInt("CLINKX_WORKFLOWS_MAX_PARALLEL", 5);
101
+ }
102
+ /** Passed to child as CLINKX_MAX_CONCURRENT. */
103
+ export function getChildMaxConcurrent() {
104
+ return envInt("CLINKX_WORKFLOWS_CHILD_MAX_CONCURRENT", 5);
105
+ }
106
+ /** Passed to child as CLINKX_MAX_RESPONSE_CHARS (200k to avoid silent context truncation). */
107
+ export function getChildMaxResponseChars() {
108
+ return envInt("CLINKX_WORKFLOWS_CHILD_MAX_RESPONSE_CHARS", 200_000);
109
+ }
110
+ /** Passed to child as CLINKX_MAX_OUTPUT_BYTES. */
111
+ export function getChildMaxOutputBytes() {
112
+ return envInt("CLINKX_WORKFLOWS_CHILD_MAX_OUTPUT_BYTES", 10_485_760);
113
+ }
114
+ /** Passed to child as CLINKX_MAX_PROMPT_BYTES. */
115
+ export function getChildMaxPromptBytes() {
116
+ return envInt("CLINKX_WORKFLOWS_CHILD_MAX_PROMPT_BYTES", 1_048_576);
117
+ }
118
+ /** Optional workflow-owned child adapter bundle path. */
119
+ export function getChildConfigPath() {
120
+ const v = process.env["CLINKX_WORKFLOWS_CHILD_CONFIG_PATH"];
121
+ return v != null && v !== "" ? v : undefined;
122
+ }
123
+ /**
124
+ * Default workflow-level timeout (seconds).
125
+ *
126
+ * This is the hard wall clock ceiling for an entire workflow run. The engine
127
+ * creates an AbortController with this deadline; when exceeded, remaining
128
+ * stages are aborted. Overridden by `settings.timeout_seconds` in the
129
+ * workflow definition.
130
+ *
131
+ * This is the workflow-server-level timeout (Layer 1 in the timeout ownership
132
+ * model). It is distinct from:
133
+ * - Per-call timeout_seconds in workflow definitions (Layer 2, upward extension only)
134
+ * - Child-side adapter timeouts in adapter JSON (Layer 3, adapter-owned)
135
+ *
136
+ * See engine.ts module comment for the full timeout ownership model.
137
+ */
138
+ export function getWorkflowTimeout() {
139
+ return envInt("CLINKX_WORKFLOWS_TIMEOUT_SECONDS", 1800);
140
+ }
141
+ /** Pre-dispatch UTF-8 prompt/context ceiling (bytes). */
142
+ export function getMaxPromptBytes() {
143
+ return envInt("CLINKX_WORKFLOWS_MAX_PROMPT_BYTES", 900_000);
144
+ }
145
+ /** Workflow server log level. */
146
+ export function getLogLevel() {
147
+ return envStr("CLINKX_WORKFLOWS_LOG_LEVEL", "info");
148
+ }
149
+ /** Persistent workflow state directory. */
150
+ export function getStateDir() {
151
+ const xdgState = process.env["XDG_STATE_HOME"];
152
+ const defaultBase = xdgState != null && xdgState !== ""
153
+ ? xdgState
154
+ : `${process.env["HOME"] ?? "~"}/.local/state`;
155
+ return envStr("CLINKX_WORKFLOWS_STATE_DIR", `${defaultBase}/clinkx-workflows`);
156
+ }
157
+ /** Base directory containing persistent run state directories. */
158
+ export function getRunsDir() {
159
+ return join(getStateDir(), "runs");
160
+ }
161
+ /** Persistent state directory for a specific run. */
162
+ export function getRunStateDir(runId) {
163
+ return join(getRunsDir(), runId);
164
+ }
165
+ /** Disposable per-run artifacts directory. */
166
+ export function getArtifactsDir() {
167
+ const tmpdir = process.env["TMPDIR"] ?? "/tmp";
168
+ return envStr("CLINKX_WORKFLOWS_ARTIFACTS_DIR", `${tmpdir}/clinkx-workflows/artifacts`);
169
+ }
170
+ // ---------------------------------------------------------------------------
171
+ // Child env scrub/reinject constants
172
+ // ---------------------------------------------------------------------------
173
+ /**
174
+ * CLINKX_* env vars to scrub from child process environment before re-injection.
175
+ * All CLINKX_* vars are scrubbed; only explicit workflow-owned values are re-injected.
176
+ */
177
+ export const CHILD_ENV_SCRUB_PREFIX = "CLINKX_";
178
+ /**
179
+ * Config-discovery vars to also scrub (prevent child from inheriting parent's
180
+ * config resolution path, which would bypass workflow-owned adapter bundles).
181
+ */
182
+ export const CHILD_ENV_SCRUB_EXTRA = ["XDG_CONFIG_HOME"];
183
+ /**
184
+ * Child env vars that are re-injected with workflow-owned values.
185
+ * Maps from workflow config key to child env var name.
186
+ */
187
+ export const CHILD_ENV_REINJECT_MAP = {
188
+ maxConcurrent: "CLINKX_MAX_CONCURRENT",
189
+ maxResponseChars: "CLINKX_MAX_RESPONSE_CHARS",
190
+ maxOutputBytes: "CLINKX_MAX_OUTPUT_BYTES",
191
+ maxPromptBytes: "CLINKX_MAX_PROMPT_BYTES",
192
+ configPath: "CLINKX_CONFIG_PATH",
193
+ allowedRoots: "CLINKX_ALLOWED_ROOTS",
194
+ logLevel: "CLINKX_LOG_LEVEL",
195
+ };
196
+ /**
197
+ * Baseline OS env vars that are NEVER scrubbed from child.
198
+ * ClinkX's internal env.ts::buildEnv handles delegate subprocess sanitization.
199
+ */
200
+ export const CHILD_ENV_BASELINE = [
201
+ "PATH",
202
+ "HOME",
203
+ "USER",
204
+ "LANG",
205
+ "TMPDIR",
206
+ ];
207
+ /**
208
+ * DEAD KNOBS: these env vars have no effect with current shipped adapters
209
+ * because adapter JSON config wins (runner.ts:156-171). Both shipped adapters
210
+ * set timeout_seconds in JSON (codex.json:9 = 3600, claude.json:8 = 3600).
211
+ *
212
+ * These are Layer 3 (child-side) timeout controls. The workflow engine does
213
+ * NOT attempt to control child-side timeouts via env vars. Instead, use
214
+ * CLINKX_WORKFLOWS_CHILD_CONFIG_PATH to point at a workflow-specific adapter
215
+ * bundle with the desired timeout floors.
216
+ *
217
+ * See engine.ts module comment for the full timeout ownership model.
218
+ *
219
+ * Do NOT set these in the child env — they create a false sense of control.
220
+ */
221
+ export const DEAD_KNOBS = [
222
+ "CLINKX_TIMEOUT_SECONDS",
223
+ "CLINKX_IDLE_TIMEOUT_SECONDS",
224
+ "CLINKX_IDLE_TIMEOUT_STARTUP_SECONDS",
225
+ ];
226
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE1C,8EAA8E;AAC9E,gDAAgD;AAChD,8EAA8E;AAE9E,SAAS,MAAM,CAAC,GAAW,EAAE,QAAgB;IAC3C,MAAM,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,C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C,OAAO,IAAI,CAAC,UAAU,EAAE,EAAE,KAAK,CAAC,CAAC;AACnC,CAAC;AAED,8CAA8C;AAC9C,MAAM,UAAU,eAAe;IAC7B,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC;IAC/C,OAAO,MAAM,CAAC,gCAAgC,EAAE,GAAG,MAAM,6BAA6B,CAAC,CAAC;AAC1F,CAAC;AAED,8EAA8E;AAC9E,qCAAqC;AACrC,8EAA8E;AAE9E;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,SAAS,CAAC;AAEhD;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,iBAAiB,CAAU,CAAC;AAElE;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,aAAa,EAAE,uBAAuB;IACtC,gBAAgB,EAAE,2BAA2B;IAC7C,cAAc,EAAE,yBAAyB;IACzC,cAAc,EAAE,yBAAyB;IACzC,UAAU,EAAE,oBAAoB;IAChC,YAAY,EAAE,sBAAsB;IACpC,QAAQ,EAAE,kBAAkB;CACpB,CAAC;AAEX;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,QAAQ;CACA,CAAC;AAEX;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,wBAAwB;IACxB,6BAA6B;IAC7B,qCAAqC;CAC7B,CAAC"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Snapshot normalization for clinkx-workflows (2-10a).
3
+ *
4
+ * Normalizes a loaded workflow definition into snapshot-ready form:
5
+ * - Inlines template text (not just hashes) — hash-only snapshots can't reconstruct for resume
6
+ * - Includes template content hashes alongside inlined text
7
+ */
8
+ import type { WorkflowDefinition, Call } from "./schema.js";
9
+ /** A call with prompt_template resolved to inlined text + hash. */
10
+ export interface NormalizedCall extends Omit<Call, "prompt_template"> {
11
+ /** Always present after normalization — either original prompt or inlined template. */
12
+ readonly prompt: string;
13
+ /** Removed after normalization — replaced by inlined prompt. */
14
+ readonly prompt_template?: undefined;
15
+ /** Present only if the original call used prompt_template. */
16
+ readonly template_hash?: string | undefined;
17
+ /** Original template path, preserved for diagnostics. */
18
+ readonly template_path?: string | undefined;
19
+ /** Built-in reducer function ID. When set, this call runs a deterministic function instead of an LLM. */
20
+ readonly reducer?: string | undefined;
21
+ /** If true, upstream context artifacts are aliased to prevent identity leakage. */
22
+ readonly anonymize_context?: boolean | undefined;
23
+ }
24
+ export interface NormalizedStage {
25
+ readonly id: string;
26
+ readonly description?: string | undefined;
27
+ readonly parallel: boolean;
28
+ readonly retry: Call extends {
29
+ retry: infer R;
30
+ } ? R : {
31
+ readonly mode: "transport_only" | "all";
32
+ readonly max_retries: number;
33
+ readonly backoff_seconds: number;
34
+ readonly max_backoff_seconds: number;
35
+ };
36
+ readonly on_failure: "abort" | "continue";
37
+ readonly calls: readonly NormalizedCall[];
38
+ }
39
+ export interface NormalizedWorkflowDefinition {
40
+ readonly name: string;
41
+ readonly description: string;
42
+ readonly version: string;
43
+ readonly stages: readonly NormalizedStage[];
44
+ readonly variables: WorkflowDefinition["variables"];
45
+ readonly settings: WorkflowDefinition["settings"];
46
+ }
47
+ /**
48
+ * Normalize a workflow definition by inlining all template text.
49
+ *
50
+ * @param definition - Parsed and validated workflow definition
51
+ * @param templates - Map of template path → template content (from resolveAllTemplates)
52
+ * @returns Normalized definition with all prompts inlined
53
+ */
54
+ export declare function normalizeDefinition(definition: WorkflowDefinition, templates: ReadonlyMap<string, string>): NormalizedWorkflowDefinition;
55
+ /**
56
+ * Snapshot-facing alias used by the execution engine and future persistence work.
57
+ * The normalized definition is already snapshot-ready because template text is inlined.
58
+ */
59
+ export declare function normalizeForSnapshot(definition: WorkflowDefinition, templates: ReadonlyMap<string, string>): NormalizedWorkflowDefinition;