pluribus-context 0.3.22 → 0.3.27
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.
- package/CHANGELOG.md +33 -3
- package/README.md +9 -2
- package/docs/community-review-packet.md +10 -2
- package/docs/context-budget-receipts.md +152 -0
- package/docs/context-input-evidence.md +397 -0
- package/docs/context-receipts-for-agent-observability.md +177 -0
- package/docs/orchestration-search-receipts.md +102 -0
- package/docs/portability-fidelity-report.md +4 -2
- package/examples/agent-skills/context-receipts/README.md +22 -0
- package/examples/agent-skills/context-receipts/SKILL.md +89 -0
- package/examples/context-input-evidence/AGENTS.md +12 -0
- package/examples/context-input-evidence/agent-overlay-log.jsonl +4 -0
- package/examples/context-input-evidence/agent-overlay-otel-trace.json +548 -0
- package/examples/context-input-evidence/agent-overlay-receipt.ndjson +3 -0
- package/examples/context-input-evidence/agentgateway-progressive-disclosure-otel-trace.json +393 -0
- package/examples/context-input-evidence/agentgateway-progressive-disclosure-receipt.ndjson +4 -0
- package/examples/context-input-evidence/brain-remediation-otel-trace.json +645 -0
- package/examples/context-input-evidence/brain-remediation-receipt.ndjson +7 -0
- package/examples/context-input-evidence/claudekit-mcp-manager-otel-trace.json +417 -0
- package/examples/context-input-evidence/claudekit-mcp-manager-receipt.ndjson +5 -0
- package/examples/context-input-evidence/cli-progressive-disclosure-otel-trace.json +399 -0
- package/examples/context-input-evidence/cli-progressive-disclosure-receipt.ndjson +4 -0
- package/examples/context-input-evidence/compaction-otel-trace.json +711 -0
- package/examples/context-input-evidence/compaction-receipt.ndjson +6 -0
- package/examples/context-input-evidence/context-selection-otel-trace.json +627 -0
- package/examples/context-input-evidence/context-selection-receipt.ndjson +7 -0
- package/examples/context-input-evidence/convert-agent-overlay-log.mjs +156 -0
- package/examples/context-input-evidence/convert-agentgateway-progressive-disclosure-log.mjs +251 -0
- package/examples/context-input-evidence/convert-brain-remediation-log.mjs +241 -0
- package/examples/context-input-evidence/convert-claudekit-mcp-manager-log.mjs +253 -0
- package/examples/context-input-evidence/convert-cli-progressive-disclosure-log.mjs +251 -0
- package/examples/context-input-evidence/convert-compaction-log.mjs +224 -0
- package/examples/context-input-evidence/convert-context-selection-log.mjs +247 -0
- package/examples/context-input-evidence/convert-mcp-tool-search-log.mjs +242 -0
- package/examples/context-input-evidence/convert-memory-consolidation-log.mjs +240 -0
- package/examples/context-input-evidence/convert-memory-governance-delete-log.mjs +223 -0
- package/examples/context-input-evidence/convert-memory-log.mjs +226 -0
- package/examples/context-input-evidence/convert-memory-provenance-log.mjs +263 -0
- package/examples/context-input-evidence/convert-secret-scanning-log.mjs +233 -0
- package/examples/context-input-evidence/convert-session-log.mjs +186 -0
- package/examples/context-input-evidence/convert-skill-log.mjs +161 -0
- package/examples/context-input-evidence/convert-skill-registry-log.mjs +246 -0
- package/examples/context-input-evidence/convert-skill-routing-log.mjs +253 -0
- package/examples/context-input-evidence/convert-subagent-context-budget-log.mjs +267 -0
- package/examples/context-input-evidence/convert-subagent-delegation-log.mjs +264 -0
- package/examples/context-input-evidence/export-otel-trace.mjs +128 -0
- package/examples/context-input-evidence/generate-receipt.mjs +188 -0
- package/examples/context-input-evidence/mcp-tool-search-otel-trace.json +477 -0
- package/examples/context-input-evidence/mcp-tool-search-receipt.ndjson +5 -0
- package/examples/context-input-evidence/memory-consolidation-otel-trace.json +492 -0
- package/examples/context-input-evidence/memory-consolidation-receipt.ndjson +4 -0
- package/examples/context-input-evidence/memory-governance-delete-otel-trace.json +614 -0
- package/examples/context-input-evidence/memory-governance-delete-receipt.ndjson +5 -0
- package/examples/context-input-evidence/memory-otel-trace.json +645 -0
- package/examples/context-input-evidence/memory-provenance-otel-trace.json +711 -0
- package/examples/context-input-evidence/memory-provenance-receipt.ndjson +5 -0
- package/examples/context-input-evidence/memory-receipt.ndjson +4 -0
- package/examples/context-input-evidence/otel-trace.json +1119 -0
- package/examples/context-input-evidence/receipt.ndjson +6 -0
- package/examples/context-input-evidence/sample-agentgateway-progressive-disclosure-log.jsonl +5 -0
- package/examples/context-input-evidence/sample-brain-remediation-log.jsonl +9 -0
- package/examples/context-input-evidence/sample-claudekit-mcp-manager-log.jsonl +6 -0
- package/examples/context-input-evidence/sample-cli-progressive-disclosure-log.jsonl +5 -0
- package/examples/context-input-evidence/sample-compaction-log.jsonl +7 -0
- package/examples/context-input-evidence/sample-context-selection-log.jsonl +7 -0
- package/examples/context-input-evidence/sample-mcp-tool-search-log.jsonl +6 -0
- package/examples/context-input-evidence/sample-memory-consolidation-log.jsonl +5 -0
- package/examples/context-input-evidence/sample-memory-governance-delete-log.jsonl +6 -0
- package/examples/context-input-evidence/sample-memory-provenance-log.jsonl +6 -0
- package/examples/context-input-evidence/sample-memory-retrieval-log.jsonl +6 -0
- package/examples/context-input-evidence/sample-secret-scanning-log.jsonl +7 -0
- package/examples/context-input-evidence/sample-session-log.jsonl +6 -0
- package/examples/context-input-evidence/sample-skill-registry-log.jsonl +5 -0
- package/examples/context-input-evidence/sample-skill-routing-log.jsonl +7 -0
- package/examples/context-input-evidence/sample-subagent-context-budget-log.jsonl +6 -0
- package/examples/context-input-evidence/sample-subagent-delegation-log.jsonl +5 -0
- package/examples/context-input-evidence/secret-scanning-otel-trace.json +794 -0
- package/examples/context-input-evidence/secret-scanning-receipt.ndjson +6 -0
- package/examples/context-input-evidence/session-otel-trace.json +411 -0
- package/examples/context-input-evidence/session-receipt.ndjson +2 -0
- package/examples/context-input-evidence/skill-invocation-log.jsonl +4 -0
- package/examples/context-input-evidence/skill-otel-trace.json +548 -0
- package/examples/context-input-evidence/skill-receipt.ndjson +3 -0
- package/examples/context-input-evidence/skill-registry-otel-trace.json +471 -0
- package/examples/context-input-evidence/skill-registry-receipt.ndjson +5 -0
- package/examples/context-input-evidence/skill-routing-otel-trace.json +567 -0
- package/examples/context-input-evidence/skill-routing-receipt.ndjson +6 -0
- package/examples/context-input-evidence/subagent-context-budget-otel-trace.json +507 -0
- package/examples/context-input-evidence/subagent-context-budget-receipt.ndjson +5 -0
- package/examples/context-input-evidence/subagent-delegation-otel-trace.json +388 -0
- package/examples/context-input-evidence/subagent-delegation-receipt.ndjson +4 -0
- package/package.json +6 -2
- package/schemas/audit-result.schema.json +409 -71
- package/src/commands/audit.js +64 -3
- package/src/utils/version.js +1 -1
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { dirname, join } from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
|
|
7
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
const inputPath = join(here, 'agent-overlay-log.jsonl');
|
|
9
|
+
const receiptPath = join(here, 'agent-overlay-receipt.ndjson');
|
|
10
|
+
const tracePath = join(here, 'agent-overlay-otel-trace.json');
|
|
11
|
+
|
|
12
|
+
function sha256(value) {
|
|
13
|
+
return `sha256:${createHash('sha256').update(value).digest('hex')}`;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function parseJsonl(filePath) {
|
|
17
|
+
return readFileSync(filePath, 'utf8')
|
|
18
|
+
.trim()
|
|
19
|
+
.split('\n')
|
|
20
|
+
.filter(Boolean)
|
|
21
|
+
.map((line) => JSON.parse(line));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function attributeValue(value) {
|
|
25
|
+
if (typeof value === 'boolean') return { boolValue: value };
|
|
26
|
+
if (typeof value === 'number') return { intValue: value };
|
|
27
|
+
return { stringValue: String(value ?? '') };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function toOtelAttributes(attributes) {
|
|
31
|
+
return Object.entries(attributes).map(([key, value]) => ({
|
|
32
|
+
key,
|
|
33
|
+
value: attributeValue(value)
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const records = parseJsonl(inputPath);
|
|
38
|
+
const session = records.find((record) => record.type === 'session.start');
|
|
39
|
+
if (!session) {
|
|
40
|
+
throw new Error('agent-overlay-log.jsonl must contain a session.start record');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const contextRecords = records.filter((record) => record.type === 'agent_context.loaded');
|
|
44
|
+
const events = contextRecords.map((record) => {
|
|
45
|
+
const loaded = record.activation !== 'not_loaded_wrong_agent' && record.delivered_text.length > 0;
|
|
46
|
+
const sourceBytesHash = sha256(record.source_text);
|
|
47
|
+
const deliveredHash = loaded ? sha256(record.delivered_text) : '';
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
trace_id: 'demo-trace-agent-overlays',
|
|
51
|
+
span_id: session.session_id,
|
|
52
|
+
name: loaded ? 'context.input.loaded' : 'context.input.candidate_suppressed',
|
|
53
|
+
time: record.time,
|
|
54
|
+
attributes: {
|
|
55
|
+
'context.input.kind': 'agent_instructions',
|
|
56
|
+
'context.input.source.path': record.source_path,
|
|
57
|
+
'context.input.source.role': record.source_role,
|
|
58
|
+
'context.input.source.bytes_hash': sourceBytesHash,
|
|
59
|
+
'context.input.delivered.hash': deliveredHash,
|
|
60
|
+
'context.input.delivered.truncated': false,
|
|
61
|
+
'session.id': session.session_id,
|
|
62
|
+
'gen_ai.conversation.id': session.conversation_id,
|
|
63
|
+
'agent.name': session.agent,
|
|
64
|
+
'workspace.name': session.workspace,
|
|
65
|
+
'context.input.loaded_by': loaded ? 'native-file-discovery' : 'overlay-selector',
|
|
66
|
+
'context.input.activation': record.activation,
|
|
67
|
+
'context.input.scope': 'repo',
|
|
68
|
+
'context.input.applies_to': record.target_agent,
|
|
69
|
+
'context.input.load_order': record.load_order,
|
|
70
|
+
'context.input.composition_policy': record.composition_policy,
|
|
71
|
+
'context.input.fallback_policy': record.fallback_policy,
|
|
72
|
+
'context.input.why_loaded': record.why_loaded,
|
|
73
|
+
'context.input.expected_benefit': record.expected_benefit,
|
|
74
|
+
'context.input.duplicate.dedupe_scope': 'conversation',
|
|
75
|
+
'context.input.duplicate.suppression_policy': loaded
|
|
76
|
+
? 'keep_distinct_source_roles_in_order'
|
|
77
|
+
: 'suppress_overlay_for_non_target_agent',
|
|
78
|
+
'context.input.duplicate.role': loaded ? 'selected' : 'suppressed',
|
|
79
|
+
'privacy.raw_context_recorded': false,
|
|
80
|
+
'privacy.raw_prompt_recorded': false,
|
|
81
|
+
'privacy.raw_tool_args_recorded': false
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
writeFileSync(receiptPath, `${events.map((event) => JSON.stringify(event)).join('\n')}\n`);
|
|
87
|
+
|
|
88
|
+
const trace = {
|
|
89
|
+
resourceSpans: [
|
|
90
|
+
{
|
|
91
|
+
resource: {
|
|
92
|
+
attributes: toOtelAttributes({
|
|
93
|
+
'service.name': 'pluribus-context-input-evidence',
|
|
94
|
+
'telemetry.sdk.language': 'javascript',
|
|
95
|
+
'pluribus.demo': 'agent-overlay-receipts'
|
|
96
|
+
})
|
|
97
|
+
},
|
|
98
|
+
scopeSpans: [
|
|
99
|
+
{
|
|
100
|
+
scope: { name: 'pluribus.context-input-evidence', version: '0.0.0-demo' },
|
|
101
|
+
spans: [
|
|
102
|
+
{
|
|
103
|
+
traceId: 'demo-trace-agent-overlays',
|
|
104
|
+
spanId: session.session_id,
|
|
105
|
+
name: 'agent.session',
|
|
106
|
+
kind: 'SPAN_KIND_INTERNAL',
|
|
107
|
+
startTimeUnixNano: '0',
|
|
108
|
+
endTimeUnixNano: '0',
|
|
109
|
+
attributes: toOtelAttributes({
|
|
110
|
+
'session.id': session.session_id,
|
|
111
|
+
'gen_ai.conversation.id': session.conversation_id,
|
|
112
|
+
'agent.name': session.agent,
|
|
113
|
+
'workspace.name': session.workspace,
|
|
114
|
+
'privacy.raw_context_recorded': false
|
|
115
|
+
}),
|
|
116
|
+
events: events.map((event) => ({
|
|
117
|
+
name: event.name,
|
|
118
|
+
timeUnixNano: '0',
|
|
119
|
+
attributes: toOtelAttributes(event.attributes)
|
|
120
|
+
}))
|
|
121
|
+
}
|
|
122
|
+
]
|
|
123
|
+
}
|
|
124
|
+
]
|
|
125
|
+
}
|
|
126
|
+
]
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
writeFileSync(tracePath, `${JSON.stringify(trace, null, 2)}\n`);
|
|
130
|
+
|
|
131
|
+
const loaded = events.filter((event) => event.name === 'context.input.loaded');
|
|
132
|
+
const suppressed = events.filter((event) => event.name === 'context.input.candidate_suppressed');
|
|
133
|
+
const rawLeakStrings = [
|
|
134
|
+
'Prefer small reviewable changes',
|
|
135
|
+
'Cursor-specific workspace rule hints',
|
|
136
|
+
'Codex-specific sandbox notes'
|
|
137
|
+
];
|
|
138
|
+
const traceText = JSON.stringify(trace);
|
|
139
|
+
const receiptText = events.map((event) => JSON.stringify(event)).join('\n');
|
|
140
|
+
const leaksRawText = rawLeakStrings.some((value) => traceText.includes(value) || receiptText.includes(value));
|
|
141
|
+
|
|
142
|
+
const summary = {
|
|
143
|
+
schema: 'pluribus.agentOverlayReceipt.demo.v0',
|
|
144
|
+
eventCount: events.length,
|
|
145
|
+
loadedContextInputs: loaded.length,
|
|
146
|
+
suppressedOverlayCandidates: suppressed.length,
|
|
147
|
+
loadedSourceRoles: loaded.map((event) => event.attributes['context.input.source.role']),
|
|
148
|
+
compositionPolicies: [...new Set(events.map((event) => event.attributes['context.input.composition_policy']))],
|
|
149
|
+
includesLoadOrder: events.every((event) => Number.isInteger(event.attributes['context.input.load_order'])),
|
|
150
|
+
rawTextCopiedToReceipt: leaksRawText,
|
|
151
|
+
receiptPath: 'examples/context-input-evidence/agent-overlay-receipt.ndjson',
|
|
152
|
+
tracePath: 'examples/context-input-evidence/agent-overlay-otel-trace.json',
|
|
153
|
+
lesson: 'Agent-specific AGENTS.md overlays need load-order, target-agent, fallback, and suppression receipts; otherwise composition is a naming convention, not evidence.'
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
console.log(JSON.stringify(summary, null, 2));
|
|
@@ -0,0 +1,251 @@
|
|
|
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-agentgateway-progressive-disclosure-log.jsonl');
|
|
9
|
+
const receiptPath = process.argv[3] ? resolve(process.argv[3]) : join(here, 'agentgateway-progressive-disclosure-receipt.ndjson');
|
|
10
|
+
const tracePath = process.argv[4] ? resolve(process.argv[4]) : join(here, 'agentgateway-progressive-disclosure-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 < 100) return 'under_100';
|
|
52
|
+
if (value < 1_000) return 'under_1k';
|
|
53
|
+
if (value < 10_000) return 'under_10k';
|
|
54
|
+
if (value < 50_000) return 'under_50k';
|
|
55
|
+
return 'over_50k';
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function byteBucket(value) {
|
|
59
|
+
if (value === 0) return 'zero';
|
|
60
|
+
if (value < 1_000) return 'under_1kb';
|
|
61
|
+
if (value < 10_000) return 'under_10kb';
|
|
62
|
+
if (value < 100_000) return 'under_100kb';
|
|
63
|
+
return 'over_100kb';
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function countBucket(value) {
|
|
67
|
+
if (value === 0) return 'zero';
|
|
68
|
+
if (value <= 5) return 'under_5';
|
|
69
|
+
if (value <= 25) return 'under_25';
|
|
70
|
+
if (value <= 100) return 'under_100';
|
|
71
|
+
return 'over_100';
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const records = readJsonl(inputPath);
|
|
75
|
+
const session = records.find((record) => record.type === 'session.start');
|
|
76
|
+
const index = records.find((record) => record.type === 'mcp.gateway.index.loaded');
|
|
77
|
+
const schema = records.find((record) => record.type === 'mcp.gateway.tool_schema.loaded');
|
|
78
|
+
const invoke = records.find((record) => record.type === 'mcp.gateway.tool_invoked');
|
|
79
|
+
const completed = records.find((record) => record.type === 'mcp.gateway.session.completed');
|
|
80
|
+
|
|
81
|
+
if (!session || !index || !schema || !invoke || !completed) {
|
|
82
|
+
throw new Error(`Expected session.start, mcp.gateway.index.loaded, mcp.gateway.tool_schema.loaded, mcp.gateway.tool_invoked, and mcp.gateway.session.completed records in ${inputPath}`);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const traceSeed = `${session.session_id}:${session.conversation_id}:agentgateway-progressive-disclosure`;
|
|
86
|
+
const traceId = sha256(traceSeed).replace('sha256:', '').slice(0, 32);
|
|
87
|
+
const spanId = sha256(`${traceSeed}:span`).replace('sha256:', '').slice(0, 16);
|
|
88
|
+
|
|
89
|
+
const events = [
|
|
90
|
+
{
|
|
91
|
+
trace_id: traceId,
|
|
92
|
+
span_id: spanId,
|
|
93
|
+
name: 'mcp.gateway.index.loaded',
|
|
94
|
+
time: index.time,
|
|
95
|
+
attributes: {
|
|
96
|
+
'session.id': session.session_id,
|
|
97
|
+
'gen_ai.conversation.id': session.conversation_id,
|
|
98
|
+
'agent.name': session.agent,
|
|
99
|
+
'mcp.gateway.name': index.gateway,
|
|
100
|
+
'mcp.gateway.tool_mode': index.mode,
|
|
101
|
+
'mcp.gateway.visible_tools_hash': sha256(index.client_visible_tools.join('\n')),
|
|
102
|
+
'mcp.gateway.visible_tool_count': index.client_visible_tools.length,
|
|
103
|
+
'mcp.gateway.upstream_server_hash': hashRef(index.upstream_server),
|
|
104
|
+
'mcp.gateway.upstream_tool_count_bucket': countBucket(index.upstream_tool_count),
|
|
105
|
+
'mcp.gateway.full_schema_token_count_bucket': tokenBucket(index.full_upstream_schema_token_count),
|
|
106
|
+
'mcp.gateway.visible_index_token_count_bucket': tokenBucket(index.visible_index_token_count),
|
|
107
|
+
'mcp.gateway.full_upstream_schemas_loaded_at_startup': false,
|
|
108
|
+
'privacy.raw_index_recorded': false,
|
|
109
|
+
'privacy.raw_upstream_tool_schemas_recorded': false
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
trace_id: traceId,
|
|
114
|
+
span_id: spanId,
|
|
115
|
+
name: 'mcp.gateway.tool_schema.loaded',
|
|
116
|
+
time: schema.time,
|
|
117
|
+
attributes: {
|
|
118
|
+
'session.id': session.session_id,
|
|
119
|
+
'gen_ai.conversation.id': session.conversation_id,
|
|
120
|
+
'mcp.gateway.name': schema.gateway,
|
|
121
|
+
'mcp.tool.name_hash': hashRef(schema.tool),
|
|
122
|
+
'mcp.tool.schema_command_hash': hashRef(schema.schema_command),
|
|
123
|
+
'mcp.tool.schema_hash': sha256(schema.raw_schema),
|
|
124
|
+
'mcp.tool.schema_token_count_bucket': tokenBucket(schema.schema_token_count),
|
|
125
|
+
'mcp.tool.schema_load_reason_hash': hashRef(schema.selection_reason),
|
|
126
|
+
'mcp.tool.unselected_tools_hash': sha256(schema.unselected_tool_names.join('\n')),
|
|
127
|
+
'mcp.tool.unselected_schema_loaded_count': schema.unselected_schema_loaded_count,
|
|
128
|
+
'privacy.raw_tool_schema_recorded': false,
|
|
129
|
+
'privacy.raw_unselected_tool_names_recorded': false
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
trace_id: traceId,
|
|
134
|
+
span_id: spanId,
|
|
135
|
+
name: 'mcp.gateway.tool_invoked',
|
|
136
|
+
time: invoke.time,
|
|
137
|
+
attributes: {
|
|
138
|
+
'session.id': session.session_id,
|
|
139
|
+
'gen_ai.conversation.id': session.conversation_id,
|
|
140
|
+
'mcp.gateway.name': invoke.gateway,
|
|
141
|
+
'mcp.tool.name_hash': hashRef(invoke.tool),
|
|
142
|
+
'mcp.tool_call.status': invoke.status,
|
|
143
|
+
'mcp.tool_call.arguments_hash': sha256(invoke.raw_arguments),
|
|
144
|
+
'mcp.tool_call.result_sample_hash': sha256(invoke.raw_result_sample),
|
|
145
|
+
'mcp.tool_call.result_count_bucket': countBucket(invoke.result_count),
|
|
146
|
+
'mcp.tool_call.latency_ms': invoke.latency_ms,
|
|
147
|
+
'mcp.tool_call.response_size_bucket': byteBucket(invoke.response_bytes),
|
|
148
|
+
'privacy.raw_tool_arguments_recorded': false,
|
|
149
|
+
'privacy.raw_tool_results_recorded': false
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
trace_id: traceId,
|
|
154
|
+
span_id: spanId,
|
|
155
|
+
name: 'mcp.gateway.session.completed',
|
|
156
|
+
time: completed.time,
|
|
157
|
+
attributes: {
|
|
158
|
+
'session.id': session.session_id,
|
|
159
|
+
'gen_ai.conversation.id': session.conversation_id,
|
|
160
|
+
'mcp.gateway.session.status': completed.status,
|
|
161
|
+
'mcp.gateway.full_upstream_schemas_loaded': completed.full_upstream_schemas_loaded,
|
|
162
|
+
'mcp.gateway.loaded_tool_schema_count': completed.loaded_tool_schema_count,
|
|
163
|
+
'mcp.gateway.invoked_tool_count': completed.invoked_tool_count,
|
|
164
|
+
'mcp.gateway.progressive_disclosure.audit_gap': completed.audit_gap
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
];
|
|
168
|
+
|
|
169
|
+
writeFileSync(receiptPath, `${events.map((event) => JSON.stringify(event)).join('\n')}\n`);
|
|
170
|
+
|
|
171
|
+
const trace = {
|
|
172
|
+
resourceSpans: [
|
|
173
|
+
{
|
|
174
|
+
resource: {
|
|
175
|
+
attributes: attributesToOtel({
|
|
176
|
+
'service.name': 'pluribus-agentgateway-progressive-disclosure-receipt-demo',
|
|
177
|
+
'service.version': '0.0.0-fixture',
|
|
178
|
+
'deployment.environment.name': 'local-fixture'
|
|
179
|
+
})
|
|
180
|
+
},
|
|
181
|
+
scopeSpans: [
|
|
182
|
+
{
|
|
183
|
+
scope: {
|
|
184
|
+
name: 'pluribus.context_input_evidence.agentgateway_progressive_disclosure_demo',
|
|
185
|
+
version: '0.0.0-fixture'
|
|
186
|
+
},
|
|
187
|
+
spans: [
|
|
188
|
+
{
|
|
189
|
+
traceId,
|
|
190
|
+
spanId,
|
|
191
|
+
parentSpanId: '',
|
|
192
|
+
name: 'agent.session.mcp.gateway.progressive_disclosure',
|
|
193
|
+
kind: 1,
|
|
194
|
+
startTimeUnixNano: unixNano(index.time),
|
|
195
|
+
endTimeUnixNano: unixNano(completed.time),
|
|
196
|
+
attributes: attributesToOtel({
|
|
197
|
+
'session.id': session.session_id,
|
|
198
|
+
'gen_ai.conversation.id': session.conversation_id,
|
|
199
|
+
'agent.name': session.agent,
|
|
200
|
+
'workspace.name': session.workspace,
|
|
201
|
+
'gen_ai.request.model': session.model,
|
|
202
|
+
'mcp.gateway.name': index.gateway,
|
|
203
|
+
'mcp.gateway.tool_mode': index.mode,
|
|
204
|
+
'mcp.gateway.disclosure.strategy': 'visible_index_then_get_tool_invoke_tool'
|
|
205
|
+
}),
|
|
206
|
+
events: events.map((event) => ({
|
|
207
|
+
name: event.name,
|
|
208
|
+
timeUnixNano: unixNano(event.time),
|
|
209
|
+
attributes: attributesToOtel(event.attributes)
|
|
210
|
+
}))
|
|
211
|
+
}
|
|
212
|
+
]
|
|
213
|
+
}
|
|
214
|
+
]
|
|
215
|
+
}
|
|
216
|
+
]
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
writeFileSync(tracePath, `${JSON.stringify(trace, null, 2)}\n`);
|
|
220
|
+
|
|
221
|
+
const forbiddenRawStrings = [
|
|
222
|
+
'Acme-Co',
|
|
223
|
+
'sk_live_gateway_fixture',
|
|
224
|
+
'finance@acme.example',
|
|
225
|
+
'private-enterprise-mcp',
|
|
226
|
+
'support.ticket.search',
|
|
227
|
+
'TICKET-private-001',
|
|
228
|
+
'Stripe prod incident',
|
|
229
|
+
'private-support-ops'
|
|
230
|
+
];
|
|
231
|
+
const exportedText = `${events.map((event) => JSON.stringify(event)).join('\n')}\n${JSON.stringify(trace)}`;
|
|
232
|
+
const rawTextCopiedToReceipt = forbiddenRawStrings.some((value) => exportedText.includes(value));
|
|
233
|
+
|
|
234
|
+
const summary = {
|
|
235
|
+
schema: 'pluribus.agentgatewayProgressiveDisclosureReceipt.demo.v0',
|
|
236
|
+
eventCount: events.length,
|
|
237
|
+
visibleToolCount: index.client_visible_tools.length,
|
|
238
|
+
upstreamToolCountBucket: events[0].attributes['mcp.gateway.upstream_tool_count_bucket'],
|
|
239
|
+
fullSchemaTokenBucket: events[0].attributes['mcp.gateway.full_schema_token_count_bucket'],
|
|
240
|
+
visibleIndexTokenBucket: events[0].attributes['mcp.gateway.visible_index_token_count_bucket'],
|
|
241
|
+
loadedToolSchemaCount: completed.loaded_tool_schema_count,
|
|
242
|
+
fullUpstreamSchemasLoaded: completed.full_upstream_schemas_loaded,
|
|
243
|
+
includesArgumentsHash: Boolean(events[2].attributes['mcp.tool_call.arguments_hash']),
|
|
244
|
+
includesResultSampleHash: Boolean(events[2].attributes['mcp.tool_call.result_sample_hash']),
|
|
245
|
+
rawTextCopiedToReceipt,
|
|
246
|
+
receiptPath: 'examples/context-input-evidence/agentgateway-progressive-disclosure-receipt.ndjson',
|
|
247
|
+
tracePath: 'examples/context-input-evidence/agentgateway-progressive-disclosure-otel-trace.json',
|
|
248
|
+
lesson: 'MCP gateway progressive disclosure still needs receipts: prove the client saw only lightweight meta-tools/index, one full schema loaded on demand, one tool ran, and private schemas/queries/results stayed out of the trace.'
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
console.log(JSON.stringify(summary, null, 2));
|
|
@@ -0,0 +1,241 @@
|
|
|
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-brain-remediation-log.jsonl');
|
|
9
|
+
const receiptPath = process.argv[3] ? resolve(process.argv[3]) : join(here, 'brain-remediation-receipt.ndjson');
|
|
10
|
+
const tracePath = process.argv[4] ? resolve(process.argv[4]) : join(here, 'brain-remediation-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 (typeof value === 'string') {
|
|
43
|
+
if (value === 'true' || value === 'false') return { boolValue: value === 'true' };
|
|
44
|
+
if (/^-?\d+$/.test(value)) return { intValue: value };
|
|
45
|
+
return { stringValue: value };
|
|
46
|
+
}
|
|
47
|
+
if (value == null) return { stringValue: '' };
|
|
48
|
+
return { stringValue: JSON.stringify(value) };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function attributesToOtel(attributes) {
|
|
52
|
+
return Object.entries(attributes).map(([key, value]) => ({ key, value: otelValue(value) }));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function dollarBucket(value) {
|
|
56
|
+
if (value === 0) return 'zero';
|
|
57
|
+
if (value < 1) return 'under_1_usd';
|
|
58
|
+
if (value < 5) return 'under_5_usd';
|
|
59
|
+
return 'over_5_usd';
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function scoreBucket(value) {
|
|
63
|
+
if (value >= 90) return 'healthy';
|
|
64
|
+
if (value >= 75) return 'needs_attention';
|
|
65
|
+
if (value >= 50) return 'degraded';
|
|
66
|
+
return 'critical';
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const records = readJsonl(inputPath);
|
|
70
|
+
const start = records.find((record) => record.type === 'brain.doctor.start');
|
|
71
|
+
const precheck = records.find((record) => record.type === 'brain.doctor.precheck');
|
|
72
|
+
const plan = records.find((record) => record.type === 'brain.remediation.plan');
|
|
73
|
+
const jobs = records.filter((record) => record.type === 'brain.remediation.job');
|
|
74
|
+
const postcheck = records.find((record) => record.type === 'brain.doctor.postcheck');
|
|
75
|
+
const completed = records.find((record) => record.type === 'brain.doctor.completed');
|
|
76
|
+
|
|
77
|
+
if (!start || !precheck || !plan || !postcheck || !completed) {
|
|
78
|
+
throw new Error(`Expected start, precheck, plan, postcheck, and completed records in ${inputPath}`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const traceSeed = `${start.instance_id}:${start.run_id}:brain-remediation`;
|
|
82
|
+
const traceId = sha256(traceSeed).replace('sha256:', '').slice(0, 32);
|
|
83
|
+
const spanId = sha256(`${traceSeed}:span`).replace('sha256:', '').slice(0, 16);
|
|
84
|
+
const instanceHash = hashRef(start.instance_id);
|
|
85
|
+
const runHash = hashRef(start.run_id);
|
|
86
|
+
const protectedPhases = start.protected_phases ?? [];
|
|
87
|
+
|
|
88
|
+
const precheckEvent = {
|
|
89
|
+
trace_id: traceId,
|
|
90
|
+
span_id: spanId,
|
|
91
|
+
name: 'brain.doctor.precheck.completed',
|
|
92
|
+
time: precheck.time,
|
|
93
|
+
attributes: {
|
|
94
|
+
'brain.instance.id_hash': instanceHash,
|
|
95
|
+
'brain.doctor.run.id_hash': runHash,
|
|
96
|
+
'brain.doctor.mode': start.mode ?? 'doctor.remediate',
|
|
97
|
+
'brain.doctor.score.before': precheck.score,
|
|
98
|
+
'brain.doctor.score.before_bucket': scoreBucket(precheck.score),
|
|
99
|
+
'brain.doctor.issue.count.before': precheck.issue_count,
|
|
100
|
+
'brain.doctor.issue.categories_hash': sha256((precheck.issue_categories ?? []).join('\n')),
|
|
101
|
+
'brain.doctor.snapshot.before_hash': hashRef(precheck.brain_snapshot),
|
|
102
|
+
'brain.privacy.raw_brain_recorded': 'false',
|
|
103
|
+
'brain.privacy.raw_issue_recorded': 'false'
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const planEvent = {
|
|
108
|
+
trace_id: traceId,
|
|
109
|
+
span_id: spanId,
|
|
110
|
+
name: 'brain.doctor.remediation.plan.selected',
|
|
111
|
+
time: plan.time,
|
|
112
|
+
attributes: {
|
|
113
|
+
'brain.instance.id_hash': instanceHash,
|
|
114
|
+
'brain.doctor.run.id_hash': runHash,
|
|
115
|
+
'brain.remediation.plan.id_hash': hashRef(plan.plan_id),
|
|
116
|
+
'brain.remediation.plan.summary_hash': sha256(plan.plan_summary ?? ''),
|
|
117
|
+
'brain.remediation.plan.step_count': plan.step_count ?? jobs.length,
|
|
118
|
+
'brain.remediation.plan.estimated_spend_bucket': dollarBucket(plan.estimated_usd ?? 0),
|
|
119
|
+
'brain.remediation.plan.expected_score_delta': plan.expected_score_delta ?? 0,
|
|
120
|
+
'brain.remediation.plan.requires_protected_phase': String(Boolean(plan.requires_protected_phase)),
|
|
121
|
+
'brain.remediation.protected_phases_hash': sha256(protectedPhases.join('\n')),
|
|
122
|
+
'brain.privacy.raw_plan_recorded': 'false'
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const jobEvents = jobs.map((job) => ({
|
|
127
|
+
trace_id: traceId,
|
|
128
|
+
span_id: spanId,
|
|
129
|
+
name: 'brain.doctor.remediation.job.evaluated',
|
|
130
|
+
time: job.time,
|
|
131
|
+
attributes: {
|
|
132
|
+
'brain.instance.id_hash': instanceHash,
|
|
133
|
+
'brain.doctor.run.id_hash': runHash,
|
|
134
|
+
'brain.remediation.job.id_hash': hashRef(job.job_id),
|
|
135
|
+
'brain.remediation.job.kind': job.step_kind ?? 'unknown',
|
|
136
|
+
'brain.remediation.job.status': job.status ?? 'unknown',
|
|
137
|
+
'brain.remediation.job.protected_phase': String(Boolean(job.protected_phase)),
|
|
138
|
+
'brain.remediation.job.estimated_spend_bucket': dollarBucket(job.estimated_usd ?? 0),
|
|
139
|
+
'brain.remediation.job.actual_spend_bucket': dollarBucket(job.actual_usd ?? 0),
|
|
140
|
+
'brain.remediation.job.changed_entity_count': job.changed_entity_count ?? 0,
|
|
141
|
+
'brain.remediation.job.refusal_reason': job.refusal_reason ?? '',
|
|
142
|
+
'brain.remediation.job.skip_reason': job.skip_reason ?? '',
|
|
143
|
+
'brain.privacy.raw_change_recorded': 'false'
|
|
144
|
+
}
|
|
145
|
+
}));
|
|
146
|
+
|
|
147
|
+
const completedEvent = {
|
|
148
|
+
trace_id: traceId,
|
|
149
|
+
span_id: spanId,
|
|
150
|
+
name: 'brain.doctor.remediation.completed',
|
|
151
|
+
time: completed.time,
|
|
152
|
+
attributes: {
|
|
153
|
+
'brain.instance.id_hash': instanceHash,
|
|
154
|
+
'brain.doctor.run.id_hash': runHash,
|
|
155
|
+
'brain.doctor.outcome': completed.outcome ?? 'unknown',
|
|
156
|
+
'brain.doctor.target_score': completed.target_score ?? start.target_score,
|
|
157
|
+
'brain.doctor.score.before': completed.score_before ?? precheck.score,
|
|
158
|
+
'brain.doctor.score.after': completed.score_after ?? postcheck.score,
|
|
159
|
+
'brain.doctor.score.after_bucket': scoreBucket(completed.score_after ?? postcheck.score),
|
|
160
|
+
'brain.doctor.target_reached': String((completed.score_after ?? postcheck.score) >= (completed.target_score ?? start.target_score ?? 0)),
|
|
161
|
+
'brain.doctor.issue.count.after': postcheck.issue_count,
|
|
162
|
+
'brain.doctor.issue.categories_after_hash': sha256((postcheck.issue_categories ?? []).join('\n')),
|
|
163
|
+
'brain.doctor.snapshot.after_hash': hashRef(postcheck.brain_snapshot),
|
|
164
|
+
'brain.remediation.jobs.submitted': completed.jobs_submitted ?? jobs.filter((job) => job.status === 'submitted').length,
|
|
165
|
+
'brain.remediation.jobs.skipped': completed.jobs_skipped ?? jobs.filter((job) => job.status === 'skipped').length,
|
|
166
|
+
'brain.remediation.jobs.refused': completed.jobs_refused ?? jobs.filter((job) => job.status === 'refused').length,
|
|
167
|
+
'brain.remediation.cost.cap_bucket': dollarBucket(completed.max_usd ?? start.max_usd ?? 0),
|
|
168
|
+
'brain.remediation.cost.actual_bucket': dollarBucket(completed.actual_usd ?? 0),
|
|
169
|
+
'brain.privacy.raw_brain_recorded': 'false',
|
|
170
|
+
'brain.privacy.raw_operator_note_recorded': 'false'
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const events = [precheckEvent, planEvent, ...jobEvents, completedEvent]
|
|
175
|
+
.sort((left, right) => Date.parse(left.time) - Date.parse(right.time));
|
|
176
|
+
writeFileSync(receiptPath, `${events.map((event) => JSON.stringify(event)).join('\n')}\n`);
|
|
177
|
+
|
|
178
|
+
const eventTimes = records.map((record) => Date.parse(record.time)).filter(Number.isFinite);
|
|
179
|
+
const startTimeMs = Number.isFinite(Date.parse(start.time)) ? Date.parse(start.time) : Math.min(...eventTimes);
|
|
180
|
+
const endTimeMs = Number.isFinite(Date.parse(completed.time)) ? Date.parse(completed.time) : Math.max(...eventTimes) + 1;
|
|
181
|
+
|
|
182
|
+
const otlpTrace = {
|
|
183
|
+
resourceSpans: [
|
|
184
|
+
{
|
|
185
|
+
resource: {
|
|
186
|
+
attributes: attributesToOtel({
|
|
187
|
+
'service.name': 'pluribus-brain-remediation-receipt-demo',
|
|
188
|
+
'service.version': '0.0.0-fixture',
|
|
189
|
+
'deployment.environment.name': 'local-fixture'
|
|
190
|
+
})
|
|
191
|
+
},
|
|
192
|
+
scopeSpans: [
|
|
193
|
+
{
|
|
194
|
+
scope: {
|
|
195
|
+
name: 'pluribus.context_input_evidence.brain_remediation_demo',
|
|
196
|
+
version: '0.0.0-fixture'
|
|
197
|
+
},
|
|
198
|
+
spans: [
|
|
199
|
+
{
|
|
200
|
+
traceId,
|
|
201
|
+
spanId,
|
|
202
|
+
parentSpanId: '',
|
|
203
|
+
name: 'agent.memory.doctor',
|
|
204
|
+
kind: 1,
|
|
205
|
+
startTimeUnixNano: `${BigInt(startTimeMs) * 1_000_000n}`,
|
|
206
|
+
endTimeUnixNano: `${BigInt(endTimeMs) * 1_000_000n}`,
|
|
207
|
+
attributes: attributesToOtel({
|
|
208
|
+
'brain.instance.id_hash': instanceHash,
|
|
209
|
+
'brain.doctor.run.id_hash': runHash,
|
|
210
|
+
'brain.doctor.mode': start.mode ?? 'doctor.remediate',
|
|
211
|
+
'brain.doctor.target_score': start.target_score ?? 0,
|
|
212
|
+
'brain.remediation.cost.cap_bucket': dollarBucket(start.max_usd ?? 0),
|
|
213
|
+
'brain.remediation.job.count': jobs.length
|
|
214
|
+
}),
|
|
215
|
+
events: events.map((event) => ({
|
|
216
|
+
name: event.name,
|
|
217
|
+
timeUnixNano: unixNano(event.time),
|
|
218
|
+
attributes: attributesToOtel(event.attributes)
|
|
219
|
+
}))
|
|
220
|
+
}
|
|
221
|
+
]
|
|
222
|
+
}
|
|
223
|
+
]
|
|
224
|
+
}
|
|
225
|
+
]
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
writeFileSync(tracePath, `${JSON.stringify(otlpTrace, null, 2)}\n`);
|
|
229
|
+
|
|
230
|
+
console.log(JSON.stringify({
|
|
231
|
+
schema: 'pluribus.contextInputEvidence.brainRemediationReceiptDemo.v0',
|
|
232
|
+
inputPath,
|
|
233
|
+
receiptPath,
|
|
234
|
+
tracePath,
|
|
235
|
+
instanceHash,
|
|
236
|
+
runHash,
|
|
237
|
+
eventCount: events.length,
|
|
238
|
+
jobEvents: jobEvents.length,
|
|
239
|
+
outcome: completed.outcome,
|
|
240
|
+
rawPayloadRecorded: false
|
|
241
|
+
}, null, 2));
|