nolo-cli 0.14.0 → 0.15.0

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 (100) hide show
  1. package/{_executeModel-TURRLTZ2.js → _executeModel-QAUS6B7J.js} +24 -24
  2. package/{action-N3KXFO5V.js → action-GUOZYYGN.js} +4 -4
  3. package/{addContentAction-4Z762DMR.js → addContentAction-QDGHGUBH.js} +3 -3
  4. package/{addDialogAgentAction-FALLEKPR.js → addDialogAgentAction-Z4YCYZIV.js} +2 -2
  5. package/{agentDeleteCommand-AZDVM4HQ.js → agentDeleteCommand-QDO62EZA.js} +20 -20
  6. package/{agentEmailCommands-M4AHOEZ3.js → agentEmailCommands-UZ5BKX3P.js} +38 -38
  7. package/{agentGrantCommands-B4MB23VQ.js → agentGrantCommands-JNDE4RWR.js} +2 -2
  8. package/{agentListCommands-OJLOXSKL.js → agentListCommands-ZC33UDWT.js} +22 -22
  9. package/{agentMachineCommands-NPMM4Z53.js → agentMachineCommands-RZGZEZRL.js} +20 -20
  10. package/{agentPullCommand-KRBRIFIY.js → agentPullCommand-6HWUT3SW.js} +2 -2
  11. package/{agentRecordCommands-RVUH7XLZ.js → agentRecordCommands-DGDXE2VH.js} +33 -33
  12. package/{agentRunCommand-F6W2WKKZ.js → agentRunCommand-SRZWFOPH.js} +35 -35
  13. package/{agentRunControl-IX4F5W2C.js → agentRunControl-6ADXVYMR.js} +2 -2
  14. package/{agentRuntimeLocal-DSUBT77I.js → agentRuntimeLocal-4YCF6IRF.js} +11 -11
  15. package/{agentSlice-PCEL26Z7.js → agentSlice-IVE735EV.js} +3 -3
  16. package/appDeleteCommands-7I26L64I.js +124 -0
  17. package/appDeployCommands-TZLZNTJN.js +163 -0
  18. package/appDeployStatusCommands-OPPTLHRW.js +144 -0
  19. package/appGetCommands-N2S4HYKY.js +119 -0
  20. package/appListCommands-OBTPPKUM.js +122 -0
  21. package/{authCommand-66ME4KZX.js → authCommand-YFTR3347.js} +5 -5
  22. package/{authCommands-GH5T6RYV.js → authCommands-YXGOXNBZ.js} +3 -3
  23. package/{chunk-3B2LFO6R.js → browser-image-compression-MFDTD7K6.js} +4 -518
  24. package/{chunk-4UUJFFMK.js → chunk-472E5RMQ.js} +1 -1
  25. package/chunk-4QQFLN5C.js +552 -0
  26. package/{chunk-33K5FKRL.js → chunk-5VMYGIIL.js} +110 -39
  27. package/{chunk-LNSRTNH7.js → chunk-6565R2TI.js} +20 -16
  28. package/{chunk-VQFY3VXW.js → chunk-6MHDWKOT.js} +3 -2
  29. package/{chunk-5NBHQD4D.js → chunk-A7GB5UGH.js} +1 -1
  30. package/{chunk-NZFWHBW5.js → chunk-AWDOJBHW.js} +487 -441
  31. package/{chunk-MYE5X27Y.js → chunk-BFRVXJJJ.js} +43 -16
  32. package/{chunk-PYAJ6ZSK.js → chunk-G2MKOQCB.js} +1 -1
  33. package/chunk-GFUIQ4RY.js +136 -0
  34. package/{chunk-KTFJUPDW.js → chunk-HRQCKQA5.js} +31 -31
  35. package/{chunk-TQCONXQ3.js → chunk-IOQ7IBPU.js} +1 -1
  36. package/{chunk-OIMX7MM4.js → chunk-ISYE6GZB.js} +1 -1
  37. package/{chunk-RZALKBP4.js → chunk-IZ2QRVEU.js} +2 -2
  38. package/{chunk-XIDYAII4.js → chunk-JBKVPAYK.js} +7 -140
  39. package/{chunk-V6VXDXGY.js → chunk-JS33TCQ3.js} +2 -2
  40. package/{chunk-5R73BS7Y.js → chunk-K53477EY.js} +5 -5
  41. package/{chunk-7JJCGV7N.js → chunk-K6EUAOW3.js} +1 -1
  42. package/{chunk-OHEKYYJF.js → chunk-KMQPSTMJ.js} +6 -6
  43. package/{chunk-3WGLLTK4.js → chunk-LSFAWXKC.js} +100 -3
  44. package/{chunk-4ON5AV72.js → chunk-MYMMNKYL.js} +1 -1
  45. package/{chunk-BHK5ZAW7.js → chunk-N5424GSW.js} +1 -1
  46. package/chunk-NTC6I2FN.js +107 -0
  47. package/{chunk-7LAIOHOL.js → chunk-O53CP2QR.js} +3 -3
  48. package/{chunk-TLNEQI2R.js → chunk-OKSYPTDZ.js} +9 -9
  49. package/{chunk-IMZ7AFIJ.js → chunk-OQMPU2ML.js} +4 -4
  50. package/{chunk-IYGQF62W.js → chunk-P4MJQWWF.js} +3 -3
  51. package/{chunk-UW3WOIWJ.js → chunk-RKM3K52F.js} +1 -1
  52. package/{chunk-A5V7UEZJ.js → chunk-SFXYKGK2.js} +3 -3
  53. package/{chunk-S5UACFUP.js → chunk-TTGAVETO.js} +10 -2
  54. package/{chunk-BOJVWKNA.js → chunk-U7LEGLEB.js} +1 -1
  55. package/{chunk-E6KIDMTW.js → chunk-UXKQQ2MR.js} +9 -9
  56. package/{chunk-R5AOLZZV.js → chunk-VE6XMVKG.js} +203 -45
  57. package/{chunk-NJVPXLRY.js → chunk-VPTJB4HM.js} +1 -1
  58. package/{chunk-PB2DHBEQ.js → chunk-WA6KZL5V.js} +25 -6
  59. package/{chunk-T3X232L6.js → chunk-WNLPAOIT.js} +1 -1
  60. package/{chunk-NFPO7274.js → chunk-WRN5EQT7.js} +1 -1
  61. package/{chunk-4F4FJPFM.js → chunk-XGQZFBO5.js} +90 -209
  62. package/{chunk-3FCSMQAC.js → chunk-XVP3C2KY.js} +1 -1
  63. package/{chunk-TYRTLSGX.js → chunk-YNHQIXX5.js} +833 -5746
  64. package/{chunk-7TN6V43T.js → chunk-Z24FGIU2.js} +2 -2
  65. package/{cliEnvHelpers-VYC2OPTB.js → cliEnvHelpers-ZXNMX7VV.js} +1 -1
  66. package/{createAgentAutomationAction-VLNDOHSP.js → createAgentAutomationAction-TS6NNZ4X.js} +9 -9
  67. package/{createDialogAction-6WYTS62Z.js → createDialogAction-5HVQ33EX.js} +10 -10
  68. package/{createPageAction-YKHOC3LW.js → createPageAction-4F3ZGQJD.js} +9 -9
  69. package/{dbSlice-7Q23HSWH.js → dbSlice-OP6UPXKA.js} +2 -2
  70. package/{dialogCommands-BQDGLVMO.js → dialogCommands-3GEPXHFB.js} +16 -16
  71. package/{dialogSlice-2A2JOFZW.js → dialogSlice-FAWUQDJW.js} +9 -9
  72. package/{docCreateCommands-K2MPMXYF.js → docCreateCommands-ZE3S6BCP.js} +22 -20
  73. package/{docDeleteCommands-NBAARB77.js → docDeleteCommands-TW6PGTRT.js} +21 -19
  74. package/{docReadCommands-S3MO5RPS.js → docReadCommands-LDXL3B6J.js} +20 -18
  75. package/{docStore-JJP5PUR7.js → docStore-2UHVWLTV.js} +10 -10
  76. package/{docUpdateCommands-EHEI7FCE.js → docUpdateCommands-GYD6XI5O.js} +21 -19
  77. package/{handleSendMessageAction-UAXTF73I.js → handleSendMessageAction-LJPUYNOH.js} +15 -11
  78. package/index.js +109 -78
  79. package/{machineCommands-BQ46IS5M.js → machineCommands-OKNDYS3M.js} +36 -36
  80. package/{machineWsRunDispatch-R33NXNNI.js → machineWsRunDispatch-ZX5AJ6FJ.js} +32 -32
  81. package/{memoryCommands-AFMES3LN.js → memoryCommands-EBMICQR6.js} +1 -1
  82. package/package.json +1 -1
  83. package/{read-SIWMJRHC.js → read-HXHAZBKH.js} +1 -1
  84. package/{readDocTool-TCYJY4PP.js → readDocTool-VPBDTO4G.js} +1 -1
  85. package/{readlineWorkspace-KBG4DKLX.js → readlineWorkspace-MB3ANKHM.js} +123 -103
  86. package/{removeDialogAgentAction-WKHZT6VJ.js → removeDialogAgentAction-HUFVN35S.js} +4 -4
  87. package/{runAgentClientLoop-MUV5YIRK.js → runAgentClientLoop-A75BUU6D.js} +19 -19
  88. package/{runtimeDoctorCommands-QNF3J3UV.js → runtimeDoctorCommands-THIHX2SY.js} +1 -1
  89. package/{setDialogExtraReferencesAction-GCI5QU6E.js → setDialogExtraReferencesAction-2VLGWQKG.js} +2 -2
  90. package/{setPrimaryDialogAgentAction-NRO57AS6.js → setPrimaryDialogAgentAction-VB4UV2CC.js} +4 -4
  91. package/{settingSlice-FTWZ5ZHT.js → settingSlice-7JYPQNAC.js} +3 -3
  92. package/{spaceCommands-4R63UST3.js → spaceCommands-O3KJNCON.js} +21 -21
  93. package/{spaceSlice-VTC3QXP3.js → spaceSlice-444MFUP6.js} +11 -9
  94. package/{streamAgentChatTurn-43N7BNV2.js → streamAgentChatTurn-DJAE7USZ.js} +42 -39
  95. package/{tableCommands-E4SQWDOX.js → tableCommands-3P7MJ3PF.js} +4 -4
  96. package/{tools-PX6PEJLE.js → tools-YB6LXSVN.js} +14 -14
  97. package/{tuiSummaryLlmCaller-2D65LKWM.js → tuiSummaryLlmCaller-QQL3JA5I.js} +3 -3
  98. package/{updateCommands-XZDOOYFH.js → updateCommands-XTW55TOT.js} +2 -2
  99. package/{updateDialogTitleAction-NPQZWAKG.js → updateDialogTitleAction-6HGFBM64.js} +9 -9
  100. package/{chunk-3QAF2LTL.js → chunk-DZ3XJVET.js} +3 -3
@@ -4,15 +4,11 @@ import {
4
4
  refreshOpenAiCodexToken,
5
5
  refreshXaiOAuthToken
6
6
  } from "./chunk-EHLHSX7R.js";
7
- import {
8
- CliProviderQuotaError,
9
- executeCli
10
- } from "./chunk-CMKUBIGW.js";
11
7
  import {
12
8
  buildLocalAgentLookupKeys,
13
9
  normalizeAgentHandle,
14
10
  shouldReadAgentKeyRemotely
15
- } from "./chunk-TQCONXQ3.js";
11
+ } from "./chunk-IOQ7IBPU.js";
16
12
  import {
17
13
  LOCAL_CODEX_AGENT_ID,
18
14
  LOCAL_CODEX_AGENT_KEY,
@@ -21,23 +17,21 @@ import {
21
17
  } from "./chunk-VHBWHNVT.js";
22
18
  import {
23
19
  inferCaptureIntent
24
- } from "./chunk-T3X232L6.js";
25
- import {
26
- buildCliPrompt
27
- } from "./chunk-ATNTHIZI.js";
20
+ } from "./chunk-WNLPAOIT.js";
28
21
  import {
29
22
  inlineImageUrlsForCustomProvider,
30
23
  prepareTools
31
- } from "./chunk-NFPO7274.js";
24
+ } from "./chunk-WRN5EQT7.js";
32
25
  import {
33
26
  getAntigravityUserAgent,
34
27
  isAntigravityOAuthAgent,
35
28
  readAntigravityProjectId,
36
29
  resolveAntigravityCloudCodeBaseUrl
37
- } from "./chunk-OIMX7MM4.js";
30
+ } from "./chunk-ISYE6GZB.js";
38
31
  import {
39
32
  FORCED_TOOLS,
40
33
  addDefaultLightWebToolsForConfiguredAgents,
34
+ addDefaultSystemCapabilityTools,
41
35
  appendEnabledPackPromptPatches,
42
36
  applyDisabledTools,
43
37
  applySystemBuiltinSkillFilter,
@@ -53,7 +47,7 @@ import {
53
47
  readXhsProfileFunctionSchema,
54
48
  rememberMemoryFunctionSchema,
55
49
  resolveEffectiveEnabledPacks
56
- } from "./chunk-R5AOLZZV.js";
50
+ } from "./chunk-VE6XMVKG.js";
57
51
  import {
58
52
  createDrainExhaustedResponse,
59
53
  isCoreDrainingBody,
@@ -65,13 +59,13 @@ import {
65
59
  } from "./chunk-OWOHNGCN.js";
66
60
  import {
67
61
  prepareTokenUsageData
68
- } from "./chunk-TYRTLSGX.js";
62
+ } from "./chunk-YNHQIXX5.js";
69
63
  import {
70
64
  BUILTIN_TITLE_LLM_CONFIG
71
65
  } from "./chunk-V2J635L5.js";
72
66
  import {
73
67
  fetchServerSyncedCredential
74
- } from "./chunk-IMZ7AFIJ.js";
68
+ } from "./chunk-OQMPU2ML.js";
75
69
  import {
76
70
  buildAgentRuntimeDialogWritePlan,
77
71
  buildLocalWorkspaceOpenAiTools,
@@ -84,7 +78,7 @@ import {
84
78
  parseSseDataLineJson,
85
79
  readOpenAiCompatibleSseCompletion,
86
80
  resolveOpenAiCompatibleProviderConfig
87
- } from "./chunk-33K5FKRL.js";
81
+ } from "./chunk-5VMYGIIL.js";
88
82
  import {
89
83
  buildPlatformChatCompletionRequest,
90
84
  canUsePlatformChatProvider,
@@ -94,14 +88,17 @@ import {
94
88
  resolveLegacyDeepSeekProxyChatFallback,
95
89
  resolvePlatformChatProviderConfig,
96
90
  shouldUsePlatformChatProvider
97
- } from "./chunk-PB2DHBEQ.js";
91
+ } from "./chunk-WA6KZL5V.js";
98
92
  import {
99
93
  resolveAgentRuntimeConfigFromRecord
100
94
  } from "./chunk-OIQPORYI.js";
101
95
  import {
102
96
  parseToolArgumentsJson,
103
97
  summarizeToolArguments
104
- } from "./chunk-VQFY3VXW.js";
98
+ } from "./chunk-6MHDWKOT.js";
99
+ import {
100
+ resolvePlatformAuthToken
101
+ } from "./chunk-HRQCKQA5.js";
105
102
  import {
106
103
  buildLoadSkillExecutor,
107
104
  buildNoloWorkspaceCliToolExecutors,
@@ -134,13 +131,27 @@ import {
134
131
  findRunRecord,
135
132
  listRunRecords,
136
133
  spawnLocalBackgroundRun
137
- } from "./chunk-4ON5AV72.js";
134
+ } from "./chunk-MYMMNKYL.js";
135
+ import {
136
+ CliProviderQuotaError,
137
+ executeCli
138
+ } from "./chunk-CMKUBIGW.js";
139
+ import {
140
+ buildCliPrompt
141
+ } from "./chunk-ATNTHIZI.js";
138
142
  import {
139
143
  toErrorMessage
140
144
  } from "./chunk-HNMXYYJR.js";
141
145
  import {
142
146
  getDefaultCliLocalRuntimeDb
143
147
  } from "./chunk-H33743XH.js";
148
+ import {
149
+ isCompiledBinary,
150
+ parseUserIdFromAuthToken
151
+ } from "./chunk-A7GB5UGH.js";
152
+ import {
153
+ DEFAULT_NOLO_SERVER_URL
154
+ } from "./chunk-OLZBQWZU.js";
144
155
  import {
145
156
  asRecordOrEmpty
146
157
  } from "./chunk-KX6YBIHG.js";
@@ -162,20 +173,13 @@ import {
162
173
  PUBLIC_GLM_52_AGENT_KEY,
163
174
  PUBLIC_KIMI_K26_IMAGE_AGENT_KEY,
164
175
  PUBLIC_KIMI_K27_CODING_AGENT_KEY
165
- } from "./chunk-NJVPXLRY.js";
176
+ } from "./chunk-VPTJB4HM.js";
166
177
  import {
167
178
  asTrimmedString
168
179
  } from "./chunk-3EUW3WEO.js";
169
180
  import {
170
181
  isRecord
171
182
  } from "./chunk-KUG52IAP.js";
172
- import {
173
- isCompiledBinary,
174
- parseUserIdFromAuthToken
175
- } from "./chunk-5NBHQD4D.js";
176
- import {
177
- DEFAULT_NOLO_SERVER_URL
178
- } from "./chunk-OLZBQWZU.js";
179
183
  import {
180
184
  NOLO_CLUSTER_SERVERS
181
185
  } from "./chunk-LCBAMY2M.js";
@@ -291,6 +295,10 @@ var STRINGS = {
291
295
  en: "Agent switch cancelled.",
292
296
  zh: "\u5DF2\u53D6\u6D88\u5207\u6362 agent\u3002"
293
297
  },
298
+ agentPickerLoading: {
299
+ en: "Loading agents\u2026",
300
+ zh: "\u6B63\u5728\u52A0\u8F7D agent \u5217\u8868\u2026"
301
+ },
294
302
  historyPickerTitle: {
295
303
  en: "Resume dialog (\u2191\u2193 Enter Esc)",
296
304
  zh: "\u6062\u590D\u5BF9\u8BDD\uFF08\u2191\u2193 \u79FB\u52A8 \xB7 Enter \u9009\u62E9 \xB7 Esc \u53D6\u6D88\uFF09"
@@ -610,10 +618,6 @@ var STRINGS = {
610
618
  en: "tools",
611
619
  zh: "\u5DE5\u5177"
612
620
  },
613
- contextFieldThinking: {
614
- en: "thinking",
615
- zh: "\u601D\u8003"
616
- },
617
621
  contextFieldServer: {
618
622
  en: "server",
619
623
  zh: "\u670D\u52A1\u7AEF"
@@ -651,7 +655,6 @@ var STRINGS = {
651
655
  " /context Show workspace context and next actions",
652
656
  " /runtime <mode> Use auto, local, or server runtime",
653
657
  " /tools <mode> Control tool trace: hide, compact, verbose",
654
- " /thinking <mode> Control thinking output: hide, marker, show",
655
658
  " /switch Pick an agent interactively (\u2191\u2193, Enter)",
656
659
  " /switch list List agents as text",
657
660
  " /switch <name> Switch directly by name, alias, or key (alias: /agent)",
@@ -688,7 +691,6 @@ var STRINGS = {
688
691
  " /context \u67E5\u770B\u5DE5\u4F5C\u533A\u4E0A\u4E0B\u6587\u4E0E\u540E\u7EED\u64CD\u4F5C",
689
692
  " /runtime <mode> \u5207\u6362 runtime\uFF1Aauto\u3001local\u3001server",
690
693
  " /tools <mode> \u5DE5\u5177\u8F68\u8FF9\u663E\u793A\uFF1Ahide\u3001compact\u3001verbose",
691
- " /thinking <mode> \u601D\u8003\u8FC7\u7A0B\u663E\u793A\uFF1Ahide\u3001marker\u3001show",
692
694
  " /switch \u4EA4\u4E92\u5F0F\u9009\u62E9 agent\uFF08\u2191\u2193 \u79FB\u52A8\uFF0CEnter \u786E\u8BA4\uFF09",
693
695
  " /switch list \u4EE5\u6587\u672C\u5217\u51FA\u5168\u90E8 agent",
694
696
  " /switch <name> \u6309\u540D\u79F0\u3001\u522B\u540D\u6216 key \u76F4\u63A5\u5207\u6362\uFF08\u522B\u540D\uFF1A/agent\uFF09",
@@ -733,12 +735,6 @@ var STRINGS = {
733
735
  },
734
736
  toolsUsage: { en: "Usage: /tools <hide|compact|verbose>", zh: "\u7528\u6CD5\uFF1A/tools <hide|compact|verbose>" },
735
737
  toolsSet: { en: "Tool display: {0}", zh: "\u5DE5\u5177\u663E\u793A\uFF1A{0}" },
736
- thinkingCurrent: {
737
- en: "Thinking display: {0} (hide | marker | show)",
738
- zh: "\u601D\u8003\u663E\u793A\uFF1A{0}\uFF08hide | marker | show\uFF09"
739
- },
740
- thinkingUsage: { en: "Usage: /thinking <hide|marker|show>", zh: "\u7528\u6CD5\uFF1A/thinking <hide|marker|show>" },
741
- thinkingSet: { en: "Thinking display: {0}", zh: "\u601D\u8003\u663E\u793A\uFF1A{0}" },
742
738
  tasksRunning: { en: "Running processes ({0}):", zh: "\u8FD0\u884C\u4E2D\u7684\u8FDB\u7A0B\uFF08{0}\uFF09\uFF1A" },
743
739
  tasksStopped: { en: "Stopped/exited ({0}):", zh: "\u5DF2\u505C\u6B62/\u5DF2\u9000\u51FA\uFF08{0}\uFF09\uFF1A" },
744
740
  tasksNone: { en: "No processes.", zh: "\u6CA1\u6709\u8FD0\u884C\u4E2D\u7684\u8FDB\u7A0B\u3002" },
@@ -929,6 +925,44 @@ function agentRunCardLabels() {
929
925
  };
930
926
  }
931
927
 
928
+ // packages/cli/client/localRuntimeDiagnostics.ts
929
+ import { ulid } from "ulid";
930
+ var preparedAgentRuntimeCache = /* @__PURE__ */ new Map();
931
+ var hybridStoreCache = /* @__PURE__ */ new Map();
932
+ function normalizeRuntimeCacheCwd(cwd) {
933
+ return (cwd?.trim() || process.cwd()).replace(/\/+$/, "") || ".";
934
+ }
935
+ function buildPreparedAgentCacheKey(args) {
936
+ const systemBuiltinSkillsKey = args.systemBuiltinSkills ? JSON.stringify(
937
+ Object.keys(args.systemBuiltinSkills).sort().map((key) => [key, args.systemBuiltinSkills?.[key]])
938
+ ) : "default";
939
+ return `${args.userId}\0${args.agentRef}\0${args.cwd}\0${systemBuiltinSkillsKey}`;
940
+ }
941
+ function clearCliLocalRuntimePreparedAgentCache() {
942
+ preparedAgentRuntimeCache.clear();
943
+ hybridStoreCache.clear();
944
+ }
945
+ async function defaultLocalRuntimeDb() {
946
+ return getDefaultCliLocalRuntimeDb();
947
+ }
948
+ function createFallbackId() {
949
+ return ulid();
950
+ }
951
+ function logLocalRuntimeDiagnostic(event, fields) {
952
+ if (process.env.NOLO_LOCAL_RUNTIME_DEBUG !== "1" && process.env.NOLO_DEBUG !== "1") {
953
+ return;
954
+ }
955
+ console.error(`[nolo-local-runtime] ${event} ${JSON.stringify(fields)}`);
956
+ }
957
+ function summarizeOpenAiToolNames(tools) {
958
+ return tools.reduce((acc, tool) => {
959
+ const fn = tool.function;
960
+ const name = fn && typeof fn === "object" && "name" in fn && typeof fn.name === "string" ? fn.name : null;
961
+ if (name) acc.push(name);
962
+ return acc;
963
+ }, []);
964
+ }
965
+
932
966
  // packages/cli/client/localRuntimeAdapter.ts
933
967
  import { dirname, extname, join } from "node:path";
934
968
  import { fileURLToPath } from "node:url";
@@ -954,7 +988,7 @@ function resolveRuntimeServerUrl(env) {
954
988
  return (env?.NOLO_SERVER_URL || env?.NOLO_SERVER || env?.BASE_URL || "").replace(/\/+$/, "");
955
989
  }
956
990
  function resolveRuntimeAuthToken(env) {
957
- return env?.AUTH_TOKEN || env?.AUTH || env?.NOLO_MACHINE_API_KEY || "";
991
+ return resolvePlatformAuthToken(env ?? {});
958
992
  }
959
993
 
960
994
  // packages/cli/client/localRuntimeFetchRetry.ts
@@ -1368,56 +1402,6 @@ async function syncLocalDialogEvidenceToRemote(args) {
1368
1402
  return { attempted: true };
1369
1403
  }
1370
1404
 
1371
- // packages/cli/client/cliChildDialogPersist.ts
1372
- async function persistCliPendingChildDialog(args) {
1373
- const nowIso = new Date(args.now).toISOString();
1374
- const dialogKey = `dialog-${args.userId}-${args.dialogId}`;
1375
- const record = {
1376
- id: args.dialogId,
1377
- dbKey: dialogKey,
1378
- type: "dialog",
1379
- userId: args.userId,
1380
- cybots: [args.agentKey],
1381
- primaryAgentKey: args.agentKey,
1382
- title: args.title.slice(0, 80),
1383
- status: "pending",
1384
- triggerType: "cli-local",
1385
- executionMode: args.background ? "background" : "foreground",
1386
- createdAt: nowIso,
1387
- updatedAt: nowIso,
1388
- ...args.spaceId ? { spaceId: args.spaceId } : {},
1389
- ...args.parentDialogId ? { parentDialogId: args.parentDialogId } : {},
1390
- ...args.rootDialogId ? { rootDialogId: args.rootDialogId } : {},
1391
- localRuntime: {
1392
- host: "cli",
1393
- workspaceRoot: args.workspaceRoot,
1394
- workspaceKind: "current",
1395
- workspaceAccess: "inherited"
1396
- }
1397
- };
1398
- await args.store.batch([{ type: "put", key: dialogKey, value: record }]);
1399
- }
1400
- async function persistCliFailedChildDialog(args) {
1401
- const dialogKey = `dialog-${args.userId}-${args.dialogId}`;
1402
- const existing = await args.store.read(dialogKey);
1403
- const existingRecord = existing && typeof existing === "object" ? existing : {};
1404
- await args.store.batch([
1405
- {
1406
- type: "put",
1407
- key: dialogKey,
1408
- value: {
1409
- ...existingRecord,
1410
- id: args.dialogId,
1411
- dbKey: dialogKey,
1412
- status: "failed",
1413
- errorMessage: args.errorMessage,
1414
- updatedAt: new Date(args.now).toISOString(),
1415
- finishedAt: args.now
1416
- }
1417
- }
1418
- ]);
1419
- }
1420
-
1421
1405
  // packages/cli/client/cliLocalToolBudget.ts
1422
1406
  function parseLocalToolBudgets(env) {
1423
1407
  const raw = env.NOLO_LOCAL_TOOL_BUDGETS?.trim();
@@ -1637,58 +1621,6 @@ async function readDialogMessages(args) {
1637
1621
  return messages;
1638
1622
  }
1639
1623
 
1640
- // packages/cli/client/cliWorkspaceToolVariants.ts
1641
- function shouldUseDeclaredOnlyLocalWorkspaceTools(env) {
1642
- const value = env.NOLO_LOCAL_WORKSPACE_TOOLSET || env.NOLO_LOCAL_TOOLSET_MODE || "";
1643
- return value === "declared-only" || value === "declared";
1644
- }
1645
- function resolveGlobFilesDescriptionVariant(env) {
1646
- return resolveLocalWorkspaceDescriptionVariant(
1647
- env.NOLO_GLOBFILES_DESCRIPTION_VARIANT
1648
- );
1649
- }
1650
- function resolveListFilesDescriptionVariant(env) {
1651
- return resolveLocalWorkspaceDescriptionVariant(
1652
- env.NOLO_LISTFILES_DESCRIPTION_VARIANT
1653
- );
1654
- }
1655
- function resolveListFilesParameterVariant(env) {
1656
- return resolveLocalWorkspaceParameterVariant(
1657
- env.NOLO_LISTFILES_PARAMETER_VARIANT
1658
- );
1659
- }
1660
- function resolveReadFileDescriptionVariant(env) {
1661
- return resolveLocalWorkspaceDescriptionVariant(
1662
- env.NOLO_READFILE_DESCRIPTION_VARIANT
1663
- );
1664
- }
1665
- function resolveReadFileParameterVariant(env) {
1666
- return resolveLocalWorkspaceParameterVariant(
1667
- env.NOLO_READFILE_PARAMETER_VARIANT
1668
- );
1669
- }
1670
- function resolveGlobFilesParameterVariant(env) {
1671
- return resolveLocalWorkspaceParameterVariant(
1672
- env.NOLO_GLOBFILES_PARAMETER_VARIANT
1673
- );
1674
- }
1675
- function resolveSearchFilesDescriptionVariant(env) {
1676
- return resolveLocalWorkspaceDescriptionVariant(
1677
- env.NOLO_SEARCHFILES_DESCRIPTION_VARIANT
1678
- );
1679
- }
1680
- function resolveSearchFilesParameterVariant(env) {
1681
- return resolveLocalWorkspaceParameterVariant(
1682
- env.NOLO_SEARCHFILES_PARAMETER_VARIANT
1683
- );
1684
- }
1685
- function resolveLocalWorkspaceDescriptionVariant(value) {
1686
- return value === "brief" || value === "strategy" || value === "workflow" || value === "antiShell" ? value : "strategy";
1687
- }
1688
- function resolveLocalWorkspaceParameterVariant(value) {
1689
- return value === "minimal" || value === "scoped" || value === "rich" ? value : "rich";
1690
- }
1691
-
1692
1624
  // packages/cli/client/cliProviderHelpers.ts
1693
1625
  function buildDelegatedTaskContent(task, input) {
1694
1626
  if (input === void 0 || input === null) {
@@ -2541,6 +2473,24 @@ function convertOpenAiMessagesToCca(messages, options) {
2541
2473
  const contents = [];
2542
2474
  const systemTexts = [];
2543
2475
  const toolNamesById = /* @__PURE__ */ new Map();
2476
+ let pendingFunctionCalls = [];
2477
+ const pushOrMergeContent = (role, parts) => {
2478
+ if (parts.length === 0) return;
2479
+ const last = contents[contents.length - 1];
2480
+ if (last && last.role === role) {
2481
+ last.parts.push(...parts);
2482
+ } else {
2483
+ contents.push({ role, parts });
2484
+ }
2485
+ };
2486
+ const flushPendingFunctionCalls = () => {
2487
+ if (pendingFunctionCalls.length === 0) return;
2488
+ const dummyResponses = pendingFunctionCalls.map(({ name }) => ({
2489
+ functionResponse: { name, response: { output: "{}" } }
2490
+ }));
2491
+ pendingFunctionCalls = [];
2492
+ pushOrMergeContent("user", dummyResponses);
2493
+ };
2544
2494
  for (const raw of messages) {
2545
2495
  if (!raw || typeof raw !== "object" || !("role" in raw)) continue;
2546
2496
  const role = String(raw.role);
@@ -2551,6 +2501,7 @@ function convertOpenAiMessagesToCca(messages, options) {
2551
2501
  continue;
2552
2502
  }
2553
2503
  if (role === "user") {
2504
+ flushPendingFunctionCalls();
2554
2505
  const text = messageText(content);
2555
2506
  const imageParts = extractInlineDataParts(
2556
2507
  content
@@ -2559,10 +2510,11 @@ function convertOpenAiMessagesToCca(messages, options) {
2559
2510
  const parts = [];
2560
2511
  if (text) parts.push({ text });
2561
2512
  for (const img of imageParts) parts.push(img);
2562
- contents.push({ role: "user", parts });
2513
+ pushOrMergeContent("user", parts);
2563
2514
  continue;
2564
2515
  }
2565
2516
  if (role === "assistant") {
2517
+ flushPendingFunctionCalls();
2566
2518
  const parts = [];
2567
2519
  const text = messageText(content);
2568
2520
  if (text) parts.push({ text });
@@ -2572,6 +2524,7 @@ function convertOpenAiMessagesToCca(messages, options) {
2572
2524
  if (!name) continue;
2573
2525
  const id = call.id?.trim() || `${name}_${toolNamesById.size}`;
2574
2526
  toolNamesById.set(id, name);
2527
+ pendingFunctionCalls.push({ name, id });
2575
2528
  const realSignature = typeof call.thought_signature === "string" && call.thought_signature ? call.thought_signature : void 0;
2576
2529
  const isFirstFunctionCallPart = !parts.some((p) => "functionCall" in p);
2577
2530
  parts.push({
@@ -2584,19 +2537,28 @@ function convertOpenAiMessagesToCca(messages, options) {
2584
2537
  });
2585
2538
  }
2586
2539
  if (parts.length === 0) continue;
2587
- contents.push({ role: "model", parts });
2540
+ pushOrMergeContent("model", parts);
2588
2541
  continue;
2589
2542
  }
2590
2543
  if (role === "tool") {
2591
2544
  const toolCallId = "tool_call_id" in raw && typeof raw.tool_call_id === "string" ? raw.tool_call_id : "";
2592
- const name = toolNamesById.get(toolCallId) ?? "tool";
2545
+ const rawName = "name" in raw && typeof raw.name === "string" ? raw.name.trim() : "";
2546
+ const name = toolNamesById.get(toolCallId) || rawName || pendingFunctionCalls[0]?.name || "tool";
2547
+ const pendingIndex = pendingFunctionCalls.findIndex(
2548
+ (p) => toolCallId ? p.id === toolCallId : p.name === name
2549
+ );
2550
+ if (pendingIndex !== -1) {
2551
+ pendingFunctionCalls.splice(pendingIndex, 1);
2552
+ } else if (pendingFunctionCalls.length > 0) {
2553
+ pendingFunctionCalls.shift();
2554
+ }
2593
2555
  const output = messageText(content) || "{}";
2594
- contents.push({
2595
- role: "user",
2596
- parts: [{ functionResponse: { name, response: { output } } }]
2597
- });
2556
+ pushOrMergeContent("user", [
2557
+ { functionResponse: { name, response: { output } } }
2558
+ ]);
2598
2559
  }
2599
2560
  }
2561
+ flushPendingFunctionCalls();
2600
2562
  return { contents, systemTexts };
2601
2563
  }
2602
2564
  function convertOpenAiTools(tools) {
@@ -9121,6 +9083,30 @@ function createOAuthApiKeyRefResolver(options = {}) {
9121
9083
  };
9122
9084
  }
9123
9085
 
9086
+ // packages/cli/client/hybridRecordStore.ts
9087
+ function resolveFallbackServers(env) {
9088
+ const values = [
9089
+ env.NOLO_SERVER_URL,
9090
+ env.BASE_URL,
9091
+ ...NOLO_CLUSTER_SERVERS
9092
+ ].filter((value) => typeof value === "string" && value.trim().length > 0);
9093
+ return [...new Set(values.map(normalizeServerOrigin))];
9094
+ }
9095
+ function resolveAuthToken(env) {
9096
+ return resolvePlatformAuthToken(env);
9097
+ }
9098
+ function createCliHybridRecordStore(deps) {
9099
+ return createHybridRecordStore({
9100
+ db: deps.db,
9101
+ defaultServer: normalizeServerOrigin(
9102
+ deps.env.NOLO_SERVER || deps.env.BASE_URL || DEFAULT_NOLO_SERVER_URL
9103
+ ),
9104
+ fallbackServers: resolveFallbackServers(deps.env),
9105
+ authToken: resolveAuthToken(deps.env),
9106
+ fetchImpl: deps.fetchImpl
9107
+ });
9108
+ }
9109
+
9124
9110
  // packages/agent-runtime/dialogTitleLlm.ts
9125
9111
  async function generateLocalDialogTitle(input) {
9126
9112
  const { env, messages, fallbackTitle } = input;
@@ -9189,73 +9175,315 @@ function safeParseJson(raw) {
9189
9175
  }
9190
9176
  }
9191
9177
 
9192
- // packages/cli/client/hybridRecordStore.ts
9193
- function resolveFallbackServers(env) {
9194
- const values = [
9195
- env.NOLO_SERVER_URL,
9196
- env.BASE_URL,
9197
- ...NOLO_CLUSTER_SERVERS
9198
- ].filter((value) => typeof value === "string" && value.trim().length > 0);
9199
- return [...new Set(values.map(normalizeServerOrigin))];
9200
- }
9201
- function resolveAuthToken(env) {
9202
- return env.AUTH_TOKEN || env.AUTH || env.BENCHMARK_AUTH_TOKEN || "";
9203
- }
9204
- function createCliHybridRecordStore(deps) {
9205
- return createHybridRecordStore({
9206
- db: deps.db,
9207
- defaultServer: normalizeServerOrigin(
9208
- deps.env.NOLO_SERVER || deps.env.BASE_URL || DEFAULT_NOLO_SERVER_URL
9209
- ),
9210
- fallbackServers: resolveFallbackServers(deps.env),
9211
- authToken: resolveAuthToken(deps.env),
9178
+ // packages/cli/client/localRuntimeDialog.ts
9179
+ async function resolveStore(deps) {
9180
+ if (deps.store) return deps.store;
9181
+ return createCliHybridRecordStore({
9182
+ db: deps.db ?? await defaultLocalRuntimeDb(),
9183
+ env: deps.env,
9212
9184
  fetchImpl: deps.fetchImpl
9213
9185
  });
9214
9186
  }
9215
-
9216
- // packages/cli/client/localRuntimeAdapter.ts
9217
- import { ulid } from "ulid";
9218
- var resolveRuntimeAuthToken2 = resolveRuntimeAuthToken;
9219
- var currentMetaFile = fileURLToPath(import.meta.url);
9220
- var isJsBundle = extname(currentMetaFile) === ".js";
9221
- var SOURCE_CLI_DIR = isJsBundle ? dirname(currentMetaFile) : dirname(dirname(currentMetaFile));
9222
- var CLI_DIR = isCompiledBinary() ? dirname(process.execPath) : SOURCE_CLI_DIR;
9223
- var CLI_ENTRYPOINT = isCompiledBinary() ? process.execPath : isJsBundle ? currentMetaFile : join(SOURCE_CLI_DIR, "index.ts");
9224
- var preparedAgentRuntimeCache = /* @__PURE__ */ new Map();
9225
- var hybridStoreCache = /* @__PURE__ */ new Map();
9226
- function normalizeRuntimeCacheCwd(cwd) {
9227
- return (cwd?.trim() || process.cwd()).replace(/\/+$/, "") || ".";
9228
- }
9229
- function buildPreparedAgentCacheKey(args) {
9230
- const systemBuiltinSkillsKey = args.systemBuiltinSkills ? JSON.stringify(
9231
- Object.keys(args.systemBuiltinSkills).sort().map((key) => [key, args.systemBuiltinSkills?.[key]])
9232
- ) : "default";
9233
- return `${args.userId}\0${args.agentRef}\0${args.cwd}\0${systemBuiltinSkillsKey}`;
9234
- }
9235
- function clearCliLocalRuntimePreparedAgentCache() {
9236
- preparedAgentRuntimeCache.clear();
9237
- hybridStoreCache.clear();
9187
+ async function getOrCreateSharedStore(deps) {
9188
+ if (deps.store) return deps.store;
9189
+ const cacheKey = normalizeRuntimeCacheCwd(deps.cwd);
9190
+ let storePromise = hybridStoreCache.get(cacheKey);
9191
+ if (!storePromise) {
9192
+ storePromise = resolveStore(deps);
9193
+ hybridStoreCache.set(cacheKey, storePromise);
9194
+ }
9195
+ return storePromise;
9238
9196
  }
9239
- async function defaultLocalRuntimeDb() {
9240
- return getDefaultCliLocalRuntimeDb();
9241
- }
9242
- function createFallbackId() {
9243
- return ulid();
9197
+ function createLocalDialogTitleGenerator(deps, ctx) {
9198
+ return async (input) => {
9199
+ if (!canUsePlatformChatProvider(deps.env)) {
9200
+ return null;
9201
+ }
9202
+ const result = await generateLocalDialogTitle({
9203
+ messages: input.messages,
9204
+ env: deps.env,
9205
+ fetchImpl: async (url, init) => fetchWithTransientRetry(
9206
+ deps.fetchImpl ?? fetch,
9207
+ url,
9208
+ init,
9209
+ {
9210
+ sleep: deps.sleep,
9211
+ loopbackRequest: ctx.loopbackRequest
9212
+ }
9213
+ ),
9214
+ resolveProviderConfig: async (args) => resolvePlatformChatProviderConfig({
9215
+ agentConfig: args.agentConfig,
9216
+ env: args.env,
9217
+ apiKeyRefResolver: ctx.apiKeyRefResolver,
9218
+ credentialBroker: ctx.credentialBroker
9219
+ }),
9220
+ buildRequest: (args) => buildPlatformChatCompletionRequest({
9221
+ providerConfig: args.providerConfig,
9222
+ messages: args.messages,
9223
+ stream: false
9224
+ }),
9225
+ parseResponse: (args) => parsePlatformChatCompletionResponse({
9226
+ providerConfig: args.providerConfig,
9227
+ data: args.data,
9228
+ trace: []
9229
+ }),
9230
+ fallbackTitle: input.fallbackTitle,
9231
+ timeoutMs: 15e3
9232
+ });
9233
+ return result.source === "llm" ? result.title : null;
9234
+ };
9244
9235
  }
9245
- function logLocalRuntimeDiagnostic(event, fields) {
9246
- if (process.env.NOLO_LOCAL_RUNTIME_DEBUG !== "1" && process.env.NOLO_DEBUG !== "1") {
9236
+ async function writeLocalTokenRecord(args) {
9237
+ const rawUsage = args.input.result.usage;
9238
+ if (!rawUsage || typeof rawUsage !== "object" || Object.keys(rawUsage).length === 0) {
9247
9239
  return;
9248
9240
  }
9249
- console.error(`[nolo-local-runtime] ${event} ${JSON.stringify(fields)}`);
9241
+ const timestamp = args.now();
9242
+ const prepared = prepareTokenUsageData({
9243
+ rawUsage,
9244
+ agentConfig: {
9245
+ model: args.input.result.model || "unknown",
9246
+ provider: args.input.result.provider,
9247
+ apiSource: "cli"
9248
+ },
9249
+ userId: args.userId,
9250
+ agentId: args.input.agentKey,
9251
+ dialogId: args.dialogId,
9252
+ timestamp,
9253
+ entry_path: "cli-local"
9254
+ });
9255
+ const recordKey = createTokenKey.record(args.userId, timestamp);
9256
+ const tokenRecord = {
9257
+ id: args.createId(),
9258
+ type: "token",
9259
+ ...prepared.tokenData
9260
+ };
9261
+ await args.store.write(recordKey, tokenRecord);
9250
9262
  }
9251
- function summarizeOpenAiToolNames(tools) {
9252
- return tools.reduce((acc, tool) => {
9253
- const fn = tool.function;
9254
- const name = fn && typeof fn === "object" && "name" in fn && typeof fn.name === "string" ? fn.name : null;
9255
- if (name) acc.push(name);
9256
- return acc;
9257
- }, []);
9263
+ async function writeDialog(args) {
9264
+ let existingDialog = null;
9265
+ if (args.input.continueDialogId) {
9266
+ const dialogKey = `dialog-${args.userId}-${args.input.continueDialogId}`;
9267
+ existingDialog = await args.store.read(dialogKey);
9268
+ }
9269
+ const authToken = resolveRuntimeAuthToken(args.env);
9270
+ const isLoggedIn = Boolean(
9271
+ authToken && (parseUserIdFromAuthToken(authToken) || args.env.NOLO_MACHINE_API_KEY?.trim())
9272
+ );
9273
+ const hasExistingTitle = typeof existingDialog?.title === "string" && existingDialog.title.trim();
9274
+ let titleOverride;
9275
+ if (isLoggedIn && !hasExistingTitle && args.titleGenerator) {
9276
+ const fallbackTitle = extractLastUserText(args.input.messages).trim().slice(0, 80) || "Local agent run";
9277
+ try {
9278
+ const generated = await args.titleGenerator({
9279
+ messages: args.input.messages,
9280
+ fallbackTitle
9281
+ });
9282
+ if (generated) {
9283
+ titleOverride = generated;
9284
+ }
9285
+ } catch {
9286
+ }
9287
+ }
9288
+ const plan = buildLocalDialogWritePlan({
9289
+ input: args.input,
9290
+ userId: args.userId,
9291
+ now: args.now(),
9292
+ createId: args.createId,
9293
+ existingDialog,
9294
+ cwd: args.cwd,
9295
+ ...titleOverride ? { titleOverride } : {}
9296
+ });
9297
+ await args.store.batch(plan.ops);
9298
+ try {
9299
+ await writeLocalTokenRecord({
9300
+ store: args.store,
9301
+ input: args.input,
9302
+ userId: args.userId,
9303
+ dialogId: plan.dialogId,
9304
+ now: args.now,
9305
+ createId: args.createId,
9306
+ output: args.output
9307
+ });
9308
+ } catch (error) {
9309
+ args.output?.write(
9310
+ `[nolo] Token usage record write failed (non-fatal): ${toErrorMessage(error)}
9311
+ `
9312
+ );
9313
+ }
9314
+ const hasSubjectRefs = localTurnHasSubjectRefs(args.input);
9315
+ const isLocalUser = args.userId === "local";
9316
+ if (!isLocalUser) {
9317
+ try {
9318
+ const syncResult = await syncLocalDialogEvidenceToRemote({
9319
+ env: args.env,
9320
+ fetchImpl: args.fetchImpl,
9321
+ input: args.input,
9322
+ ops: plan.ops,
9323
+ output: args.output,
9324
+ userId: args.userId
9325
+ });
9326
+ if (!syncResult.attempted) {
9327
+ if (hasSubjectRefs) {
9328
+ args.output?.write(
9329
+ "[nolo] Local dialog evidence is local-only; set NOLO_SERVER and AUTH_TOKEN to make subjectRefs remotely queryable.\n"
9330
+ );
9331
+ }
9332
+ }
9333
+ } catch (error) {
9334
+ if (hasSubjectRefs) {
9335
+ throw error;
9336
+ }
9337
+ args.output?.write(
9338
+ `[nolo] Remote dialog evidence sync failed; local dialog only: ${toErrorMessage(
9339
+ error
9340
+ )}
9341
+ `
9342
+ );
9343
+ }
9344
+ }
9345
+ return { dialogId: plan.dialogId, title: plan.title };
9346
+ }
9347
+ function resolveCliDialogRecordKey(userId, dialogId) {
9348
+ if (dialogId.startsWith("dialog-") && !dialogId.includes("-msg-")) {
9349
+ return dialogId;
9350
+ }
9351
+ return `dialog-${userId}-${dialogId}`;
9352
+ }
9353
+ async function loadCliDialogSummary(args) {
9354
+ const dialogKey = resolveCliDialogRecordKey(args.userId, args.dialogId);
9355
+ const record = await args.store.read(dialogKey);
9356
+ if (!record || typeof record !== "object") return null;
9357
+ const summary = typeof record.summary === "string" ? record.summary.trim() : "";
9358
+ if (!summary) return null;
9359
+ const summarizedBeforeId = record.summarizedBeforeId;
9360
+ return {
9361
+ summary,
9362
+ ...typeof summarizedBeforeId === "string" && summarizedBeforeId ? { summarizedBeforeId } : {}
9363
+ };
9364
+ }
9365
+ async function saveCliDialogSummary(args) {
9366
+ const dialogKey = resolveCliDialogRecordKey(args.userId, args.dialogId);
9367
+ const existing = await args.store.read(dialogKey) ?? {};
9368
+ const bareId = typeof existing.id === "string" && existing.id ? existing.id : args.dialogId.startsWith("dialog-") ? args.dialogId.slice(args.dialogId.lastIndexOf("-") + 1) : args.dialogId;
9369
+ const compressionCount = typeof existing.compressionCount === "number" ? existing.compressionCount + 1 : 1;
9370
+ await args.store.write(dialogKey, {
9371
+ ...existing,
9372
+ id: bareId,
9373
+ dbKey: dialogKey,
9374
+ type: "dialog",
9375
+ userId: args.userId,
9376
+ summary: args.summary,
9377
+ ...args.summarizedBeforeId !== void 0 ? { summarizedBeforeId: args.summarizedBeforeId } : {},
9378
+ compressionCount,
9379
+ summaryPending: false,
9380
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
9381
+ });
9258
9382
  }
9383
+
9384
+ // packages/cli/client/cliWorkspaceToolVariants.ts
9385
+ function shouldUseDeclaredOnlyLocalWorkspaceTools(env) {
9386
+ const value = env.NOLO_LOCAL_WORKSPACE_TOOLSET || env.NOLO_LOCAL_TOOLSET_MODE || "";
9387
+ return value === "declared-only" || value === "declared";
9388
+ }
9389
+ function resolveGlobFilesDescriptionVariant(env) {
9390
+ return resolveLocalWorkspaceDescriptionVariant(
9391
+ env.NOLO_GLOBFILES_DESCRIPTION_VARIANT
9392
+ );
9393
+ }
9394
+ function resolveListFilesDescriptionVariant(env) {
9395
+ return resolveLocalWorkspaceDescriptionVariant(
9396
+ env.NOLO_LISTFILES_DESCRIPTION_VARIANT
9397
+ );
9398
+ }
9399
+ function resolveListFilesParameterVariant(env) {
9400
+ return resolveLocalWorkspaceParameterVariant(
9401
+ env.NOLO_LISTFILES_PARAMETER_VARIANT
9402
+ );
9403
+ }
9404
+ function resolveReadFileDescriptionVariant(env) {
9405
+ return resolveLocalWorkspaceDescriptionVariant(
9406
+ env.NOLO_READFILE_DESCRIPTION_VARIANT
9407
+ );
9408
+ }
9409
+ function resolveReadFileParameterVariant(env) {
9410
+ return resolveLocalWorkspaceParameterVariant(
9411
+ env.NOLO_READFILE_PARAMETER_VARIANT
9412
+ );
9413
+ }
9414
+ function resolveGlobFilesParameterVariant(env) {
9415
+ return resolveLocalWorkspaceParameterVariant(
9416
+ env.NOLO_GLOBFILES_PARAMETER_VARIANT
9417
+ );
9418
+ }
9419
+ function resolveSearchFilesDescriptionVariant(env) {
9420
+ return resolveLocalWorkspaceDescriptionVariant(
9421
+ env.NOLO_SEARCHFILES_DESCRIPTION_VARIANT
9422
+ );
9423
+ }
9424
+ function resolveSearchFilesParameterVariant(env) {
9425
+ return resolveLocalWorkspaceParameterVariant(
9426
+ env.NOLO_SEARCHFILES_PARAMETER_VARIANT
9427
+ );
9428
+ }
9429
+ function resolveLocalWorkspaceDescriptionVariant(value) {
9430
+ return value === "brief" || value === "strategy" || value === "workflow" || value === "antiShell" ? value : "strategy";
9431
+ }
9432
+ function resolveLocalWorkspaceParameterVariant(value) {
9433
+ return value === "minimal" || value === "scoped" || value === "rich" ? value : "rich";
9434
+ }
9435
+
9436
+ // packages/cli/client/cliChildDialogPersist.ts
9437
+ async function persistCliPendingChildDialog(args) {
9438
+ const nowIso = new Date(args.now).toISOString();
9439
+ const dialogKey = `dialog-${args.userId}-${args.dialogId}`;
9440
+ const record = {
9441
+ id: args.dialogId,
9442
+ dbKey: dialogKey,
9443
+ type: "dialog",
9444
+ userId: args.userId,
9445
+ cybots: [args.agentKey],
9446
+ primaryAgentKey: args.agentKey,
9447
+ title: args.title.slice(0, 80),
9448
+ status: "pending",
9449
+ triggerType: "cli-local",
9450
+ executionMode: args.background ? "background" : "foreground",
9451
+ createdAt: nowIso,
9452
+ updatedAt: nowIso,
9453
+ ...args.spaceId ? { spaceId: args.spaceId } : {},
9454
+ ...args.parentDialogId ? { parentDialogId: args.parentDialogId } : {},
9455
+ ...args.rootDialogId ? { rootDialogId: args.rootDialogId } : {},
9456
+ localRuntime: {
9457
+ host: "cli",
9458
+ workspaceRoot: args.workspaceRoot,
9459
+ workspaceKind: "current",
9460
+ workspaceAccess: "inherited"
9461
+ }
9462
+ };
9463
+ await args.store.batch([{ type: "put", key: dialogKey, value: record }]);
9464
+ }
9465
+ async function persistCliFailedChildDialog(args) {
9466
+ const dialogKey = `dialog-${args.userId}-${args.dialogId}`;
9467
+ const existing = await args.store.read(dialogKey);
9468
+ const existingRecord = existing && typeof existing === "object" ? existing : {};
9469
+ await args.store.batch([
9470
+ {
9471
+ type: "put",
9472
+ key: dialogKey,
9473
+ value: {
9474
+ ...existingRecord,
9475
+ id: args.dialogId,
9476
+ dbKey: dialogKey,
9477
+ status: "failed",
9478
+ errorMessage: args.errorMessage,
9479
+ updatedAt: new Date(args.now).toISOString(),
9480
+ finishedAt: args.now
9481
+ }
9482
+ }
9483
+ ]);
9484
+ }
9485
+
9486
+ // packages/cli/client/localRuntimeTools.ts
9259
9487
  function buildOpenAiTools(args) {
9260
9488
  const toolset = buildLocalWorkspaceToolsetForEnv(args);
9261
9489
  const toolNameSet = new Set(args.toolNames ?? []);
@@ -9312,19 +9540,19 @@ function buildOpenAiTools(args) {
9312
9540
  }),
9313
9541
  ...buildServerPlatformOpenAiTools({ toolNames: args.toolNames }),
9314
9542
  ...buildNoloWorkspaceOpenAiTools({ toolNames: args.toolNames }),
9315
- // startAgentRun/controlAgentRun:CLI 本地 --bg 执行器已就绪(MED-1 修复,
9316
- // cliAgentRunToolExecutors),只要 agent 声明(agent-orchestration 包展开)
9317
- // 就注入 schema。
9318
9543
  ...prepareTools(
9319
9544
  ["startAgentRun", "controlAgentRun"].filter((name) => toolNameSet.has(name))
9320
9545
  )
9321
9546
  ];
9322
9547
  }
9323
9548
  var CLI_DEFAULT_TOOLS = ["exa_search", "fetchWebpage"];
9324
- function addDefaultCliCoreTools(toolNames, env) {
9549
+ function addDefaultCliCoreTools(toolNames, env, options) {
9325
9550
  const declaredOnly = env && shouldUseDeclaredOnlyLocalWorkspaceTools(env);
9326
- const injected = declaredOnly ? [...FORCED_TOOLS] : [...FORCED_TOOLS, ...CLI_DEFAULT_TOOLS];
9327
- return [.../* @__PURE__ */ new Set([...toolNames, ...injected])];
9551
+ const forcedTools = options?.hasUserChoice === true ? FORCED_TOOLS : FORCED_TOOLS.filter((name) => name !== "ui_ask_choice");
9552
+ const injected = declaredOnly ? [...forcedTools] : [...forcedTools, ...CLI_DEFAULT_TOOLS];
9553
+ const combined = [...toolNames, ...injected];
9554
+ const filtered = options?.hasUserChoice === true ? combined : combined.filter((name) => name !== "ui_ask_choice");
9555
+ return [...new Set(filtered)];
9328
9556
  }
9329
9557
  function resolveCliEffectiveEnabledPacks(args) {
9330
9558
  return resolveEffectiveEnabledPacks({
@@ -9349,16 +9577,12 @@ function withRuntimeEnabledPacksAndPrompt(config) {
9349
9577
  ...prompt ? { prompt } : {}
9350
9578
  };
9351
9579
  }
9352
- function resolveCliRequestedToolNames(agentConfig, env, systemBuiltinSkills) {
9580
+ function resolveCliRequestedToolNames(agentConfig, env, systemBuiltinSkills, options) {
9353
9581
  const declaredOnly = shouldUseDeclaredOnlyLocalWorkspaceTools(env);
9354
9582
  const expanded = addDefaultLightWebToolsForConfiguredAgents(
9355
9583
  addDefaultCliCoreTools(
9356
9584
  canonicalizeToolNames(
9357
9585
  expandEnabledPacks(
9358
- // CLI 端默认开 code 能力包:enabledPacks 为空时补 ["code"],保持
9359
- // 「CLI agent 默认能改代码」的体感,但走显式能力包而非隐式兜底
9360
- // (DEFAULT_LOCAL_CODING_TOOL_NAMES 已删除)。
9361
- // declared-only 模式下不补——用户显式要 ablation。
9362
9586
  resolveCliEffectiveEnabledPacks({
9363
9587
  enabledPacks: agentConfig?.enabledPacks,
9364
9588
  declaredOnly
@@ -9366,20 +9590,28 @@ function resolveCliRequestedToolNames(agentConfig, env, systemBuiltinSkills) {
9366
9590
  resolveRequestedRuntimeToolNames({ agentConfig })
9367
9591
  )
9368
9592
  ),
9369
- env
9593
+ env,
9594
+ options
9370
9595
  ),
9371
9596
  agentConfig
9372
9597
  );
9373
- const filtered = applySystemBuiltinSkillFilter(expanded, systemBuiltinSkills);
9598
+ const filtered = applySystemBuiltinSkillFilter(
9599
+ // Default-on system capabilities (agent-orchestration) are mounted for
9600
+ // every non-declared-only agent before the global filter runs, so the
9601
+ // user's global "off" still wins. declared-only (ablation) runs keep
9602
+ // their strict surface.
9603
+ declaredOnly ? expanded : addDefaultSystemCapabilityTools(expanded),
9604
+ systemBuiltinSkills
9605
+ );
9374
9606
  return applyDisabledTools(
9375
9607
  filtered,
9376
9608
  agentConfig?.disabledTools
9377
9609
  );
9378
9610
  }
9379
- function resolveProviderOpenAiToolBundle(agentConfig, env, buildTools = buildOpenAiTools, additionalToolNames = []) {
9611
+ function resolveProviderOpenAiToolBundle(agentConfig, env, buildTools = buildOpenAiTools, additionalToolNames = [], options) {
9380
9612
  const requestedToolNames = [
9381
9613
  .../* @__PURE__ */ new Set([
9382
- ...resolveCliRequestedToolNames(agentConfig, env),
9614
+ ...resolveCliRequestedToolNames(agentConfig, env, null, options),
9383
9615
  ...additionalToolNames
9384
9616
  ])
9385
9617
  ];
@@ -9401,18 +9633,16 @@ function buildLocalWorkspaceToolsetForEnv(args) {
9401
9633
  return toolset;
9402
9634
  }
9403
9635
  function buildLocalPolicyToolNames(args) {
9404
- const buildTools = args.buildTools ?? buildOpenAiTools;
9405
- return [
9406
- ...new Set(
9407
- summarizeOpenAiToolNames(
9408
- buildTools({
9409
- agentKey: args.agentKey,
9410
- toolNames: args.toolNames,
9411
- env: args.env
9412
- })
9413
- )
9414
- )
9415
- ];
9636
+ const schemaBuilder = args.buildProviderOpenAiTools ?? buildOpenAiTools;
9637
+ const tools = schemaBuilder({
9638
+ agentKey: args.agentKey,
9639
+ toolNames: args.toolNames,
9640
+ env: args.env
9641
+ });
9642
+ const policyNames = summarizeOpenAiToolNames(
9643
+ tools
9644
+ );
9645
+ return [...new Set(policyNames)];
9416
9646
  }
9417
9647
  function buildServerPlatformOpenAiTools(args) {
9418
9648
  const toolNameSet = new Set(args.toolNames ?? []);
@@ -9610,208 +9840,13 @@ function createCliCallAgentToolExecutor(deps, ctx) {
9610
9840
  }
9611
9841
  };
9612
9842
  }
9613
- async function resolveStore(deps) {
9614
- if (deps.store) return deps.store;
9615
- return createCliHybridRecordStore({
9616
- db: deps.db ?? await defaultLocalRuntimeDb(),
9617
- env: deps.env,
9618
- fetchImpl: deps.fetchImpl
9619
- });
9620
- }
9621
- async function getOrCreateSharedStore(deps) {
9622
- if (deps.store) return deps.store;
9623
- const cacheKey = normalizeRuntimeCacheCwd(deps.cwd);
9624
- let storePromise = hybridStoreCache.get(cacheKey);
9625
- if (!storePromise) {
9626
- storePromise = resolveStore(deps);
9627
- hybridStoreCache.set(cacheKey, storePromise);
9628
- }
9629
- return storePromise;
9630
- }
9631
- function createLocalDialogTitleGenerator(deps, ctx) {
9632
- return async (input) => {
9633
- if (!canUsePlatformChatProvider(deps.env)) {
9634
- return null;
9635
- }
9636
- const result = await generateLocalDialogTitle({
9637
- messages: input.messages,
9638
- env: deps.env,
9639
- fetchImpl: async (url, init) => fetchWithTransientRetry(
9640
- deps.fetchImpl ?? fetch,
9641
- url,
9642
- init,
9643
- {
9644
- sleep: deps.sleep,
9645
- loopbackRequest: ctx.loopbackRequest
9646
- }
9647
- ),
9648
- resolveProviderConfig: async (args) => resolvePlatformChatProviderConfig({
9649
- agentConfig: args.agentConfig,
9650
- env: args.env,
9651
- apiKeyRefResolver: ctx.apiKeyRefResolver,
9652
- credentialBroker: ctx.credentialBroker
9653
- }),
9654
- buildRequest: (args) => buildPlatformChatCompletionRequest({
9655
- providerConfig: args.providerConfig,
9656
- messages: args.messages,
9657
- stream: false
9658
- }),
9659
- parseResponse: (args) => parsePlatformChatCompletionResponse({
9660
- providerConfig: args.providerConfig,
9661
- data: args.data,
9662
- trace: []
9663
- }),
9664
- fallbackTitle: input.fallbackTitle,
9665
- timeoutMs: 15e3
9666
- });
9667
- return result.source === "llm" ? result.title : null;
9668
- };
9669
- }
9670
- async function writeLocalTokenRecord(args) {
9671
- const rawUsage = args.input.result.usage;
9672
- if (!rawUsage || typeof rawUsage !== "object" || Object.keys(rawUsage).length === 0) {
9673
- return;
9674
- }
9675
- const timestamp = args.now();
9676
- const prepared = prepareTokenUsageData({
9677
- rawUsage,
9678
- agentConfig: {
9679
- model: args.input.result.model || "unknown",
9680
- provider: args.input.result.provider,
9681
- apiSource: "cli"
9682
- },
9683
- userId: args.userId,
9684
- agentId: args.input.agentKey,
9685
- dialogId: args.dialogId,
9686
- timestamp,
9687
- entry_path: "cli-local"
9688
- });
9689
- const recordKey = createTokenKey.record(args.userId, timestamp);
9690
- const tokenRecord = {
9691
- id: args.createId(),
9692
- type: "token",
9693
- ...prepared.tokenData
9694
- };
9695
- await args.store.write(recordKey, tokenRecord);
9696
- }
9697
- async function writeDialog(args) {
9698
- let existingDialog = null;
9699
- if (args.input.continueDialogId) {
9700
- const dialogKey = `dialog-${args.userId}-${args.input.continueDialogId}`;
9701
- existingDialog = await args.store.read(dialogKey);
9702
- }
9703
- const authToken = resolveRuntimeAuthToken2(args.env);
9704
- const isLoggedIn = Boolean(authToken && parseUserIdFromAuthToken(authToken));
9705
- const hasExistingTitle = typeof existingDialog?.title === "string" && existingDialog.title.trim();
9706
- let titleOverride;
9707
- if (isLoggedIn && !hasExistingTitle && args.titleGenerator) {
9708
- const fallbackTitle = extractLastUserText(args.input.messages).trim().slice(0, 80) || "Local agent run";
9709
- try {
9710
- const generated = await args.titleGenerator({
9711
- messages: args.input.messages,
9712
- fallbackTitle
9713
- });
9714
- if (generated) {
9715
- titleOverride = generated;
9716
- }
9717
- } catch {
9718
- }
9719
- }
9720
- const plan = buildLocalDialogWritePlan({
9721
- input: args.input,
9722
- userId: args.userId,
9723
- now: args.now(),
9724
- createId: args.createId,
9725
- existingDialog,
9726
- cwd: args.cwd,
9727
- ...titleOverride ? { titleOverride } : {}
9728
- });
9729
- await args.store.batch(plan.ops);
9730
- try {
9731
- await writeLocalTokenRecord({
9732
- store: args.store,
9733
- input: args.input,
9734
- userId: args.userId,
9735
- dialogId: plan.dialogId,
9736
- now: args.now,
9737
- createId: args.createId,
9738
- output: args.output
9739
- });
9740
- } catch (error) {
9741
- args.output?.write(
9742
- `[nolo] Token usage record write failed (non-fatal): ${toErrorMessage(error)}
9743
- `
9744
- );
9745
- }
9746
- const hasSubjectRefs = localTurnHasSubjectRefs(args.input);
9747
- const isLocalUser = args.userId === "local";
9748
- if (!isLocalUser) {
9749
- try {
9750
- const syncResult = await syncLocalDialogEvidenceToRemote({
9751
- env: args.env,
9752
- fetchImpl: args.fetchImpl,
9753
- input: args.input,
9754
- ops: plan.ops,
9755
- output: args.output,
9756
- userId: args.userId
9757
- });
9758
- if (!syncResult.attempted) {
9759
- if (hasSubjectRefs) {
9760
- args.output?.write(
9761
- "[nolo] Local dialog evidence is local-only; set NOLO_SERVER and AUTH_TOKEN to make subjectRefs remotely queryable.\n"
9762
- );
9763
- }
9764
- }
9765
- } catch (error) {
9766
- if (hasSubjectRefs) {
9767
- throw error;
9768
- }
9769
- args.output?.write(
9770
- `[nolo] Remote dialog evidence sync failed; local dialog only: ${toErrorMessage(
9771
- error
9772
- )}
9773
- `
9774
- );
9775
- }
9776
- }
9777
- return { dialogId: plan.dialogId };
9778
- }
9779
- function resolveCliDialogRecordKey(userId, dialogId) {
9780
- if (dialogId.startsWith("dialog-") && !dialogId.includes("-msg-")) {
9781
- return dialogId;
9782
- }
9783
- return `dialog-${userId}-${dialogId}`;
9784
- }
9785
- async function loadCliDialogSummary(args) {
9786
- const dialogKey = resolveCliDialogRecordKey(args.userId, args.dialogId);
9787
- const record = await args.store.read(dialogKey);
9788
- if (!record || typeof record !== "object") return null;
9789
- const summary = typeof record.summary === "string" ? record.summary.trim() : "";
9790
- if (!summary) return null;
9791
- const summarizedBeforeId = record.summarizedBeforeId;
9792
- return {
9793
- summary,
9794
- ...typeof summarizedBeforeId === "string" && summarizedBeforeId ? { summarizedBeforeId } : {}
9795
- };
9796
- }
9797
- async function saveCliDialogSummary(args) {
9798
- const dialogKey = resolveCliDialogRecordKey(args.userId, args.dialogId);
9799
- const existing = await args.store.read(dialogKey) ?? {};
9800
- const bareId = typeof existing.id === "string" && existing.id ? existing.id : args.dialogId.startsWith("dialog-") ? args.dialogId.slice(args.dialogId.lastIndexOf("-") + 1) : args.dialogId;
9801
- const compressionCount = typeof existing.compressionCount === "number" ? existing.compressionCount + 1 : 1;
9802
- await args.store.write(dialogKey, {
9803
- ...existing,
9804
- id: bareId,
9805
- dbKey: dialogKey,
9806
- type: "dialog",
9807
- userId: args.userId,
9808
- summary: args.summary,
9809
- ...args.summarizedBeforeId !== void 0 ? { summarizedBeforeId: args.summarizedBeforeId } : {},
9810
- compressionCount,
9811
- summaryPending: false,
9812
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
9813
- });
9814
- }
9843
+
9844
+ // packages/cli/client/localRuntimeAdapter.ts
9845
+ var currentMetaFile = fileURLToPath(import.meta.url);
9846
+ var isJsBundle = extname(currentMetaFile) === ".js";
9847
+ var SOURCE_CLI_DIR = isJsBundle ? dirname(currentMetaFile) : dirname(dirname(currentMetaFile));
9848
+ var CLI_DIR = isCompiledBinary() ? dirname(process.execPath) : SOURCE_CLI_DIR;
9849
+ var CLI_ENTRYPOINT = isCompiledBinary() ? process.execPath : isJsBundle ? currentMetaFile : join(SOURCE_CLI_DIR, "index.ts");
9815
9850
  function createCliLocalRuntimeAdapter(deps) {
9816
9851
  const now = deps.now ?? Date.now;
9817
9852
  const createId = deps.createId ?? createFallbackId;
@@ -9883,7 +9918,13 @@ function createCliLocalRuntimeAdapter(deps) {
9883
9918
  deps.env
9884
9919
  );
9885
9920
  const agentConfig = baseAgentConfig ? withRuntimeEnabledPacksAndPrompt(baseAgentConfig) : baseAgentConfig;
9886
- const requestedToolNames = agentConfig ? resolveCliRequestedToolNames(agentConfig, deps.env, systemBuiltinSkills) : [];
9921
+ const hasUserChoice = Boolean(deps.requestUserChoice);
9922
+ const requestedToolNames = agentConfig ? resolveCliRequestedToolNames(
9923
+ agentConfig,
9924
+ deps.env,
9925
+ systemBuiltinSkills,
9926
+ { hasUserChoice }
9927
+ ) : [];
9887
9928
  activeAgentToolNames = buildLocalPolicyToolNames({
9888
9929
  agentKey: agentConfig?.key,
9889
9930
  toolNames: [...requestedToolNames, ...additionalToolNames],
@@ -10013,7 +10054,8 @@ function createCliLocalRuntimeAdapter(deps) {
10013
10054
  agentConfig,
10014
10055
  deps.env,
10015
10056
  buildProviderOpenAiTools,
10016
- additionalToolNames
10057
+ additionalToolNames,
10058
+ { hasUserChoice: Boolean(deps.requestUserChoice) }
10017
10059
  );
10018
10060
  logLocalRuntimeDiagnostic("provider.selected", {
10019
10061
  agentKey: agentConfig.key,
@@ -10094,7 +10136,8 @@ function createCliLocalRuntimeAdapter(deps) {
10094
10136
  agentConfig,
10095
10137
  deps.env,
10096
10138
  buildProviderOpenAiTools,
10097
- additionalToolNames
10139
+ additionalToolNames,
10140
+ { hasUserChoice: Boolean(deps.requestUserChoice) }
10098
10141
  );
10099
10142
  logLocalRuntimeDiagnostic("provider.selected", {
10100
10143
  agentKey: agentConfig.key,
@@ -10160,7 +10203,8 @@ function createCliLocalRuntimeAdapter(deps) {
10160
10203
  agentConfig,
10161
10204
  deps.env,
10162
10205
  buildProviderOpenAiTools,
10163
- additionalToolNames
10206
+ additionalToolNames,
10207
+ { hasUserChoice: Boolean(deps.requestUserChoice) }
10164
10208
  );
10165
10209
  logLocalRuntimeDiagnostic("provider.selected", {
10166
10210
  agentKey: agentConfig.key,
@@ -10243,7 +10287,8 @@ function createCliLocalRuntimeAdapter(deps) {
10243
10287
  agentConfig,
10244
10288
  deps.env,
10245
10289
  buildProviderOpenAiTools,
10246
- additionalToolNames
10290
+ additionalToolNames,
10291
+ { hasUserChoice: Boolean(deps.requestUserChoice) }
10247
10292
  );
10248
10293
  return {
10249
10294
  model: providerConfig2.model,
@@ -10399,7 +10444,8 @@ function createCliLocalRuntimeAdapter(deps) {
10399
10444
  agentConfig,
10400
10445
  deps.env,
10401
10446
  buildProviderOpenAiTools,
10402
- additionalToolNames
10447
+ additionalToolNames,
10448
+ { hasUserChoice: Boolean(deps.requestUserChoice) }
10403
10449
  );
10404
10450
  return {
10405
10451
  model: providerConfig.model,