@insmind/cli 1.9.0 → 2.0.0

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 (69) hide show
  1. package/dist/bin/insmind-cli.js +32 -25
  2. package/dist/bin/task-worker.js +4 -1
  3. package/dist/src/analytics/device.js +2 -2
  4. package/dist/src/bootstrap/create-cli.js +10 -8
  5. package/dist/src/bootstrap/create-runtime.js +29 -23
  6. package/dist/src/bootstrap/run-task-worker.js +7 -2
  7. package/dist/src/bootstrap/validators.js +15 -6
  8. package/dist/src/cli/action-binding.js +39 -0
  9. package/dist/src/cli/agent-commands.js +8 -12
  10. package/dist/src/cli/dam-commands.js +6 -5
  11. package/dist/src/cli/editor-commands.js +10 -5
  12. package/dist/src/cli/errors.js +60 -12
  13. package/dist/src/cli/host-input.js +34 -0
  14. package/dist/src/cli/model-commands.js +4 -3
  15. package/dist/src/cli/observed-errors.js +3 -1
  16. package/dist/src/cli/tool-commands.js +7 -9
  17. package/dist/src/contracts/creation-input.js +20 -0
  18. package/dist/src/features/agent/creative-agent-adapter.js +37 -11
  19. package/dist/src/features/agent/creative-protocol.js +21 -19
  20. package/dist/src/features/agent/creative-stream.js +54 -6
  21. package/dist/src/features/agent/result-reader.js +3 -1
  22. package/dist/src/features/agent/use-cases.js +6 -31
  23. package/dist/src/features/auth/access-policy.js +1 -3
  24. package/dist/src/features/auth/credential-store.js +6 -10
  25. package/dist/src/features/auth/sso-service.js +28 -10
  26. package/dist/src/features/auth/state.js +6 -0
  27. package/dist/src/features/auth/use-cases.js +91 -32
  28. package/dist/src/features/credits/use-cases.js +1 -1
  29. package/dist/src/features/dam/asset-projection.js +10 -1
  30. package/dist/src/features/dam/dam-api-adapter.js +30 -15
  31. package/dist/src/features/dam/file-downloader.js +2 -1
  32. package/dist/src/features/dam/input.js +23 -0
  33. package/dist/src/features/dam/use-cases.js +39 -29
  34. package/dist/src/features/editor/bridge-client.js +1 -1
  35. package/dist/src/features/editor/use-cases.js +6 -8
  36. package/dist/src/features/org/use-cases.js +3 -3
  37. package/dist/src/features/skill/installer.js +24 -22
  38. package/dist/src/features/task/store.js +31 -17
  39. package/dist/src/features/task/task-background.js +67 -19
  40. package/dist/src/features/task/use-cases.js +131 -88
  41. package/dist/src/features/tool/canvas-media.js +82 -27
  42. package/dist/src/features/tool/canvas-models.js +21 -4
  43. package/dist/src/features/tool/canvas-tool-adapter.js +29 -20
  44. package/dist/src/features/tool/canvas-video.js +2 -4
  45. package/dist/src/features/tool/dynamic-schema.js +32 -63
  46. package/dist/src/features/tool/matting-billing.js +38 -26
  47. package/dist/src/features/tool/mns-catalog-adapter.js +9 -2
  48. package/dist/src/features/tool/scene-catalog-adapter.js +0 -1
  49. package/dist/src/features/tool/tool-api-adapter.js +19 -16
  50. package/dist/src/features/tool/use-cases.js +24 -35
  51. package/dist/src/platform/file-lock.js +58 -15
  52. package/dist/src/platform/input-uri.js +105 -0
  53. package/dist/src/platform/json-input.js +1 -1
  54. package/dist/src/platform/local-json-file.js +7 -4
  55. package/dist/src/platform/remote-error-evidence.js +23 -1
  56. package/dist/src/platform/safe-upload-file.js +24 -4
  57. package/dist/src/platform/schema-issues.js +18 -0
  58. package/dist/src/platform/signed-http-transport.js +95 -37
  59. package/dist/src/platform/text-output.js +55 -13
  60. package/dist/src/telemetry/failure-summary.js +53 -2
  61. package/dist/src/telemetry/host-diagnostics.js +95 -0
  62. package/dist/src/telemetry/invocation.js +107 -23
  63. package/dist/src/telemetry/process-errors.js +38 -4
  64. package/dist/src/telemetry/sls-sink.js +71 -26
  65. package/package.json +4 -4
  66. package/skills/insmind-cli/SKILL.md +1 -0
  67. package/skills/insmind-cli/references/editor.md +1 -1
  68. package/skills/insmind-cli/references/generation-constraints.md +3 -1
  69. package/skills/insmind-cli/references/tool.md +2 -3
@@ -2,22 +2,28 @@ import { createHash } from "node:crypto";
2
2
  import { readdir, readFile, unlink, mkdir, chmod } from "node:fs/promises";
3
3
  import { join } from "node:path";
4
4
  import { cleanDiagnostic } from "./sanitize.js";
5
+ import { safeFailureSummary } from "./failure-summary.js";
5
6
  import { createLocalJsonFile } from "../platform/local-json-file.js";
6
7
  import { withFileLock } from "../platform/file-lock.js";
7
8
  const TTL = 7 * 86_400_000;
8
9
  const CAPACITY = 10 * 1024 * 1024;
9
10
  const BUDGET = 2_000;
10
11
  export function eventKey(event) {
11
- const key = event.event_name === "task_state"
12
- ? [event.cli_name, event.env, event.cli_task_id, "task_state", Number(event.task_revision)]
13
- : event.event_name === "request_sent" || event.event_name === "result_ready"
14
- ? [event.cli_name, event.env, event.cli_task_id, event.event_name]
15
- : [event.cli_name, event.env, event.trace_id, event.process_role, Number(event.record_seq)];
12
+ const key = event.event_name === "command_step"
13
+ ? [event.cli_name, event.env, event.trace_id, event.step]
14
+ : [event.cli_name, event.env, event.trace_id, event.process_role, Number(event.record_seq)];
16
15
  return createHash("sha256").update(JSON.stringify(key)).digest("hex");
17
16
  }
18
17
  export function wireEvent(event) {
19
18
  const safe = cleanDiagnostic(event);
20
- const wire = {};
19
+ if ("diagnostic_summary" in safe) {
20
+ const summary = safeFailureSummary(safe.diagnostic_summary);
21
+ if (summary)
22
+ safe.diagnostic_summary = summary;
23
+ else
24
+ delete safe.diagnostic_summary;
25
+ }
26
+ const wire = { event_id: eventKey(safe) };
21
27
  for (const [key, value] of Object.entries(safe)) {
22
28
  if (value !== undefined)
23
29
  wire[key] = typeof value === "object" ? JSON.stringify(value) : String(value);
@@ -40,8 +46,12 @@ export function wireEvent(event) {
40
46
  break;
41
47
  }
42
48
  // Keep the envelope valid even for unexpectedly large identity or adapter fields.
43
- for (const [key, value] of Object.entries(wire))
44
- wire[key] = utf8Prefix(value, 1024);
49
+ for (const [key, value] of Object.entries(wire)) {
50
+ // The bounded summary is structured JSON and contains the primary
51
+ // correlation evidence. Slicing it would make every field unreadable.
52
+ if (key !== "diagnostic_summary")
53
+ wire[key] = utf8Prefix(value, 1024);
54
+ }
45
55
  }
46
56
  return wire;
47
57
  }
@@ -62,10 +72,13 @@ export function createSlsTelemetrySink(options) {
62
72
  let writes = Promise.resolve();
63
73
  let enqueueFailures = 0;
64
74
  let lastEnqueueError;
65
- const file = (id) => createLocalJsonFile({ directory: options.directory, filename: `${id}.json` });
75
+ let status = { count: 0, delivery_failures: 0 };
76
+ let healthReady = false;
77
+ const statusFile = () => createLocalJsonFile({ directory: options.directory, filename: "delivery-status.json", role: "sls_queue" });
78
+ const file = (id) => createLocalJsonFile({ directory: options.directory, filename: `${id}.json`, role: "sls_queue" });
66
79
  let exitDeadline = Infinity;
67
80
  const locked = (run, deadline) => options.directory
68
- ? withFileLock(join(options.directory, ".lock"), run, { deadline: Math.min(deadline ?? Infinity, exitDeadline) }) : run();
81
+ ? withFileLock(join(options.directory, ".lock"), run, { deadline: Math.min(deadline ?? Infinity, exitDeadline), action: "sls_queue" }) : run();
69
82
  function checkBudget(deadline) {
70
83
  if (Date.now() >= deadline)
71
84
  throw new Error("Telemetry delivery budget exhausted.");
@@ -76,6 +89,21 @@ export function createSlsTelemetrySink(options) {
76
89
  entries.clear();
77
90
  await mkdir(options.directory, { recursive: true, mode: 0o700 });
78
91
  await chmod(options.directory, 0o700);
92
+ let rawStatus;
93
+ try {
94
+ rawStatus = JSON.parse(await statusFile().readText() ?? "{}");
95
+ }
96
+ catch { /* A malformed health file must not prevent replaying intact events. */ }
97
+ if (rawStatus && typeof rawStatus === "object" && !Array.isArray(rawStatus)) {
98
+ const value = rawStatus;
99
+ const count = (key) => typeof value[key] === "number" && Number.isSafeInteger(value[key]) && value[key] >= 0 ? value[key] : 0;
100
+ status = { count: count("count"), delivery_failures: count("delivery_failures"),
101
+ ...(["interrupted_write", "corrupt", "expired", "capacity", "http_rejected"].includes(String(value.reason)) ? { reason: value.reason } : {}),
102
+ ...(["accepted", "http_rejected", "http_retryable", "network_error"].includes(String(value.result)) ? { result: value.result } : {}),
103
+ ...(typeof value.http_status === "number" && value.http_status >= 100 && value.http_status <= 599 ? { http_status: value.http_status } : {}),
104
+ ...(count("first_at_ms") ? { first_at_ms: count("first_at_ms") } : {}),
105
+ ...(count("last_at_ms") ? { last_at_ms: count("last_at_ms") } : {}) };
106
+ }
79
107
  for (const name of await readdir(options.directory)) {
80
108
  checkBudget(deadline);
81
109
  // All writers hold the same lock, so remaining atomic-write temporaries are orphaned.
@@ -90,7 +118,7 @@ export function createSlsTelemetrySink(options) {
90
118
  const raw = await readFile(join(options.directory, name), "utf8");
91
119
  try {
92
120
  const entry = JSON.parse(raw);
93
- if (!Number.isFinite(entry.queuedAt) || !entry.event || eventKey(entry.event) !== name.slice(0, -5))
121
+ if (entry.event?.schema_version !== "6" || !Number.isFinite(entry.queuedAt) || !entry.event || eventKey(entry.event) !== name.slice(0, -5))
94
122
  throw new Error();
95
123
  entries.set(name.slice(0, -5), entry);
96
124
  }
@@ -99,18 +127,16 @@ export function createSlsTelemetrySink(options) {
99
127
  await dropped("corrupt", 1);
100
128
  }
101
129
  }
130
+ healthReady = true;
131
+ }
132
+ async function saveStatus() {
133
+ // Health recording must never stop the original event acknowledgement/backoff path.
134
+ if (options.directory)
135
+ await statusFile().writeTextAtomically(JSON.stringify(status)).catch(() => undefined);
102
136
  }
103
137
  async function dropped(reason, count) {
104
- if (!options.directory)
105
- return;
106
- const status = createLocalJsonFile({ directory: options.directory, filename: "delivery-status.json" });
107
- let prior = {};
108
- try {
109
- prior = JSON.parse(await status.readText() ?? "{}");
110
- }
111
- catch { /* Replace corrupt diagnostic status. */ }
112
- await status.writeTextAtomically(JSON.stringify({ count: (prior.count ?? 0) + count,
113
- first_at_ms: prior.first_at_ms ?? now(), last_at_ms: now(), reason }));
138
+ status = { ...status, count: status.count + count, first_at_ms: status.first_at_ms ?? now(), last_at_ms: now(), reason };
139
+ await saveStatus();
114
140
  }
115
141
  async function remove(id) {
116
142
  entries.delete(id);
@@ -131,8 +157,8 @@ export function createSlsTelemetrySink(options) {
131
157
  }
132
158
  }
133
159
  let size = [...entries.values()].reduce((sum, e) => sum + Buffer.byteLength(JSON.stringify(e)), 0);
134
- const priority = (e) => e.event.event_name === "task_state" || e.event.event_name === "request_sent" || e.event.event_name === "result_ready" ? 2
135
- : "outcome" in e.event && e.event.outcome !== "success" ? 1 : 0;
160
+ const priority = (e) => e.event.event_name === "command_step" ? 2
161
+ : e.event.event_name === "host_diagnostic" || "outcome" in e.event && e.event.outcome !== "success" ? 1 : 0;
136
162
  for (const [id, entry] of [...entries].sort((a, b) => priority(a[1]) - priority(b[1]) || a[1].queuedAt - b[1].queuedAt)) {
137
163
  checkBudget(deadline);
138
164
  if (size <= (options.maxBytes ?? CAPACITY))
@@ -208,6 +234,11 @@ export function createSlsTelemetrySink(options) {
208
234
  return; // Original records remain safe for at-least-once replay.
209
235
  await locked(async () => {
210
236
  await load(deadline);
237
+ status = { ...status, delivery_failures: status.delivery_failures + (accepted ? 0 : 1),
238
+ result: accepted ? "accepted" : rejected ? "http_rejected" : response ? "http_retryable" : "network_error",
239
+ ...(response ? { http_status: response.status } : {}) };
240
+ if (!response)
241
+ delete status.http_status;
211
242
  for (const [id, original] of batch) {
212
243
  checkBudget(deadline);
213
244
  const entry = entries.get(id);
@@ -220,7 +251,9 @@ export function createSlsTelemetrySink(options) {
220
251
  nextAttempt: now() + Math.max(retryAfter, attempt === 0 ? 0 : Math.min(60_000, 1000 * 2 ** Math.min(6, original.attempts))) });
221
252
  }
222
253
  if (rejected)
223
- await dropped(`http_${response.status}`, batch.length);
254
+ await dropped("http_rejected", batch.length);
255
+ else
256
+ await saveStatus();
224
257
  }, deadline);
225
258
  if (!accepted && (retryAfter > 0 || rejected))
226
259
  return;
@@ -231,9 +264,21 @@ export function createSlsTelemetrySink(options) {
231
264
  return sending;
232
265
  }
233
266
  return { enqueue,
234
- // This snapshot describes enqueue attempts before final flush, not SLS acceptance.
267
+ async refreshDiagnostics() {
268
+ // Read persisted facts without triggering an extra send or adding business events.
269
+ const deadline = Date.now() + 100;
270
+ await writes;
271
+ await locked(() => load(deadline), deadline).catch(() => undefined);
272
+ },
273
+ // The final flush is observable by a later invocation, never retroactively on this event.
235
274
  diagnostics: () => ({ sls_enqueue_failures: enqueueFailures,
236
- ...(lastEnqueueError ? { sls_last_enqueue_error: lastEnqueueError } : {}) }),
275
+ ...(lastEnqueueError ? { sls_last_enqueue_error: lastEnqueueError } : {}),
276
+ ...(healthReady ? { sls_queue_size: entries.size,
277
+ ...(entries.size ? { sls_queue_oldest_age_ms: Math.max(0, now() - Math.min(...[...entries.values()].map(entry => entry.queuedAt))) } : {}),
278
+ sls_delivery_failures: status.delivery_failures, sls_dropped_events: status.count,
279
+ ...(status.result ? { sls_last_delivery_result: status.result } : {}),
280
+ ...(status.http_status ? { sls_last_delivery_http_status: status.http_status } : {}),
281
+ ...(status.reason ? { sls_last_drop_reason: status.reason } : {}) } : {}) }),
237
282
  async send(events) {
238
283
  const deadline = exitDeadline = Date.now() + BUDGET;
239
284
  await enqueue(events, deadline);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@insmind/cli",
3
- "version": "1.9.0",
3
+ "version": "2.0.0",
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": "2836058427780a95d4b9ed152f122b81997df34e",
51
- "pipelineId": "231960",
52
- "pipelineUrl": "https://git.intra.gaoding.com/gtt/gaoding-cli/-/pipelines/231960"
50
+ "sourceCommit": "216c910373e0a89ff902e655f3cda89cae32887b",
51
+ "pipelineId": "241612",
52
+ "pipelineUrl": "https://git.intra.gaoding.com/gtt/gaoding-cli/-/pipelines/241612"
53
53
  }
54
54
  }
@@ -7,6 +7,7 @@ description: Use when creating images, videos or text with insMind CLI, operatin
7
7
 
8
8
  ## Discover current capabilities on demand
9
9
 
10
+ - For `agent send`, `tool call` and `editor apply`, set the top-level `host_application` in the input JSON to the calling app, for example `workbuddy`, `qwenwork` or `trae`. Use `terminal` for direct terminal use.
10
11
  - Check `insmind-cli --version` on first use. If the entry point is unclear, read `insmind-cli --help`, follow the relevant command group, then read the chosen command's `--help` before execution. Examples here are not an exhaustive capability list.
11
12
  - For structured input, query `--schema` only where the command exposes it. Discover models, parameter choices, prices and resource IDs through current lists/details rather than old examples. Report missing support or failed discovery without silently replacing explicit user constraints.
12
13
  - Reuse help and static Schema within the same session and CLI path/version; refresh after changing the CLI. Query dynamic metadata when selecting capabilities or quoting prices for this task, and refresh relevant results after identity changes or an explicit mismatch. Avoid unrelated catalog scans.
@@ -20,7 +20,7 @@ Completion requires structural and visual verification followed by a successful
20
20
 
21
21
  1. Read `insmind-cli editor connect --help` and choose `insmind-cli editor connect [target]` for the user's intended work. Do not omit the target and create a Board when recovering an existing work. Browser login, loading, edit/save permissions and content checks must pass; stop editing on connection failure.
22
22
  2. Read `insmind-cli editor snapshot`. Base changes on complete elements from the latest Snapshot and change only intended fields. Submit full Updates, never patches.
23
- 3. Build a complete, ordered Action JSON array from the Schema and Snapshot. Run `insmind-cli editor apply --input actions.json`, or use `--input -` for stdin. Use short semantic IDs; Connector direction and targets must preserve business relationships.
23
+ 3. Build an object with `host_application` and an ordered `actions` array from the Schema and Snapshot. Run `insmind-cli editor apply --input actions.json`, or use `--input -` for stdin. Use short semantic IDs; Connector direction and targets must preserve business relationships.
24
24
  4. Read a fresh Snapshot after every Apply. For layout, text or Connector changes, run `insmind-cli editor screenshot --json` and view the actual PNG at its absolute `path`. A file's existence or an accepted Action does not prove correct rendering.
25
25
  5. After structural and visual checks pass, run `insmind-cli editor save --json` and wait for the original command. Do not interrupt during silent periods or issue concurrent Editor operations. Only success proves persistence; deliver the returned `workId` and public `url`, preserving environment parameters. Discover wait limits with `editor save --help`.
26
26
  6. Run `insmind-cli editor disconnect` after saving; disconnecting does not replace saving.
@@ -6,6 +6,7 @@ Generation constraints example:
6
6
 
7
7
  ```json
8
8
  {
9
+ "host_application": "<invoking application>",
9
10
  "message": {
10
11
  "parts": [
11
12
  { "text": "<user request>" },
@@ -22,10 +23,11 @@ Generation constraints example:
22
23
  }
23
24
  ```
24
25
 
25
- `arguments` can be supplied without `model`, allowing the service Agent to select one. With a model, the CLI validates the supplied arguments against live detail; do not fill every Tool-required parameter for an Agent request. Put prompt text in a Text Part and media in separate URL Parts, not in `arguments`. Preserve input Part order. Use `metadata.role` for `reference`, `first_frame` or `last_frame`; do not inject frame-role text. For example:
26
+ `arguments` can be supplied without `model`, allowing the service Agent to select one. With a model, the CLI forwards explicit controls and maps known editing aliases to their service fields. Put prompt text in a Text Part and media in separate URL Parts, not in `arguments`. Preserve input Part order. Use `metadata.role` for `reference`, `first_frame` or `last_frame`; do not inject frame-role text. For example:
26
27
 
27
28
  ```json
28
29
  {
30
+ "host_application": "<invoking application>",
29
31
  "message": {
30
32
  "parts": [
31
33
  { "text": "Generate a transition video" },
@@ -12,14 +12,13 @@ insmind-cli tool call <tool> --input request.json --async
12
12
  insmind-cli task get <taskId>
13
13
  ```
14
14
 
15
- `tool list` lists available Tools. Model discovery provides current descriptions, prices, estimated duration and structured parameters. Follow each parameter's `required`, `type` and `description`; for SELECT parameters use `options[].value`. Explicitly supply a required parameter's `default` when the user did not specify it. Read `usageDescription` for combinations such as video mode and frame/media requirements; individual fields cannot establish these rules. Do not freeze catalog values in prompts or scripts.
16
-
17
- Provide all required fields. Put width, height, resolution and similar requirements in dedicated structured parameters when available, rather than only in prompt text. `tool call <tool> --schema` selects required fields, allowed parameters and ranges by model. Use `model get` for step, defaults and cross-field rules in `usageDescription`. Fixed JSON commands also accept `--json`.
15
+ Read `insmind-cli tool call <tool> --schema` for the input shape and `model get` for the selected model's price and estimated duration. `required` describes required inputs and `default` identifies service defaults. A defaulted field can be omitted when the user did not select a value. Use `options[].value` for a listed option. Put dimensions and resolution in `width`, `height` and `resolution` where available, and preserve explicit user values. Read `usageDescription` for cross-field rules such as video mode and frame roles.
18
16
 
19
17
  Copy the returned `model` identifier into the top-level `model` field of request JSON (runtime `arguments.model`), alongside its parameters:
20
18
 
21
19
  ```json
22
20
  {
21
+ "host_application": "<invoking application>",
23
22
  "model": "<model>",
24
23
  "prompt": "<required prompt>",
25
24
  "<parameter>": "<value>"