@xzzpig/pi-subagents 0.24.0 → 0.24.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/CHANGELOG.md +15 -0
- package/bundle/{chunk-UFNSLL5D.js → chunk-224WMDIV.js} +86 -10
- package/bundle/{chunk-7K3Z6DM7.js → chunk-4UH4WS4G.js} +4 -4
- package/bundle/{chunk-KD2IMFN4.js → chunk-BQ2OAB4Q.js} +1 -1
- package/bundle/{chunk-F3NSN7UH.js → chunk-CYY5UMJU.js} +9 -4
- package/bundle/{chunk-LPVUHUZ7.js → chunk-EUPJB4S7.js} +1 -1
- package/bundle/{chunk-T65XRVVM.js → chunk-FG6SQJAR.js} +2 -2
- package/bundle/{chunk-MYCL5QEJ.js → chunk-JEA2ZKUA.js} +2 -2
- package/bundle/{chunk-RK2HDPLK.js → chunk-LVWU2HOO.js} +1 -1
- package/bundle/{chunk-OTLRAB22.js → chunk-O4D5PBVI.js} +3 -3
- package/bundle/{chunk-NCWCVJLT.js → chunk-RU522D5W.js} +4 -4
- package/bundle/{chunk-3G4JXNZ4.js → chunk-TMHVDPYW.js} +2 -0
- package/bundle/{chunk-NTRJDXBC.js → chunk-X6LOM3Z4.js} +2 -2
- package/bundle/{chunk-OFGSZBHP.js → chunk-XWWUDWUW.js} +14 -6
- package/bundle/index.js +1 -1
- package/docs/goal-auto-continuation-gate.md +26 -0
- package/node_modules/@xzzpig/pi-components/CHANGELOG.md +12 -0
- package/node_modules/@xzzpig/pi-components/README.md +94 -0
- package/node_modules/@xzzpig/pi-components/dist/src/transcript-presenter.d.ts +186 -0
- package/node_modules/@xzzpig/pi-components/dist/src/transcript-presenter.js +693 -0
- package/node_modules/@xzzpig/pi-components/package.json +5 -1
- package/package.json +3 -3
- package/src/extension/index.js +12 -0
- package/src/goal-auto-continue-gate.d.ts +17 -0
- package/src/goal-auto-continue-gate.js +61 -0
- package/src/goal-auto-continue-state.d.ts +22 -0
- package/src/goal-auto-continue-state.js +20 -0
- package/src/runs/background/async-execution.d.ts +3 -1
- package/src/runs/background/async-execution.js +4 -0
- package/src/runs/background/async-job-tracker.js +5 -0
- package/src/runs/background/async-status.d.ts +2 -0
- package/src/runs/background/async-status.js +2 -0
- package/src/runs/background/notify.d.ts +2 -0
- package/src/runs/background/notify.js +5 -0
- package/src/runs/foreground/subagent-executor.js +4 -0
- package/src/shared/types.d.ts +2 -0
|
@@ -51,6 +51,100 @@ scrolling. Hosts keep ownership of terminal mouse-reporting setup, dialog
|
|
|
51
51
|
chrome, focus behavior, input controls, session lifecycle, and cancellation
|
|
52
52
|
policy. `Esc` handling is intentionally delegated to the host overlay.
|
|
53
53
|
|
|
54
|
+
### 有状态展示器(可选启用)
|
|
55
|
+
|
|
56
|
+
`@xzzpig/pi-components/transcript-presenter` 新增 `TranscriptPresenter`,供需要
|
|
57
|
+
真实流式状态、原生思考块点击和本地思考切换的宿主使用。上述无状态入口保持不变;
|
|
58
|
+
宿主通过导入第二个子路径显式启用。
|
|
59
|
+
|
|
60
|
+
展示器消费相同的 `TranscriptEntry` 值,并按用户条目保留一个原生
|
|
61
|
+
`UserMessageComponent`、按助手消息段保留一个原生 `AssistantMessageComponent`。
|
|
62
|
+
助手组件先以空内容构造,再通过 `updateContent(message, streaming)` 接收内容,因此
|
|
63
|
+
Pi 的原生流式状态会到达宿主侧补丁(例如 `pi-thinking-collapse`),而不是先渲染
|
|
64
|
+
一条已完成消息。只有段落文本或流式标志变化时才重新赋值内容;缩放和纯重绘保留组件
|
|
65
|
+
及其逐块点击状态。
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
import { SessionTranscript } from "@xzzpig/pi-components/transcript";
|
|
69
|
+
import { TranscriptPresenter } from "@xzzpig/pi-components/transcript-presenter";
|
|
70
|
+
|
|
71
|
+
const transcript = new SessionTranscript();
|
|
72
|
+
const presenter = new TranscriptPresenter({
|
|
73
|
+
theme,
|
|
74
|
+
// 复用 transcript 注册表,让工具 renderer 状态和展开点击跨帧保留。
|
|
75
|
+
// 仅在只读回放时省略;此时工具块回退为无状态的临时组件。
|
|
76
|
+
toolComponents: transcript.toolComponents,
|
|
77
|
+
assistantLabel: "Assistant",
|
|
78
|
+
// 省略 thinkingLabel 可保留 Pi 原生的 `Thinking...` 标签,折叠补丁会把
|
|
79
|
+
// 它替换成自己的 “click to expand” 提示。
|
|
80
|
+
});
|
|
81
|
+
presenter.attachTui(tui);
|
|
82
|
+
// 把 renderer 发起的工具重绘接到展示器修订号上。
|
|
83
|
+
transcript.toolComponents.attachTui({
|
|
84
|
+
requestRender: () => presenter.requestRender(),
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// 宿主的 transcript 版本变化时(或简单宿主每帧一次),渲染前先 sync。
|
|
88
|
+
// 对未变化条目的重复 sync 只做内容比较,不会改动展示修订号。
|
|
89
|
+
presenter.sync(transcript.entries);
|
|
90
|
+
const frame = presenter.render(innerWidth);
|
|
91
|
+
const visibleLines = frame.lines.slice(scrollOffset, scrollOffset + height);
|
|
92
|
+
|
|
93
|
+
// 鼠标路由:把可见视口行加上 scroll offset 换算到完整 transcript 空间,
|
|
94
|
+
// 再交给展示器分发。
|
|
95
|
+
const handled = presenter.handleMouse({
|
|
96
|
+
...mouseEvent,
|
|
97
|
+
y: mouseEvent.y - overlayChromeTop + scrollOffset,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// BTW 本地统一思考切换(在 overlay 绑定 Ctrl+T;不写 Pi 设置,也不碰主会话)。
|
|
101
|
+
const thinkingVisible = presenter.toggleThinkingVisibility();
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
`sync(entries)` 只更新发生变化的段,并清理条目已消失的组件。`render(width)` 返回
|
|
105
|
+
渲染行以及 `frame.rows`(组件行范围)、`frame.totalLines` 和 `frame.revision`;
|
|
106
|
+
宿主缓存应比较 `frame.revision` 与宽度。展示器自身的缓存会在条目变化、宽度变化、
|
|
107
|
+
`invalidate()`(主题变化)、思考切换和 `requestRender()`(组件发起的重绘)时失效。
|
|
108
|
+
|
|
109
|
+
鼠标处理使用 Pi 公开的 `Component.handleMouse` 路径:展示器把转录行映射到所属
|
|
110
|
+
原生组件,减去该行的 `top`,再转发事件。这样无需读取组件私有字段,即可保留 Pi
|
|
111
|
+
原生的逐块思考点击与工具展开。
|
|
112
|
+
|
|
113
|
+
思考控制:
|
|
114
|
+
|
|
115
|
+
- `thinkingVisible` 反映展示器的本地偏好。展示器初始为 `auto`:没有宿主补丁时
|
|
116
|
+
Pi 原生默认展开;存在折叠补丁时,流式内容保持可见,完成的消息折叠。
|
|
117
|
+
- `setThinkingVisible(visible)` 把显式本地偏好应用到每个保留的助手组件。隐藏使用
|
|
118
|
+
Pi 公开的 `setHideThinkingBlock(true)`,因此会清除原生的逐块覆盖。显示时先通过
|
|
119
|
+
同一个公开 setter 强制到已知的折叠状态,再通过原生思考 `MouseRegion`(经公开
|
|
120
|
+
的 `Container.children` 取得)分发一次点击。这会设置与用户点击相同的逐块覆盖,
|
|
121
|
+
因此即使宿主折叠补丁持续自动折叠,已完成消息也会展开。流式标志从不伪造,不读取
|
|
122
|
+
组件私有字段,也不修改折叠补丁。
|
|
123
|
+
- 新段继承显式的可见偏好:首次内容更新后,展示器应用相同的原生点击路径。
|
|
124
|
+
- 之后对某个思考块的真实点击仍然只切换该块,且该覆盖在内容更新、主题失效和缩放后
|
|
125
|
+
保持。
|
|
126
|
+
- `toggleThinkingVisibility()` 翻转偏好并返回新的可见性。从初始 `auto` 状态开始,
|
|
127
|
+
第一次切换隐藏,下一次展开所有保留的块。
|
|
128
|
+
- 该偏好只属于本展示器。它绝不写入 Pi 设置,也不改变主会话的思考偏好。
|
|
129
|
+
|
|
130
|
+
在 `AssistantMessageComponent` 没有思考 `MouseRegion` 的宿主(较旧的 Pi)上,
|
|
131
|
+
显示会降级为公开的 `setHideThinkingBlock(false)` 调用;内容与键盘切换仍然可用,
|
|
132
|
+
但宿主折叠补丁仍可再次折叠已完成消息。
|
|
133
|
+
|
|
134
|
+
生命周期:
|
|
135
|
+
|
|
136
|
+
- `attachTui(tui)` / `detachTui()` 接通重绘转发。分离已关闭的 overlay 会保留线程
|
|
137
|
+
状态,包括展开选择。
|
|
138
|
+
- `invalidate()` 为主题变化重新渲染原生组件,而不重新初始化宿主全局主题。
|
|
139
|
+
- `clear()` 在线程被清空时丢弃保留的消息组件与布局。
|
|
140
|
+
- `dispose()` 释放组件、分离 TUI,并让后续调用变为 no-op;在线程/会话本身销毁时
|
|
141
|
+
使用。
|
|
142
|
+
|
|
143
|
+
当宿主侧补丁自动折叠已完成的思考(例如 `pi-thinking-collapse`)时,展示器保留该
|
|
144
|
+
补丁的流式与完成行为及其原生逐块点击覆盖。统一切换通过原生点击路径为保留块显式
|
|
145
|
+
覆盖该自动折叠,新块继承该显式偏好。没有此类补丁时,已完成的思考遵循 Pi 原生
|
|
146
|
+
默认值(展开),本地切换会展开/收起每个保留块。
|
|
147
|
+
|
|
54
148
|
### History replay
|
|
55
149
|
|
|
56
150
|
Hosts that rebuild a transcript from persisted records write entries through
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { type TuiMouseEvent } from "@earendil-works/pi-tui";
|
|
2
|
+
import { type NativeToolRenderOptions, type ToolComponentLookup, type TranscriptEntry, type TranscriptTheme, type TranscriptTui } from "./transcript.js";
|
|
3
|
+
/**
|
|
4
|
+
* Options for the opt-in stateful presenter.
|
|
5
|
+
*
|
|
6
|
+
* The presenter owns user/assistant components; tool components stay owned by
|
|
7
|
+
* the caller's `TranscriptToolComponents` registry so live tool updates keep
|
|
8
|
+
* their existing renderer state. When no registry is supplied, tool calls are
|
|
9
|
+
* rendered through stateless ad-hoc components, exactly like
|
|
10
|
+
* `renderTranscriptLines`.
|
|
11
|
+
*/
|
|
12
|
+
export interface TranscriptPresenterOptions extends NativeToolRenderOptions {
|
|
13
|
+
theme: TranscriptTheme;
|
|
14
|
+
emptyText?: string;
|
|
15
|
+
assistantLabel?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Collapsed-label text used while thinking is hidden. Defaults to Pi's
|
|
18
|
+
* native `Thinking...` label so collapse patches can replace it with their
|
|
19
|
+
* own expand affordance instead of treating it as a custom label.
|
|
20
|
+
*/
|
|
21
|
+
thinkingLabel?: string;
|
|
22
|
+
assistantBadgeBackground?: string;
|
|
23
|
+
assistantBadgeForeground?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Start with the presenter's local thinking preference hidden. When omitted
|
|
26
|
+
* (or false) the presenter starts in `auto`: host patches such as
|
|
27
|
+
* `pi-thinking-collapse` keep deciding per-message visibility until the host
|
|
28
|
+
* calls `setThinkingVisible`/`toggleThinkingVisibility`.
|
|
29
|
+
*/
|
|
30
|
+
hideThinkingBlock?: boolean;
|
|
31
|
+
/** Persistent native tool components keyed by tool call id. */
|
|
32
|
+
toolComponents?: ToolComponentLookup;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A rendered, mouse-addressable component range in the full transcript.
|
|
36
|
+
* `top` is the zero-based line offset including any scroll offset the host has
|
|
37
|
+
* not applied; callers translate visible viewport rows into this space.
|
|
38
|
+
*/
|
|
39
|
+
export type TranscriptPresenterRow = {
|
|
40
|
+
kind: "user";
|
|
41
|
+
entryId: number;
|
|
42
|
+
top: number;
|
|
43
|
+
height: number;
|
|
44
|
+
} | {
|
|
45
|
+
kind: "assistant";
|
|
46
|
+
/** Stable id of the assistant message segment (its first entry id). */
|
|
47
|
+
segmentId: number;
|
|
48
|
+
entryIds: readonly number[];
|
|
49
|
+
top: number;
|
|
50
|
+
height: number;
|
|
51
|
+
} | {
|
|
52
|
+
kind: "tool";
|
|
53
|
+
entryId: number;
|
|
54
|
+
toolCallId: string;
|
|
55
|
+
top: number;
|
|
56
|
+
height: number;
|
|
57
|
+
};
|
|
58
|
+
/** One rendered frame plus the layout needed to route mouse events. */
|
|
59
|
+
export interface TranscriptPresenterFrame {
|
|
60
|
+
lines: string[];
|
|
61
|
+
rows: readonly TranscriptPresenterRow[];
|
|
62
|
+
totalLines: number;
|
|
63
|
+
width: number;
|
|
64
|
+
/**
|
|
65
|
+
* Display revision the lines were rendered at. A component that requests a
|
|
66
|
+
* repaint during rendering can raise the presenter's current revision above
|
|
67
|
+
* this value; callers then re-render instead of reusing the lines.
|
|
68
|
+
*/
|
|
69
|
+
revision: number;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Opt-in stateful transcript presenter.
|
|
73
|
+
*
|
|
74
|
+
* It consumes the same `TranscriptEntry` values as `renderTranscriptLines`,
|
|
75
|
+
* but keeps one native `UserMessageComponent` per user entry and one native
|
|
76
|
+
* `AssistantMessageComponent` per assistant message segment. Assistant
|
|
77
|
+
* components are constructed empty and receive content through
|
|
78
|
+
* `updateContent(message, streaming)`, so a host-side thinking-collapse patch
|
|
79
|
+
* observes the real streaming state instead of an already-finished message.
|
|
80
|
+
*
|
|
81
|
+
* The presenter owns its display revision: entry changes, thinking toggles,
|
|
82
|
+
* theme invalidation, width changes, and component-initiated repaint requests
|
|
83
|
+
* all raise it. `render` reuses its line cache only while that revision and
|
|
84
|
+
* the width are unchanged; content is never re-assigned on a pure repaint or
|
|
85
|
+
* resize.
|
|
86
|
+
*
|
|
87
|
+
* Mouse handling is normalized: pass a `TuiMouseEvent` whose `y` is a row in
|
|
88
|
+
* the full transcript (visible row + scroll offset). The presenter maps it to
|
|
89
|
+
* the owning component and forwards it through the component's public
|
|
90
|
+
* `handleMouse`, so Pi's native thinking-block and tool-expansion click paths
|
|
91
|
+
* keep working without private fields.
|
|
92
|
+
*/
|
|
93
|
+
export declare class TranscriptPresenter {
|
|
94
|
+
private readonly options;
|
|
95
|
+
private readonly assistantComponents;
|
|
96
|
+
private readonly assistantContent;
|
|
97
|
+
private readonly userComponents;
|
|
98
|
+
private readonly userText;
|
|
99
|
+
private readonly toolState;
|
|
100
|
+
private blocks;
|
|
101
|
+
private blockIdentities;
|
|
102
|
+
private rows;
|
|
103
|
+
private renderedToolComponents;
|
|
104
|
+
private cachedFrame;
|
|
105
|
+
private renderedWidth;
|
|
106
|
+
private renderedRevision;
|
|
107
|
+
private revisionValue;
|
|
108
|
+
private thinkingPreference;
|
|
109
|
+
private readonly expandedSegments;
|
|
110
|
+
private attachedTui;
|
|
111
|
+
private disposed;
|
|
112
|
+
constructor(options: TranscriptPresenterOptions);
|
|
113
|
+
/** Latest display revision. */
|
|
114
|
+
get revision(): number;
|
|
115
|
+
/** Retained presenter-owned message components (user + assistant). */
|
|
116
|
+
get componentCount(): number;
|
|
117
|
+
/**
|
|
118
|
+
* The presenter's local thinking preference. This is not the host patch's
|
|
119
|
+
* effective per-message state: in `auto` a collapse patch may still hide a
|
|
120
|
+
* completed message while the preference remains "visible".
|
|
121
|
+
*/
|
|
122
|
+
get thinkingVisible(): boolean;
|
|
123
|
+
/** Wires the host TUI that receives repaint requests. */
|
|
124
|
+
attachTui(tui: TranscriptTui): void;
|
|
125
|
+
/** Stops forwarding repaint requests without discarding retained state. */
|
|
126
|
+
detachTui(): void;
|
|
127
|
+
/**
|
|
128
|
+
* Marks the display dirty and asks the attached TUI to repaint. Hosts wire
|
|
129
|
+
* tool components' repaint requests here so renderer-driven invalidations
|
|
130
|
+
* bypass the presenter's line cache.
|
|
131
|
+
*/
|
|
132
|
+
requestRender(): void;
|
|
133
|
+
/**
|
|
134
|
+
* Synchronizes the presenter with the current entries. Components are
|
|
135
|
+
* created or updated only when their segment/content actually changed; a
|
|
136
|
+
* repeated sync of unchanged entries leaves the display revision alone.
|
|
137
|
+
*/
|
|
138
|
+
sync(entries: readonly TranscriptEntry[]): number;
|
|
139
|
+
/**
|
|
140
|
+
* Renders the synced entries at `width`. When nothing changed since the last
|
|
141
|
+
* frame, the cached frame is returned unchanged.
|
|
142
|
+
*/
|
|
143
|
+
render(width: number): TranscriptPresenterFrame;
|
|
144
|
+
/**
|
|
145
|
+
* Routes a normalized mouse event (transcript-space `y`) to the component
|
|
146
|
+
* whose row contains it. Returns whether the component handled the event.
|
|
147
|
+
*/
|
|
148
|
+
handleMouse(event: TuiMouseEvent): boolean;
|
|
149
|
+
/**
|
|
150
|
+
* Applies the presenter's local thinking preference to every retained
|
|
151
|
+
* assistant component.
|
|
152
|
+
*
|
|
153
|
+
* Hiding uses the public `setHideThinkingBlock(true)`, which also clears
|
|
154
|
+
* native per-block overrides. Showing first forces the known collapsed state
|
|
155
|
+
* through the same public setter, then dispatches the native thinking-block
|
|
156
|
+
* click through `MouseRegion.handleMouse`. That sets the same per-block
|
|
157
|
+
* override a user click sets, so completed messages expand even while a
|
|
158
|
+
* host collapse patch keeps auto-collapsing them. No private component field
|
|
159
|
+
* is read and the streaming flag is never faked.
|
|
160
|
+
*/
|
|
161
|
+
setThinkingVisible(visible: boolean): void;
|
|
162
|
+
/** Flips the local thinking preference and returns the new visibility. */
|
|
163
|
+
toggleThinkingVisibility(): boolean;
|
|
164
|
+
/**
|
|
165
|
+
* Invalidates native components for a theme change and raises the display
|
|
166
|
+
* revision. The host's global theme is never re-initialized here.
|
|
167
|
+
*/
|
|
168
|
+
invalidate(): void;
|
|
169
|
+
/** Drops retained message components and rendered layout. */
|
|
170
|
+
clear(): void;
|
|
171
|
+
/**
|
|
172
|
+
* Releases every retained component and detaches the TUI. Idempotent; later
|
|
173
|
+
* calls to `sync`, `render`, and `handleMouse` degrade to no-ops.
|
|
174
|
+
*/
|
|
175
|
+
dispose(): void;
|
|
176
|
+
private dropRetainedState;
|
|
177
|
+
private ensureAssistantComponent;
|
|
178
|
+
/**
|
|
179
|
+
* Expands every thinking block in `component` through the native public
|
|
180
|
+
* click path. When the host has no thinking `MouseRegion` (an older Pi), it
|
|
181
|
+
* degrades to the public visibility setter.
|
|
182
|
+
*/
|
|
183
|
+
private expandThinking;
|
|
184
|
+
private componentForRow;
|
|
185
|
+
private renderBlocks;
|
|
186
|
+
}
|