synabun 2.4.0 → 2.4.2
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/CHANGELOG.md +47 -0
- package/README.md +1 -1
- package/browser-extension/content.js +73 -11
- package/browser-extension/engine.js +196 -15
- package/browser-extension/manifest.json +4 -2
- package/browser-extension/popup-strings.js +10 -4
- package/browser-extension/popup-view.js +1 -1
- package/browser-extension/popup.css +1 -0
- package/browser-extension/popup.html +4 -1
- package/browser-extension/popup.js +22 -10
- package/browser-extension/protocol.js +102 -11
- package/browser-extension/service-worker.js +20 -4
- package/browser-extension/tokens.css +1 -1
- package/docs/browser-extension-bridge.md +25 -5
- package/lib/data-home-files.js +47 -0
- package/lib/data-home-migration.js +34 -58
- package/lib/first-launch-protection.js +8 -2
- package/lib/update-snapshot.js +11 -4
- package/mcp-server/dist/http.d.ts.map +1 -1
- package/mcp-server/dist/http.js +25 -2
- package/mcp-server/dist/http.js.map +1 -1
- package/mcp-server/dist/index.d.ts.map +1 -1
- package/mcp-server/dist/index.js +62 -17
- package/mcp-server/dist/index.js.map +1 -1
- package/mcp-server/dist/services/browser-bench.d.ts +22 -22
- package/mcp-server/dist/services/memory-maintenance.d.ts +1 -0
- package/mcp-server/dist/services/memory-maintenance.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-maintenance.js +34 -45
- package/mcp-server/dist/services/memory-maintenance.js.map +1 -1
- package/mcp-server/dist/services/memory-migration-copy.d.ts +144 -0
- package/mcp-server/dist/services/memory-migration-copy.d.ts.map +1 -0
- package/mcp-server/dist/services/memory-migration-copy.js +467 -0
- package/mcp-server/dist/services/memory-migration-copy.js.map +1 -0
- package/mcp-server/dist/services/memory-migration-worker.d.ts +2 -0
- package/mcp-server/dist/services/memory-migration-worker.d.ts.map +1 -0
- package/mcp-server/dist/services/memory-migration-worker.js +60 -0
- package/mcp-server/dist/services/memory-migration-worker.js.map +1 -0
- package/mcp-server/dist/services/memory-retrieval.d.ts +4 -0
- package/mcp-server/dist/services/memory-retrieval.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-retrieval.js +188 -40
- package/mcp-server/dist/services/memory-retrieval.js.map +1 -1
- package/mcp-server/dist/services/memory-schema.d.ts +58 -2
- package/mcp-server/dist/services/memory-schema.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-schema.js +190 -13
- package/mcp-server/dist/services/memory-schema.js.map +1 -1
- package/mcp-server/dist/services/memory-sessions.d.ts +19 -1
- package/mcp-server/dist/services/memory-sessions.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-sessions.js +56 -20
- package/mcp-server/dist/services/memory-sessions.js.map +1 -1
- package/mcp-server/dist/services/memory-verification.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-verification.js +8 -5
- package/mcp-server/dist/services/memory-verification.js.map +1 -1
- package/mcp-server/dist/services/neural-interface.d.ts +6 -0
- package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
- package/mcp-server/dist/services/neural-interface.js +19 -2
- package/mcp-server/dist/services/neural-interface.js.map +1 -1
- package/mcp-server/dist/services/retrieval-reader-worker.d.ts +2 -0
- package/mcp-server/dist/services/retrieval-reader-worker.d.ts.map +1 -0
- package/mcp-server/dist/services/retrieval-reader-worker.js +76 -0
- package/mcp-server/dist/services/retrieval-reader-worker.js.map +1 -0
- package/mcp-server/dist/services/retrieval-reader.d.ts +38 -0
- package/mcp-server/dist/services/retrieval-reader.d.ts.map +1 -0
- package/mcp-server/dist/services/retrieval-reader.js +145 -0
- package/mcp-server/dist/services/retrieval-reader.js.map +1 -0
- package/mcp-server/dist/services/sqlite-write.d.ts +14 -0
- package/mcp-server/dist/services/sqlite-write.d.ts.map +1 -0
- package/mcp-server/dist/services/sqlite-write.js +94 -0
- package/mcp-server/dist/services/sqlite-write.js.map +1 -0
- package/mcp-server/dist/services/sqlite.d.ts +39 -0
- package/mcp-server/dist/services/sqlite.d.ts.map +1 -1
- package/mcp-server/dist/services/sqlite.js +249 -8
- package/mcp-server/dist/services/sqlite.js.map +1 -1
- package/mcp-server/dist/services/tool-catalog.d.ts +1 -1
- package/mcp-server/dist/services/typesafe-config.d.ts +7 -1
- package/mcp-server/dist/services/typesafe-config.d.ts.map +1 -1
- package/mcp-server/dist/services/typesafe-config.js +32 -10
- package/mcp-server/dist/services/typesafe-config.js.map +1 -1
- package/mcp-server/dist/services/typesafe.d.ts.map +1 -1
- package/mcp-server/dist/services/typesafe.js +9 -7
- package/mcp-server/dist/services/typesafe.js.map +1 -1
- package/mcp-server/dist/services/vector-cache.d.ts +32 -0
- package/mcp-server/dist/services/vector-cache.d.ts.map +1 -1
- package/mcp-server/dist/services/vector-cache.js +161 -8
- package/mcp-server/dist/services/vector-cache.js.map +1 -1
- package/mcp-server/dist/tools/agent-definition.d.ts +2 -2
- package/mcp-server/dist/tools/agents.d.ts +13 -8
- package/mcp-server/dist/tools/agents.d.ts.map +1 -1
- package/mcp-server/dist/tools/agents.js +35 -15
- package/mcp-server/dist/tools/agents.js.map +1 -1
- package/mcp-server/dist/tools/browser-advanced.d.ts +1 -1
- package/mcp-server/dist/tools/browser-advanced.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-advanced.js +10 -3
- package/mcp-server/dist/tools/browser-advanced.js.map +1 -1
- package/mcp-server/dist/tools/browser-extension-setup.d.ts +5 -0
- package/mcp-server/dist/tools/browser-extension-setup.d.ts.map +1 -0
- package/mcp-server/dist/tools/browser-extension-setup.js +23 -0
- package/mcp-server/dist/tools/browser-extension-setup.js.map +1 -0
- package/mcp-server/dist/tools/browser-interact.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-interact.js +6 -1
- package/mcp-server/dist/tools/browser-interact.js.map +1 -1
- package/mcp-server/dist/tools/fb-groups.d.ts +2 -2
- package/mcp-server/dist/tools/skill-tools.d.ts +4 -4
- package/mcp-server/dist/tools/tool-groups.d.ts +1 -1
- package/mcp-server/package-lock.json +2 -2
- package/mcp-server/package.json +1 -1
- package/mcp-server/src/http.ts +20 -2
- package/mcp-server/src/index.ts +59 -17
- package/mcp-server/src/services/memory-maintenance.ts +31 -28
- package/mcp-server/src/services/memory-migration-copy.ts +419 -0
- package/mcp-server/src/services/memory-migration-worker.ts +55 -0
- package/mcp-server/src/services/memory-retrieval.ts +173 -32
- package/mcp-server/src/services/memory-schema.ts +194 -12
- package/mcp-server/src/services/memory-sessions.ts +54 -21
- package/mcp-server/src/services/memory-verification.ts +7 -4
- package/mcp-server/src/services/neural-interface.ts +23 -2
- package/mcp-server/src/services/retrieval-reader-worker.ts +67 -0
- package/mcp-server/src/services/retrieval-reader.ts +131 -0
- package/mcp-server/src/services/sqlite-write.ts +60 -0
- package/mcp-server/src/services/sqlite.ts +246 -8
- package/mcp-server/src/services/typesafe-config.ts +25 -6
- package/mcp-server/src/services/typesafe.ts +9 -7
- package/mcp-server/src/services/vector-cache.ts +154 -9
- package/mcp-server/src/tools/agents.ts +33 -14
- package/mcp-server/src/tools/browser-advanced.ts +10 -3
- package/mcp-server/src/tools/browser-extension-setup.ts +30 -0
- package/mcp-server/src/tools/browser-interact.ts +5 -1
- package/neural-interface/i18n/en.json +266 -2
- package/neural-interface/i18n/pt-BR.json +267 -3
- package/neural-interface/lib/agents/builtins.json +207 -0
- package/neural-interface/lib/agents/registry.js +60 -15
- package/neural-interface/lib/agents/resolve.js +69 -10
- package/neural-interface/lib/agents/split.js +32 -4
- package/neural-interface/lib/assistant-api.js +19 -8
- package/neural-interface/lib/assistant-brains/claude.js +2 -0
- package/neural-interface/lib/assistant-brains/opencode.js +60 -11
- package/neural-interface/lib/assistant-catalog.js +2 -2
- package/neural-interface/lib/assistant-config.js +0 -7
- package/neural-interface/lib/assistant-dispatch.js +384 -119
- package/neural-interface/lib/assistant-persona.js +17 -5
- package/neural-interface/lib/assistant-pricing.js +65 -14
- package/neural-interface/lib/assistant-router.js +181 -54
- package/neural-interface/lib/assistant-run-wait.js +45 -28
- package/neural-interface/lib/assistant-runtime.js +48 -34
- package/neural-interface/lib/backup-contents.js +158 -0
- package/neural-interface/lib/backup-crypto-io.js +330 -0
- package/neural-interface/lib/backup-crypto-worker.js +130 -0
- package/neural-interface/lib/backup-crypto.js +525 -0
- package/neural-interface/lib/backup-download.js +268 -0
- package/neural-interface/lib/backup-encryption.js +318 -0
- package/neural-interface/lib/backup-groups.js +287 -0
- package/neural-interface/lib/backup-restore-session.js +176 -0
- package/neural-interface/lib/backup-restore-stage.js +60 -0
- package/neural-interface/lib/backup-service.js +836 -322
- package/neural-interface/lib/backup-zip-reader.js +30 -18
- package/neural-interface/lib/backup-zip-writer.js +34 -10
- package/neural-interface/lib/browser-extension-adapter.js +109 -24
- package/neural-interface/lib/browser-extension-bridge.js +42 -8
- package/neural-interface/lib/claude-agent-bridge.js +1 -0
- package/neural-interface/lib/claude-session-cleanup.js +5 -1
- package/neural-interface/lib/cli-update-planner.js +105 -6
- package/neural-interface/lib/client-diagnostics.js +42 -0
- package/neural-interface/lib/confined-fs.js +7 -2
- package/neural-interface/lib/coordination/README.md +8 -2
- package/neural-interface/lib/coordination/contract.js +161 -0
- package/neural-interface/lib/coordination/database.js +999 -0
- package/neural-interface/lib/coordination/operations.js +436 -0
- package/neural-interface/lib/coordination/service.js +68 -537
- package/neural-interface/lib/coordination/storage-worker.js +101 -0
- package/neural-interface/lib/coordination/store.js +219 -1111
- package/neural-interface/lib/db.js +70 -32
- package/neural-interface/lib/health-count.js +37 -0
- package/neural-interface/lib/loop-stall.js +139 -0
- package/neural-interface/lib/maritaca/client.js +2 -2
- package/neural-interface/lib/maritaca/models.js +12 -17
- package/neural-interface/lib/maritaca/opencode.js +4 -2
- package/neural-interface/lib/memory-api.js +9 -1
- package/neural-interface/lib/memory-session-capture.js +42 -10
- package/neural-interface/lib/memory-store-gate.js +313 -0
- package/neural-interface/lib/memory-store-migrate.js +65 -0
- package/neural-interface/lib/memory-timers.js +7 -7
- package/neural-interface/lib/native-loop-providers.js +13 -16
- package/neural-interface/lib/native-loop-runtime.js +34 -14
- package/neural-interface/lib/opencode-build-preflight.js +30 -8
- package/neural-interface/lib/opencode-native-boundary.js +69 -8
- package/neural-interface/lib/opencode-provider-view.js +14 -3
- package/neural-interface/lib/opencode-v2-ws-requests.js +31 -1
- package/neural-interface/lib/opencode2-client.js +2 -1
- package/neural-interface/lib/peer-identity.js +13 -8
- package/neural-interface/lib/recall-impact.js +122 -0
- package/neural-interface/lib/scratch-evidence.js +420 -0
- package/neural-interface/lib/scratch-process-guard.js +139 -0
- package/neural-interface/lib/scratch-references.js +279 -0
- package/neural-interface/lib/scratch-retention-core.js +385 -0
- package/neural-interface/lib/scratch-retention-worker.js +37 -0
- package/neural-interface/lib/scratch-retention.js +151 -0
- package/neural-interface/lib/session-cache-builder.js +70 -44
- package/neural-interface/lib/session-cache-worker.js +157 -0
- package/neural-interface/lib/session-indexer.js +28 -21
- package/neural-interface/lib/session-search-index.js +85 -0
- package/neural-interface/lib/skills/creation.js +1 -1
- package/neural-interface/lib/sqlite-integrity-worker.js +3 -1
- package/neural-interface/lib/style-guide/store.js +43 -3
- package/neural-interface/lib/system-restore.js +50 -0
- package/neural-interface/lib/teams/api.js +15 -6
- package/neural-interface/lib/teams/claims.js +67 -31
- package/neural-interface/lib/teams/index.js +7 -7
- package/neural-interface/lib/teams/integration.js +40 -40
- package/neural-interface/lib/teams/landing.js +6 -6
- package/neural-interface/lib/teams/recovery.js +24 -23
- package/neural-interface/lib/teams/scheduler.js +196 -97
- package/neural-interface/lib/teams/schema.js +1 -1
- package/neural-interface/lib/teams/state.js +14 -14
- package/neural-interface/lib/teams/worktrees.js +27 -27
- package/neural-interface/lib/whatsapp/bridge.js +2 -1
- package/neural-interface/lib/worker-confinement.js +47 -2
- package/neural-interface/lib/worker-mcp-channel.js +2 -0
- package/neural-interface/lib/worker-resume.js +5 -0
- package/neural-interface/lib/worker-stop.js +86 -0
- package/neural-interface/package-lock.json +2 -2
- package/neural-interface/package.json +1 -1
- package/neural-interface/public/index.html +260 -0
- package/neural-interface/public/offline.html +4 -3
- package/neural-interface/public/onboarding.html +259 -34
- package/neural-interface/public/shared/agents/studio/ax-agent-view.js +2 -2
- package/neural-interface/public/shared/agents/studio/ax-editor-view.js +1 -1
- package/neural-interface/public/shared/agents/studio/ax-library.js +0 -6
- package/neural-interface/public/shared/agents/studio/ax-main.js +14 -7
- package/neural-interface/public/shared/agents/studio/ax-ui.js +2 -2
- package/neural-interface/public/shared/agy/agy-options.js +11 -0
- package/neural-interface/public/shared/agy/agy-panel.js +29 -10
- package/neural-interface/public/shared/agy/agy-styles.js +14 -12
- package/neural-interface/public/shared/agy/agy-tabs-logic.js +4 -1
- package/neural-interface/public/shared/api.js +3 -2
- package/neural-interface/public/shared/assistant/asst-api.js +3 -3
- package/neural-interface/public/shared/assistant/asst-brain-picker.js +13 -6
- package/neural-interface/public/shared/assistant/asst-control.js +2 -0
- package/neural-interface/public/shared/assistant/asst-motion-gate.js +78 -4
- package/neural-interface/public/shared/assistant/asst-panel.js +18 -2
- package/neural-interface/public/shared/assistant/asst-rack-styles.js +4 -0
- package/neural-interface/public/shared/assistant/asst-render.js +106 -38
- package/neural-interface/public/shared/assistant/asst-route.js +102 -21
- package/neural-interface/public/shared/assistant/asst-routes-editor.js +1 -1
- package/neural-interface/public/shared/assistant/asst-sidepanel.js +4 -2
- package/neural-interface/public/shared/assistant/asst-state.js +11 -0
- package/neural-interface/public/shared/assistant/asst-styles.js +10 -23
- package/neural-interface/public/shared/assistant/route-identity.js +2 -1
- package/neural-interface/public/shared/cc-dropdown.js +21 -15
- package/neural-interface/public/shared/cdx/cdx-render.js +9 -0
- package/neural-interface/public/shared/cdx/cdx-settings.js +3 -1
- package/neural-interface/public/shared/cdx/cdx-styles.js +6 -0
- package/neural-interface/public/shared/cdx/cdx-tabs.js +29 -9
- package/neural-interface/public/shared/client-diagnostics.js +94 -0
- package/neural-interface/public/shared/cp/cp-markdown.js +7 -2
- package/neural-interface/public/shared/cp/cp-styles.js +1 -1
- package/neural-interface/public/shared/effort-i18n.js +118 -0
- package/neural-interface/public/shared/html-shell.js +4 -51
- package/neural-interface/public/shared/loading-diagnostic-entry.js +64 -0
- package/neural-interface/public/shared/memory-store-wait.js +52 -0
- package/neural-interface/public/shared/morelogin-profile-field.js +1 -1
- package/neural-interface/public/shared/mtc/mtc-logic.js +2 -1
- package/neural-interface/public/shared/mtc/mtc-panel.js +8 -1
- package/neural-interface/public/shared/mtc/mtc-styles.js +13 -12
- package/neural-interface/public/shared/ocp-v2/ocp-v2-childpanel.js +7 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-location-logic.js +109 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-modelpicker.js +8 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-panel.js +118 -6
- package/neural-interface/public/shared/ocp-v2/ocp-v2-render.js +27 -3
- package/neural-interface/public/shared/ocp-v2/ocp-v2-send.js +13 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-session-actions.js +2 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-styles.js +27 -93
- package/neural-interface/public/shared/ocp-v2/ocp-v2-variantpicker.js +17 -6
- package/neural-interface/public/shared/output-format.js +294 -0
- package/neural-interface/public/shared/owner-authority-view.js +4 -10
- package/neural-interface/public/shared/page-session.js +1 -1
- package/neural-interface/public/shared/provider-icons.js +6 -0
- package/neural-interface/public/shared/schedules-view.js +2 -1
- package/neural-interface/public/shared/server-presence.js +77 -0
- package/neural-interface/public/shared/settings/settings-ai-browser.js +5 -5
- package/neural-interface/public/shared/settings/settings-backup-contents.js +241 -0
- package/neural-interface/public/shared/settings/settings-backup-download.js +298 -0
- package/neural-interface/public/shared/settings/settings-backup-encryption-pane.js +335 -0
- package/neural-interface/public/shared/settings/settings-backup-encryption.js +545 -0
- package/neural-interface/public/shared/settings/settings-ia.js +1 -1
- package/neural-interface/public/shared/skills/studio/sx-geometry.js +12 -3
- package/neural-interface/public/shared/skills/studio/sx-main.js +14 -7
- package/neural-interface/public/shared/start-bridge.js +2 -2
- package/neural-interface/public/shared/studio-attention.js +6 -0
- package/neural-interface/public/shared/styles.css +354 -438
- package/neural-interface/public/shared/transcript-rows.js +28 -3
- package/neural-interface/public/shared/tray-auto-close.js +18 -5
- package/neural-interface/public/shared/ui-agents.js +1 -2
- package/neural-interface/public/shared/ui-automation-studio.js +168 -108
- package/neural-interface/public/shared/ui-claude-panel.js +42 -65
- package/neural-interface/public/shared/ui-loading.js +185 -25
- package/neural-interface/public/shared/ui-native-loop-router.js +59 -20
- package/neural-interface/public/shared/ui-navbar.js +2 -1
- package/neural-interface/public/shared/ui-output.js +533 -0
- package/neural-interface/public/shared/ui-owner-authority.js +48 -25
- package/neural-interface/public/shared/ui-schedules-studio.js +165 -128
- package/neural-interface/public/shared/ui-scroll-follow.js +97 -6
- package/neural-interface/public/shared/ui-sessions.js +2 -2
- package/neural-interface/public/shared/ui-settings-entry.js +18 -0
- package/neural-interface/public/shared/ui-settings.js +234 -67
- package/neural-interface/public/shared/ui-sidepanel-tray.js +3 -2
- package/neural-interface/public/shared/ui-sync.js +1 -0
- package/neural-interface/public/shared/ui-tooltip.js +16 -0
- package/neural-interface/public/shared/ui-tutorial.js +5 -6
- package/neural-interface/public/shared/ui-worker-end.js +27 -8
- package/neural-interface/public/shared/worker-end.js +9 -4
- package/neural-interface/public/sw.js +4 -3
- package/neural-interface/public/variant/2d/main.js +5 -0
- package/neural-interface/public/variant/3d/app.js +10 -0
- package/neural-interface/public/variant/3d/main.js +17 -4
- package/neural-interface/scripts/scratch-retention.mjs +20 -0
- package/neural-interface/server.js +507 -160
- package/npm-shrinkwrap.json +2 -2
- package/package.json +2 -1
- package/scripts/restore-data-home-from-backup.mjs +175 -8
- package/setup.js +18 -4
|
@@ -28,10 +28,12 @@
|
|
|
28
28
|
// Nothing here is reachable by a worker except the channel functions (`member`, `post`, `read`, `wait`, `ack`,
|
|
29
29
|
// `claims`, `request`), which take the caller's proven run id and find its team themselves.
|
|
30
30
|
|
|
31
|
-
import {
|
|
31
|
+
import { markActivity } from '../loop-stall.js';
|
|
32
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
32
33
|
import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
33
34
|
import { join } from 'node:path';
|
|
34
35
|
import { AGENT_DENSITY_LABELS, DEFAULT_AGENT_DENSITY, maxWorkers, normalizeAgentDensity } from '../agents/density.js';
|
|
36
|
+
import { splitTitle } from '../agents/split.js';
|
|
35
37
|
import { sessionRecipient } from '../coordination/store.js';
|
|
36
38
|
import {
|
|
37
39
|
PEER_NOTICE, TEAM_ACTION_KINDS, TEAM_MESSAGE_KINDS, conflictFollowUp, peerMessagesText, teamBrief, testsFailedFollowUp,
|
|
@@ -41,6 +43,7 @@ import {
|
|
|
41
43
|
worktreePath, branchName, integrationBranchName, isTeamSlug, normalizeRelPath, normalizeTeamPlan, pathOwner, validateTeamPlan,
|
|
42
44
|
} from './schema.js';
|
|
43
45
|
import { TEAM_TEST_TIMEOUT_MS } from './test-runner.js';
|
|
46
|
+
import { testCommandOf } from './worktrees.js';
|
|
44
47
|
|
|
45
48
|
/** The team events the scheduler emits: what the Assistant reads (`kind`), the log's kind, the priority, and whether the session's mailbox gets it. */
|
|
46
49
|
export const TEAM_EVENTS = Object.freeze({
|
|
@@ -143,6 +146,21 @@ function dispatchDefaults(input = {}) {
|
|
|
143
146
|
* @param {(tag: string, detail: any) => void} [deps.log]
|
|
144
147
|
* @param {() => string} [deps.newRunId]
|
|
145
148
|
*/
|
|
149
|
+
/** What differs between an approved route's planned_split and a team plan, as one sentence; null when they match. */
|
|
150
|
+
export function routeSplitDifference(split, plan) {
|
|
151
|
+
if (!split || split.flow !== 'team') return 'the approved route has no team split (it runs as one worker).';
|
|
152
|
+
const given = plan?.slices || [];
|
|
153
|
+
if (split.projectPath !== plan?.projectPath) return `project differs: approved ${JSON.stringify(split.projectPath)}, given ${JSON.stringify(plan?.projectPath ?? null)}.`;
|
|
154
|
+
if (split.workers !== given.length) return `slice count differs: approved ${split.workers}, given ${given.length}.`;
|
|
155
|
+
// Both sides are read the same way (splitTitle): a route stored with a title over the limit starts with the cut title.
|
|
156
|
+
for (let i = 0; i < split.slices.length; i++) {
|
|
157
|
+
const approved = splitTitle(split.slices[i]);
|
|
158
|
+
if (approved !== splitTitle(given[i]?.title)) return `slice ${i + 1} title differs: approved ${JSON.stringify(approved)}, given ${JSON.stringify(given[i]?.title ?? null)}.`;
|
|
159
|
+
}
|
|
160
|
+
if (split.workers < split.target && split.reason !== plan.fewerReason) return `fewer_reason differs: approved ${JSON.stringify(split.reason)}, given ${JSON.stringify(plan.fewerReason ?? null)}.`;
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
|
|
146
164
|
export function createTeamScheduler({
|
|
147
165
|
teams, coordination, dispatcher: givenDispatcher, density = null, router: givenRouter = null, session: sessionInfo = null,
|
|
148
166
|
git = null, dataDir, broadcast = () => {}, limits: limitOverrides = {}, now = Date.now, log = () => {},
|
|
@@ -161,6 +179,13 @@ export function createTeamScheduler({
|
|
|
161
179
|
const postTimes = new Map(); // runId → the times of its recent posts
|
|
162
180
|
let unsubscribe = null;
|
|
163
181
|
let watchdog = null;
|
|
182
|
+
let watchdogPass = null;
|
|
183
|
+
const background = new Set();
|
|
184
|
+
function track(task) {
|
|
185
|
+
background.add(task);
|
|
186
|
+
task.then(() => background.delete(task), () => background.delete(task));
|
|
187
|
+
return task;
|
|
188
|
+
}
|
|
164
189
|
const reconciling = new Set(); // one pending watchdog replay per run
|
|
165
190
|
let closed = false;
|
|
166
191
|
// Nothing of a team runs before the library's own recovery has (recover()): a team a stop cut off mid-join is
|
|
@@ -237,7 +262,7 @@ export function createTeamScheduler({
|
|
|
237
262
|
* A team event: one entry of the durable log with the team's id (the team's timeline), addressed to the session
|
|
238
263
|
* that runs the team when its brain must hear it, and one broadcast to the owner's pages.
|
|
239
264
|
*/
|
|
240
|
-
function emit(record, name, detail = {}, { critical = false, mailbox = null, quiet = false } = {}) {
|
|
265
|
+
async function emit(record, name, detail = {}, { critical = false, mailbox = null, quiet = false } = {}) {
|
|
241
266
|
const spec = TEAM_EVENTS[name];
|
|
242
267
|
if (!spec) return null;
|
|
243
268
|
record.eventSeq = (Number(record.eventSeq) || 0) + 1;
|
|
@@ -250,7 +275,7 @@ export function createTeamScheduler({
|
|
|
250
275
|
};
|
|
251
276
|
let out = null;
|
|
252
277
|
try {
|
|
253
|
-
out = store.append({
|
|
278
|
+
out = await store.append({
|
|
254
279
|
id: `team:${record.teamId}:event:${record.eventSeq}`,
|
|
255
280
|
kind: spec.kind, priority: critical ? 'critical' : spec.priority,
|
|
256
281
|
teamId: record.teamId, sessionId: record.sessionId || null, runId: detail.runId || null,
|
|
@@ -285,7 +310,7 @@ export function createTeamScheduler({
|
|
|
285
310
|
const runIdle = (run) => !!run && run.state === 'idle';
|
|
286
311
|
|
|
287
312
|
/** The team's journal record, or null. */
|
|
288
|
-
const journalOf =
|
|
313
|
+
const journalOf = teamId => teams.get(teamId);
|
|
289
314
|
const sliceStateOf = (journal, sliceId) => journal?.slices?.[sliceId]?.state || 'pending';
|
|
290
315
|
|
|
291
316
|
function summary(record) {
|
|
@@ -297,11 +322,11 @@ export function createTeamScheduler({
|
|
|
297
322
|
}
|
|
298
323
|
|
|
299
324
|
/** The newest `limit` events of a team's log, oldest first. */
|
|
300
|
-
function tailOfLog(teamId, kinds, limit) {
|
|
325
|
+
async function tailOfLog(teamId, kinds, limit) {
|
|
301
326
|
const out = [];
|
|
302
327
|
let afterSeq = 0;
|
|
303
328
|
for (let page = 0; page < 40; page += 1) {
|
|
304
|
-
const rows = store.events({ teamId, afterSeq, kinds, limit: 500 });
|
|
329
|
+
const rows = await store.events({ teamId, afterSeq, kinds, limit: 500 });
|
|
305
330
|
out.push(...rows);
|
|
306
331
|
if (out.length > limit * 2) out.splice(0, out.length - limit);
|
|
307
332
|
if (rows.length < 500) break;
|
|
@@ -332,11 +357,11 @@ export function createTeamScheduler({
|
|
|
332
357
|
async function status(teamId, { timeline = limits.timeline } = {}) {
|
|
333
358
|
const record = records.get(String(teamId || ''));
|
|
334
359
|
if (!record) return refuse('TEAM_NOT_FOUND', `No team named "${teamId}" is known here.`, { status: 404 });
|
|
335
|
-
let journal = journalOf(record.teamId);
|
|
360
|
+
let journal = await journalOf(record.teamId);
|
|
336
361
|
let inspected = null;
|
|
337
362
|
if (journal && !journal.removed) { try { inspected = await teams.inspect(record.teamId); } catch (error) { inspected = null; say('teams:inspect-failed', { teamId: record.teamId, error: error?.message || String(error) }); } }
|
|
338
363
|
// Inspection asks git about every checkout; the join can change phase while it runs.
|
|
339
|
-
journal = journalOf(record.teamId);
|
|
364
|
+
journal = await journalOf(record.teamId);
|
|
340
365
|
const seen = inspected?.ok ? inspected : null;
|
|
341
366
|
const plan = journal?.plan || record.plan || { slices: [] };
|
|
342
367
|
const slices = plan.slices.map((slice) => {
|
|
@@ -357,10 +382,10 @@ export function createTeamScheduler({
|
|
|
357
382
|
};
|
|
358
383
|
});
|
|
359
384
|
let claims = [];
|
|
360
|
-
try { claims = store.claimsFor({ teamId: record.teamId }).map((claim) => ({ sliceId: claim.sliceId, runId: claim.runId || null, glob: claim.glob, claimedAt: claim.claimedAt || claim.createdAt || null })); } catch { claims = []; }
|
|
385
|
+
try { claims = (await store.claimsFor({ teamId: record.teamId })).map((claim) => ({ sliceId: claim.sliceId, runId: claim.runId || null, glob: claim.glob, claimedAt: claim.claimedAt || claim.createdAt || null })); } catch { claims = []; }
|
|
361
386
|
const tests = journal?.integration?.tests || null;
|
|
362
|
-
const events = tailOfLog(record.teamId, TEAM_EVENT_LOG_KINDS, timeline).map(eventView);
|
|
363
|
-
const messages = tailOfLog(record.teamId, [TEAM_MESSAGE_LOG_KIND], timeline).map(messageView);
|
|
387
|
+
const events = (await tailOfLog(record.teamId, TEAM_EVENT_LOG_KINDS, timeline)).map(eventView);
|
|
388
|
+
const messages = (await tailOfLog(record.teamId, [TEAM_MESSAGE_LOG_KIND], timeline)).map(messageView);
|
|
364
389
|
return {
|
|
365
390
|
ok: true,
|
|
366
391
|
team: {
|
|
@@ -504,15 +529,13 @@ export function createTeamScheduler({
|
|
|
504
529
|
const checked = await plan({ ...input, taskClass }, { sessionId: session });
|
|
505
530
|
if (!checked.ok) return { ...refuse(checked.code, checked.message, { status: checked.code === 'INVALID_PLAN' ? 400 : 409 }), plan: checked.plan, density: checked.density, errors: checked.errors };
|
|
506
531
|
const split = routed.route?.plannedSplit;
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|| (split.workers < split.target && split.reason !== checked.plan.fewerReason))) {
|
|
511
|
-
return refuse('TEAM_ROUTE_SPLIT_MISMATCH', 'The team must match the approved project, slice count, titles and fewer_reason. Route the complete plan once before starting.', { status: 409 });
|
|
532
|
+
const splitDiff = routed.route ? routeSplitDifference(split, checked.plan) : null;
|
|
533
|
+
if (splitDiff) {
|
|
534
|
+
return refuse('TEAM_ROUTE_SPLIT_MISMATCH', `The team must match the approved split: ${splitDiff} Route the complete plan once before starting.`, { status: 409 });
|
|
512
535
|
}
|
|
513
536
|
if (routed.route?.workflowId && routed.route.workflowId !== `team:${checked.plan.teamId}`) return refuse('TEAM_ROUTE_SPLIT_MISMATCH', 'This route already belongs to another team.', { status: 409 });
|
|
514
537
|
const defaults = dispatchDefaults(input);
|
|
515
|
-
if (!routed.route && !defaults.provider && checked.plan.slices.some((slice) => !slice.agentRef)) {
|
|
538
|
+
if (!routed.route && !defaults.provider && checked.plan.slices.some((slice) => !slice.agentRef || slice.agentRef === 'none')) {
|
|
516
539
|
return refuse('TEAM_PROVIDER_REQUIRED', 'Name the provider the team\'s workers run on (or give every slice an agent_ref).', { status: 400 });
|
|
517
540
|
}
|
|
518
541
|
if (records.has(checked.plan.teamId)) return refuse('TEAM_EXISTS', `A team named "${checked.plan.teamId}" exists already: a team id is used once.`, { status: 409 });
|
|
@@ -530,7 +553,7 @@ export function createTeamScheduler({
|
|
|
530
553
|
landing: null, cleanup: null, createdAt: at, updatedAt: at,
|
|
531
554
|
};
|
|
532
555
|
save(record);
|
|
533
|
-
emit(record, 'team_started', { text: `${checked.plan.slices.length} slices at Agent density ${checked.density.label}`, slices: checked.plan.slices.map((slice) => slice.id), baseCommit: made.team.baseCommit });
|
|
556
|
+
await emit(record, 'team_started', { text: `${checked.plan.slices.length} slices at Agent density ${checked.density.label}`, slices: checked.plan.slices.map((slice) => slice.id), baseCommit: made.team.baseCommit });
|
|
534
557
|
const started = await teamStep(record, () => startReady(record));
|
|
535
558
|
return { ok: true, teamId: record.teamId, workflowId: record.workflowId, density: checked.density, setup: made.setup || [], started, team: (await status(record.teamId, { timeline: 20 })) };
|
|
536
559
|
}
|
|
@@ -550,14 +573,14 @@ export function createTeamScheduler({
|
|
|
550
573
|
: await teams.startSlice(record.teamId, sliceId, { runId });
|
|
551
574
|
if (!started.ok) return started;
|
|
552
575
|
const worktree = started.worktree;
|
|
553
|
-
const journal = journalOf(record.teamId);
|
|
576
|
+
const journal = await journalOf(record.teamId);
|
|
554
577
|
const brief = teamBrief(journal, sliceId, { title: record.title, worktree, rework: rework || resolve, startCommit: started.startCommit || '' });
|
|
555
578
|
const attempt = (mine.runIds || []).length + 1;
|
|
556
579
|
// A slice that runs as one of the owner's agents runs on what that agent runs on: the team's own provider,
|
|
557
580
|
// model, effort and account are for the slices that name none. (An approved route binds every slice all the same:
|
|
558
581
|
// the router writes its target over the spec after the agent was applied.)
|
|
559
582
|
const { provider: _provider, model: _model, effort: _effort, accountId: _accountId, ...shared } = record.dispatch || {};
|
|
560
|
-
const defaults = slice.agentRef ? shared : (record.dispatch || {});
|
|
583
|
+
const defaults = slice.agentRef && slice.agentRef !== 'none' ? shared : (record.dispatch || {});
|
|
561
584
|
const spec = {
|
|
562
585
|
...defaults,
|
|
563
586
|
task: lead ? `${lead}\n\nYOUR SLICE'S TASK (as first given):\n${slice.task}` : slice.task,
|
|
@@ -584,7 +607,7 @@ export function createTeamScheduler({
|
|
|
584
607
|
try {
|
|
585
608
|
const out = await dispatcher.dispatch(spec, { assistantSessionId: record.sessionId, origin: 'assistant', team: brief, runId });
|
|
586
609
|
mine.phase = out.queued ? 'queued' : 'working';
|
|
587
|
-
emit(record, 'slice_started', { sliceId, runId, text: `${slice.title || sliceId}${rework || resolve ? ' (sent back)' : ''}${out.queued ? ' (queued for a free slot)' : ''}`, rework: rework || resolve, queued: out.queued === true });
|
|
610
|
+
await emit(record, 'slice_started', { sliceId, runId, text: `${slice.title || sliceId}${rework || resolve ? ' (sent back)' : ''}${out.queued ? ' (queued for a free slot)' : ''}`, rework: rework || resolve, queued: out.queued === true });
|
|
588
611
|
return { ok: true, sliceId, runId, queued: out.queued === true, worktree };
|
|
589
612
|
} catch (error) {
|
|
590
613
|
mine.phase = 'failed';
|
|
@@ -599,7 +622,7 @@ export function createTeamScheduler({
|
|
|
599
622
|
async function startReady(record) {
|
|
600
623
|
const started = [];
|
|
601
624
|
if (record.status !== 'running') return started;
|
|
602
|
-
const journal = journalOf(record.teamId);
|
|
625
|
+
const journal = await journalOf(record.teamId);
|
|
603
626
|
if (!journal) return started;
|
|
604
627
|
for (const slice of record.plan.slices) {
|
|
605
628
|
const mine = record.slices[slice.id];
|
|
@@ -607,18 +630,18 @@ export function createTeamScheduler({
|
|
|
607
630
|
if (slice.dependsOn.some((dep) => sliceStateOf(journal, dep) !== 'integrated')) continue;
|
|
608
631
|
const out = await dispatchSlice(record, slice.id);
|
|
609
632
|
started.push(out.ok ? { sliceId: slice.id, runId: out.runId, queued: out.queued } : { sliceId: slice.id, ok: false, code: out.code, message: out.message });
|
|
610
|
-
if (!out.ok) attention(record, { code: out.code || 'SLICE_NOT_STARTED', sliceId: slice.id, message: `Slice ${slice.id} could not start: ${out.message}` });
|
|
633
|
+
if (!out.ok) await attention(record, { code: out.code || 'SLICE_NOT_STARTED', sliceId: slice.id, message: `Slice ${slice.id} could not start: ${out.message}` });
|
|
611
634
|
}
|
|
612
635
|
return started;
|
|
613
636
|
}
|
|
614
637
|
|
|
615
638
|
// ── needs attention ────────────────────────────────────────────────────────
|
|
616
639
|
/** The team cannot go on by itself: say so once, to the session that runs it, as critical. */
|
|
617
|
-
function attention(record, { code, sliceId = null, message, report = null, event = 'needs_attention' } = {}) {
|
|
640
|
+
async function attention(record, { code, sliceId = null, message, report = null, event = 'needs_attention' } = {}) {
|
|
618
641
|
record.status = 'needs_attention';
|
|
619
642
|
record.attention = { code, sliceId, message: clip(message, 600), at: iso(now()) };
|
|
620
643
|
if (sliceId && record.slices[sliceId]) record.slices[sliceId].lastReport = { code, message: clip(message, 600), at: iso(now()), ...(report ? { report } : {}) };
|
|
621
|
-
emit(record, event, { sliceId, code, text: message, final: true, ...(report ? { report: reportBrief(report) } : {}) }, { critical: true, mailbox: true });
|
|
644
|
+
await emit(record, event, { sliceId, code, text: message, final: true, ...(report ? { report: reportBrief(report) } : {}) }, { critical: true, mailbox: true });
|
|
622
645
|
}
|
|
623
646
|
/** A report as an event carries it: the files and the test result's end, never whole blobs. */
|
|
624
647
|
function reportBrief(report) {
|
|
@@ -640,7 +663,7 @@ export function createTeamScheduler({
|
|
|
640
663
|
const run = runOf(mine.runId);
|
|
641
664
|
if (dispatcher && runLive(run)) {
|
|
642
665
|
try {
|
|
643
|
-
dispatcher.sendTurn(mine.runId, text, { origin });
|
|
666
|
+
await dispatcher.sendTurn(mine.runId, text, { origin });
|
|
644
667
|
mine.phase = 'working';
|
|
645
668
|
save(record);
|
|
646
669
|
return { ok: true, runId: mine.runId, via: 'follow-up' };
|
|
@@ -656,20 +679,20 @@ export function createTeamScheduler({
|
|
|
656
679
|
}
|
|
657
680
|
|
|
658
681
|
/** The unread messages of a member that somebody waits on (questions, change requests). */
|
|
659
|
-
function waitingMessages(teamId, runId) {
|
|
682
|
+
async function waitingMessages(teamId, runId) {
|
|
660
683
|
let rows = [];
|
|
661
|
-
try { rows = coordination.team.read({ teamId, runId, limit: 100, peek: true }); } catch { rows = []; }
|
|
684
|
+
try { rows = await coordination.team.read({ teamId, runId, limit: 100, peek: true }); } catch { rows = []; }
|
|
662
685
|
return rows.filter((event) => event.kind === TEAM_MESSAGE_LOG_KIND && TEAM_ACTION_KINDS.includes(event.payload?.messageKind));
|
|
663
686
|
}
|
|
664
687
|
|
|
665
688
|
// Read-only workers never commit or join. End a warm run before removing its checkout.
|
|
666
689
|
async function finishReader(record, sliceId, { failed = false } = {}) {
|
|
667
690
|
const mine = record.slices[sliceId];
|
|
668
|
-
if (journalOf(record.teamId)?.slices[sliceId]?.cleanup) return;
|
|
691
|
+
if ((await journalOf(record.teamId))?.slices[sliceId]?.cleanup) return;
|
|
669
692
|
const run = runOf(mine.runId);
|
|
670
693
|
if (runLive(run)) {
|
|
671
694
|
try { await dispatcherOf().complete(mine.runId, { reason: 'read_only_done' }); }
|
|
672
|
-
catch (error) { return attention(record, { code: 'WORKER_STILL_ACTIVE', sliceId, message: `Worktree kept: worker could not end (${error.message}).` }); }
|
|
695
|
+
catch (error) { return await attention(record, { code: 'WORKER_STILL_ACTIVE', sliceId, message: `Worktree kept: worker could not end (${error.message}).` }); }
|
|
673
696
|
// complete() wakes the idle run; its terminal dispatch event resumes cleanup.
|
|
674
697
|
if (runLive(runOf(mine.runId))) return;
|
|
675
698
|
}
|
|
@@ -677,12 +700,12 @@ export function createTeamScheduler({
|
|
|
677
700
|
mine.phase = failed ? 'failed' : 'completed';
|
|
678
701
|
mine.released = true;
|
|
679
702
|
mine.doneAt = iso(now());
|
|
680
|
-
emit(record, 'slice_done', { sliceId, runId: mine.runId, text: cleanup.removed ? 'Read-only worker ended; worktree removed.' : `Worktree kept: ${cleanup.kept?.path || cleanup.path} (${cleanup.kept?.reason || cleanup.code}).` });
|
|
681
|
-
if (!cleanup.ok || cleanup.kept) attention(record, { code: 'READ_ONLY_WORKTREE_KEPT', sliceId, message: `Read-only worker worktree kept at ${cleanup.kept?.path || cleanup.path}: ${cleanup.kept?.reason || cleanup.message}. Inspect it; no changes were committed or landed.`, report: cleanup });
|
|
682
|
-
else if (failed) attention(record, { code: 'SLICE_WORKER_ENDED', sliceId, message: 'Read-only worker ended before reporting done; its clean worktree was removed.' });
|
|
703
|
+
await emit(record, 'slice_done', { sliceId, runId: mine.runId, text: cleanup.removed ? 'Read-only worker ended; worktree removed.' : `Worktree kept: ${cleanup.kept?.path || cleanup.path} (${cleanup.kept?.reason || cleanup.code}).` });
|
|
704
|
+
if (!cleanup.ok || cleanup.kept) await attention(record, { code: 'READ_ONLY_WORKTREE_KEPT', sliceId, message: `Read-only worker worktree kept at ${cleanup.kept?.path || cleanup.path}: ${cleanup.kept?.reason || cleanup.message}. Inspect it; no changes were committed or landed.`, report: cleanup });
|
|
705
|
+
else if (failed) await attention(record, { code: 'SLICE_WORKER_ENDED', sliceId, message: 'Read-only worker ended before reporting done; its clean worktree was removed.' });
|
|
683
706
|
if (Object.values(record.slices).every(s => s.released) && record.status !== 'needs_attention') {
|
|
684
707
|
record.status = 'completed';
|
|
685
|
-
emit(record, 'team_completed', { text: 'All read-only workers finished. Synthesize their results; no integration or landing is needed.' });
|
|
708
|
+
await emit(record, 'team_completed', { text: 'All read-only workers finished. Synthesize their results; no integration or landing is needed.' });
|
|
686
709
|
}
|
|
687
710
|
save(record);
|
|
688
711
|
}
|
|
@@ -691,20 +714,20 @@ export function createTeamScheduler({
|
|
|
691
714
|
async function sliceReportedDone(record, sliceId, runId) {
|
|
692
715
|
if (record.plan.readOnly) return finishReader(record, sliceId);
|
|
693
716
|
const mine = record.slices[sliceId];
|
|
694
|
-
const journal = journalOf(record.teamId);
|
|
717
|
+
const journal = await journalOf(record.teamId);
|
|
695
718
|
const current = sliceStateOf(journal, sliceId);
|
|
696
719
|
if (current === 'integrated') return;
|
|
697
720
|
// Somebody asked this worker something while it worked: it answers before its slice is closed.
|
|
698
|
-
const asks = waitingMessages(record.teamId, runId);
|
|
721
|
+
const asks = await waitingMessages(record.teamId, runId);
|
|
699
722
|
if (asks.length && (Number(mine.deferrals) || 0) < limits.maxPeerDeferrals) {
|
|
700
723
|
mine.deferrals = (Number(mine.deferrals) || 0) + 1;
|
|
701
724
|
const handed = await sendBack(record, sliceId, peerMessagesText(record.teamId, asks.map(messageView), { beforeIntegration: true }), { origin: 'peer' });
|
|
702
725
|
if (!handed.ok) {
|
|
703
726
|
mine.phase = 'failed';
|
|
704
|
-
return attention(record, { code: handed.code || 'SLICE_NOT_SENT_BACK', sliceId, message: `Could not deliver the peer follow-up to ${sliceId}: ${handed.message}. Inspect agent_team status and retry with agent_team integrate.` });
|
|
727
|
+
return await attention(record, { code: handed.code || 'SLICE_NOT_SENT_BACK', sliceId, message: `Could not deliver the peer follow-up to ${sliceId}: ${handed.message}. Inspect agent_team status and retry with agent_team integrate.` });
|
|
705
728
|
}
|
|
706
729
|
if (handed.via === 'follow-up') {
|
|
707
|
-
try { coordination.team.ack({ teamId: record.teamId, runId, eventIds: asks.map((event) => event.id) }); } catch { /* handed over all the same */ }
|
|
730
|
+
try { await coordination.team.ack({ teamId: record.teamId, runId, eventIds: asks.map((event) => event.id) }); } catch { /* handed over all the same */ }
|
|
708
731
|
}
|
|
709
732
|
return;
|
|
710
733
|
}
|
|
@@ -734,11 +757,11 @@ export function createTeamScheduler({
|
|
|
734
757
|
if (finished.code === 'UNRESOLVED_CONFLICTS') return retry(record, sliceId, 'conflict', { report: { files: finished.files || [] }, text: unresolvedFollowUp({ teamId: record.teamId, sliceId, files: finished.files || [] }), message: finished.message });
|
|
735
758
|
if (finished.code === 'SLICE_ALREADY_INTEGRATED') return;
|
|
736
759
|
mine.phase = 'rejected';
|
|
737
|
-
return attention(record, { code: finished.code, sliceId, message: `Slice ${sliceId} was not committed: ${finished.message} Inspect the worktree and retry with agent_team integrate.`, report: { violations: finished.violations, stray: finished.stray } });
|
|
760
|
+
return await attention(record, { code: finished.code, sliceId, message: `Slice ${sliceId} was not committed: ${finished.message} Inspect the worktree and retry with agent_team integrate.`, report: { violations: finished.violations, stray: finished.stray } });
|
|
738
761
|
}
|
|
739
762
|
mine.phase = 'done';
|
|
740
763
|
mine.doneAt = iso(now());
|
|
741
|
-
emit(record, 'slice_done', { sliceId, runId, text: `${finished.changed?.length || 0} files${finished.committed ? '' : ' (nothing new to commit)'}${mine.stray?.length ? `, ${mine.stray.length} left out (not its own)` : ''}`, head: finished.head, changed: (finished.changed || []).length, stray: mine.stray || [] });
|
|
764
|
+
await emit(record, 'slice_done', { sliceId, runId, text: `${finished.changed?.length || 0} files${finished.committed ? '' : ' (nothing new to commit)'}${mine.stray?.length ? `, ${mine.stray.length} left out (not its own)` : ''}`, head: finished.head, changed: (finished.changed || []).length, stray: mine.stray || [] });
|
|
742
765
|
return true;
|
|
743
766
|
}
|
|
744
767
|
|
|
@@ -751,7 +774,7 @@ export function createTeamScheduler({
|
|
|
751
774
|
mine.lastReport = { code: kind === 'tests' ? 'TESTS_FAILED' : 'CONFLICT', message: clip(message || '', 600), at: iso(now()), ...(report ? { report: reportBrief(report) } : {}) };
|
|
752
775
|
if (used >= limits.maxRetries) {
|
|
753
776
|
mine.phase = kind === 'tests' ? 'tests_failed' : 'conflict';
|
|
754
|
-
return attention(record, {
|
|
777
|
+
return await attention(record, {
|
|
755
778
|
code: kind === 'tests' ? 'TESTS_FAILED' : 'CONFLICT', sliceId, report, event,
|
|
756
779
|
message: `Slice ${sliceId} ${kind === 'tests' ? 'failed the integration tests' : 'conflicts with the integration branch'} after ${used} ${used === 1 ? 'retry' : 'retries'}: ${message || ''} Decide what happens next (agent_team status has the report): fix the plan, send the worker a hint with agent_send and then agent_team integrate, or discard the team.`,
|
|
757
780
|
});
|
|
@@ -761,8 +784,8 @@ export function createTeamScheduler({
|
|
|
761
784
|
save(record);
|
|
762
785
|
const body = typeof text === 'function' ? text(used + 1) : text;
|
|
763
786
|
const sent = await sendBack(record, sliceId, body, { resolve });
|
|
764
|
-
emit(record, event, { sliceId, runId: mine.runId, attempt: used + 1, of: limits.maxRetries, text: `${clip(message || '', 300)} Sent back to its worker (${sent.ok ? sent.via : 'could not be sent'}).`, ...(report ? { report: reportBrief(report) } : {}) });
|
|
765
|
-
if (!sent.ok) attention(record, { code: sent.code || 'SLICE_NOT_SENT_BACK', sliceId, message: `Slice ${sliceId} could not be sent back to a worker: ${sent.message}`, report });
|
|
787
|
+
await emit(record, event, { sliceId, runId: mine.runId, attempt: used + 1, of: limits.maxRetries, text: `${clip(message || '', 300)} Sent back to its worker (${sent.ok ? sent.via : 'could not be sent'}).`, ...(report ? { report: reportBrief(report) } : {}) });
|
|
788
|
+
if (!sent.ok) await attention(record, { code: sent.code || 'SLICE_NOT_SENT_BACK', sliceId, message: `Slice ${sliceId} could not be sent back to a worker: ${sent.message}`, report });
|
|
766
789
|
}
|
|
767
790
|
|
|
768
791
|
async function handleJoin(record, result) {
|
|
@@ -771,7 +794,7 @@ export function createTeamScheduler({
|
|
|
771
794
|
mine.phase = 'integrated';
|
|
772
795
|
mine.integratedAt = iso(now());
|
|
773
796
|
mine.lastReport = null;
|
|
774
|
-
emit(record, 'integrated', { sliceId: result.sliceId, runId: mine.runId, commit: result.commit, method: result.method, tests: result.tests ? { ok: result.tests.ok === true, exitCode: result.tests.exitCode ?? null } : null, text: `${result.method || 'joined'}${result.tests ? (result.tests.ok ? ', tests passed' : ', tests failed') : ', not tested (no test command)'}` });
|
|
797
|
+
await emit(record, 'integrated', { sliceId: result.sliceId, runId: mine.runId, commit: result.commit, method: result.method, tests: result.tests ? { ok: result.tests.ok === true, exitCode: result.tests.exitCode ?? null } : null, text: `${result.method || 'joined'}${result.tests ? (result.tests.ok ? ', tests passed' : ', tests failed') : ', not tested (no test command)'}` });
|
|
775
798
|
release(record, result.sliceId, 'team_integrated');
|
|
776
799
|
return;
|
|
777
800
|
}
|
|
@@ -787,7 +810,7 @@ export function createTeamScheduler({
|
|
|
787
810
|
}
|
|
788
811
|
if (resolved && !resolved.ok) {
|
|
789
812
|
mine.phase = 'conflict';
|
|
790
|
-
attention(record, { code: resolved.code || 'CONFLICT', sliceId: result.sliceId, message: `Slice ${result.sliceId} conflicts with the integration branch and the conflict could not be brought into its worktree: ${resolved.message}`, report: result.report, event: 'conflict' });
|
|
813
|
+
await attention(record, { code: resolved.code || 'CONFLICT', sliceId: result.sliceId, message: `Slice ${result.sliceId} conflicts with the integration branch and the conflict could not be brought into its worktree: ${resolved.message}`, report: result.report, event: 'conflict' });
|
|
791
814
|
return;
|
|
792
815
|
}
|
|
793
816
|
await retry(record, result.sliceId, 'conflict', {
|
|
@@ -801,7 +824,7 @@ export function createTeamScheduler({
|
|
|
801
824
|
// The slice is the worker's again (its claims with it) before it is told: a live worker keeps its run.
|
|
802
825
|
if (runLive(mineRun) && (Number(mine.attempts?.tests) || 0) < limits.maxRetries) {
|
|
803
826
|
const again = await teams.startSlice(record.teamId, result.sliceId, { runId: mine.runId });
|
|
804
|
-
if (!again.ok) { mine.phase = 'tests_failed'; attention(record, { code: again.code, sliceId: result.sliceId, message: `Slice ${result.sliceId} failed the integration tests and could not be reopened: ${again.message}`, report: result.report, event: 'tests_failed' }); return; }
|
|
827
|
+
if (!again.ok) { mine.phase = 'tests_failed'; await attention(record, { code: again.code, sliceId: result.sliceId, message: `Slice ${result.sliceId} failed the integration tests and could not be reopened: ${again.message}`, report: result.report, event: 'tests_failed' }); return; }
|
|
805
828
|
}
|
|
806
829
|
await retry(record, result.sliceId, 'tests', {
|
|
807
830
|
report: result.report, message: result.message,
|
|
@@ -810,7 +833,7 @@ export function createTeamScheduler({
|
|
|
810
833
|
return;
|
|
811
834
|
}
|
|
812
835
|
mine.phase = 'failed';
|
|
813
|
-
attention(record, { code: result.code || 'INTEGRATION_FAILED', sliceId: result.sliceId, message: `Slice ${result.sliceId} could not be joined: ${result.message}`, report: result.report });
|
|
836
|
+
await attention(record, { code: result.code || 'INTEGRATION_FAILED', sliceId: result.sliceId, message: `Slice ${result.sliceId} could not be joined: ${result.message}`, report: result.report });
|
|
814
837
|
}
|
|
815
838
|
|
|
816
839
|
async function joinFinished(record) {
|
|
@@ -833,7 +856,7 @@ export function createTeamScheduler({
|
|
|
833
856
|
joined = refuse('INTEGRATION_FAILED', `${error?.message || String(error)}. Inspect the integration worktree before retrying.`);
|
|
834
857
|
}
|
|
835
858
|
if (joined.ok === false && !Array.isArray(joined.results)) {
|
|
836
|
-
attention(record, { code: joined.code || 'INTEGRATION_FAILED', message: `The team could not be joined: ${joined.message}` });
|
|
859
|
+
await attention(record, { code: joined.code || 'INTEGRATION_FAILED', message: `The team could not be joined: ${joined.message}` });
|
|
837
860
|
return joined;
|
|
838
861
|
}
|
|
839
862
|
for (const result of joined.results || []) {
|
|
@@ -846,9 +869,9 @@ export function createTeamScheduler({
|
|
|
846
869
|
if (joined.ready && record.status !== 'ready') {
|
|
847
870
|
record.status = 'ready';
|
|
848
871
|
record.attention = null;
|
|
849
|
-
const journal = journalOf(record.teamId);
|
|
872
|
+
const journal = await journalOf(record.teamId);
|
|
850
873
|
const tests = journal?.integration?.tests || null;
|
|
851
|
-
emit(record, 'team_ready', {
|
|
874
|
+
await emit(record, 'team_ready', {
|
|
852
875
|
integrationBranch: integrationBranchName(record.teamId), head: journal?.integration?.head || null,
|
|
853
876
|
tests: tests ? { ok: tests.ok === true, commit: tests.commit || null } : null,
|
|
854
877
|
text: `Every slice is joined on ${integrationBranchName(record.teamId)}${tests ? (tests.ok ? ' and the tests passed on that commit' : ' but the tests have not passed on that commit') : ' (no test command: not tested)'}. Land it with agent_team land when the tests passed, the owner's branch has not moved and no locally changed file is touched; otherwise ask the owner.`,
|
|
@@ -883,7 +906,7 @@ export function createTeamScheduler({
|
|
|
883
906
|
// an idle worker with an empty follow-up outbox, or a successfully ended worker, is done.
|
|
884
907
|
function canFinish(run) {
|
|
885
908
|
return (run?.lastResult?.status || run?.outcome) === 'done' &&
|
|
886
|
-
(run.state === 'completed' || (runIdle(run) && !coordination.followUps?.
|
|
909
|
+
(run.state === 'completed' || (runIdle(run) && !coordination.followUps?.cachedCount(run.runId)));
|
|
887
910
|
}
|
|
888
911
|
|
|
889
912
|
async function reconcileRun(record, sliceId, runId) {
|
|
@@ -891,7 +914,7 @@ export function createTeamScheduler({
|
|
|
891
914
|
if (!OPEN_STATUSES.has(record.status) || mine.runId !== runId || mine.released) return;
|
|
892
915
|
const run = runOf(runId);
|
|
893
916
|
if (!run || (!runIdle(run) && !run.terminal)) return;
|
|
894
|
-
const state = sliceStateOf(journalOf(record.teamId), sliceId);
|
|
917
|
+
const state = sliceStateOf(await journalOf(record.teamId), sliceId);
|
|
895
918
|
if (state === 'integrated' || state === 'completed') return;
|
|
896
919
|
if (record.plan.readOnly && run.terminal) return finishReader(record, sliceId, { failed: !canFinish(run) });
|
|
897
920
|
if (canFinish(run) && (mine.phase === 'finishing' || !mine.handledTurn || run.resultTurn > mine.handledTurn)) {
|
|
@@ -903,7 +926,7 @@ export function createTeamScheduler({
|
|
|
903
926
|
}
|
|
904
927
|
} catch (error) {
|
|
905
928
|
mine.phase = 'failed';
|
|
906
|
-
attention(record, { code: 'SLICE_FINALIZATION_FAILED', sliceId, message: `Could not finalize ${sliceId}: ${error.message}. Inspect its worktree and retry with agent_team integrate.` });
|
|
929
|
+
await attention(record, { code: 'SLICE_FINALIZATION_FAILED', sliceId, message: `Could not finalize ${sliceId}: ${error.message}. Inspect its worktree and retry with agent_team integrate.` });
|
|
907
930
|
}
|
|
908
931
|
return;
|
|
909
932
|
}
|
|
@@ -911,7 +934,7 @@ export function createTeamScheduler({
|
|
|
911
934
|
if (run.terminal) {
|
|
912
935
|
if (state === 'done' && canFinish(run)) return;
|
|
913
936
|
mine.phase = 'failed';
|
|
914
|
-
attention(record, { code: 'SLICE_WORKER_ENDED', sliceId,
|
|
937
|
+
await attention(record, { code: 'SLICE_WORKER_ENDED', sliceId,
|
|
915
938
|
message: `The worker of slice ${sliceId} ended (${run.completionReason || run.state}) before its slice was done. Its files are in its worktree. agent_team integrate gives the slice to a new worker; agent_team discard gives the team up.` });
|
|
916
939
|
} else if (run.outcome !== 'done') {
|
|
917
940
|
mine.phase = 'blocked';
|
|
@@ -920,7 +943,7 @@ export function createTeamScheduler({
|
|
|
920
943
|
}
|
|
921
944
|
}
|
|
922
945
|
|
|
923
|
-
function onDispatch(payload) {
|
|
946
|
+
async function onDispatch(payload) {
|
|
924
947
|
if (closed || payload?.type !== 'assistant:dispatch') return;
|
|
925
948
|
const runId = payload.run?.runId;
|
|
926
949
|
const ref = runIndex.get(runId);
|
|
@@ -932,9 +955,9 @@ export function createTeamScheduler({
|
|
|
932
955
|
if (payload.turn <= mine.handledTurn || runOf(runId)?.state !== 'running') return;
|
|
933
956
|
// The dispatcher announces the new turn before handing its prompt to the worker.
|
|
934
957
|
// A finished slice gave back its claims; restore them before the follow-up edits.
|
|
935
|
-
if (['done', 'integrating'].includes(sliceStateOf(journalOf(record.teamId), ref.sliceId))) {
|
|
936
|
-
const claims = teams.modules.claims.assign(record.teamId, ref.sliceId, runId);
|
|
937
|
-
if (!claims.ok) return attention(record, { code: claims.code, sliceId: ref.sliceId, message: claims.message });
|
|
958
|
+
if (['done', 'integrating'].includes(sliceStateOf(await journalOf(record.teamId), ref.sliceId))) {
|
|
959
|
+
const claims = await teams.modules.claims.assign(record.teamId, ref.sliceId, runId);
|
|
960
|
+
if (!claims.ok) return await attention(record, { code: claims.code, sliceId: ref.sliceId, message: claims.message });
|
|
938
961
|
mine.phase = 'working';
|
|
939
962
|
save(record);
|
|
940
963
|
}
|
|
@@ -947,15 +970,20 @@ export function createTeamScheduler({
|
|
|
947
970
|
}
|
|
948
971
|
}
|
|
949
972
|
|
|
950
|
-
function checkProgress() {
|
|
973
|
+
async function checkProgress() {
|
|
974
|
+
markActivity('scheduler:teams');
|
|
951
975
|
if (closed) return;
|
|
976
|
+
const cutoff = now() - limits.postWindowMs;
|
|
977
|
+
for (const [runId, times] of postTimes) {
|
|
978
|
+
if (times.at(-1) <= cutoff) postTimes.delete(runId);
|
|
979
|
+
}
|
|
952
980
|
for (const record of records.values()) {
|
|
953
981
|
if (!['running', 'needs_attention'].includes(record.status)) continue;
|
|
954
|
-
const journal = journalOf(record.teamId);
|
|
982
|
+
const journal = await journalOf(record.teamId);
|
|
955
983
|
const under = journal?.integrating;
|
|
956
984
|
if (under && now() - under.startedAt >= limits.joinOverdueMs && record.alertedJoin !== under.startedAt) {
|
|
957
985
|
record.alertedJoin = under.startedAt;
|
|
958
|
-
emit(record, 'needs_attention', { code: 'JOIN_OVERDUE', sliceId: under.sliceId,
|
|
986
|
+
await emit(record, 'needs_attention', { code: 'JOIN_OVERDUE', sliceId: under.sliceId,
|
|
959
987
|
text: `Integration has been ${under.phase} for ${Math.floor((now() - under.startedAt) / 60000)} minutes. Inspect agent_team status and the integration worktree before retrying.`,
|
|
960
988
|
phase: under.phase, startedAt: under.startedAt, candidate: under.candidate || null });
|
|
961
989
|
}
|
|
@@ -974,6 +1002,72 @@ export function createTeamScheduler({
|
|
|
974
1002
|
}
|
|
975
1003
|
}
|
|
976
1004
|
|
|
1005
|
+
// Lead amendments share the join reservation and all slice finalization reservations.
|
|
1006
|
+
function amend(teamId, fn) {
|
|
1007
|
+
const record = records.get(teamId);
|
|
1008
|
+
if (!record) return Promise.resolve(refuse('TEAM_NOT_FOUND', `No team named "${teamId}" is known here.`));
|
|
1009
|
+
return teamStep(record, async () => {
|
|
1010
|
+
const journal = await journalOf(teamId);
|
|
1011
|
+
if (!journal) return refuse('TEAM_NOT_FOUND', `No journal for team "${teamId}".`);
|
|
1012
|
+
if (journal.plan.readOnly) return refuse('TEAM_READ_ONLY', 'Research and review teams have read-only slices.');
|
|
1013
|
+
if (!OPEN_STATUSES.has(record.status) || journal.removed || !['planned', 'running', 'ready'].includes(journal.state)) {
|
|
1014
|
+
return refuse('TEAM_NOT_ACTIVE', `Team "${teamId}" cannot be amended in state ${journal.state}.`);
|
|
1015
|
+
}
|
|
1016
|
+
return fn(record, journal);
|
|
1017
|
+
});
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
function assign(teamId, { sliceId, paths } = {}) {
|
|
1021
|
+
return amend(teamId, async (record, journal) => {
|
|
1022
|
+
const result = await teams.modules.claims.assignPaths(journal, sliceId, paths);
|
|
1023
|
+
if (!result.ok) return result;
|
|
1024
|
+
record.plan.slices.find(slice => slice.id === sliceId).ownedPaths = result.ownedPaths;
|
|
1025
|
+
save(record);
|
|
1026
|
+
const runId = record.slices[sliceId].runId;
|
|
1027
|
+
const current = sliceStateOf(journal, sliceId);
|
|
1028
|
+
let notification = 'next_worker_brief';
|
|
1029
|
+
if (member(runId)) {
|
|
1030
|
+
const requested = [...result.requested].sort();
|
|
1031
|
+
const digest = createHash('sha256').update(JSON.stringify(requested)).digest('hex');
|
|
1032
|
+
let posted;
|
|
1033
|
+
try {
|
|
1034
|
+
posted = await coordination.team.post({
|
|
1035
|
+
id: `team:${teamId}:assign:${runId}:${digest}`, teamId, sessionId: record.sessionId, to: [runId],
|
|
1036
|
+
payload: { messageKind: 'request_change', to: 'slice', toSlice: sliceId },
|
|
1037
|
+
text: `The lead assigned these paths to your slice: ${clip(requested.join(', '), 3000)}. Check your current ownership with team claims and make the requested change when your slice is working.`,
|
|
1038
|
+
});
|
|
1039
|
+
} catch (error) {
|
|
1040
|
+
return refuse('ASSIGN_NOTIFICATION_FAILED', `Ownership was saved. Retry the same assignment to confirm mailbox delivery. ${error.message}`,
|
|
1041
|
+
{ teamId, sliceId, ownedPaths: result.ownedPaths });
|
|
1042
|
+
}
|
|
1043
|
+
notification = 'mailbox';
|
|
1044
|
+
if (current === 'running' && runIdle(runOf(runId))) {
|
|
1045
|
+
const event = posted.duplicate
|
|
1046
|
+
? (await waitingMessages(teamId, runId)).find(row => row.id === posted.id)
|
|
1047
|
+
: await store.get(posted.id);
|
|
1048
|
+
if (event && await pushTo(record, runId, [event])) notification = 'follow-up';
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
const retry = ['conflict', 'tests-failed', 'rejected'].includes(current) || (current === 'running' && !member(runId));
|
|
1052
|
+
return { ok: true, teamId, sliceId, ownedPaths: result.ownedPaths, notification,
|
|
1053
|
+
...(retry ? { next: `Call agent_team integrate with team_id "${teamId}" and slice_id "${sliceId}" to resume the slice.` } : {}) };
|
|
1054
|
+
});
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
function setTestCommand(teamId, value) {
|
|
1058
|
+
return amend(teamId, async (_record, journal) => {
|
|
1059
|
+
const command = testCommandOf(value);
|
|
1060
|
+
if (!command) return refuse('INVALID_TEST_COMMAND', 'Give the test command that proves the joined work.');
|
|
1061
|
+
// The current head can be back at base after a failed join. Its journal entry survives rollback and restart.
|
|
1062
|
+
const entries = await teams.modules.state.entriesOf(teamId);
|
|
1063
|
+
if (entries.some(entry => !entry.sliceId && entry.state === 'integrating')) {
|
|
1064
|
+
return refuse('JOIN_ALREADY_STARTED', 'The test command is fixed once the first join starts.');
|
|
1065
|
+
}
|
|
1066
|
+
await teams.modules.state.writeTeam(teamId, journal.state, { testCommand: command });
|
|
1067
|
+
return { ok: true, teamId, testCommand: command };
|
|
1068
|
+
});
|
|
1069
|
+
}
|
|
1070
|
+
|
|
977
1071
|
// ── retry, land, discard ───────────────────────────────────────────────────
|
|
978
1072
|
/**
|
|
979
1073
|
* Take a team that needs attention up again (the Assistant's `integrate`): every slice is looked at as the
|
|
@@ -989,7 +1083,7 @@ export function createTeamScheduler({
|
|
|
989
1083
|
return inTurn(record.teamId, async () => {
|
|
990
1084
|
await withAllSlices(record, async () => {
|
|
991
1085
|
if (record.status === 'needs_attention') { record.status = 'running'; record.attention = null; }
|
|
992
|
-
const journal = journalOf(record.teamId);
|
|
1086
|
+
const journal = await journalOf(record.teamId);
|
|
993
1087
|
for (const slice of record.plan.slices) {
|
|
994
1088
|
if (sliceId && slice.id !== sliceId) continue;
|
|
995
1089
|
const mine = record.slices[slice.id];
|
|
@@ -1003,11 +1097,11 @@ export function createTeamScheduler({
|
|
|
1003
1097
|
let conflicts = [];
|
|
1004
1098
|
let resolved = null;
|
|
1005
1099
|
if (runLive(run)) { resolved = await teams.resolveInSlice(record.teamId, slice.id, { runId: mine.runId }); conflicts = resolved.ok ? resolved.conflicts || [] : []; }
|
|
1006
|
-
if (resolved && !resolved.ok) { attention(record, { code: resolved.code, sliceId: slice.id, message: `Slice ${slice.id}: ${resolved.message}` }); continue; }
|
|
1100
|
+
if (resolved && !resolved.ok) { await attention(record, { code: resolved.code, sliceId: slice.id, message: `Slice ${slice.id}: ${resolved.message}` }); continue; }
|
|
1007
1101
|
await retry(record, slice.id, 'conflict', { report, message: 'Conflicts with the integration branch.', resolve: !resolved, text: (attempt) => conflictFollowUp({ teamId: record.teamId, sliceId: slice.id, report, conflicts, attempt, maxAttempts: limits.maxRetries }) });
|
|
1008
1102
|
} else if (state === 'tests-failed') {
|
|
1009
1103
|
const report = { tests: journal.slices[slice.id]?.tests || {} };
|
|
1010
|
-
if (runLive(run)) { const again = await teams.startSlice(record.teamId, slice.id, { runId: mine.runId }); if (!again.ok) { attention(record, { code: again.code, sliceId: slice.id, message: `Slice ${slice.id}: ${again.message}` }); continue; } }
|
|
1104
|
+
if (runLive(run)) { const again = await teams.startSlice(record.teamId, slice.id, { runId: mine.runId }); if (!again.ok) { await attention(record, { code: again.code, sliceId: slice.id, message: `Slice ${slice.id}: ${again.message}` }); continue; } }
|
|
1011
1105
|
await retry(record, slice.id, 'tests', { report, message: 'The integration tests failed.', text: (attempt) => testsFailedFollowUp({ teamId: record.teamId, sliceId: slice.id, report, attempt, maxAttempts: limits.maxRetries }) });
|
|
1012
1106
|
} else if (state === 'rejected') {
|
|
1013
1107
|
if (canFinish(run)) await sliceReportedDone(record, slice.id, mine.runId);
|
|
@@ -1015,7 +1109,7 @@ export function createTeamScheduler({
|
|
|
1015
1109
|
} else if (!runLive(run)) {
|
|
1016
1110
|
// Its worker is gone and the slice is not finished: a new worker takes it up where the files are.
|
|
1017
1111
|
const out = await dispatchSlice(record, slice.id, { rework: true, lead: `You take over slice ${slice.id} of team ${record.teamId} from a worker that ended before it was done. What it changed so far is in your worktree, uncommitted: read it (git status, git diff) and finish the slice.` });
|
|
1018
|
-
if (!out.ok) attention(record, { code: out.code || 'SLICE_NOT_STARTED', sliceId: slice.id, message: `Slice ${slice.id} could not be given to a new worker: ${out.message}` });
|
|
1112
|
+
if (!out.ok) await attention(record, { code: out.code || 'SLICE_NOT_STARTED', sliceId: slice.id, message: `Slice ${slice.id} could not be given to a new worker: ${out.message}` });
|
|
1019
1113
|
} else if (canFinish(run)) {
|
|
1020
1114
|
await sliceReportedDone(record, slice.id, mine.runId);
|
|
1021
1115
|
}
|
|
@@ -1037,7 +1131,7 @@ export function createTeamScheduler({
|
|
|
1037
1131
|
if (!record) return Promise.resolve(refuse('TEAM_NOT_FOUND', `No team named "${teamId}" is known here.`, { status: 404 }));
|
|
1038
1132
|
if (record.plan.readOnly) return Promise.resolve(refuse('TEAM_READ_ONLY', 'Research/review teams have no integration or landing.', { status: 409 }));
|
|
1039
1133
|
return teamStep(record, async () => {
|
|
1040
|
-
const journal = journalOf(record.teamId);
|
|
1134
|
+
const journal = await journalOf(record.teamId);
|
|
1041
1135
|
if (!journal) return refuse('TEAM_NOT_FOUND', `Team "${teamId}" has no record in the journal.`, { status: 404 });
|
|
1042
1136
|
const assistant = by?.kind !== 'owner';
|
|
1043
1137
|
const target = targetBranch ? String(targetBranch) : ((await branchOf(record.projectPath)) || journal.baseBranch || null);
|
|
@@ -1073,7 +1167,7 @@ export function createTeamScheduler({
|
|
|
1073
1167
|
branches: [...record.plan.slices.map(s => branchName(record.teamId, s.id)), integrationBranchName(record.teamId)],
|
|
1074
1168
|
next: 'When the task is fully finished, suggest deleting these worktrees and branches with a confirm follow-up; call agent_team action cleanup with user_confirmed true only after the user says yes.',
|
|
1075
1169
|
};
|
|
1076
|
-
emit(record, 'landed', {
|
|
1170
|
+
await emit(record, 'landed', {
|
|
1077
1171
|
targetBranch: landed.landed?.targetBranch || target, mode: landed.landed?.mode || mode, to: landed.landed?.to || null,
|
|
1078
1172
|
text: `Landed on ${landed.landed?.targetBranch || target} (${landed.landed?.mode || mode}); worktrees and branches kept pending confirmed cleanup.`, by: by?.kind || 'owner',
|
|
1079
1173
|
}, { quiet: assistant && by?.sessionId === record.sessionId });
|
|
@@ -1133,7 +1227,7 @@ export function createTeamScheduler({
|
|
|
1133
1227
|
if (!out.ok) return { ...out, checks: [...checks, ...(out.checks || [])] };
|
|
1134
1228
|
record.cleanedAt = iso(now());
|
|
1135
1229
|
record.cleanup = { complete: true, removed: out.removed };
|
|
1136
|
-
emit(record, 'team_cleaned', { text: 'Confirmed cleanup removed the team worktrees and branches.' });
|
|
1230
|
+
await emit(record, 'team_cleaned', { text: 'Confirmed cleanup removed the team worktrees and branches.' });
|
|
1137
1231
|
return { ok: true, teamId: record.teamId, removed: out.removed, ...(!verified ? { confirmation: 'unverified' } : {}) };
|
|
1138
1232
|
});
|
|
1139
1233
|
}
|
|
@@ -1151,7 +1245,7 @@ export function createTeamScheduler({
|
|
|
1151
1245
|
const record = records.get(String(teamId || ''));
|
|
1152
1246
|
if (!record) return Promise.resolve(refuse('TEAM_NOT_FOUND', `No team named "${teamId}" is known here.`, { status: 404 }));
|
|
1153
1247
|
return teamStep(record, async () => {
|
|
1154
|
-
const journal = journalOf(record.teamId);
|
|
1248
|
+
const journal = await journalOf(record.teamId);
|
|
1155
1249
|
if (journal?.state === 'merged') return refuse('ALREADY_LANDED', `Team "${teamId}" has landed: there is nothing to discard.`, { status: 409 });
|
|
1156
1250
|
if (record.status === 'discarded' && journal?.removed) return { ok: true, already: true, cleanup: record.cleanup };
|
|
1157
1251
|
const assistant = by?.kind !== 'owner';
|
|
@@ -1161,7 +1255,7 @@ export function createTeamScheduler({
|
|
|
1161
1255
|
record.status = 'discarded';
|
|
1162
1256
|
record.attention = null;
|
|
1163
1257
|
record.cleanup = { complete: removed.complete === true, kept: (removed.kept || []).map((item) => ({ sliceId: item.sliceId, path: item.path, branch: item.branch, reason: item.reason, files: (item.files || []).slice(0, 20), commits: item.commits ?? null })) };
|
|
1164
|
-
emit(record, 'discarded', {
|
|
1258
|
+
await emit(record, 'discarded', {
|
|
1165
1259
|
text: `Discarded${reason ? `: ${clip(reason, 200)}` : ''}. ${removed.complete ? 'Worktrees and branches removed.' : `${record.cleanup.kept.length} worktree${record.cleanup.kept.length === 1 ? '' : 's'} or branch${record.cleanup.kept.length === 1 ? '' : 'es'} kept because work is in them.`}`, by: by?.kind || 'owner',
|
|
1166
1260
|
}, { quiet: assistant && by?.sessionId === record.sessionId });
|
|
1167
1261
|
return { ok: true, stopped, complete: removed.complete === true, removed: removed.removed || [], kept: record.cleanup.kept };
|
|
@@ -1201,13 +1295,13 @@ export function createTeamScheduler({
|
|
|
1201
1295
|
}
|
|
1202
1296
|
|
|
1203
1297
|
/** Hand messages to a worker that waits warm: one follow-up, named as untrusted peer content. → delivered or not. */
|
|
1204
|
-
function pushTo(record, recipientRunId, events) {
|
|
1298
|
+
async function pushTo(record, recipientRunId, events) {
|
|
1205
1299
|
const dispatcher = dispatcherOf();
|
|
1206
1300
|
const run = runOf(recipientRunId);
|
|
1207
1301
|
if (!dispatcher || !runIdle(run)) return false;
|
|
1208
1302
|
try {
|
|
1209
|
-
dispatcher.sendTurn(recipientRunId, peerMessagesText(record.teamId, events.map(messageView)), { origin: 'peer', queue: false });
|
|
1210
|
-
coordination.team.ack({ teamId: record.teamId, runId: recipientRunId, eventIds: events.map((event) => event.id) });
|
|
1303
|
+
await dispatcher.sendTurn(recipientRunId, peerMessagesText(record.teamId, events.map(messageView)), { origin: 'peer', queue: false });
|
|
1304
|
+
await coordination.team.ack({ teamId: record.teamId, runId: recipientRunId, eventIds: events.map((event) => event.id) });
|
|
1211
1305
|
return true;
|
|
1212
1306
|
} catch (error) {
|
|
1213
1307
|
say('teams:peer-push-failed', { teamId: record.teamId, runId: recipientRunId, error: error?.code || error?.message || String(error) });
|
|
@@ -1221,7 +1315,7 @@ export function createTeamScheduler({
|
|
|
1221
1315
|
* recipient's own mailbox; a recipient that waits warm gets it as a follow-up at once, a working one at its next
|
|
1222
1316
|
* `team` call or when its turn ends.
|
|
1223
1317
|
*/
|
|
1224
|
-
function post(runId, { to = 'board', kind = 'note', text = '', path = null, id = null } = {}) {
|
|
1318
|
+
async function post(runId, { to = 'board', kind = 'note', text = '', path = null, id = null } = {}) {
|
|
1225
1319
|
const who = member(runId);
|
|
1226
1320
|
if (!who) return noMember();
|
|
1227
1321
|
const record = records.get(who.teamId);
|
|
@@ -1248,7 +1342,7 @@ export function createTeamScheduler({
|
|
|
1248
1342
|
const payload = { messageKind, fromSlice: who.sliceId, to: toSlice ? 'slice' : (target === 'lead' ? 'lead' : 'board'), ...(toSlice ? { toSlice } : {}), ...(path ? { path: String(path).slice(0, 400) } : {}) };
|
|
1249
1343
|
let out;
|
|
1250
1344
|
try {
|
|
1251
|
-
out = coordination.team.post({
|
|
1345
|
+
out = await coordination.team.post({
|
|
1252
1346
|
teamId: who.teamId, fromRunId: String(runId), kind: TEAM_MESSAGE_LOG_KIND, text: body, payload,
|
|
1253
1347
|
// Each recipient's own mailbox; the team's log has every message (the lead reads it there: agent_team status).
|
|
1254
1348
|
to: recipients.map((each) => each.runId),
|
|
@@ -1260,14 +1354,14 @@ export function createTeamScheduler({
|
|
|
1260
1354
|
}
|
|
1261
1355
|
const delivered = [];
|
|
1262
1356
|
if (!out.duplicate) {
|
|
1263
|
-
const event = store.get(out.id);
|
|
1357
|
+
const event = await store.get(out.id);
|
|
1264
1358
|
for (const each of recipients) {
|
|
1265
|
-
const pushed = event ? pushTo(record, each.runId, [event]) : false;
|
|
1359
|
+
const pushed = event ? await pushTo(record, each.runId, [event]) : false;
|
|
1266
1360
|
delivered.push({ sliceId: each.sliceId, how: pushed ? 'follow-up' : 'mailbox' });
|
|
1267
1361
|
}
|
|
1268
1362
|
// The lead (the Assistant) hears what is addressed to it, and a question or change request nobody else got.
|
|
1269
1363
|
if (target === 'lead' || (toLead && !recipients.length && TEAM_ACTION_KINDS.includes(messageKind))) {
|
|
1270
|
-
emit(record, 'team_message', { sliceId: who.sliceId, runId: String(runId), messageKind, text: `[${messageKind}] from slice ${who.sliceId}: ${body}`, untrusted: true, ...(path ? { path: String(path).slice(0, 400) } : {}) });
|
|
1364
|
+
await emit(record, 'team_message', { sliceId: who.sliceId, runId: String(runId), messageKind, text: `[${messageKind}] from slice ${who.sliceId}: ${body}`, untrusted: true, ...(path ? { path: String(path).slice(0, 400) } : {}) });
|
|
1271
1365
|
delivered.push({ sliceId: null, how: 'lead' });
|
|
1272
1366
|
} else {
|
|
1273
1367
|
try { broadcast({ type: TEAM_CHANGED, teamId: record.teamId, event: 'message', status: record.status, sliceId: who.sliceId }); } catch { /* no page is listening */ }
|
|
@@ -1284,16 +1378,16 @@ export function createTeamScheduler({
|
|
|
1284
1378
|
const seqOf = (value) => { if (value === null || value === undefined || value === '') return null; const n = Number(value); return Number.isInteger(n) && n >= 0 ? n : null; };
|
|
1285
1379
|
|
|
1286
1380
|
/** A member's messages after a position (default: what it has not acknowledged), oldest first. */
|
|
1287
|
-
function read(runId, { afterSeq = null, kinds = null, limit = null } = {}) {
|
|
1381
|
+
async function read(runId, { afterSeq = null, kinds = null, limit = null } = {}) {
|
|
1288
1382
|
const who = member(runId);
|
|
1289
1383
|
if (!who) return noMember();
|
|
1290
1384
|
const wanted = kindsOf(kinds);
|
|
1291
1385
|
const max = Math.max(1, Math.min(limits.readLimit, Number(limit) || limits.readLimit));
|
|
1292
1386
|
const cursor = seqOf(afterSeq);
|
|
1293
1387
|
let rows = [];
|
|
1294
|
-
try { rows = coordination.team.read({ teamId: who.teamId, runId: String(runId), afterSeq: cursor, limit: 200 }); } catch (error) { return refuse(error?.code || 'TEAM_READ_FAILED', error?.message || String(error), { status: Number(error?.status) || 400 }); }
|
|
1388
|
+
try { rows = await coordination.team.read({ teamId: who.teamId, runId: String(runId), afterSeq: cursor, limit: 200 }); } catch (error) { return refuse(error?.code || 'TEAM_READ_FAILED', error?.message || String(error), { status: Number(error?.status) || 400 }); }
|
|
1295
1389
|
const messages = rows.filter((event) => event.kind === TEAM_MESSAGE_LOG_KIND).map(messageView).filter((message) => !wanted || wanted.includes(message.kind)).slice(0, max);
|
|
1296
|
-
const last = rows.length ? rows[rows.length - 1].seq : (cursor ?? coordination.team.cursor({ teamId: who.teamId, runId: String(runId) }));
|
|
1390
|
+
const last = rows.length ? rows[rows.length - 1].seq : (cursor ?? await coordination.team.cursor({ teamId: who.teamId, runId: String(runId) }));
|
|
1297
1391
|
return { ok: true, teamId: who.teamId, sliceId: who.sliceId, untrusted: true, notice: PEER_NOTICE, messages, cursor: messages.length === max && messages.length ? messages[messages.length - 1].seq : last };
|
|
1298
1392
|
}
|
|
1299
1393
|
|
|
@@ -1305,7 +1399,7 @@ export function createTeamScheduler({
|
|
|
1305
1399
|
const deadline = now() + budget;
|
|
1306
1400
|
let cursor = seqOf(afterSeq);
|
|
1307
1401
|
for (;;) {
|
|
1308
|
-
const got = read(runId, { afterSeq: cursor, kinds });
|
|
1402
|
+
const got = await read(runId, { afterSeq: cursor, kinds });
|
|
1309
1403
|
if (!got.ok) return got;
|
|
1310
1404
|
if (got.messages.length) return { ...got, timedOut: false };
|
|
1311
1405
|
cursor = got.cursor ?? cursor;
|
|
@@ -1321,31 +1415,31 @@ export function createTeamScheduler({
|
|
|
1321
1415
|
}
|
|
1322
1416
|
|
|
1323
1417
|
/** The member dealt with these messages (their ids), or with everything up to a seq. */
|
|
1324
|
-
function ack(runId, { ids = null, throughSeq = null } = {}) {
|
|
1418
|
+
async function ack(runId, { ids = null, throughSeq = null } = {}) {
|
|
1325
1419
|
const who = member(runId);
|
|
1326
1420
|
if (!who) return noMember();
|
|
1327
1421
|
const through = seqOf(throughSeq);
|
|
1328
1422
|
const eventIds = (Array.isArray(ids) ? ids : (ids ? [ids] : [])).map(String).slice(0, 200);
|
|
1329
1423
|
if (through === null && !eventIds.length) return refuse('TEAM_ACK_EMPTY', 'Name the message ids, or through_seq.', { status: 400 });
|
|
1330
1424
|
try {
|
|
1331
|
-
const out = coordination.team.ack({ teamId: who.teamId, runId: String(runId), ...(through !== null ? { throughSeq: through } : { eventIds }) });
|
|
1425
|
+
const out = await coordination.team.ack({ teamId: who.teamId, runId: String(runId), ...(through !== null ? { throughSeq: through } : { eventIds }) });
|
|
1332
1426
|
return { ok: true, acked: out.acked, cursor: out.cursor };
|
|
1333
1427
|
} catch (error) { return refuse(error?.code || 'TEAM_ACK_FAILED', error?.message || String(error), { status: Number(error?.status) || 400 }); }
|
|
1334
1428
|
}
|
|
1335
1429
|
|
|
1336
1430
|
/** Who owns a path of the project (with `path`), or every slice with what it owns. */
|
|
1337
|
-
function claims(runId, { path = null } = {}) {
|
|
1431
|
+
async function claims(runId, { path = null } = {}) {
|
|
1338
1432
|
const who = member(runId);
|
|
1339
1433
|
if (!who) return noMember();
|
|
1340
1434
|
const record = records.get(who.teamId);
|
|
1341
|
-
const journal = journalOf(who.teamId);
|
|
1435
|
+
const journal = await journalOf(who.teamId);
|
|
1342
1436
|
const plan = journal?.plan || record.plan;
|
|
1343
1437
|
if (path !== null && path !== undefined && String(path).trim()) {
|
|
1344
1438
|
const verdict = teams.checkWrite(who.teamId, who.sliceId, String(path));
|
|
1345
1439
|
return { ok: true, teamId: who.teamId, sliceId: who.sliceId, path: verdict.relPath || String(path), owner: verdict.owner ?? null, mine: verdict.owner === who.sliceId, writable: verdict.allow === true, code: verdict.code, message: verdict.message || null };
|
|
1346
1440
|
}
|
|
1347
1441
|
let held = [];
|
|
1348
|
-
try { held = store.claimsFor({ teamId: who.teamId }); } catch { held = []; }
|
|
1442
|
+
try { held = await store.claimsFor({ teamId: who.teamId }); } catch { held = []; }
|
|
1349
1443
|
return {
|
|
1350
1444
|
ok: true, teamId: who.teamId, sliceId: who.sliceId,
|
|
1351
1445
|
slices: plan.slices.map((slice) => ({
|
|
@@ -1357,11 +1451,11 @@ export function createTeamScheduler({
|
|
|
1357
1451
|
}
|
|
1358
1452
|
|
|
1359
1453
|
/** Ask the slice that owns a file outside the caller's claim to change it. Nobody open owns it: the lead is asked. */
|
|
1360
|
-
function request(runId, { path = '', text = '' } = {}) {
|
|
1454
|
+
async function request(runId, { path = '', text = '' } = {}) {
|
|
1361
1455
|
const who = member(runId);
|
|
1362
1456
|
if (!who) return noMember();
|
|
1363
1457
|
const record = records.get(who.teamId);
|
|
1364
|
-
const plan = journalOf(who.teamId)?.plan || record.plan;
|
|
1458
|
+
const plan = (await journalOf(who.teamId))?.plan || record.plan;
|
|
1365
1459
|
const rel = normalizeRelPath(String(path || ''));
|
|
1366
1460
|
if (!rel) return refuse('TEAM_PATH_REQUIRED', 'path is required: the file you need changed, relative to the project.', { status: 400 });
|
|
1367
1461
|
const body = String(text ?? '').trim();
|
|
@@ -1369,7 +1463,7 @@ export function createTeamScheduler({
|
|
|
1369
1463
|
const owner = pathOwner(plan, rel);
|
|
1370
1464
|
if (owner === who.sliceId) return refuse('TEAM_OWN_FILE', `${rel} is your own file: change it yourself.`, { status: 400, owner });
|
|
1371
1465
|
const open = owner ? liveMembers(record).some((each) => each.sliceId === owner) : false;
|
|
1372
|
-
const sent = post(runId, { to: open ? owner : 'lead', kind: 'request_change', path: rel, text: open ? body : `${owner ? `The owner of ${rel} (slice ${owner}) has no worker now` : `No slice owns ${rel}`}. Requested change: ${body}` });
|
|
1466
|
+
const sent = await post(runId, { to: open ? owner : 'lead', kind: 'request_change', path: rel, text: open ? body : `${owner ? `The owner of ${rel} (slice ${owner}) has no worker now` : `No slice owns ${rel}`}. Requested change: ${body}` });
|
|
1373
1467
|
if (!sent.ok) return sent;
|
|
1374
1468
|
return { ...sent, path: rel, owner: owner || null, askedOf: open ? `slice ${owner}` : 'lead', note: open ? `Slice ${owner} was asked. Wait for its answer with the team tool (wait, kinds ["answer"]) or go on with what does not depend on it.` : 'The team lead (the Assistant) was asked: go on with what does not depend on it, and say in your ## Result block what is still open.' };
|
|
1375
1469
|
}
|
|
@@ -1392,7 +1486,7 @@ export function createTeamScheduler({
|
|
|
1392
1486
|
if (!OPEN_STATUSES.has(record.status)) continue;
|
|
1393
1487
|
out.push(await inTurn(record.teamId, async () => {
|
|
1394
1488
|
await withAllSlices(record, async () => {
|
|
1395
|
-
const journal = journalOf(record.teamId);
|
|
1489
|
+
const journal = await journalOf(record.teamId);
|
|
1396
1490
|
if (!journal) { record.status = 'failed'; record.attention = { code: 'TEAM_RECORD_MISSING', sliceId: null, message: 'The team has no record in the journal any more.', at: iso(now()) }; save(record); return { teamId: record.teamId, status: record.status }; }
|
|
1397
1491
|
if (journal.state === 'merged') { record.status = 'landed'; save(record); return { teamId: record.teamId, status: record.status }; }
|
|
1398
1492
|
if (journal.state === 'cancelled' || journal.state === 'failed') { record.status = journal.state === 'failed' ? 'failed' : 'discarded'; save(record); return { teamId: record.teamId, status: record.status }; }
|
|
@@ -1421,10 +1515,10 @@ export function createTeamScheduler({
|
|
|
1421
1515
|
if (runLive(run)) continue;
|
|
1422
1516
|
if (['running', 'conflict', 'tests-failed', 'rejected'].includes(state) && record.status === 'running') {
|
|
1423
1517
|
mine.phase = 'failed';
|
|
1424
|
-
attention(record, { code: 'SLICE_WORKER_LOST', sliceId: slice.id, message: `The worker of slice ${slice.id} did not come back after the restart. Its files are in its worktree. agent_team integrate gives the slice to a new worker.` });
|
|
1518
|
+
await attention(record, { code: 'SLICE_WORKER_LOST', sliceId: slice.id, message: `The worker of slice ${slice.id} did not come back after the restart. Its files are in its worktree. agent_team integrate gives the slice to a new worker.` });
|
|
1425
1519
|
}
|
|
1426
1520
|
}
|
|
1427
|
-
if (record.plan.readOnly && Object.values(record.slices).every(s => s.released) && record.status === 'running') { record.status = 'completed'; emit(record, 'team_completed', { text: 'Read-only workers finished; synthesize their results.' }); }
|
|
1521
|
+
if (record.plan.readOnly && Object.values(record.slices).every(s => s.released) && record.status === 'running') { record.status = 'completed'; await emit(record, 'team_completed', { text: 'Read-only workers finished; synthesize their results.' }); }
|
|
1428
1522
|
});
|
|
1429
1523
|
if (!record.plan.readOnly && OPEN_STATUSES.has(record.status) && record.status !== 'needs_attention') await joinFinished(record);
|
|
1430
1524
|
save(record);
|
|
@@ -1438,8 +1532,12 @@ export function createTeamScheduler({
|
|
|
1438
1532
|
if (unsubscribe || closed) return;
|
|
1439
1533
|
const dispatcher = dispatcherOf();
|
|
1440
1534
|
if (dispatcher && typeof dispatcher.subscribe === 'function') {
|
|
1441
|
-
unsubscribe = dispatcher.subscribe(onDispatch);
|
|
1442
|
-
watchdog = setInterval(
|
|
1535
|
+
unsubscribe = dispatcher.subscribe(payload => track(onDispatch(payload)));
|
|
1536
|
+
watchdog = setInterval(() => {
|
|
1537
|
+
if (watchdogPass) return;
|
|
1538
|
+
watchdogPass = track(checkProgress()).catch(error => say('teams:watchdog-failed', error.message))
|
|
1539
|
+
.finally(() => { watchdogPass = null; });
|
|
1540
|
+
}, limits.reconcileEveryMs);
|
|
1443
1541
|
watchdog.unref?.();
|
|
1444
1542
|
}
|
|
1445
1543
|
}
|
|
@@ -1448,6 +1546,7 @@ export function createTeamScheduler({
|
|
|
1448
1546
|
closed = true;
|
|
1449
1547
|
clearInterval(watchdog);
|
|
1450
1548
|
if (unsubscribe) { try { unsubscribe(); } catch { /* gone already */ } unsubscribe = null; }
|
|
1549
|
+
await Promise.allSettled([...background]);
|
|
1451
1550
|
await settled();
|
|
1452
1551
|
}
|
|
1453
1552
|
|
|
@@ -1455,10 +1554,10 @@ export function createTeamScheduler({
|
|
|
1455
1554
|
|
|
1456
1555
|
return Object.freeze({
|
|
1457
1556
|
limits,
|
|
1458
|
-
plan, start, status, list, get, ownedBy, integrate, land, cleanup, discard,
|
|
1557
|
+
plan, start, status, list, get, ownedBy, assign, setTestCommand, integrate, land, cleanup, discard,
|
|
1459
1558
|
// the channel of a worker's `team` tool (the caller's proven run id decides the team)
|
|
1460
1559
|
member, post, read, wait, ack, claims, request,
|
|
1461
|
-
recover, attach, shutdown, settled,
|
|
1560
|
+
recover: () => track(recover()), attach, shutdown, settled,
|
|
1462
1561
|
_internals: { records, runIndex, onDispatch, joinFinished, startReady, dispatchSlice, emit },
|
|
1463
1562
|
});
|
|
1464
1563
|
}
|