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
|
@@ -0,0 +1,1032 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { DEFAULT_CONFIG } from '../../config.js';
|
|
3
|
+
import { REVIEW_TARGET, cohensKappa, costOnlyShare, gainFrom, labelCoverage, pairedRatings, pairwiseAgreement, } from './label.js';
|
|
4
|
+
import { measure } from './measure.js';
|
|
5
|
+
import { bootstrapCi, corpusDrifted, freshnessCheck } from './probe.js';
|
|
6
|
+
import { pipelineAgent, pipelineAssistant } from './score.js';
|
|
7
|
+
/**
|
|
8
|
+
* The evaluation machinery (dream stage 2, AP8; concept 5.3, 5.4, 5.5, 4.4).
|
|
9
|
+
*
|
|
10
|
+
* This module answers one question and refuses to answer a second one: given
|
|
11
|
+
* a recorded pool of frames, a baseline arm and a candidate arm, how much
|
|
12
|
+
* better did the candidate rank the block the model actually read - and is
|
|
13
|
+
* that number worth anything at all? The first half is `evaluateCandidate`,
|
|
14
|
+
* the second half is the validity certificate it carries with it. Whether
|
|
15
|
+
* the candidate is then PROMOTED is not decided here; that is AP9's gate,
|
|
16
|
+
* and keeping the two apart is what makes "the evaluation is invalid"
|
|
17
|
+
* distinguishable from "the candidate lost" (concept 5.4, rule 3).
|
|
18
|
+
*
|
|
19
|
+
* Three contracts hold everywhere in this file:
|
|
20
|
+
*
|
|
21
|
+
* - **It never writes.** It reads frames, traces and labels through the
|
|
22
|
+
* store's read paths and nothing else. `fetchFrame` (through
|
|
23
|
+
* `freshnessCheck`) has no touch path at all and `measure` is pure, so
|
|
24
|
+
* `touch: false` is not a flag anyone could flip - it is the absence of a
|
|
25
|
+
* write path (S30). The test that pins this compares `access_count` and
|
|
26
|
+
* `usefulness` of every row before and after a full evaluation, because a
|
|
27
|
+
* sensor that feeds the feedback loop it watches is worse than no sensor.
|
|
28
|
+
* The night's corpus fingerprint is a meta WRITE (`store.corpusFingerprint`)
|
|
29
|
+
* and is therefore never called here: the caller hands its stamp in.
|
|
30
|
+
* - **It never throws.** The night has no throw site in the dream block; an
|
|
31
|
+
* internal failure is reported into the result and the night carries on.
|
|
32
|
+
* - **It reads no further than the owner it was given.** A frame of another
|
|
33
|
+
* bank that reached the pool through a join is dropped and counted, never
|
|
34
|
+
* scored (concept 10.5).
|
|
35
|
+
*
|
|
36
|
+
* The four pieces, in the order the night uses them:
|
|
37
|
+
*
|
|
38
|
+
* 1. `splitOf` - the train/holdout/audit split, deterministic, SESSION-wise
|
|
39
|
+
* and free of any store, because AP14's recorder stamps a trace with the
|
|
40
|
+
* very same function (E3).
|
|
41
|
+
* 2. `evaluateCandidate` - paired per trace on the INTERSECTION of both
|
|
42
|
+
* closed sets, cluster-bootstrapped over sessions, with the abstention
|
|
43
|
+
* histogram, the coverage rates and the five validity rules.
|
|
44
|
+
* 3. `selectOnTraining` - the ranking runs on the training half; exactly
|
|
45
|
+
* one candidate goes on to the holdout (E4/S12), and the frozen audit
|
|
46
|
+
* set is touched exactly once per promotion (S13).
|
|
47
|
+
* 4. `agreementReport` - the label agreement sensor (5.5b), with `user`
|
|
48
|
+
* privileged. Thin `user` labels are the finding, not a zero.
|
|
49
|
+
*
|
|
50
|
+
* > Der Schaetzer ist eine untere Schranke, kein Punktschaetzer (E8). Jede
|
|
51
|
+
* > Bewertung berichtet ihre Abdeckungsrate, und ein Delta, das ueberwiegend
|
|
52
|
+
* > aus unetikettierten Positionen stammt, ist ungueltig.
|
|
53
|
+
*/
|
|
54
|
+
/* ------------------------------- constants ------------------------------- */
|
|
55
|
+
/**
|
|
56
|
+
* Salt for the split draw. Deliberately NOT the recorder's sampling salt
|
|
57
|
+
* (`runtime.ts`): the sample decides whether a session is framed at all, the
|
|
58
|
+
* split decides which half it lands in, and one hash serving both would make
|
|
59
|
+
* every framed session fall on the same side of the split.
|
|
60
|
+
*/
|
|
61
|
+
const SPLIT_SALT = 'rookery.dream.split.v1';
|
|
62
|
+
/**
|
|
63
|
+
* Split rates. Guessed, like every other bare number in the concept: three
|
|
64
|
+
* in ten sessions held back for the one holdout check, one in ten frozen
|
|
65
|
+
* into the audit set that never selects and never serves as a holdout
|
|
66
|
+
* (concept 5.5d). They are parameters everywhere they are used.
|
|
67
|
+
*/
|
|
68
|
+
const DEFAULT_HOLDOUT_RATE = 0.3;
|
|
69
|
+
const DEFAULT_AUDIT_RATE = 0.1;
|
|
70
|
+
/**
|
|
71
|
+
* The one place those two rates live. The recorder stamps a trace with
|
|
72
|
+
* `splitOf` at turn time and the night reads the stamp back months later: if
|
|
73
|
+
* the two sides ever picked their rates separately, a session could change
|
|
74
|
+
* sides between the stamp and the evaluation, and the holdout would quietly
|
|
75
|
+
* stop being one.
|
|
76
|
+
*/
|
|
77
|
+
export const DEFAULT_SPLIT_RATES = {
|
|
78
|
+
holdoutRate: DEFAULT_HOLDOUT_RATE,
|
|
79
|
+
auditRate: DEFAULT_AUDIT_RATE,
|
|
80
|
+
};
|
|
81
|
+
/** Mirrors the writer in store.ts; read-only here (see the module doc). */
|
|
82
|
+
const CORPUS_STAMP_PREFIX = 'dream.corpus_stamp.';
|
|
83
|
+
/** SQLite takes at most 999 bound parameters; labels are read in batches. */
|
|
84
|
+
const TURN_BATCH = 200;
|
|
85
|
+
/** No single frame may eat the shared wall clock on its own (like probe.ts). */
|
|
86
|
+
const FRAME_TIME_LIMIT_MS = 2000;
|
|
87
|
+
/** Decimals the evidence digest prints a share or a delta with. */
|
|
88
|
+
const DIGEST_DIGITS = 4;
|
|
89
|
+
/** Every reason a frame can go unscored, zeroed - counted, never swallowed. */
|
|
90
|
+
const ABSTAIN_REASONS = [
|
|
91
|
+
'limit-out-of-box',
|
|
92
|
+
'seeds-capped',
|
|
93
|
+
'degraded-turn',
|
|
94
|
+
'frame-missing',
|
|
95
|
+
'corpus-drifted',
|
|
96
|
+
'corpus-invalidated',
|
|
97
|
+
'budget-changed',
|
|
98
|
+
'no-reachable-label',
|
|
99
|
+
'no-labelled-move',
|
|
100
|
+
'pipeline-mismatch',
|
|
101
|
+
'no-label-source',
|
|
102
|
+
'unfinished',
|
|
103
|
+
];
|
|
104
|
+
const LABEL_SOURCES = ['correction', 'review', 'merge', 'user'];
|
|
105
|
+
/**
|
|
106
|
+
* The sources the retrieval policy has a causal path to: a correction is
|
|
107
|
+
* written about what the incumbent surfaced, a merge about what the night
|
|
108
|
+
* condensed, a review about an assignment the same policy fed. `user` is the
|
|
109
|
+
* one source outside that loop, which is why it is privileged (concept 4.2b).
|
|
110
|
+
*/
|
|
111
|
+
const INFLUENCEABLE = ['correction', 'merge', 'review'];
|
|
112
|
+
/** How many common targets `user` needs before an agreement means anything. */
|
|
113
|
+
const MIN_USER_PAIRS = 10;
|
|
114
|
+
function clampRate(value) {
|
|
115
|
+
if (!Number.isFinite(value))
|
|
116
|
+
return 0;
|
|
117
|
+
return Math.min(1, Math.max(0, value));
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* The split draw of one session as a number in [0, 1): FNV-1a over the
|
|
121
|
+
* session id and the split salt. Cheap, stable and portable - it only has to
|
|
122
|
+
* be deterministic, never cryptographic, and it must survive a restart,
|
|
123
|
+
* because a session that changed sides between two nights would put
|
|
124
|
+
* near-duplicate turns on both sides of every comparison.
|
|
125
|
+
*/
|
|
126
|
+
function splitDraw(sessionId) {
|
|
127
|
+
let hash = 0x811c9dc5;
|
|
128
|
+
const input = sessionId + SPLIT_SALT;
|
|
129
|
+
for (let index = 0; index < input.length; index += 1) {
|
|
130
|
+
hash ^= input.charCodeAt(index);
|
|
131
|
+
hash = Math.imul(hash, 0x01000193);
|
|
132
|
+
}
|
|
133
|
+
return (hash >>> 0) / 0x1_0000_0000;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Which half a session falls in (E3). The unit is the SESSION, never the
|
|
137
|
+
* trace: consecutive turns of one session share topic, bank cutout and
|
|
138
|
+
* entity neighbourhood, so a per-trace split would lay near-duplicates on
|
|
139
|
+
* both sides and let `ci_low > 0` fire on leakage rather than on an effect.
|
|
140
|
+
*
|
|
141
|
+
* AP14's recorder stamps `dream_traces.holdout` and `.audit` with this same
|
|
142
|
+
* function, which is why it takes no store and reads no config: the recorder
|
|
143
|
+
* calls it inside a turn, the night calls it over a pool, and both must get
|
|
144
|
+
* the same answer for the same session id.
|
|
145
|
+
*
|
|
146
|
+
* The two bands sit at opposite ends of the unit interval on purpose. The
|
|
147
|
+
* audit set is the FROZEN one (concept 5.5d) - it takes the top band, so
|
|
148
|
+
* raising or lowering the holdout rate never moves a session in or out of
|
|
149
|
+
* it. A session without an id of its own (a trace outside any conversation)
|
|
150
|
+
* is its own cluster; the caller passes `trace.sessionId ?? trace.id` and
|
|
151
|
+
* gets a stable answer either way.
|
|
152
|
+
*/
|
|
153
|
+
export function splitOf(sessionId, rates) {
|
|
154
|
+
const audit = clampRate(rates.auditRate);
|
|
155
|
+
const holdout = clampRate(rates.holdoutRate);
|
|
156
|
+
const draw = splitDraw(sessionId);
|
|
157
|
+
// Audit first: where the two bands would overlap, the frozen set wins -
|
|
158
|
+
// it is the floor the other two stand on, not a leftover.
|
|
159
|
+
if (audit > 0 && draw >= 1 - audit)
|
|
160
|
+
return 'audit';
|
|
161
|
+
if (holdout > 0 && draw < holdout)
|
|
162
|
+
return 'holdout';
|
|
163
|
+
return 'train';
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Split a recorded pool by session. A trace that was STAMPED at record time
|
|
167
|
+
* keeps its stamp - `dream_traces.holdout`/`.audit` are what the turn
|
|
168
|
+
* decided, and re-deriving them from today's rates would silently move
|
|
169
|
+
* yesterday's evidence. Only an unstamped trace (every trace recorded before
|
|
170
|
+
* AP14 wires the stamp) is drawn here, with the same function.
|
|
171
|
+
*/
|
|
172
|
+
export function splitPool(entries, rates) {
|
|
173
|
+
const pool = { train: [], holdout: [], audit: [] };
|
|
174
|
+
for (const entry of entries) {
|
|
175
|
+
const where = entry.trace.audit
|
|
176
|
+
? 'audit'
|
|
177
|
+
: entry.trace.holdout
|
|
178
|
+
? 'holdout'
|
|
179
|
+
: splitOf(entry.trace.sessionId ?? entry.trace.id, rates);
|
|
180
|
+
pool[where].push(entry);
|
|
181
|
+
}
|
|
182
|
+
return pool;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Validity rule 1 (concept 5.4): baseline and candidate are scored on the
|
|
186
|
+
* INTERSECTION, never each arm on its own set. A candidate that abstained on
|
|
187
|
+
* the hard third of the pool and was averaged over the easy two thirds would
|
|
188
|
+
* win against a baseline that answered everywhere, and the number would not
|
|
189
|
+
* be wrong - it would be about a different set.
|
|
190
|
+
*
|
|
191
|
+
* The predicate is deliberately a check on the counts rather than a comment
|
|
192
|
+
* on the loop that produced them: it is the one rule that can only be broken
|
|
193
|
+
* by a mistake inside this file, and the test that pins it must be able to
|
|
194
|
+
* state that mistake in numbers.
|
|
195
|
+
*/
|
|
196
|
+
export function pairedOnIntersection(counts) {
|
|
197
|
+
return (counts.paired === counts.closed &&
|
|
198
|
+
counts.closed <= Math.min(counts.closedBaseline, counts.closedCandidate));
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Validity rule 2 (concept 5.4): the candidate may abstain at most
|
|
202
|
+
* `abstainEps` more often than the baseline, and BOTH arms must stay under
|
|
203
|
+
* `abstainFloor`. A candidate that wins because it was only ever tested
|
|
204
|
+
* where it felt comfortable is rejected - the delta it reports is real, and
|
|
205
|
+
* it is about the frames it did not run away from.
|
|
206
|
+
*/
|
|
207
|
+
export function abstainRuleHolds(candidateRate, baselineRate, limits) {
|
|
208
|
+
if (candidateRate > baselineRate + limits.abstainEps)
|
|
209
|
+
return false;
|
|
210
|
+
return candidateRate < limits.abstainFloor && baselineRate < limits.abstainFloor;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Validity rule 3 (concept 5.4): below `minTraces` closed traces the
|
|
214
|
+
* evaluation is INVALID, not "the candidate lost". The distinction is the
|
|
215
|
+
* whole point of the rule - a thin night must not be readable as evidence
|
|
216
|
+
* against a candidate, or the ratchet turns on noise.
|
|
217
|
+
*/
|
|
218
|
+
export function traceFloorHolds(closed, minTraces) {
|
|
219
|
+
return closed >= minTraces;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Validity rule 4 (concept 5.4): a mean `reachable_rate` under
|
|
223
|
+
* `reachableFloor` means most labelled targets are unreachable for EVERY
|
|
224
|
+
* candidate alike (superseded, forgotten, dormant, archived). The ideal is
|
|
225
|
+
* then built from what is left, and the ratio says more about the bank's
|
|
226
|
+
* condensation than about any policy.
|
|
227
|
+
*/
|
|
228
|
+
export function reachableFloorHolds(reachableRate, floor) {
|
|
229
|
+
return reachableRate >= floor;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Validity rule 5 (concept 4.4, S10): `label_coverage` over the floor and
|
|
233
|
+
* `cost_only_share` under the ceiling. Below the coverage floor an
|
|
234
|
+
* evaluation cannot tell a real delta from missing labels; above the
|
|
235
|
+
* cost-only ceiling the delta is predominantly block length, and a delta
|
|
236
|
+
* drawn from unlabelled positions is not a delta.
|
|
237
|
+
*/
|
|
238
|
+
export function coverageRuleHolds(coverage, costOnly, limits) {
|
|
239
|
+
return coverage >= limits.coverageFloor && costOnly <= limits.costOnlyCeiling;
|
|
240
|
+
}
|
|
241
|
+
/* ------------------------------- internals ------------------------------- */
|
|
242
|
+
function emptyReasons() {
|
|
243
|
+
const reasons = {};
|
|
244
|
+
for (const reason of ABSTAIN_REASONS)
|
|
245
|
+
reasons[reason] = 0;
|
|
246
|
+
return reasons;
|
|
247
|
+
}
|
|
248
|
+
/** Clamp to a range, for dream keys read outside the patch schema (E21/S23). */
|
|
249
|
+
function clampNumber(value, lo, hi) {
|
|
250
|
+
const safe = Number.isFinite(value) ? value : lo;
|
|
251
|
+
return Math.min(hi, Math.max(lo, safe));
|
|
252
|
+
}
|
|
253
|
+
function mean(values) {
|
|
254
|
+
if (!values.length)
|
|
255
|
+
return null;
|
|
256
|
+
return values.reduce((total, value) => total + value, 0) / values.length;
|
|
257
|
+
}
|
|
258
|
+
/** The chain the frame belongs to - never the other one (R15). */
|
|
259
|
+
function replay(frame, policy) {
|
|
260
|
+
return frame.pipeline === 'agent' ? pipelineAgent(frame, policy) : pipelineAssistant(frame, policy);
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* The corpus stamp a frame was recorded under. Read-only twin of probe.ts's
|
|
264
|
+
* private helper: a stamp that cannot be read certifies nothing, and the
|
|
265
|
+
* drift check is waived rather than guessed.
|
|
266
|
+
*/
|
|
267
|
+
function stampById(store, id) {
|
|
268
|
+
if (!id)
|
|
269
|
+
return null;
|
|
270
|
+
const raw = store.getMeta(CORPUS_STAMP_PREFIX + id);
|
|
271
|
+
if (!raw)
|
|
272
|
+
return null;
|
|
273
|
+
try {
|
|
274
|
+
return JSON.parse(raw);
|
|
275
|
+
}
|
|
276
|
+
catch {
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
/** The budget the assistant turn renders with; mirrors runtime.ts. */
|
|
281
|
+
function expectedBudgetChars(config) {
|
|
282
|
+
return Math.floor(config.memory.contextBudget * 0.4);
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Read the labels of a pool's turns and sessions in batches, so a pool of
|
|
286
|
+
* five hundred frames cannot walk into SQLite's bound-parameter limit. Both
|
|
287
|
+
* scopes are read: a session-wide label never yields a gain (S3), but it is
|
|
288
|
+
* part of the labelled universe `label_coverage` is measured against and it
|
|
289
|
+
* takes part in the agreement check.
|
|
290
|
+
*/
|
|
291
|
+
function labelsOfPool(store, owner, entries) {
|
|
292
|
+
const turnIds = [...new Set(entries.map((entry) => entry.trace.turnId))];
|
|
293
|
+
const sessionIds = [
|
|
294
|
+
...new Set(entries.map((entry) => entry.trace.sessionId).filter((id) => !!id)),
|
|
295
|
+
];
|
|
296
|
+
const labels = [];
|
|
297
|
+
for (let index = 0; index < turnIds.length; index += TURN_BATCH) {
|
|
298
|
+
labels.push(...store.labelsForTurns(turnIds.slice(index, index + TURN_BATCH), owner));
|
|
299
|
+
}
|
|
300
|
+
for (let index = 0; index < sessionIds.length; index += TURN_BATCH) {
|
|
301
|
+
labels.push(...store.labelsForSessions(sessionIds.slice(index, index + TURN_BATCH), owner));
|
|
302
|
+
}
|
|
303
|
+
// `labelsForSessions` selects on `turn_id`, so a session id that is also a
|
|
304
|
+
// turn id would come back twice; the key is what makes a label one label.
|
|
305
|
+
const seen = new Set();
|
|
306
|
+
return labels.filter((label) => {
|
|
307
|
+
const key = label.turnId + ' ' + label.target + ' ' + label.source;
|
|
308
|
+
if (seen.has(key))
|
|
309
|
+
return false;
|
|
310
|
+
seen.add(key);
|
|
311
|
+
return true;
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
const NO_GAIN = () => 0;
|
|
315
|
+
/**
|
|
316
|
+
* Fold a pool's labels into one gain function per turn (concept 4.1). The
|
|
317
|
+
* labelled universe is every target any label of the window names, both
|
|
318
|
+
* scopes included and the `review` sentinel excluded - that universe is what
|
|
319
|
+
* `label_coverage` asks about ("could a label exist for this position at
|
|
320
|
+
* all"), which is a question about the window, not about this turn.
|
|
321
|
+
*/
|
|
322
|
+
function indexLabels(labels) {
|
|
323
|
+
const byTurn = new Map();
|
|
324
|
+
const universe = new Set();
|
|
325
|
+
for (const label of labels) {
|
|
326
|
+
if (label.target !== REVIEW_TARGET)
|
|
327
|
+
universe.add(label.target);
|
|
328
|
+
const bucket = byTurn.get(label.turnId);
|
|
329
|
+
if (bucket)
|
|
330
|
+
bucket.push(label);
|
|
331
|
+
else
|
|
332
|
+
byTurn.set(label.turnId, [label]);
|
|
333
|
+
}
|
|
334
|
+
const gains = new Map();
|
|
335
|
+
let conflicts = 0;
|
|
336
|
+
for (const [turnId, bucket] of byTurn) {
|
|
337
|
+
const folded = gainFrom(bucket);
|
|
338
|
+
conflicts += folded.conflicts;
|
|
339
|
+
gains.set(turnId, folded.gain);
|
|
340
|
+
}
|
|
341
|
+
return { gainFor: (turnId) => gains.get(turnId) ?? NO_GAIN, universe, conflicts };
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* The paired pass (concept 5.3): score both arms over every eligible frame,
|
|
345
|
+
* keep only the traces where BOTH closed, and form one delta per kept trace.
|
|
346
|
+
*
|
|
347
|
+
* Two things happen here that are easy to get subtly wrong, and both have
|
|
348
|
+
* their own test. The intersection is formed before any mean is taken, never
|
|
349
|
+
* after - each arm averaged over its own set is the mistake rule 1 names.
|
|
350
|
+
* And a trace whose two arms moved no labelled position at all abstains as
|
|
351
|
+
* `no-labelled-move` (concept 4.4): its delta could only ever come from the
|
|
352
|
+
* cost term, and a block that is shorter by four characters is not a better
|
|
353
|
+
* ranking. Those traces leave the mean and stay in `cost_only_share`.
|
|
354
|
+
*/
|
|
355
|
+
function pairedRun(entries, index, baseline, candidate, costWeight, options) {
|
|
356
|
+
const reasons = emptyReasons();
|
|
357
|
+
const clusters = new Map();
|
|
358
|
+
const positions = [];
|
|
359
|
+
const deltaPositions = [];
|
|
360
|
+
const candidateScores = [];
|
|
361
|
+
const baselineScores = [];
|
|
362
|
+
const reachable = [];
|
|
363
|
+
const traceIds = [];
|
|
364
|
+
const pairedEntries = [];
|
|
365
|
+
let closedBaseline = 0;
|
|
366
|
+
let closedCandidate = 0;
|
|
367
|
+
let intersection = 0;
|
|
368
|
+
let costOnly = 0;
|
|
369
|
+
let frameTimeouts = 0;
|
|
370
|
+
let deadlineHit = false;
|
|
371
|
+
for (const entry of entries) {
|
|
372
|
+
if (options.signal?.aborted)
|
|
373
|
+
break;
|
|
374
|
+
const now = Date.now();
|
|
375
|
+
if (options.deadline !== undefined && now > options.deadline) {
|
|
376
|
+
deadlineHit = true;
|
|
377
|
+
break;
|
|
378
|
+
}
|
|
379
|
+
const frameDeadline = options.deadline !== undefined
|
|
380
|
+
? Math.min(options.deadline, now + FRAME_TIME_LIMIT_MS)
|
|
381
|
+
: now + FRAME_TIME_LIMIT_MS;
|
|
382
|
+
const payload = entry.frame.payload;
|
|
383
|
+
const gain = index.gainFor(entry.trace.turnId);
|
|
384
|
+
const baseResult = measure(payload, baseline, gain, costWeight);
|
|
385
|
+
const candResult = measure(payload, candidate, gain, costWeight);
|
|
386
|
+
if (!baseResult.ok)
|
|
387
|
+
reasons[baseResult.abstain] += 1;
|
|
388
|
+
else
|
|
389
|
+
closedBaseline += 1;
|
|
390
|
+
if (!candResult.ok)
|
|
391
|
+
reasons[candResult.abstain] += 1;
|
|
392
|
+
else
|
|
393
|
+
closedCandidate += 1;
|
|
394
|
+
if (!baseResult.ok || !candResult.ok)
|
|
395
|
+
continue;
|
|
396
|
+
intersection += 1;
|
|
397
|
+
reachable.push(candResult.reachableRate);
|
|
398
|
+
// A frame past its sub-cap leaves the paired set rather than eating the
|
|
399
|
+
// shared wall clock; it still counted towards both arms' closures.
|
|
400
|
+
if (Date.now() > frameDeadline) {
|
|
401
|
+
frameTimeouts += 1;
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
404
|
+
// What the model read on each arm. `measure` returns the number, not the
|
|
405
|
+
// list, so the rendered lines are replayed once more here - the price of
|
|
406
|
+
// keeping `measure` a pure score with no by-products to keep in step.
|
|
407
|
+
const baseLines = replay(payload, baseline);
|
|
408
|
+
const candLines = replay(payload, candidate);
|
|
409
|
+
if (!baseLines.ok || !candLines.ok)
|
|
410
|
+
continue;
|
|
411
|
+
const baseIds = new Set(baseLines.lines.map((memory) => memory.id));
|
|
412
|
+
const candIds = new Set(candLines.lines.map((memory) => memory.id));
|
|
413
|
+
for (const id of new Set([...baseIds, ...candIds]))
|
|
414
|
+
positions.push(id);
|
|
415
|
+
const moved = [];
|
|
416
|
+
for (const id of baseIds) {
|
|
417
|
+
if (!candIds.has(id))
|
|
418
|
+
moved.push({ id, labelPossible: index.universe.has(id) });
|
|
419
|
+
}
|
|
420
|
+
for (const id of candIds) {
|
|
421
|
+
if (!baseIds.has(id))
|
|
422
|
+
moved.push({ id, labelPossible: index.universe.has(id) });
|
|
423
|
+
}
|
|
424
|
+
deltaPositions.push(moved);
|
|
425
|
+
if (!moved.some((position) => position.labelPossible)) {
|
|
426
|
+
costOnly += 1;
|
|
427
|
+
reasons['no-labelled-move'] += 1;
|
|
428
|
+
continue;
|
|
429
|
+
}
|
|
430
|
+
const cluster = entry.trace.sessionId ?? entry.trace.id;
|
|
431
|
+
const bucket = clusters.get(cluster);
|
|
432
|
+
const delta = candResult.score - baseResult.score;
|
|
433
|
+
if (bucket)
|
|
434
|
+
bucket.push(delta);
|
|
435
|
+
else
|
|
436
|
+
clusters.set(cluster, [delta]);
|
|
437
|
+
candidateScores.push(candResult.score);
|
|
438
|
+
baselineScores.push(baseResult.score);
|
|
439
|
+
traceIds.push(entry.trace.id);
|
|
440
|
+
pairedEntries.push(entry);
|
|
441
|
+
}
|
|
442
|
+
const scoreCandidate = mean(candidateScores);
|
|
443
|
+
const scoreBaseline = mean(baselineScores);
|
|
444
|
+
return {
|
|
445
|
+
closedBaseline,
|
|
446
|
+
closedCandidate,
|
|
447
|
+
intersection,
|
|
448
|
+
costOnly,
|
|
449
|
+
closed: traceIds.length,
|
|
450
|
+
scoreCandidate,
|
|
451
|
+
scoreBaseline,
|
|
452
|
+
delta: scoreCandidate !== null && scoreBaseline !== null ? scoreCandidate - scoreBaseline : null,
|
|
453
|
+
clusters: [...clusters.values()],
|
|
454
|
+
sessions: clusters.size,
|
|
455
|
+
reachableRate: mean(reachable),
|
|
456
|
+
labelCoverage: labelCoverage(positions, index.universe),
|
|
457
|
+
costOnlyShare: costOnlyShare(deltaPositions),
|
|
458
|
+
traceIds,
|
|
459
|
+
pairedEntries,
|
|
460
|
+
reasons,
|
|
461
|
+
frameTimeouts,
|
|
462
|
+
deadlineHit,
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
/** sha256 over the sorted trace ids - order in, one hash out (concept 5.3). */
|
|
466
|
+
export function traceSetHash(traceIds) {
|
|
467
|
+
return createHash('sha256').update([...traceIds].sort().join('\n')).digest('hex');
|
|
468
|
+
}
|
|
469
|
+
/* -------------------------- the evidence digest -------------------------- */
|
|
470
|
+
function signed(value) {
|
|
471
|
+
if (value === null || value === undefined || !Number.isFinite(value))
|
|
472
|
+
return 'na';
|
|
473
|
+
return (value >= 0 ? '+' : '') + value.toFixed(DIGEST_DIGITS);
|
|
474
|
+
}
|
|
475
|
+
function share(value) {
|
|
476
|
+
return Number.isFinite(value) ? value.toFixed(3) : '0.000';
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* The condensed justification stored on the evaluation (E19,
|
|
480
|
+
* `dream_evals.evidence_digest`).
|
|
481
|
+
*
|
|
482
|
+
* Retention is what makes this a type of its own rather than a sentence:
|
|
483
|
+
* frames die after `frameRetainDays` and evaluations live for
|
|
484
|
+
* `retainDays`, so a justification that quoted the frames would either
|
|
485
|
+
* outlive the memories it quoted - which S21 forbids - or vanish before the
|
|
486
|
+
* calibration that needs it. So the digest carries NUMBERS and the closed
|
|
487
|
+
* vocabulary of this file (abstention reasons, label sources, rule names)
|
|
488
|
+
* and no verbatim text at all. The test asserts exactly that, over frames
|
|
489
|
+
* whose contents are distinctive words.
|
|
490
|
+
*/
|
|
491
|
+
export function renderEvidenceDigest(result) {
|
|
492
|
+
const detail = result.detail;
|
|
493
|
+
const worst = ABSTAIN_REASONS.filter((reason) => (result.abstainReasons[reason] ?? 0) > 0)
|
|
494
|
+
.sort((a, b) => (result.abstainReasons[b] ?? 0) - (result.abstainReasons[a] ?? 0))
|
|
495
|
+
.slice(0, 3)
|
|
496
|
+
.map((reason) => reason + ':' + result.abstainReasons[reason])
|
|
497
|
+
.join(',');
|
|
498
|
+
const sources = LABEL_SOURCES.filter((source) => detail?.deltaBySource[source] !== undefined)
|
|
499
|
+
.map((source) => source + ':' + signed(detail?.deltaBySource[source]))
|
|
500
|
+
.join('|');
|
|
501
|
+
const parts = [
|
|
502
|
+
'slot=' + result.slot,
|
|
503
|
+
'n=' + result.traces,
|
|
504
|
+
'closed=' + result.closed,
|
|
505
|
+
'sess=' + result.sessions,
|
|
506
|
+
'abst=' + share(result.abstainRateBaseline) + '/' + share(result.abstainRateCandidate),
|
|
507
|
+
'reach=' + share(result.reachableRate),
|
|
508
|
+
'cov=' + share(result.labelCoverage),
|
|
509
|
+
'cost=' + share(result.costOnlyShare),
|
|
510
|
+
'd=' + signed(result.delta),
|
|
511
|
+
'ci=[' + signed(result.ciLow) + ',' + signed(result.ciHigh) + ']',
|
|
512
|
+
'live=' + signed(result.deltaLive),
|
|
513
|
+
'sign=' + (result.signAgree === null ? 'na' : result.signAgree ? '1' : '0'),
|
|
514
|
+
'audit=' + signed(result.auditDelta) + '/' + signed(result.auditCiLow),
|
|
515
|
+
'valid=' + (result.valid ? '1' : '0'),
|
|
516
|
+
'hash=' + result.traceSetHash.slice(0, 12),
|
|
517
|
+
];
|
|
518
|
+
if (sources)
|
|
519
|
+
parts.push('src=' + sources);
|
|
520
|
+
if (worst)
|
|
521
|
+
parts.push('abstain=' + worst);
|
|
522
|
+
if (result.violations.length)
|
|
523
|
+
parts.push('violations=' + result.violations.join(','));
|
|
524
|
+
// The estimator is a lower bound, and that stands next to the number
|
|
525
|
+
// rather than in a footnote (E8); `ci` is a percentile interval of a
|
|
526
|
+
// cluster bootstrap and approximate, never exact (S11/E6).
|
|
527
|
+
parts.push('bound=lower', 'ci-kind=approximate');
|
|
528
|
+
return parts.join(' ');
|
|
529
|
+
}
|
|
530
|
+
/* --------------------------- the freshness sensor --------------------------- */
|
|
531
|
+
/**
|
|
532
|
+
* The frame-ageing sensor over a pool (concept 5.5a), through probe.ts's
|
|
533
|
+
* `freshnessCheck`.
|
|
534
|
+
*
|
|
535
|
+
* `freshnessCheck` takes ONE gain function, and a gain is a statement about
|
|
536
|
+
* one turn - so the pool is walked entry by entry, each with its own turn's
|
|
537
|
+
* gain, and the per-frame deltas are averaged here. That is the only honest
|
|
538
|
+
* way to hand a per-turn label set to a per-pool sensor; folding every
|
|
539
|
+
* turn's labels into one function would let a memory proven relevant in one
|
|
540
|
+
* turn score in every other.
|
|
541
|
+
*
|
|
542
|
+
* `touch: false` needs no flag: the live re-fetch goes through `fetchFrame`,
|
|
543
|
+
* which has no touch path at all (S30). The sensor is a comparator, never a
|
|
544
|
+
* measurement - the live world is knowingly polluted, and a sign FLIP is the
|
|
545
|
+
* only thing read out of it.
|
|
546
|
+
*/
|
|
547
|
+
function runFreshness(store, entries, index, input, costWeight, margin) {
|
|
548
|
+
const summary = {
|
|
549
|
+
frames: 0,
|
|
550
|
+
closedBoth: 0,
|
|
551
|
+
deltaFrozen: null,
|
|
552
|
+
deltaLive: null,
|
|
553
|
+
signAgree: null,
|
|
554
|
+
rowsDifferShare: 0,
|
|
555
|
+
};
|
|
556
|
+
const frozen = [];
|
|
557
|
+
const live = [];
|
|
558
|
+
let compared = 0;
|
|
559
|
+
let differ = 0;
|
|
560
|
+
for (const entry of entries) {
|
|
561
|
+
if (input.signal?.aborted)
|
|
562
|
+
break;
|
|
563
|
+
if (input.deadline !== undefined && Date.now() > input.deadline)
|
|
564
|
+
break;
|
|
565
|
+
const report = freshnessCheck(store, [entry], {
|
|
566
|
+
config: input.config,
|
|
567
|
+
baseline: input.baseline,
|
|
568
|
+
candidate: input.candidate,
|
|
569
|
+
gain: index.gainFor(entry.trace.turnId),
|
|
570
|
+
costWeight,
|
|
571
|
+
deadline: input.deadline,
|
|
572
|
+
signal: input.signal,
|
|
573
|
+
});
|
|
574
|
+
summary.frames += 1;
|
|
575
|
+
const one = report.entries[0];
|
|
576
|
+
if (!one)
|
|
577
|
+
continue;
|
|
578
|
+
if (one.fresh) {
|
|
579
|
+
compared += 1;
|
|
580
|
+
if (one.rowsDiffer)
|
|
581
|
+
differ += 1;
|
|
582
|
+
}
|
|
583
|
+
if (one.frozenDelta !== null && one.liveDelta !== null) {
|
|
584
|
+
summary.closedBoth += 1;
|
|
585
|
+
frozen.push(one.frozenDelta);
|
|
586
|
+
live.push(one.liveDelta);
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
summary.deltaFrozen = mean(frozen);
|
|
590
|
+
summary.deltaLive = mean(live);
|
|
591
|
+
summary.rowsDifferShare = compared ? differ / compared : 0;
|
|
592
|
+
if (summary.deltaFrozen !== null && summary.deltaLive !== null) {
|
|
593
|
+
// Inside the margin the sign comparison is moot, and `null` says
|
|
594
|
+
// undetermined - not "they disagree" (concept 5.5a).
|
|
595
|
+
if (Math.abs(summary.deltaFrozen) <= margin)
|
|
596
|
+
summary.signAgree = null;
|
|
597
|
+
else
|
|
598
|
+
summary.signAgree = Math.sign(summary.deltaFrozen) === Math.sign(summary.deltaLive);
|
|
599
|
+
}
|
|
600
|
+
return summary;
|
|
601
|
+
}
|
|
602
|
+
/* --------------------------- evaluateCandidate --------------------------- */
|
|
603
|
+
function emptyResult(slot) {
|
|
604
|
+
return {
|
|
605
|
+
slot,
|
|
606
|
+
traces: 0,
|
|
607
|
+
closed: 0,
|
|
608
|
+
abstained: 0,
|
|
609
|
+
abstainReasons: emptyReasons(),
|
|
610
|
+
reachableRate: 0,
|
|
611
|
+
labelCoverage: 0,
|
|
612
|
+
costOnlyShare: 0,
|
|
613
|
+
score: 0,
|
|
614
|
+
baseline: 0,
|
|
615
|
+
delta: 0,
|
|
616
|
+
ciLow: 0,
|
|
617
|
+
ciHigh: 0,
|
|
618
|
+
signAgree: null,
|
|
619
|
+
evalMs: 0,
|
|
620
|
+
traceSetHash: traceSetHash([]),
|
|
621
|
+
valid: false,
|
|
622
|
+
violations: [],
|
|
623
|
+
sessions: 0,
|
|
624
|
+
closedBaseline: 0,
|
|
625
|
+
closedCandidate: 0,
|
|
626
|
+
abstainRateBaseline: 0,
|
|
627
|
+
abstainRateCandidate: 0,
|
|
628
|
+
freshness: null,
|
|
629
|
+
error: null,
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
/** The limits of concept 5.4, clamped as they are read (S23). */
|
|
633
|
+
export function validityLimits(config) {
|
|
634
|
+
const dream = config.memory.dream;
|
|
635
|
+
return {
|
|
636
|
+
minTraces: Math.max(0, Math.floor(clampNumber(dream.minTraces, 0, 1_000_000))),
|
|
637
|
+
abstainEps: clampNumber(dream.abstainEps, 0, 1),
|
|
638
|
+
abstainFloor: clampNumber(dream.abstainFloor, 0, 1),
|
|
639
|
+
reachableFloor: clampNumber(dream.reachableFloor, 0, 1),
|
|
640
|
+
coverageFloor: clampNumber(dream.coverageFloor, 0, 1),
|
|
641
|
+
costOnlyCeiling: clampNumber(dream.costOnlyCeiling, 0, 1),
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* The five rules of concept 5.4 over a finished result. Every failure is a
|
|
646
|
+
* named violation and the result stays readable - an invalid evaluation is
|
|
647
|
+
* not an error, it is a measurement that does not certify anything, and the
|
|
648
|
+
* numbers it did produce are still worth storing.
|
|
649
|
+
*/
|
|
650
|
+
export function validityOf(result, limits) {
|
|
651
|
+
const violations = [];
|
|
652
|
+
if (!pairedOnIntersection({
|
|
653
|
+
closedBaseline: result.closedBaseline,
|
|
654
|
+
closedCandidate: result.closedCandidate,
|
|
655
|
+
closed: result.closed,
|
|
656
|
+
paired: result.closed,
|
|
657
|
+
})) {
|
|
658
|
+
violations.push('not-paired-on-intersection');
|
|
659
|
+
}
|
|
660
|
+
if (!abstainRuleHolds(result.abstainRateCandidate, result.abstainRateBaseline, limits)) {
|
|
661
|
+
violations.push('abstain-rate');
|
|
662
|
+
}
|
|
663
|
+
// Rule 3 is the one that must never read as "the candidate lost".
|
|
664
|
+
if (!traceFloorHolds(result.closed, limits.minTraces))
|
|
665
|
+
violations.push('n-closed-below-min');
|
|
666
|
+
if (!reachableFloorHolds(result.reachableRate, limits.reachableFloor)) {
|
|
667
|
+
violations.push('reachable-rate');
|
|
668
|
+
}
|
|
669
|
+
if (!coverageRuleHolds(result.labelCoverage, result.costOnlyShare, limits)) {
|
|
670
|
+
if (result.labelCoverage < limits.coverageFloor)
|
|
671
|
+
violations.push('label-coverage');
|
|
672
|
+
if (result.costOnlyShare > limits.costOnlyCeiling)
|
|
673
|
+
violations.push('cost-only-share');
|
|
674
|
+
}
|
|
675
|
+
return { valid: violations.length === 0, violations };
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* Evaluate one candidate arm against one baseline arm over a recorded pool
|
|
679
|
+
* (concept 5.3, 5.4, 4.4).
|
|
680
|
+
*
|
|
681
|
+
* The order of work is the contract. The pre-checks fire first and in a
|
|
682
|
+
* fixed order - a frame of another owner is dropped outright (10.5), then
|
|
683
|
+
* `unfinished`, then `corpus-drifted` against the stamp the caller handed
|
|
684
|
+
* in, then `budget-changed` against the config the turn would render with
|
|
685
|
+
* today. What survives is scored on both arms; the intersection of the two
|
|
686
|
+
* closed sets is what a delta may be formed over, and the bootstrap draws
|
|
687
|
+
* SESSIONS, not traces. The five validity rules run last, over the finished
|
|
688
|
+
* numbers, so their verdict is reproducible from the stored row alone.
|
|
689
|
+
*
|
|
690
|
+
* Nothing here writes, and nothing here throws.
|
|
691
|
+
*/
|
|
692
|
+
export function evaluateCandidate(store, input) {
|
|
693
|
+
const startedAt = Date.now();
|
|
694
|
+
const result = emptyResult(input.slot);
|
|
695
|
+
// First line of work: the abort guard. There is no `#throwIfAborted` in the
|
|
696
|
+
// night's dream block, so an aborted run reports an empty, invalid result.
|
|
697
|
+
if (input.signal?.aborted) {
|
|
698
|
+
result.violations.push('aborted');
|
|
699
|
+
result.evalMs = Date.now() - startedAt;
|
|
700
|
+
return result;
|
|
701
|
+
}
|
|
702
|
+
try {
|
|
703
|
+
const dream = input.config.memory.dream;
|
|
704
|
+
const costWeight = clampNumber(dream.costWeight, 0, 1);
|
|
705
|
+
const tolerance = clampNumber(dream.corpusTolerance, 0, 10);
|
|
706
|
+
const margin = clampNumber(dream.margin, 0, 1);
|
|
707
|
+
const budget = expectedBudgetChars(input.config);
|
|
708
|
+
// Pre-checks. The owner filter is first and is not an abstention: a
|
|
709
|
+
// frame of another bank is not a frame this evaluation may read at all.
|
|
710
|
+
const reasons = emptyReasons();
|
|
711
|
+
const eligible = [];
|
|
712
|
+
let foreignOwner = 0;
|
|
713
|
+
for (const entry of input.entries) {
|
|
714
|
+
if (entry.frame.owner !== input.owner || entry.trace.owner !== input.owner) {
|
|
715
|
+
foreignOwner += 1;
|
|
716
|
+
continue;
|
|
717
|
+
}
|
|
718
|
+
const payload = entry.frame.payload;
|
|
719
|
+
let reason = null;
|
|
720
|
+
if (!entry.trace.finishedAt)
|
|
721
|
+
reason = 'unfinished';
|
|
722
|
+
else if (input.corpus &&
|
|
723
|
+
corpusDrifted(payload, input.corpus, tolerance, stampById(store, payload.corpusStampId))) {
|
|
724
|
+
reason = 'corpus-drifted';
|
|
725
|
+
}
|
|
726
|
+
else if (payload.pipeline === 'assistant' && payload.budgetChars !== budget) {
|
|
727
|
+
reason = 'budget-changed';
|
|
728
|
+
}
|
|
729
|
+
if (reason) {
|
|
730
|
+
reasons[reason] += 1;
|
|
731
|
+
continue;
|
|
732
|
+
}
|
|
733
|
+
eligible.push(entry);
|
|
734
|
+
}
|
|
735
|
+
result.traces = input.entries.length - foreignOwner;
|
|
736
|
+
const labels = labelsOfPool(store, input.owner, eligible);
|
|
737
|
+
const index = indexLabels(labels);
|
|
738
|
+
const run = pairedRun(eligible, index, input.baseline, input.candidate, costWeight, {
|
|
739
|
+
deadline: input.deadline,
|
|
740
|
+
signal: input.signal,
|
|
741
|
+
});
|
|
742
|
+
for (const reason of ABSTAIN_REASONS) {
|
|
743
|
+
result.abstainReasons[reason] = reasons[reason] + run.reasons[reason];
|
|
744
|
+
}
|
|
745
|
+
result.closed = run.closed;
|
|
746
|
+
result.closedBaseline = run.closedBaseline;
|
|
747
|
+
result.closedCandidate = run.closedCandidate;
|
|
748
|
+
result.abstained = Math.max(0, result.traces - run.closed);
|
|
749
|
+
result.abstainRateBaseline = result.traces
|
|
750
|
+
? (result.traces - run.closedBaseline) / result.traces
|
|
751
|
+
: 0;
|
|
752
|
+
result.abstainRateCandidate = result.traces
|
|
753
|
+
? (result.traces - run.closedCandidate) / result.traces
|
|
754
|
+
: 0;
|
|
755
|
+
result.reachableRate = run.reachableRate ?? 0;
|
|
756
|
+
result.labelCoverage = run.labelCoverage;
|
|
757
|
+
result.costOnlyShare = run.costOnlyShare;
|
|
758
|
+
result.score = run.scoreCandidate ?? 0;
|
|
759
|
+
result.baseline = run.scoreBaseline ?? 0;
|
|
760
|
+
result.delta = run.delta ?? 0;
|
|
761
|
+
result.sessions = run.sessions;
|
|
762
|
+
result.traceSetHash = traceSetHash(run.traceIds);
|
|
763
|
+
// The interval: B = 2000 draws of SESSIONS with replacement, percentile
|
|
764
|
+
// 2.5/97.5, and it is reported as approximate - at the ten to twenty-five
|
|
765
|
+
// clusters this pool produces, the coverage of a percentile interval on a
|
|
766
|
+
// skewed paired mean sits noticeably under its nominal value (S11).
|
|
767
|
+
const ci = run.clusters.length ? bootstrapCi(run.clusters) : null;
|
|
768
|
+
result.ciLow = ci?.low ?? 0;
|
|
769
|
+
result.ciHigh = ci?.high ?? 0;
|
|
770
|
+
// Per-source deltas (concept 5.5b): the same paired pass, with each
|
|
771
|
+
// source alone supplying the gain. One source in the pool means the
|
|
772
|
+
// combined gain already IS that source's, and the second pass is skipped
|
|
773
|
+
// rather than paid for.
|
|
774
|
+
const labelsBySource = {};
|
|
775
|
+
for (const label of labels) {
|
|
776
|
+
labelsBySource[label.source] = (labelsBySource[label.source] ?? 0) + 1;
|
|
777
|
+
}
|
|
778
|
+
const present = LABEL_SOURCES.filter((source) => (labelsBySource[source] ?? 0) > 0);
|
|
779
|
+
const deltaBySource = {};
|
|
780
|
+
if (input.sourceDeltas !== false && present.length === 1) {
|
|
781
|
+
deltaBySource[present[0]] = result.delta;
|
|
782
|
+
}
|
|
783
|
+
else if (input.sourceDeltas !== false) {
|
|
784
|
+
for (const source of present) {
|
|
785
|
+
if (input.signal?.aborted)
|
|
786
|
+
break;
|
|
787
|
+
if (input.deadline !== undefined && Date.now() > input.deadline)
|
|
788
|
+
break;
|
|
789
|
+
const only = indexLabels(labels.filter((label) => label.source === source));
|
|
790
|
+
const sourceRun = pairedRun(eligible, only, input.baseline, input.candidate, costWeight, { deadline: input.deadline, signal: input.signal });
|
|
791
|
+
if (sourceRun.delta !== null)
|
|
792
|
+
deltaBySource[source] = sourceRun.delta;
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
// The freshness sensor, over the traces that actually paired - the only
|
|
796
|
+
// ones whose sign there is anything to compare.
|
|
797
|
+
if (input.freshness !== false && run.pairedEntries.length) {
|
|
798
|
+
result.freshness = runFreshness(store, run.pairedEntries, index, input, costWeight, margin);
|
|
799
|
+
if (result.freshness.deltaLive !== null)
|
|
800
|
+
result.deltaLive = result.freshness.deltaLive;
|
|
801
|
+
result.signAgree = result.freshness.signAgree;
|
|
802
|
+
}
|
|
803
|
+
result.detail = {
|
|
804
|
+
deltaBySource,
|
|
805
|
+
labelsBySource,
|
|
806
|
+
conflicts: index.conflicts,
|
|
807
|
+
foreignOwner,
|
|
808
|
+
intersection: run.intersection,
|
|
809
|
+
costOnly: run.costOnly,
|
|
810
|
+
frameTimeouts: run.frameTimeouts,
|
|
811
|
+
deadlineHit: run.deadlineHit,
|
|
812
|
+
};
|
|
813
|
+
const verdict = validityOf(result, validityLimits(input.config));
|
|
814
|
+
result.valid = verdict.valid;
|
|
815
|
+
result.violations = verdict.violations;
|
|
816
|
+
result.evalMs = Date.now() - startedAt;
|
|
817
|
+
result.evidenceDigest = renderEvidenceDigest(result);
|
|
818
|
+
return result;
|
|
819
|
+
}
|
|
820
|
+
catch (cause) {
|
|
821
|
+
// Like the probe: an internal failure is reported, and the night goes on.
|
|
822
|
+
result.error = cause.message;
|
|
823
|
+
result.evalMs = Date.now() - startedAt;
|
|
824
|
+
result.valid = false;
|
|
825
|
+
if (!result.violations.includes('error'))
|
|
826
|
+
result.violations.push('error');
|
|
827
|
+
result.evidenceDigest = renderEvidenceDigest(result);
|
|
828
|
+
return result;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
/**
|
|
832
|
+
* Rank the candidates on the training half and send exactly one of them to
|
|
833
|
+
* the holdout (E4/S12).
|
|
834
|
+
*
|
|
835
|
+
* Testing six candidates against one 95 percent interval is six-fold
|
|
836
|
+
* testing, and the concept's answer is not a correction but a discipline:
|
|
837
|
+
* the ranking happens where a wrong answer costs nothing, and the one
|
|
838
|
+
* interval that will be read is computed once, on data the ranking never
|
|
839
|
+
* saw. A candidate that is not ahead of the incumbent on training has no
|
|
840
|
+
* business on the holdout at all - the margin test itself belongs to the
|
|
841
|
+
* holdout (promotion condition 2a), so the bar here is plain improvement.
|
|
842
|
+
*
|
|
843
|
+
* The frozen audit set (concept 5.5d) is touched exactly once per promotion
|
|
844
|
+
* (S13), and only when a promotion is actually on the table: the holdout
|
|
845
|
+
* must be valid, over the margin and with `ci_low > 0` before the audit set
|
|
846
|
+
* is opened at all. Without that rule the set would be consumed by every
|
|
847
|
+
* night that measured something, and a set that is read every night is not
|
|
848
|
+
* a frozen set - it is just another holdout with a longer name.
|
|
849
|
+
*/
|
|
850
|
+
export function selectOnTraining(store, input) {
|
|
851
|
+
const rates = input.rates ?? {
|
|
852
|
+
holdoutRate: DEFAULT_HOLDOUT_RATE,
|
|
853
|
+
auditRate: DEFAULT_AUDIT_RATE,
|
|
854
|
+
};
|
|
855
|
+
const pool = splitPool(input.entries, rates);
|
|
856
|
+
const report = {
|
|
857
|
+
split: { train: pool.train.length, holdout: pool.holdout.length, audit: pool.audit.length },
|
|
858
|
+
ranked: [],
|
|
859
|
+
chosen: null,
|
|
860
|
+
holdout: null,
|
|
861
|
+
audit: null,
|
|
862
|
+
auditTouched: 0,
|
|
863
|
+
findings: [],
|
|
864
|
+
};
|
|
865
|
+
const common = {
|
|
866
|
+
owner: input.owner,
|
|
867
|
+
slot: input.slot,
|
|
868
|
+
config: input.config,
|
|
869
|
+
corpus: input.corpus,
|
|
870
|
+
sourceDeltas: input.sourceDeltas,
|
|
871
|
+
deadline: input.deadline,
|
|
872
|
+
signal: input.signal,
|
|
873
|
+
};
|
|
874
|
+
for (let index = 0; index < input.candidates.length; index += 1) {
|
|
875
|
+
if (input.signal?.aborted)
|
|
876
|
+
break;
|
|
877
|
+
const policy = input.candidates[index];
|
|
878
|
+
report.ranked.push({
|
|
879
|
+
index,
|
|
880
|
+
policy,
|
|
881
|
+
training: evaluateCandidate(store, {
|
|
882
|
+
...common,
|
|
883
|
+
entries: pool.train,
|
|
884
|
+
baseline: input.incumbent,
|
|
885
|
+
candidate: policy,
|
|
886
|
+
// The training half ranks; the freshness sensor is a promotion
|
|
887
|
+
// sensor and costs a live fetch per frame, so it runs once, on the
|
|
888
|
+
// one evaluation that can lead anywhere.
|
|
889
|
+
freshness: false,
|
|
890
|
+
}),
|
|
891
|
+
});
|
|
892
|
+
}
|
|
893
|
+
report.ranked.sort((a, b) => {
|
|
894
|
+
if (a.training.valid !== b.training.valid)
|
|
895
|
+
return a.training.valid ? -1 : 1;
|
|
896
|
+
if (b.training.delta !== a.training.delta)
|
|
897
|
+
return b.training.delta - a.training.delta;
|
|
898
|
+
if (b.training.ciLow !== a.training.ciLow)
|
|
899
|
+
return b.training.ciLow - a.training.ciLow;
|
|
900
|
+
return a.index - b.index;
|
|
901
|
+
});
|
|
902
|
+
const best = report.ranked.find((entry) => entry.training.valid && entry.training.delta > 0);
|
|
903
|
+
if (!best) {
|
|
904
|
+
report.findings.push('no-candidate-ahead-on-training');
|
|
905
|
+
return report;
|
|
906
|
+
}
|
|
907
|
+
report.chosen = best;
|
|
908
|
+
if (!pool.holdout.length) {
|
|
909
|
+
report.findings.push('holdout-empty');
|
|
910
|
+
return report;
|
|
911
|
+
}
|
|
912
|
+
report.holdout = evaluateCandidate(store, {
|
|
913
|
+
...common,
|
|
914
|
+
entries: pool.holdout,
|
|
915
|
+
baseline: input.incumbent,
|
|
916
|
+
candidate: best.policy,
|
|
917
|
+
freshness: input.freshness,
|
|
918
|
+
});
|
|
919
|
+
const margin = clampNumber(input.config.memory.dream.margin, 0, 1);
|
|
920
|
+
const promotable = report.holdout.valid && report.holdout.delta > margin && report.holdout.ciLow > 0;
|
|
921
|
+
if (!promotable) {
|
|
922
|
+
// The audit set stays shut: nothing is on the table, so nothing spends
|
|
923
|
+
// the one touch this promotion would have had (S13).
|
|
924
|
+
report.findings.push('holdout-not-promotable');
|
|
925
|
+
return report;
|
|
926
|
+
}
|
|
927
|
+
if (!pool.audit.length) {
|
|
928
|
+
report.findings.push('audit-set-empty');
|
|
929
|
+
return report;
|
|
930
|
+
}
|
|
931
|
+
report.auditTouched = 1;
|
|
932
|
+
report.audit = evaluateCandidate(store, {
|
|
933
|
+
...common,
|
|
934
|
+
entries: pool.audit,
|
|
935
|
+
// Cumulative, against the FACTORY default rather than the incumbent
|
|
936
|
+
// (condition 2b): a chain of individually significant steps, each only
|
|
937
|
+
// against its own predecessor, is a random walk with a ratchet.
|
|
938
|
+
baseline: input.factory,
|
|
939
|
+
candidate: best.policy,
|
|
940
|
+
freshness: false,
|
|
941
|
+
});
|
|
942
|
+
report.holdout.auditDelta = report.audit.delta;
|
|
943
|
+
report.holdout.auditCiLow = report.audit.ciLow;
|
|
944
|
+
report.holdout.evidenceDigest = renderEvidenceDigest(report.holdout);
|
|
945
|
+
return report;
|
|
946
|
+
}
|
|
947
|
+
/**
|
|
948
|
+
* The label agreement sensor (concept 5.5b, E12): Cohen's kappa per source
|
|
949
|
+
* pair over their common targets, with `user` privileged.
|
|
950
|
+
*
|
|
951
|
+
* `user` is privileged because it is the one source the retrieval policy has
|
|
952
|
+
* no causal path to. Everything else is written downstream of what the
|
|
953
|
+
* incumbent surfaced, so a candidate can move all of them together and be
|
|
954
|
+
* measuring its own reflection. Hence the second finding: a delta that is
|
|
955
|
+
* positive on the influenceable sources and flat or negative on `user` is
|
|
956
|
+
* flagged, not averaged away.
|
|
957
|
+
*
|
|
958
|
+
* And when `user` has too few common targets for an agreement at all, that
|
|
959
|
+
* IS the answer. The report says `validated: false` and names it, rather
|
|
960
|
+
* than falling back on the sources that agree with each other because they
|
|
961
|
+
* were written by the same process.
|
|
962
|
+
*/
|
|
963
|
+
export function agreementReport(labels, options = {}) {
|
|
964
|
+
const floor = clampNumber(options.floor ?? DEFAULT_CONFIG.memory.dream.agreementFloor, -1, 1);
|
|
965
|
+
const margin = clampNumber(options.margin ?? DEFAULT_CONFIG.memory.dream.margin, 0, 1);
|
|
966
|
+
const minUserPairs = Math.max(1, Math.floor(options.minUserPairs ?? MIN_USER_PAIRS));
|
|
967
|
+
const bySource = new Map();
|
|
968
|
+
const labelsBySource = {};
|
|
969
|
+
for (const label of labels) {
|
|
970
|
+
const bucket = bySource.get(label.source);
|
|
971
|
+
if (bucket)
|
|
972
|
+
bucket.push(label);
|
|
973
|
+
else
|
|
974
|
+
bySource.set(label.source, [label]);
|
|
975
|
+
labelsBySource[label.source] = (labelsBySource[label.source] ?? 0) + 1;
|
|
976
|
+
}
|
|
977
|
+
const pairs = [];
|
|
978
|
+
for (let i = 0; i < LABEL_SOURCES.length; i += 1) {
|
|
979
|
+
for (let j = i + 1; j < LABEL_SOURCES.length; j += 1) {
|
|
980
|
+
const a = LABEL_SOURCES[i];
|
|
981
|
+
const b = LABEL_SOURCES[j];
|
|
982
|
+
const left = bySource.get(a) ?? [];
|
|
983
|
+
const right = bySource.get(b) ?? [];
|
|
984
|
+
if (!left.length || !right.length)
|
|
985
|
+
continue;
|
|
986
|
+
const common = pairedRatings(left, right);
|
|
987
|
+
if (!common.length)
|
|
988
|
+
continue;
|
|
989
|
+
pairs.push({
|
|
990
|
+
a,
|
|
991
|
+
b,
|
|
992
|
+
pairs: common.length,
|
|
993
|
+
kappa: cohensKappa(left, right),
|
|
994
|
+
agreement: pairwiseAgreement(left, right),
|
|
995
|
+
});
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
// The privileged comparison: the best-supported pair `user` takes part in.
|
|
999
|
+
const userPairsList = pairs.filter((pair) => pair.a === 'user' || pair.b === 'user');
|
|
1000
|
+
const bestUser = userPairsList.reduce((best, pair) => (!best || pair.pairs > best.pairs ? pair : best), null);
|
|
1001
|
+
const userPairs = bestUser?.pairs ?? 0;
|
|
1002
|
+
// Kappa where it is defined, the plain rate where it is not: `merge`
|
|
1003
|
+
// writes nothing but zeroes, so a kappa against it is degenerate by
|
|
1004
|
+
// construction and a fabricated number would be worse than the fallback.
|
|
1005
|
+
const userScore = bestUser ? (bestUser.kappa ?? bestUser.agreement) : null;
|
|
1006
|
+
const validated = userPairs >= minUserPairs && userScore !== null;
|
|
1007
|
+
const floorHolds = validated && (userScore ?? 0) >= floor;
|
|
1008
|
+
const deltas = options.deltaBySource ?? {};
|
|
1009
|
+
const influenceableUp = INFLUENCEABLE.some((source) => (deltas[source] ?? 0) > margin);
|
|
1010
|
+
const userDelta = deltas.user;
|
|
1011
|
+
const influenceableOnly = influenceableUp && userDelta !== undefined && userDelta <= margin;
|
|
1012
|
+
const findings = [];
|
|
1013
|
+
if (!validated)
|
|
1014
|
+
findings.push('user-labels-thin');
|
|
1015
|
+
else if (!floorHolds)
|
|
1016
|
+
findings.push('agreement-below-floor');
|
|
1017
|
+
if (influenceableOnly)
|
|
1018
|
+
findings.push('influenceable-only-delta');
|
|
1019
|
+
return {
|
|
1020
|
+
labelsBySource,
|
|
1021
|
+
pairs,
|
|
1022
|
+
userPairs,
|
|
1023
|
+
userKappa: bestUser?.kappa ?? null,
|
|
1024
|
+
userAgreement: bestUser?.agreement ?? null,
|
|
1025
|
+
validated,
|
|
1026
|
+
floorHolds,
|
|
1027
|
+
influenceableOnly,
|
|
1028
|
+
findings,
|
|
1029
|
+
ok: findings.length === 0,
|
|
1030
|
+
};
|
|
1031
|
+
}
|
|
1032
|
+
//# sourceMappingURL=evaluate.js.map
|