oh-my-codex 0.22.0 → 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/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__/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 +121 -2
- package/dist/team/__tests__/state.test.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/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 +116 -94
- 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 +71 -66
- 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 +8 -5
- 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 +44 -0
- package/dist/team/state.js.map +1 -1
- package/dist/team/worker-bootstrap.js +2 -2
- 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';
|
|
@@ -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,12 +830,6 @@ 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
|
}
|
|
@@ -862,6 +839,25 @@ function worktreeHasUnfinishedRebase(repoRoot, worktreePath) {
|
|
|
862
839
|
return !path.ok || existsSync(resolve(worktreePath, path.stdout.trim()));
|
|
863
840
|
});
|
|
864
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
|
+
}
|
|
865
861
|
async function integrateWorkerCommitsIntoLeader(params) {
|
|
866
862
|
const { teamName, config, previous, cwd } = params;
|
|
867
863
|
const next = { ...(previous?.integrationByWorker ?? {}) };
|
|
@@ -869,33 +865,6 @@ async function integrateWorkerCommitsIntoLeader(params) {
|
|
|
869
865
|
const integratedWorkerNames = new Set();
|
|
870
866
|
const commitHygieneEntries = [];
|
|
871
867
|
const artifactCwd = resolveTeamCommitHygieneArtifactCwd(config, cwd);
|
|
872
|
-
// ── Phase A: Auto-commit dirty worktrees ──
|
|
873
|
-
for (const worker of config.workers) {
|
|
874
|
-
if (!worker.worktree_repo_root || !worker.worktree_path || !existsSync(worker.worktree_path))
|
|
875
|
-
continue;
|
|
876
|
-
if (next[worker.name]?.pending_rebase_leader_head
|
|
877
|
-
|| worktreeHasUnfinishedRebase(resolve(worker.worktree_repo_root), resolve(worker.worktree_path)))
|
|
878
|
-
continue;
|
|
879
|
-
const { committed, commitHash } = autoCommitDirtyWorktree(worker);
|
|
880
|
-
if (committed) {
|
|
881
|
-
await appendIntegrationEvent(teamName, 'worker_auto_commit', worker, {
|
|
882
|
-
worker_name: worker.name,
|
|
883
|
-
commit_hash: commitHash,
|
|
884
|
-
worktree_path: resolve(worker.worktree_path),
|
|
885
|
-
summary: `auto-committed dirty worktree for ${worker.name}`,
|
|
886
|
-
}, cwd);
|
|
887
|
-
commitHygieneEntries.push({
|
|
888
|
-
recorded_at: new Date().toISOString(),
|
|
889
|
-
operation: 'auto_checkpoint',
|
|
890
|
-
worker_name: worker.name,
|
|
891
|
-
task_id: worker.assigned_tasks[0],
|
|
892
|
-
status: 'applied',
|
|
893
|
-
operational_commit: commitHash,
|
|
894
|
-
worktree_path: resolve(worker.worktree_path),
|
|
895
|
-
detail: 'Dirty worker worktree checkpointed before runtime integration.',
|
|
896
|
-
});
|
|
897
|
-
}
|
|
898
|
-
}
|
|
899
868
|
// ── Phase B: Integrate worker commits to leader (hybrid strategy) ──
|
|
900
869
|
for (const worker of config.workers) {
|
|
901
870
|
if (!worker.worktree_repo_root || !worker.worktree_path || !existsSync(worker.worktree_path))
|
|
@@ -921,17 +890,23 @@ async function integrateWorkerCommitsIntoLeader(params) {
|
|
|
921
890
|
if (!status.ok || status.stdout.trim()
|
|
922
891
|
|| !previousState.last_integrated_head || resolveWorkerHead(worktreePath) !== previousState.last_integrated_head)
|
|
923
892
|
continue;
|
|
924
|
-
//
|
|
893
|
+
// Redeliver only the clean original source after its recorded delivery disappeared.
|
|
925
894
|
next[worker.name] = {
|
|
926
895
|
...previousState, last_integrated_head: undefined, delivery_leader_commit: undefined,
|
|
927
896
|
pending_rebase_leader_head: undefined, rebase_error: undefined,
|
|
928
897
|
conflict_commit: undefined, conflict_files: undefined, status: 'idle',
|
|
929
898
|
};
|
|
930
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;
|
|
931
906
|
const leaderHead = resolveLeaderHead(repoRoot, cwd);
|
|
932
907
|
const workerHead = resolveWorkerHead(worktreePath);
|
|
933
908
|
const state = { ...next[worker.name], last_leader_head: leaderHead ?? previousState.last_leader_head };
|
|
934
|
-
if (!workerHead || !leaderHead) {
|
|
909
|
+
if (!workerHead || workerHead !== verifiedHead || !leaderHead) {
|
|
935
910
|
next[worker.name] = state;
|
|
936
911
|
continue;
|
|
937
912
|
}
|
|
@@ -953,9 +928,8 @@ async function integrateWorkerCommitsIntoLeader(params) {
|
|
|
953
928
|
// Determine if worker is cleanly ahead of leader (merge) or diverged (cherry-pick)
|
|
954
929
|
const workerIsAheadOfLeader = runGitCommand(repoRoot, ['merge-base', '--is-ancestor', leaderHead, workerHead], cwd).ok;
|
|
955
930
|
if (workerIsAheadOfLeader) {
|
|
956
|
-
//
|
|
957
|
-
const
|
|
958
|
-
const branchRef = resolveWorkerMergeRef(workerBranch, workerHead);
|
|
931
|
+
// Publish the immutable verified commit without choosing sides on conflicts.
|
|
932
|
+
const branchRef = verifiedHead;
|
|
959
933
|
const merge = runGitCommand(repoRoot, ['merge', '--no-ff', '-m', `omx(team): merge ${worker.name}`, branchRef], cwd);
|
|
960
934
|
if (merge.ok) {
|
|
961
935
|
const newLeaderHead = resolveLeaderHead(repoRoot, cwd) ?? leaderHead;
|
|
@@ -1151,7 +1125,7 @@ async function integrateWorkerCommitsIntoLeader(params) {
|
|
|
1151
1125
|
}
|
|
1152
1126
|
next[worker.name] = state;
|
|
1153
1127
|
}
|
|
1154
|
-
// ── Phase C: Cross-worker rebase (
|
|
1128
|
+
// ── Phase C: Cross-worker rebase (ready workers onto new leader) ──
|
|
1155
1129
|
const newLeaderHead = resolveLeaderHead(resolve(config.workers[0]?.worktree_repo_root ?? cwd), cwd);
|
|
1156
1130
|
if (newLeaderHead) {
|
|
1157
1131
|
for (const worker of config.workers) {
|
|
@@ -1181,10 +1155,9 @@ async function integrateWorkerCommitsIntoLeader(params) {
|
|
|
1181
1155
|
&& leaderContainsCommit(repoRoot, cwd, state.delivery_leader_commit)));
|
|
1182
1156
|
if (!sourceDelivered)
|
|
1183
1157
|
continue;
|
|
1184
|
-
// Only rebase idle/done/failed workers to avoid race conditions
|
|
1185
1158
|
const workerStatus = await readWorkerStatus(teamName, worker.name, cwd);
|
|
1186
|
-
const
|
|
1187
|
-
if (!
|
|
1159
|
+
const verifiedHead = await readVerifiedWorkerHandoff(teamName, worker, cwd);
|
|
1160
|
+
if (!verifiedHead) {
|
|
1188
1161
|
await appendIntegrationEvent(teamName, 'worker_cross_rebase_skipped', worker, {
|
|
1189
1162
|
worker_name: worker.name,
|
|
1190
1163
|
worker_state: workerStatus.state,
|
|
@@ -1201,6 +1174,7 @@ async function integrateWorkerCommitsIntoLeader(params) {
|
|
|
1201
1174
|
};
|
|
1202
1175
|
continue;
|
|
1203
1176
|
}
|
|
1177
|
+
// Never rebase a dirty or unreadable worktree.
|
|
1204
1178
|
const statusCheck = runGitCommand(repoRoot, ['status', '--porcelain', '--untracked-files=all', '--ignore-submodules=none'], worktreePath);
|
|
1205
1179
|
if (!statusCheck.ok || statusCheck.stdout.trim()) {
|
|
1206
1180
|
await appendIntegrationEvent(teamName, 'worker_cross_rebase_skipped', worker, {
|
|
@@ -1214,6 +1188,8 @@ async function integrateWorkerCommitsIntoLeader(params) {
|
|
|
1214
1188
|
}
|
|
1215
1189
|
// Rebase without silently dropping conflicting worker changes.
|
|
1216
1190
|
const workerHeadBeforeRebase = resolveWorkerHead(worktreePath);
|
|
1191
|
+
if (workerHeadBeforeRebase !== verifiedHead)
|
|
1192
|
+
continue;
|
|
1217
1193
|
const rebase = runGitCommand(repoRoot, ['rebase', newLeaderHead], worktreePath);
|
|
1218
1194
|
if (rebase.ok) {
|
|
1219
1195
|
const workerHeadAfterRebase = resolveWorkerHead(worktreePath);
|
|
@@ -2935,6 +2911,36 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
2935
2911
|
return currentOwner.status === 'value' && currentOwner.value === expectedOwnerId;
|
|
2936
2912
|
};
|
|
2937
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
|
+
};
|
|
2938
2944
|
const workerPaneIds = Array.from({ length: workerCount }, () => undefined);
|
|
2939
2945
|
const workerReadyTimeoutMs = resolveWorkerReadyTimeoutMs(launchEnv);
|
|
2940
2946
|
const workerStartupEvidenceTimeoutMs = resolveWorkerStartupEvidenceTimeoutMs(launchEnv, workerReadyTimeoutMs);
|
|
@@ -3138,14 +3144,14 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3138
3144
|
workerRole: plan.workerRole,
|
|
3139
3145
|
};
|
|
3140
3146
|
});
|
|
3141
|
-
const
|
|
3147
|
+
const materializeWorkerStartupIdentity = async (bootstrapPlan, workerIndex, paneId) => {
|
|
3142
3148
|
const workerWorkspace = bootstrapPlan.workerWorkspace;
|
|
3143
3149
|
const identity = {
|
|
3144
3150
|
name: bootstrapPlan.workerName,
|
|
3145
3151
|
index: workerIndex,
|
|
3146
3152
|
role: bootstrapPlan.workerRole,
|
|
3147
3153
|
worker_cli: bootstrapPlan.workerCli,
|
|
3148
|
-
assigned_tasks:
|
|
3154
|
+
assigned_tasks: config?.workers[workerIndex - 1]?.assigned_tasks ?? [],
|
|
3149
3155
|
working_dir: workerWorkspace.cwd,
|
|
3150
3156
|
worktree_repo_root: workerWorkspace.worktreeRepoRoot,
|
|
3151
3157
|
worktree_path: workerWorkspace.worktreePath,
|
|
@@ -3175,7 +3181,6 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3175
3181
|
config.workers[workerIndex - 1].pane_id = paneId;
|
|
3176
3182
|
config.workers[workerIndex - 1].role = bootstrapPlan.workerRole;
|
|
3177
3183
|
config.workers[workerIndex - 1].worker_cli = bootstrapPlan.workerCli;
|
|
3178
|
-
config.workers[workerIndex - 1].assigned_tasks = bootstrapPlan.workerTasks.map((task) => task.id);
|
|
3179
3184
|
config.workers[workerIndex - 1].working_dir = workerWorkspace.cwd;
|
|
3180
3185
|
config.workers[workerIndex - 1].worktree_repo_root = workerWorkspace.worktreeRepoRoot;
|
|
3181
3186
|
config.workers[workerIndex - 1].worktree_path = workerWorkspace.worktreePath;
|
|
@@ -3185,7 +3190,6 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3185
3190
|
config.workers[workerIndex - 1].team_state_root = teamStateRoot;
|
|
3186
3191
|
}
|
|
3187
3192
|
await writeWorkerIdentity(sanitized, bootstrapPlan.workerName, identity, leaderCwd);
|
|
3188
|
-
await writeWorkerInbox(sanitized, bootstrapPlan.workerName, bootstrapPlan.inbox, leaderCwd);
|
|
3189
3193
|
};
|
|
3190
3194
|
// 6. Create worker runtime (interactive tmux panes or prompt-mode child processes)
|
|
3191
3195
|
await writeTeamPreflightContextPacket({
|
|
@@ -3204,9 +3208,27 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3204
3208
|
writeWarning: options.writeCleanupWarning,
|
|
3205
3209
|
});
|
|
3206
3210
|
const startupTiming = createStartupTimingRecorder(sanitized, leaderCwd);
|
|
3207
|
-
//
|
|
3208
|
-
|
|
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;
|
|
3209
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
|
+
});
|
|
3210
3232
|
if (workerLaunchMode === 'interactive') {
|
|
3211
3233
|
const createdSession = createTeamSession(sanitized, workerCount, leaderCwd, Array.from(workerLaunchPolicyPlan[0]?.workerLaunchArgs ?? []), workerStartups, { ownerSessionId: leaderSessionId, teamPaneOwnerId: config.tmux_pane_owner_id });
|
|
3212
3234
|
sessionName = createdSession.name;
|
|
@@ -3254,7 +3276,7 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3254
3276
|
// createHerdrTeam returns only after every agent reached an idle,
|
|
3255
3277
|
// promptable state (agent-start readiness + settle polling): that is
|
|
3256
3278
|
// the herdr equivalent of observing a ready prompt in a tmux pane.
|
|
3257
|
-
|
|
3279
|
+
herdrTeamReady = true;
|
|
3258
3280
|
sessionName = herdrTeam.name;
|
|
3259
3281
|
sessionCreated = true;
|
|
3260
3282
|
config.tmux_session = herdrTeam.name;
|
|
@@ -3294,17 +3316,16 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3294
3316
|
}
|
|
3295
3317
|
}
|
|
3296
3318
|
}
|
|
3297
|
-
|
|
3298
|
-
//
|
|
3319
|
+
await persistStartupTransport();
|
|
3320
|
+
// Refresh transport identities only; a running worker may already have a follow-up inbox.
|
|
3299
3321
|
for (let i = 1; i <= workerCount; i++) {
|
|
3300
3322
|
const bootstrapPlan = workerBootstrapPlans[i - 1];
|
|
3301
3323
|
if (!bootstrapPlan) {
|
|
3302
3324
|
throw new Error(`missing bootstrap plan for worker-${i}`);
|
|
3303
3325
|
}
|
|
3304
|
-
await
|
|
3305
|
-
startupTiming.mark('
|
|
3326
|
+
await materializeWorkerStartupIdentity(bootstrapPlan, i, workerPaneIds[i - 1]);
|
|
3327
|
+
startupTiming.mark('identity_written', { worker: bootstrapPlan.workerName, pane_id: workerPaneIds[i - 1] });
|
|
3306
3328
|
}
|
|
3307
|
-
await saveTeamConfig(config, leaderCwd);
|
|
3308
3329
|
// 7. Start all safe per-worker readiness/dispatch attempts concurrently.
|
|
3309
3330
|
// Pane creation and worktree provisioning above remain dependency-bound and
|
|
3310
3331
|
// ordered; readiness polling and startup dispatch must not let worker-1
|
|
@@ -3321,10 +3342,11 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3321
3342
|
error: new Error(`missing bootstrap plan for worker-${workerIndex}`),
|
|
3322
3343
|
};
|
|
3323
3344
|
}
|
|
3345
|
+
// Each worker has its own readiness state; don't leak evidence from other workers.
|
|
3346
|
+
let startupReadyPromptObserved = herdrTeamReady || workerLaunchMode === 'herdr';
|
|
3324
3347
|
const workerName = bootstrapPlan.workerName;
|
|
3325
3348
|
const paneId = workerPaneIds[workerIndex - 1];
|
|
3326
3349
|
const workerTasks = bootstrapPlan.workerTasks;
|
|
3327
|
-
const inbox = bootstrapPlan.inbox;
|
|
3328
3350
|
const trigger = bootstrapPlan.trigger;
|
|
3329
3351
|
const triggerIntent = bootstrapPlan.triggerIntent;
|
|
3330
3352
|
const initialPrompt = bootstrapPlan.initialPrompt;
|
|
@@ -3342,7 +3364,6 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3342
3364
|
paneId,
|
|
3343
3365
|
workerCli: bootstrapPlan.workerCli,
|
|
3344
3366
|
finalArgs: workerStartupArgs?.[workerIndex - 1],
|
|
3345
|
-
inbox,
|
|
3346
3367
|
triggerMessage: trigger,
|
|
3347
3368
|
intent: triggerIntent,
|
|
3348
3369
|
taskIds: workerTasks.map((task) => task.id),
|
|
@@ -3425,7 +3446,6 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3425
3446
|
workerIndex,
|
|
3426
3447
|
paneId,
|
|
3427
3448
|
workerCli: bootstrapPlan.workerCli,
|
|
3428
|
-
inbox,
|
|
3429
3449
|
triggerMessage: trigger,
|
|
3430
3450
|
intent: triggerIntent,
|
|
3431
3451
|
cwd: leaderCwd,
|
|
@@ -3503,7 +3523,10 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3503
3523
|
if (firstStartupError) {
|
|
3504
3524
|
throw firstStartupError.error;
|
|
3505
3525
|
}
|
|
3506
|
-
|
|
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}`);
|
|
3507
3530
|
await startupTiming.flush();
|
|
3508
3531
|
return {
|
|
3509
3532
|
teamName: sanitized,
|
|
@@ -3523,7 +3546,7 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3523
3546
|
createdWorkerPaneIds.push(...partialSession.workerPaneIds);
|
|
3524
3547
|
createdLeaderPaneId = partialSession.leaderPaneId;
|
|
3525
3548
|
applyCreatedInteractiveSessionToConfig(config, partialSession, workerPaneIds);
|
|
3526
|
-
await
|
|
3549
|
+
await persistStartupTransport();
|
|
3527
3550
|
const cleanupDebt = [
|
|
3528
3551
|
...error.cleanupErrors,
|
|
3529
3552
|
...error.proofUnavailable.map((proof) => `pane_proof_unavailable:${proof.paneId}:${proof.reason}`),
|
|
@@ -3554,7 +3577,7 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3554
3577
|
: [];
|
|
3555
3578
|
});
|
|
3556
3579
|
if (startupCleanupDebt.length > 0) {
|
|
3557
|
-
await
|
|
3580
|
+
await persistStartupTransport();
|
|
3558
3581
|
await appendTeamEvent(sanitized, {
|
|
3559
3582
|
type: 'team_leader_nudge',
|
|
3560
3583
|
worker: 'leader-fixed',
|
|
@@ -3600,7 +3623,7 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3600
3623
|
}
|
|
3601
3624
|
if (paneProcessProofUnavailable.length > 0) {
|
|
3602
3625
|
if (config)
|
|
3603
|
-
await
|
|
3626
|
+
await persistStartupTransport();
|
|
3604
3627
|
assertPaneTeardownProofsAvailable('startup_rollback', paneProcessProofUnavailable);
|
|
3605
3628
|
}
|
|
3606
3629
|
const rollbackPanePids = Object.fromEntries((config?.workers ?? [])
|
|
@@ -3633,7 +3656,7 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3633
3656
|
if (rollbackPaneTeardown.proofUnavailable.length > 0) {
|
|
3634
3657
|
if (config) {
|
|
3635
3658
|
try {
|
|
3636
|
-
await
|
|
3659
|
+
await persistStartupTransport();
|
|
3637
3660
|
}
|
|
3638
3661
|
catch (cleanupError) {
|
|
3639
3662
|
rollbackErrors.push(`saveTeamConfig(preserve rollback state): ${String(cleanupError)}`);
|
|
@@ -3643,7 +3666,7 @@ export async function startTeam(teamName, task, agentType, workerCount, tasks, c
|
|
|
3643
3666
|
}
|
|
3644
3667
|
if (rollbackPaneTeardown.kill.failed > 0) {
|
|
3645
3668
|
if (config)
|
|
3646
|
-
await
|
|
3669
|
+
await persistStartupTransport();
|
|
3647
3670
|
const originalMessage = error instanceof Error ? error.message : String(error);
|
|
3648
3671
|
throw new Error(`${originalMessage}; rollback encountered errors: paneTeardown:${rollbackPaneTeardown.kill.failedPaneIds.join(',')}`);
|
|
3649
3672
|
}
|
|
@@ -4079,13 +4102,13 @@ export async function assignTask(teamName, workerName, taskId, cwd) {
|
|
|
4079
4102
|
let outcome = { ok: false, transport: 'none', reason: 'not_attempted' };
|
|
4080
4103
|
const triggerDirective = buildTriggerDirective(workerName, sanitized, resolveInstructionStateRoot(workerInfo.worktree_path));
|
|
4081
4104
|
for (let attempt = 1; attempt <= maxAssignRetries; attempt++) {
|
|
4105
|
+
await writeWorkerInbox(sanitized, workerName, inbox, cwd);
|
|
4082
4106
|
outcome = await dispatchCriticalInboxInstruction({
|
|
4083
4107
|
teamName: sanitized,
|
|
4084
4108
|
config,
|
|
4085
4109
|
workerName,
|
|
4086
4110
|
workerIndex: workerInfo.index,
|
|
4087
4111
|
paneId: workerInfo.pane_id,
|
|
4088
|
-
inbox,
|
|
4089
4112
|
triggerMessage: triggerDirective.text,
|
|
4090
4113
|
intent: triggerDirective.intent,
|
|
4091
4114
|
cwd,
|
|
@@ -4305,13 +4328,13 @@ export async function shutdownTeam(teamName, cwd, options = {}) {
|
|
|
4305
4328
|
await writeShutdownRequest(sanitized, w.name, 'leader-fixed', cwd);
|
|
4306
4329
|
shutdownRequestTimes.set(w.name, requestedAt);
|
|
4307
4330
|
const triggerDirective = buildTriggerDirective(w.name, sanitized, resolveInstructionStateRoot(w.worktree_path));
|
|
4331
|
+
await writeWorkerInbox(sanitized, w.name, generateShutdownInbox(sanitized, w.name), cwd);
|
|
4308
4332
|
await dispatchCriticalInboxInstruction({
|
|
4309
4333
|
teamName: sanitized,
|
|
4310
4334
|
config,
|
|
4311
4335
|
workerName: w.name,
|
|
4312
4336
|
workerIndex: w.index,
|
|
4313
4337
|
paneId: w.pane_id,
|
|
4314
|
-
inbox: generateShutdownInbox(sanitized, w.name),
|
|
4315
4338
|
triggerMessage: triggerDirective.text,
|
|
4316
4339
|
intent: triggerDirective.intent,
|
|
4317
4340
|
cwd,
|
|
@@ -4756,7 +4779,10 @@ export async function shutdownTeam(teamName, cwd, options = {}) {
|
|
|
4756
4779
|
}
|
|
4757
4780
|
}
|
|
4758
4781
|
if (herdrTeardownFailures.length > 0 && !herdrWorkspaceClosed) {
|
|
4759
|
-
|
|
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(',')}`);
|
|
4760
4786
|
}
|
|
4761
4787
|
}
|
|
4762
4788
|
else if (config.worker_launch_mode === 'prompt') {
|
|
@@ -5284,7 +5310,7 @@ async function markDispatchRequestLeaderPaneMissingDeferred(params) {
|
|
|
5284
5310
|
}, cwd).catch(() => { });
|
|
5285
5311
|
}
|
|
5286
5312
|
async function attemptStartupDirectTrigger(params) {
|
|
5287
|
-
const { teamName, config, workerName, workerIndex, paneId, workerCli, finalArgs,
|
|
5313
|
+
const { teamName, config, workerName, workerIndex, paneId, workerCli, finalArgs, triggerMessage, intent, taskIds, cwd, timing, } = params;
|
|
5288
5314
|
const safety = await evaluateStartupDirectTriggerSafety(config.tmux_session, workerIndex, paneId, workerCli, finalArgs);
|
|
5289
5315
|
if (!safety.safe) {
|
|
5290
5316
|
timing.mark('startup_direct_bypass', {
|
|
@@ -5298,12 +5324,11 @@ async function attemptStartupDirectTrigger(params) {
|
|
|
5298
5324
|
}
|
|
5299
5325
|
return null;
|
|
5300
5326
|
}
|
|
5301
|
-
const queued = await
|
|
5327
|
+
const queued = await queueInboxNotification({
|
|
5302
5328
|
teamName,
|
|
5303
5329
|
workerName,
|
|
5304
5330
|
workerIndex,
|
|
5305
5331
|
paneId,
|
|
5306
|
-
inbox,
|
|
5307
5332
|
triggerMessage,
|
|
5308
5333
|
intent,
|
|
5309
5334
|
cwd,
|
|
@@ -5370,17 +5395,16 @@ async function attemptStartupDirectTrigger(params) {
|
|
|
5370
5395
|
};
|
|
5371
5396
|
}
|
|
5372
5397
|
async function dispatchCriticalInboxInstruction(params) {
|
|
5373
|
-
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;
|
|
5374
5399
|
const noteTiming = (phase, details) => {
|
|
5375
5400
|
startupTiming?.mark(phase, { worker: workerName, pane_id: paneId, ...details });
|
|
5376
5401
|
};
|
|
5377
5402
|
if (config.worker_launch_mode === 'prompt') {
|
|
5378
|
-
return await
|
|
5403
|
+
return await queueInboxNotification({
|
|
5379
5404
|
teamName,
|
|
5380
5405
|
workerName,
|
|
5381
5406
|
workerIndex,
|
|
5382
5407
|
paneId,
|
|
5383
|
-
inbox,
|
|
5384
5408
|
triggerMessage,
|
|
5385
5409
|
intent,
|
|
5386
5410
|
cwd,
|
|
@@ -5391,12 +5415,11 @@ async function dispatchCriticalInboxInstruction(params) {
|
|
|
5391
5415
|
});
|
|
5392
5416
|
}
|
|
5393
5417
|
if (dispatchPolicy.dispatch_mode === 'transport_direct') {
|
|
5394
|
-
return await
|
|
5418
|
+
return await queueInboxNotification({
|
|
5395
5419
|
teamName,
|
|
5396
5420
|
workerName,
|
|
5397
5421
|
workerIndex,
|
|
5398
5422
|
paneId,
|
|
5399
|
-
inbox,
|
|
5400
5423
|
triggerMessage,
|
|
5401
5424
|
intent,
|
|
5402
5425
|
cwd,
|
|
@@ -5406,12 +5429,11 @@ async function dispatchCriticalInboxInstruction(params) {
|
|
|
5406
5429
|
notify: (_target, message) => notifyWorkerOutcome(config, workerIndex, message, paneId),
|
|
5407
5430
|
});
|
|
5408
5431
|
}
|
|
5409
|
-
const queued = await
|
|
5432
|
+
const queued = await queueInboxNotification({
|
|
5410
5433
|
teamName,
|
|
5411
5434
|
workerName,
|
|
5412
5435
|
workerIndex,
|
|
5413
5436
|
paneId,
|
|
5414
|
-
inbox,
|
|
5415
5437
|
triggerMessage,
|
|
5416
5438
|
intent,
|
|
5417
5439
|
cwd,
|