rookery-agent 0.1.0 → 0.2.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 +11 -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 +4 -1
- 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.map +1 -1
- package/packages/core/dist/config.js +284 -10
- package/packages/core/dist/config.js.map +1 -1
- package/packages/core/dist/cron/scheduler.d.ts +49 -3
- package/packages/core/dist/cron/scheduler.d.ts.map +1 -1
- package/packages/core/dist/cron/scheduler.js +268 -25
- 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 +100 -2
- package/packages/core/dist/gateway/policy.d.ts.map +1 -1
- package/packages/core/dist/gateway/policy.js +270 -6
- package/packages/core/dist/gateway/policy.js.map +1 -1
- package/packages/core/dist/index.d.ts +36 -10
- package/packages/core/dist/index.d.ts.map +1 -1
- package/packages/core/dist/index.js +64 -10
- 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 +741 -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 +282 -3
- package/packages/core/dist/org/controller.d.ts.map +1 -1
- package/packages/core/dist/org/controller.js +2334 -237
- 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 +41 -28
- package/packages/core/dist/org/prompts.d.ts.map +1 -1
- package/packages/core/dist/org/prompts.js +281 -94
- 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 +249 -2
- package/packages/core/dist/org/store.d.ts.map +1 -1
- package/packages/core/dist/org/store.js +787 -13
- package/packages/core/dist/org/store.js.map +1 -1
- package/packages/core/dist/org/tools.d.ts +26 -2
- package/packages/core/dist/org/tools.d.ts.map +1 -1
- package/packages/core/dist/org/tools.js +352 -63
- 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 +18 -3
- package/packages/core/dist/providers/claude-code.d.ts.map +1 -1
- package/packages/core/dist/providers/claude-code.js +490 -40
- package/packages/core/dist/providers/claude-code.js.map +1 -1
- package/packages/core/dist/providers/claude-tui.d.ts +175 -0
- package/packages/core/dist/providers/claude-tui.d.ts.map +1 -0
- package/packages/core/dist/providers/claude-tui.js +683 -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 +140 -6
- package/packages/core/dist/runtime.d.ts.map +1 -1
- package/packages/core/dist/runtime.js +1312 -225
- 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 +1598 -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 +28 -8
- 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 +347 -6
- 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 +158 -1
- package/packages/server/dist/gateways/telegram.d.ts.map +1 -1
- package/packages/server/dist/gateways/telegram.js +1471 -78
- package/packages/server/dist/gateways/telegram.js.map +1 -1
- package/packages/server/dist/gateways/threads.d.ts +79 -0
- package/packages/server/dist/gateways/threads.d.ts.map +1 -0
- package/packages/server/dist/gateways/threads.js +279 -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 +39 -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 +284 -48
- 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 +162 -28
- package/packages/server/dist/routes/ws.js.map +1 -1
- package/packages/server/dist/schemas.d.ts +1125 -211
- package/packages/server/dist/schemas.d.ts.map +1 -1
- package/packages/server/dist/schemas.js +300 -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 +186 -3
- package/packages/server/dist/server.js.map +1 -1
- package/packages/server/dist/services/stream.d.ts +89 -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 +49 -0
- package/packages/server/dist/services/turns.d.ts.map +1 -0
- package/packages/server/dist/services/turns.js +138 -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-B4qWcqra.js +1 -0
- package/packages/web/dist/assets/arc-CQult7TN.js +1 -0
- package/packages/web/dist/assets/architectureDiagram-NJMV4G6O-DFTRvl66.js +36 -0
- package/packages/web/dist/assets/blockDiagram-BEXU5L5S-TCFoK_k-.js +140 -0
- package/packages/web/dist/assets/c4Diagram-YGBWAQC7-i5_GqhJa.js +38 -0
- package/packages/web/dist/assets/channel-D_4EmqNR.js +1 -0
- package/packages/web/dist/assets/chunk-2Q5K7J3B-BK6I2wfW.js +1 -0
- package/packages/web/dist/assets/chunk-3FUC2YCW-Dw-TfKT0.js +2 -0
- package/packages/web/dist/assets/chunk-5VM5RSS4-AE_XRNTT.js +15 -0
- package/packages/web/dist/assets/chunk-GTNCS2PH-DO18WaaJ.js +88 -0
- package/packages/web/dist/assets/chunk-GWA4HPMP-3rdjszP_.js +1 -0
- package/packages/web/dist/assets/chunk-JWPE2WC7-C93LH2D0.js +1 -0
- package/packages/web/dist/assets/chunk-NETBCI7D-Dj7O3-H-.js +1 -0
- package/packages/web/dist/assets/chunk-WEXAMYUT-BRFvQUIn.js +1 -0
- package/packages/web/dist/assets/chunk-XXDRQBXY-CXx6HMbz.js +1 -0
- package/packages/web/dist/assets/classDiagram-v2-NBCMYWYE-BGXszxjn.js +217 -0
- package/packages/web/dist/assets/cose-bilkent-JH36ORCC-BAuXqkne.js +1 -0
- package/packages/web/dist/assets/cynefin-OW5HDTMX-plNzhY7J.js +178 -0
- package/packages/web/dist/assets/cynefinDiagram-VND7K2PF-DuPlljFS.js +62 -0
- package/packages/web/dist/assets/cytoscape.esm-Ix0LnXOy.js +331 -0
- package/packages/web/dist/assets/dagre-6A5THRUB-CXzwdR-6.js +4 -0
- package/packages/web/dist/assets/diagram-22UHCM2B-B7iv_V2D.js +200 -0
- package/packages/web/dist/assets/diagram-3UASUU5V-BMvi7gSi.js +24 -0
- package/packages/web/dist/assets/diagram-ATOU4E4O-NJ7EB5Qg.js +3 -0
- package/packages/web/dist/assets/diagram-CDSNMT55-DccMMNJ-.js +30 -0
- package/packages/web/dist/assets/diagram-MLGK6HIB-BbwGHK4g.js +24 -0
- package/packages/web/dist/assets/diagram-MPIPVDR6-BbSSZfM3.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-BBfPNM85.js +1 -0
- package/packages/web/dist/assets/elk-276RUBZZ-dM3Y1d2a.js +27 -0
- package/packages/web/dist/assets/erDiagram-OPXOYQCR-iWrUegxy.js +99 -0
- package/packages/web/dist/assets/flowDiagram-KWPJA3E3-B6DYlbkV.js +213 -0
- package/packages/web/dist/assets/ganttDiagram-FUAMR5RP-D7dSWZcC.js +292 -0
- package/packages/web/dist/assets/gitGraphDiagram-X574FWY7-DguFgcbW.js +106 -0
- package/packages/web/dist/assets/graph-Bn3Yngep.js +1 -0
- package/packages/web/dist/assets/index-B1QvSHA5.js +660 -0
- package/packages/web/dist/assets/index-zwMuaz90.css +32 -0
- package/packages/web/dist/assets/infoDiagram-VRGFBTTK-CuiuO3uo.js +2 -0
- package/packages/web/dist/assets/ishikawaDiagram-OU5B5YK6-wBS1_40m.js +70 -0
- package/packages/web/dist/assets/journeyDiagram-ZHPQQLJL-Bd1YE2gP.js +139 -0
- package/packages/web/dist/assets/kanban-definition-PNTS6WVX-BlQzv_X1.js +89 -0
- package/packages/web/dist/assets/katex-C5jXJg4s.js +257 -0
- package/packages/web/dist/assets/mermaid.core-p3CwmLUb.js +313 -0
- package/packages/web/dist/assets/mindmap-definition-NLK3R4M7-BlticnKl.js +96 -0
- package/packages/web/dist/assets/pegDiagram-GJSIUBJH-BbXsP47B.js +1 -0
- package/packages/web/dist/assets/pieDiagram-5QR66LMP-BooBSBug.js +39 -0
- package/packages/web/dist/assets/quadrantDiagram-O4NWA36T-CkXC6VCh.js +7 -0
- package/packages/web/dist/assets/railroadDiagram-XR7U4H2S-BphzYiW-.js +1 -0
- package/packages/web/dist/assets/requirementDiagram-PLB6GJNP-PWpD4zpQ.js +84 -0
- package/packages/web/dist/assets/sankeyDiagram-IPEJSGJF-5Qm39Vfz.js +40 -0
- package/packages/web/dist/assets/scene-D4LPicHk.js +4620 -0
- package/packages/web/dist/assets/sequenceDiagram-PO4LG4MO-DA673J_w.js +169 -0
- package/packages/web/dist/assets/sizeCapture-INFHLROL-1KsNwBhd.js +1 -0
- package/packages/web/dist/assets/stateDiagram-v2-GCMORJYK-D7O0UyHr.js +291 -0
- package/packages/web/dist/assets/swimlanes-2SLR337P-culFSb1R.js +1 -0
- package/packages/web/dist/assets/swimlanesDiagram-TC7HE7FX-kzTmK2BP.js +8 -0
- package/packages/web/dist/assets/timeline-definition-EJHVYXUP-6GIO5p-k.js +120 -0
- package/packages/web/dist/assets/usecaseDiagram-POWQR4AR-BAGHDBzZ.js +370 -0
- package/packages/web/dist/assets/vennDiagram-UO4OBE2U-PbtBvPRE.js +34 -0
- package/packages/web/dist/assets/wardleyDiagram-VNRHLVJA-9scbtDvX.js +78 -0
- package/packages/web/dist/assets/xychartDiagram-PMCCYNJV-C51PiF4p.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
|
@@ -1,24 +1,39 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
1
2
|
import { EventEmitter } from 'node:events';
|
|
2
3
|
import { join } from 'node:path';
|
|
3
4
|
import { ASSISTANT_MEMORY_OWNER } from './types.js';
|
|
4
|
-
import {
|
|
5
|
+
import { databasePath, loadConfig } from './config.js';
|
|
5
6
|
import { createLogger, silentLogger } from './logger.js';
|
|
6
7
|
import { ProviderRegistry } from './providers/registry.js';
|
|
8
|
+
import { remapModel } from './providers/provider-catalog.js';
|
|
9
|
+
import { isUsageLimitError, providerBlocked, providerLow, rememberUsageFailure } from './providers/quota.js';
|
|
10
|
+
import { sharedCodexBridge } from './providers/codex-bridge.js';
|
|
11
|
+
import { tuiSessions } from './providers/claude-tui.js';
|
|
12
|
+
import { ModelGateway } from './providers/model-gateway.js';
|
|
7
13
|
import { Store } from './memory/store.js';
|
|
8
|
-
import { coreProfile, dropContradicted, recall } from './memory/recall.js';
|
|
14
|
+
import { byScoreThenId, coreProfile, dropContradicted, recall } from './memory/recall.js';
|
|
15
|
+
import { fetchFrame } from './memory/dream/frame.js';
|
|
16
|
+
import { resolvePolicy } from './memory/dream/policy.js';
|
|
17
|
+
import { DEFAULT_SPLIT_RATES, splitOf } from './memory/dream/evaluate.js';
|
|
18
|
+
import { episodeFromEvents } from './memory/dream/trajectory.js';
|
|
9
19
|
import { extractMemories, smallModelFor } from './memory/extractor.js';
|
|
10
20
|
import { admitCandidates, linkEntities } from './memory/gate.js';
|
|
11
21
|
import { SleepRunner } from './memory/sleep.js';
|
|
12
22
|
import { buildSystemPrompt, deriveTitle } from './agents/persona.js';
|
|
13
23
|
import { BridgeServer } from './org/bridge.js';
|
|
14
24
|
import { OrgController } from './org/controller.js';
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
25
|
+
import { QuestionRegistry } from './org/questions.js';
|
|
26
|
+
import { assistantOrgBlock } from './org/prompts.js';
|
|
27
|
+
import { dormantToolsHint, externalTurnExtras, toolServersFor } from './tools/hub.js';
|
|
17
28
|
import { SkillStore, renderSkillsIndex } from './skills/store.js';
|
|
29
|
+
import { renderExternalSkillsHint } from './skills/shelf.js';
|
|
30
|
+
import { matchSkills, renderSkillMatches } from './skills/suggest.js';
|
|
18
31
|
import { CronScheduler } from './cron/scheduler.js';
|
|
19
32
|
import { describeCron } from './cron/parse.js';
|
|
20
33
|
import { runCronScript } from './cron/script.js';
|
|
21
|
-
import { EventQueue } from './util/queue.js';
|
|
34
|
+
import { EventQueue, titleFromBrief } from './util/queue.js';
|
|
35
|
+
import { formatAge, formatNow } from './util/time.js';
|
|
36
|
+
import { TurnBlocks } from './util/blocks.js';
|
|
22
37
|
/**
|
|
23
38
|
* The assistant runtime.
|
|
24
39
|
*
|
|
@@ -27,10 +42,11 @@ import { EventQueue } from './util/queue.js';
|
|
|
27
42
|
*
|
|
28
43
|
* There is no routing step and no agent selection. Rookery is one personal
|
|
29
44
|
* assistant: the identity is fixed, and the provider only ever changes when
|
|
30
|
-
* the caller asks for it
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
45
|
+
* the caller asks for it, when the current one is logged out, or - the one
|
|
46
|
+
* exception - when it runs out of quota, in which case the turn switches
|
|
47
|
+
* once and says so. That matters beyond persona: switching provider throws
|
|
48
|
+
* away `providerSessionId`, so a router that changed its mind
|
|
49
|
+
* mid-conversation would silently drop the thread the assistant was holding.
|
|
34
50
|
*
|
|
35
51
|
* What the assistant can do beyond talking is run its company: every turn
|
|
36
52
|
* gets Rookery's tools through the MCP bridge, and an `assign` call from
|
|
@@ -47,6 +63,40 @@ import { EventQueue } from './util/queue.js';
|
|
|
47
63
|
* because a third would let the assistant loop over its own switches.
|
|
48
64
|
*/
|
|
49
65
|
const MAX_PROVIDER_PASSES = 2;
|
|
66
|
+
/**
|
|
67
|
+
* How many providers one turn may run on. The second only happens when the
|
|
68
|
+
* first died on its usage limit with nothing to show for it, so a switch
|
|
69
|
+
* costs one provider session, never the thread the turn was holding.
|
|
70
|
+
*/
|
|
71
|
+
const MAX_PROVIDER_ATTEMPTS = 2;
|
|
72
|
+
/**
|
|
73
|
+
* The board watcher's schedule id, deterministic so it stays findable across a
|
|
74
|
+
* restart - every other schedule id is a random uuid. One per organisation.
|
|
75
|
+
*/
|
|
76
|
+
function boardWatchJobId(orgId) {
|
|
77
|
+
return 'board-watch:' + orgId;
|
|
78
|
+
}
|
|
79
|
+
/** Wide enough that the clock rarely fires it: the event path is the fast one, this is its backstop. */
|
|
80
|
+
const BOARD_WATCH_SCHEDULE = '*/30 * * * *';
|
|
81
|
+
/**
|
|
82
|
+
* What the watcher is told to look at (E8, F3). It reports; it does not act.
|
|
83
|
+
*
|
|
84
|
+
* The earlier wording told it to "do whatever actually helps - reassign it,
|
|
85
|
+
* follow up with a fresh run on the same task, or restart it". That made the
|
|
86
|
+
* watcher the unattended caller with the widest reach in the system, and it
|
|
87
|
+
* fired hardest on `blocked` - the one status that means a person was asked
|
|
88
|
+
* something. The right answer to an open question is to wait for it, so the
|
|
89
|
+
* watcher now only says what it found. `WATCH_TOOLS` in org/tools.ts is what
|
|
90
|
+
* enforces that; this prompt only explains it.
|
|
91
|
+
*/
|
|
92
|
+
const BOARD_WATCH_PROMPT = 'Watch the board and report what needs a person. Check list_tasks for anything failed, and for ' +
|
|
93
|
+
'anything running far longer than it should. You are a backstop, not a worker: you cannot start, ' +
|
|
94
|
+
'reassign, restart or close anything, and that is deliberate - deciding what to do about what you ' +
|
|
95
|
+
'find belongs to the user. Mail the user at most once per pass, and only when something truly ' +
|
|
96
|
+
'needs a human decision: say what you saw, how long it has been that way, and what you would ' +
|
|
97
|
+
'suggest. A task waiting on an answer is working as intended, not a fault, and never a reason to ' +
|
|
98
|
+
'write. If none of what you were shown is worth interrupting somebody over, do not report that ' +
|
|
99
|
+
'everything is fine - answer with exactly [SILENT] instead.';
|
|
50
100
|
/** Add up what two passes of one turn cost; the last pass owns the context gauge. */
|
|
51
101
|
function mergeUsage(base, next) {
|
|
52
102
|
if (!base)
|
|
@@ -76,6 +126,62 @@ function continuePrompt(servers) {
|
|
|
76
126
|
'repeating what you already said.',
|
|
77
127
|
].join(' ');
|
|
78
128
|
}
|
|
129
|
+
/* --------------------------- dream recorder --------------------------- */
|
|
130
|
+
/**
|
|
131
|
+
* Salt for the dream's session-level sample draw. A fixed literal, not a
|
|
132
|
+
* per-process random: the sample must survive a restart, because it is drawn
|
|
133
|
+
* per session - consecutive turns of one session share topic, bank cutout and
|
|
134
|
+
* entity neighbourhood, and a restart must not split them across the sample.
|
|
135
|
+
*/
|
|
136
|
+
const DREAM_SAMPLE_SALT = 'rookery.dream.sample.v1';
|
|
137
|
+
/**
|
|
138
|
+
* The sample draw of one session as a number in [0, 1): FNV-1a over the
|
|
139
|
+
* session id and the salt. Cheap, stable and portable - it only has to be
|
|
140
|
+
* deterministic, never cryptographic.
|
|
141
|
+
*/
|
|
142
|
+
function dreamSampleDraw(sessionId) {
|
|
143
|
+
let hash = 0x811c9dc5;
|
|
144
|
+
const input = sessionId + DREAM_SAMPLE_SALT;
|
|
145
|
+
for (let index = 0; index < input.length; index += 1) {
|
|
146
|
+
hash ^= input.charCodeAt(index);
|
|
147
|
+
hash = Math.imul(hash, 0x01000193);
|
|
148
|
+
}
|
|
149
|
+
return (hash >>> 0) / 0x1_0000_0000;
|
|
150
|
+
}
|
|
151
|
+
/** Clamp to a range, for dream keys read outside the patch schema (E21). */
|
|
152
|
+
function clampNumber(value, lo, hi) {
|
|
153
|
+
return Math.min(hi, Math.max(lo, value));
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* The declared box around one turn's realised recall policy: the parameter
|
|
157
|
+
* space a replay of this turn's frame may move in. The interval widths are
|
|
158
|
+
* the house widths the night's grid places its candidates at - weights
|
|
159
|
+
* +/-0.1, threshold [0.05, 0.3], hop weights +/-0.15 and +/-0.2 - always
|
|
160
|
+
* stretched to contain the realised point and never past the valid range,
|
|
161
|
+
* so a knob the user turned cannot sit outside the box that is supposed to
|
|
162
|
+
* close over it. `limitMax` arrives already containing the realised limit.
|
|
163
|
+
*/
|
|
164
|
+
function declaredDreamBox(policy, limitMax) {
|
|
165
|
+
const weight = (value) => [Math.max(0, value - 0.1), Math.min(1, value + 0.1)];
|
|
166
|
+
return {
|
|
167
|
+
limitMax,
|
|
168
|
+
w: {
|
|
169
|
+
relevance: weight(policy.w.relevance),
|
|
170
|
+
importance: weight(policy.w.importance),
|
|
171
|
+
recency: weight(policy.w.recency),
|
|
172
|
+
usage: weight(policy.w.usage),
|
|
173
|
+
},
|
|
174
|
+
threshold: [Math.min(0.05, policy.threshold), Math.max(0.3, policy.threshold)],
|
|
175
|
+
hopEntity: [Math.max(0, policy.hopEntity - 0.15), Math.min(1, policy.hopEntity + 0.15)],
|
|
176
|
+
hopEdge: [Math.max(0, policy.hopEdge - 0.2), Math.min(1, policy.hopEdge + 0.2)],
|
|
177
|
+
kinds: policy.kinds,
|
|
178
|
+
minImportance: policy.minImportance,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
/** The terminal registry's key for a conversation - runs use their assignment id. */
|
|
182
|
+
export function conversationTerminalKey(sessionId) {
|
|
183
|
+
return 'chat:' + sessionId;
|
|
184
|
+
}
|
|
79
185
|
export class Assistant extends EventEmitter {
|
|
80
186
|
config;
|
|
81
187
|
store;
|
|
@@ -97,6 +203,13 @@ export class Assistant extends EventEmitter {
|
|
|
97
203
|
* and can be started by hand from the memory page.
|
|
98
204
|
*/
|
|
99
205
|
sleep;
|
|
206
|
+
/**
|
|
207
|
+
* The questions the assistant has put to the user and is waiting on. Held
|
|
208
|
+
* here, next to the company and the clock, because a question outlives the
|
|
209
|
+
* surface it appeared on: whoever is at a screen may answer it, so it
|
|
210
|
+
* cannot belong to one socket, one terminal or one chat.
|
|
211
|
+
*/
|
|
212
|
+
questions;
|
|
100
213
|
/**
|
|
101
214
|
* Whether a notification would actually reach the user right now. Set by
|
|
102
215
|
* whoever owns the outgoing channels (the server, for its gateways); left
|
|
@@ -105,11 +218,27 @@ export class Assistant extends EventEmitter {
|
|
|
105
218
|
* a blocked recipient or a channel that was switched off mid-session.
|
|
106
219
|
*/
|
|
107
220
|
notifyProbe;
|
|
221
|
+
/**
|
|
222
|
+
* The last status seen for a task, by id - only so the board-watch
|
|
223
|
+
* subscriber can tell a fresh landing in `failed` apart from an unrelated
|
|
224
|
+
* edit to a task that was already sitting there. Never read for anything
|
|
225
|
+
* else.
|
|
226
|
+
*
|
|
227
|
+
* Filled from the board when the clock starts, not left empty: a map that
|
|
228
|
+
* starts empty makes every already-failed task look like a fresh landing,
|
|
229
|
+
* so the first harmless edit to any of them after a restart - a priority,
|
|
230
|
+
* a title - would wake the watcher for a state it had already reported.
|
|
231
|
+
* Edge-triggered has to mean edge-triggered across a restart as well.
|
|
232
|
+
*/
|
|
233
|
+
#taskStatusSeen = new Map();
|
|
108
234
|
constructor(options = {}) {
|
|
109
235
|
super();
|
|
110
236
|
this.config = loadConfig(options.config ?? {});
|
|
111
237
|
this.store = options.store ?? new Store(databasePath(this.config));
|
|
112
238
|
this.providers = options.registry ?? new ProviderRegistry();
|
|
239
|
+
// Layer in configured provider profiles (e.g. GLM). A no-op when there
|
|
240
|
+
// are none, and harmless for the fixed provider lists tests inject.
|
|
241
|
+
this.providers.sync(this.config);
|
|
113
242
|
this.log =
|
|
114
243
|
options.logger ??
|
|
115
244
|
(this.config.logLevel === 'silent'
|
|
@@ -123,12 +252,25 @@ export class Assistant extends EventEmitter {
|
|
|
123
252
|
timeoutMs: this.config.org.assignmentTimeoutMs,
|
|
124
253
|
});
|
|
125
254
|
// Before the controller: the `sleep_now` tool needs it at construction.
|
|
255
|
+
// The promotion hook is a closure rather than `this.org.sendUserMail`
|
|
256
|
+
// itself for exactly that reason - the controller does not exist yet
|
|
257
|
+
// here, and it does by the time a night can promote anything.
|
|
126
258
|
this.sleep = new SleepRunner({
|
|
127
259
|
store: this.store,
|
|
128
260
|
registry: this.providers,
|
|
129
261
|
config: this.config,
|
|
130
262
|
logger: this.log,
|
|
263
|
+
onPromotion: (notice) => this.#announcePromotion(notice),
|
|
131
264
|
});
|
|
265
|
+
// Before the controller, like the night shift: the `ask_user` tool needs
|
|
266
|
+
// it at construction. Its own emitter is what the Assistant re-broadcasts:
|
|
267
|
+
// a question-closed can arrive after the asking turn's queue has closed -
|
|
268
|
+
// answered late, or cancelled when the turn's token was retired - and the
|
|
269
|
+
// turn stream would drop it exactly then, so the registry is the one wire
|
|
270
|
+
// both halves can rely on.
|
|
271
|
+
this.questions = new QuestionRegistry();
|
|
272
|
+
this.questions.on('question', (event) => this.emit('question', event));
|
|
273
|
+
this.questions.on('question-closed', (event) => this.emit('question-closed', event));
|
|
132
274
|
this.org = new OrgController({
|
|
133
275
|
store: this.store,
|
|
134
276
|
registry: this.providers,
|
|
@@ -137,6 +279,7 @@ export class Assistant extends EventEmitter {
|
|
|
137
279
|
logger: this.log,
|
|
138
280
|
cron: this.cron,
|
|
139
281
|
sleep: this.sleep,
|
|
282
|
+
questions: this.questions,
|
|
140
283
|
// The `notify` tool asks this instead of a transport it cannot see. A
|
|
141
284
|
// listener on `notify` is the floor, not the answer: a push service
|
|
142
285
|
// attaches once at startup and stays attached while it is switched
|
|
@@ -144,16 +287,27 @@ export class Assistant extends EventEmitter {
|
|
|
144
287
|
// a channel that drops the message. Whoever hosts the runtime sets
|
|
145
288
|
// `notifyProbe` to the honest test.
|
|
146
289
|
canNotify: () => (this.notifyProbe ? this.notifyProbe() : this.listenerCount('notify') > 0),
|
|
290
|
+
runAssistantMail: (input) => this.#answerMail(input.mail, input.senderLabel, input.thread),
|
|
147
291
|
});
|
|
148
292
|
this.cron.on('cron', (event) => this.emit('cron', event));
|
|
149
293
|
this.cron.on('message', (event) => this.emit('message', event));
|
|
294
|
+
this.cron.on('mail', (event) => this.emit('mail', event));
|
|
150
295
|
// Every client watches the brain fall asleep and wake up again.
|
|
151
296
|
this.sleep.on('sleep', (event) => this.emit('sleep', event));
|
|
152
297
|
// Anything an agent does is interesting to every client, not only the
|
|
153
298
|
// turn that caused it: the org page shows activity live.
|
|
154
299
|
this.org.on('assignment', (event) => this.emit('assignment', event));
|
|
300
|
+
// Live transcript lines of a running assignment, for whoever opted into
|
|
301
|
+
// watching that run - the TUI's watch mode and the server's watching
|
|
302
|
+
// sockets, never a blanket fan-out.
|
|
303
|
+
this.org.on('assignment-log', (frame) => this.emit('assignment-log', frame));
|
|
155
304
|
this.org.on('message', (event) => this.emit('message', event));
|
|
305
|
+
this.org.on('mail', (event) => this.emit('mail', event));
|
|
156
306
|
this.org.on('task', (event) => this.emit('task', event));
|
|
307
|
+
// The watcher's fast path (section 5): a task landing in `failed` or
|
|
308
|
+
// `blocked` wakes it through the same event machinery a webhook or an
|
|
309
|
+
// IMAP listener uses, no different from any other schedule.
|
|
310
|
+
this.org.on('task', (event) => this.#onTaskEvent(event));
|
|
157
311
|
this.org.on('changed', (change) => this.emit('changed', change));
|
|
158
312
|
// The assistant reaching out on its own initiative - no HTTP, no
|
|
159
313
|
// Telegram here, just an event a channel in another package can listen
|
|
@@ -161,8 +315,13 @@ export class Assistant extends EventEmitter {
|
|
|
161
315
|
this.org.on('notify', (event) => this.emit('notify', event));
|
|
162
316
|
}
|
|
163
317
|
close() {
|
|
318
|
+
// Anything still waiting on a person is settled first: an open question
|
|
319
|
+
// holds a promise inside a tool call, and shutting down around it would
|
|
320
|
+
// leave that call to time out long after there is anybody to answer.
|
|
321
|
+
this.questions.cancelAll();
|
|
164
322
|
this.cron.stop();
|
|
165
323
|
void this.org.bridge.close();
|
|
324
|
+
void sharedCodexBridge.close();
|
|
166
325
|
this.store.close();
|
|
167
326
|
}
|
|
168
327
|
/* ---------------------------- sessions ---------------------------- */
|
|
@@ -192,6 +351,11 @@ export class Assistant extends EventEmitter {
|
|
|
192
351
|
return this.store.listSessions({ limit, agentId, kind, includeArchived });
|
|
193
352
|
}
|
|
194
353
|
deleteSession(id) {
|
|
354
|
+
// A frame is a verbatim store of what was said in this session, so it
|
|
355
|
+
// may never outlive the session it quotes (R17). Dropped before the
|
|
356
|
+
// session row goes, the same safe direction the memory-retiring store
|
|
357
|
+
// methods take for their owner's frames.
|
|
358
|
+
this.store.dropDreamFramesForSession(id);
|
|
195
359
|
this.store.deleteSession(id);
|
|
196
360
|
}
|
|
197
361
|
/** Forget the provider-side thread so the next turn starts cold. */
|
|
@@ -202,6 +366,13 @@ export class Assistant extends EventEmitter {
|
|
|
202
366
|
.run(id);
|
|
203
367
|
}
|
|
204
368
|
/* ------------------------------ memory ---------------------------- */
|
|
369
|
+
/**
|
|
370
|
+
* Read-only memory search for surfaces that inspect the bank. This is the
|
|
371
|
+
* `site: 'inspect'` population of the dream's vocabulary: never framed,
|
|
372
|
+
* never scored - the recorder sits at the conversational call site, never
|
|
373
|
+
* inside `recall` (R19), precisely so a browser search or a CLI call with a
|
|
374
|
+
* free-form owner cannot end up in the night's pool.
|
|
375
|
+
*/
|
|
205
376
|
recallMemories(text, limit) {
|
|
206
377
|
return recall(this.store, {
|
|
207
378
|
text,
|
|
@@ -244,9 +415,10 @@ export class Assistant extends EventEmitter {
|
|
|
244
415
|
}
|
|
245
416
|
/**
|
|
246
417
|
* Make sure the nightly run has a schedule. Called once when the clock
|
|
247
|
-
* starts. The job is an ordinary `cron_jobs` row
|
|
248
|
-
*
|
|
249
|
-
*
|
|
418
|
+
* starts. The job is an ordinary `cron_jobs` row - one timer, no second
|
|
419
|
+
* hidden one anywhere - but it is Rookery's internal clockwork, not a
|
|
420
|
+
* user schedule: every list filters it out, and the memory page is the
|
|
421
|
+
* only place it is shown and managed.
|
|
250
422
|
*/
|
|
251
423
|
ensureSleepSchedule() {
|
|
252
424
|
const sleep = this.config.memory.sleep;
|
|
@@ -254,7 +426,9 @@ export class Assistant extends EventEmitter {
|
|
|
254
426
|
return null;
|
|
255
427
|
try {
|
|
256
428
|
const organization = this.org.activeOrganization();
|
|
257
|
-
const existing = this.cron
|
|
429
|
+
const existing = this.cron
|
|
430
|
+
.list(organization.id, { includeSystem: true })
|
|
431
|
+
.find((job) => job.kind === 'sleep');
|
|
258
432
|
if (existing) {
|
|
259
433
|
// Follow the config when the user changes it there, but never
|
|
260
434
|
// re-enable a job they switched off by hand.
|
|
@@ -277,22 +451,222 @@ export class Assistant extends EventEmitter {
|
|
|
277
451
|
return null;
|
|
278
452
|
}
|
|
279
453
|
}
|
|
454
|
+
/* ------------------------------- board watch ----------------------------- */
|
|
455
|
+
/**
|
|
456
|
+
* Make sure the board has a watcher. Called once when the clock starts.
|
|
457
|
+
*
|
|
458
|
+
* Unlike the nightly memory schedule, this row is an ordinary, visible
|
|
459
|
+
* `cron_jobs` entry - E8 wants it editable and switchable in the same UI as
|
|
460
|
+
* every other job, not hidden system clockwork. Seeding is idempotent by
|
|
461
|
+
* id: a second call, on a later start, finds the same row and returns it
|
|
462
|
+
* untouched, whatever a person did to it since - edited the schedule,
|
|
463
|
+
* rewritten the prompt, switched it off. Only a row that does not exist yet
|
|
464
|
+
* gets created.
|
|
465
|
+
*/
|
|
466
|
+
ensureBoardWatchSchedule() {
|
|
467
|
+
try {
|
|
468
|
+
const organization = this.org.activeOrganization();
|
|
469
|
+
// Seed the edge detector before the subscriber can fire: every task
|
|
470
|
+
// already on the board counts as "seen in this state", so only a real
|
|
471
|
+
// transition from here on wakes the watcher. Without this the first
|
|
472
|
+
// unrelated edit to an old failed task would look like a new failure.
|
|
473
|
+
for (const task of this.store.org.listTasks(organization.id, { anyLevel: true, limit: 5000 })) {
|
|
474
|
+
this.#taskStatusSeen.set(task.id, task.status);
|
|
475
|
+
}
|
|
476
|
+
const id = boardWatchJobId(organization.id);
|
|
477
|
+
const existing = this.cron.get(id);
|
|
478
|
+
if (existing && existing.orgId === organization.id)
|
|
479
|
+
return existing;
|
|
480
|
+
return this.cron.create({
|
|
481
|
+
id,
|
|
482
|
+
orgId: organization.id,
|
|
483
|
+
name: 'Board watch',
|
|
484
|
+
schedule: BOARD_WATCH_SCHEDULE,
|
|
485
|
+
triggerMode: 'schedule',
|
|
486
|
+
// The clock is the backstop; the fast path is the task-event
|
|
487
|
+
// subscriber below. A minute keeps ten failures or blocks in one
|
|
488
|
+
// burst to one run, exactly like every other event-fed schedule.
|
|
489
|
+
eventCooldownMs: 60_000,
|
|
490
|
+
kind: 'assistant',
|
|
491
|
+
prompt: BOARD_WATCH_PROMPT,
|
|
492
|
+
createdBy: 'assistant',
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
catch (error) {
|
|
496
|
+
this.log.warn('Could not set up the board watcher', { error: error.message });
|
|
497
|
+
return null;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* What the board watcher would have something to say about, decided in
|
|
502
|
+
* SQL rather than by a model.
|
|
503
|
+
*
|
|
504
|
+
* The watcher used to be a full turn every thirty minutes plus one per
|
|
505
|
+
* event - roughly fifty model runs a day whose usual answer was
|
|
506
|
+
* `[SILENT]`. "Is anything wrong" is a query; only "is this worth
|
|
507
|
+
* interrupting somebody over, and how do I put it" needs judgment. So the
|
|
508
|
+
* clock runs this first, the model is never started unless this finds
|
|
509
|
+
* something, and when it does the findings go into the prompt: the turn
|
|
510
|
+
* begins already knowing what it is there for.
|
|
511
|
+
*
|
|
512
|
+
* Nothing is reported twice. Everything that went wrong before the
|
|
513
|
+
* watcher last actually said something was covered by that report, so
|
|
514
|
+
* only what became true since then is news. That is what stops a board
|
|
515
|
+
* with one permanently broken task on it from mailing about it
|
|
516
|
+
* forty-eight times a day.
|
|
517
|
+
*/
|
|
518
|
+
#boardAttention(orgId, jobId) {
|
|
519
|
+
const now = Date.now();
|
|
520
|
+
// The mark is stored, not reconstructed from the run history.
|
|
521
|
+
//
|
|
522
|
+
// Reading "the newest run that produced a result" out of the last N
|
|
523
|
+
// runs looked equivalent and was not, in three ways. A quiet board
|
|
524
|
+
// writes a silent run every half hour, so after ten hours the speaking
|
|
525
|
+
// run had fallen out of any fixed window and every old failure became
|
|
526
|
+
// news again. A pass the model ended with `[SILENT]` left no result at
|
|
527
|
+
// all, so a finding it had deliberately judged not worth reporting came
|
|
528
|
+
// back every thirty minutes for ever. And both readings confused two
|
|
529
|
+
// different questions: what the model chose to say, and what it was
|
|
530
|
+
// shown. This answers the second - the mark moves when the findings are
|
|
531
|
+
// handed over, whatever the model then decides to do with them.
|
|
532
|
+
const markKey = 'board-watch:seen:' + jobId;
|
|
533
|
+
const since = Number(this.store.getMeta(markKey) ?? 0);
|
|
534
|
+
// A run that has outlived twice its own hard stop is not slow: either
|
|
535
|
+
// its timer never fired or the row was orphaned by a crash.
|
|
536
|
+
const stuckAfter = this.config.org.assignmentTimeoutMs * 2;
|
|
537
|
+
const lines = [];
|
|
538
|
+
// An explicit ceiling, and a high one. `listTasks` defaults to 100
|
|
539
|
+
// ordered by priority then oldest-first, so on a board that has built up
|
|
540
|
+
// history the newest failure - the one that matters - is exactly the row
|
|
541
|
+
// that falls off the end and is never seen.
|
|
542
|
+
for (const task of this.store.org.listTasks(orgId, { anyLevel: true, status: ['failed', 'running'], limit: 5000 })) {
|
|
543
|
+
const label = '[' + task.id.slice(0, 8) + '] ' + task.title;
|
|
544
|
+
if (task.status === 'failed') {
|
|
545
|
+
const landed = task.finishedAt ?? task.updatedAt;
|
|
546
|
+
if (landed <= since)
|
|
547
|
+
continue;
|
|
548
|
+
const runs = this.store.org.taskRunCount(task.id);
|
|
549
|
+
lines.push(label + ' failed' + (runs > 1 ? ' on run ' + runs : '') +
|
|
550
|
+
(task.error ? ': ' + task.error : '') + ' (' + formatAge(landed, now, 'minute') + ' ago)');
|
|
551
|
+
continue;
|
|
552
|
+
}
|
|
553
|
+
const started = task.startedAt ?? task.updatedAt;
|
|
554
|
+
// The moment it became stuck, not the moment we noticed: a task that
|
|
555
|
+
// crossed that line before the last report was in that report.
|
|
556
|
+
const crossed = started + stuckAfter;
|
|
557
|
+
if (crossed > now || crossed <= since)
|
|
558
|
+
continue;
|
|
559
|
+
lines.push(label + ' has been running ' + formatAge(started, now, 'minute') + ' with no end');
|
|
560
|
+
}
|
|
561
|
+
// Only a pass that actually found something moves the mark: a quiet
|
|
562
|
+
// look must not silently swallow a failure that lands a second later.
|
|
563
|
+
if (lines.length)
|
|
564
|
+
this.store.setMeta(markKey, String(now));
|
|
565
|
+
return lines;
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* A task crossed into `failed` - the one transition the watcher cares
|
|
569
|
+
* about (E8, section 5). The clock behind it fires every thirty minutes
|
|
570
|
+
* regardless; this is only the fast path, and it is edge-triggered on
|
|
571
|
+
* purpose: a task that merely stays failed while its title or priority
|
|
572
|
+
* changes must not re-fire the watcher on every one of those unrelated
|
|
573
|
+
* edits, only on actually landing in the state.
|
|
574
|
+
*
|
|
575
|
+
* `blocked` used to wake it too, and that was backwards. Blocked means an
|
|
576
|
+
* agent asked a person something and the board is correctly waiting for
|
|
577
|
+
* the answer. Waking a watcher on it meant the system's reaction to being
|
|
578
|
+
* asked a question was to go and do something instead - within a minute,
|
|
579
|
+
* while the person was still reading it.
|
|
580
|
+
*/
|
|
581
|
+
#onTaskEvent(event) {
|
|
582
|
+
if (event.type !== 'task')
|
|
583
|
+
return;
|
|
584
|
+
const { task } = event;
|
|
585
|
+
const attention = task.status === 'failed';
|
|
586
|
+
const before = this.#taskStatusSeen.get(task.id);
|
|
587
|
+
this.#taskStatusSeen.set(task.id, task.status);
|
|
588
|
+
if (!attention || before === task.status)
|
|
589
|
+
return;
|
|
590
|
+
const id = boardWatchJobId(task.orgId);
|
|
591
|
+
void this.cron.runEvent(id, 'task ' + task.id.slice(0, 8) + ' turned ' + task.status).catch((error) => {
|
|
592
|
+
this.log.warn('Could not wake the board watcher', { error: String(error) });
|
|
593
|
+
});
|
|
594
|
+
}
|
|
280
595
|
/* ------------------------------- chat ----------------------------- */
|
|
281
|
-
/**
|
|
596
|
+
/**
|
|
597
|
+
* One conversational turn, streamed - and journalled while it runs.
|
|
598
|
+
*
|
|
599
|
+
* The wrapper is the single place every yielded event passes through, which
|
|
600
|
+
* is what makes the journal faithful: whatever a live client saw, in the
|
|
601
|
+
* order it saw it, numbered once each. A client that arrives late - a
|
|
602
|
+
* reloaded tab, another browser - reads the same events back and continues
|
|
603
|
+
* from the same numbers, so rejoining can neither duplicate nor drop.
|
|
604
|
+
*
|
|
605
|
+
* `#chatTurn` does the work and opens the journal once its session is
|
|
606
|
+
* resolved; events yielded before that (a rejected empty prompt, say) are
|
|
607
|
+
* ephemeral by nature and stay unjournalled.
|
|
608
|
+
*/
|
|
282
609
|
async *chat(input) {
|
|
610
|
+
const turnId = input.turnId ?? randomUUID();
|
|
611
|
+
const startedAt = Date.now();
|
|
612
|
+
const journal = { begun: false };
|
|
613
|
+
// The backstop a turn never had. A run and a schedule both stop
|
|
614
|
+
// themselves; a turn ran until its provider process did, and over
|
|
615
|
+
// `POST /api/chat` - which passes no signal - nobody could interrupt
|
|
616
|
+
// it. The caller's own signal still works and still wins; this only
|
|
617
|
+
// adds an end to turns that would otherwise not have one.
|
|
618
|
+
const guard = new AbortController();
|
|
619
|
+
const onCallerAbort = () => guard.abort();
|
|
620
|
+
// A signal that was already aborted never fires the event again, so
|
|
621
|
+
// forwarding only through the listener would start a turn the caller
|
|
622
|
+
// had already given up on.
|
|
623
|
+
if (input.signal?.aborted)
|
|
624
|
+
guard.abort();
|
|
625
|
+
else
|
|
626
|
+
input.signal?.addEventListener('abort', onCallerAbort, { once: true });
|
|
627
|
+
const timer = setTimeout(() => guard.abort(), this.config.turns.timeoutMs);
|
|
628
|
+
// Node keeps the process alive for a pending timer; this one must never
|
|
629
|
+
// be the reason a CLI command refuses to exit.
|
|
630
|
+
timer.unref?.();
|
|
631
|
+
const guarded = { ...input, signal: guard.signal };
|
|
632
|
+
try {
|
|
633
|
+
for await (const event of this.#chatTurn(guarded, turnId, journal)) {
|
|
634
|
+
if (journal.begun)
|
|
635
|
+
this.store.turns.append(turnId, event);
|
|
636
|
+
yield event;
|
|
637
|
+
}
|
|
638
|
+
if (journal.begun) {
|
|
639
|
+
this.store.turns.settle(turnId, 'done', Date.now());
|
|
640
|
+
// Only an orderly end is an episode: a turn that died mid-flight has
|
|
641
|
+
// no outcome to judge a trajectory against (concept 7.2).
|
|
642
|
+
this.#recordTrialEpisode(turnId, journal, startedAt);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
catch (error) {
|
|
646
|
+
// The turn died mid-flight. Whatever reached the journal is the only
|
|
647
|
+
// record of it - it stays, marked, rather than vanishing whole.
|
|
648
|
+
if (journal.begun)
|
|
649
|
+
this.store.turns.settle(turnId, 'interrupted', Date.now());
|
|
650
|
+
throw error;
|
|
651
|
+
}
|
|
652
|
+
finally {
|
|
653
|
+
clearTimeout(timer);
|
|
654
|
+
input.signal?.removeEventListener('abort', onCallerAbort);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
async *#chatTurn(input, turnId, journal) {
|
|
283
658
|
const prompt = input.text.trim();
|
|
284
659
|
if (!prompt) {
|
|
285
660
|
yield { type: 'error', message: 'Nothing to send.', fatal: true };
|
|
286
661
|
return;
|
|
287
662
|
}
|
|
288
663
|
const session = this.#resolveSession(input);
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
const owner = agent ? agent.id : ASSISTANT_MEMORY_OWNER;
|
|
664
|
+
this.store.turns.begin(turnId, session.id, 'chat', Date.now());
|
|
665
|
+
journal.begun = true;
|
|
666
|
+
journal.sessionId = session.id;
|
|
667
|
+
// Chat is exclusively the assistant's own conversation; a stale
|
|
668
|
+
// `agentId` on an old session is never read here any more.
|
|
669
|
+
const owner = ASSISTANT_MEMORY_OWNER;
|
|
296
670
|
if (input.projectId && input.projectId !== session.projectId) {
|
|
297
671
|
this.store.updateSession(session.id, { projectId: input.projectId });
|
|
298
672
|
session.projectId = input.projectId;
|
|
@@ -301,216 +675,315 @@ export class Assistant extends EventEmitter {
|
|
|
301
675
|
const providerId = await this.providers.resolveUsable(wanted);
|
|
302
676
|
if (!providerId) {
|
|
303
677
|
const statuses = await this.providers.statuses();
|
|
304
|
-
|
|
678
|
+
// A provider parked for quota says so here rather than hiding behind
|
|
679
|
+
// its login state: "out of quota" tells the user what to wait for.
|
|
680
|
+
const detail = statuses
|
|
681
|
+
.map((s) => s.id + ': ' + (providerBlocked(s.id) ? 'out of quota' : (s.detail ?? 'unavailable')))
|
|
682
|
+
.join(' | ');
|
|
305
683
|
yield { type: 'error', message: 'No AI provider is ready. ' + detail, fatal: true };
|
|
306
684
|
return;
|
|
307
685
|
}
|
|
308
686
|
if (providerId !== wanted) {
|
|
309
|
-
yield { type: 'status', label: 'provider', detail: wanted
|
|
687
|
+
yield { type: 'status', label: 'provider', detail: this.#switchReason(wanted, providerId) };
|
|
310
688
|
}
|
|
311
689
|
// Resuming the provider's own thread only works on the same provider.
|
|
312
690
|
const resumed = Boolean(session.providerSessionId) && session.provider === providerId;
|
|
313
691
|
const model = input.model ?? session.model ?? this.config.defaultModel;
|
|
314
692
|
const effort = input.effort ?? this.config.defaultEffort;
|
|
315
693
|
let memories = [];
|
|
694
|
+
/**
|
|
695
|
+
* The recall as it went out on the wire, kept so the ordered transcript
|
|
696
|
+
* can carry it too: the recall happens before the first provider attempt,
|
|
697
|
+
* and `turnBlocks` below is only born once one is about to start.
|
|
698
|
+
*/
|
|
699
|
+
let recall;
|
|
316
700
|
if (this.config.memory.enabled) {
|
|
317
701
|
yield { type: 'status', label: 'recalling', detail: 'searching memory' };
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
hopEdge: this.config.memory.graph.hopEdge,
|
|
325
|
-
});
|
|
326
|
-
const profile = coreProfile(this.store, {
|
|
327
|
-
owner,
|
|
328
|
-
limit: Math.max(3, Math.floor(this.config.memory.recallLimit / 2)),
|
|
329
|
-
});
|
|
330
|
-
const byId = new Map();
|
|
331
|
-
for (const memory of profile)
|
|
332
|
-
byId.set(memory.id, memory);
|
|
333
|
-
for (const memory of matched)
|
|
334
|
-
byId.set(memory.id, memory);
|
|
335
|
-
// Of a contradicting pair only the newer sentence goes into the prompt;
|
|
336
|
-
// the older one stays in the bank and stays visible in the inspector.
|
|
337
|
-
memories = dropContradicted(this.store, [...byId.values()]).sort((a, b) => b.score - a.score);
|
|
702
|
+
// One truth about the recall parameters (concept 9.3): the resolver
|
|
703
|
+
// clamps at read time and both the turn and the recorder read it here,
|
|
704
|
+
// so a config change cannot leave the record and the live turn
|
|
705
|
+
// disagreeing about which policy produced the prompt.
|
|
706
|
+
const policy = resolvePolicy(this.store, this.config, owner, 'recall');
|
|
707
|
+
memories = this.#turnMemories(session, owner, prompt, policy, turnId);
|
|
338
708
|
if (memories.length) {
|
|
339
|
-
|
|
709
|
+
// The turn id travels with the list the surface is about to render:
|
|
710
|
+
// a click on one of these rows becomes a label about THIS turn, not
|
|
711
|
+
// about the session it happened in (S6, concept 4.2b).
|
|
712
|
+
recall = { type: 'memory', action: 'recalled', count: memories.length, items: memories, turnId };
|
|
713
|
+
yield recall;
|
|
340
714
|
}
|
|
341
715
|
}
|
|
342
|
-
|
|
716
|
+
// Read before the turn stores its own user message: a retry that cannot
|
|
717
|
+
// resume the dead provider's thread rebuilds its prompt from this.
|
|
718
|
+
const turnHistory = this.store.getMessages(session.id, this.config.memory.workingWindow);
|
|
719
|
+
const history = resumed ? [] : turnHistory;
|
|
343
720
|
// The company block: who works here, what is running, what arrived in
|
|
344
|
-
// the
|
|
721
|
+
// the mail. Read once per turn; the mail is then marked as read.
|
|
345
722
|
const organization = this.org.activeOrganization();
|
|
346
723
|
const snapshot = this.org.snapshot(organization.id);
|
|
347
|
-
const
|
|
724
|
+
const mail = this.store.org.unreadMailFor(organization.id, { kind: 'assistant' });
|
|
348
725
|
const project = session.projectId ? (this.store.org.getProject(session.projectId) ?? undefined) : undefined;
|
|
349
|
-
if (
|
|
350
|
-
this.store.org.
|
|
351
|
-
//
|
|
352
|
-
//
|
|
353
|
-
const who =
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
//
|
|
357
|
-
//
|
|
358
|
-
const
|
|
359
|
-
const skillsIndex =
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
726
|
+
if (mail.length)
|
|
727
|
+
this.store.org.markMailReadFor(mail, { kind: 'assistant' });
|
|
728
|
+
// Who is asking: the assistant. The tool servers and the prompt built on
|
|
729
|
+
// them are per provider attempt, because each provider attaches its own.
|
|
730
|
+
const who = 'assistant';
|
|
731
|
+
// Rookery's own shelf in full, and one paragraph for the far larger one
|
|
732
|
+
// installed in Claude Code: what is there, not what it says. Then the few
|
|
733
|
+
// that look like this turn - searched here rather than left to a tool call
|
|
734
|
+
// the model has to think of, the same way its memories arrive.
|
|
735
|
+
const ownSkills = this.skills.for(who);
|
|
736
|
+
const skillsIndex = [
|
|
737
|
+
renderSkillsIndex(ownSkills),
|
|
738
|
+
renderExternalSkillsHint(this.config, who),
|
|
739
|
+
renderSkillMatches(matchSkills(this.config, who, ownSkills, prompt)),
|
|
740
|
+
]
|
|
741
|
+
.filter(Boolean)
|
|
742
|
+
.join('\n\n');
|
|
743
|
+
// The journal's id, on the message (concept 9.4): it is what makes a
|
|
744
|
+
// quote from this prompt locatable to this exact turn later, instead of
|
|
745
|
+
// to a position counted off the transcript.
|
|
746
|
+
this.store.addMessage({ sessionId: session.id, role: 'user', content: prompt, turnId });
|
|
747
|
+
if (session.messageCount === 0 && session.title === 'New conversation') {
|
|
748
|
+
this.store.updateSession(session.id, { title: deriveTitle(prompt) });
|
|
749
|
+
}
|
|
750
|
+
const started = Date.now();
|
|
751
|
+
let answer = '';
|
|
752
|
+
const toolCalls = [];
|
|
753
|
+
// The same turn as an ordered transcript: text, thinking and tools in
|
|
754
|
+
// arrival order, kept beside the flat views. One instance spans every
|
|
755
|
+
// pass of every attempt; a provider fallback is the only reset.
|
|
756
|
+
const turnBlocks = new TurnBlocks();
|
|
757
|
+
// What was put in front of the answer, first in the transcript because it
|
|
758
|
+
// was first in the turn. It survives `clear()`, so a fallback attempt
|
|
759
|
+
// keeps it too.
|
|
760
|
+
if (recall)
|
|
761
|
+
turnBlocks.apply(recall);
|
|
762
|
+
let providerSessionId = resumed ? session.providerSessionId : undefined;
|
|
763
|
+
let usage;
|
|
764
|
+
let lastFatal = null;
|
|
765
|
+
/** The provider and model the turn ends up having run with. */
|
|
766
|
+
let usedProvider = providerId;
|
|
767
|
+
let usedModel = model;
|
|
768
|
+
const tried = new Set([providerId]);
|
|
769
|
+
for (let attempt = 1; attempt <= MAX_PROVIDER_ATTEMPTS; attempt += 1) {
|
|
770
|
+
const pid = usedProvider;
|
|
771
|
+
// A different backend serves different names; the fallback provider's
|
|
772
|
+
// own default stands in for a model it has never heard of.
|
|
773
|
+
usedModel = attempt === 1 && pid === wanted ? model : remapModel(pid, model);
|
|
774
|
+
// The hub decides which extra MCP servers this attempt gets, and the
|
|
775
|
+
// prompt carries one paragraph per server plus the index of skills to
|
|
776
|
+
// open. Provider-scoped, so a switch attaches its own set.
|
|
777
|
+
const extra = toolServersFor(this.config, who, pid, project?.id);
|
|
778
|
+
// The assistant also hears about the servers it could attach but has not:
|
|
779
|
+
// a switch it does not know about is a wall it cannot climb.
|
|
780
|
+
const toolHints = [...extra.hints, dormantToolsHint(this.config, who, project?.id)].filter(Boolean);
|
|
781
|
+
const systemPrompt = buildSystemPrompt({
|
|
366
782
|
config: this.config,
|
|
367
783
|
query: prompt,
|
|
368
784
|
memories,
|
|
369
|
-
|
|
370
|
-
|
|
785
|
+
// A retry cannot resume the dead provider's thread, so it rebuilds
|
|
786
|
+
// its context from the history it still has.
|
|
787
|
+
history: attempt === 1 ? history : turnHistory,
|
|
788
|
+
resumed: attempt === 1 && resumed,
|
|
371
789
|
// A voice session speaks whichever surface the turn came from.
|
|
372
790
|
voice: input.voice ?? session.kind === 'voice',
|
|
373
|
-
orgBlock: assistantOrgBlock(this.config, snapshot,
|
|
791
|
+
orgBlock: assistantOrgBlock(this.config, snapshot, mail, project, this.cron.list(organization.id), this.store),
|
|
374
792
|
toolHints,
|
|
375
793
|
skillsIndex,
|
|
376
794
|
// Lets the memory block group itself by entity.
|
|
377
795
|
store: this.store,
|
|
378
796
|
});
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
797
|
+
const provider = this.providers.get(pid);
|
|
798
|
+
// Only the first attempt may resume the provider's own thread; a
|
|
799
|
+
// fallback starts a fresh one on the new backend.
|
|
800
|
+
providerSessionId = attempt === 1 && resumed ? session.providerSessionId : undefined;
|
|
801
|
+
let failed = false;
|
|
802
|
+
yield { type: 'session', sessionId: session.id, providerSessionId, provider: pid, model: usedModel };
|
|
803
|
+
// The assistant stays in the workspace, not a project directory - it is
|
|
804
|
+
// a person, not Claude Code's coding agent.
|
|
805
|
+
const cwd = this.config.workspace;
|
|
806
|
+
// What this pass of the provider is run with. A turn usually has exactly
|
|
807
|
+
// one pass; see the continuation below for why it sometimes has two.
|
|
808
|
+
let passPrompt = prompt;
|
|
809
|
+
let passSystemPrompt = systemPrompt;
|
|
810
|
+
let passExtra = extra;
|
|
811
|
+
let attached = new Set(extra.specs.map((spec) => spec.name));
|
|
812
|
+
for (let pass = 1; pass <= MAX_PROVIDER_PASSES; pass += 1) {
|
|
813
|
+
// Everything the turn produces goes through one queue: the provider's
|
|
814
|
+
// own events, and whatever the tool calls it makes cause in the company.
|
|
815
|
+
const queue = new EventQueue();
|
|
816
|
+
const token = this.org.register({
|
|
817
|
+
orgId: organization.id,
|
|
818
|
+
audience: 'assistant',
|
|
819
|
+
agentId: undefined,
|
|
820
|
+
sessionId: session.id,
|
|
821
|
+
projectId: session.projectId,
|
|
822
|
+
depth: -1,
|
|
823
|
+
// A scheduled chat run works under the same rule as a scheduled
|
|
824
|
+
// assignment: it may read memory and open skills, but nothing it
|
|
825
|
+
// does lands back in the bank - no extraction, no tools that write.
|
|
826
|
+
// That covers every run with nobody in front of it: a session of
|
|
827
|
+
// kind `schedule`, the mail-answer turn (`kind: 'mail'`), and a
|
|
828
|
+
// schedule pinned to an ordinary conversation, which arrives with
|
|
829
|
+
// `input.scheduled` set. All three are exactly the runs that must
|
|
830
|
+
// not be offered `ask_user` - there is no screen to answer on.
|
|
831
|
+
scheduled: input.scheduled === true || session.kind === 'schedule' || session.kind === 'mail',
|
|
832
|
+
watching: input.watching === true,
|
|
833
|
+
emit: (event) => queue.push(event),
|
|
834
|
+
signal: input.signal,
|
|
835
|
+
});
|
|
836
|
+
const currentPrompt = passPrompt;
|
|
837
|
+
const currentSystemPrompt = passSystemPrompt;
|
|
838
|
+
const currentSpecs = passExtra.specs;
|
|
839
|
+
const currentResume = providerSessionId;
|
|
840
|
+
const pump = (async () => {
|
|
841
|
+
try {
|
|
842
|
+
const mcp = await this.org.bridge.spec(token);
|
|
843
|
+
for await (const event of provider.run({
|
|
844
|
+
prompt: currentPrompt,
|
|
845
|
+
systemPrompt: currentSystemPrompt,
|
|
846
|
+
systemPromptMode: 'replace',
|
|
847
|
+
providerSessionId: currentResume,
|
|
848
|
+
model: usedModel,
|
|
849
|
+
effort,
|
|
850
|
+
cwd,
|
|
851
|
+
permission: input.permission ?? this.config.defaultPermission,
|
|
852
|
+
mcp,
|
|
853
|
+
mcpExtra: currentSpecs.length ? currentSpecs : undefined,
|
|
854
|
+
// Approved subagents and hooks out of the Claude Code
|
|
855
|
+
// installation, plus Rookery's own permission floor.
|
|
856
|
+
...externalTurnExtras(this.config, who),
|
|
857
|
+
signal: input.signal,
|
|
858
|
+
})) {
|
|
859
|
+
queue.push(event);
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
catch (error) {
|
|
863
|
+
queue.push({ type: 'error', message: error.message, fatal: true });
|
|
864
|
+
}
|
|
865
|
+
finally {
|
|
866
|
+
queue.close();
|
|
867
|
+
}
|
|
868
|
+
})();
|
|
869
|
+
let passText = '';
|
|
419
870
|
try {
|
|
420
|
-
const
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
871
|
+
for await (const event of queue.drain()) {
|
|
872
|
+
switch (event.type) {
|
|
873
|
+
case 'tool':
|
|
874
|
+
toolCalls.push(event);
|
|
875
|
+
turnBlocks.apply(event);
|
|
876
|
+
// Also on the assistant's own emitter, not just this stream:
|
|
877
|
+
// a channel that is not the one that started the turn - the
|
|
878
|
+
// phone, watching a schedule run - has no other way to see
|
|
879
|
+
// what is being done. Nobody has to listen; the web UI reads
|
|
880
|
+
// these off the turn stream it already holds.
|
|
881
|
+
this.emit('tool', event);
|
|
882
|
+
yield event;
|
|
883
|
+
break;
|
|
884
|
+
case 'question':
|
|
885
|
+
case 'question-closed':
|
|
886
|
+
// Into this stream only. The assistant's emitter already
|
|
887
|
+
// carries both events - forwarded from the registry, which
|
|
888
|
+
// fires them even when this queue is long closed - so the
|
|
889
|
+
// phone and a second tab see the card without this turn's
|
|
890
|
+
// help, and emitting here as well would say everything twice.
|
|
891
|
+
yield event;
|
|
892
|
+
break;
|
|
893
|
+
case 'text':
|
|
894
|
+
passText += event.delta;
|
|
895
|
+
turnBlocks.apply(event);
|
|
896
|
+
yield event;
|
|
897
|
+
break;
|
|
898
|
+
case 'thinking':
|
|
899
|
+
// Explicit only so the transcript folds it in; on the wire
|
|
900
|
+
// this is the same pass-through `default` already gave it.
|
|
901
|
+
turnBlocks.apply(event);
|
|
902
|
+
yield event;
|
|
903
|
+
break;
|
|
904
|
+
case 'session':
|
|
905
|
+
providerSessionId = event.providerSessionId ?? providerSessionId;
|
|
906
|
+
break;
|
|
907
|
+
case 'done':
|
|
908
|
+
providerSessionId = event.providerSessionId ?? providerSessionId;
|
|
909
|
+
passText = event.text || passText;
|
|
910
|
+
turnBlocks.reconcile(event.text);
|
|
911
|
+
usage = mergeUsage(usage, event.usage);
|
|
912
|
+
break;
|
|
913
|
+
case 'error':
|
|
914
|
+
if (event.fatal) {
|
|
915
|
+
failed = true;
|
|
916
|
+
lastFatal = event.message;
|
|
917
|
+
}
|
|
918
|
+
yield event;
|
|
919
|
+
break;
|
|
920
|
+
default:
|
|
921
|
+
yield event;
|
|
922
|
+
}
|
|
435
923
|
}
|
|
436
924
|
}
|
|
437
|
-
catch (error) {
|
|
438
|
-
queue.push({ type: 'error', message: error.message, fatal: true });
|
|
439
|
-
}
|
|
440
925
|
finally {
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
case 'tool':
|
|
449
|
-
toolCalls.push(event);
|
|
450
|
-
yield event;
|
|
451
|
-
break;
|
|
452
|
-
case 'text':
|
|
453
|
-
passText += event.delta;
|
|
454
|
-
yield event;
|
|
455
|
-
break;
|
|
456
|
-
case 'session':
|
|
457
|
-
providerSessionId = event.providerSessionId ?? providerSessionId;
|
|
458
|
-
break;
|
|
459
|
-
case 'done':
|
|
460
|
-
providerSessionId = event.providerSessionId ?? providerSessionId;
|
|
461
|
-
passText = event.text || passText;
|
|
462
|
-
usage = mergeUsage(usage, event.usage);
|
|
463
|
-
break;
|
|
464
|
-
case 'error':
|
|
465
|
-
if (event.fatal)
|
|
466
|
-
failed = true;
|
|
467
|
-
yield event;
|
|
468
|
-
break;
|
|
469
|
-
default:
|
|
470
|
-
yield event;
|
|
471
|
-
}
|
|
926
|
+
await pump;
|
|
927
|
+
this.org.unregister(token);
|
|
928
|
+
// Every exit, not only an abort: a provider crash or a fallback
|
|
929
|
+
// switch ends the pass without the signal ever firing, and the
|
|
930
|
+
// questions it asked would otherwise stand answerable on every
|
|
931
|
+
// surface for their full timeout, reaching a tool call that is gone.
|
|
932
|
+
this.questions.cancelForOwner(token);
|
|
472
933
|
}
|
|
934
|
+
answer = answer && passText ? answer + '\n\n' + passText : answer || passText;
|
|
935
|
+
// The continuation. A tool server the assistant switched on mid-turn
|
|
936
|
+
// can only be attached to a provider process that has not started yet,
|
|
937
|
+
// so without this the work stalls until the user asks again - exactly
|
|
938
|
+
// the dead end the assistant is told not to accept. Instead the turn
|
|
939
|
+
// runs once more with the new servers attached and the provider's own
|
|
940
|
+
// session resumed, and the two answers are joined.
|
|
941
|
+
if (failed || pass === MAX_PROVIDER_PASSES)
|
|
942
|
+
break;
|
|
943
|
+
if (input.signal?.aborted)
|
|
944
|
+
break;
|
|
945
|
+
const next = toolServersFor(this.config, who, pid, project?.id);
|
|
946
|
+
const fresh = next.specs.map((spec) => spec.name).filter((name) => !attached.has(name));
|
|
947
|
+
if (!fresh.length)
|
|
948
|
+
break;
|
|
949
|
+
passExtra = next;
|
|
950
|
+
attached = new Set(next.specs.map((spec) => spec.name));
|
|
951
|
+
passSystemPrompt = buildSystemPrompt({
|
|
952
|
+
config: this.config,
|
|
953
|
+
query: prompt,
|
|
954
|
+
memories,
|
|
955
|
+
resumed: true,
|
|
956
|
+
voice: input.voice ?? session.kind === 'voice',
|
|
957
|
+
orgBlock: assistantOrgBlock(this.config, snapshot, [], project, this.cron.list(organization.id), this.store),
|
|
958
|
+
toolHints: [...next.hints, dormantToolsHint(this.config, who, project?.id)].filter(Boolean),
|
|
959
|
+
skillsIndex,
|
|
960
|
+
store: this.store,
|
|
961
|
+
});
|
|
962
|
+
passPrompt = continuePrompt(fresh);
|
|
963
|
+
yield { type: 'status', label: 'tools', detail: fresh.join(', ') + ' attached, carrying on' };
|
|
473
964
|
}
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
// The continuation. A tool server the assistant switched on mid-turn
|
|
480
|
-
// can only be attached to a provider process that has not started yet,
|
|
481
|
-
// so without this the work stalls until the user asks again - exactly
|
|
482
|
-
// the dead end the assistant is told not to accept. Instead the turn
|
|
483
|
-
// runs once more with the new servers attached and the provider's own
|
|
484
|
-
// session resumed, and the two answers are joined.
|
|
485
|
-
if (failed || agent || pass === MAX_PROVIDER_PASSES)
|
|
486
|
-
break;
|
|
487
|
-
if (input.signal?.aborted)
|
|
965
|
+
// A turn that died on its usage limit with nothing to show goes around
|
|
966
|
+
// once more on another provider. Anything else keeps today's semantics:
|
|
967
|
+
// nothing usable came back, so the session context stays untouched for
|
|
968
|
+
// the next attempt to resume cleanly.
|
|
969
|
+
if (!failed || answer || toolCalls.length)
|
|
488
970
|
break;
|
|
489
|
-
const
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
store: this.store,
|
|
506
|
-
});
|
|
507
|
-
passPrompt = continuePrompt(fresh);
|
|
508
|
-
yield { type: 'status', label: 'tools', detail: fresh.join(', ') + ' attached, carrying on' };
|
|
509
|
-
}
|
|
510
|
-
if (failed && !answer && !toolCalls.length) {
|
|
511
|
-
// Nothing usable came back; leave the session context untouched so the
|
|
512
|
-
// next attempt can still resume cleanly.
|
|
513
|
-
return;
|
|
971
|
+
const alternate = this.config.providerFallback.enabled &&
|
|
972
|
+
attempt < MAX_PROVIDER_ATTEMPTS &&
|
|
973
|
+
!input.signal?.aborted &&
|
|
974
|
+
lastFatal !== null &&
|
|
975
|
+
isUsageLimitError(lastFatal)
|
|
976
|
+
? await this.providers.resolveUsable(wanted, { exclude: [...tried] })
|
|
977
|
+
: null;
|
|
978
|
+
if (!alternate)
|
|
979
|
+
return;
|
|
980
|
+
rememberUsageFailure(pid);
|
|
981
|
+
yield { type: 'status', label: 'provider', detail: pid + ' hit its usage limit, continuing on ' + alternate };
|
|
982
|
+
usedProvider = alternate;
|
|
983
|
+
tried.add(alternate);
|
|
984
|
+
// The dead attempt belongs to no transcript; the next one starts clean
|
|
985
|
+
// rather than appending to a half-told story.
|
|
986
|
+
turnBlocks.clear();
|
|
514
987
|
}
|
|
515
988
|
// The provider's numbers plus the wall-clock of the whole turn, so a
|
|
516
989
|
// reloaded transcript can still show what the context looked like.
|
|
@@ -519,23 +992,59 @@ export class Assistant extends EventEmitter {
|
|
|
519
992
|
sessionId: session.id,
|
|
520
993
|
role: 'assistant',
|
|
521
994
|
content: answer,
|
|
522
|
-
|
|
523
|
-
|
|
995
|
+
turnId,
|
|
996
|
+
provider: usedProvider,
|
|
997
|
+
model: usedModel,
|
|
524
998
|
usage: turnUsage,
|
|
525
999
|
toolCalls,
|
|
1000
|
+
blocks: turnBlocks.blocks.length ? turnBlocks.blocks : undefined,
|
|
526
1001
|
});
|
|
527
|
-
if (
|
|
1002
|
+
if (lastFatal !== null && !answer)
|
|
528
1003
|
return;
|
|
529
|
-
this.store.updateSession(session.id, { provider:
|
|
1004
|
+
this.store.updateSession(session.id, { provider: usedProvider, model: usedModel, providerSessionId });
|
|
530
1005
|
yield { type: 'done', text: answer, providerSessionId, usage: turnUsage };
|
|
531
|
-
|
|
532
|
-
|
|
1006
|
+
// Scheduled runs stay out of the memory: the "user" side of that
|
|
1007
|
+
// exchange is Rookery's own boilerplate plus the job's prompt, not
|
|
1008
|
+
// something the user said today, and quoting it would file the job
|
|
1009
|
+
// description again on every firing. Mail answers are deliberately
|
|
1010
|
+
// still extracted - a person wrote in, and what they wrote stands.
|
|
1011
|
+
if (this.config.memory.enabled &&
|
|
1012
|
+
this.config.memory.autoExtract &&
|
|
1013
|
+
session.kind !== 'schedule') {
|
|
1014
|
+
void this.#learn(session.id, prompt, answer, usedProvider, owner);
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
/**
|
|
1018
|
+
* What to say when a turn starts on a provider it did not ask for. Quota
|
|
1019
|
+
* reasons first - they are the ones the user cannot see anywhere else - and
|
|
1020
|
+
* a missing login last, which the provider list already shows.
|
|
1021
|
+
*/
|
|
1022
|
+
#switchReason(wanted, chosen) {
|
|
1023
|
+
const blocked = providerBlocked(wanted);
|
|
1024
|
+
if (blocked) {
|
|
1025
|
+
return (wanted +
|
|
1026
|
+
' is out of quota' +
|
|
1027
|
+
(blocked.until ? ' until ' + new Date(blocked.until).toLocaleTimeString() : '') +
|
|
1028
|
+
', using ' +
|
|
1029
|
+
chosen);
|
|
1030
|
+
}
|
|
1031
|
+
if (this.config.providerFallback.enabled && providerLow(wanted, this.config.providerFallback.thresholdPercent)) {
|
|
1032
|
+
return wanted + ' is nearly out of quota, using ' + chosen + ' for now';
|
|
533
1033
|
}
|
|
1034
|
+
return wanted + ' is not logged in, using ' + chosen;
|
|
534
1035
|
}
|
|
535
1036
|
/* ------------------------------ assign ---------------------------- */
|
|
536
1037
|
/**
|
|
537
1038
|
* Give one agent a task directly, outside a conversation. Streams the
|
|
538
|
-
*
|
|
1039
|
+
* run's events and ends with `done` carrying the report.
|
|
1040
|
+
*
|
|
1041
|
+
* Like every other way of handing out work, this puts a card on the board
|
|
1042
|
+
* first (decision E9). It used to call `org.run()` straight, and it is the
|
|
1043
|
+
* entrance the web UI, the websocket, the CLI and every agent schedule all
|
|
1044
|
+
* come through - so the single biggest source of "sometimes there is a
|
|
1045
|
+
* card and sometimes there is only a run" was this one method. The
|
|
1046
|
+
* `assign` tool had already been moved onto the board; this is the same
|
|
1047
|
+
* move for everything that is not a tool call.
|
|
539
1048
|
*/
|
|
540
1049
|
async *assign(input) {
|
|
541
1050
|
const task = input.task.trim();
|
|
@@ -553,34 +1062,82 @@ export class Assistant extends EventEmitter {
|
|
|
553
1062
|
yield { type: 'error', message: 'No project ' + input.projectId + '.', fatal: true };
|
|
554
1063
|
return;
|
|
555
1064
|
}
|
|
1065
|
+
// The card comes first and the run hangs off it, so this work is on the
|
|
1066
|
+
// board from the moment it is handed over rather than only visible as a
|
|
1067
|
+
// row under "runs". `createdBy: 'user'` is the truth here: every caller
|
|
1068
|
+
// of this method is a person acting directly, or a schedule they set up.
|
|
1069
|
+
const card = this.store.org.createTask({
|
|
1070
|
+
orgId: organization.id,
|
|
1071
|
+
title: input.title?.trim() || titleFromBrief(task),
|
|
1072
|
+
description: task,
|
|
1073
|
+
projectId: input.projectId,
|
|
1074
|
+
assigneeId: agent.id,
|
|
1075
|
+
createdBy: 'user',
|
|
1076
|
+
// A card that appeared at three in the morning can say why. The work
|
|
1077
|
+
// is still the user's - they set the schedule up - so `createdBy`
|
|
1078
|
+
// stays `user` and this only names the arrangement that fired.
|
|
1079
|
+
scheduleId: input.scheduleId,
|
|
1080
|
+
});
|
|
1081
|
+
this.org.announceTask(card);
|
|
556
1082
|
const queue = new EventQueue();
|
|
557
1083
|
const run = this.org
|
|
558
|
-
.
|
|
1084
|
+
.runTask({
|
|
559
1085
|
orgId: organization.id,
|
|
560
|
-
|
|
561
|
-
|
|
1086
|
+
audience: 'assistant',
|
|
1087
|
+
depth: -1,
|
|
562
1088
|
projectId: input.projectId,
|
|
1089
|
+
// The conversation this was started from, when there was one. It
|
|
1090
|
+
// is what links the run back into that chat's journal; dropping
|
|
1091
|
+
// it left `turns.session_id` null and the run unfindable from the
|
|
1092
|
+
// conversation that asked for it.
|
|
563
1093
|
sessionId: input.sessionId,
|
|
564
|
-
|
|
565
|
-
depth: 0,
|
|
1094
|
+
scheduled: input.scheduled,
|
|
566
1095
|
emit: (event) => queue.push(event),
|
|
567
1096
|
signal: input.signal,
|
|
568
|
-
})
|
|
1097
|
+
}, card)
|
|
569
1098
|
.finally(() => queue.close());
|
|
570
1099
|
for await (const event of queue.drain())
|
|
571
1100
|
yield event;
|
|
572
|
-
const
|
|
573
|
-
if (
|
|
574
|
-
yield { type: 'done', text:
|
|
1101
|
+
const finished = await run;
|
|
1102
|
+
if (finished.status === 'done') {
|
|
1103
|
+
yield { type: 'done', text: finished.result ?? '' };
|
|
1104
|
+
}
|
|
1105
|
+
else if (finished.status === 'blocked') {
|
|
1106
|
+
// Not a failure: somebody was asked something and the board is
|
|
1107
|
+
// waiting for them. Saying "the run blocked" as an error made a
|
|
1108
|
+
// perfectly good question read as a breakage.
|
|
1109
|
+
yield { type: 'done', text: finished.result ?? 'Waiting for an answer.' };
|
|
575
1110
|
}
|
|
576
1111
|
else {
|
|
577
1112
|
yield {
|
|
578
1113
|
type: 'error',
|
|
579
|
-
message: '
|
|
1114
|
+
message: 'The run ' + finished.status + (finished.error ? ': ' + finished.error : '.'),
|
|
580
1115
|
fatal: true,
|
|
581
1116
|
};
|
|
582
1117
|
}
|
|
583
1118
|
}
|
|
1119
|
+
/* ---------------------------- assignment log ---------------------------- */
|
|
1120
|
+
/**
|
|
1121
|
+
* The live log of a running assignment so far; an unknown or finished id
|
|
1122
|
+
* reads as inactive and empty. Delegates to the org controller.
|
|
1123
|
+
*/
|
|
1124
|
+
snapshotAssignmentLog(assignmentId) {
|
|
1125
|
+
return this.org.snapshotAssignmentLog(assignmentId);
|
|
1126
|
+
}
|
|
1127
|
+
/**
|
|
1128
|
+
* Follow one running assignment's live log; the returned unsub stops the
|
|
1129
|
+
* listener. Delegates to the org controller.
|
|
1130
|
+
*/
|
|
1131
|
+
watchAssignmentLog(assignmentId, listener) {
|
|
1132
|
+
return this.org.watchAssignmentLog(assignmentId, listener);
|
|
1133
|
+
}
|
|
1134
|
+
/**
|
|
1135
|
+
* Replay a running assignment's buffered log, then follow it live until
|
|
1136
|
+
* the run ends. Delegates to the org controller.
|
|
1137
|
+
*/
|
|
1138
|
+
async *assignmentLog(assignmentId) {
|
|
1139
|
+
yield* this.org.assignmentLog(assignmentId);
|
|
1140
|
+
}
|
|
584
1141
|
/* ------------------------------- tasks ---------------------------- */
|
|
585
1142
|
/** Plan one task from the board on the user's behalf. Throws when the task is unknown. */
|
|
586
1143
|
async planTask(taskId, hint) {
|
|
@@ -628,9 +1185,11 @@ export class Assistant extends EventEmitter {
|
|
|
628
1185
|
}
|
|
629
1186
|
/* ----------------------------- schedules -------------------------- */
|
|
630
1187
|
/**
|
|
631
|
-
* Execute one schedule. The assistant's own jobs run as a turn in a
|
|
632
|
-
* conversation
|
|
633
|
-
*
|
|
1188
|
+
* Execute one schedule. The assistant's own jobs run as a turn in a fresh
|
|
1189
|
+
* conversation every firing - a clean rerun each time, not a diary the
|
|
1190
|
+
* assistant keeps adding to - unless the job was pinned to a specific
|
|
1191
|
+
* conversation when it was created (the "reply in this chat" case for a
|
|
1192
|
+
* one-off follow-up); an agent's jobs run as an ordinary assignment.
|
|
634
1193
|
*/
|
|
635
1194
|
async #runScheduled(job, run, signal) {
|
|
636
1195
|
void run;
|
|
@@ -666,7 +1225,19 @@ export class Assistant extends EventEmitter {
|
|
|
666
1225
|
let assignmentId;
|
|
667
1226
|
let text = '';
|
|
668
1227
|
let error;
|
|
669
|
-
|
|
1228
|
+
// `scheduled` keeps the run from learning: the assignment's words are
|
|
1229
|
+
// the job's own prompt, and no memory should grow out of them.
|
|
1230
|
+
for await (const event of this.assign({
|
|
1231
|
+
agent: agent.id,
|
|
1232
|
+
// A recurring job is called the same thing every night, and that is
|
|
1233
|
+
// right: the schedule's name is the third source of a run's name.
|
|
1234
|
+
title: job.name,
|
|
1235
|
+
task: job.prompt,
|
|
1236
|
+
projectId: job.projectId,
|
|
1237
|
+
signal,
|
|
1238
|
+
scheduled: true,
|
|
1239
|
+
scheduleId: job.id,
|
|
1240
|
+
})) {
|
|
670
1241
|
if (event.type === 'assignment' && !assignmentId)
|
|
671
1242
|
assignmentId = event.assignment.id;
|
|
672
1243
|
else if (event.type === 'done')
|
|
@@ -676,18 +1247,60 @@ export class Assistant extends EventEmitter {
|
|
|
676
1247
|
}
|
|
677
1248
|
return error ? { status: 'failed', error, assignmentId } : { status: 'done', result: text, assignmentId };
|
|
678
1249
|
}
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
1250
|
+
// The board watcher checks before it thinks. Nothing on the board that
|
|
1251
|
+
// needs saying means no session, no provider process and no model call -
|
|
1252
|
+
// which is what the overwhelming majority of its firings are.
|
|
1253
|
+
const watching = job.id === boardWatchJobId(job.orgId);
|
|
1254
|
+
const attention = watching ? this.#boardAttention(job.orgId, job.id) : [];
|
|
1255
|
+
if (watching && !attention.length)
|
|
1256
|
+
return { status: 'done', result: '', silent: true };
|
|
1257
|
+
// `job.sessionId` here only ever means "pinned at creation" - a one-off
|
|
1258
|
+
// follow-up the user asked to land in a chat they already had open.
|
|
1259
|
+
// Nothing below writes it back after a run, so a recurring job gets a
|
|
1260
|
+
// clean, unlinked conversation every single firing.
|
|
1261
|
+
const existing = job.sessionId ? this.store.getSession(job.sessionId) : null;
|
|
1262
|
+
let sessionId;
|
|
1263
|
+
if (existing) {
|
|
1264
|
+
sessionId = existing.id;
|
|
1265
|
+
// The user may have archived the chat while this was pending; reusing
|
|
1266
|
+
// it silently would bury the reply where nobody looks for it.
|
|
1267
|
+
if (existing.archived)
|
|
1268
|
+
this.store.updateSession(existing.id, { archived: false });
|
|
1269
|
+
}
|
|
1270
|
+
else {
|
|
1271
|
+
sessionId = this.createSession({ title: 'Schedule: ' + job.name, kind: 'schedule', projectId: job.projectId }).id;
|
|
683
1272
|
}
|
|
684
|
-
|
|
685
|
-
const
|
|
1273
|
+
// Same clock, same zone, same wording as every other stamp a model reads.
|
|
1274
|
+
const when = formatNow();
|
|
1275
|
+
const prompt = 'Automatic run of schedule “' + job.name + '” (' +
|
|
1276
|
+
(job.schedule ? describeCron(job.schedule) : 'fired by an event') + '), ' + when + '. ' +
|
|
686
1277
|
'Nobody is following live: carry out the assignment now and finish with a short report ' +
|
|
687
|
-
'for the user to read later
|
|
1278
|
+
'for the user to read later. If carrying it out already delivers the result to the user by ' +
|
|
1279
|
+
'itself (for example you send_mail them the thing this job exists to send), that mail is the ' +
|
|
1280
|
+
'delivery - reply with exactly [SILENT] and nothing else, so a second "schedule completed" ' +
|
|
1281
|
+
'notification is not posted on top of it.\n\n' + job.prompt +
|
|
1282
|
+
// The watcher arrives knowing what it was woken for, so the turn is
|
|
1283
|
+
// about judging those findings rather than going to look for them.
|
|
1284
|
+
// Everything here is new since its last report by construction.
|
|
1285
|
+
(attention.length
|
|
1286
|
+
? '\n\nThe board was checked before this run. These are new since you last reported, ' +
|
|
1287
|
+
'and they are the whole reason you were woken:\n- ' + attention.join('\n- ')
|
|
1288
|
+
: '');
|
|
688
1289
|
let text = '';
|
|
689
1290
|
let error;
|
|
690
|
-
for await (const event of this.chat({
|
|
1291
|
+
for await (const event of this.chat({
|
|
1292
|
+
text: prompt,
|
|
1293
|
+
sessionId,
|
|
1294
|
+
projectId: job.projectId,
|
|
1295
|
+
permission: job.permission,
|
|
1296
|
+
signal,
|
|
1297
|
+
scheduled: true,
|
|
1298
|
+
// The board watcher is the one schedule that gets a cut-down toolset:
|
|
1299
|
+
// it looks and it mails, it does not act. Keyed off the job's fixed id
|
|
1300
|
+
// so a user-made job that merely happens to be named "Board watch" is
|
|
1301
|
+
// an ordinary assistant schedule with ordinary reach.
|
|
1302
|
+
watching,
|
|
1303
|
+
})) {
|
|
691
1304
|
if (event.type === 'done')
|
|
692
1305
|
text = event.text;
|
|
693
1306
|
else if (event.type === 'error' && event.fatal)
|
|
@@ -695,11 +1308,474 @@ export class Assistant extends EventEmitter {
|
|
|
695
1308
|
}
|
|
696
1309
|
if (error && !text)
|
|
697
1310
|
return { status: 'failed', error, sessionId };
|
|
698
|
-
|
|
1311
|
+
// An exact-match check on the whole reply is too brittle: the model
|
|
1312
|
+
// sometimes reasons out loud first and tacks the sentinel on as its
|
|
1313
|
+
// last line instead of replying with only it, which used to defeat the
|
|
1314
|
+
// match and let the explanation (sentinel and all) straight into the
|
|
1315
|
+
// inbox mail. Matching it as a trailing token - not anywhere in the
|
|
1316
|
+
// text - still catches that case without firing on a report that
|
|
1317
|
+
// merely quotes or explains the convention somewhere in its middle.
|
|
1318
|
+
if (/\[SILENT\]\s*$/.test(text))
|
|
699
1319
|
return { status: 'done', result: '', silent: true, sessionId };
|
|
700
1320
|
return { status: 'done', result: text, sessionId };
|
|
701
1321
|
}
|
|
1322
|
+
/**
|
|
1323
|
+
* One assistant turn for a mail addressed to it, answered by mail.
|
|
1324
|
+
* Same shape as a scheduled run: its own conversation, nobody watching
|
|
1325
|
+
* live, the answer read later - except the answer goes back as a reply.
|
|
1326
|
+
*/
|
|
1327
|
+
async #answerMail(mail, senderLabel, thread) {
|
|
1328
|
+
// `kind: 'mail'` keeps this out of the conversations list: it is the
|
|
1329
|
+
// transcript of one answered mail, not a thread anyone continues.
|
|
1330
|
+
const session = this.createSession({ title: 'Mail: ' + mail.subject, kind: 'mail' });
|
|
1331
|
+
// Subjects only: the thread can be long, and most mail is answerable
|
|
1332
|
+
// without it. `read_mail_thread` fetches the text if this one is not.
|
|
1333
|
+
const history = thread.length
|
|
1334
|
+
? 'Earlier in this thread (' + thread.length + ' mail(s)), subjects only:\n' +
|
|
1335
|
+
thread.map((entry) => '- ' + entry.subject).join('\n') +
|
|
1336
|
+
'\nRead the full text with read_mail_thread("' + mail.threadId + '") if the answer depends on it.\n\n'
|
|
1337
|
+
: '';
|
|
1338
|
+
const prompt = 'Mail ' + mail.id + ' arrived for you from ' + senderLabel + '. Nobody is following this ' +
|
|
1339
|
+
'conversation live: answer it now, and write the answer as the body of your reply mail - no ' +
|
|
1340
|
+
'chat pleasantries, no report framing. It is sent back to them as a reply automatically. Do ' +
|
|
1341
|
+
'not send_mail the answer to them as well: this text is the reply, and doing both delivers ' +
|
|
1342
|
+
'it twice. send_mail here is only for bringing somebody else in.\n\n' +
|
|
1343
|
+
history + 'Subject: ' + mail.subject + '\n\n' + mail.body;
|
|
1344
|
+
let text = '';
|
|
1345
|
+
for await (const event of this.chat({ text: prompt, sessionId: session.id })) {
|
|
1346
|
+
if (event.type === 'done')
|
|
1347
|
+
text = event.text;
|
|
1348
|
+
else if (event.type === 'error' && event.fatal)
|
|
1349
|
+
throw new Error(event.message);
|
|
1350
|
+
}
|
|
1351
|
+
return text;
|
|
1352
|
+
}
|
|
702
1353
|
/* ---------------------------- internals --------------------------- */
|
|
1354
|
+
/**
|
|
1355
|
+
* Whether this turn is framed for the dream. All conditions must hold
|
|
1356
|
+
* (R18): the dream and the recorder are switched on, the owner is the
|
|
1357
|
+
* assistant - stage 1 records nothing but the assistant's own bank, an
|
|
1358
|
+
* agent frame would be cost without a night that ever scores it - and the
|
|
1359
|
+
* session is a real conversation. A `schedule` run walks this same code
|
|
1360
|
+
* but can never earn a correction label, because `sessionsActiveSince`
|
|
1361
|
+
* filters its kind out; framing it would be pure cost. The sample itself
|
|
1362
|
+
* is drawn per session, never per trace, and `frameRate` is clamped here
|
|
1363
|
+
* because `rookery config set` bypasses the patch schema (E21).
|
|
1364
|
+
*/
|
|
1365
|
+
#dreamRecords(session, owner) {
|
|
1366
|
+
const dream = this.config.memory.dream;
|
|
1367
|
+
if (!dream.enabled || !dream.record)
|
|
1368
|
+
return false;
|
|
1369
|
+
if (owner !== ASSISTANT_MEMORY_OWNER)
|
|
1370
|
+
return false;
|
|
1371
|
+
if (session.kind !== 'chat' && session.kind !== 'voice' && session.kind !== 'mail')
|
|
1372
|
+
return false;
|
|
1373
|
+
return dreamSampleDraw(session.id) < clampNumber(dream.frameRate, 0, 1);
|
|
1374
|
+
}
|
|
1375
|
+
/**
|
|
1376
|
+
* Index a finished turn as a trial episode (concept 7.2, Phase 6).
|
|
1377
|
+
*
|
|
1378
|
+
* `dream.trialEpisodes` gets its reader here rather than in the night,
|
|
1379
|
+
* for the plain reason that the night cannot reach the turn journal: the
|
|
1380
|
+
* episode is an INDEX over `turn_events`, and only the process that just
|
|
1381
|
+
* wrote those rows knows the turn is over. Zero by default, so this is a
|
|
1382
|
+
* single config read and a return on every turn Rookery has ever run.
|
|
1383
|
+
*
|
|
1384
|
+
* The key is a quota, not a switch: `trialEpisodes` many episodes per
|
|
1385
|
+
* bank, then nothing. Phase 6 is a sample to validate a mechanism on, not
|
|
1386
|
+
* a recorder to leave running - and a trial that never stops would keep
|
|
1387
|
+
* pointing at verbatim journal rows long after anybody looked at it.
|
|
1388
|
+
*
|
|
1389
|
+
* Nothing in here may cost the turn. The turn is finished and answered by
|
|
1390
|
+
* the time this runs; a store that refuses the write costs the episode
|
|
1391
|
+
* and a debug line (10.5).
|
|
1392
|
+
*/
|
|
1393
|
+
#recordTrialEpisode(turnId, journal, startedAt) {
|
|
1394
|
+
const trial = Math.round(clampNumber(this.config.memory.dream.trialEpisodes, 0, 1000));
|
|
1395
|
+
if (trial <= 0)
|
|
1396
|
+
return;
|
|
1397
|
+
const owner = ASSISTANT_MEMORY_OWNER;
|
|
1398
|
+
try {
|
|
1399
|
+
// Read with the quota as the limit: the question is "are there already
|
|
1400
|
+
// enough", never "how many are there".
|
|
1401
|
+
if (this.store.dreamEpisodes(owner, { limit: trial }).length >= trial)
|
|
1402
|
+
return;
|
|
1403
|
+
const sessionId = journal.sessionId;
|
|
1404
|
+
// The same session-wise split the recorder stamps on a trace (E3): a
|
|
1405
|
+
// turn outside any conversation is its own cluster.
|
|
1406
|
+
const split = splitOf(sessionId ?? turnId, DEFAULT_SPLIT_RATES);
|
|
1407
|
+
const { episode } = episodeFromEvents(turnId, this.store.turns.events(turnId), {
|
|
1408
|
+
owner,
|
|
1409
|
+
kind: 'turn',
|
|
1410
|
+
slot: 'recall',
|
|
1411
|
+
...(sessionId ? { sessionId } : {}),
|
|
1412
|
+
startedAt,
|
|
1413
|
+
finishedAt: Date.now(),
|
|
1414
|
+
holdout: split === 'holdout',
|
|
1415
|
+
audit: split === 'audit',
|
|
1416
|
+
});
|
|
1417
|
+
this.store.recordDreamEpisode(episode);
|
|
1418
|
+
}
|
|
1419
|
+
catch (error) {
|
|
1420
|
+
this.log.debug('Trial episode not recorded', { turnId, error: error.message });
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
/**
|
|
1424
|
+
* A retrieval policy went in force, so the user hears about it (S26,
|
|
1425
|
+
* concept 9.6). This is the one place that can say so: the night owns the
|
|
1426
|
+
* promotion and knows nothing about mail, the controller owns the mail and
|
|
1427
|
+
* knows nothing about the night, and the runtime holds both.
|
|
1428
|
+
*
|
|
1429
|
+
* Everything quoted is a number, an id or the promotion's own stored
|
|
1430
|
+
* rationale, which carries no verbatim text by construction (E19/S21), so
|
|
1431
|
+
* the message can outlive the memories the evaluation stood on.
|
|
1432
|
+
*
|
|
1433
|
+
* A failing send costs the message, never the night: `#announcePromotion`
|
|
1434
|
+
* in sleep.ts catches whatever comes back out of here, and this catches
|
|
1435
|
+
* first so the warning names the mail rather than the hook.
|
|
1436
|
+
*/
|
|
1437
|
+
async #announcePromotion(notice) {
|
|
1438
|
+
const version = notice.version;
|
|
1439
|
+
const evaluation = notice.evaluation;
|
|
1440
|
+
const body = [
|
|
1441
|
+
'A new ' + notice.slot + ' policy is in force for ' + notice.owner +
|
|
1442
|
+
' (version ' + version.version + ').',
|
|
1443
|
+
'',
|
|
1444
|
+
notice.rationale,
|
|
1445
|
+
'',
|
|
1446
|
+
'delta ' + evaluation.delta.toFixed(4) +
|
|
1447
|
+
', ci_low ' + evaluation.ciLow.toFixed(4) +
|
|
1448
|
+
', over ' + evaluation.closed + ' of ' + evaluation.traces + ' traces' +
|
|
1449
|
+
(evaluation.auditCiLow === undefined
|
|
1450
|
+
? ''
|
|
1451
|
+
: ', audit ci_low ' + evaluation.auditCiLow.toFixed(4)) +
|
|
1452
|
+
'.',
|
|
1453
|
+
'No further promotion of this slot before ' + new Date(notice.cooldownUntil).toISOString() + '.',
|
|
1454
|
+
'',
|
|
1455
|
+
'Take it back on its own: POST /api/dream/policies/' + version.id + '/revert' +
|
|
1456
|
+
(notice.prevActiveId ? ' (restores version ' + notice.prevActiveId + ').' : '.'),
|
|
1457
|
+
'Take the whole night back: undo sleep run ' + notice.runId + '.',
|
|
1458
|
+
].join('\n');
|
|
1459
|
+
try {
|
|
1460
|
+
await this.org.sendUserMail({
|
|
1461
|
+
orgId: this.org.activeOrganization().id,
|
|
1462
|
+
to: ['user'],
|
|
1463
|
+
subject: 'Retrieval policy ' + notice.slot + ' v' + version.version + ' is in force',
|
|
1464
|
+
body,
|
|
1465
|
+
});
|
|
1466
|
+
}
|
|
1467
|
+
catch (error) {
|
|
1468
|
+
this.log.warn('Could not mail the promotion notice', {
|
|
1469
|
+
owner: notice.owner,
|
|
1470
|
+
slot: notice.slot,
|
|
1471
|
+
policy: version.id,
|
|
1472
|
+
error: error.message,
|
|
1473
|
+
});
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
/**
|
|
1477
|
+
* The turn's merged memory list: the ranking plus the profile, pairs that
|
|
1478
|
+
* cannot both be true reduced to the newer sentence, and the whole merge
|
|
1479
|
+
* totally ordered - score descending, id ascending (R11), so a tie can no
|
|
1480
|
+
* longer pick whichever row the Map happened to insert first. That order
|
|
1481
|
+
* is what the rendered block reads, and what the recorder freezes.
|
|
1482
|
+
*
|
|
1483
|
+
* A framed turn additionally records everything the night needs to replay
|
|
1484
|
+
* this decision: the trace, the touches the ranking causes, and the frame
|
|
1485
|
+
* at the permissive corner of the declared box. The live ranking inside
|
|
1486
|
+
* the bracket is byte for byte the ranking of an unframed turn - the
|
|
1487
|
+
* recorder may not change the turn it records - and everything it writes
|
|
1488
|
+
* sits in the store's SAVEPOINT bracket (R9), so a framed turn is one
|
|
1489
|
+
* transaction or nothing.
|
|
1490
|
+
*
|
|
1491
|
+
* `turnId` is the JOURNAL's id, handed down from `chat()` - not one minted
|
|
1492
|
+
* here. That is the whole of concept 9.4's "one turn id instead of three":
|
|
1493
|
+
* the trace, the message and the journal now say the same word, so a
|
|
1494
|
+
* correction quote found in `messages.turn_id` lands on exactly the trace
|
|
1495
|
+
* that produced the prompt it corrects. Minted separately, `locateTurn`
|
|
1496
|
+
* could never match one and every correction label fell back to session
|
|
1497
|
+
* scope - where, by S3, it can never contribute a gain.
|
|
1498
|
+
*/
|
|
1499
|
+
#turnMemories(session, owner, prompt, policy, turnId) {
|
|
1500
|
+
const options = {
|
|
1501
|
+
text: prompt,
|
|
1502
|
+
owner,
|
|
1503
|
+
limit: policy.limit,
|
|
1504
|
+
threshold: policy.threshold,
|
|
1505
|
+
hopEntity: policy.hopEntity,
|
|
1506
|
+
hopEdge: policy.hopEdge,
|
|
1507
|
+
};
|
|
1508
|
+
const promptProfileLimit = Math.max(3, Math.floor(policy.limit / 2));
|
|
1509
|
+
const merged = (matched, profile) => {
|
|
1510
|
+
const byId = new Map();
|
|
1511
|
+
for (const memory of profile)
|
|
1512
|
+
byId.set(memory.id, memory);
|
|
1513
|
+
for (const memory of matched)
|
|
1514
|
+
byId.set(memory.id, memory);
|
|
1515
|
+
// Of a contradicting pair only the newer sentence goes into the prompt;
|
|
1516
|
+
// the older one stays in the bank and stays visible in the inspector.
|
|
1517
|
+
return dropContradicted(this.store, [...byId.values()]).sort(byScoreThenId);
|
|
1518
|
+
};
|
|
1519
|
+
if (!this.#dreamRecords(session, owner)) {
|
|
1520
|
+
return merged(recall(this.store, options), coreProfile(this.store, { owner, limit: promptProfileLimit }));
|
|
1521
|
+
}
|
|
1522
|
+
const dream = this.config.memory.dream;
|
|
1523
|
+
const limitMax = Math.max(Math.round(clampNumber(dream.limitMax, 4, 16)), policy.limit);
|
|
1524
|
+
const maxFrameBytes = Math.round(clampNumber(dream.maxFrameBytes, 1000, 2_000_000));
|
|
1525
|
+
// Which half of the evidence this turn belongs to, stamped at record
|
|
1526
|
+
// time (E3). The unit is the SESSION, never the trace: two traces of one
|
|
1527
|
+
// session can never disagree, and the rates come from the one exported
|
|
1528
|
+
// constant the night reads back months later - if the recorder and the
|
|
1529
|
+
// evaluation ever picked their rates separately, a session would change
|
|
1530
|
+
// sides between the stamp and the measurement and the holdout would
|
|
1531
|
+
// quietly stop being one.
|
|
1532
|
+
const split = splitOf(session.id, DEFAULT_SPLIT_RATES);
|
|
1533
|
+
let memories = [];
|
|
1534
|
+
this.store.recordDreamTurn(() => {
|
|
1535
|
+
const trace = this.store.beginTrace({
|
|
1536
|
+
// One id per turn: every traced call of this turn carries it, and
|
|
1537
|
+
// labels attach to it rather than to any single call (R19).
|
|
1538
|
+
turnId,
|
|
1539
|
+
owner,
|
|
1540
|
+
kind: 'turn',
|
|
1541
|
+
site: 'turn',
|
|
1542
|
+
pipeline: 'assistant',
|
|
1543
|
+
sessionId: session.id,
|
|
1544
|
+
sessionKind: session.kind,
|
|
1545
|
+
// The position of this turn in its session: the messages stored
|
|
1546
|
+
// before it, which is the count the session carries at recall time.
|
|
1547
|
+
turnIndex: session.messageCount,
|
|
1548
|
+
policySet: { recall: policy },
|
|
1549
|
+
framed: true,
|
|
1550
|
+
holdout: split === 'holdout',
|
|
1551
|
+
audit: split === 'audit',
|
|
1552
|
+
});
|
|
1553
|
+
// The record, fetched before the ranking: the frame freezes
|
|
1554
|
+
// `access_count`, and the values worth freezing are the ones the live
|
|
1555
|
+
// scores are about to read - not the ones this turn's own touch will
|
|
1556
|
+
// write a moment later.
|
|
1557
|
+
const frame = fetchFrame(this.store, {
|
|
1558
|
+
...options,
|
|
1559
|
+
box: declaredDreamBox(policy, limitMax),
|
|
1560
|
+
site: 'turn',
|
|
1561
|
+
pipeline: 'assistant',
|
|
1562
|
+
budgetChars: Math.floor(this.config.memory.contextBudget * 0.4),
|
|
1563
|
+
subject: 'this user',
|
|
1564
|
+
// A meta read and nothing more; empty until the first night has
|
|
1565
|
+
// stamped a fingerprint, which certifies nothing yet (R10).
|
|
1566
|
+
corpusStampId: this.store.currentCorpusStamp(owner)?.id ?? '',
|
|
1567
|
+
});
|
|
1568
|
+
const matched = recall(this.store, { ...options, touchContext: { traceId: trace.id, owner } });
|
|
1569
|
+
// One profile read at the permissive corner of the box, sliced down
|
|
1570
|
+
// for the prompt: the SQL behind `coreProfile` is prefix-invariant
|
|
1571
|
+
// now that it tie-breaks on id, so the wider read costs one query and
|
|
1572
|
+
// changes no row the prompt sees (R12).
|
|
1573
|
+
const profile = coreProfile(this.store, {
|
|
1574
|
+
owner,
|
|
1575
|
+
limit: Math.max(promptProfileLimit, Math.max(3, Math.floor(limitMax / 2))),
|
|
1576
|
+
}).slice(0, promptProfileLimit);
|
|
1577
|
+
memories = merged(matched, profile);
|
|
1578
|
+
// A frame over the size cap is refused rather than thrown at: the
|
|
1579
|
+
// trace still closes, without a frame, and the night simply never
|
|
1580
|
+
// scores this turn.
|
|
1581
|
+
if (!this.store.saveFrame(trace.id, 'recall', frame, { maxFrameBytes })) {
|
|
1582
|
+
this.log.debug('Dream frame refused: over dream.maxFrameBytes', { sessionId: session.id, turnId });
|
|
1583
|
+
}
|
|
1584
|
+
this.store.finishTrace(trace.id, { degraded: frame.degraded });
|
|
1585
|
+
});
|
|
1586
|
+
return memories;
|
|
1587
|
+
}
|
|
1588
|
+
/* ------------------------- conversation terminal ------------------------ */
|
|
1589
|
+
/**
|
|
1590
|
+
* Carries a conversation on in Claude Code's own terminal instead of the
|
|
1591
|
+
* chat: the full TUI, typed into directly, on the same provider session a
|
|
1592
|
+
* chat turn resumes - so switching back and forth loses nothing. Claude
|
|
1593
|
+
* Code keeps its own context across the switch; Rookery keeps the
|
|
1594
|
+
* conversation's history by storing every exchange the terminal reports.
|
|
1595
|
+
*
|
|
1596
|
+
* What a chat turn rebuilds every time is built once here: the system
|
|
1597
|
+
* prompt, the company block, the tool servers. A terminal has one prompt
|
|
1598
|
+
* for its whole life, so the per-turn memory recall is the one thing it
|
|
1599
|
+
* goes without - the memories still come back on the next chat turn.
|
|
1600
|
+
*
|
|
1601
|
+
* Returns at once if the conversation already has an open terminal.
|
|
1602
|
+
*/
|
|
1603
|
+
async openConversationTerminal(input) {
|
|
1604
|
+
const session = this.#resolveSession({
|
|
1605
|
+
text: '',
|
|
1606
|
+
...(input.sessionId ? { sessionId: input.sessionId } : {}),
|
|
1607
|
+
...(input.provider ? { provider: input.provider } : {}),
|
|
1608
|
+
...(input.model ? { model: input.model } : {}),
|
|
1609
|
+
...(input.projectId ? { projectId: input.projectId } : {}),
|
|
1610
|
+
});
|
|
1611
|
+
const key = conversationTerminalKey(session.id);
|
|
1612
|
+
if (tuiSessions.info(key))
|
|
1613
|
+
return { sessionId: session.id, key };
|
|
1614
|
+
if (input.projectId && input.projectId !== session.projectId) {
|
|
1615
|
+
this.store.updateSession(session.id, { projectId: input.projectId });
|
|
1616
|
+
session.projectId = input.projectId;
|
|
1617
|
+
}
|
|
1618
|
+
const wanted = input.provider ?? session.provider;
|
|
1619
|
+
const providerId = await this.providers.resolveUsable(wanted);
|
|
1620
|
+
if (!providerId)
|
|
1621
|
+
throw new Error('No AI provider is ready.');
|
|
1622
|
+
// Always the plain Claude Code adapter: the gateway, not a profile's
|
|
1623
|
+
// environment, decides where each model goes.
|
|
1624
|
+
const provider = this.providers.get('claude');
|
|
1625
|
+
if (!provider.openTerminal)
|
|
1626
|
+
throw new Error(provider.displayName + ' has no terminal of its own.');
|
|
1627
|
+
// Every model Rookery can reach, for the gateway's routing and the TUI's
|
|
1628
|
+
// `/model` menu - Claude's own entries are already in that menu.
|
|
1629
|
+
const picker = [];
|
|
1630
|
+
const direct = [];
|
|
1631
|
+
for (const status of await this.providers.statuses()) {
|
|
1632
|
+
if (status.id === 'claude' || !status.available || !status.authenticated)
|
|
1633
|
+
continue;
|
|
1634
|
+
const profile = this.providers.profiles().find((entry) => entry.id === status.id);
|
|
1635
|
+
// The gateway speaks to ChatGPT and to Anthropic-compatible endpoints;
|
|
1636
|
+
// a router-backed profile stays reachable from the chat only.
|
|
1637
|
+
if (status.id !== 'codex' && profile?.via !== 'direct')
|
|
1638
|
+
continue;
|
|
1639
|
+
const models = await this.providers.models(status.id).catch(() => []);
|
|
1640
|
+
if (profile)
|
|
1641
|
+
direct.push({ profile, models: models.map((entry) => entry.id) });
|
|
1642
|
+
for (const entry of models) {
|
|
1643
|
+
picker.push({ model: entry.id, label: entry.name || entry.id, description: status.displayName });
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
this.#gatewayProfiles = direct;
|
|
1647
|
+
this.#gateway ??= new ModelGateway({ profiles: () => this.#gatewayProfiles });
|
|
1648
|
+
const gateway = await this.#gateway.start();
|
|
1649
|
+
const ownerOf = (name) => {
|
|
1650
|
+
const route = this.#gateway?.route(name) ?? { kind: 'anthropic' };
|
|
1651
|
+
return route.kind === 'codex' ? 'codex' : route.kind === 'profile' ? route.profile.id : 'claude';
|
|
1652
|
+
};
|
|
1653
|
+
// One gateway serves every model, so the session resumes whichever
|
|
1654
|
+
// provider it last ran on - Claude Code's transcript is the same format.
|
|
1655
|
+
const resumed = Boolean(session.providerSessionId);
|
|
1656
|
+
const requested = input.model ?? session.model ?? this.config.defaultModel;
|
|
1657
|
+
// A name another provider owns (the chat's `sonnet` on a GPT terminal)
|
|
1658
|
+
// becomes that provider's own default instead of silently going to Claude.
|
|
1659
|
+
const model = requested && ownerOf(requested) === providerId ? requested : remapModel(providerId, requested);
|
|
1660
|
+
const organization = this.org.activeOrganization();
|
|
1661
|
+
const snapshot = this.org.snapshot(organization.id);
|
|
1662
|
+
const project = session.projectId ? (this.store.org.getProject(session.projectId) ?? undefined) : undefined;
|
|
1663
|
+
const who = 'assistant';
|
|
1664
|
+
const extra = toolServersFor(this.config, who, providerId, project?.id);
|
|
1665
|
+
const ownSkills = this.skills.for(who);
|
|
1666
|
+
const systemPrompt = buildSystemPrompt({
|
|
1667
|
+
config: this.config,
|
|
1668
|
+
query: '',
|
|
1669
|
+
memories: [],
|
|
1670
|
+
history: resumed ? [] : this.store.getMessages(session.id, this.config.memory.workingWindow),
|
|
1671
|
+
resumed,
|
|
1672
|
+
voice: false,
|
|
1673
|
+
orgBlock: assistantOrgBlock(this.config, snapshot, [], project, this.cron.list(organization.id), this.store),
|
|
1674
|
+
toolHints: [...extra.hints, dormantToolsHint(this.config, who, project?.id)].filter(Boolean),
|
|
1675
|
+
skillsIndex: [renderSkillsIndex(ownSkills), renderExternalSkillsHint(this.config, who)].filter(Boolean).join('\n\n'),
|
|
1676
|
+
store: this.store,
|
|
1677
|
+
});
|
|
1678
|
+
// The token lives as long as the terminal: the MCP bridge answers the
|
|
1679
|
+
// assistant's own tools for exactly that long.
|
|
1680
|
+
const token = this.org.register({
|
|
1681
|
+
orgId: organization.id,
|
|
1682
|
+
audience: 'assistant',
|
|
1683
|
+
agentId: undefined,
|
|
1684
|
+
sessionId: session.id,
|
|
1685
|
+
projectId: session.projectId,
|
|
1686
|
+
depth: -1,
|
|
1687
|
+
scheduled: false,
|
|
1688
|
+
watching: false,
|
|
1689
|
+
emit: () => undefined,
|
|
1690
|
+
signal: undefined,
|
|
1691
|
+
});
|
|
1692
|
+
const release = () => {
|
|
1693
|
+
this.org.unregister(token);
|
|
1694
|
+
this.questions.cancelForOwner(token);
|
|
1695
|
+
};
|
|
1696
|
+
try {
|
|
1697
|
+
const mcp = await this.org.bridge.spec(token);
|
|
1698
|
+
const opened = await provider.openTerminal({
|
|
1699
|
+
prompt: '',
|
|
1700
|
+
systemPrompt,
|
|
1701
|
+
systemPromptMode: 'replace',
|
|
1702
|
+
...(resumed && session.providerSessionId ? { providerSessionId: session.providerSessionId } : {}),
|
|
1703
|
+
...(model ? { model } : {}),
|
|
1704
|
+
effort: input.effort ?? this.config.defaultEffort,
|
|
1705
|
+
cwd: this.config.workspace,
|
|
1706
|
+
permission: input.permission ?? this.config.defaultPermission,
|
|
1707
|
+
mcp,
|
|
1708
|
+
...(extra.specs.length ? { mcpExtra: extra.specs } : {}),
|
|
1709
|
+
...externalTurnExtras(this.config, who),
|
|
1710
|
+
gateway: { ...gateway, picker },
|
|
1711
|
+
tui: { key },
|
|
1712
|
+
}, {
|
|
1713
|
+
onTurn: (turn) => {
|
|
1714
|
+
if (turn.prompt)
|
|
1715
|
+
this.store.addMessage({ sessionId: session.id, role: 'user', content: turn.prompt });
|
|
1716
|
+
// Stored the way a chat turn stores itself: the tool calls, and
|
|
1717
|
+
// the ordered transcript the thread renders them from - or the
|
|
1718
|
+
// chat would show a terminal turn as bare text.
|
|
1719
|
+
const toolCalls = [];
|
|
1720
|
+
const turnBlocks = new TurnBlocks();
|
|
1721
|
+
for (const event of turn.events) {
|
|
1722
|
+
if (event.type === 'tool')
|
|
1723
|
+
toolCalls.push(event);
|
|
1724
|
+
turnBlocks.apply(event);
|
|
1725
|
+
}
|
|
1726
|
+
turnBlocks.reconcile(turn.answer);
|
|
1727
|
+
// Whoever actually answered: `/model` in the terminal may have
|
|
1728
|
+
// moved the conversation to another provider since it opened.
|
|
1729
|
+
const answeredBy = turn.model ?? model;
|
|
1730
|
+
const answeredOn = ownerOf(answeredBy);
|
|
1731
|
+
this.store.addMessage({
|
|
1732
|
+
sessionId: session.id,
|
|
1733
|
+
role: 'assistant',
|
|
1734
|
+
content: turn.answer,
|
|
1735
|
+
provider: answeredOn,
|
|
1736
|
+
...(answeredBy ? { model: answeredBy } : {}),
|
|
1737
|
+
usage: turn.usage,
|
|
1738
|
+
toolCalls,
|
|
1739
|
+
...(turnBlocks.blocks.length ? { blocks: turnBlocks.blocks } : {}),
|
|
1740
|
+
});
|
|
1741
|
+
const current = this.store.getSession(session.id);
|
|
1742
|
+
if (current && current.title === 'New conversation' && turn.prompt) {
|
|
1743
|
+
this.store.updateSession(session.id, { title: deriveTitle(turn.prompt) });
|
|
1744
|
+
}
|
|
1745
|
+
this.store.updateSession(session.id, {
|
|
1746
|
+
provider: answeredOn,
|
|
1747
|
+
...(answeredBy ? { model: answeredBy } : {}),
|
|
1748
|
+
providerSessionId: turn.providerSessionId,
|
|
1749
|
+
});
|
|
1750
|
+
this.emit('changed', { kind: 'session', id: session.id });
|
|
1751
|
+
if (this.config.memory.enabled && this.config.memory.autoExtract && turn.prompt) {
|
|
1752
|
+
void this.#learn(session.id, turn.prompt, turn.answer, answeredOn, ASSISTANT_MEMORY_OWNER);
|
|
1753
|
+
}
|
|
1754
|
+
},
|
|
1755
|
+
onExit: () => {
|
|
1756
|
+
release();
|
|
1757
|
+
this.emit('changed', { kind: 'session', id: session.id });
|
|
1758
|
+
},
|
|
1759
|
+
});
|
|
1760
|
+
// Stored at once, so switching back to chat resumes this very session
|
|
1761
|
+
// even if nothing was said in the terminal yet.
|
|
1762
|
+
this.store.updateSession(session.id, { provider: providerId, model, providerSessionId: opened.providerSessionId });
|
|
1763
|
+
}
|
|
1764
|
+
catch (error) {
|
|
1765
|
+
release();
|
|
1766
|
+
throw error;
|
|
1767
|
+
}
|
|
1768
|
+
this.emit('changed', { kind: 'session', id: session.id });
|
|
1769
|
+
return { sessionId: session.id, key };
|
|
1770
|
+
}
|
|
1771
|
+
/** The model gateway conversation terminals share, started with the first one. */
|
|
1772
|
+
#gateway;
|
|
1773
|
+
/** The directly reachable profiles and their models, refreshed with every terminal. */
|
|
1774
|
+
#gatewayProfiles = [];
|
|
1775
|
+
/** Back to chat: ends the conversation's terminal. False when it had none. */
|
|
1776
|
+
closeConversationTerminal(sessionId) {
|
|
1777
|
+
return tuiSessions.kill(conversationTerminalKey(sessionId));
|
|
1778
|
+
}
|
|
703
1779
|
#resolveSession(input) {
|
|
704
1780
|
if (input.sessionId) {
|
|
705
1781
|
const existing = this.store.getSession(input.sessionId);
|
|
@@ -736,6 +1812,11 @@ export class Assistant extends EventEmitter {
|
|
|
736
1812
|
candidates,
|
|
737
1813
|
owner,
|
|
738
1814
|
config: this.config.memory,
|
|
1815
|
+
// The user's own message, and nothing else. The assistant's answer
|
|
1816
|
+
// goes to the extractor so it can tell what the exchange was about,
|
|
1817
|
+
// but a fact the assistant produced is not a fact the user confirmed,
|
|
1818
|
+
// and only the user's words may stand behind a memory about the user.
|
|
1819
|
+
sources: [userText],
|
|
739
1820
|
sourceSessionId: sessionId,
|
|
740
1821
|
});
|
|
741
1822
|
if (admitted.rejected.length) {
|
|
@@ -761,6 +1842,12 @@ function labelForOwner(assistant, owner) {
|
|
|
761
1842
|
/**
|
|
762
1843
|
* The memories the extractor needs to see so it does not write them again:
|
|
763
1844
|
* whatever this exchange actually touches, plus the small core profile.
|
|
1845
|
+
*
|
|
1846
|
+
* Deliberately untraced: this is the `site: 'extract'` population of the
|
|
1847
|
+
* dream's vocabulary - `touch: false`, `expand: false`, a wider limit and a
|
|
1848
|
+
* lower threshold than any conversational turn. Stage 1 scores only
|
|
1849
|
+
* `site = 'turn'`, so the recorder does not sit here; wiring it in would
|
|
1850
|
+
* fill the night's pool with calls no label can ever attach to.
|
|
764
1851
|
*/
|
|
765
1852
|
function relevantKnown(store, owner, text) {
|
|
766
1853
|
const matched = recall(store, { text, owner, limit: 20, threshold: 0.05, touch: false, expand: false });
|