oh-my-codex 0.22.0 → 0.22.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/Cargo.lock +6 -6
- package/Cargo.toml +1 -1
- 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/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/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/team/__tests__/completion-evidence.test.js +31 -1
- package/dist/team/__tests__/completion-evidence.test.js.map +1 -1
- 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__/mcp-comm.test.js +25 -1
- package/dist/team/__tests__/mcp-comm.test.js.map +1 -1
- package/dist/team/__tests__/p1-safety.test.d.ts +2 -0
- package/dist/team/__tests__/p1-safety.test.d.ts.map +1 -0
- package/dist/team/__tests__/p1-safety.test.js +553 -0
- package/dist/team/__tests__/p1-safety.test.js.map +1 -0
- package/dist/team/__tests__/runtime.test.js +607 -53
- package/dist/team/__tests__/runtime.test.js.map +1 -1
- package/dist/team/__tests__/scaling.test.js +355 -4
- package/dist/team/__tests__/scaling.test.js.map +1 -1
- package/dist/team/__tests__/state.test.js +127 -5
- package/dist/team/__tests__/state.test.js.map +1 -1
- package/dist/team/completion-evidence.d.ts +2 -1
- package/dist/team/completion-evidence.d.ts.map +1 -1
- package/dist/team/completion-evidence.js +30 -7
- package/dist/team/completion-evidence.js.map +1 -1
- package/dist/team/mcp-comm.d.ts +5 -3
- 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/runtime.d.ts.map +1 -1
- package/dist/team/runtime.js +244 -146
- 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 +73 -67
- package/dist/team/scaling.js.map +1 -1
- package/dist/team/state/tasks.d.ts +2 -0
- package/dist/team/state/tasks.d.ts.map +1 -1
- package/dist/team/state/tasks.js +28 -22
- package/dist/team/state/tasks.js.map +1 -1
- package/dist/team/state/types.d.ts +1 -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 +1 -0
- package/dist/team/state.d.ts.map +1 -1
- package/dist/team/state.js +60 -11
- package/dist/team/state.js.map +1 -1
- package/dist/team/worker-bootstrap.js +2 -2
- package/dist/team/worktree.d.ts +1 -0
- package/dist/team/worktree.d.ts.map +1 -1
- package/dist/team/worktree.js +64 -11
- package/dist/team/worktree.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/dist/team/runtime.js
CHANGED
|
@@ -11,7 +11,7 @@ import { reconcileScaleDownCleanupDebt } from './scaling.js';
|
|
|
11
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';
|
|
12
12
|
import { discardTeamNoticesForTeam } from './notice-ledger.js';
|
|
13
13
|
import { commitTeamMembershipTaskTransaction, teamContinuationRequiredDiagnostic, writeTeamManifestV2 as writeTeamManifestV2State, } from './state.js';
|
|
14
|
-
import {
|
|
14
|
+
import { queueInboxNotification, queueDirectMailboxMessage, queueBroadcastMailboxMessage, waitForDispatchReceipt, } from './mcp-comm.js';
|
|
15
15
|
import { appendTeamDeliveryLogForCwd } from './delivery-log.js';
|
|
16
16
|
import { remapRepoAwareDecompositionMetadataToCreatedTasks, } from './repo-aware-decomposition.js';
|
|
17
17
|
import { generateWorkerOverlay, writeTeamWorkerInstructionsFile, removeTeamWorkerInstructionsFile, writeWorkerWorktreeRootAgentsFile, removeWorkerWorktreeRootAgentsFile, generateInitialInbox, generateTaskAssignmentInbox, generateShutdownInbox, buildTriggerDirective, buildMailboxTriggerDirective, buildLeaderMailboxTriggerDirective, writeWorkerRoleInstructionsFile, } from './worker-bootstrap.js';
|
|
@@ -37,7 +37,7 @@ import { buildApprovedTeamHandoffSection, buildApprovedTeamExecutionBinding, nor
|
|
|
37
37
|
import { readPersistedTeamUltragoalContext, renderLeaderOwnedUltragoalContextSection, resolveLeaderOwnedUltragoalContextOutcome, writePersistedTeamUltragoalContext, } from './ultragoal-context.js';
|
|
38
38
|
import { appendTeamCommitHygieneEntries, buildTeamCommitHygieneContext, resolveTeamCommitHygieneArtifactCwd, writeTeamCommitHygieneContext, } from './commit-hygiene.js';
|
|
39
39
|
import { classifyRecordedIdentity, defaultProcessInspectionProvider, } from '../hooks/session.js';
|
|
40
|
-
import { assertCleanLeaderWorkspaceForWorkerWorktrees, ensureWorktree, isGitRepository, isWorktreeDirty, planWorktreeTarget, removeWorktreeForce, rollbackProvisionedWorktrees, replaySubmoduleRecovery, } from './worktree.js';
|
|
40
|
+
import { archiveIgnoredCompletionEvidence, assertCleanLeaderWorkspaceForWorkerWorktrees, ensureWorktree, isGitRepository, isWorktreeDirty, planWorktreeTarget, removeWorktreeForce, rollbackProvisionedWorktrees, replaySubmoduleRecovery, } from './worktree.js';
|
|
41
41
|
import { cleanupOmxMcpProcesses, findLaunchSafeCleanupCandidates, } from '../cli/cleanup.js';
|
|
42
42
|
function joinContextSections(...sections) {
|
|
43
43
|
const present = sections.filter((section) => Boolean(section?.trim()));
|
|
@@ -820,23 +820,6 @@ async function emitCanonicalWorkerEvent(cwd, eventName, context) {
|
|
|
820
820
|
// best effort only
|
|
821
821
|
}
|
|
822
822
|
}
|
|
823
|
-
function autoCommitDirtyWorktree(worker) {
|
|
824
|
-
const worktreePath = resolve(worker.worktree_path);
|
|
825
|
-
const repoRoot = resolve(worker.worktree_repo_root);
|
|
826
|
-
const status = runGitCommand(repoRoot, ['status', '--porcelain'], worktreePath);
|
|
827
|
-
if (!status.ok || !status.stdout.trim())
|
|
828
|
-
return { committed: false, commitHash: null };
|
|
829
|
-
const taskId = worker.assigned_tasks[0] || 'unknown';
|
|
830
|
-
const addResult = runGitCommand(repoRoot, ['add', '-A'], worktreePath);
|
|
831
|
-
if (!addResult.ok)
|
|
832
|
-
return { committed: false, commitHash: null };
|
|
833
|
-
const msg = `omx(team): auto-checkpoint ${worker.name} [${taskId}]`;
|
|
834
|
-
const commitResult = runGitCommand(repoRoot, ['commit', '--no-verify', '-m', msg], worktreePath);
|
|
835
|
-
if (!commitResult.ok)
|
|
836
|
-
return { committed: false, commitHash: null };
|
|
837
|
-
const head = runGitCommand(repoRoot, ['rev-parse', 'HEAD'], worktreePath);
|
|
838
|
-
return { committed: true, commitHash: head.ok ? head.stdout : null };
|
|
839
|
-
}
|
|
840
823
|
function appendIntegrationReport(teamName, entry, cwd) {
|
|
841
824
|
const teamStateRoot = resolveCanonicalTeamStateRoot(cwd);
|
|
842
825
|
const reportPath = join(teamStateRoot, 'team', teamName, 'integration-report.md');
|
|
@@ -847,55 +830,94 @@ function appendIntegrationReport(teamName, entry, cwd) {
|
|
|
847
830
|
const line = `- [${timestamp}] ${entry.workerName}: ${entry.operation} on files: ${entry.files.join(', ') || 'unknown'}. ${entry.detail}\n`;
|
|
848
831
|
appendFileSync(reportPath, existsSync(reportPath) ? line : `# Integration Report\n\n${line}`);
|
|
849
832
|
}
|
|
850
|
-
function resolveWorkerMergeRef(branchResult, workerHead) {
|
|
851
|
-
const branchRef = branchResult.ok ? branchResult.stdout.trim() : '';
|
|
852
|
-
if (!branchRef || branchRef === 'HEAD')
|
|
853
|
-
return workerHead;
|
|
854
|
-
return branchRef;
|
|
855
|
-
}
|
|
856
833
|
function leaderContainsCommit(repoRoot, cwd, commit) {
|
|
857
834
|
return runGitCommand(repoRoot, ['merge-base', '--is-ancestor', commit, 'HEAD'], cwd).ok;
|
|
858
835
|
}
|
|
859
|
-
function
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
return
|
|
863
|
-
|
|
836
|
+
function gitOperationError(repoRoot, cwd) {
|
|
837
|
+
const gitDir = runGitCommand(repoRoot, ['rev-parse', '--absolute-git-dir'], cwd);
|
|
838
|
+
if (!gitDir.ok || !gitDir.stdout)
|
|
839
|
+
return new Error(`git_operation_state_unavailable:${cwd}`);
|
|
840
|
+
for (const marker of ['rebase-merge', 'rebase-apply', 'MERGE_HEAD', 'CHERRY_PICK_HEAD', 'REVERT_HEAD', 'sequencer', 'BISECT_START']) {
|
|
841
|
+
if (existsSync(join(gitDir.stdout, marker)))
|
|
842
|
+
return new Error(`git_operation_in_progress:${cwd}:${marker}. Finish or abort it manually before retrying.`);
|
|
843
|
+
}
|
|
844
|
+
return null;
|
|
864
845
|
}
|
|
865
|
-
|
|
866
|
-
const
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
846
|
+
function assertNoActiveGitOperation(repoRoot, cwd) {
|
|
847
|
+
const error = gitOperationError(repoRoot, cwd);
|
|
848
|
+
if (error)
|
|
849
|
+
throw error;
|
|
850
|
+
}
|
|
851
|
+
function assertShutdownGitOperationsIdle(config, cwd) {
|
|
852
|
+
if (config.workers.some((worker) => worker.worktree_repo_root && worker.worktree_path) && isGitRepository(cwd)) {
|
|
853
|
+
assertNoActiveGitOperation(cwd, cwd);
|
|
854
|
+
}
|
|
873
855
|
for (const worker of config.workers) {
|
|
874
856
|
if (!worker.worktree_repo_root || !worker.worktree_path || !existsSync(worker.worktree_path))
|
|
875
857
|
continue;
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
858
|
+
assertNoActiveGitOperation(worker.worktree_repo_root, worker.worktree_path);
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
function abortOwnedIntegration(repoRoot, cwd, operation, sourceCommit) {
|
|
862
|
+
const marker = operation === 'merge' ? 'MERGE_HEAD' : 'CHERRY_PICK_HEAD';
|
|
863
|
+
const head = runGitCommand(repoRoot, ['rev-parse', '--verify', '--quiet', marker], cwd);
|
|
864
|
+
if (head.ok && head.stdout === sourceCommit)
|
|
865
|
+
runGitCommand(repoRoot, [operation, '--abort'], cwd);
|
|
866
|
+
}
|
|
867
|
+
async function readVerifiedWorkerHandoff(teamName, worker, cwd) {
|
|
868
|
+
const status = await readWorkerStatus(teamName, worker.name, cwd);
|
|
869
|
+
if (status.state !== 'idle' && status.state !== 'done')
|
|
870
|
+
return null;
|
|
871
|
+
const tasks = await listTasks(teamName, cwd);
|
|
872
|
+
const taskIds = new Set([
|
|
873
|
+
...worker.assigned_tasks,
|
|
874
|
+
...(status.current_task_id ? [status.current_task_id] : []),
|
|
875
|
+
...tasks.filter((task) => task.owner === worker.name || task.claim?.owner === worker.name).map((task) => task.id),
|
|
876
|
+
]);
|
|
877
|
+
// Historical research is exempt, but cannot authorize publication on its own.
|
|
878
|
+
const associatedTasks = [...taskIds].map((id) => tasks.find((task) => task.id === id));
|
|
879
|
+
if (!associatedTasks.length || !associatedTasks.every((task) => task?.owner === worker.name
|
|
880
|
+
&& task.status === 'completed' && !task.claim))
|
|
881
|
+
return null;
|
|
882
|
+
const workerHead = resolveWorkerHead(resolve(worker.worktree_path));
|
|
883
|
+
return associatedTasks.some((task) => task?.requires_code_change === true
|
|
884
|
+
&& task.verified_head === workerHead && hasStructuredVerificationEvidence(task.result)) ? workerHead : null;
|
|
885
|
+
}
|
|
886
|
+
async function integrateWorkerCommitsIntoLeader(params) {
|
|
887
|
+
const { teamName, previous, cwd } = params;
|
|
888
|
+
const next = { ...(previous?.integrationByWorker ?? {}) };
|
|
889
|
+
const entries = [];
|
|
890
|
+
let finished = false;
|
|
891
|
+
try {
|
|
892
|
+
try {
|
|
893
|
+
const result = await applyWorkerIntegrations(params, next, entries);
|
|
894
|
+
finished = true;
|
|
895
|
+
return result;
|
|
896
|
+
}
|
|
897
|
+
finally {
|
|
898
|
+
if (entries.length > 0)
|
|
899
|
+
await appendTeamCommitHygieneEntries(teamName, entries, resolveTeamCommitHygieneArtifactCwd(params.config, cwd));
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
finally {
|
|
903
|
+
// Commit receipts must survive failures in the rest of monitorTeam; idle polls need no extra write.
|
|
904
|
+
if (!finished || entries.length > 0) {
|
|
905
|
+
await withTeamTaskMembershipBarrier(teamName, cwd, async () => {
|
|
906
|
+
const latest = await readMonitorSnapshot(teamName, cwd) ?? previous ?? {
|
|
907
|
+
taskStatusById: {}, workerAliveByName: {}, workerStateByName: {}, workerTurnCountByName: {},
|
|
908
|
+
workerTaskIdByName: {}, mailboxNotifiedByMessageId: {}, completedEventTaskIds: {},
|
|
909
|
+
};
|
|
910
|
+
await writeMonitorSnapshot(teamName, {
|
|
911
|
+
...latest, integrationByWorker: { ...latest.integrationByWorker, ...next },
|
|
912
|
+
}, cwd);
|
|
896
913
|
});
|
|
897
914
|
}
|
|
898
915
|
}
|
|
916
|
+
}
|
|
917
|
+
async function applyWorkerIntegrations(params, next, commitHygieneEntries) {
|
|
918
|
+
const { teamName, config, cwd } = params;
|
|
919
|
+
const leaderHeadAtCycleStart = resolveLeaderHead(resolve(config.workers[0]?.worktree_repo_root ?? cwd), cwd);
|
|
920
|
+
const integratedWorkerNames = new Set();
|
|
899
921
|
// ── Phase B: Integrate worker commits to leader (hybrid strategy) ──
|
|
900
922
|
for (const worker of config.workers) {
|
|
901
923
|
if (!worker.worktree_repo_root || !worker.worktree_path || !existsSync(worker.worktree_path))
|
|
@@ -903,11 +925,11 @@ async function integrateWorkerCommitsIntoLeader(params) {
|
|
|
903
925
|
const repoRoot = resolve(worker.worktree_repo_root);
|
|
904
926
|
const worktreePath = resolve(worker.worktree_path);
|
|
905
927
|
const previousState = next[worker.name] ?? {};
|
|
906
|
-
|
|
907
|
-
if (
|
|
928
|
+
const blocker = gitOperationError(repoRoot, worktreePath);
|
|
929
|
+
if (blocker) {
|
|
908
930
|
next[worker.name] = {
|
|
909
931
|
...previousState, status: 'rebase_conflict',
|
|
910
|
-
rebase_error:
|
|
932
|
+
rebase_error: blocker.message,
|
|
911
933
|
};
|
|
912
934
|
continue;
|
|
913
935
|
}
|
|
@@ -921,17 +943,24 @@ async function integrateWorkerCommitsIntoLeader(params) {
|
|
|
921
943
|
if (!status.ok || status.stdout.trim()
|
|
922
944
|
|| !previousState.last_integrated_head || resolveWorkerHead(worktreePath) !== previousState.last_integrated_head)
|
|
923
945
|
continue;
|
|
924
|
-
//
|
|
946
|
+
// Redeliver only the clean original source after its recorded delivery disappeared.
|
|
925
947
|
next[worker.name] = {
|
|
926
948
|
...previousState, last_integrated_head: undefined, delivery_leader_commit: undefined,
|
|
927
949
|
pending_rebase_leader_head: undefined, rebase_error: undefined,
|
|
928
950
|
conflict_commit: undefined, conflict_files: undefined, status: 'idle',
|
|
929
951
|
};
|
|
930
952
|
}
|
|
953
|
+
const verifiedHead = await readVerifiedWorkerHandoff(teamName, worker, cwd);
|
|
954
|
+
if (!verifiedHead)
|
|
955
|
+
continue;
|
|
956
|
+
const clean = runGitCommand(resolve(worker.worktree_repo_root), ['status', '--porcelain', '--untracked-files=all', '--ignore-submodules=none'], resolve(worker.worktree_path));
|
|
957
|
+
if (!clean.ok || clean.stdout.trim())
|
|
958
|
+
continue;
|
|
931
959
|
const leaderHead = resolveLeaderHead(repoRoot, cwd);
|
|
932
960
|
const workerHead = resolveWorkerHead(worktreePath);
|
|
933
961
|
const state = { ...next[worker.name], last_leader_head: leaderHead ?? previousState.last_leader_head };
|
|
934
|
-
|
|
962
|
+
next[worker.name] = state;
|
|
963
|
+
if (!workerHead || workerHead !== verifiedHead || !leaderHead) {
|
|
935
964
|
next[worker.name] = state;
|
|
936
965
|
continue;
|
|
937
966
|
}
|
|
@@ -945,6 +974,9 @@ async function integrateWorkerCommitsIntoLeader(params) {
|
|
|
945
974
|
if (alreadyMerged) {
|
|
946
975
|
Object.assign(state, { last_integrated_head: workerHead, delivery_leader_commit: workerHead });
|
|
947
976
|
state.status = 'idle';
|
|
977
|
+
state.rebase_error = undefined;
|
|
978
|
+
state.conflict_commit = undefined;
|
|
979
|
+
state.conflict_files = undefined;
|
|
948
980
|
state.updated_at = new Date().toISOString();
|
|
949
981
|
integratedWorkerNames.add(worker.name);
|
|
950
982
|
next[worker.name] = state;
|
|
@@ -953,9 +985,9 @@ async function integrateWorkerCommitsIntoLeader(params) {
|
|
|
953
985
|
// Determine if worker is cleanly ahead of leader (merge) or diverged (cherry-pick)
|
|
954
986
|
const workerIsAheadOfLeader = runGitCommand(repoRoot, ['merge-base', '--is-ancestor', leaderHead, workerHead], cwd).ok;
|
|
955
987
|
if (workerIsAheadOfLeader) {
|
|
956
|
-
//
|
|
957
|
-
const
|
|
958
|
-
|
|
988
|
+
// Publish the immutable verified commit without choosing sides on conflicts.
|
|
989
|
+
const branchRef = verifiedHead;
|
|
990
|
+
assertNoActiveGitOperation(repoRoot, cwd);
|
|
959
991
|
const merge = runGitCommand(repoRoot, ['merge', '--no-ff', '-m', `omx(team): merge ${worker.name}`, branchRef], cwd);
|
|
960
992
|
if (merge.ok) {
|
|
961
993
|
const newLeaderHead = resolveLeaderHead(repoRoot, cwd) ?? leaderHead;
|
|
@@ -1030,7 +1062,7 @@ async function integrateWorkerCommitsIntoLeader(params) {
|
|
|
1030
1062
|
else {
|
|
1031
1063
|
// Abort without changing either side; leave resolution to the leader.
|
|
1032
1064
|
const conflictFiles = listConflictFiles(repoRoot, cwd);
|
|
1033
|
-
|
|
1065
|
+
abortOwnedIntegration(repoRoot, cwd, 'merge', branchRef);
|
|
1034
1066
|
state.status = 'cherry_pick_conflict';
|
|
1035
1067
|
state.conflict_commit = workerHead;
|
|
1036
1068
|
state.conflict_files = conflictFiles;
|
|
@@ -1075,11 +1107,12 @@ async function integrateWorkerCommitsIntoLeader(params) {
|
|
|
1075
1107
|
worktree_path: worktreePath,
|
|
1076
1108
|
summary: `detected worker commit ${commit.slice(0, 12)}`,
|
|
1077
1109
|
}, cwd);
|
|
1110
|
+
assertNoActiveGitOperation(repoRoot, cwd);
|
|
1078
1111
|
const pick = runGitCommand(repoRoot, ['cherry-pick', '--allow-empty', commit], cwd);
|
|
1079
1112
|
if (!pick.ok) {
|
|
1080
1113
|
// Abort this commit and stop; do not rebase unintegrated changes.
|
|
1081
1114
|
const conflictFiles = listConflictFiles(repoRoot, cwd);
|
|
1082
|
-
|
|
1115
|
+
abortOwnedIntegration(repoRoot, cwd, 'cherry-pick', commit);
|
|
1083
1116
|
state.status = 'cherry_pick_conflict';
|
|
1084
1117
|
state.conflict_commit = commit;
|
|
1085
1118
|
state.conflict_files = conflictFiles;
|
|
@@ -1151,7 +1184,7 @@ async function integrateWorkerCommitsIntoLeader(params) {
|
|
|
1151
1184
|
}
|
|
1152
1185
|
next[worker.name] = state;
|
|
1153
1186
|
}
|
|
1154
|
-
// ── Phase C: Cross-worker rebase (
|
|
1187
|
+
// ── Phase C: Cross-worker rebase (ready workers onto new leader) ──
|
|
1155
1188
|
const newLeaderHead = resolveLeaderHead(resolve(config.workers[0]?.worktree_repo_root ?? cwd), cwd);
|
|
1156
1189
|
if (newLeaderHead) {
|
|
1157
1190
|
for (const worker of config.workers) {
|
|
@@ -1181,10 +1214,9 @@ async function integrateWorkerCommitsIntoLeader(params) {
|
|
|
1181
1214
|
&& leaderContainsCommit(repoRoot, cwd, state.delivery_leader_commit)));
|
|
1182
1215
|
if (!sourceDelivered)
|
|
1183
1216
|
continue;
|
|
1184
|
-
// Only rebase idle/done/failed workers to avoid race conditions
|
|
1185
1217
|
const workerStatus = await readWorkerStatus(teamName, worker.name, cwd);
|
|
1186
|
-
const
|
|
1187
|
-
if (!
|
|
1218
|
+
const verifiedHead = await readVerifiedWorkerHandoff(teamName, worker, cwd);
|
|
1219
|
+
if (!verifiedHead) {
|
|
1188
1220
|
await appendIntegrationEvent(teamName, 'worker_cross_rebase_skipped', worker, {
|
|
1189
1221
|
worker_name: worker.name,
|
|
1190
1222
|
worker_state: workerStatus.state,
|
|
@@ -1194,13 +1226,15 @@ async function integrateWorkerCommitsIntoLeader(params) {
|
|
|
1194
1226
|
}, cwd);
|
|
1195
1227
|
continue;
|
|
1196
1228
|
}
|
|
1197
|
-
|
|
1229
|
+
const blocker = gitOperationError(repoRoot, worktreePath);
|
|
1230
|
+
if (blocker) {
|
|
1198
1231
|
next[worker.name] = {
|
|
1199
1232
|
...state, status: 'rebase_conflict',
|
|
1200
|
-
|
|
1233
|
+
pending_rebase_leader_head: newLeaderHead, rebase_error: blocker.message,
|
|
1201
1234
|
};
|
|
1202
1235
|
continue;
|
|
1203
1236
|
}
|
|
1237
|
+
// Never rebase a dirty or unreadable worktree.
|
|
1204
1238
|
const statusCheck = runGitCommand(repoRoot, ['status', '--porcelain', '--untracked-files=all', '--ignore-submodules=none'], worktreePath);
|
|
1205
1239
|
if (!statusCheck.ok || statusCheck.stdout.trim()) {
|
|
1206
1240
|
await appendIntegrationEvent(teamName, 'worker_cross_rebase_skipped', worker, {
|
|
@@ -1214,6 +1248,8 @@ async function integrateWorkerCommitsIntoLeader(params) {
|
|
|
1214
1248
|
}
|
|
1215
1249
|
// Rebase without silently dropping conflicting worker changes.
|
|
1216
1250
|
const workerHeadBeforeRebase = resolveWorkerHead(worktreePath);
|
|
1251
|
+
if (workerHeadBeforeRebase !== verifiedHead)
|
|
1252
|
+
continue;
|
|
1217
1253
|
const rebase = runGitCommand(repoRoot, ['rebase', newLeaderHead], worktreePath);
|
|
1218
1254
|
if (rebase.ok) {
|
|
1219
1255
|
const workerHeadAfterRebase = resolveWorkerHead(worktreePath);
|
|
@@ -1276,9 +1312,6 @@ async function integrateWorkerCommitsIntoLeader(params) {
|
|
|
1276
1312
|
}
|
|
1277
1313
|
}
|
|
1278
1314
|
}
|
|
1279
|
-
if (commitHygieneEntries.length > 0) {
|
|
1280
|
-
await appendTeamCommitHygieneEntries(teamName, commitHygieneEntries, artifactCwd);
|
|
1281
|
-
}
|
|
1282
1315
|
return next;
|
|
1283
1316
|
}
|
|
1284
1317
|
function renderWorktreeMergeReport(report) {
|
|
@@ -1431,6 +1464,7 @@ async function prepareShutdownMergeReport(worker, leaderCwd) {
|
|
|
1431
1464
|
}
|
|
1432
1465
|
const worktreePath = resolve(worker.worktree_path);
|
|
1433
1466
|
const repoRoot = resolve(worker.worktree_repo_root);
|
|
1467
|
+
assertNoActiveGitOperation(repoRoot, worktreePath);
|
|
1434
1468
|
await removeGeneratedShutdownReport(repoRoot, worktreePath);
|
|
1435
1469
|
// Replay any pending submodule recovery journals before any git operations.
|
|
1436
1470
|
// If the process was killed after moving submodules but before creating placeholders,
|
|
@@ -1506,6 +1540,7 @@ async function prepareShutdownMergeReport(worker, leaderCwd) {
|
|
|
1506
1540
|
mergeDetail = 'source already reachable from leader HEAD';
|
|
1507
1541
|
}
|
|
1508
1542
|
else {
|
|
1543
|
+
assertNoActiveGitOperation(repoRoot, leaderCwd);
|
|
1509
1544
|
const mergeResult = runGitCommand(repoRoot, ['merge', '--no-ff', '--no-edit', sourceRef], leaderCwd);
|
|
1510
1545
|
if (mergeResult.ok) {
|
|
1511
1546
|
mergeOutcome = 'merged';
|
|
@@ -1515,7 +1550,7 @@ async function prepareShutdownMergeReport(worker, leaderCwd) {
|
|
|
1515
1550
|
else {
|
|
1516
1551
|
mergeOutcome = 'conflict';
|
|
1517
1552
|
mergeDetail = mergeResult.stderr || mergeResult.stdout || 'merge failed';
|
|
1518
|
-
|
|
1553
|
+
abortOwnedIntegration(repoRoot, leaderCwd, 'merge', sourceRef);
|
|
1519
1554
|
leaderHeadAfter = resolveLeaderHead(repoRoot, leaderCwd) ?? leaderHeadBefore;
|
|
1520
1555
|
}
|
|
1521
1556
|
}
|
|
@@ -2935,6 +2970,36 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
2935
2970
|
return currentOwner.status === 'value' && currentOwner.value === expectedOwnerId;
|
|
2936
2971
|
};
|
|
2937
2972
|
let config = null;
|
|
2973
|
+
// Only transport/debt fields belong to startup after workers can execute.
|
|
2974
|
+
const persistStartupTransport = async () => {
|
|
2975
|
+
const startup = config;
|
|
2976
|
+
if (!startup)
|
|
2977
|
+
throw new Error(`team_config_missing:${sanitized}`);
|
|
2978
|
+
config = await withTeamTaskMembershipBarrier(sanitized, leaderCwd, async () => {
|
|
2979
|
+
const current = await readTeamConfig(sanitized, leaderCwd);
|
|
2980
|
+
if (!current)
|
|
2981
|
+
throw new Error(`team_config_missing:${sanitized}`);
|
|
2982
|
+
current.tmux_session = startup.tmux_session;
|
|
2983
|
+
current.tmux_session_id = startup.tmux_session_id;
|
|
2984
|
+
current.tmux_session_created = startup.tmux_session_created;
|
|
2985
|
+
current.tmux_pane_owner_id = startup.tmux_pane_owner_id;
|
|
2986
|
+
current.leader_pane_id = startup.leader_pane_id;
|
|
2987
|
+
current.leader_pane_pid = startup.leader_pane_pid;
|
|
2988
|
+
current.hud_pane_id = startup.hud_pane_id;
|
|
2989
|
+
current.hud_pane_pid = startup.hud_pane_pid;
|
|
2990
|
+
current.resize_hook_name = startup.resize_hook_name;
|
|
2991
|
+
current.resize_hook_target = startup.resize_hook_target;
|
|
2992
|
+
current.startup_cleanup_panes = startup.startup_cleanup_panes;
|
|
2993
|
+
current.workers = current.workers.flatMap((worker) => {
|
|
2994
|
+
const transport = startup.workers.find((candidate) => candidate.name === worker.name);
|
|
2995
|
+
return transport ? [{ ...worker, pane_id: transport.pane_id, pid: transport.pid }]
|
|
2996
|
+
: worker.index <= workerCount ? [] : [worker];
|
|
2997
|
+
});
|
|
2998
|
+
current.worker_count = current.workers.length;
|
|
2999
|
+
await saveTeamConfig(current, leaderCwd);
|
|
3000
|
+
return current;
|
|
3001
|
+
});
|
|
3002
|
+
};
|
|
2938
3003
|
const workerPaneIds = Array.from({ length: workerCount }, () => undefined);
|
|
2939
3004
|
const workerReadyTimeoutMs = resolveWorkerReadyTimeoutMs(launchEnv);
|
|
2940
3005
|
const workerStartupEvidenceTimeoutMs = resolveWorkerStartupEvidenceTimeoutMs(launchEnv, workerReadyTimeoutMs);
|
|
@@ -3138,14 +3203,14 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3138
3203
|
workerRole: plan.workerRole,
|
|
3139
3204
|
};
|
|
3140
3205
|
});
|
|
3141
|
-
const
|
|
3206
|
+
const materializeWorkerStartupIdentity = async (bootstrapPlan, workerIndex, paneId) => {
|
|
3142
3207
|
const workerWorkspace = bootstrapPlan.workerWorkspace;
|
|
3143
3208
|
const identity = {
|
|
3144
3209
|
name: bootstrapPlan.workerName,
|
|
3145
3210
|
index: workerIndex,
|
|
3146
3211
|
role: bootstrapPlan.workerRole,
|
|
3147
3212
|
worker_cli: bootstrapPlan.workerCli,
|
|
3148
|
-
assigned_tasks:
|
|
3213
|
+
assigned_tasks: config?.workers[workerIndex - 1]?.assigned_tasks ?? [],
|
|
3149
3214
|
working_dir: workerWorkspace.cwd,
|
|
3150
3215
|
worktree_repo_root: workerWorkspace.worktreeRepoRoot,
|
|
3151
3216
|
worktree_path: workerWorkspace.worktreePath,
|
|
@@ -3175,7 +3240,6 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3175
3240
|
config.workers[workerIndex - 1].pane_id = paneId;
|
|
3176
3241
|
config.workers[workerIndex - 1].role = bootstrapPlan.workerRole;
|
|
3177
3242
|
config.workers[workerIndex - 1].worker_cli = bootstrapPlan.workerCli;
|
|
3178
|
-
config.workers[workerIndex - 1].assigned_tasks = bootstrapPlan.workerTasks.map((task) => task.id);
|
|
3179
3243
|
config.workers[workerIndex - 1].working_dir = workerWorkspace.cwd;
|
|
3180
3244
|
config.workers[workerIndex - 1].worktree_repo_root = workerWorkspace.worktreeRepoRoot;
|
|
3181
3245
|
config.workers[workerIndex - 1].worktree_path = workerWorkspace.worktreePath;
|
|
@@ -3185,7 +3249,6 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3185
3249
|
config.workers[workerIndex - 1].team_state_root = teamStateRoot;
|
|
3186
3250
|
}
|
|
3187
3251
|
await writeWorkerIdentity(sanitized, bootstrapPlan.workerName, identity, leaderCwd);
|
|
3188
|
-
await writeWorkerInbox(sanitized, bootstrapPlan.workerName, bootstrapPlan.inbox, leaderCwd);
|
|
3189
3252
|
};
|
|
3190
3253
|
// 6. Create worker runtime (interactive tmux panes or prompt-mode child processes)
|
|
3191
3254
|
await writeTeamPreflightContextPacket({
|
|
@@ -3204,9 +3267,27 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3204
3267
|
writeWarning: options.writeCleanupWarning,
|
|
3205
3268
|
});
|
|
3206
3269
|
const startupTiming = createStartupTimingRecorder(sanitized, leaderCwd);
|
|
3207
|
-
//
|
|
3208
|
-
|
|
3270
|
+
// For herdr mode, all workers are ready after createHerdrTeam returns.
|
|
3271
|
+
// For interactive/prompt modes, readiness is determined per-worker.
|
|
3272
|
+
let herdrTeamReady = false;
|
|
3209
3273
|
let workerStartupArgs;
|
|
3274
|
+
// Initial prompts can execute during pane/process creation, before it returns.
|
|
3275
|
+
config = await withTeamTaskMembershipBarrier(sanitized, leaderCwd, async () => {
|
|
3276
|
+
const current = await readTeamConfig(sanitized, leaderCwd);
|
|
3277
|
+
if (!current)
|
|
3278
|
+
throw new Error(`team_config_missing:${sanitized}`);
|
|
3279
|
+
config = current;
|
|
3280
|
+
const startupTasks = await listTasks(sanitized, leaderCwd);
|
|
3281
|
+
for (let i = 1; i <= workerCount; i++) {
|
|
3282
|
+
const plan = workerBootstrapPlans[i - 1];
|
|
3283
|
+
current.workers[i - 1].assigned_tasks = startupTasks
|
|
3284
|
+
.filter((task) => task.owner === plan.workerName).map((task) => task.id);
|
|
3285
|
+
await materializeWorkerStartupIdentity(plan, i, undefined);
|
|
3286
|
+
await writeWorkerInbox(sanitized, plan.workerName, plan.inbox, leaderCwd);
|
|
3287
|
+
}
|
|
3288
|
+
await saveTeamConfig(current, leaderCwd);
|
|
3289
|
+
return current;
|
|
3290
|
+
});
|
|
3210
3291
|
if (workerLaunchMode === 'interactive') {
|
|
3211
3292
|
const createdSession = createTeamSession(sanitized, workerCount, leaderCwd, Array.from(workerLaunchPolicyPlan[0]?.workerLaunchArgs ?? []), workerStartups, { ownerSessionId: leaderSessionId, teamPaneOwnerId: config.tmux_pane_owner_id });
|
|
3212
3293
|
sessionName = createdSession.name;
|
|
@@ -3254,7 +3335,7 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3254
3335
|
// createHerdrTeam returns only after every agent reached an idle,
|
|
3255
3336
|
// promptable state (agent-start readiness + settle polling): that is
|
|
3256
3337
|
// the herdr equivalent of observing a ready prompt in a tmux pane.
|
|
3257
|
-
|
|
3338
|
+
herdrTeamReady = true;
|
|
3258
3339
|
sessionName = herdrTeam.name;
|
|
3259
3340
|
sessionCreated = true;
|
|
3260
3341
|
config.tmux_session = herdrTeam.name;
|
|
@@ -3294,17 +3375,16 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3294
3375
|
}
|
|
3295
3376
|
}
|
|
3296
3377
|
}
|
|
3297
|
-
|
|
3298
|
-
//
|
|
3378
|
+
await persistStartupTransport();
|
|
3379
|
+
// Refresh transport identities only; a running worker may already have a follow-up inbox.
|
|
3299
3380
|
for (let i = 1; i <= workerCount; i++) {
|
|
3300
3381
|
const bootstrapPlan = workerBootstrapPlans[i - 1];
|
|
3301
3382
|
if (!bootstrapPlan) {
|
|
3302
3383
|
throw new Error(`missing bootstrap plan for worker-${i}`);
|
|
3303
3384
|
}
|
|
3304
|
-
await
|
|
3305
|
-
startupTiming.mark('
|
|
3385
|
+
await materializeWorkerStartupIdentity(bootstrapPlan, i, workerPaneIds[i - 1]);
|
|
3386
|
+
startupTiming.mark('identity_written', { worker: bootstrapPlan.workerName, pane_id: workerPaneIds[i - 1] });
|
|
3306
3387
|
}
|
|
3307
|
-
await saveTeamConfig(config, leaderCwd);
|
|
3308
3388
|
// 7. Start all safe per-worker readiness/dispatch attempts concurrently.
|
|
3309
3389
|
// Pane creation and worktree provisioning above remain dependency-bound and
|
|
3310
3390
|
// ordered; readiness polling and startup dispatch must not let worker-1
|
|
@@ -3321,10 +3401,11 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3321
3401
|
error: new Error(`missing bootstrap plan for worker-${workerIndex}`),
|
|
3322
3402
|
};
|
|
3323
3403
|
}
|
|
3404
|
+
// Each worker has its own readiness state; don't leak evidence from other workers.
|
|
3405
|
+
let startupReadyPromptObserved = herdrTeamReady || workerLaunchMode === 'herdr';
|
|
3324
3406
|
const workerName = bootstrapPlan.workerName;
|
|
3325
3407
|
const paneId = workerPaneIds[workerIndex - 1];
|
|
3326
3408
|
const workerTasks = bootstrapPlan.workerTasks;
|
|
3327
|
-
const inbox = bootstrapPlan.inbox;
|
|
3328
3409
|
const trigger = bootstrapPlan.trigger;
|
|
3329
3410
|
const triggerIntent = bootstrapPlan.triggerIntent;
|
|
3330
3411
|
const initialPrompt = bootstrapPlan.initialPrompt;
|
|
@@ -3342,7 +3423,6 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3342
3423
|
paneId,
|
|
3343
3424
|
workerCli: bootstrapPlan.workerCli,
|
|
3344
3425
|
finalArgs: workerStartupArgs?.[workerIndex - 1],
|
|
3345
|
-
inbox,
|
|
3346
3426
|
triggerMessage: trigger,
|
|
3347
3427
|
intent: triggerIntent,
|
|
3348
3428
|
taskIds: workerTasks.map((task) => task.id),
|
|
@@ -3425,7 +3505,6 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3425
3505
|
workerIndex,
|
|
3426
3506
|
paneId,
|
|
3427
3507
|
workerCli: bootstrapPlan.workerCli,
|
|
3428
|
-
inbox,
|
|
3429
3508
|
triggerMessage: trigger,
|
|
3430
3509
|
intent: triggerIntent,
|
|
3431
3510
|
cwd: leaderCwd,
|
|
@@ -3503,7 +3582,10 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3503
3582
|
if (firstStartupError) {
|
|
3504
3583
|
throw firstStartupError.error;
|
|
3505
3584
|
}
|
|
3506
|
-
|
|
3585
|
+
// Startup attempts only read config; workers may have changed canonical task assignments meanwhile.
|
|
3586
|
+
config = await readTeamConfig(sanitized, leaderCwd);
|
|
3587
|
+
if (!config)
|
|
3588
|
+
throw new Error(`team_config_missing:${sanitized}`);
|
|
3507
3589
|
await startupTiming.flush();
|
|
3508
3590
|
return {
|
|
3509
3591
|
teamName: sanitized,
|
|
@@ -3523,7 +3605,7 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3523
3605
|
createdWorkerPaneIds.push(...partialSession.workerPaneIds);
|
|
3524
3606
|
createdLeaderPaneId = partialSession.leaderPaneId;
|
|
3525
3607
|
applyCreatedInteractiveSessionToConfig(config, partialSession, workerPaneIds);
|
|
3526
|
-
await
|
|
3608
|
+
await persistStartupTransport();
|
|
3527
3609
|
const cleanupDebt = [
|
|
3528
3610
|
...error.cleanupErrors,
|
|
3529
3611
|
...error.proofUnavailable.map((proof) => `pane_proof_unavailable:${proof.paneId}:${proof.reason}`),
|
|
@@ -3554,7 +3636,7 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3554
3636
|
: [];
|
|
3555
3637
|
});
|
|
3556
3638
|
if (startupCleanupDebt.length > 0) {
|
|
3557
|
-
await
|
|
3639
|
+
await persistStartupTransport();
|
|
3558
3640
|
await appendTeamEvent(sanitized, {
|
|
3559
3641
|
type: 'team_leader_nudge',
|
|
3560
3642
|
worker: 'leader-fixed',
|
|
@@ -3600,7 +3682,7 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3600
3682
|
}
|
|
3601
3683
|
if (paneProcessProofUnavailable.length > 0) {
|
|
3602
3684
|
if (config)
|
|
3603
|
-
await
|
|
3685
|
+
await persistStartupTransport();
|
|
3604
3686
|
assertPaneTeardownProofsAvailable('startup_rollback', paneProcessProofUnavailable);
|
|
3605
3687
|
}
|
|
3606
3688
|
const rollbackPanePids = Object.fromEntries((config?.workers ?? [])
|
|
@@ -3633,7 +3715,7 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3633
3715
|
if (rollbackPaneTeardown.proofUnavailable.length > 0) {
|
|
3634
3716
|
if (config) {
|
|
3635
3717
|
try {
|
|
3636
|
-
await
|
|
3718
|
+
await persistStartupTransport();
|
|
3637
3719
|
}
|
|
3638
3720
|
catch (cleanupError) {
|
|
3639
3721
|
rollbackErrors.push(`saveTeamConfig(preserve rollback state): ${String(cleanupError)}`);
|
|
@@ -3643,7 +3725,7 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3643
3725
|
}
|
|
3644
3726
|
if (rollbackPaneTeardown.kill.failed > 0) {
|
|
3645
3727
|
if (config)
|
|
3646
|
-
await
|
|
3728
|
+
await persistStartupTransport();
|
|
3647
3729
|
const originalMessage = error instanceof Error ? error.message : String(error);
|
|
3648
3730
|
throw new Error(`${originalMessage}; rollback encountered errors: paneTeardown:${rollbackPaneTeardown.kill.failedPaneIds.join(',')}`);
|
|
3649
3731
|
}
|
|
@@ -3903,9 +3985,9 @@ export async function monitorTeam(teamName, cwd, options = {}) {
|
|
|
3903
3985
|
recommendations.push(`Integration unresolved for ${worker.name}; resolve delivery failure before terminal success`);
|
|
3904
3986
|
continue;
|
|
3905
3987
|
}
|
|
3906
|
-
if (
|
|
3988
|
+
if (gitOperationError(worker.worktree_repo_root, worker.worktree_path)) {
|
|
3907
3989
|
integrationFailed = true;
|
|
3908
|
-
recommendations.push(`Integration unresolved for ${worker.name}; unfinished
|
|
3990
|
+
recommendations.push(`Integration unresolved for ${worker.name}; unfinished Git operation or unavailable state preserved before terminal success`);
|
|
3909
3991
|
continue;
|
|
3910
3992
|
}
|
|
3911
3993
|
const workerHead = resolveWorkerHead(worker.worktree_path);
|
|
@@ -3974,23 +4056,26 @@ export async function monitorTeam(teamName, cwd, options = {}) {
|
|
|
3974
4056
|
const updatedAt = new Date().toISOString();
|
|
3975
4057
|
const totalMs = performance.now() - monitorStartMs;
|
|
3976
4058
|
if (!readOnly)
|
|
3977
|
-
await
|
|
3978
|
-
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
4059
|
+
await withTeamTaskMembershipBarrier(sanitized, cwd, async () => {
|
|
4060
|
+
const latest = await readMonitorSnapshot(sanitized, cwd);
|
|
4061
|
+
await writeMonitorSnapshot(sanitized, {
|
|
4062
|
+
taskStatusById: Object.fromEntries(taskView.map((t) => [t.id, t.status])),
|
|
4063
|
+
workerAliveByName: Object.fromEntries(workers.map((w) => [w.name, w.alive])),
|
|
4064
|
+
workerStateByName: Object.fromEntries(workers.map((w) => [w.name, w.status.state])),
|
|
4065
|
+
workerTurnCountByName: Object.fromEntries(workers.map((w) => [w.name, w.heartbeat?.turn_count ?? 0])),
|
|
4066
|
+
workerTaskIdByName: Object.fromEntries(workers.map((w) => [w.name, w.status.current_task_id ?? ''])),
|
|
4067
|
+
mailboxNotifiedByMessageId,
|
|
4068
|
+
completedEventTaskIds: { ...previousSnapshot?.completedEventTaskIds, ...latest?.completedEventTaskIds },
|
|
4069
|
+
integrationByWorker,
|
|
4070
|
+
monitorTimings: {
|
|
4071
|
+
list_tasks_ms: Number(listTasksMs.toFixed(2)),
|
|
4072
|
+
worker_scan_ms: Number(workerScanMs.toFixed(2)),
|
|
4073
|
+
mailbox_delivery_ms: Number(mailboxDeliveryMs.toFixed(2)),
|
|
4074
|
+
total_ms: Number(totalMs.toFixed(2)),
|
|
4075
|
+
updated_at: updatedAt,
|
|
4076
|
+
},
|
|
4077
|
+
}, cwd);
|
|
4078
|
+
});
|
|
3994
4079
|
return {
|
|
3995
4080
|
teamName: sanitized,
|
|
3996
4081
|
phase,
|
|
@@ -4079,13 +4164,13 @@ export async function assignTask(teamName, workerName, taskId, cwd) {
|
|
|
4079
4164
|
let outcome = { ok: false, transport: 'none', reason: 'not_attempted' };
|
|
4080
4165
|
const triggerDirective = buildTriggerDirective(workerName, sanitized, resolveInstructionStateRoot(workerInfo.worktree_path));
|
|
4081
4166
|
for (let attempt = 1; attempt <= maxAssignRetries; attempt++) {
|
|
4167
|
+
await writeWorkerInbox(sanitized, workerName, inbox, cwd);
|
|
4082
4168
|
outcome = await dispatchCriticalInboxInstruction({
|
|
4083
4169
|
teamName: sanitized,
|
|
4084
4170
|
config,
|
|
4085
4171
|
workerName,
|
|
4086
4172
|
workerIndex: workerInfo.index,
|
|
4087
4173
|
paneId: workerInfo.pane_id,
|
|
4088
|
-
inbox,
|
|
4089
4174
|
triggerMessage: triggerDirective.text,
|
|
4090
4175
|
intent: triggerDirective.intent,
|
|
4091
4176
|
cwd,
|
|
@@ -4225,6 +4310,8 @@ export async function shutdownTeam(teamName, cwd, options = {}) {
|
|
|
4225
4310
|
: '';
|
|
4226
4311
|
const governance = resolveGovernancePolicy(manifest?.governance, manifest?.policy);
|
|
4227
4312
|
const classification = await withTeamTaskMembershipBarrier(sanitized, cwd, async () => {
|
|
4313
|
+
if (!force)
|
|
4314
|
+
assertShutdownGitOperationsIdle(config, cwd);
|
|
4228
4315
|
const current = await classifyShutdown({
|
|
4229
4316
|
teamName: sanitized,
|
|
4230
4317
|
cwd,
|
|
@@ -4305,13 +4392,13 @@ export async function shutdownTeam(teamName, cwd, options = {}) {
|
|
|
4305
4392
|
await writeShutdownRequest(sanitized, w.name, 'leader-fixed', cwd);
|
|
4306
4393
|
shutdownRequestTimes.set(w.name, requestedAt);
|
|
4307
4394
|
const triggerDirective = buildTriggerDirective(w.name, sanitized, resolveInstructionStateRoot(w.worktree_path));
|
|
4395
|
+
await writeWorkerInbox(sanitized, w.name, generateShutdownInbox(sanitized, w.name), cwd);
|
|
4308
4396
|
await dispatchCriticalInboxInstruction({
|
|
4309
4397
|
teamName: sanitized,
|
|
4310
4398
|
config,
|
|
4311
4399
|
workerName: w.name,
|
|
4312
4400
|
workerIndex: w.index,
|
|
4313
4401
|
paneId: w.pane_id,
|
|
4314
|
-
inbox: generateShutdownInbox(sanitized, w.name),
|
|
4315
4402
|
triggerMessage: triggerDirective.text,
|
|
4316
4403
|
intent: triggerDirective.intent,
|
|
4317
4404
|
cwd,
|
|
@@ -4756,7 +4843,10 @@ export async function shutdownTeam(teamName, cwd, options = {}) {
|
|
|
4756
4843
|
}
|
|
4757
4844
|
}
|
|
4758
4845
|
if (herdrTeardownFailures.length > 0 && !herdrWorkspaceClosed) {
|
|
4759
|
-
|
|
4846
|
+
throw new Error(`shutdown_herdr_teardown_failed:${herdrTeardownFailures.join(',')}`);
|
|
4847
|
+
}
|
|
4848
|
+
if (herdrTeardownFailures.length > 0 && herdrWorkspaceClosed) {
|
|
4849
|
+
console.warn(`[team shutdown] ${sanitized}: herdr pane teardown issues: ${herdrTeardownFailures.join(',')}`);
|
|
4760
4850
|
}
|
|
4761
4851
|
}
|
|
4762
4852
|
else if (config.worker_launch_mode === 'prompt') {
|
|
@@ -4783,6 +4873,7 @@ export async function shutdownTeam(teamName, cwd, options = {}) {
|
|
|
4783
4873
|
throw new Error(`shutdown_prompt_teardown_failed:${promptTeardownFailures.join(',')}`);
|
|
4784
4874
|
}
|
|
4785
4875
|
}
|
|
4876
|
+
assertShutdownGitOperationsIdle(config, cwd);
|
|
4786
4877
|
const shutdownReports = await prepareWorkerWorktreeShutdownReports(config, cwd);
|
|
4787
4878
|
const provisionedWorktrees = collectProvisionedShutdownWorktrees(config);
|
|
4788
4879
|
const commitHygieneEntries = [];
|
|
@@ -4820,7 +4911,7 @@ export async function shutdownTeam(teamName, cwd, options = {}) {
|
|
|
4820
4911
|
}
|
|
4821
4912
|
}
|
|
4822
4913
|
const artifactCwd = resolveTeamCommitHygieneArtifactCwd(config, cwd);
|
|
4823
|
-
const taskView = await listTasks(sanitized, cwd)
|
|
4914
|
+
const taskView = await listTasks(sanitized, cwd);
|
|
4824
4915
|
const internalLedger = await appendTeamCommitHygieneEntries(sanitized, commitHygieneEntries, artifactCwd);
|
|
4825
4916
|
const commitHygieneArtifactTeamNames = resolveCommitHygieneArtifactTeamNames(config, sanitized);
|
|
4826
4917
|
let commitHygieneArtifacts = null;
|
|
@@ -4866,12 +4957,14 @@ export async function shutdownTeam(teamName, cwd, options = {}) {
|
|
|
4866
4957
|
const head = runGitCommand(worktree.repoRoot, ['rev-parse', 'HEAD'], worktree.worktreePath);
|
|
4867
4958
|
const saved = head.ok && runGitCommand(worktree.repoRoot, ['merge-base', '--is-ancestor', head.stdout, 'HEAD'], cwd).ok;
|
|
4868
4959
|
await removeGeneratedShutdownReport(worktree.repoRoot, worktree.worktreePath);
|
|
4960
|
+
await archiveIgnoredCompletionEvidence(worktree.worktreePath);
|
|
4869
4961
|
const status = runGitCommand(worktree.repoRoot, ['status', '--porcelain', '--untracked-files=all', '--ignored', '--ignore-submodules=none'], worktree.worktreePath);
|
|
4870
4962
|
if (!saved || !status.ok || status.stdout) {
|
|
4871
4963
|
throw new Error(`shutdown_worktree_preservation_failed:${worktree.worktreePath}:worktree changed or could not be verified; worktree and team state retained`);
|
|
4872
4964
|
}
|
|
4873
4965
|
}
|
|
4874
4966
|
if (provisionedWorktrees.length > 0) {
|
|
4967
|
+
assertShutdownGitOperationsIdle(config, cwd);
|
|
4875
4968
|
// Keep recovery state if removal itself fails, including after a partial cleanup.
|
|
4876
4969
|
await rollbackProvisionedWorktrees(provisionedWorktrees, {
|
|
4877
4970
|
force: false,
|
|
@@ -5127,21 +5220,30 @@ async function isTaskApprovedForExecution(teamName, taskId, cwd) {
|
|
|
5127
5220
|
return record?.status === 'approved';
|
|
5128
5221
|
}
|
|
5129
5222
|
async function emitMonitorDerivedEvents(teamName, tasks, workers, previous, workerLaunchMode, cwd) {
|
|
5130
|
-
|
|
5131
|
-
const
|
|
5132
|
-
|
|
5133
|
-
|
|
5134
|
-
|
|
5135
|
-
|
|
5136
|
-
|
|
5137
|
-
|
|
5138
|
-
|
|
5139
|
-
|
|
5140
|
-
|
|
5141
|
-
|
|
5142
|
-
|
|
5223
|
+
await withTeamTaskMembershipBarrier(teamName, cwd, async () => {
|
|
5224
|
+
const latest = await readMonitorSnapshot(teamName, cwd) ?? previous;
|
|
5225
|
+
const completedEventTaskIds = { ...previous?.completedEventTaskIds, ...latest?.completedEventTaskIds };
|
|
5226
|
+
let changed = false;
|
|
5227
|
+
for (const task of tasks) {
|
|
5228
|
+
const prevStatus = previous?.taskStatusById[task.id];
|
|
5229
|
+
if (prevStatus && prevStatus !== 'completed' && task.status === 'completed') {
|
|
5230
|
+
// Skip if a task_completed event was already emitted by transitionTaskStatus (issue #161).
|
|
5231
|
+
if (completedEventTaskIds[task.id])
|
|
5232
|
+
continue;
|
|
5233
|
+
await appendTeamEvent(teamName, {
|
|
5234
|
+
type: 'task_completed',
|
|
5235
|
+
worker: task.owner || 'unknown',
|
|
5236
|
+
task_id: task.id,
|
|
5237
|
+
message_id: null,
|
|
5238
|
+
reason: undefined,
|
|
5239
|
+
}, cwd);
|
|
5240
|
+
completedEventTaskIds[task.id] = true;
|
|
5241
|
+
changed = true;
|
|
5242
|
+
}
|
|
5143
5243
|
}
|
|
5144
|
-
|
|
5244
|
+
if (changed && latest)
|
|
5245
|
+
await writeMonitorSnapshot(teamName, { ...latest, completedEventTaskIds }, cwd);
|
|
5246
|
+
});
|
|
5145
5247
|
for (const worker of workers) {
|
|
5146
5248
|
const prevAlive = previous?.workerAliveByName[worker.name];
|
|
5147
5249
|
const shouldEmitInitialPromptWorkerStop = workerLaunchMode === 'prompt' && prevAlive === undefined;
|
|
@@ -5284,7 +5386,7 @@ async function markDispatchRequestLeaderPaneMissingDeferred(params) {
|
|
|
5284
5386
|
}, cwd).catch(() => { });
|
|
5285
5387
|
}
|
|
5286
5388
|
async function attemptStartupDirectTrigger(params) {
|
|
5287
|
-
const { teamName, config, workerName, workerIndex, paneId, workerCli, finalArgs,
|
|
5389
|
+
const { teamName, config, workerName, workerIndex, paneId, workerCli, finalArgs, triggerMessage, intent, taskIds, cwd, timing, } = params;
|
|
5288
5390
|
const safety = await evaluateStartupDirectTriggerSafety(config.tmux_session, workerIndex, paneId, workerCli, finalArgs);
|
|
5289
5391
|
if (!safety.safe) {
|
|
5290
5392
|
timing.mark('startup_direct_bypass', {
|
|
@@ -5298,12 +5400,11 @@ async function attemptStartupDirectTrigger(params) {
|
|
|
5298
5400
|
}
|
|
5299
5401
|
return null;
|
|
5300
5402
|
}
|
|
5301
|
-
const queued = await
|
|
5403
|
+
const queued = await queueInboxNotification({
|
|
5302
5404
|
teamName,
|
|
5303
5405
|
workerName,
|
|
5304
5406
|
workerIndex,
|
|
5305
5407
|
paneId,
|
|
5306
|
-
inbox,
|
|
5307
5408
|
triggerMessage,
|
|
5308
5409
|
intent,
|
|
5309
5410
|
cwd,
|
|
@@ -5370,17 +5471,16 @@ async function attemptStartupDirectTrigger(params) {
|
|
|
5370
5471
|
};
|
|
5371
5472
|
}
|
|
5372
5473
|
async function dispatchCriticalInboxInstruction(params) {
|
|
5373
|
-
const { teamName, config, workerName, workerIndex, paneId, workerCli,
|
|
5474
|
+
const { teamName, config, workerName, workerIndex, paneId, workerCli, triggerMessage, intent, cwd, dispatchPolicy, inboxCorrelationKey, requireWorkerStartupEvidence, startupEvidenceTimeoutMs, startupReadyPromptObserved = false, startupTiming, } = params;
|
|
5374
5475
|
const noteTiming = (phase, details) => {
|
|
5375
5476
|
startupTiming?.mark(phase, { worker: workerName, pane_id: paneId, ...details });
|
|
5376
5477
|
};
|
|
5377
5478
|
if (config.worker_launch_mode === 'prompt') {
|
|
5378
|
-
return await
|
|
5479
|
+
return await queueInboxNotification({
|
|
5379
5480
|
teamName,
|
|
5380
5481
|
workerName,
|
|
5381
5482
|
workerIndex,
|
|
5382
5483
|
paneId,
|
|
5383
|
-
inbox,
|
|
5384
5484
|
triggerMessage,
|
|
5385
5485
|
intent,
|
|
5386
5486
|
cwd,
|
|
@@ -5391,12 +5491,11 @@ async function dispatchCriticalInboxInstruction(params) {
|
|
|
5391
5491
|
});
|
|
5392
5492
|
}
|
|
5393
5493
|
if (dispatchPolicy.dispatch_mode === 'transport_direct') {
|
|
5394
|
-
return await
|
|
5494
|
+
return await queueInboxNotification({
|
|
5395
5495
|
teamName,
|
|
5396
5496
|
workerName,
|
|
5397
5497
|
workerIndex,
|
|
5398
5498
|
paneId,
|
|
5399
|
-
inbox,
|
|
5400
5499
|
triggerMessage,
|
|
5401
5500
|
intent,
|
|
5402
5501
|
cwd,
|
|
@@ -5406,12 +5505,11 @@ async function dispatchCriticalInboxInstruction(params) {
|
|
|
5406
5505
|
notify: (_target, message) => notifyWorkerOutcome(config, workerIndex, message, paneId),
|
|
5407
5506
|
});
|
|
5408
5507
|
}
|
|
5409
|
-
const queued = await
|
|
5508
|
+
const queued = await queueInboxNotification({
|
|
5410
5509
|
teamName,
|
|
5411
5510
|
workerName,
|
|
5412
5511
|
workerIndex,
|
|
5413
5512
|
paneId,
|
|
5414
|
-
inbox,
|
|
5415
5513
|
triggerMessage,
|
|
5416
5514
|
intent,
|
|
5417
5515
|
cwd,
|