nolo-cli 0.10.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 (125) hide show
  1. package/{_executeModel-YAXYAUOK.js → _executeModel-MWAY74HA.js} +47 -44
  2. package/{action-TLI3V62L.js → action-RAXNQQKC.js} +9 -10
  3. package/{addContentAction-PLWJSCOZ.js → addContentAction-ZHI7TVV3.js} +8 -10
  4. package/{addDialogAgentAction-BJ6SB76X.js → addDialogAgentAction-JWXPKXNC.js} +7 -8
  5. package/{agentDeleteCommand-2VYX73U5.js → agentDeleteCommand-LXR5A5FV.js} +36 -26
  6. package/{agentEmailCommands-3GDZIX64.js → agentEmailCommands-DXRAP7BB.js} +63 -58
  7. package/{agentListCommands-UWVBT3LH.js → agentListCommands-ZFMS5ZLY.js} +132 -35
  8. package/{agentMachineCommands-WOKMUG2Y.js → agentMachineCommands-ZJLYVV52.js} +40 -29
  9. package/{agentPullCommand-O2MTUAFR.js → agentPullCommand-KRBRIFIY.js} +6 -6
  10. package/{agentRecordCommands-MVNZRH3U.js → agentRecordCommands-DFS626TB.js} +55 -50
  11. package/{agentRunCommand-K7THIJLA.js → agentRunCommand-GWBIE2TS.js} +60 -56
  12. package/{agentRunControl-K4VKNEHF.js → agentRunControl-IX4F5W2C.js} +3 -3
  13. package/{agentRuntimeLocal-WJIGU24U.js → agentRuntimeLocal-YNZSHMZC.js} +29 -14
  14. package/{agentSlice-LL5TKZEO.js → agentSlice-T2PXOEPQ.js} +9 -10
  15. package/{authCommand-TC2SW2CQ.js → authCommand-DMW336GT.js} +13 -13
  16. package/{authCommands-XPEHTKSM.js → authCommands-GH5T6RYV.js} +6 -6
  17. package/{chunk-5JGGZCZL.js → chunk-3HHTVM6G.js} +64 -5
  18. package/chunk-3QKO4EHV.js +112 -0
  19. package/{chunk-AUQ747NZ.js → chunk-43UD5ZP7.js} +76 -15
  20. package/{chunk-6SLCD4RB.js → chunk-4BTHUYMY.js} +596 -67
  21. package/{chunk-T7R3NGUU.js → chunk-4EH7AR52.js} +13 -13
  22. package/{chunk-C3RUNRHT.js → chunk-4GBNEA5B.js} +1 -1
  23. package/{chunk-4IJYA27C.js → chunk-4LG74DRG.js} +1 -1
  24. package/{chunk-2FTTDCD4.js → chunk-4ON5AV72.js} +2 -1
  25. package/{chunk-IWX4UW2E.js → chunk-524BDL33.js} +89 -8
  26. package/{chunk-EXXFGKF7.js → chunk-5ITRDSHY.js} +1400 -119
  27. package/{chunk-ISNCLGUZ.js → chunk-5NBHQD4D.js} +4 -3
  28. package/{chunk-7KNKFIRO.js → chunk-6LMFFG3K.js} +3 -3
  29. package/{chunk-PAKN26FP.js → chunk-6OVCRC72.js} +1 -1
  30. package/{chunk-CKOJQDKR.js → chunk-7JJCGV7N.js} +146 -3
  31. package/{chunk-KBKYAONQ.js → chunk-7MYHLZ3F.js} +2 -2
  32. package/{chunk-PIVFPOW6.js → chunk-AM53Q2SD.js} +175 -2541
  33. package/chunk-BYXBJQAS.js +0 -0
  34. package/{chunk-CL3IOKGK.js → chunk-DE5BA4O6.js} +20 -2
  35. package/{chunk-6KUOUWMP.js → chunk-DRMGJFGQ.js} +300 -89
  36. package/{chunk-QAALPJS7.js → chunk-EBH7G34M.js} +20 -7
  37. package/{chunk-HJGEVL7C.js → chunk-G3B356GF.js} +15 -17
  38. package/{chunk-OZMMKDBI.js → chunk-GDBCUWQ3.js} +26 -20
  39. package/{chunk-I5URP43I.js → chunk-GPZM7QH6.js} +9 -9
  40. package/chunk-IKXL2HZ3.js +70 -0
  41. package/{chunk-AS4PVWA4.js → chunk-IVAOVLM7.js} +1 -1
  42. package/{chunk-TNPIMII7.js → chunk-JUN3HFMN.js} +221 -81
  43. package/{chunk-HFASY3WO.js → chunk-JZDIW766.js} +1 -1
  44. package/{chunk-6JJWFVZ6.js → chunk-LHSJMY5V.js} +17 -17
  45. package/chunk-LTRXGFMS.js +83 -0
  46. package/{chunk-YIHFXH5Q.js → chunk-MEVCDATU.js} +3 -3
  47. package/{chunk-TILFE6LV.js → chunk-NCGFB7NN.js} +5 -3
  48. package/{chunk-BE2OOJ5P.js → chunk-NITP2JDG.js} +42 -11
  49. package/{chunk-YPRZSPF3.js → chunk-OCDEWRE2.js} +1 -1
  50. package/{chunk-VVX233PH.js → chunk-OHEKYYJF.js} +9 -9
  51. package/chunk-OOIN7HSO.js +146 -0
  52. package/{chunk-WPE4F4Z6.js → chunk-OPKKB25T.js} +1 -1
  53. package/{chunk-OR2XR25C.js → chunk-QCA3EPYK.js} +8 -8
  54. package/{chunk-SL35K7AH.js → chunk-QLUFR47U.js} +13 -83
  55. package/{chunk-CDTLMEB3.js → chunk-RNQ5BLR2.js} +1 -1
  56. package/{chunk-AVMKZHBC.js → chunk-RSEUHW6T.js} +3 -2
  57. package/{chunk-TYSCFY6S.js → chunk-RZ735TLX.js} +762 -167
  58. package/chunk-S3UTETIC.js +4885 -0
  59. package/chunk-S73OEOHH.js +2286 -0
  60. package/{chunk-JRKKFRAV.js → chunk-TSKWE74T.js} +58 -8
  61. package/{chunk-A67QFHAA.js → chunk-UG3WOFU6.js} +1 -1
  62. package/{chunk-4ZDM73SD.js → chunk-V2J635L5.js} +1 -1
  63. package/chunk-VC6OZXO5.js +298 -0
  64. package/{chunk-7U44LYTR.js → chunk-WPHL6ALY.js} +1 -1
  65. package/{chunk-4SIMLBEU.js → chunk-WTYKCU4W.js} +9 -9
  66. package/{chunk-NPVBXJY2.js → chunk-WWU275LU.js} +9 -9
  67. package/{chunk-ZQ2UM4KG.js → chunk-WZSRQNQG.js} +1 -292
  68. package/{chunk-DSZUWUYB.js → chunk-XHQWJUW4.js} +2 -2
  69. package/{chunk-GAKEBQD6.js → chunk-YDCZVUFP.js} +4 -0
  70. package/{chunk-2O4IZNTG.js → chunk-YTQLJYLB.js} +2 -2
  71. package/{chunk-3Y3HW5PX.js → chunk-ZPFRLGIZ.js} +1512 -935
  72. package/{chunk-5KLGBAAR.js → chunk-ZR4VHQ5D.js} +14 -13
  73. package/cliEnvHelpers-VYC2OPTB.js +30 -0
  74. package/{cliExecutor-DNE7TCC4.js → cliExecutor-K3F7DMRO.js} +2 -2
  75. package/{createAgentAutomationAction-CCE7CWGQ.js → createAgentAutomationAction-G32GKDGV.js} +22 -23
  76. package/{createDialogAction-QTRR4AT7.js → createDialogAction-TISANRZK.js} +25 -25
  77. package/{createPageAction-Y4KQOAJE.js → createPageAction-O7KOYNV4.js} +27 -27
  78. package/{dbSlice-WWNV2SGX.js → dbSlice-WDP2ZZHK.js} +7 -8
  79. package/{deleteFile-OW53A6BX.js → deleteFile-M7UNIUOO.js} +5 -5
  80. package/{dialogCommands-SMKIAC3Y.js → dialogCommands-6JPB3YQY.js} +33 -23
  81. package/{dialogSlice-PT7YBWNE.js → dialogSlice-PRHHYSP5.js} +21 -22
  82. package/{docCreateCommands-RFNA4HNM.js → docCreateCommands-75E6TZNN.js} +36 -25
  83. package/{docDeleteCommands-4YZ325M6.js → docDeleteCommands-EJHLN7LW.js} +37 -27
  84. package/{docReadCommands-RT6VAFFG.js → docReadCommands-RJYBC4FS.js} +36 -25
  85. package/{docStore-QUQZAFZF.js → docStore-H5VWKT5D.js} +22 -23
  86. package/{docUpdateCommands-EKKKNYPW.js → docUpdateCommands-MG4CNISV.js} +36 -25
  87. package/fetchMessages-KTNM7QAR.js +1 -1
  88. package/{getPricing-3E6UNPKL.js → getPricing-6TOZXPAU.js} +7 -3
  89. package/{handleSendMessageAction-5NSYAS53.js → handleSendMessageAction-QTUGICSZ.js} +22 -23
  90. package/index.js +77 -76
  91. package/{machineCommands-DOOSIUKG.js → machineCommands-MAV7M3TK.js} +67 -60
  92. package/{machineWsRunDispatch-PIOIQRBW.js → machineWsRunDispatch-ZOEGTKHC.js} +54 -49
  93. package/{memoryCommands-O4MIPIWQ.js → memoryCommands-AFMES3LN.js} +5 -5
  94. package/{models-4OPOOLFS.js → models-LSCRJJ6P.js} +2 -2
  95. package/package.json +1 -1
  96. package/{read-GW7ZEI23.js → read-2MIMRBZ2.js} +5 -5
  97. package/{readDocTool-HUFU6OCT.js → readDocTool-QHVGQHUJ.js} +1 -1
  98. package/{readlineWorkspace-QEAOH5EP.js → readlineWorkspace-SWQKC7ZS.js} +1126 -678
  99. package/{removeDialogAgentAction-OHMCNSSD.js → removeDialogAgentAction-GTX5AN54.js} +11 -11
  100. package/{runAgentClientLoop-AIGLXC3R.js → runAgentClientLoop-P25HACXX.js} +42 -40
  101. package/{runtimeDoctorCommands-LRHLPDRC.js → runtimeDoctorCommands-QNF3J3UV.js} +6 -6
  102. package/{setDialogExtraReferencesAction-YJUM5BWQ.js → setDialogExtraReferencesAction-WFQ63KYO.js} +7 -8
  103. package/{setPrimaryDialogAgentAction-EBAREZDM.js → setPrimaryDialogAgentAction-P57FXTSU.js} +11 -11
  104. package/{settingSlice-UW4IUI5L.js → settingSlice-CK5YZGNI.js} +8 -9
  105. package/skillDiscovery-ZYHSX7VD.js +16 -0
  106. package/{spaceCommands-BKHSPR73.js → spaceCommands-6O5EFEM5.js} +41 -33
  107. package/{spaceSlice-TYNWE3OC.js → spaceSlice-4EXTYXS4.js} +25 -24
  108. package/{streamAgentChatTurn-HRMFFA7E.js → streamAgentChatTurn-Q3FJAHG2.js} +205 -107
  109. package/{tableCommands-O7O2LBEG.js → tableCommands-E4SQWDOX.js} +10 -10
  110. package/{tools-3JNDS3WH.js → tools-AHNQE4GP.js} +33 -31
  111. package/{tuiSummaryLlmCaller-RV3THLZF.js → tuiSummaryLlmCaller-TXLF4MEI.js} +8 -6
  112. package/{updateCommands-VOSPKXFF.js → updateCommands-XZDOOYFH.js} +13 -5
  113. package/{updateDialogTitleAction-OCETSKCP.js → updateDialogTitleAction-XZDVLKVX.js} +25 -25
  114. package/chunk-5MMAK75Q.js +0 -15
  115. package/chunk-AZPCASRE.js +0 -36
  116. package/chunk-BBYVOSU2.js +0 -792
  117. package/chunk-DCOA4QSN.js +0 -105
  118. package/chunk-UAD2WT54.js +0 -64
  119. package/{chunk-DZ3XJVET.js → chunk-3QAF2LTL.js} +3 -3
  120. package/{chunk-X7W4TNB4.js → chunk-CMKUBIGW.js} +3 -3
  121. package/{chunk-4CQLVGRV.js → chunk-ID4G2MAR.js} +3 -3
  122. package/{chunk-5CS33IBL.js → chunk-PDL2AV3E.js} +3 -3
  123. package/{chunk-EHLHSX7R.js → chunk-TOILAPLH.js} +3 -3
  124. package/{chunk-UTLZINAP.js → chunk-TSUJOM6N.js} +10 -10
  125. package/{offlineMarxistsAgentCommand-BCPJITJL.js → offlineMarxistsAgentCommand-5OOWZLJI.js} +3 -3
@@ -1,8 +1,3 @@
1
- import {
2
- createRunActivityTracker,
3
- finalizeRunRecord,
4
- spawnLocalBackgroundRun
5
- } from "./chunk-2FTTDCD4.js";
6
1
  import {
7
2
  buildLocalRunEnv,
8
3
  isFullstackCodingAgentRef,
@@ -11,100 +6,121 @@ import {
11
6
  resolveRawAgentInput,
12
7
  resolveServerUrl,
13
8
  writeUsage
14
- } from "./chunk-DZ3XJVET.js";
9
+ } from "./chunk-3QAF2LTL.js";
15
10
  import {
11
+ resolveMachineId
12
+ } from "./chunk-6HYVJV7B.js";
13
+ import {
14
+ agentRunCardLabels,
16
15
  createCliCallAgentToolExecutor,
17
16
  createCliLocalRuntimeAdapter,
18
- isBuiltinNoloAgentRef
19
- } from "./chunk-EXXFGKF7.js";
17
+ getCliLocale,
18
+ isBuiltinNoloAgentRef,
19
+ t,
20
+ toolLabel
21
+ } from "./chunk-5ITRDSHY.js";
22
+ import {
23
+ CliProviderQuotaError
24
+ } from "./chunk-CMKUBIGW.js";
20
25
  import {
21
26
  getReadableCliDb
22
27
  } from "./chunk-W4NVOSFF.js";
23
28
  import {
24
29
  readDbRecord,
25
30
  resolveAgentRecordFromHybridStore
26
- } from "./chunk-OR2XR25C.js";
31
+ } from "./chunk-QCA3EPYK.js";
27
32
  import {
28
33
  normalizeAgentHandle
29
- } from "./chunk-CDTLMEB3.js";
34
+ } from "./chunk-RNQ5BLR2.js";
30
35
  import {
31
36
  NOLO_PROJECT_MANAGER_AGENT_KEY,
32
37
  isLocalCliAgentKey
33
38
  } from "./chunk-VHBWHNVT.js";
34
39
  import {
35
40
  applyModelLayerOverride,
36
- buildMemoryOverlayLayer,
37
- buildMemoryUseGuidanceLayer,
38
- buildModelLayerOverride,
39
- buildSkillDiscoveryLayer
40
- } from "./chunk-SL35K7AH.js";
41
- import {
42
- CliProviderQuotaError
43
- } from "./chunk-X7W4TNB4.js";
41
+ buildModelLayerOverride
42
+ } from "./chunk-LTRXGFMS.js";
44
43
  import {
45
- resolveMachineId
46
- } from "./chunk-6HYVJV7B.js";
44
+ formatAgentListCard,
45
+ formatListRunsCard,
46
+ formatNotFoundRunCard,
47
+ formatStartRunCard,
48
+ formatStatusRunCard,
49
+ formatStopRunCard,
50
+ isAgentRunTerminalStatus
51
+ } from "./chunk-RZ735TLX.js";
47
52
  import {
48
53
  isGatewayHttpStatus
49
- } from "./chunk-GAKEBQD6.js";
54
+ } from "./chunk-YDCZVUFP.js";
50
55
  import {
51
56
  buildMemorySubjectsForAgent,
52
57
  resolveAgentMemoryPolicy
53
- } from "./chunk-HJGEVL7C.js";
58
+ } from "./chunk-G3B356GF.js";
54
59
  import {
55
- load,
56
60
  parseExternalSkillMarkdown,
57
61
  parseSkillDocProtocol
58
- } from "./chunk-ZQ2UM4KG.js";
62
+ } from "./chunk-VC6OZXO5.js";
59
63
  import {
60
- touchMemoryItemsInDb
61
- } from "./chunk-HNW7IJSK.js";
62
- import {
63
- chooseMemoryOwners,
64
- loadMemoryCandidatesFromDb
65
- } from "./chunk-XENYHRUE.js";
66
- import {
67
- getModelContextWindow,
64
+ API_REPORTED_COST_MULTIPLIER,
65
+ normalizeUsage,
68
66
  parseUiAskChoiceContent
69
- } from "./chunk-PIVFPOW6.js";
70
- import {
71
- readPipeText,
72
- spawnProcess
73
- } from "./chunk-IDZTNRP2.js";
67
+ } from "./chunk-AM53Q2SD.js";
74
68
  import {
75
- resolveAuthToken
76
- } from "./chunk-ISNCLGUZ.js";
69
+ buildSkillDiscoveryContextBlock
70
+ } from "./chunk-3QKO4EHV.js";
77
71
  import {
78
72
  buildPlatformChatCompletionRequest,
79
73
  parsePlatformChatCompletionData
80
- } from "./chunk-5KLGBAAR.js";
74
+ } from "./chunk-ZR4VHQ5D.js";
81
75
  import {
82
76
  resolveAgentRuntimeConfigFromRecord
83
- } from "./chunk-TILFE6LV.js";
77
+ } from "./chunk-NCGFB7NN.js";
84
78
  import {
85
79
  LOCAL_AGENT_CONFIG_MISSING_CODE,
86
80
  LOCAL_TURN_ABORTED_CODE,
87
81
  readActionGate,
88
82
  readCommandActionGatePayload
89
- } from "./chunk-6SLCD4RB.js";
83
+ } from "./chunk-4BTHUYMY.js";
90
84
  import {
91
85
  resolvePlatformChatCompletionsEndpoint
92
- } from "./chunk-JRKKFRAV.js";
86
+ } from "./chunk-TSKWE74T.js";
93
87
  import {
94
- clipCompactText
95
- } from "./chunk-5MMAK75Q.js";
88
+ DEFAULT_CONTEXT_WINDOW,
89
+ clipCompactText,
90
+ getModelContextWindow
91
+ } from "./chunk-S73OEOHH.js";
96
92
  import {
97
93
  findModelConfig
98
- } from "./chunk-BBYVOSU2.js";
94
+ } from "./chunk-S3UTETIC.js";
99
95
  import {
100
- compactWhitespace
101
- } from "./chunk-DWLEOOGR.js";
96
+ buildMemoryOverlayLayer,
97
+ buildMemoryUseGuidanceLayer
98
+ } from "./chunk-QLUFR47U.js";
99
+ import {
100
+ createRunActivityTracker,
101
+ finalizeRunRecord,
102
+ spawnLocalBackgroundRun
103
+ } from "./chunk-4ON5AV72.js";
102
104
  import {
103
105
  toErrorMessage
104
106
  } from "./chunk-HNMXYYJR.js";
105
107
  import {
106
108
  getDefaultCliLocalRuntimeDb
107
109
  } from "./chunk-H33743XH.js";
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";
108
124
  import {
109
125
  parsePositiveFiniteNumberOrFallback
110
126
  } from "./chunk-Y5GCAMGP.js";
@@ -112,22 +128,252 @@ import {
112
128
  asTrimmedLowercaseString
113
129
  } from "./chunk-QSJ3HFEF.js";
114
130
  import {
131
+ BUILTIN_NOLO_AGENT_KEY,
115
132
  PUBLIC_DEEPSEEK_V4_FLASH_AGENT_KEY,
116
- PUBLIC_DEEPSEEK_V4_PRO_AGENT_KEY,
117
- PUBLIC_GLM_52_AGENT_KEY,
118
133
  PUBLIC_KIMI_K26_IMAGE_AGENT_KEY
119
- } from "./chunk-DSZUWUYB.js";
120
- import {
121
- isLoopbackUrl
122
- } from "./chunk-4SN6J65J.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";
141
+ import {
142
+ isLoopbackUrl
143
+ } from "./chunk-4SN6J65J.js";
126
144
  import {
127
145
  asOptionalTrimmedString
128
146
  } from "./chunk-G3SUCT4W.js";
129
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
+
130
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
+ }
131
377
  var PROVIDER_LOOKUP_ORDER = [
132
378
  "openrouter",
133
379
  "fireworks",
@@ -147,7 +393,15 @@ function parseUsageRecord(usage) {
147
393
  const output = Number(usage.output_tokens ?? usage.completion_tokens ?? 0);
148
394
  if (!Number.isFinite(input) || !Number.isFinite(output)) return void 0;
149
395
  if (!input && !output) return void 0;
150
- 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
+ };
151
405
  }
152
406
  function resolveContextWindow(model) {
153
407
  const raw = model?.trim();
@@ -163,10 +417,13 @@ function buildTurnTokenUsage(usage, model) {
163
417
  if (!parsed) return void 0;
164
418
  const contextWindow = resolveContextWindow(model);
165
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;
166
422
  return {
167
423
  ...parsed,
168
424
  ...contextWindow ? { contextWindow } : {},
169
- ...remaining != null ? { remaining } : {}
425
+ ...remaining != null ? { remaining } : {},
426
+ ...credits !== void 0 ? { credits } : {}
170
427
  };
171
428
  }
172
429
  function formatTokenCount(value) {
@@ -183,7 +440,8 @@ function formatTokenCount(value) {
183
440
  function renderTokenStatus(tokens) {
184
441
  if (!tokens) return "in \u2014 out \u2014 left \u2014";
185
442
  const left = tokens.remaining != null ? formatTokenCount(tokens.remaining) : tokens.contextWindow ? "\u2014" : "\u2014";
186
- 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}`;
187
445
  }
188
446
  function shouldShowUsage(env) {
189
447
  return env.NOLO_DEBUG === "1" || env.NOLO_SHOW_USAGE === "1";
@@ -235,8 +493,277 @@ function styleCliText(text, style, enabled = resolveCliColorEnabled()) {
235
493
  if (!code) return text;
236
494
  return `${code}${text}${RESET}`;
237
495
  }
238
- function dimCliText(text, enabled = resolveCliColorEnabled()) {
239
- return styleCliText(text, "dim", enabled);
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 : [""];
751
+ }
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;
240
767
  }
241
768
 
242
769
  // packages/cli/tui/theme.ts
@@ -399,8 +926,24 @@ function getActiveDensity() {
399
926
  function setActiveDensity(density) {
400
927
  activeDensity = density;
401
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
+ ]);
402
939
  function supportsTruecolor(env = process.env) {
403
- 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);
404
947
  }
405
948
  function resolveTuiBrightness(env = process.env) {
406
949
  const explicit = (env.NOLO_TUI_THEME ?? "").trim().toLowerCase();
@@ -434,6 +977,17 @@ var TERMINAL_BASE = {
434
977
  dark: "1E1E2E",
435
978
  light: "FFFFFF"
436
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
+ }
437
991
  function readHexChannels(hex) {
438
992
  if (!/^[0-9A-F]{6}$/.test(hex)) return null;
439
993
  return [
@@ -471,21 +1025,49 @@ function diffLineSequences(env = process.env, brightness = resolveTuiBrightness(
471
1025
  const palette = THEME_PALETTES[activeThemeName] ?? THEME_PALETTES.trail;
472
1026
  const successHex = palette[brightness].success.hex;
473
1027
  const dangerHex = palette[brightness].danger.hex;
474
- const weight = brightness === "dark" ? 0.14 : 0.1;
475
- 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);
476
1031
  const addedBgHex = blendHex(successHex, baseHex, weight);
477
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);
478
1037
  return {
479
1038
  added: {
480
- fg: hexToSgr(successHex),
481
- bg: hexToBgSgr(addedBgHex)
1039
+ fg: successSgr,
1040
+ bg: hexToBgSgr(addedBgHex),
1041
+ bar: `${successSgr}\u258C\x1B[39m`
482
1042
  },
483
1043
  removed: {
484
- fg: hexToSgr(dangerHex),
485
- bg: hexToBgSgr(removedBgHex)
486
- }
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: " " }
487
1054
  };
488
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
+ }
489
1071
  function surfaceBackgroundSequence(env = process.env, brightness = resolveTuiBrightness(env)) {
490
1072
  if (!supportsTruecolor(env)) return "";
491
1073
  return hexToBgSgr((SURFACE_HEX[activeThemeName] ?? SURFACE_HEX.trail)[brightness]);
@@ -499,69 +1081,11 @@ function themeText(text, token, colorEnabled = resolveCliColorEnabled(), env = p
499
1081
  if (!colorEnabled) return text;
500
1082
  return `${themeColorSequence(token, env)}${text}\x1B[39m`;
501
1083
  }
502
- function renderDiffCodeBlock(code, env = process.env) {
503
- const border = themeText("\u2502", "chrome", true, env);
504
- const addedColor = themeColorSequence("success", env);
505
- const deletedColor = themeColorSequence("danger", env);
506
- const hunkColor = themeColorSequence("info", env);
507
- const contextColor = themeColorSequence("chrome", env);
508
- const reset = "\x1B[0m";
509
- const lines = code.split("\n").map((line) => {
510
- let color = contextColor;
511
- if (line.startsWith("@@")) {
512
- color = hunkColor;
513
- } else if (line.startsWith("+") && !line.startsWith("+++")) {
514
- color = addedColor;
515
- } else if (line.startsWith("-") && !line.startsWith("---")) {
516
- color = deletedColor;
517
- }
518
- return ` ${border} ${color}${line}${reset}`;
519
- });
520
- return ` ${themeText("\u250C\u2500\u2500\u2500", "chrome", true, env)}
521
- ${lines.join("\n")}
522
- ${themeText("\u2514\u2500\u2500\u2500", "chrome", true, env)}`;
523
- }
524
- function highlightMarkdown(text, colorEnabled = resolveCliColorEnabled(), env = process.env) {
525
- if (!colorEnabled) return text;
526
- let result = text;
527
- result = result.replace(/```([a-zA-Z-]*)\n([\s\S]*?)\n```/g, (match, lang, code) => {
528
- if (lang.toLowerCase() === "diff") {
529
- return renderDiffCodeBlock(code, env);
530
- }
531
- const infoColor = themeColorSequence("info", env);
532
- const reset2 = "\x1B[39m\x1B[22m";
533
- const border = themeText("\u2502", "chrome", true, env);
534
- const formattedCode = code.split("\n").map((line) => ` ${border} ${infoColor}${line}${reset2}`).join("\n");
535
- return ` ${themeText("\u250C\u2500\u2500\u2500", "chrome", true, env)}
536
- ${formattedCode}
537
- ${themeText("\u2514\u2500\u2500\u2500", "chrome", true, env)}`;
538
- });
539
- result = result.replace(/^(#{1,3})\s+(.+)$/gm, (match, hashes, title) => {
540
- const level = hashes.length;
541
- const reset2 = "\x1B[0m";
542
- if (level === 1) {
543
- return `\x1B[1m\x1B[4m${themeColorSequence("accent", env)}${title}${reset2}`;
544
- }
545
- if (level === 2) {
546
- return `\x1B[1m${themeColorSequence("warning", env)}${title}${reset2}`;
547
- }
548
- return `\x1B[1m${themeColorSequence("info", env)}${title}${reset2}`;
549
- });
550
- result = result.replace(
551
- /^(进入 nolo-plan[^\n]*)$/gm,
552
- (match, content) => `${themeColorSequence("chrome", env)}\x1B[2m${content}\x1B[0m`
553
- );
554
- result = result.replace(/^>\s?(.*)$/gm, (match, content) => {
555
- const border = themeColorSequence("chrome", env);
556
- return `${border}\u2502\x1B[39m \x1B[2m${content}\x1B[22m`;
557
- });
558
- result = result.replace(/\*\*([\s\S]*?)\*\*/g, "\x1B[1m$1\x1B[22m");
559
- const mutedColor = themeColorSequence("muted", env);
560
- const reset = "\x1B[39m";
561
- result = result.replace(/`([^`\n]+)`/g, `${mutedColor}$1${reset}`);
562
- result = result.replace(/(?<!\*)\*([^*\n]+?)\*(?!\*)/g, `\x1B[2m$1\x1B[22m`);
563
- result = result.replace(/~~([^~\n]+?)~~/g, `\x1B[2m\x1B[9m$1\x1B[29m\x1B[22m`);
564
- 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";
565
1089
  }
566
1090
 
567
1091
  // packages/cli/client/assistantOutput.ts
@@ -740,20 +1264,7 @@ function highlightCodeLine(line, lang, brightness) {
740
1264
  return `${info}${line}${STYLE.reset}`;
741
1265
  }
742
1266
  if (lang === "diff") {
743
- const added = colorSeq("success", brightness);
744
- const deleted = colorSeq("danger", brightness);
745
- const hunk = colorSeq("info", brightness);
746
- const context = colorSeq("chrome", brightness);
747
- const reset2 = STYLE.reset;
748
- let color = context;
749
- if (line.startsWith("@@")) {
750
- color = hunk;
751
- } else if (line.startsWith("+") && !line.startsWith("+++")) {
752
- color = added;
753
- } else if (line.startsWith("-") && !line.startsWith("---")) {
754
- color = deleted;
755
- }
756
- return `${color}${line}${reset2}`;
1267
+ return renderDiffLine({ kind: classifyDiffLine(line), text: line, colorEnabled: true });
757
1268
  }
758
1269
  const regions = scanStringCommentRegions(line, lang);
759
1270
  const keywords = KEYWORDS[lang];
@@ -950,7 +1461,7 @@ function styleRichMarkdownLine(line, brightness) {
950
1461
  const ordered = line.match(/^(\s*)(\d+\.)\s(.+)$/);
951
1462
  if (ordered) {
952
1463
  const styled = styleInlineMarkdown(ordered[3], brightness);
953
- return `${ordered[1]}${colorSeq("accent", brightness)}${ordered[2]}${STYLE.reset} ${styled}`;
1464
+ return `${ordered[1]}${colorSeq("chrome", brightness)}${ordered[2]}${STYLE.reset} ${styled}`;
954
1465
  }
955
1466
  const task = line.match(/^(\s*)(☐|☑)\s(.+)$/);
956
1467
  if (task) {
@@ -1351,454 +1862,254 @@ function formatFetchTreeLines(items) {
1351
1862
  return { header, count, lines };
1352
1863
  }
1353
1864
 
1354
- // packages/cli/tui/i18n.ts
1355
- var ZH_PATTERNS = /^zh/i;
1356
- function parseCliLocale(raw) {
1357
- const normalized = raw?.trim().toLowerCase();
1358
- if (!normalized) return null;
1359
- if (ZH_PATTERNS.test(normalized)) return "zh";
1360
- if (normalized === "en" || normalized.startsWith("en")) return "en";
1361
- return null;
1362
- }
1363
- function detectLocaleFromEnv(env) {
1364
- const explicit = parseCliLocale(env.NOLO_LANG);
1365
- if (explicit) return explicit;
1366
- const candidates = [env.LC_ALL, env.LC_CTYPE, env.LANG].filter(Boolean);
1367
- for (const candidate of candidates) {
1368
- if (ZH_PATTERNS.test(candidate)) return "zh";
1369
- if (candidate && !candidate.startsWith("C.") && !candidate.startsWith("POSIX")) {
1370
- 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
+ }
1371
1963
  }
1372
1964
  }
1373
- return null;
1374
- }
1375
- function detectLocale(env) {
1376
- return detectLocaleFromEnv(env) ?? "zh";
1377
- }
1378
- var currentLocale = detectLocale(process.env);
1379
- function getCliLocale() {
1380
- return currentLocale;
1381
- }
1382
- function setCliLocale(locale) {
1383
- currentLocale = locale;
1384
- }
1385
- function initCliLocale(env = process.env) {
1386
- currentLocale = detectLocale(env);
1387
- }
1388
- var STRINGS = {
1389
- welcomeHint: {
1390
- en: "Tell nolo what you want. Use /help for commands. Shift+Enter for newline.",
1391
- zh: "\u544A\u8BC9 nolo \u4F60\u60F3\u8981\u4EC0\u4E48\u3002\u8F93\u5165 /help \u67E5\u770B\u547D\u4EE4\u3002Shift+Enter \u6362\u884C\u3002"
1392
- },
1393
- promptLabel: {
1394
- en: "\u276F ",
1395
- zh: "\u276F "
1396
- },
1397
- continueLabel: {
1398
- en: "\u2502 ",
1399
- zh: "\u2502 "
1400
- },
1401
- placeholder: {
1402
- en: "Type a message or / for commands...",
1403
- zh: "\u8F93\u5165\u6D88\u606F\uFF0C\u6216\u7528 / \u67E5\u770B\u547D\u4EE4\u2026"
1404
- },
1405
- newDialog: {
1406
- en: "new dialog",
1407
- zh: "\u65B0\u5BF9\u8BDD"
1408
- },
1409
- startedFreshDialog: {
1410
- en: "Started a fresh dialog.",
1411
- zh: "\u5DF2\u5F00\u59CB\u65B0\u5BF9\u8BDD\u3002"
1412
- },
1413
- bye: {
1414
- en: "Bye.",
1415
- zh: "\u518D\u89C1\u3002"
1416
- },
1417
- resumedDialogPrefix: {
1418
- en: "Resumed dialog",
1419
- zh: "\u5DF2\u6062\u590D\u5BF9\u8BDD"
1420
- },
1421
- resumeInvalidId: {
1422
- en: "does not look like a dialog id. Use /history to pick one.",
1423
- zh: "\u770B\u8D77\u6765\u4E0D\u662F dialog id\u3002\u7528 /history \u4ECE\u5217\u8868\u91CC\u9009\u4E00\u4E2A\u3002"
1424
- },
1425
- dialogResumeCancelled: {
1426
- en: "Dialog resume cancelled.",
1427
- zh: "\u5DF2\u53D6\u6D88\u6062\u590D\u5BF9\u8BDD\u3002"
1428
- },
1429
- agentSwitchCancelled: {
1430
- en: "Agent switch cancelled.",
1431
- zh: "\u5DF2\u53D6\u6D88\u5207\u6362 agent\u3002"
1432
- },
1433
- historyPickerTitle: {
1434
- en: "Resume dialog (\u2191\u2193 Enter Esc)",
1435
- zh: "\u6062\u590D\u5BF9\u8BDD\uFF08\u2191\u2193 \u79FB\u52A8 \xB7 Enter \u9009\u62E9 \xB7 Esc \u53D6\u6D88\uFF09"
1436
- },
1437
- noDialogsYet: {
1438
- en: "No dialogs yet.",
1439
- zh: "\u8FD8\u6CA1\u6709\u5386\u53F2\u5BF9\u8BDD\u3002"
1440
- },
1441
- langUsage: {
1442
- en: "Usage: /lang <zh|en>",
1443
- zh: "\u7528\u6CD5\uFF1A/lang <zh|en>"
1444
- },
1445
- stopHint: {
1446
- en: "Esc to stop",
1447
- zh: "Esc \u505C\u6B62\u56DE\u590D"
1448
- },
1449
- queuedHint: {
1450
- en: "queued",
1451
- zh: "\u6392\u961F"
1452
- },
1453
- turnStopped: {
1454
- en: "Stopped this reply.",
1455
- zh: "\u5DF2\u505C\u6B62\u672C\u6B21\u56DE\u590D\u3002"
1456
- },
1457
- turnFailed: {
1458
- en: "This reply failed. Queued messages are kept \u2014 press Enter to resend.",
1459
- 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"
1460
- },
1461
- quotaExhaustedHint: {
1462
- 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.",
1463
- 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"
1464
- },
1465
- balanceExhaustedHint: {
1466
- en: '[nolo] Insufficient balance. Your message is saved in this dialog \u2014 top up, then send again or say "continue".',
1467
- 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"
1468
- },
1469
- dialogPreservedHint: {
1470
- en: '[nolo] This turn failed, but the dialog is kept. Send another message (or say "continue") to keep going in the same conversation.',
1471
- 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"
1472
- },
1473
- dialogNotSavedHint: {
1474
- en: "[nolo] This turn did not create a dialog. Your next message will start a new conversation \u2014 restate what you need.",
1475
- 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"
1476
- },
1477
- copiedLastReply: {
1478
- en: "Copied the last reply to the clipboard.",
1479
- zh: "\u5DF2\u590D\u5236\u6700\u540E\u4E00\u6761\u56DE\u590D\u5230\u526A\u8D34\u677F\u3002"
1480
- },
1481
- copyNothing: {
1482
- en: "Nothing to copy yet.",
1483
- zh: "\u8FD8\u6CA1\u6709\u53EF\u590D\u5236\u7684\u5185\u5BB9\u3002"
1484
- },
1485
- copyFailed: {
1486
- en: "Copy failed",
1487
- zh: "\u590D\u5236\u5931\u8D25"
1488
- },
1489
- copyUnavailable: {
1490
- en: "Clipboard is unavailable in this environment. The last reply was printed above for manual copy.",
1491
- 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"
1492
- },
1493
- copyUsage: {
1494
- en: "Usage: /copy or /copy view",
1495
- zh: "\u7528\u6CD5\uFF1A/copy \u6216 /copy view"
1496
- },
1497
- copyViewTitle: {
1498
- en: "Copy view \u2014 latest AI reply",
1499
- zh: "\u590D\u5236\u89C6\u56FE \u2014 \u6700\u65B0 AI \u56DE\u590D"
1500
- },
1501
- copyViewHint: {
1502
- en: "Drag to select; edge scrolling uses native terminal scrollback. Press Esc or Enter to return.",
1503
- 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"
1504
- },
1505
- historyNoToken: {
1506
- en: "History requires an auth token. Run `nolo login` or set AUTH_TOKEN.",
1507
- 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"
1508
- },
1509
- historyBadToken: {
1510
- en: "Could not read a user id from AUTH_TOKEN. Run `nolo login` again.",
1511
- zh: "\u65E0\u6CD5\u4ECE AUTH_TOKEN \u89E3\u6790\u51FA\u7528\u6237 id\uFF0C\u8BF7\u91CD\u65B0\u8FD0\u884C `nolo login`\u3002"
1512
- },
1513
- mouseOn: {
1514
- en: "Mouse mode on: wheel scrolls the transcript; hold Shift (or Option/Fn) to select text.",
1515
- 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"
1516
- },
1517
- mouseOff: {
1518
- en: "Mouse mode off: drag to select/copy freely; scroll with PageUp/PageDown.",
1519
- 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"
1520
- },
1521
- mouseUsage: {
1522
- en: "Usage: /mouse <on|off>",
1523
- zh: "\u7528\u6CD5\uFF1A/mouse <on|off>"
1524
- },
1525
- langSwitched: {
1526
- en: "Language switched to English.",
1527
- zh: "\u5DF2\u5207\u6362\u4E3A\u4E2D\u6587\u3002"
1528
- },
1529
- // --- Tool trace copy ------------------------------------------------------
1530
- // The compact trace shows only status, never timing or output size: a line
1531
- // count told the user nothing actionable and the ms figure read as noise.
1532
- toolNeedsAction: {
1533
- en: "needs action",
1534
- zh: "\u5F85\u786E\u8BA4"
1535
- },
1536
- toolTimedOut: {
1537
- en: "timed out",
1538
- zh: "\u5DF2\u8D85\u65F6"
1539
- },
1540
- toolExitCode: {
1541
- en: "exit",
1542
- zh: "\u9000\u51FA\u7801"
1543
- },
1544
- toolFailed: {
1545
- en: "failed",
1546
- zh: "\u5931\u8D25"
1547
- },
1548
- // --- Dialog (picker / confirm) copy --------------------------------------
1549
- // Key-hint wording is unified across select / multi-select / confirm so the
1550
- // three dialogs read as one family: "<Label> <↑↓ move · Enter choose ·
1551
- // Esc cancel> <count>". Connectors are "·" between keys, two spaces between
1552
- // the label, hint, and count. zh uses full-width parentheses to match the
1553
- // existing historyPickerTitle; en uses ASCII parentheses.
1554
- dialogSelectLabel: {
1555
- en: "Select",
1556
- zh: "\u9009\u62E9"
1557
- },
1558
- dialogSelectHint: {
1559
- en: "(\u2191\u2193 move \xB7 Enter choose \xB7 Esc cancel)",
1560
- zh: "\uFF08\u2191\u2193 \u79FB\u52A8 \xB7 Enter \u9009\u62E9 \xB7 Esc \u53D6\u6D88\uFF09"
1561
- },
1562
- dialogMultiSelectLabel: {
1563
- en: "Select",
1564
- zh: "\u9009\u62E9"
1565
- },
1566
- dialogMultiSelectHint: {
1567
- en: "(\u2191\u2193 move \xB7 Space toggle \xB7 Enter submit \xB7 Esc cancel)",
1568
- zh: "\uFF08\u2191\u2193 \u79FB\u52A8 \xB7 Space \u5207\u6362 \xB7 Enter \u63D0\u4EA4 \xB7 Esc \u53D6\u6D88\uFF09"
1569
- },
1570
- dialogMultiSelectSelected: {
1571
- en: "selected",
1572
- zh: "\u5DF2\u9009"
1573
- },
1574
- dialogConfirmHint: {
1575
- en: "(\u2191\u2193 move \xB7 Enter choose \xB7 Esc cancel)",
1576
- zh: "\uFF08\u2191\u2193 \u79FB\u52A8 \xB7 Enter \u9009\u62E9 \xB7 Esc \u53D6\u6D88\uFF09"
1577
- },
1578
- dialogConfirmTitle: {
1579
- en: "Confirm destructive shell command",
1580
- zh: "\u786E\u8BA4\u6267\u884C\u7834\u574F\u6027 shell \u547D\u4EE4"
1581
- },
1582
- dialogConfirmBody: {
1583
- en: "This command may delete or reset user content and needs explicit confirmation before it runs.",
1584
- 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"
1585
- },
1586
- dialogConfirmCommandLabel: {
1587
- en: "Command",
1588
- zh: "\u547D\u4EE4"
1589
- },
1590
- dialogConfirmCommandTruncated: {
1591
- en: "(truncated)",
1592
- zh: "\uFF08\u5DF2\u622A\u65AD\uFF09"
1593
- },
1594
- dialogConfirmAllowLabel: {
1595
- en: "Allow",
1596
- zh: "\u5141\u8BB8"
1597
- },
1598
- dialogConfirmAllowDetail: {
1599
- en: "execute this time",
1600
- zh: "\u672C\u6B21\u6267\u884C"
1601
- },
1602
- dialogConfirmCancelLabel: {
1603
- en: "Cancel",
1604
- zh: "\u53D6\u6D88"
1605
- },
1606
- dialogConfirmCancelDetail: {
1607
- en: "abort the operation",
1608
- zh: "\u4E2D\u6B62\u64CD\u4F5C"
1609
- },
1610
- contextTitle: {
1611
- en: "Workspace context",
1612
- zh: "\u5DE5\u4F5C\u533A\u4E0A\u4E0B\u6587"
1613
- },
1614
- contextNext: {
1615
- en: "Next:",
1616
- zh: "\u4E0B\u4E00\u6B65\uFF1A"
1617
- },
1618
- contextFieldAgent: {
1619
- en: "agent",
1620
- zh: "\u667A\u80FD\u4F53"
1621
- },
1622
- contextFieldTokens: {
1623
- en: "tokens",
1624
- zh: "\u4EE4\u724C"
1625
- },
1626
- contextFieldDialog: {
1627
- en: "dialog",
1628
- zh: "\u5BF9\u8BDD"
1629
- },
1630
- contextFieldDocs: {
1631
- en: "docs",
1632
- zh: "\u6587\u6863"
1633
- },
1634
- contextFieldSkills: {
1635
- en: "skills",
1636
- zh: "\u6280\u80FD"
1637
- },
1638
- contextFieldProfile: {
1639
- en: "profile",
1640
- zh: "\u914D\u7F6E"
1641
- },
1642
- contextFieldRuntime: {
1643
- en: "runtime",
1644
- zh: "\u8FD0\u884C\u65F6"
1645
- },
1646
- contextFieldTools: {
1647
- en: "tools",
1648
- zh: "\u5DE5\u5177"
1649
- },
1650
- contextFieldThinking: {
1651
- en: "thinking",
1652
- zh: "\u601D\u8003"
1653
- },
1654
- contextFieldServer: {
1655
- en: "server",
1656
- zh: "\u670D\u52A1\u7AEF"
1657
- },
1658
- contextNextAgents: {
1659
- en: "see specialist shortcuts",
1660
- zh: "\u67E5\u770B\u4E13\u7528\u667A\u80FD\u4F53\u5FEB\u6377\u65B9\u5F0F"
1661
- },
1662
- contextNextDoc: {
1663
- en: "add working context",
1664
- zh: "\u6DFB\u52A0\u5DE5\u4F5C\u4E0A\u4E0B\u6587"
1665
- },
1666
- contextNextSkill: {
1667
- en: "attach a skill to this workspace",
1668
- zh: "\u4E3A\u8BE5\u5DE5\u4F5C\u533A\u6302\u8F7D\u6280\u80FD"
1669
- },
1670
- contextNextNew: {
1671
- en: "start a clean dialog",
1672
- zh: "\u5F00\u59CB\u4E00\u4E2A\u5E72\u51C0\u7684\u5BF9\u8BDD"
1673
- },
1674
- agentsTitle: {
1675
- en: "Agents:",
1676
- zh: "\u667A\u80FD\u4F53\uFF1A"
1677
- },
1678
- agentsTip: {
1679
- en: "Tip: run /switch for the full picker, or /switch list for your private agents too.",
1680
- 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"
1681
- },
1682
- helpText: {
1683
- en: [
1684
- "Commands:",
1685
- " /help Show this help",
1686
- " /new Clear screen and start a fresh dialog",
1687
- " /compact Compact current dialog and fork a new one",
1688
- " /context Show workspace context and next actions",
1689
- " /runtime <mode> Use auto, local, or server runtime",
1690
- " /tools <mode> Control tool trace: hide, compact, verbose",
1691
- " /thinking <mode> Control thinking output: hide, marker, show",
1692
- " /switch Pick an agent interactively (\u2191\u2193, Enter)",
1693
- " /switch list List agents as text",
1694
- " /switch <name> Switch directly by name, alias, or key (alias: /agent)",
1695
- " /agents List platform agent shortcuts",
1696
- " /history Pick a recent dialog to resume (\u2191\u2193, Enter)",
1697
- " /resume <dialogId> Resume a dialog directly by id",
1698
- " /lang <zh|en> Switch interface language",
1699
- " /copy Copy the last reply to the clipboard",
1700
- " /copy view Open native scrollback for partial selection (Ctrl+O)",
1701
- " /mouse <on|off> Toggle mouse mode (off = drag to select text)",
1702
- " /doc List attached docs",
1703
- " /doc attach <doc> Attach a doc to this workspace",
1704
- " /skill List attached skills",
1705
- " /skill attach <ref> Attach a skill (dbKey, name, or SKILL.md path)",
1706
- " /skill detach <ref> Detach a skill",
1707
- " /skill clear Detach all skills",
1708
- " /customize Describe how you want to tune nolo",
1709
- " /tasks List background process tasks (aliases: /jobs, /procs)",
1710
- " /stop <pid|all> Stop background process tasks",
1711
- " /login Show login/profile hint",
1712
- " /profile Show active profile",
1713
- " /update Update the nolo CLI install",
1714
- " /version Show version/update hint",
1715
- " /exit Leave the workspace",
1716
- "",
1717
- "You can also type normally. nolo routes simple read/status requests to CLI commands and sends the rest to the current agent."
1718
- ].join("\n"),
1719
- zh: [
1720
- "\u547D\u4EE4\uFF1A",
1721
- " /help \u663E\u793A\u672C\u5E2E\u52A9",
1722
- " /new \u6E05\u5C4F\u5E76\u5F00\u59CB\u65B0\u5BF9\u8BDD",
1723
- " /compact \u538B\u7F29\u5F53\u524D\u5BF9\u8BDD\u5E76\u5206\u53C9\u51FA\u65B0\u5BF9\u8BDD",
1724
- " /context \u67E5\u770B\u5DE5\u4F5C\u533A\u4E0A\u4E0B\u6587\u4E0E\u540E\u7EED\u64CD\u4F5C",
1725
- " /runtime <mode> \u5207\u6362 runtime\uFF1Aauto\u3001local\u3001server",
1726
- " /tools <mode> \u5DE5\u5177\u8F68\u8FF9\u663E\u793A\uFF1Ahide\u3001compact\u3001verbose",
1727
- " /thinking <mode> \u601D\u8003\u8FC7\u7A0B\u663E\u793A\uFF1Ahide\u3001marker\u3001show",
1728
- " /switch \u4EA4\u4E92\u5F0F\u9009\u62E9 agent\uFF08\u2191\u2193 \u79FB\u52A8\uFF0CEnter \u786E\u8BA4\uFF09",
1729
- " /switch list \u4EE5\u6587\u672C\u5217\u51FA\u5168\u90E8 agent",
1730
- " /switch <name> \u6309\u540D\u79F0\u3001\u522B\u540D\u6216 key \u76F4\u63A5\u5207\u6362\uFF08\u522B\u540D\uFF1A/agent\uFF09",
1731
- " /agents \u5217\u51FA\u5E73\u53F0 agent \u5FEB\u6377\u65B9\u5F0F",
1732
- " /history \u4ECE\u6700\u8FD1\u5BF9\u8BDD\u4E2D\u9009\u62E9\u5E76\u6062\u590D\uFF08\u2191\u2193\uFF0CEnter\uFF09",
1733
- " /resume <dialogId> \u6309 id \u76F4\u63A5\u6062\u590D\u5BF9\u8BDD",
1734
- " /lang <zh|en> \u5207\u6362\u754C\u9762\u8BED\u8A00",
1735
- " /copy \u590D\u5236\u6700\u540E\u4E00\u6761\u56DE\u590D\u5230\u526A\u8D34\u677F",
1736
- " /copy view \u6253\u5F00\u539F\u751F\u56DE\u6EDA\u8FDB\u884C\u8DE8\u5C4F\u62D6\u9009\uFF08Ctrl+O\uFF09",
1737
- " /mouse <on|off> \u5207\u6362\u9F20\u6807\u6A21\u5F0F\uFF08off \u540E\u53EF\u76F4\u63A5\u62D6\u9009\u6587\u672C\uFF09",
1738
- " /doc \u5217\u51FA\u5DF2\u6302\u8F7D\u7684\u6587\u6863",
1739
- " /doc attach <doc> \u6302\u8F7D\u6587\u6863\u5230\u5F53\u524D\u5DE5\u4F5C\u533A",
1740
- " /skill \u5217\u51FA\u5DF2\u6302\u8F7D\u7684\u6280\u80FD",
1741
- " /skill attach <ref> \u6302\u8F7D\u6280\u80FD\uFF08dbKey\u3001\u540D\u79F0\u6216 SKILL.md \u8DEF\u5F84\uFF09",
1742
- " /skill detach <ref> \u5378\u8F7D\u6307\u5B9A\u6280\u80FD",
1743
- " /skill clear \u5378\u8F7D\u5168\u90E8\u6280\u80FD",
1744
- " /customize \u63CF\u8FF0\u4F60\u60F3\u600E\u4E48\u8C03\u6559 nolo",
1745
- " /tasks \u5217\u51FA\u540E\u53F0\u5B50\u8FDB\u7A0B\u4EFB\u52A1\uFF08\u522B\u540D\uFF1A/jobs, /procs\uFF09",
1746
- " /stop <pid|all> \u505C\u6B62\u6307\u5B9A\u7684\u540E\u53F0\u4EFB\u52A1",
1747
- " /login \u67E5\u770B\u767B\u5F55 / \u914D\u7F6E\u63D0\u793A",
1748
- " /profile \u67E5\u770B\u5F53\u524D\u914D\u7F6E\u73AF\u5883",
1749
- " /update \u66F4\u65B0 nolo CLI",
1750
- " /version \u67E5\u770B\u7248\u672C\u4E0E\u66F4\u65B0\u63D0\u793A",
1751
- " /exit \u9000\u51FA\u5DE5\u4F5C\u533A",
1752
- "",
1753
- "\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"
1754
- ].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;
1755
2064
  }
1756
2065
  };
1757
- function t(key) {
1758
- return STRINGS[key][currentLocale];
1759
- }
1760
- var TOOL_LABELS = {
1761
- // Local workspace tools (packages/agent-runtime/localWorkspaceTools.ts)
1762
- readFile: { en: "Read", zh: "\u8BFB\u53D6" },
1763
- writeFile: { en: "Write", zh: "\u5199\u5165" },
1764
- editFile: { en: "Edit", zh: "\u7F16\u8F91" },
1765
- listFiles: { en: "List", zh: "\u5217\u51FA" },
1766
- searchFiles: { en: "Search", zh: "\u641C\u7D22" },
1767
- globFiles: { en: "Glob", zh: "\u5339\u914D" },
1768
- execShell: { en: "Run", zh: "\u6267\u884C" },
1769
- runCommand: { en: "Run", zh: "\u6267\u884C" },
1770
- captureVisualState: { en: "Capture", zh: "\u622A\u5C4F" },
1771
- // Workspace / diagnostics
1772
- searchWorkspace: { en: "Search workspace", zh: "\u641C\u7D22\u5DE5\u4F5C\u533A" },
1773
- cliDoctor: { en: "Doctor", zh: "\u81EA\u68C0" },
1774
- cliWhoami: { en: "Whoami", zh: "\u67E5\u770B\u8EAB\u4EFD" },
1775
- checkEnv: { en: "Check env", zh: "\u68C0\u67E5\u73AF\u5883" },
1776
- configure: { en: "Configure", zh: "\u914D\u7F6E" },
1777
- notifyUser: { en: "Notify", zh: "\u901A\u77E5" },
1778
- // Docs / dialogs / spaces
1779
- readDoc: { en: "Read doc", zh: "\u8BFB\u53D6\u6587\u6863" },
1780
- createDoc: { en: "Create doc", zh: "\u65B0\u5EFA\u6587\u6863" },
1781
- updateDoc: { en: "Update doc", zh: "\u66F4\u65B0\u6587\u6863" },
1782
- readDialog: { en: "Read dialog", zh: "\u8BFB\u53D6\u5BF9\u8BDD" },
1783
- listDialogs: { en: "List dialogs", zh: "\u5217\u51FA\u5BF9\u8BDD" },
1784
- queryDialogsBySubjectRef: { en: "Query dialogs", zh: "\u67E5\u8BE2\u5BF9\u8BDD" },
1785
- searchDialogMessages: { en: "Search messages", zh: "\u641C\u7D22\u6D88\u606F" },
1786
- listSpaces: { en: "List spaces", zh: "\u5217\u51FA\u7A7A\u95F4" },
1787
- readSpace: { en: "Read space", zh: "\u8BFB\u53D6\u7A7A\u95F4" },
1788
- // Tables
1789
- createTable: { en: "Create table", zh: "\u521B\u5EFA\u8868" },
1790
- queryTableRows: { en: "Query rows", zh: "\u67E5\u8BE2\u8868\u884C" },
1791
- addTableRow: { en: "Add row", zh: "\u65B0\u589E\u8868\u884C" },
1792
- addTableRows: { en: "Add rows", zh: "\u65B0\u589E\u8868\u884C" },
1793
- updateTableRow: { en: "Update row", zh: "\u66F4\u65B0\u8868\u884C" },
1794
- deleteTableRow: { en: "Delete row", zh: "\u5220\u9664\u8868\u884C" },
1795
- // Web
1796
- fetchWebpage: { en: "Fetch page", zh: "\u6293\u53D6\u7F51\u9875" },
1797
- readPage: { en: "Read page", zh: "\u8BFB\u53D6\u7F51\u9875" },
1798
- exaSearch: { en: "Web search", zh: "\u8054\u7F51\u641C\u7D22" }
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
+ }
1799
2091
  };
1800
- function toolLabel(name) {
1801
- 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;
1802
2113
  }
1803
2114
 
1804
2115
  // packages/cli/client/toolOutput.ts
@@ -1871,25 +2182,65 @@ function readReadFileRange(metadata) {
1871
2182
  if (!truncated && startLine === 1 && endLine === totalLines) return void 0;
1872
2183
  return `${startLine}-${endLine}/${totalLines}`;
1873
2184
  }
1874
- var EDIT_SNIPPET_MAX_LINES = 5;
2185
+ var EDIT_SNIPPET_MAX_LINES = 10;
1875
2186
  var EDIT_SNIPPET_MAX_WIDTH = 96;
1876
2187
  function formatEditFileSnippet(metadata) {
1877
2188
  const oldSnippet = typeof metadata.oldSnippet === "string" ? metadata.oldSnippet : void 0;
1878
2189
  const newSnippet = typeof metadata.newSnippet === "string" ? metadata.newSnippet : void 0;
1879
2190
  if (!oldSnippet && !newSnippet) return void 0;
1880
- const lines = [];
1881
- if (oldSnippet) {
1882
- for (const line of snippetLines(oldSnippet)) lines.push(`- ${line}`);
2191
+ if (oldSnippet && !newSnippet) {
2192
+ return snippetLinesWithKind(oldSnippet, "removed");
1883
2193
  }
1884
- if (newSnippet) {
1885
- for (const line of snippetLines(newSnippet)) lines.push(`+ ${line}`);
2194
+ if (newSnippet && !oldSnippet) {
2195
+ return snippetLinesWithKind(newSnippet, "added");
1886
2196
  }
1887
- 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" ? "- " : " ";
1888
2211
  }
1889
- 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) {
1890
2216
  const lines = snippet.split(/\r?\n/).filter((line) => line.length > 0);
1891
- const shown = lines.slice(0, EDIT_SNIPPET_MAX_LINES);
1892
- 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;
1893
2244
  }
1894
2245
  function isFailedToolResult(event) {
1895
2246
  const exitCode = event.metadata?.exitCode;
@@ -1900,6 +2251,22 @@ function isFailedToolResult(event) {
1900
2251
  function isNeedsActionToolResult(event) {
1901
2252
  return Boolean(event.metadata?.actionGate);
1902
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
+ }
1903
2270
  function parseUiAskChoiceForCli(event) {
1904
2271
  if (event.toolName !== "ui_ask_choice" && !event.metadata?.uiAskChoice) {
1905
2272
  return null;
@@ -1911,18 +2278,66 @@ function parseUiAskChoiceForCli(event) {
1911
2278
  label: String(c.label ?? "").trim(),
1912
2279
  userMessage: typeof c.userMessage === "string" ? c.userMessage : void 0
1913
2280
  })).filter((c) => c.label.length > 0);
1914
- if (!question || choices.length === 0) return null;
1915
- 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
+ };
1916
2300
  }
1917
2301
  function formatUiAskChoiceBlock(event, colorEnabled) {
1918
2302
  const parsed = parseUiAskChoiceForCli(event);
1919
2303
  if (!parsed) return null;
1920
2304
  const lines = [];
1921
2305
  lines.push("");
2306
+ const questionText = parsed.question || "";
1922
2307
  if (colorEnabled) {
1923
- lines.push(`${themeText("\u2753 ", "info", true)}${styleCliText(parsed.question, "cyan", true)}`);
2308
+ lines.push(`${themeText("\u2753 ", "info", true)}${styleCliText(questionText, "cyan", true)}`);
1924
2309
  } else {
1925
- 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
+ `;
1926
2341
  }
1927
2342
  parsed.choices.forEach((choice, i) => {
1928
2343
  const num = String(i + 1);
@@ -1935,7 +2350,7 @@ function formatUiAskChoiceBlock(event, colorEnabled) {
1935
2350
  lines.push(` ${num}. ${label}`);
1936
2351
  }
1937
2352
  });
1938
- const hint = "\u8BF7\u8F93\u5165\u5E8F\u53F7\u9009\u62E9\uFF0C\u6216\u76F4\u63A5\u56DE\u590D\uFF1A";
2353
+ const hint = t("askChoiceHistoryHint");
1939
2354
  if (colorEnabled) {
1940
2355
  lines.push(` ${dimCliText(hint, true)}`);
1941
2356
  } else {
@@ -1954,6 +2369,129 @@ function formatToolTraceLine(text, colorEnabled, accent = "none") {
1954
2369
  return `${dimCliText(text, true)}
1955
2370
  `;
1956
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
+ );
2494
+ }
1957
2495
  function formatVerboseToolEvent(event, colorEnabled) {
1958
2496
  const round = event.round + 1;
1959
2497
  const detail = event.argumentsPreview ? ` ${event.argumentsPreview}` : "";
@@ -2001,15 +2539,16 @@ function isRunResultFoldable(event) {
2001
2539
  function formatSearchTreeBlockForCli(items, colorEnabled) {
2002
2540
  if (items.length === 0) return "";
2003
2541
  const { count, lines } = formatSearchTreeLines(items);
2542
+ const titleText = toolLabel("searchFiles");
2004
2543
  if (!colorEnabled) {
2005
- const headerLine2 = `\u2022 Search (${count})
2544
+ const headerLine2 = `\u2022 ${titleText} (${count})
2006
2545
  `;
2007
2546
  const treeLines2 = lines.map((l) => ` ${l.connector}${l.queryText}`).join("\n");
2008
2547
  return `${headerLine2}${treeLines2}
2009
2548
  `;
2010
2549
  }
2011
2550
  const bullet = themeText("\u2022", "chrome", true);
2012
- const title = styleCliText("Search", "bold", true);
2551
+ const title = styleCliText(titleText, "bold", true);
2013
2552
  const countText = themeText(`(${count})`, "muted", true);
2014
2553
  const headerLine = `${bullet} ${title} ${countText}
2015
2554
  `;
@@ -2024,15 +2563,16 @@ function formatSearchTreeBlockForCli(items, colorEnabled) {
2024
2563
  function formatReadTreeBlockForCli(items, colorEnabled) {
2025
2564
  if (items.length === 0) return "";
2026
2565
  const { count, lines } = formatReadTreeLines(items);
2566
+ const titleText = toolLabel("readFile");
2027
2567
  if (!colorEnabled) {
2028
- const headerLine2 = `\u2022 Read (${count})
2568
+ const headerLine2 = `\u2022 ${titleText} (${count})
2029
2569
  `;
2030
2570
  const treeLines2 = lines.map((l) => ` ${l.connector}${l.pathWithRange}`).join("\n");
2031
2571
  return `${headerLine2}${treeLines2}
2032
2572
  `;
2033
2573
  }
2034
2574
  const bullet = themeText("\u2022", "chrome", true);
2035
- const title = styleCliText("Read", "bold", true);
2575
+ const title = styleCliText(titleText, "bold", true);
2036
2576
  const countText = themeText(`(${count})`, "muted", true);
2037
2577
  const headerLine = `${bullet} ${title} ${countText}
2038
2578
  `;
@@ -2047,15 +2587,16 @@ function formatReadTreeBlockForCli(items, colorEnabled) {
2047
2587
  function formatRunTreeBlockForCli(items, colorEnabled) {
2048
2588
  if (items.length === 0) return "";
2049
2589
  const { count, lines } = formatRunTreeLines(items);
2590
+ const titleText = toolLabel("execShell");
2050
2591
  if (!colorEnabled) {
2051
- const headerLine2 = `\u2022 Run (${count})
2592
+ const headerLine2 = `\u2022 ${titleText} (${count})
2052
2593
  `;
2053
2594
  const treeLines2 = lines.map((l) => ` ${l.connector}${l.commandText}`).join("\n");
2054
2595
  return `${headerLine2}${treeLines2}
2055
2596
  `;
2056
2597
  }
2057
2598
  const bullet = themeText("\u2022", "chrome", true);
2058
- const title = styleCliText("Run", "bold", true);
2599
+ const title = styleCliText(titleText, "bold", true);
2059
2600
  const countText = themeText(`(${count})`, "muted", true);
2060
2601
  const headerLine = `${bullet} ${title} ${countText}
2061
2602
  `;
@@ -2070,15 +2611,16 @@ function formatRunTreeBlockForCli(items, colorEnabled) {
2070
2611
  function formatFetchTreeBlockForCli(items, colorEnabled) {
2071
2612
  if (items.length === 0) return "";
2072
2613
  const { count, lines } = formatFetchTreeLines(items);
2614
+ const titleText = toolLabel("fetchWebpage");
2073
2615
  if (!colorEnabled) {
2074
- const headerLine2 = `\u2022 Fetch (${count})
2616
+ const headerLine2 = `\u2022 ${titleText} (${count})
2075
2617
  `;
2076
2618
  const treeLines2 = lines.map((l) => ` ${l.connector}${l.urlText}`).join("\n");
2077
2619
  return `${headerLine2}${treeLines2}
2078
2620
  `;
2079
2621
  }
2080
2622
  const bullet = themeText("\u2022", "chrome", true);
2081
- const title = styleCliText("Fetch", "bold", true);
2623
+ const title = styleCliText(titleText, "bold", true);
2082
2624
  const countText = themeText(`(${count})`, "muted", true);
2083
2625
  const headerLine = `${bullet} ${title} ${countText}
2084
2626
  `;
@@ -2090,6 +2632,16 @@ function formatFetchTreeBlockForCli(items, colorEnabled) {
2090
2632
  return `${headerLine}${treeLines}
2091
2633
  `;
2092
2634
  }
2635
+ function resolveLoadSkillName(event) {
2636
+ const metaName = typeof event.metadata?.name === "string" ? event.metadata.name : void 0;
2637
+ if (metaName) return metaName;
2638
+ const argName = event.argumentsPreview?.trim();
2639
+ if (argName && !argName.startsWith("{")) return argName;
2640
+ const content = typeof event.content === "string" ? event.content : "";
2641
+ const match = content.match(/Skill "([^"]+)" loaded inline/);
2642
+ if (match?.[1]) return match[1];
2643
+ return argName || "skill";
2644
+ }
2093
2645
  function formatCompactToolLine(event, pending, colorEnabled) {
2094
2646
  const toolName = event.toolName || pending?.toolName || "tool";
2095
2647
  if (isReadToolName(toolName) && event.type === "tool-result") {
@@ -2118,6 +2670,28 @@ function formatCompactToolLine(event, pending, colorEnabled) {
2118
2670
  const message = clip(event.message ?? t("toolFailed"), 96);
2119
2671
  return formatToolTraceLine(`\u25B8 ${label} \u2717 ${message}`, colorEnabled, "error");
2120
2672
  }
2673
+ if (event.type === "tool-result" && toolName === "loadSkill") {
2674
+ const skillName = resolveLoadSkillName(event);
2675
+ const content = typeof event.content === "string" ? event.content : "";
2676
+ const failed2 = /^Skill\s+"[^"]*"\s+not found/.test(content) || isFailedToolResult(event);
2677
+ const labelText = t("usedSkillLabel");
2678
+ if (failed2) {
2679
+ const message = clip(content.split("\n")[0] || t("toolFailed"), 96);
2680
+ return formatToolTraceLine(`\u25B8 ${labelText} (${skillName}) \u2717 ${message}`, colorEnabled, "error");
2681
+ }
2682
+ if (!colorEnabled) {
2683
+ return `\u2726 ${labelText}: ${skillName}
2684
+ `;
2685
+ }
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}
2690
+ `;
2691
+ }
2692
+ if (event.type === "tool-result" && (toolName === "listAgents" || toolName === "startAgentRun" || toolName === "controlAgentRun")) {
2693
+ return formatOrchestrationCardBlock(event, toolName, colorEnabled);
2694
+ }
2121
2695
  if (event.type === "tool-result" && (event.toolName === "ui_ask_choice" || event.metadata?.uiAskChoice)) {
2122
2696
  const block = formatUiAskChoiceBlock(event, colorEnabled);
2123
2697
  if (block) return block;
@@ -2139,36 +2713,17 @@ function formatCompactToolLine(event, pending, colorEnabled) {
2139
2713
  mainLine = `${chromePointer} ${mutedLabel}${argsPart} ${statusToken}${suffixPart}
2140
2714
  `;
2141
2715
  }
2142
- if (!hint.detail) return mainLine;
2143
- const detailLines = hint.detail.split("\n").map((line) => formatEditDetailLine(line, colorEnabled)).join("");
2144
- return `${mainLine}${detailLines}`;
2716
+ if (!hint.detail?.length) return mainLine;
2717
+ return `${mainLine}${formatEditDetailBlock(hint.detail, colorEnabled)}`;
2145
2718
  }
2146
- function formatEditDetailLine(line, colorEnabled) {
2147
- const marker = line.slice(0, 2);
2148
- const rest = line.slice(2);
2149
- if (!colorEnabled) return ` ${line}
2150
- `;
2151
- const diff = diffLineSequences();
2152
- if (!diff) {
2153
- const color = marker === "- " ? "red" : marker === "+ " ? "green" : void 0;
2154
- if (color) {
2155
- return ` ${styleCliText(marker, color, true)}${dimCliText(rest, true)}
2156
- `;
2157
- }
2158
- return ` ${dimCliText(line, true)}
2159
- `;
2160
- }
2161
- const RESET2 = "\x1B[0m";
2162
- if (marker === "- ") {
2163
- return ` ${diff.removed.bg}${diff.removed.fg}- ${rest}${RESET2}
2164
- `;
2165
- }
2166
- if (marker === "+ ") {
2167
- return ` ${diff.added.bg}${diff.added.fg}+ ${rest}${RESET2}
2168
- `;
2719
+ function formatEditDetailBlock(lines, colorEnabled) {
2720
+ if (!colorEnabled) {
2721
+ return lines.map((line) => ` ${line.text}
2722
+ `).join("");
2169
2723
  }
2170
- return ` ${dimCliText(line, true)}
2171
- `;
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("");
2172
2727
  }
2173
2728
  function createToolEventFormatter(mode, colorEnabled = resolveCliColorEnabled()) {
2174
2729
  const pending = /* @__PURE__ */ new Map();
@@ -2176,8 +2731,33 @@ function createToolEventFormatter(mode, colorEnabled = resolveCliColorEnabled())
2176
2731
  let searchBuffer = [];
2177
2732
  let runBuffer = [];
2178
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
+ };
2179
2759
  const flushBuffers = () => {
2180
- let out = "";
2760
+ let out = flushStatusFold();
2181
2761
  if (readBuffer.length > 0) {
2182
2762
  const items = readBuffer.map((evt) => {
2183
2763
  const call = pending.get(evt.toolCallId);
@@ -2226,6 +2806,51 @@ function createToolEventFormatter(mode, colorEnabled = resolveCliColorEnabled())
2226
2806
  const formatter = (event) => {
2227
2807
  if (mode === "hide") return "";
2228
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
+ }
2229
2854
  if (isReadToolName(event.toolName)) {
2230
2855
  if (event.type === "tool-call") {
2231
2856
  pending.set(event.toolCallId, {
@@ -2798,10 +3423,165 @@ function isKnownServerPlatformAgent(options) {
2798
3423
  );
2799
3424
  }
2800
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
+
2801
3581
  // packages/cli/client/agentRun.ts
2802
3582
  import { ulid } from "ulid";
2803
3583
  async function loadRunLocalAgentTurn() {
2804
- const { runLocalAgentTurn } = await import("./agentRuntimeLocal-WJIGU24U.js");
3584
+ const { runLocalAgentTurn } = await import("./agentRuntimeLocal-YNZSHMZC.js");
2805
3585
  return runLocalAgentTurn;
2806
3586
  }
2807
3587
  async function resolveCurrentMachineId(options) {
@@ -2814,6 +3594,12 @@ function resolveRequestedRuntimeMode(options) {
2814
3594
  return envMode;
2815
3595
  return "auto";
2816
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
+ }
2817
3603
  function buildDefaultLocalRuntimeAdapter(options) {
2818
3604
  return createCliLocalRuntimeAdapter({
2819
3605
  env: options.env,
@@ -2821,7 +3607,8 @@ function buildDefaultLocalRuntimeAdapter(options) {
2821
3607
  cwd: options.localRuntimeCwd,
2822
3608
  output: options.output,
2823
3609
  ...options.confirmDestructiveAction ? { confirmDestructiveAction: options.confirmDestructiveAction } : {},
2824
- ...options.requestUserChoice ? { requestUserChoice: options.requestUserChoice } : {}
3610
+ ...options.requestUserChoice ? { requestUserChoice: options.requestUserChoice } : {},
3611
+ ...options.pastedTextStore?.items.size ? { pastedTextStore: options.pastedTextStore } : {}
2825
3612
  });
2826
3613
  }
2827
3614
  function resolveLocalRuntimeAdapter(options) {
@@ -3046,12 +3833,14 @@ async function runHttpAgentTurn(options, authToken) {
3046
3833
  (name) => name.trim()
3047
3834
  );
3048
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;
3049
3841
  const buildRequestBody = (stream) => JSON.stringify({
3050
3842
  agentKey: options.agentKey,
3051
- userInput: buildUserInputContent(
3052
- options.extraContextBlocks?.length ? [...options.extraContextBlocks, "", options.message].join("\n") : options.message,
3053
- options.imageUrls
3054
- ),
3843
+ userInput: buildUserInputContent(expandedMessage, options.imageUrls),
3055
3844
  runtimeContext: {
3056
3845
  surface: "cli",
3057
3846
  host: "terminal",
@@ -3071,6 +3860,7 @@ async function runHttpAgentTurn(options, authToken) {
3071
3860
  ...options.background ? { background: true } : {},
3072
3861
  ...typeof options.timeoutMs === "number" ? { timeoutMs: options.timeoutMs } : {},
3073
3862
  ...options.modelOverride ? { runtimeOptions: { quickChatModelOverride: options.modelOverride } } : {},
3863
+ ...serverContextBlockScopes ? { contextBlockScopes: serverContextBlockScopes } : {},
3074
3864
  stream
3075
3865
  });
3076
3866
  const postAgentRun = (stream) => fetchImpl(`${options.serverUrl}/api/agent/run`, {
@@ -3228,7 +4018,7 @@ async function runLocalAgentTurnForCli(options, settings) {
3228
4018
  } : void 0;
3229
4019
  const currentDialogId = options.continueDialogId ?? ulid();
3230
4020
  const runChildTurn = async (input) => {
3231
- const { runLocalAgentTurn } = await import("./agentRuntimeLocal-WJIGU24U.js");
4021
+ const { runLocalAgentTurn } = await import("./agentRuntimeLocal-YNZSHMZC.js");
3232
4022
  return runLocalAgentTurn(input);
3233
4023
  };
3234
4024
  const createFreshChildBaseAdapter = () => {
@@ -3276,6 +4066,7 @@ async function runLocalAgentTurnForCli(options, settings) {
3276
4066
  spaceId: options.spaceId,
3277
4067
  runtimeContext
3278
4068
  });
4069
+ const expandedMessage = options.pastedTextStore?.items.size ? expandCollapsedPastes(options.message, options.pastedTextStore) : options.message;
3279
4070
  const workingLabel = `${options.agentName} -> working locally`;
3280
4071
  const turnOutput = createCliTurnOutput({
3281
4072
  options,
@@ -3288,6 +4079,19 @@ async function runLocalAgentTurnForCli(options, settings) {
3288
4079
  adapter,
3289
4080
  agentRef: options.agentKey,
3290
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
+ } : {},
3291
4095
  continueDialogId: currentDialogId,
3292
4096
  spaceId: options.spaceId,
3293
4097
  category: options.category,
@@ -3296,8 +4100,7 @@ async function runLocalAgentTurnForCli(options, settings) {
3296
4100
  background: options.background,
3297
4101
  noStream: options.noStream,
3298
4102
  ...runtimeContext ? { runtimeContext } : {},
3299
- ...options.extraContextBlocks?.length ? { contextBlocks: options.extraContextBlocks } : {},
3300
- ...options.contextBlockScopes?.length ? { contextBlockScopes: options.contextBlockScopes } : {},
4103
+ ...options.contextBlockScopes?.length ? { contextBlockScopes: options.contextBlockScopes } : options.extraContextBlocks?.length ? { contextBlocks: options.extraContextBlocks } : {},
3301
4104
  ...typeof options.timeoutMs === "number" ? { timeoutMs: options.timeoutMs } : {},
3302
4105
  ...options.actionGateHandler ? { onActionGate: options.actionGateHandler } : {},
3303
4106
  onLoopEvent: (event) => {
@@ -3333,10 +4136,12 @@ async function runLocalAgentTurnForCli(options, settings) {
3333
4136
  turnOutput.spinner.stop();
3334
4137
  const savedDialogId = error?.dialogId;
3335
4138
  if (error?.code === LOCAL_TURN_ABORTED_CODE || options.abortSignal?.aborted) {
4139
+ const pendingToolName = error?.pendingToolName;
3336
4140
  return {
3337
4141
  exitCode: 0,
3338
4142
  streamInterrupted: true,
3339
- ...savedDialogId ? { dialogId: savedDialogId } : {}
4143
+ ...savedDialogId ? { dialogId: savedDialogId } : {},
4144
+ ...pendingToolName ? { pendingToolName } : {}
3340
4145
  };
3341
4146
  }
3342
4147
  if (settings.reportFailure) {
@@ -3369,7 +4174,8 @@ async function runAgentTurn(options) {
3369
4174
  exitCode: localResult.exitCode,
3370
4175
  ...localResult.dialogId ? { dialogId: localResult.dialogId } : {},
3371
4176
  ...localResult.turnTokens ? { turnTokens: localResult.turnTokens } : {},
3372
- ...localResult.streamInterrupted ? { streamInterrupted: localResult.streamInterrupted } : {}
4177
+ ...localResult.streamInterrupted ? { streamInterrupted: localResult.streamInterrupted } : {},
4178
+ ...localResult.pendingToolName ? { pendingToolName: localResult.pendingToolName } : {}
3373
4179
  };
3374
4180
  }
3375
4181
  if (isMissingLocalAgentConfigError(localResult.localError, options.agentKey)) {
@@ -3420,265 +4226,18 @@ async function runAgentTurn(options) {
3420
4226
  }
3421
4227
 
3422
4228
  // packages/cli/agentRunCommand.ts
3423
- import { existsSync as existsSync3, readFileSync as readFileSync3 } from "node:fs";
3424
- import { join as join3 } from "node:path";
3425
-
3426
- // packages/agent-runtime/quickChatIntentCore.ts
3427
- var INTENT_MODEL = "deepseek-v4-flash";
3428
- var INTENT_PROVIDER = "deepseek";
3429
- var QUICK_CHAT_INTENT_TIMEOUT_MS = 4e3;
3430
- var SHORT_GREETING_MAX_LENGTH = 20;
3431
- var SHORT_GREETING_PATTERN = /^(?:hi|hello|hey|hiya|yo|sup|howdy|嗨|哈喽|哈囉|你好|您好|在吗|在嘛|喂|早上好|中午好|下午好|晚上好|拜拜|再见|谢谢|thanks|thx|ok|好的|收到|了解)[!.。,、~~]?$/iu;
3432
- function isShortGreeting(text) {
3433
- const trimmed = text.trim();
3434
- if (!trimmed) return false;
3435
- if (trimmed.length > SHORT_GREETING_MAX_LENGTH) return false;
3436
- return SHORT_GREETING_PATTERN.test(trimmed);
3437
- }
3438
- var COMPLEXITY_SIMPLE_MAX_LENGTH = 80;
3439
- var COMPLEXITY_MEDIUM_MAX_LENGTH = 500;
3440
- var COMPLEXITY_KEYWORDS = /为什么|如何|分析|对比|比较|设计|架构|实现|原理|推导|评价|区别|关系|影响|优化|重构/;
3441
- var COMPLEXITY_CODE_BLOCK = /```[\s\S]*```/;
3442
- function estimateComplexity(text) {
3443
- const trimmed = text.trim();
3444
- const len = trimmed.length;
3445
- if (len > COMPLEXITY_MEDIUM_MAX_LENGTH) return "complex";
3446
- if (COMPLEXITY_CODE_BLOCK.test(trimmed)) return "complex";
3447
- if (len > COMPLEXITY_SIMPLE_MAX_LENGTH) return "medium";
3448
- if (COMPLEXITY_KEYWORDS.test(trimmed)) return "medium";
3449
- return "simple";
3450
- }
3451
- var TIER_DESCRIPTIONS = {
3452
- flash: "\u5FEB\u901F\u7B80\u5355\uFF1A\u95EE\u5019\u3001\u95F2\u804A\u3001\u5FEB\u901F\u95EE\u7B54\u3001\u7FFB\u8BD1\u3001\u77ED\u6587",
3453
- balanced: "\u5E73\u8861\u63A8\u7406\uFF1A\u5206\u6790\u3001\u4E2D\u7B49\u957F\u5EA6\u5199\u4F5C\u3001\u4EE3\u7801\u3001\u63A8\u7406",
3454
- quality: "\u9AD8\u8D28\u91CF\u6DF1\u5EA6\uFF1A\u590D\u6742\u63A8\u7406\u3001\u957F\u6587\u3001\u67B6\u6784\u8BBE\u8BA1\u3001\u6DF1\u5EA6\u5206\u6790"
3455
- };
3456
- function buildQuickChatIntentSystemPrompt(tierAgents) {
3457
- const agentList = tierAgents.map((t2) => ` - "${t2.agentKey}"\uFF1A${t2.description}`).join("\n");
3458
- 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
3459
-
3460
- \u53EF\u9009 agent \u5217\u8868\uFF08agentKey \u4E0E\u63CF\u8FF0\uFF09\uFF1A
3461
- ${agentList}
3462
-
3463
- \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
3464
- - \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
3465
- - \u7B80\u5355\u95EE\u5019\u3001\u95F2\u804A\u3001\u5FEB\u901F\u95EE\u7B54\u3001\u7FFB\u8BD1\u3001\u77ED\u6587 \u2192 \u9009 flash \u6863
3466
- - \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
3467
- - \u590D\u6742\u63A8\u7406\u3001\u957F\u6587\u3001\u67B6\u6784\u8BBE\u8BA1\u3001\u6DF1\u5EA6\u5206\u6790 \u2192 \u9009 quality \u6863
3468
- - **\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
3469
- - \u4E13\u804C agent \u8DEF\u7531\u89C4\u5219\uFF08\u6709\u660E\u786E\u5339\u914D\u65F6\u4F7F\u7528\uFF09\uFF1A
3470
- - \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
3471
- - \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
3472
- - \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
3473
- - \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
3474
- - **\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
3475
-
3476
- \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
3477
- - 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
3478
- - 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
3479
- - \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
3480
-
3481
- \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
3482
-
3483
- \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
3484
- - \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"
3485
- - \u7528\u6237\u8981\u5199/\u6DA6\u8272/\u6539\u5199/\u7EED\u5199/\u6392\u7248\u4E00\u7BC7\u6587\u6863\u6216\u6587\u7AE0 \u2192 skills \u542B "doc"
3486
- - \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
3487
- - \u666E\u901A\u95EE\u7B54/\u7EAF\u95F2\u804A/\u5EFA\u5E94\u7528 \u2192 skills \u4E3A []
3488
-
3489
- \u53EA\u8F93\u51FA JSON\uFF0C\u4E0D\u8981\u8F93\u51FA\u5176\u4ED6\u5185\u5BB9\uFF1A
3490
- {"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 []>}`;
3491
- }
3492
- function parseQuickChatIntentResult(content, tierAgents) {
3493
- try {
3494
- const parsed = JSON.parse(content.trim());
3495
- if (typeof parsed !== "object" || parsed === null || !("agentKey" in parsed)) return null;
3496
- const key = parsed.agentKey;
3497
- if (typeof key !== "string") return null;
3498
- if (!tierAgents.some((t2) => t2.agentKey === key)) return null;
3499
- const rawNeedsWorkspace = parsed.needsWorkspace;
3500
- const needsWorkspace = rawNeedsWorkspace === true;
3501
- const rawConfidence = parsed.confidence;
3502
- const confidence = typeof rawConfidence === "number" && Number.isFinite(rawConfidence) && rawConfidence >= 0 && rawConfidence <= 1 ? rawConfidence : void 0;
3503
- const rawSkills = parsed.skills;
3504
- let skills;
3505
- if (Array.isArray(rawSkills)) {
3506
- const filtered = [...new Set(rawSkills)].filter(
3507
- (s) => s === "table" || s === "doc" || s === "code"
3508
- );
3509
- if (filtered.length > 0) skills = filtered;
3510
- }
3511
- return { agentKey: key, needsWorkspace, confidence, skills };
3512
- } catch {
3513
- return null;
3514
- }
3515
- }
3516
-
3517
- // packages/cli/client/autoModelRouter.ts
3518
- var CLI_AUTO_TIER_AGENT_KEYS = {
3519
- flash: PUBLIC_DEEPSEEK_V4_FLASH_AGENT_KEY,
3520
- balanced: PUBLIC_DEEPSEEK_V4_PRO_AGENT_KEY,
3521
- quality: PUBLIC_GLM_52_AGENT_KEY
3522
- };
3523
- var CLI_IMAGE_AGENT_KEY = PUBLIC_KIMI_K26_IMAGE_AGENT_KEY;
3524
- var CLI_AUTO_TIER_AGENT_KEY_TABLE = {
3525
- [CLI_AUTO_TIER_AGENT_KEYS.flash]: true,
3526
- [CLI_AUTO_TIER_AGENT_KEYS.balanced]: true,
3527
- [CLI_AUTO_TIER_AGENT_KEYS.quality]: true
3528
- };
3529
- var buildRouteOptions = () => ["flash", "balanced", "quality"].map((tier) => ({
3530
- tier,
3531
- agentKey: CLI_AUTO_TIER_AGENT_KEYS[tier],
3532
- description: TIER_DESCRIPTIONS[tier]
3533
- }));
3534
- var tierForAgentKey = (agentKey) => {
3535
- for (const tier of ["flash", "balanced", "quality"]) {
3536
- if (CLI_AUTO_TIER_AGENT_KEYS[tier] === agentKey) return tier;
3537
- }
3538
- return null;
3539
- };
3540
- function resolveCliAutoFallbackTier(text) {
3541
- switch (estimateComplexity(text)) {
3542
- case "complex":
3543
- return "quality";
3544
- case "medium":
3545
- return "balanced";
3546
- case "simple":
3547
- default:
3548
- return "flash";
3549
- }
3550
- }
3551
- async function classifyCliAutoRoute(text, options) {
3552
- const timeoutMs = options.timeoutMs ?? QUICK_CHAT_INTENT_TIMEOUT_MS;
3553
- const fallbackTier = resolveCliAutoFallbackTier(text);
3554
- const fallback = () => ({
3555
- agentKey: CLI_AUTO_TIER_AGENT_KEYS[fallbackTier],
3556
- tier: fallbackTier,
3557
- classified: false
3558
- });
3559
- if (!text.trim()) return fallback();
3560
- if (isShortGreeting(text)) {
3561
- return {
3562
- agentKey: CLI_AUTO_TIER_AGENT_KEYS.flash,
3563
- tier: "flash",
3564
- classified: true
3565
- };
3566
- }
3567
- if (!options.authToken) return fallback();
3568
- const fetchImpl = options.fetchImpl ?? globalThis.fetch;
3569
- const controller = new AbortController();
3570
- const timeoutHandle = setTimeout(() => controller.abort(), timeoutMs);
3571
- try {
3572
- const routeOptions = buildRouteOptions();
3573
- const messages = [
3574
- { role: "system", content: buildQuickChatIntentSystemPrompt(routeOptions) },
3575
- { role: "user", content: text }
3576
- ];
3577
- const { url, init } = buildPlatformChatCompletionRequest({
3578
- providerConfig: {
3579
- serverUrl: options.serverUrl,
3580
- authToken: options.authToken,
3581
- agentKey: CLI_AUTO_TIER_AGENT_KEYS.flash,
3582
- model: INTENT_MODEL,
3583
- provider: INTENT_PROVIDER,
3584
- endpoint: resolvePlatformChatCompletionsEndpoint(INTENT_PROVIDER) ?? "",
3585
- requestOptions: {}
3586
- },
3587
- messages,
3588
- stream: false
3589
- });
3590
- const response = await fetchImpl(url, {
3591
- ...init,
3592
- signal: controller.signal
3593
- });
3594
- if (!response.ok) return fallback();
3595
- const data = parsePlatformChatCompletionData(await response.text());
3596
- const content = data?.choices?.[0]?.message?.content;
3597
- if (typeof content !== "string" || !content.trim()) return fallback();
3598
- const parsed = parseQuickChatIntentResult(content, routeOptions);
3599
- if (!parsed) return fallback();
3600
- const tier = tierForAgentKey(parsed.agentKey) ?? fallbackTier;
3601
- return {
3602
- agentKey: parsed.agentKey,
3603
- tier,
3604
- classified: true,
3605
- confidence: parsed.confidence,
3606
- needsWorkspace: parsed.needsWorkspace,
3607
- skills: parsed.skills
3608
- };
3609
- } catch {
3610
- return fallback();
3611
- } finally {
3612
- clearTimeout(timeoutHandle);
3613
- }
3614
- }
3615
-
3616
- // packages/agent-runtime/skillDiscovery.ts
3617
- import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
3618
- import { join } from "node:path";
3619
- var SKILL_SCAN_DIRS = [".agents/skills", "docs/skills"];
3620
- var MAX_DISCOVERED_SKILLS = 50;
3621
- function parseSkillFrontmatter(filePath) {
3622
- try {
3623
- const content = readFileSync(filePath, "utf8").slice(0, 2048);
3624
- const fmMatch = content.match(/^---\n([\s\S]*?)\n---/);
3625
- if (!fmMatch) return {};
3626
- const fm = load(fmMatch[1]);
3627
- if (!fm || typeof fm !== "object") return {};
3628
- const name = typeof fm.name === "string" ? fm.name : void 0;
3629
- const rawDesc = fm.description;
3630
- const description = typeof rawDesc === "string" ? rawDesc : rawDesc == null ? void 0 : String(rawDesc);
3631
- const sanitize = (s) => s?.trim().replace(/^["']|["']$/g, "").replace(/[\n\r]+/g, " ").slice(0, 200);
3632
- return { name: sanitize(name), description: sanitize(description) };
3633
- } catch {
3634
- return {};
3635
- }
3636
- }
3637
- function discoverSkills(cwd) {
3638
- const skills = [];
3639
- for (const dir of SKILL_SCAN_DIRS) {
3640
- if (skills.length >= MAX_DISCOVERED_SKILLS) break;
3641
- const absDir = join(cwd, dir);
3642
- if (!existsSync(absDir) || !statSync(absDir).isDirectory()) continue;
3643
- try {
3644
- for (const entry of readdirSync(absDir)) {
3645
- if (skills.length >= MAX_DISCOVERED_SKILLS) break;
3646
- const skillMdPath = join(absDir, entry, "SKILL.md");
3647
- if (existsSync(skillMdPath)) {
3648
- const { name, description } = parseSkillFrontmatter(skillMdPath);
3649
- skills.push({ name: name ?? entry, description: description ?? "", relativePath: join(dir, entry, "SKILL.md") });
3650
- continue;
3651
- }
3652
- if (dir === "docs/skills" && entry.endsWith(".md")) {
3653
- const flatPath = join(absDir, entry);
3654
- const { name, description } = parseSkillFrontmatter(flatPath);
3655
- skills.push({ name: name ?? entry.replace(/\.md$/, ""), description: description ?? "", relativePath: join(dir, entry) });
3656
- }
3657
- }
3658
- } catch {
3659
- }
3660
- }
3661
- return skills;
3662
- }
3663
- function buildSkillDiscoveryContextBlock(cwd) {
3664
- try {
3665
- const discovered = discoverSkills(cwd);
3666
- const layer = buildSkillDiscoveryLayer(discovered, cwd);
3667
- return layer?.content ?? null;
3668
- } catch {
3669
- return null;
3670
- }
3671
- }
4229
+ import { existsSync as existsSync2, readFileSync as readFileSync2 } from "node:fs";
4230
+ import { join as join2 } from "node:path";
3672
4231
 
3673
4232
  // packages/cli/agentRunPrompts.ts
3674
- import { existsSync as existsSync2, readFileSync as readFileSync2, readdirSync as readdirSync2, statSync as statSync2 } from "node:fs";
3675
- import { dirname, extname, isAbsolute, join as join2, relative as relativePath, resolve, sep } from "node:path";
4233
+ import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
4234
+ import { dirname, extname, isAbsolute, join, relative as relativePath, resolve, sep } from "node:path";
3676
4235
  function workflowRefToCandidatePath(cwd, ref) {
3677
4236
  const normalized = ref.trim();
3678
4237
  if (!normalized) return "";
3679
4238
  if (normalized.endsWith(".md") || normalized.includes("/") || normalized.includes("\\")) {
3680
4239
  const directPath = resolve(cwd, normalized);
3681
- if (existsSync2(directPath)) return directPath;
4240
+ if (existsSync(directPath)) return directPath;
3682
4241
  }
3683
4242
  const fileName = normalized.replace(/[^a-zA-Z0-9一-鿿]+/g, "-").replace(/^-+|-+$/g, "");
3684
4243
  return resolve(cwd, "docs", "workflows", `${fileName}.md`);
@@ -3692,26 +4251,26 @@ function skillRefToCandidatePath(cwd, ref) {
3692
4251
  if (!normalized) return "";
3693
4252
  if (normalized.endsWith(".md") || normalized.includes("/") || normalized.includes("\\")) {
3694
4253
  const directPath = resolve(cwd, normalized);
3695
- if (existsSync2(directPath)) return directPath;
4254
+ if (existsSync(directPath)) return directPath;
3696
4255
  }
3697
4256
  const fileName = normalized.replace(/[^a-zA-Z0-9一-鿿]+/g, "-").replace(/^-+|-+$/g, "");
3698
4257
  for (const dir of SKILL_SEARCH_DIRS) {
3699
4258
  if (dir === "docs/skills") {
3700
4259
  const flatPath = resolve(cwd, dir, `${fileName}.md`);
3701
- if (existsSync2(flatPath)) return flatPath;
4260
+ if (existsSync(flatPath)) return flatPath;
3702
4261
  } else {
3703
4262
  const skillMdPath = resolve(cwd, dir, fileName, "SKILL.md");
3704
- if (existsSync2(skillMdPath)) return skillMdPath;
4263
+ if (existsSync(skillMdPath)) return skillMdPath;
3705
4264
  }
3706
4265
  }
3707
4266
  return resolve(cwd, "docs", "skills", `${fileName}.md`);
3708
4267
  }
3709
4268
  async function resolveWorkflowReference(ref, cwd = process.cwd()) {
3710
4269
  const path = workflowRefToCandidatePath(cwd, ref);
3711
- if (!path || !existsSync2(path)) {
4270
+ if (!path || !existsSync(path)) {
3712
4271
  throw new Error(`Workflow reference not found: ${ref}`);
3713
4272
  }
3714
- const markdown = readFileSync2(path, "utf8");
4273
+ const markdown = readFileSync(path, "utf8");
3715
4274
  const parsed = parseSkillDocProtocol(markdown);
3716
4275
  return {
3717
4276
  ref,
@@ -3728,8 +4287,8 @@ function inlineRelativeRefs(body, skillDir) {
3728
4287
  const absPath = resolve(skillDir, cleaned);
3729
4288
  const relative = relativePath(normalizedSkillDir, absPath);
3730
4289
  if (relative.startsWith("..") || isAbsolute(relative)) return match;
3731
- if (!existsSync2(absPath) || !absPath.endsWith(".md")) return match;
3732
- const refContent = readFileSync2(absPath, "utf8");
4290
+ if (!existsSync(absPath) || !absPath.endsWith(".md")) return match;
4291
+ const refContent = readFileSync(absPath, "utf8");
3733
4292
  return `
3734
4293
 
3735
4294
  ### ${label}
@@ -3740,9 +4299,9 @@ ${refContent}
3740
4299
  });
3741
4300
  }
3742
4301
  function listSkillScripts(skillDir) {
3743
- const scriptsDir = join2(skillDir, "scripts");
3744
- if (!existsSync2(scriptsDir) || !statSync2(scriptsDir).isDirectory()) return null;
3745
- const entries = readdirSync2(scriptsDir).filter((e) => !e.startsWith("."));
4302
+ const scriptsDir = join(skillDir, "scripts");
4303
+ if (!existsSync(scriptsDir) || !statSync(scriptsDir).isDirectory()) return null;
4304
+ const entries = readdirSync(scriptsDir).filter((e) => !e.startsWith("."));
3746
4305
  if (entries.length === 0) return null;
3747
4306
  return [
3748
4307
  "",
@@ -3768,10 +4327,10 @@ async function resolveSkillReference(ref, options = {}) {
3768
4327
  } else {
3769
4328
  const cwd = options.cwd ?? process.cwd();
3770
4329
  const path = skillRefToCandidatePath(cwd, ref);
3771
- if (!path || !existsSync2(path)) {
4330
+ if (!path || !existsSync(path)) {
3772
4331
  throw new Error(`Skill reference not found: ${ref}`);
3773
4332
  }
3774
- markdown = readFileSync2(path, "utf8");
4333
+ markdown = readFileSync(path, "utf8");
3775
4334
  filePath = path;
3776
4335
  skillDir = dirname(path);
3777
4336
  }
@@ -3862,8 +4421,8 @@ function prependSubjectDialogMarker(message, subjectDialogKey) {
3862
4421
  function normalizeCliImageInput(input) {
3863
4422
  if (/^(https?:|data:|file:)/i.test(input)) return input;
3864
4423
  const absolutePath = resolve(input);
3865
- if (!existsSync2(absolutePath)) return input;
3866
- const base64 = readFileSync2(absolutePath).toString("base64");
4424
+ if (!existsSync(absolutePath)) return input;
4425
+ const base64 = readFileSync(absolutePath).toString("base64");
3867
4426
  return `data:${imageMimeTypeForPath(absolutePath)};base64,${base64}`;
3868
4427
  }
3869
4428
  function imageMimeTypeForPath(path) {
@@ -4013,16 +4572,16 @@ var buildCjkTokens = (text) => {
4013
4572
  }
4014
4573
  return tokens;
4015
4574
  };
4016
- var tokenize = (text) => {
4575
+ var tokenize2 = (text) => {
4017
4576
  const normalized = text.toLowerCase();
4018
4577
  const wordTokens = normalized.split(/[\s,.;:!?()[\]{}"'`,。!?:;、]+/).map((token) => token.trim()).filter((token) => token.length >= 2);
4019
4578
  return [...wordTokens, ...buildCjkTokens(normalized)];
4020
4579
  };
4021
4580
  var keywordScore = (query, item) => {
4022
- const queryTokens = new Set(tokenize(query));
4581
+ const queryTokens = new Set(tokenize2(query));
4023
4582
  if (queryTokens.size === 0) return 0;
4024
4583
  const haystack = /* @__PURE__ */ new Set([
4025
- ...tokenize(item.content),
4584
+ ...tokenize2(item.content),
4026
4585
  ...(item.tags ?? []).map((tag) => tag.toLowerCase()),
4027
4586
  item.patternKey?.toLowerCase() ?? ""
4028
4587
  ]);
@@ -4512,10 +5071,10 @@ async function runAgentRunCommand(args, deps) {
4512
5071
  const extraContextBlocks = [];
4513
5072
  const AGENTS_MD_MAX = 8192;
4514
5073
  for (const name of ["AGENTS.md", "CLAUDE.md"]) {
4515
- const agentsMdPath = join3(cliCwd, name);
4516
- if (existsSync3(agentsMdPath)) {
5074
+ const agentsMdPath = join2(cliCwd, name);
5075
+ if (existsSync2(agentsMdPath)) {
4517
5076
  try {
4518
- let mdContent = readFileSync3(agentsMdPath, "utf8").trim();
5077
+ let mdContent = readFileSync2(agentsMdPath, "utf8").trim();
4519
5078
  if (!mdContent) continue;
4520
5079
  if (Buffer.byteLength(mdContent, "utf8") > AGENTS_MD_MAX) {
4521
5080
  mdContent = Buffer.from(mdContent, "utf8").subarray(0, AGENTS_MD_MAX).toString("utf8") + "\n\n<!-- AGENTS.md truncated -->";
@@ -4636,8 +5195,7 @@ ${mdContent}`);
4636
5195
  traceTools: parsed.traceTools,
4637
5196
  ...parsed.eventsMode ? { eventsMode: parsed.eventsMode } : {},
4638
5197
  ...parsed.taskEvidence ? { taskEvidence: parsed.taskEvidence } : {},
4639
- ...extraContextBlocks.length > 0 ? { extraContextBlocks } : {},
4640
- ...contextBlockScopes.length > 0 ? { contextBlockScopes } : {}
5198
+ ...contextBlockScopes.length > 0 ? { contextBlockScopes } : extraContextBlocks.length > 0 ? { extraContextBlocks } : {}
4641
5199
  });
4642
5200
  let result = await raceWithWatchdog(
4643
5201
  runner({
@@ -4768,10 +5326,28 @@ function isBalanceExhaustedError(error) {
4768
5326
  }
4769
5327
 
4770
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,
4771
5335
  formatTokenCount,
4772
5336
  renderTokenStatus,
4773
5337
  resolveCliColorEnabled,
4774
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,
4775
5351
  THEME_PALETTES,
4776
5352
  getActiveThemeName,
4777
5353
  setActiveThemeName,
@@ -4780,23 +5356,24 @@ export {
4780
5356
  getActiveDensity,
4781
5357
  setActiveDensity,
4782
5358
  resolveTuiBrightness,
5359
+ setActiveTerminalBaseHex,
4783
5360
  surfaceBackgroundSequence,
4784
5361
  themeColorSequence,
4785
5362
  themeText,
4786
- highlightMarkdown,
4787
5363
  formatAssistantDisplay,
4788
5364
  normalizeThinkingDisplayMode,
4789
- parseCliLocale,
4790
- getCliLocale,
4791
- setCliLocale,
4792
- initCliLocale,
4793
- t,
4794
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,
4795
5376
  runAgentTurn,
4796
- CLI_IMAGE_AGENT_KEY,
4797
- CLI_AUTO_TIER_AGENT_KEY_TABLE,
4798
- classifyCliAutoRoute,
4799
- buildSkillDiscoveryContextBlock,
4800
5377
  resolveWorkflowReference,
4801
5378
  resolveSkillReference,
4802
5379
  buildSkillContextBlocks,