@swifty.js/swifty 0.0.35 → 0.0.36

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.
@@ -37,7 +37,7 @@ interface UsageInfo {
37
37
  cacheReadInputTokens: number;
38
38
  cacheCreationInputTokens: number;
39
39
  }
40
- /** Tool use delta: Input partial JSON */
40
+ /** Events emitted by an LLM stream: text/thinking deltas, tool-call lifecycle, and stream end. */
41
41
  type StreamEvent = {
42
42
  type: "text_delta";
43
43
  text: string;
@@ -253,7 +253,7 @@ declare class PermissionChecker {
253
253
  allowAlways(toolName: string, args: Record<string, unknown>): void;
254
254
  /**
255
255
  * Generate a human-readable description of the tool action for display in HITL confirmation dialogs.
256
- * Prioritizes extracting fields defined in contentFields (e.g., command, file_path);
256
+ * Prioritizes extracting fields defined in CONTENT_FIELDS (e.g., command, file_path);
257
257
  * falls back to a key:value summary of parameters if no match is found.
258
258
  */
259
259
  describeToolAction(toolName: string, args: Record<string, unknown>): string;
@@ -275,6 +275,100 @@ declare namespace index$v {
275
275
  export { type index$v_Decision as Decision, type index$v_DecisionEffect as DecisionEffect, index$v_PathSandbox as PathSandbox, index$v_PermissionChecker as PermissionChecker, type index$v_PermissionMode as PermissionMode, index$v_RuleEngine as RuleEngine, index$v_evaluateRules as evaluateRules, index$v_extractContent as extractContent, index$v_isSafeCommand as isSafeCommand };
276
276
  }
277
277
 
278
+ /**
279
+ * Copyright (c) 2026 hangtiancheng
280
+ *
281
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
282
+ * of this software and associated documentation files (the "Software"), to deal
283
+ * in the Software without restriction, including without limitation the rights
284
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
285
+ * copies of the Software, and to permit persons to whom the Software is
286
+ * furnished to do so, subject to the following conditions:
287
+ *
288
+ * The above copyright notice and this permission notice shall be included in
289
+ * all copies or substantial portions of the Software.
290
+ *
291
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
292
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
293
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
294
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
295
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
296
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
297
+ * SOFTWARE.
298
+ */
299
+ type AgentTaskStatus = "running" | "completed" | "failed" | "cancelled";
300
+ /**
301
+ * What a task wraps. Hosts use this to wait selectively: print-mode blocks on
302
+ * agent tasks (their results feed the final answer) but must not block on
303
+ * shell/js tasks, which can run indefinitely (dev servers) and are killed at
304
+ * exit instead. Absent kind means "agent" (the original TaskManager use).
305
+ */
306
+ type TaskKind = "agent" | "shell" | "js";
307
+ interface AgentTask {
308
+ id: string;
309
+ name: string;
310
+ originToolCallId?: string;
311
+ kind?: TaskKind;
312
+ status: AgentTaskStatus;
313
+ output: string;
314
+ cancel: () => void;
315
+ done: Promise<void>;
316
+ }
317
+ interface CreateTaskOptions {
318
+ originToolCallId?: string;
319
+ /** ID prefix; defaults to "agent" (background subagents). Bash background tasks use "bash". */
320
+ idPrefix?: string;
321
+ /** Task category; defaults to "agent". */
322
+ kind?: TaskKind;
323
+ }
324
+ /**
325
+ * A runner failure that carries its own pre-formatted output. TaskManager
326
+ * stores `output` verbatim on the failed task instead of the generic
327
+ * `Error: <message>` wrapper, so tool-level results (e.g. a background Bash
328
+ * command's captured output and exit code) reach the notification intact.
329
+ */
330
+ declare class TaskFailure extends Error {
331
+ readonly output: string;
332
+ constructor(output: string);
333
+ }
334
+ declare class TaskManager {
335
+ private tasks;
336
+ private notifiedTaskIds;
337
+ private listeners;
338
+ private nextId;
339
+ private pendingTaskIds;
340
+ create(name: string, runner: (task: AgentTask) => Promise<string>, cancel: () => void, options?: CreateTaskOptions): AgentTask;
341
+ get(id: string): AgentTask | undefined;
342
+ list(): AgentTask[];
343
+ subscribe(listener: (tasks: AgentTask[]) => void): () => void;
344
+ private emitChange;
345
+ hasRunning(): boolean;
346
+ stop(id: string): boolean;
347
+ stopAndWait(id: string): Promise<boolean>;
348
+ stopAll(): Promise<void>;
349
+ /**
350
+ * Wait for tasks to settle. An optional filter selects which tasks to wait
351
+ * for (e.g. print-mode waits only for agent-kind tasks: shell/js tasks may
352
+ * run indefinitely and are stopped, not awaited, at exit).
353
+ */
354
+ waitAll(filter?: (task: AgentTask) => boolean): Promise<void>;
355
+ drainNotifications(): AgentTask[];
356
+ clear(): void;
357
+ }
358
+ declare function formatAgentTaskNotification(task: AgentTask): string;
359
+
360
+ type taskManager_AgentTask = AgentTask;
361
+ type taskManager_AgentTaskStatus = AgentTaskStatus;
362
+ type taskManager_TaskFailure = TaskFailure;
363
+ declare const taskManager_TaskFailure: typeof TaskFailure;
364
+ type taskManager_TaskKind = TaskKind;
365
+ type taskManager_TaskManager = TaskManager;
366
+ declare const taskManager_TaskManager: typeof TaskManager;
367
+ declare const taskManager_formatAgentTaskNotification: typeof formatAgentTaskNotification;
368
+ declare namespace taskManager {
369
+ export { type taskManager_AgentTask as AgentTask, type taskManager_AgentTaskStatus as AgentTaskStatus, taskManager_TaskFailure as TaskFailure, type taskManager_TaskKind as TaskKind, taskManager_TaskManager as TaskManager, taskManager_formatAgentTaskNotification as formatAgentTaskNotification };
370
+ }
371
+
278
372
  /**
279
373
  * Copyright (c) 2026 hangtiancheng
280
374
  *
@@ -312,6 +406,22 @@ interface ToolContext {
312
406
  workDir: string;
313
407
  toolCallId?: string;
314
408
  backgroundTaskId?: string;
409
+ /**
410
+ * Owning session, when the call runs on the main thread. Lets tools persist
411
+ * auxiliary artifacts (e.g. a backgrounded Bash command's output) into the
412
+ * session's tool-results spill directory so the model can Read them back.
413
+ */
414
+ sessionId?: string;
415
+ /**
416
+ * Background task registry of the loop running this call. Subagent loops
417
+ * inject their own manager so backgrounded Bash commands notify that loop
418
+ * instead of the main thread; tools fall back to their host-wired default
419
+ * when absent. Explicit `null` disables backgrounding for this call even
420
+ * when the tool instance carries a host-wired manager (in-process teammate
421
+ * turns use this: their per-turn drain disappears at turn end, so commands
422
+ * backgrounded there could never deliver a notification).
423
+ */
424
+ taskManager?: TaskManager | null;
315
425
  abortSignal?: AbortSignal;
316
426
  fileHistory?: FileHistory | undefined;
317
427
  fileStateCache?: FileStateCache | undefined;
@@ -399,9 +509,10 @@ interface Tool {
399
509
  * judged by actual arguments rather than just the tool category.
400
510
  *
401
511
  * When not implemented, falls back to category: read-only tools may run
402
- * concurrently, write and command tools may not. Currently only Bash
403
- * implements this — whether a command is read-only depends on the command
404
- * itself (ls vs rm are both Bash but have very different safety profiles).
512
+ * concurrently, write and command tools may not. Currently Bash
513
+ * (argument-dependent: ls vs rm are both Bash but have very different safety
514
+ * profiles) and ComputerUse (always false — it drives a single physical
515
+ * screen/mouse/keyboard) implement this.
405
516
  */
406
517
  isConcurrencySafe?(args: Record<string, unknown>): boolean;
407
518
  schema(): ToolSchema;
@@ -735,7 +846,8 @@ declare function rebuildFromSession(saved: SessionMessage[]): RestoredMessage[];
735
846
  declare function listSessions(workDir: string): SessionInfo[];
736
847
  /**
737
848
  * Cleans up expired sessions: deletes .jsonl files whose last modified time exceeds SESSION_EXPIRY_DAYS.
738
- * Called during listSessions or on startup to prevent the session directory from growing indefinitely.
849
+ * Not currently invoked anywhere; intended to run during listSessions or on
850
+ * startup to prevent the session directory from growing indefinitely.
739
851
  * Silently skips failures (best-effort).
740
852
  */
741
853
  declare function cleanExpiredSessions(workDir: string): number;
@@ -1771,7 +1883,6 @@ interface MemoryHeader {
1771
1883
  description: string;
1772
1884
  type: string;
1773
1885
  }
1774
- /** One memory selected for surfacing into the main conversation. */
1775
1886
  /**
1776
1887
  * The output of a single recall: the rendered system-reminder body and the
1777
1888
  * selected memory file paths. Paths are only recorded as surfaced once the
@@ -1781,6 +1892,7 @@ interface RecallResult {
1781
1892
  reminder: string;
1782
1893
  paths: string[];
1783
1894
  }
1895
+ /** One memory selected for surfacing into the main conversation. */
1784
1896
  interface RelevantMemory {
1785
1897
  path: string;
1786
1898
  mtimeMs: number;
@@ -1795,7 +1907,9 @@ declare class MemoryManager {
1795
1907
  loadAll(): MemoryFile[];
1796
1908
  getMemories(): MemoryFile[];
1797
1909
  /**
1798
- * Builds the memory index injected into the system prompt.
1910
+ * Builds the memory index injected into the conversation as a
1911
+ * system-reminder message (not the system prompt, which stays
1912
+ * project-independent to preserve prompt caching).
1799
1913
  *
1800
1914
  * This content is re-sent to the model on every conversation turn, so each additional index line
1801
1915
  * is a recurring cost. We therefore enforce both a line-count and a byte-size cap at the output
@@ -1815,8 +1929,9 @@ declare class MemoryManager {
1815
1929
  private writeIndex;
1816
1930
  /**
1817
1931
  * Scans all memory headers from both dirs, asks the LLM to select the
1818
- * top 5 most relevant ones for the query, and returns the full content
1819
- * of those files. Best-effort: selector failures return an empty array.
1932
+ * top 5 most relevant ones for the query, and returns their paths (with
1933
+ * mtimes); the file contents are read later by renderReminder.
1934
+ * Best-effort: selector failures return an empty array.
1820
1935
  */
1821
1936
  findRelevantMemories(query: string, client: LLMClient, recentTools?: string[], alreadySurfaced?: Set<string>): Promise<RelevantMemory[]>;
1822
1937
  private scanMemoryHeaders;
@@ -2144,6 +2259,14 @@ interface AgentConfig {
2144
2259
  recoveryState?: RecoveryState;
2145
2260
  maxIterations?: number;
2146
2261
  notificationFn?: () => string[];
2262
+ /**
2263
+ * Background task registry owned by this loop. Injected into every tool
2264
+ * context so backgrounded Bash commands register — and later notify — here
2265
+ * instead of on the host-level default. Subagent runs pass their own;
2266
+ * explicit `null` disables backgrounding for the whole loop (in-process
2267
+ * teammate turns) even when tools carry a host-wired manager.
2268
+ */
2269
+ taskManager?: TaskManager | null;
2147
2270
  onLoopComplete?: (conversation: ConversationManager) => void;
2148
2271
  activeSkills?: Map<string, string>;
2149
2272
  toolFilter?: (name: string) => boolean;
@@ -2181,6 +2304,7 @@ declare class Agent {
2181
2304
  private recoveryState;
2182
2305
  private maxIterations;
2183
2306
  private notificationFn?;
2307
+ private taskManager?;
2184
2308
  private onLoopComplete?;
2185
2309
  private compactTracking;
2186
2310
  private onPermissionRequest?;
@@ -3307,6 +3431,15 @@ interface SubagentRunOptions {
3307
3431
  onPermissionRequest?: AgentConfig["onPermissionRequest"];
3308
3432
  permissionMode?: PermissionChecker["mode"];
3309
3433
  conversation?: ConversationManager;
3434
+ /**
3435
+ * Whether this run gets a per-run background task manager (default true).
3436
+ * In-process teammate turns pass false: a teammate loop is one run per task
3437
+ * turn, so the turn-end stopAll() would immediately kill anything the
3438
+ * teammate backgrounded, and the drain disappears before any notification
3439
+ * could be delivered. Teammates stay purely foreground (matching the
3440
+ * subprocess teammate path); subagents they spawn themselves are unaffected.
3441
+ */
3442
+ backgroundTasks?: boolean;
3310
3443
  }
3311
3444
  declare function spawnSubagent(definition: AgentDefinition, prompt: string, parentClient: LLMClient, parentRegistry: ToolRegistry, parentProvider: ProviderConfig, workDir: string, onProgress?: (p: {
3312
3445
  turn?: number;
@@ -3348,18 +3481,20 @@ declare namespace spawn {
3348
3481
  * Auto-detect the best backend for running teammates.
3349
3482
  *
3350
3483
  * Auto-detection logic:
3351
- * - Default to **in-process** so progress tracking works (agent events
3352
- * flow in the same process and can update the Spinner Tree in real time).
3353
- * - Only use tmux/iTerm panes when the user explicitly requests it via
3354
- * config `teammateMode: "tmux"`.
3484
+ * - Windows: always **in-process**.
3485
+ * - Otherwise: tmux/iTerm panes when the corresponding environment is
3486
+ * detected (TMUX / ITERM_SESSION_ID), else **in-process** so progress
3487
+ * tracking works (agent events flow in the same process and can update
3488
+ * the Spinner Tree in real time).
3355
3489
  *
3356
3490
  * In-process teammates share the Node.js event loop but are context-isolated.
3357
3491
  * They communicate via the same file-based mailbox as external teammates.
3358
3492
  */
3359
3493
  declare function detectBackend(): TeamMode;
3360
3494
  /**
3361
- * Detect available pane backend (for explicit tmux mode).
3362
- * Used when the user overrides teammateMode to "tmux".
3495
+ * Detect available pane backend from the environment (TMUX /
3496
+ * ITERM_SESSION_ID); falls back to in-process. Called unconditionally by
3497
+ * detectBackend on non-Windows platforms.
3363
3498
  */
3364
3499
  declare function detectBackendFromEnv(): TeamMode;
3365
3500
  interface SpawnConfig {
@@ -3589,71 +3724,8 @@ declare namespace registry {
3589
3724
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3590
3725
  * SOFTWARE.
3591
3726
  */
3592
- type AgentTaskStatus = "running" | "completed" | "failed" | "cancelled";
3593
- interface AgentTask {
3594
- id: string;
3595
- name: string;
3596
- originToolCallId?: string;
3597
- status: AgentTaskStatus;
3598
- output: string;
3599
- cancel: () => void;
3600
- done: Promise<void>;
3601
- }
3602
- interface CreateTaskOptions {
3603
- originToolCallId?: string;
3604
- }
3605
- declare class TaskManager {
3606
- private tasks;
3607
- private notifiedTaskIds;
3608
- private listeners;
3609
- private nextId;
3610
- create(name: string, runner: (task: AgentTask) => Promise<string>, cancel: () => void, options?: CreateTaskOptions): AgentTask;
3611
- get(id: string): AgentTask | undefined;
3612
- list(): AgentTask[];
3613
- subscribe(listener: (tasks: AgentTask[]) => void): () => void;
3614
- private emitChange;
3615
- hasRunning(): boolean;
3616
- stop(id: string): boolean;
3617
- stopAndWait(id: string): Promise<boolean>;
3618
- stopAll(): Promise<void>;
3619
- waitAll(): Promise<void>;
3620
- drainNotifications(): AgentTask[];
3621
- clear(): void;
3622
- }
3623
- declare function formatAgentTaskNotification(task: AgentTask): string;
3624
3727
 
3625
- type taskManager_AgentTask = AgentTask;
3626
- type taskManager_AgentTaskStatus = AgentTaskStatus;
3627
- type taskManager_TaskManager = TaskManager;
3628
- declare const taskManager_TaskManager: typeof TaskManager;
3629
- declare const taskManager_formatAgentTaskNotification: typeof formatAgentTaskNotification;
3630
- declare namespace taskManager {
3631
- export { type taskManager_AgentTask as AgentTask, type taskManager_AgentTaskStatus as AgentTaskStatus, taskManager_TaskManager as TaskManager, taskManager_formatAgentTaskNotification as formatAgentTaskNotification };
3632
- }
3633
-
3634
- /**
3635
- * Copyright (c) 2026 hangtiancheng
3636
- *
3637
- * Permission is hereby granted, free of charge, to any person obtaining a copy
3638
- * of this software and associated documentation files (the "Software"), to deal
3639
- * in the Software without restriction, including without limitation the rights
3640
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3641
- * copies of the Software, and to permit persons to whom the Software is
3642
- * furnished to do so, subject to the following conditions:
3643
- *
3644
- * The above copyright notice and this permission notice shall be included in
3645
- * all copies or substantial portions of the Software.
3646
- *
3647
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3648
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3649
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3650
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3651
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3652
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3653
- * SOFTWARE.
3654
- */
3655
-
3656
- /** Abort a running teammate or one-shot background Agent task. */
3728
+ /** Abort a running teammate or one-shot background Agent/Bash/PowerShell/JavaScript task. */
3657
3729
  declare class TaskStopTool implements Tool {
3658
3730
  private teamManager;
3659
3731
  private taskManager?;
@@ -3662,7 +3734,7 @@ declare class TaskStopTool implements Tool {
3662
3734
  category: ToolCategory;
3663
3735
  constructor(teamManager: TeamManager, taskManager?: TaskManager | undefined);
3664
3736
  schema(): ToolSchema;
3665
- execute(_ctx: ToolContext, args: Record<string, unknown>): Promise<ToolResult>;
3737
+ execute(ctx: ToolContext, args: Record<string, unknown>): Promise<ToolResult>;
3666
3738
  /** List all current teammate names for the model, so it doesn't keep retrying with a misremembered name */
3667
3739
  private knownMembers;
3668
3740
  }
@@ -3997,6 +4069,8 @@ declare class Team {
3997
4069
  * Returns the concatenated prompt or a shutdown flag.
3998
4070
  */
3999
4071
  private waitForNextPromptOrShutdown;
4072
+ /** Reads the teammate's plan file for review; returns a fallback note when empty or unreadable. */
4073
+ private readPlanForReview;
4000
4074
  /**
4001
4075
  * Sends the teammate's completed plan to the Lead, blocks until approval is received,
4002
4076
  * and returns the prompt to feed the model on the next turn.
@@ -4007,7 +4081,6 @@ declare class Team {
4007
4081
  * drive progress from the Lead side. Returns null when the teammate has been
4008
4082
  * deactivated; the caller should exit the main loop.
4009
4083
  */
4010
- private readPlanForReview;
4011
4084
  private runPlanApproval;
4012
4085
  getMember(name: string): Member | undefined;
4013
4086
  sendMessage(from: string, to: string, content: string): Promise<void>;
@@ -5074,7 +5147,7 @@ declare function closeLogger(): void;
5074
5147
  /**
5075
5148
  * Global logger export. Modules can import and use it at file top level:
5076
5149
  * ```ts
5077
- * import { logger } from "@/logger/logger.js";
5150
+ * import { logger } from "@/logger/index.js";
5078
5151
  * logger.warn({ module: "app" }, "something looks off");
5079
5152
  * ```
5080
5153
  * Before initLogger(), calls fall back to the silent target (pre-init logs
@@ -5676,7 +5749,7 @@ declare namespace instructions {
5676
5749
  */
5677
5750
  /**
5678
5751
  Memory freshness calculation and expiration reminders. Appends a prompt text
5679
- to memories older than 1 day, instructing the model that the memory may be
5752
+ to memories at least 2 days old, instructing the model that the memory may be
5680
5753
  stale and should be verified before use.
5681
5754
  */
5682
5755
  declare function memoryAgeDays(mtimeMs: number): number;
@@ -6251,7 +6324,6 @@ interface CreateRemoteAgentOptions {
6251
6324
  /**
6252
6325
  * Initializes the full agent stack: tools, LLM client, conversation, session,
6253
6326
  * skills, hooks, MCP servers, team management, and memory.
6254
- * Replicates ALL logic from server-old.ts initAgent() + initMCPServers().
6255
6327
  */
6256
6328
  declare function createRemoteAgent(opts: CreateRemoteAgentOptions): Promise<RemoteAgentHandle>;
6257
6329
  interface RemoteServerOptions {
@@ -6691,8 +6763,9 @@ declare const CUSTOM_AGENT_DISALLOWED_TOOLS: Set<AllTools>;
6691
6763
  declare const ASYNC_AGENT_ALLOWED_TOOLS: Set<AllTools>;
6692
6764
  /**
6693
6765
  * Multi-layer tool filtering, applied in order:
6694
- * 1. MCP tools (mcp__*) — Always allowed
6695
- * 2. ALL_AGENT_DISALLOWED_TOOLS — Globally disallowed (prevents recursion)
6766
+ * 1. MCP tools (mcp__*) — exempt from layers 2-4, but still subject to
6767
+ * definition-level disallowedTools/tools (layers 5-6)
6768
+ * 2. SUBAGENT_DISALLOWED_TOOLS — Globally disallowed (prevents recursion)
6696
6769
  * 3. CUSTOM_AGENT_DISALLOWED_TOOLS — Additional restrictions for custom Agents
6697
6770
  * 4. ASYNC_AGENT_ALLOWED_TOOLS — Whitelist for background Agents
6698
6771
  * 5. Definition-level disallowedTools — Blacklist
@@ -6763,8 +6836,16 @@ declare namespace index$6 {
6763
6836
  */
6764
6837
 
6765
6838
  declare const TOOL_RESULT_PREVIEW_CHARS = 2000;
6839
+ declare function spillDir(workDir: string, sessionId: string): string;
6766
6840
  declare function toDisplayPreview(content: string): string;
6767
6841
  declare function replaceToolResultContent(result: ToolResultBlock, content: string): void;
6842
+ /**
6843
+ * The `<persisted-output>` wrapper text. buildSpillPreview derives the inputs
6844
+ * from an in-memory string; tool-level producers (e.g. a backgrounded Bash
6845
+ * command's live output file) build the same wrapper from a stat + partial
6846
+ * read without ever loading the full content into JS.
6847
+ */
6848
+ declare function buildPersistedOutputPreview(totalChars: number, preview: string, spillPath: string): string;
6768
6849
  /**
6769
6850
  * Determine whether a tool call is reading back a file under the spill
6770
6851
  * directory. Such results are not spilled: writing the model's freshly-read
@@ -6790,19 +6871,22 @@ declare function isSpillReadback(toolName: string, args: Record<string, unknown>
6790
6871
  declare function applyBudget(toolResults: ToolResultBlock[], workDir: string, sessionId: string, exemptIds?: Set<string>): void;
6791
6872
  /**
6792
6873
  * Spill an oversized tool output to disk and return the preview text. On
6793
- * write failure the content is returned unchanged. Called from agent.ts when
6794
- * tool results enter the conversation history, in place of direct truncation.
6874
+ * write failure the content is returned unchanged. Called from agent/index.ts
6875
+ * (and tools/javascript.ts) when tool results enter the conversation history,
6876
+ * in place of direct truncation.
6795
6877
  */
6796
6878
  declare function persistLargeResult(workDir: string, sessionId: string, toolUseId: string, content: string): string;
6797
6879
 
6798
6880
  declare const index$5_TOOL_RESULT_PREVIEW_CHARS: typeof TOOL_RESULT_PREVIEW_CHARS;
6799
6881
  declare const index$5_applyBudget: typeof applyBudget;
6882
+ declare const index$5_buildPersistedOutputPreview: typeof buildPersistedOutputPreview;
6800
6883
  declare const index$5_isSpillReadback: typeof isSpillReadback;
6801
6884
  declare const index$5_persistLargeResult: typeof persistLargeResult;
6802
6885
  declare const index$5_replaceToolResultContent: typeof replaceToolResultContent;
6886
+ declare const index$5_spillDir: typeof spillDir;
6803
6887
  declare const index$5_toDisplayPreview: typeof toDisplayPreview;
6804
6888
  declare namespace index$5 {
6805
- export { index$5_TOOL_RESULT_PREVIEW_CHARS as TOOL_RESULT_PREVIEW_CHARS, index$5_applyBudget as applyBudget, index$5_isSpillReadback as isSpillReadback, index$5_persistLargeResult as persistLargeResult, index$5_replaceToolResultContent as replaceToolResultContent, index$5_toDisplayPreview as toDisplayPreview };
6889
+ export { index$5_TOOL_RESULT_PREVIEW_CHARS as TOOL_RESULT_PREVIEW_CHARS, index$5_applyBudget as applyBudget, index$5_buildPersistedOutputPreview as buildPersistedOutputPreview, index$5_isSpillReadback as isSpillReadback, index$5_persistLargeResult as persistLargeResult, index$5_replaceToolResultContent as replaceToolResultContent, index$5_spillDir as spillDir, index$5_toDisplayPreview as toDisplayPreview };
6806
6890
  }
6807
6891
 
6808
6892
  /**
@@ -6834,6 +6918,18 @@ declare class BashTool implements Tool {
6834
6918
  sandbox: Sandbox | null;
6835
6919
  sandboxRequired: boolean;
6836
6920
  sandboxConfig: SandboxConfig;
6921
+ /**
6922
+ * Background task registry, injected by the host (TUI / print mode / remote
6923
+ * server) — the same instance the Agent tool uses, so completion
6924
+ * notifications share one drain and TaskStop covers both. When null, Bash is
6925
+ * foreground-only: run_in_background disappears from the schema, timeouts
6926
+ * kill, and Ctrl+B is a no-op. Calls running inside a subagent loop carry
6927
+ * that loop's own manager in ctx.taskManager, which takes precedence.
6928
+ */
6929
+ taskManager: TaskManager | null;
6930
+ /** Running foreground executions eligible for manual backgrounding (Ctrl+B). */
6931
+ private foreground;
6932
+ private nextForegroundId;
6837
6933
  /**
6838
6934
  * Read-only commands can run concurrently with other read-only tools;
6839
6935
  * mutating commands must run exclusively.
@@ -6845,8 +6941,30 @@ declare class BashTool implements Tool {
6845
6941
  * pipes, command chaining, and command substitution are already excluded.
6846
6942
  */
6847
6943
  isConcurrencySafe(args: Record<string, unknown>): boolean;
6944
+ /**
6945
+ * The background subsystem needs a task manager and can be disabled
6946
+ * wholesale with SWIFTY_DISABLE_BACKGROUND_TASKS=1 (schema parameter
6947
+ * removed, timeouts kill, Ctrl+B becomes a no-op). Instance-level gate used
6948
+ * by the schema; execute() re-checks with the ctx-resolved manager.
6949
+ */
6950
+ backgroundEnabled(): boolean;
6951
+ /** True while at least one foreground Bash command runs (gates the Ctrl+B handler). */
6952
+ hasForegroundTasks(): boolean;
6953
+ /**
6954
+ * Move every running foreground Bash command to the background (Ctrl+B).
6955
+ * Returns how many commands were actually backgrounded.
6956
+ */
6957
+ backgroundForegroundTasks(): number;
6848
6958
  schema(): ToolSchema;
6849
6959
  execute(ctx: ToolContext, args: Record<string, unknown>): Promise<ToolResult>;
6960
+ /**
6961
+ * Spawn the command with stdout+stderr writing directly into the output
6962
+ * file (ccb's file-descriptor mode): output never flows through JS, so
6963
+ * backgrounding is a bookkeeping switch — no re-spawn, no buffer handover.
6964
+ * The returned handle exposes the tool-call promise plus a background()
6965
+ * trigger that transitions the running command into a TaskManager task.
6966
+ */
6967
+ private startCommand;
6850
6968
  }
6851
6969
 
6852
6970
  type bash_BashTool = BashTool;
@@ -6969,8 +7087,28 @@ declare namespace computerUse {
6969
7087
  * SOFTWARE.
6970
7088
  */
6971
7089
  declare const BASH_DESCRIPTION = "Execute command in Bash; return stdout and stderr. Prefer PowerShell on Windows.\n- timeout is in seconds: default 120, maximum 600. Each call starts a fresh, independent shell in the Agent's working directory; cd, variables, functions, and options do not persist.\n- Quote paths with spaces. To change directory, use cd \"path\" && command in the same call. Separate independent commands; chain dependent commands with &&, not ;.\n- Prefer dedicated file/search tools over cat, head, tail, sed, awk, echo, or find. Scope searches to a directory, never the filesystem root. Diagnose failures rather than retrying in sleep loops.\nGit: commit or push only when requested. Destructive operations (push --force, reset --hard, checkout ., clean -f, branch -D), amending, or skipping hooks/signing require explicit authorization; never bypass permission/hook denials. Prefer new commits. When committing, include Co-Authored-By: Swifty <usr161043261@outlook.com>.";
7090
+ /**
7091
+ * Appended to the Bash schema description only when background execution is
7092
+ * available (a TaskManager is wired and not disabled via env), so the
7093
+ * run_in_background parameter and its guidance never advertise a capability
7094
+ * the current host cannot deliver.
7095
+ */
7096
+ declare const BASH_BACKGROUND_DESCRIPTION = "- Set run_in_background to true to run the command in the background. The call returns a task ID immediately and the result arrives later as a task notification; do not poll or sleep waiting for it. Use this for long-running commands you do not need the result of right away. Use TaskStop with the task_id to kill a background command early. A foreground command that exceeds its timeout is moved to the background automatically instead of being killed, unless it is a bare sleep.";
6972
7097
  declare const POWERSHELL_DESCRIPTION = "Execute command in PowerShell; return stdout and stderr. Recommended on Windows (powershell.exe); uses pwsh elsewhere.\n- timeout is in seconds: default 120, maximum 600. Each call starts a fresh, independent shell in the Agent's working directory; location, variables, and options do not persist.\n- Quote paths with spaces; use Set-Location -LiteralPath \"path\" in the same call. Separate independent commands. For dependencies, check $LASTEXITCODE for native commands and use -ErrorAction Stop for cmdlets; ; does not stop on failure. Do not assume PowerShell 7 syntax.\n- Prefer dedicated file/search tools over Get-Content, Select-String, or Write-Output. Scope recursion to a directory, not a drive root. Diagnose failures rather than retrying in Start-Sleep loops.\nGit: commit or push only when requested. Destructive operations (push --force, reset --hard, checkout ., clean -f, branch -D), amending, or skipping hooks/signing require explicit authorization; never bypass permission/hook denials. Prefer new commits. When committing, include Co-Authored-By: Swifty <usr161043261@outlook.com>.";
7098
+ /**
7099
+ * Appended to the PowerShell schema description only when background execution
7100
+ * is available; mirrors BASH_BACKGROUND_DESCRIPTION with PS-flavored wording.
7101
+ */
7102
+ declare const POWERSHELL_BACKGROUND_DESCRIPTION = "- Set run_in_background to true to run the command in the background. The call returns a task ID immediately and the result arrives later as a task notification; do not poll or Start-Sleep waiting for it. Use this for long-running commands you do not need the result of right away. Use TaskStop with the task_id to kill a background command early. A foreground command that exceeds its timeout is moved to the background automatically instead of being killed, unless it is a bare Start-Sleep.";
6973
7103
  declare const JAVASCRIPT_DESCRIPTION = "Execute JavaScript in a fresh isolated V8 context for pure computation.\n- Provide a function body and use return to produce a JSON-compatible result. Optional input is available as globalThis.input.\n- No filesystem, network, process, require, imports, timers, or host callbacks are available. Use Bash for Node.js or system operations.\n- timeout_ms defaults to 1000 (max 10000); memory_limit_mb defaults to 64 (max 256). Requires Node.js 24 or newer.";
7104
+ /**
7105
+ * Appended to the JavaScript schema description only when background execution
7106
+ * is available. No timeout auto-background here: timeout_ms is the isolate's
7107
+ * hard safety cap — V8 kills a synchronous script at the cap, and a wall-clock
7108
+ * deadline disposes the isolate when an evaluation is suspended on a promise —
7109
+ * so there is nothing left to keep running.
7110
+ */
7111
+ declare const JAVASCRIPT_BACKGROUND_DESCRIPTION = "- Set run_in_background to true to evaluate in the background. The call returns a task ID immediately and the result arrives later as a task notification; do not poll. timeout_ms still caps the evaluation (max 10000). Use TaskStop with the task_id to abort it early.";
6974
7112
  declare const READ_FILE_DESCRIPTION = "Read text with 1-based display line numbers, or images (png, jpg, jpeg, gif, webp) as visual content; not directories.\n- file_path is absolute or relative to the Agent's working directory. offset skips lines (0-based, default 0); limit defaults to 2000 lines, with a 50KB text output cap. Displayed line 101 starts at offset=100. Follow continuation/readback instructions for partial output.\n- Images ignore offset/limit. A successful read refreshes the file-state cache used by EditFile/WriteFile; re-read after an external-change error.";
6975
7113
  declare const EDIT_FILE_DESCRIPTION = "Replace exact text in an existing file and return a diff. Prefer this over whole-file rewrites.\n- file_path is absolute or relative to the Agent's working directory. ReadFile is required first; stale file-state errors require a fresh read and revised edit.\n- old_string must be non-empty and unique unless replace_all=true (default false). Use enough context to disambiguate; preserve whitespace and exclude display line numbers.\n- new_string must differ from old_string; an empty string deletes the match.";
6976
7114
  declare const WRITE_FILE_DESCRIPTION = "Write complete UTF-8 content to file_path, creating parent directories and overwriting existing content. Use for new files or complete rewrites; prefer EditFile for targeted changes.\n- file_path is absolute or relative to the Agent's working directory. Existing files require ReadFile first; re-read if the cached state is stale.\n- content includes any desired trailing newline; an empty string creates or truncates an empty file. Avoid unrelated files or unsolicited documentation.";
@@ -6978,17 +7116,20 @@ declare const GLOB_DESCRIPTION = "Find files by glob pattern (e.g. \"**/*.ts\",
6978
7116
  declare const GREP_DESCRIPTION = "Search file content with a case-insensitive, line-by-line JavaScript-style regex pattern; return file:line:content with 1-based lines and working-directory-relative paths.\n- path is a file or directory, absolute or relative to the Agent's working directory (default \".\"). Escape regex backslashes in JSON. No multiline matching or general PCRE support.\n- include is an optional glob: \"*.ts\" matches names at any depth; patterns with \"/\" match working-directory-relative paths. A direct file path is searched without this filter.\n- Traversal includes dotfiles but skips fixed directories such as .git, .agents, .swifty, node_modules, dist, and __pycache__, not .gitignore rules. Binary/unreadable files are skipped; directory symlinks are not traversed.\n- At most 500 matching lines. Narrow searches; never search the filesystem root. Use ReadFile for context and this tool instead of shell grep/rg.";
6979
7117
  declare const WEB_FETCH_DESCRIPTION = "Fetch a URL over HTTP(S) and return its content as Markdown. Use it to retrieve and analyze web pages.\n- url must be a fully-formed http or https URL; redirects are followed automatically and the final URL is reported when it differs.\n- HTML is converted to Markdown; other text formats (plain text, JSON, XML, Markdown) are returned as-is. Binary content (images, PDFs, archives) is rejected.\n- Responses over 10MB are rejected and results are truncated at 100K characters. Successful fetches are cached for 15 minutes.";
6980
7118
 
7119
+ declare const descriptions_BASH_BACKGROUND_DESCRIPTION: typeof BASH_BACKGROUND_DESCRIPTION;
6981
7120
  declare const descriptions_BASH_DESCRIPTION: typeof BASH_DESCRIPTION;
6982
7121
  declare const descriptions_EDIT_FILE_DESCRIPTION: typeof EDIT_FILE_DESCRIPTION;
6983
7122
  declare const descriptions_GLOB_DESCRIPTION: typeof GLOB_DESCRIPTION;
6984
7123
  declare const descriptions_GREP_DESCRIPTION: typeof GREP_DESCRIPTION;
7124
+ declare const descriptions_JAVASCRIPT_BACKGROUND_DESCRIPTION: typeof JAVASCRIPT_BACKGROUND_DESCRIPTION;
6985
7125
  declare const descriptions_JAVASCRIPT_DESCRIPTION: typeof JAVASCRIPT_DESCRIPTION;
7126
+ declare const descriptions_POWERSHELL_BACKGROUND_DESCRIPTION: typeof POWERSHELL_BACKGROUND_DESCRIPTION;
6986
7127
  declare const descriptions_POWERSHELL_DESCRIPTION: typeof POWERSHELL_DESCRIPTION;
6987
7128
  declare const descriptions_READ_FILE_DESCRIPTION: typeof READ_FILE_DESCRIPTION;
6988
7129
  declare const descriptions_WEB_FETCH_DESCRIPTION: typeof WEB_FETCH_DESCRIPTION;
6989
7130
  declare const descriptions_WRITE_FILE_DESCRIPTION: typeof WRITE_FILE_DESCRIPTION;
6990
7131
  declare namespace descriptions {
6991
- export { descriptions_BASH_DESCRIPTION as BASH_DESCRIPTION, descriptions_EDIT_FILE_DESCRIPTION as EDIT_FILE_DESCRIPTION, descriptions_GLOB_DESCRIPTION as GLOB_DESCRIPTION, descriptions_GREP_DESCRIPTION as GREP_DESCRIPTION, descriptions_JAVASCRIPT_DESCRIPTION as JAVASCRIPT_DESCRIPTION, descriptions_POWERSHELL_DESCRIPTION as POWERSHELL_DESCRIPTION, descriptions_READ_FILE_DESCRIPTION as READ_FILE_DESCRIPTION, descriptions_WEB_FETCH_DESCRIPTION as WEB_FETCH_DESCRIPTION, descriptions_WRITE_FILE_DESCRIPTION as WRITE_FILE_DESCRIPTION };
7132
+ export { descriptions_BASH_BACKGROUND_DESCRIPTION as BASH_BACKGROUND_DESCRIPTION, descriptions_BASH_DESCRIPTION as BASH_DESCRIPTION, descriptions_EDIT_FILE_DESCRIPTION as EDIT_FILE_DESCRIPTION, descriptions_GLOB_DESCRIPTION as GLOB_DESCRIPTION, descriptions_GREP_DESCRIPTION as GREP_DESCRIPTION, descriptions_JAVASCRIPT_BACKGROUND_DESCRIPTION as JAVASCRIPT_BACKGROUND_DESCRIPTION, descriptions_JAVASCRIPT_DESCRIPTION as JAVASCRIPT_DESCRIPTION, descriptions_POWERSHELL_BACKGROUND_DESCRIPTION as POWERSHELL_BACKGROUND_DESCRIPTION, descriptions_POWERSHELL_DESCRIPTION as POWERSHELL_DESCRIPTION, descriptions_READ_FILE_DESCRIPTION as READ_FILE_DESCRIPTION, descriptions_WEB_FETCH_DESCRIPTION as WEB_FETCH_DESCRIPTION, descriptions_WRITE_FILE_DESCRIPTION as WRITE_FILE_DESCRIPTION };
6992
7133
  }
6993
7134
 
6994
7135
  /**
@@ -7107,6 +7248,47 @@ declare namespace enterWorktree {
7107
7248
  export { enterWorktree_EnterWorktreeTool as EnterWorktreeTool };
7108
7249
  }
7109
7250
 
7251
+ /**
7252
+ * Copyright (c) 2026 hangtiancheng
7253
+ *
7254
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7255
+ * of this software and associated documentation files (the "Software"), to deal
7256
+ * in the Software without restriction, including without limitation the rights
7257
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7258
+ * copies of the Software, and to permit persons to whom the Software is
7259
+ * furnished to do so, subject to the following conditions:
7260
+ *
7261
+ * The above copyright notice and this permission notice shall be included in
7262
+ * all copies or substantial portions of the Software.
7263
+ *
7264
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
7265
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
7266
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
7267
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
7268
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
7269
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
7270
+ * SOFTWARE.
7271
+ */
7272
+ /**
7273
+ * Extract the base command name from a command string.
7274
+ * For piped commands, take the last segment: bash and PowerShell both surface
7275
+ * the exit code of the last command in a pipeline.
7276
+ */
7277
+ declare function extractBaseCmd(command: string): string;
7278
+ /**
7279
+ * Return a semantic hint for a non-zero exit code, helping the LLM understand
7280
+ * what the code means. Command-specific hints win over generic ones; POSIX
7281
+ * 128+n signal exits get a fallback description. Returns empty string when
7282
+ * nothing is recognized.
7283
+ */
7284
+ declare function exitCodeHint(command: string, exitCode: number): string;
7285
+
7286
+ declare const exitCodeHints_exitCodeHint: typeof exitCodeHint;
7287
+ declare const exitCodeHints_extractBaseCmd: typeof extractBaseCmd;
7288
+ declare namespace exitCodeHints {
7289
+ export { exitCodeHints_exitCodeHint as exitCodeHint, exitCodeHints_extractBaseCmd as extractBaseCmd };
7290
+ }
7291
+
7110
7292
  /**
7111
7293
  * Copyright (c) 2026 hangtiancheng
7112
7294
  *
@@ -7331,8 +7513,35 @@ declare class JavaScriptTool implements Tool {
7331
7513
  name: string;
7332
7514
  description: string;
7333
7515
  category: ToolCategory;
7516
+ /**
7517
+ * Background task registry, injected by the host — same contract as
7518
+ * BashTool.taskManager. Unlike the shell tools there is no timeout
7519
+ * auto-background: timeout_ms is the isolate's hard safety cap — V8 kills a
7520
+ * synchronous script at the cap, and a wall-clock deadline disposes the
7521
+ * isolate when an evaluation is suspended on a promise — so nothing is left
7522
+ * to keep running.
7523
+ */
7524
+ taskManager: TaskManager | null;
7525
+ /** Running foreground evaluations eligible for manual backgrounding (Ctrl+B). */
7526
+ private foreground;
7527
+ private nextForegroundId;
7528
+ /** Instance-level background gate; see BashTool.backgroundEnabled. */
7529
+ backgroundEnabled(): boolean;
7530
+ /** True while at least one foreground evaluation runs. */
7531
+ hasForegroundTasks(): boolean;
7532
+ /** Move every running foreground evaluation to the background (Ctrl+B). */
7533
+ backgroundForegroundTasks(): number;
7334
7534
  schema(): ToolSchema;
7335
7535
  execute(ctx: ToolContext, args: Record<string, unknown>): Promise<ToolResult>;
7536
+ /**
7537
+ * Start the isolated evaluation. The returned handle mirrors the shell
7538
+ * tools: background() transitions the pending evaluation into a TaskManager
7539
+ * task — the isolate keeps running on its own thread, the tool call
7540
+ * resolves immediately, and completion arrives as a task notification.
7541
+ * While foreground, the caller's abort signal (Esc) disposes the isolate;
7542
+ * once backgrounded, only TaskStop or session shutdown can abort it.
7543
+ */
7544
+ private startEvaluation;
7336
7545
  }
7337
7546
 
7338
7547
  type javascript_JavaScriptEvaluation = JavaScriptEvaluation;
@@ -7367,13 +7576,16 @@ declare namespace javascript {
7367
7576
  * SOFTWARE.
7368
7577
  */
7369
7578
  /**
7370
- * Unified call entry point for MCP tools.
7579
+ * Unified call entry point for MCP tools (dispatch mode only — see
7580
+ * mcp/strategy.ts for the eager/native modes, where MCP tools ship in tools[]
7581
+ * directly or stay there flagged with defer_loading).
7371
7582
  *
7372
- * MCP tools never enter tools[]. The model first reads the schema via ToolSearch,
7373
- * then passes the tool name and arguments through McpCall. This keeps the tools
7374
- * array byte-identical throughout the whole session, so the prompt cache prefix is
7375
- * never broken — tools render after system and before messages, so any change to
7376
- * the array forces the entire trailing history to be recomputed.
7583
+ * In dispatch mode MCP tools never enter tools[]. The model first reads the
7584
+ * schema via ToolSearch, then passes the tool name and arguments through
7585
+ * McpCall. This keeps the tools array byte-identical throughout the whole
7586
+ * session, so the prompt cache prefix is never broken — tools render after
7587
+ * system and before messages, so any change to the array forces the entire
7588
+ * trailing history to be recomputed.
7377
7589
  *
7378
7590
  * The trade-off is that arguments are generated freely by the model with no schema
7379
7591
  * constraint at the interface level, so the JSON type is occasionally wrong.
@@ -7458,8 +7670,30 @@ declare class PowerShellTool implements Tool {
7458
7670
  name: string;
7459
7671
  description: string;
7460
7672
  category: ToolCategory;
7673
+ /**
7674
+ * Background task registry, injected by the host — same contract as
7675
+ * BashTool.taskManager (schema gating, timeout auto-background, Ctrl+B).
7676
+ * Calls running inside a subagent loop carry that loop's own manager in
7677
+ * ctx.taskManager, which takes precedence.
7678
+ */
7679
+ taskManager: TaskManager | null;
7680
+ /** Running foreground executions eligible for manual backgrounding (Ctrl+B). */
7681
+ private foreground;
7682
+ private nextForegroundId;
7683
+ /** Instance-level background gate; see BashTool.backgroundEnabled. */
7684
+ backgroundEnabled(): boolean;
7685
+ /** True while at least one foreground PowerShell command runs. */
7686
+ hasForegroundTasks(): boolean;
7687
+ /** Move every running foreground command to the background (Ctrl+B). */
7688
+ backgroundForegroundTasks(): number;
7461
7689
  schema(): ToolSchema;
7462
7690
  execute(ctx: ToolContext, args: Record<string, unknown>): Promise<ToolResult>;
7691
+ /**
7692
+ * Spawn PowerShell with stdout+stderr writing directly into the output file
7693
+ * (fd mode, shared with BashTool): output never flows through JS, so
7694
+ * backgrounding is a bookkeeping switch — no re-spawn, no buffer handover.
7695
+ */
7696
+ private startCommand;
7463
7697
  }
7464
7698
 
7465
7699
  type powershell_PowerShellTool = PowerShellTool;
@@ -7505,6 +7739,138 @@ declare namespace readFile {
7505
7739
  export { readFile_ReadFileTool as ReadFileTool };
7506
7740
  }
7507
7741
 
7742
+ /** Notification body budget: larger outputs stay on disk and only a preview travels in the notification. */
7743
+ declare const BACKGROUND_NOTIFICATION_CHARS = 30000;
7744
+ /**
7745
+ * ccb parity: a backgrounded command may fill up to 5GB before the size
7746
+ * watchdog kills it (their incident: a stuck append loop wrote 768GB with no
7747
+ * JS in the write path to notice). Foreground keeps the historical 10MB cap.
7748
+ */
7749
+ declare const BACKGROUND_MAX_OUTPUT_BYTES: number;
7750
+ declare const SIZE_WATCHDOG_INTERVAL_MS = 500;
7751
+ /** Why a command moved to the background. */
7752
+ type BackgroundReason = "explicit" | "user" | "timeout";
7753
+ /** Terminal facts about the child process, consumed to build results and notifications. */
7754
+ interface ShellExit {
7755
+ code: number | null;
7756
+ signal: NodeJS.Signals | null;
7757
+ aborted: boolean;
7758
+ timedOut: boolean;
7759
+ sizeKilled: boolean;
7760
+ spawnError?: string;
7761
+ }
7762
+ interface CommandHandle {
7763
+ /** Resolves the tool call: either the inline completion or an early "moved to background" message. */
7764
+ result: Promise<ToolResult>;
7765
+ /**
7766
+ * Move the running command to the background. Returns the background task ID,
7767
+ * or null when the command already finished or backgrounding is unavailable.
7768
+ */
7769
+ background: (reason: BackgroundReason) => string | null;
7770
+ }
7771
+ /**
7772
+ * Whether a command may be *automatically* backgrounded on timeout. Bare
7773
+ * sleeps are killed instead: backgrounding one would just hold a task slot
7774
+ * until session end. Explicit run_in_background and manual Ctrl+B are always
7775
+ * honored regardless of this gate. Only the first token is considered:
7776
+ * `sleep 60` should die on timeout, but `npm run build && sleep 1` is a real
7777
+ * workload worth keeping alive.
7778
+ */
7779
+ declare function isAutobackgroundingAllowed(command: string, disallowed: ReadonlySet<string>): boolean;
7780
+ declare function backgroundTaskName(command: string): string;
7781
+ declare function backgroundMessage(reason: BackgroundReason, taskId: string, timeout: number): string;
7782
+ /** Slice buf to at most maxBytes, ending on a UTF-8 character boundary. */
7783
+ declare function sliceUtf8Safe(buf: Buffer, maxBytes: number): Buffer;
7784
+ /** Read at most maxBytes of the output file; missing files read as empty. */
7785
+ declare function readOutputFile(path: string, maxBytes: number): {
7786
+ text: string;
7787
+ size: number;
7788
+ truncated: boolean;
7789
+ };
7790
+ declare function unlinkQuiet(path: string): void;
7791
+ declare function discardFd(fd: number): void;
7792
+ declare function openOutputFd(path: string): number;
7793
+ /**
7794
+ * Create the file that receives a command's stdout+stderr. Lives in the
7795
+ * session tool-results directory (the established spill location, readable by
7796
+ * the model for backgrounded commands); falls back to the OS temp dir when
7797
+ * that directory cannot be created.
7798
+ */
7799
+ declare function createShellOutputFile(workDir: string, sessionId: string): {
7800
+ path: string;
7801
+ fd: number;
7802
+ };
7803
+ /**
7804
+ * Build the foreground tool result from exit facts and the captured output.
7805
+ * Shared verbatim by the inline foreground path and the background task
7806
+ * notification body, so both report identically. `prompt` is the tool's shell
7807
+ * marker ("$ " for Bash, "PS> " for PowerShell).
7808
+ */
7809
+ declare function formatFinalResult(prompt: string, command: string, exit: ShellExit, merged: string, truncated: boolean, timeout: number): ToolResult;
7810
+ /**
7811
+ * Build the notification body for a finished background command from the
7812
+ * output file. Small outputs are inlined and the file is deleted; large
7813
+ * outputs keep the file on disk and the notification carries its path with a
7814
+ * 2000-char preview, so the full text stays readable via ReadFile without ever
7815
+ * loading it into JS here. `annotate` is the sandbox's stderr annotator
7816
+ * (sandbox-runtime violation notes); the foreground path applies it in
7817
+ * settleExit, and background notifications must report identically.
7818
+ */
7819
+ declare function buildBackgroundBody(prompt: string, command: string, exit: ShellExit, outputPath: string, timeout: number, annotate?: (text: string) => string): ToolResult;
7820
+ /** The subset of a tool instance the host wiring below needs. */
7821
+ interface BackgroundableTool {
7822
+ taskManager: TaskManager | null;
7823
+ backgroundEnabled(): boolean;
7824
+ hasForegroundTasks(): boolean;
7825
+ backgroundForegroundTasks(): number;
7826
+ }
7827
+ /** Tools that support background execution, in Ctrl+B priority order. */
7828
+ declare const BACKGROUNDABLE_TOOL_NAMES: readonly ["Bash", "PowerShell", "JavaScript"];
7829
+ /**
7830
+ * Share one background task registry across every backgroundable tool in the
7831
+ * registry, so run_in_background, Ctrl+B and timeout auto-background deliver
7832
+ * results through the same task-notification drain as background agents.
7833
+ */
7834
+ declare function attachBackgroundTaskManager(registry: ToolRegistry, manager: TaskManager): void;
7835
+ /**
7836
+ * Whether any backgroundable tool has a running foreground task. Gates the
7837
+ * Ctrl+B handler: the keypress must stay inert when nothing is running, so
7838
+ * other components that also bind Ctrl+B (e.g. the provider-login form's
7839
+ * cursor-back) don't double-fire.
7840
+ */
7841
+ declare function hasAnyForegroundTasks(registry: ToolRegistry): boolean;
7842
+ /**
7843
+ * Move every running foreground task of every backgroundable tool to the
7844
+ * background (the Ctrl+B action). Returns how many were backgrounded.
7845
+ */
7846
+ declare function backgroundAllForegroundTasks(registry: ToolRegistry): number;
7847
+
7848
+ declare const shellBackground_BACKGROUNDABLE_TOOL_NAMES: typeof BACKGROUNDABLE_TOOL_NAMES;
7849
+ declare const shellBackground_BACKGROUND_MAX_OUTPUT_BYTES: typeof BACKGROUND_MAX_OUTPUT_BYTES;
7850
+ declare const shellBackground_BACKGROUND_NOTIFICATION_CHARS: typeof BACKGROUND_NOTIFICATION_CHARS;
7851
+ type shellBackground_BackgroundReason = BackgroundReason;
7852
+ type shellBackground_BackgroundableTool = BackgroundableTool;
7853
+ type shellBackground_CommandHandle = CommandHandle;
7854
+ declare const shellBackground_SIZE_WATCHDOG_INTERVAL_MS: typeof SIZE_WATCHDOG_INTERVAL_MS;
7855
+ type shellBackground_ShellExit = ShellExit;
7856
+ declare const shellBackground_attachBackgroundTaskManager: typeof attachBackgroundTaskManager;
7857
+ declare const shellBackground_backgroundAllForegroundTasks: typeof backgroundAllForegroundTasks;
7858
+ declare const shellBackground_backgroundMessage: typeof backgroundMessage;
7859
+ declare const shellBackground_backgroundTaskName: typeof backgroundTaskName;
7860
+ declare const shellBackground_buildBackgroundBody: typeof buildBackgroundBody;
7861
+ declare const shellBackground_createShellOutputFile: typeof createShellOutputFile;
7862
+ declare const shellBackground_discardFd: typeof discardFd;
7863
+ declare const shellBackground_formatFinalResult: typeof formatFinalResult;
7864
+ declare const shellBackground_hasAnyForegroundTasks: typeof hasAnyForegroundTasks;
7865
+ declare const shellBackground_isAutobackgroundingAllowed: typeof isAutobackgroundingAllowed;
7866
+ declare const shellBackground_openOutputFd: typeof openOutputFd;
7867
+ declare const shellBackground_readOutputFile: typeof readOutputFile;
7868
+ declare const shellBackground_sliceUtf8Safe: typeof sliceUtf8Safe;
7869
+ declare const shellBackground_unlinkQuiet: typeof unlinkQuiet;
7870
+ declare namespace shellBackground {
7871
+ export { shellBackground_BACKGROUNDABLE_TOOL_NAMES as BACKGROUNDABLE_TOOL_NAMES, shellBackground_BACKGROUND_MAX_OUTPUT_BYTES as BACKGROUND_MAX_OUTPUT_BYTES, shellBackground_BACKGROUND_NOTIFICATION_CHARS as BACKGROUND_NOTIFICATION_CHARS, type shellBackground_BackgroundReason as BackgroundReason, type shellBackground_BackgroundableTool as BackgroundableTool, type shellBackground_CommandHandle as CommandHandle, shellBackground_SIZE_WATCHDOG_INTERVAL_MS as SIZE_WATCHDOG_INTERVAL_MS, type shellBackground_ShellExit as ShellExit, shellBackground_attachBackgroundTaskManager as attachBackgroundTaskManager, shellBackground_backgroundAllForegroundTasks as backgroundAllForegroundTasks, shellBackground_backgroundMessage as backgroundMessage, shellBackground_backgroundTaskName as backgroundTaskName, shellBackground_buildBackgroundBody as buildBackgroundBody, shellBackground_createShellOutputFile as createShellOutputFile, shellBackground_discardFd as discardFd, shellBackground_formatFinalResult as formatFinalResult, shellBackground_hasAnyForegroundTasks as hasAnyForegroundTasks, shellBackground_isAutobackgroundingAllowed as isAutobackgroundingAllowed, shellBackground_openOutputFd as openOutputFd, shellBackground_readOutputFile as readOutputFile, shellBackground_sliceUtf8Safe as sliceUtf8Safe, shellBackground_unlinkQuiet as unlinkQuiet };
7872
+ }
7873
+
7508
7874
  /**
7509
7875
  * Copyright (c) 2026 hangtiancheng
7510
7876
  *
@@ -7662,6 +8028,42 @@ declare namespace toolSearch {
7662
8028
  export { toolSearch_ToolSearchTool as ToolSearchTool };
7663
8029
  }
7664
8030
 
8031
+ /**
8032
+ * Copyright (c) 2026 hangtiancheng
8033
+ *
8034
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8035
+ * of this software and associated documentation files (the "Software"), to deal
8036
+ * in the Software without restriction, including without limitation the rights
8037
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8038
+ * copies of the Software, and to permit persons to whom the Software is
8039
+ * furnished to do so, subject to the following conditions:
8040
+ *
8041
+ * The above copyright notice and this permission notice shall be included in
8042
+ * all copies or substantial portions of the Software.
8043
+ *
8044
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
8045
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
8046
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
8047
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
8048
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
8049
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
8050
+ * SOFTWARE.
8051
+ */
8052
+
8053
+ declare class WebFetchTool implements Tool {
8054
+ name: string;
8055
+ description: string;
8056
+ category: ToolCategory;
8057
+ schema(): ToolSchema;
8058
+ execute(ctx: ToolContext, args: Record<string, unknown>): Promise<ToolResult>;
8059
+ }
8060
+
8061
+ type webFetch_WebFetchTool = WebFetchTool;
8062
+ declare const webFetch_WebFetchTool: typeof WebFetchTool;
8063
+ declare namespace webFetch {
8064
+ export { webFetch_WebFetchTool as WebFetchTool };
8065
+ }
8066
+
7665
8067
  /**
7666
8068
  * Copyright (c) 2026 hangtiancheng
7667
8069
  *
@@ -7721,7 +8123,7 @@ declare namespace writeFile {
7721
8123
  */
7722
8124
 
7723
8125
  declare namespace index$4 {
7724
- export { askUser as AskUser, bash as Bash, computerUse as ComputerUse, descriptions as Descriptions, diff as Diff, editFile as EditFile, enterWorktree as EnterWorktree, exitPlanMode as ExitPlanMode, exitWorktree as ExitWorktree, fileMutationQueue as FileMutationQueue, fileStateCache as FileStateCache, glob as Glob, grep as Grep, isDiffTool$1 as IsDiffTool, javascript as JavaScript, mcpCall as McpCall, powershell as PowerShell, readFile as ReadFile, registry$1 as Registry, shellOutput as ShellOutput, snippets as Snippets, syntheticOutput as SyntheticOutput, toolSearch as ToolSearch, types as Types, writeFile as WriteFile };
8126
+ export { askUser as AskUser, bash as Bash, computerUse as ComputerUse, descriptions as Descriptions, diff as Diff, editFile as EditFile, enterWorktree as EnterWorktree, exitCodeHints as ExitCodeHints, exitPlanMode as ExitPlanMode, exitWorktree as ExitWorktree, fileMutationQueue as FileMutationQueue, fileStateCache as FileStateCache, glob as Glob, grep as Grep, isDiffTool$1 as IsDiffTool, javascript as JavaScript, mcpCall as McpCall, powershell as PowerShell, readFile as ReadFile, registry$1 as Registry, shellBackground as ShellBackground, shellOutput as ShellOutput, snippets as Snippets, syntheticOutput as SyntheticOutput, toolSearch as ToolSearch, types as Types, webFetch as WebFetchTool, writeFile as WriteFile };
7725
8127
  }
7726
8128
 
7727
8129
  /**