nolo-cli 0.11.0 → 0.12.0-alpha.1

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 (123) hide show
  1. package/{_executeModel-ZEDPX6OF.js → _executeModel-MWAY74HA.js} +51 -50
  2. package/{action-AA4IJ5K2.js → action-RAXNQQKC.js} +8 -9
  3. package/{addContentAction-QYVO4SYP.js → addContentAction-ZHI7TVV3.js} +7 -9
  4. package/{addDialogAgentAction-WVVKT5WQ.js → addDialogAgentAction-JWXPKXNC.js} +9 -10
  5. package/{agentDeleteCommand-RDPGYIWF.js → agentDeleteCommand-LXR5A5FV.js} +38 -28
  6. package/{agentEmailCommands-2HJJKS5F.js → agentEmailCommands-DXRAP7BB.js} +64 -62
  7. package/{agentListCommands-HFEVV3ZW.js → agentListCommands-ZFMS5ZLY.js} +127 -31
  8. package/{agentMachineCommands-25ZOENJU.js → agentMachineCommands-ZJLYVV52.js} +37 -26
  9. package/{agentPullCommand-GOL2S4W2.js → agentPullCommand-KRBRIFIY.js} +7 -7
  10. package/{agentRecordCommands-GTCOAM3L.js → agentRecordCommands-DFS626TB.js} +56 -54
  11. package/{agentRunCommand-YBS3JDLD.js → agentRunCommand-GWBIE2TS.js} +59 -59
  12. package/{agentRunControl-K4VKNEHF.js → agentRunControl-IX4F5W2C.js} +3 -3
  13. package/{agentRuntimeLocal-UQBMQI2M.js → agentRuntimeLocal-YNZSHMZC.js} +30 -15
  14. package/{agentSlice-6EKOBCCS.js → agentSlice-T2PXOEPQ.js} +8 -9
  15. package/{authCommand-O2OWACN4.js → authCommand-DMW336GT.js} +15 -15
  16. package/{authCommands-H7365TZP.js → authCommands-GH5T6RYV.js} +6 -6
  17. package/{chunk-7D3JY6C2.js → chunk-3HHTVM6G.js} +64 -5
  18. package/{chunk-AFON4QUU.js → chunk-3QKO4EHV.js} +3 -3
  19. package/{chunk-4SOKXIW4.js → chunk-43UD5ZP7.js} +8 -11
  20. package/{chunk-S3GS2PRL.js → chunk-4BTHUYMY.js} +597 -68
  21. package/{chunk-SV5MWASH.js → chunk-4EH7AR52.js} +12 -12
  22. package/{chunk-FXXSGWAJ.js → chunk-4GBNEA5B.js} +1 -1
  23. package/{chunk-PXZAAB4L.js → chunk-4LG74DRG.js} +4 -4
  24. package/{chunk-2FTTDCD4.js → chunk-4ON5AV72.js} +2 -1
  25. package/{chunk-IWX4UW2E.js → chunk-524BDL33.js} +89 -8
  26. package/{chunk-X2S7JTIG.js → chunk-5ITRDSHY.js} +1240 -136
  27. package/{chunk-ISNCLGUZ.js → chunk-5NBHQD4D.js} +4 -3
  28. package/{chunk-GBDSZATH.js → chunk-6LMFFG3K.js} +3 -3
  29. package/{chunk-OUI3ZHYD.js → chunk-6OVCRC72.js} +1 -1
  30. package/{chunk-CKOJQDKR.js → chunk-7JJCGV7N.js} +146 -3
  31. package/{chunk-MQI77IRB.js → chunk-7MYHLZ3F.js} +2 -2
  32. package/{chunk-5MOUAAMK.js → chunk-AM53Q2SD.js} +194 -2564
  33. package/chunk-BYXBJQAS.js +0 -0
  34. package/{chunk-LAX2JSTX.js → chunk-DE5BA4O6.js} +20 -2
  35. package/{chunk-BX6U3ETE.js → chunk-DRMGJFGQ.js} +293 -89
  36. package/{chunk-KJR5KAUQ.js → chunk-EBH7G34M.js} +20 -7
  37. package/{chunk-E4HNJSHC.js → chunk-G3B356GF.js} +16 -18
  38. package/{chunk-KQQVGRA3.js → chunk-GDBCUWQ3.js} +35 -29
  39. package/{chunk-Q3UKJVU4.js → chunk-GPZM7QH6.js} +10 -10
  40. package/chunk-IKXL2HZ3.js +70 -0
  41. package/{chunk-QNMFBBZK.js → chunk-IVAOVLM7.js} +1 -1
  42. package/{chunk-EVZKZF32.js → chunk-JUN3HFMN.js} +182 -75
  43. package/{chunk-NEM67FX7.js → chunk-JZDIW766.js} +1 -1
  44. package/{chunk-TACHTH5D.js → chunk-LHSJMY5V.js} +18 -18
  45. package/{chunk-XYZA7S7V.js → chunk-MEVCDATU.js} +6 -6
  46. package/{chunk-YOCHZD7D.js → chunk-NCGFB7NN.js} +5 -3
  47. package/{chunk-O26GI2JP.js → chunk-NITP2JDG.js} +39 -8
  48. package/{chunk-YPRZSPF3.js → chunk-OCDEWRE2.js} +1 -1
  49. package/{chunk-PNEW2Z3T.js → chunk-OHEKYYJF.js} +7 -7
  50. package/chunk-OOIN7HSO.js +146 -0
  51. package/{chunk-DWGAEFJL.js → chunk-OPKKB25T.js} +1 -1
  52. package/{chunk-AEZAORLG.js → chunk-QCA3EPYK.js} +5 -5
  53. package/{chunk-C4FTUXVF.js → chunk-QLUFR47U.js} +11 -1
  54. package/{chunk-C2MDQQ4O.js → chunk-RNQ5BLR2.js} +1 -1
  55. package/{chunk-L53FGHA4.js → chunk-RSEUHW6T.js} +1 -1
  56. package/{chunk-2W2VYVI5.js → chunk-RZ735TLX.js} +527 -176
  57. package/chunk-S3UTETIC.js +4885 -0
  58. package/chunk-S73OEOHH.js +2286 -0
  59. package/{chunk-YTBMA7NO.js → chunk-TSKWE74T.js} +58 -8
  60. package/{chunk-5OIFWVX7.js → chunk-UG3WOFU6.js} +1 -1
  61. package/{chunk-4ZDM73SD.js → chunk-V2J635L5.js} +1 -1
  62. package/{chunk-IPYUUY4E.js → chunk-WPHL6ALY.js} +1 -1
  63. package/{chunk-3NSIQZZ6.js → chunk-WTYKCU4W.js} +9 -9
  64. package/{chunk-LP65VRCI.js → chunk-WWU275LU.js} +6 -6
  65. package/{chunk-XFOLQLDN.js → chunk-XHQWJUW4.js} +2 -2
  66. package/{chunk-D6OQHXVG.js → chunk-YDCZVUFP.js} +7 -7
  67. package/{chunk-PXQN7IBQ.js → chunk-YTQLJYLB.js} +2 -2
  68. package/{chunk-ZEYDOXHF.js → chunk-ZPFRLGIZ.js} +1467 -869
  69. package/{chunk-ZPRK73XY.js → chunk-ZR4VHQ5D.js} +14 -13
  70. package/cliEnvHelpers-VYC2OPTB.js +30 -0
  71. package/{createAgentAutomationAction-LTI5QU35.js → createAgentAutomationAction-G32GKDGV.js} +25 -26
  72. package/{createDialogAction-OJJ7L3L3.js → createDialogAction-TISANRZK.js} +26 -27
  73. package/{createPageAction-5MXWVRGY.js → createPageAction-O7KOYNV4.js} +26 -27
  74. package/{dbSlice-RQFQQVHT.js → dbSlice-WDP2ZZHK.js} +6 -7
  75. package/{deleteFile-7XP5BGC7.js → deleteFile-M7UNIUOO.js} +4 -4
  76. package/{dialogCommands-JTJ3RPPW.js → dialogCommands-6JPB3YQY.js} +33 -23
  77. package/{dialogSlice-OWROKURJ.js → dialogSlice-PRHHYSP5.js} +26 -27
  78. package/{docCreateCommands-WJBEW2V7.js → docCreateCommands-75E6TZNN.js} +33 -23
  79. package/{docDeleteCommands-BVEHJOY5.js → docDeleteCommands-EJHLN7LW.js} +34 -25
  80. package/{docReadCommands-NEWOZIJV.js → docReadCommands-RJYBC4FS.js} +33 -23
  81. package/{docStore-3DXRYBMD.js → docStore-H5VWKT5D.js} +25 -26
  82. package/{docUpdateCommands-C7WHT7UU.js → docUpdateCommands-MG4CNISV.js} +33 -23
  83. package/fetchMessages-KTNM7QAR.js +1 -1
  84. package/{getPricing-3E6UNPKL.js → getPricing-6TOZXPAU.js} +7 -3
  85. package/{handleSendMessageAction-B5PRR7BE.js → handleSendMessageAction-QTUGICSZ.js} +29 -30
  86. package/index.js +77 -76
  87. package/{localDialogRead-YSKFFRTT.js → localDialogRead-2VRI24F4.js} +1 -1
  88. package/{machineCommands-IIIREAEK.js → machineCommands-MAV7M3TK.js} +63 -61
  89. package/{machineWsRunDispatch-3SIU6ILW.js → machineWsRunDispatch-ZOEGTKHC.js} +55 -53
  90. package/{memoryCommands-O4MIPIWQ.js → memoryCommands-AFMES3LN.js} +5 -5
  91. package/{models-4OPOOLFS.js → models-LSCRJJ6P.js} +2 -2
  92. package/package.json +1 -1
  93. package/{read-QJNKRROM.js → read-2MIMRBZ2.js} +4 -4
  94. package/{readDocTool-H6X6KO6X.js → readDocTool-QHVGQHUJ.js} +1 -1
  95. package/{readlineWorkspace-HGP3I3OC.js → readlineWorkspace-SWQKC7ZS.js} +1113 -678
  96. package/{removeDialogAgentAction-TCT35SOF.js → removeDialogAgentAction-GTX5AN54.js} +13 -13
  97. package/{runAgentClientLoop-EFM4PTVI.js → runAgentClientLoop-P25HACXX.js} +47 -47
  98. package/{runtimeDoctorCommands-ID43Z7VX.js → runtimeDoctorCommands-QNF3J3UV.js} +6 -6
  99. package/{setDialogExtraReferencesAction-CGYLZMFH.js → setDialogExtraReferencesAction-WFQ63KYO.js} +9 -10
  100. package/{setPrimaryDialogAgentAction-F6BFQDJU.js → setPrimaryDialogAgentAction-P57FXTSU.js} +13 -13
  101. package/{settingSlice-2I5HMG47.js → settingSlice-CK5YZGNI.js} +7 -8
  102. package/{skillDiscovery-UGSQGX2U.js → skillDiscovery-ZYHSX7VD.js} +3 -3
  103. package/{spaceCommands-MT7BWCIL.js → spaceCommands-6O5EFEM5.js} +37 -29
  104. package/{spaceSlice-BS5TSW3W.js → spaceSlice-4EXTYXS4.js} +28 -27
  105. package/{streamAgentChatTurn-I3VBFNR3.js → streamAgentChatTurn-Q3FJAHG2.js} +222 -128
  106. package/{toolApiClient-C7P7YSE4.js → toolApiClient-QI3YBNWB.js} +2 -2
  107. package/{tools-XSD2BOEN.js → tools-AHNQE4GP.js} +34 -34
  108. package/{tuiSummaryLlmCaller-32NRHTT2.js → tuiSummaryLlmCaller-TXLF4MEI.js} +8 -6
  109. package/{updateCommands-VOSPKXFF.js → updateCommands-XZDOOYFH.js} +13 -5
  110. package/{updateDialogTitleAction-7FYNJOGP.js → updateDialogTitleAction-XZDVLKVX.js} +29 -29
  111. package/chunk-5MMAK75Q.js +0 -15
  112. package/chunk-AZPCASRE.js +0 -36
  113. package/chunk-BBYVOSU2.js +0 -792
  114. package/chunk-DCOA4QSN.js +0 -105
  115. package/chunk-UAD2WT54.js +0 -64
  116. package/{chunk-JK7VW2FN.js → chunk-5MIDPSSK.js} +3 -3
  117. package/{chunk-5CS33IBL.js → chunk-PDL2AV3E.js} +3 -3
  118. package/{chunk-5MMZUWSG.js → chunk-TOILAPLH.js} +5 -5
  119. package/{chunk-OOM6SJNR.js → chunk-TSUJOM6N.js} +6 -6
  120. package/{db-6QED3ZVO.js → db-HCJ5PRB5.js} +3 -3
  121. package/{offlineMarxistsAgentCommand-BCPJITJL.js → offlineMarxistsAgentCommand-5OOWZLJI.js} +3 -3
  122. package/{tableCommands-M3DJUETS.js → tableCommands-E4SQWDOX.js} +6 -6
  123. package/{understanding-ZOESBLF3.js → understanding-3CUQQ6SV.js} +3 -3
@@ -1,6 +1,3 @@
1
- import {
2
- resolveMachineId
3
- } from "./chunk-6HYVJV7B.js";
4
1
  import {
5
2
  buildLocalRunEnv,
6
3
  isFullstackCodingAgentRef,
@@ -11,10 +8,17 @@ import {
11
8
  writeUsage
12
9
  } from "./chunk-3QAF2LTL.js";
13
10
  import {
11
+ resolveMachineId
12
+ } from "./chunk-6HYVJV7B.js";
13
+ import {
14
+ agentRunCardLabels,
14
15
  createCliCallAgentToolExecutor,
15
16
  createCliLocalRuntimeAdapter,
16
- isBuiltinNoloAgentRef
17
- } from "./chunk-X2S7JTIG.js";
17
+ getCliLocale,
18
+ isBuiltinNoloAgentRef,
19
+ t,
20
+ toolLabel
21
+ } from "./chunk-5ITRDSHY.js";
18
22
  import {
19
23
  CliProviderQuotaError
20
24
  } from "./chunk-CMKUBIGW.js";
@@ -24,10 +28,10 @@ import {
24
28
  import {
25
29
  readDbRecord,
26
30
  resolveAgentRecordFromHybridStore
27
- } from "./chunk-AEZAORLG.js";
31
+ } from "./chunk-QCA3EPYK.js";
28
32
  import {
29
33
  normalizeAgentHandle
30
- } from "./chunk-C2MDQQ4O.js";
34
+ } from "./chunk-RNQ5BLR2.js";
31
35
  import {
32
36
  NOLO_PROJECT_MANAGER_AGENT_KEY,
33
37
  isLocalCliAgentKey
@@ -36,78 +40,67 @@ import {
36
40
  applyModelLayerOverride,
37
41
  buildModelLayerOverride
38
42
  } from "./chunk-LTRXGFMS.js";
43
+ import {
44
+ formatAgentListCard,
45
+ formatListRunsCard,
46
+ formatNotFoundRunCard,
47
+ formatStartRunCard,
48
+ formatStatusRunCard,
49
+ formatStopRunCard,
50
+ isAgentRunTerminalStatus
51
+ } from "./chunk-RZ735TLX.js";
39
52
  import {
40
53
  isGatewayHttpStatus
41
- } from "./chunk-D6OQHXVG.js";
54
+ } from "./chunk-YDCZVUFP.js";
42
55
  import {
43
56
  buildMemorySubjectsForAgent,
44
57
  resolveAgentMemoryPolicy
45
- } from "./chunk-E4HNJSHC.js";
58
+ } from "./chunk-G3B356GF.js";
46
59
  import {
47
60
  parseExternalSkillMarkdown,
48
61
  parseSkillDocProtocol
49
62
  } from "./chunk-VC6OZXO5.js";
50
63
  import {
51
- getModelContextWindow,
64
+ API_REPORTED_COST_MULTIPLIER,
65
+ normalizeUsage,
52
66
  parseUiAskChoiceContent
53
- } from "./chunk-5MOUAAMK.js";
54
- import {
55
- parsePositiveFiniteNumberOrFallback
56
- } from "./chunk-Y5GCAMGP.js";
57
- import {
58
- touchMemoryItemsInDb
59
- } from "./chunk-HNW7IJSK.js";
60
- import {
61
- chooseMemoryOwners,
62
- loadMemoryCandidatesFromDb
63
- } from "./chunk-XENYHRUE.js";
64
- import {
65
- readPipeText,
66
- spawnProcess
67
- } from "./chunk-IDZTNRP2.js";
67
+ } from "./chunk-AM53Q2SD.js";
68
68
  import {
69
69
  buildSkillDiscoveryContextBlock
70
- } from "./chunk-AFON4QUU.js";
71
- import {
72
- buildMemoryOverlayLayer,
73
- buildMemoryUseGuidanceLayer
74
- } from "./chunk-C4FTUXVF.js";
70
+ } from "./chunk-3QKO4EHV.js";
75
71
  import {
76
72
  buildPlatformChatCompletionRequest,
77
73
  parsePlatformChatCompletionData
78
- } from "./chunk-ZPRK73XY.js";
74
+ } from "./chunk-ZR4VHQ5D.js";
79
75
  import {
80
76
  resolveAgentRuntimeConfigFromRecord
81
- } from "./chunk-YOCHZD7D.js";
77
+ } from "./chunk-NCGFB7NN.js";
82
78
  import {
83
79
  LOCAL_AGENT_CONFIG_MISSING_CODE,
84
80
  LOCAL_TURN_ABORTED_CODE,
85
81
  readActionGate,
86
82
  readCommandActionGatePayload
87
- } from "./chunk-S3GS2PRL.js";
83
+ } from "./chunk-4BTHUYMY.js";
88
84
  import {
89
85
  resolvePlatformChatCompletionsEndpoint
90
- } from "./chunk-YTBMA7NO.js";
86
+ } from "./chunk-TSKWE74T.js";
91
87
  import {
92
- clipCompactText
93
- } from "./chunk-5MMAK75Q.js";
88
+ DEFAULT_CONTEXT_WINDOW,
89
+ clipCompactText,
90
+ getModelContextWindow
91
+ } from "./chunk-S73OEOHH.js";
94
92
  import {
95
93
  findModelConfig
96
- } from "./chunk-BBYVOSU2.js";
94
+ } from "./chunk-S3UTETIC.js";
97
95
  import {
98
- asTrimmedLowercaseString
99
- } from "./chunk-QSJ3HFEF.js";
100
- import {
101
- compactWhitespace
102
- } from "./chunk-DWLEOOGR.js";
96
+ buildMemoryOverlayLayer,
97
+ buildMemoryUseGuidanceLayer
98
+ } from "./chunk-QLUFR47U.js";
103
99
  import {
104
100
  createRunActivityTracker,
105
101
  finalizeRunRecord,
106
102
  spawnLocalBackgroundRun
107
- } from "./chunk-2FTTDCD4.js";
108
- import {
109
- resolveAuthToken
110
- } from "./chunk-ISNCLGUZ.js";
103
+ } from "./chunk-4ON5AV72.js";
111
104
  import {
112
105
  toErrorMessage
113
106
  } from "./chunk-HNMXYYJR.js";
@@ -115,14 +108,36 @@ import {
115
108
  getDefaultCliLocalRuntimeDb
116
109
  } from "./chunk-H33743XH.js";
117
110
  import {
111
+ touchMemoryItemsInDb
112
+ } from "./chunk-HNW7IJSK.js";
113
+ import {
114
+ chooseMemoryOwners,
115
+ loadMemoryCandidatesFromDb
116
+ } from "./chunk-XENYHRUE.js";
117
+ import {
118
+ compactWhitespace
119
+ } from "./chunk-DWLEOOGR.js";
120
+ import {
121
+ readPipeText,
122
+ spawnProcess
123
+ } from "./chunk-IDZTNRP2.js";
124
+ import {
125
+ parsePositiveFiniteNumberOrFallback
126
+ } from "./chunk-Y5GCAMGP.js";
127
+ import {
128
+ asTrimmedLowercaseString
129
+ } from "./chunk-QSJ3HFEF.js";
130
+ import {
131
+ BUILTIN_NOLO_AGENT_KEY,
118
132
  PUBLIC_DEEPSEEK_V4_FLASH_AGENT_KEY,
119
- PUBLIC_DEEPSEEK_V4_PRO_AGENT_KEY,
120
- PUBLIC_GLM_52_AGENT_KEY,
121
133
  PUBLIC_KIMI_K26_IMAGE_AGENT_KEY
122
- } from "./chunk-XFOLQLDN.js";
134
+ } from "./chunk-XHQWJUW4.js";
123
135
  import {
124
136
  asTrimmedString
125
137
  } from "./chunk-3EUW3WEO.js";
138
+ import {
139
+ resolveAuthToken
140
+ } from "./chunk-5NBHQD4D.js";
126
141
  import {
127
142
  isLoopbackUrl
128
143
  } from "./chunk-4SN6J65J.js";
@@ -130,7 +145,235 @@ import {
130
145
  asOptionalTrimmedString
131
146
  } from "./chunk-G3SUCT4W.js";
132
147
 
148
+ // packages/agent-runtime/quickChatIntentCore.ts
149
+ var INTENT_MODEL = "deepseek-v4-flash";
150
+ var INTENT_PROVIDER = "deepseek";
151
+ var QUICK_CHAT_INTENT_TIMEOUT_MS = 4e3;
152
+ var SHORT_GREETING_MAX_LENGTH = 20;
153
+ var SHORT_GREETING_PATTERN = /^(?:hi|hello|hey|hiya|yo|sup|howdy|嗨|哈喽|哈囉|你好|您好|在吗|在嘛|喂|早上好|中午好|下午好|晚上好|拜拜|再见|谢谢|thanks|thx|ok|好的|收到|了解)[!.。,、~~]?$/iu;
154
+ function isShortGreeting(text) {
155
+ const trimmed = text.trim();
156
+ if (!trimmed) return false;
157
+ if (trimmed.length > SHORT_GREETING_MAX_LENGTH) return false;
158
+ return SHORT_GREETING_PATTERN.test(trimmed);
159
+ }
160
+ var COMPLEXITY_SIMPLE_MAX_LENGTH = 80;
161
+ var COMPLEXITY_MEDIUM_MAX_LENGTH = 500;
162
+ var COMPLEXITY_KEYWORDS = /为什么|如何|分析|对比|比较|设计|架构|实现|原理|推导|评价|区别|关系|影响|优化|重构/;
163
+ var COMPLEXITY_CODE_BLOCK = /```[\s\S]*```/;
164
+ function estimateComplexity(text) {
165
+ const trimmed = text.trim();
166
+ const len = trimmed.length;
167
+ if (len > COMPLEXITY_MEDIUM_MAX_LENGTH) return "complex";
168
+ if (COMPLEXITY_CODE_BLOCK.test(trimmed)) return "complex";
169
+ if (len > COMPLEXITY_SIMPLE_MAX_LENGTH) return "medium";
170
+ if (COMPLEXITY_KEYWORDS.test(trimmed)) return "medium";
171
+ return "simple";
172
+ }
173
+ var TIER_DESCRIPTIONS = {
174
+ flash: "\u5FEB\u901F\u7B80\u5355\uFF1A\u95EE\u5019\u3001\u95F2\u804A\u3001\u5FEB\u901F\u95EE\u7B54\u3001\u7FFB\u8BD1\u3001\u77ED\u6587",
175
+ balanced: "\u5E73\u8861\u63A8\u7406\uFF1A\u5206\u6790\u3001\u4E2D\u7B49\u957F\u5EA6\u5199\u4F5C\u3001\u4EE3\u7801\u3001\u63A8\u7406\uFF08\u5F53\u524D\u8DEF\u7531\u81F3 DeepSeek V4 Flash\uFF09",
176
+ quality: "\u9AD8\u8D28\u91CF\u6DF1\u5EA6\uFF1A\u590D\u6742\u63A8\u7406\u3001\u957F\u6587\u3001\u67B6\u6784\u8BBE\u8BA1\u3001\u6DF1\u5EA6\u5206\u6790\uFF08\u5F53\u524D\u8DEF\u7531\u81F3 DeepSeek V4 Flash\uFF09"
177
+ };
178
+ function buildQuickChatIntentSystemPrompt(tierAgents) {
179
+ const agentList = tierAgents.map((t2) => ` - "${t2.agentKey}"\uFF1A${t2.description}`).join("\n");
180
+ return `\u4F60\u662F\u4E00\u4E2A\u610F\u56FE\u8DEF\u7531\u5668\u3002\u6839\u636E\u7528\u6237\u6D88\u606F\uFF0C\u5224\u65AD\u5E94\u8BE5\u4EA4\u7ED9\u54EA\u4E2A agent \u5904\u7406\u3002
181
+
182
+ \u53EF\u9009 agent \u5217\u8868\uFF08agentKey \u4E0E\u63CF\u8FF0\uFF09\uFF1A
183
+ ${agentList}
184
+
185
+ \u5224\u65AD\u539F\u5219\uFF08\u9ED8\u8BA4\u504F\u5411\u901A\u7528\u6863\u4F4D\uFF1B\u4E13\u804C agent \u5728\u660E\u786E\u5339\u914D\u65F6\u4F7F\u7528\uFF1B**\u7F16\u7801/\u672C\u5730\u4ED3\u5E93\u4EFB\u52A1\u8D70\u901A\u7528\u6863 + needsWorkspace=true**\uFF09\uFF1A
186
+ - \u9ED8\u8BA4\u60C5\u51B5\u4E0B\uFF0C**\u9664\u975E\u7528\u6237\u660E\u786E\u8868\u8FBE\u8981\u5EFA\u5E94\u7528/\u5EFA Agent/\u63D0\u4EA4\u53CD\u9988/\u591A Agent \u7F16\u6392**\uFF0C\u5426\u5219\u9009\u901A\u7528\u6863\u4F4D\uFF08flash/balanced/quality\uFF09\uFF1A
187
+ - \u7B80\u5355\u95EE\u5019\u3001\u95F2\u804A\u3001\u5FEB\u901F\u95EE\u7B54\u3001\u7FFB\u8BD1\u3001\u77ED\u6587 \u2192 \u9009 flash \u6863
188
+ - \u9700\u8981\u63A8\u7406\u3001\u5206\u6790\u3001\u4E2D\u7B49\u957F\u5EA6\u5199\u4F5C\u3001\u666E\u901A\u4EE3\u7801\u89E3\u91CA/\u67B6\u6784\u95EE\u7B54 \u2192 \u9009 balanced \u6863
189
+ - \u590D\u6742\u63A8\u7406\u3001\u957F\u6587\u3001\u67B6\u6784\u8BBE\u8BA1\u3001\u6DF1\u5EA6\u5206\u6790 \u2192 \u9009 quality \u6863
190
+ - **\u660E\u786E\u7F16\u7801\u4EFB\u52A1\uFF08\u5B9E\u73B0\u529F\u80FD\u3001\u4FEE bug\u3001refactor\u3001\u5199/\u8865\u6D4B\u8BD5\u3001\u8DD1 build/tests/ci\uFF09\u6216\u67E5\u770B\u672C\u673A\u4ED3\u5E93/\u4EE3\u7801\u72B6\u6001\uFF08git/\u5206\u652F/commit/\u672C\u5730\u4E0E\u8FDC\u7A0B\u5DEE\u8DDD/\u672A\u63D0\u4EA4\u6539\u52A8\u7B49\uFF09** \u2192 \u9009 balanced \u6216 quality \u6863\uFF08\u6309\u590D\u6742\u5EA6\uFF1B**\u4E0D\u8981\u9009 flash**\uFF09\uFF0C\u4E14 needsWorkspace=true
191
+ - \u4E13\u804C agent \u8DEF\u7531\u89C4\u5219\uFF08\u6709\u660E\u786E\u5339\u914D\u65F6\u4F7F\u7528\uFF09\uFF1A
192
+ - \u8981\u63D0\u4EA4/\u8BB0\u5F55 bug\u3001\u4F53\u9A8C\u95EE\u9898\u3001\u6570\u636E\u5F02\u5E38\u3001\u4EA7\u54C1\u5EFA\u8BAE\uFF0C\u6216\u53E3\u8BED\u5982\u300C\u60F3\u53CD\u9988\u4E00\u4E9B\u95EE\u9898\u300D\u300C\u53CD\u9988\u4E00\u4E0B\u300D\u2192 \u9009\u610F\u89C1\u53CD\u9988\u4E13\u804C agent
193
+ - \u8981\u65B0\u5EFA\u6216\u5B9A\u5236 AI/Agent/\u667A\u80FD\u4F53\u52A9\u624B\uFF08\u542B\u914D\u7F6E\u5DE5\u5177\u3001\u77E5\u8BC6\u3001\u786E\u8BA4\u521B\u5EFA\uFF09\u2192 \u9009\u521B\u5EFA Agent \u4E13\u804C agent
194
+ - \u8981\u505A/\u6539/\u53D1\u5E03\u7F51\u7AD9\u3001\u7F51\u9875\u3001\u5C0F\u5E94\u7528\u3001\u9884\u7EA6\u9875\u3001\u535A\u5BA2\u3001\u770B\u677F \u2192 \u9009\u5E94\u7528\u6784\u5EFA\u4E13\u804C agent
195
+ - \u8981\u6D3E\u591A\u4E2A agent\u3001\u591A agent \u5E76\u884C\u3001\u62C6\u6210\u4EFB\u52A1\u540E\u53F0\u6267\u884C\u3001\u591A\u4E2A agent review\u3001\u8BA9\u4E0D\u540C agent \u8BA8\u8BBA/\u4F1A\u5546 \u2192 \u9009\u591A Agent \u7F16\u6392\u4E13\u804C agent\uFF08\u663E\u5F0F multi-agent \u4F18\u5148\uFF09
196
+ - **\u62FF\u4E0D\u51C6\u65F6**\uFF1A\u7EAF\u95F2\u804A\u9009 flash\uFF1B**\u82E5\u6CBE\u8FB9\u672C\u5730\u4ED3\u5E93/\u5F53\u524D\u4EE3\u7801\u72B6\u6001\uFF0C\u9009 balanced/quality + needsWorkspace=true**\u3002
197
+
198
+ \u540C\u65F6\u5224\u65AD\u672C\u8F6E\u662F\u5426\u9700\u8981\u6CE8\u5165\u300C\u5DE5\u4F5C\u533A\u53EA\u8BFB\u5DE5\u5177\u300D\uFF08listFiles/globFiles/searchFiles/readFile/execShell \u7B49\uFF09\uFF1A
199
+ - needsWorkspace=true \u7684\u573A\u666F\uFF1A\u7528\u6237\u8981\u8BFB/\u6539/\u5206\u6790\u6587\u4EF6\u6216\u4EE3\u7801\u3001\u63D0\u5230\u4E86\u6587\u4EF6\u8DEF\u5F84/\u6269\u5C55\u540D\uFF08.md/.csv/.ts \u7B49\uFF09\u3001\u63D0\u5230\u5DE5\u4F5C\u533A/\u4EE3\u7801\u5E93/\u4ED3\u5E93/\u76EE\u5F55/git/\u5206\u652F\u3001\u8981\u770B\u5F53\u524D\u4EE3\u7801\u6216\u4ED3\u5E93\u72B6\u6001\u3001\u672C\u5730\u641C\u7D22/\u67E5\u770B\u4EE3\u7801\u3002
200
+ - needsWorkspace=false \u7684\u573A\u666F\uFF1A\u901A\u7528\u77E5\u8BC6\u95EE\u7B54\uFF08\u5982\u300C\u5E7F\u4E1C\u7ECF\u6D4E\u6570\u636E\u300D\u300C\u5199\u4E00\u9996\u8BD7\u300D\uFF09\u3001\u7EAF\u95F2\u804A\u95EE\u5019\u3001\u7FFB\u8BD1\u3001\u4E0D\u6D89\u53CA\u672C\u5730\u6587\u4EF6/\u4ED3\u5E93\u3002
201
+ - \u6F0F\u5224\uFF08\u7528\u6237\u8981\u6587\u4EF6\u800C\u6CA1\u5E26\u5DE5\u5177\uFF09\u6BD4\u8BEF\u5224\uFF08\u767D\u641C\u51E0\u8F6E\uFF09\u4EE3\u4EF7\u66F4\u9AD8\uFF0C\u5B81\u53EF\u504F\u5BBD\u5224 true\u3002
202
+
203
+ \u5728\u7ED9\u51FA agentKey \u4E4B\u524D\uFF0C\u5148\u5728\u5FC3\u91CC\u533A\u5206\u5019\u9009\u6863\u4F4D\u7684\u8FB9\u754C\u518D\u7ED9\u7F6E\u4FE1\u5EA6\uFF1Abalanced \u4E0E quality \u7684\u8FB9\u754C\u5728\u4E8E\u590D\u6742\u5EA6/\u7BC7\u5E45/\u662F\u5426\u9700\u8981\u6DF1\u5EA6\u5206\u6790\uFF0C\u62FF\u4E0D\u51C6\u5C31\u7ED9\u4F4E confidence\u3002
204
+
205
+ \u540C\u65F6\u5224\u65AD\u672C\u8F6E\u6D88\u606F\u662F\u5426\u9700\u8981\u6302\u8F7D\u5BF9\u8C61\u64CD\u4F5C\u6280\u80FD\uFF08skills \u6570\u7EC4\uFF0C\u672A\u547D\u4E2D\u7ED9 []\uFF09\uFF1A
206
+ - \u7528\u6237\u8981\u65B0\u5EFA/\u6574\u7406/\u5F55\u5165/\u6279\u91CF\u5904\u7406\u8868\u683C\u6570\u636E\uFF08\u5EFA\u8868\u3001\u52A0\u884C\u3001\u6539\u5217\u3001\u6309\u6761\u4EF6\u6574\u7406\u6570\u636E\uFF09\u2192 skills \u542B "table"
207
+ - \u7528\u6237\u8981\u5199/\u6DA6\u8272/\u6539\u5199/\u7EED\u5199/\u6392\u7248\u4E00\u7BC7\u6587\u6863\u6216\u6587\u7AE0 \u2192 skills \u542B "doc"
208
+ - \u7528\u6237\u8981\u5199/\u6539/\u5B9E\u73B0/\u4FEE bug/refactor/\u8865\u6D4B\u8BD5/\u5BA1\u67E5\u5E76\u4FEE\u6539\u4EE3\u7801 \u2192 skills \u542B "code"\uFF08\u4EC5\u95EE\u901A\u7528\u77E5\u8BC6\u3001\u7EAF\u95F2\u804A\u3001\u53EA\u67E5\u770B git/\u4ED3\u5E93\u72B6\u6001\u800C\u4E0D\u4FEE\u6539\u4EE3\u7801\u65F6\u4E0D\u6302 "code"\uFF09
209
+ - \u666E\u901A\u95EE\u7B54/\u7EAF\u95F2\u804A/\u5EFA\u5E94\u7528 \u2192 skills \u4E3A []
210
+
211
+ \u53EA\u8F93\u51FA JSON\uFF0C\u4E0D\u8981\u8F93\u51FA\u5176\u4ED6\u5185\u5BB9\uFF1A
212
+ {"confidence": <0\u52301\u4E4B\u95F4\u7684\u5C0F\u6570\uFF0C\u8868\u793A\u4F60\u5BF9\u8FD9\u4E2A\u5206\u7C7B\u5224\u65AD\u7684\u628A\u63E1\u7A0B\u5EA6>, "agentKey": "<\u4ECE\u5217\u8868\u4E2D\u9009\u62E9\u7684 agentKey>", "needsWorkspace": <true \u6216 false>, "skills": <\u5B57\u7B26\u4E32\u6570\u7EC4\uFF0C\u5143\u7D20\u53EA\u80FD\u662F "table" | "doc" | "code"\uFF0C\u672A\u547D\u4E2D\u7ED9 []>}`;
213
+ }
214
+ function parseQuickChatIntentResult(content, tierAgents) {
215
+ try {
216
+ const parsed = JSON.parse(content.trim());
217
+ if (typeof parsed !== "object" || parsed === null || !("agentKey" in parsed)) return null;
218
+ const key = parsed.agentKey;
219
+ if (typeof key !== "string") return null;
220
+ if (!tierAgents.some((t2) => t2.agentKey === key)) return null;
221
+ const rawNeedsWorkspace = parsed.needsWorkspace;
222
+ const needsWorkspace = rawNeedsWorkspace === true;
223
+ const rawConfidence = parsed.confidence;
224
+ const confidence = typeof rawConfidence === "number" && Number.isFinite(rawConfidence) && rawConfidence >= 0 && rawConfidence <= 1 ? rawConfidence : void 0;
225
+ const rawSkills = parsed.skills;
226
+ let skills;
227
+ if (Array.isArray(rawSkills)) {
228
+ const filtered = [...new Set(rawSkills)].filter(
229
+ (s) => s === "table" || s === "doc" || s === "code"
230
+ );
231
+ if (filtered.length > 0) skills = filtered;
232
+ }
233
+ return { agentKey: key, needsWorkspace, confidence, skills };
234
+ } catch {
235
+ return null;
236
+ }
237
+ }
238
+
239
+ // packages/cli/client/autoModelRouter.ts
240
+ var CLI_AUTO_TIER_AGENT_KEYS = {
241
+ flash: PUBLIC_DEEPSEEK_V4_FLASH_AGENT_KEY,
242
+ balanced: PUBLIC_DEEPSEEK_V4_FLASH_AGENT_KEY,
243
+ quality: PUBLIC_DEEPSEEK_V4_FLASH_AGENT_KEY
244
+ };
245
+ var CLI_AUTO_TIER_MODELS = {
246
+ flash: "deepseek-v4-flash",
247
+ balanced: "deepseek-v4-flash",
248
+ quality: "deepseek-v4-flash"
249
+ };
250
+ var CLI_IMAGE_AGENT_KEY = PUBLIC_KIMI_K26_IMAGE_AGENT_KEY;
251
+ var CLI_IMAGE_AGENT_MODEL = "kimi-k2.6";
252
+ var CLI_AUTO_TIER_AGENT_KEY_TABLE = {
253
+ [CLI_AUTO_TIER_AGENT_KEYS.flash]: true,
254
+ [CLI_AUTO_TIER_AGENT_KEYS.balanced]: true,
255
+ [CLI_AUTO_TIER_AGENT_KEYS.quality]: true
256
+ };
257
+ function resolveCliAutoAgentModel(agentKey) {
258
+ if (agentKey === CLI_AUTO_TIER_AGENT_KEYS.flash) return CLI_AUTO_TIER_MODELS.flash;
259
+ if (agentKey === CLI_AUTO_TIER_AGENT_KEYS.balanced) {
260
+ return CLI_AUTO_TIER_MODELS.balanced;
261
+ }
262
+ if (agentKey === CLI_AUTO_TIER_AGENT_KEYS.quality) {
263
+ return CLI_AUTO_TIER_MODELS.quality;
264
+ }
265
+ if (agentKey === CLI_IMAGE_AGENT_KEY) return CLI_IMAGE_AGENT_MODEL;
266
+ return void 0;
267
+ }
268
+ var buildRouteOptions = () => ["flash", "balanced", "quality"].map((tier) => ({
269
+ tier,
270
+ agentKey: CLI_AUTO_TIER_AGENT_KEYS[tier],
271
+ description: TIER_DESCRIPTIONS[tier]
272
+ }));
273
+ var tierForAgentKey = (agentKey) => {
274
+ for (const tier of ["flash", "balanced", "quality"]) {
275
+ if (CLI_AUTO_TIER_AGENT_KEYS[tier] === agentKey) return tier;
276
+ }
277
+ return null;
278
+ };
279
+ function resolveCliAutoFallbackTier(text) {
280
+ switch (estimateComplexity(text)) {
281
+ case "complex":
282
+ return "quality";
283
+ case "medium":
284
+ return "balanced";
285
+ case "simple":
286
+ default:
287
+ return "flash";
288
+ }
289
+ }
290
+ async function classifyCliAutoRoute(text, options) {
291
+ const timeoutMs = options.timeoutMs ?? QUICK_CHAT_INTENT_TIMEOUT_MS;
292
+ const fallbackTier = resolveCliAutoFallbackTier(text);
293
+ const fallback = () => ({
294
+ agentKey: CLI_AUTO_TIER_AGENT_KEYS[fallbackTier],
295
+ tier: fallbackTier,
296
+ classified: false
297
+ });
298
+ if (!text.trim()) return fallback();
299
+ if (isShortGreeting(text)) {
300
+ return {
301
+ agentKey: CLI_AUTO_TIER_AGENT_KEYS.flash,
302
+ tier: "flash",
303
+ classified: true
304
+ };
305
+ }
306
+ if (!options.authToken) return fallback();
307
+ const fetchImpl = options.fetchImpl ?? globalThis.fetch;
308
+ const controller = new AbortController();
309
+ const timeoutHandle = setTimeout(() => controller.abort(), timeoutMs);
310
+ try {
311
+ const routeOptions = buildRouteOptions();
312
+ const messages = [
313
+ { role: "system", content: buildQuickChatIntentSystemPrompt(routeOptions) },
314
+ { role: "user", content: text }
315
+ ];
316
+ const { url, init } = buildPlatformChatCompletionRequest({
317
+ providerConfig: {
318
+ serverUrl: options.serverUrl,
319
+ authToken: options.authToken,
320
+ agentKey: CLI_AUTO_TIER_AGENT_KEYS.flash,
321
+ model: INTENT_MODEL,
322
+ provider: INTENT_PROVIDER,
323
+ endpoint: resolvePlatformChatCompletionsEndpoint(INTENT_PROVIDER) ?? "",
324
+ requestOptions: {}
325
+ },
326
+ messages,
327
+ stream: false
328
+ });
329
+ const response = await fetchImpl(url, {
330
+ ...init,
331
+ signal: controller.signal
332
+ });
333
+ if (!response.ok) return fallback();
334
+ const data = parsePlatformChatCompletionData(await response.text());
335
+ const content = data?.choices?.[0]?.message?.content;
336
+ if (typeof content !== "string" || !content.trim()) return fallback();
337
+ const parsed = parseQuickChatIntentResult(content, routeOptions);
338
+ if (!parsed) return fallback();
339
+ const tier = tierForAgentKey(parsed.agentKey) ?? fallbackTier;
340
+ return {
341
+ agentKey: parsed.agentKey,
342
+ tier,
343
+ classified: true,
344
+ confidence: parsed.confidence,
345
+ needsWorkspace: parsed.needsWorkspace,
346
+ skills: parsed.skills
347
+ };
348
+ } catch {
349
+ return fallback();
350
+ } finally {
351
+ clearTimeout(timeoutHandle);
352
+ }
353
+ }
354
+
133
355
  // packages/cli/client/tokenUsage.ts
356
+ var isUsableModelId = (model) => {
357
+ const raw = model?.trim();
358
+ return Boolean(raw) && raw !== "-" && raw !== "auto";
359
+ };
360
+ function resolveAgentContextWindow(opts) {
361
+ if (isUsableModelId(opts.model)) {
362
+ return getModelContextWindow(opts.model);
363
+ }
364
+ const agentKey = opts.agentKey?.trim();
365
+ if (agentKey) {
366
+ const tierModel = resolveCliAutoAgentModel(agentKey);
367
+ if (tierModel) return getModelContextWindow(tierModel);
368
+ if (opts.autoRouteDefault !== false && agentKey === BUILTIN_NOLO_AGENT_KEY) {
369
+ return getModelContextWindow(CLI_AUTO_TIER_MODELS.flash);
370
+ }
371
+ }
372
+ if (opts.agentName?.trim()) {
373
+ return getModelContextWindow(opts.agentName);
374
+ }
375
+ return DEFAULT_CONTEXT_WINDOW;
376
+ }
134
377
  var PROVIDER_LOOKUP_ORDER = [
135
378
  "openrouter",
136
379
  "fireworks",
@@ -150,7 +393,15 @@ function parseUsageRecord(usage) {
150
393
  const output = Number(usage.output_tokens ?? usage.completion_tokens ?? 0);
151
394
  if (!Number.isFinite(input) || !Number.isFinite(output)) return void 0;
152
395
  if (!input && !output) return void 0;
153
- return { input, output };
396
+ const normalized = normalizeUsage(usage);
397
+ const cacheRead = normalized.cache_read_input_tokens || void 0;
398
+ const cacheWrite = normalized.cache_creation_input_tokens || void 0;
399
+ return {
400
+ input,
401
+ output,
402
+ ...cacheRead === void 0 ? {} : { cacheRead },
403
+ ...cacheWrite === void 0 ? {} : { cacheWrite }
404
+ };
154
405
  }
155
406
  function resolveContextWindow(model) {
156
407
  const raw = model?.trim();
@@ -166,10 +417,13 @@ function buildTurnTokenUsage(usage, model) {
166
417
  if (!parsed) return void 0;
167
418
  const contextWindow = resolveContextWindow(model);
168
419
  const remaining = contextWindow && parsed.input > 0 ? Math.max(0, contextWindow - parsed.input) : void 0;
420
+ const rawCost = typeof usage?.cost === "number" ? usage.cost : void 0;
421
+ const credits = rawCost !== void 0 && rawCost > 0 ? rawCost * API_REPORTED_COST_MULTIPLIER : void 0;
169
422
  return {
170
423
  ...parsed,
171
424
  ...contextWindow ? { contextWindow } : {},
172
- ...remaining != null ? { remaining } : {}
425
+ ...remaining != null ? { remaining } : {},
426
+ ...credits !== void 0 ? { credits } : {}
173
427
  };
174
428
  }
175
429
  function formatTokenCount(value) {
@@ -186,7 +440,8 @@ function formatTokenCount(value) {
186
440
  function renderTokenStatus(tokens) {
187
441
  if (!tokens) return "in \u2014 out \u2014 left \u2014";
188
442
  const left = tokens.remaining != null ? formatTokenCount(tokens.remaining) : tokens.contextWindow ? "\u2014" : "\u2014";
189
- return `in ${formatTokenCount(tokens.input)} out ${formatTokenCount(tokens.output)} left ${left}`;
443
+ const cache = tokens.cacheRead != null && tokens.cacheRead > 0 ? ` (cache ${formatTokenCount(tokens.cacheRead)})` : "";
444
+ return `in ${formatTokenCount(tokens.input)}${cache} out ${formatTokenCount(tokens.output)} left ${left}`;
190
445
  }
191
446
  function shouldShowUsage(env) {
192
447
  return env.NOLO_DEBUG === "1" || env.NOLO_SHOW_USAGE === "1";
@@ -232,14 +487,283 @@ function resolveCliColorEnabled(env = process.env, isTTY = Boolean(process.stdou
232
487
  if (setting === "1" || setting === "true" || setting === "on") return true;
233
488
  return isTTY;
234
489
  }
235
- function styleCliText(text, style, enabled = resolveCliColorEnabled()) {
236
- if (!enabled || !text) return text;
237
- const code = ANSI_FG[style] ?? ANSI_BG[style];
238
- if (!code) return text;
239
- return `${code}${text}${RESET}`;
490
+ function styleCliText(text, style, enabled = resolveCliColorEnabled()) {
491
+ if (!enabled || !text) return text;
492
+ const code = ANSI_FG[style] ?? ANSI_BG[style];
493
+ if (!code) return text;
494
+ return `${code}${text}${RESET}`;
495
+ }
496
+ function dimCliText(text, enabled = resolveCliColorEnabled()) {
497
+ return styleCliText(text, "dim", enabled);
498
+ }
499
+
500
+ // packages/cli/tui/tuiAnsi.ts
501
+ var ANSI_ESCAPE_REGEX = /\x1b\[[\x30-\x3f]*[\x20-\x2f]*[\x40-\x7e]/g;
502
+ var OSC_HYPERLINK_REGEX = /\x1b\]8;;[^\x07\x1b]*(?:\x07|\x1b\\)\x1b\]8;;(?:\x07|\x1b\\)|\x1b\]8;;[^\x07\x1b]*(?:\x07|\x1b\\)/g;
503
+ function stripAnsi(text) {
504
+ return text.replace(OSC_HYPERLINK_REGEX, "").replace(ANSI_ESCAPE_REGEX, "");
505
+ }
506
+ var SGR_SEQUENCE_REGEX = /^\x1b\[[0-9;]*m/;
507
+ var TRAILING_SGR_REGEX = /(?:\x1b\[[0-9;]*m)+$/;
508
+ function applyTerminalOutputToText(existing, chunk) {
509
+ if (!chunk) return existing;
510
+ let text = existing;
511
+ let index = 0;
512
+ while (index < chunk.length) {
513
+ if (chunk[index] === "\x1B") {
514
+ const sgr = SGR_SEQUENCE_REGEX.exec(chunk.slice(index));
515
+ if (sgr) {
516
+ text += sgr[0];
517
+ index += sgr[0].length;
518
+ continue;
519
+ }
520
+ const osc = chunk.slice(index).match(/^\x1b\]8;;[^\x07\x1b]*(?:\x07|\x1b\\)/);
521
+ if (osc) {
522
+ index += osc[0].length;
523
+ continue;
524
+ }
525
+ const csi = chunk.slice(index).match(/^\x1b\[[\x30-\x3f]*[\x20-\x2f]*[\x40-\x7e]/);
526
+ if (csi) {
527
+ index += csi[0].length;
528
+ continue;
529
+ }
530
+ index += 1;
531
+ continue;
532
+ }
533
+ const ch = chunk[index];
534
+ if (ch === "\r") {
535
+ const lastNl = text.lastIndexOf("\n");
536
+ text = lastNl === -1 ? "" : text.slice(0, lastNl + 1);
537
+ index += 1;
538
+ continue;
539
+ }
540
+ if (ch === "\n") {
541
+ text += "\n";
542
+ index += 1;
543
+ continue;
544
+ }
545
+ if (ch === "\b") {
546
+ const trailing = TRAILING_SGR_REGEX.exec(text);
547
+ const sgrTail = trailing ? trailing[0] : "";
548
+ const head = sgrTail ? text.slice(0, -sgrTail.length) : text;
549
+ if (head.length > 0 && head[head.length - 1] !== "\n") {
550
+ text = head.slice(0, -1) + sgrTail;
551
+ }
552
+ index += 1;
553
+ continue;
554
+ }
555
+ const code = ch.charCodeAt(0);
556
+ if (code < 32 && ch !== " " || code === 127) {
557
+ index += 1;
558
+ continue;
559
+ }
560
+ text += ch;
561
+ index += 1;
562
+ }
563
+ return text;
564
+ }
565
+ function displayWidth(str) {
566
+ let width = 0;
567
+ for (const char of str) {
568
+ const code = char.codePointAt(0) ?? 0;
569
+ if (code < 32 || code === 127) continue;
570
+ if (code >= 4352 && code <= 4447 || // 0x2768-0x2775 (ornamental brackets, incl. the ❯ prompt at U+276F)
571
+ // render narrow in terminals; counting them wide drifts the cursor.
572
+ code >= 9728 && code <= 10175 && !(code >= 10088 && code <= 10101) || // 0x2B00-0x2BFF (Misc Symbols and Arrows, incl. ⬢ U+2B22 used as the
573
+ // status-line agent icon) render double-wide in common monospace fonts;
574
+ // counting ⬢ as width 1 drifts the whole status line right of the icon.
575
+ code >= 11008 && code <= 11263 || code >= 11904 && code <= 12350 || code >= 12352 && code <= 13247 || code >= 13312 && code <= 19903 || code >= 19968 && code <= 42191 || code >= 44032 && code <= 55203 || code >= 63744 && code <= 64255 || code >= 65072 && code <= 65135 || code >= 65281 && code <= 65376 || code >= 65504 && code <= 65510 || code >= 127744 && code <= 129791 || code >= 131072 && code <= 196605 || code >= 196608 && code <= 262141 || // East Asian Ambiguous CJK quotation marks (U+201C/D “ ”, U+2018/9 ‘ ’).
576
+ // In CJK locale + CJK fonts these render double-wide like 全角 punctuation;
577
+ // in English fonts they stay width 1. Follow the active locale so Chinese
578
+ // replies align correctly without breaking English terminal output.
579
+ getCliLocale() === "zh" && (code === 8220 || code === 8221 || code === 8216 || code === 8217)) {
580
+ width += 2;
581
+ } else {
582
+ width += 1;
583
+ }
584
+ }
585
+ return width;
586
+ }
587
+ function visibleWidth(str) {
588
+ return displayWidth(stripAnsi(str));
589
+ }
590
+ function truncateAnsi(text, maxWidth) {
591
+ if (maxWidth <= 0) return "";
592
+ if (visibleWidth(text) <= maxWidth) return text;
593
+ let width = 0;
594
+ let out = "";
595
+ let i = 0;
596
+ let sawAnsi = false;
597
+ while (i < text.length) {
598
+ if (text[i] === "\x1B" && text[i + 1] === "[") {
599
+ sawAnsi = true;
600
+ let j = i + 2;
601
+ while (j < text.length) {
602
+ const code = text.charCodeAt(j);
603
+ j += 1;
604
+ if (code >= 64 && code <= 126) break;
605
+ }
606
+ out += text.slice(i, j);
607
+ i = j;
608
+ continue;
609
+ }
610
+ const codePoint = text.codePointAt(i) ?? 0;
611
+ const char = String.fromCodePoint(codePoint);
612
+ const charWidth = displayWidth(char);
613
+ if (width + charWidth > maxWidth) break;
614
+ out += char;
615
+ width += charWidth;
616
+ i += char.length;
617
+ }
618
+ return sawAnsi ? `${out}\x1B[0m` : out;
619
+ }
620
+ function fitAnsiLine(text, width, ellipsis = "\u2026") {
621
+ if (width <= 0) return "";
622
+ if (visibleWidth(text) <= width) return text;
623
+ const ellipsisWidth = displayWidth(ellipsis);
624
+ if (width < ellipsisWidth) return truncateAnsi(text, width);
625
+ if (width === ellipsisWidth) return truncateAnsi(ellipsis, width) || truncateAnsi(text, width);
626
+ return `${truncateAnsi(text, width - ellipsisWidth)}${ellipsis}`;
627
+ }
628
+ function countPhysicalLines(text, columns) {
629
+ const lines = text.split("\n");
630
+ let total = 0;
631
+ for (const line of lines) {
632
+ const width = displayWidth(line);
633
+ total += Math.max(1, Math.ceil(width / columns));
634
+ }
635
+ return Math.max(total, 1);
636
+ }
637
+ function takeDisplayWidth(text, width) {
638
+ let used = 0;
639
+ let index = 0;
640
+ for (const char of text) {
641
+ const charWidth = displayWidth(char);
642
+ if (used + charWidth > width && used > 0) break;
643
+ used += charWidth;
644
+ index += char.length;
645
+ }
646
+ return { prefix: text.slice(0, index), rest: text.slice(index) };
647
+ }
648
+ function padOrTruncateToWidth(text, width) {
649
+ const textWidth = visibleWidth(text);
650
+ if (textWidth > width) {
651
+ return truncateAnsi(text, width);
652
+ }
653
+ return `${text}${" ".repeat(width - textWidth)}`;
654
+ }
655
+ var SGR_RESET_REGEX = /^\x1b\[0?m$/;
656
+ function tokenizeAnsiLine(line) {
657
+ const tokens = [];
658
+ let index = 0;
659
+ while (index < line.length) {
660
+ if (line[index] === "\x1B") {
661
+ const osc = line.slice(index).match(/^\x1b\]8;;[^\x07\x1b]*(?:\x07|\x1b\\)/);
662
+ if (osc) {
663
+ tokens.push({ kind: "sgr", value: osc[0], width: 0 });
664
+ index += osc[0].length;
665
+ continue;
666
+ }
667
+ const sgr = SGR_SEQUENCE_REGEX.exec(line.slice(index));
668
+ if (sgr) {
669
+ tokens.push({ kind: "sgr", value: sgr[0], width: 0 });
670
+ index += sgr[0].length;
671
+ continue;
672
+ }
673
+ }
674
+ const codePoint = line.codePointAt(index) ?? 0;
675
+ const value = String.fromCodePoint(codePoint);
676
+ tokens.push({ kind: "char", value, width: displayWidth(value) });
677
+ index += value.length;
678
+ }
679
+ return tokens;
680
+ }
681
+ function wrapTranscriptLine(line, columns, hangingIndent = "") {
682
+ if (line === "") return [""];
683
+ const tokens = tokenizeAnsiLine(line);
684
+ const result = [];
685
+ let activeStyles = [];
686
+ const applyStyleToken = (value) => {
687
+ if (SGR_RESET_REGEX.test(value)) {
688
+ activeStyles = [];
689
+ } else {
690
+ activeStyles.push(value);
691
+ }
692
+ };
693
+ let start = 0;
694
+ while (start < tokens.length) {
695
+ if (tokens.slice(start).every((token) => token.kind === "sgr")) {
696
+ if (result.length > 0) break;
697
+ }
698
+ const openingStyles = [...activeStyles];
699
+ const isContinuation = result.length > 0 && hangingIndent.length > 0;
700
+ const indentWidth = isContinuation ? displayWidth(hangingIndent) : 0;
701
+ const maxSegmentWidth = Math.max(1, columns - indentWidth);
702
+ let width = 0;
703
+ let end = start;
704
+ let lastBreak = -1;
705
+ while (end < tokens.length) {
706
+ const token = tokens[end];
707
+ if (token.kind === "sgr") {
708
+ end += 1;
709
+ continue;
710
+ }
711
+ if (width + token.width > maxSegmentWidth && width > 0) break;
712
+ width += token.width;
713
+ end += 1;
714
+ if (token.value === " " || token.value === " ") {
715
+ lastBreak = end;
716
+ }
717
+ }
718
+ let segmentEnd = end;
719
+ if (end < tokens.length && lastBreak > start) {
720
+ const overflowToken = tokens[end];
721
+ if (overflowToken.kind === "char" && overflowToken.value !== " " && overflowToken.width === 1) {
722
+ segmentEnd = lastBreak;
723
+ }
724
+ }
725
+ if (segmentEnd === start) segmentEnd = start + 1;
726
+ let segment = "";
727
+ let sawStyle = openingStyles.length > 0;
728
+ for (let i = start; i < segmentEnd; i += 1) {
729
+ const token = tokens[i];
730
+ segment += token.value;
731
+ if (token.kind === "sgr") {
732
+ sawStyle = true;
733
+ applyStyleToken(token.value);
734
+ }
735
+ }
736
+ const prefix = openingStyles.join("");
737
+ const needsReset = (sawStyle || activeStyles.length > 0) && !segment.endsWith("\x1B[0m");
738
+ const lineContent = `${prefix}${segment}${needsReset ? "\x1B[0m" : ""}`;
739
+ result.push(isContinuation ? `${hangingIndent}${lineContent}` : lineContent);
740
+ start = segmentEnd;
741
+ while (start < tokens.length) {
742
+ const token = tokens[start];
743
+ if (token.kind === "char" && token.value === " ") {
744
+ start += 1;
745
+ continue;
746
+ }
747
+ break;
748
+ }
749
+ }
750
+ return result.length > 0 ? result : [""];
240
751
  }
241
- function dimCliText(text, enabled = resolveCliColorEnabled()) {
242
- return styleCliText(text, "dim", enabled);
752
+ function wrapTextToLines(text, columns) {
753
+ const result = [];
754
+ for (const logicalLine of text.split("\n")) {
755
+ if (logicalLine === "") {
756
+ result.push("");
757
+ continue;
758
+ }
759
+ let remaining = logicalLine;
760
+ while (remaining.length > 0) {
761
+ const { prefix, rest } = takeDisplayWidth(remaining, columns);
762
+ result.push(prefix);
763
+ remaining = rest;
764
+ }
765
+ }
766
+ return result;
243
767
  }
244
768
 
245
769
  // packages/cli/tui/theme.ts
@@ -402,8 +926,24 @@ function getActiveDensity() {
402
926
  function setActiveDensity(density) {
403
927
  activeDensity = density;
404
928
  }
929
+ var TRUECOLOR_TERM_PROGRAMS = /* @__PURE__ */ new Set([
930
+ "iterm.app",
931
+ "wezterm",
932
+ "ghostty",
933
+ "vscode",
934
+ "hyper",
935
+ "tabby",
936
+ "rio",
937
+ "warpterminal"
938
+ ]);
405
939
  function supportsTruecolor(env = process.env) {
406
- return /truecolor|24bit/i.test(env.COLORTERM ?? "");
940
+ const explicit = (env.NOLO_TUI_TRUECOLOR ?? "").trim().toLowerCase();
941
+ if (explicit === "1" || explicit === "true") return true;
942
+ if (explicit === "0" || explicit === "false") return false;
943
+ if (/truecolor|24bit/i.test(env.COLORTERM ?? "")) return true;
944
+ if (/direct|24bit/i.test(env.TERM ?? "")) return true;
945
+ const program = (env.TERM_PROGRAM ?? "").toLowerCase();
946
+ return TRUECOLOR_TERM_PROGRAMS.has(program);
407
947
  }
408
948
  function resolveTuiBrightness(env = process.env) {
409
949
  const explicit = (env.NOLO_TUI_THEME ?? "").trim().toLowerCase();
@@ -437,6 +977,17 @@ var TERMINAL_BASE = {
437
977
  dark: "1E1E2E",
438
978
  light: "FFFFFF"
439
979
  };
980
+ var activeTerminalBaseHex = null;
981
+ function setActiveTerminalBaseHex(hex) {
982
+ if (hex === null) {
983
+ activeTerminalBaseHex = null;
984
+ return;
985
+ }
986
+ activeTerminalBaseHex = readHexChannels(hex.replace(/^#/, "").toUpperCase()) ? hex.replace(/^#/, "").toUpperCase() : null;
987
+ }
988
+ function resolveTerminalBaseHex(brightness) {
989
+ return activeTerminalBaseHex ?? TERMINAL_BASE[brightness];
990
+ }
440
991
  function readHexChannels(hex) {
441
992
  if (!/^[0-9A-F]{6}$/.test(hex)) return null;
442
993
  return [
@@ -474,21 +1025,49 @@ function diffLineSequences(env = process.env, brightness = resolveTuiBrightness(
474
1025
  const palette = THEME_PALETTES[activeThemeName] ?? THEME_PALETTES.trail;
475
1026
  const successHex = palette[brightness].success.hex;
476
1027
  const dangerHex = palette[brightness].danger.hex;
477
- const weight = brightness === "dark" ? 0.14 : 0.1;
478
- const baseHex = TERMINAL_BASE[brightness];
1028
+ const infoHex = palette[brightness].info.hex;
1029
+ const weight = brightness === "dark" ? 0.18 : 0.12;
1030
+ const baseHex = resolveTerminalBaseHex(brightness);
479
1031
  const addedBgHex = blendHex(successHex, baseHex, weight);
480
1032
  const removedBgHex = blendHex(dangerHex, baseHex, weight);
1033
+ const hunkBgHex = blendHex(infoHex, baseHex, weight * 0.6);
1034
+ const successSgr = hexToSgr(successHex);
1035
+ const dangerSgr = hexToSgr(dangerHex);
1036
+ const infoSgr = hexToSgr(infoHex);
481
1037
  return {
482
1038
  added: {
483
- fg: hexToSgr(successHex),
484
- bg: hexToBgSgr(addedBgHex)
1039
+ fg: successSgr,
1040
+ bg: hexToBgSgr(addedBgHex),
1041
+ bar: `${successSgr}\u258C\x1B[39m`
485
1042
  },
486
1043
  removed: {
487
- fg: hexToSgr(dangerHex),
488
- bg: hexToBgSgr(removedBgHex)
489
- }
1044
+ fg: dangerSgr,
1045
+ bg: hexToBgSgr(removedBgHex),
1046
+ bar: `${dangerSgr}\u258C\x1B[39m`
1047
+ },
1048
+ hunk: {
1049
+ fg: infoSgr,
1050
+ bg: hexToBgSgr(hunkBgHex),
1051
+ bar: " "
1052
+ },
1053
+ context: { fg: "", bg: "", bar: " " }
490
1054
  };
491
1055
  }
1056
+ function renderDiffLine(args) {
1057
+ const { kind, text } = args;
1058
+ const env = args.env ?? process.env;
1059
+ const colorEnabled = args.colorEnabled ?? resolveCliColorEnabled();
1060
+ if (!colorEnabled) return text;
1061
+ const seqs = diffLineSequences(env);
1062
+ if (!seqs) {
1063
+ if (kind === "context") return text;
1064
+ const token = kind === "added" ? "success" : kind === "removed" ? "danger" : "info";
1065
+ return `${themeColorSequence(token, env)}${text}\x1B[39m`;
1066
+ }
1067
+ const seq = seqs[kind];
1068
+ const padding = args.padTo === void 0 ? "" : " ".repeat(Math.max(0, args.padTo - displayWidth(text)));
1069
+ return `${seq.bar}${seq.bg}${seq.fg}${text}${padding}\x1B[0m`;
1070
+ }
492
1071
  function surfaceBackgroundSequence(env = process.env, brightness = resolveTuiBrightness(env)) {
493
1072
  if (!supportsTruecolor(env)) return "";
494
1073
  return hexToBgSgr((SURFACE_HEX[activeThemeName] ?? SURFACE_HEX.trail)[brightness]);
@@ -502,69 +1081,11 @@ function themeText(text, token, colorEnabled = resolveCliColorEnabled(), env = p
502
1081
  if (!colorEnabled) return text;
503
1082
  return `${themeColorSequence(token, env)}${text}\x1B[39m`;
504
1083
  }
505
- function renderDiffCodeBlock(code, env = process.env) {
506
- const border = themeText("\u2502", "chrome", true, env);
507
- const addedColor = themeColorSequence("success", env);
508
- const deletedColor = themeColorSequence("danger", env);
509
- const hunkColor = themeColorSequence("info", env);
510
- const contextColor = themeColorSequence("chrome", env);
511
- const reset = "\x1B[0m";
512
- const lines = code.split("\n").map((line) => {
513
- let color = contextColor;
514
- if (line.startsWith("@@")) {
515
- color = hunkColor;
516
- } else if (line.startsWith("+") && !line.startsWith("+++")) {
517
- color = addedColor;
518
- } else if (line.startsWith("-") && !line.startsWith("---")) {
519
- color = deletedColor;
520
- }
521
- return ` ${border} ${color}${line}${reset}`;
522
- });
523
- return ` ${themeText("\u250C\u2500\u2500\u2500", "chrome", true, env)}
524
- ${lines.join("\n")}
525
- ${themeText("\u2514\u2500\u2500\u2500", "chrome", true, env)}`;
526
- }
527
- function highlightMarkdown(text, colorEnabled = resolveCliColorEnabled(), env = process.env) {
528
- if (!colorEnabled) return text;
529
- let result = text;
530
- result = result.replace(/```([a-zA-Z-]*)\n([\s\S]*?)\n```/g, (match, lang, code) => {
531
- if (lang.toLowerCase() === "diff") {
532
- return renderDiffCodeBlock(code, env);
533
- }
534
- const infoColor = themeColorSequence("info", env);
535
- const reset2 = "\x1B[39m\x1B[22m";
536
- const border = themeText("\u2502", "chrome", true, env);
537
- const formattedCode = code.split("\n").map((line) => ` ${border} ${infoColor}${line}${reset2}`).join("\n");
538
- return ` ${themeText("\u250C\u2500\u2500\u2500", "chrome", true, env)}
539
- ${formattedCode}
540
- ${themeText("\u2514\u2500\u2500\u2500", "chrome", true, env)}`;
541
- });
542
- result = result.replace(/^(#{1,3})\s+(.+)$/gm, (match, hashes, title) => {
543
- const level = hashes.length;
544
- const reset2 = "\x1B[0m";
545
- if (level === 1) {
546
- return `\x1B[1m\x1B[4m${themeColorSequence("accent", env)}${title}${reset2}`;
547
- }
548
- if (level === 2) {
549
- return `\x1B[1m${themeColorSequence("warning", env)}${title}${reset2}`;
550
- }
551
- return `\x1B[1m${themeColorSequence("info", env)}${title}${reset2}`;
552
- });
553
- result = result.replace(
554
- /^(进入 nolo-plan[^\n]*)$/gm,
555
- (match, content) => `${themeColorSequence("chrome", env)}\x1B[2m${content}\x1B[0m`
556
- );
557
- result = result.replace(/^>\s?(.*)$/gm, (match, content) => {
558
- const border = themeColorSequence("chrome", env);
559
- return `${border}\u2502\x1B[39m \x1B[2m${content}\x1B[22m`;
560
- });
561
- result = result.replace(/\*\*([\s\S]*?)\*\*/g, "\x1B[1m$1\x1B[22m");
562
- const mutedColor = themeColorSequence("muted", env);
563
- const reset = "\x1B[39m";
564
- result = result.replace(/`([^`\n]+)`/g, `${mutedColor}$1${reset}`);
565
- result = result.replace(/(?<!\*)\*([^*\n]+?)\*(?!\*)/g, `\x1B[2m$1\x1B[22m`);
566
- result = result.replace(/~~([^~\n]+?)~~/g, `\x1B[2m\x1B[9m$1\x1B[29m\x1B[22m`);
567
- return result;
1084
+ function classifyDiffLine(line) {
1085
+ if (line.startsWith("@@")) return "hunk";
1086
+ if (line.startsWith("+") && !line.startsWith("+++")) return "added";
1087
+ if (line.startsWith("-") && !line.startsWith("---")) return "removed";
1088
+ return "context";
568
1089
  }
569
1090
 
570
1091
  // packages/cli/client/assistantOutput.ts
@@ -743,20 +1264,7 @@ function highlightCodeLine(line, lang, brightness) {
743
1264
  return `${info}${line}${STYLE.reset}`;
744
1265
  }
745
1266
  if (lang === "diff") {
746
- const added = colorSeq("success", brightness);
747
- const deleted = colorSeq("danger", brightness);
748
- const hunk = colorSeq("info", brightness);
749
- const context = colorSeq("chrome", brightness);
750
- const reset2 = STYLE.reset;
751
- let color = context;
752
- if (line.startsWith("@@")) {
753
- color = hunk;
754
- } else if (line.startsWith("+") && !line.startsWith("+++")) {
755
- color = added;
756
- } else if (line.startsWith("-") && !line.startsWith("---")) {
757
- color = deleted;
758
- }
759
- return `${color}${line}${reset2}`;
1267
+ return renderDiffLine({ kind: classifyDiffLine(line), text: line, colorEnabled: true });
760
1268
  }
761
1269
  const regions = scanStringCommentRegions(line, lang);
762
1270
  const keywords = KEYWORDS[lang];
@@ -953,7 +1461,7 @@ function styleRichMarkdownLine(line, brightness) {
953
1461
  const ordered = line.match(/^(\s*)(\d+\.)\s(.+)$/);
954
1462
  if (ordered) {
955
1463
  const styled = styleInlineMarkdown(ordered[3], brightness);
956
- return `${ordered[1]}${colorSeq("accent", brightness)}${ordered[2]}${STYLE.reset} ${styled}`;
1464
+ return `${ordered[1]}${colorSeq("chrome", brightness)}${ordered[2]}${STYLE.reset} ${styled}`;
957
1465
  }
958
1466
  const task = line.match(/^(\s*)(☐|☑)\s(.+)$/);
959
1467
  if (task) {
@@ -1354,456 +1862,254 @@ function formatFetchTreeLines(items) {
1354
1862
  return { header, count, lines };
1355
1863
  }
1356
1864
 
1357
- // packages/cli/tui/i18n.ts
1358
- var ZH_PATTERNS = /^zh/i;
1359
- function parseCliLocale(raw) {
1360
- const normalized = raw?.trim().toLowerCase();
1361
- if (!normalized) return null;
1362
- if (ZH_PATTERNS.test(normalized)) return "zh";
1363
- if (normalized === "en" || normalized.startsWith("en")) return "en";
1364
- return null;
1365
- }
1366
- function detectLocaleFromEnv(env) {
1367
- const explicit = parseCliLocale(env.NOLO_LANG);
1368
- if (explicit) return explicit;
1369
- const candidates = [env.LC_ALL, env.LC_CTYPE, env.LANG].filter(Boolean);
1370
- for (const candidate of candidates) {
1371
- if (ZH_PATTERNS.test(candidate)) return "zh";
1372
- if (candidate && !candidate.startsWith("C.") && !candidate.startsWith("POSIX")) {
1373
- return "en";
1865
+ // packages/cli/node_modules/diff/libesm/diff/base.js
1866
+ var Diff = class {
1867
+ diff(oldStr, newStr, options = {}) {
1868
+ let callback;
1869
+ if (typeof options === "function") {
1870
+ callback = options;
1871
+ options = {};
1872
+ } else if ("callback" in options) {
1873
+ callback = options.callback;
1874
+ }
1875
+ const oldString = this.castInput(oldStr, options);
1876
+ const newString = this.castInput(newStr, options);
1877
+ const oldTokens = this.removeEmpty(this.tokenize(oldString, options));
1878
+ const newTokens = this.removeEmpty(this.tokenize(newString, options));
1879
+ return this.diffWithOptionsObj(oldTokens, newTokens, options, callback);
1880
+ }
1881
+ diffWithOptionsObj(oldTokens, newTokens, options, callback) {
1882
+ var _a;
1883
+ const done = (value) => {
1884
+ value = this.postProcess(value, options);
1885
+ if (callback) {
1886
+ setTimeout(function() {
1887
+ callback(value);
1888
+ }, 0);
1889
+ return void 0;
1890
+ } else {
1891
+ return value;
1892
+ }
1893
+ };
1894
+ const newLen = newTokens.length, oldLen = oldTokens.length;
1895
+ let editLength = 1;
1896
+ let maxEditLength = newLen + oldLen;
1897
+ if (options.maxEditLength != null) {
1898
+ maxEditLength = Math.min(maxEditLength, options.maxEditLength);
1899
+ }
1900
+ const maxExecutionTime = (_a = options.timeout) !== null && _a !== void 0 ? _a : Infinity;
1901
+ const abortAfterTimestamp = Date.now() + maxExecutionTime;
1902
+ const bestPath = [{ oldPos: -1, lastComponent: void 0 }];
1903
+ let newPos = this.extractCommon(bestPath[0], newTokens, oldTokens, 0, options);
1904
+ if (bestPath[0].oldPos + 1 >= oldLen && newPos + 1 >= newLen) {
1905
+ return done(this.buildValues(bestPath[0].lastComponent, newTokens, oldTokens));
1906
+ }
1907
+ let minDiagonalToConsider = -Infinity, maxDiagonalToConsider = Infinity;
1908
+ const execEditLength = () => {
1909
+ for (let diagonalPath = Math.max(minDiagonalToConsider, -editLength); diagonalPath <= Math.min(maxDiagonalToConsider, editLength); diagonalPath += 2) {
1910
+ let basePath;
1911
+ const removePath = bestPath[diagonalPath - 1], addPath = bestPath[diagonalPath + 1];
1912
+ if (removePath) {
1913
+ bestPath[diagonalPath - 1] = void 0;
1914
+ }
1915
+ let canAdd = false;
1916
+ if (addPath) {
1917
+ const addPathNewPos = addPath.oldPos - diagonalPath;
1918
+ canAdd = addPath && 0 <= addPathNewPos && addPathNewPos < newLen;
1919
+ }
1920
+ const canRemove = removePath && removePath.oldPos + 1 < oldLen;
1921
+ if (!canAdd && !canRemove) {
1922
+ bestPath[diagonalPath] = void 0;
1923
+ continue;
1924
+ }
1925
+ if (!canRemove || canAdd && removePath.oldPos < addPath.oldPos) {
1926
+ basePath = this.addToPath(addPath, true, false, 0, options);
1927
+ } else {
1928
+ basePath = this.addToPath(removePath, false, true, 1, options);
1929
+ }
1930
+ newPos = this.extractCommon(basePath, newTokens, oldTokens, diagonalPath, options);
1931
+ if (basePath.oldPos + 1 >= oldLen && newPos + 1 >= newLen) {
1932
+ return done(this.buildValues(basePath.lastComponent, newTokens, oldTokens)) || true;
1933
+ } else {
1934
+ bestPath[diagonalPath] = basePath;
1935
+ if (basePath.oldPos + 1 >= oldLen) {
1936
+ maxDiagonalToConsider = Math.min(maxDiagonalToConsider, diagonalPath - 1);
1937
+ }
1938
+ if (newPos + 1 >= newLen) {
1939
+ minDiagonalToConsider = Math.max(minDiagonalToConsider, diagonalPath + 1);
1940
+ }
1941
+ }
1942
+ }
1943
+ editLength++;
1944
+ };
1945
+ if (callback) {
1946
+ (function exec() {
1947
+ setTimeout(function() {
1948
+ if (editLength > maxEditLength || Date.now() > abortAfterTimestamp) {
1949
+ return callback(void 0);
1950
+ }
1951
+ if (!execEditLength()) {
1952
+ exec();
1953
+ }
1954
+ }, 0);
1955
+ })();
1956
+ } else {
1957
+ while (editLength <= maxEditLength && Date.now() <= abortAfterTimestamp) {
1958
+ const ret = execEditLength();
1959
+ if (ret) {
1960
+ return ret;
1961
+ }
1962
+ }
1374
1963
  }
1375
1964
  }
1376
- return null;
1377
- }
1378
- function detectLocale(env) {
1379
- return detectLocaleFromEnv(env) ?? "zh";
1380
- }
1381
- var currentLocale = detectLocale(process.env);
1382
- function getCliLocale() {
1383
- return currentLocale;
1384
- }
1385
- function setCliLocale(locale) {
1386
- currentLocale = locale;
1387
- }
1388
- function initCliLocale(env = process.env) {
1389
- currentLocale = detectLocale(env);
1390
- }
1391
- var STRINGS = {
1392
- welcomeHint: {
1393
- en: "Tell nolo what you want. Use /help for commands. Shift+Enter for newline.",
1394
- zh: "\u544A\u8BC9 nolo \u4F60\u60F3\u8981\u4EC0\u4E48\u3002\u8F93\u5165 /help \u67E5\u770B\u547D\u4EE4\u3002Shift+Enter \u6362\u884C\u3002"
1395
- },
1396
- promptLabel: {
1397
- en: "\u276F ",
1398
- zh: "\u276F "
1399
- },
1400
- continueLabel: {
1401
- en: "\u2502 ",
1402
- zh: "\u2502 "
1403
- },
1404
- placeholder: {
1405
- en: "Type a message or / for commands...",
1406
- zh: "\u8F93\u5165\u6D88\u606F\uFF0C\u6216\u7528 / \u67E5\u770B\u547D\u4EE4\u2026"
1407
- },
1408
- newDialog: {
1409
- en: "new dialog",
1410
- zh: "\u65B0\u5BF9\u8BDD"
1411
- },
1412
- startedFreshDialog: {
1413
- en: "Started a fresh dialog.",
1414
- zh: "\u5DF2\u5F00\u59CB\u65B0\u5BF9\u8BDD\u3002"
1415
- },
1416
- bye: {
1417
- en: "Bye.",
1418
- zh: "\u518D\u89C1\u3002"
1419
- },
1420
- resumedDialogPrefix: {
1421
- en: "Resumed dialog",
1422
- zh: "\u5DF2\u6062\u590D\u5BF9\u8BDD"
1423
- },
1424
- resumeInvalidId: {
1425
- en: "does not look like a dialog id. Use /history to pick one.",
1426
- zh: "\u770B\u8D77\u6765\u4E0D\u662F dialog id\u3002\u7528 /history \u4ECE\u5217\u8868\u91CC\u9009\u4E00\u4E2A\u3002"
1427
- },
1428
- dialogResumeCancelled: {
1429
- en: "Dialog resume cancelled.",
1430
- zh: "\u5DF2\u53D6\u6D88\u6062\u590D\u5BF9\u8BDD\u3002"
1431
- },
1432
- agentSwitchCancelled: {
1433
- en: "Agent switch cancelled.",
1434
- zh: "\u5DF2\u53D6\u6D88\u5207\u6362 agent\u3002"
1435
- },
1436
- historyPickerTitle: {
1437
- en: "Resume dialog (\u2191\u2193 Enter Esc)",
1438
- zh: "\u6062\u590D\u5BF9\u8BDD\uFF08\u2191\u2193 \u79FB\u52A8 \xB7 Enter \u9009\u62E9 \xB7 Esc \u53D6\u6D88\uFF09"
1439
- },
1440
- noDialogsYet: {
1441
- en: "No dialogs yet.",
1442
- zh: "\u8FD8\u6CA1\u6709\u5386\u53F2\u5BF9\u8BDD\u3002"
1443
- },
1444
- langUsage: {
1445
- en: "Usage: /lang <zh|en>",
1446
- zh: "\u7528\u6CD5\uFF1A/lang <zh|en>"
1447
- },
1448
- stopHint: {
1449
- en: "Esc to stop",
1450
- zh: "Esc \u505C\u6B62\u56DE\u590D"
1451
- },
1452
- queuedHint: {
1453
- en: "queued",
1454
- zh: "\u6392\u961F"
1455
- },
1456
- turnStopped: {
1457
- en: "Stopped this reply.",
1458
- zh: "\u5DF2\u505C\u6B62\u672C\u6B21\u56DE\u590D\u3002"
1459
- },
1460
- turnFailed: {
1461
- en: "This reply failed. Queued messages are kept \u2014 press Enter to resend.",
1462
- zh: "\u672C\u6B21\u56DE\u590D\u51FA\u9519\u3002\u5DF2\u6392\u961F\u7684\u6D88\u606F\u4ECD\u4FDD\u7559\uFF0C\u6309 Enter \u53EF\u91CD\u65B0\u53D1\u9001\u3002"
1463
- },
1464
- quotaExhaustedHint: {
1465
- en: "[nolo] This agent seems to have hit a quota/rate limit (HTTP 429).\nUse /agent to switch to another agent and keep going \u2014 the dialog context is preserved.",
1466
- zh: "[nolo] \u5F53\u524D agent \u4F3C\u4E4E\u989D\u5EA6/\u901F\u7387\u53D7\u9650\uFF08429\uFF09\u3002\n\u53EF\u4EE5\u7528 /agent \u5207\u6362\u5230\u5176\u4ED6 agent \u540E\u7EE7\u7EED\uFF0C\u540C\u4E00\u5BF9\u8BDD\u4F1A\u4FDD\u7559\u4E0A\u4E0B\u6587\u3002"
1467
- },
1468
- balanceExhaustedHint: {
1469
- en: '[nolo] Insufficient balance. Your message is saved in this dialog \u2014 top up, then send again or say "continue".',
1470
- zh: "[nolo] \u4F59\u989D\u4E0D\u8DB3\u3002\u4F60\u521A\u53D1\u7684\u8BDD\u5DF2\u4FDD\u5B58\u5728\u5F53\u524D\u5BF9\u8BDD\u91CC\u2014\u2014\u5145\u503C\u540E\u76F4\u63A5\u518D\u8BF4\u4E00\u53E5\u6216\u8BF4\u300C\u7EE7\u7EED\u300D\u5373\u53EF\uFF0C\u4E0D\u4F1A\u4E22\u4E0A\u4E0B\u6587\u3002"
1471
- },
1472
- dialogPreservedHint: {
1473
- en: '[nolo] This turn failed, but the dialog is kept. Send another message (or say "continue") to keep going in the same conversation.',
1474
- zh: "[nolo] \u672C\u8F6E\u5931\u8D25\u4E86\uFF0C\u4F46\u5BF9\u8BDD\u5DF2\u4FDD\u7559\u3002\u76F4\u63A5\u518D\u8BF4\u4E00\u53E5\uFF08\u6216\u8BF4\u300C\u7EE7\u7EED\u300D\uFF09\u5373\u53EF\u5728\u540C\u4E00\u5BF9\u8BDD\u91CC\u63A5\u7740\u804A\u3002"
1475
- },
1476
- dialogNotSavedHint: {
1477
- en: "[nolo] This turn did not create a dialog. Your next message will start a new conversation \u2014 restate what you need.",
1478
- zh: "[nolo] \u672C\u8F6E\u6CA1\u6709\u5EFA\u6210\u5BF9\u8BDD\u3002\u4E0B\u4E00\u53E5\u4F1A\u662F\u65B0\u5BF9\u8BDD\u2014\u2014\u8BF7\u628A\u4F60\u60F3\u505A\u7684\u4E8B\u518D\u8BF4\u4E00\u904D\u3002"
1479
- },
1480
- copiedLastReply: {
1481
- en: "Copied the last reply to the clipboard.",
1482
- zh: "\u5DF2\u590D\u5236\u6700\u540E\u4E00\u6761\u56DE\u590D\u5230\u526A\u8D34\u677F\u3002"
1483
- },
1484
- copyNothing: {
1485
- en: "Nothing to copy yet.",
1486
- zh: "\u8FD8\u6CA1\u6709\u53EF\u590D\u5236\u7684\u5185\u5BB9\u3002"
1487
- },
1488
- copyFailed: {
1489
- en: "Copy failed",
1490
- zh: "\u590D\u5236\u5931\u8D25"
1491
- },
1492
- copyUnavailable: {
1493
- en: "Clipboard is unavailable in this environment. The last reply was printed above for manual copy.",
1494
- zh: "\u5F53\u524D\u73AF\u5883\u6CA1\u6709\u53EF\u7528\u7684\u526A\u8D34\u677F\u3002\u6700\u540E\u4E00\u6761\u56DE\u590D\u5DF2\u6253\u5370\u5728\u4E0A\u65B9\uFF0C\u53EF\u624B\u52A8\u590D\u5236\u3002"
1495
- },
1496
- copyUsage: {
1497
- en: "Usage: /copy or /copy view",
1498
- zh: "\u7528\u6CD5\uFF1A/copy \u6216 /copy view"
1499
- },
1500
- copyViewTitle: {
1501
- en: "Copy view \u2014 latest AI reply",
1502
- zh: "\u590D\u5236\u89C6\u56FE \u2014 \u6700\u65B0 AI \u56DE\u590D"
1503
- },
1504
- copyViewHint: {
1505
- en: "Drag to select; edge scrolling uses native terminal scrollback. Press Esc or Enter to return.",
1506
- zh: "\u76F4\u63A5\u62D6\u9009\uFF0C\u62D6\u5230\u8FB9\u7F18\u53EF\u7528\u7EC8\u7AEF\u539F\u751F\u56DE\u6EDA\u8DE8\u5C4F\u9009\u62E9\u3002\u6309 Esc \u6216 Enter \u8FD4\u56DE\u3002"
1507
- },
1508
- historyNoToken: {
1509
- en: "History requires an auth token. Run `nolo login` or set AUTH_TOKEN.",
1510
- zh: "\u67E5\u770B\u5386\u53F2\u5BF9\u8BDD\u9700\u8981\u767B\u5F55\u51ED\u8BC1\u3002\u8BF7\u8FD0\u884C `nolo login` \u6216\u8BBE\u7F6E AUTH_TOKEN\u3002"
1511
- },
1512
- historyBadToken: {
1513
- en: "Could not read a user id from AUTH_TOKEN. Run `nolo login` again.",
1514
- zh: "\u65E0\u6CD5\u4ECE AUTH_TOKEN \u89E3\u6790\u51FA\u7528\u6237 id\uFF0C\u8BF7\u91CD\u65B0\u8FD0\u884C `nolo login`\u3002"
1515
- },
1516
- mouseOn: {
1517
- en: "Mouse mode on: wheel scrolls the transcript; hold Shift (or Option/Fn) to select text.",
1518
- zh: "\u9F20\u6807\u6A21\u5F0F\u5DF2\u5F00\u542F\uFF1A\u6EDA\u8F6E\u6EDA\u52A8\u5BF9\u8BDD\u8BB0\u5F55\uFF1B\u6309\u4F4F Shift\uFF08\u6216 Option/Fn\uFF09\u53EF\u62D6\u9009\u590D\u5236\u3002"
1519
- },
1520
- mouseOff: {
1521
- en: "Mouse mode off: drag to select/copy freely; scroll with PageUp/PageDown.",
1522
- zh: "\u9F20\u6807\u6A21\u5F0F\u5DF2\u5173\u95ED\uFF1A\u53EF\u76F4\u63A5\u62D6\u9009\u590D\u5236\uFF1B\u7528 PageUp/PageDown \u6EDA\u52A8\u5BF9\u8BDD\u8BB0\u5F55\u3002"
1523
- },
1524
- mouseUsage: {
1525
- en: "Usage: /mouse <on|off>",
1526
- zh: "\u7528\u6CD5\uFF1A/mouse <on|off>"
1527
- },
1528
- langSwitched: {
1529
- en: "Language switched to English.",
1530
- zh: "\u5DF2\u5207\u6362\u4E3A\u4E2D\u6587\u3002"
1531
- },
1532
- // --- Tool trace copy ------------------------------------------------------
1533
- // The compact trace shows only status, never timing or output size: a line
1534
- // count told the user nothing actionable and the ms figure read as noise.
1535
- toolNeedsAction: {
1536
- en: "needs action",
1537
- zh: "\u5F85\u786E\u8BA4"
1538
- },
1539
- toolTimedOut: {
1540
- en: "timed out",
1541
- zh: "\u5DF2\u8D85\u65F6"
1542
- },
1543
- toolExitCode: {
1544
- en: "exit",
1545
- zh: "\u9000\u51FA\u7801"
1546
- },
1547
- toolFailed: {
1548
- en: "failed",
1549
- zh: "\u5931\u8D25"
1550
- },
1551
- // --- Dialog (picker / confirm) copy --------------------------------------
1552
- // Key-hint wording is unified across select / multi-select / confirm so the
1553
- // three dialogs read as one family: "<Label> <↑↓ move · Enter choose ·
1554
- // Esc cancel> <count>". Connectors are "·" between keys, two spaces between
1555
- // the label, hint, and count. zh uses full-width parentheses to match the
1556
- // existing historyPickerTitle; en uses ASCII parentheses.
1557
- dialogSelectLabel: {
1558
- en: "Select",
1559
- zh: "\u9009\u62E9"
1560
- },
1561
- dialogSelectHint: {
1562
- en: "(\u2191\u2193 move \xB7 Enter choose \xB7 Esc cancel)",
1563
- zh: "\uFF08\u2191\u2193 \u79FB\u52A8 \xB7 Enter \u9009\u62E9 \xB7 Esc \u53D6\u6D88\uFF09"
1564
- },
1565
- dialogMultiSelectLabel: {
1566
- en: "Select",
1567
- zh: "\u9009\u62E9"
1568
- },
1569
- dialogMultiSelectHint: {
1570
- en: "(\u2191\u2193 move \xB7 Space toggle \xB7 Enter submit \xB7 Esc cancel)",
1571
- zh: "\uFF08\u2191\u2193 \u79FB\u52A8 \xB7 Space \u5207\u6362 \xB7 Enter \u63D0\u4EA4 \xB7 Esc \u53D6\u6D88\uFF09"
1572
- },
1573
- dialogMultiSelectSelected: {
1574
- en: "selected",
1575
- zh: "\u5DF2\u9009"
1576
- },
1577
- dialogConfirmHint: {
1578
- en: "(\u2191\u2193 move \xB7 Enter choose \xB7 Esc cancel)",
1579
- zh: "\uFF08\u2191\u2193 \u79FB\u52A8 \xB7 Enter \u9009\u62E9 \xB7 Esc \u53D6\u6D88\uFF09"
1580
- },
1581
- dialogConfirmTitle: {
1582
- en: "Confirm destructive shell command",
1583
- zh: "\u786E\u8BA4\u6267\u884C\u7834\u574F\u6027 shell \u547D\u4EE4"
1584
- },
1585
- dialogConfirmBody: {
1586
- en: "This command may delete or reset user content and needs explicit confirmation before it runs.",
1587
- zh: "\u8BE5\u547D\u4EE4\u53EF\u80FD\u5220\u9664\u6216\u91CD\u7F6E\u7528\u6237\u5185\u5BB9\uFF0C\u9700\u8981\u7528\u6237\u660E\u786E\u786E\u8BA4\u540E\u624D\u80FD\u6267\u884C\u3002"
1588
- },
1589
- dialogConfirmCommandLabel: {
1590
- en: "Command",
1591
- zh: "\u547D\u4EE4"
1592
- },
1593
- dialogConfirmCommandTruncated: {
1594
- en: "(truncated)",
1595
- zh: "\uFF08\u5DF2\u622A\u65AD\uFF09"
1596
- },
1597
- dialogConfirmAllowLabel: {
1598
- en: "Allow",
1599
- zh: "\u5141\u8BB8"
1600
- },
1601
- dialogConfirmAllowDetail: {
1602
- en: "execute this time",
1603
- zh: "\u672C\u6B21\u6267\u884C"
1604
- },
1605
- dialogConfirmCancelLabel: {
1606
- en: "Cancel",
1607
- zh: "\u53D6\u6D88"
1608
- },
1609
- dialogConfirmCancelDetail: {
1610
- en: "abort the operation",
1611
- zh: "\u4E2D\u6B62\u64CD\u4F5C"
1612
- },
1613
- contextTitle: {
1614
- en: "Workspace context",
1615
- zh: "\u5DE5\u4F5C\u533A\u4E0A\u4E0B\u6587"
1616
- },
1617
- contextNext: {
1618
- en: "Next:",
1619
- zh: "\u4E0B\u4E00\u6B65\uFF1A"
1620
- },
1621
- contextFieldAgent: {
1622
- en: "agent",
1623
- zh: "\u667A\u80FD\u4F53"
1624
- },
1625
- contextFieldTokens: {
1626
- en: "tokens",
1627
- zh: "\u4EE4\u724C"
1628
- },
1629
- contextFieldDialog: {
1630
- en: "dialog",
1631
- zh: "\u5BF9\u8BDD"
1632
- },
1633
- contextFieldDocs: {
1634
- en: "docs",
1635
- zh: "\u6587\u6863"
1636
- },
1637
- contextFieldSkills: {
1638
- en: "skills",
1639
- zh: "\u6280\u80FD"
1640
- },
1641
- contextFieldProfile: {
1642
- en: "profile",
1643
- zh: "\u914D\u7F6E"
1644
- },
1645
- contextFieldRuntime: {
1646
- en: "runtime",
1647
- zh: "\u8FD0\u884C\u65F6"
1648
- },
1649
- contextFieldTools: {
1650
- en: "tools",
1651
- zh: "\u5DE5\u5177"
1652
- },
1653
- contextFieldThinking: {
1654
- en: "thinking",
1655
- zh: "\u601D\u8003"
1656
- },
1657
- contextFieldServer: {
1658
- en: "server",
1659
- zh: "\u670D\u52A1\u7AEF"
1660
- },
1661
- contextNextAgents: {
1662
- en: "see specialist shortcuts",
1663
- zh: "\u67E5\u770B\u4E13\u7528\u667A\u80FD\u4F53\u5FEB\u6377\u65B9\u5F0F"
1664
- },
1665
- contextNextDoc: {
1666
- en: "add working context",
1667
- zh: "\u6DFB\u52A0\u5DE5\u4F5C\u4E0A\u4E0B\u6587"
1668
- },
1669
- contextNextSkill: {
1670
- en: "attach a skill to this workspace",
1671
- zh: "\u4E3A\u8BE5\u5DE5\u4F5C\u533A\u6302\u8F7D\u6280\u80FD"
1672
- },
1673
- contextNextNew: {
1674
- en: "start a clean dialog",
1675
- zh: "\u5F00\u59CB\u4E00\u4E2A\u5E72\u51C0\u7684\u5BF9\u8BDD"
1676
- },
1677
- agentsTitle: {
1678
- en: "Agents:",
1679
- zh: "\u667A\u80FD\u4F53\uFF1A"
1680
- },
1681
- agentsTip: {
1682
- en: "Tip: run /switch for the full picker, or /switch list for your private agents too.",
1683
- zh: "\u63D0\u793A\uFF1A\u7528 /switch \u6253\u5F00\u5B8C\u6574\u9009\u62E9\u5668\uFF0C\u6216 /switch list \u8FDE\u4F60\u7684\u79C1\u6709\u667A\u80FD\u4F53\u4E00\u8D77\u5217\u51FA\u3002"
1684
- },
1685
- helpText: {
1686
- en: [
1687
- "Commands:",
1688
- " /help Show this help",
1689
- " /new Clear screen and start a fresh dialog",
1690
- " /compact Compact current dialog and fork a new one",
1691
- " /context Show workspace context and next actions",
1692
- " /runtime <mode> Use auto, local, or server runtime",
1693
- " /tools <mode> Control tool trace: hide, compact, verbose",
1694
- " /thinking <mode> Control thinking output: hide, marker, show",
1695
- " /switch Pick an agent interactively (\u2191\u2193, Enter)",
1696
- " /switch list List agents as text",
1697
- " /switch <name> Switch directly by name, alias, or key (alias: /agent)",
1698
- " /agents List platform agent shortcuts",
1699
- " /history Pick a recent dialog to resume (\u2191\u2193, Enter)",
1700
- " /resume <dialogId> Resume a dialog directly by id",
1701
- " /lang <zh|en> Switch interface language",
1702
- " /copy Copy the last reply to the clipboard",
1703
- " /copy view Open native scrollback for partial selection (Ctrl+O)",
1704
- " /mouse <on|off> Toggle mouse mode (off = drag to select text)",
1705
- " /doc List attached docs",
1706
- " /doc attach <doc> Attach a doc to this workspace",
1707
- " /skill List attached skills",
1708
- " /skill attach <ref> Attach a skill (dbKey, name, or SKILL.md path)",
1709
- " /skill detach <ref> Detach a skill",
1710
- " /skill clear Detach all skills",
1711
- " /customize Describe how you want to tune nolo",
1712
- " /tasks List background process tasks (aliases: /jobs, /procs)",
1713
- " /stop <pid|all> Stop background process tasks",
1714
- " /login Show login/profile hint",
1715
- " /profile Show active profile",
1716
- " /update Update the nolo CLI install",
1717
- " /version Show version/update hint",
1718
- " /exit Leave the workspace",
1719
- "",
1720
- "You can also type normally. nolo routes simple read/status requests to CLI commands and sends the rest to the current agent."
1721
- ].join("\n"),
1722
- zh: [
1723
- "\u547D\u4EE4\uFF1A",
1724
- " /help \u663E\u793A\u672C\u5E2E\u52A9",
1725
- " /new \u6E05\u5C4F\u5E76\u5F00\u59CB\u65B0\u5BF9\u8BDD",
1726
- " /compact \u538B\u7F29\u5F53\u524D\u5BF9\u8BDD\u5E76\u5206\u53C9\u51FA\u65B0\u5BF9\u8BDD",
1727
- " /context \u67E5\u770B\u5DE5\u4F5C\u533A\u4E0A\u4E0B\u6587\u4E0E\u540E\u7EED\u64CD\u4F5C",
1728
- " /runtime <mode> \u5207\u6362 runtime\uFF1Aauto\u3001local\u3001server",
1729
- " /tools <mode> \u5DE5\u5177\u8F68\u8FF9\u663E\u793A\uFF1Ahide\u3001compact\u3001verbose",
1730
- " /thinking <mode> \u601D\u8003\u8FC7\u7A0B\u663E\u793A\uFF1Ahide\u3001marker\u3001show",
1731
- " /switch \u4EA4\u4E92\u5F0F\u9009\u62E9 agent\uFF08\u2191\u2193 \u79FB\u52A8\uFF0CEnter \u786E\u8BA4\uFF09",
1732
- " /switch list \u4EE5\u6587\u672C\u5217\u51FA\u5168\u90E8 agent",
1733
- " /switch <name> \u6309\u540D\u79F0\u3001\u522B\u540D\u6216 key \u76F4\u63A5\u5207\u6362\uFF08\u522B\u540D\uFF1A/agent\uFF09",
1734
- " /agents \u5217\u51FA\u5E73\u53F0 agent \u5FEB\u6377\u65B9\u5F0F",
1735
- " /history \u4ECE\u6700\u8FD1\u5BF9\u8BDD\u4E2D\u9009\u62E9\u5E76\u6062\u590D\uFF08\u2191\u2193\uFF0CEnter\uFF09",
1736
- " /resume <dialogId> \u6309 id \u76F4\u63A5\u6062\u590D\u5BF9\u8BDD",
1737
- " /lang <zh|en> \u5207\u6362\u754C\u9762\u8BED\u8A00",
1738
- " /copy \u590D\u5236\u6700\u540E\u4E00\u6761\u56DE\u590D\u5230\u526A\u8D34\u677F",
1739
- " /copy view \u6253\u5F00\u539F\u751F\u56DE\u6EDA\u8FDB\u884C\u8DE8\u5C4F\u62D6\u9009\uFF08Ctrl+O\uFF09",
1740
- " /mouse <on|off> \u5207\u6362\u9F20\u6807\u6A21\u5F0F\uFF08off \u540E\u53EF\u76F4\u63A5\u62D6\u9009\u6587\u672C\uFF09",
1741
- " /doc \u5217\u51FA\u5DF2\u6302\u8F7D\u7684\u6587\u6863",
1742
- " /doc attach <doc> \u6302\u8F7D\u6587\u6863\u5230\u5F53\u524D\u5DE5\u4F5C\u533A",
1743
- " /skill \u5217\u51FA\u5DF2\u6302\u8F7D\u7684\u6280\u80FD",
1744
- " /skill attach <ref> \u6302\u8F7D\u6280\u80FD\uFF08dbKey\u3001\u540D\u79F0\u6216 SKILL.md \u8DEF\u5F84\uFF09",
1745
- " /skill detach <ref> \u5378\u8F7D\u6307\u5B9A\u6280\u80FD",
1746
- " /skill clear \u5378\u8F7D\u5168\u90E8\u6280\u80FD",
1747
- " /customize \u63CF\u8FF0\u4F60\u60F3\u600E\u4E48\u8C03\u6559 nolo",
1748
- " /tasks \u5217\u51FA\u540E\u53F0\u5B50\u8FDB\u7A0B\u4EFB\u52A1\uFF08\u522B\u540D\uFF1A/jobs, /procs\uFF09",
1749
- " /stop <pid|all> \u505C\u6B62\u6307\u5B9A\u7684\u540E\u53F0\u4EFB\u52A1",
1750
- " /login \u67E5\u770B\u767B\u5F55 / \u914D\u7F6E\u63D0\u793A",
1751
- " /profile \u67E5\u770B\u5F53\u524D\u914D\u7F6E\u73AF\u5883",
1752
- " /update \u66F4\u65B0 nolo CLI",
1753
- " /version \u67E5\u770B\u7248\u672C\u4E0E\u66F4\u65B0\u63D0\u793A",
1754
- " /exit \u9000\u51FA\u5DE5\u4F5C\u533A",
1755
- "",
1756
- "\u4E5F\u53EF\u4EE5\u76F4\u63A5\u8F93\u5165\u81EA\u7136\u8BED\u8A00\u3002\u7B80\u5355\u7684\u8BFB\u53D6/\u72B6\u6001\u8BF7\u6C42\u4F1A\u8D70 CLI \u547D\u4EE4\uFF0C\u5176\u4F59\u4EA4\u7ED9\u5F53\u524D agent\u3002"
1757
- ].join("\n")
1965
+ addToPath(path, added, removed, oldPosInc, options) {
1966
+ const last = path.lastComponent;
1967
+ if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) {
1968
+ return {
1969
+ oldPos: path.oldPos + oldPosInc,
1970
+ lastComponent: { count: last.count + 1, added, removed, previousComponent: last.previousComponent }
1971
+ };
1972
+ } else {
1973
+ return {
1974
+ oldPos: path.oldPos + oldPosInc,
1975
+ lastComponent: { count: 1, added, removed, previousComponent: last }
1976
+ };
1977
+ }
1978
+ }
1979
+ extractCommon(basePath, newTokens, oldTokens, diagonalPath, options) {
1980
+ const newLen = newTokens.length, oldLen = oldTokens.length;
1981
+ let oldPos = basePath.oldPos, newPos = oldPos - diagonalPath, commonCount = 0;
1982
+ while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(oldTokens[oldPos + 1], newTokens[newPos + 1], options)) {
1983
+ newPos++;
1984
+ oldPos++;
1985
+ commonCount++;
1986
+ if (options.oneChangePerToken) {
1987
+ basePath.lastComponent = { count: 1, previousComponent: basePath.lastComponent, added: false, removed: false };
1988
+ }
1989
+ }
1990
+ if (commonCount && !options.oneChangePerToken) {
1991
+ basePath.lastComponent = { count: commonCount, previousComponent: basePath.lastComponent, added: false, removed: false };
1992
+ }
1993
+ basePath.oldPos = oldPos;
1994
+ return newPos;
1995
+ }
1996
+ equals(left, right, options) {
1997
+ if (options.comparator) {
1998
+ return options.comparator(left, right);
1999
+ } else {
2000
+ return left === right || !!options.ignoreCase && left.toLowerCase() === right.toLowerCase();
2001
+ }
2002
+ }
2003
+ removeEmpty(array) {
2004
+ const ret = [];
2005
+ for (let i = 0; i < array.length; i++) {
2006
+ if (array[i]) {
2007
+ ret.push(array[i]);
2008
+ }
2009
+ }
2010
+ return ret;
2011
+ }
2012
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2013
+ castInput(value, options) {
2014
+ return value;
2015
+ }
2016
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2017
+ tokenize(value, options) {
2018
+ return Array.from(value);
2019
+ }
2020
+ join(chars) {
2021
+ return chars.join("");
2022
+ }
2023
+ postProcess(changeObjects, options) {
2024
+ return changeObjects;
2025
+ }
2026
+ get useLongestToken() {
2027
+ return false;
2028
+ }
2029
+ buildValues(lastComponent, newTokens, oldTokens) {
2030
+ const components = [];
2031
+ let nextComponent;
2032
+ while (lastComponent) {
2033
+ components.push(lastComponent);
2034
+ nextComponent = lastComponent.previousComponent;
2035
+ delete lastComponent.previousComponent;
2036
+ lastComponent = nextComponent;
2037
+ }
2038
+ components.reverse();
2039
+ const componentLen = components.length;
2040
+ let componentPos = 0, newPos = 0, oldPos = 0;
2041
+ for (; componentPos < componentLen; componentPos++) {
2042
+ const component = components[componentPos];
2043
+ if (!component.removed) {
2044
+ if (!component.added && this.useLongestToken) {
2045
+ let value = newTokens.slice(newPos, newPos + component.count);
2046
+ value = value.map(function(value2, i) {
2047
+ const oldValue = oldTokens[oldPos + i];
2048
+ return oldValue.length > value2.length ? oldValue : value2;
2049
+ });
2050
+ component.value = this.join(value);
2051
+ } else {
2052
+ component.value = this.join(newTokens.slice(newPos, newPos + component.count));
2053
+ }
2054
+ newPos += component.count;
2055
+ if (!component.added) {
2056
+ oldPos += component.count;
2057
+ }
2058
+ } else {
2059
+ component.value = this.join(oldTokens.slice(oldPos, oldPos + component.count));
2060
+ oldPos += component.count;
2061
+ }
2062
+ }
2063
+ return components;
1758
2064
  }
1759
2065
  };
1760
- function t(key) {
1761
- return STRINGS[key][currentLocale];
1762
- }
1763
- var TOOL_LABELS = {
1764
- // Local workspace tools (packages/agent-runtime/localWorkspaceTools.ts)
1765
- readFile: { en: "Read", zh: "\u8BFB\u53D6" },
1766
- writeFile: { en: "Write", zh: "\u5199\u5165" },
1767
- editFile: { en: "Edit", zh: "\u7F16\u8F91" },
1768
- listFiles: { en: "List", zh: "\u5217\u51FA" },
1769
- searchFiles: { en: "Search", zh: "\u641C\u7D22" },
1770
- globFiles: { en: "Glob", zh: "\u5339\u914D" },
1771
- execShell: { en: "Run", zh: "\u6267\u884C" },
1772
- runCommand: { en: "Run", zh: "\u6267\u884C" },
1773
- captureVisualState: { en: "Capture", zh: "\u622A\u5C4F" },
1774
- // Workspace / diagnostics
1775
- searchWorkspace: { en: "Search workspace", zh: "\u641C\u7D22\u5DE5\u4F5C\u533A" },
1776
- cliDoctor: { en: "Doctor", zh: "\u81EA\u68C0" },
1777
- cliWhoami: { en: "Whoami", zh: "\u67E5\u770B\u8EAB\u4EFD" },
1778
- checkEnv: { en: "Check env", zh: "\u68C0\u67E5\u73AF\u5883" },
1779
- configure: { en: "Configure", zh: "\u914D\u7F6E" },
1780
- notifyUser: { en: "Notify", zh: "\u901A\u77E5" },
1781
- // Docs / dialogs / spaces
1782
- readDoc: { en: "Read doc", zh: "\u8BFB\u53D6\u6587\u6863" },
1783
- createDoc: { en: "Create doc", zh: "\u65B0\u5EFA\u6587\u6863" },
1784
- updateDoc: { en: "Update doc", zh: "\u66F4\u65B0\u6587\u6863" },
1785
- readDialog: { en: "Read dialog", zh: "\u8BFB\u53D6\u5BF9\u8BDD" },
1786
- listDialogs: { en: "List dialogs", zh: "\u5217\u51FA\u5BF9\u8BDD" },
1787
- queryDialogsBySubjectRef: { en: "Query dialogs", zh: "\u67E5\u8BE2\u5BF9\u8BDD" },
1788
- searchDialogMessages: { en: "Search messages", zh: "\u641C\u7D22\u6D88\u606F" },
1789
- listSpaces: { en: "List spaces", zh: "\u5217\u51FA\u7A7A\u95F4" },
1790
- readSpace: { en: "Read space", zh: "\u8BFB\u53D6\u7A7A\u95F4" },
1791
- // Tables
1792
- createTable: { en: "Create table", zh: "\u521B\u5EFA\u8868" },
1793
- queryTableRows: { en: "Query rows", zh: "\u67E5\u8BE2\u8868\u884C" },
1794
- addTableRow: { en: "Add row", zh: "\u65B0\u589E\u8868\u884C" },
1795
- addTableRows: { en: "Add rows", zh: "\u65B0\u589E\u8868\u884C" },
1796
- updateTableRow: { en: "Update row", zh: "\u66F4\u65B0\u8868\u884C" },
1797
- deleteTableRow: { en: "Delete row", zh: "\u5220\u9664\u8868\u884C" },
1798
- // Web
1799
- fetchWebpage: { en: "Fetch page", zh: "\u6293\u53D6\u7F51\u9875" },
1800
- readPage: { en: "Read page", zh: "\u8BFB\u53D6\u7F51\u9875" },
1801
- exaSearch: { en: "Web search", zh: "\u8054\u7F51\u641C\u7D22" },
1802
- // Skill loading
1803
- loadSkill: { en: "Used Skill", zh: "\u4F7F\u7528\u6280\u80FD" }
2066
+
2067
+ // packages/cli/node_modules/diff/libesm/diff/line.js
2068
+ var LineDiff = class extends Diff {
2069
+ constructor() {
2070
+ super(...arguments);
2071
+ this.tokenize = tokenize;
2072
+ }
2073
+ equals(left, right, options) {
2074
+ if (options.ignoreWhitespace) {
2075
+ if (!options.newlineIsToken || !left.includes("\n")) {
2076
+ left = left.trim();
2077
+ }
2078
+ if (!options.newlineIsToken || !right.includes("\n")) {
2079
+ right = right.trim();
2080
+ }
2081
+ } else if (options.ignoreNewlineAtEof && !options.newlineIsToken) {
2082
+ if (left.endsWith("\n")) {
2083
+ left = left.slice(0, -1);
2084
+ }
2085
+ if (right.endsWith("\n")) {
2086
+ right = right.slice(0, -1);
2087
+ }
2088
+ }
2089
+ return super.equals(left, right, options);
2090
+ }
1804
2091
  };
1805
- function toolLabel(name) {
1806
- return TOOL_LABELS[name]?.[currentLocale] ?? name;
2092
+ var lineDiff = new LineDiff();
2093
+ function diffLines(oldStr, newStr, options) {
2094
+ return lineDiff.diff(oldStr, newStr, options);
2095
+ }
2096
+ function tokenize(value, options) {
2097
+ if (options.stripTrailingCr) {
2098
+ value = value.replace(/\r\n/g, "\n");
2099
+ }
2100
+ const retLines = [], linesAndNewlines = value.split(/(\n|\r\n)/);
2101
+ if (!linesAndNewlines[linesAndNewlines.length - 1]) {
2102
+ linesAndNewlines.pop();
2103
+ }
2104
+ for (let i = 0; i < linesAndNewlines.length; i++) {
2105
+ const line = linesAndNewlines[i];
2106
+ if (i % 2 && !options.newlineIsToken) {
2107
+ retLines[retLines.length - 1] += line;
2108
+ } else {
2109
+ retLines.push(line);
2110
+ }
2111
+ }
2112
+ return retLines;
1807
2113
  }
1808
2114
 
1809
2115
  // packages/cli/client/toolOutput.ts
@@ -1876,25 +2182,65 @@ function readReadFileRange(metadata) {
1876
2182
  if (!truncated && startLine === 1 && endLine === totalLines) return void 0;
1877
2183
  return `${startLine}-${endLine}/${totalLines}`;
1878
2184
  }
1879
- var EDIT_SNIPPET_MAX_LINES = 5;
2185
+ var EDIT_SNIPPET_MAX_LINES = 10;
1880
2186
  var EDIT_SNIPPET_MAX_WIDTH = 96;
1881
2187
  function formatEditFileSnippet(metadata) {
1882
2188
  const oldSnippet = typeof metadata.oldSnippet === "string" ? metadata.oldSnippet : void 0;
1883
2189
  const newSnippet = typeof metadata.newSnippet === "string" ? metadata.newSnippet : void 0;
1884
2190
  if (!oldSnippet && !newSnippet) return void 0;
1885
- const lines = [];
1886
- if (oldSnippet) {
1887
- for (const line of snippetLines(oldSnippet)) lines.push(`- ${line}`);
2191
+ if (oldSnippet && !newSnippet) {
2192
+ return snippetLinesWithKind(oldSnippet, "removed");
1888
2193
  }
1889
- if (newSnippet) {
1890
- for (const line of snippetLines(newSnippet)) lines.push(`+ ${line}`);
2194
+ if (newSnippet && !oldSnippet) {
2195
+ return snippetLinesWithKind(newSnippet, "added");
1891
2196
  }
1892
- return lines.length ? lines.join("\n") : void 0;
2197
+ const parts = diffLines(oldSnippet, newSnippet);
2198
+ const all = [];
2199
+ for (const part of parts) {
2200
+ const kind = part.added ? "added" : part.removed ? "removed" : "context";
2201
+ const raw = part.value.split("\n");
2202
+ if (raw.length > 0 && raw[raw.length - 1] === "") raw.pop();
2203
+ for (const line of raw) all.push(buildEditLine(kind, line));
2204
+ }
2205
+ const changeCount = all.filter((l) => l.kind !== "context").length;
2206
+ if (changeCount === 0) return void 0;
2207
+ return windowAndTruncate(all, EDIT_SNIPPET_MAX_LINES);
2208
+ }
2209
+ function prefixFor(kind) {
2210
+ return kind === "added" ? "+ " : kind === "removed" ? "- " : " ";
1893
2211
  }
1894
- function snippetLines(snippet) {
2212
+ function buildEditLine(kind, body) {
2213
+ return { kind, text: prefixFor(kind) + truncateByDisplayWidth(body, EDIT_SNIPPET_MAX_WIDTH) };
2214
+ }
2215
+ function snippetLinesWithKind(snippet, kind) {
1895
2216
  const lines = snippet.split(/\r?\n/).filter((line) => line.length > 0);
1896
- const shown = lines.slice(0, EDIT_SNIPPET_MAX_LINES);
1897
- return shown.map((line) => line.length > EDIT_SNIPPET_MAX_WIDTH ? `${line.slice(0, EDIT_SNIPPET_MAX_WIDTH)}\u2026` : line);
2217
+ return lines.slice(0, EDIT_SNIPPET_MAX_LINES).map((line) => buildEditLine(kind, line));
2218
+ }
2219
+ function truncateByDisplayWidth(line, maxWidth) {
2220
+ if (displayWidth(line) <= maxWidth) return line;
2221
+ let width = 0;
2222
+ let kept = "";
2223
+ for (const char of line) {
2224
+ const w = displayWidth(char);
2225
+ if (width + w + 1 > maxWidth) break;
2226
+ kept += char;
2227
+ width += w;
2228
+ }
2229
+ return `${kept}\u2026`;
2230
+ }
2231
+ function windowAndTruncate(lines, maxLines) {
2232
+ if (lines.length <= maxLines) return lines;
2233
+ const firstChange = lines.findIndex((l) => l.kind !== "context");
2234
+ if (firstChange === -1) return lines.slice(0, maxLines);
2235
+ const half = Math.floor(maxLines / 2);
2236
+ let start = Math.max(0, firstChange - half);
2237
+ if (start + maxLines > lines.length) start = Math.max(0, lines.length - maxLines);
2238
+ const kept = lines.slice(start, start + maxLines);
2239
+ const omitted = lines.length - kept.length;
2240
+ if (omitted > 0) {
2241
+ kept.push({ kind: "context", text: ` \u2026 +${omitted} more lines` });
2242
+ }
2243
+ return kept;
1898
2244
  }
1899
2245
  function isFailedToolResult(event) {
1900
2246
  const exitCode = event.metadata?.exitCode;
@@ -1905,6 +2251,22 @@ function isFailedToolResult(event) {
1905
2251
  function isNeedsActionToolResult(event) {
1906
2252
  return Boolean(event.metadata?.actionGate);
1907
2253
  }
2254
+ function readRunAgentName(parsed) {
2255
+ const agentName = typeof parsed.agentName === "string" ? parsed.agentName.trim() : "";
2256
+ if (agentName) return agentName;
2257
+ const name = typeof parsed.name === "string" ? parsed.name.trim() : "";
2258
+ return name || "agent";
2259
+ }
2260
+ function readRunLogLines(parsed) {
2261
+ if (Array.isArray(parsed.logLines)) return parsed.logLines;
2262
+ if (typeof parsed.logTail === "string" && parsed.logTail.trim()) {
2263
+ return parsed.logTail.split("\n");
2264
+ }
2265
+ return void 0;
2266
+ }
2267
+ function readRunErrorMessage(parsed) {
2268
+ return typeof parsed.errorMessage === "string" ? parsed.errorMessage : void 0;
2269
+ }
1908
2270
  function parseUiAskChoiceForCli(event) {
1909
2271
  if (event.toolName !== "ui_ask_choice" && !event.metadata?.uiAskChoice) {
1910
2272
  return null;
@@ -1916,18 +2278,66 @@ function parseUiAskChoiceForCli(event) {
1916
2278
  label: String(c.label ?? "").trim(),
1917
2279
  userMessage: typeof c.userMessage === "string" ? c.userMessage : void 0
1918
2280
  })).filter((c) => c.label.length > 0);
1919
- if (!question || choices.length === 0) return null;
1920
- return { question, choices };
2281
+ const selected = parsed.selected && typeof parsed.selected === "object" ? {
2282
+ label: String(parsed.selected.label ?? "").trim(),
2283
+ userMessage: String(parsed.selected.userMessage ?? "").trim()
2284
+ } : void 0;
2285
+ const answers = Array.isArray(parsed.answers) ? parsed.answers : void 0;
2286
+ const cancelled = Boolean(parsed.cancelled);
2287
+ const resolved = Boolean(
2288
+ event.metadata?.resolved || selected || cancelled || answers && answers.length > 0
2289
+ );
2290
+ if (!resolved && (!question || choices.length === 0)) return null;
2291
+ if (!question && !selected && !cancelled) return null;
2292
+ return {
2293
+ question,
2294
+ choices,
2295
+ ...selected ? { selected } : {},
2296
+ ...answers ? { answers } : {},
2297
+ ...cancelled ? { cancelled: true } : {},
2298
+ resolved
2299
+ };
1921
2300
  }
1922
2301
  function formatUiAskChoiceBlock(event, colorEnabled) {
1923
2302
  const parsed = parseUiAskChoiceForCli(event);
1924
2303
  if (!parsed) return null;
1925
2304
  const lines = [];
1926
2305
  lines.push("");
2306
+ const questionText = parsed.question || "";
1927
2307
  if (colorEnabled) {
1928
- lines.push(`${themeText("\u2753 ", "info", true)}${styleCliText(parsed.question, "cyan", true)}`);
2308
+ lines.push(`${themeText("\u2753 ", "info", true)}${styleCliText(questionText, "cyan", true)}`);
1929
2309
  } else {
1930
- lines.push(`\u2753 ${parsed.question}`);
2310
+ lines.push(`\u2753 ${questionText}`);
2311
+ }
2312
+ if (parsed.resolved) {
2313
+ if (parsed.cancelled) {
2314
+ const cancelled = t("askChoiceHistoryCancelled");
2315
+ lines.push(
2316
+ colorEnabled ? ` ${themeText("\xB7", "chrome", true)} ${themeText(cancelled, "muted", true)}` : ` \xB7 ${cancelled}`
2317
+ );
2318
+ return `${lines.join("\n")}
2319
+ `;
2320
+ }
2321
+ const selectedLabel = parsed.selected?.label || parsed.selected?.userMessage || (parsed.answers ? parsed.answers.map((a) => a.userMessage).filter(Boolean).join(", ") : "");
2322
+ const marker = t("askChoiceHistorySelected");
2323
+ const displayLabel = selectedLabel || "\u2014";
2324
+ if (colorEnabled) {
2325
+ lines.push(
2326
+ ` ${themeText("\u2713", "success", true)} ${themeText(marker, "muted", true)} ${displayLabel}`
2327
+ );
2328
+ } else {
2329
+ lines.push(` \u2713 ${marker} ${displayLabel}`);
2330
+ }
2331
+ if (parsed.answers && parsed.answers.length > 1) {
2332
+ for (const answer of parsed.answers) {
2333
+ if (!answer.userMessage) continue;
2334
+ lines.push(
2335
+ colorEnabled ? ` ${themeText("\xB7", "chrome", true)} ${answer.userMessage}` : ` \xB7 ${answer.userMessage}`
2336
+ );
2337
+ }
2338
+ }
2339
+ return `${lines.join("\n")}
2340
+ `;
1931
2341
  }
1932
2342
  parsed.choices.forEach((choice, i) => {
1933
2343
  const num = String(i + 1);
@@ -1940,7 +2350,7 @@ function formatUiAskChoiceBlock(event, colorEnabled) {
1940
2350
  lines.push(` ${num}. ${label}`);
1941
2351
  }
1942
2352
  });
1943
- const hint = "\u8BF7\u8F93\u5165\u5E8F\u53F7\u9009\u62E9\uFF0C\u6216\u76F4\u63A5\u56DE\u590D\uFF1A";
2353
+ const hint = t("askChoiceHistoryHint");
1944
2354
  if (colorEnabled) {
1945
2355
  lines.push(` ${dimCliText(hint, true)}`);
1946
2356
  } else {
@@ -1956,8 +2366,131 @@ function formatToolTraceLine(text, colorEnabled, accent = "none") {
1956
2366
  return `${themeText(text, "danger", true)}
1957
2367
  `;
1958
2368
  }
1959
- return `${dimCliText(text, true)}
1960
- `;
2369
+ return `${dimCliText(text, true)}
2370
+ `;
2371
+ }
2372
+ function recoverOrchestrationDisplayFromContent(toolName, content) {
2373
+ const trimmed = content.trim();
2374
+ if (!trimmed.startsWith("{") && !trimmed.startsWith("[")) return content;
2375
+ const labels = agentRunCardLabels();
2376
+ try {
2377
+ const parsed = JSON.parse(trimmed);
2378
+ if (toolName === "listAgents") {
2379
+ const agents = Array.isArray(parsed.agents) ? parsed.agents : [];
2380
+ return formatAgentListCard(agents);
2381
+ }
2382
+ if (toolName === "startAgentRun") {
2383
+ const name = typeof parsed.agentName === "string" && parsed.agentName.trim() ? parsed.agentName.trim() : typeof parsed.name === "string" && parsed.name.trim() ? parsed.name.trim() : "agent";
2384
+ const status = typeof parsed.status === "string" ? parsed.status : "running";
2385
+ return formatStartRunCard(name, status, labels);
2386
+ }
2387
+ if (toolName === "controlAgentRun") {
2388
+ if (Array.isArray(parsed.runs)) {
2389
+ const runs = parsed.runs;
2390
+ return formatListRunsCard(runs, labels);
2391
+ }
2392
+ const status = typeof parsed.status === "string" ? parsed.status : void 0;
2393
+ if (parsed.found === false || status === "not_found") {
2394
+ return formatNotFoundRunCard(labels);
2395
+ }
2396
+ if (status === "killed" || status === "cancelled" || status === "cancelling") {
2397
+ return formatStopRunCard(status, labels);
2398
+ }
2399
+ return formatStatusRunCard(readRunAgentName(parsed), status ?? "\u2014", {
2400
+ errorMessage: readRunErrorMessage(parsed),
2401
+ logLines: readRunLogLines(parsed),
2402
+ labels
2403
+ });
2404
+ }
2405
+ } catch {
2406
+ }
2407
+ return content;
2408
+ }
2409
+ function parseControlAgentRunStatusEvent(event) {
2410
+ const raw = typeof event.content === "string" && event.content.trim() ? event.content.trim() : "";
2411
+ if (!raw.startsWith("{")) return null;
2412
+ try {
2413
+ const parsed = JSON.parse(raw);
2414
+ if (Array.isArray(parsed.runs)) return null;
2415
+ const status = typeof parsed.status === "string" ? parsed.status : void 0;
2416
+ if (parsed.found === false || status === "not_found") return null;
2417
+ if (status === "killed" || status === "cancelled" || status === "cancelling") return null;
2418
+ if (!status) return null;
2419
+ const runId = typeof parsed.runId === "string" && parsed.runId.trim() ? parsed.runId.trim() : typeof event.metadata?.runId === "string" ? event.metadata.runId : "";
2420
+ if (!runId) return null;
2421
+ const agentName = readRunAgentName(parsed);
2422
+ const errorMessage = readRunErrorMessage(parsed);
2423
+ const logLines = readRunLogLines(parsed);
2424
+ const logKey = logLines && logLines.length > 0 ? logLines.join("\n") : "";
2425
+ return { runId, status, agentName, errorMessage, logLines, logKey };
2426
+ } catch {
2427
+ return null;
2428
+ }
2429
+ }
2430
+ function formatOrchestrationCardBlock(event, toolName, colorEnabled) {
2431
+ const rawLabel = toolLabel(toolName);
2432
+ let rawDataStr = typeof event.metadata?.displayData === "string" && event.metadata.displayData.trim() ? event.metadata.displayData : typeof event.content === "string" ? event.content : "";
2433
+ if (typeof event.metadata?.displayData !== "string" && typeof event.content === "string" && event.content.trim()) {
2434
+ rawDataStr = recoverOrchestrationDisplayFromContent(toolName, event.content);
2435
+ }
2436
+ const failed = event.type === "tool-error" || isFailedToolResult(event) || Boolean(event.metadata?.failed) || /^Error:/i.test(rawDataStr.trim());
2437
+ if (failed) {
2438
+ const firstLine = rawDataStr.trim().split("\n")[0] || event.summary || event.message || t("toolFailed");
2439
+ const message = clip(firstLine, 96);
2440
+ if (!colorEnabled) {
2441
+ return `\u2717 ${rawLabel} ${message}
2442
+ `;
2443
+ }
2444
+ const cross = themeText("\u2717", "danger", true);
2445
+ const labelPart2 = themeText(rawLabel, "muted", true);
2446
+ const msgPart = themeText(message, "danger", true);
2447
+ return `${cross} ${labelPart2} ${msgPart}
2448
+ `;
2449
+ }
2450
+ const displayData = rawDataStr.trim();
2451
+ const lines = displayData ? displayData.split("\n").filter((line) => !/^\s*agent\s+agent\s*$/.test(line)) : [];
2452
+ if (!colorEnabled) {
2453
+ let out2 = `\u25CF ${rawLabel}
2454
+ `;
2455
+ for (const line of lines) {
2456
+ out2 += ` ${line}
2457
+ `;
2458
+ }
2459
+ return out2;
2460
+ }
2461
+ const bullet = themeText("\u25CF", "success", true);
2462
+ const labelPart = themeText(rawLabel, "muted", true);
2463
+ let out = `${bullet} ${labelPart}
2464
+ `;
2465
+ for (const line of lines) {
2466
+ out += ` ${themeText(line, "muted", true)}
2467
+ `;
2468
+ }
2469
+ return out;
2470
+ }
2471
+ function formatFoldedControlStatusCard(snapshot, colorEnabled) {
2472
+ const labels = agentRunCardLabels();
2473
+ const body = formatStatusRunCard(snapshot.agentName, snapshot.status, {
2474
+ errorMessage: snapshot.errorMessage,
2475
+ logLines: snapshot.logLines,
2476
+ pollCount: snapshot.pollCount,
2477
+ elapsedMs: snapshot.elapsedMs,
2478
+ includeLogTail: snapshot.includeLogTail,
2479
+ labels
2480
+ });
2481
+ return formatOrchestrationCardBlock(
2482
+ {
2483
+ type: "tool-result",
2484
+ round: 0,
2485
+ toolCallId: `fold-${snapshot.runId}`,
2486
+ toolName: "controlAgentRun",
2487
+ content: "",
2488
+ metadata: { displayData: body },
2489
+ elapsedMs: snapshot.elapsedMs
2490
+ },
2491
+ "controlAgentRun",
2492
+ colorEnabled
2493
+ );
1961
2494
  }
1962
2495
  function formatVerboseToolEvent(event, colorEnabled) {
1963
2496
  const round = event.round + 1;
@@ -2006,15 +2539,16 @@ function isRunResultFoldable(event) {
2006
2539
  function formatSearchTreeBlockForCli(items, colorEnabled) {
2007
2540
  if (items.length === 0) return "";
2008
2541
  const { count, lines } = formatSearchTreeLines(items);
2542
+ const titleText = toolLabel("searchFiles");
2009
2543
  if (!colorEnabled) {
2010
- const headerLine2 = `\u2022 Search (${count})
2544
+ const headerLine2 = `\u2022 ${titleText} (${count})
2011
2545
  `;
2012
2546
  const treeLines2 = lines.map((l) => ` ${l.connector}${l.queryText}`).join("\n");
2013
2547
  return `${headerLine2}${treeLines2}
2014
2548
  `;
2015
2549
  }
2016
2550
  const bullet = themeText("\u2022", "chrome", true);
2017
- const title = styleCliText("Search", "bold", true);
2551
+ const title = styleCliText(titleText, "bold", true);
2018
2552
  const countText = themeText(`(${count})`, "muted", true);
2019
2553
  const headerLine = `${bullet} ${title} ${countText}
2020
2554
  `;
@@ -2029,15 +2563,16 @@ function formatSearchTreeBlockForCli(items, colorEnabled) {
2029
2563
  function formatReadTreeBlockForCli(items, colorEnabled) {
2030
2564
  if (items.length === 0) return "";
2031
2565
  const { count, lines } = formatReadTreeLines(items);
2566
+ const titleText = toolLabel("readFile");
2032
2567
  if (!colorEnabled) {
2033
- const headerLine2 = `\u2022 Read (${count})
2568
+ const headerLine2 = `\u2022 ${titleText} (${count})
2034
2569
  `;
2035
2570
  const treeLines2 = lines.map((l) => ` ${l.connector}${l.pathWithRange}`).join("\n");
2036
2571
  return `${headerLine2}${treeLines2}
2037
2572
  `;
2038
2573
  }
2039
2574
  const bullet = themeText("\u2022", "chrome", true);
2040
- const title = styleCliText("Read", "bold", true);
2575
+ const title = styleCliText(titleText, "bold", true);
2041
2576
  const countText = themeText(`(${count})`, "muted", true);
2042
2577
  const headerLine = `${bullet} ${title} ${countText}
2043
2578
  `;
@@ -2052,15 +2587,16 @@ function formatReadTreeBlockForCli(items, colorEnabled) {
2052
2587
  function formatRunTreeBlockForCli(items, colorEnabled) {
2053
2588
  if (items.length === 0) return "";
2054
2589
  const { count, lines } = formatRunTreeLines(items);
2590
+ const titleText = toolLabel("execShell");
2055
2591
  if (!colorEnabled) {
2056
- const headerLine2 = `\u2022 Run (${count})
2592
+ const headerLine2 = `\u2022 ${titleText} (${count})
2057
2593
  `;
2058
2594
  const treeLines2 = lines.map((l) => ` ${l.connector}${l.commandText}`).join("\n");
2059
2595
  return `${headerLine2}${treeLines2}
2060
2596
  `;
2061
2597
  }
2062
2598
  const bullet = themeText("\u2022", "chrome", true);
2063
- const title = styleCliText("Run", "bold", true);
2599
+ const title = styleCliText(titleText, "bold", true);
2064
2600
  const countText = themeText(`(${count})`, "muted", true);
2065
2601
  const headerLine = `${bullet} ${title} ${countText}
2066
2602
  `;
@@ -2075,15 +2611,16 @@ function formatRunTreeBlockForCli(items, colorEnabled) {
2075
2611
  function formatFetchTreeBlockForCli(items, colorEnabled) {
2076
2612
  if (items.length === 0) return "";
2077
2613
  const { count, lines } = formatFetchTreeLines(items);
2614
+ const titleText = toolLabel("fetchWebpage");
2078
2615
  if (!colorEnabled) {
2079
- const headerLine2 = `\u2022 Fetch (${count})
2616
+ const headerLine2 = `\u2022 ${titleText} (${count})
2080
2617
  `;
2081
2618
  const treeLines2 = lines.map((l) => ` ${l.connector}${l.urlText}`).join("\n");
2082
2619
  return `${headerLine2}${treeLines2}
2083
2620
  `;
2084
2621
  }
2085
2622
  const bullet = themeText("\u2022", "chrome", true);
2086
- const title = styleCliText("Fetch", "bold", true);
2623
+ const title = styleCliText(titleText, "bold", true);
2087
2624
  const countText = themeText(`(${count})`, "muted", true);
2088
2625
  const headerLine = `${bullet} ${title} ${countText}
2089
2626
  `;
@@ -2137,24 +2674,24 @@ function formatCompactToolLine(event, pending, colorEnabled) {
2137
2674
  const skillName = resolveLoadSkillName(event);
2138
2675
  const content = typeof event.content === "string" ? event.content : "";
2139
2676
  const failed2 = /^Skill\s+"[^"]*"\s+not found/.test(content) || isFailedToolResult(event);
2677
+ const labelText = t("usedSkillLabel");
2140
2678
  if (failed2) {
2141
2679
  const message = clip(content.split("\n")[0] || t("toolFailed"), 96);
2142
- return formatToolTraceLine(`\u25B8 Used Skill (${skillName}) \u2717 ${message}`, colorEnabled, "error");
2680
+ return formatToolTraceLine(`\u25B8 ${labelText} (${skillName}) \u2717 ${message}`, colorEnabled, "error");
2143
2681
  }
2144
- const resultLine = `Skill "${skillName}" loaded inline. Follow its instructions.`;
2145
2682
  if (!colorEnabled) {
2146
- return `\u25CF Used Skill (${skillName})
2147
- ${resultLine}
2683
+ return `\u2726 ${labelText}: ${skillName}
2148
2684
  `;
2149
2685
  }
2150
- const bullet = themeText("\u25CF", "success", true);
2151
- const labelPart = themeText("Used Skill", "muted", true);
2152
- const namePart = themeText(`(${skillName})`, "chrome", true);
2153
- const detail = themeText(` ${resultLine}`, "muted", true);
2154
- return `${bullet} ${labelPart} ${namePart}
2155
- ${detail}
2686
+ const star = themeText("\u2726", "success", true);
2687
+ const labelPart = themeText(labelText, "muted", true);
2688
+ const namePart = themeText(skillName, "chrome", true);
2689
+ return `${star} ${labelPart}: ${namePart}
2156
2690
  `;
2157
2691
  }
2692
+ if (event.type === "tool-result" && (toolName === "listAgents" || toolName === "startAgentRun" || toolName === "controlAgentRun")) {
2693
+ return formatOrchestrationCardBlock(event, toolName, colorEnabled);
2694
+ }
2158
2695
  if (event.type === "tool-result" && (event.toolName === "ui_ask_choice" || event.metadata?.uiAskChoice)) {
2159
2696
  const block = formatUiAskChoiceBlock(event, colorEnabled);
2160
2697
  if (block) return block;
@@ -2176,36 +2713,17 @@ ${detail}
2176
2713
  mainLine = `${chromePointer} ${mutedLabel}${argsPart} ${statusToken}${suffixPart}
2177
2714
  `;
2178
2715
  }
2179
- if (!hint.detail) return mainLine;
2180
- const detailLines = hint.detail.split("\n").map((line) => formatEditDetailLine(line, colorEnabled)).join("");
2181
- return `${mainLine}${detailLines}`;
2716
+ if (!hint.detail?.length) return mainLine;
2717
+ return `${mainLine}${formatEditDetailBlock(hint.detail, colorEnabled)}`;
2182
2718
  }
2183
- function formatEditDetailLine(line, colorEnabled) {
2184
- const marker = line.slice(0, 2);
2185
- const rest = line.slice(2);
2186
- if (!colorEnabled) return ` ${line}
2187
- `;
2188
- const diff = diffLineSequences();
2189
- if (!diff) {
2190
- const color = marker === "- " ? "red" : marker === "+ " ? "green" : void 0;
2191
- if (color) {
2192
- return ` ${styleCliText(marker, color, true)}${dimCliText(rest, true)}
2193
- `;
2194
- }
2195
- return ` ${dimCliText(line, true)}
2196
- `;
2197
- }
2198
- const RESET2 = "\x1B[0m";
2199
- if (marker === "- ") {
2200
- return ` ${diff.removed.bg}${diff.removed.fg}- ${rest}${RESET2}
2201
- `;
2202
- }
2203
- if (marker === "+ ") {
2204
- return ` ${diff.added.bg}${diff.added.fg}+ ${rest}${RESET2}
2205
- `;
2719
+ function formatEditDetailBlock(lines, colorEnabled) {
2720
+ if (!colorEnabled) {
2721
+ return lines.map((line) => ` ${line.text}
2722
+ `).join("");
2206
2723
  }
2207
- return ` ${dimCliText(line, true)}
2208
- `;
2724
+ const padTo = Math.max(...lines.map((line) => displayWidth(line.text))) + 1;
2725
+ return lines.map((line) => ` ${renderDiffLine({ kind: line.kind, text: line.text, padTo, colorEnabled: true })}
2726
+ `).join("");
2209
2727
  }
2210
2728
  function createToolEventFormatter(mode, colorEnabled = resolveCliColorEnabled()) {
2211
2729
  const pending = /* @__PURE__ */ new Map();
@@ -2213,8 +2731,33 @@ function createToolEventFormatter(mode, colorEnabled = resolveCliColorEnabled())
2213
2731
  let searchBuffer = [];
2214
2732
  let runBuffer = [];
2215
2733
  let fetchBuffer = [];
2734
+ let statusFold = null;
2735
+ const lastEmittedLogByRunId = /* @__PURE__ */ new Map();
2736
+ const flushStatusFold = () => {
2737
+ if (!statusFold) return "";
2738
+ const fold = statusFold;
2739
+ statusFold = null;
2740
+ const prevLog = lastEmittedLogByRunId.get(fold.runId);
2741
+ const includeLogTail = Boolean(fold.logKey) && fold.logKey !== prevLog;
2742
+ if (fold.logKey) {
2743
+ lastEmittedLogByRunId.set(fold.runId, fold.logKey);
2744
+ }
2745
+ return formatFoldedControlStatusCard(
2746
+ {
2747
+ runId: fold.runId,
2748
+ status: fold.status,
2749
+ agentName: fold.agentName,
2750
+ errorMessage: fold.errorMessage,
2751
+ logLines: fold.logLines,
2752
+ pollCount: fold.pollCount,
2753
+ elapsedMs: fold.elapsedMs,
2754
+ includeLogTail
2755
+ },
2756
+ colorEnabled
2757
+ );
2758
+ };
2216
2759
  const flushBuffers = () => {
2217
- let out = "";
2760
+ let out = flushStatusFold();
2218
2761
  if (readBuffer.length > 0) {
2219
2762
  const items = readBuffer.map((evt) => {
2220
2763
  const call = pending.get(evt.toolCallId);
@@ -2263,6 +2806,51 @@ function createToolEventFormatter(mode, colorEnabled = resolveCliColorEnabled())
2263
2806
  const formatter = (event) => {
2264
2807
  if (mode === "hide") return "";
2265
2808
  if (mode === "verbose") return formatVerboseToolEvent(event, colorEnabled);
2809
+ if (event.toolName === "controlAgentRun") {
2810
+ if (event.type === "tool-call") {
2811
+ pending.set(event.toolCallId, {
2812
+ toolName: event.toolName,
2813
+ argumentsPreview: event.argumentsPreview
2814
+ });
2815
+ return "";
2816
+ }
2817
+ if (event.type === "tool-result") {
2818
+ const snapshot = parseControlAgentRunStatusEvent(event);
2819
+ if (snapshot) {
2820
+ let out = "";
2821
+ if (statusFold && statusFold.runId !== snapshot.runId) {
2822
+ out += flushStatusFold();
2823
+ }
2824
+ if (!statusFold) {
2825
+ statusFold = {
2826
+ ...snapshot,
2827
+ pollCount: 1,
2828
+ elapsedMs: event.elapsedMs
2829
+ };
2830
+ } else {
2831
+ statusFold = {
2832
+ runId: snapshot.runId,
2833
+ status: snapshot.status,
2834
+ agentName: snapshot.agentName,
2835
+ errorMessage: snapshot.errorMessage ?? statusFold.errorMessage,
2836
+ logLines: snapshot.logLines ?? statusFold.logLines,
2837
+ logKey: snapshot.logKey || statusFold.logKey,
2838
+ pollCount: statusFold.pollCount + 1,
2839
+ elapsedMs: event.elapsedMs
2840
+ };
2841
+ }
2842
+ pending.delete(event.toolCallId);
2843
+ if (isAgentRunTerminalStatus(snapshot.status)) {
2844
+ out += flushBuffers();
2845
+ }
2846
+ return out;
2847
+ }
2848
+ const flushed2 = flushBuffers();
2849
+ const call2 = pending.get(event.toolCallId);
2850
+ pending.delete(event.toolCallId);
2851
+ return `${flushed2}${formatCompactToolLine(event, call2, colorEnabled)}`;
2852
+ }
2853
+ }
2266
2854
  if (isReadToolName(event.toolName)) {
2267
2855
  if (event.type === "tool-call") {
2268
2856
  pending.set(event.toolCallId, {
@@ -2835,10 +3423,165 @@ function isKnownServerPlatformAgent(options) {
2835
3423
  );
2836
3424
  }
2837
3425
 
3426
+ // packages/core/collapsedPaste.ts
3427
+ var COLLAPSE_PASTE_MIN_LINES = 8;
3428
+ var COLLAPSE_PASTE_MIN_CHARS = 400;
3429
+ var COLLAPSED_PASTE_PLACEHOLDER_RE = /\[paste #(\d+) · (\d+) lines\]/g;
3430
+ var COLLAPSED_PASTE_MODEL_REFERENCE_RE = /\[paste #(\d+)(?: scope:([a-zA-Z0-9_-]+))? · [^\]]+; full content available via readPastedText\(pasteId=(\d+)\)\]/g;
3431
+ function countTextLines(text) {
3432
+ if (text.length === 0) return 0;
3433
+ let lines = 1;
3434
+ for (let i = 0; i < text.length; i += 1) {
3435
+ if (text.charCodeAt(i) === 10) lines += 1;
3436
+ }
3437
+ return lines;
3438
+ }
3439
+ function shouldCollapsePaste(text, threshold = {}) {
3440
+ const minLines = threshold.minLines ?? COLLAPSE_PASTE_MIN_LINES;
3441
+ const minChars = threshold.minChars ?? COLLAPSE_PASTE_MIN_CHARS;
3442
+ if (text.length === 0) return false;
3443
+ if (text.length >= minChars) return true;
3444
+ return countTextLines(text) >= minLines;
3445
+ }
3446
+ function formatPasteByteSize(bytes) {
3447
+ if (!Number.isFinite(bytes) || bytes < 0) return "0 B";
3448
+ if (bytes < 1024) return `${Math.round(bytes)} B`;
3449
+ if (bytes < 1024 * 1024) {
3450
+ const kb = bytes / 1024;
3451
+ return `${kb >= 10 ? kb.toFixed(0) : kb.toFixed(1)} KB`;
3452
+ }
3453
+ const mb = bytes / (1024 * 1024);
3454
+ return `${mb >= 10 ? mb.toFixed(0) : mb.toFixed(1)} MB`;
3455
+ }
3456
+ function estimatePasteBytes(text) {
3457
+ let bytes = 0;
3458
+ for (let i = 0; i < text.length; i += 1) {
3459
+ const code = text.charCodeAt(i);
3460
+ if (code <= 127) bytes += 1;
3461
+ else if (code <= 2047) bytes += 2;
3462
+ else if (code >= 55296 && code <= 56319) {
3463
+ bytes += 4;
3464
+ i += 1;
3465
+ } else bytes += 3;
3466
+ }
3467
+ return bytes;
3468
+ }
3469
+ function formatCollapsedPastePlaceholder(id, text) {
3470
+ const lines = countTextLines(text);
3471
+ return `[paste #${id} \xB7 ${lines} lines]`;
3472
+ }
3473
+ function generatePasteScope() {
3474
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
3475
+ return crypto.randomUUID().slice(0, 8);
3476
+ }
3477
+ return Math.random().toString(36).slice(2, 10);
3478
+ }
3479
+ function formatCollapsedPasteModelReference(id, text, scope) {
3480
+ const lines = countTextLines(text);
3481
+ const size = formatPasteByteSize(estimatePasteBytes(text));
3482
+ const scopeAttr = scope ? ` scope:${scope}` : "";
3483
+ return `[paste #${id}${scopeAttr} \xB7 ${lines} lines \xB7 ${size}; full content available via readPastedText(pasteId=${id})]`;
3484
+ }
3485
+ function createCollapsedPasteStore(scope) {
3486
+ return { scope: scope ?? generatePasteScope(), nextId: 1, items: /* @__PURE__ */ new Map() };
3487
+ }
3488
+ function allocateCollapsedPaste(store, text) {
3489
+ const id = store.nextId;
3490
+ store.nextId += 1;
3491
+ store.items.set(id, text);
3492
+ return { id, placeholder: formatCollapsedPastePlaceholder(id, text) };
3493
+ }
3494
+ function releaseCollapsedPaste(store, id) {
3495
+ store.items.delete(id);
3496
+ }
3497
+ function clearCollapsedPasteStore(store) {
3498
+ store.items.clear();
3499
+ store.nextId = 1;
3500
+ store.scope = generatePasteScope();
3501
+ }
3502
+ function expandCollapsedPastes(buffer, store) {
3503
+ COLLAPSED_PASTE_MODEL_REFERENCE_RE.lastIndex = 0;
3504
+ const expandedReferences = buffer.replace(
3505
+ COLLAPSED_PASTE_MODEL_REFERENCE_RE,
3506
+ (match, _displayIdRaw, scopeRaw, idRaw) => {
3507
+ if (scopeRaw && scopeRaw === store.scope) {
3508
+ const full = store.items.get(Number(idRaw));
3509
+ return full === void 0 ? match : full;
3510
+ }
3511
+ return match;
3512
+ }
3513
+ );
3514
+ if (store.items.size === 0) return expandedReferences;
3515
+ COLLAPSED_PASTE_PLACEHOLDER_RE.lastIndex = 0;
3516
+ return expandedReferences.replace(COLLAPSED_PASTE_PLACEHOLDER_RE, (match, idRaw) => {
3517
+ const id = Number(idRaw);
3518
+ const full = store.items.get(id);
3519
+ return full === void 0 ? match : full;
3520
+ });
3521
+ }
3522
+ function replaceCollapsedPastesWithReferences(buffer, store) {
3523
+ if (store.items.size === 0) return buffer;
3524
+ COLLAPSED_PASTE_PLACEHOLDER_RE.lastIndex = 0;
3525
+ return buffer.replace(COLLAPSED_PASTE_PLACEHOLDER_RE, (match, idRaw) => {
3526
+ const id = Number(idRaw);
3527
+ const full = store.items.get(id);
3528
+ return full === void 0 ? match : formatCollapsedPasteModelReference(id, full, store.scope);
3529
+ });
3530
+ }
3531
+ function releaseCollapsedPasteReferences(buffer, store) {
3532
+ const ids = /* @__PURE__ */ new Set();
3533
+ COLLAPSED_PASTE_MODEL_REFERENCE_RE.lastIndex = 0;
3534
+ let modelMatch;
3535
+ while ((modelMatch = COLLAPSED_PASTE_MODEL_REFERENCE_RE.exec(buffer)) !== null) {
3536
+ const id = Number(modelMatch[3]);
3537
+ const scope = modelMatch[2];
3538
+ if (scope && scope === store.scope) {
3539
+ ids.add(id);
3540
+ }
3541
+ }
3542
+ COLLAPSED_PASTE_PLACEHOLDER_RE.lastIndex = 0;
3543
+ let placeholderMatch;
3544
+ while ((placeholderMatch = COLLAPSED_PASTE_PLACEHOLDER_RE.exec(buffer)) !== null) {
3545
+ ids.add(Number(placeholderMatch[1]));
3546
+ }
3547
+ for (const id of ids) releaseCollapsedPaste(store, id);
3548
+ }
3549
+ function expandRangeToCollapsedPasteChips(buffer, start, end) {
3550
+ let s = Math.max(0, Math.min(start, end));
3551
+ let e = Math.max(s, Math.max(start, end));
3552
+ if (s === e) return { start: s, end: e };
3553
+ COLLAPSED_PASTE_PLACEHOLDER_RE.lastIndex = 0;
3554
+ let match;
3555
+ while ((match = COLLAPSED_PASTE_PLACEHOLDER_RE.exec(buffer)) !== null) {
3556
+ const chipStart = match.index;
3557
+ const chipEnd = chipStart + match[0].length;
3558
+ if (chipStart < e && chipEnd > s) {
3559
+ if (chipStart < s) s = chipStart;
3560
+ if (chipEnd > e) e = chipEnd;
3561
+ }
3562
+ }
3563
+ return { start: s, end: e };
3564
+ }
3565
+ function findCollapsedPasteSpanAt(buffer, pos, opts = {}) {
3566
+ COLLAPSED_PASTE_PLACEHOLDER_RE.lastIndex = 0;
3567
+ let match;
3568
+ while ((match = COLLAPSED_PASTE_PLACEHOLDER_RE.exec(buffer)) !== null) {
3569
+ const start = match.index;
3570
+ const end = start + match[0].length;
3571
+ const inside = pos > start && pos < end;
3572
+ const atEnd = opts.preferLeft && pos === end;
3573
+ const atStart = !opts.preferLeft && pos === start;
3574
+ if (inside || atEnd || atStart) {
3575
+ return { id: Number(match[1]), start, end };
3576
+ }
3577
+ }
3578
+ return null;
3579
+ }
3580
+
2838
3581
  // packages/cli/client/agentRun.ts
2839
3582
  import { ulid } from "ulid";
2840
3583
  async function loadRunLocalAgentTurn() {
2841
- const { runLocalAgentTurn } = await import("./agentRuntimeLocal-UQBMQI2M.js");
3584
+ const { runLocalAgentTurn } = await import("./agentRuntimeLocal-YNZSHMZC.js");
2842
3585
  return runLocalAgentTurn;
2843
3586
  }
2844
3587
  async function resolveCurrentMachineId(options) {
@@ -2851,6 +3594,12 @@ function resolveRequestedRuntimeMode(options) {
2851
3594
  return envMode;
2852
3595
  return "auto";
2853
3596
  }
3597
+ function canResolveCollapsedPasteReference(store, content) {
3598
+ const expand = (text) => expandCollapsedPastes(text, store) !== text;
3599
+ if (typeof content === "string") return expand(content);
3600
+ if (!Array.isArray(content)) return false;
3601
+ return content.some((part) => part.type === "text" && expand(part.text));
3602
+ }
2854
3603
  function buildDefaultLocalRuntimeAdapter(options) {
2855
3604
  return createCliLocalRuntimeAdapter({
2856
3605
  env: options.env,
@@ -2858,7 +3607,8 @@ function buildDefaultLocalRuntimeAdapter(options) {
2858
3607
  cwd: options.localRuntimeCwd,
2859
3608
  output: options.output,
2860
3609
  ...options.confirmDestructiveAction ? { confirmDestructiveAction: options.confirmDestructiveAction } : {},
2861
- ...options.requestUserChoice ? { requestUserChoice: options.requestUserChoice } : {}
3610
+ ...options.requestUserChoice ? { requestUserChoice: options.requestUserChoice } : {},
3611
+ ...options.pastedTextStore?.items.size ? { pastedTextStore: options.pastedTextStore } : {}
2862
3612
  });
2863
3613
  }
2864
3614
  function resolveLocalRuntimeAdapter(options) {
@@ -3083,12 +3833,14 @@ async function runHttpAgentTurn(options, authToken) {
3083
3833
  (name) => name.trim()
3084
3834
  );
3085
3835
  const shouldStream = !options.noStream && !options.background;
3836
+ const expandedMessage = options.pastedTextStore?.items.size ? expandCollapsedPastes(options.message, options.pastedTextStore) : options.message;
3837
+ const serverContextBlockScopes = options.contextBlockScopes && options.contextBlockScopes.length > 0 ? options.contextBlockScopes : options.extraContextBlocks && options.extraContextBlocks.length > 0 ? options.extraContextBlocks.map((block) => ({
3838
+ content: block,
3839
+ cacheScope: "turn"
3840
+ })) : void 0;
3086
3841
  const buildRequestBody = (stream) => JSON.stringify({
3087
3842
  agentKey: options.agentKey,
3088
- userInput: buildUserInputContent(
3089
- options.extraContextBlocks?.length ? [...options.extraContextBlocks, "", options.message].join("\n") : options.message,
3090
- options.imageUrls
3091
- ),
3843
+ userInput: buildUserInputContent(expandedMessage, options.imageUrls),
3092
3844
  runtimeContext: {
3093
3845
  surface: "cli",
3094
3846
  host: "terminal",
@@ -3108,6 +3860,7 @@ async function runHttpAgentTurn(options, authToken) {
3108
3860
  ...options.background ? { background: true } : {},
3109
3861
  ...typeof options.timeoutMs === "number" ? { timeoutMs: options.timeoutMs } : {},
3110
3862
  ...options.modelOverride ? { runtimeOptions: { quickChatModelOverride: options.modelOverride } } : {},
3863
+ ...serverContextBlockScopes ? { contextBlockScopes: serverContextBlockScopes } : {},
3111
3864
  stream
3112
3865
  });
3113
3866
  const postAgentRun = (stream) => fetchImpl(`${options.serverUrl}/api/agent/run`, {
@@ -3265,7 +4018,7 @@ async function runLocalAgentTurnForCli(options, settings) {
3265
4018
  } : void 0;
3266
4019
  const currentDialogId = options.continueDialogId ?? ulid();
3267
4020
  const runChildTurn = async (input) => {
3268
- const { runLocalAgentTurn } = await import("./agentRuntimeLocal-UQBMQI2M.js");
4021
+ const { runLocalAgentTurn } = await import("./agentRuntimeLocal-YNZSHMZC.js");
3269
4022
  return runLocalAgentTurn(input);
3270
4023
  };
3271
4024
  const createFreshChildBaseAdapter = () => {
@@ -3313,6 +4066,7 @@ async function runLocalAgentTurnForCli(options, settings) {
3313
4066
  spaceId: options.spaceId,
3314
4067
  runtimeContext
3315
4068
  });
4069
+ const expandedMessage = options.pastedTextStore?.items.size ? expandCollapsedPastes(options.message, options.pastedTextStore) : options.message;
3316
4070
  const workingLabel = `${options.agentName} -> working locally`;
3317
4071
  const turnOutput = createCliTurnOutput({
3318
4072
  options,
@@ -3325,6 +4079,19 @@ async function runLocalAgentTurnForCli(options, settings) {
3325
4079
  adapter,
3326
4080
  agentRef: options.agentKey,
3327
4081
  input: buildUserInputContent(options.message, options.imageUrls),
4082
+ ...expandedMessage !== options.message ? {
4083
+ persistedInput: buildUserInputContent(
4084
+ expandedMessage,
4085
+ options.imageUrls
4086
+ ),
4087
+ persistedInputReference: buildUserInputContent(
4088
+ options.message,
4089
+ options.imageUrls
4090
+ )
4091
+ } : {},
4092
+ ...options.pastedTextStore ? {
4093
+ contextReferenceResolver: (reference) => canResolveCollapsedPasteReference(options.pastedTextStore, reference)
4094
+ } : {},
3328
4095
  continueDialogId: currentDialogId,
3329
4096
  spaceId: options.spaceId,
3330
4097
  category: options.category,
@@ -3333,8 +4100,7 @@ async function runLocalAgentTurnForCli(options, settings) {
3333
4100
  background: options.background,
3334
4101
  noStream: options.noStream,
3335
4102
  ...runtimeContext ? { runtimeContext } : {},
3336
- ...options.extraContextBlocks?.length ? { contextBlocks: options.extraContextBlocks } : {},
3337
- ...options.contextBlockScopes?.length ? { contextBlockScopes: options.contextBlockScopes } : {},
4103
+ ...options.contextBlockScopes?.length ? { contextBlockScopes: options.contextBlockScopes } : options.extraContextBlocks?.length ? { contextBlocks: options.extraContextBlocks } : {},
3338
4104
  ...typeof options.timeoutMs === "number" ? { timeoutMs: options.timeoutMs } : {},
3339
4105
  ...options.actionGateHandler ? { onActionGate: options.actionGateHandler } : {},
3340
4106
  onLoopEvent: (event) => {
@@ -3370,10 +4136,12 @@ async function runLocalAgentTurnForCli(options, settings) {
3370
4136
  turnOutput.spinner.stop();
3371
4137
  const savedDialogId = error?.dialogId;
3372
4138
  if (error?.code === LOCAL_TURN_ABORTED_CODE || options.abortSignal?.aborted) {
4139
+ const pendingToolName = error?.pendingToolName;
3373
4140
  return {
3374
4141
  exitCode: 0,
3375
4142
  streamInterrupted: true,
3376
- ...savedDialogId ? { dialogId: savedDialogId } : {}
4143
+ ...savedDialogId ? { dialogId: savedDialogId } : {},
4144
+ ...pendingToolName ? { pendingToolName } : {}
3377
4145
  };
3378
4146
  }
3379
4147
  if (settings.reportFailure) {
@@ -3406,7 +4174,8 @@ async function runAgentTurn(options) {
3406
4174
  exitCode: localResult.exitCode,
3407
4175
  ...localResult.dialogId ? { dialogId: localResult.dialogId } : {},
3408
4176
  ...localResult.turnTokens ? { turnTokens: localResult.turnTokens } : {},
3409
- ...localResult.streamInterrupted ? { streamInterrupted: localResult.streamInterrupted } : {}
4177
+ ...localResult.streamInterrupted ? { streamInterrupted: localResult.streamInterrupted } : {},
4178
+ ...localResult.pendingToolName ? { pendingToolName: localResult.pendingToolName } : {}
3410
4179
  };
3411
4180
  }
3412
4181
  if (isMissingLocalAgentConfigError(localResult.localError, options.agentKey)) {
@@ -3460,196 +4229,6 @@ async function runAgentTurn(options) {
3460
4229
  import { existsSync as existsSync2, readFileSync as readFileSync2 } from "node:fs";
3461
4230
  import { join as join2 } from "node:path";
3462
4231
 
3463
- // packages/agent-runtime/quickChatIntentCore.ts
3464
- var INTENT_MODEL = "deepseek-v4-flash";
3465
- var INTENT_PROVIDER = "deepseek";
3466
- var QUICK_CHAT_INTENT_TIMEOUT_MS = 4e3;
3467
- var SHORT_GREETING_MAX_LENGTH = 20;
3468
- var SHORT_GREETING_PATTERN = /^(?:hi|hello|hey|hiya|yo|sup|howdy|嗨|哈喽|哈囉|你好|您好|在吗|在嘛|喂|早上好|中午好|下午好|晚上好|拜拜|再见|谢谢|thanks|thx|ok|好的|收到|了解)[!.。,、~~]?$/iu;
3469
- function isShortGreeting(text) {
3470
- const trimmed = text.trim();
3471
- if (!trimmed) return false;
3472
- if (trimmed.length > SHORT_GREETING_MAX_LENGTH) return false;
3473
- return SHORT_GREETING_PATTERN.test(trimmed);
3474
- }
3475
- var COMPLEXITY_SIMPLE_MAX_LENGTH = 80;
3476
- var COMPLEXITY_MEDIUM_MAX_LENGTH = 500;
3477
- var COMPLEXITY_KEYWORDS = /为什么|如何|分析|对比|比较|设计|架构|实现|原理|推导|评价|区别|关系|影响|优化|重构/;
3478
- var COMPLEXITY_CODE_BLOCK = /```[\s\S]*```/;
3479
- function estimateComplexity(text) {
3480
- const trimmed = text.trim();
3481
- const len = trimmed.length;
3482
- if (len > COMPLEXITY_MEDIUM_MAX_LENGTH) return "complex";
3483
- if (COMPLEXITY_CODE_BLOCK.test(trimmed)) return "complex";
3484
- if (len > COMPLEXITY_SIMPLE_MAX_LENGTH) return "medium";
3485
- if (COMPLEXITY_KEYWORDS.test(trimmed)) return "medium";
3486
- return "simple";
3487
- }
3488
- var TIER_DESCRIPTIONS = {
3489
- flash: "\u5FEB\u901F\u7B80\u5355\uFF1A\u95EE\u5019\u3001\u95F2\u804A\u3001\u5FEB\u901F\u95EE\u7B54\u3001\u7FFB\u8BD1\u3001\u77ED\u6587",
3490
- balanced: "\u5E73\u8861\u63A8\u7406\uFF1A\u5206\u6790\u3001\u4E2D\u7B49\u957F\u5EA6\u5199\u4F5C\u3001\u4EE3\u7801\u3001\u63A8\u7406",
3491
- quality: "\u9AD8\u8D28\u91CF\u6DF1\u5EA6\uFF1A\u590D\u6742\u63A8\u7406\u3001\u957F\u6587\u3001\u67B6\u6784\u8BBE\u8BA1\u3001\u6DF1\u5EA6\u5206\u6790"
3492
- };
3493
- function buildQuickChatIntentSystemPrompt(tierAgents) {
3494
- const agentList = tierAgents.map((t2) => ` - "${t2.agentKey}"\uFF1A${t2.description}`).join("\n");
3495
- return `\u4F60\u662F\u4E00\u4E2A\u610F\u56FE\u8DEF\u7531\u5668\u3002\u6839\u636E\u7528\u6237\u6D88\u606F\uFF0C\u5224\u65AD\u5E94\u8BE5\u4EA4\u7ED9\u54EA\u4E2A agent \u5904\u7406\u3002
3496
-
3497
- \u53EF\u9009 agent \u5217\u8868\uFF08agentKey \u4E0E\u63CF\u8FF0\uFF09\uFF1A
3498
- ${agentList}
3499
-
3500
- \u5224\u65AD\u539F\u5219\uFF08\u9ED8\u8BA4\u504F\u5411\u901A\u7528\u6863\u4F4D\uFF1B\u4E13\u804C agent \u5728\u660E\u786E\u5339\u914D\u65F6\u4F7F\u7528\uFF1B**\u7F16\u7801/\u672C\u5730\u4ED3\u5E93\u4EFB\u52A1\u8D70\u901A\u7528\u6863 + needsWorkspace=true**\uFF09\uFF1A
3501
- - \u9ED8\u8BA4\u60C5\u51B5\u4E0B\uFF0C**\u9664\u975E\u7528\u6237\u660E\u786E\u8868\u8FBE\u8981\u5EFA\u5E94\u7528/\u5EFA Agent/\u63D0\u4EA4\u53CD\u9988/\u591A Agent \u7F16\u6392**\uFF0C\u5426\u5219\u9009\u901A\u7528\u6863\u4F4D\uFF08flash/balanced/quality\uFF09\uFF1A
3502
- - \u7B80\u5355\u95EE\u5019\u3001\u95F2\u804A\u3001\u5FEB\u901F\u95EE\u7B54\u3001\u7FFB\u8BD1\u3001\u77ED\u6587 \u2192 \u9009 flash \u6863
3503
- - \u9700\u8981\u63A8\u7406\u3001\u5206\u6790\u3001\u4E2D\u7B49\u957F\u5EA6\u5199\u4F5C\u3001\u666E\u901A\u4EE3\u7801\u89E3\u91CA/\u67B6\u6784\u95EE\u7B54 \u2192 \u9009 balanced \u6863
3504
- - \u590D\u6742\u63A8\u7406\u3001\u957F\u6587\u3001\u67B6\u6784\u8BBE\u8BA1\u3001\u6DF1\u5EA6\u5206\u6790 \u2192 \u9009 quality \u6863
3505
- - **\u660E\u786E\u7F16\u7801\u4EFB\u52A1\uFF08\u5B9E\u73B0\u529F\u80FD\u3001\u4FEE bug\u3001refactor\u3001\u5199/\u8865\u6D4B\u8BD5\u3001\u8DD1 build/tests/ci\uFF09\u6216\u67E5\u770B\u672C\u673A\u4ED3\u5E93/\u4EE3\u7801\u72B6\u6001\uFF08git/\u5206\u652F/commit/\u672C\u5730\u4E0E\u8FDC\u7A0B\u5DEE\u8DDD/\u672A\u63D0\u4EA4\u6539\u52A8\u7B49\uFF09** \u2192 \u9009 balanced \u6216 quality \u6863\uFF08\u6309\u590D\u6742\u5EA6\uFF1B**\u4E0D\u8981\u9009 flash**\uFF09\uFF0C\u4E14 needsWorkspace=true
3506
- - \u4E13\u804C agent \u8DEF\u7531\u89C4\u5219\uFF08\u6709\u660E\u786E\u5339\u914D\u65F6\u4F7F\u7528\uFF09\uFF1A
3507
- - \u8981\u63D0\u4EA4/\u8BB0\u5F55 bug\u3001\u4F53\u9A8C\u95EE\u9898\u3001\u6570\u636E\u5F02\u5E38\u3001\u4EA7\u54C1\u5EFA\u8BAE\uFF0C\u6216\u53E3\u8BED\u5982\u300C\u60F3\u53CD\u9988\u4E00\u4E9B\u95EE\u9898\u300D\u300C\u53CD\u9988\u4E00\u4E0B\u300D\u2192 \u9009\u610F\u89C1\u53CD\u9988\u4E13\u804C agent
3508
- - \u8981\u65B0\u5EFA\u6216\u5B9A\u5236 AI/Agent/\u667A\u80FD\u4F53\u52A9\u624B\uFF08\u542B\u914D\u7F6E\u5DE5\u5177\u3001\u77E5\u8BC6\u3001\u786E\u8BA4\u521B\u5EFA\uFF09\u2192 \u9009\u521B\u5EFA Agent \u4E13\u804C agent
3509
- - \u8981\u505A/\u6539/\u53D1\u5E03\u7F51\u7AD9\u3001\u7F51\u9875\u3001\u5C0F\u5E94\u7528\u3001\u9884\u7EA6\u9875\u3001\u535A\u5BA2\u3001\u770B\u677F \u2192 \u9009\u5E94\u7528\u6784\u5EFA\u4E13\u804C agent
3510
- - \u8981\u6D3E\u591A\u4E2A agent\u3001\u591A agent \u5E76\u884C\u3001\u62C6\u6210\u4EFB\u52A1\u540E\u53F0\u6267\u884C\u3001\u591A\u4E2A agent review\u3001\u8BA9\u4E0D\u540C agent \u8BA8\u8BBA/\u4F1A\u5546 \u2192 \u9009\u591A Agent \u7F16\u6392\u4E13\u804C agent\uFF08\u663E\u5F0F multi-agent \u4F18\u5148\uFF09
3511
- - **\u62FF\u4E0D\u51C6\u65F6**\uFF1A\u7EAF\u95F2\u804A\u9009 flash\uFF1B**\u82E5\u6CBE\u8FB9\u672C\u5730\u4ED3\u5E93/\u5F53\u524D\u4EE3\u7801\u72B6\u6001\uFF0C\u9009 balanced/quality + needsWorkspace=true**\u3002
3512
-
3513
- \u540C\u65F6\u5224\u65AD\u672C\u8F6E\u662F\u5426\u9700\u8981\u6CE8\u5165\u300C\u5DE5\u4F5C\u533A\u53EA\u8BFB\u5DE5\u5177\u300D\uFF08listFiles/globFiles/searchFiles/readFile/execShell \u7B49\uFF09\uFF1A
3514
- - needsWorkspace=true \u7684\u573A\u666F\uFF1A\u7528\u6237\u8981\u8BFB/\u6539/\u5206\u6790\u6587\u4EF6\u6216\u4EE3\u7801\u3001\u63D0\u5230\u4E86\u6587\u4EF6\u8DEF\u5F84/\u6269\u5C55\u540D\uFF08.md/.csv/.ts \u7B49\uFF09\u3001\u63D0\u5230\u5DE5\u4F5C\u533A/\u4EE3\u7801\u5E93/\u4ED3\u5E93/\u76EE\u5F55/git/\u5206\u652F\u3001\u8981\u770B\u5F53\u524D\u4EE3\u7801\u6216\u4ED3\u5E93\u72B6\u6001\u3001\u672C\u5730\u641C\u7D22/\u67E5\u770B\u4EE3\u7801\u3002
3515
- - needsWorkspace=false \u7684\u573A\u666F\uFF1A\u901A\u7528\u77E5\u8BC6\u95EE\u7B54\uFF08\u5982\u300C\u5E7F\u4E1C\u7ECF\u6D4E\u6570\u636E\u300D\u300C\u5199\u4E00\u9996\u8BD7\u300D\uFF09\u3001\u7EAF\u95F2\u804A\u95EE\u5019\u3001\u7FFB\u8BD1\u3001\u4E0D\u6D89\u53CA\u672C\u5730\u6587\u4EF6/\u4ED3\u5E93\u3002
3516
- - \u6F0F\u5224\uFF08\u7528\u6237\u8981\u6587\u4EF6\u800C\u6CA1\u5E26\u5DE5\u5177\uFF09\u6BD4\u8BEF\u5224\uFF08\u767D\u641C\u51E0\u8F6E\uFF09\u4EE3\u4EF7\u66F4\u9AD8\uFF0C\u5B81\u53EF\u504F\u5BBD\u5224 true\u3002
3517
-
3518
- \u5728\u7ED9\u51FA agentKey \u4E4B\u524D\uFF0C\u5148\u5728\u5FC3\u91CC\u533A\u5206\u5019\u9009\u6863\u4F4D\u7684\u8FB9\u754C\u518D\u7ED9\u7F6E\u4FE1\u5EA6\uFF1Abalanced \u4E0E quality \u7684\u8FB9\u754C\u5728\u4E8E\u590D\u6742\u5EA6/\u7BC7\u5E45/\u662F\u5426\u9700\u8981\u6DF1\u5EA6\u5206\u6790\uFF0C\u62FF\u4E0D\u51C6\u5C31\u7ED9\u4F4E confidence\u3002
3519
-
3520
- \u540C\u65F6\u5224\u65AD\u672C\u8F6E\u6D88\u606F\u662F\u5426\u9700\u8981\u6302\u8F7D\u5BF9\u8C61\u64CD\u4F5C\u6280\u80FD\uFF08skills \u6570\u7EC4\uFF0C\u672A\u547D\u4E2D\u7ED9 []\uFF09\uFF1A
3521
- - \u7528\u6237\u8981\u65B0\u5EFA/\u6574\u7406/\u5F55\u5165/\u6279\u91CF\u5904\u7406\u8868\u683C\u6570\u636E\uFF08\u5EFA\u8868\u3001\u52A0\u884C\u3001\u6539\u5217\u3001\u6309\u6761\u4EF6\u6574\u7406\u6570\u636E\uFF09\u2192 skills \u542B "table"
3522
- - \u7528\u6237\u8981\u5199/\u6DA6\u8272/\u6539\u5199/\u7EED\u5199/\u6392\u7248\u4E00\u7BC7\u6587\u6863\u6216\u6587\u7AE0 \u2192 skills \u542B "doc"
3523
- - \u7528\u6237\u8981\u5199/\u6539/\u5B9E\u73B0/\u4FEE bug/refactor/\u8865\u6D4B\u8BD5/\u5BA1\u67E5\u5E76\u4FEE\u6539\u4EE3\u7801 \u2192 skills \u542B "code"\uFF08\u4EC5\u95EE\u901A\u7528\u77E5\u8BC6\u3001\u7EAF\u95F2\u804A\u3001\u53EA\u67E5\u770B git/\u4ED3\u5E93\u72B6\u6001\u800C\u4E0D\u4FEE\u6539\u4EE3\u7801\u65F6\u4E0D\u6302 "code"\uFF09
3524
- - \u666E\u901A\u95EE\u7B54/\u7EAF\u95F2\u804A/\u5EFA\u5E94\u7528 \u2192 skills \u4E3A []
3525
-
3526
- \u53EA\u8F93\u51FA JSON\uFF0C\u4E0D\u8981\u8F93\u51FA\u5176\u4ED6\u5185\u5BB9\uFF1A
3527
- {"confidence": <0\u52301\u4E4B\u95F4\u7684\u5C0F\u6570\uFF0C\u8868\u793A\u4F60\u5BF9\u8FD9\u4E2A\u5206\u7C7B\u5224\u65AD\u7684\u628A\u63E1\u7A0B\u5EA6>, "agentKey": "<\u4ECE\u5217\u8868\u4E2D\u9009\u62E9\u7684 agentKey>", "needsWorkspace": <true \u6216 false>, "skills": <\u5B57\u7B26\u4E32\u6570\u7EC4\uFF0C\u5143\u7D20\u53EA\u80FD\u662F "table" | "doc" | "code"\uFF0C\u672A\u547D\u4E2D\u7ED9 []>}`;
3528
- }
3529
- function parseQuickChatIntentResult(content, tierAgents) {
3530
- try {
3531
- const parsed = JSON.parse(content.trim());
3532
- if (typeof parsed !== "object" || parsed === null || !("agentKey" in parsed)) return null;
3533
- const key = parsed.agentKey;
3534
- if (typeof key !== "string") return null;
3535
- if (!tierAgents.some((t2) => t2.agentKey === key)) return null;
3536
- const rawNeedsWorkspace = parsed.needsWorkspace;
3537
- const needsWorkspace = rawNeedsWorkspace === true;
3538
- const rawConfidence = parsed.confidence;
3539
- const confidence = typeof rawConfidence === "number" && Number.isFinite(rawConfidence) && rawConfidence >= 0 && rawConfidence <= 1 ? rawConfidence : void 0;
3540
- const rawSkills = parsed.skills;
3541
- let skills;
3542
- if (Array.isArray(rawSkills)) {
3543
- const filtered = [...new Set(rawSkills)].filter(
3544
- (s) => s === "table" || s === "doc" || s === "code"
3545
- );
3546
- if (filtered.length > 0) skills = filtered;
3547
- }
3548
- return { agentKey: key, needsWorkspace, confidence, skills };
3549
- } catch {
3550
- return null;
3551
- }
3552
- }
3553
-
3554
- // packages/cli/client/autoModelRouter.ts
3555
- var CLI_AUTO_TIER_AGENT_KEYS = {
3556
- flash: PUBLIC_DEEPSEEK_V4_FLASH_AGENT_KEY,
3557
- balanced: PUBLIC_DEEPSEEK_V4_PRO_AGENT_KEY,
3558
- quality: PUBLIC_GLM_52_AGENT_KEY
3559
- };
3560
- var CLI_IMAGE_AGENT_KEY = PUBLIC_KIMI_K26_IMAGE_AGENT_KEY;
3561
- var CLI_AUTO_TIER_AGENT_KEY_TABLE = {
3562
- [CLI_AUTO_TIER_AGENT_KEYS.flash]: true,
3563
- [CLI_AUTO_TIER_AGENT_KEYS.balanced]: true,
3564
- [CLI_AUTO_TIER_AGENT_KEYS.quality]: true
3565
- };
3566
- var buildRouteOptions = () => ["flash", "balanced", "quality"].map((tier) => ({
3567
- tier,
3568
- agentKey: CLI_AUTO_TIER_AGENT_KEYS[tier],
3569
- description: TIER_DESCRIPTIONS[tier]
3570
- }));
3571
- var tierForAgentKey = (agentKey) => {
3572
- for (const tier of ["flash", "balanced", "quality"]) {
3573
- if (CLI_AUTO_TIER_AGENT_KEYS[tier] === agentKey) return tier;
3574
- }
3575
- return null;
3576
- };
3577
- function resolveCliAutoFallbackTier(text) {
3578
- switch (estimateComplexity(text)) {
3579
- case "complex":
3580
- return "quality";
3581
- case "medium":
3582
- return "balanced";
3583
- case "simple":
3584
- default:
3585
- return "flash";
3586
- }
3587
- }
3588
- async function classifyCliAutoRoute(text, options) {
3589
- const timeoutMs = options.timeoutMs ?? QUICK_CHAT_INTENT_TIMEOUT_MS;
3590
- const fallbackTier = resolveCliAutoFallbackTier(text);
3591
- const fallback = () => ({
3592
- agentKey: CLI_AUTO_TIER_AGENT_KEYS[fallbackTier],
3593
- tier: fallbackTier,
3594
- classified: false
3595
- });
3596
- if (!text.trim()) return fallback();
3597
- if (isShortGreeting(text)) {
3598
- return {
3599
- agentKey: CLI_AUTO_TIER_AGENT_KEYS.flash,
3600
- tier: "flash",
3601
- classified: true
3602
- };
3603
- }
3604
- if (!options.authToken) return fallback();
3605
- const fetchImpl = options.fetchImpl ?? globalThis.fetch;
3606
- const controller = new AbortController();
3607
- const timeoutHandle = setTimeout(() => controller.abort(), timeoutMs);
3608
- try {
3609
- const routeOptions = buildRouteOptions();
3610
- const messages = [
3611
- { role: "system", content: buildQuickChatIntentSystemPrompt(routeOptions) },
3612
- { role: "user", content: text }
3613
- ];
3614
- const { url, init } = buildPlatformChatCompletionRequest({
3615
- providerConfig: {
3616
- serverUrl: options.serverUrl,
3617
- authToken: options.authToken,
3618
- agentKey: CLI_AUTO_TIER_AGENT_KEYS.flash,
3619
- model: INTENT_MODEL,
3620
- provider: INTENT_PROVIDER,
3621
- endpoint: resolvePlatformChatCompletionsEndpoint(INTENT_PROVIDER) ?? "",
3622
- requestOptions: {}
3623
- },
3624
- messages,
3625
- stream: false
3626
- });
3627
- const response = await fetchImpl(url, {
3628
- ...init,
3629
- signal: controller.signal
3630
- });
3631
- if (!response.ok) return fallback();
3632
- const data = parsePlatformChatCompletionData(await response.text());
3633
- const content = data?.choices?.[0]?.message?.content;
3634
- if (typeof content !== "string" || !content.trim()) return fallback();
3635
- const parsed = parseQuickChatIntentResult(content, routeOptions);
3636
- if (!parsed) return fallback();
3637
- const tier = tierForAgentKey(parsed.agentKey) ?? fallbackTier;
3638
- return {
3639
- agentKey: parsed.agentKey,
3640
- tier,
3641
- classified: true,
3642
- confidence: parsed.confidence,
3643
- needsWorkspace: parsed.needsWorkspace,
3644
- skills: parsed.skills
3645
- };
3646
- } catch {
3647
- return fallback();
3648
- } finally {
3649
- clearTimeout(timeoutHandle);
3650
- }
3651
- }
3652
-
3653
4232
  // packages/cli/agentRunPrompts.ts
3654
4233
  import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
3655
4234
  import { dirname, extname, isAbsolute, join, relative as relativePath, resolve, sep } from "node:path";
@@ -3993,16 +4572,16 @@ var buildCjkTokens = (text) => {
3993
4572
  }
3994
4573
  return tokens;
3995
4574
  };
3996
- var tokenize = (text) => {
4575
+ var tokenize2 = (text) => {
3997
4576
  const normalized = text.toLowerCase();
3998
4577
  const wordTokens = normalized.split(/[\s,.;:!?()[\]{}"'`,。!?:;、]+/).map((token) => token.trim()).filter((token) => token.length >= 2);
3999
4578
  return [...wordTokens, ...buildCjkTokens(normalized)];
4000
4579
  };
4001
4580
  var keywordScore = (query, item) => {
4002
- const queryTokens = new Set(tokenize(query));
4581
+ const queryTokens = new Set(tokenize2(query));
4003
4582
  if (queryTokens.size === 0) return 0;
4004
4583
  const haystack = /* @__PURE__ */ new Set([
4005
- ...tokenize(item.content),
4584
+ ...tokenize2(item.content),
4006
4585
  ...(item.tags ?? []).map((tag) => tag.toLowerCase()),
4007
4586
  item.patternKey?.toLowerCase() ?? ""
4008
4587
  ]);
@@ -4616,8 +5195,7 @@ ${mdContent}`);
4616
5195
  traceTools: parsed.traceTools,
4617
5196
  ...parsed.eventsMode ? { eventsMode: parsed.eventsMode } : {},
4618
5197
  ...parsed.taskEvidence ? { taskEvidence: parsed.taskEvidence } : {},
4619
- ...extraContextBlocks.length > 0 ? { extraContextBlocks } : {},
4620
- ...contextBlockScopes.length > 0 ? { contextBlockScopes } : {}
5198
+ ...contextBlockScopes.length > 0 ? { contextBlockScopes } : extraContextBlocks.length > 0 ? { extraContextBlocks } : {}
4621
5199
  });
4622
5200
  let result = await raceWithWatchdog(
4623
5201
  runner({
@@ -4748,10 +5326,28 @@ function isBalanceExhaustedError(error) {
4748
5326
  }
4749
5327
 
4750
5328
  export {
5329
+ CLI_AUTO_TIER_AGENT_KEYS,
5330
+ CLI_IMAGE_AGENT_KEY,
5331
+ CLI_AUTO_TIER_AGENT_KEY_TABLE,
5332
+ resolveCliAutoFallbackTier,
5333
+ classifyCliAutoRoute,
5334
+ resolveAgentContextWindow,
4751
5335
  formatTokenCount,
4752
5336
  renderTokenStatus,
4753
5337
  resolveCliColorEnabled,
4754
5338
  dimCliText,
5339
+ ANSI_ESCAPE_REGEX,
5340
+ stripAnsi,
5341
+ applyTerminalOutputToText,
5342
+ displayWidth,
5343
+ visibleWidth,
5344
+ truncateAnsi,
5345
+ fitAnsiLine,
5346
+ countPhysicalLines,
5347
+ takeDisplayWidth,
5348
+ padOrTruncateToWidth,
5349
+ wrapTranscriptLine,
5350
+ wrapTextToLines,
4755
5351
  THEME_PALETTES,
4756
5352
  getActiveThemeName,
4757
5353
  setActiveThemeName,
@@ -4760,22 +5356,24 @@ export {
4760
5356
  getActiveDensity,
4761
5357
  setActiveDensity,
4762
5358
  resolveTuiBrightness,
5359
+ setActiveTerminalBaseHex,
4763
5360
  surfaceBackgroundSequence,
4764
5361
  themeColorSequence,
4765
5362
  themeText,
4766
- highlightMarkdown,
4767
5363
  formatAssistantDisplay,
4768
5364
  normalizeThinkingDisplayMode,
4769
- parseCliLocale,
4770
- getCliLocale,
4771
- setCliLocale,
4772
- initCliLocale,
4773
- t,
4774
5365
  normalizeToolDisplayMode,
5366
+ COLLAPSED_PASTE_PLACEHOLDER_RE,
5367
+ shouldCollapsePaste,
5368
+ createCollapsedPasteStore,
5369
+ allocateCollapsedPaste,
5370
+ releaseCollapsedPaste,
5371
+ clearCollapsedPasteStore,
5372
+ replaceCollapsedPastesWithReferences,
5373
+ releaseCollapsedPasteReferences,
5374
+ expandRangeToCollapsedPasteChips,
5375
+ findCollapsedPasteSpanAt,
4775
5376
  runAgentTurn,
4776
- CLI_IMAGE_AGENT_KEY,
4777
- CLI_AUTO_TIER_AGENT_KEY_TABLE,
4778
- classifyCliAutoRoute,
4779
5377
  resolveWorkflowReference,
4780
5378
  resolveSkillReference,
4781
5379
  buildSkillContextBlocks,