billion-context-omp 0.1.0 → 0.1.2
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 +168 -30
- package/README.zh-CN.md +168 -30
- package/dist/auto-compress.d.ts +65 -0
- package/dist/commands.d.ts +8 -0
- package/dist/compat.d.ts +24 -0
- package/dist/compress-tool.d.ts +27 -0
- package/dist/config.d.ts +92 -0
- package/dist/decompress-tool.d.ts +15 -0
- package/dist/dump.d.ts +22 -0
- package/dist/footer-status.d.ts +2 -0
- package/dist/home.d.ts +2 -0
- package/dist/index.d.ts +5 -59
- package/dist/index.js +4760 -43
- package/dist/index.js.map +1 -1
- package/dist/log.d.ts +21 -0
- package/dist/messages.d.ts +65 -0
- package/dist/runtime.d.ts +34 -0
- package/dist/search-index.d.ts +18 -0
- package/dist/search-tool.d.ts +11 -0
- package/dist/status-tool.d.ts +17 -0
- package/dist/system-prompt.d.ts +2 -0
- package/dist/tokens.d.ts +16 -0
- package/dist/tool-guardrails.d.ts +13 -0
- package/dist/update.d.ts +2 -0
- package/dist/user-config.d.ts +26 -0
- package/package.json +74 -65
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { type Config, type Prompts } from "acp-kernel";
|
|
2
|
+
/** Delegate sub-agent configuration. */
|
|
3
|
+
export interface DelegateConfig {
|
|
4
|
+
/** Enable acp_delegate tools (delegate/wait/cancel) and their system-prompt
|
|
5
|
+
* section. Default: true. Set `enabled: false` to skip registering them. */
|
|
6
|
+
enabled?: boolean;
|
|
7
|
+
/** How delegate usage is reported back to the main session.
|
|
8
|
+
* "separate" (default) — delegate tokens tracked in a separate accumulator;
|
|
9
|
+
* main session totals stay clean, delegate usage shows as its own block in
|
|
10
|
+
* acp_status (excluded from main totals).
|
|
11
|
+
* "merged" — delegate token usage folded into the tool-result usage field,
|
|
12
|
+
* counted as part of the main session totals. */
|
|
13
|
+
displayUsage?: "merged" | "separate";
|
|
14
|
+
}
|
|
15
|
+
/** Compression tuning. All fields accept a ratio (0.75) or percent string
|
|
16
|
+
* ("75%") where noted. */
|
|
17
|
+
export interface CompressConfig {
|
|
18
|
+
maxContextLimit?: number | string;
|
|
19
|
+
emergencyThresholdPercent?: number | string;
|
|
20
|
+
nudgeGrowthTokens?: number;
|
|
21
|
+
/** Model for /compact summaries, as "provider:modelId" (e.g.
|
|
22
|
+
* "zhipuai:glm-5.2"). Omit to use the current session model. */
|
|
23
|
+
compressModel?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Adapter configuration. Maps onto acp-kernel's `Config` plus Pi-specific knobs
|
|
27
|
+
* (live model context window, protected tools, state persistence).
|
|
28
|
+
*/
|
|
29
|
+
export interface AdapterConfig {
|
|
30
|
+
/** When omitted, the adapter reads `ctx.model.contextWindow` live each turn.
|
|
31
|
+
* Set explicitly for tests/headless runs. */
|
|
32
|
+
modelContextLimit?: number;
|
|
33
|
+
protectedTools?: string[];
|
|
34
|
+
preserveRecentMessages?: number;
|
|
35
|
+
/** Check npm for a newer billion-context-omp on startup and auto-install it. Default: true.
|
|
36
|
+
* Disable via `autoUpdate: false` or env `ACP_AUTO_UPDATE=0` to avoid all
|
|
37
|
+
* network calls on startup. */
|
|
38
|
+
autoUpdate?: boolean;
|
|
39
|
+
/** Enable debug-level events in the ACP log file (default ~/.omp/acp-omp.log).
|
|
40
|
+
* Always-on events (session/turn/compress/delegate lifecycle, all errors and
|
|
41
|
+
* warnings) are written regardless; `debug` only adds verbose diagnostics.
|
|
42
|
+
* Default: false (or env ACP_DEBUG=1/true). */
|
|
43
|
+
debug?: boolean;
|
|
44
|
+
/** Default timeout in seconds injected into the bash tool when the model
|
|
45
|
+
* omits `timeout`. Pi has NO built-in default, so without this a command
|
|
46
|
+
* that the model forgets to time out can hang for thousands of seconds.
|
|
47
|
+
* Default: 60 (catches hangs quickly). On timeout the model is guided to
|
|
48
|
+
* re-run with a larger `timeout`. Set to 0 to disable (restore Pi's
|
|
49
|
+
* unbounded behavior). */
|
|
50
|
+
toolBashDefaultTimeout?: number;
|
|
51
|
+
/** Hard byte cap applied to tool result text via the `tool_result` hook.
|
|
52
|
+
* Default: 200000 (~200KB, roughly 5000 lines at ~40 bytes/line) — a
|
|
53
|
+
* generous ceiling that stops runaway output. Pi already caps bash/read/grep
|
|
54
|
+
* at 50KB/2000 lines (bash full output is saved to a temp file), so this
|
|
55
|
+
* default mainly caps tools Pi doesn't cap. Set lower (e.g. 8192) for a
|
|
56
|
+
* tighter context budget, or 0 to disable. When capped, oversized text is
|
|
57
|
+
* head-truncated with a notice telling the model how to see the full output
|
|
58
|
+
* (bash: read BashToolDetails.fullOutputPath). */
|
|
59
|
+
toolOutputMaxBytes?: number;
|
|
60
|
+
/** Delegate sub-agent config. Accepts a boolean shorthand (`true` →
|
|
61
|
+
* `{ enabled: true }`, `false` → `{ enabled: false }`) or a DelegateConfig
|
|
62
|
+
* object. Default: enabled. */
|
|
63
|
+
delegate?: boolean | DelegateConfig;
|
|
64
|
+
/** Compression tuning. */
|
|
65
|
+
compress?: CompressConfig;
|
|
66
|
+
/** Legacy flat alias for `delegate.displayUsage`. Kept for backward
|
|
67
|
+
* compatibility with existing acp-omp.json files. Prefer `delegate.displayUsage`. */
|
|
68
|
+
displayUsage?: "merged" | "separate";
|
|
69
|
+
/** Override acp-kernel's load-bearing compression prompt rules (the 4
|
|
70
|
+
* Prompts fields). Each set field replaces the kernel default verbatim.
|
|
71
|
+
* Requires acknowledgePromptsRisk: true — without it, overrides are dropped
|
|
72
|
+
* (defaults used) and a warning is logged. Set via ~/.omp/acp-omp.json. */
|
|
73
|
+
prompts?: Partial<Prompts>;
|
|
74
|
+
/** Must be true for `prompts` overrides to take effect. Acknowledges that
|
|
75
|
+
* replacing the kernel's tuned compression rules may reduce summary quality
|
|
76
|
+
* (lost paths/signatures/decisions → worse retrieval). */
|
|
77
|
+
acknowledgePromptsRisk?: boolean;
|
|
78
|
+
coreOverrides?: Partial<Config>;
|
|
79
|
+
}
|
|
80
|
+
export declare const DEFAULT_TOOL_BASH_TIMEOUT = 60;
|
|
81
|
+
export declare const DEFAULT_TOOL_OUTPUT_MAX_BYTES = 200000;
|
|
82
|
+
/** Resolve delegate config from the adapter, handling the boolean shorthand
|
|
83
|
+
* and the legacy flat `displayUsage` alias.
|
|
84
|
+
*
|
|
85
|
+
* Forward-compatible: not yet wired (AGENTS.md §7 — delegates deferred).
|
|
86
|
+
* Retained so future wiring can consume it without re-deriving the logic. */
|
|
87
|
+
export declare function resolveDelegate(adapter: AdapterConfig): {
|
|
88
|
+
enabled: boolean;
|
|
89
|
+
displayUsage: "merged" | "separate";
|
|
90
|
+
};
|
|
91
|
+
export declare function resolveConfig(adapter: AdapterConfig, liveContextLimit: number): Config;
|
|
92
|
+
export declare function parsePercent(v: number | string): number;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ToolDefinition } from "@oh-my-pi/pi-coding-agent";
|
|
2
|
+
import type { AcpRuntime } from "./runtime.js";
|
|
3
|
+
declare const DecompressParams: import("@oh-my-pi/omptype").FluentType<{
|
|
4
|
+
blockId: string;
|
|
5
|
+
full?: boolean | undefined;
|
|
6
|
+
inline?: boolean | undefined;
|
|
7
|
+
toFile?: string | undefined;
|
|
8
|
+
}, {
|
|
9
|
+
blockId: string;
|
|
10
|
+
full?: boolean | undefined;
|
|
11
|
+
inline?: boolean | undefined;
|
|
12
|
+
toFile?: string | undefined;
|
|
13
|
+
}>;
|
|
14
|
+
export declare function makeDecompressTool(runtime: AcpRuntime): ToolDefinition<typeof DecompressParams>;
|
|
15
|
+
export {};
|
package/dist/dump.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare function dumpDir(): string;
|
|
2
|
+
export interface DumpMeta {
|
|
3
|
+
sid: string;
|
|
4
|
+
injected: boolean;
|
|
5
|
+
emergency: boolean;
|
|
6
|
+
}
|
|
7
|
+
/** Dump the full AgentMessage[] sent to the LLM for each context event.
|
|
8
|
+
* Only fires when debug mode is on (ACP_DEBUG=1 or debug:true in config).
|
|
9
|
+
* Files are sequential JSON in ~/.omp/acp-omp-dumps/: 0000.json, 0001.json, ...
|
|
10
|
+
* Diff two dumps to verify prefix stability or inspect nudge injection. */
|
|
11
|
+
export declare function dumpContextMessages(messages: unknown[], meta: DumpMeta): string | null;
|
|
12
|
+
/** Extract a compact summary of the provider request payload for log lines.
|
|
13
|
+
* Captures the prefix signature (system prompt + first N messages) so cache
|
|
14
|
+
* instability is visible as a changing hash between consecutive turns. */
|
|
15
|
+
export declare function summarizeProviderPayload(payload: unknown): Record<string, unknown>;
|
|
16
|
+
/** Dump the raw provider request payload — the actual bytes sent to the LLM
|
|
17
|
+
* after ALL processing (ACP tags, omp system-reminders, message reordering).
|
|
18
|
+
* This is the true LLM exit point via the `before_provider_request` hook.
|
|
19
|
+
* Files: ~/.omp/acp-omp-dumps/req_NNNN.json */
|
|
20
|
+
export declare function dumpProviderRequest(payload: unknown, meta: {
|
|
21
|
+
sid: string;
|
|
22
|
+
}): string | null;
|
package/dist/home.d.ts
ADDED
package/dist/index.d.ts
CHANGED
|
@@ -1,59 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
* `billion-context` is a Node.js proxy that sits between an AI agent and its
|
|
8
|
-
* model API, rewriting Anthropic/OpenAI streams with acp-kernel compression.
|
|
9
|
-
* This package wires [omp](https://github.com/can1357/oh-my-pi) — the terminal
|
|
10
|
-
* coding agent — into that pipeline: it builds the base_url override that
|
|
11
|
-
* routes omp's traffic through a running billion-context proxy, and
|
|
12
|
-
* self-disables when it detects omp is *already* behind bili (so two layers of
|
|
13
|
-
* compression never stack).
|
|
14
|
-
*
|
|
15
|
-
* > Skeleton package. The config-building helpers below are placeholders; wire
|
|
16
|
-
* > them to omp's actual provider/base_url config shape as you build it out.
|
|
17
|
-
*/
|
|
18
|
-
/** Marker path segment bili rewrites upstream URLs under. */
|
|
19
|
-
declare const BILI_PREFIX = "/bili/";
|
|
20
|
-
interface BillionContextOmpOptions {
|
|
21
|
-
/**
|
|
22
|
-
* Origin of a running billion-context proxy, e.g. `http://localhost:8787`.
|
|
23
|
-
*/
|
|
24
|
-
endpoint?: string;
|
|
25
|
-
}
|
|
26
|
-
interface OmpProviderOverride {
|
|
27
|
-
/** The provider key to override in omp's config (e.g. `openai`, `anthropic`). */
|
|
28
|
-
provider: string;
|
|
29
|
-
/** Original upstream base URL, e.g. `https://api.openai.com/v1`. */
|
|
30
|
-
upstream: string;
|
|
31
|
-
}
|
|
32
|
-
declare class BillionContextOmp {
|
|
33
|
-
private readonly endpoint?;
|
|
34
|
-
constructor(options?: BillionContextOmpOptions);
|
|
35
|
-
/**
|
|
36
|
-
* Detect whether a base_url is already pointing at a billion-context proxy.
|
|
37
|
-
* Client extensions use this to self-disable and avoid double compression.
|
|
38
|
-
*/
|
|
39
|
-
isBiliBaseUrl(baseUrl: string): boolean;
|
|
40
|
-
/**
|
|
41
|
-
* Build the base_url omp should use so its traffic flows through bili.
|
|
42
|
-
* Result shape: `${endpoint}/bili/${upstream}`.
|
|
43
|
-
*/
|
|
44
|
-
buildBaseUrl(upstream: string): string;
|
|
45
|
-
/**
|
|
46
|
-
* Produce the provider overrides omp should merge into its config to route
|
|
47
|
-
* every listed provider through bili.
|
|
48
|
-
*
|
|
49
|
-
* Skeleton — returns base_url overrides only; extend with headers / auth
|
|
50
|
-
* passthrough / model-list tweaks as needed.
|
|
51
|
-
*/
|
|
52
|
-
buildConfig(providers: OmpProviderOverride[]): Record<string, {
|
|
53
|
-
base_url: string;
|
|
54
|
-
}>;
|
|
55
|
-
/** Whether the client is configured against a proxy endpoint. */
|
|
56
|
-
get hasEndpoint(): boolean;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export { BILI_PREFIX, BillionContextOmp, type BillionContextOmpOptions, type OmpProviderOverride, BillionContextOmp as default };
|
|
1
|
+
import type { ExtensionFactory } from "@oh-my-pi/pi-coding-agent";
|
|
2
|
+
import { type AdapterConfig } from "./config.js";
|
|
3
|
+
export declare function createAcpExtension(adapter?: AdapterConfig): ExtensionFactory;
|
|
4
|
+
declare const _default: ExtensionFactory;
|
|
5
|
+
export default _default;
|