@gaoding/cli 1.1.0 → 1.3.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 (65) hide show
  1. package/contracts/operations/task.get/input.schema.json +14 -0
  2. package/contracts/operations/task.get/output.schema.json +103 -0
  3. package/contracts/operations/task.list/input.schema.json +18 -0
  4. package/contracts/operations/task.list/output.schema.json +53 -0
  5. package/dist/bin/agent-worker.js +41 -0
  6. package/dist/bin/gd-cli.js +2 -1
  7. package/dist/bin/insmind-cli.js +60 -0
  8. package/dist/bin/postinstall.js +1 -1
  9. package/dist/src/bootstrap/create-cli.js +16 -4
  10. package/dist/src/bootstrap/create-runtime.js +190 -33
  11. package/dist/src/bootstrap/run-agent-worker.js +37 -0
  12. package/dist/src/bootstrap/validators.js +17 -5
  13. package/dist/src/cli/agent-commands.js +40 -14
  14. package/dist/src/cli/auth-commands.js +13 -10
  15. package/dist/src/cli/credits-command.js +23 -0
  16. package/dist/src/cli/dam-commands.js +70 -69
  17. package/dist/src/cli/editor-commands.js +12 -11
  18. package/dist/src/cli/errors.js +60 -9
  19. package/dist/src/cli/model-commands.js +6 -5
  20. package/dist/src/cli/presenter.js +24 -6
  21. package/dist/src/cli/task-commands.js +48 -0
  22. package/dist/src/cli/tool-commands.js +38 -14
  23. package/dist/src/cli/update-command.js +4 -3
  24. package/dist/src/features/agent/creative-agent-adapter.js +9 -3
  25. package/dist/src/features/agent/creative-protocol.js +5 -16
  26. package/dist/src/features/agent/creative-stream.js +12 -1
  27. package/dist/src/features/agent/filems-resource-auth-key-provider.js +23 -0
  28. package/dist/src/features/agent/resource-authorizer.js +47 -0
  29. package/dist/src/features/agent/result-reader.js +30 -0
  30. package/dist/src/features/agent/use-cases.js +98 -95
  31. package/dist/src/features/auth/credential-store.js +1 -1
  32. package/dist/src/features/auth/sso-service.js +3 -1
  33. package/dist/src/features/auth/use-cases.js +38 -12
  34. package/dist/src/features/credits/use-cases.js +52 -0
  35. package/dist/src/features/dam/storage-upload.js +1 -1
  36. package/dist/src/features/editor/bridge-process.js +11 -4
  37. package/dist/src/features/editor/session-state.js +1 -1
  38. package/dist/src/features/editor/session.js +14 -8
  39. package/dist/src/features/org/use-cases.js +7 -0
  40. package/dist/src/features/skill/bundled-skills.js +13 -5
  41. package/dist/src/features/task/agent-background.js +63 -0
  42. package/dist/src/features/task/store.js +97 -0
  43. package/dist/src/features/task/types.js +1 -0
  44. package/dist/src/features/task/use-cases.js +139 -0
  45. package/dist/src/features/tool/catalog.js +13 -13
  46. package/dist/src/features/tool/tool-api-adapter.js +53 -36
  47. package/dist/src/features/tool/use-cases.js +111 -108
  48. package/dist/src/features/update/latest-version.js +2 -2
  49. package/dist/src/features/update/update-notification.js +10 -3
  50. package/dist/src/features/update/update-service.js +57 -23
  51. package/dist/src/platform/resource-auth-key.js +1 -0
  52. package/dist/src/platform/signed-http-transport.js +1 -0
  53. package/dist/src/platform/task-observer.js +1 -0
  54. package/dist/src/product/billing.js +47 -0
  55. package/dist/src/product/config.js +85 -0
  56. package/dist/src/product/locale.js +38 -0
  57. package/dist/src/product/text.js +3 -0
  58. package/dist/src/telemetry/sls-sink.js +1 -2
  59. package/package.json +5 -5
  60. package/skills/gd-cli/SKILL.md +1 -1
  61. package/skills/gd-cli/references/agent.md +34 -0
  62. package/skills/gd-cli/references/creation.md +5 -73
  63. package/skills/gd-cli/references/errors.md +18 -2
  64. package/skills/gd-cli/references/generation-constraints.md +36 -0
  65. package/skills/gd-cli/references/tool.md +31 -0
@@ -0,0 +1,14 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "type": "object",
4
+ "additionalProperties": false,
5
+ "properties": {
6
+ "taskId": {
7
+ "type": "string",
8
+ "format": "uuid"
9
+ }
10
+ },
11
+ "required": [
12
+ "taskId"
13
+ ]
14
+ }
@@ -0,0 +1,103 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://gdcli.gaoding.com/contracts/operations/task.get/output.schema.json",
4
+ "title": "TaskResult",
5
+ "allOf": [
6
+ {
7
+ "if": {
8
+ "properties": {
9
+ "state": {
10
+ "const": "completed"
11
+ }
12
+ }
13
+ },
14
+ "then": {
15
+ "properties": {
16
+ "result": {}
17
+ },
18
+ "required": [
19
+ "result"
20
+ ]
21
+ },
22
+ "else": {
23
+ "not": {
24
+ "properties": {
25
+ "result": {}
26
+ },
27
+ "required": [
28
+ "result"
29
+ ]
30
+ }
31
+ }
32
+ }
33
+ ],
34
+ "type": "object",
35
+ "additionalProperties": false,
36
+ "required": [
37
+ "taskId",
38
+ "operation",
39
+ "label",
40
+ "createdAt",
41
+ "updatedAt",
42
+ "state"
43
+ ],
44
+ "properties": {
45
+ "taskId": {
46
+ "type": "string",
47
+ "format": "uuid"
48
+ },
49
+ "operation": {
50
+ "enum": [
51
+ "agent.send",
52
+ "tool.call"
53
+ ]
54
+ },
55
+ "label": {
56
+ "type": "string",
57
+ "maxLength": 200
58
+ },
59
+ "createdAt": {
60
+ "type": "string",
61
+ "format": "date-time"
62
+ },
63
+ "updatedAt": {
64
+ "type": "string",
65
+ "format": "date-time"
66
+ },
67
+ "state": {
68
+ "enum": [
69
+ "running",
70
+ "completed",
71
+ "failed",
72
+ "unknown"
73
+ ]
74
+ },
75
+ "contextId": {
76
+ "type": "string",
77
+ "minLength": 1
78
+ },
79
+ "note": {
80
+ "type": "string"
81
+ },
82
+ "result": {
83
+ "oneOf": [
84
+ {
85
+ "$ref": "../agent.send/output.schema.json"
86
+ },
87
+ {
88
+ "$ref": "../tool.call/output.schema.json"
89
+ }
90
+ ]
91
+ },
92
+ "partialResult": {
93
+ "oneOf": [
94
+ {
95
+ "$ref": "../agent.send/output.schema.json"
96
+ },
97
+ {
98
+ "$ref": "../tool.call/output.schema.json"
99
+ }
100
+ ]
101
+ }
102
+ }
103
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "type": "object",
4
+ "additionalProperties": false,
5
+ "properties": {
6
+ "limit": {
7
+ "type": "integer",
8
+ "minimum": 1,
9
+ "maximum": 100
10
+ },
11
+ "operation": {
12
+ "enum": [
13
+ "agent.send",
14
+ "tool.call"
15
+ ]
16
+ }
17
+ }
18
+ }
@@ -0,0 +1,53 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://gdcli.gaoding.com/contracts/operations/task.list/output.schema.json",
4
+ "title": "TaskListResult",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "required": [
8
+ "tasks"
9
+ ],
10
+ "properties": {
11
+ "tasks": {
12
+ "type": "array",
13
+ "items": {
14
+ "type": "object",
15
+ "additionalProperties": false,
16
+ "required": [
17
+ "taskId",
18
+ "operation",
19
+ "label",
20
+ "createdAt",
21
+ "updatedAt",
22
+ "state"
23
+ ],
24
+ "properties": {
25
+ "taskId": {
26
+ "$ref": "../task.get/output.schema.json#/properties/taskId"
27
+ },
28
+ "operation": {
29
+ "$ref": "../task.get/output.schema.json#/properties/operation"
30
+ },
31
+ "label": {
32
+ "$ref": "../task.get/output.schema.json#/properties/label"
33
+ },
34
+ "createdAt": {
35
+ "$ref": "../task.get/output.schema.json#/properties/createdAt"
36
+ },
37
+ "updatedAt": {
38
+ "$ref": "../task.get/output.schema.json#/properties/updatedAt"
39
+ },
40
+ "state": {
41
+ "$ref": "../task.get/output.schema.json#/properties/state"
42
+ },
43
+ "contextId": {
44
+ "$ref": "../task.get/output.schema.json#/properties/contextId"
45
+ },
46
+ "note": {
47
+ "$ref": "../task.get/output.schema.json#/properties/note"
48
+ }
49
+ }
50
+ }
51
+ }
52
+ }
53
+ }
@@ -0,0 +1,41 @@
1
+ // Private one-task process; not a public CLI command or a resident service.
2
+ import { once } from "node:events";
3
+ import { Readable } from "node:stream";
4
+ import { gaodingProduct, insmindProduct } from "../src/product/config.js";
5
+ import { createProductionRuntime } from "../src/bootstrap/create-runtime.js";
6
+ import { runAgentWorker } from "../src/bootstrap/run-agent-worker.js";
7
+ if (!process.send) {
8
+ process.exitCode = 2;
9
+ }
10
+ else {
11
+ const controller = new AbortController();
12
+ const interrupt = () => controller.abort(new Error("SIGINT"));
13
+ process.once("SIGINT", interrupt);
14
+ process.once("SIGTERM", interrupt);
15
+ const send = (message) => {
16
+ if (process.connected)
17
+ process.send?.(message, () => undefined);
18
+ };
19
+ try {
20
+ const [job] = await once(process, "message");
21
+ const product = job.product === "insmind" ? insmindProduct : gaodingProduct;
22
+ const endpoints = { ...product.endpoints };
23
+ for (const key of Object.keys(endpoints))
24
+ endpoints[key] = new URL(job.endpoints[key]);
25
+ const runtime = createProductionRuntime({
26
+ product, endpoints, homeDirectory: job.homeDirectory, locale: job.locale,
27
+ io: { input: Readable.from([]), stdout: { write() { } }, stderr: { write() { } } }
28
+ });
29
+ await runAgentWorker({ runtime, job, signal: controller.signal, send });
30
+ }
31
+ catch {
32
+ send({ type: "error", failure: { code: "TASK_WORKER_UNAVAILABLE", message: "The background task could not start. Check task list/get before submitting again." }, exitCode: 1 });
33
+ process.exitCode = 1;
34
+ }
35
+ finally {
36
+ if (process.connected)
37
+ process.disconnect();
38
+ process.removeListener("SIGINT", interrupt);
39
+ process.removeListener("SIGTERM", interrupt);
40
+ }
41
+ }
@@ -27,7 +27,8 @@ try {
27
27
  signal: controller.signal,
28
28
  telemetry: runtime.telemetry,
29
29
  telemetrySink: runtime.telemetrySink,
30
- updateNotification: runtime.updateNotification
30
+ updateNotification: runtime.updateNotification,
31
+ product: runtime.product
31
32
  });
32
33
  }
33
34
  catch (error) {
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env node
2
+ import { insmindProduct } from "../src/product/config.js";
3
+ import { localeOption } from "../src/product/locale.js";
4
+ const controller = new AbortController();
5
+ const interrupt = () => controller.abort(new Error("SIGINT"));
6
+ process.once("SIGINT", interrupt);
7
+ let runtime;
8
+ let mapCliError;
9
+ let redact;
10
+ try {
11
+ const [cliModule, runtimeModule, errorsModule, redactModule] = await Promise.all([
12
+ import("../src/bootstrap/create-cli.js"),
13
+ import("../src/bootstrap/create-runtime.js"),
14
+ import("../src/cli/errors.js"),
15
+ import("../src/platform/redact.js")
16
+ ]);
17
+ mapCliError = errorsModule.mapCliError;
18
+ redact = redactModule.redact;
19
+ const selectedLocale = localeOption(process.argv.slice(2));
20
+ runtime = runtimeModule.createProductionRuntime({
21
+ product: insmindProduct,
22
+ ...(selectedLocale === undefined ? {} : { locale: selectedLocale })
23
+ });
24
+ const program = cliModule.createCli(runtime, { signal: controller.signal });
25
+ process.exitCode = await cliModule.executeCli({
26
+ program,
27
+ argv: process.argv.slice(2),
28
+ presenter: runtime.presenter,
29
+ signal: controller.signal,
30
+ telemetry: runtime.telemetry,
31
+ telemetrySink: runtime.telemetrySink,
32
+ updateNotification: runtime.updateNotification,
33
+ product: runtime.product
34
+ });
35
+ }
36
+ catch (error) {
37
+ if (mapCliError === undefined || redact === undefined) {
38
+ process.stderr.write("INTERNAL_ERROR: CLI failed to start.\n");
39
+ process.exitCode = 1;
40
+ }
41
+ else {
42
+ const outcome = redact(mapCliError(error, { aborted: controller.signal.aborted, product: insmindProduct }));
43
+ if (runtime) {
44
+ runtime.presenter.error(outcome, { json: process.argv.includes("--json") });
45
+ }
46
+ else if (outcome.kind === "interrupted") {
47
+ process.stderr.write("Cancelled.\n");
48
+ }
49
+ else if (process.argv.includes("--json")) {
50
+ process.stderr.write(`${JSON.stringify({ error: outcome.failure })}\n`);
51
+ }
52
+ else {
53
+ process.stderr.write(`${outcome.failure.code}: ${outcome.failure.message}\n`);
54
+ }
55
+ process.exitCode = outcome.exitCode;
56
+ }
57
+ }
58
+ finally {
59
+ process.removeListener("SIGINT", interrupt);
60
+ }
@@ -12,7 +12,7 @@ export function isSupportedGlobalLifecycle(env) {
12
12
  return userAgent.startsWith("pnpm/")
13
13
  && env.npm_command === "add"
14
14
  && env.npm_lifecycle_event === "postinstall"
15
- && env.npm_package_name === "@gaoding/cli"
15
+ && (env.npm_package_name === "@gaoding/cli" || env.npm_package_name === "@insmind/cli")
16
16
  && /\/v\d+\/[0-9a-f]+-[0-9a-f]+-[0-9a-f]{16}$/u.test(initialDirectory);
17
17
  }
18
18
  export async function runPostinstall(options = {}) {
@@ -1,3 +1,4 @@
1
+ import { registerTaskCommands } from "../cli/task-commands.js";
1
2
  import { Command, CommanderError } from "commander";
2
3
  import { assertAllLeafCommandsBound, configureActionEnvironment } from "../cli/action-binding.js";
3
4
  import { registerAgentCommands } from "../cli/agent-commands.js";
@@ -9,12 +10,13 @@ import { registerModelCommands } from "../cli/model-commands.js";
9
10
  import { registerEditorCommands } from "../cli/editor-commands.js";
10
11
  import { registerDamCommands } from "../cli/dam-commands.js";
11
12
  import { registerUpdateCommand } from "../cli/update-command.js";
13
+ import { registerCreditsCommand } from "../cli/credits-command.js";
12
14
  import { redact } from "../platform/redact.js";
13
15
  export { assertAllLeafCommandsBound, bindAction } from "../cli/action-binding.js";
14
16
  export function createCli(runtime, options) {
15
17
  const program = new Command()
16
- .name("gd-cli")
17
- .description("稿定命令行工具")
18
+ .name(runtime.product.commandName)
19
+ .description(runtime.product.description)
18
20
  .version(runtime.version)
19
21
  .helpCommand(false)
20
22
  .showHelpAfterError(false)
@@ -25,6 +27,9 @@ export function createCli(runtime, options) {
25
27
  writeOut: runtime.io.writeOut,
26
28
  writeErr: () => undefined
27
29
  });
30
+ if (runtime.product.id === "insmind") {
31
+ program.option("--locale <locale>", "locale for service-owned business descriptions");
32
+ }
28
33
  configureActionEnvironment(program, {
29
34
  policies: runtime.accessPolicies,
30
35
  signal: options.signal,
@@ -32,13 +37,17 @@ export function createCli(runtime, options) {
32
37
  updateNotification: runtime.updateNotification
33
38
  });
34
39
  registerAuthCommands(program, runtime);
35
- registerOrgCommands(program, runtime);
40
+ if (runtime.product.exposesOrganizations)
41
+ registerOrgCommands(program, runtime);
42
+ else
43
+ registerCreditsCommand(program, runtime);
36
44
  registerAgentCommands(program, runtime);
37
45
  registerToolCommands(program, runtime);
38
46
  registerModelCommands(program, runtime);
39
47
  registerEditorCommands(program, runtime);
40
48
  registerDamCommands(program, runtime);
41
49
  registerUpdateCommand(program, runtime);
50
+ registerTaskCommands(program, runtime);
42
51
  assertAllLeafCommandsBound(program);
43
52
  return program;
44
53
  }
@@ -68,7 +77,10 @@ export async function executeCli(options) {
68
77
  // The original Commander error is mapped and presented below.
69
78
  }
70
79
  }
71
- const outcome = redact(mapCliError(error, { aborted: options.signal.aborted }));
80
+ const outcome = redact(mapCliError(error, {
81
+ aborted: options.signal.aborted,
82
+ ...(options.product ? { product: options.product } : {})
83
+ }));
72
84
  const telemetryError = classifyTelemetryError(error);
73
85
  const traceId = options.telemetry.selected
74
86
  ? options.telemetry.traceId