mixdog 0.7.18 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (844) hide show
  1. package/README.md +37 -331
  2. package/package.json +67 -99
  3. package/scripts/boot-smoke.mjs +94 -0
  4. package/scripts/build-tui.mjs +52 -0
  5. package/scripts/compact-smoke.mjs +199 -0
  6. package/scripts/lead-workflow-smoke.mjs +598 -0
  7. package/scripts/live-worker-smoke.mjs +239 -0
  8. package/scripts/output-style-smoke.mjs +101 -0
  9. package/scripts/smoke-loop-report.mjs +221 -0
  10. package/scripts/smoke-loop.mjs +201 -0
  11. package/scripts/smoke.mjs +113 -0
  12. package/scripts/tool-failures.mjs +143 -0
  13. package/scripts/tool-smoke.mjs +456 -0
  14. package/src/agents/debugger/AGENT.md +3 -0
  15. package/src/agents/debugger/agent.json +6 -0
  16. package/src/agents/explore/AGENT.md +4 -0
  17. package/src/agents/explore/agent.json +6 -0
  18. package/src/agents/heavy-worker/AGENT.md +3 -0
  19. package/src/agents/heavy-worker/agent.json +6 -0
  20. package/src/agents/maintainer/AGENT.md +3 -0
  21. package/src/agents/maintainer/agent.json +6 -0
  22. package/src/agents/reviewer/AGENT.md +3 -0
  23. package/src/agents/reviewer/agent.json +6 -0
  24. package/src/agents/scheduler-task.md +3 -0
  25. package/src/agents/web-researcher/AGENT.md +3 -0
  26. package/src/agents/web-researcher/agent.json +6 -0
  27. package/src/agents/webhook-handler.md +3 -0
  28. package/src/agents/worker/AGENT.md +3 -0
  29. package/src/agents/worker/agent.json +6 -0
  30. package/src/app.mjs +90 -0
  31. package/src/cli.mjs +11 -0
  32. package/src/defaults/hidden-roles.json +72 -0
  33. package/src/defaults/mixdog-config.template.json +15 -0
  34. package/src/hooks/lib/permission-evaluator.cjs +488 -0
  35. package/src/hooks/lib/settings-loader.cjs +112 -0
  36. package/src/lib/keychain-cjs.cjs +332 -0
  37. package/src/lib/plugin-paths.cjs +28 -0
  38. package/src/lib/rules-builder.cjs +315 -0
  39. package/src/mixdog-session-runtime.mjs +3704 -0
  40. package/src/output-styles/default.md +38 -0
  41. package/src/output-styles/extreme-simple.md +17 -0
  42. package/src/output-styles/simple.md +17 -0
  43. package/src/repl.mjs +322 -0
  44. package/src/rules/bridge/00-common.md +5 -0
  45. package/src/rules/bridge/20-skip-protocol.md +11 -0
  46. package/src/rules/bridge/30-explorer.md +4 -0
  47. package/src/rules/bridge/40-cycle1-agent.md +28 -0
  48. package/src/rules/bridge/41-cycle2-agent.md +59 -0
  49. package/src/rules/lead/00-tool-lead.md +5 -0
  50. package/src/rules/lead/01-general.md +5 -0
  51. package/src/rules/lead/02-channels.md +3 -0
  52. package/src/rules/lead/04-workflow.md +12 -0
  53. package/src/rules/shared/00-language.md +3 -0
  54. package/src/rules/shared/01-tool.md +3 -0
  55. package/src/runtime/agent/orchestrator/bridge-trace.mjs +814 -0
  56. package/src/runtime/agent/orchestrator/cache-mtime.mjs +60 -0
  57. package/src/runtime/agent/orchestrator/config.mjs +446 -0
  58. package/src/runtime/agent/orchestrator/context/collect.mjs +796 -0
  59. package/src/runtime/agent/orchestrator/dispatch-persist.mjs +417 -0
  60. package/src/runtime/agent/orchestrator/internal-roles.mjs +188 -0
  61. package/src/runtime/agent/orchestrator/internal-tools.mjs +88 -0
  62. package/src/runtime/agent/orchestrator/mcp/client.mjs +345 -0
  63. package/src/runtime/agent/orchestrator/providers/anthropic-oauth.mjs +2104 -0
  64. package/src/runtime/agent/orchestrator/providers/anthropic.mjs +784 -0
  65. package/src/runtime/agent/orchestrator/providers/api-usage.mjs +341 -0
  66. package/src/runtime/agent/orchestrator/providers/gemini.mjs +1679 -0
  67. package/src/runtime/agent/orchestrator/providers/grok-oauth.mjs +959 -0
  68. package/src/runtime/agent/orchestrator/providers/media-normalization.mjs +213 -0
  69. package/src/runtime/agent/orchestrator/providers/model-cache.mjs +38 -0
  70. package/src/runtime/agent/orchestrator/providers/model-catalog.mjs +471 -0
  71. package/src/runtime/agent/orchestrator/providers/oauth-usage.mjs +615 -0
  72. package/src/runtime/agent/orchestrator/providers/openai-compat-stream.mjs +808 -0
  73. package/src/runtime/agent/orchestrator/providers/openai-compat.mjs +1719 -0
  74. package/src/runtime/agent/orchestrator/providers/openai-oauth-ws.mjs +2587 -0
  75. package/src/runtime/agent/orchestrator/providers/openai-oauth.mjs +1953 -0
  76. package/src/runtime/agent/orchestrator/providers/openai-ws.mjs +136 -0
  77. package/src/runtime/agent/orchestrator/providers/opencode-go-usage.mjs +317 -0
  78. package/src/runtime/agent/orchestrator/providers/opencode-go.mjs +109 -0
  79. package/src/runtime/agent/orchestrator/providers/registry.mjs +247 -0
  80. package/src/runtime/agent/orchestrator/providers/retry-classifier.mjs +332 -0
  81. package/src/runtime/agent/orchestrator/providers/statusline-route-meta.mjs +11 -0
  82. package/src/runtime/agent/orchestrator/providers/trace-utils.mjs +50 -0
  83. package/src/runtime/agent/orchestrator/session/cache/prefetch-cache.mjs +142 -0
  84. package/src/runtime/agent/orchestrator/session/cache/read-cache.mjs +318 -0
  85. package/src/runtime/agent/orchestrator/session/cache/scoped-cache.mjs +367 -0
  86. package/src/runtime/agent/orchestrator/session/compact.mjs +882 -0
  87. package/src/runtime/agent/orchestrator/session/context-utils.mjs +233 -0
  88. package/src/runtime/agent/orchestrator/session/loop.mjs +2320 -0
  89. package/src/runtime/agent/orchestrator/session/manager.mjs +2960 -0
  90. package/src/runtime/agent/orchestrator/session/result-classification.mjs +65 -0
  91. package/src/runtime/agent/orchestrator/session/store.mjs +663 -0
  92. package/src/runtime/agent/orchestrator/session/tool-result-offload.mjs +166 -0
  93. package/src/runtime/agent/orchestrator/smart-bridge/bridge-llm.mjs +339 -0
  94. package/src/runtime/agent/orchestrator/smart-bridge/cache-strategy.mjs +419 -0
  95. package/src/runtime/agent/orchestrator/stall-policy.mjs +227 -0
  96. package/src/runtime/agent/orchestrator/tool-loop-guard.mjs +235 -0
  97. package/src/runtime/agent/orchestrator/tools/bash-session.mjs +723 -0
  98. package/src/runtime/agent/orchestrator/tools/builtin/arg-guard.mjs +389 -0
  99. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool.mjs +637 -0
  100. package/src/runtime/agent/orchestrator/tools/builtin/builtin-tools.mjs +165 -0
  101. package/src/runtime/agent/orchestrator/tools/builtin/fuzzy-match.mjs +104 -0
  102. package/src/runtime/agent/orchestrator/tools/builtin/glob-walk.mjs +194 -0
  103. package/src/runtime/agent/orchestrator/tools/builtin/list-tool.mjs +596 -0
  104. package/src/runtime/agent/orchestrator/tools/builtin/native-edit-runner.mjs +110 -0
  105. package/src/runtime/agent/orchestrator/tools/builtin/path-diagnostics.mjs +153 -0
  106. package/src/runtime/agent/orchestrator/tools/builtin/read-formatting.mjs +118 -0
  107. package/src/runtime/agent/orchestrator/tools/builtin/read-open.mjs +189 -0
  108. package/src/runtime/agent/orchestrator/tools/builtin/read-single-tool.mjs +731 -0
  109. package/src/runtime/agent/orchestrator/tools/builtin/read-snapshot-runtime.mjs +168 -0
  110. package/src/runtime/agent/orchestrator/tools/builtin/read-streaming.mjs +602 -0
  111. package/src/runtime/agent/orchestrator/tools/builtin/rg-runner.mjs +465 -0
  112. package/src/runtime/agent/orchestrator/tools/builtin/search-builders.mjs +160 -0
  113. package/src/runtime/agent/orchestrator/tools/builtin/search-tool.mjs +982 -0
  114. package/src/runtime/agent/orchestrator/tools/builtin/shell-jobs.mjs +1087 -0
  115. package/src/runtime/agent/orchestrator/tools/builtin/shell-runtime.mjs +231 -0
  116. package/src/runtime/agent/orchestrator/tools/builtin/snapshot-store.mjs +223 -0
  117. package/src/runtime/agent/orchestrator/tools/builtin.mjs +478 -0
  118. package/src/runtime/agent/orchestrator/tools/code-graph-tool-defs.mjs +24 -0
  119. package/src/runtime/agent/orchestrator/tools/code-graph.mjs +4102 -0
  120. package/src/runtime/agent/orchestrator/tools/destructive-warning.mjs +323 -0
  121. package/src/runtime/agent/orchestrator/tools/graph-binary-fetcher.mjs +154 -0
  122. package/src/runtime/agent/orchestrator/tools/graph-manifest.json +26 -0
  123. package/src/runtime/agent/orchestrator/tools/patch-binary-fetcher.mjs +143 -0
  124. package/src/runtime/agent/orchestrator/tools/patch-tool-defs.mjs +18 -0
  125. package/src/runtime/agent/orchestrator/tools/patch.mjs +2772 -0
  126. package/src/runtime/agent/orchestrator/tools/progress-message.mjs +114 -0
  127. package/src/runtime/agent/orchestrator/tools/shell-command.mjs +880 -0
  128. package/src/runtime/agent/orchestrator/tools/shell-snapshot.mjs +312 -0
  129. package/src/runtime/channels/backends/discord.mjs +781 -0
  130. package/src/runtime/channels/data/voice-runtime-manifest.json +138 -0
  131. package/src/runtime/channels/index.mjs +3309 -0
  132. package/src/runtime/channels/lib/config.mjs +285 -0
  133. package/src/runtime/channels/lib/drop-trace.mjs +71 -0
  134. package/src/runtime/channels/lib/event-pipeline.mjs +81 -0
  135. package/src/runtime/channels/lib/holidays.mjs +138 -0
  136. package/src/runtime/channels/lib/hook-pipe-server.mjs +671 -0
  137. package/src/runtime/channels/lib/output-forwarder.mjs +765 -0
  138. package/src/runtime/channels/lib/runtime-paths.mjs +497 -0
  139. package/src/runtime/channels/lib/scheduler.mjs +710 -0
  140. package/src/runtime/channels/lib/session-discovery.mjs +102 -0
  141. package/src/runtime/channels/lib/state-file.mjs +68 -0
  142. package/src/runtime/channels/lib/status-snapshot.mjs +224 -0
  143. package/src/runtime/channels/lib/tool-format.mjs +124 -0
  144. package/src/runtime/channels/lib/transcript-discovery.mjs +195 -0
  145. package/src/runtime/channels/lib/voice-runtime-fetcher.mjs +734 -0
  146. package/src/runtime/channels/lib/webhook.mjs +1288 -0
  147. package/src/runtime/channels/tool-defs.mjs +177 -0
  148. package/src/runtime/lib/keychain-cjs.cjs +289 -0
  149. package/src/runtime/memory/data/runtime-manifest.json +40 -0
  150. package/src/runtime/memory/index.mjs +3600 -0
  151. package/src/runtime/memory/lib/core-memory-store.mjs +336 -0
  152. package/src/runtime/memory/lib/embedding-provider.mjs +275 -0
  153. package/src/runtime/memory/lib/embedding-worker.mjs +331 -0
  154. package/src/runtime/memory/lib/memory-cycle-requests.mjs +276 -0
  155. package/src/runtime/memory/lib/memory-cycle1.mjs +783 -0
  156. package/src/runtime/memory/lib/memory-cycle2.mjs +1389 -0
  157. package/src/runtime/memory/lib/memory-cycle3.mjs +646 -0
  158. package/src/runtime/memory/lib/memory-embed.mjs +300 -0
  159. package/src/runtime/memory/lib/memory-ops-policy.mjs +149 -0
  160. package/src/runtime/memory/lib/memory-recall-store.mjs +644 -0
  161. package/src/runtime/memory/lib/memory.mjs +418 -0
  162. package/src/runtime/memory/lib/pg/adapter.mjs +314 -0
  163. package/src/runtime/memory/lib/pg/process.mjs +366 -0
  164. package/src/runtime/memory/lib/pg/supervisor.mjs +495 -0
  165. package/src/runtime/memory/lib/runtime-fetcher.mjs +464 -0
  166. package/src/runtime/memory/lib/trace-store.mjs +734 -0
  167. package/src/runtime/memory/tool-defs.mjs +79 -0
  168. package/src/runtime/search/index.mjs +925 -0
  169. package/src/runtime/search/lib/config.mjs +61 -0
  170. package/src/runtime/search/lib/web-tools.mjs +1278 -0
  171. package/src/runtime/search/tool-defs.mjs +64 -0
  172. package/src/runtime/shared/atomic-file.mjs +435 -0
  173. package/src/runtime/shared/background-tasks.mjs +376 -0
  174. package/src/runtime/shared/child-guardian.mjs +98 -0
  175. package/src/runtime/shared/config.mjs +393 -0
  176. package/src/runtime/shared/err-text.mjs +121 -0
  177. package/src/runtime/shared/launcher-control.mjs +259 -0
  178. package/src/runtime/shared/llm/http-agent.mjs +129 -0
  179. package/src/runtime/shared/open-url.mjs +37 -0
  180. package/src/runtime/shared/plugin-paths.mjs +25 -0
  181. package/src/runtime/shared/process-shutdown.mjs +147 -0
  182. package/src/runtime/shared/schedules-store.mjs +70 -0
  183. package/src/runtime/shared/tool-execution-contract.mjs +104 -0
  184. package/src/runtime/shared/tool-surface.mjs +950 -0
  185. package/src/runtime/shared/user-cwd.mjs +221 -0
  186. package/src/runtime/shared/user-data-guard.mjs +232 -0
  187. package/src/runtime/shared/workspace-router.mjs +259 -0
  188. package/src/standalone/bridge-tool.mjs +1414 -0
  189. package/src/standalone/channel-admin.mjs +366 -0
  190. package/src/standalone/channel-worker-preload.cjs +3 -0
  191. package/src/standalone/channel-worker.mjs +353 -0
  192. package/src/standalone/explore-tool.mjs +233 -0
  193. package/src/standalone/hook-bus.mjs +246 -0
  194. package/src/standalone/plugin-admin.mjs +247 -0
  195. package/src/standalone/provider-admin.mjs +338 -0
  196. package/src/standalone/seeds.mjs +94 -0
  197. package/src/standalone/usage-dashboard.mjs +510 -0
  198. package/src/tui/App.jsx +5438 -0
  199. package/src/tui/components/AnsiText.jsx +199 -0
  200. package/src/tui/components/ContextPanel.jsx +217 -0
  201. package/src/tui/components/Markdown.jsx +205 -0
  202. package/src/tui/components/MarkdownTable.jsx +204 -0
  203. package/src/tui/components/Message.jsx +103 -0
  204. package/src/tui/components/Picker.jsx +317 -0
  205. package/src/tui/components/PromptInput.jsx +584 -0
  206. package/src/tui/components/QueuedCommands.jsx +47 -0
  207. package/src/tui/components/SlashCommandPalette.jsx +114 -0
  208. package/src/tui/components/Spinner.jsx +317 -0
  209. package/src/tui/components/StatusLine.jsx +87 -0
  210. package/src/tui/components/TextEntryPanel.jsx +323 -0
  211. package/src/tui/components/ToolExecution.jsx +772 -0
  212. package/src/tui/components/TurnDone.jsx +78 -0
  213. package/src/tui/components/UsagePanel.jsx +331 -0
  214. package/src/tui/dist/index.mjs +12359 -0
  215. package/src/tui/engine.mjs +2410 -0
  216. package/src/tui/figures.mjs +50 -0
  217. package/src/tui/hooks/useEngine.mjs +16 -0
  218. package/src/tui/index.jsx +254 -0
  219. package/src/tui/input-editing.mjs +242 -0
  220. package/src/tui/markdown/format-token.mjs +194 -0
  221. package/src/tui/paste-attachments.mjs +198 -0
  222. package/src/tui/runtime/shared/process-shutdown.mjs +1 -0
  223. package/src/tui/spinner-verbs.mjs +45 -0
  224. package/src/tui/theme.mjs +67 -0
  225. package/src/tui/time-format.mjs +53 -0
  226. package/src/ui/ansi.mjs +115 -0
  227. package/src/ui/markdown.mjs +195 -0
  228. package/src/ui/statusline.mjs +730 -0
  229. package/src/ui/tool-card.mjs +101 -0
  230. package/src/vendor/statusline/bin/statusline-lib.mjs +805 -0
  231. package/src/vendor/statusline/bin/statusline-route.mjs +596 -0
  232. package/src/vendor/statusline/scripts/lib/gateway-settings.mjs +285 -0
  233. package/src/vendor/statusline/src/gateway/claude-current.mjs +320 -0
  234. package/src/vendor/statusline/src/gateway/route-meta.mjs +753 -0
  235. package/src/vendor/statusline/src/gateway/session-routes.mjs +244 -0
  236. package/src/workflows/default/WORKFLOW.md +7 -0
  237. package/src/workflows/default/workflow.json +14 -0
  238. package/vendor/ink/build/ansi-tokenizer.d.ts +38 -0
  239. package/vendor/ink/build/ansi-tokenizer.js +316 -0
  240. package/vendor/ink/build/ansi-tokenizer.js.map +1 -0
  241. package/vendor/ink/build/colorize.d.ts +3 -0
  242. package/vendor/ink/build/colorize.js +48 -0
  243. package/vendor/ink/build/colorize.js.map +1 -0
  244. package/vendor/ink/build/components/AccessibilityContext.d.ts +3 -0
  245. package/vendor/ink/build/components/AccessibilityContext.js +5 -0
  246. package/vendor/ink/build/components/AccessibilityContext.js.map +1 -0
  247. package/vendor/ink/build/components/AnimationContext.d.ts +9 -0
  248. package/vendor/ink/build/components/AnimationContext.js +13 -0
  249. package/vendor/ink/build/components/AnimationContext.js.map +1 -0
  250. package/vendor/ink/build/components/App.d.ts +24 -0
  251. package/vendor/ink/build/components/App.js +554 -0
  252. package/vendor/ink/build/components/App.js.map +1 -0
  253. package/vendor/ink/build/components/AppContext.d.ts +80 -0
  254. package/vendor/ink/build/components/AppContext.js +25 -0
  255. package/vendor/ink/build/components/AppContext.js.map +1 -0
  256. package/vendor/ink/build/components/BackgroundContext.d.ts +4 -0
  257. package/vendor/ink/build/components/BackgroundContext.js +3 -0
  258. package/vendor/ink/build/components/BackgroundContext.js.map +1 -0
  259. package/vendor/ink/build/components/Box.d.ts +130 -0
  260. package/vendor/ink/build/components/Box.js +34 -0
  261. package/vendor/ink/build/components/Box.js.map +1 -0
  262. package/vendor/ink/build/components/CursorContext.d.ts +11 -0
  263. package/vendor/ink/build/components/CursorContext.js +8 -0
  264. package/vendor/ink/build/components/CursorContext.js.map +1 -0
  265. package/vendor/ink/build/components/ErrorBoundary.d.ts +18 -0
  266. package/vendor/ink/build/components/ErrorBoundary.js +23 -0
  267. package/vendor/ink/build/components/ErrorBoundary.js.map +1 -0
  268. package/vendor/ink/build/components/ErrorOverview.d.ts +6 -0
  269. package/vendor/ink/build/components/ErrorOverview.js +90 -0
  270. package/vendor/ink/build/components/ErrorOverview.js.map +1 -0
  271. package/vendor/ink/build/components/FocusContext.d.ts +16 -0
  272. package/vendor/ink/build/components/FocusContext.js +17 -0
  273. package/vendor/ink/build/components/FocusContext.js.map +1 -0
  274. package/vendor/ink/build/components/Newline.d.ts +13 -0
  275. package/vendor/ink/build/components/Newline.js +8 -0
  276. package/vendor/ink/build/components/Newline.js.map +1 -0
  277. package/vendor/ink/build/components/Spacer.d.ts +7 -0
  278. package/vendor/ink/build/components/Spacer.js +11 -0
  279. package/vendor/ink/build/components/Spacer.js.map +1 -0
  280. package/vendor/ink/build/components/Static.d.ts +24 -0
  281. package/vendor/ink/build/components/Static.js +28 -0
  282. package/vendor/ink/build/components/Static.js.map +1 -0
  283. package/vendor/ink/build/components/StderrContext.d.ts +15 -0
  284. package/vendor/ink/build/components/StderrContext.js +13 -0
  285. package/vendor/ink/build/components/StderrContext.js.map +1 -0
  286. package/vendor/ink/build/components/StdinContext.d.ts +28 -0
  287. package/vendor/ink/build/components/StdinContext.js +20 -0
  288. package/vendor/ink/build/components/StdinContext.js.map +1 -0
  289. package/vendor/ink/build/components/StdoutContext.d.ts +15 -0
  290. package/vendor/ink/build/components/StdoutContext.js +13 -0
  291. package/vendor/ink/build/components/StdoutContext.js.map +1 -0
  292. package/vendor/ink/build/components/Text.d.ts +55 -0
  293. package/vendor/ink/build/components/Text.js +50 -0
  294. package/vendor/ink/build/components/Text.js.map +1 -0
  295. package/vendor/ink/build/components/Transform.d.ts +16 -0
  296. package/vendor/ink/build/components/Transform.js +15 -0
  297. package/vendor/ink/build/components/Transform.js.map +1 -0
  298. package/vendor/ink/build/cursor-helpers.d.ts +39 -0
  299. package/vendor/ink/build/cursor-helpers.js +62 -0
  300. package/vendor/ink/build/cursor-helpers.js.map +1 -0
  301. package/vendor/ink/build/devtools-window-polyfill.d.ts +1 -0
  302. package/vendor/ink/build/devtools-window-polyfill.js +68 -0
  303. package/vendor/ink/build/devtools-window-polyfill.js.map +1 -0
  304. package/vendor/ink/build/devtools.d.ts +1 -0
  305. package/vendor/ink/build/devtools.js +36 -0
  306. package/vendor/ink/build/devtools.js.map +1 -0
  307. package/vendor/ink/build/dom.d.ts +62 -0
  308. package/vendor/ink/build/dom.js +143 -0
  309. package/vendor/ink/build/dom.js.map +1 -0
  310. package/vendor/ink/build/get-max-width.d.ts +3 -0
  311. package/vendor/ink/build/get-max-width.js +10 -0
  312. package/vendor/ink/build/get-max-width.js.map +1 -0
  313. package/vendor/ink/build/hooks/use-animation.d.ts +49 -0
  314. package/vendor/ink/build/hooks/use-animation.js +87 -0
  315. package/vendor/ink/build/hooks/use-animation.js.map +1 -0
  316. package/vendor/ink/build/hooks/use-app.d.ts +5 -0
  317. package/vendor/ink/build/hooks/use-app.js +8 -0
  318. package/vendor/ink/build/hooks/use-app.js.map +1 -0
  319. package/vendor/ink/build/hooks/use-box-metrics.d.ts +59 -0
  320. package/vendor/ink/build/hooks/use-box-metrics.js +81 -0
  321. package/vendor/ink/build/hooks/use-box-metrics.js.map +1 -0
  322. package/vendor/ink/build/hooks/use-cursor.d.ts +12 -0
  323. package/vendor/ink/build/hooks/use-cursor.js +29 -0
  324. package/vendor/ink/build/hooks/use-cursor.js.map +1 -0
  325. package/vendor/ink/build/hooks/use-focus-manager.d.ts +43 -0
  326. package/vendor/ink/build/hooks/use-focus-manager.js +18 -0
  327. package/vendor/ink/build/hooks/use-focus-manager.js.map +1 -0
  328. package/vendor/ink/build/hooks/use-focus.d.ts +30 -0
  329. package/vendor/ink/build/hooks/use-focus.js +43 -0
  330. package/vendor/ink/build/hooks/use-focus.js.map +1 -0
  331. package/vendor/ink/build/hooks/use-input.d.ts +132 -0
  332. package/vendor/ink/build/hooks/use-input.js +126 -0
  333. package/vendor/ink/build/hooks/use-input.js.map +1 -0
  334. package/vendor/ink/build/hooks/use-is-screen-reader-enabled.d.ts +6 -0
  335. package/vendor/ink/build/hooks/use-is-screen-reader-enabled.js +12 -0
  336. package/vendor/ink/build/hooks/use-is-screen-reader-enabled.js.map +1 -0
  337. package/vendor/ink/build/hooks/use-paste.d.ts +35 -0
  338. package/vendor/ink/build/hooks/use-paste.js +62 -0
  339. package/vendor/ink/build/hooks/use-paste.js.map +1 -0
  340. package/vendor/ink/build/hooks/use-stderr.d.ts +5 -0
  341. package/vendor/ink/build/hooks/use-stderr.js +8 -0
  342. package/vendor/ink/build/hooks/use-stderr.js.map +1 -0
  343. package/vendor/ink/build/hooks/use-stdin.d.ts +7 -0
  344. package/vendor/ink/build/hooks/use-stdin.js +9 -0
  345. package/vendor/ink/build/hooks/use-stdin.js.map +1 -0
  346. package/vendor/ink/build/hooks/use-stdout.d.ts +5 -0
  347. package/vendor/ink/build/hooks/use-stdout.js +8 -0
  348. package/vendor/ink/build/hooks/use-stdout.js.map +1 -0
  349. package/vendor/ink/build/hooks/use-window-size.d.ts +18 -0
  350. package/vendor/ink/build/hooks/use-window-size.js +22 -0
  351. package/vendor/ink/build/hooks/use-window-size.js.map +1 -0
  352. package/vendor/ink/build/index.d.ts +42 -0
  353. package/vendor/ink/build/index.js +24 -0
  354. package/vendor/ink/build/index.js.map +1 -0
  355. package/vendor/ink/build/ink.d.ts +146 -0
  356. package/vendor/ink/build/ink.js +1022 -0
  357. package/vendor/ink/build/ink.js.map +1 -0
  358. package/vendor/ink/build/input-parser.d.ts +10 -0
  359. package/vendor/ink/build/input-parser.js +194 -0
  360. package/vendor/ink/build/input-parser.js.map +1 -0
  361. package/vendor/ink/build/instances.d.ts +3 -0
  362. package/vendor/ink/build/instances.js +8 -0
  363. package/vendor/ink/build/instances.js.map +1 -0
  364. package/vendor/ink/build/kitty-keyboard.d.ts +23 -0
  365. package/vendor/ink/build/kitty-keyboard.js +32 -0
  366. package/vendor/ink/build/kitty-keyboard.js.map +1 -0
  367. package/vendor/ink/build/log-update.d.ts +20 -0
  368. package/vendor/ink/build/log-update.js +261 -0
  369. package/vendor/ink/build/log-update.js.map +1 -0
  370. package/vendor/ink/build/measure-element.d.ts +20 -0
  371. package/vendor/ink/build/measure-element.js +13 -0
  372. package/vendor/ink/build/measure-element.js.map +1 -0
  373. package/vendor/ink/build/measure-text.d.ts +6 -0
  374. package/vendor/ink/build/measure-text.js +21 -0
  375. package/vendor/ink/build/measure-text.js.map +1 -0
  376. package/vendor/ink/build/output.d.ts +35 -0
  377. package/vendor/ink/build/output.js +328 -0
  378. package/vendor/ink/build/output.js.map +1 -0
  379. package/vendor/ink/build/parse-keypress.d.ts +20 -0
  380. package/vendor/ink/build/parse-keypress.js +495 -0
  381. package/vendor/ink/build/parse-keypress.js.map +1 -0
  382. package/vendor/ink/build/reconciler.d.ts +4 -0
  383. package/vendor/ink/build/reconciler.js +306 -0
  384. package/vendor/ink/build/reconciler.js.map +1 -0
  385. package/vendor/ink/build/render-background.d.ts +4 -0
  386. package/vendor/ink/build/render-background.js +25 -0
  387. package/vendor/ink/build/render-background.js.map +1 -0
  388. package/vendor/ink/build/render-border.d.ts +4 -0
  389. package/vendor/ink/build/render-border.js +84 -0
  390. package/vendor/ink/build/render-border.js.map +1 -0
  391. package/vendor/ink/build/render-node-to-output.d.ts +14 -0
  392. package/vendor/ink/build/render-node-to-output.js +162 -0
  393. package/vendor/ink/build/render-node-to-output.js.map +1 -0
  394. package/vendor/ink/build/render-to-string.d.ts +38 -0
  395. package/vendor/ink/build/render-to-string.js +116 -0
  396. package/vendor/ink/build/render-to-string.js.map +1 -0
  397. package/vendor/ink/build/render.d.ts +176 -0
  398. package/vendor/ink/build/render.js +71 -0
  399. package/vendor/ink/build/render.js.map +1 -0
  400. package/vendor/ink/build/renderer.d.ts +8 -0
  401. package/vendor/ink/build/renderer.js +64 -0
  402. package/vendor/ink/build/renderer.js.map +1 -0
  403. package/vendor/ink/build/sanitize-ansi.d.ts +2 -0
  404. package/vendor/ink/build/sanitize-ansi.js +27 -0
  405. package/vendor/ink/build/sanitize-ansi.js.map +1 -0
  406. package/vendor/ink/build/squash-text-nodes.d.ts +3 -0
  407. package/vendor/ink/build/squash-text-nodes.js +36 -0
  408. package/vendor/ink/build/squash-text-nodes.js.map +1 -0
  409. package/vendor/ink/build/styles.d.ts +302 -0
  410. package/vendor/ink/build/styles.js +303 -0
  411. package/vendor/ink/build/styles.js.map +1 -0
  412. package/vendor/ink/build/utils.d.ts +9 -0
  413. package/vendor/ink/build/utils.js +19 -0
  414. package/vendor/ink/build/utils.js.map +1 -0
  415. package/vendor/ink/build/wrap-text.d.ts +3 -0
  416. package/vendor/ink/build/wrap-text.js +38 -0
  417. package/vendor/ink/build/wrap-text.js.map +1 -0
  418. package/vendor/ink/build/write-synchronized.d.ts +4 -0
  419. package/vendor/ink/build/write-synchronized.js +9 -0
  420. package/vendor/ink/build/write-synchronized.js.map +1 -0
  421. package/vendor/ink/license +10 -0
  422. package/vendor/ink/package.json +137 -0
  423. package/.claude-plugin/marketplace.json +0 -34
  424. package/.claude-plugin/plugin.json +0 -20
  425. package/.gitattributes +0 -34
  426. package/.mcp.json +0 -14
  427. package/ARCHITECTURE.md +0 -77
  428. package/CHANGELOG.md +0 -30
  429. package/CONTRIBUTING.md +0 -45
  430. package/DATA-FLOW.md +0 -79
  431. package/LICENSE +0 -21
  432. package/SECURITY.md +0 -138
  433. package/UNINSTALL.md +0 -115
  434. package/agents/maintenance.md +0 -5
  435. package/agents/memory-classification.md +0 -30
  436. package/agents/scheduler-task.md +0 -18
  437. package/agents/webhook-handler.md +0 -27
  438. package/agents/worker.md +0 -24
  439. package/bin/bridge +0 -133
  440. package/bin/statusline-launcher.mjs +0 -82
  441. package/bin/statusline-lib.mjs +0 -581
  442. package/bin/statusline-route.mjs +0 -273
  443. package/bin/statusline.mjs +0 -638
  444. package/bun.lock +0 -927
  445. package/commands/config.md +0 -16
  446. package/commands/doctor.md +0 -13
  447. package/commands/model.md +0 -61
  448. package/commands/setup.md +0 -17
  449. package/defaults/hidden-roles.json +0 -68
  450. package/defaults/memory-chunk-prompt.md +0 -63
  451. package/defaults/mixdog-config.template.json +0 -27
  452. package/defaults/user-workflow.json +0 -8
  453. package/defaults/user-workflow.md +0 -17
  454. package/hooks/hooks.json +0 -73
  455. package/hooks/lib/active-instance.cjs +0 -77
  456. package/hooks/lib/permission-evaluator.cjs +0 -411
  457. package/hooks/lib/permission-route.cjs +0 -63
  458. package/hooks/lib/settings-loader.cjs +0 -117
  459. package/hooks/post-tool-use.cjs +0 -84
  460. package/hooks/pre-mcp-sandbox.cjs +0 -158
  461. package/hooks/pre-tool-subagent.cjs +0 -258
  462. package/hooks/session-start.cjs +0 -1493
  463. package/hooks/shim-launcher.cjs +0 -65
  464. package/hooks/turn-timer.cjs +0 -82
  465. package/lib/claude-md-writer.cjs +0 -386
  466. package/lib/keychain-cjs.cjs +0 -290
  467. package/lib/plugin-paths.cjs +0 -69
  468. package/lib/rules-builder.cjs +0 -241
  469. package/native/README.md +0 -117
  470. package/native/prebuilt/linux-aarch64/mixdog-shim +0 -0
  471. package/native/prebuilt/linux-x86_64/mixdog-shim +0 -0
  472. package/native/prebuilt/macos-aarch64/mixdog-shim +0 -0
  473. package/native/prebuilt/macos-x86_64/mixdog-shim +0 -0
  474. package/native/prebuilt/windows-x86_64/mixdog-shim.exe +0 -0
  475. package/prompts/code-review.txt +0 -16
  476. package/prompts/security-audit.txt +0 -17
  477. package/rules/bridge/00-common.md +0 -39
  478. package/rules/bridge/20-skip-protocol.md +0 -18
  479. package/rules/bridge/30-explorer.md +0 -33
  480. package/rules/bridge/40-cycle1-agent.md +0 -52
  481. package/rules/bridge/41-cycle2-agent.md +0 -62
  482. package/rules/lead/00-tool-lead.md +0 -61
  483. package/rules/lead/01-general.md +0 -26
  484. package/rules/lead/02-channels.md +0 -49
  485. package/rules/lead/03-team.md +0 -27
  486. package/rules/lead/04-workflow.md +0 -20
  487. package/rules/shared/00-language.md +0 -14
  488. package/rules/shared/01-tool.md +0 -138
  489. package/scripts/bootstrap.mjs +0 -130
  490. package/scripts/bridge-unify-smoke.mjs +0 -308
  491. package/scripts/build-runtime-linux.sh +0 -348
  492. package/scripts/build-runtime-macos.sh +0 -217
  493. package/scripts/build-runtime-windows.ps1 +0 -242
  494. package/scripts/builtin-utils-smoke.mjs +0 -398
  495. package/scripts/bump.mjs +0 -80
  496. package/scripts/check-json.mjs +0 -45
  497. package/scripts/check-syntax-changed.mjs +0 -102
  498. package/scripts/check-syntax.mjs +0 -58
  499. package/scripts/code-graph-batch.test.mjs +0 -33
  500. package/scripts/config-preserve-smoke.mjs +0 -180
  501. package/scripts/doctor.mjs +0 -489
  502. package/scripts/edit-normalize-fuzz.mjs +0 -130
  503. package/scripts/edit-normalize-smoke.mjs +0 -401
  504. package/scripts/edit-operation-smoke.mjs +0 -369
  505. package/scripts/edit2-smoke.mjs +0 -63
  506. package/scripts/ensure-deps.mjs +0 -259
  507. package/scripts/fuzzy-e2e.mjs +0 -28
  508. package/scripts/fuzzy-smoke.mjs +0 -26
  509. package/scripts/gateway-model.mjs +0 -596
  510. package/scripts/generate-runtime-manifest.mjs +0 -166
  511. package/scripts/guard-smoke.mjs +0 -66
  512. package/scripts/hidden-role-schema-smoke.mjs +0 -162
  513. package/scripts/hook-routing-smoke.mjs +0 -29
  514. package/scripts/inject-input.ps1 +0 -204
  515. package/scripts/io-complex-smoke.mjs +0 -667
  516. package/scripts/io-explore-bench.mjs +0 -424
  517. package/scripts/io-guardrails-smoke.mjs +0 -205
  518. package/scripts/io-mini-bench-baseline.json +0 -11
  519. package/scripts/io-mini-bench.mjs +0 -216
  520. package/scripts/io-route-harness.mjs +0 -933
  521. package/scripts/io-telemetry-report.mjs +0 -691
  522. package/scripts/lib/gateway-inventory.mjs +0 -178
  523. package/scripts/lib/gateway-settings.mjs +0 -78
  524. package/scripts/mutation-bench.mjs +0 -564
  525. package/scripts/mutation-io-smoke.mjs +0 -1097
  526. package/scripts/native-patch-bridge-smoke.mjs +0 -288
  527. package/scripts/native-patch-smoke.mjs +0 -304
  528. package/scripts/openai-oauth-catalog-smoke.mjs +0 -53
  529. package/scripts/patch-interior-context-smoke.mjs +0 -49
  530. package/scripts/patch-newline-utf8-smoke.mjs +0 -157
  531. package/scripts/perf-hook-smoke.mjs +0 -71
  532. package/scripts/permission-eval-smoke.mjs +0 -443
  533. package/scripts/prep-patch.mjs +0 -53
  534. package/scripts/prep-shim.mjs +0 -96
  535. package/scripts/provider-cache-smoke.mjs +0 -687
  536. package/scripts/report-runtime-health.mjs +0 -132
  537. package/scripts/resolve-bun.mjs +0 -60
  538. package/scripts/run-mcp.mjs +0 -1473
  539. package/scripts/salvage-v4a-shatter.test.mjs +0 -58
  540. package/scripts/scoped-cache-io-smoke.mjs +0 -103
  541. package/scripts/shell-policy-round3-smoke.mjs +0 -46
  542. package/scripts/smoke-runtime-negative.ps1 +0 -100
  543. package/scripts/smoke-runtime-negative.sh +0 -95
  544. package/scripts/stall-policy-smoke.mjs +0 -50
  545. package/scripts/start-memory-worker.mjs +0 -23
  546. package/scripts/statusline-launcher-smoke.mjs +0 -235
  547. package/scripts/stress-atomic-write.mjs +0 -1028
  548. package/scripts/test-fault-inject.mjs +0 -164
  549. package/scripts/test-large-file.mjs +0 -174
  550. package/scripts/tool-edge-smoke.mjs +0 -209
  551. package/scripts/uninstall.mjs +0 -238
  552. package/scripts/webhook-selfheal-smoke.mjs +0 -27
  553. package/scripts/write-overwrite-guard-smoke.mjs +0 -56
  554. package/server-main.mjs +0 -3350
  555. package/server.mjs +0 -468
  556. package/setup/config-merge.mjs +0 -246
  557. package/setup/install.mjs +0 -574
  558. package/setup/launch-core.mjs +0 -617
  559. package/setup/launch.mjs +0 -101
  560. package/setup/locate-claude.mjs +0 -56
  561. package/setup/mixdog-cli.mjs +0 -122
  562. package/setup/setup-server.mjs +0 -3305
  563. package/setup/setup.html +0 -3740
  564. package/setup/tui.mjs +0 -325
  565. package/skills/retro-skill-proposer/SKILL.md +0 -92
  566. package/skills/schedule-add/SKILL.md +0 -77
  567. package/skills/setup/SKILL.md +0 -356
  568. package/skills/webhook-add/SKILL.md +0 -81
  569. package/src/agent/bridge-stall-watchdog.mjs +0 -337
  570. package/src/agent/index.mjs +0 -2229
  571. package/src/agent/orchestrator/ai-wrapped-dispatch.mjs +0 -1010
  572. package/src/agent/orchestrator/bridge-retry.mjs +0 -220
  573. package/src/agent/orchestrator/bridge-trace.mjs +0 -601
  574. package/src/agent/orchestrator/cache-mtime.mjs +0 -58
  575. package/src/agent/orchestrator/config.mjs +0 -405
  576. package/src/agent/orchestrator/context/collect.mjs +0 -651
  577. package/src/agent/orchestrator/dispatch-persist.mjs +0 -549
  578. package/src/agent/orchestrator/drain-registry.mjs +0 -50
  579. package/src/agent/orchestrator/explore-validator.mjs +0 -8
  580. package/src/agent/orchestrator/internal-roles.mjs +0 -118
  581. package/src/agent/orchestrator/internal-tools.mjs +0 -88
  582. package/src/agent/orchestrator/jobs.mjs +0 -116
  583. package/src/agent/orchestrator/mcp/client.mjs +0 -364
  584. package/src/agent/orchestrator/providers/anthropic-oauth.mjs +0 -1884
  585. package/src/agent/orchestrator/providers/anthropic.mjs +0 -598
  586. package/src/agent/orchestrator/providers/gemini.mjs +0 -1530
  587. package/src/agent/orchestrator/providers/grok-oauth.mjs +0 -779
  588. package/src/agent/orchestrator/providers/model-catalog.mjs +0 -374
  589. package/src/agent/orchestrator/providers/openai-compat-stream.mjs +0 -366
  590. package/src/agent/orchestrator/providers/openai-compat.mjs +0 -1511
  591. package/src/agent/orchestrator/providers/openai-oauth-ws.mjs +0 -1891
  592. package/src/agent/orchestrator/providers/openai-oauth.mjs +0 -1456
  593. package/src/agent/orchestrator/providers/openai-ws.mjs +0 -127
  594. package/src/agent/orchestrator/providers/registry.mjs +0 -192
  595. package/src/agent/orchestrator/providers/retry-classifier.mjs +0 -325
  596. package/src/agent/orchestrator/session/cache/prefetch-cache.mjs +0 -142
  597. package/src/agent/orchestrator/session/cache/read-cache.mjs +0 -319
  598. package/src/agent/orchestrator/session/cache/scoped-cache.mjs +0 -361
  599. package/src/agent/orchestrator/session/loop.mjs +0 -1619
  600. package/src/agent/orchestrator/session/manager.mjs +0 -1991
  601. package/src/agent/orchestrator/session/result-classification.mjs +0 -65
  602. package/src/agent/orchestrator/session/store.mjs +0 -632
  603. package/src/agent/orchestrator/session/stream-watchdog.mjs +0 -130
  604. package/src/agent/orchestrator/session/tool-result-offload.mjs +0 -166
  605. package/src/agent/orchestrator/session/trim.mjs +0 -491
  606. package/src/agent/orchestrator/smart-bridge/CACHE-SHARD.md +0 -115
  607. package/src/agent/orchestrator/smart-bridge/bridge-llm.mjs +0 -331
  608. package/src/agent/orchestrator/smart-bridge/cache-obs.mjs +0 -150
  609. package/src/agent/orchestrator/smart-bridge/cache-strategy.mjs +0 -228
  610. package/src/agent/orchestrator/smart-bridge/index.mjs +0 -215
  611. package/src/agent/orchestrator/smart-bridge/profiles.mjs +0 -37
  612. package/src/agent/orchestrator/smart-bridge/registry.mjs +0 -348
  613. package/src/agent/orchestrator/stall-policy.mjs +0 -201
  614. package/src/agent/orchestrator/tool-loop-guard.mjs +0 -75
  615. package/src/agent/orchestrator/tools/bash-session.mjs +0 -722
  616. package/src/agent/orchestrator/tools/builtin/arg-guard.mjs +0 -511
  617. package/src/agent/orchestrator/tools/builtin/bash-tool.mjs +0 -480
  618. package/src/agent/orchestrator/tools/builtin/builtin-tools.mjs +0 -256
  619. package/src/agent/orchestrator/tools/builtin/edit-base-guard.mjs +0 -58
  620. package/src/agent/orchestrator/tools/builtin/edit-byte-plan.mjs +0 -240
  621. package/src/agent/orchestrator/tools/builtin/edit-byte-utils.mjs +0 -113
  622. package/src/agent/orchestrator/tools/builtin/edit-commit.mjs +0 -74
  623. package/src/agent/orchestrator/tools/builtin/edit-context-utils.mjs +0 -242
  624. package/src/agent/orchestrator/tools/builtin/edit-diagnostics.mjs +0 -211
  625. package/src/agent/orchestrator/tools/builtin/edit-engine.mjs +0 -1364
  626. package/src/agent/orchestrator/tools/builtin/edit-failure-context.mjs +0 -126
  627. package/src/agent/orchestrator/tools/builtin/edit-hint.mjs +0 -141
  628. package/src/agent/orchestrator/tools/builtin/edit-match-utils.mjs +0 -194
  629. package/src/agent/orchestrator/tools/builtin/edit-partial-write.mjs +0 -60
  630. package/src/agent/orchestrator/tools/builtin/edit-stale-refresh.mjs +0 -168
  631. package/src/agent/orchestrator/tools/builtin/edit-tool.mjs +0 -173
  632. package/src/agent/orchestrator/tools/builtin/edit-utf8-guard.mjs +0 -48
  633. package/src/agent/orchestrator/tools/builtin/fuzzy-match.mjs +0 -99
  634. package/src/agent/orchestrator/tools/builtin/glob-walk.mjs +0 -193
  635. package/src/agent/orchestrator/tools/builtin/list-tool.mjs +0 -597
  636. package/src/agent/orchestrator/tools/builtin/native-edit-runner.mjs +0 -110
  637. package/src/agent/orchestrator/tools/builtin/notebook-edit-tool.mjs +0 -300
  638. package/src/agent/orchestrator/tools/builtin/path-diagnostics.mjs +0 -152
  639. package/src/agent/orchestrator/tools/builtin/read-formatting.mjs +0 -118
  640. package/src/agent/orchestrator/tools/builtin/read-open.mjs +0 -190
  641. package/src/agent/orchestrator/tools/builtin/read-single-tool.mjs +0 -728
  642. package/src/agent/orchestrator/tools/builtin/read-snapshot-runtime.mjs +0 -173
  643. package/src/agent/orchestrator/tools/builtin/read-streaming.mjs +0 -602
  644. package/src/agent/orchestrator/tools/builtin/rename-tool.mjs +0 -196
  645. package/src/agent/orchestrator/tools/builtin/rg-runner.mjs +0 -422
  646. package/src/agent/orchestrator/tools/builtin/search-builders.mjs +0 -158
  647. package/src/agent/orchestrator/tools/builtin/search-tool.mjs +0 -869
  648. package/src/agent/orchestrator/tools/builtin/shell-jobs.mjs +0 -962
  649. package/src/agent/orchestrator/tools/builtin/shell-runtime.mjs +0 -223
  650. package/src/agent/orchestrator/tools/builtin/snapshot-store.mjs +0 -206
  651. package/src/agent/orchestrator/tools/builtin/write-tool.mjs +0 -401
  652. package/src/agent/orchestrator/tools/builtin.mjs +0 -503
  653. package/src/agent/orchestrator/tools/code-graph-tool-defs.mjs +0 -24
  654. package/src/agent/orchestrator/tools/code-graph.mjs +0 -4095
  655. package/src/agent/orchestrator/tools/cwd-tool.mjs +0 -298
  656. package/src/agent/orchestrator/tools/destructive-warning.mjs +0 -323
  657. package/src/agent/orchestrator/tools/edit-normalize.mjs +0 -603
  658. package/src/agent/orchestrator/tools/graph-binary-fetcher.mjs +0 -154
  659. package/src/agent/orchestrator/tools/graph-manifest.json +0 -26
  660. package/src/agent/orchestrator/tools/host-input.mjs +0 -204
  661. package/src/agent/orchestrator/tools/patch-binary-fetcher.mjs +0 -143
  662. package/src/agent/orchestrator/tools/patch-manifest.json +0 -26
  663. package/src/agent/orchestrator/tools/patch-tool-defs.mjs +0 -20
  664. package/src/agent/orchestrator/tools/patch.mjs +0 -2754
  665. package/src/agent/orchestrator/tools/progress-message.mjs +0 -118
  666. package/src/agent/orchestrator/tools/shell-command.mjs +0 -865
  667. package/src/agent/orchestrator/tools/shell-policy-imports.mjs +0 -7
  668. package/src/agent/orchestrator/tools/shell-snapshot.mjs +0 -313
  669. package/src/agent/orchestrator/workflow-store.mjs +0 -93
  670. package/src/agent/tool-defs.mjs +0 -110
  671. package/src/channels/backends/discord.mjs +0 -784
  672. package/src/channels/data/voice-runtime-manifest.json +0 -138
  673. package/src/channels/index.mjs +0 -3268
  674. package/src/channels/lib/config.mjs +0 -292
  675. package/src/channels/lib/drop-trace.mjs +0 -71
  676. package/src/channels/lib/event-pipeline.mjs +0 -81
  677. package/src/channels/lib/holidays.mjs +0 -138
  678. package/src/channels/lib/hook-pipe-server.mjs +0 -822
  679. package/src/channels/lib/output-forwarder.mjs +0 -765
  680. package/src/channels/lib/runtime-paths.mjs +0 -552
  681. package/src/channels/lib/scheduler.mjs +0 -723
  682. package/src/channels/lib/session-discovery.mjs +0 -103
  683. package/src/channels/lib/state-file.mjs +0 -68
  684. package/src/channels/lib/status-snapshot.mjs +0 -219
  685. package/src/channels/lib/tool-format.mjs +0 -140
  686. package/src/channels/lib/transcript-discovery.mjs +0 -195
  687. package/src/channels/lib/voice-runtime-fetcher.mjs +0 -734
  688. package/src/channels/lib/webhook.mjs +0 -1318
  689. package/src/channels/tool-defs.mjs +0 -170
  690. package/src/daemon/host.mjs +0 -118
  691. package/src/daemon/mcp-transport.mjs +0 -47
  692. package/src/daemon/session.mjs +0 -100
  693. package/src/daemon/thin-client.mjs +0 -71
  694. package/src/daemon/transport.mjs +0 -163
  695. package/src/gateway/claude-current.mjs +0 -255
  696. package/src/gateway/oauth-usage.mjs +0 -598
  697. package/src/gateway/route-meta.mjs +0 -629
  698. package/src/gateway/server.mjs +0 -713
  699. package/src/memory/data/runtime-manifest.json +0 -40
  700. package/src/memory/index.mjs +0 -3332
  701. package/src/memory/lib/core-memory-store.mjs +0 -330
  702. package/src/memory/lib/embedding-provider.mjs +0 -269
  703. package/src/memory/lib/embedding-worker.mjs +0 -323
  704. package/src/memory/lib/memory-cycle1.mjs +0 -645
  705. package/src/memory/lib/memory-cycle2.mjs +0 -1284
  706. package/src/memory/lib/memory-cycle3.mjs +0 -540
  707. package/src/memory/lib/memory-embed.mjs +0 -299
  708. package/src/memory/lib/memory-ops-policy.mjs +0 -190
  709. package/src/memory/lib/memory-recall-store.mjs +0 -638
  710. package/src/memory/lib/memory.mjs +0 -412
  711. package/src/memory/lib/pg/adapter.mjs +0 -308
  712. package/src/memory/lib/pg/process.mjs +0 -360
  713. package/src/memory/lib/pg/supervisor.mjs +0 -396
  714. package/src/memory/lib/runtime-fetcher.mjs +0 -458
  715. package/src/memory/lib/trace-store.mjs +0 -728
  716. package/src/memory/tool-defs.mjs +0 -79
  717. package/src/search/index.mjs +0 -1173
  718. package/src/search/lib/backends/anthropic-oauth.mjs +0 -98
  719. package/src/search/lib/backends/exa.mjs +0 -50
  720. package/src/search/lib/backends/firecrawl.mjs +0 -61
  721. package/src/search/lib/backends/gemini-api.mjs +0 -83
  722. package/src/search/lib/backends/grok-oauth.mjs +0 -86
  723. package/src/search/lib/backends/index.mjs +0 -150
  724. package/src/search/lib/backends/openai-api.mjs +0 -144
  725. package/src/search/lib/backends/openai-oauth.mjs +0 -102
  726. package/src/search/lib/backends/openai-web-search.mjs +0 -76
  727. package/src/search/lib/backends/tavily.mjs +0 -55
  728. package/src/search/lib/backends/xai-api.mjs +0 -113
  729. package/src/search/lib/config.mjs +0 -192
  730. package/src/search/lib/provider-usage.mjs +0 -67
  731. package/src/search/lib/providers.mjs +0 -47
  732. package/src/search/lib/search-intent.mjs +0 -109
  733. package/src/search/lib/setup-handler.mjs +0 -261
  734. package/src/search/lib/web-tools.mjs +0 -1219
  735. package/src/search/tool-defs.mjs +0 -83
  736. package/src/setup/defender-exclusion.mjs +0 -183
  737. package/src/shared/atomic-file.mjs +0 -436
  738. package/src/shared/config.mjs +0 -372
  739. package/src/shared/daemon-recycle.mjs +0 -108
  740. package/src/shared/disable-claude-builtins.mjs +0 -91
  741. package/src/shared/err-text.mjs +0 -12
  742. package/src/shared/llm/http-agent.mjs +0 -123
  743. package/src/shared/open-url.mjs +0 -62
  744. package/src/shared/plugin-paths.mjs +0 -58
  745. package/src/shared/schedules-store.mjs +0 -70
  746. package/src/shared/seed.mjs +0 -161
  747. package/src/shared/user-cwd.mjs +0 -225
  748. package/src/shared/user-data-guard.mjs +0 -244
  749. package/src/status/aggregator.mjs +0 -584
  750. package/src/status/server.mjs +0 -413
  751. package/tools.json +0 -1671
  752. /package/{defaults → src/defaults}/cycle3-review-prompt.md +0 -0
  753. /package/{defaults → src/defaults}/memory-promote-prompt.md +0 -0
  754. /package/{hooks → src/hooks}/lib/permission-rules.cjs +0 -0
  755. /package/{lib → src/lib}/config-cjs.cjs +0 -0
  756. /package/{lib → src/lib}/hook-pipe-path.cjs +0 -0
  757. /package/{lib → src/lib}/mixdog-debug.cjs +0 -0
  758. /package/{lib → src/lib}/text-utils.cjs +0 -0
  759. /package/{rules → src/rules}/bridge/42-cycle3-agent.md +0 -0
  760. /package/src/{agent → runtime/agent}/orchestrator/activity-bus.mjs +0 -0
  761. /package/src/{agent → runtime/agent}/orchestrator/providers/anthropic-betas.mjs +0 -0
  762. /package/src/{agent → runtime/agent}/orchestrator/session/abort-lookup.mjs +0 -0
  763. /package/src/{agent → runtime/agent}/orchestrator/session/cache/post-edit-marks.mjs +0 -0
  764. /package/src/{agent → runtime/agent}/orchestrator/session/cache/scoped-cache-outcome.mjs +0 -0
  765. /package/src/{agent → runtime/agent}/orchestrator/session/cache/util.mjs +0 -0
  766. /package/src/{agent → runtime/agent}/orchestrator/session/read-dedup.mjs +0 -0
  767. /package/src/{agent → runtime/agent}/orchestrator/session/save-session-worker.mjs +0 -0
  768. /package/src/{agent → runtime/agent}/orchestrator/smart-bridge/session-builder.mjs +0 -0
  769. /package/src/{agent → runtime/agent}/orchestrator/tools/bash-policy-scan.mjs +0 -0
  770. /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/advisory-lock.mjs +0 -0
  771. /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/atomic-write.mjs +0 -0
  772. /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/binary-file.mjs +0 -0
  773. /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/cache-layers.mjs +0 -0
  774. /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/cwd-utils.mjs +0 -0
  775. /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/device-paths.mjs +0 -0
  776. /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/diagnostics-tool.mjs +0 -0
  777. /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/diff-utils.mjs +0 -0
  778. /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/fs-reachability.mjs +0 -0
  779. /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/grep-formatting.mjs +0 -0
  780. /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/hash-utils.mjs +0 -0
  781. /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/list-formatting.mjs +0 -0
  782. /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/open-config-tool.mjs +0 -0
  783. /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/path-locks.mjs +0 -0
  784. /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/path-utils.mjs +0 -0
  785. /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/read-args.mjs +0 -0
  786. /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/read-batch.mjs +0 -0
  787. /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/read-constants.mjs +0 -0
  788. /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/read-image-resize.mjs +0 -0
  789. /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/read-image.mjs +0 -0
  790. /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/read-lines.mjs +0 -0
  791. /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/read-mode-tool.mjs +0 -0
  792. /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/read-range-index.mjs +0 -0
  793. /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/read-ranges.mjs +0 -0
  794. /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/read-special-files.mjs +0 -0
  795. /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/read-tool.mjs +0 -0
  796. /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/read-windows.mjs +0 -0
  797. /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/shell-analysis.mjs +0 -0
  798. /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/shell-output.mjs +0 -0
  799. /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/snapshot-helpers.mjs +0 -0
  800. /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/snapshot-validation.mjs +0 -0
  801. /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/text-stats.mjs +0 -0
  802. /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/windows-roots.mjs +0 -0
  803. /package/src/{agent → runtime/agent}/orchestrator/tools/code-graph-prewarm-worker.mjs +0 -0
  804. /package/src/{agent → runtime/agent}/orchestrator/tools/env-scrub.mjs +0 -0
  805. /package/src/{agent → runtime/agent}/orchestrator/tools/mutation-content-cache.mjs +0 -0
  806. /package/src/{agent → runtime/agent}/orchestrator/tools/mutation-planner.mjs +0 -0
  807. /package/src/{agent → runtime/agent}/orchestrator/tools/next-call-utils.mjs +0 -0
  808. /package/src/{agent → runtime/agent}/orchestrator/tools/result-compression.mjs +0 -0
  809. /package/src/{agent → runtime/agent}/orchestrator/tools/shell-exec-policy.mjs +0 -0
  810. /package/src/{agent → runtime/agent}/orchestrator/tools/shell-policy-danger-target.mjs +0 -0
  811. /package/src/{agent → runtime/agent}/orchestrator/tools/shell-policy.mjs +0 -0
  812. /package/src/{channels → runtime/channels}/lib/cli-worker-host.mjs +0 -0
  813. /package/src/{channels → runtime/channels}/lib/config-lock.mjs +0 -0
  814. /package/src/{channels → runtime/channels}/lib/event-queue.mjs +0 -0
  815. /package/src/{channels → runtime/channels}/lib/executor.mjs +0 -0
  816. /package/src/{channels → runtime/channels}/lib/format.mjs +0 -0
  817. /package/src/{channels → runtime/channels}/lib/interaction-workflows.mjs +0 -0
  818. /package/src/{channels → runtime/channels}/lib/memory-client.mjs +0 -0
  819. /package/src/{channels → runtime/channels}/lib/session-control.mjs +0 -0
  820. /package/src/{channels → runtime/channels}/lib/settings.mjs +0 -0
  821. /package/src/{channels → runtime/channels}/lib/whisper-server.mjs +0 -0
  822. /package/src/{memory → runtime/memory}/lib/agent-ipc.mjs +0 -0
  823. /package/src/{memory → runtime/memory}/lib/bridge-trace-queries.mjs +0 -0
  824. /package/src/{memory → runtime/memory}/lib/llm-worker-host.mjs +0 -0
  825. /package/src/{memory → runtime/memory}/lib/memory-cycle.mjs +0 -0
  826. /package/src/{memory → runtime/memory}/lib/memory-extraction.mjs +0 -0
  827. /package/src/{memory → runtime/memory}/lib/memory-maintenance-store.mjs +0 -0
  828. /package/src/{memory → runtime/memory}/lib/memory-recall-id-patch.mjs +0 -0
  829. /package/src/{memory → runtime/memory}/lib/memory-recall-read-query.mjs +0 -0
  830. /package/src/{memory → runtime/memory}/lib/memory-recall-scope-filter.mjs +0 -0
  831. /package/src/{memory → runtime/memory}/lib/memory-retrievers.mjs +0 -0
  832. /package/src/{memory → runtime/memory}/lib/memory-score.mjs +0 -0
  833. /package/src/{memory → runtime/memory}/lib/memory-text-utils.mjs +0 -0
  834. /package/src/{memory → runtime/memory}/lib/model-profile.mjs +0 -0
  835. /package/src/{memory → runtime/memory}/lib/project-id-resolver.mjs +0 -0
  836. /package/src/{search → runtime/search}/lib/cache.mjs +0 -0
  837. /package/src/{search → runtime/search}/lib/formatter.mjs +0 -0
  838. /package/src/{search → runtime/search}/lib/state.mjs +0 -0
  839. /package/src/{shared → runtime/shared}/abort-controller.mjs +0 -0
  840. /package/src/{shared → runtime/shared}/llm/cost.mjs +0 -0
  841. /package/src/{shared → runtime/shared}/llm/index.mjs +0 -0
  842. /package/src/{shared → runtime/shared}/llm/pid-cleanup.mjs +0 -0
  843. /package/src/{shared → runtime/shared}/llm/usage-log.mjs +0 -0
  844. /package/src/{shared → runtime/shared}/wsl.mjs +0 -0
@@ -0,0 +1,731 @@
1
+ import { closeSync, lstatSync, openSync, readFileSync, readSync, realpathSync, readdirSync, statSync } from 'fs';
2
+ import * as fsPromises from 'fs/promises';
3
+ import { readFile } from 'fs/promises';
4
+ import { extname } from 'path';
5
+ import { normalizeInputPath } from './path-utils.mjs';
6
+ import { findFileByBasename } from './path-diagnostics.mjs';
7
+ import { getReadSnapshot } from './read-snapshot-runtime.mjs';
8
+ import { snapshotCoversFullFile, statMatchesSnapshot } from './snapshot-helpers.mjs';
9
+ import { formatBinaryReadPreview } from './binary-file.mjs';
10
+
11
+ function snapshotBodyWasReturnedByRead(snapshot) {
12
+ return String(snapshot?.source || '').startsWith('read');
13
+ }
14
+
15
+ // Optional context-budget for a whole-file read: `max_lines:N` requests a
16
+ // TIGHTER head+tail elision than the default 600-line / 200+100 cap, to bound
17
+ // lead-context cost when only a glance is needed. Returns null (= default) when
18
+ // unset. No heuristic guessing — the budget is explicit and reuses the existing
19
+ // smartReadTruncate head/tail invariant. (`budget:'compact'` is a SEPARATE,
20
+ // pre-existing knob handled upstream in read-tool.mjs applyCompactReadBudget —
21
+ // it remaps a whole-file read to mode:'count' stats, not head+tail content.)
22
+ function resolveReadBudget(args) {
23
+ const ml = Number(args?.max_lines);
24
+ if (Number.isFinite(ml) && ml > 0) {
25
+ const maxLines = Math.trunc(ml);
26
+ const headLines = Math.max(1, Math.ceil(maxLines * 0.7));
27
+ return { maxLines, headLines, tailLines: Math.max(0, maxLines - headLines) };
28
+ }
29
+ return null;
30
+ }
31
+
32
+ function withSymbolReadNote(text, args) {
33
+ const note = typeof args?._symbolReadNote === 'string' ? args._symbolReadNote.trim() : '';
34
+ if (!note || typeof text !== 'string') return text;
35
+ return `${note}\n\n${text}`;
36
+ }
37
+
38
+ // BOM-only read-encoding detection. Mirrors CC fileRead.ts:34
39
+ // (buffer[0]===0xff && buffer[1]===0xfe -> 'utf16le') / file.ts
40
+ // detectFileEncoding. STRICTLY a leading-BOM rule — no content sniffing
41
+ // and no heuristic fallback.
42
+ // Returns the decoder name plus the BOM byte length to strip before
43
+ // decoding. utf8-with-BOM (EF BB BF) keeps the utf-8 decoder; its leading
44
+ // U+FEFF is stripped for display downstream, so bomLen is reported but not
45
+ // applied for utf8.
46
+ function detectReadEncoding(fullPath) {
47
+ let fd;
48
+ try {
49
+ fd = openSync(fullPath, 'r');
50
+ const head = Buffer.alloc(3);
51
+ const n = readSync(fd, head, 0, 3, 0);
52
+ if (n >= 2 && head[0] === 0xff && head[1] === 0xfe) {
53
+ return { encoding: 'utf16le', bomLen: 2 };
54
+ }
55
+ if (n >= 2 && head[0] === 0xfe && head[1] === 0xff) {
56
+ return { encoding: 'utf16be', bomLen: 2 };
57
+ }
58
+ if (n >= 3 && head[0] === 0xef && head[1] === 0xbb && head[2] === 0xbf) {
59
+ return { encoding: 'utf8', bomLen: 3 };
60
+ }
61
+ return { encoding: 'utf8', bomLen: 0 };
62
+ } catch {
63
+ return { encoding: 'utf8', bomLen: 0 };
64
+ } finally {
65
+ if (fd !== undefined) { try { closeSync(fd); } catch {} }
66
+ }
67
+ }
68
+
69
+ export async function executeSingleReadTool(args, workDir, readStateScope, options = {}, helpers = {}) {
70
+ const {
71
+ appendReadContextAdvisory,
72
+ classifyResultKind,
73
+ extractIpynbText,
74
+ extractPdfText,
75
+ findSimilarFile,
76
+ isBinaryFile,
77
+ isBlockedDevicePath,
78
+ isUncPath,
79
+ isWindowsDevicePath,
80
+ hasUnsafeWin32Component,
81
+ isSpecialFileStat,
82
+ normalizeErrorMessage,
83
+ normalizeOutputPath,
84
+ parseLineLimitArg,
85
+ parseOffsetArg,
86
+ renderReadLine,
87
+ resolveAgainstCwd,
88
+ smartReadTruncate,
89
+ streamReadRange,
90
+ streamSmartReadSummary,
91
+ READ_MAX_OUTPUT_BYTES,
92
+ READ_MAX_SIZE_BYTES,
93
+ READ_SMART_STREAM_MIN_BYTES,
94
+ READ_STREAM_RANGE_MIN_BYTES,
95
+ _cacheGetEntry,
96
+ _cacheSet,
97
+ _hashText,
98
+ _rangeHashesForReadRanges,
99
+ _rangeHashesFromRenderedReadText,
100
+ _rawContentCacheGet,
101
+ _rawContentCacheSet,
102
+ _recordReadSnapshot,
103
+ } = helpers;
104
+ // Normalize path (strip whitespace, expand ~, posix→windows) up front so
105
+ // LLM-injected stray spaces don't trigger an ENOENT retry that pollutes
106
+ // the conversation history and breaks the cache prefix on later turns.
107
+ if (typeof args.path === 'string') args.path = normalizeInputPath(args.path);
108
+ const filePath = args.path;
109
+ if (!filePath)
110
+ return 'Error: path is required.';
111
+ // R1: UNC / SMB share reject (\\server\share, //server/share). Reading
112
+ // these on Windows auto-authenticates to the remote host and leaks the
113
+ // NTLM hash of the current user to any attacker-controlled SMB target.
114
+ // CC parity: FileReadTool.ts:461 rejects the same prefix before stat.
115
+ // Must run before resolveAgainstCwd so a relative path can't be coerced
116
+ // into a UNC share by the cwd resolution.
117
+ if (typeof isUncPath === 'function' && isUncPath(filePath))
118
+ return `Error: cannot read UNC / SMB path (network credential leak risk): ${normalizeOutputPath(filePath)}`;
119
+ // R2: Windows reserved device names (CON / NUL / PRN / AUX / COM[0-9] /
120
+ // LPT[0-9]) and raw-device namespaces (\\.\ and \\?\). These are kernel
121
+ // aliases that never resolve to real files and can hang or grant raw
122
+ // device access regardless of directory.
123
+ if (typeof isWindowsDevicePath === 'function' && isWindowsDevicePath(filePath))
124
+ return `Error: cannot read Windows device path (reserved name or raw-device namespace): ${normalizeOutputPath(filePath)}`;
125
+ // R12: Win32 component guard. Trailing dot/space or embedded ':' in
126
+ // any path component lets Win32 silently resolve to a different file
127
+ // (stripped dot/space) or an NTFS Alternate Data Stream attached to
128
+ // another file, bypassing the string-based device/UNC checks above.
129
+ if (typeof hasUnsafeWin32Component === 'function' && hasUnsafeWin32Component(filePath))
130
+ return `Error: cannot read Windows path with trailing dot/space or NTFS ADS suffix (bypasses device guard): ${normalizeOutputPath(filePath)}`;
131
+ // G6: block device pseudo-files (would hang / produce infinite output).
132
+ if (isBlockedDevicePath(filePath))
133
+ return `Error: cannot read device file (would block or produce infinite output): ${normalizeOutputPath(filePath)}`;
134
+ const fullPath = resolveAgainstCwd(filePath, workDir);
135
+ // R1: re-check the resolved path — `resolveAgainstCwd` could have produced
136
+ // a UNC / Windows device path even when the user-supplied string did not
137
+ // (rare, but possible with custom cwd containing a UNC root).
138
+ if (typeof isUncPath === 'function' && isUncPath(fullPath))
139
+ return `Error: cannot read UNC / SMB path (network credential leak risk): ${normalizeOutputPath(fullPath)}`;
140
+ if (typeof isWindowsDevicePath === 'function' && isWindowsDevicePath(fullPath))
141
+ return `Error: cannot read Windows device path (reserved name or raw-device namespace): ${normalizeOutputPath(fullPath)}`;
142
+ if (typeof hasUnsafeWin32Component === 'function' && hasUnsafeWin32Component(fullPath))
143
+ return `Error: cannot read Windows path with trailing dot/space or NTFS ADS suffix (bypasses device guard): ${normalizeOutputPath(fullPath)}`;
144
+ // Pre-read size cap (Anthropic FileReadTool/limits.ts pattern):
145
+ // throw a small error response when the file is too big rather
146
+ // than truncating to 25K tokens of content. Throw is decisively
147
+ // more token-efficient (Anthropic #21841 reverted truncation).
148
+ // Large-file branch: if offset/limit is provided, stream the
149
+ // requested line window instead of throwing (Task B). Without
150
+ // range args the cap still throws so small-file default path
151
+ // can't be weaponised to pull megabytes by accident.
152
+ const hasOffsetArg = args.offset !== undefined && args.offset !== null;
153
+ const hasLimitArg = args.limit !== undefined && args.limit !== null;
154
+ const hasRangeArgs = hasOffsetArg || hasLimitArg;
155
+ const wantFull = args.full === true;
156
+ const offset = parseOffsetArg(args.offset);
157
+ // full:true bypasses the default 2000-line cap so the whole file
158
+ // can be returned in one call; the byte-cap path below still
159
+ // emits a compact truncation marker when rendered bytes overflow
160
+ // READ_MAX_OUTPUT_BYTES.
161
+ const limit = parseLineLimitArg(args.limit, wantFull ? Infinity : 2000);
162
+ // Context-budget (compact / max_lines) — only meaningful on a whole-file
163
+ // read (no range, not full). Ignored otherwise.
164
+ const _readBudget = (!hasRangeArgs && !wantFull) ? resolveReadBudget(args) : null;
165
+ let st;
166
+ let _statErr;
167
+ try {
168
+ st = statSync(fullPath);
169
+ } catch (err) {
170
+ // Fall through to the existing similar-file recovery path below.
171
+ st = null;
172
+ _statErr = err;
173
+ }
174
+ if (st) {
175
+ if (st.isDirectory()) {
176
+ let entries = [];
177
+ try {
178
+ entries = readdirSync(fullPath, { withFileTypes: true })
179
+ .slice(0, 20)
180
+ .map((entry) => `${entry.name}${entry.isDirectory() ? '/' : ''}`);
181
+ } catch { /* best-effort preview */ }
182
+ const preview = entries.length ? `\nentries:\n${entries.map((entry) => `- ${entry}`).join('\n')}` : '';
183
+ return `Error: Directory: ${normalizeOutputPath(filePath)}. Use list/glob to inspect directories; read expects a file.${preview}`;
184
+ }
185
+ // R2: special-file reject AFTER stat. FIFOs, char devices, block
186
+ // devices, and sockets pass a normal stat but reading them either
187
+ // hangs (FIFO with no writer, socket) or produces unbounded output
188
+ // (/dev/zero, /dev/random). Catches arbitrary user paths that point
189
+ // at a special inode (custom mknod, etc.) that the string-based
190
+ // device guard above doesn't know about.
191
+ if (typeof isSpecialFileStat === 'function' && isSpecialFileStat(st))
192
+ return `Error: cannot read special file (FIFO / character / block device / socket): ${normalizeOutputPath(filePath)}`;
193
+ // R1+R2: realpath the resolved path so a symlink → /dev/zero (or any
194
+ // other blocked device, UNC, or Windows reserved name) is caught on
195
+ // the REAL target, not the symlink name. lstatSync detects whether
196
+ // the entry IS a symlink first so realpathSync is only called when
197
+ // it would actually differ — saves a syscall on the common case.
198
+ try {
199
+ const _lst = lstatSync(fullPath);
200
+ if (_lst && typeof _lst.isSymbolicLink === 'function' && _lst.isSymbolicLink()) {
201
+ let _realTarget = null;
202
+ try { _realTarget = realpathSync(fullPath); } catch { _realTarget = null; }
203
+ if (_realTarget && _realTarget !== fullPath) {
204
+ if (isBlockedDevicePath(_realTarget))
205
+ return `Error: cannot read device file via symlink (would block or produce infinite output): ${normalizeOutputPath(filePath)} → ${normalizeOutputPath(_realTarget)}`;
206
+ if (typeof isUncPath === 'function' && isUncPath(_realTarget))
207
+ return `Error: cannot read UNC / SMB path via symlink (network credential leak risk): ${normalizeOutputPath(filePath)} → ${normalizeOutputPath(_realTarget)}`;
208
+ if (typeof isWindowsDevicePath === 'function' && isWindowsDevicePath(_realTarget))
209
+ return `Error: cannot read Windows device path via symlink (reserved name or raw-device namespace): ${normalizeOutputPath(filePath)} → ${normalizeOutputPath(_realTarget)}`;
210
+ // Re-run the special-file stat on the real target — the
211
+ // symlink itself was already checked above via `st`, but
212
+ // the target stat could differ from the link stat in
213
+ // pathological cases (replaced under us).
214
+ try {
215
+ const _rst = statSync(_realTarget);
216
+ if (typeof isSpecialFileStat === 'function' && isSpecialFileStat(_rst))
217
+ return `Error: cannot read special file via symlink (FIFO / character / block device / socket): ${normalizeOutputPath(filePath)} → ${normalizeOutputPath(_realTarget)}`;
218
+ } catch { /* if the target is gone, let the normal path surface ENOENT */ }
219
+ }
220
+ }
221
+ } catch { /* lstat failure is non-fatal; the original `st` is authoritative */ }
222
+ }
223
+ if (!st) {
224
+ const err = _statErr;
225
+ const similar = findSimilarFile(fullPath);
226
+ let hint = similar ? ` Did you mean "${normalizeOutputPath(similar)}"?` : '';
227
+ // Right-name / wrong-directory miss: findSimilarFile only checks the
228
+ // same dir. Locate the basename elsewhere in the tree and name the real
229
+ // path(s) directly — the route a model would otherwise reconstruct with
230
+ // a grep/glob storm.
231
+ if (!similar) {
232
+ const elsewhere = findFileByBasename(workDir, fullPath);
233
+ if (elsewhere.length) {
234
+ hint = ` Not found at this path; the same filename exists at: ${elsewhere.map((p) => `"${normalizeOutputPath(p)}"`).join(', ')}. Read that path directly.`;
235
+ }
236
+ }
237
+ const _rawMsg = err instanceof Error ? err.message : String(err);
238
+ const _safeMsg = normalizeErrorMessage(_rawMsg, workDir);
239
+ return `Error: ${_safeMsg}${hint}`;
240
+ }
241
+ // MEDIA-WINS: .pdf/.ipynb dispatch runs BEFORE any cache/snapshot fast
242
+ // path. A media file previously read as text can carry a stale result-
243
+ // cache or read-snapshot entry; returning that cached TEXT instead of the
244
+ // fresh media shape (PDF document block / ipynb content-block array) is
245
+ // wrong — media must win. Hoisted here, right after the UNC/device/ADS
246
+ // guards + stat but before _cacheGetEntry / getReadSnapshot, so neither
247
+ // fast path can short-circuit a media read. extractPdfText /
248
+ // extractIpynbText own their size handling internally (PDF >20MB → text
249
+ // fallback via PDF_DOCUMENT_MAX_BYTES, page-range filter, ipynb range
250
+ // refusal), so this single early dispatch supersedes the old >10MiB media
251
+ // lines and the old post-cache media lines without bypassing those
252
+ // decisions. mediaTextOnly (batch dispatcher) must produce a flat string,
253
+ // never a content-block object, so a batch aggregate's String()+join can't
254
+ // stringify it to "[object Object]"; scalar reads leave it unset and get
255
+ // the rich block shapes.
256
+ const _mediaTextOnly = options?.mediaTextOnly === true;
257
+ const _mediaExt = extname(fullPath).toLowerCase();
258
+ if (_mediaExt === '.pdf') return extractPdfText(fullPath, args.pages, { maxOutputBytes: READ_MAX_OUTPUT_BYTES, textOnly: _mediaTextOnly });
259
+ if (_mediaExt === '.ipynb') {
260
+ const _ipynbOut = await extractIpynbText(fullPath, { maxOutputBytes: READ_MAX_OUTPUT_BYTES, hasRangeArgs: hasRangeArgs || args.line !== undefined, textOnly: _mediaTextOnly });
261
+ // Record a full-file read snapshot for cache/read-state consistency.
262
+ // Skipped on an Error string (no real read).
263
+ if (typeof _ipynbOut !== 'string' || !_ipynbOut.startsWith('Error:')) {
264
+ _recordReadSnapshot(fullPath, st, readStateScope, { source: 'read', replaceExisting: true });
265
+ }
266
+ return _ipynbOut;
267
+ }
268
+ const cacheKey = `read|${fullPath}|${st.mtimeMs}|${st.size}|${hasOffsetArg ? offset : 'd'}|${hasLimitArg ? limit : 'd'}|${wantFull ? 'f' : 's'}|${_readBudget ? `b${_readBudget.maxLines}` : 'd'}`;
269
+ // Race-guard helper: same-mtime same-size rapid rewrite (NTFS / exFAT 1 s
270
+ // resolution) can pass mtimeMs+size yet differ in content. When the cache
271
+ // entry stores a contentPrefixHash, recompute the current prefix and bail
272
+ // to a fresh read on mismatch. Helper kept local (not hoisted) so it can
273
+ // close over fullPath and st without an extra arg.
274
+ const _readPrefixHashForCacheGuard = () => {
275
+ try {
276
+ if (st.size <= 65536) {
277
+ return _hashText(readFileSync(fullPath, 'utf-8'));
278
+ }
279
+ const _fd = openSync(fullPath, 'r');
280
+ try {
281
+ const _buf = Buffer.allocUnsafe(65536);
282
+ const _n = readSync(_fd, _buf, 0, 65536, 0);
283
+ return _hashText(_buf.subarray(0, _n));
284
+ } finally { try { closeSync(_fd); } catch {} }
285
+ } catch { return ''; }
286
+ };
287
+ const cachedEntry = _cacheGetEntry(cacheKey);
288
+ if (cachedEntry !== null) {
289
+ let _entryStillValid = true;
290
+ // Single-pass cache-hit guard. The cache key already pins
291
+ // mtimeMs+size, so a hit means only a same-mtime/same-size rewrite
292
+ // (NTFS / exFAT 1 s resolution) could differ — caught by re-hashing
293
+ // the on-disk body. Previously this ran as two passes: a 64KiB
294
+ // prefix-hash guard, then a separate full-content guard that
295
+ // re-read the whole file again. For ≤64KiB files contentPrefixHash
296
+ // and contentHash are computed over the identical body at the read
297
+ // result-cache set sites (:360 and :367) and are byte-equal by
298
+ // construction, so the two passes read+hashed the same bytes twice
299
+ // for nothing. Collapse to one read + one hash per hit.
300
+ const _prefixHash = cachedEntry.contentPrefixHash;
301
+ const _snapHash = cachedEntry.readSnapshotMeta?.contentHash;
302
+ if (_prefixHash || _snapHash) {
303
+ if (st.size <= 65536) {
304
+ // ≤64KiB: one full-body read validates whichever hash the
305
+ // entry carries — prefix == full at this size. Prefer the
306
+ // exact full contentHash when present, else the prefix hash
307
+ // (also full-body here). A read failure drops to fresh read.
308
+ try {
309
+ const _freshHash = _hashText(readFileSync(fullPath, 'utf-8'));
310
+ const _expect = _snapHash || _prefixHash;
311
+ if (!_freshHash || _freshHash !== _expect) _entryStillValid = false;
312
+ } catch { _entryStillValid = false; }
313
+ } else if (_prefixHash) {
314
+ // >64KiB: contentHash may still be stored (full-file reads
315
+ // keep it up to the 10MB read cap), but validating it here
316
+ // means a synchronous full-content sha that blocks the main
317
+ // thread on a multi-megabyte body every cache check — so the
318
+ // validation, not the storage, is size-gated: for >64KiB only
319
+ // the 64KiB head prefix is checked. It catches same-mtime/
320
+ // same-size rewrites within the first 64KiB (the common case);
321
+ // writes through edit/apply_patch/write invalidate by path,
322
+ // and shell mutationMode='global' wipes both builtin +
323
+ // code-graph caches, bounding stale risk past the head.
324
+ const _curHash = _readPrefixHashForCacheGuard();
325
+ if (!_curHash || _curHash !== _prefixHash) _entryStillValid = false;
326
+ }
327
+ }
328
+ if (_entryStillValid) {
329
+ // Cross-session stub guard: RESULT_CACHE is process-global, so a
330
+ // cache hit can be an entry SET BY ANOTHER SESSION whose body this
331
+ // conversation never received. The file_unchanged stub assumes the
332
+ // full body is already in a prior tool_result of THIS session — only
333
+ // true when a session-scoped snapshot exists, matches the current
334
+ // stat, and was itself produced by a body-returning read. Probe that
335
+ // BEFORE recording the snapshot below (which would otherwise mark the
336
+ // file as body-returned and mask the cross-session case). A null
337
+ // readStateScope has no session evidence, so it always fails the gate
338
+ // and falls through to the full cached body.
339
+ const _sessionSnap = readStateScope ? getReadSnapshot(fullPath, readStateScope) : null;
340
+ const _stubBodyAlreadySent = !!_sessionSnap
341
+ && statMatchesSnapshot(st, _sessionSnap)
342
+ && snapshotBodyWasReturnedByRead(_sessionSnap)
343
+ // Range-coverage guard: snapshotBodyWasReturnedByRead only
344
+ // proves SOME body was returned, not WHICH lines. A session
345
+ // that read just lines 1-10 (ranged, source 'read', stat
346
+ // matches) must NOT get an unchanged stub on a later full
347
+ // read whose body it never saw — another session's full read
348
+ // populated the global cache. For a full-file read require
349
+ // the session snapshot to cover the whole file. For a ranged
350
+ // read there is no requested-window-coverage helper
351
+ // (snapshotRangesCoverAllLines checks ALL lines, not the
352
+ // window), so conservatively require full coverage there too:
353
+ // failing the gate only falls through to the full cached body
354
+ // (a few extra tokens), which is never incorrect. The
355
+ // path-snapshot fallback at the size-gated branch below
356
+ // already requires snapshotCoversFullFile for this reason.
357
+ && snapshotCoversFullFile(_sessionSnap);
358
+ _recordReadSnapshot(fullPath, st, readStateScope, cachedEntry.readSnapshotMeta || { source: 'read_cached' });
359
+ // G6: file_unchanged stub. The full body is already in the
360
+ // prior tool_result; resending it wastes cache_creation
361
+ // tokens (Claude Code upstream measured ~18% on Read calls).
362
+ // The stub keeps the snapshot tracking intact (Edit
363
+ // validation still works) while collapsing the response
364
+ // payload. Falls back to the full body when the cached
365
+ // value is itself a stub-incompatible error string, or when
366
+ // this session has no body-returned snapshot proving it saw the
367
+ // body (cross-session cache hit — emit the full cached body so
368
+ // the recorded snapshot above is honestly body-returned here).
369
+ const _cachedVal = cachedEntry.value;
370
+ if (typeof _cachedVal === 'string' && classifyResultKind(_cachedVal) !== 'error') {
371
+ if (_stubBodyAlreadySent && options?.suppressReadUnchangedStub !== true) {
372
+ return withSymbolReadNote(`[file unchanged: ${normalizeOutputPath(filePath)}]`, args);
373
+ }
374
+ }
375
+ return withSymbolReadNote(_cachedVal, args);
376
+ }
377
+ // Race detected — fall through to fresh read below.
378
+ }
379
+ // Path-snapshot fallback: exact cache-key hits above can still collapse
380
+ // duplicate reads. Size-gate the fallback so a missing cache entry never
381
+ // hashes a large file just to emit an unchanged stub.
382
+ if (!hasRangeArgs && st.size <= 65536) {
383
+ const _snap = getReadSnapshot(fullPath, readStateScope);
384
+ if (_snap
385
+ && statMatchesSnapshot(st, _snap)
386
+ && snapshotCoversFullFile(_snap)
387
+ && snapshotBodyWasReturnedByRead(_snap)
388
+ && typeof _snap.contentHash === 'string'
389
+ && _snap.contentHash) {
390
+ let _diskHash = '';
391
+ try { _diskHash = _hashText(readFileSync(fullPath, 'utf-8')); } catch {}
392
+ if (_diskHash && _diskHash === _snap.contentHash) {
393
+ if (options?.suppressReadUnchangedStub !== true) {
394
+ return withSymbolReadNote(`[file unchanged: ${normalizeOutputPath(filePath)}]`, args);
395
+ }
396
+ }
397
+ }
398
+ }
399
+ // BOM-only encoding detection runs BEFORE the >10MiB size branch so a
400
+ // large UTF-16LE+BOM file is recognized as text up front and routed to
401
+ // the bounded in-memory utf16le path below, never mis-decoded as utf-8
402
+ // or rejected by the utf-8 streaming/binary branch (Bug 1).
403
+ const _readEnc = detectReadEncoding(fullPath);
404
+ // UTF-16 (LE or BE) reads share one constraint: the streaming/binary
405
+ // paths decode chunks as utf-8, so a BOM-flagged UTF-16 file must route
406
+ // to the bounded in-memory decode below regardless of byte order.
407
+ const _isUtf16 = _readEnc.encoding === 'utf16le' || _readEnc.encoding === 'utf16be';
408
+ if (st.size > READ_MAX_SIZE_BYTES) {
409
+ // .pdf/.ipynb were already dispatched up front (MEDIA-WINS), so this
410
+ // >10MiB branch only handles the non-media text path from here on.
411
+ // utf16le bound (Bug 2): utf16le reads route through a single
412
+ // in-memory full read+decode+split (streamReadRange is gated off
413
+ // for utf16le because it decodes chunks as utf-8). Keep that one
414
+ // path but cap it — a >10MiB utf16le file would otherwise be
415
+ // unbounded in memory or mis-routed into the utf-8 stream/binary
416
+ // branch. Refuse so utf16le memory is always <= READ_MAX_SIZE_BYTES.
417
+ if (_isUtf16) {
418
+ return `Error: UTF-16 file size ${st.size} bytes exceeds ${READ_MAX_SIZE_BYTES} bytes; utf16 ranged reads are bounded — convert to UTF-8 or narrow the range.`;
419
+ }
420
+ if (!hasRangeArgs) {
421
+ return `Error: file size ${st.size} bytes exceeds ${READ_MAX_SIZE_BYTES}-byte cap.`;
422
+ }
423
+ if (isBinaryFile(fullPath, st.size)) {
424
+ const { text, snapshotMeta } = formatBinaryReadPreview(fullPath, normalizeOutputPath(filePath), st.size);
425
+ _recordReadSnapshot(fullPath, st, readStateScope, snapshotMeta);
426
+ _cacheSet(cacheKey, text, { paths: [fullPath], readSnapshotMeta: snapshotMeta });
427
+ return withSymbolReadNote(text, args);
428
+ }
429
+ try {
430
+ const _streamRes = await streamReadRange(fullPath, offset, limit, st, { displayPath: filePath });
431
+ const out = _streamRes.text;
432
+ // W1 H: snapshot only emitted line bounds, not the
433
+ // requested window — byte-cap truncation can stop short.
434
+ const _emittedRanges = (_streamRes.firstEmitted && _streamRes.lastEmitted)
435
+ ? [{ startLine: _streamRes.firstEmitted, endLine: _streamRes.lastEmitted }]
436
+ : [];
437
+ const snapshotMeta = {
438
+ source: 'read',
439
+ ranges: _emittedRanges,
440
+ // D-R1-1: rangeHash covers the exact text returned so
441
+ // _isSnapshotStale can detect same-mtime+same-size
442
+ // rewrites within the read window at edit time.
443
+ // Fix J-1 (b): hash raw line text, not rendered
444
+ // "N\ttext" form, to match _isSnapshotStale which
445
+ // hashes _lines.slice().join('\n') (raw content).
446
+ // Strip the rendered line-number prefix from each
447
+ // returned line before hashing so both sides match.
448
+ rangeHashes: _rangeHashesFromRenderedReadText(out, _emittedRanges),
449
+ };
450
+ // Compute prefix hash for race-guard on next cache hit.
451
+ // Async to avoid blocking the event loop on a 64KB read
452
+ // for every large-file streaming path.
453
+ const _streamPrefixHash = _streamRes.prefixHash || await (async () => {
454
+ try {
455
+ if (st.size <= 65536) return _hashText(await readFile(fullPath, 'utf-8'));
456
+ const fh = await fsPromises.open(fullPath, 'r');
457
+ try {
458
+ const _buf = Buffer.allocUnsafe(65536);
459
+ const _readRes = await fh.read(_buf, 0, 65536, 0);
460
+ return _hashText(_buf.subarray(0, _readRes.bytesRead));
461
+ } finally { await fh.close().catch(() => {}); }
462
+ } catch { return ''; }
463
+ })();
464
+ _cacheSet(cacheKey, out, { paths: [fullPath], readSnapshotMeta: snapshotMeta, contentPrefixHash: _streamPrefixHash });
465
+ _recordReadSnapshot(fullPath, st, readStateScope, snapshotMeta);
466
+ return withSymbolReadNote(out, args);
467
+ } catch (err) {
468
+ return `Error: ${normalizeErrorMessage(err instanceof Error ? err.message : String(err))}`;
469
+ }
470
+ }
471
+ // Non-text special formats (.pdf/.ipynb) were intercepted up front
472
+ // (MEDIA-WINS, before the cache/snapshot fast paths), so the binary check
473
+ // below only ever sees the non-media text path.
474
+ // BOM-only encoding peek BEFORE the binary/NUL check. A UTF-16LE+BOM
475
+ // file is full of 0x00 bytes (the high byte of every ASCII char), so
476
+ // isBinaryFile would wrongly reject it. The FF FE BOM is an
477
+ // unambiguous TEXT signal, so classify it as utf16le up front and skip
478
+ // NUL rejection. (_readEnc was detected above, before the >10MiB size
479
+ // branch, so the large-file path can classify utf16le.)
480
+ if (!_isUtf16 && isBinaryFile(fullPath, st.size)) {
481
+ const { text, snapshotMeta } = formatBinaryReadPreview(fullPath, normalizeOutputPath(filePath), st.size);
482
+ _recordReadSnapshot(fullPath, st, readStateScope, snapshotMeta);
483
+ _cacheSet(cacheKey, text, { paths: [fullPath], readSnapshotMeta: snapshotMeta });
484
+ return withSymbolReadNote(text, args);
485
+ }
486
+ // Whole-file reads above READ_WHOLE_FILE_MAX_BYTES use stream smart-elide
487
+ // (then READ_MAX_OUTPUT_BYTES truncation) instead of refusing. Absolute
488
+ // in-memory ceiling remains READ_MAX_SIZE_BYTES (10 MiB) above.
489
+ // The streaming paths (smart-summary + range) decode chunks as utf-8;
490
+ // a utf16le file must instead fall through to the encoding-aware
491
+ // in-memory regular read below, which still runs smartReadTruncate so
492
+ // smart-elide stays intact. utf-8 keeps the streaming fast path.
493
+ if (!_isUtf16 && !hasRangeArgs && !wantFull && st.size >= READ_SMART_STREAM_MIN_BYTES) {
494
+ try {
495
+ const _streamSmart = typeof streamSmartReadSummary === 'function'
496
+ ? await streamSmartReadSummary(fullPath, st, 'read_smart_stream')
497
+ : null;
498
+ if (_streamSmart?.text) {
499
+ let out = _streamSmart.text;
500
+ // Honor a compact/max_lines budget on a large file: the stream
501
+ // already elided to head 200/tail 100; re-apply the tighter
502
+ // head+tail so the lead sees only the requested glance.
503
+ if (_readBudget) {
504
+ // Use the file's REAL line count from the stream pass
505
+ // (snapshotMeta.fileLineCount — the result has no top-level
506
+ // totalLines), not the already-elided output's row count: the
507
+ // re-budget marker otherwise reports "[TRUNCATED - 301 lines]"
508
+ // for a 3800-line file.
509
+ const _rebud = smartReadTruncate(out, _streamSmart.snapshotMeta?.fileLineCount || out.split('\n').length, st.size, filePath, _readBudget);
510
+ if (_rebud?.truncated) out = _rebud.text;
511
+ }
512
+ const snapshotMeta = _streamSmart.snapshotMeta || {
513
+ source: 'read_smart_stream',
514
+ ranges: [],
515
+ };
516
+ const _streamPrefixHash = _streamSmart.prefixHash || await (async () => {
517
+ try {
518
+ if (st.size <= 65536) return _hashText(await readFile(fullPath, 'utf-8'));
519
+ const fh = await fsPromises.open(fullPath, 'r');
520
+ try {
521
+ const _buf = Buffer.allocUnsafe(65536);
522
+ const _readRes = await fh.read(_buf, 0, 65536, 0);
523
+ return _hashText(_buf.subarray(0, _readRes.bytesRead));
524
+ } finally { await fh.close().catch(() => {}); }
525
+ } catch { return ''; }
526
+ })();
527
+ _cacheSet(cacheKey, out, { paths: [fullPath], readSnapshotMeta: snapshotMeta, contentPrefixHash: _streamPrefixHash });
528
+ _recordReadSnapshot(fullPath, st, readStateScope, snapshotMeta);
529
+ return withSymbolReadNote(out, args);
530
+ }
531
+ } catch {
532
+ // Fall through to the regular read path; it still enforces output caps.
533
+ }
534
+ }
535
+ if (!_isUtf16 && hasRangeArgs && !wantFull && st.size > READ_STREAM_RANGE_MIN_BYTES) {
536
+ try {
537
+ const _streamRes = await streamReadRange(fullPath, offset, limit, st, { displayPath: filePath });
538
+ const out = _streamRes.text;
539
+ const _emittedRanges = (_streamRes.firstEmitted && _streamRes.lastEmitted)
540
+ ? [{ startLine: _streamRes.firstEmitted, endLine: _streamRes.lastEmitted }]
541
+ : [];
542
+ const snapshotMeta = {
543
+ source: 'read_stream_range',
544
+ ranges: _emittedRanges,
545
+ rangeHashes: _rangeHashesFromRenderedReadText(out, _emittedRanges),
546
+ };
547
+ const _streamPrefixHash = _streamRes.prefixHash || await (async () => {
548
+ try {
549
+ if (st.size <= 65536) return _hashText(await readFile(fullPath, 'utf-8'));
550
+ const fh = await fsPromises.open(fullPath, 'r');
551
+ try {
552
+ const _buf = Buffer.allocUnsafe(65536);
553
+ const _readRes = await fh.read(_buf, 0, 65536, 0);
554
+ return _hashText(_buf.subarray(0, _readRes.bytesRead));
555
+ } finally { await fh.close().catch(() => {}); }
556
+ } catch { return ''; }
557
+ })();
558
+ _cacheSet(cacheKey, out, { paths: [fullPath], readSnapshotMeta: snapshotMeta, contentPrefixHash: _streamPrefixHash });
559
+ _recordReadSnapshot(fullPath, st, readStateScope, snapshotMeta);
560
+ return withSymbolReadNote(out, args);
561
+ } catch (err) {
562
+ return `Error: ${normalizeErrorMessage(err instanceof Error ? err.message : String(err))}`;
563
+ }
564
+ }
565
+ try {
566
+ const cachedRawBuf = _rawContentCacheGet ? _rawContentCacheGet(fullPath, st) : null;
567
+ const rawBuf = cachedRawBuf || await readFile(fullPath);
568
+ // Encoding-aware decode (fresh read AND raw-content cache hit both
569
+ // flow through here). For a BOM-flagged UTF-16LE file, strip the
570
+ // 2-byte FF FE BOM and decode as utf16le so it reverses the write
571
+ // tool's preservation; utf-8 stays byte-identical to before (the
572
+ // leading U+FEFF of a utf8-BOM file is stripped later at the
573
+ // line[0] charCodeAt check for display).
574
+ // UTF-16BE has no Node string encoding: swap byte pairs to LE (swap16
575
+ // needs an even length) then decode as utf16le, so a BE file reverses
576
+ // the same way a LE file does.
577
+ let content;
578
+ if (_readEnc.encoding === 'utf16le') {
579
+ content = rawBuf.subarray(_readEnc.bomLen).toString('utf16le');
580
+ } else if (_readEnc.encoding === 'utf16be') {
581
+ const _body = rawBuf.subarray(_readEnc.bomLen);
582
+ const _even = _body.length & ~1;
583
+ content = Buffer.from(_body.subarray(0, _even)).swap16().toString('utf16le');
584
+ } else {
585
+ content = rawBuf.toString('utf-8');
586
+ }
587
+ // W1 M: re-stat after the async readFile so a concurrent
588
+ // Write that landed during the read is detected before
589
+ // the cache + snapshot record stale bytes.
590
+ let _stPostRead;
591
+ let _readStableForRawCache = true;
592
+ if (cachedRawBuf) {
593
+ _stPostRead = st;
594
+ } else {
595
+ try { _stPostRead = await fsPromises.stat(fullPath); } catch { _stPostRead = st; }
596
+ if (_stPostRead.mtimeMs !== st.mtimeMs || _stPostRead.size !== st.size) {
597
+ st = _stPostRead;
598
+ _readStableForRawCache = false;
599
+ }
600
+ }
601
+ const lines = content.split(/\r?\n/);
602
+ if (lines.length > 0 && lines[0].charCodeAt(0) === 0xFEFF) lines[0] = lines[0].slice(1);
603
+ // wc-l compatible line count: a trailing newline ends a line, it
604
+ // does not start a new empty one. Display count must match the
605
+ // count emitted by mode:"count" so footer and count agree.
606
+ const lineCount = lines.length > 0 && lines[lines.length - 1] === '' ? lines.length - 1 : lines.length;
607
+ const renderEnd = (!hasRangeArgs && !wantFull)
608
+ ? lineCount
609
+ : Math.min(offset + limit, lineCount);
610
+ const sliced = lines.slice(offset, renderEnd);
611
+ const rendered = sliced
612
+ .map((line, i) => renderReadLine(offset + i + 1, line, { truncateLongLine: !wantFull }))
613
+ .join('\n');
614
+ // Output byte cap protects against many-line slices that
615
+ // individually pass the file-size check but explode after
616
+ // line-number prefixing.
617
+ let out;
618
+ // W1 H: track lines actually rendered so the snapshot below
619
+ // doesn't mark byte-cap-truncated lines as editable.
620
+ let _renderedLineCount = sliced.length;
621
+ // W1 H: byte-cap truncation drops trailing lines the model never
622
+ // saw. Track it so isFullFileView below records partial coverage
623
+ // (rangeHashes over the visible window) instead of a full-file
624
+ // contentHash — otherwise snapshotCoversFullFile would wrongly
625
+ // green-light an overwrite against bytes the read never returned.
626
+ let _byteCapTruncated = false;
627
+ const smart = (!hasRangeArgs && !wantFull && typeof smartReadTruncate === 'function')
628
+ ? smartReadTruncate(rendered, lineCount, st.size, filePath, _readBudget)
629
+ : null;
630
+ let _smartTruncated = false;
631
+ let _smartVisibleRanges = null;
632
+ if (smart?.truncated) {
633
+ out = smart.text;
634
+ _smartTruncated = true;
635
+ _smartVisibleRanges = Array.isArray(smart.ranges) ? smart.ranges : null;
636
+ _renderedLineCount = 0;
637
+ } else if (Buffer.byteLength(rendered, 'utf8') > READ_MAX_OUTPUT_BYTES) {
638
+ let lo = 0;
639
+ let hi = rendered.length;
640
+ while (lo < hi) {
641
+ const mid = Math.ceil((lo + hi) / 2);
642
+ if (Buffer.byteLength(rendered.slice(0, mid), 'utf8') <= READ_MAX_OUTPUT_BYTES) lo = mid;
643
+ else hi = mid - 1;
644
+ }
645
+ const slice = rendered.slice(0, lo);
646
+ const completeRenderedLines = Math.max(0, slice.split('\n').length - 1);
647
+ _renderedLineCount = completeRenderedLines;
648
+ _byteCapTruncated = true;
649
+ out = slice + `\n\n... [output truncated at ${Math.round(READ_MAX_OUTPUT_BYTES/1024)} KB] ...`;
650
+ } else {
651
+ out = rendered;
652
+ }
653
+ if (hasRangeArgs) {
654
+ if (sliced.length === 0 && offset >= lineCount) {
655
+ out = `(no lines in range; file has ${lineCount} lines)`;
656
+ } else if (_byteCapTruncated) {
657
+ const emittedStart = offset + 1;
658
+ const emittedEnd = offset + _renderedLineCount;
659
+ const capKb = Math.round(READ_MAX_OUTPUT_BYTES / 1024);
660
+ const footer = `[lines ${emittedStart}-${emittedEnd} of ${lineCount}; output truncated at ${capKb} KB${emittedEnd < lineCount ? `; pass offset:${emittedEnd} to continue` : ''}]`;
661
+ out += `${out ? '\n' : ''}${footer}`;
662
+ } else if (Buffer.byteLength(rendered, 'utf8') <= READ_MAX_OUTPUT_BYTES) {
663
+ const emittedStart = offset + 1;
664
+ const emittedEnd = offset + sliced.length;
665
+ const footer = `[lines ${emittedStart}-${emittedEnd} of ${lineCount}${emittedEnd < lineCount ? `; pass offset:${emittedEnd} to continue` : ''}]`;
666
+ out += `${out ? '\n' : ''}${footer}`;
667
+ }
668
+ }
669
+ // Smart cap. Only engages when the caller asked for
670
+ // the default read (no offset/limit, full:false) AND the file
671
+ // is over the line/byte threshold. Explicit ranges always see
672
+ // byte-exact output.
673
+ // W1 H: smart-middle elision drops lines the model never
674
+ // saw — don't claim full-file coverage when it triggered.
675
+ if (!hasRangeArgs && !wantFull) {
676
+ if (!_smartTruncated && content.length > 0) {
677
+ out = appendReadContextAdvisory(out, { filePath, lineCount, bytes: st.size });
678
+ }
679
+ }
680
+ // CC parity: empty file gets a system-reminder instead of
681
+ // a bare `1│` line. The reminder makes the empty-state
682
+ // explicit so the agent doesn't assume content was elided.
683
+ if (content.length === 0) {
684
+ // W1 M: filename can contain `<` or `</system-reminder>`
685
+ // sequences; XML-escape before interpolation so a hostile
686
+ // path can't terminate the envelope and inject markup.
687
+ const _safePath = normalizeOutputPath(filePath)
688
+ .replace(/&/g, '&amp;')
689
+ .replace(/</g, '&lt;')
690
+ .replace(/>/g, '&gt;');
691
+ out = `<system-reminder>File exists but has empty contents: ${_safePath}</system-reminder>`;
692
+ }
693
+ const isFullFileView = offset === 0 && offset + limit >= lineCount && !_smartTruncated && !_byteCapTruncated;
694
+ const _visibleRanges = _smartTruncated && _smartVisibleRanges
695
+ ? _smartVisibleRanges
696
+ : (_renderedLineCount > 0
697
+ ? [{ startLine: offset + 1, endLine: Math.min(lineCount, offset + _renderedLineCount) }]
698
+ : []);
699
+ const _rangeHashes = !isFullFileView ? _rangeHashesForReadRanges(content, _visibleRanges) : [];
700
+ // Hash the full body once when the whole file is in view: both the
701
+ // snapshot contentHash and (for ≤64KiB) the race-guard prefix hash
702
+ // are SHA-256 over the identical `content`, so computing it twice
703
+ // here was pure duplicate CPU on the common small full-file read.
704
+ const _fullContentHash = isFullFileView ? _hashText(content) : '';
705
+ const snapshotMeta = {
706
+ source: 'read',
707
+ fileLineCount: lineCount,
708
+ ranges: isFullFileView
709
+ ? [{ startLine: 1, endLine: Infinity }]
710
+ : _visibleRanges,
711
+ ...(isFullFileView ? { contentHash: _fullContentHash } : {}),
712
+ ...(_rangeHashes.length > 0 ? { rangeHashes: _rangeHashes } : {}),
713
+ };
714
+ // Race-guard prefix hash. content is the full file body here
715
+ // (regular branch, st.size <= READ_MAX_SIZE_BYTES). For files
716
+ // ≤64KiB the prefix hash equals the full-content hash, so reuse
717
+ // _fullContentHash when it was computed; otherwise hash the 64KiB
718
+ // head (sufficient to detect a same-mtime / same-size rewrite of
719
+ // any bytes within the first 64KiB — the common case).
720
+ const _regPrefixHash = (content.length <= 65536 && _fullContentHash)
721
+ ? _fullContentHash
722
+ : _hashText(content.length <= 65536 ? content : content.slice(0, 65536));
723
+ _cacheSet(cacheKey, out, { paths: [fullPath], readSnapshotMeta: snapshotMeta, contentPrefixHash: _regPrefixHash });
724
+ if (_readStableForRawCache) _rawContentCacheSet(fullPath, st, rawBuf);
725
+ _recordReadSnapshot(fullPath, st, readStateScope, snapshotMeta);
726
+ return withSymbolReadNote(out, args);
727
+ }
728
+ catch (err) {
729
+ return `Error: ${normalizeErrorMessage(err instanceof Error ? err.message : String(err))}`;
730
+ }
731
+ }