nolo-cli 0.32.0 → 0.33.0-alpha.3

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 (170) hide show
  1. package/README.md +6 -12
  2. package/{_executeModel-LTMSIBS4.js → _executeModel-RWPVI3YV.js} +76 -67
  3. package/{action-HI3VRQLP.js → action-SMLG6OTB.js} +17 -15
  4. package/{addContentAction-NCURJ6PK.js → addContentAction-SFO244QN.js} +14 -13
  5. package/{addDialogAgentAction-RCY4ECF4.js → addDialogAgentAction-W44ZCEHB.js} +14 -13
  6. package/{agentDeleteCommand-D3MYZK6E.js → agentDeleteCommand-KU2RXQPP.js} +42 -59
  7. package/{agentEmailCommands-6BXS574I.js → agentEmailCommands-MPCMDENS.js} +89 -80
  8. package/{agentGrantCommands-E7ZZFRHK.js → agentGrantCommands-2LEZDADN.js} +2 -2
  9. package/{agentListCommands-SF3HEUTT.js → agentListCommands-EPD4N6FX.js} +73 -78
  10. package/{agentMachineCommands-YARVXRR6.js → agentMachineCommands-AF7C3YRT.js} +40 -57
  11. package/{agentPullCommand-ARSIDNVC.js → agentPullCommand-YH5GEBK4.js} +5 -5
  12. package/agentRecordCommands-EYE6MZZG.js +112 -0
  13. package/agentRunCommand-LL22SGTN.js +130 -0
  14. package/{agentRuntimeLocal-ATGJY6WC.js → agentRuntimeLocal-JX34G47Z.js} +35 -50
  15. package/{agentSlice-4XWW344Y.js → agentSlice-TNMFQQOV.js} +15 -13
  16. package/{appDeleteCommands-63JO7RXS.js → appDeleteCommands-43K5VXQB.js} +38 -55
  17. package/{appDeployCommands-Y7EWYUGM.js → appDeployCommands-FEEJSVDZ.js} +38 -55
  18. package/{appDeployStatusCommands-ZBEY3DWB.js → appDeployStatusCommands-H76CG45R.js} +38 -55
  19. package/{appGetCommands-QSSOSEYL.js → appGetCommands-MDZYFTYZ.js} +38 -55
  20. package/{appListCommands-PH3XWNDX.js → appListCommands-TUJJXPWG.js} +38 -55
  21. package/{authCommand-BBDHMSO6.js → authCommand-T7UK4CWS.js} +18 -18
  22. package/{authCommands-4UDEKRE6.js → authCommands-EAPFGNHN.js} +8 -8
  23. package/chatQueueReduxAdapter-LVQXC4ZY.js +180 -0
  24. package/chunk-2H3XIBY4.js +239 -0
  25. package/{chunk-TEYN42N3.js → chunk-2IVEXF7P.js} +11 -4
  26. package/{chunk-WTGCTVJG.js → chunk-2QTEYCR7.js} +3 -6
  27. package/{chunk-DOISARTV.js → chunk-2UECQ7RE.js} +1 -1
  28. package/{chunk-SWYMCHM7.js → chunk-37V5LNEQ.js} +69 -1
  29. package/{chunk-E3APEOIM.js → chunk-3GZXL6FM.js} +4 -19
  30. package/{chunk-O3JR45Q2.js → chunk-3VAQHAXT.js} +44 -44
  31. package/{chunk-O5OMJPPF.js → chunk-3WXRAHCG.js} +6 -5
  32. package/{chunk-LAXMH7JY.js → chunk-57QJXIB6.js} +18 -15
  33. package/chunk-5CS33IBL.js +301 -0
  34. package/{chunk-3UGKATZQ.js → chunk-5SBK2MTI.js} +8 -369
  35. package/chunk-6PO2SYCS.js +1800 -0
  36. package/{chunk-TA6EA2A3.js → chunk-6SXC35F4.js} +182 -20
  37. package/{chunk-MXFQHRSS.js → chunk-6XIE5ZGI.js} +1 -1
  38. package/{chunk-3GZT3L6F.js → chunk-73GINUCW.js} +326 -481
  39. package/{chunk-VMWR7VNI.js → chunk-7E72JMBB.js} +7 -7
  40. package/{chunk-4PNU7W7K.js → chunk-AAGCMVFT.js} +106 -124
  41. package/chunk-ADLYMQB6.js +642 -0
  42. package/{chunk-ZWJOGMKH.js → chunk-AETZ7AD6.js} +1 -1
  43. package/{chunk-UDA3ZYLW.js → chunk-AFV4FOT2.js} +70 -24
  44. package/{chunk-BGTUGS3T.js → chunk-AOXVOC6D.js} +4 -30
  45. package/{chunk-2ZRP5RUG.js → chunk-B2BSG6QQ.js} +12 -11
  46. package/{chunk-44HACRCK.js → chunk-BANYWEYY.js} +4 -4
  47. package/{chunk-TOW4E763.js → chunk-BJIRLHJR.js} +2 -0
  48. package/{chunk-ZJ2WITOO.js → chunk-BQXOGBFN.js} +2 -2
  49. package/{chunk-G5GVZAXF.js → chunk-CLP2K7U4.js} +15 -19
  50. package/{chunk-2K4NDPT5.js → chunk-DFUPZE6V.js} +20 -12
  51. package/{chunk-YHGHADBQ.js → chunk-DPMBNHOJ.js} +4 -4
  52. package/chunk-EGRJC4ZN.js +91 -0
  53. package/{chunk-K6QEHQZ3.js → chunk-EKLRRZIN.js} +1 -1
  54. package/{chunk-XFG3BAKN.js → chunk-FMEVI5TG.js} +65 -0
  55. package/{chunk-RH53LMEJ.js → chunk-FSSX3XRY.js} +2 -4
  56. package/{chunk-VP4WJWKW.js → chunk-GM6PU7B6.js} +431 -345
  57. package/{chunk-EEF23OOK.js → chunk-GMXWYXAF.js} +7 -7
  58. package/{chunk-SFWZUTCI.js → chunk-GTYM4HKV.js} +1 -1
  59. package/{chunk-MITD7CON.js → chunk-HDKRSRYU.js} +1461 -301
  60. package/chunk-HS7MLR74.js +38 -0
  61. package/{chunk-3AUWC6EM.js → chunk-HUCT7HID.js} +5 -84
  62. package/{chunk-PTHDLIRB.js → chunk-I6N2UVVY.js} +1 -1
  63. package/chunk-IDAU4UFS.js +437 -0
  64. package/{chunk-Q76I4SXI.js → chunk-IHEC7VBF.js} +1 -1
  65. package/{chunk-OWHNFZNW.js → chunk-IL545V3E.js} +4 -4
  66. package/{chunk-3LY4F7SV.js → chunk-INZZJSQF.js} +348 -331
  67. package/{chunk-CF2WZF4N.js → chunk-J6WH4PYZ.js} +0 -8
  68. package/{chunk-2HXKAPH7.js → chunk-JMPYDFHY.js} +6 -6
  69. package/{chunk-V54H24CQ.js → chunk-JTSGWTYZ.js} +3 -3
  70. package/{chunk-ATK5WJOA.js → chunk-JZ5AMMXU.js} +4 -4
  71. package/chunk-KHCLMKZZ.js +3062 -0
  72. package/{chunk-WHLVPK32.js → chunk-KMSZPTM6.js} +27 -3
  73. package/{chunk-L3GCUVOH.js → chunk-KSRFVP36.js} +1 -1
  74. package/{chunk-DLWCWUNW.js → chunk-LOD75GOS.js} +336 -32
  75. package/{chunk-UOJRKY5J.js → chunk-M2YMQOLC.js} +44 -53
  76. package/chunk-M3JEW6N6.js +193 -0
  77. package/{chunk-XDHHF73Q.js → chunk-M4NC7NF6.js} +95 -95
  78. package/{chunk-3FCNXC2J.js → chunk-MPZJVZDC.js} +3735 -1394
  79. package/{chunk-IXZX5CJK.js → chunk-MQRZ5QUH.js} +1 -1
  80. package/{chunk-3ASDTTEI.js → chunk-MRWGHF56.js} +2 -0
  81. package/{chunk-D34RI6NI.js → chunk-NNWHHCVP.js} +75 -1
  82. package/{chunk-6YABCOFU.js → chunk-NUO3QFWD.js} +1 -1
  83. package/{chunk-GAF5X6B7.js → chunk-O6GEBMIY.js} +269 -309
  84. package/{chunk-CAENRKNJ.js → chunk-OR2HNLVO.js} +126 -88
  85. package/chunk-OW765XBU.js +10 -0
  86. package/chunk-PREQU5QV.js +231 -0
  87. package/{chunk-Q3CSL43H.js → chunk-Q5ITEGIN.js} +1 -1
  88. package/{chunk-7S54ZGF6.js → chunk-RAZOLMJR.js} +256 -12
  89. package/chunk-RCFIB45Q.js +28 -0
  90. package/chunk-RY57GLGW.js +188 -0
  91. package/{chunk-KGEVMUMI.js → chunk-TFPUAELY.js} +11 -11
  92. package/{chunk-ZJH3LKEW.js → chunk-UK5JGQVU.js} +94 -15
  93. package/chunk-URMS4XY2.js +10 -0
  94. package/{chunk-RXVX5LFR.js → chunk-VH2F7ZB6.js} +1 -1
  95. package/chunk-VIDPVFP3.js +20 -0
  96. package/{chunk-W367V5CH.js → chunk-WHD6BG7M.js} +400 -115
  97. package/{chunk-5RDLGLAP.js → chunk-WJSW43QZ.js} +4 -7
  98. package/{chunk-CF7S2RYZ.js → chunk-WLH5BAKX.js} +6 -6
  99. package/{chunk-VVEH6XUE.js → chunk-X2DAEZ3X.js} +1 -1
  100. package/{chunk-2IJAKBK2.js → chunk-X664KVEV.js} +426 -246
  101. package/{chunk-43EPBPZ2.js → chunk-XCCGU6QB.js} +2 -2
  102. package/chunk-Y5GCAMGP.js +9 -0
  103. package/{chunk-V42OE5HT.js → chunk-YDTYDA5W.js} +3 -3
  104. package/chunk-YYLHWIW6.js +48 -0
  105. package/{chunk-AOS5IN2I.js → chunk-ZHYK3N56.js} +1 -1
  106. package/{chunk-ODS2MVMU.js → chunk-ZJMME4DS.js} +19 -303
  107. package/{chunk-PJ2DDQQM.js → chunk-ZURFOV5J.js} +2 -2
  108. package/chunk-ZZ2MH7LE.js +84 -0
  109. package/{cliExecutor-BBUVQU4L.js → cliExecutor-DW3PHGEL.js} +2 -2
  110. package/{clipboardy-BVE3LVEH.js → clipboardy-MMBYVRLF.js} +166 -372
  111. package/{codingSkills-V35TRR4Y.js → codingSkills-DY5MINPG.js} +5 -4
  112. package/{createAgentAutomationAction-WLRNE7C4.js → createAgentAutomationAction-INQT23LX.js} +40 -31
  113. package/createDialogAction-LDCPDI73.js +60 -0
  114. package/{createPageAction-7YROVZ3W.js → createPageAction-5YXOG2M4.js} +56 -47
  115. package/{db-6DPSJ6WT.js → db-3H3JECGY.js} +45 -5
  116. package/{dbSlice-BBL3PEVW.js → dbSlice-3SD5L5H2.js} +13 -12
  117. package/{deleteFile-RJTEPOT4.js → deleteFile-XQXPBFFB.js} +7 -6
  118. package/dialogCommands-CHJO47AX.js +81 -0
  119. package/{dialogSlice-N4HPG6HM.js → dialogSlice-DOWKOILN.js} +36 -29
  120. package/{docCreateCommands-GRA5BHSA.js → docCreateCommands-OVZARUFX.js} +40 -55
  121. package/{docDeleteCommands-ONIJM5MD.js → docDeleteCommands-E2XJ62LD.js} +42 -57
  122. package/{docReadCommands-H55VQ2US.js → docReadCommands-I7OSREPJ.js} +40 -55
  123. package/{docStore-B5AHDNW5.js → docStore-UAWSKZ2Y.js} +39 -30
  124. package/{docUpdateCommands-ZQIQVGC2.js → docUpdateCommands-X4Z26VJM.js} +43 -58
  125. package/{fetchMessages-VPPQDDZ4.js → fetchMessages-7QRCCRYK.js} +3 -3
  126. package/{getPricing-QO5TYNCK.js → getPricing-L2ENXWHV.js} +7 -6
  127. package/{handleSendMessageAction-IN5XX5U7.js → handleSendMessageAction-C3TSDWKH.js} +38 -31
  128. package/index.js +67 -67
  129. package/{lib-FYYBQIXS.js → lib-2ZTNRXR4.js} +432 -183
  130. package/{localDialogRead-3DBXVYXS.js → localDialogRead-SLMPV5SK.js} +2 -2
  131. package/{localRuntimeAuthority-NDUA2D7Y.js → localRuntimeAuthority-E3R24J4T.js} +4 -2
  132. package/{localRuntimeDb-GKYRBWLQ.js → localRuntimeDb-DDZCJFQZ.js} +1 -1
  133. package/{machineCommands-H3UMKE76.js → machineCommands-BUOIYJAD.js} +93 -84
  134. package/{machineWsRunDispatch-HONRUK3R.js → machineWsRunDispatch-7CRWAA6O.js} +83 -74
  135. package/{models-WDUTTYFS.js → models-OX2S5C6Q.js} +2 -2
  136. package/{offlineMarxistsAgentCommand-E6LUG63A.js → offlineMarxistsAgentCommand-GEH6SNNA.js} +1 -1
  137. package/package.json +1 -4
  138. package/{read-64OQDO3I.js → read-6G73BMEY.js} +8 -7
  139. package/{readDocTool-MXM3T6PE.js → readDocTool-DK4EI2GA.js} +1 -2
  140. package/{readlineWorkspace-XVJZDCSC.js → readlineWorkspace-ZDWEASJV.js} +265 -428
  141. package/{removeDialogAgentAction-NEKVAMSH.js → removeDialogAgentAction-E7H557UO.js} +19 -17
  142. package/{runAgentClientLoop-H7U53QB6.js → runAgentClientLoop-U7HYA3O5.js} +72 -64
  143. package/{runtimeDoctorCommands-WI2YZUSJ.js → runtimeDoctorCommands-KIKM6BIO.js} +5 -5
  144. package/{setDialogExtraReferencesAction-WTOHQDIV.js → setDialogExtraReferencesAction-RMMGBR5F.js} +15 -14
  145. package/{setPrimaryDialogAgentAction-LDJOYC4F.js → setPrimaryDialogAgentAction-FWBKKLVA.js} +19 -17
  146. package/{settingSlice-4M37TN7V.js → settingSlice-73PV4KG4.js} +16 -14
  147. package/{skillDiscovery-5U6RYAHN.js → skillDiscovery-KLLKXPUO.js} +4 -4
  148. package/{slateUtils-2M7MUTWX.js → slateUtils-VO2FU36K.js} +1 -1
  149. package/{spaceCommands-7VVKJBDV.js → spaceCommands-GEWZXGHM.js} +43 -240
  150. package/{spaceSlice-T6YK6D34.js → spaceSlice-B6MOVY4N.js} +38 -61
  151. package/{streamAgentChatTurn-RQ63QFQ7.js → streamAgentChatTurn-T527EQTT.js} +1261 -150
  152. package/{switchDialogAgentAction-XVWGKR2Z.js → switchDialogAgentAction-US6QNL3N.js} +14 -13
  153. package/syncMapping-RK2MANUX.js +43 -0
  154. package/{tableCommands-RJZ3V4TF.js → tableCommands-QE47K72R.js} +8 -7
  155. package/{toolApiClient-ARGFDJAG.js → toolApiClient-B2MFXMEG.js} +3 -3
  156. package/tools-XMWCVMPM.js +98 -0
  157. package/{tuiSummaryLlmCaller-SRZ4QQUP.js → tuiSummaryLlmCaller-NCAJSVSD.js} +24 -21
  158. package/{updateDialogTitleAction-BBDSWHNG.js → updateDialogTitleAction-XPJZRJEL.js} +48 -38
  159. package/agentRecordCommands-JFZRQJQ4.js +0 -103
  160. package/agentRunCommand-NOX5FLKO.js +0 -121
  161. package/chunk-AYMOSAHE.js +0 -3158
  162. package/chunk-D2BPX6DQ.js +0 -1707
  163. package/chunk-DCDL3GC4.js +0 -171
  164. package/chunk-F3MP7CP6.js +0 -73
  165. package/chunk-WZSRQNQG.js +0 -2587
  166. package/createDialogAction-Y6YV64QB.js +0 -52
  167. package/dialogCommands-XLO5CAHZ.js +0 -95
  168. package/tools-KYZX3BGO.js +0 -90
  169. package/{chunk-Z5MXSEOJ.js → chunk-RQSOAMPJ.js} +2 -2
  170. package/{chunk-JDSUTNYY.js → chunk-SAQQLJZ5.js} +3 -3
@@ -1,13 +1,19 @@
1
+ import {
2
+ DataType,
3
+ fileKey,
4
+ getFileIdFromKey,
5
+ ulid
6
+ } from "./chunk-KMSZPTM6.js";
1
7
  import {
2
8
  loadFileFromIndexedDb,
3
9
  removeAction,
4
10
  saveFileToIndexedDb
5
- } from "./chunk-ZJ2WITOO.js";
11
+ } from "./chunk-BQXOGBFN.js";
6
12
  import {
7
13
  readAction,
8
14
  readRequestManager,
9
15
  resolveAgentReadServers
10
- } from "./chunk-ZJH3LKEW.js";
16
+ } from "./chunk-UK5JGQVU.js";
11
17
  import {
12
18
  asyncThunkCreator,
13
19
  buildCreateSlice,
@@ -27,27 +33,22 @@ import {
27
33
  shouldReplaceLocalWithRemoteRecord,
28
34
  shouldReplicateLocalRecord,
29
35
  uploadToCurrentServer
30
- } from "./chunk-2IJAKBK2.js";
36
+ } from "./chunk-X664KVEV.js";
31
37
  import {
32
38
  fetchFromClientDb,
33
39
  fetchFromServer,
34
40
  logger,
35
41
  normalizeTimeFields
36
- } from "./chunk-5RDLGLAP.js";
37
- import {
38
- API_ENDPOINTS
39
- } from "./chunk-LCBAMY2M.js";
40
- import {
41
- fileKey,
42
- getFileIdFromKey,
43
- ulid
44
- } from "./chunk-WHLVPK32.js";
42
+ } from "./chunk-WJSW43QZ.js";
45
43
  import {
46
44
  isTombstoneRecord
47
45
  } from "./chunk-GBRG75BQ.js";
48
46
  import {
49
47
  isRecord
50
48
  } from "./chunk-KUG52IAP.js";
49
+ import {
50
+ API_ENDPOINTS
51
+ } from "./chunk-LCBAMY2M.js";
51
52
 
52
53
  // packages/database/actions/readAndWait.ts
53
54
  var hashTokenScope = (currentToken) => {
@@ -251,7 +252,9 @@ var writeAction = async (writeConfig, thunkApi) => {
251
252
  "setting" /* SETTING */,
252
253
  "table" /* TABLE */,
253
254
  "table_row" /* TABLE_ROW */,
254
- "email" /* EMAIL */
255
+ "email" /* EMAIL */,
256
+ "agent" /* AGENT */,
257
+ DataType.AUTOMATION
255
258
  ];
256
259
  if (!data.type || !VALID_TYPES.includes(data.type)) {
257
260
  logger.warn(
@@ -704,7 +707,7 @@ var dbSlice = createSliceWithThunks({
704
707
  // 动态 import 在调用期解析,避开 TDZ/求值顺序问题(同下方 share)。
705
708
  read: create.asyncThunk(
706
709
  async (payload, thunkApi) => {
707
- const { readAction: readAction2 } = await import("./read-64OQDO3I.js");
710
+ const { readAction: readAction2 } = await import("./read-6G73BMEY.js");
708
711
  return readAction2(payload, thunkApi);
709
712
  },
710
713
  {
@@ -778,7 +781,7 @@ var dbSlice = createSliceWithThunks({
778
781
  // 这里改成动态 import,运行期才解析,彻底断开这条边。
779
782
  share: create.asyncThunk(
780
783
  async (config, thunkApi) => {
781
- const { shareResourceAction } = await import("./action-HI3VRQLP.js");
784
+ const { shareResourceAction } = await import("./action-SMLG6OTB.js");
782
785
  return shareResourceAction(config, thunkApi);
783
786
  }
784
787
  ),
@@ -0,0 +1,301 @@
1
+ import {
2
+ getCredentialsDir
3
+ } from "./chunk-JZPBVBIY.js";
4
+ import {
5
+ asNonEmptyStringArray
6
+ } from "./chunk-I42VC5KR.js";
7
+ import {
8
+ asTrimmedString
9
+ } from "./chunk-3EUW3WEO.js";
10
+ import {
11
+ asOptionalPositiveFiniteNumber
12
+ } from "./chunk-U6VC4MU4.js";
13
+ import {
14
+ isRecord
15
+ } from "./chunk-KUG52IAP.js";
16
+
17
+ // packages/agent-runtime/fileCredentialBroker.ts
18
+ import {
19
+ chmodSync,
20
+ existsSync,
21
+ mkdirSync,
22
+ readFileSync,
23
+ unlinkSync,
24
+ writeFileSync
25
+ } from "node:fs";
26
+ import { homedir } from "node:os";
27
+ import { join } from "node:path";
28
+
29
+ // packages/agent-runtime/credentialBroker.ts
30
+ function assertCredentialRef(ref) {
31
+ const trimmed = asTrimmedString(ref);
32
+ if (!trimmed) {
33
+ throw new Error("invalid_ref");
34
+ }
35
+ if (trimmed.includes("..") || trimmed.includes("/") || trimmed.includes("\\")) {
36
+ throw new Error("invalid_ref");
37
+ }
38
+ return trimmed;
39
+ }
40
+
41
+ // packages/agent-runtime/fileCredentialBroker.ts
42
+ function getApiKeyCredentialsDir(homeDir = homedir()) {
43
+ return join(getCredentialsDir(homeDir), "keys");
44
+ }
45
+ function credentialRefToFileName(ref) {
46
+ const safe = assertCredentialRef(ref).replace(/[^a-zA-Z0-9._-]+/g, "_");
47
+ if (!safe || safe === "." || safe === "..") {
48
+ throw new Error(`Credential ref is not filesystem-safe: ${ref}`);
49
+ }
50
+ return `${safe}.json`;
51
+ }
52
+ function getApiKeyCredentialPath(ref, homeDir = homedir()) {
53
+ return join(getApiKeyCredentialsDir(homeDir), credentialRefToFileName(ref));
54
+ }
55
+ function ensurePrivateDir(dir) {
56
+ mkdirSync(dir, { recursive: true, mode: 448 });
57
+ try {
58
+ chmodSync(dir, 448);
59
+ } catch {
60
+ }
61
+ }
62
+ function writePrivateFile(path, body) {
63
+ writeFileSync(path, body, { encoding: "utf8", mode: 384 });
64
+ try {
65
+ chmodSync(path, 384);
66
+ } catch {
67
+ }
68
+ }
69
+ function readApiKeyCredential(ref, homeDir = homedir()) {
70
+ const path = getApiKeyCredentialPath(ref, homeDir);
71
+ if (!existsSync(path)) return null;
72
+ try {
73
+ const raw = readFileSync(path, "utf8");
74
+ const parsed = JSON.parse(raw);
75
+ if (typeof parsed?.secret !== "string" || !parsed.secret) return null;
76
+ return parsed.secret;
77
+ } catch {
78
+ return null;
79
+ }
80
+ }
81
+ function writeApiKeyCredential(ref, secret, homeDir = homedir(), now = Date.now()) {
82
+ const trimmedSecret = secret.trim();
83
+ if (!trimmedSecret) {
84
+ throw new Error("Cannot store an empty credential secret.");
85
+ }
86
+ assertCredentialRef(ref);
87
+ const dir = getApiKeyCredentialsDir(homeDir);
88
+ ensurePrivateDir(dir);
89
+ const path = getApiKeyCredentialPath(ref, homeDir);
90
+ const payload = {
91
+ secret: trimmedSecret,
92
+ updatedAt: now
93
+ };
94
+ writePrivateFile(path, `${JSON.stringify(payload, null, 2)}
95
+ `);
96
+ }
97
+ function removeApiKeyCredential(ref, homeDir = homedir()) {
98
+ assertCredentialRef(ref);
99
+ const path = getApiKeyCredentialPath(ref, homeDir);
100
+ if (!existsSync(path)) return;
101
+ unlinkSync(path);
102
+ }
103
+ function hasApiKeyCredential(ref, homeDir = homedir()) {
104
+ return readApiKeyCredential(ref, homeDir) !== null;
105
+ }
106
+ function createFileCredentialBroker(options = {}) {
107
+ const homeDir = options.homeDir ?? homedir();
108
+ const now = options.now ?? Date.now;
109
+ return {
110
+ get(ref) {
111
+ return readApiKeyCredential(ref, homeDir);
112
+ },
113
+ put(ref, secret) {
114
+ writeApiKeyCredential(ref, secret, homeDir, now());
115
+ },
116
+ delete(ref) {
117
+ removeApiKeyCredential(ref, homeDir);
118
+ },
119
+ has(ref) {
120
+ return hasApiKeyCredential(ref, homeDir);
121
+ }
122
+ };
123
+ }
124
+
125
+ // packages/agent-runtime/migrateAgentSecrets.ts
126
+ function buildAgentApiKeyCredentialRef(agentKey) {
127
+ const key = asTrimmedString(agentKey);
128
+ if (!key) throw new Error("agentKey is required to build a credential ref.");
129
+ return `api-key:${key}`;
130
+ }
131
+ function readRawApiKey(agent) {
132
+ return asTrimmedString(agent.apiKey);
133
+ }
134
+ function resolveTargetRef(agent) {
135
+ const fromCredential = asTrimmedString(agent.credentialRef);
136
+ if (fromCredential) return fromCredential;
137
+ const fromApiKeyRef = asTrimmedString(agent.apiKeyRef);
138
+ if (fromApiKeyRef.startsWith("api-key:")) return fromApiKeyRef;
139
+ return buildAgentApiKeyCredentialRef(agent.key);
140
+ }
141
+ async function brokerHas(broker, ref) {
142
+ return Boolean(await broker.has(ref));
143
+ }
144
+ async function brokerPut(broker, ref, secret) {
145
+ await broker.put(ref, secret);
146
+ }
147
+ async function migrateAgentSecrets(args) {
148
+ const { agent, broker } = args;
149
+ const raw = readRawApiKey(agent);
150
+ const migration = asTrimmedString(agent.credentialMigration);
151
+ if (migration === "done" && !raw) {
152
+ const ref = typeof agent.credentialRef === "string" && agent.credentialRef.trim() || (typeof agent.apiKeyRef === "string" && agent.apiKeyRef.startsWith("api-key:") ? agent.apiKeyRef.trim() : "") || void 0;
153
+ return {
154
+ updates: {},
155
+ status: "already-done",
156
+ ...ref ? { credentialRef: ref } : {},
157
+ phase: "complete"
158
+ };
159
+ }
160
+ if (!raw && migration !== "pending") {
161
+ return { updates: {}, status: "noop", phase: "none" };
162
+ }
163
+ const targetRef = resolveTargetRef(agent);
164
+ if (raw) {
165
+ await brokerPut(broker, targetRef, raw);
166
+ const stored2 = await brokerHas(broker, targetRef);
167
+ if (!stored2) {
168
+ return {
169
+ updates: {
170
+ credentialRef: targetRef,
171
+ credentialMigration: "pending"
172
+ },
173
+ status: "resumed-pending",
174
+ credentialRef: targetRef,
175
+ phase: "put"
176
+ };
177
+ }
178
+ return {
179
+ updates: {
180
+ apiKey: null,
181
+ credentialRef: targetRef,
182
+ // Keep apiKeyRef for resolution if not already an OAuth provider name.
183
+ // Prefer explicit credentialRef; set apiKeyRef only when empty so OAuth agents stay intact.
184
+ ...!(typeof agent.apiKeyRef === "string" && agent.apiKeyRef.trim()) ? { apiKeyRef: targetRef } : {},
185
+ credentialMigration: "done"
186
+ },
187
+ status: migration === "pending" ? "resumed-pending" : "migrated",
188
+ credentialRef: targetRef,
189
+ phase: "strip"
190
+ };
191
+ }
192
+ const stored = await brokerHas(broker, targetRef);
193
+ if (stored) {
194
+ return {
195
+ updates: {
196
+ credentialRef: targetRef,
197
+ credentialMigration: "done",
198
+ ...!(typeof agent.apiKeyRef === "string" && agent.apiKeyRef.trim()) ? { apiKeyRef: targetRef } : {}
199
+ },
200
+ status: "resumed-pending",
201
+ credentialRef: targetRef,
202
+ phase: "complete"
203
+ };
204
+ }
205
+ return {
206
+ updates: {
207
+ credentialRef: targetRef,
208
+ credentialMigration: "pending"
209
+ },
210
+ status: "awaiting-secret",
211
+ credentialRef: targetRef,
212
+ phase: "put"
213
+ };
214
+ }
215
+ function applyAgentSecretMigrationUpdates(record, updates) {
216
+ const next = { ...record };
217
+ if ("apiKey" in updates) {
218
+ if (updates.apiKey === null || updates.apiKey === "") {
219
+ delete next.apiKey;
220
+ } else if (typeof updates.apiKey === "string") {
221
+ next.apiKey = updates.apiKey;
222
+ }
223
+ }
224
+ if (updates.apiKeyRef !== void 0) next.apiKeyRef = updates.apiKeyRef;
225
+ if (updates.credentialRef !== void 0) next.credentialRef = updates.credentialRef;
226
+ if (updates.credentialMigration !== void 0) {
227
+ next.credentialMigration = updates.credentialMigration;
228
+ }
229
+ return next;
230
+ }
231
+
232
+ // packages/agent-runtime/runtimeToolPolicy.ts
233
+ function unique(values) {
234
+ return [...new Set(values)];
235
+ }
236
+ function normalizeAgentRuntimeToolPolicy(value) {
237
+ if (!isRecord(value)) return void 0;
238
+ return {
239
+ version: 1,
240
+ ...asNonEmptyStringArray(value.agentTools).length ? { agentTools: unique(asNonEmptyStringArray(value.agentTools)) } : {},
241
+ ...asNonEmptyStringArray(value.runtimeTools).length ? { runtimeTools: unique(asNonEmptyStringArray(value.runtimeTools)) } : {},
242
+ ...isRecord(value.workspace) ? { workspace: { ...value.workspace } } : {},
243
+ ...isRecord(value.shell) ? { shell: { ...value.shell } } : {},
244
+ ...isRecord(value.isolation) ? { isolation: { ...value.isolation } } : {},
245
+ ...isRecord(value.git) ? { git: { ...value.git } } : {},
246
+ ...isRecord(value.budget) ? { budget: { ...value.budget } } : {},
247
+ ...isRecord(value.audit) ? { audit: { ...value.audit } } : {}
248
+ };
249
+ }
250
+ function runtimeBindingRecord(runtimeBinding) {
251
+ return isRecord(runtimeBinding) ? runtimeBinding : void 0;
252
+ }
253
+ function runtimeToolNamesFromPolicy(policy) {
254
+ return asNonEmptyStringArray(policy?.runtimeTools);
255
+ }
256
+ function readPositiveNumber(value) {
257
+ return asOptionalPositiveFiniteNumber(Number(value));
258
+ }
259
+ function resolveRequestedRuntimeToolNames(args) {
260
+ const runtimeBinding = runtimeBindingRecord(args.agentConfig.runtimeBinding);
261
+ const bindingPolicy = normalizeAgentRuntimeToolPolicy(
262
+ runtimeBinding?.runtimeToolPolicy
263
+ );
264
+ const bindingSnapshotPolicy = normalizeAgentRuntimeToolPolicy(
265
+ runtimeBinding?.runtimeToolPolicySnapshot
266
+ );
267
+ return unique([
268
+ ...asNonEmptyStringArray(args.agentConfig.toolNames),
269
+ ...runtimeToolNamesFromPolicy(
270
+ normalizeAgentRuntimeToolPolicy(args.agentConfig.runtimeToolPolicy)
271
+ ),
272
+ ...runtimeToolNamesFromPolicy(bindingPolicy),
273
+ ...runtimeToolNamesFromPolicy(bindingSnapshotPolicy)
274
+ ]);
275
+ }
276
+ function resolveCurrentRunRuntimeToolPolicy(agentConfig) {
277
+ const runtimeBinding = runtimeBindingRecord(agentConfig?.runtimeBinding);
278
+ return normalizeAgentRuntimeToolPolicy(
279
+ runtimeBinding?.runtimeToolPolicySnapshot ?? agentConfig?.runtimeToolPolicy ?? runtimeBinding?.runtimeToolPolicy
280
+ );
281
+ }
282
+ function resolveLocalRuntimeEnvFromPolicy(runtimeEnv, policy) {
283
+ return { ...runtimeEnv };
284
+ }
285
+ function resolveLocalWorkspaceExecutorOptionsFromPolicy(policy) {
286
+ const maxOutputBytes = readPositiveNumber(policy?.shell?.maxOutputBytes);
287
+ return {
288
+ ...maxOutputBytes ? { commandOutputLimit: Math.floor(maxOutputBytes) } : {}
289
+ };
290
+ }
291
+
292
+ export {
293
+ createFileCredentialBroker,
294
+ migrateAgentSecrets,
295
+ applyAgentSecretMigrationUpdates,
296
+ normalizeAgentRuntimeToolPolicy,
297
+ resolveRequestedRuntimeToolNames,
298
+ resolveCurrentRunRuntimeToolPolicy,
299
+ resolveLocalRuntimeEnvFromPolicy,
300
+ resolveLocalWorkspaceExecutorOptionsFromPolicy
301
+ };