@oh-my-pi/pi-coding-agent 16.2.1 → 16.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/CHANGELOG.md +72 -0
  2. package/dist/cli.js +3621 -3579
  3. package/dist/types/advisor/__tests__/config.test.d.ts +1 -0
  4. package/dist/types/advisor/advise-tool.d.ts +8 -4
  5. package/dist/types/advisor/config.d.ts +88 -0
  6. package/dist/types/advisor/index.d.ts +1 -0
  7. package/dist/types/advisor/runtime.d.ts +15 -1
  8. package/dist/types/advisor/transcript-recorder.d.ts +13 -2
  9. package/dist/types/advisor/watchdog.d.ts +20 -0
  10. package/dist/types/collab/guest.d.ts +29 -0
  11. package/dist/types/config/model-roles.d.ts +1 -1
  12. package/dist/types/config/settings-schema.d.ts +113 -12
  13. package/dist/types/debug/log-viewer.d.ts +1 -0
  14. package/dist/types/debug/raw-sse.d.ts +1 -0
  15. package/dist/types/discovery/omp-extension-roots.d.ts +3 -3
  16. package/dist/types/edit/hashline/diff.d.ts +0 -11
  17. package/dist/types/edit/index.d.ts +18 -0
  18. package/dist/types/edit/streaming.d.ts +30 -0
  19. package/dist/types/extensibility/custom-tools/types.d.ts +1 -0
  20. package/dist/types/extensibility/shared-events.d.ts +1 -0
  21. package/dist/types/extensibility/tool-event-input.d.ts +7 -0
  22. package/dist/types/extensibility/utils.d.ts +12 -0
  23. package/dist/types/mcp/oauth-discovery.d.ts +0 -11
  24. package/dist/types/mcp/transports/index.d.ts +1 -0
  25. package/dist/types/mcp/transports/sse.d.ts +20 -0
  26. package/dist/types/modes/components/advisor-config.d.ts +59 -0
  27. package/dist/types/modes/components/index.d.ts +1 -0
  28. package/dist/types/modes/components/model-selector.d.ts +9 -1
  29. package/dist/types/modes/components/settings-selector.d.ts +1 -0
  30. package/dist/types/modes/components/status-line/component.d.ts +30 -3
  31. package/dist/types/modes/components/status-line/types.d.ts +13 -1
  32. package/dist/types/modes/controllers/selector-controller.d.ts +1 -0
  33. package/dist/types/modes/interactive-mode.d.ts +10 -4
  34. package/dist/types/modes/skill-command.d.ts +32 -0
  35. package/dist/types/modes/types.d.ts +7 -2
  36. package/dist/types/sdk.d.ts +1 -1
  37. package/dist/types/session/agent-session.d.ts +84 -12
  38. package/dist/types/session/indexed-session-storage.d.ts +7 -1
  39. package/dist/types/session/messages.d.ts +32 -7
  40. package/dist/types/session/messages.test.d.ts +1 -0
  41. package/dist/types/session/session-entries.d.ts +31 -3
  42. package/dist/types/session/session-history-format.d.ts +6 -0
  43. package/dist/types/session/session-loader.d.ts +9 -1
  44. package/dist/types/session/session-manager.d.ts +6 -4
  45. package/dist/types/session/session-storage.d.ts +11 -0
  46. package/dist/types/session/session-title-slot.d.ts +19 -0
  47. package/dist/types/session/settings-stream-fn.d.ts +21 -0
  48. package/dist/types/session/turn-persistence.d.ts +88 -0
  49. package/dist/types/ssh/connection-manager.d.ts +47 -0
  50. package/dist/types/ssh/utils.d.ts +16 -0
  51. package/dist/types/task/executor.d.ts +3 -16
  52. package/dist/types/task/render.d.ts +0 -5
  53. package/dist/types/task/renderer.d.ts +13 -0
  54. package/dist/types/task/types.d.ts +16 -0
  55. package/dist/types/task/yield-assembly.d.ts +28 -0
  56. package/dist/types/tiny/text.d.ts +8 -0
  57. package/dist/types/tools/render-utils.d.ts +2 -0
  58. package/dist/types/tools/review.d.ts +6 -4
  59. package/dist/types/tools/ssh.d.ts +1 -1
  60. package/dist/types/tools/todo.d.ts +6 -0
  61. package/dist/types/tools/yield.d.ts +8 -3
  62. package/dist/types/utils/thinking-display.d.ts +4 -0
  63. package/package.json +12 -12
  64. package/src/advisor/__tests__/advisor.test.ts +438 -10
  65. package/src/advisor/__tests__/config.test.ts +173 -0
  66. package/src/advisor/advise-tool.ts +11 -6
  67. package/src/advisor/config.ts +256 -0
  68. package/src/advisor/index.ts +1 -0
  69. package/src/advisor/runtime.ts +77 -4
  70. package/src/advisor/transcript-recorder.ts +25 -2
  71. package/src/advisor/watchdog.ts +57 -31
  72. package/src/auto-thinking/classifier.ts +2 -2
  73. package/src/autoresearch/index.ts +7 -2
  74. package/src/cli/gc-cli.ts +17 -10
  75. package/src/collab/guest.ts +43 -7
  76. package/src/config/model-registry.ts +80 -18
  77. package/src/config/model-resolver.ts +5 -1
  78. package/src/config/model-roles.ts +3 -3
  79. package/src/config/settings-schema.ts +107 -8
  80. package/src/debug/index.ts +32 -7
  81. package/src/debug/log-viewer.ts +111 -53
  82. package/src/debug/raw-sse.ts +68 -48
  83. package/src/discovery/codex.ts +13 -5
  84. package/src/discovery/omp-extension-roots.ts +38 -13
  85. package/src/edit/hashline/diff.ts +57 -4
  86. package/src/edit/index.ts +21 -0
  87. package/src/edit/streaming.ts +170 -0
  88. package/src/eval/js/shared/local-module-loader.ts +23 -1
  89. package/src/export/html/template.js +13 -7
  90. package/src/extensibility/custom-tools/types.ts +1 -0
  91. package/src/extensibility/extensions/loader.ts +5 -3
  92. package/src/extensibility/extensions/wrapper.ts +9 -3
  93. package/src/extensibility/hooks/loader.ts +3 -3
  94. package/src/extensibility/hooks/tool-wrapper.ts +13 -4
  95. package/src/extensibility/plugins/legacy-pi-bundled-keys.ts +18 -1
  96. package/src/extensibility/plugins/legacy-pi-bundled-registry.ts +59 -2
  97. package/src/extensibility/plugins/manager.ts +76 -5
  98. package/src/extensibility/shared-events.ts +1 -0
  99. package/src/extensibility/tool-event-input.ts +23 -0
  100. package/src/extensibility/utils.ts +74 -0
  101. package/src/internal-urls/docs-index.generated.txt +1 -1
  102. package/src/mcp/client.ts +3 -1
  103. package/src/mcp/manager.ts +12 -5
  104. package/src/mcp/oauth-discovery.ts +5 -29
  105. package/src/mcp/transports/http.ts +3 -1
  106. package/src/mcp/transports/index.ts +1 -0
  107. package/src/mcp/transports/sse.ts +377 -0
  108. package/src/memories/index.ts +15 -6
  109. package/src/mnemopi/backend.ts +2 -2
  110. package/src/modes/acp/acp-agent.ts +1 -1
  111. package/src/modes/components/advisor-config.ts +555 -0
  112. package/src/modes/components/advisor-message.ts +9 -2
  113. package/src/modes/components/agent-hub.ts +9 -4
  114. package/src/modes/components/assistant-message.ts +5 -5
  115. package/src/modes/components/index.ts +2 -0
  116. package/src/modes/components/model-selector.ts +79 -48
  117. package/src/modes/components/settings-selector.ts +1 -0
  118. package/src/modes/components/status-line/component.ts +145 -14
  119. package/src/modes/components/status-line/segments.ts +47 -22
  120. package/src/modes/components/status-line/types.ts +13 -1
  121. package/src/modes/components/tool-execution.ts +47 -6
  122. package/src/modes/controllers/command-controller.ts +23 -2
  123. package/src/modes/controllers/event-controller.ts +114 -11
  124. package/src/modes/controllers/extension-ui-controller.ts +1 -1
  125. package/src/modes/controllers/input-controller.ts +61 -61
  126. package/src/modes/controllers/selector-controller.ts +100 -9
  127. package/src/modes/interactive-mode.ts +65 -10
  128. package/src/modes/print-mode.ts +1 -1
  129. package/src/modes/skill-command.ts +116 -0
  130. package/src/modes/types.ts +7 -2
  131. package/src/modes/utils/transcript-render-helpers.ts +2 -2
  132. package/src/modes/utils/ui-helpers.ts +46 -27
  133. package/src/prompts/agents/reviewer.md +11 -10
  134. package/src/prompts/review-custom-request.md +1 -2
  135. package/src/prompts/review-request.md +1 -2
  136. package/src/prompts/system/interrupted-thinking.md +7 -0
  137. package/src/prompts/system/recap-user.md +9 -0
  138. package/src/prompts/system/subagent-system-prompt.md +8 -5
  139. package/src/prompts/system/subagent-yield-reminder.md +6 -5
  140. package/src/prompts/system/system-prompt.md +0 -1
  141. package/src/prompts/tools/irc.md +2 -2
  142. package/src/prompts/tools/read.md +2 -2
  143. package/src/sdk.ts +40 -50
  144. package/src/session/agent-session.ts +1139 -600
  145. package/src/session/indexed-session-storage.ts +86 -13
  146. package/src/session/messages.test.ts +125 -0
  147. package/src/session/messages.ts +192 -21
  148. package/src/session/redis-session-storage.ts +49 -2
  149. package/src/session/session-entries.ts +39 -2
  150. package/src/session/session-history-format.ts +29 -2
  151. package/src/session/session-listing.ts +54 -24
  152. package/src/session/session-loader.ts +66 -3
  153. package/src/session/session-manager.ts +113 -19
  154. package/src/session/session-persistence.ts +96 -3
  155. package/src/session/session-storage.ts +36 -0
  156. package/src/session/session-title-slot.ts +141 -0
  157. package/src/session/settings-stream-fn.ts +49 -0
  158. package/src/session/sql-session-storage.ts +71 -11
  159. package/src/session/turn-persistence.ts +142 -0
  160. package/src/session/unexpected-stop-classifier.ts +2 -2
  161. package/src/slash-commands/builtin-registry.ts +16 -3
  162. package/src/slash-commands/helpers/mcp.ts +2 -1
  163. package/src/ssh/__tests__/connection-manager-args.test.ts +123 -1
  164. package/src/ssh/__tests__/file-transfer-posix-guard.test.ts +55 -18
  165. package/src/ssh/connection-manager.ts +139 -12
  166. package/src/ssh/file-transfer.ts +23 -18
  167. package/src/ssh/ssh-executor.ts +2 -13
  168. package/src/ssh/utils.ts +19 -0
  169. package/src/task/executor.ts +21 -23
  170. package/src/task/render.ts +162 -20
  171. package/src/task/renderer.ts +14 -0
  172. package/src/task/types.ts +17 -0
  173. package/src/task/yield-assembly.ts +207 -0
  174. package/src/tiny/models.ts +8 -6
  175. package/src/tiny/text.ts +37 -7
  176. package/src/tools/ask.ts +55 -4
  177. package/src/tools/image-gen.ts +2 -1
  178. package/src/tools/render-utils.ts +2 -0
  179. package/src/tools/renderers.ts +8 -2
  180. package/src/tools/review.ts +17 -7
  181. package/src/tools/ssh.ts +8 -4
  182. package/src/tools/todo.ts +17 -1
  183. package/src/tools/tts.ts +2 -1
  184. package/src/tools/yield.ts +140 -31
  185. package/src/utils/thinking-display.ts +15 -0
  186. package/src/utils/title-generator.ts +1 -1
  187. package/src/web/search/providers/tavily.ts +36 -19
@@ -0,0 +1,7 @@
1
+ <system-notice type="interrupted-thinking">
2
+ Your previous turn was interrupted while you were thinking.
3
+ - You MUST treat the preserved reasoning as internal continuity context.
4
+ - You MUST continue the user's task from the relevant unfinished point.
5
+ ------
6
+ {{reasoning}}
7
+ </system-notice>
@@ -0,0 +1,9 @@
1
+ <recap>
2
+ The user stepped away and is coming back. Recap in under 40 words, 1-2 plain sentences, no markdown. Lead with the overall goal and current task, then the one next action. Skip root-cause narrative, fix internals, secondary to-dos, and em-dash tangents.
3
+ {{#if goal}}
4
+ Overall goal: {{goal}}
5
+ {{/if}}
6
+ {{#if task}}
7
+ Active task: {{task}}
8
+ {{/if}}
9
+ </recap>
@@ -50,13 +50,16 @@ Use `irc` only for quick coordination, never long-form content. Address peers by
50
50
  COMPLETION
51
51
  ===================================
52
52
 
53
- No TODO tracking, no progress updates. Execute, call `yield`, done.
53
+ No TODO tracking, no progress updates. Execute; report results with `yield`.
54
54
 
55
- While work remains, you MUST continue with another tool call — investigate, edit, run, verify. Save narrative for the final `yield` payload.
55
+ While work remains, you MUST continue with another tool call — investigate, edit, run, verify. Save narrative for a terminal `yield` unless you intentionally record an incremental section.
56
56
 
57
- When finished, you MUST call `yield` exactly once. This is like writing to a ticket: provide what is required and close it.
57
+ Yield protocol:
58
+ - Omit `type` for the normal single terminal structured result in `result.data`.
59
+ - Use non-empty `type: string[]` for incremental, non-terminal sections; calls accumulate by section.
60
+ - Use `type: string` for a terminal result; if data is omitted, your last assistant turn becomes the raw final result.
58
61
 
59
- This is your only way to return a result. You NEVER put JSON in plain text, and you NEVER substitute a text summary for the structured `result.data` parameter.
62
+ This is your only way to return a final result. For structured results, you NEVER put JSON in plain text or substitute a text summary for `result.data`.
60
63
 
61
64
  {{#if outputSchema}}
62
65
  Your result MUST match this TypeScript interface:
@@ -65,7 +68,7 @@ Your result MUST match this TypeScript interface:
65
68
  ```
66
69
  {{/if}}
67
70
 
68
- Giving up is a last resort. If truly blocked, you MUST call `yield` exactly once with `result.error` describing what you tried and the exact blocker.
71
+ Giving up is a last resort. If truly blocked, you MUST terminal-yield `result.error` describing what you tried and the exact blocker.
69
72
  You NEVER give up due to uncertainty, missing information obtainable via tools or repo context, or needing a design decision you can derive yourself.
70
73
 
71
74
  You MUST keep going until this ticket is closed. This matters.
@@ -1,12 +1,13 @@
1
1
  <system-reminder>
2
2
  Your last turn ended without a tool call, so the session went idle. This is reminder {{retryCount}} of {{maxRetries}}.
3
3
 
4
- Every turn MUST end with a tool call. Pick exactly one of:
5
- 1. **Resume the work** — if the assignment is not finished, call the next tool you would have called (edit, write, bash, search, etc.). NEVER yield. NEVER treat this reminder as a forced stop.
6
- 2. **Yield with success** — only if the assignment is genuinely complete: call `yield` with the structured payload in `result.data`.
7
- 3. **Yield with error** — only if you hit a real, concrete blocker you can name (missing file, unavailable API, contradictory spec). Describe what you tried and the exact blocker. NEVER fabricate a "forced immediate-yield" or "system reminder required termination" reason this reminder is not a blocker.
4
+ Every turn MUST end with a tool call. Pick the first that applies:
5
+ 1. **Resume the work** — if the assignment is not finished and you are not recording an incremental section, call the next tool you would have called (edit, write, bash, search, etc.). NEVER treat this reminder as a forced stop.
6
+ 2. **Yield an incremental section** — only when useful for the assignment: call `yield` with non-empty `type: string[]`; matching sections accumulate and the task continues.
7
+ 3. **Yield with success** — only if the assignment is genuinely complete: call terminal `yield`. Omit `type` for the single final structured result in `result.data`; use `type: string` to finalize from the last assistant turn when data is omitted.
8
+ 4. **Yield with error** — only if you hit a real, concrete blocker you can name (missing file, unavailable API, contradictory spec). Describe what you tried and the exact blocker. NEVER fabricate a "forced immediate-yield" or "system reminder required termination" reason — this reminder is not a blocker.
8
9
 
9
- Default to option 1 unless the work is actually done or actually blocked.
10
+ Default to option 1 unless the work is actually done, actually blocked, or ready for an incremental section.
10
11
 
11
12
  You NEVER end this turn with text only.
12
13
  </system-reminder>
@@ -58,7 +58,6 @@ Special URLs for internal resources; with most FS/bash tools they auto-resolve t
58
58
  {{/if}}
59
59
  - `agent://<id>`: agent output artifact; `/<path>` extracts a JSON field
60
60
  - `artifact://<id>`: artifact content
61
- - `history://<agentId>`: agent transcript (markdown); bare `history://` lists agents
62
61
  - `local://<name>.md`: plan artifacts or shared content for subagents
63
62
  {{#if hasObsidian}}
64
63
  - `vault://<vault>/<path>`: Obsidian vault (read/edit). `vault://` lists vaults; `vault://_/…` targets the active vault. File ops `?op=outline|backlinks|links|tags|properties|tasks|base|…`; vault ops `?op=search&q=…|daily|tasks|orphans|unresolved|bases|…`.
@@ -7,7 +7,7 @@ Send/receive short text messages between agents in this process.
7
7
  - Messaging an `idle`/`parked` peer wakes it — no separate revive call.
8
8
  - `op: "wait"` — block for a message (optionally only `from` one peer); consumes + returns it. Timeout = clean "no message", not an error.
9
9
  - `op: "inbox"` — drain pending messages without blocking.
10
- - Replies arrive only when the recipient sends one. For peer background, `read` `history://<id>`, don't interrogate.
10
+ - Replies arrive only when the recipient sends one; don't interrogate a peer for status.
11
11
  </instruction>
12
12
 
13
13
  <when_to_use>
@@ -24,7 +24,7 @@ NEVER for: routine progress updates, things a tool call can verify, questions yo
24
24
  Applies to sending + replying.
25
25
  - **Plain prose only.** NEVER JSON status payloads like `{"type":"task_completed",…}` — write a normal sentence.
26
26
  - **NEVER quote the message you answer.** Lead with the answer; set `replyTo`.
27
- - **Learn about peers via IRC** — NEVER grep artifacts, read other sessions' JSONL, or shell-poke. DM them, or `read` `history://<id>`.
27
+ - **Learn about peers via IRC** — NEVER grep artifacts, read other sessions' JSONL, or shell-poke. DM them.
28
28
  - **Send, then keep working.** `wait`/`await: true` only when you cannot proceed. NEVER "did you get my message?". A `failed` receipt = peer unreachable — move on; NEVER retry in a loop.
29
29
  - **Answer expected questions** via `irc send` to the sender (finish your current step first).
30
30
  - **Stay terse.** One question per send; share files via `local://`/`memory://`/`artifact://` URLs, never pasted blobs.
@@ -7,7 +7,7 @@ Read files, directories, archives, SQLite, images, documents, internal resources
7
7
 
8
8
  ## Parameters
9
9
 
10
- - `path` — required. Local path, internal URI (`skill://`, `agent://`, `artifact://`, `history://`, `memory://`, `rule://`, `local://`, `vault://`, `mcp://`, `omp://`, `issue://`, `pr://`, `ssh://`), or URL. Append `:<sel>` for ranges/modes (e.g. `src/foo.ts:50-200`, `src/foo.ts:raw`, `db.sqlite:users:42`).
10
+ - `path` — required. Local path, internal URI (`skill://`, `agent://`, `artifact://`, `memory://`, `rule://`, `local://`, `vault://`, `mcp://`, `omp://`, `issue://`, `pr://`, `ssh://`), or URL. Append `:<sel>` for ranges/modes (e.g. `src/foo.ts:50-200`, `src/foo.ts:raw`, `db.sqlite:users:42`).
11
11
 
12
12
  ## Selectors
13
13
 
@@ -67,7 +67,7 @@ For `.sqlite`, `.sqlite3`, `.db`, `.db3`:
67
67
 
68
68
  # Internal URIs
69
69
 
70
- All URI schemes take the same line selectors. `artifact://<id>` recovers full output a bash/eval/tool result spilled or truncated. `history://<agentId>` = agent transcript; bare `history://` lists agents.
70
+ All URI schemes take the same line selectors. `artifact://<id>` recovers full output a bash/eval/tool result spilled or truncated.
71
71
 
72
72
  `ssh://host/<absolute-path>` reads a remote text file (UTF-8, ≤1 MiB) or lists a directory one level deep, on a pre-configured SSH host or `~/.ssh/config` alias; `ssh://host/` lists the remote root and bare `ssh://` lists the configured hosts. Files are also writable via `write` and searchable via `search`; a directory only lists (`search` refuses a directory, `write` refuses to overwrite one). A literal `:`, `?`, or `#` in the remote path must be percent-encoded (`%3A`/`%3F`/`%23`) — a trailing `:sel` is read as a line selector, and `?`/`#` start a URL query/fragment. Requires a POSIX login shell (`sh`/`bash`/`zsh`); a Windows host or a non-POSIX shell (fish, csh/tcsh) is rejected — use the `ssh` tool there.
73
73
 
package/src/sdk.ts CHANGED
@@ -8,14 +8,7 @@ import {
8
8
  filterProviderReplayMessages,
9
9
  type ThinkingLevel,
10
10
  } from "@oh-my-pi/pi-agent-core";
11
- import {
12
- type Context,
13
- type CredentialDisabledEvent,
14
- type Message,
15
- type Model,
16
- type SimpleStreamOptions,
17
- streamSimple,
18
- } from "@oh-my-pi/pi-ai";
11
+ import type { Context, CredentialDisabledEvent, Message, Model, SimpleStreamOptions } from "@oh-my-pi/pi-ai";
19
12
  import type { Dialect } from "@oh-my-pi/pi-ai/dialect";
20
13
  import {
21
14
  getOpenAICodexTransportDetails,
@@ -26,7 +19,7 @@ import type { Component } from "@oh-my-pi/pi-tui";
26
19
  import { $env, $flag, getAgentDir, getProjectDir, logger, postmortem, prompt, Snowflake } from "@oh-my-pi/pi-utils";
27
20
  import { INTENT_FIELD } from "@oh-my-pi/pi-wire";
28
21
  import {
29
- ADVISOR_READONLY_TOOL_NAMES,
22
+ discoverAdvisorConfigs,
30
23
  discoverWatchdogFiles,
31
24
  formatActiveRepoWatchdogPrompt,
32
25
  formatAdvisorContextPrompt,
@@ -49,7 +42,7 @@ import {
49
42
  resolveModelRoleValue,
50
43
  } from "./config/model-resolver";
51
44
  import { loadPromptTemplates as loadPromptTemplatesInternal, type PromptTemplate } from "./config/prompt-templates";
52
- import { Settings, type SkillsSettings, validateProviderMaxInFlightRequests } from "./config/settings";
45
+ import { Settings, type SkillsSettings } from "./config/settings";
53
46
  import { CursorExecHandlers } from "./cursor";
54
47
  import "./discovery";
55
48
  import { initializeWithSettings } from "./discovery";
@@ -125,6 +118,7 @@ import {
125
118
  import { clampProviderContextImages } from "./session/provider-image-budget";
126
119
  import { getRestorableSessionModels } from "./session/session-context";
127
120
  import { SessionManager } from "./session/session-manager";
121
+ import { createSettingsAwareStreamFn } from "./session/settings-stream-fn";
128
122
  import { SnapcompactInlineTransformer } from "./session/snapcompact-inline";
129
123
  import { createSnapcompactSavingsRecorder } from "./session/snapcompact-savings-journal";
130
124
  import { closeAllConnections } from "./ssh/connection-manager";
@@ -975,6 +969,7 @@ function createCustomToolsExtension(tools: CustomTool[]): ExtensionFactory {
975
969
  maxAttempts: event.maxAttempts,
976
970
  delayMs: event.delayMs,
977
971
  errorMessage: event.errorMessage,
972
+ errorId: event.errorId,
978
973
  },
979
974
  ctx,
980
975
  ),
@@ -1163,6 +1158,8 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
1163
1158
  activeRepoContextPromise.catch(() => {});
1164
1159
  const watchdogFilesPromise = logger.time("discoverWatchdogFiles", () => discoverWatchdogFiles(cwd, agentDir));
1165
1160
  watchdogFilesPromise.catch(() => {});
1161
+ const advisorConfigsPromise = logger.time("discoverAdvisorConfigs", () => discoverAdvisorConfigs(cwd, agentDir));
1162
+ advisorConfigsPromise.catch(() => {});
1166
1163
  const promptTemplatesPromise = options.promptTemplates
1167
1164
  ? Promise.resolve(options.promptTemplates)
1168
1165
  : logger.time("discoverPromptTemplates", discoverPromptTemplates, cwd, agentDir);
@@ -1408,12 +1405,14 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
1408
1405
  }
1409
1406
  return result;
1410
1407
  };
1411
- const [contextFiles, resolvedWorkspaceTree, watchdogFiles, activeRepoContext] = await Promise.all([
1412
- contextFilesPromise,
1413
- raceWithDeadline("buildWorkspaceTree", workspaceTreePromise),
1414
- watchdogFilesPromise,
1415
- activeRepoContextPromise,
1416
- ]);
1408
+ const [contextFiles, resolvedWorkspaceTree, watchdogFiles, activeRepoContext, discoveredAdvisors] =
1409
+ await Promise.all([
1410
+ contextFilesPromise,
1411
+ raceWithDeadline("buildWorkspaceTree", workspaceTreePromise),
1412
+ watchdogFilesPromise,
1413
+ activeRepoContextPromise,
1414
+ advisorConfigsPromise,
1415
+ ]);
1417
1416
 
1418
1417
  let agent: Agent;
1419
1418
  let session!: AgentSession;
@@ -2536,6 +2535,11 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
2536
2535
  // One-shot launch-latency marker: fired the first time the loop dispatches
2537
2536
  // a chat request to the provider transport. See onFirstChatDispatch.
2538
2537
  let notifyFirstChatDispatch = options.onFirstChatDispatch;
2538
+ // Shared, settings-aware stream wrapper used by both the main agent and
2539
+ // the advisor (via AgentSessionConfig.streamFn). Keeps OpenRouter
2540
+ // sticky-routing variants, antigravity endpoint routing, in-flight caps,
2541
+ // and the loop guard consistent across every agent the session drives.
2542
+ const settingsAwareStreamFn = createSettingsAwareStreamFn(settings);
2539
2543
  agent = new Agent({
2540
2544
  initialState: {
2541
2545
  systemPrompt,
@@ -2586,23 +2590,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
2586
2590
  });
2587
2591
  }
2588
2592
  }
2589
- const openrouterRoutingPreset = settings.get("providers.openrouterVariant");
2590
- const openrouterVariant =
2591
- openrouterRoutingPreset && openrouterRoutingPreset !== "default" ? openrouterRoutingPreset : undefined;
2592
- const antigravityEndpointMode = settings.get("providers.antigravityEndpoint");
2593
- return streamSimple(streamModel, context, {
2594
- ...streamOptions,
2595
- openrouterVariant: streamOptions?.openrouterVariant ?? openrouterVariant,
2596
- antigravityEndpointMode: streamOptions?.antigravityEndpointMode ?? antigravityEndpointMode,
2597
- maxInFlightRequests: validateProviderMaxInFlightRequests(
2598
- streamOptions?.maxInFlightRequests ?? settings.get("providers.maxInFlightRequests"),
2599
- ),
2600
- loopGuard: {
2601
- enabled: settings.get("model.loopGuard.enabled"),
2602
- checkAssistantContent: settings.get("model.loopGuard.checkAssistantContent"),
2603
- ...streamOptions?.loopGuard,
2604
- },
2605
- });
2593
+ return settingsAwareStreamFn(streamModel, context, streamOptions);
2606
2594
  },
2607
2595
  cursorExecHandlers,
2608
2596
  transformToolCallArguments: (args, _toolName) => {
@@ -2649,34 +2637,32 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
2649
2637
  }
2650
2638
  }
2651
2639
 
2652
- // Hard-isolated read-only toolset for the advisor (built unconditionally so
2653
- // it can be toggled at runtime). Fresh ReadTool/GrepTool/GlobTool bound to a
2654
- // DISTINCT ToolSession so the advisor's investigative reads never touch the
2655
- // primary's snapshot, seen-lines, conflict, or summary caches (all keyed on
2656
- // session identity). `cwd` stays dynamic; edit/yield capabilities are off.
2640
+ // Full toolset for the advisor, built unconditionally so it can be toggled at
2641
+ // runtime. Bound to a DISTINCT ToolSession (its own `-advisor` session id +
2642
+ // agent id) so the advisor's tool state snapshot, seen-lines, conflict, and
2643
+ // summary caches, all keyed on session identity stays isolated from the
2644
+ // primary, while edit/bash/write stay fully functional: the advisor is a full
2645
+ // agent and its config's `tools` selects which of these it actually gets
2646
+ // (defaulting to read/grep/glob).
2657
2647
  const advisorToolSession: ToolSession = {
2658
2648
  ...toolSession,
2659
2649
  get cwd() {
2660
2650
  return sessionManager.getCwd();
2661
2651
  },
2662
- hasEditTool: false,
2652
+ hasEditTool: true,
2663
2653
  requireYieldTool: false,
2664
- conflictHistory: undefined,
2665
- fileSnapshotStore: undefined,
2666
2654
  getSessionId: () => {
2667
2655
  const id = sessionManager.getSessionId?.();
2668
2656
  return id ? `${id}-advisor` : null;
2669
2657
  },
2670
2658
  getAgentId: () => "advisor",
2671
2659
  };
2672
- const built = await Promise.all(
2673
- [...ADVISOR_READONLY_TOOL_NAMES].map(name =>
2674
- BUILTIN_TOOLS[name as keyof typeof BUILTIN_TOOLS](advisorToolSession),
2675
- ),
2676
- );
2677
- const advisorReadOnlyTools: Tool[] = built
2678
- .filter((tool): tool is Tool => tool != null)
2679
- .map(wrapToolWithMetaNotice);
2660
+ const advisorToolBuilds: Array<Tool | null | Promise<Tool | null>> = [];
2661
+ for (const name in BUILTIN_TOOLS) {
2662
+ advisorToolBuilds.push(BUILTIN_TOOLS[name as keyof typeof BUILTIN_TOOLS](advisorToolSession));
2663
+ }
2664
+ const built = await Promise.all(advisorToolBuilds);
2665
+ const advisorTools: Tool[] = built.filter((tool): tool is Tool => tool != null).map(wrapToolWithMetaNotice);
2680
2666
 
2681
2667
  const advisorWatchdogPrompts = [...watchdogFiles];
2682
2668
  if (activeRepoContext) {
@@ -2693,6 +2679,8 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
2693
2679
  session = new AgentSession({
2694
2680
  advisorWatchdogPrompt,
2695
2681
  advisorContextPrompt,
2682
+ advisorSharedInstructions: discoveredAdvisors.sharedInstructions,
2683
+ advisorConfigs: discoveredAdvisors.advisors,
2696
2684
  agent,
2697
2685
  pruneToolDescriptions: inlineToolDescriptors,
2698
2686
  thinkingLevel: autoThinking ? AUTO_THINKING : effectiveThinkingLevel,
@@ -2718,8 +2706,10 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
2718
2706
  toolRegistry,
2719
2707
  builtInToolNames: builtInRegistryToolNames,
2720
2708
  transformContext,
2709
+ transformProviderContext,
2721
2710
  onPayload,
2722
2711
  onResponse,
2712
+ advisorStreamFn: settingsAwareStreamFn,
2723
2713
  convertToLlm: convertToLlmFinal,
2724
2714
  rebuildSystemPrompt,
2725
2715
  reloadSshTool,
@@ -2750,7 +2740,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
2750
2740
  agentKind,
2751
2741
  providerSessionId: options.providerSessionId,
2752
2742
  parentEvalSessionId: options.parentEvalSessionId,
2753
- advisorReadOnlyTools,
2743
+ advisorTools,
2754
2744
  });
2755
2745
  hasSession = true;
2756
2746
  if (asyncJobManager) {