@cortex-agent/server 2026.9.21 → 2026.9.25
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/defaults/config/thread-templates/agents/creative.json +17 -0
- package/defaults/prompts/systemPrompts/creative.md +13 -0
- package/defaults/prompts/systemPrompts/direct.md +1 -1
- package/dist/agent-adapter/claude/adapter.d.ts +12 -0
- package/dist/agent-adapter/claude/adapter.js +19 -1
- package/dist/agent-adapter/claude/spawn-args.d.ts +7 -0
- package/dist/agent-adapter/claude/spawn-args.js +10 -0
- package/dist/agent-adapter/pi/child-runner.d.ts +4 -2
- package/dist/agent-adapter/pi/child-runner.js +5 -1
- package/dist/agent-adapter/pi/event-parser.d.ts +3 -2
- package/dist/agent-adapter/pi/event-parser.js +46 -2
- package/dist/agent-adapter/pi/extensions.d.ts +7 -1
- package/dist/agent-adapter/pi/extensions.js +10 -3
- package/dist/agent-adapter/pi/mcp-bridge.js +8 -8
- package/dist/agent-adapter/pi/pi-session.js +5 -0
- package/dist/agent-adapter/pi/runtime.js +3 -0
- package/dist/agent-adapter/pi/session-options.js +5 -1
- package/dist/agent-adapter/pi/subagent.d.ts +15 -3
- package/dist/agent-adapter/pi/subagent.js +18 -0
- package/dist/agent-adapter/pi/tool-shims.d.ts +6 -1
- package/dist/agent-adapter/pi/tool-shims.js +34 -1
- package/dist/agent-adapter/types.d.ts +5 -0
- package/dist/core/agents/subagent/types.d.ts +3 -0
- package/dist/core/config-generator.js +17 -2
- package/dist/core/debug-mode.d.ts +11 -10
- package/dist/core/debug-mode.js +12 -18
- package/dist/core/exec-async.d.ts +26 -0
- package/dist/core/exec-async.js +47 -0
- package/dist/core/locales/en.d.ts +14 -1
- package/dist/core/locales/slices/commands.d.ts +12 -1
- package/dist/core/locales/slices/commands.js +24 -2
- package/dist/core/locales/slices/startup.d.ts +2 -0
- package/dist/core/locales/slices/startup.js +4 -0
- package/dist/core/rebuild-progress.d.ts +58 -0
- package/dist/core/rebuild-progress.js +103 -0
- package/dist/core/resilient-watch.js +5 -3
- package/dist/core/run-registry.d.ts +7 -0
- package/dist/core/run-registry.js +6 -0
- package/dist/core/types/thread-types.d.ts +23 -4
- package/dist/domain/agents/agent-state.d.ts +7 -0
- package/dist/domain/agents/agent-state.js +9 -1
- package/dist/domain/agents/agent-switch.d.ts +38 -0
- package/dist/domain/agents/agent-switch.js +106 -0
- package/dist/domain/agents/config.d.ts +20 -2
- package/dist/domain/agents/config.js +58 -4
- package/dist/domain/agents/index.d.ts +1 -0
- package/dist/domain/agents/index.js +1 -0
- package/dist/domain/agents/profile-manager.d.ts +6 -0
- package/dist/domain/agents/profile-manager.js +14 -1
- package/dist/domain/executions/registry.d.ts +2 -0
- package/dist/domain/executions/registry.js +84 -7
- package/dist/domain/plugins/runtime.js +1 -1
- package/dist/domain/plugins/skill-projection.d.ts +8 -2
- package/dist/domain/plugins/skill-projection.js +76 -19
- package/dist/domain/remote/client-bootstrap.js +1 -1
- package/dist/domain/remote/client-hot-reload.d.ts +1 -1
- package/dist/domain/remote/client-hot-reload.js +27 -23
- package/dist/domain/runs/engine-spec.js +4 -0
- package/dist/domain/runs/request.d.ts +6 -0
- package/dist/domain/runs/run.js +1 -0
- package/dist/domain/runs/spec-loader.d.ts +4 -3
- package/dist/domain/runs/spec-loader.js +4 -3
- package/dist/domain/scheduling/jobs/sync-public.js +6 -6
- package/dist/domain/scheduling/scheduler.js +14 -12
- package/dist/domain/sessions/session-lifecycle.d.ts +5 -0
- package/dist/domain/sessions/session-lifecycle.js +13 -1
- package/dist/domain/system/rebuild-hold.d.ts +44 -0
- package/dist/domain/system/rebuild-hold.js +91 -0
- package/dist/domain/system/server-update-check.d.ts +2 -1
- package/dist/domain/system/server-update-check.js +15 -13
- package/dist/domain/tasks/archiver.js +21 -13
- package/dist/domain/tasks/mutator.js +60 -59
- package/dist/domain/tasks/system/task-completion.d.ts +7 -2
- package/dist/domain/tasks/system/task-completion.js +69 -6
- package/dist/domain/tasks/system/task-lifecycle-edit.d.ts +6 -1
- package/dist/domain/tasks/system/task-lifecycle-edit.js +21 -2
- package/dist/domain/tasks/system/task-lock.d.ts +23 -0
- package/dist/domain/tasks/system/task-lock.js +29 -1
- package/dist/domain/tasks/system/task-mutations.d.ts +14 -1
- package/dist/domain/tasks/system/task-mutations.js +25 -2
- package/dist/domain/tasks/system/task-state.d.ts +12 -1
- package/dist/domain/tasks/system/task-state.js +19 -2
- package/dist/domain/threads/prompt-builder.d.ts +9 -6
- package/dist/domain/threads/prompt-builder.js +28 -10
- package/dist/domain/threads/runner.js +7 -3
- package/dist/domain/threads/state-machine.js +15 -11
- package/dist/domain/threads/template-loader.js +6 -4
- package/dist/domain/threads/template-validate.d.ts +43 -6
- package/dist/domain/threads/template-validate.js +12 -0
- package/dist/domain/ui-service/app-router.d.ts +10 -0
- package/dist/domain/ui-service/app-router.js +2 -1
- package/dist/domain/ui-service/input-schemas.d.ts +11 -0
- package/dist/domain/ui-service/input-schemas.js +11 -0
- package/dist/domain/ui-service/mutate/sessions.d.ts +2 -1
- package/dist/domain/ui-service/mutate/sessions.js +40 -0
- package/dist/domain/ui-service/mutate/tasks.js +4 -3
- package/dist/domain/ui-service/query/config.js +19 -1
- package/dist/domain/ui-service/query/memory.js +28 -34
- package/dist/domain/ui-service/query/sessions.js +89 -12
- package/dist/domain/ui-service/query/system.js +19 -0
- package/dist/domain/ui-service/query-input-schemas.d.ts +1 -0
- package/dist/domain/ui-service/query-input-schemas.js +2 -0
- package/dist/domain/ui-service/types.d.ts +97 -3
- package/dist/domain/ui-service/ui-service.js +2 -1
- package/dist/entry/app.js +23 -4
- package/dist/entry/daemon-notice.d.ts +10 -1
- package/dist/entry/daemon-notice.js +16 -1
- package/dist/entry/daemon.d.ts +43 -2
- package/dist/entry/daemon.js +163 -9
- package/dist/orchestration/agent-runner.js +16 -0
- package/dist/orchestration/conversation-request.d.ts +33 -0
- package/dist/orchestration/conversation-request.js +78 -16
- package/dist/orchestration/mid-turn-inject.d.ts +3 -0
- package/dist/orchestration/mid-turn-inject.js +9 -4
- package/dist/orchestration/resume-dispatcher.js +4 -2
- package/dist/orchestration/routing/commands/mode.js +114 -63
- package/dist/orchestration/thread-executor.js +13 -0
- package/dist/orchestration/turn/turn.js +1 -0
- package/dist/store/conversation-display-projection.d.ts +9 -1
- package/dist/store/conversation-display-projection.js +13 -6
- package/dist/store/conversation-history-reader.d.ts +19 -0
- package/dist/store/conversation-history-reader.js +163 -44
- package/dist/store/conversation-history-repo.d.ts +37 -10
- package/dist/store/conversation-history-repo.js +161 -139
- package/dist/store/session-registry-journal.d.ts +4 -0
- package/dist/store/session-registry-journal.js +4 -0
- package/dist/store/session-registry-repo.d.ts +2 -1
- package/dist/store/session-registry-repo.js +2 -0
- package/dist/store/task-repo.d.ts +6 -3
- package/dist/store/task-repo.js +26 -10
- package/package.json +2 -1
- package/web/dist/AGENTS.md +10 -0
- package/web/dist/assets/index-B1dBi8Za.css +1 -0
- package/web/dist/assets/{index-DZTuqUO4.js → index-BAeLybF0.js} +1 -1
- package/web/dist/assets/index-BcQI8Fh5.js +445 -0
- package/web/dist/index.html +12 -4
- package/web/dist/theme.css +211 -40
- package/web/dist/assets/index-CwwQNMpP.css +0 -1
- package/web/dist/assets/index-DLSfgq3o.js +0 -444
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as fs from 'node:fs';
|
|
2
|
-
import
|
|
2
|
+
import * as os from 'node:os';
|
|
3
|
+
import { spawn } from 'node:child_process';
|
|
3
4
|
import { getSettings } from '../../core/settings.js';
|
|
5
|
+
import { runFile } from '../../core/exec-async.js';
|
|
4
6
|
import { CORTEX_VERSION } from '../../core/version.js';
|
|
5
7
|
import { loadUpdateState, saveUpdateState } from './update-state.js';
|
|
6
8
|
import { reportServerUpdateFailed, reportServerUpdateInstalled } from './update-ui-state.js';
|
|
@@ -24,18 +26,18 @@ export function isUpdateDevMode() {
|
|
|
24
26
|
}
|
|
25
27
|
}
|
|
26
28
|
// ── Default implementations ─────────────────────────────────────
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
catch {
|
|
29
|
+
/** Async: `npm view` is a network round trip and must not stall the event loop (it used to run
|
|
30
|
+
* via execSync with a 15s timeout, on a timer that fires 60s after boot). */
|
|
31
|
+
async function defaultGetLatest() {
|
|
32
|
+
const result = await runFile('npm', ['view', '@cortex-agent/server', 'version'], {
|
|
33
|
+
timeoutMs: 15000,
|
|
34
|
+
// Outside any project checkout, so a local .npmrc cannot redirect the registry lookup.
|
|
35
|
+
cwd: os.tmpdir(),
|
|
36
|
+
});
|
|
37
|
+
if (!result.ok)
|
|
37
38
|
return null;
|
|
38
|
-
|
|
39
|
+
const version = result.stdout.trim();
|
|
40
|
+
return version || null;
|
|
39
41
|
}
|
|
40
42
|
/** Keep the reported stderr small enough to sit in a dialog and in the status snapshot. */
|
|
41
43
|
const INSTALL_STDERR_CAP = 2000;
|
|
@@ -91,7 +93,7 @@ export async function checkServerUpdate(deps) {
|
|
|
91
93
|
const saveState = deps.saveState ?? saveUpdateState;
|
|
92
94
|
const now = deps.now ?? defaultNow;
|
|
93
95
|
// 2. Fetch latest version
|
|
94
|
-
const latestVersion = getLatest();
|
|
96
|
+
const latestVersion = await getLatest();
|
|
95
97
|
if (latestVersion === null) {
|
|
96
98
|
return { action: null, latestVersion: null };
|
|
97
99
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as fs from 'fs';
|
|
2
2
|
import * as path from 'path';
|
|
3
|
-
import {
|
|
3
|
+
import { runFile } from '../../core/exec-async.js';
|
|
4
4
|
import { PROJECTS_DIR, DATA_DIR } from '../../core/utils.js';
|
|
5
5
|
import { createLogger } from '../../core/log.js';
|
|
6
|
-
import { readTasks,
|
|
6
|
+
import { readTasks, withTaskFileMutationLockAsync, writeTasks, } from './system/task-lifecycle-edit.js';
|
|
7
7
|
import { taskStore } from './store.js';
|
|
8
8
|
const log = createLogger('task-archiver');
|
|
9
9
|
const ARCHIVE_AGE_DAYS = 3;
|
|
@@ -60,10 +60,10 @@ function processProjectUnlocked(projectName) {
|
|
|
60
60
|
fs.writeFileSync(archivePath, archiveContent);
|
|
61
61
|
return { project: projectName, ids: archivedIds };
|
|
62
62
|
}
|
|
63
|
-
function processProject(projectName) {
|
|
64
|
-
return
|
|
63
|
+
async function processProject(projectName) {
|
|
64
|
+
return withTaskFileMutationLockAsync(projectName, async () => processProjectUnlocked(projectName));
|
|
65
65
|
}
|
|
66
|
-
function gitCommit(results) {
|
|
66
|
+
async function gitCommit(results) {
|
|
67
67
|
const files = [];
|
|
68
68
|
for (const r of results) {
|
|
69
69
|
const projectDir = path.join(PROJECTS_DIR, r.project);
|
|
@@ -71,16 +71,24 @@ function gitCommit(results) {
|
|
|
71
71
|
files.push(path.join(projectDir, 'tasks-archive.md'));
|
|
72
72
|
}
|
|
73
73
|
try {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
// Async git (was execSync): this job runs inside the shared server process.
|
|
75
|
+
const added = await runFile('git', ['add', ...files], { cwd: DATA_DIR, timeoutMs: 10000 });
|
|
76
|
+
if (!added.ok) {
|
|
77
|
+
log.error('Git add failed:', (added.stderr || added.error || '').trim());
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const status = await runFile('git', ['diff', '--cached', '--stat'], { cwd: DATA_DIR, timeoutMs: 5000 });
|
|
81
|
+
if (!status.ok || !status.stdout.trim()) {
|
|
78
82
|
log.info('No changes to commit');
|
|
79
83
|
return;
|
|
80
84
|
}
|
|
81
85
|
const summary = results.map((r) => `${r.project}: ${r.ids.length} tasks`).join('; ');
|
|
82
86
|
const msg = `auto-archive: completed tasks (${summary})`;
|
|
83
|
-
|
|
87
|
+
const committed = await runFile('git', ['commit', '-m', msg], { cwd: DATA_DIR, timeoutMs: 10000 });
|
|
88
|
+
if (!committed.ok) {
|
|
89
|
+
log.error('Git commit failed:', (committed.stderr || committed.stdout || '').trim());
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
84
92
|
log.info(`Committed: ${msg}`);
|
|
85
93
|
}
|
|
86
94
|
catch (e) {
|
|
@@ -88,7 +96,7 @@ function gitCommit(results) {
|
|
|
88
96
|
}
|
|
89
97
|
}
|
|
90
98
|
async function runTaskArchiver() {
|
|
91
|
-
return taskStore.runExclusive(() => {
|
|
99
|
+
return taskStore.runExclusive(async () => {
|
|
92
100
|
log.info('Starting scan...');
|
|
93
101
|
const results = {
|
|
94
102
|
archived: [], skipped: [], errors: [],
|
|
@@ -104,7 +112,7 @@ async function runTaskArchiver() {
|
|
|
104
112
|
}
|
|
105
113
|
for (const name of projectNames) {
|
|
106
114
|
try {
|
|
107
|
-
const result = processProject(name);
|
|
115
|
+
const result = await processProject(name);
|
|
108
116
|
if (result)
|
|
109
117
|
results.archived.push(result);
|
|
110
118
|
else
|
|
@@ -116,7 +124,7 @@ async function runTaskArchiver() {
|
|
|
116
124
|
}
|
|
117
125
|
}
|
|
118
126
|
if (results.archived.length > 0)
|
|
119
|
-
gitCommit(results.archived);
|
|
127
|
+
await gitCommit(results.archived);
|
|
120
128
|
const archivedCount = results.archived.reduce((sum, r) => sum + r.ids.length, 0);
|
|
121
129
|
log.info(`Done. Archived ${archivedCount} tasks from ${results.archived.length} project(s)`);
|
|
122
130
|
return results;
|
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
import { taskStore } from '../../store/task-repo.js';
|
|
2
2
|
import { emitCortexEvent } from '../../core/hook-bus.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
3
|
+
import { approveTaskAsync as lifecycleApproveTask, blockTaskAsync as lifecycleBlockTask, claimTaskAsync as lifecycleClaimTask, clearApprovalTaskAsync as lifecycleClearApprovalTask, pauseTaskAsync as lifecyclePauseTask, requestApprovalTaskAsync as lifecycleRequestApprovalTask, resumeTaskAsync as lifecycleResumeTask, unblockTaskAsync as lifecycleUnblockTask, unclaimTaskAsync as lifecycleUnclaimTask, } from './system/task-state.js';
|
|
4
|
+
import { completeTaskAsync as lifecycleCompleteTask, uncompleteTaskAsync as lifecycleUncompleteTask, } from './system/task-completion.js';
|
|
5
|
+
import { addTaskAsync as lifecycleAddTask, batchEditAsync as lifecycleBatchEdit, decomposeTaskAsync as lifecycleDecomposeTask, } from './system/task-mutations.js';
|
|
6
|
+
import { editTaskAsync as lifecycleEditTask } from './system/task-lifecycle-edit.js';
|
|
7
|
+
import { acquireLockAsync, assertLockHeld, getOwnerIdentity, isProjectLocked, releaseLockAsync, } from './system/task-lock.js';
|
|
8
8
|
const SYSTEM_LOCK_RETRY_MS = 50;
|
|
9
9
|
let systemLockSequence = 0;
|
|
10
|
-
function addTaskRecord(request) {
|
|
11
|
-
return lifecycleAddTask(request.project, request.text, request.why, request.doneWhen, request.priority, request.template, request.dependsOn, request.plan);
|
|
10
|
+
async function addTaskRecord(request) {
|
|
11
|
+
return await lifecycleAddTask(request.project, request.text, request.why, request.doneWhen, request.priority, request.template, request.dependsOn, request.plan);
|
|
12
12
|
}
|
|
13
13
|
async function acquireSystemProjectLock(project) {
|
|
14
14
|
const owner = `system:${process.pid}:${++systemLockSequence}`;
|
|
15
|
-
|
|
15
|
+
// Async lock: a contended cross-process mutation lock must not park the event loop here.
|
|
16
|
+
while (!(await acquireLockAsync(project, { owner })).acquired) {
|
|
16
17
|
await new Promise((resolve) => setTimeout(resolve, SYSTEM_LOCK_RETRY_MS));
|
|
17
18
|
}
|
|
18
19
|
return owner;
|
|
19
20
|
}
|
|
20
|
-
function releaseSystemProjectLock(project, owner) {
|
|
21
|
-
const result =
|
|
21
|
+
async function releaseSystemProjectLock(project, owner) {
|
|
22
|
+
const result = await releaseLockAsync(project, owner);
|
|
22
23
|
if (!result.released)
|
|
23
24
|
throw new Error(result.message || `Failed to release project lock for ${project}`);
|
|
24
25
|
}
|
|
@@ -50,42 +51,42 @@ export class TaskMutator {
|
|
|
50
51
|
return task;
|
|
51
52
|
}
|
|
52
53
|
async claim(taskId, agent, options = {}) {
|
|
53
|
-
return this.store.runExclusive(() => {
|
|
54
|
+
return this.store.runExclusive(async () => {
|
|
54
55
|
const task = this.store.getById(taskId);
|
|
55
56
|
if (!task)
|
|
56
57
|
return { success: false, message: `Task not found: ${taskId}` };
|
|
57
|
-
const result = lifecycleClaimTask(task.text, task.project, agent, taskId, options.generation ?? null);
|
|
58
|
+
const result = await lifecycleClaimTask(task.text, task.project, agent, taskId, options.generation ?? null);
|
|
58
59
|
if (result.success) {
|
|
59
60
|
this.store.refresh();
|
|
60
|
-
this.store.commitAndPush(`task-store: claim ${taskId} by ${agent}`);
|
|
61
|
+
await this.store.commitAndPush(`task-store: claim ${taskId} by ${agent}`);
|
|
61
62
|
this.bus?.publish({ type: 'task.claimed', taskId, by: agent });
|
|
62
63
|
}
|
|
63
64
|
return result;
|
|
64
65
|
});
|
|
65
66
|
}
|
|
66
67
|
async unclaim(taskId, options = {}) {
|
|
67
|
-
return this.store.runExclusive(() => {
|
|
68
|
+
return this.store.runExclusive(async () => {
|
|
68
69
|
const task = this.store.getById(taskId);
|
|
69
70
|
if (!task)
|
|
70
71
|
return { success: false, message: `Task not found: ${taskId}` };
|
|
71
|
-
const result = lifecycleUnclaimTask(task.text, task.project, taskId, options.ownership);
|
|
72
|
+
const result = await lifecycleUnclaimTask(task.text, task.project, taskId, options.ownership);
|
|
72
73
|
if (result.success) {
|
|
73
74
|
this.store.refresh();
|
|
74
|
-
this.store.commitAndPush(`task-store: unclaim ${taskId}`);
|
|
75
|
+
await this.store.commitAndPush(`task-store: unclaim ${taskId}`);
|
|
75
76
|
this.bus?.publish({ type: 'task.unclaimed', taskId });
|
|
76
77
|
}
|
|
77
78
|
return result;
|
|
78
79
|
});
|
|
79
80
|
}
|
|
80
81
|
async complete(taskId, note, options = {}) {
|
|
81
|
-
return this.store.runExclusive(() => {
|
|
82
|
+
return this.store.runExclusive(async () => {
|
|
82
83
|
const task = this.getByIdFresh(taskId);
|
|
83
84
|
if (!task)
|
|
84
85
|
return { success: false, message: `Task not found: ${taskId}` };
|
|
85
|
-
const result = lifecycleCompleteTask(task.text, task.project, note || '', taskId, options.skipVerify ?? false, options.skipVerifyReason ?? null, options.ownership);
|
|
86
|
+
const result = await lifecycleCompleteTask(task.text, task.project, note || '', taskId, options.skipVerify ?? false, options.skipVerifyReason ?? null, options.ownership);
|
|
86
87
|
if (result.success) {
|
|
87
88
|
this.store.refresh();
|
|
88
|
-
this.store.commitAndPush(`task-store: complete ${taskId}`);
|
|
89
|
+
await this.store.commitAndPush(`task-store: complete ${taskId}`);
|
|
89
90
|
this.bus?.publish({
|
|
90
91
|
type: 'task.completed', taskId,
|
|
91
92
|
...(options.ownership ? { dispatchGeneration: options.ownership.generation } : {}),
|
|
@@ -96,27 +97,27 @@ export class TaskMutator {
|
|
|
96
97
|
});
|
|
97
98
|
}
|
|
98
99
|
async uncomplete(taskId) {
|
|
99
|
-
return this.store.runExclusive(() => {
|
|
100
|
+
return this.store.runExclusive(async () => {
|
|
100
101
|
const task = this.store.getById(taskId);
|
|
101
102
|
if (!task)
|
|
102
103
|
return { success: false, message: `Task not found: ${taskId}` };
|
|
103
|
-
const result = lifecycleUncompleteTask(task.text, task.project, taskId);
|
|
104
|
+
const result = await lifecycleUncompleteTask(task.text, task.project, taskId);
|
|
104
105
|
if (result.success) {
|
|
105
106
|
this.store.refresh();
|
|
106
|
-
this.store.commitAndPush(`task-store: uncomplete ${taskId}`);
|
|
107
|
+
await this.store.commitAndPush(`task-store: uncomplete ${taskId}`);
|
|
107
108
|
}
|
|
108
109
|
return result;
|
|
109
110
|
});
|
|
110
111
|
}
|
|
111
112
|
async block(taskId, reason, options = {}) {
|
|
112
|
-
return this.store.runExclusive(() => {
|
|
113
|
+
return this.store.runExclusive(async () => {
|
|
113
114
|
const task = this.getByIdFresh(taskId);
|
|
114
115
|
if (!task)
|
|
115
116
|
return { success: false, message: `Task not found: ${taskId}` };
|
|
116
|
-
const result = lifecycleBlockTask(task.text, task.project, reason, taskId, options.ownership);
|
|
117
|
+
const result = await lifecycleBlockTask(task.text, task.project, reason, taskId, options.ownership);
|
|
117
118
|
if (result.success) {
|
|
118
119
|
this.store.refresh();
|
|
119
|
-
this.store.commitAndPush(`task-store: block ${taskId}`);
|
|
120
|
+
await this.store.commitAndPush(`task-store: block ${taskId}`);
|
|
120
121
|
// DR-0014 §8: a blocked task is a child's escalation — wake its waiting manager.
|
|
121
122
|
this.bus?.publish({
|
|
122
123
|
type: 'task.blocked', taskId, reason,
|
|
@@ -128,93 +129,93 @@ export class TaskMutator {
|
|
|
128
129
|
});
|
|
129
130
|
}
|
|
130
131
|
async unblock(taskId) {
|
|
131
|
-
return this.store.runExclusive(() => {
|
|
132
|
+
return this.store.runExclusive(async () => {
|
|
132
133
|
const task = this.store.getById(taskId);
|
|
133
134
|
if (!task)
|
|
134
135
|
return { success: false, message: `Task not found: ${taskId}` };
|
|
135
|
-
const result = lifecycleUnblockTask(task.text, task.project, taskId);
|
|
136
|
+
const result = await lifecycleUnblockTask(task.text, task.project, taskId);
|
|
136
137
|
if (result.success) {
|
|
137
138
|
this.store.refresh();
|
|
138
|
-
this.store.commitAndPush(`task-store: unblock ${taskId}`);
|
|
139
|
+
await this.store.commitAndPush(`task-store: unblock ${taskId}`);
|
|
139
140
|
this.bus?.publish({ type: 'task.unblocked', taskId });
|
|
140
141
|
}
|
|
141
142
|
return result;
|
|
142
143
|
});
|
|
143
144
|
}
|
|
144
145
|
async pause(taskId) {
|
|
145
|
-
return this.store.runExclusive(() => {
|
|
146
|
+
return this.store.runExclusive(async () => {
|
|
146
147
|
const task = this.store.getById(taskId);
|
|
147
148
|
if (!task)
|
|
148
149
|
return { success: false, message: `Task not found: ${taskId}` };
|
|
149
|
-
const result = lifecyclePauseTask(task.text, task.project, taskId);
|
|
150
|
+
const result = await lifecyclePauseTask(task.text, task.project, taskId);
|
|
150
151
|
if (result.success) {
|
|
151
152
|
this.store.refresh();
|
|
152
|
-
this.store.commitAndPush(`task-store: pause ${taskId}`);
|
|
153
|
+
await this.store.commitAndPush(`task-store: pause ${taskId}`);
|
|
153
154
|
}
|
|
154
155
|
return result;
|
|
155
156
|
});
|
|
156
157
|
}
|
|
157
158
|
async resume(taskId) {
|
|
158
|
-
return this.store.runExclusive(() => {
|
|
159
|
+
return this.store.runExclusive(async () => {
|
|
159
160
|
const task = this.store.getById(taskId);
|
|
160
161
|
if (!task)
|
|
161
162
|
return { success: false, message: `Task not found: ${taskId}` };
|
|
162
|
-
const result = lifecycleResumeTask(task.text, task.project, taskId);
|
|
163
|
+
const result = await lifecycleResumeTask(task.text, task.project, taskId);
|
|
163
164
|
if (result.success) {
|
|
164
165
|
this.store.refresh();
|
|
165
|
-
this.store.commitAndPush(`task-store: resume ${taskId}`);
|
|
166
|
+
await this.store.commitAndPush(`task-store: resume ${taskId}`);
|
|
166
167
|
}
|
|
167
168
|
return result;
|
|
168
169
|
});
|
|
169
170
|
}
|
|
170
171
|
async requestApproval(taskId) {
|
|
171
|
-
return this.store.runExclusive(() => {
|
|
172
|
+
return this.store.runExclusive(async () => {
|
|
172
173
|
const task = this.store.getById(taskId);
|
|
173
174
|
if (!task)
|
|
174
175
|
return { success: false, message: `Task not found: ${taskId}` };
|
|
175
|
-
const result = lifecycleRequestApprovalTask(task.text, task.project, taskId);
|
|
176
|
+
const result = await lifecycleRequestApprovalTask(task.text, task.project, taskId);
|
|
176
177
|
if (result.success) {
|
|
177
178
|
this.store.refresh();
|
|
178
|
-
this.store.commitAndPush(`task-store: requestApproval ${taskId}`);
|
|
179
|
+
await this.store.commitAndPush(`task-store: requestApproval ${taskId}`);
|
|
179
180
|
}
|
|
180
181
|
return result;
|
|
181
182
|
});
|
|
182
183
|
}
|
|
183
184
|
async approve(taskId) {
|
|
184
|
-
return this.store.runExclusive(() => {
|
|
185
|
+
return this.store.runExclusive(async () => {
|
|
185
186
|
const task = this.store.getById(taskId);
|
|
186
187
|
if (!task)
|
|
187
188
|
return { success: false, message: `Task not found: ${taskId}` };
|
|
188
|
-
const result = lifecycleApproveTask(task.text, task.project, taskId);
|
|
189
|
+
const result = await lifecycleApproveTask(task.text, task.project, taskId);
|
|
189
190
|
if (result.success) {
|
|
190
191
|
this.store.refresh();
|
|
191
|
-
this.store.commitAndPush(`task-store: approve ${taskId}`);
|
|
192
|
+
await this.store.commitAndPush(`task-store: approve ${taskId}`);
|
|
192
193
|
}
|
|
193
194
|
return result;
|
|
194
195
|
});
|
|
195
196
|
}
|
|
196
197
|
async clearApproval(taskId) {
|
|
197
|
-
return this.store.runExclusive(() => {
|
|
198
|
+
return this.store.runExclusive(async () => {
|
|
198
199
|
const task = this.store.getById(taskId);
|
|
199
200
|
if (!task)
|
|
200
201
|
return { success: false, message: `Task not found: ${taskId}` };
|
|
201
|
-
const result = lifecycleClearApprovalTask(task.text, task.project, taskId);
|
|
202
|
+
const result = await lifecycleClearApprovalTask(task.text, task.project, taskId);
|
|
202
203
|
if (result.success) {
|
|
203
204
|
this.store.refresh();
|
|
204
|
-
this.store.commitAndPush(`task-store: clearApproval ${taskId}`);
|
|
205
|
+
await this.store.commitAndPush(`task-store: clearApproval ${taskId}`);
|
|
205
206
|
}
|
|
206
207
|
return result;
|
|
207
208
|
});
|
|
208
209
|
}
|
|
209
210
|
async batchEdit(project, taskIds, options) {
|
|
210
|
-
return this.store.runExclusive(() => {
|
|
211
|
+
return this.store.runExclusive(async () => {
|
|
211
212
|
const lockError = assertLockHeld(project, getOwnerIdentity());
|
|
212
213
|
if (lockError)
|
|
213
214
|
return { success: false, message: lockError };
|
|
214
|
-
const result = lifecycleBatchEdit(project, taskIds, options);
|
|
215
|
+
const result = await lifecycleBatchEdit(project, taskIds, options);
|
|
215
216
|
if (result.success) {
|
|
216
217
|
this.store.refresh();
|
|
217
|
-
this.store.commitAndPush(`task-store: batch-edit ${taskIds.length} tasks in ${project}`);
|
|
218
|
+
await this.store.commitAndPush(`task-store: batch-edit ${taskIds.length} tasks in ${project}`);
|
|
218
219
|
}
|
|
219
220
|
return result;
|
|
220
221
|
});
|
|
@@ -229,60 +230,60 @@ export class TaskMutator {
|
|
|
229
230
|
};
|
|
230
231
|
if (options.system)
|
|
231
232
|
return this.addSystemTask(request);
|
|
232
|
-
return this.store.runExclusive(() => {
|
|
233
|
+
return this.store.runExclusive(async () => {
|
|
233
234
|
const lockError = assertLockHeld(project, getOwnerIdentity());
|
|
234
235
|
if (lockError)
|
|
235
236
|
return { success: false, message: lockError };
|
|
236
|
-
const result = addTaskRecord(request);
|
|
237
|
+
const result = await addTaskRecord(request);
|
|
237
238
|
if (result.success) {
|
|
238
239
|
this.store.refresh();
|
|
239
|
-
this.store.commitAndPush(`task-store: add task to ${project}`);
|
|
240
|
+
await this.store.commitAndPush(`task-store: add task to ${project}`);
|
|
240
241
|
}
|
|
241
242
|
return result;
|
|
242
243
|
});
|
|
243
244
|
}
|
|
244
245
|
async addSystemTask(request) {
|
|
245
246
|
const owner = await acquireSystemProjectLock(request.project);
|
|
246
|
-
return this.store.runExclusive(() => {
|
|
247
|
+
return this.store.runExclusive(async () => {
|
|
247
248
|
let result;
|
|
248
249
|
try {
|
|
249
|
-
result = addTaskRecord(request);
|
|
250
|
+
result = await addTaskRecord(request);
|
|
250
251
|
}
|
|
251
252
|
finally {
|
|
252
|
-
releaseSystemProjectLock(request.project, owner);
|
|
253
|
+
await releaseSystemProjectLock(request.project, owner);
|
|
253
254
|
}
|
|
254
255
|
if (result.success) {
|
|
255
256
|
this.store.refresh();
|
|
256
|
-
this.store.commitAndPush(`task-store: add task to ${request.project}`);
|
|
257
|
+
await this.store.commitAndPush(`task-store: add task to ${request.project}`);
|
|
257
258
|
}
|
|
258
259
|
return result;
|
|
259
260
|
});
|
|
260
261
|
}
|
|
261
262
|
async edit(project, options) {
|
|
262
|
-
return this.store.runExclusive(() => {
|
|
263
|
+
return this.store.runExclusive(async () => {
|
|
263
264
|
const lockError = assertLockHeld(project, getOwnerIdentity());
|
|
264
265
|
if (lockError)
|
|
265
266
|
return { success: false, message: lockError };
|
|
266
|
-
const result = lifecycleEditTask(project, options);
|
|
267
|
+
const result = await lifecycleEditTask(project, options);
|
|
267
268
|
if (result.success) {
|
|
268
269
|
this.store.refresh();
|
|
269
|
-
this.store.commitAndPush(`task-store: edit task in ${project}`);
|
|
270
|
+
await this.store.commitAndPush(`task-store: edit task in ${project}`);
|
|
270
271
|
}
|
|
271
272
|
return result;
|
|
272
273
|
});
|
|
273
274
|
}
|
|
274
275
|
async decompose(project, taskText, subtasks, taskId, options = {}) {
|
|
275
|
-
return this.store.runExclusive(() => {
|
|
276
|
+
return this.store.runExclusive(async () => {
|
|
276
277
|
const lockError = decomposeLockError(project, options);
|
|
277
278
|
if (lockError)
|
|
278
279
|
return { success: false, message: lockError };
|
|
279
|
-
const result = lifecycleDecomposeTask(project, taskText, subtasks, taskId || null, {
|
|
280
|
+
const result = await lifecycleDecomposeTask(project, taskText, subtasks, taskId || null, {
|
|
280
281
|
keepParent: options.keepParent,
|
|
281
282
|
ownership: options.ownership,
|
|
282
283
|
});
|
|
283
284
|
if (result.success) {
|
|
284
285
|
this.store.refresh();
|
|
285
|
-
this.store.commitAndPush(`task-store: decompose task in ${project}${options.keepParent ? ' (keep-parent)' : ''}`);
|
|
286
|
+
await this.store.commitAndPush(`task-store: decompose task in ${project}${options.keepParent ? ' (keep-parent)' : ''}`);
|
|
286
287
|
}
|
|
287
288
|
return result;
|
|
288
289
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type TaskGenerationExpectation } from '../../../core/task-parser.js';
|
|
2
|
-
declare function completeTaskUnlocked(taskText: string | null, project: string, completionNote?: string, taskId?: string | null, skipVerify?: boolean, skipVerifyReason?: string | null, ownership?: TaskGenerationExpectation): {
|
|
2
|
+
declare function completeTaskUnlocked(taskText: string | null, project: string, completionNote?: string, taskId?: string | null, skipVerify?: boolean, skipVerifyReason?: string | null, ownership?: TaskGenerationExpectation, precomputedEvidence?: boolean | null): {
|
|
3
3
|
success: boolean;
|
|
4
4
|
message: string;
|
|
5
5
|
stale?: undefined;
|
|
@@ -36,4 +36,9 @@ declare function uncompleteTaskUnlocked(taskText: string | null, project: string
|
|
|
36
36
|
};
|
|
37
37
|
declare const completeTask: typeof completeTaskUnlocked;
|
|
38
38
|
declare const uncompleteTask: typeof uncompleteTaskUnlocked;
|
|
39
|
-
|
|
39
|
+
/** Async twin of `completeTask` for the server's completion path: the evidence probes
|
|
40
|
+
* (`git cat-file` / `git log`) run through runFile instead of execFileSync, so completing a task
|
|
41
|
+
* no longer stalls every session in the process. The sync export stays for the CLI and tests. */
|
|
42
|
+
declare function completeTaskAsync(taskText: string | null, project: string, completionNote?: string, taskId?: string | null, skipVerify?: boolean, skipVerifyReason?: string | null, ownership?: TaskGenerationExpectation): Promise<ReturnType<typeof completeTaskUnlocked>>;
|
|
43
|
+
declare function uncompleteTaskAsync(taskText: string | null, project: string, taskId?: string | null, ownership?: TaskGenerationExpectation): Promise<ReturnType<typeof uncompleteTaskUnlocked>>;
|
|
44
|
+
export { completeTask, completeTaskAsync, uncompleteTask, uncompleteTaskAsync };
|
|
@@ -2,7 +2,8 @@ import * as fs from 'node:fs';
|
|
|
2
2
|
import * as path from 'node:path';
|
|
3
3
|
import { execFileSync } from 'node:child_process';
|
|
4
4
|
import { DATA_DIR, INSTALL_ROOT, PROJECTS_DIR, STORE_DIR, WORKSPACE_DIR } from '../../../core/utils.js';
|
|
5
|
-
import {
|
|
5
|
+
import { runFile } from '../../../core/exec-async.js';
|
|
6
|
+
import { clearDependsOnAll, findTask, getTasksPath, readTasks, taskFileProjects, withTaskFileMutationLock, withTaskFileMutationLockAsync, withTaskFileMutationLocks, withTaskFileMutationLocksAsync, writeTasks, } from './task-lifecycle-edit.js';
|
|
6
7
|
const EXPLICIT_SHA = /\b(?:implementation\s+sha|commit(?:\s+sha)?|sha)\s*[:=#]?\s*`?([0-9a-f]{7,40})(?![0-9a-f])`?/gi;
|
|
7
8
|
function runGit(repo, args, input) {
|
|
8
9
|
try {
|
|
@@ -14,6 +15,14 @@ function runGit(repo, args, input) {
|
|
|
14
15
|
return null;
|
|
15
16
|
}
|
|
16
17
|
}
|
|
18
|
+
/** Async twin of `runGit`: same argv, same 5s timeout, no event-loop block. The server's
|
|
19
|
+
* completion path uses this; the CLI keeps the synchronous original. */
|
|
20
|
+
async function runGitAsync(repo, args, input) {
|
|
21
|
+
const result = await runFile('git', ['-C', repo, ...args], { timeoutMs: 5000, stdin: input });
|
|
22
|
+
if (!result.ok)
|
|
23
|
+
return null;
|
|
24
|
+
return result.stdout.trim();
|
|
25
|
+
}
|
|
17
26
|
function extractExplicitShas(note) {
|
|
18
27
|
const shas = [...note.matchAll(EXPLICIT_SHA)].map((match) => match[1].toLowerCase());
|
|
19
28
|
return [...new Set(shas)];
|
|
@@ -133,13 +142,46 @@ function loadCompletionTask(taskText, project, taskId) {
|
|
|
133
142
|
const found = findTask(tasks, taskText, taskId);
|
|
134
143
|
return 'error' in found ? found : { tasks, task: found.task };
|
|
135
144
|
}
|
|
136
|
-
function completionWarning(project, task, completionNote, skipVerify, skipVerifyReason) {
|
|
145
|
+
function completionWarning(project, task, completionNote, skipVerify, skipVerifyReason, precomputedEvidence = null) {
|
|
137
146
|
if (skipVerify)
|
|
138
147
|
return `verify skipped: ${skipVerifyReason ?? 'no reason given'}`;
|
|
139
|
-
|
|
148
|
+
const verified = precomputedEvidence ?? verifyCompletionEvidence(project, task.id, task.done_when, completionNote);
|
|
149
|
+
if (verified)
|
|
140
150
|
return null;
|
|
141
151
|
return 'no evidence of work: no verified implementation SHA, persisted thread artifact, matching git commit, or Done-when artifact. Re-run with --skip-verify to bypass.';
|
|
142
152
|
}
|
|
153
|
+
/** Async twin of `verifyCompletionEvidence` for callers that must not block on git. Same order and
|
|
154
|
+
* same short-circuiting as the sync version, so both reach the same verdict. */
|
|
155
|
+
async function verifyCompletionEvidenceAsync(project, taskId, doneWhen, completionNote) {
|
|
156
|
+
if (await hasVerifiedImplementationShaAsync(completionNote, project))
|
|
157
|
+
return true;
|
|
158
|
+
if (hasCompletionArtifact(project, taskId))
|
|
159
|
+
return true;
|
|
160
|
+
if (await hasTaskCommitAsync(taskId))
|
|
161
|
+
return true;
|
|
162
|
+
return hasDoneWhenArtifact(doneWhen);
|
|
163
|
+
}
|
|
164
|
+
async function hasVerifiedImplementationShaAsync(note, project) {
|
|
165
|
+
const refs = extractExplicitShas(note).map((sha) => `${sha}^{commit}`);
|
|
166
|
+
if (refs.length === 0)
|
|
167
|
+
return false;
|
|
168
|
+
const repos = [...new Set([process.cwd(), INSTALL_ROOT, DATA_DIR, ...readConfiguredProjectRepos(project)])];
|
|
169
|
+
for (const repo of repos) {
|
|
170
|
+
const out = await runGitAsync(repo, ['cat-file', '--batch-check=%(objecttype)'], `${refs.join('\n')}\n`);
|
|
171
|
+
if (out !== null && out.split('\n').includes('commit'))
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
async function hasTaskCommitAsync(taskId) {
|
|
177
|
+
if (!taskId)
|
|
178
|
+
return false;
|
|
179
|
+
const out = await runGitAsync(DATA_DIR, ['log', '--oneline', `--grep=${taskId}`]);
|
|
180
|
+
if (out === null)
|
|
181
|
+
return false;
|
|
182
|
+
return out.split('\n').filter(Boolean)
|
|
183
|
+
.some((line) => !/task-store:\s+(claim|unclaim)/i.test(line));
|
|
184
|
+
}
|
|
143
185
|
function markTaskCompleted(task, completionNote, completedAt, ownership) {
|
|
144
186
|
task.status = 'done';
|
|
145
187
|
task.claimed_by = null;
|
|
@@ -152,7 +194,7 @@ function markTaskCompleted(task, completionNote, completedAt, ownership) {
|
|
|
152
194
|
task.completed_at = completedAt;
|
|
153
195
|
task.completed_note = completionNote || null;
|
|
154
196
|
}
|
|
155
|
-
function completeTaskUnlocked(taskText, project, completionNote = '', taskId = null, skipVerify = false, skipVerifyReason = null, ownership) {
|
|
197
|
+
function completeTaskUnlocked(taskText, project, completionNote = '', taskId = null, skipVerify = false, skipVerifyReason = null, ownership, precomputedEvidence = null) {
|
|
156
198
|
const loaded = loadCompletionTask(taskText, project, taskId);
|
|
157
199
|
if ('error' in loaded)
|
|
158
200
|
return { success: false, message: loaded.error };
|
|
@@ -163,7 +205,7 @@ function completeTaskUnlocked(taskText, project, completionNote = '', taskId = n
|
|
|
163
205
|
const stateError = completionStateError(task);
|
|
164
206
|
if (stateError)
|
|
165
207
|
return { success: false, message: stateError };
|
|
166
|
-
const verifyWarning = completionWarning(project, task, completionNote, skipVerify, skipVerifyReason);
|
|
208
|
+
const verifyWarning = completionWarning(project, task, completionNote, skipVerify, skipVerifyReason, precomputedEvidence);
|
|
167
209
|
const completedAt = new Date().toISOString();
|
|
168
210
|
const today = completedAt.slice(0, 10);
|
|
169
211
|
markTaskCompleted(task, completionNote, completedAt, ownership);
|
|
@@ -202,4 +244,25 @@ function lockCompletionMutation(mutation) {
|
|
|
202
244
|
}
|
|
203
245
|
const completeTask = ((...args) => withTaskFileMutationLocks([...taskFileProjects(), args[1]], () => completeTaskUnlocked(...args)));
|
|
204
246
|
const uncompleteTask = lockCompletionMutation(uncompleteTaskUnlocked);
|
|
205
|
-
|
|
247
|
+
/** Async twin of `completeTask` for the server's completion path: the evidence probes
|
|
248
|
+
* (`git cat-file` / `git log`) run through runFile instead of execFileSync, so completing a task
|
|
249
|
+
* no longer stalls every session in the process. The sync export stays for the CLI and tests. */
|
|
250
|
+
async function completeTaskAsync(taskText, project, completionNote = '', taskId = null, skipVerify = false, skipVerifyReason = null, ownership) {
|
|
251
|
+
return withTaskFileMutationLocksAsync([...taskFileProjects(), project], async () => {
|
|
252
|
+
// Probe the (read-only) evidence while holding the mutation lock — same window as the sync
|
|
253
|
+
// path, which runs execFileSync there — but without parking the event loop. A failed pre-read
|
|
254
|
+
// passes null, and completeTaskUnlocked then returns its own load error before verifying.
|
|
255
|
+
let precomputedEvidence = null;
|
|
256
|
+
if (!skipVerify) {
|
|
257
|
+
const loaded = loadCompletionTask(taskText, project, taskId);
|
|
258
|
+
if (!('error' in loaded)) {
|
|
259
|
+
precomputedEvidence = await verifyCompletionEvidenceAsync(project, loaded.task.id, loaded.task.done_when, completionNote);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return completeTaskUnlocked(taskText, project, completionNote, taskId, skipVerify, skipVerifyReason, ownership, precomputedEvidence);
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
async function uncompleteTaskAsync(taskText, project, taskId = null, ownership) {
|
|
266
|
+
return withTaskFileMutationLockAsync(project, async () => uncompleteTaskUnlocked(taskText, project, taskId, ownership));
|
|
267
|
+
}
|
|
268
|
+
export { completeTask, completeTaskAsync, uncompleteTask, uncompleteTaskAsync };
|
|
@@ -3,6 +3,9 @@ declare function withTaskFileMutationLock<T>(project: string, mutate: () => T):
|
|
|
3
3
|
declare function withTaskFileMutationLocks<T>(projects: string[], mutate: () => T): T;
|
|
4
4
|
declare function taskFileProjects(): string[];
|
|
5
5
|
declare function withTaskFileMutationLockAsync<T>(project: string, mutate: () => Promise<T>): Promise<T>;
|
|
6
|
+
/** Multi-project async twin of `withTaskFileMutationLocks`: acquires in sorted order and releases
|
|
7
|
+
* in reverse, so cross-project mutations cannot deadlock against each other. */
|
|
8
|
+
declare function withTaskFileMutationLocksAsync<T>(projects: string[], mutate: () => Promise<T>): Promise<T>;
|
|
6
9
|
declare function sweepTaskOrphans(tasksPath: string): void;
|
|
7
10
|
declare const VALID_PRIORITIES: Set<string>;
|
|
8
11
|
declare function _resetTemplateNameCacheForTests(): void;
|
|
@@ -34,5 +37,7 @@ type TaskLineTransformResult = {
|
|
|
34
37
|
message: string;
|
|
35
38
|
};
|
|
36
39
|
declare const editTask: (project: string, options?: any) => TaskLineTransformResult;
|
|
37
|
-
|
|
40
|
+
/** Async twin of `editTask` for the server's per-message edit path. */
|
|
41
|
+
declare const editTaskAsync: (project: string, options?: any) => Promise<TaskLineTransformResult>;
|
|
42
|
+
export { VALID_PRIORITIES, _resetTemplateNameCacheForTests, clearDependsOnAll, editTask, editTaskAsync, findTask, findTaskById, getTasksPath, readTasks, sweepTaskOrphans, taskFileProjects, validateTemplateName, withTaskFileMutationLock, withTaskFileMutationLockAsync, withTaskFileMutationLocks, withTaskFileMutationLocksAsync, writeTasks, };
|
|
38
43
|
export type { TaskLineTransformResult };
|
|
@@ -209,6 +209,23 @@ async function withTaskFileMutationLockAsync(project, mutate) {
|
|
|
209
209
|
release();
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
|
+
/** Multi-project async twin of `withTaskFileMutationLocks`: acquires in sorted order and releases
|
|
213
|
+
* in reverse, so cross-project mutations cannot deadlock against each other. */
|
|
214
|
+
async function withTaskFileMutationLocksAsync(projects, mutate) {
|
|
215
|
+
const existing = [...new Set(projects)]
|
|
216
|
+
.filter((project) => fs.existsSync(getTasksPath(project)))
|
|
217
|
+
.sort();
|
|
218
|
+
const releases = [];
|
|
219
|
+
try {
|
|
220
|
+
for (const project of existing)
|
|
221
|
+
releases.push(await acquireTaskFileMutationLockAsync(project));
|
|
222
|
+
return await mutate();
|
|
223
|
+
}
|
|
224
|
+
finally {
|
|
225
|
+
for (const release of releases.reverse())
|
|
226
|
+
release();
|
|
227
|
+
}
|
|
228
|
+
}
|
|
212
229
|
function sweepTaskOrphans(tasksPath) {
|
|
213
230
|
try {
|
|
214
231
|
const dir = path.dirname(tasksPath);
|
|
@@ -251,7 +268,7 @@ function _resetTemplateNameCacheForTests() {
|
|
|
251
268
|
}
|
|
252
269
|
function validateTemplateName(name) {
|
|
253
270
|
if (FORBIDDEN_TEMPLATES.has(name)) {
|
|
254
|
-
return `Template '${name}' is forbidden. The 'default' and 'scheduler' templates are single-agent templates with no review pipeline and are not allowed for task dispatch. Use a multi-agent review template instead (e.g. stage-gate, coder-review,
|
|
271
|
+
return `Template '${name}' is forbidden. The 'default' and 'scheduler' templates are single-agent templates with no review pipeline and are not allowed for task dispatch. Use a multi-agent review template instead (e.g. stage-gate, coder-review, execute-review).`;
|
|
255
272
|
}
|
|
256
273
|
const valid = getValidTemplateNames();
|
|
257
274
|
if (valid.size === 0)
|
|
@@ -400,7 +417,9 @@ function editTaskUnlocked(project, options = {}) {
|
|
|
400
417
|
return { success: true, message: 'Task updated', task_id: taskId, updated_fields: updatedFields };
|
|
401
418
|
}
|
|
402
419
|
const editTask = (project, options = {}) => withTaskFileMutationLock(project, () => editTaskUnlocked(project, options));
|
|
420
|
+
/** Async twin of `editTask` for the server's per-message edit path. */
|
|
421
|
+
const editTaskAsync = async (project, options = {}) => withTaskFileMutationLockAsync(project, async () => editTaskUnlocked(project, options));
|
|
403
422
|
// Base of the TASKS.yaml write path: this module owns the file I/O and the line-level primitives;
|
|
404
423
|
// task-state / task-completion / task-mutations / task-process build on top of it. There is no
|
|
405
424
|
// barrel for this folder on purpose — task-store.ts and the CLI import each sub-module directly.
|
|
406
|
-
export { VALID_PRIORITIES, _resetTemplateNameCacheForTests, clearDependsOnAll, editTask, findTask, findTaskById, getTasksPath, readTasks, sweepTaskOrphans, taskFileProjects, validateTemplateName, withTaskFileMutationLock, withTaskFileMutationLockAsync, withTaskFileMutationLocks, writeTasks, };
|
|
425
|
+
export { VALID_PRIORITIES, _resetTemplateNameCacheForTests, clearDependsOnAll, editTask, editTaskAsync, findTask, findTaskById, getTasksPath, readTasks, sweepTaskOrphans, taskFileProjects, validateTemplateName, withTaskFileMutationLock, withTaskFileMutationLockAsync, withTaskFileMutationLocks, withTaskFileMutationLocksAsync, writeTasks, };
|