audit-tools 0.50.4 → 0.50.6
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/audit/cli/auditStep.d.ts +30 -0
- package/dist/audit/cli/auditStep.d.ts.map +1 -1
- package/dist/audit/cli/auditStep.js +50 -0
- package/dist/audit/cli/auditStep.js.map +1 -1
- package/dist/audit/cli/foldTransaction.d.ts +103 -0
- package/dist/audit/cli/foldTransaction.d.ts.map +1 -0
- package/dist/audit/cli/foldTransaction.js +243 -0
- package/dist/audit/cli/foldTransaction.js.map +1 -0
- package/dist/audit/cli/nextStepHelpers.d.ts +109 -28
- package/dist/audit/cli/nextStepHelpers.d.ts.map +1 -1
- package/dist/audit/cli/nextStepHelpers.js +645 -560
- package/dist/audit/cli/nextStepHelpers.js.map +1 -1
- package/dist/audit/cli/reviewRun.d.ts +15 -3
- package/dist/audit/cli/reviewRun.d.ts.map +1 -1
- package/dist/audit/cli/reviewRun.js +39 -13
- package/dist/audit/cli/reviewRun.js.map +1 -1
- package/dist/audit/orchestrator/advance.d.ts +38 -36
- package/dist/audit/orchestrator/advance.d.ts.map +1 -1
- package/dist/audit/orchestrator/advance.js +126 -82
- package/dist/audit/orchestrator/advance.js.map +1 -1
- package/dist/audit/orchestrator/advanceTypes.d.ts +23 -0
- package/dist/audit/orchestrator/advanceTypes.d.ts.map +1 -1
- package/dist/audit/orchestrator/designReviewSnapshot.d.ts +8 -2
- package/dist/audit/orchestrator/designReviewSnapshot.d.ts.map +1 -1
- package/dist/audit/orchestrator/designReviewSnapshot.js +12 -6
- package/dist/audit/orchestrator/designReviewSnapshot.js.map +1 -1
- package/dist/audit/orchestrator/executorRunners.d.ts.map +1 -1
- package/dist/audit/orchestrator/executorRunners.js +1 -1
- package/dist/audit/orchestrator/executorRunners.js.map +1 -1
- package/dist/audit/orchestrator/executors.d.ts.map +1 -1
- package/dist/audit/orchestrator/executors.js +1 -1
- package/dist/audit/orchestrator/executors.js.map +1 -1
- package/dist/audit/orchestrator/hostInputPause.d.ts +0 -33
- package/dist/audit/orchestrator/hostInputPause.d.ts.map +1 -1
- package/dist/audit/orchestrator/hostInputPause.js +6 -64
- package/dist/audit/orchestrator/hostInputPause.js.map +1 -1
- package/dist/audit/orchestrator/obligationPolicy.d.ts +90 -0
- package/dist/audit/orchestrator/obligationPolicy.d.ts.map +1 -0
- package/dist/audit/orchestrator/obligationPolicy.js +228 -0
- package/dist/audit/orchestrator/obligationPolicy.js.map +1 -0
- package/dist/audit/orchestrator/systemicChallengeExecutor.d.ts +1 -1
- package/dist/audit/orchestrator/systemicChallengeExecutor.d.ts.map +1 -1
- package/dist/audit/orchestrator/systemicChallengeExecutor.js +23 -1
- package/dist/audit/orchestrator/systemicChallengeExecutor.js.map +1 -1
- package/dist/audit/types/systemicChallenge.d.ts +9 -0
- package/dist/audit/types/systemicChallenge.d.ts.map +1 -1
- package/dist/shared/engine/obligationEngine.d.ts +45 -11
- package/dist/shared/engine/obligationEngine.d.ts.map +1 -1
- package/dist/shared/engine/obligationEngine.js +41 -7
- package/dist/shared/engine/obligationEngine.js.map +1 -1
- package/package.json +1 -1
|
@@ -152,25 +152,44 @@ export declare function deriveEngineBound(cap: number): number;
|
|
|
152
152
|
* - `step` null, `stopped: "bound"` → the fold spent `maxTransitions`
|
|
153
153
|
* transitions without reaching an emit or completion. Also non-convergence,
|
|
154
154
|
* detected by counting rather than by signature.
|
|
155
|
+
* - `step` null, `stopped: "budget"` → the fold spent `maxExecutions` charged
|
|
156
|
+
* obligation executions. This is NOT non-convergence: the budget is a pacing
|
|
157
|
+
* cap, the stop is graceful, and the caller resumes the fold on its next
|
|
158
|
+
* call. Only possible when `opts.maxExecutions` is supplied.
|
|
155
159
|
*
|
|
156
160
|
* `stopped` being ABSENT is what means "the run is complete". A caller that
|
|
157
161
|
* branches on `step` alone therefore cannot tell completion from
|
|
158
|
-
* non-convergence, and would report a wedged fold as a finished one — so
|
|
159
|
-
* stopped
|
|
160
|
-
* obligation the fold was executing
|
|
161
|
-
*
|
|
162
|
+
* non-convergence, and would report a wedged fold as a finished one — so every
|
|
163
|
+
* stopped value must be handled explicitly. `lastObligationId` names the
|
|
164
|
+
* obligation the fold was executing (or, for `budget`, about to execute) when
|
|
165
|
+
* it stopped, so a caller can say WHICH obligation is in flight without
|
|
166
|
+
* parsing it out of a message.
|
|
162
167
|
*/
|
|
163
168
|
export interface AdvanceResult<S, Step> {
|
|
164
169
|
state: S;
|
|
165
170
|
step: Step | null;
|
|
166
|
-
stopped?: "cycle" | "bound";
|
|
171
|
+
stopped?: "cycle" | "bound" | "budget";
|
|
167
172
|
/** The obligation in flight when `stopped` was set; absent otherwise. */
|
|
168
173
|
lastObligationId?: string;
|
|
174
|
+
/**
|
|
175
|
+
* The numeric limit that fired — `maxTransitions` for `bound`,
|
|
176
|
+
* `maxExecutions` for `budget`; absent for `cycle` (no number fired). Carried
|
|
177
|
+
* ON the result so `describeStoppedFold` reports the number that actually
|
|
178
|
+
* stopped the fold, and no caller has to know which of two limits to restate.
|
|
179
|
+
*/
|
|
180
|
+
stoppedBound?: number;
|
|
169
181
|
}
|
|
170
|
-
/**
|
|
182
|
+
/**
|
|
183
|
+
* A stop, described once for every draw that can hit one. `cycle` and `bound`
|
|
184
|
+
* are non-convergence; `budget` is the graceful pacing cap — a caller that
|
|
185
|
+
* expects the cap should branch on `stopped === "budget"` BEFORE reaching for
|
|
186
|
+
* this description, and build its own resumable pause from its accumulators.
|
|
187
|
+
* The description exists so a caller that does NOT special-case the budget
|
|
188
|
+
* still reports the stop honestly rather than as a finished run.
|
|
189
|
+
*/
|
|
171
190
|
export interface StoppedFoldDescription {
|
|
172
191
|
/** Which backstop fired, carried through so a caller need not re-read it. */
|
|
173
|
-
stopped: "cycle" | "bound";
|
|
192
|
+
stopped: "cycle" | "bound" | "budget";
|
|
174
193
|
/**
|
|
175
194
|
* The obligation in flight when the fold stopped, or `"unknown"` when it
|
|
176
195
|
* stopped before selecting one. Never parsed out of prose.
|
|
@@ -189,14 +208,16 @@ export interface StoppedFoldDescription {
|
|
|
189
208
|
* null-check itself the branch: there is no way to consume the description
|
|
190
209
|
* without having asked the question.
|
|
191
210
|
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
211
|
+
* The number reported is `outcome.stoppedBound` — the limit that actually
|
|
212
|
+
* fired, carried on the result by the engine itself. `opts.bound` remains as
|
|
213
|
+
* the fallback for callers describing an outcome from an engine that did not
|
|
214
|
+
* stamp one, so the number a host reads is still never a restated constant.
|
|
194
215
|
*
|
|
195
216
|
* `cause` is prose for a human terminal ONLY. Never match it: `stopped` and
|
|
196
217
|
* `spinning` are the machine-readable fields, and recognizing a wedged fold by
|
|
197
218
|
* its message text is the divergence this module's bounded-call invariant bans.
|
|
198
219
|
*/
|
|
199
|
-
export declare function describeStoppedFold(outcome: Pick<AdvanceResult<unknown, unknown>, "stopped" | "lastObligationId">, opts?: {
|
|
220
|
+
export declare function describeStoppedFold(outcome: Pick<AdvanceResult<unknown, unknown>, "stopped" | "lastObligationId" | "stoppedBound">, opts?: {
|
|
200
221
|
bound?: number;
|
|
201
222
|
}): StoppedFoldDescription | null;
|
|
202
223
|
/**
|
|
@@ -222,7 +243,19 @@ export declare function describeStoppedFold(outcome: Pick<AdvanceResult<unknown,
|
|
|
222
243
|
* signature — it stops the loop with `stopped: "bound"` after that many
|
|
223
244
|
* consecutive transitions.
|
|
224
245
|
*
|
|
225
|
-
*
|
|
246
|
+
* **Execution budget.** `opts.maxExecutions` is the consumer-facing pacing cap
|
|
247
|
+
* (PH-03: a budget stop the result expresses structurally, so no caller wraps
|
|
248
|
+
* the engine in a second drain to enforce one). The engine charges EVERY
|
|
249
|
+
* `obligation.execute` call to it, spend-before-dispatch: once the budget is
|
|
250
|
+
* spent, the next selected obligation is NOT executed and the loop returns
|
|
251
|
+
* `stopped: "budget"` naming it. Because every transition follows a charged
|
|
252
|
+
* execution, `transitions <= charged executions` holds by construction — so a
|
|
253
|
+
* `maxTransitions` derived via {@link deriveEngineBound} from the same cap can
|
|
254
|
+
* never fire first, which is the bounded-call invariant this module owns. An
|
|
255
|
+
* `emit` spends its charge and returns normally; it is never converted into a
|
|
256
|
+
* budget stop.
|
|
257
|
+
*
|
|
258
|
+
* ALL backstops terminate GRACEFULLY. The bound used to throw, which forced
|
|
226
259
|
* every consumer to recognize a wedged fold by matching text in an error
|
|
227
260
|
* message and to recover the spinning obligation's id with a regex over that
|
|
228
261
|
* same prose — so the engine's bound was part of its contract while its only
|
|
@@ -239,5 +272,6 @@ export declare function describeStoppedFold(outcome: Pick<AdvanceResult<unknown,
|
|
|
239
272
|
export declare function advance<S, Ctx, Step>(engine: ObligationEngine<S, Ctx, Step>, state: S, ctx: Ctx, opts?: {
|
|
240
273
|
maxTransitions?: number;
|
|
241
274
|
stateSignature?: (state: S) => string;
|
|
275
|
+
maxExecutions?: number;
|
|
242
276
|
}): Promise<AdvanceResult<S, Step>>;
|
|
243
277
|
//# sourceMappingURL=obligationEngine.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"obligationEngine.d.ts","sourceRoot":"","sources":["../../../src/shared/engine/obligationEngine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,oEAMhC,CAAC;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEpE,+EAA+E;AAC/E,eAAO,MAAM,gBAAgB;;;;;;;;;;;;EAMlB,CAAC;AACZ,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE1D;;;;;;;;;;;;GAYG;AACH,wBAAgB,6BAA6B,CAAC,CAAC,SAAS,UAAU,EAChE,QAAQ,EAAE,SAAS,MAAM,EAAE,EAC3B,WAAW,EAAE,SAAS,C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,EAAE,MAAM,CAAC;IACjB,yEAAyE;IACzE,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,IAAI,CACX,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,EAC/B,SAAS,GAAG,kBAAkB,GAAG,cAAc,CAChD,EACD,IAAI,CAAC,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GACxB,sBAAsB,GAAG,IAAI,CAc/B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,wBAAsB,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,IAAI,EACxC,MAAM,EAAE,gBAAgB,CAAC,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,EACtC,KAAK,EAAE,CAAC,EACR,GAAG,EAAE,GAAG,EACR,IAAI,CAAC,EAAE;IACL,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,CAAC;IACtC,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,GACA,OAAO,CAAC,aAAa,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAqEjC"}
|
|
@@ -111,8 +111,10 @@ export function deriveEngineBound(cap) {
|
|
|
111
111
|
* null-check itself the branch: there is no way to consume the description
|
|
112
112
|
* without having asked the question.
|
|
113
113
|
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
114
|
+
* The number reported is `outcome.stoppedBound` — the limit that actually
|
|
115
|
+
* fired, carried on the result by the engine itself. `opts.bound` remains as
|
|
116
|
+
* the fallback for callers describing an outcome from an engine that did not
|
|
117
|
+
* stamp one, so the number a host reads is still never a restated constant.
|
|
116
118
|
*
|
|
117
119
|
* `cause` is prose for a human terminal ONLY. Never match it: `stopped` and
|
|
118
120
|
* `spinning` are the machine-readable fields, and recognizing a wedged fold by
|
|
@@ -121,13 +123,16 @@ export function deriveEngineBound(cap) {
|
|
|
121
123
|
export function describeStoppedFold(outcome, opts) {
|
|
122
124
|
if (!outcome.stopped)
|
|
123
125
|
return null;
|
|
124
|
-
const bound = opts?.bound ?? DEFAULT_MAX_TRANSITIONS;
|
|
126
|
+
const bound = outcome.stoppedBound ?? opts?.bound ?? DEFAULT_MAX_TRANSITIONS;
|
|
127
|
+
const cause = outcome.stopped === "bound"
|
|
128
|
+
? `spent the engine transition bound (${String(bound)}) without reaching a host-actionable step`
|
|
129
|
+
: outcome.stopped === "budget"
|
|
130
|
+
? `spent its charged-execution budget (${String(bound)}) and pauses resumably at the cap`
|
|
131
|
+
: "revisited a state it had already scanned this run";
|
|
125
132
|
return {
|
|
126
133
|
stopped: outcome.stopped,
|
|
127
134
|
spinning: outcome.lastObligationId ?? "unknown",
|
|
128
|
-
cause
|
|
129
|
-
? `spent the engine transition bound (${String(bound)}) without reaching a host-actionable step`
|
|
130
|
-
: "revisited a state it had already scanned this run",
|
|
135
|
+
cause,
|
|
131
136
|
};
|
|
132
137
|
}
|
|
133
138
|
/**
|
|
@@ -153,7 +158,19 @@ export function describeStoppedFold(outcome, opts) {
|
|
|
153
158
|
* signature — it stops the loop with `stopped: "bound"` after that many
|
|
154
159
|
* consecutive transitions.
|
|
155
160
|
*
|
|
156
|
-
*
|
|
161
|
+
* **Execution budget.** `opts.maxExecutions` is the consumer-facing pacing cap
|
|
162
|
+
* (PH-03: a budget stop the result expresses structurally, so no caller wraps
|
|
163
|
+
* the engine in a second drain to enforce one). The engine charges EVERY
|
|
164
|
+
* `obligation.execute` call to it, spend-before-dispatch: once the budget is
|
|
165
|
+
* spent, the next selected obligation is NOT executed and the loop returns
|
|
166
|
+
* `stopped: "budget"` naming it. Because every transition follows a charged
|
|
167
|
+
* execution, `transitions <= charged executions` holds by construction — so a
|
|
168
|
+
* `maxTransitions` derived via {@link deriveEngineBound} from the same cap can
|
|
169
|
+
* never fire first, which is the bounded-call invariant this module owns. An
|
|
170
|
+
* `emit` spends its charge and returns normally; it is never converted into a
|
|
171
|
+
* budget stop.
|
|
172
|
+
*
|
|
173
|
+
* ALL backstops terminate GRACEFULLY. The bound used to throw, which forced
|
|
157
174
|
* every consumer to recognize a wedged fold by matching text in an error
|
|
158
175
|
* message and to recover the spinning obligation's id with a regex over that
|
|
159
176
|
* same prose — so the engine's bound was part of its contract while its only
|
|
@@ -169,10 +186,12 @@ export function describeStoppedFold(outcome, opts) {
|
|
|
169
186
|
*/
|
|
170
187
|
export async function advance(engine, state, ctx, opts) {
|
|
171
188
|
const maxTransitions = opts?.maxTransitions ?? DEFAULT_MAX_TRANSITIONS;
|
|
189
|
+
const maxExecutions = opts?.maxExecutions;
|
|
172
190
|
const stateSignature = opts?.stateSignature;
|
|
173
191
|
const visited = stateSignature ? new Set() : null;
|
|
174
192
|
let current = state;
|
|
175
193
|
let transitions = 0;
|
|
194
|
+
let executions = 0;
|
|
176
195
|
// The obligation most recently selected — reported on every non-convergent
|
|
177
196
|
// stop so the caller can name what is spinning.
|
|
178
197
|
let lastObligationId = null;
|
|
@@ -197,6 +216,20 @@ export async function advance(engine, state, ctx, opts) {
|
|
|
197
216
|
if (!obligation)
|
|
198
217
|
return { state: current, step: null };
|
|
199
218
|
lastObligationId = obligation.id;
|
|
219
|
+
if (maxExecutions !== undefined && executions >= maxExecutions) {
|
|
220
|
+
// The budget is spent and another obligation is still actionable. Spend-
|
|
221
|
+
// before-dispatch: the selected obligation is NOT executed — a cap stated
|
|
222
|
+
// as a maximum must never authorize one step past itself. Graceful and
|
|
223
|
+
// resumable; the next call re-selects this same obligation.
|
|
224
|
+
return {
|
|
225
|
+
state: current,
|
|
226
|
+
step: null,
|
|
227
|
+
stopped: "budget",
|
|
228
|
+
lastObligationId,
|
|
229
|
+
stoppedBound: maxExecutions,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
executions += 1;
|
|
200
233
|
const outcome = await obligation.execute(current, ctx);
|
|
201
234
|
if (outcome.kind === "emit") {
|
|
202
235
|
return { state: outcome.state ?? current, step: outcome.step };
|
|
@@ -213,6 +246,7 @@ export async function advance(engine, state, ctx, opts) {
|
|
|
213
246
|
step: null,
|
|
214
247
|
stopped: "bound",
|
|
215
248
|
lastObligationId,
|
|
249
|
+
stoppedBound: maxTransitions,
|
|
216
250
|
};
|
|
217
251
|
}
|
|
218
252
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"obligationEngine.js","sourceRoot":"","sources":["../../../src/shared/engine/obligationEngine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,IAAI,CAAC;IAC1C,SAAS;IACT,SAAS;IACT,OAAO;IACP,SAAS;IACT,WAAW;CACZ,CAAC,CAAC;AAGH,+EAA+E;AAC/E,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC;KAC9B,MAAM,CAAC;IACN,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,KAAK,EAAE,qBAAqB;IAC5B,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC9B,CAAC;KACD,MAAM,EAAE,CAAC;AAGZ;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,6BAA6B,CAC3C,QAA2B,EAC3B,WAAyB;IAEzB,KAAK,MAAM,EAAE,IAAI,QAAQ,EAAE,CAAC;QAC1B,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAClD,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,KAAK,SAAS,IAAI,IAAI,CAAC,KAAK,KAAK,OAAO,CAAC,EAAE,CAAC;YACjE,OAAO,IAAI,CAAC;QACd,CAAC;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