agentfootprint 9.75.0 → 9.76.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.
Files changed (118) hide show
  1. package/CHANGELOG.md +94 -0
  2. package/CLAUDE.md +22 -18
  3. package/dist/artifacts/index.js +3 -1
  4. package/dist/artifacts/index.js.map +1 -1
  5. package/dist/artifacts/recordingArtifact.js +47 -1
  6. package/dist/artifacts/recordingArtifact.js.map +1 -1
  7. package/dist/core/Agent.js +30 -0
  8. package/dist/core/Agent.js.map +1 -1
  9. package/dist/core/agent/stages/toolCalls.js +42 -0
  10. package/dist/core/agent/stages/toolCalls.js.map +1 -1
  11. package/dist/core/agent/toolDispatch.js +101 -0
  12. package/dist/core/agent/toolDispatch.js.map +1 -0
  13. package/dist/core/flowchartAsTool.js +9 -2
  14. package/dist/core/flowchartAsTool.js.map +1 -1
  15. package/dist/core/runbook/coverage.js +162 -0
  16. package/dist/core/runbook/coverage.js.map +1 -0
  17. package/dist/core/runbook/dispatch.js +119 -0
  18. package/dist/core/runbook/dispatch.js.map +1 -0
  19. package/dist/core/runbook/index.js +24 -0
  20. package/dist/core/runbook/index.js.map +1 -0
  21. package/dist/core/runbook/report.js +69 -0
  22. package/dist/core/runbook/report.js.map +1 -0
  23. package/dist/core/runbook/runbookAsTool.js +381 -0
  24. package/dist/core/runbook/runbookAsTool.js.map +1 -0
  25. package/dist/core/runbook/types.js +22 -0
  26. package/dist/core/runbook/types.js.map +1 -0
  27. package/dist/core/runbook/verdicts.js +156 -0
  28. package/dist/core/runbook/verdicts.js.map +1 -0
  29. package/dist/core/runbook/walk.js +115 -0
  30. package/dist/core/runbook/walk.js.map +1 -0
  31. package/dist/core/tools.js +55 -1
  32. package/dist/core/tools.js.map +1 -1
  33. package/dist/esm/artifacts/index.d.ts +1 -1
  34. package/dist/esm/artifacts/index.js +1 -1
  35. package/dist/esm/artifacts/index.js.map +1 -1
  36. package/dist/esm/artifacts/recordingArtifact.d.ts +36 -0
  37. package/dist/esm/artifacts/recordingArtifact.js +45 -0
  38. package/dist/esm/artifacts/recordingArtifact.js.map +1 -1
  39. package/dist/esm/core/Agent.js +30 -0
  40. package/dist/esm/core/Agent.js.map +1 -1
  41. package/dist/esm/core/agent/stages/toolCalls.js +42 -0
  42. package/dist/esm/core/agent/stages/toolCalls.js.map +1 -1
  43. package/dist/esm/core/agent/toolDispatch.d.ts +50 -0
  44. package/dist/esm/core/agent/toolDispatch.js +97 -0
  45. package/dist/esm/core/agent/toolDispatch.js.map +1 -0
  46. package/dist/esm/core/flowchartAsTool.d.ts +6 -0
  47. package/dist/esm/core/flowchartAsTool.js +9 -2
  48. package/dist/esm/core/flowchartAsTool.js.map +1 -1
  49. package/dist/esm/core/runbook/coverage.d.ts +69 -0
  50. package/dist/esm/core/runbook/coverage.js +155 -0
  51. package/dist/esm/core/runbook/coverage.js.map +1 -0
  52. package/dist/esm/core/runbook/dispatch.d.ts +69 -0
  53. package/dist/esm/core/runbook/dispatch.js +112 -0
  54. package/dist/esm/core/runbook/dispatch.js.map +1 -0
  55. package/dist/esm/core/runbook/index.d.ts +9 -0
  56. package/dist/esm/core/runbook/index.js +9 -0
  57. package/dist/esm/core/runbook/index.js.map +1 -0
  58. package/dist/esm/core/runbook/report.d.ts +52 -0
  59. package/dist/esm/core/runbook/report.js +64 -0
  60. package/dist/esm/core/runbook/report.js.map +1 -0
  61. package/dist/esm/core/runbook/runbookAsTool.d.ts +90 -0
  62. package/dist/esm/core/runbook/runbookAsTool.js +377 -0
  63. package/dist/esm/core/runbook/runbookAsTool.js.map +1 -0
  64. package/dist/esm/core/runbook/types.d.ts +203 -0
  65. package/dist/esm/core/runbook/types.js +21 -0
  66. package/dist/esm/core/runbook/types.js.map +1 -0
  67. package/dist/esm/core/runbook/verdicts.d.ts +78 -0
  68. package/dist/esm/core/runbook/verdicts.js +148 -0
  69. package/dist/esm/core/runbook/verdicts.js.map +1 -0
  70. package/dist/esm/core/runbook/walk.d.ts +72 -0
  71. package/dist/esm/core/runbook/walk.js +110 -0
  72. package/dist/esm/core/runbook/walk.js.map +1 -0
  73. package/dist/esm/core/tools.d.ts +112 -0
  74. package/dist/esm/core/tools.js +52 -0
  75. package/dist/esm/core/tools.js.map +1 -1
  76. package/dist/esm/index.d.ts +4 -3
  77. package/dist/esm/index.js +19 -2
  78. package/dist/esm/index.js.map +1 -1
  79. package/dist/esm/lib/mcp/toolExtras.d.ts +8 -0
  80. package/dist/esm/lib/mcp/toolExtras.js +7 -1
  81. package/dist/esm/lib/mcp/toolExtras.js.map +1 -1
  82. package/dist/index.js +97 -66
  83. package/dist/index.js.map +1 -1
  84. package/dist/lib/mcp/toolExtras.js +6 -0
  85. package/dist/lib/mcp/toolExtras.js.map +1 -1
  86. package/dist/types/artifacts/index.d.ts +1 -1
  87. package/dist/types/artifacts/index.d.ts.map +1 -1
  88. package/dist/types/artifacts/recordingArtifact.d.ts +36 -0
  89. package/dist/types/artifacts/recordingArtifact.d.ts.map +1 -1
  90. package/dist/types/core/Agent.d.ts.map +1 -1
  91. package/dist/types/core/agent/stages/toolCalls.d.ts.map +1 -1
  92. package/dist/types/core/agent/toolDispatch.d.ts +51 -0
  93. package/dist/types/core/agent/toolDispatch.d.ts.map +1 -0
  94. package/dist/types/core/flowchartAsTool.d.ts +6 -0
  95. package/dist/types/core/flowchartAsTool.d.ts.map +1 -1
  96. package/dist/types/core/runbook/coverage.d.ts +70 -0
  97. package/dist/types/core/runbook/coverage.d.ts.map +1 -0
  98. package/dist/types/core/runbook/dispatch.d.ts +70 -0
  99. package/dist/types/core/runbook/dispatch.d.ts.map +1 -0
  100. package/dist/types/core/runbook/index.d.ts +10 -0
  101. package/dist/types/core/runbook/index.d.ts.map +1 -0
  102. package/dist/types/core/runbook/report.d.ts +53 -0
  103. package/dist/types/core/runbook/report.d.ts.map +1 -0
  104. package/dist/types/core/runbook/runbookAsTool.d.ts +91 -0
  105. package/dist/types/core/runbook/runbookAsTool.d.ts.map +1 -0
  106. package/dist/types/core/runbook/types.d.ts +204 -0
  107. package/dist/types/core/runbook/types.d.ts.map +1 -0
  108. package/dist/types/core/runbook/verdicts.d.ts +79 -0
  109. package/dist/types/core/runbook/verdicts.d.ts.map +1 -0
  110. package/dist/types/core/runbook/walk.d.ts +73 -0
  111. package/dist/types/core/runbook/walk.d.ts.map +1 -0
  112. package/dist/types/core/tools.d.ts +112 -0
  113. package/dist/types/core/tools.d.ts.map +1 -1
  114. package/dist/types/index.d.ts +4 -3
  115. package/dist/types/index.d.ts.map +1 -1
  116. package/dist/types/lib/mcp/toolExtras.d.ts +8 -0
  117. package/dist/types/lib/mcp/toolExtras.d.ts.map +1 -1
  118. package/package.json +1 -1
@@ -0,0 +1,381 @@
1
+ "use strict";
2
+ /**
3
+ * runbookAsTool — turn a written operational procedure into a tool whose
4
+ * every answer is EVIDENCE: who decided what, against which threshold, on
5
+ * which rule version, with the recorded walk to check it against.
6
+ *
7
+ * The standard bridge from a footprintjs chart to the Agent's tool surface.
8
+ * Where `flowchartAsTool` returns bare `JSON.stringify(values)`,
9
+ * runbookAsTool supplies the missing middle — the honesty envelope every
10
+ * hand-rolled triage tool was building for itself:
11
+ *
12
+ * THE MANDATORY SPINE (every runbook, whatever its shape):
13
+ * - `af_coverage` — the three-list ledger, with every INNER tool's own
14
+ * ledger folded upward through the run's dispatch, plus the sentence
15
+ * naming the rule set and version;
16
+ * - `result.af_provenance` — re-emitted FIRST (a carried `LOCAL SEED`
17
+ * confession survives composition);
18
+ * - `result.rule_version` — the declared rules' version, or the honest
19
+ * `'undeclared'`;
20
+ * - `result.walk` — the recorded walk's descriptor. The walk itself
21
+ * ships as an artifact ticket (kind `recording/chart-walk`), never as
22
+ * bytes; when it does not fit, the CONTROL FLOW survives and the
23
+ * projection is declared.
24
+ *
25
+ * THE OPTIONAL PROJECTION (selected by `resultKind: 'verdict/*'`):
26
+ * verdict rows off the chart's `verdicts` state key, capped with
27
+ * truthful counters, a pre-rendered table over the SAME rows, and
28
+ * `verdict_meanings` GENERATED from the decider's declared branches +
29
+ * the rule labels this run's decide() evidence carried.
30
+ *
31
+ * THREE OUTCOMES, honestly: a clean envelope; an inner ABSENCE passed
32
+ * through verbatim (the framework still reads it as an absence); and
33
+ * DECLINED rows counted into the ledger as not-checked ground.
34
+ *
35
+ * The procedure is a FACTORY invoked per call with the run's own tool
36
+ * dispatch (`ctx.tools`) — fresh chart every run, stages close over the
37
+ * dispatch, and every inner tool's honesty ledger folds into this tool's
38
+ * answer.
39
+ *
40
+ * Reserved state keys the bridge reads off the final scope:
41
+ * - `verdicts` — the rowset (verdict projection only);
42
+ * - `coverage` — chart-declared coverage entries (`{checked?, not_checked?,
43
+ * cannot_cover?}`);
44
+ * - `report` — the app's own result fields, spread into `result` verbatim
45
+ * BESIDE the spine, never over it: the envelope's own names (the spine
46
+ * plus the projection this run assembled) are reserved, and a report
47
+ * field spelling one of them is discarded and NAMED in `report_note`.
48
+ *
49
+ * Pause: NOT yet bridged. A paused inner chart throws with the checkpoint
50
+ * attached, exactly like `flowchartAsTool` — the approval-gate integration
51
+ * is the next phase of the runbook program.
52
+ *
53
+ * @example the smallest legal call — still yields the honest spine
54
+ * const tool = runbookAsTool({
55
+ * name: 'restart_check',
56
+ * description: 'Run the restart-safety procedure.',
57
+ * procedure: () =>
58
+ * flowChart<{ safe: boolean }>('restart-safety', (scope) => {
59
+ * scope.safe = true;
60
+ * }, 'check').build(),
61
+ * });
62
+ *
63
+ * @example a triage runbook with rules, verdicts, and an inner tool
64
+ * const triage = runbookAsTool({
65
+ * name: 'backup_triage',
66
+ * description: 'Assess backup protection posture for every subject.',
67
+ * resultKind: 'verdict/backup-posture',
68
+ * rules: { name: 'health-signal', version: 'v1' },
69
+ * verdicts: { decider: 'posture' },
70
+ * composedOf: ['backup_inventory'],
71
+ * procedure: (tools) =>
72
+ * flowChart<TriageState>('backup-triage', async (scope) => {
73
+ * const inner = (await tools.call('backup_inventory', {})) as InventoryResult;
74
+ * scope.subjects = inner.result.rows;
75
+ * }, 'inventory')
76
+ * .addDeciderFunction('Posture', postureDecider, 'posture')
77
+ * .addFunctionBranch('protected', 'Protected', landProtected)
78
+ * .addFunctionBranch('unprotected', 'Unprotected', landUnprotected)
79
+ * .end()
80
+ * .build(),
81
+ * });
82
+ */
83
+ Object.defineProperty(exports, "__esModule", { value: true });
84
+ exports.runbookAsTool = void 0;
85
+ const footprintjs_1 = require("footprintjs");
86
+ const trace_1 = require("footprintjs/trace");
87
+ const innerRunRecords_js_1 = require("../../lib/trace-toolpack/innerRunRecords.js");
88
+ const tools_js_1 = require("../tools.js");
89
+ const coverage_js_1 = require("./coverage.js");
90
+ const dispatch_js_1 = require("./dispatch.js");
91
+ const report_js_1 = require("./report.js");
92
+ const verdicts_js_1 = require("./verdicts.js");
93
+ const walk_js_1 = require("./walk.js");
94
+ /** The projection selector: a `resultKind` in the `verdict/` namespace gets
95
+ * the rowset projection; every other kind ships the spine plus the chart's
96
+ * own `report`. */
97
+ const VERDICT_KIND_PREFIX = 'verdict/';
98
+ function bagOf(value) {
99
+ return value !== null && typeof value === 'object' && !Array.isArray(value)
100
+ ? value
101
+ : undefined;
102
+ }
103
+ /** Lift the chart's declared input schema when it is a PLAIN JSON-Schema
104
+ * object. A parseable schema (`.safeParse`/`.parse` — zod et al.) validates
105
+ * at the executor but cannot be serialized for the model: skipped, default
106
+ * applies. */
107
+ function liftInputSchema(chart) {
108
+ const schema = bagOf(chart.inputSchema);
109
+ if (schema === undefined)
110
+ return undefined;
111
+ const parseable = typeof schema.safeParse === 'function' ||
112
+ typeof schema.parse === 'function';
113
+ return parseable ? undefined : schema;
114
+ }
115
+ /**
116
+ * Wrap a footprintjs procedure as a `Tool` whose every answer carries the
117
+ * honesty spine. See the module header for the envelope; see
118
+ * {@link RunbookAsToolOptions} for the full options bag. The smallest legal
119
+ * call is `{ name, description, procedure }`.
120
+ */
121
+ function runbookAsTool(opts) {
122
+ const label = `runbookAsTool(${opts.name || '?'})`;
123
+ if (!opts.name || opts.name.trim().length === 0) {
124
+ throw new Error('runbookAsTool: `name` is required and must be non-empty.');
125
+ }
126
+ if (!opts.description || opts.description.length === 0) {
127
+ throw new Error(`${label}: \`description\` is required — a description-less tool is invisible to the model.`);
128
+ }
129
+ if (typeof opts.procedure !== 'function') {
130
+ throw new Error(`${label}: \`procedure\` is required — a factory invoked per call with the run's ` +
131
+ `tool dispatch, returning a built chart. (Migrating from flowchartAsTool? Wrap ` +
132
+ `your chart: \`procedure: () => chart\` builds it fresh each run.)`);
133
+ }
134
+ if (opts.rules !== undefined) {
135
+ const { name, version } = opts.rules;
136
+ if (typeof name !== 'string' ||
137
+ name.trim() === '' ||
138
+ typeof version !== 'string' ||
139
+ version.trim() === '') {
140
+ throw new Error(`${label}: \`rules\` must carry a non-empty name and version — it is the provenance ` +
141
+ `stamp every evidence sentence names. Got ${JSON.stringify(opts.rules)}.`);
142
+ }
143
+ }
144
+ if (opts.verdicts !== undefined) {
145
+ if (typeof opts.verdicts.decider !== 'string' || opts.verdicts.decider.trim() === '') {
146
+ throw new Error(`${label}: \`verdicts.decider\` must name the decider stage whose branches generate ` +
147
+ `verdict_meanings. Got ${JSON.stringify(opts.verdicts.decider)}.`);
148
+ }
149
+ const maxRows = opts.verdicts.maxRows;
150
+ if (maxRows !== undefined && (!Number.isInteger(maxRows) || maxRows < 1)) {
151
+ throw new Error(`${label}: \`verdicts.maxRows\` must be a whole number of rows, at least 1 — got ` +
152
+ `${String(maxRows)}.`);
153
+ }
154
+ }
155
+ const cap = opts.walk?.cap;
156
+ if (cap !== undefined && (!Number.isInteger(cap) || cap < 1)) {
157
+ throw new Error(`${label}: \`walk.cap\` must be a whole number of rows, at least 1 — got ${String(cap)}.`);
158
+ }
159
+ if (opts.keepRecordLimit !== undefined) {
160
+ if (opts.keepRecord !== true) {
161
+ throw new Error(`${label}: \`keepRecordLimit\` caps records that are never kept — add ` +
162
+ `\`keepRecord: true\`, or drop the limit.`);
163
+ }
164
+ if (!Number.isInteger(opts.keepRecordLimit) || opts.keepRecordLimit < 1) {
165
+ throw new Error(`${label}: \`keepRecordLimit\` must be a whole number of invocations, at least 1 — ` +
166
+ `got ${String(opts.keepRecordLimit)}.`);
167
+ }
168
+ }
169
+ // ── Definition-time probe: read the chart's declared contract ─────────
170
+ let probeChart;
171
+ try {
172
+ probeChart = opts.procedure((0, dispatch_js_1.probeDispatch)(opts.name));
173
+ }
174
+ catch (err) {
175
+ throw new Error(`${label}: the procedure factory threw at the definition probe — ` +
176
+ `${err instanceof Error ? err.message : String(err)}. The factory is invoked once ` +
177
+ `at definition (stage bodies do not run) to read the chart's declared contract; ` +
178
+ `it must be side-effect-free at build.`);
179
+ }
180
+ if (probeChart === null ||
181
+ typeof probeChart !== 'object' ||
182
+ typeof probeChart.stageMap !== 'object') {
183
+ throw new Error(`${label}: \`procedure\` must return a BUILT chart (call .build() on the builder).`);
184
+ }
185
+ const inputSchema = opts.inputSchema ?? liftInputSchema(probeChart);
186
+ const isVerdictKind = opts.resultKind?.startsWith(VERDICT_KIND_PREFIX) === true;
187
+ const maxRows = opts.verdicts?.maxRows ?? verdicts_js_1.DEFAULT_MAX_ROWS;
188
+ const walkCap = opts.walk?.cap ?? walk_js_1.DEFAULT_WALK_CAP;
189
+ const store = opts.keepRecord === true
190
+ ? (0, innerRunRecords_js_1.innerRunStore)(opts.keepRecordLimit ?? innerRunRecords_js_1.DEFAULT_INNER_RUN_LIMIT)
191
+ : undefined;
192
+ const tool = (0, tools_js_1.defineTool)({
193
+ name: opts.name,
194
+ description: opts.description,
195
+ ...(inputSchema !== undefined && { inputSchema }),
196
+ // GAP-8 closed: the rail-read declarations forward verbatim.
197
+ ...(opts.resultKind !== undefined && { resultKind: opts.resultKind }),
198
+ ...(opts.resultClass !== undefined && { resultClass: opts.resultClass }),
199
+ ...(opts.owner !== undefined && { owner: opts.owner }),
200
+ ...(opts.resultCeiling !== undefined && { resultCeiling: opts.resultCeiling }),
201
+ ...(opts.wants !== undefined && { wants: opts.wants }),
202
+ ...(opts.argumentsFrom !== undefined && { argumentsFrom: opts.argumentsFrom }),
203
+ ...(opts.composedOf !== undefined && { composedOf: opts.composedOf }),
204
+ execute: async (args, ctx) => {
205
+ const dispatch = (0, dispatch_js_1.recordingDispatch)(ctx.tools, opts.name);
206
+ const chart = opts.procedure(dispatch.tools);
207
+ const executor = new footprintjs_1.FlowChartExecutor(chart);
208
+ if (opts.redact)
209
+ executor.setRedactionPolicy(opts.redact);
210
+ for (const recorder of opts.recorders ?? []) {
211
+ executor.attachCombinedRecorder(recorder);
212
+ }
213
+ // Values off: the walk is about the DECISIONS — a per-key value dump
214
+ // would bury six branch choices under four hundred reads.
215
+ const walkRecorder = (0, footprintjs_1.narrative)({ includeValues: false });
216
+ executor.attachCombinedRecorder(walkRecorder);
217
+ // Meanings harvest — resolve the decider on THIS run's chart (a fresh
218
+ // chart per call; the static branches are the same, the resolution is
219
+ // cheap) and collect rule labels as the evidence fires.
220
+ const identity = opts.verdicts !== undefined ? (0, verdicts_js_1.resolveDecider)(chart, opts.verdicts.decider) : undefined;
221
+ const harvest = identity !== undefined ? (0, verdicts_js_1.meaningsRecorder)(identity) : undefined;
222
+ if (harvest !== undefined)
223
+ executor.attachCombinedRecorder(harvest.recorder);
224
+ const ctrl = store ? (0, trace_1.controlDepRecorder)() : undefined;
225
+ if (ctrl)
226
+ executor.attachCombinedRecorder(ctrl);
227
+ const keepRecordOf = (outcome, known) => {
228
+ if (!store)
229
+ return;
230
+ try {
231
+ const snapshot = known ?? executor.getSnapshot();
232
+ const commitLog = snapshot.commitLog;
233
+ const lines = walkRecorder.getEntries()
234
+ .map((entry) => entry.text)
235
+ .filter((text) => typeof text === 'string' && text.length > 0);
236
+ store.keep({
237
+ toolCallId: ctx.toolCallId,
238
+ toolName: opts.name,
239
+ outcome,
240
+ steps: Array.isArray(commitLog) ? commitLog.length : 0,
241
+ recording: {
242
+ snapshot,
243
+ structure: chart.buildTimeStructure,
244
+ },
245
+ ...(ctrl !== undefined && { controlDeps: ctrl.asLookup() }),
246
+ ...(lines.length > 0 && { narrative: lines }),
247
+ });
248
+ }
249
+ catch (e) {
250
+ store.keep({
251
+ toolCallId: ctx.toolCallId,
252
+ toolName: opts.name,
253
+ outcome,
254
+ steps: 0,
255
+ problem: e instanceof Error ? e.message : String(e),
256
+ });
257
+ }
258
+ };
259
+ const env = {};
260
+ if (ctx.signal)
261
+ env.signal = ctx.signal;
262
+ try {
263
+ await executor.run({ input: args, env });
264
+ }
265
+ catch (e) {
266
+ const signal = (0, dispatch_js_1.absenceSignalOf)(e);
267
+ if (signal !== undefined) {
268
+ // ABSENCE PASS-THROUGH: the inner source answered "I looked and
269
+ // there is nothing", and the runbook has nothing to add. It goes
270
+ // back EXACTLY as it arrived so the framework still reads it as an
271
+ // absence. The kept record files as 'error' — the closed outcome
272
+ // word nearest "the traversal ended on a thrown signal".
273
+ keepRecordOf('error');
274
+ return signal.absence;
275
+ }
276
+ keepRecordOf('error');
277
+ throw e;
278
+ }
279
+ if (executor.isPaused()) {
280
+ keepRecordOf('paused');
281
+ const err = new Error(`${label}: the inner chart paused. Approval-gate integration (typed resume ` +
282
+ `through agent.resume) is the runbook program's next phase; until it lands a ` +
283
+ `paused procedure cannot be resumed through the tool boundary. The checkpoint ` +
284
+ `is on err.checkpoint.`);
285
+ err.checkpoint = executor.getCheckpoint();
286
+ throw err;
287
+ }
288
+ const raw = executor.getSnapshot();
289
+ keepRecordOf('ok', raw);
290
+ const state = raw.sharedState ??
291
+ raw.values ??
292
+ {};
293
+ // ── The walk ────────────────────────────────────────────────────────
294
+ const entries = walkRecorder.getEntries();
295
+ const projected = (0, walk_js_1.projectWalk)(entries, walkCap);
296
+ const walk = await (0, walk_js_1.mintWalk)(ctx, projected, {
297
+ toolName: opts.name,
298
+ toolCallId: ctx.toolCallId,
299
+ ...(ctx.runId !== undefined && { runId: ctx.runId }),
300
+ stepsExecuted: walkRecorder.stepCount,
301
+ });
302
+ // ── The projection (verdict kinds only) ─────────────────────────────
303
+ let rows;
304
+ let shown;
305
+ let declined;
306
+ if (isVerdictKind) {
307
+ rows = (0, verdicts_js_1.verdictRowsOf)(state);
308
+ shown = rows.slice(0, maxRows);
309
+ declined = rows.filter((row) => row.verdict === verdicts_js_1.DECLINED_VERDICT).length;
310
+ }
311
+ const meanings = identity !== undefined && harvest !== undefined
312
+ ? (0, verdicts_js_1.composeMeanings)(identity, harvest.observed)
313
+ : undefined;
314
+ // ── The ledger ──────────────────────────────────────────────────────
315
+ // The procedure's display name: the chart's own root name (what the
316
+ // author called it) — the tool name is the fallback, never the
317
+ // auto-generated multi-line description.
318
+ const chartName = chart.buildTimeStructure?.name ?? opts.name;
319
+ const ledger = (0, coverage_js_1.composeLedger)((0, coverage_js_1.foldInnerCoverage)(dispatch.records), (0, coverage_js_1.chartCoverageOf)(state), {
320
+ chartName,
321
+ stepsExecuted: walkRecorder.stepCount,
322
+ ...(opts.rules !== undefined && { rules: opts.rules }),
323
+ ...(rows !== undefined && { rowsTotal: rows.length }),
324
+ ...(declined !== undefined && { declinedRows: declined }),
325
+ });
326
+ // ── Provenance — re-emitted FIRST ───────────────────────────────────
327
+ const af_provenance = {
328
+ ...(0, coverage_js_1.carriedProvenanceOf)(dispatch.records),
329
+ tool: opts.name,
330
+ toolCallId: ctx.toolCallId,
331
+ };
332
+ // ── The envelope ────────────────────────────────────────────────────
333
+ // The spine and the projection are assembled FIRST, and the chart's
334
+ // `report` is admitted against the names they took: spine keys win, as
335
+ // the contract says, by explicit precedence rather than by spread order
336
+ // (which had the report land on top of `af_provenance` and
337
+ // `rule_version`). A refused field is named in `report_note` — see
338
+ // report.ts for the law and why the refusal is spoken.
339
+ const spine = {
340
+ af_provenance,
341
+ rule_version: opts.rules?.version ?? 'undeclared',
342
+ walk,
343
+ };
344
+ const projection = shown !== undefined && rows !== undefined
345
+ ? {
346
+ verdicts: shown,
347
+ rows_shown: shown.length,
348
+ rows_total: rows.length,
349
+ rows_complete: shown.length === rows.length,
350
+ table: (0, verdicts_js_1.renderVerdictTable)(shown),
351
+ render_note: verdicts_js_1.VERDICT_RENDER_NOTE,
352
+ ...(meanings !== undefined && { verdict_meanings: meanings }),
353
+ }
354
+ : undefined;
355
+ const report = (0, report_js_1.admitReport)(bagOf(state.report) ?? {}, [
356
+ ...Object.keys(spine),
357
+ ...Object.keys(projection ?? {}),
358
+ ]);
359
+ const envelope = {
360
+ af_coverage: ledger,
361
+ result: {
362
+ af_provenance: spine.af_provenance,
363
+ rule_version: spine.rule_version,
364
+ ...report.fields,
365
+ ...(projection ?? {}),
366
+ ...(report.refused.length > 0 && {
367
+ [report_js_1.REPORT_NOTE_KEY]: (0, report_js_1.shadowedFieldsNote)(report.refused),
368
+ }),
369
+ walk: spine.walk,
370
+ },
371
+ };
372
+ return envelope;
373
+ },
374
+ });
375
+ if (store === undefined)
376
+ return tool;
377
+ const keepsRecords = { ...tool, [innerRunRecords_js_1.INNER_RUN_RECORDS]: store };
378
+ return keepsRecords;
379
+ }
380
+ exports.runbookAsTool = runbookAsTool;
381
+ //# sourceMappingURL=runbookAsTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runbookAsTool.js","sourceRoot":"","sources":["../../../src/core/runbook/runbookAsTool.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgFG;;;AAEH,6CAAkF;AAClF,6CAAuD;AAEvD,oFAOqD;AACrD,0CAA+E;AAC/E,+CAKuB;AACvB,+CAAkF;AAClF,2CAA+E;AAE/E,+CASuB;AACvB,uCAA6F;AAE7F;;oBAEoB;AACpB,MAAM,mBAAmB,GAAG,UAAU,CAAC;AAEvC,SAAS,KAAK,CAAC,KAAc;IAC3B,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACzE,CAAC,CAAE,KAAiC;QACpC,CAAC,CAAC,S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CAAC,QAAQ,KAAK,SAAS,IAAI,EAAE,gBAAgB,EAAE,QAAQ,EAAE,CAAC;iBAC9D;gBACH,CAAC,CAAC,SAAS,CAAC;YAChB,MAAM,MAAM,GAAG,IAAA,uBAAW,EAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE;gBACpD,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;gBACrB,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,IAAI,EAAE,CAAC;aACjC,CAAC,CAAC;YACH,MAAM,QAAQ,GAAoB;gBAChC,WAAW,EAAE,MAAM;gBACnB,MAAM,EAAE;oBACN,aAAa,EAAE,KAAK,CAAC,aAAa;oBAClC,YAAY,EAAE,KAAK,CAAC,YAAY;oBAChC,GAAG,MAAM,CAAC,MAAM;oBAChB,GAAG,CAAC,UAAU,IAAI,EAAE,CAAC;oBACrB,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI;wBAC/B,CAAC,2BAAe,CAAC,EAAE,IAAA,8BAAkB,EAAC,MAAM,CAAC,OAAO,CAAC;qBACtD,CAAC;oBACF,IAAI,EAAE,KAAK,CAAC,IAAI;iBACjB;aACF,CAAC;YACF,OAAO,QAAQ,CAAC;QAClB,CAAC;KACF,CAAC,CAAC;IAEH,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IACrC,MAAM,YAAY,GAA0B,EAAE,GAAG,IAAI,EAAE,CAAC,sCAAiB,CAAC,EAAE,KAAK,EAAE,CAAC;IACpF,OAAO,YAAY,CAAC;AACtB,CAAC;AAtSD,sCAsSC"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ /**
3
+ * runbook/types — the vocabulary of the runbook bridge.
4
+ *
5
+ * Pattern: one options bag, four concerns (declarations, procedure, evidence
6
+ * policy, walk policy) + one envelope type split into a MANDATORY
7
+ * SPINE and an OPTIONAL projection. Pure data, no behavior.
8
+ * Role: core/ layer. `runbookAsTool.ts` consumes; consumers read the
9
+ * envelope types when they assert on results.
10
+ * Emits: N/A.
11
+ *
12
+ * The SPINE / PROJECTION split is load-bearing honesty, not taste: the spine
13
+ * (coverage, provenance, rule version, the recorded walk) is what EVERY
14
+ * runbook ships whatever its shape, so an answer can never arrive without its
15
+ * boundary; the verdict/rowset projection is one shape of answer (a triage),
16
+ * selected by `resultKind: 'verdict/*'` — an action-taking runbook ships the
17
+ * spine plus its own `report` payload and no rowset. The spine's wire shape
18
+ * is explicitly PROVISIONAL until a second, differently-shaped consumer has
19
+ * shipped through it.
20
+ */
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/runbook/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;GAkBG"}
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ /**
3
+ * runbook/verdicts — the OPTIONAL verdict/rowset projection.
4
+ *
5
+ * Pattern: pure selection + rendering over the run's final state, plus one
6
+ * tiny recorder that harvests decide() evidence for generated
7
+ * meanings. Selected by `resultKind: 'verdict/*'`; a runbook of any
8
+ * other kind never sees this module.
9
+ * Role: core/runbook.
10
+ * Emits: N/A.
11
+ *
12
+ * THE ONE-NUMBER LAW: the rendered table and the structured `verdicts` list
13
+ * show the SAME rows under the SAME cap. A rendered table beside a longer
14
+ * structured list is an invitation that gets accepted — rows come back
15
+ * retyped with subtly wrong identifiers.
16
+ *
17
+ * GENERATED MEANINGS, never hand-restated: `verdict_meanings` is composed
18
+ * from (a) the named decider's declared branches in the chart's own structure
19
+ * (branch description, falling back to branch name), overlaid by (b) the rule
20
+ * LABELS this run's decide() evidence carried — the rule speaking for itself.
21
+ * A decider inside a dynamically generated fan-out branch is invisible to (a)
22
+ * by construction (the branch chart does not exist at build time); (b) still
23
+ * covers every verdict an executed rule produced.
24
+ */
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.composeMeanings = exports.meaningsRecorder = exports.resolveDecider = exports.renderVerdictTable = exports.verdictRowsOf = exports.DECLINED_VERDICT = exports.VERDICT_RENDER_NOTE = exports.DEFAULT_MAX_ROWS = void 0;
27
+ /** Default cap on `verdicts` rows and the rendered table. */
28
+ exports.DEFAULT_MAX_ROWS = 50;
29
+ /** The render law, stated to the model beside every table. */
30
+ exports.VERDICT_RENDER_NOTE = 'table is PRE-RENDERED over the same rows as `verdicts` — output it VERBATIM. Never ' +
31
+ 'retype an identifier from `verdicts`; a transcribed name that looks right and matches ' +
32
+ 'nothing is the failure this note exists to stop.';
33
+ /** The reserved verdict word for "no classification was reached" — rows
34
+ * carrying it are counted into the coverage ledger as not-checked ground
35
+ * (the three-outcome honesty: reached, reached-and-clear, DECLINED). */
36
+ exports.DECLINED_VERDICT = 'declined';
37
+ /** Read the rowset off the final state's `verdicts` key — an array of bags
38
+ * each carrying a string `verdict`. Anything else reads as "no rowset". */
39
+ function verdictRowsOf(state) {
40
+ const raw = state.verdicts;
41
+ if (!Array.isArray(raw))
42
+ return [];
43
+ return raw.filter((row) => row !== null &&
44
+ typeof row === 'object' &&
45
+ !Array.isArray(row) &&
46
+ typeof row.verdict === 'string');
47
+ }
48
+ exports.verdictRowsOf = verdictRowsOf;
49
+ /** The one place a `—` is written for a value the source did not report — a
50
+ * blank cell reads as a zero; a dash reads as "not reported". */
51
+ function cell(value) {
52
+ if (value === null || value === undefined || value === '')
53
+ return '—';
54
+ if (value === true)
55
+ return 'yes';
56
+ if (value === false)
57
+ return 'no';
58
+ return String(value).replace(/\|/g, '\\|').replace(/\n/g, ' ');
59
+ }
60
+ /**
61
+ * Render the shown rows as one markdown table. Columns are the FIRST row's
62
+ * own keys in declaration order — the chart writes its rows, so the chart
63
+ * owns the column vocabulary; the bridge only renders it.
64
+ */
65
+ function renderVerdictTable(rows) {
66
+ if (rows.length === 0)
67
+ return 'No rows in the projected set.';
68
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
69
+ const columns = Object.keys(rows[0]);
70
+ const head = `| ${columns.join(' | ')} |\n|${columns.map(() => '---').join('|')}|\n`;
71
+ return (head +
72
+ rows.map((row) => `| ${columns.map((column) => cell(row[column])).join(' | ')} |`).join('\n'));
73
+ }
74
+ exports.renderVerdictTable = renderVerdictTable;
75
+ /**
76
+ * Find the named decider in the chart's static structure (root graph plus
77
+ * statically declared subflows) and read its branches. Loop-ref stubs are
78
+ * skipped FIRST — they deliberately violate node-id uniqueness.
79
+ */
80
+ function resolveDecider(chart, decider) {
81
+ const spellings = new Set([decider]);
82
+ const declared = new Map();
83
+ const visited = new Set();
84
+ const walk = (node) => {
85
+ if (node === undefined || node.isLoopRef === true || visited.has(node))
86
+ return;
87
+ visited.add(node);
88
+ if ((node.id === decider || node.name === decider) && (node.children?.length ?? 0) > 0) {
89
+ if (node.id !== undefined)
90
+ spellings.add(node.id);
91
+ if (node.name !== undefined)
92
+ spellings.add(node.name);
93
+ for (const child of node.children ?? []) {
94
+ const branch = child.branchId ?? child.id;
95
+ if (branch === undefined)
96
+ continue;
97
+ const meaning = child.description ?? child.name;
98
+ if (meaning !== undefined && !declared.has(branch))
99
+ declared.set(branch, meaning);
100
+ }
101
+ }
102
+ for (const child of node.children ?? [])
103
+ walk(child);
104
+ walk(node.next);
105
+ };
106
+ walk(chart.root);
107
+ for (const subflow of Object.values(chart.subflows ?? {})) {
108
+ walk(subflow.root);
109
+ }
110
+ return { spellings, declared };
111
+ }
112
+ exports.resolveDecider = resolveDecider;
113
+ /**
114
+ * A tiny flow recorder capturing the named decider's decide() evidence as it
115
+ * fires — collected DURING the traversal, never reconstructed after. Rule
116
+ * labels are harvested for every rule the evidence lists (matched or not):
117
+ * a rule that was evaluated has spoken its label, whichever branch won.
118
+ *
119
+ * A decider inside a subflow (including a generated fan-out branch) reports
120
+ * itself PATH-PREFIXED (`per-subject~0/Protection posture`), so the match is
121
+ * on the LAST `/`-segment — the same last-delimiter reading every upstream
122
+ * parser of these paths uses, which is what keeps the generated-branch
123
+ * marker opaque here.
124
+ */
125
+ function meaningsRecorder(identity) {
126
+ const observed = new Map();
127
+ const lastSegment = (path) => path.slice(path.lastIndexOf('/') + 1);
128
+ const recorder = {
129
+ id: 'runbook-verdict-meanings',
130
+ onDecision(event) {
131
+ if (!identity.spellings.has(lastSegment(event.decider)))
132
+ return;
133
+ const evidence = event.evidence;
134
+ for (const rule of evidence?.rules ?? []) {
135
+ if (typeof rule.branch === 'string' && typeof rule.label === 'string') {
136
+ observed.set(rule.branch, rule.label);
137
+ }
138
+ }
139
+ },
140
+ };
141
+ return { recorder, observed };
142
+ }
143
+ exports.meaningsRecorder = meaningsRecorder;
144
+ /** Compose the final meanings: declared branches first, observed rule labels
145
+ * winning where both speak (the rule is the sharper sentence). Undefined
146
+ * when neither source produced anything — absent, never `{}`. */
147
+ function composeMeanings(identity, observed) {
148
+ const meanings = {};
149
+ for (const [branch, meaning] of identity.declared)
150
+ meanings[branch] = meaning;
151
+ for (const [branch, label] of observed)
152
+ meanings[branch] = label;
153
+ return Object.keys(meanings).length > 0 ? meanings : undefined;
154
+ }
155
+ exports.composeMeanings = composeMeanings;
156
+ //# sourceMappingURL=verdicts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verdicts.js","sourceRoot":"","sources":["../../../src/core/runbook/verdicts.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;AAMH,6DAA6D;AAChD,QAAA,gBAAgB,GAAG,EAAE,CAAC;AAEnC,8DAA8D;AACjD,QAAA,mBAAmB,GAC9B,qFAAqF;IACrF,wFAAwF;IACxF,kDAAkD,CAAC;AAErD;;yEAEyE;AAC5D,QAAA,gBAAgB,GAAG,UAAU,CAAC;AAE3C;4EAC4E;AAC5E,SAAgB,aAAa,CAAC,KAAwC;IACpE,MAAM,GAAG,GAAG,KAAK,CAAC,QAAQ,CAAC;IAC3B,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;QAA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