rookery-agent 0.1.0 → 0.3.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.
- package/README.md +467 -367
- package/docs/migration.md +88 -88
- package/docs/updates.md +112 -0
- package/package.json +13 -3
- package/packages/cli/dist/commands/config.js +2 -2
- package/packages/cli/dist/commands/doctor.d.ts.map +1 -1
- package/packages/cli/dist/commands/doctor.js +13 -9
- package/packages/cli/dist/commands/doctor.js.map +1 -1
- package/packages/cli/dist/commands/memory.js +1 -1
- package/packages/cli/dist/commands/org.d.ts +2 -2
- package/packages/cli/dist/commands/org.d.ts.map +1 -1
- package/packages/cli/dist/commands/org.js +19 -17
- package/packages/cli/dist/commands/org.js.map +1 -1
- package/packages/cli/dist/commands/serve.js +1 -1
- package/packages/cli/dist/commands/serve.js.map +1 -1
- package/packages/cli/dist/commands/shared.d.ts.map +1 -1
- package/packages/cli/dist/commands/shared.js +2 -1
- package/packages/cli/dist/commands/shared.js.map +1 -1
- package/packages/cli/dist/commands/tasks.d.ts.map +1 -1
- package/packages/cli/dist/commands/tasks.js +25 -11
- package/packages/cli/dist/commands/tasks.js.map +1 -1
- package/packages/cli/dist/commands/tools.js +1 -1
- package/packages/cli/dist/commands/tools.js.map +1 -1
- package/packages/cli/dist/index.js +13 -13
- package/packages/cli/dist/index.js.map +1 -1
- package/packages/cli/dist/repl.d.ts +12 -0
- package/packages/cli/dist/repl.d.ts.map +1 -1
- package/packages/cli/dist/repl.js +170 -16
- package/packages/cli/dist/repl.js.map +1 -1
- package/packages/cli/dist/tui/App.d.ts +7 -3
- package/packages/cli/dist/tui/App.d.ts.map +1 -1
- package/packages/cli/dist/tui/App.js +182 -16
- package/packages/cli/dist/tui/App.js.map +1 -1
- package/packages/cli/dist/tui/commands.d.ts +7 -0
- package/packages/cli/dist/tui/commands.d.ts.map +1 -1
- package/packages/cli/dist/tui/commands.js +70 -8
- package/packages/cli/dist/tui/commands.js.map +1 -1
- package/packages/cli/dist/tui/components/AssignmentsView.js +4 -4
- package/packages/cli/dist/tui/components/AssignmentsView.js.map +1 -1
- package/packages/cli/dist/tui/components/Banner.d.ts +11 -2
- package/packages/cli/dist/tui/components/Banner.d.ts.map +1 -1
- package/packages/cli/dist/tui/components/Banner.js +7 -10
- package/packages/cli/dist/tui/components/Banner.js.map +1 -1
- package/packages/cli/dist/tui/components/CodeBlock.js +2 -2
- package/packages/cli/dist/tui/components/CodeBlock.js.map +1 -1
- package/packages/cli/dist/tui/components/InputBox.d.ts.map +1 -1
- package/packages/cli/dist/tui/components/InputBox.js +4 -4
- package/packages/cli/dist/tui/components/InputBox.js.map +1 -1
- package/packages/cli/dist/tui/components/Logo.d.ts +56 -0
- package/packages/cli/dist/tui/components/Logo.d.ts.map +1 -0
- package/packages/cli/dist/tui/components/Logo.js +50 -0
- package/packages/cli/dist/tui/components/Logo.js.map +1 -0
- package/packages/cli/dist/tui/components/Markdown.js +8 -8
- package/packages/cli/dist/tui/components/Markdown.js.map +1 -1
- package/packages/cli/dist/tui/components/Message.d.ts +1 -1
- package/packages/cli/dist/tui/components/Message.d.ts.map +1 -1
- package/packages/cli/dist/tui/components/Message.js +5 -4
- package/packages/cli/dist/tui/components/Message.js.map +1 -1
- package/packages/cli/dist/tui/components/QuestionView.d.ts +29 -0
- package/packages/cli/dist/tui/components/QuestionView.d.ts.map +1 -0
- package/packages/cli/dist/tui/components/QuestionView.js +53 -0
- package/packages/cli/dist/tui/components/QuestionView.js.map +1 -0
- package/packages/cli/dist/tui/components/SlashPalette.d.ts +5 -2
- package/packages/cli/dist/tui/components/SlashPalette.d.ts.map +1 -1
- package/packages/cli/dist/tui/components/SlashPalette.js +2 -2
- package/packages/cli/dist/tui/components/SlashPalette.js.map +1 -1
- package/packages/cli/dist/tui/components/StatusLine.d.ts +0 -2
- package/packages/cli/dist/tui/components/StatusLine.d.ts.map +1 -1
- package/packages/cli/dist/tui/components/StatusLine.js +8 -5
- package/packages/cli/dist/tui/components/StatusLine.js.map +1 -1
- package/packages/cli/dist/tui/components/ToolGroup.js +2 -2
- package/packages/cli/dist/tui/components/ToolGroup.js.map +1 -1
- package/packages/cli/dist/tui/components/WatchView.d.ts +21 -0
- package/packages/cli/dist/tui/components/WatchView.d.ts.map +1 -0
- package/packages/cli/dist/tui/components/WatchView.js +36 -0
- package/packages/cli/dist/tui/components/WatchView.js.map +1 -0
- package/packages/cli/dist/tui/history.d.ts +20 -0
- package/packages/cli/dist/tui/history.d.ts.map +1 -0
- package/packages/cli/dist/tui/history.js +105 -0
- package/packages/cli/dist/tui/history.js.map +1 -0
- package/packages/cli/dist/tui/hooks/useSlash.d.ts.map +1 -1
- package/packages/cli/dist/tui/hooks/useSlash.js +3 -2
- package/packages/cli/dist/tui/hooks/useSlash.js.map +1 -1
- package/packages/cli/dist/tui/hooks/useTurn.d.ts +58 -1
- package/packages/cli/dist/tui/hooks/useTurn.d.ts.map +1 -1
- package/packages/cli/dist/tui/hooks/useTurn.js +214 -36
- package/packages/cli/dist/tui/hooks/useTurn.js.map +1 -1
- package/packages/cli/dist/tui/hooks/useWatch.d.ts +52 -0
- package/packages/cli/dist/tui/hooks/useWatch.d.ts.map +1 -0
- package/packages/cli/dist/tui/hooks/useWatch.js +145 -0
- package/packages/cli/dist/tui/hooks/useWatch.js.map +1 -0
- package/packages/cli/dist/tui/inkTheme.d.ts +19 -0
- package/packages/cli/dist/tui/inkTheme.d.ts.map +1 -0
- package/packages/cli/dist/tui/inkTheme.js +81 -0
- package/packages/cli/dist/tui/inkTheme.js.map +1 -0
- package/packages/cli/dist/tui/theme.d.ts +39 -29
- package/packages/cli/dist/tui/theme.d.ts.map +1 -1
- package/packages/cli/dist/tui/theme.js +35 -25
- package/packages/cli/dist/tui/theme.js.map +1 -1
- package/packages/cli/dist/tui/types.d.ts +56 -3
- package/packages/cli/dist/tui/types.d.ts.map +1 -1
- package/packages/cli/dist/tui/types.js +85 -0
- package/packages/cli/dist/tui/types.js.map +1 -1
- package/packages/cli/dist/ui/modelNames.d.ts +51 -0
- package/packages/cli/dist/ui/modelNames.d.ts.map +1 -0
- package/packages/cli/dist/ui/modelNames.js +134 -0
- package/packages/cli/dist/ui/modelNames.js.map +1 -0
- package/packages/cli/dist/ui/render.d.ts.map +1 -1
- package/packages/cli/dist/ui/render.js +17 -8
- package/packages/cli/dist/ui/render.js.map +1 -1
- package/packages/cli/dist/ui/speech.js +5 -0
- package/packages/cli/dist/ui/speech.js.map +1 -1
- package/packages/cli/dist/ui/theme.d.ts +33 -9
- package/packages/cli/dist/ui/theme.d.ts.map +1 -1
- package/packages/cli/dist/ui/theme.js +33 -9
- package/packages/cli/dist/ui/theme.js.map +1 -1
- package/packages/cli/package.json +1 -1
- package/packages/core/dist/agents/persona.d.ts.map +1 -1
- package/packages/core/dist/agents/persona.js +5 -2
- package/packages/core/dist/agents/persona.js.map +1 -1
- package/packages/core/dist/computer/accessibility.d.ts +78 -0
- package/packages/core/dist/computer/accessibility.d.ts.map +1 -0
- package/packages/core/dist/computer/accessibility.js +270 -0
- package/packages/core/dist/computer/accessibility.js.map +1 -0
- package/packages/core/dist/computer/assemblies.d.ts +17 -0
- package/packages/core/dist/computer/assemblies.d.ts.map +1 -0
- package/packages/core/dist/computer/assemblies.js +55 -0
- package/packages/core/dist/computer/assemblies.js.map +1 -0
- package/packages/core/dist/computer/browser-init.d.ts +9 -0
- package/packages/core/dist/computer/browser-init.d.ts.map +1 -0
- package/packages/core/dist/computer/browser-init.js +133 -0
- package/packages/core/dist/computer/browser-init.js.map +1 -0
- package/packages/core/dist/computer/cursor.d.ts +30 -0
- package/packages/core/dist/computer/cursor.d.ts.map +1 -0
- package/packages/core/dist/computer/cursor.js +30 -0
- package/packages/core/dist/computer/cursor.js.map +1 -0
- package/packages/core/dist/computer/mcp-server.js +524 -82
- package/packages/core/dist/computer/mcp-server.js.map +1 -1
- package/packages/core/dist/computer/powershell.d.ts +4 -0
- package/packages/core/dist/computer/powershell.d.ts.map +1 -1
- package/packages/core/dist/computer/powershell.js +471 -81
- package/packages/core/dist/computer/powershell.js.map +1 -1
- package/packages/core/dist/computer/screen-text.d.ts +82 -0
- package/packages/core/dist/computer/screen-text.d.ts.map +1 -0
- package/packages/core/dist/computer/screen-text.js +243 -0
- package/packages/core/dist/computer/screen-text.js.map +1 -0
- package/packages/core/dist/computer/sketch.d.ts +66 -0
- package/packages/core/dist/computer/sketch.d.ts.map +1 -0
- package/packages/core/dist/computer/sketch.js +540 -0
- package/packages/core/dist/computer/sketch.js.map +1 -0
- package/packages/core/dist/computer/tools.d.ts +8 -8
- package/packages/core/dist/computer/tools.d.ts.map +1 -1
- package/packages/core/dist/computer/tools.js +186 -31
- package/packages/core/dist/computer/tools.js.map +1 -1
- package/packages/core/dist/computer/validation.d.ts +555 -0
- package/packages/core/dist/computer/validation.d.ts.map +1 -0
- package/packages/core/dist/computer/validation.js +111 -0
- package/packages/core/dist/computer/validation.js.map +1 -0
- package/packages/core/dist/computer/windows-cursor.d.ts +14 -0
- package/packages/core/dist/computer/windows-cursor.d.ts.map +1 -0
- package/packages/core/dist/computer/windows-cursor.js +713 -0
- package/packages/core/dist/computer/windows-cursor.js.map +1 -0
- package/packages/core/dist/config.d.ts +34 -1
- package/packages/core/dist/config.d.ts.map +1 -1
- package/packages/core/dist/config.js +362 -11
- package/packages/core/dist/config.js.map +1 -1
- package/packages/core/dist/cron/scheduler.d.ts +59 -6
- package/packages/core/dist/cron/scheduler.d.ts.map +1 -1
- package/packages/core/dist/cron/scheduler.js +295 -27
- package/packages/core/dist/cron/scheduler.js.map +1 -1
- package/packages/core/dist/cron/store.d.ts +19 -1
- package/packages/core/dist/cron/store.d.ts.map +1 -1
- package/packages/core/dist/cron/store.js +36 -8
- package/packages/core/dist/cron/store.js.map +1 -1
- package/packages/core/dist/external/claude-code.d.ts +4 -0
- package/packages/core/dist/external/claude-code.d.ts.map +1 -0
- package/packages/core/dist/external/claude-code.js +111 -0
- package/packages/core/dist/external/claude-code.js.map +1 -0
- package/packages/core/dist/external/discovery.d.ts +33 -0
- package/packages/core/dist/external/discovery.d.ts.map +1 -0
- package/packages/core/dist/external/discovery.js +144 -0
- package/packages/core/dist/external/discovery.js.map +1 -0
- package/packages/core/dist/external/homes.d.ts +26 -0
- package/packages/core/dist/external/homes.d.ts.map +1 -0
- package/packages/core/dist/external/homes.js +49 -0
- package/packages/core/dist/external/homes.js.map +1 -0
- package/packages/core/dist/external/shared.d.ts +201 -0
- package/packages/core/dist/external/shared.d.ts.map +1 -0
- package/packages/core/dist/external/shared.js +308 -0
- package/packages/core/dist/external/shared.js.map +1 -0
- package/packages/core/dist/gateway/policy.d.ts +117 -2
- package/packages/core/dist/gateway/policy.d.ts.map +1 -1
- package/packages/core/dist/gateway/policy.js +286 -6
- package/packages/core/dist/gateway/policy.js.map +1 -1
- package/packages/core/dist/index.d.ts +38 -12
- package/packages/core/dist/index.d.ts.map +1 -1
- package/packages/core/dist/index.js +66 -12
- package/packages/core/dist/index.js.map +1 -1
- package/packages/core/dist/memory/db.d.ts +1 -1
- package/packages/core/dist/memory/db.d.ts.map +1 -1
- package/packages/core/dist/memory/db.js +878 -1
- package/packages/core/dist/memory/db.js.map +1 -1
- package/packages/core/dist/memory/dream/admission.d.ts +124 -0
- package/packages/core/dist/memory/dream/admission.d.ts.map +1 -0
- package/packages/core/dist/memory/dream/admission.js +116 -0
- package/packages/core/dist/memory/dream/admission.js.map +1 -0
- package/packages/core/dist/memory/dream/candidate.d.ts +152 -0
- package/packages/core/dist/memory/dream/candidate.d.ts.map +1 -0
- package/packages/core/dist/memory/dream/candidate.js +547 -0
- package/packages/core/dist/memory/dream/candidate.js.map +1 -0
- package/packages/core/dist/memory/dream/evaluate.d.ts +394 -0
- package/packages/core/dist/memory/dream/evaluate.d.ts.map +1 -0
- package/packages/core/dist/memory/dream/evaluate.js +1032 -0
- package/packages/core/dist/memory/dream/evaluate.js.map +1 -0
- package/packages/core/dist/memory/dream/frame.d.ts +61 -0
- package/packages/core/dist/memory/dream/frame.d.ts.map +1 -0
- package/packages/core/dist/memory/dream/frame.js +292 -0
- package/packages/core/dist/memory/dream/frame.js.map +1 -0
- package/packages/core/dist/memory/dream/label.d.ts +370 -0
- package/packages/core/dist/memory/dream/label.d.ts.map +1 -0
- package/packages/core/dist/memory/dream/label.js +439 -0
- package/packages/core/dist/memory/dream/label.js.map +1 -0
- package/packages/core/dist/memory/dream/measure.d.ts +114 -0
- package/packages/core/dist/memory/dream/measure.d.ts.map +1 -0
- package/packages/core/dist/memory/dream/measure.js +205 -0
- package/packages/core/dist/memory/dream/measure.js.map +1 -0
- package/packages/core/dist/memory/dream/policy.d.ts +21 -0
- package/packages/core/dist/memory/dream/policy.d.ts.map +1 -0
- package/packages/core/dist/memory/dream/policy.js +157 -0
- package/packages/core/dist/memory/dream/policy.js.map +1 -0
- package/packages/core/dist/memory/dream/probe.d.ts +202 -0
- package/packages/core/dist/memory/dream/probe.d.ts.map +1 -0
- package/packages/core/dist/memory/dream/probe.js +671 -0
- package/packages/core/dist/memory/dream/probe.js.map +1 -0
- package/packages/core/dist/memory/dream/promote.d.ts +312 -0
- package/packages/core/dist/memory/dream/promote.d.ts.map +1 -0
- package/packages/core/dist/memory/dream/promote.js +528 -0
- package/packages/core/dist/memory/dream/promote.js.map +1 -0
- package/packages/core/dist/memory/dream/score.d.ts +103 -0
- package/packages/core/dist/memory/dream/score.d.ts.map +1 -0
- package/packages/core/dist/memory/dream/score.js +334 -0
- package/packages/core/dist/memory/dream/score.js.map +1 -0
- package/packages/core/dist/memory/dream/slots.d.ts +193 -0
- package/packages/core/dist/memory/dream/slots.d.ts.map +1 -0
- package/packages/core/dist/memory/dream/slots.js +0 -0
- package/packages/core/dist/memory/dream/slots.js.map +1 -0
- package/packages/core/dist/memory/dream/trajectory.d.ts +262 -0
- package/packages/core/dist/memory/dream/trajectory.d.ts.map +1 -0
- package/packages/core/dist/memory/dream/trajectory.js +366 -0
- package/packages/core/dist/memory/dream/trajectory.js.map +1 -0
- package/packages/core/dist/memory/extractor.d.ts +7 -0
- package/packages/core/dist/memory/extractor.d.ts.map +1 -1
- package/packages/core/dist/memory/extractor.js +35 -12
- package/packages/core/dist/memory/extractor.js.map +1 -1
- package/packages/core/dist/memory/gate.d.ts +43 -7
- package/packages/core/dist/memory/gate.d.ts.map +1 -1
- package/packages/core/dist/memory/gate.js +91 -4
- package/packages/core/dist/memory/gate.js.map +1 -1
- package/packages/core/dist/memory/recall.d.ts +57 -0
- package/packages/core/dist/memory/recall.d.ts.map +1 -1
- package/packages/core/dist/memory/recall.js +60 -123
- package/packages/core/dist/memory/recall.js.map +1 -1
- package/packages/core/dist/memory/sleep.d.ts +131 -4
- package/packages/core/dist/memory/sleep.d.ts.map +1 -1
- package/packages/core/dist/memory/sleep.js +2384 -65
- package/packages/core/dist/memory/sleep.js.map +1 -1
- package/packages/core/dist/memory/store.d.ts +564 -10
- package/packages/core/dist/memory/store.d.ts.map +1 -1
- package/packages/core/dist/memory/store.js +1673 -102
- package/packages/core/dist/memory/store.js.map +1 -1
- package/packages/core/dist/org/controller.d.ts +268 -4
- package/packages/core/dist/org/controller.d.ts.map +1 -1
- package/packages/core/dist/org/controller.js +2298 -248
- package/packages/core/dist/org/controller.js.map +1 -1
- package/packages/core/dist/org/ponytail.d.ts +1 -1
- package/packages/core/dist/org/ponytail.js +1 -1
- package/packages/core/dist/org/project-mcp.d.ts +3 -3
- package/packages/core/dist/org/prompts.d.ts +44 -30
- package/packages/core/dist/org/prompts.d.ts.map +1 -1
- package/packages/core/dist/org/prompts.js +209 -92
- package/packages/core/dist/org/prompts.js.map +1 -1
- package/packages/core/dist/org/questions.d.ts +104 -0
- package/packages/core/dist/org/questions.d.ts.map +1 -0
- package/packages/core/dist/org/questions.js +136 -0
- package/packages/core/dist/org/questions.js.map +1 -0
- package/packages/core/dist/org/review.d.ts +100 -0
- package/packages/core/dist/org/review.d.ts.map +1 -0
- package/packages/core/dist/org/review.js +256 -0
- package/packages/core/dist/org/review.js.map +1 -0
- package/packages/core/dist/org/store.d.ts +311 -2
- package/packages/core/dist/org/store.d.ts.map +1 -1
- package/packages/core/dist/org/store.js +981 -13
- package/packages/core/dist/org/store.js.map +1 -1
- package/packages/core/dist/org/tools.d.ts +33 -3
- package/packages/core/dist/org/tools.d.ts.map +1 -1
- package/packages/core/dist/org/tools.js +380 -67
- package/packages/core/dist/org/tools.js.map +1 -1
- package/packages/core/dist/providers/catalogue.d.ts +1 -1
- package/packages/core/dist/providers/catalogue.d.ts.map +1 -1
- package/packages/core/dist/providers/catalogue.js +2 -2
- package/packages/core/dist/providers/catalogue.js.map +1 -1
- package/packages/core/dist/providers/claude-code.d.ts +19 -3
- package/packages/core/dist/providers/claude-code.d.ts.map +1 -1
- package/packages/core/dist/providers/claude-code.js +501 -40
- package/packages/core/dist/providers/claude-code.js.map +1 -1
- package/packages/core/dist/providers/claude-tui.d.ts +288 -0
- package/packages/core/dist/providers/claude-tui.d.ts.map +1 -0
- package/packages/core/dist/providers/claude-tui.js +1118 -0
- package/packages/core/dist/providers/claude-tui.js.map +1 -0
- package/packages/core/dist/providers/codex-auth.d.ts +15 -0
- package/packages/core/dist/providers/codex-auth.d.ts.map +1 -0
- package/packages/core/dist/providers/codex-auth.js +127 -0
- package/packages/core/dist/providers/codex-auth.js.map +1 -0
- package/packages/core/dist/providers/codex-bridge.d.ts +58 -0
- package/packages/core/dist/providers/codex-bridge.d.ts.map +1 -0
- package/packages/core/dist/providers/codex-bridge.js +375 -0
- package/packages/core/dist/providers/codex-bridge.js.map +1 -0
- package/packages/core/dist/providers/codex-translate.d.ts +75 -0
- package/packages/core/dist/providers/codex-translate.d.ts.map +1 -0
- package/packages/core/dist/providers/codex-translate.js +383 -0
- package/packages/core/dist/providers/codex-translate.js.map +1 -0
- package/packages/core/dist/providers/model-gateway.d.ts +56 -0
- package/packages/core/dist/providers/model-gateway.d.ts.map +1 -0
- package/packages/core/dist/providers/model-gateway.js +119 -0
- package/packages/core/dist/providers/model-gateway.js.map +1 -0
- package/packages/core/dist/providers/process.d.ts +3 -1
- package/packages/core/dist/providers/process.d.ts.map +1 -1
- package/packages/core/dist/providers/process.js +3 -3
- package/packages/core/dist/providers/process.js.map +1 -1
- package/packages/core/dist/providers/profiles.d.ts +11 -0
- package/packages/core/dist/providers/profiles.d.ts.map +1 -0
- package/packages/core/dist/providers/profiles.js +28 -0
- package/packages/core/dist/providers/profiles.js.map +1 -0
- package/packages/core/dist/providers/provider-catalog.d.ts +72 -0
- package/packages/core/dist/providers/provider-catalog.d.ts.map +1 -0
- package/packages/core/dist/providers/provider-catalog.js +144 -0
- package/packages/core/dist/providers/provider-catalog.js.map +1 -0
- package/packages/core/dist/providers/quota.d.ts +40 -1
- package/packages/core/dist/providers/quota.d.ts.map +1 -1
- package/packages/core/dist/providers/quota.js +288 -25
- package/packages/core/dist/providers/quota.js.map +1 -1
- package/packages/core/dist/providers/registry.d.ts +46 -3
- package/packages/core/dist/providers/registry.d.ts.map +1 -1
- package/packages/core/dist/providers/registry.js +148 -13
- package/packages/core/dist/providers/registry.js.map +1 -1
- package/packages/core/dist/providers/router.d.ts +28 -0
- package/packages/core/dist/providers/router.d.ts.map +1 -0
- package/packages/core/dist/providers/router.js +88 -0
- package/packages/core/dist/providers/router.js.map +1 -0
- package/packages/core/dist/providers/user-settings-guard.d.ts +12 -0
- package/packages/core/dist/providers/user-settings-guard.d.ts.map +1 -0
- package/packages/core/dist/providers/user-settings-guard.js +130 -0
- package/packages/core/dist/providers/user-settings-guard.js.map +1 -0
- package/packages/core/dist/runtime.d.ts +193 -7
- package/packages/core/dist/runtime.d.ts.map +1 -1
- package/packages/core/dist/runtime.js +1676 -219
- package/packages/core/dist/runtime.js.map +1 -1
- package/packages/core/dist/skills/builtin.d.ts +34 -0
- package/packages/core/dist/skills/builtin.d.ts.map +1 -0
- package/packages/core/dist/skills/builtin.js +305 -0
- package/packages/core/dist/skills/builtin.js.map +1 -0
- package/packages/core/dist/skills/shelf.d.ts +30 -0
- package/packages/core/dist/skills/shelf.d.ts.map +1 -0
- package/packages/core/dist/skills/shelf.js +159 -0
- package/packages/core/dist/skills/shelf.js.map +1 -0
- package/packages/core/dist/skills/store.d.ts +66 -4
- package/packages/core/dist/skills/store.d.ts.map +1 -1
- package/packages/core/dist/skills/store.js +105 -18
- package/packages/core/dist/skills/store.js.map +1 -1
- package/packages/core/dist/skills/suggest.d.ts +21 -0
- package/packages/core/dist/skills/suggest.d.ts.map +1 -0
- package/packages/core/dist/skills/suggest.js +150 -0
- package/packages/core/dist/skills/suggest.js.map +1 -0
- package/packages/core/dist/tools/catalog.d.ts +1 -3
- package/packages/core/dist/tools/catalog.d.ts.map +1 -1
- package/packages/core/dist/tools/catalog.js +38 -26
- package/packages/core/dist/tools/catalog.js.map +1 -1
- package/packages/core/dist/tools/hub.d.ts +136 -10
- package/packages/core/dist/tools/hub.d.ts.map +1 -1
- package/packages/core/dist/tools/hub.js +418 -24
- package/packages/core/dist/tools/hub.js.map +1 -1
- package/packages/core/dist/turns/journal.d.ts +78 -0
- package/packages/core/dist/turns/journal.d.ts.map +1 -0
- package/packages/core/dist/turns/journal.js +104 -0
- package/packages/core/dist/turns/journal.js.map +1 -0
- package/packages/core/dist/types.d.ts +1776 -12
- package/packages/core/dist/types.d.ts.map +1 -1
- package/packages/core/dist/types.js.map +1 -1
- package/packages/core/dist/util/blocks.d.ts +41 -0
- package/packages/core/dist/util/blocks.d.ts.map +1 -0
- package/packages/core/dist/util/blocks.js +175 -0
- package/packages/core/dist/util/blocks.js.map +1 -0
- package/packages/core/dist/util/queue.d.ts +12 -0
- package/packages/core/dist/util/queue.d.ts.map +1 -1
- package/packages/core/dist/util/queue.js +16 -0
- package/packages/core/dist/util/queue.js.map +1 -1
- package/packages/core/dist/util/time.d.ts +39 -0
- package/packages/core/dist/util/time.d.ts.map +1 -0
- package/packages/core/dist/util/time.js +71 -0
- package/packages/core/dist/util/time.js.map +1 -0
- package/packages/core/package.json +1 -1
- package/packages/server/dist/auth.d.ts +14 -1
- package/packages/server/dist/auth.d.ts.map +1 -1
- package/packages/server/dist/auth.js +19 -0
- package/packages/server/dist/auth.js.map +1 -1
- package/packages/server/dist/context.d.ts +35 -1
- package/packages/server/dist/context.d.ts.map +1 -1
- package/packages/server/dist/context.js +39 -10
- package/packages/server/dist/context.js.map +1 -1
- package/packages/server/dist/gateways/attachments.d.ts +32 -0
- package/packages/server/dist/gateways/attachments.d.ts.map +1 -0
- package/packages/server/dist/gateways/attachments.js +167 -0
- package/packages/server/dist/gateways/attachments.js.map +1 -0
- package/packages/server/dist/gateways/markdown.d.ts +9 -0
- package/packages/server/dist/gateways/markdown.d.ts.map +1 -0
- package/packages/server/dist/gateways/markdown.js +170 -0
- package/packages/server/dist/gateways/markdown.js.map +1 -0
- package/packages/server/dist/gateways/push.d.ts +1 -1
- package/packages/server/dist/gateways/push.d.ts.map +1 -1
- package/packages/server/dist/gateways/push.js +420 -13
- package/packages/server/dist/gateways/push.js.map +1 -1
- package/packages/server/dist/gateways/telegram-api.d.ts +70 -1
- package/packages/server/dist/gateways/telegram-api.d.ts.map +1 -1
- package/packages/server/dist/gateways/telegram-api.js +140 -1
- package/packages/server/dist/gateways/telegram-api.js.map +1 -1
- package/packages/server/dist/gateways/telegram.d.ts +181 -1
- package/packages/server/dist/gateways/telegram.d.ts.map +1 -1
- package/packages/server/dist/gateways/telegram.js +1572 -78
- package/packages/server/dist/gateways/telegram.js.map +1 -1
- package/packages/server/dist/gateways/threads.d.ts +84 -0
- package/packages/server/dist/gateways/threads.d.ts.map +1 -0
- package/packages/server/dist/gateways/threads.js +289 -0
- package/packages/server/dist/gateways/threads.js.map +1 -0
- package/packages/server/dist/index.d.ts +2 -1
- package/packages/server/dist/index.d.ts.map +1 -1
- package/packages/server/dist/index.js +2 -1
- package/packages/server/dist/index.js.map +1 -1
- package/packages/server/dist/listeners/imap.d.ts +13 -0
- package/packages/server/dist/listeners/imap.d.ts.map +1 -0
- package/packages/server/dist/listeners/imap.js +0 -0
- package/packages/server/dist/listeners/imap.js.map +1 -0
- package/packages/server/dist/listeners/registry.d.ts +18 -0
- package/packages/server/dist/listeners/registry.d.ts.map +1 -0
- package/packages/server/dist/listeners/registry.js +88 -0
- package/packages/server/dist/listeners/registry.js.map +1 -0
- package/packages/server/dist/listeners/types.d.ts +55 -0
- package/packages/server/dist/listeners/types.d.ts.map +1 -0
- package/packages/server/dist/listeners/types.js +2 -0
- package/packages/server/dist/listeners/types.js.map +1 -0
- package/packages/server/dist/main.js +15 -1
- package/packages/server/dist/main.js.map +1 -1
- package/packages/server/dist/routes/chat.d.ts +7 -3
- package/packages/server/dist/routes/chat.d.ts.map +1 -1
- package/packages/server/dist/routes/chat.js +8 -17
- package/packages/server/dist/routes/chat.js.map +1 -1
- package/packages/server/dist/routes/config.d.ts.map +1 -1
- package/packages/server/dist/routes/config.js +66 -7
- package/packages/server/dist/routes/config.js.map +1 -1
- package/packages/server/dist/routes/cron.d.ts.map +1 -1
- package/packages/server/dist/routes/cron.js +65 -8
- package/packages/server/dist/routes/cron.js.map +1 -1
- package/packages/server/dist/routes/dream.d.ts +22 -0
- package/packages/server/dist/routes/dream.d.ts.map +1 -0
- package/packages/server/dist/routes/dream.js +152 -0
- package/packages/server/dist/routes/dream.js.map +1 -0
- package/packages/server/dist/routes/hooks.d.ts +18 -0
- package/packages/server/dist/routes/hooks.d.ts.map +1 -0
- package/packages/server/dist/routes/hooks.js +62 -0
- package/packages/server/dist/routes/hooks.js.map +1 -0
- package/packages/server/dist/routes/listeners.d.ts +10 -0
- package/packages/server/dist/routes/listeners.d.ts.map +1 -0
- package/packages/server/dist/routes/listeners.js +12 -0
- package/packages/server/dist/routes/listeners.js.map +1 -0
- package/packages/server/dist/routes/memories.d.ts.map +1 -1
- package/packages/server/dist/routes/memories.js +55 -3
- package/packages/server/dist/routes/memories.js.map +1 -1
- package/packages/server/dist/routes/org.d.ts.map +1 -1
- package/packages/server/dist/routes/org.js +289 -49
- package/packages/server/dist/routes/org.js.map +1 -1
- package/packages/server/dist/routes/profile.d.ts.map +1 -1
- package/packages/server/dist/routes/profile.js +6 -3
- package/packages/server/dist/routes/profile.js.map +1 -1
- package/packages/server/dist/routes/providers.d.ts.map +1 -1
- package/packages/server/dist/routes/providers.js +66 -7
- package/packages/server/dist/routes/providers.js.map +1 -1
- package/packages/server/dist/routes/questions.d.ts +45 -0
- package/packages/server/dist/routes/questions.d.ts.map +1 -0
- package/packages/server/dist/routes/questions.js +73 -0
- package/packages/server/dist/routes/questions.js.map +1 -0
- package/packages/server/dist/routes/sessions.d.ts.map +1 -1
- package/packages/server/dist/routes/sessions.js +26 -6
- package/packages/server/dist/routes/sessions.js.map +1 -1
- package/packages/server/dist/routes/sleep.d.ts.map +1 -1
- package/packages/server/dist/routes/sleep.js +71 -2
- package/packages/server/dist/routes/sleep.js.map +1 -1
- package/packages/server/dist/routes/terminals.d.ts +25 -0
- package/packages/server/dist/routes/terminals.d.ts.map +1 -0
- package/packages/server/dist/routes/terminals.js +35 -0
- package/packages/server/dist/routes/terminals.js.map +1 -0
- package/packages/server/dist/routes/tools.d.ts.map +1 -1
- package/packages/server/dist/routes/tools.js +140 -6
- package/packages/server/dist/routes/tools.js.map +1 -1
- package/packages/server/dist/routes/updates.d.ts +10 -0
- package/packages/server/dist/routes/updates.d.ts.map +1 -0
- package/packages/server/dist/routes/updates.js +22 -0
- package/packages/server/dist/routes/updates.js.map +1 -0
- package/packages/server/dist/routes/ws.d.ts +11 -5
- package/packages/server/dist/routes/ws.d.ts.map +1 -1
- package/packages/server/dist/routes/ws.js +168 -28
- package/packages/server/dist/routes/ws.js.map +1 -1
- package/packages/server/dist/schemas.d.ts +1177 -215
- package/packages/server/dist/schemas.d.ts.map +1 -1
- package/packages/server/dist/schemas.js +317 -12
- package/packages/server/dist/schemas.js.map +1 -1
- package/packages/server/dist/server.d.ts +7 -1
- package/packages/server/dist/server.d.ts.map +1 -1
- package/packages/server/dist/server.js +210 -3
- package/packages/server/dist/server.js.map +1 -1
- package/packages/server/dist/services/stream.d.ts +94 -5
- package/packages/server/dist/services/stream.d.ts.map +1 -1
- package/packages/server/dist/services/stream.js +9 -20
- package/packages/server/dist/services/stream.js.map +1 -1
- package/packages/server/dist/services/stt.d.ts +65 -0
- package/packages/server/dist/services/stt.d.ts.map +1 -0
- package/packages/server/dist/services/stt.js +306 -0
- package/packages/server/dist/services/stt.js.map +1 -0
- package/packages/server/dist/services/turns.d.ts +54 -0
- package/packages/server/dist/services/turns.d.ts.map +1 -0
- package/packages/server/dist/services/turns.js +186 -0
- package/packages/server/dist/services/turns.js.map +1 -0
- package/packages/server/dist/services/updates.d.ts +99 -0
- package/packages/server/dist/services/updates.d.ts.map +1 -0
- package/packages/server/dist/services/updates.js +316 -0
- package/packages/server/dist/services/updates.js.map +1 -0
- package/packages/server/package.json +1 -1
- package/packages/web/dist/app-icon.svg +2 -0
- package/packages/web/dist/apple-touch-icon.png +0 -0
- package/packages/web/dist/assets/abnfDiagram-O67JEVCF-D7YyFndQ.js +1 -0
- package/packages/web/dist/assets/arc-C_Zgk2dJ.js +1 -0
- package/packages/web/dist/assets/architectureDiagram-NJMV4G6O-eI0adu1B.js +36 -0
- package/packages/web/dist/assets/blockDiagram-BEXU5L5S-WAoOFUA9.js +140 -0
- package/packages/web/dist/assets/c4Diagram-YGBWAQC7-DE8Zyhng.js +38 -0
- package/packages/web/dist/assets/channel-egZxcyUK.js +1 -0
- package/packages/web/dist/assets/chunk-2Q5K7J3B-bnqLP2XD.js +1 -0
- package/packages/web/dist/assets/chunk-3FUC2YCW-Ck1_SVe0.js +2 -0
- package/packages/web/dist/assets/chunk-5VM5RSS4-hDmC41gD.js +15 -0
- package/packages/web/dist/assets/chunk-GTNCS2PH-PoWvfCrT.js +88 -0
- package/packages/web/dist/assets/chunk-GWA4HPMP-D3V0IG43.js +1 -0
- package/packages/web/dist/assets/chunk-JWPE2WC7-BryfpHM5.js +1 -0
- package/packages/web/dist/assets/chunk-NETBCI7D-8ic1iEdT.js +1 -0
- package/packages/web/dist/assets/chunk-WEXAMYUT-nM8tmQT2.js +1 -0
- package/packages/web/dist/assets/chunk-XXDRQBXY-Do28F482.js +1 -0
- package/packages/web/dist/assets/classDiagram-v2-NBCMYWYE-Bop9oNNO.js +217 -0
- package/packages/web/dist/assets/cose-bilkent-JH36ORCC-a7f_bpnt.js +1 -0
- package/packages/web/dist/assets/cynefin-OW5HDTMX-DnArcis_.js +178 -0
- package/packages/web/dist/assets/cynefinDiagram-VND7K2PF-vEuTb1GD.js +62 -0
- package/packages/web/dist/assets/cytoscape.esm-Ix0LnXOy.js +331 -0
- package/packages/web/dist/assets/dagre-6A5THRUB-BgG4MynJ.js +4 -0
- package/packages/web/dist/assets/diagram-22UHCM2B-DRCQpafv.js +200 -0
- package/packages/web/dist/assets/diagram-3UASUU5V-BKgmAXde.js +24 -0
- package/packages/web/dist/assets/diagram-ATOU4E4O-B6Hsy36X.js +3 -0
- package/packages/web/dist/assets/diagram-CDSNMT55-JflyfyoB.js +30 -0
- package/packages/web/dist/assets/diagram-MLGK6HIB-Dd2QPJjT.js +24 -0
- package/packages/web/dist/assets/diagram-MPIPVDR6-DE5QU60x.js +41 -0
- package/packages/web/dist/assets/draco_decoder-C32yEggz.wasm +0 -0
- package/packages/web/dist/assets/draco_decoder-Z1_iN-Ht.wasm +0 -0
- package/packages/web/dist/assets/draco_decoder-fzg4nYZr.js +34 -0
- package/packages/web/dist/assets/draco_wasm_wrapper-DxJM36Ib.js +117 -0
- package/packages/web/dist/assets/draco_wasm_wrapper-fZCQGLGb.js +116 -0
- package/packages/web/dist/assets/ebnfDiagram-ZINNZB2B-D7AQ741b.js +1 -0
- package/packages/web/dist/assets/elk-276RUBZZ-CeewBVLF.js +27 -0
- package/packages/web/dist/assets/erDiagram-OPXOYQCR-mLLYkZ5c.js +99 -0
- package/packages/web/dist/assets/flowDiagram-KWPJA3E3-DtpSpsQN.js +213 -0
- package/packages/web/dist/assets/ganttDiagram-FUAMR5RP-1_lh-3ky.js +292 -0
- package/packages/web/dist/assets/gitGraphDiagram-X574FWY7-DoPXZuT5.js +106 -0
- package/packages/web/dist/assets/graph-Bn3Yngep.js +1 -0
- package/packages/web/dist/assets/index-Cw2Opmx7.js +648 -0
- package/packages/web/dist/assets/index-j0zBRCgT.css +32 -0
- package/packages/web/dist/assets/infoDiagram-VRGFBTTK-DQpRGGiD.js +2 -0
- package/packages/web/dist/assets/ishikawaDiagram-OU5B5YK6-gH5C9Q2e.js +70 -0
- package/packages/web/dist/assets/journeyDiagram-ZHPQQLJL-Bg-oeFjb.js +139 -0
- package/packages/web/dist/assets/kanban-definition-PNTS6WVX-BnpI4VH8.js +89 -0
- package/packages/web/dist/assets/katex-C5jXJg4s.js +257 -0
- package/packages/web/dist/assets/mermaid.core-BwBKxlRA.js +313 -0
- package/packages/web/dist/assets/mindmap-definition-NLK3R4M7-NBnnxEoO.js +96 -0
- package/packages/web/dist/assets/pegDiagram-GJSIUBJH-RrXXbIvO.js +1 -0
- package/packages/web/dist/assets/pieDiagram-5QR66LMP-B27q6Gso.js +39 -0
- package/packages/web/dist/assets/quadrantDiagram-O4NWA36T-DGDsdur2.js +7 -0
- package/packages/web/dist/assets/railroadDiagram-XR7U4H2S-GdjkE3mI.js +1 -0
- package/packages/web/dist/assets/requirementDiagram-PLB6GJNP-DjK0GfgO.js +84 -0
- package/packages/web/dist/assets/sankeyDiagram-IPEJSGJF-BG_AIkwF.js +40 -0
- package/packages/web/dist/assets/scene-D4LPicHk.js +4620 -0
- package/packages/web/dist/assets/sequenceDiagram-PO4LG4MO-CIQwUb4y.js +169 -0
- package/packages/web/dist/assets/sizeCapture-INFHLROL-bpIoPxdJ.js +1 -0
- package/packages/web/dist/assets/stateDiagram-v2-GCMORJYK-8hYXvPPv.js +291 -0
- package/packages/web/dist/assets/swimlanes-2SLR337P-gfflUMF9.js +1 -0
- package/packages/web/dist/assets/swimlanesDiagram-TC7HE7FX-9wdzGXU-.js +8 -0
- package/packages/web/dist/assets/timeline-definition-EJHVYXUP-PHMNoGTZ.js +120 -0
- package/packages/web/dist/assets/usecaseDiagram-POWQR4AR-B2j5iteO.js +370 -0
- package/packages/web/dist/assets/vennDiagram-UO4OBE2U-BzxtZ-_2.js +34 -0
- package/packages/web/dist/assets/wardleyDiagram-VNRHLVJA-DL7YbMpY.js +78 -0
- package/packages/web/dist/assets/xychartDiagram-PMCCYNJV-CisgP1cT.js +7 -0
- package/packages/web/dist/draco/draco_decoder.js +33 -0
- package/packages/web/dist/draco/draco_decoder.wasm +0 -0
- package/packages/web/dist/draco/draco_wasm_wrapper.js +116 -0
- package/packages/web/dist/favicon-16.png +0 -0
- package/packages/web/dist/favicon-32.png +0 -0
- package/packages/web/dist/favicon-48.png +0 -0
- package/packages/web/dist/favicon.ico +0 -0
- package/packages/web/dist/favicon.svg +1 -1
- package/packages/web/dist/icon-192.png +0 -0
- package/packages/web/dist/icon-512.png +0 -0
- package/packages/web/dist/index.html +12 -4
- package/packages/web/dist/logo-light.svg +1 -1
- package/packages/web/dist/logo-mono.svg +2 -0
- package/packages/web/dist/logo-stacked-light.svg +2 -0
- package/packages/web/dist/logo-stacked.svg +2 -0
- package/packages/web/dist/logo-white.svg +2 -0
- package/packages/web/dist/logo.svg +1 -1
- package/packages/web/dist/mark-light.svg +1 -1
- package/packages/web/dist/mark-mono.svg +2 -0
- package/packages/web/dist/mark-small-light.svg +2 -0
- package/packages/web/dist/mark-small.svg +2 -0
- package/packages/web/dist/mark-white.svg +2 -0
- package/packages/web/dist/mark.svg +1 -1
- package/packages/web/dist/models/LICENSE.txt +5 -0
- package/packages/web/dist/models/brain.glb +0 -0
- package/packages/web/dist/site.webmanifest +23 -0
- package/packages/web/dist/wordmark-light.svg +2 -0
- package/packages/web/dist/wordmark.svg +2 -0
- package/packages/web/package.json +1 -1
- package/scripts/rookery.mjs +204 -122
- package/scripts/updater.mjs +227 -0
- package/packages/cli/dist/tui/components/Wordmark.d.ts +0 -35
- package/packages/cli/dist/tui/components/Wordmark.d.ts.map +0 -1
- package/packages/cli/dist/tui/components/Wordmark.js +0 -81
- package/packages/cli/dist/tui/components/Wordmark.js.map +0 -1
- package/packages/core/dist/agents/orchestrator.d.ts +0 -24
- package/packages/core/dist/agents/orchestrator.d.ts.map +0 -1
- package/packages/core/dist/agents/orchestrator.js +0 -88
- package/packages/core/dist/agents/orchestrator.js.map +0 -1
- package/packages/core/dist/agents/roles.d.ts +0 -21
- package/packages/core/dist/agents/roles.d.ts.map +0 -1
- package/packages/core/dist/agents/roles.js +0 -81
- package/packages/core/dist/agents/roles.js.map +0 -1
- package/packages/core/dist/agents/team.d.ts +0 -105
- package/packages/core/dist/agents/team.d.ts.map +0 -1
- package/packages/core/dist/agents/team.js +0 -623
- package/packages/core/dist/agents/team.js.map +0 -1
- package/packages/core/dist/providers/codex.d.ts +0 -10
- package/packages/core/dist/providers/codex.d.ts.map +0 -1
- package/packages/core/dist/providers/codex.js +0 -375
- package/packages/core/dist/providers/codex.js.map +0 -1
- package/packages/core/dist/tools/browser.d.ts +0 -20
- package/packages/core/dist/tools/browser.d.ts.map +0 -1
- package/packages/core/dist/tools/browser.js +0 -72
- package/packages/core/dist/tools/browser.js.map +0 -1
- package/packages/server/dist/routes/agents.d.ts +0 -5
- package/packages/server/dist/routes/agents.d.ts.map +0 -1
- package/packages/server/dist/routes/agents.js +0 -6
- package/packages/server/dist/routes/agents.js.map +0 -1
- package/packages/server/dist/routes/team.d.ts +0 -11
- package/packages/server/dist/routes/team.d.ts.map +0 -1
- package/packages/server/dist/routes/team.js +0 -36
- package/packages/server/dist/routes/team.js.map +0 -1
- package/packages/web/dist/assets/3d-force-graph-BPZmoydi.js +0 -1163
- package/packages/web/dist/assets/index-IBSTzK7-.js +0 -1255
- package/packages/web/dist/assets/index-qUXUui7W.css +0 -1
- package/packages/web/dist/assets/three-spritetext-B9ZIW7c-.js +0 -4
- package/packages/web/dist/assets/three.module-cmFfBtHS.js +0 -4228
|
@@ -0,0 +1,1118 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { open, readdir, readFile, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { homedir } from 'node:os';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { quoteForCmd } from './process.js';
|
|
7
|
+
import { userSettingsGuard } from './user-settings-guard.js';
|
|
8
|
+
/** How much screen output a late viewer gets replayed, in characters. */
|
|
9
|
+
const REPLAY_LIMIT = 1_000_000;
|
|
10
|
+
/** How long a finished agent's terminal stays open before it is killed. */
|
|
11
|
+
export const TUI_LINGER_MS = 10 * 60 * 1000;
|
|
12
|
+
/** A size that fits the run page; the browser resizes to its own right away. */
|
|
13
|
+
const DEFAULT_COLS = 120;
|
|
14
|
+
const DEFAULT_ROWS = 34;
|
|
15
|
+
/** Longer prompts go to a file: argv on Windows ends at 32 767 characters. */
|
|
16
|
+
const INLINE_PROMPT_LIMIT = 12_000;
|
|
17
|
+
/**
|
|
18
|
+
* No screen output and no transcript growth for this long means the terminal
|
|
19
|
+
* waits for input nobody is giving - a permission question, or a run that
|
|
20
|
+
* was interrupted with Esc and never told what to do next. Until then a
|
|
21
|
+
* person can still answer it from the run page.
|
|
22
|
+
*/
|
|
23
|
+
const IDLE_LIMIT_MS = 15 * 60 * 1000;
|
|
24
|
+
/** How long the transcript may trail the Stop hook before it is read as is. */
|
|
25
|
+
const SETTLE_LIMIT_MS = 3000;
|
|
26
|
+
const POLL_MS = 250;
|
|
27
|
+
let ptyModule;
|
|
28
|
+
/**
|
|
29
|
+
* The native pty binding, or `null` where it cannot load (a platform without
|
|
30
|
+
* a prebuilt binary). Callers fall back to the headless run then.
|
|
31
|
+
*/
|
|
32
|
+
export function loadPty() {
|
|
33
|
+
ptyModule ??= import('@lydell/node-pty')
|
|
34
|
+
.then((module) => module)
|
|
35
|
+
.catch(() => null);
|
|
36
|
+
return ptyModule;
|
|
37
|
+
}
|
|
38
|
+
let mirrorModule;
|
|
39
|
+
/**
|
|
40
|
+
* A terminal emulator with no screen, fed the same bytes as the browser.
|
|
41
|
+
*
|
|
42
|
+
* A viewer that opens a terminal late used to get the raw byte history
|
|
43
|
+
* replayed - cursor moves and partial repaints computed for whatever size
|
|
44
|
+
* the terminal had back then, cut off at a byte limit wherever that fell.
|
|
45
|
+
* Played into a terminal of another size that came out skewed: prompt bars
|
|
46
|
+
* twice, lines broken halfway, colour runs ending in the wrong place. The
|
|
47
|
+
* mirror keeps the screen as it actually is, and a late viewer gets that,
|
|
48
|
+
* serialized - colours and all - at the size the process has now.
|
|
49
|
+
*/
|
|
50
|
+
function loadMirror() {
|
|
51
|
+
mirrorModule ??= Promise.all([import('@xterm/headless'), import('@xterm/addon-serialize')])
|
|
52
|
+
.then(([headless, serialize]) => {
|
|
53
|
+
const Terminal = headless.Terminal ??
|
|
54
|
+
headless.default.Terminal;
|
|
55
|
+
const SerializeAddon = serialize.SerializeAddon ??
|
|
56
|
+
serialize.default.SerializeAddon;
|
|
57
|
+
return (cols, rows) => {
|
|
58
|
+
const TerminalClass = Terminal;
|
|
59
|
+
const SerializeClass = SerializeAddon;
|
|
60
|
+
const term = new TerminalClass({ cols, rows, scrollback: 5000, allowProposedApi: true });
|
|
61
|
+
const addon = new SerializeClass();
|
|
62
|
+
term.loadAddon(addon);
|
|
63
|
+
return {
|
|
64
|
+
write: (data, done) => term.write(data, done),
|
|
65
|
+
// Queued behind what is still waiting to be parsed: a write is
|
|
66
|
+
// processed later, a resize at once, and bytes painted for the old
|
|
67
|
+
// width then landed on the new one - overlapping, skewed lines.
|
|
68
|
+
resize: (c, r) => term.write('', () => term.resize(c, r)),
|
|
69
|
+
serialize: () => addon.serialize(),
|
|
70
|
+
text: () => {
|
|
71
|
+
const buffer = term.buffer.active;
|
|
72
|
+
const lines = [];
|
|
73
|
+
for (let y = buffer.viewportY; y < buffer.viewportY + term.rows; y += 1) {
|
|
74
|
+
lines.push(buffer.getLine(y)?.translateToString(true) ?? '');
|
|
75
|
+
}
|
|
76
|
+
return lines.join('\n');
|
|
77
|
+
},
|
|
78
|
+
dispose: () => term.dispose(),
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
})
|
|
82
|
+
.catch(() => null);
|
|
83
|
+
return mirrorModule;
|
|
84
|
+
}
|
|
85
|
+
// Loaded up front, not with the first terminal. The mirror replays what was
|
|
86
|
+
// painted before it existed, at the size it is created with; if the module
|
|
87
|
+
// took its time on first use, a browser could resize the process in between,
|
|
88
|
+
// and the early bytes were then replayed at the wrong width.
|
|
89
|
+
void loadMirror();
|
|
90
|
+
const PASTE_ON = String.fromCharCode(27) + '[?2004h';
|
|
91
|
+
const PASTE_OFF = String.fromCharCode(27) + '[?2004l';
|
|
92
|
+
class TuiSession {
|
|
93
|
+
info;
|
|
94
|
+
pty;
|
|
95
|
+
cleanup;
|
|
96
|
+
lingerMs;
|
|
97
|
+
buffer = '';
|
|
98
|
+
lingerTimer;
|
|
99
|
+
/** The screen as it is, for late viewers; unset where the emulator cannot load. */
|
|
100
|
+
mirror;
|
|
101
|
+
/** Whether the TUI has bracketed paste switched on right now. */
|
|
102
|
+
pasteMode = false;
|
|
103
|
+
constructor(info, pty, cleanup, lingerMs) {
|
|
104
|
+
this.info = info;
|
|
105
|
+
this.pty = pty;
|
|
106
|
+
this.cleanup = cleanup;
|
|
107
|
+
this.lingerMs = lingerMs;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Every terminal that is still open, by assignment id.
|
|
112
|
+
*
|
|
113
|
+
* One per process, like the codex bridge: the provider starts sessions, the
|
|
114
|
+
* server streams them to browsers, and both have to find the same ones.
|
|
115
|
+
* Events: `data` (key, chunk), `state` (info), `exit` (key).
|
|
116
|
+
*/
|
|
117
|
+
export class TuiSessionRegistry extends EventEmitter {
|
|
118
|
+
#sessions = new Map();
|
|
119
|
+
/** Registers a freshly spawned pty; an older session under the same key is killed. */
|
|
120
|
+
attach(key, pty, providerSessionId, cleanup, lingerMs = TUI_LINGER_MS) {
|
|
121
|
+
this.kill(key);
|
|
122
|
+
const session = new TuiSession({ key, providerSessionId, state: 'running', startedAt: Date.now(), cols: DEFAULT_COLS, rows: DEFAULT_ROWS }, pty, cleanup, lingerMs);
|
|
123
|
+
this.#sessions.set(key, session);
|
|
124
|
+
// Everything painted before the emulator was ready is still in the raw
|
|
125
|
+
// buffer; it goes in first, and every later chunk after it.
|
|
126
|
+
void loadMirror().then((create) => {
|
|
127
|
+
if (!create || this.#sessions.get(key) !== session)
|
|
128
|
+
return;
|
|
129
|
+
const mirror = create(session.info.cols, session.info.rows);
|
|
130
|
+
mirror.write(session.buffer);
|
|
131
|
+
session.mirror = mirror;
|
|
132
|
+
});
|
|
133
|
+
pty.onData((data) => {
|
|
134
|
+
if (this.#sessions.get(key) !== session)
|
|
135
|
+
return;
|
|
136
|
+
session.buffer = (session.buffer + data).slice(-REPLAY_LIMIT);
|
|
137
|
+
session.mirror?.write(data);
|
|
138
|
+
const on = data.lastIndexOf(PASTE_ON);
|
|
139
|
+
const off = data.lastIndexOf(PASTE_OFF);
|
|
140
|
+
if (on !== off)
|
|
141
|
+
session.pasteMode = on > off;
|
|
142
|
+
this.emit('data', key, data);
|
|
143
|
+
});
|
|
144
|
+
pty.onExit(() => {
|
|
145
|
+
clearTimeout(session.lingerTimer);
|
|
146
|
+
session.mirror?.dispose();
|
|
147
|
+
session.mirror = undefined;
|
|
148
|
+
session.cleanup();
|
|
149
|
+
if (this.#sessions.get(key) !== session)
|
|
150
|
+
return;
|
|
151
|
+
this.#sessions.delete(key);
|
|
152
|
+
session.info.state = 'exited';
|
|
153
|
+
this.emit('state', { ...session.info });
|
|
154
|
+
this.emit('exit', key);
|
|
155
|
+
});
|
|
156
|
+
this.emit('state', { ...session.info });
|
|
157
|
+
}
|
|
158
|
+
/** Terminals currently attached, whether their run is working or waiting. */
|
|
159
|
+
get size() {
|
|
160
|
+
return this.#sessions.size;
|
|
161
|
+
}
|
|
162
|
+
info(key) {
|
|
163
|
+
const session = this.#sessions.get(key);
|
|
164
|
+
return session ? { ...session.info } : null;
|
|
165
|
+
}
|
|
166
|
+
list() {
|
|
167
|
+
return [...this.#sessions.values()].map((session) => ({ ...session.info }));
|
|
168
|
+
}
|
|
169
|
+
/** The raw output so far - what the process wrote, not what the screen shows. */
|
|
170
|
+
snapshot(key) {
|
|
171
|
+
const session = this.#sessions.get(key);
|
|
172
|
+
return session ? { info: { ...session.info }, data: session.buffer } : null;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* The screen as it is now, for a viewer that opens the terminal late:
|
|
176
|
+
* scrollback and visible screen serialized at the process's current size.
|
|
177
|
+
* Falls back to the raw output where there is no emulator.
|
|
178
|
+
*/
|
|
179
|
+
async screen(key) {
|
|
180
|
+
const session = this.#sessions.get(key);
|
|
181
|
+
if (!session)
|
|
182
|
+
return null;
|
|
183
|
+
const mirror = session.mirror;
|
|
184
|
+
if (!mirror)
|
|
185
|
+
return { info: { ...session.info }, data: session.buffer };
|
|
186
|
+
// Parsing is asynchronous; wait until what has arrived is on the screen.
|
|
187
|
+
await new Promise((resolve) => mirror.write('', resolve));
|
|
188
|
+
if (session.mirror !== mirror)
|
|
189
|
+
return this.snapshot(key);
|
|
190
|
+
return { info: { ...session.info }, data: mirror.serialize() };
|
|
191
|
+
}
|
|
192
|
+
/** What the screen shows right now as plain text, or null without an emulator. */
|
|
193
|
+
screenText(key) {
|
|
194
|
+
return this.#sessions.get(key)?.mirror?.text() ?? null;
|
|
195
|
+
}
|
|
196
|
+
/** Whether the TUI takes pasted text as one paste right now. */
|
|
197
|
+
pasteMode(key) {
|
|
198
|
+
return this.#sessions.get(key)?.pasteMode ?? false;
|
|
199
|
+
}
|
|
200
|
+
/** Keystrokes from a person. Typing into a finished terminal keeps it open longer. */
|
|
201
|
+
write(key, data) {
|
|
202
|
+
const session = this.#sessions.get(key);
|
|
203
|
+
if (!session)
|
|
204
|
+
return false;
|
|
205
|
+
session.pty.write(data);
|
|
206
|
+
if (session.info.state === 'idle')
|
|
207
|
+
this.linger(key);
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
resize(key, cols, rows) {
|
|
211
|
+
const session = this.#sessions.get(key);
|
|
212
|
+
if (!session)
|
|
213
|
+
return;
|
|
214
|
+
const c = Math.max(20, Math.min(400, Math.floor(cols)));
|
|
215
|
+
const r = Math.max(5, Math.min(200, Math.floor(rows)));
|
|
216
|
+
if (c === session.info.cols && r === session.info.rows)
|
|
217
|
+
return;
|
|
218
|
+
try {
|
|
219
|
+
session.pty.resize(c, r);
|
|
220
|
+
session.mirror?.resize(c, r);
|
|
221
|
+
session.info.cols = c;
|
|
222
|
+
session.info.rows = r;
|
|
223
|
+
// Every other viewer of this terminal follows the new size instead of
|
|
224
|
+
// fighting it with its own (run-terminal.tsx).
|
|
225
|
+
this.emit('state', { ...session.info });
|
|
226
|
+
}
|
|
227
|
+
catch {
|
|
228
|
+
// A pty that is exiting refuses a resize; nothing to keep.
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Work started (again): a person typed into a conversation terminal. The
|
|
233
|
+
* countdown a finished turn set is off while Claude is working.
|
|
234
|
+
*/
|
|
235
|
+
markRunning(key) {
|
|
236
|
+
const session = this.#sessions.get(key);
|
|
237
|
+
if (!session)
|
|
238
|
+
return;
|
|
239
|
+
clearTimeout(session.lingerTimer);
|
|
240
|
+
if (session.info.state === 'running')
|
|
241
|
+
return;
|
|
242
|
+
session.info.state = 'running';
|
|
243
|
+
this.emit('state', { ...session.info });
|
|
244
|
+
}
|
|
245
|
+
/** The work is over: the terminal stays open, then goes. */
|
|
246
|
+
linger(key) {
|
|
247
|
+
const session = this.#sessions.get(key);
|
|
248
|
+
if (!session)
|
|
249
|
+
return;
|
|
250
|
+
const ms = session.lingerMs;
|
|
251
|
+
clearTimeout(session.lingerTimer);
|
|
252
|
+
if (session.info.state !== 'idle') {
|
|
253
|
+
session.info.state = 'idle';
|
|
254
|
+
this.emit('state', { ...session.info });
|
|
255
|
+
}
|
|
256
|
+
session.lingerTimer = setTimeout(() => this.kill(key), ms);
|
|
257
|
+
session.lingerTimer.unref?.();
|
|
258
|
+
}
|
|
259
|
+
kill(key) {
|
|
260
|
+
const session = this.#sessions.get(key);
|
|
261
|
+
if (!session)
|
|
262
|
+
return false;
|
|
263
|
+
clearTimeout(session.lingerTimer);
|
|
264
|
+
try {
|
|
265
|
+
session.pty.kill();
|
|
266
|
+
}
|
|
267
|
+
catch {
|
|
268
|
+
// Already gone; the exit handler has done or will do the rest.
|
|
269
|
+
}
|
|
270
|
+
return true;
|
|
271
|
+
}
|
|
272
|
+
/** Server shutdown: no terminal outlives the process that owns it. */
|
|
273
|
+
killAll() {
|
|
274
|
+
for (const key of [...this.#sessions.keys()])
|
|
275
|
+
this.kill(key);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
export const tuiSessions = new TuiSessionRegistry();
|
|
279
|
+
/** The Stop hook's command: the payload on stdin, verbatim into the marker file. */
|
|
280
|
+
export function stopHookCommand(markerFile) {
|
|
281
|
+
const node = process.execPath.replace(/\\/g, '/');
|
|
282
|
+
const target = markerFile.replace(/\\/g, '/').replace(/'/g, "\\'");
|
|
283
|
+
return `"${node}" -e "require('fs').writeFileSync('${target}', require('fs').readFileSync(0))"`;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Environment for the child. A Rookery started from inside a Claude Code
|
|
287
|
+
* session inherits that session's markers, and with
|
|
288
|
+
* `CLAUDE_CODE_CHILD_SESSION` set the new process quietly stops writing its
|
|
289
|
+
* transcript - which is everything this mode reads.
|
|
290
|
+
*/
|
|
291
|
+
function childEnv(extra) {
|
|
292
|
+
const env = {};
|
|
293
|
+
for (const [name, value] of Object.entries(process.env)) {
|
|
294
|
+
if (value === undefined)
|
|
295
|
+
continue;
|
|
296
|
+
if (name === 'CLAUDECODE' || name.startsWith('CLAUDE_CODE_'))
|
|
297
|
+
continue;
|
|
298
|
+
env[name] = value;
|
|
299
|
+
}
|
|
300
|
+
for (const [name, value] of Object.entries(extra)) {
|
|
301
|
+
if (value !== undefined)
|
|
302
|
+
env[name] = value;
|
|
303
|
+
}
|
|
304
|
+
env.TERM = 'xterm-256color';
|
|
305
|
+
env.COLORTERM = 'truecolor';
|
|
306
|
+
return env;
|
|
307
|
+
}
|
|
308
|
+
const ESC = String.fromCharCode(27);
|
|
309
|
+
/** Screen text without escape sequences and whitespace, for spotting a dialog. */
|
|
310
|
+
function flatten(screen) {
|
|
311
|
+
return screen
|
|
312
|
+
.split(ESC)
|
|
313
|
+
.join('')
|
|
314
|
+
.replace(/\[[0-9;?]*[ -/]*[@-~]/g, '')
|
|
315
|
+
.replace(/\s+/g, '');
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* First-run dialogs a print run never shows, and the answer a person would
|
|
319
|
+
* give. The folder is one Rookery already works in; the bypass warning only
|
|
320
|
+
* appears for a `full` agent, which is a setting somebody chose.
|
|
321
|
+
*/
|
|
322
|
+
const STARTUP_DIALOGS = [
|
|
323
|
+
{ marker: 'Yes,Itrustthisfolder', keys: ESC + '[B' },
|
|
324
|
+
{ marker: 'Yes,Iaccept', keys: ESC + '[B' },
|
|
325
|
+
];
|
|
326
|
+
function configDir(env) {
|
|
327
|
+
return env.CLAUDE_CONFIG_DIR || process.env.CLAUDE_CONFIG_DIR || join(homedir(), '.claude');
|
|
328
|
+
}
|
|
329
|
+
/** The transcript file, once Claude Code has created it. */
|
|
330
|
+
async function findTranscript(root, sessionId) {
|
|
331
|
+
const projects = join(root, 'projects');
|
|
332
|
+
let folders;
|
|
333
|
+
try {
|
|
334
|
+
folders = await readdir(projects);
|
|
335
|
+
}
|
|
336
|
+
catch {
|
|
337
|
+
return null;
|
|
338
|
+
}
|
|
339
|
+
for (const folder of folders) {
|
|
340
|
+
const candidate = join(projects, folder, sessionId + '.jsonl');
|
|
341
|
+
if (existsSync(candidate))
|
|
342
|
+
return candidate;
|
|
343
|
+
}
|
|
344
|
+
return null;
|
|
345
|
+
}
|
|
346
|
+
/** Reads a growing JSONL file from where the last call stopped. */
|
|
347
|
+
class TranscriptTail {
|
|
348
|
+
path;
|
|
349
|
+
#offset = 0;
|
|
350
|
+
#partial = '';
|
|
351
|
+
#seen = new Set();
|
|
352
|
+
constructor(path) {
|
|
353
|
+
this.path = path;
|
|
354
|
+
}
|
|
355
|
+
/** Starts at the current end: a resumed session's history is not news. */
|
|
356
|
+
async skipToEnd() {
|
|
357
|
+
try {
|
|
358
|
+
const handle = await open(this.path, 'r');
|
|
359
|
+
try {
|
|
360
|
+
this.#offset = (await handle.stat()).size;
|
|
361
|
+
}
|
|
362
|
+
finally {
|
|
363
|
+
await handle.close();
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
catch {
|
|
367
|
+
// Not there yet: then everything in it will be new.
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
async read() {
|
|
371
|
+
let handle;
|
|
372
|
+
try {
|
|
373
|
+
handle = await open(this.path, 'r');
|
|
374
|
+
}
|
|
375
|
+
catch {
|
|
376
|
+
return [];
|
|
377
|
+
}
|
|
378
|
+
try {
|
|
379
|
+
const { size } = await handle.stat();
|
|
380
|
+
if (size <= this.#offset)
|
|
381
|
+
return [];
|
|
382
|
+
const buffer = Buffer.alloc(size - this.#offset);
|
|
383
|
+
await handle.read(buffer, 0, buffer.length, this.#offset);
|
|
384
|
+
this.#offset = size;
|
|
385
|
+
const text = this.#partial + buffer.toString('utf8');
|
|
386
|
+
const lines = text.split('\n');
|
|
387
|
+
this.#partial = lines.pop() ?? '';
|
|
388
|
+
const entries = [];
|
|
389
|
+
for (const line of lines) {
|
|
390
|
+
if (!line.trim())
|
|
391
|
+
continue;
|
|
392
|
+
try {
|
|
393
|
+
const entry = JSON.parse(line);
|
|
394
|
+
const id = typeof entry.uuid === 'string' ? entry.uuid : undefined;
|
|
395
|
+
if (id) {
|
|
396
|
+
if (this.#seen.has(id))
|
|
397
|
+
continue;
|
|
398
|
+
this.#seen.add(id);
|
|
399
|
+
}
|
|
400
|
+
entries.push(entry);
|
|
401
|
+
}
|
|
402
|
+
catch {
|
|
403
|
+
// A torn line is completed by the next read; a broken one is skipped.
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
return entries;
|
|
407
|
+
}
|
|
408
|
+
finally {
|
|
409
|
+
await handle.close();
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* What a person typed, out of one `user` transcript entry - or `null` for
|
|
415
|
+
* the entries that only look like one: tool results, and the wrappers Claude
|
|
416
|
+
* Code writes for slash commands and its own reminders.
|
|
417
|
+
*/
|
|
418
|
+
function typedPrompt(entry) {
|
|
419
|
+
if (entry.type !== 'user' || entry.isMeta === true || entry.isSidechain === true)
|
|
420
|
+
return null;
|
|
421
|
+
const message = entry.message;
|
|
422
|
+
const content = message?.content;
|
|
423
|
+
let text = '';
|
|
424
|
+
if (typeof content === 'string')
|
|
425
|
+
text = content;
|
|
426
|
+
else if (Array.isArray(content)) {
|
|
427
|
+
const blocks = content;
|
|
428
|
+
if (blocks.some((block) => block.type === 'tool_result'))
|
|
429
|
+
return null;
|
|
430
|
+
text = blocks.map((block) => (block.type === 'text' && typeof block.text === 'string' ? block.text : '')).join('\n');
|
|
431
|
+
}
|
|
432
|
+
text = text.trim();
|
|
433
|
+
if (!text || text.startsWith('<'))
|
|
434
|
+
return null;
|
|
435
|
+
return text;
|
|
436
|
+
}
|
|
437
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
438
|
+
/** A spawned terminal, and what its transcript has said so far. */
|
|
439
|
+
class TerminalWatch {
|
|
440
|
+
spec;
|
|
441
|
+
resumed;
|
|
442
|
+
exitCode = null;
|
|
443
|
+
lastActivity = Date.now();
|
|
444
|
+
/** The last time the screen changed - quiet here means the TUI sits at its prompt. */
|
|
445
|
+
lastScreen = Date.now();
|
|
446
|
+
/** The newest text block - what a print run reports as its result. */
|
|
447
|
+
lastBlock = '';
|
|
448
|
+
/** Assistant entries read so far; growth after a Stop means work went on. */
|
|
449
|
+
assistantEntries = 0;
|
|
450
|
+
apiError = null;
|
|
451
|
+
contextTokens;
|
|
452
|
+
/** The model of the newest assistant entry - `/model` can change it mid-session. */
|
|
453
|
+
model;
|
|
454
|
+
#tail = null;
|
|
455
|
+
#root;
|
|
456
|
+
constructor(spec,
|
|
457
|
+
/** A resumed session: its transcript already has a history to skip. */
|
|
458
|
+
resumed) {
|
|
459
|
+
this.spec = spec;
|
|
460
|
+
this.resumed = resumed;
|
|
461
|
+
this.#root = configDir(spec.env);
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* New transcript entries, as the events a print run would have streamed.
|
|
465
|
+
* What a person typed comes out as a `status` event labelled `input`, in
|
|
466
|
+
* its place between the answers.
|
|
467
|
+
*/
|
|
468
|
+
async read() {
|
|
469
|
+
if (!this.#tail) {
|
|
470
|
+
const path = await findTranscript(this.#root, this.spec.sessionId);
|
|
471
|
+
if (!path)
|
|
472
|
+
return [];
|
|
473
|
+
this.#tail = new TranscriptTail(path);
|
|
474
|
+
if (this.resumed)
|
|
475
|
+
await this.#tail.skipToEnd();
|
|
476
|
+
}
|
|
477
|
+
const events = [];
|
|
478
|
+
for (const entry of await this.#tail.read()) {
|
|
479
|
+
this.lastActivity = Date.now();
|
|
480
|
+
if (entry.isSidechain === true)
|
|
481
|
+
continue;
|
|
482
|
+
const typed = typedPrompt(entry);
|
|
483
|
+
if (typed !== null) {
|
|
484
|
+
events.push({ type: 'status', label: 'input', detail: typed });
|
|
485
|
+
continue;
|
|
486
|
+
}
|
|
487
|
+
if (entry.type === 'assistant') {
|
|
488
|
+
this.assistantEntries += 1;
|
|
489
|
+
const message = entry.message;
|
|
490
|
+
if (typeof message?.model === 'string' && message.model !== '<synthetic>')
|
|
491
|
+
this.model = message.model;
|
|
492
|
+
const usage = message?.usage;
|
|
493
|
+
if (usage) {
|
|
494
|
+
const parts = [usage.input_tokens, usage.cache_read_input_tokens, usage.cache_creation_input_tokens].filter((value) => typeof value === 'number');
|
|
495
|
+
if (parts.length)
|
|
496
|
+
this.contextTokens = parts.reduce((sum, value) => sum + value, 0);
|
|
497
|
+
}
|
|
498
|
+
if (entry.isApiErrorMessage === true) {
|
|
499
|
+
const content = Array.isArray(message?.content) ? message.content : [];
|
|
500
|
+
this.apiError =
|
|
501
|
+
content
|
|
502
|
+
.map((block) => (typeof block.text === 'string' ? block.text : ''))
|
|
503
|
+
.join(' ')
|
|
504
|
+
.trim() || 'The API returned an error.';
|
|
505
|
+
continue;
|
|
506
|
+
}
|
|
507
|
+
this.apiError = null;
|
|
508
|
+
}
|
|
509
|
+
for (const event of this.spec.mapEntry(entry)) {
|
|
510
|
+
if (event.type === 'text')
|
|
511
|
+
this.lastBlock = event.delta.replace(/^\n\n/, '');
|
|
512
|
+
events.push(event);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
return events;
|
|
516
|
+
}
|
|
517
|
+
/** The Stop hook's payload, once it has written one. */
|
|
518
|
+
async marker() {
|
|
519
|
+
try {
|
|
520
|
+
const raw = await readFile(this.spec.markerFile, 'utf8');
|
|
521
|
+
return raw.trim() ? JSON.parse(raw) : null;
|
|
522
|
+
}
|
|
523
|
+
catch {
|
|
524
|
+
return null;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
async clearMarker() {
|
|
528
|
+
await writeFile(this.spec.markerFile, '').catch(() => undefined);
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* After a Stop: read until the reported message is in the transcript (it
|
|
532
|
+
* can trail the hook), then look once more. New assistant entries a moment
|
|
533
|
+
* later mean a Stop hook of the person's own answered "block" and Claude
|
|
534
|
+
* Code kept working - this stop was not the end.
|
|
535
|
+
*/
|
|
536
|
+
async settle(reported) {
|
|
537
|
+
const events = [];
|
|
538
|
+
for (let waited = 0; waited < SETTLE_LIMIT_MS; waited += POLL_MS) {
|
|
539
|
+
events.push(...(await this.read()));
|
|
540
|
+
if (!reported || this.lastBlock.trim() === reported)
|
|
541
|
+
break;
|
|
542
|
+
await sleep(POLL_MS);
|
|
543
|
+
}
|
|
544
|
+
const before = this.assistantEntries;
|
|
545
|
+
await sleep(4 * POLL_MS);
|
|
546
|
+
events.push(...(await this.read()));
|
|
547
|
+
return { events, holds: this.assistantEntries === before };
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
/** Starts Claude Code in a pty and registers it. Throws only before the process exists. */
|
|
551
|
+
async function spawnTerminal(spec, resumed) {
|
|
552
|
+
const pty = await loadPty();
|
|
553
|
+
if (!pty)
|
|
554
|
+
throw new Error('Terminal support is not available on this system.');
|
|
555
|
+
// Through a `.cmd` shim the whole command line is cmd.exe's to parse, and
|
|
556
|
+
// a task is outside text - a mail can carry quotes, `&` or `%VAR%`. It
|
|
557
|
+
// never goes on that line: the file holds it, the line only points there.
|
|
558
|
+
let prompt = spec.prompt;
|
|
559
|
+
if (prompt !== undefined && (prompt.length > INLINE_PROMPT_LIMIT || spec.binary.isShim)) {
|
|
560
|
+
const file = join(spec.workDir, 'task.md');
|
|
561
|
+
await writeFile(file, prompt);
|
|
562
|
+
prompt =
|
|
563
|
+
'Your task is written down in the file ' +
|
|
564
|
+
file.replace(/\\/g, '/') +
|
|
565
|
+
' - read all of it first, then do exactly what it says.';
|
|
566
|
+
}
|
|
567
|
+
const env = childEnv(spec.env);
|
|
568
|
+
const argv = prompt !== undefined ? [...spec.args, prompt] : spec.args;
|
|
569
|
+
const options = {
|
|
570
|
+
name: 'xterm-256color',
|
|
571
|
+
cols: DEFAULT_COLS,
|
|
572
|
+
rows: DEFAULT_ROWS,
|
|
573
|
+
...(spec.cwd ? { cwd: spec.cwd } : {}),
|
|
574
|
+
env,
|
|
575
|
+
};
|
|
576
|
+
// This is Rookery's terminal, not the person's own `claude`: a model picked
|
|
577
|
+
// here with Enter must not become their global default.
|
|
578
|
+
const release = userSettingsGuard.acquire(configDir(spec.env));
|
|
579
|
+
let child;
|
|
580
|
+
try {
|
|
581
|
+
child = spec.binary.isShim
|
|
582
|
+
? pty.spawn(env.COMSPEC ?? 'cmd.exe', '/d /s /c ' + quoteForCmd([spec.binary.path, ...argv]), options)
|
|
583
|
+
: pty.spawn(spec.binary.path, argv, options);
|
|
584
|
+
}
|
|
585
|
+
catch (error) {
|
|
586
|
+
release();
|
|
587
|
+
throw error;
|
|
588
|
+
}
|
|
589
|
+
const watch = new TerminalWatch(spec, resumed);
|
|
590
|
+
let screen = '';
|
|
591
|
+
const answered = new Set();
|
|
592
|
+
child.onExit((event) => {
|
|
593
|
+
watch.exitCode = event.exitCode;
|
|
594
|
+
});
|
|
595
|
+
child.onData((data) => {
|
|
596
|
+
watch.lastActivity = Date.now();
|
|
597
|
+
watch.lastScreen = watch.lastActivity;
|
|
598
|
+
if (answered.size === STARTUP_DIALOGS.length)
|
|
599
|
+
return;
|
|
600
|
+
screen = (screen + data).slice(-20_000);
|
|
601
|
+
const flat = flatten(screen);
|
|
602
|
+
for (const dialog of STARTUP_DIALOGS) {
|
|
603
|
+
if (answered.has(dialog.marker) || !flat.includes(dialog.marker))
|
|
604
|
+
continue;
|
|
605
|
+
answered.add(dialog.marker);
|
|
606
|
+
// Down to "Yes", then Enter - the same two keys a person presses.
|
|
607
|
+
setTimeout(() => {
|
|
608
|
+
child.write(dialog.keys);
|
|
609
|
+
setTimeout(() => child.write('\r'), 150);
|
|
610
|
+
}, 150);
|
|
611
|
+
}
|
|
612
|
+
});
|
|
613
|
+
tuiSessions.attach(spec.key, child, spec.sessionId, () => {
|
|
614
|
+
release();
|
|
615
|
+
spec.cleanup();
|
|
616
|
+
}, spec.lingerMs);
|
|
617
|
+
return watch;
|
|
618
|
+
}
|
|
619
|
+
/** Whether the terminal a watch belongs to is still the one registered under its key. */
|
|
620
|
+
function stillOpen(watch) {
|
|
621
|
+
return watch.exitCode === null && tuiSessions.info(watch.spec.key)?.providerSessionId === watch.spec.sessionId;
|
|
622
|
+
}
|
|
623
|
+
/**
|
|
624
|
+
* Keeps reading while a finished run's terminal lingers, so what a person
|
|
625
|
+
* does in it reaches the run's transcript too - and one last time after the
|
|
626
|
+
* process is gone, for whatever it wrote on the way out.
|
|
627
|
+
*/
|
|
628
|
+
async function followLate(watch, onEvent) {
|
|
629
|
+
const deliver = async () => {
|
|
630
|
+
try {
|
|
631
|
+
for (const event of await watch.read())
|
|
632
|
+
onEvent(event);
|
|
633
|
+
}
|
|
634
|
+
catch {
|
|
635
|
+
// A transcript that cannot be read now is read on the next pass.
|
|
636
|
+
}
|
|
637
|
+
};
|
|
638
|
+
while (stillOpen(watch)) {
|
|
639
|
+
await sleep(4 * POLL_MS);
|
|
640
|
+
await deliver();
|
|
641
|
+
}
|
|
642
|
+
await sleep(4 * POLL_MS);
|
|
643
|
+
await deliver();
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* Runs Claude Code in a pty and yields what a print run would have yielded.
|
|
647
|
+
* Throws only before the process exists; afterwards failures are events.
|
|
648
|
+
*/
|
|
649
|
+
export async function* runTui(spec) {
|
|
650
|
+
const watch = await spawnTerminal(spec, false);
|
|
651
|
+
const started = Date.now();
|
|
652
|
+
let finished = false;
|
|
653
|
+
try {
|
|
654
|
+
yield { type: 'status', label: 'terminal', detail: 'Claude Code is running in a terminal.' };
|
|
655
|
+
while (true) {
|
|
656
|
+
if (spec.signal?.aborted)
|
|
657
|
+
return;
|
|
658
|
+
await sleep(POLL_MS);
|
|
659
|
+
yield* await watch.read();
|
|
660
|
+
const payload = await watch.marker();
|
|
661
|
+
if (payload) {
|
|
662
|
+
const reported = typeof payload.last_assistant_message === 'string' ? payload.last_assistant_message.trim() : '';
|
|
663
|
+
const { events, holds } = await watch.settle(reported);
|
|
664
|
+
yield* events;
|
|
665
|
+
if (!holds) {
|
|
666
|
+
await watch.clearMarker();
|
|
667
|
+
continue;
|
|
668
|
+
}
|
|
669
|
+
if (watch.apiError) {
|
|
670
|
+
yield { type: 'error', message: watch.apiError, fatal: true };
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
finished = true;
|
|
674
|
+
yield {
|
|
675
|
+
type: 'done',
|
|
676
|
+
text: reported || watch.lastBlock,
|
|
677
|
+
providerSessionId: spec.sessionId,
|
|
678
|
+
usage: {
|
|
679
|
+
durationMs: Date.now() - started,
|
|
680
|
+
...(watch.contextTokens !== undefined ? { contextTokens: watch.contextTokens } : {}),
|
|
681
|
+
},
|
|
682
|
+
};
|
|
683
|
+
return;
|
|
684
|
+
}
|
|
685
|
+
if (Date.now() - watch.lastActivity > IDLE_LIMIT_MS) {
|
|
686
|
+
yield {
|
|
687
|
+
type: 'error',
|
|
688
|
+
message: 'The terminal showed no activity for 15 minutes - it was most likely waiting for an answer nobody gave.',
|
|
689
|
+
fatal: true,
|
|
690
|
+
};
|
|
691
|
+
return;
|
|
692
|
+
}
|
|
693
|
+
if (watch.exitCode !== null) {
|
|
694
|
+
yield* await watch.read();
|
|
695
|
+
yield {
|
|
696
|
+
type: 'error',
|
|
697
|
+
message: watch.apiError ?? 'Claude Code closed its terminal (exit code ' + watch.exitCode + ') before finishing.',
|
|
698
|
+
fatal: true,
|
|
699
|
+
};
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
finally {
|
|
705
|
+
// Done: keep the terminal for a while, and keep listening to it. Anything
|
|
706
|
+
// else - cancelled, timed out, failed, or the consumer walking away - ends
|
|
707
|
+
// it now.
|
|
708
|
+
if (finished) {
|
|
709
|
+
tuiSessions.linger(spec.key);
|
|
710
|
+
if (spec.onLateEvent)
|
|
711
|
+
void followLate(watch, spec.onLateEvent);
|
|
712
|
+
}
|
|
713
|
+
else {
|
|
714
|
+
tuiSessions.kill(spec.key);
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
/** A conversation terminal nobody has used for this long is closed. */
|
|
719
|
+
const CONVERSATION_IDLE_MS = 60 * 60 * 1000;
|
|
720
|
+
/** Screen silence that means the TUI sits at its prompt, ready for keys. */
|
|
721
|
+
const READY_QUIET_MS = 800;
|
|
722
|
+
/** A fresh terminal paints, answers its dialogs and settles within this. */
|
|
723
|
+
const READY_LIMIT_MS = 30_000;
|
|
724
|
+
/** How long a typed message may take to show up in the transcript. */
|
|
725
|
+
const ACCEPT_LIMIT_MS = 15_000;
|
|
726
|
+
/** How often an unconfirmed message is looked after: Enter again, or typed again. */
|
|
727
|
+
const ACCEPT_RETRY_MS = 3000;
|
|
728
|
+
/**
|
|
729
|
+
* A panel or menu is open and waiting for Esc. Not the first-run dialogs:
|
|
730
|
+
* Esc there declines the folder and Claude Code quits.
|
|
731
|
+
*/
|
|
732
|
+
function hasOpenPanel(screen) {
|
|
733
|
+
const lower = screen.toLowerCase();
|
|
734
|
+
if (lower.includes('trust this folder') || lower.includes('yes, i accept'))
|
|
735
|
+
return false;
|
|
736
|
+
return lower.includes('esc to cancel') || lower.includes('esc to close') || lower.includes('esc to exit');
|
|
737
|
+
}
|
|
738
|
+
/** The screen a command left, as text for the chat: without the hint lines and the empty tail. */
|
|
739
|
+
function commandOutput(screen, command) {
|
|
740
|
+
const lines = screen.split('\n');
|
|
741
|
+
// Only what came after the command line itself, not the conversation above it.
|
|
742
|
+
const at = lines.map((line) => line.includes(command)).lastIndexOf(true);
|
|
743
|
+
return lines
|
|
744
|
+
.slice(at + 1)
|
|
745
|
+
.filter((line) => !/esc to (cancel|close|exit)/i.test(line))
|
|
746
|
+
.join('\n')
|
|
747
|
+
.replace(/\s+$/, '')
|
|
748
|
+
.replace(/^\s*\n/, '');
|
|
749
|
+
}
|
|
750
|
+
/** Lines Claude Code draws under its input box, and only there. */
|
|
751
|
+
const INPUT_FOOTERS = ['shift+tab to cycle', '? for shortcuts', 'for shortcuts'];
|
|
752
|
+
/** How long an interrupted turn gets to write what it had before it is read as is. */
|
|
753
|
+
const INTERRUPT_SETTLE_MS = 1500;
|
|
754
|
+
/** Bracketed paste: the TUI takes the text as one paste, newlines and all. */
|
|
755
|
+
const PASTE_START = ESC + '[200~';
|
|
756
|
+
const PASTE_END = ESC + '[201~';
|
|
757
|
+
/**
|
|
758
|
+
* The `UserPromptSubmit` hook of a conversation terminal: whatever Rookery
|
|
759
|
+
* wrote into the context file for this one message goes to Claude Code as
|
|
760
|
+
* `additionalContext`, and the file is emptied so the next message - typed in
|
|
761
|
+
* the terminal by a person, say - does not get it again. Single quotes only:
|
|
762
|
+
* the command runs through whichever shell Claude Code picks.
|
|
763
|
+
*/
|
|
764
|
+
export function promptContextHookCommand(contextFile) {
|
|
765
|
+
const node = process.execPath.replace(/\\/g, '/');
|
|
766
|
+
const target = contextFile.replace(/\\/g, '/').replace(/'/g, "\\'");
|
|
767
|
+
const script = "const fs=require('fs');const f='" + target + "';let t='';" +
|
|
768
|
+
"try{t=fs.readFileSync(f,'utf8');fs.writeFileSync(f,'')}catch(e){}" +
|
|
769
|
+
"if(t.trim())process.stdout.write(JSON.stringify({hookSpecificOutput:{hookEventName:'UserPromptSubmit',additionalContext:t}}))";
|
|
770
|
+
return `"${node}" -e "${script}"`;
|
|
771
|
+
}
|
|
772
|
+
/** The context file of a conversation terminal, next to its Stop marker. */
|
|
773
|
+
export function contextFileFor(workDir) {
|
|
774
|
+
return join(workDir, 'context.md');
|
|
775
|
+
}
|
|
776
|
+
/**
|
|
777
|
+
* One conversation, one Claude Code process. A person may type into it from
|
|
778
|
+
* the terminal view, and Rookery types into it for every chat message - from
|
|
779
|
+
* the web, from Telegram, or a report-back from work handed off earlier. What
|
|
780
|
+
* Rookery typed comes back to the caller of `submit`; what a person typed
|
|
781
|
+
* comes back through `onTurn`. Both are the same process and the same
|
|
782
|
+
* transcript, which is the point: the chat and the terminal are one
|
|
783
|
+
* conversation, not two views taking turns writing to it.
|
|
784
|
+
*/
|
|
785
|
+
export class ConversationTerminal {
|
|
786
|
+
watch;
|
|
787
|
+
handlers;
|
|
788
|
+
#pending = null;
|
|
789
|
+
/** Submissions run one after another, never interleaved. */
|
|
790
|
+
#queue = Promise.resolve();
|
|
791
|
+
#spawned = Date.now();
|
|
792
|
+
/** Prompts a person typed since the last answer, and what came of them. */
|
|
793
|
+
#typed = [];
|
|
794
|
+
#typedEvents = [];
|
|
795
|
+
#typedStarted = Date.now();
|
|
796
|
+
constructor(watch, handlers) {
|
|
797
|
+
this.watch = watch;
|
|
798
|
+
this.handlers = handlers;
|
|
799
|
+
}
|
|
800
|
+
get key() {
|
|
801
|
+
return this.watch.spec.key;
|
|
802
|
+
}
|
|
803
|
+
get providerSessionId() {
|
|
804
|
+
return this.watch.spec.sessionId;
|
|
805
|
+
}
|
|
806
|
+
alive() {
|
|
807
|
+
return stillOpen(this.watch);
|
|
808
|
+
}
|
|
809
|
+
/** Whether a submitted message is being answered right now. */
|
|
810
|
+
get busy() {
|
|
811
|
+
return this.#pending !== null;
|
|
812
|
+
}
|
|
813
|
+
close() {
|
|
814
|
+
tuiSessions.kill(this.key);
|
|
815
|
+
}
|
|
816
|
+
/** Nothing being answered right now, neither a submitted message nor a typed one. */
|
|
817
|
+
async whenIdle(limitMs = 10 * 60 * 1000) {
|
|
818
|
+
const deadline = Date.now() + limitMs;
|
|
819
|
+
while (Date.now() < deadline && this.alive()) {
|
|
820
|
+
const working = this.#pending !== null || this.#typed.length > 0 || tuiSessions.info(this.key)?.state === 'running';
|
|
821
|
+
if (!working)
|
|
822
|
+
return;
|
|
823
|
+
await sleep(POLL_MS);
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
/**
|
|
827
|
+
* Type one message into the terminal and wait for its answer. `context`
|
|
828
|
+
* reaches Claude Code through the `UserPromptSubmit` hook rather than as
|
|
829
|
+
* part of the message, so the transcript - and the terminal a person may be
|
|
830
|
+
* watching - shows exactly what was said, nothing Rookery added.
|
|
831
|
+
*/
|
|
832
|
+
submit(input) {
|
|
833
|
+
const run = this.#queue.then(() => this.#submit(input));
|
|
834
|
+
this.#queue = run.catch(() => undefined);
|
|
835
|
+
return run;
|
|
836
|
+
}
|
|
837
|
+
async #submit(input) {
|
|
838
|
+
const failed = (error) => ({
|
|
839
|
+
prompt: input.prompt,
|
|
840
|
+
answer: '',
|
|
841
|
+
events: [],
|
|
842
|
+
providerSessionId: this.providerSessionId,
|
|
843
|
+
usage: { durationMs: 0 },
|
|
844
|
+
error,
|
|
845
|
+
});
|
|
846
|
+
if (!this.alive())
|
|
847
|
+
return failed('The terminal is closed.');
|
|
848
|
+
await this.#ready(input.signal);
|
|
849
|
+
if (input.signal?.aborted)
|
|
850
|
+
return failed('Cancelled before it was sent.');
|
|
851
|
+
if (!this.alive())
|
|
852
|
+
return failed('The terminal closed before the message could be sent.');
|
|
853
|
+
await writeFile(contextFileFor(this.watch.spec.workDir), input.context ?? '').catch(() => undefined);
|
|
854
|
+
// A turn started while the Stop marker still holds the last answer would
|
|
855
|
+
// end the moment it began.
|
|
856
|
+
await this.watch.clearMarker();
|
|
857
|
+
let pending;
|
|
858
|
+
const ended = new Promise((resolve) => {
|
|
859
|
+
pending = {
|
|
860
|
+
prompt: input.prompt,
|
|
861
|
+
onEvent: input.onEvent,
|
|
862
|
+
events: [],
|
|
863
|
+
started: Date.now(),
|
|
864
|
+
accepted: false,
|
|
865
|
+
done: resolve,
|
|
866
|
+
};
|
|
867
|
+
});
|
|
868
|
+
if (!pending)
|
|
869
|
+
return failed('The terminal could not take the message.');
|
|
870
|
+
const mine = pending;
|
|
871
|
+
this.#pending = mine;
|
|
872
|
+
tuiSessions.markRunning(this.key);
|
|
873
|
+
this.#type(input.prompt);
|
|
874
|
+
const onAbort = () => {
|
|
875
|
+
// Esc is what a person presses: Claude Code stops, keeps what it had,
|
|
876
|
+
// and writes no Stop payload - so the turn is closed here instead.
|
|
877
|
+
tuiSessions.write(this.key, ESC);
|
|
878
|
+
setTimeout(() => void this.#interrupted(mine), INTERRUPT_SETTLE_MS);
|
|
879
|
+
};
|
|
880
|
+
if (input.signal?.aborted)
|
|
881
|
+
onAbort();
|
|
882
|
+
else
|
|
883
|
+
input.signal?.addEventListener('abort', onAbort, { once: true });
|
|
884
|
+
// A slash command or a `!` shell line is the terminal's own business: it
|
|
885
|
+
// may never reach the model, so no Stop hook comes. Once the screen has
|
|
886
|
+
// settled without a model turn starting, it is done - whatever it showed
|
|
887
|
+
// is on the terminal, which is where a command's output lives anyway.
|
|
888
|
+
const command = /^[/!]/.test(input.prompt.trim());
|
|
889
|
+
if (command) {
|
|
890
|
+
void (async () => {
|
|
891
|
+
const typedAt = Date.now();
|
|
892
|
+
while (this.#pending === mine && !mine.accepted && Date.now() - typedAt < ACCEPT_LIMIT_MS) {
|
|
893
|
+
await sleep(POLL_MS * 2);
|
|
894
|
+
if (Date.now() - typedAt > 2500 && Date.now() - this.watch.lastScreen > 1500 && !mine.accepted) {
|
|
895
|
+
// What the command put on the screen is its answer - the chat
|
|
896
|
+
// cannot see the terminal, so `/cost` there shows the costs. A
|
|
897
|
+
// panel it opened is closed again, or the next message would be
|
|
898
|
+
// typed into it.
|
|
899
|
+
const screen = tuiSessions.screenText(this.key) ?? '';
|
|
900
|
+
const output = commandOutput(screen, input.prompt.trim());
|
|
901
|
+
// Fenced: a panel is laid out in columns, and markdown would reflow it.
|
|
902
|
+
this.#settle(mine, { answer: output ? '```\n' + output + '\n```' : '' });
|
|
903
|
+
if (hasOpenPanel(screen))
|
|
904
|
+
tuiSessions.write(this.key, ESC);
|
|
905
|
+
return;
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
// Still running past the limit (a command that started real work
|
|
909
|
+
// settles through the Stop hook instead): never leave it hanging.
|
|
910
|
+
if (this.#pending === mine && !mine.accepted)
|
|
911
|
+
this.#settle(mine, { answer: '' });
|
|
912
|
+
})();
|
|
913
|
+
}
|
|
914
|
+
// The message has to arrive. Every few seconds without it in the
|
|
915
|
+
// transcript, the screen says why: the text sits in the input box (a
|
|
916
|
+
// paste the TUI held on to) and gets another Enter, or it is not there at
|
|
917
|
+
// all (keys swallowed while the TUI was still setting up) and is typed
|
|
918
|
+
// again. Past the limit it is an error, not a turn waiting for ever.
|
|
919
|
+
void (async () => {
|
|
920
|
+
if (command)
|
|
921
|
+
return;
|
|
922
|
+
const typedAt = Date.now();
|
|
923
|
+
const snippet = input.prompt.replace(/\s+/g, ' ').trim().slice(0, 24);
|
|
924
|
+
while (Date.now() - typedAt < ACCEPT_LIMIT_MS * 2) {
|
|
925
|
+
await sleep(ACCEPT_RETRY_MS);
|
|
926
|
+
if (this.#pending !== mine || mine.accepted)
|
|
927
|
+
return;
|
|
928
|
+
const screen = tuiSessions.screenText(this.key);
|
|
929
|
+
const waiting = screen === null || screen.includes('[Pasted text') || screen.replace(/\s+/g, ' ').includes(snippet);
|
|
930
|
+
if (waiting)
|
|
931
|
+
tuiSessions.write(this.key, '\r');
|
|
932
|
+
else
|
|
933
|
+
this.#type(input.prompt);
|
|
934
|
+
}
|
|
935
|
+
if (this.#pending !== mine || mine.accepted)
|
|
936
|
+
return;
|
|
937
|
+
this.#settle(mine, { error: 'The terminal did not take the message.' });
|
|
938
|
+
})();
|
|
939
|
+
try {
|
|
940
|
+
return await ended;
|
|
941
|
+
}
|
|
942
|
+
finally {
|
|
943
|
+
input.signal?.removeEventListener('abort', onAbort);
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
/**
|
|
947
|
+
* Wait until the TUI sits at its prompt: not working, quiet for a moment,
|
|
948
|
+
* and - where the screen can be read - showing the footer Claude Code only
|
|
949
|
+
* draws under a live input box. Quiet alone was not enough: a fresh
|
|
950
|
+
* terminal pauses while its startup hooks run, and keys typed into that
|
|
951
|
+
* pause are swallowed.
|
|
952
|
+
*/
|
|
953
|
+
async #ready(signal) {
|
|
954
|
+
const deadline = Date.now() + READY_LIMIT_MS;
|
|
955
|
+
let closed = 0;
|
|
956
|
+
while (Date.now() < deadline && !signal?.aborted && this.alive()) {
|
|
957
|
+
const working = tuiSessions.info(this.key)?.state === 'running' || this.#typed.length > 0;
|
|
958
|
+
const quiet = Date.now() - this.#spawned > 1500 && Date.now() - this.watch.lastScreen > READY_QUIET_MS;
|
|
959
|
+
const screen = tuiSessions.screenText(this.key);
|
|
960
|
+
const prompt = screen === null || INPUT_FOOTERS.some((footer) => screen.includes(footer));
|
|
961
|
+
if (!working && quiet && prompt)
|
|
962
|
+
return;
|
|
963
|
+
// A panel left open - by a command typed in the terminal, say - sits
|
|
964
|
+
// where the input box would be. Esc closes it, as a person would.
|
|
965
|
+
if (!working && quiet && screen !== null && hasOpenPanel(screen) && closed < 3) {
|
|
966
|
+
closed += 1;
|
|
967
|
+
tuiSessions.write(this.key, ESC);
|
|
968
|
+
await sleep(READY_QUIET_MS);
|
|
969
|
+
}
|
|
970
|
+
await sleep(POLL_MS);
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
/** The message as keystrokes: pasted whole where the TUI allows it, then Enter. */
|
|
974
|
+
#type(prompt) {
|
|
975
|
+
const body = tuiSessions.pasteMode(this.key) ? PASTE_START + prompt + PASTE_END : prompt.replace(/\r?\n/g, ' ');
|
|
976
|
+
tuiSessions.write(this.key, body);
|
|
977
|
+
// Enter on its own write, a beat later: in the same chunk the TUI can read
|
|
978
|
+
// it as part of the paste rather than as the key that sends it.
|
|
979
|
+
setTimeout(() => tuiSessions.write(this.key, '\r'), 200);
|
|
980
|
+
}
|
|
981
|
+
async #interrupted(pending) {
|
|
982
|
+
if (this.#pending !== pending)
|
|
983
|
+
return;
|
|
984
|
+
for (const event of await this.watch.read().catch(() => []))
|
|
985
|
+
this.take(event);
|
|
986
|
+
this.#settle(pending, { interrupted: true });
|
|
987
|
+
}
|
|
988
|
+
#settle(pending, extra) {
|
|
989
|
+
if (this.#pending !== pending)
|
|
990
|
+
return;
|
|
991
|
+
this.#pending = null;
|
|
992
|
+
let lastText = '';
|
|
993
|
+
for (const event of pending.events)
|
|
994
|
+
if (event.type === 'text')
|
|
995
|
+
lastText = event.delta.replace(/^\n\n/, '');
|
|
996
|
+
pending.done({
|
|
997
|
+
prompt: pending.prompt,
|
|
998
|
+
answer: extra.answer ?? lastText,
|
|
999
|
+
events: pending.events,
|
|
1000
|
+
...(this.watch.model ? { model: this.watch.model } : {}),
|
|
1001
|
+
providerSessionId: this.providerSessionId,
|
|
1002
|
+
usage: {
|
|
1003
|
+
durationMs: Date.now() - pending.started,
|
|
1004
|
+
...(this.watch.contextTokens !== undefined ? { contextTokens: this.watch.contextTokens } : {}),
|
|
1005
|
+
},
|
|
1006
|
+
...(extra.interrupted ? { interrupted: true } : {}),
|
|
1007
|
+
...(extra.error ? { error: extra.error } : {}),
|
|
1008
|
+
});
|
|
1009
|
+
tuiSessions.linger(this.key);
|
|
1010
|
+
}
|
|
1011
|
+
/** From the read loop: one transcript event, for the submitted turn if there is one. */
|
|
1012
|
+
take(event) {
|
|
1013
|
+
const pending = this.#pending;
|
|
1014
|
+
if (event.type === 'status' && event.label === 'input' && event.detail) {
|
|
1015
|
+
// The first message after a submission is the one Rookery typed.
|
|
1016
|
+
if (pending && !pending.accepted) {
|
|
1017
|
+
pending.accepted = true;
|
|
1018
|
+
return;
|
|
1019
|
+
}
|
|
1020
|
+
if (!pending) {
|
|
1021
|
+
if (this.#typed.length === 0 && this.#typedEvents.length === 0)
|
|
1022
|
+
this.#typedStarted = Date.now();
|
|
1023
|
+
this.#typed.push(event.detail);
|
|
1024
|
+
tuiSessions.markRunning(this.key);
|
|
1025
|
+
}
|
|
1026
|
+
return;
|
|
1027
|
+
}
|
|
1028
|
+
if (event.type !== 'text' && event.type !== 'thinking' && event.type !== 'tool')
|
|
1029
|
+
return;
|
|
1030
|
+
if (pending) {
|
|
1031
|
+
pending.accepted = true;
|
|
1032
|
+
pending.events.push(event);
|
|
1033
|
+
pending.onEvent(event);
|
|
1034
|
+
}
|
|
1035
|
+
else {
|
|
1036
|
+
this.#typedEvents.push(event);
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
/** From the read loop: the Stop hook fired and the transcript caught up. */
|
|
1040
|
+
stopped(reported) {
|
|
1041
|
+
const pending = this.#pending;
|
|
1042
|
+
if (pending) {
|
|
1043
|
+
if (this.watch.apiError)
|
|
1044
|
+
this.#settle(pending, { error: this.watch.apiError });
|
|
1045
|
+
else
|
|
1046
|
+
this.#settle(pending, { answer: reported || this.watch.lastBlock });
|
|
1047
|
+
return;
|
|
1048
|
+
}
|
|
1049
|
+
const answer = reported || this.watch.lastBlock;
|
|
1050
|
+
if (this.#typed.length || answer) {
|
|
1051
|
+
this.handlers.onTurn({
|
|
1052
|
+
prompt: this.#typed.join('\n\n'),
|
|
1053
|
+
answer,
|
|
1054
|
+
events: this.#typedEvents,
|
|
1055
|
+
...(this.watch.model ? { model: this.watch.model } : {}),
|
|
1056
|
+
providerSessionId: this.providerSessionId,
|
|
1057
|
+
usage: {
|
|
1058
|
+
durationMs: Date.now() - this.#typedStarted,
|
|
1059
|
+
...(this.watch.contextTokens !== undefined ? { contextTokens: this.watch.contextTokens } : {}),
|
|
1060
|
+
},
|
|
1061
|
+
});
|
|
1062
|
+
}
|
|
1063
|
+
this.#typed = [];
|
|
1064
|
+
this.#typedEvents = [];
|
|
1065
|
+
// Answered: waiting for the person again.
|
|
1066
|
+
tuiSessions.linger(this.key);
|
|
1067
|
+
}
|
|
1068
|
+
/** From the read loop: the process is gone, and a turn still waiting on it ends. */
|
|
1069
|
+
exited() {
|
|
1070
|
+
const pending = this.#pending;
|
|
1071
|
+
if (pending)
|
|
1072
|
+
this.#settle(pending, { error: this.watch.apiError ?? 'Claude Code closed its terminal before answering.' });
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
/**
|
|
1076
|
+
* Opens a conversation in Claude Code's own terminal. There is no task and
|
|
1077
|
+
* no end: a person or Rookery types, Claude answers. It runs until somebody
|
|
1078
|
+
* closes it, or until nobody has used it for an hour; the next message then
|
|
1079
|
+
* starts it again on the same session.
|
|
1080
|
+
*/
|
|
1081
|
+
export async function startConversationTerminal(spec, resumed, handlers) {
|
|
1082
|
+
const watch = await spawnTerminal({ ...spec, lingerMs: CONVERSATION_IDLE_MS }, resumed);
|
|
1083
|
+
const terminal = new ConversationTerminal(watch, handlers);
|
|
1084
|
+
// A conversation terminal waits for its person first - idle, not working,
|
|
1085
|
+
// and closed by itself after an hour of nobody typing.
|
|
1086
|
+
tuiSessions.linger(spec.key);
|
|
1087
|
+
void (async () => {
|
|
1088
|
+
try {
|
|
1089
|
+
while (stillOpen(watch)) {
|
|
1090
|
+
await sleep(POLL_MS);
|
|
1091
|
+
for (const event of await watch.read())
|
|
1092
|
+
terminal.take(event);
|
|
1093
|
+
const payload = await watch.marker();
|
|
1094
|
+
if (payload) {
|
|
1095
|
+
const reported = typeof payload.last_assistant_message === 'string' ? payload.last_assistant_message.trim() : '';
|
|
1096
|
+
const settled = await watch.settle(reported);
|
|
1097
|
+
for (const event of settled.events)
|
|
1098
|
+
terminal.take(event);
|
|
1099
|
+
await watch.clearMarker();
|
|
1100
|
+
if (!settled.holds)
|
|
1101
|
+
continue;
|
|
1102
|
+
terminal.stopped(reported);
|
|
1103
|
+
}
|
|
1104
|
+
if (Date.now() - watch.lastActivity > CONVERSATION_IDLE_MS)
|
|
1105
|
+
tuiSessions.kill(spec.key);
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
catch {
|
|
1109
|
+
// A read that throws past its own guards ends the watch, not the server.
|
|
1110
|
+
}
|
|
1111
|
+
finally {
|
|
1112
|
+
terminal.exited();
|
|
1113
|
+
handlers.onExit();
|
|
1114
|
+
}
|
|
1115
|
+
})();
|
|
1116
|
+
return terminal;
|
|
1117
|
+
}
|
|
1118
|
+
//# sourceMappingURL=claude-tui.js.map
|