dsh-harness-reflex 0.1.0 → 0.3.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/README.md +20 -6
- package/client.js +3511 -185
- package/dist/attribution.d.ts +266 -0
- package/dist/attribution.js +238 -0
- package/dist/attribution.js.map +1 -0
- package/dist/bridge.d.ts +311 -13
- package/dist/bridge.js +714 -42
- package/dist/bridge.js.map +1 -1
- package/dist/client-bundle.js +4 -1
- package/dist/client-bundle.js.map +1 -1
- package/dist/command.js +10 -0
- package/dist/command.js.map +1 -1
- package/dist/config.d.ts +530 -22
- package/dist/config.js +808 -27
- package/dist/config.js.map +1 -1
- package/dist/delegation-dispatch.d.ts +132 -0
- package/dist/delegation-dispatch.js +186 -0
- package/dist/delegation-dispatch.js.map +1 -0
- package/dist/delegation-health.d.ts +131 -0
- package/dist/delegation-health.js +97 -0
- package/dist/delegation-health.js.map +1 -0
- package/dist/delegation.d.ts +148 -0
- package/dist/delegation.js +186 -0
- package/dist/delegation.js.map +1 -0
- package/dist/effort-delegation.d.ts +144 -0
- package/dist/effort-delegation.js +280 -0
- package/dist/effort-delegation.js.map +1 -0
- package/dist/effort.d.ts +141 -0
- package/dist/effort.js +251 -9
- package/dist/effort.js.map +1 -1
- package/dist/host-patch.d.ts +156 -0
- package/dist/host-patch.js +534 -0
- package/dist/host-patch.js.map +1 -0
- package/dist/index.d.ts +12 -3
- package/dist/index.js +99 -7
- package/dist/index.js.map +1 -1
- package/dist/interventions.d.ts +98 -373
- package/dist/interventions.js +442 -1702
- package/dist/interventions.js.map +1 -1
- package/dist/panel-api.d.ts +328 -4
- package/dist/panel-api.js +322 -15
- package/dist/panel-api.js.map +1 -1
- package/dist/panel-mount.d.ts +81 -22
- package/dist/panel-mount.js +228 -7
- package/dist/panel-mount.js.map +1 -1
- package/dist/routing.d.ts +23 -18
- package/dist/routing.js +471 -153
- package/dist/routing.js.map +1 -1
- package/dist/session-audit.d.ts +70 -0
- package/dist/session-audit.js +73 -0
- package/dist/session-audit.js.map +1 -1
- package/dist/systemone-probe.d.ts +114 -0
- package/dist/systemone-probe.js +383 -0
- package/dist/systemone-probe.js.map +1 -0
- package/dist/testing.d.ts +212 -7
- package/dist/testing.js +333 -27
- package/dist/testing.js.map +1 -1
- package/dist/tools.d.ts +109 -3
- package/dist/tools.js +103 -4
- package/dist/tools.js.map +1 -1
- package/dist/unconfigured-backend.d.ts +72 -0
- package/dist/unconfigured-backend.js +94 -0
- package/dist/unconfigured-backend.js.map +1 -0
- package/dist/vendor/harness-reflex/backend/factory.d.ts +31 -1
- package/dist/vendor/harness-reflex/backend/factory.js +18 -3
- package/dist/vendor/harness-reflex/backend/factory.js.map +1 -1
- package/dist/vendor/harness-reflex/backend/jev.d.ts +20 -0
- package/dist/vendor/harness-reflex/backend/jev.js +11 -4
- package/dist/vendor/harness-reflex/backend/jev.js.map +1 -1
- package/dist/vendor/harness-reflex/backend/simple-jev.d.ts +16 -0
- package/dist/vendor/harness-reflex/backend/simple-jev.js +17 -6
- package/dist/vendor/harness-reflex/backend/simple-jev.js.map +1 -1
- package/dist/vendor/harness-reflex/core/closing.d.ts +90 -0
- package/dist/vendor/harness-reflex/core/closing.js +111 -0
- package/dist/vendor/harness-reflex/core/closing.js.map +1 -0
- package/dist/vendor/harness-reflex/core/evidence.d.ts +119 -0
- package/dist/vendor/harness-reflex/core/evidence.js +209 -0
- package/dist/vendor/harness-reflex/core/evidence.js.map +1 -0
- package/dist/vendor/harness-reflex/core/judge.d.ts +221 -0
- package/dist/vendor/harness-reflex/core/judge.js +251 -0
- package/dist/vendor/harness-reflex/core/judge.js.map +1 -0
- package/dist/vendor/harness-reflex/core/orchestrate-closing.d.ts +237 -0
- package/dist/vendor/harness-reflex/core/orchestrate-closing.js +250 -0
- package/dist/vendor/harness-reflex/core/orchestrate-closing.js.map +1 -0
- package/dist/vendor/harness-reflex/core/orchestrate-correction.d.ts +209 -0
- package/dist/vendor/harness-reflex/core/orchestrate-correction.js +141 -0
- package/dist/vendor/harness-reflex/core/orchestrate-correction.js.map +1 -0
- package/dist/vendor/harness-reflex/core/orchestrate-host.d.ts +225 -0
- package/dist/vendor/harness-reflex/core/orchestrate-host.js +80 -0
- package/dist/vendor/harness-reflex/core/orchestrate-host.js.map +1 -0
- package/dist/vendor/harness-reflex/core/orchestrate-stagnation.d.ts +259 -0
- package/dist/vendor/harness-reflex/core/orchestrate-stagnation.js +270 -0
- package/dist/vendor/harness-reflex/core/orchestrate-stagnation.js.map +1 -0
- package/dist/vendor/harness-reflex/core/orchestrate.d.ts +357 -0
- package/dist/vendor/harness-reflex/core/orchestrate.js +418 -0
- package/dist/vendor/harness-reflex/core/orchestrate.js.map +1 -0
- package/dist/vendor/harness-reflex/core/policy.d.ts +122 -0
- package/dist/vendor/harness-reflex/core/policy.js +102 -0
- package/dist/vendor/harness-reflex/core/policy.js.map +1 -0
- package/dist/vendor/harness-reflex/core/prune-plan.d.ts +141 -0
- package/dist/vendor/harness-reflex/core/prune-plan.js +390 -0
- package/dist/vendor/harness-reflex/core/prune-plan.js.map +1 -0
- package/dist/vendor/harness-reflex/core/text.d.ts +36 -0
- package/dist/vendor/harness-reflex/core/text.js +66 -0
- package/dist/vendor/harness-reflex/core/text.js.map +1 -0
- package/dist/vendor/harness-reflex/ports/audit.d.ts +18 -0
- package/dist/vendor/harness-reflex/ports/audit.js +11 -0
- package/dist/vendor/harness-reflex/ports/audit.js.map +1 -0
- package/dist/vendor/harness-reflex/ports/clock.d.ts +14 -0
- package/dist/vendor/harness-reflex/ports/clock.js +11 -0
- package/dist/vendor/harness-reflex/ports/clock.js.map +1 -0
- package/dist/vendor/harness-reflex/ports/decision.d.ts +75 -0
- package/dist/vendor/harness-reflex/ports/decision.js +2 -0
- package/dist/vendor/harness-reflex/ports/decision.js.map +1 -0
- package/dist/vendor/harness-reflex/ports/index.d.ts +14 -0
- package/dist/vendor/harness-reflex/ports/index.js +2 -0
- package/dist/vendor/harness-reflex/ports/index.js.map +1 -0
- package/dist/vendor/harness-reflex/ports/log.d.ts +22 -0
- package/dist/vendor/harness-reflex/ports/log.js +12 -0
- package/dist/vendor/harness-reflex/ports/log.js.map +1 -0
- package/dist/vendor/harness-reflex/ports/state.d.ts +46 -0
- package/dist/vendor/harness-reflex/ports/state.js +13 -0
- package/dist/vendor/harness-reflex/ports/state.js.map +1 -0
- package/package.json +25 -13
package/dist/interventions.d.ts
CHANGED
|
@@ -1,10 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Automatic interventions on the Host's native tool and agent lifecycle hooks.
|
|
3
|
+
*
|
|
4
|
+
* The plugin's eight MCP tools are pull-based: they act only when the *model*
|
|
5
|
+
* decides to call one. This module is the push half — the same System 1
|
|
6
|
+
* judgments, spent automatically at the four points where the Host already asks
|
|
7
|
+
* its listeners a question:
|
|
8
|
+
*
|
|
9
|
+
* | Hook | Capability | What it may do |
|
|
10
|
+
* | --- | --- | --- |
|
|
11
|
+
* | `tools/pre-execute` | `stagnation` | deny a call the run is repeating |
|
|
12
|
+
* | `tools/post-execute` | `prune` | replace an oversized result with its reduction |
|
|
13
|
+
* | `tools/post-execute` | `gate` | turn a repeated failure into corrective feedback |
|
|
14
|
+
* | `agent/pre-step` | `stagnation` | attach the correction to the next step |
|
|
15
|
+
* | `agent/turn-stopping` | `closing` | object to a turn closing on contradicted evidence |
|
|
16
|
+
*
|
|
17
|
+
* ## The three-state discipline
|
|
18
|
+
*
|
|
19
|
+
* Every capability runs in one of three modes. The distinction is *not* "on/off
|
|
20
|
+
* with logging": `observe` runs the same detection, the same judgment, and the
|
|
21
|
+
* same plan as `active`, and withholds only the application. That is what makes
|
|
22
|
+
* the mode worth having — what observe measures is exactly what active would
|
|
23
|
+
* have done, on the same payloads, at the same cost.
|
|
24
|
+
*
|
|
25
|
+
* | Mode | Detection | Judgment | Application | Model-visible change |
|
|
26
|
+
* | --- | --- | --- | --- | --- |
|
|
27
|
+
* | `off` | none | none | none | none |
|
|
28
|
+
* | `observe` | full | full | none | **none at all** |
|
|
29
|
+
* | `active` | full | full | full | the planned text |
|
|
30
|
+
*
|
|
31
|
+
* `observe` is therefore *not* the reference plugin's shadow mode: that one
|
|
32
|
+
* injects a model-visible notice saying it changed nothing. Here an observation
|
|
33
|
+
* has no model-visible surface whatsoever — no message, no rewritten content, no
|
|
34
|
+
* denial, no steering. The one thing it produces is an audit record in the
|
|
35
|
+
* session log, which the model cannot read.
|
|
36
|
+
*
|
|
37
|
+
* ## Cost discipline
|
|
38
|
+
*
|
|
39
|
+
* A deterministic, local pre-trigger decides whether a *judgment* may be spent
|
|
40
|
+
* at all, and judgments are budgeted per turn and per session: at most
|
|
41
|
+
* {@link ResolvedInterventionsConfig.maxJudgmentsPerTurn} per turn and
|
|
42
|
+
* {@link ResolvedInterventionsConfig.maxJudgmentsPerSession} per agent, with one
|
|
43
|
+
* verdict reused by every hook of the same turn. A turn presenting twenty
|
|
44
|
+
* similar results therefore costs one judgment, not twenty. Applied
|
|
45
|
+
* interventions carry their own ceiling, so an intervention can never become the
|
|
46
|
+
* loop it was meant to break.
|
|
47
|
+
*
|
|
48
|
+
* ## Fail-open and isolation
|
|
49
|
+
*
|
|
50
|
+
* Every hook delegates first (`await next()`), and every planning step is
|
|
51
|
+
* wrapped: an exception, an aborted signal, or an unusable verdict leaves the
|
|
52
|
+
* call, the result, the messages, and the turn exactly as the rest of the
|
|
53
|
+
* waterfall left them. Detection state is keyed by agent id, so two agents in one
|
|
54
|
+
* process can never see each other's history, verdicts, or budgets. Nothing here
|
|
55
|
+
* grants a permission the Host would not have granted, and nothing here overrides
|
|
56
|
+
* one either: a call the rest of the waterfall denied, cancelled, or routed to an
|
|
57
|
+
* approval flow is returned untouched, so the only decision this module can add
|
|
58
|
+
* is a strictly narrower one on top of a plain `allow`.
|
|
59
|
+
*
|
|
60
|
+
* ## Retained originals
|
|
61
|
+
*
|
|
62
|
+
* A reduction is installed only after the bytes it replaces have been retained
|
|
63
|
+
* in the agent's own Session log, in the plugin-record channel the audit trail
|
|
64
|
+
* already uses. The replacement publishes a locator derived from the payload's
|
|
65
|
+
* digest, a reader resolves it back to the verbatim original, and a payload that
|
|
66
|
+
* cannot be retained — too large, no session, a log that did not commit — is
|
|
67
|
+
* never replaced: `saved` is reported only for a replacement that really
|
|
68
|
+
* happened and can really be checked.
|
|
69
|
+
*
|
|
70
|
+
* @module dsh-reflex/interventions
|
|
71
|
+
*/
|
|
1
72
|
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
-
import type {
|
|
73
|
+
import type { ContextFormed, UserMessage } from '@deepseek-ai/dsh-llm';
|
|
3
74
|
import type { PreStepDecision } from '@deepseek-ai/dsh-agent';
|
|
4
75
|
import type { PostToolDecision, PreToolDecision, ToolExecution, ToolExecutionResult } from '@deepseek-ai/dsh-tools';
|
|
5
76
|
import { type InterventionCapability, type InterventionMode, type ResolvedInterventionsConfig } from './config.js';
|
|
6
77
|
import { appendInterventionRecord, type InterventionAuditRecord } from './session-audit.js';
|
|
7
78
|
import type { ReflexGateService, StagnationDetector, ToolResultPruner } from './vendor/harness-reflex/index.js';
|
|
79
|
+
import type { Attribution } from './attribution.js';
|
|
80
|
+
import { type InterventionCostBucket, type ObservedStep } from './vendor/harness-reflex/core/judge.js';
|
|
81
|
+
export { claimCandidates } from './vendor/harness-reflex/core/closing.js';
|
|
82
|
+
export { assembleEvidence, evidenceOf, FAILURE_MARKER, failureOf } from './vendor/harness-reflex/core/evidence.js';
|
|
83
|
+
export { countTrailingFailures, countTrailingRepeats, detectOscillation, suspicionOf } from './vendor/harness-reflex/core/judge.js';
|
|
84
|
+
export { applyPruneFloor, pruneFloorPlan, pruneMarker } from './vendor/harness-reflex/core/prune-plan.js';
|
|
85
|
+
export { digestOf, estimateTokens, textOfContent } from './vendor/harness-reflex/core/text.js';
|
|
86
|
+
export type { EvidenceEntry, EvidencePriority } from './vendor/harness-reflex/core/evidence.js';
|
|
87
|
+
export type { InterventionCostBucket } from './vendor/harness-reflex/core/judge.js';
|
|
88
|
+
export type { PruneFloorOptions, PruneFloorPlan } from './vendor/harness-reflex/core/prune-plan.js';
|
|
8
89
|
/**
|
|
9
90
|
* Producer-owned source kind of every message this plugin appends.
|
|
10
91
|
*
|
|
@@ -21,13 +102,6 @@ declare module '@deepseek-ai/dsh-llm' {
|
|
|
21
102
|
} & ContextFormed;
|
|
22
103
|
}
|
|
23
104
|
}
|
|
24
|
-
/**
|
|
25
|
-
* Matches the failure markers that make a result a *candidate* for the closing
|
|
26
|
-
* evidence. A hit is a safety floor: the line is kept whatever the budget says.
|
|
27
|
-
* A miss is never a "failure-free" conclusion — the tail summary goes to System
|
|
28
|
-
* One, which decides what the result means.
|
|
29
|
-
*/
|
|
30
|
-
export declare const FAILURE_MARKER: RegExp;
|
|
31
105
|
/** The action names one plan may carry. */
|
|
32
106
|
export type InterventionAction = 'deny-call' | 'prune-result' | 'corrective-feedback' | 'corrective-context' | 'steer-closing';
|
|
33
107
|
/**
|
|
@@ -199,47 +273,6 @@ export declare function waitGoalOf(exec: ToolExecution, shape: string, repeats:
|
|
|
199
273
|
* @returns a copy with `[poll #n]` appended to each poll's input.
|
|
200
274
|
*/
|
|
201
275
|
export declare function annotateWaitHistory(steps: readonly ObservedStep[], signature: string): ObservedStep[];
|
|
202
|
-
/** One step of one agent's detection window. */
|
|
203
|
-
interface ObservedStep {
|
|
204
|
-
/** `tool:argumentsDigest` — the identity a repetition is measured on. */
|
|
205
|
-
signature: string;
|
|
206
|
-
tool: string;
|
|
207
|
-
input: string;
|
|
208
|
-
output: string;
|
|
209
|
-
error: string;
|
|
210
|
-
failed: boolean;
|
|
211
|
-
turn: number;
|
|
212
|
-
at: number;
|
|
213
|
-
/** Whether the step was a legitimate wait query (see {@link isWaitQuery}). */
|
|
214
|
-
wait?: boolean;
|
|
215
|
-
}
|
|
216
|
-
/** One token and latency account of a mode or a capability. */
|
|
217
|
-
export interface InterventionCostBucket {
|
|
218
|
-
/** Decisions planned. */
|
|
219
|
-
plans: number;
|
|
220
|
-
/** Decisions whose plan was executed. */
|
|
221
|
-
applied: number;
|
|
222
|
-
/** System 1 judgments paid for. */
|
|
223
|
-
judgments: number;
|
|
224
|
-
/** Judgments served from the per-turn verdict memo instead of a new call. */
|
|
225
|
-
memoHits: number;
|
|
226
|
-
/** Milliseconds spent in local, deterministic work. */
|
|
227
|
-
localLatencyMs: number;
|
|
228
|
-
/** Milliseconds spent waiting for System 1. */
|
|
229
|
-
remoteLatencyMs: number;
|
|
230
|
-
/** Tokens the judgments reasoned about. */
|
|
231
|
-
judgeTokens: number;
|
|
232
|
-
/** Tokens of the payloads decisions were made about. */
|
|
233
|
-
originalTokens: number;
|
|
234
|
-
/** Tokens the candidates would carry. */
|
|
235
|
-
candidateTokens: number;
|
|
236
|
-
/** Tokens the candidates would have saved. */
|
|
237
|
-
potentialSavedTokens: number;
|
|
238
|
-
/** Tokens actually removed from the model-visible surface. */
|
|
239
|
-
actualSavedTokens: number;
|
|
240
|
-
/** Tokens actually added to the model-visible surface. */
|
|
241
|
-
injectedTokens: number;
|
|
242
|
-
}
|
|
243
276
|
/** The baseline side of the accounting: what the hooks were shown, untouched. */
|
|
244
277
|
export interface InterventionBaseline {
|
|
245
278
|
/** Results the post-execute hook was shown. */
|
|
@@ -294,6 +327,22 @@ export interface InterventionEngineOptions {
|
|
|
294
327
|
prune: Pick<ToolResultPruner, 'prune'>;
|
|
295
328
|
/** Verification plus the closing-claim classification that precedes it. */
|
|
296
329
|
gate: Pick<ReflexGateService, 'verify' | 'classifyClaims'>;
|
|
330
|
+
/**
|
|
331
|
+
* Run one outbound decision inside the runtime's per-call attribution.
|
|
332
|
+
*
|
|
333
|
+
* The engine spends real System One judgments at Host hook points, and g-068
|
|
334
|
+
* requires every such call to be attributed on the ledger and in any payload
|
|
335
|
+
* it returns. Absent for a bare construction (a test, an embedding Host), in
|
|
336
|
+
* which case the call runs as it always did; the ledger then records it as
|
|
337
|
+
* `unknown` rather than letting it read as a remote success.
|
|
338
|
+
*/
|
|
339
|
+
attribute?: <T>(run: () => Promise<T>, options: {
|
|
340
|
+
answered(value: T): boolean;
|
|
341
|
+
localFallback?: (value: T) => boolean;
|
|
342
|
+
}) => Promise<{
|
|
343
|
+
result: T;
|
|
344
|
+
attribution: Attribution;
|
|
345
|
+
}>;
|
|
297
346
|
/** Names of this plugin's own tools: their output is already optimized. */
|
|
298
347
|
ownTools?: readonly string[];
|
|
299
348
|
/** Clock seam. */
|
|
@@ -311,301 +360,6 @@ export interface InterventionEngineOptions {
|
|
|
311
360
|
/** Audit sink; the plugin attaches the session log here. */
|
|
312
361
|
audit?: (record: InterventionAuditRecord, session: unknown) => void;
|
|
313
362
|
}
|
|
314
|
-
/**
|
|
315
|
-
* Tokens one text costs, at the ledger's shared four-characters-per-token rate.
|
|
316
|
-
* @param text - any text.
|
|
317
|
-
* @returns the estimated token count.
|
|
318
|
-
*/
|
|
319
|
-
export declare function estimateTokens(text: string): number;
|
|
320
|
-
/**
|
|
321
|
-
* Stable short digest of one value, used as a tool-call identity.
|
|
322
|
-
* @param value - the text to digest.
|
|
323
|
-
* @returns sixteen hexadecimal characters.
|
|
324
|
-
*/
|
|
325
|
-
export declare function digestOf(value: string): string;
|
|
326
|
-
/**
|
|
327
|
-
* Concatenate the text blocks of one content list.
|
|
328
|
-
* @param content - message or result content.
|
|
329
|
-
* @returns the text, in block order.
|
|
330
|
-
*/
|
|
331
|
-
export declare function textOfContent(content: readonly ContentBlock[] | undefined): string;
|
|
332
|
-
/**
|
|
333
|
-
* Whether one content list carries at least one text block.
|
|
334
|
-
* @param content - message or result content.
|
|
335
|
-
* @returns whether there is text to rewrite.
|
|
336
|
-
*/
|
|
337
|
-
export declare function hasTextBlock(content: readonly ContentBlock[] | undefined): boolean;
|
|
338
|
-
/**
|
|
339
|
-
* The exit status one tool result carries in its own canonical value.
|
|
340
|
-
*
|
|
341
|
-
* A shell result is *reported*, not errored: a command that exits 1 returns a
|
|
342
|
-
* successful `ToolExecutionResult` whose `value.exitCode` is the whole truth. The
|
|
343
|
-
* distinction matters twice over — a correction that never fires because the
|
|
344
|
-
* failure looked like a success, and a closing check that reads a green claim
|
|
345
|
-
* over a red build — so the status is taken from the tool's own structured field
|
|
346
|
-
* whenever the payload exposes one.
|
|
347
|
-
*
|
|
348
|
-
* @param value - the result's canonical value, when it has one.
|
|
349
|
-
* @returns the exit status, or `undefined` when the value is not a shell result.
|
|
350
|
-
*/
|
|
351
|
-
export declare function structuredExitStatus(value: unknown): {
|
|
352
|
-
exitCode: number;
|
|
353
|
-
signal?: string;
|
|
354
|
-
} | undefined;
|
|
355
|
-
/**
|
|
356
|
-
* Whether the text ends in the Host's own exit marker for a failed command.
|
|
357
|
-
*
|
|
358
|
-
* The marker is the last line of the model-facing content, so anchoring it to the
|
|
359
|
-
* end of the text keeps an *ordinary* result that merely mentions "exit code 1"
|
|
360
|
-
* in its body from being misread as a failure. This is the fallback for a result
|
|
361
|
-
* that carries no structured value — a Virtual tool, a replay from an older
|
|
362
|
-
* record — not a replacement for {@link structuredExitStatus}.
|
|
363
|
-
* @param text - the model-facing text.
|
|
364
|
-
* @returns whether the last marker line reports a non-zero exit or a signal.
|
|
365
|
-
*/
|
|
366
|
-
export declare function exitMarkerFailure(text: string): boolean;
|
|
367
|
-
/**
|
|
368
|
-
* Whether one result is a failure the interventions may act on.
|
|
369
|
-
*
|
|
370
|
-
* Three sources, in order of authority: the Host's own `isError` flag, the exit
|
|
371
|
-
* status inside the tool's structured value, and the exit marker the Host appends
|
|
372
|
-
* to the text. A text heuristic over words like "failed" is deliberately absent:
|
|
373
|
-
* a test log that prints the word is not a failing command, and treating it as
|
|
374
|
-
* one would both spend a judgment on it and block a legitimate retry.
|
|
375
|
-
*
|
|
376
|
-
* @param result - the execution-local result.
|
|
377
|
-
* @param text - the effective model-facing text of that result.
|
|
378
|
-
* @returns whether the result proves a failure.
|
|
379
|
-
*/
|
|
380
|
-
export declare function failureOf(result: Readonly<ToolExecutionResult> | undefined, text: string): boolean;
|
|
381
|
-
/**
|
|
382
|
-
* Priority of one closing-evidence candidate when the budget truncates.
|
|
383
|
-
*
|
|
384
|
-
* `diagnostic` lines are the safety floor: a FAILURE_MARKER hit is kept even
|
|
385
|
-
* past the budget. `tail` summaries carry the structured/status facts of every
|
|
386
|
-
* observed result (so `{ok:false}`, a timeout, or a Chinese error reaches System
|
|
387
|
-
* One). `other` is the head fallback, dropped first.
|
|
388
|
-
*/
|
|
389
|
-
export type EvidencePriority = 'diagnostic' | 'tail' | 'other';
|
|
390
|
-
/** One candidate the closing judgment may read. */
|
|
391
|
-
export interface EvidenceEntry {
|
|
392
|
-
/** Tool that produced the result. */
|
|
393
|
-
tool: string;
|
|
394
|
-
/** Bounded line or summary. */
|
|
395
|
-
text: string;
|
|
396
|
-
/** Truncation priority (lower is safer). */
|
|
397
|
-
priority: EvidencePriority;
|
|
398
|
-
/** Whether the result behind this entry is a failure suspicion. */
|
|
399
|
-
suspect: boolean;
|
|
400
|
-
}
|
|
401
|
-
/**
|
|
402
|
-
* Turn one observed result into closing-evidence candidates.
|
|
403
|
-
*
|
|
404
|
-
* The regex is a prefilter and a floor, never a conclusion: matching lines are
|
|
405
|
-
* kept whatever else happens, and a non-matching result still contributes its
|
|
406
|
-
* tail summary (with the structured facts) to System One. A result is a failure
|
|
407
|
-
* *suspicion* when a structured fact, a marker line, or a broader cue says so;
|
|
408
|
-
* what the result really means is decided by `gate.verify`.
|
|
409
|
-
*
|
|
410
|
-
* @param tool - tool name that produced the result.
|
|
411
|
-
* @param result - the execution-local result.
|
|
412
|
-
* @param text - the effective model-facing text.
|
|
413
|
-
* @returns bounded candidates, diagnostics first.
|
|
414
|
-
*/
|
|
415
|
-
export declare function evidenceOf(tool: string, result: Readonly<ToolExecutionResult> | undefined, text: string): EvidenceEntry[];
|
|
416
|
-
/**
|
|
417
|
-
* Assemble the turn's evidence candidates into one budgeted string.
|
|
418
|
-
*
|
|
419
|
-
* Priority order is diagnostic → tail → other. A diagnostic line is the safety
|
|
420
|
-
* floor and is never dropped; everything else competes for the budget and the
|
|
421
|
-
* dropped characters are reported so the truncation is auditable.
|
|
422
|
-
*
|
|
423
|
-
* @param entries - candidates, oldest first.
|
|
424
|
-
* @param budget - character budget of the assembled text.
|
|
425
|
-
* @returns assembled text plus the kept/dropped character counts.
|
|
426
|
-
*/
|
|
427
|
-
export declare function assembleEvidence(entries: readonly EvidenceEntry[], budget: number): {
|
|
428
|
-
text: string;
|
|
429
|
-
retainedChars: number;
|
|
430
|
-
truncatedChars: number;
|
|
431
|
-
};
|
|
432
|
-
/**
|
|
433
|
-
* The floor decision of one reduction, computed from lengths alone.
|
|
434
|
-
*
|
|
435
|
-
* {@link pruneFloorPlan} returns the *decision*: whether the floor applies and
|
|
436
|
-
* the size that decision was modelled on. {@link applyPruneFloor} returns the
|
|
437
|
-
* same decision next to the size the composed text *really* has, because line
|
|
438
|
-
* alignment and duplicate removal move that size. Callers account for the text
|
|
439
|
-
* a mode really installs, so the composed numbers are the authoritative ones.
|
|
440
|
-
*/
|
|
441
|
-
export interface PruneFloorPlan {
|
|
442
|
-
/** Whether the floor form replaces the judged candidate. */
|
|
443
|
-
floored: boolean;
|
|
444
|
-
/**
|
|
445
|
-
* Whether the installed reduction fell short of the floor's promised share.
|
|
446
|
-
*
|
|
447
|
-
* True exactly when the composition could not build a form that both carries
|
|
448
|
-
* `floorRatio` of the original and stays smaller than it, so the judged
|
|
449
|
-
* candidate itself was installed. It is what separates "nothing was reduced"
|
|
450
|
-
* from "the reduction was real, but it did not reach the floor's promise"; a
|
|
451
|
-
* plan that never needed the floor reports `false`.
|
|
452
|
-
*/
|
|
453
|
-
floorMissed: boolean;
|
|
454
|
-
/** Characters the installed text carries: modelled by the plan, real once composed. */
|
|
455
|
-
resultChars: number;
|
|
456
|
-
/** Characters the installed form does not carry. */
|
|
457
|
-
omittedChars: number;
|
|
458
|
-
/** Context characters taken from the head of the original. */
|
|
459
|
-
headChars: number;
|
|
460
|
-
/** Context characters taken from the tail of the original. */
|
|
461
|
-
tailChars: number;
|
|
462
|
-
/**
|
|
463
|
-
* Marker characters the installed form carries, summed over its sides.
|
|
464
|
-
*
|
|
465
|
-
* Zero when nothing is floored, one marker when only the mandatory locator side
|
|
466
|
-
* fits, two when the share's budget can pay for a matching marker after the
|
|
467
|
-
* candidate. Publishing it is what lets {@link applyPruneFloor} rebuild exactly
|
|
468
|
-
* the form whose size the plan promised.
|
|
469
|
-
*/
|
|
470
|
-
markerChars: number;
|
|
471
|
-
/**
|
|
472
|
-
* Whether a floor-missed install wanted the locator marker but could not carry it.
|
|
473
|
-
*
|
|
474
|
-
* The marker is what tells a reader that the reduction happened and where the
|
|
475
|
-
* full payload lives, so a candidate that fits only *without* it is still
|
|
476
|
-
* installed — the reduction is real — but the omission is recorded instead of
|
|
477
|
-
* being silently dropped. Always `false` when `floorMissed` is false.
|
|
478
|
-
*/
|
|
479
|
-
markerOmitted: boolean;
|
|
480
|
-
}
|
|
481
|
-
/** The floor options shared by the plan and the composition. */
|
|
482
|
-
export interface PruneFloorOptions {
|
|
483
|
-
/** Lowest share of the original a reduction may keep. */
|
|
484
|
-
floorRatio: number;
|
|
485
|
-
/** Default split of the context budget, in characters. */
|
|
486
|
-
headChars?: number;
|
|
487
|
-
/** Default split of the context budget, in characters. */
|
|
488
|
-
tailChars?: number;
|
|
489
|
-
/**
|
|
490
|
-
* Length of the marker the installed form carries per side.
|
|
491
|
-
*
|
|
492
|
-
* A caller that composes a locator-carrying form passes the real marker
|
|
493
|
-
* length here; a caller that only accounts for it passes the same number. That
|
|
494
|
-
* is what keeps the predicted size and the installed size identical in both
|
|
495
|
-
* modes.
|
|
496
|
-
*/
|
|
497
|
-
markerChars?: number;
|
|
498
|
-
}
|
|
499
|
-
/**
|
|
500
|
-
* Decide the deterministic floor of one reduction from lengths alone.
|
|
501
|
-
*
|
|
502
|
-
* Lengths are enough because the floor form is fixed: context, marker, candidate,
|
|
503
|
-
* marker, context. Deciding it this way is what lets `observe` account for the
|
|
504
|
-
* *same* candidate `active` would install without building it.
|
|
505
|
-
*
|
|
506
|
-
* The floor is a *share*, not a suggestion. `pruneFloorRatio` says how much of
|
|
507
|
-
* the original must survive, so the context budget is derived from it rather than
|
|
508
|
-
* capped by the head/tail hints: a candidate that keeps 8% of a long payload is
|
|
509
|
-
* not "floored" to 8% plus two small slices, it is widened until the installed
|
|
510
|
-
* form really carries the promised share. The head/tail hints only decide how
|
|
511
|
-
* that budget is split. A plan that cannot reach the share — because the marker
|
|
512
|
-
* alone would eat the whole allowance — is refused, so a reduction never grows
|
|
513
|
-
* the context.
|
|
514
|
-
*
|
|
515
|
-
* @param originalChars - length of the raw payload.
|
|
516
|
-
* @param candidateChars - length of the judged candidate.
|
|
517
|
-
* @param options - floor ratio, split hints, and marker length.
|
|
518
|
-
* @returns the floor decision.
|
|
519
|
-
*/
|
|
520
|
-
export declare function pruneFloorPlan(originalChars: number, candidateChars: number, options: PruneFloorOptions): PruneFloorPlan;
|
|
521
|
-
/** The marker one floored reduction carries on each side of its candidate. */
|
|
522
|
-
export declare function pruneMarker(locator: string): string;
|
|
523
|
-
/**
|
|
524
|
-
* Enforce the deterministic floor of a judged reduction.
|
|
525
|
-
*
|
|
526
|
-
* The judgment proposes; this floor disposes. A candidate that cut deeper than
|
|
527
|
-
* {@link ResolvedInterventionsConfig.pruneFloorRatio} of the original is replaced
|
|
528
|
-
* by a form that keeps the head and the tail — the two places a compiler error, a
|
|
529
|
-
* stack-trace summary, and a final result usually are — around the judgment's own
|
|
530
|
-
* extract, with explicit markers that name where the full original was retained.
|
|
531
|
-
* A candidate that is not actually smaller is refused outright, so a "reduction"
|
|
532
|
-
* can never grow the context.
|
|
533
|
-
*
|
|
534
|
-
* The context is composed out of *whole lines* of the original, never out of
|
|
535
|
-
* character slices: a cut that lands mid-line leaves the reader a fragment like
|
|
536
|
-
* `=] progress 092`, which is not a shorter answer but a broken one. The head is
|
|
537
|
-
* the longest run of complete lines its budget can pay for, the tail the shortest
|
|
538
|
-
* run of complete lines that still carries its own, and any candidate line the
|
|
539
|
-
* kept context already shows verbatim is dropped as a duplicate. Alignment and
|
|
540
|
-
* removal move the real size, so the decision's modelled size is replaced here by
|
|
541
|
-
* the size the text really has: a form that would fall short of the promised
|
|
542
|
-
* share, or that would not be smaller than the original at all, is refused. A
|
|
543
|
-
* refusal installs the judgment's own candidate with `floorMissed: true` rather
|
|
544
|
-
* than the original — the candidate is a real reduction, and dropping it would
|
|
545
|
-
* trade a smaller answer for the whole payload just because the floor form could
|
|
546
|
-
* not be built.
|
|
547
|
-
*
|
|
548
|
-
* @param original - the raw payload.
|
|
549
|
-
* @param candidate - the judged reduction.
|
|
550
|
-
* @param options - floor options plus the locator the replacement publishes.
|
|
551
|
-
* @returns the text to install, the floor decision, and the sizes involved.
|
|
552
|
-
*/
|
|
553
|
-
export declare function applyPruneFloor(original: string, candidate: string, options: PruneFloorOptions & {
|
|
554
|
-
locator: string;
|
|
555
|
-
}): PruneFloorPlan & {
|
|
556
|
-
text: string;
|
|
557
|
-
};
|
|
558
|
-
/**
|
|
559
|
-
* Count the identical trailing repeats of one signature.
|
|
560
|
-
* @param steps - observed steps, oldest first.
|
|
561
|
-
* @param signature - the identity to count.
|
|
562
|
-
* @returns the length of the trailing run of that signature.
|
|
563
|
-
*/
|
|
564
|
-
export declare function countTrailingRepeats(steps: readonly ObservedStep[], signature: string): number;
|
|
565
|
-
/**
|
|
566
|
-
* Count the trailing consecutive failures.
|
|
567
|
-
* @param steps - observed steps, oldest first.
|
|
568
|
-
* @returns the length of the trailing run of failing steps.
|
|
569
|
-
*/
|
|
570
|
-
export declare function countTrailingFailures(steps: readonly ObservedStep[]): number;
|
|
571
|
-
/**
|
|
572
|
-
* Whether the window's tail alternates between exactly two call identities.
|
|
573
|
-
*
|
|
574
|
-
* `A B A B` is the cheapest loop to miss and among the most wasteful to run:
|
|
575
|
-
* neither call repeats consecutively, so a consecutive-repeat trigger never
|
|
576
|
-
* fires.
|
|
577
|
-
* @param steps - observed steps, oldest first.
|
|
578
|
-
* @param window - how many trailing steps to inspect.
|
|
579
|
-
* @returns whether the tail oscillates.
|
|
580
|
-
*/
|
|
581
|
-
export declare function detectOscillation(steps: readonly ObservedStep[], window: number): boolean;
|
|
582
|
-
/** Why a deterministic pre-trigger wants a judgment. */
|
|
583
|
-
export interface StagnationSuspicion {
|
|
584
|
-
suspicious: boolean;
|
|
585
|
-
/** The pattern the trigger suspects, before System 1 confirms it. */
|
|
586
|
-
pattern?: 'repetition' | 'oscillation' | 'failing_retry';
|
|
587
|
-
/** Human-readable trigger facts, for the audit record. */
|
|
588
|
-
note: string;
|
|
589
|
-
/** How many steps the pattern was measured on. */
|
|
590
|
-
repeats: number;
|
|
591
|
-
}
|
|
592
|
-
/**
|
|
593
|
-
* Decide, locally and deterministically, whether a judgment is worth spending.
|
|
594
|
-
*
|
|
595
|
-
* This is the cost gate of the whole module: the expensive path is a System 1
|
|
596
|
-
* call, and it only opens when the *cheap* path already sees a pattern. A single
|
|
597
|
-
* distinctive call is never judged, however large its output.
|
|
598
|
-
*
|
|
599
|
-
* @param steps - observed steps, oldest first.
|
|
600
|
-
* @param options - thresholds, window, and the current call identity.
|
|
601
|
-
* @returns the suspicion, with `suspicious: false` when nothing justifies a call.
|
|
602
|
-
*/
|
|
603
|
-
export declare function suspicionOf(steps: readonly ObservedStep[], options: {
|
|
604
|
-
repeatThreshold: number;
|
|
605
|
-
failureThreshold: number;
|
|
606
|
-
window: number;
|
|
607
|
-
signature: string;
|
|
608
|
-
}): StagnationSuspicion;
|
|
609
363
|
/**
|
|
610
364
|
* What the engine hands its retention sink before it replaces a payload.
|
|
611
365
|
*
|
|
@@ -706,22 +460,6 @@ export declare class InterventionEngine {
|
|
|
706
460
|
forget(agentId: string): void;
|
|
707
461
|
/** Drop every agent's state and every account, for a fresh measurement. */
|
|
708
462
|
reset(): void;
|
|
709
|
-
/**
|
|
710
|
-
* `tools/pre-execute`: refuse a call the run is repeating.
|
|
711
|
-
*
|
|
712
|
-
* Delegates first and returns the downstream decision **by identity** whenever
|
|
713
|
-
* that decision is not a plain `allow`. A later listener may already have sent
|
|
714
|
-
* the call to an approval flow, denied it with its own structured error
|
|
715
|
-
* identity, or cancelled it; overwriting any of those would drop information the
|
|
716
|
-
* Host attached and could turn a stricter decision into a weaker one. The only
|
|
717
|
-
* decision this hook ever *adds* is a `deny` on top of an `allow`, which is
|
|
718
|
-
* strictly narrower than what the waterfall already permitted — permissions
|
|
719
|
-
* here are monotone by construction, never escalated and never relaxed.
|
|
720
|
-
*
|
|
721
|
-
* @param exec - the tool call about to run.
|
|
722
|
-
* @param next - the rest of the waterfall.
|
|
723
|
-
* @returns the decision the Host dispatches on.
|
|
724
|
-
*/
|
|
725
463
|
toolCall(exec: ToolExecution, next: () => Promise<PreToolDecision>): Promise<PreToolDecision>;
|
|
726
464
|
/**
|
|
727
465
|
* `tools/post-execute`: reduce an oversized result, or correct a repeated
|
|
@@ -861,17 +599,4 @@ export declare function sessionOf(value: unknown): unknown;
|
|
|
861
599
|
* @returns the session identity, or the agent's own key when it has none.
|
|
862
600
|
*/
|
|
863
601
|
export declare function sessionKeyOf(value: unknown): string;
|
|
864
|
-
/**
|
|
865
|
-
* The *candidate* sentences of one turn's assistant text.
|
|
866
|
-
*
|
|
867
|
-
* Deterministic and semantic-free on purpose: splitting, de-duplication, the
|
|
868
|
-
* length floor, and the last-{@link MAX_CLAIMS} bound are all the local work
|
|
869
|
-
* this module may do. Whether a candidate really claims completion is System
|
|
870
|
-
* One's answer — an English word list would miss 中文「全部通过」 and read
|
|
871
|
-
* `not complete` as the opposite, so there is none here any more.
|
|
872
|
-
*
|
|
873
|
-
* @param text - the turn's assistant text.
|
|
874
|
-
* @returns bounded, deduplicated candidates in their original order.
|
|
875
|
-
*/
|
|
876
|
-
export declare function claimCandidates(text: string): string[];
|
|
877
602
|
export { appendInterventionRecord };
|