@thinkingai/ae-cli 6.1.25 → 6.1.26

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 (121) hide show
  1. package/README.md +28 -9
  2. package/README.zh.md +25 -9
  3. package/bin/ae-cli.js +6 -1
  4. package/cli-installation-guide.md +91 -0
  5. package/dist/{auth-LHM7NQPR.js → auth-YHMC3GDH.js} +6 -8
  6. package/dist/automation-NWWVLWG2.js +459 -0
  7. package/dist/{capability-SJI5KOCK.js → capability-3QLLIVFB.js} +6 -6
  8. package/dist/chunk-4655PUNX.js +43 -0
  9. package/dist/{chunk-KS4DE3MX.js → chunk-5XJYLEVC.js} +4 -4
  10. package/dist/{chunk-N4BLPJC7.js → chunk-7QXISROD.js} +1 -1
  11. package/dist/{chunk-7WZACOAI.js → chunk-AP7YP2NX.js} +2 -2
  12. package/dist/{chunk-SO5LKIWP.js → chunk-CT7QDJS6.js} +2 -2
  13. package/dist/chunk-D6ACFILC.js +56 -0
  14. package/dist/{chunk-QYXDJOLA.js → chunk-EOYSKMXN.js} +19 -11
  15. package/dist/{chunk-5XRQ3CZR.js → chunk-FMNNGNYO.js} +43 -8
  16. package/dist/{chunk-DU72X2IO.js → chunk-GIK6EDUG.js} +22 -10
  17. package/dist/chunk-HVHR4SCP.js +133 -0
  18. package/dist/{chunk-2FJM4HRV.js → chunk-KAEHZZH4.js} +3 -3
  19. package/dist/{chunk-BW7JUDEI.js → chunk-KFNMQTZI.js} +514 -213
  20. package/dist/{chunk-KJDOTPYU.js → chunk-PLE722AJ.js} +28 -11
  21. package/dist/chunk-RK6GLDGI.js +27 -0
  22. package/dist/{chunk-GK7WDY7E.js → chunk-S6M42KND.js} +1 -1
  23. package/dist/{chunk-IG3DYEIR.js → chunk-UQ77JXYH.js} +4 -3
  24. package/dist/{chunk-YVGXGTD6.js → chunk-WNGFSIOB.js} +7 -1
  25. package/dist/{chunk-XKIW3QMF.js → chunk-XCHAYMSF.js} +3 -3
  26. package/dist/{community-report-client-6VJDDMJJ.js → community-report-client-PEERQCX2.js} +1 -1
  27. package/dist/{config-XQWOPDHN.js → config-AHPMEW5A.js} +4 -4
  28. package/dist/context-YAE3QXP3.js +136 -0
  29. package/dist/{data-integration-XBTCGXQT.js → data-integration-HESZET7E.js} +6 -6
  30. package/dist/index.js +123 -46
  31. package/dist/{local-data-upload-client-3P7NIVQ4.js → local-data-upload-client-TWMHFLUA.js} +1 -1
  32. package/dist/memory-62BJOULV.js +580 -0
  33. package/dist/{metadata-JRYKNUS5.js → metadata-C7CEDHOJ.js} +7 -7
  34. package/dist/{model-ZS7HVGKN.js → model-SBV2JFJI.js} +9 -5
  35. package/dist/{personal-semantic-preference-IDE2GE5T.js → personal-semantic-preference-QECDPHND.js} +117 -11
  36. package/dist/{project-semantic-36KOCYN7.js → project-semantic-Z4QAMBWF.js} +6 -6
  37. package/dist/{sync-EQLSTUS7.js → sync-SU33KYX7.js} +12 -8
  38. package/dist/{te-agent-Z3HCTKR7.js → te-agent-F5QBZSQA.js} +90 -454
  39. package/dist/{te-analysis-5ZZ6YHVH.js → te-analysis-2ECAAIFK.js} +297 -20
  40. package/dist/{te-community-Z7JACGF3.js → te-community-PFLDLPP4.js} +3 -3
  41. package/dist/{te-dataops-F7GQOIS6.js → te-dataops-FOQSRIAZ.js} +5 -5
  42. package/dist/{te-engage-RNRMYDO3.js → te-engage-QKUGIWSR.js} +6 -6
  43. package/dist/{te-experiment-BTAC2UNK.js → te-experiment-26PXR2UO.js} +6 -6
  44. package/dist/{te-kb-QJLJEX5K.js → te-kb-MHDOST62.js} +494 -214
  45. package/dist/{te-system-IXC43QHZ.js → te-system-J2FQF5ER.js} +6 -6
  46. package/dist/{te-team-BIZIKIHZ.js → te-team-5UOZPTU3.js} +6 -6
  47. package/dist/things-VPPXXLHB.js +1091 -0
  48. package/dist/{update-W2SGQNKT.js → update-EEUTEI6R.js} +59 -51
  49. package/dist/workspace-O3EEIYQM.js +554 -0
  50. package/package.json +21 -9
  51. package/skills/ae-agent/SKILL.md +89 -139
  52. package/skills/ae-agent/references/add-model.md +1 -1
  53. package/skills/ae-agent/references/create-agent.md +1 -1
  54. package/skills/ae-agent/references/find-archived-conversations.md +12 -5
  55. package/skills/ae-agent/references/get-agent.md +1 -1
  56. package/skills/ae-agent/references/list-agents.md +2 -2
  57. package/skills/ae-agent/references/list-models.md +2 -2
  58. package/skills/ae-agent/references/restore-conversation.md +3 -1
  59. package/skills/ae-analysis/SKILL.md +15 -6
  60. package/skills/ae-analysis/references/ai_models/funnel.md +5 -3
  61. package/skills/ae-analysis/references/ai_models.md +27 -0
  62. package/skills/ae-analysis/references/command_index.md +12 -4
  63. package/skills/ae-analysis/references/dashboard_move.md +21 -0
  64. package/skills/ae-analysis/references/dashboard_report_add.md +2 -0
  65. package/skills/ae-analysis/references/dashboard_report_get.md +19 -0
  66. package/skills/ae-analysis/references/dashboard_report_update.md +27 -0
  67. package/skills/ae-analysis/references/dashboard_update.md +1 -1
  68. package/skills/ae-analysis/references/event_report_presentation.md +76 -0
  69. package/skills/ae-analysis/references/feedback_submit.md +37 -0
  70. package/skills/ae-analysis/references/metadata_resolution.md +15 -0
  71. package/skills/ae-analysis/references/personal_semantic_preference_review.md +9 -0
  72. package/skills/ae-analysis/references/personal_semantic_preference_review_list.md +7 -0
  73. package/skills/ae-analysis/references/personal_semantic_preference_submit.md +7 -0
  74. package/skills/ae-analysis/references/project_semantic_knowledge_wiki.md +68 -27
  75. package/skills/ae-analysis/references/project_semantic_knowledge_wiki_plan_schema.md +40 -1
  76. package/skills/ae-analysis/references/report_create.md +13 -3
  77. package/skills/ae-analysis/references/report_get.md +5 -1
  78. package/skills/ae-analysis/references/report_update.md +15 -4
  79. package/skills/ae-analysis/references/system_query_monitor_overview.md +2 -0
  80. package/skills/ae-analysis/references/system_query_task_cancel.md +2 -0
  81. package/skills/ae-analysis/references/system_query_task_export.md +6 -2
  82. package/skills/ae-analysis/references/system_query_task_get.md +2 -0
  83. package/skills/ae-analysis/references/system_query_task_list.md +7 -3
  84. package/skills/ae-analysis/references/system_query_task_options.md +2 -2
  85. package/skills/ae-analysis/references/system_query_task_realtime_list.md +15 -0
  86. package/skills/ae-analysis/references/user_tag_models.md +2 -0
  87. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/build-empty-skeleton.mjs +105 -0
  88. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/build-project-semantic-wiki.mjs +337 -22
  89. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/company-kb.mjs +21 -8
  90. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/default-compile-rules.md +24 -11
  91. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/default-compile-schema.md +66 -0
  92. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/generate-build-ir.mjs +1 -0
  93. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/package-wiki-source-zip.mjs +109 -40
  94. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/plan-kb-source-sync.mjs +1 -1
  95. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/prepare-compile-schema.mjs +64 -0
  96. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/refresh-state-parts.mjs +91 -0
  97. package/skills/ae-automation/SKILL.md +16 -0
  98. package/skills/ae-automation/references/cli.md +53 -0
  99. package/skills/ae-automation/references/command_index.md +17 -0
  100. package/skills/ae-capability/SKILL.md +15 -6
  101. package/skills/ae-current-context/SKILL.md +3 -2
  102. package/skills/ae-kb/SKILL.md +62 -12
  103. package/skills/ae-kb/references/analysis-workflow.md +73 -36
  104. package/skills/ae-kb/references/query-workflow.md +67 -33
  105. package/skills/ae-kb/references/schema-import.md +5 -3
  106. package/skills/ae-kb/references/source-mutations.md +6 -4
  107. package/skills/ae-kb/references/text-sources.md +53 -0
  108. package/skills/ae-kb-discovery/SKILL.md +1 -1
  109. package/skills/ae-team/SKILL.md +23 -17
  110. package/skills/ae-things/SKILL.md +85 -0
  111. package/skills/ae-things/references/cli.md +103 -0
  112. package/skills/ae-things-progress/SKILL.md +43 -0
  113. package/skills/ae-things-review/SKILL.md +42 -0
  114. package/skills/ae-workspace/SKILL.md +43 -0
  115. package/skills/ae-workspace/references/commands.md +51 -0
  116. package/dist/chunk-E2JKXMVO.js +0 -29
  117. package/dist/context-M3HDGEIR.js +0 -46
  118. package/dist/memory-6APEB2JB.js +0 -892
  119. package/skills/ae-agent/references/create-automation.md +0 -125
  120. package/skills/ae-agent/references/list-automations.md +0 -56
  121. package/skills/ae-agent/references/update-automation.md +0 -107
@@ -6,17 +6,18 @@ import {
6
6
  SecureStoreAuthError,
7
7
  clearCliTokenCache,
8
8
  getCliToken
9
- } from "./chunk-DU72X2IO.js";
9
+ } from "./chunk-GIK6EDUG.js";
10
10
  import {
11
11
  safeJsonParse
12
- } from "./chunk-IG3DYEIR.js";
12
+ } from "./chunk-UQ77JXYH.js";
13
13
  import {
14
14
  PermissionError
15
- } from "./chunk-YVGXGTD6.js";
15
+ } from "./chunk-WNGFSIOB.js";
16
16
 
17
17
  // src/core/cli-agent-context.ts
18
18
  import { readFileSync, statSync } from "fs";
19
19
  import { dirname, join, parse, resolve } from "path";
20
+ import { AsyncLocalStorage } from "async_hooks";
20
21
  var MAX_CONTEXT_FILE_BYTES = 64 * 1024;
21
22
  var CONTEXT_FILE_ENV = "TA_CLI_CONTEXT_FILE";
22
23
  var CONTEXT_ARG = "--agent-context";
@@ -42,12 +43,17 @@ var FIELDS = [
42
43
  { key: "session_goal", env: "TA_CLI_SESSION_GOAL", header: "X-TA-CLI-Session-Goal", maxLength: 2048 },
43
44
  { key: "context_capture_status", env: "TA_CLI_CONTEXT_CAPTURE_STATUS", header: "X-TA-CLI-Context-Capture-Status", maxLength: 32 }
44
45
  ];
46
+ var scopedContext = new AsyncLocalStorage();
47
+ function runWithCliAgentContext(context, run) {
48
+ return scopedContext.run(context, run);
49
+ }
45
50
  function readCliAgentContext() {
46
51
  const context = {
47
52
  ...inferRuntimeContext(),
48
53
  ...readEnvContext(),
49
54
  ...readArgumentContext(),
50
- ...readFileContext()
55
+ ...readFileContext(),
56
+ ...scopedContext.getStore()
51
57
  };
52
58
  return withCaptureStatus(context);
53
59
  }
@@ -271,11 +277,11 @@ var CapabilityGatewayError = class extends Error {
271
277
  meta;
272
278
  type;
273
279
  };
274
- function buildCapabilityGatewayUrl(host, domain, pathAfterV1, queryParams = {}) {
280
+ function buildCapabilityGatewayUrl(host, domain, pathAfterV1, queryParams = {}, apiVersion = "v1") {
275
281
  const base = host.replace(/\/+$/, "");
276
282
  const cleanDomain = domain.replace(/^\/+|\/+$/g, "");
277
283
  const cleanPath = pathAfterV1.replace(/^\/+|\/+$/g, "");
278
- const gatewayPrefix = cleanDomain === "" ? "/api/cli/v1" : `/api/cli/${cleanDomain}/v1`;
284
+ const gatewayPrefix = cleanDomain === "" ? `/api/cli/${apiVersion}` : `/api/cli/${cleanDomain}/${apiVersion}`;
279
285
  const url = new URL(`${base}${gatewayPrefix}/${cleanPath}`);
280
286
  for (const [key, value] of Object.entries(queryParams)) {
281
287
  if (value !== void 0 && value !== null) {
@@ -383,7 +389,7 @@ async function throwCapabilityHttpError(resp) {
383
389
  }
384
390
  throw error;
385
391
  }
386
- async function requestOnce(url, method, token, body, accept = "application/json") {
392
+ async function requestOnce(url, method, token, body, accept = "application/json", includeClientContextInBody = true) {
387
393
  const agentContext = readCliAgentContext();
388
394
  const headers = {
389
395
  "cli-token": token,
@@ -394,7 +400,7 @@ async function requestOnce(url, method, token, body, accept = "application/json"
394
400
  const init = { method, headers };
395
401
  if (body !== void 0 && method !== "GET") {
396
402
  headers["Content-Type"] = "application/json";
397
- init.body = JSON.stringify(withCliAgentContextBody(body, agentContext));
403
+ init.body = JSON.stringify(includeClientContextInBody ? withCliAgentContextBody(body, agentContext) : body);
398
404
  }
399
405
  return fetch(url, init);
400
406
  }
@@ -413,13 +419,13 @@ async function callGateway(host, domain, pathAfterV1, method, body, queryParams
413
419
  return (await callGatewayWithEnvelope(host, domain, pathAfterV1, method, body, queryParams, options)).data;
414
420
  }
415
421
  async function callGatewayWithEnvelope(host, domain, pathAfterV1, method, body, queryParams = {}, options = {}) {
416
- const url = buildCapabilityGatewayUrl(options.apiBaseUrl ?? host, domain, pathAfterV1, queryParams);
422
+ const url = buildCapabilityGatewayUrl(options.apiBaseUrl ?? host, domain, pathAfterV1, queryParams, options.apiVersion);
417
423
  const token = await getCliToken(host);
418
- let resp = await requestOnce(url, method, token, body);
424
+ let resp = await requestOnce(url, method, token, body, "application/json", options.includeClientContextInBody);
419
425
  if (resp.status === 401 && options.retryOnUnauthorized === true) {
420
426
  await resp.body?.cancel();
421
427
  clearCliTokenCache(host);
422
- resp = await requestOnce(url, method, await getCliToken(host), body);
428
+ resp = await requestOnce(url, method, await getCliToken(host), body, "application/json", options.includeClientContextInBody);
423
429
  }
424
430
  if (resp.status === 403) {
425
431
  const error = await permissionError(resp);
@@ -549,6 +555,8 @@ async function callCapabilityApi(host, domain, action, method = "POST", params =
549
555
  }
550
556
 
551
557
  export {
558
+ runWithCliAgentContext,
559
+ readCliAgentContext,
552
560
  CapabilityGatewayError,
553
561
  buildCapabilityGatewayUrl,
554
562
  fetchCapabilityGateway,
@@ -1,17 +1,17 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
2
  import {
3
3
  CapabilityGatewayError
4
- } from "./chunk-QYXDJOLA.js";
4
+ } from "./chunk-EOYSKMXN.js";
5
5
  import {
6
6
  SecureStoreAuthError,
7
7
  getCliToken
8
- } from "./chunk-DU72X2IO.js";
8
+ } from "./chunk-GIK6EDUG.js";
9
9
  import {
10
10
  safeJsonParse
11
- } from "./chunk-IG3DYEIR.js";
11
+ } from "./chunk-UQ77JXYH.js";
12
12
  import {
13
13
  PermissionError
14
- } from "./chunk-YVGXGTD6.js";
14
+ } from "./chunk-WNGFSIOB.js";
15
15
 
16
16
  // src/core/mcp-access.ts
17
17
  function buildUrl(host, path, params = {}) {
@@ -26,6 +26,11 @@ function buildUrl(host, path, params = {}) {
26
26
  return url.toString();
27
27
  }
28
28
  var KbUnauthorizedError = class extends Error {
29
+ constructor(message, code) {
30
+ super(message);
31
+ this.code = code;
32
+ }
33
+ code;
29
34
  };
30
35
  function optionalString(value) {
31
36
  return typeof value === "string" && value.trim() ? value.trim() : void 0;
@@ -49,6 +54,16 @@ function responseErrorMessage(data) {
49
54
  const nestedError = data?.error && typeof data.error === "object" ? data.error : void 0;
50
55
  return optionalString(typeof data?.error === "string" ? data.error : void 0) ?? optionalString(nestedError?.message) ?? optionalString(data?.message) ?? optionalString(data?.return_message);
51
56
  }
57
+ function safeTextErrorCode(data) {
58
+ const rawCode = responseErrorMetadata(data).code;
59
+ return rawCode && /^[a-z0-9][a-z0-9_.:-]{0,127}$/i.test(rawCode) ? rawCode : void 0;
60
+ }
61
+ function safeTextError(resp, data) {
62
+ const code = safeTextErrorCode(data);
63
+ const message = resp.status === 404 && !code ? "This host does not support the KB text API (HTTP 404)." : `KB text request failed (HTTP ${resp.status}${code ? `, ${code}` : ""}).`;
64
+ const hint = code === "SOURCE_CONTENT_REVISION_CONFLICT" ? "The source changed. Keep your local input, read the current revision and explicitly resolve the conflict." : resp.status === 404 ? "Verify the exact source and host support for text APIs; no upload fallback was attempted." : "Inspect the source list and current state before retrying. Source content is omitted from diagnostics.";
65
+ return resp.status === 403 ? new PermissionError(message, code, hint) : new KbHttpError(message, code, resp.status, hint);
66
+ }
52
67
  function responseStatus(resp) {
53
68
  const statusText = optionalString(resp.statusText);
54
69
  return statusText ? `${resp.status} ${statusText}` : String(resp.status);
@@ -68,6 +83,7 @@ var KbHttpError = class extends CapabilityGatewayError {
68
83
  }
69
84
  };
70
85
  function nonOkResponseError(resp, data, options) {
86
+ if (options.redactErrorDetails) return safeTextError(resp, data);
71
87
  const metadata = responseErrorMetadata(data);
72
88
  const serverMessage = responseErrorMessage(data);
73
89
  const fallbackMessage = `KB API HTTP error: ${responseStatus(resp)}`;
@@ -84,41 +100,59 @@ function parseKbResponse(resp, text, options = {}) {
84
100
  let metadata = {};
85
101
  try {
86
102
  const d = safeJsonParse(text);
103
+ if (options.redactErrorDetails) throw safeTextError(resp, d);
87
104
  const m = d && (typeof d.error === "string" ? d.error : d.error?.message || d.message);
88
105
  if (m && typeof m === "string") msg = m;
89
106
  if (options.preserveErrorMetadata) metadata = responseErrorMetadata(d);
90
- } catch {
107
+ } catch (error) {
108
+ if (error instanceof PermissionError) throw error;
91
109
  }
92
110
  throw new PermissionError(msg, metadata.code, metadata.hint);
93
111
  }
94
112
  if (resp.status === 401) {
113
+ let code;
114
+ if (options.redactErrorDetails) {
115
+ try {
116
+ code = safeTextErrorCode(safeJsonParse(text));
117
+ } catch {
118
+ }
119
+ }
95
120
  throw new KbUnauthorizedError(
96
- `KB API token auth failed: HTTP ${resp.status} ${resp.statusText}`
121
+ options.redactErrorDetails ? "KB API token auth failed: HTTP 401." : `KB API token auth failed: HTTP ${resp.status} ${resp.statusText}`,
122
+ code
97
123
  );
98
124
  }
99
125
  if (!text.trim()) {
126
+ if (options.redactErrorDetails && !resp.ok) throw safeTextError(resp, void 0);
100
127
  throw malformedResponseError(resp, "empty response body");
101
128
  }
102
129
  let data;
103
130
  try {
104
131
  data = safeJsonParse(text);
105
132
  } catch {
133
+ if (options.redactErrorDetails && !resp.ok) throw safeTextError(resp, void 0);
106
134
  throw malformedResponseError(resp, "non-JSON response");
107
135
  }
108
136
  if (data?.return_code === -1001) {
109
137
  throw new KbUnauthorizedError(
110
- `KB API token auth failed: ${data.return_message || "unauthorized"} (code: ${data.return_code})`
138
+ options.redactErrorDetails ? "KB API token auth failed (code: -1001)." : `KB API token auth failed: ${data.return_message || "unauthorized"} (code: ${data.return_code})`,
139
+ options.redactErrorDetails ? safeTextErrorCode(data) : void 0
111
140
  );
112
141
  }
113
142
  if (!resp.ok) {
114
143
  throw nonOkResponseError(resp, data, options);
115
144
  }
116
145
  if (data?.return_code !== 0 && data?.return_code !== void 0) {
146
+ if (options.redactErrorDetails) throw safeTextError(resp, data);
117
147
  throw new Error(
118
148
  `AE API error: ${data.return_message || "unknown"} (code: ${data.return_code})`
119
149
  );
120
150
  }
151
+ if (options.redactErrorDetails && data?.error && typeof data.error === "object") {
152
+ throw safeTextError(resp, data);
153
+ }
121
154
  if (data && typeof data === "object" && typeof data.error === "string" && data.error.trim() && data.return_code === void 0 && data.success === void 0) {
155
+ if (options.redactErrorDetails) throw safeTextError(resp, data);
122
156
  if (options.preserveErrorMetadata) {
123
157
  const metadata = responseErrorMetadata(data);
124
158
  throw new CapabilityGatewayError(
@@ -171,7 +205,8 @@ async function requestWithCliToken(host, input, init, options) {
171
205
  }
172
206
  }
173
207
  throw new SecureStoreAuthError(
174
- `The stored CLI token for ${host} is invalid or expired. Run: ae-cli auth login --host ${host}`
208
+ `The stored CLI token for ${host} is invalid or expired. Run: ae-cli auth login --host ${host}`,
209
+ options.redactErrorDetails ? error.code : void 0
175
210
  );
176
211
  }
177
212
  throw error;
@@ -6,11 +6,11 @@ import {
6
6
  normalizeUrl,
7
7
  safeJsonParse,
8
8
  safeReadJsonFile
9
- } from "./chunk-IG3DYEIR.js";
9
+ } from "./chunk-UQ77JXYH.js";
10
10
  import {
11
11
  PermissionError,
12
12
  logger
13
- } from "./chunk-YVGXGTD6.js";
13
+ } from "./chunk-WNGFSIOB.js";
14
14
 
15
15
  // src/core/secure-store.ts
16
16
  import crypto from "crypto";
@@ -521,10 +521,12 @@ function loadCliToken(host) {
521
521
  return getActiveCredential(host)?.cliToken ?? null;
522
522
  }
523
523
  var SecureStoreAuthError = class extends Error {
524
- constructor(message) {
524
+ constructor(message, code) {
525
525
  super(message);
526
+ this.code = code;
526
527
  this.name = "SecureStoreAuthError";
527
528
  }
529
+ code;
528
530
  };
529
531
  var CredentialStoreUnreadableError = class extends Error {
530
532
  code = "CREDENTIAL_STORE_UNREADABLE";
@@ -542,6 +544,9 @@ import path2 from "path";
542
544
  var CLI_TOKEN_GENERATE_PATH = "/v1/ta/cli/token/generate";
543
545
  var CLI_TOKEN_RENEW_PATH = "/v1/ta/cli/token/renew";
544
546
  var CLI_TOKEN_VALIDATE_PATH = "/v1/ta/cli/token/validate";
547
+ function safeReturnCode(value) {
548
+ return typeof value === "number" && Number.isFinite(value) ? String(value) : void 0;
549
+ }
545
550
  var CliTokenValidationUnavailableError = class extends Error {
546
551
  constructor(message) {
547
552
  super(message);
@@ -660,19 +665,26 @@ async function generateCliToken(hostUrl, accessToken) {
660
665
  body = text ? safeJsonParse(text) : {};
661
666
  } catch {
662
667
  }
663
- const message = body.message ?? body.return_message ?? "CLI access is disabled for this account.";
664
- const code = body.code ?? (String(message).includes("CLI_ACCESS_DISABLED") ? "CLI_ACCESS_DISABLED" : void 0);
665
- throw new PermissionError(message, code, body.hint);
668
+ const serviceMessage = body.message ?? body.return_message;
669
+ const code = body.code === "CLI_ACCESS_DISABLED" || String(serviceMessage).includes("CLI_ACCESS_DISABLED") ? "CLI_ACCESS_DISABLED" : void 0;
670
+ throw new PermissionError(
671
+ code === "CLI_ACCESS_DISABLED" ? "CLI access is disabled for this account." : "You do not have permission to generate a CLI token.",
672
+ code
673
+ );
666
674
  }
667
675
  throw new Error(`CLI token generate HTTP error: ${resp.status} ${resp.statusText}`);
668
676
  }
669
677
  const data = safeJsonParse(await resp.text());
670
678
  if (data.return_code !== 0) {
671
- const message = data.return_message || data.message || "unknown";
672
- if (data.code === "CLI_ACCESS_DISABLED" || String(message).includes("CLI_ACCESS_DISABLED")) {
673
- throw new PermissionError(message, "CLI_ACCESS_DISABLED", data.hint);
679
+ const serviceMessage = data.return_message || data.message;
680
+ if (data.code === "CLI_ACCESS_DISABLED" || String(serviceMessage).includes("CLI_ACCESS_DISABLED")) {
681
+ throw new PermissionError(
682
+ "CLI access is disabled for this account.",
683
+ "CLI_ACCESS_DISABLED"
684
+ );
674
685
  }
675
- throw new Error(`CLI token generate error: ${message} (code: ${data.return_code})`);
686
+ const code = safeReturnCode(data.return_code);
687
+ throw new Error(`CLI token generation failed${code ? ` (code: ${code})` : ""}`);
676
688
  }
677
689
  const cliToken = data.data?.userSecret ?? data.data?.user_secret;
678
690
  if (!cliToken) throw new Error("CLI token generate error: empty userSecret in response");
@@ -0,0 +1,133 @@
1
+ import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
+ import {
3
+ currentAgentSpaceId
4
+ } from "./chunk-RK6GLDGI.js";
5
+ import {
6
+ deleteAgentApi,
7
+ getAgentApi,
8
+ patchAgentApi,
9
+ postAgentApi,
10
+ putAgentApi,
11
+ uploadAgentApi
12
+ } from "./chunk-4655PUNX.js";
13
+ import {
14
+ TeAgentApiError,
15
+ createTeAgentApiError
16
+ } from "./chunk-PLE722AJ.js";
17
+ import {
18
+ CliValidationError,
19
+ isApiErrorType
20
+ } from "./chunk-WNGFSIOB.js";
21
+
22
+ // src/commands/workspace/client.ts
23
+ var DEFAULT_TE_CLAUDE_BASE_PATH = "/agent";
24
+ var WORKSPACE_CLI_BASE_PATH = "/api/cli/workspace/v1";
25
+ function normalizeBasePath(value) {
26
+ const trimmed = value.trim();
27
+ if (!trimmed || trimmed === "/") return "";
28
+ return `/${trimmed.replace(/^\/+|\/+$/g, "")}`;
29
+ }
30
+ function resolveWorkspaceApiBaseUrl(host) {
31
+ const base = host.replace(/\/+$/, "");
32
+ const basePath = normalizeBasePath(
33
+ process.env.TE_CLAUDE_BASE_PATH ?? process.env.AE_API_PREFIX ?? DEFAULT_TE_CLAUDE_BASE_PATH
34
+ );
35
+ return basePath && !base.endsWith(basePath) ? `${base}${basePath}` : base;
36
+ }
37
+ function buildWorkspaceCliUrl(ctx, path) {
38
+ return `${resolveWorkspaceApiBaseUrl(ctx.host())}${path}`;
39
+ }
40
+ function unwrapWorkspaceResponse(response) {
41
+ if (response && typeof response === "object" && !Array.isArray(response)) {
42
+ const envelope = response;
43
+ if (envelope.ok === true) return envelope.data;
44
+ if (envelope.ok === false) {
45
+ const error = envelope.error;
46
+ if (error && isApiErrorType(error.type) && typeof error.code === "string" && error.code.trim() && typeof error.message === "string" && error.message.trim()) {
47
+ throw createTeAgentApiError(response, 200, "Workspace API request failed");
48
+ }
49
+ throw new TeAgentApiError("The Workspace API returned an invalid error response.", 200, "WORKSPACE_INVALID_RESPONSE");
50
+ }
51
+ }
52
+ return response;
53
+ }
54
+ async function getWorkspaceApi(ctx, path) {
55
+ return unwrapWorkspaceResponse(await getAgentApi(ctx, path));
56
+ }
57
+ async function postWorkspaceApi(ctx, path, body) {
58
+ return unwrapWorkspaceResponse(await postAgentApi(ctx, path, body));
59
+ }
60
+ async function patchWorkspaceApi(ctx, path, body) {
61
+ return unwrapWorkspaceResponse(await patchAgentApi(ctx, path, body));
62
+ }
63
+ async function putWorkspaceApi(ctx, path, body) {
64
+ return unwrapWorkspaceResponse(await putAgentApi(ctx, path, body));
65
+ }
66
+ async function deleteWorkspaceApi(ctx, path) {
67
+ return unwrapWorkspaceResponse(await deleteAgentApi(ctx, path));
68
+ }
69
+ async function uploadWorkspaceApi(ctx, path, formData) {
70
+ return unwrapWorkspaceResponse(await uploadAgentApi(ctx, path, formData));
71
+ }
72
+
73
+ // src/commands/workspace/target.ts
74
+ function optional(value) {
75
+ const trimmed = value?.trim();
76
+ return trimmed || void 0;
77
+ }
78
+ var workspaceTargetFlags = [
79
+ {
80
+ name: "workspace-id",
81
+ type: "string",
82
+ required: false,
83
+ desc: "AgentSpace ID; defaults to the current AgentSpace or resolves from the current conversation"
84
+ },
85
+ {
86
+ name: "conversation-id",
87
+ type: "string",
88
+ required: false,
89
+ desc: "Conversation ID used to verify or resolve the AgentSpace target"
90
+ }
91
+ ];
92
+ function workspaceTargetParams(ctx) {
93
+ const params = new URLSearchParams();
94
+ const workspaceId = optional(ctx.str("workspaceId")) ?? currentAgentSpaceId();
95
+ const conversationId = optional(ctx.str("conversationId")) ?? optional(process.env.TE_AGENT_CONVERSATION_ID);
96
+ if (!workspaceId && !conversationId) {
97
+ throw new CliValidationError(
98
+ "Workspace target is required. Provide --workspace-id or --conversation-id, or run inside an AgentSpace conversation."
99
+ );
100
+ }
101
+ if (workspaceId) params.set("agentSpaceId", workspaceId);
102
+ if (conversationId) params.set("conversationId", conversationId);
103
+ return params;
104
+ }
105
+ function workspaceTargetPath(ctx) {
106
+ return `${WORKSPACE_CLI_BASE_PATH}/target?${workspaceTargetParams(ctx).toString()}`;
107
+ }
108
+ async function resolveWorkspaceTarget(ctx) {
109
+ return getWorkspaceApi(ctx, workspaceTargetPath(ctx));
110
+ }
111
+ function workspaceResourcePath(agentSpaceId, suffix = "") {
112
+ return `${WORKSPACE_CLI_BASE_PATH}/agent-spaces/${encodeURIComponent(agentSpaceId)}${suffix}`;
113
+ }
114
+ function previewWorkspaceResourcePath(ctx, suffix = "") {
115
+ const id = optional(ctx.str("workspaceId")) ?? currentAgentSpaceId() ?? ":resolved-workspace-id";
116
+ return workspaceResourcePath(id, suffix);
117
+ }
118
+
119
+ export {
120
+ WORKSPACE_CLI_BASE_PATH,
121
+ buildWorkspaceCliUrl,
122
+ getWorkspaceApi,
123
+ postWorkspaceApi,
124
+ patchWorkspaceApi,
125
+ putWorkspaceApi,
126
+ deleteWorkspaceApi,
127
+ uploadWorkspaceApi,
128
+ workspaceTargetFlags,
129
+ workspaceTargetPath,
130
+ resolveWorkspaceTarget,
131
+ workspaceResourcePath,
132
+ previewWorkspaceResourcePath
133
+ };
@@ -3,16 +3,16 @@ import {
3
3
  dryRunCapability,
4
4
  executeCapabilityWithEnvelope,
5
5
  validateCapability
6
- } from "./chunk-QYXDJOLA.js";
6
+ } from "./chunk-EOYSKMXN.js";
7
7
  import {
8
8
  resolveGatewayDomain
9
9
  } from "./chunk-KPQY44JQ.js";
10
10
  import {
11
11
  withOutputMetadata
12
- } from "./chunk-BW7JUDEI.js";
12
+ } from "./chunk-KFNMQTZI.js";
13
13
  import {
14
14
  CliValidationError
15
- } from "./chunk-YVGXGTD6.js";
15
+ } from "./chunk-WNGFSIOB.js";
16
16
 
17
17
  // src/core/definition-intent.ts
18
18
  import { createHash } from "crypto";