@thinkingai/ae-cli 6.1.27 → 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 (177) hide show
  1. package/README.md +52 -6
  2. package/README.zh.md +52 -6
  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-WA7YGGRT.js → auth-OBQ5KVQM.js} +175 -45
  7. package/dist/{automation-VAAQBM7Y.js → automation-NAR5DDGL.js} +94 -38
  8. package/dist/{capability-GAAYJ3IQ.js → capability-LFSVNI5B.js} +57 -28
  9. package/dist/chunk-2UW3Y463.js +2289 -0
  10. package/dist/{chunk-VZZNLV3I.js → chunk-3SDHJOCR.js} +68 -18
  11. package/dist/chunk-6HAUVWOQ.js +132 -0
  12. package/dist/{chunk-5XJYLEVC.js → chunk-72NJKS7O.js} +4 -4
  13. package/dist/{chunk-Q5US7JC5.js → chunk-7JAVT5TK.js} +3 -3
  14. package/dist/{chunk-7KU2WNQE.js → chunk-CVCTFLSO.js} +37 -15
  15. package/dist/{chunk-GHXZK54S.js → chunk-H3K5UGYC.js} +41 -13
  16. package/dist/{chunk-OP44TT4H.js → chunk-IN7KKL6K.js} +4 -2
  17. package/dist/{chunk-S6M42KND.js → chunk-JEUXDY3B.js} +1 -1
  18. package/dist/{chunk-ZL7SGNIA.js → chunk-JNVVJ273.js} +58 -46
  19. package/dist/chunk-N6XBLRB7.js +105 -0
  20. package/dist/{chunk-AP7YP2NX.js → chunk-OAWPT7VP.js} +2 -2
  21. package/dist/{chunk-AQJPNWZF.js → chunk-PWXDWMCW.js} +7 -7
  22. package/dist/{chunk-CT7QDJS6.js → chunk-QVRIDN42.js} +2 -2
  23. package/dist/chunk-QZLRHGVH.js +222 -0
  24. package/dist/{chunk-RPBOAQQQ.js → chunk-QZUVLFNR.js} +1 -1
  25. package/dist/{chunk-3YVEAZUN.js → chunk-RJHGDWSC.js} +32 -21
  26. package/dist/{chunk-MWIA43UJ.js → chunk-VCZE3IWO.js} +10 -8
  27. package/dist/chunk-YVG6QD3V.js +233 -0
  28. package/dist/{chunk-WNGFSIOB.js → chunk-Z3Q2AEIN.js} +237 -86
  29. package/dist/{community-report-client-PEERQCX2.js → community-report-client-TJVCLZ3K.js} +1 -1
  30. package/dist/compat-check-CII6B74E.js +32 -0
  31. package/dist/{config-JOD5DOPE.js → config-YZ6O2UQ2.js} +40 -7
  32. package/dist/{context-NGVFPCBK.js → context-F6FCGTF3.js} +4 -4
  33. package/dist/{data-integration-BCLQFTGU.js → data-integration-6UAZO4GG.js} +207 -24
  34. package/dist/evaluation-4LO2O4AF.js +3714 -0
  35. package/dist/index.js +352 -81
  36. package/dist/{local-data-upload-client-TWMHFLUA.js → local-data-upload-client-KCMG6J62.js} +1 -1
  37. package/dist/{memory-CQKH2JAV.js → memory-HHPX3NF2.js} +6 -6
  38. package/dist/{metadata-NR3PHR23.js → metadata-TIFY24LW.js} +17 -9
  39. package/dist/{model-VX5M2CJ6.js → model-7UHGWYVR.js} +4 -4
  40. package/dist/{personal-semantic-preference-2RAI36P3.js → personal-semantic-preference-WKJEGPTM.js} +7 -6
  41. package/dist/{project-semantic-3BUGP3ZM.js → project-semantic-EIQVZNHW.js} +11 -10
  42. package/dist/{sync-RZIAV37C.js → sync-RV3OPCTI.js} +8 -7
  43. package/dist/{te-agent-AORRE2FM.js → te-agent-5ENVZJUH.js} +757 -94
  44. package/dist/{te-analysis-GP7DSQ7Q.js → te-analysis-USIK6ZZG.js} +584 -100
  45. package/dist/{te-community-42M7ICDO.js → te-community-WE2UU4XV.js} +722 -228
  46. package/dist/{te-dataops-BNKNZ4F2.js → te-dataops-XNMO7MBF.js} +9 -6
  47. package/dist/{te-engage-2CO6LRCX.js → te-engage-6C3HCFQR.js} +13 -12
  48. package/dist/{te-experiment-652CLXMU.js → te-experiment-LVTRI3QK.js} +55 -21
  49. package/dist/{te-kb-ULATOTQ3.js → te-kb-TUPGMVBY.js} +409 -85
  50. package/dist/{te-system-UGHVKBVV.js → te-system-YM657FKO.js} +6 -6
  51. package/dist/{te-team-YA6SNOJ3.js → te-team-G4VEJJNL.js} +64 -41
  52. package/dist/{things-DTCOQIQB.js → things-22KQWC23.js} +7 -7
  53. package/dist/{update-ESNYKUVR.js → update-XX4ILU7X.js} +11 -7
  54. package/dist/{workspace-JEOHKFPX.js → workspace-LYDAP647.js} +6 -6
  55. package/package.json +26 -11
  56. package/skills/ae-agent/SKILL.md +22 -3
  57. package/skills/ae-agent/references/command_index.md +8 -0
  58. package/skills/ae-agent/references/resource-package.md +57 -0
  59. package/skills/ae-analysis/SKILL.md +23 -10
  60. package/skills/ae-analysis/references/adhoc_export.md +1 -1
  61. package/skills/ae-analysis/references/agent_review_preflight.md +55 -10
  62. package/skills/ae-analysis/references/agent_review_priorities_comparisons.md +5 -3
  63. package/skills/ae-analysis/references/agent_review_submit_to_page.md +60 -24
  64. package/skills/ae-analysis/references/ai_models/event.md +58 -2
  65. package/skills/ae-analysis/references/ai_models/rank_list.md +1 -0
  66. package/skills/ae-analysis/references/ai_models/retention.md +2 -0
  67. package/skills/ae-analysis/references/ai_models/revenue.md +2 -0
  68. package/skills/ae-analysis/references/analysis_data_export.md +11 -1
  69. package/skills/ae-analysis/references/asset_batch_info_export.md +2 -2
  70. package/skills/ae-analysis/references/asset_batch_sql_export.md +2 -2
  71. package/skills/ae-analysis/references/asset_export.md +1 -1
  72. package/skills/ae-analysis/references/bi_panel_page_data_export.md +1 -1
  73. package/skills/ae-analysis/references/check_export.md +1 -1
  74. package/skills/ae-analysis/references/command_index.md +39 -26
  75. package/skills/ae-analysis/references/dashboard_report_data_export.md +2 -0
  76. package/skills/ae-analysis/references/dashboard_report_get.md +6 -2
  77. package/skills/ae-analysis/references/dashboard_report_update.md +24 -5
  78. package/skills/ae-analysis/references/feedback_submit.md +1 -1
  79. package/skills/ae-analysis/references/governance_recommendation_export.md +40 -18
  80. package/skills/ae-analysis/references/governance_recommendation_run_update.md +13 -0
  81. package/skills/ae-analysis/references/live_data_export.md +1 -1
  82. package/skills/ae-analysis/references/metric_create.md +29 -0
  83. package/skills/ae-analysis/references/metric_get.md +2 -0
  84. package/skills/ae-analysis/references/metric_update.md +2 -0
  85. package/skills/ae-analysis/references/operation_record_export.md +1 -1
  86. package/skills/ae-analysis/references/plan_change_log_export.md +1 -1
  87. package/skills/ae-analysis/references/plan_export.md +1 -1
  88. package/skills/ae-analysis/references/project_info_get.md +4 -0
  89. package/skills/ae-analysis/references/project_member_group_add_members.md +35 -0
  90. package/skills/ae-analysis/references/project_member_group_create.md +25 -0
  91. package/skills/ae-analysis/references/project_member_group_delete.md +34 -0
  92. package/skills/ae-analysis/references/project_member_group_list.md +29 -0
  93. package/skills/ae-analysis/references/project_member_group_members.md +28 -0
  94. package/skills/ae-analysis/references/project_member_group_remove_members.md +35 -0
  95. package/skills/ae-analysis/references/project_member_group_rename.md +26 -0
  96. package/skills/ae-analysis/references/project_semantic_knowledge_wiki.md +9 -1
  97. package/skills/ae-analysis/references/project_semantic_knowledge_wiki_plan_schema.md +6 -1
  98. package/skills/ae-analysis/references/report_data_export.md +1 -1
  99. package/skills/ae-analysis/references/scenario_append.md +31 -0
  100. package/skills/ae-analysis/references/scenario_begin.md +11 -0
  101. package/skills/ae-analysis/references/scenario_collect.md +43 -0
  102. package/skills/ae-analysis/references/scenario_evaluation.md +18 -0
  103. package/skills/ae-analysis/references/scenario_get.md +15 -0
  104. package/skills/ae-analysis/references/scenario_list.md +64 -0
  105. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/build-project-semantic-wiki.mjs +73 -4
  106. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/company-kb.mjs +14 -1
  107. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/default-compile-schema.md +5 -1
  108. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/execution-contract.mjs +173 -0
  109. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/generate-build-ir.mjs +109 -64
  110. package/skills/ae-automation/SKILL.md +2 -2
  111. package/skills/ae-automation/references/cli.md +18 -1
  112. package/skills/ae-capability/SKILL.md +7 -3
  113. package/skills/ae-community/SKILL.md +77 -27
  114. package/skills/ae-community/references/community-analyzing-theme-comment.md +10 -8
  115. package/skills/ae-community/references/community-data-quality.md +68 -0
  116. package/skills/ae-community/references/community-query-evidence.md +85 -0
  117. package/skills/ae-community/references/community-scenario-capabilities.md +137 -0
  118. package/skills/ae-community/references/community-weekly-report.md +6 -3
  119. package/skills/ae-community/references/get_channel_info.md +7 -4
  120. package/skills/ae-community/references/get_comment_tag_analysis.md +3 -3
  121. package/skills/ae-community/references/get_comments_summary.md +4 -4
  122. package/skills/ae-community/references/get_corpus_tags.md +3 -3
  123. package/skills/ae-community/references/get_daily_summary.md +3 -3
  124. package/skills/ae-community/references/get_hot_topics.md +3 -3
  125. package/skills/ae-community/references/get_livestream_analysis.md +3 -3
  126. package/skills/ae-community/references/get_livestream_detail.md +4 -4
  127. package/skills/ae-community/references/get_livestream_list.md +3 -3
  128. package/skills/ae-community/references/get_livestream_overview.md +3 -3
  129. package/skills/ae-community/references/get_livestream_room_metrics.md +3 -3
  130. package/skills/ae-community/references/get_livestream_rooms.md +3 -3
  131. package/skills/ae-community/references/get_overview_metrics.md +3 -3
  132. package/skills/ae-community/references/get_post_detail.md +4 -4
  133. package/skills/ae-community/references/get_risk_content.md +5 -5
  134. package/skills/ae-community/references/get_sentiment_overview.md +4 -4
  135. package/skills/ae-community/references/get_tag_trends.md +3 -3
  136. package/skills/ae-community/references/get_topic_detail.md +3 -3
  137. package/skills/ae-community/references/list_sources.md +28 -0
  138. package/skills/ae-community/references/list_spaces.md +39 -0
  139. package/skills/ae-community/references/search_posts.md +21 -7
  140. package/skills/ae-data-integration/SKILL.md +6 -4
  141. package/skills/ae-data-integration/references/error-handling.md +1 -0
  142. package/skills/ae-data-integration/references/handoff.md +1 -1
  143. package/skills/ae-data-integration/references/sink-upload.md +11 -0
  144. package/skills/ae-data-integration/references/source-inspect.md +2 -1
  145. package/skills/ae-data-integration/references/transform.md +1 -1
  146. package/skills/ae-data-integration/references/ue-mapping.md +1 -1
  147. package/skills/ae-evaluation/SKILL.md +83 -0
  148. package/skills/ae-evaluation/references/access-and-members.md +55 -0
  149. package/skills/ae-evaluation/references/connections.md +78 -0
  150. package/skills/ae-evaluation/references/datasets.md +57 -0
  151. package/skills/ae-evaluation/references/evaluators.md +81 -0
  152. package/skills/ae-evaluation/references/files.md +33 -0
  153. package/skills/ae-evaluation/references/integrations.md +39 -0
  154. package/skills/ae-evaluation/references/runs.md +160 -0
  155. package/skills/ae-evaluation/references/schedules.md +31 -0
  156. package/skills/ae-experiment/SKILL.md +7 -1
  157. package/skills/ae-experiment/references/manage_experiment.md +18 -1
  158. package/skills/ae-experiment/references/query_experiment_detail.md +7 -0
  159. package/skills/ae-experiment/references/save_experiment.md +76 -2
  160. package/skills/ae-experiment/references/save_submit_experiment.md +7 -0
  161. package/skills/ae-kb/SKILL.md +33 -7
  162. package/skills/ae-kb/references/publication.md +81 -0
  163. package/skills/ae-kb/references/query-workflow.md +14 -1
  164. package/skills/ae-metadata/SKILL.md +3 -2
  165. package/skills/ae-metadata/references/metadata_data_table_download.md +7 -1
  166. package/skills/ae-metadata/references/metadata_data_table_get.md +37 -0
  167. package/skills/ae-system/SKILL.md +1 -1
  168. package/skills/ae-team/SKILL.md +2 -2
  169. package/skills/ae-team/references/run-start.md +1 -0
  170. package/skills/ae-team/references/run-watch.md +7 -5
  171. package/skills/ae-things/SKILL.md +53 -51
  172. package/skills/ae-things/references/cli.md +56 -54
  173. package/skills/ae-things-progress/SKILL.md +20 -20
  174. package/skills/ae-things-review/SKILL.md +19 -19
  175. package/skills/ae-workspace/SKILL.md +1 -1
  176. package/dist/chunk-6VNIR4AP.js +0 -1422
  177. package/dist/chunk-CI24BDR2.js +0 -43
@@ -6,13 +6,15 @@ import {
6
6
  SecureStoreAuthError,
7
7
  clearCliTokenCache,
8
8
  getCliToken
9
- } from "./chunk-GHXZK54S.js";
9
+ } from "./chunk-H3K5UGYC.js";
10
10
  import {
11
- safeJsonParse
12
- } from "./chunk-ZL7SGNIA.js";
11
+ safeJsonParse,
12
+ stringifyJsonRequest
13
+ } from "./chunk-JNVVJ273.js";
13
14
  import {
14
- PermissionError
15
- } from "./chunk-WNGFSIOB.js";
15
+ PermissionError,
16
+ externalCliTokenRequestOptions
17
+ } from "./chunk-Z3Q2AEIN.js";
16
18
 
17
19
  // src/core/cli-agent-context.ts
18
20
  import { readFileSync, statSync } from "fs";
@@ -262,13 +264,14 @@ function isPlainRecord(value) {
262
264
  import { readFile } from "fs/promises";
263
265
  import { basename } from "path";
264
266
  var CapabilityGatewayError = class extends Error {
265
- constructor(message, code, httpStatus, hint, meta, type = "api") {
267
+ constructor(message, code, httpStatus, hint, meta, type = "api", details) {
266
268
  super(message);
267
269
  this.code = code;
268
270
  this.httpStatus = httpStatus;
269
271
  this.hint = hint;
270
272
  this.meta = meta;
271
273
  this.type = type;
274
+ this.details = details;
272
275
  this.name = "CapabilityGatewayError";
273
276
  }
274
277
  code;
@@ -276,6 +279,7 @@ var CapabilityGatewayError = class extends Error {
276
279
  hint;
277
280
  meta;
278
281
  type;
282
+ details;
279
283
  };
280
284
  function buildCapabilityGatewayUrl(host, domain, pathAfterV1, queryParams = {}, apiVersion = "v1") {
281
285
  const base = host.replace(/\/+$/, "");
@@ -306,7 +310,13 @@ async function permissionError(resp) {
306
310
  const body = safeJsonParse(await codeResponse.text());
307
311
  const error = isRecord(body?.error) ? body.error : void 0;
308
312
  const code = nonEmptyString(error?.code) ?? nonEmptyString(body?.code);
309
- return new PermissionError(message, code);
313
+ return new PermissionError(
314
+ message,
315
+ code,
316
+ nonEmptyString(error?.hint) ?? nonEmptyString(body?.hint),
317
+ void 0,
318
+ isRecord(body?.meta) ? body.meta : void 0
319
+ );
310
320
  }
311
321
  function isInvalidCliTokenMessage(message) {
312
322
  return /\byour token is invalid\b/i.test(message) || /\bcli[-_\s]?token\b.*\binvalid\b/i.test(message) || /\binvalid\b.*\bcli[-_\s]?token\b/i.test(message);
@@ -319,7 +329,10 @@ function parseCapabilityResponse(text) {
319
329
  return text;
320
330
  }
321
331
  }
322
- function parseCapabilityEnvelope(body) {
332
+ function isCommunityGatewayRequest(domain, pathAfterV1) {
333
+ return domain.replace(/^\/+|\/+$/g, "") === "community" || /^capabilities\/community\./.test(pathAfterV1.replace(/^\/+/, ""));
334
+ }
335
+ function parseCapabilityEnvelope(body, acceptCommunityLegacyEnvelope = false) {
323
336
  if (body == null) {
324
337
  throw new CapabilityGatewayError("Empty capability gateway response");
325
338
  }
@@ -341,13 +354,36 @@ function parseCapabilityEnvelope(body) {
341
354
  err.http_status ?? err.httpStatus,
342
355
  hint,
343
356
  isRecord(body.meta) ? body.meta : void 0,
344
- err.type === "validation" ? "validation" : "api"
357
+ err.type === "validation" ? "validation" : "api",
358
+ isRecord(err.details) ? err.details : void 0
359
+ );
360
+ }
361
+ const legacyReturnCode = acceptCommunityLegacyEnvelope ? body.return_code ?? body.returnCode : void 0;
362
+ if (legacyReturnCode !== void 0 && Number(legacyReturnCode) !== 0) {
363
+ const code = String(legacyReturnCode);
364
+ const rawMessage = nonEmptyString(body.return_message) ?? nonEmptyString(body.returnMessage) ?? nonEmptyString(body.message);
365
+ const message = safeLegacyErrorMessage(rawMessage, code);
366
+ throw new CapabilityGatewayError(
367
+ message,
368
+ code,
369
+ void 0,
370
+ "The community service returned a legacy error envelope. Verify that the capability gateway route is deployed on the current host.",
371
+ { legacy_return_code: legacyReturnCode }
345
372
  );
346
373
  }
374
+ if (legacyReturnCode !== void 0 && Number(legacyReturnCode) === 0 && "data" in body) {
375
+ return { ok: true, data: body.data };
376
+ }
347
377
  return { ok: true, data: body };
348
378
  }
349
- function unwrapCapabilityEnvelope(body) {
350
- return parseCapabilityEnvelope(body).data;
379
+ function safeLegacyErrorMessage(message, code) {
380
+ if (!message || /\n\s*at\s|stacktrace|\.java:\d+/i.test(message)) {
381
+ return `Capability service request failed (legacy return code ${code})`;
382
+ }
383
+ return message.slice(0, 500);
384
+ }
385
+ function unwrapCapabilityEnvelope(body, acceptCommunityLegacyEnvelope = false) {
386
+ return parseCapabilityEnvelope(body, acceptCommunityLegacyEnvelope).data;
351
387
  }
352
388
  function nonEmptyString(value) {
353
389
  return typeof value === "string" && value.trim() ? value.trim() : void 0;
@@ -370,7 +406,8 @@ function buildCapabilityHttpError(resp, body) {
370
406
  resp.status,
371
407
  hint,
372
408
  isRecord(body.meta) ? body.meta : void 0,
373
- err.type === "validation" ? "validation" : "api"
409
+ err.type === "validation" ? "validation" : "api",
410
+ isRecord(err.details) ? err.details : void 0
374
411
  );
375
412
  }
376
413
  }
@@ -400,13 +437,14 @@ async function requestOnce(url, method, token, body, accept = "application/json"
400
437
  const init = { method, headers };
401
438
  if (body !== void 0 && method !== "GET") {
402
439
  headers["Content-Type"] = "application/json";
403
- init.body = JSON.stringify(includeClientContextInBody ? withCliAgentContextBody(body, agentContext) : body);
440
+ init.body = stringifyJsonRequest(includeClientContextInBody ? withCliAgentContextBody(body, agentContext) : body);
404
441
  }
405
- return fetch(url, init);
442
+ return fetch(url, { ...init, ...externalCliTokenRequestOptions(url) });
406
443
  }
407
444
  async function requestMultipartOnce(url, token, form) {
408
445
  return fetch(url, {
409
446
  method: "POST",
447
+ ...externalCliTokenRequestOptions(url),
410
448
  headers: {
411
449
  "cli-token": token,
412
450
  "Accept": "application/json",
@@ -439,7 +477,10 @@ async function callGatewayWithEnvelope(host, domain, pathAfterV1, method, body,
439
477
  if (!resp.ok) {
440
478
  await throwCapabilityHttpError(resp);
441
479
  }
442
- return parseCapabilityEnvelope(parseCapabilityResponse(await resp.text()));
480
+ return parseCapabilityEnvelope(
481
+ parseCapabilityResponse(await resp.text()),
482
+ isCommunityGatewayRequest(domain, pathAfterV1)
483
+ );
443
484
  }
444
485
  async function fetchCapabilityGateway(host, domain, pathAfterV1, method = "GET", body, accept = "application/json") {
445
486
  const url = buildCapabilityGatewayUrl(host, domain, pathAfterV1);
@@ -459,11 +500,17 @@ async function fetchCapabilityGateway(host, domain, pathAfterV1, method = "GET",
459
500
  }
460
501
  async function requestCapabilityGateway(host, domain, pathAfterV1, method = "GET", body) {
461
502
  const resp = await fetchCapabilityGateway(host, domain, pathAfterV1, method, body);
462
- return unwrapCapabilityEnvelope(parseCapabilityResponse(await resp.text()));
503
+ return unwrapCapabilityEnvelope(
504
+ parseCapabilityResponse(await resp.text()),
505
+ isCommunityGatewayRequest(domain, pathAfterV1)
506
+ );
463
507
  }
464
508
  async function requestCapabilityGatewayWithEnvelope(host, domain, pathAfterV1, method = "GET", body) {
465
509
  const resp = await fetchCapabilityGateway(host, domain, pathAfterV1, method, body);
466
- return parseCapabilityEnvelope(parseCapabilityResponse(await resp.text()));
510
+ return parseCapabilityEnvelope(
511
+ parseCapabilityResponse(await resp.text()),
512
+ isCommunityGatewayRequest(domain, pathAfterV1)
513
+ );
467
514
  }
468
515
  async function listCapabilitiesWithEnvelope(host, domain, projectId) {
469
516
  return callGatewayWithEnvelope(host, domain, "capabilities", "GET", void 0, { project_id: projectId });
@@ -544,7 +591,10 @@ async function uploadInputFileBytes(host, domain, projectId, purpose, bytes, fil
544
591
  if (!resp.ok) {
545
592
  await throwCapabilityHttpError(resp);
546
593
  }
547
- return unwrapCapabilityEnvelope(parseCapabilityResponse(await resp.text()));
594
+ return unwrapCapabilityEnvelope(
595
+ parseCapabilityResponse(await resp.text()),
596
+ isCommunityGatewayRequest(domain, "input-files")
597
+ );
548
598
  }
549
599
  async function callCapabilityApi(host, domain, action, method = "POST", params = {}, options = {}) {
550
600
  const isGet = method === "GET";
@@ -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-2UW3Y463.js";
11
+ import {
12
+ peekCliToken
13
+ } from "./chunk-H3K5UGYC.js";
14
+ import {
15
+ getActiveHost,
16
+ getConfigDir
17
+ } from "./chunk-JNVVJ273.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
+ };
@@ -1,20 +1,20 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
2
  import {
3
3
  require_lib
4
- } from "./chunk-CT7QDJS6.js";
4
+ } from "./chunk-QVRIDN42.js";
5
5
  import {
6
6
  require_archiver,
7
7
  require_string_decoder
8
- } from "./chunk-AP7YP2NX.js";
8
+ } from "./chunk-OAWPT7VP.js";
9
9
  import {
10
10
  require_inherits,
11
11
  require_node
12
- } from "./chunk-S6M42KND.js";
12
+ } from "./chunk-JEUXDY3B.js";
13
13
  import {
14
14
  __commonJS,
15
15
  __require,
16
16
  __toESM
17
- } from "./chunk-WNGFSIOB.js";
17
+ } from "./chunk-Z3Q2AEIN.js";
18
18
 
19
19
  // node_modules/exceljs/lib/utils/under-dash.js
20
20
  var require_under_dash = __commonJS({
@@ -9,15 +9,15 @@ import {
9
9
  postAgentApi,
10
10
  putAgentApi,
11
11
  uploadAgentApi
12
- } from "./chunk-CI24BDR2.js";
12
+ } from "./chunk-N6XBLRB7.js";
13
13
  import {
14
14
  TeAgentApiError,
15
15
  createTeAgentApiError
16
- } from "./chunk-3YVEAZUN.js";
16
+ } from "./chunk-RJHGDWSC.js";
17
17
  import {
18
18
  CliValidationError,
19
19
  isApiErrorType
20
- } from "./chunk-WNGFSIOB.js";
20
+ } from "./chunk-Z3Q2AEIN.js";
21
21
 
22
22
  // src/commands/workspace/client.ts
23
23
  var DEFAULT_TE_CLAUDE_BASE_PATH = "/agent";
@@ -1,17 +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-VZZNLV3I.js";
4
+ } from "./chunk-3SDHJOCR.js";
5
5
  import {
6
6
  SecureStoreAuthError,
7
7
  getCliToken
8
- } from "./chunk-GHXZK54S.js";
8
+ } from "./chunk-H3K5UGYC.js";
9
9
  import {
10
10
  safeJsonParse
11
- } from "./chunk-ZL7SGNIA.js";
11
+ } from "./chunk-JNVVJ273.js";
12
12
  import {
13
- PermissionError
14
- } from "./chunk-WNGFSIOB.js";
13
+ PermissionError,
14
+ externalCliTokenRequestOptions,
15
+ isKbQueryPath,
16
+ kbReadHeaders,
17
+ readKbExecutionContext
18
+ } from "./chunk-Z3Q2AEIN.js";
15
19
 
16
20
  // src/core/mcp-access.ts
17
21
  function buildUrl(host, path, params = {}) {
@@ -170,7 +174,7 @@ function parseKbResponse(resp, text, options = {}) {
170
174
  async function fetchWithCliToken(input, init, cliToken, options = {}) {
171
175
  const headers = new Headers(init.headers);
172
176
  headers.set("cli-token", cliToken);
173
- const resp = await fetch(input, { ...init, headers });
177
+ const resp = await fetch(input, { ...init, headers, ...externalCliTokenRequestOptions(input) });
174
178
  if (options.responseType === "empty" && resp.status === 204) return null;
175
179
  if (options.responseType === "bytes" && resp.ok) {
176
180
  if (resp.headers.get("content-type")?.includes("application/json")) {
@@ -217,18 +221,36 @@ async function getAuthHeaders(ctx) {
217
221
  return { "cli-token": cliToken };
218
222
  }
219
223
  async function kbApi(ctx, method, path, params = {}, body, options = {}) {
220
- const host = ctx.host();
221
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
+ }
222
250
  return requestWithCliToken(
223
251
  host,
224
- buildUrl(host, path, params),
225
- {
226
- method: upperMethod,
227
- headers: {
228
- "Content-Type": "application/json"
229
- },
230
- body: upperMethod === "GET" ? void 0 : JSON.stringify(body ?? {})
231
- },
252
+ url,
253
+ init,
232
254
  options
233
255
  );
234
256
  }
@@ -3,14 +3,17 @@ import {
3
3
  getActiveHost,
4
4
  getConfigDir,
5
5
  getFallbackCliToken,
6
- normalizeUrl,
6
+ readSandboxCliTokenEntry,
7
7
  safeJsonParse,
8
8
  safeReadJsonFile
9
- } from "./chunk-ZL7SGNIA.js";
9
+ } from "./chunk-JNVVJ273.js";
10
10
  import {
11
11
  PermissionError,
12
- logger
13
- } from "./chunk-WNGFSIOB.js";
12
+ externalCliTokenRequestOptions,
13
+ logger,
14
+ normalizeUrl,
15
+ readExternalCliToken
16
+ } from "./chunk-Z3Q2AEIN.js";
14
17
 
15
18
  // src/core/secure-store.ts
16
19
  import crypto from "crypto";
@@ -696,7 +699,8 @@ async function validateCliTokenOnServer(hostUrl, cliToken) {
696
699
  try {
697
700
  resp = await fetch(url, {
698
701
  method: "GET",
699
- headers: { Accept: "application/json", "cli-token": cliToken }
702
+ headers: { Accept: "application/json", "cli-token": cliToken },
703
+ ...externalCliTokenRequestOptions(url)
700
704
  });
701
705
  } catch (error) {
702
706
  throw new CliTokenValidationUnavailableError(`Unable to validate CLI token for ${hostUrl}: ${error.message}`);
@@ -734,10 +738,14 @@ async function validateCliTokenOnServer(hostUrl, cliToken) {
734
738
  ...cliTokenExpiresAt ? { cliTokenExpiresAt } : {}
735
739
  };
736
740
  }
737
- async function renewCliTokenOnServer(hostUrl, cliToken) {
741
+ async function renewCliTokenOnServer(hostUrl, cliToken, external = false) {
738
742
  const url = new URL(`${hostUrl.replace(/\/+$/, "")}${CLI_TOKEN_RENEW_PATH}`);
739
- url.searchParams.set("cli-token", cliToken);
740
- const resp = await fetch(url.toString(), { method: "GET", headers: { Accept: "application/json" } });
743
+ if (!external) url.searchParams.set("cli-token", cliToken);
744
+ const resp = await fetch(url.toString(), {
745
+ method: "GET",
746
+ headers: { Accept: "application/json", ...external ? { "cli-token": cliToken } : {} },
747
+ ...externalCliTokenRequestOptions(url.toString())
748
+ });
741
749
  const text = await resp.text();
742
750
  let data;
743
751
  try {
@@ -750,10 +758,10 @@ async function renewCliTokenOnServer(hostUrl, cliToken) {
750
758
  throw new Error(`CLI token renew error: ${data.return_message || "unknown"} (code: ${data.return_code})`);
751
759
  }
752
760
  }
753
- async function maybeRenewCliTokenDaily(hostUrl, cliToken) {
761
+ async function maybeRenewCliTokenDaily(hostUrl, cliToken, external = false) {
754
762
  const key = renewKey(hostUrl, cliToken);
755
763
  const today = localRenewDate();
756
- if (renewedLocalDate.get(key) === today || persistedRenewDate(hostUrl, cliToken) === today) {
764
+ if (renewedLocalDate.get(key) === today || !external && persistedRenewDate(hostUrl, cliToken) === today) {
757
765
  renewedLocalDate.set(key, today);
758
766
  return;
759
767
  }
@@ -761,11 +769,12 @@ async function maybeRenewCliTokenDaily(hostUrl, cliToken) {
761
769
  if (existing) return existing;
762
770
  const attempt = (async () => {
763
771
  try {
764
- await renewCliTokenOnServer(hostUrl, cliToken);
765
- markRenewSucceeded(hostUrl, cliToken, today);
772
+ await renewCliTokenOnServer(hostUrl, cliToken, external);
773
+ if (external) renewedLocalDate.set(key, today);
774
+ else markRenewSucceeded(hostUrl, cliToken, today);
766
775
  logger.info(`cli-token: renewed for ${normalizeUrl(hostUrl)} (local day ${today})`);
767
776
  } catch (error) {
768
- logger.warn(`cli-token: renew failed for ${normalizeUrl(hostUrl)}: ${error?.message || error}; business call proceeds`);
777
+ logger.warn(`cli-token: renew failed for ${normalizeUrl(hostUrl)}${external ? "" : `: ${error?.message || error}`}; business call proceeds`);
769
778
  } finally {
770
779
  renewInFlight.delete(key);
771
780
  }
@@ -774,6 +783,9 @@ async function maybeRenewCliTokenDaily(hostUrl, cliToken) {
774
783
  await attempt;
775
784
  }
776
785
  function peekCliToken(hostOverride) {
786
+ const external = readExternalCliToken(hostOverride);
787
+ if (external) return external.token;
788
+ if (process.env.TE_AGENT_CLI_CONFIG_DIR !== void 0) return sessionCliToken(hostOverride);
777
789
  const hostUrl = hostOverride || getActiveHost();
778
790
  if (!hostUrl) return void 0;
779
791
  const normalizedHost = normalizeUrl(hostUrl);
@@ -791,6 +803,16 @@ function peekCliToken(hostOverride) {
791
803
  return cliTokenCache.get(normalizedHost) || getFallbackCliToken(normalizedHost) || void 0;
792
804
  }
793
805
  async function getCliToken(hostOverride) {
806
+ const external = readExternalCliToken(hostOverride);
807
+ if (external) {
808
+ await maybeRenewCliTokenDaily(external.url, external.token, true);
809
+ return external.token;
810
+ }
811
+ if (process.env.TE_AGENT_CLI_CONFIG_DIR !== void 0) {
812
+ const token2 = sessionCliToken(hostOverride);
813
+ if (!token2) throw new SecureStoreAuthError("Current session CLI credential is unavailable or does not match the requested host.");
814
+ return token2;
815
+ }
794
816
  const resolvedHost = hostOverride || getActiveHost();
795
817
  if (!resolvedHost) throw new SecureStoreAuthError("No AE host configured. Run: ae-cli auth login --host <url>");
796
818
  const hostUrl = normalizeUrl(resolvedHost);
@@ -803,6 +825,12 @@ async function getCliToken(hostOverride) {
803
825
  await maybeRenewCliTokenDaily(hostUrl, token);
804
826
  return token;
805
827
  }
828
+ function sessionCliToken(hostOverride) {
829
+ const entry = readSandboxCliTokenEntry();
830
+ if (!entry?.token.startsWith("cli_")) return void 0;
831
+ if (hostOverride && normalizeUrl(entry.url) !== normalizeUrl(hostOverride)) return void 0;
832
+ return entry.token;
833
+ }
806
834
  async function mintCliToken(hostUrl, accessToken) {
807
835
  logger.info(`Generating CLI token for ${hostUrl}`);
808
836
  const cliToken = await generateCliToken(hostUrl, accessToken);
@@ -1,8 +1,10 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
2
  import {
3
- getActiveHost,
3
+ getActiveHost
4
+ } from "./chunk-JNVVJ273.js";
5
+ import {
4
6
  normalizeUrl
5
- } from "./chunk-ZL7SGNIA.js";
7
+ } from "./chunk-Z3Q2AEIN.js";
6
8
 
7
9
  // src/core/auth.ts
8
10
  function resolveHost(hostOverride) {
@@ -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-WNGFSIOB.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({