billion-context-pi 0.1.27 → 0.1.29
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 +17 -2
- package/README.zh-CN.md +19 -2
- package/dist/config.d.ts +3 -1
- package/dist/delegate-events.d.ts +69 -0
- package/dist/delegate-tool.d.ts +3 -0
- package/dist/delegate-watchdog.d.ts +31 -0
- package/dist/index.js +580 -131
- package/dist/index.js.map +1 -1
- package/dist/log.d.ts +12 -2
- package/dist/runtime.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -154,7 +154,7 @@ Create `~/.pi/acp.json` (global) and/or `<project>/.pi/acp.json` (project-local,
|
|
|
154
154
|
|
|
155
155
|
| Key | Default | Description |
|
|
156
156
|
|-----|---------|-------------|
|
|
157
|
-
| `debug` | `false` |
|
|
157
|
+
| `debug` | `false` | Enable verbose **debug-level** events in the log. The always-on log (lifecycle events, errors, warnings) is written regardless; `debug` only adds extra diagnostics. Also enabled by env `ACP_DEBUG=1`. |
|
|
158
158
|
| `autoUpdate` | `true` | On Pi startup, check npm for a newer version and auto-install it (throttled to one check per 3 minutes). Disable to avoid all startup network calls. |
|
|
159
159
|
| `modelContextLimit` | *(auto)* | Override the context limit (in tokens). Defaults to the model's `contextWindow`. |
|
|
160
160
|
| `delegate` | `true` | Enable the `acp_delegate` tools (delegate/wait/cancel) and their system-prompt section. Set `false` to skip registering them (e.g. you use a different sub-agent extension, or run headless where async injection adds no value). |
|
|
@@ -169,7 +169,22 @@ Create `~/.pi/acp.json` (global) and/or `<project>/.pi/acp.json` (project-local,
|
|
|
169
169
|
|----------|--------|
|
|
170
170
|
| `ACP_AUTO_UPDATE` | Set to `0` / `false` / `no` / `off` (case-insensitive) to disable auto-update, overriding the config. |
|
|
171
171
|
| `ACP_MODEL_CONTEXT_LIMIT` | Override the context limit. Takes precedence over the config value. |
|
|
172
|
-
| `ACP_DEBUG` | Set to `1` or `true` to enable debug logging. |
|
|
172
|
+
| `ACP_DEBUG` | Set to `1` or `true` to enable debug-level logging (always-on events are written regardless). |
|
|
173
|
+
| `ACP_LOG_FILE` | Override the log file path (default `~/.pi/acp.log`). |
|
|
174
|
+
|
|
175
|
+
### Logging
|
|
176
|
+
|
|
177
|
+
billion-context-pi writes a structured, always-on log to `~/.pi/acp.log` (override with `ACP_LOG_FILE`). It covers the model's whole working session and is useful for diagnosing problems:
|
|
178
|
+
|
|
179
|
+
- **Always written** (even with `debug: false`): `error`, `warn`, `info` levels — session start, every context turn (token usage / nudge decision), compress/decompress, delegate spawn/done, and **all errors and warnings** (config/state/tool failures, delegate errors, guardrail caps, update failures). Error lines include the message and stack trace.
|
|
180
|
+
- **Written only when `debug: true`**: verbose `debug`-level diagnostics (full field dumps, per-turn internals).
|
|
181
|
+
|
|
182
|
+
Each line: `<ISO timestamp> [<level>] [<scope>] key=value key=value`. The file rotates to `~/.pi/acp.log.old` at 10 MB.
|
|
183
|
+
|
|
184
|
+
```sh
|
|
185
|
+
tail -f ~/.pi/acp.log # watch the session live
|
|
186
|
+
grep '\[error\]' ~/.pi/acp.log # surface every recorded failure
|
|
187
|
+
```
|
|
173
188
|
|
|
174
189
|
### Compression philosophy
|
|
175
190
|
|
package/README.zh-CN.md
CHANGED
|
@@ -153,7 +153,7 @@ billion-context-pi 开箱即用,无需任何配置。可以在 JSON 配置文件
|
|
|
153
153
|
|
|
154
154
|
| Key | 默认值 | 说明 |
|
|
155
155
|
|-----|--------|------|
|
|
156
|
-
| `debug` | `false` |
|
|
156
|
+
| `debug` | `false` | 启用诊断日志(`error`/`warn`/`info` 始终写入 `~/.pi/acp.log`,此开关仅额外打开详细 `debug` 事件)。也可用环境变量 `ACP_DEBUG=1` 启用。 |
|
|
157
157
|
| `autoUpdate` | `true` | Pi 启动时检查 npm 是否有更新版本并自动安装(限频:每 3 分钟最多一次检查)。禁用以避免所有启动时的网络请求。 |
|
|
158
158
|
| `modelContextLimit` | *(自动)* | 覆盖上下文上限(token 数)。默认为模型的 `contextWindow`。 |
|
|
159
159
|
| `delegate` | `true` | 启用 `acp_delegate` 工具(delegate/wait/cancel)及其系统提示词段落。设为 `false` 则不注册这些工具(例如你用了别的子代理扩展,或跑 headless 场景异步注入没有意义)。 |
|
|
@@ -168,7 +168,24 @@ billion-context-pi 开箱即用,无需任何配置。可以在 JSON 配置文件
|
|
|
168
168
|
|------|------|
|
|
169
169
|
| `ACP_AUTO_UPDATE` | 设为 `0` / `false` / `no` / `off`(不区分大小写)以禁用自动更新,覆盖配置值。 |
|
|
170
170
|
| `ACP_MODEL_CONTEXT_LIMIT` | 覆盖上下文上限。优先级高于配置值。 |
|
|
171
|
-
| `ACP_DEBUG` | 设为 `1` 或 `true` 启用 debug
|
|
171
|
+
| `ACP_DEBUG` | 设为 `1` 或 `true` 启用 debug 日志(`error`/`warn`/`info` 始终写入,无需此开关)。 |
|
|
172
|
+
| `ACP_LOG_FILE` | 覆盖日志文件路径(默认 `~/.pi/acp.log`)。 |
|
|
173
|
+
|
|
174
|
+
### 日志
|
|
175
|
+
|
|
176
|
+
billion-context-pi 会向 `~/.pi/acp.log`(可用 `ACP_LOG_FILE` 覆盖)写入结构化的**始终开启**日志,覆盖模型工作的整个会话,便于排查问题:
|
|
177
|
+
|
|
178
|
+
- `error` — 详细记录所有报错(含 `message` 与 `stack`):上下文变换、压缩/解压/搜索执行失败、delegate 子进程错误、状态读写失败、子代理工具注册失败等。原本被静默吞掉的异常现在一律落盘。
|
|
179
|
+
- `warn` — 值得注意的非致命情况:紧急 nudge 注入、配置加载失败、自动更新网络错误、工具输出被截断、委派结果注入被跳过。
|
|
180
|
+
- `info` — 生命周期事件:会话启动、每轮上下文变换摘要(消息数/token/压缩比/活跃块数)、压缩/解压、delegate 派发与完成、自动更新检查。
|
|
181
|
+
- `debug` —— 仅在 `debug: true` 时额外写入(细粒度的字段级事件)。
|
|
182
|
+
|
|
183
|
+
每行格式:`<ISO 时间戳> [<级别>] [<范围>] key=value key=value`。文件达到 10 MB 时轮转为 `~/.pi/acp.log.old`。
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
tail -f ~/.pi/acp.log # 实时观察会话
|
|
187
|
+
grep '\[error\]' ~/.pi/acp.log # 汇总所有记录的失败
|
|
188
|
+
```
|
|
172
189
|
|
|
173
190
|
### 压缩策略
|
|
174
191
|
|
package/dist/config.d.ts
CHANGED
|
@@ -13,7 +13,9 @@ export interface AdapterConfig {
|
|
|
13
13
|
* Disable via `autoUpdate: false` or env `ACP_AUTO_UPDATE=0` to avoid all
|
|
14
14
|
* network calls on startup. */
|
|
15
15
|
autoUpdate?: boolean;
|
|
16
|
-
/**
|
|
16
|
+
/** Enable debug-level events in the ACP log file (default ~/.pi/acp.log).
|
|
17
|
+
* Always-on events (session/turn/compress/delegate lifecycle, all errors and
|
|
18
|
+
* warnings) are written regardless; `debug` only adds verbose diagnostics.
|
|
17
19
|
* Default: false (or env ACP_DEBUG=1/true). */
|
|
18
20
|
debug?: boolean;
|
|
19
21
|
/** Enable acp_delegate tools (delegate/wait/cancel) and their system-prompt
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export interface ToolStartEvent {
|
|
2
|
+
kind: "tool-start";
|
|
3
|
+
toolName: string;
|
|
4
|
+
argsText: string;
|
|
5
|
+
}
|
|
6
|
+
export interface ToolUpdateEvent {
|
|
7
|
+
kind: "tool-update";
|
|
8
|
+
toolCallId: string;
|
|
9
|
+
text: string;
|
|
10
|
+
}
|
|
11
|
+
export interface ToolEndEvent {
|
|
12
|
+
kind: "tool-end";
|
|
13
|
+
toolName: string;
|
|
14
|
+
isError: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface ReplyDeltaEvent {
|
|
17
|
+
kind: "reply-delta";
|
|
18
|
+
delta: string;
|
|
19
|
+
}
|
|
20
|
+
export interface ReplyCompleteEvent {
|
|
21
|
+
kind: "reply-complete";
|
|
22
|
+
content: string;
|
|
23
|
+
}
|
|
24
|
+
export interface ThinkingDeltaEvent {
|
|
25
|
+
kind: "thinking-delta";
|
|
26
|
+
delta: string;
|
|
27
|
+
}
|
|
28
|
+
export type ParsedEvent = ToolStartEvent | ToolUpdateEvent | ToolEndEvent | ReplyDeltaEvent | ReplyCompleteEvent | ThinkingDeltaEvent | ThinkingEndEvent | RetryStartEvent | RetryEndEvent;
|
|
29
|
+
export interface ThinkingEndEvent {
|
|
30
|
+
kind: "thinking-end";
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Accumulates thinking_delta tokens and emits one human-readable line per
|
|
34
|
+
* thinking segment (a segment ends at thinking_end / text_start). Nothing is
|
|
35
|
+
* emitted when showThinking is off.
|
|
36
|
+
*/
|
|
37
|
+
export declare class ThinkingCollector {
|
|
38
|
+
private readonly showThinking;
|
|
39
|
+
private buf;
|
|
40
|
+
constructor(showThinking: boolean);
|
|
41
|
+
push(delta: string): void;
|
|
42
|
+
/** Return the segment line to write ("" when empty or disabled), resetting. */
|
|
43
|
+
flush(): string;
|
|
44
|
+
}
|
|
45
|
+
export interface RetryStartEvent {
|
|
46
|
+
kind: "retry-start";
|
|
47
|
+
attempt: number;
|
|
48
|
+
maxAttempts: number;
|
|
49
|
+
delayMs: number;
|
|
50
|
+
errorMessage: string;
|
|
51
|
+
}
|
|
52
|
+
export interface RetryEndEvent {
|
|
53
|
+
kind: "retry-end";
|
|
54
|
+
success: boolean;
|
|
55
|
+
attempt: number;
|
|
56
|
+
}
|
|
57
|
+
export declare function parseEventLine(line: string): ParsedEvent | null;
|
|
58
|
+
/** Join `content[].text` blocks from a tool result / partialResult payload. */
|
|
59
|
+
export declare function extractContentText(payload: unknown): string;
|
|
60
|
+
/** Format a parsed event as human-readable activity file lines (each with a
|
|
61
|
+
* trailing newline; empty when none). */
|
|
62
|
+
export declare function activityLines(ev: ParsedEvent, opts: {
|
|
63
|
+
showThinking: boolean;
|
|
64
|
+
}): string[];
|
|
65
|
+
/**
|
|
66
|
+
* partialResult is an accumulated snapshot (not a delta), so each update
|
|
67
|
+
* carries everything so far. Return only the newly-appended portion.
|
|
68
|
+
*/
|
|
69
|
+
export declare function newPortion(text: string, prev: string): string;
|
package/dist/delegate-tool.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ declare const DelegateParams: Type.TObject<{
|
|
|
13
13
|
cwd: Type.TOptional<Type.TString>;
|
|
14
14
|
model: Type.TOptional<Type.TString>;
|
|
15
15
|
async: Type.TOptional<Type.TBoolean>;
|
|
16
|
+
showThinking: Type.TOptional<Type.TBoolean>;
|
|
16
17
|
}>;
|
|
17
18
|
type DelegateArgs = Static<typeof DelegateParams>;
|
|
18
19
|
declare const CancelParams: Type.TObject<{
|
|
@@ -40,5 +41,7 @@ export declare function makeDelegateCancelTool(_pi: ExtensionAPI): ToolDefinitio
|
|
|
40
41
|
export declare function buildChildArgs(args: DelegateArgs, rolePrompt: string, ctx: ExtensionContext): Promise<{
|
|
41
42
|
cliArgs: string[];
|
|
42
43
|
tmpDir: string;
|
|
44
|
+
isAsync: boolean;
|
|
45
|
+
useJsonStream: boolean;
|
|
43
46
|
}>;
|
|
44
47
|
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Readable } from "node:stream";
|
|
2
|
+
export interface WatchdogOptions {
|
|
3
|
+
eofGraceMs: number;
|
|
4
|
+
idleMs: number;
|
|
5
|
+
timeoutMs: number;
|
|
6
|
+
killGraceMs: number;
|
|
7
|
+
}
|
|
8
|
+
export interface WatchdogHooks {
|
|
9
|
+
/** True once the run is finalized; watchdogs stop firing. */
|
|
10
|
+
isSettled(): boolean;
|
|
11
|
+
/** The child is about to be killed (SIGTERM). reason explains why. */
|
|
12
|
+
onKill(reason: string): void;
|
|
13
|
+
/** stdout EOF passed without the process exiting; force-finalize now. */
|
|
14
|
+
onEofGrace(): void;
|
|
15
|
+
}
|
|
16
|
+
export interface WatchdogHandle {
|
|
17
|
+
/** Re-arm the idle timer (call on every stdout data). */
|
|
18
|
+
poke(): void;
|
|
19
|
+
/** Stop all timers (call on finalize). */
|
|
20
|
+
dispose(): void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Guarantees a hung child process gets killed. A stuck child holds its stdout
|
|
24
|
+
* fd open, so stdout EOF never fires — hence the idle timer (no output for
|
|
25
|
+
* idleMs) is the main defense; the hard time limit and the EOF grace period
|
|
26
|
+
* cover the rest. Kill is SIGTERM, escalated to SIGKILL after killGraceMs.
|
|
27
|
+
*/
|
|
28
|
+
export declare function attachWatchdogs(child: {
|
|
29
|
+
kill(signal: NodeJS.Signals): boolean;
|
|
30
|
+
stdout: Readable | null;
|
|
31
|
+
}, hooks: WatchdogHooks, opts: WatchdogOptions): WatchdogHandle;
|