@insmind/cli 1.5.12 → 1.5.13
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.
|
@@ -56,7 +56,7 @@ export function createCli(runtime, options) {
|
|
|
56
56
|
registerUpdateCommand(program, runtime);
|
|
57
57
|
registerTaskCommands(program, runtime);
|
|
58
58
|
assertAllLeafCommandsBound(program);
|
|
59
|
-
outputs.set(program, runtime
|
|
59
|
+
outputs.set(program, runtime);
|
|
60
60
|
if (runtime.analytics)
|
|
61
61
|
analyticsShutdown.set(program, () => runtime.analytics.shutdown());
|
|
62
62
|
return program;
|
|
@@ -75,7 +75,8 @@ export async function executeCli(options) {
|
|
|
75
75
|
await checkUpdateNotification(options.updateNotification, options.signal);
|
|
76
76
|
options.signal.throwIfAborted();
|
|
77
77
|
}
|
|
78
|
-
await options.telemetry.stage("output", async () => { await outputs.get(options.program)?.flush?.(); });
|
|
78
|
+
await options.telemetry.stage("output", async () => { await outputs.get(options.program)?.io.flush?.(); });
|
|
79
|
+
await outputs.get(options.program)?.tasks.outputCompleted();
|
|
79
80
|
if (!helpOnly)
|
|
80
81
|
await sendFinished(options, { outcome: "success" });
|
|
81
82
|
return 0;
|
|
@@ -108,7 +109,7 @@ export async function executeCli(options) {
|
|
|
108
109
|
catch (presenterError) {
|
|
109
110
|
await options.telemetry.stage("output", () => { throw presenterError; }).catch(() => undefined);
|
|
110
111
|
}
|
|
111
|
-
await options.telemetry.stage("output", async () => { await outputs.get(options.program)?.flush?.(); }).catch(() => undefined);
|
|
112
|
+
await options.telemetry.stage("output", async () => { await outputs.get(options.program)?.io.flush?.(); }).catch(() => undefined);
|
|
112
113
|
await sendFinished(options, outcome.kind === "interrupted"
|
|
113
114
|
? { outcome: "interrupted", error }
|
|
114
115
|
: {
|
|
@@ -98,7 +98,7 @@ export function createProductionRuntime(options = {}) {
|
|
|
98
98
|
spanIdFactory: () => randomBytes(8).toString("hex"),
|
|
99
99
|
runtime: { os: process.platform, arch: process.arch, nodeMajor: Number.parseInt(process.versions.node, 10) },
|
|
100
100
|
classifyError: error => classifyTelemetryError(error, { product }),
|
|
101
|
-
onEvent:
|
|
101
|
+
...(telemetrySink.enqueue ? { onEvent: (event) => telemetrySink.enqueue([event]) } : {})
|
|
102
102
|
});
|
|
103
103
|
// Explicit test transport enables SDK tests; test-mode child processes never emit real analytics.
|
|
104
104
|
const analytics = options.analytics ?? (telemetryEnvironment === "production" || options.windFetch
|
|
@@ -56,6 +56,7 @@ const LEASE_MS = 15_000;
|
|
|
56
56
|
export function createTaskUseCases(dependencies) {
|
|
57
57
|
const { text, commandName } = dependencies;
|
|
58
58
|
const telemetry = dependencies.telemetry;
|
|
59
|
+
let pendingOutput;
|
|
59
60
|
const warnedTasks = new Set();
|
|
60
61
|
const stage = (name, run) => telemetry ? telemetry.stage(name, run) : run();
|
|
61
62
|
function cacheWarning(id) {
|
|
@@ -71,21 +72,22 @@ export function createTaskUseCases(dependencies) {
|
|
|
71
72
|
let context = record.telemetry.context;
|
|
72
73
|
if (!record.telemetry.states?.length) {
|
|
73
74
|
const current = telemetry.creationContext();
|
|
74
|
-
context = { ...context, schema_version: "
|
|
75
|
+
context = { ...context, schema_version: "5",
|
|
75
76
|
...(current.tool_name ? { tool_name: current.tool_name } : {}),
|
|
76
77
|
...(current.model_id ? { model_id: current.model_id } : {}) };
|
|
77
78
|
record.telemetry.context = Object.freeze(context);
|
|
78
79
|
}
|
|
79
|
-
const
|
|
80
|
+
const failure = error === undefined ? {} : telemetry.taskFailure(error);
|
|
81
|
+
const make = (states = []) => {
|
|
80
82
|
const previous = states.at(-1);
|
|
81
|
-
if (
|
|
82
|
-
||
|
|
83
|
-
return
|
|
84
|
-
return { ...context, ...
|
|
85
|
-
schema_version: "
|
|
86
|
-
occurred_at_ms: at, started_at_ms: previous?.started_at_ms ?? record.telemetry?.request_sent?.occurred_at_ms ?? (state === "
|
|
83
|
+
if (states.some(event => event.schema_version === "5" && (event.result_state === "completed" || event.result_state === "success" && state === "failed"
|
|
84
|
+
|| event.result_state === state && (state !== "failed" || Object.entries(failure).every(([key, value]) => JSON.stringify(event[key]) === JSON.stringify(value))))))
|
|
85
|
+
return;
|
|
86
|
+
return { ...context, ...failure,
|
|
87
|
+
schema_version: "5", event_name: "task_state", result_state: state,
|
|
88
|
+
occurred_at_ms: at, started_at_ms: previous?.started_at_ms ?? record.telemetry?.request_sent?.occurred_at_ms ?? (state === "start" ? at : Date.parse(record.task.createdAt)),
|
|
87
89
|
task_revision: (previous?.task_revision ?? 0) + 1, record_seq: (previous?.task_revision ?? 0) + 1,
|
|
88
|
-
...(state === "completed" && record.task.result ? { result_types: resultTypes(record.task.result) } : {}) };
|
|
90
|
+
...((state === "success" || state === "completed") && record.task.result ? { result_types: resultTypes(record.task.result) } : {}) };
|
|
89
91
|
};
|
|
90
92
|
let event;
|
|
91
93
|
let writeConfirmed = false;
|
|
@@ -114,11 +116,6 @@ export function createTaskUseCases(dependencies) {
|
|
|
114
116
|
await telemetry.emit(event);
|
|
115
117
|
}
|
|
116
118
|
}
|
|
117
|
-
async function replay(record) {
|
|
118
|
-
// Old request_sent/result_ready records are readable, but are never emitted by this binary.
|
|
119
|
-
for (const event of record.telemetry?.states ?? [])
|
|
120
|
-
await telemetry?.emit(event);
|
|
121
|
-
}
|
|
122
119
|
function summary(record) {
|
|
123
120
|
const { result: _result, partialResult: _partial, ...task } = record.task;
|
|
124
121
|
if (!record.progress.detached && task.state === "running"
|
|
@@ -143,7 +140,7 @@ export function createTaskUseCases(dependencies) {
|
|
|
143
140
|
...(dependencies.creationVersion ? { cli_version: dependencies.creationVersion } : {}),
|
|
144
141
|
...(input.state.account ? { account_id: input.state.account.id } : {}), organization_id: input.state.organization.id } };
|
|
145
142
|
}
|
|
146
|
-
//
|
|
143
|
+
// Wind belongs to execution; result queries never call it.
|
|
147
144
|
const analytics = input.state.account ? await dependencies.analytics?.prepare({
|
|
148
145
|
userId: input.state.account.id, organizationId: input.state.organization.id
|
|
149
146
|
}).catch(() => undefined) : undefined;
|
|
@@ -221,7 +218,7 @@ export function createTaskUseCases(dependencies) {
|
|
|
221
218
|
const result = await input.run(async (progress) => {
|
|
222
219
|
if (progress.dispatchedAt !== undefined) {
|
|
223
220
|
dispatched = true;
|
|
224
|
-
await fact(scope, record, "
|
|
221
|
+
await fact(scope, record, "start", progress.dispatchedAt);
|
|
225
222
|
await analyticsFact("started");
|
|
226
223
|
return;
|
|
227
224
|
}
|
|
@@ -245,7 +242,7 @@ export function createTaskUseCases(dependencies) {
|
|
|
245
242
|
await stage("task.validate", async () => { finish(record, result); });
|
|
246
243
|
telemetry?.annotate({ result_state: record.task.state });
|
|
247
244
|
if (record.task.state === "completed") {
|
|
248
|
-
await fact(scope, record, "
|
|
245
|
+
await fact(scope, record, "success", dependencies.now().getTime());
|
|
249
246
|
await analyticsFact("completed");
|
|
250
247
|
}
|
|
251
248
|
try {
|
|
@@ -257,7 +254,7 @@ export function createTaskUseCases(dependencies) {
|
|
|
257
254
|
}
|
|
258
255
|
cacheWarning(record.task.taskId);
|
|
259
256
|
}
|
|
260
|
-
return { task: record.task, result };
|
|
257
|
+
return { task: record.task, result, record };
|
|
261
258
|
}
|
|
262
259
|
catch (error) {
|
|
263
260
|
clearInterval(timer);
|
|
@@ -280,21 +277,25 @@ export function createTaskUseCases(dependencies) {
|
|
|
280
277
|
if (detail)
|
|
281
278
|
record.task.note = [record.task.note, redactSensitiveText(detail)].filter(Boolean).join(" ");
|
|
282
279
|
telemetry?.annotate({ result_state: record.task.state });
|
|
283
|
-
if (dispatched)
|
|
284
|
-
await fact(scope, record,
|
|
280
|
+
if (dispatched && record.task.state !== "completed")
|
|
281
|
+
await fact(scope, record, "failed", dependencies.now().getTime(), error);
|
|
285
282
|
await stage("task.persist", save).catch(() => undefined);
|
|
286
283
|
throw error;
|
|
287
284
|
}
|
|
288
285
|
}
|
|
289
286
|
return {
|
|
290
287
|
async track(input) {
|
|
291
|
-
|
|
288
|
+
const execution = await execute(input, (record, result) => {
|
|
292
289
|
dependencies.validateResult?.(result);
|
|
293
290
|
record.task.state = "completed";
|
|
294
291
|
record.task.result = withoutResourceKeys(result);
|
|
295
292
|
if ("message" in result)
|
|
296
293
|
record.task.contextId = result.message.contextId;
|
|
297
|
-
})
|
|
294
|
+
});
|
|
295
|
+
if (input.executionMode !== "async") {
|
|
296
|
+
pendingOutput = { scope: taskScope(input.state), record: execution.record };
|
|
297
|
+
}
|
|
298
|
+
return execution.result;
|
|
298
299
|
},
|
|
299
300
|
async submit(input) {
|
|
300
301
|
return (await execute({ ...input, executionMode: "async" }, record => { record.progress.detached = true; })).task;
|
|
@@ -311,9 +312,10 @@ export function createTaskUseCases(dependencies) {
|
|
|
311
312
|
if (!record)
|
|
312
313
|
throw new TaskNotFoundError(text(`当前身份中没有该任务。请执行 ${commandName} task list 查找。`, `No task was found in the current identity context. Use ${commandName} task list to find it.`));
|
|
313
314
|
telemetry?.annotate({ cli_task_id: id, result_state: record.task.state });
|
|
314
|
-
await replay(record);
|
|
315
315
|
if (record.task.state === "completed" && record.task.result) {
|
|
316
|
-
|
|
316
|
+
const result = { ...record.task, result: await stage("task.authorize", () => dependencies.recovery.authorize(record.task.result, state, signal)) };
|
|
317
|
+
pendingOutput = { scope, record };
|
|
318
|
+
return result;
|
|
317
319
|
}
|
|
318
320
|
const task = summary(record);
|
|
319
321
|
if (task.state === "failed" || (task.state === "running" && !record.progress.detached))
|
|
@@ -329,7 +331,7 @@ export function createTaskUseCases(dependencies) {
|
|
|
329
331
|
}
|
|
330
332
|
if (result.state === "completed" || result.state === "failed") {
|
|
331
333
|
record.task = withoutResourceKeys(result);
|
|
332
|
-
await fact(scope, record, result.state, dependencies.now().getTime(), failure);
|
|
334
|
+
await fact(scope, record, result.state === "completed" ? "success" : "failed", dependencies.now().getTime(), failure);
|
|
333
335
|
}
|
|
334
336
|
telemetry?.annotate({ result_state: result.state });
|
|
335
337
|
// Store merging protects terminal results and facts against stale heartbeats.
|
|
@@ -345,7 +347,15 @@ export function createTaskUseCases(dependencies) {
|
|
|
345
347
|
cacheWarning(id);
|
|
346
348
|
}
|
|
347
349
|
}
|
|
350
|
+
if (result.state === "completed" && result.result)
|
|
351
|
+
pendingOutput = { scope, record };
|
|
348
352
|
return result;
|
|
353
|
+
},
|
|
354
|
+
async outputCompleted() {
|
|
355
|
+
const output = pendingOutput;
|
|
356
|
+
pendingOutput = undefined;
|
|
357
|
+
if (output)
|
|
358
|
+
await fact(output.scope, output.record, "completed", dependencies.now().getTime());
|
|
349
359
|
}
|
|
350
360
|
};
|
|
351
361
|
}
|
|
@@ -17,6 +17,7 @@ export function createTelemetryInvocation(options) {
|
|
|
17
17
|
let sequence = 0;
|
|
18
18
|
const context = {};
|
|
19
19
|
const events = [];
|
|
20
|
+
const published = new Set();
|
|
20
21
|
const failures = [];
|
|
21
22
|
function base() {
|
|
22
23
|
const mode = definition?.mode?.();
|
|
@@ -55,8 +56,11 @@ export function createTelemetryInvocation(options) {
|
|
|
55
56
|
return safe;
|
|
56
57
|
}
|
|
57
58
|
async function publish(event) {
|
|
59
|
+
if (!options.onEvent)
|
|
60
|
+
return;
|
|
58
61
|
try {
|
|
59
|
-
await options.onEvent
|
|
62
|
+
if (await options.onEvent(event) !== false)
|
|
63
|
+
published.add(event);
|
|
60
64
|
}
|
|
61
65
|
catch { /* Logging cannot fail the operation. */ }
|
|
62
66
|
}
|
|
@@ -132,7 +136,7 @@ export function createTelemetryInvocation(options) {
|
|
|
132
136
|
...(completion.remoteErrorCode === undefined ? {} : { remote_error_code: completion.remoteErrorCode }),
|
|
133
137
|
...(completion.remoteErrorBody === undefined ? {} : { remote_error_body: completion.remoteErrorBody })
|
|
134
138
|
} : {}) });
|
|
135
|
-
return events;
|
|
139
|
+
return events.filter(event => !published.has(event));
|
|
136
140
|
}
|
|
137
141
|
};
|
|
138
142
|
}
|
|
@@ -144,7 +144,8 @@ export function createSlsTelemetrySink(options) {
|
|
|
144
144
|
}
|
|
145
145
|
function enqueue(events, deadline) {
|
|
146
146
|
if (events.length === 0)
|
|
147
|
-
return writes;
|
|
147
|
+
return writes.then(() => true);
|
|
148
|
+
let accepted = true;
|
|
148
149
|
writes = writes.catch(() => undefined).then(() => locked(async () => {
|
|
149
150
|
await load(deadline);
|
|
150
151
|
for (const event of events) {
|
|
@@ -157,6 +158,7 @@ export function createSlsTelemetrySink(options) {
|
|
|
157
158
|
}
|
|
158
159
|
await trim(deadline);
|
|
159
160
|
}, deadline)).catch(error => {
|
|
161
|
+
accepted = false;
|
|
160
162
|
enqueueFailures++;
|
|
161
163
|
lastEnqueueError = error instanceof Error && error.message === "Local state lock timed out." ? "lock_timeout"
|
|
162
164
|
: error instanceof Error && error.message === "Telemetry delivery budget exhausted." ? "budget_exhausted" : "storage_error";
|
|
@@ -164,7 +166,7 @@ export function createSlsTelemetrySink(options) {
|
|
|
164
166
|
if (options.background && deadline === undefined)
|
|
165
167
|
void writes.then(() => { if (!sending)
|
|
166
168
|
void start(Math.min(Date.now() + BUDGET, exitDeadline)); });
|
|
167
|
-
return writes;
|
|
169
|
+
return writes.then(() => accepted);
|
|
168
170
|
}
|
|
169
171
|
let sending;
|
|
170
172
|
async function flush(deadline) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@insmind/cli",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.13",
|
|
4
4
|
"description": "insMind command-line interface for agents and people.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"@gaoding/cli": "workspace:*"
|
|
47
47
|
},
|
|
48
48
|
"gaodingRelease": {
|
|
49
|
-
"sourceCommit": "
|
|
50
|
-
"pipelineId": "
|
|
51
|
-
"pipelineUrl": "https://git.intra.gaoding.com/gtt/gaoding-cli/-/pipelines/
|
|
49
|
+
"sourceCommit": "3cfa7151f00ae7207dbb5d7148adaeb5b6c3a413",
|
|
50
|
+
"pipelineId": "221754",
|
|
51
|
+
"pipelineUrl": "https://git.intra.gaoding.com/gtt/gaoding-cli/-/pipelines/221754"
|
|
52
52
|
}
|
|
53
53
|
}
|