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,65 @@
1
+ /**
2
+ * Artifact storage and ordered context threading.
3
+ */
4
+ import type { NormalizedWorkflowDefinition, NormalizedStage, NormalizedCall } from "./definition-normalizer.js";
5
+ import type { PromptBudgetContributor } from "./prompt-budget.js";
6
+ import type { ValidatorRegistry } from "./validators/index.js";
7
+ export interface ValidatedJsonOutput {
8
+ readonly parsed: unknown;
9
+ readonly serialized: string;
10
+ readonly sizeBytes: number;
11
+ }
12
+ export interface ArtifactRecord {
13
+ readonly stageId: string;
14
+ readonly callId: string;
15
+ readonly reference: string;
16
+ readonly filePath: string;
17
+ readonly filename: string;
18
+ readonly sizeBytes: number;
19
+ readonly parsed: unknown;
20
+ }
21
+ export interface OmittedArtifactRecord {
22
+ readonly stageId: string;
23
+ readonly callId: string;
24
+ readonly reference: string;
25
+ readonly reason: string;
26
+ }
27
+ export interface ContextArtifacts {
28
+ readonly absoluteFilePaths: readonly string[];
29
+ readonly context: string | undefined;
30
+ readonly contributors: readonly PromptBudgetContributor[];
31
+ readonly artifacts: readonly ArtifactRecord[];
32
+ readonly omissions: readonly OmittedArtifactRecord[];
33
+ }
34
+ /**
35
+ * Recursively strip keys ending in `_id` from a parsed JSON structure
36
+ * to prevent identity leakage in anonymized context.
37
+ * Objects: strip `_id` keys, recurse into remaining values.
38
+ * Arrays: recurse into each element.
39
+ * Primitives: return as-is.
40
+ */
41
+ export declare function stripIdentityFields(parsed: unknown): unknown;
42
+ export declare class ArtifactStore {
43
+ private readonly runDir;
44
+ private readonly validatorRegistry;
45
+ private readonly artifactRoot;
46
+ private readonly artifactsByReference;
47
+ private readonly omissionsByReference;
48
+ constructor(runDir: string, validatorRegistry: ValidatorRegistry);
49
+ get artifactsDir(): string;
50
+ validateJsonOutput(stageId: string, callId: string, validatorSchemaId: string, outputText: string): ValidatedJsonOutput;
51
+ writeCallArtifact(options: {
52
+ readonly stage: NormalizedStage;
53
+ readonly call: NormalizedCall;
54
+ readonly stageIndex: number;
55
+ readonly callIndex: number;
56
+ readonly validated: ValidatedJsonOutput;
57
+ }): ArtifactRecord;
58
+ writeStageAggregate(stage: NormalizedStage, stageIndex: number): string | undefined;
59
+ noteFailedCall(stageId: string, callId: string, reason: string): void;
60
+ seedArtifact(record: ArtifactRecord): void;
61
+ seedFailedCall(stageId: string, callId: string, reason: string): void;
62
+ buildContext(definition: NormalizedWorkflowDefinition, refs: readonly string[] | undefined): ContextArtifacts;
63
+ buildAnonymizedContext(definition: NormalizedWorkflowDefinition, refs: readonly string[] | undefined, rotationIndex?: number): ContextArtifacts;
64
+ private collectReference;
65
+ }
@@ -0,0 +1,268 @@
1
+ /**
2
+ * Artifact storage and ordered context threading.
3
+ */
4
+ import { mkdirSync, writeFileSync } from "node:fs";
5
+ import { join } from "node:path";
6
+ import { WorkflowError } from "./errors.js";
7
+ import { renderContextSummary } from "./template.js";
8
+ import { createPathContributor } from "./prompt-budget.js";
9
+ /**
10
+ * Recursively strip keys ending in `_id` from a parsed JSON structure
11
+ * to prevent identity leakage in anonymized context.
12
+ * Objects: strip `_id` keys, recurse into remaining values.
13
+ * Arrays: recurse into each element.
14
+ * Primitives: return as-is.
15
+ */
16
+ export function stripIdentityFields(parsed) {
17
+ if (parsed == null || typeof parsed !== "object") {
18
+ return parsed;
19
+ }
20
+ if (Array.isArray(parsed)) {
21
+ return parsed.map((element) => stripIdentityFields(element));
22
+ }
23
+ const obj = parsed;
24
+ const result = {};
25
+ for (const key of Object.keys(obj)) {
26
+ if (!key.endsWith("_id")) {
27
+ result[key] = stripIdentityFields(obj[key]);
28
+ }
29
+ }
30
+ return result;
31
+ }
32
+ export class ArtifactStore {
33
+ runDir;
34
+ validatorRegistry;
35
+ artifactRoot;
36
+ artifactsByReference = new Map();
37
+ omissionsByReference = new Map();
38
+ constructor(runDir, validatorRegistry) {
39
+ this.runDir = runDir;
40
+ this.validatorRegistry = validatorRegistry;
41
+ this.artifactRoot = join(runDir, "artifacts");
42
+ mkdirSync(this.artifactRoot, { recursive: true });
43
+ }
44
+ get artifactsDir() {
45
+ return this.artifactRoot;
46
+ }
47
+ validateJsonOutput(stageId, callId, validatorSchemaId, outputText) {
48
+ let parsed;
49
+ try {
50
+ parsed = JSON.parse(outputText);
51
+ }
52
+ catch (error) {
53
+ throw new WorkflowError(`Invalid JSON output for ${stageId}.${callId}: ${error instanceof Error ? error.message : String(error)}`);
54
+ }
55
+ const validator = this.validatorRegistry.get(validatorSchemaId);
56
+ if (validator == null) {
57
+ throw new WorkflowError(`Unknown validator schema "${validatorSchemaId}" for ${stageId}.${callId}`);
58
+ }
59
+ const result = validator.schema.safeParse(parsed);
60
+ if (!result.success) {
61
+ throw new WorkflowError(`Validation failed for ${stageId}.${callId} against ${validatorSchemaId}: ` +
62
+ result.error.issues.map((issue) => `${issue.path.join(".")}: ${issue.message}`).join("; "));
63
+ }
64
+ const serialized = `${JSON.stringify(result.data, null, 2)}\n`;
65
+ const sizeBytes = Buffer.byteLength(serialized, "utf-8");
66
+ if (validator.maxBytes != null && sizeBytes > validator.maxBytes) {
67
+ throw new WorkflowError(`Validated output for ${stageId}.${callId} exceeds ${String(validator.maxBytes)} bytes ` +
68
+ `(got ${String(sizeBytes)} bytes)`);
69
+ }
70
+ return { parsed: result.data, serialized, sizeBytes };
71
+ }
72
+ writeCallArtifact(options) {
73
+ const stageDir = join(this.artifactRoot, options.stage.id);
74
+ mkdirSync(stageDir, { recursive: true });
75
+ const filename = `${ordinal(options.callIndex + 1)}-${options.call.id}.json`;
76
+ const filePath = join(stageDir, filename);
77
+ writeFileSync(filePath, options.validated.serialized, "utf-8");
78
+ const record = {
79
+ stageId: options.stage.id,
80
+ callId: options.call.id,
81
+ reference: `${options.stage.id}.${options.call.id}`,
82
+ filePath,
83
+ filename,
84
+ sizeBytes: options.validated.sizeBytes,
85
+ parsed: options.validated.parsed,
86
+ };
87
+ this.artifactsByReference.set(record.reference, record);
88
+ return record;
89
+ }
90
+ writeStageAggregate(stage, stageIndex) {
91
+ const stageArtifacts = stage.calls
92
+ .map((call) => this.artifactsByReference.get(`${stage.id}.${call.id}`))
93
+ .filter((artifact) => artifact != null);
94
+ if (stageArtifacts.length === 0) {
95
+ return undefined;
96
+ }
97
+ const aggregatePath = join(this.artifactRoot, `${ordinal(stageIndex + 1)}-${stage.id}.json`);
98
+ const payload = {
99
+ stage_id: stage.id,
100
+ artifacts: stageArtifacts.map((artifact) => ({
101
+ call_id: artifact.callId,
102
+ file: artifact.filename,
103
+ output: artifact.parsed,
104
+ })),
105
+ };
106
+ writeFileSync(aggregatePath, `${JSON.stringify(payload, null, 2)}\n`, "utf-8");
107
+ return aggregatePath;
108
+ }
109
+ noteFailedCall(stageId, callId, reason) {
110
+ const reference = `${stageId}.${callId}`;
111
+ this.omissionsByReference.set(reference, {
112
+ stageId,
113
+ callId,
114
+ reference,
115
+ reason,
116
+ });
117
+ }
118
+ seedArtifact(record) {
119
+ this.artifactsByReference.set(record.reference, record);
120
+ }
121
+ seedFailedCall(stageId, callId, reason) {
122
+ this.noteFailedCall(stageId, callId, reason);
123
+ }
124
+ buildContext(definition, refs) {
125
+ if (refs == null || refs.length === 0) {
126
+ return {
127
+ absoluteFilePaths: [],
128
+ context: undefined,
129
+ contributors: [],
130
+ artifacts: [],
131
+ omissions: [],
132
+ };
133
+ }
134
+ const artifacts = [];
135
+ const omissions = [];
136
+ const seenArtifacts = new Set();
137
+ const seenOmissions = new Set();
138
+ const perStage = new Map();
139
+ for (const ref of refs) {
140
+ const dot = ref.indexOf(".");
141
+ if (dot === -1) {
142
+ const stage = definition.stages.find((candidate) => candidate.id === ref);
143
+ if (stage == null) {
144
+ throw new WorkflowError(`Unknown stage reference "${ref}" while building context`);
145
+ }
146
+ for (const call of stage.calls) {
147
+ this.collectReference(`${stage.id}.${call.id}`, artifacts, omissions, seenArtifacts, seenOmissions);
148
+ }
149
+ }
150
+ else {
151
+ this.collectReference(ref, artifacts, omissions, seenArtifacts, seenOmissions);
152
+ }
153
+ }
154
+ for (const artifact of artifacts) {
155
+ const group = perStage.get(artifact.stageId) ?? [];
156
+ group.push(artifact);
157
+ perStage.set(artifact.stageId, group);
158
+ }
159
+ const summaryParts = [];
160
+ for (const [stageId, stageArtifacts] of perStage) {
161
+ summaryParts.push(renderContextSummary(stageId, stageArtifacts.map((artifact) => ({
162
+ filename: artifact.filename,
163
+ sizeBytes: artifact.sizeBytes,
164
+ }))));
165
+ }
166
+ if (omissions.length > 0) {
167
+ summaryParts.push(`Omitted failed outputs: ${omissions.map((omission) => omission.reference).join(", ")}.`);
168
+ }
169
+ return {
170
+ absoluteFilePaths: artifacts.map((artifact) => artifact.filePath),
171
+ context: summaryParts.length > 0 ? summaryParts.join(" ") : undefined,
172
+ contributors: artifacts.map((artifact) => createPathContributor(`context_from:${artifact.reference}`, artifact.filePath, "context")),
173
+ artifacts,
174
+ omissions,
175
+ };
176
+ }
177
+ buildAnonymizedContext(definition, refs, rotationIndex = 0) {
178
+ const base = this.buildContext(definition, refs);
179
+ if (base.artifacts.length === 0) {
180
+ return base;
181
+ }
182
+ if (base.artifacts.length > 26) {
183
+ throw new WorkflowError("Anonymous aliasing supports at most 26 artifacts (A-Z)");
184
+ }
185
+ const anonDir = join(this.artifactRoot, "anonymous");
186
+ mkdirSync(anonDir, { recursive: true });
187
+ const aliasedArtifacts = [];
188
+ const aliasedPaths = [];
189
+ const perStage = new Map();
190
+ for (let i = 0; i < base.artifacts.length; i++) {
191
+ const artifact = base.artifacts[i];
192
+ const letter = String.fromCharCode(65 + (i % 26));
193
+ const aliasFilename = `${letter}.json`;
194
+ const aliasPath = join(anonDir, aliasFilename);
195
+ const content = JSON.stringify(stripIdentityFields(artifact.parsed), null, 2) + "\n";
196
+ writeFileSync(aliasPath, content, "utf-8");
197
+ aliasedPaths.push(aliasPath);
198
+ aliasedArtifacts.push({
199
+ ...artifact,
200
+ filePath: aliasPath,
201
+ filename: aliasFilename,
202
+ });
203
+ const group = perStage.get(artifact.stageId) ?? [];
204
+ group.push({ filename: aliasFilename, sizeBytes: artifact.sizeBytes });
205
+ perStage.set(artifact.stageId, group);
206
+ }
207
+ // Rotate file presentation order to mitigate position bias across reviewers.
208
+ // The alias→candidate mapping is stable; only the order changes.
209
+ const effectiveRotation = aliasedPaths.length > 0
210
+ ? ((rotationIndex % aliasedPaths.length) + aliasedPaths.length) % aliasedPaths.length
211
+ : 0;
212
+ const rotatedPaths = effectiveRotation === 0
213
+ ? aliasedPaths
214
+ : [...aliasedPaths.slice(effectiveRotation), ...aliasedPaths.slice(0, effectiveRotation)];
215
+ // Build summary text in rotated order so the text matches rotatedPaths.
216
+ const rotatedArtifacts = effectiveRotation === 0
217
+ ? aliasedArtifacts
218
+ : [...aliasedArtifacts.slice(effectiveRotation), ...aliasedArtifacts.slice(0, effectiveRotation)];
219
+ const rotatedPerStage = new Map();
220
+ for (const artifact of rotatedArtifacts) {
221
+ const group = rotatedPerStage.get(artifact.stageId) ?? [];
222
+ group.push({ filename: artifact.filename, sizeBytes: artifact.sizeBytes });
223
+ rotatedPerStage.set(artifact.stageId, group);
224
+ }
225
+ const summaryParts = [];
226
+ for (const [stageId, stageArtifacts] of rotatedPerStage) {
227
+ const fileList = stageArtifacts
228
+ .map((a) => {
229
+ const letter = a.filename.replace(".json", "");
230
+ const sizeKb = Math.ceil(a.sizeBytes / 1024);
231
+ return `Answer ${letter} (${String(sizeKb)}KB)`;
232
+ })
233
+ .join(", ");
234
+ summaryParts.push(`Stage ${stageId} outputs: ${fileList}. ` +
235
+ "Read these files to synthesize your response.");
236
+ }
237
+ if (base.omissions.length > 0) {
238
+ const anonymizedOmissions = base.omissions.map((_o, idx) => `omitted_${idx + 1}`);
239
+ summaryParts.push(`Omitted failed outputs: ${anonymizedOmissions.join(", ")}.`);
240
+ }
241
+ return {
242
+ absoluteFilePaths: rotatedPaths,
243
+ context: summaryParts.length > 0 ? summaryParts.join(" ") : undefined,
244
+ contributors: aliasedArtifacts.map((artifact, index) => createPathContributor(`context_from:answer_${String.fromCharCode(65 + index)}`, artifact.filePath, "context")),
245
+ artifacts: aliasedArtifacts,
246
+ omissions: base.omissions,
247
+ };
248
+ }
249
+ collectReference(reference, artifacts, omissions, seenArtifacts, seenOmissions) {
250
+ const artifact = this.artifactsByReference.get(reference);
251
+ if (artifact != null) {
252
+ if (!seenArtifacts.has(reference)) {
253
+ artifacts.push(artifact);
254
+ seenArtifacts.add(reference);
255
+ }
256
+ return;
257
+ }
258
+ const omission = this.omissionsByReference.get(reference);
259
+ if (omission != null && !seenOmissions.has(reference)) {
260
+ omissions.push(omission);
261
+ seenOmissions.add(reference);
262
+ }
263
+ }
264
+ }
265
+ function ordinal(value) {
266
+ return String(value).padStart(2, "0");
267
+ }
268
+ //# sourceMappingURL=artifacts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"artifacts.js","sourceRoot":"","sources":["../src/artifacts.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO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,MAAM,QAAQ,GAAG,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC1D,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAC;YACrB,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;gBAClC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBACzB,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;YAC/B,CAAC;YACD,OAAO;QACT,CAAC;QAED,MAAM,QAAQ,GAAG,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC1D,IAAI,QAAQ,IAAI,IAAI,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;YACtD,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACzB,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;CACF;AAED,SAAS,OAAO,CAAC,KAAa;IAC5B,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AACxC,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Backend abstraction for the workflow engine.
3
+ *
4
+ * Allows the engine to call clink either via:
5
+ * - Child process MCP transport (ClinkSession — existing)
6
+ * - In-process direct call (LocalClinkBackend — new)
7
+ */
8
+ export interface ToolCallResult {
9
+ readonly content: ReadonlyArray<{
10
+ readonly type: string;
11
+ readonly text?: string | undefined;
12
+ }>;
13
+ readonly isError?: boolean | undefined;
14
+ }
15
+ export interface ClinkBackend {
16
+ /** Advertised cli_name values. */
17
+ readonly cliNames: string[];
18
+ /** Advertised role values. */
19
+ readonly roleNames: string[];
20
+ /** Whether the backend has been terminated. */
21
+ readonly isTerminated: boolean;
22
+ /** Whether the backend's child process died unexpectedly (only relevant for child-process backends). */
23
+ readonly hasChildDied: boolean;
24
+ /** Initialize the backend (connect to child, etc). No-op for in-process backends. */
25
+ connect(): Promise<void>;
26
+ /** Call the clink tool. */
27
+ callTool(args: Record<string, unknown>, options?: {
28
+ signal?: AbortSignal;
29
+ timeoutMs?: number;
30
+ }): Promise<ToolCallResult>;
31
+ /** Shut down the backend. */
32
+ terminate(): Promise<void>;
33
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Backend abstraction for the workflow engine.
3
+ *
4
+ * Allows the engine to call clink either via:
5
+ * - Child process MCP transport (ClinkSession — existing)
6
+ * - In-process direct call (LocalClinkBackend — new)
7
+ */
8
+ export {};
9
+ //# sourceMappingURL=backend.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backend.js","sourceRoot":"","sources":["../src/backend.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Child environment builder for clinkx-workflows.
3
+ *
4
+ * Builds a sanitized environment for the ClinkX child process:
5
+ * 1. Start with process.env (inherit parent env)
6
+ * 2. Scrub ALL CLINKX_* vars and config-discovery vars (XDG_CONFIG_HOME)
7
+ * 3. Re-inject ONLY explicit workflow-owned controls from config
8
+ *
9
+ * Baseline OS env (PATH, HOME, USER, LANG, TMPDIR) is NEVER scrubbed.
10
+ * Dead knobs (CLINKX_TIMEOUT_SECONDS, CLINKX_IDLE_TIMEOUT_*) are NEVER set.
11
+ */
12
+ export interface ChildEnvOverrides {
13
+ readonly allowedRoots: string;
14
+ readonly configPath?: string | undefined;
15
+ readonly logLevel?: string | undefined;
16
+ }
17
+ /**
18
+ * Build a sanitized environment for the ClinkX child process.
19
+ *
20
+ * @param overrides - Runtime overrides (allowedRoots is required)
21
+ * @returns A clean env record suitable for child_process.spawn
22
+ */
23
+ export declare function buildChildEnv(overrides: ChildEnvOverrides): Record<string, string>;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Child environment builder for clinkx-workflows.
3
+ *
4
+ * Builds a sanitized environment for the ClinkX child process:
5
+ * 1. Start with process.env (inherit parent env)
6
+ * 2. Scrub ALL CLINKX_* vars and config-discovery vars (XDG_CONFIG_HOME)
7
+ * 3. Re-inject ONLY explicit workflow-owned controls from config
8
+ *
9
+ * Baseline OS env (PATH, HOME, USER, LANG, TMPDIR) is NEVER scrubbed.
10
+ * Dead knobs (CLINKX_TIMEOUT_SECONDS, CLINKX_IDLE_TIMEOUT_*) are NEVER set.
11
+ */
12
+ import { CHILD_ENV_SCRUB_PREFIX, CHILD_ENV_SCRUB_EXTRA, DEAD_KNOBS, getChildMaxConcurrent, getChildMaxResponseChars, getChildMaxOutputBytes, getChildMaxPromptBytes, getChildConfigPath, getLogLevel, } from "./config.js";
13
+ /**
14
+ * Build a sanitized environment for the ClinkX child process.
15
+ *
16
+ * @param overrides - Runtime overrides (allowedRoots is required)
17
+ * @returns A clean env record suitable for child_process.spawn
18
+ */
19
+ export function buildChildEnv(overrides) {
20
+ const env = {};
21
+ const deadKnobSet = new Set(DEAD_KNOBS);
22
+ const scrubExtra = new Set(CHILD_ENV_SCRUB_EXTRA);
23
+ // Step 1: Copy parent env, scrubbing CLINKX_* and config-discovery vars
24
+ for (const [key, value] of Object.entries(process.env)) {
25
+ if (value == null)
26
+ continue;
27
+ // Scrub all CLINKX_* vars
28
+ if (key.startsWith(CHILD_ENV_SCRUB_PREFIX))
29
+ continue;
30
+ // Scrub config-discovery vars
31
+ if (scrubExtra.has(key))
32
+ continue;
33
+ env[key] = value;
34
+ }
35
+ // Step 2: Re-inject workflow-owned controls (never dead knobs)
36
+ env["CLINKX_MAX_CONCURRENT"] = String(getChildMaxConcurrent());
37
+ env["CLINKX_MAX_RESPONSE_CHARS"] = String(getChildMaxResponseChars());
38
+ env["CLINKX_MAX_OUTPUT_BYTES"] = String(getChildMaxOutputBytes());
39
+ env["CLINKX_MAX_PROMPT_BYTES"] = String(getChildMaxPromptBytes());
40
+ env["CLINKX_ALLOWED_ROOTS"] = overrides.allowedRoots;
41
+ env["CLINKX_LOG_LEVEL"] = overrides.logLevel ?? getLogLevel();
42
+ // Optional: workflow-owned config path
43
+ const configPath = overrides.configPath ?? getChildConfigPath();
44
+ if (configPath != null) {
45
+ env["CLINKX_CONFIG_PATH"] = configPath;
46
+ }
47
+ // Safety: ensure dead knobs are never present
48
+ for (const knob of deadKnobSet) {
49
+ delete env[knob];
50
+ }
51
+ return env;
52
+ }
53
+ //# sourceMappingURL=child-env.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"child-env.js","sourceRoot":"","sources":["../src/child-env.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,UAAU,EACV,qBAAqB,EACrB,wBAAwB,EACxB,sBAAsB,EACtB,sBAAsB,EACtB,kBAAkB,EAClB,WAAW,GACZ,MAAM,aAAa,CAAC;AAQrB;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,SAA4B;IACxD,MAAM,GAAG,GAA2B,EAAE,CAAC;IACvC,MAAM,WAAW,GAAG,IAAI,GAAG,CAAS,UAAU,CAAC,CAAC;IAChD,MAAM,UAAU,GAAG,IAAI,GAAG,CAAS,qBAAqB,CAAC,CAAC;IAE1D,wEAAwE;IACxE,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACvD,IAAI,KAAK,IAAI,IAAI;YAAE,SAAS;QAE5B,0BAA0B;QAC1B,IAAI,GAAG,CAAC,UAAU,CAAC,sBAAsB,CAAC;YAAE,SAAS;QAErD,8BAA8B;QAC9B,IAAI,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,SAAS;QAElC,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACnB,CAAC;IAED,+DAA+D;IAC/D,GAAG,CAAC,uBAAuB,CAAC,GAAG,MAAM,CAAC,qBAAqB,EAAE,CAAC,CAAC;IAC/D,GAAG,CAAC,2BAA2B,CAAC,GAAG,MAAM,CAAC,wBAAwB,EAAE,CAAC,CAAC;IACtE,GAAG,CAAC,yBAAyB,CAAC,GAAG,MAAM,CAAC,sBAAsB,EAAE,CAAC,CAAC;IAClE,GAAG,CAAC,yBAAyB,CAAC,GAAG,MAAM,CAAC,sBAAsB,EAAE,CAAC,CAAC;IAClE,GAAG,CAAC,sBAAsB,CAAC,GAAG,SAAS,CAAC,YAAY,CAAC;IACrD,GAAG,CAAC,kBAAkB,CAAC,GAAG,SAAS,CAAC,QAAQ,IAAI,WAAW,EAAE,CAAC;IAE9D,uCAAuC;IACvC,MAAM,UAAU,GAAG,SAAS,CAAC,UAAU,IAAI,kBAAkB,EAAE,CAAC;IAChE,IAAI,UAAU,IAAI,IAAI,EAAE,CAAC;QACvB,GAAG,CAAC,oBAAoB,CAAC,GAAG,UAAU,CAAC;IACzC,CAAC;IAED,8CAA8C;IAC9C,KAAK,MAAM,IAAI,IAAI,WAAW,EAAE,CAAC;QAC/B,OAAO,GAAG,CAAC,IAAI,CAAC,CAAC;IACnB,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,51 @@
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 type { ClinkBackend, ToolCallResult } from "./backend.js";
16
+ /** Parsed result from a clink call. */
17
+ export interface ClinkCallResult {
18
+ /** Primary output text (for storage/threading/hashing). */
19
+ readonly outputText: string;
20
+ /** Optional _debug metadata block (parsed JSON, or null). */
21
+ readonly debugMetadata: Record<string, unknown> | null;
22
+ }
23
+ /**
24
+ * Build the tool arguments for a child clink call.
25
+ *
26
+ * Ensures debug: true is always set and strips any _meta.progressToken
27
+ * to prevent child from emitting progress to the host.
28
+ */
29
+ export declare function buildCallArgs(input: Record<string, unknown>): Record<string, unknown>;
30
+ /**
31
+ * Parse the MCP tool call result into output_text and debug_metadata.
32
+ *
33
+ * Does NOT assume positional ordering — scans all text content blocks
34
+ * and identifies the _debug block by JSON-parsing each one.
35
+ */
36
+ export declare function parseCallResult(result: ToolCallResult): ClinkCallResult;
37
+ /**
38
+ * Call the child's clink tool and return parsed output.
39
+ *
40
+ * @param session - Active ClinkBackend
41
+ * @param input - Tool input arguments (ClinkInput shape)
42
+ * @param signal - Optional AbortSignal for cancellation
43
+ * @param context - Stage/call context for error attribution
44
+ * @returns Parsed clink call result
45
+ * @throws InvalidCallError on child -32602
46
+ * @throws CallExecutionError on child isError: true
47
+ */
48
+ export declare function callClink(session: ClinkBackend, input: Record<string, unknown>, signal?: AbortSignal, context?: {
49
+ stageId: string;
50
+ callId: string;
51
+ }, timeoutMs?: number): Promise<ClinkCallResult>;