zcode-app-cli 4.0.0-50 → 4.0.0-51
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 +4 -1
- package/bin/zcode.js +2 -0
- package/docs/CONFIGURATION.md +10 -0
- package/docs/CONFIGURATION.zh-CN.md +12 -0
- package/package.json +1 -1
- package/setting.example.json +1 -0
- package/vendor/cli-config.cjs +218 -121
- package/vendor/extraction.json +1 -1
- package/vendor/node_modules/@zcode/tui/dist/index.js +667 -49
- package/vendor/zcode.cjs +8 -8
package/README.md
CHANGED
|
@@ -145,6 +145,8 @@ workflow panels; status-bar-only Shift+Tab mode cycling
|
|
|
145
145
|
cycling (Tab also cycles effort on an empty prompt); structured session-goal status in the right side of the turn footer;
|
|
146
146
|
animated active-turn timer with a static `ZCODE_TUI_REDUCED_MOTION=1`
|
|
147
147
|
fallback; responsive context-remaining and session-token metrics.
|
|
148
|
+
optional plan-quota statusline segment (`ui.quotaStatusline`) and a
|
|
149
|
+
`/quota` balance card for signed-in Coding Plan / Start Plan accounts.
|
|
148
150
|
|
|
149
151
|
**Session discovery.** Bare `/resume` opens a directory-scoped picker;
|
|
150
152
|
`/sessions` browses desktop and CLI sessions across directories, including forks
|
|
@@ -586,7 +588,8 @@ overrides leave Desktop's credentials and provider configuration untouched.
|
|
|
586
588
|
Client headers and a local usage row do not independently prove server-side
|
|
587
589
|
bonus accounting.
|
|
588
590
|
|
|
589
|
-
`/settings`
|
|
591
|
+
`/settings` and `/model default` save the default model; `/model` changes only
|
|
592
|
+
the current session.
|
|
590
593
|
See [`provider.example.json`](./provider.example.json) for complete field examples
|
|
591
594
|
and the [provider configuration reference](./docs/PROVIDER_CONFIG.md) for multimodal
|
|
592
595
|
capabilities, native search, token limits, reasoning maps and automatic upstream
|
package/bin/zcode.js
CHANGED
|
@@ -62,6 +62,7 @@ var setting_example_default = {
|
|
|
62
62
|
"theme": "auto",
|
|
63
63
|
"tuiMode": "regular",
|
|
64
64
|
"toolCallStyle": "regular",
|
|
65
|
+
"quotaStatusline": false,
|
|
65
66
|
"copyOnSelect": true,
|
|
66
67
|
"notifications": {
|
|
67
68
|
"method": "auto",
|
|
@@ -355,6 +356,7 @@ async function markSetupPending(env = process.env) {
|
|
|
355
356
|
async function clearSetupPending(env = process.env) {
|
|
356
357
|
await rm(setupPendingPath(env), { force: true }).catch(() => {});
|
|
357
358
|
}
|
|
359
|
+
new AsyncLocalStorage();
|
|
358
360
|
promisify(execFile);
|
|
359
361
|
promisify(execFile);
|
|
360
362
|
new AsyncLocalStorage();
|
package/docs/CONFIGURATION.md
CHANGED
|
@@ -637,6 +637,16 @@ user config: `~/.zcode/cli/setting.json` on macOS/Linux or
|
|
|
637
637
|
takes priority over terminal probing. `auto` queries the terminal background
|
|
638
638
|
color and color scheme at startup and re-applies the matching palette.
|
|
639
639
|
|
|
640
|
+
## Plan quota statusline
|
|
641
|
+
|
|
642
|
+
Set `ui.quotaStatusline` to `true` in the user config to add a `quota <percent>%`
|
|
643
|
+
segment to the compact statusline. It shows the lowest remaining balance across
|
|
644
|
+
the signed-in account's plan slots, warning-tinted below 20% and error-tinted
|
|
645
|
+
when exhausted, refreshed in the background every five minutes. It renders only
|
|
646
|
+
for OAuth sessions (Start Plan / Coding Plan); manual API-key providers have no
|
|
647
|
+
zcode-plan balance to read. `/quota` opens the full balance card on demand and
|
|
648
|
+
refreshes immediately.
|
|
649
|
+
|
|
640
650
|
## Turn completion notifications
|
|
641
651
|
|
|
642
652
|
Notifications are enabled by default and emitted after a normal agent turn
|
|
@@ -513,6 +513,18 @@ ZCODE_TUI_RUNTIME_LOG=/tmp/zcode-tui-runtime.log zcode
|
|
|
513
513
|
}
|
|
514
514
|
}
|
|
515
515
|
```
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
## 计划额度状态栏
|
|
519
|
+
|
|
520
|
+
在用户配置中将 `ui.quotaStatusline` 设为 `true`,紧凑状态栏会追加
|
|
521
|
+
`quota <percent>%` 段:显示登录账号所有计划槽位中剩余最少的一项,
|
|
522
|
+
低于 20% 时以警告色显示,耗尽时以错误色显示,后台每五分钟刷新一次。
|
|
523
|
+
该功能仅适用于 OAuth 会话(Start Plan / Coding Plan);手动 API-key
|
|
524
|
+
提供商没有可读取的 zcode-plan 余额。`/quota` 可随时打开完整余额卡片
|
|
525
|
+
并立即刷新。
|
|
526
|
+
|
|
527
|
+
|
|
516
528
|
|
|
517
529
|
正常退出或处理 `SIGINT`、`SIGTERM`、`SIGHUP` 时会恢复终端状态。
|
|
518
530
|
任何终端程序都无法拦截强制的 `SIGKILL`。
|
package/package.json
CHANGED
package/setting.example.json
CHANGED
package/vendor/cli-config.cjs
CHANGED
|
@@ -147,6 +147,185 @@ async function listSessionsForPicker(app) {
|
|
|
147
147
|
}));
|
|
148
148
|
}
|
|
149
149
|
//#endregion
|
|
150
|
+
//#region src/subagent-execution.ts
|
|
151
|
+
const active = new node_async_hooks.AsyncLocalStorage();
|
|
152
|
+
function lockPath(output, child) {
|
|
153
|
+
const key = (0, node_crypto.createHash)("sha256").update(child).digest("hex");
|
|
154
|
+
return (0, node_path.join)((0, node_path.dirname)(output), `execution-${key}.sqlite`);
|
|
155
|
+
}
|
|
156
|
+
function busy(error) {
|
|
157
|
+
const code = error?.errcode;
|
|
158
|
+
return code === 5 || code === 6;
|
|
159
|
+
}
|
|
160
|
+
function openDatabase(path, readOnly = false) {
|
|
161
|
+
return new (require("node:sqlite")).DatabaseSync(path, { readOnly });
|
|
162
|
+
}
|
|
163
|
+
function readSubagentRun(output, child, agent) {
|
|
164
|
+
if (!output) return;
|
|
165
|
+
try {
|
|
166
|
+
const run = JSON.parse((0, node_fs.readFileSync)((0, node_path.join)((0, node_path.dirname)(output), "metadata.json"), "utf8"));
|
|
167
|
+
if (run?.childSessionId === child && (!agent || run.agentId === agent)) return run;
|
|
168
|
+
} catch {}
|
|
169
|
+
}
|
|
170
|
+
function previousExecution(db) {
|
|
171
|
+
if (!db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='execution'").get()) return;
|
|
172
|
+
return db.prepare("SELECT id FROM execution WHERE singleton=1").get()?.id;
|
|
173
|
+
}
|
|
174
|
+
function subagentExecutionState(output, child) {
|
|
175
|
+
if (!output || !child) return "unknown";
|
|
176
|
+
const path = lockPath(output, child);
|
|
177
|
+
if (!(0, node_fs.existsSync)(path)) return "unknown";
|
|
178
|
+
let db;
|
|
179
|
+
try {
|
|
180
|
+
db = openDatabase(path, true);
|
|
181
|
+
const generation = previousExecution(db);
|
|
182
|
+
return generation && generation === readSubagentRun(output, child)?.executionId ? "released" : "unknown";
|
|
183
|
+
} catch (error) {
|
|
184
|
+
return busy(error) ? "held" : "unknown";
|
|
185
|
+
} finally {
|
|
186
|
+
db?.close();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
async function withSubagentExecution(task, resume, work) {
|
|
190
|
+
(0, node_fs.mkdirSync)((0, node_path.dirname)(task.outputFile), { recursive: true });
|
|
191
|
+
const db = openDatabase(lockPath(task.outputFile, task.childSessionId));
|
|
192
|
+
let references = 1;
|
|
193
|
+
const release = () => {
|
|
194
|
+
if (--references === 0) db.close();
|
|
195
|
+
};
|
|
196
|
+
try {
|
|
197
|
+
db.exec("PRAGMA locking_mode=EXCLUSIVE; BEGIN EXCLUSIVE");
|
|
198
|
+
if (resume) {
|
|
199
|
+
const metadata = readSubagentRun(task.outputFile, task.childSessionId, task.agentId);
|
|
200
|
+
const generation = previousExecution(db);
|
|
201
|
+
if (!metadata || ![
|
|
202
|
+
"completed",
|
|
203
|
+
"failed",
|
|
204
|
+
"stopped"
|
|
205
|
+
].includes(metadata.status) && !(metadata.status === "running" && generation && generation === metadata.executionId)) throw new Error("Cannot resume this agent because its previous execution owner is unknown.");
|
|
206
|
+
}
|
|
207
|
+
db.exec("CREATE TABLE IF NOT EXISTS execution (singleton INTEGER PRIMARY KEY, id TEXT NOT NULL)");
|
|
208
|
+
db.prepare("INSERT OR REPLACE INTO execution VALUES (1, ?)").run(task.executionId);
|
|
209
|
+
db.exec("COMMIT");
|
|
210
|
+
} catch (error) {
|
|
211
|
+
db.close();
|
|
212
|
+
if (busy(error)) throw new Error("This agent execution is still owned by a runtime.");
|
|
213
|
+
throw error;
|
|
214
|
+
}
|
|
215
|
+
try {
|
|
216
|
+
return await active.run({ retain() {
|
|
217
|
+
references++;
|
|
218
|
+
return release;
|
|
219
|
+
} }, work);
|
|
220
|
+
} finally {
|
|
221
|
+
release();
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
function trackSubagentExecution(work) {
|
|
225
|
+
const release = active.getStore()?.retain();
|
|
226
|
+
if (release) work.then(release, release);
|
|
227
|
+
}
|
|
228
|
+
//#endregion
|
|
229
|
+
//#region src/runtime-background-restore.ts
|
|
230
|
+
const history = /* @__PURE__ */ new WeakMap();
|
|
231
|
+
const reads = /* @__PURE__ */ new WeakMap();
|
|
232
|
+
function historicalTaskOutput(registry, id) {
|
|
233
|
+
const task = history.get(registry)?.get(id);
|
|
234
|
+
return task && [
|
|
235
|
+
"completed",
|
|
236
|
+
"failed",
|
|
237
|
+
"killed"
|
|
238
|
+
].includes(task.status ?? "") ? task : void 0;
|
|
239
|
+
}
|
|
240
|
+
function historicalTasks(app) {
|
|
241
|
+
const registry = app.runtime?.runtimeTaskRegistry;
|
|
242
|
+
return registry ? [...history.get(registry)?.values() ?? []] : [];
|
|
243
|
+
}
|
|
244
|
+
async function readHistory(app, session) {
|
|
245
|
+
const runtime = app.runtime;
|
|
246
|
+
const registry = runtime?.runtimeTaskRegistry;
|
|
247
|
+
if (!app.readSubagents || !registry) return;
|
|
248
|
+
const tasks = /* @__PURE__ */ new Map();
|
|
249
|
+
let cursor;
|
|
250
|
+
do {
|
|
251
|
+
const page = await app.readSubagents({
|
|
252
|
+
endedCursor: cursor,
|
|
253
|
+
endedLimit: 100
|
|
254
|
+
});
|
|
255
|
+
for (const agent of [...page.running, ...page.ended.items]) {
|
|
256
|
+
const id = agent.agentId ?? agent.toolCallId;
|
|
257
|
+
const live = registry.get?.(id);
|
|
258
|
+
if (live?.status === "running") continue;
|
|
259
|
+
const output = runtime.transcriptAgentOutputFiles?.get(id) ?? (typeof live?.outputFile === "string" ? live.outputFile : void 0);
|
|
260
|
+
const owner = subagentExecutionState(output, agent.childSessionId);
|
|
261
|
+
const run = readSubagentRun(output, agent.childSessionId, id);
|
|
262
|
+
const savedTerminal = run && {
|
|
263
|
+
completed: "completed",
|
|
264
|
+
failed: "failed",
|
|
265
|
+
stopped: "killed"
|
|
266
|
+
}[run.status];
|
|
267
|
+
const projectedTerminal = {
|
|
268
|
+
success: "completed",
|
|
269
|
+
failed: "failed",
|
|
270
|
+
cancelled: "killed"
|
|
271
|
+
}[agent.status];
|
|
272
|
+
let status = savedTerminal ?? projectedTerminal ?? "owner_unknown";
|
|
273
|
+
if (owner === "held") status = "running_elsewhere";
|
|
274
|
+
else if (run?.status === "running" || !savedTerminal && !projectedTerminal) status = owner === "released" ? "lost" : "owner_unknown";
|
|
275
|
+
if (live && (live.status === status || live.executionId === run?.executionId && run?.executionId)) continue;
|
|
276
|
+
tasks.set(id, {
|
|
277
|
+
taskId: id,
|
|
278
|
+
agentId: id,
|
|
279
|
+
agentType: agent.subagentType,
|
|
280
|
+
type: "local_agent",
|
|
281
|
+
childSessionId: agent.childSessionId,
|
|
282
|
+
parentSessionId: session,
|
|
283
|
+
parentToolCallId: agent.toolCallId,
|
|
284
|
+
description: agent.title,
|
|
285
|
+
isBackgrounded: true,
|
|
286
|
+
status,
|
|
287
|
+
outputFile: output,
|
|
288
|
+
cancellable: false,
|
|
289
|
+
startedAt: agent.startedAt,
|
|
290
|
+
completedAt: agent.endedAt,
|
|
291
|
+
error: status === "failed" ? agent.summary : void 0,
|
|
292
|
+
output: status === "completed" && agent.summary ? {
|
|
293
|
+
status: "completed",
|
|
294
|
+
content: [{
|
|
295
|
+
type: "text",
|
|
296
|
+
text: agent.summary
|
|
297
|
+
}]
|
|
298
|
+
} : void 0
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
cursor = page.ended.nextCursor;
|
|
302
|
+
} while (cursor);
|
|
303
|
+
if (app.sessionId === session && app.runtime === runtime) history.set(registry, tasks);
|
|
304
|
+
}
|
|
305
|
+
async function restoreTuiBackgroundTasks(app) {
|
|
306
|
+
const session = app.sessionId;
|
|
307
|
+
const registry = app.runtime?.runtimeTaskRegistry;
|
|
308
|
+
if (!session || !registry) return;
|
|
309
|
+
const read = reads.get(registry);
|
|
310
|
+
if (read?.session === session && Date.now() - read.time < 2e3) {
|
|
311
|
+
const releasedSinceRead = historicalTasks(app).some((task) => task.status === "running_elsewhere" && subagentExecutionState(task.outputFile, task.childSessionId) !== "held");
|
|
312
|
+
if (read.time === Infinity || !releasedSinceRead) return read.pending;
|
|
313
|
+
}
|
|
314
|
+
if (read?.session !== session) history.delete(registry);
|
|
315
|
+
const entry = {
|
|
316
|
+
session,
|
|
317
|
+
time: Infinity,
|
|
318
|
+
pending: Promise.resolve()
|
|
319
|
+
};
|
|
320
|
+
reads.set(registry, entry);
|
|
321
|
+
entry.pending = readHistory(app, session).then(() => {
|
|
322
|
+
entry.time = Date.now();
|
|
323
|
+
}, () => {
|
|
324
|
+
if (reads.get(registry) === entry) reads.delete(registry);
|
|
325
|
+
});
|
|
326
|
+
return entry.pending;
|
|
327
|
+
}
|
|
328
|
+
//#endregion
|
|
150
329
|
//#region src/runtime-tui-bridge.ts
|
|
151
330
|
const execFileAsync$1 = (0, node_util.promisify)(node_child_process.execFile);
|
|
152
331
|
const workspaceSnapshots = /* @__PURE__ */ new WeakMap();
|
|
@@ -157,6 +336,7 @@ function taskDetail(task) {
|
|
|
157
336
|
const kind = task.taskType ?? task.type;
|
|
158
337
|
return {
|
|
159
338
|
taskId: task.taskId,
|
|
339
|
+
executionId: task.executionId,
|
|
160
340
|
taskKind: kind,
|
|
161
341
|
agentId: task.agentId,
|
|
162
342
|
agentType: task.agentType,
|
|
@@ -174,7 +354,7 @@ function taskDetail(task) {
|
|
|
174
354
|
cancelRequestedAt: running ? null : task.cancelRequestedAt,
|
|
175
355
|
blocked: running ? null : task.blocked,
|
|
176
356
|
blockedReason: running ? null : task.blockedReason,
|
|
177
|
-
cancellable: kind === "local_agent" ? running : task.cancellable
|
|
357
|
+
cancellable: kind === "local_agent" ? running && typeof task.executionId === "string" : task.cancellable
|
|
178
358
|
};
|
|
179
359
|
}
|
|
180
360
|
async function readRuntimeWorkspace(runtime) {
|
|
@@ -206,8 +386,19 @@ async function readTuiRuntimeProjection(app, bridge) {
|
|
|
206
386
|
await bridge.$zRestorePersistedBackgroundTasks?.(app);
|
|
207
387
|
const projection = await app.runtime?.getProjection?.();
|
|
208
388
|
if (!projection) return null;
|
|
209
|
-
const
|
|
210
|
-
const
|
|
389
|
+
const live = Object.values(app.runtime?.runtimeTaskRegistry?.all?.() ?? {}).filter((task) => task.isBackgrounded === true);
|
|
390
|
+
const history = historicalTasks(app).filter((task) => !live.some((current) => current.taskId === task.taskId && current.status === "running"));
|
|
391
|
+
const details = [...live, ...history].map(taskDetail);
|
|
392
|
+
const tasks = Array.isArray(projection.backgroundTasks) ? projection.backgroundTasks.map((task) => {
|
|
393
|
+
const kind = task.taskKind ?? task.taskType ?? task.type;
|
|
394
|
+
if ((kind === "local_agent" || kind === "agent" || task.toolName === "Agent") && task.status === "running") return {
|
|
395
|
+
...task,
|
|
396
|
+
status: "owner_unknown",
|
|
397
|
+
cancellable: false,
|
|
398
|
+
executionId: void 0
|
|
399
|
+
};
|
|
400
|
+
return task;
|
|
401
|
+
}) : [];
|
|
211
402
|
for (const detail of details) {
|
|
212
403
|
const index = tasks.findIndex((existing) => existing.taskId === detail.taskId);
|
|
213
404
|
if (index < 0) tasks.push(detail);
|
|
@@ -222,29 +413,35 @@ async function readTuiRuntimeProjection(app, bridge) {
|
|
|
222
413
|
workspace: await readRuntimeWorkspace(app.runtime),
|
|
223
414
|
backgroundTasks: tasks,
|
|
224
415
|
backgroundTaskDetails: details,
|
|
225
|
-
restoredBackgroundTasks:
|
|
416
|
+
restoredBackgroundTasks: history.filter((task) => [
|
|
417
|
+
"completed",
|
|
418
|
+
"failed",
|
|
419
|
+
"lost"
|
|
420
|
+
].includes(task.status ?? "")).map(taskDetail)
|
|
226
421
|
};
|
|
227
422
|
}
|
|
423
|
+
async function stopTuiBackgroundTask(app, id, executionId) {
|
|
424
|
+
const task = app.runtime?.runtimeTaskRegistry?.get?.(id);
|
|
425
|
+
if (!executionId && task?.type !== "local_agent" && !historicalTasks(app).some((row) => row.taskId === id)) return app.cancelBackgroundTask?.(id);
|
|
426
|
+
if (!executionId || task?.executionId !== executionId || !app.runtime?.stopBackgroundTask) throw new Error("This agent execution is no longer available to stop.");
|
|
427
|
+
const result = await app.runtime.stopBackgroundTask(id, {
|
|
428
|
+
expectedExecutionId: executionId,
|
|
429
|
+
initiator: "user",
|
|
430
|
+
strict: true
|
|
431
|
+
});
|
|
432
|
+
if (!result.ok) throw new Error(`Agent stop rejected: ${result.reason}`);
|
|
433
|
+
return result;
|
|
434
|
+
}
|
|
228
435
|
async function sendTuiBackgroundTaskMessage(app, bridge, input) {
|
|
229
436
|
await bridge.$zRestorePersistedBackgroundTasks?.(app);
|
|
230
437
|
const runtime = app.runtime;
|
|
231
|
-
|
|
232
|
-
if (!task && typeof app.sessionId === "string") {
|
|
233
|
-
app.$zRestoredBackgroundTasksSession = void 0;
|
|
234
|
-
await bridge.$zRestorePersistedBackgroundTasks?.(app);
|
|
235
|
-
task = runtime?.runtimeTaskRegistry?.get?.(input?.taskId);
|
|
236
|
-
}
|
|
438
|
+
const task = runtime?.runtimeTaskRegistry?.get?.(input?.taskId) ?? historicalTasks(app).find((row) => row.taskId === input?.taskId);
|
|
237
439
|
if (!runtime?.subagentPort?.sendMessage) throw new Error("Background agent messaging is unavailable in this runtime.");
|
|
238
440
|
if (!task || (task.type ?? task.taskType) !== "local_agent") throw new Error("The selected task is not a local agent.");
|
|
239
441
|
if (typeof input?.message !== "string" || !input.message.trim()) throw new Error("Enter a message for the background agent.");
|
|
240
442
|
const message = input.message.trim().slice(0, maximumTaskMessageLength);
|
|
241
443
|
const summary = (typeof input.summary === "string" ? input.summary : message).replace(/\s+/g, " ").trim().slice(0, maximumTaskSummaryLength);
|
|
242
|
-
if (input.restart
|
|
243
|
-
if (!runtime.subagentPort.stopTask) throw new Error("Background agent restart is unavailable in this runtime.");
|
|
244
|
-
await runtime.subagentPort.stopTask(input.taskId);
|
|
245
|
-
task = runtime.runtimeTaskRegistry?.get?.(input.taskId);
|
|
246
|
-
if (!task) throw new Error("The background agent stopped but could not be restored.");
|
|
247
|
-
}
|
|
444
|
+
if (input.restart) await stopTuiBackgroundTask(app, input.taskId, input.executionId);
|
|
248
445
|
return await runtime.subagentPort.sendMessage({
|
|
249
446
|
sessionId: task.parentSessionId ?? runtime.getSessionId?.(),
|
|
250
447
|
turnId: task.turnId ?? "tui-task-message",
|
|
@@ -591,111 +788,6 @@ function createTuiWorkflowManagement(deps) {
|
|
|
591
788
|
};
|
|
592
789
|
}
|
|
593
790
|
//#endregion
|
|
594
|
-
//#region src/runtime-background-restore.ts
|
|
595
|
-
const maximumReminderLength = 4e3;
|
|
596
|
-
async function restoreSessionChildren(app, sessionId, queries) {
|
|
597
|
-
const store = app.runtime?.sessionStore;
|
|
598
|
-
const eventStore = app.runtime?.getSessionEventStore?.();
|
|
599
|
-
if (!store || !eventStore) return [];
|
|
600
|
-
const parentSession = await store.getSession(sessionId);
|
|
601
|
-
if (!parentSession) return [];
|
|
602
|
-
const [messages, parentEvents, parentProjection] = await Promise.all([
|
|
603
|
-
store.messages({ sessionID: sessionId }),
|
|
604
|
-
eventStore.getEvents(sessionId),
|
|
605
|
-
app.runtime?.getProjection?.()
|
|
606
|
-
]);
|
|
607
|
-
const ids = [...new Set(queries.collectChildSessionIds(parentSession, messages, parentEvents))];
|
|
608
|
-
const valid = (await Promise.all(ids.map(async (id) => {
|
|
609
|
-
const session = await store.getSession(id);
|
|
610
|
-
if (!session || session.parentID !== sessionId || session.taskType !== "subagent_child") return null;
|
|
611
|
-
const [messages, events] = await Promise.all([store.messages({ sessionID: id }), eventStore.getEvents(id)]);
|
|
612
|
-
return {
|
|
613
|
-
session,
|
|
614
|
-
messages,
|
|
615
|
-
projection: events.length ? queries.projectChildEvents(events) : void 0
|
|
616
|
-
};
|
|
617
|
-
}))).filter((child) => child !== null);
|
|
618
|
-
const projection = queries.projectSubagents({
|
|
619
|
-
revision: 0,
|
|
620
|
-
parentSession,
|
|
621
|
-
messages,
|
|
622
|
-
parentEvents,
|
|
623
|
-
parentProjection,
|
|
624
|
-
childSessionsById: new Map(valid.map((child) => [child.session.id, child.session])),
|
|
625
|
-
childMessagesById: new Map(valid.map((child) => [child.session.id, child.messages])),
|
|
626
|
-
childProjectionsById: new Map(valid.flatMap((child) => child.projection ? [[child.session.id, child.projection]] : []))
|
|
627
|
-
});
|
|
628
|
-
return [...projection.running, ...projection.ended].map((agent) => ({
|
|
629
|
-
taskId: agent.agentId ?? agent.toolCallId,
|
|
630
|
-
agentId: agent.agentId ?? agent.toolCallId,
|
|
631
|
-
agentType: agent.subagentType,
|
|
632
|
-
childSessionId: agent.childSessionId,
|
|
633
|
-
description: agent.title,
|
|
634
|
-
isBackgrounded: true,
|
|
635
|
-
parentSessionId: sessionId,
|
|
636
|
-
parentToolCallId: agent.toolCallId,
|
|
637
|
-
startedAt: agent.startedAt,
|
|
638
|
-
completedAt: agent.endedAt,
|
|
639
|
-
status: [
|
|
640
|
-
"running",
|
|
641
|
-
"waiting",
|
|
642
|
-
"blocked"
|
|
643
|
-
].includes(agent.status) ? "running" : agent.status === "success" ? "completed" : agent.status === "failed" ? "failed" : "stopped",
|
|
644
|
-
error: agent.status === "failed" ? agent.summary : void 0,
|
|
645
|
-
output: agent.status === "success" && agent.summary ? {
|
|
646
|
-
status: "completed",
|
|
647
|
-
content: [{
|
|
648
|
-
type: "text",
|
|
649
|
-
text: agent.summary
|
|
650
|
-
}]
|
|
651
|
-
} : void 0,
|
|
652
|
-
taskType: "local_agent",
|
|
653
|
-
type: "local_agent"
|
|
654
|
-
}));
|
|
655
|
-
}
|
|
656
|
-
async function restore(app, queries) {
|
|
657
|
-
const runtime = app.runtime;
|
|
658
|
-
const registry = runtime?.runtimeTaskRegistry;
|
|
659
|
-
const sessionId = app.sessionId;
|
|
660
|
-
if (!registry?.register || typeof sessionId !== "string" || sessionId === app.$zRestoredBackgroundTasksSession) return;
|
|
661
|
-
app.$zRestoredBackgroundTasksLog = [];
|
|
662
|
-
try {
|
|
663
|
-
const tasks = await restoreSessionChildren(app, sessionId, queries);
|
|
664
|
-
if (app.sessionId !== sessionId || app.runtime !== runtime) return;
|
|
665
|
-
const restored = [];
|
|
666
|
-
for (const task of tasks) {
|
|
667
|
-
if (registry.get?.(task.taskId)) continue;
|
|
668
|
-
registry.register(task);
|
|
669
|
-
restored.push(task);
|
|
670
|
-
}
|
|
671
|
-
app.$zRestoredBackgroundTasksSession = sessionId;
|
|
672
|
-
if (restored.length === 0) return;
|
|
673
|
-
const taskIds = restored.slice(-32).map((task) => `- ${task.taskId} (${task.status})`).join("\n").slice(0, maximumReminderLength);
|
|
674
|
-
runtime?.messageHistory?.addAttachment?.("task_status", `Background agent tasks from this resumed session have been restored and are available again.
|
|
675
|
-
Earlier TaskOutput errors saying "No task found" occurred before restoration and are stale.
|
|
676
|
-
Use TaskOutput to collect results or SendMessage to continue a task. Do not assume these tasks were lost.
|
|
677
|
-
Restored task IDs:\n${taskIds}`);
|
|
678
|
-
app.$zRestoredBackgroundTasksLog = [...app.$zRestoredBackgroundTasksLog ?? [], ...restored].slice(-64);
|
|
679
|
-
} catch {
|
|
680
|
-
if (app.sessionId === sessionId) app.$zRestoredBackgroundTasksSession = void 0;
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
const pendingRestores = /* @__PURE__ */ new WeakMap();
|
|
684
|
-
async function restoreTuiBackgroundTasks(app, queries) {
|
|
685
|
-
const pending = pendingRestores.get(app);
|
|
686
|
-
if (pending) {
|
|
687
|
-
await pending;
|
|
688
|
-
return restoreTuiBackgroundTasks(app, queries);
|
|
689
|
-
}
|
|
690
|
-
const operation = restore(app, queries);
|
|
691
|
-
pendingRestores.set(app, operation);
|
|
692
|
-
try {
|
|
693
|
-
await operation;
|
|
694
|
-
} finally {
|
|
695
|
-
pendingRestores.delete(app);
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
//#endregion
|
|
699
791
|
//#region src/runtime-workspace-paths.ts
|
|
700
792
|
function compare(first, second) {
|
|
701
793
|
return first.rank - second.rank || Number(first.item.kind === "file") - Number(second.item.kind === "file") || first.depth - second.depth || first.item.path.localeCompare(second.item.path);
|
|
@@ -1722,6 +1814,7 @@ exports.createRecoverableSystemKeyStore = createRecoverableSystemKeyStore;
|
|
|
1722
1814
|
exports.createTuiWorkflowManagement = createTuiWorkflowManagement;
|
|
1723
1815
|
exports.ensureSessionForTitle = ensureSessionForTitle;
|
|
1724
1816
|
exports.exchangeBigmodelOAuthCode = exchangeBigmodelOAuthCode;
|
|
1817
|
+
exports.historicalTaskOutput = historicalTaskOutput;
|
|
1725
1818
|
exports.inspectRuntimeConfiguration = inspectRuntimeConfiguration;
|
|
1726
1819
|
exports.installSqliteWriteRecovery = installSqliteWriteRecovery;
|
|
1727
1820
|
exports.listManagedWorktrees = listManagedWorktrees;
|
|
@@ -1743,9 +1836,13 @@ exports.sendTuiBackgroundTaskMessage = sendTuiBackgroundTaskMessage;
|
|
|
1743
1836
|
exports.sharedOAuthCredentialReader = sharedOAuthCredentialReader;
|
|
1744
1837
|
exports.sqliteRecoveryStats = sqliteRecoveryStats;
|
|
1745
1838
|
exports.startTuiSavedWorkflow = startTuiSavedWorkflow;
|
|
1839
|
+
exports.stopTuiBackgroundTask = stopTuiBackgroundTask;
|
|
1840
|
+
exports.subagentExecutionState = subagentExecutionState;
|
|
1841
|
+
exports.trackSubagentExecution = trackSubagentExecution;
|
|
1746
1842
|
exports.unlockKeychainInTerminal = unlockKeychainInTerminal;
|
|
1747
1843
|
exports.withHeadlessPromptLifecycle = withHeadlessPromptLifecycle;
|
|
1748
1844
|
exports.withRecursiveWorkspacePathSuggestions = withRecursiveWorkspacePathSuggestions;
|
|
1845
|
+
exports.withSubagentExecution = withSubagentExecution;
|
|
1749
1846
|
exports.writeConfigurationDoctor = writeConfigurationDoctor;
|
|
1750
1847
|
exports.writeTuiShowReasoning = writeTuiShowReasoning;
|
|
1751
1848
|
exports.zaiBusinessAccessToken = zaiBusinessAccessToken;
|
package/vendor/extraction.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"appVersion": "4.0.0",
|
|
3
3
|
"cliVersion": "0.18.0",
|
|
4
|
-
"extractedAt": "2026-
|
|
4
|
+
"extractedAt": "2026-12-03T00:35:28.382Z",
|
|
5
5
|
"sha512": "rl0Q2ZO0W9gxf7oi7PjAgyBw+3ivnVYzXF9VdBWAs2Ie7KtzNLV6yv3wJkz/fvr35TWOFUr2wLodUS/PqxfhBA==",
|
|
6
6
|
"source": "https://cdn-zcode.z.ai/zcode/electron/releases/4.0.0/linux-x64/ZCode-4.0.0-linux-x64.deb",
|
|
7
7
|
"runtimeCapabilities": {
|