@sensigo/realm-mcp 0.25.0 → 0.27.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/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/json-trace-buffer-store.d.ts +170 -4
- package/dist/json-trace-buffer-store.d.ts.map +1 -1
- package/dist/json-trace-buffer-store.js +571 -73
- package/dist/json-trace-buffer-store.js.map +1 -1
- package/dist/server.d.ts +37 -3
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +43 -5
- package/dist/server.js.map +1 -1
- package/dist/tools/abandon-run.d.ts +3 -2
- package/dist/tools/abandon-run.d.ts.map +1 -1
- package/dist/tools/abandon-run.js.map +1 -1
- package/dist/tools/append-trace.d.ts +28 -8
- package/dist/tools/append-trace.d.ts.map +1 -1
- package/dist/tools/append-trace.js +253 -25
- package/dist/tools/append-trace.js.map +1 -1
- package/dist/tools/create-workflow.d.ts +2 -2
- package/dist/tools/create-workflow.d.ts.map +1 -1
- package/dist/tools/create-workflow.js.map +1 -1
- package/dist/tools/execute-step.d.ts +21 -1
- package/dist/tools/execute-step.d.ts.map +1 -1
- package/dist/tools/execute-step.js +94 -1
- package/dist/tools/execute-step.js.map +1 -1
- package/dist/tools/get-run-state.d.ts +11 -2
- package/dist/tools/get-run-state.d.ts.map +1 -1
- package/dist/tools/get-run-state.js +13 -1
- package/dist/tools/get-run-state.js.map +1 -1
- package/dist/tools/get-workflow-protocol.d.ts.map +1 -1
- package/dist/tools/get-workflow-protocol.js +13 -1
- package/dist/tools/get-workflow-protocol.js.map +1 -1
- package/dist/tools/start-run.d.ts +12 -3
- package/dist/tools/start-run.d.ts.map +1 -1
- package/dist/tools/start-run.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,8 +1,138 @@
|
|
|
1
1
|
// append-trace.ts — append_trace MCP tool for incremental mid-step trace ingestion.
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { JsonWorkflowStore, JsonFileStore, WorkflowError, buildPreExecutionErrorEnvelope, } from '@sensigo/realm';
|
|
4
|
-
import { traceEntrySchema } from './execute-step.js';
|
|
3
|
+
import { JsonWorkflowStore, JsonFileStore, WorkflowError, buildPreExecutionErrorEnvelope, isTerminalPhase, storeDeclaresNonceCarriage, } from '@sensigo/realm';
|
|
4
|
+
import { traceEntrySchema, validateWriterNonceShape, isWriterNonceRequired, writerNonceRequiredError, } from './execute-step.js';
|
|
5
5
|
import { sseJsonStringify } from '../sse-json.js';
|
|
6
|
+
/**
|
|
7
|
+
* Fill-ratio threshold (issue #208) at which `append_trace` starts advising the calling agent
|
|
8
|
+
* that this step's trace buffer is approaching `BUFFER_FULL` — a concrete instantiation of the
|
|
9
|
+
* issue's own "e.g. 80%" motivation. Advisory only (#119): never gates, never changes `status`.
|
|
10
|
+
* Chosen at 0.8 as the balance point: early enough that an agent can still act (trim tracing
|
|
11
|
+
* verbosity, or call `execute_step` to finalize the step) before the ceiling is hit, but late
|
|
12
|
+
* enough that it doesn't nag on every ordinary append.
|
|
13
|
+
*/
|
|
14
|
+
const CAPACITY_WARNING_THRESHOLD = 0.8;
|
|
15
|
+
/**
|
|
16
|
+
* Pure, store-agnostic capacity-warning helper (issue #208, AC 1/3/4; re-homed on both bounds by
|
|
17
|
+
* issue #197 PR-2) — every `AppendResult` already carries `buffer_count`/`limit_count`/
|
|
18
|
+
* `buffer_bytes`/`limit_bytes` (WRITER scope) regardless of which `TraceBufferStore`
|
|
19
|
+
* implementation produced it, so this needs no store-specific knowledge at all. When a carriage
|
|
20
|
+
* store ALSO returns the additive `file_*` fields (whole-FILE scope, all writers combined —
|
|
21
|
+
* `BUFFER_BACKSTOP_*`, 2× the per-writer ceiling), this checks that bound too — naive porting
|
|
22
|
+
* would arithmetically lose a tier (0.8×400 > 200, so a single writer could never trip the file
|
|
23
|
+
* bound before its own writer bound already fired, silently making the file check dead code for
|
|
24
|
+
* exactly the common case it must still cover for multi-writer traffic).
|
|
25
|
+
*
|
|
26
|
+
* Returns `undefined` strictly below `CAPACITY_WARNING_THRESHOLD` on EITHER bound; AT OR ABOVE it
|
|
27
|
+
* on the MORE PRESSING one (`>=`, deliberately not `>` — hitting the threshold exactly still
|
|
28
|
+
* warns) returns ONE deterministic message naming that scope, whichever dimension (entries or
|
|
29
|
+
* bytes) within it is closer to its own ceiling, the actual numbers and percentage, and the
|
|
30
|
+
* issue's own actionable guidance.
|
|
31
|
+
*
|
|
32
|
+
* Byte-identity note (issue #197 PR-2): for a SINGLE writer (all-bare traffic, or any carriage
|
|
33
|
+
* store with only one active writer on this key), the file-scope ratio is ALWAYS EXACTLY HALF the
|
|
34
|
+
* writer-scope ratio (file limit = 2× writer limit, same numerator) — so the writer-scope branch
|
|
35
|
+
* below is provably always the one that fires, reproducing the EXACT pre-#197 message text. The
|
|
36
|
+
* shipped #208 tests (which drive `InMemoryTraceBufferStore` — ALWAYS `file_*`-present since
|
|
37
|
+
* PR-1) exercise precisely this provably-writer-scope-wins path; this claim is verified by running
|
|
38
|
+
* those tests, not merely by this proof (see the PR-2 report's mutation-probe (f) transcript).
|
|
39
|
+
*/
|
|
40
|
+
function capacityWarning(result) {
|
|
41
|
+
const writerCountRatio = result.buffer_count / result.limit_count;
|
|
42
|
+
const writerBytesRatio = result.buffer_bytes / result.limit_bytes;
|
|
43
|
+
const writerRatio = Math.max(writerCountRatio, writerBytesRatio);
|
|
44
|
+
const hasFileScope = result.file_count !== undefined &&
|
|
45
|
+
result.file_limit_count !== undefined &&
|
|
46
|
+
result.file_bytes !== undefined &&
|
|
47
|
+
result.file_limit_bytes !== undefined;
|
|
48
|
+
const fileCountRatio = hasFileScope ? result.file_count / result.file_limit_count : 0;
|
|
49
|
+
const fileBytesRatio = hasFileScope ? result.file_bytes / result.file_limit_bytes : 0;
|
|
50
|
+
const fileRatio = hasFileScope ? Math.max(fileCountRatio, fileBytesRatio) : 0;
|
|
51
|
+
const ratio = Math.max(writerRatio, fileRatio);
|
|
52
|
+
if (ratio < CAPACITY_WARNING_THRESHOLD)
|
|
53
|
+
return undefined;
|
|
54
|
+
if (hasFileScope && fileRatio >= writerRatio) {
|
|
55
|
+
const binding = fileCountRatio >= fileBytesRatio ? 'entries' : 'bytes';
|
|
56
|
+
const detail = binding === 'entries'
|
|
57
|
+
? `${result.file_count}/${result.file_limit_count} entries (${Math.round(fileCountRatio * 100)}%)`
|
|
58
|
+
: `${result.file_bytes}/${result.file_limit_bytes} bytes (${Math.round(fileBytesRatio * 100)}%)`;
|
|
59
|
+
return (`trace buffer for this step (whole-file, all writers combined) is at ${detail} of ` +
|
|
60
|
+
'capacity, approaching the limit — reduce tracing verbosity or call execute_step to ' +
|
|
61
|
+
'finalize the step before further appends are refused with BUFFER_FULL');
|
|
62
|
+
}
|
|
63
|
+
const binding = writerCountRatio >= writerBytesRatio ? 'entries' : 'bytes';
|
|
64
|
+
const detail = binding === 'entries'
|
|
65
|
+
? `${result.buffer_count}/${result.limit_count} entries (${Math.round(writerCountRatio * 100)}%)`
|
|
66
|
+
: `${result.buffer_bytes}/${result.limit_bytes} bytes (${Math.round(writerBytesRatio * 100)}%)`;
|
|
67
|
+
return (`trace buffer for this step is at ${detail} of capacity, approaching the limit — reduce ` +
|
|
68
|
+
'tracing verbosity or call execute_step to finalize the step before further appends are ' +
|
|
69
|
+
'refused with BUFFER_FULL');
|
|
70
|
+
}
|
|
71
|
+
/** The specific settled/in-flight state for a step, or `undefined` if none apply — the granular
|
|
72
|
+
* counterpart to `isStepSettledOrInFlight` (issue #207 PR-2). `append_trace`'s refusal detail
|
|
73
|
+
* must name WHICH state applies: agent guidance differs by state (`in_progress` invites a retry
|
|
74
|
+
* once `execute_step` finishes; `completed`/`failed`/`skipped` are permanent). Checked in a fixed
|
|
75
|
+
* priority order, reused identically pre-CS and inside the `appendFenced` guard so both paths
|
|
76
|
+
* agree on the same taxonomy. */
|
|
77
|
+
function stepStateOf(run, stepId) {
|
|
78
|
+
if (run.completed_steps.includes(stepId))
|
|
79
|
+
return 'completed';
|
|
80
|
+
if (run.failed_steps.includes(stepId))
|
|
81
|
+
return 'failed';
|
|
82
|
+
if (run.skipped_steps.includes(stepId))
|
|
83
|
+
return 'skipped';
|
|
84
|
+
if (run.in_progress_steps.includes(stepId))
|
|
85
|
+
return 'in_progress';
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
function stepNotEligibleError(stepId, runVersion, stepState, extraDetails) {
|
|
89
|
+
const messages = {
|
|
90
|
+
completed: `Step '${stepId}' has already completed.`,
|
|
91
|
+
failed: `Step '${stepId}' has already failed.`,
|
|
92
|
+
skipped: `Step '${stepId}' was skipped.`,
|
|
93
|
+
in_progress: `Step '${stepId}' is currently being executed by execute_step.`,
|
|
94
|
+
run_terminal: `Run is terminal — trace entries can no longer be adopted by any step.`,
|
|
95
|
+
run_not_found: `Run not found at write time — trace entries can no longer be adopted.`,
|
|
96
|
+
};
|
|
97
|
+
return new WorkflowError(messages[stepState], {
|
|
98
|
+
code: 'STATE_STEP_NOT_ELIGIBLE',
|
|
99
|
+
category: 'STATE',
|
|
100
|
+
agentAction: stepState === 'in_progress' ? 'resolve_precondition' : 'report_to_user',
|
|
101
|
+
retryable: false,
|
|
102
|
+
details: { step_id: stepId, step_state: stepState, run_version: runVersion, ...extraDetails },
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/** Store-constructor names already warned about lacking the fenced trio (issue #207 PR-2) —
|
|
106
|
+
* module-level so a long-lived process warns once per store type, not once per call. Exported
|
|
107
|
+
* ONLY for test isolation (`resetUnfencedTraceStoreWarnings`) — production code never calls it. */
|
|
108
|
+
const warnedUnfencedStoreNames = new Set();
|
|
109
|
+
/** Test-only reset hook (issue #207 PR-2): clears the dedup set so a test can assert the
|
|
110
|
+
* console.warn fires fresh, independent of any earlier test's use of a same-named store class. */
|
|
111
|
+
export function resetUnfencedTraceStoreWarnings() {
|
|
112
|
+
warnedUnfencedStoreNames.clear();
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Builds the ok envelope's warnings + `writer_nonce_applied` marker (issue #197 PR-2) — shared by
|
|
116
|
+
* all three append call sites (empty-probe, fenced, unfenced) so this logic lives in exactly one
|
|
117
|
+
* place. `extraWarnings` carries whatever warnings that SPECIFIC call site already has (e.g. the
|
|
118
|
+
* unfenced-store caveat) — capacity and not-persisted are always appended AFTER, matching each
|
|
119
|
+
* call site's own pre-existing ordering convention.
|
|
120
|
+
*/
|
|
121
|
+
function buildAppendOkResult(result, writerNonce, carriageActive, extraWarnings) {
|
|
122
|
+
const warnings = [...extraWarnings];
|
|
123
|
+
const capacity = capacityWarning(result);
|
|
124
|
+
if (capacity !== undefined)
|
|
125
|
+
warnings.push(capacity);
|
|
126
|
+
if (writerNonce !== undefined && !carriageActive) {
|
|
127
|
+
warnings.push('writer_nonce not persisted: attribution unavailable on this store');
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
status: 'ok',
|
|
131
|
+
...result,
|
|
132
|
+
...(warnings.length > 0 ? { warnings } : {}),
|
|
133
|
+
...(writerNonce !== undefined && carriageActive ? { writer_nonce_applied: true } : {}),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
6
136
|
/**
|
|
7
137
|
* Business logic for the append_trace tool.
|
|
8
138
|
* Buffers trace entries to the WAL for (runId, stepId). Entries are merged with
|
|
@@ -17,6 +147,27 @@ export async function handleAppendTrace(args, stores) {
|
|
|
17
147
|
const traceBufferStore = stores?.traceBufferStore;
|
|
18
148
|
// 1. Load the run. Throws STATE_RUN_NOT_FOUND if missing.
|
|
19
149
|
const run = await runStore.get(args.run_id);
|
|
150
|
+
// 1b. issue #187: reject a terminal run BEFORE any step guard or WAL write. A WAL appended to
|
|
151
|
+
// a completed/failed/abandoned/aborted run is always unreadable residue — the step it names
|
|
152
|
+
// will never finalize again, so nothing will ever adopt or delete it. This is the one orphan
|
|
153
|
+
// source correct purge ordering structurally can't reach (a WAL born after purge's snapshot
|
|
154
|
+
// but before the run-file unlink) — refusing it here means it is never created in the first
|
|
155
|
+
// place. A terminal run is permanent, so this is agentAction: 'report_to_user' (NOT
|
|
156
|
+
// provide_input/retryable — retrying can't un-terminate a run).
|
|
157
|
+
if (isTerminalPhase(run.run_phase)) {
|
|
158
|
+
throw new WorkflowError(`Run '${args.run_id}' is terminal (phase: '${run.run_phase}') — trace entries can no longer be adopted by any step.`, {
|
|
159
|
+
code: 'STATE_STEP_NOT_ELIGIBLE',
|
|
160
|
+
category: 'STATE',
|
|
161
|
+
agentAction: 'report_to_user',
|
|
162
|
+
retryable: false,
|
|
163
|
+
details: {
|
|
164
|
+
step_id: args.step_id,
|
|
165
|
+
step_state: 'run_terminal',
|
|
166
|
+
run_phase: run.run_phase,
|
|
167
|
+
run_version: run.version,
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
}
|
|
20
171
|
// 2. Load the workflow definition.
|
|
21
172
|
const definition = await workflowStore.get(run.workflow_id);
|
|
22
173
|
// 3. Find the step in the definition.
|
|
@@ -40,24 +191,14 @@ export async function handleAppendTrace(args, stores) {
|
|
|
40
191
|
details: { step_id: args.step_id, step_type: stepDef.execution, run_version: run.version },
|
|
41
192
|
});
|
|
42
193
|
}
|
|
43
|
-
// 5.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
if (run.in_progress_steps.includes(args.step_id)) {
|
|
54
|
-
throw new WorkflowError(`Step '${args.step_id}' is currently being executed by execute_step.`, {
|
|
55
|
-
code: 'STATE_STEP_NOT_ELIGIBLE',
|
|
56
|
-
category: 'STATE',
|
|
57
|
-
agentAction: 'report_to_user',
|
|
58
|
-
retryable: false,
|
|
59
|
-
details: { step_id: args.step_id, step_state: 'in_progress', run_version: run.version },
|
|
60
|
-
});
|
|
194
|
+
// 5. Pre-CS fast-fail eligibility check (issue #207 PR-2): granular step_state values aligned
|
|
195
|
+
// to the guard taxonomy (stepStateOf/stepNotEligibleError, above) — 'skipped' is a NEW check
|
|
196
|
+
// (the latent omission D3 identified: a skipped step could previously still accept a trace
|
|
197
|
+
// append). Race-invariant: step existence and execution === 'agent' were already closed over
|
|
198
|
+
// above: this check only reads the four step-membership arrays off the SAME pre-CS `run` load.
|
|
199
|
+
const preCsState = stepStateOf(run, args.step_id);
|
|
200
|
+
if (preCsState !== undefined) {
|
|
201
|
+
throw stepNotEligibleError(args.step_id, run.version, preCsState);
|
|
61
202
|
}
|
|
62
203
|
// Steps 6 + 7: Require buffer store for any append_trace operation.
|
|
63
204
|
if (traceBufferStore === undefined) {
|
|
@@ -68,14 +209,91 @@ export async function handleAppendTrace(args, stores) {
|
|
|
68
209
|
retryable: false,
|
|
69
210
|
});
|
|
70
211
|
}
|
|
71
|
-
// 6
|
|
212
|
+
// issue #197 PR-2 (design §6): shape-validate BEFORE anything else touches the store — routes
|
|
213
|
+
// every violation through ONE typed refusal, never a bare zod/SDK error.
|
|
214
|
+
if (args.writer_nonce !== undefined) {
|
|
215
|
+
validateWriterNonceShape(args.writer_nonce);
|
|
216
|
+
}
|
|
217
|
+
// issue #197 PR-2 (design §6, dormant strict posture — default off, zero behavior change):
|
|
218
|
+
// non-agent steps already refused above (step 4), before this check ever runs.
|
|
219
|
+
if (isWriterNonceRequired() && args.writer_nonce === undefined) {
|
|
220
|
+
throw writerNonceRequiredError(args.step_id, run.version);
|
|
221
|
+
}
|
|
222
|
+
// issue #197 PR-2 (FLAG_GATING, design §3 activation gate): a nonce is carried ONLY when this
|
|
223
|
+
// store genuinely declares writer_nonce_carriage — a non-declaring store must NEVER receive the
|
|
224
|
+
// nonce argument at all (never merely ignore it silently inside the store call).
|
|
225
|
+
const carriageActive = storeDeclaresNonceCarriage(traceBufferStore);
|
|
226
|
+
const nonceOptions = args.writer_nonce !== undefined && carriageActive
|
|
227
|
+
? { writerNonce: args.writer_nonce }
|
|
228
|
+
: undefined;
|
|
229
|
+
// 6. Empty entries — return current buffer state without writing. Stays on the raw unlocked
|
|
230
|
+
// path UNCONDITIONALLY (issue #207 PR-2, D3 §2) — writes nothing, so there is no settlement
|
|
231
|
+
// race to fence against and no unfenced-store advisory to add here, regardless of what the
|
|
232
|
+
// store declares. The CAPACITY warning (issue #208) still applies: this is the natural
|
|
233
|
+
// read-your-capacity call — an agent probing at 85% full should see it just as a real append
|
|
234
|
+
// would show it. issue #197 PR-2: the probe passes the nonce too (writer-scope numbers for the
|
|
235
|
+
// probing writer specifically, not the whole file).
|
|
72
236
|
if (args.entries.length === 0) {
|
|
73
|
-
const result = await traceBufferStore.append(args.run_id, args.step_id, []);
|
|
74
|
-
return
|
|
237
|
+
const result = await traceBufferStore.append(args.run_id, args.step_id, [], nonceOptions);
|
|
238
|
+
return buildAppendOkResult(result, args.writer_nonce, carriageActive, []);
|
|
75
239
|
}
|
|
76
240
|
// 7. Append entries to the buffer.
|
|
77
|
-
|
|
78
|
-
|
|
241
|
+
if (typeof traceBufferStore.appendFenced === 'function') {
|
|
242
|
+
// Capability present (issue #207 PR-2): guard = ONE fresh lock-free runStore.get,
|
|
243
|
+
// re-verifying the exact same premise the pre-CS check above already established, but at
|
|
244
|
+
// write time — this is what closes append-trace.ts's Window A (D3 problem statement): a
|
|
245
|
+
// concurrent execute_step claiming/settling the step between the pre-CS load and the
|
|
246
|
+
// physical write. The guard performs exactly one store read and nothing else, per the fenced
|
|
247
|
+
// trio's own contract.
|
|
248
|
+
const appendFenced = traceBufferStore.appendFenced.bind(traceBufferStore);
|
|
249
|
+
const guard = async () => {
|
|
250
|
+
let freshRun;
|
|
251
|
+
try {
|
|
252
|
+
freshRun = await runStore.get(args.run_id);
|
|
253
|
+
}
|
|
254
|
+
catch (err) {
|
|
255
|
+
if (err instanceof WorkflowError && err.code === 'STATE_RUN_NOT_FOUND') {
|
|
256
|
+
throw stepNotEligibleError(args.step_id, run.version, 'run_not_found');
|
|
257
|
+
}
|
|
258
|
+
// Any other failure propagates UNWRAPPED, per the fenced trio's own guard contract —
|
|
259
|
+
// never assume every guard failure fits this tool's own eligibility taxonomy.
|
|
260
|
+
throw err;
|
|
261
|
+
}
|
|
262
|
+
if (isTerminalPhase(freshRun.run_phase)) {
|
|
263
|
+
throw stepNotEligibleError(args.step_id, freshRun.version, 'run_terminal', {
|
|
264
|
+
run_phase: freshRun.run_phase,
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
const freshState = stepStateOf(freshRun, args.step_id);
|
|
268
|
+
if (freshState !== undefined) {
|
|
269
|
+
throw stepNotEligibleError(args.step_id, freshRun.version, freshState);
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
const result = await appendFenced(args.run_id, args.step_id, args.entries, guard, nonceOptions);
|
|
273
|
+
return buildAppendOkResult(result, args.writer_nonce, carriageActive, []);
|
|
274
|
+
}
|
|
275
|
+
// Capability absent (issue #207 PR-2): legacy unfenced append() — Window A stays open for this
|
|
276
|
+
// store. Deduped console.warn (once per store constructor name, not once per call) plus an
|
|
277
|
+
// envelope advisory on every success response — advisory only, never gates (#119); this branch
|
|
278
|
+
// is unreachable once the store declares the trio.
|
|
279
|
+
const storeName = traceBufferStore.constructor.name;
|
|
280
|
+
if (!warnedUnfencedStoreNames.has(storeName)) {
|
|
281
|
+
warnedUnfencedStoreNames.add(storeName);
|
|
282
|
+
console.warn(`[append_trace] trace buffer store '${storeName}' does not declare the fenced trio (issue ` +
|
|
283
|
+
'#207) — appended entries are not fenced against a concurrent settlement and may end up ' +
|
|
284
|
+
'neither adopted nor refused. See the response envelope\'s "warnings" field for the ' +
|
|
285
|
+
'same caveat on every affected call.');
|
|
286
|
+
}
|
|
287
|
+
// issue #197 PR-2: an unfenced store can never satisfy the ladder (carriage requires seal
|
|
288
|
+
// requires the fenced trio) — carriageActive is always false on this branch, so nonceOptions is
|
|
289
|
+
// always undefined here and the not-persisted warning fires whenever a nonce was supplied.
|
|
290
|
+
const result = await traceBufferStore.append(args.run_id, args.step_id, args.entries, nonceOptions);
|
|
291
|
+
// issue #208: capacity SECOND, after the pre-existing unfenced-store advisory — both (and the
|
|
292
|
+
// #197 not-persisted caveat) may be present at once; each is an independent fact.
|
|
293
|
+
return buildAppendOkResult(result, args.writer_nonce, carriageActive, [
|
|
294
|
+
'this store does not fence trace appends against concurrent settlement; entries ' +
|
|
295
|
+
'acknowledged here may not be adopted',
|
|
296
|
+
]);
|
|
79
297
|
}
|
|
80
298
|
/** Registers the append_trace MCP tool on the server. */
|
|
81
299
|
export function registerAppendTrace(server, opts) {
|
|
@@ -84,10 +302,20 @@ export function registerAppendTrace(server, opts) {
|
|
|
84
302
|
'Entries are buffered and merged with any entries submitted at execute_step finalization.',
|
|
85
303
|
'Delivery is best-effort: entries are durable after this call returns but are not canonical until execute_step completes.',
|
|
86
304
|
'Only valid for agent steps that have not yet been claimed (before execute_step is called).',
|
|
305
|
+
'Optional: writer_nonce — mint a fresh UUIDv4 per step-attempt (the SAME value on every',
|
|
306
|
+
"append_trace call for this attempt, a NEW one next attempt) to get this attempt's own",
|
|
307
|
+
'lines faithfully attributed instead of the honest-but-unattributed floor. Mint on BOTH',
|
|
308
|
+
'append_trace and execute_step for this attempt, or neither — a guessable or reused nonce',
|
|
309
|
+
'is worse than omitting one (it lets residue be adopted with no caveat, or silently folds a',
|
|
310
|
+
'crashed attempt into this one).',
|
|
87
311
|
].join(' '), {
|
|
88
312
|
run_id: z.string(),
|
|
89
313
|
step_id: z.string(),
|
|
90
314
|
entries: z.array(traceEntrySchema),
|
|
315
|
+
// issue #197 PR-2 (design §6): UNBOUNDED at the zod layer — every shape violation
|
|
316
|
+
// (empty/whitespace/too-long) routes through validateWriterNonceShape to ONE typed realm
|
|
317
|
+
// envelope refusal, never a bare zod/SDK error.
|
|
318
|
+
writer_nonce: z.string().optional(),
|
|
91
319
|
}, async (args) => {
|
|
92
320
|
try {
|
|
93
321
|
const result = await handleAppendTrace(args, opts);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"append-trace.js","sourceRoot":"","sources":["../../src/tools/append-trace.ts"],"names":[],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AAQ,GAAqB,8BAA8B,CAC/D,cAAc,EACd,IAAI,CAAC,MAAM,EACX,UAAU,EACV,WAAW,EACX,WAAW,CACZ,CAAC;YACF,OAAO;gBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,gBAAgB,CAAC,QAAQ,CAAC,EAAE,CAAC;aACvE,CAAC;QACJ,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
-
import { JsonWorkflowStore,
|
|
2
|
+
import { JsonWorkflowStore, type ResponseEnvelope, type RunStore } from '@sensigo/realm';
|
|
3
3
|
import { type HandleRunStores } from './start-run.js';
|
|
4
4
|
export interface CreateWorkflowStep {
|
|
5
5
|
id: string;
|
|
@@ -29,7 +29,7 @@ export interface CreateWorkflowArgs {
|
|
|
29
29
|
*/
|
|
30
30
|
export declare function handleCreateWorkflow(args: CreateWorkflowArgs, stores?: {
|
|
31
31
|
workflowStore?: JsonWorkflowStore;
|
|
32
|
-
runStore?:
|
|
32
|
+
runStore?: RunStore;
|
|
33
33
|
}): Promise<ResponseEnvelope>;
|
|
34
34
|
/** Registers the create_workflow MCP tool on the server. */
|
|
35
35
|
export declare function registerCreateWorkflow(server: McpServer, opts?: HandleRunStores): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-workflow.d.ts","sourceRoot":"","sources":["../../src/tools/create-workflow.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,EACL,iBAAiB,
|
|
1
|
+
{"version":3,"file":"create-workflow.d.ts","sourceRoot":"","sources":["../../src/tools/create-workflow.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,EACL,iBAAiB,EAMjB,KAAK,g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CAAC;YACxF,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACjE,OAAO;gBACL,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,MAAe;wBACrB,IAAI,EAAE,gBAAgB,CAAC;4BACrB,OAAO,EAAE,iBAAiB;4BAC1B,MAAM,EAAE,EAAE;4BACV,MAAM,EAAE,OAAO;4BACf,IAAI,EAAE,EAAE;4BACR,QAAQ,EAAE,EAAE;4BACZ,QAAQ,EAAE,EAAE;4BACZ,MAAM,EAAE,CAAC,OAAO,CAAC;4BACjB,YAAY,EAAE,WAAW;4BACzB,YAAY,EACV,wFAAwF;4BAC1F,YAAY,EAAE,EAAE;yBACjB,CAAC;qBACH;iBACF;aACF,CAAC;QACJ,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,7 +1,25 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
|
-
import { type ResponseEnvelope, type AgentTraceEntry } from '@sensigo/realm';
|
|
3
|
+
import { WorkflowError, type ResponseEnvelope, type AgentTraceEntry } from '@sensigo/realm';
|
|
4
4
|
import type { HandleRunStores } from './start-run.js';
|
|
5
|
+
/** Actionable guidance appended to every writer_nonce-related refusal (issue #197 PR-2). */
|
|
6
|
+
export declare const WRITER_NONCE_GUIDANCE: string;
|
|
7
|
+
/**
|
|
8
|
+
* Validates a caller-submitted `writer_nonce`'s SHAPE (issue #197 PR-2, design §6) — throws a
|
|
9
|
+
* typed `WorkflowError` on any violation, never a bare zod/SDK error (the zod schema itself
|
|
10
|
+
* accepts any string, deliberately UNBOUNDED, so every shape violation routes through this ONE
|
|
11
|
+
* check). Shared by `append_trace` and `execute_step` — the shape rule lives in exactly one
|
|
12
|
+
* place; each tool's OWN refusal taxonomy is otherwise free to differ.
|
|
13
|
+
*/
|
|
14
|
+
export declare function validateWriterNonceShape(nonce: string): void;
|
|
15
|
+
/**
|
|
16
|
+
* Dormant strict posture (issue #197 PR-2, design §6 — the #169→#170 template): read PER CALL,
|
|
17
|
+
* NEVER cached at module load (a test flips the env var mid-process). "on" = set to any
|
|
18
|
+
* non-empty value other than `'0'`/`'false'`. Default (unset) ⇒ zero behavior change anywhere.
|
|
19
|
+
*/
|
|
20
|
+
export declare function isWriterNonceRequired(): boolean;
|
|
21
|
+
/** Refusal for `isWriterNonceRequired()` ⇒ true and a bare (agent-step) call (issue #197 PR-2). */
|
|
22
|
+
export declare function writerNonceRequiredError(stepId: string, runVersion: number): WorkflowError;
|
|
5
23
|
/** Zod schema for a single agent trace entry submitted to execute_step or append_trace. */
|
|
6
24
|
export declare const traceEntrySchema: z.ZodObject<{
|
|
7
25
|
event: z.ZodString;
|
|
@@ -25,6 +43,7 @@ export declare function handleExecuteStep(args: {
|
|
|
25
43
|
command: string;
|
|
26
44
|
params?: Record<string, unknown>;
|
|
27
45
|
trace?: AgentTraceEntry[] | undefined;
|
|
46
|
+
writer_nonce?: string | undefined;
|
|
28
47
|
}, stores?: HandleRunStores): Promise<ResponseEnvelope>;
|
|
29
48
|
/**
|
|
30
49
|
* MCP-layer wrapper around handleExecuteStep.
|
|
@@ -36,6 +55,7 @@ export declare function handleExecuteStepTool(args: {
|
|
|
36
55
|
command: string;
|
|
37
56
|
params?: Record<string, unknown>;
|
|
38
57
|
trace?: AgentTraceEntry[] | undefined;
|
|
58
|
+
writer_nonce?: string | undefined;
|
|
39
59
|
}, stores?: HandleRunStores): Promise<{
|
|
40
60
|
content: Array<{
|
|
41
61
|
type: 'text';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execute-step.d.ts","sourceRoot":"","sources":["../../src/tools/execute-step.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,SAAS,EAAE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AAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,KAAK,CAAC,EAAE,eAAe,EAAE,GAAG,SAAS,CAAC;IACtC,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACnC,EACD,MAAM,CAAC,EAAE,eAAe,GACvB,OAAO,CAAC;IAAE,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,CAAC,CA2C7D;AAED,yDAAyD;AACzD,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,eAAe,GAAG,IAAI,CA0BnF"}
|
|
@@ -2,6 +2,58 @@
|
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { JsonWorkflowStore, JsonFileStore, executeChain, WorkflowError, buildPreExecutionErrorEnvelope, buildFailedAttemptRecord, serializeFailedAttemptLine, } from '@sensigo/realm';
|
|
4
4
|
import { sseJsonStringify } from '../sse-json.js';
|
|
5
|
+
/** Maximum `writer_nonce` length (issue #197 PR-2, design §6). */
|
|
6
|
+
const WRITER_NONCE_MAX_LENGTH = 128;
|
|
7
|
+
/** Actionable guidance appended to every writer_nonce-related refusal (issue #197 PR-2). */
|
|
8
|
+
export const WRITER_NONCE_GUIDANCE = 'writer_nonce must be a non-empty string, ≤128 chars, no leading/trailing whitespace; ' +
|
|
9
|
+
'recommended: a fresh UUIDv4 per step-attempt.';
|
|
10
|
+
/**
|
|
11
|
+
* Validates a caller-submitted `writer_nonce`'s SHAPE (issue #197 PR-2, design §6) — throws a
|
|
12
|
+
* typed `WorkflowError` on any violation, never a bare zod/SDK error (the zod schema itself
|
|
13
|
+
* accepts any string, deliberately UNBOUNDED, so every shape violation routes through this ONE
|
|
14
|
+
* check). Shared by `append_trace` and `execute_step` — the shape rule lives in exactly one
|
|
15
|
+
* place; each tool's OWN refusal taxonomy is otherwise free to differ.
|
|
16
|
+
*/
|
|
17
|
+
export function validateWriterNonceShape(nonce) {
|
|
18
|
+
let reason;
|
|
19
|
+
if (nonce.length === 0) {
|
|
20
|
+
reason = 'must not be empty';
|
|
21
|
+
}
|
|
22
|
+
else if (nonce !== nonce.trim()) {
|
|
23
|
+
reason = 'must not have leading or trailing whitespace';
|
|
24
|
+
}
|
|
25
|
+
else if (nonce.length > WRITER_NONCE_MAX_LENGTH) {
|
|
26
|
+
reason = `must be ≤${WRITER_NONCE_MAX_LENGTH} characters`;
|
|
27
|
+
}
|
|
28
|
+
if (reason === undefined)
|
|
29
|
+
return;
|
|
30
|
+
throw new WorkflowError(`Invalid writer_nonce: ${reason}. ${WRITER_NONCE_GUIDANCE}`, {
|
|
31
|
+
code: 'VALIDATION_EMPTY_VALUE',
|
|
32
|
+
category: 'VALIDATION',
|
|
33
|
+
agentAction: 'provide_input',
|
|
34
|
+
retryable: false,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Dormant strict posture (issue #197 PR-2, design §6 — the #169→#170 template): read PER CALL,
|
|
39
|
+
* NEVER cached at module load (a test flips the env var mid-process). "on" = set to any
|
|
40
|
+
* non-empty value other than `'0'`/`'false'`. Default (unset) ⇒ zero behavior change anywhere.
|
|
41
|
+
*/
|
|
42
|
+
export function isWriterNonceRequired() {
|
|
43
|
+
const v = process.env['REALM_REQUIRE_WRITER_NONCE'];
|
|
44
|
+
return v !== undefined && v !== '' && v !== '0' && v !== 'false';
|
|
45
|
+
}
|
|
46
|
+
/** Refusal for `isWriterNonceRequired()` ⇒ true and a bare (agent-step) call (issue #197 PR-2). */
|
|
47
|
+
export function writerNonceRequiredError(stepId, runVersion) {
|
|
48
|
+
return new WorkflowError('This deployment requires writer_nonce for agent steps (REALM_REQUIRE_WRITER_NONCE is set) ' +
|
|
49
|
+
`— step '${stepId}' was called without one. ${WRITER_NONCE_GUIDANCE}`, {
|
|
50
|
+
code: 'VALIDATION_EMPTY_VALUE',
|
|
51
|
+
category: 'VALIDATION',
|
|
52
|
+
agentAction: 'provide_input',
|
|
53
|
+
retryable: false,
|
|
54
|
+
details: { step_id: stepId, run_version: runVersion },
|
|
55
|
+
});
|
|
56
|
+
}
|
|
5
57
|
/**
|
|
6
58
|
* Pre-claim validation rejections carry one of these error codes (claimStep runs strictly after all
|
|
7
59
|
* three schema gates, so they never reach failed_steps[] / never bump version — a write-free path).
|
|
@@ -85,6 +137,34 @@ export async function handleExecuteStep(args, stores) {
|
|
|
85
137
|
const run = await runStore.get(args.run_id);
|
|
86
138
|
const definition = await workflowStore.get(run.workflow_id);
|
|
87
139
|
const params = args.params ?? {};
|
|
140
|
+
const stepDef = definition.steps[args.command];
|
|
141
|
+
// issue #197 PR-2 (design §6): shape-validate BEFORE anything else — routes every violation
|
|
142
|
+
// through ONE typed refusal, never a bare zod/SDK error.
|
|
143
|
+
if (args.writer_nonce !== undefined) {
|
|
144
|
+
validateWriterNonceShape(args.writer_nonce);
|
|
145
|
+
}
|
|
146
|
+
// A writer_nonce PRESENT on a non-agent step is refused (design §6) — mirrors append_trace's
|
|
147
|
+
// own non-agent taxonomy (STATE_STEP_NOT_ELIGIBLE + step_type detail). A BARE execute_step call
|
|
148
|
+
// on a non-agent step stays byte-identical — auto/handler steps legally execute through this
|
|
149
|
+
// tool, and this check only fires when a nonce was actually supplied.
|
|
150
|
+
if (args.writer_nonce !== undefined && stepDef !== undefined && stepDef.execution !== 'agent') {
|
|
151
|
+
throw new WorkflowError(`Step '${args.command}' is not an agent step (execution: '${stepDef.execution}') — ` +
|
|
152
|
+
'writer_nonce is only meaningful on agent steps.', {
|
|
153
|
+
code: 'STATE_STEP_NOT_ELIGIBLE',
|
|
154
|
+
category: 'STATE',
|
|
155
|
+
agentAction: 'report_to_user',
|
|
156
|
+
retryable: false,
|
|
157
|
+
details: { step_id: args.command, step_type: stepDef.execution, run_version: run.version },
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
// issue #197 PR-2 (design §6, dormant strict posture — default off, zero behavior change):
|
|
161
|
+
// agent steps only — an auto/handler step's execute_step call never carries a caller-chosen
|
|
162
|
+
// writer_nonce in the first place.
|
|
163
|
+
if (isWriterNonceRequired() &&
|
|
164
|
+
stepDef?.execution === 'agent' &&
|
|
165
|
+
args.writer_nonce === undefined) {
|
|
166
|
+
throw writerNonceRequiredError(args.command, run.version);
|
|
167
|
+
}
|
|
88
168
|
// Per-definition registry (project extensions) — awaited before execution; a throwing
|
|
89
169
|
// provider fails the tool call before any step is claimed. Provider wins over `registry`.
|
|
90
170
|
const registry = stores?.registryProvider !== undefined
|
|
@@ -102,6 +182,7 @@ export async function handleExecuteStep(args, stores) {
|
|
|
102
182
|
...(stores?.traceBufferStore !== undefined
|
|
103
183
|
? { traceBufferStore: stores.traceBufferStore }
|
|
104
184
|
: {}),
|
|
185
|
+
...(args.writer_nonce !== undefined ? { writerNonce: args.writer_nonce } : {}),
|
|
105
186
|
});
|
|
106
187
|
// P2/P3 observability: on a pre-claim validation rejection, fan a metadata-only record out to the
|
|
107
188
|
// ephemeral stderr line (P2) and the durable per-run sidecar (P3, when wired). Reads the pre-strip
|
|
@@ -153,11 +234,23 @@ export async function handleExecuteStepTool(args, stores) {
|
|
|
153
234
|
}
|
|
154
235
|
/** Registers the execute_step MCP tool on the server. */
|
|
155
236
|
export function registerExecuteStep(server, opts) {
|
|
156
|
-
server.tool('execute_step',
|
|
237
|
+
server.tool('execute_step', [
|
|
238
|
+
'Execute a workflow step. For agent steps, pass your output in params.',
|
|
239
|
+
'Optional: writer_nonce — mint a fresh UUIDv4 per step-attempt (same value on every',
|
|
240
|
+
"append_trace call for this attempt, a NEW one next attempt) to get this step's own",
|
|
241
|
+
'buffered trace lines faithfully attributed instead of the honest-but-unattributed floor.',
|
|
242
|
+
'Mint on BOTH append_trace and execute_step for this attempt, or neither — a guessable or',
|
|
243
|
+
'reused nonce is worse than omitting one (it lets residue be adopted with no caveat, or',
|
|
244
|
+
'silently folds a crashed attempt into this one).',
|
|
245
|
+
].join(' '), {
|
|
157
246
|
run_id: z.string(),
|
|
158
247
|
command: z.string(),
|
|
159
248
|
params: z.record(z.unknown()).optional().default({}),
|
|
160
249
|
trace: z.array(traceEntrySchema).optional(),
|
|
250
|
+
// issue #197 PR-2 (design §6): UNBOUNDED at the zod layer — every shape violation
|
|
251
|
+
// (empty/whitespace/too-long) routes through validateWriterNonceShape to ONE typed realm
|
|
252
|
+
// envelope refusal, never a bare zod/SDK error.
|
|
253
|
+
writer_nonce: z.string().optional(),
|
|
161
254
|
}, async (args) => {
|
|
162
255
|
return handleExecuteStepTool(args, opts);
|
|
163
256
|
});
|