@timmyjl12/pi-subagents 0.0.0-stage → 0.20.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.md +827 -0
- package/CONTRIBUTING.md +72 -0
- package/LICENSE +21 -0
- package/README.md +1079 -2
- package/SECURITY.md +97 -0
- package/dist/abortable.d.ts +12 -0
- package/dist/abortable.js +42 -0
- package/dist/active-agents-prompt.d.ts +18 -0
- package/dist/active-agents-prompt.js +34 -0
- package/dist/advisor-status.d.ts +16 -0
- package/dist/advisor-status.js +74 -0
- package/dist/agent-color.d.ts +35 -0
- package/dist/agent-color.js +123 -0
- package/dist/agent-file-toggle.d.ts +125 -0
- package/dist/agent-file-toggle.js +264 -0
- package/dist/agent-manager.d.ts +485 -0
- package/dist/agent-manager.js +1380 -0
- package/dist/agent-runner.d.ts +319 -0
- package/dist/agent-runner.js +1128 -0
- package/dist/agent-types.d.ts +119 -0
- package/dist/agent-types.js +286 -0
- package/dist/child-context.d.ts +15 -0
- package/dist/child-context.js +181 -0
- package/dist/child-session-shutdown.d.ts +3 -0
- package/dist/child-session-shutdown.js +48 -0
- package/dist/context.d.ts +12 -0
- package/dist/context.js +56 -0
- package/dist/cross-extension-rpc.d.ts +66 -0
- package/dist/cross-extension-rpc.js +138 -0
- package/dist/custom-agents.d.ts +54 -0
- package/dist/custom-agents.js +386 -0
- package/dist/default-agents.d.ts +7 -0
- package/dist/default-agents.js +125 -0
- package/dist/enabled-models.d.ts +49 -0
- package/dist/enabled-models.js +145 -0
- package/dist/env.d.ts +6 -0
- package/dist/env.js +28 -0
- package/dist/error-log.d.ts +58 -0
- package/dist/error-log.js +168 -0
- package/dist/group-join.d.ts +32 -0
- package/dist/group-join.js +116 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +3896 -0
- package/dist/invocation-config.d.ts +137 -0
- package/dist/invocation-config.js +129 -0
- package/dist/memory.d.ts +53 -0
- package/dist/memory.js +165 -0
- package/dist/mention-clone.d.ts +87 -0
- package/dist/mention-clone.js +178 -0
- package/dist/mention.d.ts +81 -0
- package/dist/mention.js +131 -0
- package/dist/model-resolver.d.ts +36 -0
- package/dist/model-resolver.js +95 -0
- package/dist/model-scope.d.ts +49 -0
- package/dist/model-scope.js +48 -0
- package/dist/nested-tools.d.ts +55 -0
- package/dist/nested-tools.js +299 -0
- package/dist/output-diagnostics.d.ts +11 -0
- package/dist/output-diagnostics.js +64 -0
- package/dist/output-file.d.ts +53 -0
- package/dist/output-file.js +248 -0
- package/dist/prompts.d.ts +61 -0
- package/dist/prompts.js +94 -0
- package/dist/recovery.d.ts +56 -0
- package/dist/recovery.js +341 -0
- package/dist/schedule-store.d.ts +44 -0
- package/dist/schedule-store.js +210 -0
- package/dist/schedule.d.ts +109 -0
- package/dist/schedule.js +359 -0
- package/dist/settings.d.ts +360 -0
- package/dist/settings.js +251 -0
- package/dist/skill-loader.d.ts +24 -0
- package/dist/skill-loader.js +93 -0
- package/dist/standalone-fallback.d.ts +30 -0
- package/dist/standalone-fallback.js +239 -0
- package/dist/status-note.d.ts +61 -0
- package/dist/status-note.js +85 -0
- package/dist/structured-output.d.ts +61 -0
- package/dist/structured-output.js +112 -0
- package/dist/terminal-progress.d.ts +115 -0
- package/dist/terminal-progress.js +206 -0
- package/dist/types.d.ts +382 -0
- package/dist/types.js +5 -0
- package/dist/ui/agent-mention.d.ts +82 -0
- package/dist/ui/agent-mention.js +187 -0
- package/dist/ui/agent-widget.d.ts +235 -0
- package/dist/ui/agent-widget.js +652 -0
- package/dist/ui/conversation-viewer.d.ts +105 -0
- package/dist/ui/conversation-viewer.js +540 -0
- package/dist/ui/fleet-list.d.ts +183 -0
- package/dist/ui/fleet-list.js +494 -0
- package/dist/ui/fleet-overlay.d.ts +172 -0
- package/dist/ui/fleet-overlay.js +691 -0
- package/dist/ui/native-transcript.d.ts +33 -0
- package/dist/ui/native-transcript.js +230 -0
- package/dist/ui/schedule-menu.d.ts +16 -0
- package/dist/ui/schedule-menu.js +94 -0
- package/dist/ui/select-item.d.ts +27 -0
- package/dist/ui/select-item.js +34 -0
- package/dist/ui/tool-progress.d.ts +22 -0
- package/dist/ui/tool-progress.js +56 -0
- package/dist/ui/viewer-keys.d.ts +20 -0
- package/dist/ui/viewer-keys.js +17 -0
- package/dist/ui/workflow-card.d.ts +175 -0
- package/dist/ui/workflow-card.js +332 -0
- package/dist/ui/workflow-dialog.d.ts +305 -0
- package/dist/ui/workflow-dialog.js +843 -0
- package/dist/ui/workflow-menu.d.ts +60 -0
- package/dist/ui/workflow-menu.js +147 -0
- package/dist/usage.d.ts +135 -0
- package/dist/usage.js +120 -0
- package/dist/workflow/collisions.d.ts +95 -0
- package/dist/workflow/collisions.js +88 -0
- package/dist/workflow/entry.d.ts +32 -0
- package/dist/workflow/entry.js +29 -0
- package/dist/workflow/host.d.ts +62 -0
- package/dist/workflow/host.js +363 -0
- package/dist/workflow/journal.d.ts +97 -0
- package/dist/workflow/journal.js +120 -0
- package/dist/workflow/json-schema.d.ts +51 -0
- package/dist/workflow/json-schema.js +111 -0
- package/dist/workflow/meta.d.ts +67 -0
- package/dist/workflow/meta.js +317 -0
- package/dist/workflow/progress.d.ts +224 -0
- package/dist/workflow/progress.js +361 -0
- package/dist/workflow/runtime.d.ts +334 -0
- package/dist/workflow/runtime.js +830 -0
- package/dist/workflow/saved.d.ts +90 -0
- package/dist/workflow/saved.js +203 -0
- package/dist/workflow/task.d.ts +136 -0
- package/dist/workflow/task.js +207 -0
- package/dist/workflow/tool-description.d.ts +38 -0
- package/dist/workflow/tool-description.js +199 -0
- package/dist/workflow/worker-source.d.ts +47 -0
- package/dist/workflow/worker-source.js +778 -0
- package/dist/worktree.d.ts +52 -0
- package/dist/worktree.js +164 -0
- package/dist/xml.d.ts +10 -0
- package/dist/xml.js +12 -0
- package/docs/FORK.md +40 -0
- package/docs/recovery.md +62 -0
- package/docs/rpc.md +189 -0
- package/docs/workflows.md +437 -0
- package/examples/agent-tool-description.md +43 -0
- package/examples/workflows/compose.js +51 -0
- package/examples/workflows/fan-out-audit.js +47 -0
- package/examples/workflows/gated-fix.js +60 -0
- package/examples/workflows/lib/count-child.js +27 -0
- package/examples/workflows/review-panel.js +63 -0
- package/examples/workflows/structured-findings.js +78 -0
- package/package.json +75 -6
- package/src/abortable.ts +43 -0
- package/src/active-agents-prompt.ts +39 -0
- package/src/advisor-status.ts +74 -0
- package/src/agent-color.ts +161 -0
- package/src/agent-file-toggle.ts +273 -0
- package/src/agent-manager.ts +1601 -0
- package/src/agent-runner.ts +1372 -0
- package/src/agent-types.ts +345 -0
- package/src/child-context.ts +173 -0
- package/src/child-session-shutdown.ts +46 -0
- package/src/context.ts +58 -0
- package/src/cross-extension-rpc.ts +198 -0
- package/src/custom-agents.ts +417 -0
- package/src/default-agents.ts +129 -0
- package/src/enabled-models.ts +180 -0
- package/src/env.ts +33 -0
- package/src/error-log.ts +193 -0
- package/src/group-join.ts +141 -0
- package/src/index.ts +4218 -0
- package/src/invocation-config.ts +230 -0
- package/src/memory.ts +179 -0
- package/src/mention-clone.ts +221 -0
- package/src/mention.ts +141 -0
- package/src/model-resolver.ts +118 -0
- package/src/model-scope.ts +70 -0
- package/src/nested-tools.ts +422 -0
- package/src/output-diagnostics.ts +68 -0
- package/src/output-file.ts +258 -0
- package/src/prompts.ts +151 -0
- package/src/recovery.ts +320 -0
- package/src/schedule-store.ts +201 -0
- package/src/schedule.ts +386 -0
- package/src/settings.ts +587 -0
- package/src/skill-loader.ts +102 -0
- package/src/standalone-fallback.ts +195 -0
- package/src/status-note.ts +90 -0
- package/src/structured-output.ts +130 -0
- package/src/terminal-progress.ts +215 -0
- package/src/types.ts +394 -0
- package/src/ui/agent-mention.ts +216 -0
- package/src/ui/agent-widget.ts +732 -0
- package/src/ui/conversation-viewer.ts +523 -0
- package/src/ui/fleet-list.ts +563 -0
- package/src/ui/fleet-overlay.ts +847 -0
- package/src/ui/native-transcript.ts +220 -0
- package/src/ui/schedule-menu.ts +105 -0
- package/src/ui/select-item.ts +45 -0
- package/src/ui/tool-progress.ts +67 -0
- package/src/ui/viewer-keys.ts +39 -0
- package/src/ui/workflow-card.ts +470 -0
- package/src/ui/workflow-dialog.ts +1115 -0
- package/src/ui/workflow-menu.ts +193 -0
- package/src/usage.ts +167 -0
- package/src/workflow/collisions.ts +123 -0
- package/src/workflow/entry.ts +47 -0
- package/src/workflow/host.ts +404 -0
- package/src/workflow/journal.ts +164 -0
- package/src/workflow/json-schema.ts +128 -0
- package/src/workflow/meta.ts +325 -0
- package/src/workflow/progress.ts +550 -0
- package/src/workflow/runtime.ts +1219 -0
- package/src/workflow/saved.ts +217 -0
- package/src/workflow/task.ts +302 -0
- package/src/workflow/tool-description.ts +200 -0
- package/src/workflow/worker-source.ts +781 -0
- package/src/worktree.ts +205 -0
- package/src/xml.ts +13 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type AgentSession, type AgentSessionEvent } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { type Component, type MarkdownTheme, type TUI, type TuiMouseEvent } from "@earendil-works/pi-tui";
|
|
3
|
+
type AgentMessage = AgentSession["messages"][number];
|
|
4
|
+
export declare class NativeTranscript implements Component {
|
|
5
|
+
private session;
|
|
6
|
+
private tui;
|
|
7
|
+
private markdownTheme;
|
|
8
|
+
private entries;
|
|
9
|
+
private tools;
|
|
10
|
+
private seen;
|
|
11
|
+
private streaming;
|
|
12
|
+
private readonly builtIns;
|
|
13
|
+
private expanded;
|
|
14
|
+
constructor(session: AgentSession, tui: TUI, markdownTheme: MarkdownTheme);
|
|
15
|
+
/** Synchronous replay, called after subscribing. No await/gap between snapshot and event delivery. */
|
|
16
|
+
hydrate(): void;
|
|
17
|
+
handleEvent(event: AgentSessionEvent): void;
|
|
18
|
+
private renderers;
|
|
19
|
+
private get cwd();
|
|
20
|
+
private ensureTool;
|
|
21
|
+
private updateTool;
|
|
22
|
+
private updateAssistant;
|
|
23
|
+
private addMessage;
|
|
24
|
+
/** Inspection uses the same live source, not only committed history. */
|
|
25
|
+
inspectionMessages(): (AgentMessage & {
|
|
26
|
+
viewerElided?: number;
|
|
27
|
+
})[];
|
|
28
|
+
toggleExpanded(): void;
|
|
29
|
+
render(width: number): string[];
|
|
30
|
+
handleMouse(event: TuiMouseEvent): import("@earendil-works/pi-tui").TuiMouseEventResult | undefined;
|
|
31
|
+
invalidate(): void;
|
|
32
|
+
}
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { AssistantMessageComponent, CustomMessageComponent, createBashToolDefinition, createEditToolDefinition, createFindToolDefinition, createGrepToolDefinition, createLsToolDefinition, createPowerShellToolDefinition, createReadToolDefinition, createWriteToolDefinition, ToolExecutionComponent, UserMessageComponent, } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { Text, truncateToWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
3
|
+
import { extractText } from "../context.js";
|
|
4
|
+
import { boundToolResult, getToolProgress, RESULT_MAX_CHARS, truncationNote } from "./tool-progress.js";
|
|
5
|
+
const factories = {
|
|
6
|
+
read: createReadToolDefinition, bash: createBashToolDefinition, powershell: createPowerShellToolDefinition,
|
|
7
|
+
edit: createEditToolDefinition, write: createWriteToolDefinition, grep: createGrepToolDefinition,
|
|
8
|
+
find: createFindToolDefinition, ls: createLsToolDefinition,
|
|
9
|
+
};
|
|
10
|
+
export class NativeTranscript {
|
|
11
|
+
session;
|
|
12
|
+
tui;
|
|
13
|
+
markdownTheme;
|
|
14
|
+
entries = [];
|
|
15
|
+
tools = new Map();
|
|
16
|
+
seen = new WeakSet();
|
|
17
|
+
streaming;
|
|
18
|
+
builtIns = new Map();
|
|
19
|
+
expanded = false;
|
|
20
|
+
constructor(session, tui, markdownTheme) {
|
|
21
|
+
this.session = session;
|
|
22
|
+
this.tui = tui;
|
|
23
|
+
this.markdownTheme = markdownTheme;
|
|
24
|
+
}
|
|
25
|
+
/** Synchronous replay, called after subscribing. No await/gap between snapshot and event delivery. */
|
|
26
|
+
hydrate() {
|
|
27
|
+
this.entries = [];
|
|
28
|
+
this.tools.clear();
|
|
29
|
+
this.seen = new WeakSet();
|
|
30
|
+
this.streaming = undefined;
|
|
31
|
+
for (const message of this.session.messages)
|
|
32
|
+
this.addMessage(message);
|
|
33
|
+
const partial = this.session.agent?.state.streamingMessage;
|
|
34
|
+
if (partial?.role === "assistant" && !this.seen.has(partial))
|
|
35
|
+
this.updateAssistant(partial, true);
|
|
36
|
+
for (const progress of getToolProgress(this.session)) {
|
|
37
|
+
const entry = this.ensureTool(progress.toolCallId, progress.toolName, progress.args);
|
|
38
|
+
entry.component.markExecutionStarted();
|
|
39
|
+
entry.component.setArgsComplete();
|
|
40
|
+
if (progress.result)
|
|
41
|
+
this.updateTool(progress.toolCallId, progress.result, true, progress.elided);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
handleEvent(event) {
|
|
45
|
+
if (event.type === "message_start" || event.type === "message_end") {
|
|
46
|
+
if (event.message.role === "assistant") {
|
|
47
|
+
this.updateAssistant(event.message, event.type === "message_start");
|
|
48
|
+
}
|
|
49
|
+
else if (event.type === "message_end" || event.message.role === "user") {
|
|
50
|
+
this.addMessage(event.message);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else if (event.type === "message_update" && event.message.role === "assistant") {
|
|
54
|
+
this.updateAssistant(event.message, true);
|
|
55
|
+
}
|
|
56
|
+
else if (event.type === "tool_execution_start" || event.type === "tool_execution_update") {
|
|
57
|
+
const entry = this.ensureTool(event.toolCallId, event.toolName, event.args);
|
|
58
|
+
entry.component.markExecutionStarted();
|
|
59
|
+
entry.component.setArgsComplete();
|
|
60
|
+
if (event.type === "tool_execution_update")
|
|
61
|
+
this.updateTool(event.toolCallId, { ...event.partialResult, isError: false }, true);
|
|
62
|
+
}
|
|
63
|
+
else if (event.type === "tool_execution_end") {
|
|
64
|
+
this.ensureTool(event.toolCallId, event.toolName, {});
|
|
65
|
+
this.updateTool(event.toolCallId, { ...event.result, isError: event.isError }, false);
|
|
66
|
+
}
|
|
67
|
+
else if (event.type === "compaction_end" && event.result && !event.aborted) {
|
|
68
|
+
this.hydrate();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
renderers(name) {
|
|
72
|
+
const definition = this.session.getToolDefinition?.(name);
|
|
73
|
+
if (!this.builtIns.has(name) && Object.hasOwn(factories, name)) {
|
|
74
|
+
// Public factories provide the callbacks missing from session built-ins. Never execute them.
|
|
75
|
+
this.builtIns.set(name, factories[name](this.cwd));
|
|
76
|
+
}
|
|
77
|
+
const fallback = this.builtIns.get(name);
|
|
78
|
+
return definition ? {
|
|
79
|
+
...definition,
|
|
80
|
+
renderCall: definition.renderCall ?? fallback?.renderCall,
|
|
81
|
+
renderResult: definition.renderResult ?? fallback?.renderResult,
|
|
82
|
+
} : fallback;
|
|
83
|
+
}
|
|
84
|
+
get cwd() { return this.session.sessionManager?.getCwd() ?? process.cwd(); }
|
|
85
|
+
ensureTool(id, name, args) {
|
|
86
|
+
const existing = this.tools.get(id);
|
|
87
|
+
if (existing)
|
|
88
|
+
return existing;
|
|
89
|
+
const component = new ToolExecutionComponent(name, id, args, {
|
|
90
|
+
showImages: this.session.settingsManager?.getShowImages() ?? true,
|
|
91
|
+
}, this.renderers(name), this.tui, this.cwd);
|
|
92
|
+
component.setExpanded(this.expanded);
|
|
93
|
+
const entry = {
|
|
94
|
+
component, name, args, top: 0, height: 0,
|
|
95
|
+
raw: () => `${name} ${JSON.stringify(entry.args)}\n${entry.result?.content.filter(p => p.type === "text").map(p => p.text ?? "").join("\n") ?? ""}`,
|
|
96
|
+
};
|
|
97
|
+
this.entries.push(entry);
|
|
98
|
+
this.tools.set(id, entry);
|
|
99
|
+
return entry;
|
|
100
|
+
}
|
|
101
|
+
updateTool(id, result, partial, alreadyElided = 0) {
|
|
102
|
+
const entry = this.tools.get(id);
|
|
103
|
+
if (!entry)
|
|
104
|
+
return;
|
|
105
|
+
const bounded = boundToolResult(result);
|
|
106
|
+
entry.result = bounded.result;
|
|
107
|
+
entry.elided = bounded.elided + alreadyElided;
|
|
108
|
+
entry.component.updateResult(bounded.result, partial);
|
|
109
|
+
}
|
|
110
|
+
updateAssistant(message, partial) {
|
|
111
|
+
if (!this.streaming && this.seen.has(message))
|
|
112
|
+
return;
|
|
113
|
+
if (!this.streaming) {
|
|
114
|
+
const component = new AssistantMessageComponent(undefined, this.session.settingsManager?.getHideThinkingBlock() ?? false, this.markdownTheme, undefined, this.session.settingsManager?.getOutputPad() ?? 1, this.session.extensionRunner?.getMarkdownTransformers());
|
|
115
|
+
const entry = { component, raw: () => extractText(message.content), top: 0, height: 0 };
|
|
116
|
+
this.streaming = { message, entry, component };
|
|
117
|
+
this.entries.push(entry);
|
|
118
|
+
}
|
|
119
|
+
const current = this.streaming;
|
|
120
|
+
current.message = message;
|
|
121
|
+
current.entry.raw = () => message.content.map(p => p.type === "thinking" ? p.thinking : p.type === "text" ? p.text : "").join("\n");
|
|
122
|
+
current.component.updateContent(message, partial);
|
|
123
|
+
for (const part of message.content) {
|
|
124
|
+
if (part.type !== "toolCall")
|
|
125
|
+
continue;
|
|
126
|
+
const entry = this.ensureTool(part.id, part.name, part.arguments);
|
|
127
|
+
entry.args = part.arguments;
|
|
128
|
+
entry.component.updateArgs(part.arguments);
|
|
129
|
+
if (!partial)
|
|
130
|
+
entry.component.setArgsComplete();
|
|
131
|
+
}
|
|
132
|
+
if (!partial) {
|
|
133
|
+
this.seen.add(message);
|
|
134
|
+
this.streaming = undefined;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
addMessage(message) {
|
|
138
|
+
if (this.seen.has(message))
|
|
139
|
+
return;
|
|
140
|
+
if (message.role === "assistant") {
|
|
141
|
+
this.updateAssistant(message, false);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
this.seen.add(message);
|
|
145
|
+
if (message.role === "toolResult") {
|
|
146
|
+
const entry = this.ensureTool(message.toolCallId, message.toolName, {});
|
|
147
|
+
entry.component.setArgsComplete();
|
|
148
|
+
this.updateTool(message.toolCallId, message, false);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
let component;
|
|
152
|
+
let raw;
|
|
153
|
+
if (message.role === "user") {
|
|
154
|
+
const text = typeof message.content === "string" ? message.content : extractText(message.content);
|
|
155
|
+
raw = () => text;
|
|
156
|
+
component = new UserMessageComponent(text, this.markdownTheme, this.session.settingsManager?.getOutputPad() ?? 1, this.session.extensionRunner?.getMarkdownTransformers());
|
|
157
|
+
}
|
|
158
|
+
else if (message.role === "custom") {
|
|
159
|
+
if (!message.display)
|
|
160
|
+
return;
|
|
161
|
+
raw = () => typeof message.content === "string" ? message.content : extractText(message.content);
|
|
162
|
+
component = new CustomMessageComponent(message, this.session.extensionRunner?.getMessageRenderer(message.customType), this.markdownTheme, this.session.settingsManager?.getOutputPad() ?? 1);
|
|
163
|
+
}
|
|
164
|
+
else if (message.role === "bashExecution") {
|
|
165
|
+
raw = () => `$ ${message.command}\n${message.output.slice(0, RESULT_MAX_CHARS)}`;
|
|
166
|
+
component = new Text(raw(), 0, 0);
|
|
167
|
+
this.entries.push({ component, raw, top: 0, height: 0, elided: Math.max(0, message.output.length - RESULT_MAX_CHARS) });
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
else if (message.role === "compactionSummary" || message.role === "branchSummary") {
|
|
171
|
+
raw = () => message.summary;
|
|
172
|
+
component = new Text(raw(), 0, 0);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
this.entries.push({ component, raw, top: 0, height: 0 });
|
|
178
|
+
}
|
|
179
|
+
/** Inspection uses the same live source, not only committed history. */
|
|
180
|
+
inspectionMessages() {
|
|
181
|
+
const messages = [...this.session.messages];
|
|
182
|
+
if (this.streaming && !messages.includes(this.streaming.message))
|
|
183
|
+
messages.push(this.streaming.message);
|
|
184
|
+
const committed = new Set(messages.filter(m => m.role === "toolResult").map(m => m.toolCallId));
|
|
185
|
+
for (const [id, entry] of this.tools) {
|
|
186
|
+
if (!entry.result || committed.has(id))
|
|
187
|
+
continue;
|
|
188
|
+
messages.push({ role: "toolResult", toolCallId: id, toolName: entry.name,
|
|
189
|
+
content: entry.result.content, details: entry.result.details,
|
|
190
|
+
isError: entry.result.isError, timestamp: 0, viewerElided: entry.elided });
|
|
191
|
+
}
|
|
192
|
+
return messages;
|
|
193
|
+
}
|
|
194
|
+
toggleExpanded() {
|
|
195
|
+
this.expanded = !this.expanded;
|
|
196
|
+
for (const entry of this.tools.values())
|
|
197
|
+
entry.component.setExpanded(this.expanded);
|
|
198
|
+
}
|
|
199
|
+
render(width) {
|
|
200
|
+
const lines = [];
|
|
201
|
+
for (const entry of this.entries) {
|
|
202
|
+
entry.top = lines.length;
|
|
203
|
+
if (entry.failed && !entry.raw().startsWith(entry.failedPrefix ?? ""))
|
|
204
|
+
entry.failed = false;
|
|
205
|
+
try {
|
|
206
|
+
lines.push(...(entry.failed ? wrapTextWithAnsi(entry.raw(), width) : entry.component.render(width)));
|
|
207
|
+
}
|
|
208
|
+
catch {
|
|
209
|
+
// Arbitrary extension renderers/Markdown must not take down the parent TUI.
|
|
210
|
+
entry.failed = true;
|
|
211
|
+
entry.failedPrefix = entry.raw();
|
|
212
|
+
lines.push(...wrapTextWithAnsi(entry.failedPrefix, width));
|
|
213
|
+
}
|
|
214
|
+
if (entry.elided)
|
|
215
|
+
lines.push(truncationNote(entry.elided));
|
|
216
|
+
entry.height = lines.length - entry.top;
|
|
217
|
+
}
|
|
218
|
+
return lines.map(line => truncateToWidth(line, width));
|
|
219
|
+
}
|
|
220
|
+
handleMouse(event) {
|
|
221
|
+
const entry = this.entries.find(item => event.y >= item.top && event.y < item.top + item.height);
|
|
222
|
+
return entry?.component.handleMouse?.({ ...event, y: event.y - entry.top, height: entry.height });
|
|
223
|
+
}
|
|
224
|
+
invalidate() {
|
|
225
|
+
for (const entry of this.entries) {
|
|
226
|
+
entry.failed = false;
|
|
227
|
+
entry.component.invalidate();
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* schedule-menu.ts — `/agents → Scheduled jobs` submenu.
|
|
3
|
+
*
|
|
4
|
+
* Minimal v1 surface: list scheduled jobs, select one to inspect details +
|
|
5
|
+
* confirm cancellation. No create wizard (the `Agent` tool's `schedule` param
|
|
6
|
+
* is the canonical creation path), no toggle/cleanup (cancel is enough for
|
|
7
|
+
* "I scheduled something dumb, get rid of it"). Add management surfaces here
|
|
8
|
+
* if real demand emerges.
|
|
9
|
+
*/
|
|
10
|
+
import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
11
|
+
import type { SubagentScheduler } from "../schedule.js";
|
|
12
|
+
/**
|
|
13
|
+
* List scheduled jobs; selecting one opens a cancel-confirm with details.
|
|
14
|
+
* Returns when the user backs out or after a cancellation.
|
|
15
|
+
*/
|
|
16
|
+
export declare function showSchedulesMenu(ctx: ExtensionCommandContext, scheduler: SubagentScheduler): Promise<void>;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* schedule-menu.ts — `/agents → Scheduled jobs` submenu.
|
|
3
|
+
*
|
|
4
|
+
* Minimal v1 surface: list scheduled jobs, select one to inspect details +
|
|
5
|
+
* confirm cancellation. No create wizard (the `Agent` tool's `schedule` param
|
|
6
|
+
* is the canonical creation path), no toggle/cleanup (cancel is enough for
|
|
7
|
+
* "I scheduled something dumb, get rid of it"). Add management surfaces here
|
|
8
|
+
* if real demand emerges.
|
|
9
|
+
*/
|
|
10
|
+
import { selectItem } from "./select-item.js";
|
|
11
|
+
/** Format an ISO timestamp as relative time ("in 4h", "2d ago", "—"). */
|
|
12
|
+
function relTime(iso, now = Date.now()) {
|
|
13
|
+
if (!iso)
|
|
14
|
+
return "—";
|
|
15
|
+
const t = new Date(iso).getTime();
|
|
16
|
+
if (Number.isNaN(t))
|
|
17
|
+
return "—";
|
|
18
|
+
const diff = t - now;
|
|
19
|
+
const abs = Math.abs(diff);
|
|
20
|
+
const future = diff > 0;
|
|
21
|
+
if (abs < 60_000)
|
|
22
|
+
return future ? "in <1m" : "<1m ago";
|
|
23
|
+
const m = Math.round(abs / 60_000);
|
|
24
|
+
if (m < 60)
|
|
25
|
+
return future ? `in ${m}m` : `${m}m ago`;
|
|
26
|
+
const h = Math.round(abs / 3_600_000);
|
|
27
|
+
if (h < 24)
|
|
28
|
+
return future ? `in ${h}h` : `${h}h ago`;
|
|
29
|
+
const d = Math.round(abs / 86_400_000);
|
|
30
|
+
return future ? `in ${d}d` : `${d}d ago`;
|
|
31
|
+
}
|
|
32
|
+
/** One-line status icon. */
|
|
33
|
+
function statusIcon(j) {
|
|
34
|
+
if (!j.enabled)
|
|
35
|
+
return "✗";
|
|
36
|
+
if (j.lastStatus === "error")
|
|
37
|
+
return "!";
|
|
38
|
+
if (j.lastStatus === "running")
|
|
39
|
+
return "⋯";
|
|
40
|
+
return "✓";
|
|
41
|
+
}
|
|
42
|
+
/** Compact selectable row — name, schedule, agent type, next/last run, count. */
|
|
43
|
+
function formatJob(j, scheduler) {
|
|
44
|
+
const next = scheduler.getNextRun(j.id);
|
|
45
|
+
return [
|
|
46
|
+
statusIcon(j),
|
|
47
|
+
j.name.padEnd(18).slice(0, 18),
|
|
48
|
+
j.schedule.padEnd(14).slice(0, 14),
|
|
49
|
+
`[${j.subagent_type}]`,
|
|
50
|
+
`next ${relTime(next)}`,
|
|
51
|
+
`last ${relTime(j.lastRun)}`,
|
|
52
|
+
`runs ${j.runCount}`,
|
|
53
|
+
].join(" ");
|
|
54
|
+
}
|
|
55
|
+
/** Multi-line details block for the cancel confirm. */
|
|
56
|
+
function formatDetails(j, scheduler) {
|
|
57
|
+
const next = scheduler.getNextRun(j.id) ?? "—";
|
|
58
|
+
return [
|
|
59
|
+
`name: ${j.name}`,
|
|
60
|
+
`schedule: ${j.schedule} (${j.scheduleType})`,
|
|
61
|
+
`agent: ${j.subagent_type}`,
|
|
62
|
+
`prompt: ${j.prompt.slice(0, 200)}${j.prompt.length > 200 ? "…" : ""}`,
|
|
63
|
+
`created: ${j.createdAt}`,
|
|
64
|
+
`last run: ${j.lastRun ?? "—"} (${j.lastStatus ?? "—"})`,
|
|
65
|
+
`next run: ${next}`,
|
|
66
|
+
`runs: ${j.runCount}`,
|
|
67
|
+
].join("\n");
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* List scheduled jobs; selecting one opens a cancel-confirm with details.
|
|
71
|
+
* Returns when the user backs out or after a cancellation.
|
|
72
|
+
*/
|
|
73
|
+
export async function showSchedulesMenu(ctx, scheduler) {
|
|
74
|
+
if (!scheduler.isActive()) {
|
|
75
|
+
ctx.ui.notify("Scheduler is not active in this session.", "warning");
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const jobs = scheduler.list();
|
|
79
|
+
if (jobs.length === 0) {
|
|
80
|
+
ctx.ui.notify("No scheduled jobs.", "info");
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
// Numbered + item-paired: two jobs whose names agree in the first 18
|
|
84
|
+
// characters format identically, and matching the returned string back
|
|
85
|
+
// against a parallel label array cancelled whichever came first.
|
|
86
|
+
const job = await selectItem(ctx.ui, `Scheduled jobs (${jobs.length}) — select to cancel`, jobs, j => formatJob(j, scheduler));
|
|
87
|
+
if (!job)
|
|
88
|
+
return;
|
|
89
|
+
const ok = await ctx.ui.confirm(`Cancel "${job.name}"?`, formatDetails(job, scheduler));
|
|
90
|
+
if (!ok)
|
|
91
|
+
return;
|
|
92
|
+
scheduler.removeJob(job.id);
|
|
93
|
+
ctx.ui.notify(`Cancelled "${job.name}".`, "info");
|
|
94
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* select-item.ts — pick an item from a list via `ctx.ui.select`, safely.
|
|
3
|
+
*
|
|
4
|
+
* Pi's dialog API is `select(title, options: string[]) => Promise<string | undefined>`:
|
|
5
|
+
* strings in, string out, with no index or value form. Callers therefore have to
|
|
6
|
+
* map the returned string back to the item it came from, and the obvious way —
|
|
7
|
+
* `labels.indexOf(choice)` over a parallel array — silently resolves to the
|
|
8
|
+
* FIRST match whenever two rows format identically. Row formatters here truncate
|
|
9
|
+
* (job names to 18 chars, agent descriptions to whatever fits), and the text they
|
|
10
|
+
* truncate is LLM-authored, so collisions are ordinary rather than exotic.
|
|
11
|
+
*
|
|
12
|
+
* This numbers every row, which makes the labels unique by construction — no
|
|
13
|
+
* data-dependent branch that only executes in the case nobody exercises — and
|
|
14
|
+
* keeps each label paired with its item so a later edit that sorts or filters
|
|
15
|
+
* between building and resolving cannot desync them.
|
|
16
|
+
*/
|
|
17
|
+
/** Minimal shape of the `ctx.ui` surface this needs. */
|
|
18
|
+
export interface SelectUI {
|
|
19
|
+
select(title: string, options: string[]): Promise<string | undefined>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Show a numbered picker and return the chosen item (not its label).
|
|
23
|
+
*
|
|
24
|
+
* Returns undefined when the user escapes, or when the returned string is not
|
|
25
|
+
* one we offered.
|
|
26
|
+
*/
|
|
27
|
+
export declare function selectItem<T>(ui: SelectUI, title: string, items: readonly T[], format: (item: T, index: number) => string): Promise<T | undefined>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* select-item.ts — pick an item from a list via `ctx.ui.select`, safely.
|
|
3
|
+
*
|
|
4
|
+
* Pi's dialog API is `select(title, options: string[]) => Promise<string | undefined>`:
|
|
5
|
+
* strings in, string out, with no index or value form. Callers therefore have to
|
|
6
|
+
* map the returned string back to the item it came from, and the obvious way —
|
|
7
|
+
* `labels.indexOf(choice)` over a parallel array — silently resolves to the
|
|
8
|
+
* FIRST match whenever two rows format identically. Row formatters here truncate
|
|
9
|
+
* (job names to 18 chars, agent descriptions to whatever fits), and the text they
|
|
10
|
+
* truncate is LLM-authored, so collisions are ordinary rather than exotic.
|
|
11
|
+
*
|
|
12
|
+
* This numbers every row, which makes the labels unique by construction — no
|
|
13
|
+
* data-dependent branch that only executes in the case nobody exercises — and
|
|
14
|
+
* keeps each label paired with its item so a later edit that sorts or filters
|
|
15
|
+
* between building and resolving cannot desync them.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Show a numbered picker and return the chosen item (not its label).
|
|
19
|
+
*
|
|
20
|
+
* Returns undefined when the user escapes, or when the returned string is not
|
|
21
|
+
* one we offered.
|
|
22
|
+
*/
|
|
23
|
+
export async function selectItem(ui, title, items, format) {
|
|
24
|
+
// Pad the number so a 10+ item list keeps its columns aligned.
|
|
25
|
+
const width = String(items.length).length;
|
|
26
|
+
const rows = items.map((item, i) => ({
|
|
27
|
+
item,
|
|
28
|
+
label: `${String(i + 1).padStart(width)}. ${format(item, i)}`,
|
|
29
|
+
}));
|
|
30
|
+
const choice = await ui.select(title, rows.map(r => r.label));
|
|
31
|
+
if (!choice)
|
|
32
|
+
return undefined;
|
|
33
|
+
return rows.find(r => r.label === choice)?.item;
|
|
34
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Transient, session-owned tool progress. Attach before the child starts, not when a viewer opens. */
|
|
2
|
+
import type { AgentSession, ToolExecutionComponent } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
export declare const RESULT_MAX_CHARS = 16000;
|
|
4
|
+
export declare function truncationNote(elided: number): string;
|
|
5
|
+
export type ToolDisplayResult = Parameters<ToolExecutionComponent["updateResult"]>[0];
|
|
6
|
+
export interface ToolProgress {
|
|
7
|
+
toolCallId: string;
|
|
8
|
+
toolName: string;
|
|
9
|
+
args: unknown;
|
|
10
|
+
result?: ToolDisplayResult;
|
|
11
|
+
elided: number;
|
|
12
|
+
}
|
|
13
|
+
/** Bound text before retaining it or handing it to a renderer; never change the session's result. */
|
|
14
|
+
export declare function boundToolResult(result: ToolDisplayResult): {
|
|
15
|
+
result: ToolDisplayResult;
|
|
16
|
+
elided: number;
|
|
17
|
+
};
|
|
18
|
+
/** Idempotent across resumes. The manager owns this subscription until session eviction/disposal. */
|
|
19
|
+
export declare function attachToolProgress(session: AgentSession): void;
|
|
20
|
+
export declare function getToolProgress(session: AgentSession): readonly ToolProgress[];
|
|
21
|
+
/** Never called by the viewer: closing a view must not stop collecting the child's progress. */
|
|
22
|
+
export declare function releaseToolProgress(session: AgentSession): void;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export const RESULT_MAX_CHARS = 16_000;
|
|
2
|
+
export function truncationNote(elided) {
|
|
3
|
+
const thousands = elided < 999_950;
|
|
4
|
+
const value = thousands ? elided / 1_000 : elided / 1_000_000;
|
|
5
|
+
const count = elided < 1_000 ? `${elided}` : `${value.toFixed(1).replace(/\.0$/, "")}${thousands ? "k" : "M"}`;
|
|
6
|
+
return `... (truncated, ${count} more character${elided === 1 ? "" : "s"})`;
|
|
7
|
+
}
|
|
8
|
+
/** Bound text before retaining it or handing it to a renderer; never change the session's result. */
|
|
9
|
+
export function boundToolResult(result) {
|
|
10
|
+
let remaining = RESULT_MAX_CHARS;
|
|
11
|
+
let elided = 0;
|
|
12
|
+
const content = result.content.map(part => {
|
|
13
|
+
if (part.type !== "text" || part.text === undefined)
|
|
14
|
+
return part;
|
|
15
|
+
const text = part.text.slice(0, remaining);
|
|
16
|
+
remaining -= text.length;
|
|
17
|
+
elided += part.text.length - text.length;
|
|
18
|
+
return { ...part, text };
|
|
19
|
+
});
|
|
20
|
+
return { result: { ...result, content }, elided };
|
|
21
|
+
}
|
|
22
|
+
const caches = new WeakMap();
|
|
23
|
+
/** Idempotent across resumes. The manager owns this subscription until session eviction/disposal. */
|
|
24
|
+
export function attachToolProgress(session) {
|
|
25
|
+
if (caches.has(session))
|
|
26
|
+
return;
|
|
27
|
+
const active = new Map();
|
|
28
|
+
const unsubscribe = session.subscribe(event => {
|
|
29
|
+
if (event.type === "tool_execution_start") {
|
|
30
|
+
active.set(event.toolCallId, { toolCallId: event.toolCallId, toolName: event.toolName, args: event.args, elided: 0 });
|
|
31
|
+
}
|
|
32
|
+
else if (event.type === "tool_execution_update") {
|
|
33
|
+
const bounded = boundToolResult({ ...event.partialResult, isError: false });
|
|
34
|
+
active.set(event.toolCallId, { toolCallId: event.toolCallId, toolName: event.toolName, args: event.args, ...bounded });
|
|
35
|
+
}
|
|
36
|
+
else if (event.type === "tool_execution_end") {
|
|
37
|
+
active.delete(event.toolCallId);
|
|
38
|
+
}
|
|
39
|
+
else if (event.type === "agent_end") {
|
|
40
|
+
active.clear();
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
caches.set(session, { active, unsubscribe });
|
|
44
|
+
}
|
|
45
|
+
export function getToolProgress(session) {
|
|
46
|
+
return [...(caches.get(session)?.active.values() ?? [])];
|
|
47
|
+
}
|
|
48
|
+
/** Never called by the viewer: closing a view must not stop collecting the child's progress. */
|
|
49
|
+
export function releaseToolProgress(session) {
|
|
50
|
+
const cache = caches.get(session);
|
|
51
|
+
if (!cache)
|
|
52
|
+
return;
|
|
53
|
+
cache.unsubscribe();
|
|
54
|
+
cache.active.clear();
|
|
55
|
+
caches.delete(session);
|
|
56
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* viewer-keys.ts — Scroll key matchers for the conversation viewer.
|
|
3
|
+
*
|
|
4
|
+
* Resolves `tui.select.*` through the user's keybindings when pi provides a
|
|
5
|
+
* manager, falling back to the previous hardcoded keys otherwise. The viewer's
|
|
6
|
+
* k/j and shift+arrow aliases always work alongside whatever is bound.
|
|
7
|
+
*/
|
|
8
|
+
/** The `tui.select.*` keybinding ids the viewer resolves. */
|
|
9
|
+
export type ViewerScrollKeybinding = "tui.select.up" | "tui.select.down" | "tui.select.pageUp" | "tui.select.pageDown";
|
|
10
|
+
/** Structural subset of pi-tui's `KeybindingsManager` (which satisfies it). */
|
|
11
|
+
export interface ViewerKeybindings {
|
|
12
|
+
matches(data: string, keybinding: ViewerScrollKeybinding): boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface ViewerKeys {
|
|
15
|
+
scrollUp(data: string): boolean;
|
|
16
|
+
scrollDown(data: string): boolean;
|
|
17
|
+
pageUp(data: string): boolean;
|
|
18
|
+
pageDown(data: string): boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare function createViewerKeys(keybindings?: ViewerKeybindings): ViewerKeys;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* viewer-keys.ts — Scroll key matchers for the conversation viewer.
|
|
3
|
+
*
|
|
4
|
+
* Resolves `tui.select.*` through the user's keybindings when pi provides a
|
|
5
|
+
* manager, falling back to the previous hardcoded keys otherwise. The viewer's
|
|
6
|
+
* k/j and shift+arrow aliases always work alongside whatever is bound.
|
|
7
|
+
*/
|
|
8
|
+
import { matchesKey } from "@earendil-works/pi-tui";
|
|
9
|
+
export function createViewerKeys(keybindings) {
|
|
10
|
+
const matches = (data, id, fallback) => keybindings ? keybindings.matches(data, id) : matchesKey(data, fallback);
|
|
11
|
+
return {
|
|
12
|
+
scrollUp: (data) => matches(data, "tui.select.up", "up") || matchesKey(data, "k"),
|
|
13
|
+
scrollDown: (data) => matches(data, "tui.select.down", "down") || matchesKey(data, "j"),
|
|
14
|
+
pageUp: (data) => matches(data, "tui.select.pageUp", "pageUp") || matchesKey(data, "shift+up"),
|
|
15
|
+
pageDown: (data) => matches(data, "tui.select.pageDown", "pageDown") || matchesKey(data, "shift+down"),
|
|
16
|
+
};
|
|
17
|
+
}
|