@code-yeongyu/senpi 2026.9.15 → 2026.9.16

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 (227) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/dist/core/extensions/builtin/config-reload/index.d.ts.map +1 -1
  3. package/dist/core/extensions/builtin/config-reload/index.js +25 -8
  4. package/dist/core/extensions/builtin/config-reload/index.js.map +1 -1
  5. package/dist/core/extensions/builtin/config-reload/watch-engine.d.ts +4 -5
  6. package/dist/core/extensions/builtin/config-reload/watch-engine.d.ts.map +1 -1
  7. package/dist/core/extensions/builtin/config-reload/watch-engine.js +14 -18
  8. package/dist/core/extensions/builtin/config-reload/watch-engine.js.map +1 -1
  9. package/dist/core/extensions/builtin/config-reload/watch-event-source.d.ts.map +1 -1
  10. package/dist/core/extensions/builtin/config-reload/watch-event-source.js +32 -9
  11. package/dist/core/extensions/builtin/config-reload/watch-event-source.js.map +1 -1
  12. package/dist/core/extensions/builtin/cursor-cli-oauth/catalog-refresh.d.ts +23 -0
  13. package/dist/core/extensions/builtin/cursor-cli-oauth/catalog-refresh.d.ts.map +1 -0
  14. package/dist/core/extensions/builtin/cursor-cli-oauth/catalog-refresh.js +48 -0
  15. package/dist/core/extensions/builtin/cursor-cli-oauth/catalog-refresh.js.map +1 -0
  16. package/dist/core/extensions/builtin/cursor-cli-oauth/environment.d.ts +13 -0
  17. package/dist/core/extensions/builtin/cursor-cli-oauth/environment.d.ts.map +1 -0
  18. package/dist/core/extensions/builtin/cursor-cli-oauth/environment.js +24 -0
  19. package/dist/core/extensions/builtin/cursor-cli-oauth/environment.js.map +1 -0
  20. package/dist/core/extensions/builtin/cursor-cli-oauth/executable.d.ts +1 -0
  21. package/dist/core/extensions/builtin/cursor-cli-oauth/executable.d.ts.map +1 -1
  22. package/dist/core/extensions/builtin/cursor-cli-oauth/executable.js +7 -1
  23. package/dist/core/extensions/builtin/cursor-cli-oauth/executable.js.map +1 -1
  24. package/dist/core/extensions/builtin/cursor-cli-oauth/index.d.ts +2 -0
  25. package/dist/core/extensions/builtin/cursor-cli-oauth/index.d.ts.map +1 -1
  26. package/dist/core/extensions/builtin/cursor-cli-oauth/index.js +11 -9
  27. package/dist/core/extensions/builtin/cursor-cli-oauth/index.js.map +1 -1
  28. package/dist/core/extensions/builtin/cursor-cli-oauth/models-probe.d.ts +18 -0
  29. package/dist/core/extensions/builtin/cursor-cli-oauth/models-probe.d.ts.map +1 -0
  30. package/dist/core/extensions/builtin/cursor-cli-oauth/models-probe.js +61 -0
  31. package/dist/core/extensions/builtin/cursor-cli-oauth/models-probe.js.map +1 -0
  32. package/dist/core/extensions/builtin/cursor-cli-oauth/models.d.ts +4 -1
  33. package/dist/core/extensions/builtin/cursor-cli-oauth/models.d.ts.map +1 -1
  34. package/dist/core/extensions/builtin/cursor-cli-oauth/models.js +1 -44
  35. package/dist/core/extensions/builtin/cursor-cli-oauth/models.js.map +1 -1
  36. package/dist/core/extensions/builtin/cursor-cli-oauth/oauth-login.d.ts +22 -0
  37. package/dist/core/extensions/builtin/cursor-cli-oauth/oauth-login.d.ts.map +1 -1
  38. package/dist/core/extensions/builtin/cursor-cli-oauth/oauth-login.js +1 -1
  39. package/dist/core/extensions/builtin/cursor-cli-oauth/oauth-login.js.map +1 -1
  40. package/dist/core/extensions/builtin/cursor-cli-oauth/transport.d.ts.map +1 -1
  41. package/dist/core/extensions/builtin/cursor-cli-oauth/transport.js +2 -13
  42. package/dist/core/extensions/builtin/cursor-cli-oauth/transport.js.map +1 -1
  43. package/dist/core/extensions/builtin/terminal/monitor-file-digest.d.ts +3 -0
  44. package/dist/core/extensions/builtin/terminal/monitor-file-digest.d.ts.map +1 -0
  45. package/dist/core/extensions/builtin/terminal/monitor-file-digest.js +25 -0
  46. package/dist/core/extensions/builtin/terminal/monitor-file-digest.js.map +1 -0
  47. package/dist/core/extensions/builtin/terminal/monitor-file-watch.d.ts +9 -0
  48. package/dist/core/extensions/builtin/terminal/monitor-file-watch.d.ts.map +1 -0
  49. package/dist/core/extensions/builtin/terminal/monitor-file-watch.js +33 -0
  50. package/dist/core/extensions/builtin/terminal/monitor-file-watch.js.map +1 -0
  51. package/dist/core/extensions/builtin/terminal/monitor-line-buffer.d.ts +6 -0
  52. package/dist/core/extensions/builtin/terminal/monitor-line-buffer.d.ts.map +1 -0
  53. package/dist/core/extensions/builtin/terminal/monitor-line-buffer.js +22 -0
  54. package/dist/core/extensions/builtin/terminal/monitor-line-buffer.js.map +1 -0
  55. package/dist/core/extensions/builtin/terminal/monitor-registry.d.ts.map +1 -1
  56. package/dist/core/extensions/builtin/terminal/monitor-registry.js +14 -35
  57. package/dist/core/extensions/builtin/terminal/monitor-registry.js.map +1 -1
  58. package/dist/core/extensions/kernel-tools-context.d.ts +13 -0
  59. package/dist/core/extensions/kernel-tools-context.d.ts.map +1 -0
  60. package/dist/core/extensions/kernel-tools-context.js +3 -0
  61. package/dist/core/extensions/kernel-tools-context.js.map +1 -0
  62. package/dist/core/extensions/runner.d.ts +19 -0
  63. package/dist/core/extensions/runner.d.ts.map +1 -1
  64. package/dist/core/extensions/runner.js +103 -1
  65. package/dist/core/extensions/runner.js.map +1 -1
  66. package/dist/core/extensions/types.d.ts +21 -0
  67. package/dist/core/extensions/types.d.ts.map +1 -1
  68. package/dist/core/extensions/types.js.map +1 -1
  69. package/dist/core/resource-loader.d.ts.map +1 -1
  70. package/dist/core/resource-loader.js +9 -17
  71. package/dist/core/resource-loader.js.map +1 -1
  72. package/dist/core/session-manager.d.ts +3 -0
  73. package/dist/core/session-manager.d.ts.map +1 -1
  74. package/dist/core/session-manager.js +14 -0
  75. package/dist/core/session-manager.js.map +1 -1
  76. package/dist/core/settings-manager.d.ts +23 -0
  77. package/dist/core/settings-manager.d.ts.map +1 -1
  78. package/dist/core/settings-manager.js +41 -0
  79. package/dist/core/settings-manager.js.map +1 -1
  80. package/dist/core/tools/index.d.ts +1 -1
  81. package/dist/core/tools/index.d.ts.map +1 -1
  82. package/dist/core/tools/index.js +4 -3
  83. package/dist/core/tools/index.js.map +1 -1
  84. package/dist/core/tools/read.d.ts +3 -1
  85. package/dist/core/tools/read.d.ts.map +1 -1
  86. package/dist/core/tools/read.js +16 -2
  87. package/dist/core/tools/read.js.map +1 -1
  88. package/dist/index.d.ts +1 -0
  89. package/dist/index.d.ts.map +1 -1
  90. package/dist/index.js +1 -0
  91. package/dist/index.js.map +1 -1
  92. package/dist/modes/interactive/interactive-mode.js +3 -3
  93. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  94. package/dist/modes/rpc/host-watchdog.d.ts.map +1 -1
  95. package/dist/modes/rpc/host-watchdog.js +5 -24
  96. package/dist/modes/rpc/host-watchdog.js.map +1 -1
  97. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  98. package/dist/modes/rpc/rpc-mode.js +3 -8
  99. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  100. package/dist/modes/rpc/session-command-router.d.ts.map +1 -1
  101. package/dist/modes/rpc/session-command-router.js +3 -0
  102. package/dist/modes/rpc/session-command-router.js.map +1 -1
  103. package/dist/modes/rpc/session-worker-client.d.ts +3 -0
  104. package/dist/modes/rpc/session-worker-client.d.ts.map +1 -1
  105. package/dist/modes/rpc/session-worker-client.js +17 -6
  106. package/dist/modes/rpc/session-worker-client.js.map +1 -1
  107. package/dist/modes/rpc/shutdown.d.ts +3 -0
  108. package/dist/modes/rpc/shutdown.d.ts.map +1 -0
  109. package/dist/modes/rpc/shutdown.js +17 -0
  110. package/dist/modes/rpc/shutdown.js.map +1 -0
  111. package/docs/extensions.md +3 -0
  112. package/docs/settings.md +12 -0
  113. package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +36 -0
  114. package/node_modules/@code-yeongyu/senpi-codemode/README.md +24 -0
  115. package/node_modules/@code-yeongyu/senpi-codemode/package.json +4 -4
  116. package/node_modules/@code-yeongyu/senpi-codemode/src/bridge/http-server.ts +7 -1
  117. package/node_modules/@code-yeongyu/senpi-codemode/src/bridge/kernel-tools-protocol.ts +85 -0
  118. package/node_modules/@code-yeongyu/senpi-codemode/src/bridge/protocol.ts +6 -0
  119. package/node_modules/@code-yeongyu/senpi-codemode/src/bridges/agent-bridge.ts +30 -11
  120. package/node_modules/@code-yeongyu/senpi-codemode/src/extension/session-manager.ts +11 -0
  121. package/node_modules/@code-yeongyu/senpi-codemode/src/index.ts +10 -0
  122. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/jl/prelude.jl +46 -0
  123. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/jl/runner.jl +1 -1
  124. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/context-manager.ts +58 -10
  125. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-contract.ts +12 -0
  126. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-context.d.ts +13 -0
  127. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-context.js +7 -0
  128. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-define.d.ts +10 -0
  129. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-define.js +12 -0
  130. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-errors.js +22 -0
  131. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-errors.ts +26 -0
  132. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-host.ts +134 -0
  133. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-naming.js +28 -0
  134. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-parse.d.ts +5 -0
  135. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-parse.js +255 -0
  136. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-pump.js +105 -0
  137. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-registry.d.ts +27 -0
  138. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-registry.js +127 -0
  139. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-schema.js +69 -0
  140. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-types.ts +42 -0
  141. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/prelude.ts +2 -0
  142. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-core.js +26 -3
  143. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-runtime.js +20 -8
  144. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-slot.ts +6 -1
  145. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-startup.ts +9 -7
  146. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/workpool.js +37 -0
  147. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/kernel-tools-unavailable.ts +5 -0
  148. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/py/kernel.ts +13 -0
  149. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/py/prelude.py +57 -3
  150. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/rb/prelude.rb +13 -2
  151. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/rb/workpool.rb +38 -0
  152. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/shared/subprocess-kernel.ts +13 -0
  153. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/shared/subprocess-queue.ts +9 -1
  154. package/node_modules/@code-yeongyu/senpi-codemode/src/prompt/eval-prompt-template.ts +4 -2
  155. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/cell-handler.ts +8 -1
  156. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/detached-cell-manager.ts +36 -71
  157. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/image-resize.ts +52 -0
  158. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/image.ts +37 -72
  159. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/managed-cell.ts +78 -0
  160. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/render.ts +30 -5
  161. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/run-eval-cell.ts +49 -30
  162. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/terminal-snapshot-store.ts +35 -0
  163. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/tool-result-marshal.ts +23 -0
  164. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/types.ts +2 -0
  165. package/node_modules/@earendil-works/pi-agent-core/dist/empty-assistant-recovery.d.ts.map +1 -1
  166. package/node_modules/@earendil-works/pi-agent-core/dist/empty-assistant-recovery.js +51 -12
  167. package/node_modules/@earendil-works/pi-agent-core/dist/empty-assistant-recovery.js.map +1 -1
  168. package/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/read.d.ts +3 -0
  169. package/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/read.d.ts.map +1 -1
  170. package/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/read.js +18 -3
  171. package/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/read.js.map +1 -1
  172. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/brace-scanner.d.ts +4 -0
  173. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/brace-scanner.d.ts.map +1 -0
  174. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/brace-scanner.js +268 -0
  175. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/brace-scanner.js.map +1 -0
  176. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/header-protection.d.ts +18 -0
  177. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/header-protection.d.ts.map +1 -0
  178. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/header-protection.js +69 -0
  179. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/header-protection.js.map +1 -0
  180. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/index.d.ts +27 -0
  181. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/index.d.ts.map +1 -0
  182. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/index.js +118 -0
  183. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/index.js.map +1 -0
  184. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/lexical-context.d.ts +21 -0
  185. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/lexical-context.d.ts.map +1 -0
  186. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/lexical-context.js +24 -0
  187. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/lexical-context.js.map +1 -0
  188. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/lexical-spans.d.ts +12 -0
  189. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/lexical-spans.d.ts.map +1 -0
  190. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/lexical-spans.js +92 -0
  191. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/lexical-spans.js.map +1 -0
  192. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/types.d.ts +47 -0
  193. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/types.d.ts.map +1 -0
  194. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/types.js +8 -0
  195. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/types.js.map +1 -0
  196. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/segmented-read-view.d.ts +52 -0
  197. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/segmented-read-view.d.ts.map +1 -0
  198. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/segmented-read-view.js +155 -0
  199. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/segmented-read-view.js.map +1 -0
  200. package/node_modules/@earendil-works/pi-agent-core/dist/index.d.ts +2 -0
  201. package/node_modules/@earendil-works/pi-agent-core/dist/index.d.ts.map +1 -1
  202. package/node_modules/@earendil-works/pi-agent-core/dist/index.js +2 -0
  203. package/node_modules/@earendil-works/pi-agent-core/dist/index.js.map +1 -1
  204. package/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
  205. package/node_modules/@earendil-works/pi-ai/dist/index.d.ts +1 -0
  206. package/node_modules/@earendil-works/pi-ai/dist/index.d.ts.map +1 -1
  207. package/node_modules/@earendil-works/pi-ai/dist/index.js +1 -0
  208. package/node_modules/@earendil-works/pi-ai/dist/index.js.map +1 -1
  209. package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
  210. package/node_modules/@earendil-works/pi-ai/dist/providers/data/alibaba-token-plan.json +1 -1
  211. package/node_modules/@earendil-works/pi-ai/dist/providers/data/amazon-bedrock.json +1 -1
  212. package/node_modules/@earendil-works/pi-ai/dist/providers/data/fireworks.json +1 -1
  213. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
  214. package/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan.json +1 -1
  215. package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
  216. package/node_modules/@earendil-works/pi-ai/dist/utils/empty-response-errors.d.ts +15 -0
  217. package/node_modules/@earendil-works/pi-ai/dist/utils/empty-response-errors.d.ts.map +1 -0
  218. package/node_modules/@earendil-works/pi-ai/dist/utils/empty-response-errors.js +15 -0
  219. package/node_modules/@earendil-works/pi-ai/dist/utils/empty-response-errors.js.map +1 -0
  220. package/node_modules/@earendil-works/pi-ai/dist/utils/retry.d.ts.map +1 -1
  221. package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js +10 -0
  222. package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js.map +1 -1
  223. package/node_modules/@earendil-works/pi-ai/package.json +2 -2
  224. package/node_modules/@earendil-works/pi-pty/package.json +1 -1
  225. package/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
  226. package/node_modules/@earendil-works/pi-tui/package.json +1 -1
  227. package/package.json +7 -7
@@ -1,14 +1,12 @@
1
1
  import type { AgentToolResult } from "@code-yeongyu/senpi";
2
2
  import { DEFAULT_HARD_LIMIT_SECONDS, DEFAULT_RUN_BUDGET_SECONDS } from "../config/settings.ts";
3
3
  import type { WakeSourceState } from "../extension/wake-source-state.ts";
4
- import { type CellDeadlineExpiry, CellDeadlines } from "./cell-deadlines.ts";
4
+ import type { CellDeadlineExpiry } from "./cell-deadlines.ts";
5
5
  import type {
6
6
  EvalDetachedCellManagerOptions,
7
7
  EvalDetachedCellSnapshot,
8
- EvalDetachedCellState,
9
8
  EvalDetachedCellStatusEntry,
10
9
  } from "./detached-cell-contract.ts";
11
- import { detachedNotificationSpillPath } from "./detached-cell-notification.ts";
12
10
  import { currentDetachedResult, detachedErrorResult, snapshotDetachedCell } from "./detached-cell-snapshot.ts";
13
11
  import {
14
12
  activeDetachedCellReuseError,
@@ -17,6 +15,8 @@ import {
17
15
  } from "./detached-cell-state.ts";
18
16
  import { detachedStatusEntries, detachedWakeSourceState } from "./detached-cell-status.ts";
19
17
  import { DetachedNotificationQueue } from "./detached-notification-queue.ts";
18
+ import { createManagedCell, type LiveResultProvider, type ManagedCell } from "./managed-cell.ts";
19
+ import { TerminalSnapshotStore } from "./terminal-snapshot-store.ts";
20
20
  import type { EvalKernel, EvalLanguage, EvalToolDetails, EvalToolInput } from "./types.ts";
21
21
 
22
22
  export type {
@@ -28,40 +28,13 @@ export type {
28
28
  EvalDetachedCellStatusEntry,
29
29
  } from "./detached-cell-contract.ts";
30
30
 
31
- type LiveResultProvider = () => AgentToolResult<EvalToolDetails>;
32
-
33
- type ManagedCell = {
34
- readonly cellId: string;
35
- readonly input: EvalToolInput;
36
- readonly spillPath: string | undefined;
37
- readonly startedAtMs: number;
38
- readonly terminal: PromiseWithResolvers<EvalDetachedCellSnapshot>;
39
- state: EvalDetachedCellState;
40
- canDetach: boolean;
41
- wasDetached: boolean;
42
- kernel: EvalKernel | undefined;
43
- stateRetained: boolean | undefined;
44
- interruptNote: string | undefined;
45
- /** Holds the completion notification until the interrupt has reported whether kernel state survived. */
46
- interruptOutcome: PromiseWithResolvers<void> | undefined;
47
- liveResult: LiveResultProvider | undefined;
48
- terminalResult: AgentToolResult<EvalToolDetails> | undefined;
49
- notificationQueued: boolean;
50
- readonly deadlines: CellDeadlines;
51
- readonly hardLimitSeconds: number;
52
- readonly runBudgetSeconds: number;
53
- hardLimited: boolean;
54
- runBudgetExhausted: boolean;
55
- /** Foreground killer: the still-awaited CellExecution owns interrupting and rejecting its own call; bound from creation so a deadline firing during kernel boot still ends it. */
56
- onKill: ((error: Error) => void) | undefined;
57
- };
58
-
59
31
  export class EvalDetachedCellManager {
60
32
  readonly #artifactsDir: string | undefined;
61
33
  readonly #onStatusChange: ((entries: readonly EvalDetachedCellStatusEntry[]) => void) | undefined;
62
34
  readonly #onWakeSourceState: ((state: WakeSourceState) => void) | undefined;
63
35
  readonly #cells = new Map<string, ManagedCell>();
64
36
  readonly #detachedByLanguage = new Map<EvalLanguage, ManagedCell>();
37
+ readonly #terminalSnapshots = new TerminalSnapshotStore();
65
38
  readonly #notificationQueue: DetachedNotificationQueue;
66
39
  readonly #now: () => number;
67
40
  readonly #hardLimitSeconds: number;
@@ -83,40 +56,20 @@ export class EvalDetachedCellManager {
83
56
  if (detachedCellIsActive(existing.state)) throw activeDetachedCellReuseError(existing);
84
57
  this.#cells.delete(cellId);
85
58
  }
86
- // An explicit longer per-call timeout raises the deadline, mirroring bash keeping explicit timeouts.
87
- const hardLimitSeconds = Math.max(this.#hardLimitSeconds, input.timeout ?? 0);
88
- const runBudgetSeconds = input.timeout ?? this.#runBudgetSeconds;
89
- const cell: ManagedCell = {
59
+ this.#terminalSnapshots.delete(cellId);
60
+ const cell = createManagedCell({
90
61
  cellId,
91
62
  input,
92
- spillPath: detachedNotificationSpillPath(this.#artifactsDir, cellId),
93
- startedAtMs: this.#now(),
94
- state: "running",
95
- canDetach: false,
96
- wasDetached: false,
97
- kernel: undefined,
98
- stateRetained: undefined,
99
- interruptNote: undefined,
100
- interruptOutcome: undefined,
101
- liveResult: undefined,
102
- terminalResult: undefined,
103
- notificationQueued: false,
104
- deadlines: new CellDeadlines({
105
- cellId,
106
- hardLimitSeconds,
107
- runBudgetSeconds,
108
- onExpire: (expiry) => {
109
- const managed = this.#cells.get(cellId);
110
- if (managed !== undefined) void this.#expireDeadline(managed, expiry);
111
- },
112
- }),
113
- hardLimitSeconds,
114
- runBudgetSeconds,
115
- hardLimited: false,
116
- runBudgetExhausted: false,
63
+ artifactsDir: this.#artifactsDir,
64
+ now: this.#now,
65
+ defaultHardLimitSeconds: this.#hardLimitSeconds,
66
+ defaultRunBudgetSeconds: this.#runBudgetSeconds,
117
67
  onKill,
118
- terminal: Promise.withResolvers<EvalDetachedCellSnapshot>(),
119
- };
68
+ onExpire: (expiredId, expiry) => {
69
+ const managed = this.#cells.get(expiredId);
70
+ if (managed !== undefined) void this.#expireDeadline(managed, expiry);
71
+ },
72
+ });
120
73
  this.#cells.set(cellId, cell);
121
74
  return cell;
122
75
  }
@@ -166,13 +119,15 @@ export class EvalDetachedCellManager {
166
119
  }
167
120
 
168
121
  async stop(cellId: string, reason = "Stopped detached eval cell"): Promise<EvalDetachedCellSnapshot> {
169
- const cell = this.#get(cellId);
170
- if (cell.state === "detached") await this.#cancel(cell, reason);
171
- return this.#snapshot(cell);
122
+ const live = this.#cells.get(cellId);
123
+ if (live === undefined) return this.#terminal(cellId);
124
+ if (live.state === "detached") await this.#cancel(live, reason);
125
+ return this.#snapshot(live);
172
126
  }
173
127
 
174
128
  peek(cellId: string): EvalDetachedCellSnapshot {
175
- return this.#snapshot(this.#get(cellId));
129
+ const live = this.#cells.get(cellId);
130
+ return live === undefined ? this.#terminal(cellId) : this.#snapshot(live);
176
131
  }
177
132
 
178
133
  busyFor(language: EvalLanguage): EvalDetachedCellSnapshot | undefined {
@@ -181,7 +136,8 @@ export class EvalDetachedCellManager {
181
136
  }
182
137
 
183
138
  async waitForTerminal(cellId: string): Promise<EvalDetachedCellSnapshot> {
184
- return await this.#get(cellId).terminal.promise;
139
+ const live = this.#cells.get(cellId);
140
+ return live === undefined ? this.#terminal(cellId) : await live.terminal.promise;
185
141
  }
186
142
 
187
143
  async dispose(): Promise<void> {
@@ -191,6 +147,8 @@ export class EvalDetachedCellManager {
191
147
  );
192
148
  if (detached.length === 0) this.#emitWakeSourceState([]);
193
149
  await this.#notificationQueue.flush();
150
+ this.#cells.clear();
151
+ this.#terminalSnapshots.clear();
194
152
  }
195
153
 
196
154
  async flushNotifications(): Promise<void> {
@@ -213,6 +171,8 @@ export class EvalDetachedCellManager {
213
171
  cell.terminalResult = result;
214
172
  cell.liveResult = undefined;
215
173
  cell.terminal.resolve(this.#snapshot(cell));
174
+ this.#cells.delete(cell.cellId);
175
+ this.#refreshTerminalSnapshot(cell);
216
176
  if (cell.wasDetached) {
217
177
  if (this.#detachedByLanguage.get(cell.input.language) === cell)
218
178
  this.#detachedByLanguage.delete(cell.input.language);
@@ -257,9 +217,14 @@ export class EvalDetachedCellManager {
257
217
  cell.stateRetained = await handle.stateRetained;
258
218
  } finally {
259
219
  outcome.resolve();
220
+ this.#refreshTerminalSnapshot(cell);
260
221
  }
261
222
  }
262
223
 
224
+ #refreshTerminalSnapshot(cell: ManagedCell): void {
225
+ if (!this.#cells.has(cell.cellId)) this.#terminalSnapshots.remember(this.#snapshot(cell));
226
+ }
227
+
263
228
  #emitStatus(): void {
264
229
  const liveCells = [...this.#detachedByLanguage.values()];
265
230
  this.#onStatusChange?.(detachedStatusEntries(liveCells));
@@ -274,9 +239,9 @@ export class EvalDetachedCellManager {
274
239
  return snapshotDetachedCell(cell, this.#now());
275
240
  }
276
241
 
277
- #get(cellId: string): ManagedCell {
278
- const cell = this.#cells.get(cellId);
279
- if (cell === undefined) throw new Error(`Unknown detached eval cell "${cellId}"`);
280
- return cell;
242
+ #terminal(cellId: string): EvalDetachedCellSnapshot {
243
+ const snapshot = this.#terminalSnapshots.get(cellId);
244
+ if (snapshot === undefined) throw new Error(`Unknown detached eval cell "${cellId}"`);
245
+ return snapshot;
281
246
  }
282
247
  }
@@ -0,0 +1,52 @@
1
+ import type { ExtensionContext } from "@code-yeongyu/senpi";
2
+ import { convertToPng, formatDimensionNote, resizeImage } from "@code-yeongyu/senpi";
3
+
4
+ export interface EvalImageContent {
5
+ readonly type: "image";
6
+ readonly data: string;
7
+ readonly mimeType: string;
8
+ }
9
+
10
+ export interface EvalImageResizeResult {
11
+ readonly image: EvalImageContent;
12
+ readonly dimensionNote?: string;
13
+ }
14
+
15
+ export type EvalImageResizer = (
16
+ image: EvalImageContent,
17
+ model: ExtensionContext["model"],
18
+ ) => Promise<EvalImageResizeResult>;
19
+
20
+ type WebpModel = { readonly provider: string; readonly api: string } | undefined;
21
+
22
+ export function webpExclusionForModel(model: WebpModel): true | undefined {
23
+ if (model === undefined) return undefined;
24
+ return model.provider === "ollama" ||
25
+ model.provider === "ollama-cloud" ||
26
+ model.provider === "llama.cpp" ||
27
+ model.provider === "lm-studio" ||
28
+ model.provider === "local-server" ||
29
+ model.api === "ollama-chat"
30
+ ? true
31
+ : undefined;
32
+ }
33
+
34
+ export const resizeEvalImage: EvalImageResizer = async (image, model) => {
35
+ const excludeWebP = webpExclusionForModel(model);
36
+ const forceWebpConversion = excludeWebP === true && image.mimeType === "image/webp";
37
+ const resized = await resizeImage(
38
+ Buffer.from(image.data, "base64"),
39
+ image.mimeType,
40
+ forceWebpConversion ? { maxBytes: Buffer.byteLength(image.data, "utf8") } : undefined,
41
+ );
42
+ let output: EvalImageContent =
43
+ resized === null ? image : { type: "image", data: resized.data, mimeType: resized.mimeType };
44
+ if (excludeWebP === true && output.mimeType === "image/webp") {
45
+ const converted = await convertToPng(output.data, output.mimeType);
46
+ if (converted === null)
47
+ throw new TypeError(`Unable to convert ${output.mimeType} display output for the active model`);
48
+ output = { type: "image", data: converted.data, mimeType: converted.mimeType };
49
+ }
50
+ const dimensionNote = resized === null ? undefined : formatDimensionNote(resized);
51
+ return { image: output, ...(dimensionNote === undefined ? {} : { dimensionNote }) };
52
+ };
@@ -1,6 +1,5 @@
1
1
  import { writeFile } from "node:fs/promises";
2
- import type { AgentToolResult, ExtensionContext } from "@code-yeongyu/senpi";
3
- import { convertToPng, formatDimensionNote, resizeImage } from "@code-yeongyu/senpi";
2
+ import type { ExtensionContext } from "@code-yeongyu/senpi";
4
3
  import type { KernelToHostMessage } from "../bridge/protocol.ts";
5
4
  import type { TruncationMeta } from "../output/output-meta.ts";
6
5
  import {
@@ -12,24 +11,24 @@ import {
12
11
  TailBuffer,
13
12
  truncateTail,
14
13
  } from "../output/streaming-output.ts";
14
+ import { type EvalImageContent, type EvalImageResizer, resizeEvalImage } from "./image-resize.ts";
15
15
 
16
- const MAX_DISPLAY_TEXT_BYTES = 8_000;
17
-
18
- export interface EvalImageContent {
19
- readonly type: "image";
20
- readonly data: string;
21
- readonly mimeType: string;
22
- }
16
+ export {
17
+ type EvalImageContent,
18
+ type EvalImageResizeResult,
19
+ type EvalImageResizer,
20
+ resizeEvalImage,
21
+ webpExclusionForModel,
22
+ } from "./image-resize.ts";
23
+ export { marshalToolResult, toolResultIsError } from "./tool-result-marshal.ts";
23
24
 
24
- export interface EvalImageResizeResult {
25
- readonly image: EvalImageContent;
26
- readonly dimensionNote?: string;
27
- }
25
+ const MAX_DISPLAY_TEXT_BYTES = 8_000;
28
26
 
29
- export type EvalImageResizer = (
30
- image: EvalImageContent,
31
- model: ExtensionContext["model"],
32
- ) => Promise<EvalImageResizeResult>;
27
+ // Per-cell display caps: display payloads are retained for the whole result lifetime, so an unbounded
28
+ // burst pins base64 originals plus resized copies on the session heap (#1695).
29
+ const MAX_DISPLAY_IMAGES_PER_CELL = 8;
30
+ const MAX_DISPLAY_IMAGE_BYTES_PER_CELL = 24 * 1024 * 1024;
31
+ const MAX_JSON_OUTPUTS_PER_CELL = 64;
33
32
 
34
33
  export interface EvalOutputOptions {
35
34
  readonly artifactPath?: string;
@@ -51,7 +50,6 @@ export interface EvalOutputResult {
51
50
  }
52
51
 
53
52
  type DisplayMessage = Extract<KernelToHostMessage, { type: "display" }>;
54
- type WebpModel = { readonly provider: string; readonly api: string } | undefined;
55
53
 
56
54
  class DisplayPayloadError extends Error {
57
55
  readonly name = "DisplayPayloadError";
@@ -69,6 +67,9 @@ export class EvalOutputCollector {
69
67
  readonly #displayImages: EvalImageContent[] = [];
70
68
  readonly #images: EvalImageContent[] = [];
71
69
  readonly #jsonOutputs: unknown[] = [];
70
+ #displayImageBytes = 0;
71
+ #displayImagesElided = 0;
72
+ #jsonOutputsElided = 0;
72
73
  #hasMarkdown = false;
73
74
  #imagesProcessed = false;
74
75
 
@@ -92,11 +93,23 @@ export class EvalOutputCollector {
92
93
 
93
94
  display(message: DisplayMessage): void {
94
95
  if (message.mimeType.startsWith("image/")) {
96
+ if (
97
+ this.#displayImages.length >= MAX_DISPLAY_IMAGES_PER_CELL ||
98
+ this.#displayImageBytes + message.dataBase64.length > MAX_DISPLAY_IMAGE_BYTES_PER_CELL
99
+ ) {
100
+ this.#displayImagesElided++;
101
+ return;
102
+ }
95
103
  this.#displayImages.push({ type: "image", mimeType: message.mimeType, data: message.dataBase64 });
104
+ this.#displayImageBytes += message.dataBase64.length;
96
105
  return;
97
106
  }
98
107
  const text = Buffer.from(message.dataBase64, "base64").toString("utf8");
99
108
  if (message.mimeType === "application/json") {
109
+ if (this.#jsonOutputs.length >= MAX_JSON_OUTPUTS_PER_CELL) {
110
+ this.#jsonOutputsElided++;
111
+ return;
112
+ }
100
113
  let value: unknown;
101
114
  try {
102
115
  value = JSON.parse(text);
@@ -118,6 +131,12 @@ export class EvalOutputCollector {
118
131
 
119
132
  async finish(): Promise<EvalOutputResult> {
120
133
  await this.#processImages();
134
+ const elided = this.#displayImagesElided + this.#jsonOutputsElided;
135
+ if (elided > 0) {
136
+ this.#sink.push(
137
+ `[${this.#displayImagesElided} display image(s) and ${this.#jsonOutputsElided} JSON output(s) elided beyond per-cell caps]\n`,
138
+ );
139
+ }
121
140
  const summary = await this.#finalSummary();
122
141
  const meta = truncationMetaFromSummary(summary, this.#options.maxColumns);
123
142
  const notice = summary.artifactId === undefined ? undefined : artifactNotice(summary.artifactId);
@@ -171,38 +190,6 @@ export class EvalOutputCollector {
171
190
  }
172
191
  }
173
192
 
174
- export function webpExclusionForModel(model: WebpModel): true | undefined {
175
- if (model === undefined) return undefined;
176
- return model.provider === "ollama" ||
177
- model.provider === "ollama-cloud" ||
178
- model.provider === "llama.cpp" ||
179
- model.provider === "lm-studio" ||
180
- model.provider === "local-server" ||
181
- model.api === "ollama-chat"
182
- ? true
183
- : undefined;
184
- }
185
-
186
- export const resizeEvalImage: EvalImageResizer = async (image, model) => {
187
- const excludeWebP = webpExclusionForModel(model);
188
- const forceWebpConversion = excludeWebP === true && image.mimeType === "image/webp";
189
- const resized = await resizeImage(
190
- Buffer.from(image.data, "base64"),
191
- image.mimeType,
192
- forceWebpConversion ? { maxBytes: Buffer.byteLength(image.data, "utf8") } : undefined,
193
- );
194
- let output: EvalImageContent =
195
- resized === null ? image : { type: "image", data: resized.data, mimeType: resized.mimeType };
196
- if (excludeWebP === true && output.mimeType === "image/webp") {
197
- const converted = await convertToPng(output.data, output.mimeType);
198
- if (converted === null)
199
- throw new TypeError(`Unable to convert ${output.mimeType} display output for the active model`);
200
- output = { type: "image", data: converted.data, mimeType: converted.mimeType };
201
- }
202
- const dimensionNote = resized === null ? undefined : formatDimensionNote(resized);
203
- return { image: output, ...(dimensionNote === undefined ? {} : { dimensionNote }) };
204
- };
205
-
206
193
  function formatDisplayJson(value: unknown): string {
207
194
  let text: string;
208
195
  try {
@@ -259,25 +246,3 @@ function truncationMetaFromSummary(summary: OutputSummary, maxColumns: number):
259
246
  ...artifact,
260
247
  };
261
248
  }
262
-
263
- export function marshalToolResult(result: AgentToolResult<unknown>) {
264
- const texts = result.content.filter((part) => part.type === "text").map((part) => part.text);
265
- const images = result.content
266
- .filter((part) => part.type === "image")
267
- .map((part) => ({ mimeType: part.mimeType, dataBase64: part.data }));
268
- const details =
269
- typeof result.details === "object" &&
270
- result.details !== null &&
271
- !Array.isArray(result.details) &&
272
- Object.keys(result.details).length === 0
273
- ? undefined
274
- : result.details;
275
- const hasError = toolResultIsError(result);
276
- const text = texts.join("\n");
277
- return images.length === 0 && details === undefined && !hasError ? { text } : { text, details, images, hasError };
278
- }
279
-
280
- export function toolResultIsError(result: AgentToolResult<unknown>): boolean {
281
- const details = result.details;
282
- return typeof details === "object" && details !== null && "isError" in details && details.isError === true;
283
- }
@@ -0,0 +1,78 @@
1
+ import type { AgentToolResult } from "@code-yeongyu/senpi";
2
+ import { type CellDeadlineExpiry, CellDeadlines } from "./cell-deadlines.ts";
3
+ import type { EvalDetachedCellSnapshot, EvalDetachedCellState } from "./detached-cell-contract.ts";
4
+ import { detachedNotificationSpillPath } from "./detached-cell-notification.ts";
5
+ import type { EvalKernel, EvalToolDetails, EvalToolInput } from "./types.ts";
6
+
7
+ export type LiveResultProvider = () => AgentToolResult<EvalToolDetails>;
8
+
9
+ export type ManagedCell = {
10
+ readonly cellId: string;
11
+ readonly input: EvalToolInput;
12
+ readonly spillPath: string | undefined;
13
+ readonly startedAtMs: number;
14
+ readonly terminal: PromiseWithResolvers<EvalDetachedCellSnapshot>;
15
+ state: EvalDetachedCellState;
16
+ canDetach: boolean;
17
+ wasDetached: boolean;
18
+ kernel: EvalKernel | undefined;
19
+ stateRetained: boolean | undefined;
20
+ interruptNote: string | undefined;
21
+ /** Holds the completion notification until the interrupt has reported whether kernel state survived. */
22
+ interruptOutcome: PromiseWithResolvers<void> | undefined;
23
+ liveResult: LiveResultProvider | undefined;
24
+ terminalResult: AgentToolResult<EvalToolDetails> | undefined;
25
+ notificationQueued: boolean;
26
+ readonly deadlines: CellDeadlines;
27
+ readonly hardLimitSeconds: number;
28
+ readonly runBudgetSeconds: number;
29
+ hardLimited: boolean;
30
+ runBudgetExhausted: boolean;
31
+ /** Foreground killer: the still-awaited CellExecution owns interrupting and rejecting its own call; bound from creation so a deadline firing during kernel boot still ends it. */
32
+ onKill: ((error: Error) => void) | undefined;
33
+ };
34
+
35
+ export interface ManagedCellInit {
36
+ readonly cellId: string;
37
+ readonly input: EvalToolInput;
38
+ readonly artifactsDir: string | undefined;
39
+ readonly now: () => number;
40
+ readonly defaultHardLimitSeconds: number;
41
+ readonly defaultRunBudgetSeconds: number;
42
+ readonly onKill: ((error: Error) => void) | undefined;
43
+ readonly onExpire: (cellId: string, expiry: CellDeadlineExpiry) => void;
44
+ }
45
+
46
+ export function createManagedCell(init: ManagedCellInit): ManagedCell {
47
+ // An explicit longer per-call timeout raises the deadline, mirroring bash keeping explicit timeouts.
48
+ const hardLimitSeconds = Math.max(init.defaultHardLimitSeconds, init.input.timeout ?? 0);
49
+ const runBudgetSeconds = init.input.timeout ?? init.defaultRunBudgetSeconds;
50
+ return {
51
+ cellId: init.cellId,
52
+ input: init.input,
53
+ spillPath: detachedNotificationSpillPath(init.artifactsDir, init.cellId),
54
+ startedAtMs: init.now(),
55
+ state: "running",
56
+ canDetach: false,
57
+ wasDetached: false,
58
+ kernel: undefined,
59
+ stateRetained: undefined,
60
+ interruptNote: undefined,
61
+ interruptOutcome: undefined,
62
+ liveResult: undefined,
63
+ terminalResult: undefined,
64
+ notificationQueued: false,
65
+ deadlines: new CellDeadlines({
66
+ cellId: init.cellId,
67
+ hardLimitSeconds,
68
+ runBudgetSeconds,
69
+ onExpire: (expiry) => init.onExpire(init.cellId, expiry),
70
+ }),
71
+ hardLimitSeconds,
72
+ runBudgetSeconds,
73
+ hardLimited: false,
74
+ runBudgetExhausted: false,
75
+ onKill: init.onKill,
76
+ terminal: Promise.withResolvers<EvalDetachedCellSnapshot>(),
77
+ };
78
+ }
@@ -71,10 +71,15 @@ const TOOL_CALL_COLLAPSED_VISUAL_LINES = 4;
71
71
  const TOOL_CALL_COLLAPSED_ERROR_CODE_POINTS = 512;
72
72
  const TOOL_ERROR_OMISSION_MARKER = "[tool error omitted]";
73
73
  const LIVE_ELAPSED_TICK_MS = 1_000;
74
+ // A live row repaints on every tick, so this many ticks without a render means the row is gone.
75
+ const LIVE_TICKER_MAX_IDLE_TICKS = 60;
74
76
 
75
77
  class PlainTextComponent implements EvalRenderComponent {
76
78
  #blocks: readonly RenderBlock[] = [];
77
79
  #ticker: ReturnType<typeof setInterval> | undefined;
80
+ #live = false;
81
+ #invalidate: (() => void) | undefined;
82
+ #idleTicks = 0;
78
83
 
79
84
  setBlocks(blocks: readonly RenderBlock[]): void {
80
85
  this.#blocks = blocks;
@@ -84,16 +89,19 @@ class PlainTextComponent implements EvalRenderComponent {
84
89
  * The host only animates tool rows for streaming args, `task`, and results carrying
85
90
  * `details.progress`; an eval row matches none of them, so nothing repaints it between
86
91
  * update events. While a cell is non-terminal this drives the repaint itself so the
87
- * header's elapsed time advances, and it emits no tool updates or RPC traffic.
92
+ * header's elapsed time advances, and it emits no tool updates or RPC traffic. Detached
93
+ * and terminal cards never arm it, and a ticker whose row stopped rendering (transcript
94
+ * rebuild, session switch) stops itself after LIVE_TICKER_MAX_IDLE_TICKS and rearms on
95
+ * the next render, so dropped rows cannot accumulate intervals.
88
96
  */
89
97
  syncLiveTicker(isLive: boolean, invalidate: () => void): void {
98
+ this.#live = isLive;
99
+ this.#invalidate = invalidate;
90
100
  if (!isLive) {
91
101
  this.stopLiveTicker();
92
102
  return;
93
103
  }
94
- if (this.#ticker !== undefined) return;
95
- this.#ticker = setInterval(invalidate, LIVE_ELAPSED_TICK_MS);
96
- this.#ticker.unref?.();
104
+ this.#armTicker();
97
105
  }
98
106
 
99
107
  stopLiveTicker(): void {
@@ -102,7 +110,24 @@ class PlainTextComponent implements EvalRenderComponent {
102
110
  this.#ticker = undefined;
103
111
  }
104
112
 
113
+ #armTicker(): void {
114
+ if (this.#ticker !== undefined || this.#invalidate === undefined) return;
115
+ this.#ticker = setInterval(() => this.#tick(), LIVE_ELAPSED_TICK_MS);
116
+ this.#ticker.unref?.();
117
+ }
118
+
119
+ #tick(): void {
120
+ this.#idleTicks += 1;
121
+ if (this.#idleTicks >= LIVE_TICKER_MAX_IDLE_TICKS) {
122
+ this.stopLiveTicker();
123
+ return;
124
+ }
125
+ this.#invalidate?.();
126
+ }
127
+
105
128
  render(width: number): string[] {
129
+ this.#idleTicks = 0;
130
+ if (this.#live) this.#armTicker();
106
131
  const lines: string[] = [];
107
132
  for (const block of this.#blocks) {
108
133
  switch (block.kind) {
@@ -269,7 +294,7 @@ function spinner(frame: number | undefined): string {
269
294
  }
270
295
 
271
296
  function isLiveCellStatus(status: CellStatus): boolean {
272
- return status === "pending" || status === "running" || status === "detached";
297
+ return status === "pending" || status === "running";
273
298
  }
274
299
 
275
300
  function cellPresentation(status: CellStatus, spinnerFrame: number | undefined): StatusPresentation {
@@ -1,7 +1,8 @@
1
1
  import { randomUUID } from "node:crypto";
2
2
  import { join } from "node:path";
3
- import type { AgentToolResult, ExtensionContext } from "@code-yeongyu/senpi";
3
+ import { type AgentToolResult, type ExtensionContext, kernelToolsStorage } from "@code-yeongyu/senpi";
4
4
  import { DEFAULT_FOREGROUND_WINDOW_SECONDS, defaultCodemodeSettings } from "../config/settings.ts";
5
+ import type { KernelToolsCapability } from "../kernels/js/kernel-tools-types.ts";
5
6
  import { TIMEOUT_PAUSE_OP, TIMEOUT_RESUME_OP } from "../timeouts/bridge-timeout.ts";
6
7
  import { abortError, CellExecution, defaultTimeoutFactory } from "./cell-execution.ts";
7
8
  import { CellHandler, type CellState } from "./cell-handler.ts";
@@ -11,7 +12,7 @@ import { buildEvalExecutionEventPayload, type EvalExecutionSettleOutcome } from
11
12
  import { evalTimeoutBehavior } from "./eval-request.ts";
12
13
  import type { CreateEvalToolOptions, EvalCellInvocation } from "./eval-tool-options.ts";
13
14
  import { describeTimeoutState } from "./interrupt-note.ts";
14
- import type { EvalToolDetails } from "./types.ts";
15
+ import type { EvalKernel, EvalToolDetails } from "./types.ts";
15
16
 
16
17
  export async function runEvalCell(
17
18
  options: CreateEvalToolOptions,
@@ -166,34 +167,39 @@ async function executeCell(
166
167
  void pending.catch((error: unknown) => execution.cancel(error));
167
168
  }),
168
169
  );
169
- execution.setKernel(kernel);
170
- const activeHandler = new CellHandler(kernel, state, {
171
- executeTool: options.executeTool,
172
- ...(options.listTools === undefined ? {} : { listTools: options.listTools }),
173
- settings: options.settings ?? defaultCodemodeSettings,
174
- ...(options.complete === undefined ? {} : { complete: options.complete }),
175
- ctx: bridgeContext,
176
- ...(options.artifactsDir === undefined
177
- ? {}
178
- : { artifactPath: join(options.artifactsDir, `eval-${randomUUID()}.log`) }),
179
- ...(options.imageResizer === undefined ? {} : { imageResizer: options.imageResizer }),
180
- });
181
- handler = activeHandler;
182
- cellManager.markRunning(
183
- cell,
184
- kernel,
185
- () => activeHandler.liveResult(),
186
- (error) => execution.cancel(error),
187
- );
188
- // Includes a steer already queued at execute start or received while acquiring the kernel.
189
- onReady();
190
- if ("setContext" in options.kernelManager && typeof options.kernelManager.setContext === "function") {
191
- options.kernelManager.setContext(bridgeContext);
192
- }
193
- if (invocation.input.reset) await execution.wait(kernel.reset());
194
- const result = await execution.wait(kernel.run({ cellId: invocation.cellId, code: invocation.input.code }));
195
- if (result.ok && state.pendingBridgeCalls.length > 0) await execution.wait(Promise.all(state.pendingBridgeCalls));
196
- return await handler.finalize(result);
170
+ const runBound = async (): Promise<AgentToolResult<EvalToolDetails>> => {
171
+ execution.setKernel(kernel);
172
+ const activeHandler = new CellHandler(kernel, state, {
173
+ executeTool: options.executeTool,
174
+ ...(options.listTools === undefined ? {} : { listTools: options.listTools }),
175
+ settings: options.settings ?? defaultCodemodeSettings,
176
+ ...(options.complete === undefined ? {} : { complete: options.complete }),
177
+ ctx: bridgeContext,
178
+ ...(options.artifactsDir === undefined
179
+ ? {}
180
+ : { artifactPath: join(options.artifactsDir, `eval-${randomUUID()}.log`) }),
181
+ ...(options.imageResizer === undefined ? {} : { imageResizer: options.imageResizer }),
182
+ });
183
+ handler = activeHandler;
184
+ cellManager.markRunning(
185
+ cell,
186
+ kernel,
187
+ () => activeHandler.liveResult(),
188
+ (error) => execution.cancel(error),
189
+ );
190
+ // Includes a steer already queued at execute start or received while acquiring the kernel.
191
+ onReady();
192
+ if ("setContext" in options.kernelManager && typeof options.kernelManager.setContext === "function") {
193
+ options.kernelManager.setContext(bridgeContext);
194
+ }
195
+ if (invocation.input.reset) await execution.wait(kernel.reset());
196
+ const result = await execution.wait(kernel.run({ cellId: invocation.cellId, code: invocation.input.code }));
197
+ if (result.ok && state.pendingBridgeCalls.length > 0)
198
+ await execution.wait(Promise.all(state.pendingBridgeCalls));
199
+ return await handler.finalize(result);
200
+ };
201
+ const kernelTools = jsKernelTools(kernel, invocation.input.language);
202
+ return kernelTools ? await kernelToolsStorage.run(kernelTools, runBound) : await runBound();
197
203
  } catch (error) {
198
204
  if (handler && error instanceof Error && error.name === "CodemodeSessionDisposedError")
199
205
  return await handler.finalizeCancellation(error);
@@ -206,3 +212,16 @@ async function executeCell(
206
212
  if (handler) await handler.flushOutput();
207
213
  }
208
214
  }
215
+
216
+ function jsKernelTools(kernel: EvalKernel, language: string): KernelToolsCapability | undefined {
217
+ if (language !== "js") return undefined;
218
+ if (!("describeKernelTools" in kernel) || typeof kernel.describeKernelTools !== "function") return undefined;
219
+ const js = kernel as EvalKernel & {
220
+ describeKernelTools: KernelToolsCapability["describe"];
221
+ invokeKernelTool: KernelToolsCapability["invoke"];
222
+ };
223
+ return {
224
+ describe: (names) => js.describeKernelTools(names),
225
+ invoke: (request, signal) => js.invokeKernelTool(request, signal),
226
+ };
227
+ }