@lushly-dev/afd-server 2.1.0 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +233 -8
- package/dist/approval-crypto.d.ts +33 -0
- package/dist/approval-crypto.d.ts.map +1 -0
- package/dist/approval-crypto.js +121 -0
- package/dist/approval-crypto.js.map +1 -0
- package/dist/approval-relay.d.ts +85 -0
- package/dist/approval-relay.d.ts.map +1 -0
- package/dist/approval-relay.js +62 -0
- package/dist/approval-relay.js.map +1 -0
- package/dist/approval.d.ts +156 -0
- package/dist/approval.d.ts.map +1 -0
- package/dist/approval.js +299 -0
- package/dist/approval.js.map +1 -0
- package/dist/bootstrap/afd-context.d.ts +13 -0
- package/dist/bootstrap/afd-context.d.ts.map +1 -1
- package/dist/bootstrap/afd-context.js +12 -1
- package/dist/bootstrap/afd-context.js.map +1 -1
- package/dist/bootstrap/afd-docs.d.ts.map +1 -1
- package/dist/bootstrap/afd-docs.js +6 -1
- package/dist/bootstrap/afd-docs.js.map +1 -1
- package/dist/bootstrap/described-command.d.ts +2 -1
- package/dist/bootstrap/described-command.d.ts.map +1 -1
- package/dist/bootstrap/described-command.js.map +1 -1
- package/dist/confirmations.d.ts +115 -0
- package/dist/confirmations.d.ts.map +1 -0
- package/dist/confirmations.js +186 -0
- package/dist/confirmations.js.map +1 -0
- package/dist/define.d.ts +1 -1
- package/dist/define.d.ts.map +1 -1
- package/dist/define.js.map +1 -1
- package/dist/direct-registry.d.ts +10 -1
- package/dist/direct-registry.d.ts.map +1 -1
- package/dist/direct-registry.js +15 -5
- package/dist/direct-registry.js.map +1 -1
- package/dist/elicitation-state.d.ts +30 -0
- package/dist/elicitation-state.d.ts.map +1 -0
- package/dist/elicitation-state.js +25 -0
- package/dist/elicitation-state.js.map +1 -0
- package/dist/execution.d.ts +4 -2
- package/dist/execution.d.ts.map +1 -1
- package/dist/execution.js +9 -4
- package/dist/execution.js.map +1 -1
- package/dist/http-handler.d.ts +6 -0
- package/dist/http-handler.d.ts.map +1 -1
- package/dist/http-handler.js +34 -14
- package/dist/http-handler.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/journal-replay.d.ts +97 -0
- package/dist/journal-replay.d.ts.map +1 -0
- package/dist/journal-replay.js +250 -0
- package/dist/journal-replay.js.map +1 -0
- package/dist/journal.d.ts +90 -0
- package/dist/journal.d.ts.map +1 -0
- package/dist/journal.js +175 -0
- package/dist/journal.js.map +1 -0
- package/dist/lazy-tools.d.ts +1 -0
- package/dist/lazy-tools.d.ts.map +1 -1
- package/dist/lazy-tools.js +2 -1
- package/dist/lazy-tools.js.map +1 -1
- package/dist/mcp-modern.d.ts +76 -0
- package/dist/mcp-modern.d.ts.map +1 -0
- package/dist/mcp-modern.js +329 -0
- package/dist/mcp-modern.js.map +1 -0
- package/dist/meta-tools.d.ts +8 -1
- package/dist/meta-tools.d.ts.map +1 -1
- package/dist/meta-tools.js +12 -0
- package/dist/meta-tools.js.map +1 -1
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +8 -5
- package/dist/middleware.js.map +1 -1
- package/dist/request-context.d.ts +15 -0
- package/dist/request-context.d.ts.map +1 -0
- package/dist/request-context.js +21 -0
- package/dist/request-context.js.map +1 -0
- package/dist/schema.d.ts +9 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +2 -0
- package/dist/schema.js.map +1 -1
- package/dist/server-types.d.ts +60 -1
- package/dist/server-types.d.ts.map +1 -1
- package/dist/server-types.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +37 -21
- package/dist/server.js.map +1 -1
- package/dist/tool-router.d.ts +5 -0
- package/dist/tool-router.d.ts.map +1 -1
- package/dist/tool-router.js +82 -6
- package/dist/tool-router.js.map +1 -1
- package/dist/tools.d.ts +5 -1
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +35 -5
- package/dist/tools.js.map +1 -1
- package/package.json +7 -5
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Replay a command journal against a registry and diff the results.
|
|
3
|
+
*
|
|
4
|
+
* Replay restores the clock and random values each call read (its tape) and reports, per
|
|
5
|
+
* entry, whether the result is the same. It does not make handlers deterministic: any other
|
|
6
|
+
* nondeterminism (I/O, global state, `Date.now()` read directly) shows up as divergence.
|
|
7
|
+
*/
|
|
8
|
+
import { fixedClock, journalActor, seededRandom } from '@lushly-dev/afd-core';
|
|
9
|
+
import { JOURNAL_REPLAY } from './journal.js';
|
|
10
|
+
const DEFAULT_IGNORE = ['metadata.executionTimeMs'];
|
|
11
|
+
const DEFAULT_MAX_DIFFERENCES = 100;
|
|
12
|
+
/** Replays the recorded clock readings, then holds the last one. */
|
|
13
|
+
function tapeClock(readings, start) {
|
|
14
|
+
let index = 0;
|
|
15
|
+
let last = start;
|
|
16
|
+
let overran = false;
|
|
17
|
+
let ended = false;
|
|
18
|
+
return {
|
|
19
|
+
now() {
|
|
20
|
+
if (ended)
|
|
21
|
+
return last;
|
|
22
|
+
if (index < readings.length)
|
|
23
|
+
last = readings[index++];
|
|
24
|
+
else
|
|
25
|
+
overran = true;
|
|
26
|
+
return last;
|
|
27
|
+
},
|
|
28
|
+
rewind() {
|
|
29
|
+
index = 0;
|
|
30
|
+
last = start;
|
|
31
|
+
overran = false;
|
|
32
|
+
ended = false;
|
|
33
|
+
},
|
|
34
|
+
end() {
|
|
35
|
+
ended = true;
|
|
36
|
+
},
|
|
37
|
+
used: () => index,
|
|
38
|
+
overran: () => overran,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/** Replays the recorded random values, then continues with a source seeded with `seed`. */
|
|
42
|
+
function tapeRandom(values, seed) {
|
|
43
|
+
let index = 0;
|
|
44
|
+
let overran = false;
|
|
45
|
+
let fallback = seededRandom(seed);
|
|
46
|
+
let ended = false;
|
|
47
|
+
return {
|
|
48
|
+
seed,
|
|
49
|
+
next() {
|
|
50
|
+
if (ended)
|
|
51
|
+
return fallback.next();
|
|
52
|
+
if (index < values.length)
|
|
53
|
+
return values[index++];
|
|
54
|
+
overran = true;
|
|
55
|
+
return fallback.next();
|
|
56
|
+
},
|
|
57
|
+
rewind() {
|
|
58
|
+
index = 0;
|
|
59
|
+
overran = false;
|
|
60
|
+
ended = false;
|
|
61
|
+
fallback = seededRandom(seed);
|
|
62
|
+
},
|
|
63
|
+
end() {
|
|
64
|
+
ended = true;
|
|
65
|
+
},
|
|
66
|
+
used: () => index,
|
|
67
|
+
overran: () => overran,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/** What replay could not restore for `entry`, from how its tape was read. */
|
|
71
|
+
function tapeNotes(entry, clock, random) {
|
|
72
|
+
const { tape } = entry;
|
|
73
|
+
if (!tape)
|
|
74
|
+
return [];
|
|
75
|
+
const notes = [];
|
|
76
|
+
if (tape.truncated)
|
|
77
|
+
notes.push('the recorded tape was truncated; values past it are not restored');
|
|
78
|
+
if (clock?.overran()) {
|
|
79
|
+
notes.push(`clock: the tape holds ${tape.clock.length} readings and the replay read more; later readings repeat the last one`);
|
|
80
|
+
}
|
|
81
|
+
else if (clock && clock.used() < tape.clock.length) {
|
|
82
|
+
notes.push(`clock: the replay read ${clock.used()} of ${tape.clock.length} recorded readings`);
|
|
83
|
+
}
|
|
84
|
+
if (random.overran()) {
|
|
85
|
+
notes.push(`random: the tape holds ${tape.random.length} values and the replay read more; later values come from seed '${random.seed}'`);
|
|
86
|
+
}
|
|
87
|
+
else if (random.used() < tape.random.length) {
|
|
88
|
+
notes.push(`random: the replay read ${random.used()} of ${tape.random.length} recorded values`);
|
|
89
|
+
}
|
|
90
|
+
return notes;
|
|
91
|
+
}
|
|
92
|
+
/** `value` as plain JSON, so recorded and replayed results compare the same way. */
|
|
93
|
+
function toJson(value) {
|
|
94
|
+
const text = JSON.stringify(value);
|
|
95
|
+
return text === undefined ? null : JSON.parse(text);
|
|
96
|
+
}
|
|
97
|
+
function isPlainObject(value) {
|
|
98
|
+
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
99
|
+
}
|
|
100
|
+
function childPath(path, key) {
|
|
101
|
+
return path === '' ? key : `${path}.${key}`;
|
|
102
|
+
}
|
|
103
|
+
/** Structural differences between two JSON values, skipping `ignore` paths. */
|
|
104
|
+
function diffJson(recorded, replayed, path, ignore, out, max) {
|
|
105
|
+
if (out.length >= max || ignore.has(path))
|
|
106
|
+
return;
|
|
107
|
+
if (Array.isArray(recorded) && Array.isArray(replayed)) {
|
|
108
|
+
for (let i = 0; i < Math.max(recorded.length, replayed.length); i++) {
|
|
109
|
+
const at = `${path}[${i}]`;
|
|
110
|
+
if (i >= replayed.length) {
|
|
111
|
+
if (!ignore.has(at) && out.length < max)
|
|
112
|
+
out.push({ path: at, kind: 'removed', recorded: recorded[i] });
|
|
113
|
+
}
|
|
114
|
+
else if (i >= recorded.length) {
|
|
115
|
+
if (!ignore.has(at) && out.length < max)
|
|
116
|
+
out.push({ path: at, kind: 'added', replayed: replayed[i] });
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
diffJson(recorded[i], replayed[i], at, ignore, out, max);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (isPlainObject(recorded) && isPlainObject(replayed)) {
|
|
125
|
+
const keys = new Set([...Object.keys(recorded), ...Object.keys(replayed)]);
|
|
126
|
+
for (const key of [...keys].sort()) {
|
|
127
|
+
const at = childPath(path, key);
|
|
128
|
+
if (!Object.hasOwn(replayed, key)) {
|
|
129
|
+
if (!ignore.has(at) && out.length < max)
|
|
130
|
+
out.push({ path: at, kind: 'removed', recorded: recorded[key] });
|
|
131
|
+
}
|
|
132
|
+
else if (!Object.hasOwn(recorded, key)) {
|
|
133
|
+
if (!ignore.has(at) && out.length < max)
|
|
134
|
+
out.push({ path: at, kind: 'added', replayed: replayed[key] });
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
diffJson(recorded[key], replayed[key], at, ignore, out, max);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (recorded !== replayed)
|
|
143
|
+
out.push({ path, kind: 'changed', recorded, replayed });
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Re-execute journal entries in `seq` order against `registry` and compare each result with
|
|
147
|
+
* the recorded one.
|
|
148
|
+
*
|
|
149
|
+
* Each call gets the entry's trace ID, actor and interface, and a clock and random source
|
|
150
|
+
* that return the values recorded on its tape. An entry without a tape gets a clock fixed at
|
|
151
|
+
* its `timestamp` and a random source seeded with `${seed}:${seq}`. The registry should be
|
|
152
|
+
* fresh (or reset to the state the recording started from): replay re-runs mutations. Give it
|
|
153
|
+
* the same middleware as the recording server: a journal middleware in it lines the tape up
|
|
154
|
+
* with the handler and records nothing during replay.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```typescript
|
|
158
|
+
* const entries = parseJournal(readFileSync('session.jsonl', 'utf8'));
|
|
159
|
+
* const report = await replayJournal(createMcpServer({ name: 'todo', version: '1', commands }), entries);
|
|
160
|
+
* if (report.diverged) console.log(report.entries.filter((entry) => entry.status !== 'same'));
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
export async function replayJournal(registry, entries, options = {}) {
|
|
164
|
+
const ignore = new Set(options.ignore ?? DEFAULT_IGNORE);
|
|
165
|
+
const seed = options.seed ?? 'afd-replay';
|
|
166
|
+
const maxDifferences = options.maxDifferences ?? DEFAULT_MAX_DIFFERENCES;
|
|
167
|
+
const ordered = [...entries].sort((a, b) => a.seq - b.seq);
|
|
168
|
+
const report = {
|
|
169
|
+
entries: [],
|
|
170
|
+
same: 0,
|
|
171
|
+
different: 0,
|
|
172
|
+
errors: 0,
|
|
173
|
+
diverged: false,
|
|
174
|
+
skipped: 0,
|
|
175
|
+
};
|
|
176
|
+
for (const [index, entry] of ordered.entries()) {
|
|
177
|
+
const { tape } = entry;
|
|
178
|
+
const random = tapeRandom(tape?.random ?? [], `${seed}:${entry.seq}`);
|
|
179
|
+
let clock;
|
|
180
|
+
let outcome;
|
|
181
|
+
try {
|
|
182
|
+
// Inside the try: a bad timestamp or a throwing context factory fails this entry only.
|
|
183
|
+
clock = tape ? tapeClock(tape.clock, Date.parse(entry.timestamp)) : undefined;
|
|
184
|
+
const actor = journalActor(entry.actor);
|
|
185
|
+
const extra = typeof options.context === 'function' ? options.context(entry) : options.context;
|
|
186
|
+
const context = {
|
|
187
|
+
...(entry.traceId !== undefined ? { traceId: entry.traceId } : {}),
|
|
188
|
+
...(actor ? { actor } : {}),
|
|
189
|
+
...(entry.contextDigest.interface !== undefined
|
|
190
|
+
? { interface: entry.contextDigest.interface }
|
|
191
|
+
: {}),
|
|
192
|
+
clock: clock ?? fixedClock(entry.timestamp),
|
|
193
|
+
random,
|
|
194
|
+
...extra,
|
|
195
|
+
};
|
|
196
|
+
// A journal middleware in the replayed chain rewinds the tape where it sits, so
|
|
197
|
+
// middleware outside it does not shift the handler's readings.
|
|
198
|
+
const marker = {
|
|
199
|
+
rewind() {
|
|
200
|
+
clock?.rewind();
|
|
201
|
+
random.rewind();
|
|
202
|
+
},
|
|
203
|
+
end() {
|
|
204
|
+
clock?.end();
|
|
205
|
+
random.end();
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
context[JOURNAL_REPLAY] = marker;
|
|
209
|
+
const replayed = await registry.execute(entry.command, entry.input, context);
|
|
210
|
+
const differences = [];
|
|
211
|
+
diffJson(toJson(entry.result), toJson(replayed), '', ignore, differences, maxDifferences);
|
|
212
|
+
outcome = {
|
|
213
|
+
seq: entry.seq,
|
|
214
|
+
command: entry.command,
|
|
215
|
+
status: differences.length === 0 ? 'same' : 'different',
|
|
216
|
+
recorded: entry.result,
|
|
217
|
+
replayed,
|
|
218
|
+
...(differences.length > 0 ? { differences } : {}),
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
outcome = {
|
|
223
|
+
seq: entry.seq,
|
|
224
|
+
command: entry.command,
|
|
225
|
+
status: 'error',
|
|
226
|
+
recorded: entry.result,
|
|
227
|
+
error: error instanceof Error ? error.message : String(error),
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
const notes = tapeNotes(entry, clock, random);
|
|
231
|
+
if (notes.length > 0)
|
|
232
|
+
outcome.notes = notes;
|
|
233
|
+
report.entries.push(outcome);
|
|
234
|
+
if (outcome.status === 'same')
|
|
235
|
+
report.same++;
|
|
236
|
+
else if (outcome.status === 'different')
|
|
237
|
+
report.different++;
|
|
238
|
+
else
|
|
239
|
+
report.errors++;
|
|
240
|
+
if (outcome.status !== 'same') {
|
|
241
|
+
report.diverged = true;
|
|
242
|
+
if (options.stopOnDivergence) {
|
|
243
|
+
report.skipped = ordered.length - index - 1;
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return report;
|
|
249
|
+
}
|
|
250
|
+
//# sourceMappingURL=journal-replay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"journal-replay.js","sourceRoot":"","sources":["../src/journal-replay.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AASH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,EAAE,cAAc,EAA4B,MAAM,cAAc,CAAC;AA6ExE,MAAM,cAAc,GAAG,CAAC,0BAA0B,CAAC,CAAC;AACpD,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAcpC,oEAAoE;AACpE,SAAS,SAAS,CAAC,QAA2B,EAAE,KAAa;IAC5D,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,IAAI,GAAG,KAAK,CAAC;IACjB,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,IAAI,KAAK,GAAG,KAAK,CAAC;IAClB,OAAO;QACN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AAC,OAAO,KAAK,EAAE,CAAC;YAChB,OAAO,GAAG;gBACT,GAAG,EAAE,KAAK,CAAC,GAAG;gBACd,OAAO,EAAE,KAAK,CAAC,OAAO;gBACtB,MAAM,EAAE,OAAO;gBACf,QAAQ,EAAE,KAAK,CAAC,MAAM;gBACtB,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;aAC7D,CAAC;QACH,CAAC;QAED,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;QAC9C,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;YAAE,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC;QAE5C,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC7B,IAAI,OAAO,CAAC,MAAM,KAAK,MAAM;YAAE,MAAM,CAAC,IAAI,EAAE,CAAC;aACxC,IAAI,OAAO,CAAC,MAAM,KAAK,WAAW;YAAE,MAAM,CAAC,SAAS,EAAE,CAAC;;YACvD,MAAM,CAAC,MAAM,EAAE,CAAC;QAErB,IAAI,OAAO,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;YAC/B,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC;YACvB,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;gBAC9B,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,GAAG,KAAK,GAAG,CAAC,CAAC;gBAC5C,MAAM;YACP,CAAC;QACF,CAAC;IACF,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Journal middleware: records each accepted command call to a `JournalSink`.
|
|
3
|
+
*
|
|
4
|
+
* Server middleware runs after lookup, exposure and input validation, so a call rejected
|
|
5
|
+
* there never reaches it and is never recorded. See `replayJournal()` in
|
|
6
|
+
* `journal-replay.ts` for playing a journal back.
|
|
7
|
+
*/
|
|
8
|
+
import type { CommandMiddleware, JournalRecord, JournalSink } from '@lushly-dev/afd-core';
|
|
9
|
+
/**
|
|
10
|
+
* Context key `replayJournal()` sets on each replayed call. The first journal middleware that
|
|
11
|
+
* finds it rewinds the replay tape at its own position, so readings by middleware outside it do
|
|
12
|
+
* not shift what the handler gets, and spends the marker so nested calls and inner journals do
|
|
13
|
+
* not rewind again. No journal middleware records during replay. Only `replayJournal()` sets it.
|
|
14
|
+
*
|
|
15
|
+
* A registered symbol (`Symbol.for`), so separately loaded copies of afd-server agree on it: a
|
|
16
|
+
* globally installed `afd replay` marks calls that a project's own copy of the journal
|
|
17
|
+
* middleware recognizes. Any code can therefore name it, but setting it only stops recording
|
|
18
|
+
* and rewinds a tape the caller would have to supply itself.
|
|
19
|
+
*/
|
|
20
|
+
export declare const JOURNAL_REPLAY: unique symbol;
|
|
21
|
+
/** The value under {@link JOURNAL_REPLAY}. */
|
|
22
|
+
export interface JournalReplayMarker {
|
|
23
|
+
/** Restart the replay clock and random source from the first recorded value. */
|
|
24
|
+
rewind(): void;
|
|
25
|
+
/** The handler is done: readings after this (by outer middleware) are not tape overruns. */
|
|
26
|
+
end(): void;
|
|
27
|
+
}
|
|
28
|
+
/** Options for {@link createJournalMiddleware}. */
|
|
29
|
+
export interface JournalMiddlewareOptions {
|
|
30
|
+
/**
|
|
31
|
+
* Also record calls that fail after validation: a failure result from the handler or from
|
|
32
|
+
* middleware inside this one (an auth or approval rejection), and a handler that throws
|
|
33
|
+
* (recorded as the `COMMAND_EXECUTION_ERROR` result the server returns outside devMode,
|
|
34
|
+
* without the exception message). Default `false`:
|
|
35
|
+
* only successful calls are recorded.
|
|
36
|
+
*/
|
|
37
|
+
recordFailures?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Record only the commands this returns `true` for. Default: every command except those
|
|
40
|
+
* named `auth-*` (`@lushly-dev/afd-auth`'s `auth-sign-in` takes a password). A custom
|
|
41
|
+
* filter replaces the default, so exclude `auth-*` in it too unless you redact them.
|
|
42
|
+
*/
|
|
43
|
+
filter?: (commandName: string) => boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Last look at each record before it is stored: return it (changed or not), or `undefined`
|
|
46
|
+
* to skip it. Use it to drop secrets from inputs or results, such as a password argument
|
|
47
|
+
* or an issued token. A redacted entry may no longer replay to the same result. When a secret
|
|
48
|
+
* is derived from `context.random` (a generated code or token), drop `record.tape` too:
|
|
49
|
+
* the recorded random values would rebuild it.
|
|
50
|
+
*/
|
|
51
|
+
redact?: (record: JournalRecord) => JournalRecord | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Most clock readings and most random values kept per call, each. Past it the tape is
|
|
54
|
+
* marked `truncated` and replay cannot restore the rest. Default 1000.
|
|
55
|
+
*/
|
|
56
|
+
maxTapeReads?: number;
|
|
57
|
+
/** Called when building or appending an entry fails. The command result is unaffected. */
|
|
58
|
+
onError?: (error: Error) => void;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Create a middleware that appends a `JournalEntry` to `sink` for each command call.
|
|
62
|
+
*
|
|
63
|
+
* Each entry holds the command, its validated input, the actor, the trace ID, a context
|
|
64
|
+
* digest (a hash plus the interface; no other context value), the result and the duration.
|
|
65
|
+
* It also holds the tape: every value the handler read from `context.clock` and
|
|
66
|
+
* `context.random`, which `replayJournal()` feeds back. Place this middleware last in the
|
|
67
|
+
* list, so the tape holds only what the handler (and the server's own timing) read, and so
|
|
68
|
+
* the actor it records is the one auth middleware settled on.
|
|
69
|
+
*
|
|
70
|
+
* Appends are awaited, so entries are in call order for sequential calls, and sink latency is
|
|
71
|
+
* added to each recorded call. A sink error goes to `onError` and never changes the command
|
|
72
|
+
* result. Commands named `auth-*` are not recorded unless `filter` allows them. During
|
|
73
|
+
* `replayJournal()` this middleware records nothing; it restarts the replay tape at its position.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* import { createJournalMiddleware, createMcpServer } from '@lushly-dev/afd-server';
|
|
78
|
+
* import { MemoryJournalSink } from '@lushly-dev/afd-core';
|
|
79
|
+
*
|
|
80
|
+
* const journal = new MemoryJournalSink();
|
|
81
|
+
* const server = createMcpServer({
|
|
82
|
+
* name: 'todo',
|
|
83
|
+
* version: '1.0.0',
|
|
84
|
+
* commands,
|
|
85
|
+
* middleware: [createAuthMiddleware(auth), createJournalMiddleware(journal)],
|
|
86
|
+
* });
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export declare function createJournalMiddleware(sink: JournalSink, options?: JournalMiddlewareOptions): CommandMiddleware;
|
|
90
|
+
//# sourceMappingURL=journal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"journal.d.ts","sourceRoot":"","sources":["../src/journal.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAEX,iBAAiB,EAEjB,aAAa,EACb,WAAW,EAGX,MAAM,sBAAsB,CAAC;AAS9B;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc,EAAE,OAAO,MAA4D,CAAC;AAejG,8CAA8C;AAC9C,MAAM,WAAW,mBAAmB;IACnC,gFAAgF;IAChF,MAAM,IAAI,IAAI,CAAC;IACf,4FAA4F;IAC5F,GAAG,IAAI,IAAI,CAAC;CACZ;AAOD,mDAAmD;AACnD,MAAM,WAAW,wBAAwB;IACxC;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;;OAIG;IACH,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,OAAO,CAAC;IAC1C;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,aAAa,GAAG,SAAS,CAAC;IAC9D;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,0FAA0F;IAC1F,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CACjC;AA8CD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,uBAAuB,CACtC,IAAI,EAAE,WAAW,EACjB,OAAO,GAAE,wBAA6B,GACpC,iBAAiB,CA6EnB"}
|
package/dist/journal.js
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Journal middleware: records each accepted command call to a `JournalSink`.
|
|
3
|
+
*
|
|
4
|
+
* Server middleware runs after lookup, exposure and input validation, so a call rejected
|
|
5
|
+
* there never reaches it and is never recorded. See `replayJournal()` in
|
|
6
|
+
* `journal-replay.ts` for playing a journal back.
|
|
7
|
+
*/
|
|
8
|
+
import { createContextDigest, executionFailure, journalActor, systemClock, systemRandom, } from '@lushly-dev/afd-core';
|
|
9
|
+
/**
|
|
10
|
+
* Context key `replayJournal()` sets on each replayed call. The first journal middleware that
|
|
11
|
+
* finds it rewinds the replay tape at its own position, so readings by middleware outside it do
|
|
12
|
+
* not shift what the handler gets, and spends the marker so nested calls and inner journals do
|
|
13
|
+
* not rewind again. No journal middleware records during replay. Only `replayJournal()` sets it.
|
|
14
|
+
*
|
|
15
|
+
* A registered symbol (`Symbol.for`), so separately loaded copies of afd-server agree on it: a
|
|
16
|
+
* globally installed `afd replay` marks calls that a project's own copy of the journal
|
|
17
|
+
* middleware recognizes. Any code can therefore name it, but setting it only stops recording
|
|
18
|
+
* and rewinds a tape the caller would have to supply itself.
|
|
19
|
+
*/
|
|
20
|
+
export const JOURNAL_REPLAY = Symbol.for('@lushly-dev/afd-server/journal-replay');
|
|
21
|
+
/** A marker that does nothing: what nested calls and inner journal middleware see. */
|
|
22
|
+
const SPENT_REPLAY = { rewind() { }, end() { } };
|
|
23
|
+
/** On a recording clock: the clock it wraps, for timing that must stay off the tape. */
|
|
24
|
+
const UNTAPED = Symbol('afd.journal.untaped');
|
|
25
|
+
/** The clock under any recording wrappers, so a journal's own timing lands on no tape. */
|
|
26
|
+
function untaped(clock) {
|
|
27
|
+
let current = clock;
|
|
28
|
+
while (current[UNTAPED])
|
|
29
|
+
current = current[UNTAPED];
|
|
30
|
+
return current;
|
|
31
|
+
}
|
|
32
|
+
/** Commands not recorded unless `filter` says otherwise: the auth commands take passwords and return sessions. */
|
|
33
|
+
function defaultFilter(commandName) {
|
|
34
|
+
return !commandName.startsWith('auth-');
|
|
35
|
+
}
|
|
36
|
+
const DEFAULT_MAX_TAPE_READS = 1000;
|
|
37
|
+
/** `value` as plain JSON (a copy), so the entry is what a JSON Lines file would hold. */
|
|
38
|
+
function toJson(value) {
|
|
39
|
+
const text = JSON.stringify(value);
|
|
40
|
+
return text === undefined ? null : JSON.parse(text);
|
|
41
|
+
}
|
|
42
|
+
function toError(error) {
|
|
43
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
44
|
+
}
|
|
45
|
+
/** A clock and random source that pass values through and write them to `tape`. */
|
|
46
|
+
function recordingSources(clock, random, tape, maxReads) {
|
|
47
|
+
const keep = (values, value) => {
|
|
48
|
+
if (values.length < maxReads)
|
|
49
|
+
values.push(value);
|
|
50
|
+
else
|
|
51
|
+
tape.truncated = true;
|
|
52
|
+
};
|
|
53
|
+
const recordingClock = {
|
|
54
|
+
[UNTAPED]: clock,
|
|
55
|
+
now() {
|
|
56
|
+
const value = clock.now();
|
|
57
|
+
keep(tape.clock, value);
|
|
58
|
+
return value;
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
return {
|
|
62
|
+
clock: recordingClock,
|
|
63
|
+
random: {
|
|
64
|
+
...(random.seed !== undefined ? { seed: random.seed } : {}),
|
|
65
|
+
next() {
|
|
66
|
+
const value = random.next();
|
|
67
|
+
keep(tape.random, value);
|
|
68
|
+
return value;
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Create a middleware that appends a `JournalEntry` to `sink` for each command call.
|
|
75
|
+
*
|
|
76
|
+
* Each entry holds the command, its validated input, the actor, the trace ID, a context
|
|
77
|
+
* digest (a hash plus the interface; no other context value), the result and the duration.
|
|
78
|
+
* It also holds the tape: every value the handler read from `context.clock` and
|
|
79
|
+
* `context.random`, which `replayJournal()` feeds back. Place this middleware last in the
|
|
80
|
+
* list, so the tape holds only what the handler (and the server's own timing) read, and so
|
|
81
|
+
* the actor it records is the one auth middleware settled on.
|
|
82
|
+
*
|
|
83
|
+
* Appends are awaited, so entries are in call order for sequential calls, and sink latency is
|
|
84
|
+
* added to each recorded call. A sink error goes to `onError` and never changes the command
|
|
85
|
+
* result. Commands named `auth-*` are not recorded unless `filter` allows them. During
|
|
86
|
+
* `replayJournal()` this middleware records nothing; it restarts the replay tape at its position.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* import { createJournalMiddleware, createMcpServer } from '@lushly-dev/afd-server';
|
|
91
|
+
* import { MemoryJournalSink } from '@lushly-dev/afd-core';
|
|
92
|
+
*
|
|
93
|
+
* const journal = new MemoryJournalSink();
|
|
94
|
+
* const server = createMcpServer({
|
|
95
|
+
* name: 'todo',
|
|
96
|
+
* version: '1.0.0',
|
|
97
|
+
* commands,
|
|
98
|
+
* middleware: [createAuthMiddleware(auth), createJournalMiddleware(journal)],
|
|
99
|
+
* });
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export function createJournalMiddleware(sink, options = {}) {
|
|
103
|
+
const { recordFailures = false, filter = defaultFilter, redact = (record) => record, maxTapeReads = DEFAULT_MAX_TAPE_READS, onError, } = options;
|
|
104
|
+
return async (commandName, input, context, next) => {
|
|
105
|
+
const replay = context[JOURNAL_REPLAY];
|
|
106
|
+
if (replay) {
|
|
107
|
+
replay.rewind();
|
|
108
|
+
context[JOURNAL_REPLAY] = SPENT_REPLAY;
|
|
109
|
+
try {
|
|
110
|
+
return await next();
|
|
111
|
+
}
|
|
112
|
+
finally {
|
|
113
|
+
replay.end();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (!filter(commandName))
|
|
117
|
+
return next();
|
|
118
|
+
const clock = context.clock ?? systemClock;
|
|
119
|
+
const random = context.random ?? systemRandom;
|
|
120
|
+
const tape = { clock: [], random: [] };
|
|
121
|
+
// The same context object reaches the handler, so swapping its sources records what it reads.
|
|
122
|
+
const recording = recordingSources(clock, random, tape, maxTapeReads);
|
|
123
|
+
context.clock = recording.clock;
|
|
124
|
+
context.random = recording.random;
|
|
125
|
+
// This journal's own timing reads the clock under any outer journal's recorder.
|
|
126
|
+
const timing = untaped(clock);
|
|
127
|
+
const start = timing.now();
|
|
128
|
+
let result;
|
|
129
|
+
let thrown;
|
|
130
|
+
try {
|
|
131
|
+
result = await next();
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
thrown = { error };
|
|
135
|
+
}
|
|
136
|
+
finally {
|
|
137
|
+
context.clock = clock;
|
|
138
|
+
context.random = random;
|
|
139
|
+
}
|
|
140
|
+
const durationMs = Math.max(0, timing.now() - start);
|
|
141
|
+
// What the server returns for a throw outside devMode, never the exception message.
|
|
142
|
+
const recorded = result ?? executionFailure(thrown?.error, false);
|
|
143
|
+
if (recorded.success || recordFailures) {
|
|
144
|
+
try {
|
|
145
|
+
const actor = journalActor(context.actor);
|
|
146
|
+
const hasTape = tape.clock.length > 0 || tape.random.length > 0 || tape.truncated;
|
|
147
|
+
const record = redact({
|
|
148
|
+
timestamp: new Date(start).toISOString(),
|
|
149
|
+
...(typeof context.traceId === 'string' ? { traceId: context.traceId } : {}),
|
|
150
|
+
command: commandName,
|
|
151
|
+
input: toJson(input),
|
|
152
|
+
...(actor ? { actor } : {}),
|
|
153
|
+
contextDigest: await createContextDigest(context),
|
|
154
|
+
result: toJson(recorded),
|
|
155
|
+
durationMs,
|
|
156
|
+
...(hasTape ? { tape } : {}),
|
|
157
|
+
});
|
|
158
|
+
if (record)
|
|
159
|
+
await sink.append(record);
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
try {
|
|
163
|
+
onError?.(toError(error));
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
// A failing onError has nowhere left to report.
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (thrown)
|
|
171
|
+
throw thrown.error;
|
|
172
|
+
return recorded;
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=journal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"journal.js","sourceRoot":"","sources":["../src/journal.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAWH,OAAO,EACN,mBAAmB,EACnB,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,YAAY,GACZ,MAAM,sBAAsB,CAAC;AAE9B;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,cAAc,GAAkB,MAAM,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;AAEjG,sFAAsF;AACtF,MAAM,YAAY,GAAwB,EAAE,MAAM,KAAI,CAAC,EAAE,GAAG,KAAI,CAAC,EAAE,CAAC;AAEpE,wFAAwF;AACxF,MAAM,OAAO,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AAE9C,0FAA0F;AAC1F,SAAS,OAAO,CAAC,KAAY;IAC5B,IAAI,OAAO,GAAkC,KAAK,CAAC;IACnD,OAAO,OAAO,CAAC,OAAO,CAAC;QAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACpD,OAAO,OAAO,CAAC;AAChB,CAAC;AAUD,kHAAkH;AAClH,SAAS,aAAa,CAAC,WAAmB;IACzC,OAAO,CAAC,WAAW,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AACzC,CAAC;AAmCD,MAAM,sBAAsB,GAAG,IAAI,CAAC;AAEpC,yFAAyF;AACzF,SAAS,MAAM,CAAC,KAAc;IAC7B,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC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WAAW,EAAE,UAAU,CAAC;IACxB,YAAY,CAAC,EAAE,UAAU,CAAC;IAC1B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,cAAc,GAAG,UAAU,GAAG,aAAa,CAAC;IACvD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;CAClB;AAED,UAAU,WAAW;IACpB,sEAAsE;IACtE,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,KAAK,CAAC;IACb,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;CAC7D;AAED,KAAK,WAAW,GAAG,YAAY,GAAG,WAAW,CAAC;AAgC9C,wBAAgB,eAAe,CAC9B,QAAQ,EAAE,oBAAoB,EAAE,EAChC,KAAK,EAAE,aAAa,GAClB,aAAa,CAAC,cAAc,CAAC,CAuE/B;AAMD,wBAAgB,aAAa,CAC5B,qBAAqB,EAAE,oBAAoB,EAAE,EAC7C,mBAAmB,EAAE,GAAG,CAAC,MAAM,CAAC,EAChC,KAAK,EAAE,WAAW,GAChB,aAAa,CAAC,WAAW,EAAE,CAAC,CAqD9B"}
|
package/dist/lazy-tools.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Lazy-loading discovery tools: afd-discover, afd-detail.
|
|
3
3
|
*/
|
|
4
|
-
import { success, truncateName } from '@lushly-dev/afd-core';
|
|
4
|
+
import { approvalMode, success, truncateName } from '@lushly-dev/afd-core';
|
|
5
5
|
import { defaultCommandGroup, notFoundSuggestion } from './command-routing.js';
|
|
6
6
|
// ═══════════════════════════════════════════════════════════════════════════════
|
|
7
7
|
// HELPERS
|
|
@@ -123,6 +123,7 @@ export function executeDetail(allRegisteredCommands, exposedCommandNames, input)
|
|
|
123
123
|
destructive: cmd.destructive,
|
|
124
124
|
confirmPrompt: cmd.confirmPrompt,
|
|
125
125
|
undoable: cmd.undoable,
|
|
126
|
+
approval: approvalMode(cmd.approval),
|
|
126
127
|
handoff: cmd.handoff,
|
|
127
128
|
handoffProtocol: cmd.handoffProtocol,
|
|
128
129
|
version: cmd.version,
|
package/dist/lazy-tools.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazy-tools.js","sourceRoot":"","sources":["../src/lazy-tools.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"lazy-tools.js","sourceRoot":"","sources":["../src/lazy-tools.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAC3E,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAuD/E,kFAAkF;AAClF,UAAU;AACV,kFAAkF;AAElF,SAAS,mBAAmB,CAAC,IAAY,EAAE,GAAG,GAAG,GAAG;IACnD,MAAM,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;IACpD,IAAI,aAAa,CAAC,MAAM,IAAI,GAAG;QAAE,OAAO,aAAa,CAAC;IACtD,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC,QAAQ,CAAC;AAC1C,CAAC;AAED,SAAS,aAAa,CAAC,GAAyB,EAAE,KAAa;IAC9D,MAAM,MAAM,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC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