nolo-cli 0.14.0-alpha.9 → 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 (92) hide show
  1. package/{_executeModel-OQ6KPFSB.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-UBXH2FDO.js → agentDeleteCommand-QDO62EZA.js} +20 -20
  6. package/{agentEmailCommands-ZI2FIUBV.js → agentEmailCommands-UZ5BKX3P.js} +37 -37
  7. package/{agentListCommands-7M6FHCSH.js → agentListCommands-ZC33UDWT.js} +22 -22
  8. package/{agentMachineCommands-R3FW62QH.js → agentMachineCommands-RZGZEZRL.js} +20 -20
  9. package/{agentRecordCommands-WUY3C3HZ.js → agentRecordCommands-DGDXE2VH.js} +32 -32
  10. package/{agentRunCommand-CWXYVYPZ.js → agentRunCommand-SRZWFOPH.js} +34 -34
  11. package/{agentRuntimeLocal-BONMVACL.js → agentRuntimeLocal-4YCF6IRF.js} +11 -11
  12. package/{agentSlice-IHOSTSWC.js → agentSlice-IVE735EV.js} +3 -3
  13. package/appDeleteCommands-7I26L64I.js +124 -0
  14. package/appDeployCommands-TZLZNTJN.js +163 -0
  15. package/appDeployStatusCommands-OPPTLHRW.js +144 -0
  16. package/appGetCommands-N2S4HYKY.js +119 -0
  17. package/appListCommands-OBTPPKUM.js +122 -0
  18. package/{authCommand-IKIU4FZY.js → authCommand-YFTR3347.js} +5 -5
  19. package/{authCommands-QP43ADV3.js → authCommands-YXGOXNBZ.js} +3 -3
  20. package/{chunk-3B2LFO6R.js → browser-image-compression-MFDTD7K6.js} +4 -518
  21. package/{chunk-YQAG2J2T.js → chunk-472E5RMQ.js} +1 -1
  22. package/chunk-4QQFLN5C.js +552 -0
  23. package/{chunk-SZ7RUWAQ.js → chunk-5VMYGIIL.js} +97 -38
  24. package/{chunk-P6DRYHVM.js → chunk-6565R2TI.js} +16 -14
  25. package/{chunk-2ROIXEDX.js → chunk-6MHDWKOT.js} +2 -2
  26. package/{chunk-GGHFCK3X.js → chunk-AWDOJBHW.js} +426 -430
  27. package/{chunk-DUE6E46E.js → chunk-BFRVXJJJ.js} +43 -16
  28. package/{chunk-UONU6Q4P.js → chunk-G2MKOQCB.js} +1 -1
  29. package/chunk-GFUIQ4RY.js +136 -0
  30. package/{chunk-SRKNB2WB.js → chunk-HRQCKQA5.js} +4 -4
  31. package/{chunk-CDQ2ICPR.js → chunk-IOQ7IBPU.js} +1 -1
  32. package/{chunk-QLO2G5HP.js → chunk-ISYE6GZB.js} +1 -1
  33. package/{chunk-CXLGUR7M.js → chunk-IZ2QRVEU.js} +2 -2
  34. package/{chunk-U4J6ZZFY.js → chunk-JBKVPAYK.js} +7 -140
  35. package/{chunk-V6VXDXGY.js → chunk-JS33TCQ3.js} +2 -2
  36. package/{chunk-YG3CCS7C.js → chunk-K53477EY.js} +4 -4
  37. package/{chunk-3WGLLTK4.js → chunk-LSFAWXKC.js} +100 -3
  38. package/{chunk-BHK5ZAW7.js → chunk-N5424GSW.js} +1 -1
  39. package/chunk-NTC6I2FN.js +107 -0
  40. package/{chunk-QNXEDF7V.js → chunk-O53CP2QR.js} +3 -3
  41. package/{chunk-CY4TAX6S.js → chunk-OKSYPTDZ.js} +9 -9
  42. package/{chunk-NFHGY5T5.js → chunk-OQMPU2ML.js} +4 -4
  43. package/{chunk-NSZB7BYV.js → chunk-P4MJQWWF.js} +2 -2
  44. package/{chunk-JHFMRUGX.js → chunk-RKM3K52F.js} +1 -1
  45. package/{chunk-A5V7UEZJ.js → chunk-SFXYKGK2.js} +3 -3
  46. package/{chunk-S5UACFUP.js → chunk-TTGAVETO.js} +10 -2
  47. package/{chunk-BOJVWKNA.js → chunk-U7LEGLEB.js} +1 -1
  48. package/{chunk-YDOTMXTK.js → chunk-UXKQQ2MR.js} +9 -9
  49. package/{chunk-KUDUXBNE.js → chunk-VE6XMVKG.js} +189 -41
  50. package/{chunk-NJVPXLRY.js → chunk-VPTJB4HM.js} +1 -1
  51. package/{chunk-3AE4NQ5O.js → chunk-WA6KZL5V.js} +25 -6
  52. package/{chunk-T3X232L6.js → chunk-WNLPAOIT.js} +1 -1
  53. package/{chunk-MEXNTURY.js → chunk-WRN5EQT7.js} +1 -1
  54. package/{chunk-FVGJNXPJ.js → chunk-XGQZFBO5.js} +83 -206
  55. package/{chunk-3FCSMQAC.js → chunk-XVP3C2KY.js} +1 -1
  56. package/{chunk-SW3Q2OV5.js → chunk-YNHQIXX5.js} +774 -5735
  57. package/{chunk-7VKJDLPO.js → chunk-Z24FGIU2.js} +2 -2
  58. package/{createAgentAutomationAction-W4OZQ63I.js → createAgentAutomationAction-TS6NNZ4X.js} +9 -9
  59. package/{createDialogAction-G6XQLPAN.js → createDialogAction-5HVQ33EX.js} +10 -10
  60. package/{createPageAction-RNT4LCAX.js → createPageAction-4F3ZGQJD.js} +9 -9
  61. package/{dbSlice-7Q23HSWH.js → dbSlice-OP6UPXKA.js} +2 -2
  62. package/{dialogCommands-YUTOCICO.js → dialogCommands-3GEPXHFB.js} +16 -16
  63. package/{dialogSlice-QZZF4JXD.js → dialogSlice-FAWUQDJW.js} +9 -9
  64. package/{docCreateCommands-LQYOVE7D.js → docCreateCommands-ZE3S6BCP.js} +22 -20
  65. package/{docDeleteCommands-LNS5V76K.js → docDeleteCommands-TW6PGTRT.js} +21 -19
  66. package/{docReadCommands-IRCP66BG.js → docReadCommands-LDXL3B6J.js} +20 -18
  67. package/{docStore-66Q4JTTG.js → docStore-2UHVWLTV.js} +10 -10
  68. package/{docUpdateCommands-4VUX3Q7W.js → docUpdateCommands-GYD6XI5O.js} +21 -19
  69. package/{handleSendMessageAction-CB5UKK2X.js → handleSendMessageAction-LJPUYNOH.js} +9 -9
  70. package/index.js +92 -61
  71. package/{machineCommands-PX2BADIB.js → machineCommands-OKNDYS3M.js} +35 -35
  72. package/{machineWsRunDispatch-IBNCRCEQ.js → machineWsRunDispatch-ZX5AJ6FJ.js} +31 -31
  73. package/package.json +1 -1
  74. package/{read-SIWMJRHC.js → read-HXHAZBKH.js} +1 -1
  75. package/{readDocTool-TCYJY4PP.js → readDocTool-VPBDTO4G.js} +1 -1
  76. package/{readlineWorkspace-YIXJ2OOO.js → readlineWorkspace-MB3ANKHM.js} +92 -92
  77. package/{removeDialogAgentAction-WKHZT6VJ.js → removeDialogAgentAction-HUFVN35S.js} +4 -4
  78. package/{runAgentClientLoop-BXMDAQB2.js → runAgentClientLoop-A75BUU6D.js} +19 -19
  79. package/{setDialogExtraReferencesAction-GCI5QU6E.js → setDialogExtraReferencesAction-2VLGWQKG.js} +2 -2
  80. package/{setPrimaryDialogAgentAction-NRO57AS6.js → setPrimaryDialogAgentAction-VB4UV2CC.js} +4 -4
  81. package/{settingSlice-FTWZ5ZHT.js → settingSlice-7JYPQNAC.js} +3 -3
  82. package/{spaceCommands-7Z6DZFEE.js → spaceCommands-O3KJNCON.js} +21 -21
  83. package/{spaceSlice-3GLIRD3Q.js → spaceSlice-444MFUP6.js} +9 -9
  84. package/{streamAgentChatTurn-SN7YS2VV.js → streamAgentChatTurn-DJAE7USZ.js} +42 -39
  85. package/{tools-4JSNWHIK.js → tools-YB6LXSVN.js} +14 -14
  86. package/{tuiSummaryLlmCaller-PS5BDLHV.js → tuiSummaryLlmCaller-QQL3JA5I.js} +3 -3
  87. package/{updateDialogTitleAction-DUJ2JZXX.js → updateDialogTitleAction-6HGFBM64.js} +9 -9
  88. package/{agentGrantCommands-JMTM6U4B.js → agentGrantCommands-JNDE4RWR.js} +1 -1
  89. package/{agentPullCommand-UXANSFU3.js → agentPullCommand-6HWUT3SW.js} +1 -1
  90. package/{chunk-3QAF2LTL.js → chunk-DZ3XJVET.js} +3 -3
  91. package/{chunk-HBRZXXP5.js → chunk-KMQPSTMJ.js} +6 -6
  92. package/{tableCommands-V5O7QMXY.js → tableCommands-3P7MJ3PF.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-CDQ2ICPR.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-MEXNTURY.js";
24
+ } from "./chunk-WRN5EQT7.js";
32
25
  import {
33
26
  getAntigravityUserAgent,
34
27
  isAntigravityOAuthAgent,
35
28
  readAntigravityProjectId,
36
29
  resolveAntigravityCloudCodeBaseUrl
37
- } from "./chunk-QLO2G5HP.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-KUDUXBNE.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-SW3Q2OV5.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-NFHGY5T5.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-SZ7RUWAQ.js";
81
+ } from "./chunk-5VMYGIIL.js";
88
82
  import {
89
83
  buildPlatformChatCompletionRequest,
90
84
  canUsePlatformChatProvider,
@@ -94,17 +88,17 @@ import {
94
88
  resolveLegacyDeepSeekProxyChatFallback,
95
89
  resolvePlatformChatProviderConfig,
96
90
  shouldUsePlatformChatProvider
97
- } from "./chunk-3AE4NQ5O.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-2ROIXEDX.js";
98
+ } from "./chunk-6MHDWKOT.js";
105
99
  import {
106
100
  resolvePlatformAuthToken
107
- } from "./chunk-SRKNB2WB.js";
101
+ } from "./chunk-HRQCKQA5.js";
108
102
  import {
109
103
  buildLoadSkillExecutor,
110
104
  buildNoloWorkspaceCliToolExecutors,
@@ -138,12 +132,26 @@ import {
138
132
  listRunRecords,
139
133
  spawnLocalBackgroundRun
140
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";
141
142
  import {
142
143
  toErrorMessage
143
144
  } from "./chunk-HNMXYYJR.js";
144
145
  import {
145
146
  getDefaultCliLocalRuntimeDb
146
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";
147
155
  import {
148
156
  asRecordOrEmpty
149
157
  } from "./chunk-KX6YBIHG.js";
@@ -165,20 +173,13 @@ import {
165
173
  PUBLIC_GLM_52_AGENT_KEY,
166
174
  PUBLIC_KIMI_K26_IMAGE_AGENT_KEY,
167
175
  PUBLIC_KIMI_K27_CODING_AGENT_KEY
168
- } from "./chunk-NJVPXLRY.js";
176
+ } from "./chunk-VPTJB4HM.js";
169
177
  import {
170
178
  asTrimmedString
171
179
  } from "./chunk-3EUW3WEO.js";
172
180
  import {
173
181
  isRecord
174
182
  } from "./chunk-KUG52IAP.js";
175
- import {
176
- isCompiledBinary,
177
- parseUserIdFromAuthToken
178
- } from "./chunk-A7GB5UGH.js";
179
- import {
180
- DEFAULT_NOLO_SERVER_URL
181
- } from "./chunk-OLZBQWZU.js";
182
183
  import {
183
184
  NOLO_CLUSTER_SERVERS
184
185
  } from "./chunk-LCBAMY2M.js";
@@ -294,6 +295,10 @@ var STRINGS = {
294
295
  en: "Agent switch cancelled.",
295
296
  zh: "\u5DF2\u53D6\u6D88\u5207\u6362 agent\u3002"
296
297
  },
298
+ agentPickerLoading: {
299
+ en: "Loading agents\u2026",
300
+ zh: "\u6B63\u5728\u52A0\u8F7D agent \u5217\u8868\u2026"
301
+ },
297
302
  historyPickerTitle: {
298
303
  en: "Resume dialog (\u2191\u2193 Enter Esc)",
299
304
  zh: "\u6062\u590D\u5BF9\u8BDD\uFF08\u2191\u2193 \u79FB\u52A8 \xB7 Enter \u9009\u62E9 \xB7 Esc \u53D6\u6D88\uFF09"
@@ -613,10 +618,6 @@ var STRINGS = {
613
618
  en: "tools",
614
619
  zh: "\u5DE5\u5177"
615
620
  },
616
- contextFieldThinking: {
617
- en: "thinking",
618
- zh: "\u601D\u8003"
619
- },
620
621
  contextFieldServer: {
621
622
  en: "server",
622
623
  zh: "\u670D\u52A1\u7AEF"
@@ -654,7 +655,6 @@ var STRINGS = {
654
655
  " /context Show workspace context and next actions",
655
656
  " /runtime <mode> Use auto, local, or server runtime",
656
657
  " /tools <mode> Control tool trace: hide, compact, verbose",
657
- " /thinking <mode> Control thinking output: hide, marker, show",
658
658
  " /switch Pick an agent interactively (\u2191\u2193, Enter)",
659
659
  " /switch list List agents as text",
660
660
  " /switch <name> Switch directly by name, alias, or key (alias: /agent)",
@@ -691,7 +691,6 @@ var STRINGS = {
691
691
  " /context \u67E5\u770B\u5DE5\u4F5C\u533A\u4E0A\u4E0B\u6587\u4E0E\u540E\u7EED\u64CD\u4F5C",
692
692
  " /runtime <mode> \u5207\u6362 runtime\uFF1Aauto\u3001local\u3001server",
693
693
  " /tools <mode> \u5DE5\u5177\u8F68\u8FF9\u663E\u793A\uFF1Ahide\u3001compact\u3001verbose",
694
- " /thinking <mode> \u601D\u8003\u8FC7\u7A0B\u663E\u793A\uFF1Ahide\u3001marker\u3001show",
695
694
  " /switch \u4EA4\u4E92\u5F0F\u9009\u62E9 agent\uFF08\u2191\u2193 \u79FB\u52A8\uFF0CEnter \u786E\u8BA4\uFF09",
696
695
  " /switch list \u4EE5\u6587\u672C\u5217\u51FA\u5168\u90E8 agent",
697
696
  " /switch <name> \u6309\u540D\u79F0\u3001\u522B\u540D\u6216 key \u76F4\u63A5\u5207\u6362\uFF08\u522B\u540D\uFF1A/agent\uFF09",
@@ -736,12 +735,6 @@ var STRINGS = {
736
735
  },
737
736
  toolsUsage: { en: "Usage: /tools <hide|compact|verbose>", zh: "\u7528\u6CD5\uFF1A/tools <hide|compact|verbose>" },
738
737
  toolsSet: { en: "Tool display: {0}", zh: "\u5DE5\u5177\u663E\u793A\uFF1A{0}" },
739
- thinkingCurrent: {
740
- en: "Thinking display: {0} (hide | marker | show)",
741
- zh: "\u601D\u8003\u663E\u793A\uFF1A{0}\uFF08hide | marker | show\uFF09"
742
- },
743
- thinkingUsage: { en: "Usage: /thinking <hide|marker|show>", zh: "\u7528\u6CD5\uFF1A/thinking <hide|marker|show>" },
744
- thinkingSet: { en: "Thinking display: {0}", zh: "\u601D\u8003\u663E\u793A\uFF1A{0}" },
745
738
  tasksRunning: { en: "Running processes ({0}):", zh: "\u8FD0\u884C\u4E2D\u7684\u8FDB\u7A0B\uFF08{0}\uFF09\uFF1A" },
746
739
  tasksStopped: { en: "Stopped/exited ({0}):", zh: "\u5DF2\u505C\u6B62/\u5DF2\u9000\u51FA\uFF08{0}\uFF09\uFF1A" },
747
740
  tasksNone: { en: "No processes.", zh: "\u6CA1\u6709\u8FD0\u884C\u4E2D\u7684\u8FDB\u7A0B\u3002" },
@@ -932,6 +925,44 @@ function agentRunCardLabels() {
932
925
  };
933
926
  }
934
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
+
935
966
  // packages/cli/client/localRuntimeAdapter.ts
936
967
  import { dirname, extname, join } from "node:path";
937
968
  import { fileURLToPath } from "node:url";
@@ -1371,56 +1402,6 @@ async function syncLocalDialogEvidenceToRemote(args) {
1371
1402
  return { attempted: true };
1372
1403
  }
1373
1404
 
1374
- // packages/cli/client/cliChildDialogPersist.ts
1375
- async function persistCliPendingChildDialog(args) {
1376
- const nowIso = new Date(args.now).toISOString();
1377
- const dialogKey = `dialog-${args.userId}-${args.dialogId}`;
1378
- const record = {
1379
- id: args.dialogId,
1380
- dbKey: dialogKey,
1381
- type: "dialog",
1382
- userId: args.userId,
1383
- cybots: [args.agentKey],
1384
- primaryAgentKey: args.agentKey,
1385
- title: args.title.slice(0, 80),
1386
- status: "pending",
1387
- triggerType: "cli-local",
1388
- executionMode: args.background ? "background" : "foreground",
1389
- createdAt: nowIso,
1390
- updatedAt: nowIso,
1391
- ...args.spaceId ? { spaceId: args.spaceId } : {},
1392
- ...args.parentDialogId ? { parentDialogId: args.parentDialogId } : {},
1393
- ...args.rootDialogId ? { rootDialogId: args.rootDialogId } : {},
1394
- localRuntime: {
1395
- host: "cli",
1396
- workspaceRoot: args.workspaceRoot,
1397
- workspaceKind: "current",
1398
- workspaceAccess: "inherited"
1399
- }
1400
- };
1401
- await args.store.batch([{ type: "put", key: dialogKey, value: record }]);
1402
- }
1403
- async function persistCliFailedChildDialog(args) {
1404
- const dialogKey = `dialog-${args.userId}-${args.dialogId}`;
1405
- const existing = await args.store.read(dialogKey);
1406
- const existingRecord = existing && typeof existing === "object" ? existing : {};
1407
- await args.store.batch([
1408
- {
1409
- type: "put",
1410
- key: dialogKey,
1411
- value: {
1412
- ...existingRecord,
1413
- id: args.dialogId,
1414
- dbKey: dialogKey,
1415
- status: "failed",
1416
- errorMessage: args.errorMessage,
1417
- updatedAt: new Date(args.now).toISOString(),
1418
- finishedAt: args.now
1419
- }
1420
- }
1421
- ]);
1422
- }
1423
-
1424
1405
  // packages/cli/client/cliLocalToolBudget.ts
1425
1406
  function parseLocalToolBudgets(env) {
1426
1407
  const raw = env.NOLO_LOCAL_TOOL_BUDGETS?.trim();
@@ -1640,58 +1621,6 @@ async function readDialogMessages(args) {
1640
1621
  return messages;
1641
1622
  }
1642
1623
 
1643
- // packages/cli/client/cliWorkspaceToolVariants.ts
1644
- function shouldUseDeclaredOnlyLocalWorkspaceTools(env) {
1645
- const value = env.NOLO_LOCAL_WORKSPACE_TOOLSET || env.NOLO_LOCAL_TOOLSET_MODE || "";
1646
- return value === "declared-only" || value === "declared";
1647
- }
1648
- function resolveGlobFilesDescriptionVariant(env) {
1649
- return resolveLocalWorkspaceDescriptionVariant(
1650
- env.NOLO_GLOBFILES_DESCRIPTION_VARIANT
1651
- );
1652
- }
1653
- function resolveListFilesDescriptionVariant(env) {
1654
- return resolveLocalWorkspaceDescriptionVariant(
1655
- env.NOLO_LISTFILES_DESCRIPTION_VARIANT
1656
- );
1657
- }
1658
- function resolveListFilesParameterVariant(env) {
1659
- return resolveLocalWorkspaceParameterVariant(
1660
- env.NOLO_LISTFILES_PARAMETER_VARIANT
1661
- );
1662
- }
1663
- function resolveReadFileDescriptionVariant(env) {
1664
- return resolveLocalWorkspaceDescriptionVariant(
1665
- env.NOLO_READFILE_DESCRIPTION_VARIANT
1666
- );
1667
- }
1668
- function resolveReadFileParameterVariant(env) {
1669
- return resolveLocalWorkspaceParameterVariant(
1670
- env.NOLO_READFILE_PARAMETER_VARIANT
1671
- );
1672
- }
1673
- function resolveGlobFilesParameterVariant(env) {
1674
- return resolveLocalWorkspaceParameterVariant(
1675
- env.NOLO_GLOBFILES_PARAMETER_VARIANT
1676
- );
1677
- }
1678
- function resolveSearchFilesDescriptionVariant(env) {
1679
- return resolveLocalWorkspaceDescriptionVariant(
1680
- env.NOLO_SEARCHFILES_DESCRIPTION_VARIANT
1681
- );
1682
- }
1683
- function resolveSearchFilesParameterVariant(env) {
1684
- return resolveLocalWorkspaceParameterVariant(
1685
- env.NOLO_SEARCHFILES_PARAMETER_VARIANT
1686
- );
1687
- }
1688
- function resolveLocalWorkspaceDescriptionVariant(value) {
1689
- return value === "brief" || value === "strategy" || value === "workflow" || value === "antiShell" ? value : "strategy";
1690
- }
1691
- function resolveLocalWorkspaceParameterVariant(value) {
1692
- return value === "minimal" || value === "scoped" || value === "rich" ? value : "rich";
1693
- }
1694
-
1695
1624
  // packages/cli/client/cliProviderHelpers.ts
1696
1625
  function buildDelegatedTaskContent(task, input) {
1697
1626
  if (input === void 0 || input === null) {
@@ -9154,6 +9083,30 @@ function createOAuthApiKeyRefResolver(options = {}) {
9154
9083
  };
9155
9084
  }
9156
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
+
9157
9110
  // packages/agent-runtime/dialogTitleLlm.ts
9158
9111
  async function generateLocalDialogTitle(input) {
9159
9112
  const { env, messages, fallbackTitle } = input;
@@ -9222,73 +9175,315 @@ function safeParseJson(raw) {
9222
9175
  }
9223
9176
  }
9224
9177
 
9225
- // packages/cli/client/hybridRecordStore.ts
9226
- function resolveFallbackServers(env) {
9227
- const values = [
9228
- env.NOLO_SERVER_URL,
9229
- env.BASE_URL,
9230
- ...NOLO_CLUSTER_SERVERS
9231
- ].filter((value) => typeof value === "string" && value.trim().length > 0);
9232
- return [...new Set(values.map(normalizeServerOrigin))];
9233
- }
9234
- function resolveAuthToken(env) {
9235
- return resolvePlatformAuthToken(env);
9236
- }
9237
- function createCliHybridRecordStore(deps) {
9238
- return createHybridRecordStore({
9239
- db: deps.db,
9240
- defaultServer: normalizeServerOrigin(
9241
- deps.env.NOLO_SERVER || deps.env.BASE_URL || DEFAULT_NOLO_SERVER_URL
9242
- ),
9243
- fallbackServers: resolveFallbackServers(deps.env),
9244
- 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,
9245
9184
  fetchImpl: deps.fetchImpl
9246
9185
  });
9247
9186
  }
9248
-
9249
- // packages/cli/client/localRuntimeAdapter.ts
9250
- import { ulid } from "ulid";
9251
- var resolveRuntimeAuthToken2 = resolveRuntimeAuthToken;
9252
- var currentMetaFile = fileURLToPath(import.meta.url);
9253
- var isJsBundle = extname(currentMetaFile) === ".js";
9254
- var SOURCE_CLI_DIR = isJsBundle ? dirname(currentMetaFile) : dirname(dirname(currentMetaFile));
9255
- var CLI_DIR = isCompiledBinary() ? dirname(process.execPath) : SOURCE_CLI_DIR;
9256
- var CLI_ENTRYPOINT = isCompiledBinary() ? process.execPath : isJsBundle ? currentMetaFile : join(SOURCE_CLI_DIR, "index.ts");
9257
- var preparedAgentRuntimeCache = /* @__PURE__ */ new Map();
9258
- var hybridStoreCache = /* @__PURE__ */ new Map();
9259
- function normalizeRuntimeCacheCwd(cwd) {
9260
- return (cwd?.trim() || process.cwd()).replace(/\/+$/, "") || ".";
9261
- }
9262
- function buildPreparedAgentCacheKey(args) {
9263
- const systemBuiltinSkillsKey = args.systemBuiltinSkills ? JSON.stringify(
9264
- Object.keys(args.systemBuiltinSkills).sort().map((key) => [key, args.systemBuiltinSkills?.[key]])
9265
- ) : "default";
9266
- return `${args.userId}\0${args.agentRef}\0${args.cwd}\0${systemBuiltinSkillsKey}`;
9267
- }
9268
- function clearCliLocalRuntimePreparedAgentCache() {
9269
- preparedAgentRuntimeCache.clear();
9270
- hybridStoreCache.clear();
9271
- }
9272
- async function defaultLocalRuntimeDb() {
9273
- return getDefaultCliLocalRuntimeDb();
9274
- }
9275
- function createFallbackId() {
9276
- return ulid();
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;
9277
9196
  }
9278
- function logLocalRuntimeDiagnostic(event, fields) {
9279
- if (process.env.NOLO_LOCAL_RUNTIME_DEBUG !== "1" && process.env.NOLO_DEBUG !== "1") {
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
+ };
9235
+ }
9236
+ async function writeLocalTokenRecord(args) {
9237
+ const rawUsage = args.input.result.usage;
9238
+ if (!rawUsage || typeof rawUsage !== "object" || Object.keys(rawUsage).length === 0) {
9280
9239
  return;
9281
9240
  }
9282
- 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);
9262
+ }
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
+ });
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 }]);
9283
9464
  }
9284
- function summarizeOpenAiToolNames(tools) {
9285
- return tools.reduce((acc, tool) => {
9286
- const fn = tool.function;
9287
- const name = fn && typeof fn === "object" && "name" in fn && typeof fn.name === "string" ? fn.name : null;
9288
- if (name) acc.push(name);
9289
- return acc;
9290
- }, []);
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
+ ]);
9291
9484
  }
9485
+
9486
+ // packages/cli/client/localRuntimeTools.ts
9292
9487
  function buildOpenAiTools(args) {
9293
9488
  const toolset = buildLocalWorkspaceToolsetForEnv(args);
9294
9489
  const toolNameSet = new Set(args.toolNames ?? []);
@@ -9345,9 +9540,6 @@ function buildOpenAiTools(args) {
9345
9540
  }),
9346
9541
  ...buildServerPlatformOpenAiTools({ toolNames: args.toolNames }),
9347
9542
  ...buildNoloWorkspaceOpenAiTools({ toolNames: args.toolNames }),
9348
- // startAgentRun/controlAgentRun:CLI 本地 --bg 执行器已就绪(MED-1 修复,
9349
- // cliAgentRunToolExecutors),只要 agent 声明(agent-orchestration 包展开)
9350
- // 就注入 schema。
9351
9543
  ...prepareTools(
9352
9544
  ["startAgentRun", "controlAgentRun"].filter((name) => toolNameSet.has(name))
9353
9545
  )
@@ -9356,10 +9548,10 @@ function buildOpenAiTools(args) {
9356
9548
  var CLI_DEFAULT_TOOLS = ["exa_search", "fetchWebpage"];
9357
9549
  function addDefaultCliCoreTools(toolNames, env, options) {
9358
9550
  const declaredOnly = env && shouldUseDeclaredOnlyLocalWorkspaceTools(env);
9359
- const forcedTools = options?.hasUserChoice ? FORCED_TOOLS : FORCED_TOOLS.filter((name) => name !== "ui_ask_choice");
9551
+ const forcedTools = options?.hasUserChoice === true ? FORCED_TOOLS : FORCED_TOOLS.filter((name) => name !== "ui_ask_choice");
9360
9552
  const injected = declaredOnly ? [...forcedTools] : [...forcedTools, ...CLI_DEFAULT_TOOLS];
9361
9553
  const combined = [...toolNames, ...injected];
9362
- const filtered = options?.hasUserChoice ? combined : combined.filter((name) => name !== "ui_ask_choice");
9554
+ const filtered = options?.hasUserChoice === true ? combined : combined.filter((name) => name !== "ui_ask_choice");
9363
9555
  return [...new Set(filtered)];
9364
9556
  }
9365
9557
  function resolveCliEffectiveEnabledPacks(args) {
@@ -9391,10 +9583,6 @@ function resolveCliRequestedToolNames(agentConfig, env, systemBuiltinSkills, opt
9391
9583
  addDefaultCliCoreTools(
9392
9584
  canonicalizeToolNames(
9393
9585
  expandEnabledPacks(
9394
- // CLI 端默认开 code 能力包:enabledPacks 为空时补 ["code"],保持
9395
- // 「CLI agent 默认能改代码」的体感,但走显式能力包而非隐式兜底
9396
- // (DEFAULT_LOCAL_CODING_TOOL_NAMES 已删除)。
9397
- // declared-only 模式下不补——用户显式要 ablation。
9398
9586
  resolveCliEffectiveEnabledPacks({
9399
9587
  enabledPacks: agentConfig?.enabledPacks,
9400
9588
  declaredOnly
@@ -9407,7 +9595,14 @@ function resolveCliRequestedToolNames(agentConfig, env, systemBuiltinSkills, opt
9407
9595
  ),
9408
9596
  agentConfig
9409
9597
  );
9410
- 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
+ );
9411
9606
  return applyDisabledTools(
9412
9607
  filtered,
9413
9608
  agentConfig?.disabledTools
@@ -9438,18 +9633,16 @@ function buildLocalWorkspaceToolsetForEnv(args) {
9438
9633
  return toolset;
9439
9634
  }
9440
9635
  function buildLocalPolicyToolNames(args) {
9441
- const buildTools = args.buildTools ?? buildOpenAiTools;
9442
- return [
9443
- ...new Set(
9444
- summarizeOpenAiToolNames(
9445
- buildTools({
9446
- agentKey: args.agentKey,
9447
- toolNames: args.toolNames,
9448
- env: args.env
9449
- })
9450
- )
9451
- )
9452
- ];
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)];
9453
9646
  }
9454
9647
  function buildServerPlatformOpenAiTools(args) {
9455
9648
  const toolNameSet = new Set(args.toolNames ?? []);
@@ -9647,210 +9840,13 @@ function createCliCallAgentToolExecutor(deps, ctx) {
9647
9840
  }
9648
9841
  };
9649
9842
  }
9650
- async function resolveStore(deps) {
9651
- if (deps.store) return deps.store;
9652
- return createCliHybridRecordStore({
9653
- db: deps.db ?? await defaultLocalRuntimeDb(),
9654
- env: deps.env,
9655
- fetchImpl: deps.fetchImpl
9656
- });
9657
- }
9658
- async function getOrCreateSharedStore(deps) {
9659
- if (deps.store) return deps.store;
9660
- const cacheKey = normalizeRuntimeCacheCwd(deps.cwd);
9661
- let storePromise = hybridStoreCache.get(cacheKey);
9662
- if (!storePromise) {
9663
- storePromise = resolveStore(deps);
9664
- hybridStoreCache.set(cacheKey, storePromise);
9665
- }
9666
- return storePromise;
9667
- }
9668
- function createLocalDialogTitleGenerator(deps, ctx) {
9669
- return async (input) => {
9670
- if (!canUsePlatformChatProvider(deps.env)) {
9671
- return null;
9672
- }
9673
- const result = await generateLocalDialogTitle({
9674
- messages: input.messages,
9675
- env: deps.env,
9676
- fetchImpl: async (url, init) => fetchWithTransientRetry(
9677
- deps.fetchImpl ?? fetch,
9678
- url,
9679
- init,
9680
- {
9681
- sleep: deps.sleep,
9682
- loopbackRequest: ctx.loopbackRequest
9683
- }
9684
- ),
9685
- resolveProviderConfig: async (args) => resolvePlatformChatProviderConfig({
9686
- agentConfig: args.agentConfig,
9687
- env: args.env,
9688
- apiKeyRefResolver: ctx.apiKeyRefResolver,
9689
- credentialBroker: ctx.credentialBroker
9690
- }),
9691
- buildRequest: (args) => buildPlatformChatCompletionRequest({
9692
- providerConfig: args.providerConfig,
9693
- messages: args.messages,
9694
- stream: false
9695
- }),
9696
- parseResponse: (args) => parsePlatformChatCompletionResponse({
9697
- providerConfig: args.providerConfig,
9698
- data: args.data,
9699
- trace: []
9700
- }),
9701
- fallbackTitle: input.fallbackTitle,
9702
- timeoutMs: 15e3
9703
- });
9704
- return result.source === "llm" ? result.title : null;
9705
- };
9706
- }
9707
- async function writeLocalTokenRecord(args) {
9708
- const rawUsage = args.input.result.usage;
9709
- if (!rawUsage || typeof rawUsage !== "object" || Object.keys(rawUsage).length === 0) {
9710
- return;
9711
- }
9712
- const timestamp = args.now();
9713
- const prepared = prepareTokenUsageData({
9714
- rawUsage,
9715
- agentConfig: {
9716
- model: args.input.result.model || "unknown",
9717
- provider: args.input.result.provider,
9718
- apiSource: "cli"
9719
- },
9720
- userId: args.userId,
9721
- agentId: args.input.agentKey,
9722
- dialogId: args.dialogId,
9723
- timestamp,
9724
- entry_path: "cli-local"
9725
- });
9726
- const recordKey = createTokenKey.record(args.userId, timestamp);
9727
- const tokenRecord = {
9728
- id: args.createId(),
9729
- type: "token",
9730
- ...prepared.tokenData
9731
- };
9732
- await args.store.write(recordKey, tokenRecord);
9733
- }
9734
- async function writeDialog(args) {
9735
- let existingDialog = null;
9736
- if (args.input.continueDialogId) {
9737
- const dialogKey = `dialog-${args.userId}-${args.input.continueDialogId}`;
9738
- existingDialog = await args.store.read(dialogKey);
9739
- }
9740
- const authToken = resolveRuntimeAuthToken2(args.env);
9741
- const isLoggedIn = Boolean(
9742
- authToken && (parseUserIdFromAuthToken(authToken) || args.env.NOLO_MACHINE_API_KEY?.trim())
9743
- );
9744
- const hasExistingTitle = typeof existingDialog?.title === "string" && existingDialog.title.trim();
9745
- let titleOverride;
9746
- if (isLoggedIn && !hasExistingTitle && args.titleGenerator) {
9747
- const fallbackTitle = extractLastUserText(args.input.messages).trim().slice(0, 80) || "Local agent run";
9748
- try {
9749
- const generated = await args.titleGenerator({
9750
- messages: args.input.messages,
9751
- fallbackTitle
9752
- });
9753
- if (generated) {
9754
- titleOverride = generated;
9755
- }
9756
- } catch {
9757
- }
9758
- }
9759
- const plan = buildLocalDialogWritePlan({
9760
- input: args.input,
9761
- userId: args.userId,
9762
- now: args.now(),
9763
- createId: args.createId,
9764
- existingDialog,
9765
- cwd: args.cwd,
9766
- ...titleOverride ? { titleOverride } : {}
9767
- });
9768
- await args.store.batch(plan.ops);
9769
- try {
9770
- await writeLocalTokenRecord({
9771
- store: args.store,
9772
- input: args.input,
9773
- userId: args.userId,
9774
- dialogId: plan.dialogId,
9775
- now: args.now,
9776
- createId: args.createId,
9777
- output: args.output
9778
- });
9779
- } catch (error) {
9780
- args.output?.write(
9781
- `[nolo] Token usage record write failed (non-fatal): ${toErrorMessage(error)}
9782
- `
9783
- );
9784
- }
9785
- const hasSubjectRefs = localTurnHasSubjectRefs(args.input);
9786
- const isLocalUser = args.userId === "local";
9787
- if (!isLocalUser) {
9788
- try {
9789
- const syncResult = await syncLocalDialogEvidenceToRemote({
9790
- env: args.env,
9791
- fetchImpl: args.fetchImpl,
9792
- input: args.input,
9793
- ops: plan.ops,
9794
- output: args.output,
9795
- userId: args.userId
9796
- });
9797
- if (!syncResult.attempted) {
9798
- if (hasSubjectRefs) {
9799
- args.output?.write(
9800
- "[nolo] Local dialog evidence is local-only; set NOLO_SERVER and AUTH_TOKEN to make subjectRefs remotely queryable.\n"
9801
- );
9802
- }
9803
- }
9804
- } catch (error) {
9805
- if (hasSubjectRefs) {
9806
- throw error;
9807
- }
9808
- args.output?.write(
9809
- `[nolo] Remote dialog evidence sync failed; local dialog only: ${toErrorMessage(
9810
- error
9811
- )}
9812
- `
9813
- );
9814
- }
9815
- }
9816
- return { dialogId: plan.dialogId, title: plan.title };
9817
- }
9818
- function resolveCliDialogRecordKey(userId, dialogId) {
9819
- if (dialogId.startsWith("dialog-") && !dialogId.includes("-msg-")) {
9820
- return dialogId;
9821
- }
9822
- return `dialog-${userId}-${dialogId}`;
9823
- }
9824
- async function loadCliDialogSummary(args) {
9825
- const dialogKey = resolveCliDialogRecordKey(args.userId, args.dialogId);
9826
- const record = await args.store.read(dialogKey);
9827
- if (!record || typeof record !== "object") return null;
9828
- const summary = typeof record.summary === "string" ? record.summary.trim() : "";
9829
- if (!summary) return null;
9830
- const summarizedBeforeId = record.summarizedBeforeId;
9831
- return {
9832
- summary,
9833
- ...typeof summarizedBeforeId === "string" && summarizedBeforeId ? { summarizedBeforeId } : {}
9834
- };
9835
- }
9836
- async function saveCliDialogSummary(args) {
9837
- const dialogKey = resolveCliDialogRecordKey(args.userId, args.dialogId);
9838
- const existing = await args.store.read(dialogKey) ?? {};
9839
- const bareId = typeof existing.id === "string" && existing.id ? existing.id : args.dialogId.startsWith("dialog-") ? args.dialogId.slice(args.dialogId.lastIndexOf("-") + 1) : args.dialogId;
9840
- const compressionCount = typeof existing.compressionCount === "number" ? existing.compressionCount + 1 : 1;
9841
- await args.store.write(dialogKey, {
9842
- ...existing,
9843
- id: bareId,
9844
- dbKey: dialogKey,
9845
- type: "dialog",
9846
- userId: args.userId,
9847
- summary: args.summary,
9848
- ...args.summarizedBeforeId !== void 0 ? { summarizedBeforeId: args.summarizedBeforeId } : {},
9849
- compressionCount,
9850
- summaryPending: false,
9851
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
9852
- });
9853
- }
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");
9854
9850
  function createCliLocalRuntimeAdapter(deps) {
9855
9851
  const now = deps.now ?? Date.now;
9856
9852
  const createId = deps.createId ?? createFallbackId;
@@ -9922,12 +9918,12 @@ function createCliLocalRuntimeAdapter(deps) {
9922
9918
  deps.env
9923
9919
  );
9924
9920
  const agentConfig = baseAgentConfig ? withRuntimeEnabledPacksAndPrompt(baseAgentConfig) : baseAgentConfig;
9925
- const hasUserChoice2 = Boolean(deps.requestUserChoice);
9921
+ const hasUserChoice = Boolean(deps.requestUserChoice);
9926
9922
  const requestedToolNames = agentConfig ? resolveCliRequestedToolNames(
9927
9923
  agentConfig,
9928
9924
  deps.env,
9929
9925
  systemBuiltinSkills,
9930
- { hasUserChoice: hasUserChoice2 }
9926
+ { hasUserChoice }
9931
9927
  ) : [];
9932
9928
  activeAgentToolNames = buildLocalPolicyToolNames({
9933
9929
  agentKey: agentConfig?.key,
@@ -10059,7 +10055,7 @@ function createCliLocalRuntimeAdapter(deps) {
10059
10055
  deps.env,
10060
10056
  buildProviderOpenAiTools,
10061
10057
  additionalToolNames,
10062
- { hasUserChoice }
10058
+ { hasUserChoice: Boolean(deps.requestUserChoice) }
10063
10059
  );
10064
10060
  logLocalRuntimeDiagnostic("provider.selected", {
10065
10061
  agentKey: agentConfig.key,
@@ -10141,7 +10137,7 @@ function createCliLocalRuntimeAdapter(deps) {
10141
10137
  deps.env,
10142
10138
  buildProviderOpenAiTools,
10143
10139
  additionalToolNames,
10144
- { hasUserChoice }
10140
+ { hasUserChoice: Boolean(deps.requestUserChoice) }
10145
10141
  );
10146
10142
  logLocalRuntimeDiagnostic("provider.selected", {
10147
10143
  agentKey: agentConfig.key,
@@ -10208,7 +10204,7 @@ function createCliLocalRuntimeAdapter(deps) {
10208
10204
  deps.env,
10209
10205
  buildProviderOpenAiTools,
10210
10206
  additionalToolNames,
10211
- { hasUserChoice }
10207
+ { hasUserChoice: Boolean(deps.requestUserChoice) }
10212
10208
  );
10213
10209
  logLocalRuntimeDiagnostic("provider.selected", {
10214
10210
  agentKey: agentConfig.key,