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
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shared orchestration of one judged reduction.
|
|
3
|
+
*
|
|
4
|
+
* This module owns *when and in what order* a pruning decision is made; it does
|
|
5
|
+
* not own any of the host facts that decision is made of. It was lifted verbatim
|
|
6
|
+
* in behaviour from the DSH engine's private prune branch so that a second host
|
|
7
|
+
* can reuse it, and it is written as a pure function over a port so that the
|
|
8
|
+
* order — which is a safety property, not a style — is stated in exactly one
|
|
9
|
+
* place:
|
|
10
|
+
*
|
|
11
|
+
* ```
|
|
12
|
+
* refuse off / downstream-blocked / value-shaped
|
|
13
|
+
* → refuse payloads that are not line-oriented output
|
|
14
|
+
* → refuse payloads too large to retain
|
|
15
|
+
* → refuse when no retention sink exists
|
|
16
|
+
* → refuse when the turn's action allowance is spent
|
|
17
|
+
* → buy a judgment (memo first), refuse when the judgment budget is spent
|
|
18
|
+
* → compose the floored candidate, refuse when it is not smaller
|
|
19
|
+
* → [observe: record the plan and stop]
|
|
20
|
+
* → retain the original, refuse when no verifiable copy exists
|
|
21
|
+
* → compose against the real locator, refuse when the result is not smaller
|
|
22
|
+
* → ask the host to install it, refuse when there is no text block
|
|
23
|
+
* → only now record the saving
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* Every "refuse" returns the downstream decision untouched and reports why. A
|
|
27
|
+
* reduction that cannot be verified can therefore never be reported as applied.
|
|
28
|
+
*
|
|
29
|
+
* ## What is shared and what is not
|
|
30
|
+
*
|
|
31
|
+
* Shared here: the order above, every skip reason, the budget rules (which
|
|
32
|
+
* counter moves when), the size arithmetic, the memo semantics, and the shape of
|
|
33
|
+
* the audit detail. *Not* shared here: how a candidate is obtained (the host's
|
|
34
|
+
* judge), how an original is retained (the host's sink, whose locator differs per
|
|
35
|
+
* host), how text is installed into a host content type, and how the operator-
|
|
36
|
+
* facing note is worded (that is a product decision per host).
|
|
37
|
+
*
|
|
38
|
+
* ## Why the port rather than callback arguments
|
|
39
|
+
*
|
|
40
|
+
* The DSH engine and the Claude hook disagree about nearly every *fact* and
|
|
41
|
+
* about none of the *rules*. A port keeps the rules in one file and lets each
|
|
42
|
+
* host answer only the questions it alone can answer. `HostPrunePort` is
|
|
43
|
+
* deliberately total: there is no optional method, so a host that cannot retain
|
|
44
|
+
* an original says so once, up front, instead of the shared layer guessing from
|
|
45
|
+
* an absent callback.
|
|
46
|
+
*
|
|
47
|
+
* @module core/orchestrate
|
|
48
|
+
*/
|
|
49
|
+
import type { HostDecisionPort, JudgmentState } from './orchestrate-host.js';
|
|
50
|
+
import { type TextBlockLike } from './text.js';
|
|
51
|
+
/** Line breaks a payload needs before it is treated as line-oriented output. */
|
|
52
|
+
export declare const PRUNE_MIN_LINES = 4;
|
|
53
|
+
/**
|
|
54
|
+
* Largest payload the shared layer is willing to see copied into a host log.
|
|
55
|
+
*
|
|
56
|
+
* Retention is what makes a reduction safe, so this is a *precondition* of
|
|
57
|
+
* pruning rather than a fallback: above it the decision reports
|
|
58
|
+
* `retention-too-large` and leaves the result untouched, so an oversized payload
|
|
59
|
+
* can never be reported as saved on the strength of a copy that was never kept.
|
|
60
|
+
*/
|
|
61
|
+
export declare const MAX_RETAINED_CHARS = 100000;
|
|
62
|
+
/** Characters of a reduction's explanatory note. */
|
|
63
|
+
export declare const PRUNE_FEEDBACK_CHARS = 600;
|
|
64
|
+
/** The floor options a reduction is composed with. */
|
|
65
|
+
export interface PruneFloorSettings {
|
|
66
|
+
/** Lowest share of the original a reduction may keep. */
|
|
67
|
+
readonly floorRatio: number;
|
|
68
|
+
/** Default split of the context budget, taken from the head. */
|
|
69
|
+
readonly headChars: number;
|
|
70
|
+
/** Default split of the context budget, taken from the tail. */
|
|
71
|
+
readonly tailChars: number;
|
|
72
|
+
}
|
|
73
|
+
/** The payload half of a prune decision's audit fields. */
|
|
74
|
+
export type PrunePayloadDetail = {
|
|
75
|
+
/** Payload identity, absent for an empty payload. */
|
|
76
|
+
readonly digest?: string;
|
|
77
|
+
/** Size of the payload the decision is about. */
|
|
78
|
+
readonly originalChars?: number;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* The payload half of a prune decision's audit fields.
|
|
82
|
+
*
|
|
83
|
+
* Taken before the service is asked, so a branch that refuses the payload early
|
|
84
|
+
* still names the payload it refused.
|
|
85
|
+
* @param text - the effective text the decision is about.
|
|
86
|
+
* @returns the digest and size, or nothing for an empty payload.
|
|
87
|
+
*/
|
|
88
|
+
export declare function prunePayloadDetail(text: string): PrunePayloadDetail;
|
|
89
|
+
/** What the judged candidate reports about its own path. */
|
|
90
|
+
export interface PruneDiagnostics {
|
|
91
|
+
readonly judgePath?: 'segmented' | 'local' | 'fallback';
|
|
92
|
+
readonly judgedSegments?: number;
|
|
93
|
+
readonly unjudgedSegments?: number;
|
|
94
|
+
readonly keptSegments?: number;
|
|
95
|
+
readonly aggressiveChars?: number;
|
|
96
|
+
readonly balancedChars?: number;
|
|
97
|
+
readonly conservativeChars?: number;
|
|
98
|
+
readonly scoredSegments?: number;
|
|
99
|
+
readonly autoKeptSegments?: number;
|
|
100
|
+
readonly unparsedScoreAnswers?: number;
|
|
101
|
+
readonly fallbackReason?: string;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The judgment half of a prune decision's audit fields.
|
|
105
|
+
*
|
|
106
|
+
* A pure pass-through of what the prune service computed, plus the two sizes
|
|
107
|
+
* every record quotes.
|
|
108
|
+
* @param response - the service's answer.
|
|
109
|
+
* @param originalTokens - tokens of the raw payload.
|
|
110
|
+
* @param candidateTokens - tokens of the composed candidate.
|
|
111
|
+
* @returns the diagnostics plus sizes.
|
|
112
|
+
*/
|
|
113
|
+
export declare function pruneDiagnosticsOf(response: PruneDiagnostics, originalTokens: number, candidateTokens: number): PruneDiagnostics & {
|
|
114
|
+
readonly originalTokens: number;
|
|
115
|
+
readonly candidateTokens: number;
|
|
116
|
+
};
|
|
117
|
+
/** One remembered reduction of one payload. */
|
|
118
|
+
export interface PruneMemoEntry {
|
|
119
|
+
/** The real reduction, absent until a mode computed it. */
|
|
120
|
+
readonly text?: string;
|
|
121
|
+
readonly originalChars: number;
|
|
122
|
+
readonly prunedChars: number;
|
|
123
|
+
readonly tokensSaved: number;
|
|
124
|
+
/** Whether the reduction was floored, so a memo hit reports the same plan. */
|
|
125
|
+
readonly floored: boolean;
|
|
126
|
+
/** Whether the reduction missed the floor's promised share, replayed on a hit. */
|
|
127
|
+
readonly floorMissed?: boolean;
|
|
128
|
+
/** Whether that miss installed without its locator marker, replayed on a hit. */
|
|
129
|
+
readonly markerOmitted?: boolean;
|
|
130
|
+
/** Locator of the retained original, once a retention for this payload succeeded. */
|
|
131
|
+
readonly locator?: string;
|
|
132
|
+
/** Diagnostics of the judgment that composed this form, replayed on a hit. */
|
|
133
|
+
readonly diagnostics?: PruneDiagnostics;
|
|
134
|
+
}
|
|
135
|
+
/** What the shared layer asks a host to retain before it replaces a payload. */
|
|
136
|
+
export interface PruneRetentionRequest {
|
|
137
|
+
/** Payload identity: `digestOf(text)`. */
|
|
138
|
+
readonly digest: string;
|
|
139
|
+
/** Identity of the call whose result is about to shrink. */
|
|
140
|
+
readonly callId: string;
|
|
141
|
+
/** Name of that call. */
|
|
142
|
+
readonly tool: string;
|
|
143
|
+
/** Turn and step of the replacement. */
|
|
144
|
+
readonly turn: number;
|
|
145
|
+
readonly step: number;
|
|
146
|
+
/** The replaced payload, verbatim. */
|
|
147
|
+
readonly text: string;
|
|
148
|
+
}
|
|
149
|
+
/** The controlled copy one retention produced. */
|
|
150
|
+
export interface PruneRetention {
|
|
151
|
+
/** Locator the replacement publishes. */
|
|
152
|
+
readonly locator: string;
|
|
153
|
+
/** Committed log position, when the sink can report one. */
|
|
154
|
+
readonly seq?: number;
|
|
155
|
+
}
|
|
156
|
+
/** The counters one reduction spends from, and where it is deciding. */
|
|
157
|
+
export type PruneState = JudgmentState;
|
|
158
|
+
/** A judged candidate, as the shared layer needs it. */
|
|
159
|
+
export interface PruneCandidate {
|
|
160
|
+
/** The candidate text the floor composes from. */
|
|
161
|
+
readonly processedOutput: string;
|
|
162
|
+
/** Reduction share the service reported, recorded as the plan's confidence. */
|
|
163
|
+
readonly reductionPercentage: number;
|
|
164
|
+
/** Whether the service withheld the text (measured but not returned). */
|
|
165
|
+
readonly shadow?: boolean;
|
|
166
|
+
/** Service latency, used to split local from remote time. */
|
|
167
|
+
readonly latencyMs: number;
|
|
168
|
+
/** Path diagnostics, recorded only. */
|
|
169
|
+
readonly diagnostics?: PruneDiagnostics;
|
|
170
|
+
}
|
|
171
|
+
/** The judgment cost of one decision. */
|
|
172
|
+
export interface PruneJudgmentCharge {
|
|
173
|
+
readonly judgments: number;
|
|
174
|
+
readonly memoHits: number;
|
|
175
|
+
readonly localLatencyMs: number;
|
|
176
|
+
readonly remoteLatencyMs: number;
|
|
177
|
+
readonly judgeTokens: number;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Everything the pruning decision cannot know by itself.
|
|
181
|
+
*
|
|
182
|
+
* {@link HostDecisionPort} answers the part every capability asks — policy,
|
|
183
|
+
* counters, billing channels — but this port departs from the base in two ways,
|
|
184
|
+
* and both are deliberate rather than pending:
|
|
185
|
+
*
|
|
186
|
+
* 1. **`skip` and `conclude` are wider here.** A pruning skip carries the
|
|
187
|
+
* payload diagnostics (`digest`, `floored`, the segment counts) that make
|
|
188
|
+
* "why was nothing pruned" answerable, and a pruning `conclude` carries the
|
|
189
|
+
* four size columns and the retained locator that make a saving verifiable.
|
|
190
|
+
* Narrowing either to the base signature would drop a field the audit trail
|
|
191
|
+
* is defined by, so this port overrides them with the wider shape.
|
|
192
|
+
* 2. **`now()` replaces `clock()`.** The pruning decision only ever needs one
|
|
193
|
+
* number, taken at hook entry; handing it a port for one reading would be a
|
|
194
|
+
* ceremony. The signature is structurally compatible with `ClockPort`, so a
|
|
195
|
+
* host can satisfy either reading from the same source.
|
|
196
|
+
*
|
|
197
|
+
* The rest — `serves()`, `budget()`, `chargeJudgment()` — keeps the base
|
|
198
|
+
* contract: `serves()` is answered from the effective mode, which this port
|
|
199
|
+
* already exposes as `mode()`.
|
|
200
|
+
*/
|
|
201
|
+
export interface HostPrunePort<Result> extends HostDecisionPort<PruneState> {
|
|
202
|
+
/** The effective mode of the `prune` capability. */
|
|
203
|
+
mode(): 'off' | 'observe' | 'active';
|
|
204
|
+
/** Whether the decision applies at all: the mode is not `off`. */
|
|
205
|
+
serves(): boolean;
|
|
206
|
+
/** Latest clock reading. Structurally the same reading `ClockPort` gives. */
|
|
207
|
+
now(): number;
|
|
208
|
+
/** Character count above which a payload is a pruning candidate. */
|
|
209
|
+
threshold(): number;
|
|
210
|
+
/** Floor settings in force. */
|
|
211
|
+
floor(): PruneFloorSettings;
|
|
212
|
+
/** The memo namespace of this agent's session. */
|
|
213
|
+
memoKey(): string;
|
|
214
|
+
/** One memoized reduction, refreshed on hit; `undefined` when not remembered. */
|
|
215
|
+
memoGet(key: string): PruneMemoEntry | undefined;
|
|
216
|
+
/** Remember one reduction. */
|
|
217
|
+
memoSet(key: string, entry: PruneMemoEntry): void;
|
|
218
|
+
/**
|
|
219
|
+
* The locator this host's sink *will* give a payload.
|
|
220
|
+
*
|
|
221
|
+
* The prediction exists so both modes account for the same form: the floor
|
|
222
|
+
* composes against a locator, and if the sink then names the copy differently
|
|
223
|
+
* the text has to be rebuilt and the plan no longer describes what is
|
|
224
|
+
* installed. Only the host knows its own naming scheme — DSH prefixes the
|
|
225
|
+
* plugin record type, the Claude store hashes into a path — so this is a host
|
|
226
|
+
* fact, not a shared rule.
|
|
227
|
+
*/
|
|
228
|
+
locatorOf(digest: string): string;
|
|
229
|
+
/** Ask the pruning service for a candidate. */
|
|
230
|
+
judge(text: string): Promise<PruneCandidate>;
|
|
231
|
+
/**
|
|
232
|
+
* Retain one original and prove the copy landed.
|
|
233
|
+
*
|
|
234
|
+
* Returns the locator of a *verifiable* copy, or `undefined` when nothing
|
|
235
|
+
* verifiable was written. A host without a sink returns a function that always
|
|
236
|
+
* answers `undefined`; the shared layer then reports `retention-unavailable`
|
|
237
|
+
* before it spends anything.
|
|
238
|
+
*/
|
|
239
|
+
retain(request: PruneRetentionRequest, session: unknown): PruneRetention | undefined;
|
|
240
|
+
/** Whether this host has a retention sink at all. */
|
|
241
|
+
hasRetention(): boolean;
|
|
242
|
+
/** The session a retention request belongs to, for a session-scoped sink. */
|
|
243
|
+
session(): unknown;
|
|
244
|
+
/**
|
|
245
|
+
* Install `text` into the host's effective content.
|
|
246
|
+
*
|
|
247
|
+
* @returns the replacement the host commits, or `undefined` when there is no
|
|
248
|
+
* text block to replace.
|
|
249
|
+
*/
|
|
250
|
+
install(text: string): Result | undefined;
|
|
251
|
+
/** Whether the effective content carries a text block at all. */
|
|
252
|
+
hasTextBlock(): boolean;
|
|
253
|
+
/** Word the operator-facing note of one reduction. */
|
|
254
|
+
describe(facts: PruneFeedbackFacts): string;
|
|
255
|
+
/**
|
|
256
|
+
* Count one abandoned plan by reason, with the diagnostic detail it carried.
|
|
257
|
+
*
|
|
258
|
+
* An abandoned plan that got far enough to have a candidate is charged by the
|
|
259
|
+
* host here (its judgment really ran); one refused before that is not charged
|
|
260
|
+
* at all, because nothing was bought.
|
|
261
|
+
*/
|
|
262
|
+
skip(reason: string, detail: Record<string, unknown>, judgment?: PruneJudgmentCharge): void;
|
|
263
|
+
/**
|
|
264
|
+
* Bill a judgment whose plan was abandoned after it was really made.
|
|
265
|
+
*
|
|
266
|
+
* A refusal before the service runs costs nothing and is never billed here. A
|
|
267
|
+
* refusal *after* it did spend the judgment, so hiding it would understate what
|
|
268
|
+
* the turn cost. `originalTokens` is the size the abandoned branch had already
|
|
269
|
+
* measured, or zero when it had measured nothing.
|
|
270
|
+
*/
|
|
271
|
+
chargeJudgment(judgment: PruneJudgmentCharge, originalTokens?: number): void;
|
|
272
|
+
/**
|
|
273
|
+
* Record one applied or observed plan, with the sizes it accounts for.
|
|
274
|
+
*
|
|
275
|
+
* This is the one place a plan is billed: `plans` +1, `applied` +1 when it
|
|
276
|
+
* really took effect, and every size column from `costs`.
|
|
277
|
+
*/
|
|
278
|
+
conclude(record: PrunePlanRecord, applied: boolean, costs: {
|
|
279
|
+
readonly originalTokens: number;
|
|
280
|
+
readonly candidateTokens: number;
|
|
281
|
+
readonly potentialSavedTokens: number;
|
|
282
|
+
readonly actualSavedTokens?: number;
|
|
283
|
+
}, judgment: PruneJudgmentCharge | undefined, originalLocator?: string): void;
|
|
284
|
+
/** Count one retained copy, once per payload per activation. */
|
|
285
|
+
noteRetained(locator: string): void;
|
|
286
|
+
/** The decision this reduction passes through when it does nothing. */
|
|
287
|
+
passThrough(): Result;
|
|
288
|
+
}
|
|
289
|
+
/** What one reduction installed, for the note. */
|
|
290
|
+
export interface PruneFeedbackFacts {
|
|
291
|
+
readonly tool: string;
|
|
292
|
+
readonly originalTokens: number;
|
|
293
|
+
readonly candidateTokens: number;
|
|
294
|
+
readonly floored: boolean;
|
|
295
|
+
readonly floorMissed: boolean;
|
|
296
|
+
readonly markerOmitted: boolean;
|
|
297
|
+
readonly locator: string;
|
|
298
|
+
readonly keptSegments?: number;
|
|
299
|
+
readonly judgedSegments?: number;
|
|
300
|
+
}
|
|
301
|
+
/** One planned reduction, as the host records it. */
|
|
302
|
+
export interface PrunePlanRecord {
|
|
303
|
+
readonly capability: 'prune';
|
|
304
|
+
readonly action: 'prune-result';
|
|
305
|
+
readonly reason: string;
|
|
306
|
+
feedback: string;
|
|
307
|
+
readonly detail: Record<string, unknown>;
|
|
308
|
+
}
|
|
309
|
+
/** The outcome of one orchestrated decision. */
|
|
310
|
+
export interface PruneOutcome<Result> {
|
|
311
|
+
/** What the host should return to its caller. */
|
|
312
|
+
readonly result: Result;
|
|
313
|
+
/** Whether a reduction was really installed. */
|
|
314
|
+
readonly applied: boolean;
|
|
315
|
+
/** The skip reason, when the decision refused to reduce. */
|
|
316
|
+
readonly skip?: string;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Run the one pruning decision.
|
|
320
|
+
*
|
|
321
|
+
* @param invocation - the call whose result is being considered, and the
|
|
322
|
+
* effective text of that result.
|
|
323
|
+
* @param port - everything that is the host's to answer.
|
|
324
|
+
* @returns the decision the host commits.
|
|
325
|
+
*/
|
|
326
|
+
export declare function orchestratePrune<Result>(invocation: {
|
|
327
|
+
readonly callId: string;
|
|
328
|
+
readonly tool: string;
|
|
329
|
+
/** The effective text of the result (downstream first). */
|
|
330
|
+
readonly text: string;
|
|
331
|
+
/** Whether the rest of the waterfall blocked the result outright. */
|
|
332
|
+
readonly blockedByDownstream: boolean;
|
|
333
|
+
/** Whether a value-shaped accept replaced the payload wholesale. */
|
|
334
|
+
readonly valueShapedAccept: boolean;
|
|
335
|
+
/** Clock reading at hook entry. */
|
|
336
|
+
readonly started: number;
|
|
337
|
+
}, port: HostPrunePort<Result>): Promise<PruneOutcome<Result>>;
|
|
338
|
+
/**
|
|
339
|
+
* Percentage of a payload a reduction kept.
|
|
340
|
+
* @param originalChars - size of the raw payload.
|
|
341
|
+
* @param prunedChars - size of the reduction.
|
|
342
|
+
* @returns the kept share, rounded to one decimal.
|
|
343
|
+
*/
|
|
344
|
+
export declare function reductionPercentageOf(originalChars: number, prunedChars: number): number;
|
|
345
|
+
/**
|
|
346
|
+
* The note of one reduction, in the default wording.
|
|
347
|
+
*
|
|
348
|
+
* It is meant for an operator, never for the model: a prune is supposed to remove
|
|
349
|
+
* context, so sending an explanation of the removal would work against the thing
|
|
350
|
+
* it accounts for. A host that shows it to a *person* may keep this wording
|
|
351
|
+
* verbatim; that is why it lives here next to the facts it is built from.
|
|
352
|
+
* @param facts - what the reduction did.
|
|
353
|
+
* @returns the note, bounded.
|
|
354
|
+
*/
|
|
355
|
+
export declare function describeReduction(facts: PruneFeedbackFacts): string;
|
|
356
|
+
/** Re-exported so a host can name the same content shape the core reads. */
|
|
357
|
+
export type { TextBlockLike };
|