taskmeld 0.1.1

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 (204) hide show
  1. package/LICENSE +18 -0
  2. package/README.md +172 -0
  3. package/README.zh-CN.md +172 -0
  4. package/dist/src/app/app-context-env.js +51 -0
  5. package/dist/src/app/create-app-context.js +127 -0
  6. package/dist/src/app/data-dir.js +29 -0
  7. package/dist/src/app/pipeline-config.js +105 -0
  8. package/dist/src/app/pipeline-plugin-config.js +2 -0
  9. package/dist/src/app/pipeline-registry.js +502 -0
  10. package/dist/src/app/pipeline-runtime.js +202 -0
  11. package/dist/src/app/runtime-store.js +151 -0
  12. package/dist/src/app/user-config.js +37 -0
  13. package/dist/src/artifacts/artifact-cleanup.js +192 -0
  14. package/dist/src/artifacts/artifact-index.js +262 -0
  15. package/dist/src/artifacts/artifact-rebuilder.js +120 -0
  16. package/dist/src/artifacts/storage-service.js +371 -0
  17. package/dist/src/cli/bootstrap.js +226 -0
  18. package/dist/src/cli/commands/agent.js +126 -0
  19. package/dist/src/cli/commands/artifact.js +175 -0
  20. package/dist/src/cli/commands/init.js +150 -0
  21. package/dist/src/cli/commands/pipeline/errors.js +37 -0
  22. package/dist/src/cli/commands/pipeline/result.js +179 -0
  23. package/dist/src/cli/commands/pipeline/selector.js +51 -0
  24. package/dist/src/cli/commands/pipeline/types.js +2 -0
  25. package/dist/src/cli/commands/pipeline/watch.js +67 -0
  26. package/dist/src/cli/commands/pipeline.js +339 -0
  27. package/dist/src/cli/commands/scheduler.js +81 -0
  28. package/dist/src/cli/commands/server.js +70 -0
  29. package/dist/src/cli/commands/system.js +21 -0
  30. package/dist/src/cli/errors.js +71 -0
  31. package/dist/src/cli/help.js +184 -0
  32. package/dist/src/cli/index.js +65 -0
  33. package/dist/src/cli/output.js +19 -0
  34. package/dist/src/cli/renderers/engine/json.js +67 -0
  35. package/dist/src/cli/renderers/engine/markdown.js +95 -0
  36. package/dist/src/cli/renderers/engine/types.js +2 -0
  37. package/dist/src/cli/renderers/engine/utils.js +32 -0
  38. package/dist/src/cli/renderers/index.js +27 -0
  39. package/dist/src/cli/renderers/specs/agent.js +78 -0
  40. package/dist/src/cli/renderers/specs/artifact.js +32 -0
  41. package/dist/src/cli/renderers/specs/index.js +36 -0
  42. package/dist/src/cli/renderers/specs/init.js +25 -0
  43. package/dist/src/cli/renderers/specs/pipeline.js +561 -0
  44. package/dist/src/cli/renderers/specs/scheduler.js +46 -0
  45. package/dist/src/cli/renderers/specs/server.js +38 -0
  46. package/dist/src/cli/renderers/specs/system.js +36 -0
  47. package/dist/src/cli/router.js +199 -0
  48. package/dist/src/cli/server-runtime-client.js +780 -0
  49. package/dist/src/cli/types.js +2 -0
  50. package/dist/src/gateway/frame-sanitizer.js +78 -0
  51. package/dist/src/gateway/gateway-client.js +462 -0
  52. package/dist/src/gateway/index.js +18 -0
  53. package/dist/src/gateway/types.js +2 -0
  54. package/dist/src/index.js +123 -0
  55. package/dist/src/logs/run-log-reader.js +141 -0
  56. package/dist/src/logs/run-log-service.js +42 -0
  57. package/dist/src/logs/run-log-types.js +2 -0
  58. package/dist/src/pipeline/agent-activity.js +191 -0
  59. package/dist/src/pipeline/artifact-storage.js +208 -0
  60. package/dist/src/pipeline/diagnostics/dependency-diagnostic.js +105 -0
  61. package/dist/src/pipeline/diagnostics/index.js +6 -0
  62. package/dist/src/pipeline/dispatch/pipeline-inbound-queue.js +215 -0
  63. package/dist/src/pipeline/dispatch/pipeline-link-dispatcher.js +66 -0
  64. package/dist/src/pipeline/dispatch/pipeline-link-store.js +94 -0
  65. package/dist/src/pipeline/dispatch/pipeline-queue-drainer.js +71 -0
  66. package/dist/src/pipeline/execution/dependency-check.js +52 -0
  67. package/dist/src/pipeline/execution/execution-result.js +2 -0
  68. package/dist/src/pipeline/execution/group-item-executor.js +128 -0
  69. package/dist/src/pipeline/execution/index.js +5 -0
  70. package/dist/src/pipeline/execution/node-item-executor.js +58 -0
  71. package/dist/src/pipeline/execution/node-runner.js +159 -0
  72. package/dist/src/pipeline/execution/readiness-state.js +10 -0
  73. package/dist/src/pipeline/execution/reject-handler.js +94 -0
  74. package/dist/src/pipeline/execution/rejected-artifact-archiver.js +45 -0
  75. package/dist/src/pipeline/execution/route-item-manager.js +253 -0
  76. package/dist/src/pipeline/execution/run-abort-controller.js +66 -0
  77. package/dist/src/pipeline/execution/run-state-helpers.js +257 -0
  78. package/dist/src/pipeline/execution/service.js +165 -0
  79. package/dist/src/pipeline/execution/session-registry.js +96 -0
  80. package/dist/src/pipeline/execution/structured-node-runner.js +411 -0
  81. package/dist/src/pipeline/execution-status.js +96 -0
  82. package/dist/src/pipeline/execution-timeout.js +21 -0
  83. package/dist/src/pipeline/identity/index.js +32 -0
  84. package/dist/src/pipeline/identity/types.js +2 -0
  85. package/dist/src/pipeline/item-batch-controller.js +227 -0
  86. package/dist/src/pipeline/output/pipeline-output-resolver.js +91 -0
  87. package/dist/src/pipeline/output/pipeline-output-store.js +60 -0
  88. package/dist/src/pipeline/runtime-model.js +173 -0
  89. package/dist/src/pipeline/scheduler/dependency-state.js +144 -0
  90. package/dist/src/pipeline/scheduler-service.js +314 -0
  91. package/dist/src/pipeline/state/group-item-state.js +50 -0
  92. package/dist/src/pipeline/state/group-run-state.js +41 -0
  93. package/dist/src/pipeline/state/index.js +20 -0
  94. package/dist/src/pipeline/state/node-item-state.js +67 -0
  95. package/dist/src/pipeline/state/node-run-state.js +51 -0
  96. package/dist/src/pipeline/state/types.js +2 -0
  97. package/dist/src/pipeline/state-machine.js +101 -0
  98. package/dist/src/pipeline/structured-output/contract.js +133 -0
  99. package/dist/src/pipeline/structured-output/index.js +22 -0
  100. package/dist/src/pipeline/structured-output/parser.js +214 -0
  101. package/dist/src/pipeline/structured-output/prompt.js +290 -0
  102. package/dist/src/pipeline/structured-output/waiter.js +139 -0
  103. package/dist/src/pipeline/template.js +135 -0
  104. package/dist/src/pipeline/timeline-log-store.js +57 -0
  105. package/dist/src/pipeline/tool-activity.js +94 -0
  106. package/dist/src/pipeline/types/pipeline-link.js +7 -0
  107. package/dist/src/pipeline/types/pipeline-output.js +11 -0
  108. package/dist/src/pipeline/types/workflow.js +2 -0
  109. package/dist/src/pipeline/workflow/branch-rules.js +74 -0
  110. package/dist/src/pipeline/workflow/defaults.js +48 -0
  111. package/dist/src/pipeline/workflow/io.js +89 -0
  112. package/dist/src/pipeline/workflow/normalize.js +347 -0
  113. package/dist/src/pipeline/workflow/routes.js +16 -0
  114. package/dist/src/pipeline/workflow/template-mapper.js +113 -0
  115. package/dist/src/pipeline/workflow/validate.js +312 -0
  116. package/dist/src/pipeline/workflow-graph.js +165 -0
  117. package/dist/src/server/api-handler.js +163 -0
  118. package/dist/src/server/http-utils.js +34 -0
  119. package/dist/src/server/middleware.js +61 -0
  120. package/dist/src/server/router.js +105 -0
  121. package/dist/src/server/routes/agents.js +189 -0
  122. package/dist/src/server/routes/artifacts.js +163 -0
  123. package/dist/src/server/routes/gateway.js +18 -0
  124. package/dist/src/server/routes/health.js +16 -0
  125. package/dist/src/server/routes/logs.js +73 -0
  126. package/dist/src/server/routes/pipeline-batch.js +163 -0
  127. package/dist/src/server/routes/pipeline-diagnostics.js +33 -0
  128. package/dist/src/server/routes/pipeline-identity.js +24 -0
  129. package/dist/src/server/routes/pipeline-links.js +117 -0
  130. package/dist/src/server/routes/pipeline-outputs.js +27 -0
  131. package/dist/src/server/routes/pipeline-queue.js +62 -0
  132. package/dist/src/server/routes/pipeline-runtime.js +162 -0
  133. package/dist/src/server/routes/pipeline-scheduler.js +69 -0
  134. package/dist/src/server/routes/pipeline-workflow.js +180 -0
  135. package/dist/src/server/routes/pipelines.js +96 -0
  136. package/dist/src/server/routes/sessions.js +244 -0
  137. package/dist/src/server/routes/timeline.js +14 -0
  138. package/dist/src/server/serve-static.js +42 -0
  139. package/dist/src/server/types.js +2 -0
  140. package/dist/src/services/agent-service.js +79 -0
  141. package/dist/src/services/artifact-service.js +74 -0
  142. package/dist/src/services/gateway-read-helpers.js +10 -0
  143. package/dist/src/services/index.js +23 -0
  144. package/dist/src/services/pipeline-service.js +529 -0
  145. package/dist/src/services/pipeline-status.js +93 -0
  146. package/dist/src/services/read-services.js +60 -0
  147. package/dist/src/services/scheduler-service.js +37 -0
  148. package/dist/src/services/session-service.js +227 -0
  149. package/dist/src/services/system-service.js +26 -0
  150. package/dist/src/transport/ws-broker.js +48 -0
  151. package/dist/src/utils/array.js +17 -0
  152. package/dist/src/utils/guards.js +5 -0
  153. package/dist/src/utils/session.js +60 -0
  154. package/dist/src/version.js +5 -0
  155. package/package.json +61 -0
  156. package/web/dist/assets/index-CWnfhkn-.js +65 -0
  157. package/web/dist/assets/index-gZ0xOfSO.css +1 -0
  158. package/web/dist/assets/jetbrains-mono-cyrillic-400-normal-BEIGL1Tu.woff2 +0 -0
  159. package/web/dist/assets/jetbrains-mono-cyrillic-400-normal-ugxPyKxw.woff +0 -0
  160. package/web/dist/assets/jetbrains-mono-cyrillic-500-normal-DJqRU3vO.woff +0 -0
  161. package/web/dist/assets/jetbrains-mono-cyrillic-500-normal-DmUKJPL_.woff2 +0 -0
  162. package/web/dist/assets/jetbrains-mono-cyrillic-700-normal-BWTpRfYl.woff2 +0 -0
  163. package/web/dist/assets/jetbrains-mono-cyrillic-700-normal-CEoEElIJ.woff +0 -0
  164. package/web/dist/assets/jetbrains-mono-greek-400-normal-B9oWc5Lo.woff +0 -0
  165. package/web/dist/assets/jetbrains-mono-greek-400-normal-C190GLew.woff2 +0 -0
  166. package/web/dist/assets/jetbrains-mono-greek-500-normal-D7SFKleX.woff +0 -0
  167. package/web/dist/assets/jetbrains-mono-greek-500-normal-JpySY46c.woff2 +0 -0
  168. package/web/dist/assets/jetbrains-mono-greek-700-normal-C6CZE3T8.woff2 +0 -0
  169. package/web/dist/assets/jetbrains-mono-greek-700-normal-DEigVDxa.woff +0 -0
  170. package/web/dist/assets/jetbrains-mono-latin-400-normal-6-qcROiO.woff +0 -0
  171. package/web/dist/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
  172. package/web/dist/assets/jetbrains-mono-latin-500-normal-BWZEU5yA.woff2 +0 -0
  173. package/web/dist/assets/jetbrains-mono-latin-500-normal-CJOVTJB7.woff +0 -0
  174. package/web/dist/assets/jetbrains-mono-latin-700-normal-BYuf6tUa.woff2 +0 -0
  175. package/web/dist/assets/jetbrains-mono-latin-700-normal-D3wTyLJW.woff +0 -0
  176. package/web/dist/assets/jetbrains-mono-latin-ext-400-normal-Bc8Ftmh3.woff2 +0 -0
  177. package/web/dist/assets/jetbrains-mono-latin-ext-400-normal-fXTG6kC5.woff +0 -0
  178. package/web/dist/assets/jetbrains-mono-latin-ext-500-normal-Cut-4mMH.woff2 +0 -0
  179. package/web/dist/assets/jetbrains-mono-latin-ext-500-normal-ckzbgY84.woff +0 -0
  180. package/web/dist/assets/jetbrains-mono-latin-ext-700-normal-CZipNAKV.woff2 +0 -0
  181. package/web/dist/assets/jetbrains-mono-latin-ext-700-normal-CxPITLHs.woff +0 -0
  182. package/web/dist/assets/jetbrains-mono-vietnamese-400-normal-CqNFfHCs.woff +0 -0
  183. package/web/dist/assets/jetbrains-mono-vietnamese-500-normal-DNRqzVM1.woff +0 -0
  184. package/web/dist/assets/jetbrains-mono-vietnamese-700-normal-BDLVIk2r.woff +0 -0
  185. package/web/dist/assets/space-grotesk-latin-400-normal-BnQMeOim.woff +0 -0
  186. package/web/dist/assets/space-grotesk-latin-400-normal-CJ-V5oYT.woff2 +0 -0
  187. package/web/dist/assets/space-grotesk-latin-500-normal-CNSSEhBt.woff +0 -0
  188. package/web/dist/assets/space-grotesk-latin-500-normal-lFbtlQH6.woff2 +0 -0
  189. package/web/dist/assets/space-grotesk-latin-700-normal-CwsQ-cCU.woff +0 -0
  190. package/web/dist/assets/space-grotesk-latin-700-normal-RjhwGPKo.woff2 +0 -0
  191. package/web/dist/assets/space-grotesk-latin-ext-400-normal-CfP_5XZW.woff2 +0 -0
  192. package/web/dist/assets/space-grotesk-latin-ext-400-normal-DRPE3kg4.woff +0 -0
  193. package/web/dist/assets/space-grotesk-latin-ext-500-normal-3dgZTiw9.woff +0 -0
  194. package/web/dist/assets/space-grotesk-latin-ext-500-normal-DUe3BAxM.woff2 +0 -0
  195. package/web/dist/assets/space-grotesk-latin-ext-700-normal-BQnZhY3m.woff2 +0 -0
  196. package/web/dist/assets/space-grotesk-latin-ext-700-normal-HVCqSBdx.woff +0 -0
  197. package/web/dist/assets/space-grotesk-vietnamese-400-normal-B7xT_GF5.woff2 +0 -0
  198. package/web/dist/assets/space-grotesk-vietnamese-400-normal-BIWiOVfw.woff +0 -0
  199. package/web/dist/assets/space-grotesk-vietnamese-500-normal-BTqKIpxg.woff +0 -0
  200. package/web/dist/assets/space-grotesk-vietnamese-500-normal-BmEvtly_.woff2 +0 -0
  201. package/web/dist/assets/space-grotesk-vietnamese-700-normal-DMty7AZE.woff2 +0 -0
  202. package/web/dist/assets/space-grotesk-vietnamese-700-normal-Duxec5Rn.woff +0 -0
  203. package/web/dist/favicon.svg +10 -0
  204. package/web/dist/index.html +14 -0
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.serverRenderSpecs = void 0;
4
+ const utils_1 = require("../engine/utils");
5
+ const kv = (payload, field, key) => ({
6
+ field,
7
+ value: payload[key] ?? "-",
8
+ });
9
+ const ensureRows = (data) => {
10
+ const p = (0, utils_1.readRecord)(data);
11
+ return [kv(p, "OK", "ok"), kv(p, "Action", "action"), kv(p, "Endpoint", "endpoint"), kv(p, "Reused", "reused"), kv(p, "PID", "pid"), kv(p, "Started At", "startedAt")];
12
+ };
13
+ const statusRows = (data) => {
14
+ const p = (0, utils_1.readRecord)(data);
15
+ return [kv(p, "OK", "ok"), kv(p, "Endpoint", "endpoint"), kv(p, "Ready", "ready"), kv(p, "Metadata Present", "metadataPresent"), kv(p, "PID", "pid"), kv(p, "PID Running", "pidRunning"), kv(p, "Started At", "startedAt")];
16
+ };
17
+ exports.serverRenderSpecs = {
18
+ "server.ensure": {
19
+ kind: "detail",
20
+ title: "Server Ensure",
21
+ sections: [{ title: "Summary", kind: "key-value", rows: ensureRows }],
22
+ },
23
+ "server.start": {
24
+ kind: "detail",
25
+ title: "Server Start",
26
+ sections: [{ title: "Summary", kind: "key-value", rows: ensureRows }],
27
+ },
28
+ "server.status": {
29
+ kind: "detail",
30
+ title: "Server Status",
31
+ sections: [{ title: "Summary", kind: "key-value", rows: statusRows }],
32
+ },
33
+ "server.stop": {
34
+ kind: "detail",
35
+ title: "Server Stop",
36
+ sections: [{ title: "Summary", kind: "key-value", rows: ensureRows }],
37
+ },
38
+ };
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.systemRenderSpecs = void 0;
4
+ const utils_1 = require("../engine/utils");
5
+ exports.systemRenderSpecs = {
6
+ "system.snapshot": {
7
+ kind: "detail",
8
+ title: "System Snapshot",
9
+ sections: [
10
+ {
11
+ title: "Summary",
12
+ kind: "key-value",
13
+ rows: (data) => {
14
+ const snapshot = (0, utils_1.readRecord)(data);
15
+ const pipelines = (0, utils_1.asArray)(snapshot.pipelines);
16
+ return [
17
+ { field: "Generated At", value: (0, utils_1.pickText)(snapshot.generatedAt) },
18
+ { field: "Pipeline Count", value: pipelines.length },
19
+ ];
20
+ },
21
+ },
22
+ {
23
+ title: "Pipelines",
24
+ kind: "table",
25
+ columns: [
26
+ { title: "ID", render: (r) => r.id ?? r.pipelineId ?? "-" },
27
+ { title: "Title", render: (r) => r.title ?? r.name ?? "-" },
28
+ ],
29
+ rows: (data) => {
30
+ const snapshot = (0, utils_1.readRecord)(data);
31
+ return (0, utils_1.asArray)(snapshot.pipelines);
32
+ },
33
+ },
34
+ ],
35
+ },
36
+ };
@@ -0,0 +1,199 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.getRouteDefinition = exports.resolveRoute = exports.CLI_ROUTES = void 0;
37
+ const errors_1 = require("./errors");
38
+ const agentCommands = __importStar(require("./commands/agent"));
39
+ const artifactCommands = __importStar(require("./commands/artifact"));
40
+ const initCommands = __importStar(require("./commands/init"));
41
+ const pipelineCommands = __importStar(require("./commands/pipeline"));
42
+ const schedulerCommands = __importStar(require("./commands/scheduler"));
43
+ const serverCommands = __importStar(require("./commands/server"));
44
+ const systemCommands = __importStar(require("./commands/system"));
45
+ const help_1 = require("./help");
46
+ const collectRoutesFromModule = (moduleExports) => {
47
+ // 只聚合命令模块导出的 *Routes,router 不再内联维护路由定义。
48
+ return Object.entries(moduleExports)
49
+ .filter(([exportName, value]) => exportName.endsWith("Routes") && Array.isArray(value))
50
+ .flatMap(([, value]) => value);
51
+ };
52
+ exports.CLI_ROUTES = [
53
+ ...collectRoutesFromModule(initCommands),
54
+ ...collectRoutesFromModule(systemCommands),
55
+ ...collectRoutesFromModule(serverCommands),
56
+ ...collectRoutesFromModule(pipelineCommands),
57
+ ...collectRoutesFromModule(agentCommands),
58
+ ...collectRoutesFromModule(artifactCommands),
59
+ ...collectRoutesFromModule(schedulerCommands),
60
+ ];
61
+ const parseFlagsAndArgs = (argv) => {
62
+ const args = [];
63
+ const flags = {};
64
+ let index = 0;
65
+ while (index < argv.length) {
66
+ const token = argv[index];
67
+ if (token === "-h") {
68
+ flags.help = true;
69
+ flags.h = true;
70
+ index += 1;
71
+ continue;
72
+ }
73
+ if (token === "-f") {
74
+ const nextToken = argv[index + 1];
75
+ if (nextToken && !nextToken.startsWith("-")) {
76
+ flags.format = nextToken;
77
+ index += 2;
78
+ continue;
79
+ }
80
+ flags.format = true;
81
+ index += 1;
82
+ continue;
83
+ }
84
+ if (!token.startsWith("--")) {
85
+ args.push(token);
86
+ index += 1;
87
+ continue;
88
+ }
89
+ const normalized = token.slice(2).trim();
90
+ if (!normalized) {
91
+ index += 1;
92
+ continue;
93
+ }
94
+ const equalIndex = normalized.indexOf("=");
95
+ if (equalIndex >= 0) {
96
+ const key = normalized.slice(0, equalIndex).trim();
97
+ const value = normalized.slice(equalIndex + 1).trim();
98
+ if (key)
99
+ flags[key] = value;
100
+ index += 1;
101
+ continue;
102
+ }
103
+ const nextToken = argv[index + 1];
104
+ if (nextToken && !nextToken.startsWith("--")) {
105
+ flags[normalized] = nextToken;
106
+ index += 2;
107
+ continue;
108
+ }
109
+ flags[normalized] = true;
110
+ index += 1;
111
+ }
112
+ return { args, flags };
113
+ };
114
+ const isTruthyFlag = (value) => {
115
+ if (value === true)
116
+ return true;
117
+ if (typeof value !== "string")
118
+ return false;
119
+ const normalized = value.trim().toLowerCase();
120
+ return normalized === "true" || normalized === "1";
121
+ };
122
+ const resolveRoute = (options) => {
123
+ const parsed = parseFlagsAndArgs(options.argv);
124
+ if (Object.prototype.hasOwnProperty.call(parsed.flags, "version")) {
125
+ throw new errors_1.CliError("VERSION", { code: "VERSION_REQUESTED", exitCode: 0 });
126
+ }
127
+ const help = parsed.flags.help === true || parsed.flags.h === true;
128
+ if (help) {
129
+ const helpInfo = (0, help_1.resolveHelp)(exports.CLI_ROUTES, parsed.args);
130
+ if (!helpInfo) {
131
+ throw new errors_1.CliError(`Unknown command for help: ${parsed.args.join(" ") || "<empty>"}`, {
132
+ code: "UNKNOWN_COMMAND",
133
+ exitCode: 2,
134
+ });
135
+ }
136
+ throw new errors_1.CliError(helpInfo.text, { code: "HELP_REQUESTED", exitCode: 0 });
137
+ }
138
+ if (parsed.flags.format === true) {
139
+ throw new errors_1.CliError("Invalid output format: missing value for -f/--format. Use json or md", {
140
+ code: "INVALID_ARGUMENT",
141
+ exitCode: 2,
142
+ });
143
+ }
144
+ const rawFormatFlag = typeof parsed.flags.format === "string" ? parsed.flags.format.trim().toLowerCase() : undefined;
145
+ if (Object.prototype.hasOwnProperty.call(parsed.flags, "json") || Object.prototype.hasOwnProperty.call(parsed.flags, "md")) {
146
+ throw new errors_1.CliError("Deprecated output flags: use -f/--format <json|md> instead of --json/--md", {
147
+ code: "INVALID_ARGUMENT",
148
+ exitCode: 2,
149
+ });
150
+ }
151
+ let format = "md";
152
+ if (rawFormatFlag) {
153
+ if (rawFormatFlag !== "json" && rawFormatFlag !== "md") {
154
+ throw new errors_1.CliError(`Invalid output format: ${rawFormatFlag}. Use json or md`, {
155
+ code: "INVALID_ARGUMENT",
156
+ exitCode: 2,
157
+ });
158
+ }
159
+ format = rawFormatFlag;
160
+ }
161
+ const envelope = isTruthyFlag(parsed.flags.envelope);
162
+ if (format !== "json" && envelope) {
163
+ throw new errors_1.CliError("Invalid flag: --envelope requires --format json", {
164
+ code: "INVALID_ARGUMENT",
165
+ exitCode: 2,
166
+ });
167
+ }
168
+ const pathTokens = parsed.args.slice(0, 2);
169
+ const route = exports.CLI_ROUTES.find((item) => item.path[0] === pathTokens[0] && item.path[1] === pathTokens[1]);
170
+ if (!route) {
171
+ const hint = (0, help_1.resolveHelpHint)(exports.CLI_ROUTES, parsed.args);
172
+ throw new errors_1.CliError(`Unknown command: ${pathTokens.join(" ") || "<empty>"}. ${hint}`, {
173
+ code: "UNKNOWN_COMMAND",
174
+ exitCode: 2,
175
+ });
176
+ }
177
+ const commandArgs = parsed.args.slice(route.path.length);
178
+ return {
179
+ key: route.key,
180
+ input: {
181
+ args: commandArgs,
182
+ flags: parsed.flags,
183
+ stdin: options.stdin,
184
+ },
185
+ global: { format, envelope },
186
+ };
187
+ };
188
+ exports.resolveRoute = resolveRoute;
189
+ const getRouteDefinition = (key) => {
190
+ const route = exports.CLI_ROUTES.find((item) => item.key === key);
191
+ if (!route) {
192
+ throw new errors_1.CliError(`Route not found: ${key}`, {
193
+ code: "ROUTE_NOT_FOUND",
194
+ exitCode: 2,
195
+ });
196
+ }
197
+ return route;
198
+ };
199
+ exports.getRouteDefinition = getRouteDefinition;