@thinkingai/ae-cli 6.0.42 → 6.0.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 (87) hide show
  1. package/dist/{auth-GBMV6TEJ.js → auth-2WTQOP77.js} +3 -3
  2. package/dist/{auth-NDSXE54J.js → auth-77BUFLGC.js} +57 -13
  3. package/dist/{capability-CETVHGXF.js → capability-ENHWPMTG.js} +12 -12
  4. package/dist/{capability-ZSQBMNOE.js → capability-WA37LSIR.js} +12 -12
  5. package/dist/{chunk-AFXA7BRK.js → chunk-4KVPKXFX.js} +5 -5
  6. package/dist/chunk-4SGZG4XY.js +311 -0
  7. package/dist/chunk-6EIJSNBD.js +8 -0
  8. package/dist/chunk-C4MGVGJW.js +13 -0
  9. package/dist/{chunk-4E3DB4MM.js → chunk-EE45RGOO.js} +7 -7
  10. package/dist/{chunk-WZRX4KOH.js → chunk-GT46FPXN.js} +4 -6
  11. package/dist/{chunk-5XUSIK27.js → chunk-ILIU36SU.js} +10 -7
  12. package/dist/{chunk-JHENBQ5B.js → chunk-LYVNONC4.js} +0 -35
  13. package/dist/{chunk-WANVG6SY.js → chunk-MGU2N3HW.js} +7 -7
  14. package/dist/{chunk-JUW4AJXN.js → chunk-P3FGXJTU.js} +12 -7
  15. package/dist/{chunk-FNZA5RZA.js → chunk-QEFCIRNJ.js} +4 -4
  16. package/dist/chunk-QGM4M3NI.js +37 -0
  17. package/dist/{chunk-J2N4PB56.js → chunk-QI524WPY.js} +4 -4
  18. package/dist/{chunk-VLWOLBGZ.js → chunk-UOUS37JQ.js} +149 -161
  19. package/dist/{chunk-AXDXJTPC.js → chunk-UW5UN47B.js} +19 -2
  20. package/dist/chunk-VPKZ7I72.js +509 -0
  21. package/dist/chunk-ZZUOD757.js +598 -0
  22. package/dist/{client-L2YDMHQ6.js → client-TKG4WBHN.js} +4 -5
  23. package/dist/{community-report-client-M2RW4MXD.js → community-report-client-FI4LNVYS.js} +3 -2
  24. package/dist/{config-OL2LWGBV.js → config-RE6CMGPK.js} +7 -7
  25. package/dist/data-integration-2MYMANJI.js +3383 -0
  26. package/dist/index.js +74 -40
  27. package/dist/local-data-upload-client-BWHSUQQK.js +167 -0
  28. package/dist/{memory-MUP7PPL7.js → memory-CHRU2F7W.js} +7 -6
  29. package/dist/{memory-U4O5PMXH.js → memory-YK33G4T7.js} +7 -6
  30. package/dist/{metadata-BD6BXAYE.js → metadata-AXVHAAZG.js} +10 -9
  31. package/dist/{metadata-HXOFACDE.js → metadata-GGEHHPBE.js} +10 -9
  32. package/dist/{model-JTUEO5M4.js → model-K3KLWIW6.js} +7 -3
  33. package/dist/model-NR3JHFSJ.js +139 -0
  34. package/dist/{sync-MOSFNBVR.js → sync-DAVKYVMW.js} +8 -6
  35. package/dist/sync-FCKOVWWS.js +10261 -0
  36. package/dist/{te-agent-IFKZDHZI.js → te-agent-4BKBODMF.js} +686 -71
  37. package/dist/te-agent-HLW4VTQK.js +3893 -0
  38. package/dist/{te-analysis-PXNF7ZJT.js → te-analysis-WX7LRVAV.js} +38 -15
  39. package/dist/{te-analysis-T7C7WSAH.js → te-analysis-YKFDBMA6.js} +38 -15
  40. package/dist/{te-community-HNKVTERD.js → te-community-6HPBWJUZ.js} +24 -19
  41. package/dist/{te-community-IWE5B7W6.js → te-community-HLC43QKH.js} +24 -20
  42. package/dist/{te-dataops-KXCEB4CS.js → te-dataops-EJP56W3K.js} +57 -34
  43. package/dist/{te-dataops-KQPYNAE3.js → te-dataops-HDRUXY4K.js} +59 -34
  44. package/dist/{te-engage-BVB7RGEO.js → te-engage-UBHPAJCO.js} +12 -11
  45. package/dist/{te-engage-LCEGC7G4.js → te-engage-WLDTS5J5.js} +12 -11
  46. package/dist/{te-kb-OIH3T6CS.js → te-kb-APXBWBDY.js} +6 -6
  47. package/dist/{te-system-AZ3URMUO.js → te-system-YARIK4S5.js} +7 -4
  48. package/dist/te-system-Z77IKZFN.js +2213 -0
  49. package/dist/{te-team-GZPU6UWA.js → te-team-EFKWYKMK.js} +7 -7
  50. package/dist/{update-TOBFXF2V.js → update-OGPSZM5A.js} +7 -7
  51. package/package.json +13 -3
  52. package/skills/ae-agent/SKILL.md +21 -11
  53. package/skills/ae-agent/references/approval-effect.md +44 -0
  54. package/skills/ae-agent/references/approval-request.md +46 -0
  55. package/skills/ae-agent/references/approval-task.md +45 -0
  56. package/skills/ae-agent/references/approval-type.md +32 -0
  57. package/skills/ae-agent/references/command_index.md +19 -0
  58. package/skills/ae-analysis/SKILL.md +11 -7
  59. package/skills/ae-analysis/references/adhoc_run.md +2 -0
  60. package/skills/ae-analysis/references/ai_models.md +27 -0
  61. package/skills/ae-analysis/references/analysis_gateway_assets.md +3 -2
  62. package/skills/ae-analysis/references/command_index.md +4 -1
  63. package/skills/ae-analysis/references/dashboard_get.md +8 -2
  64. package/skills/ae-analysis/references/dashboard_report_data_run.md +3 -1
  65. package/skills/ae-analysis/references/dashboard_update.md +4 -1
  66. package/skills/ae-analysis/references/project_space_business_filter_upsert.md +17 -0
  67. package/skills/ae-analysis/references/user_tag_models.md +4 -4
  68. package/skills/ae-data-integration/SKILL.md +54 -0
  69. package/skills/ae-data-integration/references/handoff.md +43 -0
  70. package/skills/ae-data-integration/references/local-analysis.md +27 -0
  71. package/skills/ae-data-integration/references/reuse.md +41 -0
  72. package/skills/ae-data-integration/references/sink-upload.md +58 -0
  73. package/skills/ae-data-integration/references/source-inspect.md +55 -0
  74. package/skills/ae-data-integration/references/sync-json-upload.md +60 -0
  75. package/skills/ae-data-integration/references/tracking-plan.md +35 -0
  76. package/skills/ae-data-integration/references/transform.md +65 -0
  77. package/skills/ae-data-integration/references/ue-mapping.md +142 -0
  78. package/skills/ae-data-integration/references/ue-routing.md +35 -0
  79. package/skills/ae-data-integration-helper/SKILL.md +1 -1
  80. package/skills/ae-dataops/SKILL.md +1 -1
  81. package/skills/ae-dataops/references/dataops-query.md +4 -4
  82. package/skills/ae-generate-tracking-plan/SKILL.md +54 -3
  83. package/skills/ae-metadata/SKILL.md +0 -1
  84. package/dist/chunk-3FY3RJ26.js +0 -293
  85. package/dist/chunk-S5NTSDBS.js +0 -198
  86. package/dist/chunk-ZQKDZXDO.js +0 -317
  87. package/dist/cli-token-4UPER74P.js +0 -21
@@ -9,12 +9,42 @@ import {
9
9
  postToMainApp,
10
10
  putToMainApp,
11
11
  uploadToMainApp
12
- } from "./chunk-VLWOLBGZ.js";
13
- import "./chunk-3FY3RJ26.js";
12
+ } from "./chunk-VPKZ7I72.js";
13
+ import {
14
+ buildCapabilityGatewayUrl,
15
+ callCapabilityApi
16
+ } from "./chunk-ILIU36SU.js";
17
+ import "./chunk-6EIJSNBD.js";
18
+ import "./chunk-4SGZG4XY.js";
19
+ import "./chunk-ZZUOD757.js";
14
20
  import {
15
21
  CliValidationError
16
- } from "./chunk-AXDXJTPC.js";
17
- import "./chunk-JHENBQ5B.js";
22
+ } from "./chunk-UW5UN47B.js";
23
+ import "./chunk-LYVNONC4.js";
24
+ import "./chunk-QGM4M3NI.js";
25
+
26
+ // src/commands/te-agent/api-client.ts
27
+ function getAgentApi(ctx, path) {
28
+ return getFromMainApp(path, ctx.host());
29
+ }
30
+ function postAgentApi(ctx, path, body) {
31
+ return postToMainApp(path, body, ctx.host());
32
+ }
33
+ function patchAgentApi(ctx, path, body) {
34
+ return patchToMainApp(path, body, ctx.host());
35
+ }
36
+ function putAgentApi(ctx, path, body) {
37
+ return putToMainApp(path, body, ctx.host());
38
+ }
39
+ function deleteAgentApi(ctx, path) {
40
+ return deleteFromMainApp(path, ctx.host());
41
+ }
42
+ function uploadAgentApi(ctx, path, formData) {
43
+ return uploadToMainApp(path, formData, ctx.host());
44
+ }
45
+ function getAgentBuffer(ctx, path) {
46
+ return getBufferFromMainApp(path, ctx.host());
47
+ }
18
48
 
19
49
  // src/commands/te-agent/agents.ts
20
50
  var BASE_PATH = "/api/sandbox/agent/agents";
@@ -53,7 +83,7 @@ var listAgents = {
53
83
  }
54
84
  },
55
85
  dryRun: (ctx) => ({ method: "GET", url: `${BASE_PATH}${buildQuery(ctx)}` }),
56
- execute: async (ctx) => getFromMainApp(`${BASE_PATH}${buildQuery(ctx)}`)
86
+ execute: async (ctx) => getAgentApi(ctx, `${BASE_PATH}${buildQuery(ctx)}`)
57
87
  };
58
88
  async function resolveInstructions(raw) {
59
89
  if (raw === "@-") {
@@ -126,7 +156,7 @@ var createAgent = {
126
156
  const skillIds = ctx.json("skillIds");
127
157
  if (skillIds) body.skillIds = skillIds;
128
158
  if (ctx.bool("autoRename")) body.autoRename = true;
129
- return postToMainApp(BASE_PATH, body);
159
+ return postAgentApi(ctx, BASE_PATH, body);
130
160
  }
131
161
  };
132
162
  var updateAgent = {
@@ -182,7 +212,7 @@ var updateAgent = {
182
212
  const skillIds = ctx.json("skillIds");
183
213
  if (skillIds) body.skillIds = skillIds;
184
214
  if (ctx.str("enabled")) body.enabled = ctx.bool("enabled");
185
- return patchToMainApp(`${BASE_PATH}/${encodeURIComponent(ctx.str("id"))}`, body);
215
+ return patchAgentApi(ctx, `${BASE_PATH}/${encodeURIComponent(ctx.str("id"))}`, body);
186
216
  }
187
217
  };
188
218
  var delAgent = {
@@ -198,7 +228,7 @@ var delAgent = {
198
228
  url: `${BASE_PATH}/${encodeURIComponent(ctx.str("id"))}`
199
229
  }),
200
230
  execute: async (ctx) => {
201
- return deleteFromMainApp(`${BASE_PATH}/${encodeURIComponent(ctx.str("id"))}`);
231
+ return deleteAgentApi(ctx, `${BASE_PATH}/${encodeURIComponent(ctx.str("id"))}`);
202
232
  }
203
233
  };
204
234
  var getAgent = {
@@ -214,7 +244,7 @@ var getAgent = {
214
244
  url: `${BASE_PATH}/${encodeURIComponent(ctx.str("id"))}`
215
245
  }),
216
246
  execute: async (ctx) => {
217
- return getFromMainApp(`${BASE_PATH}/${encodeURIComponent(ctx.str("id"))}`);
247
+ return getAgentApi(ctx, `${BASE_PATH}/${encodeURIComponent(ctx.str("id"))}`);
218
248
  }
219
249
  };
220
250
 
@@ -252,7 +282,8 @@ var listModels = {
252
282
  if (scope) params.set("scope", scope);
253
283
  const qs = params.toString();
254
284
  const current = process.env.TE_AGENT_CURRENT_MODEL_ID?.trim();
255
- const data = await getFromMainApp(
285
+ const data = await getAgentApi(
286
+ ctx,
256
287
  `${BASE_PATH2}${qs ? `?${qs}` : ""}`
257
288
  );
258
289
  const items = data?.items ?? [];
@@ -332,7 +363,7 @@ var addModel = {
332
363
  }
333
364
  }),
334
365
  execute: async (ctx) => {
335
- return postToMainApp(BASE_PATH2, {
366
+ return postAgentApi(ctx, BASE_PATH2, {
336
367
  modelId: ctx.str("modelId"),
337
368
  displayName: ctx.str("name"),
338
369
  baseUrl: ctx.str("baseUrl"),
@@ -378,7 +409,7 @@ var delModel = {
378
409
  execute: async (ctx) => {
379
410
  const scope = ctx.str("scope") || "personal";
380
411
  const qs = `id=${encodeURIComponent(ctx.str("id"))}&scope=${encodeURIComponent(scope)}`;
381
- return deleteFromMainApp(`${BASE_PATH2}?${qs}`);
412
+ return deleteAgentApi(ctx, `${BASE_PATH2}?${qs}`);
382
413
  }
383
414
  };
384
415
  var toggleModel = {
@@ -406,7 +437,7 @@ var toggleModel = {
406
437
  body: { id: ctx.str("id"), enabled: ctx.bool("enabled") }
407
438
  }),
408
439
  execute: async (ctx) => {
409
- return patchToMainApp(BASE_PATH2, {
440
+ return patchAgentApi(ctx, BASE_PATH2, {
410
441
  id: ctx.str("id"),
411
442
  enabled: ctx.bool("enabled")
412
443
  });
@@ -480,7 +511,7 @@ var updateModel = {
480
511
  if (contextLength !== void 0) body.contextLength = contextLength;
481
512
  if (ctx.bool("autoRename")) body.autoRename = true;
482
513
  body.scope = ctx.str("scope") || "personal";
483
- return postToMainApp(BASE_PATH2, body);
514
+ return postAgentApi(ctx, BASE_PATH2, body);
484
515
  }
485
516
  };
486
517
  var testModel = {
@@ -527,7 +558,7 @@ var testModel = {
527
558
  if (provider) body.provider = provider;
528
559
  const id = ctx.str("id");
529
560
  if (id) body.existingConfigId = id;
530
- return postToMainApp(`${BASE_PATH2}/test`, body);
561
+ return postAgentApi(ctx, `${BASE_PATH2}/test`, body);
531
562
  }
532
563
  };
533
564
 
@@ -601,7 +632,7 @@ var listMcps = {
601
632
  execute: async (ctx) => {
602
633
  const scope = ctx.str("scope");
603
634
  const qs = scope ? `?scope=${encodeURIComponent(scope)}` : "";
604
- return getFromMainApp(`${BASE_PATH3}${qs}`);
635
+ return getAgentApi(ctx, `${BASE_PATH3}${qs}`);
605
636
  }
606
637
  };
607
638
  var addMcp = {
@@ -665,7 +696,7 @@ var addMcp = {
665
696
  return { method: "POST", url: BASE_PATH3, body };
666
697
  },
667
698
  execute: async (ctx) => {
668
- const created = await postToMainApp(BASE_PATH3, {
699
+ const created = await postAgentApi(ctx, BASE_PATH3, {
669
700
  name: ctx.str("name"),
670
701
  url: ctx.str("url"),
671
702
  displayName: ctx.str("displayName") || void 0,
@@ -678,7 +709,7 @@ var addMcp = {
678
709
  const meta = buildMetaBody(ctx);
679
710
  if (id && meta) {
680
711
  try {
681
- await patchToMainApp(`${MARKET_BASE_PATH}/${encodeURIComponent(id)}/meta`, meta);
712
+ await patchAgentApi(ctx, `${MARKET_BASE_PATH}/${encodeURIComponent(id)}/meta`, meta);
682
713
  } catch (err) {
683
714
  process.stderr.write(`Warning: MCP created but meta update failed: ${err?.message ?? err}
684
715
  `);
@@ -700,7 +731,7 @@ var delMcp = {
700
731
  url: `${BASE_PATH3}?id=${encodeURIComponent(ctx.str("id"))}`
701
732
  }),
702
733
  execute: async (ctx) => {
703
- return deleteFromMainApp(`${BASE_PATH3}?id=${encodeURIComponent(ctx.str("id"))}`);
734
+ return deleteAgentApi(ctx, `${BASE_PATH3}?id=${encodeURIComponent(ctx.str("id"))}`);
704
735
  }
705
736
  };
706
737
  var toggleMcp = {
@@ -718,7 +749,7 @@ var toggleMcp = {
718
749
  body: { id: ctx.str("id"), enabled: ctx.bool("enabled") }
719
750
  }),
720
751
  execute: async (ctx) => {
721
- return patchToMainApp(BASE_PATH3, {
752
+ return patchAgentApi(ctx, BASE_PATH3, {
722
753
  id: ctx.str("id"),
723
754
  enabled: ctx.bool("enabled")
724
755
  });
@@ -756,7 +787,7 @@ var listMcpMarket = {
756
787
  url: `${MARKET_BASE_PATH}/market?${buildMarketQuery(ctx).toString()}`
757
788
  }),
758
789
  execute: async (ctx) => {
759
- return getFromMainApp(`${MARKET_BASE_PATH}/market?${buildMarketQuery(ctx).toString()}`);
790
+ return getAgentApi(ctx, `${MARKET_BASE_PATH}/market?${buildMarketQuery(ctx).toString()}`);
760
791
  }
761
792
  };
762
793
  var setMcpMeta = {
@@ -785,7 +816,8 @@ var setMcpMeta = {
785
816
  body: buildMetaBody(ctx)
786
817
  }),
787
818
  execute: async (ctx) => {
788
- return patchToMainApp(
819
+ return patchAgentApi(
820
+ ctx,
789
821
  `${MARKET_BASE_PATH}/${encodeURIComponent(ctx.str("id"))}/meta`,
790
822
  buildMetaBody(ctx)
791
823
  );
@@ -875,7 +907,8 @@ var updateMcp = {
875
907
  body: buildUpdateBody(ctx)
876
908
  }),
877
909
  execute: async (ctx) => {
878
- return patchToMainApp(
910
+ return patchAgentApi(
911
+ ctx,
879
912
  `${BASE_PATH3}/${encodeURIComponent(ctx.str("id"))}`,
880
913
  buildUpdateBody(ctx)
881
914
  );
@@ -894,7 +927,7 @@ var mcpTools = {
894
927
  url: `${BASE_PATH3}/${encodeURIComponent(ctx.str("id"))}/tools`
895
928
  }),
896
929
  execute: async (ctx) => {
897
- return getFromMainApp(`${BASE_PATH3}/${encodeURIComponent(ctx.str("id"))}/tools`);
930
+ return getAgentApi(ctx, `${BASE_PATH3}/${encodeURIComponent(ctx.str("id"))}/tools`);
898
931
  }
899
932
  };
900
933
  var mcpAuthStart = {
@@ -916,7 +949,8 @@ var mcpAuthStart = {
916
949
  }
917
950
  }),
918
951
  execute: async (ctx) => {
919
- const result = await postToMainApp(
952
+ const result = await postAgentApi(
953
+ ctx,
920
954
  `${BASE_PATH3}/${encodeURIComponent(ctx.str("id"))}/auth/start`,
921
955
  {
922
956
  redirectAfter: ctx.str("redirectAfter") || void 0
@@ -951,7 +985,7 @@ var mcpAuthStatus = {
951
985
  url: `${BASE_PATH3}/${encodeURIComponent(ctx.str("id"))}/auth/status`
952
986
  }),
953
987
  execute: async (ctx) => {
954
- return getFromMainApp(`${BASE_PATH3}/${encodeURIComponent(ctx.str("id"))}/auth/status`);
988
+ return getAgentApi(ctx, `${BASE_PATH3}/${encodeURIComponent(ctx.str("id"))}/auth/status`);
955
989
  }
956
990
  };
957
991
  var mcpAuthDisconnect = {
@@ -967,7 +1001,8 @@ var mcpAuthDisconnect = {
967
1001
  url: `${BASE_PATH3}/${encodeURIComponent(ctx.str("id"))}/auth/disconnect`
968
1002
  }),
969
1003
  execute: async (ctx) => {
970
- return postToMainApp(
1004
+ return postAgentApi(
1005
+ ctx,
971
1006
  `${BASE_PATH3}/${encodeURIComponent(ctx.str("id"))}/auth/disconnect`,
972
1007
  {}
973
1008
  );
@@ -983,8 +1018,8 @@ var listMcpCredentials = {
983
1018
  method: "GET",
984
1019
  url: CRED_BASE_PATH
985
1020
  }),
986
- execute: async () => {
987
- return getFromMainApp(CRED_BASE_PATH);
1021
+ execute: async (ctx) => {
1022
+ return getAgentApi(ctx, CRED_BASE_PATH);
988
1023
  }
989
1024
  };
990
1025
  var setMcpCredential = {
@@ -1022,7 +1057,7 @@ var setMcpCredential = {
1022
1057
  }
1023
1058
  }),
1024
1059
  execute: async (ctx) => {
1025
- return postToMainApp(CRED_BASE_PATH, {
1060
+ return postAgentApi(ctx, CRED_BASE_PATH, {
1026
1061
  mcpServerId: ctx.str("mcpServerId"),
1027
1062
  authType: ctx.str("authType") || "oauth",
1028
1063
  token: ctx.str("token") || void 0,
@@ -1047,7 +1082,7 @@ var autoProvisionMcpCredentials = {
1047
1082
  }),
1048
1083
  execute: async (ctx) => {
1049
1084
  const accessToken = ctx.str("accessToken") || await ctx.token();
1050
- return postToMainApp(`${CRED_BASE_PATH}/auto-provision`, { accessToken });
1085
+ return postAgentApi(ctx, `${CRED_BASE_PATH}/auto-provision`, { accessToken });
1051
1086
  }
1052
1087
  };
1053
1088
  var mcpToken = {
@@ -1061,7 +1096,7 @@ var mcpToken = {
1061
1096
  url: `${CRED_BASE_PATH}/mcp-token`
1062
1097
  }),
1063
1098
  execute: async (ctx) => {
1064
- const result = await getFromMainApp(`${CRED_BASE_PATH}/mcp-token`);
1099
+ const result = await getAgentApi(ctx, `${CRED_BASE_PATH}/mcp-token`);
1065
1100
  if (process.stderr.isTTY) {
1066
1101
  process.stderr.write(
1067
1102
  `
@@ -1093,7 +1128,7 @@ var mcpStats = {
1093
1128
  },
1094
1129
  execute: async (ctx) => {
1095
1130
  const days = ctx.optionalNum("days") ?? 30;
1096
- return getFromMainApp(`${STATS_PATH}?days=${days}`);
1131
+ return getAgentApi(ctx, `${STATS_PATH}?days=${days}`);
1097
1132
  }
1098
1133
  };
1099
1134
 
@@ -1149,7 +1184,7 @@ var listSkills = {
1149
1184
  execute: async (ctx) => {
1150
1185
  const scope = ctx.str("scope");
1151
1186
  const qs = scope ? `?scope=${encodeURIComponent(scope)}` : "";
1152
- return getFromMainApp(`${BASE_PATH4}${qs}`);
1187
+ return getAgentApi(ctx, `${BASE_PATH4}${qs}`);
1153
1188
  }
1154
1189
  };
1155
1190
  var addSkill = {
@@ -1245,7 +1280,7 @@ var addSkill = {
1245
1280
  },
1246
1281
  execute: async (ctx) => {
1247
1282
  const instructions = await resolveInstructions2(ctx.str("instructions"));
1248
- const created = await postToMainApp(BASE_PATH4, {
1283
+ const created = await postAgentApi(ctx, BASE_PATH4, {
1249
1284
  name: ctx.str("name"),
1250
1285
  description: ctx.str("description"),
1251
1286
  instructions,
@@ -1257,7 +1292,7 @@ var addSkill = {
1257
1292
  const meta = buildMetaBody2(ctx);
1258
1293
  if (id && meta) {
1259
1294
  try {
1260
- await patchToMainApp(`${MARKET_BASE_PATH2}/${encodeURIComponent(id)}/meta`, meta);
1295
+ await patchAgentApi(ctx, `${MARKET_BASE_PATH2}/${encodeURIComponent(id)}/meta`, meta);
1261
1296
  } catch (err) {
1262
1297
  process.stderr.write(`Warning: Skill created but meta update failed: ${err?.message ?? err}
1263
1298
  `);
@@ -1284,7 +1319,7 @@ var delSkill = {
1284
1319
  url: `${BASE_PATH4}?id=${encodeURIComponent(ctx.str("id"))}`
1285
1320
  }),
1286
1321
  execute: async (ctx) => {
1287
- return deleteFromMainApp(`${BASE_PATH4}?id=${encodeURIComponent(ctx.str("id"))}`);
1322
+ return deleteAgentApi(ctx, `${BASE_PATH4}?id=${encodeURIComponent(ctx.str("id"))}`);
1288
1323
  }
1289
1324
  };
1290
1325
  var toggleSkill = {
@@ -1312,7 +1347,7 @@ var toggleSkill = {
1312
1347
  body: { id: ctx.str("id"), enabled: ctx.bool("enabled") }
1313
1348
  }),
1314
1349
  execute: async (ctx) => {
1315
- return patchToMainApp(BASE_PATH4, {
1350
+ return patchAgentApi(ctx, BASE_PATH4, {
1316
1351
  id: ctx.str("id"),
1317
1352
  enabled: ctx.bool("enabled")
1318
1353
  });
@@ -1384,7 +1419,7 @@ var listSkillMarket = {
1384
1419
  url: `${MARKET_BASE_PATH2}/market?${buildMarketQuery(ctx).toString()}`
1385
1420
  }),
1386
1421
  execute: async (ctx) => {
1387
- return getFromMainApp(`${MARKET_BASE_PATH2}/market?${buildMarketQuery(ctx).toString()}`);
1422
+ return getAgentApi(ctx, `${MARKET_BASE_PATH2}/market?${buildMarketQuery(ctx).toString()}`);
1388
1423
  }
1389
1424
  };
1390
1425
  var setSkillMeta = {
@@ -1433,7 +1468,7 @@ var setSkillMeta = {
1433
1468
  body: buildMetaBody2(ctx)
1434
1469
  }),
1435
1470
  execute: async (ctx) => {
1436
- return patchToMainApp(`${MARKET_BASE_PATH2}/${encodeURIComponent(ctx.str("id"))}/meta`, buildMetaBody2(ctx));
1471
+ return patchAgentApi(ctx, `${MARKET_BASE_PATH2}/${encodeURIComponent(ctx.str("id"))}/meta`, buildMetaBody2(ctx));
1437
1472
  }
1438
1473
  };
1439
1474
  var copySkill = {
@@ -1479,7 +1514,7 @@ var copySkill = {
1479
1514
  body: buildMetaBody2(ctx) ?? {}
1480
1515
  }),
1481
1516
  execute: async (ctx) => {
1482
- return postToMainApp(`${MARKET_BASE_PATH2}/${encodeURIComponent(ctx.str("id"))}/copy`, buildMetaBody2(ctx) ?? {});
1517
+ return postAgentApi(ctx, `${MARKET_BASE_PATH2}/${encodeURIComponent(ctx.str("id"))}/copy`, buildMetaBody2(ctx) ?? {});
1483
1518
  }
1484
1519
  };
1485
1520
 
@@ -1561,7 +1596,7 @@ function makeAssetListCommand(commandName, description, dirName) {
1561
1596
  url: `${BASE_PATH5}/${encodeURIComponent(ctx.str("id"))}/${dirName}`
1562
1597
  }),
1563
1598
  execute: async (ctx) => {
1564
- return getFromMainApp(`${BASE_PATH5}/${encodeURIComponent(ctx.str("id"))}/${dirName}`);
1599
+ return getAgentApi(ctx, `${BASE_PATH5}/${encodeURIComponent(ctx.str("id"))}/${dirName}`);
1565
1600
  }
1566
1601
  };
1567
1602
  }
@@ -1604,7 +1639,7 @@ function makeAssetUploadCommand(commandName, description, dirName) {
1604
1639
  }),
1605
1640
  execute: async (ctx) => {
1606
1641
  const fd = buildAssetFormData(ctx.str("file"), ctx.str("subPath") || void 0);
1607
- return uploadToMainApp(`${BASE_PATH5}/${encodeURIComponent(ctx.str("id"))}/${dirName}`, fd);
1642
+ return uploadAgentApi(ctx, `${BASE_PATH5}/${encodeURIComponent(ctx.str("id"))}/${dirName}`, fd);
1608
1643
  }
1609
1644
  };
1610
1645
  }
@@ -1647,7 +1682,7 @@ function makeAssetReadCommand(commandName, description, dirName) {
1647
1682
  const filePath = ctx.str("path");
1648
1683
  const encodedPath = filePath.split("/").map((seg) => encodeURIComponent(seg)).join("/");
1649
1684
  const url = `${BASE_PATH5}/${encodeURIComponent(ctx.str("id"))}/${dirName}/${encodedPath}`;
1650
- const { buffer, fileName, contentType } = await getBufferFromMainApp(url);
1685
+ const { buffer, fileName, contentType } = await getAgentBuffer(ctx, url);
1651
1686
  const outputPath = ctx.str("output");
1652
1687
  if (outputPath) {
1653
1688
  const resolved = resolve(outputPath);
@@ -1692,7 +1727,7 @@ function makeAssetDelCommand(commandName, description, dirName) {
1692
1727
  execute: async (ctx) => {
1693
1728
  const filePath = ctx.str("path");
1694
1729
  const encodedPath = filePath.split("/").map((seg) => encodeURIComponent(seg)).join("/");
1695
- return deleteFromMainApp(`${BASE_PATH5}/${encodeURIComponent(ctx.str("id"))}/${dirName}/${encodedPath}`);
1730
+ return deleteAgentApi(ctx, `${BASE_PATH5}/${encodeURIComponent(ctx.str("id"))}/${dirName}/${encodedPath}`);
1696
1731
  }
1697
1732
  };
1698
1733
  }
@@ -1807,7 +1842,7 @@ var editSkill = {
1807
1842
  if (ctx.str("iconEmoji")) body.iconEmoji = ctx.str("iconEmoji");
1808
1843
  if (ctx.str("iconColor")) body.iconColor = ctx.str("iconColor");
1809
1844
  if (ctx.str("version")) body.version = ctx.str("version");
1810
- return putToMainApp(`${BASE_PATH5}/${encodeURIComponent(ctx.str("id"))}`, body);
1845
+ return putAgentApi(ctx, `${BASE_PATH5}/${encodeURIComponent(ctx.str("id"))}`, body);
1811
1846
  }
1812
1847
  };
1813
1848
  var getSkillContent = {
@@ -1828,7 +1863,7 @@ var getSkillContent = {
1828
1863
  url: `${BASE_PATH5}/${encodeURIComponent(ctx.str("id"))}/content`
1829
1864
  }),
1830
1865
  execute: async (ctx) => {
1831
- return getFromMainApp(`${BASE_PATH5}/${encodeURIComponent(ctx.str("id"))}/content`);
1866
+ return getAgentApi(ctx, `${BASE_PATH5}/${encodeURIComponent(ctx.str("id"))}/content`);
1832
1867
  }
1833
1868
  };
1834
1869
  var listSkillAssets = makeAssetListCommand(
@@ -2039,7 +2074,7 @@ var uploadSkill = {
2039
2074
  if (ctx.str("iconEmoji")) fd.append("iconEmoji", ctx.str("iconEmoji"));
2040
2075
  if (ctx.str("iconColor")) fd.append("iconColor", ctx.str("iconColor"));
2041
2076
  if (ctx.str("version")) fd.append("version", ctx.str("version"));
2042
- return uploadToMainApp(`${BASE_PATH5}/upload`, fd);
2077
+ return uploadAgentApi(ctx, `${BASE_PATH5}/upload`, fd);
2043
2078
  }
2044
2079
  };
2045
2080
  var rescanSkills = {
@@ -2052,8 +2087,8 @@ var rescanSkills = {
2052
2087
  method: "POST",
2053
2088
  url: `${BASE_PATH5}/rescan`
2054
2089
  }),
2055
- execute: async () => {
2056
- return postToMainApp(`${BASE_PATH5}/rescan`, {});
2090
+ execute: async (ctx) => {
2091
+ return postAgentApi(ctx, `${BASE_PATH5}/rescan`, {});
2057
2092
  }
2058
2093
  };
2059
2094
 
@@ -2103,7 +2138,7 @@ var submitSkill = {
2103
2138
  if (iconEmoji) body.iconEmoji = iconEmoji;
2104
2139
  const iconColor = ctx.str("iconColor");
2105
2140
  if (iconColor) body.iconColor = iconColor;
2106
- return postToMainApp(`${BASE}/${encodeURIComponent(ctx.str("id"))}/submit`, body);
2141
+ return postAgentApi(ctx, `${BASE}/${encodeURIComponent(ctx.str("id"))}/submit`, body);
2107
2142
  }
2108
2143
  };
2109
2144
  var listSkillSubmissions = {
@@ -2135,7 +2170,7 @@ var listSkillSubmissions = {
2135
2170
  if (status) params.set("status", status);
2136
2171
  if (ctx.bool("mine")) params.set("mine", "true");
2137
2172
  const qs = params.toString();
2138
- return getFromMainApp(`${BASE}/submissions${qs ? `?${qs}` : ""}`);
2173
+ return getAgentApi(ctx, `${BASE}/submissions${qs ? `?${qs}` : ""}`);
2139
2174
  }
2140
2175
  };
2141
2176
  var cancelSkillSubmission = {
@@ -2151,7 +2186,7 @@ var cancelSkillSubmission = {
2151
2186
  url: `${BASE}/submissions/${encodeURIComponent(ctx.str("id"))}/cancel`
2152
2187
  }),
2153
2188
  execute: async (ctx) => {
2154
- return postToMainApp(`${BASE}/submissions/${encodeURIComponent(ctx.str("id"))}/cancel`, {});
2189
+ return postAgentApi(ctx, `${BASE}/submissions/${encodeURIComponent(ctx.str("id"))}/cancel`, {});
2155
2190
  }
2156
2191
  };
2157
2192
  var approveSkill = {
@@ -2167,7 +2202,7 @@ var approveSkill = {
2167
2202
  url: `${BASE}/submissions/${encodeURIComponent(ctx.str("id"))}/approve`
2168
2203
  }),
2169
2204
  execute: async (ctx) => {
2170
- return postToMainApp(`${BASE}/submissions/${encodeURIComponent(ctx.str("id"))}/approve`, {});
2205
+ return postAgentApi(ctx, `${BASE}/submissions/${encodeURIComponent(ctx.str("id"))}/approve`, {});
2171
2206
  }
2172
2207
  };
2173
2208
  var rejectSkill = {
@@ -2191,7 +2226,7 @@ var rejectSkill = {
2191
2226
  body: { reason: ctx.str("reason") }
2192
2227
  }),
2193
2228
  execute: async (ctx) => {
2194
- return postToMainApp(`${BASE}/submissions/${encodeURIComponent(ctx.str("id"))}/reject`, {
2229
+ return postAgentApi(ctx, `${BASE}/submissions/${encodeURIComponent(ctx.str("id"))}/reject`, {
2195
2230
  reason: ctx.str("reason")
2196
2231
  });
2197
2232
  }
@@ -2239,7 +2274,7 @@ var shareSkill = {
2239
2274
  if (iconEmoji) body.iconEmoji = iconEmoji;
2240
2275
  const iconColor = ctx.str("iconColor");
2241
2276
  if (iconColor) body.iconColor = iconColor;
2242
- return postToMainApp(`${BASE2}/${encodeURIComponent(ctx.str("id"))}/share`, body);
2277
+ return postAgentApi(ctx, `${BASE2}/${encodeURIComponent(ctx.str("id"))}/share`, body);
2243
2278
  }
2244
2279
  };
2245
2280
  var listSkillShares = {
@@ -2273,7 +2308,7 @@ var listSkillShares = {
2273
2308
  params.set("direction", ctx.str("direction") || "received");
2274
2309
  const status = ctx.str("status");
2275
2310
  if (status) params.set("status", status);
2276
- return getFromMainApp(`${BASE2}/shares?${params.toString()}`);
2311
+ return getAgentApi(ctx, `${BASE2}/shares?${params.toString()}`);
2277
2312
  }
2278
2313
  };
2279
2314
  var acceptSkillShare = {
@@ -2289,7 +2324,7 @@ var acceptSkillShare = {
2289
2324
  url: `${BASE2}/shares/${encodeURIComponent(ctx.str("id"))}/accept`
2290
2325
  }),
2291
2326
  execute: async (ctx) => {
2292
- return postToMainApp(`${BASE2}/shares/${encodeURIComponent(ctx.str("id"))}/accept`, {});
2327
+ return postAgentApi(ctx, `${BASE2}/shares/${encodeURIComponent(ctx.str("id"))}/accept`, {});
2293
2328
  }
2294
2329
  };
2295
2330
  var rejectSkillShare = {
@@ -2305,7 +2340,7 @@ var rejectSkillShare = {
2305
2340
  url: `${BASE2}/shares/${encodeURIComponent(ctx.str("id"))}/reject`
2306
2341
  }),
2307
2342
  execute: async (ctx) => {
2308
- return postToMainApp(`${BASE2}/shares/${encodeURIComponent(ctx.str("id"))}/reject`, {});
2343
+ return postAgentApi(ctx, `${BASE2}/shares/${encodeURIComponent(ctx.str("id"))}/reject`, {});
2309
2344
  }
2310
2345
  };
2311
2346
 
@@ -2362,7 +2397,7 @@ function resolveFilePaths(ctx) {
2362
2397
  throw err;
2363
2398
  }
2364
2399
  }
2365
- async function uploadFiles(filePaths) {
2400
+ async function uploadFiles(ctx, filePaths) {
2366
2401
  const formData = new FormData();
2367
2402
  for (const filePath of filePaths) {
2368
2403
  const resolved = resolve2(filePath);
@@ -2374,7 +2409,7 @@ async function uploadFiles(filePaths) {
2374
2409
  const blob = new Blob([buffer], { type: mimeType });
2375
2410
  formData.append("file", blob, basename2(resolved));
2376
2411
  }
2377
- return uploadToMainApp(UPLOAD_PATH, formData);
2412
+ return uploadAgentApi(ctx, UPLOAD_PATH, formData);
2378
2413
  }
2379
2414
  var listAttachments = {
2380
2415
  service: "agent",
@@ -2409,7 +2444,7 @@ var listAttachments = {
2409
2444
  if (ctx.num("page")) params.set("page", String(ctx.num("page")));
2410
2445
  if (ctx.num("pageSize")) params.set("pageSize", String(ctx.num("pageSize")));
2411
2446
  const qs = params.toString();
2412
- return getFromMainApp(`${LIST_PATH}${qs ? "?" + qs : ""}`);
2447
+ return getAgentApi(ctx, `${LIST_PATH}${qs ? "?" + qs : ""}`);
2413
2448
  }
2414
2449
  };
2415
2450
  var addAttachment = {
@@ -2430,7 +2465,7 @@ var addAttachment = {
2430
2465
  },
2431
2466
  execute: async (ctx) => {
2432
2467
  const paths = resolveFilePaths(ctx);
2433
- return uploadFiles(paths);
2468
+ return uploadFiles(ctx, paths);
2434
2469
  }
2435
2470
  };
2436
2471
  var delAttachment = {
@@ -2446,7 +2481,7 @@ var delAttachment = {
2446
2481
  url: `${LIST_PATH}?id=${encodeURIComponent(ctx.str("id"))}`
2447
2482
  }),
2448
2483
  execute: async (ctx) => {
2449
- return deleteFromMainApp(`${LIST_PATH}?id=${encodeURIComponent(ctx.str("id"))}`);
2484
+ return deleteAgentApi(ctx, `${LIST_PATH}?id=${encodeURIComponent(ctx.str("id"))}`);
2450
2485
  }
2451
2486
  };
2452
2487
  var attachmentStats = {
@@ -2459,8 +2494,8 @@ var attachmentStats = {
2459
2494
  method: "GET",
2460
2495
  url: STATS_PATH2
2461
2496
  }),
2462
- execute: async () => {
2463
- return getFromMainApp(STATS_PATH2);
2497
+ execute: async (ctx) => {
2498
+ return getAgentApi(ctx, STATS_PATH2);
2464
2499
  }
2465
2500
  };
2466
2501
 
@@ -2695,7 +2730,7 @@ var listAutomations = {
2695
2730
  method: "GET",
2696
2731
  url: buildListPath(ctx)
2697
2732
  }),
2698
- execute: async (ctx) => getFromMainApp(buildListPath(ctx))
2733
+ execute: async (ctx) => getAgentApi(ctx, buildListPath(ctx))
2699
2734
  };
2700
2735
  var createAutomation = {
2701
2736
  service: "agent",
@@ -2764,7 +2799,7 @@ var createAutomation = {
2764
2799
  url: BASE_PATH6,
2765
2800
  body: buildCreateBody(ctx)
2766
2801
  }),
2767
- execute: async (ctx) => postToMainApp(BASE_PATH6, buildCreateBody(ctx))
2802
+ execute: async (ctx) => postAgentApi(ctx, BASE_PATH6, buildCreateBody(ctx))
2768
2803
  };
2769
2804
  var updateAutomation = {
2770
2805
  service: "agent",
@@ -2810,7 +2845,8 @@ var updateAutomation = {
2810
2845
  url: `${BASE_PATH6}/${encodeURIComponent(ctx.str("id"))}`,
2811
2846
  body: buildUpdateBody2(ctx)
2812
2847
  }),
2813
- execute: async (ctx) => patchToMainApp(
2848
+ execute: async (ctx) => patchAgentApi(
2849
+ ctx,
2814
2850
  `${BASE_PATH6}/${encodeURIComponent(ctx.str("id"))}`,
2815
2851
  buildUpdateBody2(ctx)
2816
2852
  )
@@ -3151,7 +3187,8 @@ var findArchivedConversations = {
3151
3187
  }),
3152
3188
  execute: async (ctx) => {
3153
3189
  const timeZone = readTimeZone(ctx);
3154
- const result = await getFromMainApp(
3190
+ const result = await getAgentApi(
3191
+ ctx,
3155
3192
  buildArchivedConversationSearchPath(ctx)
3156
3193
  );
3157
3194
  return {
@@ -3181,7 +3218,8 @@ var restoreConversation = {
3181
3218
  body: {}
3182
3219
  }),
3183
3220
  execute: async (ctx) => {
3184
- const result = await postToMainApp(
3221
+ const result = await postAgentApi(
3222
+ ctx,
3185
3223
  `${CONVERSATION_PATH}/${encodeURIComponent(ctx.str("conversationId"))}/restore`,
3186
3224
  {}
3187
3225
  );
@@ -3189,6 +3227,569 @@ var restoreConversation = {
3189
3227
  }
3190
3228
  };
3191
3229
 
3230
+ // src/commands/te-agent/approval-cli-client.ts
3231
+ var APPROVAL_GATEWAY_DOMAIN = "approval";
3232
+ var DEFAULT_TE_CLAUDE_BASE_PATH = "/agent";
3233
+ function normalizeBasePath(value) {
3234
+ const trimmed = value.trim();
3235
+ if (!trimmed || trimmed === "/") return "";
3236
+ return `/${trimmed.replace(/^\/+|\/+$/g, "")}`;
3237
+ }
3238
+ function resolveApprovalApiBaseUrl(host) {
3239
+ const base = host.replace(/\/+$/, "");
3240
+ const basePath = normalizeBasePath(
3241
+ process.env.TE_CLAUDE_BASE_PATH ?? process.env.AE_API_PREFIX ?? DEFAULT_TE_CLAUDE_BASE_PATH
3242
+ );
3243
+ return basePath && !base.endsWith(basePath) ? `${base}${basePath}` : base;
3244
+ }
3245
+ function buildApprovalCliUrl(ctx, path) {
3246
+ return buildCapabilityGatewayUrl(resolveApprovalApiBaseUrl(ctx.host()), APPROVAL_GATEWAY_DOMAIN, path);
3247
+ }
3248
+ function requestApprovalCli(ctx, method, path, body, options = {}) {
3249
+ return callCapabilityApi(
3250
+ ctx.host(),
3251
+ APPROVAL_GATEWAY_DOMAIN,
3252
+ path,
3253
+ method,
3254
+ body,
3255
+ {
3256
+ apiBaseUrl: resolveApprovalApiBaseUrl(ctx.host()),
3257
+ ...options,
3258
+ retryOnInvalidTokenForbidden: false
3259
+ }
3260
+ );
3261
+ }
3262
+ function getApprovalCli(ctx, path) {
3263
+ return requestApprovalCli(ctx, "GET", path);
3264
+ }
3265
+ function postApprovalCli(ctx, path, body, options = {}) {
3266
+ return requestApprovalCli(ctx, "POST", path, body, options);
3267
+ }
3268
+
3269
+ // src/commands/te-agent/approval-commands.ts
3270
+ var SERVICE = "agent";
3271
+ var MAX_ID_LENGTH = 191;
3272
+ var MAX_VERSION = 2147483647;
3273
+ var DECISION_STATUSES = ["pending", "approved", "rejected", "cancelled"];
3274
+ var TASK_STATUSES = ["pending", "completed", "cancelled"];
3275
+ var EFFECT_STATUSES = ["pending", "running", "succeeded", "failed", "manual_required"];
3276
+ var LOCAL_DRY_RUN_HELP = [
3277
+ "Dry-run is a local request preview only.",
3278
+ "It does not verify server permissions, current approval state, or future conditional routing."
3279
+ ].join(" ");
3280
+ function validation(message, hint) {
3281
+ throw new CliValidationError(message, { hint });
3282
+ }
3283
+ function optionalString(ctx, name) {
3284
+ const value = ctx.str(name);
3285
+ return value ? value : void 0;
3286
+ }
3287
+ function validateStableId(ctx, name, flagName) {
3288
+ const value = ctx.str(name);
3289
+ if (!value || value !== value.trim() || value.length > MAX_ID_LENGTH) {
3290
+ validation(`--${flagName} must be a non-empty identifier of at most ${MAX_ID_LENGTH} characters`);
3291
+ }
3292
+ }
3293
+ function validateApprovalTypeId(ctx) {
3294
+ const value = ctx.str("approvalTypeId");
3295
+ if (!value || value.length > MAX_ID_LENGTH || !/^[a-z][a-z0-9_.-]*@[1-9]\d*$/.test(value)) {
3296
+ validation("--approval-type-id must use the format type.key@version");
3297
+ }
3298
+ const version = value.slice(value.lastIndexOf("@") + 1);
3299
+ if (BigInt(version) > BigInt(MAX_VERSION)) {
3300
+ validation("--approval-type-id version is out of range");
3301
+ }
3302
+ }
3303
+ function validateClientRequestId(ctx) {
3304
+ validateStableId(ctx, "clientRequestId", "client-request-id");
3305
+ if (ctx.str("clientRequestId").startsWith("system:")) {
3306
+ validation("--client-request-id must not use the reserved system: prefix");
3307
+ }
3308
+ }
3309
+ function validateText(ctx, name, flagName, options) {
3310
+ const value = ctx.str(name);
3311
+ if (!value && !options.required) return;
3312
+ if (!value || value.trim().length === 0) {
3313
+ validation(`--${flagName} must not be empty`);
3314
+ }
3315
+ if (value.length > options.maxLength) {
3316
+ validation(`--${flagName} must not exceed ${options.maxLength} characters`);
3317
+ }
3318
+ }
3319
+ function validateNonNegativeInteger(ctx, name, flagName) {
3320
+ const value = ctx.optionalNum(name);
3321
+ if (value === void 0 || !Number.isInteger(value) || value < 0 || value > MAX_VERSION) {
3322
+ validation(`--${flagName} must be an integer between 0 and ${MAX_VERSION}`);
3323
+ }
3324
+ }
3325
+ function validateExpectedVersion(ctx) {
3326
+ validateNonNegativeInteger(ctx, "expectedVersion", "expected-version");
3327
+ }
3328
+ function validateExpectedAttempt(ctx) {
3329
+ validateNonNegativeInteger(ctx, "expectedAttempt", "expected-attempt");
3330
+ }
3331
+ function assertAllowed(value, flagName, allowed) {
3332
+ if (value && !allowed.includes(value)) {
3333
+ validation(`--${flagName} must be one of: ${allowed.join(", ")}`);
3334
+ }
3335
+ }
3336
+ function validateDateRange(ctx) {
3337
+ const createdAfter = optionalString(ctx, "createdAfter");
3338
+ const createdBefore = optionalString(ctx, "createdBefore");
3339
+ if (createdAfter && Number.isNaN(Date.parse(createdAfter))) {
3340
+ validation("--created-after must be a valid ISO datetime");
3341
+ }
3342
+ if (createdBefore && Number.isNaN(Date.parse(createdBefore))) {
3343
+ validation("--created-before must be a valid ISO datetime");
3344
+ }
3345
+ if (createdAfter && createdBefore && Date.parse(createdAfter) >= Date.parse(createdBefore)) {
3346
+ validation("--created-after must be earlier than --created-before");
3347
+ }
3348
+ }
3349
+ function validateLimit(ctx) {
3350
+ const limit = ctx.optionalNum("limit") ?? 20;
3351
+ if (!Number.isInteger(limit) || limit < 1 || limit > 100) {
3352
+ validation("--limit must be an integer between 1 and 100");
3353
+ }
3354
+ }
3355
+ function isRecord(value) {
3356
+ return value !== null && typeof value === "object" && !Array.isArray(value);
3357
+ }
3358
+ function validateSnakeCaseValue(value, path = "payload") {
3359
+ if (Array.isArray(value)) {
3360
+ value.forEach((item, index) => validateSnakeCaseValue(item, `${path}[${index}]`));
3361
+ return;
3362
+ }
3363
+ if (!isRecord(value)) return;
3364
+ for (const [key, child] of Object.entries(value)) {
3365
+ if (!/^[a-z][a-z0-9]*(?:_[a-z0-9]+)*$/.test(key)) {
3366
+ validation(`--payload keys must use snake_case (invalid key at ${path})`);
3367
+ }
3368
+ validateSnakeCaseValue(child, `${path}.${key}`);
3369
+ }
3370
+ }
3371
+ function approvalPayload(ctx) {
3372
+ const payload = ctx.json("payload");
3373
+ if (!isRecord(payload)) {
3374
+ validation("--payload must be a JSON object");
3375
+ }
3376
+ validateSnakeCaseValue(payload);
3377
+ return payload;
3378
+ }
3379
+ function buildQuery2(params) {
3380
+ const searchParams = new URLSearchParams();
3381
+ for (const [key, value] of Object.entries(params)) {
3382
+ if (value !== void 0 && value !== "") searchParams.set(key, String(value));
3383
+ }
3384
+ const query = searchParams.toString();
3385
+ return query ? `?${query}` : "";
3386
+ }
3387
+ function requestListPath(ctx) {
3388
+ return `requests${buildQuery2({
3389
+ cursor: optionalString(ctx, "cursor"),
3390
+ limit: ctx.optionalNum("limit") ?? 20,
3391
+ type_id: optionalString(ctx, "approvalTypeId"),
3392
+ status: optionalString(ctx, "status"),
3393
+ requester_id: optionalString(ctx, "requesterId"),
3394
+ created_after: optionalString(ctx, "createdAfter"),
3395
+ created_before: optionalString(ctx, "createdBefore")
3396
+ })}`;
3397
+ }
3398
+ function taskListPath(ctx) {
3399
+ return `tasks${buildQuery2({
3400
+ cursor: optionalString(ctx, "cursor"),
3401
+ limit: ctx.optionalNum("limit") ?? 20,
3402
+ status: optionalString(ctx, "status"),
3403
+ request_id: optionalString(ctx, "approvalRequestId"),
3404
+ created_after: optionalString(ctx, "createdAfter"),
3405
+ created_before: optionalString(ctx, "createdBefore")
3406
+ })}`;
3407
+ }
3408
+ function effectListPath(ctx) {
3409
+ return `effects${buildQuery2({
3410
+ cursor: optionalString(ctx, "cursor"),
3411
+ limit: ctx.optionalNum("limit") ?? 20,
3412
+ status: optionalString(ctx, "status"),
3413
+ request_id: optionalString(ctx, "approvalRequestId"),
3414
+ created_after: optionalString(ctx, "createdAfter"),
3415
+ created_before: optionalString(ctx, "createdBefore")
3416
+ })}`;
3417
+ }
3418
+ function submitBody(ctx) {
3419
+ return {
3420
+ type_id: ctx.str("approvalTypeId"),
3421
+ resource_id: ctx.str("resourceId"),
3422
+ reason: ctx.str("reason"),
3423
+ payload: approvalPayload(ctx),
3424
+ client_request_id: ctx.str("clientRequestId")
3425
+ };
3426
+ }
3427
+ function cancelBody(ctx) {
3428
+ return {
3429
+ expected_version: ctx.num("expectedVersion"),
3430
+ ...optionalString(ctx, "reason") ? { reason: ctx.str("reason") } : {},
3431
+ client_request_id: ctx.str("clientRequestId")
3432
+ };
3433
+ }
3434
+ function approveBody(ctx) {
3435
+ return {
3436
+ expected_version: ctx.num("expectedVersion"),
3437
+ ...optionalString(ctx, "note") ? { note: ctx.str("note") } : {},
3438
+ client_request_id: ctx.str("clientRequestId")
3439
+ };
3440
+ }
3441
+ function rejectBody(ctx) {
3442
+ return {
3443
+ expected_version: ctx.num("expectedVersion"),
3444
+ reason: ctx.str("reason"),
3445
+ client_request_id: ctx.str("clientRequestId")
3446
+ };
3447
+ }
3448
+ function retryEffectBody(ctx) {
3449
+ return {
3450
+ expected_version: ctx.num("expectedVersion"),
3451
+ expected_attempt: ctx.num("expectedAttempt"),
3452
+ reason: ctx.str("reason"),
3453
+ confirm_risk: true,
3454
+ client_request_id: ctx.str("clientRequestId")
3455
+ };
3456
+ }
3457
+ var approvalTypeIdFlag = {
3458
+ name: "approval-type-id",
3459
+ type: "string",
3460
+ required: true,
3461
+ maxLength: MAX_ID_LENGTH,
3462
+ desc: "Versioned approval type ID, for example skill.publish@1"
3463
+ };
3464
+ var approvalRequestIdFlag = {
3465
+ name: "approval-request-id",
3466
+ type: "string",
3467
+ required: true,
3468
+ maxLength: MAX_ID_LENGTH,
3469
+ desc: "Approval request ID"
3470
+ };
3471
+ var taskIdFlag = {
3472
+ name: "task-id",
3473
+ type: "string",
3474
+ required: true,
3475
+ maxLength: MAX_ID_LENGTH,
3476
+ desc: "Approval task ID"
3477
+ };
3478
+ var effectIdFlag = {
3479
+ name: "effect-id",
3480
+ type: "string",
3481
+ required: true,
3482
+ maxLength: MAX_ID_LENGTH,
3483
+ desc: "Approval Effect ID"
3484
+ };
3485
+ var clientRequestIdFlag = {
3486
+ name: "client-request-id",
3487
+ type: "string",
3488
+ required: true,
3489
+ maxLength: MAX_ID_LENGTH,
3490
+ desc: "Caller-generated idempotency key"
3491
+ };
3492
+ var expectedVersionFlag = {
3493
+ name: "expected-version",
3494
+ type: "number",
3495
+ required: true,
3496
+ min: 0,
3497
+ max: MAX_VERSION,
3498
+ desc: "Expected optimistic version from the latest request, task, or Effect read"
3499
+ };
3500
+ var expectedAttemptFlag = {
3501
+ name: "expected-attempt",
3502
+ type: "number",
3503
+ required: true,
3504
+ min: 0,
3505
+ max: MAX_VERSION,
3506
+ desc: "Expected Effect attempt from the latest Effect read"
3507
+ };
3508
+ var pageFlags = [
3509
+ { name: "cursor", type: "string", required: false, maxLength: 1024, desc: "Opaque cursor from the previous page" },
3510
+ { name: "limit", type: "number", required: false, default: 20, min: 1, max: 100, desc: "Page size from 1 to 100" },
3511
+ { name: "created-after", type: "string", required: false, desc: "Include records created at or after this ISO datetime" },
3512
+ { name: "created-before", type: "string", required: false, desc: "Include records created before this ISO datetime" }
3513
+ ];
3514
+ var listApprovalTypes = {
3515
+ service: SERVICE,
3516
+ resource: "approval-type",
3517
+ command: "list",
3518
+ description: "List registered versioned approval types and their input contracts",
3519
+ flags: [],
3520
+ risk: "read",
3521
+ dryRun: (ctx) => ({ method: "GET", url: buildApprovalCliUrl(ctx, "types") }),
3522
+ execute: (ctx) => getApprovalCli(ctx, "types")
3523
+ };
3524
+ var getApprovalType = {
3525
+ service: SERVICE,
3526
+ resource: "approval-type",
3527
+ command: "get",
3528
+ description: "Get one versioned approval type and its input contract",
3529
+ flags: [approvalTypeIdFlag],
3530
+ risk: "read",
3531
+ validate: validateApprovalTypeId,
3532
+ dryRun: (ctx) => ({
3533
+ method: "GET",
3534
+ url: buildApprovalCliUrl(ctx, `types/${encodeURIComponent(ctx.str("approvalTypeId"))}`)
3535
+ }),
3536
+ execute: (ctx) => getApprovalCli(ctx, `types/${encodeURIComponent(ctx.str("approvalTypeId"))}`)
3537
+ };
3538
+ var listApprovalRequests = {
3539
+ service: SERVICE,
3540
+ resource: "approval-request",
3541
+ command: "list",
3542
+ description: "List approval requests visible to the current user",
3543
+ flags: [
3544
+ ...pageFlags,
3545
+ { name: "approval-type-id", type: "string", required: false, maxLength: MAX_ID_LENGTH, desc: "Filter by versioned approval type ID" },
3546
+ { name: "status", type: "string", required: false, desc: `Filter by decision status: ${DECISION_STATUSES.join(" | ")}` },
3547
+ { name: "requester-id", type: "string", required: false, maxLength: MAX_ID_LENGTH, desc: "Filter by requester user ID when authorized" }
3548
+ ],
3549
+ risk: "read",
3550
+ validate: (ctx) => {
3551
+ validateLimit(ctx);
3552
+ validateDateRange(ctx);
3553
+ assertAllowed(optionalString(ctx, "status"), "status", DECISION_STATUSES);
3554
+ if (optionalString(ctx, "approvalTypeId")) validateApprovalTypeId(ctx);
3555
+ if (optionalString(ctx, "requesterId")) validateStableId(ctx, "requesterId", "requester-id");
3556
+ },
3557
+ dryRun: (ctx) => ({ method: "GET", url: buildApprovalCliUrl(ctx, requestListPath(ctx)) }),
3558
+ execute: (ctx) => getApprovalCli(ctx, requestListPath(ctx))
3559
+ };
3560
+ var getApprovalRequest = {
3561
+ service: SERVICE,
3562
+ resource: "approval-request",
3563
+ command: "get",
3564
+ description: "Get one approval request by approval request ID",
3565
+ flags: [approvalRequestIdFlag],
3566
+ risk: "read",
3567
+ validate: (ctx) => validateStableId(ctx, "approvalRequestId", "approval-request-id"),
3568
+ dryRun: (ctx) => ({
3569
+ method: "GET",
3570
+ url: buildApprovalCliUrl(ctx, `requests/${encodeURIComponent(ctx.str("approvalRequestId"))}`)
3571
+ }),
3572
+ execute: (ctx) => getApprovalCli(ctx, `requests/${encodeURIComponent(ctx.str("approvalRequestId"))}`)
3573
+ };
3574
+ var submitApprovalRequest = {
3575
+ service: SERVICE,
3576
+ resource: "approval-request",
3577
+ command: "submit",
3578
+ description: "Submit a resource snapshot to a versioned approval type",
3579
+ helpText: LOCAL_DRY_RUN_HELP,
3580
+ flags: [
3581
+ approvalTypeIdFlag,
3582
+ { name: "resource-id", type: "string", required: true, maxLength: MAX_ID_LENGTH, desc: "Business resource ID resolved by the selected approval type" },
3583
+ { name: "reason", type: "string", required: true, maxLength: 2e3, desc: "Submission reason" },
3584
+ { name: "payload", type: "json", required: true, desc: "Type-specific snake_case JSON object from approval-type get" },
3585
+ clientRequestIdFlag
3586
+ ],
3587
+ risk: "write",
3588
+ validate: (ctx) => {
3589
+ validateApprovalTypeId(ctx);
3590
+ validateStableId(ctx, "resourceId", "resource-id");
3591
+ validateText(ctx, "reason", "reason", { required: true, maxLength: 2e3 });
3592
+ validateClientRequestId(ctx);
3593
+ approvalPayload(ctx);
3594
+ },
3595
+ dryRun: (ctx) => ({ method: "POST", url: buildApprovalCliUrl(ctx, "requests"), body: submitBody(ctx) }),
3596
+ execute: (ctx) => postApprovalCli(ctx, "requests", submitBody(ctx))
3597
+ };
3598
+ var cancelApprovalRequest = {
3599
+ service: SERVICE,
3600
+ resource: "approval-request",
3601
+ command: "cancel",
3602
+ description: "Cancel a pending approval request with optimistic concurrency control",
3603
+ helpText: LOCAL_DRY_RUN_HELP,
3604
+ flags: [
3605
+ approvalRequestIdFlag,
3606
+ expectedVersionFlag,
3607
+ { name: "reason", type: "string", required: false, maxLength: 2e3, desc: "Optional cancellation reason; required when cancelling another user request" },
3608
+ clientRequestIdFlag
3609
+ ],
3610
+ risk: "write",
3611
+ validate: (ctx) => {
3612
+ validateStableId(ctx, "approvalRequestId", "approval-request-id");
3613
+ validateExpectedVersion(ctx);
3614
+ validateText(ctx, "reason", "reason", { required: false, maxLength: 2e3 });
3615
+ validateClientRequestId(ctx);
3616
+ },
3617
+ dryRun: (ctx) => ({
3618
+ method: "POST",
3619
+ url: buildApprovalCliUrl(ctx, `requests/${encodeURIComponent(ctx.str("approvalRequestId"))}/cancel`),
3620
+ body: cancelBody(ctx)
3621
+ }),
3622
+ execute: (ctx) => postApprovalCli(
3623
+ ctx,
3624
+ `requests/${encodeURIComponent(ctx.str("approvalRequestId"))}/cancel`,
3625
+ cancelBody(ctx)
3626
+ )
3627
+ };
3628
+ var listApprovalTasks = {
3629
+ service: SERVICE,
3630
+ resource: "approval-task",
3631
+ command: "list",
3632
+ description: "List approval tasks currently visible to the current approver",
3633
+ flags: [
3634
+ ...pageFlags,
3635
+ { name: "status", type: "string", required: false, desc: `Filter by task status: ${TASK_STATUSES.join(" | ")}` },
3636
+ { name: "approval-request-id", type: "string", required: false, maxLength: MAX_ID_LENGTH, desc: "Filter by approval request ID" }
3637
+ ],
3638
+ risk: "read",
3639
+ validate: (ctx) => {
3640
+ validateLimit(ctx);
3641
+ validateDateRange(ctx);
3642
+ assertAllowed(optionalString(ctx, "status"), "status", TASK_STATUSES);
3643
+ if (optionalString(ctx, "approvalRequestId")) {
3644
+ validateStableId(ctx, "approvalRequestId", "approval-request-id");
3645
+ }
3646
+ },
3647
+ dryRun: (ctx) => ({ method: "GET", url: buildApprovalCliUrl(ctx, taskListPath(ctx)) }),
3648
+ execute: (ctx) => getApprovalCli(ctx, taskListPath(ctx))
3649
+ };
3650
+ var getApprovalTask = {
3651
+ service: SERVICE,
3652
+ resource: "approval-task",
3653
+ command: "get",
3654
+ description: "Get one approval task by task ID",
3655
+ flags: [taskIdFlag],
3656
+ risk: "read",
3657
+ validate: (ctx) => validateStableId(ctx, "taskId", "task-id"),
3658
+ dryRun: (ctx) => ({
3659
+ method: "GET",
3660
+ url: buildApprovalCliUrl(ctx, `tasks/${encodeURIComponent(ctx.str("taskId"))}`)
3661
+ }),
3662
+ execute: (ctx) => getApprovalCli(ctx, `tasks/${encodeURIComponent(ctx.str("taskId"))}`)
3663
+ };
3664
+ var approveApprovalTask = {
3665
+ service: SERVICE,
3666
+ resource: "approval-task",
3667
+ command: "approve",
3668
+ description: "Approve a pending approval task with optimistic concurrency control",
3669
+ helpText: LOCAL_DRY_RUN_HELP,
3670
+ flags: [
3671
+ taskIdFlag,
3672
+ expectedVersionFlag,
3673
+ { name: "note", type: "string", required: false, maxLength: 2e3, desc: "Optional approval note" },
3674
+ clientRequestIdFlag
3675
+ ],
3676
+ risk: "write",
3677
+ validate: (ctx) => {
3678
+ validateStableId(ctx, "taskId", "task-id");
3679
+ validateExpectedVersion(ctx);
3680
+ validateText(ctx, "note", "note", { required: false, maxLength: 2e3 });
3681
+ validateClientRequestId(ctx);
3682
+ },
3683
+ dryRun: (ctx) => ({
3684
+ method: "POST",
3685
+ url: buildApprovalCliUrl(ctx, `tasks/${encodeURIComponent(ctx.str("taskId"))}/approve`),
3686
+ body: approveBody(ctx)
3687
+ }),
3688
+ execute: (ctx) => postApprovalCli(
3689
+ ctx,
3690
+ `tasks/${encodeURIComponent(ctx.str("taskId"))}/approve`,
3691
+ approveBody(ctx)
3692
+ )
3693
+ };
3694
+ var rejectApprovalTask = {
3695
+ service: SERVICE,
3696
+ resource: "approval-task",
3697
+ command: "reject",
3698
+ description: "Reject a pending approval task with a required reason",
3699
+ helpText: LOCAL_DRY_RUN_HELP,
3700
+ flags: [
3701
+ taskIdFlag,
3702
+ expectedVersionFlag,
3703
+ { name: "reason", type: "string", required: true, maxLength: 2e3, desc: "Rejection reason" },
3704
+ clientRequestIdFlag
3705
+ ],
3706
+ risk: "write",
3707
+ validate: (ctx) => {
3708
+ validateStableId(ctx, "taskId", "task-id");
3709
+ validateExpectedVersion(ctx);
3710
+ validateText(ctx, "reason", "reason", { required: true, maxLength: 2e3 });
3711
+ validateClientRequestId(ctx);
3712
+ },
3713
+ dryRun: (ctx) => ({
3714
+ method: "POST",
3715
+ url: buildApprovalCliUrl(ctx, `tasks/${encodeURIComponent(ctx.str("taskId"))}/reject`),
3716
+ body: rejectBody(ctx)
3717
+ }),
3718
+ execute: (ctx) => postApprovalCli(
3719
+ ctx,
3720
+ `tasks/${encodeURIComponent(ctx.str("taskId"))}/reject`,
3721
+ rejectBody(ctx)
3722
+ )
3723
+ };
3724
+ var listApprovalEffects = {
3725
+ service: SERVICE,
3726
+ resource: "approval-effect",
3727
+ command: "list",
3728
+ description: "List approval Effects visible to the current company administrator",
3729
+ flags: [
3730
+ ...pageFlags,
3731
+ { name: "status", type: "string", required: false, desc: `Filter by Effect status: ${EFFECT_STATUSES.join(" | ")}` },
3732
+ { name: "approval-request-id", type: "string", required: false, maxLength: MAX_ID_LENGTH, desc: "Filter by approval request ID" }
3733
+ ],
3734
+ risk: "read",
3735
+ validate: (ctx) => {
3736
+ validateLimit(ctx);
3737
+ validateDateRange(ctx);
3738
+ assertAllowed(optionalString(ctx, "status"), "status", EFFECT_STATUSES);
3739
+ if (optionalString(ctx, "approvalRequestId")) {
3740
+ validateStableId(ctx, "approvalRequestId", "approval-request-id");
3741
+ }
3742
+ },
3743
+ dryRun: (ctx) => ({ method: "GET", url: buildApprovalCliUrl(ctx, effectListPath(ctx)) }),
3744
+ execute: (ctx) => getApprovalCli(ctx, effectListPath(ctx))
3745
+ };
3746
+ var getApprovalEffect = {
3747
+ service: SERVICE,
3748
+ resource: "approval-effect",
3749
+ command: "get",
3750
+ description: "Get one approval Effect by Effect ID",
3751
+ flags: [effectIdFlag],
3752
+ risk: "read",
3753
+ validate: (ctx) => validateStableId(ctx, "effectId", "effect-id"),
3754
+ dryRun: (ctx) => ({
3755
+ method: "GET",
3756
+ url: buildApprovalCliUrl(ctx, `effects/${encodeURIComponent(ctx.str("effectId"))}`)
3757
+ }),
3758
+ execute: (ctx) => getApprovalCli(ctx, `effects/${encodeURIComponent(ctx.str("effectId"))}`)
3759
+ };
3760
+ var retryApprovalEffect = {
3761
+ service: SERVICE,
3762
+ resource: "approval-effect",
3763
+ command: "retry",
3764
+ description: "Manually retry a failed or manual-required approval Effect",
3765
+ helpText: `${LOCAL_DRY_RUN_HELP} Actual execution requires confirmation; pass global --yes only after explicit user authorization.`,
3766
+ flags: [
3767
+ effectIdFlag,
3768
+ expectedVersionFlag,
3769
+ expectedAttemptFlag,
3770
+ { name: "reason", type: "string", required: true, maxLength: 2e3, desc: "Auditable manual retry reason" },
3771
+ clientRequestIdFlag
3772
+ ],
3773
+ risk: "high-risk-write",
3774
+ validate: (ctx) => {
3775
+ validateStableId(ctx, "effectId", "effect-id");
3776
+ validateExpectedVersion(ctx);
3777
+ validateExpectedAttempt(ctx);
3778
+ validateText(ctx, "reason", "reason", { required: true, maxLength: 2e3 });
3779
+ validateClientRequestId(ctx);
3780
+ },
3781
+ dryRun: (ctx) => ({
3782
+ method: "POST",
3783
+ url: buildApprovalCliUrl(ctx, `effects/${encodeURIComponent(ctx.str("effectId"))}/retry`),
3784
+ body: retryEffectBody(ctx)
3785
+ }),
3786
+ execute: (ctx) => postApprovalCli(
3787
+ ctx,
3788
+ `effects/${encodeURIComponent(ctx.str("effectId"))}/retry`,
3789
+ retryEffectBody(ctx)
3790
+ )
3791
+ };
3792
+
3192
3793
  // src/commands/te-agent/index.ts
3193
3794
  var commands = [
3194
3795
  // Agent CRUD
@@ -3252,6 +3853,20 @@ var commands = [
3252
3853
  cancelSkillSubmission,
3253
3854
  approveSkill,
3254
3855
  rejectSkill,
3856
+ // Generic versioned approval workflow
3857
+ listApprovalTypes,
3858
+ getApprovalType,
3859
+ listApprovalRequests,
3860
+ getApprovalRequest,
3861
+ submitApprovalRequest,
3862
+ cancelApprovalRequest,
3863
+ listApprovalTasks,
3864
+ getApprovalTask,
3865
+ approveApprovalTask,
3866
+ rejectApprovalTask,
3867
+ listApprovalEffects,
3868
+ getApprovalEffect,
3869
+ retryApprovalEffect,
3255
3870
  // Skill share (peer-to-peer)
3256
3871
  shareSkill,
3257
3872
  listSkillShares,