oira666_pi-subagent 0.5.0 → 0.5.1
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 +1 -1
- package/config.ts +72 -0
- package/docs/configuration.md +1 -1
- package/package.json +1 -1
- package/ui/detail-lines.ts +1 -1
- package/ui/detail-model.ts +4 -0
- package/ui/detail-transcript.ts +44 -6
- package/ui/session.ts +7 -3
package/README.md
CHANGED
|
@@ -75,7 +75,7 @@ See [configuration](docs/configuration.md) for frontmatter, layer restrictions,
|
|
|
75
75
|
|
|
76
76
|
Collapsed results show each child's name, task, status, and most recent activity anywhere in its subtree. `Ctrl+O` expands the newest call from memory without reading historical transcripts.
|
|
77
77
|
|
|
78
|
-
`/subagent-expand <name>` opens a saved worker transcript. With no name, it opens a searchable picker. Name completion is fuzzy.
|
|
78
|
+
`/subagent-expand <name>` opens a saved worker transcript. With no name, it opens a searchable picker. Name completion is fuzzy. Each task or resume shows its actual provider/model and thinking level from the worker's session, not the parent's settings. Missing historical metadata appears as `unknown`.
|
|
79
79
|
|
|
80
80
|
| Key | Action |
|
|
81
81
|
| --- | --- |
|
package/config.ts
CHANGED
|
@@ -30,6 +30,77 @@ function readConfig(filePath: string): Record<string, unknown> {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
34
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let tempFileCounter = 0;
|
|
38
|
+
|
|
39
|
+
/** Add the explicit default without allowing a failed write to change runtime behavior. */
|
|
40
|
+
function persistSmartDecisionFallback(config: Record<string, unknown>, filePath: string): void {
|
|
41
|
+
const smartDecision = config["smart-decision"];
|
|
42
|
+
if (!isRecord(smartDecision) || Object.hasOwn(smartDecision, "fallback")) return;
|
|
43
|
+
|
|
44
|
+
smartDecision.fallback = true;
|
|
45
|
+
let tempPath: string | undefined;
|
|
46
|
+
let ownsTemp = false;
|
|
47
|
+
try {
|
|
48
|
+
// Replace the target rather than a symlink that points to it.
|
|
49
|
+
const targetPath = fs.realpathSync(filePath);
|
|
50
|
+
// Re-read immediately before writing so unrelated edits made since the initial load survive.
|
|
51
|
+
// Retrying also makes concurrent nested-worker migrations converge without clobbering one another.
|
|
52
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
53
|
+
const source = fs.readFileSync(targetPath, "utf8");
|
|
54
|
+
const latest = JSON.parse(source) as unknown;
|
|
55
|
+
if (!isRecord(latest)) return;
|
|
56
|
+
const latestSmartDecision = latest["smart-decision"];
|
|
57
|
+
if (!isRecord(latestSmartDecision)) return;
|
|
58
|
+
if (Object.hasOwn(latestSmartDecision, "fallback")) {
|
|
59
|
+
smartDecision.fallback = latestSmartDecision.fallback;
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
latestSmartDecision.fallback = true;
|
|
64
|
+
const mode = fs.statSync(targetPath).mode & 0o7777;
|
|
65
|
+
const candidatePath = path.join(
|
|
66
|
+
path.dirname(targetPath),
|
|
67
|
+
`.${path.basename(targetPath)}.${process.pid}.${tempFileCounter++}.tmp`,
|
|
68
|
+
);
|
|
69
|
+
const fd = fs.openSync(candidatePath, "wx", mode);
|
|
70
|
+
tempPath = candidatePath;
|
|
71
|
+
ownsTemp = true;
|
|
72
|
+
try {
|
|
73
|
+
fs.writeFileSync(fd, `${JSON.stringify(latest, null, 2)}\n`, "utf8");
|
|
74
|
+
fs.fchmodSync(fd, mode);
|
|
75
|
+
fs.fsyncSync(fd);
|
|
76
|
+
} finally {
|
|
77
|
+
fs.closeSync(fd);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (fs.readFileSync(targetPath, "utf8") !== source) {
|
|
81
|
+
fs.unlinkSync(tempPath);
|
|
82
|
+
tempPath = undefined;
|
|
83
|
+
ownsTemp = false;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
fs.renameSync(tempPath, targetPath);
|
|
87
|
+
tempPath = undefined;
|
|
88
|
+
ownsTemp = false;
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
throw new Error("config changed during fallback migration");
|
|
92
|
+
} catch {
|
|
93
|
+
if (ownsTemp && tempPath) {
|
|
94
|
+
try {
|
|
95
|
+
fs.unlinkSync(tempPath);
|
|
96
|
+
} catch {
|
|
97
|
+
// Best-effort cleanup. Do not expose filesystem errors or configuration contents.
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
console.warn("[pi-subagent] Failed to save the default smart-decision fallback.");
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
33
104
|
function readToolPrompts(config: Record<string, unknown>, filePath: string): Record<string, string> {
|
|
34
105
|
const toolPrompts = config["tool-prompts"];
|
|
35
106
|
if (toolPrompts === undefined) return {};
|
|
@@ -85,6 +156,7 @@ export function loadPiSubagentsConfig(cwd?: string, includeProject = false): PiS
|
|
|
85
156
|
let smartDecision: SmartDecisionConfig | undefined;
|
|
86
157
|
for (const filePath of new Set(paths)) {
|
|
87
158
|
const config = readConfig(filePath);
|
|
159
|
+
persistSmartDecisionFallback(config, filePath);
|
|
88
160
|
Object.assign(toolPrompts, readToolPrompts(config, filePath));
|
|
89
161
|
if (Object.hasOwn(config, "smart-decision")) {
|
|
90
162
|
smartDecision = parseSmartDecisionConfig(config["smart-decision"]);
|
package/docs/configuration.md
CHANGED
|
@@ -80,7 +80,7 @@ Replace the example choices with models available in your Pi installation. Each
|
|
|
80
80
|
- `enabled` must be `true`. Missing settings, disabled settings, or an empty model list leave existing behavior unchanged and make no Jev requests.
|
|
81
81
|
- `model` selects the decision model, not the worker model. `jev` maps to TypeSafe's `jev-latest`; explicit TypeSafe model IDs also work.
|
|
82
82
|
- `api_key` is your TypeSafe API key. Worker providers still need their own Pi credentials.
|
|
83
|
-
- `fallback` defaults to `true`. If selection fails, a short warning is written and the worker uses the original launch settings. Set it to `false` to return a tool error without launching the affected worker. This covers network errors, the 10-second request timeout, API errors, invalid answers, and invalid enabled configuration. Cancellation cancels the task instead of falling back.
|
|
83
|
+
- `fallback` defaults to `true`. When a loaded `smart-decision` object omits it, the extension adds `"fallback": true` and saves that configuration file at runtime. Existing values, including `false`, are left untouched. Untrusted project files are never changed. If saving fails, a warning is emitted and the runtime default still applies. If selection fails, a short warning is written and the worker uses the original launch settings. Set it to `false` to return a tool error without launching the affected worker. This covers network errors, the 10-second request timeout, API errors, invalid answers, and invalid enabled configuration. Cancellation cancels the task instead of falling back.
|
|
84
84
|
|
|
85
85
|
Each fresh launch and actual resume sends the agent definition's system prompt, the assigned task, and the candidate descriptions to `https://api.typesafe.ai/v1/systemone`. Jev must select a configured candidate. Its provider, model, and thinking level override the parent model and agent frontmatter for that run. The parent's explicit `--provider` and `--api-key` are not forwarded when a Jev choice is applied. Startup retries reuse the choice. Finished results reused without launching a process make no request.
|
|
86
86
|
|
package/package.json
CHANGED
package/ui/detail-lines.ts
CHANGED
|
@@ -93,11 +93,11 @@ export function renderTurnOverviewLines(
|
|
|
93
93
|
const meta = [
|
|
94
94
|
`Turn ${blockIndex + 1} of ${detail.blocks.length}: ${turnTitle}`,
|
|
95
95
|
block.at ? formatClockTime(block.at) : "",
|
|
96
|
-
detail.model ?? "",
|
|
97
96
|
]
|
|
98
97
|
.filter(Boolean)
|
|
99
98
|
.join(" • ");
|
|
100
99
|
out.wrap(meta, "", "dim");
|
|
100
|
+
out.wrap(`Model: ${block.model ?? "unknown"} • Thinking: ${block.thinkingLevel ?? "unknown"}`, "", "dim");
|
|
101
101
|
out.wrap(`session total: ${usageLine(detail.usage)}`, "", "dim");
|
|
102
102
|
for (const note of detail.notes) out.wrap(note, "", "warning");
|
|
103
103
|
|
package/ui/detail-model.ts
CHANGED
|
@@ -16,6 +16,9 @@ export interface DetailBlock {
|
|
|
16
16
|
index: number;
|
|
17
17
|
prompt: string;
|
|
18
18
|
at?: number;
|
|
19
|
+
/** Actual settings recorded for this task or resume, not the parent's model. */
|
|
20
|
+
model?: string;
|
|
21
|
+
thinkingLevel?: string;
|
|
19
22
|
events: DetailEvent[];
|
|
20
23
|
}
|
|
21
24
|
|
|
@@ -32,6 +35,7 @@ export interface SubagentDetail {
|
|
|
32
35
|
name: string;
|
|
33
36
|
agent: string;
|
|
34
37
|
model?: string;
|
|
38
|
+
thinkingLevel?: string;
|
|
35
39
|
tools?: string[];
|
|
36
40
|
createdAt?: number;
|
|
37
41
|
sessionDir: string;
|
package/ui/detail-transcript.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { sessionFilesIn,
|
|
1
|
+
import { sessionFilesIn, readSessionEntries } from "./session.js";
|
|
2
2
|
export { sessionFilesIn, readSessionMessages } from "./session.js";
|
|
3
3
|
import * as os from "node:os";
|
|
4
4
|
import type { NamesRegistry, SubagentNameRecord } from "../names.js";
|
|
@@ -92,23 +92,41 @@ export interface ParsedTranscript {
|
|
|
92
92
|
blocks: DetailBlock[];
|
|
93
93
|
usage: DetailUsage;
|
|
94
94
|
toolCallCount: number;
|
|
95
|
+
model?: string;
|
|
96
|
+
thinkingLevel?: string;
|
|
95
97
|
}
|
|
96
98
|
|
|
97
99
|
export function parseTranscriptMessages(messages: unknown[]): ParsedTranscript {
|
|
98
100
|
const blocks: DetailBlock[] = [];
|
|
99
101
|
const usage: DetailUsage = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0, turns: 0 };
|
|
100
102
|
let toolCallCount = 0;
|
|
103
|
+
let model: string | undefined;
|
|
104
|
+
let thinkingLevel: string | undefined;
|
|
101
105
|
const pendingTools = new Map<string, Extract<DetailEvent, { type: "tool" }>>();
|
|
106
|
+
const observedModels = new Set<DetailBlock>();
|
|
102
107
|
|
|
103
108
|
const currentBlock = (): DetailBlock => {
|
|
104
109
|
if (blocks.length === 0) {
|
|
105
|
-
blocks.push({ kind: "task", index: 0, prompt: "", events: [] });
|
|
110
|
+
blocks.push({ kind: "task", index: 0, prompt: "", model, thinkingLevel, events: [] });
|
|
106
111
|
}
|
|
107
112
|
return blocks[blocks.length - 1];
|
|
108
113
|
};
|
|
109
114
|
|
|
110
115
|
for (const entry of messages) {
|
|
111
116
|
const wrapper = asRecord(entry);
|
|
117
|
+
if (wrapper.type === "model_change") {
|
|
118
|
+
if (typeof wrapper.modelId === "string" && wrapper.modelId && wrapper.modelId !== "synthetic-tool-call") {
|
|
119
|
+
model =
|
|
120
|
+
typeof wrapper.provider === "string" && wrapper.provider
|
|
121
|
+
? `${wrapper.provider}/${wrapper.modelId}`
|
|
122
|
+
: wrapper.modelId;
|
|
123
|
+
}
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
if (wrapper.type === "thinking_level_change") {
|
|
127
|
+
if (typeof wrapper.thinkingLevel === "string" && wrapper.thinkingLevel) thinkingLevel = wrapper.thinkingLevel;
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
112
130
|
const message = asRecord(wrapper.message);
|
|
113
131
|
const at = parseTimestamp(wrapper.timestamp ?? message.timestamp);
|
|
114
132
|
const role = message.role;
|
|
@@ -121,6 +139,8 @@ export function parseTranscriptMessages(messages: unknown[]): ParsedTranscript {
|
|
|
121
139
|
index,
|
|
122
140
|
prompt,
|
|
123
141
|
at,
|
|
142
|
+
model,
|
|
143
|
+
thinkingLevel,
|
|
124
144
|
events: [],
|
|
125
145
|
});
|
|
126
146
|
continue;
|
|
@@ -138,6 +158,19 @@ export function parseTranscriptMessages(messages: unknown[]): ParsedTranscript {
|
|
|
138
158
|
usage.cost += typeof cost === "number" ? cost : Number(asRecord(cost).total) || 0;
|
|
139
159
|
|
|
140
160
|
const block = currentBlock();
|
|
161
|
+
// Legacy transcripts may have messages but no model-change entries.
|
|
162
|
+
if (typeof message.model === "string" && message.model && message.model !== "synthetic-tool-call") {
|
|
163
|
+
const actualModel =
|
|
164
|
+
typeof message.provider === "string" && message.provider
|
|
165
|
+
? `${message.provider}/${message.model}`
|
|
166
|
+
: message.model;
|
|
167
|
+
if (!observedModels.has(block)) {
|
|
168
|
+
block.model = actualModel;
|
|
169
|
+
block.thinkingLevel = thinkingLevel;
|
|
170
|
+
observedModels.add(block);
|
|
171
|
+
}
|
|
172
|
+
model = actualModel;
|
|
173
|
+
}
|
|
141
174
|
for (const rawPart of Array.isArray(message.content) ? message.content : []) {
|
|
142
175
|
const part = asRecord(rawPart);
|
|
143
176
|
if (part.type === "thinking" && typeof part.thinking === "string") {
|
|
@@ -188,7 +221,7 @@ export function parseTranscriptMessages(messages: unknown[]): ParsedTranscript {
|
|
|
188
221
|
}
|
|
189
222
|
}
|
|
190
223
|
|
|
191
|
-
return { blocks, usage, toolCallCount };
|
|
224
|
+
return { blocks, usage, toolCallCount, model, thinkingLevel };
|
|
192
225
|
}
|
|
193
226
|
|
|
194
227
|
export function buildSubagentDetail(record: SubagentNameRecord, options: { sessionDir?: string } = {}): SubagentDetail {
|
|
@@ -200,11 +233,15 @@ export function buildSubagentDetail(record: SubagentNameRecord, options: { sessi
|
|
|
200
233
|
let blocks: DetailBlock[] = [];
|
|
201
234
|
let usage: DetailUsage = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0, turns: 0 };
|
|
202
235
|
let toolCallCount = 0;
|
|
236
|
+
let model: string | undefined;
|
|
237
|
+
let thinkingLevel: string | undefined;
|
|
203
238
|
|
|
204
239
|
if (!sessionFile) {
|
|
205
240
|
notes.push(`No session transcript found in ${shortenPath(sessionDir)}`);
|
|
206
241
|
} else {
|
|
207
|
-
const parsed = parseTranscriptMessages(
|
|
242
|
+
const parsed = parseTranscriptMessages(readSessionEntries(sessionFile));
|
|
243
|
+
model = parsed.model;
|
|
244
|
+
thinkingLevel = parsed.thinkingLevel;
|
|
208
245
|
blocks = parsed.blocks;
|
|
209
246
|
usage = parsed.usage;
|
|
210
247
|
toolCallCount = parsed.toolCallCount;
|
|
@@ -214,7 +251,7 @@ export function buildSubagentDetail(record: SubagentNameRecord, options: { sessi
|
|
|
214
251
|
}
|
|
215
252
|
|
|
216
253
|
if (blocks.length === 0 && record.task) {
|
|
217
|
-
blocks = [{ kind: "task", index: 0, prompt: record.task, at: record.createdAt, events: [] }];
|
|
254
|
+
blocks = [{ kind: "task", index: 0, prompt: record.task, at: record.createdAt, model, thinkingLevel, events: [] }];
|
|
218
255
|
}
|
|
219
256
|
if (blocks.length > 0 && !blocks[0].prompt && record.task) {
|
|
220
257
|
blocks[0].prompt = record.task;
|
|
@@ -223,7 +260,8 @@ export function buildSubagentDetail(record: SubagentNameRecord, options: { sessi
|
|
|
223
260
|
return {
|
|
224
261
|
name: record.name,
|
|
225
262
|
agent: record.agent,
|
|
226
|
-
model
|
|
263
|
+
model,
|
|
264
|
+
thinkingLevel,
|
|
227
265
|
tools: record.tools,
|
|
228
266
|
createdAt: record.createdAt,
|
|
229
267
|
sessionDir,
|
package/ui/session.ts
CHANGED
|
@@ -18,8 +18,8 @@ export function sessionFilesIn(sessionDir: string): string[] {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export function
|
|
22
|
-
const messages: unknown[] = [];
|
|
21
|
+
export function readSessionEntries(file: string): Record<string, unknown>[] {
|
|
22
|
+
const messages: Record<string, unknown>[] = [];
|
|
23
23
|
let raw: string;
|
|
24
24
|
try {
|
|
25
25
|
raw = fs.readFileSync(file, "utf8");
|
|
@@ -34,7 +34,11 @@ export function readSessionMessages(file: string): unknown[] {
|
|
|
34
34
|
} catch {
|
|
35
35
|
continue;
|
|
36
36
|
}
|
|
37
|
-
|
|
37
|
+
messages.push(entry);
|
|
38
38
|
}
|
|
39
39
|
return messages;
|
|
40
40
|
}
|
|
41
|
+
|
|
42
|
+
export function readSessionMessages(file: string): unknown[] {
|
|
43
|
+
return readSessionEntries(file).filter((entry) => entry.type === "message" && entry.message);
|
|
44
|
+
}
|