@insmind/cli 2.1.1 → 2.1.3
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 +30 -0
- package/dist/bin/sync-skill.js +33 -0
- package/dist/src/bootstrap/create-runtime.js +5 -1
- package/dist/src/bootstrap/validators.js +88 -152
- package/dist/src/cli/agent-commands.js +2 -2
- package/dist/src/cli/editor-commands.js +9 -7
- package/dist/src/cli/errors.js +4 -5
- package/dist/src/cli/host-input.js +3 -5
- package/dist/src/cli/observed-errors.js +7 -3
- package/dist/src/cli/presenter.js +4 -5
- package/dist/src/contracts/creation-input.js +20 -17
- package/dist/src/features/auth/credential-store.js +1 -0
- package/dist/src/features/dam/object-storage.js +2 -1
- package/dist/src/features/dam/use-cases.js +2 -2
- package/dist/src/features/editor/bridge-process.js +3 -2
- package/dist/src/features/editor/session-state.js +1 -0
- package/dist/src/features/task/creation-refusal.js +3 -1
- package/dist/src/features/task/store.js +65 -22
- package/dist/src/features/task/task-background.js +3 -2
- package/dist/src/features/tool/canvas-media.js +2 -3
- package/dist/src/features/tool/canvas-results.js +13 -6
- package/dist/src/features/tool/catalog.js +2 -23
- package/dist/src/features/tool/dynamic-schema.js +3 -6
- package/dist/src/features/tool/tool-definitions.js +23 -0
- package/dist/src/features/update/package-manager.js +124 -0
- package/dist/src/features/update/update-service.js +133 -67
- package/dist/src/platform/detached-spawn.js +9 -0
- package/dist/src/platform/file-lock.js +12 -4
- package/dist/src/platform/input-uri.js +23 -1
- package/dist/src/platform/local-json-file.js +97 -15
- package/dist/src/platform/open-browser.js +5 -2
- package/dist/src/platform/safe-upload-file.js +2 -3
- package/dist/src/platform/schema-compiler.js +16 -0
- package/dist/src/platform/windows-acl/LICENSE-mingw-w64 +43 -0
- package/dist/src/platform/windows-acl/arm64.node +0 -0
- package/dist/src/platform/windows-acl/ia32.node +0 -0
- package/dist/src/platform/windows-acl/x64.node +0 -0
- package/dist/src/platform/windows-host-job/arm64.exe +0 -0
- package/dist/src/platform/windows-host-job/ia32.exe +0 -0
- package/dist/src/platform/windows-host-job/sha256.json +7 -0
- package/dist/src/platform/windows-host-job/x64.exe +0 -0
- package/dist/src/platform/windows-private-state.js +72 -0
- package/dist/src/product/config.js +1 -1
- package/dist/src/telemetry/failure-summary.js +2 -2
- package/dist/src/telemetry/sls-sink.js +48 -29
- package/package.json +4 -4
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"job-launcher.c": "8c79e1ed2a4eb51deb272299542795c4cab5d73ccdcc7e6351d6dba4c1481c0b",
|
|
3
|
+
"shell-start.h": "6db1ac78fa52269bb91ee4058079eb554ebe1c9f3823389ca94b3d18f54163b8",
|
|
4
|
+
"x64.exe": "d096ab181dba17e132ec7d4c51c1439118add01b6072cdef0b8a498269508614",
|
|
5
|
+
"arm64.exe": "16d1dd531462f37caa3758deeffb0c9754342a56767bb46b5797b6bca23bfc97",
|
|
6
|
+
"ia32.exe": "4346a09da68102b4cc81a113c9bba36c8ae4c0e22a89b9265e490842b10f8e8b"
|
|
7
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { close, closeSync, readFile } from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { join, toNamespacedPath } from "node:path";
|
|
4
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
5
|
+
import { promisify } from "node:util";
|
|
6
|
+
const read = promisify(readFile);
|
|
7
|
+
const closeFile = promisify(close);
|
|
8
|
+
const require = createRequire(import.meta.url);
|
|
9
|
+
const actions = { file: 0, directory: 1, create: 2 };
|
|
10
|
+
const systemCodes = {
|
|
11
|
+
2: "ENOENT", 3: "ENOENT", 5: "EACCES", 32: "EBUSY", 33: "EBUSY", 267: "ENOTDIR"
|
|
12
|
+
};
|
|
13
|
+
let open;
|
|
14
|
+
export function openWindowsState(path, action) {
|
|
15
|
+
open ??= require(`./windows-acl/${process.arch}.node`);
|
|
16
|
+
const fd = open(toNamespacedPath(path), actions[action]);
|
|
17
|
+
if (fd < 0)
|
|
18
|
+
throw Object.assign(new Error("Cannot secure local Windows state."), {
|
|
19
|
+
code: systemCodes[-fd] ?? "EIO", win32Code: -fd
|
|
20
|
+
});
|
|
21
|
+
return fd;
|
|
22
|
+
}
|
|
23
|
+
export function openWindowsStateReader(path) {
|
|
24
|
+
const fd = openWindowsState(path, "file");
|
|
25
|
+
return {
|
|
26
|
+
readFile: (encoding) => read(fd, encoding),
|
|
27
|
+
close: () => closeFile(fd)
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** Pin each managed directory below the caller's trusted home. A child path
|
|
31
|
+
* is never opened through an unchecked or replaceable parent junction. */
|
|
32
|
+
export function pinWindowsStateDirectories(home, components, create) {
|
|
33
|
+
const fds = [];
|
|
34
|
+
const release = () => { for (const fd of fds.reverse())
|
|
35
|
+
closeSync(fd); };
|
|
36
|
+
let path = home;
|
|
37
|
+
try {
|
|
38
|
+
for (const component of components) {
|
|
39
|
+
path = join(path, component);
|
|
40
|
+
fds.push(openWindowsState(path, create ? "create" : "directory"));
|
|
41
|
+
}
|
|
42
|
+
return release;
|
|
43
|
+
}
|
|
44
|
+
catch (cause) {
|
|
45
|
+
release();
|
|
46
|
+
throw cause;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export async function readWindowsPrivateText(path) {
|
|
50
|
+
const reader = openWindowsStateReader(path);
|
|
51
|
+
try {
|
|
52
|
+
return await reader.readFile("utf8");
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
await reader.close();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// MoveFileEx can briefly reject replacement while a reader holds the old file.
|
|
59
|
+
// Retry only the rename of the same prepared temporary file.
|
|
60
|
+
export async function retryWindowsStateRename(rename) {
|
|
61
|
+
for (const wait of [8, 24, 64, 128]) {
|
|
62
|
+
try {
|
|
63
|
+
return await rename();
|
|
64
|
+
}
|
|
65
|
+
catch (cause) {
|
|
66
|
+
if (!(cause instanceof Error && "code" in cause && ["EPERM", "EACCES", "EBUSY"].includes(String(cause.code))))
|
|
67
|
+
throw cause;
|
|
68
|
+
await delay(wait);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
await rename();
|
|
72
|
+
}
|
|
@@ -27,12 +27,12 @@ const enums = Object.fromEntries(Object.entries({
|
|
|
27
27
|
quotaDecisionSource: ["cli_precheck"], quotaUnit: ["gaodou"], quotaLimitScope: ["account", "member_period"],
|
|
28
28
|
outputWritePhase: ["write_sync", "write_callback", "stream_error"],
|
|
29
29
|
hostPhase: ["started", "finished"],
|
|
30
|
-
hostReason: ["authenticated", "unauthenticated", "version", "timeout", "output_limit", "host_signal", "stdout_closed", "spawn_failure", "cli_exit", "invalid_response"]
|
|
30
|
+
hostReason: ["authenticated", "unauthenticated", "version", "timeout", "output_limit", "host_signal", "stdout_closed", "spawn_failure", "cli_exit", "invalid_response", "helper_unavailable", "upgrade_required"]
|
|
31
31
|
}).map(([key, values]) => [key, new Set(values)]));
|
|
32
32
|
const nonnegativeIntegers = new Set(["streamFirstByteMs", "streamReceivedBytes", "lockWaitMs", "lockOwnerCount",
|
|
33
33
|
"lockOwnerPid", "lockContenderPid", "lockOwnerStartedAtMs", "lockOwnerAgeMs", "lockOwnerAcquiredAtMs", "lockOwnerHeldMs", "localProcessPid", "localParentPid", "workerPid", "downloadUrlCount", "mediaBytesRead", "requestTimeoutMs", "requestDurationMs",
|
|
34
34
|
"outputElapsedMs", "outputWriteCount", "outputAttemptedBytes", "outputAcknowledgedBytes", "outputPendingWrites", "outputBufferedBytes",
|
|
35
|
-
"hostElapsedMs", "hostTimeoutMs", "hostStartedAtMs", "hostProcessPid", "hostParentPid", "hostChildPid", "hostStdoutBytes", "hostStderrBytes"]);
|
|
35
|
+
"hostElapsedMs", "hostTimeoutMs", "hostShellStartedAtMs", "hostWorkerThreadId", "hostStartedAtMs", "hostProcessPid", "hostParentPid", "hostChildPid", "hostStdoutBytes", "hostStderrBytes"]);
|
|
36
36
|
const quotaNumbers = new Set(["quotaTotal", "quotaUsed", "quotaPending", "quotaMemberLimit", "quotaMemberUsed", "quotaAvailable", "quotaRequired"]);
|
|
37
37
|
/** Fixed diagnostic facts, never arbitrary response fields or error messages. */
|
|
38
38
|
export function safeFailureSummary(value) {
|
|
@@ -8,6 +8,7 @@ import { withFileLock } from "../platform/file-lock.js";
|
|
|
8
8
|
const TTL = 7 * 86_400_000;
|
|
9
9
|
const CAPACITY = 10 * 1024 * 1024;
|
|
10
10
|
const BUDGET = 2_000;
|
|
11
|
+
const QUEUE_READ_BATCH = 8;
|
|
11
12
|
export function eventKey(event) {
|
|
12
13
|
const key = event.event_name === "command_step"
|
|
13
14
|
? [event.cli_name, event.env, event.trace_id, event.step]
|
|
@@ -104,38 +105,54 @@ export function createSlsTelemetrySink(options) {
|
|
|
104
105
|
...(count("first_at_ms") ? { first_at_ms: count("first_at_ms") } : {}),
|
|
105
106
|
...(count("last_at_ms") ? { last_at_ms: count("last_at_ms") } : {}) };
|
|
106
107
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
108
|
+
const directory = options.directory;
|
|
109
|
+
const names = await readdir(directory);
|
|
110
|
+
for (let offset = 0; offset < names.length; offset += QUEUE_READ_BATCH) {
|
|
111
|
+
const batch = names.slice(offset, offset + QUEUE_READ_BATCH);
|
|
112
|
+
// Read independent files together under the same lock. Settle every
|
|
113
|
+
// started read before releasing it, including on timeout or I/O error.
|
|
114
|
+
const records = await Promise.allSettled(batch.map(async (name) => {
|
|
115
|
+
checkBudget(deadline);
|
|
116
|
+
return /^[a-f0-9]{64}\.json$/u.test(name) ? readFile(join(directory, name), "utf8") : undefined;
|
|
117
|
+
}));
|
|
118
|
+
for (const [index, result] of records.entries()) {
|
|
119
|
+
checkBudget(deadline);
|
|
120
|
+
if (result.status === "rejected")
|
|
121
|
+
throw result.reason; // Unreadable files survive for replay.
|
|
122
|
+
await restoreEntry(directory, batch[index], result.value);
|
|
114
123
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
//
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
delete event.parameters;
|
|
127
|
-
const agent = event.operation === "agent.send" || (event.operation === "task.get" && !event.execution_protocol);
|
|
128
|
-
if (agent && Number(event.http_status) >= 400)
|
|
129
|
-
delete event.remote_error_body;
|
|
130
|
-
}
|
|
131
|
-
entries.set(name.slice(0, -5), entry);
|
|
124
|
+
}
|
|
125
|
+
healthReady = true;
|
|
126
|
+
}
|
|
127
|
+
async function restoreEntry(directory, name, raw) {
|
|
128
|
+
if (raw === undefined) {
|
|
129
|
+
// All writers hold the same lock, so remaining write temporaries are orphaned.
|
|
130
|
+
if (/^(?:[a-f0-9]{64}|delivery-status)\.json\.tmp-[a-f0-9-]+$/u.test(name)) {
|
|
131
|
+
await unlink(join(directory, name)).catch(() => undefined);
|
|
132
|
+
// The health snapshot is not an event; its interrupted write loses no queued event.
|
|
133
|
+
if (!name.startsWith("delivery-status.json.tmp-"))
|
|
134
|
+
await dropped("interrupted_write", 1);
|
|
132
135
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
try {
|
|
139
|
+
const entry = JSON.parse(raw);
|
|
140
|
+
if (entry.event?.schema_version !== "6" || !Number.isFinite(entry.queuedAt) || eventKey(entry.event) !== name.slice(0, -5))
|
|
141
|
+
throw new Error();
|
|
142
|
+
// Earlier v6 clients could queue input parameters and echoed Agent HTTP errors.
|
|
143
|
+
const event = entry.event;
|
|
144
|
+
if (event.event_name === "stage_finished") {
|
|
145
|
+
delete event.parameters;
|
|
146
|
+
const agent = event.operation === "agent.send" || (event.operation === "task.get" && !event.execution_protocol);
|
|
147
|
+
if (agent && Number(event.http_status) >= 400)
|
|
148
|
+
delete event.remote_error_body;
|
|
136
149
|
}
|
|
150
|
+
entries.set(name.slice(0, -5), entry);
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
await unlink(join(directory, name)).catch(() => undefined);
|
|
154
|
+
await dropped("corrupt", 1);
|
|
137
155
|
}
|
|
138
|
-
healthReady = true;
|
|
139
156
|
}
|
|
140
157
|
async function saveStatus() {
|
|
141
158
|
// Health recording must never stop the original event acknowledgement/backoff path.
|
|
@@ -197,7 +214,7 @@ export function createSlsTelemetrySink(options) {
|
|
|
197
214
|
lastEnqueueError = error instanceof Error && error.message === "Local state lock timed out." ? "lock_timeout"
|
|
198
215
|
: error instanceof Error && error.message === "Telemetry delivery budget exhausted." ? "budget_exhausted" : "storage_error";
|
|
199
216
|
});
|
|
200
|
-
if (options.background && deadline === undefined)
|
|
217
|
+
if (options.background && !options.reporterFlushes && deadline === undefined)
|
|
201
218
|
void writes.then(() => { if (!sending)
|
|
202
219
|
void start(Math.min(Date.now() + BUDGET, exitDeadline)); });
|
|
203
220
|
return writes.then(() => accepted);
|
|
@@ -290,6 +307,8 @@ export function createSlsTelemetrySink(options) {
|
|
|
290
307
|
async send(events) {
|
|
291
308
|
const deadline = exitDeadline = Date.now() + BUDGET;
|
|
292
309
|
await enqueue(events, deadline);
|
|
310
|
+
if (options.reporterFlushes)
|
|
311
|
+
return;
|
|
293
312
|
if (sending)
|
|
294
313
|
await sending;
|
|
295
314
|
if (Date.now() < deadline)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@insmind/cli",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.3",
|
|
4
4
|
"description": "insMind command-line interface for agents and people.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
"@gaoding/cli": "workspace:*"
|
|
48
48
|
},
|
|
49
49
|
"gaodingRelease": {
|
|
50
|
-
"sourceCommit": "
|
|
51
|
-
"pipelineId": "
|
|
52
|
-
"pipelineUrl": "https://git.intra.gaoding.com/gtt/gaoding-cli/-/pipelines/
|
|
50
|
+
"sourceCommit": "e6cfcdd32450fc7a5753f11fddf6cf8b91298a17",
|
|
51
|
+
"pipelineId": "253026",
|
|
52
|
+
"pipelineUrl": "https://git.intra.gaoding.com/gtt/gaoding-cli/-/pipelines/253026"
|
|
53
53
|
}
|
|
54
54
|
}
|