@timmyjl12/pi-subagents 0.0.0-stage → 0.21.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 +862 -0
- package/CONTRIBUTING.md +72 -0
- package/LICENSE +21 -0
- package/README.md +1125 -3
- 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 +40 -0
- package/dist/active-agents-prompt.js +98 -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 +131 -0
- package/dist/agent-file-toggle.d.ts +125 -0
- package/dist/agent-file-toggle.js +264 -0
- package/dist/agent-manager.d.ts +872 -0
- package/dist/agent-manager.js +2910 -0
- package/dist/agent-runner.d.ts +358 -0
- package/dist/agent-runner.js +1219 -0
- package/dist/agent-types.d.ts +142 -0
- package/dist/agent-types.js +315 -0
- package/dist/awaited-result.d.ts +37 -0
- package/dist/awaited-result.js +150 -0
- package/dist/child-context.d.ts +15 -0
- package/dist/child-context.js +181 -0
- package/dist/child-session-shutdown.d.ts +21 -0
- package/dist/child-session-shutdown.js +97 -0
- package/dist/cleanup-plans.d.ts +10 -0
- package/dist/cleanup-plans.js +112 -0
- package/dist/context.d.ts +12 -0
- package/dist/context.js +56 -0
- package/dist/cross-extension-rpc.d.ts +73 -0
- package/dist/cross-extension-rpc.js +192 -0
- package/dist/custom-agents.d.ts +79 -0
- package/dist/custom-agents.js +583 -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 +64 -0
- package/dist/error-log.js +176 -0
- package/dist/force-main-model.d.ts +21 -0
- package/dist/force-main-model.js +28 -0
- package/dist/goal-bridge.d.ts +155 -0
- package/dist/goal-bridge.js +305 -0
- package/dist/group-join.d.ts +36 -0
- package/dist/group-join.js +161 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +6390 -0
- package/dist/invocation-config.d.ts +164 -0
- package/dist/invocation-config.js +158 -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 +76 -0
- package/dist/nested-tools.js +393 -0
- package/dist/output-diagnostics.d.ts +11 -0
- package/dist/output-diagnostics.js +64 -0
- package/dist/output-file.d.ts +64 -0
- package/dist/output-file.js +351 -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/report-cleanup.d.ts +204 -0
- package/dist/report-cleanup.js +1632 -0
- package/dist/report-store.d.ts +738 -0
- package/dist/report-store.js +3612 -0
- package/dist/schedule-store.d.ts +52 -0
- package/dist/schedule-store.js +240 -0
- package/dist/schedule.d.ts +121 -0
- package/dist/schedule.js +420 -0
- package/dist/settings.d.ts +388 -0
- package/dist/settings.js +268 -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 +411 -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 +304 -0
- package/dist/ui/agent-widget.js +770 -0
- package/dist/ui/cleanup-preview.d.ts +59 -0
- package/dist/ui/cleanup-preview.js +466 -0
- package/dist/ui/conversation-viewer.d.ts +105 -0
- package/dist/ui/conversation-viewer.js +544 -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 +203 -0
- package/dist/ui/fleet-overlay.js +887 -0
- package/dist/ui/hub-feed.d.ts +52 -0
- package/dist/ui/hub-feed.js +148 -0
- package/dist/ui/native-transcript.d.ts +33 -0
- package/dist/ui/native-transcript.js +234 -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 +848 -0
- package/dist/ui/workflow-menu.d.ts +60 -0
- package/dist/ui/workflow-menu.js +147 -0
- package/dist/usage.d.ts +147 -0
- package/dist/usage.js +147 -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 +65 -0
- package/dist/workflow/host.js +477 -0
- package/dist/workflow/journal.d.ts +113 -0
- package/dist/workflow/journal.js +177 -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 +373 -0
- package/dist/workflow/runtime.js +919 -0
- package/dist/workflow/saved.d.ts +90 -0
- package/dist/workflow/saved.js +203 -0
- package/dist/workflow/task.d.ts +145 -0
- package/dist/workflow/task.js +213 -0
- package/dist/workflow/tool-description.d.ts +43 -0
- package/dist/workflow/tool-description.js +204 -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/DEVELOPMENT.md +40 -0
- package/docs/artifacts.md +93 -0
- package/docs/recovery.md +62 -0
- package/docs/rpc.md +252 -0
- package/docs/runtime-performance.md +53 -0
- package/docs/workflows.md +467 -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 +66 -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 +115 -0
- package/src/advisor-status.ts +74 -0
- package/src/agent-color.ts +169 -0
- package/src/agent-file-toggle.ts +273 -0
- package/src/agent-manager.ts +3312 -0
- package/src/agent-runner.ts +1500 -0
- package/src/agent-types.ts +390 -0
- package/src/awaited-result.ts +187 -0
- package/src/child-context.ts +173 -0
- package/src/child-session-shutdown.ts +114 -0
- package/src/cleanup-plans.ts +112 -0
- package/src/context.ts +58 -0
- package/src/cross-extension-rpc.ts +257 -0
- package/src/custom-agents.ts +689 -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 +202 -0
- package/src/force-main-model.ts +29 -0
- package/src/goal-bridge.ts +468 -0
- package/src/group-join.ts +188 -0
- package/src/index.ts +6856 -0
- package/src/invocation-config.ts +276 -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 +553 -0
- package/src/output-diagnostics.ts +68 -0
- package/src/output-file.ts +380 -0
- package/src/prompts.ts +151 -0
- package/src/recovery.ts +320 -0
- package/src/report-cleanup.ts +2044 -0
- package/src/report-store.ts +4130 -0
- package/src/schedule-store.ts +244 -0
- package/src/schedule.ts +450 -0
- package/src/settings.ts +632 -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 +424 -0
- package/src/ui/agent-mention.ts +216 -0
- package/src/ui/agent-widget.ts +866 -0
- package/src/ui/cleanup-preview.ts +518 -0
- package/src/ui/conversation-viewer.ts +527 -0
- package/src/ui/fleet-list.ts +563 -0
- package/src/ui/fleet-overlay.ts +1048 -0
- package/src/ui/hub-feed.ts +179 -0
- package/src/ui/native-transcript.ts +224 -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 +1119 -0
- package/src/ui/workflow-menu.ts +193 -0
- package/src/usage.ts +217 -0
- package/src/workflow/collisions.ts +123 -0
- package/src/workflow/entry.ts +47 -0
- package/src/workflow/host.ts +524 -0
- package/src/workflow/journal.ts +221 -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 +1342 -0
- package/src/workflow/saved.ts +217 -0
- package/src/workflow/task.ts +313 -0
- package/src/workflow/tool-description.ts +205 -0
- package/src/workflow/worker-source.ts +781 -0
- package/src/worktree.ts +205 -0
- package/src/xml.ts +13 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hub-feed.ts — pure data for the fleet overlay's live panes (omp Agent Hub parity).
|
|
3
|
+
*
|
|
4
|
+
* - `transcriptTail`: the last few events of one agent's child session — prompts,
|
|
5
|
+
* replies, tool calls and failed results — for the right pane under the detail card.
|
|
6
|
+
* - `activityFeed`: the same events across every agent, newest first, for the
|
|
7
|
+
* Activity tab, with All / Errors / Responses / Tools filters.
|
|
8
|
+
* - `treeOrder`: parent → child ordering for the tree view.
|
|
9
|
+
*
|
|
10
|
+
* Everything is derived from `session.messages` on render; no extra state is
|
|
11
|
+
* recorded, so the feed can never disagree with the conversation viewer.
|
|
12
|
+
*/
|
|
13
|
+
import type { AgentRecord } from "../types.ts";
|
|
14
|
+
export type FeedKind = "prompt" | "response" | "tool" | "error";
|
|
15
|
+
export type ActivityFilter = "all" | "errors" | "responses" | "tools";
|
|
16
|
+
export declare const ACTIVITY_FILTERS: readonly ActivityFilter[];
|
|
17
|
+
export interface FeedEvent {
|
|
18
|
+
readonly kind: FeedKind;
|
|
19
|
+
readonly text: string;
|
|
20
|
+
readonly at?: number;
|
|
21
|
+
}
|
|
22
|
+
export interface ActivityEntry extends FeedEvent {
|
|
23
|
+
readonly agentId: string;
|
|
24
|
+
readonly agent: string;
|
|
25
|
+
}
|
|
26
|
+
/** Events of one message, in order. */
|
|
27
|
+
export declare function eventsOf(message: unknown): FeedEvent[];
|
|
28
|
+
/** The last `max` events of an agent's session, oldest → newest (bottom is live). */
|
|
29
|
+
export declare function transcriptTail(record: AgentRecord, max: number): FeedEvent[];
|
|
30
|
+
/**
|
|
31
|
+
* Combined log across agents, newest first. Each agent contributes at most
|
|
32
|
+
* `perAgent` recent events so one chatty agent cannot crowd out the rest.
|
|
33
|
+
*/
|
|
34
|
+
export declare function activityFeed(records: readonly AgentRecord[], options: {
|
|
35
|
+
filter: ActivityFilter;
|
|
36
|
+
limit: number;
|
|
37
|
+
perAgent?: number;
|
|
38
|
+
}): ActivityEntry[];
|
|
39
|
+
export interface TreeRow {
|
|
40
|
+
readonly record: AgentRecord;
|
|
41
|
+
readonly depth: number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Parent → child order. Roots are the given top-level records in their given
|
|
45
|
+
* order; each child follows its parent, oldest first. Orphans (parent swept)
|
|
46
|
+
* surface as roots so nothing disappears.
|
|
47
|
+
*
|
|
48
|
+
* `hidden` drops a row from the output without dropping what is under it: the
|
|
49
|
+
* subtree is still traversed, one level up, so a view filter (a dismissed row)
|
|
50
|
+
* can never re-insert the row it removed or hide its descendants.
|
|
51
|
+
*/
|
|
52
|
+
export declare function treeOrder(roots: readonly AgentRecord[], all: readonly AgentRecord[], hidden?: (record: AgentRecord) => boolean): TreeRow[];
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hub-feed.ts — pure data for the fleet overlay's live panes (omp Agent Hub parity).
|
|
3
|
+
*
|
|
4
|
+
* - `transcriptTail`: the last few events of one agent's child session — prompts,
|
|
5
|
+
* replies, tool calls and failed results — for the right pane under the detail card.
|
|
6
|
+
* - `activityFeed`: the same events across every agent, newest first, for the
|
|
7
|
+
* Activity tab, with All / Errors / Responses / Tools filters.
|
|
8
|
+
* - `treeOrder`: parent → child ordering for the tree view.
|
|
9
|
+
*
|
|
10
|
+
* Everything is derived from `session.messages` on render; no extra state is
|
|
11
|
+
* recorded, so the feed can never disagree with the conversation viewer.
|
|
12
|
+
*/
|
|
13
|
+
export const ACTIVITY_FILTERS = ["all", "errors", "responses", "tools"];
|
|
14
|
+
function oneLine(text, max = 240) {
|
|
15
|
+
const flat = text.replace(/\s+/g, " ").trim();
|
|
16
|
+
return flat.length > max ? `${flat.slice(0, max - 1)}…` : flat;
|
|
17
|
+
}
|
|
18
|
+
function textOf(content) {
|
|
19
|
+
if (typeof content === "string")
|
|
20
|
+
return content;
|
|
21
|
+
if (!Array.isArray(content))
|
|
22
|
+
return "";
|
|
23
|
+
return content
|
|
24
|
+
.map(part => (part && typeof part === "object" && part.type === "text" ? String(part.text ?? "") : ""))
|
|
25
|
+
.filter(Boolean)
|
|
26
|
+
.join(" ");
|
|
27
|
+
}
|
|
28
|
+
/** Compact `name(arg)` label: the first string argument says the most (path, pattern, command). */
|
|
29
|
+
function toolLabel(part) {
|
|
30
|
+
const name = typeof part.name === "string" ? part.name : "tool";
|
|
31
|
+
const args = part.arguments && typeof part.arguments === "object" ? Object.values(part.arguments) : [];
|
|
32
|
+
const first = args.find(value => typeof value === "string");
|
|
33
|
+
return first ? `${name}(${oneLine(first, 80)})` : `${name}()`;
|
|
34
|
+
}
|
|
35
|
+
/** Events of one message, in order. */
|
|
36
|
+
export function eventsOf(message) {
|
|
37
|
+
const m = (message ?? {});
|
|
38
|
+
const at = typeof m.timestamp === "number" ? m.timestamp : undefined;
|
|
39
|
+
const events = [];
|
|
40
|
+
if (m.role === "user") {
|
|
41
|
+
const text = oneLine(textOf(m.content));
|
|
42
|
+
if (text)
|
|
43
|
+
events.push({ kind: "prompt", text, at });
|
|
44
|
+
}
|
|
45
|
+
else if (m.role === "assistant") {
|
|
46
|
+
if (Array.isArray(m.content)) {
|
|
47
|
+
for (const part of m.content) {
|
|
48
|
+
if (part?.type === "text" && typeof part.text === "string" && part.text.trim()) {
|
|
49
|
+
events.push({ kind: "response", text: oneLine(part.text), at });
|
|
50
|
+
}
|
|
51
|
+
else if (part?.type === "toolCall") {
|
|
52
|
+
events.push({ kind: "tool", text: toolLabel(part), at });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (m.stopReason === "error" && typeof m.errorMessage === "string") {
|
|
57
|
+
events.push({ kind: "error", text: oneLine(m.errorMessage), at });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else if (m.role === "toolResult" && m.isError === true) {
|
|
61
|
+
const name = typeof m.toolName === "string" ? m.toolName : "tool";
|
|
62
|
+
events.push({ kind: "error", text: `${name} failed: ${oneLine(textOf(m.content), 160)}`, at });
|
|
63
|
+
}
|
|
64
|
+
return events;
|
|
65
|
+
}
|
|
66
|
+
function messagesOf(record) {
|
|
67
|
+
const messages = record.session?.messages;
|
|
68
|
+
return Array.isArray(messages) ? messages : [];
|
|
69
|
+
}
|
|
70
|
+
/** The last `max` events of an agent's session, oldest → newest (bottom is live). */
|
|
71
|
+
export function transcriptTail(record, max) {
|
|
72
|
+
if (max <= 0)
|
|
73
|
+
return [];
|
|
74
|
+
const messages = messagesOf(record);
|
|
75
|
+
const out = [];
|
|
76
|
+
// Walk backwards and stop early: a long session never pays for its whole history.
|
|
77
|
+
for (let i = messages.length - 1; i >= 0 && out.length < max; i -= 1) {
|
|
78
|
+
const events = eventsOf(messages[i]);
|
|
79
|
+
for (let j = events.length - 1; j >= 0 && out.length < max; j -= 1)
|
|
80
|
+
out.push(events[j]);
|
|
81
|
+
}
|
|
82
|
+
return out.reverse();
|
|
83
|
+
}
|
|
84
|
+
function matchesFilter(kind, filter) {
|
|
85
|
+
if (filter === "all")
|
|
86
|
+
return true;
|
|
87
|
+
if (filter === "errors")
|
|
88
|
+
return kind === "error";
|
|
89
|
+
if (filter === "responses")
|
|
90
|
+
return kind === "response";
|
|
91
|
+
return kind === "tool";
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Combined log across agents, newest first. Each agent contributes at most
|
|
95
|
+
* `perAgent` recent events so one chatty agent cannot crowd out the rest.
|
|
96
|
+
*/
|
|
97
|
+
export function activityFeed(records, options) {
|
|
98
|
+
const perAgent = options.perAgent ?? 60;
|
|
99
|
+
const entries = [];
|
|
100
|
+
let order = 0;
|
|
101
|
+
for (const record of records) {
|
|
102
|
+
const agent = record.alias ?? record.handle ?? record.type;
|
|
103
|
+
for (const event of transcriptTail(record, perAgent)) {
|
|
104
|
+
if (!matchesFilter(event.kind, options.filter))
|
|
105
|
+
continue;
|
|
106
|
+
entries.push({ ...event, agentId: record.id, agent, order: order++ });
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
entries.sort((a, b) => (b.at ?? 0) - (a.at ?? 0) || b.order - a.order);
|
|
110
|
+
return entries.slice(0, options.limit).map(({ order: _order, ...entry }) => entry);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Parent → child order. Roots are the given top-level records in their given
|
|
114
|
+
* order; each child follows its parent, oldest first. Orphans (parent swept)
|
|
115
|
+
* surface as roots so nothing disappears.
|
|
116
|
+
*
|
|
117
|
+
* `hidden` drops a row from the output without dropping what is under it: the
|
|
118
|
+
* subtree is still traversed, one level up, so a view filter (a dismissed row)
|
|
119
|
+
* can never re-insert the row it removed or hide its descendants.
|
|
120
|
+
*/
|
|
121
|
+
export function treeOrder(roots, all, hidden) {
|
|
122
|
+
const children = new Map();
|
|
123
|
+
const ids = new Set(all.map(record => record.id));
|
|
124
|
+
for (const record of all) {
|
|
125
|
+
const parent = record.parentAgentId;
|
|
126
|
+
if (!parent || !ids.has(parent))
|
|
127
|
+
continue;
|
|
128
|
+
const list = children.get(parent) ?? [];
|
|
129
|
+
list.push(record);
|
|
130
|
+
children.set(parent, list);
|
|
131
|
+
}
|
|
132
|
+
const out = [];
|
|
133
|
+
const seen = new Set();
|
|
134
|
+
const visit = (record, depth) => {
|
|
135
|
+
if (seen.has(record.id))
|
|
136
|
+
return;
|
|
137
|
+
seen.add(record.id);
|
|
138
|
+
const hiddenHere = hidden?.(record) ?? false;
|
|
139
|
+
if (!hiddenHere)
|
|
140
|
+
out.push({ record, depth });
|
|
141
|
+
for (const child of (children.get(record.id) ?? []).sort((a, b) => a.startedAt - b.startedAt)) {
|
|
142
|
+
visit(child, hiddenHere ? depth : depth + 1);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
for (const root of roots)
|
|
146
|
+
visit(root, 0);
|
|
147
|
+
return out;
|
|
148
|
+
}
|
|
@@ -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,234 @@
|
|
|
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
|
+
// Same shape pi's own transcript hands the card: renderers read durationMs.
|
|
66
|
+
this.updateTool(event.toolCallId, {
|
|
67
|
+
...event.result, isError: event.isError, ...(event.durationMs === undefined ? {} : { durationMs: event.durationMs }),
|
|
68
|
+
}, false);
|
|
69
|
+
}
|
|
70
|
+
else if (event.type === "compaction_end" && event.result && !event.aborted) {
|
|
71
|
+
this.hydrate();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
renderers(name) {
|
|
75
|
+
const definition = this.session.getToolDefinition?.(name);
|
|
76
|
+
if (!this.builtIns.has(name) && Object.hasOwn(factories, name)) {
|
|
77
|
+
// Public factories provide the callbacks missing from session built-ins. Never execute them.
|
|
78
|
+
this.builtIns.set(name, factories[name](this.cwd));
|
|
79
|
+
}
|
|
80
|
+
const fallback = this.builtIns.get(name);
|
|
81
|
+
return definition ? {
|
|
82
|
+
...definition,
|
|
83
|
+
renderCall: definition.renderCall ?? fallback?.renderCall,
|
|
84
|
+
renderResult: definition.renderResult ?? fallback?.renderResult,
|
|
85
|
+
} : fallback;
|
|
86
|
+
}
|
|
87
|
+
get cwd() { return this.session.sessionManager?.getCwd() ?? process.cwd(); }
|
|
88
|
+
ensureTool(id, name, args) {
|
|
89
|
+
const existing = this.tools.get(id);
|
|
90
|
+
if (existing)
|
|
91
|
+
return existing;
|
|
92
|
+
const component = new ToolExecutionComponent(name, id, args, {
|
|
93
|
+
showImages: this.session.settingsManager?.getShowImages() ?? true,
|
|
94
|
+
outputPad: this.session.settingsManager?.getOutputPad() ?? 1,
|
|
95
|
+
}, this.renderers(name), this.tui, this.cwd);
|
|
96
|
+
component.setExpanded(this.expanded);
|
|
97
|
+
const entry = {
|
|
98
|
+
component, name, args, top: 0, height: 0,
|
|
99
|
+
raw: () => `${name} ${JSON.stringify(entry.args)}\n${entry.result?.content.filter(p => p.type === "text").map(p => p.text ?? "").join("\n") ?? ""}`,
|
|
100
|
+
};
|
|
101
|
+
this.entries.push(entry);
|
|
102
|
+
this.tools.set(id, entry);
|
|
103
|
+
return entry;
|
|
104
|
+
}
|
|
105
|
+
updateTool(id, result, partial, alreadyElided = 0) {
|
|
106
|
+
const entry = this.tools.get(id);
|
|
107
|
+
if (!entry)
|
|
108
|
+
return;
|
|
109
|
+
const bounded = boundToolResult(result);
|
|
110
|
+
entry.result = bounded.result;
|
|
111
|
+
entry.elided = bounded.elided + alreadyElided;
|
|
112
|
+
entry.component.updateResult(bounded.result, partial);
|
|
113
|
+
}
|
|
114
|
+
updateAssistant(message, partial) {
|
|
115
|
+
if (!this.streaming && this.seen.has(message))
|
|
116
|
+
return;
|
|
117
|
+
if (!this.streaming) {
|
|
118
|
+
const component = new AssistantMessageComponent(undefined, this.session.settingsManager?.getHideThinkingBlock() ?? false, this.markdownTheme, undefined, this.session.settingsManager?.getOutputPad() ?? 1, this.session.extensionRunner?.getMarkdownTransformers());
|
|
119
|
+
const entry = { component, raw: () => extractText(message.content), top: 0, height: 0 };
|
|
120
|
+
this.streaming = { message, entry, component };
|
|
121
|
+
this.entries.push(entry);
|
|
122
|
+
}
|
|
123
|
+
const current = this.streaming;
|
|
124
|
+
current.message = message;
|
|
125
|
+
current.entry.raw = () => message.content.map(p => p.type === "thinking" ? p.thinking : p.type === "text" ? p.text : "").join("\n");
|
|
126
|
+
current.component.updateContent(message, partial);
|
|
127
|
+
for (const part of message.content) {
|
|
128
|
+
if (part.type !== "toolCall")
|
|
129
|
+
continue;
|
|
130
|
+
const entry = this.ensureTool(part.id, part.name, part.arguments);
|
|
131
|
+
entry.args = part.arguments;
|
|
132
|
+
entry.component.updateArgs(part.arguments);
|
|
133
|
+
if (!partial)
|
|
134
|
+
entry.component.setArgsComplete();
|
|
135
|
+
}
|
|
136
|
+
if (!partial) {
|
|
137
|
+
this.seen.add(message);
|
|
138
|
+
this.streaming = undefined;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
addMessage(message) {
|
|
142
|
+
if (this.seen.has(message))
|
|
143
|
+
return;
|
|
144
|
+
if (message.role === "assistant") {
|
|
145
|
+
this.updateAssistant(message, false);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
this.seen.add(message);
|
|
149
|
+
if (message.role === "toolResult") {
|
|
150
|
+
const entry = this.ensureTool(message.toolCallId, message.toolName, {});
|
|
151
|
+
entry.component.setArgsComplete();
|
|
152
|
+
this.updateTool(message.toolCallId, message, false);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
let component;
|
|
156
|
+
let raw;
|
|
157
|
+
if (message.role === "user") {
|
|
158
|
+
const text = typeof message.content === "string" ? message.content : extractText(message.content);
|
|
159
|
+
raw = () => text;
|
|
160
|
+
component = new UserMessageComponent(text, this.markdownTheme, this.session.settingsManager?.getOutputPad() ?? 1, this.session.extensionRunner?.getMarkdownTransformers());
|
|
161
|
+
}
|
|
162
|
+
else if (message.role === "custom") {
|
|
163
|
+
if (!message.display)
|
|
164
|
+
return;
|
|
165
|
+
raw = () => typeof message.content === "string" ? message.content : extractText(message.content);
|
|
166
|
+
component = new CustomMessageComponent(message, this.session.extensionRunner?.getMessageRenderer(message.customType), this.markdownTheme, this.session.settingsManager?.getOutputPad() ?? 1);
|
|
167
|
+
}
|
|
168
|
+
else if (message.role === "bashExecution") {
|
|
169
|
+
raw = () => `$ ${message.command}\n${message.output.slice(0, RESULT_MAX_CHARS)}`;
|
|
170
|
+
component = new Text(raw(), 0, 0);
|
|
171
|
+
this.entries.push({ component, raw, top: 0, height: 0, elided: Math.max(0, message.output.length - RESULT_MAX_CHARS) });
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
else if (message.role === "compactionSummary" || message.role === "branchSummary") {
|
|
175
|
+
raw = () => message.summary;
|
|
176
|
+
component = new Text(raw(), 0, 0);
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
this.entries.push({ component, raw, top: 0, height: 0 });
|
|
182
|
+
}
|
|
183
|
+
/** Inspection uses the same live source, not only committed history. */
|
|
184
|
+
inspectionMessages() {
|
|
185
|
+
const messages = [...this.session.messages];
|
|
186
|
+
if (this.streaming && !messages.includes(this.streaming.message))
|
|
187
|
+
messages.push(this.streaming.message);
|
|
188
|
+
const committed = new Set(messages.filter(m => m.role === "toolResult").map(m => m.toolCallId));
|
|
189
|
+
for (const [id, entry] of this.tools) {
|
|
190
|
+
if (!entry.result || committed.has(id))
|
|
191
|
+
continue;
|
|
192
|
+
messages.push({ role: "toolResult", toolCallId: id, toolName: entry.name,
|
|
193
|
+
content: entry.result.content, details: entry.result.details,
|
|
194
|
+
isError: entry.result.isError, timestamp: 0, viewerElided: entry.elided });
|
|
195
|
+
}
|
|
196
|
+
return messages;
|
|
197
|
+
}
|
|
198
|
+
toggleExpanded() {
|
|
199
|
+
this.expanded = !this.expanded;
|
|
200
|
+
for (const entry of this.tools.values())
|
|
201
|
+
entry.component.setExpanded(this.expanded);
|
|
202
|
+
}
|
|
203
|
+
render(width) {
|
|
204
|
+
const lines = [];
|
|
205
|
+
for (const entry of this.entries) {
|
|
206
|
+
entry.top = lines.length;
|
|
207
|
+
if (entry.failed && !entry.raw().startsWith(entry.failedPrefix ?? ""))
|
|
208
|
+
entry.failed = false;
|
|
209
|
+
try {
|
|
210
|
+
lines.push(...(entry.failed ? wrapTextWithAnsi(entry.raw(), width) : entry.component.render(width)));
|
|
211
|
+
}
|
|
212
|
+
catch {
|
|
213
|
+
// Arbitrary extension renderers/Markdown must not take down the parent TUI.
|
|
214
|
+
entry.failed = true;
|
|
215
|
+
entry.failedPrefix = entry.raw();
|
|
216
|
+
lines.push(...wrapTextWithAnsi(entry.failedPrefix, width));
|
|
217
|
+
}
|
|
218
|
+
if (entry.elided)
|
|
219
|
+
lines.push(truncationNote(entry.elided));
|
|
220
|
+
entry.height = lines.length - entry.top;
|
|
221
|
+
}
|
|
222
|
+
return lines.map(line => truncateToWidth(line, width));
|
|
223
|
+
}
|
|
224
|
+
handleMouse(event) {
|
|
225
|
+
const entry = this.entries.find(item => event.y >= item.top && event.y < item.top + item.height);
|
|
226
|
+
return entry?.component.handleMouse?.({ ...event, y: event.y - entry.top, height: entry.height });
|
|
227
|
+
}
|
|
228
|
+
invalidate() {
|
|
229
|
+
for (const entry of this.entries) {
|
|
230
|
+
entry.failed = false;
|
|
231
|
+
entry.component.invalidate();
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
@@ -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.ts";
|
|
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
|
+
await 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;
|