scream-code 0.7.2 → 0.7.4

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.
@@ -556,7 +556,7 @@ const SCREAM_ERROR_INFO = {
556
556
  title: "Compaction failed",
557
557
  retryable: false,
558
558
  public: true,
559
- action: "Inspect logs and consider increasing compaction limits."
559
+ action: "The model returned an empty or invalid compaction summary. Common causes: max output tokens too low, an incompatible model, or a provider/proxy dropping the stream. Try /compact again, switch to a different model, or check your provider configuration."
560
560
  },
561
561
  "compaction.unable": {
562
562
  title: "Unable to compact",
@@ -50067,11 +50067,11 @@ async function generate(provider, systemPrompt, tools, history, callbacks, optio
50067
50067
  await throwIfAborted(options?.signal, stream);
50068
50068
  options?.onStreamEnd?.();
50069
50069
  if (pendingPart !== null) flushPart(message, pendingPart, toolCallIndexMap);
50070
- if (message.content.length === 0 && message.toolCalls.length === 0) throw new APIEmptyResponseError(`The API returned an empty response (no content, no tool calls). Provider: ${provider.name}, model: ${provider.modelName}`);
50070
+ if (message.content.length === 0 && message.toolCalls.length === 0) throw new APIEmptyResponseError(`The API returned an empty response (no content, no tool calls). Provider: ${provider.name}, model: ${provider.modelName}. Common causes: the model's max output tokens are set too low, the model does not support this request format, or the provider/proxy returned an empty stream. Try again, switch models, or check provider settings.`);
50071
50071
  const hasThink = message.content.some((p) => p.type === "think");
50072
50072
  const hasText = message.content.some((p) => p.type === "text" && p.text.trim().length > 0);
50073
50073
  const hasToolCalls = message.toolCalls.length > 0;
50074
- if (hasThink && !hasText && !hasToolCalls) throw new APIEmptyResponseError(`The API returned a response containing only thinking content without any text or tool calls. This usually indicates the stream was interrupted or the output token budget was exhausted during reasoning. Provider: ${provider.name}, model: ${provider.modelName}`);
50074
+ if (hasThink && !hasText && !hasToolCalls) throw new APIEmptyResponseError(`The API returned a response containing only thinking content without any text or tool calls. This usually indicates the stream was interrupted or the output token budget was exhausted during reasoning. Provider: ${provider.name}, model: ${provider.modelName}. If this persists, reduce reasoning effort or switch to a model with a larger output budget.`);
50075
50075
  if (callbacks?.onToolCall !== void 0) for (const toolCall of message.toolCalls) {
50076
50076
  await throwIfAborted(options?.signal, stream);
50077
50077
  await callbacks.onToolCall(toolCall);
@@ -69535,6 +69535,14 @@ const ProviderConfigSchema = z.object({
69535
69535
  env: StringRecordSchema.optional(),
69536
69536
  customHeaders: StringRecordSchema.optional()
69537
69537
  });
69538
+ const ThinkingEffortSchema = z.enum([
69539
+ "off",
69540
+ "low",
69541
+ "medium",
69542
+ "high",
69543
+ "xhigh",
69544
+ "max"
69545
+ ]);
69538
69546
  const ModelAliasSchema = z.object({
69539
69547
  provider: z.string(),
69540
69548
  model: z.string(),
@@ -69543,7 +69551,8 @@ const ModelAliasSchema = z.object({
69543
69551
  capabilities: z.array(z.string()).optional(),
69544
69552
  displayName: z.string().optional(),
69545
69553
  reasoningKey: z.string().optional(),
69546
- adaptiveThinking: z.boolean().optional()
69554
+ adaptiveThinking: z.boolean().optional(),
69555
+ thinkingLevels: z.array(ThinkingEffortSchema).optional()
69547
69556
  });
69548
69557
  const ThinkingConfigSchema = z.object({
69549
69558
  mode: z.enum([
@@ -69647,6 +69656,13 @@ const McpServerConfigSchema = z.preprocess((raw) => {
69647
69656
  };
69648
69657
  return obj;
69649
69658
  }, McpServerConfigDiscriminatedSchema);
69659
+ const SecretEntrySchema = z.object({
69660
+ type: z.enum(["plain", "regex"]),
69661
+ content: z.string().min(1),
69662
+ mode: z.enum(["obfuscate", "replace"]).default("obfuscate"),
69663
+ replacement: z.string().optional(),
69664
+ flags: z.string().optional()
69665
+ });
69650
69666
  const ScreamConfigSchema = z.object({
69651
69667
  providers: z.record(z.string(), ProviderConfigSchema).default({}),
69652
69668
  defaultProvider: z.string().optional(),
@@ -69665,6 +69681,7 @@ const ScreamConfigSchema = z.object({
69665
69681
  extraSkillDirs: z.array(z.string()).optional(),
69666
69682
  loopControl: LoopControlSchema.optional(),
69667
69683
  background: BackgroundConfigSchema.optional(),
69684
+ secrets: z.array(SecretEntrySchema).optional(),
69668
69685
  raw: z.record(z.string(), z.unknown()).optional()
69669
69686
  });
69670
69687
  const ProviderConfigPatchSchema = ProviderConfigSchema.partial();
@@ -69697,7 +69714,8 @@ const ScreamConfigPatchSchema = z.object({
69697
69714
  mergeAllAvailableSkills: z.boolean().optional(),
69698
69715
  extraSkillDirs: z.array(z.string()).optional(),
69699
69716
  loopControl: LoopControlPatchSchema.optional(),
69700
- background: BackgroundConfigPatchSchema.optional()
69717
+ background: BackgroundConfigPatchSchema.optional(),
69718
+ secrets: z.array(SecretEntrySchema).optional()
69701
69719
  }).strict();
69702
69720
  function getDefaultConfig() {
69703
69721
  return { providers: {} };
@@ -71423,6 +71441,25 @@ function makeCarriageReturnsVisible(text) {
71423
71441
  function computeAnchor(text) {
71424
71442
  return createHash("sha256").update(text).digest("hex").slice(0, 8);
71425
71443
  }
71444
+ const entries$1 = /* @__PURE__ */ new Map();
71445
+ function recordFailedEdit(canonicalPath, inputHash) {
71446
+ const prev = entries$1.get(canonicalPath);
71447
+ const count = prev && prev.hash === inputHash ? prev.count + 1 : 1;
71448
+ entries$1.set(canonicalPath, {
71449
+ hash: inputHash,
71450
+ count
71451
+ });
71452
+ return {
71453
+ count,
71454
+ escalate: count >= 3
71455
+ };
71456
+ }
71457
+ function resetNoopLoop(canonicalPath) {
71458
+ entries$1.delete(canonicalPath);
71459
+ }
71460
+ function hashEditPayload(input) {
71461
+ return createHash("sha256").update(JSON.stringify(input)).digest("hex");
71462
+ }
71426
71463
  //#endregion
71427
71464
  //#region ../../packages/agent-core/src/tools/builtin/file/edit.md
71428
71465
  var edit_default = "Perform exact string replacements against the text view returned by Read.\n\n- When copying from Read output, omit the line-number prefix and tab; match only the file content.\n- By default, old_string must occur exactly once. If it matches multiple locations, add surrounding context or set replace_all when every occurrence should change.\n- Prefer Edit for targeted changes to existing files; use Write only for new files or complete overwrites.\n- To modify a file, always use Edit; do not run a Shell `sed` command for edits.\n- When making several independent changes, issue multiple Edit calls in parallel within a single response; edits to the same file are serialized automatically by a write lock.\n- When several parallel Edit calls target the same file, a write lock serializes them; they apply in the order the calls appear in your response. An edit fails with `old_string not found` if its old_string was taken from text an earlier edit already replaced — base every old_string on the latest Read view and order dependent edits accordingly.\n- For pure CRLF files, Read shows LF and Edit.old_string/new_string should use LF; Edit writes the file back with CRLF preserved.\n- For mixed line endings or lone carriage returns, Read displays carriage returns as \\r; include actual \\r escapes in old_string/new_string for those positions.\n- When Read returned an `Anchor:` value in its status block, pass it as `anchor` to verify the file has not changed since it was read. If the anchor does not match, re-read the file before editing.\n- Edit refuses if `old_string` lands inside an unresolved merge conflict block, or if `new_string` would introduce `<<<<<<<`/`=======`/`>>>>>>>` markers. To clean up a conflict, include the markers in `old_string` so Edit replaces them.";
@@ -71478,6 +71515,31 @@ var EditTool = class {
71478
71515
  };
71479
71516
  }
71480
71517
  async execution(args, safePath) {
71518
+ const result = await this.executionCore(args, safePath);
71519
+ const inputHash = hashEditPayload({
71520
+ path: args.path,
71521
+ old_string: args.old_string,
71522
+ new_string: args.new_string,
71523
+ replace_all: args.replace_all,
71524
+ anchor: args.anchor
71525
+ });
71526
+ if (result.isError !== true) {
71527
+ resetNoopLoop(safePath);
71528
+ return result;
71529
+ }
71530
+ const { count, escalate } = recordFailedEdit(safePath, inputHash);
71531
+ if (escalate) return {
71532
+ isError: true,
71533
+ stopTurn: true,
71534
+ output: `Edit to ${args.path} has failed ${String(3)} times in a row with the same payload. The model appears stuck in a loop. Turn stopped. Re-read ${args.path} with the Read tool to observe current content, then issue a different edit.`
71535
+ };
71536
+ if (count >= 2) return {
71537
+ ...result,
71538
+ output: (typeof result.output === "string" ? result.output : "") + `\n\nWarning: attempt ${String(count)} of ${String(3)} with the same payload on ${args.path}. The file may have changed — re-read it before retrying. One more identical failure will stop the turn.`
71539
+ };
71540
+ return result;
71541
+ }
71542
+ async executionCore(args, safePath) {
71481
71543
  if (args.old_string === args.new_string) return {
71482
71544
  isError: true,
71483
71545
  output: "No changes to make: old_string and new_string are exactly the same."
@@ -75232,7 +75294,7 @@ z.object({
75232
75294
  numMatches: z.number().int().nonnegative().optional(),
75233
75295
  appliedLimit: z.number().int().nonnegative().optional()
75234
75296
  });
75235
- const DEFAULT_TIMEOUT_MS = 2e4;
75297
+ const DEFAULT_TIMEOUT_MS$1 = 2e4;
75236
75298
  const SIGTERM_GRACE_MS$1 = 5e3;
75237
75299
  const MAX_OUTPUT_BYTES = 10 * 1024 * 1024;
75238
75300
  const RG_MAX_COLUMNS = 500;
@@ -75335,7 +75397,7 @@ var GrepTool = class {
75335
75397
  if (bufferTruncated || timedOut) stdoutText = omitIncompleteTrailingRecord(stdoutText, mode);
75336
75398
  if (timedOut && stdoutText.trim() === "") return {
75337
75399
  isError: true,
75338
- output: `Grep timed out after ${String(DEFAULT_TIMEOUT_MS / 1e3)}s. Try a more specific path or pattern.`
75400
+ output: `Grep timed out after ${String(DEFAULT_TIMEOUT_MS$1 / 1e3)}s. Try a more specific path or pattern.`
75339
75401
  };
75340
75402
  if (signal.aborted) return {
75341
75403
  isError: true,
@@ -75375,7 +75437,7 @@ var GrepTool = class {
75375
75437
  else messages.push(paginationNotice);
75376
75438
  }
75377
75439
  if (bufferTruncated) messages.push(`[stdout truncated at ${String(MAX_OUTPUT_BYTES)} bytes; incomplete trailing line omitted]`);
75378
- if (timedOut) messages.push(`Grep timed out after ${String(DEFAULT_TIMEOUT_MS / 1e3)}s; partial results returned`);
75440
+ if (timedOut) messages.push(`Grep timed out after ${String(DEFAULT_TIMEOUT_MS$1 / 1e3)}s; partial results returned`);
75379
75441
  const contentIncludesLineNumbers = mode === "content" && args["-n"] !== false;
75380
75442
  const contentBody = limited.map((line) => formatDisplayLine(line, mode, this.workspace.workspaceDir, pathClass, contentIncludesLineNumbers)).join("\n");
75381
75443
  const visibleBody = orderedLines.length === 0 && filteredSensitive.size > 0 ? "No non-sensitive matches found" : contentBody;
@@ -75492,7 +75554,7 @@ async function runRipgrepOnce(jian, rgArgs, signal) {
75492
75554
  const timeoutHandle = setTimeout(() => {
75493
75555
  timedOut = true;
75494
75556
  killProc();
75495
- }, DEFAULT_TIMEOUT_MS);
75557
+ }, DEFAULT_TIMEOUT_MS$1);
75496
75558
  let exitCode = 0;
75497
75559
  let stdoutText = "";
75498
75560
  let stderrText = "";
@@ -77185,10 +77247,10 @@ var WriteTool = class {
77185
77247
  };
77186
77248
  //#endregion
77187
77249
  //#region ../../packages/agent-core/src/tools/builtin/planning/enter-plan-mode.md
77188
- var enter_plan_mode_default = "Use this tool proactively when you're about to start a non-trivial implementation task.\nGetting user sign-off on your approach via ExitPlanMode before writing code prevents wasted effort.\n\nUse it when ANY of these conditions apply:\n\n1. New Feature Implementation - e.g. \"Add a caching layer to the API\"\n2. Multiple Valid Approaches - e.g. \"Optimize database queries\" (indexing vs rewrite vs caching)\n3. Code Modifications - e.g. \"Refactor auth module to support OAuth\"\n4. Architectural Decisions - e.g. \"Add WebSocket support\"\n5. Multi-File Changes - involves more than 2-3 files\n6. Unclear Requirements - need exploration to understand scope\n7. User Preferences Matter - if user input would materially change the implementation approach, use EnterPlanMode to structure the decision\n\nPermission mode notes:\n- EnterPlanMode enters plan mode automatically without an approval prompt in all permission modes.\n- In yolo and manual modes, ExitPlanMode still presents the plan to the user for approval.\n- In auto permission mode, do not use AskUserQuestion; make the best decision from available context.\n- In auto permission mode, ExitPlanMode exits plan mode without asking the user.\n- Use EnterPlanMode only when planning itself adds value.\n\nWhen NOT to use:\n- Single-line or few-line fixes (typos, obvious bugs, small tweaks)\n- User gave very specific, detailed instructions\n- Pure research/exploration tasks\n\n## What Happens in Plan Mode\nIn plan mode, you will:\n1. Identify 2-3 key questions about the codebase that are critical to your plan. If you are not confident about the codebase structure or relevant code paths, use `Agent(subagent_type=\"explore\")` to investigate these questions first - this is strongly recommended for non-trivial tasks.\n2. Explore the codebase using Glob, Grep, Read, and other read-only tools for any remaining quick lookups. Use Bash only when needed; Bash follows the normal permission mode and rules.\n3. Design an implementation approach based on your findings\n4. Write your plan to the current plan file with Write or Edit\n5. Present your plan to the user via ExitPlanMode for approval\n";
77250
+ var enter_plan_mode_default = "Use this tool proactively when you're about to start a non-trivial implementation task.\nGetting user sign-off on your approach via ExitPlanMode before writing code prevents wasted effort.\n\n## Planning Modes\n\nThe host supports two planning strategies. You can request either one via this tool:\n\n- **Normal plan** (default): You investigate the codebase, design a single implementation approach, write it to the plan file, and present it for approval. Best when the task is straightforward or you are already confident about the right approach.\n- **Fusion plan**: The host spawns multiple independent planning subagents in parallel, each exploring a different angle, then synthesizes their outputs into one consolidated plan. Best when the task is ambiguous, has many valid approaches, crosses many files, or when exploration itself adds significant value. Fusion plan may take longer but tends to surface risks and alternatives you might miss.\n\nTo request a fusion plan, include `mode: 'fusion'` in your tool arguments. If you omit `mode` or set it to `normal`, the host uses the normal plan flow.\n\n### When to choose which mode\n\nPrefer **normal plan** when:\n1. The user gave specific, detailed instructions.\n2. The change is small or localized (1-3 files, single concern).\n3. You are confident about the codebase structure and the right approach.\n4. Speed matters more than exploring alternatives.\n\nPrefer **fusion plan** when:\n1. The task is open-ended or ambiguous (e.g. \"improve performance\", \"refactor auth\").\n2. Multiple valid architectures or approaches exist.\n3. The change spans more than 3-5 files or touches core abstractions.\n4. You are unfamiliar with the relevant code paths and want parallel exploration.\n5. The user explicitly asked for a thorough plan or mentioned comparing options.\n\nIf unsure, choose normal plan for small fixes and fusion plan for larger design tasks.\n\n## When to Use\n\nUse this tool when ANY of these conditions apply:\n\n1. New Feature Implementation - e.g. \"Add a caching layer to the API\"\n2. Multiple Valid Approaches - e.g. \"Optimize database queries\" (indexing vs rewrite vs caching)\n3. Code Modifications - e.g. \"Refactor auth module to support OAuth\"\n4. Architectural Decisions - e.g. \"Add WebSocket support\"\n5. Multi-File Changes - involves more than 2-3 files\n6. Unclear Requirements - need exploration to understand scope\n7. User Preferences Matter - if user input would materially change the implementation approach, use EnterPlanMode to structure the decision\n\nPermission mode notes:\n- EnterPlanMode enters plan mode automatically without an approval prompt in all permission modes.\n- In yolo and manual modes, ExitPlanMode still presents the plan to the user for approval.\n- In auto permission mode, do not use AskUserQuestion; make the best decision from available context.\n- In auto permission mode, ExitPlanMode exits plan mode without asking the user.\n- Use EnterPlanMode only when planning itself adds value.\n\nWhen NOT to use:\n- Single-line or few-line fixes (typos, obvious bugs, small tweaks)\n- User gave very specific, detailed instructions\n- Pure research/exploration tasks\n\n## What Happens in Plan Mode\nIn plan mode, you will:\n1. Identify 2-3 key questions about the codebase that are critical to your plan. If you are not confident about the codebase structure or relevant code paths, use `Agent(subagent_type=\"explore\")` to investigate these questions first - this is strongly recommended for non-trivial tasks.\n2. Explore the codebase using Glob, Grep, Read, and other read-only tools for any remaining quick lookups. Use Bash only when needed; Bash follows the normal permission mode and rules.\n3. Design an implementation approach based on your findings (or, for fusion plan, review the synthesized plan the host provides).\n4. Write the plan to the current plan file with Write or Edit.\n5. Present your plan to the user via ExitPlanMode for approval\n\nFor fusion plan, the host performs the parallel exploration and synthesis for you; you should still review the result, fill in any gaps, and ensure it matches the user's intent before exiting plan mode.\n";
77189
77251
  //#endregion
77190
77252
  //#region ../../packages/agent-core/src/tools/builtin/planning/enter-plan-mode.ts
77191
- const EnterPlanModeInputSchema = z.object({}).strict();
77253
+ const EnterPlanModeInputSchema = z.object({ mode: z.enum(["normal", "fusion"]).default("normal").describe("Planning strategy. 'normal' (default): you design the plan. 'fusion': the host spawns parallel planning subagents and synthesizes a single plan for you to review. Use 'fusion' for ambiguous, large, or multi-approach tasks.") }).strict();
77192
77254
  var EnterPlanModeTool = class {
77193
77255
  agent;
77194
77256
  name = "EnterPlanMode";
@@ -77207,7 +77269,7 @@ var EnterPlanModeTool = class {
77207
77269
  output: "Plan mode is already active. Use ExitPlanMode when the plan is ready."
77208
77270
  };
77209
77271
  try {
77210
- await this.agent.planMode.enter();
77272
+ await this.agent.planMode.enter(void 0, false, true, _args.mode);
77211
77273
  } catch (error) {
77212
77274
  return {
77213
77275
  isError: true,
@@ -78766,10 +78828,10 @@ var FullCompaction = class {
78766
78828
  async compactionWorker(signal, data, compactedCount) {
78767
78829
  const originalHistory = [...this.agent.context.history];
78768
78830
  const tokensBefore = estimateTokensForMessages(originalHistory);
78831
+ const model = this.agent.config.model;
78769
78832
  let retryCount = 0;
78770
78833
  try {
78771
78834
  await this.triggerPreCompactHook(data, tokensBefore, signal);
78772
- const model = this.agent.config.model;
78773
78835
  const delays = retryBackoffDelays(5);
78774
78836
  let usage;
78775
78837
  let summary;
@@ -78788,8 +78850,7 @@ var FullCompaction = class {
78788
78850
  const response = await this.agent.generate(this.agent.config.provider, COMPACTION_SYSTEM_PROMPT, [], messages, void 0, { signal });
78789
78851
  if (response.finishReason === "truncated") throw new TruncatedError();
78790
78852
  usage = response.usage;
78791
- summary = extractCompactionSummary(response);
78792
- summary = this.postProcessSummary(summary);
78853
+ summary = extractCompactionSummary(response, model);
78793
78854
  break;
78794
78855
  } catch (error) {
78795
78856
  if (error instanceof APIContextOverflowError || error instanceof TruncatedError) compactedCount = this.strategy.reduceCompactOnOverflow(messagesToCompact);
@@ -78836,11 +78897,19 @@ var FullCompaction = class {
78836
78897
  });
78837
78898
  this.agent.log.error("compaction failed", {
78838
78899
  code: isScreamError(error) ? error.code : void 0,
78839
- error
78900
+ error,
78901
+ model,
78902
+ retryCount,
78903
+ compactedCount,
78904
+ tokensBefore
78840
78905
  });
78841
78906
  this.markCanceled();
78842
78907
  if (!blockedByTurn) {
78843
- const payload = isScreamError(error) && error.code === ErrorCodes.AUTH_LOGIN_REQUIRED ? toScreamErrorPayload(error) : makeErrorPayload(ErrorCodes.COMPACTION_FAILED, String(error));
78908
+ const details = {
78909
+ model,
78910
+ retryCount
78911
+ };
78912
+ const payload = isScreamError(error) && error.code === ErrorCodes.AUTH_LOGIN_REQUIRED ? toScreamErrorPayload(error) : makeErrorPayload(ErrorCodes.COMPACTION_FAILED, String(error), { details });
78844
78913
  this.agent.emitEvent({
78845
78914
  type: "error",
78846
78915
  ...payload
@@ -78921,9 +78990,9 @@ var FullCompaction = class {
78921
78990
  return `${summary.trim()}\n\n${todoMarkdown}`;
78922
78991
  }
78923
78992
  };
78924
- function extractCompactionSummary(response) {
78993
+ function extractCompactionSummary(response, model) {
78925
78994
  const summary = typeof response.message.content === "string" ? response.message.content : response.message.content.map((part) => part.type === "text" ? part.text : "").join("");
78926
- if (summary.trim().length === 0) throw new APIEmptyResponseError("The compaction response did not contain a non-empty summary.");
78995
+ if (summary.trim().length === 0) throw new APIEmptyResponseError(`The compaction response did not contain a non-empty summary. Model "${model}" returned empty content. Common causes: output token limit set too low, an incompatible model, or a provider/proxy that dropped the stream. Try /compact again, switch models, or check your provider configuration.`);
78927
78996
  return summary;
78928
78997
  }
78929
78998
  const COMPACTION_INSTRUCTION = (customInstruction = "") => renderPrompt(compaction_instruction_default, { customInstruction });
@@ -82415,17 +82484,19 @@ var PlanMode = class {
82415
82484
  _isActive = false;
82416
82485
  _planId = null;
82417
82486
  _planFilePath = null;
82487
+ _strategy = "normal";
82418
82488
  constructor(agent) {
82419
82489
  this.agent = agent;
82420
82490
  }
82421
82491
  createPlanId() {
82422
82492
  return generateHeroSlug(randomUUID(), /* @__PURE__ */ new Set());
82423
82493
  }
82424
- async enter(id = this.createPlanId(), createFile = false, emitStatus = true) {
82494
+ async enter(id = this.createPlanId(), createFile = false, emitStatus = true, strategy = "normal") {
82425
82495
  if (this._isActive) throw new Error("Already in plan mode");
82426
82496
  this._isActive = true;
82427
82497
  this._planId = id;
82428
82498
  this._planFilePath = null;
82499
+ this._strategy = strategy;
82429
82500
  let enterRecorded = false;
82430
82501
  try {
82431
82502
  const planFilePath = this.planFilePathFor(id);
@@ -82433,7 +82504,8 @@ var PlanMode = class {
82433
82504
  await this.ensurePlanDirectory(planFilePath);
82434
82505
  this.agent.records.logRecord({
82435
82506
  type: "plan_mode.enter",
82436
- id
82507
+ id,
82508
+ strategy
82437
82509
  });
82438
82510
  enterRecorded = true;
82439
82511
  if (createFile) await this.writeEmptyPlanFile(planFilePath);
@@ -82443,19 +82515,22 @@ var PlanMode = class {
82443
82515
  this._isActive = false;
82444
82516
  this._planId = null;
82445
82517
  this._planFilePath = null;
82518
+ this._strategy = "normal";
82446
82519
  }
82447
82520
  throw error;
82448
82521
  }
82449
82522
  if (emitStatus) this.agent.emitStatusUpdated();
82450
82523
  }
82451
- restoreEnter({ id }) {
82524
+ restoreEnter({ id, strategy }) {
82452
82525
  this.agent.replayBuilder.push({
82453
82526
  type: "plan_updated",
82454
- enabled: true
82527
+ enabled: true,
82528
+ strategy
82455
82529
  });
82456
82530
  this._isActive = true;
82457
82531
  this._planId = id;
82458
82532
  this._planFilePath = this.planFilePathFor(id);
82533
+ this._strategy = strategy ?? "normal";
82459
82534
  }
82460
82535
  cancel(id) {
82461
82536
  this.agent.records.logRecord({
@@ -82469,6 +82544,7 @@ var PlanMode = class {
82469
82544
  this._isActive = false;
82470
82545
  this._planId = null;
82471
82546
  this._planFilePath = null;
82547
+ this._strategy = "normal";
82472
82548
  this.agent.emitStatusUpdated();
82473
82549
  }
82474
82550
  async clear() {
@@ -82487,6 +82563,7 @@ var PlanMode = class {
82487
82563
  this._isActive = false;
82488
82564
  this._planId = null;
82489
82565
  this._planFilePath = null;
82566
+ this._strategy = "normal";
82490
82567
  this.agent.emitStatusUpdated();
82491
82568
  }
82492
82569
  get isActive() {
@@ -82495,6 +82572,9 @@ var PlanMode = class {
82495
82572
  get planFilePath() {
82496
82573
  return this._planFilePath;
82497
82574
  }
82575
+ get strategy() {
82576
+ return this._strategy;
82577
+ }
82498
82578
  async data() {
82499
82579
  if (!this._planId || !this._planFilePath) return null;
82500
82580
  let content = "";
@@ -82528,6 +82608,286 @@ function isMissingFileError(error) {
82528
82608
  return error.code === "ENOENT";
82529
82609
  }
82530
82610
  //#endregion
82611
+ //#region ../../packages/agent-core/src/agent/secrets.ts
82612
+ const PLACEHOLDER_ALPHABET = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
82613
+ const PLACEHOLDER_LENGTH = 6;
82614
+ const PLACEHOLDER_RE = /#[A-Z2-9]{6}#/g;
82615
+ function compileSecretRegex(pattern, flags) {
82616
+ let resolvedPattern = pattern;
82617
+ let resolvedFlags = flags ?? "";
82618
+ const literalMatch = /^\/((?:[^\\/]|\\.)*)\/([ gimsuy]*)$/.exec(pattern);
82619
+ if (literalMatch) {
82620
+ if (literalMatch[1] !== void 0) resolvedPattern = literalMatch[1];
82621
+ if (literalMatch[2] !== void 0) {
82622
+ const combined = new Set(Array.from(resolvedFlags).concat(Array.from(literalMatch[2])));
82623
+ resolvedFlags = Array.from(combined).join("");
82624
+ }
82625
+ }
82626
+ if (!resolvedFlags.includes("g")) resolvedFlags += "g";
82627
+ return new RegExp(resolvedPattern, resolvedFlags);
82628
+ }
82629
+ function replaceAll(text, search, replacement) {
82630
+ if (search.length === 0) return text;
82631
+ return text.split(search).join(replacement);
82632
+ }
82633
+ function buildPlaceholder(secret, salt) {
82634
+ const hash = createHash("sha256").update(`${salt}:${secret}`).digest();
82635
+ let s = "#";
82636
+ for (let i = 0; i < PLACEHOLDER_LENGTH; i++) {
82637
+ const byte = hash[i] ?? 0;
82638
+ s += PLACEHOLDER_ALPHABET[byte % 32];
82639
+ }
82640
+ return s + "#";
82641
+ }
82642
+ function buildReplaceMarker(secret, salt) {
82643
+ const hash = createHash("sha256").update(`replace:${salt}:${secret}`).digest();
82644
+ let s = "[REDACTED-";
82645
+ for (let i = 0; i < 4; i++) {
82646
+ const byte = hash[i] ?? 0;
82647
+ s += PLACEHOLDER_ALPHABET[byte % 32];
82648
+ }
82649
+ return s + "]";
82650
+ }
82651
+ var SecretObfuscator = class {
82652
+ plainObfuscate = /* @__PURE__ */ new Map();
82653
+ plainReplace = /* @__PURE__ */ new Map();
82654
+ regexEntries = [];
82655
+ placeholderToSecret = /* @__PURE__ */ new Map();
82656
+ secretToPlaceholder = /* @__PURE__ */ new Map();
82657
+ hasAny;
82658
+ constructor(entries) {
82659
+ let hasReal = false;
82660
+ for (const entry of entries) {
82661
+ const mode = entry.mode ?? "obfuscate";
82662
+ if (entry.type === "plain") if (mode === "obfuscate") {
82663
+ if (entry.content.length < 8) continue;
82664
+ const placeholder = buildPlaceholder(entry.content, "plain");
82665
+ this.plainObfuscate.set(entry.content, placeholder);
82666
+ this.placeholderToSecret.set(placeholder, entry.content);
82667
+ this.secretToPlaceholder.set(entry.content, placeholder);
82668
+ hasReal = true;
82669
+ } else {
82670
+ const replacement = entry.replacement ?? buildReplaceMarker(entry.content, "plain");
82671
+ this.plainReplace.set(entry.content, replacement);
82672
+ hasReal = true;
82673
+ }
82674
+ else try {
82675
+ const regex = compileSecretRegex(entry.content, entry.flags);
82676
+ this.regexEntries.push({
82677
+ regex,
82678
+ mode,
82679
+ replacement: entry.replacement,
82680
+ salt: entry.content
82681
+ });
82682
+ hasReal = true;
82683
+ } catch {}
82684
+ }
82685
+ this.hasAny = hasReal;
82686
+ }
82687
+ placeholderFor(secret, salt) {
82688
+ const existing = this.secretToPlaceholder.get(secret);
82689
+ if (existing !== void 0) return existing;
82690
+ let placeholder = buildPlaceholder(secret, salt);
82691
+ if (this.placeholderToSecret.has(placeholder)) placeholder = buildPlaceholder(secret, `${salt}:alt`);
82692
+ this.secretToPlaceholder.set(secret, placeholder);
82693
+ this.placeholderToSecret.set(placeholder, secret);
82694
+ return placeholder;
82695
+ }
82696
+ hasSecrets() {
82697
+ return this.hasAny;
82698
+ }
82699
+ obfuscate(text) {
82700
+ if (!this.hasAny) return text;
82701
+ let result = text;
82702
+ const replaceSorted = [...this.plainReplace.entries()].toSorted((a, b) => b[0].length - a[0].length);
82703
+ for (const [secret, replacement] of replaceSorted) result = replaceAll(result, secret, replacement);
82704
+ const obfuscateSorted = [...this.plainObfuscate.entries()].toSorted((a, b) => b[0].length - a[0].length);
82705
+ for (const [secret, placeholder] of obfuscateSorted) result = replaceAll(result, secret, placeholder);
82706
+ for (const entry of this.regexEntries) {
82707
+ entry.regex.lastIndex = 0;
82708
+ const matches = /* @__PURE__ */ new Set();
82709
+ for (;;) {
82710
+ const match = entry.regex.exec(result);
82711
+ if (match === null) break;
82712
+ if (match[0].length === 0) {
82713
+ entry.regex.lastIndex++;
82714
+ continue;
82715
+ }
82716
+ matches.add(match[0]);
82717
+ }
82718
+ for (const matchValue of matches) if (entry.mode === "replace") {
82719
+ const replacement = entry.replacement ?? buildReplaceMarker(matchValue, entry.salt);
82720
+ result = replaceAll(result, matchValue, replacement);
82721
+ } else {
82722
+ if (matchValue.length < 8) continue;
82723
+ const placeholder = this.placeholderFor(matchValue, entry.salt);
82724
+ result = replaceAll(result, matchValue, placeholder);
82725
+ }
82726
+ }
82727
+ return result;
82728
+ }
82729
+ deobfuscate(text) {
82730
+ if (!this.hasAny || !text.includes("#")) return text;
82731
+ return text.replaceAll(PLACEHOLDER_RE, (match) => this.placeholderToSecret.get(match) ?? match);
82732
+ }
82733
+ deobfuscateJsonString(jsonStr) {
82734
+ if (jsonStr === null) return null;
82735
+ if (!this.hasAny || !jsonStr.includes("#")) return jsonStr;
82736
+ let parsed;
82737
+ try {
82738
+ parsed = JSON.parse(jsonStr);
82739
+ } catch {
82740
+ return this.deobfuscate(jsonStr);
82741
+ }
82742
+ const walked = mapJsonStrings(parsed, (s) => this.deobfuscate(s));
82743
+ return JSON.stringify(walked);
82744
+ }
82745
+ obfuscateJsonString(jsonStr) {
82746
+ if (jsonStr === null) return null;
82747
+ if (!this.hasAny) return jsonStr;
82748
+ let parsed;
82749
+ try {
82750
+ parsed = JSON.parse(jsonStr);
82751
+ } catch {
82752
+ return this.obfuscate(jsonStr);
82753
+ }
82754
+ const walked = mapJsonStrings(parsed, (s) => this.obfuscate(s));
82755
+ return JSON.stringify(walked);
82756
+ }
82757
+ };
82758
+ function mapJsonStrings(value, fn) {
82759
+ if (typeof value === "string") return fn(value);
82760
+ if (Array.isArray(value)) {
82761
+ let changed = false;
82762
+ const out = value.map((item) => {
82763
+ const next = mapJsonStrings(item, fn);
82764
+ if (next !== item) changed = true;
82765
+ return next;
82766
+ });
82767
+ return changed ? out : value;
82768
+ }
82769
+ if (value !== null && typeof value === "object") {
82770
+ let changed = false;
82771
+ const out = {};
82772
+ for (const key of Object.keys(value)) {
82773
+ const item = value[key];
82774
+ if (item === void 0) continue;
82775
+ const next = mapJsonStrings(item, fn);
82776
+ if (next !== item) changed = true;
82777
+ out[key] = next;
82778
+ }
82779
+ return changed ? out : value;
82780
+ }
82781
+ return value;
82782
+ }
82783
+ function obfuscateMessages(obf, messages) {
82784
+ if (!obf.hasSecrets()) return [...messages];
82785
+ let changed = false;
82786
+ const result = messages.map((message) => {
82787
+ let localChanged = false;
82788
+ const content = message.content.map((part) => {
82789
+ if (part.type === "text") {
82790
+ const text = obf.obfuscate(part.text);
82791
+ if (text === part.text) return part;
82792
+ localChanged = true;
82793
+ return {
82794
+ ...part,
82795
+ text
82796
+ };
82797
+ }
82798
+ if (part.type === "think") {
82799
+ const think = obf.obfuscate(part.think);
82800
+ if (think === part.think) return part;
82801
+ localChanged = true;
82802
+ return {
82803
+ ...part,
82804
+ think
82805
+ };
82806
+ }
82807
+ return part;
82808
+ });
82809
+ let toolCalls = message.toolCalls;
82810
+ if (message.role === "assistant" && message.toolCalls.length > 0) {
82811
+ let tcChanged = false;
82812
+ toolCalls = message.toolCalls.map((call) => {
82813
+ if (call.arguments === null) return call;
82814
+ const obfuscated = obf.obfuscateJsonString(call.arguments);
82815
+ if (obfuscated === call.arguments) return call;
82816
+ tcChanged = true;
82817
+ return {
82818
+ ...call,
82819
+ arguments: obfuscated
82820
+ };
82821
+ });
82822
+ if (tcChanged) localChanged = true;
82823
+ }
82824
+ if (!localChanged) return message;
82825
+ changed = true;
82826
+ return {
82827
+ ...message,
82828
+ content,
82829
+ toolCalls
82830
+ };
82831
+ });
82832
+ return changed ? result : [...messages];
82833
+ }
82834
+ function deobfuscateToolCalls(obf, toolCalls) {
82835
+ if (!obf.hasSecrets()) return [...toolCalls];
82836
+ let changed = false;
82837
+ const result = toolCalls.map((call) => {
82838
+ const args = obf.deobfuscateJsonString(call.arguments);
82839
+ if (args === call.arguments) return call;
82840
+ changed = true;
82841
+ return {
82842
+ ...call,
82843
+ arguments: args
82844
+ };
82845
+ });
82846
+ return changed ? result : [...toolCalls];
82847
+ }
82848
+ const DEFAULT_SECRET_PATTERNS = [
82849
+ {
82850
+ type: "regex",
82851
+ content: "AKIA[0-9A-Z]{16}",
82852
+ mode: "obfuscate"
82853
+ },
82854
+ {
82855
+ type: "regex",
82856
+ content: "ghp_[A-Za-z0-9]{36}",
82857
+ mode: "obfuscate"
82858
+ },
82859
+ {
82860
+ type: "regex",
82861
+ content: "gho_[A-Za-z0-9]{36}",
82862
+ mode: "obfuscate"
82863
+ },
82864
+ {
82865
+ type: "regex",
82866
+ content: "ghs_[A-Za-z0-9]{36}",
82867
+ mode: "obfuscate"
82868
+ },
82869
+ {
82870
+ type: "regex",
82871
+ content: "sk-proj-[A-Za-z0-9\\-_]{20,}",
82872
+ mode: "obfuscate"
82873
+ },
82874
+ {
82875
+ type: "regex",
82876
+ content: "sk-[A-Za-z0-9]{48}",
82877
+ mode: "obfuscate"
82878
+ },
82879
+ {
82880
+ type: "regex",
82881
+ content: "sk-ant-[A-Za-z0-9\\-_]{20,}",
82882
+ mode: "obfuscate"
82883
+ },
82884
+ {
82885
+ type: "regex",
82886
+ content: "(api[_-]?key|apikey|token|secret)[\"'\\s:=]+[\"']?([A-Za-z0-9\\-_]{20,})",
82887
+ mode: "obfuscate"
82888
+ }
82889
+ ];
82890
+ //#endregion
82531
82891
  //#region ../../packages/agent-core/src/agent/wolfpack/index.ts
82532
82892
  var WolfPackMode = class {
82533
82893
  agent;
@@ -83296,7 +83656,10 @@ function restoreAgentRecord(agent, input) {
83296
83656
  agent.fullCompaction.markCompleted();
83297
83657
  return;
83298
83658
  case "plan_mode.enter":
83299
- agent.planMode.restoreEnter(input);
83659
+ agent.planMode.restoreEnter({
83660
+ id: input.id,
83661
+ strategy: input.strategy
83662
+ });
83300
83663
  return;
83301
83664
  case "plan_mode.cancel":
83302
83665
  agent.planMode.cancel(input.id);
@@ -95668,17 +96031,46 @@ const RawAgentProfileSchema = z.object({
95668
96031
  subagents: z.record(z.string(), RawSubagentProfileSchema).optional()
95669
96032
  });
95670
96033
  //#endregion
96034
+ //#region ../../packages/agent-core/src/config/path.ts
96035
+ function resolveScreamHome(homeDir) {
96036
+ return homeDir ?? process.env["SCREAM_CODE_HOME"] ?? join$1(homedir(), ".scream-code");
96037
+ }
96038
+ function resolveConfigPath$1(input) {
96039
+ return input.configPath ?? join$1(resolveScreamHome(input.homeDir), "config.toml");
96040
+ }
96041
+ function ensureScreamHome(homeDir) {
96042
+ mkdirSync(homeDir, {
96043
+ recursive: true,
96044
+ mode: 448
96045
+ });
96046
+ }
96047
+ //#endregion
95671
96048
  //#region ../../packages/agent-core/src/profile/context.ts
95672
96049
  const AGENTS_MD_MAX_BYTES = 32 * 1024;
95673
96050
  const S_IFMT = 61440;
95674
96051
  const S_IFREG = 32768;
95675
96052
  async function prepareSystemPromptContext(jian) {
95676
- const [cwdListing, agentsMd] = await Promise.all([listDirectory(jian), loadAgentsMd(jian)]);
96053
+ const [cwdListing, agentsMd, roleAdditional] = await Promise.all([
96054
+ listDirectory(jian),
96055
+ loadAgentsMd(jian),
96056
+ loadRoleAdditional(jian)
96057
+ ]);
95677
96058
  return {
95678
96059
  cwdListing,
95679
- agentsMd
96060
+ agentsMd,
96061
+ roleAdditional
95680
96062
  };
95681
96063
  }
96064
+ async function loadRoleAdditional(_jian) {
96065
+ const prefsPath = join$1(resolveScreamHome(), "user-prefs.md");
96066
+ if (!await pathExists(_jian, prefsPath)) return;
96067
+ try {
96068
+ const trimmed = (await _jian.readText(prefsPath)).trim();
96069
+ return trimmed.length > 0 ? trimmed : void 0;
96070
+ } catch {
96071
+ return;
96072
+ }
96073
+ }
95682
96074
  async function loadAgentsMd(jian) {
95683
96075
  const workDir = jian.getcwd();
95684
96076
  const dirs = dirsRootToLeaf(jian, workDir, await findProjectRoot(jian, workDir));
@@ -95768,7 +96160,7 @@ function renderAgentFiles(files) {
95768
96160
  continue;
95769
96161
  }
95770
96162
  let content = file.content;
95771
- if (byteLength(content) > remaining) content = truncateUtf8(content, remaining).trim();
96163
+ if (byteLength(content) > remaining) content = truncateUtf8$1(content, remaining).trim();
95772
96164
  remaining -= byteLength(content);
95773
96165
  budgeted[i] = {
95774
96166
  path: file.path,
@@ -95777,7 +96169,7 @@ function renderAgentFiles(files) {
95777
96169
  }
95778
96170
  return budgeted.filter((file) => file !== void 0 && file.content.length > 0).map((file) => `${annotationFor(file.path)}${file.content}`).join("\n\n");
95779
96171
  }
95780
- function truncateUtf8(text, maxBytes) {
96172
+ function truncateUtf8$1(text, maxBytes) {
95781
96173
  let result = text;
95782
96174
  while (byteLength(result) > maxBytes) result = result.slice(0, -1);
95783
96175
  return result;
@@ -95885,9 +96277,16 @@ function buildTemplateVars(context, promptVars) {
95885
96277
  SCREAM_AGENTS_MD: context.agentsMd ?? "",
95886
96278
  SCREAM_SKILLS: skills,
95887
96279
  SCREAM_ADDITIONAL_DIRS_INFO: context.additionalDirsInfo ?? "",
95888
- ROLE_ADDITIONAL: context.roleAdditional ?? promptVars["ROLE_ADDITIONAL"] ?? promptVars["roleAdditional"] ?? ""
96280
+ ROLE_ADDITIONAL: mergeRoleAdditional(context.roleAdditional, promptVars)
95889
96281
  };
95890
96282
  }
96283
+ function mergeRoleAdditional(contextValue, promptVars) {
96284
+ const userPrefs = contextValue?.trim() ?? "";
96285
+ const profileAdditional = promptVars["ROLE_ADDITIONAL"]?.trim() ?? promptVars["roleAdditional"]?.trim() ?? "";
96286
+ if (userPrefs.length === 0) return profileAdditional;
96287
+ if (profileAdditional.length === 0) return userPrefs;
96288
+ return `${userPrefs}\n\n${profileAdditional}`;
96289
+ }
95891
96290
  function applySubagentDescriptions(mergedProfiles, resolvedProfiles) {
95892
96291
  for (const [ownerName, owner] of mergedProfiles) {
95893
96292
  if (owner.subagents === void 0) continue;
@@ -95976,7 +96375,7 @@ const PROFILE_SOURCES = {
95976
96375
  "profile/default/oracle.yaml": "extends: agent\nname: oracle\npromptVars:\n roleAdditional: |\n You are now running as a sub-agent. All `user` messages are sent by the main agent.\n You are the Oracle sub-agent. Your role is deep debugging, architecture decisions,\n and second opinions.\n\n # Behavior\n\n - Investigate root causes, not symptoms.\n - Ask clarifying questions only when the premise is genuinely ambiguous.\n - Return concise, evidence-based conclusions with concrete file paths and line numbers.\n - Do NOT implement fixes unless explicitly asked to do so.\n - Do NOT run project-wide verification, lint, or format unless explicitly asked.\n - Do NOT ask the end user questions.\n\n # Output format\n\n When the task is complete, return:\n 1. A one-sentence verdict.\n 2. The key evidence (file paths, line numbers, command output, or URLs).\n 3. The recommended next step for the parent agent.\nwhenToUse: |\n Use when the main agent is stuck on a complex bug, needs an architecture trade-off,\n or wants a second opinion before a risky change.\ntools:\n - Bash\n - Read\n - ReadMediaFile\n - Glob\n - Grep\n - Write\n - Edit\n - WebSearch\n - FetchURL\n - MemoryLookup\n - MemoryConsolidatePlan\n - MemoryConsolidateApply\n - mcp__*\n",
95977
96376
  "profile/default/plan.yaml": "extends: agent\nname: plan\npromptVars:\n roleAdditional: |\n You are now running as a subagent. All the `user` messages are sent by the main agent. The main agent cannot see your context, it can only see your last message when you finish the task. You must treat the parent agent as your caller. Do not directly ask the end user questions. If something is unclear, explain the ambiguity in your final summary to the parent agent.\n\n Before designing your implementation plan, consider whether you fully understand the codebase areas relevant to the task. If not, recommend the parent agent to use the explore agent (subagent_type=\"explore\") to investigate key questions first. In your response, clearly state:\n 1. What you already know from the information provided\n 2. What questions remain unanswered that would benefit from explore agent investigation\n 3. Your implementation plan (either preliminary if questions remain, or final if sufficient context exists)\nwhenToUse: |\n Use this agent when the parent agent needs a step-by-step implementation plan, key file identification, and architectural trade-off analysis before code changes are made.\ntools:\n - Read\n - ReadMediaFile\n - Glob\n - Grep\n - WebSearch\n - MemoryLookup\n - MemoryConsolidatePlan\n - MemoryConsolidateApply\n - FetchURL\n",
95978
96377
  "profile/default/reviewer.yaml": "extends: agent\nname: reviewer\npromptVars:\n roleAdditional: |\n You are now running as a subagent. All the `user` messages are sent by the main agent. The main agent cannot see your context, it can only see your last message when you finish the task. You must treat the parent agent as your caller. Do not directly ask the end user questions. If something is unclear, explain the ambiguity in your final summary to the parent agent.\n\n You are a code review specialist. Your job is to identify bugs the author would want fixed before merge.\n\n # Procedure\n\n 1. Run `git diff`, `jj diff --git`, or read modified files to view the patch.\n 2. Read modified files for full context.\n 3. Call `ReportFinding` for each issue you identify.\n 4. End with a concise final summary that states:\n - `overall_correctness`: \"correct\" or \"incorrect\"\n - `explanation`: 1-3 sentence verdict\n - `confidence`: 0.0-1.0\n\n You NEVER make file edits or trigger builds. Bash is read-only: `git diff`, `git log`, `git show`, `jj diff --git`.\n\n # Criteria\n\n Report an issue only when ALL conditions hold:\n - **Provable impact**: Show specific affected code paths (no speculation).\n - **Actionable**: Discrete fix, not vague \"consider improving X\".\n - **Unintentional**: Clearly not a deliberate design choice.\n - **Introduced in patch**: Do not flag pre-existing bugs unless asked.\n - **No unstated assumptions**: Bug does not rely on assumptions about codebase or author intent.\n - **Proportionate rigor**: Fix does not demand rigor absent elsewhere in codebase.\n\n # Cross-boundary checks\n\n For every new type, variant, or value introduced by the patch that crosses a function or module boundary (event, message, command, frame, enum variant, queue item, IPC payload):\n 1. Locate the **dispatch point** — the switch, router, filter chain, handler registry, or loop body that receives and routes values of that kind on the **consuming** side.\n 2. Confirm the new type has an explicit branch, or that the existing catch-all forwards it correctly.\n 3. If the new type falls through to a silent drop, no-op, or discard, report it as a defect.\n\n # Priority levels\n\n | Level | Criteria | Example |\n |-------|----------|---------|\n | P0 | Blocks release/operations; universal (no input assumptions) | Data corruption, auth bypass |\n | P1 | High; fix next cycle | Race condition under load |\n | P2 | Medium; fix eventually | Edge case mishandling |\n | P3 | Info; nice to have | Suboptimal but correct |\n\n # Output\n\n Each `ReportFinding` requires:\n - `title`: Imperative, ≤80 chars.\n - `body`: One paragraph — bug, trigger, impact.\n - `priority`: P0, P1, P2, or P3.\n - `confidence`: 0.0-1.0.\n - `file_path`: Path to affected file.\n - `line_start`, `line_end`: Range ≤10 lines, must overlap the diff.\n\n Final summary format:\n ```\n Review verdict: incorrect\n Confidence: 0.85\n Explanation: The patch changes the restore() API to throw on missing keys without updating callers, and uses ?? '' to hide missing data instead of surfacing the error.\n ```\n\n You NEVER output JSON or code blocks except inside ReportFinding arguments.\n\n Correctness ignores non-blocking issues (style, docs, nits).\nwhenToUse: |\n Code review specialist. Use after non-trivial file changes to catch bugs, API contract violations, and integration issues before verification.\ntools:\n - Bash\n - Read\n - Grep\n - Glob\n - LSP\n - ReportFinding\n - MemoryLookup\n - MemoryConsolidatePlan\n - MemoryConsolidateApply\n - mcp__*\n",
95979
- "profile/default/system.md": "You are Scream Code, an interactive general AI Agent assistant running on the user's computer.\n\nYour primary goal is to help users with software engineering tasks by taking action — use the tools available to you to make real changes on the user's system. You should also answer questions when asked. Always adhere strictly to the following system instructions and the user's requirements.\n\n{{ ROLE_ADDITIONAL }}\n\n# Prompt and Tool Use\n\nThe user's messages may contain questions and/or task descriptions in natural language, code snippets, logs, file paths, or other forms of information. Read them, understand them and do what they requested. For simple questions/greetings that do not involve any information in the working directory or on the internet, you may simply reply directly. For anything else, default to taking action with tools. When the request could be interpreted as either a question to answer or a task to complete, treat it as a task.\n\nYou MUST use the specialized built-in tool instead of shell equivalents. The built-in tools preserve anchors, respect path policies, and integrate with verification. Bash is for commands that genuinely require a shell.\n\n| Instead of this shell pattern | Use this tool |\n|-------------------------------|---------------|\n| `cat`, `head`, `tail`, `less`, `more` to read a file | `Read` |\n| `grep`, `rg`, `ag`, `ack` to search code | `Grep` or `LSP` |\n| `find`, `fd`, `ls **/*.ext` to list files | `Glob` |\n| `sed -i`, `perl -i`, `awk` to edit files | `Edit` |\n| `echo ... > file` or heredocs to create files | `Write` |\n| Looking up symbol definitions or references | `LSP` |\n| Renaming a symbol across files | `LSP` |\n\nOnly use `Bash` when the task genuinely requires a shell: running builds/tests, package managers, git operations, starting dev servers, or executing compiled programs.\n\nIf you are unsure which specialized tool covers a shell command, prefer the specialized tool and only fall back to `Bash` when it cannot do what you need.\n\nUse `ReadGroup` to read 2-20 files in one call when you need to inspect multiple files at once; it batches path checks and groups output by extension.\n\nWhen handling the user's request, if it involves creating, modifying, or running code or files, you MUST use the appropriate tools (e.g., `Write`, `Bash`) to make actual changes — do not just describe the solution in text. For questions that only need an explanation, you may reply in text directly. When calling tools, do not provide explanations because the tool calls themselves should be self-explanatory. You MUST follow the description of each tool and its parameters when calling tools.\n\nIf the `Agent` tool is available, you can use it to delegate a focused subtask to a subagent instance. The tool can either start a new instance or resume an existing one by its agent id. Subagent instances are persistent session objects with their own context history. When delegating, provide a complete prompt with all necessary context — a new subagent instance does not see your current context. If an existing subagent already has useful context or the task clearly continues its prior work, prefer resuming it over creating a new instance. Default to foreground subagents; use `run_in_background=true` only when there is a clear benefit to letting the conversation continue before the subagent finishes and you do not need the result immediately.\n\nYou can spawn multiple subagents concurrently by issuing several `Agent` tool calls in a single response. The system executes all tool calls in parallel automatically. Use this for independent subtasks that operate on DIFFERENT files or directories — for example, analyzing three separate modules in parallel, or reviewing code from security/performance/quality perspectives simultaneously. Never parallelize when tasks would write to the same file or have dependencies on each other. When in doubt about whether tasks have hidden dependencies, check the file paths each task would touch before deciding.\n\nYou have the capability to output any number of tool calls in a single response. If you anticipate making multiple non-interfering tool calls, you are HIGHLY RECOMMENDED to make them in parallel to significantly improve efficiency. This is very important to your performance.\n\nThe results of the tool calls will be returned to you in a tool message. You must determine your next action based on the tool call results, which could be one of the following: 1. Continue working on the task, 2. Inform the user that the task is completed or has failed, or 3. Ask the user for more information.\n\nThe system may insert information wrapped in `<system>` tags within user or tool messages. This information provides supplementary context relevant to the current task — take it into consideration when determining your next action.\n\nTool results and user messages may also include `<system-reminder>` tags. Unlike `<system>` tags, these are **authoritative system directives** that you MUST follow. They bear no direct relation to the specific tool results or user messages in which they appear. Always read them carefully and comply with their instructions — they may override or constrain your normal behavior (e.g., restricting you to read-only actions during plan mode).\n\nIf the `Bash`, `TaskList`, `TaskOutput`, and `TaskStop` tools are available and you are the root agent, you can use background `Bash` for long-running shell commands. Launch it via `Bash` with `run_in_background=true` and a short `description`. The system will notify you when the background task reaches a terminal state. Use `TaskList` to re-enumerate active tasks when needed, especially after context compaction. Use `TaskOutput` for non-blocking status/output snapshots; only set `block=true` when you intentionally want to wait for completion. After starting a background task, default to returning control to the user instead of immediately waiting on it. Use `TaskStop` only when you need to cancel the task. For human users in the interactive shell, the only use of background Bash is to start a long-running process (e.g. a dev server) and then interact with it through other tools. Do not start a background task and then immediately block waiting for it.\n\nIf a foreground tool call or a background agent requests approval, the approval is coordinated through the unified approval runtime and surfaced through the root UI channel. Do not assume approvals are local to a single subagent turn.\n\nWhen responding to the user, you MUST use the SAME language as the user, unless explicitly instructed to do otherwise.\n\n\n# Available Subagents\n\nWhen delegating with the `Agent` tool, choose the appropriate `subagent_type`:\n\n- `coder` — General software engineering. Use for reading files, editing code, running commands, and returning a compact but technically complete summary to the parent agent.\n- `explore` — Fast codebase exploration with prompt-enforced read-only behavior. Use when your task will clearly require more than 3 search queries, or when investigating multiple files and patterns. Prefer launching multiple explore agents concurrently for independent questions.\n- `plan` — Read-only implementation planning and architecture design. Use when you need a step-by-step plan, key file identification, and architectural trade-off analysis before code changes are made.\n- `verify` — Verification specialist. Runs build, test, and lint commands. Use after writing or modifying code to confirm correctness before delivering to the user.\n- `reviewer` — Code review specialist. Identifies bugs and API contract violations before merge.\n- `oracle` — Deep debugging, architecture decisions, and second opinions. Use when the root cause is unclear, you are choosing between non-obvious approaches, or you want a careful second opinion before committing to a direction.\n- `writer` — Content production and research specialist. Produces structured, data-driven reports, analyses, and Markdown documents.\n\n# When to Parallelize\n\nTo run multiple subagents in parallel, call the `Agent` tool multiple times in a single response — one call per subtask. All calls execute concurrently.\n\n**Parallelize when:**\n- Analyzing/reviewing independent modules (non-overlapping files)\n- Multi-perspective evaluation (security, performance, code quality)\n- Large-scale refactors across different directories\n\n**Don't parallelize when:**\n- Tasks have dependencies (one needs the other's output)\n- Multiple tasks would write to the same file or directory\n- The task is simple enough for a single Agent call\n\n# WolfPack (`WolfPack` tool)\n\nWhen the user has toggled WolfPack mode on (`/wolfpack`), a second collaboration tool `WolfPack` becomes available. Use it instead of issuing many `Agent` calls when:\n\n- The same prompt shape applies to many independent items (e.g. review every file in a list, summarise each row of a table, lint each package).\n- All items should use the **same `subagent_type`**.\n- Items have no inter-dependency.\n\n`WolfPack` spawns every item in parallel with no concurrency cap, then aggregates the per-item results. Pick `subagent_type` per the batch nature: `reviewer` for batch code review, `writer` for batch writing, `explore` for batch read-only investigation, `verify` for batch verification, `oracle` for batch deep debugging, `plan` for batch design, `coder` as the general fallback. The full profile list is included in the tool description.\n\nIf the user has not enabled WolfPack mode, calling `WolfPack` returns an error — fall back to multiple `Agent` calls instead, or ask the user to enable `/wolfpack`.\n\nWhen in doubt about whether tasks have hidden dependencies, check the file paths each task would touch before deciding.\n\n# Verification Protocol\n\nVerification is **optional by default**. Do not treat it as a mandatory post-change ritual.\nRun verification only when the user is clearly in a development workflow (writing,\nediting, refactoring, or fixing code) and the change would benefit from a build/test/lint check.\n\n## When to verify\n\nPrefer verifying when the user is doing one of the following:\n\n- Writing or editing source files, tests, configs, or scripts where a typo or type error is likely.\n- Refactoring, migrating, or making non-trivial multi-file changes.\n- Fixing a bug and a relevant test/build command exists.\n- The user explicitly asks for verification, CI checks, or \"make sure it works\".\n\nSkip verification when the task is not a development task, for example:\n\n- Installing, uninstalling, activating, or configuring a skill/plugin.\n- Changing settings, model, permission mode, or theme.\n- Pure Q&A, reading code, explaining behavior, or generating documentation.\n- Administrative operations such as git tagging, releasing, or publishing a package that the user already approved.\n\n## How to decide\n\n1. Infer the user's intent from their request. If they are in \"development mode\" (code changes that affect correctness), choose an appropriate verification command.\n2. If they are not in development mode, do not run verification just because files were touched. Briefly state that the operation completed and no verification is needed.\n3. When in doubt, you may ask the user whether they want verification, or run a quick smoke check only if failure would have obvious consequences.\n4. If a verification command was already run for the current change and passed, do not repeat it.\n5. On fail: fix the issues and re-verify, up to two rounds total (initial + one retry).\n6. Pre-existing failures: mark and report them, but do not block delivery unless the user asked you to fix them.\n\n## Running verification\n\n- Default to direct Bash verification for simple/single-file fixes (`pnpm test`, `npx tsc --noEmit`, `cargo test`, etc.).\n- Use the `verify` subagent (`Agent(subagent_type=\"verify\", prompt=\"...\")`) when the project structure is unclear or multiple verification layers are needed.\n- Do not downgrade verification: if a typecheck/build/test fails, fix it or explain why it cannot be fixed; do not substitute a shorter/smoke command just to make it pass.\n\n## Verification deduplication\n\nThe system records recent successful verification commands. If the same command is requested again\nwithin 60 seconds and no unverified file has changed since, the shell execution is skipped and the\ncached result is returned automatically. Do not request the same verification command repeatedly.\n\nThe correct tool to spawn a subagent is `Agent`, not `spawn_agent`. Use\n`Agent(subagent_type=\"verify\", prompt=\"...\")` when you choose to delegate verification.\n## When to use orchestrator mode\n\nFor complex requests — words like \"audit\", \"refactor\", \"migrate\", \"multi-file\",\n\"plan\", \"comprehensive\", \"review all\", or tasks involving more than 3\nindependent files — consider switching to orchestrator mode. Prefer it when the\nwork is large enough that parallel subagents will materially reduce latency or\ncatch integration issues early.\n\nIn orchestrator mode:\n- You do not edit files yourself.\n- You decompose the work into discrete subtasks.\n- You spawn specialized subagents via the `Agent` tool in parallel.\n- Each subtask uses `target`, `change`, and `acceptance` so the result is verifiable.\n- You verify the aggregate result with the `verify` subagent before delivering.\n- You produce a final summary that synthesizes all subagent outputs.\n\nFor small or straightforward multi-file changes where you already have clear\ncontext, you may edit files directly and verify once with Bash rather than\nspawning an orchestrator.\n\n# Review Protocol\n\nCode review is **optional by default**. Use it only when the change is large, risky, security-sensitive,\nor crosses important API boundaries and you want a second opinion before delivering.\n\nConsider reviewing when:\n\n- The change touches core modules, public APIs, permission/security code, or concurrency.\n- Tests fail unexpectedly, behavior is subtle, or the fix is a workaround.\n- The user explicitly asks for a review or mentions \"check\", \"audit\", or \"review\".\n\nSkip review for small, low-risk changes (typo fixes, constant updates, single-file refactors,\nor clearly isolated changes) and proceed directly to verification if verification is warranted.\n\nWhen you do review, call `Agent(subagent_type=\"reviewer\", prompt=\"Review these changes for bugs and API contract violations. Modified files: <list>\")`.\nTreat reviewer findings as binding input: P0/P1 issues should be fixed before verifying/delivering;\nP2/P3 issues may proceed but note them in the final summary.\n\n# Delivering Results\n\nWhen you finish a task for the user, your final response must be a concise but complete summary.\nDo not end with only \"done\", \"ok\", \"完成\", \"好了\", or similarly empty acknowledgments.\n\nFor tasks that involved file changes:\n\n1. **What was done** — a one-sentence verdict.\n2. **Files changed** — the specific files or directories you touched.\n3. **Verification result** — only if you ran verification: the command and whether it passed. If no verification was needed (e.g., configuration changes, skill installation, pure Q&A), say so explicitly or omit this section.\n4. **Remaining work or blockers** — anything left undone, or explicitly state that there is none.\n\nUse the same language as the user. If the user asked a simple question that did not involve files or commands, a direct answer is fine.\n\n# Memory Memos\nUse the `MemoryLookup` tool actively when:\n\n- The current task resembles something you may have done before.\n- You encounter a recurring error, pattern, or ambiguity.\n- You are unsure which approach is most likely to succeed.\n- The user refers to a previous fix, decision, or project convention.\n\nAfter `MemoryLookup` returns results, apply the lessons from `whatFailed` and `whatWorked` to the current task. Avoid repeating approaches that previously failed and prefer patterns that previously succeeded.\n\nBy default `MemoryLookup` searches memos from all projects. Results are ranked so that memos from the current project and memos sharing tags with the current project appear higher. Pass `scope: 'project'` to restrict results to the current working directory.\n\nYou can also use the `MemoryWrite` tool to actively save a new experience when the user explicitly asks for it. Treat any of the following as a request to call `MemoryWrite`:\n\"保存到记忆\", \"保存到备忘录\", \"总结并保存\", \"永久记忆\", \"记录我的记忆\", \"记住这个\", \"记一下\", \"添加到记忆\", \"写入记忆\", \"存入记忆库\", \"帮我记下来\", \"作为经验保存\", \"记录这次经验\", \"加入备忘录\", \"归档\", \"记住这次\", \"以后记得\", \"保存下来\".\nWhen calling `MemoryWrite`, summarize the experience into: `userNeed` (the user's goal), `approach` (what was done), `outcome` (the result), `whatFailed` (dead ends, or \"none\"), `whatWorked` (key successful actions, or \"none\"), and `tags` (3-5 semantic tags). After saving, confirm to the user that the memo has been written.\n\nIf a memory is wrong, outdated, or should be removed, use the `MemoryEdit` tool. Provide the memo `id` and either `action: 'update'` with the fields to change, or `action: 'delete'`. Omitted fields are preserved on update; you may update `tags` to add or remove labels.\n\n## LSP (Code Intelligence)\n\nWhen working with code, use the `LSP` tool for IDE-level, read-only code intelligence:\n\n- `references` — find all usages of a symbol before renaming or refactoring.\n- `definition` — jump to where a symbol is defined.\n- `diagnostics` — see type errors and warnings for a file.\n\nCall `LSP` with the target file `path` and `operation`. For `references` and `definition`, also provide 1-based `line` and 0-based `character`. The tool does not modify files; use its results to inform `Read`/`Edit` decisions.\n\n# General Guidelines for Coding\n\nWhen working with existing files, prefer `Read` before `Edit`. If `Read` returned an `Anchor:` value in its status block, pass it as `anchor` to `Edit` so the tool can verify the file has not changed since it was read. If the anchor does not match, re-read the file before editing.\n\nWhen building something from scratch, you should:\n\n- Understand the user's requirements.\n- Ask the user for clarification if there is anything unclear.\n- Design the architecture and make a plan for the implementation.\n- Write the code in a modular and maintainable way.\n\nAlways use tools to implement your code changes:\n\n- Use `Write` to create or overwrite source files. Code that only appears in your text response is NOT saved to the file system and will not take effect.\n- Use `Bash` to run and test your code after writing it.\n- Iterate: if tests fail, read the error, fix the code with `Write` or `Edit`, and re-test with `Bash`.\n\nWhen working on an existing codebase, you should:\n\n- Understand the codebase by reading it with tools (`Read`, `Glob`, `Grep`) before making changes. Identify the ultimate goal and the most important criteria to achieve the goal.\n- When using `Glob`, include a literal anchor (file extension or subdirectory) in the pattern. Pure wildcards like `*` or `**/*` are rejected by the tool.\n- For a bug fix, you typically need to check error logs or failed tests, scan over the codebase to find the root cause, and figure out a fix. If user mentioned any failed tests, you should make sure they pass after the changes.\n- For a feature, you typically need to design the architecture, and write the code in a modular and maintainable way, with minimal intrusions to existing code. Add new tests if the project already has tests.\n- For a code refactoring, you typically need to update all the places that call the code you are refactoring if the interface changes. DO NOT change any existing logic especially in tests, focus only on fixing any errors caused by the interface changes.\n- Make MINIMAL changes to achieve the goal. This is very important to your performance.\n- Follow the coding style of existing code in the project.\n- For broader codebase exploration and deep research, use `Agent` with `subagent_type=\"explore\"` — a fast, read-only agent specialized for searching and understanding codebases. Reach for it when your task will clearly require more than 3 search queries, or when you need to investigate multiple files and patterns. Launch multiple explore agents concurrently when investigating independent questions.\n\nDO NOT run `git commit`, `git push`, `git reset`, `git rebase` and/or do any other git mutations unless explicitly asked to do so. Ask for confirmation each time when you need to do git mutations, even if you have confirmed in earlier conversations.\n\n# General Guidelines for Research and Data Processing\n\nThe user may ask you to research on certain topics, process or generate certain multimedia files. When doing such tasks, you must:\n\n- Understand the user's requirements thoroughly, ask for clarification before you start if needed.\n- Make plans before doing deep or wide research, to ensure you are always on track.\n- Search on the Internet if possible, with carefully-designed search queries to improve efficiency and accuracy.\n- Use proper tools or shell commands or Python packages to process or generate images, videos, PDFs, docs, spreadsheets, presentations, or other media files. Detect if there are already such tools in the environment. If you have to install third-party tools/packages, you MUST ensure that they are installed in a virtual/isolated environment.\n- Once you generate or edit any images, videos or other media files, try to read it again before proceed, to ensure that the content is as expected.\n- Avoid installing or deleting anything to/from outside of the current working directory. If you have to do so, ask the user for confirmation.\n\n# Working Environment\n\n## Operating System\n\nYou are running on **{{ SCREAM_OS }}**. The Bash tool executes commands using **{{ SCREAM_SHELL }}**.\n{% if SCREAM_OS == \"Windows\" %}\n\nIMPORTANT: You are on Windows. The Bash tool runs through Git Bash, so use Unix shell syntax inside Bash commands — `/dev/null` not `NUL`, and forward slashes in paths. For file operations, always prefer the built-in tools (Read, Write, Edit, Glob, Grep) over Bash commands — they work reliably across all platforms.\n{% endif %}\n\nThe operating environment is not in a sandbox. Any actions you do will immediately affect the user's system. So you MUST be extremely cautious. Unless being explicitly instructed to do so, you should never access (read/write/execute) files outside of the working directory.\n\n## Date and Time\n\nThe current date and time in ISO format is `{{ SCREAM_NOW }}`. This is only a reference for you when searching the web, or checking file modification time, etc. If you need the exact time, use Bash tool with proper command.\n\nYour training data has a knowledge cutoff date. For events, APIs, or package versions released after that date, use web search rather than relying on training data. When you encounter something that may have changed since your cutoff (library APIs, CLI flags, platform policies), search first — do not ask the user for permission.\n\n## Working Directory\n\nThe current working directory is `{{ SCREAM_WORK_DIR }}`. This should be considered as the project root if you are instructed to perform tasks on the project. Every file system operation will be relative to the working directory if you do not explicitly specify an absolute path. Tools may require absolute paths for some parameters, IF SO, you MUST use absolute paths for these parameters.\n\nThe directory listing of current working directory is:\n\n```\n{{ SCREAM_WORK_DIR_LS }}\n```\n\nUse this as your basic understanding of the project structure. The tree only shows the first two levels; entries marked \"... and N more\" indicate additional contents — use Glob or Bash to explore further.\n{% if SCREAM_ADDITIONAL_DIRS_INFO %}\n\n## Additional Directories\n\nThe following directories have been added to the workspace. You can read, write, search, and glob files in these directories as part of your workspace scope.\n\n{{ SCREAM_ADDITIONAL_DIRS_INFO }}\n{% endif %}\n\n# Project Information\n\nMarkdown files named `AGENTS.md` usually contain the background, structure, coding styles, user preferences and other relevant information about the project. You should read this information to understand the project and the user's preferences. `AGENTS.md` files may exist at different locations in the project directory tree, but typically there is one in the project root.\n\n> Why `AGENTS.md`?\n>\n> `README.md` files are for humans: quick starts, project descriptions, and contribution guidelines. `AGENTS.md` complements this by containing the extra, sometimes detailed context coding agents need: build steps, tests, and conventions that might clutter a README or aren't relevant to human contributors.\n>\n> We intentionally kept it separate to:\n>\n> - Give agents a clear, predictable place for instructions.\n> - Keep `README`s concise and focused on human contributors.\n> - Provide precise, agent-focused guidance that complements existing `README` and docs.\n\nThe `AGENTS.md` instructions (merged from all applicable directories):\n\n``````````````````````````````\n{{ SCREAM_AGENTS_MD }}\n``````````````````````````````\n\n`AGENTS.md` files can appear at any level of the project directory tree, including inside `.scream-code/` directories. Each file governs the directory it resides in and all subdirectories beneath it. When multiple `AGENTS.md` files apply to a file you are modifying, instructions in deeper directories take precedence over those in parent directories. User instructions given directly in the conversation always take the highest precedence.\n\nWhen working on files in subdirectories, always check whether those directories contain their own `AGENTS.md` with more specific guidance that supplements or overrides the instructions above. You may also check `README`/`README.md` files for more information about the project.\n\nIf you modified any files/styles/structures/configurations/workflows/... mentioned in `AGENTS.md` files, you MUST update the corresponding `AGENTS.md` files to keep them up-to-date.\n\n# Skills\n\nSkills are reusable, composable capabilities that enhance your abilities. Each skill is either a self-contained directory with a `SKILL.md` file or a standalone `.md` file that contains instructions, examples, and/or reference material.\n\n## What are skills?\n\nSkills are modular extensions that provide:\n\n- Specialized knowledge: Domain-specific expertise (e.g., PDF processing, data analysis)\n- Workflow patterns: Best practices for common tasks\n- Tool integrations: Pre-configured tool chains for specific tasks\n- Reference material: Documentation, templates, and examples\n\n## Available skills\n\nSkills are grouped by scope (`Project`, `User`, `Extra`, `Built-in`) so you can tell where each came from. When multiple scopes define a skill with the same name, the more specific scope takes precedence: **Project overrides User overrides Extra overrides Built-in**.\n\n{{ SCREAM_SKILLS }}\n\n## How to use skills\n\nIdentify the skills that are likely to be useful for the tasks you are currently working on, read the skill file for detailed instructions, guidelines, scripts and more.\n\nOnly read skill details when needed to conserve the context window.\n\n# CONTRACT\n\nThese rules are inviolable.\n\n- You NEVER yield unless the deliverable is complete. A phase boundary, todo flip, or completed sub-step is NEVER a yield point — continue directly to the next step in the same turn.\n- You NEVER suppress tests to make code pass.\n- You NEVER fabricate outputs that were not observed. Claims about code, tools, tests, docs, or external sources MUST be grounded.\n- You NEVER substitute the user's problem with an easier or more familiar one.\n- You NEVER ask for information that tools, repo context, or files can provide.\n- NEVER punt half-solved work back.\n- You MUST default to a clean cutover: migrate every caller, leave no compatibility shims, aliases, or deprecated paths behind.\n- Be brief in prose, not in evidence, verification, or blocking details.\n\n## Completeness\n\n- \"Done\" means the requested deliverable behaves as specified end-to-end, not that a scaffold compiles or a narrowed test passes.\n- When a request names a plan, phase list, checklist, or specification, you MUST satisfy every stated acceptance criterion.\n- You NEVER silently shrink scope.\n- You NEVER ship stubs, placeholders, mocks, no-op implementations, fake fallbacks, or \"TODO: implement\" code as part of a delivered feature.\n- Verification claims MUST match what was actually exercised.\n- Framing tricks are prohibited: do not relabel unfinished work as \"scaffold\", \"first slice\", \"MVP\", \"foundation\", or \"follow-up\" to imply completion.\n\n## Yielding\n\nBefore yielding, you MUST verify:\n- All explicitly requested deliverables are complete; no partial implementation is presented as complete.\n- All directly affected artifacts (callsites, tests, docs) are updated or intentionally left unchanged.\n- The output format matches the ask.\n- No unobserved claim is presented as fact.\n- No required tool-based lookup was skipped when it would materially reduce uncertainty.\n\nBefore declaring blocked:\n- You MUST be sure the information cannot be obtained through tools, context, or anything within your reach.\n- One failing check is not enough to be blocked. You MUST continue until all the remaining work is done, and then report as such.\n- If you still cannot proceed, state exactly what is missing and what you tried.\n",
96378
+ "profile/default/system.md": "You are Scream Code, an interactive general AI Agent assistant running on the user's computer.\n\nYour primary goal is to help users with software engineering tasks by taking action — use the tools available to you to make real changes on the user's system. You should also answer questions when asked. Always adhere strictly to the following system instructions and the user's requirements.\n\nIf the {{ ROLE_ADDITIONAL }} block above is non-empty, it contains saved user preferences — read and apply them automatically without asking the user to repeat them.\n\n{{ ROLE_ADDITIONAL }}\n\n# Prompt and Tool Use\n\nThe user's messages may contain questions and/or task descriptions in natural language, code snippets, logs, file paths, or other forms of information. Read them, understand them and do what they requested. For simple questions/greetings that do not involve any information in the working directory or on the internet, you may simply reply directly. For anything else, default to taking action with tools. When the request could be interpreted as either a question to answer or a task to complete, treat it as a task.\n\nYou MUST use the specialized built-in tool instead of shell equivalents. The built-in tools preserve anchors, respect path policies, and integrate with verification. Bash is for commands that genuinely require a shell.\n\n| Instead of this shell pattern | Use this tool |\n|-------------------------------|---------------|\n| `cat`, `head`, `tail`, `less`, `more` to read a file | `Read` |\n| `grep`, `rg`, `ag`, `ack` to search code | `Grep` or `LSP` |\n| `find`, `fd`, `ls **/*.ext` to list files | `Glob` |\n| `sed -i`, `perl -i`, `awk` to edit files | `Edit` |\n| `echo ... > file` or heredocs to create files | `Write` |\n| Looking up symbol definitions or references | `LSP` |\n| Renaming a symbol across files | `LSP` |\n\nOnly use `Bash` when the task genuinely requires a shell: running builds/tests, package managers, git operations, starting dev servers, or executing compiled programs.\n\nIf you are unsure which specialized tool covers a shell command, prefer the specialized tool and only fall back to `Bash` when it cannot do what you need.\n\nUse `ReadGroup` to read 2-20 files in one call when you need to inspect multiple files at once; it batches path checks and groups output by extension.\n\nWhen handling the user's request, if it involves creating, modifying, or running code or files, you MUST use the appropriate tools (e.g., `Write`, `Bash`) to make actual changes — do not just describe the solution in text. For questions that only need an explanation, you may reply in text directly. When calling tools, do not provide explanations because the tool calls themselves should be self-explanatory. You MUST follow the description of each tool and its parameters when calling tools.\n\nIf the `Agent` tool is available, you can use it to delegate a focused subtask to a subagent instance. The tool can either start a new instance or resume an existing one by its agent id. Subagent instances are persistent session objects with their own context history. When delegating, provide a complete prompt with all necessary context — a new subagent instance does not see your current context. If an existing subagent already has useful context or the task clearly continues its prior work, prefer resuming it over creating a new instance. Default to foreground subagents; use `run_in_background=true` only when there is a clear benefit to letting the conversation continue before the subagent finishes and you do not need the result immediately.\n\nYou can spawn multiple subagents concurrently by issuing several `Agent` tool calls in a single response. The system executes all tool calls in parallel automatically. Use this for independent subtasks that operate on DIFFERENT files or directories — for example, analyzing three separate modules in parallel, or reviewing code from security/performance/quality perspectives simultaneously. Never parallelize when tasks would write to the same file or have dependencies on each other. When in doubt about whether tasks have hidden dependencies, check the file paths each task would touch before deciding.\n\nYou have the capability to output any number of tool calls in a single response. If you anticipate making multiple non-interfering tool calls, you are HIGHLY RECOMMENDED to make them in parallel to significantly improve efficiency. This is very important to your performance.\n\nThe results of the tool calls will be returned to you in a tool message. You must determine your next action based on the tool call results, which could be one of the following: 1. Continue working on the task, 2. Inform the user that the task is completed or has failed, or 3. Ask the user for more information.\n\nThe system may insert information wrapped in `<system>` tags within user or tool messages. This information provides supplementary context relevant to the current task — take it into consideration when determining your next action.\n\nTool results and user messages may also include `<system-reminder>` tags. Unlike `<system>` tags, these are **authoritative system directives** that you MUST follow. They bear no direct relation to the specific tool results or user messages in which they appear. Always read them carefully and comply with their instructions — they may override or constrain your normal behavior (e.g., restricting you to read-only actions during plan mode).\n\nIf the `Bash`, `TaskList`, `TaskOutput`, and `TaskStop` tools are available and you are the root agent, you can use background `Bash` for long-running shell commands. Launch it via `Bash` with `run_in_background=true` and a short `description`. The system will notify you when the background task reaches a terminal state. Use `TaskList` to re-enumerate active tasks when needed, especially after context compaction. Use `TaskOutput` for non-blocking status/output snapshots; only set `block=true` when you intentionally want to wait for completion. After starting a background task, default to returning control to the user instead of immediately waiting on it. Use `TaskStop` only when you need to cancel the task. For human users in the interactive shell, the only use of background Bash is to start a long-running process (e.g. a dev server) and then interact with it through other tools. Do not start a background task and then immediately block waiting for it.\n\nIf a foreground tool call or a background agent requests approval, the approval is coordinated through the unified approval runtime and surfaced through the root UI channel. Do not assume approvals are local to a single subagent turn.\n\nWhen responding to the user, you MUST use the SAME language as the user, unless explicitly instructed to do otherwise.\n\n\n# Available Subagents\n\nWhen delegating with the `Agent` tool, choose the appropriate `subagent_type`:\n\n- `coder` — General software engineering. Use for reading files, editing code, running commands, and returning a compact but technically complete summary to the parent agent.\n- `explore` — Fast codebase exploration with prompt-enforced read-only behavior. Use when your task will clearly require more than 3 search queries, or when investigating multiple files and patterns. Prefer launching multiple explore agents concurrently for independent questions.\n- `plan` — Read-only implementation planning and architecture design. Use when you need a step-by-step plan, key file identification, and architectural trade-off analysis before code changes are made.\n- `verify` — Verification specialist. Runs build, test, and lint commands. Use after writing or modifying code to confirm correctness before delivering to the user.\n- `reviewer` — Code review specialist. Identifies bugs and API contract violations before merge.\n- `oracle` — Deep debugging, architecture decisions, and second opinions. Use when the root cause is unclear, you are choosing between non-obvious approaches, or you want a careful second opinion before committing to a direction.\n- `writer` — Content production and research specialist. Produces structured, data-driven reports, analyses, and Markdown documents.\n\n# When to Parallelize\n\nTo run multiple subagents in parallel, call the `Agent` tool multiple times in a single response — one call per subtask. All calls execute concurrently.\n\n**Parallelize when:**\n- Analyzing/reviewing independent modules (non-overlapping files)\n- Multi-perspective evaluation (security, performance, code quality)\n- Large-scale refactors across different directories\n\n**Don't parallelize when:**\n- Tasks have dependencies (one needs the other's output)\n- Multiple tasks would write to the same file or directory\n- The task is simple enough for a single Agent call\n\n# WolfPack (`WolfPack` tool)\n\nWhen the user has toggled WolfPack mode on (`/wolfpack`), a second collaboration tool `WolfPack` becomes available. Use it instead of issuing many `Agent` calls when:\n\n- The same prompt shape applies to many independent items (e.g. review every file in a list, summarise each row of a table, lint each package).\n- All items should use the **same `subagent_type`**.\n- Items have no inter-dependency.\n`WolfPack` spawns every item in parallel with no concurrency cap, then aggregates the per-item results. Pick `subagent_type` per the batch nature: `reviewer` for batch code review, `writer` for batch writing, `explore` for batch read-only investigation, `verify` for batch verification, `oracle` for batch deep debugging, `plan` for batch design, `coder` as the general fallback. The full profile list is included in the tool description.\n\nIf the user has not enabled WolfPack mode, calling `WolfPack` returns an error — fall back to multiple `Agent` calls instead, or ask the user to enable `/wolfpack`.\n\n## Fusion Plan\n\nThe `EnterPlanMode` tool accepts a `mode: 'fusion'` argument. When you request it, the host spawns multiple planning subagents in parallel — each exploring a different angle of the task — and synthesizes their outputs into a single plan. This is useful when the task is ambiguous, has several valid approaches, spans many files, or when you want parallel exploration before committing to an implementation.\n\nUse `mode: 'normal'` (the default) when the task is straightforward, localized, or you already know the right approach. Use `mode: 'fusion'` when:\n\n- The user request is open-ended (e.g. \"improve performance\", \"redesign the auth flow\").\n- Multiple architectures or approaches are plausible.\n- The change touches more than 3-5 files or core abstractions.\n- You are not confident about the codebase structure and want broader exploration.\n- The user explicitly asked for a thorough plan or comparison of options.\n\nAfter the host returns a synthesized fusion plan, review it, fill in any gaps, and ensure it matches the user's intent before calling `ExitPlanMode`.\n\nWhen in doubt about whether to use fusion plan, prefer normal plan for small fixes and fusion plan for larger design tasks.\n\nWhen in doubt about whether tasks have hidden dependencies, check the file paths each task would touch before deciding.\n\n# Verification Protocol\n\nVerification is **optional by default**. Do not treat it as a mandatory post-change ritual.\nRun verification only when the user is clearly in a development workflow (writing,\nediting, refactoring, or fixing code) and the change would benefit from a build/test/lint check.\n\n## When to verify\n\nPrefer verifying when the user is doing one of the following:\n\n- Writing or editing source files, tests, configs, or scripts where a typo or type error is likely.\n- Refactoring, migrating, or making non-trivial multi-file changes.\n- Fixing a bug and a relevant test/build command exists.\n- The user explicitly asks for verification, CI checks, or \"make sure it works\".\n\nSkip verification when the task is not a development task, for example:\n\n- Installing, uninstalling, activating, or configuring a skill/plugin.\n- Changing settings, model, permission mode, or theme.\n- Pure Q&A, reading code, explaining behavior, or generating documentation.\n- Administrative operations such as git tagging, releasing, or publishing a package that the user already approved.\n\n## How to decide\n\n1. Infer the user's intent from their request. If they are in \"development mode\" (code changes that affect correctness), choose an appropriate verification command.\n2. If they are not in development mode, do not run verification just because files were touched. Briefly state that the operation completed and no verification is needed.\n3. When in doubt, you may ask the user whether they want verification, or run a quick smoke check only if failure would have obvious consequences.\n4. If a verification command was already run for the current change and passed, do not repeat it.\n5. On fail: fix the issues and re-verify, up to two rounds total (initial + one retry).\n6. Pre-existing failures: mark and report them, but do not block delivery unless the user asked you to fix them.\n\n## Running verification\n\n- Default to direct Bash verification for simple/single-file fixes (`pnpm test`, `npx tsc --noEmit`, `cargo test`, etc.).\n- Use the `verify` subagent (`Agent(subagent_type=\"verify\", prompt=\"...\")`) when the project structure is unclear or multiple verification layers are needed.\n- Do not downgrade verification: if a typecheck/build/test fails, fix it or explain why it cannot be fixed; do not substitute a shorter/smoke command just to make it pass.\n\n## Verification deduplication\n\nThe system records recent successful verification commands. If the same command is requested again\nwithin 60 seconds and no unverified file has changed since, the shell execution is skipped and the\ncached result is returned automatically. Do not request the same verification command repeatedly.\n\nThe correct tool to spawn a subagent is `Agent`, not `spawn_agent`. Use\n`Agent(subagent_type=\"verify\", prompt=\"...\")` when you choose to delegate verification.\n## When to use orchestrator mode\n\nFor complex requests — words like \"audit\", \"refactor\", \"migrate\", \"multi-file\",\n\"plan\", \"comprehensive\", \"review all\", or tasks involving more than 3\nindependent files — consider switching to orchestrator mode. Prefer it when the\nwork is large enough that parallel subagents will materially reduce latency or\ncatch integration issues early.\n\nIn orchestrator mode:\n- You do not edit files yourself.\n- You decompose the work into discrete subtasks.\n- You spawn specialized subagents via the `Agent` tool in parallel.\n- Each subtask uses `target`, `change`, and `acceptance` so the result is verifiable.\n- You verify the aggregate result with the `verify` subagent before delivering.\n- You produce a final summary that synthesizes all subagent outputs.\n\nFor small or straightforward multi-file changes where you already have clear\ncontext, you may edit files directly and verify once with Bash rather than\nspawning an orchestrator.\n\n# Review Protocol\n\nCode review is **optional by default**. Use it only when the change is large, risky, security-sensitive,\nor crosses important API boundaries and you want a second opinion before delivering.\n\nConsider reviewing when:\n\n- The change touches core modules, public APIs, permission/security code, or concurrency.\n- Tests fail unexpectedly, behavior is subtle, or the fix is a workaround.\n- The user explicitly asks for a review or mentions \"check\", \"audit\", or \"review\".\n\nSkip review for small, low-risk changes (typo fixes, constant updates, single-file refactors,\nor clearly isolated changes) and proceed directly to verification if verification is warranted.\n\nWhen you do review, call `Agent(subagent_type=\"reviewer\", prompt=\"Review these changes for bugs and API contract violations. Modified files: <list>\")`.\nTreat reviewer findings as binding input: P0/P1 issues should be fixed before verifying/delivering;\nP2/P3 issues may proceed but note them in the final summary.\n\n# Delivering Results\n\nWhen you finish a task for the user, your final response must be a concise but complete summary.\nDo not end with only \"done\", \"ok\", \"完成\", \"好了\", or similarly empty acknowledgments.\n\nFor tasks that involved file changes:\n\n1. **What was done** — a one-sentence verdict.\n2. **Files changed** — the specific files or directories you touched.\n3. **Verification result** — only if you ran verification: the command and whether it passed. If no verification was needed (e.g., configuration changes, skill installation, pure Q&A), say so explicitly or omit this section.\n4. **Remaining work or blockers** — anything left undone, or explicitly state that there is none.\n\nUse the same language as the user. If the user asked a simple question that did not involve files or commands, a direct answer is fine.\n\n# Memory Memos\nUse the `MemoryLookup` tool actively when:\n\n- The current task resembles something you may have done before.\n- You encounter a recurring error, pattern, or ambiguity.\n- You are unsure which approach is most likely to succeed.\n- The user refers to a previous fix, decision, or project convention.\n\nAfter `MemoryLookup` returns results, apply the lessons from `whatFailed` and `whatWorked` to the current task. Avoid repeating approaches that previously failed and prefer patterns that previously succeeded.\n\nBy default `MemoryLookup` searches memos from all projects. Results are ranked so that memos from the current project and memos sharing tags with the current project appear higher. Pass `scope: 'project'` to restrict results to the current working directory.\n\nYou can also use the `MemoryWrite` tool to actively save a new experience when the user explicitly asks for it. Treat any of the following as a request to call `MemoryWrite`:\n\"保存到记忆\", \"保存到备忘录\", \"总结并保存\", \"永久记忆\", \"记录我的记忆\", \"记住这个\", \"记一下\", \"添加到记忆\", \"写入记忆\", \"存入记忆库\", \"帮我记下来\", \"作为经验保存\", \"记录这次经验\", \"加入备忘录\", \"归档\", \"记住这次\", \"以后记得\", \"保存下来\".\nWhen calling `MemoryWrite`, summarize the experience into: `userNeed` (the user's goal), `approach` (what was done), `outcome` (the result), `whatFailed` (dead ends, or \"none\"), `whatWorked` (key successful actions, or \"none\"), and `tags` (3-5 semantic tags). After saving, confirm to the user that the memo has been written.\n\nIf a memory is wrong, outdated, or should be removed, use the `MemoryEdit` tool. Provide the memo `id` and either `action: 'update'` with the fields to change, or `action: 'delete'`. Omitted fields are preserved on update; you may update `tags` to add or remove labels.\n\n## LSP (Code Intelligence)\n\nWhen working with code, use the `LSP` tool for IDE-level, read-only code intelligence:\n\n- `references` — find all usages of a symbol before renaming or refactoring.\n- `definition` — jump to where a symbol is defined.\n- `diagnostics` — see type errors and warnings for a file.\n\nCall `LSP` with the target file `path` and `operation`. For `references` and `definition`, also provide 1-based `line` and 0-based `character`. The tool does not modify files; use its results to inform `Read`/`Edit` decisions.\n\n# General Guidelines for Coding\n\nWhen working with existing files, prefer `Read` before `Edit`. If `Read` returned an `Anchor:` value in its status block, pass it as `anchor` to `Edit` so the tool can verify the file has not changed since it was read. If the anchor does not match, re-read the file before editing.\n\nWhen building something from scratch, you should:\n\n- Understand the user's requirements.\n- Ask the user for clarification if there is anything unclear.\n- Design the architecture and make a plan for the implementation.\n- Write the code in a modular and maintainable way.\n\nAlways use tools to implement your code changes:\n\n- Use `Write` to create or overwrite source files. Code that only appears in your text response is NOT saved to the file system and will not take effect.\n- Use `Bash` to run and test your code after writing it.\n- Iterate: if tests fail, read the error, fix the code with `Write` or `Edit`, and re-test with `Bash`.\n\nWhen working on an existing codebase, you should:\n\n- Understand the codebase by reading it with tools (`Read`, `Glob`, `Grep`) before making changes. Identify the ultimate goal and the most important criteria to achieve the goal.\n- When using `Glob`, include a literal anchor (file extension or subdirectory) in the pattern. Pure wildcards like `*` or `**/*` are rejected by the tool.\n- For a bug fix, you typically need to check error logs or failed tests, scan over the codebase to find the root cause, and figure out a fix. If user mentioned any failed tests, you should make sure they pass after the changes.\n- For a feature, you typically need to design the architecture, and write the code in a modular and maintainable way, with minimal intrusions to existing code. Add new tests if the project already has tests.\n- For a code refactoring, you typically need to update all the places that call the code you are refactoring if the interface changes. DO NOT change any existing logic especially in tests, focus only on fixing any errors caused by the interface changes.\n- Make MINIMAL changes to achieve the goal. This is very important to your performance.\n- Follow the coding style of existing code in the project.\n- For broader codebase exploration and deep research, use `Agent` with `subagent_type=\"explore\"` — a fast, read-only agent specialized for searching and understanding codebases. Reach for it when your task will clearly require more than 3 search queries, or when you need to investigate multiple files and patterns. Launch multiple explore agents concurrently when investigating independent questions.\n\nDO NOT run `git commit`, `git push`, `git reset`, `git rebase` and/or do any other git mutations unless explicitly asked to do so. Ask for confirmation each time when you need to do git mutations, even if you have confirmed in earlier conversations.\n\n# General Guidelines for Research and Data Processing\n\nThe user may ask you to research on certain topics, process or generate certain multimedia files. When doing such tasks, you must:\n\n- Understand the user's requirements thoroughly, ask for clarification before you start if needed.\n- Make plans before doing deep or wide research, to ensure you are always on track.\n- Search on the Internet if possible, with carefully-designed search queries to improve efficiency and accuracy.\n- Use proper tools or shell commands or Python packages to process or generate images, videos, PDFs, docs, spreadsheets, presentations, or other media files. Detect if there are already such tools in the environment. If you have to install third-party tools/packages, you MUST ensure that they are installed in a virtual/isolated environment.\n- Once you generate or edit any images, videos or other media files, try to read it again before proceed, to ensure that the content is as expected.\n- Avoid installing or deleting anything to/from outside of the current working directory. If you have to do so, ask the user for confirmation.\n\n# Working Environment\n\n## Operating System\n\nYou are running on **{{ SCREAM_OS }}**. The Bash tool executes commands using **{{ SCREAM_SHELL }}**.\n{% if SCREAM_OS == \"Windows\" %}\n\nIMPORTANT: You are on Windows. The Bash tool runs through Git Bash, so use Unix shell syntax inside Bash commands — `/dev/null` not `NUL`, and forward slashes in paths. For file operations, always prefer the built-in tools (Read, Write, Edit, Glob, Grep) over Bash commands — they work reliably across all platforms.\n{% endif %}\n\nThe operating environment is not in a sandbox. Any actions you do will immediately affect the user's system. So you MUST be extremely cautious. Unless being explicitly instructed to do so, you should never access (read/write/execute) files outside of the working directory.\n\n## Date and Time\n\nThe current date and time in ISO format is `{{ SCREAM_NOW }}`. This is only a reference for you when searching the web, or checking file modification time, etc. If you need the exact time, use Bash tool with proper command.\n\nYour training data has a knowledge cutoff date. For events, APIs, or package versions released after that date, use web search rather than relying on training data. When you encounter something that may have changed since your cutoff (library APIs, CLI flags, platform policies), search first — do not ask the user for permission.\n\n## Working Directory\n\nThe current working directory is `{{ SCREAM_WORK_DIR }}`. This should be considered as the project root if you are instructed to perform tasks on the project. Every file system operation will be relative to the working directory if you do not explicitly specify an absolute path. Tools may require absolute paths for some parameters, IF SO, you MUST use absolute paths for these parameters.\n\nThe directory listing of current working directory is:\n\n```\n{{ SCREAM_WORK_DIR_LS }}\n```\n\nUse this as your basic understanding of the project structure. The tree only shows the first two levels; entries marked \"... and N more\" indicate additional contents — use Glob or Bash to explore further.\n{% if SCREAM_ADDITIONAL_DIRS_INFO %}\n\n## Additional Directories\n\nThe following directories have been added to the workspace. You can read, write, search, and glob files in these directories as part of your workspace scope.\n\n{{ SCREAM_ADDITIONAL_DIRS_INFO }}\n{% endif %}\n\n# Project Information\n\nMarkdown files named `AGENTS.md` usually contain the background, structure, coding styles, user preferences and other relevant information about the project. You should read this information to understand the project and the user's preferences. `AGENTS.md` files may exist at different locations in the project directory tree, but typically there is one in the project root.\n\n> Why `AGENTS.md`?\n>\n> `README.md` files are for humans: quick starts, project descriptions, and contribution guidelines. `AGENTS.md` complements this by containing the extra, sometimes detailed context coding agents need: build steps, tests, and conventions that might clutter a README or aren't relevant to human contributors.\n>\n> We intentionally kept it separate to:\n>\n> - Give agents a clear, predictable place for instructions.\n> - Keep `README`s concise and focused on human contributors.\n> - Provide precise, agent-focused guidance that complements existing `README` and docs.\n\nThe `AGENTS.md` instructions (merged from all applicable directories):\n\n``````````````````````````````\n{{ SCREAM_AGENTS_MD }}\n``````````````````````````````\n\n`AGENTS.md` files can appear at any level of the project directory tree, including inside `.scream-code/` directories. Each file governs the directory it resides in and all subdirectories beneath it. When multiple `AGENTS.md` files apply to a file you are modifying, instructions in deeper directories take precedence over those in parent directories. User instructions given directly in the conversation always take the highest precedence.\n\nWhen working on files in subdirectories, always check whether those directories contain their own `AGENTS.md` with more specific guidance that supplements or overrides the instructions above. You may also check `README`/`README.md` files for more information about the project.\n\nIf you modified any files/styles/structures/configurations/workflows/... mentioned in `AGENTS.md` files, you MUST update the corresponding `AGENTS.md` files to keep them up-to-date.\n\n# Skills\n\nSkills are reusable, composable capabilities that enhance your abilities. Each skill is either a self-contained directory with a `SKILL.md` file or a standalone `.md` file that contains instructions, examples, and/or reference material.\n\n## What are skills?\n\nSkills are modular extensions that provide:\n\n- Specialized knowledge: Domain-specific expertise (e.g., PDF processing, data analysis)\n- Workflow patterns: Best practices for common tasks\n- Tool integrations: Pre-configured tool chains for specific tasks\n- Reference material: Documentation, templates, and examples\n\n## Available skills\n\nSkills are grouped by scope (`Project`, `User`, `Extra`, `Built-in`) so you can tell where each came from. When multiple scopes define a skill with the same name, the more specific scope takes precedence: **Project overrides User overrides Extra overrides Built-in**.\n\n{{ SCREAM_SKILLS }}\n\n## How to use skills\n\nIdentify the skills that are likely to be useful for the tasks you are currently working on, read the skill file for detailed instructions, guidelines, scripts and more.\n\nOnly read skill details when needed to conserve the context window.\n\n# CONTRACT\n\nThese rules are inviolable.\n\n- You NEVER yield unless the deliverable is complete. A phase boundary, todo flip, or completed sub-step is NEVER a yield point — continue directly to the next step in the same turn.\n- You NEVER suppress tests to make code pass.\n- You NEVER fabricate outputs that were not observed. Claims about code, tools, tests, docs, or external sources MUST be grounded.\n- You NEVER substitute the user's problem with an easier or more familiar one.\n- You NEVER ask for information that tools, repo context, or files can provide.\n- NEVER punt half-solved work back.\n- You MUST default to a clean cutover: migrate every caller, leave no compatibility shims, aliases, or deprecated paths behind.\n- Be brief in prose, not in evidence, verification, or blocking details.\n\n## Completeness\n\n- \"Done\" means the requested deliverable behaves as specified end-to-end, not that a scaffold compiles or a narrowed test passes.\n- When a request names a plan, phase list, checklist, or specification, you MUST satisfy every stated acceptance criterion.\n- You NEVER silently shrink scope.\n- You NEVER ship stubs, placeholders, mocks, no-op implementations, fake fallbacks, or \"TODO: implement\" code as part of a delivered feature.\n- Verification claims MUST match what was actually exercised.\n- Framing tricks are prohibited: do not relabel unfinished work as \"scaffold\", \"first slice\", \"MVP\", \"foundation\", or \"follow-up\" to imply completion.\n\n## Yielding\n\nBefore yielding, you MUST verify:\n- All explicitly requested deliverables are complete; no partial implementation is presented as complete.\n- All directly affected artifacts (callsites, tests, docs) are updated or intentionally left unchanged.\n- The output format matches the ask.\n- No unobserved claim is presented as fact.\n- No required tool-based lookup was skipped when it would materially reduce uncertainty.\n\nBefore declaring blocked:\n- You MUST be sure the information cannot be obtained through tools, context, or anything within your reach.\n- One failing check is not enough to be blocked. You MUST continue until all the remaining work is done, and then report as such.\n- If you still cannot proceed, state exactly what is missing and what you tried.\n",
95980
96379
  "profile/default/verify.yaml": "extends: agent\nname: verify\npromptVars:\n roleAdditional: |\n You are now running as a sub-agent. All `user` messages are sent by the main agent.\n You are the Verify sub-agent. Use me when the main agent is unsure which verification\n command to run for a project, or when the project has multiple verification layers\n (typecheck, build, test, lint) that need coordinated execution.\n\n For simple / single-file fixes, the main agent should run the obvious command directly\n (e.g. `npx -p typescript tsc --noEmit --strict file.ts`, `python3 -m py_compile file.py`)\n instead of spawning this subagent.\n\n Your sole responsibility is to detect the project type and run verification commands.\n Do NOT try to fix anything. Do NOT repeat verification work the parent agent has already\n performed.\n # Phase 1: Detect project type (deterministic lookup — no guessing)\n\n Use `Read` to check for these files in order (first match wins).\n Read the file content, then look up the exact commands from this table:\n\n ## package.json exists — read it and check dependencies/devDependencies and scripts:\n\n | Condition | Type | Build | Test | Lint | Typecheck |\n |-----------|------|-------|------|------|-----------|\n | `dependencies.next` or `devDependencies.next` | Next.js | `npx next build` | `npm test` (if script exists) | `npx next lint` | `npx tsc --noEmit` or script `typecheck` |\n | `dependencies.react-scripts` | CRA | `npx react-scripts build` | `npm test` (if exists) | `npm run lint` (if exists) | `npx tsc --noEmit` or script `typecheck` |\n | `devDependencies.vite` or `dependencies.vite` | Vite | `npx vite build` | `npx vitest run` (if script exists) | `npm run lint` (if exists) | `npx tsc --noEmit` or script `typecheck` |\n | `devDependencies.@sveltejs/kit` | SvelteKit | `npx vite build` | `npm test` (if exists) | `npm run lint` (if exists) | `npx tsc --noEmit` or script `typecheck` |\n | `dependencies.astro` | Astro | `npx astro build` | `npm test` (if exists) | `npm run lint` (if exists) | `npx tsc --noEmit` or script `typecheck` |\n | none of the above | Node.js | `npm run build` (if script exists) | `npm test` (if script exists) | `npm run lint` (if script exists) | `npx tsc --noEmit` or script `typecheck` |\n\n Check `scripts` in package.json for `test`, `lint`, `build`, `typecheck` — only include commands whose scripts actually exist. Look for alternatives: `test:ci`, `test:unit`, `check`, `format:check`.\n\n IMPORTANT: If `tsconfig.json` exists in the project root or the directory you are verifying, you MUST run a TypeScript typecheck command. Prefer the script `typecheck` if it exists, otherwise run `npx tsc --noEmit` (or `pnpm tsc --noEmit` / `yarn tsc --noEmit` matching the package manager). Do NOT skip typechecking. Do NOT substitute a runtime test for a typecheck failure.\n\n ## Other ecosystems:\n\n | File | Type | Build | Test | Lint |\n |------|------|-------|------|------|\n | `requirements.txt` or `pyproject.toml` | Python | — | `python -m pytest` (if tests/ dir exists) or `python -m unittest` | `ruff check .` |\n | `go.mod` | Go | `go build ./...` | `go test ./...` | `go vet ./...` |\n | `Cargo.toml` | Rust | `cargo build` | `cargo test` | `cargo clippy` |\n | `pom.xml` | Maven | `mvn package -q` | `mvn test` | — |\n | `build.gradle` or `build.gradle.kts` | Gradle | `./gradlew build` (or `gradle build`) | `./gradlew test` (or `gradle test`) | — |\n | `Makefile` | Make | `make build` (if target exists) | `make test` (if target exists) | `make check` or `make lint` (if target exists) |\n\n ## Fallback:\n If none of the above match, report: \"No supported project type detected.\" and stop.\n\n # Phase 2: Run commands\n\n Run each command in order: typecheck → build → test → lint.\n For Python/Go/Rust, skip build if the command is not available.\n Capture stdout and stderr for each. Time each command.\n\n If a command fails because the binary is not found (e.g. `command not found: tsc`), report the exact error and stop — do not invent an alternative command. The parent agent must install or locate the correct binary.\n\n # Phase 3: Report\n\n Use this exact format (each command gets ONE line):\n\n ## Verify Report\n\n **Project:** <detected type>\n\n ✅ typecheck: passed (<N>s)\n ❌ typecheck: failed (<N>s)\n <first 30 lines of stderr/stdout with errors>\n ✅ build: passed (<N>s)\n ❌ test: <N> failed, <M> passed (<N>s)\n FAIL <file> > <test name>\n <error message>\n ⚠️ lint: <N> warnings, no errors (<N>s)\n ⏭️ lint: skipped: not configured\n\n If all pass:\n **Result:** ✅ All checks passed.\n\n If any fail:\n **Result:** ❌ <N> check(s) failed. See details above.\n\n # Phase 4: Machine-readable status\n\n You MUST end your response with a machine-readable `[verification_status]` block:\n\n On success:\n ```\n [verification_status]\n passed: true\n command: <the primary verification command that was run>\n exit_code: 0\n ```\n\n On failure:\n ```\n [verification_status]\n passed: false\n command: <command that failed>\n exit_code: <non-zero exit code>\n ```\n\n If no supported project type was detected:\n ```\n [verification_status]\n passed: true\n command: none\n exit_code: 0\n ```\n\n # Rules\n\n - Do NOT try to fix anything. Report only.\n - Do NOT ask questions. Run and report.\n - Do NOT run runtime smoke tests as a substitute for a failed typecheck/build/test.\n - Skip commands whose scripts/tools don't exist — mark as \"⏭️ skipped: not configured\".\n - If the SAME test was already failing before this change (the parent agent will tell you), mark it \"⏭️ pre-existing\" not \"❌\".\n\nwhenToUse: |\n Verification specialist. Detects project type deterministically and runs\n build, test, lint, and typecheck commands. Use after writing or modifying code to\n confirm correctness before delivering to the user.\ntools:\n - Bash\n - Read\n - Glob\n - Grep\n - MemoryLookup\n - MemoryConsolidatePlan\n - MemoryConsolidateApply\n",
95981
96380
  "profile/default/writer.yaml": "extends: agent\nname: writer\npromptVars:\n roleAdditional: |\n You are now running as a subagent. All the `user` messages are sent by the main agent. The main agent cannot see your context, it can only see your last message when you finish the task. You must treat the parent agent as your caller. Do not directly ask the end user questions. If something is unclear, explain the ambiguity in your final summary to the parent agent.\n\n You are a content production and research specialist. Your output is not merely text — it is structured, evidence-based analysis presented in Markdown. Every piece of content you produce must demonstrate depth, traceability, and intellectual honesty.\n\n ## Core Methodology: Three-Layer Deep Analysis\n\n Before you write a single paragraph, you must perform a three-layer analysis of the request. This is your most important responsibility. Surface-level writing is not acceptable.\n\n **Layer 1 — The Ask:** What did the user explicitly request? What is the surface-level topic, format, and scope?\n\n **Layer 2 — The Purpose:** Why does the user want this? What decision will this content inform? What outcome are they trying to achieve? If the request is a report, who is the audience and what do they need to decide? If it is an analysis, what hypothesis is being tested?\n\n **Layer 3 — The Origin:** How did this purpose come to be? What is the broader context, market force, organizational pressure, or personal motivation that created this need? What would happen if this need were left unaddressed?\n\n Your final output must reflect all three layers. The content should not just describe — it should explain, contextualize, and anticipate. The reader should finish reading and think, \"This person truly understands why I needed this.\"\n\n ## Your Strengths\n\n - **Multi-dimensional analysis**: You do not settle for a single angle. You examine topics through multiple lenses — economic, technical, social, temporal, competitive — and synthesize them into a coherent narrative.\n - **Evidence-based writing**: Every significant claim has a source. You prefer primary sources and data over secondary opinion. You cite sources inline or in a dedicated Evidence section.\n - **Objective rigor**: You distinguish fact from inference and inference from speculation. You present counter-arguments. You flag uncertainty explicitly rather than hiding it behind confident language.\n - **Table precision**: When data is involved, you present it in clean, accurate Markdown tables. You verify column alignment, unit consistency, and mathematical correctness before outputting.\n\n ## Guidelines\n\n ### Deep Analysis\n - Start every substantial piece with a \"Why This Matters\" section that captures your three-layer analysis.\n - Do not merely list facts. Explain the relationships between them. Cause and effect, trade-offs, second-order consequences.\n - When comparing options, use a structured comparison table that covers all relevant dimensions, not just the obvious ones.\n - Anticipate the reader's next three questions and address them proactively.\n\n ### Sources and Evidence\n - For data claims, cite the source. Prefer: `SearchWeb`, `FetchURL`, or files provided by the caller.\n - If you cannot verify a claim, say so explicitly: \"This figure could not be independently verified.\"\n - Distinguish between \"confirmed\" (you checked it), \"reported\" (a source claims it), and \"estimated\" (your inference).\n - Include an Evidence section in your output listing sources and verification methods.\n\n ### Objectivity\n - Present both supporting and contradicting evidence.\n - Avoid adjectives that imply certainty without proof: \"obviously\", \"undoubtedly\", \"inevitably\".\n - Use probabilistic language when appropriate: \"based on current data, the most likely outcome is...\"\n - Separate \"what is\" (fact) from \"what it means\" (interpretation) from \"what should be done\" (recommendation).\n\n ### Markdown Tables (Mandatory for Data)\n - All tables use standard Markdown pipe syntax.\n - Headers are bold and semantically clear.\n - Numbers are right-aligned; text is left-aligned; status/tags are centered.\n - Every table has a descriptive caption above it (e.g., \"Table 1: Q1-Q4 Revenue by Region\").\n - Keep columns ≤ 8. If more are needed, split into related tables.\n - Verify arithmetic: totals, percentages, and growth rates must be correct.\n - Use consistent units within a column.\n\n ### Content Structure\n - Use clear heading hierarchies (`#`, `##`, `###`).\n - Each major section begins with a concise summary of what the section covers.\n - Each major section ends with a \"So What\" takeaway that connects the facts back to the reader's purpose.\n - Complex comparisons always use tables. Narrative descriptions of tabular data are insufficient.\n\n ## Output Format\n\n Your final response must include:\n\n ```markdown\n ## SUMMARY\n A concise executive summary capturing the three-layer analysis and key conclusions.\n\n ## WHY THIS MATTERS\n The three-layer deep analysis (Ask → Purpose → Origin) that frames everything below.\n\n ## [Main Content Sections]\n The body of the analysis, report, or document.\n\n ## EVIDENCE\n - Source A: description and verification method\n - Source B: description and verification method\n\n ## RISKS & LIMITATIONS\n What is uncertain, unverified, or context-dependent in this analysis.\n ```\n\n ## Important Reminders\n\n - Your only output is Markdown content. You do not generate .docx, .pdf, or any other format.\n - If the caller asks for a specific file format, output Markdown and note that format conversion is the caller's responsibility.\n - If the user provides a template or sample file, Read it first and match its depth, tone, and structure.\n - After writing, verify: logical self-consistency, source accuracy, table arithmetic, and structural completeness.\n - Never fabricate data. If data is missing, say so and explain the impact of the gap.\nwhenToUse: |\n Use this agent when the task involves producing substantial written content that requires depth: research reports, competitive analysis, data-driven documents, strategic proposals, or any work where understanding the \"why\" behind the request is as important as the \"what.\" This agent excels at multi-dimensional analysis, evidence-based reasoning, and structured Markdown output with precise tables.\ntools:\n - Bash\n - Read\n - ReadMediaFile\n - Glob\n - Grep\n - Write\n - Edit\n - WebSearch\n - FetchURL\n - MemoryLookup\n - MemoryConsolidatePlan\n - MemoryConsolidateApply\n - mcp__*\n"
95982
96381
  };
@@ -96695,7 +97094,8 @@ function isMutatingTool(toolName) {
96695
97094
  * to try a different approach.
96696
97095
  * - Storm Breaker: when a mutating tool is called repeatedly on the same target
96697
97096
  * within a sliding window (default size 6), the call is suppressed entirely
96698
- * and an error result is returned to the model.
97097
+ * and a friendly advisory result is returned to the model (non-error, so the
97098
+ * TUI renders it as normal output rather than a failed tool call).
96699
97099
  */
96700
97100
  var ToolCallDeduplicator = class {
96701
97101
  stepDeferreds = /* @__PURE__ */ new Map();
@@ -96755,10 +97155,7 @@ var ToolCallDeduplicator = class {
96755
97155
  const key = makeKey(toolName, args);
96756
97156
  if (isMutatingTool(toolName)) {
96757
97157
  const priorCount = this.stormWindow.filter((e) => e.key === key).length;
96758
- if (priorCount >= this.stormThreshold - 1) return {
96759
- output: `Storm Breaker: ${toolName} 对同一目标已连续调用 ${String(priorCount + 1)} 次。请制定计划后再执行,或尝试不同的方法。`,
96760
- isError: true
96761
- };
97158
+ if (priorCount >= this.stormThreshold - 1) return { output: `Storm Breaker(风暴守护者):检测到无效循环调用风险——${toolName} 对同一目标已连续调用 ${String(priorCount + 1)} 次。建议先制定计划方案,或更换其他方法后再继续。` };
96762
97159
  }
96763
97160
  const index = this.stepCalls.length;
96764
97161
  this.stepCalls.push(key);
@@ -97699,6 +98096,7 @@ var LtodLLM = class {
97699
98096
  provider;
97700
98097
  generate;
97701
98098
  completionBudgetConfig;
98099
+ obfuscator;
97702
98100
  constructor(config) {
97703
98101
  this.provider = config.provider;
97704
98102
  this.modelName = config.modelName;
@@ -97706,6 +98104,7 @@ var LtodLLM = class {
97706
98104
  this.capability = config.capability;
97707
98105
  this.generate = config.generate ?? generate;
97708
98106
  this.completionBudgetConfig = config.completionBudgetConfig;
98107
+ this.obfuscator = config.obfuscator;
97709
98108
  }
97710
98109
  async chat(params) {
97711
98110
  let requestStartedAt = Date.now();
@@ -97720,22 +98119,26 @@ var LtodLLM = class {
97720
98119
  const markStreamOutput = () => {
97721
98120
  firstChunkAt ??= Date.now();
97722
98121
  };
97723
- const callbacks = buildLtodCallbacks(params, markStreamOutput);
98122
+ const { callbacks, flushPending } = buildLtodCallbacks(params, markStreamOutput, this.obfuscator);
97724
98123
  const effectiveProvider = applyCompletionBudget({
97725
98124
  provider: this.provider,
97726
98125
  budget: this.completionBudgetConfig,
97727
98126
  capability: this.capability
97728
98127
  });
97729
- const result = await this.generate(effectiveProvider, this.systemPrompt, [...params.tools], params.messages, callbacks, generateOptions(params, {
98128
+ const outboundMessages = this.obfuscator && this.obfuscator.hasSecrets() ? obfuscateMessages(this.obfuscator, params.messages) : params.messages;
98129
+ const result = await this.generate(effectiveProvider, this.systemPrompt, [...params.tools], outboundMessages, callbacks, generateOptions(params, {
97730
98130
  onRequestStart: markRequestStart,
97731
- onStreamEnd: markStreamEnd
98131
+ onStreamEnd: () => {
98132
+ markStreamEnd();
98133
+ flushPending();
98134
+ }
97732
98135
  }));
97733
98136
  if (params.onTextPart !== void 0 || params.onThinkPart !== void 0) {
97734
98137
  for (const part of result.message.content) if (part.type === "text" && params.onTextPart !== void 0) await params.onTextPart(part);
97735
98138
  else if (part.type === "think" && params.onThinkPart !== void 0) await params.onThinkPart(part);
97736
98139
  }
97737
98140
  return {
97738
- toolCalls: [...result.message.toolCalls],
98141
+ toolCalls: this.obfuscator && this.obfuscator.hasSecrets() ? deobfuscateToolCalls(this.obfuscator, result.message.toolCalls) : [...result.message.toolCalls],
97739
98142
  providerFinishReason: result.finishReason ?? void 0,
97740
98143
  rawFinishReason: result.rawFinishReason ?? void 0,
97741
98144
  usage: result.usage ?? emptyUsage(),
@@ -97761,78 +98164,129 @@ function generateOptions(params, hooks) {
97761
98164
  [GENERATE_REQUEST_LOG_CONTEXT]: params.requestLogContext
97762
98165
  };
97763
98166
  }
97764
- function buildLtodCallbacks(params, markStreamOutput) {
98167
+ function buildLtodCallbacks(params, markStreamOutput, obfuscator) {
97765
98168
  const toolCallIdentities = /* @__PURE__ */ new Map();
97766
98169
  const pendingIndexedToolCallDeltas = /* @__PURE__ */ new Map();
97767
98170
  let lastToolCallIdentity;
98171
+ let pendingTextTail = "";
98172
+ let pendingThinkTail = "";
98173
+ const pendingToolCallTails = /* @__PURE__ */ new Map();
98174
+ const PARTIAL_PLACEHOLDER_RE = /#[A-Z2-9]{0,6}$/;
98175
+ const deobfuscateWithBuffer = (text, setBuffer, getBuffer) => {
98176
+ if (obfuscator === void 0 || !obfuscator.hasSecrets()) return getBuffer() + text;
98177
+ const combined = getBuffer() + text;
98178
+ setBuffer("");
98179
+ const deobfuscated = obfuscator.deobfuscate(combined);
98180
+ const partialMatch = deobfuscated.match(PARTIAL_PLACEHOLDER_RE);
98181
+ if (partialMatch !== null && partialMatch[0].length > 0) {
98182
+ setBuffer(partialMatch[0]);
98183
+ return deobfuscated.slice(0, deobfuscated.length - partialMatch[0].length);
98184
+ }
98185
+ return deobfuscated;
98186
+ };
97768
98187
  const emitToolCallDelta = (delta) => {
97769
98188
  if (params.onToolCallDelta === void 0) return;
98189
+ if (delta.argumentsPart !== void 0) {
98190
+ const id = delta.toolCallId;
98191
+ const out = deobfuscateWithBuffer(delta.argumentsPart, (v) => pendingToolCallTails.set(id, v), () => pendingToolCallTails.get(id) ?? "");
98192
+ if (out.length > 0) delta = {
98193
+ ...delta,
98194
+ argumentsPart: out
98195
+ };
98196
+ else return;
98197
+ }
97770
98198
  params.onToolCallDelta(delta);
97771
98199
  };
97772
- return { onMessagePart: (part) => {
97773
- markStreamOutput();
97774
- if (part.type === "text") {
97775
- if (params.onTextDelta === void 0) return;
97776
- params.onTextDelta(part.text);
97777
- return;
97778
- }
97779
- if (part.type === "think") {
97780
- if (params.onThinkDelta === void 0) return;
97781
- params.onThinkDelta(part.think);
97782
- return;
97783
- }
97784
- if (part.type === "function") {
97785
- const identity = {
97786
- toolCallId: part.id,
97787
- name: part.name
97788
- };
97789
- lastToolCallIdentity = identity;
97790
- if (part._streamIndex !== void 0) toolCallIdentities.set(part._streamIndex, identity);
97791
- emitToolCallDelta({
97792
- toolCallId: part.id,
97793
- name: part.name,
97794
- ...part.arguments !== null ? { argumentsPart: part.arguments } : {}
97795
- });
97796
- if (part._streamIndex !== void 0) {
97797
- const pendingDeltas = pendingIndexedToolCallDeltas.get(part._streamIndex);
97798
- if (pendingDeltas !== void 0) {
97799
- pendingIndexedToolCallDeltas.delete(part._streamIndex);
97800
- for (const delta of pendingDeltas) emitToolCallDelta({
98200
+ return {
98201
+ callbacks: { onMessagePart: (part) => {
98202
+ markStreamOutput();
98203
+ if (part.type === "text") {
98204
+ if (params.onTextDelta === void 0) return;
98205
+ const out = deobfuscateWithBuffer(part.text, (v) => {
98206
+ pendingTextTail = v;
98207
+ }, () => pendingTextTail);
98208
+ if (out.length > 0) params.onTextDelta(out);
98209
+ return;
98210
+ }
98211
+ if (part.type === "think") {
98212
+ if (params.onThinkDelta === void 0) return;
98213
+ const out = deobfuscateWithBuffer(part.think, (v) => {
98214
+ pendingThinkTail = v;
98215
+ }, () => pendingThinkTail);
98216
+ if (out.length > 0) params.onThinkDelta(out);
98217
+ return;
98218
+ }
98219
+ if (part.type === "function") {
98220
+ const identity = {
98221
+ toolCallId: part.id,
98222
+ name: part.name
98223
+ };
98224
+ lastToolCallIdentity = identity;
98225
+ if (part._streamIndex !== void 0) toolCallIdentities.set(part._streamIndex, identity);
98226
+ emitToolCallDelta({
98227
+ toolCallId: part.id,
98228
+ name: part.name,
98229
+ ...part.arguments !== null ? { argumentsPart: part.arguments } : {}
98230
+ });
98231
+ if (part._streamIndex !== void 0) {
98232
+ const pendingDeltas = pendingIndexedToolCallDeltas.get(part._streamIndex);
98233
+ if (pendingDeltas !== void 0) {
98234
+ pendingIndexedToolCallDeltas.delete(part._streamIndex);
98235
+ for (const delta of pendingDeltas) emitToolCallDelta({
98236
+ toolCallId: identity.toolCallId,
98237
+ name: identity.name,
98238
+ ...delta
98239
+ });
98240
+ }
98241
+ }
98242
+ return;
98243
+ }
98244
+ if (part.type === "tool_call_part") {
98245
+ const argumentsPart = part.argumentsPart;
98246
+ const delta = argumentsPart !== null ? { argumentsPart } : {};
98247
+ if (part.index !== void 0) {
98248
+ const identity = toolCallIdentities.get(part.index);
98249
+ if (identity === void 0) {
98250
+ const pendingDeltas = pendingIndexedToolCallDeltas.get(part.index) ?? [];
98251
+ pendingDeltas.push(delta);
98252
+ pendingIndexedToolCallDeltas.set(part.index, pendingDeltas);
98253
+ return;
98254
+ }
98255
+ emitToolCallDelta({
97801
98256
  toolCallId: identity.toolCallId,
97802
98257
  name: identity.name,
97803
98258
  ...delta
97804
98259
  });
97805
- }
97806
- }
97807
- return;
97808
- }
97809
- if (part.type === "tool_call_part") {
97810
- const argumentsPart = part.argumentsPart;
97811
- const delta = argumentsPart !== null ? { argumentsPart } : {};
97812
- if (part.index !== void 0) {
97813
- const identity = toolCallIdentities.get(part.index);
97814
- if (identity === void 0) {
97815
- const pendingDeltas = pendingIndexedToolCallDeltas.get(part.index) ?? [];
97816
- pendingDeltas.push(delta);
97817
- pendingIndexedToolCallDeltas.set(part.index, pendingDeltas);
97818
98260
  return;
97819
98261
  }
98262
+ const identity = lastToolCallIdentity;
98263
+ if (identity === void 0) return;
97820
98264
  emitToolCallDelta({
97821
98265
  toolCallId: identity.toolCallId,
97822
98266
  name: identity.name,
97823
98267
  ...delta
97824
98268
  });
97825
- return;
97826
98269
  }
97827
- const identity = lastToolCallIdentity;
97828
- if (identity === void 0) return;
97829
- emitToolCallDelta({
97830
- toolCallId: identity.toolCallId,
97831
- name: identity.name,
97832
- ...delta
97833
- });
98270
+ } },
98271
+ flushPending: () => {
98272
+ if (pendingTextTail.length > 0 && params.onTextDelta !== void 0) {
98273
+ params.onTextDelta(pendingTextTail);
98274
+ pendingTextTail = "";
98275
+ }
98276
+ if (pendingThinkTail.length > 0 && params.onThinkDelta !== void 0) {
98277
+ params.onThinkDelta(pendingThinkTail);
98278
+ pendingThinkTail = "";
98279
+ }
98280
+ if (params.onToolCallDelta !== void 0) {
98281
+ for (const [id, tail] of pendingToolCallTails) if (tail.length > 0) params.onToolCallDelta({
98282
+ toolCallId: id,
98283
+ name: "",
98284
+ argumentsPart: tail
98285
+ });
98286
+ pendingToolCallTails.clear();
98287
+ }
97834
98288
  }
97835
- } };
98289
+ };
97836
98290
  }
97837
98291
  //#endregion
97838
98292
  //#region ../../packages/agent-core/src/agent/usage/index.ts
@@ -98033,9 +98487,19 @@ var Agent = class {
98033
98487
  systemPrompt: this.config.systemPrompt,
98034
98488
  capability: this.config.modelCapabilities,
98035
98489
  generate: this.generate,
98036
- completionBudgetConfig
98490
+ completionBudgetConfig,
98491
+ obfuscator: this.obfuscator
98037
98492
  });
98038
98493
  }
98494
+ _obfuscator;
98495
+ _obfuscatorConfigRef;
98496
+ get obfuscator() {
98497
+ if (this._obfuscatorConfigRef === this.screamConfig && this._obfuscator !== void 0) return this._obfuscator;
98498
+ this._obfuscatorConfigRef = this.screamConfig;
98499
+ const userEntries = this.screamConfig?.secrets ?? [];
98500
+ this._obfuscator = new SecretObfuscator([...DEFAULT_SECRET_PATTERNS, ...userEntries]);
98501
+ return this._obfuscator;
98502
+ }
98039
98503
  logLlmRequest(provider, systemPrompt, tools, history, options) {
98040
98504
  const context = buildLlmRequestContext(options);
98041
98505
  const configMetadata = buildLlmConfigMetadata(provider, this.config.modelAlias, systemPrompt, tools);
@@ -98301,10 +98765,12 @@ var Agent = class {
98301
98765
  this.emitEvent({
98302
98766
  type: "agent.status.updated",
98303
98767
  model,
98768
+ thinkingLevel: this.config.thinkingLevel,
98304
98769
  contextTokens,
98305
98770
  maxContextTokens,
98306
98771
  contextUsage,
98307
98772
  planMode: this.planMode.isActive,
98773
+ planStrategy: this.planMode.isActive ? this.planMode.strategy : void 0,
98308
98774
  permission: this.permission.mode,
98309
98775
  usage
98310
98776
  });
@@ -98402,20 +98868,6 @@ function isPlainObject$2(value) {
98402
98868
  return typeof value === "object" && value !== null && !Array.isArray(value);
98403
98869
  }
98404
98870
  //#endregion
98405
- //#region ../../packages/agent-core/src/config/path.ts
98406
- function resolveScreamHome(homeDir) {
98407
- return homeDir ?? process.env["SCREAM_CODE_HOME"] ?? join$1(homedir(), ".scream-code");
98408
- }
98409
- function resolveConfigPath$1(input) {
98410
- return input.configPath ?? join$1(resolveScreamHome(input.homeDir), "config.toml");
98411
- }
98412
- function ensureScreamHome(homeDir) {
98413
- mkdirSync(homeDir, {
98414
- recursive: true,
98415
- mode: 448
98416
- });
98417
- }
98418
- //#endregion
98419
98871
  //#region ../../packages/agent-core/src/config/env-model.ts
98420
98872
  /** Reserved keys for the env-driven synthetic provider / model alias. */
98421
98873
  const ENV_MODEL_PROVIDER_KEY = "__scream_env__";
@@ -102922,7 +103374,9 @@ var Session$1 = class {
102922
103374
  ...this.metadata.custom,
102923
103375
  recap
102924
103376
  };
102925
- this.writeMetadata();
103377
+ this.writeMetadata().catch((error) => {
103378
+ this.log.error("failed to write session recap metadata", error);
103379
+ });
102926
103380
  }
102927
103381
  }
102928
103382
  try {
@@ -102962,7 +103416,9 @@ var Session$1 = class {
102962
103416
  type,
102963
103417
  parentAgentId: parentAgentId ?? null
102964
103418
  };
102965
- this.writeMetadata();
103419
+ this.writeMetadata().catch((error) => {
103420
+ this.log.error("failed to write session metadata after agent creation", error);
103421
+ });
102966
103422
  return {
102967
103423
  id,
102968
103424
  agent
@@ -103018,7 +103474,7 @@ var Session$1 = class {
103018
103474
  });
103019
103475
  await this.options.jian.writeText(this.metadataPath, text);
103020
103476
  };
103021
- this.writeMetadataPromise = this.writeMetadataPromise.then(write, write);
103477
+ this.writeMetadataPromise = this.writeMetadataPromise.then(() => write());
103022
103478
  return this.writeMetadataPromise;
103023
103479
  }
103024
103480
  async readMetadata() {
@@ -120730,7 +121186,7 @@ var Session = class {
120730
121186
  }
120731
121187
  async compact(options = {}) {
120732
121188
  this.ensureOpen();
120733
- const instruction = normalizeOptionalString(options.instruction);
121189
+ const instruction = normalizeOptionalString$1(options.instruction);
120734
121190
  await this.rpc.compact({
120735
121191
  sessionId: this.id,
120736
121192
  ...instruction !== void 0 ? { instruction } : {}
@@ -120906,7 +121362,7 @@ var Session = class {
120906
121362
  async activateSkill(name, args) {
120907
121363
  this.ensureOpen();
120908
121364
  const skillName = normalizeRequiredString(name, "Skill name cannot be empty", ErrorCodes.SKILL_NAME_EMPTY);
120909
- const skillArgs = normalizeOptionalString(args);
121365
+ const skillArgs = normalizeOptionalString$1(args);
120910
121366
  await this.rpc.activateSkill({
120911
121367
  sessionId: this.id,
120912
121368
  name: skillName,
@@ -121033,7 +121489,7 @@ function normalizeRequiredString(value, message, code) {
121033
121489
  if (normalized.length === 0) throw new ScreamError(code, message);
121034
121490
  return normalized;
121035
121491
  }
121036
- function normalizeOptionalString(value) {
121492
+ function normalizeOptionalString$1(value) {
121037
121493
  if (value === void 0) return void 0;
121038
121494
  const normalized = value.trim();
121039
121495
  return normalized.length > 0 ? normalized : void 0;
@@ -121310,8 +121766,14 @@ function applyCatalogProvider(config, options) {
121310
121766
  for (const model of options.models) models[`${options.providerId}/${model.id}`] = catalogModelToAlias(options.providerId, model);
121311
121767
  config.models = models;
121312
121768
  const defaultModel = `${options.providerId}/${options.selectedModelId}`;
121769
+ const thinkingLevel = options.thinkingLevel ?? (options.thinking === true ? "medium" : "off");
121313
121770
  config.defaultModel = defaultModel;
121314
- config.defaultThinking = options.thinking;
121771
+ config.defaultThinking = thinkingLevel !== "off";
121772
+ config.thinking = {
121773
+ ...config.thinking,
121774
+ mode: thinkingLevel === "off" ? "off" : "on",
121775
+ effort: thinkingLevel
121776
+ };
121315
121777
  return { defaultModel };
121316
121778
  }
121317
121779
  //#endregion
@@ -121322,6 +121784,7 @@ const CLI_USER_AGENT_PRODUCT = "scream-code-cli";
121322
121784
  const CLI_UI_MODE = "shell";
121323
121785
  const SCREAM_CODE_HOME_ENV = "SCREAM_CODE_HOME";
121324
121786
  const SCREAM_CODE_DATA_DIR_NAME = ".scream-code";
121787
+ const SCREAM_CODE_LOG_DIR_NAME = "logs";
121325
121788
  const SCREAM_CODE_UPDATE_DIR_NAME = "updates";
121326
121789
  const SCREAM_CODE_UPDATE_STATE_FILE_NAME = "latest.json";
121327
121790
  const SCREAM_CODE_INPUT_HISTORY_DIR_NAME = "user-history";
@@ -121436,6 +121899,12 @@ function getDataDir() {
121436
121899
  return join(homedir(), SCREAM_CODE_DATA_DIR_NAME);
121437
121900
  }
121438
121901
  /**
121902
+ * Return the diagnostic log directory: `<dataDir>/logs/`.
121903
+ */
121904
+ function getLogDir() {
121905
+ return join(getDataDir(), SCREAM_CODE_LOG_DIR_NAME);
121906
+ }
121907
+ /**
121439
121908
  * Return the update cache file: `<dataDir>/updates/latest.json`.
121440
121909
  */
121441
121910
  function getUpdateStateFile() {
@@ -121706,6 +122175,7 @@ async function runPrompt(opts, version, io = {}) {
121706
122175
  workDir
121707
122176
  });
121708
122177
  let restorePromptSessionPermission = async () => {};
122178
+ let cleanupEphemeralSession = async () => {};
121709
122179
  let removeTerminationCleanup;
121710
122180
  let cleanupPromise;
121711
122181
  const cleanupPromptRun = async () => {
@@ -121714,7 +122184,11 @@ async function runPrompt(opts, version, io = {}) {
121714
122184
  try {
121715
122185
  await restorePromptSessionPermission();
121716
122186
  } finally {
121717
- await harness.close();
122187
+ try {
122188
+ await cleanupEphemeralSession();
122189
+ } finally {
122190
+ await harness.close();
122191
+ }
121718
122192
  }
121719
122193
  })();
121720
122194
  await cleanupPromise;
@@ -121722,13 +122196,19 @@ async function runPrompt(opts, version, io = {}) {
121722
122196
  removeTerminationCleanup = installPromptTerminationCleanup(promptProcess, cleanupPromptRun);
121723
122197
  try {
121724
122198
  await harness.ensureConfigFile();
121725
- const { session, restorePermission } = await resolvePromptSession(harness, opts, workDir, (await harness.getConfig()).defaultModel, stderr, (restorePermission) => {
122199
+ const { session, resumed, restorePermission } = await resolvePromptSession(harness, opts, workDir, (await harness.getConfig()).defaultModel, stderr, (restorePermission) => {
121726
122200
  restorePromptSessionPermission = restorePermission;
121727
122201
  });
121728
122202
  restorePromptSessionPermission = restorePermission;
122203
+ if (process.env["SCREAM_FUSIONPLAN_SUBAGENT"] === "1" && !resumed) {
122204
+ const ephemeralSessionId = session.id;
122205
+ cleanupEphemeralSession = async () => {
122206
+ await harness.deleteSession(ephemeralSessionId).catch(() => {});
122207
+ };
122208
+ }
121729
122209
  const outputFormat = opts.outputFormat ?? "text";
121730
122210
  await runPromptTurn(session, opts.prompt, outputFormat, stdout, stderr);
121731
- writeResumeHint(session.id, outputFormat, stdout, stderr);
122211
+ if (process.env["SCREAM_FUSIONPLAN_SUBAGENT"] !== "1") writeResumeHint(session.id, outputFormat, stdout, stderr);
121732
122212
  } finally {
121733
122213
  await cleanupPromptRun();
121734
122214
  }
@@ -122148,18 +122628,33 @@ const NotificationsConfigSchema = z.object({
122148
122628
  enabled: z.boolean(),
122149
122629
  condition: NotificationConditionSchema
122150
122630
  });
122631
+ const TuiLikePreferencesSchema = z.object({
122632
+ nickname: z.string().optional(),
122633
+ tone: z.string().optional(),
122634
+ other: z.string().optional()
122635
+ });
122151
122636
  const TuiConfigFileSchema = z.object({
122152
122637
  theme: TuiThemeSchema.optional(),
122153
122638
  editor: z.object({ command: z.string().optional() }).optional(),
122154
122639
  notifications: z.object({
122155
122640
  enabled: z.boolean().optional(),
122156
122641
  notification_condition: NotificationConditionSchema.optional()
122642
+ }).optional(),
122643
+ like: TuiLikePreferencesSchema.optional(),
122644
+ fusionPlan: z.object({
122645
+ timeoutSeconds: z.number().int().min(30).max(3600).optional(),
122646
+ workerCount: z.number().int().min(1).max(8).optional()
122157
122647
  }).optional()
122158
122648
  });
122159
122649
  const TuiConfigSchema = z.object({
122160
122650
  theme: TuiThemeSchema,
122161
122651
  editorCommand: z.string().nullable(),
122162
- notifications: NotificationsConfigSchema
122652
+ notifications: NotificationsConfigSchema,
122653
+ like: TuiLikePreferencesSchema,
122654
+ fusionPlan: z.object({
122655
+ timeoutSeconds: z.number().int().min(30).max(3600),
122656
+ workerCount: z.number().int().min(1).max(8)
122657
+ })
122163
122658
  });
122164
122659
  const DEFAULT_NOTIFICATIONS_CONFIG = {
122165
122660
  enabled: true,
@@ -122168,13 +122663,17 @@ const DEFAULT_NOTIFICATIONS_CONFIG = {
122168
122663
  const DEFAULT_TUI_CONFIG = TuiConfigSchema.parse({
122169
122664
  theme: "auto",
122170
122665
  editorCommand: null,
122171
- notifications: DEFAULT_NOTIFICATIONS_CONFIG
122666
+ notifications: DEFAULT_NOTIFICATIONS_CONFIG,
122667
+ like: {},
122668
+ fusionPlan: {
122669
+ timeoutSeconds: 600,
122670
+ workerCount: 3
122671
+ }
122172
122672
  });
122173
122673
  /**
122174
122674
  * Thrown by `loadTuiConfig` when the on-disk TOML cannot be parsed.
122175
122675
  * Carries `fallback` so the caller can recover without re-running the
122176
- * I/O, and use `message` (== `INVALID_TUI_CONFIG_MESSAGE`) as a
122177
- * user-facing notice.
122676
+ * discovery code.
122178
122677
  */
122179
122678
  var TuiConfigParseError = class extends Error {
122180
122679
  name = "TuiConfigParseError";
@@ -122209,16 +122708,35 @@ async function saveTuiConfig(config, filePath = getTuiConfigPath()) {
122209
122708
  }
122210
122709
  function normalizeTuiConfig(config) {
122211
122710
  const command = config.editor?.command?.trim();
122711
+ const like = config.like ?? {};
122712
+ const fusionPlan = config.fusionPlan ?? {};
122212
122713
  return TuiConfigSchema.parse({
122213
122714
  theme: config.theme ?? DEFAULT_TUI_CONFIG.theme,
122214
122715
  editorCommand: command === void 0 || command.length === 0 ? null : command,
122215
122716
  notifications: {
122216
122717
  enabled: config.notifications?.enabled ?? DEFAULT_NOTIFICATIONS_CONFIG.enabled,
122217
122718
  condition: config.notifications?.notification_condition ?? DEFAULT_NOTIFICATIONS_CONFIG.condition
122719
+ },
122720
+ like: {
122721
+ nickname: normalizeOptionalString(like.nickname),
122722
+ tone: normalizeOptionalString(like.tone),
122723
+ other: normalizeOptionalString(like.other)
122724
+ },
122725
+ fusionPlan: {
122726
+ timeoutSeconds: fusionPlan.timeoutSeconds ?? DEFAULT_TUI_CONFIG.fusionPlan.timeoutSeconds,
122727
+ workerCount: fusionPlan.workerCount ?? DEFAULT_TUI_CONFIG.fusionPlan.workerCount
122218
122728
  }
122219
122729
  });
122220
122730
  }
122731
+ function normalizeOptionalString(value) {
122732
+ if (value === void 0) return void 0;
122733
+ const trimmed = value.trim();
122734
+ return trimmed.length > 0 ? trimmed : void 0;
122735
+ }
122221
122736
  function renderTuiConfig(config) {
122737
+ const nickname = escapeTomlBasicString(config.like.nickname ?? "");
122738
+ const tone = escapeTomlBasicString(config.like.tone ?? "");
122739
+ const other = escapeTomlBasicString(config.like.other ?? "");
122222
122740
  return `# ~/.scream-code/tui.toml
122223
122741
  # Terminal UI preferences for scream-code.
122224
122742
  # Agent/runtime settings stay in ~/.scream-code/config.toml.
@@ -122231,6 +122749,15 @@ command = "${escapeTomlBasicString(config.editorCommand ?? "")}" # Empty uses $V
122231
122749
  [notifications]
122232
122750
  enabled = ${String(config.notifications.enabled)} # true | false
122233
122751
  notification_condition = "${config.notifications.condition}" # "unfocused" | "always"
122752
+
122753
+ [like]
122754
+ nickname = "${nickname}"
122755
+ tone = "${tone}"
122756
+ other = "${other}"
122757
+
122758
+ [fusionPlan]
122759
+ timeoutSeconds = ${config.fusionPlan.timeoutSeconds} # 30..3600, default 600
122760
+ workerCount = ${config.fusionPlan.workerCount} # 1..8, default 3
122234
122761
  `;
122235
122762
  }
122236
122763
  function escapeTomlBasicString(value) {
@@ -122391,6 +122918,13 @@ const BUILTIN_SLASH_COMMANDS = [
122391
122918
  priority: 118,
122392
122919
  availability: (args) => args.trim().toLowerCase() === "clear" ? "idle-only" : "always"
122393
122920
  },
122921
+ {
122922
+ name: "fusionplan",
122923
+ aliases: ["fp"],
122924
+ description: "切换融合计划模式(多子代理并行规划)",
122925
+ priority: 118,
122926
+ availability: (args) => args.trim().toLowerCase() === "clear" ? "idle-only" : "always"
122927
+ },
122394
122928
  {
122395
122929
  name: "tasks",
122396
122930
  aliases: ["task"],
@@ -122426,6 +122960,13 @@ const BUILTIN_SLASH_COMMANDS = [
122426
122960
  priority: 113,
122427
122961
  availability: "always"
122428
122962
  },
122963
+ {
122964
+ name: "like",
122965
+ aliases: [],
122966
+ description: "设置你的偏好(昵称、语气、其他偏好)",
122967
+ priority: 113,
122968
+ availability: "always"
122969
+ },
122429
122970
  {
122430
122971
  name: "mcp",
122431
122972
  aliases: [],
@@ -123137,6 +123678,12 @@ function optionLabelStyle(option, selected, colors) {
123137
123678
  }
123138
123679
  //#endregion
123139
123680
  //#region src/tui/components/dialogs/model-selector.ts
123681
+ const DEFAULT_THINKING_LEVELS = [
123682
+ "off",
123683
+ "low",
123684
+ "medium",
123685
+ "high"
123686
+ ];
123140
123687
  function modelDisplayName$1(alias, model) {
123141
123688
  return model?.displayName ?? model?.model ?? alias;
123142
123689
  }
@@ -123158,11 +123705,17 @@ function thinkingAvailability(model) {
123158
123705
  if (caps.includes("thinking") || model.adaptiveThinking === true) return "toggle";
123159
123706
  return "unsupported";
123160
123707
  }
123161
- function effectiveThinking(model, thinkingDraft) {
123708
+ function getThinkingLevels(model) {
123162
123709
  const availability = thinkingAvailability(model);
123163
- if (availability === "always-on") return true;
123164
- if (availability === "unsupported") return false;
123165
- return thinkingDraft;
123710
+ if (availability === "unsupported") return ["off"];
123711
+ const base = model.thinkingLevels ?? DEFAULT_THINKING_LEVELS;
123712
+ if (availability === "always-on") return base.filter((level) => level !== "off");
123713
+ return base;
123714
+ }
123715
+ function effectiveThinkingLevel(model, thinkingDraft) {
123716
+ const levels = getThinkingLevels(model);
123717
+ if (levels.includes(thinkingDraft)) return thinkingDraft;
123718
+ return levels[0] ?? "off";
123166
123719
  }
123167
123720
  var ModelSelectorComponent = class extends Container {
123168
123721
  focused = false;
@@ -123182,7 +123735,8 @@ var ModelSelectorComponent = class extends Container {
123182
123735
  initialIndex: Math.max(selectedIdx, 0),
123183
123736
  searchable: opts.searchable === true
123184
123737
  });
123185
- this.thinkingDraft = opts.currentThinking;
123738
+ const initialChoice = choices[selectedIdx];
123739
+ this.thinkingDraft = initialChoice !== void 0 ? effectiveThinkingLevel(initialChoice.model, opts.currentThinkingLevel) : opts.currentThinkingLevel;
123186
123740
  }
123187
123741
  handleInput(data) {
123188
123742
  if (matchesKey(data, Key.escape)) {
@@ -123191,13 +123745,17 @@ var ModelSelectorComponent = class extends Container {
123191
123745
  return;
123192
123746
  }
123193
123747
  const selected = this.list.selected();
123194
- if (selected !== void 0 && thinkingAvailability(selected.model) === "toggle") {
123748
+ if (selected !== void 0 && thinkingAvailability(selected.model) !== "unsupported") {
123749
+ const levels = getThinkingLevels(selected.model);
123750
+ const idx = levels.indexOf(this.thinkingDraft);
123195
123751
  if (matchesKey(data, Key.left)) {
123196
- this.thinkingDraft = true;
123752
+ const nextIdx = idx <= 0 ? levels.length - 1 : idx - 1;
123753
+ this.thinkingDraft = levels[nextIdx];
123197
123754
  return;
123198
123755
  }
123199
123756
  if (matchesKey(data, Key.right)) {
123200
- this.thinkingDraft = false;
123757
+ const nextIdx = idx === -1 || idx >= levels.length - 1 ? 0 : idx + 1;
123758
+ this.thinkingDraft = levels[nextIdx];
123201
123759
  return;
123202
123760
  }
123203
123761
  }
@@ -123205,7 +123763,7 @@ var ModelSelectorComponent = class extends Container {
123205
123763
  if (selected === void 0) return;
123206
123764
  this.opts.onSelect({
123207
123765
  alias: selected.alias,
123208
- thinking: effectiveThinking(selected.model, this.thinkingDraft)
123766
+ thinkingLevel: effectiveThinkingLevel(selected.model, this.thinkingDraft)
123209
123767
  });
123210
123768
  return;
123211
123769
  }
@@ -123216,7 +123774,7 @@ var ModelSelectorComponent = class extends Container {
123216
123774
  const searchable = this.opts.searchable === true;
123217
123775
  const view = this.list.view();
123218
123776
  const choices = view.items;
123219
- const navParts = ["↑↓ 模型", "←→ 思考"];
123777
+ const navParts = ["↑↓ 模型", "←→ 思考等级"];
123220
123778
  if (view.page.pageCount > 1) navParts.push("PgUp/PgDn 翻页");
123221
123779
  navParts.push("Enter 应用", "Esc 取消");
123222
123780
  const titleSuffix = searchable && view.query.length === 0 ? chalk.hex(colors.textMuted)(" (输入搜索)") : "";
@@ -123247,11 +123805,14 @@ var ModelSelectorComponent = class extends Container {
123247
123805
  }
123248
123806
  renderThinkingControl(model) {
123249
123807
  const { colors } = this.opts;
123250
- const segment = (label, active) => active ? chalk.hex(colors.primary).bold(`[ ${label} ]`) : chalk.hex(colors.text)(` ${label} `);
123251
123808
  const availability = thinkingAvailability(model);
123252
- if (availability === "always-on") return ` ${segment("Always on", true)}`;
123253
- if (availability === "unsupported") return ` ${segment("Off", true)} ${chalk.hex(colors.textMuted)("unsupported")}`;
123254
- return ` ${segment("On", this.thinkingDraft)} ${segment("Off", !this.thinkingDraft)}`;
123809
+ const levels = getThinkingLevels(model);
123810
+ const effectiveLevel = effectiveThinkingLevel(model, this.thinkingDraft);
123811
+ const line = ` ${levels.map((level) => {
123812
+ return level === effectiveLevel ? chalk.hex(colors.primary).bold(`[ ${level} ]`) : chalk.hex(colors.text)(level);
123813
+ }).join(" ")}`;
123814
+ if (availability === "unsupported") return `${line} ${chalk.hex(colors.textMuted)("unsupported")}`;
123815
+ return line;
123255
123816
  }
123256
123817
  };
123257
123818
  //#endregion
@@ -123272,6 +123833,7 @@ var TextInputDialogComponent = class extends Container {
123272
123833
  this.onDone = onDone;
123273
123834
  this.opts = opts;
123274
123835
  this.input = new Input();
123836
+ if (opts.initialValue !== void 0) this.input.setValue(opts.initialValue);
123275
123837
  this.input.onSubmit = (value) => {
123276
123838
  this.submit(value);
123277
123839
  };
@@ -123327,7 +123889,7 @@ var TextInputDialogComponent = class extends Container {
123327
123889
  submit(value) {
123328
123890
  if (this.done) return;
123329
123891
  const trimmed = value.trim();
123330
- if (trimmed.length === 0) {
123892
+ if (trimmed.length === 0 && !this.opts.allowEmpty) {
123331
123893
  this.emptyHinted = true;
123332
123894
  return;
123333
123895
  }
@@ -123410,24 +123972,23 @@ async function promptModelSelectionForCatalog(host, providerId, models) {
123410
123972
  const model = models.find((m) => `${providerId}/${m.id}` === selection.alias);
123411
123973
  return model ? {
123412
123974
  model,
123413
- thinking: selection.thinking
123975
+ thinkingLevel: selection.thinkingLevel
123414
123976
  } : void 0;
123415
123977
  }
123416
123978
  function runModelSelector(host, modelDict) {
123417
123979
  return new Promise((resolve) => {
123418
123980
  const firstAlias = Object.keys(modelDict)[0] ?? "";
123419
- const caps = modelDict[firstAlias]?.capabilities ?? [];
123420
123981
  const selector = new ModelSelectorComponent({
123421
123982
  models: modelDict,
123422
123983
  currentValue: firstAlias,
123423
- currentThinking: caps.includes("always_thinking") || caps.includes("thinking"),
123984
+ currentThinkingLevel: (modelDict[firstAlias]?.capabilities ?? []).includes("always_thinking") ? "medium" : "off",
123424
123985
  colors: host.state.theme.colors,
123425
123986
  searchable: true,
123426
- onSelect: ({ alias, thinking }) => {
123987
+ onSelect: ({ alias, thinkingLevel }) => {
123427
123988
  host.restoreEditor();
123428
123989
  resolve({
123429
123990
  alias,
123430
- thinking
123991
+ thinkingLevel
123431
123992
  });
123432
123993
  },
123433
123994
  onCancel: () => {
@@ -123447,13 +124008,24 @@ const WIRE_TYPE_OPTIONS = [{
123447
124008
  label: "Anthropic 协议",
123448
124009
  description: "适用于 Claude 系列模型"
123449
124010
  }];
123450
- const THINKING_OPTIONS = [{
123451
- value: "true",
123452
- label: "开启思考模式"
123453
- }, {
123454
- value: "false",
123455
- label: "关闭思考模式"
123456
- }];
124011
+ const THINKING_OPTIONS = [
124012
+ {
124013
+ value: "off",
124014
+ label: "关闭思考"
124015
+ },
124016
+ {
124017
+ value: "low",
124018
+ label: "低强度思考"
124019
+ },
124020
+ {
124021
+ value: "medium",
124022
+ label: "中强度思考"
124023
+ },
124024
+ {
124025
+ value: "high",
124026
+ label: "高强度思考"
124027
+ }
124028
+ ];
123457
124029
  function promptWireType(host) {
123458
124030
  return new Promise((resolve) => {
123459
124031
  const picker = new ChoicePickerComponent({
@@ -123473,7 +124045,7 @@ function promptWireType(host) {
123473
124045
  host.mountEditorReplacement(picker);
123474
124046
  });
123475
124047
  }
123476
- function promptTextInput(host, title, opts) {
124048
+ function promptTextInput$1(host, title, opts) {
123477
124049
  return new Promise((resolve) => {
123478
124050
  const dialog = new TextInputDialogComponent((result) => {
123479
124051
  host.restoreEditor();
@@ -123492,12 +124064,12 @@ function promptThinkingMode(host) {
123492
124064
  return new Promise((resolve) => {
123493
124065
  const picker = new ChoicePickerComponent({
123494
124066
  title: "思考模式",
123495
- hint: "启用后模型会先思考再回答(需要模型支持)",
124067
+ hint: "选择模型思考强度(需要模型支持)",
123496
124068
  options: THINKING_OPTIONS,
123497
124069
  colors: host.state.theme.colors,
123498
124070
  onSelect: (value) => {
123499
124071
  host.restoreEditor();
123500
- resolve(value === "true");
124072
+ resolve(value);
123501
124073
  },
123502
124074
  onCancel: () => {
123503
124075
  host.restoreEditor();
@@ -123588,7 +124160,7 @@ async function handleConnectCommand(host, args) {
123588
124160
  apiKey,
123589
124161
  models,
123590
124162
  selectedModelId: selection.model.id,
123591
- thinking: selection.thinking
124163
+ thinkingLevel: selection.thinkingLevel
123592
124164
  });
123593
124165
  await host.harness.setConfig({
123594
124166
  providers: config.providers,
@@ -123635,20 +124207,20 @@ async function handleLogoutCommand(host) {
123635
124207
  async function handleDiyConfig(host) {
123636
124208
  const wire = await promptWireType(host);
123637
124209
  if (wire === void 0) return;
123638
- const baseUrl = await promptTextInput(host, "输入服务商 API 地址", { subtitle: "例如 https://api.deepseek.com(可粘贴)" });
124210
+ const baseUrl = await promptTextInput$1(host, "输入服务商 API 地址", { subtitle: "例如 https://api.deepseek.com(可粘贴)" });
123639
124211
  if (baseUrl === void 0) return;
123640
- const apiKey = await promptTextInput(host, "输入 API Key", { subtitle: "密钥保存到 ~/.scream/config.toml(可粘贴,Esc 取消)" });
124212
+ const apiKey = await promptTextInput$1(host, "输入 API Key", { subtitle: "密钥保存到 ~/.scream/config.toml(可粘贴,Esc 取消)" });
123641
124213
  if (apiKey === void 0) return;
123642
- const modelId = await promptTextInput(host, "输入模型型号", { subtitle: "例如 deepseek-v4-flash" });
124214
+ const modelId = await promptTextInput$1(host, "输入模型型号", { subtitle: "例如 deepseek-v4-flash" });
123643
124215
  if (modelId === void 0) return;
123644
- const maxContextStr = await promptTextInput(host, "输入模型最大上下文长度 (tokens)", {
124216
+ const maxContextStr = await promptTextInput$1(host, "输入模型最大上下文长度 (tokens)", {
123645
124217
  subtitle: "默认 131072,DeepSeek V4 填 1000000",
123646
124218
  placeholder: "131072"
123647
124219
  });
123648
124220
  if (maxContextStr === void 0) return;
123649
124221
  const maxContextTokens = parseInt(maxContextStr, 10) || 131072;
123650
- const thinking = await promptThinkingMode(host);
123651
- if (thinking === void 0) return;
124222
+ const thinkingLevel = await promptThinkingMode(host);
124223
+ if (thinkingLevel === void 0) return;
123652
124224
  const providerId = `custom-${modelId.replaceAll(/[^A-Za-z0-9._-]/g, "-")}`;
123653
124225
  const catalogModel = {
123654
124226
  id: modelId,
@@ -123658,7 +124230,7 @@ async function handleDiyConfig(host) {
123658
124230
  image_in: false,
123659
124231
  video_in: false,
123660
124232
  audio_in: false,
123661
- thinking,
124233
+ thinking: thinkingLevel !== "off",
123662
124234
  tool_use: true
123663
124235
  },
123664
124236
  reasoningKey: wire === "anthropic" ? "thinking" : void 0,
@@ -123675,12 +124247,18 @@ async function handleDiyConfig(host) {
123675
124247
  models[`${providerId}/${modelId}`] = catalogModelToAlias(providerId, catalogModel);
123676
124248
  config.models = models;
123677
124249
  config.defaultModel = `${providerId}/${modelId}`;
123678
- config.defaultThinking = thinking;
124250
+ config.defaultThinking = thinkingLevel !== "off";
124251
+ config.thinking = {
124252
+ ...config.thinking,
124253
+ mode: thinkingLevel === "off" ? "off" : "on",
124254
+ effort: thinkingLevel
124255
+ };
123679
124256
  await host.harness.setConfig({
123680
124257
  providers: config.providers,
123681
124258
  models: config.models,
123682
124259
  defaultModel: config.defaultModel,
123683
- defaultThinking: config.defaultThinking
124260
+ defaultThinking: config.defaultThinking,
124261
+ thinking: config.thinking
123684
124262
  });
123685
124263
  await host.authFlow.refreshConfigAfterLogin();
123686
124264
  host.showStatus(`已连接: ${providerId} · ${modelId} (${wire})`);
@@ -123836,6 +124414,52 @@ var ThemeSelectorComponent = class extends ChoicePickerComponent {
123836
124414
  }
123837
124415
  };
123838
124416
  //#endregion
124417
+ //#region src/tui/utils/app-state.ts
124418
+ /** True when a model turn is in progress (waiting / thinking / composing). */
124419
+ function isStreaming(state) {
124420
+ return state.streamingPhase !== "idle";
124421
+ }
124422
+ /** True when the session is busy and should reject state-changing operations.
124423
+ * Covers both active streaming and context compaction. */
124424
+ function isBusy(state) {
124425
+ return isStreaming(state) || state.isCompacting;
124426
+ }
124427
+ //#endregion
124428
+ //#region src/utils/usage/usage-format.ts
124429
+ /**
124430
+ * Formatting helpers for the `/usage` slash command.
124431
+ *
124432
+ * Kept pure + ANSI-free so they're trivial to unit-test; the slash
124433
+ * command itself chalks the colour afterwards.
124434
+ */
124435
+ function formatTokenCount$1(n) {
124436
+ if (!Number.isFinite(n) || n < 0) return "0";
124437
+ if (n >= 1e6) return `${(n / 1e6).toFixed(1)}M`;
124438
+ if (n >= 1e3) return `${(n / 1e3).toFixed(1)}k`;
124439
+ return String(Math.round(n));
124440
+ }
124441
+ /**
124442
+ * Build a `[███░░░░░░░]` style bar. Returns a plain-ASCII string with
124443
+ * `filled`/`empty` glyphs — colouring is the caller's responsibility.
124444
+ */
124445
+ function renderProgressBar(ratio, width = 20, filled = "█", empty = "░") {
124446
+ const clamped = safeUsageRatio(ratio);
124447
+ const filledCount = Math.round(clamped * width);
124448
+ return filled.repeat(filledCount) + empty.repeat(Math.max(0, width - filledCount));
124449
+ }
124450
+ function safeUsageRatio(ratio) {
124451
+ return Number.isFinite(ratio) ? Math.max(0, Math.min(ratio, 1)) : 0;
124452
+ }
124453
+ /**
124454
+ * Map a usage ratio to a semantic colour token — the `/usage` renderer
124455
+ * translates these into palette hex values.
124456
+ */
124457
+ function ratioSeverity(ratio) {
124458
+ if (ratio >= .85) return "danger";
124459
+ if (ratio >= .5) return "warn";
124460
+ return "ok";
124461
+ }
124462
+ //#endregion
123839
124463
  //#region src/tui/constant/terminal.ts
123840
124464
  const QUERY_TERMINAL_THEME = `[?996n`;
123841
124465
  const TERMINAL_THEME_DARK = `[?997;1n`;
@@ -124012,6 +124636,7 @@ const darkColors = {
124012
124636
  primary: dark.green,
124013
124637
  accent: dark.tangerine400,
124014
124638
  planMode: "#00FFFF",
124639
+ fusionPlanMode: "#ffff66",
124015
124640
  text: dark.gray100,
124016
124641
  textStrong: dark.gray50,
124017
124642
  textDim: dark.gray500,
@@ -124041,6 +124666,7 @@ const lightColors = {
124041
124666
  primary: light.green,
124042
124667
  accent: light.tangerine700,
124043
124668
  planMode: "#00838F",
124669
+ fusionPlanMode: "#ffff66",
124044
124670
  text: light.gray900,
124045
124671
  textStrong: light.gray900,
124046
124672
  textDim: light.gray700,
@@ -124163,41 +124789,6 @@ function resolveThemeSync(theme) {
124163
124789
  return theme;
124164
124790
  }
124165
124791
  //#endregion
124166
- //#region src/utils/usage/usage-format.ts
124167
- /**
124168
- * Formatting helpers for the `/usage` slash command.
124169
- *
124170
- * Kept pure + ANSI-free so they're trivial to unit-test; the slash
124171
- * command itself chalks the colour afterwards.
124172
- */
124173
- function formatTokenCount$1(n) {
124174
- if (!Number.isFinite(n) || n < 0) return "0";
124175
- if (n >= 1e6) return `${(n / 1e6).toFixed(1)}M`;
124176
- if (n >= 1e3) return `${(n / 1e3).toFixed(1)}k`;
124177
- return String(Math.round(n));
124178
- }
124179
- /**
124180
- * Build a `[███░░░░░░░]` style bar. Returns a plain-ASCII string with
124181
- * `filled`/`empty` glyphs — colouring is the caller's responsibility.
124182
- */
124183
- function renderProgressBar(ratio, width = 20, filled = "█", empty = "░") {
124184
- const clamped = safeUsageRatio(ratio);
124185
- const filledCount = Math.round(clamped * width);
124186
- return filled.repeat(filledCount) + empty.repeat(Math.max(0, width - filledCount));
124187
- }
124188
- function safeUsageRatio(ratio) {
124189
- return Number.isFinite(ratio) ? Math.max(0, Math.min(ratio, 1)) : 0;
124190
- }
124191
- /**
124192
- * Map a usage ratio to a semantic colour token — the `/usage` renderer
124193
- * translates these into palette hex values.
124194
- */
124195
- function ratioSeverity(ratio) {
124196
- if (ratio >= .85) return "danger";
124197
- if (ratio >= .5) return "warn";
124198
- return "ok";
124199
- }
124200
- //#endregion
124201
124792
  //#region src/tui/components/messages/usage-panel.ts
124202
124793
  const LEFT_MARGIN$1 = 2;
124203
124794
  const SIDE_PADDING$1 = 1;
@@ -124333,7 +124924,7 @@ function displayModelName(alias, models) {
124333
124924
  function formatModelStatus(options) {
124334
124925
  const model = options.status?.model ?? options.model;
124335
124926
  if (model.trim().length === 0) return "未设置";
124336
- const thinking = (options.status?.thinkingLevel ?? (options.thinking ? "on" : "off")) === "off" ? "off" : "on";
124927
+ const thinking = (options.status?.thinkingLevel ?? options.thinkingLevel) === "off" ? "off" : "on";
124337
124928
  return `${displayModelName(model, options.availableModels)} (thinking ${thinking})`;
124338
124929
  }
124339
124930
  function addFieldRows(lines, rows, muted, value, errorStyle) {
@@ -124358,37 +124949,38 @@ function buildStatusReportLines(options) {
124358
124949
  const errorStyle = chalk.hex(colors.error);
124359
124950
  const severityHex = (sev) => sev === "danger" ? colors.error : sev === "warn" ? colors.warning : colors.success;
124360
124951
  const permission = options.status?.permission ?? options.permissionMode;
124361
- const planMode = options.status?.planMode ?? options.planMode;
124952
+ const planMode = options.planMode !== "off" ? options.planMode : options.status?.planMode ? options.status.planStrategy === "fusion" ? "fusionplan" : "plan" : "off";
124953
+ const planModeLabel = planMode === "off" ? "off" : planMode === "plan" ? "plan" : "fusion";
124362
124954
  const sessionId = options.sessionId.trim().length > 0 ? options.sessionId : "无";
124363
124955
  const rows = [
124364
124956
  {
124365
- label: "模型",
124957
+ label: "模型名称",
124366
124958
  value: formatModelStatus(options)
124367
124959
  },
124368
124960
  {
124369
- label: "目录",
124961
+ label: "工作目录",
124370
124962
  value: options.workDir
124371
124963
  },
124372
124964
  {
124373
- label: "权限",
124965
+ label: "权限模式",
124374
124966
  value: permission
124375
124967
  },
124376
124968
  {
124377
124969
  label: "计划模式",
124378
- value: planMode ? "on" : "off"
124970
+ value: planModeLabel
124379
124971
  },
124380
124972
  {
124381
- label: "会话",
124973
+ label: "会话编号",
124382
124974
  value: sessionId
124383
124975
  }
124384
124976
  ];
124385
124977
  const title = options.sessionTitle?.trim();
124386
124978
  if (title !== void 0 && title.length > 0) rows.push({
124387
- label: "标题",
124979
+ label: "会话标题",
124388
124980
  value: title
124389
124981
  });
124390
124982
  if (options.statusError !== void 0) rows.push({
124391
- label: "警告",
124983
+ label: "状态警告",
124392
124984
  value: options.statusError,
124393
124985
  severity: "error"
124394
124986
  });
@@ -124442,7 +125034,7 @@ async function showStatusReport(host) {
124442
125034
  workDir: appState.workDir,
124443
125035
  sessionId: appState.sessionId,
124444
125036
  sessionTitle: appState.sessionTitle,
124445
- thinking: appState.thinking,
125037
+ thinkingLevel: appState.thinkingLevel,
124446
125038
  permissionMode: appState.permissionMode,
124447
125039
  planMode: appState.planMode,
124448
125040
  contextUsage: appState.contextUsage,
@@ -124489,6 +125081,46 @@ async function loadManagedUsageReport(host) {
124489
125081
  }
124490
125082
  //#endregion
124491
125083
  //#region src/tui/commands/config.ts
125084
+ /**
125085
+ * Storm Breaker guard for model switches. Returns the (currentTokens,
125086
+ * maxContextTokens) pair when switching to `alias` would overflow its
125087
+ * context window, or `null` when the switch is safe / unknown.
125088
+ *
125089
+ * Exported (and kept pure) so the guard is unit-testable without spinning
125090
+ * up a full ScreamTUI + session mock.
125091
+ */
125092
+ function contextOverflowForModel(state, alias) {
125093
+ const targetModel = state.availableModels[alias];
125094
+ if (targetModel === void 0) return null;
125095
+ const currentTokens = state.contextTokens;
125096
+ if (currentTokens <= 0) return null;
125097
+ if (currentTokens <= targetModel.maxContextSize) return null;
125098
+ return {
125099
+ currentTokens,
125100
+ maxContextTokens: targetModel.maxContextSize
125101
+ };
125102
+ }
125103
+ /**
125104
+ * Storm Breaker guard for /compact. Returns the (currentTokens,
125105
+ * maxContextTokens, ratio) triple when context usage is below 5% — compressing
125106
+ * at this point yields no benefit and discards useful history. Returns `null`
125107
+ * when compression is legitimate or when the window size is unknown.
125108
+ *
125109
+ * Exported (and kept pure) so the guard is unit-testable without a session.
125110
+ */
125111
+ function shouldGuardCompaction(state) {
125112
+ const max = state.maxContextTokens;
125113
+ if (max <= 0) return null;
125114
+ const currentTokens = state.contextTokens;
125115
+ if (currentTokens <= 0) return null;
125116
+ const ratio = currentTokens / max;
125117
+ if (ratio >= .05) return null;
125118
+ return {
125119
+ currentTokens,
125120
+ maxContextTokens: max,
125121
+ ratio
125122
+ };
125123
+ }
124492
125124
  async function handlePlanCommand(host, args) {
124493
125125
  const session = host.session;
124494
125126
  if (session === void 0) {
@@ -124501,23 +125133,25 @@ async function handlePlanCommand(host, args) {
124501
125133
  host.showNotice("计划已清除");
124502
125134
  return;
124503
125135
  }
124504
- let enabled;
124505
- if (subcmd.length === 0) enabled = !host.state.appState.planMode;
124506
- else if (subcmd === "on") enabled = true;
124507
- else if (subcmd === "off") enabled = false;
125136
+ let state;
125137
+ if (subcmd.length === 0) state = host.state.appState.planMode === "off" ? "plan" : "off";
125138
+ else if (subcmd === "on") state = "plan";
125139
+ else if (subcmd === "off") state = "off";
124508
125140
  else {
124509
125141
  host.showError(`Unknown plan subcommand: ${subcmd}`);
124510
125142
  return;
124511
125143
  }
124512
- await applyPlanMode(host, session, enabled);
125144
+ await applyPlanMode(host, session, state);
124513
125145
  }
124514
- async function applyPlanMode(host, session, enabled) {
125146
+ async function applyPlanMode(host, session, state) {
125147
+ const enabled = state !== "off";
124515
125148
  try {
124516
- await session.setPlanMode(enabled);
124517
- host.setAppState({ planMode: enabled });
125149
+ if (((await session.getStatus().catch(() => null))?.planMode ?? false) !== enabled) await session.setPlanMode(enabled);
125150
+ host.setAppState({ planMode: state });
124518
125151
  if (enabled) {
124519
125152
  const plan = await session.getPlan().catch(() => null);
124520
- host.showNotice("计划模式:开启", plan?.path !== void 0 ? `计划将创建于此:${plan.path}` : void 0);
125153
+ const label = state === "fusionplan" ? "融合计划模式:开启" : "计划模式:开启";
125154
+ host.showNotice(label, plan?.path !== void 0 ? `计划将创建于此:${plan.path}` : void 0);
124521
125155
  return;
124522
125156
  }
124523
125157
  host.showNotice("计划模式:关闭");
@@ -124526,6 +125160,23 @@ async function applyPlanMode(host, session, enabled) {
124526
125160
  host.showError(`Failed to set plan mode: ${msg}`);
124527
125161
  }
124528
125162
  }
125163
+ async function handleFusionPlanCommand(host, args) {
125164
+ const session = host.session;
125165
+ if (session === void 0) {
125166
+ host.showError(NO_ACTIVE_SESSION_MESSAGE);
125167
+ return;
125168
+ }
125169
+ const subcmd = args.trim().toLowerCase();
125170
+ let state;
125171
+ if (subcmd.length === 0) state = host.state.appState.planMode === "fusionplan" ? "off" : "fusionplan";
125172
+ else if (subcmd === "on") state = "fusionplan";
125173
+ else if (subcmd === "off") state = "off";
125174
+ else {
125175
+ host.showError(`Unknown fusionplan subcommand: ${subcmd}`);
125176
+ return;
125177
+ }
125178
+ await applyPlanMode(host, session, state);
125179
+ }
124529
125180
  async function handleYoloCommand(host, args) {
124530
125181
  const session = host.session;
124531
125182
  if (session === void 0) {
@@ -124640,6 +125291,12 @@ async function handleCompactCommand(host, args) {
124640
125291
  return;
124641
125292
  }
124642
125293
  const customInstruction = args.trim() || void 0;
125294
+ const guard = shouldGuardCompaction(host.state.appState);
125295
+ if (guard !== null) {
125296
+ const pct = (guard.ratio * 100).toFixed(1);
125297
+ host.showNotice("Storm Breaker(风暴守护者)", `当前上下文仅 ${formatTokenCount$1(guard.currentTokens)} / ${formatTokenCount$1(guard.maxContextTokens)}(${pct}%),压缩无收益。建议继续对话,待上下文增长至 5% 以上再执行 /compact。`);
125298
+ return;
125299
+ }
124643
125300
  await session.compact({ instruction: customInstruction });
124644
125301
  }
124645
125302
  async function handleEditorCommand(host, args) {
@@ -124698,7 +125355,9 @@ async function applyEditorChoice(host, value) {
124698
125355
  await saveTuiConfig({
124699
125356
  theme: host.state.appState.theme,
124700
125357
  editorCommand,
124701
- notifications: host.state.appState.notifications
125358
+ notifications: host.state.appState.notifications,
125359
+ like: host.state.appState.like,
125360
+ fusionPlan: host.state.appState.fusionPlan
124702
125361
  });
124703
125362
  } catch (error) {
124704
125363
  host.showStatus(`Failed to save editor: ${formatErrorMessage(error)}`, host.state.theme.colors.error);
@@ -124716,33 +125375,37 @@ function showModelPicker(host, selectedValue = host.state.appState.model) {
124716
125375
  models: host.state.appState.availableModels,
124717
125376
  currentValue: host.state.appState.model,
124718
125377
  selectedValue,
124719
- currentThinking: host.state.appState.thinking,
125378
+ currentThinkingLevel: host.state.appState.thinkingLevel,
124720
125379
  colors: host.state.theme.colors,
124721
125380
  searchable: true,
124722
- onSelect: ({ alias, thinking }) => {
125381
+ onSelect: ({ alias, thinkingLevel }) => {
124723
125382
  host.restoreEditor();
124724
- performModelSwitch(host, alias, thinking);
125383
+ performModelSwitch(host, alias, thinkingLevel);
124725
125384
  },
124726
125385
  onCancel: () => {
124727
125386
  host.restoreEditor();
124728
125387
  }
124729
125388
  }));
124730
125389
  }
124731
- async function performModelSwitch(host, alias, thinking) {
124732
- if (host.state.appState.streamingPhase !== "idle") {
125390
+ async function performModelSwitch(host, alias, thinkingLevel) {
125391
+ if (isBusy(host.state.appState)) {
124733
125392
  host.showError("Cannot switch models while streaming — press Esc or Ctrl-C first.");
124734
125393
  return;
124735
125394
  }
124736
- const level = thinking ? "on" : "off";
124737
125395
  const prevModel = host.state.appState.model;
124738
- const prevThinking = host.state.appState.thinking;
124739
- const runtimeChanged = alias !== prevModel || thinking !== prevThinking;
125396
+ const prevThinkingLevel = host.state.appState.thinkingLevel;
125397
+ const runtimeChanged = alias !== prevModel || thinkingLevel !== prevThinkingLevel;
125398
+ const overflow = alias !== prevModel ? contextOverflowForModel(host.state.appState, alias) : null;
125399
+ if (overflow !== null) {
125400
+ host.showNotice("Storm Breaker(风暴守护者)", `无法切换到模型「${alias}」:当前会话上下文 ${formatTokenCount$1(overflow.currentTokens)} 已超出该模型上限 ${formatTokenCount$1(overflow.maxContextTokens)}。建议先执行 /compact 压缩上下文,或选择上下文窗口更大的模型。`);
125401
+ return;
125402
+ }
124740
125403
  const session = host.session;
124741
125404
  try {
124742
- if (session === void 0 && runtimeChanged) await host.authFlow.activateModelAfterLogin(alias, thinking);
125405
+ if (session === void 0 && runtimeChanged) await host.authFlow.activateModelAfterLogin(alias, thinkingLevel);
124743
125406
  else if (session !== void 0) {
124744
125407
  if (alias !== prevModel) await session.setModel(alias);
124745
- if (thinking !== prevThinking) await session.setThinking(level);
125408
+ if (thinkingLevel !== prevThinkingLevel) await session.setThinking(thinkingLevel);
124746
125409
  }
124747
125410
  } catch (error) {
124748
125411
  const msg = formatErrorMessage(error);
@@ -124751,25 +125414,33 @@ async function performModelSwitch(host, alias, thinking) {
124751
125414
  }
124752
125415
  host.setAppState({
124753
125416
  model: alias,
124754
- thinking
125417
+ thinkingLevel
124755
125418
  });
124756
125419
  let persisted = false;
124757
125420
  try {
124758
- persisted = await persistModelSelection(host, alias, thinking);
125421
+ persisted = await persistModelSelection(host, alias, thinkingLevel);
124759
125422
  } catch (error) {
124760
125423
  const msg = formatErrorMessage(error);
124761
125424
  host.showError(`Switched to ${alias}, but failed to save default: ${msg}`);
124762
125425
  return;
124763
125426
  }
124764
- const status = runtimeChanged ? `Switched to ${alias} with thinking ${level}.` : persisted ? `Saved ${alias} with thinking ${level} as default.` : `Already using ${alias} with thinking ${level}.`;
125427
+ const status = runtimeChanged ? `Switched to ${alias} with thinking ${thinkingLevel}.` : persisted ? `Saved ${alias} with thinking ${thinkingLevel} as default.` : `Already using ${alias} with thinking ${thinkingLevel}.`;
124765
125428
  host.showStatus(status, host.state.theme.colors.success);
124766
125429
  }
124767
- async function persistModelSelection(host, alias, thinking) {
125430
+ async function persistModelSelection(host, alias, thinkingLevel) {
124768
125431
  const config = await host.harness.getConfig({ reload: true });
124769
- if (config.defaultModel === alias && config.defaultThinking === thinking) return false;
125432
+ const effectiveThinking = thinkingLevel !== "off";
125433
+ const existingEffort = config.thinking?.effort;
125434
+ const newEffort = effectiveThinking ? thinkingLevel : existingEffort;
125435
+ if (config.defaultModel === alias && config.defaultThinking === effectiveThinking && existingEffort === newEffort) return false;
124770
125436
  await host.harness.setConfig({
124771
125437
  defaultModel: alias,
124772
- defaultThinking: thinking
125438
+ defaultThinking: effectiveThinking,
125439
+ thinking: {
125440
+ ...config.thinking,
125441
+ mode: effectiveThinking ? "on" : "off",
125442
+ effort: newEffort
125443
+ }
124773
125444
  });
124774
125445
  return true;
124775
125446
  }
@@ -124796,7 +125467,9 @@ async function applyThemeChoice(host, theme) {
124796
125467
  await saveTuiConfig({
124797
125468
  theme,
124798
125469
  editorCommand: host.state.appState.editorCommand,
124799
- notifications: host.state.appState.notifications
125470
+ notifications: host.state.appState.notifications,
125471
+ like: host.state.appState.like,
125472
+ fusionPlan: host.state.appState.fusionPlan
124800
125473
  });
124801
125474
  } catch (error) {
124802
125475
  host.showStatus(`Failed to save theme: ${formatErrorMessage(error)}`, host.state.theme.colors.error);
@@ -125322,6 +125995,13 @@ var GoalStatusMessageComponent = class {
125322
125995
  }
125323
125996
  };
125324
125997
  //#endregion
125998
+ //#region src/tui/utils/goal-loop-conflict.ts
125999
+ function detectGoalLoopConflict(state, action) {
126000
+ if (action === "enable_loop" && state.goalActive) return "goal_active";
126001
+ if (action === "enable_goal" && state.loopModeEnabled) return "loop_active";
126002
+ return null;
126003
+ }
126004
+ //#endregion
125325
126005
  //#region src/tui/commands/goal.ts
125326
126006
  const GOAL_STATUS_DISMISS_MS = 1e4;
125327
126007
  let activeGoalPanel;
@@ -125393,10 +126073,14 @@ async function createGoal(host, parsed) {
125393
126073
  host.showError("没有活跃的会话。");
125394
126074
  return;
125395
126075
  }
126076
+ if (detectGoalLoopConflict(host.state.appState, "enable_goal") === "loop_active") {
126077
+ host.showNotice("Storm Breaker(风暴守护者)", "当前已开启循环模式(/loop)。/goal 与 /loop 语义冲突:loop 每轮重置上下文,会破坏 goal 的工作笔记迭代。请先 /loop 关闭循环模式,再设置目标。");
126078
+ return;
126079
+ }
125396
126080
  try {
125397
126081
  await session.createGoal(parsed.objective, { replace: parsed.replace });
125398
126082
  host.showStatus(`🎯 目标已设置:${parsed.objective}`);
125399
- if (host.state.appState.streamingPhase === "idle") host.sendQueuedMessage(session, {
126083
+ if (!isBusy(host.state.appState)) host.sendQueuedMessage(session, {
125400
126084
  text: parsed.objective,
125401
126085
  agentId: void 0
125402
126086
  });
@@ -125440,7 +126124,7 @@ async function resumeGoal(host) {
125440
126124
  }
125441
126125
  await session.updateGoalStatus("active");
125442
126126
  host.showStatus("🎯 目标已恢复。");
125443
- if (host.state.appState.streamingPhase === "idle") host.sendQueuedMessage(session, {
126127
+ if (!isBusy(host.state.appState)) host.sendQueuedMessage(session, {
125444
126128
  text: "继续执行当前目标。",
125445
126129
  agentId: void 0
125446
126130
  });
@@ -125501,9 +126185,9 @@ function dismissGoalPanel(host) {
125501
126185
  }
125502
126186
  //#endregion
125503
126187
  //#region src/tui/components/chrome/welcome.ts
125504
- const HUE_STOPS = 24;
125505
- const SUB_STEPS = 5;
125506
- const BREATHE_STEPS = HUE_STOPS * SUB_STEPS;
126188
+ const HUE_STOPS$1 = 24;
126189
+ const SUB_STEPS$1 = 5;
126190
+ const BREATHE_STEPS$1 = HUE_STOPS$1 * SUB_STEPS$1;
125507
126191
  const BREATHE_INTERVAL_MS$1 = 40;
125508
126192
  const WELCOME_TIPS = [
125509
126193
  "/config 配置模型",
@@ -125527,7 +126211,7 @@ function hexToRgb$2(hex) {
125527
126211
  parseInt(hex.slice(5, 7), 16)
125528
126212
  ];
125529
126213
  }
125530
- function rgbToHsl$1(r, g, b) {
126214
+ function rgbToHsl$2(r, g, b) {
125531
126215
  const rf = r / 255, gf = g / 255, bf = b / 255;
125532
126216
  const max = Math.max(rf, gf, bf), min = Math.min(rf, gf, bf);
125533
126217
  const l = (max + min) / 2;
@@ -125548,7 +126232,7 @@ function rgbToHsl$1(r, g, b) {
125548
126232
  l * 100
125549
126233
  ];
125550
126234
  }
125551
- function hslToRgb(h, s, l) {
126235
+ function hslToRgb$1(h, s, l) {
125552
126236
  const hf = (h % 360 + 360) % 360 / 360;
125553
126237
  const sf = s / 100, lf = l / 100;
125554
126238
  if (sf === 0) {
@@ -125579,13 +126263,13 @@ function rgbToHex(r, g, b) {
125579
126263
  const c = (v) => Math.round(Math.max(0, Math.min(255, v))).toString(16).padStart(2, "0");
125580
126264
  return `#${c(r)}${c(g)}${c(b)}`;
125581
126265
  }
125582
- function buildBreathingPalette(primaryHex, hueStops, subSteps) {
126266
+ function buildBreathingPalette$1(primaryHex, hueStops, subSteps) {
125583
126267
  const [r, g, b] = hexToRgb$2(primaryHex);
125584
- const [baseHue] = rgbToHsl$1(r, g, b);
126268
+ const [baseHue] = rgbToHsl$2(r, g, b);
125585
126269
  const steps = hueStops * subSteps;
125586
126270
  const palette = [];
125587
126271
  for (let i = 0; i < steps; i++) {
125588
- const [rr, gg, bb] = hslToRgb((baseHue + i / steps * 360) % 360, 90, 70);
126272
+ const [rr, gg, bb] = hslToRgb$1((baseHue + i / steps * 360) % 360, 90, 70);
125589
126273
  palette.push(rgbToHex(rr, gg, bb));
125590
126274
  }
125591
126275
  return palette;
@@ -125623,7 +126307,7 @@ var WelcomeComponent = class {
125623
126307
  this.colors = colors;
125624
126308
  this.ui = ui;
125625
126309
  this.recentSessions = recentSessions;
125626
- this.breathePalette = buildBreathingPalette(colors.primary, HUE_STOPS, SUB_STEPS);
126310
+ this.breathePalette = buildBreathingPalette$1(colors.primary, HUE_STOPS$1, SUB_STEPS$1);
125627
126311
  this.startBreathing();
125628
126312
  }
125629
126313
  stopBreathing() {
@@ -125638,7 +126322,7 @@ var WelcomeComponent = class {
125638
126322
  }
125639
126323
  startBreathing() {
125640
126324
  this.breatheTimer = setInterval(() => {
125641
- this.breatheFrame = (this.breatheFrame + 1) % BREATHE_STEPS;
126325
+ this.breatheFrame = (this.breatheFrame + 1) % BREATHE_STEPS$1;
125642
126326
  this.ui.requestRender();
125643
126327
  }, BREATHE_INTERVAL_MS$1);
125644
126328
  }
@@ -128762,7 +129446,7 @@ function getTranscriptComponentEntry(component) {
128762
129446
  //#endregion
128763
129447
  //#region src/tui/commands/revoke.ts
128764
129448
  async function handleRevokeCommand(host, args = "") {
128765
- if (host.state.appState.streamingPhase !== "idle") {
129449
+ if (isBusy(host.state.appState)) {
128766
129450
  host.showError("无法在 streaming 中撤回 — 请先按 Esc 或 Ctrl-C 取消。");
128767
129451
  return;
128768
129452
  }
@@ -129503,7 +130187,7 @@ async function writeUpdateCache(value, filePath = getUpdateStateFile()) {
129503
130187
  }
129504
130188
  //#endregion
129505
130189
  //#region src/cli/update/cdn.ts
129506
- const NPM_TIMEOUT_MS = 15e3;
130190
+ const NPM_TIMEOUT_MS = 3e3;
129507
130191
  /**
129508
130192
  * Resolve the npm executable name for the current platform.
129509
130193
  *
@@ -129665,7 +130349,7 @@ async function runInstallStep(cmd, args, cwd, label, timeoutMs = INSTALL_TIMEOUT
129665
130349
  });
129666
130350
  }
129667
130351
  async function handleUpdateCommand(host) {
129668
- if (host.state.appState.streamingPhase !== "idle") {
130352
+ if (isBusy(host.state.appState)) {
129669
130353
  host.showError("请在空闲时执行更新。");
129670
130354
  return;
129671
130355
  }
@@ -130361,7 +131045,7 @@ async function handleMakeSkillCommand(host, args) {
130361
131045
  host.showError(NO_ACTIVE_SESSION_MESSAGE);
130362
131046
  return;
130363
131047
  }
130364
- if (host.state.appState.streamingPhase !== "idle") {
131048
+ if (isBusy(host.state.appState)) {
130365
131049
  host.showError("请等待当前回复完成后再使用 /make-skill");
130366
131050
  return;
130367
131051
  }
@@ -131386,6 +132070,10 @@ async function handleLoopCommand(host, args) {
131386
132070
  host.showError(parsed);
131387
132071
  return;
131388
132072
  }
132073
+ if (detectGoalLoopConflict(host.state.appState, "enable_loop") === "goal_active") {
132074
+ host.showNotice("Storm Breaker(风暴守护者)", "当前已有激活的目标(/goal)。/loop 与 /goal 语义冲突:loop 每轮重置上下文,会破坏 goal 的工作笔记迭代。请先 /goal off 关闭目标,再开启循环模式。");
132075
+ return;
132076
+ }
131389
132077
  const loopLimit = createLoopLimitRuntime(parsed.limit);
131390
132078
  host.setAppState({
131391
132079
  loopModeEnabled: true,
@@ -131393,7 +132081,8 @@ async function handleLoopCommand(host, args) {
131393
132081
  loopLimit,
131394
132082
  loopVerifier: parsed.verifier ? makeVerifier(parsed.verifier.command) : void 0,
131395
132083
  loopIteration: 0,
131396
- loopLastVerifyPassed: void 0
132084
+ loopLastVerifyPassed: void 0,
132085
+ loopVerifying: false
131397
132086
  });
131398
132087
  await ensureAutoPermission(host);
131399
132088
  const limitSuffix = parsed.limit ? ` 限制:${describeLoopLimit(parsed.limit)}。` : "";
@@ -131418,11 +132107,89 @@ function disableLoopMode(host, message) {
131418
132107
  loopLimit: void 0,
131419
132108
  loopVerifier: void 0,
131420
132109
  loopIteration: 0,
131421
- loopLastVerifyPassed: void 0
132110
+ loopLastVerifyPassed: void 0,
132111
+ loopVerifying: false
131422
132112
  });
131423
132113
  if (message) host.showStatus(message);
131424
132114
  }
131425
132115
  //#endregion
132116
+ //#region src/tui/commands/like.ts
132117
+ function promptTextInput(host, title, opts) {
132118
+ const { promise, resolve } = Promise.withResolvers();
132119
+ const dialog = new TextInputDialogComponent((result) => {
132120
+ host.restoreEditor();
132121
+ resolve(result.kind === "ok" ? result.value : void 0);
132122
+ }, {
132123
+ title,
132124
+ subtitle: opts?.subtitle,
132125
+ placeholder: opts?.placeholder,
132126
+ initialValue: opts?.initialValue,
132127
+ allowEmpty: opts?.allowEmpty,
132128
+ colors: host.state.theme.colors
132129
+ });
132130
+ host.mountEditorReplacement(dialog);
132131
+ return promise;
132132
+ }
132133
+ function buildRoleAdditionalText(prefs) {
132134
+ const parts = [];
132135
+ if (prefs.nickname !== void 0 && prefs.nickname.trim().length > 0) parts.push(`The user's preferred nickname is "${prefs.nickname.trim()}".`);
132136
+ if (prefs.tone !== void 0 && prefs.tone.trim().length > 0) parts.push(`Respond in a ${prefs.tone.trim()} tone.`);
132137
+ if (prefs.other !== void 0 && prefs.other.trim().length > 0) parts.push(`Additional user preferences: ${prefs.other.trim()}`);
132138
+ return parts.join("\n");
132139
+ }
132140
+ async function getUserPrefsPath() {
132141
+ return join(getDataDir(), "user-prefs.md");
132142
+ }
132143
+ async function persistLikePreferences(host, prefs) {
132144
+ const configPath = getTuiConfigPath();
132145
+ await saveTuiConfig({
132146
+ ...await loadTuiConfig(configPath),
132147
+ like: prefs
132148
+ }, configPath);
132149
+ const roleAdditional = buildRoleAdditionalText(prefs);
132150
+ await writeFile(await getUserPrefsPath(), roleAdditional, "utf-8");
132151
+ host.setAppState({ like: prefs });
132152
+ }
132153
+ async function handleLikeCommand(host) {
132154
+ const current = host.state.appState.like ?? {};
132155
+ const nickname = await promptTextInput(host, "设置昵称", {
132156
+ subtitle: "你希望我怎么称呼你?留空表示不设置。",
132157
+ placeholder: "例如:Alex",
132158
+ initialValue: current.nickname,
132159
+ allowEmpty: true
132160
+ });
132161
+ if (nickname === void 0) {
132162
+ host.showStatus("已取消 /like 设置", host.state.theme.colors.textDim);
132163
+ return;
132164
+ }
132165
+ const tone = await promptTextInput(host, "设置回应语气", {
132166
+ subtitle: "例如:友好、专业、幽默、简洁等(留空表示不设置)",
132167
+ placeholder: "例如:友好而专业",
132168
+ initialValue: current.tone,
132169
+ allowEmpty: true
132170
+ });
132171
+ if (tone === void 0) {
132172
+ host.showStatus("已取消 /like 设置", host.state.theme.colors.textDim);
132173
+ return;
132174
+ }
132175
+ const other = await promptTextInput(host, "其他偏好", {
132176
+ subtitle: "例如:多说例子、先给结论再展开、避免术语等(留空表示不设置)",
132177
+ placeholder: "例如:请用中文回答,避免缩写",
132178
+ initialValue: current.other,
132179
+ allowEmpty: true
132180
+ });
132181
+ if (other === void 0) {
132182
+ host.showStatus("已取消 /like 设置", host.state.theme.colors.textDim);
132183
+ return;
132184
+ }
132185
+ await persistLikePreferences(host, {
132186
+ nickname: nickname.trim().length > 0 ? nickname.trim() : void 0,
132187
+ tone: tone.trim().length > 0 ? tone.trim() : void 0,
132188
+ other: other.trim().length > 0 ? other.trim() : void 0
132189
+ });
132190
+ host.showStatus("偏好已保存(下次新会话生效)", host.state.theme.colors.success);
132191
+ }
132192
+ //#endregion
131426
132193
  //#region src/tui/commands/dispatch.ts
131427
132194
  function dispatchInput(host, text) {
131428
132195
  if (parseSlashInput(text) !== null) {
@@ -131514,6 +132281,9 @@ async function handleBuiltInSlashCommand(host, name, args) {
131514
132281
  case "settings":
131515
132282
  showSettingsSelector(host);
131516
132283
  return;
132284
+ case "like":
132285
+ await handleLikeCommand(host);
132286
+ return;
131517
132287
  case "usage":
131518
132288
  showUsage(host).catch((error) => {
131519
132289
  host.showError(`显示使用情况失败:${formatErrorMessage(error)}`);
@@ -131536,6 +132306,9 @@ async function handleBuiltInSlashCommand(host, name, args) {
131536
132306
  case "plan":
131537
132307
  await handlePlanCommand(host, args);
131538
132308
  return;
132309
+ case "fusionplan":
132310
+ await handleFusionPlanCommand(host, args);
132311
+ return;
131539
132312
  case "wolfpack":
131540
132313
  await handleWolfpackCommand(host, args);
131541
132314
  return;
@@ -131606,9 +132379,9 @@ var AuthFlowController = class {
131606
132379
  availableProviders: config.providers ?? {}
131607
132380
  });
131608
132381
  }
131609
- async activateModelAfterLogin(model, thinking) {
132382
+ async activateModelAfterLogin(model, thinkingLevel) {
131610
132383
  const { host } = this;
131611
- const level = thinking === void 0 ? void 0 : thinking ? "on" : "off";
132384
+ const level = thinkingLevel === void 0 ? void 0 : thinkingLevel === "off" ? "off" : thinkingLevel;
131612
132385
  if (host.session !== void 0) {
131613
132386
  await host.session.setModel(model);
131614
132387
  if (level !== void 0) await host.session.setThinking(level);
@@ -131619,7 +132392,7 @@ var AuthFlowController = class {
131619
132392
  model,
131620
132393
  thinking: level,
131621
132394
  permission: host.options.startup.auto ? "auto" : host.options.startup.yolo ? "yolo" : void 0,
131622
- planMode: host.state.appState.planMode ? true : void 0
132395
+ planMode: host.state.appState.planMode !== "off" ? true : void 0
131623
132396
  });
131624
132397
  await host.setSession(session);
131625
132398
  host.setAppState({
@@ -131656,14 +132429,14 @@ var AuthFlowController = class {
131656
132429
  });
131657
132430
  return;
131658
132431
  }
131659
- await this.activateModelAfterLogin(defaultModel, config.defaultThinking);
132432
+ await this.activateModelAfterLogin(defaultModel, resolveDefaultThinkingLevel(config));
131660
132433
  const appStatePatch = {
131661
132434
  availableModels,
131662
132435
  availableProviders,
131663
132436
  model: defaultModel,
131664
- maxContextTokens: selected.maxContextSize
132437
+ maxContextTokens: selected.maxContextSize,
132438
+ thinkingLevel: resolveDefaultThinkingLevel(config)
131665
132439
  };
131666
- if (config.defaultThinking !== void 0) appStatePatch.thinking = config.defaultThinking;
131667
132440
  host.setAppState(appStatePatch);
131668
132441
  }
131669
132442
  async refreshConfigAfterLogout() {
@@ -131672,13 +132445,19 @@ var AuthFlowController = class {
131672
132445
  availableModels: config.models ?? {},
131673
132446
  availableProviders: config.providers ?? {},
131674
132447
  model: "",
131675
- thinking: false,
132448
+ thinkingLevel: "off",
131676
132449
  maxContextTokens: 0,
131677
132450
  contextUsage: 0,
131678
132451
  contextTokens: 0
131679
132452
  });
131680
132453
  }
131681
132454
  };
132455
+ function resolveDefaultThinkingLevel(config) {
132456
+ if (config.thinking?.mode === "off" || config.defaultThinking === false) return "off";
132457
+ const effort = config.thinking?.effort;
132458
+ if (effort === "low" || effort === "medium" || effort === "high" || effort === "xhigh" || effort === "max") return effort;
132459
+ return config.defaultThinking === true ? "medium" : "off";
132460
+ }
131682
132461
  //#endregion
131683
132462
  //#region src/utils/image/image-mime.ts
131684
132463
  function parseImageMeta(bytes) {
@@ -132355,7 +133134,7 @@ var EditorKeyboardController = class {
132355
133134
  this.cancelCurrentCompaction();
132356
133135
  return;
132357
133136
  }
132358
- if (host.state.appState.streamingPhase !== "idle") {
133137
+ if (isStreaming(host.state.appState)) {
132359
133138
  this.clearPendingExit();
132360
133139
  this.cancelCurrentStream();
132361
133140
  return;
@@ -132386,7 +133165,7 @@ var EditorKeyboardController = class {
132386
133165
  this.cancelCurrentCompaction();
132387
133166
  return;
132388
133167
  }
132389
- if (host.state.appState.streamingPhase !== "idle") {
133168
+ if (isStreaming(host.state.appState)) {
132390
133169
  this.cancelCurrentStream();
132391
133170
  return;
132392
133171
  }
@@ -132400,8 +133179,9 @@ var EditorKeyboardController = class {
132400
133179
  host.showError(NO_ACTIVE_SESSION_MESSAGE);
132401
133180
  return;
132402
133181
  }
132403
- const next = !host.state.appState.planMode;
132404
- host.handlePlanToggle(next);
133182
+ const current = host.state.appState.planMode;
133183
+ const next = current === "off" ? "plan" : current === "plan" ? "fusionplan" : "off";
133184
+ host.handlePlanModeStateChange(next);
132405
133185
  };
132406
133186
  editor.onOpenExternalEditor = () => {
132407
133187
  this.openExternalEditor();
@@ -132411,7 +133191,7 @@ var EditorKeyboardController = class {
132411
133191
  };
132412
133192
  editor.onTogglePlanExpand = () => host.togglePlanExpansion();
132413
133193
  editor.onCtrlS = () => {
132414
- if (host.state.appState.streamingPhase === "idle" || host.state.appState.isCompacting) return;
133194
+ if (!isBusy(host.state.appState)) return;
132415
133195
  const text = editor.getText().trim();
132416
133196
  const queuedTexts = host.state.queuedMessages.map((m) => m.text);
132417
133197
  host.clearQueuedMessages();
@@ -132434,7 +133214,7 @@ var EditorKeyboardController = class {
132434
133214
  host.cancelPendingMemoryExtraction();
132435
133215
  };
132436
133216
  editor.onUpArrowEmpty = () => {
132437
- if (host.state.appState.streamingPhase === "idle" && !host.state.appState.isCompacting) return false;
133217
+ if (!isBusy(host.state.appState)) return false;
132438
133218
  const recalled = host.recallLastQueued();
132439
133219
  if (recalled !== void 0) {
132440
133220
  editor.setText(recalled);
@@ -132850,6 +133630,53 @@ function nextTranscriptId() {
132850
133630
  return `entry-${String(transcriptIdCounter)}`;
132851
133631
  }
132852
133632
  //#endregion
133633
+ //#region src/tui/streaming-phase.ts
133634
+ /**
133635
+ * Returns true when transitioning `from → to` is a valid directed edge.
133636
+ * Self-loops are no-ops and return false so callers can use this as an
133637
+ * idempotency guard:
133638
+ * if (canTransitionTo(state.appState.streamingPhase, 'thinking')) {
133639
+ * setAppState({ streamingPhase: 'thinking' });
133640
+ * }
133641
+ */
133642
+ function canTransitionTo(from, to) {
133643
+ return from !== to;
133644
+ }
133645
+ //#endregion
133646
+ //#region src/tui/utils/compaction-anomaly.ts
133647
+ /** Rapid-refire window: < 30s between end of previous compaction and start of next. */
133648
+ const RAPID_REFIRE_MS = 3e4;
133649
+ /** First-step-blowup: ratio of current tokens to window when first auto-compaction fires. */
133650
+ const FIRST_STEP_BLOWUP_RATIO = .7;
133651
+ /**
133652
+ * Inspects one auto-compaction start for pathological patterns. Returns `null`
133653
+ * when the compaction looks routine.
133654
+ *
133655
+ * Two signals:
133656
+ * - `rapid_refire`: previous auto-compaction finished < 30s ago — model is likely
133657
+ * emitting a runaway stream or looping on a tool that explodes context.
133658
+ * - `first_step_blowup`: very first auto-compaction of the session, and context
133659
+ * is already above 70% — likely a giant system prompt, a huge file read, or
133660
+ * similar one-shot inflation.
133661
+ */
133662
+ function detectCompactionAnomaly(input) {
133663
+ if (input.lastFinishedAt !== void 0) {
133664
+ const elapsed = input.now - input.lastFinishedAt;
133665
+ if (elapsed >= 0 && elapsed < RAPID_REFIRE_MS) return {
133666
+ kind: "rapid_refire",
133667
+ detail: `上次压缩结束仅 ${(elapsed / 1e3).toFixed(1)} 秒后再次触发自动压缩。`
133668
+ };
133669
+ }
133670
+ if (input.autoCompactionCount === 0 && input.maxContextTokens > 0) {
133671
+ const ratio = input.currentTokens / input.maxContextTokens;
133672
+ if (ratio >= FIRST_STEP_BLOWUP_RATIO) return {
133673
+ kind: "first_step_blowup",
133674
+ detail: `会话首次自动压缩时上下文已达 ${(ratio * 100).toFixed(0)}%,可能存在巨型文件读取或初始 prompt 过大。`
133675
+ };
133676
+ }
133677
+ return null;
133678
+ }
133679
+ //#endregion
132853
133680
  //#region src/tui/controllers/session-event-handler.ts
132854
133681
  var SessionEventHandler = class {
132855
133682
  host;
@@ -132858,6 +133685,17 @@ var SessionEventHandler = class {
132858
133685
  }
132859
133686
  backgroundAgentMetadata = /* @__PURE__ */ new Map();
132860
133687
  backgroundTasks = /* @__PURE__ */ new Map();
133688
+ /**
133689
+ * Compaction trigger of the in-flight compaction, captured in
133690
+ * `handleCompactionBegin` (CompactionStartedEvent carries `trigger`) and
133691
+ * read in `handleCompactionEnd` (CompactionCompletedEvent does not). Used so
133692
+ * Storm Breaker cadence tracking only counts auto-compactions — manual
133693
+ * /compact must not inflate `autoCompactionCount` or set
133694
+ * `lastCompactionFinishedAt`, otherwise the first genuine auto-compaction
133695
+ * would silently fail to trigger `first_step_blowup`, and a manual compact
133696
+ * followed shortly by an auto one would falsely trip `rapid_refire`.
133697
+ */
133698
+ lastCompactionTrigger;
132861
133699
  backgroundTaskTranscriptedTerminal = /* @__PURE__ */ new Set();
132862
133700
  subagentInfo = /* @__PURE__ */ new Map();
132863
133701
  renderedSkillActivationIds = /* @__PURE__ */ new Set();
@@ -133107,14 +133945,10 @@ var SessionEventHandler = class {
133107
133945
  this.host.streamingUI.resetToolUi();
133108
133946
  this.host.streamingUI.setStep(0);
133109
133947
  this.host.patchLivePane({
133110
- mode: "waiting",
133111
133948
  pendingApproval: null,
133112
133949
  pendingQuestion: null
133113
133950
  });
133114
- this.host.setAppState({
133115
- streamingPhase: "waiting",
133116
- streamingStartTime: Date.now()
133117
- });
133951
+ this.host.setAppState({ streamingPhase: "waiting" });
133118
133952
  }
133119
133953
  handleTurnEnd(event, sendQueued) {
133120
133954
  this.host.streamingUI.flushNow();
@@ -133143,7 +133977,8 @@ var SessionEventHandler = class {
133143
133977
  loopLimit: void 0,
133144
133978
  loopVerifier: void 0,
133145
133979
  loopIteration: 0,
133146
- loopLastVerifyPassed: void 0
133980
+ loopLastVerifyPassed: void 0,
133981
+ loopVerifying: false
133147
133982
  });
133148
133983
  this.host.showStatus(message);
133149
133984
  }
@@ -133154,14 +133989,22 @@ var SessionEventHandler = class {
133154
133989
  this.host.setAppState({ loopIteration: currentIteration });
133155
133990
  const verifier = state.loopVerifier;
133156
133991
  if (verifier) {
133992
+ this.host.setAppState({ loopVerifying: true });
133157
133993
  const result = await runShellVerifier(verifier, state.workDir);
133158
133994
  const after = this.host.state.appState;
133159
- if (!after.loopModeEnabled || after.loopPrompt !== loopPrompt) return;
133995
+ if (!after.loopModeEnabled || after.loopPrompt !== loopPrompt) {
133996
+ this.host.setAppState({ loopVerifying: false });
133997
+ return;
133998
+ }
133160
133999
  if (result.passed) {
134000
+ this.host.setAppState({ loopVerifying: false });
133161
134001
  this.disableLoop(`✓ 验证通过,循环结束(${currentIteration} 次迭代)。`);
133162
134002
  return;
133163
134003
  }
133164
- this.host.setAppState({ loopLastVerifyPassed: false });
134004
+ this.host.setAppState({
134005
+ loopVerifying: false,
134006
+ loopLastVerifyPassed: false
134007
+ });
133165
134008
  }
133166
134009
  if (!consumeLoopLimitIteration(this.host.state.appState.loopLimit)) {
133167
134010
  const reason = this.host.state.appState.loopLimit?.kind === "duration" ? "时间" : "次数";
@@ -133175,16 +134018,12 @@ var SessionEventHandler = class {
133175
134018
  this.host.streamingUI.flushNow();
133176
134019
  this.host.streamingUI.setStep(event.step);
133177
134020
  this.host.streamingUI.resetToolUi();
133178
- this.host.streamingUI.finalizeLiveTextBuffers("waiting");
134021
+ this.host.streamingUI.finalizeLiveTextBuffers();
133179
134022
  this.host.patchLivePane({
133180
- mode: "waiting",
133181
134023
  pendingApproval: null,
133182
134024
  pendingQuestion: null
133183
134025
  });
133184
- this.host.setAppState({
133185
- streamingPhase: "waiting",
133186
- streamingStartTime: Date.now()
133187
- });
134026
+ this.host.setAppState({ streamingPhase: "waiting" });
133188
134027
  }
133189
134028
  handleStepCompleted(event) {
133190
134029
  this.host.streamingUI.flushNow();
@@ -133208,7 +134047,7 @@ var SessionEventHandler = class {
133208
134047
  handleStepInterrupted(event) {
133209
134048
  this.host.streamingUI.flushNow();
133210
134049
  this.host.streamingUI.resetToolUi();
133211
- this.host.streamingUI.finalizeLiveTextBuffers("idle");
134050
+ this.host.streamingUI.finalizeLiveTextBuffers();
133212
134051
  const reason = event.reason;
133213
134052
  if (reason === "error") return;
133214
134053
  if (reason === "aborted" || reason === void 0 || reason === "") {
@@ -133220,31 +134059,23 @@ var SessionEventHandler = class {
133220
134059
  handleThinkingDelta(event) {
133221
134060
  const { state, streamingUI } = this.host;
133222
134061
  streamingUI.appendThinkingDelta(event.delta);
133223
- this.host.patchLivePane({ mode: "idle" });
133224
- if (state.appState.streamingPhase !== "thinking") this.host.setAppState({
133225
- streamingPhase: "thinking",
133226
- streamingStartTime: Date.now()
133227
- });
134062
+ if (canTransitionTo(state.appState.streamingPhase, "thinking")) this.host.setAppState({ streamingPhase: "thinking" });
133228
134063
  streamingUI.scheduleFlush();
133229
134064
  }
133230
134065
  handleAssistantDelta(event) {
133231
134066
  const { state, streamingUI } = this.host;
133232
- if (streamingUI.hasThinkingDraft()) streamingUI.flushThinkingToTranscript("idle");
134067
+ if (streamingUI.hasThinkingDraft()) streamingUI.flushThinkingToTranscript();
133233
134068
  streamingUI.appendAssistantDelta(event.delta);
133234
134069
  this.host.patchLivePane({
133235
- mode: "idle",
133236
134070
  pendingApproval: null,
133237
134071
  pendingQuestion: null
133238
134072
  });
133239
- if (state.appState.streamingPhase !== "composing") this.host.setAppState({
133240
- streamingPhase: "composing",
133241
- streamingStartTime: Date.now()
133242
- });
134073
+ if (canTransitionTo(state.appState.streamingPhase, "composing")) this.host.setAppState({ streamingPhase: "composing" });
133243
134074
  streamingUI.scheduleFlush();
133244
134075
  }
133245
134076
  handleHookResult(event) {
133246
134077
  this.host.streamingUI.flushNow();
133247
- if (this.host.streamingUI.hasThinkingDraft()) this.host.streamingUI.flushThinkingToTranscript("idle");
134078
+ if (this.host.streamingUI.hasThinkingDraft()) this.host.streamingUI.flushThinkingToTranscript();
133248
134079
  this.host.streamingUI.finalizeAssistantStream();
133249
134080
  this.host.appendTranscriptEntry({
133250
134081
  id: nextTranscriptId(),
@@ -133254,7 +134085,6 @@ var SessionEventHandler = class {
133254
134085
  content: formatHookResultMarkdown(event)
133255
134086
  });
133256
134087
  this.host.patchLivePane({
133257
- mode: "idle",
133258
134088
  pendingApproval: null,
133259
134089
  pendingQuestion: null
133260
134090
  });
@@ -133274,24 +134104,20 @@ var SessionEventHandler = class {
133274
134104
  };
133275
134105
  streamingUI.registerToolCall(toolCall);
133276
134106
  this.host.patchLivePane({
133277
- mode: "tool",
133278
134107
  pendingApproval: null,
133279
134108
  pendingQuestion: null
133280
134109
  });
134110
+ if (canTransitionTo(this.host.state.appState.streamingPhase, "tool")) this.host.setAppState({ streamingPhase: "tool" });
133281
134111
  }
133282
134112
  handleToolCallDelta(event) {
133283
134113
  if (event.toolCallId.length === 0) return;
133284
134114
  const { state, streamingUI } = this.host;
133285
134115
  streamingUI.accumulateToolCallDelta(event.toolCallId, event.name, event.argumentsPart);
133286
134116
  this.host.patchLivePane({
133287
- mode: "tool",
133288
134117
  pendingApproval: null,
133289
134118
  pendingQuestion: null
133290
134119
  });
133291
- if (state.appState.streamingPhase !== "composing") this.host.setAppState({
133292
- streamingPhase: "composing",
133293
- streamingStartTime: Date.now()
133294
- });
134120
+ if (canTransitionTo(state.appState.streamingPhase, "tool")) this.host.setAppState({ streamingPhase: "tool" });
133295
134121
  streamingUI.scheduleFlush();
133296
134122
  }
133297
134123
  handleToolProgress(event) {
@@ -133323,16 +134149,17 @@ var SessionEventHandler = class {
133323
134149
  streamingUI.setTodoList(sanitized);
133324
134150
  }
133325
134151
  }
133326
- this.host.patchLivePane({ mode: "waiting" });
134152
+ if (canTransitionTo(this.host.state.appState.streamingPhase, "waiting")) this.host.setAppState({ streamingPhase: "waiting" });
133327
134153
  }
133328
134154
  handleStatusUpdate(event) {
133329
134155
  const patch = {};
133330
134156
  if (event.contextUsage !== void 0) patch.contextUsage = event.contextUsage;
133331
134157
  if (event.contextTokens !== void 0) patch.contextTokens = event.contextTokens;
133332
134158
  if (event.maxContextTokens !== void 0) patch.maxContextTokens = event.maxContextTokens;
133333
- if (event.planMode !== void 0) patch.planMode = event.planMode;
134159
+ if (event.planMode !== void 0) patch.planMode = event.planMode ? event.planStrategy === "fusion" ? "fusionplan" : this.host.state.appState.planMode === "fusionplan" ? "fusionplan" : "plan" : "off";
133334
134160
  if (event.permission !== void 0) patch.permissionMode = event.permission;
133335
134161
  if (event.model !== void 0) patch.model = event.model;
134162
+ if (event.thinkingLevel !== void 0) patch.thinkingLevel = event.thinkingLevel;
133336
134163
  if (Object.keys(patch).length > 0) this.host.setAppState(patch);
133337
134164
  }
133338
134165
  handleSessionMetaChanged(event) {
@@ -133345,7 +134172,7 @@ var SessionEventHandler = class {
133345
134172
  handleSessionError(event) {
133346
134173
  this.host.streamingUI.flushNow();
133347
134174
  this.host.streamingUI.resetToolUi();
133348
- this.host.streamingUI.finalizeLiveTextBuffers("idle");
134175
+ this.host.streamingUI.finalizeLiveTextBuffers();
133349
134176
  this.host.showError(`[${event.code}] ${event.message}`);
133350
134177
  }
133351
134178
  handleSessionWarning(event) {
@@ -133459,22 +134286,38 @@ var SessionEventHandler = class {
133459
134286
  });
133460
134287
  }
133461
134288
  handleCompactionBegin(event) {
133462
- this.host.streamingUI.finalizeLiveTextBuffers("waiting");
134289
+ this.host.streamingUI.finalizeLiveTextBuffers();
134290
+ this.lastCompactionTrigger = event.trigger;
134291
+ if (event.trigger === "auto") {
134292
+ const anomaly = detectCompactionAnomaly({
134293
+ lastFinishedAt: this.host.state.appState.lastCompactionFinishedAt,
134294
+ autoCompactionCount: this.host.state.appState.autoCompactionCount,
134295
+ currentTokens: this.host.state.appState.contextTokens,
134296
+ maxContextTokens: this.host.state.appState.maxContextTokens,
134297
+ now: Date.now()
134298
+ });
134299
+ if (anomaly !== null) this.host.showNotice("Storm Breaker(风暴守护者)", `检测到异常压缩节奏:${anomaly.detail}可能存在工具调用循环或超长输出,建议查看最近几步的对话记录。`);
134300
+ }
133463
134301
  this.host.setAppState({
133464
134302
  isCompacting: true,
133465
- streamingPhase: "waiting",
133466
- streamingStartTime: Date.now()
134303
+ streamingPhase: "waiting"
133467
134304
  });
133468
134305
  this.host.streamingUI.beginCompaction(event.instruction);
133469
134306
  }
133470
134307
  handleCompactionEnd(event, sendQueued) {
133471
134308
  this.host.streamingUI.endCompaction(event.result.tokensBefore, event.result.tokensAfter);
133472
134309
  this.host.markMemoryExtracted();
134310
+ if (this.lastCompactionTrigger === "auto") this.host.setAppState({
134311
+ lastCompactionFinishedAt: Date.now(),
134312
+ autoCompactionCount: this.host.state.appState.autoCompactionCount + 1
134313
+ });
134314
+ this.lastCompactionTrigger = void 0;
133473
134315
  this.finishCompaction(sendQueued);
133474
134316
  }
133475
134317
  handleCompactionCancel(event, sendQueued) {
133476
134318
  if (event.reason) this.host.showStatus(event.reason, this.host.state.theme.colors.warning);
133477
134319
  this.host.streamingUI.cancelCompaction();
134320
+ this.lastCompactionTrigger = void 0;
133478
134321
  this.finishCompaction(sendQueued);
133479
134322
  }
133480
134323
  finishCompaction(sendQueued) {
@@ -133750,7 +134593,7 @@ function appStateFromResumeAgent(agent) {
133750
134593
  contextTokens,
133751
134594
  maxContextTokens,
133752
134595
  contextUsage,
133753
- planMode: agent.plan !== null,
134596
+ planMode: agent.plan !== null ? "plan" : "off",
133754
134597
  permissionMode: agent.permission.mode
133755
134598
  };
133756
134599
  }
@@ -134626,7 +135469,7 @@ var StreamingUIController = class {
134626
135469
  const existingComponent = this._pendingToolComponents.get(toolCall.id);
134627
135470
  if (existingComponent !== void 0) existingComponent.updateToolCall(toolCall);
134628
135471
  else if (existing === void 0) {
134629
- this.finalizeLiveTextBuffers("tool");
135472
+ this.finalizeLiveTextBuffers();
134630
135473
  if (toolCall.name !== "Agent") this.onToolCallStart(toolCall);
134631
135474
  }
134632
135475
  return existing === void 0;
@@ -134749,11 +135592,10 @@ var StreamingUIController = class {
134749
135592
  markThinkingDirty() {
134750
135593
  this.pendingThinkingFlush = true;
134751
135594
  }
134752
- flushThinkingToTranscript(nextMode = "idle") {
135595
+ flushThinkingToTranscript() {
134753
135596
  this.flushNow();
134754
135597
  this._thinkingDraft = "";
134755
135598
  this.onThinkingEnd();
134756
- this.host.patchLivePane({ mode: nextMode });
134757
135599
  }
134758
135600
  finalizeAssistantStream() {
134759
135601
  this.flushNow();
@@ -134784,8 +135626,8 @@ var StreamingUIController = class {
134784
135626
  resetToolCallState() {
134785
135627
  this._activeToolCalls.clear();
134786
135628
  }
134787
- finalizeLiveTextBuffers(nextMode = "idle") {
134788
- this.flushThinkingToTranscript(nextMode);
135629
+ finalizeLiveTextBuffers() {
135630
+ this.flushThinkingToTranscript();
134789
135631
  this.finalizeAssistantStream();
134790
135632
  }
134791
135633
  finalizeTurn(sendQueued) {
@@ -134793,7 +135635,7 @@ var StreamingUIController = class {
134793
135635
  if (state.appState.streamingPhase === "idle") return;
134794
135636
  this.host.deferUserMessages = false;
134795
135637
  const completedTurnKey = this._currentTurnId ?? `local:${String(state.appState.streamingStartTime)}`;
134796
- this.finalizeLiveTextBuffers("idle");
135638
+ this.finalizeLiveTextBuffers();
134797
135639
  this.resetToolCallState();
134798
135640
  this._currentTurnId = void 0;
134799
135641
  const next = this.host.shiftQueuedMessage();
@@ -135058,7 +135900,7 @@ var StreamingUIController = class {
135058
135900
  turnId: this._currentTurnId
135059
135901
  };
135060
135902
  this._activeToolCalls.set(id, toolCall);
135061
- if (this._thinkingDraft.length > 0 || this._streamingBlock !== null) this.finalizeLiveTextBuffers("tool");
135903
+ if (this._thinkingDraft.length > 0 || this._streamingBlock !== null) this.finalizeLiveTextBuffers();
135062
135904
  const existingComponent = this._pendingToolComponents.get(id);
135063
135905
  if (existingComponent !== void 0) existingComponent.updateToolCall(toolCall);
135064
135906
  else if (toolCall.name !== "Agent") this.onToolCallStart(toolCall);
@@ -136094,6 +136936,94 @@ var TasksBrowserController = class {
136094
136936
  }
136095
136937
  };
136096
136938
  //#endregion
136939
+ //#region src/tui/components/messages/fusion-plan-status.ts
136940
+ const STATUS_ICONS = {
136941
+ pending: "⏳",
136942
+ running: "⏳",
136943
+ completed: "✅",
136944
+ failed: "❌"
136945
+ };
136946
+ var FusionPlanStatusComponent = class {
136947
+ data;
136948
+ colors;
136949
+ ui;
136950
+ spinnerFrame = 0;
136951
+ intervalId = null;
136952
+ cachedWidth;
136953
+ cachedLines;
136954
+ constructor(data, colors, ui) {
136955
+ this.data = data;
136956
+ this.colors = colors;
136957
+ this.ui = ui;
136958
+ this.startSpinner();
136959
+ }
136960
+ setData(data) {
136961
+ this.data = data;
136962
+ this.cachedWidth = void 0;
136963
+ this.cachedLines = void 0;
136964
+ if (this.isTerminal(data.phase)) this.stopSpinner();
136965
+ else if (this.intervalId === null) this.startSpinner();
136966
+ this.ui.requestRender();
136967
+ }
136968
+ invalidate() {
136969
+ this.cachedWidth = void 0;
136970
+ this.cachedLines = void 0;
136971
+ }
136972
+ render(width) {
136973
+ if (this.cachedLines !== void 0 && this.cachedWidth === width) return this.cachedLines;
136974
+ const contentWidth = Math.max(1, width - 2);
136975
+ const lines = [""];
136976
+ const headerLines = new Text(this.renderHeader(), 0, 0).render(contentWidth);
136977
+ for (let i = 0; i < headerLines.length; i += 1) lines.push((i === 0 ? "" : " ") + headerLines[i]);
136978
+ for (const worker of this.data.workers) {
136979
+ const icon = STATUS_ICONS[worker.status];
136980
+ const isActive = worker.status === "running" || worker.status === "pending";
136981
+ const runningIcon = worker.status === "running" ? this.currentSpinnerFrame() + " " : "";
136982
+ const label = chalk.hex(this.colors.textDim)(`视角 ${worker.index + 1}`);
136983
+ const name = chalk.hex(this.colors.text)(worker.label);
136984
+ const wrapped = new Text(`${isActive ? runningIcon : ""}${icon} ${label} · ${name}`, 0, 0).render(contentWidth);
136985
+ for (const line of wrapped) lines.push(" " + line);
136986
+ }
136987
+ if (this.data.detail !== void 0 && this.data.detail.length > 0) {
136988
+ const detailLines = new Text(chalk.hex(this.colors.textDim)(this.data.detail), 0, 0).render(contentWidth);
136989
+ for (const line of detailLines) lines.push(" " + line);
136990
+ }
136991
+ this.cachedWidth = width;
136992
+ this.cachedLines = lines;
136993
+ return lines;
136994
+ }
136995
+ renderHeader() {
136996
+ const phase = this.data.phase;
136997
+ const { completedWorkers, totalWorkers, failedWorkers } = this.data;
136998
+ const tone = phase === "failed" ? this.colors.error : this.colors.primary;
136999
+ const spinner = this.isTerminal(phase) ? "" : this.currentSpinnerFrame() + " ";
137000
+ const summary = `融合计划 · ${completedWorkers}/${totalWorkers} 个视角`;
137001
+ const failedText = failedWorkers > 0 ? `(${failedWorkers} 失败)` : "";
137002
+ const phaseText = phase === "planning" ? "规划中" : phase === "synthesis" ? "完毕后将自动切换为 Plan 执行,当前融合中..." : phase === "completed" ? "已完成" : "失败";
137003
+ return chalk.hex(tone)(`${spinner}${summary}${failedText} · ${phaseText}`);
137004
+ }
137005
+ currentSpinnerFrame() {
137006
+ return BRAILLE_SPINNER_FRAMES[this.spinnerFrame % BRAILLE_SPINNER_FRAMES.length];
137007
+ }
137008
+ startSpinner() {
137009
+ if (this.intervalId !== null) return;
137010
+ this.intervalId = setInterval(() => {
137011
+ this.spinnerFrame = (this.spinnerFrame + 1) % BRAILLE_SPINNER_FRAMES.length;
137012
+ this.cachedWidth = void 0;
137013
+ this.cachedLines = void 0;
137014
+ this.ui.requestRender();
137015
+ }, 80);
137016
+ }
137017
+ stopSpinner() {
137018
+ if (this.intervalId === null) return;
137019
+ clearInterval(this.intervalId);
137020
+ this.intervalId = null;
137021
+ }
137022
+ isTerminal(phase) {
137023
+ return phase === "completed" || phase === "failed";
137024
+ }
137025
+ };
137026
+ //#endregion
136097
137027
  //#region src/tui/components/messages/cron-message.ts
136098
137028
  var CronMessageComponent = class {
136099
137029
  colors;
@@ -136213,6 +137143,52 @@ function basenameLike(raw) {
136213
137143
  return raw.split(/[\\/]/).filter((part) => part.length > 0).at(-1) ?? raw;
136214
137144
  }
136215
137145
  //#endregion
137146
+ //#region src/tui/utils/cached-container.ts
137147
+ /**
137148
+ * A Container that caches its rendered lines until explicitly invalidated or
137149
+ * its child list changes.
137150
+ *
137151
+ * pi-tui's built-in `Container.render()` walks and concatenates every child on
137152
+ * every frame. For large static subtrees (e.g., committed transcript history)
137153
+ * this work is wasted because the children do not change between frames.
137154
+ *
137155
+ * This subclass caches the concatenated output. Callers are responsible for
137156
+ * invalidating the container when a child mutates internally; structural
137157
+ * changes (`addChild`, `removeChild`, `clear`) automatically mark the cache
137158
+ * dirty.
137159
+ */
137160
+ var CachedContainer = class extends Container {
137161
+ cachedWidth;
137162
+ cachedLines;
137163
+ dirty = true;
137164
+ addChild(component) {
137165
+ super.addChild(component);
137166
+ this.markDirty();
137167
+ }
137168
+ removeChild(component) {
137169
+ super.removeChild(component);
137170
+ this.markDirty();
137171
+ }
137172
+ clear() {
137173
+ super.clear();
137174
+ this.markDirty();
137175
+ }
137176
+ invalidate() {
137177
+ super.invalidate();
137178
+ this.markDirty();
137179
+ }
137180
+ render(width) {
137181
+ if (!this.dirty && this.cachedWidth === width && this.cachedLines !== void 0) return this.cachedLines;
137182
+ this.cachedWidth = width;
137183
+ this.cachedLines = super.render(width);
137184
+ this.dirty = false;
137185
+ return this.cachedLines;
137186
+ }
137187
+ markDirty() {
137188
+ this.dirty = true;
137189
+ }
137190
+ };
137191
+ //#endregion
136216
137192
  //#region src/tui/components/transcript/committed-transcript.ts
136217
137193
  var CommittedMessageComponent = class {
136218
137194
  entry;
@@ -136277,7 +137253,7 @@ var CommittedMessageComponent = class {
136277
137253
  }
136278
137254
  }
136279
137255
  };
136280
- var CommittedTranscriptComponent = class extends Container {
137256
+ var CommittedTranscriptComponent = class extends CachedContainer {
136281
137257
  header;
136282
137258
  colors;
136283
137259
  committedCount = 0;
@@ -136294,6 +137270,7 @@ var CommittedTranscriptComponent = class extends Container {
136294
137270
  this.committedCount = count;
136295
137271
  if (count === 0) this.header.setText("");
136296
137272
  else this.header.setText(` ${chalk.hex(this.colors.textDim)(`↑ 还有 ${count} 条历史消息`)}`);
137273
+ this.invalidate();
136297
137274
  }
136298
137275
  appendEntry(entry, colors) {
136299
137276
  this.addChild(new CommittedMessageComponent(entry, colors));
@@ -136334,38 +137311,40 @@ var TranscriptController = class TranscriptController {
136334
137311
  return this.host.state.transcriptContainer.children.length;
136335
137312
  }
136336
137313
  commit() {
136337
- const { state } = this.host;
136338
- if (state.appState.streamingPhase !== "idle") return;
136339
- const container = state.transcriptContainer;
136340
- const children = container.children;
136341
- if (children.length <= TranscriptController.LIVE_LIMIT) return;
136342
- const toCommit = [];
136343
- for (const child of children) {
136344
- if (this.pendingComponents.has(child)) continue;
136345
- if (child === this.welcomeComponent) continue;
136346
- if (child === this.committedComponent) continue;
136347
- const entry = this.liveComponentToEntry.get(child);
136348
- if (entry === void 0) continue;
136349
- if (children.length - toCommit.length <= TranscriptController.LIVE_LIMIT) break;
136350
- toCommit.push({
136351
- component: child,
136352
- entry
136353
- });
136354
- }
136355
- if (toCommit.length === 0) return;
136356
- if (this.committedComponent === void 0) {
136357
- this.committedComponent = new CommittedTranscriptComponent(state.theme.colors);
136358
- container.children.unshift(this.committedComponent);
136359
- }
136360
- for (const { component, entry } of toCommit) {
136361
- this.committedComponent.appendEntry(entry, state.theme.colors);
136362
- container.removeChild(component);
136363
- this.liveComponentToEntry.delete(component);
136364
- }
136365
- this.committedComponent.setCount(this.committedComponent.getCount() + toCommit.length);
136366
- if (process.env["SCREAM_CODE_DEBUG"] === "1") this.host.showStatus(`[debug] committed=${this.committedComponent.getCount()} live=${this.getLiveCount()}`);
136367
- container.invalidate();
136368
- state.ui.requestRender();
137314
+ this.host.batchUpdate(() => {
137315
+ const { state } = this.host;
137316
+ if (isStreaming(state.appState)) return;
137317
+ const container = state.transcriptContainer;
137318
+ const children = container.children;
137319
+ if (children.length <= TranscriptController.LIVE_LIMIT) return;
137320
+ const toCommit = [];
137321
+ for (const child of children) {
137322
+ if (this.pendingComponents.has(child)) continue;
137323
+ if (child === this.welcomeComponent) continue;
137324
+ if (child === this.committedComponent) continue;
137325
+ const entry = this.liveComponentToEntry.get(child);
137326
+ if (entry === void 0) continue;
137327
+ if (children.length - toCommit.length <= TranscriptController.LIVE_LIMIT) break;
137328
+ toCommit.push({
137329
+ component: child,
137330
+ entry
137331
+ });
137332
+ }
137333
+ if (toCommit.length === 0) return;
137334
+ if (this.committedComponent === void 0) {
137335
+ this.committedComponent = new CommittedTranscriptComponent(state.theme.colors);
137336
+ container.children.unshift(this.committedComponent);
137337
+ }
137338
+ for (const { component, entry } of toCommit) {
137339
+ this.committedComponent.appendEntry(entry, state.theme.colors);
137340
+ container.removeChild(component);
137341
+ this.liveComponentToEntry.delete(component);
137342
+ }
137343
+ this.committedComponent.setCount(this.committedComponent.getCount() + toCommit.length);
137344
+ if (process.env["SCREAM_CODE_DEBUG"] === "1") this.host.showStatus(`[debug] committed=${this.committedComponent.getCount()} live=${this.getLiveCount()}`);
137345
+ container.invalidate();
137346
+ state.ui.requestRender();
137347
+ });
136369
137348
  }
136370
137349
  createComponent(entry) {
136371
137350
  const { state, imageStore } = this.host;
@@ -136404,9 +137383,11 @@ var TranscriptController = class TranscriptController {
136404
137383
  return tc;
136405
137384
  }
136406
137385
  if (entry.backgroundAgentStatus !== void 0) return new BackgroundAgentStatusComponent(entry.backgroundAgentStatus, state.theme.colors);
137386
+ if (entry.fusionPlanStatus !== void 0) return new FusionPlanStatusComponent(entry.fusionPlanStatus, state.theme.colors, state.ui);
136407
137387
  return entry.renderMode === "notice" ? new NoticeMessageComponent(entry.content, entry.detail, state.theme.colors) : new StatusMessageComponent(entry.content, state.theme.colors, entry.color);
136408
137388
  case "status":
136409
137389
  if (entry.backgroundAgentStatus !== void 0) return new BackgroundAgentStatusComponent(entry.backgroundAgentStatus, state.theme.colors);
137390
+ if (entry.fusionPlanStatus !== void 0) return new FusionPlanStatusComponent(entry.fusionPlanStatus, state.theme.colors, state.ui);
136410
137391
  return entry.renderMode === "notice" ? new NoticeMessageComponent(entry.content, entry.detail, state.theme.colors) : new StatusMessageComponent(entry.content, state.theme.colors, entry.color);
136411
137392
  case "cron":
136412
137393
  if (entry.cronData === void 0) return null;
@@ -136423,6 +137404,7 @@ var TranscriptController = class TranscriptController {
136423
137404
  this.host.state.transcriptContainer.addChild(component);
136424
137405
  this.host.state.ui.requestRender();
136425
137406
  }
137407
+ return component ?? null;
136426
137408
  }
136427
137409
  appendApprovalEntry(request, response) {
136428
137410
  if (request.toolName === "ExitPlanMode" || request.display.kind === "plan_review") return;
@@ -137013,7 +137995,7 @@ var LifecycleController = class LifecycleController {
137013
137995
  async performIdleMemoryExtraction() {
137014
137996
  if (Date.now() - this.lastMemoryExtractionTime < LifecycleController.MEMORY_EXTRACT_COOLDOWN_MS) return;
137015
137997
  const { state, session } = this.host;
137016
- if (state.appState.streamingPhase !== "idle") return;
137998
+ if (isStreaming(state.appState)) return;
137017
137999
  if (state.appState.isCompacting) return;
137018
138000
  if (state.appState.isReplaying) return;
137019
138001
  if (session === void 0) return;
@@ -137127,7 +138109,6 @@ var LifecycleController = class LifecycleController {
137127
138109
  break;
137128
138110
  }
137129
138111
  case "idle":
137130
- case "session":
137131
138112
  this.stopActivitySpinner();
137132
138113
  this.stopPulseWave();
137133
138114
  break;
@@ -137141,10 +138122,8 @@ var LifecycleController = class LifecycleController {
137141
138122
  if (state.appState.isCompacting) return "hidden";
137142
138123
  if (state.livePane.pendingQuestion !== null) return "hidden";
137143
138124
  const streamingPhase = state.appState.streamingPhase;
137144
- if (state.livePane.mode === "idle") {
137145
- if (streamingPhase === "thinking" || streamingPhase === "composing") return streamingPhase;
137146
- }
137147
- return state.livePane.mode;
138125
+ if (streamingPhase === "waiting" || streamingPhase === "thinking" || streamingPhase === "composing" || streamingPhase === "tool") return streamingPhase;
138126
+ return "idle";
137148
138127
  }
137149
138128
  shouldShowTerminalProgress(effectiveMode) {
137150
138129
  if (this.host.state.appState.isCompacting) return true;
@@ -137435,6 +138414,415 @@ var QueuePaneComponent = class extends Container {
137435
138414
  }
137436
138415
  };
137437
138416
  //#endregion
138417
+ //#region src/tui/utils/fusion-plan.ts
138418
+ /**
138419
+ * Fusion plan worker orchestration.
138420
+ *
138421
+ * Spawns multiple `scream` CLI subagents in headless JSON mode to produce
138422
+ * parallel implementation plans, then synthesizes them into a single plan.
138423
+ *
138424
+ * This is intentionally a TUI-layer strategy: agent-core still sees a plain
138425
+ * boolean plan mode, and the synthesized plan is injected into the normal
138426
+ * plan file before the agent takes over.
138427
+ */
138428
+ const APP_ROOT = fileURLToPath(new URL("../../..", import.meta.url));
138429
+ const MAIN_TS = resolve(APP_ROOT, "src/main.ts");
138430
+ const MAIN_MJS = resolve(APP_ROOT, "dist/main.mjs");
138431
+ const RAW_TEXT_LOADER = resolve(APP_ROOT, "../../build/register-raw-text-loader.mjs");
138432
+ function tsxCommand() {
138433
+ return process.platform === "win32" ? "tsx.cmd" : "tsx";
138434
+ }
138435
+ function buildSourceCommand() {
138436
+ const prefixArgs = existsSync(RAW_TEXT_LOADER) ? [
138437
+ "--import",
138438
+ RAW_TEXT_LOADER,
138439
+ MAIN_TS
138440
+ ] : [MAIN_TS];
138441
+ return {
138442
+ command: tsxCommand(),
138443
+ prefixArgs
138444
+ };
138445
+ }
138446
+ function trySourceOrDist() {
138447
+ if (existsSync(MAIN_TS)) return buildSourceCommand();
138448
+ if (existsSync(MAIN_MJS)) return {
138449
+ command: process.execPath,
138450
+ prefixArgs: [MAIN_MJS]
138451
+ };
138452
+ return {
138453
+ command: "scream",
138454
+ prefixArgs: []
138455
+ };
138456
+ }
138457
+ const SCREAM_FUSIONPLAN_SUBAGENT_ENV = "SCREAM_FUSIONPLAN_SUBAGENT";
138458
+ /**
138459
+ * Terminate a child process tree reliably on both POSIX and Windows.
138460
+ * On Windows `proc.kill()` only signals the wrapper, so use `taskkill /T`.
138461
+ * On POSIX, kill the process group so grandchildren inherit the signal.
138462
+ */
138463
+ function killProcessTree(proc, signal) {
138464
+ if (proc.pid === void 0) return;
138465
+ if (process.platform === "win32") {
138466
+ const child = spawn("taskkill", [
138467
+ ...signal === "SIGKILL" ? ["/F"] : [],
138468
+ "/T",
138469
+ "/PID",
138470
+ String(proc.pid)
138471
+ ], {
138472
+ stdio: "ignore",
138473
+ windowsHide: true,
138474
+ detached: true
138475
+ });
138476
+ if (typeof child.unref === "function") child.unref();
138477
+ return;
138478
+ }
138479
+ try {
138480
+ process.kill(-proc.pid, signal);
138481
+ } catch {
138482
+ try {
138483
+ proc.kill(signal);
138484
+ } catch {}
138485
+ }
138486
+ }
138487
+ const WORKER_ANGLES = [
138488
+ {
138489
+ angle: "Focus on correctness and edge cases. Identify risks, invariants, and safety checks.",
138490
+ label: "最佳正确性"
138491
+ },
138492
+ {
138493
+ angle: "Focus on minimal invasiveness. Prefer small, incremental changes that are easy to review.",
138494
+ label: "最小侵入性"
138495
+ },
138496
+ {
138497
+ angle: "Focus on architecture and future maintainability. Consider testability, clarity, and naming.",
138498
+ label: "最优架构性"
138499
+ }
138500
+ ];
138501
+ const DEFAULT_WORKER_COUNT = 3;
138502
+ const DEFAULT_TIMEOUT_MS = 6e5;
138503
+ const DEFAULT_MAX_OUTPUT_BYTES = 8e3;
138504
+ const DEFAULT_SYNTHESIS_MAX_OUTPUT_BYTES = 12e3;
138505
+ /** Override via `SCREAM_FUSIONPLAN_TIMEOUT_SECONDS` env var (30..3600). */
138506
+ function resolveDefaultTimeoutMs() {
138507
+ const env = process.env["SCREAM_FUSIONPLAN_TIMEOUT_SECONDS"];
138508
+ if (env === void 0) return DEFAULT_TIMEOUT_MS;
138509
+ const parsed = Number.parseInt(env, 10);
138510
+ if (Number.isNaN(parsed)) return DEFAULT_TIMEOUT_MS;
138511
+ return Math.max(3e4, Math.min(36e5, parsed * 1e3));
138512
+ }
138513
+ function buildPlannerPrompt(input) {
138514
+ return [
138515
+ "You are a planning specialist. Create an implementation plan for the request below.",
138516
+ "",
138517
+ `Request: ${input.task}`,
138518
+ "",
138519
+ `Your specific angle: ${input.angle}`,
138520
+ "",
138521
+ "Constraints:",
138522
+ "- Investigate the codebase as needed using available tools.",
138523
+ "- Produce a concrete, step-by-step implementation plan.",
138524
+ "- Do not write implementation code; only produce the plan.",
138525
+ `- Keep your response focused and under ${input.maxOutputBytes} bytes.`,
138526
+ "- Return only the plan."
138527
+ ].join("\n");
138528
+ }
138529
+ function buildSynthesisPrompt(input) {
138530
+ const plans = input.workerOutputs.map((output, index) => `### Plan ${index + 1}\n\n${output}`).join("\n\n");
138531
+ return [
138532
+ "You are a senior engineer. Review the following plans from multiple planning specialists and synthesize them into a single optimal implementation plan.",
138533
+ "",
138534
+ `Request: ${input.task}`,
138535
+ "",
138536
+ plans,
138537
+ "",
138538
+ "Instructions:",
138539
+ "- Incorporate the strongest ideas from each specialist plan.",
138540
+ "- Resolve contradictions explicitly.",
138541
+ "- Produce one concrete, step-by-step implementation plan.",
138542
+ `- Keep the final plan under ${input.maxOutputBytes} bytes.`,
138543
+ "- Return only the final plan."
138544
+ ].join("\n");
138545
+ }
138546
+ async function createPromptDir() {
138547
+ return mkdtemp(join(tmpdir(), "scream-fusionplan-"));
138548
+ }
138549
+ async function writePromptFile(dir, index, prompt) {
138550
+ const file = join(dir, `worker-${index}.md`);
138551
+ await writeFile(file, prompt, "utf8");
138552
+ return file;
138553
+ }
138554
+ async function cleanupPromptDir(dir) {
138555
+ await rm(dir, {
138556
+ recursive: true,
138557
+ force: true
138558
+ });
138559
+ }
138560
+ async function buildWorkerArgs(input) {
138561
+ const args = [
138562
+ "--output-format",
138563
+ "stream-json",
138564
+ "--prompt",
138565
+ await readFile(input.promptFile, "utf8")
138566
+ ];
138567
+ if (input.model) args.push("--model", input.model);
138568
+ return args;
138569
+ }
138570
+ function resolveScreamCommand(screamBin) {
138571
+ if (screamBin) return {
138572
+ command: screamBin,
138573
+ prefixArgs: []
138574
+ };
138575
+ const entry = process.argv[1];
138576
+ if (!entry) return trySourceOrDist();
138577
+ const absoluteEntry = resolve(entry);
138578
+ if (/[\\/]scripts[\\/]dev\.mjs$/.test(absoluteEntry)) return trySourceOrDist();
138579
+ if (absoluteEntry.endsWith("dist/main.mjs")) return {
138580
+ command: process.execPath,
138581
+ prefixArgs: [absoluteEntry]
138582
+ };
138583
+ if (absoluteEntry.endsWith("src/main.ts")) return buildSourceCommand();
138584
+ if (absoluteEntry.endsWith(".mjs") || absoluteEntry.endsWith(".js")) return {
138585
+ command: process.execPath,
138586
+ prefixArgs: [absoluteEntry]
138587
+ };
138588
+ return trySourceOrDist();
138589
+ }
138590
+ function textFromContent(content) {
138591
+ if (typeof content === "string") return content;
138592
+ if (Array.isArray(content)) return content.map((part) => {
138593
+ if (typeof part === "string") return part;
138594
+ if (part && typeof part === "object" && "text" in part && typeof part.text === "string") return part.text;
138595
+ return "";
138596
+ }).join("");
138597
+ return "";
138598
+ }
138599
+ function truncateUtf8(input, maxBytes) {
138600
+ const encoder = new TextEncoder();
138601
+ if (encoder.encode(input).length <= maxBytes) return input;
138602
+ const suffix = "…";
138603
+ const suffixBytes = encoder.encode(suffix).length;
138604
+ const targetBytes = Math.max(0, maxBytes - suffixBytes);
138605
+ let low = 0;
138606
+ let high = input.length;
138607
+ while (low < high) {
138608
+ const mid = Math.floor((low + high + 1) / 2);
138609
+ if (encoder.encode(input.slice(0, mid)).length <= targetBytes) low = mid;
138610
+ else high = mid - 1;
138611
+ }
138612
+ return `${input.slice(0, low)}${suffix}`;
138613
+ }
138614
+ async function runWorker(input) {
138615
+ const maxOutputBytes = input.maxOutputBytes ?? DEFAULT_MAX_OUTPUT_BYTES;
138616
+ const promptFile = await writePromptFile(input.promptDir, input.index, buildPlannerPrompt({
138617
+ task: input.task,
138618
+ angle: input.angle,
138619
+ maxOutputBytes
138620
+ }));
138621
+ const result = {
138622
+ ok: false,
138623
+ output: "",
138624
+ stderr: "",
138625
+ exitCode: null,
138626
+ timedOut: false
138627
+ };
138628
+ try {
138629
+ const args = await buildWorkerArgs({
138630
+ promptFile,
138631
+ model: input.model
138632
+ });
138633
+ const { command, prefixArgs } = resolveScreamCommand(input.screamBin);
138634
+ const timeoutMs = input.timeoutMs ?? resolveDefaultTimeoutMs();
138635
+ result.command = [
138636
+ command,
138637
+ ...prefixArgs,
138638
+ ...args
138639
+ ].join(" ");
138640
+ const exitCode = await new Promise((resolve) => {
138641
+ const proc = spawn(command, [...prefixArgs, ...args], {
138642
+ cwd: input.cwd,
138643
+ shell: false,
138644
+ stdio: [
138645
+ "ignore",
138646
+ "pipe",
138647
+ "pipe"
138648
+ ],
138649
+ env: {
138650
+ ...process.env,
138651
+ [SCREAM_FUSIONPLAN_SUBAGENT_ENV]: "1"
138652
+ }
138653
+ });
138654
+ input.onStarted?.();
138655
+ let stdoutBuffer = "";
138656
+ let timeout;
138657
+ const processLine = (line) => {
138658
+ if (!line.trim()) return;
138659
+ let event;
138660
+ try {
138661
+ event = JSON.parse(line);
138662
+ } catch {
138663
+ return;
138664
+ }
138665
+ if (event.role === "assistant" && event.content) {
138666
+ const text = textFromContent(event.content).trim();
138667
+ if (text) result.output += (result.output ? "\n\n" : "") + text;
138668
+ }
138669
+ };
138670
+ proc.stdout.on("data", (data) => {
138671
+ stdoutBuffer += data.toString("utf8");
138672
+ const lines = stdoutBuffer.split("\n");
138673
+ stdoutBuffer = lines.pop() ?? "";
138674
+ for (const line of lines) processLine(line);
138675
+ });
138676
+ proc.stderr.on("data", (data) => {
138677
+ result.stderr += data.toString("utf8");
138678
+ });
138679
+ let resolved = false;
138680
+ const safeResolve = (value) => {
138681
+ if (resolved) return;
138682
+ resolved = true;
138683
+ resolve(value);
138684
+ };
138685
+ proc.on("error", (error) => {
138686
+ result.stderr += error.message;
138687
+ safeResolve(null);
138688
+ });
138689
+ proc.on("close", (code) => {
138690
+ clearTimeout(timeout);
138691
+ if (stdoutBuffer.trim()) processLine(stdoutBuffer);
138692
+ safeResolve(code ?? 0);
138693
+ });
138694
+ timeout = setTimeout(() => {
138695
+ result.timedOut = true;
138696
+ killProcessTree(proc, "SIGTERM");
138697
+ setTimeout(() => killProcessTree(proc, "SIGKILL"), 5e3).unref();
138698
+ }, timeoutMs);
138699
+ timeout.unref();
138700
+ });
138701
+ result.exitCode = exitCode;
138702
+ result.timeoutMs = timeoutMs;
138703
+ result.ok = exitCode === 0 && !result.timedOut && result.output.trim().length > 0;
138704
+ if (!result.output.trim()) result.output = result.stderr.trim() || "(worker produced no final assistant output)";
138705
+ return result;
138706
+ } finally {
138707
+ await rm(promptFile, { force: true });
138708
+ }
138709
+ }
138710
+ async function runSynthesisWorker(input, promptDir) {
138711
+ const maxOutputBytes = input.maxOutputBytes ?? DEFAULT_SYNTHESIS_MAX_OUTPUT_BYTES;
138712
+ const truncatedOutputs = input.workerOutputs.map((output) => truncateUtf8(output, maxOutputBytes));
138713
+ const result = await runWorker({
138714
+ index: 0,
138715
+ task: buildSynthesisPrompt({
138716
+ task: input.task,
138717
+ workerOutputs: truncatedOutputs,
138718
+ maxOutputBytes
138719
+ }),
138720
+ angle: "Synthesize the best plan from the specialist outputs.",
138721
+ label: "综合",
138722
+ cwd: input.cwd,
138723
+ promptDir,
138724
+ model: input.model,
138725
+ thinkingLevel: input.thinkingLevel,
138726
+ timeoutMs: input.timeoutMs,
138727
+ maxOutputBytes,
138728
+ screamBin: input.screamBin
138729
+ });
138730
+ return result.ok ? result.output.trim() : `(synthesis failed: ${result.stderr || "no output"})`;
138731
+ }
138732
+ function buildWorkerProgress(states) {
138733
+ return states.map((s, index) => ({
138734
+ index,
138735
+ status: s.status,
138736
+ angle: s.angle,
138737
+ label: s.label
138738
+ }));
138739
+ }
138740
+ async function runFusionPlan(input) {
138741
+ if (process.env["SCREAM_FUSIONPLAN_SUBAGENT"] === "1") return {
138742
+ ok: false,
138743
+ plan: "",
138744
+ workerResults: []
138745
+ };
138746
+ const workerCount = Math.max(1, Math.min(8, input.workerCount ?? DEFAULT_WORKER_COUNT));
138747
+ const maxOutputBytes = input.maxOutputBytes ?? DEFAULT_MAX_OUTPUT_BYTES;
138748
+ const timeoutMs = input.timeoutMs ?? resolveDefaultTimeoutMs();
138749
+ const promptDir = await createPromptDir();
138750
+ const workerStates = [];
138751
+ for (let i = 0; i < workerCount; i += 1) {
138752
+ const angleDef = WORKER_ANGLES[i % WORKER_ANGLES.length];
138753
+ workerStates.push({
138754
+ status: "pending",
138755
+ angle: angleDef.angle,
138756
+ label: angleDef.label
138757
+ });
138758
+ }
138759
+ const emitProgress = (phase) => {
138760
+ const completedWorkers = workerStates.filter((s) => s.status === "completed").length;
138761
+ const failedWorkers = workerStates.filter((s) => s.status === "failed").length;
138762
+ input.onProgress?.({
138763
+ phase,
138764
+ completedWorkers,
138765
+ totalWorkers: workerCount,
138766
+ failedWorkers,
138767
+ workers: buildWorkerProgress(workerStates)
138768
+ });
138769
+ };
138770
+ try {
138771
+ emitProgress("planning");
138772
+ const workerPromises = workerStates.map((state, index) => runWorker({
138773
+ index,
138774
+ task: input.task,
138775
+ angle: state.angle,
138776
+ label: state.label,
138777
+ cwd: input.cwd,
138778
+ promptDir,
138779
+ model: input.model,
138780
+ thinkingLevel: input.thinkingLevel,
138781
+ timeoutMs,
138782
+ maxOutputBytes,
138783
+ screamBin: input.screamBin,
138784
+ onStarted: () => {
138785
+ state.status = "running";
138786
+ emitProgress("planning");
138787
+ }
138788
+ }).then((result) => {
138789
+ state.status = result.ok ? "completed" : "failed";
138790
+ emitProgress("planning");
138791
+ return result;
138792
+ }));
138793
+ const workerResults = await Promise.all(workerPromises);
138794
+ const successfulOutputs = workerResults.filter((r) => r.ok).map((r) => truncateUtf8(r.output, maxOutputBytes));
138795
+ if (successfulOutputs.length === 0) {
138796
+ emitProgress("failed");
138797
+ return {
138798
+ ok: false,
138799
+ plan: "",
138800
+ workerResults
138801
+ };
138802
+ }
138803
+ emitProgress("synthesis");
138804
+ const plan = await runSynthesisWorker({
138805
+ task: input.task,
138806
+ workerOutputs: successfulOutputs,
138807
+ cwd: input.cwd,
138808
+ model: input.model,
138809
+ thinkingLevel: input.thinkingLevel,
138810
+ timeoutMs,
138811
+ maxOutputBytes: input.synthesisMaxOutputBytes,
138812
+ screamBin: input.screamBin
138813
+ }, promptDir);
138814
+ const ok = plan.length > 0 && !plan.startsWith("(synthesis failed");
138815
+ emitProgress(ok ? "completed" : "failed");
138816
+ return {
138817
+ ok,
138818
+ plan,
138819
+ workerResults
138820
+ };
138821
+ } finally {
138822
+ await cleanupPromptDir(promptDir);
138823
+ }
138824
+ }
138825
+ //#endregion
137438
138826
  //#region src/tui/utils/image-placeholder.ts
137439
138827
  const PLACEHOLDER_REGEX = /\[(image|video) #(\d+) (?:(\(\d+×\d+\))|([^\]]+))\]/g;
137440
138828
  function extractMediaAttachments(text, store) {
@@ -137543,7 +138931,7 @@ function hexToRgb$1(hex) {
137543
138931
  v & 255
137544
138932
  ];
137545
138933
  }
137546
- function rgbToHsl(r, g, b) {
138934
+ function rgbToHsl$1(r, g, b) {
137547
138935
  const rf = r / 255, gf = g / 255, bf = b / 255;
137548
138936
  const max = Math.max(rf, gf, bf), min = Math.min(rf, gf, bf);
137549
138937
  const l = (max + min) / 2;
@@ -137599,6 +138987,9 @@ var InputController = class {
137599
138987
  breatheFrame = 0;
137600
138988
  /** Once the user types, breathing stops permanently (same as welcome). */
137601
138989
  breatheOnceStopped = false;
138990
+ fusionPlanComponent;
138991
+ fusionPlanEntry;
138992
+ isFusionPlanRunning = false;
137602
138993
  constructor(host) {
137603
138994
  this.host = host;
137604
138995
  }
@@ -137611,7 +139002,7 @@ var InputController = class {
137611
139002
  this.host.stopWelcomeBreathing();
137612
139003
  this.#permanentlyStopBreathing();
137613
139004
  };
137614
- if (!this.host.state.appState.planMode) this.#startBreathing();
139005
+ if (this.host.state.appState.planMode === "off") this.#startBreathing();
137615
139006
  }
137616
139007
  handleInput(text) {
137617
139008
  if (text.trim().length === 0) return;
@@ -137623,22 +139014,29 @@ var InputController = class {
137623
139014
  dispatchInput(this.host, text);
137624
139015
  this.host.stopMemoryIdleTimer();
137625
139016
  }
137626
- sendNormalUserInput(text) {
139017
+ async sendNormalUserInput(text) {
137627
139018
  if (this.host.state.appState.model.trim().length === 0) {
137628
139019
  this.host.showError(LLM_NOT_SET_MESSAGE);
137629
139020
  return;
137630
139021
  }
137631
- const extraction = extractMediaAttachments(text, this.host.imageStore);
137632
- if (!this.validateMediaCapabilities(extraction)) return;
137633
139022
  const session = this.host.session;
137634
139023
  if (session === void 0) {
137635
139024
  this.host.showError(LLM_NOT_SET_MESSAGE);
137636
139025
  return;
137637
139026
  }
139027
+ if (this.host.state.appState.planMode === "fusionplan") {
139028
+ this.sendFusionPlanUserInput(text, session);
139029
+ return;
139030
+ }
139031
+ this.dispatchUserInput(text, session);
139032
+ }
139033
+ dispatchUserInput(text, session) {
137638
139034
  if (this.host.state.appState.loopModeEnabled && !this.host.state.appState.loopPrompt) {
137639
139035
  this.host.setAppState({ loopPrompt: text });
137640
139036
  consumeLoopLimitIteration(this.host.state.appState.loopLimit);
137641
139037
  }
139038
+ const extraction = extractMediaAttachments(text, this.host.imageStore);
139039
+ if (!this.validateMediaCapabilities(extraction)) return;
137642
139040
  if (extraction.hasMedia) this.sendMessage(session, text, {
137643
139041
  hasMedia: true,
137644
139042
  parts: extraction.parts,
@@ -137648,12 +139046,111 @@ var InputController = class {
137648
139046
  this.host.updateQueueDisplay();
137649
139047
  this.host.state.ui.requestRender();
137650
139048
  }
139049
+ sendFusionPlanUserInput(text, session) {
139050
+ if (this.isFusionPlanRunning) {
139051
+ this.host.showError("已有融合计划正在运行,请等待完成。");
139052
+ return;
139053
+ }
139054
+ this.isFusionPlanRunning = true;
139055
+ this.fusionPlanEntry = void 0;
139056
+ this.fusionPlanComponent = void 0;
139057
+ runFusionPlan({
139058
+ task: text,
139059
+ cwd: this.host.state.appState.workDir,
139060
+ model: this.host.state.appState.model,
139061
+ thinkingLevel: this.host.state.appState.thinkingLevel === "off" ? void 0 : this.host.state.appState.thinkingLevel,
139062
+ workerCount: this.host.state.appState.fusionPlan.workerCount,
139063
+ timeoutMs: this.host.state.appState.fusionPlan.timeoutSeconds * 1e3,
139064
+ onProgress: (event) => {
139065
+ if (this.fusionPlanEntry === void 0) {
139066
+ this.fusionPlanEntry = {
139067
+ id: nextTranscriptId(),
139068
+ kind: "status",
139069
+ renderMode: "plain",
139070
+ content: "融合计划",
139071
+ fusionPlanStatus: event
139072
+ };
139073
+ const component = this.host.appendTranscriptEntry(this.fusionPlanEntry);
139074
+ this.fusionPlanComponent = component instanceof FusionPlanStatusComponent ? component : void 0;
139075
+ return;
139076
+ }
139077
+ this.fusionPlanEntry.fusionPlanStatus = event;
139078
+ this.fusionPlanComponent?.setData(event);
139079
+ }
139080
+ }).then(async (result) => {
139081
+ if (!result.ok) {
139082
+ const details = result.workerResults.map((r, i) => {
139083
+ if (r.ok) return `worker ${i + 1}: ok`;
139084
+ if (r.timedOut) {
139085
+ const timeoutS = r.timeoutMs !== void 0 ? Math.round(r.timeoutMs / 1e3) : 600;
139086
+ return `worker ${i + 1}: timed out after ${timeoutS}s`;
139087
+ }
139088
+ const reason = r.exitCode !== null ? `exit ${r.exitCode}` : r.stderr.trim() || "no output";
139089
+ const commandHint = r.command ? ` [${r.command}]` : "";
139090
+ return `worker ${i + 1}: failed (${reason})${commandHint}`;
139091
+ }).join("; ");
139092
+ this.updateFusionPlanStatus({
139093
+ phase: "failed",
139094
+ detail: details
139095
+ });
139096
+ this.host.showError(`融合计划生成失败 (${details})`);
139097
+ return;
139098
+ }
139099
+ try {
139100
+ if (!((await session.getStatus().catch(() => null))?.planMode ?? false)) await session.setPlanMode(true);
139101
+ const plan = await session.getPlan();
139102
+ if (plan?.path) await writeFile(plan.path, result.plan, "utf8");
139103
+ else {
139104
+ this.updateFusionPlanStatus({
139105
+ phase: "failed",
139106
+ detail: "无法定位计划文件路径"
139107
+ });
139108
+ this.host.showError("无法定位计划文件路径");
139109
+ return;
139110
+ }
139111
+ } catch (error) {
139112
+ const message = formatErrorMessage(error);
139113
+ this.updateFusionPlanStatus({
139114
+ phase: "failed",
139115
+ detail: message
139116
+ });
139117
+ this.host.showError(`写入计划文件失败:${message}`);
139118
+ return;
139119
+ }
139120
+ this.host.setAppState({ planMode: "plan" });
139121
+ this.host.showStatus("融合计划已生成,进入计划审批", this.host.state.theme.colors.success);
139122
+ this.dispatchUserInput(text, session);
139123
+ }).catch((error) => {
139124
+ const message = formatErrorMessage(error);
139125
+ this.updateFusionPlanStatus({
139126
+ phase: "failed",
139127
+ detail: message
139128
+ });
139129
+ this.host.showError(`融合计划异常:${message}`);
139130
+ }).finally(() => {
139131
+ this.isFusionPlanRunning = false;
139132
+ this.fusionPlanComponent = void 0;
139133
+ this.fusionPlanEntry = void 0;
139134
+ });
139135
+ }
139136
+ updateFusionPlanStatus(patch) {
139137
+ if (this.fusionPlanEntry === void 0 || this.fusionPlanComponent === void 0) return;
139138
+ const current = this.fusionPlanEntry.fusionPlanStatus;
139139
+ if (current === void 0) return;
139140
+ const updated = {
139141
+ ...current,
139142
+ phase: patch.phase,
139143
+ detail: patch.detail
139144
+ };
139145
+ this.fusionPlanEntry.fusionPlanStatus = updated;
139146
+ this.fusionPlanComponent.setData(updated);
139147
+ }
137651
139148
  steerMessage(session, input) {
137652
139149
  if (this.host.deferUserMessages || this.host.state.appState.isCompacting) {
137653
139150
  for (const part of input) this.enqueueMessage(part);
137654
139151
  return;
137655
139152
  }
137656
- if (this.host.state.appState.streamingPhase === "idle") {
139153
+ if (!isStreaming(this.host.state.appState)) {
137657
139154
  for (const part of input) this.sendMessageInternal(session, part);
137658
139155
  return;
137659
139156
  }
@@ -137670,16 +139167,19 @@ var InputController = class {
137670
139167
  this.host.showError(`引导失败:${message}`);
137671
139168
  });
137672
139169
  }
137673
- handlePlanToggle(next) {
137674
- handlePlanCommand(this.host, next ? "on" : "off");
139170
+ handlePlanModeStateChange(state) {
139171
+ if (state === "off") handlePlanCommand(this.host, "off");
139172
+ else if (state === "plan") handlePlanCommand(this.host, "on");
139173
+ else handleFusionPlanCommand(this.host, "on");
137675
139174
  }
137676
139175
  updateEditorBorderHighlight(text) {
137677
139176
  const trimmed = (text ?? this.host.state.editor.getText()).trimStart();
137678
- const isPlan = this.host.state.appState.planMode;
139177
+ const planMode = this.host.state.appState.planMode;
139178
+ const isPlan = planMode !== "off";
137679
139179
  if (trimmed.length === 0 && !isPlan && !this.breatheOnceStopped) this.#startBreathing();
137680
139180
  else {
137681
139181
  this.#stopBreathing();
137682
- const colorToken = isPlan ? this.host.state.theme.colors.planMode : this.host.state.theme.colors.primary;
139182
+ const colorToken = isPlan ? planMode === "fusionplan" ? this.host.state.theme.colors.fusionPlanMode : this.host.state.theme.colors.planMode : this.host.state.theme.colors.primary;
137683
139183
  this.host.state.editor.borderColor = (s) => chalk.hex(colorToken)(s);
137684
139184
  this.host.state.ui.requestRender();
137685
139185
  }
@@ -137700,7 +139200,7 @@ var InputController = class {
137700
139200
  if (this.breatheOnceStopped) return;
137701
139201
  const primaryHex = this.host.state.theme.colors.primary;
137702
139202
  const [r, g, b] = hexToRgb$1(primaryHex);
137703
- const [baseHue] = rgbToHsl(r, g, b);
139203
+ const [baseHue] = rgbToHsl$1(r, g, b);
137704
139204
  this.breatheFrame = 0;
137705
139205
  const editor = this.host.state.editor;
137706
139206
  const ui = this.host.state.ui;
@@ -137779,7 +139279,7 @@ var InputController = class {
137779
139279
  });
137780
139280
  }
137781
139281
  sendMessage(session, input, options) {
137782
- if (this.host.deferUserMessages || this.host.state.appState.streamingPhase !== "idle" || this.host.state.appState.isCompacting) {
139282
+ if (this.host.deferUserMessages || isBusy(this.host.state.appState)) {
137783
139283
  this.enqueueMessage(input, options);
137784
139284
  return;
137785
139285
  }
@@ -138000,11 +139500,50 @@ var QuestionController = class extends ReverseRpcController {
138000
139500
  //#endregion
138001
139501
  //#region src/tui/types.ts
138002
139502
  const INITIAL_LIVE_PANE = {
138003
- mode: "idle",
138004
139503
  pendingApproval: null,
138005
139504
  pendingQuestion: null
138006
139505
  };
138007
139506
  //#endregion
139507
+ //#region src/tui/utils/render-batcher.ts
139508
+ function createRenderBatcher(doRender) {
139509
+ let scheduled = false;
139510
+ let pendingForce = false;
139511
+ let batchDepth = 0;
139512
+ let batchNeedsRender = false;
139513
+ const scheduleRender = (force) => {
139514
+ pendingForce ||= force;
139515
+ if (scheduled) return;
139516
+ scheduled = true;
139517
+ queueMicrotask(() => {
139518
+ scheduled = false;
139519
+ const renderForce = pendingForce;
139520
+ pendingForce = false;
139521
+ doRender(renderForce);
139522
+ });
139523
+ };
139524
+ return {
139525
+ requestRender(force = false) {
139526
+ if (batchDepth > 0) {
139527
+ batchNeedsRender = true;
139528
+ return;
139529
+ }
139530
+ scheduleRender(force);
139531
+ },
139532
+ batchUpdate(fn) {
139533
+ batchDepth++;
139534
+ try {
139535
+ return fn();
139536
+ } finally {
139537
+ batchDepth--;
139538
+ if (batchDepth === 0 && batchNeedsRender) {
139539
+ batchNeedsRender = false;
139540
+ scheduleRender(true);
139541
+ }
139542
+ }
139543
+ }
139544
+ };
139545
+ }
139546
+ //#endregion
138008
139547
  //#region src/tui/components/chrome/error-banner.ts
138009
139548
  const MAX_BANNER_LINES = 3;
138010
139549
  const CONTINUATION_INDENT = " ";
@@ -138043,6 +139582,14 @@ var ErrorBannerComponent = class {
138043
139582
  }
138044
139583
  };
138045
139584
  //#endregion
139585
+ //#region src/tui/loop-state.ts
139586
+ function resolveLoopSubstate(state) {
139587
+ if (!state.loopModeEnabled) return "idle";
139588
+ if (state.loopVerifying) return "verifying";
139589
+ if (state.loopPrompt === void 0) return "paused";
139590
+ return "running";
139591
+ }
139592
+ //#endregion
138046
139593
  //#region src/tui/utils/shimmer.ts
138047
139594
  const SHIMMER_SPEED_CELLS_PER_S = 30;
138048
139595
  const PADDING = 10;
@@ -138595,10 +140142,10 @@ function lerpGradient(t) {
138595
140142
  const b = Math.round(b0 + (b1 - b0) * localT);
138596
140143
  return `#${r.toString(16).padStart(2, "0")}${g.toString(16).padStart(2, "0")}${b.toString(16).padStart(2, "0")}`;
138597
140144
  }
138598
- function buildStatusLine(streamingPhase, livePaneMode, streamingStartTime) {
138599
- if (streamingPhase === "idle" && livePaneMode !== "tool") return "○ 空闲";
140145
+ function buildStatusLine(streamingPhase, streamingStartTime) {
140146
+ if (streamingPhase === "idle") return "○ 空闲";
138600
140147
  let label;
138601
- if (livePaneMode === "tool") label = "执行中";
140148
+ if (streamingPhase === "tool") label = "执行中";
138602
140149
  else if (streamingPhase === "waiting") label = "等待响应";
138603
140150
  else if (streamingPhase === "thinking") label = "思考中";
138604
140151
  else if (streamingPhase === "composing") label = "输出中";
@@ -138699,7 +140246,10 @@ var FooterComponent = class {
138699
140246
  const left = [];
138700
140247
  if (state.permissionMode === "auto") left.push(chalk.hex(colors.warning).bold("auto"));
138701
140248
  if (state.permissionMode === "yolo") left.push(chalk.hex(colors.warning).bold("YES"));
138702
- if (state.planMode) left.push(chalk.hex(colors.planMode).bold("plan"));
140249
+ if (state.planMode !== "off") {
140250
+ const isFusion = state.planMode === "fusionplan";
140251
+ left.push(chalk.hex(isFusion ? colors.fusionPlanMode : colors.planMode).bold(isFusion ? "fusion" : "plan"));
140252
+ }
138703
140253
  if (state.wolfpackMode) left.push(chalk.hex(colors.primary).bold("wolfpack"));
138704
140254
  if (state.loopModeEnabled) {
138705
140255
  const iter = state.loopIteration;
@@ -138710,6 +140260,7 @@ var FooterComponent = class {
138710
140260
  const remainMs = Math.max(0, limit.deadlineMs - Date.now());
138711
140261
  badge = remainMs >= 6e4 ? `loop ${Math.ceil(remainMs / 6e4)}m` : `loop ${Math.max(1, Math.ceil(remainMs / 1e3))}s`;
138712
140262
  }
140263
+ if (resolveLoopSubstate(state) === "verifying") badge += " · 验证中";
138713
140264
  if (state.loopLastVerifyPassed === false) badge += " · ✗";
138714
140265
  left.push(chalk.hex(colors.primary).bold(badge));
138715
140266
  }
@@ -138734,7 +140285,7 @@ var FooterComponent = class {
138734
140285
  let rightText;
138735
140286
  if (this.transientHint) rightText = chalk.hex(colors.warning).bold(this.transientHint);
138736
140287
  else {
138737
- const statusLine = buildStatusLine(state.streamingPhase, state.livePaneMode, state.streamingStartTime);
140288
+ const statusLine = buildStatusLine(state.streamingPhase, state.streamingStartTime);
138738
140289
  const ccDot = state.ccConnectActive ? chalk.hex(colors.success)("●") : chalk.hex(colors.textDim)("●");
138739
140290
  const contextColor = pickContextColor(state.contextUsage, colors);
138740
140291
  rightText = `${ccDot} ${chalk.hex(contextColor)(formatContextStatus(state.contextUsage, state.contextTokens, state.maxContextTokens))}${chalk.hex(colors.textDim)(` ${statusLine}`)}`;
@@ -138966,6 +140517,8 @@ var CustomEditor = class extends Editor {
138966
140517
  }
138967
140518
  /** Whether the active model has thinking enabled. When true, a small "think" label is embedded in the top-right of the input box border. */
138968
140519
  thinking = false;
140520
+ /** Current thinking effort level (e.g. low, medium, high). Used to annotate the think label. */
140521
+ thinkingLevel = "off";
138969
140522
  consumingPaste = false;
138970
140523
  consumeBuffer = "";
138971
140524
  /**
@@ -139024,7 +140577,7 @@ var CustomEditor = class extends Editor {
139024
140577
  const withPrompt = injectPromptSymbol(firstContent);
139025
140578
  if (withPrompt !== void 0) lines[firstContentIdx] = withPrompt;
139026
140579
  }
139027
- if (this.thinking) injectThinkLabel(lines, width, this.borderColor ?? ((s) => s));
140580
+ if (this.thinking) injectThinkLabel(lines, width, this.thinkingLevel, this.borderColor ?? ((s) => s));
139028
140581
  return lines;
139029
140582
  }
139030
140583
  handleInput(data) {
@@ -139154,14 +140707,14 @@ const THINK_LABEL_MIN_WIDTH = 14;
139154
140707
  * The label only appears when the active model has thinking enabled.
139155
140708
  * Works with pi-tui's flat two-line design (no side borders).
139156
140709
  */
139157
- function injectThinkLabel(lines, width, paint) {
140710
+ function injectThinkLabel(lines, width, thinkingLevel, paint) {
139158
140711
  if (width < THINK_LABEL_MIN_WIDTH) return;
139159
140712
  const topIdx = lines.findIndex((line) => {
139160
140713
  const plain = stripSgr(line);
139161
140714
  return plain.length > 0 && plain[0] === "─";
139162
140715
  });
139163
140716
  if (topIdx === -1) return;
139164
- const labelBlock = `─${THINK_LABEL}─`;
140717
+ const labelBlock = `─${thinkingLevel !== "off" ? ` Think ${thinkingLevel} ` : THINK_LABEL}─`;
139165
140718
  const labelVis = visibleWidth(labelBlock);
139166
140719
  const leftDashCount = width - 1 - labelVis;
139167
140720
  if (leftDashCount < 1) return;
@@ -139353,6 +140906,15 @@ function detectFdPath() {
139353
140906
  }
139354
140907
  //#endregion
139355
140908
  //#region src/tui/tui-state.ts
140909
+ function logRenderError(error) {
140910
+ try {
140911
+ const logDir = getLogDir();
140912
+ mkdirSync(logDir, { recursive: true });
140913
+ const message = error instanceof Error ? error.stack ?? error.message : String(error);
140914
+ const line = `[${(/* @__PURE__ */ new Date()).toISOString()}] TUI render error: ${message}\n`;
140915
+ appendFileSync(`${logDir}/render-errors.log`, line, "utf8");
140916
+ } catch {}
140917
+ }
139356
140918
  function createTUIState(options) {
139357
140919
  const initialAppState = options.initialAppState;
139358
140920
  const theme = createScreamTUIThemeBundle(initialAppState.theme, options.resolvedTheme);
@@ -139364,7 +140926,13 @@ function createTUIState(options) {
139364
140926
  uiAny["doRender"] = () => {
139365
140927
  try {
139366
140928
  originalDoRender();
139367
- } catch {}
140929
+ } catch (error) {
140930
+ logRenderError(error);
140931
+ }
140932
+ };
140933
+ const renderBatcher = createRenderBatcher(ui.requestRender.bind(ui));
140934
+ ui.requestRender = (force = false) => {
140935
+ renderBatcher.requestRender(force);
139368
140936
  };
139369
140937
  const transcriptContainer = new GutterContainer(1, 1);
139370
140938
  const activityContainer = new GutterContainer(1, 1);
@@ -139376,7 +140944,8 @@ function createTUIState(options) {
139376
140944
  errorBannerContainer.addChild(errorBanner);
139377
140945
  const editorContainer = new GutterContainer(1, 1);
139378
140946
  const editor = new CustomEditor(ui, theme.colors);
139379
- editor.thinking = initialAppState.thinking;
140947
+ editor.thinking = initialAppState.thinkingLevel !== "off";
140948
+ editor.thinkingLevel = initialAppState.thinkingLevel;
139380
140949
  return {
139381
140950
  ui,
139382
140951
  terminal,
@@ -139409,7 +140978,8 @@ function createTUIState(options) {
139409
140978
  externalEditorRunning: false,
139410
140979
  queuedMessages: [],
139411
140980
  fdPath: detectFdPath(),
139412
- gitLsFilesCache: createGitLsFilesCache(initialAppState.workDir)
140981
+ gitLsFilesCache: createGitLsFilesCache(initialAppState.workDir),
140982
+ renderBatcher
139413
140983
  };
139414
140984
  }
139415
140985
  //#endregion
@@ -139909,9 +141479,8 @@ var SessionManager = class {
139909
141479
  this.host.setAppState({
139910
141480
  sessionId: session.id,
139911
141481
  model: status.model ?? "",
139912
- thinking: status.thinkingLevel !== "off",
139913
- permissionMode: status.permission,
139914
- planMode: status.planMode,
141482
+ thinkingLevel: status.thinkingLevel,
141483
+ planMode: status.planMode ? "plan" : "off",
139915
141484
  contextTokens: status.contextTokens,
139916
141485
  maxContextTokens: status.maxContextTokens,
139917
141486
  contextUsage: status.contextUsage,
@@ -139965,7 +141534,7 @@ var SessionManager = class {
139965
141534
  this.host.showStatus("已在该会话中。");
139966
141535
  return { switched: true };
139967
141536
  }
139968
- if (this.host.state.appState.streamingPhase !== "idle") {
141537
+ if (isBusy(this.host.state.appState)) {
139969
141538
  this.host.showError("流式传输期间无法切换会话 — 请先按 Esc 或 Ctrl-C。");
139970
141539
  return { switched: false };
139971
141540
  }
@@ -140043,9 +141612,9 @@ var SessionManager = class {
140043
141612
  return this.host.harness.createSession({
140044
141613
  workDir: this.host.state.appState.workDir,
140045
141614
  model,
140046
- thinking: this.host.session === void 0 ? void 0 : this.host.state.appState.thinking ? "on" : "off",
141615
+ thinking: this.host.session === void 0 ? void 0 : this.host.state.appState.thinkingLevel === "off" ? "off" : this.host.state.appState.thinkingLevel,
140047
141616
  permission: this.host.state.appState.permissionMode,
140048
- planMode: this.host.state.appState.planMode ? true : void 0
141617
+ planMode: this.host.state.appState.planMode !== "off" ? true : void 0
140049
141618
  });
140050
141619
  }
140051
141620
  resetSessionRuntime() {
@@ -141981,22 +143550,25 @@ function createInitialAppState(input) {
141981
143550
  workDir: input.workDir,
141982
143551
  sessionId: "",
141983
143552
  permissionMode: startupPermission,
141984
- planMode: input.cliOptions.plan,
141985
- thinking: false,
143553
+ planMode: input.cliOptions.plan ? "plan" : "off",
143554
+ thinkingLevel: "off",
141986
143555
  contextUsage: 0,
141987
143556
  contextTokens: 0,
141988
143557
  maxContextTokens: 0,
141989
143558
  isCompacting: false,
143559
+ lastCompactionFinishedAt: void 0,
143560
+ autoCompactionCount: 0,
141990
143561
  isReplaying: false,
141991
143562
  streamingPhase: "idle",
141992
143563
  streamingStartTime: 0,
141993
- livePaneMode: "idle",
141994
143564
  theme: input.tuiConfig.theme,
141995
143565
  version: input.version,
141996
143566
  hasNewVersion: false,
141997
143567
  latestVersion: null,
141998
143568
  editorCommand: input.tuiConfig.editorCommand,
141999
143569
  notifications: input.tuiConfig.notifications,
143570
+ like: input.tuiConfig.like,
143571
+ fusionPlan: input.tuiConfig.fusionPlan,
142000
143572
  availableModels: {},
142001
143573
  availableProviders: {},
142002
143574
  sessionTitle: null,
@@ -142011,6 +143583,7 @@ function createInitialAppState(input) {
142011
143583
  loopVerifier: void 0,
142012
143584
  loopIteration: 0,
142013
143585
  loopLastVerifyPassed: void 0,
143586
+ loopVerifying: false,
142014
143587
  recentSessions: []
142015
143588
  };
142016
143589
  }
@@ -142031,6 +143604,7 @@ var ScreamTUI = class {
142031
143604
  isShuttingDown = false;
142032
143605
  reverseRpcDisposers = [];
142033
143606
  startupNotice;
143607
+ updatePrefetched;
142034
143608
  sessionManager;
142035
143609
  dialogManager;
142036
143610
  streamingUI;
@@ -142043,6 +143617,14 @@ var ScreamTUI = class {
142043
143617
  lifecycleController;
142044
143618
  inputController;
142045
143619
  onExit;
143620
+ /**
143621
+ * Execute a compound UI update without intermediate renders. All
143622
+ * `requestRender()` calls inside `fn` are deferred; a single force render is
143623
+ * queued when the batch completes.
143624
+ */
143625
+ batchUpdate(fn) {
143626
+ return this.state.renderBatcher.batchUpdate(fn);
143627
+ }
142046
143628
  constructor(harness, startupInput) {
142047
143629
  this.harness = harness;
142048
143630
  const tuiOptions = {
@@ -142060,6 +143642,7 @@ var ScreamTUI = class {
142060
143642
  };
142061
143643
  this.options = tuiOptions;
142062
143644
  this.startupNotice = startupInput.startupNotice;
143645
+ this.updatePrefetched = startupInput.updatePrefetched === true;
142063
143646
  this.state = createTUIState(tuiOptions);
142064
143647
  this.reverseRpcDisposers.push(...registerReverseRPCHandlers(this.approvalController, this.questionController, {
142065
143648
  showApprovalPanel: (payload) => {
@@ -142132,6 +143715,7 @@ var ScreamTUI = class {
142132
143715
  }
142133
143716
  async initMainTui() {
142134
143717
  const shouldReplayHistory = await this.init();
143718
+ await this.checkForUpdates();
142135
143719
  try {
142136
143720
  const sessions = await this.harness.listSessions({ workDir: this.state.appState.workDir });
142137
143721
  this.state.appState.recentSessions = sessions.slice(0, 3).map((s) => ({
@@ -142165,11 +143749,7 @@ var ScreamTUI = class {
142165
143749
  if (shouldReplayHistory) await this.sessionReplay.hydrateFromReplay(this.requireSession());
142166
143750
  const resumeState = this.session?.getResumeState();
142167
143751
  if (resumeState?.warning !== void 0) this.showStatus(`警告:${resumeState.warning}`, this.state.theme.colors.warning);
142168
- if (this.session !== void 0) this.sessionEventHandler.startSubscription();
142169
- this.fetchSessions();
142170
- if (this.session !== void 0) this.refreshSessionTitle();
142171
143752
  this.refreshSkillCommands(this.session);
142172
- this.checkForUpdates();
142173
143753
  }
142174
143754
  async showTmuxKeyboardWarningIfNeeded() {
142175
143755
  const warning = await detectTmuxKeyboardWarning();
@@ -142251,8 +143831,8 @@ var ScreamTUI = class {
142251
143831
  emergencyTerminalExit(exitCode) {
142252
143832
  this.onEmergencyExit(exitCode);
142253
143833
  }
142254
- handlePlanToggle(next) {
142255
- this.inputController.handlePlanToggle(next);
143834
+ handlePlanModeStateChange(state) {
143835
+ this.inputController.handlePlanModeStateChange(state);
142256
143836
  }
142257
143837
  steerMessage(session, input) {
142258
143838
  this.inputController.steerMessage(session, input);
@@ -142263,14 +143843,10 @@ var ScreamTUI = class {
142263
143843
  this.streamingUI.resetToolUi();
142264
143844
  this.streamingUI.resetToolCallState();
142265
143845
  this.patchLivePane({
142266
- mode: "waiting",
142267
143846
  pendingApproval: null,
142268
143847
  pendingQuestion: null
142269
143848
  });
142270
- this.setAppState({
142271
- streamingPhase: "waiting",
142272
- streamingStartTime: Date.now()
142273
- });
143849
+ this.setAppState({ streamingPhase: "waiting" });
142274
143850
  }
142275
143851
  failSessionRequest(message) {
142276
143852
  this.setAppState({ streamingPhase: "idle" });
@@ -142352,11 +143928,18 @@ var ScreamTUI = class {
142352
143928
  }
142353
143929
  }
142354
143930
  setAppState(patch) {
143931
+ if ("streamingPhase" in patch && patch.streamingPhase !== void 0 && patch.streamingPhase !== this.state.appState.streamingPhase) patch = {
143932
+ ...patch,
143933
+ streamingStartTime: patch.streamingPhase === "idle" ? 0 : Date.now()
143934
+ };
142355
143935
  if (!hasPatchChanges(this.state.appState, patch)) return;
142356
143936
  const busyChanged = "streamingPhase" in patch || "isCompacting" in patch;
142357
143937
  Object.assign(this.state.appState, patch);
142358
143938
  if ("planMode" in patch) this.updateEditorBorderHighlight();
142359
- if ("thinking" in patch) this.state.editor.thinking = patch.thinking ?? false;
143939
+ if ("thinkingLevel" in patch) {
143940
+ this.state.editor.thinking = patch.thinkingLevel !== "off";
143941
+ this.state.editor.thinkingLevel = patch.thinkingLevel ?? "off";
143942
+ }
142360
143943
  if ("streamingPhase" in patch && patch.streamingPhase !== "idle") this.transcriptController.stopWelcomeBreathing();
142361
143944
  this.state.footer.setState(this.state.appState);
142362
143945
  this.lifecycleController.updateActivityPane();
@@ -142366,10 +143949,6 @@ var ScreamTUI = class {
142366
143949
  patchLivePane(patch) {
142367
143950
  if (!hasPatchChanges(this.state.livePane, patch)) return;
142368
143951
  Object.assign(this.state.livePane, patch);
142369
- if ("mode" in patch) {
142370
- this.state.appState.livePaneMode = patch.mode;
142371
- this.state.footer.setState(this.state.appState);
142372
- }
142373
143952
  this.lifecycleController.updateActivityPane();
142374
143953
  this.state.ui.requestRender();
142375
143954
  }
@@ -142396,7 +143975,7 @@ var ScreamTUI = class {
142396
143975
  }
142397
143976
  async checkForUpdates() {
142398
143977
  try {
142399
- await refreshUpdateCache().catch(() => {});
143978
+ if (!this.updatePrefetched) await refreshUpdateCache().catch(() => {});
142400
143979
  const cache = await readUpdateCache();
142401
143980
  const target = selectUpdateTarget(this.state.appState.version, cache.latest);
142402
143981
  if (target !== null) this.setAppState({
@@ -142411,14 +143990,6 @@ var ScreamTUI = class {
142411
143990
  resetSessionRuntime() {
142412
143991
  this.sessionManager.resetSessionRuntime();
142413
143992
  }
142414
- /**
142415
- * Pin the editor + footer to the terminal bottom. The pi-tui patch adds a
142416
- * `fixedBottomLineCount` property: the last N rendered lines stay pinned
142417
- * while the transcript above scrolls independently.
142418
- *
142419
- * We override `doRender` to measure the editor + footer height each frame
142420
- * and set the count before the real render runs.
142421
- */
142422
143993
  async resumeSession(targetSessionId) {
142423
143994
  return (await this.sessionManager.resumeSession(targetSessionId)).switched;
142424
143995
  }
@@ -142436,7 +144007,7 @@ var ScreamTUI = class {
142436
144007
  this.transcriptController.stopWelcomeBreathing();
142437
144008
  }
142438
144009
  appendTranscriptEntry(entry) {
142439
- this.transcriptController.appendEntry(entry);
144010
+ return this.transcriptController.appendEntry(entry);
142440
144011
  }
142441
144012
  appendApprovalTranscriptEntry(request, response) {
142442
144013
  this.transcriptController.appendApprovalEntry(request, response);
@@ -142548,10 +144119,10 @@ const SHADOW_CHARS = new Set([
142548
144119
  "╩",
142549
144120
  "╬"
142550
144121
  ]);
142551
- const SHEEN_STEP = 2;
142552
- const SHEEN_INTERVAL_MS = 150;
144122
+ const SHEEN_STEP = 4;
144123
+ const SHEEN_INTERVAL_MS = 60;
142553
144124
  const LOADING_DURATION_MS = 1500;
142554
- const THEME_ACCENT = {
144125
+ const THEME_PRIMARY = {
142555
144126
  dark: [
142556
144127
  78,
142557
144128
  200,
@@ -142578,39 +144149,98 @@ const DIM_RGB = [
142578
144149
  85,
142579
144150
  85
142580
144151
  ];
144152
+ const HUE_STOPS = 24;
144153
+ const SUB_STEPS = 5;
144154
+ const BREATHE_STEPS = HUE_STOPS * SUB_STEPS;
144155
+ function rgbToHsl(r, g, b) {
144156
+ const rf = r / 255, gf = g / 255, bf = b / 255;
144157
+ const max = Math.max(rf, gf, bf), min = Math.min(rf, gf, bf);
144158
+ const l = (max + min) / 2;
144159
+ if (max === min) return [
144160
+ 0,
144161
+ 0,
144162
+ l * 100
144163
+ ];
144164
+ const d = max - min;
144165
+ const s = l > .5 ? d / (2 - max - min) : d / (max + min);
144166
+ let h = 0;
144167
+ if (max === rf) h = ((gf - bf) / d + (gf < bf ? 6 : 0)) / 6;
144168
+ else if (max === gf) h = ((bf - rf) / d + 2) / 6;
144169
+ else h = ((rf - gf) / d + 4) / 6;
144170
+ return [
144171
+ h * 360,
144172
+ s * 100,
144173
+ l * 100
144174
+ ];
144175
+ }
144176
+ function hslToRgb(h, s, l) {
144177
+ const hf = (h % 360 + 360) % 360 / 360;
144178
+ const sf = s / 100, lf = l / 100;
144179
+ if (sf === 0) {
144180
+ const v = Math.round(lf * 255);
144181
+ return [
144182
+ v,
144183
+ v,
144184
+ v
144185
+ ];
144186
+ }
144187
+ const q = lf < .5 ? lf * (1 + sf) : lf + sf - lf * sf;
144188
+ const p = 2 * lf - q;
144189
+ const hue = (t) => {
144190
+ if (t < 0) t += 1;
144191
+ if (t > 1) t -= 1;
144192
+ if (t < 1 / 6) return p + (q - p) * 6 * t;
144193
+ if (t < 1 / 2) return q;
144194
+ if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
144195
+ return p;
144196
+ };
144197
+ return [
144198
+ Math.round(hue(hf + 1 / 3) * 255),
144199
+ Math.round(hue(hf) * 255),
144200
+ Math.round(hue(hf - 1 / 3) * 255)
144201
+ ];
144202
+ }
144203
+ function buildBreathingPalette(primary) {
144204
+ const [r, g, b] = primary;
144205
+ const [baseHue] = rgbToHsl(r, g, b);
144206
+ const steps = HUE_STOPS * SUB_STEPS;
144207
+ const palette = [];
144208
+ for (let i = 0; i < steps; i++) {
144209
+ const hueAngle = (baseHue + i / steps * 360) % 360;
144210
+ palette.push(hslToRgb(hueAngle, 90, 70));
144211
+ }
144212
+ return palette;
144213
+ }
142581
144214
  function fg(r, g, b) {
142582
144215
  return `\u001B[38;2;${r};${g};${b}m`;
142583
144216
  }
142584
144217
  const RESET = "\x1B[0m";
142585
144218
  const BOLD = "\x1B[1m";
142586
144219
  const DIM = "\x1B[2m";
142587
- function renderSheen(char, charIndex, sheenPos, isReversing, accent) {
144220
+ function renderSheen(char, charIndex, sheenPos, isReversing, breatheColor) {
142588
144221
  if (char === " ") return " ";
142589
144222
  if (char === "█") return `${fg(...BLOCK_RGB)}█${RESET}`;
142590
144223
  if (!SHADOW_CHARS.has(char)) return `${fg(...LOGO_RGB)}${char}${RESET}`;
142591
- let color;
142592
- if (isReversing) color = charIndex <= sheenPos ? LOGO_RGB : accent;
142593
- else color = charIndex <= sheenPos ? accent : LOGO_RGB;
142594
- return `${fg(...color)}${char}${RESET}`;
144224
+ return `${fg(...isReversing ? charIndex <= sheenPos ? LOGO_RGB : breatheColor : charIndex <= sheenPos ? breatheColor : LOGO_RGB)}${char}${RESET}`;
142595
144225
  }
142596
144226
  const LOADING_TEXT = "Ai正在加载中...";
142597
- function buildShimmerPalette(n, accent) {
144227
+ function buildShimmerPalette(n, breatheColor) {
142598
144228
  const size = Math.max(8, Math.min(20, Math.ceil(n * 1.5)));
142599
144229
  const palette = [];
142600
144230
  for (let i = 0; i < size; i++) {
142601
144231
  const t = i / (size - 1);
142602
144232
  palette.push([
142603
- Math.round(accent[0] - t * accent[0] * .35),
142604
- Math.round(accent[1] - t * accent[1] * .6),
142605
- Math.round(accent[2] - t * accent[2] * .33)
144233
+ Math.round(breatheColor[0] - t * breatheColor[0] * .35),
144234
+ Math.round(breatheColor[1] - t * breatheColor[1] * .6),
144235
+ Math.round(breatheColor[2] - t * breatheColor[2] * .33)
142606
144236
  ]);
142607
144237
  }
142608
144238
  return palette;
142609
144239
  }
142610
- function renderShimmer(pulse, accent) {
144240
+ function renderShimmer(pulse, breatheColor) {
142611
144241
  const chars = LOADING_TEXT.split("");
142612
144242
  const n = chars.length;
142613
- const palette = buildShimmerPalette(n, accent);
144243
+ const palette = buildShimmerPalette(n, breatheColor);
142614
144244
  let out = "";
142615
144245
  for (let i = 0; i < n; i++) {
142616
144246
  const phase = (pulse - i + n) % n;
@@ -142676,34 +144306,44 @@ function supportsAnsi() {
142676
144306
  ansiSupported = false;
142677
144307
  return false;
142678
144308
  }
142679
- function runLoadingAnimation(theme = "dark") {
144309
+ function runLoadingAnimation(theme = "dark", prefetch) {
142680
144310
  if (!supportsAnsi()) {
142681
- for (const line of LOGO) stdout.write(`${fg(...LOGO_RGB)}${line}${RESET}\n`);
142682
- stdout.write(`${BOLD}${fg(...THEME_ACCENT[theme])}正在唤醒核心...${RESET}\n`);
142683
- return Promise.resolve();
144311
+ const finish = () => {
144312
+ for (const line of LOGO) stdout.write(`${fg(...LOGO_RGB)}${line}${RESET}\n`);
144313
+ stdout.write(`${BOLD}${fg(...THEME_PRIMARY[theme])}正在唤醒核心...${RESET}\n`);
144314
+ };
144315
+ if (prefetch === void 0) {
144316
+ finish();
144317
+ return Promise.resolve();
144318
+ }
144319
+ return prefetch.catch(() => {}).finally(() => finish()).then(() => void 0);
142684
144320
  }
142685
144321
  return new Promise((resolve) => {
142686
144322
  if (process$1.platform !== "win32") stdout.write("\x1B[?1049h");
142687
144323
  stdout.write("\x1B[2J");
142688
144324
  stdout.write("\x1B[?25l");
142689
- const accent = THEME_ACCENT[theme];
144325
+ const primary = THEME_PRIMARY[theme];
144326
+ const breathePalette = buildBreathingPalette(primary);
142690
144327
  let sheenPos = 0;
142691
144328
  let isReversing = false;
142692
144329
  let shimmerPulse = 0;
144330
+ let breatheFrame = 0;
142693
144331
  let phase = "loading";
142694
144332
  function render() {
142695
144333
  const { cols, rows } = getTerminalSize();
142696
144334
  const lines = [];
142697
- const contentHeight = LOGO.length + 4;
144335
+ const contentHeight = LOGO.length + 5;
142698
144336
  const topPad = Math.max(0, Math.floor((rows - contentHeight) / 2));
142699
144337
  for (let i = 0; i < topPad; i++) lines.push("");
144338
+ const breatheColor = breathePalette[breatheFrame] ?? primary;
142700
144339
  for (const line of LOGO) {
142701
144340
  let colored = "";
142702
- for (let ci = 0; ci < line.length; ci++) colored += renderSheen(line[ci], ci, sheenPos, isReversing, accent);
144341
+ for (let ci = 0; ci < line.length; ci++) colored += renderSheen(line[ci], ci, sheenPos, isReversing, breatheColor);
142703
144342
  lines.push(centerPad(colored, cols));
142704
144343
  }
142705
- if (phase === "loading") lines.push(centerPad(renderShimmer(shimmerPulse, accent), cols));
142706
- else lines.push(centerPad(`${BOLD}${fg(...accent)}按下 ENTER 唤醒核心${RESET}`, cols));
144344
+ lines.push("");
144345
+ if (phase === "loading") lines.push(centerPad(renderShimmer(shimmerPulse, breatheColor), cols));
144346
+ else lines.push(centerPad(`${BOLD}${fg(...breatheColor)}按下 ENTER 唤醒核心${RESET}`, cols));
142707
144347
  lines.push("");
142708
144348
  lines.push("");
142709
144349
  lines.push(centerPad(`${fg(...DIM_RGB)}按住 Ctrl+C 即可退出 Scream Code${RESET}`, cols));
@@ -142718,6 +144358,7 @@ function runLoadingAnimation(theme = "dark") {
142718
144358
  sheenPos = 0;
142719
144359
  }
142720
144360
  shimmerPulse = (shimmerPulse + 1) % 10;
144361
+ breatheFrame = (breatheFrame + 1) % BREATHE_STEPS;
142721
144362
  render();
142722
144363
  }
142723
144364
  function onData(data) {
@@ -142757,17 +144398,20 @@ function runLoadingAnimation(theme = "dark") {
142757
144398
  stdout.write("\x1B[?25h");
142758
144399
  if (process$1.platform !== "win32") stdout.write("\x1B[?1049l");
142759
144400
  for (const line of LOGO) stdout.write(`${fg(...LOGO_RGB)}${line}${RESET}\n`);
142760
- stdout.write(`${BOLD}${fg(...accent)}正在唤醒核心...${RESET}\n`);
144401
+ stdout.write(`${BOLD}${fg(...primary)}正在唤醒核心...${RESET}\n`);
142761
144402
  resolve();
142762
144403
  return;
142763
144404
  }
142764
144405
  stdin.on("data", onData);
142765
144406
  render();
142766
144407
  const timer = setInterval(tick, SHEEN_INTERVAL_MS);
142767
- setTimeout(() => {
144408
+ const minDelay = new Promise((resolve) => {
144409
+ setTimeout(resolve, LOADING_DURATION_MS);
144410
+ });
144411
+ (prefetch === void 0 ? minDelay : Promise.all([minDelay, prefetch.catch(() => {})])).then(() => {
142768
144412
  phase = "ready";
142769
144413
  render();
142770
- }, LOADING_DURATION_MS);
144414
+ });
142771
144415
  });
142772
144416
  }
142773
144417
  //#endregion
@@ -142797,14 +144441,15 @@ async function runShell(opts, version) {
142797
144441
  });
142798
144442
  await harness.ensureConfigFile();
142799
144443
  await harness.preflight();
142800
- await runLoadingAnimation(resolvedTheme);
144444
+ await runLoadingAnimation(resolvedTheme, refreshUpdateCache().catch(() => {}));
142801
144445
  const tui = new ScreamTUI(harness, {
142802
144446
  cliOptions: opts,
142803
144447
  tuiConfig,
142804
144448
  version,
142805
144449
  workDir,
142806
144450
  startupNotice: configWarning,
142807
- resolvedTheme
144451
+ resolvedTheme,
144452
+ updatePrefetched: true
142808
144453
  });
142809
144454
  tui.onExit = async (exitCode = 0) => {
142810
144455
  const sessionId = tui.getCurrentSessionId();