@deathbeam/pi-delegate 0.0.49 → 0.0.50
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/index.ts +22 -6
- package/package.json +1 -1
- package/src/agents.ts +45 -13
- package/src/child.ts +2 -8
- package/src/format.ts +72 -3
- package/src/inspector.ts +21 -7
- package/src/store.ts +6 -3
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ Optional `delegate` settings live in `~/.pi/agent/settings.json` or `.pi/setting
|
|
|
18
18
|
```json
|
|
19
19
|
{
|
|
20
20
|
"delegate": {
|
|
21
|
-
"agentDirs": ["
|
|
21
|
+
"agentDirs": ["../shared/agents"],
|
|
22
22
|
"models": {
|
|
23
23
|
"cheap": "anthropic/claude-haiku-5-5:low",
|
|
24
24
|
"balanced": "anthropic/claude-sonnet-5-5:high",
|
|
@@ -28,7 +28,7 @@ Optional `delegate` settings live in `~/.pi/agent/settings.json` or `.pi/setting
|
|
|
28
28
|
}
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
- `agentDirs` adds directories
|
|
31
|
+
- `agentDirs` adds agent directories on top of the defaults: bundled, `~/.agents/agents`, `~/.pi/agent/agents`, `.agents/agents` from the working directory up to the git root, then `.pi/agents`. Later wins on a name clash. Project dirs and `.pi/settings.json` load only in a trusted project.
|
|
32
32
|
- `models` maps the `cheap`, `balanced`, and `strong` tiers to a `provider/model-id` with an optional `:<thinking>` suffix. A tier without an entry uses the session model.
|
|
33
33
|
|
|
34
34
|
Agents are Markdown files with frontmatter. The body is appended to the delegate's system prompt.
|
package/index.ts
CHANGED
|
@@ -43,7 +43,15 @@ import {
|
|
|
43
43
|
type IsolationState,
|
|
44
44
|
} from "./src/isolation.ts";
|
|
45
45
|
import { registerInspector } from "./src/inspector.ts";
|
|
46
|
-
import {
|
|
46
|
+
import {
|
|
47
|
+
agentByName,
|
|
48
|
+
agentsFor,
|
|
49
|
+
configFor,
|
|
50
|
+
contextWindowFor,
|
|
51
|
+
projectTrusted,
|
|
52
|
+
resolveModel,
|
|
53
|
+
type AgentFile,
|
|
54
|
+
} from "./src/agents.ts";
|
|
47
55
|
|
|
48
56
|
type SteerDetails = Pick<
|
|
49
57
|
DelegateJob,
|
|
@@ -274,7 +282,11 @@ export default function (pi: ExtensionAPI) {
|
|
|
274
282
|
const entrypoint = process.argv[1];
|
|
275
283
|
if (!entrypoint) throw new Error("Pi CLI entrypoint missing; start Pi from its CLI to delegate.");
|
|
276
284
|
const requested = fields.model ?? agent.model;
|
|
277
|
-
const { model, thinking } = resolveModel(
|
|
285
|
+
const { model, thinking } = resolveModel(
|
|
286
|
+
requested,
|
|
287
|
+
configFor(ctx.cwd, ctx.isProjectTrusted()).models ?? {},
|
|
288
|
+
ctx,
|
|
289
|
+
);
|
|
278
290
|
if (!model) throw new Error(`No model found for "${requested}".`);
|
|
279
291
|
const tools = (agent.tools?.length ? agent.tools : pi.getActiveTools()).filter(
|
|
280
292
|
(tool) => !DELEGATION_TOOLS.has(tool),
|
|
@@ -392,7 +404,11 @@ export default function (pi: ExtensionAPI) {
|
|
|
392
404
|
/** Swaps a running child's model over the RPC; the child confirms or rejects it, and never restarts. */
|
|
393
405
|
async function swapModel(job: DelegateJob, request: string, ctx: ExtensionContext) {
|
|
394
406
|
if (!job.swapModel) throw new Error(`Delegate job "${job.id}" cannot switch models.`);
|
|
395
|
-
const { model, explicit: level } = resolveModel(
|
|
407
|
+
const { model, explicit: level } = resolveModel(
|
|
408
|
+
request,
|
|
409
|
+
configFor(ctx.cwd, ctx.isProjectTrusted()).models ?? {},
|
|
410
|
+
ctx,
|
|
411
|
+
);
|
|
396
412
|
if (!model) throw new Error(`No model found for "${request}".`);
|
|
397
413
|
const [provider, ...rest] = model.split("/");
|
|
398
414
|
if (!rest.length) throw new Error(`Model "${model}" has no provider prefix.`);
|
|
@@ -479,7 +495,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
479
495
|
|
|
480
496
|
registerInspector(pi, store, DELEGATE_SESSION_DIR);
|
|
481
497
|
|
|
482
|
-
const agentList = agentsFor(process.cwd()).map((agent) => {
|
|
498
|
+
const agentList = agentsFor(process.cwd(), projectTrusted(process.cwd())).map((agent) => {
|
|
483
499
|
const qualifiers = [agent.model, agent.isolated ? "isolated" : undefined].filter(Boolean).join(", ");
|
|
484
500
|
return `- ${agent.name}${qualifiers ? ` (${qualifiers})` : ""}: ${agent.description}`;
|
|
485
501
|
});
|
|
@@ -542,7 +558,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
542
558
|
const cloneId = jobId(optional(rawParams.clone));
|
|
543
559
|
if (cloneId && isolated === false) throw new Error("clone always runs isolated; omit isolated: false.");
|
|
544
560
|
const clone = cloneId ? clonedJob(cloneId).isolation : undefined;
|
|
545
|
-
const agent = agentByName(ctx.cwd, agentName);
|
|
561
|
+
const agent = agentByName(ctx.cwd, agentName, ctx.isProjectTrusted());
|
|
546
562
|
const effective = clone ? true : (isolated ?? agent.isolated);
|
|
547
563
|
return runDelegate(ctx, agent, undefined, { description, model, isolated: effective, clone }, task, signal);
|
|
548
564
|
},
|
|
@@ -643,7 +659,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
643
659
|
throw new Error(
|
|
644
660
|
`The isolated clone of delegate job "${id}" was already applied or discarded; delegate_steer cannot continue it. Start a fresh delegate with a condensed brief instead.`,
|
|
645
661
|
);
|
|
646
|
-
const agent = agentByName(ctx.cwd, prior.agent);
|
|
662
|
+
const agent = agentByName(ctx.cwd, prior.agent, ctx.isProjectTrusted());
|
|
647
663
|
return runDelegate(
|
|
648
664
|
ctx,
|
|
649
665
|
agent,
|
package/package.json
CHANGED
package/src/agents.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
|
-
import { join, resolve } from "node:path";
|
|
3
|
+
import { dirname, join, resolve } from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
CONFIG_DIR_NAME,
|
|
8
|
+
getAgentDir,
|
|
9
|
+
hasTrustRequiringProjectResources,
|
|
10
|
+
parseFrontmatter,
|
|
11
|
+
ProjectTrustStore,
|
|
12
|
+
} from "@earendil-works/pi-coding-agent";
|
|
7
13
|
|
|
8
14
|
export type AgentFile = {
|
|
9
15
|
name: string;
|
|
@@ -19,7 +25,6 @@ type DelegateConfig = {
|
|
|
19
25
|
models?: Record<string, unknown>;
|
|
20
26
|
};
|
|
21
27
|
|
|
22
|
-
const DEFAULT_AGENT_DIR = "~/.agents/agents";
|
|
23
28
|
const BUNDLED_AGENT_DIR = fileURLToPath(new URL("../agents", import.meta.url));
|
|
24
29
|
const MODEL_TIERS = new Set(["cheap", "balanced", "strong"]);
|
|
25
30
|
|
|
@@ -71,10 +76,31 @@ function loadAgents(dir: string): AgentFile[] {
|
|
|
71
76
|
return agents;
|
|
72
77
|
}
|
|
73
78
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
);
|
|
79
|
+
/** pi's user skill dirs (`<agentDir>/skills` then `~/.agents/skills`) with `agents` for `skills`. */
|
|
80
|
+
function userAgentDirs(): string[] {
|
|
81
|
+
// Reversed: pi loads `<agentDir>` first, so it wins.
|
|
82
|
+
return [join(homedir(), ".agents", "agents"), join(getAgentDir(), "agents")];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** pi's project skill dirs: `<cwd>/.pi/skills` plus `.agents/skills` from cwd up to the git root. */
|
|
86
|
+
function projectAgentDirs(cwd: string): string[] {
|
|
87
|
+
const agentsDirs: string[] = [];
|
|
88
|
+
for (let dir = resolve(cwd); ; dir = dirname(dir)) {
|
|
89
|
+
agentsDirs.unshift(join(dir, ".agents", "agents"));
|
|
90
|
+
if (existsSync(join(dir, ".git")) || dirname(dir) === dir) break;
|
|
91
|
+
}
|
|
92
|
+
// Same reversal: pi loads .pi first.
|
|
93
|
+
return [...agentsDirs, join(cwd, CONFIG_DIR_NAME, "agents")];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Later dirs win; same order as pi's skill discovery.
|
|
97
|
+
function discoverAgents(cwd: string, configuredDirs: unknown, trusted: boolean): AgentFile[] {
|
|
98
|
+
const dirs = [
|
|
99
|
+
BUNDLED_AGENT_DIR,
|
|
100
|
+
...userAgentDirs(),
|
|
101
|
+
...(trusted ? projectAgentDirs(cwd) : []),
|
|
102
|
+
...stringList(configuredDirs),
|
|
103
|
+
].map((dir) => expandPath(dir, cwd));
|
|
78
104
|
const agents = new Map<string, AgentFile>();
|
|
79
105
|
for (const dir of [...new Set(dirs)]) {
|
|
80
106
|
for (const agent of loadAgents(dir)) agents.set(agent.name, agent);
|
|
@@ -82,12 +108,12 @@ function discoverAgents(cwd: string, configuredDirs: unknown): AgentFile[] {
|
|
|
82
108
|
return [...agents.values()];
|
|
83
109
|
}
|
|
84
110
|
|
|
85
|
-
export function agentsFor(cwd: string): AgentFile[] {
|
|
86
|
-
return discoverAgents(cwd, configFor(cwd).agentDirs);
|
|
111
|
+
export function agentsFor(cwd: string, trusted: boolean): AgentFile[] {
|
|
112
|
+
return discoverAgents(cwd, configFor(cwd, trusted).agentDirs, trusted);
|
|
87
113
|
}
|
|
88
114
|
|
|
89
|
-
export function agentByName(cwd: string, name: string): AgentFile {
|
|
90
|
-
const agents = agentsFor(cwd);
|
|
115
|
+
export function agentByName(cwd: string, name: string, trusted: boolean): AgentFile {
|
|
116
|
+
const agents = agentsFor(cwd, trusted);
|
|
91
117
|
const agent = agents.find((candidate) => candidate.name === name);
|
|
92
118
|
if (!agent) {
|
|
93
119
|
const names = agents.map((candidate) => candidate.name).join(", ") || "(none)";
|
|
@@ -96,9 +122,15 @@ export function agentByName(cwd: string, name: string): AgentFile {
|
|
|
96
122
|
return agent;
|
|
97
123
|
}
|
|
98
124
|
|
|
99
|
-
|
|
125
|
+
/** pi's rule without a ctx: a stored decision, else trusted unless project resources need gating. */
|
|
126
|
+
export function projectTrusted(cwd: string): boolean {
|
|
127
|
+
return new ProjectTrustStore(getAgentDir()).get(cwd) ?? !hasTrustRequiringProjectResources(cwd);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function configFor(cwd: string, trusted: boolean): DelegateConfig {
|
|
100
131
|
const global = readConfig(join(getAgentDir(), "settings.json"));
|
|
101
|
-
|
|
132
|
+
// pi ignores project settings in an untrusted project.
|
|
133
|
+
const project = trusted ? readConfig(join(cwd, CONFIG_DIR_NAME, "settings.json")) : {};
|
|
102
134
|
return {
|
|
103
135
|
agentDirs: [...stringList(global.agentDirs), ...stringList(project.agentDirs)],
|
|
104
136
|
models: { ...(global.models ?? {}), ...(project.models ?? {}) },
|
package/src/child.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { ChildProcessWithoutNullStreams } from "node:child_process";
|
|
|
2
2
|
import { readdirSync } from "node:fs";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { SessionManager, type MessageEndEvent } from "@earendil-works/pi-coding-agent";
|
|
5
|
-
import { limitOutput, textParts } from "./format.ts";
|
|
5
|
+
import { answerTokens, limitOutput, textParts, usageTokens } from "./format.ts";
|
|
6
6
|
|
|
7
7
|
type Child = ChildProcessWithoutNullStreams;
|
|
8
8
|
|
|
@@ -22,12 +22,6 @@ type ChildRun = {
|
|
|
22
22
|
swapModel: (provider: string, modelId: string, level?: string, onModelSet?: () => void) => Promise<void>;
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
function usageTokens(usage: any): number | undefined {
|
|
26
|
-
if (!usage) return undefined;
|
|
27
|
-
const tokens = usage.totalTokens || usage.input + usage.output + usage.cacheRead + usage.cacheWrite;
|
|
28
|
-
return tokens > 0 ? tokens : undefined;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
25
|
/** Run one RPC child, keeping its writer serialized so backpressure and EPIPE reach the caller. */
|
|
32
26
|
export function runChild(
|
|
33
27
|
child: Child,
|
|
@@ -139,7 +133,7 @@ export function runChild(
|
|
|
139
133
|
childError = message.errorMessage;
|
|
140
134
|
const text = textParts(message.content).join("");
|
|
141
135
|
if (text) liveText = text;
|
|
142
|
-
contextTokens =
|
|
136
|
+
contextTokens = answerTokens(message);
|
|
143
137
|
}
|
|
144
138
|
onUpdate?.({ contextTokens, message });
|
|
145
139
|
return;
|
package/src/format.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
calculateContextTokens,
|
|
3
|
+
getMarkdownTheme,
|
|
4
|
+
type KeybindingHints,
|
|
5
|
+
type Theme,
|
|
6
|
+
} from "@earendil-works/pi-coding-agent";
|
|
2
7
|
import {
|
|
3
8
|
type Component,
|
|
4
9
|
Container,
|
|
@@ -9,7 +14,7 @@ import {
|
|
|
9
14
|
truncateToWidth,
|
|
10
15
|
} from "@earendil-works/pi-tui";
|
|
11
16
|
import type { IsolationState } from "./isolation.ts";
|
|
12
|
-
import type { DelegateJob, JobStatus } from "./store.ts";
|
|
17
|
+
import type { DelegateJob, InspectJob, JobStatus } from "./store.ts";
|
|
13
18
|
|
|
14
19
|
type UsageInfo = {
|
|
15
20
|
contextTokens?: number;
|
|
@@ -41,6 +46,16 @@ export type DelegateDetails = Pick<DelegateJob, "id" | "agent" | "model" | "tool
|
|
|
41
46
|
background: boolean;
|
|
42
47
|
};
|
|
43
48
|
|
|
49
|
+
export type JobUsage = {
|
|
50
|
+
input: number;
|
|
51
|
+
output: number;
|
|
52
|
+
cacheRead: number;
|
|
53
|
+
cacheWrite: number;
|
|
54
|
+
cost: number;
|
|
55
|
+
cacheHit?: number;
|
|
56
|
+
contextTokens?: number;
|
|
57
|
+
};
|
|
58
|
+
|
|
44
59
|
const SPINNER_FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
45
60
|
export const SPINNER_INTERVAL_MS = 100;
|
|
46
61
|
const STATUS_ICONS = {
|
|
@@ -101,7 +116,7 @@ function formatTokens(count: number): string {
|
|
|
101
116
|
return `${Math.round(count / 1000000)}M`;
|
|
102
117
|
}
|
|
103
118
|
|
|
104
|
-
function formatDuration(ms: number): string {
|
|
119
|
+
export function formatDuration(ms: number): string {
|
|
105
120
|
const seconds = Math.max(0, Math.floor(ms / 1000));
|
|
106
121
|
if (seconds < 60) return `${seconds}s`;
|
|
107
122
|
const minutes = Math.floor(seconds / 60);
|
|
@@ -118,6 +133,60 @@ export function usageStats(usage: UsageInfo, elapsedMs: number): string {
|
|
|
118
133
|
return [tokens, formatDuration(elapsedMs)].filter(Boolean).join(" · ");
|
|
119
134
|
}
|
|
120
135
|
|
|
136
|
+
export function usageTokens(usage: any): number | undefined {
|
|
137
|
+
if (!usage) return undefined;
|
|
138
|
+
const tokens = calculateContextTokens(usage);
|
|
139
|
+
return tokens > 0 ? tokens : undefined;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Context tokens of an answer pi counts: aborted and failed ones carry no usable usage. */
|
|
143
|
+
export function answerTokens(message: { stopReason?: string; usage?: any }): number | undefined {
|
|
144
|
+
if (message.stopReason === "aborted" || message.stopReason === "error") return undefined;
|
|
145
|
+
return usageTokens(message.usage);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Same totals pi's footer builds. */
|
|
149
|
+
export function usageFromMessages(
|
|
150
|
+
messages: readonly { role?: string; usage?: any }[],
|
|
151
|
+
contextTokens?: number,
|
|
152
|
+
): JobUsage {
|
|
153
|
+
const totals: JobUsage = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0 };
|
|
154
|
+
for (const message of messages) {
|
|
155
|
+
const usage = message.usage;
|
|
156
|
+
if (!usage) continue;
|
|
157
|
+
totals.input += usage.input ?? 0;
|
|
158
|
+
totals.output += usage.output ?? 0;
|
|
159
|
+
totals.cacheRead += usage.cacheRead ?? 0;
|
|
160
|
+
totals.cacheWrite += usage.cacheWrite ?? 0;
|
|
161
|
+
totals.cost += usage.cost?.total ?? 0;
|
|
162
|
+
if (message.role !== "assistant") continue;
|
|
163
|
+
const prompt = usage.input + usage.cacheRead + usage.cacheWrite;
|
|
164
|
+
totals.cacheHit = prompt > 0 ? (usage.cacheRead / prompt) * 100 : undefined;
|
|
165
|
+
const total = answerTokens(message);
|
|
166
|
+
if (total) totals.contextTokens = total;
|
|
167
|
+
}
|
|
168
|
+
return { ...totals, contextTokens: totals.contextTokens ?? contextTokens };
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** pi's footer stats line. */
|
|
172
|
+
export function usageLine(theme: Theme, usage: JobUsage, contextWindow?: number): string {
|
|
173
|
+
const parts: string[] = [];
|
|
174
|
+
if (usage.input) parts.push(`↑${formatTokens(usage.input)}`);
|
|
175
|
+
if (usage.output) parts.push(`↓${formatTokens(usage.output)}`);
|
|
176
|
+
if (usage.cacheRead) parts.push(`R${formatTokens(usage.cacheRead)}`);
|
|
177
|
+
if (usage.cacheWrite) parts.push(`W${formatTokens(usage.cacheWrite)}`);
|
|
178
|
+
if ((usage.cacheRead > 0 || usage.cacheWrite > 0) && usage.cacheHit !== undefined)
|
|
179
|
+
parts.push(`CH${usage.cacheHit.toFixed(1)}%`);
|
|
180
|
+
if (usage.cost) parts.push(`$${usage.cost.toFixed(3)}`);
|
|
181
|
+
const window = contextWindow ?? 0;
|
|
182
|
+
const percent = window && usage.contextTokens !== undefined ? (usage.contextTokens / window) * 100 : undefined;
|
|
183
|
+
const context =
|
|
184
|
+
percent === undefined ? `?/${formatTokens(window)}` : `${percent.toFixed(1)}%/${formatTokens(window)}`;
|
|
185
|
+
const color = percent === undefined ? undefined : percent > 90 ? "error" : percent > 70 ? "warning" : undefined;
|
|
186
|
+
parts.push(color ? theme.fg(color, context) : context);
|
|
187
|
+
return parts.join(" ");
|
|
188
|
+
}
|
|
189
|
+
|
|
121
190
|
export function elapsedMs(job: { startedAt: number; endedAt?: number }, now = Date.now()): number {
|
|
122
191
|
return (job.endedAt ?? now) - job.startedAt;
|
|
123
192
|
}
|
package/src/inspector.ts
CHANGED
|
@@ -13,11 +13,13 @@ import {
|
|
|
13
13
|
Spacer,
|
|
14
14
|
Text,
|
|
15
15
|
truncateToWidth,
|
|
16
|
+
visibleWidth,
|
|
16
17
|
wrapTextWithAnsi,
|
|
17
18
|
} from "@earendil-works/pi-tui";
|
|
18
19
|
import { type ChildMessage, sessionMessages } from "./child.ts";
|
|
19
20
|
import {
|
|
20
21
|
elapsedMs,
|
|
22
|
+
formatDuration,
|
|
21
23
|
formatTools,
|
|
22
24
|
jobIdentity,
|
|
23
25
|
resultPreview,
|
|
@@ -27,6 +29,8 @@ import {
|
|
|
27
29
|
textParts,
|
|
28
30
|
toolCallDetail,
|
|
29
31
|
toolLines,
|
|
32
|
+
usageFromMessages,
|
|
33
|
+
usageLine,
|
|
30
34
|
usageStats,
|
|
31
35
|
} from "./format.ts";
|
|
32
36
|
import type { InspectJob, JobStore } from "./store.ts";
|
|
@@ -257,10 +261,20 @@ export function registerInspector(pi: ExtensionAPI, store: JobStore, sessionDir:
|
|
|
257
261
|
}
|
|
258
262
|
function renderHistory(width: number, job: InspectJob): string[] {
|
|
259
263
|
const tools = toolsLines(job, width);
|
|
260
|
-
// Fixed rows: header, model, description, rule,
|
|
264
|
+
// Fixed rows: header, model, description, rule, footer, plus the failure detail.
|
|
261
265
|
const height = Math.max(0, bodyHeight() - 5 - tools.length - (job.detail ? 1 : 0));
|
|
262
266
|
const view = transcript(job);
|
|
263
|
-
|
|
267
|
+
const messages = messagesOf(job);
|
|
268
|
+
view.sync(messages);
|
|
269
|
+
// A finished job keeps the totals captured at finish; a restored one recounts its transcript.
|
|
270
|
+
const usage = theme.fg(
|
|
271
|
+
"dim",
|
|
272
|
+
usageLine(
|
|
273
|
+
theme,
|
|
274
|
+
job.usage ?? usageFromMessages(messages, job.contextTokens),
|
|
275
|
+
job.contextWindow,
|
|
276
|
+
),
|
|
277
|
+
);
|
|
264
278
|
const window = view.window(width, top, height);
|
|
265
279
|
lastWindow = { height, total: window.total };
|
|
266
280
|
const shown = window.lines.length
|
|
@@ -275,13 +289,13 @@ export function registerInspector(pi: ExtensionAPI, store: JobStore, sessionDir:
|
|
|
275
289
|
),
|
|
276
290
|
]
|
|
277
291
|
: [];
|
|
278
|
-
const
|
|
279
|
-
? `${window.start + 1}–${window.start + window.lines.length}`
|
|
280
|
-
:
|
|
292
|
+
const counterText = window.lines.length
|
|
293
|
+
? `${window.start + 1}–${window.start + window.lines.length}/${window.total}`
|
|
294
|
+
: `0/${window.total}`;
|
|
281
295
|
return (
|
|
282
296
|
[
|
|
283
297
|
truncateToWidth(
|
|
284
|
-
`${statusText(theme, job.status)} ${jobIdentity(theme, job)} ${theme.fg("muted",
|
|
298
|
+
`${statusText(theme, job.status)} ${jobIdentity(theme, job)} ${theme.fg("muted", formatDuration(elapsedMs(job)))}`,
|
|
285
299
|
width,
|
|
286
300
|
),
|
|
287
301
|
truncateToWidth(theme.fg("dim", job.model), width),
|
|
@@ -293,7 +307,7 @@ export function registerInspector(pi: ExtensionAPI, store: JobStore, sessionDir:
|
|
|
293
307
|
...(job.detail
|
|
294
308
|
? [truncateToWidth(theme.fg(STATUS_COLORS.failed, job.detail), width)]
|
|
295
309
|
: []),
|
|
296
|
-
truncateToWidth(theme.fg("dim",
|
|
310
|
+
`${truncateToWidth(usage, Math.max(0, width - visibleWidth(counterText) - 2), "…")} ${theme.fg("dim", counterText)}`,
|
|
297
311
|
]
|
|
298
312
|
.slice(0, bodyHeight())
|
|
299
313
|
// Pad every row so the pane's right edge holds still while the transcript scrolls.
|
package/src/store.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ChildMessage, ChildUpdate } from "./child.ts";
|
|
2
|
-
import { resultPreview, toolCallDetail } from "./format.ts";
|
|
2
|
+
import { type JobUsage, resultPreview, toolCallDetail, usageFromMessages } from "./format.ts";
|
|
3
3
|
import type { IsolationState } from "./isolation.ts";
|
|
4
4
|
|
|
5
5
|
export type JobStatus = "running" | "done" | "failed" | "cancelled" | "interrupted";
|
|
@@ -21,6 +21,8 @@ export type InspectJob = {
|
|
|
21
21
|
/** The failure detail shown under a finished job's transcript. */
|
|
22
22
|
detail?: string;
|
|
23
23
|
isolation?: IsolationState;
|
|
24
|
+
/** Usage totals captured at finish: a restored transcript can drop pre-compaction messages. */
|
|
25
|
+
usage?: JobUsage;
|
|
24
26
|
/** Set once an isolated job's clone was applied or discarded, so a steer revive refuses instead of rerunning in the main tree. */
|
|
25
27
|
cloneClosed?: boolean;
|
|
26
28
|
};
|
|
@@ -31,6 +33,8 @@ export type DelegateJob = InspectJob & {
|
|
|
31
33
|
swapModel?: (provider: string, modelId: string, level?: string, onModelSet?: () => void) => Promise<void>;
|
|
32
34
|
};
|
|
33
35
|
|
|
36
|
+
export type JobStore = ReturnType<typeof createJobStore>;
|
|
37
|
+
|
|
34
38
|
const JOB_ENTRY = "delegate-job";
|
|
35
39
|
|
|
36
40
|
/** The latest delegate-job entry per id, newest first: the append-only log's current view. */
|
|
@@ -125,6 +129,7 @@ export function createJobStore(append: (customType: string, data: InspectJob) =>
|
|
|
125
129
|
running.delete(job.id);
|
|
126
130
|
job.status = status;
|
|
127
131
|
if (detail) job.detail = detail;
|
|
132
|
+
job.usage = usageFromMessages(job.messages, job.contextTokens);
|
|
128
133
|
commit({ ...plain(job), messages: [], endedAt: Date.now() });
|
|
129
134
|
return true;
|
|
130
135
|
},
|
|
@@ -165,8 +170,6 @@ export function createJobStore(append: (customType: string, data: InspectJob) =>
|
|
|
165
170
|
};
|
|
166
171
|
}
|
|
167
172
|
|
|
168
|
-
export type JobStore = ReturnType<typeof createJobStore>;
|
|
169
|
-
|
|
170
173
|
/** The job's latest tool call and its result, once the result arrives. */
|
|
171
174
|
export function lastToolCall(job: InspectJob): {
|
|
172
175
|
tool?: { name: string; detail: string };
|