@insmind/cli 2.1.1 → 2.1.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.
Files changed (44) hide show
  1. package/README.md +30 -0
  2. package/dist/bin/sync-skill.js +33 -0
  3. package/dist/src/bootstrap/create-runtime.js +5 -1
  4. package/dist/src/bootstrap/validators.js +88 -152
  5. package/dist/src/cli/agent-commands.js +2 -2
  6. package/dist/src/cli/editor-commands.js +9 -7
  7. package/dist/src/cli/errors.js +4 -5
  8. package/dist/src/cli/host-input.js +3 -5
  9. package/dist/src/cli/presenter.js +4 -5
  10. package/dist/src/contracts/creation-input.js +20 -17
  11. package/dist/src/features/auth/credential-store.js +1 -0
  12. package/dist/src/features/dam/object-storage.js +2 -1
  13. package/dist/src/features/dam/use-cases.js +2 -2
  14. package/dist/src/features/editor/bridge-process.js +3 -2
  15. package/dist/src/features/editor/session-state.js +1 -0
  16. package/dist/src/features/task/store.js +65 -22
  17. package/dist/src/features/task/task-background.js +3 -2
  18. package/dist/src/features/tool/canvas-media.js +2 -3
  19. package/dist/src/features/tool/canvas-results.js +13 -6
  20. package/dist/src/features/tool/catalog.js +2 -23
  21. package/dist/src/features/tool/dynamic-schema.js +3 -6
  22. package/dist/src/features/tool/tool-definitions.js +23 -0
  23. package/dist/src/features/update/package-manager.js +124 -0
  24. package/dist/src/features/update/update-service.js +133 -67
  25. package/dist/src/platform/detached-spawn.js +9 -0
  26. package/dist/src/platform/file-lock.js +12 -4
  27. package/dist/src/platform/input-uri.js +23 -1
  28. package/dist/src/platform/local-json-file.js +97 -15
  29. package/dist/src/platform/open-browser.js +5 -2
  30. package/dist/src/platform/safe-upload-file.js +2 -3
  31. package/dist/src/platform/schema-compiler.js +16 -0
  32. package/dist/src/platform/windows-acl/LICENSE-mingw-w64 +43 -0
  33. package/dist/src/platform/windows-acl/arm64.node +0 -0
  34. package/dist/src/platform/windows-acl/ia32.node +0 -0
  35. package/dist/src/platform/windows-acl/x64.node +0 -0
  36. package/dist/src/platform/windows-host-job/arm64.exe +0 -0
  37. package/dist/src/platform/windows-host-job/ia32.exe +0 -0
  38. package/dist/src/platform/windows-host-job/sha256.json +7 -0
  39. package/dist/src/platform/windows-host-job/x64.exe +0 -0
  40. package/dist/src/platform/windows-private-state.js +72 -0
  41. package/dist/src/product/config.js +1 -1
  42. package/dist/src/telemetry/failure-summary.js +2 -2
  43. package/dist/src/telemetry/sls-sink.js +45 -28
  44. package/package.json +4 -4
@@ -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
+ }
@@ -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
+ }
@@ -1,4 +1,4 @@
1
- import { defaultToolDefinitions } from "../features/tool/catalog.js";
1
+ import { defaultToolDefinitions } from "../features/tool/tool-definitions.js";
2
2
  function freezeProduct(config) {
3
3
  Object.freeze(config.endpoints);
4
4
  for (const tool of config.tools)
@@ -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,52 @@ 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
- for (const name of await readdir(options.directory)) {
108
- checkBudget(deadline);
109
- // All writers hold the same lock, so remaining atomic-write temporaries are orphaned.
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);
123
+ }
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.
110
130
  if (/^(?:[a-f0-9]{64}|delivery-status)\.json\.tmp-[a-f0-9-]+$/u.test(name)) {
111
- await unlink(join(options.directory, name)).catch(() => undefined);
131
+ await unlink(join(directory, name)).catch(() => undefined);
112
132
  await dropped("interrupted_write", 1);
113
- continue;
114
- }
115
- if (!/^[a-f0-9]{64}\.json$/u.test(name))
116
- continue;
117
- // An unreadable valid record is not corrupt and must survive for replay.
118
- const raw = await readFile(join(options.directory, name), "utf8");
119
- try {
120
- const entry = JSON.parse(raw);
121
- if (entry.event?.schema_version !== "6" || !Number.isFinite(entry.queuedAt) || !entry.event || eventKey(entry.event) !== name.slice(0, -5))
122
- throw new Error();
123
- // Earlier v6 clients could queue input parameters and echoed Agent HTTP errors.
124
- const event = entry.event;
125
- if (event.event_name === "stage_finished") {
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);
132
133
  }
133
- catch {
134
- await unlink(join(options.directory, name)).catch(() => undefined);
135
- await dropped("corrupt", 1);
134
+ return;
135
+ }
136
+ try {
137
+ const entry = JSON.parse(raw);
138
+ if (entry.event?.schema_version !== "6" || !Number.isFinite(entry.queuedAt) || eventKey(entry.event) !== name.slice(0, -5))
139
+ throw new Error();
140
+ // Earlier v6 clients could queue input parameters and echoed Agent HTTP errors.
141
+ const event = entry.event;
142
+ if (event.event_name === "stage_finished") {
143
+ delete event.parameters;
144
+ const agent = event.operation === "agent.send" || (event.operation === "task.get" && !event.execution_protocol);
145
+ if (agent && Number(event.http_status) >= 400)
146
+ delete event.remote_error_body;
136
147
  }
148
+ entries.set(name.slice(0, -5), entry);
149
+ }
150
+ catch {
151
+ await unlink(join(directory, name)).catch(() => undefined);
152
+ await dropped("corrupt", 1);
137
153
  }
138
- healthReady = true;
139
154
  }
140
155
  async function saveStatus() {
141
156
  // Health recording must never stop the original event acknowledgement/backoff path.
@@ -197,7 +212,7 @@ export function createSlsTelemetrySink(options) {
197
212
  lastEnqueueError = error instanceof Error && error.message === "Local state lock timed out." ? "lock_timeout"
198
213
  : error instanceof Error && error.message === "Telemetry delivery budget exhausted." ? "budget_exhausted" : "storage_error";
199
214
  });
200
- if (options.background && deadline === undefined)
215
+ if (options.background && !options.reporterFlushes && deadline === undefined)
201
216
  void writes.then(() => { if (!sending)
202
217
  void start(Math.min(Date.now() + BUDGET, exitDeadline)); });
203
218
  return writes.then(() => accepted);
@@ -290,6 +305,8 @@ export function createSlsTelemetrySink(options) {
290
305
  async send(events) {
291
306
  const deadline = exitDeadline = Date.now() + BUDGET;
292
307
  await enqueue(events, deadline);
308
+ if (options.reporterFlushes)
309
+ return;
293
310
  if (sending)
294
311
  await sending;
295
312
  if (Date.now() < deadline)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@insmind/cli",
3
- "version": "2.1.1",
3
+ "version": "2.1.2",
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": "6bb95e37a8accaddd86c5219d536bd9db493ed32",
51
- "pipelineId": "245407",
52
- "pipelineUrl": "https://git.intra.gaoding.com/gtt/gaoding-cli/-/pipelines/245407"
50
+ "sourceCommit": "db01676824330fe8f15c190fe71b3516b8b1924e",
51
+ "pipelineId": "246753",
52
+ "pipelineUrl": "https://git.intra.gaoding.com/gtt/gaoding-cli/-/pipelines/246753"
53
53
  }
54
54
  }