pluribus-context 0.3.22 → 0.3.26

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 (93) hide show
  1. package/CHANGELOG.md +25 -3
  2. package/README.md +2 -2
  3. package/docs/community-review-packet.md +2 -1
  4. package/docs/context-budget-receipts.md +150 -0
  5. package/docs/context-input-evidence.md +397 -0
  6. package/docs/context-receipts-for-agent-observability.md +177 -0
  7. package/docs/orchestration-search-receipts.md +102 -0
  8. package/docs/portability-fidelity-report.md +4 -2
  9. package/examples/context-input-evidence/AGENTS.md +12 -0
  10. package/examples/context-input-evidence/agent-overlay-log.jsonl +4 -0
  11. package/examples/context-input-evidence/agent-overlay-otel-trace.json +548 -0
  12. package/examples/context-input-evidence/agent-overlay-receipt.ndjson +3 -0
  13. package/examples/context-input-evidence/agentgateway-progressive-disclosure-otel-trace.json +393 -0
  14. package/examples/context-input-evidence/agentgateway-progressive-disclosure-receipt.ndjson +4 -0
  15. package/examples/context-input-evidence/brain-remediation-otel-trace.json +645 -0
  16. package/examples/context-input-evidence/brain-remediation-receipt.ndjson +7 -0
  17. package/examples/context-input-evidence/claudekit-mcp-manager-otel-trace.json +417 -0
  18. package/examples/context-input-evidence/claudekit-mcp-manager-receipt.ndjson +5 -0
  19. package/examples/context-input-evidence/cli-progressive-disclosure-otel-trace.json +399 -0
  20. package/examples/context-input-evidence/cli-progressive-disclosure-receipt.ndjson +4 -0
  21. package/examples/context-input-evidence/compaction-otel-trace.json +711 -0
  22. package/examples/context-input-evidence/compaction-receipt.ndjson +6 -0
  23. package/examples/context-input-evidence/context-selection-otel-trace.json +627 -0
  24. package/examples/context-input-evidence/context-selection-receipt.ndjson +7 -0
  25. package/examples/context-input-evidence/convert-agent-overlay-log.mjs +156 -0
  26. package/examples/context-input-evidence/convert-agentgateway-progressive-disclosure-log.mjs +251 -0
  27. package/examples/context-input-evidence/convert-brain-remediation-log.mjs +241 -0
  28. package/examples/context-input-evidence/convert-claudekit-mcp-manager-log.mjs +253 -0
  29. package/examples/context-input-evidence/convert-cli-progressive-disclosure-log.mjs +251 -0
  30. package/examples/context-input-evidence/convert-compaction-log.mjs +224 -0
  31. package/examples/context-input-evidence/convert-context-selection-log.mjs +247 -0
  32. package/examples/context-input-evidence/convert-mcp-tool-search-log.mjs +242 -0
  33. package/examples/context-input-evidence/convert-memory-consolidation-log.mjs +240 -0
  34. package/examples/context-input-evidence/convert-memory-governance-delete-log.mjs +223 -0
  35. package/examples/context-input-evidence/convert-memory-log.mjs +226 -0
  36. package/examples/context-input-evidence/convert-memory-provenance-log.mjs +263 -0
  37. package/examples/context-input-evidence/convert-secret-scanning-log.mjs +233 -0
  38. package/examples/context-input-evidence/convert-session-log.mjs +186 -0
  39. package/examples/context-input-evidence/convert-skill-log.mjs +161 -0
  40. package/examples/context-input-evidence/convert-skill-registry-log.mjs +246 -0
  41. package/examples/context-input-evidence/convert-skill-routing-log.mjs +253 -0
  42. package/examples/context-input-evidence/convert-subagent-context-budget-log.mjs +267 -0
  43. package/examples/context-input-evidence/convert-subagent-delegation-log.mjs +264 -0
  44. package/examples/context-input-evidence/export-otel-trace.mjs +128 -0
  45. package/examples/context-input-evidence/generate-receipt.mjs +188 -0
  46. package/examples/context-input-evidence/mcp-tool-search-otel-trace.json +477 -0
  47. package/examples/context-input-evidence/mcp-tool-search-receipt.ndjson +5 -0
  48. package/examples/context-input-evidence/memory-consolidation-otel-trace.json +492 -0
  49. package/examples/context-input-evidence/memory-consolidation-receipt.ndjson +4 -0
  50. package/examples/context-input-evidence/memory-governance-delete-otel-trace.json +614 -0
  51. package/examples/context-input-evidence/memory-governance-delete-receipt.ndjson +5 -0
  52. package/examples/context-input-evidence/memory-otel-trace.json +645 -0
  53. package/examples/context-input-evidence/memory-provenance-otel-trace.json +711 -0
  54. package/examples/context-input-evidence/memory-provenance-receipt.ndjson +5 -0
  55. package/examples/context-input-evidence/memory-receipt.ndjson +4 -0
  56. package/examples/context-input-evidence/otel-trace.json +1119 -0
  57. package/examples/context-input-evidence/receipt.ndjson +6 -0
  58. package/examples/context-input-evidence/sample-agentgateway-progressive-disclosure-log.jsonl +5 -0
  59. package/examples/context-input-evidence/sample-brain-remediation-log.jsonl +9 -0
  60. package/examples/context-input-evidence/sample-claudekit-mcp-manager-log.jsonl +6 -0
  61. package/examples/context-input-evidence/sample-cli-progressive-disclosure-log.jsonl +5 -0
  62. package/examples/context-input-evidence/sample-compaction-log.jsonl +7 -0
  63. package/examples/context-input-evidence/sample-context-selection-log.jsonl +7 -0
  64. package/examples/context-input-evidence/sample-mcp-tool-search-log.jsonl +6 -0
  65. package/examples/context-input-evidence/sample-memory-consolidation-log.jsonl +5 -0
  66. package/examples/context-input-evidence/sample-memory-governance-delete-log.jsonl +6 -0
  67. package/examples/context-input-evidence/sample-memory-provenance-log.jsonl +6 -0
  68. package/examples/context-input-evidence/sample-memory-retrieval-log.jsonl +6 -0
  69. package/examples/context-input-evidence/sample-secret-scanning-log.jsonl +7 -0
  70. package/examples/context-input-evidence/sample-session-log.jsonl +6 -0
  71. package/examples/context-input-evidence/sample-skill-registry-log.jsonl +5 -0
  72. package/examples/context-input-evidence/sample-skill-routing-log.jsonl +7 -0
  73. package/examples/context-input-evidence/sample-subagent-context-budget-log.jsonl +6 -0
  74. package/examples/context-input-evidence/sample-subagent-delegation-log.jsonl +5 -0
  75. package/examples/context-input-evidence/secret-scanning-otel-trace.json +794 -0
  76. package/examples/context-input-evidence/secret-scanning-receipt.ndjson +6 -0
  77. package/examples/context-input-evidence/session-otel-trace.json +411 -0
  78. package/examples/context-input-evidence/session-receipt.ndjson +2 -0
  79. package/examples/context-input-evidence/skill-invocation-log.jsonl +4 -0
  80. package/examples/context-input-evidence/skill-otel-trace.json +548 -0
  81. package/examples/context-input-evidence/skill-receipt.ndjson +3 -0
  82. package/examples/context-input-evidence/skill-registry-otel-trace.json +471 -0
  83. package/examples/context-input-evidence/skill-registry-receipt.ndjson +5 -0
  84. package/examples/context-input-evidence/skill-routing-otel-trace.json +567 -0
  85. package/examples/context-input-evidence/skill-routing-receipt.ndjson +6 -0
  86. package/examples/context-input-evidence/subagent-context-budget-otel-trace.json +507 -0
  87. package/examples/context-input-evidence/subagent-context-budget-receipt.ndjson +5 -0
  88. package/examples/context-input-evidence/subagent-delegation-otel-trace.json +388 -0
  89. package/examples/context-input-evidence/subagent-delegation-receipt.ndjson +4 -0
  90. package/package.json +6 -2
  91. package/schemas/audit-result.schema.json +409 -71
  92. package/src/commands/audit.js +64 -3
  93. package/src/utils/version.js +1 -1
@@ -0,0 +1,242 @@
1
+ #!/usr/bin/env node
2
+ import { createHash } from 'node:crypto';
3
+ import { readFileSync, writeFileSync } from 'node:fs';
4
+ import { dirname, join, resolve } from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+
7
+ const here = dirname(fileURLToPath(import.meta.url));
8
+ const inputPath = process.argv[2] ? resolve(process.argv[2]) : join(here, 'sample-mcp-tool-search-log.jsonl');
9
+ const receiptPath = process.argv[3] ? resolve(process.argv[3]) : join(here, 'mcp-tool-search-receipt.ndjson');
10
+ const tracePath = process.argv[4] ? resolve(process.argv[4]) : join(here, 'mcp-tool-search-otel-trace.json');
11
+
12
+ function sha256(value) {
13
+ return `sha256:${createHash('sha256').update(value ?? '').digest('hex')}`;
14
+ }
15
+
16
+ function hashRef(value) {
17
+ return sha256(value ?? '').slice(0, 19);
18
+ }
19
+
20
+ function readJsonl(path) {
21
+ return readFileSync(path, 'utf8')
22
+ .trim()
23
+ .split('\n')
24
+ .filter(Boolean)
25
+ .map((line, index) => {
26
+ try {
27
+ return JSON.parse(line);
28
+ } catch (error) {
29
+ throw new Error(`Invalid JSONL at ${path}:${index + 1}: ${error.message}`);
30
+ }
31
+ });
32
+ }
33
+
34
+ function unixNano(isoTimestamp) {
35
+ return `${BigInt(Date.parse(isoTimestamp)) * 1_000_000n}`;
36
+ }
37
+
38
+ function otelValue(value) {
39
+ if (typeof value === 'boolean') return { boolValue: value };
40
+ if (typeof value === 'number' && Number.isInteger(value)) return { intValue: String(value) };
41
+ if (typeof value === 'number') return { doubleValue: value };
42
+ if (value == null) return { stringValue: '' };
43
+ return { stringValue: String(value) };
44
+ }
45
+
46
+ function attributesToOtel(attributes) {
47
+ return Object.entries(attributes).map(([key, value]) => ({ key, value: otelValue(value) }));
48
+ }
49
+
50
+ function tokenBucket(value) {
51
+ if (value < 1_000) return 'under_1k';
52
+ if (value < 10_000) return 'under_10k';
53
+ if (value < 50_000) return 'under_50k';
54
+ return 'over_50k';
55
+ }
56
+
57
+ function countBucket(value) {
58
+ if (value === 0) return 'zero';
59
+ if (value <= 5) return 'under_5';
60
+ if (value <= 25) return 'under_25';
61
+ return 'over_25';
62
+ }
63
+
64
+ const records = readJsonl(inputPath);
65
+ const session = records.find((record) => record.type === 'session.start');
66
+ const indexes = records.filter((record) => record.type === 'mcp.tool_index.loaded');
67
+ const search = records.find((record) => record.type === 'mcp.tool_search.performed');
68
+ const definition = records.find((record) => record.type === 'mcp.tool_definition.loaded');
69
+ const call = records.find((record) => record.type === 'mcp.tool_call.completed');
70
+
71
+ if (!session || indexes.length === 0 || !search || !definition || !call) {
72
+ throw new Error(`Expected session.start, mcp.tool_index.loaded, mcp.tool_search.performed, mcp.tool_definition.loaded, and mcp.tool_call.completed records in ${inputPath}`);
73
+ }
74
+
75
+ const traceSeed = `${session.session_id}:${session.conversation_id}:mcp-tool-search`;
76
+ const traceId = sha256(traceSeed).replace('sha256:', '').slice(0, 32);
77
+ const spanId = sha256(`${traceSeed}:span`).replace('sha256:', '').slice(0, 16);
78
+
79
+ const indexEvents = indexes.map((record) => ({
80
+ trace_id: traceId,
81
+ span_id: spanId,
82
+ name: 'mcp.tool_index.loaded',
83
+ time: record.time,
84
+ attributes: {
85
+ 'session.id': session.session_id,
86
+ 'gen_ai.conversation.id': session.conversation_id,
87
+ 'agent.name': session.agent,
88
+ 'mcp.server.name_hash': hashRef(record.server),
89
+ 'mcp.transport': record.transport,
90
+ 'mcp.tool_loading.strategy': record.startup_strategy,
91
+ 'mcp.tool.names_hash': sha256(record.tool_names.join('\n')),
92
+ 'mcp.tool.count': record.tool_names.length,
93
+ 'mcp.tool.full_definitions.loaded_at_startup': record.full_definitions_loaded,
94
+ 'mcp.tool.definition_token_count_bucket': tokenBucket(record.definition_token_count),
95
+ 'mcp.tool.index_token_count_bucket': tokenBucket(record.index_token_count),
96
+ 'mcp.tool.index_only': true,
97
+ 'privacy.raw_tool_definitions_recorded': false,
98
+ 'privacy.raw_tool_descriptions_recorded': false
99
+ }
100
+ }));
101
+
102
+ const searchEvent = {
103
+ trace_id: traceId,
104
+ span_id: spanId,
105
+ name: 'mcp.tool_search.performed',
106
+ time: search.time,
107
+ attributes: {
108
+ 'session.id': session.session_id,
109
+ 'gen_ai.conversation.id': session.conversation_id,
110
+ 'mcp.tool_search.query_hash': sha256(search.raw_query),
111
+ 'mcp.tool_search.candidate_count_bucket': countBucket(search.candidate_count),
112
+ 'mcp.tool_search.selected_server_hash': hashRef(search.selected_server),
113
+ 'mcp.tool_search.selected_tool_hash': hashRef(search.selected_tool),
114
+ 'mcp.tool_search.selection_policy': search.selection_policy,
115
+ 'mcp.tool_search.loaded_definition_count': search.loaded_definition_count,
116
+ 'mcp.tool_search.unselected_definitions_loaded': 0,
117
+ 'privacy.raw_query_recorded': false,
118
+ 'privacy.raw_candidate_rationale_recorded': false
119
+ }
120
+ };
121
+
122
+ const definitionEvent = {
123
+ trace_id: traceId,
124
+ span_id: spanId,
125
+ name: 'mcp.tool_definition.loaded',
126
+ time: definition.time,
127
+ attributes: {
128
+ 'session.id': session.session_id,
129
+ 'gen_ai.conversation.id': session.conversation_id,
130
+ 'mcp.server.name_hash': hashRef(definition.server),
131
+ 'mcp.tool.name_hash': hashRef(definition.tool),
132
+ 'mcp.tool.definition_hash': sha256(definition.raw_definition),
133
+ 'mcp.tool.definition_load_reason': definition.load_reason,
134
+ 'mcp.tool.definition_token_count_bucket': tokenBucket(definition.definition_token_count),
135
+ 'mcp.tool.definition_loaded_on_demand': true,
136
+ 'privacy.raw_tool_definition_recorded': false
137
+ }
138
+ };
139
+
140
+ const callEvent = {
141
+ trace_id: traceId,
142
+ span_id: spanId,
143
+ name: 'mcp.tool_call.completed',
144
+ time: call.time,
145
+ attributes: {
146
+ 'session.id': session.session_id,
147
+ 'gen_ai.conversation.id': session.conversation_id,
148
+ 'mcp.server.name_hash': hashRef(call.server),
149
+ 'mcp.tool.name_hash': hashRef(call.tool),
150
+ 'mcp.tool_call.status': call.status,
151
+ 'mcp.tool_call.result_count_bucket': countBucket(call.result_count),
152
+ 'mcp.tool_call.arguments_hash': sha256(call.raw_arguments),
153
+ 'mcp.tool_call.result_sample_hash': sha256(call.raw_result_sample),
154
+ 'mcp.tool_search.audit_gap': 'receipt_proves_loaded_boundary_not_selection_optimality',
155
+ 'privacy.raw_tool_arguments_recorded': false,
156
+ 'privacy.raw_tool_results_recorded': false
157
+ }
158
+ };
159
+
160
+ const events = [...indexEvents, searchEvent, definitionEvent, callEvent]
161
+ .sort((left, right) => Date.parse(left.time) - Date.parse(right.time));
162
+
163
+ writeFileSync(receiptPath, `${events.map((event) => JSON.stringify(event)).join('\n')}\n`);
164
+
165
+ const trace = {
166
+ resourceSpans: [
167
+ {
168
+ resource: {
169
+ attributes: attributesToOtel({
170
+ 'service.name': 'pluribus-mcp-tool-search-receipt-demo',
171
+ 'service.version': '0.0.0-fixture',
172
+ 'deployment.environment.name': 'local-fixture'
173
+ })
174
+ },
175
+ scopeSpans: [
176
+ {
177
+ scope: {
178
+ name: 'pluribus.context_input_evidence.mcp_tool_search_demo',
179
+ version: '0.0.0-fixture'
180
+ },
181
+ spans: [
182
+ {
183
+ traceId,
184
+ spanId,
185
+ parentSpanId: '',
186
+ name: 'agent.session.mcp.tool_search',
187
+ kind: 1,
188
+ startTimeUnixNano: unixNano(indexes[0].time),
189
+ endTimeUnixNano: unixNano(call.time),
190
+ attributes: attributesToOtel({
191
+ 'session.id': session.session_id,
192
+ 'gen_ai.conversation.id': session.conversation_id,
193
+ 'agent.name': session.agent,
194
+ 'workspace.name': session.workspace,
195
+ 'gen_ai.request.model': session.model,
196
+ 'mcp.tool_loading.strategy': 'deferred_tool_loading',
197
+ 'mcp.server.count': indexes.length
198
+ }),
199
+ events: events.map((event) => ({
200
+ name: event.name,
201
+ timeUnixNano: unixNano(event.time),
202
+ attributes: attributesToOtel(event.attributes)
203
+ }))
204
+ }
205
+ ]
206
+ }
207
+ ]
208
+ }
209
+ ]
210
+ };
211
+
212
+ writeFileSync(tracePath, `${JSON.stringify(trace, null, 2)}\n`);
213
+
214
+ const forbiddenRawStrings = [
215
+ 'private staging checkout failures',
216
+ 'private repo issue search',
217
+ 'Never expose enterprise URLs or tokens',
218
+ 'private observability tools',
219
+ 'sensitive customer-like fixture data',
220
+ 'payment token errors',
221
+ 'private-checkout-api',
222
+ 'internal trace IDs',
223
+ 'customer-like payload excerpts'
224
+ ];
225
+ const exportedText = `${events.map((event) => JSON.stringify(event)).join('\n')}\n${JSON.stringify(trace)}`;
226
+ const rawTextCopiedToReceipt = forbiddenRawStrings.some((value) => exportedText.includes(value));
227
+
228
+ const summary = {
229
+ schema: 'pluribus.mcpToolSearchReceipt.demo.v0',
230
+ eventCount: events.length,
231
+ indexedServers: indexes.length,
232
+ startupFullDefinitionsLoaded: indexes.reduce((sum, record) => sum + record.full_definitions_loaded, 0),
233
+ onDemandDefinitionsLoaded: search.loaded_definition_count,
234
+ includesToolSearchQueryHash: Boolean(searchEvent.attributes['mcp.tool_search.query_hash']),
235
+ includesAuditGap: callEvent.attributes['mcp.tool_search.audit_gap'],
236
+ rawTextCopiedToReceipt,
237
+ receiptPath: 'examples/context-input-evidence/mcp-tool-search-receipt.ndjson',
238
+ tracePath: 'examples/context-input-evidence/mcp-tool-search-otel-trace.json',
239
+ lesson: 'Deferred MCP tool loading still needs receipts: prove which tool indexes were loaded, which full definition was expanded on demand, and which private query/results stayed out of the trace.'
240
+ };
241
+
242
+ console.log(JSON.stringify(summary, null, 2));
@@ -0,0 +1,240 @@
1
+ #!/usr/bin/env node
2
+ import { createHash } from 'node:crypto';
3
+ import { readFileSync, writeFileSync } from 'node:fs';
4
+ import { dirname, join, resolve } from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+
7
+ const here = dirname(fileURLToPath(import.meta.url));
8
+ const inputPath = process.argv[2] ? resolve(process.argv[2]) : join(here, 'sample-memory-consolidation-log.jsonl');
9
+ const receiptPath = process.argv[3] ? resolve(process.argv[3]) : join(here, 'memory-consolidation-receipt.ndjson');
10
+ const tracePath = process.argv[4] ? resolve(process.argv[4]) : join(here, 'memory-consolidation-otel-trace.json');
11
+
12
+ function sha256(value) {
13
+ return `sha256:${createHash('sha256').update(value ?? '').digest('hex')}`;
14
+ }
15
+
16
+ function hashRef(value) {
17
+ return sha256(value ?? '').slice(0, 19);
18
+ }
19
+
20
+ function readJsonl(path) {
21
+ return readFileSync(path, 'utf8')
22
+ .trim()
23
+ .split('\n')
24
+ .filter(Boolean)
25
+ .map((line, index) => {
26
+ try {
27
+ return JSON.parse(line);
28
+ } catch (error) {
29
+ throw new Error(`Invalid JSONL at ${path}:${index + 1}: ${error.message}`);
30
+ }
31
+ });
32
+ }
33
+
34
+ function unixNano(isoTimestamp) {
35
+ return `${BigInt(Date.parse(isoTimestamp)) * 1_000_000n}`;
36
+ }
37
+
38
+ function otelValue(value) {
39
+ if (typeof value === 'boolean') return { boolValue: value };
40
+ if (typeof value === 'number' && Number.isInteger(value)) return { intValue: String(value) };
41
+ if (typeof value === 'number') return { doubleValue: value };
42
+ if (value == null) return { stringValue: '' };
43
+ return { stringValue: String(value) };
44
+ }
45
+
46
+ function attributesToOtel(attributes) {
47
+ return Object.entries(attributes).map(([key, value]) => ({ key, value: otelValue(value) }));
48
+ }
49
+
50
+ function countBucket(value) {
51
+ if (value === 0) return 'zero';
52
+ if (value <= 5) return 'under_5';
53
+ if (value <= 25) return 'under_25';
54
+ return 'over_25';
55
+ }
56
+
57
+ function durationBucket(ms) {
58
+ if (ms < 1_000) return 'under_1s';
59
+ if (ms < 10_000) return 'under_10s';
60
+ if (ms < 60_000) return 'under_60s';
61
+ return 'over_60s';
62
+ }
63
+
64
+ function scoreBucket(value) {
65
+ if (value < 0.4) return 'low';
66
+ if (value < 0.7) return 'medium';
67
+ if (value < 0.9) return 'high';
68
+ return 'very_high';
69
+ }
70
+
71
+ const records = readJsonl(inputPath);
72
+ const session = records.find((record) => record.type === 'session.start');
73
+ const precheck = records.find((record) => record.type === 'memory.consolidation.precheck');
74
+ const cluster = records.find((record) => record.type === 'memory.consolidation.cluster.selected');
75
+ const output = records.find((record) => record.type === 'memory.consolidation.output.created');
76
+ const completed = records.find((record) => record.type === 'memory.consolidation.completed');
77
+
78
+ if (!session || !precheck || !cluster || !output || !completed) {
79
+ throw new Error(`Expected session.start, memory.consolidation.precheck, cluster.selected, output.created, and completed records in ${inputPath}`);
80
+ }
81
+
82
+ const traceSeed = `${session.session_id}:${session.conversation_id}:memory-consolidation`;
83
+ const traceId = sha256(traceSeed).replace('sha256:', '').slice(0, 32);
84
+ const spanId = sha256(`${traceSeed}:span`).replace('sha256:', '').slice(0, 16);
85
+
86
+ const precheckEvent = {
87
+ trace_id: traceId,
88
+ span_id: spanId,
89
+ name: 'memory.consolidation.precheck',
90
+ time: precheck.time,
91
+ attributes: {
92
+ 'session.id': session.session_id,
93
+ 'gen_ai.conversation.id': session.conversation_id,
94
+ 'agent.name': session.agent,
95
+ 'memory.provider': precheck.provider,
96
+ 'memory.client': precheck.client,
97
+ 'memory.project.hash': hashRef(precheck.project),
98
+ 'memory.consolidation.mode': precheck.mode,
99
+ 'memory.consolidation.trigger': precheck.trigger,
100
+ 'memory.consolidation.horizon': precheck.horizon,
101
+ 'memory.consolidation.last_run_at_hash': hashRef(precheck.last_run_at),
102
+ 'memory.consolidation.candidate_count': precheck.candidate_count,
103
+ 'memory.consolidation.candidate_count_bucket': countBucket(precheck.candidate_count),
104
+ 'memory.consolidation.candidate_ids_hash': sha256(precheck.candidate_ids.join('\n')),
105
+ 'memory.consolidation.project_path_hash': sha256(precheck.project_path),
106
+ 'memory.consolidation.precheck_latency_bucket': durationBucket(precheck.latency_ms),
107
+ 'privacy.raw_candidate_text_recorded': false,
108
+ 'privacy.raw_project_path_recorded': false
109
+ }
110
+ };
111
+
112
+ const clusterEvent = {
113
+ trace_id: traceId,
114
+ span_id: spanId,
115
+ name: 'memory.consolidation.cluster.selected',
116
+ time: cluster.time,
117
+ attributes: {
118
+ 'session.id': session.session_id,
119
+ 'gen_ai.conversation.id': session.conversation_id,
120
+ 'memory.consolidation.cluster.hash': hashRef(cluster.cluster_id),
121
+ 'memory.consolidation.cluster.strategy': cluster.strategy,
122
+ 'memory.consolidation.cluster.source_count': cluster.source_count,
123
+ 'memory.consolidation.cluster.source_ids_hash': sha256(cluster.source_ids.join('\n')),
124
+ 'memory.consolidation.cluster.topic_hash': sha256(cluster.topic),
125
+ 'memory.consolidation.cluster.similarity_bucket': cluster.similarity_bucket,
126
+ 'memory.consolidation.cluster.max_source_age_minutes_bucket': countBucket(cluster.max_source_age_minutes),
127
+ 'privacy.raw_cluster_notes_recorded': false,
128
+ 'privacy.raw_memory_text_recorded': false
129
+ }
130
+ };
131
+
132
+ const outputEvent = {
133
+ trace_id: traceId,
134
+ span_id: spanId,
135
+ name: 'memory.consolidation.output.created',
136
+ time: output.time,
137
+ attributes: {
138
+ 'session.id': session.session_id,
139
+ 'gen_ai.conversation.id': session.conversation_id,
140
+ 'memory.consolidation.output.hash': hashRef(output.consolidated_id),
141
+ 'memory.consolidation.cluster.hash': hashRef(output.cluster_id),
142
+ 'memory.consolidation.output.source_ids_hash': sha256(output.source_ids.join('\n')),
143
+ 'memory.consolidation.output.memory_type': output.memory_type,
144
+ 'memory.consolidation.output.lineage_edge': output.lineage_edge,
145
+ 'memory.consolidation.output.content_hash': sha256(output.raw_consolidated_memory),
146
+ 'memory.consolidation.quality_score_before_bucket': scoreBucket(output.quality_score_before),
147
+ 'memory.consolidation.quality_score_after_bucket': scoreBucket(output.quality_score_after),
148
+ 'memory.consolidation.changed_entity_count_bucket': countBucket(output.changed_entities.length),
149
+ 'memory.consolidation.changed_entities_hash': sha256(output.changed_entities.join('\n')),
150
+ 'memory.consolidation.output_latency_bucket': durationBucket(output.latency_ms),
151
+ 'privacy.raw_consolidated_memory_recorded': false,
152
+ 'privacy.raw_entity_names_recorded': false
153
+ }
154
+ };
155
+
156
+ const completedEvent = {
157
+ trace_id: traceId,
158
+ span_id: spanId,
159
+ name: 'memory.consolidation.completed',
160
+ time: completed.time,
161
+ attributes: {
162
+ 'session.id': session.session_id,
163
+ 'gen_ai.conversation.id': session.conversation_id,
164
+ 'memory.provider': completed.provider,
165
+ 'memory.client': completed.client,
166
+ 'memory.project.hash': hashRef(completed.project),
167
+ 'memory.consolidation.mode': completed.mode,
168
+ 'memory.consolidation.trigger': completed.trigger,
169
+ 'memory.consolidation.candidate_count': completed.candidate_count,
170
+ 'memory.consolidation.cluster_count': completed.cluster_count,
171
+ 'memory.consolidation.consolidated_count': completed.consolidated_count,
172
+ 'memory.consolidation.skipped_count': completed.skipped_count,
173
+ 'memory.consolidation.duration_bucket': durationBucket(completed.duration_ms),
174
+ 'memory.consolidation.latency_budget_bucket': durationBucket(completed.latency_budget_ms),
175
+ 'memory.consolidation.within_latency_budget': completed.duration_ms <= completed.latency_budget_ms,
176
+ 'memory.consolidation.status': completed.status,
177
+ 'memory.consolidation.next_cursor_hash': hashRef(completed.next_cursor),
178
+ 'memory.consolidation.audit_gap': 'receipt_proves_bounded_run_and_lineage_not_summary_correctness',
179
+ 'privacy.raw_operator_note_recorded': false,
180
+ 'privacy.raw_memory_text_recorded': false
181
+ }
182
+ };
183
+
184
+ const events = [precheckEvent, clusterEvent, outputEvent, completedEvent]
185
+ .sort((left, right) => Date.parse(left.time) - Date.parse(right.time));
186
+
187
+ writeFileSync(receiptPath, `${events.map((event) => JSON.stringify(event)).join('\n')}\n`);
188
+
189
+ const trace = {
190
+ resourceSpans: [
191
+ {
192
+ resource: {
193
+ attributes: attributesToOtel({
194
+ 'service.name': 'pluribus-memory-consolidation-receipt-demo',
195
+ 'service.version': '0.0.0-fixture',
196
+ 'deployment.environment.name': 'local-fixture'
197
+ })
198
+ },
199
+ scopeSpans: [
200
+ {
201
+ scope: {
202
+ name: 'pluribus.context_input_evidence.memory_consolidation_demo',
203
+ version: '0.0.0-fixture'
204
+ },
205
+ spans: [
206
+ {
207
+ traceId,
208
+ spanId,
209
+ parentSpanId: '',
210
+ name: 'agent.session.memory.consolidation',
211
+ kind: 1,
212
+ startTimeUnixNano: unixNano(precheck.time),
213
+ endTimeUnixNano: unixNano(completed.time),
214
+ attributes: attributesToOtel({
215
+ 'session.id': session.session_id,
216
+ 'gen_ai.conversation.id': session.conversation_id,
217
+ 'agent.name': session.agent,
218
+ 'workspace.name': session.workspace,
219
+ 'gen_ai.request.model': session.model,
220
+ 'memory.consolidation.mode': completed.mode,
221
+ 'memory.consolidation.trigger': completed.trigger
222
+ }),
223
+ events: events.map((event) => ({
224
+ name: event.name,
225
+ timeUnixNano: unixNano(event.time),
226
+ attributes: attributesToOtel(event.attributes)
227
+ })),
228
+ status: { code: 1 }
229
+ }
230
+ ]
231
+ }
232
+ ]
233
+ }
234
+ ]
235
+ };
236
+
237
+ writeFileSync(tracePath, `${JSON.stringify(trace, null, 2)}\n`);
238
+
239
+ console.log(`Wrote ${events.length} memory consolidation receipt events to ${receiptPath}`);
240
+ console.log(`Wrote OTel-style trace to ${tracePath}`);