@llm-dev-ops/agentics-cli 1.5.9 → 1.5.11

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 (105) hide show
  1. package/README.md +478 -148
  2. package/dist/bundled-agents/manifest.json +1 -0
  3. package/dist/commands/phase4.d.ts.map +1 -1
  4. package/dist/commands/phase4.js +4 -2
  5. package/dist/commands/phase4.js.map +1 -1
  6. package/dist/commands/phase6.d.ts.map +1 -1
  7. package/dist/commands/phase6.js +4 -2
  8. package/dist/commands/phase6.js.map +1 -1
  9. package/dist/mcp/mcp-server.js +11 -10
  10. package/dist/mcp/mcp-server.js.map +1 -1
  11. package/dist/pipeline/auto-chain.d.ts +5 -0
  12. package/dist/pipeline/auto-chain.d.ts.map +1 -1
  13. package/dist/pipeline/auto-chain.js +131 -47
  14. package/dist/pipeline/auto-chain.js.map +1 -1
  15. package/dist/pipeline/enterprise/artifact-assembler.d.ts +64 -0
  16. package/dist/pipeline/enterprise/artifact-assembler.d.ts.map +1 -0
  17. package/dist/pipeline/enterprise/artifact-assembler.js +542 -0
  18. package/dist/pipeline/enterprise/artifact-assembler.js.map +1 -0
  19. package/dist/pipeline/enterprise/artifact-renderers.d.ts +42 -0
  20. package/dist/pipeline/enterprise/artifact-renderers.d.ts.map +1 -0
  21. package/dist/pipeline/enterprise/artifact-renderers.js +513 -0
  22. package/dist/pipeline/enterprise/artifact-renderers.js.map +1 -0
  23. package/dist/pipeline/enterprise/code-resolver.d.ts +43 -0
  24. package/dist/pipeline/enterprise/code-resolver.d.ts.map +1 -0
  25. package/dist/pipeline/enterprise/code-resolver.js +219 -0
  26. package/dist/pipeline/enterprise/code-resolver.js.map +1 -0
  27. package/dist/pipeline/enterprise/decision-graph-client.d.ts +171 -0
  28. package/dist/pipeline/enterprise/decision-graph-client.d.ts.map +1 -0
  29. package/dist/pipeline/enterprise/decision-graph-client.js +222 -0
  30. package/dist/pipeline/enterprise/decision-graph-client.js.map +1 -0
  31. package/dist/pipeline/enterprise/decision-graph-memory.d.ts +104 -0
  32. package/dist/pipeline/enterprise/decision-graph-memory.d.ts.map +1 -0
  33. package/dist/pipeline/enterprise/decision-graph-memory.js +292 -0
  34. package/dist/pipeline/enterprise/decision-graph-memory.js.map +1 -0
  35. package/dist/pipeline/enterprise/decision-graph.d.ts +237 -0
  36. package/dist/pipeline/enterprise/decision-graph.d.ts.map +1 -0
  37. package/dist/pipeline/enterprise/decision-graph.js +654 -0
  38. package/dist/pipeline/enterprise/decision-graph.js.map +1 -0
  39. package/dist/pipeline/enterprise/index.d.ts +40 -0
  40. package/dist/pipeline/enterprise/index.d.ts.map +1 -0
  41. package/dist/pipeline/enterprise/index.js +43 -0
  42. package/dist/pipeline/enterprise/index.js.map +1 -0
  43. package/dist/pipeline/enterprise/pass-executor.d.ts +33 -0
  44. package/dist/pipeline/enterprise/pass-executor.d.ts.map +1 -0
  45. package/dist/pipeline/enterprise/pass-executor.js +459 -0
  46. package/dist/pipeline/enterprise/pass-executor.js.map +1 -0
  47. package/dist/pipeline/enterprise/pass-registry.d.ts +19 -0
  48. package/dist/pipeline/enterprise/pass-registry.d.ts.map +1 -0
  49. package/dist/pipeline/enterprise/pass-registry.js +243 -0
  50. package/dist/pipeline/enterprise/pass-registry.js.map +1 -0
  51. package/dist/pipeline/enterprise/pass2-simulation.d.ts +130 -0
  52. package/dist/pipeline/enterprise/pass2-simulation.d.ts.map +1 -0
  53. package/dist/pipeline/enterprise/pass2-simulation.js +691 -0
  54. package/dist/pipeline/enterprise/pass2-simulation.js.map +1 -0
  55. package/dist/pipeline/enterprise/pass4-governance.d.ts +195 -0
  56. package/dist/pipeline/enterprise/pass4-governance.d.ts.map +1 -0
  57. package/dist/pipeline/enterprise/pass4-governance.js +748 -0
  58. package/dist/pipeline/enterprise/pass4-governance.js.map +1 -0
  59. package/dist/pipeline/enterprise/pass5-decision.d.ts +90 -0
  60. package/dist/pipeline/enterprise/pass5-decision.d.ts.map +1 -0
  61. package/dist/pipeline/enterprise/pass5-decision.js +487 -0
  62. package/dist/pipeline/enterprise/pass5-decision.js.map +1 -0
  63. package/dist/pipeline/enterprise/pass7-observability.d.ts +198 -0
  64. package/dist/pipeline/enterprise/pass7-observability.d.ts.map +1 -0
  65. package/dist/pipeline/enterprise/pass7-observability.js +636 -0
  66. package/dist/pipeline/enterprise/pass7-observability.js.map +1 -0
  67. package/dist/pipeline/enterprise/pipeline-orchestrator.d.ts +29 -0
  68. package/dist/pipeline/enterprise/pipeline-orchestrator.d.ts.map +1 -0
  69. package/dist/pipeline/enterprise/pipeline-orchestrator.js +283 -0
  70. package/dist/pipeline/enterprise/pipeline-orchestrator.js.map +1 -0
  71. package/dist/pipeline/enterprise/provenance-tracker.d.ts +135 -0
  72. package/dist/pipeline/enterprise/provenance-tracker.d.ts.map +1 -0
  73. package/dist/pipeline/enterprise/provenance-tracker.js +437 -0
  74. package/dist/pipeline/enterprise/provenance-tracker.js.map +1 -0
  75. package/dist/pipeline/enterprise/trace-middleware.d.ts +37 -0
  76. package/dist/pipeline/enterprise/trace-middleware.d.ts.map +1 -0
  77. package/dist/pipeline/enterprise/trace-middleware.js +188 -0
  78. package/dist/pipeline/enterprise/trace-middleware.js.map +1 -0
  79. package/dist/pipeline/enterprise/types.d.ts +199 -0
  80. package/dist/pipeline/enterprise/types.d.ts.map +1 -0
  81. package/dist/pipeline/enterprise/types.js +30 -0
  82. package/dist/pipeline/enterprise/types.js.map +1 -0
  83. package/dist/pipeline/phase2/phases/adr-generator.d.ts.map +1 -1
  84. package/dist/pipeline/phase2/phases/adr-generator.js +56 -8
  85. package/dist/pipeline/phase2/phases/adr-generator.js.map +1 -1
  86. package/dist/pipeline/phase3/phases/test-generator.d.ts.map +1 -1
  87. package/dist/pipeline/phase3/phases/test-generator.js +53 -0
  88. package/dist/pipeline/phase3/phases/test-generator.js.map +1 -1
  89. package/dist/pipeline/phase4/phases/deployment-generator.d.ts.map +1 -1
  90. package/dist/pipeline/phase4/phases/deployment-generator.js +147 -0
  91. package/dist/pipeline/phase4/phases/deployment-generator.js.map +1 -1
  92. package/dist/pipeline/phase4-adrs/phase4-adrs-coordinator.d.ts.map +1 -1
  93. package/dist/pipeline/phase4-adrs/phase4-adrs-coordinator.js +52 -1
  94. package/dist/pipeline/phase4-adrs/phase4-adrs-coordinator.js.map +1 -1
  95. package/dist/pipeline/phase6/phases/deployment-finalizer.d.ts.map +1 -1
  96. package/dist/pipeline/phase6/phases/deployment-finalizer.js +226 -0
  97. package/dist/pipeline/phase6/phases/deployment-finalizer.js.map +1 -1
  98. package/dist/pipeline/phase6/phases/service-registrar.d.ts +1 -1
  99. package/dist/pipeline/phase6/phases/service-registrar.d.ts.map +1 -1
  100. package/dist/pipeline/phase6/phases/service-registrar.js +47 -7
  101. package/dist/pipeline/phase6/phases/service-registrar.js.map +1 -1
  102. package/dist/pipeline/swarm-orchestrator.d.ts.map +1 -1
  103. package/dist/pipeline/swarm-orchestrator.js +47 -19
  104. package/dist/pipeline/swarm-orchestrator.js.map +1 -1
  105. package/package.json +1 -1
@@ -0,0 +1,437 @@
1
+ /**
2
+ * Provenance Tracker — Runtime Tracing System (ADR-039)
3
+ *
4
+ * Records every agent invocation during a pipeline execution as a
5
+ * structured TraceRecord. Produces the Provenance Manifest (Artifact #15).
6
+ *
7
+ * Features:
8
+ * - Structured trace recording with code provenance
9
+ * - DecisionGraph namespace storage (provenance:{executionId}:{traceId})
10
+ * - Audit query helpers (who/what/when/how/reproducibility)
11
+ * - Rich manifest generation with all ADR-039 sections
12
+ * - Load/rehydrate from persisted records
13
+ * - Filtering by agent, pass, workstream, status
14
+ * - Privacy-safe: metadata only, no payload duplication
15
+ * - Version discrepancy detection
16
+ */
17
+ import * as fs from 'node:fs';
18
+ import * as path from 'node:path';
19
+ import { resolveCodeProvenance, resolveGitCommit } from './code-resolver.js';
20
+ // ============================================================================
21
+ // Provenance Key Format (ADR-039)
22
+ // ============================================================================
23
+ /** Generate the provenance namespace key for a trace record. */
24
+ export function provenanceKey(executionId, traceId) {
25
+ return `provenance:${executionId}:${traceId}`;
26
+ }
27
+ /** Generate tags for a trace record's memory entry. */
28
+ export function provenanceTags(record) {
29
+ return [
30
+ `agent:${record.agent.domain}/${record.agent.agent}`,
31
+ `pass:${record.pass}`,
32
+ `execution:${record.executionId}`,
33
+ `status:${record.outputs.status}`,
34
+ `workstream:${record.workstream}`,
35
+ ];
36
+ }
37
+ // ============================================================================
38
+ // Provenance Tracker
39
+ // ============================================================================
40
+ export class ProvenanceTracker {
41
+ records = [];
42
+ executionId;
43
+ sequenceCounter = 0;
44
+ constructor(executionId) {
45
+ this.executionId = executionId;
46
+ }
47
+ /** Get the execution ID. */
48
+ getExecutionId() {
49
+ return this.executionId;
50
+ }
51
+ // --------------------------------------------------------------------------
52
+ // Recording
53
+ // --------------------------------------------------------------------------
54
+ /** Record an agent invocation as a trace record with full code provenance. */
55
+ recordInvocation(params) {
56
+ this.sequenceCounter++;
57
+ const codeProv = resolveCodeProvenance(params.agent);
58
+ const record = {
59
+ traceId: `trace-${this.sequenceCounter}-${Date.now()}`,
60
+ executionId: this.executionId,
61
+ agent: {
62
+ ...params.agent,
63
+ agentId: `${params.agent.domain}/${params.agent.agent}`,
64
+ version: codeProv.version,
65
+ },
66
+ pass: params.pass,
67
+ passName: params.passName,
68
+ workstream: params.workstream,
69
+ startedAt: params.startedAt,
70
+ completedAt: params.completedAt,
71
+ durationMs: params.durationMs,
72
+ codeProvenance: codeProv,
73
+ inputs: {
74
+ decisionGraphNodes: [...params.inputNodeIds],
75
+ parameters: {},
76
+ },
77
+ outputs: {
78
+ decisionGraphNodes: [...params.outputNodeIds],
79
+ artifactNumbers: [...params.artifactNumbers],
80
+ status: params.status,
81
+ confidence: params.confidence,
82
+ },
83
+ resources: {
84
+ tokensUsed: params.tokensUsed ?? 0,
85
+ modelUsed: params.modelUsed ?? 'unknown',
86
+ estimatedCost: params.estimatedCost ?? 0,
87
+ },
88
+ };
89
+ this.records.push(record);
90
+ return record;
91
+ }
92
+ /** Convenience: record from an AgentInvocationResult. */
93
+ recordFromResult(result, passName, workstream, outputNodeIds = []) {
94
+ return this.recordInvocation({
95
+ agent: result.agent,
96
+ pass: result.pass,
97
+ passName,
98
+ workstream,
99
+ startedAt: result.timestamp,
100
+ completedAt: new Date(new Date(result.timestamp).getTime() + result.durationMs).toISOString(),
101
+ durationMs: result.durationMs,
102
+ inputNodeIds: [],
103
+ outputNodeIds,
104
+ artifactNumbers: [],
105
+ status: result.status >= 200 && result.status < 300 ? 'success' : 'failed',
106
+ confidence: result.status >= 200 && result.status < 300 ? 0.85 : 0,
107
+ });
108
+ }
109
+ // --------------------------------------------------------------------------
110
+ // Querying
111
+ // --------------------------------------------------------------------------
112
+ /** Get all trace records. */
113
+ getAllRecords() {
114
+ return this.records;
115
+ }
116
+ /** Get records for a specific pass. */
117
+ getRecordsByPass(pass) {
118
+ return this.records.filter(r => r.pass === pass);
119
+ }
120
+ /** Get records for a specific agent (domain/agent). */
121
+ getRecordsByAgent(domain, agent) {
122
+ return this.records.filter(r => r.agent.domain === domain && r.agent.agent === agent);
123
+ }
124
+ /** Get records for a specific workstream. */
125
+ getRecordsByWorkstream(workstream) {
126
+ return this.records.filter(r => r.workstream === workstream);
127
+ }
128
+ /** Get records by status. */
129
+ getRecordsByStatus(status) {
130
+ return this.records.filter(r => r.outputs.status === status);
131
+ }
132
+ /** Get a specific record by trace ID. */
133
+ getRecordByTraceId(traceId) {
134
+ return this.records.find(r => r.traceId === traceId);
135
+ }
136
+ /** Get total number of unique agents invoked. */
137
+ getUniqueAgentCount() {
138
+ const seen = new Set();
139
+ for (const r of this.records) {
140
+ seen.add(r.agent.agentId);
141
+ }
142
+ return seen.size;
143
+ }
144
+ /** Get total tokens used. */
145
+ getTotalTokens() {
146
+ let total = 0;
147
+ for (const r of this.records) {
148
+ total += r.resources.tokensUsed;
149
+ }
150
+ return total;
151
+ }
152
+ /** Get total estimated cost. */
153
+ getTotalCost() {
154
+ let total = 0;
155
+ for (const r of this.records) {
156
+ total += r.resources.estimatedCost;
157
+ }
158
+ return total;
159
+ }
160
+ /** Get total pipeline duration (sum of all agent durations). */
161
+ getTotalDuration() {
162
+ let total = 0;
163
+ for (const r of this.records) {
164
+ total += r.durationMs;
165
+ }
166
+ return total;
167
+ }
168
+ /** Get the longest-running agent. */
169
+ getLongestAgent() {
170
+ if (this.records.length === 0)
171
+ return undefined;
172
+ let longest = this.records[0];
173
+ for (const r of this.records) {
174
+ if (r.durationMs > longest.durationMs) {
175
+ longest = r;
176
+ }
177
+ }
178
+ return { agentId: longest.agent.agentId, durationMs: longest.durationMs };
179
+ }
180
+ // --------------------------------------------------------------------------
181
+ // Audit Queries (ADR-039 Auditability)
182
+ // --------------------------------------------------------------------------
183
+ /** Who made a decision (for a specific trace). */
184
+ auditWho(traceId) {
185
+ const r = this.getRecordByTraceId(traceId);
186
+ if (!r)
187
+ return undefined;
188
+ return {
189
+ agentDomain: r.agent.domain,
190
+ agentName: r.agent.agent,
191
+ agentId: r.agent.agentId,
192
+ role: r.agent.role,
193
+ };
194
+ }
195
+ /** What code was used (for a specific trace). */
196
+ auditWhat(traceId) {
197
+ const r = this.getRecordByTraceId(traceId);
198
+ if (!r)
199
+ return undefined;
200
+ return {
201
+ package: r.codeProvenance.package,
202
+ version: r.codeProvenance.version,
203
+ entryPoint: r.codeProvenance.entryPoint,
204
+ commitHash: r.codeProvenance.commitHash,
205
+ };
206
+ }
207
+ /** Reproducibility info (for a specific trace). */
208
+ auditReproducibility(traceId) {
209
+ const r = this.getRecordByTraceId(traceId);
210
+ if (!r)
211
+ return undefined;
212
+ return {
213
+ commitHash: r.codeProvenance.commitHash,
214
+ parameters: r.inputs.parameters,
215
+ inputNodeIds: r.inputs.decisionGraphNodes,
216
+ codePackage: r.codeProvenance.package,
217
+ codeVersion: r.codeProvenance.version,
218
+ };
219
+ }
220
+ // --------------------------------------------------------------------------
221
+ // Statistics
222
+ // --------------------------------------------------------------------------
223
+ /** Compute aggregate provenance statistics. */
224
+ getStatistics() {
225
+ const byPass = {};
226
+ const byStatus = {};
227
+ const byWorkstream = {};
228
+ const packages = new Set();
229
+ for (const r of this.records) {
230
+ byPass[r.pass] = (byPass[r.pass] ?? 0) + 1;
231
+ byStatus[r.outputs.status] = (byStatus[r.outputs.status] ?? 0) + 1;
232
+ byWorkstream[r.workstream] = (byWorkstream[r.workstream] ?? 0) + 1;
233
+ packages.add(r.codeProvenance.package);
234
+ }
235
+ return {
236
+ totalRecords: this.records.length,
237
+ uniqueAgents: this.getUniqueAgentCount(),
238
+ uniquePackages: packages.size,
239
+ totalTokens: this.getTotalTokens(),
240
+ totalCost: this.getTotalCost(),
241
+ totalDurationMs: this.getTotalDuration(),
242
+ byPass,
243
+ byStatus,
244
+ byWorkstream,
245
+ longestAgent: this.getLongestAgent(),
246
+ };
247
+ }
248
+ // --------------------------------------------------------------------------
249
+ // Manifest Generation (Artifact #15 — ADR-039)
250
+ // --------------------------------------------------------------------------
251
+ /** Generate the Provenance Manifest as a markdown string. */
252
+ generateManifest(params) {
253
+ const now = new Date().toISOString();
254
+ const stats = this.getStatistics();
255
+ const longest = stats.longestAgent;
256
+ // Collect unique packages
257
+ const packages = new Map();
258
+ for (const r of this.records) {
259
+ const pkg = r.codeProvenance.package;
260
+ const existing = packages.get(pkg);
261
+ if (existing) {
262
+ existing.agents.add(r.agent.agent);
263
+ }
264
+ else {
265
+ packages.set(pkg, {
266
+ version: r.codeProvenance.version,
267
+ repository: r.codeProvenance.repository,
268
+ agents: new Set([r.agent.agent]),
269
+ });
270
+ }
271
+ }
272
+ const lines = [];
273
+ // Header
274
+ lines.push('# Agent & Code Provenance Manifest');
275
+ lines.push(`**Execution ID:** ${this.executionId}`);
276
+ lines.push(`**Date:** ${now}`);
277
+ lines.push(`**Pipeline Duration:** ${formatDuration(stats.totalDurationMs)}`);
278
+ lines.push(`**Total Agents Invoked:** ${this.records.length}`);
279
+ lines.push(`**Unique Agent Types:** ${stats.uniqueAgents}`);
280
+ lines.push(`**Total LLM Tokens Used:** ${stats.totalTokens.toLocaleString()}`);
281
+ lines.push(`**Estimated Pipeline Cost:** $${stats.totalCost.toFixed(4)}`);
282
+ lines.push('');
283
+ // Agent Inventory
284
+ lines.push('## Agent Inventory');
285
+ lines.push('');
286
+ lines.push('| # | Agent | Domain | Pass | Duration | Tokens | Model | Status |');
287
+ lines.push('|---|-------|--------|------|----------|--------|-------|--------|');
288
+ for (let i = 0; i < this.records.length; i++) {
289
+ const r = this.records[i];
290
+ const statusIcon = r.outputs.status === 'success' ? '\u2705' : r.outputs.status === 'partial' ? '\u26a0\ufe0f' : '\u274c';
291
+ lines.push(`| ${i + 1} | ${r.agent.agent} | ${r.agent.domain} | Pass ${r.pass} | ${formatDuration(r.durationMs)} | ${r.resources.tokensUsed.toLocaleString()} | ${r.resources.modelUsed} | ${statusIcon} |`);
292
+ }
293
+ lines.push('');
294
+ // Code Inventory
295
+ lines.push('## Code Inventory');
296
+ lines.push('');
297
+ lines.push('| Package | Version | Repository | Agents Using |');
298
+ lines.push('|---------|---------|------------|-------------|');
299
+ for (const [pkg, info] of packages.entries()) {
300
+ lines.push(`| ${pkg} | ${info.version} | ${info.repository} | ${Array.from(info.agents).join(', ')} |`);
301
+ }
302
+ lines.push('');
303
+ lines.push(`**Git Commit:** ${this.records[0]?.codeProvenance.commitHash ?? resolveGitCommit()}`);
304
+ lines.push('');
305
+ // Execution Flow by Pass
306
+ lines.push('## Execution Flow');
307
+ lines.push('');
308
+ const passNames = {
309
+ 1: 'Problem Intelligence',
310
+ 2: 'Simulation & Scenario Modeling',
311
+ 3: 'Architecture & Prototype Generation',
312
+ 4: 'Governance, Compliance & CostOps',
313
+ 5: 'Decision Artifacts',
314
+ 6: 'ERP Prototype Deployment',
315
+ 7: 'Observability & Continuous Learning',
316
+ };
317
+ for (let pass = 1; pass <= 7; pass++) {
318
+ const passRecords = this.records.filter(r => r.pass === pass);
319
+ if (passRecords.length === 0)
320
+ continue;
321
+ lines.push(`### Pass ${pass} \u2014 ${passNames[pass] ?? `Pass ${pass}`}`);
322
+ lines.push('```');
323
+ for (const r of passRecords) {
324
+ const statusIcon = r.outputs.status === 'success' ? '\u2705' : '\u274c';
325
+ lines.push(`[${r.startedAt}] ${r.agent.agent} (${r.agent.domain}) - ${formatDuration(r.durationMs)} ${statusIcon}`);
326
+ }
327
+ lines.push('```');
328
+ lines.push('');
329
+ }
330
+ // Artifact Ownership
331
+ lines.push('## Artifact Ownership');
332
+ lines.push('');
333
+ lines.push('| # | Artifact | Producing Agent(s) | Pass |');
334
+ lines.push('|---|----------|-------------------|------|');
335
+ for (const a of params.artifactOwnership) {
336
+ lines.push(`| ${a.number} | ${a.name} | ${a.agent} | ${a.pass} |`);
337
+ }
338
+ lines.push('');
339
+ // Quality Scores
340
+ lines.push('## Quality Scores');
341
+ lines.push('');
342
+ lines.push('| Agent | Domain | Confidence | Status | Notes |');
343
+ lines.push('|-------|--------|-----------|--------|-------|');
344
+ for (const r of this.records) {
345
+ const notes = r.outputs.status !== 'success' ? r.outputs.status : '\u2014';
346
+ lines.push(`| ${r.agent.agent} | ${r.agent.domain} | ${r.outputs.confidence.toFixed(2)} | ${r.outputs.status} | ${notes} |`);
347
+ }
348
+ lines.push('');
349
+ // Resource Summary
350
+ lines.push('## Resource Summary');
351
+ lines.push('');
352
+ lines.push('| Resource | Value |');
353
+ lines.push('|----------|-------|');
354
+ lines.push(`| Total agents invoked | ${this.records.length} |`);
355
+ lines.push(`| Unique agent types | ${stats.uniqueAgents} |`);
356
+ lines.push(`| Unique code packages | ${packages.size} |`);
357
+ lines.push(`| Total LLM tokens | ${stats.totalTokens.toLocaleString()} |`);
358
+ lines.push(`| Total estimated cost | $${stats.totalCost.toFixed(4)} |`);
359
+ lines.push(`| Pipeline wall-clock time | ${formatDuration(stats.totalDurationMs)} |`);
360
+ if (longest) {
361
+ lines.push(`| Longest agent execution | ${longest.agentId} (${formatDuration(longest.durationMs)}) |`);
362
+ }
363
+ lines.push(`| Passes completed | ${params.passesCompleted}/7 |`);
364
+ lines.push(`| Passes degraded | ${params.passesDegraded.length > 0 ? params.passesDegraded.join(', ') : 'None'} |`);
365
+ lines.push('');
366
+ // Auditability (ADR-039)
367
+ lines.push('## Auditability');
368
+ lines.push('');
369
+ lines.push('| Requirement | How It\'s Met |');
370
+ lines.push('|-------------|-------------|');
371
+ lines.push('| **Who** made each decision | `agent.domain` + `agent.agent` in every TraceRecord |');
372
+ lines.push('| **What** code was used | `codeProvenance.package` + `commitHash` |');
373
+ lines.push('| **When** it happened | `startedAt` / `completedAt` timestamps |');
374
+ lines.push('| **What** data was used | `inputs.decisionGraphNodes` — exact node IDs read |');
375
+ lines.push('| **What** was produced | `outputs.decisionGraphNodes` + `outputs.artifactNumbers` |');
376
+ lines.push('| **How** confident | `outputs.confidence` per agent |');
377
+ lines.push('| **How much** it cost | `resources.tokensUsed` + `resources.estimatedCost` |');
378
+ lines.push('| **Reproducibility** | `commitHash` + `inputs.parameters` enable re-execution |');
379
+ lines.push('');
380
+ // Privacy note
381
+ lines.push('## Privacy & Redaction');
382
+ lines.push('');
383
+ lines.push('TraceRecords contain **metadata only** — no agent input/output payloads are stored.');
384
+ lines.push('DecisionGraph node IDs (pointers) are recorded, not content.');
385
+ lines.push('Access control on DecisionGraph nodes governs who can see actual data.');
386
+ lines.push('');
387
+ // Schema version
388
+ lines.push('---');
389
+ lines.push('*Provenance Schema v1.0 (ADR-039)*');
390
+ return lines.join('\n');
391
+ }
392
+ // --------------------------------------------------------------------------
393
+ // Persistence
394
+ // --------------------------------------------------------------------------
395
+ /** Persist trace records to the output directory. */
396
+ persist(outputDir) {
397
+ const traceDir = path.join(outputDir, 'provenance');
398
+ fs.mkdirSync(traceDir, { recursive: true });
399
+ const filePath = path.join(traceDir, 'trace-records.json');
400
+ fs.writeFileSync(filePath, JSON.stringify(this.records, null, 2), 'utf-8');
401
+ return filePath;
402
+ }
403
+ /** Load trace records from a previously persisted file. */
404
+ static load(executionId, outputDir) {
405
+ const tracker = new ProvenanceTracker(executionId);
406
+ const filePath = path.join(outputDir, 'provenance', 'trace-records.json');
407
+ if (!fs.existsSync(filePath))
408
+ return tracker;
409
+ try {
410
+ const raw = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
411
+ if (Array.isArray(raw)) {
412
+ for (const record of raw) {
413
+ tracker.records.push(record);
414
+ }
415
+ tracker.sequenceCounter = tracker.records.length;
416
+ }
417
+ }
418
+ catch {
419
+ // Corrupted file — return empty tracker
420
+ }
421
+ return tracker;
422
+ }
423
+ }
424
+ // ============================================================================
425
+ // Helpers
426
+ // ============================================================================
427
+ /** Format milliseconds as human-readable duration. */
428
+ function formatDuration(ms) {
429
+ if (ms < 1000)
430
+ return `${ms}ms`;
431
+ if (ms < 60_000)
432
+ return `${(ms / 1000).toFixed(1)}s`;
433
+ const minutes = Math.floor(ms / 60_000);
434
+ const seconds = Math.round((ms % 60_000) / 1000);
435
+ return `${minutes}m ${seconds}s`;
436
+ }
437
+ //# sourceMappingURL=provenance-tracker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provenance-tracker.js","sourceRoot":"","sources":["../../../src/pipeline/enterprise/provenance-tracker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAQlC,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE7E,+EAA+E;AAC/E,kCAAkC;AAClC,+EAA+E;AAE/E,gEAAgE;AAChE,MAAM,UAAU,aAAa,CAAC,WAAmB,EAAE,OAAe;IAChE,OAAO,cAAc,WAAW,IAAI,OAAO,EAAE,CAAC;AAChD,CAAC;AAED,uDAAuD;AACvD,MAAM,UAAU,cAAc,CAAC,MAAmB;IAChD,OAAO;QACL,SAAS,MAAM,CAAC,KAAK,CAAC,MAAM,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE;QACpD,Q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AAO,CAAC,CAAC,CAAC,GAAG,CAAC;IACrD,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,MAAM,CAAC,CAAC;IACxC,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC;IACjD,OAAO,GAAG,OAAO,KAAK,OAAO,GAAG,CAAC;AACnC,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Trace Middleware — Transparent Agent Invocation Tracing (ADR-039)
3
+ *
4
+ * Wraps agent invocations without modifying agent code. Infers inputs
5
+ * (which DecisionGraph nodes were read) and outputs (which nodes were
6
+ * written) by diffing the graph state before and after execution.
7
+ *
8
+ * Key principle: Agents are unaware of tracing. They do not need to
9
+ * emit trace data. The middleware handles everything.
10
+ */
11
+ import type { PassNumber, AgentRef, AgentInvocationResult } from './types.js';
12
+ import { DecisionGraph } from './decision-graph.js';
13
+ import { ProvenanceTracker } from './provenance-tracker.js';
14
+ /** The agent invoker function signature. */
15
+ export type AgentInvoker = (agents: readonly AgentRef[], payload: Record<string, unknown>, pass: PassNumber, timeoutMs: number) => Promise<AgentInvocationResult[]>;
16
+ /**
17
+ * Create a tracing wrapper around an agent invoker.
18
+ *
19
+ * The wrapped invoker:
20
+ * 1. Snapshots the graph node count before invocation
21
+ * 2. Invokes the original invoker
22
+ * 3. Diffs the graph to find new nodes (inferred outputs)
23
+ * 4. Records a TraceRecord per agent with code provenance
24
+ *
25
+ * Usage:
26
+ * const tracedInvoker = createTracingInvoker(originalInvoker, graph, tracker, 'Pass Name', 'workstream');
27
+ * const results = await tracedInvoker(agents, payload, pass, timeoutMs);
28
+ */
29
+ export declare function createTracingInvoker(inner: AgentInvoker, graph: DecisionGraph, tracker: ProvenanceTracker, passName: string, workstream: string): AgentInvoker;
30
+ /**
31
+ * Create a tracing wrapper that also writes TraceRecords to the DecisionGraph.
32
+ *
33
+ * This is the full ADR-039 implementation: trace records are stored both
34
+ * in the ProvenanceTracker (in-memory) and as DecisionGraph nodes (persisted).
35
+ */
36
+ export declare function createFullTracingInvoker(inner: AgentInvoker, graph: DecisionGraph, tracker: ProvenanceTracker, passName: string, workstream: string): AgentInvoker;
37
+ //# sourceMappingURL=trace-middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trace-middleware.d.ts","sourceRoot":"","sources":["../../../src/pipeline/enterprise/trace-middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,QAAQ,EACR,qBAAqB,EACtB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAO5D,4CAA4C;AAC5C,MAAM,MAAM,YAAY,GAAG,CACzB,MAAM,EAAE,SAAS,QAAQ,EAAE,EAC3B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,IAAI,EAAE,UAAU,EAChB,SAAS,EAAE,MAAM,KACd,OAAO,CAAC,qBAAqB,EAAE,CAAC,CAAC;AAMtC;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,YAAY,EACnB,KAAK,EAAE,aAAa,EACpB,OAAO,EAAE,iBAAiB,EAC1B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,GACjB,YAAY,CAyDd;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,YAAY,EACnB,KAAK,EAAE,aAAa,EACpB,OAAO,EAAE,iBAAiB,EAC1B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,GACjB,YAAY,CAmDd"}