@xzzpig/pi-subagents 0.6.0 → 0.8.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 +45 -4
- package/README.md +1 -1
- package/agents/reviewer.md +12 -2
- package/docs/agents.md +4 -4
- package/docs/configuration.md +6 -6
- package/docs/extension-api.md +14 -4
- package/docs/models.md +47 -6
- package/docs/observability.md +14 -3
- package/docs/tool-reference.md +21 -6
- package/docs/workflows.md +7 -1
- package/index.ts +10 -1
- package/node_modules/@xzzpig/pi-components/CHANGELOG.md +102 -0
- package/node_modules/@xzzpig/pi-components/LICENSE +21 -0
- package/node_modules/@xzzpig/pi-components/README.md +59 -0
- package/node_modules/@xzzpig/pi-components/dist/index.d.ts +1 -0
- package/node_modules/@xzzpig/pi-components/dist/index.js +1 -0
- package/node_modules/@xzzpig/pi-components/dist/src/transcript.d.ts +345 -0
- package/node_modules/@xzzpig/pi-components/dist/src/transcript.js +1169 -0
- package/node_modules/@xzzpig/pi-components/package.json +49 -0
- package/node_modules/@xzzpig/pi-components/src/transcript.ts +1785 -0
- package/package.json +7 -3
- package/prompts/council.md +19 -7
- package/prompts/parallel-review.md +5 -1
- package/prompts/review-loop.md +9 -5
- package/skills/council-mode/SKILL.md +50 -26
- package/skills/pi-subagents/SKILL.md +5 -1
- package/skills/pi-subagents/references/constraints-and-recipes.md +16 -1
- package/skills/pi-subagents/references/execution-controls.md +13 -4
- package/skills/pi-subagents/references/multi-lane-orchestration.md +3 -3
- package/skills/pi-subagents/references/prompting-and-roles.md +14 -7
- package/src/agents/agent-management.ts +115 -14
- package/src/agents/agent-serializer.ts +4 -2
- package/src/agents/agents.ts +226 -48
- package/src/api/external-job-provider.ts +10 -1
- package/src/api/preflight.ts +52 -19
- package/src/api/project-panes.ts +2 -0
- package/src/extension/doctor.ts +10 -0
- package/src/extension/fanout-child.ts +3 -2
- package/src/extension/index.ts +24 -4
- package/src/extension/public-execution.ts +12 -9
- package/src/extension/rpc.ts +77 -3
- package/src/extension/schemas.ts +7 -1
- package/src/extension/tool-description.ts +9 -6
- package/src/extension/tool-result.ts +19 -0
- package/src/inspectors/herdr/client.ts +3 -3
- package/src/inspectors/herdr/focus.ts +55 -0
- package/src/inspectors/herdr/project-panes.ts +228 -44
- package/src/integrations/herdr-status.ts +26 -4
- package/src/runs/background/async-execution.ts +146 -17
- package/src/runs/background/async-job-tracker.ts +33 -14
- package/src/runs/background/async-resume.ts +23 -2
- package/src/runs/background/async-retention.ts +1 -1
- package/src/runs/background/async-status.ts +10 -0
- package/src/runs/background/chain-root-attachment.ts +5 -0
- package/src/runs/background/control-channel.ts +98 -10
- package/src/runs/background/notify.ts +62 -1
- package/src/runs/background/result-watcher.ts +4 -3
- package/src/runs/background/run-status.ts +15 -1
- package/src/runs/background/stale-run-reconciler.ts +3 -0
- package/src/runs/background/subagent-runner.ts +333 -48
- package/src/runs/background/wait-completions.ts +2 -0
- package/src/runs/background/wait-tool.ts +4 -3
- package/src/runs/foreground/async-stop-action.ts +23 -2
- package/src/runs/foreground/execution.ts +148 -13
- package/src/runs/foreground/foreground-history.ts +3 -2
- package/src/runs/foreground/subagent-executor.ts +417 -50
- package/src/runs/foreground/workflow-detach-reconcile.ts +18 -6
- package/src/runs/shared/acceptance.ts +11 -5
- package/src/runs/shared/agent-contract.ts +1 -1
- package/src/runs/shared/child-identity.ts +36 -0
- package/src/runs/shared/completion-guard.ts +52 -2
- package/src/runs/shared/dynamic-fanout.ts +1 -1
- package/src/runs/shared/extension-bindings.ts +78 -0
- package/src/runs/shared/external-cli-runner.ts +2 -0
- package/src/runs/shared/external-job-bridge.ts +53 -37
- package/src/runs/shared/external-job-runner.ts +126 -23
- package/src/runs/shared/fast-mode-extension.ts +10 -0
- package/src/runs/shared/model-exclusions.ts +2 -1
- package/src/runs/shared/model-fallback.ts +48 -22
- package/src/runs/shared/model-scope.ts +106 -39
- package/src/runs/shared/mutation-evidence.ts +145 -0
- package/src/runs/shared/orca-progress-tabs.ts +71 -9
- package/src/runs/shared/parallel-utils.ts +15 -0
- package/src/runs/shared/pi-args.ts +78 -1
- package/src/runs/shared/structured-output.ts +18 -4
- package/src/runs/shared/subagent-prompt-runtime.ts +48 -15
- package/src/runs/shared/tool-availability.ts +1 -3
- package/src/shared/launch-contract.ts +12 -5
- package/src/shared/settings.ts +6 -1
- package/src/shared/thinking-ceiling.ts +52 -0
- package/src/shared/types.ts +121 -5
- package/src/tui/fleet-native-transcript.ts +374 -0
- package/src/tui/fleet-status.ts +66 -13
- package/src/tui/fleet-transcript.ts +47 -1
- package/src/tui/fleet.ts +96 -24
- package/src/tui/render.ts +5 -4
- package/src/watchdog/permission-arbiter.ts +59 -52
- package/src/workflows/scripted-workflow.ts +156 -12
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
TranscriptEntry,
|
|
3
|
+
TranscriptState,
|
|
4
|
+
} from "@xzzpig/pi-components/transcript";
|
|
5
|
+
import { readTranscriptRecords, type FleetTranscriptReadOptions } from "./fleet-transcript.ts";
|
|
6
|
+
|
|
7
|
+
/** Runtime shape of `@xzzpig/pi-components/transcript` as consumed here.
|
|
8
|
+
* Expressed as a static typeof-import so the dependency stays lazy at
|
|
9
|
+
* runtime: the module is only loaded through the guarded dynamic import. */
|
|
10
|
+
type NativeTranscriptModule = typeof import("@xzzpig/pi-components/transcript");
|
|
11
|
+
|
|
12
|
+
export type { NativeTranscriptModule };
|
|
13
|
+
|
|
14
|
+
const REQUIRED_NATIVE_EXPORTS = [
|
|
15
|
+
"createTranscriptState",
|
|
16
|
+
"appendEntry",
|
|
17
|
+
"ensureTurn",
|
|
18
|
+
"finishTurn",
|
|
19
|
+
"findLatestEntry",
|
|
20
|
+
"ensureToolCall",
|
|
21
|
+
"upsertText",
|
|
22
|
+
"upsertToolResult",
|
|
23
|
+
"appendNotice",
|
|
24
|
+
"renderTranscriptLines",
|
|
25
|
+
"TranscriptToolComponents",
|
|
26
|
+
"ensureTranscriptTheme",
|
|
27
|
+
] as const;
|
|
28
|
+
|
|
29
|
+
let nativeSupportPromise: Promise<NativeTranscriptModule | null> | undefined;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Structural probe for a candidate transcript module: every export the native
|
|
33
|
+
* renderer calls must be present. Exported pure so hosts and tests can check
|
|
34
|
+
* arbitrary objects (e.g. simulating an older shared-library build).
|
|
35
|
+
*/
|
|
36
|
+
export function hasRequiredNativeExports(candidate: unknown): candidate is NativeTranscriptModule {
|
|
37
|
+
if (!candidate || typeof candidate !== "object") return false;
|
|
38
|
+
return REQUIRED_NATIVE_EXPORTS.every((name) => name in (candidate as Record<string, unknown>));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Loads the shared transcript module once and validates it exposes every
|
|
43
|
+
* export the native renderer needs. Resolves `null` when the package is
|
|
44
|
+
* absent (or an older host ships an incompatible build) so callers can fall
|
|
45
|
+
* back to the legacy rail renderer without try/catch at call sites.
|
|
46
|
+
*/
|
|
47
|
+
export function loadNativeTranscriptSupport(): Promise<NativeTranscriptModule | null> {
|
|
48
|
+
nativeSupportPromise ??= (async () => {
|
|
49
|
+
try {
|
|
50
|
+
const mod: NativeTranscriptModule = await import("@xzzpig/pi-components/transcript");
|
|
51
|
+
return hasRequiredNativeExports(mod) ? mod : null;
|
|
52
|
+
} catch {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
})();
|
|
56
|
+
return nativeSupportPromise;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface NativeFleetBuildInput {
|
|
60
|
+
filePath: string;
|
|
61
|
+
trustedRoots: string[];
|
|
62
|
+
width: number;
|
|
63
|
+
expandedTools: boolean;
|
|
64
|
+
cwd?: string;
|
|
65
|
+
maxRecords?: number;
|
|
66
|
+
theme: {
|
|
67
|
+
fg(color: string, text: string): string;
|
|
68
|
+
bg(color: string, text: string): string;
|
|
69
|
+
bold(text: string): string;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface NativeFleetBuildResult {
|
|
74
|
+
lines: string[];
|
|
75
|
+
conversationState: string;
|
|
76
|
+
truncated: boolean;
|
|
77
|
+
warning?: string;
|
|
78
|
+
entryCount: number;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function contentParts(content: unknown): Array<{ type: string; text?: string; thinking?: string }> {
|
|
82
|
+
if (!Array.isArray(content)) return [];
|
|
83
|
+
return content.filter((part): part is { type: string; text?: string; thinking?: string } =>
|
|
84
|
+
Boolean(part) && typeof part === "object" && typeof (part as { type?: unknown }).type === "string");
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function partsToText(parts: Array<{ type: string; text?: string }>): string {
|
|
88
|
+
return parts
|
|
89
|
+
.filter((part) => part.type === "text" && typeof part.text === "string")
|
|
90
|
+
.map((part) => part.text)
|
|
91
|
+
.join("\n")
|
|
92
|
+
.trim();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function partsToThinking(parts: Array<{ type: string; thinking?: string }>): string {
|
|
96
|
+
return parts
|
|
97
|
+
.filter((part) => part.type === "thinking" && typeof part.thinking === "string")
|
|
98
|
+
.map((part) => part.thinking)
|
|
99
|
+
.join("\n")
|
|
100
|
+
.trim();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function parseArgsPayload(value: unknown): Record<string, unknown> | undefined {
|
|
104
|
+
if (typeof value !== "string" || !value.trim()) return undefined;
|
|
105
|
+
try {
|
|
106
|
+
const parsed: unknown = JSON.parse(value);
|
|
107
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed)
|
|
108
|
+
? parsed as Record<string, unknown>
|
|
109
|
+
: undefined;
|
|
110
|
+
} catch {
|
|
111
|
+
// Truncated payloads (>32 KiB at write time) are not valid JSON; D4
|
|
112
|
+
// degrades them to empty arguments instead of failing the entry.
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function stringValue(record: Record<string, unknown>, key: string): string | undefined {
|
|
118
|
+
const value = record[key];
|
|
119
|
+
return typeof value === "string" && value.trim() ? value : undefined;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function nestedField(record: Record<string, unknown>, key: string): Record<string, unknown> | undefined {
|
|
123
|
+
const value = record[key];
|
|
124
|
+
return value && typeof value === "object" && !Array.isArray(value)
|
|
125
|
+
? value as Record<string, unknown>
|
|
126
|
+
: undefined;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Builds entries from child-transcript v1 JSONL records. Mirrors the legacy
|
|
130
|
+
* parser's semantics: user messages open exchanges (a finished assistant turn
|
|
131
|
+
* is closed before the next supervisor message), tool calls pair with results
|
|
132
|
+
* by toolCallId regardless of record order, stderr becomes an error notice,
|
|
133
|
+
* and stdout stays ignored. */
|
|
134
|
+
function ingestRecords(
|
|
135
|
+
mod: NativeTranscriptModule,
|
|
136
|
+
state: TranscriptState,
|
|
137
|
+
records: Array<Record<string, unknown>>,
|
|
138
|
+
): { truncatedMarkerSeen: boolean } {
|
|
139
|
+
let truncatedMarkerSeen = false;
|
|
140
|
+
let currentTurnHasFinishedAssistant = false;
|
|
141
|
+
const pendingErrors = new Map<string, boolean>();
|
|
142
|
+
const degradedArgs = new Map<string, string>();
|
|
143
|
+
|
|
144
|
+
for (const record of records) {
|
|
145
|
+
const recordType = stringValue(record, "recordType");
|
|
146
|
+
if (recordType === "truncated") {
|
|
147
|
+
truncatedMarkerSeen = true;
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (recordType === "stdout") continue;
|
|
151
|
+
|
|
152
|
+
if (recordType === "stderr") {
|
|
153
|
+
const text = stringValue(record, "text");
|
|
154
|
+
if (text) mod.appendNotice(state, text, "error");
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (recordType === "tool_start") {
|
|
159
|
+
const turnId = mod.ensureTurn(state);
|
|
160
|
+
const toolName = stringValue(record, "toolName") ?? "tool";
|
|
161
|
+
const toolCallId = stringValue(record, "toolCallId") ?? `tool-${state.nextEntryId}`;
|
|
162
|
+
const parsedArgs = parseArgsPayload(record.argsPayload);
|
|
163
|
+
if (parsedArgs === undefined && record.argsPayload !== undefined) {
|
|
164
|
+
// Truncated/corrupt payload: builtin renderers need real args and
|
|
165
|
+
// may swallow text-only results, so remember to re-surface the
|
|
166
|
+
// preview and outcome as a warning notice after pairing completes.
|
|
167
|
+
degradedArgs.set(toolCallId, stringValue(record, "argsPreview") ?? "");
|
|
168
|
+
}
|
|
169
|
+
mod.ensureToolCall(state, turnId, toolCallId, toolName, parsedArgs ?? {});
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (recordType === "tool_end") {
|
|
174
|
+
const toolCallId = stringValue(record, "toolCallId");
|
|
175
|
+
if (toolCallId) pendingErrors.set(toolCallId, record.isError === true);
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (recordType !== "message") continue;
|
|
180
|
+
|
|
181
|
+
const message = nestedField(record, "message");
|
|
182
|
+
const role = stringValue(record, "role") ?? stringValue(message ?? {}, "role");
|
|
183
|
+
|
|
184
|
+
if (role === "user") {
|
|
185
|
+
if (state.currentTurnId !== null && currentTurnHasFinishedAssistant) {
|
|
186
|
+
mod.finishTurn(state);
|
|
187
|
+
}
|
|
188
|
+
const turnId = mod.ensureTurn(state);
|
|
189
|
+
const textParts = contentParts(message?.content);
|
|
190
|
+
const text = stringValue(record, "text") ?? partsToText(textParts);
|
|
191
|
+
if (!text) continue;
|
|
192
|
+
const existing = mod.findLatestEntry(state, turnId, "user-message");
|
|
193
|
+
if (existing) existing.text = text;
|
|
194
|
+
else mod.appendEntry(state, { type: "user-message", turnId, text });
|
|
195
|
+
currentTurnHasFinishedAssistant = false;
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (role === "assistant") {
|
|
200
|
+
const turnId = mod.ensureTurn(state);
|
|
201
|
+
const parts = contentParts(message?.content);
|
|
202
|
+
const thinking = partsToThinking(parts);
|
|
203
|
+
const text = partsToText(parts);
|
|
204
|
+
if (thinking) mod.upsertText(state, turnId, "thinking", thinking, false);
|
|
205
|
+
if (text) {
|
|
206
|
+
mod.upsertText(state, turnId, "assistant-text", text, false);
|
|
207
|
+
currentTurnHasFinishedAssistant = true;
|
|
208
|
+
}
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (role === "toolResult" || role === "tool_result") {
|
|
213
|
+
const toolCallId = stringValue(record, "toolCallId") ?? stringValue(message ?? {}, "toolCallId") ?? `tool-${state.nextEntryId}`;
|
|
214
|
+
const toolName = stringValue(record, "toolName") ?? stringValue(message ?? {}, "toolName") ?? "tool";
|
|
215
|
+
const failed = record.isError === true || message?.isError === true;
|
|
216
|
+
const isError = failed || pendingErrors.get(toolCallId) === true;
|
|
217
|
+
pendingErrors.delete(toolCallId);
|
|
218
|
+
const resultContent = Array.isArray(message?.content)
|
|
219
|
+
? message.content
|
|
220
|
+
: typeof record.text === "string"
|
|
221
|
+
? [{ type: "text", text: record.text }]
|
|
222
|
+
: [];
|
|
223
|
+
const turnId = state.toolCalls.get(toolCallId)?.turnId ?? mod.ensureTurn(state);
|
|
224
|
+
mod.upsertToolResult(
|
|
225
|
+
state,
|
|
226
|
+
turnId,
|
|
227
|
+
toolCallId,
|
|
228
|
+
toolName,
|
|
229
|
+
{ content: resultContent },
|
|
230
|
+
isError,
|
|
231
|
+
false,
|
|
232
|
+
);
|
|
233
|
+
currentTurnHasFinishedAssistant = false;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Terminal-state guarantee: every recorded call gets a result entry so the
|
|
238
|
+
// native component never renders a stale running spinner for history.
|
|
239
|
+
for (const [toolCallId, toolCall] of state.toolCalls.entries()) {
|
|
240
|
+
if (toolCall.resultEntryId !== undefined) continue;
|
|
241
|
+
const callEntry = state.entries.find((entry) => entry.id === toolCall.callEntryId);
|
|
242
|
+
if (callEntry?.type !== "tool-call") continue;
|
|
243
|
+
const isError = pendingErrors.get(toolCallId) === true;
|
|
244
|
+
mod.upsertToolResult(
|
|
245
|
+
state,
|
|
246
|
+
toolCall.turnId,
|
|
247
|
+
toolCallId,
|
|
248
|
+
callEntry.toolName,
|
|
249
|
+
{ content: [{ type: "text", text: isError ? "(tool ended with error)" : "(no result recorded)" }] },
|
|
250
|
+
isError,
|
|
251
|
+
false,
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Degraded-argument visibility net: builtin renderers can hide text-only
|
|
256
|
+
// results when args are empty, so re-surface preview + outcome as a notice.
|
|
257
|
+
for (const [toolCallId, preview] of degradedArgs) {
|
|
258
|
+
const toolRecord = state.toolCalls.get(toolCallId);
|
|
259
|
+
const callEntry = state.entries.find((entry) => entry.id === toolRecord?.callEntryId);
|
|
260
|
+
if (callEntry?.type !== "tool-call") continue;
|
|
261
|
+
const resultEntry = toolRecord?.resultEntryId === undefined
|
|
262
|
+
? undefined
|
|
263
|
+
: state.entries.find((candidate) => candidate.id === toolRecord.resultEntryId);
|
|
264
|
+
const resultText = resultEntry?.type === "tool-result"
|
|
265
|
+
? (resultEntry.result?.content ?? []).map((part) => part.text ?? "").join(" ").trim()
|
|
266
|
+
: "";
|
|
267
|
+
const summary = [
|
|
268
|
+
`${callEntry.toolName}: arguments truncated`,
|
|
269
|
+
preview ? `preview ${preview}` : undefined,
|
|
270
|
+
resultText ? `result: ${resultText.split(/\r?\n/)[0]}` : undefined,
|
|
271
|
+
].filter(Boolean).join(" · ");
|
|
272
|
+
mod.appendNotice(state, summary, "warning");
|
|
273
|
+
}
|
|
274
|
+
return { truncatedMarkerSeen };
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function conversationStateOf(entries: readonly TranscriptEntry[]): string {
|
|
278
|
+
for (let index = entries.length - 1; index >= 0; index--) {
|
|
279
|
+
const entry = entries[index];
|
|
280
|
+
if (!entry || entry.type === "turn-boundary") continue;
|
|
281
|
+
if (entry.type === "assistant-text") return "assistant response";
|
|
282
|
+
if (entry.type === "user-message") return "supervisor message";
|
|
283
|
+
if (entry.type === "tool-result") return `${entry.toolName} · ${entry.isError ? "error" : "complete"}`;
|
|
284
|
+
if (entry.type === "tool-call") {
|
|
285
|
+
const toolRecord = state_toolCallStatus(entries, entry.toolCallId);
|
|
286
|
+
return `${entry.toolName} · ${toolRecord}`;
|
|
287
|
+
}
|
|
288
|
+
return "activity";
|
|
289
|
+
}
|
|
290
|
+
return "activity";
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function state_toolCallStatus(entries: readonly TranscriptEntry[], toolCallId: string): "running" | "complete" | "error" {
|
|
294
|
+
for (let index = entries.length - 1; index >= 0; index--) {
|
|
295
|
+
const entry = entries[index];
|
|
296
|
+
if (entry?.type === "tool-result" && entry.toolCallId === toolCallId) {
|
|
297
|
+
return entry.isError ? "error" : "complete";
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return "complete";
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Renders a persisted child transcript through Pi-native components. Reads
|
|
305
|
+
* via the shared trusted-root guard, replays records into shared-library
|
|
306
|
+
* entries, then renders with the same message/tool components the main
|
|
307
|
+
* transcript uses. Returns `null` only when the caller passed a module that
|
|
308
|
+
* turned out to be unusable; read/validation problems surface as warnings.
|
|
309
|
+
*/
|
|
310
|
+
export function buildNativeFleetTranscript(
|
|
311
|
+
mod: NativeTranscriptModule,
|
|
312
|
+
input: NativeFleetBuildInput,
|
|
313
|
+
): NativeFleetBuildResult {
|
|
314
|
+
mod.ensureTranscriptTheme();
|
|
315
|
+
const readOptions: FleetTranscriptReadOptions = {
|
|
316
|
+
trustedRoots: input.trustedRoots,
|
|
317
|
+
...(input.maxRecords !== undefined ? { maxRecords: input.maxRecords } : {}),
|
|
318
|
+
};
|
|
319
|
+
const read = readTranscriptRecords(input.filePath, readOptions);
|
|
320
|
+
if (read.records.length === 0) {
|
|
321
|
+
return {
|
|
322
|
+
lines: [],
|
|
323
|
+
conversationState: "activity",
|
|
324
|
+
truncated: read.truncated,
|
|
325
|
+
...(read.warning ? { warning: read.warning } : {}),
|
|
326
|
+
entryCount: 0,
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
const state = mod.createTranscriptState({});
|
|
331
|
+
const { truncatedMarkerSeen } = ingestRecords(mod, state, read.records);
|
|
332
|
+
|
|
333
|
+
const registry = new mod.TranscriptToolComponents({
|
|
334
|
+
expanded: input.expandedTools,
|
|
335
|
+
...(input.cwd ? { cwd: input.cwd } : {}),
|
|
336
|
+
});
|
|
337
|
+
for (const entry of state.entries) {
|
|
338
|
+
if (entry.type !== "tool-call") continue;
|
|
339
|
+
registry.handleStart(entry.toolCallId, entry.toolName, entry.args);
|
|
340
|
+
const toolRecord = state.toolCalls.get(entry.toolCallId);
|
|
341
|
+
const resultEntry = toolRecord?.resultEntryId === undefined
|
|
342
|
+
? undefined
|
|
343
|
+
: state.entries.find((candidate) => candidate.id === toolRecord.resultEntryId);
|
|
344
|
+
if (resultEntry?.type === "tool-result") {
|
|
345
|
+
registry.handleEnd(entry.toolCallId, entry.toolName, resultEntry.result, resultEntry.isError);
|
|
346
|
+
} else {
|
|
347
|
+
registry.handleEnd(entry.toolCallId, entry.toolName, null, false);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
const lines = mod.renderTranscriptLines(state.entries, {
|
|
352
|
+
width: input.width,
|
|
353
|
+
theme: input.theme,
|
|
354
|
+
toolComponents: registry,
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
const indicatorLines: string[] = [];
|
|
358
|
+
if (read.truncated || truncatedMarkerSeen) {
|
|
359
|
+
indicatorLines.push(input.theme.fg("dim", "↑ Earlier activity omitted"));
|
|
360
|
+
}
|
|
361
|
+
if (read.warning) {
|
|
362
|
+
for (const line of read.warning.split(/\r?\n/)) {
|
|
363
|
+
indicatorLines.push(input.theme.fg("warning", `! ${line}`));
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
return {
|
|
368
|
+
lines: [...indicatorLines, ...lines],
|
|
369
|
+
conversationState: conversationStateOf(state.entries),
|
|
370
|
+
truncated: read.truncated || truncatedMarkerSeen,
|
|
371
|
+
...(read.warning ? { warning: read.warning } : {}),
|
|
372
|
+
entryCount: state.entries.length,
|
|
373
|
+
};
|
|
374
|
+
}
|
package/src/tui/fleet-status.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
|
2
2
|
import { type EditorComponent, isKeyRelease, Key, matchesKey, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
3
3
|
import { snapshotExternalRuns } from "../api/external-runs.ts";
|
|
4
4
|
import { formatModelThinking } from "../shared/formatters.ts";
|
|
5
|
-
import type { AsyncJobStep, FleetViewPlacement, NestedRunSummary, NestedStepSummary, SubagentState } from "../shared/types.ts";
|
|
5
|
+
import type { AsyncJobState, AsyncJobStep, FleetViewPlacement, HerdrProjectPaneSnapshot, NestedRunSummary, NestedStepSummary, SubagentState } from "../shared/types.ts";
|
|
6
6
|
import { formatWorkflowJsonPreview } from "../workflows/scripted-workflow.ts";
|
|
7
7
|
|
|
8
8
|
export const FLEET_STATUS_WIDGET_KEY = "subagent-fleet-status";
|
|
@@ -17,6 +17,7 @@ type FleetStatusTui = {
|
|
|
17
17
|
};
|
|
18
18
|
type FleetStatusEntry = {
|
|
19
19
|
key: string;
|
|
20
|
+
surface?: "project-pane";
|
|
20
21
|
parentKey?: string;
|
|
21
22
|
workflowWrapper?: boolean;
|
|
22
23
|
agent: string;
|
|
@@ -26,6 +27,7 @@ type FleetStatusEntry = {
|
|
|
26
27
|
tokens: number;
|
|
27
28
|
state: string;
|
|
28
29
|
external?: true;
|
|
30
|
+
projectPane?: HerdrProjectPaneSnapshot;
|
|
29
31
|
nestedChildren?: NestedRunSummary[];
|
|
30
32
|
workflowRows?: FleetWorkflowRow[];
|
|
31
33
|
};
|
|
@@ -284,7 +286,32 @@ function foregroundDescription(control: { parentWorkflowRunId?: string; workflow
|
|
|
284
286
|
}
|
|
285
287
|
|
|
286
288
|
function activeLeafAgentCount(entries: FleetStatusEntry[]): number {
|
|
287
|
-
return entries.filter((entry) => !entry.workflowWrapper).length;
|
|
289
|
+
return entries.filter((entry) => !entry.workflowWrapper && !entry.surface).length;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function projectPaneNeedsAttention(pane: HerdrProjectPaneSnapshot): boolean {
|
|
293
|
+
return ["attention", "blocked", "paused", "failed", "error"].some((status) => pane.agentStatus.includes(status))
|
|
294
|
+
|| pane.summary?.includes("⚠") === true;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function projectName(projectRoot: string): string {
|
|
298
|
+
return projectRoot.split(/[\\/]/).filter(Boolean).at(-1) ?? projectRoot;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function projectPaneEntries(state: SubagentState): FleetStatusEntry[] {
|
|
302
|
+
return [...(state.herdrProjectPanes?.values() ?? [])]
|
|
303
|
+
.filter((pane) => pane.state === "open")
|
|
304
|
+
.sort((left, right) => left.openedAt.localeCompare(right.openedAt) || left.projectRoot.localeCompare(right.projectRoot))
|
|
305
|
+
.map((pane) => ({
|
|
306
|
+
key: `project-pane:${pane.projectRoot}`,
|
|
307
|
+
surface: "project-pane" as const,
|
|
308
|
+
agent: `${projectName(pane.projectRoot)} · ${pane.paneId}`,
|
|
309
|
+
description: pane.summary,
|
|
310
|
+
startedAt: Date.parse(pane.openedAt) || pane.refreshedAt,
|
|
311
|
+
tokens: 0,
|
|
312
|
+
state: pane.agentStatus || "unknown",
|
|
313
|
+
projectPane: pane,
|
|
314
|
+
}));
|
|
288
315
|
}
|
|
289
316
|
|
|
290
317
|
export function collectFleetStatusEntries(state: SubagentState): FleetStatusEntry[] {
|
|
@@ -406,6 +433,7 @@ export function collectFleetStatusEntries(state: SubagentState): FleetStatusEntr
|
|
|
406
433
|
}
|
|
407
434
|
}
|
|
408
435
|
|
|
436
|
+
entries.push(...projectPaneEntries(state));
|
|
409
437
|
return entries.sort((left, right) => left.startedAt - right.startedAt || left.key.localeCompare(right.key));
|
|
410
438
|
}
|
|
411
439
|
|
|
@@ -483,7 +511,7 @@ export class SubagentFleetStatus {
|
|
|
483
511
|
this.clearWidget();
|
|
484
512
|
return;
|
|
485
513
|
}
|
|
486
|
-
if (this.
|
|
514
|
+
if (!this.hasInlineSurface()) {
|
|
487
515
|
this.active = false;
|
|
488
516
|
this.selectedKey = "main";
|
|
489
517
|
this.lastRenderKey = "";
|
|
@@ -578,26 +606,31 @@ export class SubagentFleetStatus {
|
|
|
578
606
|
}
|
|
579
607
|
|
|
580
608
|
render(width: number, theme: Theme): string[] {
|
|
581
|
-
if (this.
|
|
609
|
+
if (!this.hasInlineSurface()) return [];
|
|
582
610
|
if (!this.active) {
|
|
583
|
-
const
|
|
611
|
+
const workEntries = this.entries.filter((entry) => !entry.surface);
|
|
612
|
+
const projectEntries = this.entries.filter((entry) => entry.surface === "project-pane");
|
|
613
|
+
const tokens = workEntries.reduce((total, entry) => total + entry.tokens, 0);
|
|
584
614
|
const capacity = this.state.activeAsyncCapacity;
|
|
585
|
-
const hasNativeRows =
|
|
615
|
+
const hasNativeRows = workEntries.some((entry) => !entry.external);
|
|
586
616
|
const showNativeSummary = hasNativeRows || Boolean(capacity?.used);
|
|
587
617
|
const asyncRuns = capacity && showNativeSummary ? `Async runs ${capacity.used}/${capacity.limit || "∞"}` : "";
|
|
588
|
-
const activeEntries = activeLeafAgentCount(
|
|
589
|
-
const noun =
|
|
618
|
+
const activeEntries = activeLeafAgentCount(workEntries);
|
|
619
|
+
const noun = workEntries.some((entry) => entry.external) ? "job" : "agent";
|
|
590
620
|
const agents = activeEntries > 0 ? `${activeEntries} active ${noun}${activeEntries === 1 ? "" : "s"}` : "";
|
|
591
|
-
const
|
|
621
|
+
const paneAttention = projectEntries.filter((entry) => entry.projectPane && projectPaneNeedsAttention(entry.projectPane)).length;
|
|
622
|
+
const panes = projectEntries.length > 0 ? `${projectEntries.length} pane${projectEntries.length === 1 ? "" : "s"}${paneAttention ? ` (${paneAttention} ⚠)` : ""}` : "";
|
|
623
|
+
const label = [agents, asyncRuns, panes].filter(Boolean).join(" · ");
|
|
592
624
|
const detail = [showNativeSummary ? formatFleetTokens(tokens) : undefined, "↓/← to inspect"].filter(Boolean).join(" · ");
|
|
593
|
-
return [truncateToWidth(` ${theme.fg("muted", label)} · ${theme.fg("dim", detail)}`, width)];
|
|
625
|
+
return [truncateToWidth(` ${theme.fg("muted", label)}${label && detail ? " · " : ""}${theme.fg("dim", detail)}`, width)];
|
|
594
626
|
}
|
|
595
627
|
const roster = this.rosterKeys();
|
|
596
628
|
const selectedIndex = Math.max(0, roster.indexOf(this.selectedKey));
|
|
597
629
|
const lines = [truncateToWidth(` ${theme.fg("dim", "↑↓/jk select · enter inspect · esc back")}`, width), ""];
|
|
598
630
|
lines.push(truncateToWidth(` ${this.bullet(0, selectedIndex, theme)} main`, width));
|
|
599
631
|
|
|
600
|
-
const
|
|
632
|
+
const workEntries = this.entries.filter((entry) => !entry.surface);
|
|
633
|
+
const tree = fleetTreeRows(workEntries);
|
|
601
634
|
const selectedTreeIndex = Math.max(0, tree.findIndex((row) => (row.kind === "owner" || row.kind === "child") && row.entry.key === this.selectedKey));
|
|
602
635
|
const visibleCount = Math.min(this.maxAgentRows, tree.length);
|
|
603
636
|
const start = selectedTreeIndex < visibleCount ? 0 : selectedTreeIndex - visibleCount + 1;
|
|
@@ -615,15 +648,30 @@ export class SubagentFleetStatus {
|
|
|
615
648
|
}
|
|
616
649
|
}
|
|
617
650
|
if (hiddenBelow > 0) lines.push(rightAlign("", theme.fg("dim", `↓ ${hiddenBelow} more`), width));
|
|
651
|
+
this.renderProjectPaneSection(lines, selectedIndex, width, theme);
|
|
618
652
|
return lines;
|
|
619
653
|
}
|
|
620
654
|
|
|
655
|
+
private renderProjectPaneSection(lines: string[], selectedIndex: number, width: number, theme: Theme): void {
|
|
656
|
+
const entries = this.entries.filter((entry) => entry.surface === "project-pane");
|
|
657
|
+
if (!entries.length) return;
|
|
658
|
+
lines.push("", truncateToWidth(` ${theme.fg("dim", "project panes")}`, width));
|
|
659
|
+
for (const entry of entries) {
|
|
660
|
+
const rosterIndex = this.entries.findIndex((candidate) => candidate.key === entry.key) + 1;
|
|
661
|
+
lines.push(this.renderEntry(rosterIndex, selectedIndex, entry, width, theme));
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
|
|
621
666
|
private renderEntry(rosterIndex: number, selectedIndex: number, entry: FleetStatusEntry, width: number, theme: Theme, branch?: string): string {
|
|
622
667
|
const agent = entry.modelThinking ? `${entry.agent} (${entry.modelThinking})` : entry.agent;
|
|
623
668
|
const prefix = branch ? ` ${branch}` : " ";
|
|
624
669
|
const left = `${prefix} ${this.bullet(rosterIndex, selectedIndex, theme)} ${theme.fg("muted", agent)} · ${entry.state}`;
|
|
625
670
|
const elapsed = Date.now() - entry.startedAt;
|
|
626
|
-
const
|
|
671
|
+
const rightText = entry.projectPane
|
|
672
|
+
? `${entry.projectPane.summary ?? "—"} · ${formatFleetElapsed(Date.now() - entry.projectPane.refreshedAt)} ago`
|
|
673
|
+
: entry.external ? formatFleetElapsed(elapsed) : `${formatFleetElapsed(elapsed)} · ${formatFleetTokens(entry.tokens)}`;
|
|
674
|
+
const right = theme.fg("dim", rightText);
|
|
627
675
|
return rightAlign(left, right, width);
|
|
628
676
|
}
|
|
629
677
|
|
|
@@ -692,6 +740,7 @@ export class SubagentFleetStatus {
|
|
|
692
740
|
entries: this.entries.map((entry) => this.active
|
|
693
741
|
? [
|
|
694
742
|
entry.key,
|
|
743
|
+
entry.surface,
|
|
695
744
|
entry.parentKey,
|
|
696
745
|
entry.agent,
|
|
697
746
|
entry.state,
|
|
@@ -719,10 +768,14 @@ export class SubagentFleetStatus {
|
|
|
719
768
|
row.overflow,
|
|
720
769
|
]),
|
|
721
770
|
]
|
|
722
|
-
: [entry.key, entry.state, entry.external, entry.tokens]),
|
|
771
|
+
: [entry.key, entry.state, entry.external, entry.surface, entry.tokens, entry.projectPane?.refreshedAt, entry.projectPane?.summary]),
|
|
723
772
|
});
|
|
724
773
|
}
|
|
725
774
|
|
|
775
|
+
private hasInlineSurface(): boolean {
|
|
776
|
+
return this.entries.length > 0 || Boolean(this.state.activeAsyncCapacity?.used);
|
|
777
|
+
}
|
|
778
|
+
|
|
726
779
|
private getActiveUiContext(): ExtensionContext | undefined {
|
|
727
780
|
const ctx = this.ctx;
|
|
728
781
|
if (!ctx) return undefined;
|
|
@@ -59,7 +59,7 @@ export interface FleetTranscript {
|
|
|
59
59
|
warning?: string;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
interface FleetTranscriptReadOptions {
|
|
62
|
+
export interface FleetTranscriptReadOptions {
|
|
63
63
|
trustedRoots: string[];
|
|
64
64
|
maxRecords?: number;
|
|
65
65
|
maxBytes?: number;
|
|
@@ -356,6 +356,52 @@ export function readFleetTranscript(filePath: string, options: FleetTranscriptRe
|
|
|
356
356
|
};
|
|
357
357
|
}
|
|
358
358
|
|
|
359
|
+
export interface TranscriptRecordRead {
|
|
360
|
+
records: Array<Record<string, unknown>>;
|
|
361
|
+
truncated: boolean;
|
|
362
|
+
warning?: string;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Shared trusted-root-guarded tail reader that returns raw parsed JSONL
|
|
367
|
+
* records instead of fleet events. Both the legacy rail renderer and the
|
|
368
|
+
* native-component renderer ingest through this single validation path, so
|
|
369
|
+
* symlink refusal and path-escape rejection cannot diverge between them.
|
|
370
|
+
*/
|
|
371
|
+
export function readTranscriptRecords(filePath: string, options: FleetTranscriptReadOptions): TranscriptRecordRead {
|
|
372
|
+
const validated = validateTranscriptPath(filePath, options.trustedRoots);
|
|
373
|
+
if (!validated.resolvedPath) {
|
|
374
|
+
return { records: [], truncated: false, ...(validated.warning ? { warning: safeDisplayText(validated.warning) } : {}) };
|
|
375
|
+
}
|
|
376
|
+
const maxRecords = Math.max(1, options.maxRecords ?? DEFAULT_MAX_RECORDS);
|
|
377
|
+
const tail = readTailLines(validated.resolvedPath, Math.max(1024, options.maxBytes ?? DEFAULT_MAX_BYTES));
|
|
378
|
+
const selected = tail.lines.slice(-maxRecords);
|
|
379
|
+
const records: Array<Record<string, unknown>> = [];
|
|
380
|
+
let malformed = 0;
|
|
381
|
+
for (const line of selected) {
|
|
382
|
+
if (!line.trim()) continue;
|
|
383
|
+
try {
|
|
384
|
+
const parsed: unknown = JSON.parse(line);
|
|
385
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
386
|
+
records.push(parsed as Record<string, unknown>);
|
|
387
|
+
} else {
|
|
388
|
+
malformed++;
|
|
389
|
+
}
|
|
390
|
+
} catch {
|
|
391
|
+
malformed++;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
const warnings = [
|
|
395
|
+
tail.warning,
|
|
396
|
+
malformed > 0 ? `Skipped ${malformed} malformed transcript record${malformed === 1 ? "" : "s"}.` : undefined,
|
|
397
|
+
].filter((value): value is string => Boolean(value));
|
|
398
|
+
return {
|
|
399
|
+
records,
|
|
400
|
+
truncated: tail.truncated || tail.lines.length > maxRecords,
|
|
401
|
+
...(warnings.length ? { warning: safeDisplayText(warnings.join(" ")) } : {}),
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
|
|
359
405
|
function statusGlyph(event: Extract<FleetTranscriptEvent, { kind: "tool" }>, theme: Theme): string {
|
|
360
406
|
if (event.status === "running") return theme.fg("warning", "●");
|
|
361
407
|
if (event.status === "error") return theme.fg("error", "✗");
|