dsh-context-compression-improved 0.4.0 → 0.5.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.ja.md +19 -0
- package/CHANGELOG.ko.md +19 -0
- package/CHANGELOG.md +21 -0
- package/CHANGELOG.zh.md +17 -0
- package/docs/installation.md +25 -1
- package/docs/installation.zh.md +24 -1
- package/package.json +1 -1
- package/packages/selector/lib/{review-registry.js → advisor-state.js} +105 -4
- package/packages/selector/lib/client.d.ts +7 -0
- package/packages/selector/lib/client.js +32 -2
- package/packages/selector/lib/index.d.ts +7 -0
- package/packages/selector/lib/index.js +101 -2
- package/packages/selector/lib/pruner.d.ts +82 -0
- package/packages/selector/lib/pruner.js +545 -11
- package/packages/selector/src/client/preset-options.ts +2 -0
- package/packages/selector/src/index.ts +108 -0
- package/packages/selector/src/profiles.ts +48 -0
- package/packages/selector/src/pruner/state.ts +3 -0
- package/packages/selector/src/pruner.ts +113 -0
- package/packages/selector/src/runtime/audit.ts +22 -0
- package/packages/selector/src/runtime/config.ts +58 -0
- package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +188 -0
- package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +133 -0
- package/packages/selector/src/runtime/tokenpilot/advisor.ts +419 -0
- package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +24 -9
- package/packages/selector/src/runtime/types.ts +21 -0
- package/packages/selector/tests/advisor-report.host.spec.ts +223 -0
- package/packages/selector/tests/runtime/advisor-invariant.spec.ts +272 -0
- package/packages/selector/tests/runtime/advisor.spec.ts +226 -0
- package/packages/selector/tests/runtime/audit.spec.ts +44 -0
- package/packages/selector/tests/runtime/tokenpilot/profile-baseline.spec.ts +12 -0
|
@@ -82,6 +82,20 @@ interface PresetOptions {
|
|
|
82
82
|
readonly estimator: {
|
|
83
83
|
readonly mode: '' | 'host' | 'direct';
|
|
84
84
|
};
|
|
85
|
+
/**
|
|
86
|
+
* Advisory relevance advisor: statistics and suggestions only — every output
|
|
87
|
+
* (summaries, scores, decay, recertification) is observational and must never
|
|
88
|
+
* suppress, delay, or rewrite any reduction that would land. `''` (the
|
|
89
|
+
* default) keeps the advisor fully off.
|
|
90
|
+
*/
|
|
91
|
+
readonly advisor: {
|
|
92
|
+
readonly mode: '' | 'host' | 'direct';
|
|
93
|
+
readonly timeoutMs: number;
|
|
94
|
+
readonly refreshTurns: number;
|
|
95
|
+
readonly scoreThreshold: number;
|
|
96
|
+
readonly sampleLimit: number;
|
|
97
|
+
readonly minTokens: number;
|
|
98
|
+
};
|
|
85
99
|
/**
|
|
86
100
|
* Human-gated review pipeline (beta): edge/high-impact candidates queue for
|
|
87
101
|
* manual approval and execute in one merged batch at the next turn boundary
|
|
@@ -158,6 +172,13 @@ interface PresetOptionsSettings {
|
|
|
158
172
|
readonly estimatorBaseUrl?: string;
|
|
159
173
|
readonly estimatorApiKey?: string;
|
|
160
174
|
readonly estimatorTimeoutMs?: number;
|
|
175
|
+
/** Advisory advisor channel; `''` (the default) keeps the advisor off. */
|
|
176
|
+
readonly advisorMode?: '' | 'host' | 'direct';
|
|
177
|
+
readonly advisorTimeoutMs?: number;
|
|
178
|
+
readonly advisorRefreshTurns?: number;
|
|
179
|
+
readonly advisorScoreThreshold?: number;
|
|
180
|
+
readonly advisorSampleLimit?: number;
|
|
181
|
+
readonly advisorMinTokens?: number;
|
|
161
182
|
}
|
|
162
183
|
/** Durable global preference exposed through `ctx.settings`. */
|
|
163
184
|
interface ContextCompressionSettings {
|
|
@@ -336,6 +357,56 @@ interface PruneResult {
|
|
|
336
357
|
readonly tokensRemoved: number;
|
|
337
358
|
}
|
|
338
359
|
//#endregion
|
|
360
|
+
//#region src/runtime/tokenpilot/sidechannel.d.ts
|
|
361
|
+
/** Audit record of one side-channel call (Phase 13). All fields optional-safe. */
|
|
362
|
+
interface SideChannelAudit {
|
|
363
|
+
readonly ok: boolean;
|
|
364
|
+
readonly latencyMs: number;
|
|
365
|
+
/** host|direct plus the resolved provider/model identity. */
|
|
366
|
+
readonly channel?: string;
|
|
367
|
+
/** L2 coverage: content shown N of node content total M. */
|
|
368
|
+
readonly coverage?: {
|
|
369
|
+
readonly shown: number;
|
|
370
|
+
readonly total: number;
|
|
371
|
+
};
|
|
372
|
+
readonly reason?: string;
|
|
373
|
+
}
|
|
374
|
+
interface SideChannelRequest {
|
|
375
|
+
readonly system: string;
|
|
376
|
+
readonly user: string;
|
|
377
|
+
readonly signal: AbortSignal;
|
|
378
|
+
}
|
|
379
|
+
/** One bound side channel. `ask` resolves `undefined` on ANY failure. */
|
|
380
|
+
declare class SideChannel {
|
|
381
|
+
private readonly ctx;
|
|
382
|
+
private readonly options;
|
|
383
|
+
private readonly overrides?;
|
|
384
|
+
/**
|
|
385
|
+
* @param overrides - per-consumer overrides of the estimator-named options.
|
|
386
|
+
* The estimator itself never passes them (byte-identical behavior); the
|
|
387
|
+
* advisory advisor passes its own mode/timeout/output budget so both
|
|
388
|
+
* consumers share one transport without sharing one configuration.
|
|
389
|
+
*/
|
|
390
|
+
constructor(ctx: Context, options: PresetOptionsSettings, overrides?: {
|
|
391
|
+
readonly mode?: "" | "host" | "direct";
|
|
392
|
+
readonly timeoutMs?: number;
|
|
393
|
+
readonly maxTokens?: number;
|
|
394
|
+
} | undefined);
|
|
395
|
+
private get mode();
|
|
396
|
+
get enabled(): boolean;
|
|
397
|
+
ask(request: SideChannelRequest): Promise<string | undefined>;
|
|
398
|
+
/** Failure-open wrapper that also records one audit record per call. */
|
|
399
|
+
askAudited(request: SideChannelRequest): Promise<{
|
|
400
|
+
text?: string;
|
|
401
|
+
audit: SideChannelAudit;
|
|
402
|
+
}>;
|
|
403
|
+
identity(): string | undefined;
|
|
404
|
+
/** Same host-route resolution as the estimator: explicit, then host default. */
|
|
405
|
+
private resolveHostRoute;
|
|
406
|
+
private askHost;
|
|
407
|
+
private askDirect;
|
|
408
|
+
}
|
|
409
|
+
//#endregion
|
|
339
410
|
//#region src/runtime/tokenpilot/estimator.d.ts
|
|
340
411
|
/** Per-session estimator failure bookkeeping for exponential backoff. */
|
|
341
412
|
interface EstimatorFailures {
|
|
@@ -532,6 +603,8 @@ interface PrunerState {
|
|
|
532
603
|
readonly reviewClocks: WeakMap<Session, number>;
|
|
533
604
|
/** Estimator-reported remaining turns Ŝ per Session; advisory only. */
|
|
534
605
|
readonly estimatorRemainingTurns: WeakMap<Session, number>;
|
|
606
|
+
/** Per-session advisor side channel, constructed once with the advisor overrides. */
|
|
607
|
+
readonly advisorChannels: WeakMap<Session, SideChannel>;
|
|
535
608
|
/** Four-state outcome counters per Session (floating-window summary row). */
|
|
536
609
|
readonly reviewSummaries: WeakMap<Session, ReviewSessionSummary>;
|
|
537
610
|
}
|
|
@@ -847,6 +920,15 @@ declare class ToolResultPruner extends Service {
|
|
|
847
920
|
* superseded classification.
|
|
848
921
|
*/
|
|
849
922
|
private postflightEstimatorPass;
|
|
923
|
+
/**
|
|
924
|
+
* Advisory advisor pass at the turn boundary, strictly fire-and-forget.
|
|
925
|
+
* Produces todolist-bound tail-task summaries, incremental relevance
|
|
926
|
+
* scores, and a prefix-decay figure — all observational. Every short
|
|
927
|
+
* circuit below (mode off, re-entry, cooldown, no task semantics, no
|
|
928
|
+
* direct endpoint) returns without touching any state the pruning chain
|
|
929
|
+
* reads, so the default configuration adds exactly zero behavior.
|
|
930
|
+
*/
|
|
931
|
+
private postflightAdvisorPass;
|
|
850
932
|
/**
|
|
851
933
|
* The per-session review queue, or `undefined` while review mode is off
|
|
852
934
|
* (every review path must then behave exactly like before).
|