pi-subagent-manager 0.12.0 → 0.14.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/README.md +2 -2
- package/docs/custom-agents.md +35 -0
- package/docs/settings.md +3 -3
- package/docs/tools-and-ui.md +15 -7
- package/package.json +1 -1
- package/src/index.ts +48 -9
- package/src/orch/prompt.ts +8 -3
- package/src/orch/runtime.ts +107 -52
- package/src/orch/tools.ts +37 -15
- package/src/prefs/config.ts +572 -43
- package/src/prefs/models.ts +19 -2
- package/src/types.ts +20 -0
- package/src/ui/agent-navigation-editor.ts +40 -26
- package/src/ui/live-agent-view.ts +19 -2
- package/src/ui/status-ui.ts +30 -6
- package/src/ui/ui.ts +223 -56
package/src/prefs/models.ts
CHANGED
|
@@ -36,6 +36,21 @@ export function modelIdentity(model: { provider: string; id: string }): string {
|
|
|
36
36
|
return `${model.provider}/${model.id}`;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
export class ModelPreferenceError extends Error {
|
|
40
|
+
constructor(
|
|
41
|
+
message: string,
|
|
42
|
+
readonly scopedModelFiltering: boolean,
|
|
43
|
+
) {
|
|
44
|
+
super(message);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
get summary(): string {
|
|
48
|
+
return this.scopedModelFiltering
|
|
49
|
+
? "No preferred model is available in /scoped-models; update the scope or this type's models."
|
|
50
|
+
: "No preferred model is available; check provider credentials or this type's models.";
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
39
54
|
export function selectPreferredModel(
|
|
40
55
|
type: { name: string; models?: unknown; model?: unknown },
|
|
41
56
|
eligibleModels: readonly { model: { provider: string; id: string } }[],
|
|
@@ -50,11 +65,13 @@ export function selectPreferredModel(
|
|
|
50
65
|
const preferenceList = `[${preferences.join(", ")}]`;
|
|
51
66
|
const availableList = available.length === 0 ? "(none)" : `[${available.join(", ")}]`;
|
|
52
67
|
if (!scopedModelFiltering) {
|
|
53
|
-
throw new
|
|
68
|
+
throw new ModelPreferenceError(
|
|
54
69
|
`Agent type ${JSON.stringify(type.name)} prefers models ${preferenceList}, but none are available. Available models: ${availableList}. Update this agent type's models list.`,
|
|
70
|
+
false,
|
|
55
71
|
);
|
|
56
72
|
}
|
|
57
|
-
throw new
|
|
73
|
+
throw new ModelPreferenceError(
|
|
58
74
|
`Agent type ${JSON.stringify(type.name)} prefers scoped models ${preferenceList}, but none are available in /scoped-models. Available scoped models: ${availableList}. Update /scoped-models or this agent type's models list.`,
|
|
75
|
+
true,
|
|
59
76
|
);
|
|
60
77
|
}
|
package/src/types.ts
CHANGED
|
@@ -3,6 +3,10 @@ import type { ToolDefinition } from "@earendil-works/pi-coding-agent";
|
|
|
3
3
|
|
|
4
4
|
export const THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"] as const;
|
|
5
5
|
export type ThinkingLevel = (typeof THINKING_LEVELS)[number];
|
|
6
|
+
export interface ResolvedAgentSettings {
|
|
7
|
+
model: string;
|
|
8
|
+
thinkingLevel: ThinkingLevel;
|
|
9
|
+
}
|
|
6
10
|
export interface AgentType {
|
|
7
11
|
name: string;
|
|
8
12
|
description: string;
|
|
@@ -20,6 +24,22 @@ export interface AgentType {
|
|
|
20
24
|
systemPrompt: string;
|
|
21
25
|
filePath?: string;
|
|
22
26
|
source?: "bundled" | "user" | "project";
|
|
27
|
+
/**
|
|
28
|
+
* How this definition is customized relative to its base.
|
|
29
|
+
* - fork: a full `<name>.md` copy (owns the system prompt).
|
|
30
|
+
* - override: a settings-only `<name>.yml` merged on top of the base
|
|
31
|
+
* (no Markdown body; unset fields follow the base).
|
|
32
|
+
* Absent for pure bundled definitions and brand-new drafts.
|
|
33
|
+
*/
|
|
34
|
+
customization?: {
|
|
35
|
+
kind: "fork" | "override";
|
|
36
|
+
scope: "user" | "project";
|
|
37
|
+
filePath: string;
|
|
38
|
+
};
|
|
39
|
+
/** Source of the base definition under the customization, if any. */
|
|
40
|
+
baseSource?: "bundled" | "user" | "project";
|
|
41
|
+
/** File path of the base definition under the customization, if any. */
|
|
42
|
+
baseFilePath?: string;
|
|
23
43
|
}
|
|
24
44
|
export type ThreadState = "starting" | "running" | "paused" | "completed" | "failed" | "stopped";
|
|
25
45
|
export interface ThreadView {
|
|
@@ -16,6 +16,9 @@ export interface AgentNavigationEditorOptions {
|
|
|
16
16
|
/** Must return the whole navigation interaction, so repeated Left cannot reopen it. */
|
|
17
17
|
openTree(): void | Promise<void>;
|
|
18
18
|
canOpen(): boolean;
|
|
19
|
+
/** Session-local widget collapse; never saves the configured display mode. */
|
|
20
|
+
collapseWidget?(): void | Promise<void>;
|
|
21
|
+
canCollapse?(): boolean;
|
|
19
22
|
/** Root ownership token; changing it invalidates queued transitions. */
|
|
20
23
|
generation(): unknown;
|
|
21
24
|
onError?(error: unknown): void;
|
|
@@ -27,12 +30,12 @@ export interface AgentNavigationEditorOptions {
|
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
/**
|
|
30
|
-
* Physical
|
|
33
|
+
* Physical arrow boundary adapter. It owns no session/history internals and never
|
|
31
34
|
* changes the draft. Install once per root UI lifecycle, not for tree navigation.
|
|
32
35
|
* Another custom editor occupies the same host slot; skip installation rather than stack.
|
|
33
36
|
*/
|
|
34
37
|
export class AgentNavigationEditor extends CustomEditor {
|
|
35
|
-
private pending
|
|
38
|
+
private pending: "left" | "right" | undefined;
|
|
36
39
|
private disposed = false;
|
|
37
40
|
private dispatchDepth = 0;
|
|
38
41
|
private inputEpoch = 0;
|
|
@@ -59,20 +62,21 @@ export class AgentNavigationEditor extends CustomEditor {
|
|
|
59
62
|
this.inputEpoch++;
|
|
60
63
|
}
|
|
61
64
|
|
|
62
|
-
private
|
|
63
|
-
if (!matchesKey(data, Key.left)) return false;
|
|
65
|
+
private ordinaryArrow(data: string, direction: "left" | "right"): boolean {
|
|
66
|
+
if (!matchesKey(data, direction === "left" ? Key.left : Key.right)) return false;
|
|
67
|
+
const action = direction === "left" ? "tui.editor.cursorLeft" : "tui.editor.cursorRight";
|
|
64
68
|
// Editor uses the global TUI bindings; CustomEditor uses the injected app
|
|
65
69
|
// manager. Both must agree, and a conflicting remap wins conservatively.
|
|
66
70
|
for (const keys of [this.navigationKeys, getKeybindings()]) {
|
|
67
|
-
if (!keys.matches(data,
|
|
68
|
-
for (const
|
|
71
|
+
if (!keys.matches(data, action)) return false;
|
|
72
|
+
for (const other of Object.keys(keys.getResolvedBindings())) {
|
|
69
73
|
if (
|
|
70
|
-
|
|
71
|
-
(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
keys.matches(data,
|
|
74
|
+
other !== action &&
|
|
75
|
+
(other.startsWith("tui.editor.") ||
|
|
76
|
+
other.startsWith("tui.input.") ||
|
|
77
|
+
other.startsWith("tui.altScreen.") ||
|
|
78
|
+
other.startsWith("app.")) &&
|
|
79
|
+
keys.matches(data, other as Keybinding)
|
|
76
80
|
)
|
|
77
81
|
return false;
|
|
78
82
|
}
|
|
@@ -82,8 +86,9 @@ export class AgentNavigationEditor extends CustomEditor {
|
|
|
82
86
|
|
|
83
87
|
override handleInput(data: string): void {
|
|
84
88
|
const outer = this.dispatchDepth === 0;
|
|
85
|
-
const
|
|
86
|
-
|
|
89
|
+
const direction = this.ordinaryArrow(data, "left") ? "left"
|
|
90
|
+
: this.ordinaryArrow(data, "right") ? "right" : undefined;
|
|
91
|
+
if (outer && (!direction || (this.pending && this.pending !== direction))) this.inputEpoch++;
|
|
87
92
|
const previousPaste = this.pastePending;
|
|
88
93
|
const wasPaste = previousPaste || data.includes("\x1b[200~");
|
|
89
94
|
// Update before dispatch: Pi recursively sends a suffix after the end
|
|
@@ -93,16 +98,20 @@ export class AgentNavigationEditor extends CustomEditor {
|
|
|
93
98
|
const wasJump = this.jumpPending;
|
|
94
99
|
const cursor = this.getCursor();
|
|
95
100
|
const text = this.getText();
|
|
101
|
+
const lines = text.split("\n");
|
|
102
|
+
const atBoundary = direction === "left"
|
|
103
|
+
? cursor.line === 0 && cursor.col === 0
|
|
104
|
+
: direction === "right" && cursor.line === lines.length - 1 &&
|
|
105
|
+
cursor.col === lines.at(-1)!.length;
|
|
96
106
|
const eligible =
|
|
97
107
|
outer &&
|
|
98
|
-
|
|
108
|
+
direction !== undefined &&
|
|
99
109
|
this.focused &&
|
|
100
110
|
!this.disposed &&
|
|
101
111
|
!wasPaste &&
|
|
102
112
|
!wasJump &&
|
|
103
113
|
!this.isShowingAutocomplete() &&
|
|
104
|
-
|
|
105
|
-
cursor.col === 0;
|
|
114
|
+
atBoundary;
|
|
106
115
|
const generation = eligible ? this.navigation.generation() : undefined;
|
|
107
116
|
let changed = false;
|
|
108
117
|
let consumed = false;
|
|
@@ -150,17 +159,21 @@ export class AgentNavigationEditor extends CustomEditor {
|
|
|
150
159
|
after.line === cursor.line &&
|
|
151
160
|
after.col === cursor.col
|
|
152
161
|
) {
|
|
153
|
-
this.
|
|
162
|
+
this.queueNavigation(text, cursor, generation, direction!);
|
|
154
163
|
}
|
|
155
164
|
}
|
|
156
165
|
|
|
157
|
-
private
|
|
166
|
+
private queueNavigation(
|
|
158
167
|
text: string,
|
|
159
168
|
cursor: { line: number; col: number },
|
|
160
169
|
generation: unknown,
|
|
170
|
+
direction: "left" | "right",
|
|
161
171
|
): void {
|
|
162
|
-
|
|
163
|
-
|
|
172
|
+
const allowed = () => direction === "left"
|
|
173
|
+
? this.navigation.canOpen()
|
|
174
|
+
: !!this.navigation.collapseWidget && (this.navigation.canCollapse?.() ?? false);
|
|
175
|
+
if (this.pending || !allowed()) return;
|
|
176
|
+
this.pending = direction;
|
|
164
177
|
const epoch = this.inputEpoch;
|
|
165
178
|
queueMicrotask(() => {
|
|
166
179
|
const after = this.getCursor();
|
|
@@ -169,25 +182,26 @@ export class AgentNavigationEditor extends CustomEditor {
|
|
|
169
182
|
!this.focused ||
|
|
170
183
|
this.inputEpoch !== epoch ||
|
|
171
184
|
this.navigation.generation() !== generation ||
|
|
172
|
-
!
|
|
185
|
+
!allowed() ||
|
|
173
186
|
this.isShowingAutocomplete() ||
|
|
174
187
|
this.getText() !== text ||
|
|
175
188
|
after.line !== cursor.line ||
|
|
176
189
|
after.col !== cursor.col
|
|
177
190
|
) {
|
|
178
|
-
this.pending =
|
|
191
|
+
this.pending = undefined;
|
|
179
192
|
return;
|
|
180
193
|
}
|
|
181
194
|
try {
|
|
182
195
|
// Call within the checked microtask: an extra Promise.then would leave
|
|
183
196
|
// a gap in which root ownership could change after validation.
|
|
184
|
-
void Promise.resolve(
|
|
197
|
+
void Promise.resolve(direction === "left"
|
|
198
|
+
? this.navigation.openTree() : this.navigation.collapseWidget!())
|
|
185
199
|
.catch((error: unknown) => this.navigation.onError?.(error))
|
|
186
200
|
.finally(() => {
|
|
187
|
-
this.pending =
|
|
201
|
+
this.pending = undefined;
|
|
188
202
|
});
|
|
189
203
|
} catch (error) {
|
|
190
|
-
this.pending =
|
|
204
|
+
this.pending = undefined;
|
|
191
205
|
this.navigation.onError?.(error);
|
|
192
206
|
}
|
|
193
207
|
});
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
} from "@earendil-works/pi-tui";
|
|
14
14
|
import type { ThreadService, TranscriptSnapshot } from "../types.ts";
|
|
15
15
|
import { dialogText, type DialogHost } from "./dialog.ts";
|
|
16
|
-
import { agentTypeLabel } from "./ui.ts";
|
|
16
|
+
import { AGENT_PROGRESS_INTERVAL, agentProgressIcon, agentTypeLabel } from "./ui.ts";
|
|
17
17
|
|
|
18
18
|
/** Transcript detail level cycled by the t key: full → preview → compact. */
|
|
19
19
|
export type TranscriptDetail = "full" | "preview" | "compact";
|
|
@@ -64,6 +64,7 @@ export class LiveAgentView {
|
|
|
64
64
|
private attachment = 0;
|
|
65
65
|
private unsubscribe: (() => void) | undefined;
|
|
66
66
|
private renderTimer: ReturnType<typeof setTimeout> | undefined;
|
|
67
|
+
private progressTimer: ReturnType<typeof setInterval> | undefined;
|
|
67
68
|
private cache = new WeakMap<object, { width: number; detail: TranscriptDetail; lines: string[] }>();
|
|
68
69
|
private scroll: ScrollView;
|
|
69
70
|
private content: string[] = [];
|
|
@@ -165,6 +166,7 @@ export class LiveAgentView {
|
|
|
165
166
|
} catch (error) {
|
|
166
167
|
if (this.disposed || attachment !== this.attachment) return;
|
|
167
168
|
this.error = error instanceof Error ? error.message : String(error);
|
|
169
|
+
this.syncProgress();
|
|
168
170
|
this.scheduleRender();
|
|
169
171
|
}
|
|
170
172
|
}
|
|
@@ -179,9 +181,23 @@ export class LiveAgentView {
|
|
|
179
181
|
return;
|
|
180
182
|
this.snapshot = snapshot;
|
|
181
183
|
this.error = snapshot.error;
|
|
184
|
+
this.syncProgress();
|
|
182
185
|
this.scheduleRender();
|
|
183
186
|
}
|
|
184
187
|
|
|
188
|
+
private syncProgress(): void {
|
|
189
|
+
const state = this.snapshot?.thread?.state;
|
|
190
|
+
const active = this.nerdFontIcons && !this.disposed && !this.error &&
|
|
191
|
+
(state === "starting" || state === "running");
|
|
192
|
+
if (!active) {
|
|
193
|
+
if (this.progressTimer !== undefined) clearInterval(this.progressTimer);
|
|
194
|
+
this.progressTimer = undefined;
|
|
195
|
+
} else if (this.progressTimer === undefined) {
|
|
196
|
+
this.progressTimer = setInterval(() => this.scheduleRender(), AGENT_PROGRESS_INTERVAL);
|
|
197
|
+
this.progressTimer.unref?.();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
185
201
|
private scheduleRender(): void {
|
|
186
202
|
if (this.disposed || this.renderTimer) return;
|
|
187
203
|
this.renderTimer = setTimeout(() => {
|
|
@@ -204,6 +220,7 @@ export class LiveAgentView {
|
|
|
204
220
|
this.unsubscribe = undefined;
|
|
205
221
|
if (this.renderTimer) clearTimeout(this.renderTimer);
|
|
206
222
|
this.renderTimer = undefined;
|
|
223
|
+
this.syncProgress();
|
|
207
224
|
}
|
|
208
225
|
|
|
209
226
|
handleInput(data: string): void {
|
|
@@ -460,7 +477,7 @@ export class LiveAgentView {
|
|
|
460
477
|
const header = this.theme.fg(
|
|
461
478
|
"accent",
|
|
462
479
|
dialogText(
|
|
463
|
-
`${this.path} · ${agentTypeLabel(thread?.type ?? "agent", thread
|
|
480
|
+
`${this.path} · ${agentTypeLabel(thread?.type ?? "agent", thread ? agentProgressIcon(thread, this.nerdFontIcons) : undefined, this.nerdFontIcons)} · ${thread?.state ?? "attaching"} — Watching — main continues`,
|
|
464
481
|
),
|
|
465
482
|
);
|
|
466
483
|
const body: string[] = [];
|
package/src/ui/status-ui.ts
CHANGED
|
@@ -25,7 +25,9 @@ import {
|
|
|
25
25
|
} from "./dialog.ts";
|
|
26
26
|
import type { ThreadService } from "../types.ts";
|
|
27
27
|
import { buildStatusTree, type StatusRow } from "./thread-tree.ts";
|
|
28
|
-
import {
|
|
28
|
+
import {
|
|
29
|
+
AGENT_PROGRESS_INTERVAL, agentProgressIcon, agentTypeBadge, agentTypeLabel, showThreads, threadMetrics,
|
|
30
|
+
} from "./ui.ts";
|
|
29
31
|
import { LiveAgentView, fillViewport, type AgentViewportState } from "./live-agent-view.ts";
|
|
30
32
|
|
|
31
33
|
export { buildStatusTree, type StatusRow };
|
|
@@ -91,6 +93,8 @@ export class StatusDialog {
|
|
|
91
93
|
}
|
|
92
94
|
private viewport = 1;
|
|
93
95
|
private timer: ReturnType<typeof setInterval> | undefined;
|
|
96
|
+
private refreshDelay = 0;
|
|
97
|
+
private refreshing = false;
|
|
94
98
|
|
|
95
99
|
constructor(
|
|
96
100
|
private host: DialogHost,
|
|
@@ -111,22 +115,39 @@ export class StatusDialog {
|
|
|
111
115
|
|
|
112
116
|
invalidate(): void {}
|
|
113
117
|
|
|
114
|
-
/**
|
|
118
|
+
/** Poll retained status, accelerating the existing timer only for animated live agents. */
|
|
115
119
|
startRefresh(): void {
|
|
116
120
|
this.stopRefresh();
|
|
117
|
-
this.
|
|
118
|
-
|
|
121
|
+
this.refreshing = true;
|
|
122
|
+
this.syncRefresh();
|
|
119
123
|
}
|
|
120
124
|
|
|
121
125
|
/** Stop the refresh. Safe to call more than once, including from dispose(). */
|
|
122
126
|
dispose(): void {
|
|
127
|
+
this.refreshing = false;
|
|
123
128
|
this.stopRefresh();
|
|
124
129
|
}
|
|
125
130
|
|
|
131
|
+
private syncRefresh(): void {
|
|
132
|
+
if (!this.refreshing) return;
|
|
133
|
+
const delay = this.nerdFontIcons && this.service.list().some((thread) =>
|
|
134
|
+
thread.path !== ROOT && (thread.state === "starting" || thread.state === "running"))
|
|
135
|
+
? AGENT_PROGRESS_INTERVAL : 1000;
|
|
136
|
+
if (this.timer !== undefined && this.refreshDelay === delay) return;
|
|
137
|
+
this.stopRefresh();
|
|
138
|
+
this.refreshDelay = delay;
|
|
139
|
+
this.timer = setInterval(() => {
|
|
140
|
+
this.syncRefresh();
|
|
141
|
+
this.host.requestRender();
|
|
142
|
+
}, delay);
|
|
143
|
+
if (typeof this.timer.unref === "function") this.timer.unref();
|
|
144
|
+
}
|
|
145
|
+
|
|
126
146
|
private stopRefresh(): void {
|
|
127
147
|
if (this.timer === undefined) return;
|
|
128
148
|
clearInterval(this.timer);
|
|
129
149
|
this.timer = undefined;
|
|
150
|
+
this.refreshDelay = 0;
|
|
130
151
|
}
|
|
131
152
|
|
|
132
153
|
/** Stop every live agent. Stopping a subtree covers its descendants, so only top-most live paths are sent. */
|
|
@@ -247,9 +268,11 @@ export class StatusDialog {
|
|
|
247
268
|
const rest = [thread.path, thread.state, thread.status]
|
|
248
269
|
.map((part) => dialogText(part))
|
|
249
270
|
.join(" ");
|
|
271
|
+
const badge = agentTypeBadge(thread.type, thread.color, this.theme,
|
|
272
|
+
agentProgressIcon(thread, this.nerdFontIcons), this.nerdFontIcons);
|
|
250
273
|
if (selected)
|
|
251
|
-
return `${this.theme.fg("accent", head)}${
|
|
252
|
-
return `${head}${
|
|
274
|
+
return `${this.theme.fg("accent", head)}${badge} ${this.theme.fg("accent", rest)}`;
|
|
275
|
+
return `${head}${badge} ${rest}`;
|
|
253
276
|
}
|
|
254
277
|
|
|
255
278
|
private detail(row: StatusRow | undefined): string[] {
|
|
@@ -263,6 +286,7 @@ export class StatusDialog {
|
|
|
263
286
|
}
|
|
264
287
|
|
|
265
288
|
render(width: number): string[] {
|
|
289
|
+
this.syncRefresh();
|
|
266
290
|
const rows = this.rows();
|
|
267
291
|
const height = this.navigation?.fullscreen
|
|
268
292
|
? Math.max(1, this.host.terminal?.rows ?? 24)
|