oh-my-codex 0.21.48 → 0.22.1
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/Cargo.lock +6 -6
- package/Cargo.toml +1 -1
- package/README.md +15 -0
- package/crates/omx-mux/src/herdr.rs +481 -0
- package/crates/omx-mux/src/lib.rs +5 -0
- package/dist/cli/__tests__/plugin-cache-live-pin-3790.test.js +104 -3
- package/dist/cli/__tests__/plugin-cache-live-pin-3790.test.js.map +1 -1
- package/dist/cli/__tests__/question.test.js +33 -0
- package/dist/cli/__tests__/question.test.js.map +1 -1
- package/dist/cli/__tests__/session-compare.test.d.ts +2 -0
- package/dist/cli/__tests__/session-compare.test.d.ts.map +1 -0
- package/dist/cli/__tests__/session-compare.test.js +183 -0
- package/dist/cli/__tests__/session-compare.test.js.map +1 -0
- package/dist/cli/__tests__/team.test.js +8 -0
- package/dist/cli/__tests__/team.test.js.map +1 -1
- package/dist/cli/plugin-marketplace.d.ts.map +1 -1
- package/dist/cli/plugin-marketplace.js +11 -4
- package/dist/cli/plugin-marketplace.js.map +1 -1
- package/dist/cli/question.d.ts.map +1 -1
- package/dist/cli/question.js +8 -1
- package/dist/cli/question.js.map +1 -1
- package/dist/cli/session-compare.d.ts +11 -0
- package/dist/cli/session-compare.d.ts.map +1 -0
- package/dist/cli/session-compare.js +172 -0
- package/dist/cli/session-compare.js.map +1 -0
- package/dist/cli/session-search.d.ts.map +1 -1
- package/dist/cli/session-search.js +7 -0
- package/dist/cli/session-search.js.map +1 -1
- package/dist/cli/team.d.ts.map +1 -1
- package/dist/cli/team.js +2 -0
- package/dist/cli/team.js.map +1 -1
- package/dist/config/__tests__/multiplexer.test.d.ts +2 -0
- package/dist/config/__tests__/multiplexer.test.d.ts.map +1 -0
- package/dist/config/__tests__/multiplexer.test.js +118 -0
- package/dist/config/__tests__/multiplexer.test.js.map +1 -0
- package/dist/config/multiplexer.d.ts +29 -0
- package/dist/config/multiplexer.d.ts.map +1 -0
- package/dist/config/multiplexer.js +91 -0
- package/dist/config/multiplexer.js.map +1 -0
- package/dist/question/__tests__/ui.test.js +40 -1
- package/dist/question/__tests__/ui.test.js.map +1 -1
- package/dist/question/ui.d.ts.map +1 -1
- package/dist/question/ui.js +37 -7
- package/dist/question/ui.js.map +1 -1
- package/dist/scripts/__tests__/codex-native-hook.test.js +281 -1
- package/dist/scripts/__tests__/codex-native-hook.test.js.map +1 -1
- package/dist/scripts/codex-native-hook.d.ts.map +1 -1
- package/dist/scripts/codex-native-hook.js +8 -2
- package/dist/scripts/codex-native-hook.js.map +1 -1
- package/dist/scripts/notify-hook/team-worker-lease.d.ts +15 -0
- package/dist/scripts/notify-hook/team-worker-lease.d.ts.map +1 -0
- package/dist/scripts/notify-hook/team-worker-lease.js +63 -0
- package/dist/scripts/notify-hook/team-worker-lease.js.map +1 -0
- package/dist/scripts/notify-hook/team-worker-posttooluse.d.ts +1 -0
- package/dist/scripts/notify-hook/team-worker-posttooluse.d.ts.map +1 -1
- package/dist/scripts/notify-hook/team-worker-posttooluse.js +16 -5
- package/dist/scripts/notify-hook/team-worker-posttooluse.js.map +1 -1
- package/dist/scripts/notify-hook/team-worker.d.ts +12 -1
- package/dist/scripts/notify-hook/team-worker.d.ts.map +1 -1
- package/dist/scripts/notify-hook/team-worker.js +16 -4
- package/dist/scripts/notify-hook/team-worker.js.map +1 -1
- package/dist/session-history/__tests__/compare.test.d.ts +2 -0
- package/dist/session-history/__tests__/compare.test.d.ts.map +1 -0
- package/dist/session-history/__tests__/compare.test.js +257 -0
- package/dist/session-history/__tests__/compare.test.js.map +1 -0
- package/dist/session-history/compare.d.ts +74 -0
- package/dist/session-history/compare.d.ts.map +1 -0
- package/dist/session-history/compare.js +165 -0
- package/dist/session-history/compare.js.map +1 -0
- package/dist/team/__tests__/api-interop.test.js +3 -3
- package/dist/team/__tests__/completion-evidence.test.js +31 -1
- package/dist/team/__tests__/completion-evidence.test.js.map +1 -1
- package/dist/team/__tests__/cross-rebase-smoke.test.js +263 -31
- package/dist/team/__tests__/cross-rebase-smoke.test.js.map +1 -1
- package/dist/team/__tests__/herdr-session-realherdr.test.d.ts +2 -0
- package/dist/team/__tests__/herdr-session-realherdr.test.d.ts.map +1 -0
- package/dist/team/__tests__/herdr-session-realherdr.test.js +68 -0
- package/dist/team/__tests__/herdr-session-realherdr.test.js.map +1 -0
- package/dist/team/__tests__/herdr-session.test.d.ts +2 -0
- package/dist/team/__tests__/herdr-session.test.d.ts.map +1 -0
- package/dist/team/__tests__/herdr-session.test.js +228 -0
- package/dist/team/__tests__/herdr-session.test.js.map +1 -0
- package/dist/team/__tests__/hook-primary-e2e-contract.test.js +9 -3
- package/dist/team/__tests__/hook-primary-e2e-contract.test.js.map +1 -1
- package/dist/team/__tests__/idle-nudge.test.js +84 -0
- package/dist/team/__tests__/idle-nudge.test.js.map +1 -1
- package/dist/team/__tests__/mcp-comm.test.js +25 -1
- package/dist/team/__tests__/mcp-comm.test.js.map +1 -1
- package/dist/team/__tests__/rebalance-policy.test.js +27 -9
- package/dist/team/__tests__/rebalance-policy.test.js.map +1 -1
- package/dist/team/__tests__/runtime-delivery.test.d.ts +2 -0
- package/dist/team/__tests__/runtime-delivery.test.d.ts.map +1 -0
- package/dist/team/__tests__/runtime-delivery.test.js +570 -0
- package/dist/team/__tests__/runtime-delivery.test.js.map +1 -0
- package/dist/team/__tests__/runtime.test.js +938 -70
- package/dist/team/__tests__/runtime.test.js.map +1 -1
- package/dist/team/__tests__/scaling.test.js +645 -1
- package/dist/team/__tests__/scaling.test.js.map +1 -1
- package/dist/team/__tests__/state-renewal.test.d.ts +2 -0
- package/dist/team/__tests__/state-renewal.test.d.ts.map +1 -0
- package/dist/team/__tests__/state-renewal.test.js +555 -0
- package/dist/team/__tests__/state-renewal.test.js.map +1 -0
- package/dist/team/__tests__/state.test.js +121 -2
- package/dist/team/__tests__/state.test.js.map +1 -1
- package/dist/team/__tests__/task-lease.test.d.ts +2 -0
- package/dist/team/__tests__/task-lease.test.d.ts.map +1 -0
- package/dist/team/__tests__/task-lease.test.js +179 -0
- package/dist/team/__tests__/task-lease.test.js.map +1 -0
- package/dist/team/__tests__/team-ops-contract.test.js +1 -0
- package/dist/team/__tests__/team-ops-contract.test.js.map +1 -1
- package/dist/team/__tests__/worker-bootstrap.test.js +2 -0
- package/dist/team/__tests__/worker-bootstrap.test.js.map +1 -1
- package/dist/team/api-interop.d.ts +1 -1
- package/dist/team/api-interop.d.ts.map +1 -1
- package/dist/team/api-interop.js +13 -1
- package/dist/team/api-interop.js.map +1 -1
- package/dist/team/completion-evidence.d.ts +1 -1
- package/dist/team/completion-evidence.d.ts.map +1 -1
- package/dist/team/completion-evidence.js +9 -0
- package/dist/team/completion-evidence.js.map +1 -1
- package/dist/team/goal-workflow.js +1 -1
- package/dist/team/herdr-session.d.ts +234 -0
- package/dist/team/herdr-session.d.ts.map +1 -0
- package/dist/team/herdr-session.js +489 -0
- package/dist/team/herdr-session.js.map +1 -0
- package/dist/team/idle-nudge.d.ts +16 -4
- package/dist/team/idle-nudge.d.ts.map +1 -1
- package/dist/team/idle-nudge.js +51 -19
- package/dist/team/idle-nudge.js.map +1 -1
- package/dist/team/mcp-comm.d.ts +6 -4
- package/dist/team/mcp-comm.d.ts.map +1 -1
- package/dist/team/mcp-comm.js +4 -0
- package/dist/team/mcp-comm.js.map +1 -1
- package/dist/team/rebalance-policy.d.ts.map +1 -1
- package/dist/team/rebalance-policy.js +5 -2
- package/dist/team/rebalance-policy.js.map +1 -1
- package/dist/team/runtime.d.ts.map +1 -1
- package/dist/team/runtime.js +463 -166
- package/dist/team/runtime.js.map +1 -1
- package/dist/team/scaling.d.ts +3 -3
- package/dist/team/scaling.d.ts.map +1 -1
- package/dist/team/scaling.js +394 -200
- package/dist/team/scaling.js.map +1 -1
- package/dist/team/state/monitor.d.ts +3 -0
- package/dist/team/state/monitor.d.ts.map +1 -1
- package/dist/team/state/monitor.js +3 -0
- package/dist/team/state/monitor.js.map +1 -1
- package/dist/team/state/tasks.d.ts +4 -1
- package/dist/team/state/tasks.d.ts.map +1 -1
- package/dist/team/state/tasks.js +36 -5
- package/dist/team/state/tasks.js.map +1 -1
- package/dist/team/state/types.d.ts +9 -0
- package/dist/team/state/types.d.ts.map +1 -1
- package/dist/team/state/types.js.map +1 -1
- package/dist/team/state.d.ts +15 -2
- package/dist/team/state.d.ts.map +1 -1
- package/dist/team/state.js +73 -5
- package/dist/team/state.js.map +1 -1
- package/dist/team/task-lease.d.ts +4 -0
- package/dist/team/task-lease.d.ts.map +1 -0
- package/dist/team/task-lease.js +74 -0
- package/dist/team/task-lease.js.map +1 -0
- package/dist/team/team-ops.d.ts +2 -1
- package/dist/team/team-ops.d.ts.map +1 -1
- package/dist/team/team-ops.js +1 -0
- package/dist/team/team-ops.js.map +1 -1
- package/dist/team/tmux-session.d.ts +1 -1
- package/dist/team/tmux-session.d.ts.map +1 -1
- package/dist/team/tmux-session.js +10 -2
- package/dist/team/tmux-session.js.map +1 -1
- package/dist/team/worker-bootstrap.d.ts.map +1 -1
- package/dist/team/worker-bootstrap.js +16 -3
- package/dist/team/worker-bootstrap.js.map +1 -1
- package/package.json +1 -1
- package/plugins/oh-my-codex/.codex-plugin/plugin.json +1 -1
- package/plugins/oh-my-codex/hooks/codex-native-hook.mjs +4 -1
- package/plugins/oh-my-codex/skills/worker/SKILL.md +7 -1
- package/skills/worker/SKILL.md +7 -1
- package/src/scripts/__tests__/codex-native-hook.test.ts +279 -0
- package/src/scripts/codex-native-hook.ts +8 -2
- package/src/scripts/notify-hook/team-worker-lease.ts +69 -0
- package/src/scripts/notify-hook/team-worker-posttooluse.ts +16 -4
- package/src/scripts/notify-hook/team-worker.ts +15 -4
package/dist/team/runtime.js
CHANGED
|
@@ -5,12 +5,13 @@ import { mkdir, readdir, readFile, rm, writeFile, lstat, link, rename } from 'fs
|
|
|
5
5
|
import { performance } from 'perf_hooks';
|
|
6
6
|
import { spawn, spawnSync } from 'child_process';
|
|
7
7
|
import { sanitizeTeamName, isTmuxAvailable, hasCurrentTmuxClientContext, createTeamSession, CreateTeamSessionPartialError, buildWorkerProcessLaunchSpec, scrubTeamWorkerHudOwnershipEnv, resolveTeamWorkerCli, resolveTeamWorkerCliForResolvedLaunchArgs, assertTeamWorkerCliPolicyCompatibility, resolveTeamWorkerLaunchMode, waitForWorkerReady, waitForWorkerReadyAsync, waitForWorkerReadyDetailedAsync, dismissTrustPromptIfPresent, evaluateStartupDirectTriggerSafety, sendToWorker, sendToWorkerStdin, isWorkerAlive, isWorkerPaneOpen, paneHasOmxInstanceTag, readPaneTeamOwnerTagResult, restoreStandaloneHudPane, finalizeRestoredHudCleanupDebtSync, reconcileRestoredHudCleanupDebtSync, teardownWorkerPanes, unregisterResizeHook, queryDetachedTeamSession, requestDetachedTeamSessionDestroy, queryDetachedSessionLeaderBinding, listPaneIds, listTeamSessions, resolveSharedSessionShutdownTopology, } from './tmux-session.js';
|
|
8
|
+
import { createHerdrTeam, destroyHerdrTeam, herdrWorkspaceIdFromPaneId, interruptHerdrWorker, isHerdrBinaryCallable, isHerdrWorkerAlive, submitToHerdrWorker, teardownHerdrWorker, } from './herdr-session.js';
|
|
8
9
|
import { readExactPaneProofSync, readExactPaneProofsSync } from './exact-pane.js';
|
|
9
10
|
import { reconcileScaleDownCleanupDebt } from './scaling.js';
|
|
10
11
|
import { teamInit as initTeamState, DEFAULT_MAX_WORKERS, teamReadConfig as readTeamConfig, teamReadConfigSnapshot as readTeamConfigSnapshot, teamWriteWorkerIdentity as writeWorkerIdentity, teamReadWorkerHeartbeat as readWorkerHeartbeat, teamReadWorkerStatus as readWorkerStatus, teamWriteWorkerInbox as writeWorkerInbox, teamCreateTask as createStateTask, teamReadTask as readTask, teamListTasks as listTasks, teamListTasksSnapshot as listTasksSnapshot, teamUpdateTask as updateTask, teamReadManifest as readTeamManifestV2, teamReadManifestSnapshot as readTeamManifestV2Snapshot, teamNormalizeGovernance as normalizeTeamGovernance, teamNormalizePolicy as normalizeTeamPolicy, teamClaimTask as claimTask, teamReleaseTaskClaim as releaseTaskClaim, teamReclaimExpiredTaskClaim as reclaimExpiredTaskClaim, teamAppendEvent as appendTeamEvent, teamReadTaskApproval as readTaskApproval, teamListMailbox as listMailboxMessages, teamMarkMessageDelivered as markMessageDelivered, teamMarkMessageNotified as markMessageNotified, teamRetireMailboxMessages as retireTeamMailboxMessages, teamEnqueueDispatchRequest as enqueueDispatchRequest, teamMarkDispatchRequestNotified as markDispatchRequestNotified, teamTransitionDispatchRequest as transitionDispatchRequest, teamReadDispatchRequest as readDispatchRequest, teamListDispatchRequests as listDispatchRequests, teamRemoveDispatchRequestsForWorkers as removeDispatchRequestsForWorkers, teamCleanup as cleanupTeamState, teamSaveConfig as saveTeamConfig, teamWriteShutdownRequest as writeShutdownRequest, teamReadShutdownAck as readShutdownAck, teamReadMonitorSnapshot as readMonitorSnapshot, teamWriteMonitorSnapshot as writeMonitorSnapshot, teamReadPhase as readTeamPhaseState, teamWritePhase as writeTeamPhaseState, teamWriteWorkerStatus as writeWorkerStatus, writeAtomic, teamWithTaskMembershipBarrier as withTeamTaskMembershipBarrier, teamRemoveDurableFile as removeDurableFile, } from './team-ops.js';
|
|
11
12
|
import { discardTeamNoticesForTeam } from './notice-ledger.js';
|
|
12
13
|
import { commitTeamMembershipTaskTransaction, teamContinuationRequiredDiagnostic, writeTeamManifestV2 as writeTeamManifestV2State, } from './state.js';
|
|
13
|
-
import {
|
|
14
|
+
import { queueInboxNotification, queueDirectMailboxMessage, queueBroadcastMailboxMessage, waitForDispatchReceipt, } from './mcp-comm.js';
|
|
14
15
|
import { appendTeamDeliveryLogForCwd } from './delivery-log.js';
|
|
15
16
|
import { remapRepoAwareDecompositionMetadataToCreatedTasks, } from './repo-aware-decomposition.js';
|
|
16
17
|
import { generateWorkerOverlay, writeTeamWorkerInstructionsFile, removeTeamWorkerInstructionsFile, writeWorkerWorktreeRootAgentsFile, removeWorkerWorktreeRootAgentsFile, generateInitialInbox, generateTaskAssignmentInbox, generateShutdownInbox, buildTriggerDirective, buildMailboxTriggerDirective, buildLeaderMailboxTriggerDirective, writeWorkerRoleInstructionsFile, } from './worker-bootstrap.js';
|
|
@@ -42,8 +43,10 @@ function joinContextSections(...sections) {
|
|
|
42
43
|
const present = sections.filter((section) => Boolean(section?.trim()));
|
|
43
44
|
return present.length > 0 ? present.join('\n\n') : undefined;
|
|
44
45
|
}
|
|
45
|
-
async function
|
|
46
|
-
|
|
46
|
+
async function syncRootTeamModeStateForMonitor(teamName, phaseState, hasDeliveryDebt, cwd) {
|
|
47
|
+
const phase = phaseState.current_phase;
|
|
48
|
+
const terminal = isTerminalPhase(phase);
|
|
49
|
+
if (!terminal && (!hasDeliveryDebt || phaseState.terminal_epoch))
|
|
47
50
|
return;
|
|
48
51
|
try {
|
|
49
52
|
const localStatePath = join(resolve(cwd), '.omx', 'state', 'team-state.json');
|
|
@@ -56,6 +59,19 @@ async function syncRootTeamModeStateOnTerminalPhase(teamName, phase, cwd) {
|
|
|
56
59
|
const stateTeamName = typeof teamState.team_name === 'string' ? teamState.team_name.trim() : '';
|
|
57
60
|
if (stateTeamName && stateTeamName !== teamName)
|
|
58
61
|
return;
|
|
62
|
+
if (!terminal) {
|
|
63
|
+
if (stateTeamName !== teamName || teamState.active !== false
|
|
64
|
+
|| teamState.current_phase !== 'complete' || teamState.terminal_epoch)
|
|
65
|
+
return;
|
|
66
|
+
const updates = { active: true, current_phase: phase, completed_at: undefined };
|
|
67
|
+
if (localTeamState) {
|
|
68
|
+
await writeFile(localStatePath, JSON.stringify({ ...localTeamState, ...updates }, null, 2), 'utf-8');
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
await updateModeState('team', updates, cwd);
|
|
72
|
+
}
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
59
75
|
const alreadySynced = teamState.active === false
|
|
60
76
|
&& teamState.current_phase === phase
|
|
61
77
|
&& typeof teamState.completed_at === 'string'
|
|
@@ -545,6 +561,17 @@ async function reconcileDetachedSessionDestroyReceipt(teamName, cwd, config) {
|
|
|
545
561
|
async function destroyConfiguredDetachedTeamSession(teamName, cwd, config) {
|
|
546
562
|
if (!config.tmux_session)
|
|
547
563
|
return;
|
|
564
|
+
if (config.worker_launch_mode === 'herdr') {
|
|
565
|
+
// Herdr teams have no tmux session authority to converge; the workspace
|
|
566
|
+
// itself is the session.
|
|
567
|
+
const firstHerdrPane = config.workers
|
|
568
|
+
.map((worker) => worker.pane_id)
|
|
569
|
+
.find((paneId) => typeof paneId === 'string' && paneId !== '');
|
|
570
|
+
if (firstHerdrPane) {
|
|
571
|
+
await destroyHerdrTeam(herdrWorkspaceIdFromPaneId(firstHerdrPane));
|
|
572
|
+
}
|
|
573
|
+
return;
|
|
574
|
+
}
|
|
548
575
|
await withDetachedSessionDestroyLock(teamName, cwd, async () => {
|
|
549
576
|
const canonical = await readTeamConfig(teamName, cwd);
|
|
550
577
|
if (!canonical)
|
|
@@ -773,7 +800,6 @@ async function recordIntegrationFailure(teamName, worker, state, details, cwd) {
|
|
|
773
800
|
appendIntegrationReport(teamName, {
|
|
774
801
|
workerName: worker.name,
|
|
775
802
|
operation: details.operation,
|
|
776
|
-
strategy: details.strategy,
|
|
777
803
|
files: [],
|
|
778
804
|
detail: `${details.operation} reported success for ${sourceShort}, but leader HEAD did not advance from ${leaderShort}; not marking worker as integrated.`,
|
|
779
805
|
}, cwd);
|
|
@@ -794,23 +820,6 @@ async function emitCanonicalWorkerEvent(cwd, eventName, context) {
|
|
|
794
820
|
// best effort only
|
|
795
821
|
}
|
|
796
822
|
}
|
|
797
|
-
function autoCommitDirtyWorktree(worker) {
|
|
798
|
-
const worktreePath = resolve(worker.worktree_path);
|
|
799
|
-
const repoRoot = resolve(worker.worktree_repo_root);
|
|
800
|
-
const status = runGitCommand(repoRoot, ['status', '--porcelain'], worktreePath);
|
|
801
|
-
if (!status.ok || !status.stdout.trim())
|
|
802
|
-
return { committed: false, commitHash: null };
|
|
803
|
-
const taskId = worker.assigned_tasks[0] || 'unknown';
|
|
804
|
-
const addResult = runGitCommand(repoRoot, ['add', '-A'], worktreePath);
|
|
805
|
-
if (!addResult.ok)
|
|
806
|
-
return { committed: false, commitHash: null };
|
|
807
|
-
const msg = `omx(team): auto-checkpoint ${worker.name} [${taskId}]`;
|
|
808
|
-
const commitResult = runGitCommand(repoRoot, ['commit', '--no-verify', '-m', msg], worktreePath);
|
|
809
|
-
if (!commitResult.ok)
|
|
810
|
-
return { committed: false, commitHash: null };
|
|
811
|
-
const head = runGitCommand(repoRoot, ['rev-parse', 'HEAD'], worktreePath);
|
|
812
|
-
return { committed: true, commitHash: head.ok ? head.stdout : null };
|
|
813
|
-
}
|
|
814
823
|
function appendIntegrationReport(teamName, entry, cwd) {
|
|
815
824
|
const teamStateRoot = resolveCanonicalTeamStateRoot(cwd);
|
|
816
825
|
const reportPath = join(teamStateRoot, 'team', teamName, 'integration-report.md');
|
|
@@ -818,18 +827,37 @@ function appendIntegrationReport(teamName, entry, cwd) {
|
|
|
818
827
|
if (!existsSync(dir))
|
|
819
828
|
mkdirSync(dir, { recursive: true });
|
|
820
829
|
const timestamp = new Date().toISOString();
|
|
821
|
-
const line = `- [${timestamp}] ${entry.workerName}: ${entry.operation}
|
|
830
|
+
const line = `- [${timestamp}] ${entry.workerName}: ${entry.operation} on files: ${entry.files.join(', ') || 'unknown'}. ${entry.detail}\n`;
|
|
822
831
|
appendFileSync(reportPath, existsSync(reportPath) ? line : `# Integration Report\n\n${line}`);
|
|
823
832
|
}
|
|
824
|
-
function resolveWorkerMergeRef(branchResult, workerHead) {
|
|
825
|
-
const branchRef = branchResult.ok ? branchResult.stdout.trim() : '';
|
|
826
|
-
if (!branchRef || branchRef === 'HEAD')
|
|
827
|
-
return workerHead;
|
|
828
|
-
return branchRef;
|
|
829
|
-
}
|
|
830
833
|
function leaderContainsCommit(repoRoot, cwd, commit) {
|
|
831
834
|
return runGitCommand(repoRoot, ['merge-base', '--is-ancestor', commit, 'HEAD'], cwd).ok;
|
|
832
835
|
}
|
|
836
|
+
function worktreeHasUnfinishedRebase(repoRoot, worktreePath) {
|
|
837
|
+
return ['rebase-merge', 'rebase-apply'].some((name) => {
|
|
838
|
+
const path = runGitCommand(repoRoot, ['rev-parse', '--git-path', name], worktreePath);
|
|
839
|
+
return !path.ok || existsSync(resolve(worktreePath, path.stdout.trim()));
|
|
840
|
+
});
|
|
841
|
+
}
|
|
842
|
+
async function readVerifiedWorkerHandoff(teamName, worker, cwd) {
|
|
843
|
+
const status = await readWorkerStatus(teamName, worker.name, cwd);
|
|
844
|
+
if (status.state !== 'idle' && status.state !== 'done')
|
|
845
|
+
return null;
|
|
846
|
+
const tasks = await listTasks(teamName, cwd);
|
|
847
|
+
const taskIds = new Set([
|
|
848
|
+
...worker.assigned_tasks,
|
|
849
|
+
...(status.current_task_id ? [status.current_task_id] : []),
|
|
850
|
+
...tasks.filter((task) => task.owner === worker.name || task.claim?.owner === worker.name).map((task) => task.id),
|
|
851
|
+
]);
|
|
852
|
+
// Historical research is exempt, but cannot authorize publication on its own.
|
|
853
|
+
const associatedTasks = [...taskIds].map((id) => tasks.find((task) => task.id === id));
|
|
854
|
+
if (!associatedTasks.length || !associatedTasks.every((task) => task?.owner === worker.name
|
|
855
|
+
&& task.status === 'completed' && !task.claim))
|
|
856
|
+
return null;
|
|
857
|
+
const workerHead = resolveWorkerHead(resolve(worker.worktree_path));
|
|
858
|
+
return associatedTasks.some((task) => task?.requires_code_change === true
|
|
859
|
+
&& task.verified_head === workerHead && hasStructuredVerificationEvidence(task.result)) ? workerHead : null;
|
|
860
|
+
}
|
|
833
861
|
async function integrateWorkerCommitsIntoLeader(params) {
|
|
834
862
|
const { teamName, config, previous, cwd } = params;
|
|
835
863
|
const next = { ...(previous?.integrationByWorker ?? {}) };
|
|
@@ -837,60 +865,72 @@ async function integrateWorkerCommitsIntoLeader(params) {
|
|
|
837
865
|
const integratedWorkerNames = new Set();
|
|
838
866
|
const commitHygieneEntries = [];
|
|
839
867
|
const artifactCwd = resolveTeamCommitHygieneArtifactCwd(config, cwd);
|
|
840
|
-
// ── Phase A: Auto-commit dirty worktrees ──
|
|
841
|
-
for (const worker of config.workers) {
|
|
842
|
-
if (!worker.worktree_repo_root || !worker.worktree_path || !existsSync(worker.worktree_path))
|
|
843
|
-
continue;
|
|
844
|
-
const { committed, commitHash } = autoCommitDirtyWorktree(worker);
|
|
845
|
-
if (committed) {
|
|
846
|
-
await appendIntegrationEvent(teamName, 'worker_auto_commit', worker, {
|
|
847
|
-
worker_name: worker.name,
|
|
848
|
-
commit_hash: commitHash,
|
|
849
|
-
worktree_path: resolve(worker.worktree_path),
|
|
850
|
-
summary: `auto-committed dirty worktree for ${worker.name}`,
|
|
851
|
-
}, cwd);
|
|
852
|
-
commitHygieneEntries.push({
|
|
853
|
-
recorded_at: new Date().toISOString(),
|
|
854
|
-
operation: 'auto_checkpoint',
|
|
855
|
-
worker_name: worker.name,
|
|
856
|
-
task_id: worker.assigned_tasks[0],
|
|
857
|
-
status: 'applied',
|
|
858
|
-
operational_commit: commitHash,
|
|
859
|
-
worktree_path: resolve(worker.worktree_path),
|
|
860
|
-
detail: 'Dirty worker worktree checkpointed before runtime integration.',
|
|
861
|
-
});
|
|
862
|
-
}
|
|
863
|
-
}
|
|
864
868
|
// ── Phase B: Integrate worker commits to leader (hybrid strategy) ──
|
|
865
869
|
for (const worker of config.workers) {
|
|
866
870
|
if (!worker.worktree_repo_root || !worker.worktree_path || !existsSync(worker.worktree_path))
|
|
867
871
|
continue;
|
|
868
872
|
const repoRoot = resolve(worker.worktree_repo_root);
|
|
869
873
|
const worktreePath = resolve(worker.worktree_path);
|
|
874
|
+
const previousState = next[worker.name] ?? {};
|
|
875
|
+
// Orig-head/onto do not prove ownership: a manual rebase can recreate the same operation.
|
|
876
|
+
if (worktreeHasUnfinishedRebase(repoRoot, worktreePath)) {
|
|
877
|
+
next[worker.name] = {
|
|
878
|
+
...previousState, status: 'rebase_conflict',
|
|
879
|
+
rebase_error: 'Unfinished rebase preserved. Finish or abort it manually before retrying integration.',
|
|
880
|
+
};
|
|
881
|
+
continue;
|
|
882
|
+
}
|
|
883
|
+
if (previousState.pending_rebase_leader_head) {
|
|
884
|
+
if (previousState.delivery_leader_commit && leaderContainsCommit(repoRoot, cwd, previousState.delivery_leader_commit))
|
|
885
|
+
continue;
|
|
886
|
+
const workerStatus = await readWorkerStatus(teamName, worker.name, cwd);
|
|
887
|
+
if (workerStatus.state !== 'idle' && workerStatus.state !== 'done')
|
|
888
|
+
continue;
|
|
889
|
+
const status = runGitCommand(repoRoot, ['status', '--porcelain', '--untracked-files=all', '--ignore-submodules=none'], worktreePath);
|
|
890
|
+
if (!status.ok || status.stdout.trim()
|
|
891
|
+
|| !previousState.last_integrated_head || resolveWorkerHead(worktreePath) !== previousState.last_integrated_head)
|
|
892
|
+
continue;
|
|
893
|
+
// Redeliver only the clean original source after its recorded delivery disappeared.
|
|
894
|
+
next[worker.name] = {
|
|
895
|
+
...previousState, last_integrated_head: undefined, delivery_leader_commit: undefined,
|
|
896
|
+
pending_rebase_leader_head: undefined, rebase_error: undefined,
|
|
897
|
+
conflict_commit: undefined, conflict_files: undefined, status: 'idle',
|
|
898
|
+
};
|
|
899
|
+
}
|
|
900
|
+
const verifiedHead = await readVerifiedWorkerHandoff(teamName, worker, cwd);
|
|
901
|
+
if (!verifiedHead)
|
|
902
|
+
continue;
|
|
903
|
+
const clean = runGitCommand(resolve(worker.worktree_repo_root), ['status', '--porcelain', '--untracked-files=all', '--ignore-submodules=none'], resolve(worker.worktree_path));
|
|
904
|
+
if (!clean.ok || clean.stdout.trim())
|
|
905
|
+
continue;
|
|
870
906
|
const leaderHead = resolveLeaderHead(repoRoot, cwd);
|
|
871
907
|
const workerHead = resolveWorkerHead(worktreePath);
|
|
872
|
-
const
|
|
873
|
-
|
|
874
|
-
if (!workerHead || !leaderHead) {
|
|
908
|
+
const state = { ...next[worker.name], last_leader_head: leaderHead ?? previousState.last_leader_head };
|
|
909
|
+
if (!workerHead || workerHead !== verifiedHead || !leaderHead) {
|
|
875
910
|
next[worker.name] = state;
|
|
876
911
|
continue;
|
|
877
912
|
}
|
|
913
|
+
// A source baseline is reusable only while its actual leader delivery survives.
|
|
914
|
+
if (!state.delivery_leader_commit || !leaderContainsCommit(repoRoot, cwd, state.delivery_leader_commit)) {
|
|
915
|
+
state.last_integrated_head = undefined;
|
|
916
|
+
state.delivery_leader_commit = undefined;
|
|
917
|
+
}
|
|
878
918
|
state.last_seen_head = workerHead;
|
|
879
919
|
const alreadyMerged = runGitCommand(repoRoot, ['merge-base', '--is-ancestor', workerHead, 'HEAD'], cwd).ok;
|
|
880
920
|
if (alreadyMerged) {
|
|
881
|
-
state
|
|
921
|
+
Object.assign(state, { last_integrated_head: workerHead, delivery_leader_commit: workerHead });
|
|
882
922
|
state.status = 'idle';
|
|
883
923
|
state.updated_at = new Date().toISOString();
|
|
924
|
+
integratedWorkerNames.add(worker.name);
|
|
884
925
|
next[worker.name] = state;
|
|
885
926
|
continue;
|
|
886
927
|
}
|
|
887
928
|
// Determine if worker is cleanly ahead of leader (merge) or diverged (cherry-pick)
|
|
888
929
|
const workerIsAheadOfLeader = runGitCommand(repoRoot, ['merge-base', '--is-ancestor', leaderHead, workerHead], cwd).ok;
|
|
889
930
|
if (workerIsAheadOfLeader) {
|
|
890
|
-
//
|
|
891
|
-
const
|
|
892
|
-
const
|
|
893
|
-
const merge = runGitCommand(repoRoot, ['merge', '--no-ff', '-X', 'theirs', '-m', `omx(team): merge ${worker.name}`, branchRef], cwd);
|
|
931
|
+
// Publish the immutable verified commit without choosing sides on conflicts.
|
|
932
|
+
const branchRef = verifiedHead;
|
|
933
|
+
const merge = runGitCommand(repoRoot, ['merge', '--no-ff', '-m', `omx(team): merge ${worker.name}`, branchRef], cwd);
|
|
894
934
|
if (merge.ok) {
|
|
895
935
|
const newLeaderHead = resolveLeaderHead(repoRoot, cwd) ?? leaderHead;
|
|
896
936
|
const workerIntegrated = leaderContainsCommit(repoRoot, cwd, workerHead);
|
|
@@ -901,11 +941,11 @@ async function integrateWorkerCommitsIntoLeader(params) {
|
|
|
901
941
|
leaderHeadBefore: leaderHead,
|
|
902
942
|
leaderHeadAfter: newLeaderHead,
|
|
903
943
|
worktreePath,
|
|
904
|
-
strategy: '-X theirs',
|
|
905
944
|
}, cwd);
|
|
906
945
|
}
|
|
907
946
|
else if (workerIntegrated) {
|
|
908
947
|
state.last_integrated_head = workerHead;
|
|
948
|
+
state.delivery_leader_commit = newLeaderHead;
|
|
909
949
|
state.last_leader_head = newLeaderHead;
|
|
910
950
|
state.status = 'integrated';
|
|
911
951
|
state.conflict_commit = undefined;
|
|
@@ -918,7 +958,7 @@ async function integrateWorkerCommitsIntoLeader(params) {
|
|
|
918
958
|
leader_head_before: leaderHead,
|
|
919
959
|
leader_head_after: newLeaderHead,
|
|
920
960
|
worktree_path: worktreePath,
|
|
921
|
-
summary: `merged ${worker.name} into leader via --no-ff
|
|
961
|
+
summary: `merged ${worker.name} into leader via --no-ff`,
|
|
922
962
|
}, cwd);
|
|
923
963
|
await sendIntegrationMessageToLeader(teamName, worker, `INTEGRATED: merged ${worker.name} (${workerHead.slice(0, 12)}) into leader HEAD ${newLeaderHead.slice(0, 12)} via merge --no-ff.`, cwd);
|
|
924
964
|
commitHygieneEntries.push({
|
|
@@ -942,7 +982,6 @@ async function integrateWorkerCommitsIntoLeader(params) {
|
|
|
942
982
|
appendIntegrationReport(teamName, {
|
|
943
983
|
workerName: worker.name,
|
|
944
984
|
operation: 'merge',
|
|
945
|
-
strategy: '-X theirs',
|
|
946
985
|
files: [],
|
|
947
986
|
detail: `merge reported success but leader HEAD did not advance cleanly (leader_before=${leaderHead.slice(0, 12)}, leader_after=${newLeaderHead.slice(0, 12)}, worker_integrated=${workerIntegrated}, merge_ref=${branchRef}).`,
|
|
948
987
|
}, cwd);
|
|
@@ -963,7 +1002,7 @@ async function integrateWorkerCommitsIntoLeader(params) {
|
|
|
963
1002
|
}
|
|
964
1003
|
}
|
|
965
1004
|
else {
|
|
966
|
-
//
|
|
1005
|
+
// Abort without changing either side; leave resolution to the leader.
|
|
967
1006
|
const conflictFiles = listConflictFiles(repoRoot, cwd);
|
|
968
1007
|
runGitCommand(repoRoot, ['merge', '--abort'], cwd);
|
|
969
1008
|
state.status = 'cherry_pick_conflict';
|
|
@@ -977,25 +1016,26 @@ async function integrateWorkerCommitsIntoLeader(params) {
|
|
|
977
1016
|
worktree_path: worktreePath,
|
|
978
1017
|
conflict_files: conflictFiles,
|
|
979
1018
|
stderr: merge.stderr || merge.stdout,
|
|
980
|
-
summary: `merge conflict for ${worker.name} (
|
|
1019
|
+
summary: `merge conflict for ${worker.name} (aborted; manual resolution required)`,
|
|
981
1020
|
}, cwd);
|
|
982
1021
|
appendIntegrationReport(teamName, {
|
|
983
1022
|
workerName: worker.name,
|
|
984
1023
|
operation: 'merge',
|
|
985
|
-
strategy: '-X theirs',
|
|
986
1024
|
files: conflictFiles,
|
|
987
|
-
detail: `merge --no-ff
|
|
1025
|
+
detail: `merge --no-ff failed; aborted; originals preserved. stderr: ${(merge.stderr || '').slice(0, 200)}`,
|
|
988
1026
|
}, cwd);
|
|
989
|
-
await sendIntegrationMessageToLeader(teamName, worker, `CONFLICT
|
|
1027
|
+
await sendIntegrationMessageToLeader(teamName, worker, `INTEGRATION CONFLICT: ${worker.name}'s merge was aborted on files: ${conflictFiles.join(', ') || 'unknown'}. Leader and worker originals are preserved. Resolve the conflict in ${worktreePath} before retrying integration.`, cwd);
|
|
990
1028
|
}
|
|
991
1029
|
}
|
|
992
1030
|
else {
|
|
993
|
-
// Diverged → cherry-pick individual commits
|
|
1031
|
+
// Diverged → cherry-pick individual commits without choosing conflict sides
|
|
994
1032
|
const baseline = state.last_integrated_head && runGitCommand(repoRoot, ['rev-parse', '--verify', state.last_integrated_head], worktreePath).ok
|
|
995
1033
|
? state.last_integrated_head
|
|
996
1034
|
: leaderHead;
|
|
997
1035
|
const commits = listCommitRange(repoRoot, baseline, workerHead, worktreePath);
|
|
998
1036
|
if (commits.length === 0) {
|
|
1037
|
+
if (state.last_integrated_head === workerHead)
|
|
1038
|
+
integratedWorkerNames.add(worker.name);
|
|
999
1039
|
next[worker.name] = state;
|
|
1000
1040
|
continue;
|
|
1001
1041
|
}
|
|
@@ -1009,9 +1049,9 @@ async function integrateWorkerCommitsIntoLeader(params) {
|
|
|
1009
1049
|
worktree_path: worktreePath,
|
|
1010
1050
|
summary: `detected worker commit ${commit.slice(0, 12)}`,
|
|
1011
1051
|
}, cwd);
|
|
1012
|
-
const pick = runGitCommand(repoRoot, ['cherry-pick', '--allow-empty',
|
|
1052
|
+
const pick = runGitCommand(repoRoot, ['cherry-pick', '--allow-empty', commit], cwd);
|
|
1013
1053
|
if (!pick.ok) {
|
|
1014
|
-
//
|
|
1054
|
+
// Abort this commit and stop; do not rebase unintegrated changes.
|
|
1015
1055
|
const conflictFiles = listConflictFiles(repoRoot, cwd);
|
|
1016
1056
|
runGitCommand(repoRoot, ['cherry-pick', '--abort'], cwd);
|
|
1017
1057
|
state.status = 'cherry_pick_conflict';
|
|
@@ -1025,16 +1065,15 @@ async function integrateWorkerCommitsIntoLeader(params) {
|
|
|
1025
1065
|
worktree_path: worktreePath,
|
|
1026
1066
|
conflict_files: conflictFiles,
|
|
1027
1067
|
stderr: pick.stderr || pick.stdout,
|
|
1028
|
-
summary: `cherry-pick conflict for ${worker.name} at ${commit.slice(0, 12)} (
|
|
1068
|
+
summary: `cherry-pick conflict for ${worker.name} at ${commit.slice(0, 12)} (aborted; manual resolution required)`,
|
|
1029
1069
|
}, cwd);
|
|
1030
1070
|
appendIntegrationReport(teamName, {
|
|
1031
1071
|
workerName: worker.name,
|
|
1032
1072
|
operation: 'cherry-pick',
|
|
1033
|
-
strategy: '-X theirs',
|
|
1034
1073
|
files: conflictFiles,
|
|
1035
|
-
detail: `cherry-pick
|
|
1074
|
+
detail: `cherry-pick ${commit.slice(0, 12)} failed; aborted; originals preserved. stderr: ${(pick.stderr || '').slice(0, 200)}`,
|
|
1036
1075
|
}, cwd);
|
|
1037
|
-
await sendIntegrationMessageToLeader(teamName, worker, `CONFLICT
|
|
1076
|
+
await sendIntegrationMessageToLeader(teamName, worker, `INTEGRATION CONFLICT: ${worker.name}'s cherry-pick ${commit.slice(0, 12)} was aborted on files: ${conflictFiles.join(', ') || 'unknown'}. Leader and worker originals are preserved. Resolve the conflict in ${worktreePath} before retrying integration.`, cwd);
|
|
1038
1077
|
allPicked = false;
|
|
1039
1078
|
break;
|
|
1040
1079
|
}
|
|
@@ -1046,12 +1085,12 @@ async function integrateWorkerCommitsIntoLeader(params) {
|
|
|
1046
1085
|
leaderHeadBefore: leaderHead,
|
|
1047
1086
|
leaderHeadAfter: newLeaderHead,
|
|
1048
1087
|
worktreePath,
|
|
1049
|
-
strategy: '-X theirs',
|
|
1050
1088
|
}, cwd);
|
|
1051
1089
|
allPicked = false;
|
|
1052
1090
|
break;
|
|
1053
1091
|
}
|
|
1054
1092
|
state.last_integrated_head = commit;
|
|
1093
|
+
state.delivery_leader_commit = newLeaderHead;
|
|
1055
1094
|
state.last_leader_head = newLeaderHead;
|
|
1056
1095
|
state.status = 'integrated';
|
|
1057
1096
|
state.conflict_commit = undefined;
|
|
@@ -1063,9 +1102,9 @@ async function integrateWorkerCommitsIntoLeader(params) {
|
|
|
1063
1102
|
leader_head_before: leaderHead,
|
|
1064
1103
|
leader_head_after: newLeaderHead,
|
|
1065
1104
|
worktree_path: worktreePath,
|
|
1066
|
-
summary: `cherry-picked ${commit.slice(0, 12)} from ${worker.name}
|
|
1105
|
+
summary: `cherry-picked ${commit.slice(0, 12)} from ${worker.name}`,
|
|
1067
1106
|
}, cwd);
|
|
1068
|
-
await sendIntegrationMessageToLeader(teamName, worker, `INTEGRATED: cherry-picked ${commit.slice(0, 12)} from ${worker.name} into leader HEAD ${newLeaderHead.slice(0, 12)}
|
|
1107
|
+
await sendIntegrationMessageToLeader(teamName, worker, `INTEGRATED: cherry-picked ${commit.slice(0, 12)} from ${worker.name} into leader HEAD ${newLeaderHead.slice(0, 12)}.`, cwd);
|
|
1069
1108
|
commitHygieneEntries.push({
|
|
1070
1109
|
recorded_at: new Date().toISOString(),
|
|
1071
1110
|
operation: 'integration_cherry_pick',
|
|
@@ -1086,20 +1125,39 @@ async function integrateWorkerCommitsIntoLeader(params) {
|
|
|
1086
1125
|
}
|
|
1087
1126
|
next[worker.name] = state;
|
|
1088
1127
|
}
|
|
1089
|
-
// ── Phase C: Cross-worker rebase (
|
|
1128
|
+
// ── Phase C: Cross-worker rebase (ready workers onto new leader) ──
|
|
1090
1129
|
const newLeaderHead = resolveLeaderHead(resolve(config.workers[0]?.worktree_repo_root ?? cwd), cwd);
|
|
1091
|
-
if (newLeaderHead
|
|
1130
|
+
if (newLeaderHead) {
|
|
1092
1131
|
for (const worker of config.workers) {
|
|
1132
|
+
const state = next[worker.name] ?? {};
|
|
1133
|
+
const leaderAdvanced = leaderHeadAtCycleStart && newLeaderHead !== leaderHeadAtCycleStart;
|
|
1134
|
+
if (!leaderAdvanced && !state.pending_rebase_leader_head)
|
|
1135
|
+
continue;
|
|
1093
1136
|
if (!worker.worktree_repo_root || !worker.worktree_path || !existsSync(worker.worktree_path))
|
|
1094
1137
|
continue;
|
|
1095
|
-
//
|
|
1096
|
-
|
|
1138
|
+
// Never rewrite worker history while its source delivery is unresolved.
|
|
1139
|
+
if (state.status === 'cherry_pick_conflict' || state.status === 'integration_failed'
|
|
1140
|
+
|| (!integratedWorkerNames.has(worker.name) && !state.pending_rebase_leader_head)) {
|
|
1141
|
+
await appendIntegrationEvent(teamName, 'worker_cross_rebase_skipped', worker, {
|
|
1142
|
+
worker_name: worker.name,
|
|
1143
|
+
reason: 'unintegrated_changes',
|
|
1144
|
+
leader_head: newLeaderHead,
|
|
1145
|
+
worktree_path: resolve(worker.worktree_path),
|
|
1146
|
+
summary: `skipped cross-rebase for ${worker.name} (unintegrated changes; resolve integration first)`,
|
|
1147
|
+
}, cwd);
|
|
1148
|
+
continue;
|
|
1149
|
+
}
|
|
1097
1150
|
const repoRoot = resolve(worker.worktree_repo_root);
|
|
1098
1151
|
const worktreePath = resolve(worker.worktree_path);
|
|
1099
|
-
|
|
1152
|
+
const sourceHead = resolveWorkerHead(worktreePath);
|
|
1153
|
+
const sourceDelivered = sourceHead && (leaderContainsCommit(repoRoot, cwd, sourceHead)
|
|
1154
|
+
|| (state.last_integrated_head === sourceHead && state.delivery_leader_commit
|
|
1155
|
+
&& leaderContainsCommit(repoRoot, cwd, state.delivery_leader_commit)));
|
|
1156
|
+
if (!sourceDelivered)
|
|
1157
|
+
continue;
|
|
1100
1158
|
const workerStatus = await readWorkerStatus(teamName, worker.name, cwd);
|
|
1101
|
-
const
|
|
1102
|
-
if (!
|
|
1159
|
+
const verifiedHead = await readVerifiedWorkerHandoff(teamName, worker, cwd);
|
|
1160
|
+
if (!verifiedHead) {
|
|
1103
1161
|
await appendIntegrationEvent(teamName, 'worker_cross_rebase_skipped', worker, {
|
|
1104
1162
|
worker_name: worker.name,
|
|
1105
1163
|
worker_state: workerStatus.state,
|
|
@@ -1109,9 +1167,16 @@ async function integrateWorkerCommitsIntoLeader(params) {
|
|
|
1109
1167
|
}, cwd);
|
|
1110
1168
|
continue;
|
|
1111
1169
|
}
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1170
|
+
if (worktreeHasUnfinishedRebase(repoRoot, worktreePath)) {
|
|
1171
|
+
next[worker.name] = {
|
|
1172
|
+
...state, status: 'rebase_conflict',
|
|
1173
|
+
rebase_error: 'Unfinished rebase preserved. Finish or abort it manually before retrying integration.',
|
|
1174
|
+
};
|
|
1175
|
+
continue;
|
|
1176
|
+
}
|
|
1177
|
+
// Never rebase a dirty or unreadable worktree.
|
|
1178
|
+
const statusCheck = runGitCommand(repoRoot, ['status', '--porcelain', '--untracked-files=all', '--ignore-submodules=none'], worktreePath);
|
|
1179
|
+
if (!statusCheck.ok || statusCheck.stdout.trim()) {
|
|
1115
1180
|
await appendIntegrationEvent(teamName, 'worker_cross_rebase_skipped', worker, {
|
|
1116
1181
|
worker_name: worker.name,
|
|
1117
1182
|
reason: 'dirty_worktree',
|
|
@@ -1121,13 +1186,16 @@ async function integrateWorkerCommitsIntoLeader(params) {
|
|
|
1121
1186
|
}, cwd);
|
|
1122
1187
|
continue;
|
|
1123
1188
|
}
|
|
1124
|
-
// Rebase
|
|
1189
|
+
// Rebase without silently dropping conflicting worker changes.
|
|
1125
1190
|
const workerHeadBeforeRebase = resolveWorkerHead(worktreePath);
|
|
1126
|
-
|
|
1191
|
+
if (workerHeadBeforeRebase !== verifiedHead)
|
|
1192
|
+
continue;
|
|
1193
|
+
const rebase = runGitCommand(repoRoot, ['rebase', newLeaderHead], worktreePath);
|
|
1127
1194
|
if (rebase.ok) {
|
|
1128
1195
|
const workerHeadAfterRebase = resolveWorkerHead(worktreePath);
|
|
1129
|
-
const state = next[worker.name] ?? {};
|
|
1130
1196
|
state.last_rebased_leader_head = newLeaderHead;
|
|
1197
|
+
state.pending_rebase_leader_head = undefined;
|
|
1198
|
+
state.rebase_error = undefined;
|
|
1131
1199
|
state.status = 'idle';
|
|
1132
1200
|
state.conflict_commit = undefined;
|
|
1133
1201
|
state.conflict_files = undefined;
|
|
@@ -1137,7 +1205,7 @@ async function integrateWorkerCommitsIntoLeader(params) {
|
|
|
1137
1205
|
worker_name: worker.name,
|
|
1138
1206
|
leader_head: newLeaderHead,
|
|
1139
1207
|
worktree_path: worktreePath,
|
|
1140
|
-
summary: `cross-rebased ${worker.name} onto ${newLeaderHead.slice(0, 12)}
|
|
1208
|
+
summary: `cross-rebased ${worker.name} onto ${newLeaderHead.slice(0, 12)}`,
|
|
1141
1209
|
}, cwd);
|
|
1142
1210
|
commitHygieneEntries.push({
|
|
1143
1211
|
recorded_at: new Date().toISOString(),
|
|
@@ -1156,23 +1224,31 @@ async function integrateWorkerCommitsIntoLeader(params) {
|
|
|
1156
1224
|
else {
|
|
1157
1225
|
// Rebase failed — abort to restore worktree, log for retry next cycle
|
|
1158
1226
|
const conflictFiles = listConflictFiles(repoRoot, worktreePath);
|
|
1159
|
-
runGitCommand(repoRoot, ['rebase', '--abort'], worktreePath);
|
|
1227
|
+
const abortResult = runGitCommand(repoRoot, ['rebase', '--abort'], worktreePath);
|
|
1228
|
+
state.status = 'rebase_conflict';
|
|
1229
|
+
state.pending_rebase_leader_head = newLeaderHead;
|
|
1230
|
+
state.rebase_error = `${rebase.stderr || rebase.stdout}; abort: ${abortResult.ok ? 'ok' : abortResult.stderr || abortResult.stdout}`;
|
|
1231
|
+
state.conflict_commit = workerHeadBeforeRebase ?? undefined;
|
|
1232
|
+
state.conflict_files = conflictFiles;
|
|
1233
|
+
state.updated_at = new Date().toISOString();
|
|
1234
|
+
next[worker.name] = state;
|
|
1160
1235
|
await appendIntegrationEvent(teamName, 'worker_cross_rebase_conflict', worker, {
|
|
1161
1236
|
worker_name: worker.name,
|
|
1162
1237
|
leader_head: newLeaderHead,
|
|
1163
1238
|
worktree_path: worktreePath,
|
|
1164
1239
|
conflict_files: conflictFiles,
|
|
1165
1240
|
stderr: rebase.stderr || rebase.stdout,
|
|
1166
|
-
|
|
1241
|
+
abort_ok: abortResult.ok,
|
|
1242
|
+
abort_stderr: abortResult.stderr,
|
|
1243
|
+
summary: `cross-rebase conflict for ${worker.name} onto ${newLeaderHead.slice(0, 12)} (abort ${abortResult.ok ? 'succeeded' : 'failed'}, will retry)`,
|
|
1167
1244
|
}, cwd);
|
|
1168
1245
|
appendIntegrationReport(teamName, {
|
|
1169
1246
|
workerName: worker.name,
|
|
1170
1247
|
operation: 'rebase',
|
|
1171
|
-
strategy: '-X ours',
|
|
1172
1248
|
files: conflictFiles,
|
|
1173
|
-
detail: `rebase
|
|
1249
|
+
detail: `rebase onto ${newLeaderHead.slice(0, 12)} failed; abort ${abortResult.ok ? 'succeeded' : 'failed'}. Will retry next cycle. ${state.rebase_error}`,
|
|
1174
1250
|
}, cwd);
|
|
1175
|
-
await sendIntegrationMessageToLeader(teamName, worker, `CONFLICT
|
|
1251
|
+
await sendIntegrationMessageToLeader(teamName, worker, `REBASE CONFLICT: ${worker.name}'s rebase onto ${newLeaderHead.slice(0, 12)} was aborted on files: ${conflictFiles.join(', ') || 'unknown'}. Original worker HEAD is preserved. Resolve the conflict in ${worktreePath} before retrying.`, cwd);
|
|
1176
1252
|
}
|
|
1177
1253
|
}
|
|
1178
1254
|
}
|
|
@@ -2779,7 +2855,12 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
2779
2855
|
if (workerLaunchMode === 'prompt') {
|
|
2780
2856
|
assertPromptModeWorkerCliSupported(workerLaunchPolicyPlan.map((workerLaunchPolicy) => workerLaunchPolicy.workerCli), launchEnv);
|
|
2781
2857
|
}
|
|
2782
|
-
if (workerLaunchMode === '
|
|
2858
|
+
if (workerLaunchMode === 'herdr') {
|
|
2859
|
+
if (!(await isHerdrBinaryCallable())) {
|
|
2860
|
+
throw new Error('Team mode herdr backend requires the herdr binary. Install from https://herdr.dev (curl -fsSL https://herdr.dev/install.sh | sh, or brew install herdr) and retry.');
|
|
2861
|
+
}
|
|
2862
|
+
}
|
|
2863
|
+
else if (workerLaunchMode === 'interactive') {
|
|
2783
2864
|
if (!isTmuxAvailable()) {
|
|
2784
2865
|
throw new Error('Team mode requires tmux. Install with: apt install tmux / brew install tmux');
|
|
2785
2866
|
}
|
|
@@ -2830,6 +2911,36 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
2830
2911
|
return currentOwner.status === 'value' && currentOwner.value === expectedOwnerId;
|
|
2831
2912
|
};
|
|
2832
2913
|
let config = null;
|
|
2914
|
+
// Only transport/debt fields belong to startup after workers can execute.
|
|
2915
|
+
const persistStartupTransport = async () => {
|
|
2916
|
+
const startup = config;
|
|
2917
|
+
if (!startup)
|
|
2918
|
+
throw new Error(`team_config_missing:${sanitized}`);
|
|
2919
|
+
config = await withTeamTaskMembershipBarrier(sanitized, leaderCwd, async () => {
|
|
2920
|
+
const current = await readTeamConfig(sanitized, leaderCwd);
|
|
2921
|
+
if (!current)
|
|
2922
|
+
throw new Error(`team_config_missing:${sanitized}`);
|
|
2923
|
+
current.tmux_session = startup.tmux_session;
|
|
2924
|
+
current.tmux_session_id = startup.tmux_session_id;
|
|
2925
|
+
current.tmux_session_created = startup.tmux_session_created;
|
|
2926
|
+
current.tmux_pane_owner_id = startup.tmux_pane_owner_id;
|
|
2927
|
+
current.leader_pane_id = startup.leader_pane_id;
|
|
2928
|
+
current.leader_pane_pid = startup.leader_pane_pid;
|
|
2929
|
+
current.hud_pane_id = startup.hud_pane_id;
|
|
2930
|
+
current.hud_pane_pid = startup.hud_pane_pid;
|
|
2931
|
+
current.resize_hook_name = startup.resize_hook_name;
|
|
2932
|
+
current.resize_hook_target = startup.resize_hook_target;
|
|
2933
|
+
current.startup_cleanup_panes = startup.startup_cleanup_panes;
|
|
2934
|
+
current.workers = current.workers.flatMap((worker) => {
|
|
2935
|
+
const transport = startup.workers.find((candidate) => candidate.name === worker.name);
|
|
2936
|
+
return transport ? [{ ...worker, pane_id: transport.pane_id, pid: transport.pid }]
|
|
2937
|
+
: worker.index <= workerCount ? [] : [worker];
|
|
2938
|
+
});
|
|
2939
|
+
current.worker_count = current.workers.length;
|
|
2940
|
+
await saveTeamConfig(current, leaderCwd);
|
|
2941
|
+
return current;
|
|
2942
|
+
});
|
|
2943
|
+
};
|
|
2833
2944
|
const workerPaneIds = Array.from({ length: workerCount }, () => undefined);
|
|
2834
2945
|
const workerReadyTimeoutMs = resolveWorkerReadyTimeoutMs(launchEnv);
|
|
2835
2946
|
const workerStartupEvidenceTimeoutMs = resolveWorkerStartupEvidenceTimeoutMs(launchEnv, workerReadyTimeoutMs);
|
|
@@ -3033,14 +3144,14 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3033
3144
|
workerRole: plan.workerRole,
|
|
3034
3145
|
};
|
|
3035
3146
|
});
|
|
3036
|
-
const
|
|
3147
|
+
const materializeWorkerStartupIdentity = async (bootstrapPlan, workerIndex, paneId) => {
|
|
3037
3148
|
const workerWorkspace = bootstrapPlan.workerWorkspace;
|
|
3038
3149
|
const identity = {
|
|
3039
3150
|
name: bootstrapPlan.workerName,
|
|
3040
3151
|
index: workerIndex,
|
|
3041
3152
|
role: bootstrapPlan.workerRole,
|
|
3042
3153
|
worker_cli: bootstrapPlan.workerCli,
|
|
3043
|
-
assigned_tasks:
|
|
3154
|
+
assigned_tasks: config?.workers[workerIndex - 1]?.assigned_tasks ?? [],
|
|
3044
3155
|
working_dir: workerWorkspace.cwd,
|
|
3045
3156
|
worktree_repo_root: workerWorkspace.worktreeRepoRoot,
|
|
3046
3157
|
worktree_path: workerWorkspace.worktreePath,
|
|
@@ -3070,7 +3181,6 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3070
3181
|
config.workers[workerIndex - 1].pane_id = paneId;
|
|
3071
3182
|
config.workers[workerIndex - 1].role = bootstrapPlan.workerRole;
|
|
3072
3183
|
config.workers[workerIndex - 1].worker_cli = bootstrapPlan.workerCli;
|
|
3073
|
-
config.workers[workerIndex - 1].assigned_tasks = bootstrapPlan.workerTasks.map((task) => task.id);
|
|
3074
3184
|
config.workers[workerIndex - 1].working_dir = workerWorkspace.cwd;
|
|
3075
3185
|
config.workers[workerIndex - 1].worktree_repo_root = workerWorkspace.worktreeRepoRoot;
|
|
3076
3186
|
config.workers[workerIndex - 1].worktree_path = workerWorkspace.worktreePath;
|
|
@@ -3080,7 +3190,6 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3080
3190
|
config.workers[workerIndex - 1].team_state_root = teamStateRoot;
|
|
3081
3191
|
}
|
|
3082
3192
|
await writeWorkerIdentity(sanitized, bootstrapPlan.workerName, identity, leaderCwd);
|
|
3083
|
-
await writeWorkerInbox(sanitized, bootstrapPlan.workerName, bootstrapPlan.inbox, leaderCwd);
|
|
3084
3193
|
};
|
|
3085
3194
|
// 6. Create worker runtime (interactive tmux panes or prompt-mode child processes)
|
|
3086
3195
|
await writeTeamPreflightContextPacket({
|
|
@@ -3099,7 +3208,27 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3099
3208
|
writeWarning: options.writeCleanupWarning,
|
|
3100
3209
|
});
|
|
3101
3210
|
const startupTiming = createStartupTimingRecorder(sanitized, leaderCwd);
|
|
3211
|
+
// For herdr mode, all workers are ready after createHerdrTeam returns.
|
|
3212
|
+
// For interactive/prompt modes, readiness is determined per-worker.
|
|
3213
|
+
let herdrTeamReady = false;
|
|
3102
3214
|
let workerStartupArgs;
|
|
3215
|
+
// Initial prompts can execute during pane/process creation, before it returns.
|
|
3216
|
+
config = await withTeamTaskMembershipBarrier(sanitized, leaderCwd, async () => {
|
|
3217
|
+
const current = await readTeamConfig(sanitized, leaderCwd);
|
|
3218
|
+
if (!current)
|
|
3219
|
+
throw new Error(`team_config_missing:${sanitized}`);
|
|
3220
|
+
config = current;
|
|
3221
|
+
const startupTasks = await listTasks(sanitized, leaderCwd);
|
|
3222
|
+
for (let i = 1; i <= workerCount; i++) {
|
|
3223
|
+
const plan = workerBootstrapPlans[i - 1];
|
|
3224
|
+
current.workers[i - 1].assigned_tasks = startupTasks
|
|
3225
|
+
.filter((task) => task.owner === plan.workerName).map((task) => task.id);
|
|
3226
|
+
await materializeWorkerStartupIdentity(plan, i, undefined);
|
|
3227
|
+
await writeWorkerInbox(sanitized, plan.workerName, plan.inbox, leaderCwd);
|
|
3228
|
+
}
|
|
3229
|
+
await saveTeamConfig(current, leaderCwd);
|
|
3230
|
+
return current;
|
|
3231
|
+
});
|
|
3103
3232
|
if (workerLaunchMode === 'interactive') {
|
|
3104
3233
|
const createdSession = createTeamSession(sanitized, workerCount, leaderCwd, Array.from(workerLaunchPolicyPlan[0]?.workerLaunchArgs ?? []), workerStartups, { ownerSessionId: leaderSessionId, teamPaneOwnerId: config.tmux_pane_owner_id });
|
|
3105
3234
|
sessionName = createdSession.name;
|
|
@@ -3126,6 +3255,47 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3126
3255
|
startupTiming.mark('split_returned', { worker: `worker-${index + 1}`, pane_id: paneId });
|
|
3127
3256
|
}
|
|
3128
3257
|
}
|
|
3258
|
+
else if (workerLaunchMode === 'herdr') {
|
|
3259
|
+
const herdrPlans = [];
|
|
3260
|
+
for (let i = 1; i <= workerCount; i++) {
|
|
3261
|
+
const startup = workerStartups[i - 1];
|
|
3262
|
+
const workerLaunchPolicy = workerLaunchPolicyPlan[i - 1];
|
|
3263
|
+
if (!startup || !workerLaunchPolicy) {
|
|
3264
|
+
throw new Error(`missing worker launch plan for worker-${i}`);
|
|
3265
|
+
}
|
|
3266
|
+
const spec = buildWorkerProcessLaunchSpec(sanitized, i, startup.launchArgs, startup.cwd, startup.env, startup.workerCli, startup.initialPrompt, startup.workerRole);
|
|
3267
|
+
herdrPlans.push({
|
|
3268
|
+
kind: spec.workerCli,
|
|
3269
|
+
agentArgs: spec.args,
|
|
3270
|
+
env: spec.env,
|
|
3271
|
+
cwd: startup.cwd,
|
|
3272
|
+
initialPrompt: startup.initialPrompt,
|
|
3273
|
+
});
|
|
3274
|
+
}
|
|
3275
|
+
const herdrTeam = await createHerdrTeam(sanitized, leaderCwd, herdrPlans, { env: launchEnv });
|
|
3276
|
+
// createHerdrTeam returns only after every agent reached an idle,
|
|
3277
|
+
// promptable state (agent-start readiness + settle polling): that is
|
|
3278
|
+
// the herdr equivalent of observing a ready prompt in a tmux pane.
|
|
3279
|
+
herdrTeamReady = true;
|
|
3280
|
+
sessionName = herdrTeam.name;
|
|
3281
|
+
sessionCreated = true;
|
|
3282
|
+
config.tmux_session = herdrTeam.name;
|
|
3283
|
+
config.leader_pane_id = null;
|
|
3284
|
+
config.hud_pane_id = null;
|
|
3285
|
+
config.leader_pane_pid = null;
|
|
3286
|
+
config.hud_pane_pid = null;
|
|
3287
|
+
config.resize_hook_name = null;
|
|
3288
|
+
config.resize_hook_target = null;
|
|
3289
|
+
for (const worker of herdrTeam.workers) {
|
|
3290
|
+
if (config.workers[worker.index - 1]) {
|
|
3291
|
+
config.workers[worker.index - 1].pane_id = worker.paneId;
|
|
3292
|
+
config.workers[worker.index - 1].pid = undefined;
|
|
3293
|
+
}
|
|
3294
|
+
workerPaneIds[worker.index - 1] = worker.paneId;
|
|
3295
|
+
createdWorkerPaneIds.push(worker.paneId);
|
|
3296
|
+
startupTiming.mark('split_returned', { worker: `worker-${worker.index}`, pane_id: worker.paneId });
|
|
3297
|
+
}
|
|
3298
|
+
}
|
|
3129
3299
|
else {
|
|
3130
3300
|
config.tmux_session = `prompt-${sanitized}`;
|
|
3131
3301
|
config.leader_pane_id = null;
|
|
@@ -3146,17 +3316,16 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3146
3316
|
}
|
|
3147
3317
|
}
|
|
3148
3318
|
}
|
|
3149
|
-
|
|
3150
|
-
//
|
|
3319
|
+
await persistStartupTransport();
|
|
3320
|
+
// Refresh transport identities only; a running worker may already have a follow-up inbox.
|
|
3151
3321
|
for (let i = 1; i <= workerCount; i++) {
|
|
3152
3322
|
const bootstrapPlan = workerBootstrapPlans[i - 1];
|
|
3153
3323
|
if (!bootstrapPlan) {
|
|
3154
3324
|
throw new Error(`missing bootstrap plan for worker-${i}`);
|
|
3155
3325
|
}
|
|
3156
|
-
await
|
|
3157
|
-
startupTiming.mark('
|
|
3326
|
+
await materializeWorkerStartupIdentity(bootstrapPlan, i, workerPaneIds[i - 1]);
|
|
3327
|
+
startupTiming.mark('identity_written', { worker: bootstrapPlan.workerName, pane_id: workerPaneIds[i - 1] });
|
|
3158
3328
|
}
|
|
3159
|
-
await saveTeamConfig(config, leaderCwd);
|
|
3160
3329
|
// 7. Start all safe per-worker readiness/dispatch attempts concurrently.
|
|
3161
3330
|
// Pane creation and worktree provisioning above remain dependency-bound and
|
|
3162
3331
|
// ordered; readiness polling and startup dispatch must not let worker-1
|
|
@@ -3173,10 +3342,11 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3173
3342
|
error: new Error(`missing bootstrap plan for worker-${workerIndex}`),
|
|
3174
3343
|
};
|
|
3175
3344
|
}
|
|
3345
|
+
// Each worker has its own readiness state; don't leak evidence from other workers.
|
|
3346
|
+
let startupReadyPromptObserved = herdrTeamReady || workerLaunchMode === 'herdr';
|
|
3176
3347
|
const workerName = bootstrapPlan.workerName;
|
|
3177
3348
|
const paneId = workerPaneIds[workerIndex - 1];
|
|
3178
3349
|
const workerTasks = bootstrapPlan.workerTasks;
|
|
3179
|
-
const inbox = bootstrapPlan.inbox;
|
|
3180
3350
|
const trigger = bootstrapPlan.trigger;
|
|
3181
3351
|
const triggerIntent = bootstrapPlan.triggerIntent;
|
|
3182
3352
|
const initialPrompt = bootstrapPlan.initialPrompt;
|
|
@@ -3194,7 +3364,6 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3194
3364
|
paneId,
|
|
3195
3365
|
workerCli: bootstrapPlan.workerCli,
|
|
3196
3366
|
finalArgs: workerStartupArgs?.[workerIndex - 1],
|
|
3197
|
-
inbox,
|
|
3198
3367
|
triggerMessage: trigger,
|
|
3199
3368
|
intent: triggerIntent,
|
|
3200
3369
|
taskIds: workerTasks.map((task) => task.id),
|
|
@@ -3217,7 +3386,6 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3217
3386
|
error: new Error(`worker_startup_incompatible:${workerName}:${startupDirectOutcome.reason}`),
|
|
3218
3387
|
};
|
|
3219
3388
|
}
|
|
3220
|
-
let startupReadyPromptObserved = false;
|
|
3221
3389
|
if (workerLaunchMode === 'interactive' && !skipWorkerReadyWait && !initialPrompt && !startupDirectOutcome?.ok) {
|
|
3222
3390
|
startupTiming.mark('ready_wait_start', { worker: workerName, pane_id: paneId });
|
|
3223
3391
|
let readinessIncompatibility = null;
|
|
@@ -3278,7 +3446,6 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3278
3446
|
workerIndex,
|
|
3279
3447
|
paneId,
|
|
3280
3448
|
workerCli: bootstrapPlan.workerCli,
|
|
3281
|
-
inbox,
|
|
3282
3449
|
triggerMessage: trigger,
|
|
3283
3450
|
intent: triggerIntent,
|
|
3284
3451
|
cwd: leaderCwd,
|
|
@@ -3356,7 +3523,10 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3356
3523
|
if (firstStartupError) {
|
|
3357
3524
|
throw firstStartupError.error;
|
|
3358
3525
|
}
|
|
3359
|
-
|
|
3526
|
+
// Startup attempts only read config; workers may have changed canonical task assignments meanwhile.
|
|
3527
|
+
config = await readTeamConfig(sanitized, leaderCwd);
|
|
3528
|
+
if (!config)
|
|
3529
|
+
throw new Error(`team_config_missing:${sanitized}`);
|
|
3360
3530
|
await startupTiming.flush();
|
|
3361
3531
|
return {
|
|
3362
3532
|
teamName: sanitized,
|
|
@@ -3376,7 +3546,7 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3376
3546
|
createdWorkerPaneIds.push(...partialSession.workerPaneIds);
|
|
3377
3547
|
createdLeaderPaneId = partialSession.leaderPaneId;
|
|
3378
3548
|
applyCreatedInteractiveSessionToConfig(config, partialSession, workerPaneIds);
|
|
3379
|
-
await
|
|
3549
|
+
await persistStartupTransport();
|
|
3380
3550
|
const cleanupDebt = [
|
|
3381
3551
|
...error.cleanupErrors,
|
|
3382
3552
|
...error.proofUnavailable.map((proof) => `pane_proof_unavailable:${proof.paneId}:${proof.reason}`),
|
|
@@ -3407,7 +3577,7 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3407
3577
|
: [];
|
|
3408
3578
|
});
|
|
3409
3579
|
if (startupCleanupDebt.length > 0) {
|
|
3410
|
-
await
|
|
3580
|
+
await persistStartupTransport();
|
|
3411
3581
|
await appendTeamEvent(sanitized, {
|
|
3412
3582
|
type: 'team_leader_nudge',
|
|
3413
3583
|
worker: 'leader-fixed',
|
|
@@ -3453,7 +3623,7 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3453
3623
|
}
|
|
3454
3624
|
if (paneProcessProofUnavailable.length > 0) {
|
|
3455
3625
|
if (config)
|
|
3456
|
-
await
|
|
3626
|
+
await persistStartupTransport();
|
|
3457
3627
|
assertPaneTeardownProofsAvailable('startup_rollback', paneProcessProofUnavailable);
|
|
3458
3628
|
}
|
|
3459
3629
|
const rollbackPanePids = Object.fromEntries((config?.workers ?? [])
|
|
@@ -3486,7 +3656,7 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3486
3656
|
if (rollbackPaneTeardown.proofUnavailable.length > 0) {
|
|
3487
3657
|
if (config) {
|
|
3488
3658
|
try {
|
|
3489
|
-
await
|
|
3659
|
+
await persistStartupTransport();
|
|
3490
3660
|
}
|
|
3491
3661
|
catch (cleanupError) {
|
|
3492
3662
|
rollbackErrors.push(`saveTeamConfig(preserve rollback state): ${String(cleanupError)}`);
|
|
@@ -3496,7 +3666,7 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3496
3666
|
}
|
|
3497
3667
|
if (rollbackPaneTeardown.kill.failed > 0) {
|
|
3498
3668
|
if (config)
|
|
3499
|
-
await
|
|
3669
|
+
await persistStartupTransport();
|
|
3500
3670
|
const originalMessage = error instanceof Error ? error.message : String(error);
|
|
3501
3671
|
throw new Error(`${originalMessage}; rollback encountered errors: paneTeardown:${rollbackPaneTeardown.kill.failedPaneIds.join(',')}`);
|
|
3502
3672
|
}
|
|
@@ -3633,9 +3803,7 @@ export async function monitorTeam(teamName, cwd, options = {}) {
|
|
|
3633
3803
|
const recommendations = [];
|
|
3634
3804
|
const workerScanStartMs = performance.now();
|
|
3635
3805
|
const workerSignals = await Promise.all(config.workers.map(async (worker) => {
|
|
3636
|
-
const alive = config
|
|
3637
|
-
? isPromptWorkerAlive(config, worker)
|
|
3638
|
-
: isWorkerAlive(sessionName, worker.index, worker.pane_id, worker.pid, config.tmux_pane_owner_id ?? undefined, config.hud_pane_id ?? undefined);
|
|
3806
|
+
const alive = await isTeamWorkerAliveForMode(config, sessionName, worker);
|
|
3639
3807
|
const [status, heartbeat] = await Promise.all([
|
|
3640
3808
|
readWorkerStatus(sanitized, worker.name, cwd),
|
|
3641
3809
|
readWorkerHeartbeat(sanitized, worker.name, cwd),
|
|
@@ -3736,36 +3904,71 @@ export async function monitorTeam(teamName, cwd, options = {}) {
|
|
|
3736
3904
|
}
|
|
3737
3905
|
}
|
|
3738
3906
|
const allTasksTerminal = taskCounts.pending === 0 && taskCounts.blocked === 0 && taskCounts.in_progress === 0;
|
|
3739
|
-
const deadWorkerStall = config.worker_launch_mode
|
|
3907
|
+
const deadWorkerStall = config.worker_launch_mode !== 'interactive'
|
|
3740
3908
|
&& config.workers.length > 0
|
|
3741
3909
|
&& deadWorkers.length >= config.workers.length
|
|
3742
3910
|
&& !allTasksTerminal;
|
|
3743
|
-
const
|
|
3911
|
+
const integrationByWorker = readOnly
|
|
3912
|
+
? (previousSnapshot?.integrationByWorker ?? {})
|
|
3913
|
+
: await integrateWorkerCommitsIntoLeader({
|
|
3914
|
+
teamName: sanitized,
|
|
3915
|
+
config,
|
|
3916
|
+
previous: previousSnapshot,
|
|
3917
|
+
cwd,
|
|
3918
|
+
});
|
|
3919
|
+
const deliveryWorkers = config.workers.filter((worker) => worker.worktree_path && worker.worktree_repo_root);
|
|
3920
|
+
let integrationPending = false;
|
|
3921
|
+
let integrationFailed = false;
|
|
3922
|
+
for (const worker of deliveryWorkers) {
|
|
3923
|
+
const delivery = integrationByWorker[worker.name];
|
|
3924
|
+
if (delivery?.status === 'cherry_pick_conflict' || delivery?.status === 'integration_failed' || delivery?.status === 'rebase_conflict' || delivery?.pending_rebase_leader_head) {
|
|
3925
|
+
integrationFailed = true;
|
|
3926
|
+
recommendations.push(`Integration unresolved for ${worker.name}; resolve delivery failure before terminal success`);
|
|
3927
|
+
continue;
|
|
3928
|
+
}
|
|
3929
|
+
if (worktreeHasUnfinishedRebase(worker.worktree_repo_root, worker.worktree_path)) {
|
|
3930
|
+
integrationFailed = true;
|
|
3931
|
+
recommendations.push(`Integration unresolved for ${worker.name}; unfinished rebase preserved before terminal success`);
|
|
3932
|
+
continue;
|
|
3933
|
+
}
|
|
3934
|
+
const workerHead = resolveWorkerHead(worker.worktree_path);
|
|
3935
|
+
const status = runGitCommand(worker.worktree_repo_root, ['--no-optional-locks', 'status', '--porcelain', '--untracked-files=all', '--ignore-submodules=none'], worker.worktree_path);
|
|
3936
|
+
const contained = workerHead && leaderContainsCommit(worker.worktree_repo_root, cwd, workerHead);
|
|
3937
|
+
const delivered = workerHead && delivery?.last_integrated_head === workerHead
|
|
3938
|
+
&& delivery.delivery_leader_commit && leaderContainsCommit(worker.worktree_repo_root, cwd, delivery.delivery_leader_commit);
|
|
3939
|
+
if (!workerHead || !status.ok || status.stdout.trim() || (!contained && !delivered)) {
|
|
3940
|
+
integrationPending = true;
|
|
3941
|
+
recommendations.push(`Integration pending for ${worker.name}; verify code delivery before terminal success`);
|
|
3942
|
+
}
|
|
3943
|
+
}
|
|
3744
3944
|
const targetPhase = deadWorkerStall
|
|
3745
3945
|
? 'failed'
|
|
3746
3946
|
: inferPhaseTargetFromTaskCounts(taskCounts, {
|
|
3747
|
-
verificationPending: verificationPendingTasks.length > 0,
|
|
3947
|
+
verificationPending: verificationPendingTasks.length > 0 || integrationPending,
|
|
3748
3948
|
});
|
|
3749
|
-
const
|
|
3750
|
-
|
|
3751
|
-
|
|
3949
|
+
const deliveryGatedTarget = targetPhase === 'complete' || targetPhase === 'team-verify'
|
|
3950
|
+
? integrationFailed ? 'team-fix' : targetPhase
|
|
3951
|
+
: targetPhase;
|
|
3952
|
+
const reconcileMonitorPhase = async () => {
|
|
3953
|
+
const persistedPhase = await readTeamPhaseState(sanitized, cwd);
|
|
3954
|
+
const next = reconcilePhaseStateForMonitor(persistedPhase, deliveryGatedTarget);
|
|
3955
|
+
if (!readOnly) {
|
|
3956
|
+
await writeTeamPhaseState(sanitized, next, cwd);
|
|
3957
|
+
await syncRootTeamModeStateForMonitor(sanitized, next, integrationPending || integrationFailed, cwd);
|
|
3958
|
+
}
|
|
3959
|
+
return next;
|
|
3960
|
+
};
|
|
3961
|
+
// Shutdown publishes its epoch under this barrier; never reopen root from a stale phase read.
|
|
3962
|
+
const phaseState = readOnly
|
|
3963
|
+
? await reconcileMonitorPhase()
|
|
3964
|
+
: await withTeamTaskMembershipBarrier(sanitized, cwd, reconcileMonitorPhase);
|
|
3752
3965
|
const phase = phaseState.current_phase;
|
|
3753
|
-
if (!readOnly)
|
|
3754
|
-
await syncRootTeamModeStateOnTerminalPhase(sanitized, phase, cwd);
|
|
3755
3966
|
if (deadWorkerStall) {
|
|
3756
3967
|
recommendations.push('All workers are dead while work remains; mark the team failed or restart with fresh workers.');
|
|
3757
3968
|
}
|
|
3758
3969
|
if (!readOnly) {
|
|
3759
3970
|
await emitMonitorDerivedEvents(sanitized, taskView, workers, previousSnapshot, config.worker_launch_mode, cwd);
|
|
3760
3971
|
}
|
|
3761
|
-
const integrationByWorker = readOnly
|
|
3762
|
-
? (previousSnapshot?.integrationByWorker ?? {})
|
|
3763
|
-
: await integrateWorkerCommitsIntoLeader({
|
|
3764
|
-
teamName: sanitized,
|
|
3765
|
-
config,
|
|
3766
|
-
previous: previousSnapshot,
|
|
3767
|
-
cwd,
|
|
3768
|
-
});
|
|
3769
3972
|
const mailboxDeliveryStartMs = performance.now();
|
|
3770
3973
|
const mailboxNotifiedByMessageId = phaseState.terminal_epoch
|
|
3771
3974
|
? {}
|
|
@@ -3863,6 +4066,11 @@ export async function assignTask(teamName, workerName, taskId, cwd) {
|
|
|
3863
4066
|
if (!workerInfo)
|
|
3864
4067
|
throw new Error(`Worker ${workerName} not found in team`);
|
|
3865
4068
|
const dispatchPolicy = resolveDispatchPolicy(manifest?.policy, config.worker_launch_mode);
|
|
4069
|
+
const outstandingTask = (await listTasks(sanitized, cwd)).find((current) => current.id !== taskId && current.owner === workerName
|
|
4070
|
+
&& (current.status === 'pending' || current.status === 'in_progress'));
|
|
4071
|
+
if (outstandingTask) {
|
|
4072
|
+
throw new Error(`Worker ${workerName} already owns outstanding task ${outstandingTask.id}`);
|
|
4073
|
+
}
|
|
3866
4074
|
const claim = await claimTask(sanitized, taskId, workerName, task.version ?? 1, cwd);
|
|
3867
4075
|
if (!claim.ok) {
|
|
3868
4076
|
if (claim.error === 'blocked_dependency') {
|
|
@@ -3883,24 +4091,24 @@ export async function assignTask(teamName, workerName, taskId, cwd) {
|
|
|
3883
4091
|
: synthesizeCoordinationPlan(task);
|
|
3884
4092
|
const hasCurrentCoordination = task.coordination?.source === 'explicit' || coordinationPlansEqual(task.coordination, currentCoordinationPlan);
|
|
3885
4093
|
const taskForInbox = task.delegation && hasCurrentCoordination
|
|
3886
|
-
? task
|
|
4094
|
+
? claim.task
|
|
3887
4095
|
: (await updateTask(sanitized, taskId, {
|
|
3888
4096
|
delegation: task.delegation ?? synthesizeDelegationPlan(task),
|
|
3889
4097
|
coordination: task.coordination?.source === 'explicit' ? task.coordination : currentCoordinationPlan,
|
|
3890
|
-
}, cwd)) ?? task;
|
|
4098
|
+
}, cwd)) ?? claim.task;
|
|
3891
4099
|
const inbox = generateTaskAssignmentInbox(workerName, sanitized, taskForInbox, { approvedContextSection });
|
|
3892
4100
|
const maxAssignRetries = 2;
|
|
3893
4101
|
const assignRetryDelayS = 2;
|
|
3894
4102
|
let outcome = { ok: false, transport: 'none', reason: 'not_attempted' };
|
|
3895
4103
|
const triggerDirective = buildTriggerDirective(workerName, sanitized, resolveInstructionStateRoot(workerInfo.worktree_path));
|
|
3896
4104
|
for (let attempt = 1; attempt <= maxAssignRetries; attempt++) {
|
|
4105
|
+
await writeWorkerInbox(sanitized, workerName, inbox, cwd);
|
|
3897
4106
|
outcome = await dispatchCriticalInboxInstruction({
|
|
3898
4107
|
teamName: sanitized,
|
|
3899
4108
|
config,
|
|
3900
4109
|
workerName,
|
|
3901
4110
|
workerIndex: workerInfo.index,
|
|
3902
4111
|
paneId: workerInfo.pane_id,
|
|
3903
|
-
inbox,
|
|
3904
4112
|
triggerMessage: triggerDirective.text,
|
|
3905
4113
|
intent: triggerDirective.intent,
|
|
3906
4114
|
cwd,
|
|
@@ -4120,13 +4328,13 @@ export async function shutdownTeam(teamName, cwd, options = {}) {
|
|
|
4120
4328
|
await writeShutdownRequest(sanitized, w.name, 'leader-fixed', cwd);
|
|
4121
4329
|
shutdownRequestTimes.set(w.name, requestedAt);
|
|
4122
4330
|
const triggerDirective = buildTriggerDirective(w.name, sanitized, resolveInstructionStateRoot(w.worktree_path));
|
|
4331
|
+
await writeWorkerInbox(sanitized, w.name, generateShutdownInbox(sanitized, w.name), cwd);
|
|
4123
4332
|
await dispatchCriticalInboxInstruction({
|
|
4124
4333
|
teamName: sanitized,
|
|
4125
4334
|
config,
|
|
4126
4335
|
workerName: w.name,
|
|
4127
4336
|
workerIndex: w.index,
|
|
4128
4337
|
paneId: w.pane_id,
|
|
4129
|
-
inbox: generateShutdownInbox(sanitized, w.name),
|
|
4130
4338
|
triggerMessage: triggerDirective.text,
|
|
4131
4339
|
intent: triggerDirective.intent,
|
|
4132
4340
|
cwd,
|
|
@@ -4163,17 +4371,15 @@ export async function shutdownTeam(teamName, cwd, options = {}) {
|
|
|
4163
4371
|
const detail = rejected.map(r => `${r.worker}:${r.reason}`).join(',');
|
|
4164
4372
|
throw new Error(`shutdown_rejected:${detail}`);
|
|
4165
4373
|
}
|
|
4166
|
-
const
|
|
4167
|
-
|
|
4168
|
-
: isWorkerAlive(sessionName, w.index, w.pane_id, w.pid, config.tmux_pane_owner_id ?? undefined, config.hud_pane_id ?? undefined)));
|
|
4374
|
+
const anyAliveSignals = await Promise.all(config.workers.map((w) => isTeamWorkerAliveForMode(config, sessionName, w)));
|
|
4375
|
+
const anyAlive = anyAliveSignals.some(Boolean);
|
|
4169
4376
|
if (!anyAlive)
|
|
4170
4377
|
break;
|
|
4171
4378
|
// Sleep 2s
|
|
4172
4379
|
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
4173
4380
|
}
|
|
4174
|
-
const
|
|
4175
|
-
|
|
4176
|
-
: isWorkerAlive(sessionName, w.index, w.pane_id, w.pid, config.tmux_pane_owner_id ?? undefined, config.hud_pane_id ?? undefined)));
|
|
4381
|
+
const anyAliveAfterWaitSignals = await Promise.all(config.workers.map((w) => isTeamWorkerAliveForMode(config, sessionName, w)));
|
|
4382
|
+
const anyAliveAfterWait = anyAliveAfterWaitSignals.some(Boolean);
|
|
4177
4383
|
if (anyAliveAfterWait && !force) {
|
|
4178
4384
|
// Workers may have accepted shutdown but not exited (Codex TUI requires explicit exit).
|
|
4179
4385
|
// In this case, proceed to force kill panes (next step) rather than failing and leaving state around.
|
|
@@ -4541,6 +4747,44 @@ export async function shutdownTeam(teamName, cwd, options = {}) {
|
|
|
4541
4747
|
throw new Error(`shutdown_pane_teardown_failed:${workerTeardown.kill.failedPaneIds.join(',')}`);
|
|
4542
4748
|
}
|
|
4543
4749
|
}
|
|
4750
|
+
else if (config.worker_launch_mode === 'herdr') {
|
|
4751
|
+
const herdrTeardownFailures = [];
|
|
4752
|
+
let herdrWorkspaceClosed = false;
|
|
4753
|
+
for (const w of config.workers) {
|
|
4754
|
+
if (typeof w.pane_id !== 'string' || w.pane_id === '')
|
|
4755
|
+
continue;
|
|
4756
|
+
try {
|
|
4757
|
+
await interruptHerdrWorker(w.pane_id);
|
|
4758
|
+
}
|
|
4759
|
+
catch {
|
|
4760
|
+
// Best-effort interrupt: teardown below still removes the pane.
|
|
4761
|
+
}
|
|
4762
|
+
try {
|
|
4763
|
+
await teardownHerdrWorker(w.pane_id);
|
|
4764
|
+
}
|
|
4765
|
+
catch (error) {
|
|
4766
|
+
herdrTeardownFailures.push(`${w.name}:${error instanceof Error ? error.message : String(error)}`);
|
|
4767
|
+
}
|
|
4768
|
+
}
|
|
4769
|
+
const firstHerdrPane = config.workers
|
|
4770
|
+
.map((w) => w.pane_id)
|
|
4771
|
+
.find((paneId) => typeof paneId === 'string' && paneId !== '');
|
|
4772
|
+
if (firstHerdrPane) {
|
|
4773
|
+
try {
|
|
4774
|
+
await destroyHerdrTeam(herdrWorkspaceIdFromPaneId(firstHerdrPane));
|
|
4775
|
+
herdrWorkspaceClosed = true;
|
|
4776
|
+
}
|
|
4777
|
+
catch (error) {
|
|
4778
|
+
herdrTeardownFailures.push(`workspace:${error instanceof Error ? error.message : String(error)}`);
|
|
4779
|
+
}
|
|
4780
|
+
}
|
|
4781
|
+
if (herdrTeardownFailures.length > 0 && !herdrWorkspaceClosed) {
|
|
4782
|
+
throw new Error(`shutdown_herdr_teardown_failed:${herdrTeardownFailures.join(',')}`);
|
|
4783
|
+
}
|
|
4784
|
+
if (herdrTeardownFailures.length > 0 && herdrWorkspaceClosed) {
|
|
4785
|
+
console.warn(`[team shutdown] ${sanitized}: herdr pane teardown issues: ${herdrTeardownFailures.join(',')}`);
|
|
4786
|
+
}
|
|
4787
|
+
}
|
|
4544
4788
|
else if (config.worker_launch_mode === 'prompt') {
|
|
4545
4789
|
const promptTeardownFailures = [];
|
|
4546
4790
|
const promptTeardownResults = new Map();
|
|
@@ -4731,7 +4975,14 @@ export async function resumeTeam(teamName, cwd) {
|
|
|
4731
4975
|
if (approvedExecutionState.status === 'stale') {
|
|
4732
4976
|
throw new Error(`approved_execution_binding_stale:${approvedExecutionState.binding.prd_path}:${approvedExecutionState.binding.task}`);
|
|
4733
4977
|
}
|
|
4734
|
-
if (config.worker_launch_mode === '
|
|
4978
|
+
if (config.worker_launch_mode === 'herdr') {
|
|
4979
|
+
const aliveSignals = await Promise.all(config.workers
|
|
4980
|
+
.filter((worker) => typeof worker.pane_id === 'string' && worker.pane_id !== '')
|
|
4981
|
+
.map((worker) => isHerdrWorkerAlive(worker.pane_id)));
|
|
4982
|
+
if (!aliveSignals.some(Boolean))
|
|
4983
|
+
return null;
|
|
4984
|
+
}
|
|
4985
|
+
else if (config.worker_launch_mode === 'prompt') {
|
|
4735
4986
|
const handleTeamConfig = { ...config, name: sanitized };
|
|
4736
4987
|
const hasLivePromptWorker = config.workers.some((worker) => isPromptWorkerAlive(handleTeamConfig, worker));
|
|
4737
4988
|
if (!hasLivePromptWorker)
|
|
@@ -4773,9 +5024,7 @@ async function findActiveTeams(cwd, leaderSessionId) {
|
|
|
4773
5024
|
if (!existsSync(root))
|
|
4774
5025
|
return [];
|
|
4775
5026
|
const listedSessions = listTeamSessions();
|
|
4776
|
-
|
|
4777
|
-
throw new Error('tmux_session_query_unavailable');
|
|
4778
|
-
const sessions = new Set(listedSessions);
|
|
5027
|
+
const sessions = listedSessions !== null ? new Set(listedSessions) : null;
|
|
4779
5028
|
const entries = await readdir(root, { withFileTypes: true });
|
|
4780
5029
|
const active = [];
|
|
4781
5030
|
for (const e of entries) {
|
|
@@ -4802,6 +5051,19 @@ async function findActiveTeams(cwd, leaderSessionId) {
|
|
|
4802
5051
|
}
|
|
4803
5052
|
continue;
|
|
4804
5053
|
}
|
|
5054
|
+
if (workerLaunchMode === 'herdr') {
|
|
5055
|
+
const herdrAlive = await Promise.all((cfg?.workers ?? [])
|
|
5056
|
+
.filter((worker) => typeof worker.pane_id === 'string' && worker.pane_id !== '')
|
|
5057
|
+
.map((worker) => isHerdrWorkerAlive(worker.pane_id)));
|
|
5058
|
+
if (herdrAlive.some(Boolean)) {
|
|
5059
|
+
active.push(teamName);
|
|
5060
|
+
}
|
|
5061
|
+
continue;
|
|
5062
|
+
}
|
|
5063
|
+
if (sessions === null) {
|
|
5064
|
+
// An interactive (tmux) team exists but tmux cannot be queried.
|
|
5065
|
+
throw new Error('tmux_session_query_unavailable');
|
|
5066
|
+
}
|
|
4805
5067
|
if (sessions.has(tmuxSession))
|
|
4806
5068
|
active.push(teamName);
|
|
4807
5069
|
}
|
|
@@ -4811,12 +5073,23 @@ async function detectAndCleanStaleTeam(teamName, leaderCwd, workerCount, confirm
|
|
|
4811
5073
|
const stateDir = teamRuntimeTeamRoot(teamName, leaderCwd);
|
|
4812
5074
|
if (!existsSync(stateDir))
|
|
4813
5075
|
return;
|
|
4814
|
-
const
|
|
4815
|
-
if (
|
|
4816
|
-
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
|
|
5076
|
+
const existingConfig = await readTeamConfig(teamName, leaderCwd);
|
|
5077
|
+
if (existingConfig?.worker_launch_mode === 'herdr') {
|
|
5078
|
+
// Herdr teams have no tmux session; liveness comes from their panes.
|
|
5079
|
+
const herdrAlive = await Promise.all((existingConfig.workers ?? [])
|
|
5080
|
+
.filter((worker) => typeof worker.pane_id === 'string' && worker.pane_id !== '')
|
|
5081
|
+
.map((worker) => isHerdrWorkerAlive(worker.pane_id)));
|
|
5082
|
+
if (herdrAlive.some(Boolean))
|
|
5083
|
+
return;
|
|
5084
|
+
}
|
|
5085
|
+
else {
|
|
5086
|
+
const listedSessions = listTeamSessions();
|
|
5087
|
+
if (listedSessions === null)
|
|
5088
|
+
return;
|
|
5089
|
+
const sessions = new Set(listedSessions);
|
|
5090
|
+
if (sessions.has(`omx-team-${teamName}`))
|
|
5091
|
+
return;
|
|
5092
|
+
}
|
|
4820
5093
|
const repoRootResult = spawnSync('git', ['rev-parse', '--show-toplevel'], {
|
|
4821
5094
|
cwd: leaderCwd, encoding: 'utf-8', windowsHide: true,
|
|
4822
5095
|
});
|
|
@@ -4948,10 +5221,38 @@ async function emitMonitorDerivedEvents(teamName, tasks, workers, previous, work
|
|
|
4948
5221
|
}
|
|
4949
5222
|
}
|
|
4950
5223
|
}
|
|
5224
|
+
/** Backend-aware worker liveness: prompt children, herdr panes, or tmux panes. */
|
|
5225
|
+
async function isTeamWorkerAliveForMode(config, sessionName, worker) {
|
|
5226
|
+
if (config.worker_launch_mode === 'prompt') {
|
|
5227
|
+
return isPromptWorkerAlive(config, worker);
|
|
5228
|
+
}
|
|
5229
|
+
if (config.worker_launch_mode === 'herdr') {
|
|
5230
|
+
if (typeof worker.pane_id !== 'string' || worker.pane_id === '')
|
|
5231
|
+
return false;
|
|
5232
|
+
return isHerdrWorkerAlive(worker.pane_id);
|
|
5233
|
+
}
|
|
5234
|
+
return isWorkerAlive(sessionName, worker.index, worker.pane_id, worker.pid, config.tmux_pane_owner_id ?? undefined, config.hud_pane_id ?? undefined);
|
|
5235
|
+
}
|
|
4951
5236
|
async function notifyWorkerOutcome(config, workerIndex, message, workerPaneId) {
|
|
4952
5237
|
const worker = config.workers.find((candidate) => candidate.index === workerIndex);
|
|
4953
5238
|
if (!worker)
|
|
4954
5239
|
return { ok: false, transport: 'none', reason: 'worker_not_found' };
|
|
5240
|
+
if (config.worker_launch_mode === 'herdr') {
|
|
5241
|
+
if (typeof worker.pane_id !== 'string' || worker.pane_id === '') {
|
|
5242
|
+
return { ok: false, transport: 'herdr_prompt', reason: 'herdr_pane_id_missing' };
|
|
5243
|
+
}
|
|
5244
|
+
try {
|
|
5245
|
+
await submitToHerdrWorker(worker.pane_id, message);
|
|
5246
|
+
return { ok: true, transport: 'herdr_prompt', reason: 'herdr_prompt_sent' };
|
|
5247
|
+
}
|
|
5248
|
+
catch (error) {
|
|
5249
|
+
return {
|
|
5250
|
+
ok: false,
|
|
5251
|
+
transport: 'herdr_prompt',
|
|
5252
|
+
reason: `herdr_prompt_failed:${error instanceof Error ? error.message : String(error)}`,
|
|
5253
|
+
};
|
|
5254
|
+
}
|
|
5255
|
+
}
|
|
4955
5256
|
if (config.worker_launch_mode === 'prompt') {
|
|
4956
5257
|
const handle = getPromptWorkerHandle(config.name, worker.name);
|
|
4957
5258
|
if (!handle)
|
|
@@ -5009,7 +5310,7 @@ async function markDispatchRequestLeaderPaneMissingDeferred(params) {
|
|
|
5009
5310
|
}, cwd).catch(() => { });
|
|
5010
5311
|
}
|
|
5011
5312
|
async function attemptStartupDirectTrigger(params) {
|
|
5012
|
-
const { teamName, config, workerName, workerIndex, paneId, workerCli, finalArgs,
|
|
5313
|
+
const { teamName, config, workerName, workerIndex, paneId, workerCli, finalArgs, triggerMessage, intent, taskIds, cwd, timing, } = params;
|
|
5013
5314
|
const safety = await evaluateStartupDirectTriggerSafety(config.tmux_session, workerIndex, paneId, workerCli, finalArgs);
|
|
5014
5315
|
if (!safety.safe) {
|
|
5015
5316
|
timing.mark('startup_direct_bypass', {
|
|
@@ -5023,12 +5324,11 @@ async function attemptStartupDirectTrigger(params) {
|
|
|
5023
5324
|
}
|
|
5024
5325
|
return null;
|
|
5025
5326
|
}
|
|
5026
|
-
const queued = await
|
|
5327
|
+
const queued = await queueInboxNotification({
|
|
5027
5328
|
teamName,
|
|
5028
5329
|
workerName,
|
|
5029
5330
|
workerIndex,
|
|
5030
5331
|
paneId,
|
|
5031
|
-
inbox,
|
|
5032
5332
|
triggerMessage,
|
|
5033
5333
|
intent,
|
|
5034
5334
|
cwd,
|
|
@@ -5095,17 +5395,16 @@ async function attemptStartupDirectTrigger(params) {
|
|
|
5095
5395
|
};
|
|
5096
5396
|
}
|
|
5097
5397
|
async function dispatchCriticalInboxInstruction(params) {
|
|
5098
|
-
const { teamName, config, workerName, workerIndex, paneId, workerCli,
|
|
5398
|
+
const { teamName, config, workerName, workerIndex, paneId, workerCli, triggerMessage, intent, cwd, dispatchPolicy, inboxCorrelationKey, requireWorkerStartupEvidence, startupEvidenceTimeoutMs, startupReadyPromptObserved = false, startupTiming, } = params;
|
|
5099
5399
|
const noteTiming = (phase, details) => {
|
|
5100
5400
|
startupTiming?.mark(phase, { worker: workerName, pane_id: paneId, ...details });
|
|
5101
5401
|
};
|
|
5102
5402
|
if (config.worker_launch_mode === 'prompt') {
|
|
5103
|
-
return await
|
|
5403
|
+
return await queueInboxNotification({
|
|
5104
5404
|
teamName,
|
|
5105
5405
|
workerName,
|
|
5106
5406
|
workerIndex,
|
|
5107
5407
|
paneId,
|
|
5108
|
-
inbox,
|
|
5109
5408
|
triggerMessage,
|
|
5110
5409
|
intent,
|
|
5111
5410
|
cwd,
|
|
@@ -5116,12 +5415,11 @@ async function dispatchCriticalInboxInstruction(params) {
|
|
|
5116
5415
|
});
|
|
5117
5416
|
}
|
|
5118
5417
|
if (dispatchPolicy.dispatch_mode === 'transport_direct') {
|
|
5119
|
-
return await
|
|
5418
|
+
return await queueInboxNotification({
|
|
5120
5419
|
teamName,
|
|
5121
5420
|
workerName,
|
|
5122
5421
|
workerIndex,
|
|
5123
5422
|
paneId,
|
|
5124
|
-
inbox,
|
|
5125
5423
|
triggerMessage,
|
|
5126
5424
|
intent,
|
|
5127
5425
|
cwd,
|
|
@@ -5131,12 +5429,11 @@ async function dispatchCriticalInboxInstruction(params) {
|
|
|
5131
5429
|
notify: (_target, message) => notifyWorkerOutcome(config, workerIndex, message, paneId),
|
|
5132
5430
|
});
|
|
5133
5431
|
}
|
|
5134
|
-
const queued = await
|
|
5432
|
+
const queued = await queueInboxNotification({
|
|
5135
5433
|
teamName,
|
|
5136
5434
|
workerName,
|
|
5137
5435
|
workerIndex,
|
|
5138
5436
|
paneId,
|
|
5139
|
-
inbox,
|
|
5140
5437
|
triggerMessage,
|
|
5141
5438
|
intent,
|
|
5142
5439
|
cwd,
|