@gaoding/cli 3.0.0 → 3.0.2
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 -2
- package/contracts/operations/agent.send/input.schema.json +1 -1
- package/contracts/operations/credits.get/output.schema.json +3 -3
- package/contracts/operations/dam.copy/input.schema.json +3 -3
- package/contracts/operations/dam.copy/output.schema.json +1 -1
- package/contracts/operations/dam.list/output.schema.json +2 -2
- package/contracts/operations/dam.move/input.schema.json +3 -3
- package/contracts/operations/dam.search/output.schema.json +2 -2
- package/contracts/operations/task.get/output.schema.json +2 -2
- package/contracts/presentations/task.get.schema.json +2 -2
- package/dist/bin/gd-cli.js +1 -6
- package/dist/bin/insmind-cli.js +1 -6
- package/dist/src/bootstrap/create-cli.js +32 -19
- package/dist/src/bootstrap/create-runtime.js +6 -2
- package/dist/src/bootstrap/run-task-worker.js +6 -2
- package/dist/src/bootstrap/validators.js +0 -8
- package/dist/src/cli/agent-commands.js +3 -3
- package/dist/src/cli/dam-commands.js +14 -6
- package/dist/src/cli/errors.js +17 -6
- package/dist/src/cli/task-commands.js +1 -1
- package/dist/src/cli/update-command.js +3 -3
- package/dist/src/contracts/creation-input.js +0 -3
- package/dist/src/features/dam/file-downloader.js +19 -9
- package/dist/src/features/dam/operation-executor.js +2 -0
- package/dist/src/features/dam/use-cases.js +53 -29
- package/dist/src/features/skill/manual.js +37 -31
- package/dist/src/features/task/store.js +7 -0
- package/dist/src/features/task/use-cases.js +66 -10
- package/dist/src/features/update/check-schema.js +22 -16
- package/dist/src/features/update/update-notification.js +8 -4
- package/dist/src/features/update/update-service.js +37 -16
- package/dist/src/telemetry/invocation.js +8 -4
- package/dist/src/telemetry/process-errors.js +7 -2
- package/dist/src/telemetry/sanitize.js +18 -7
- package/dist/src/telemetry/sls-sink.js +38 -15
- package/package.json +7 -7
- package/skills/gd-cli/SKILL.md +1 -1
- package/dist/src/features/editor/bridge-client.js +0 -107
- package/dist/src/features/editor/bridge-process.js +0 -237
- package/dist/src/features/editor/bridge-server.js +0 -339
- package/dist/src/features/editor/protocol.js +0 -1
- package/dist/src/features/editor/public-url.js +0 -1
- package/dist/src/features/editor/session-state.js +0 -81
- package/dist/src/features/editor/session.js +0 -232
- package/dist/src/features/editor/use-cases.js +0 -118
|
@@ -16,8 +16,10 @@ export class DamDownloadError extends Error {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
export class DamDownloadDestinationExistsError extends Error {
|
|
19
|
-
|
|
19
|
+
remainingPaths;
|
|
20
|
+
constructor(remainingPaths = []) {
|
|
20
21
|
super("目标文件已存在,未覆盖任何文件。");
|
|
22
|
+
this.remainingPaths = remainingPaths;
|
|
21
23
|
this.name = "DamDownloadDestinationExistsError";
|
|
22
24
|
}
|
|
23
25
|
}
|
|
@@ -234,6 +236,7 @@ export function createDamFileDownloader(options = {}) {
|
|
|
234
236
|
item.open = false;
|
|
235
237
|
}
|
|
236
238
|
for (const item of pending) {
|
|
239
|
+
input.signal.throwIfAborted();
|
|
237
240
|
try {
|
|
238
241
|
await dependencies.fileSystem.link(item.temporaryPath, item.finalPath);
|
|
239
242
|
}
|
|
@@ -258,28 +261,35 @@ export function createDamFileDownloader(options = {}) {
|
|
|
258
261
|
}));
|
|
259
262
|
}
|
|
260
263
|
catch (error) {
|
|
261
|
-
|
|
264
|
+
// Another process can replace a published name. Only remove the private temporaries.
|
|
265
|
+
const remainingPaths = [...createdFinalPaths];
|
|
262
266
|
const cleanupErrors = [];
|
|
263
267
|
let temporaryCleanupFailed = false;
|
|
264
268
|
await Promise.all(pending.map(async (item) => {
|
|
265
269
|
if (item.open)
|
|
266
270
|
await item.handle.close().catch(cause => { cleanupErrors.push(cause); });
|
|
267
|
-
await dependencies.fileSystem.rm(item.temporaryPath, { force: true }).catch(
|
|
271
|
+
await dependencies.fileSystem.rm(item.temporaryPath, { force: true }).catch(() => {
|
|
268
272
|
remainingPaths.push(item.temporaryPath);
|
|
269
273
|
temporaryCleanupFailed = true;
|
|
270
274
|
});
|
|
271
275
|
}));
|
|
272
|
-
await Promise.all(createdFinalPaths.map((path) => (dependencies.fileSystem.rm(path, { force: true }).catch(cause => { remainingPaths.push(path); cleanupErrors.push(cause); }))));
|
|
273
276
|
if (temporaryCleanupFailed)
|
|
274
277
|
warnCleanup();
|
|
275
278
|
if (cleanupErrors.length)
|
|
276
279
|
throw new DamDownloadError(new AggregateError([error, ...cleanupErrors], "Download cleanup failed.", { cause: error }), "cleanup", undefined, remainingPaths);
|
|
277
|
-
if (isInterruption(error, input.signal))
|
|
280
|
+
if (isInterruption(error, input.signal)) {
|
|
281
|
+
if (remainingPaths.length)
|
|
282
|
+
throw new DamDownloadError(input.signal.reason, "interrupted", undefined, remainingPaths);
|
|
278
283
|
throw input.signal.reason;
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
throw
|
|
282
|
-
|
|
284
|
+
}
|
|
285
|
+
if (error instanceof DamDownloadDestinationExistsError)
|
|
286
|
+
throw new DamDownloadDestinationExistsError(remainingPaths);
|
|
287
|
+
if (error instanceof DamDownloadError) {
|
|
288
|
+
if (!remainingPaths.length)
|
|
289
|
+
throw error;
|
|
290
|
+
throw new DamDownloadError(error.cause, error.phase, error.status, remainingPaths);
|
|
291
|
+
}
|
|
292
|
+
throw new DamDownloadError(error, "write", undefined, remainingPaths);
|
|
283
293
|
}
|
|
284
294
|
}
|
|
285
295
|
};
|
|
@@ -51,6 +51,8 @@ export function createDamOperationExecutor(dependencies) {
|
|
|
51
51
|
if (task.fail_count !== null && task.fail_count > 0) {
|
|
52
52
|
throw new DamOperationFailedError(input.operation);
|
|
53
53
|
}
|
|
54
|
+
if (input.operation === "move")
|
|
55
|
+
return { task_id: taskId };
|
|
54
56
|
if (input.operation !== "copy" || input.inspectResult === undefined)
|
|
55
57
|
return {};
|
|
56
58
|
const result = await input.inspectResult(taskId, input.signal);
|
|
@@ -90,6 +90,45 @@ export function createDamUseCases(dependencies) {
|
|
|
90
90
|
});
|
|
91
91
|
return { repositoryId: detail.repository_id, folderId: detail.folder_id };
|
|
92
92
|
}
|
|
93
|
+
async function verifyEntryChange(signal, matches) {
|
|
94
|
+
signal.throwIfAborted();
|
|
95
|
+
const timeoutMs = 60_000;
|
|
96
|
+
const end = performance.now() + timeoutMs;
|
|
97
|
+
const controller = new AbortController();
|
|
98
|
+
const verificationSignal = AbortSignal.any([signal, controller.signal]);
|
|
99
|
+
const expire = () => controller.abort(new Error("DAM verification timed out"));
|
|
100
|
+
const timer = setTimeout(expire, timeoutMs);
|
|
101
|
+
let onAbort;
|
|
102
|
+
const aborted = new Promise((_resolve, reject) => {
|
|
103
|
+
onAbort = () => reject(verificationSignal.reason);
|
|
104
|
+
verificationSignal.addEventListener("abort", onAbort, { once: true });
|
|
105
|
+
});
|
|
106
|
+
function remainingTime() {
|
|
107
|
+
const remaining = end - performance.now();
|
|
108
|
+
if (remaining <= 0)
|
|
109
|
+
expire();
|
|
110
|
+
verificationSignal.throwIfAborted();
|
|
111
|
+
return remaining;
|
|
112
|
+
}
|
|
113
|
+
async function verify() {
|
|
114
|
+
while (true) {
|
|
115
|
+
remainingTime();
|
|
116
|
+
const confirmed = await matches(verificationSignal);
|
|
117
|
+
const remaining = remainingTime();
|
|
118
|
+
if (confirmed)
|
|
119
|
+
return;
|
|
120
|
+
await dependencies.sleep(Math.min(2_000, remaining), verificationSignal);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
try {
|
|
124
|
+
// End the wait even if the in-flight read or interval ignores cancellation.
|
|
125
|
+
await Promise.race([verify(), aborted]);
|
|
126
|
+
}
|
|
127
|
+
finally {
|
|
128
|
+
clearTimeout(timer);
|
|
129
|
+
verificationSignal.removeEventListener("abort", onAbort);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
93
132
|
function assertEntryOperationInput(input) {
|
|
94
133
|
assertAssetId(input.entry_id, "entry_id");
|
|
95
134
|
if (input.kind !== "asset" && input.kind !== "folder")
|
|
@@ -157,6 +196,7 @@ export function createDamUseCases(dependencies) {
|
|
|
157
196
|
sourceRepositoryId: sourceRepository.id,
|
|
158
197
|
targetRepositoryId,
|
|
159
198
|
targetFolderId: input.request.targetFolderId,
|
|
199
|
+
...(execution.task_id ? { taskId: execution.task_id } : {}),
|
|
160
200
|
...(execution.copied_entry_id === undefined
|
|
161
201
|
? {}
|
|
162
202
|
: { copiedEntryId: execution.copied_entry_id })
|
|
@@ -358,16 +398,7 @@ export function createDamUseCases(dependencies) {
|
|
|
358
398
|
return result;
|
|
359
399
|
}
|
|
360
400
|
try {
|
|
361
|
-
await dependencies.telemetry.stage("verify", async () => {
|
|
362
|
-
for (let attempt = 0; attempt <= 30; attempt += 1) {
|
|
363
|
-
signal.throwIfAborted();
|
|
364
|
-
if (await entryTitle(request) === input.title)
|
|
365
|
-
return;
|
|
366
|
-
if (attempt < 30)
|
|
367
|
-
await dependencies.sleep(2_000, signal);
|
|
368
|
-
}
|
|
369
|
-
throw new DamOperationUnconfirmedError("rename");
|
|
370
|
-
});
|
|
401
|
+
await dependencies.telemetry.stage("verify", () => verifyEntryChange(signal, async (verifySignal) => await entryTitle({ ...request, signal: verifySignal }) === input.title));
|
|
371
402
|
}
|
|
372
403
|
catch (error) {
|
|
373
404
|
throw new DamOperationUnconfirmedError("rename", { phase: "verify", entry_id: input.entry_id, repository_id: repository.id, accepted: true }, error);
|
|
@@ -386,28 +417,21 @@ export function createDamUseCases(dependencies) {
|
|
|
386
417
|
input = { ...input, entry_id: normalizeDamAssetId(input.entry_id, "entry_id") };
|
|
387
418
|
const operation = await entryOperation({ operation: "move", request: input, access, signal });
|
|
388
419
|
try {
|
|
389
|
-
await dependencies.telemetry.stage("verify", async () => {
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
if (location.repositoryId === operation.targetRepositoryId
|
|
400
|
-
&& location.folderId === operation.targetFolderId)
|
|
401
|
-
return;
|
|
402
|
-
if (attempt < 30)
|
|
403
|
-
await dependencies.sleep(2_000, signal);
|
|
404
|
-
}
|
|
405
|
-
throw new DamOperationUnconfirmedError("move");
|
|
406
|
-
});
|
|
420
|
+
await dependencies.telemetry.stage("verify", () => verifyEntryChange(signal, async (verifySignal) => {
|
|
421
|
+
const location = await entryLocation({
|
|
422
|
+
entryId: input.entry_id,
|
|
423
|
+
kind: input.kind,
|
|
424
|
+
repositoryId: operation.targetRepositoryId,
|
|
425
|
+
access,
|
|
426
|
+
signal: verifySignal
|
|
427
|
+
});
|
|
428
|
+
return location.repositoryId === operation.targetRepositoryId && location.folderId === operation.targetFolderId;
|
|
429
|
+
}));
|
|
407
430
|
}
|
|
408
431
|
catch (error) {
|
|
409
432
|
throw new DamOperationUnconfirmedError("move", { phase: "verify", accepted: true,
|
|
410
|
-
entry_id: input.entry_id, repository_id: operation.targetRepositoryId, folder_id: operation.targetFolderId
|
|
433
|
+
entry_id: input.entry_id, repository_id: operation.targetRepositoryId, folder_id: operation.targetFolderId,
|
|
434
|
+
...(operation.taskId ? { task_id: operation.taskId } : {}) }, error);
|
|
411
435
|
}
|
|
412
436
|
const result = {
|
|
413
437
|
entry_id: input.entry_id,
|
|
@@ -2,8 +2,14 @@ import { readFile } from "node:fs/promises";
|
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
import { createSkillCatalog, MissingSkill } from "./catalog.js";
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
export class SkillManualError extends Error {
|
|
6
|
+
code;
|
|
7
|
+
constructor(code, message) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.code = code;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export function skillManualArguments(argv, name) {
|
|
7
13
|
if (!argv.includes("--skill"))
|
|
8
14
|
return;
|
|
9
15
|
const end = argv.indexOf("--");
|
|
@@ -27,45 +33,45 @@ export async function runSkillManual(argv, name, jsonErrors) {
|
|
|
27
33
|
return;
|
|
28
34
|
if (end >= 0)
|
|
29
35
|
words.push(...argv.slice(end + 1));
|
|
36
|
+
return words;
|
|
37
|
+
}
|
|
38
|
+
export async function writeSkillManual(words, name, write, catalog = createSkillCatalog(name)) {
|
|
30
39
|
const english = name === "insmind-cli";
|
|
31
40
|
const usage = english ? "Usage: insmind-cli --skill [chapter]" : "用法:gd-cli --skill [章节]";
|
|
32
41
|
const [chapter] = words;
|
|
33
42
|
const help = chapter === "--help" || chapter === "-h";
|
|
34
43
|
if (words.length > 1 || (chapter && !help && !/^[a-z][a-z0-9-]{0,63}$/u.test(chapter))) {
|
|
35
|
-
|
|
36
|
-
return 2;
|
|
44
|
+
throw new SkillManualError("USAGE_ERROR", usage);
|
|
37
45
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
process.stdout.write(await catalog.read(chapter));
|
|
42
|
-
return 0;
|
|
46
|
+
async function read(load) {
|
|
47
|
+
try {
|
|
48
|
+
return await load();
|
|
43
49
|
}
|
|
44
|
-
|
|
50
|
+
catch (error) {
|
|
51
|
+
if (error instanceof MissingSkill) {
|
|
52
|
+
throw new SkillManualError("USAGE_ERROR", (english ? "Unknown chapter. " : "未找到该章节。") + usage);
|
|
53
|
+
}
|
|
54
|
+
throw new SkillManualError("SKILL_UNAVAILABLE", english
|
|
55
|
+
? "The guide is unavailable. Use command --help for basic usage."
|
|
56
|
+
: "当前无法取得指引,可用命令的 --help 查看基础用法。");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (chapter !== undefined && !help) {
|
|
60
|
+
await write(await read(() => catalog.read(chapter)));
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (!help) {
|
|
64
|
+
const entry = await read(async () => {
|
|
45
65
|
const { loadBundledSkills } = await import("./bundled-skills.js");
|
|
46
66
|
const skill = loadBundledSkills(fileURLToPath(import.meta.url)).find(entry => entry.skill === name);
|
|
47
67
|
if (!skill)
|
|
48
68
|
throw Error("Missing entry Skill");
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
process.stdout.write(usage + "\n");
|
|
53
|
-
const skills = await catalog.list();
|
|
54
|
-
for (const item of skills)
|
|
55
|
-
process.stdout.write(name + " --skill " + item.id + " " + item.title + " — " + item.description + "\n");
|
|
56
|
-
return 0;
|
|
69
|
+
return readFile(join(skill.sourceDirectory, "SKILL.md"), "utf8");
|
|
70
|
+
});
|
|
71
|
+
await write(entry.replace(/^---\n[\s\S]*?\n---\n/u, "") + "\n");
|
|
57
72
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
const message = english ? "The guide is unavailable. Use command --help for basic usage."
|
|
64
|
-
: "当前无法取得指引,可用命令的 --help 查看基础用法。";
|
|
65
|
-
writeError("SKILL_UNAVAILABLE", message, jsonErrors);
|
|
66
|
-
return 1;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
function writeError(code, message, json) {
|
|
70
|
-
process.stderr.write((json ? JSON.stringify({ error: { code, message } }) : message) + "\n");
|
|
73
|
+
await write(usage + "\n");
|
|
74
|
+
const skills = await read(catalog.list);
|
|
75
|
+
for (const item of skills)
|
|
76
|
+
await write(name + " --skill " + item.id + " " + item.title + " — " + item.description + "\n");
|
|
71
77
|
}
|
|
@@ -108,6 +108,11 @@ export function createTaskStore(options) {
|
|
|
108
108
|
const previous = await store.read(scope, record.task.taskId);
|
|
109
109
|
if (previous) {
|
|
110
110
|
record.progress = mergeProgress(previous.progress, record.progress);
|
|
111
|
+
if (previous.observationCorrection && !record.observationCorrection) {
|
|
112
|
+
if (record.task.state !== "completed")
|
|
113
|
+
record.task = previous.task;
|
|
114
|
+
record.observationCorrection = previous.observationCorrection;
|
|
115
|
+
}
|
|
111
116
|
if (previous.task.state === "completed" || (previous.task.state === "failed" && record.task.state !== "completed")) {
|
|
112
117
|
record.task = previous.task;
|
|
113
118
|
}
|
|
@@ -116,6 +121,8 @@ export function createTaskStore(options) {
|
|
|
116
121
|
if (previous.telemetry) {
|
|
117
122
|
const steps = [...previous.telemetry.steps];
|
|
118
123
|
for (const item of record.telemetry?.steps ?? []) {
|
|
124
|
+
if (item.event.step === "result_received" && record.task.state === "completed" && item.event.outcome === "failure")
|
|
125
|
+
continue;
|
|
119
126
|
if (!steps.some(saved => saved.event.step === item.event.step))
|
|
120
127
|
steps.push(item);
|
|
121
128
|
}
|
|
@@ -33,6 +33,26 @@ function resultTypes(result) {
|
|
|
33
33
|
}
|
|
34
34
|
return [...types].sort();
|
|
35
35
|
}
|
|
36
|
+
function legacyObservationFailure(record) {
|
|
37
|
+
const { task, progress } = record;
|
|
38
|
+
if (task.state !== "failed" || record.observationCorrection)
|
|
39
|
+
return;
|
|
40
|
+
const hasReceipt = task.operation === "agent.send"
|
|
41
|
+
? progress.contextId && progress.localMessageId
|
|
42
|
+
: !Object.hasOwn(progress, "toolRun") && (progress.remoteTaskId || progress.toolPipeline?.settlement?.contentId
|
|
43
|
+
|| progress.toolPipeline?.matting?.segmentTaskId || progress.toolPipeline?.matting?.classifyTaskId);
|
|
44
|
+
if (!hasReceipt)
|
|
45
|
+
return;
|
|
46
|
+
const terminal = record.telemetry?.steps.filter(({ event }) => event.step === "result_received" || event.step === "delivered").at(-1)?.event;
|
|
47
|
+
if (!terminal || terminal.outcome === "success" || (terminal.cli_task_id && terminal.cli_task_id !== task.taskId))
|
|
48
|
+
return;
|
|
49
|
+
for (const code of [terminal.diagnostic_reason, terminal.error_code]) {
|
|
50
|
+
if (code === "LOCAL_WAIT_INTERRUPTED" || code === "TASK_QUERY_FAILED")
|
|
51
|
+
return code;
|
|
52
|
+
}
|
|
53
|
+
if (terminal.failure_stage === "task.query" && terminal.remote_error_code === "12020704")
|
|
54
|
+
return "task.query/12020704";
|
|
55
|
+
}
|
|
36
56
|
const HEARTBEAT_MS = 5_000;
|
|
37
57
|
const LEASE_MS = 15_000;
|
|
38
58
|
export function taskStartedNotice(taskId, command, mode, text) {
|
|
@@ -75,15 +95,20 @@ export function createTaskUseCases(dependencies) {
|
|
|
75
95
|
if (!telemetry)
|
|
76
96
|
return;
|
|
77
97
|
for (const item of record.telemetry?.steps ?? []) {
|
|
78
|
-
if (item.enqueued)
|
|
98
|
+
if (item.enqueued || (record.observationCorrection && item.event.step !== "request_sent"))
|
|
79
99
|
continue;
|
|
80
100
|
const generation = taskProcessGeneration();
|
|
81
101
|
let mayEmit = true;
|
|
82
102
|
try {
|
|
83
103
|
await dependencies.store.update(scope, record.task.taskId, stored => {
|
|
104
|
+
if (stored.observationCorrection && item.event.step !== "request_sent") {
|
|
105
|
+
mayEmit = false;
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
84
108
|
const saved = stored.telemetry?.steps.find(row => row.event.step === item.event.step);
|
|
85
109
|
if (!saved)
|
|
86
110
|
return; // The first-observation write failed; the stable event still goes to the queue.
|
|
111
|
+
item.event = saved.event;
|
|
87
112
|
item.enqueued = saved.enqueued;
|
|
88
113
|
mayEmit = !saved.enqueued && !taskProcessAlive(saved.enqueuePid, saved.enqueueGeneration, saved.enqueueAtMs ?? saved.event.occurred_at_ms);
|
|
89
114
|
if (mayEmit) {
|
|
@@ -127,9 +152,13 @@ export function createTaskUseCases(dependencies) {
|
|
|
127
152
|
catch { /* If the writer exits here, a later process reuses the original event key. */ }
|
|
128
153
|
}
|
|
129
154
|
}
|
|
130
|
-
|
|
155
|
+
function factObservation(record, step, at, outcome = "success", error) {
|
|
131
156
|
if (!telemetry || !record.telemetry)
|
|
132
157
|
return;
|
|
158
|
+
// Terminal facts for this corrected trace already have stable IDs. Keep the
|
|
159
|
+
// original evidence locally and do not send conflicting outcomes on recovery.
|
|
160
|
+
if (record.observationCorrection && step !== "request_sent")
|
|
161
|
+
return;
|
|
133
162
|
const current = telemetry.creationContext();
|
|
134
163
|
const { parameters, ...origin } = record.telemetry.context;
|
|
135
164
|
const creating = current.operation === origin.operation;
|
|
@@ -147,9 +176,9 @@ export function createTaskUseCases(dependencies) {
|
|
|
147
176
|
...(step === "request_sent" && (current.parameters ?? parameters) ? { parameters: current.parameters ?? parameters } : {}),
|
|
148
177
|
...(error === undefined ? {} : telemetry.taskFailure(error)),
|
|
149
178
|
...(step !== "request_sent" && record.task.result ? { result_types: resultTypes(record.task.result) } : {}) };
|
|
150
|
-
|
|
179
|
+
return (stored) => {
|
|
151
180
|
const facts = stored.telemetry;
|
|
152
|
-
if (!facts)
|
|
181
|
+
if (!facts || (stored.observationCorrection && step !== "request_sent"))
|
|
153
182
|
return;
|
|
154
183
|
for (const item of record.telemetry?.steps ?? []) {
|
|
155
184
|
if (!facts.steps.some(saved => saved.event.step === item.event.step))
|
|
@@ -170,7 +199,12 @@ export function createTaskUseCases(dependencies) {
|
|
|
170
199
|
facts.context = { ...origin, ...(protocol ? { execution_protocol: protocol } : {}), ...(event.content_id ? { content_id: event.content_id } : {}), ...(event.tool_name ? { tool_name: event.tool_name } : {}), ...(event.model_id ? { model_id: event.model_id } : {}) };
|
|
171
200
|
}
|
|
172
201
|
facts.steps.push({ event, enqueued: false });
|
|
173
|
-
}
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
async function fact(scope, record, step, at, outcome = "success", error) {
|
|
205
|
+
const observe = factObservation(record, step, at, outcome, error);
|
|
206
|
+
if (!observe)
|
|
207
|
+
return;
|
|
174
208
|
try {
|
|
175
209
|
const updated = await dependencies.store.update(scope, record.task.taskId, observe);
|
|
176
210
|
if (updated.telemetry)
|
|
@@ -327,7 +361,7 @@ export function createTaskUseCases(dependencies) {
|
|
|
327
361
|
catch (error) {
|
|
328
362
|
if (!(error instanceof LocalFileError) || !dispatched || (input.executionMode === "async" && !durableAcceptance)
|
|
329
363
|
|| (progress.toolPipeline?.matting && progress.toolPipeline.stage !== "complete")) {
|
|
330
|
-
throw storageContext(error, dispatched ? "after_dispatch" : "before_dispatch");
|
|
364
|
+
throw storageContext(error, dispatched ? "after_dispatch" : record.progress.submissionStarted ? "submission_unconfirmed" : "before_dispatch");
|
|
331
365
|
}
|
|
332
366
|
await cacheWarning(record.task.taskId);
|
|
333
367
|
return;
|
|
@@ -338,7 +372,9 @@ export function createTaskUseCases(dependencies) {
|
|
|
338
372
|
clearInterval(timer);
|
|
339
373
|
await stage("task.validate", async () => { finish(record, result); });
|
|
340
374
|
telemetry?.annotate({ result_state: record.task.state });
|
|
341
|
-
|
|
375
|
+
if (record.task.state === "completed") {
|
|
376
|
+
factObservation(record, "result_received", dependencies.now().getTime())?.(record);
|
|
377
|
+
}
|
|
342
378
|
let persistenceError;
|
|
343
379
|
try {
|
|
344
380
|
await stage("task.persist", save);
|
|
@@ -349,7 +385,7 @@ export function createTaskUseCases(dependencies) {
|
|
|
349
385
|
persistenceError = error;
|
|
350
386
|
}
|
|
351
387
|
if (record.task.state === "completed") {
|
|
352
|
-
await
|
|
388
|
+
await enqueuePending(scope, record);
|
|
353
389
|
await analyticsFact("completed");
|
|
354
390
|
}
|
|
355
391
|
if (persistenceError) {
|
|
@@ -431,7 +467,21 @@ export function createTaskUseCases(dependencies) {
|
|
|
431
467
|
},
|
|
432
468
|
async get({ state, id, signal }) {
|
|
433
469
|
const scope = taskScope(state);
|
|
434
|
-
|
|
470
|
+
let record = await readRecord(state, id, signal);
|
|
471
|
+
if (legacyObservationFailure(record)) {
|
|
472
|
+
record = await stage("task.persist", () => dependencies.store.update(scope, id, stored => {
|
|
473
|
+
const reason = legacyObservationFailure(stored);
|
|
474
|
+
if (!reason)
|
|
475
|
+
return;
|
|
476
|
+
const task = stored.task;
|
|
477
|
+
const correctedAt = dependencies.now().toISOString();
|
|
478
|
+
stored.observationCorrection = { previousState: "failed", previousUpdatedAt: task.updatedAt, reason, correctedAt,
|
|
479
|
+
...(task.note === undefined ? {} : { previousNote: task.note }) };
|
|
480
|
+
task.state = "unknown";
|
|
481
|
+
task.updatedAt = correctedAt;
|
|
482
|
+
delete task.note;
|
|
483
|
+
}));
|
|
484
|
+
}
|
|
435
485
|
await enqueuePending(scope, record);
|
|
436
486
|
telemetry?.annotate({ diagnostic_summary: {
|
|
437
487
|
...(record.progress.contextId ? { agentContextId: record.progress.contextId } : {}),
|
|
@@ -440,6 +490,11 @@ export function createTaskUseCases(dependencies) {
|
|
|
440
490
|
telemetry?.annotate({ cli_task_id: id, result_state: record.task.state });
|
|
441
491
|
if (record.task.state === "completed" && record.task.result) {
|
|
442
492
|
const result = { ...record.task, result: await stage("task.authorize", () => dependencies.recovery.authorize(record.task.result, state, signal, record.progress)) };
|
|
493
|
+
// A pre-upgrade writer could save the work before recording its receipt.
|
|
494
|
+
if (record.telemetry?.steps.some(item => item.event.step === "request_sent")
|
|
495
|
+
&& !record.telemetry.steps.some(item => item.event.step === "result_received")) {
|
|
496
|
+
await fact(scope, record, "result_received", dependencies.now().getTime());
|
|
497
|
+
}
|
|
443
498
|
pendingOutput = { scope, record };
|
|
444
499
|
await usageWarning(id, record.progress.agentUsageModelMissing === true, record.progress.agentUsageAmountMissing === true);
|
|
445
500
|
return result;
|
|
@@ -496,6 +551,7 @@ export function createTaskUseCases(dependencies) {
|
|
|
496
551
|
record.task = result;
|
|
497
552
|
// Store merging protects terminal results and facts against stale heartbeats.
|
|
498
553
|
const observedTask = record.task;
|
|
554
|
+
factObservation(record, "result_received", dependencies.now().getTime(), result.state === "completed" ? "success" : "failure", failure)?.(record);
|
|
499
555
|
try {
|
|
500
556
|
await stage("task.persist", () => dependencies.store.write(scope, record));
|
|
501
557
|
}
|
|
@@ -507,7 +563,7 @@ export function createTaskUseCases(dependencies) {
|
|
|
507
563
|
if (record.task !== observedTask || recoveredFromCache) {
|
|
508
564
|
result = { ...record.task, ...(record.task.result ? { result: await stage("task.authorize", () => dependencies.recovery.authorize(record.task.result, state, signal, record.progress)) } : {}) };
|
|
509
565
|
}
|
|
510
|
-
await
|
|
566
|
+
await enqueuePending(scope, record);
|
|
511
567
|
if (result.state === "failed")
|
|
512
568
|
pendingOutput = { scope, record, rejected: true };
|
|
513
569
|
}
|
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
// Local CLI output contract exposed by `update check --schema`.
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
2
|
+
export function updateCheckSchema(english) {
|
|
3
|
+
return {
|
|
4
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
5
|
+
type: "object",
|
|
6
|
+
additionalProperties: false,
|
|
7
|
+
required: ["status", "currentVersion"],
|
|
8
|
+
properties: {
|
|
9
|
+
status: { enum: ["available", "current", "managed", "unknown"], description: english
|
|
10
|
+
? "available: a newer version was found. current: the installed version is current. managed: the host manages updates and npm was not queried. unknown: this check could not determine availability."
|
|
11
|
+
: "available 表示查到新版本;current 表示当前已是最新;managed 表示更新由宿主管理,本次未查询 npm;unknown 表示本次无法确定是否有更新。" },
|
|
12
|
+
currentVersion: { type: "string" }, latestVersion: { type: "string" },
|
|
13
|
+
updateCommand: { type: "string", description: english
|
|
14
|
+
? "The self-update command for a recognized global installation, or the command to read update guidance for other sources."
|
|
15
|
+
: "已确认的全局安装返回自更新命令;其他来源返回查看更新说明的命令。" }, notice: { type: "string" }
|
|
16
|
+
},
|
|
17
|
+
oneOf: [
|
|
18
|
+
{ properties: { status: { const: "available" } }, required: ["latestVersion", "updateCommand"] },
|
|
19
|
+
{ properties: { status: { const: "current" }, notice: false, updateCommand: false }, required: ["latestVersion"] },
|
|
20
|
+
{ properties: { status: { enum: ["managed", "unknown"] }, latestVersion: false, updateCommand: false, notice: false } }
|
|
21
|
+
]
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { legacyQwenBridge, updateGuidance } from "./update-service.js";
|
|
1
2
|
import { homedir } from "node:os";
|
|
2
3
|
import { join } from "node:path";
|
|
3
4
|
import { gt, valid } from "semver";
|
|
@@ -52,7 +53,7 @@ export function createUpdateNotificationService(options) {
|
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
async function report(signal, channel, deliver, remember = true) {
|
|
55
|
-
if (options.installationOwner === "workbuddy")
|
|
56
|
+
if (options.installationOwner === "workbuddy" || (command === "gd-cli" && options.installationOwner !== "invalid" && legacyQwenBridge(env)))
|
|
56
57
|
return deliver({ status: "managed", currentVersion });
|
|
57
58
|
if (options.installationOwner === "invalid" || env.CI === "true")
|
|
58
59
|
return deliver(unknown);
|
|
@@ -77,14 +78,17 @@ export function createUpdateNotificationService(options) {
|
|
|
77
78
|
return await deliver(unknown);
|
|
78
79
|
if (!gt(latest, currentVersion))
|
|
79
80
|
return await deliver({ status: "current", currentVersion, latestVersion: latest });
|
|
80
|
-
const
|
|
81
|
+
const source = options.installSource?.();
|
|
82
|
+
const installChannel = source?.kind === "global" ? "global" : source?.channel ?? "unknown";
|
|
83
|
+
const available = { status: "available", currentVersion, latestVersion: latest,
|
|
84
|
+
updateCommand: installChannel === "global" ? command + " update" : command + " update --help" };
|
|
81
85
|
const windowStart = now().getTime() - HOUR;
|
|
82
86
|
const recent = Object.fromEntries(Object.entries(state.notified_at ?? {}).filter(([, at]) => at > windowStart));
|
|
83
87
|
if (!channel || Object.hasOwn(recent, channel))
|
|
84
88
|
return await deliver(available);
|
|
85
89
|
const notice = command === "gd-cli"
|
|
86
|
-
? `gd-cli 有新版本 ${latest},当前版本为 ${currentVersion}
|
|
87
|
-
: `${command} ${latest} is available; current version is ${currentVersion}.
|
|
90
|
+
? `gd-cli 有新版本 ${latest},当前版本为 ${currentVersion}。${updateGuidance(installChannel, command)}`
|
|
91
|
+
: `${command} ${latest} is available; current version is ${currentVersion}. ${updateGuidance(installChannel, command)}`;
|
|
88
92
|
await deliver({ ...available, notice });
|
|
89
93
|
if (remember)
|
|
90
94
|
await save(file, { ...state, notified_at: { ...recent, [channel]: now().getTime() } }).catch(() => undefined);
|