@thinkingai/ae-cli 6.1.28 → 6.1.29

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 (116) hide show
  1. package/README.md +24 -4
  2. package/README.zh.md +24 -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-NKD5Z5BQ.js → auth-OBQ5KVQM.js} +30 -12
  7. package/dist/{automation-K32V2NKP.js → automation-NAR5DDGL.js} +6 -6
  8. package/dist/{capability-4CGSL7PK.js → capability-LFSVNI5B.js} +54 -26
  9. package/dist/chunk-2UW3Y463.js +2289 -0
  10. package/dist/{chunk-QW3R6O7L.js → chunk-3SDHJOCR.js} +57 -15
  11. package/dist/chunk-6HAUVWOQ.js +132 -0
  12. package/dist/{chunk-KHS64JZQ.js → chunk-72NJKS7O.js} +4 -4
  13. package/dist/{chunk-UUD5RB36.js → chunk-7JAVT5TK.js} +3 -3
  14. package/dist/{chunk-GTPWDLTE.js → chunk-CVCTFLSO.js} +35 -14
  15. package/dist/{chunk-P7KL7IOH.js → chunk-H3K5UGYC.js} +2 -2
  16. package/dist/{chunk-P6VFCH3P.js → chunk-IN7KKL6K.js} +2 -2
  17. package/dist/{chunk-T44M3PLZ.js → chunk-JEUXDY3B.js} +1 -1
  18. package/dist/{chunk-LMCYSVVA.js → chunk-JNVVJ273.js} +51 -37
  19. package/dist/{chunk-JJJIP2XQ.js → chunk-N6XBLRB7.js} +2 -2
  20. package/dist/{chunk-QSAR3GHY.js → chunk-OAWPT7VP.js} +2 -2
  21. package/dist/{chunk-UF244C5C.js → chunk-PWXDWMCW.js} +7 -7
  22. package/dist/{chunk-2IYIYSUO.js → chunk-QVRIDN42.js} +2 -2
  23. package/dist/chunk-QZLRHGVH.js +222 -0
  24. package/dist/{chunk-GI5BMEZO.js → chunk-QZUVLFNR.js} +1 -1
  25. package/dist/{chunk-2UWS5CUP.js → chunk-RJHGDWSC.js} +3 -3
  26. package/dist/{chunk-UJ7UPRXK.js → chunk-VCZE3IWO.js} +10 -8
  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-CII6B74E.js +32 -0
  31. package/dist/{config-ASSAAIOI.js → config-YZ6O2UQ2.js} +38 -6
  32. package/dist/{context-6RWLVOM5.js → context-F6FCGTF3.js} +4 -4
  33. package/dist/{data-integration-EXSUPUDZ.js → data-integration-6UAZO4GG.js} +207 -24
  34. package/dist/{evaluation-5YT4QLCL.js → evaluation-4LO2O4AF.js} +4 -4
  35. package/dist/index.js +297 -70
  36. package/dist/{local-data-upload-client-7HCPGIS3.js → local-data-upload-client-KCMG6J62.js} +1 -1
  37. package/dist/{memory-VCYLVPMI.js → memory-HHPX3NF2.js} +6 -6
  38. package/dist/{metadata-YGI5M6OF.js → metadata-TIFY24LW.js} +16 -8
  39. package/dist/{model-DPJHSD73.js → model-7UHGWYVR.js} +4 -4
  40. package/dist/{personal-semantic-preference-76TBKAPY.js → personal-semantic-preference-WKJEGPTM.js} +7 -6
  41. package/dist/{project-semantic-XOEBO2Q5.js → project-semantic-EIQVZNHW.js} +11 -10
  42. package/dist/{sync-7PP6KQ75.js → sync-RV3OPCTI.js} +8 -7
  43. package/dist/{te-agent-PJVAPKBD.js → te-agent-5ENVZJUH.js} +11 -7
  44. package/dist/{te-analysis-OX62G5VD.js → te-analysis-USIK6ZZG.js} +185 -33
  45. package/dist/{te-community-QN3WMPNT.js → te-community-WE2UU4XV.js} +720 -228
  46. package/dist/{te-dataops-UKD2XN3E.js → te-dataops-XNMO7MBF.js} +6 -5
  47. package/dist/{te-engage-X3DIXPRA.js → te-engage-6C3HCFQR.js} +13 -12
  48. package/dist/{te-experiment-MEIIK3DP.js → te-experiment-LVTRI3QK.js} +55 -21
  49. package/dist/{te-kb-73EWDFDF.js → te-kb-TUPGMVBY.js} +409 -85
  50. package/dist/{te-system-IE7NCKC3.js → te-system-YM657FKO.js} +6 -6
  51. package/dist/{te-team-MGQ5CNRW.js → te-team-G4VEJJNL.js} +7 -6
  52. package/dist/{things-4JIBCA55.js → things-22KQWC23.js} +7 -7
  53. package/dist/{update-AX66IFMJ.js → update-XX4ILU7X.js} +11 -7
  54. package/dist/{workspace-Q5NMEKEN.js → workspace-LYDAP647.js} +6 -6
  55. package/package.json +17 -7
  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-experiment/SKILL.md +7 -1
  107. package/skills/ae-experiment/references/manage_experiment.md +18 -1
  108. package/skills/ae-experiment/references/query_experiment_detail.md +7 -0
  109. package/skills/ae-experiment/references/save_experiment.md +76 -2
  110. package/skills/ae-experiment/references/save_submit_experiment.md +7 -0
  111. package/skills/ae-kb/SKILL.md +33 -6
  112. package/skills/ae-kb/references/publication.md +81 -0
  113. package/skills/ae-kb/references/query-workflow.md +14 -1
  114. package/skills/ae-metadata/SKILL.md +2 -2
  115. package/skills/ae-metadata/references/metadata_data_table_get.md +35 -0
  116. package/dist/chunk-ELCR235M.js +0 -1429
@@ -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-2UW3Y463.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
+ };
@@ -3,7 +3,7 @@ import {
3
3
  getAgentApi,
4
4
  patchAgentApi,
5
5
  postAgentApi
6
- } from "./chunk-JJJIP2XQ.js";
6
+ } from "./chunk-N6XBLRB7.js";
7
7
 
8
8
  // src/commands/memory/cli-client.ts
9
9
  var DEFAULT_TE_CLAUDE_BASE_PATH = "/agent";
@@ -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-H3K5UGYC.js";
8
8
  import {
9
9
  getActiveHost,
10
10
  getSandboxRuntimeRoot
11
- } from "./chunk-LMCYSVVA.js";
11
+ } from "./chunk-JNVVJ273.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";
@@ -1,18 +1,21 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
- import {
3
- dryRunCapability,
4
- executeCapabilityWithEnvelope,
5
- validateCapability
6
- } from "./chunk-QW3R6O7L.js";
7
2
  import {
8
3
  resolveGatewayDomain
9
4
  } from "./chunk-KPQY44JQ.js";
10
5
  import {
11
6
  withOutputMetadata
12
- } from "./chunk-ELCR235M.js";
7
+ } from "./chunk-QZLRHGVH.js";
8
+ import {
9
+ dryRunCapability,
10
+ executeCapabilityWithEnvelope,
11
+ validateCapability
12
+ } from "./chunk-3SDHJOCR.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
  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) {
@@ -48,6 +48,139 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
48
48
  ));
49
49
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
50
50
 
51
+ // src/core/errors.ts
52
+ var PermissionError = class extends Error {
53
+ constructor(message, code, hint, details, meta) {
54
+ super(message);
55
+ this.code = code;
56
+ this.hint = hint;
57
+ this.details = details;
58
+ this.meta = meta;
59
+ this.name = "PermissionError";
60
+ }
61
+ code;
62
+ hint;
63
+ details;
64
+ meta;
65
+ };
66
+ function isApiErrorType(value) {
67
+ return value === "auth" || value === "permission" || value === "validation" || value === "not_found" || value === "api";
68
+ }
69
+ var CliValidationError = class extends Error {
70
+ code;
71
+ hint;
72
+ location;
73
+ constructor(message, options = {}) {
74
+ super(message);
75
+ this.name = "CliValidationError";
76
+ this.code = options.code;
77
+ this.hint = options.hint;
78
+ if (options.location) {
79
+ const location = {};
80
+ if (typeof options.location.segment === "number" && Number.isFinite(options.location.segment)) {
81
+ location.segment = options.location.segment;
82
+ }
83
+ if (typeof options.location.record === "number" && Number.isFinite(options.location.record)) {
84
+ location.record = options.location.record;
85
+ }
86
+ if (typeof options.location.field === "string" && options.location.field.length > 0) {
87
+ location.field = options.location.field;
88
+ }
89
+ if (Object.keys(location).length > 0) this.location = location;
90
+ }
91
+ }
92
+ };
93
+ var CliApiError = class extends Error {
94
+ code;
95
+ hint;
96
+ meta;
97
+ constructor(message, options = {}) {
98
+ super(message);
99
+ this.name = "CliApiError";
100
+ this.code = options.code;
101
+ this.hint = options.hint;
102
+ this.meta = options.meta;
103
+ }
104
+ };
105
+ var CommunityReportError = class extends Error {
106
+ code;
107
+ httpStatus;
108
+ hint;
109
+ meta;
110
+ constructor(message, options = {}) {
111
+ super(message, options.cause === void 0 ? void 0 : { cause: options.cause });
112
+ this.name = "CommunityReportError";
113
+ this.code = options.code;
114
+ this.httpStatus = options.httpStatus;
115
+ this.hint = options.hint;
116
+ this.meta = options.meta;
117
+ }
118
+ };
119
+ var LocalDataUploadError = class extends Error {
120
+ code;
121
+ httpStatus;
122
+ hint;
123
+ meta;
124
+ constructor(message, options = {}) {
125
+ super(message, options.cause === void 0 ? void 0 : { cause: options.cause });
126
+ this.name = "LocalDataUploadError";
127
+ this.code = options.code;
128
+ this.httpStatus = options.httpStatus;
129
+ this.hint = options.hint;
130
+ this.meta = options.meta;
131
+ }
132
+ };
133
+
134
+ // src/core/kb-read-context.ts
135
+ import fs from "fs";
136
+ var secrets = /* @__PURE__ */ new Set();
137
+ function fail(code) {
138
+ throw new CliValidationError(code, { code });
139
+ }
140
+ function kbExecutionContextRequired() {
141
+ return process.env.AE_KB_READ_CONTEXT_REQUIRED !== void 0 || process.env.AE_KB_READ_CONTEXT_FILE !== void 0;
142
+ }
143
+ function isKbQueryPath(method, pathname) {
144
+ return method === "POST" && /^\/(?:agent\/)?api\/external\/knowledge-bases\/(list|index|grep|read)$/.test(pathname);
145
+ }
146
+ function readKbExecutionContext() {
147
+ if (!kbExecutionContextRequired()) return void 0;
148
+ const file = process.env.AE_KB_READ_CONTEXT_FILE;
149
+ if (process.env.AE_KB_READ_CONTEXT_REQUIRED !== "1" || !file) fail("KB_READ_CONTEXT_REQUIRED");
150
+ let fd;
151
+ let data;
152
+ try {
153
+ fd = fs.openSync(file, fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW);
154
+ const stat = fs.fstatSync(fd);
155
+ if (!stat.isFile() || stat.size > 16384 || (stat.mode & 511) !== 384 || process.getuid && stat.uid !== process.getuid())
156
+ throw new Error();
157
+ data = JSON.parse(fs.readFileSync(fd, "utf8"));
158
+ if (!data || Array.isArray(data) || Object.keys(data).sort().join(",") !== "executionRef,expiresAt,formatVersion,origin,readContextId,required,token" || data.formatVersion !== 1 || data.required !== true || typeof data.executionRef !== "string" || !/^[^\s\0]{1,191}$/.test(data.executionRef) || typeof data.readContextId !== "string" || !/^[^\s\0]{1,191}$/.test(data.readContextId) || typeof data.token !== "string" || !/^cli_kbr_[A-Za-z0-9_-]{43,}$/.test(data.token) || typeof data.expiresAt !== "string" || !Number.isFinite(Date.parse(data.expiresAt)))
159
+ throw new Error();
160
+ const origin = new URL(data.origin);
161
+ if (!["http:", "https:"].includes(origin.protocol) || origin.username || origin.password || origin.origin !== data.origin)
162
+ throw new Error();
163
+ } catch {
164
+ fail("KB_READ_CONTEXT_REQUIRED");
165
+ } finally {
166
+ if (fd !== void 0) fs.closeSync(fd);
167
+ }
168
+ secrets.add(data.token);
169
+ if (Date.parse(data.expiresAt) <= Date.now()) fail("KB_READ_CONTEXT_EXPIRED");
170
+ return data;
171
+ }
172
+ function kbReadHeaders(url, explicitId) {
173
+ const context = readKbExecutionContext();
174
+ if (!context) return explicitId ? { "X-KB-Read-Context": explicitId } : void 0;
175
+ if (new URL(url).origin !== context.origin || explicitId && explicitId !== context.readContextId)
176
+ fail("KB_READ_CONTEXT_MISMATCH");
177
+ return { "cli-token": context.token, "X-KB-Read-Context": context.readContextId };
178
+ }
179
+ function redactKbReadCredential(value) {
180
+ for (const token of secrets) value = value.split(token).join("[REDACTED]");
181
+ return value.replace(/cli_kbr_[A-Za-z0-9_-]+/g, "[REDACTED]");
182
+ }
183
+
51
184
  // src/core/url-utils.ts
52
185
  function normalizeUrl(url) {
53
186
  if (!url) return url;
@@ -58,7 +191,7 @@ function normalizeUrl(url) {
58
191
  }
59
192
 
60
193
  // src/core/external-cli-token.ts
61
- import fs from "fs";
194
+ import fs2 from "fs";
62
195
  var ExternalCliTokenError = class extends Error {
63
196
  constructor(message, code = "EXTERNAL_CLI_TOKEN_INVALID") {
64
197
  super(message);
@@ -98,9 +231,9 @@ function readExternalCliToken(hostOverride) {
98
231
  if (!file.trim()) throw new ExternalCliTokenError("The external CLI token file path is empty.");
99
232
  let data;
100
233
  try {
101
- const stat = fs.statSync(file);
234
+ const stat = fs2.statSync(file);
102
235
  if (!stat.isFile() || stat.size > 64 * 1024) throw new Error();
103
- data = JSON.parse(fs.readFileSync(file, "utf8"));
236
+ data = JSON.parse(fs2.readFileSync(file, "utf8"));
104
237
  } catch {
105
238
  throw new ExternalCliTokenError("The external CLI token file must be a readable JSON file no larger than 64 KiB.");
106
239
  }
@@ -134,11 +267,11 @@ function redactExternalCliToken(value) {
134
267
  }
135
268
  const forms = [...diagnosticSecrets].flatMap((token) => [token, JSON.stringify(token).slice(1, -1), encodeURIComponent(token)]);
136
269
  for (const form of [...new Set(forms)].sort((a, b) => b.length - a.length)) value = value.split(form).join("[REDACTED]");
137
- return value;
270
+ return redactKbReadCredential(value);
138
271
  }
139
272
 
140
273
  // src/core/logger.ts
141
- import fs2 from "fs";
274
+ import fs3 from "fs";
142
275
  import path from "path";
143
276
  var LOG_DIR = path.join(process.env.HOME || "", ".ae-cli", "log");
144
277
  var Logger = class {
@@ -157,8 +290,8 @@ var Logger = class {
157
290
  return (/* @__PURE__ */ new Date()).toISOString().replace("T", " ").split(".")[0];
158
291
  }
159
292
  ensureDir() {
160
- if (!fs2.existsSync(this.logDir)) {
161
- fs2.mkdirSync(this.logDir, { recursive: true });
293
+ if (!fs3.existsSync(this.logDir)) {
294
+ fs3.mkdirSync(this.logDir, { recursive: true });
162
295
  }
163
296
  }
164
297
  filePath(level) {
@@ -176,7 +309,7 @@ var Logger = class {
176
309
  const line = `[${ts}] ${redactExternalCliToken(message)}
177
310
  `;
178
311
  try {
179
- fs2.appendFileSync(this.filePath(level), line);
312
+ fs3.appendFileSync(this.filePath(level), line);
180
313
  } catch {
181
314
  }
182
315
  }
@@ -220,89 +353,6 @@ var Logger = class {
220
353
  };
221
354
  var logger = new Logger();
222
355
 
223
- // src/core/errors.ts
224
- var PermissionError = class extends Error {
225
- constructor(message, code, hint, details, meta) {
226
- super(message);
227
- this.code = code;
228
- this.hint = hint;
229
- this.details = details;
230
- this.meta = meta;
231
- this.name = "PermissionError";
232
- }
233
- code;
234
- hint;
235
- details;
236
- meta;
237
- };
238
- function isApiErrorType(value) {
239
- return value === "auth" || value === "permission" || value === "validation" || value === "not_found" || value === "api";
240
- }
241
- var CliValidationError = class extends Error {
242
- code;
243
- hint;
244
- location;
245
- constructor(message, options = {}) {
246
- super(message);
247
- this.name = "CliValidationError";
248
- this.code = options.code;
249
- this.hint = options.hint;
250
- if (options.location) {
251
- const location = {};
252
- if (typeof options.location.segment === "number" && Number.isFinite(options.location.segment)) {
253
- location.segment = options.location.segment;
254
- }
255
- if (typeof options.location.record === "number" && Number.isFinite(options.location.record)) {
256
- location.record = options.location.record;
257
- }
258
- if (typeof options.location.field === "string" && options.location.field.length > 0) {
259
- location.field = options.location.field;
260
- }
261
- if (Object.keys(location).length > 0) this.location = location;
262
- }
263
- }
264
- };
265
- var CliApiError = class extends Error {
266
- code;
267
- hint;
268
- meta;
269
- constructor(message, options = {}) {
270
- super(message);
271
- this.name = "CliApiError";
272
- this.code = options.code;
273
- this.hint = options.hint;
274
- this.meta = options.meta;
275
- }
276
- };
277
- var CommunityReportError = class extends Error {
278
- code;
279
- httpStatus;
280
- hint;
281
- meta;
282
- constructor(message, options = {}) {
283
- super(message, options.cause === void 0 ? void 0 : { cause: options.cause });
284
- this.name = "CommunityReportError";
285
- this.code = options.code;
286
- this.httpStatus = options.httpStatus;
287
- this.hint = options.hint;
288
- this.meta = options.meta;
289
- }
290
- };
291
- var LocalDataUploadError = class extends Error {
292
- code;
293
- httpStatus;
294
- hint;
295
- meta;
296
- constructor(message, options = {}) {
297
- super(message, options.cause === void 0 ? void 0 : { cause: options.cause });
298
- this.name = "LocalDataUploadError";
299
- this.code = options.code;
300
- this.httpStatus = options.httpStatus;
301
- this.hint = options.hint;
302
- this.meta = options.meta;
303
- }
304
- };
305
-
306
356
  export {
307
357
  __require,
308
358
  __esm,
@@ -310,17 +360,21 @@ export {
310
360
  __export,
311
361
  __toESM,
312
362
  __toCommonJS,
363
+ PermissionError,
364
+ isApiErrorType,
365
+ CliValidationError,
366
+ CliApiError,
367
+ CommunityReportError,
368
+ LocalDataUploadError,
369
+ kbExecutionContextRequired,
370
+ isKbQueryPath,
371
+ readKbExecutionContext,
372
+ kbReadHeaders,
313
373
  normalizeUrl,
314
374
  ExternalCliTokenError,
315
375
  setExternalCliTokenFile,
316
376
  readExternalCliToken,
317
377
  externalCliTokenRequestOptions,
318
378
  redactExternalCliToken,
319
- logger,
320
- PermissionError,
321
- isApiErrorType,
322
- CliValidationError,
323
- CliApiError,
324
- CommunityReportError,
325
- LocalDataUploadError
379
+ logger
326
380
  };
@@ -2,7 +2,7 @@ import { createRequire as __createRequire } from 'node:module'; const require =
2
2
  import {
3
3
  CommunityReportError,
4
4
  logger
5
- } from "./chunk-ZW4VMY5H.js";
5
+ } from "./chunk-Z3Q2AEIN.js";
6
6
 
7
7
  // src/core/community-report-client.ts
8
8
  var DEFAULT_TIMEOUT_MS = 3e4;
@@ -0,0 +1,32 @@
1
+ import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
+ import {
3
+ fetchCliConfig,
4
+ formatCapabilityMissCompatHint,
5
+ getCachedCompatForHost,
6
+ getPendingHostCompatNotice,
7
+ getPendingUpdateNotice,
8
+ isCompatCacheStale,
9
+ isNonInteractiveOutput,
10
+ notifyIfHostCompat,
11
+ runHostCompatCheck,
12
+ shouldNotifyCompat,
13
+ shouldSkipAutoSync,
14
+ shouldSkipCompatCheck
15
+ } from "./chunk-2UW3Y463.js";
16
+ import "./chunk-H3K5UGYC.js";
17
+ import "./chunk-JNVVJ273.js";
18
+ import "./chunk-Z3Q2AEIN.js";
19
+ export {
20
+ fetchCliConfig,
21
+ formatCapabilityMissCompatHint,
22
+ getCachedCompatForHost,
23
+ getPendingHostCompatNotice,
24
+ getPendingUpdateNotice,
25
+ isCompatCacheStale,
26
+ isNonInteractiveOutput,
27
+ notifyIfHostCompat,
28
+ runHostCompatCheck,
29
+ shouldNotifyCompat,
30
+ shouldSkipAutoSync,
31
+ shouldSkipCompatCheck
32
+ };