@atrib/recall 0.14.7 → 1.0.0
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/README.md +40 -4
- package/dist/event-type-filter.d.ts +9 -0
- package/dist/event-type-filter.js +15 -0
- package/dist/event-type-filter.js.map +1 -0
- package/dist/index.d.ts +59 -2
- package/dist/index.js +383 -456
- package/dist/index.js.map +1 -1
- package/dist/recall-verb.d.ts +128 -0
- package/dist/recall-verb.js +299 -0
- package/dist/recall-verb.js.map +1 -0
- package/dist/trace-storage.d.ts +36 -0
- package/dist/trace-storage.js +93 -0
- package/dist/trace-storage.js.map +1 -0
- package/dist/trace-tools.d.ts +102 -0
- package/dist/trace-tools.js +314 -0
- package/dist/trace-tools.js.map +1 -0
- package/dist/trace-walk.d.ts +106 -0
- package/dist/trace-walk.js +275 -0
- package/dist/trace-walk.js.map +1 -0
- package/dist/verification.d.ts +108 -0
- package/dist/verification.js +223 -0
- package/dist/verification.js.map +1 -0
- package/package.json +14 -2
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { logReadPrimitiveCall } from '@atrib/mcp';
|
|
4
|
+
import { EventTypeFilterSchema } from './event-type-filter.js';
|
|
5
|
+
import { recall, runRecallAnnotations, runRecallByContent, runRecallBySigner, runRecallOrphans, runRecallRevisions, runRecallSessionChain, runRecallWalk, } from './index.js';
|
|
6
|
+
import { extractRecordHashFieldsFromMcpResult, runTraceWalk, } from './trace-tools.js';
|
|
7
|
+
import { tryHandleAtribVerify, VerifyInput } from './verification.js';
|
|
8
|
+
const SHA256_REF_PATTERN = /^sha256:[0-9a-f]{64}$/;
|
|
9
|
+
export const RECALL_SHAPES = [
|
|
10
|
+
'history',
|
|
11
|
+
'walk',
|
|
12
|
+
'content',
|
|
13
|
+
'chain',
|
|
14
|
+
'annotations',
|
|
15
|
+
'revisions',
|
|
16
|
+
'orphans',
|
|
17
|
+
'by_signer',
|
|
18
|
+
];
|
|
19
|
+
const RecallFilters = z.object({
|
|
20
|
+
context_id: z
|
|
21
|
+
.string()
|
|
22
|
+
.optional()
|
|
23
|
+
.describe('32-hex context_id filter (history, chain, orphans; walk trace scoping).'),
|
|
24
|
+
context_scope: z
|
|
25
|
+
.enum(['all', 'env'])
|
|
26
|
+
.optional()
|
|
27
|
+
.describe("History only. How to treat an omitted context_id: 'all' (default) searches cross-context; " +
|
|
28
|
+
"'env' applies the D078/D083 env-derived current context."),
|
|
29
|
+
creator_key: z
|
|
30
|
+
.string()
|
|
31
|
+
.optional()
|
|
32
|
+
.describe('Exact creator_key match (history, orphans).'),
|
|
33
|
+
event_type: EventTypeFilterSchema.optional().describe('Event-kind filter: shorthand alias or full URI (history, orphans).'),
|
|
34
|
+
content_id: z.string().optional().describe('Exact content_id match (history).'),
|
|
35
|
+
tool_name: z.string().optional().describe('Exact §8.2 disclosed tool_name match (history).'),
|
|
36
|
+
args_hash: z.string().optional().describe('Exact §8.3 args_hash match (history).'),
|
|
37
|
+
min_importance: z
|
|
38
|
+
.enum(['critical', 'high', 'medium', 'low', 'noise'])
|
|
39
|
+
.optional()
|
|
40
|
+
.describe('History only. Minimum annotation-derived importance.'),
|
|
41
|
+
topic_tags: z
|
|
42
|
+
.array(z.string())
|
|
43
|
+
.optional()
|
|
44
|
+
.describe('History only. OR-match against annotation topic tags.'),
|
|
45
|
+
include_revised: z
|
|
46
|
+
.boolean()
|
|
47
|
+
.optional()
|
|
48
|
+
.describe('History only. Hide records superseded by a revision when true.'),
|
|
49
|
+
min_signers: z
|
|
50
|
+
.number()
|
|
51
|
+
.optional()
|
|
52
|
+
.describe('History only. Minimum count of distinct signers.'),
|
|
53
|
+
});
|
|
54
|
+
export const RecallVerbInput = z.object({
|
|
55
|
+
shape: z
|
|
56
|
+
.enum(RECALL_SHAPES)
|
|
57
|
+
.optional()
|
|
58
|
+
.describe('Which read shape to run. Required unless `verification` is supplied (verification-only ' +
|
|
59
|
+
'call). history = filter-and-page over the local mirror; walk = graph/causal walk from ' +
|
|
60
|
+
'`start`; content = BM25 free-form retrieval over `query`; chain = chronological ' +
|
|
61
|
+
'session chain; annotations / revisions = per-record aggregations from `start`; ' +
|
|
62
|
+
'orphans = loose-end discovery; by_signer = per-creator aggregation.'),
|
|
63
|
+
direction: z
|
|
64
|
+
.enum(['backward', 'forward'])
|
|
65
|
+
.optional()
|
|
66
|
+
.describe("Walk only. Omit for the local derived-graph walk (legacy recall_walk). 'backward' walks " +
|
|
67
|
+
"the informed_by chain that led to `start` (legacy trace); 'forward' walks the records " +
|
|
68
|
+
'that cited `start` (legacy trace_forward).'),
|
|
69
|
+
start: z
|
|
70
|
+
.string()
|
|
71
|
+
.regex(SHA256_REF_PATTERN)
|
|
72
|
+
.optional()
|
|
73
|
+
.describe("'sha256:<64-hex>' starting record_hash. REQUIRED for walk, annotations, and revisions."),
|
|
74
|
+
query: z
|
|
75
|
+
.string()
|
|
76
|
+
.optional()
|
|
77
|
+
.describe('Free-form BM25 content query per D086. REQUIRED for shape=content.'),
|
|
78
|
+
filters: RecallFilters.optional().describe('AND-combined filters. Which fields apply depends on the shape; see each field.'),
|
|
79
|
+
rank_by: z
|
|
80
|
+
.enum(['timestamp', 'relevance', 'causal_distance'])
|
|
81
|
+
.optional()
|
|
82
|
+
.describe('History only. Result ordering; same semantics as the legacy tool.'),
|
|
83
|
+
rank_anchor: z
|
|
84
|
+
.string()
|
|
85
|
+
.optional()
|
|
86
|
+
.describe('History only. Anchor for non-timestamp rank_by modes.'),
|
|
87
|
+
limit: z
|
|
88
|
+
.number()
|
|
89
|
+
.optional()
|
|
90
|
+
.describe('Page size / top-k. history: default 10, max 200. content: top-k, default 10, max 50. ' +
|
|
91
|
+
'chain and orphans: default 50, max 500.'),
|
|
92
|
+
offset: z
|
|
93
|
+
.number()
|
|
94
|
+
.optional()
|
|
95
|
+
.describe('History only. Pagination offset (explicit handle; never protocol-session state).'),
|
|
96
|
+
compact: z
|
|
97
|
+
.boolean()
|
|
98
|
+
.optional()
|
|
99
|
+
.describe('history and walk-with-direction: omit heavy record fields (default true).'),
|
|
100
|
+
include_unverified: z
|
|
101
|
+
.boolean()
|
|
102
|
+
.optional()
|
|
103
|
+
.describe('History only. Include records that failed local signature verification.'),
|
|
104
|
+
toc: z
|
|
105
|
+
.boolean()
|
|
106
|
+
.optional()
|
|
107
|
+
.describe('History only. Table-of-contents entry shape per record.'),
|
|
108
|
+
edge_types: z
|
|
109
|
+
.array(z.enum(['CHAIN_PRECEDES', 'INFORMED_BY', 'ANNOTATES', 'REVISES']))
|
|
110
|
+
.optional()
|
|
111
|
+
.describe('Walk (no direction) only. Layer 1 edge types to follow; default all four.'),
|
|
112
|
+
depth: z
|
|
113
|
+
.number()
|
|
114
|
+
.optional()
|
|
115
|
+
.describe('Walk only. Maximum hop count. Graph walk default 3; directional walks default 3, max 10.'),
|
|
116
|
+
max_nodes: z
|
|
117
|
+
.number()
|
|
118
|
+
.optional()
|
|
119
|
+
.describe('Walk with direction only. Hard cap on visited records (default 200, max 500).'),
|
|
120
|
+
include_content: z
|
|
121
|
+
.boolean()
|
|
122
|
+
.optional()
|
|
123
|
+
.describe('chain and walk-with-direction: include the D062 local mirror body per record.'),
|
|
124
|
+
max_records: z
|
|
125
|
+
.number()
|
|
126
|
+
.optional()
|
|
127
|
+
.describe('Content only. Maximum newest-first records to search before candidate scoring.'),
|
|
128
|
+
evidence_mode: z
|
|
129
|
+
.enum(['bounded', 'require_complete'])
|
|
130
|
+
.optional()
|
|
131
|
+
.describe('Content only. Coverage posture; same semantics as the legacy tool (D123/D125).'),
|
|
132
|
+
include_tool_call_args: z
|
|
133
|
+
.boolean()
|
|
134
|
+
.optional()
|
|
135
|
+
.describe('Content only. Lift the operational tool_call score suppression (D156).'),
|
|
136
|
+
min_records: z
|
|
137
|
+
.number()
|
|
138
|
+
.optional()
|
|
139
|
+
.describe('by_signer only. Minimum record count to include a creator.'),
|
|
140
|
+
verification: VerifyInput.extend({
|
|
141
|
+
mode: z
|
|
142
|
+
.literal('handoff')
|
|
143
|
+
.optional()
|
|
144
|
+
.describe("Verification mode. Only 'handoff' (Pattern 3 claim acceptance) exists today."),
|
|
145
|
+
})
|
|
146
|
+
.optional()
|
|
147
|
+
.describe('Run handoff-evidence verification (legacy atrib-verify) and attach the tiered result ' +
|
|
148
|
+
'as a `verification` block on the response. When the optional @atrib/verify peer is ' +
|
|
149
|
+
'not installed, the block is { status: "verifier_unavailable" } and the read result ' +
|
|
150
|
+
'is unaffected (§5.8). Supply without `shape` for a verification-only call.'),
|
|
151
|
+
});
|
|
152
|
+
function refusal(message) {
|
|
153
|
+
return { isError: true, content: [{ type: 'text', text: message }] };
|
|
154
|
+
}
|
|
155
|
+
/** Dispatch one recall-verb call to the shape runners. Exported for tests. */
|
|
156
|
+
export async function runRecallVerb(input) {
|
|
157
|
+
if (!input.shape && !input.verification) {
|
|
158
|
+
return { error: 'recall requires `shape`, `verification`, or both' };
|
|
159
|
+
}
|
|
160
|
+
let payload = {};
|
|
161
|
+
if (input.shape) {
|
|
162
|
+
const f = input.filters ?? {};
|
|
163
|
+
switch (input.shape) {
|
|
164
|
+
case 'history': {
|
|
165
|
+
payload = (await recall({
|
|
166
|
+
...(f.context_id !== undefined ? { context_id: f.context_id } : {}),
|
|
167
|
+
...(f.context_scope !== undefined ? { context_scope: f.context_scope } : {}),
|
|
168
|
+
...(f.creator_key !== undefined ? { creator_key: f.creator_key } : {}),
|
|
169
|
+
...(f.event_type !== undefined ? { event_type: f.event_type } : {}),
|
|
170
|
+
...(f.content_id !== undefined ? { content_id: f.content_id } : {}),
|
|
171
|
+
...(f.tool_name !== undefined ? { tool_name: f.tool_name } : {}),
|
|
172
|
+
...(f.args_hash !== undefined ? { args_hash: f.args_hash } : {}),
|
|
173
|
+
...(f.min_importance !== undefined ? { min_importance: f.min_importance } : {}),
|
|
174
|
+
...(f.topic_tags !== undefined ? { topic_tags: f.topic_tags } : {}),
|
|
175
|
+
...(f.include_revised !== undefined ? { include_revised: f.include_revised } : {}),
|
|
176
|
+
...(f.min_signers !== undefined ? { min_signers: f.min_signers } : {}),
|
|
177
|
+
...(input.limit !== undefined ? { limit: input.limit } : {}),
|
|
178
|
+
...(input.offset !== undefined ? { offset: input.offset } : {}),
|
|
179
|
+
...(input.compact !== undefined ? { compact: input.compact } : {}),
|
|
180
|
+
...(input.include_unverified !== undefined
|
|
181
|
+
? { include_unverified: input.include_unverified }
|
|
182
|
+
: {}),
|
|
183
|
+
...(input.rank_by !== undefined ? { rank_by: input.rank_by } : {}),
|
|
184
|
+
...(input.rank_anchor !== undefined ? { rank_anchor: input.rank_anchor } : {}),
|
|
185
|
+
...(input.toc !== undefined ? { toc: input.toc } : {}),
|
|
186
|
+
}));
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
case 'walk': {
|
|
190
|
+
if (!input.start)
|
|
191
|
+
return { error: "shape='walk' requires `start`" };
|
|
192
|
+
if (input.direction) {
|
|
193
|
+
const traceArgs = {
|
|
194
|
+
record_hash: input.start,
|
|
195
|
+
...(f.context_id !== undefined ? { context_id: f.context_id } : {}),
|
|
196
|
+
...(input.depth !== undefined ? { depth: input.depth } : {}),
|
|
197
|
+
...(input.max_nodes !== undefined ? { max_nodes: input.max_nodes } : {}),
|
|
198
|
+
...(input.compact !== undefined ? { compact: input.compact } : {}),
|
|
199
|
+
...(input.include_content !== undefined
|
|
200
|
+
? { include_content: input.include_content }
|
|
201
|
+
: {}),
|
|
202
|
+
};
|
|
203
|
+
payload = runTraceWalk(input.direction, traceArgs);
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
payload = await runRecallWalk({
|
|
207
|
+
from_record_hash: input.start,
|
|
208
|
+
...(input.edge_types !== undefined
|
|
209
|
+
? { edge_types: input.edge_types }
|
|
210
|
+
: {}),
|
|
211
|
+
...(input.depth !== undefined ? { depth: input.depth } : {}),
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
case 'content': {
|
|
217
|
+
if (input.query === undefined)
|
|
218
|
+
return { error: "shape='content' requires `query`" };
|
|
219
|
+
payload = await runRecallByContent({
|
|
220
|
+
query: input.query,
|
|
221
|
+
...(input.limit !== undefined ? { k: input.limit } : {}),
|
|
222
|
+
...(input.max_records !== undefined ? { max_records: input.max_records } : {}),
|
|
223
|
+
...(input.evidence_mode !== undefined ? { evidence_mode: input.evidence_mode } : {}),
|
|
224
|
+
...(input.include_tool_call_args !== undefined
|
|
225
|
+
? { include_tool_call_args: input.include_tool_call_args }
|
|
226
|
+
: {}),
|
|
227
|
+
});
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
case 'chain': {
|
|
231
|
+
payload = await runRecallSessionChain({
|
|
232
|
+
...(f.context_id !== undefined ? { context_id: f.context_id } : {}),
|
|
233
|
+
...(input.limit !== undefined ? { limit: input.limit } : {}),
|
|
234
|
+
...(input.include_content !== undefined
|
|
235
|
+
? { include_content: input.include_content }
|
|
236
|
+
: {}),
|
|
237
|
+
});
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
case 'annotations': {
|
|
241
|
+
if (!input.start)
|
|
242
|
+
return { error: "shape='annotations' requires `start`" };
|
|
243
|
+
payload = await runRecallAnnotations({ record_hash: input.start });
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
case 'revisions': {
|
|
247
|
+
if (!input.start)
|
|
248
|
+
return { error: "shape='revisions' requires `start`" };
|
|
249
|
+
payload = await runRecallRevisions({ record_hash: input.start });
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
case 'orphans': {
|
|
253
|
+
payload = await runRecallOrphans({
|
|
254
|
+
...(f.context_id !== undefined ? { context_id: f.context_id } : {}),
|
|
255
|
+
...(f.event_type !== undefined ? { event_type: f.event_type } : {}),
|
|
256
|
+
...(f.creator_key !== undefined ? { creator_key: f.creator_key } : {}),
|
|
257
|
+
...(input.limit !== undefined ? { limit: input.limit } : {}),
|
|
258
|
+
});
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
case 'by_signer': {
|
|
262
|
+
payload = await runRecallBySigner({
|
|
263
|
+
...(input.min_records !== undefined ? { min_records: input.min_records } : {}),
|
|
264
|
+
});
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
if (input.verification) {
|
|
270
|
+
const { mode: _mode, ...verifyArgs } = input.verification;
|
|
271
|
+
payload = { ...payload, verification: await tryHandleAtribVerify(verifyArgs) };
|
|
272
|
+
}
|
|
273
|
+
return { payload };
|
|
274
|
+
}
|
|
275
|
+
/** Register the `recall` verb tool on a server. */
|
|
276
|
+
export function registerRecallVerbTool(mcp) {
|
|
277
|
+
mcp.registerTool('recall', {
|
|
278
|
+
description: "Look up the agent's signed past: atrib's read verb. One read-only tool absorbs the " +
|
|
279
|
+
'legacy recall_* tools (shape argument), trace / trace_forward (shape=walk with a ' +
|
|
280
|
+
'direction), and atrib-verify (the verification parameter). Results are JSON-identical ' +
|
|
281
|
+
'to the legacy tool they map onto; every compact result keeps record_hash so calls can ' +
|
|
282
|
+
'be chained. Signs nothing.',
|
|
283
|
+
inputSchema: RecallVerbInput.shape,
|
|
284
|
+
}, async (rawInput) => {
|
|
285
|
+
const input = RecallVerbInput.parse(rawInput);
|
|
286
|
+
const primitive = `recall:${input.shape ?? 'verification'}`;
|
|
287
|
+
return logReadPrimitiveCall(primitive, rawInput, async () => {
|
|
288
|
+
const outcome = await runRecallVerb(input);
|
|
289
|
+
if ('error' in outcome)
|
|
290
|
+
return refusal(outcome.error);
|
|
291
|
+
return {
|
|
292
|
+
content: [
|
|
293
|
+
{ type: 'text', text: JSON.stringify(outcome.payload, null, 2) },
|
|
294
|
+
],
|
|
295
|
+
};
|
|
296
|
+
}, extractRecordHashFieldsFromMcpResult);
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
//# sourceMappingURL=recall-verb.js.map
|
|
@@ -0,0 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;QACE,WAAW,EACT,qFAAqF;YACrF,mFAAmF;YACnF,wFAAwF;YACxF,wFAAwF;YACxF,4BAA4B;QAC9B,WAAW,EAAE,eAAe,CAAC,KAAK;KACnC,EACD,KAAK,EAAE,QAAQ,EAAE,EAAE;QACjB,MAAM,KAAK,GAAG,eAAe,CAAC,KAAK,CAAC,QAAQ,CAAqB,CAAA;QACjE,MAAM,SAAS,GAAG,UAAU,KAAK,CAAC,KAAK,IAAI,cAAc,EAAE,CAAA;QAC3D,OAAO,oBAAoB,CACzB,SAAS,EACT,QAAQ,EACR,KAAK,IAAI,EAAE;YACT,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC,KAAK,CAAC,CAAA;YAC1C,IAAI,OAAO,IAAI,OAAO;gBAAE,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;YACrD,OAAO;gBACL,OAAO,EAAE;oBACP,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE;iBAC1E;aACF,CAAA;QACH,CAAC,EACD,oCAAoC,CACrC,CAAA;IACH,CAAC,CACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type AtribRecord, type OnRecordSidecar } from '@atrib/mcp';
|
|
2
|
+
export interface IndexedRecord {
|
|
3
|
+
record: AtribRecord;
|
|
4
|
+
/** sha256:<64-hex> form, matching informed_by entries. */
|
|
5
|
+
record_hash: string;
|
|
6
|
+
/** Source file the record was read from (for debugging). */
|
|
7
|
+
source: string;
|
|
8
|
+
/**
|
|
9
|
+
* Pre-sign payload context, when the producer wrote it to the local
|
|
10
|
+
* mirror as a `_local` sidecar on the envelope. Carries semantic content
|
|
11
|
+
* (toolName, args, result, content) the signed AtribRecord COMMITS TO
|
|
12
|
+
* via content_id / args_hash / result_hash but does not itself contain.
|
|
13
|
+
* Absent on legacy bare-record entries from older mirror writes.
|
|
14
|
+
*/
|
|
15
|
+
local?: SidecarPayload;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Combined sidecar shape, superset of every producer's local payload
|
|
19
|
+
* (mcp-wrap writes toolName/args/result; atrib-emit writes content).
|
|
20
|
+
*/
|
|
21
|
+
export interface SidecarPayload extends OnRecordSidecar {
|
|
22
|
+
content?: unknown;
|
|
23
|
+
producer?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Read every *.jsonl mirror in ATRIB_RECORDS_DIR and return an index keyed
|
|
27
|
+
* by sha256:<64-hex> record_hash. Both shapes (bare AtribRecord and emit's
|
|
28
|
+
* { record, proof, written_at } envelope) are supported.
|
|
29
|
+
*
|
|
30
|
+
* Returns the indexed map AND a flat list (newest-first by timestamp) for
|
|
31
|
+
* callers that want recall-style enumeration without by-hash lookup.
|
|
32
|
+
*/
|
|
33
|
+
export declare function loadAllRecords(dir?: string): {
|
|
34
|
+
byHash: Map<string, IndexedRecord>;
|
|
35
|
+
newestFirst: IndexedRecord[];
|
|
36
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
/**
|
|
3
|
+
* Local mirror reader for atrib-trace.
|
|
4
|
+
*
|
|
5
|
+
* Reads either one ATRIB_RECORD_FILE mirror or every *.jsonl mirror under
|
|
6
|
+
* ~/.atrib/records/ and normalizes to bare AtribRecord shape regardless of
|
|
7
|
+
* producer (wrapper-signed or emit envelope).
|
|
8
|
+
*
|
|
9
|
+
* Builds an in-memory index by record_hash so trace can walk informed_by
|
|
10
|
+
* chains in O(1) per hop. The hash key is sha256:<64-hex> (the same form
|
|
11
|
+
* informed_by entries use), so no transformation needed at lookup time.
|
|
12
|
+
*/
|
|
13
|
+
import { existsSync, readFileSync, readdirSync } from 'node:fs';
|
|
14
|
+
import { homedir } from 'node:os';
|
|
15
|
+
import { basename, join } from 'node:path';
|
|
16
|
+
import { canonicalRecord, hexEncode, sha256, withDerivedLocalContent, } from '@atrib/mcp';
|
|
17
|
+
const RECORDS_FILE = process.env.ATRIB_RECORD_FILE;
|
|
18
|
+
const RECORDS_DIR = process.env.ATRIB_RECORDS_DIR ?? join(homedir(), '.atrib', 'records');
|
|
19
|
+
/**
|
|
20
|
+
* Read every *.jsonl mirror in ATRIB_RECORDS_DIR and return an index keyed
|
|
21
|
+
* by sha256:<64-hex> record_hash. Both shapes (bare AtribRecord and emit's
|
|
22
|
+
* { record, proof, written_at } envelope) are supported.
|
|
23
|
+
*
|
|
24
|
+
* Returns the indexed map AND a flat list (newest-first by timestamp) for
|
|
25
|
+
* callers that want recall-style enumeration without by-hash lookup.
|
|
26
|
+
*/
|
|
27
|
+
export function loadAllRecords(dir = RECORDS_DIR) {
|
|
28
|
+
const byHash = new Map();
|
|
29
|
+
const all = [];
|
|
30
|
+
const paths = [];
|
|
31
|
+
if (RECORDS_FILE) {
|
|
32
|
+
paths.push({ path: RECORDS_FILE, source: basename(RECORDS_FILE) });
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
if (!existsSync(dir))
|
|
36
|
+
return { byHash, newestFirst: [] };
|
|
37
|
+
try {
|
|
38
|
+
for (const fname of readdirSync(dir).filter((f) => f.endsWith('.jsonl'))) {
|
|
39
|
+
paths.push({ path: join(dir, fname), source: fname });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return { byHash, newestFirst: [] };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
for (const { path, source } of paths) {
|
|
47
|
+
try {
|
|
48
|
+
const raw = readFileSync(path, 'utf8');
|
|
49
|
+
for (const line of raw.split('\n')) {
|
|
50
|
+
const trimmed = line.trim();
|
|
51
|
+
if (!trimmed)
|
|
52
|
+
continue;
|
|
53
|
+
try {
|
|
54
|
+
const parsed = JSON.parse(trimmed);
|
|
55
|
+
// Normalize: envelope shape vs legacy bare record shape.
|
|
56
|
+
const isEnvelope = 'record' in parsed &&
|
|
57
|
+
parsed.record &&
|
|
58
|
+
parsed.record.context_id !== undefined;
|
|
59
|
+
const rec = isEnvelope
|
|
60
|
+
? parsed.record
|
|
61
|
+
: parsed;
|
|
62
|
+
if (!rec.context_id || !rec.signature || !rec.timestamp)
|
|
63
|
+
continue;
|
|
64
|
+
const hashHex = hexEncode(sha256(canonicalRecord(rec)));
|
|
65
|
+
const indexed = {
|
|
66
|
+
record: rec,
|
|
67
|
+
record_hash: `sha256:${hashHex}`,
|
|
68
|
+
source,
|
|
69
|
+
};
|
|
70
|
+
// Lift the `_local` sidecar onto the indexed record when present.
|
|
71
|
+
// Legacy bare-record entries have no sidecar; that's OK, consumers
|
|
72
|
+
// tolerate its absence.
|
|
73
|
+
if (isEnvelope) {
|
|
74
|
+
const sidecar = parsed._local;
|
|
75
|
+
if (sidecar)
|
|
76
|
+
indexed.local = withDerivedLocalContent(rec.event_type, sidecar);
|
|
77
|
+
}
|
|
78
|
+
byHash.set(indexed.record_hash, indexed);
|
|
79
|
+
all.push(indexed);
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
// Malformed line; skip.
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
// File read failure; skip this file.
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
all.sort((a, b) => b.record.timestamp - a.record.timestamp);
|
|
91
|
+
return { byHash, newestFirst: all };
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=trace-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace-storage.js","sourceRoot":"","sources":["../src/trace-storage.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,QAAQ,E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WAAW,EAAE,OAAO,CAAC,CAAA;oBACxC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;gBACnB,CAAC;gBAAC,MAAM,CAAC;oBACP,wBAAwB;gBAC1B,CAAC;YACH,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,qCAAqC;QACvC,CAAC;IACH,CAAC;IAED,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;IAC3D,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,CAAA;AACrC,CAAC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The legacy `trace` / `trace_forward` tools, kept as permanent aliases over
|
|
3
|
+
* @atrib/recall's read surface (the walk shapes of the `recall` verb). Walks
|
|
4
|
+
* a record's informed_by chain backward (the reasoning chain that led to it)
|
|
5
|
+
* or forward (the records that cited it). Reads only the local mirror
|
|
6
|
+
* (~/.atrib/records/*.jsonl), same scope as recall.
|
|
7
|
+
*
|
|
8
|
+
* Moved here from @atrib/trace per the attest/recall rename; @atrib/trace
|
|
9
|
+
* re-exports this module so existing imports keep working, and the
|
|
10
|
+
* `recall` verb reaches the same implementation via shape='walk' with a
|
|
11
|
+
* direction argument.
|
|
12
|
+
*/
|
|
13
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
14
|
+
import { z } from 'zod';
|
|
15
|
+
import { type IndexedRecord, type SidecarPayload } from './trace-storage.js';
|
|
16
|
+
import { type TraceVisited } from './trace-walk.js';
|
|
17
|
+
export declare const TraceInput: z.ZodObject<{
|
|
18
|
+
record_hash: z.ZodString;
|
|
19
|
+
context_id: z.ZodOptional<z.ZodString>;
|
|
20
|
+
depth: z.ZodOptional<z.ZodNumber>;
|
|
21
|
+
max_nodes: z.ZodOptional<z.ZodNumber>;
|
|
22
|
+
compact: z.ZodOptional<z.ZodBoolean>;
|
|
23
|
+
include_content: z.ZodOptional<z.ZodBoolean>;
|
|
24
|
+
}, z.core.$strip>;
|
|
25
|
+
export type TraceInputT = z.infer<typeof TraceInput>;
|
|
26
|
+
interface CompactVisited {
|
|
27
|
+
depth: number;
|
|
28
|
+
record_hash: string;
|
|
29
|
+
parent_hashes: string[];
|
|
30
|
+
source: string | null;
|
|
31
|
+
event_type: string | null;
|
|
32
|
+
context_id: string | null;
|
|
33
|
+
creator_key: string | null;
|
|
34
|
+
timestamp: number | null;
|
|
35
|
+
/** informed_by entries on this record. Empty if none or dangling. */
|
|
36
|
+
next_informed_by: string[];
|
|
37
|
+
/** Sub-set of next_informed_by that were resolved (present in mirror). */
|
|
38
|
+
next_resolved: string[];
|
|
39
|
+
/** Sub-set of next_informed_by that were dangling (not in mirror). */
|
|
40
|
+
next_dangling: string[];
|
|
41
|
+
/**
|
|
42
|
+
* Semantic context from the local sidecar when present. Carries
|
|
43
|
+
* tool name + brief content summary so the agent can reason about
|
|
44
|
+
* the record's meaning without separately fetching it. Absent on
|
|
45
|
+
* legacy bare-record entries that pre-date the sidecar.
|
|
46
|
+
*/
|
|
47
|
+
sidecar_summary?: {
|
|
48
|
+
tool_name?: string;
|
|
49
|
+
span_kind?: string;
|
|
50
|
+
span_name?: string;
|
|
51
|
+
model_name?: string;
|
|
52
|
+
prompt_version?: string;
|
|
53
|
+
topics?: string[];
|
|
54
|
+
intent?: string;
|
|
55
|
+
rationale?: string;
|
|
56
|
+
/**
|
|
57
|
+
* First 200 chars of the record's human-readable content, derived
|
|
58
|
+
* per event_type from the @atrib/mcp normative shapes (D086):
|
|
59
|
+
* observation `what`, annotation `summary`, revision `new_position`.
|
|
60
|
+
* For legacy records using non-normative names (`summary` on
|
|
61
|
+
* observation), falls back to `summary`.
|
|
62
|
+
*/
|
|
63
|
+
what?: string;
|
|
64
|
+
/** Annotation `importance` field when present. */
|
|
65
|
+
importance?: string;
|
|
66
|
+
producer?: string;
|
|
67
|
+
};
|
|
68
|
+
/** Signed structural disclosures, surfaced when present on the record. */
|
|
69
|
+
informed_by?: string[];
|
|
70
|
+
tool_name?: string;
|
|
71
|
+
args_hash?: string;
|
|
72
|
+
result_hash?: string;
|
|
73
|
+
/** D062 local mirror body, included only when include_content=true. */
|
|
74
|
+
local_content?: unknown;
|
|
75
|
+
local_producer?: string;
|
|
76
|
+
}
|
|
77
|
+
/** Pull a compact summary from the sidecar's content payload.
|
|
78
|
+
* Exported for unit testing of the per-event_type content-shape handling. */
|
|
79
|
+
export declare function summarizeSidecar(loadedRecord: {
|
|
80
|
+
local?: SidecarPayload;
|
|
81
|
+
} | undefined): CompactVisited['sidecar_summary'];
|
|
82
|
+
export declare function compactVisited(v: TraceVisited, danglingSet: Set<string>, byHash: Map<string, IndexedRecord>, includeContent: boolean): CompactVisited;
|
|
83
|
+
export declare function extractRecordHashFieldsFromMcpResult(result: unknown): string[];
|
|
84
|
+
/**
|
|
85
|
+
* Run one informed_by walk and return the JSON payload. This is the single
|
|
86
|
+
* implementation behind the legacy `trace` / `trace_forward` tools AND the
|
|
87
|
+
* `recall` verb's shape='walk' with a direction, so their results are
|
|
88
|
+
* JSON-identical by construction (read-equivalence conformance family).
|
|
89
|
+
*/
|
|
90
|
+
export declare function runTraceWalk(direction: 'backward' | 'forward', args: TraceInputT): Record<string, unknown>;
|
|
91
|
+
/** Register the legacy `trace` + `trace_forward` tools on a server. */
|
|
92
|
+
export declare function registerTraceTools(mcp: McpServer): void;
|
|
93
|
+
export interface AtribTraceServer {
|
|
94
|
+
mcp: McpServer;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Wire up the legacy atrib-trace MCP server. Mounts `trace` and
|
|
98
|
+
* `trace_forward` plus the `recall` verb (alias-window rule W1). The
|
|
99
|
+
* @atrib/trace package re-exports this factory.
|
|
100
|
+
*/
|
|
101
|
+
export declare function createAtribTraceServer(): Promise<AtribTraceServer>;
|
|
102
|
+
export {};
|