agentfootprint 9.75.0 → 9.76.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/CHANGELOG.md +64 -0
- package/CLAUDE.md +22 -18
- package/dist/artifacts/index.js +3 -1
- package/dist/artifacts/index.js.map +1 -1
- package/dist/artifacts/recordingArtifact.js +47 -1
- package/dist/artifacts/recordingArtifact.js.map +1 -1
- package/dist/core/Agent.js +30 -0
- package/dist/core/Agent.js.map +1 -1
- package/dist/core/agent/stages/toolCalls.js +42 -0
- package/dist/core/agent/stages/toolCalls.js.map +1 -1
- package/dist/core/agent/toolDispatch.js +101 -0
- package/dist/core/agent/toolDispatch.js.map +1 -0
- package/dist/core/flowchartAsTool.js +9 -2
- package/dist/core/flowchartAsTool.js.map +1 -1
- package/dist/core/runbook/coverage.js +162 -0
- package/dist/core/runbook/coverage.js.map +1 -0
- package/dist/core/runbook/dispatch.js +119 -0
- package/dist/core/runbook/dispatch.js.map +1 -0
- package/dist/core/runbook/index.js +24 -0
- package/dist/core/runbook/index.js.map +1 -0
- package/dist/core/runbook/runbookAsTool.js +358 -0
- package/dist/core/runbook/runbookAsTool.js.map +1 -0
- package/dist/core/runbook/types.js +22 -0
- package/dist/core/runbook/types.js.map +1 -0
- package/dist/core/runbook/verdicts.js +156 -0
- package/dist/core/runbook/verdicts.js.map +1 -0
- package/dist/core/runbook/walk.js +115 -0
- package/dist/core/runbook/walk.js.map +1 -0
- package/dist/core/tools.js +55 -1
- package/dist/core/tools.js.map +1 -1
- package/dist/esm/artifacts/index.d.ts +1 -1
- package/dist/esm/artifacts/index.js +1 -1
- package/dist/esm/artifacts/index.js.map +1 -1
- package/dist/esm/artifacts/recordingArtifact.d.ts +36 -0
- package/dist/esm/artifacts/recordingArtifact.js +45 -0
- package/dist/esm/artifacts/recordingArtifact.js.map +1 -1
- package/dist/esm/core/Agent.js +30 -0
- package/dist/esm/core/Agent.js.map +1 -1
- package/dist/esm/core/agent/stages/toolCalls.js +42 -0
- package/dist/esm/core/agent/stages/toolCalls.js.map +1 -1
- package/dist/esm/core/agent/toolDispatch.d.ts +50 -0
- package/dist/esm/core/agent/toolDispatch.js +97 -0
- package/dist/esm/core/agent/toolDispatch.js.map +1 -0
- package/dist/esm/core/flowchartAsTool.d.ts +6 -0
- package/dist/esm/core/flowchartAsTool.js +9 -2
- package/dist/esm/core/flowchartAsTool.js.map +1 -1
- package/dist/esm/core/runbook/coverage.d.ts +69 -0
- package/dist/esm/core/runbook/coverage.js +155 -0
- package/dist/esm/core/runbook/coverage.js.map +1 -0
- package/dist/esm/core/runbook/dispatch.d.ts +69 -0
- package/dist/esm/core/runbook/dispatch.js +112 -0
- package/dist/esm/core/runbook/dispatch.js.map +1 -0
- package/dist/esm/core/runbook/index.d.ts +9 -0
- package/dist/esm/core/runbook/index.js +9 -0
- package/dist/esm/core/runbook/index.js.map +1 -0
- package/dist/esm/core/runbook/runbookAsTool.d.ts +88 -0
- package/dist/esm/core/runbook/runbookAsTool.js +354 -0
- package/dist/esm/core/runbook/runbookAsTool.js.map +1 -0
- package/dist/esm/core/runbook/types.d.ts +196 -0
- package/dist/esm/core/runbook/types.js +21 -0
- package/dist/esm/core/runbook/types.js.map +1 -0
- package/dist/esm/core/runbook/verdicts.d.ts +78 -0
- package/dist/esm/core/runbook/verdicts.js +148 -0
- package/dist/esm/core/runbook/verdicts.js.map +1 -0
- package/dist/esm/core/runbook/walk.d.ts +72 -0
- package/dist/esm/core/runbook/walk.js +110 -0
- package/dist/esm/core/runbook/walk.js.map +1 -0
- package/dist/esm/core/tools.d.ts +112 -0
- package/dist/esm/core/tools.js +52 -0
- package/dist/esm/core/tools.js.map +1 -1
- package/dist/esm/index.d.ts +4 -3
- package/dist/esm/index.js +19 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/mcp/toolExtras.d.ts +8 -0
- package/dist/esm/lib/mcp/toolExtras.js +7 -1
- package/dist/esm/lib/mcp/toolExtras.js.map +1 -1
- package/dist/index.js +97 -66
- package/dist/index.js.map +1 -1
- package/dist/lib/mcp/toolExtras.js +6 -0
- package/dist/lib/mcp/toolExtras.js.map +1 -1
- package/dist/types/artifacts/index.d.ts +1 -1
- package/dist/types/artifacts/index.d.ts.map +1 -1
- package/dist/types/artifacts/recordingArtifact.d.ts +36 -0
- package/dist/types/artifacts/recordingArtifact.d.ts.map +1 -1
- package/dist/types/core/Agent.d.ts.map +1 -1
- package/dist/types/core/agent/stages/toolCalls.d.ts.map +1 -1
- package/dist/types/core/agent/toolDispatch.d.ts +51 -0
- package/dist/types/core/agent/toolDispatch.d.ts.map +1 -0
- package/dist/types/core/flowchartAsTool.d.ts +6 -0
- package/dist/types/core/flowchartAsTool.d.ts.map +1 -1
- package/dist/types/core/runbook/coverage.d.ts +70 -0
- package/dist/types/core/runbook/coverage.d.ts.map +1 -0
- package/dist/types/core/runbook/dispatch.d.ts +70 -0
- package/dist/types/core/runbook/dispatch.d.ts.map +1 -0
- package/dist/types/core/runbook/index.d.ts +10 -0
- package/dist/types/core/runbook/index.d.ts.map +1 -0
- package/dist/types/core/runbook/runbookAsTool.d.ts +89 -0
- package/dist/types/core/runbook/runbookAsTool.d.ts.map +1 -0
- package/dist/types/core/runbook/types.d.ts +197 -0
- package/dist/types/core/runbook/types.d.ts.map +1 -0
- package/dist/types/core/runbook/verdicts.d.ts +79 -0
- package/dist/types/core/runbook/verdicts.d.ts.map +1 -0
- package/dist/types/core/runbook/walk.d.ts +73 -0
- package/dist/types/core/runbook/walk.d.ts.map +1 -0
- package/dist/types/core/tools.d.ts +112 -0
- package/dist/types/core/tools.d.ts.map +1 -1
- package/dist/types/index.d.ts +4 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lib/mcp/toolExtras.d.ts +8 -0
- package/dist/types/lib/mcp/toolExtras.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* runbookAsTool — turn a written operational procedure into a tool whose
|
|
3
|
+
* every answer is EVIDENCE: who decided what, against which threshold, on
|
|
4
|
+
* which rule version, with the recorded walk to check it against.
|
|
5
|
+
*
|
|
6
|
+
* The standard bridge from a footprintjs chart to the Agent's tool surface.
|
|
7
|
+
* Where `flowchartAsTool` returns bare `JSON.stringify(values)`,
|
|
8
|
+
* runbookAsTool supplies the missing middle — the honesty envelope every
|
|
9
|
+
* hand-rolled triage tool was building for itself:
|
|
10
|
+
*
|
|
11
|
+
* THE MANDATORY SPINE (every runbook, whatever its shape):
|
|
12
|
+
* - `af_coverage` — the three-list ledger, with every INNER tool's own
|
|
13
|
+
* ledger folded upward through the run's dispatch, plus the sentence
|
|
14
|
+
* naming the rule set and version;
|
|
15
|
+
* - `result.af_provenance` — re-emitted FIRST (a carried `LOCAL SEED`
|
|
16
|
+
* confession survives composition);
|
|
17
|
+
* - `result.rule_version` — the declared rules' version, or the honest
|
|
18
|
+
* `'undeclared'`;
|
|
19
|
+
* - `result.walk` — the recorded walk's descriptor. The walk itself
|
|
20
|
+
* ships as an artifact ticket (kind `recording/chart-walk`), never as
|
|
21
|
+
* bytes; when it does not fit, the CONTROL FLOW survives and the
|
|
22
|
+
* projection is declared.
|
|
23
|
+
*
|
|
24
|
+
* THE OPTIONAL PROJECTION (selected by `resultKind: 'verdict/*'`):
|
|
25
|
+
* verdict rows off the chart's `verdicts` state key, capped with
|
|
26
|
+
* truthful counters, a pre-rendered table over the SAME rows, and
|
|
27
|
+
* `verdict_meanings` GENERATED from the decider's declared branches +
|
|
28
|
+
* the rule labels this run's decide() evidence carried.
|
|
29
|
+
*
|
|
30
|
+
* THREE OUTCOMES, honestly: a clean envelope; an inner ABSENCE passed
|
|
31
|
+
* through verbatim (the framework still reads it as an absence); and
|
|
32
|
+
* DECLINED rows counted into the ledger as not-checked ground.
|
|
33
|
+
*
|
|
34
|
+
* The procedure is a FACTORY invoked per call with the run's own tool
|
|
35
|
+
* dispatch (`ctx.tools`) — fresh chart every run, stages close over the
|
|
36
|
+
* dispatch, and every inner tool's honesty ledger folds into this tool's
|
|
37
|
+
* answer.
|
|
38
|
+
*
|
|
39
|
+
* Reserved state keys the bridge reads off the final scope:
|
|
40
|
+
* - `verdicts` — the rowset (verdict projection only);
|
|
41
|
+
* - `coverage` — chart-declared coverage entries (`{checked?, not_checked?,
|
|
42
|
+
* cannot_cover?}`);
|
|
43
|
+
* - `report` — the app's own result fields, spread into `result` verbatim
|
|
44
|
+
* (spine keys win).
|
|
45
|
+
*
|
|
46
|
+
* Pause: NOT yet bridged. A paused inner chart throws with the checkpoint
|
|
47
|
+
* attached, exactly like `flowchartAsTool` — the approval-gate integration
|
|
48
|
+
* is the next phase of the runbook program.
|
|
49
|
+
*
|
|
50
|
+
* @example the smallest legal call — still yields the honest spine
|
|
51
|
+
* const tool = runbookAsTool({
|
|
52
|
+
* name: 'restart_check',
|
|
53
|
+
* description: 'Run the restart-safety procedure.',
|
|
54
|
+
* procedure: () =>
|
|
55
|
+
* flowChart<{ safe: boolean }>('restart-safety', (scope) => {
|
|
56
|
+
* scope.safe = true;
|
|
57
|
+
* }, 'check').build(),
|
|
58
|
+
* });
|
|
59
|
+
*
|
|
60
|
+
* @example a triage runbook with rules, verdicts, and an inner tool
|
|
61
|
+
* const triage = runbookAsTool({
|
|
62
|
+
* name: 'backup_triage',
|
|
63
|
+
* description: 'Assess backup protection posture for every subject.',
|
|
64
|
+
* resultKind: 'verdict/backup-posture',
|
|
65
|
+
* rules: { name: 'health-signal', version: 'v1' },
|
|
66
|
+
* verdicts: { decider: 'posture' },
|
|
67
|
+
* composedOf: ['backup_inventory'],
|
|
68
|
+
* procedure: (tools) =>
|
|
69
|
+
* flowChart<TriageState>('backup-triage', async (scope) => {
|
|
70
|
+
* const inner = (await tools.call('backup_inventory', {})) as InventoryResult;
|
|
71
|
+
* scope.subjects = inner.result.rows;
|
|
72
|
+
* }, 'inventory')
|
|
73
|
+
* .addDeciderFunction('Posture', postureDecider, 'posture')
|
|
74
|
+
* .addFunctionBranch('protected', 'Protected', landProtected)
|
|
75
|
+
* .addFunctionBranch('unprotected', 'Unprotected', landUnprotected)
|
|
76
|
+
* .end()
|
|
77
|
+
* .build(),
|
|
78
|
+
* });
|
|
79
|
+
*/
|
|
80
|
+
import { FlowChartExecutor, narrative } from 'footprintjs';
|
|
81
|
+
import { controlDepRecorder } from 'footprintjs/trace';
|
|
82
|
+
import { DEFAULT_INNER_RUN_LIMIT, INNER_RUN_RECORDS, innerRunStore, } from '../../lib/trace-toolpack/innerRunRecords.js';
|
|
83
|
+
import { defineTool } from '../tools.js';
|
|
84
|
+
import { carriedProvenanceOf, chartCoverageOf, composeLedger, foldInnerCoverage, } from './coverage.js';
|
|
85
|
+
import { absenceSignalOf, probeDispatch, recordingDispatch } from './dispatch.js';
|
|
86
|
+
import { composeMeanings, DECLINED_VERDICT, DEFAULT_MAX_ROWS, meaningsRecorder, renderVerdictTable, resolveDecider, VERDICT_RENDER_NOTE, verdictRowsOf, } from './verdicts.js';
|
|
87
|
+
import { DEFAULT_WALK_CAP, mintWalk, projectWalk } from './walk.js';
|
|
88
|
+
/** The projection selector: a `resultKind` in the `verdict/` namespace gets
|
|
89
|
+
* the rowset projection; every other kind ships the spine plus the chart's
|
|
90
|
+
* own `report`. */
|
|
91
|
+
const VERDICT_KIND_PREFIX = 'verdict/';
|
|
92
|
+
function bagOf(value) {
|
|
93
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
94
|
+
? value
|
|
95
|
+
: undefined;
|
|
96
|
+
}
|
|
97
|
+
/** Lift the chart's declared input schema when it is a PLAIN JSON-Schema
|
|
98
|
+
* object. A parseable schema (`.safeParse`/`.parse` — zod et al.) validates
|
|
99
|
+
* at the executor but cannot be serialized for the model: skipped, default
|
|
100
|
+
* applies. */
|
|
101
|
+
function liftInputSchema(chart) {
|
|
102
|
+
const schema = bagOf(chart.inputSchema);
|
|
103
|
+
if (schema === undefined)
|
|
104
|
+
return undefined;
|
|
105
|
+
const parseable = typeof schema.safeParse === 'function' ||
|
|
106
|
+
typeof schema.parse === 'function';
|
|
107
|
+
return parseable ? undefined : schema;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Wrap a footprintjs procedure as a `Tool` whose every answer carries the
|
|
111
|
+
* honesty spine. See the module header for the envelope; see
|
|
112
|
+
* {@link RunbookAsToolOptions} for the full options bag. The smallest legal
|
|
113
|
+
* call is `{ name, description, procedure }`.
|
|
114
|
+
*/
|
|
115
|
+
export function runbookAsTool(opts) {
|
|
116
|
+
const label = `runbookAsTool(${opts.name || '?'})`;
|
|
117
|
+
if (!opts.name || opts.name.trim().length === 0) {
|
|
118
|
+
throw new Error('runbookAsTool: `name` is required and must be non-empty.');
|
|
119
|
+
}
|
|
120
|
+
if (!opts.description || opts.description.length === 0) {
|
|
121
|
+
throw new Error(`${label}: \`description\` is required — a description-less tool is invisible to the model.`);
|
|
122
|
+
}
|
|
123
|
+
if (typeof opts.procedure !== 'function') {
|
|
124
|
+
throw new Error(`${label}: \`procedure\` is required — a factory invoked per call with the run's ` +
|
|
125
|
+
`tool dispatch, returning a built chart. (Migrating from flowchartAsTool? Wrap ` +
|
|
126
|
+
`your chart: \`procedure: () => chart\` builds it fresh each run.)`);
|
|
127
|
+
}
|
|
128
|
+
if (opts.rules !== undefined) {
|
|
129
|
+
const { name, version } = opts.rules;
|
|
130
|
+
if (typeof name !== 'string' ||
|
|
131
|
+
name.trim() === '' ||
|
|
132
|
+
typeof version !== 'string' ||
|
|
133
|
+
version.trim() === '') {
|
|
134
|
+
throw new Error(`${label}: \`rules\` must carry a non-empty name and version — it is the provenance ` +
|
|
135
|
+
`stamp every evidence sentence names. Got ${JSON.stringify(opts.rules)}.`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (opts.verdicts !== undefined) {
|
|
139
|
+
if (typeof opts.verdicts.decider !== 'string' || opts.verdicts.decider.trim() === '') {
|
|
140
|
+
throw new Error(`${label}: \`verdicts.decider\` must name the decider stage whose branches generate ` +
|
|
141
|
+
`verdict_meanings. Got ${JSON.stringify(opts.verdicts.decider)}.`);
|
|
142
|
+
}
|
|
143
|
+
const maxRows = opts.verdicts.maxRows;
|
|
144
|
+
if (maxRows !== undefined && (!Number.isInteger(maxRows) || maxRows < 1)) {
|
|
145
|
+
throw new Error(`${label}: \`verdicts.maxRows\` must be a whole number of rows, at least 1 — got ` +
|
|
146
|
+
`${String(maxRows)}.`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
const cap = opts.walk?.cap;
|
|
150
|
+
if (cap !== undefined && (!Number.isInteger(cap) || cap < 1)) {
|
|
151
|
+
throw new Error(`${label}: \`walk.cap\` must be a whole number of rows, at least 1 — got ${String(cap)}.`);
|
|
152
|
+
}
|
|
153
|
+
if (opts.keepRecordLimit !== undefined) {
|
|
154
|
+
if (opts.keepRecord !== true) {
|
|
155
|
+
throw new Error(`${label}: \`keepRecordLimit\` caps records that are never kept — add ` +
|
|
156
|
+
`\`keepRecord: true\`, or drop the limit.`);
|
|
157
|
+
}
|
|
158
|
+
if (!Number.isInteger(opts.keepRecordLimit) || opts.keepRecordLimit < 1) {
|
|
159
|
+
throw new Error(`${label}: \`keepRecordLimit\` must be a whole number of invocations, at least 1 — ` +
|
|
160
|
+
`got ${String(opts.keepRecordLimit)}.`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
// ── Definition-time probe: read the chart's declared contract ─────────
|
|
164
|
+
let probeChart;
|
|
165
|
+
try {
|
|
166
|
+
probeChart = opts.procedure(probeDispatch(opts.name));
|
|
167
|
+
}
|
|
168
|
+
catch (err) {
|
|
169
|
+
throw new Error(`${label}: the procedure factory threw at the definition probe — ` +
|
|
170
|
+
`${err instanceof Error ? err.message : String(err)}. The factory is invoked once ` +
|
|
171
|
+
`at definition (stage bodies do not run) to read the chart's declared contract; ` +
|
|
172
|
+
`it must be side-effect-free at build.`);
|
|
173
|
+
}
|
|
174
|
+
if (probeChart === null ||
|
|
175
|
+
typeof probeChart !== 'object' ||
|
|
176
|
+
typeof probeChart.stageMap !== 'object') {
|
|
177
|
+
throw new Error(`${label}: \`procedure\` must return a BUILT chart (call .build() on the builder).`);
|
|
178
|
+
}
|
|
179
|
+
const inputSchema = opts.inputSchema ?? liftInputSchema(probeChart);
|
|
180
|
+
const isVerdictKind = opts.resultKind?.startsWith(VERDICT_KIND_PREFIX) === true;
|
|
181
|
+
const maxRows = opts.verdicts?.maxRows ?? DEFAULT_MAX_ROWS;
|
|
182
|
+
const walkCap = opts.walk?.cap ?? DEFAULT_WALK_CAP;
|
|
183
|
+
const store = opts.keepRecord === true
|
|
184
|
+
? innerRunStore(opts.keepRecordLimit ?? DEFAULT_INNER_RUN_LIMIT)
|
|
185
|
+
: undefined;
|
|
186
|
+
const tool = defineTool({
|
|
187
|
+
name: opts.name,
|
|
188
|
+
description: opts.description,
|
|
189
|
+
...(inputSchema !== undefined && { inputSchema }),
|
|
190
|
+
// GAP-8 closed: the rail-read declarations forward verbatim.
|
|
191
|
+
...(opts.resultKind !== undefined && { resultKind: opts.resultKind }),
|
|
192
|
+
...(opts.resultClass !== undefined && { resultClass: opts.resultClass }),
|
|
193
|
+
...(opts.owner !== undefined && { owner: opts.owner }),
|
|
194
|
+
...(opts.resultCeiling !== undefined && { resultCeiling: opts.resultCeiling }),
|
|
195
|
+
...(opts.wants !== undefined && { wants: opts.wants }),
|
|
196
|
+
...(opts.argumentsFrom !== undefined && { argumentsFrom: opts.argumentsFrom }),
|
|
197
|
+
...(opts.composedOf !== undefined && { composedOf: opts.composedOf }),
|
|
198
|
+
execute: async (args, ctx) => {
|
|
199
|
+
const dispatch = recordingDispatch(ctx.tools, opts.name);
|
|
200
|
+
const chart = opts.procedure(dispatch.tools);
|
|
201
|
+
const executor = new FlowChartExecutor(chart);
|
|
202
|
+
if (opts.redact)
|
|
203
|
+
executor.setRedactionPolicy(opts.redact);
|
|
204
|
+
for (const recorder of opts.recorders ?? []) {
|
|
205
|
+
executor.attachCombinedRecorder(recorder);
|
|
206
|
+
}
|
|
207
|
+
// Values off: the walk is about the DECISIONS — a per-key value dump
|
|
208
|
+
// would bury six branch choices under four hundred reads.
|
|
209
|
+
const walkRecorder = narrative({ includeValues: false });
|
|
210
|
+
executor.attachCombinedRecorder(walkRecorder);
|
|
211
|
+
// Meanings harvest — resolve the decider on THIS run's chart (a fresh
|
|
212
|
+
// chart per call; the static branches are the same, the resolution is
|
|
213
|
+
// cheap) and collect rule labels as the evidence fires.
|
|
214
|
+
const identity = opts.verdicts !== undefined ? resolveDecider(chart, opts.verdicts.decider) : undefined;
|
|
215
|
+
const harvest = identity !== undefined ? meaningsRecorder(identity) : undefined;
|
|
216
|
+
if (harvest !== undefined)
|
|
217
|
+
executor.attachCombinedRecorder(harvest.recorder);
|
|
218
|
+
const ctrl = store ? controlDepRecorder() : undefined;
|
|
219
|
+
if (ctrl)
|
|
220
|
+
executor.attachCombinedRecorder(ctrl);
|
|
221
|
+
const keepRecordOf = (outcome, known) => {
|
|
222
|
+
if (!store)
|
|
223
|
+
return;
|
|
224
|
+
try {
|
|
225
|
+
const snapshot = known ?? executor.getSnapshot();
|
|
226
|
+
const commitLog = snapshot.commitLog;
|
|
227
|
+
const lines = walkRecorder.getEntries()
|
|
228
|
+
.map((entry) => entry.text)
|
|
229
|
+
.filter((text) => typeof text === 'string' && text.length > 0);
|
|
230
|
+
store.keep({
|
|
231
|
+
toolCallId: ctx.toolCallId,
|
|
232
|
+
toolName: opts.name,
|
|
233
|
+
outcome,
|
|
234
|
+
steps: Array.isArray(commitLog) ? commitLog.length : 0,
|
|
235
|
+
recording: {
|
|
236
|
+
snapshot,
|
|
237
|
+
structure: chart.buildTimeStructure,
|
|
238
|
+
},
|
|
239
|
+
...(ctrl !== undefined && { controlDeps: ctrl.asLookup() }),
|
|
240
|
+
...(lines.length > 0 && { narrative: lines }),
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
catch (e) {
|
|
244
|
+
store.keep({
|
|
245
|
+
toolCallId: ctx.toolCallId,
|
|
246
|
+
toolName: opts.name,
|
|
247
|
+
outcome,
|
|
248
|
+
steps: 0,
|
|
249
|
+
problem: e instanceof Error ? e.message : String(e),
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
const env = {};
|
|
254
|
+
if (ctx.signal)
|
|
255
|
+
env.signal = ctx.signal;
|
|
256
|
+
try {
|
|
257
|
+
await executor.run({ input: args, env });
|
|
258
|
+
}
|
|
259
|
+
catch (e) {
|
|
260
|
+
const signal = absenceSignalOf(e);
|
|
261
|
+
if (signal !== undefined) {
|
|
262
|
+
// ABSENCE PASS-THROUGH: the inner source answered "I looked and
|
|
263
|
+
// there is nothing", and the runbook has nothing to add. It goes
|
|
264
|
+
// back EXACTLY as it arrived so the framework still reads it as an
|
|
265
|
+
// absence. The kept record files as 'error' — the closed outcome
|
|
266
|
+
// word nearest "the traversal ended on a thrown signal".
|
|
267
|
+
keepRecordOf('error');
|
|
268
|
+
return signal.absence;
|
|
269
|
+
}
|
|
270
|
+
keepRecordOf('error');
|
|
271
|
+
throw e;
|
|
272
|
+
}
|
|
273
|
+
if (executor.isPaused()) {
|
|
274
|
+
keepRecordOf('paused');
|
|
275
|
+
const err = new Error(`${label}: the inner chart paused. Approval-gate integration (typed resume ` +
|
|
276
|
+
`through agent.resume) is the runbook program's next phase; until it lands a ` +
|
|
277
|
+
`paused procedure cannot be resumed through the tool boundary. The checkpoint ` +
|
|
278
|
+
`is on err.checkpoint.`);
|
|
279
|
+
err.checkpoint = executor.getCheckpoint();
|
|
280
|
+
throw err;
|
|
281
|
+
}
|
|
282
|
+
const raw = executor.getSnapshot();
|
|
283
|
+
keepRecordOf('ok', raw);
|
|
284
|
+
const state = raw.sharedState ??
|
|
285
|
+
raw.values ??
|
|
286
|
+
{};
|
|
287
|
+
// ── The walk ────────────────────────────────────────────────────────
|
|
288
|
+
const entries = walkRecorder.getEntries();
|
|
289
|
+
const projected = projectWalk(entries, walkCap);
|
|
290
|
+
const walk = await mintWalk(ctx, projected, {
|
|
291
|
+
toolName: opts.name,
|
|
292
|
+
toolCallId: ctx.toolCallId,
|
|
293
|
+
...(ctx.runId !== undefined && { runId: ctx.runId }),
|
|
294
|
+
stepsExecuted: walkRecorder.stepCount,
|
|
295
|
+
});
|
|
296
|
+
// ── The projection (verdict kinds only) ─────────────────────────────
|
|
297
|
+
let rows;
|
|
298
|
+
let shown;
|
|
299
|
+
let declined;
|
|
300
|
+
if (isVerdictKind) {
|
|
301
|
+
rows = verdictRowsOf(state);
|
|
302
|
+
shown = rows.slice(0, maxRows);
|
|
303
|
+
declined = rows.filter((row) => row.verdict === DECLINED_VERDICT).length;
|
|
304
|
+
}
|
|
305
|
+
const meanings = identity !== undefined && harvest !== undefined
|
|
306
|
+
? composeMeanings(identity, harvest.observed)
|
|
307
|
+
: undefined;
|
|
308
|
+
// ── The ledger ──────────────────────────────────────────────────────
|
|
309
|
+
// The procedure's display name: the chart's own root name (what the
|
|
310
|
+
// author called it) — the tool name is the fallback, never the
|
|
311
|
+
// auto-generated multi-line description.
|
|
312
|
+
const chartName = chart.buildTimeStructure?.name ?? opts.name;
|
|
313
|
+
const ledger = composeLedger(foldInnerCoverage(dispatch.records), chartCoverageOf(state), {
|
|
314
|
+
chartName,
|
|
315
|
+
stepsExecuted: walkRecorder.stepCount,
|
|
316
|
+
...(opts.rules !== undefined && { rules: opts.rules }),
|
|
317
|
+
...(rows !== undefined && { rowsTotal: rows.length }),
|
|
318
|
+
...(declined !== undefined && { declinedRows: declined }),
|
|
319
|
+
});
|
|
320
|
+
// ── Provenance — re-emitted FIRST ───────────────────────────────────
|
|
321
|
+
const af_provenance = {
|
|
322
|
+
...carriedProvenanceOf(dispatch.records),
|
|
323
|
+
tool: opts.name,
|
|
324
|
+
toolCallId: ctx.toolCallId,
|
|
325
|
+
};
|
|
326
|
+
const report = bagOf(state.report) ?? {};
|
|
327
|
+
const envelope = {
|
|
328
|
+
af_coverage: ledger,
|
|
329
|
+
result: {
|
|
330
|
+
af_provenance,
|
|
331
|
+
rule_version: opts.rules?.version ?? 'undeclared',
|
|
332
|
+
...report,
|
|
333
|
+
...(shown !== undefined &&
|
|
334
|
+
rows !== undefined && {
|
|
335
|
+
verdicts: shown,
|
|
336
|
+
rows_shown: shown.length,
|
|
337
|
+
rows_total: rows.length,
|
|
338
|
+
rows_complete: shown.length === rows.length,
|
|
339
|
+
table: renderVerdictTable(shown),
|
|
340
|
+
render_note: VERDICT_RENDER_NOTE,
|
|
341
|
+
...(meanings !== undefined && { verdict_meanings: meanings }),
|
|
342
|
+
}),
|
|
343
|
+
walk,
|
|
344
|
+
},
|
|
345
|
+
};
|
|
346
|
+
return envelope;
|
|
347
|
+
},
|
|
348
|
+
});
|
|
349
|
+
if (store === undefined)
|
|
350
|
+
return tool;
|
|
351
|
+
const keepsRecords = { ...tool, [INNER_RUN_RECORDS]: store };
|
|
352
|
+
return keepsRecords;
|
|
353
|
+
}
|
|
354
|
+
//# sourceMappingURL=runbookAsTool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runbookAsTool.js","sourceRoot":"","sources":["../../../../src/core/runbook/runbookAsTool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8EG;AAEH,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAyB,MAAM,aAAa,CAAC;AAClF,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EACL,uBAAuB,EACvB,iBAAiB,EACjB,aAAa,GAId,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAAE,UAAU,EAAwC,MAAM,aAAa,CAAC;AAC/E,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,iBAAiB,GAClB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC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I,YAAY;oBACjD,GAAG,MAAM;oBACT,GAAG,CAAC,KAAK,KAAK,SAAS;wBACrB,IAAI,KAAK,SAAS,IAAI;wBACpB,QAAQ,EAAE,KAAK;wBACf,UAAU,EAAE,KAAK,CAAC,MAAM;wBACxB,UAAU,EAAE,IAAI,CAAC,MAAM;wBACvB,aAAa,EAAE,KAAK,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM;wBAC3C,KAAK,EAAE,kBAAkB,CAAC,KAAK,CAAC;wBAChC,WAAW,EAAE,mBAAmB;wBAChC,GAAG,CAAC,QAAQ,KAAK,SAAS,IAAI,EAAE,gBAAgB,EAAE,QAAQ,EAAE,CAAC;qBAC9D,CAAC;oBACJ,IAAI;iBACL;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,iBAAiB,CAAC,EAAE,KAAK,EAAE,CAAC;IACpF,OAAO,YAAY,CAAC;AACtB,CAAC"}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* runbook/types — the vocabulary of the runbook bridge.
|
|
3
|
+
*
|
|
4
|
+
* Pattern: one options bag, four concerns (declarations, procedure, evidence
|
|
5
|
+
* policy, walk policy) + one envelope type split into a MANDATORY
|
|
6
|
+
* SPINE and an OPTIONAL projection. Pure data, no behavior.
|
|
7
|
+
* Role: core/ layer. `runbookAsTool.ts` consumes; consumers read the
|
|
8
|
+
* envelope types when they assert on results.
|
|
9
|
+
* Emits: N/A.
|
|
10
|
+
*
|
|
11
|
+
* The SPINE / PROJECTION split is load-bearing honesty, not taste: the spine
|
|
12
|
+
* (coverage, provenance, rule version, the recorded walk) is what EVERY
|
|
13
|
+
* runbook ships whatever its shape, so an answer can never arrive without its
|
|
14
|
+
* boundary; the verdict/rowset projection is one shape of answer (a triage),
|
|
15
|
+
* selected by `resultKind: 'verdict/*'` — an action-taking runbook ships the
|
|
16
|
+
* spine plus its own `report` payload and no rowset. The spine's wire shape
|
|
17
|
+
* is explicitly PROVISIONAL until a second, differently-shaped consumer has
|
|
18
|
+
* shipped through it.
|
|
19
|
+
*/
|
|
20
|
+
import type { CombinedRecorder, FlowChart, RedactionPolicy } from 'footprintjs';
|
|
21
|
+
import type { CoverageItem } from '../agent/coverage/types.js';
|
|
22
|
+
import type { ToolDispatch, ToolOwner, ToolResultCeiling } from '../tools.js';
|
|
23
|
+
import type { ToolResultClass } from '../../lib/semantics/types.js';
|
|
24
|
+
import type { ToolWants } from '../../artifacts/wants.js';
|
|
25
|
+
/**
|
|
26
|
+
* The procedure: a factory invoked PER CALL with the run's own tool dispatch
|
|
27
|
+
* (`ctx.tools`), returning a FRESH chart whose stages close over it.
|
|
28
|
+
*
|
|
29
|
+
* Per call for two reasons that are really one: a chart shared between two
|
|
30
|
+
* runs is a chart whose closures belong to whichever run built it last, and
|
|
31
|
+
* the dispatch only exists at execute time — so the factory is both the
|
|
32
|
+
* fresh-chart law and the delivery mechanism.
|
|
33
|
+
*
|
|
34
|
+
* It is ALSO invoked once at definition time, with a probe dispatch whose
|
|
35
|
+
* `has` answers false and whose `call` refuses — to read the chart's declared
|
|
36
|
+
* contract (input schema, the named decider's branches). Stage bodies do not
|
|
37
|
+
* run at build, so a well-formed factory pays nothing; a factory with side
|
|
38
|
+
* effects at build time is a factory that lies about being a declaration.
|
|
39
|
+
*/
|
|
40
|
+
export type RunbookProcedure = (tools: ToolDispatch) => FlowChart;
|
|
41
|
+
/** Rule provenance — threaded bridge → envelope → coverage sentence, so an
|
|
42
|
+
* answer produced under one reading of the rules can be told apart from an
|
|
43
|
+
* answer produced under the next. */
|
|
44
|
+
export interface RunbookRules {
|
|
45
|
+
/** The rule set's name ('health-signal'). Non-empty. */
|
|
46
|
+
readonly name: string;
|
|
47
|
+
/** Its version stamp ('v1'). Non-empty; bump when the READING changes,
|
|
48
|
+
* never for wording. */
|
|
49
|
+
readonly version: string;
|
|
50
|
+
}
|
|
51
|
+
/** The verdict/rowset projection's dials. */
|
|
52
|
+
export interface RunbookVerdictsOptions {
|
|
53
|
+
/**
|
|
54
|
+
* The decider stage (by id or name) whose declared branch labels generate
|
|
55
|
+
* `verdict_meanings`. Branch descriptions come from the chart's own
|
|
56
|
+
* structure when the decider is statically declared; rule labels observed
|
|
57
|
+
* in this run's decide() evidence refine them (and are the only source
|
|
58
|
+
* when the decider lives inside a dynamically generated fan-out branch,
|
|
59
|
+
* where build-time structure cannot see it).
|
|
60
|
+
*/
|
|
61
|
+
readonly decider: string;
|
|
62
|
+
/** Cap on `verdicts` rows AND the rendered table — ONE number for both
|
|
63
|
+
* halves (a longer list beside a shorter table is an invitation to retype
|
|
64
|
+
* identifiers). Default 50. */
|
|
65
|
+
readonly maxRows?: number;
|
|
66
|
+
}
|
|
67
|
+
/** The walk policy. */
|
|
68
|
+
export interface RunbookWalkOptions {
|
|
69
|
+
/** Row cap on the minted walk (default 500). When the full walk does not
|
|
70
|
+
* fit, the CONTROL FLOW survives — see `walk.ts` for the projection law. */
|
|
71
|
+
readonly cap?: number;
|
|
72
|
+
}
|
|
73
|
+
/** Everything `runbookAsTool` accepts. Smallest legal call:
|
|
74
|
+
* `{ name, description, procedure }` — and it still yields the spine. */
|
|
75
|
+
export interface RunbookAsToolOptions {
|
|
76
|
+
/** Tool name the LLM dispatches by. */
|
|
77
|
+
readonly name: string;
|
|
78
|
+
/** REQUIRED — a description-less tool is invisible to the model. */
|
|
79
|
+
readonly description: string;
|
|
80
|
+
/** The procedure factory — see {@link RunbookProcedure}. */
|
|
81
|
+
readonly procedure: RunbookProcedure;
|
|
82
|
+
/** Selects the envelope projection (`'verdict/*'` gets the rowset) AND is
|
|
83
|
+
* the artifact kind a placed result is minted under. */
|
|
84
|
+
readonly resultKind?: string;
|
|
85
|
+
readonly resultClass?: ToolResultClass;
|
|
86
|
+
readonly owner?: ToolOwner;
|
|
87
|
+
readonly resultCeiling?: ToolResultCeiling;
|
|
88
|
+
readonly wants?: ToolWants;
|
|
89
|
+
readonly argumentsFrom?: readonly string[];
|
|
90
|
+
/** The named ingredient tools the procedure calls through `ctx.tools` —
|
|
91
|
+
* drift-checked at agent build. */
|
|
92
|
+
readonly composedOf?: readonly string[];
|
|
93
|
+
/** Explicit input schema wins; otherwise the chart's `.contract()` input
|
|
94
|
+
* is lifted when it is a plain JSON-Schema object (a parseable schema —
|
|
95
|
+
* zod et al. — cannot be serialized for the model and falls back to the
|
|
96
|
+
* empty-object default). */
|
|
97
|
+
readonly inputSchema?: Readonly<Record<string, unknown>>;
|
|
98
|
+
/** Rule provenance — see {@link RunbookRules}. */
|
|
99
|
+
readonly rules?: RunbookRules;
|
|
100
|
+
/** The verdict projection's dials — see {@link RunbookVerdictsOptions}. */
|
|
101
|
+
readonly verdicts?: RunbookVerdictsOptions;
|
|
102
|
+
/** The walk policy — see {@link RunbookWalkOptions}. */
|
|
103
|
+
readonly walk?: RunbookWalkOptions;
|
|
104
|
+
/** Observers attached to each invocation's fresh inner executor. */
|
|
105
|
+
readonly recorders?: ReadonlyArray<CombinedRecorder>;
|
|
106
|
+
/** Keep each invocation's inner record for `inspect_tool_run` descent. */
|
|
107
|
+
readonly keepRecord?: boolean;
|
|
108
|
+
/** Bounded LRU size for kept records (requires `keepRecord: true`). */
|
|
109
|
+
readonly keepRecordLimit?: number;
|
|
110
|
+
/** Redaction policy for the inner run (commit-time scrub). */
|
|
111
|
+
readonly redact?: RedactionPolicy;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* The recorded-walk descriptor — ALWAYS on the spine. The walk itself ships
|
|
115
|
+
* as an artifact ticket (`ref`), never as bytes in the envelope; with no
|
|
116
|
+
* store attached (or a failed mint) the descriptor still states its
|
|
117
|
+
* counters and the `note` names why there is no ticket — a missing walk must
|
|
118
|
+
* never be mistaken for a short run.
|
|
119
|
+
*/
|
|
120
|
+
export interface WalkDescriptor {
|
|
121
|
+
/** The claim-ticket ref of the minted walk artifact. Absent when no store
|
|
122
|
+
* is attached or the mint failed — `note` says which. */
|
|
123
|
+
readonly ref?: string;
|
|
124
|
+
/** The artifact kind (`'recording/chart-walk'`). Present with `ref`. */
|
|
125
|
+
readonly kind?: string;
|
|
126
|
+
/** Rows in the minted artifact. */
|
|
127
|
+
readonly rows: number;
|
|
128
|
+
/** Total execution steps the narrative recorder counted — spans isolated
|
|
129
|
+
* subflow logs, which the root commit log cannot. */
|
|
130
|
+
readonly steps_executed: number;
|
|
131
|
+
/** `'full'` — every narrative entry fit under the cap; `'control-flow'` —
|
|
132
|
+
* it did not, and the stages/forks/subflows/decisions survived while the
|
|
133
|
+
* per-key reads and writes were dropped. */
|
|
134
|
+
readonly projection: 'full' | 'control-flow';
|
|
135
|
+
readonly shown: number;
|
|
136
|
+
readonly total: number;
|
|
137
|
+
readonly complete: boolean;
|
|
138
|
+
/**
|
|
139
|
+
* WHICH SEGMENT of the run this walk covers. `'full'` for an un-gated run
|
|
140
|
+
* (all of phase 1). When approval gates land, a resumed run's recorders
|
|
141
|
+
* start empty on the fresh executor — its walk will say `'post-resume'`
|
|
142
|
+
* and its counters will count only that segment; the discriminant ships
|
|
143
|
+
* NOW so the wire does not break then.
|
|
144
|
+
*/
|
|
145
|
+
readonly walk_segment: 'full' | 'pre-pause' | 'post-resume';
|
|
146
|
+
/** The human sentence: what the walk is, and (when projected) what the
|
|
147
|
+
* control-flow projection kept and dropped, or why there is no ticket. */
|
|
148
|
+
readonly note: string;
|
|
149
|
+
}
|
|
150
|
+
/** One verdict row, as the chart wrote it. The bridge reads rows from the
|
|
151
|
+
* final state's `verdicts` key and requires only `verdict`; every other
|
|
152
|
+
* column is the app's own vocabulary. */
|
|
153
|
+
export interface VerdictRow {
|
|
154
|
+
readonly verdict: string;
|
|
155
|
+
readonly [column: string]: unknown;
|
|
156
|
+
}
|
|
157
|
+
/** The mandatory-spine + optional-projection envelope every runbook returns
|
|
158
|
+
* (unless an inner absence passed through — then the answer IS that absence,
|
|
159
|
+
* verbatim). Recognized by the framework's coverage funnel at the dispatch
|
|
160
|
+
* boundary like any `coverage()` ledger. */
|
|
161
|
+
export interface RunbookEnvelope {
|
|
162
|
+
readonly af_coverage: {
|
|
163
|
+
readonly checked?: readonly CoverageItem[];
|
|
164
|
+
readonly not_checked?: readonly CoverageItem[];
|
|
165
|
+
readonly cannot_cover?: readonly CoverageItem[];
|
|
166
|
+
/** The static coverage law sentence (the `coverage()` note). */
|
|
167
|
+
readonly note: string;
|
|
168
|
+
/** The run's own sentence — names the rule set and version. */
|
|
169
|
+
readonly sentence: string;
|
|
170
|
+
};
|
|
171
|
+
readonly result: {
|
|
172
|
+
/** Re-emitted FIRST: the carried inner provenance stamp (if any inner
|
|
173
|
+
* tool declared one — a LOCAL SEED confession survives composition)
|
|
174
|
+
* plus this call's own `{tool, toolCallId}`. */
|
|
175
|
+
readonly af_provenance: Readonly<Record<string, unknown>>;
|
|
176
|
+
/** `rules.version`, or the honest `'undeclared'` when no rules were
|
|
177
|
+
* declared — the field never silently vanishes. */
|
|
178
|
+
readonly rule_version: string;
|
|
179
|
+
/** The recorded walk — always present. */
|
|
180
|
+
readonly walk: WalkDescriptor;
|
|
181
|
+
readonly verdicts?: readonly VerdictRow[];
|
|
182
|
+
readonly rows_shown?: number;
|
|
183
|
+
readonly rows_total?: number;
|
|
184
|
+
readonly rows_complete?: boolean;
|
|
185
|
+
/** Pre-rendered markdown table over the SAME rows as `verdicts`. */
|
|
186
|
+
readonly table?: string;
|
|
187
|
+
/** The render law, stated to the model. Present with `table`. */
|
|
188
|
+
readonly render_note?: string;
|
|
189
|
+
/** branch → meaning, GENERATED from the decider's declared branches and
|
|
190
|
+
* the rule labels this run's evidence carried — never hand-restated. */
|
|
191
|
+
readonly verdict_meanings?: Readonly<Record<string, string>>;
|
|
192
|
+
/** Everything the chart put in its `report` state key — the app's own
|
|
193
|
+
* result fields, spread here verbatim (spine keys win). */
|
|
194
|
+
readonly [appField: string]: unknown;
|
|
195
|
+
};
|
|
196
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* runbook/types — the vocabulary of the runbook bridge.
|
|
3
|
+
*
|
|
4
|
+
* Pattern: one options bag, four concerns (declarations, procedure, evidence
|
|
5
|
+
* policy, walk policy) + one envelope type split into a MANDATORY
|
|
6
|
+
* SPINE and an OPTIONAL projection. Pure data, no behavior.
|
|
7
|
+
* Role: core/ layer. `runbookAsTool.ts` consumes; consumers read the
|
|
8
|
+
* envelope types when they assert on results.
|
|
9
|
+
* Emits: N/A.
|
|
10
|
+
*
|
|
11
|
+
* The SPINE / PROJECTION split is load-bearing honesty, not taste: the spine
|
|
12
|
+
* (coverage, provenance, rule version, the recorded walk) is what EVERY
|
|
13
|
+
* runbook ships whatever its shape, so an answer can never arrive without its
|
|
14
|
+
* boundary; the verdict/rowset projection is one shape of answer (a triage),
|
|
15
|
+
* selected by `resultKind: 'verdict/*'` — an action-taking runbook ships the
|
|
16
|
+
* spine plus its own `report` payload and no rowset. The spine's wire shape
|
|
17
|
+
* is explicitly PROVISIONAL until a second, differently-shaped consumer has
|
|
18
|
+
* shipped through it.
|
|
19
|
+
*/
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/core/runbook/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG"}
|