@cortex-agent/server 2026.10.2 → 2026.10.6
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 +31 -31
- package/defaults/AGENTS.md +3 -3
- package/defaults/config/{thread-templates/agents/direct.json → environments/main.json} +2 -2
- package/defaults/context/AGENTS.md +0 -2
- package/defaults/context/projects/AGENTS.md +0 -2
- package/defaults/context/user/AGENTS.md +1 -1
- package/defaults/hooks/cortex-hook-api.mjs +1 -3
- package/defaults/hooks/new-session-hook.mjs +2 -3
- package/defaults/hooks/status-md-guard.mjs +5 -5
- package/defaults/plugins/cortex-system/.claude-plugin/plugin.json +2 -2
- package/defaults/plugins/cortex-system/plugin.json +2 -2
- package/defaults/plugins/cortex-system/skills/project-init/SKILL.md +4 -4
- package/defaults/plugins/cortex-system/skills/schedule/SKILL.md +11 -13
- package/defaults/plugins/cortex-system/skills/user-learn/SKILL.md +1 -1
- package/defaults/prompts/systemPrompts/web-opus-4-6.md +2 -2
- package/defaults/prompts/systemPrompts/web-sonnet-4-6.md +2 -2
- package/defaults/rules/issues-md.md +2 -2
- package/defaults/rules/meta-conventions.md +1 -2
- package/defaults/rules/mission-md.md +1 -1
- package/defaults/rules/overview-md.md +1 -1
- package/defaults/rules/roadmap-md.md +1 -1
- package/defaults/rules/status-md.md +4 -4
- package/dist/agent-adapter/claude/adapter.d.ts +6 -1
- package/dist/agent-adapter/claude/adapter.js +15 -4
- package/dist/agent-adapter/claude/compact-window.d.ts +11 -3
- package/dist/agent-adapter/claude/compact-window.js +12 -3
- package/dist/agent-adapter/claude/defaults.d.ts +0 -1
- package/dist/agent-adapter/claude/defaults.js +0 -1
- package/dist/agent-adapter/claude/event-translator.d.ts +2 -2
- package/dist/agent-adapter/claude/event-translator.js +2 -1
- package/dist/agent-adapter/claude/hooks-builder.d.ts +0 -5
- package/dist/agent-adapter/claude/hooks-builder.js +0 -13
- package/dist/agent-adapter/claude/spawn-args.d.ts +5 -12
- package/dist/agent-adapter/claude/spawn-args.js +45 -38
- package/dist/agent-adapter/claude/turn-machine.d.ts +2 -2
- package/dist/agent-adapter/claude/turn-machine.js +6 -3
- package/dist/agent-adapter/continuation-phase.js +2 -1
- package/dist/agent-adapter/normalize/event-types.d.ts +4 -1
- package/dist/agent-adapter/normalize/tool-result-images.d.ts +11 -0
- package/dist/agent-adapter/normalize/tool-result-images.js +32 -0
- package/dist/agent-adapter/pi/child-events.js +3 -0
- package/dist/agent-adapter/pi/child-runner.d.ts +1 -2
- package/dist/agent-adapter/pi/child-runner.js +6 -6
- package/dist/agent-adapter/pi/child-session.d.ts +1 -1
- package/dist/agent-adapter/pi/event-parser.d.ts +13 -2
- package/dist/agent-adapter/pi/event-parser.js +38 -11
- package/dist/agent-adapter/pi/mcp-bridge-logic.d.ts +0 -1
- package/dist/agent-adapter/pi/mcp-bridge-logic.js +0 -3
- package/dist/agent-adapter/pi/mcp-bridge.js +4 -4
- package/dist/agent-adapter/pi/pi-session.d.ts +4 -2
- package/dist/agent-adapter/pi/pi-session.js +18 -9
- package/dist/agent-adapter/pi/runtime-settings.d.ts +7 -0
- package/dist/agent-adapter/pi/runtime-settings.js +23 -0
- package/dist/agent-adapter/pi/runtime.d.ts +2 -3
- package/dist/agent-adapter/pi/session-options.d.ts +4 -1
- package/dist/agent-adapter/pi/session-options.js +13 -21
- package/dist/agent-adapter/pi/session-support.d.ts +2 -0
- package/dist/agent-adapter/run-events.d.ts +3 -1
- package/dist/agent-adapter/types.d.ts +6 -12
- package/dist/agent-adapter/types.js +2 -4
- package/dist/core/agents/roles.d.ts +1 -1
- package/dist/core/agents/subagent/attribution.js +1 -0
- package/dist/core/agents/subagent/catalog.d.ts +8 -0
- package/dist/core/agents/subagent/catalog.js +21 -10
- package/dist/core/agents/subagent/types.d.ts +4 -1
- package/dist/core/config-generator.d.ts +0 -6
- package/dist/core/config-generator.js +1 -35
- package/dist/core/icons.d.ts +33 -33
- package/dist/core/locales/en.d.ts +863 -1030
- package/dist/core/locales/slices/commands.d.ts +282 -349
- package/dist/core/locales/slices/commands.js +20 -160
- package/dist/core/locales/slices/init.d.ts +152 -152
- package/dist/core/locales/slices/interactions.d.ts +44 -45
- package/dist/core/locales/slices/interactions.js +0 -4
- package/dist/core/locales/slices/lang.d.ts +5 -5
- package/dist/core/locales/slices/notices.d.ts +75 -118
- package/dist/core/locales/slices/notices.js +13 -99
- package/dist/core/locales/slices/scheduling.d.ts +31 -31
- package/dist/core/locales/slices/startup.d.ts +5 -5
- package/dist/core/locales/slices/status.d.ts +43 -43
- package/dist/core/locales/slices/tui.d.ts +91 -114
- package/dist/core/locales/slices/tui.js +0 -46
- package/dist/core/locales/slices/uiextra.d.ts +41 -61
- package/dist/core/locales/slices/uiextra.js +11 -51
- package/dist/core/locales/slices/uimsg.d.ts +86 -99
- package/dist/core/locales/slices/uimsg.js +6 -32
- package/dist/core/mcp-bundles.d.ts +1 -1
- package/dist/core/mcp-bundles.js +7 -5
- package/dist/core/mcp-tool-gate.js +8 -5
- package/dist/core/platform-settings-spec.d.ts +3 -3
- package/dist/core/production-benchmark-evidence.d.ts +1 -9
- package/dist/core/production-benchmark-evidence.js +0 -22
- package/dist/core/rebuild-progress.d.ts +3 -2
- package/dist/core/rebuild-progress.js +5 -2
- package/dist/core/run-registry.d.ts +7 -28
- package/dist/core/run-registry.js +6 -51
- package/dist/core/session-retention-liveness.d.ts +0 -2
- package/dist/core/session-retention-liveness.js +0 -13
- package/dist/core/session-state.d.ts +1 -2
- package/dist/core/session-state.js +2 -3
- package/dist/core/settings-spec.d.ts +19 -60
- package/dist/core/settings-spec.js +30 -60
- package/dist/core/status-format.d.ts +0 -14
- package/dist/core/status-format.js +2 -24
- package/dist/core/types/agent-types.d.ts +26 -9
- package/dist/core/types/benchmark-types.d.ts +17 -0
- package/dist/core/types/environment-types.d.ts +64 -0
- package/dist/core/types/environment-types.js +1 -0
- package/dist/core/utils.d.ts +14 -4
- package/dist/core/utils.js +32 -6
- package/dist/domain/agents/agent-switch.js +2 -4
- package/dist/domain/agents/config.js +1 -1
- package/dist/domain/agents/environments/entities.d.ts +49 -0
- package/dist/domain/agents/environments/entities.js +94 -0
- package/dist/domain/agents/environments/file-refs.d.ts +19 -0
- package/dist/domain/agents/environments/file-refs.js +48 -0
- package/dist/domain/agents/environments/index.d.ts +6 -0
- package/dist/domain/agents/environments/index.js +8 -0
- package/dist/domain/agents/environments/paths.d.ts +7 -0
- package/dist/domain/agents/environments/paths.js +9 -0
- package/dist/domain/{threads/template-resolver.js → agents/environments/prompt-includes.js} +2 -2
- package/dist/domain/agents/environments/registry.d.ts +17 -0
- package/dist/domain/agents/environments/registry.js +159 -0
- package/dist/domain/agents/environments/schema.d.ts +68 -0
- package/dist/domain/agents/environments/schema.js +111 -0
- package/dist/domain/agents/environments/schema.parity.d.ts +1 -0
- package/dist/domain/agents/environments/schema.parity.js +7 -0
- package/dist/domain/agents/environments/slot-config.d.ts +14 -0
- package/dist/domain/agents/environments/slot-config.js +78 -0
- package/dist/domain/agents/model-selection.d.ts +3 -0
- package/dist/domain/agents/model-selection.js +1 -1
- package/dist/domain/agents/subagent/runner.js +3 -2
- package/dist/domain/benchmark/accounting-reconciliation.d.ts +1 -1
- package/dist/domain/benchmark/atif.d.ts +4 -4
- package/dist/domain/benchmark/atif.js +7 -7
- package/dist/domain/benchmark/attempt-record.d.ts +16 -55
- package/dist/domain/benchmark/attempt-record.js +3 -17
- package/dist/domain/benchmark/composite-manifest.d.ts +4 -4
- package/dist/domain/benchmark/composite-manifest.js +5 -11
- package/dist/domain/benchmark/journal.d.ts +6 -4
- package/dist/domain/benchmark/journal.js +6 -4
- package/dist/domain/benchmark/manifest-contract.d.ts +1 -1
- package/dist/domain/benchmark/production-attempt-identity.d.ts +11 -16
- package/dist/domain/benchmark/production-attempt-identity.js +31 -94
- package/dist/domain/benchmark/production-attempt-journal.js +14 -7
- package/dist/domain/benchmark/production-evidence-journal.js +8 -6
- package/dist/domain/benchmark/production-evidence-projection.d.ts +1 -11
- package/dist/domain/benchmark/production-evidence-projection.js +32 -143
- package/dist/domain/benchmark/session-evidence.d.ts +6 -0
- package/dist/domain/benchmark/session-evidence.js +27 -0
- package/dist/domain/costs/cost-tracker.d.ts +1 -7
- package/dist/domain/costs/cost-tracker.js +0 -4
- package/dist/domain/costs/resume-registry.d.ts +9 -20
- package/dist/domain/costs/resume-registry.js +24 -39
- package/dist/domain/executions/registry.d.ts +3 -18
- package/dist/domain/executions/registry.js +4 -158
- package/dist/domain/mcp/bundled-server.js +20 -27
- package/dist/domain/mcp/tools/commission-tools.js +0 -1
- package/dist/domain/mcp/tools/context.d.ts +2 -9
- package/dist/domain/mcp/tools/context.js +2 -7
- package/dist/domain/mcp/tools/executions.js +6 -19
- package/dist/domain/mcp/tools/interaction-ask.js +0 -1
- package/dist/domain/mcp/tools/interaction-plan.d.ts +0 -1
- package/dist/domain/mcp/tools/interaction-plan.js +0 -2
- package/dist/domain/mcp/tools/{task-ops.d.ts → remote-ops.d.ts} +1 -1
- package/dist/domain/mcp/tools/{task-ops.js → remote-ops.js} +1 -1
- package/dist/domain/mcp/tools/schedule.d.ts +3 -3
- package/dist/domain/mcp/tools/schedule.js +10 -32
- package/dist/domain/mcp/tools/subagent.d.ts +4 -0
- package/dist/domain/mcp/tools/subagent.js +10 -8
- package/dist/domain/mcp/tools/ui-view.js +3 -2
- package/dist/domain/mcp/tools/waitpoint.js +2 -3
- package/dist/domain/mcp/tools/{thread-ops.d.ts → workers.d.ts} +1 -1
- package/dist/domain/mcp/tools/workers.js +84 -0
- package/dist/domain/memory/user-context.d.ts +2 -3
- package/dist/domain/memory/user-context.js +2 -3
- package/dist/domain/monitor/gpu-monitor.js +1 -1
- package/dist/domain/pi-providers/custom-provider-model.d.ts +1 -1
- package/dist/domain/projects/project-store.d.ts +1 -2
- package/dist/domain/projects/project-store.js +1 -9
- package/dist/domain/remote/client-manager.d.ts +1 -1
- package/dist/domain/remote/client-manager.js +1 -1
- package/dist/domain/remote/client-remove.d.ts +1 -1
- package/dist/domain/remote/machine-registry.d.ts +54 -0
- package/dist/domain/{tasks/dispatch-utils.js → remote/machine-registry.js} +1 -61
- package/dist/domain/runs/attempt.js +3 -8
- package/dist/domain/runs/builders.d.ts +2 -3
- package/dist/domain/runs/builders.js +2 -3
- package/dist/domain/runs/engine-spec.js +3 -10
- package/dist/domain/runs/fallback.d.ts +1 -3
- package/dist/domain/runs/fallback.js +1 -3
- package/dist/domain/runs/observers/resume-recorder.d.ts +0 -15
- package/dist/domain/runs/observers/resume-recorder.js +0 -17
- package/dist/domain/runs/prompt.d.ts +23 -8
- package/dist/domain/runs/prompt.js +31 -5
- package/dist/domain/runs/request.d.ts +6 -15
- package/dist/domain/runs/run.js +0 -2
- package/dist/domain/runs/service.js +0 -2
- package/dist/domain/runs/spec-loader.d.ts +4 -6
- package/dist/domain/runs/spec-loader.js +3 -5
- package/dist/domain/scheduling/builtin-job-migration.js +3 -3
- package/dist/domain/scheduling/builtin-jobs.js +0 -13
- package/dist/domain/scheduling/job-registry.d.ts +12 -27
- package/dist/domain/scheduling/job-registry.js +2 -3
- package/dist/domain/scheduling/jobs/scheduled-task.d.ts +18 -6
- package/dist/domain/scheduling/jobs/scheduled-task.js +66 -125
- package/dist/domain/scheduling/run-guards.d.ts +6 -0
- package/dist/domain/scheduling/run-guards.js +18 -0
- package/dist/domain/scheduling/runner.d.ts +0 -1
- package/dist/domain/scheduling/runner.js +0 -1
- package/dist/domain/scheduling/schedule-cli.js +1 -1
- package/dist/domain/scheduling/scheduler.d.ts +0 -4
- package/dist/domain/scheduling/scheduler.js +2 -6
- package/dist/domain/sessions/session-hooks.d.ts +2 -2
- package/dist/domain/sessions/session-lifecycle.d.ts +23 -9
- package/dist/domain/sessions/session-lifecycle.js +27 -15
- package/dist/domain/sessions/session-retention.d.ts +8 -0
- package/dist/domain/sessions/session-retention.js +139 -34
- package/dist/domain/sessions/team.d.ts +18 -0
- package/dist/domain/sessions/team.js +21 -0
- package/dist/domain/system/install-cli.js +5 -5
- package/dist/domain/system/rebuild-hold.d.ts +1 -1
- package/dist/domain/system/server-update-check.js +2 -1
- package/dist/domain/ui-service/app-router.d.ts +41 -154
- package/dist/domain/ui-service/app-router.js +9 -30
- package/dist/domain/ui-service/input-schemas.d.ts +64 -205
- package/dist/domain/ui-service/input-schemas.js +26 -71
- package/dist/domain/ui-service/mutate/environments.d.ts +23 -0
- package/dist/domain/ui-service/mutate/environments.js +51 -0
- package/dist/domain/ui-service/mutate/plugin-packages.js +3 -9
- package/dist/domain/ui-service/mutate/plugins.js +7 -109
- package/dist/domain/ui-service/mutate/schedules.js +1 -2
- package/dist/domain/ui-service/plugins-shared.d.ts +0 -3
- package/dist/domain/ui-service/plugins-shared.js +0 -14
- package/dist/domain/ui-service/query/config.js +10 -13
- package/dist/domain/ui-service/query/environments.d.ts +12 -0
- package/dist/domain/ui-service/query/environments.js +72 -0
- package/dist/domain/ui-service/query/executions.js +1 -1
- package/dist/domain/ui-service/query/hooks.d.ts +1 -1
- package/dist/domain/ui-service/query/hooks.js +13 -24
- package/dist/domain/ui-service/query/memory.js +1 -1
- package/dist/domain/ui-service/query/plugins.js +6 -82
- package/dist/domain/ui-service/query/schedules.js +0 -1
- package/dist/domain/ui-service/query/sessions.js +23 -5
- package/dist/domain/ui-service/query/system.js +0 -1
- package/dist/domain/ui-service/query-input-schemas.d.ts +5 -26
- package/dist/domain/ui-service/query-input-schemas.js +0 -18
- package/dist/domain/ui-service/types.d.ts +68 -330
- package/dist/domain/ui-service/ui-service.js +7 -23
- package/dist/domain/waitpoints/notices.d.ts +1 -1
- package/dist/domain/waitpoints/notices.js +1 -1
- package/dist/entry/app.js +70 -146
- package/dist/entry/cli-help.js +0 -1
- package/dist/entry/cli.js +1 -6
- package/dist/entry/daemon.d.ts +27 -23
- package/dist/entry/daemon.js +61 -49
- package/dist/entry/fast-install.d.ts +13 -2
- package/dist/entry/fast-install.js +43 -11
- package/dist/entry/hook-cli.d.ts +0 -1
- package/dist/entry/hook-cli.js +20 -49
- package/dist/entry/init.js +8 -11
- package/dist/entry/local-ui.d.ts +1 -1
- package/dist/entry/platform-connect.d.ts +23 -0
- package/dist/entry/platform-connect.js +94 -0
- package/dist/entry/production-evidence-export-cli.js +0 -2
- package/dist/events/event-logger.js +1 -0
- package/dist/events/event-types.d.ts +13 -62
- package/dist/hooks/cortex-hook-api.mjs +1 -3
- package/dist/hooks/new-session-hook.mjs +2 -3
- package/dist/hooks/status-md-guard.mjs +5 -5
- package/dist/orchestration/agent-runner.d.ts +3 -0
- package/dist/orchestration/agent-runner.js +21 -19
- package/dist/orchestration/agent-view-send.d.ts +7 -0
- package/dist/orchestration/agent-view-send.js +12 -0
- package/dist/orchestration/benchmark-session-webhook.d.ts +19 -0
- package/dist/orchestration/benchmark-session-webhook.js +130 -0
- package/dist/orchestration/conversation-request.d.ts +39 -1
- package/dist/orchestration/conversation-request.js +71 -15
- package/dist/orchestration/interactions/answer-question.d.ts +16 -0
- package/dist/orchestration/interactions/answer-question.js +38 -0
- package/dist/orchestration/interactions/ask-user-question.d.ts +2 -3
- package/dist/orchestration/interactions/ask-user-question.js +1 -3
- package/dist/orchestration/interactions/ask-user-resume.d.ts +1 -3
- package/dist/orchestration/interactions/ask-user-resume.js +2 -14
- package/dist/orchestration/interactions/interaction-handlers.js +6 -35
- package/dist/orchestration/interactions/plan-response.d.ts +2 -1
- package/dist/orchestration/interactions/plan-response.js +2 -2
- package/dist/orchestration/orchestrator.d.ts +1 -7
- package/dist/orchestration/orchestrator.js +2 -11
- package/dist/orchestration/resume-dispatcher.d.ts +0 -22
- package/dist/orchestration/resume-dispatcher.js +8 -72
- package/dist/orchestration/routing/commands/cancel.d.ts +1 -7
- package/dist/orchestration/routing/commands/cancel.js +17 -37
- package/dist/orchestration/routing/commands/channel.js +1 -1
- package/dist/orchestration/routing/commands/device.js +1 -1
- package/dist/orchestration/routing/commands/index.d.ts +0 -7
- package/dist/orchestration/routing/commands/index.js +1 -9
- package/dist/orchestration/routing/commands/mode.js +7 -7
- package/dist/orchestration/routing/commands/nvtop.js +1 -1
- package/dist/orchestration/routing/commands/sendfile.js +1 -1
- package/dist/orchestration/routing/commands/status.js +8 -14
- package/dist/orchestration/routing/hook-bridge-subscribers.d.ts +4 -1
- package/dist/orchestration/routing/hook-bridge-subscribers.js +19 -12
- package/dist/orchestration/routing/hook-bridge.d.ts +3 -3
- package/dist/orchestration/routing/hook-bridge.js +9 -9
- package/dist/orchestration/routing/message-router.js +2 -25
- package/dist/orchestration/routing/webhook.js +24 -350
- package/dist/orchestration/session-events.d.ts +13 -0
- package/dist/orchestration/session-events.js +8 -0
- package/dist/orchestration/session-gateway.d.ts +4 -2
- package/dist/orchestration/session-gateway.js +17 -12
- package/dist/orchestration/session-retention-controller.d.ts +5 -2
- package/dist/orchestration/session-retention-controller.js +7 -4
- package/dist/orchestration/status-helpers.d.ts +1 -4
- package/dist/orchestration/status-helpers.js +3 -5
- package/dist/orchestration/team-delivery.d.ts +64 -0
- package/dist/orchestration/team-delivery.js +224 -0
- package/dist/orchestration/team-state.d.ts +48 -0
- package/dist/orchestration/team-state.js +146 -0
- package/dist/orchestration/team-webhook.d.ts +48 -0
- package/dist/orchestration/team-webhook.js +295 -0
- package/dist/orchestration/transcript-sink.d.ts +18 -4
- package/dist/orchestration/transcript-sink.js +31 -3
- package/dist/orchestration/turn/background-hold.d.ts +2 -2
- package/dist/orchestration/turn/background-hold.js +1 -1
- package/dist/orchestration/turn/hold-render-platform.d.ts +2 -2
- package/dist/orchestration/turn/hold-render-platform.js +2 -2
- package/dist/orchestration/turn/hold-render-web.d.ts +3 -3
- package/dist/orchestration/turn/hold-render-web.js +2 -2
- package/dist/orchestration/turn/terminal.d.ts +5 -2
- package/dist/orchestration/turn/terminal.js +11 -10
- package/dist/orchestration/turn/turn.d.ts +13 -1
- package/dist/orchestration/turn/turn.js +58 -15
- package/dist/platform/adapters/composite-adapter.d.ts +2 -0
- package/dist/platform/adapters/composite-adapter.js +7 -4
- package/dist/platform/adapters/feishu.d.ts +6 -0
- package/dist/platform/adapters/feishu.js +50 -4
- package/dist/platform/index.d.ts +1 -1
- package/dist/platform/index.js +1 -1
- package/dist/platform/tui/protocol.d.ts +2 -2
- package/dist/platform/types.d.ts +3 -3
- package/dist/platform/types.js +3 -3
- package/dist/store/conversation-history-reader.js +17 -3
- package/dist/store/conversation-history-repo.d.ts +18 -4
- package/dist/store/conversation-history-repo.js +14 -5
- package/dist/store/conversation-ledger-repo.js +1 -16
- package/dist/store/execution-repo.d.ts +17 -40
- package/dist/store/execution-repo.js +46 -116
- package/dist/store/hook-registry.d.ts +4 -16
- package/dist/store/hook-registry.js +5 -65
- package/dist/store/plugin-sync.js +4 -0
- package/dist/store/profile-repo.js +1 -1
- package/dist/store/prompt-migration-replacements.d.ts +0 -1
- package/dist/store/prompt-migration-replacements.js +0 -49
- package/dist/store/retention-candidate-repo.d.ts +2 -0
- package/dist/store/retention-candidate-repo.js +5 -0
- package/dist/store/schedule-repo.d.ts +3 -15
- package/dist/store/schedule-repo.js +18 -4
- package/dist/store/session-registry-journal.d.ts +15 -0
- package/dist/store/session-registry-journal.js +68 -10
- package/dist/store/session-registry-repo.d.ts +13 -0
- package/dist/store/session-registry-repo.js +74 -21
- package/dist/store/session-totals.d.ts +3 -3
- package/dist/store/session-totals.js +3 -3
- package/dist/store/team-outbox-repo.d.ts +20 -0
- package/dist/store/team-outbox-repo.js +39 -0
- package/dist/store/tool-image-files.d.ts +12 -0
- package/dist/store/tool-image-files.js +40 -0
- package/dist/store/version-migrations.d.ts +31 -8
- package/dist/store/version-migrations.js +307 -87
- package/dist/store/waitpoint-repo.d.ts +0 -2
- package/dist/tui/App.js +1 -1
- package/dist/tui/components/Dashboard.js +0 -8
- package/dist/tui/components/InputBox.js +1 -7
- package/dist/tui/components/StatusLine.js +1 -1
- package/dist/tui/hooks/useDashboardData.d.ts +1 -1
- package/dist/tui/hooks/useDashboardData.js +0 -4
- package/dist/tui/hooks/useNotifications.d.ts +1 -1
- package/dist/tui/slash-commands.js +1 -4
- package/package.json +4 -5
- package/web/dist/assets/index-BU_kY1rV.js +449 -0
- package/web/dist/assets/{index-zvUjPRjt.js → index-CDjsmgsy.js} +1 -1
- package/web/dist/assets/index-DzPDbcY1.css +1 -0
- package/web/dist/index.html +2 -2
- package/defaults/config/hooks/02-tasks-yaml-guard.json +0 -11
- package/defaults/config/hooks/11-task-status-check.json +0 -14
- package/defaults/config/thread-templates/agents/coder-reviewer.json +0 -17
- package/defaults/config/thread-templates/agents/coder.json +0 -17
- package/defaults/config/thread-templates/agents/direct-review.json +0 -14
- package/defaults/config/thread-templates/agents/direct-web.json +0 -14
- package/defaults/config/thread-templates/agents/director.json +0 -11
- package/defaults/config/thread-templates/agents/doc-reviewer.json +0 -13
- package/defaults/config/thread-templates/agents/doc-writer.json +0 -24
- package/defaults/config/thread-templates/agents/executor-reviewer.json +0 -13
- package/defaults/config/thread-templates/agents/executor.json +0 -24
- package/defaults/config/thread-templates/agents/main.json +0 -14
- package/defaults/config/thread-templates/agents/manager.json +0 -14
- package/defaults/config/thread-templates/agents/scheduler-main.json +0 -13
- package/defaults/config/thread-templates/shells/worker-review.json +0 -12
- package/defaults/config/thread-templates/templates/coder-review.json +0 -20
- package/defaults/config/thread-templates/templates/default.json +0 -10
- package/defaults/config/thread-templates/templates/doc-review.json +0 -6
- package/defaults/config/thread-templates/templates/execute-review.json +0 -6
- package/defaults/config/thread-templates/templates/manager.json +0 -11
- package/defaults/config/thread-templates/templates/scheduler.json +0 -10
- package/defaults/hooks/task-status-check.mjs +0 -166
- package/defaults/hooks/tasks-yaml-guard.mjs +0 -225
- package/defaults/plugins/cortex-system/skills/task/SKILL.md +0 -547
- package/defaults/plugins/cortex-system/skills/thread/SKILL.md +0 -505
- package/defaults/prompts/directives/coder-reviewer.md +0 -7
- package/defaults/prompts/directives/coder.md +0 -7
- package/defaults/prompts/directives/director.md +0 -7
- package/defaults/prompts/directives/doc-reviewer.md +0 -6
- package/defaults/prompts/directives/doc-writer.md +0 -7
- package/defaults/prompts/directives/executor-reviewer.md +0 -6
- package/defaults/prompts/directives/executor.md +0 -7
- package/defaults/prompts/directives/manager.md +0 -24
- package/defaults/prompts/systemPrompts/coder.md +0 -10
- package/defaults/prompts/systemPrompts/worker.md +0 -10
- package/defaults/rules/task-system.md +0 -53
- package/dist/core/task-node.d.ts +0 -7
- package/dist/core/task-node.js +0 -21
- package/dist/core/task-parser.d.ts +0 -86
- package/dist/core/task-parser.js +0 -436
- package/dist/core/types/thread-types.d.ts +0 -506
- package/dist/domain/benchmark/production-evidence-topology.d.ts +0 -14
- package/dist/domain/benchmark/production-evidence-topology.js +0 -257
- package/dist/domain/mcp/tools/manager-qa.d.ts +0 -4
- package/dist/domain/mcp/tools/manager-qa.js +0 -63
- package/dist/domain/mcp/tools/task-monitor.d.ts +0 -3
- package/dist/domain/mcp/tools/task-monitor.js +0 -92
- package/dist/domain/mcp/tools/thread-ops.js +0 -73
- package/dist/domain/scheduling/jobs/register-thread-session.d.ts +0 -15
- package/dist/domain/scheduling/jobs/register-thread-session.js +0 -32
- package/dist/domain/scheduling/jobs/target-dispatch.d.ts +0 -30
- package/dist/domain/scheduling/jobs/target-dispatch.js +0 -33
- package/dist/domain/scheduling/jobs/task-archive.d.ts +0 -2
- package/dist/domain/scheduling/jobs/task-archive.js +0 -16
- package/dist/domain/scheduling/jobs/task-dispatch.d.ts +0 -12
- package/dist/domain/scheduling/jobs/task-dispatch.js +0 -402
- package/dist/domain/tasks/acceptance-ledger.d.ts +0 -39
- package/dist/domain/tasks/acceptance-ledger.js +0 -133
- package/dist/domain/tasks/archiver.d.ts +0 -10
- package/dist/domain/tasks/archiver.js +0 -133
- package/dist/domain/tasks/claim-recovery.d.ts +0 -9
- package/dist/domain/tasks/claim-recovery.js +0 -54
- package/dist/domain/tasks/dispatch-utils.d.ts +0 -117
- package/dist/domain/tasks/dispatcher.d.ts +0 -49
- package/dist/domain/tasks/dispatcher.js +0 -305
- package/dist/domain/tasks/lint.d.ts +0 -12
- package/dist/domain/tasks/lint.js +0 -130
- package/dist/domain/tasks/mutator.d.ts +0 -39
- package/dist/domain/tasks/mutator.js +0 -176
- package/dist/domain/tasks/production-topology-ledger.d.ts +0 -106
- package/dist/domain/tasks/production-topology-ledger.js +0 -161
- package/dist/domain/tasks/system/task-cli.d.ts +0 -7
- package/dist/domain/tasks/system/task-cli.js +0 -991
- package/dist/domain/tasks/system/task-completion.d.ts +0 -44
- package/dist/domain/tasks/system/task-completion.js +0 -262
- package/dist/domain/tasks/system/task-file-input.d.ts +0 -10
- package/dist/domain/tasks/system/task-file-input.js +0 -53
- package/dist/domain/tasks/system/task-id-utils.d.ts +0 -24
- package/dist/domain/tasks/system/task-id-utils.js +0 -90
- package/dist/domain/tasks/system/task-lifecycle-edit.d.ts +0 -40
- package/dist/domain/tasks/system/task-lifecycle-edit.js +0 -419
- package/dist/domain/tasks/system/task-lock.d.ts +0 -44
- package/dist/domain/tasks/system/task-lock.js +0 -137
- package/dist/domain/tasks/system/task-mutations.d.ts +0 -86
- package/dist/domain/tasks/system/task-mutations.js +0 -336
- package/dist/domain/tasks/system/task-state.d.ts +0 -140
- package/dist/domain/tasks/system/task-state.js +0 -287
- package/dist/domain/threads/artifact-io.d.ts +0 -4
- package/dist/domain/threads/artifact-io.js +0 -57
- package/dist/domain/threads/contract.d.ts +0 -17
- package/dist/domain/threads/contract.js +0 -54
- package/dist/domain/threads/evidence-context.d.ts +0 -2
- package/dist/domain/threads/evidence-context.js +0 -40
- package/dist/domain/threads/hook-runner.d.ts +0 -7
- package/dist/domain/threads/hook-runner.js +0 -237
- package/dist/domain/threads/index.d.ts +0 -7
- package/dist/domain/threads/index.js +0 -13
- package/dist/domain/threads/pending-user-inputs.d.ts +0 -3
- package/dist/domain/threads/pending-user-inputs.js +0 -33
- package/dist/domain/threads/prompt-builder.d.ts +0 -55
- package/dist/domain/threads/prompt-builder.js +0 -245
- package/dist/domain/threads/runner.d.ts +0 -150
- package/dist/domain/threads/runner.js +0 -832
- package/dist/domain/threads/shell-templates.d.ts +0 -9
- package/dist/domain/threads/shell-templates.js +0 -108
- package/dist/domain/threads/state-machine.d.ts +0 -96
- package/dist/domain/threads/state-machine.js +0 -646
- package/dist/domain/threads/template-loader.d.ts +0 -37
- package/dist/domain/threads/template-loader.js +0 -487
- package/dist/domain/threads/template-validate.d.ts +0 -287
- package/dist/domain/threads/template-validate.js +0 -575
- package/dist/domain/threads/template-validate.parity.d.ts +0 -1
- package/dist/domain/threads/template-validate.parity.js +0 -39
- package/dist/domain/threads/template-writer.d.ts +0 -57
- package/dist/domain/threads/template-writer.js +0 -126
- package/dist/domain/threads/thread-transcript.d.ts +0 -60
- package/dist/domain/threads/thread-transcript.js +0 -117
- package/dist/domain/threads/tree.d.ts +0 -46
- package/dist/domain/threads/tree.js +0 -196
- package/dist/domain/threads/utils.d.ts +0 -24
- package/dist/domain/threads/utils.js +0 -55
- package/dist/domain/ui-service/mutate/tasks.d.ts +0 -23
- package/dist/domain/ui-service/mutate/tasks.js +0 -58
- package/dist/domain/ui-service/mutate/thread-templates.d.ts +0 -4
- package/dist/domain/ui-service/mutate/thread-templates.js +0 -46
- package/dist/domain/ui-service/mutate/threads.d.ts +0 -4
- package/dist/domain/ui-service/mutate/threads.js +0 -19
- package/dist/domain/ui-service/query/task-verification.d.ts +0 -2
- package/dist/domain/ui-service/query/task-verification.js +0 -58
- package/dist/domain/ui-service/query/tasks.d.ts +0 -3
- package/dist/domain/ui-service/query/tasks.js +0 -73
- package/dist/domain/ui-service/query/thread-template-detail.d.ts +0 -2
- package/dist/domain/ui-service/query/thread-template-detail.js +0 -57
- package/dist/domain/ui-service/query/thread-templates.d.ts +0 -15
- package/dist/domain/ui-service/query/thread-templates.js +0 -79
- package/dist/domain/ui-service/query/threads.d.ts +0 -3
- package/dist/domain/ui-service/query/threads.js +0 -180
- package/dist/hooks/task-status-check.mjs +0 -166
- package/dist/hooks/tasks-yaml-guard.mjs +0 -225
- package/dist/orchestration/dispatch-reconciler.d.ts +0 -1
- package/dist/orchestration/dispatch-reconciler.js +0 -19
- package/dist/orchestration/human-answer-backstop.d.ts +0 -36
- package/dist/orchestration/human-answer-backstop.js +0 -69
- package/dist/orchestration/manager-qa.d.ts +0 -66
- package/dist/orchestration/manager-qa.js +0 -356
- package/dist/orchestration/routing/commands/dispatch.d.ts +0 -2
- package/dist/orchestration/routing/commands/dispatch.js +0 -48
- package/dist/orchestration/routing/commands/task.d.ts +0 -4
- package/dist/orchestration/routing/commands/task.js +0 -140
- package/dist/orchestration/routing/commands/thread-handlers.d.ts +0 -2
- package/dist/orchestration/routing/commands/thread-handlers.js +0 -152
- package/dist/orchestration/thread-callback.d.ts +0 -107
- package/dist/orchestration/thread-callback.js +0 -555
- package/dist/orchestration/thread-delivery.d.ts +0 -40
- package/dist/orchestration/thread-delivery.js +0 -76
- package/dist/orchestration/thread-executor.d.ts +0 -25
- package/dist/orchestration/thread-executor.js +0 -180
- package/dist/orchestration/thread-input.d.ts +0 -15
- package/dist/orchestration/thread-input.js +0 -50
- package/dist/orchestration/thread-notices.d.ts +0 -43
- package/dist/orchestration/thread-notices.js +0 -195
- package/dist/orchestration/thread-run/index.d.ts +0 -3
- package/dist/orchestration/thread-run/index.js +0 -2
- package/dist/orchestration/thread-run/render-summary.d.ts +0 -57
- package/dist/orchestration/thread-run/render-summary.js +0 -109
- package/dist/orchestration/thread-run/render-task.d.ts +0 -94
- package/dist/orchestration/thread-run/render-task.js +0 -154
- package/dist/orchestration/thread-run/settle.d.ts +0 -11
- package/dist/orchestration/thread-run/settle.js +0 -18
- package/dist/orchestration/thread-run/thread-run.d.ts +0 -114
- package/dist/orchestration/thread-run/thread-run.js +0 -181
- package/dist/orchestration/thread-run/thread-surface.d.ts +0 -41
- package/dist/orchestration/thread-run/thread-surface.js +0 -23
- package/dist/orchestration/thread-run/verdict.d.ts +0 -11
- package/dist/orchestration/thread-run/verdict.js +0 -20
- package/dist/store/plugin-retirement.d.ts +0 -37
- package/dist/store/plugin-retirement.js +0 -144
- package/dist/store/task-repo.d.ts +0 -43
- package/dist/store/task-repo.js +0 -143
- package/dist/store/thread-repo.d.ts +0 -65
- package/dist/store/thread-repo.js +0 -294
- package/dist/tui/components/DashboardTasksTab.d.ts +0 -12
- package/dist/tui/components/DashboardTasksTab.js +0 -196
- package/dist/tui/components/DashboardThreadsTab.d.ts +0 -11
- package/dist/tui/components/DashboardThreadsTab.js +0 -96
- package/web/dist/assets/index-C9sEss8T.css +0 -1
- package/web/dist/assets/index-fVf_wSMQ.js +0 -447
- /package/defaults/config/{thread-templates/agents → environments}/creative.json +0 -0
- /package/dist/core/types/{thread-types.js → benchmark-types.js} +0 -0
- /package/dist/domain/{threads/template-resolver.d.ts → agents/environments/prompt-includes.d.ts} +0 -0
|
@@ -24,51 +24,6 @@ export const CODER_COMMIT_POLICY_REPLACEMENTS = [
|
|
|
24
24
|
`- Git commit messages: concise and describe what was implemented. ${CODER_COMMIT_POLICY} No decorative language.`,
|
|
25
25
|
],
|
|
26
26
|
];
|
|
27
|
-
export const MANAGER_TASK_FILE_REPLACEMENTS = [
|
|
28
|
-
[
|
|
29
|
-
'3. **Decompose via /manager-method** — the method (map the seams before cutting, the Cut-at-the-Seam Iron Rules, one-criterion-one-task with explicit dependencies, template selection by residual reasoning, and the per-child self-audit quality gate) lives in the skill (pointer below). After the method yields your children, create them in ONE call (exact recipe — write the JSON to a temp file first):',
|
|
30
|
-
'3. **Decompose via /manager-method** — the method (map the seams before cutting, the Cut-at-the-Seam Iron Rules, one-criterion-one-task with explicit dependencies, template selection by residual reasoning, and the per-child self-audit quality gate) lives in the skill (pointer below). After the method yields your children, create them in ONE call. Use the Write tool—not shell redirection—to create `/tmp/subtasks-<your Task ID>.json` with this content:',
|
|
31
|
-
],
|
|
32
|
-
[
|
|
33
|
-
[
|
|
34
|
-
' ```bash',
|
|
35
|
-
" cat > /tmp/subtasks-<your Task ID>.json <<'JSON'",
|
|
36
|
-
' {"subtasks": [',
|
|
37
|
-
' {"key": "a", "text": "Create X", "done-when": "X exists and ...", "template": "execute-review"},',
|
|
38
|
-
' {"key": "b", "text": "Create Y", "done-when": "...", "template": "execute-review", "depends-on": ["a"]}',
|
|
39
|
-
' ]}',
|
|
40
|
-
' JSON',
|
|
41
|
-
' cortex-task decompose --project <project> --task-id <your Task ID> --keep-parent --auto-lock --subtasks-file /tmp/subtasks-<your Task ID>.json',
|
|
42
|
-
' ```',
|
|
43
|
-
].join('\n'),
|
|
44
|
-
[
|
|
45
|
-
' ```json',
|
|
46
|
-
' [',
|
|
47
|
-
' {"key": "a", "text": "Create X", "done-when": "X exists and ...", "template": "execute-review"},',
|
|
48
|
-
' {"key": "b", "text": "Create Y", "done-when": "...", "template": "execute-review", "depends-on": ["a"]}',
|
|
49
|
-
' ]',
|
|
50
|
-
' ```',
|
|
51
|
-
'',
|
|
52
|
-
' Then run `cortex-task decompose --project <project> --task-id <your Task ID> --keep-parent --auto-lock --subtasks-file /tmp/subtasks-<your Task ID>.json`.',
|
|
53
|
-
].join('\n'),
|
|
54
|
-
],
|
|
55
|
-
[
|
|
56
|
-
'1. Read the actual deliverable (code, files, experiment records) and check it against the child\'s done_when. Run tests where code is involved. Never accept a completion note as evidence. When the deliverable is substantial (files / code / a report / an experiment), prefer spawning an independent **verifier** child (`cortex-task spawn --text "Verify <deliverable> against: <done_when>" --template <review template>`) and consume only its verdict — an independent fresh-context check catches what your anchored read misses, and keeps large deliverables out of your own context.',
|
|
57
|
-
'1. Read the actual deliverable (code, files, experiment records) and check it against the child\'s done_when. Run tests where code is involved. Never accept a completion note as evidence. When the deliverable is substantial (files / code / a report / an experiment), prefer spawning an independent **verifier** child: use the Write tool to stage its task JSON at `/tmp/cortex-task-<your Task ID>-<child-id>.json`, run `cortex-task spawn --task-file /tmp/cortex-task-<your Task ID>-<child-id>.json`, and consume only its verdict. An independent fresh-context check catches what your anchored read misses and keeps large deliverables out of your own context.',
|
|
58
|
-
],
|
|
59
|
-
[
|
|
60
|
-
'- For a quick sub-call that doesn\'t merit a full decomposition (an independent verifier pass on a child\'s deliverable, a short research probe before deciding a split), create a single child with `cortex-task spawn --text "..." --template <name>` (it hangs under you and joins via `depends_on`, like decompose) and then call `thread_wait`. It flows through the dispatch queue like any child — there is no in-process thread spawn (`thread_start` was removed; tasks are the only delegation primitive).',
|
|
61
|
-
'- For a quick sub-call that doesn\'t merit a full decomposition (an independent verifier pass on a child\'s deliverable, a short research probe before deciding a split), use the Write tool to stage one child task JSON at `/tmp/cortex-task-<your Task ID>-<unique-id>.json`, run `cortex-task spawn --task-file /tmp/cortex-task-<your Task ID>-<unique-id>.json` (it hangs under you and joins via `depends_on`, like decompose), and then call `thread_wait`. It flows through the dispatch queue like any child — there is no in-process thread spawn (`thread_start` was removed; tasks are the only delegation primitive).',
|
|
62
|
-
],
|
|
63
|
-
[
|
|
64
|
-
'1. Read the actual deliverable (code, files, experiment records) and check it against the child\'s done_when. Run tests where code is involved. Never accept a completion note as evidence. When the deliverable is substantial (files / code / a report / an experiment), prefer spawning an independent **verifier** child: use the Write tool to stage its task JSON, run `cortex-task spawn --task-file <path>`, and consume only its verdict. An independent fresh-context check catches what your anchored read misses and keeps large deliverables out of your own context.',
|
|
65
|
-
'1. Read the actual deliverable (code, files, experiment records) and check it against the child\'s done_when. Run tests where code is involved. Never accept a completion note as evidence. When the deliverable is substantial (files / code / a report / an experiment), prefer spawning an independent **verifier** child: use the Write tool to stage its task JSON at `/tmp/cortex-task-<your Task ID>-<child-id>.json`, run `cortex-task spawn --task-file /tmp/cortex-task-<your Task ID>-<child-id>.json`, and consume only its verdict. An independent fresh-context check catches what your anchored read misses and keeps large deliverables out of your own context.',
|
|
66
|
-
],
|
|
67
|
-
[
|
|
68
|
-
'- For a quick sub-call that doesn\'t merit a full decomposition (an independent verifier pass on a child\'s deliverable, a short research probe before deciding a split), use the Write tool to stage one child task JSON, run `cortex-task spawn --task-file <path>` (it hangs under you and joins via `depends_on`, like decompose), and then call `thread_wait`. It flows through the dispatch queue like any child — there is no in-process thread spawn (`thread_start` was removed; tasks are the only delegation primitive).',
|
|
69
|
-
'- For a quick sub-call that doesn\'t merit a full decomposition (an independent verifier pass on a child\'s deliverable, a short research probe before deciding a split), use the Write tool to stage one child task JSON at `/tmp/cortex-task-<your Task ID>-<unique-id>.json`, run `cortex-task spawn --task-file /tmp/cortex-task-<your Task ID>-<unique-id>.json` (it hangs under you and joins via `depends_on`, like decompose), and then call `thread_wait`. It flows through the dispatch queue like any child — there is no in-process thread spawn (`thread_start` was removed; tasks are the only delegation primitive).',
|
|
70
|
-
],
|
|
71
|
-
];
|
|
72
27
|
// STATUS.md register semantics: stock prompts used to mandate unconditional
|
|
73
28
|
// STATUS.md updates and a `## Milestone Verdict` section; the register
|
|
74
29
|
// convention makes STATUS updates conditional on a situation change and moves
|
|
@@ -83,10 +38,6 @@ export const STATUS_REGISTER_REPLACEMENTS = [
|
|
|
83
38
|
"Prefer editing the existing project artifacts (STATUS.md, knowledge entries, the role's artifact file) over creating parallel new files.",
|
|
84
39
|
"Prefer editing the existing project artifacts (the role's artifact file, knowledge entries, existing experiment records) over creating parallel new files.",
|
|
85
40
|
],
|
|
86
|
-
[
|
|
87
|
-
"7. Update the project's `STATUS.md`; record durable findings in the project knowledge files.",
|
|
88
|
-
"7. Record durable findings in the project knowledge files. Update `STATUS.md` only if the delivered work changed the project's situation (unblocked something, introduced a blocker, changed the next step) — one line + pointer, not a completion report (see rules/status-md.md).",
|
|
89
|
-
],
|
|
90
41
|
[
|
|
91
42
|
'- **STATUS.md update**: append or replace a `## Milestone Verdict` section summarizing the verdict and the top 3 reasons. Include a timestamp and the milestone being judged.',
|
|
92
43
|
'- **STATUS.md update**: one pointer line in the register (replacing any previous milestone line): `Milestone <N> gate (<ISO date>): <verdict> → <artifact path>`. The verdict, reasons, and analysis live only in the artifact — do not copy them into STATUS.md.',
|
|
@@ -4,6 +4,8 @@ export declare class RetentionCandidateRepo {
|
|
|
4
4
|
constructor(filePath?: string);
|
|
5
5
|
mark(category: RetentionCandidateCategory, key: string, stamp: number): Promise<void>;
|
|
6
6
|
isConfirmed(category: RetentionCandidateCategory, key: string, stamp: number): Promise<boolean>;
|
|
7
|
+
/** Called for every scanned file, nearly all of which were never marked: check before `mutate`,
|
|
8
|
+
* which always rewrites the file. */
|
|
7
9
|
clear(category: RetentionCandidateCategory, key: string): Promise<void>;
|
|
8
10
|
flush(): Promise<void>;
|
|
9
11
|
}
|
|
@@ -24,7 +24,12 @@ export class RetentionCandidateRepo {
|
|
|
24
24
|
const data = await this.repo.read();
|
|
25
25
|
return data.categories[category]?.[key] === stamp;
|
|
26
26
|
}
|
|
27
|
+
/** Called for every scanned file, nearly all of which were never marked: check before `mutate`,
|
|
28
|
+
* which always rewrites the file. */
|
|
27
29
|
async clear(category, key) {
|
|
30
|
+
const current = await this.repo.read();
|
|
31
|
+
if (!(key in (current.categories[category] ?? {})))
|
|
32
|
+
return;
|
|
28
33
|
await this.repo.mutate((data) => {
|
|
29
34
|
const group = data.categories[category];
|
|
30
35
|
if (!group || !(key in group))
|
|
@@ -1,22 +1,15 @@
|
|
|
1
1
|
export declare const SCHEDULES_FILE: string;
|
|
2
2
|
export declare const CHANNEL_REGISTRY_FILE: string;
|
|
3
3
|
/** Where a fired scheduled-task should land. Resolved by the cortex_schedule_add MCP tool
|
|
4
|
-
* (or schedule-cli) at create time —
|
|
5
|
-
*
|
|
6
|
-
* scheduling/jobs/scheduled-task.ts. */
|
|
4
|
+
* (or schedule-cli) at create time — shorthand placeholders are concretized then, so list/get
|
|
5
|
+
* always show real IDs. Every fire opens a fresh session (scheduling/jobs/scheduled-task.ts). */
|
|
7
6
|
export type ScheduleTarget = {
|
|
8
7
|
kind: 'fresh';
|
|
9
8
|
}
|
|
10
|
-
/** Fire into the project —
|
|
9
|
+
/** Fire into the project — the fresh session is bound to that project. */
|
|
11
10
|
| {
|
|
12
11
|
kind: 'project';
|
|
13
12
|
projectId: string;
|
|
14
|
-
}
|
|
15
|
-
/** Continue a specific thread; only valid while thread.status is running|waiting. */
|
|
16
|
-
| {
|
|
17
|
-
kind: 'thread';
|
|
18
|
-
threadId: string;
|
|
19
|
-
channel: string;
|
|
20
13
|
};
|
|
21
14
|
export interface ScheduleTask {
|
|
22
15
|
id: string;
|
|
@@ -41,11 +34,6 @@ export interface ScheduleTask {
|
|
|
41
34
|
taskConfigHash?: string;
|
|
42
35
|
/** Dispatch routing — defaults to { kind: 'fresh' } for legacy records. */
|
|
43
36
|
target?: ScheduleTarget;
|
|
44
|
-
/** What to do when the target thread no longer exists at fire time.
|
|
45
|
-
* fresh: silently fall back to fresh-thread dispatch.
|
|
46
|
-
* skip: record lastSkipped, post a Slack one-liner, do not run.
|
|
47
|
-
* wait: reschedule short delay (max 3 retries), then fall back to fresh. */
|
|
48
|
-
fallback?: 'fresh' | 'skip' | 'wait';
|
|
49
37
|
}
|
|
50
38
|
export interface SchedulesData {
|
|
51
39
|
tasks: ScheduleTask[];
|
|
@@ -4,6 +4,19 @@ import { JsonRepository } from '../core/json-repository.js';
|
|
|
4
4
|
import { STORE_DIR } from '../core/paths.js';
|
|
5
5
|
export const SCHEDULES_FILE = path.join(STORE_DIR, 'schedules.json');
|
|
6
6
|
export const CHANNEL_REGISTRY_FILE = path.join(STORE_DIR, 'channel-registry.json');
|
|
7
|
+
/** A stored target this build can run, else null. Kinds that no longer exist (a thread target)
|
|
8
|
+
* and malformed records are read as null and land as a fresh session. */
|
|
9
|
+
function readTarget(raw) {
|
|
10
|
+
if (typeof raw !== 'object' || raw === null)
|
|
11
|
+
return null;
|
|
12
|
+
const target = raw;
|
|
13
|
+
if (target.kind === 'fresh')
|
|
14
|
+
return { kind: 'fresh' };
|
|
15
|
+
if (target.kind === 'project' && typeof target.projectId === 'string' && target.projectId) {
|
|
16
|
+
return { kind: 'project', projectId: target.projectId };
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
7
20
|
function defaultData() {
|
|
8
21
|
return { tasks: [] };
|
|
9
22
|
}
|
|
@@ -51,11 +64,12 @@ function makeMigrate(channelRegistryPath) {
|
|
|
51
64
|
delete t.channel;
|
|
52
65
|
}
|
|
53
66
|
}
|
|
54
|
-
// Backfill target=fresh on records persisted before
|
|
55
|
-
// so
|
|
67
|
+
// Backfill target=fresh on records persisted before targets existed, and on targets of a kind
|
|
68
|
+
// that no longer exists, so every reader sees one of the kinds above. `fallback` chose what a
|
|
69
|
+
// thread target did once its thread was gone; older records may still carry it.
|
|
56
70
|
for (const task of data.tasks) {
|
|
57
|
-
|
|
58
|
-
|
|
71
|
+
task.target = readTarget(task.target) ?? { kind: 'fresh' };
|
|
72
|
+
delete task.fallback;
|
|
59
73
|
}
|
|
60
74
|
return data;
|
|
61
75
|
};
|
|
@@ -52,6 +52,12 @@ export interface SessionRecord {
|
|
|
52
52
|
commissionBlockFor?: string | null;
|
|
53
53
|
contextUsage?: unknown;
|
|
54
54
|
browser?: SessionBrowserOption | null;
|
|
55
|
+
/** Team mode: the lead session that owns this worker. Non-null means this session is a worker. */
|
|
56
|
+
teamLeadId?: string | null;
|
|
57
|
+
/** The worker's short name, unique within its lead's team. */
|
|
58
|
+
workerName?: string | null;
|
|
59
|
+
/** Epoch ms when the worker was retired; null while active. */
|
|
60
|
+
workerRetiredAt?: number | null;
|
|
55
61
|
}
|
|
56
62
|
/** Copied VERBATIM from store/conversation-ledger-repo.ts:9-22 (B.T1). The journal owns turn history
|
|
57
63
|
* now, but must NOT import the ledger module (dependency direction). Keep this in lock-step with the
|
|
@@ -171,6 +177,8 @@ export interface SessionRegistryState {
|
|
|
171
177
|
conversations: Map<string, ConversationHeader>;
|
|
172
178
|
eventCount: number;
|
|
173
179
|
fileSize: number;
|
|
180
|
+
/** Journal size right after the last compaction (0 until one runs this process). */
|
|
181
|
+
compactedFileSize: number;
|
|
174
182
|
}
|
|
175
183
|
export interface SessionRegistryJournalOptions {
|
|
176
184
|
writeAppend?: (handle: fsp.FileHandle, line: string) => Promise<void>;
|
|
@@ -189,6 +197,13 @@ export declare function deriveSessionOrigin(kind: SessionKind, label: string | n
|
|
|
189
197
|
export declare function shouldCompactSessionRegistry(state: SessionRegistryState, options: SessionRegistryJournalOptions): boolean;
|
|
190
198
|
export declare function loadSessionRegistryState(filePath: string, options?: SessionRegistryJournalOptions): Promise<SessionRegistryState>;
|
|
191
199
|
export declare function appendSessionRegistryEvent(filePath: string, state: SessionRegistryState, event: SessionRegistryEvent, options?: SessionRegistryJournalOptions): Promise<void>;
|
|
200
|
+
/**
|
|
201
|
+
* Append several events with one write and one fsync. Every event is validated against the state
|
|
202
|
+
* before the batch, so the events must not depend on each other: a session id may appear at most
|
|
203
|
+
* once (channel-scoped events carry no precondition and may repeat). A crash mid-write leaves a
|
|
204
|
+
* prefix of whole lines plus a torn tail that the next load truncates.
|
|
205
|
+
*/
|
|
206
|
+
export declare function appendSessionRegistryEvents(filePath: string, state: SessionRegistryState, events: SessionRegistryEvent[], options?: SessionRegistryJournalOptions): Promise<void>;
|
|
192
207
|
export declare function compactSessionRegistry(filePath: string, state: SessionRegistryState, options?: SessionRegistryJournalOptions): Promise<void>;
|
|
193
208
|
/** Every key a `patch` may carry, derived from the exhaustive reader table so the WRITER (repo
|
|
194
209
|
* `diffRecord`) and the READER can never disagree: adding a field to SessionRecord without a
|
|
@@ -6,6 +6,7 @@ import { STORE_DIR } from '../core/paths.js';
|
|
|
6
6
|
const REGISTRY_VERSION = 1;
|
|
7
7
|
const DEFAULT_YIELD_EVERY = 256;
|
|
8
8
|
const MAX_FILE_BYTES = 16 * 1024 * 1024;
|
|
9
|
+
const REPLACEMENT_CHUNK_CHARS = 1024 * 1024;
|
|
9
10
|
const CHANNEL_REGISTRY_FILE = path.join(STORE_DIR, 'channel-registry.json');
|
|
10
11
|
const THREAD_LABEL_RE = /^\[[^\]]+:[^\]]+\]$/;
|
|
11
12
|
export function createSessionRegistryState() {
|
|
@@ -18,6 +19,7 @@ export function createSessionRegistryState() {
|
|
|
18
19
|
conversations: new Map(),
|
|
19
20
|
eventCount: 0,
|
|
20
21
|
fileSize: 0,
|
|
22
|
+
compactedFileSize: 0,
|
|
21
23
|
};
|
|
22
24
|
}
|
|
23
25
|
export function legacyPathFor(filePath) {
|
|
@@ -41,9 +43,19 @@ export function shouldCompactSessionRegistry(state, options) {
|
|
|
41
43
|
};
|
|
42
44
|
if (options.shouldCompact)
|
|
43
45
|
return options.shouldCompact(stats);
|
|
44
|
-
//
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
// Both limits are relative to what a compaction would write back. An absolute limit that the
|
|
47
|
+
// compacted state itself exceeds (many turns per session, or a registry over MAX_FILE_BYTES)
|
|
48
|
+
// would make every later append rewrite the whole file.
|
|
49
|
+
const threshold = Math.max(512, state.live.size * 4, materializedEventCount(state) * 2);
|
|
50
|
+
const sizeLimit = Math.max(MAX_FILE_BYTES, state.compactedFileSize * 2);
|
|
51
|
+
return state.fileSize > sizeLimit || state.eventCount > threshold;
|
|
52
|
+
}
|
|
53
|
+
/** Number of events `compactSessionRegistry` would write for this state. */
|
|
54
|
+
function materializedEventCount(state) {
|
|
55
|
+
let turns = 0;
|
|
56
|
+
for (const list of state.turns.values())
|
|
57
|
+
turns += list.length;
|
|
58
|
+
return state.live.size + state.pending.size + state.bindings.size + state.conversations.size + turns;
|
|
47
59
|
}
|
|
48
60
|
export async function loadSessionRegistryState(filePath, options = {}) {
|
|
49
61
|
await ensureJournalAuthority(filePath);
|
|
@@ -51,11 +63,31 @@ export async function loadSessionRegistryState(filePath, options = {}) {
|
|
|
51
63
|
return replaySessionRegistry(filePath, options);
|
|
52
64
|
}
|
|
53
65
|
export async function appendSessionRegistryEvent(filePath, state, event, options = {}) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
66
|
+
await appendSessionRegistryEvents(filePath, state, [event], options);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Append several events with one write and one fsync. Every event is validated against the state
|
|
70
|
+
* before the batch, so the events must not depend on each other: a session id may appear at most
|
|
71
|
+
* once (channel-scoped events carry no precondition and may repeat). A crash mid-write leaves a
|
|
72
|
+
* prefix of whole lines plus a torn tail that the next load truncates.
|
|
73
|
+
*/
|
|
74
|
+
export async function appendSessionRegistryEvents(filePath, state, events, options = {}) {
|
|
75
|
+
if (events.length === 0)
|
|
76
|
+
return;
|
|
77
|
+
const sessionIds = new Set();
|
|
78
|
+
for (const event of events) {
|
|
79
|
+
if ('id' in event) {
|
|
80
|
+
if (sessionIds.has(event.id))
|
|
81
|
+
throw new Error(`Session appears twice in one append batch: ${event.id}`);
|
|
82
|
+
sessionIds.add(event.id);
|
|
83
|
+
}
|
|
84
|
+
assertAppendableEvent(state, event);
|
|
85
|
+
}
|
|
86
|
+
const text = events.map(event => `${JSON.stringify(event)}\n`).join('');
|
|
87
|
+
const fileSize = await appendLineWithRollback(filePath, text, options.writeAppend);
|
|
88
|
+
for (const event of events)
|
|
89
|
+
applyEvent(state, event);
|
|
90
|
+
state.eventCount += events.length;
|
|
59
91
|
state.fileSize = fileSize;
|
|
60
92
|
}
|
|
61
93
|
export async function compactSessionRegistry(filePath, state, options = {}) {
|
|
@@ -63,6 +95,7 @@ export async function compactSessionRegistry(filePath, state, options = {}) {
|
|
|
63
95
|
await replaceJournalFile(filePath, events);
|
|
64
96
|
state.eventCount = events.length;
|
|
65
97
|
state.fileSize = (await fsp.stat(filePath)).size;
|
|
98
|
+
state.compactedFileSize = state.fileSize;
|
|
66
99
|
options.onCompact?.();
|
|
67
100
|
}
|
|
68
101
|
function compactedEvents(state) {
|
|
@@ -364,6 +397,9 @@ function assertSessionRecord(raw, expectedId) {
|
|
|
364
397
|
commissionBlockFor: toOptionalNullableString(row?.commissionBlockFor),
|
|
365
398
|
contextUsage: row?.contextUsage,
|
|
366
399
|
browser: toOptionalBrowserValue(row?.browser),
|
|
400
|
+
teamLeadId: toOptionalNullableString(row?.teamLeadId),
|
|
401
|
+
workerName: toOptionalNullableString(row?.workerName),
|
|
402
|
+
workerRetiredAt: toOptionalNullableNumber(row?.workerRetiredAt),
|
|
367
403
|
};
|
|
368
404
|
return assertRecordId(record, expectedId);
|
|
369
405
|
}
|
|
@@ -408,6 +444,13 @@ function toOptionalBrowserValue(value) {
|
|
|
408
444
|
throw new Error('Invalid session registry browser option');
|
|
409
445
|
return { device };
|
|
410
446
|
}
|
|
447
|
+
function toOptionalNullableNumber(value) {
|
|
448
|
+
if (value === undefined)
|
|
449
|
+
return undefined;
|
|
450
|
+
if (value === null)
|
|
451
|
+
return null;
|
|
452
|
+
return toNumberValue(value);
|
|
453
|
+
}
|
|
411
454
|
function toKindValue(value) {
|
|
412
455
|
if (value === 'local' || value === 'scheduled')
|
|
413
456
|
return value;
|
|
@@ -466,6 +509,9 @@ const PATCH_FIELD_READERS = {
|
|
|
466
509
|
commissionBlockFor: toOptionalNullableString,
|
|
467
510
|
contextUsage: value => value,
|
|
468
511
|
browser: toOptionalBrowserValue,
|
|
512
|
+
teamLeadId: toOptionalNullableString,
|
|
513
|
+
workerName: toOptionalNullableString,
|
|
514
|
+
workerRetiredAt: toOptionalNullableNumber,
|
|
469
515
|
};
|
|
470
516
|
/** Every key a `patch` may carry, derived from the exhaustive reader table so the WRITER (repo
|
|
471
517
|
* `diffRecord`) and the READER can never disagree: adding a field to SessionRecord without a
|
|
@@ -715,8 +761,20 @@ async function replaceJournalFile(filePath, events) {
|
|
|
715
761
|
async function writeReplacementFile(tmp, events) {
|
|
716
762
|
const handle = await fsp.open(tmp, 'w');
|
|
717
763
|
try {
|
|
718
|
-
|
|
719
|
-
|
|
764
|
+
let chunk = [];
|
|
765
|
+
let chunkBytes = 0;
|
|
766
|
+
for (const event of events) {
|
|
767
|
+
const line = `${JSON.stringify(event)}\n`;
|
|
768
|
+
chunk.push(line);
|
|
769
|
+
chunkBytes += line.length;
|
|
770
|
+
if (chunkBytes < REPLACEMENT_CHUNK_CHARS)
|
|
771
|
+
continue;
|
|
772
|
+
await handle.writeFile(chunk.join(''), 'utf8');
|
|
773
|
+
chunk = [];
|
|
774
|
+
chunkBytes = 0;
|
|
775
|
+
}
|
|
776
|
+
if (chunk.length)
|
|
777
|
+
await handle.writeFile(chunk.join(''), 'utf8');
|
|
720
778
|
await handle.sync();
|
|
721
779
|
}
|
|
722
780
|
finally {
|
|
@@ -33,6 +33,8 @@ export interface RegisterSessionOpts {
|
|
|
33
33
|
browser?: SessionBrowserOption | null;
|
|
34
34
|
commissionId?: string | null;
|
|
35
35
|
commissionDraft?: string | null;
|
|
36
|
+
teamLeadId?: string | null;
|
|
37
|
+
workerName?: string | null;
|
|
36
38
|
}
|
|
37
39
|
/** Mutators available inside `batch(fn)` — each shares the one locked state so several events land
|
|
38
40
|
* in a single critical section (§5). Read APIs are not exposed; read from the returned records. */
|
|
@@ -76,6 +78,8 @@ export declare class SessionRegistryRepo {
|
|
|
76
78
|
getById(sessionId: string): Promise<Session | null>;
|
|
77
79
|
listByProject(projectId: string): Promise<Session[]>;
|
|
78
80
|
listByOrigin(origin: SessionOrigin, projectId?: string): Promise<Session[]>;
|
|
81
|
+
/** Every worker owned by `leadSessionId`, retired or not. */
|
|
82
|
+
listWorkers(leadSessionId: string): Promise<Session[]>;
|
|
79
83
|
listResumable(projectId?: string): Promise<Session[]>;
|
|
80
84
|
/** Storage primitive behind use-count admission — the in-memory counter and lease semantics live
|
|
81
85
|
* in `@domain/sessions/session-use.ts`. Patches `lastUsedAt=now` iff the session is live and NOT
|
|
@@ -98,6 +102,8 @@ export declare class SessionRegistryRepo {
|
|
|
98
102
|
* `cortex_commission_start`, by the composer's "new" on a live session, and by session creation.
|
|
99
103
|
* Refuses to touch a session already bound to a commission — that is a terminal state. */
|
|
100
104
|
setCommissionDraft(sessionId: string, draftDir: string | null): Promise<Session | null>;
|
|
105
|
+
/** Retire a worker (epoch ms), or reactivate it with null. */
|
|
106
|
+
setWorkerRetired(sessionId: string, retiredAt: number | null): Promise<Session | null>;
|
|
101
107
|
/** Record that the `[Commission]` block for `key` is now in this session's backend history. */
|
|
102
108
|
markCommissionBlockDelivered(sessionId: string, key: string): Promise<Session | null>;
|
|
103
109
|
/** Forget the delivery marker so the next turn re-injects the block. Called after compaction,
|
|
@@ -114,6 +120,9 @@ export declare class SessionRegistryRepo {
|
|
|
114
120
|
/** Remove every binding pointing at one of `sessionIds`. Used when sessions are torn down.
|
|
115
121
|
* Returns the number of bindings removed. */
|
|
116
122
|
unbindBySessionIds(sessionIds: Iterable<string>): Promise<number>;
|
|
123
|
+
/** Drop the conversation header and turns of every channel whose conversation names one of
|
|
124
|
+
* `sessionIds`, in one append. Returns the number of channels cleared. */
|
|
125
|
+
clearConversationsBySessionIds(sessionIds: Iterable<string>): Promise<number>;
|
|
117
126
|
listBindings(): Promise<Array<{
|
|
118
127
|
channel: string;
|
|
119
128
|
sessionId: string;
|
|
@@ -152,6 +161,9 @@ export declare class SessionRegistryRepo {
|
|
|
152
161
|
listPendingDeletions(): Promise<PendingDeletion[]>;
|
|
153
162
|
beginDeleteExpired(cutoff: number | Date, protectedIds: Iterable<string>, prepareCleanup?: (session: Session, turns: TurnRecord[]) => Promise<SessionDeleteCleanup>): Promise<PendingDeletion[]>;
|
|
154
163
|
commitDeletion(sessionId: string): Promise<boolean>;
|
|
164
|
+
/** Commit several pending deletions with one append. Ids that are not pending are skipped;
|
|
165
|
+
* returns the ids that were committed. */
|
|
166
|
+
commitDeletions(sessionIds: Iterable<string>): Promise<string[]>;
|
|
155
167
|
compactNow(): Promise<void>;
|
|
156
168
|
/** `backend` is accepted and ignored — a channel has one session. Pure in-registry lookup:
|
|
157
169
|
* the channel's bound sessionId → the live record's name. */
|
|
@@ -165,6 +177,7 @@ export declare class SessionRegistryRepo {
|
|
|
165
177
|
private doUpdateById;
|
|
166
178
|
/** Append a `patch` for the delta between `current` (live) and `next`. No-op when nothing changed. */
|
|
167
179
|
private writePatch;
|
|
180
|
+
private appendBatch;
|
|
168
181
|
private maybeCompact;
|
|
169
182
|
}
|
|
170
183
|
export declare const sessionStore: SessionRegistryRepo;
|
|
@@ -3,7 +3,7 @@ import * as path from 'node:path';
|
|
|
3
3
|
import { isDeepStrictEqual } from 'node:util';
|
|
4
4
|
import { AsyncMutex } from '../core/async-mutex.js';
|
|
5
5
|
import { STORE_DIR } from '../core/paths.js';
|
|
6
|
-
import { appendSessionRegistryEvent, compactSessionRegistry, createSessionRegistryState, deriveSessionOrigin, loadSessionRegistryState, shouldCompactSessionRegistry, PATCH_KEYS, } from './session-registry-journal.js';
|
|
6
|
+
import { appendSessionRegistryEvent, appendSessionRegistryEvents, compactSessionRegistry, createSessionRegistryState, deriveSessionOrigin, loadSessionRegistryState, shouldCompactSessionRegistry, PATCH_KEYS, } from './session-registry-journal.js';
|
|
7
7
|
export const REGISTRY_FILE = path.join(STORE_DIR, 'session-registry.jsonl');
|
|
8
8
|
export { deriveSessionOrigin, };
|
|
9
9
|
/** Compute the minimal patch from `current` to `next`. A key present in `current` but gone from
|
|
@@ -112,6 +112,9 @@ export class SessionRegistryRepo {
|
|
|
112
112
|
browser: opts.browser ?? null,
|
|
113
113
|
commissionId: opts.commissionId ?? null,
|
|
114
114
|
commissionDraft: opts.commissionDraft ?? null,
|
|
115
|
+
...(opts.teamLeadId
|
|
116
|
+
? { teamLeadId: opts.teamLeadId, workerName: opts.workerName ?? null, workerRetiredAt: null }
|
|
117
|
+
: {}),
|
|
115
118
|
});
|
|
116
119
|
}
|
|
117
120
|
async convertToDirect(sessionId, opts) {
|
|
@@ -175,6 +178,10 @@ export class SessionRegistryRepo {
|
|
|
175
178
|
async listByOrigin(origin, projectId) {
|
|
176
179
|
return this.withState(async (state) => sortRecent(filterLive(state, s => s.origin === origin && (projectId === undefined || s.projectId === projectId))));
|
|
177
180
|
}
|
|
181
|
+
/** Every worker owned by `leadSessionId`, retired or not. */
|
|
182
|
+
async listWorkers(leadSessionId) {
|
|
183
|
+
return this.withState(async (state) => sortRecent(filterLive(state, s => s.teamLeadId === leadSessionId)));
|
|
184
|
+
}
|
|
178
185
|
async listResumable(projectId) {
|
|
179
186
|
return this.withState(async (state) => sortRecent(filterLive(state, s => s.kind !== 'scheduled' && (projectId === undefined || s.projectId === projectId))));
|
|
180
187
|
}
|
|
@@ -229,6 +236,10 @@ export class SessionRegistryRepo {
|
|
|
229
236
|
? record
|
|
230
237
|
: { ...record, commissionDraft: draftDir }));
|
|
231
238
|
}
|
|
239
|
+
/** Retire a worker (epoch ms), or reactivate it with null. */
|
|
240
|
+
async setWorkerRetired(sessionId, retiredAt) {
|
|
241
|
+
return this.updateById(sessionId, (record) => ({ ...record, workerRetiredAt: retiredAt }));
|
|
242
|
+
}
|
|
232
243
|
/** Record that the `[Commission]` block for `key` is now in this session's backend history. */
|
|
233
244
|
async markCommissionBlockDelivered(sessionId, key) {
|
|
234
245
|
return this.updateById(sessionId, (record) => ({ ...record, commissionBlockFor: key }));
|
|
@@ -273,8 +284,24 @@ export class SessionRegistryRepo {
|
|
|
273
284
|
const channels = Array.from(state.bindings)
|
|
274
285
|
.filter(([, boundId]) => targets.has(boundId))
|
|
275
286
|
.map(([channel]) => channel);
|
|
276
|
-
|
|
277
|
-
|
|
287
|
+
await this.appendBatch(state, channels.map((channel) => ({ v: 1, op: 'unbind', channel })));
|
|
288
|
+
return channels.length;
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
/** Drop the conversation header and turns of every channel whose conversation names one of
|
|
292
|
+
* `sessionIds`, in one append. Returns the number of channels cleared. */
|
|
293
|
+
async clearConversationsBySessionIds(sessionIds) {
|
|
294
|
+
const targets = new Set(sessionIds);
|
|
295
|
+
if (targets.size === 0)
|
|
296
|
+
return 0;
|
|
297
|
+
return this.withState(async (state) => {
|
|
298
|
+
const channels = Array.from(state.conversations)
|
|
299
|
+
.filter(([, header]) => header.sessionId && targets.has(header.sessionId))
|
|
300
|
+
.map(([channel]) => channel);
|
|
301
|
+
await this.appendBatch(state, channels.flatMap((channel) => [
|
|
302
|
+
{ v: 1, op: 'conversation', channel, kind: 'clear' },
|
|
303
|
+
{ v: 1, op: 'turn', channel, kind: 'clear' },
|
|
304
|
+
]));
|
|
278
305
|
return channels.length;
|
|
279
306
|
});
|
|
280
307
|
}
|
|
@@ -395,38 +422,55 @@ export class SessionRegistryRepo {
|
|
|
395
422
|
return this.withState(async (state) => {
|
|
396
423
|
const blocked = new Set(protectedIds);
|
|
397
424
|
const removed = [];
|
|
398
|
-
|
|
425
|
+
const intents = [];
|
|
426
|
+
const records = sortRecent(state.live.values());
|
|
427
|
+
const channelsBySession = conversationChannelsBySession(state);
|
|
428
|
+
const expired = (record) => {
|
|
429
|
+
const lastUsedAtMs = parseLastUsedAtMs(record.lastUsedAt);
|
|
430
|
+
return lastUsedAtMs !== null && lastUsedAtMs < toCutoffMs(cutoff);
|
|
431
|
+
};
|
|
432
|
+
// A team worker lives as long as its lead: kept while the lead exists, deleted with it.
|
|
433
|
+
const leadsDeleted = new Set(records
|
|
434
|
+
.filter(record => !record.teamLeadId && !blocked.has(record.sessionId) && expired(record))
|
|
435
|
+
.map(record => record.sessionId));
|
|
436
|
+
const liveIds = new Set(records.map(record => record.sessionId));
|
|
437
|
+
for (const record of records) {
|
|
399
438
|
// In-use sessions are protected by the caller: `domain/sessions/session-retention.ts` unions
|
|
400
439
|
// `activeSessionUseIds()` into `protectedIds`. The store no longer keeps a use counter.
|
|
401
440
|
if (blocked.has(record.sessionId))
|
|
402
441
|
continue;
|
|
403
|
-
const
|
|
404
|
-
if (
|
|
442
|
+
const leadId = record.teamLeadId && liveIds.has(record.teamLeadId) ? record.teamLeadId : null;
|
|
443
|
+
if (leadId ? !leadsDeleted.has(leadId) : !expired(record))
|
|
405
444
|
continue;
|
|
406
445
|
// Hand the callback the session's turns from the locked state directly — the ledger is now a
|
|
407
446
|
// façade over THIS registry, so a callback that read it back would re-enter `withState` and
|
|
408
447
|
// deadlock. (The old ledger was a separate store with its own lock.)
|
|
409
|
-
const
|
|
410
|
-
await
|
|
448
|
+
const turns = (channelsBySession.get(record.sessionId) ?? []).flatMap(channel => readTurns(state, channel));
|
|
449
|
+
const cleanup = await prepareCleanup(cloneSession(record), turns);
|
|
450
|
+
intents.push({
|
|
411
451
|
v: 1,
|
|
412
452
|
op: 'delete-intent',
|
|
413
453
|
id: record.sessionId,
|
|
414
454
|
record: toStoredRecord(cloneSession(record)),
|
|
415
455
|
cleanup,
|
|
416
|
-
}
|
|
417
|
-
await this.maybeCompact(state);
|
|
456
|
+
});
|
|
418
457
|
removed.push({ session: cloneSession(record), cleanup });
|
|
419
458
|
}
|
|
459
|
+
// All intents land durably before the caller starts any cleanup they describe.
|
|
460
|
+
await this.appendBatch(state, intents);
|
|
420
461
|
return removed;
|
|
421
462
|
});
|
|
422
463
|
}
|
|
423
464
|
async commitDeletion(sessionId) {
|
|
465
|
+
return (await this.commitDeletions([sessionId])).length > 0;
|
|
466
|
+
}
|
|
467
|
+
/** Commit several pending deletions with one append. Ids that are not pending are skipped;
|
|
468
|
+
* returns the ids that were committed. */
|
|
469
|
+
async commitDeletions(sessionIds) {
|
|
424
470
|
return this.withState(async (state) => {
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
await this.maybeCompact(state);
|
|
429
|
-
return true;
|
|
471
|
+
const ids = [...new Set(sessionIds)].filter(id => state.pending.has(id));
|
|
472
|
+
await this.appendBatch(state, ids.map((id) => ({ v: 1, op: 'delete-commit', id })));
|
|
473
|
+
return ids;
|
|
430
474
|
});
|
|
431
475
|
}
|
|
432
476
|
async compactNow() {
|
|
@@ -494,6 +538,12 @@ export class SessionRegistryRepo {
|
|
|
494
538
|
}, this.options);
|
|
495
539
|
await this.maybeCompact(state);
|
|
496
540
|
}
|
|
541
|
+
async appendBatch(state, events) {
|
|
542
|
+
if (events.length === 0)
|
|
543
|
+
return;
|
|
544
|
+
await appendSessionRegistryEvents(this.filePath, state, events, this.options);
|
|
545
|
+
await this.maybeCompact(state);
|
|
546
|
+
}
|
|
497
547
|
async maybeCompact(state) {
|
|
498
548
|
if (shouldCompactSessionRegistry(state, this.options)) {
|
|
499
549
|
await compactSessionRegistry(this.filePath, state, this.options);
|
|
@@ -507,15 +557,18 @@ function readConversationHeader(state, channel) {
|
|
|
507
557
|
const header = state.conversations.get(channel);
|
|
508
558
|
return header ? { ...header } : null;
|
|
509
559
|
}
|
|
510
|
-
/**
|
|
560
|
+
/** sessionId → channels whose conversation header names it — the rows the ledger's
|
|
511
561
|
* `listBySessionIds` would surface, read straight from the (already-locked) state. */
|
|
512
|
-
function
|
|
513
|
-
const
|
|
562
|
+
function conversationChannelsBySession(state) {
|
|
563
|
+
const index = new Map();
|
|
514
564
|
for (const [channel, header] of state.conversations) {
|
|
515
|
-
if (header.sessionId
|
|
516
|
-
|
|
565
|
+
if (!header.sessionId)
|
|
566
|
+
continue;
|
|
567
|
+
const channels = index.get(header.sessionId) ?? [];
|
|
568
|
+
channels.push(channel);
|
|
569
|
+
index.set(header.sessionId, channels);
|
|
517
570
|
}
|
|
518
|
-
return
|
|
571
|
+
return index;
|
|
519
572
|
}
|
|
520
573
|
function* filterLive(state, predicate) {
|
|
521
574
|
for (const record of state.live.values()) {
|
|
@@ -47,9 +47,9 @@ export type ExecutionLike = Pick<ExecutionRecord, 'session' | 'thread' | 'runtim
|
|
|
47
47
|
* - `subagent`: the run was spawned BY that session (`session.ownerSessionId`) and only its cost
|
|
48
48
|
* rolls up.
|
|
49
49
|
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* a record can only ever be folded once, with final numbers.
|
|
50
|
+
* A legacy record from the retired thread runtime is excluded outright: that run went beside its
|
|
51
|
+
* parent and was never the session's own turn, as the last-run resolver also assumes. Unfinished
|
|
52
|
+
* runs are excluded so a record can only ever be folded once, with final numbers.
|
|
53
53
|
*/
|
|
54
54
|
export declare function classifyForTotals(record: ExecutionLike): {
|
|
55
55
|
sessionId: string;
|
|
@@ -21,9 +21,9 @@ function finiteNumber(value) {
|
|
|
21
21
|
* - `subagent`: the run was spawned BY that session (`session.ownerSessionId`) and only its cost
|
|
22
22
|
* rolls up.
|
|
23
23
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* a record can only ever be folded once, with final numbers.
|
|
24
|
+
* A legacy record from the retired thread runtime is excluded outright: that run went beside its
|
|
25
|
+
* parent and was never the session's own turn, as the last-run resolver also assumes. Unfinished
|
|
26
|
+
* runs are excluded so a record can only ever be folded once, with final numbers.
|
|
27
27
|
*/
|
|
28
28
|
export function classifyForTotals(record) {
|
|
29
29
|
if (record?.thread?.threadId)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** A worker report a restart kept its lead from receiving, waiting to be delivered once it is back. */
|
|
2
|
+
export interface TeamOutboxEntry {
|
|
3
|
+
id: string;
|
|
4
|
+
leadId: string;
|
|
5
|
+
workerId: string;
|
|
6
|
+
status: 'completed' | 'failed' | 'stopped';
|
|
7
|
+
/** The worker's full final reply for that turn. */
|
|
8
|
+
text: string;
|
|
9
|
+
at: number;
|
|
10
|
+
}
|
|
11
|
+
export declare class TeamOutboxRepo {
|
|
12
|
+
private readonly repo;
|
|
13
|
+
constructor(filePath?: string);
|
|
14
|
+
add(entry: TeamOutboxEntry): Promise<void>;
|
|
15
|
+
remove(ids: string[]): Promise<void>;
|
|
16
|
+
/** Oldest first. */
|
|
17
|
+
list(): Promise<TeamOutboxEntry[]>;
|
|
18
|
+
flush(): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export declare const teamOutboxRepo: TeamOutboxRepo;
|