billion-context-dsh 0.1.5 → 0.1.7
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.en.md +8 -7
- package/README.md +8 -7
- package/dist/config.d.ts +6 -2
- package/dist/index.d.ts +37 -6
- package/dist/index.js +186 -43
- package/dist/index.js.map +1 -1
- package/dist/region.d.ts +40 -12
- package/dist/system-prompt.d.ts +1 -1
- package/dist/tools.d.ts +4 -0
- package/dist/window.d.ts +32 -0
- package/package.json +1 -1
package/dist/region.d.ts
CHANGED
|
@@ -39,21 +39,49 @@ export interface AcpBlockLedgerEntry {
|
|
|
39
39
|
export declare function findOpenTurn(events: readonly SessionEvent[]): number | null;
|
|
40
40
|
/** Reject a second concurrent compaction for the same session. */
|
|
41
41
|
export declare function assertNoActiveCompaction(events: readonly SessionEvent[]): void;
|
|
42
|
+
/**
|
|
43
|
+
* A requested range whose EVERY live message was already shadowed by one or
|
|
44
|
+
* more blocks. The compress tool catches this and reports the range as already
|
|
45
|
+
* compressed (with the covering block ids) instead of folding block summary
|
|
46
|
+
* nodes as plain messages or erroring out. Distillation stays an explicit act:
|
|
47
|
+
* target a LIVE checkpoint seq directly to distill (tier 2/3).
|
|
48
|
+
*/
|
|
49
|
+
export declare class AlreadyCompressedRangeError extends Error {
|
|
50
|
+
readonly start: number;
|
|
51
|
+
readonly end: number;
|
|
52
|
+
readonly coveringBlockIds: readonly string[];
|
|
53
|
+
constructor(start: number, end: number, coveringBlockIds: readonly string[]);
|
|
54
|
+
}
|
|
55
|
+
export interface ResolvedSurfaceRange {
|
|
56
|
+
readonly start: number;
|
|
57
|
+
readonly end: number;
|
|
58
|
+
/**
|
|
59
|
+
* True when the requested edges were not on the current surface and were
|
|
60
|
+
* remapped to the still-live content of the requested span (an earlier
|
|
61
|
+
* compression shadowed them). Callers surface this so the model sees what
|
|
62
|
+
* was actually compressed instead of silently shadowing a different span.
|
|
63
|
+
*/
|
|
64
|
+
readonly recovered?: boolean;
|
|
65
|
+
}
|
|
42
66
|
/**
|
|
43
67
|
* Validate one inclusive surface span and adjust its edges to a
|
|
44
|
-
* tool-pairing-balanced range whose boundaries carry a bare-seq ref.
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
68
|
+
* tool-pairing-balanced range whose boundaries carry a bare-seq ref. Reversed
|
|
69
|
+
* ranges throw. An edge that sits inside a tool-call/result pair — or on a
|
|
70
|
+
* multi-tool-call assistant message that has no bare-seq ref — is first nudged
|
|
71
|
+
* inward to the nearest clean cut; if that collapses the range (e.g. the model
|
|
72
|
+
* asked for a SINGLE tool result, which can never be balanced alone), the
|
|
73
|
+
* range EXPANDS outward to the enclosing clean pair instead — a lone tool
|
|
74
|
+
* message is almost always a "consumed output" the model genuinely wants to
|
|
75
|
+
* compress. The returned range is what a caller should actually shadow.
|
|
76
|
+
*
|
|
77
|
+
* Missing edges are NOT an immediate error: the seqs were probably shadowed by
|
|
78
|
+
* an earlier compression (stale nudge table / old compress result). The span
|
|
79
|
+
* is rebuilt from its still-live remainder via recoverStaleRange — a fully
|
|
80
|
+
* shadowed span throws AlreadyCompressedRangeError, a genuinely unknown edge
|
|
81
|
+
* throws the not-in-surface guidance error. The returned range is what a
|
|
82
|
+
* caller should actually shadow.
|
|
52
83
|
*/
|
|
53
|
-
export declare function resolveSurfaceRange(session: Session, start: number, end: number):
|
|
54
|
-
start: number;
|
|
55
|
-
end: number;
|
|
56
|
-
};
|
|
84
|
+
export declare function resolveSurfaceRange(session: Session, start: number, end: number): ResolvedSurfaceRange;
|
|
57
85
|
/** The surface seqs shadowed by the inclusive positional span. */
|
|
58
86
|
export declare function shadowedSeqsOf(session: Session, start: number, end: number): number[];
|
|
59
87
|
export interface CompactionTransactionInput {
|
package/dist/system-prompt.d.ts
CHANGED
|
@@ -6,6 +6,6 @@
|
|
|
6
6
|
* to compress (never "compress now").
|
|
7
7
|
* @module billion-context-dsh/system-prompt
|
|
8
8
|
*/
|
|
9
|
-
export declare const ACP_SYSTEM_PROMPT = "Active Context Pruning \u2014 model-driven context management\n\nYOU decide whether and when to compress context. Nothing forces you: the injected \"nudge\" is a suggestion, not an order, and you may ignore it when compression would not help. Compress only ranges you have genuinely consumed (read tool outputs, finished explorations, superseded steps) that the current work no longer needs verbatim.\n\nCompression Philosophy:\n- All compression serves the primary task, but be frugal.\n- Context capacity is precious. Save context by compressing consumed outputs, not by avoiding tools.\n- Compress by need, not by percentage.\n- Work from summaries, not raw tool outputs. All listed ranges (user prompts, tool outputs, code, logs, exploration, intermediate steps) should be compressed to summary format \u2014 the ONLY exceptions are protected content, content the current step is actively using, or critical content you cannot reconstruct.\n\nCompression tools (refs are SURFACE SEQS, not ids):\n- compress: replace one or more seq ranges, each with your own dense summary. Single range: compress({ content: [{ startSeq, endSeq, summary }] }). Batch multiple unrelated segments in one call (each entry becomes its own block): compress({ content: [{ startSeq: 1, endSeq: 5, summary: '...' }, { startSeq: 12, endSeq: 18, summary: '...' }] }). Keep ranges disjoint \u2014 overlapping entries in one batch are skipped. Edges are auto-balanced to tool-call/result boundaries; a trailing #callId fragment in a seq is ignored.
|
|
9
|
+
export declare const ACP_SYSTEM_PROMPT = "Active Context Pruning \u2014 model-driven context management\n\nYOU decide whether and when to compress context. Nothing forces you: the injected \"nudge\" is a suggestion, not an order, and you may ignore it when compression would not help. Compress only ranges you have genuinely consumed (read tool outputs, finished explorations, superseded steps) that the current work no longer needs verbatim.\n\nCompression Philosophy:\n- All compression serves the primary task, but be frugal.\n- Context capacity is precious. Save context by compressing consumed outputs, not by avoiding tools.\n- Compress by need, not by percentage.\n- Work from summaries, not raw tool outputs. All listed ranges (user prompts, tool outputs, code, logs, exploration, intermediate steps) should be compressed to summary format \u2014 the ONLY exceptions are protected content, content the current step is actively using, or critical content you cannot reconstruct.\n\nCompression tools (refs are SURFACE SEQS, not ids):\n- compress: replace one or more seq ranges, each with your own dense summary. Single range: compress({ content: [{ startSeq, endSeq, summary }] }). Batch multiple unrelated segments in one call (each entry becomes its own block): compress({ content: [{ startSeq: 1, endSeq: 5, summary: '...' }, { startSeq: 12, endSeq: 18, summary: '...' }] }). Keep ranges disjoint \u2014 overlapping entries in one batch are skipped. Edges are auto-balanced to tool-call/result boundaries; a trailing #callId fragment in a seq is ignored. Seq refs must be on the current surface: seqs from older nudges or earlier compresses go stale as the surface moves, so a stale span is auto-remapped to its still-live remainder (the result reports the adjusted span), a fully compressed span is reported as already compressed, and invented/other-session seqs fail with guidance.\n- decompress: recover a compressed block's original content, read-only. decompress({ blockId }).\n- search_context: find information inside compressed blocks BEFORE decompressing. search_context({ query }).\n- acp_status: current context usage and the live compressible-range list. Run it right before compressing \u2014 the only seqs that never go stale are the ones you just read.\n\nTiered compression: each compressed block appears on the surface as one summary node. Compressing that node again DISTILLS the block (tier 2): the parent summary folds into your new summary and the original messages are freed. Distilling a tier-2 block yields tier 3. Distill when a summary itself is consumed \u2014 decompress on the tier-2 block recovers the full originals.\n\nWhen you write a summary, it becomes the ONLY record of that range: keep file paths, signatures, exact values, decisions, and error strings verbatim so a later reader (or you, after decompress) can continue without the original. Never reuse historical seqs \u2014 the surface moves as messages land and compress; verify with acp_status.";
|
|
10
10
|
/** System-prompt section order: tool guidance lives in 100–199. */
|
|
11
11
|
export declare const ACP_SYSTEM_PROMPT_ORDER = 150;
|
package/dist/tools.d.ts
CHANGED
|
@@ -11,11 +11,15 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { type ToolDefinition } from '@deepseek-ai/dsh-tools';
|
|
13
13
|
import { type CompressionCore } from 'acp-kernel';
|
|
14
|
+
import type { Agent } from '@deepseek-ai/dsh-agent';
|
|
14
15
|
import type { AcpStateStore } from './state.ts';
|
|
15
16
|
import { type KernelConfigInput } from './config.ts';
|
|
17
|
+
import { type AcpWindow } from './window.ts';
|
|
16
18
|
export interface ToolEnvironment extends KernelConfigInput {
|
|
17
19
|
readonly kernel: CompressionCore;
|
|
18
20
|
readonly store: AcpStateStore;
|
|
21
|
+
/** Resolve the effective context window for an agent (optional: status falls back to modelContextLimit). */
|
|
22
|
+
readonly windowFor?: (agent: Agent) => Promise<AcpWindow>;
|
|
19
23
|
}
|
|
20
24
|
/** Build the four ACP model tools bound to one engine. */
|
|
21
25
|
export declare function makeTools(env: ToolEnvironment): ToolDefinition[];
|
package/dist/window.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auto context-window detection — resolve the model's real context window
|
|
3
|
+
* from the host LLM runtime instead of trusting a hardcoded config default.
|
|
4
|
+
*
|
|
5
|
+
* `agent.ctx.llm` (the cordis `LlmRuntime` service) exposes
|
|
6
|
+
* `resolveModelInfo(provider, model)` → `{ context: { contextWindow } }`, the
|
|
7
|
+
* exact-route capacity the adapter learned from the provider API (pi-ai reads
|
|
8
|
+
* `context_window`/`context_length` during discovery). Probing is a standalone
|
|
9
|
+
* capability query — no request is sent.
|
|
10
|
+
* @module billion-context-dsh/window
|
|
11
|
+
*/
|
|
12
|
+
import type { Agent } from '@deepseek-ai/dsh-agent';
|
|
13
|
+
/** Fallback window when auto-detection is unavailable. Same default as acp-kernel's `defaultConfig`. */
|
|
14
|
+
export declare const DEFAULT_CONTEXT_WINDOW = 128000;
|
|
15
|
+
/** The effective context window plus where it came from. */
|
|
16
|
+
export interface AcpWindow {
|
|
17
|
+
/** Effective context window in tokens. */
|
|
18
|
+
readonly limit: number;
|
|
19
|
+
/** Where the limit came from. */
|
|
20
|
+
readonly source: 'explicit' | 'auto' | 'default';
|
|
21
|
+
/** Route the auto window was resolved for (auto source only). */
|
|
22
|
+
readonly provider?: string;
|
|
23
|
+
readonly model?: string;
|
|
24
|
+
}
|
|
25
|
+
/** Human label for an AcpWindow's source (used by acp_status). */
|
|
26
|
+
export declare function windowSourceLabel(window: AcpWindow): string;
|
|
27
|
+
/**
|
|
28
|
+
* Probe the model's real context window. Returns null when the host provides
|
|
29
|
+
* no llm service, the adapter discloses no window, or the probe throws —
|
|
30
|
+
* callers fall back to DEFAULT_CONTEXT_WINDOW. Never throws.
|
|
31
|
+
*/
|
|
32
|
+
export declare function detectContextWindow(agent: Agent, provider: string, model: string): Promise<number | null>;
|
package/package.json
CHANGED