@thinkingai/ae-cli 6.0.56 → 6.0.58

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 (112) hide show
  1. package/README.md +12 -4
  2. package/README.zh.md +12 -4
  3. package/bin/ae-cli.js +5 -0
  4. package/bin/runtime-capabilities.json +5 -0
  5. package/cli-installation-guide.md +24 -3
  6. package/dist/{auth-U7MNUUEF.js → auth-A5OO4VS4.js} +30 -12
  7. package/dist/{automation-K32V2NKP.js → automation-FD2QZUP6.js} +6 -6
  8. package/dist/{capability-VV7RHB3B.js → capability-SKI4GHF4.js} +48 -20
  9. package/dist/{chunk-P6VFCH3P.js → chunk-2F64AZYH.js} +2 -2
  10. package/dist/{chunk-LMCYSVVA.js → chunk-4PSTYEG5.js} +50 -41
  11. package/dist/{chunk-KHS64JZQ.js → chunk-72NJKS7O.js} +4 -4
  12. package/dist/{chunk-GI5BMEZO.js → chunk-AWVZTN2B.js} +1 -1
  13. package/dist/{chunk-UUD5RB36.js → chunk-E25OSZLJ.js} +3 -3
  14. package/dist/{chunk-W2PTY5NN.js → chunk-EEARZNHE.js} +3 -3
  15. package/dist/chunk-GBSACKFB.js +2283 -0
  16. package/dist/{chunk-3TQA5RXE.js → chunk-HQCY3QCA.js} +6 -4
  17. package/dist/{chunk-T44M3PLZ.js → chunk-JEUXDY3B.js} +1 -1
  18. package/dist/{chunk-2UWS5CUP.js → chunk-JSBLCLFE.js} +3 -3
  19. package/dist/chunk-K2Z7QHDR.js +132 -0
  20. package/dist/{chunk-QSAR3GHY.js → chunk-OAWPT7VP.js} +2 -2
  21. package/dist/{chunk-2IYIYSUO.js → chunk-QVRIDN42.js} +2 -2
  22. package/dist/{chunk-F6NIPIT5.js → chunk-QWSA3EOD.js} +35 -14
  23. package/dist/{chunk-P7KL7IOH.js → chunk-SOSFRU3O.js} +2 -2
  24. package/dist/{chunk-MXV3PYC3.js → chunk-UYJMEHAF.js} +50 -12
  25. package/dist/{chunk-JJJIP2XQ.js → chunk-VDICGXCY.js} +2 -2
  26. package/dist/chunk-WMDO53YK.js +222 -0
  27. package/dist/{chunk-X7DRLE62.js → chunk-YVG6QD3V.js} +1 -1
  28. package/dist/{chunk-ZW4VMY5H.js → chunk-Z3Q2AEIN.js} +152 -98
  29. package/dist/{community-report-client-S2K3A3Q6.js → community-report-client-TJVCLZ3K.js} +1 -1
  30. package/dist/compat-check-WFEKVLTH.js +32 -0
  31. package/dist/{config-ASSAAIOI.js → config-U4I7X25P.js} +38 -6
  32. package/dist/{context-6RWLVOM5.js → context-CDB5H5PD.js} +4 -4
  33. package/dist/{data-integration-EXSUPUDZ.js → data-integration-QE37EQ3A.js} +207 -24
  34. package/dist/{evaluation-5YT4QLCL.js → evaluation-LR4YDYWL.js} +4 -4
  35. package/dist/index.js +291 -71
  36. package/dist/{local-data-upload-client-7HCPGIS3.js → local-data-upload-client-KCMG6J62.js} +1 -1
  37. package/dist/{memory-VCYLVPMI.js → memory-SNFR5M23.js} +6 -6
  38. package/dist/{metadata-TIWIOFTU.js → metadata-6QM6EED5.js} +16 -8
  39. package/dist/{model-DPJHSD73.js → model-KEVCEXWD.js} +4 -4
  40. package/dist/{personal-semantic-preference-SBKU2LOK.js → personal-semantic-preference-7VXQPP2N.js} +7 -6
  41. package/dist/{project-semantic-SKNWLH3I.js → project-semantic-PSEPYH2L.js} +7 -6
  42. package/dist/{sync-7PP6KQ75.js → sync-22ACDK5Z.js} +8 -7
  43. package/dist/{te-agent-L2BYNPHM.js → te-agent-BJ36B4QI.js} +11 -7
  44. package/dist/{te-analysis-RJB6VJC4.js → te-analysis-WQ6D6YG4.js} +179 -27
  45. package/dist/{te-community-QN3WMPNT.js → te-community-VRWMFGI6.js} +720 -228
  46. package/dist/{te-dataops-UKD2XN3E.js → te-dataops-YTLFTTW7.js} +6 -5
  47. package/dist/{te-engage-KPTN4N2U.js → te-engage-V2QW7TIC.js} +7 -6
  48. package/dist/{te-kb-SFZI3W5T.js → te-kb-4AQLISDR.js} +407 -83
  49. package/dist/{te-system-IE7NCKC3.js → te-system-CYWSK3UN.js} +6 -6
  50. package/dist/{te-team-4KHCFM2I.js → te-team-6ELNGBWT.js} +7 -6
  51. package/dist/{things-7JJUVAWL.js → things-HFWLGCUH.js} +7 -7
  52. package/dist/{update-AX66IFMJ.js → update-3CRVVHV5.js} +11 -7
  53. package/dist/{workspace-Q5NMEKEN.js → workspace-2CKQX2XL.js} +6 -6
  54. package/package.json +17 -7
  55. package/skills/ae-agent/SKILL.md +1 -1
  56. package/skills/ae-agent/references/resource-package.md +4 -0
  57. package/skills/ae-analysis/SKILL.md +14 -10
  58. package/skills/ae-analysis/references/agent_review_preflight.md +52 -11
  59. package/skills/ae-analysis/references/agent_review_priorities_comparisons.md +5 -3
  60. package/skills/ae-analysis/references/agent_review_submit_to_page.md +57 -25
  61. package/skills/ae-analysis/references/command_index.md +7 -3
  62. package/skills/ae-analysis/references/governance_recommendation_export.md +31 -17
  63. package/skills/ae-analysis/references/governance_recommendation_run_update.md +13 -0
  64. package/skills/ae-analysis/references/project_semantic_knowledge_wiki.md +9 -1
  65. package/skills/ae-analysis/references/scenario_append.md +6 -0
  66. package/skills/ae-analysis/references/scenario_begin.md +11 -0
  67. package/skills/ae-analysis/references/scenario_collect.md +10 -2
  68. package/skills/ae-analysis/references/scenario_evaluation.md +6 -18
  69. package/skills/ae-analysis/references/scenario_get.md +15 -0
  70. package/skills/ae-analysis/references/scenario_list.md +64 -0
  71. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/company-kb.mjs +14 -1
  72. package/skills/ae-community/SKILL.md +77 -27
  73. package/skills/ae-community/references/community-analyzing-theme-comment.md +10 -8
  74. package/skills/ae-community/references/community-data-quality.md +68 -0
  75. package/skills/ae-community/references/community-query-evidence.md +85 -0
  76. package/skills/ae-community/references/community-scenario-capabilities.md +137 -0
  77. package/skills/ae-community/references/community-weekly-report.md +6 -3
  78. package/skills/ae-community/references/get_channel_info.md +7 -4
  79. package/skills/ae-community/references/get_comment_tag_analysis.md +3 -3
  80. package/skills/ae-community/references/get_comments_summary.md +4 -4
  81. package/skills/ae-community/references/get_corpus_tags.md +3 -3
  82. package/skills/ae-community/references/get_daily_summary.md +3 -3
  83. package/skills/ae-community/references/get_hot_topics.md +3 -3
  84. package/skills/ae-community/references/get_livestream_analysis.md +3 -3
  85. package/skills/ae-community/references/get_livestream_detail.md +4 -4
  86. package/skills/ae-community/references/get_livestream_list.md +3 -3
  87. package/skills/ae-community/references/get_livestream_overview.md +3 -3
  88. package/skills/ae-community/references/get_livestream_room_metrics.md +3 -3
  89. package/skills/ae-community/references/get_livestream_rooms.md +3 -3
  90. package/skills/ae-community/references/get_overview_metrics.md +3 -3
  91. package/skills/ae-community/references/get_post_detail.md +4 -4
  92. package/skills/ae-community/references/get_risk_content.md +5 -5
  93. package/skills/ae-community/references/get_sentiment_overview.md +4 -4
  94. package/skills/ae-community/references/get_tag_trends.md +3 -3
  95. package/skills/ae-community/references/get_topic_detail.md +3 -3
  96. package/skills/ae-community/references/list_sources.md +28 -0
  97. package/skills/ae-community/references/list_spaces.md +39 -0
  98. package/skills/ae-community/references/search_posts.md +21 -7
  99. package/skills/ae-data-integration/SKILL.md +6 -4
  100. package/skills/ae-data-integration/references/error-handling.md +1 -0
  101. package/skills/ae-data-integration/references/handoff.md +1 -1
  102. package/skills/ae-data-integration/references/sink-upload.md +11 -0
  103. package/skills/ae-data-integration/references/source-inspect.md +2 -1
  104. package/skills/ae-data-integration/references/transform.md +1 -1
  105. package/skills/ae-data-integration/references/ue-mapping.md +1 -1
  106. package/skills/ae-kb/SKILL.md +37 -8
  107. package/skills/ae-kb/references/publication.md +81 -0
  108. package/skills/ae-kb/references/query-workflow.md +20 -6
  109. package/skills/ae-kb-discovery/SKILL.md +15 -6
  110. package/skills/ae-metadata/SKILL.md +2 -2
  111. package/skills/ae-metadata/references/metadata_data_table_get.md +35 -0
  112. package/dist/chunk-ELCR235M.js +0 -1429
@@ -6,13 +6,16 @@ import {
6
6
  dryRunCapability,
7
7
  executeCapabilityWithEnvelope,
8
8
  validateCapability
9
- } from "./chunk-MXV3PYC3.js";
9
+ } from "./chunk-UYJMEHAF.js";
10
10
  import {
11
11
  withOutputMetadata
12
- } from "./chunk-ELCR235M.js";
12
+ } from "./chunk-WMDO53YK.js";
13
13
  import {
14
14
  CliValidationError
15
- } from "./chunk-ZW4VMY5H.js";
15
+ } from "./chunk-Z3Q2AEIN.js";
16
+
17
+ // src/core/capability-command.ts
18
+ import { randomBytes } from "crypto";
16
19
 
17
20
  // src/core/definition-intent.ts
18
21
  import { createHash } from "crypto";
@@ -83,7 +86,6 @@ function isRecord(value) {
83
86
  }
84
87
 
85
88
  // src/core/capability-command.ts
86
- import { randomBytes } from "crypto";
87
89
  function createCapabilityCommand(config) {
88
90
  return {
89
91
  service: config.cliService,
@@ -2,7 +2,7 @@ import { createRequire as __createRequire } from 'node:module'; const require =
2
2
  import {
3
3
  __commonJS,
4
4
  __require
5
- } from "./chunk-ZW4VMY5H.js";
5
+ } from "./chunk-Z3Q2AEIN.js";
6
6
 
7
7
  // node_modules/process-nextick-args/index.js
8
8
  var require_process_nextick_args = __commonJS({
@@ -4,17 +4,17 @@ import {
4
4
  } from "./chunk-Y74WTIKJ.js";
5
5
  import {
6
6
  getCliToken
7
- } from "./chunk-P7KL7IOH.js";
7
+ } from "./chunk-SOSFRU3O.js";
8
8
  import {
9
9
  getActiveHost,
10
10
  getSandboxRuntimeRoot
11
- } from "./chunk-LMCYSVVA.js";
11
+ } from "./chunk-4PSTYEG5.js";
12
12
  import {
13
13
  PermissionError,
14
14
  externalCliTokenRequestOptions,
15
15
  isApiErrorType,
16
16
  readExternalCliToken
17
- } from "./chunk-ZW4VMY5H.js";
17
+ } from "./chunk-Z3Q2AEIN.js";
18
18
 
19
19
  // src/core/te-agent-credentials.ts
20
20
  import { readFileSync } from "fs";
@@ -0,0 +1,132 @@
1
+ import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
+ import {
3
+ canManageGlobalSkills,
4
+ fetchCliConfig,
5
+ getLocalCliPackageInfo,
6
+ isBusinessSkillContextCurrent,
7
+ rememberBusinessConfig,
8
+ reserveBusinessSkillContext,
9
+ syncBusinessSkills
10
+ } from "./chunk-GBSACKFB.js";
11
+ import {
12
+ peekCliToken
13
+ } from "./chunk-SOSFRU3O.js";
14
+ import {
15
+ getActiveHost,
16
+ getConfigDir
17
+ } from "./chunk-4PSTYEG5.js";
18
+ import {
19
+ normalizeUrl
20
+ } from "./chunk-Z3Q2AEIN.js";
21
+
22
+ // src/core/environment-refresh.ts
23
+ import crypto from "crypto";
24
+ import fs from "fs";
25
+ import path from "path";
26
+ function cliTokenFingerprint(token) {
27
+ return crypto.createHash("sha256").update(token).digest("hex");
28
+ }
29
+ function invalidateBusinessSkillSynchronization() {
30
+ if (canManageGlobalSkills()) reserveBusinessSkillContext({});
31
+ }
32
+ async function refreshEnvironmentConfig(host, options = {}) {
33
+ const normalized = normalizeUrl(host);
34
+ const skipped = (reason) => ({
35
+ host: normalized,
36
+ businesses: {},
37
+ source: "unavailable",
38
+ skills: { status: "skipped", reason }
39
+ });
40
+ let token;
41
+ try {
42
+ token = peekCliToken(normalized);
43
+ } catch {
44
+ return skipped("Credentials could not be read. Sign in before refreshing Skills.");
45
+ }
46
+ if (!token) return skipped("Sign in to this environment before refreshing its business configuration.");
47
+ const fingerprint = cliTokenFingerprint(token);
48
+ const localActiveEnvironment = () => {
49
+ try {
50
+ return canManageGlobalSkills() && normalizeUrl(getActiveHost()) === normalized && cliTokenFingerprint(peekCliToken(normalized) ?? "") === fingerprint;
51
+ } catch {
52
+ return false;
53
+ }
54
+ };
55
+ const synchronize = options.synchronizeSkills !== false && localActiveEnvironment();
56
+ const generation = synchronize ? reserveBusinessSkillContext({ host: normalized, tokenFingerprint: fingerprint }) : void 0;
57
+ let config;
58
+ try {
59
+ config = await (options.fetchConfig ?? fetchCliConfig)(normalized, token);
60
+ } catch {
61
+ config = null;
62
+ }
63
+ if (!config) return skipped("CLI configuration is unavailable; existing Skills were preserved.");
64
+ if (generation && !isBusinessSkillContextCurrent({
65
+ host: normalized,
66
+ tokenFingerprint: fingerprint,
67
+ generation,
68
+ isCurrentContext: localActiveEnvironment
69
+ })) {
70
+ return {
71
+ host: normalized,
72
+ businesses: {},
73
+ source: "remote",
74
+ skills: { status: "skipped", reason: "A newer environment refresh superseded this response." }
75
+ };
76
+ }
77
+ rememberBusinessConfig(normalized, token, config.businesses);
78
+ const result = {
79
+ host: normalized,
80
+ businesses: config.businesses ?? {},
81
+ source: "remote",
82
+ skills: { status: "skipped", reason: "Only an explicitly refreshed active local environment changes global Skills." }
83
+ };
84
+ if (config.businesses === void 0) {
85
+ result.skills = { status: "skipped", reason: "This server does not provide business states; existing Skills were preserved." };
86
+ return result;
87
+ }
88
+ if (!synchronize || !localActiveEnvironment()) return result;
89
+ try {
90
+ const syncOptions = {
91
+ skillsDirectory: path.join(getLocalCliPackageInfo().root, "skills"),
92
+ host: normalized,
93
+ tokenFingerprint: fingerprint,
94
+ businesses: config.businesses,
95
+ packageVersion: getLocalCliPackageInfo().version,
96
+ generation,
97
+ isCurrentContext: localActiveEnvironment
98
+ };
99
+ if (!fs.existsSync(path.join(getConfigDir(), "business-skills.json"))) {
100
+ const adoption = syncBusinessSkills({ ...syncOptions, mode: "adopt" });
101
+ if (["failed", "busy", "stale"].includes(adoption.status)) {
102
+ result.skills = adoption;
103
+ return result;
104
+ }
105
+ }
106
+ result.skills = syncBusinessSkills(syncOptions);
107
+ } catch {
108
+ result.skills = { status: "failed", reason: "Skill synchronization could not complete. Retry: ae-cli config refresh" };
109
+ }
110
+ return result;
111
+ }
112
+ async function refreshEnvironmentAfterLogin(host) {
113
+ try {
114
+ const result = await refreshEnvironmentConfig(host);
115
+ if (!["success", "skipped"].includes(result.skills.status)) {
116
+ process.stderr.write("[ae-cli] Some Skills could not be synchronized. Run: ae-cli config refresh\n");
117
+ }
118
+ if (result.source === "unavailable") {
119
+ process.stderr.write("[ae-cli] Business configuration could not be refreshed. Sign in if needed, then run: ae-cli config refresh\n");
120
+ }
121
+ return result;
122
+ } catch {
123
+ process.stderr.write("[ae-cli] Business configuration could not be refreshed. Retry: ae-cli config refresh\n");
124
+ return void 0;
125
+ }
126
+ }
127
+
128
+ export {
129
+ invalidateBusinessSkillSynchronization,
130
+ refreshEnvironmentConfig,
131
+ refreshEnvironmentAfterLogin
132
+ };
@@ -5,14 +5,14 @@ import {
5
5
  require_node,
6
6
  require_process_nextick_args,
7
7
  require_util
8
- } from "./chunk-T44M3PLZ.js";
8
+ } from "./chunk-JEUXDY3B.js";
9
9
  import {
10
10
  __commonJS,
11
11
  __esm,
12
12
  __export,
13
13
  __require,
14
14
  __toCommonJS
15
- } from "./chunk-ZW4VMY5H.js";
15
+ } from "./chunk-Z3Q2AEIN.js";
16
16
 
17
17
  // node_modules/readdir-glob/node_modules/minimatch/lib/path.js
18
18
  var require_path = __commonJS({
@@ -5,11 +5,11 @@ import {
5
5
  require_node,
6
6
  require_process_nextick_args,
7
7
  require_util
8
- } from "./chunk-T44M3PLZ.js";
8
+ } from "./chunk-JEUXDY3B.js";
9
9
  import {
10
10
  __commonJS,
11
11
  __require
12
- } from "./chunk-ZW4VMY5H.js";
12
+ } from "./chunk-Z3Q2AEIN.js";
13
13
 
14
14
  // node_modules/jszip/node_modules/readable-stream/lib/internal/streams/stream.js
15
15
  var require_stream = __commonJS({
@@ -1,18 +1,21 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
2
  import {
3
3
  CapabilityGatewayError
4
- } from "./chunk-MXV3PYC3.js";
4
+ } from "./chunk-UYJMEHAF.js";
5
5
  import {
6
6
  SecureStoreAuthError,
7
7
  getCliToken
8
- } from "./chunk-P7KL7IOH.js";
8
+ } from "./chunk-SOSFRU3O.js";
9
9
  import {
10
10
  safeJsonParse
11
- } from "./chunk-LMCYSVVA.js";
11
+ } from "./chunk-4PSTYEG5.js";
12
12
  import {
13
13
  PermissionError,
14
- externalCliTokenRequestOptions
15
- } from "./chunk-ZW4VMY5H.js";
14
+ externalCliTokenRequestOptions,
15
+ isKbQueryPath,
16
+ kbReadHeaders,
17
+ readKbExecutionContext
18
+ } from "./chunk-Z3Q2AEIN.js";
16
19
 
17
20
  // src/core/mcp-access.ts
18
21
  function buildUrl(host, path, params = {}) {
@@ -218,18 +221,36 @@ async function getAuthHeaders(ctx) {
218
221
  return { "cli-token": cliToken };
219
222
  }
220
223
  async function kbApi(ctx, method, path, params = {}, body, options = {}) {
221
- const host = ctx.host();
222
224
  const upperMethod = method.toUpperCase();
225
+ const isQuery = isKbQueryPath(upperMethod, path);
226
+ const execution = isQuery ? readKbExecutionContext() : void 0;
227
+ const host = execution ? ctx.hostOverride?.() || execution.origin : ctx.host();
228
+ const selectedHost = execution && !ctx.hostOverride ? ctx.host() : host;
229
+ const url = buildUrl(selectedHost, path, params);
230
+ const queryHeaders = isQuery ? kbReadHeaders(url, ctx.str("read-context")) : void 0;
231
+ const init = {
232
+ method: upperMethod,
233
+ headers: { "Content-Type": "application/json", ...queryHeaders },
234
+ body: upperMethod === "GET" ? void 0 : JSON.stringify(body ?? {})
235
+ };
236
+ if (execution) {
237
+ const response = await fetch(url, { ...init, redirect: "error" });
238
+ const text = await response.text();
239
+ if (!response.ok) {
240
+ let code = "KB_READ_CONTEXT_REQUEST_FAILED";
241
+ try {
242
+ const value = responseErrorMetadata(safeJsonParse(text)).code;
243
+ if (value?.startsWith("KB_READ_CONTEXT_")) code = value;
244
+ } catch {
245
+ }
246
+ throw new KbHttpError(code, code, response.status);
247
+ }
248
+ return parseKbResponse(response, text, { ...options, redactErrorDetails: true });
249
+ }
223
250
  return requestWithCliToken(
224
251
  host,
225
- buildUrl(host, path, params),
226
- {
227
- method: upperMethod,
228
- headers: {
229
- "Content-Type": "application/json"
230
- },
231
- body: upperMethod === "GET" ? void 0 : JSON.stringify(body ?? {})
232
- },
252
+ url,
253
+ init,
233
254
  options
234
255
  );
235
256
  }
@@ -6,14 +6,14 @@ import {
6
6
  readSandboxCliTokenEntry,
7
7
  safeJsonParse,
8
8
  safeReadJsonFile
9
- } from "./chunk-LMCYSVVA.js";
9
+ } from "./chunk-4PSTYEG5.js";
10
10
  import {
11
11
  PermissionError,
12
12
  externalCliTokenRequestOptions,
13
13
  logger,
14
14
  normalizeUrl,
15
15
  readExternalCliToken
16
- } from "./chunk-ZW4VMY5H.js";
16
+ } from "./chunk-Z3Q2AEIN.js";
17
17
 
18
18
  // src/core/secure-store.ts
19
19
  import crypto from "crypto";
@@ -6,14 +6,15 @@ import {
6
6
  SecureStoreAuthError,
7
7
  clearCliTokenCache,
8
8
  getCliToken
9
- } from "./chunk-P7KL7IOH.js";
9
+ } from "./chunk-SOSFRU3O.js";
10
10
  import {
11
- safeJsonParse
12
- } from "./chunk-LMCYSVVA.js";
11
+ safeJsonParse,
12
+ stringifyJsonRequest
13
+ } from "./chunk-4PSTYEG5.js";
13
14
  import {
14
15
  PermissionError,
15
16
  externalCliTokenRequestOptions
16
- } from "./chunk-ZW4VMY5H.js";
17
+ } from "./chunk-Z3Q2AEIN.js";
17
18
 
18
19
  // src/core/cli-agent-context.ts
19
20
  import { readFileSync, statSync } from "fs";
@@ -326,7 +327,10 @@ function parseCapabilityResponse(text) {
326
327
  return text;
327
328
  }
328
329
  }
329
- function parseCapabilityEnvelope(body) {
330
+ function isCommunityGatewayRequest(domain, pathAfterV1) {
331
+ return domain.replace(/^\/+|\/+$/g, "") === "community" || /^capabilities\/community\./.test(pathAfterV1.replace(/^\/+/, ""));
332
+ }
333
+ function parseCapabilityEnvelope(body, acceptCommunityLegacyEnvelope = false) {
330
334
  if (body == null) {
331
335
  throw new CapabilityGatewayError("Empty capability gateway response");
332
336
  }
@@ -351,10 +355,32 @@ function parseCapabilityEnvelope(body) {
351
355
  err.type === "validation" ? "validation" : "api"
352
356
  );
353
357
  }
358
+ const legacyReturnCode = acceptCommunityLegacyEnvelope ? body.return_code ?? body.returnCode : void 0;
359
+ if (legacyReturnCode !== void 0 && Number(legacyReturnCode) !== 0) {
360
+ const code = String(legacyReturnCode);
361
+ const rawMessage = nonEmptyString(body.return_message) ?? nonEmptyString(body.returnMessage) ?? nonEmptyString(body.message);
362
+ const message = safeLegacyErrorMessage(rawMessage, code);
363
+ throw new CapabilityGatewayError(
364
+ message,
365
+ code,
366
+ void 0,
367
+ "The community service returned a legacy error envelope. Verify that the capability gateway route is deployed on the current host.",
368
+ { legacy_return_code: legacyReturnCode }
369
+ );
370
+ }
371
+ if (legacyReturnCode !== void 0 && Number(legacyReturnCode) === 0 && "data" in body) {
372
+ return { ok: true, data: body.data };
373
+ }
354
374
  return { ok: true, data: body };
355
375
  }
356
- function unwrapCapabilityEnvelope(body) {
357
- return parseCapabilityEnvelope(body).data;
376
+ function safeLegacyErrorMessage(message, code) {
377
+ if (!message || /\n\s*at\s|stacktrace|\.java:\d+/i.test(message)) {
378
+ return `Capability service request failed (legacy return code ${code})`;
379
+ }
380
+ return message.slice(0, 500);
381
+ }
382
+ function unwrapCapabilityEnvelope(body, acceptCommunityLegacyEnvelope = false) {
383
+ return parseCapabilityEnvelope(body, acceptCommunityLegacyEnvelope).data;
358
384
  }
359
385
  function nonEmptyString(value) {
360
386
  return typeof value === "string" && value.trim() ? value.trim() : void 0;
@@ -407,7 +433,7 @@ async function requestOnce(url, method, token, body, accept = "application/json"
407
433
  const init = { method, headers };
408
434
  if (body !== void 0 && method !== "GET") {
409
435
  headers["Content-Type"] = "application/json";
410
- init.body = JSON.stringify(includeClientContextInBody ? withCliAgentContextBody(body, agentContext) : body);
436
+ init.body = stringifyJsonRequest(includeClientContextInBody ? withCliAgentContextBody(body, agentContext) : body);
411
437
  }
412
438
  return fetch(url, { ...init, ...externalCliTokenRequestOptions(url) });
413
439
  }
@@ -447,7 +473,10 @@ async function callGatewayWithEnvelope(host, domain, pathAfterV1, method, body,
447
473
  if (!resp.ok) {
448
474
  await throwCapabilityHttpError(resp);
449
475
  }
450
- return parseCapabilityEnvelope(parseCapabilityResponse(await resp.text()));
476
+ return parseCapabilityEnvelope(
477
+ parseCapabilityResponse(await resp.text()),
478
+ isCommunityGatewayRequest(domain, pathAfterV1)
479
+ );
451
480
  }
452
481
  async function fetchCapabilityGateway(host, domain, pathAfterV1, method = "GET", body, accept = "application/json") {
453
482
  const url = buildCapabilityGatewayUrl(host, domain, pathAfterV1);
@@ -467,11 +496,17 @@ async function fetchCapabilityGateway(host, domain, pathAfterV1, method = "GET",
467
496
  }
468
497
  async function requestCapabilityGateway(host, domain, pathAfterV1, method = "GET", body) {
469
498
  const resp = await fetchCapabilityGateway(host, domain, pathAfterV1, method, body);
470
- return unwrapCapabilityEnvelope(parseCapabilityResponse(await resp.text()));
499
+ return unwrapCapabilityEnvelope(
500
+ parseCapabilityResponse(await resp.text()),
501
+ isCommunityGatewayRequest(domain, pathAfterV1)
502
+ );
471
503
  }
472
504
  async function requestCapabilityGatewayWithEnvelope(host, domain, pathAfterV1, method = "GET", body) {
473
505
  const resp = await fetchCapabilityGateway(host, domain, pathAfterV1, method, body);
474
- return parseCapabilityEnvelope(parseCapabilityResponse(await resp.text()));
506
+ return parseCapabilityEnvelope(
507
+ parseCapabilityResponse(await resp.text()),
508
+ isCommunityGatewayRequest(domain, pathAfterV1)
509
+ );
475
510
  }
476
511
  async function listCapabilitiesWithEnvelope(host, domain, projectId) {
477
512
  return callGatewayWithEnvelope(host, domain, "capabilities", "GET", void 0, { project_id: projectId });
@@ -552,7 +587,10 @@ async function uploadInputFileBytes(host, domain, projectId, purpose, bytes, fil
552
587
  if (!resp.ok) {
553
588
  await throwCapabilityHttpError(resp);
554
589
  }
555
- return unwrapCapabilityEnvelope(parseCapabilityResponse(await resp.text()));
590
+ return unwrapCapabilityEnvelope(
591
+ parseCapabilityResponse(await resp.text()),
592
+ isCommunityGatewayRequest(domain, "input-files")
593
+ );
556
594
  }
557
595
  async function callCapabilityApi(host, domain, action, method = "POST", params = {}, options = {}) {
558
596
  const isGet = method === "GET";
@@ -10,10 +10,10 @@ import {
10
10
  postToMainApp,
11
11
  putToMainApp,
12
12
  uploadToMainApp
13
- } from "./chunk-2UWS5CUP.js";
13
+ } from "./chunk-JSBLCLFE.js";
14
14
  import {
15
15
  clearCliTokenCache
16
- } from "./chunk-P7KL7IOH.js";
16
+ } from "./chunk-SOSFRU3O.js";
17
17
 
18
18
  // src/core/resource-package-client.ts
19
19
  function checkPath(path) {
@@ -0,0 +1,222 @@
1
+ import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
+ import {
3
+ getPendingHostCompatNotice,
4
+ getPendingUpdateNotice
5
+ } from "./chunk-GBSACKFB.js";
6
+ import {
7
+ logger,
8
+ redactExternalCliToken
9
+ } from "./chunk-Z3Q2AEIN.js";
10
+
11
+ // src/framework/output.ts
12
+ import Table from "cli-table3";
13
+ import { JqError, json as jqJson } from "jq-wasm";
14
+ var KNOWN_ARRAY_FIELDS = [
15
+ "items",
16
+ "events",
17
+ "reports",
18
+ "dashboards",
19
+ "tags",
20
+ "clusters",
21
+ "flows",
22
+ "tasks",
23
+ "channels",
24
+ "nodes",
25
+ "members",
26
+ "records",
27
+ "entities",
28
+ "metrics",
29
+ "tables",
30
+ "columns",
31
+ "properties"
32
+ ];
33
+ var OUTPUT_METADATA = /* @__PURE__ */ Symbol("ae-cli-output-metadata");
34
+ function withOutputMetadata(data, meta) {
35
+ if (!meta || Object.keys(meta).length === 0) return data;
36
+ if (isOutputWithMetadata(data)) {
37
+ return {
38
+ [OUTPUT_METADATA]: true,
39
+ data: data.data,
40
+ meta: { ...data.meta, ...meta }
41
+ };
42
+ }
43
+ return {
44
+ [OUTPUT_METADATA]: true,
45
+ data,
46
+ meta
47
+ };
48
+ }
49
+ function isOutputWithMetadata(value) {
50
+ return Boolean(value?.[OUTPUT_METADATA]);
51
+ }
52
+ function unwrapOutputData(value) {
53
+ return isOutputWithMetadata(value) ? value.data : value;
54
+ }
55
+ function readOutputMetadata(value) {
56
+ return isOutputWithMetadata(value) ? value.meta : void 0;
57
+ }
58
+ function findArrayField(data) {
59
+ if (Array.isArray(data)) return { rows: data };
60
+ if (typeof data !== "object" || data === null) return null;
61
+ for (const key of KNOWN_ARRAY_FIELDS) {
62
+ if (Array.isArray(data[key])) return { key, rows: data[key] };
63
+ }
64
+ for (const key of Object.keys(data)) {
65
+ if (Array.isArray(data[key])) return { key, rows: data[key] };
66
+ }
67
+ return null;
68
+ }
69
+ function formatTable(data) {
70
+ if (Array.isArray(data?.title) && data.title.length > 0 && Array.isArray(data?.rows)) {
71
+ const headers = data.title.map((value) => String(value));
72
+ const table2 = new Table({ head: headers, wordWrap: true });
73
+ for (const row of data.rows) {
74
+ const values = Array.isArray(row) ? row : [row];
75
+ table2.push(headers.map((_header, index) => {
76
+ const value = values[index];
77
+ if (value === void 0 || value === null) return "";
78
+ if (typeof value === "object") return JSON.stringify(value);
79
+ return String(value);
80
+ }));
81
+ }
82
+ return table2.toString();
83
+ }
84
+ const arrayField = findArrayField(data);
85
+ if (!arrayField || arrayField.rows.length === 0) {
86
+ return JSON.stringify(data, null, 2);
87
+ }
88
+ const rows = arrayField.rows;
89
+ const allKeys = /* @__PURE__ */ new Set();
90
+ for (const row of rows) {
91
+ if (typeof row === "object" && row !== null) {
92
+ Object.keys(row).forEach((k) => allKeys.add(k));
93
+ }
94
+ }
95
+ const keys = Array.from(allKeys);
96
+ if (keys.length === 0) return JSON.stringify(rows, null, 2);
97
+ const table = new Table({ head: keys, wordWrap: true });
98
+ for (const row of rows) {
99
+ table.push(keys.map((k) => {
100
+ const v = row?.[k];
101
+ if (v === void 0 || v === null) return "";
102
+ if (typeof v === "object") return JSON.stringify(v);
103
+ return String(v);
104
+ }));
105
+ }
106
+ const sections = [];
107
+ if (arrayField.key && typeof data === "object" && data !== null) {
108
+ const summaryEntries = Object.entries(data).filter(([key]) => key !== arrayField.key);
109
+ if (summaryEntries.length > 0) {
110
+ const summary = new Table({ head: ["field", "value"], wordWrap: true });
111
+ for (const [key, value] of summaryEntries) {
112
+ summary.push([key, typeof value === "object" && value !== null ? JSON.stringify(value) : String(value ?? "")]);
113
+ }
114
+ sections.push(summary.toString());
115
+ }
116
+ }
117
+ sections.push(table.toString());
118
+ return sections.join("\n\n");
119
+ }
120
+ async function applyJq(data, expr) {
121
+ const trimmed = expr.trim();
122
+ if (!trimmed) return data;
123
+ let results;
124
+ try {
125
+ results = await jqJson(data ?? null, trimmed);
126
+ } catch (err) {
127
+ const message = err instanceof JqError ? err.message : err?.message || String(err);
128
+ const error = new Error(`Invalid --jq expression: ${message}`);
129
+ error.type = "validation";
130
+ error.code = "OUTPUT_PROJECTION_FAILED";
131
+ error.hint = "The command completed. Original data and metadata are preserved in stdout; fix the jq expression locally without executing the command again. --jq applies to the command data before envelope wrapping.";
132
+ throw error;
133
+ }
134
+ if (results.length === 0) return null;
135
+ if (results.length === 1) return results[0];
136
+ return results;
137
+ }
138
+ async function formatOutput(data, format, jqExpr) {
139
+ const outputData = isOutputWithMetadata(data) ? data.data : data;
140
+ const meta = isOutputWithMetadata(data) ? data.meta : void 0;
141
+ let processed = outputData;
142
+ if (jqExpr) {
143
+ processed = await applyJq(outputData, jqExpr);
144
+ }
145
+ if (format === "table") {
146
+ return redactExternalCliToken(formatTable(processed));
147
+ }
148
+ const hostCompat = getPendingHostCompatNotice();
149
+ const updateNotice = getPendingUpdateNotice();
150
+ const notices = {
151
+ ...updateNotice ? {} : hostCompat ? { host_compat: hostCompat } : {},
152
+ ...updateNotice ? { update: updateNotice } : {}
153
+ };
154
+ const envelope = {
155
+ ok: true,
156
+ data: processed,
157
+ ...meta ? { meta } : {},
158
+ // Soft tip lives only under _notice (not mirrored into meta) to avoid duplicate fields.
159
+ ...Object.keys(notices).length > 0 ? { _notice: notices } : {}
160
+ };
161
+ return redactExternalCliToken(JSON.stringify(envelope, null, 2));
162
+ }
163
+ function formatError(type, message, hint, code, meta, details) {
164
+ const envelope = {
165
+ ok: false,
166
+ error: { type, message, hint, code, ...details === void 0 ? {} : { details } },
167
+ ...meta && Object.keys(meta).length > 0 ? { meta } : {}
168
+ };
169
+ return redactExternalCliToken(JSON.stringify(envelope, null, 2));
170
+ }
171
+ function printError(type, message, hint, code, meta, options = {}) {
172
+ const formatted = formatError(type, message, hint, code, meta, options.details);
173
+ process.stderr.write(formatted + "\n");
174
+ if (options.log !== false) {
175
+ logger.error(`[${type}] ${message}${hint ? " | " + hint : ""}`);
176
+ }
177
+ }
178
+ function sensitiveRecoveryData(data) {
179
+ const safe = {};
180
+ const item = {};
181
+ if (typeof data?.item?.id === "string") item.id = data.item.id;
182
+ if (Number.isSafeInteger(data?.item?.contentRevision)) item.contentRevision = data.item.contentRevision;
183
+ if (Object.keys(item).length > 0) safe.item = item;
184
+ if (["markdown", "text"].includes(data?.contentFormat)) safe.contentFormat = data.contentFormat;
185
+ if (typeof data?.out === "string") safe.out = data.out;
186
+ return safe;
187
+ }
188
+ async function printOutput(data, format, jqExpr, options = {}) {
189
+ try {
190
+ process.stdout.write(await formatOutput(data, format, jqExpr) + "\n");
191
+ } catch (error) {
192
+ if (error?.code === "OUTPUT_PROJECTION_FAILED") {
193
+ if (options.redactErrors) {
194
+ error.message = "Invalid --jq expression: output projection failed; source content is omitted from diagnostics.";
195
+ error.hint = "The read completed. Fix --jq and explicitly run read-text again without --out, or inspect the file at data.out if present. This error result excludes source content.";
196
+ }
197
+ const recovery = JSON.parse(formatError(
198
+ "validation",
199
+ error.message,
200
+ error.hint,
201
+ error.code,
202
+ options.redactErrors ? void 0 : readOutputMetadata(data)
203
+ ));
204
+ const recoveryData = options.redactErrors ? sensitiveRecoveryData(unwrapOutputData(data)) : unwrapOutputData(data);
205
+ await new Promise((resolve, reject) => {
206
+ process.stdout.write(
207
+ redactExternalCliToken(JSON.stringify({ ...recovery, data: recoveryData }, null, 2)) + "\n",
208
+ (error2) => error2 ? reject(error2) : resolve()
209
+ );
210
+ });
211
+ }
212
+ throw error;
213
+ }
214
+ }
215
+
216
+ export {
217
+ withOutputMetadata,
218
+ unwrapOutputData,
219
+ readOutputMetadata,
220
+ printError,
221
+ printOutput
222
+ };
@@ -2,7 +2,7 @@ import { createRequire as __createRequire } from 'node:module'; const require =
2
2
  import {
3
3
  CliValidationError,
4
4
  logger
5
- } from "./chunk-ZW4VMY5H.js";
5
+ } from "./chunk-Z3Q2AEIN.js";
6
6
 
7
7
  // src/core/eval-endpoint.ts
8
8
  function resolveEvaluationHost(host) {