@fitlab-ai/agent-infra 0.11.7 → 0.11.8
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/dist/bin/internal-cli.js +8 -2
- package/dist/lib/agent-clients/adapters/codex.js +1 -1
- package/dist/lib/agent-clients/config.js +11 -3
- package/dist/lib/defaults.json +6 -3
- package/dist/lib/internal/cli-route-inventory.js +3 -0
- package/dist/lib/internal/platform-pr-review.js +20 -3
- package/dist/lib/internal/task-operation-registry.js +3 -1
- package/dist/lib/internal/task-platform-recovery.js +56 -0
- package/dist/lib/merge.js +25 -5
- package/dist/lib/platform/completion-backfill.js +2 -1
- package/dist/lib/platform/in-label-sync.js +12 -1
- package/dist/lib/platform/issue-comments.js +58 -4
- package/dist/lib/platform/issues.js +105 -5
- package/dist/lib/platform/operation-coordinator.js +74 -0
- package/dist/lib/platform/pr-review.js +107 -1
- package/dist/lib/platform/pr-summary.js +79 -57
- package/dist/lib/platform/pull-requests.js +96 -4
- package/dist/lib/sandbox/commands/create.js +6 -3
- package/dist/lib/sandbox/commands/ls.js +4 -3
- package/dist/lib/sandbox/commands/rm.js +1 -1
- package/dist/lib/sandbox/config.js +22 -4
- package/dist/lib/sandbox/git-metadata.js +50 -0
- package/dist/lib/sandbox/index.js +1 -1
- package/dist/lib/sandbox/mounts.js +12 -0
- package/dist/lib/sandbox/recovery.js +11 -0
- package/dist/lib/sandbox/removal.js +58 -20
- package/dist/lib/sandbox/tools.js +29 -7
- package/dist/lib/task/activity-intent.js +4 -3
- package/dist/lib/task/create-service.js +5 -3
- package/dist/lib/task/create.js +22 -5
- package/dist/lib/task/finalization-artifacts.js +4 -1
- package/dist/lib/task/finalization.js +157 -24
- package/dist/lib/task/lifecycle.js +38 -2
- package/dist/lib/task/platform-operation-journal.js +152 -0
- package/dist/lib/task/platform-operation-recovery.js +459 -0
- package/dist/lib/task/workflow-warning-intents.js +7 -1
- package/dist/lifecycle-build-manifest.json +3 -3
- package/lib/agent-clients/adapters/codex.ts +1 -1
- package/lib/agent-clients/config.ts +9 -3
- package/lib/defaults.json +6 -3
- package/lib/internal/cli-route-inventory.ts +2 -0
- package/lib/internal/platform-pr-review.ts +14 -3
- package/lib/internal/task-operation-registry.ts +3 -1
- package/lib/internal/task-platform-recovery.ts +53 -0
- package/lib/merge.ts +26 -6
- package/lib/platform/completion-backfill.ts +2 -1
- package/lib/platform/in-label-sync.ts +12 -0
- package/lib/platform/issue-comments.ts +59 -3
- package/lib/platform/issues.ts +103 -5
- package/lib/platform/operation-coordinator.ts +96 -0
- package/lib/platform/pr-review.ts +113 -1
- package/lib/platform/pr-summary.ts +22 -1
- package/lib/platform/pull-requests.ts +105 -5
- package/lib/sandbox/commands/create.ts +7 -8
- package/lib/sandbox/commands/ls.ts +4 -3
- package/lib/sandbox/commands/rm.ts +1 -1
- package/lib/sandbox/config.ts +23 -5
- package/lib/sandbox/git-metadata.ts +66 -0
- package/lib/sandbox/index.ts +1 -1
- package/lib/sandbox/mounts.ts +14 -0
- package/lib/sandbox/recovery.ts +13 -0
- package/lib/sandbox/removal.ts +57 -19
- package/lib/sandbox/tool-types.ts +1 -1
- package/lib/sandbox/tools.ts +36 -7
- package/lib/task/activity-intent.ts +4 -3
- package/lib/task/create-service.ts +5 -3
- package/lib/task/create.ts +17 -5
- package/lib/task/finalization-artifacts.ts +4 -1
- package/lib/task/finalization.ts +154 -21
- package/lib/task/lifecycle.ts +35 -3
- package/lib/task/platform-operation-journal.ts +230 -0
- package/lib/task/platform-operation-recovery.ts +435 -0
- package/lib/task/workflow-warning-intents.ts +9 -1
- package/package.json +1 -1
- package/templates/.agents/README.en.md +19 -17
- package/templates/.agents/README.zh-CN.md +18 -16
- package/templates/.agents/rules/README.en.md +1 -1
- package/templates/.agents/rules/README.zh-CN.md +1 -1
- package/templates/.agents/rules/task-management.en.md +12 -0
- package/templates/.agents/rules/task-management.zh-CN.md +12 -0
- package/templates/.agents/skills/cancel-task/SKILL.en.md +4 -2
- package/templates/.agents/skills/cancel-task/SKILL.zh-CN.md +4 -2
- package/templates/.agents/skills/code-task/SKILL.en.md +2 -2
- package/templates/.agents/skills/code-task/SKILL.zh-CN.md +2 -2
- package/templates/.agents/skills/complete-task/SKILL.en.md +2 -0
- package/templates/.agents/skills/complete-task/SKILL.zh-CN.md +2 -0
- package/templates/.agents/skills/plan-task/config/verify.en.json +1 -1
- package/templates/.agents/skills/plan-task/config/verify.zh-CN.json +1 -1
- package/templates/.agents/skills/review-pr/SKILL.en.md +11 -11
- package/templates/.agents/skills/review-pr/SKILL.zh-CN.md +11 -11
- package/templates/.agents/skills/review-pr/reference/output-guidance.en.md +3 -3
- package/templates/.agents/skills/review-pr/reference/output-guidance.zh-CN.md +3 -3
- package/templates/.agents/skills/review-pr/reference/report-template.en.md +4 -0
- package/templates/.agents/skills/review-pr/reference/report-template.zh-CN.md +4 -0
- package/templates/.agents/skills/update-agent-infra/scripts/sync-templates.js +19 -6
|
@@ -50,10 +50,22 @@ function cloneDefaults() {
|
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
52
|
function resolveSandboxToolIds(sandbox, defaults) {
|
|
53
|
-
if (
|
|
54
|
-
return
|
|
53
|
+
if (sandbox.tools === undefined) {
|
|
54
|
+
return [...defaults];
|
|
55
55
|
}
|
|
56
|
-
|
|
56
|
+
if (typeof sandbox.tools !== 'object' || sandbox.tools === null || Array.isArray(sandbox.tools)) {
|
|
57
|
+
throw new Error('sandbox.tools must be an object when configured');
|
|
58
|
+
}
|
|
59
|
+
const tools = sandbox.tools;
|
|
60
|
+
if (!Array.isArray(tools.ids)) {
|
|
61
|
+
throw new Error('sandbox.tools.ids must be an array');
|
|
62
|
+
}
|
|
63
|
+
return tools.ids.map((id, index) => {
|
|
64
|
+
if (typeof id !== 'string') {
|
|
65
|
+
throw new Error(`sandbox.tools.ids[${index}] must be a string`);
|
|
66
|
+
}
|
|
67
|
+
return id;
|
|
68
|
+
});
|
|
57
69
|
}
|
|
58
70
|
export function loadConfig({ platformFn = platform, writeStderr = (chunk) => process.stderr.write(chunk) } = {}) {
|
|
59
71
|
const repoRoot = detectRepoRoot();
|
|
@@ -100,7 +112,13 @@ export function loadConfig({ platformFn = platform, writeStderr = (chunk) => pro
|
|
|
100
112
|
' Update "sandbox.runtimes" in .agents/.airc.json (e.g. "node22"), or relax "engines.node".\n'));
|
|
101
113
|
}
|
|
102
114
|
}
|
|
103
|
-
const
|
|
115
|
+
const toolsConfig = sandbox.tools && typeof sandbox.tools === 'object' && !Array.isArray(sandbox.tools)
|
|
116
|
+
? sandbox.tools
|
|
117
|
+
: undefined;
|
|
118
|
+
if (sandbox.customTools !== undefined) {
|
|
119
|
+
throw new Error('sandbox.customTools is no longer supported; use sandbox.tools.definitions');
|
|
120
|
+
}
|
|
121
|
+
const customTools = parseCustomTools(toolsConfig?.definitions, { home });
|
|
104
122
|
const tools = resolveSandboxToolIds(sandbox, defaults.tools);
|
|
105
123
|
return {
|
|
106
124
|
repoRoot,
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
export const SANDBOX_GIT_COMMON_DIR = '/run/agent-infra/git';
|
|
5
|
+
function gitText(worktreeRoot, args) {
|
|
6
|
+
const env = { ...process.env };
|
|
7
|
+
for (const key of [
|
|
8
|
+
'GIT_DIR',
|
|
9
|
+
'GIT_COMMON_DIR',
|
|
10
|
+
'GIT_WORK_TREE',
|
|
11
|
+
'GIT_INDEX_FILE',
|
|
12
|
+
'GIT_PREFIX',
|
|
13
|
+
'GIT_NAMESPACE',
|
|
14
|
+
'GIT_OBJECT_DIRECTORY',
|
|
15
|
+
'GIT_CEILING_DIRECTORIES',
|
|
16
|
+
'GIT_DISCOVERY_ACROSS_FILESYSTEM'
|
|
17
|
+
]) {
|
|
18
|
+
delete env[key];
|
|
19
|
+
}
|
|
20
|
+
return execFileSync('git', ['-C', worktreeRoot, ...args], {
|
|
21
|
+
encoding: 'utf8',
|
|
22
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
23
|
+
env
|
|
24
|
+
}).trim();
|
|
25
|
+
}
|
|
26
|
+
export function resolveSandboxGitMetadata(worktreeRoot, controlDir) {
|
|
27
|
+
const commonDir = fs.realpathSync.native(gitText(worktreeRoot, [
|
|
28
|
+
'rev-parse', '--path-format=absolute', '--git-common-dir'
|
|
29
|
+
]));
|
|
30
|
+
const gitDir = fs.realpathSync.native(gitText(worktreeRoot, ['rev-parse', '--absolute-git-dir']));
|
|
31
|
+
const relativeGitDir = path.relative(commonDir, gitDir);
|
|
32
|
+
if (path.isAbsolute(relativeGitDir) || relativeGitDir.startsWith(`..${path.sep}`) || relativeGitDir === '..') {
|
|
33
|
+
throw new Error('SANDBOX_GIT_METADATA_INVALID: worktree git directory is outside its common directory');
|
|
34
|
+
}
|
|
35
|
+
const containerGitDir = relativeGitDir === '.'
|
|
36
|
+
? SANDBOX_GIT_COMMON_DIR
|
|
37
|
+
: path.posix.join(SANDBOX_GIT_COMMON_DIR, ...relativeGitDir.split(path.sep));
|
|
38
|
+
return {
|
|
39
|
+
commonDir,
|
|
40
|
+
worktreeGitFile: path.join(controlDir, 'workspace.git'),
|
|
41
|
+
worktreeGitFileContent: `gitdir: ${containerGitDir}\n`
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export function materializeSandboxGitMetadata(worktreeRoot, controlDir) {
|
|
45
|
+
const metadata = resolveSandboxGitMetadata(worktreeRoot, controlDir);
|
|
46
|
+
fs.mkdirSync(controlDir, { recursive: true });
|
|
47
|
+
fs.writeFileSync(metadata.worktreeGitFile, metadata.worktreeGitFileContent, 'utf8');
|
|
48
|
+
return metadata;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=git-metadata.js.map
|
|
@@ -19,7 +19,7 @@ Commands:
|
|
|
19
19
|
rm <branch | TASK-id> | --unbound | --purge
|
|
20
20
|
Remove one sandbox; use a full TASK-id for task-bound
|
|
21
21
|
cleanup and a branch for branch-only cleanup. --unbound
|
|
22
|
-
removes
|
|
22
|
+
removes sandboxes not bound to an active task short id.
|
|
23
23
|
start [--recreate] <branch | TASK-id | N>
|
|
24
24
|
Verify or recover an existing sandbox container;
|
|
25
25
|
optionally replace only the container on failure
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { shareBranchDir, shareCommonDir, shellConfigDirCandidates, worktreeDirCandidates } from './constants.js';
|
|
3
3
|
import { sandboxWorkspaceViewStatePaths } from './workspace-view.js';
|
|
4
|
+
import { SANDBOX_GIT_COMMON_DIR } from './git-metadata.js';
|
|
4
5
|
export function sandboxCoreBindMounts(config, branch, overrides) {
|
|
5
6
|
const taskSources = overrides.taskSources ?? [];
|
|
6
7
|
const taskBound = Boolean(taskSources.length > 0 && overrides.taskId);
|
|
@@ -15,7 +16,17 @@ export function sandboxCoreBindMounts(config, branch, overrides) {
|
|
|
15
16
|
containerPath: path.posix.join('/workspace/.agents/workspace', state),
|
|
16
17
|
readOnly: true
|
|
17
18
|
});
|
|
19
|
+
if (Boolean(overrides.gitCommonDir) !== Boolean(overrides.worktreeGitFile)) {
|
|
20
|
+
throw new Error('SANDBOX_GIT_METADATA_INCOMPLETE');
|
|
21
|
+
}
|
|
22
|
+
const gitCommonMount = overrides.gitCommonDir
|
|
23
|
+
? { hostPaths: [overrides.gitCommonDir], containerPath: SANDBOX_GIT_COMMON_DIR, readOnly: false }
|
|
24
|
+
: null;
|
|
25
|
+
const worktreeGitFileMount = overrides.worktreeGitFile
|
|
26
|
+
? { hostPaths: [overrides.worktreeGitFile], containerPath: '/workspace/.git', readOnly: true }
|
|
27
|
+
: null;
|
|
18
28
|
const mounts = [
|
|
29
|
+
...(gitCommonMount ? [gitCommonMount] : []),
|
|
19
30
|
{
|
|
20
31
|
hostPaths: overrides.worktree
|
|
21
32
|
? [overrides.worktree]
|
|
@@ -23,6 +34,7 @@ export function sandboxCoreBindMounts(config, branch, overrides) {
|
|
|
23
34
|
containerPath: '/workspace',
|
|
24
35
|
readOnly: false
|
|
25
36
|
},
|
|
37
|
+
...(worktreeGitFileMount ? [worktreeGitFileMount] : []),
|
|
26
38
|
...workspaceMounts,
|
|
27
39
|
];
|
|
28
40
|
if (taskBound) {
|
|
@@ -9,6 +9,7 @@ import { isAgentClientId } from '../agent-clients/types.js';
|
|
|
9
9
|
import { createSandboxCapabilityPlan } from './agent-client-reconciler.js';
|
|
10
10
|
import { toEnginePath } from './engines/wsl2-paths.js';
|
|
11
11
|
import { sandboxCoreBindMounts } from './mounts.js';
|
|
12
|
+
import { resolveSandboxGitMetadata } from './git-metadata.js';
|
|
12
13
|
import { assertSandboxTaskSource, sandboxControlPaths, sandboxWorkspaceViewPaths } from './workspace-view.js';
|
|
13
14
|
import { resolveTaskWorkspace } from './task-resolver.js';
|
|
14
15
|
import { parseSandboxWorkspaceIdentity, sameSandboxWorkspaceIdentity } from './workspace-identity.js';
|
|
@@ -530,7 +531,17 @@ function expectedMounts(params) {
|
|
|
530
531
|
? recoveryTaskSources(config.repoRoot, params.workspace.taskId)
|
|
531
532
|
: null;
|
|
532
533
|
const taskId = params.workspace.mode === 'task-bound' ? params.workspace.taskId : null;
|
|
534
|
+
const worktrees = worktreeDirCandidates(config, branch).filter((candidate) => fs.existsSync(path.join(candidate, '.git')));
|
|
535
|
+
const gitMetadata = worktrees.length === 1
|
|
536
|
+
? resolveSandboxGitMetadata(worktrees[0], control.channelDir)
|
|
537
|
+
: null;
|
|
533
538
|
const core = sandboxCoreBindMounts(config, branch, {
|
|
539
|
+
...(gitMetadata === null
|
|
540
|
+
? {}
|
|
541
|
+
: {
|
|
542
|
+
gitCommonDir: gitMetadata.commonDir,
|
|
543
|
+
worktreeGitFile: gitMetadata.worktreeGitFile
|
|
544
|
+
}),
|
|
534
545
|
workspaceViewRoot: view.root,
|
|
535
546
|
controlDir: control.channelDir,
|
|
536
547
|
controlStatusDir: control.statusDir,
|
|
@@ -8,7 +8,7 @@ import { ENGINES, detectEngine, engineDisplayName, isManagedEngine, stopManagedV
|
|
|
8
8
|
import { pruneSandboxDanglingImages } from './image-prune.js';
|
|
9
9
|
import { assertManagedPath, removeManagedDir, removeWorktreeDir } from './managed-fs.js';
|
|
10
10
|
import { run, runEngine, runOk, runOkEngine, runSafe, runSafeEngine } from './shell.js';
|
|
11
|
-
import { parseSandboxWorkspaceIdentity, resolveSandboxCleanupTarget, sameSandboxWorkspaceIdentity } from './workspace-identity.js';
|
|
11
|
+
import { parseSandboxWorkspaceIdentity, resolveSandboxCleanupTarget, resolveSandboxTarget, sameSandboxWorkspaceIdentity } from './workspace-identity.js';
|
|
12
12
|
import { sandboxControlPaths, sandboxWorkspaceViewPaths } from './workspace-view.js';
|
|
13
13
|
import { advanceSandboxRemovalJournalToPhase, advanceSandboxRemovalJournalPhase, claimSandboxRemovalJournal, clearSandboxRemovalJournalRecord, isDefaultSandboxRemovalJournal, listSandboxRemovalJournals, removeSandboxControlRoot, readSandboxControlManifest, sandboxRemovalPhaseIndex } from './control/lifecycle.js';
|
|
14
14
|
import { inspectSandboxControlContainer } from './control/container-identity.js';
|
|
@@ -792,38 +792,76 @@ async function rmPurgeCore(config, tools, prompt = {}) {
|
|
|
792
792
|
p.outro(pc.green('All project sandboxes removed'));
|
|
793
793
|
}
|
|
794
794
|
async function rmUnbound(config, tools, options) {
|
|
795
|
-
return rmUnboundCore(config, tools, options);
|
|
795
|
+
return withRepositoryMutationLock(config.repoRoot, () => rmUnboundCore(config, tools, options));
|
|
796
796
|
}
|
|
797
797
|
async function rmUnboundCore(config, tools, options) {
|
|
798
798
|
const engine = detectEngine(config);
|
|
799
799
|
const listed = fetchSandboxRows(engine, sandboxLabel(config), sandboxBranchLabel(config), { mode: sandboxWorkspaceModeLabel(config), taskId: sandboxTaskIdLabel(config) });
|
|
800
|
-
const
|
|
800
|
+
const discovered = [...listed.running, ...listed.nonRunning];
|
|
801
|
+
const branchMismatches = [];
|
|
802
|
+
const classified = discovered.map((row) => {
|
|
803
|
+
if (!row.branch)
|
|
804
|
+
return { row, protected: true, cleanupTarget: null };
|
|
805
|
+
if (row.workspaceMode === 'task-bound' && row.taskId) {
|
|
806
|
+
try {
|
|
807
|
+
resolveSandboxTarget(row.taskId, config.repoRoot);
|
|
808
|
+
return { row, protected: true, cleanupTarget: null };
|
|
809
|
+
}
|
|
810
|
+
catch {
|
|
811
|
+
try {
|
|
812
|
+
const cleanupTarget = resolveSandboxCleanupTarget(row.taskId, config.repoRoot, { allowProtected: true });
|
|
813
|
+
if (cleanupTarget.taskState === 'blocked'
|
|
814
|
+
|| cleanupTarget.taskState === 'completed'
|
|
815
|
+
|| cleanupTarget.taskState === 'archive') {
|
|
816
|
+
if (row.branch !== cleanupTarget.branch) {
|
|
817
|
+
branchMismatches.push({ container: row.name, labelBranch: row.branch, taskBranch: cleanupTarget.branch });
|
|
818
|
+
return { row, protected: true, cleanupTarget: null };
|
|
819
|
+
}
|
|
820
|
+
const activeBranchTarget = resolveSandboxTarget(cleanupTarget.branch, config.repoRoot);
|
|
821
|
+
if (activeBranchTarget.workspace.mode === 'branch-only') {
|
|
822
|
+
return { row, protected: false, cleanupTarget };
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
catch {
|
|
827
|
+
// An unresolved task identity has no active short-id evidence, so keep it out of bulk cleanup.
|
|
828
|
+
}
|
|
829
|
+
return { row, protected: true, cleanupTarget: null };
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
if (row.workspaceMode !== 'branch-only')
|
|
833
|
+
return { row, protected: true, cleanupTarget: null };
|
|
834
|
+
const cleanupTarget = resolveSandboxCleanupTarget(row.branch, config.repoRoot);
|
|
835
|
+
return cleanupTarget.workspace.mode === 'branch-only'
|
|
836
|
+
? { row, protected: false, cleanupTarget }
|
|
837
|
+
: { row, protected: true, cleanupTarget: null };
|
|
838
|
+
});
|
|
839
|
+
const protectedBranches = new Set(classified
|
|
840
|
+
.filter((entry) => entry.protected)
|
|
841
|
+
.map(({ row }) => row.branch));
|
|
842
|
+
const targets = classified
|
|
843
|
+
.filter((entry) => !entry.protected && !protectedBranches.has(entry.row.branch) && entry.cleanupTarget)
|
|
844
|
+
.map(({ row, cleanupTarget }) => ({
|
|
845
|
+
row,
|
|
846
|
+
cleanupTarget: cleanupTarget,
|
|
847
|
+
target: resolveRmTarget(config, tools, cleanupTarget, { discoveredContainers: [row.name] })
|
|
848
|
+
}));
|
|
801
849
|
p.intro(pc.cyan(`Removing sandboxes for ${config.project}`));
|
|
850
|
+
for (const mismatch of branchMismatches) {
|
|
851
|
+
p.log.warn(`Skipping task-bound sandbox '${mismatch.container}': container branch '${mismatch.labelBranch}' differs from task record branch '${mismatch.taskBranch}'. Inspect the task record and container labels before retrying cleanup.`);
|
|
852
|
+
}
|
|
802
853
|
if (options.dryRun) {
|
|
803
|
-
p.outro(`Dry run: ${
|
|
854
|
+
p.outro(`Dry run: ${targets.length} sandbox(es) found, nothing deleted`);
|
|
804
855
|
return;
|
|
805
856
|
}
|
|
806
|
-
for (const row of
|
|
807
|
-
|
|
808
|
-
runSafeEngine(engine, 'docker', ['rm', '-f', row.name]);
|
|
809
|
-
continue;
|
|
810
|
-
}
|
|
811
|
-
const cleanupTarget = {
|
|
812
|
-
requestedRef: row.branch,
|
|
813
|
-
branch: row.branch,
|
|
814
|
-
workspace: row.workspaceMode === 'task-bound' && row.taskId
|
|
815
|
-
? { mode: 'task-bound', taskId: row.taskId }
|
|
816
|
-
: { mode: 'branch-only' },
|
|
817
|
-
taskState: 'branch-only'
|
|
818
|
-
};
|
|
819
|
-
const target = resolveRmTarget(config, tools, cleanupTarget, { discoveredContainers: [row.name] });
|
|
820
|
-
await rmOne(config, tools, cleanupTarget.branch, {
|
|
857
|
+
for (const { row, cleanupTarget, target } of targets) {
|
|
858
|
+
await runRmOneUnderRepositoryLock(config, tools, cleanupTarget.branch, {
|
|
821
859
|
assumeYes: options.assumeYes,
|
|
822
860
|
target,
|
|
823
861
|
cleanupTarget
|
|
824
862
|
});
|
|
825
863
|
}
|
|
826
|
-
p.outro(pc.green(`Removed ${
|
|
864
|
+
p.outro(pc.green(`Removed ${targets.length} sandbox(es)`));
|
|
827
865
|
}
|
|
828
866
|
export { authorizeWorktrees, rmOne, rmPurge, rmUnbound };
|
|
829
867
|
//# sourceMappingURL=removal.js.map
|
|
@@ -56,6 +56,15 @@ function asOptionalNonEmptyString(value, field, context) {
|
|
|
56
56
|
}
|
|
57
57
|
return value;
|
|
58
58
|
}
|
|
59
|
+
function asOptionalBoolean(value, field, context) {
|
|
60
|
+
if (value === undefined) {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
if (typeof value !== 'boolean') {
|
|
64
|
+
throw new Error(`${context}: field "${field}" must be a boolean when provided`);
|
|
65
|
+
}
|
|
66
|
+
return value;
|
|
67
|
+
}
|
|
59
68
|
function asStringRecord(value, field, context) {
|
|
60
69
|
if (value === undefined) {
|
|
61
70
|
return undefined;
|
|
@@ -158,13 +167,14 @@ function parseTmpfs(value, context) {
|
|
|
158
167
|
if (!isPlainObject(value)) {
|
|
159
168
|
throw new Error(`${context}: field "tmpfs" must be an object when provided`);
|
|
160
169
|
}
|
|
170
|
+
const exec = asOptionalBoolean(value.exec, 'tmpfs.exec', context);
|
|
161
171
|
return {
|
|
162
172
|
size: asOptionalNonEmptyString(value.size, 'tmpfs.size', context),
|
|
163
|
-
seed: asStringArray(value.seed, 'tmpfs.seed', context)
|
|
173
|
+
seed: asStringArray(value.seed, 'tmpfs.seed', context),
|
|
174
|
+
...(exec === undefined ? {} : { exec })
|
|
164
175
|
};
|
|
165
176
|
}
|
|
166
|
-
export function parseCustomTool(entry, index, options) {
|
|
167
|
-
const context = `customTools[${index}]`;
|
|
177
|
+
export function parseCustomTool(entry, index, options, context = `customTools[${index}]`) {
|
|
168
178
|
if (!isPlainObject(entry)) {
|
|
169
179
|
throw new Error(`${context} must be an object`);
|
|
170
180
|
}
|
|
@@ -198,13 +208,25 @@ export function parseCustomTool(entry, index, options) {
|
|
|
198
208
|
return tool;
|
|
199
209
|
}
|
|
200
210
|
export function parseCustomTools(value, options) {
|
|
201
|
-
if (value === undefined
|
|
211
|
+
if (value === undefined) {
|
|
202
212
|
return [];
|
|
203
213
|
}
|
|
204
|
-
if (!
|
|
205
|
-
throw new Error('sandbox
|
|
214
|
+
if (!isPlainObject(value)) {
|
|
215
|
+
throw new Error('sandbox.tools.definitions must be an object');
|
|
206
216
|
}
|
|
207
|
-
return value.map((
|
|
217
|
+
return Object.entries(value).map(([id, definition], index) => {
|
|
218
|
+
const context = `sandbox.tools.definitions.${id}`;
|
|
219
|
+
if (!TOOL_ID_PATTERN.test(id)) {
|
|
220
|
+
throw new Error(`${context}: tool id must match ${TOOL_ID_PATTERN.source}`);
|
|
221
|
+
}
|
|
222
|
+
if (!isPlainObject(definition)) {
|
|
223
|
+
throw new Error(`${context} must be an object`);
|
|
224
|
+
}
|
|
225
|
+
if (Object.hasOwn(definition, 'id')) {
|
|
226
|
+
throw new Error(`${context}.id is not allowed; the definition key is the tool id`);
|
|
227
|
+
}
|
|
228
|
+
return parseCustomTool({ ...definition, id }, index, options, context);
|
|
229
|
+
});
|
|
208
230
|
}
|
|
209
231
|
export function resolveTools(config) {
|
|
210
232
|
return [...createSandboxCapabilityPlan(config).tools];
|
|
@@ -11,6 +11,7 @@ const REVIEW_ACTION_RE = /^Review PR \(Round ([1-9]\d*)\)( \[started\])?$/;
|
|
|
11
11
|
const VERDICTS = new Set(['approved', 'changes-requested', 'commented']);
|
|
12
12
|
const OUTCOMES = new Set(['aborted', 'superseded']);
|
|
13
13
|
const SUCCESS_STATUSES = new Set(['applied', 'no-op']);
|
|
14
|
+
const LOCAL_COMPLETION_STATUSES = new Set(['applied', 'no-op', 'blocked', 'failed']);
|
|
14
15
|
const ARTIFACT_STATUSES = new Set([
|
|
15
16
|
'pending', 'applied', 'no-op', 'blocked', 'failed', 'aborted', 'superseded'
|
|
16
17
|
]);
|
|
@@ -102,7 +103,7 @@ function readSnapshot(taskRef, repoRoot) {
|
|
|
102
103
|
}
|
|
103
104
|
if (terminal.length === 1) {
|
|
104
105
|
const note = terminal[0].note;
|
|
105
|
-
const terminalMatchesStatus = (note.startsWith('Verdict: ') &&
|
|
106
|
+
const terminalMatchesStatus = (note.startsWith('Verdict: ') && LOCAL_COMPLETION_STATUSES.has(parsed.status))
|
|
106
107
|
|| (note.startsWith('Outcome: Aborted, ') && parsed.status === 'aborted')
|
|
107
108
|
|| (note.startsWith('Outcome: Superseded, ') && parsed.status === 'superseded')
|
|
108
109
|
|| (note.startsWith('receipt ') && SUCCESS_STATUSES.has(parsed.status));
|
|
@@ -233,8 +234,8 @@ function applyLocked(intent, normalizedAgent, options) {
|
|
|
233
234
|
if (roundState.startedAgent === null) {
|
|
234
235
|
return failed(intent, 'ACTIVITY_STATE_CONFLICT', `${base} has no matching started row`, state.taskId);
|
|
235
236
|
}
|
|
236
|
-
if (intent.kind === 'pr-review-complete' && !
|
|
237
|
-
return failed(intent, 'ACTIVITY_STATE_CONFLICT', `${intent.artifact} must
|
|
237
|
+
if (intent.kind === 'pr-review-complete' && !LOCAL_COMPLETION_STATUSES.has(roundState.status)) {
|
|
238
|
+
return failed(intent, 'ACTIVITY_STATE_CONFLICT', `${intent.artifact} must record a publication outcome before completion`, state.taskId);
|
|
238
239
|
}
|
|
239
240
|
if (intent.kind === 'pr-review-terminate' && roundState.status !== intent.outcome) {
|
|
240
241
|
return failed(intent, 'ACTIVITY_STATE_CONFLICT', `${intent.artifact} status must match outcome ${intent.outcome}`, state.taskId);
|
|
@@ -3,6 +3,7 @@ import { createPlatformIssue, syncPlatformIssue } from '../platform/issues.js';
|
|
|
3
3
|
import { VERSION } from '../version.js';
|
|
4
4
|
import { applyWorkflowWarningIntent } from './workflow-warning-intents.js';
|
|
5
5
|
import { createLocalTask } from './create.js';
|
|
6
|
+
import { TaskExecutionLockError } from './task-execution-lock.js';
|
|
6
7
|
import { verifyTaskEvent } from './verification.js';
|
|
7
8
|
const DEFAULT_DEPENDENCIES = {
|
|
8
9
|
createIssue: createPlatformIssue,
|
|
@@ -151,8 +152,9 @@ async function createTask(value, options) {
|
|
|
151
152
|
}
|
|
152
153
|
catch (error) {
|
|
153
154
|
const message = error instanceof Error ? error.message : String(error);
|
|
154
|
-
const
|
|
155
|
-
|
|
155
|
+
const lockBusy = error instanceof TaskExecutionLockError && error.code === 'ORCHESTRATION_LOCK_BUSY';
|
|
156
|
+
const code = lockBusy ? error.code : /^([A-Z][A-Z0-9_]+)/.exec(message)?.[1] ?? 'TASK_CREATE_FAILED';
|
|
157
|
+
return taskCreateFailure({ code, message, retryable: lockBusy || code === 'TASK_CREATE_LOCK_TIMEOUT' });
|
|
156
158
|
}
|
|
157
159
|
const operations = [{
|
|
158
160
|
name: 'task:local', status: local.status, reasonCode: null
|
|
@@ -203,7 +205,7 @@ async function createTask(value, options) {
|
|
|
203
205
|
task: local.task, issue, operations, warnings: [], error: verified.error
|
|
204
206
|
};
|
|
205
207
|
return {
|
|
206
|
-
status:
|
|
208
|
+
status: 'degraded',
|
|
207
209
|
changed: local.changed,
|
|
208
210
|
task: local.task,
|
|
209
211
|
issue,
|
package/dist/lib/task/create.js
CHANGED
|
@@ -4,7 +4,7 @@ import os from 'node:os';
|
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import { isValidAgentInfraVersion, VERSION } from '../version.js';
|
|
6
6
|
import { loadShortIdByTaskId, mutateShortIdRegistry } from './short-id.js';
|
|
7
|
-
import { TaskExecutionLockError, withTaskExecutionLock } from './task-execution-lock.js';
|
|
7
|
+
import { TaskExecutionLockError, withRepositoryMutationLock, withTaskExecutionLock } from './task-execution-lock.js';
|
|
8
8
|
import { readDeliveryDefaults, validateBaseRef, validateRemote } from './delivery-target.js';
|
|
9
9
|
import { buildUnboundFact, encodePrDeliveryFact } from './pr-delivery-fact.js';
|
|
10
10
|
import { CANDIDATE_COLUMNS, CONSTRAINT_COLUMNS, parseTaskQualification } from './qualification-audit.js';
|
|
@@ -375,7 +375,7 @@ function createLocalTask(value, options) {
|
|
|
375
375
|
const canonical = canonicalTaskCreateCandidate(candidate);
|
|
376
376
|
const candidateDigest = sha256(canonical);
|
|
377
377
|
const keyDigest = sha256(candidate.idempotencyKey);
|
|
378
|
-
|
|
378
|
+
function createUnderRepositoryLock() {
|
|
379
379
|
const recovered = recoverPublishedTask(repoRoot, keyDigest, candidateDigest);
|
|
380
380
|
if (recovered) {
|
|
381
381
|
return { status: 'no-op', changed: false, task: { id: recovered.taskId, shortId: recovered.shortId, state: recovered.state } };
|
|
@@ -402,12 +402,29 @@ function createLocalTask(value, options) {
|
|
|
402
402
|
fs.writeFileSync(path.join(temporary, 'task.md'), rendered, { flag: 'wx', mode: 0o600 });
|
|
403
403
|
const destination = path.join(activeRoot, taskId);
|
|
404
404
|
fs.renameSync(temporary, destination);
|
|
405
|
-
let shortId;
|
|
406
405
|
const allocated = mutateShortIdRegistry(repoRoot, taskId, 'alloc');
|
|
407
406
|
if (!allocated.shortId)
|
|
408
407
|
throw new Error('TASK_CREATE_SHORT_ID_FAILED');
|
|
409
|
-
shortId
|
|
410
|
-
|
|
408
|
+
return { status: 'applied', changed: true, task: { id: taskId, shortId: allocated.shortId, state: 'active' } };
|
|
409
|
+
}
|
|
410
|
+
return withCreateLock(repoRoot, projectConfig.project, () => {
|
|
411
|
+
let callbackError;
|
|
412
|
+
try {
|
|
413
|
+
return withRepositoryMutationLock(repoRoot, () => {
|
|
414
|
+
try {
|
|
415
|
+
return createUnderRepositoryLock();
|
|
416
|
+
}
|
|
417
|
+
catch (error) {
|
|
418
|
+
callbackError = error;
|
|
419
|
+
throw error;
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
catch (error) {
|
|
424
|
+
if (callbackError !== undefined)
|
|
425
|
+
throw callbackError;
|
|
426
|
+
throw error;
|
|
427
|
+
}
|
|
411
428
|
});
|
|
412
429
|
}
|
|
413
430
|
export { canonicalTaskCreateCandidate, createLocalTask, validateTaskCreateCandidate };
|
|
@@ -5,7 +5,10 @@ const COMPLETION_BACKFILL_FAMILIES = [
|
|
|
5
5
|
'plan',
|
|
6
6
|
'review-plan',
|
|
7
7
|
'code',
|
|
8
|
-
'review-code'
|
|
8
|
+
'review-code',
|
|
9
|
+
'manual-validation',
|
|
10
|
+
'validation-run',
|
|
11
|
+
'pr-review'
|
|
9
12
|
];
|
|
10
13
|
function inspectCompletionArtifacts(taskRef, options = {}) {
|
|
11
14
|
const artifacts = [];
|