@ornexus/neocortex 4.60.80 → 4.61.0
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/release-source.json +1 -1
- package/dist/sbom.cdx.json +1193 -1193
- package/install.ps1 +33 -1
- package/install.sh +35 -1
- package/package.json +2 -2
- package/packages/client/dist/adapters/platform-detector.d.ts +1 -1
- package/packages/client/dist/adapters/platform-detector.js +6 -0
- package/packages/client/dist/cli.js +7 -0
- package/packages/client/dist/commands/invoke.d.ts +15 -8
- package/packages/client/dist/commands/invoke.js +69 -0
- package/packages/client/dist/commands/story-checkpoint.d.ts +2 -1
- package/packages/client/dist/commands/story-checkpoint.js +34 -2
- package/packages/client/dist/commands/story-worktree.d.ts +46 -0
- package/packages/client/dist/commands/story-worktree.js +258 -0
- package/packages/client/dist/config.js +1 -0
- package/packages/client/dist/git/direct-yolo-checkpoint.d.ts +46 -0
- package/packages/client/dist/git/direct-yolo-checkpoint.js +137 -1
- package/packages/client/dist/git/git-lifecycle-store.d.ts +82 -0
- package/packages/client/dist/git/git-lifecycle-store.js +313 -5
- package/packages/client/dist/git/story-worktree-cleanup.d.ts +226 -0
- package/packages/client/dist/git/story-worktree-cleanup.js +1058 -0
- package/packages/client/dist/git/story-worktree-integration.d.ts +91 -0
- package/packages/client/dist/git/story-worktree-integration.js +603 -0
- package/packages/client/dist/git/story-worktree-manager.d.ts +205 -0
- package/packages/client/dist/git/story-worktree-manager.js +843 -0
- package/packages/client/dist/git/story-worktree-paths.d.ts +65 -0
- package/packages/client/dist/git/story-worktree-paths.js +150 -0
- package/packages/client/dist/policy/subagent-approval-policy.js +3 -1
- package/packages/client/dist/runner/headless/continuous-story-workspace.d.ts +49 -1
- package/packages/client/dist/runner/headless/continuous-story-workspace.js +175 -27
- package/packages/client/dist/runner/headless/run-yoloop.d.ts +39 -0
- package/packages/client/dist/runner/headless/run-yoloop.js +71 -0
- package/packages/client/dist/runner-cli.js +0 -0
- package/packages/shared/dist/yoloop/epic-terminal-git.js +27 -3
- package/targets-stubs/antigravity/gemini.md +1 -1
- package/targets-stubs/antigravity/neocortex.md +21 -0
- package/targets-stubs/antigravity/skill/SKILL.md +1 -1
- package/targets-stubs/claude-code/README.md +17 -0
- package/targets-stubs/claude-code/neocortex-root.agent.yaml +1 -1
- package/targets-stubs/claude-code/neocortex-root.md +57 -49
- package/targets-stubs/claude-code/neocortex.agent.yaml +1 -1
- package/targets-stubs/claude-code/neocortex.md +28 -25
- package/targets-stubs/codex/AGENTS.md +31 -30
- package/targets-stubs/codex/neocortex.toml +10 -0
- package/targets-stubs/cursor/agent.md +13 -2
- package/targets-stubs/deepseek-harness/SKILL.md +13 -0
- package/targets-stubs/gemini-cli/agent.md +23 -2
- package/targets-stubs/grok/SKILL.md +21 -0
- package/targets-stubs/kimi/neocortex.md +21 -0
- package/targets-stubs/openclaw/SKILL.md +21 -0
- package/targets-stubs/opencode/neocortex-root.md +19 -15
- package/targets-stubs/opencode/neocortex.md +10 -0
- package/targets-stubs/vscode/neocortex.agent.md +13 -2
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license FSL-1.1
|
|
3
|
+
* Copyright (c) 2026 OrNexus AI
|
|
4
|
+
*
|
|
5
|
+
* This file is part of Neocortex CLI, licensed under the
|
|
6
|
+
* Functional Source License, Version 1.1 (FSL-1.1).
|
|
7
|
+
*
|
|
8
|
+
* Change Date: February 20, 2029
|
|
9
|
+
* Change License: MIT
|
|
10
|
+
*
|
|
11
|
+
* See the LICENSE file in the project root for full license text.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* P225.05 -- `neocortex-client story-worktree` (P225-CON-WORKTREE).
|
|
15
|
+
* P225.06 -- `cleanup`, `recover`, `record-push` and `--dry-run`.
|
|
16
|
+
*
|
|
17
|
+
* Closed argument grammar; stdout is public-safe JSON (opaque IDs, SHAs,
|
|
18
|
+
* repository-relative paths, reason codes). The private absolute worktree path
|
|
19
|
+
* is written only to an explicit new `--path-file` (0600), never printed.
|
|
20
|
+
* Exit codes: 0 success, 1 refused, 2 invalid arguments.
|
|
21
|
+
*/
|
|
22
|
+
import { readFile, stat, writeFile } from 'node:fs/promises';
|
|
23
|
+
import { dirname, isAbsolute, resolve } from 'node:path';
|
|
24
|
+
import { STORY_WORKTREE_CLEANUP_TRIGGERS, StoryWorktreeCleanup, } from '../git/story-worktree-cleanup.js';
|
|
25
|
+
import { StoryWorktreeManager } from '../git/story-worktree-manager.js';
|
|
26
|
+
export const STORY_WORKTREE_ACTIONS = Object.freeze([
|
|
27
|
+
'create', 'adopt', 'sync', 'status', 'release', 'cleanup', 'recover', 'record-push',
|
|
28
|
+
]);
|
|
29
|
+
/** Triggers accepted by `cleanup`; `orphan-recovery` is reserved to `recover`. */
|
|
30
|
+
const CLI_CLEANUP_TRIGGERS = STORY_WORKTREE_CLEANUP_TRIGGERS
|
|
31
|
+
.filter((trigger) => trigger !== 'orphan-recovery');
|
|
32
|
+
const VALUE_FLAGS = Object.freeze({
|
|
33
|
+
'--project-root': 'projectRoot',
|
|
34
|
+
'--format': 'format',
|
|
35
|
+
'--epic': 'epicId',
|
|
36
|
+
'--story': 'storyId',
|
|
37
|
+
'--dispatch': 'dispatchId',
|
|
38
|
+
'--base-sha': 'baseSha',
|
|
39
|
+
'--graph-revision': 'graphRevision',
|
|
40
|
+
'--owner': 'ownerId',
|
|
41
|
+
'--lease': 'leaseId',
|
|
42
|
+
'--sha': 'sha',
|
|
43
|
+
'--directive-file': 'directiveFile',
|
|
44
|
+
'--worktree-path': 'worktreePath',
|
|
45
|
+
'--path-file': 'pathFile',
|
|
46
|
+
'--trigger': 'trigger',
|
|
47
|
+
'--remote': 'remote',
|
|
48
|
+
});
|
|
49
|
+
const BOOLEAN_FLAGS = Object.freeze({
|
|
50
|
+
'--dry-run': 'dryRun',
|
|
51
|
+
});
|
|
52
|
+
const REQUIRED = Object.freeze({
|
|
53
|
+
create: ['epicId', 'storyId', 'dispatchId', 'baseSha', 'graphRevision'],
|
|
54
|
+
adopt: ['epicId', 'storyId', 'dispatchId', 'baseSha', 'graphRevision', 'worktreePath'],
|
|
55
|
+
sync: ['leaseId'],
|
|
56
|
+
status: [],
|
|
57
|
+
release: ['leaseId'],
|
|
58
|
+
cleanup: ['leaseId', 'trigger'],
|
|
59
|
+
recover: [],
|
|
60
|
+
'record-push': ['leaseId', 'remote'],
|
|
61
|
+
});
|
|
62
|
+
const ALLOWED = Object.freeze({
|
|
63
|
+
create: [...REQUIRED.create, 'ownerId', 'pathFile'],
|
|
64
|
+
adopt: [...REQUIRED.adopt, 'ownerId', 'pathFile'],
|
|
65
|
+
sync: ['leaseId', 'sha', 'directiveFile'],
|
|
66
|
+
status: ['leaseId', 'epicId'],
|
|
67
|
+
release: ['leaseId'],
|
|
68
|
+
cleanup: ['leaseId', 'trigger', 'dryRun'],
|
|
69
|
+
recover: ['epicId', 'dryRun'],
|
|
70
|
+
'record-push': ['leaseId', 'remote'],
|
|
71
|
+
});
|
|
72
|
+
export class StoryWorktreeArgumentError extends Error {
|
|
73
|
+
reasonCode;
|
|
74
|
+
constructor(reasonCode) {
|
|
75
|
+
super(reasonCode);
|
|
76
|
+
this.reasonCode = reasonCode;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export function parseStoryWorktreeArgs(args, cwd = process.cwd()) {
|
|
80
|
+
const action = args[0];
|
|
81
|
+
if (!STORY_WORKTREE_ACTIONS.includes(action))
|
|
82
|
+
throw new StoryWorktreeArgumentError('story-worktree-action-invalid');
|
|
83
|
+
const values = {};
|
|
84
|
+
for (let index = 1; index < args.length; index++) {
|
|
85
|
+
const arg = args[index];
|
|
86
|
+
const booleanKey = BOOLEAN_FLAGS[arg];
|
|
87
|
+
if (booleanKey) {
|
|
88
|
+
if (values[booleanKey] !== undefined)
|
|
89
|
+
throw new StoryWorktreeArgumentError('story-worktree-argument-invalid');
|
|
90
|
+
values[booleanKey] = 'true';
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
const equals = arg.indexOf('=');
|
|
94
|
+
const flag = equals > 0 ? arg.slice(0, equals) : arg;
|
|
95
|
+
const key = VALUE_FLAGS[flag];
|
|
96
|
+
if (!key)
|
|
97
|
+
throw new StoryWorktreeArgumentError('story-worktree-argument-invalid');
|
|
98
|
+
const value = equals > 0 ? arg.slice(equals + 1) : args[++index];
|
|
99
|
+
if (value === undefined || value === '' || values[key] !== undefined) {
|
|
100
|
+
throw new StoryWorktreeArgumentError('story-worktree-argument-invalid');
|
|
101
|
+
}
|
|
102
|
+
values[key] = value;
|
|
103
|
+
}
|
|
104
|
+
const typedAction = action;
|
|
105
|
+
const allowed = new Set([...ALLOWED[typedAction], 'projectRoot', 'format']);
|
|
106
|
+
if (Object.keys(values).some((key) => !allowed.has(key)))
|
|
107
|
+
throw new StoryWorktreeArgumentError('story-worktree-option-invalid');
|
|
108
|
+
if (REQUIRED[typedAction].some((key) => values[key] === undefined)) {
|
|
109
|
+
throw new StoryWorktreeArgumentError('story-worktree-option-required');
|
|
110
|
+
}
|
|
111
|
+
if (typedAction === 'sync' && (values.sha === undefined) === (values.directiveFile === undefined)) {
|
|
112
|
+
throw new StoryWorktreeArgumentError('story-worktree-sync-source-invalid');
|
|
113
|
+
}
|
|
114
|
+
if (typedAction === 'status' && (values.leaseId === undefined) === (values.epicId === undefined)) {
|
|
115
|
+
throw new StoryWorktreeArgumentError('story-worktree-status-selector-invalid');
|
|
116
|
+
}
|
|
117
|
+
if (typedAction === 'cleanup' && !CLI_CLEANUP_TRIGGERS.includes(values.trigger)) {
|
|
118
|
+
throw new StoryWorktreeArgumentError('story-worktree-trigger-invalid');
|
|
119
|
+
}
|
|
120
|
+
const format = values.format ?? 'json';
|
|
121
|
+
if (format !== 'json' && format !== 'plain')
|
|
122
|
+
throw new StoryWorktreeArgumentError('story-worktree-format-invalid');
|
|
123
|
+
for (const key of ['directiveFile', 'worktreePath', 'pathFile']) {
|
|
124
|
+
if (values[key] !== undefined && !isAbsolute(values[key]))
|
|
125
|
+
throw new StoryWorktreeArgumentError('story-worktree-path-argument-invalid');
|
|
126
|
+
}
|
|
127
|
+
const { dryRun, ...stringValues } = values;
|
|
128
|
+
return {
|
|
129
|
+
...stringValues,
|
|
130
|
+
...(dryRun ? { dryRun: true } : {}),
|
|
131
|
+
action: typedAction,
|
|
132
|
+
projectRoot: resolve(cwd, values.projectRoot ?? '.'),
|
|
133
|
+
format,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
async function assertPathFileWritable(path) {
|
|
137
|
+
try {
|
|
138
|
+
await stat(path);
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
try {
|
|
142
|
+
if ((await stat(dirname(path))).isDirectory())
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
// fall through
|
|
147
|
+
}
|
|
148
|
+
throw new StoryWorktreeArgumentError('story-worktree-path-file-invalid');
|
|
149
|
+
}
|
|
150
|
+
throw new StoryWorktreeArgumentError('story-worktree-path-file-exists');
|
|
151
|
+
}
|
|
152
|
+
/** Execute one parsed command and return the public payload plus exit code. */
|
|
153
|
+
export async function runStoryWorktreeCommand(options, manager = new StoryWorktreeManager({ projectRoot: options.projectRoot }), cleanup = new StoryWorktreeCleanup({ projectRoot: options.projectRoot, manager })) {
|
|
154
|
+
if (options.pathFile)
|
|
155
|
+
await assertPathFileWritable(options.pathFile);
|
|
156
|
+
let result;
|
|
157
|
+
switch (options.action) {
|
|
158
|
+
case 'create':
|
|
159
|
+
result = await manager.create({
|
|
160
|
+
epicId: options.epicId, storyId: options.storyId, dispatchId: options.dispatchId,
|
|
161
|
+
baseSha: options.baseSha, graphRevision: options.graphRevision,
|
|
162
|
+
...(options.ownerId ? { ownerId: options.ownerId } : {}),
|
|
163
|
+
});
|
|
164
|
+
break;
|
|
165
|
+
case 'adopt':
|
|
166
|
+
result = await manager.adopt({
|
|
167
|
+
epicId: options.epicId, storyId: options.storyId, dispatchId: options.dispatchId,
|
|
168
|
+
baseSha: options.baseSha, graphRevision: options.graphRevision, worktreePath: options.worktreePath,
|
|
169
|
+
...(options.ownerId ? { ownerId: options.ownerId } : {}),
|
|
170
|
+
});
|
|
171
|
+
break;
|
|
172
|
+
case 'sync': {
|
|
173
|
+
let directive;
|
|
174
|
+
if (options.directiveFile) {
|
|
175
|
+
try {
|
|
176
|
+
directive = JSON.parse(await readFile(options.directiveFile, 'utf8'));
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
return { exitCode: 1, payload: { action: 'sync', ok: false, reasonCode: 'story-worktree-directive-invalid' } };
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
result = await manager.sync({
|
|
183
|
+
leaseId: options.leaseId,
|
|
184
|
+
...(options.sha ? { integratedSha: options.sha } : {}),
|
|
185
|
+
...(directive !== undefined ? { directive } : {}),
|
|
186
|
+
});
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
case 'status':
|
|
190
|
+
result = await manager.status(options.leaseId ? { leaseId: options.leaseId } : { epicId: options.epicId });
|
|
191
|
+
break;
|
|
192
|
+
case 'release':
|
|
193
|
+
result = await manager.release({ leaseId: options.leaseId });
|
|
194
|
+
break;
|
|
195
|
+
case 'cleanup':
|
|
196
|
+
result = await cleanup.cleanup({
|
|
197
|
+
leaseId: options.leaseId, trigger: options.trigger,
|
|
198
|
+
...(options.dryRun ? { dryRun: true } : {}),
|
|
199
|
+
});
|
|
200
|
+
break;
|
|
201
|
+
case 'recover':
|
|
202
|
+
result = await cleanup.sweep({
|
|
203
|
+
...(options.epicId ? { epicId: options.epicId } : {}), ...(options.dryRun ? { dryRun: true } : {}),
|
|
204
|
+
});
|
|
205
|
+
break;
|
|
206
|
+
case 'record-push':
|
|
207
|
+
result = await cleanup.recordPush({ leaseId: options.leaseId, remote: options.remote });
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
if (!result.ok) {
|
|
211
|
+
return {
|
|
212
|
+
exitCode: 1,
|
|
213
|
+
payload: {
|
|
214
|
+
action: options.action, ok: false, reasonCode: result.reasonCode,
|
|
215
|
+
...(result.conflictPaths ? { conflictPaths: result.conflictPaths } : {}),
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
if (options.pathFile && result.privatePath) {
|
|
220
|
+
try {
|
|
221
|
+
await writeFile(options.pathFile, `${result.privatePath}\n`, { flag: 'wx', mode: 0o600 });
|
|
222
|
+
}
|
|
223
|
+
catch {
|
|
224
|
+
return { exitCode: 1, payload: { action: options.action, ok: false, reasonCode: 'story-worktree-path-file-invalid' } };
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return { exitCode: 0, payload: { action: options.action, ok: true, value: result.value } };
|
|
228
|
+
}
|
|
229
|
+
function render(payload, format) {
|
|
230
|
+
if (format === 'json')
|
|
231
|
+
return JSON.stringify(payload, null, 2);
|
|
232
|
+
const parts = [`story-worktree ${String(payload.action)}: ${payload.ok ? 'ok' : 'refused'}`];
|
|
233
|
+
if (payload.reasonCode)
|
|
234
|
+
parts.push(`reason=${String(payload.reasonCode)}`);
|
|
235
|
+
return parts.join(' ');
|
|
236
|
+
}
|
|
237
|
+
export async function storyWorktreeCliHandler(args) {
|
|
238
|
+
let options;
|
|
239
|
+
try {
|
|
240
|
+
options = parseStoryWorktreeArgs(args);
|
|
241
|
+
}
|
|
242
|
+
catch (error) {
|
|
243
|
+
const reasonCode = error instanceof StoryWorktreeArgumentError ? error.reasonCode : 'story-worktree-argument-invalid';
|
|
244
|
+
const action = STORY_WORKTREE_ACTIONS.includes(args[0]) ? args[0] : null;
|
|
245
|
+
process.stdout.write(`${JSON.stringify({ action, ok: false, reasonCode })}\n`);
|
|
246
|
+
return 2;
|
|
247
|
+
}
|
|
248
|
+
try {
|
|
249
|
+
const { exitCode, payload } = await runStoryWorktreeCommand(options);
|
|
250
|
+
process.stdout.write(`${render(payload, options.format)}\n`);
|
|
251
|
+
return exitCode;
|
|
252
|
+
}
|
|
253
|
+
catch (error) {
|
|
254
|
+
const reasonCode = error instanceof StoryWorktreeArgumentError ? error.reasonCode : 'story-worktree-internal-error';
|
|
255
|
+
process.stdout.write(`${render({ action: options.action, ok: false, reasonCode }, options.format)}\n`);
|
|
256
|
+
return error instanceof StoryWorktreeArgumentError ? 2 : 1;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RootProjectMemoryEffect } from '@neocortex/shared';
|
|
1
2
|
import type { StoryCommitCheckpoint } from '../../../shared/dist/yoloop/branch-unit.js';
|
|
2
3
|
export type DirectYoloCheckpointResult<T> = {
|
|
3
4
|
readonly ok: true;
|
|
@@ -43,6 +44,10 @@ export interface DirectYoloSetupReceipt {
|
|
|
43
44
|
readonly leaseExpiresAt: string;
|
|
44
45
|
readonly reused: boolean;
|
|
45
46
|
readonly publicSafe: true;
|
|
47
|
+
/** P225.07: present only when C01 ran inside a managed story worktree. */
|
|
48
|
+
readonly workspace?: 'story-worktree';
|
|
49
|
+
readonly temporaryBranch?: string;
|
|
50
|
+
readonly baseSha?: string;
|
|
46
51
|
}
|
|
47
52
|
export interface DirectYoloSetupAcceptanceReceipt extends DirectYoloSetupReceipt {
|
|
48
53
|
readonly kind: 'direct-yolo-setup-receipt';
|
|
@@ -102,6 +107,47 @@ export declare function finalizeDirectYoloStoryCheckpoint(options: DirectYoloChe
|
|
|
102
107
|
export declare function recoverLegacyDirectYoloStoryCheckpoint(options: DirectYoloCheckpointOptions & {
|
|
103
108
|
readonly commitSha: string;
|
|
104
109
|
}): Promise<DirectYoloCheckpointResult<StoryCommitCheckpoint>>;
|
|
110
|
+
/**
|
|
111
|
+
* P225.07 root integration authority: the same logical authority as direct
|
|
112
|
+
* C08, required from the root checkout on the execution branch.
|
|
113
|
+
*/
|
|
114
|
+
export declare function resolveDirectYoloIntegrationAuthority(projectRootInput: string, storyId: string): Promise<{
|
|
115
|
+
originBinding: {
|
|
116
|
+
schemaVersion: 1;
|
|
117
|
+
originBranch: string;
|
|
118
|
+
originHeadSha: string;
|
|
119
|
+
executionBranch: string;
|
|
120
|
+
capturedFromCurrentCheckout: true;
|
|
121
|
+
capturedAt: string;
|
|
122
|
+
} | undefined;
|
|
123
|
+
projectRoot: string;
|
|
124
|
+
storyId: string;
|
|
125
|
+
story: Record<string, unknown>;
|
|
126
|
+
epicId: string;
|
|
127
|
+
executionBranch: string;
|
|
128
|
+
originBranch: string;
|
|
129
|
+
graphRevision: string;
|
|
130
|
+
authorizedWriteSet: string[];
|
|
131
|
+
rootMemoryEffect: import("../private-execution/shared-root-memory-types.js").RootProjectMemoryEffect | undefined;
|
|
132
|
+
}>;
|
|
133
|
+
/** P225.07: the direct C08 write-set rule, shared with root integration. */
|
|
134
|
+
export declare function validateDirectYoloWriteSet(paths: readonly string[], authorizedWriteSet: readonly string[], storyId: string, rootMemoryEffect?: RootProjectMemoryEffect): {
|
|
135
|
+
readonly ok: true;
|
|
136
|
+
} | {
|
|
137
|
+
readonly ok: false;
|
|
138
|
+
readonly reasonCode: string;
|
|
139
|
+
};
|
|
140
|
+
/** P225.07: deterministic direct-checkpoint idempotency key (same formula as begin/finalize). */
|
|
141
|
+
export declare function directYoloCommitIdempotencyKey(input: {
|
|
142
|
+
readonly storyId: string;
|
|
143
|
+
readonly epicId: string;
|
|
144
|
+
readonly executionBranch: string;
|
|
145
|
+
readonly baseSha: string;
|
|
146
|
+
readonly bundleDigest: string;
|
|
147
|
+
readonly graphRevision: string;
|
|
148
|
+
readonly claimRevision: string;
|
|
149
|
+
}): string;
|
|
150
|
+
export declare const DIRECT_YOLO_STORY_CHECKPOINT_LEASE_MS: number;
|
|
105
151
|
/** Physical observation for a private YOLO agent step; this is not actor attribution. */
|
|
106
152
|
export declare function captureDirectYoloCheckoutEvidence(projectRootInput: string): Promise<{
|
|
107
153
|
readonly headSha: string;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { execFile } from 'node:child_process';
|
|
3
3
|
import { createHash, randomBytes, timingSafeEqual } from 'node:crypto';
|
|
4
4
|
import { existsSync } from 'node:fs';
|
|
5
|
-
import { readFile } from 'node:fs/promises';
|
|
5
|
+
import { readFile, realpath } from 'node:fs/promises';
|
|
6
6
|
import { join, resolve } from 'node:path';
|
|
7
7
|
import { promisify } from 'node:util';
|
|
8
8
|
import { readRootMemoryEffectForCheckpoint } from '../private-execution/root-memory-scope.js';
|
|
@@ -10,6 +10,7 @@ import { rootMemoryEffectDigest, verifyRootMemoryPhysicalWriteSet } from '../pri
|
|
|
10
10
|
import { acquireGitLifecyclePhysicalIntegrationLock, applyGitLifecycleRuntimeOverlay, computeImmutableStoryQaEvidenceDigest, computeGitLifecyclePhysicalIntegrationLockOwnerDigest, computeP205StoryQaEvidenceDigest, computeLegacyDirectYoloRecoveryReceiptRef, ensureRuntimeEpic, ensureRuntimeStory, ensureGitLifecyclePrivateChildDirectory, executeP205TransientAuthority, projectP205TransientExecutionEvidence, publicStoryReviewArtifactFromGit, LEGACY_DIRECT_YOLO_RECOVERY_COMMITS, mutateGitLifecycleRuntime, P205_COMPLETE_COMMAND, readGitLifecycleRuntime, gitLifecycleRuntimeDirectory, assertGitLifecyclePrivateFile, releaseGitLifecyclePhysicalIntegrationLock, releaseGitLifecyclePhysicalIntegrationLockForCheckpoint, verifyGitLifecyclePhysicalIntegrationLock, verifyAcceptedGitLifecycleStoryCheckpoint, } from './git-lifecycle-store.js';
|
|
11
11
|
import { anchoredAtomicWriteFile, anchoredRemoveFile } from './secure-filesystem-boundary.js';
|
|
12
12
|
import { parseNeocortexTrailers, trailerReasonKey, trailerValue } from './neocortex-trailers.js';
|
|
13
|
+
import { StoryWorktreeManager } from './story-worktree-manager.js';
|
|
13
14
|
import { GIT_LIFECYCLE_COMMIT_PUSH_STEP_ID, GIT_LIFECYCLE_REVIEW_PR_STEP_ID, GIT_LIFECYCLE_SETUP_BRANCH_STEP_ID, } from './git-lifecycle-step-ids.js';
|
|
14
15
|
const execFileAsync = promisify(execFile);
|
|
15
16
|
// The canonical complete P205 gate can legitimately exceed the former
|
|
@@ -26,6 +27,12 @@ export async function prepareDirectYoloSetup(options) {
|
|
|
26
27
|
let recoveryPhysicalStarted = false;
|
|
27
28
|
try {
|
|
28
29
|
const authority = await resolveLogicalAuthority(options.projectRoot, options.storyId);
|
|
30
|
+
if (await isSecondaryWorktree(authority.projectRoot)) {
|
|
31
|
+
if (options.expiredSetupRecovery)
|
|
32
|
+
return failure('direct-yolo-expired-setup-recovery-invalid');
|
|
33
|
+
const bound = await bindStoryWorktreeSetup(authority);
|
|
34
|
+
return { ok: true, value: storyWorktreeSetupReceipt(authority, bound, false) };
|
|
35
|
+
}
|
|
29
36
|
const nowIso = normalizedTime(options.nowIso);
|
|
30
37
|
const nowMs = Date.parse(nowIso);
|
|
31
38
|
const currentBranch = await git(authority.projectRoot, ['symbolic-ref', '--quiet', '--short', 'HEAD']);
|
|
@@ -197,6 +204,9 @@ export async function prepareDirectYoloSetup(options) {
|
|
|
197
204
|
export async function acceptDirectYoloSetupCheckpoint(options) {
|
|
198
205
|
let physicalLock;
|
|
199
206
|
try {
|
|
207
|
+
const logical = await resolveLogicalAuthority(options.projectRoot, options.storyId);
|
|
208
|
+
if (await isSecondaryWorktree(logical.projectRoot))
|
|
209
|
+
return await acceptStoryWorktreeSetup(logical);
|
|
200
210
|
const authority = await resolveAuthority(options.projectRoot, options.storyId);
|
|
201
211
|
const nowIso = normalizedTime(options.nowIso);
|
|
202
212
|
const statePath = join(authority.projectRoot, '.neocortex/state.json');
|
|
@@ -883,6 +893,132 @@ export async function recoverLegacyDirectYoloStoryCheckpoint(options) {
|
|
|
883
893
|
return failure(publicReason(error, 'direct-yolo-recovery-failed'));
|
|
884
894
|
}
|
|
885
895
|
}
|
|
896
|
+
/** A secondary worktree has a private git dir distinct from the common dir. */
|
|
897
|
+
async function isSecondaryWorktree(projectRoot) {
|
|
898
|
+
const gitDir = await realpath(await git(projectRoot, ['rev-parse', '--absolute-git-dir']));
|
|
899
|
+
const commonDir = await realpath(await git(projectRoot, ['rev-parse', '--path-format=absolute', '--git-common-dir']));
|
|
900
|
+
return gitDir !== commonDir;
|
|
901
|
+
}
|
|
902
|
+
/**
|
|
903
|
+
* P225.07 C01 in a managed story worktree (P225.07-ADR-7): bind to the unique
|
|
904
|
+
* active journal lease of the story and prove the checkout sits, clean, on the
|
|
905
|
+
* temporary branch at the authorized base. No epic lease, no branch switch.
|
|
906
|
+
*/
|
|
907
|
+
async function bindStoryWorktreeSetup(authority) {
|
|
908
|
+
const runtime = await readGitLifecycleRuntime(authority.projectRoot, { required: true });
|
|
909
|
+
const candidates = Object.values(runtime.storyWorktrees?.entries ?? {})
|
|
910
|
+
.filter((entry) => entry.storyId === authority.storyId && entry.epicId === authority.epicId && entry.state === 'active');
|
|
911
|
+
if (candidates.length === 0)
|
|
912
|
+
throw new Error('direct-yolo-worktree-lease-missing');
|
|
913
|
+
if (candidates.length > 1)
|
|
914
|
+
throw new Error('direct-yolo-worktree-lease-ambiguous');
|
|
915
|
+
const entry = candidates[0];
|
|
916
|
+
if (entry.executionBranch !== authority.executionBranch)
|
|
917
|
+
throw new Error('direct-yolo-worktree-branch-mismatch');
|
|
918
|
+
const toplevel = await realpath(await git(authority.projectRoot, ['rev-parse', '--show-toplevel']));
|
|
919
|
+
if (toplevel !== entry.worktreePath)
|
|
920
|
+
throw new Error('direct-yolo-worktree-path-mismatch');
|
|
921
|
+
const currentBranch = await git(authority.projectRoot, ['symbolic-ref', '--quiet', '--short', 'HEAD']).catch(() => '');
|
|
922
|
+
if (currentBranch !== entry.temporaryBranch)
|
|
923
|
+
throw new Error('direct-yolo-worktree-branch-mismatch');
|
|
924
|
+
const probe = await new StoryWorktreeManager({ projectRoot: authority.projectRoot }).probe(entry.leaseId);
|
|
925
|
+
if (!probe.ok || probe.value.ownership !== 'proven')
|
|
926
|
+
throw new Error('direct-yolo-worktree-ownership-unproven');
|
|
927
|
+
const binding = validOriginBinding(asRecord(runtime.epics[authority.epicId])?.origin_binding, authority.executionBranch, authority.originBranch);
|
|
928
|
+
if (!binding)
|
|
929
|
+
throw new Error('direct-yolo-origin-binding-invalid');
|
|
930
|
+
const authorizedBase = entry.syncedSha ?? entry.baseSha;
|
|
931
|
+
const headSha = await git(authority.projectRoot, ['rev-parse', 'HEAD']);
|
|
932
|
+
const epicRef = `refs/heads/${authority.executionBranch}`;
|
|
933
|
+
if (headSha !== authorizedBase
|
|
934
|
+
|| !(await gitExitOk(authority.projectRoot, ['merge-base', '--is-ancestor', authorizedBase, epicRef]))
|
|
935
|
+
|| !(await gitExitOk(authority.projectRoot, ['merge-base', '--is-ancestor', binding.originHeadSha, authorizedBase]))) {
|
|
936
|
+
throw new Error('direct-yolo-worktree-base-divergent');
|
|
937
|
+
}
|
|
938
|
+
if (probe.value.clean !== true
|
|
939
|
+
|| (await gitRaw(authority.projectRoot, ['status', '--porcelain=v1', '-z', '--untracked-files=all'])).length > 0) {
|
|
940
|
+
throw new Error('direct-yolo-worktree-dirty');
|
|
941
|
+
}
|
|
942
|
+
return {
|
|
943
|
+
leaseId: entry.leaseId, temporaryBranch: entry.temporaryBranch, authorizedBase, headSha,
|
|
944
|
+
expiresAt: entry.expiresAt, binding,
|
|
945
|
+
};
|
|
946
|
+
}
|
|
947
|
+
function storyWorktreeSetupReceipt(authority, bound, reused) {
|
|
948
|
+
return Object.freeze({
|
|
949
|
+
...setupReceipt(authority, bound.binding, bound.expiresAt, reused),
|
|
950
|
+
workspace: 'story-worktree', temporaryBranch: bound.temporaryBranch, baseSha: bound.authorizedBase,
|
|
951
|
+
});
|
|
952
|
+
}
|
|
953
|
+
async function acceptStoryWorktreeSetup(authority) {
|
|
954
|
+
const bound = await bindStoryWorktreeSetup(authority);
|
|
955
|
+
const statePath = join(authority.projectRoot, '.neocortex/state.json');
|
|
956
|
+
const trackedBefore = await readFile(statePath, 'utf8');
|
|
957
|
+
const tracked = asRecord(JSON.parse(trackedBefore));
|
|
958
|
+
const trackedStory = asRecord(asRecord(tracked?.stories)?.[authority.storyId]);
|
|
959
|
+
const runtime = await readGitLifecycleRuntime(authority.projectRoot, { required: true });
|
|
960
|
+
const runtimeStory = asRecord(runtime.stories[authority.storyId]);
|
|
961
|
+
if (!trackedStory || !['backlog', 'ready_to_start'].includes(String(trackedStory.status))
|
|
962
|
+
|| (trackedStory.steps_completed !== undefined
|
|
963
|
+
&& (!Array.isArray(trackedStory.steps_completed) || trackedStory.steps_completed.length > 0))
|
|
964
|
+
|| trackedStory.branch_name || trackedStory.checkpoint) {
|
|
965
|
+
return failure('direct-yolo-setup-story-progress-conflict');
|
|
966
|
+
}
|
|
967
|
+
const accepted = runtimeStory?.status === 'branch-ready'
|
|
968
|
+
&& runtimeStory.last_step === GIT_LIFECYCLE_SETUP_BRANCH_STEP_ID
|
|
969
|
+
&& Array.isArray(runtimeStory.steps_completed) && runtimeStory.steps_completed.length === 1
|
|
970
|
+
&& runtimeStory.steps_completed[0] === GIT_LIFECYCLE_SETUP_BRANCH_STEP_ID
|
|
971
|
+
&& Object.keys(runtimeStory).sort().join(',') === 'last_step,status,steps_completed';
|
|
972
|
+
if (runtimeStory && Object.keys(runtimeStory).length > 0 && !accepted) {
|
|
973
|
+
return failure('direct-yolo-setup-story-progress-conflict');
|
|
974
|
+
}
|
|
975
|
+
if (!accepted) {
|
|
976
|
+
await mutateGitLifecycleRuntime(authority.projectRoot, (document) => {
|
|
977
|
+
const currentStory = ensureRuntimeStory(document, authority.storyId);
|
|
978
|
+
if (Object.keys(currentStory).length > 0)
|
|
979
|
+
throw new Error('direct-yolo-setup-runtime-raced');
|
|
980
|
+
currentStory.status = 'branch-ready';
|
|
981
|
+
currentStory.last_step = GIT_LIFECYCLE_SETUP_BRANCH_STEP_ID;
|
|
982
|
+
currentStory.steps_completed = [GIT_LIFECYCLE_SETUP_BRANCH_STEP_ID];
|
|
983
|
+
}, {
|
|
984
|
+
expectedRevision: runtime.revision,
|
|
985
|
+
preCommit: async () => {
|
|
986
|
+
if (await readFile(statePath, 'utf8') !== trackedBefore
|
|
987
|
+
|| await git(authority.projectRoot, ['symbolic-ref', '--quiet', '--short', 'HEAD']) !== bound.temporaryBranch
|
|
988
|
+
|| await git(authority.projectRoot, ['rev-parse', 'HEAD']) !== bound.headSha
|
|
989
|
+
|| (await gitRaw(authority.projectRoot, ['status', '--porcelain=v1', '-z', '--untracked-files=all'])).length > 0) {
|
|
990
|
+
throw new Error('direct-yolo-setup-physical-state-raced');
|
|
991
|
+
}
|
|
992
|
+
},
|
|
993
|
+
});
|
|
994
|
+
}
|
|
995
|
+
return { ok: true, value: Object.freeze({
|
|
996
|
+
...storyWorktreeSetupReceipt(authority, bound, accepted),
|
|
997
|
+
checkpointAccepted: true, graphRevision: authority.graphRevision, headSha: bound.headSha,
|
|
998
|
+
}) };
|
|
999
|
+
}
|
|
1000
|
+
/**
|
|
1001
|
+
* P225.07 root integration authority: the same logical authority as direct
|
|
1002
|
+
* C08, required from the root checkout on the execution branch.
|
|
1003
|
+
*/
|
|
1004
|
+
export async function resolveDirectYoloIntegrationAuthority(projectRootInput, storyId) {
|
|
1005
|
+
const authority = await resolveAuthority(projectRootInput, storyId);
|
|
1006
|
+
const runtime = await readGitLifecycleRuntime(authority.projectRoot, { required: true });
|
|
1007
|
+
const binding = validOriginBinding(asRecord(runtime.epics[authority.epicId])?.origin_binding, authority.executionBranch, authority.originBranch);
|
|
1008
|
+
return { ...authority, originBinding: binding };
|
|
1009
|
+
}
|
|
1010
|
+
/** P225.07: the direct C08 write-set rule, shared with root integration. */
|
|
1011
|
+
export function validateDirectYoloWriteSet(paths, authorizedWriteSet, storyId, rootMemoryEffect) {
|
|
1012
|
+
return validateDirectWriteSet(paths, authorizedWriteSet, storyId, rootMemoryEffect);
|
|
1013
|
+
}
|
|
1014
|
+
/** P225.07: deterministic direct-checkpoint idempotency key (same formula as begin/finalize). */
|
|
1015
|
+
export function directYoloCommitIdempotencyKey(input) {
|
|
1016
|
+
return digest([
|
|
1017
|
+
'direct-yolo-commit-v1', input.storyId, input.epicId, input.executionBranch,
|
|
1018
|
+
input.baseSha, input.bundleDigest, input.graphRevision, input.claimRevision,
|
|
1019
|
+
].join('\0'));
|
|
1020
|
+
}
|
|
1021
|
+
export const DIRECT_YOLO_STORY_CHECKPOINT_LEASE_MS = DIRECT_STORY_CHECKPOINT_LEASE_MS;
|
|
886
1022
|
async function resolveLogicalAuthority(projectRootInput, storyId) {
|
|
887
1023
|
if (!/^[A-Za-z][A-Za-z0-9_-]*\.[A-Za-z0-9._-]+$/.test(storyId))
|
|
888
1024
|
throw new Error('direct-yolo-story-id-invalid');
|
|
@@ -31,6 +31,40 @@ export interface GitLifecycleRuntimeDocument {
|
|
|
31
31
|
* closed-schema validation in `epic-operational-state.ts` before use.
|
|
32
32
|
*/
|
|
33
33
|
readonly operational?: Record<string, unknown>;
|
|
34
|
+
/**
|
|
35
|
+
* P225.05 optional story-worktree journal. Absent until the first
|
|
36
|
+
* `story-worktree` command; closed-schema validated on every read/write.
|
|
37
|
+
*/
|
|
38
|
+
readonly storyWorktrees?: StoryWorktreeJournal;
|
|
39
|
+
}
|
|
40
|
+
export declare const STORY_WORKTREE_JOURNAL_MAX_CLEANUP_RECEIPTS = 64;
|
|
41
|
+
export declare const STORY_WORKTREE_JOURNAL_MAX_ENTRIES = 256;
|
|
42
|
+
export interface StoryWorktreeJournalEntry {
|
|
43
|
+
readonly schemaVersion: 1;
|
|
44
|
+
readonly leaseId: string;
|
|
45
|
+
readonly epicId: string;
|
|
46
|
+
readonly storyId: string;
|
|
47
|
+
readonly dispatchDigest: string;
|
|
48
|
+
readonly hash8: string;
|
|
49
|
+
readonly executionBranch: string;
|
|
50
|
+
readonly temporaryBranch: string;
|
|
51
|
+
readonly worktreeRef: string;
|
|
52
|
+
/** Private absolute path; never projected into public output. */
|
|
53
|
+
readonly worktreePath: string;
|
|
54
|
+
readonly workspaceMechanism: 'client_managed_worktree' | 'native_subagent_worktree';
|
|
55
|
+
readonly ownerId: string;
|
|
56
|
+
readonly nonceDigest: string;
|
|
57
|
+
readonly baseSha: string;
|
|
58
|
+
readonly graphRevision: string;
|
|
59
|
+
readonly state: 'creating' | 'active';
|
|
60
|
+
readonly acquiredAt: string;
|
|
61
|
+
readonly expiresAt: string;
|
|
62
|
+
readonly syncedSha?: string;
|
|
63
|
+
}
|
|
64
|
+
export interface StoryWorktreeJournal {
|
|
65
|
+
readonly schemaVersion: 1;
|
|
66
|
+
readonly entries: Record<string, StoryWorktreeJournalEntry>;
|
|
67
|
+
readonly cleanupReceipts: Record<string, unknown>[];
|
|
34
68
|
}
|
|
35
69
|
export interface GitLifecycleMutationResult<T> {
|
|
36
70
|
readonly document: GitLifecycleRuntimeDocument;
|
|
@@ -173,6 +207,54 @@ export declare function persistGitLifecycleGraphAuthority(projectRoot: string, a
|
|
|
173
207
|
export declare function mutateGitLifecycleRuntime<T>(projectRoot: string, mutate: (document: GitLifecycleRuntimeDocument) => T, options?: GitLifecycleMutationOptions): Promise<GitLifecycleMutationResult<T>>;
|
|
174
208
|
/** Merge the runtime overlay over tracked state without mutating either input. */
|
|
175
209
|
export declare function applyGitLifecycleRuntimeOverlay(tracked: Record<string, unknown>, runtime: GitLifecycleRuntimeDocument): Record<string, unknown>;
|
|
210
|
+
/** Return (creating when absent) the mutable P225.05 story-worktree journal. */
|
|
211
|
+
export declare function ensureStoryWorktreeJournal(document: GitLifecycleRuntimeDocument): StoryWorktreeJournal;
|
|
212
|
+
/** Drop an empty journal so documents return to their pre-P225.05 shape. */
|
|
213
|
+
export declare function compactStoryWorktreeJournal(document: GitLifecycleRuntimeDocument): void;
|
|
214
|
+
/**
|
|
215
|
+
* Closed P225-CON-RECEIPTS `cleanup-receipt` shape, checked locally so the
|
|
216
|
+
* published client closure needs no extra shared module. Tests prove parity
|
|
217
|
+
* with the shared `validateStoryWorktreeReceipt`.
|
|
218
|
+
*/
|
|
219
|
+
export declare function isStoryWorktreeCleanupReceiptRecord(value: unknown): boolean;
|
|
220
|
+
/**
|
|
221
|
+
* P225.07 root-written evidence container read by the server phase authority
|
|
222
|
+
* (`epics[<id>].story_worktree_evidence`, P225.04-ADR-3). Closed and bounded.
|
|
223
|
+
*/
|
|
224
|
+
export interface StoryWorktreeSpecAcceptanceRecord {
|
|
225
|
+
readonly storyId: string;
|
|
226
|
+
readonly specDigest: string;
|
|
227
|
+
readonly graphRevision: string;
|
|
228
|
+
}
|
|
229
|
+
export interface StoryWorktreeEvidenceContainer {
|
|
230
|
+
readonly schemaVersion: 1;
|
|
231
|
+
readonly specAcceptances?: readonly StoryWorktreeSpecAcceptanceRecord[];
|
|
232
|
+
readonly receipts?: readonly Record<string, unknown>[];
|
|
233
|
+
}
|
|
234
|
+
export declare const STORY_WORKTREE_EVIDENCE_MAX_RECEIPTS = 512;
|
|
235
|
+
export declare const STORY_WORKTREE_EVIDENCE_MAX_SPEC_ACCEPTANCES = 256;
|
|
236
|
+
/**
|
|
237
|
+
* Closed local validator for the P225-CON-RECEIPTS kinds the root persists in
|
|
238
|
+
* `story_worktree_evidence` (phase-one, spec-barrier, integration). Kept in the
|
|
239
|
+
* published client closure; tests prove parity with the shared validator.
|
|
240
|
+
*/
|
|
241
|
+
export declare function isStoryWorktreeEvidenceReceiptRecord(value: unknown): boolean;
|
|
242
|
+
/** True only for the closed `integration-receipt` shape. */
|
|
243
|
+
export declare function isStoryWorktreeIntegrationReceiptRecord(value: unknown): boolean;
|
|
244
|
+
/** Read (never create) the validated evidence container of one runtime epic overlay. */
|
|
245
|
+
export declare function readStoryWorktreeEvidence(document: GitLifecycleRuntimeDocument, epicId: string): StoryWorktreeEvidenceContainer | undefined;
|
|
246
|
+
/**
|
|
247
|
+
* Append server-returned or root-produced evidence to the mutable runtime
|
|
248
|
+
* document (call inside `mutateGitLifecycleRuntime`). Receipts dedupe by
|
|
249
|
+
* `receiptId` (identical bytes only); spec acceptances dedupe by `storyId`.
|
|
250
|
+
*/
|
|
251
|
+
export declare function appendStoryWorktreeEvidence(document: GitLifecycleRuntimeDocument, epicId: string, input: {
|
|
252
|
+
readonly receipts?: readonly unknown[];
|
|
253
|
+
readonly specAcceptances?: readonly unknown[];
|
|
254
|
+
}): {
|
|
255
|
+
readonly appendedReceipts: number;
|
|
256
|
+
readonly appendedSpecAcceptances: number;
|
|
257
|
+
};
|
|
176
258
|
export declare function ensureRuntimeEpic(document: GitLifecycleRuntimeDocument, epicId: string): Record<string, unknown>;
|
|
177
259
|
export declare function ensureRuntimeStory(document: GitLifecycleRuntimeDocument, storyId: string): Record<string, unknown>;
|
|
178
260
|
/** Runtime-safe accepted-checkpoint predicate kept in the published client closure. */
|