@thinkingai/ae-cli 6.1.42 → 6.1.44

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 +14 -4
  2. package/README.zh.md +14 -4
  3. package/bin/ae-cli.js +3 -0
  4. package/bin/heari/commander-LICENSE +22 -0
  5. package/bin/heari/engine.mjs +6136 -0
  6. package/bin/heari/package.json +6 -0
  7. package/bin/heari.mjs +29 -0
  8. package/cli-installation-guide.md +3 -5
  9. package/dist/{ai-monitor-E62FT3TT.js → ai-monitor-4VPHXQTL.js} +7 -6
  10. package/dist/ai-monitor.js +10 -9
  11. package/dist/{auth-SDK5OAGP.js → auth-RDSS2LUT.js} +18 -16
  12. package/dist/{automation-IMDCJUML.js → automation-VLIWG2XY.js} +5 -4
  13. package/dist/{capability-F6YWGPZZ.js → capability-CUOEIB5F.js} +5 -4
  14. package/dist/{chunk-KE5WGBXS.js → chunk-3DTMWDJX.js} +1 -1
  15. package/dist/{chunk-KAZ5FWPB.js → chunk-3FSYICDW.js} +6 -5
  16. package/dist/{chunk-ZK6KEGUR.js → chunk-3TV24AVQ.js} +10 -10
  17. package/dist/{chunk-DTODOQ6T.js → chunk-3U75VLCP.js} +1 -1
  18. package/dist/{chunk-N2QILIGH.js → chunk-4MOCV6HU.js} +1 -1
  19. package/dist/{chunk-M2OCZRVX.js → chunk-6VLHJKDD.js} +2 -2
  20. package/dist/{chunk-WG27BD67.js → chunk-7KBENPQF.js} +8 -16
  21. package/dist/{chunk-CDBW5RE6.js → chunk-BFSWGXM2.js} +3 -3
  22. package/dist/{chunk-UK7HQ4IL.js → chunk-CBNE2S44.js} +2 -2
  23. package/dist/{chunk-UWQXGF44.js → chunk-FEYZBUFQ.js} +4 -353
  24. package/dist/chunk-FKTVD63C.js +369 -0
  25. package/dist/{chunk-2H3SFJE3.js → chunk-FKVG7LOP.js} +5 -3
  26. package/dist/{chunk-GTENC5CO.js → chunk-IAZ4AMVY.js} +6 -4
  27. package/dist/{chunk-ZSKLELL7.js → chunk-LSELMDKQ.js} +2 -2
  28. package/dist/{chunk-2RORKIF6.js → chunk-NJGB4YOH.js} +2 -2
  29. package/dist/{chunk-L7MT53VM.js → chunk-PWG5IGCP.js} +1 -1
  30. package/dist/{chunk-DIYDOOBL.js → chunk-TFEGYB4X.js} +2 -2
  31. package/dist/{chunk-DZRQGI2Z.js → chunk-ZPAOEDK7.js} +5 -3
  32. package/dist/{compat-check-J5K3NO5G.js → compat-check-L3C7HCVG.js} +4 -3
  33. package/dist/{config-O3W6XLHO.js → config-LAF5MMYK.js} +6 -5
  34. package/dist/context-E4YKECC4.js +350 -0
  35. package/dist/{evaluation-OZM54MES.js → evaluation-I4IJ25CY.js} +4 -3
  36. package/dist/heari-cli-login.js +83 -0
  37. package/dist/index.js +42 -34
  38. package/dist/{memory-VPOPSU52.js → memory-Y7LPCRP4.js} +5 -4
  39. package/dist/{metadata-3GA2N27I.js → metadata-T6HYAU7E.js} +7 -6
  40. package/dist/{model-2F2354QP.js → model-2BNN72MN.js} +7 -6
  41. package/dist/{personal-semantic-preference-T2HFF2V4.js → personal-semantic-preference-WCZBOA7V.js} +42 -16
  42. package/dist/{project-semantic-WJOP2HGJ.js → project-semantic-WW5AZST3.js} +266 -17
  43. package/dist/{sync-K65X7ODO.js → sync-6PL25V42.js} +13 -12
  44. package/dist/{te-agent-QWZC36YS.js → te-agent-KXLDW4NE.js} +6 -5
  45. package/dist/{te-analysis-7E2GVKOR.js → te-analysis-KKRECQ7F.js} +311 -52
  46. package/dist/{te-community-NQNSLNON.js → te-community-6RGX7IWH.js} +8 -6
  47. package/dist/{te-dataops-PMI7UX36.js → te-dataops-RSPBC6WJ.js} +726 -220
  48. package/dist/{te-engage-EZBV5IPQ.js → te-engage-FIPP5L2Z.js} +6 -5
  49. package/dist/{te-experiment-RDB3TYBG.js → te-experiment-KQ5CBYKI.js} +86 -10
  50. package/dist/{te-kb-OWPJB243.js → te-kb-XYSDXZUG.js} +32 -11
  51. package/dist/{te-system-Z4VEB6PL.js → te-system-QSOHAP7M.js} +7 -6
  52. package/dist/{te-team-NCMN34IL.js → te-team-R6MZ4RK2.js} +6 -5
  53. package/dist/{things-UBMLTY3S.js → things-DEONFUGS.js} +6 -5
  54. package/dist/{update-LYVYF3KJ.js → update-C6G4P3C7.js} +5 -4
  55. package/dist/{web-runtime-XJWDFVP3.js → web-runtime-UGKPTBOK.js} +12 -10
  56. package/dist/{workspace-W5ZPVWJS.js → workspace-OBIIE5FN.js} +5 -4
  57. package/package.json +7 -5
  58. package/skills/ae-analysis/SKILL.md +41 -16
  59. package/skills/ae-analysis/references/adhoc_export.md +1 -1
  60. package/skills/ae-analysis/references/adhoc_run.md +8 -2
  61. package/skills/ae-analysis/references/analysis_drilldown_contract.md +1 -1
  62. package/skills/ae-analysis/references/audience_scheduling.md +30 -0
  63. package/skills/ae-analysis/references/business_semantics_workspace.md +57 -0
  64. package/skills/ae-analysis/references/command_index.md +18 -13
  65. package/skills/ae-analysis/references/context_prepare.md +49 -0
  66. package/skills/ae-analysis/references/drilldown_entities_export.md +1 -1
  67. package/skills/ae-analysis/references/drilldown_entities_run.md +1 -1
  68. package/skills/ae-analysis/references/drilldown_user_events_export.md +3 -1
  69. package/skills/ae-analysis/references/drilldown_user_events_run.md +2 -1
  70. package/skills/ae-analysis/references/governance_recommendation_export.md +1 -1
  71. package/skills/ae-analysis/references/personal_semantic_preference_add.md +5 -1
  72. package/skills/ae-analysis/references/personal_semantic_preference_get.md +4 -2
  73. package/skills/ae-analysis/references/personal_semantic_preference_list.md +7 -6
  74. package/skills/ae-analysis/references/personal_semantic_preference_submit.md +1 -1
  75. package/skills/ae-analysis/references/personal_semantic_preference_update.md +5 -1
  76. package/skills/ae-analysis/references/project_info_get.md +4 -0
  77. package/skills/ae-analysis/references/project_semantic_knowledge_wiki.md +1 -1
  78. package/skills/ae-analysis/references/project_semantic_setup.md +60 -0
  79. package/skills/ae-analysis/references/report_get.md +2 -0
  80. package/skills/ae-analysis/references/report_presentation.md +55 -0
  81. package/skills/ae-analysis/references/report_update.md +4 -2
  82. package/skills/ae-analysis/references/system_openapi_token_batch_generate.md +20 -0
  83. package/skills/ae-analysis/references/system_openapi_token_get.md +14 -0
  84. package/skills/ae-analysis/references/user_cluster_create.md +3 -1
  85. package/skills/ae-analysis/references/user_cluster_models.md +2 -0
  86. package/skills/ae-analysis/references/user_cluster_update.md +5 -3
  87. package/skills/ae-analysis/references/user_tag_create.md +4 -22
  88. package/skills/ae-analysis/references/user_tag_models.md +8 -0
  89. package/skills/ae-analysis/references/user_tag_update.md +6 -14
  90. package/skills/ae-analysis/scripts/read-semantic-catalog.mjs +40 -0
  91. package/skills/ae-analysis-global/SKILL.md +2 -2
  92. package/skills/ae-capability/SKILL.md +5 -1
  93. package/skills/ae-community/SKILL.md +1 -1
  94. package/skills/ae-data-integration/SKILL.md +1 -1
  95. package/skills/ae-data-integration-helper/SKILL.md +1 -1
  96. package/skills/ae-dataops/SKILL.md +9 -6
  97. package/skills/ae-dataops/references/dataops-flow-create.md +64 -47
  98. package/skills/ae-dataops/references/dataops-flow-monitor.md +4 -2
  99. package/skills/ae-dataops/references/dataops-flow-python.md +109 -0
  100. package/skills/ae-experiment/SKILL.md +9 -1
  101. package/skills/ae-experiment/references/manage_feature_fixed_value.md +73 -0
  102. package/skills/ae-experiment/references/save_feature.md +14 -1
  103. package/skills/ae-generate-tracking-code/SKILL.md +1 -1
  104. package/skills/ae-generate-tracking-plan/SKILL.md +2 -2
  105. package/skills/ae-heari-research/SKILL.md +40 -0
  106. package/skills/ae-heari-research/references/design.md +35 -0
  107. package/skills/ae-heari-research/references/examples.md +46 -0
  108. package/skills/ae-heari-research/references/platform-auth.md +35 -0
  109. package/skills/ae-heari-research/references/platform-research.md +74 -0
  110. package/skills/ae-heari-research/references/platform-results.md +73 -0
  111. package/skills/ae-heari-research/references/platform.md +34 -0
  112. package/skills/ae-heari-research/references/probing-screening.md +31 -0
  113. package/skills/ae-heari-research/references/quality.md +44 -0
  114. package/skills/ae-kb/SKILL.md +10 -5
  115. package/skills/ae-kb/references/analysis-workflow.md +19 -10
  116. package/skills/ae-kb/references/query-workflow.md +34 -17
  117. package/skills/ae-kb-discovery/SKILL.md +4 -3
  118. package/skills/ae-migrate-tracking-code/SKILL.md +2 -2
  119. package/skills/ae-onboarding/SKILL.md +3 -3
  120. package/dist/context-WJQGJD6F.js +0 -139
  121. package/dist/{data-integration-KMJWYAKK.js → data-integration-SCYYZLWI.js} +4 -4
@@ -0,0 +1,369 @@
1
+ import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
+ import {
3
+ CredentialStoreUnreadableError,
4
+ SecureStoreAuthError,
5
+ getActiveCredential,
6
+ loadCliToken,
7
+ markCredentialRenewed
8
+ } from "./chunk-FEYZBUFQ.js";
9
+ import {
10
+ getActiveHost,
11
+ getConfigDir,
12
+ getFallbackCliToken,
13
+ readSandboxCliTokenEntry,
14
+ safeJsonParse,
15
+ safeReadJsonFile
16
+ } from "./chunk-IGU3R2JD.js";
17
+ import {
18
+ externalCliTokenRequestOptions,
19
+ logger,
20
+ normalizeUrl,
21
+ readExternalCliToken
22
+ } from "./chunk-MTK4ZE7W.js";
23
+ import {
24
+ PermissionError
25
+ } from "./chunk-3ZQY7SLZ.js";
26
+
27
+ // src/core/internal-call-source.ts
28
+ function internalCallSourceHeaders() {
29
+ return {};
30
+ }
31
+
32
+ // src/core/cli-token.ts
33
+ import crypto from "crypto";
34
+ import fs from "fs";
35
+ import path from "path";
36
+ var CLI_TOKEN_GENERATE_PATH = "/v1/ta/cli/token/generate";
37
+ var CLI_TOKEN_RENEW_PATH = "/v1/ta/cli/token/renew";
38
+ var CLI_TOKEN_VALIDATE_PATH = "/v1/ta/cli/token/validate";
39
+ function safeReturnCode(value) {
40
+ return typeof value === "number" && Number.isFinite(value) ? String(value) : void 0;
41
+ }
42
+ var CliTokenValidationUnavailableError = class extends Error {
43
+ constructor(message) {
44
+ super(message);
45
+ this.name = "CliTokenValidationUnavailableError";
46
+ }
47
+ };
48
+ function isExplicitCliTokenRejection(data, responseText) {
49
+ const code = String(data?.code ?? data?.error?.code ?? "");
50
+ const message = String(data?.return_message ?? data?.message ?? data?.error?.message ?? responseText);
51
+ return /cli[_-]?token[_-]?(invalid|expired)/i.test(code) || /cli[-_\s]?token.*\b(invalid|expired)\b/i.test(message) || /\b(invalid|expired)\b.*cli[-_\s]?token/i.test(message);
52
+ }
53
+ function cliAccessDisabledDetails(data, responseText) {
54
+ const code = String(data?.code ?? data?.error?.code ?? "");
55
+ const message = String(data?.return_message ?? data?.message ?? data?.error?.message ?? responseText);
56
+ if (code !== "CLI_ACCESS_DISABLED" && !message.includes("CLI_ACCESS_DISABLED")) return void 0;
57
+ return {
58
+ message: message || "CLI access is disabled for this account.",
59
+ hint: data?.hint ?? data?.error?.hint
60
+ };
61
+ }
62
+ function optionalNonEmptyString(...values) {
63
+ return values.find((value) => typeof value === "string" && value.trim());
64
+ }
65
+ function optionalIsoDate(...values) {
66
+ const value = values.find((candidate) => typeof candidate === "string" && candidate.trim() || typeof candidate === "number");
67
+ if (value === void 0) return void 0;
68
+ const date = new Date(value);
69
+ return Number.isFinite(date.getTime()) ? date.toISOString() : void 0;
70
+ }
71
+ var cliTokenCache = /* @__PURE__ */ new Map();
72
+ var renewedLocalDate = /* @__PURE__ */ new Map();
73
+ var renewInFlight = /* @__PURE__ */ new Map();
74
+ function tokenFingerprint(cliToken) {
75
+ return crypto.createHash("sha256").update(cliToken).digest("hex").slice(0, 16);
76
+ }
77
+ function renewKey(hostUrl, cliToken) {
78
+ return `${normalizeUrl(hostUrl)}#${tokenFingerprint(cliToken)}`;
79
+ }
80
+ function renewStateFilePath() {
81
+ return path.join(getConfigDir(), "cli-token-renew.json");
82
+ }
83
+ function localRenewDate(now = /* @__PURE__ */ new Date()) {
84
+ const y = now.getFullYear();
85
+ const m = String(now.getMonth() + 1).padStart(2, "0");
86
+ const d = String(now.getDate()).padStart(2, "0");
87
+ return `${y}-${m}-${d}`;
88
+ }
89
+ function loadRenewStore() {
90
+ try {
91
+ const file = renewStateFilePath();
92
+ if (!fs.existsSync(file)) return {};
93
+ const data = safeReadJsonFile(file);
94
+ return data && typeof data === "object" && !Array.isArray(data) ? data : {};
95
+ } catch {
96
+ return {};
97
+ }
98
+ }
99
+ function saveRenewStore(store) {
100
+ const file = renewStateFilePath();
101
+ if (Object.keys(store).length === 0) {
102
+ try {
103
+ fs.rmSync(file, { force: true });
104
+ } catch {
105
+ }
106
+ return;
107
+ }
108
+ const dir = getConfigDir();
109
+ if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
110
+ fs.writeFileSync(file, JSON.stringify(store, null, 2), { encoding: "utf8", mode: 384 });
111
+ try {
112
+ fs.chmodSync(file, 384);
113
+ } catch {
114
+ }
115
+ }
116
+ function persistedRenewDate(hostUrl, cliToken) {
117
+ const credential = getActiveCredential(hostUrl);
118
+ if (credential?.cliToken === cliToken && credential.lastRenewedOn) return credential.lastRenewedOn;
119
+ return loadRenewStore()[renewKey(hostUrl, cliToken)]?.date;
120
+ }
121
+ function markRenewSucceeded(hostUrl, cliToken, date) {
122
+ const key = renewKey(hostUrl, cliToken);
123
+ renewedLocalDate.set(key, date);
124
+ markCredentialRenewed(hostUrl, cliToken, date);
125
+ const store = loadRenewStore();
126
+ store[key] = { date };
127
+ saveRenewStore(store);
128
+ }
129
+ function clearCliTokenCache(hostUrl) {
130
+ if (!hostUrl) {
131
+ cliTokenCache.clear();
132
+ renewedLocalDate.clear();
133
+ renewInFlight.clear();
134
+ return;
135
+ }
136
+ const normalizedHost = normalizeUrl(hostUrl);
137
+ cliTokenCache.delete(normalizedHost);
138
+ for (const key of [...renewedLocalDate.keys()]) {
139
+ if (key.startsWith(`${normalizedHost}#`)) renewedLocalDate.delete(key);
140
+ }
141
+ for (const key of [...renewInFlight.keys()]) {
142
+ if (key.startsWith(`${normalizedHost}#`)) renewInFlight.delete(key);
143
+ }
144
+ }
145
+ async function generateCliToken(hostUrl, accessToken, signal) {
146
+ if (!accessToken) throw new Error("CLI token generation requires the access token returned by auth login.");
147
+ const url = `${hostUrl.replace(/\/+$/, "")}${CLI_TOKEN_GENERATE_PATH}`;
148
+ const resp = await fetch(url, {
149
+ method: "GET",
150
+ headers: { Authorization: `bearer ${accessToken}`, ...internalCallSourceHeaders() },
151
+ signal,
152
+ ...signal ? { redirect: "error" } : {}
153
+ });
154
+ if (!resp.ok) {
155
+ if (resp.status === 403) {
156
+ const text = await resp.text();
157
+ let body = {};
158
+ try {
159
+ body = text ? safeJsonParse(text) : {};
160
+ } catch {
161
+ }
162
+ const serviceMessage = body.message ?? body.return_message;
163
+ const code = body.code === "CLI_ACCESS_DISABLED" || String(serviceMessage).includes("CLI_ACCESS_DISABLED") ? "CLI_ACCESS_DISABLED" : void 0;
164
+ throw new PermissionError(
165
+ code === "CLI_ACCESS_DISABLED" ? "CLI access is disabled for this account." : "You do not have permission to generate a CLI token.",
166
+ code
167
+ );
168
+ }
169
+ throw new Error(`CLI token generate HTTP error: ${resp.status} ${resp.statusText}`);
170
+ }
171
+ const data = safeJsonParse(await resp.text());
172
+ if (data.return_code !== 0) {
173
+ const serviceMessage = data.return_message || data.message;
174
+ if (data.code === "CLI_ACCESS_DISABLED" || String(serviceMessage).includes("CLI_ACCESS_DISABLED")) {
175
+ throw new PermissionError(
176
+ "CLI access is disabled for this account.",
177
+ "CLI_ACCESS_DISABLED"
178
+ );
179
+ }
180
+ const code = safeReturnCode(data.return_code);
181
+ throw new Error(`CLI token generation failed${code ? ` (code: ${code})` : ""}`);
182
+ }
183
+ const cliToken = data.data?.userSecret ?? data.data?.user_secret;
184
+ if (!cliToken) throw new Error("CLI token generate error: empty userSecret in response");
185
+ return cliToken;
186
+ }
187
+ async function validateCliTokenOnServer(hostUrl, cliToken, signal) {
188
+ const url = `${hostUrl.replace(/\/+$/, "")}${CLI_TOKEN_VALIDATE_PATH}`;
189
+ let resp;
190
+ try {
191
+ resp = await fetch(url, {
192
+ method: "GET",
193
+ headers: { Accept: "application/json", "cli-token": cliToken, ...internalCallSourceHeaders() },
194
+ ...externalCliTokenRequestOptions(url),
195
+ ...signal ? { redirect: "error" } : {},
196
+ signal
197
+ });
198
+ } catch (error) {
199
+ signal?.throwIfAborted();
200
+ throw new CliTokenValidationUnavailableError(`Unable to validate CLI token for ${hostUrl}: ${error.message}`);
201
+ }
202
+ const responseText = await resp.text();
203
+ let body;
204
+ try {
205
+ body = safeJsonParse(responseText);
206
+ } catch {
207
+ body = void 0;
208
+ }
209
+ const accessDisabled = cliAccessDisabledDetails(body, responseText);
210
+ if (accessDisabled) {
211
+ throw new PermissionError(accessDisabled.message, "CLI_ACCESS_DISABLED", accessDisabled.hint);
212
+ }
213
+ if (isExplicitCliTokenRejection(body, responseText)) {
214
+ throw new SecureStoreAuthError(`CLI token is invalid or expired for ${hostUrl}.`);
215
+ }
216
+ if (!resp.ok) {
217
+ throw new CliTokenValidationUnavailableError(
218
+ `CLI token validation is unavailable for ${hostUrl} (HTTP ${resp.status} ${resp.statusText})`
219
+ );
220
+ }
221
+ if (body?.return_code !== 0) {
222
+ throw new CliTokenValidationUnavailableError(`CLI token validation returned an unsupported response for ${hostUrl}`);
223
+ }
224
+ const data = body?.data;
225
+ const openId = optionalNonEmptyString(data?.openId, data?.open_id);
226
+ const loginName = optionalNonEmptyString(data?.loginName, data?.login_name);
227
+ const userName = optionalNonEmptyString(data?.userName, data?.user_name);
228
+ const account = openId && loginName && userName ? { openId, loginName, userName } : void 0;
229
+ const cliTokenExpiresAt = optionalIsoDate(data?.expiresAt, data?.expires_at);
230
+ return {
231
+ ...account ? { account } : {},
232
+ ...cliTokenExpiresAt ? { cliTokenExpiresAt } : {}
233
+ };
234
+ }
235
+ async function renewCliTokenOnServer(hostUrl, cliToken, external = false, signal) {
236
+ const url = new URL(`${hostUrl.replace(/\/+$/, "")}${CLI_TOKEN_RENEW_PATH}`);
237
+ if (!external) url.searchParams.set("cli-token", cliToken);
238
+ const resp = await fetch(url.toString(), {
239
+ method: "GET",
240
+ headers: { Accept: "application/json", ...external ? { "cli-token": cliToken } : {}, ...internalCallSourceHeaders() },
241
+ ...externalCliTokenRequestOptions(url.toString()),
242
+ signal
243
+ });
244
+ const text = await resp.text();
245
+ let data;
246
+ try {
247
+ data = text ? safeJsonParse(text) : {};
248
+ } catch {
249
+ data = {};
250
+ }
251
+ if (!resp.ok) throw new Error(`CLI token renew HTTP error: ${resp.status} ${resp.statusText}`);
252
+ if (data?.return_code !== void 0 && data.return_code !== 0) {
253
+ throw new Error(`CLI token renew error: ${data.return_message || "unknown"} (code: ${data.return_code})`);
254
+ }
255
+ }
256
+ async function maybeRenewCliTokenDaily(hostUrl, cliToken, external = false, signal) {
257
+ signal?.throwIfAborted();
258
+ const key = renewKey(hostUrl, cliToken);
259
+ const today = localRenewDate();
260
+ if (renewedLocalDate.get(key) === today || !external && persistedRenewDate(hostUrl, cliToken) === today) {
261
+ renewedLocalDate.set(key, today);
262
+ return;
263
+ }
264
+ let attempt = renewInFlight.get(key);
265
+ if (!attempt || attempt.controller.signal.aborted) {
266
+ const current = { controller: new AbortController(), promise: Promise.resolve(), waiters: 0 };
267
+ current.promise = (async () => {
268
+ try {
269
+ await renewCliTokenOnServer(hostUrl, cliToken, external, current.controller.signal);
270
+ current.controller.signal.throwIfAborted();
271
+ if (external) renewedLocalDate.set(key, today);
272
+ else markRenewSucceeded(hostUrl, cliToken, today);
273
+ logger.info(`cli-token: renewed for ${normalizeUrl(hostUrl)} (local day ${today})`);
274
+ } catch (error) {
275
+ if (!current.controller.signal.aborted) {
276
+ logger.warn(`cli-token: renew failed for ${normalizeUrl(hostUrl)}${external ? "" : `: ${error?.message || error}`}; business call proceeds`);
277
+ }
278
+ } finally {
279
+ if (renewInFlight.get(key) === current) renewInFlight.delete(key);
280
+ }
281
+ })();
282
+ renewInFlight.set(key, current);
283
+ attempt = current;
284
+ }
285
+ attempt.waiters++;
286
+ let onAbort = () => void 0;
287
+ try {
288
+ const aborted = signal && new Promise((_resolve, reject) => {
289
+ onAbort = () => reject(signal.reason ?? new DOMException("The operation was aborted", "AbortError"));
290
+ if (signal.aborted) onAbort();
291
+ else signal.addEventListener("abort", onAbort, { once: true });
292
+ });
293
+ await (aborted ? Promise.race([attempt.promise, aborted]) : attempt.promise);
294
+ } finally {
295
+ signal?.removeEventListener("abort", onAbort);
296
+ if (--attempt.waiters === 0) {
297
+ if (renewInFlight.get(key) === attempt) renewInFlight.delete(key);
298
+ attempt.controller.abort();
299
+ }
300
+ }
301
+ }
302
+ function peekCliToken(hostOverride) {
303
+ const external = readExternalCliToken(hostOverride);
304
+ if (external) return external.token;
305
+ if (process.env.TE_AGENT_CLI_CONFIG_DIR !== void 0) return sessionCliToken(hostOverride);
306
+ const hostUrl = hostOverride || getActiveHost();
307
+ if (!hostUrl) return void 0;
308
+ const normalizedHost = normalizeUrl(hostUrl);
309
+ let stored;
310
+ try {
311
+ stored = loadCliToken(normalizedHost);
312
+ } catch (error) {
313
+ if (error instanceof CredentialStoreUnreadableError) return void 0;
314
+ throw error;
315
+ }
316
+ if (stored) {
317
+ cliTokenCache.set(normalizedHost, stored);
318
+ return stored;
319
+ }
320
+ return cliTokenCache.get(normalizedHost) || getFallbackCliToken(normalizedHost) || void 0;
321
+ }
322
+ async function getCliToken(hostOverride, signal) {
323
+ signal?.throwIfAborted();
324
+ const external = readExternalCliToken(hostOverride);
325
+ if (external) {
326
+ await maybeRenewCliTokenDaily(external.url, external.token, true, signal);
327
+ signal?.throwIfAborted();
328
+ return external.token;
329
+ }
330
+ if (process.env.TE_AGENT_CLI_CONFIG_DIR !== void 0) {
331
+ const token2 = sessionCliToken(hostOverride);
332
+ if (!token2) throw new SecureStoreAuthError("Current session CLI credential is unavailable or does not match the requested host.");
333
+ return token2;
334
+ }
335
+ const resolvedHost = hostOverride || getActiveHost();
336
+ if (!resolvedHost) throw new SecureStoreAuthError("No AE host configured. Run: ae-cli auth login --host <url>");
337
+ const hostUrl = normalizeUrl(resolvedHost);
338
+ const stored = loadCliToken(hostUrl);
339
+ let token = stored || getFallbackCliToken(hostUrl) || cliTokenCache.get(hostUrl);
340
+ if (!token) {
341
+ throw new SecureStoreAuthError(`No stored CLI token for ${hostUrl}. Run: ae-cli auth login --host ${hostUrl}`);
342
+ }
343
+ cliTokenCache.set(hostUrl, token);
344
+ await maybeRenewCliTokenDaily(hostUrl, token, false, signal);
345
+ signal?.throwIfAborted();
346
+ return token;
347
+ }
348
+ function sessionCliToken(hostOverride) {
349
+ const entry = readSandboxCliTokenEntry();
350
+ if (!entry?.token.startsWith("cli_")) return void 0;
351
+ if (hostOverride && normalizeUrl(entry.url) !== normalizeUrl(hostOverride)) return void 0;
352
+ return entry.token;
353
+ }
354
+ async function mintCliToken(hostUrl, accessToken, signal) {
355
+ logger.info(`Generating CLI token for ${hostUrl}`);
356
+ const cliToken = await generateCliToken(hostUrl, accessToken, signal);
357
+ cliTokenCache.set(normalizeUrl(hostUrl), cliToken);
358
+ return cliToken;
359
+ }
360
+
361
+ export {
362
+ internalCallSourceHeaders,
363
+ CliTokenValidationUnavailableError,
364
+ clearCliTokenCache,
365
+ validateCliTokenOnServer,
366
+ peekCliToken,
367
+ getCliToken,
368
+ mintCliToken
369
+ };
@@ -1,7 +1,7 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
2
  import {
3
3
  internalCallSourceHeaders
4
- } from "./chunk-UWQXGF44.js";
4
+ } from "./chunk-FKTVD63C.js";
5
5
  import {
6
6
  logger
7
7
  } from "./chunk-MTK4ZE7W.js";
@@ -119,7 +119,7 @@ async function authorizeDevice(host, protocol = "legacy", signal) {
119
119
  const contentType = resp.headers.get("content-type");
120
120
  const text = await resp.text().catch(() => "");
121
121
  signal?.throwIfAborted();
122
- if (looksLikeMissingEndpoint(resp.status, contentType, text)) {
122
+ if (protocol === "uba" && resp.status === 401 || looksLikeMissingEndpoint(resp.status, contentType, text)) {
123
123
  throw new DeviceFlowUnsupportedError(resp.status);
124
124
  }
125
125
  if (!resp.ok) {
@@ -325,7 +325,9 @@ async function authorizeLoginDevice(host, signal) {
325
325
  }
326
326
  return { baseUrl: host, protocol: "uba", authorization };
327
327
  } catch (error) {
328
- if (!(error instanceof DeviceFlowUnsupportedError) || error.httpStatus !== 404) throw error;
328
+ if (!(error instanceof DeviceFlowUnsupportedError) || error.httpStatus !== 401 && error.httpStatus !== 404) {
329
+ throw error;
330
+ }
329
331
  const baseUrl = resolveLegacyLoginBase(host);
330
332
  return { baseUrl, protocol: "legacy", authorization: await authorizeDevice(baseUrl, "legacy", signal) };
331
333
  }
@@ -2,11 +2,11 @@ import { createRequire as __createRequire } from 'node:module'; const require =
2
2
  import {
3
3
  CapabilityGatewayError,
4
4
  getLocalCliPackageInfo
5
- } from "./chunk-WG27BD67.js";
5
+ } from "./chunk-7KBENPQF.js";
6
6
  import {
7
7
  internalCallSourceHeaders,
8
8
  peekCliToken
9
- } from "./chunk-UWQXGF44.js";
9
+ } from "./chunk-FKTVD63C.js";
10
10
  import {
11
11
  getActiveHost,
12
12
  getConfigDir,
@@ -1504,7 +1504,8 @@ import path8 from "path";
1504
1504
  // src/core/skill-businesses.json
1505
1505
  var skill_businesses_default = {
1506
1506
  base: [
1507
- "ae-capability"
1507
+ "ae-capability",
1508
+ "ae-heari-research"
1508
1509
  ],
1509
1510
  analysis: [
1510
1511
  "ae-analysis",
@@ -1659,6 +1660,7 @@ function normalizeBusinesses(value) {
1659
1660
  }
1660
1661
  function businessForCommand(commandPath) {
1661
1662
  const [service, resource] = commandPath;
1663
+ if (service === "context" && (!resource || resource === "prepare")) return void 0;
1662
1664
  if (service === "system") return AGENT_SYSTEM_COMMANDS.has(resource) ? "agent" : void 0;
1663
1665
  return COMMAND_BUSINESSES[service];
1664
1666
  }
@@ -2692,7 +2694,7 @@ async function readBusinessConfigForExecution(hostOverride, synchronizeSkills =
2692
2694
  const token = peekCliToken(host);
2693
2695
  if (!token) return {};
2694
2696
  return await resolveBusinessConfig(host, token, async () => {
2695
- const { fetchCliConfig: fetchCliConfig2 } = await import("./compat-check-J5K3NO5G.js");
2697
+ const { fetchCliConfig: fetchCliConfig2 } = await import("./compat-check-L3C7HCVG.js");
2696
2698
  return fetchCliConfig2(host, token);
2697
2699
  }, Date.now(), synchronizeSkills);
2698
2700
  } catch {
@@ -6,12 +6,12 @@ import {
6
6
  readOutputMetadata,
7
7
  unwrapOutputData,
8
8
  withOutputMetadata
9
- } from "./chunk-N2QILIGH.js";
9
+ } from "./chunk-4MOCV6HU.js";
10
10
  import {
11
11
  CapabilityGatewayError,
12
12
  fetchCapabilityGateway,
13
13
  requestCapabilityGateway
14
- } from "./chunk-WG27BD67.js";
14
+ } from "./chunk-7KBENPQF.js";
15
15
  import {
16
16
  PermissionError
17
17
  } from "./chunk-3ZQY7SLZ.js";
@@ -9,11 +9,11 @@ import {
9
9
  postAgentApi,
10
10
  putAgentApi,
11
11
  uploadAgentApi
12
- } from "./chunk-UK7HQ4IL.js";
12
+ } from "./chunk-CBNE2S44.js";
13
13
  import {
14
14
  TeAgentApiError,
15
15
  createTeAgentApiError
16
- } from "./chunk-KE5WGBXS.js";
16
+ } from "./chunk-3DTMWDJX.js";
17
17
  import {
18
18
  CliValidationError,
19
19
  isApiErrorType
@@ -1,7 +1,7 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
2
  import {
3
3
  internalCallSourceHeaders
4
- } from "./chunk-UWQXGF44.js";
4
+ } from "./chunk-FKTVD63C.js";
5
5
  import {
6
6
  logger
7
7
  } from "./chunk-MTK4ZE7W.js";
@@ -1,13 +1,13 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
2
  import {
3
3
  createCapabilityCommand
4
- } from "./chunk-KAZ5FWPB.js";
4
+ } from "./chunk-3FSYICDW.js";
5
5
  import {
6
6
  registerCapabilityGatewayRoute
7
7
  } from "./chunk-AWW2T2WL.js";
8
8
  import {
9
9
  executeCapabilityWithEnvelope
10
- } from "./chunk-WG27BD67.js";
10
+ } from "./chunk-7KBENPQF.js";
11
11
  import {
12
12
  CliApiError,
13
13
  CliValidationError
@@ -1,12 +1,14 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
2
  import {
3
3
  CapabilityGatewayError
4
- } from "./chunk-WG27BD67.js";
4
+ } from "./chunk-7KBENPQF.js";
5
5
  import {
6
- SecureStoreAuthError,
7
6
  getCliToken,
8
7
  internalCallSourceHeaders
9
- } from "./chunk-UWQXGF44.js";
8
+ } from "./chunk-FKTVD63C.js";
9
+ import {
10
+ SecureStoreAuthError
11
+ } from "./chunk-FEYZBUFQ.js";
10
12
  import {
11
13
  safeJsonParse
12
14
  } from "./chunk-IGU3R2JD.js";
@@ -12,9 +12,10 @@ import {
12
12
  shouldNotifyCompat,
13
13
  shouldSkipAutoSync,
14
14
  shouldSkipCompatCheck
15
- } from "./chunk-GTENC5CO.js";
16
- import "./chunk-WG27BD67.js";
17
- import "./chunk-UWQXGF44.js";
15
+ } from "./chunk-IAZ4AMVY.js";
16
+ import "./chunk-7KBENPQF.js";
17
+ import "./chunk-FKTVD63C.js";
18
+ import "./chunk-FEYZBUFQ.js";
18
19
  import "./chunk-IGU3R2JD.js";
19
20
  import "./chunk-MTK4ZE7W.js";
20
21
  import "./chunk-3ZQY7SLZ.js";
@@ -4,7 +4,7 @@ import {
4
4
  invalidateBusinessSkillSynchronization,
5
5
  refreshEnvironmentAfterLogin,
6
6
  refreshEnvironmentConfig
7
- } from "./chunk-CDBW5RE6.js";
7
+ } from "./chunk-BFSWGXM2.js";
8
8
  import {
9
9
  MultiselectCancelled,
10
10
  promptSingleSelect
@@ -12,18 +12,19 @@ import {
12
12
  import {
13
13
  printError,
14
14
  printOutput
15
- } from "./chunk-N2QILIGH.js";
15
+ } from "./chunk-4MOCV6HU.js";
16
16
  import {
17
17
  aeRegistrationUrl,
18
18
  fetchCliConfig,
19
19
  missingAeHostHint,
20
20
  readCurrentBusinessConfig,
21
21
  resolveKbAutoDiscoveryFeature
22
- } from "./chunk-GTENC5CO.js";
23
- import "./chunk-WG27BD67.js";
22
+ } from "./chunk-IAZ4AMVY.js";
23
+ import "./chunk-7KBENPQF.js";
24
24
  import {
25
25
  peekCliToken
26
- } from "./chunk-UWQXGF44.js";
26
+ } from "./chunk-FKTVD63C.js";
27
+ import "./chunk-FEYZBUFQ.js";
27
28
  import {
28
29
  addHost,
29
30
  getActiveHost,