pi-web-ui 0.116.0 → 0.117.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/CHANGELOG.md +38 -4
  2. package/bin/device-hub-cli.mjs +26 -3
  3. package/bin/pi-web-ui.mjs +138 -70
  4. package/dist/server/agent-service-daemon.js +52 -6
  5. package/dist/server/agent-service.js +495 -141
  6. package/dist/server/canvas/canvas-workspace.js +18 -86
  7. package/dist/server/client-state.js +35 -6
  8. package/dist/server/compaction-markers.js +43 -24
  9. package/dist/server/dangling-tools.js +172 -16
  10. package/dist/server/device-center/bot-execution.js +48 -1
  11. package/dist/server/device-center/collab-service.js +26 -8
  12. package/dist/server/device-center/collab-tool.js +394 -18
  13. package/dist/server/device-center/connector.js +107 -37
  14. package/dist/server/device-center/delivery-authority.js +98 -0
  15. package/dist/server/device-center/delivery-subject.js +30 -0
  16. package/dist/server/device-center/device-integration.js +453 -183
  17. package/dist/server/device-center/execution-guides.js +15 -5
  18. package/dist/server/device-center/executor.js +47 -5
  19. package/dist/server/device-center/hub-conversations.js +14 -4
  20. package/dist/server/device-center/hub-deliveries.js +120 -15
  21. package/dist/server/device-center/hub-integration.js +655 -334
  22. package/dist/server/device-center/hub-page.js +5 -4
  23. package/dist/server/device-center/hub-setup.js +23 -1
  24. package/dist/server/device-center/hub-transaction-log.js +197 -0
  25. package/dist/server/device-center/hub.js +772 -354
  26. package/dist/server/device-center/integration-verification.js +113 -0
  27. package/dist/server/device-center/local-hub.js +6 -2
  28. package/dist/server/device-center/local-publication.js +423 -0
  29. package/dist/server/device-center/local-verification-job.js +97 -0
  30. package/dist/server/device-center/local-verification.js +274 -0
  31. package/dist/server/device-center/local.js +107 -12
  32. package/dist/server/device-center/main.js +4 -1
  33. package/dist/server/device-center/partition-log.js +62 -25
  34. package/dist/server/device-center/publication-journal.js +312 -0
  35. package/dist/server/device-center/publish-intent.js +379 -0
  36. package/dist/server/device-center/relay.js +134 -24
  37. package/dist/server/device-center/runtime.js +426 -42
  38. package/dist/server/device-center/store.js +225 -47
  39. package/dist/server/device-center/task-outcome.js +81 -0
  40. package/dist/server/device-center/task-recovery.js +603 -178
  41. package/dist/server/device-center/task-settlement.js +353 -0
  42. package/dist/server/device-center/task-workspace.js +443 -0
  43. package/dist/server/device-center/verification-limits.js +10 -0
  44. package/dist/server/device-center/work-contract.js +995 -0
  45. package/dist/server/dispatch-domain-handlers.js +15 -0
  46. package/dist/server/dsh/dsh-agent-service.js +9 -2
  47. package/dist/server/index.js +26 -1
  48. package/dist/server/patch-node-pty.js +3 -2
  49. package/dist/server/patch-remote-catalog.js +3 -2
  50. package/dist/server/preset-fields.js +17 -1
  51. package/dist/server/preset-share.js +1 -0
  52. package/dist/server/protocol-version.js +1 -1
  53. package/dist/server/quick-ask-settings.js +28 -0
  54. package/dist/server/quick-ask.js +164 -0
  55. package/dist/server/resolve-global-sdk.js +61 -11
  56. package/dist/server/scheduler-tasks.js +35 -8
  57. package/dist/server/session-list-scan.js +223 -0
  58. package/dist/server/session-open.js +93 -0
  59. package/dist/server/session-parser.js +4 -0
  60. package/dist/server/session-scan.js +90 -38
  61. package/dist/server/settings-service.js +9 -1
  62. package/dist/server/soft-cap.js +5 -0
  63. package/dist/server/transcript-prepare.js +73 -0
  64. package/dist/server/universal/drivers/claude-code.js +98 -34
  65. package/dist/server/universal/universal-session.js +4 -0
  66. package/dist/server/workspace-handle.js +428 -0
  67. package/docs/architecture-plugins.md +18 -5
  68. package/docs/device-center.md +30 -22
  69. package/package.json +3 -4
  70. package/plugin-sdk/README.md +16 -8
  71. package/plugin-sdk/client.d.ts +27 -0
  72. package/plugin-sdk/client.mjs +82 -0
  73. package/plugin-sdk/index.d.ts +10 -0
  74. package/plugin-sdk/index.mjs +4 -683
  75. package/plugin-sdk/package.json +15 -4
  76. package/plugin-sdk/testing.d.ts +10 -0
  77. package/plugin-sdk/testing.mjs +566 -0
  78. package/themes/flow-cristallo.css +168 -0
  79. package/themes/flow-ink.css +169 -0
  80. package/themes/flow-obsidian.css +169 -0
  81. package/themes/flow-zurich.css +169 -0
  82. package/web/dist/.build-assets.json +1 -1
  83. package/web/dist/assets/{BgTasksModal-BDoOpj-F.js → BgTasksModal-BjNRIUIc.js} +1 -1
  84. package/web/dist/assets/{BgTasksModal-C0i3O1FT.js → BgTasksModal-C0zuU8FE.js} +1 -1
  85. package/web/dist/assets/{CanvasStudio-B8thymBN.js → CanvasStudio-BWvdmJ0M.js} +3 -3
  86. package/web/dist/assets/{CanvasStudio-zSxyIx1R.js → CanvasStudio-VQFjmTGq.js} +3 -3
  87. package/web/dist/assets/DeviceCenter-DI9_0aBB.js +3 -0
  88. package/web/dist/assets/DeviceCenter-DsNtXqzY.js +3 -0
  89. package/web/dist/assets/{DeviceExecutionSettings-q5Ik8oXg.js → DeviceExecutionSettings-BLP1Su5G.js} +1 -1
  90. package/web/dist/assets/DeviceGroups-2Pvk0Cds.js +1 -0
  91. package/web/dist/assets/DeviceGroups-CP7CcyPD.js +1 -0
  92. package/web/dist/assets/{Dropdown-C4LIhshN.js → Dropdown-CQtstPGv.js} +1 -1
  93. package/web/dist/assets/FilePreview-BMB2tNyT.js +2 -0
  94. package/web/dist/assets/FilePreview-RGFQUbJo.js +2 -0
  95. package/web/dist/assets/{GlobalSearchModal-BWgU8yPd.js → GlobalSearchModal-BM5wxiqU.js} +1 -1
  96. package/web/dist/assets/{GlobalSearchModal-F7fNimKk.js → GlobalSearchModal-DGv_WINq.js} +1 -1
  97. package/web/dist/assets/GroupConversation-B7SnuXj1.js +61 -0
  98. package/web/dist/assets/GroupConversation-Dda69q-2.js +61 -0
  99. package/web/dist/assets/{HintTip-c6d0TJoh.js → HintTip-ChTW8o1m.js} +1 -1
  100. package/web/dist/assets/ModelConfigModal-C-0Z4hUZ.js +2 -0
  101. package/web/dist/assets/ModelConfigModal-yqeadyab.js +2 -0
  102. package/web/dist/assets/{PiSetupModal-BmMrrgB9.js → PiSetupModal-BX5rUuoI.js} +1 -1
  103. package/web/dist/assets/{ProviderOAuthControls-BGSBIKD7.js → ProviderOAuthControls-DY4SCfXg.js} +1 -1
  104. package/web/dist/assets/SCMPanel-C4KbQvvK.js +2 -0
  105. package/web/dist/assets/SCMPanel-DPAyY2sW.js +2 -0
  106. package/web/dist/assets/SettingsModal-DxZp6D_g.js +32 -0
  107. package/web/dist/assets/SettingsModal-WhQzaOPt.js +32 -0
  108. package/web/dist/assets/{TerminalPanel-DDavKvFr.js → TerminalPanel-D4By_RVc.js} +2 -2
  109. package/web/dist/assets/{TerminalPanel-0CYvD72B.js → TerminalPanel-lZw8-i3j.js} +2 -2
  110. package/web/dist/assets/{TuiOverlayModal-BsA-QTvN.js → TuiOverlayModal-C3pAVuC8.js} +1 -1
  111. package/web/dist/assets/{TuiOverlayModal-DzoVQBuG.js → TuiOverlayModal-D7_rEXcJ.js} +1 -1
  112. package/web/dist/assets/app-globals-KqOVtmp1.js +123 -0
  113. package/web/dist/assets/{canvas-client-CUnXlQYX.js → canvas-client-BY6ojmle.js} +1 -1
  114. package/web/dist/assets/{desktop-aAKpvKJV.js → desktop-CV6KKp9R.js} +1 -1
  115. package/web/dist/assets/index-BawF7ZP5.js +397 -0
  116. package/web/dist/assets/index-BoGCoq5X.js +397 -0
  117. package/web/dist/assets/index-CVW9FoY2.css +1 -0
  118. package/web/dist/assets/{plugin-host-BRWib9DF.js → plugin-host-Dn8Dd6SC.js} +1 -1
  119. package/web/dist/assets/{remote-ssh-client-CfYSMEZg.js → remote-ssh-client-Dzi-eEyE.js} +1 -1
  120. package/web/dist/assets/{theme-D2l_mLNo.js → theme-D_bihpdN.js} +1 -1
  121. package/web/dist/index.html +11 -11
  122. package/web/dist/sw.js +1 -1
  123. package/dist/gh-comment-781.md +0 -5
  124. package/dist/server/device-center/local-page.js +0 -17
  125. package/dist/server/device-center/smoke-preview.js +0 -3
  126. package/dist/server/durable/durable-capabilities.js +0 -11
  127. package/dist/server/markers/builtins/services.js +0 -123
  128. package/dist/server/markers/builtins/todo.js +0 -189
  129. package/dist/server/markers-list-tool.js +0 -34
  130. package/dist/server/orchestrator.js +0 -109
  131. package/dist/server/patch-turn-end-boundary.js +0 -77
  132. package/dist/server/system-prompt-soul.js +0 -41
  133. package/dist/server/univer-service.js +0 -448
  134. package/dist/server/universal/drivers/dsh-driver.js +0 -379
  135. package/dist/test-artifact.md +0 -9
  136. package/dist/test-preview-modal.md +0 -11
  137. package/dist/test-report.html +0 -20
  138. package/web/dist/assets/DeviceCenter-DfAHKcid.js +0 -3
  139. package/web/dist/assets/DeviceCenter-ydvOTlzE.js +0 -3
  140. package/web/dist/assets/DeviceGroups-CI14_SRb.js +0 -1
  141. package/web/dist/assets/DeviceGroups-DvsB5IEU.js +0 -1
  142. package/web/dist/assets/FilePreview-BgGongmv.js +0 -2
  143. package/web/dist/assets/FilePreview-D4NrhF-U.js +0 -2
  144. package/web/dist/assets/GroupConversation-Dh71Pdb-.js +0 -17
  145. package/web/dist/assets/GroupConversation-ZK3nRmNm.js +0 -17
  146. package/web/dist/assets/ModelConfigModal-YVEgyy34.js +0 -2
  147. package/web/dist/assets/ModelConfigModal-vWtg3srp.js +0 -2
  148. package/web/dist/assets/SCMPanel-B8_EDxNr.js +0 -2
  149. package/web/dist/assets/SCMPanel-BU58qk3T.js +0 -2
  150. package/web/dist/assets/SettingsModal-CMUybq3J.js +0 -32
  151. package/web/dist/assets/SettingsModal-OBmGTh-5.js +0 -32
  152. package/web/dist/assets/app-globals-CZxzGvIo.js +0 -123
  153. package/web/dist/assets/index-C6DwztqE.css +0 -1
  154. package/web/dist/assets/index-CuN802Sj.js +0 -93
  155. package/web/dist/assets/index-EH5Fw9fa.js +0 -93
@@ -0,0 +1,73 @@
1
+ /**
2
+ * 打开历史会话前的转录预处理:链修复(compaction-markers)+ 悬空 toolCall 修复(dangling-tools)
3
+ * 合并为一次异步读盘。
4
+ *
5
+ * 原流程对同一个文件做两次同步 readFileSync,并对每一行完整 JSON.parse(悬空检查无缓存),
6
+ * 大转录(10MB+)打开时会阻塞事件循环、卡住所有客户端的 WebSocket。现在:
7
+ * - 两项检查各自的健康指纹(mtimeMs:size)都命中 → 不读盘;
8
+ * - 否则只用 fs.promises.readFile 读一次,两项检查共用文本;悬空检查按需解析(见
9
+ * healDanglingToolCallsInText),健康长转录只完整解析末尾几行;
10
+ * - 修复结束后按最终文件状态刷新两份指纹。
11
+ *
12
+ * 语义保持与原 repairTranscriptFileBeforeOpen 一致:链修复改写了文件时本次不做悬空修复
13
+ * (下次打开时指纹不匹配会再查);链修复失败(读/写失败)时整体放弃。
14
+ */
15
+ import { promises as fsPromises, statSync } from "node:fs";
16
+ import { healthyRepairResult, isTranscriptHealthyCached, rememberHealthyTranscriptSig, repairSessionFileFromText, } from "./compaction-markers.js";
17
+ import { forgetHealthyDangling, healDanglingToolCallsInText, isDanglingHealthyCached, rememberHealthyDangling, } from "./dangling-tools.js";
18
+ function sigOf(st) {
19
+ return `${st.mtimeMs}:${st.size}`;
20
+ }
21
+ export async function prepareTranscriptForOpen(filePath, cause = "generic") {
22
+ let sig;
23
+ try {
24
+ sig = sigOf(await fsPromises.stat(filePath));
25
+ }
26
+ catch {
27
+ return { repair: null, healed: 0, read: false };
28
+ }
29
+ const repairHealthy = isTranscriptHealthyCached(filePath, sig);
30
+ const danglingHealthy = isDanglingHealthyCached(filePath, sig);
31
+ if (repairHealthy && danglingHealthy) {
32
+ return { repair: healthyRepairResult(filePath), healed: 0, read: false };
33
+ }
34
+ let raw;
35
+ try {
36
+ raw = await fsPromises.readFile(filePath, "utf8");
37
+ }
38
+ catch {
39
+ return { repair: null, healed: 0, read: false };
40
+ }
41
+ const repair = repairHealthy ? healthyRepairResult(filePath) : repairSessionFileFromText(filePath, raw);
42
+ if (!repair)
43
+ return { repair: null, healed: 0, read: true };
44
+ if (repair.changed) {
45
+ // 文件已被改写:悬空检查留到下次打开(与原流程一致),旧指纹作废。
46
+ forgetHealthyDangling(filePath);
47
+ return { repair, healed: 0, read: true };
48
+ }
49
+ let healed = 0;
50
+ if (!danglingHealthy) {
51
+ try {
52
+ healed = healDanglingToolCallsInText(filePath, raw, cause);
53
+ }
54
+ catch {
55
+ healed = 0;
56
+ }
57
+ }
58
+ // 按最终文件状态刷新指纹:追加合成结果后 size/mtime 已变,两项检查对新内容均为健康。
59
+ if (healed >= 0) {
60
+ try {
61
+ const finalSig = healed > 0 ? sigOf(statSync(filePath)) : sig;
62
+ rememberHealthyDangling(filePath, finalSig);
63
+ rememberHealthyTranscriptSig(filePath, finalSig);
64
+ }
65
+ catch {
66
+ /* best effort */
67
+ }
68
+ }
69
+ else {
70
+ forgetHealthyDangling(filePath);
71
+ }
72
+ return { repair, healed, read: true };
73
+ }
@@ -163,6 +163,8 @@ export class ClaudeCodeDriver extends BaseAgentDriver {
163
163
  turnCompleteEmitted = false;
164
164
  lastTurnMeta;
165
165
  currentThinkingLevel = "medium";
166
+ seenToolStarts = new Set();
167
+ seenToolEnds = new Set();
166
168
  constructor(cwd, opts) {
167
169
  super(cwd);
168
170
  this.executablePath = resolveClaudeExecutable(opts?.executablePath ?? "claude");
@@ -193,6 +195,8 @@ export class ClaudeCodeDriver extends BaseAgentDriver {
193
195
  this.lastErrorHint = "";
194
196
  this.turnHadText = false;
195
197
  this.turnCompleteEmitted = false;
198
+ this.seenToolStarts.clear();
199
+ this.seenToolEnds.clear();
196
200
  // 格式化用户附件上下文
197
201
  let finalPrompt = prompt;
198
202
  if (attachments && attachments.length > 0) {
@@ -227,11 +231,12 @@ export class ClaudeCodeDriver extends BaseAgentDriver {
227
231
  const args = ["-p", "--output-format", "stream-json", "--verbose", ...this.extraArgs];
228
232
  // 解析目标模型与对应服务商凭据
229
233
  let targetModel = this.currentModel;
230
- let targetProvider = "anthropic";
234
+ let targetProvider = null;
235
+ let isOfficial = false;
231
236
  if (this.currentModel.includes("/")) {
232
237
  const parts = this.currentModel.split("/");
233
238
  if (parts[0] === "claude-code") {
234
- targetProvider = "anthropic";
239
+ isOfficial = true;
235
240
  targetModel = parts.slice(1).join("/");
236
241
  }
237
242
  else {
@@ -239,6 +244,9 @@ export class ClaudeCodeDriver extends BaseAgentDriver {
239
244
  targetModel = parts.slice(1).join("/");
240
245
  }
241
246
  }
247
+ else {
248
+ isOfficial = true;
249
+ }
242
250
  if (targetModel) {
243
251
  args.push("--model", targetModel);
244
252
  }
@@ -248,28 +256,7 @@ export class ClaudeCodeDriver extends BaseAgentDriver {
248
256
  if (this.activeSessionId) {
249
257
  args.push("--resume", this.activeSessionId);
250
258
  }
251
- // 动态从模型配置基础层解析凭据与 BaseURL,实现类似 cc-switch 的零侵入环境注入
252
- const cred = this.agentDir
253
- ? resolveProviderCredential(this.agentDir, targetProvider)
254
- : { providerId: targetProvider };
255
- const spawnEnv = {
256
- ...process.env,
257
- NO_COLOR: "1",
258
- CI: "1",
259
- };
260
- if (cred.baseUrl) {
261
- spawnEnv.ANTHROPIC_BASE_URL = cred.baseUrl;
262
- }
263
- if (cred.apiKey) {
264
- spawnEnv.ANTHROPIC_API_KEY = cred.apiKey;
265
- }
266
- if (cred.headers) {
267
- for (const [hk, hv] of Object.entries(cred.headers)) {
268
- if (hk.toLowerCase() === "authorization" && hv) {
269
- spawnEnv.ANTHROPIC_AUTH_TOKEN = hv.replace(/^Bearer\s+/i, "");
270
- }
271
- }
272
- }
259
+ const spawnEnv = this.buildSpawnEnv(isOfficial, targetProvider);
273
260
  let proc;
274
261
  try {
275
262
  proc = spawn(this.executablePath, args, {
@@ -353,12 +340,17 @@ export class ClaudeCodeDriver extends BaseAgentDriver {
353
340
  });
354
341
  }
355
342
  handleClaudeEvent(event, sink, activeToolJson) {
343
+ // 0. 支持解包 stream_event 包裹层(Claude Code 启用流式事件或内部代理时的标准结构)
344
+ if (event.type === "stream_event" && event.event && typeof event.event === "object") {
345
+ this.handleClaudeEvent(event.event, sink, activeToolJson);
346
+ return;
347
+ }
356
348
  const type = String(event.type ?? "");
357
349
  // 1. 会话建立或恢复事件
358
350
  if (type === "system" && typeof event.session_id === "string") {
359
351
  this.activeSessionId = event.session_id;
360
352
  }
361
- // 1.1 assistant 完整消息(含思考、正文、错误或合成响应)
353
+ // 1.1 assistant 完整消息(含思考、正文、工具调用、错误或合成响应)
362
354
  if (type === "assistant") {
363
355
  const msg = event.message;
364
356
  if (msg && Array.isArray(msg.content)) {
@@ -372,6 +364,15 @@ export class ClaudeCodeDriver extends BaseAgentDriver {
372
364
  sink.onTextDelta(block.text);
373
365
  this.turnHadText = true;
374
366
  }
367
+ else if (block.type === "tool_use") {
368
+ const callId = String(block.id ?? `tool_${Date.now()}`);
369
+ if (!this.seenToolStarts.has(callId)) {
370
+ this.seenToolStarts.add(callId);
371
+ const toolName = String(block.name ?? "tool");
372
+ const input = block.input ?? {};
373
+ sink.onToolStart(callId, toolName, input);
374
+ }
375
+ }
375
376
  }
376
377
  }
377
378
  }
@@ -380,6 +381,26 @@ export class ClaudeCodeDriver extends BaseAgentDriver {
380
381
  this.lastErrorHint = errMsg;
381
382
  }
382
383
  }
384
+ // 1.2 user 完整消息(Claude Code 执行工具后将 tool_result 以 user role 反馈)
385
+ if (type === "user") {
386
+ const msg = event.message;
387
+ if (msg && Array.isArray(msg.content)) {
388
+ for (const item of msg.content) {
389
+ if (item && typeof item === "object") {
390
+ const block = item;
391
+ if (block.type === "tool_result") {
392
+ const toolId = String(block.tool_use_id ?? block.id ?? "");
393
+ if (toolId && !this.seenToolEnds.has(toolId)) {
394
+ this.seenToolEnds.add(toolId);
395
+ const content = typeof block.content === "string" ? block.content : JSON.stringify(block.content ?? "");
396
+ const isError = Boolean(block.is_error);
397
+ sink.onToolEnd(toolId, isError ? { error: content } : { output: content });
398
+ }
399
+ }
400
+ }
401
+ }
402
+ }
403
+ }
383
404
  // 2. 流式 Content Block 增量
384
405
  if (type === "content_block_delta") {
385
406
  const delta = event.delta;
@@ -402,24 +423,33 @@ export class ClaudeCodeDriver extends BaseAgentDriver {
402
423
  const block = event.content_block;
403
424
  if (block && block.type === "tool_use") {
404
425
  const callId = String(block.id ?? `tool_${Date.now()}`);
405
- const toolName = String(block.name ?? "tool");
406
- const input = block.input ?? {};
407
- sink.onToolStart(callId, toolName, input);
426
+ if (!this.seenToolStarts.has(callId)) {
427
+ this.seenToolStarts.add(callId);
428
+ const toolName = String(block.name ?? "tool");
429
+ const input = block.input ?? {};
430
+ sink.onToolStart(callId, toolName, input);
431
+ }
408
432
  }
409
433
  }
410
434
  // 4. 工具调用直接触发 (完整块)
411
435
  if (type === "tool_use") {
412
436
  const callId = String(event.id ?? `tool_${Date.now()}`);
413
- const toolName = String(event.name ?? "tool");
414
- const input = event.input ?? {};
415
- sink.onToolStart(callId, toolName, input);
437
+ if (!this.seenToolStarts.has(callId)) {
438
+ this.seenToolStarts.add(callId);
439
+ const toolName = String(event.name ?? "tool");
440
+ const input = event.input ?? {};
441
+ sink.onToolStart(callId, toolName, input);
442
+ }
416
443
  }
417
444
  // 5. 工具执行结果
418
445
  if (type === "tool_result") {
419
446
  const toolId = String(event.tool_use_id ?? event.id ?? "");
420
- const content = typeof event.content === "string" ? event.content : JSON.stringify(event.content ?? "");
421
- const isError = Boolean(event.is_error);
422
- sink.onToolEnd(toolId, isError ? { error: content } : { output: content });
447
+ if (toolId && !this.seenToolEnds.has(toolId)) {
448
+ this.seenToolEnds.add(toolId);
449
+ const content = typeof event.content === "string" ? event.content : JSON.stringify(event.content ?? "");
450
+ const isError = Boolean(event.is_error);
451
+ sink.onToolEnd(toolId, isError ? { error: content } : { output: content });
452
+ }
423
453
  }
424
454
  // 6. 最终完成统计
425
455
  if (type === "result") {
@@ -456,6 +486,40 @@ export class ClaudeCodeDriver extends BaseAgentDriver {
456
486
  sink.onTurnComplete(turnMeta);
457
487
  }
458
488
  }
489
+ /**
490
+ * 构建子进程环境变量。
491
+ * 关键安全防线:原生环境隔离与防封号保障:
492
+ * 1. 若为官方内置 Claude 模型(isOfficial):严禁注入 models.json / auth.json / provider-keys.json
493
+ * 中的任何 BaseURL、API Key 或 Auth Token,保证 100% 保持官方原生环境,完全交由 Claude Code
494
+ * 自身的官方登录态(claude login OAuth 凭据,~/.claude.json)直接与 api.anthropic.com 通信;
495
+ * 2. 仅当用户显式选择第三方自定义 Provider(!isOfficial 且 targetProvider 存在)时,
496
+ * 才动态从配置解析中转 BaseURL 与 Key 注入环境变量。
497
+ */
498
+ buildSpawnEnv(isOfficial, targetProvider) {
499
+ const spawnEnv = {
500
+ ...process.env,
501
+ NO_COLOR: "1",
502
+ };
503
+ if (!isOfficial && targetProvider) {
504
+ const cred = this.agentDir
505
+ ? resolveProviderCredential(this.agentDir, targetProvider)
506
+ : { providerId: targetProvider };
507
+ if (cred.baseUrl) {
508
+ spawnEnv.ANTHROPIC_BASE_URL = cred.baseUrl;
509
+ }
510
+ if (cred.apiKey) {
511
+ spawnEnv.ANTHROPIC_API_KEY = cred.apiKey;
512
+ }
513
+ if (cred.headers) {
514
+ for (const [hk, hv] of Object.entries(cred.headers)) {
515
+ if (hk.toLowerCase() === "authorization" && hv) {
516
+ spawnEnv.ANTHROPIC_AUTH_TOKEN = hv.replace(/^Bearer\s+/i, "");
517
+ }
518
+ }
519
+ }
520
+ }
521
+ return spawnEnv;
522
+ }
459
523
  async abort() {
460
524
  this.turnSeq++;
461
525
  this.aborted = true;
@@ -8,6 +8,7 @@
8
8
  * 4. 无缝复用宿主 FilesService(文件树/预览/SCM/上传)、TerminalManager(终端)与 BgServerTracker(后台服务)。
9
9
  */
10
10
  import { startTurnTiming, finishTurnTiming } from "../turn-timing.js";
11
+ import { normalizeQuickAskSettings } from "../quick-ask-settings.js";
11
12
  import { randomUUID } from "node:crypto";
12
13
  import { existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
13
14
  import { homedir } from "node:os";
@@ -1993,6 +1994,7 @@ export class UniversalSession {
1993
1994
  pushSettings() {
1994
1995
  const s = this.stateStore?.getSettings(this.clientId);
1995
1996
  const settings = {
1997
+ ...normalizeQuickAskSettings(s ?? {}),
1996
1998
  steeringMode: s?.steeringMode ?? "all",
1997
1999
  followUpMode: s?.followUpMode ?? "all",
1998
2000
  promptMode: s?.promptMode ?? "append",
@@ -2016,6 +2018,7 @@ export class UniversalSession {
2016
2018
  retryMaxAttempts: 0,
2017
2019
  softCapTokens: 0,
2018
2020
  softCapByModel: {},
2021
+ autoCompactionInstructions: "",
2019
2022
  questionnaireEnabled: false,
2020
2023
  toolApprovalEnabled: true,
2021
2024
  approvalPolicy: { allowAll: false, categories: [] },
@@ -2223,6 +2226,7 @@ export class UniversalSession {
2223
2226
  retryMaxAttempts: s.retryMaxAttempts,
2224
2227
  softCapTokens: s.softCapTokens,
2225
2228
  softCapByModel: s.softCapByModel,
2229
+ autoCompactionInstructions: s.autoCompactionInstructions ?? "",
2226
2230
  });
2227
2231
  this.stateStore.savePresets(this.clientId, filtered);
2228
2232
  this.pushSettings();