@ornexus/neocortex 4.60.66 → 4.60.68
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 +1598 -1640
- package/install.ps1 +1 -1
- package/install.sh +2 -1
- package/package.json +10 -7
- package/packages/client/dist/adapters/adapter-registry.js +108 -1
- package/packages/client/dist/adapters/antigravity-adapter.js +77 -2
- package/packages/client/dist/adapters/claude-code-adapter.js +79 -3
- package/packages/client/dist/adapters/codex-adapter.js +80 -2
- package/packages/client/dist/adapters/cursor-adapter.js +115 -4
- package/packages/client/dist/adapters/gemini-adapter.js +71 -2
- package/packages/client/dist/adapters/grok-adapter.js +42 -2
- package/packages/client/dist/adapters/index.js +22 -1
- package/packages/client/dist/adapters/platform-detector.js +212 -1
- package/packages/client/dist/adapters/target-adapter.js +12 -0
- package/packages/client/dist/adapters/vscode-adapter.js +72 -2
- package/packages/client/dist/agent/refresh-stubs.js +417 -2
- package/packages/client/dist/agent/update-agent-yaml.js +102 -1
- package/packages/client/dist/agent/update-description.js +251 -1
- package/packages/client/dist/cache/crypto-utils.js +78 -1
- package/packages/client/dist/cache/encrypted-cache.js +108 -1
- package/packages/client/dist/cache/in-memory-asset-cache.js +73 -1
- package/packages/client/dist/cache/index.js +13 -1
- package/packages/client/dist/cache/protected-pi-boundary.js +44 -1
- package/packages/client/dist/checkpoint/checkpoint-client-reader.js +127 -2
- package/packages/client/dist/checkpoint/index.js +11 -1
- package/packages/client/dist/checkpoint/shared-checkpoint-types.js +32 -1
- package/packages/client/dist/cli.js +303 -3
- package/packages/client/dist/commands/activate.js +394 -8
- package/packages/client/dist/commands/architecture-answers.js +274 -7
- package/packages/client/dist/commands/architecture-memory-terminal.js +253 -4
- package/packages/client/dist/commands/architecture-non-ui-continuation.js +100 -1
- package/packages/client/dist/commands/architecture-root-binding.js +51 -1
- package/packages/client/dist/commands/cache-status.js +112 -2
- package/packages/client/dist/commands/config.js +88 -1
- package/packages/client/dist/commands/doctor.d.ts +135 -0
- package/packages/client/dist/commands/doctor.js +635 -0
- package/packages/client/dist/commands/invoke.d.ts +18 -0
- package/packages/client/dist/commands/invoke.js +7140 -142
- package/packages/client/dist/commands/legacy-epic-terminal.js +71 -1
- package/packages/client/dist/commands/legacy-story-branch.js +96 -1
- package/packages/client/dist/commands/legacy-story-pr.js +276 -1
- package/packages/client/dist/commands/mutation-qa-checkpoint.js +285 -5
- package/packages/client/dist/commands/mutation-qa-gate.js +54 -1
- package/packages/client/dist/commands/mutation-qa-git.js +41 -1
- package/packages/client/dist/commands/mutation-qa-policy.js +102 -1
- package/packages/client/dist/commands/mutation-qa-run.js +219 -3
- package/packages/client/dist/commands/mutation-qa-verdict.js +149 -1
- package/packages/client/dist/commands/mutation-qa.js +220 -1
- package/packages/client/dist/commands/native-agent.js +136 -2
- package/packages/client/dist/commands/planning-diagnosis.js +43 -1
- package/packages/client/dist/commands/planning-generation.js +53 -1
- package/packages/client/dist/commands/planning-memory.js +40 -1
- package/packages/client/dist/commands/planning-research.js +42 -1
- package/packages/client/dist/commands/private-session.js +75 -1
- package/packages/client/dist/commands/property-qa.js +139 -1
- package/packages/client/dist/commands/qa-control.js +16 -1
- package/packages/client/dist/commands/qa-scan-browser-launch.js +55 -1
- package/packages/client/dist/commands/qa-scan-browser-route.js +28 -1
- package/packages/client/dist/commands/qa-scan-capture.js +663 -5
- package/packages/client/dist/commands/qa-scan-discovery.js +376 -3
- package/packages/client/dist/commands/qa-scan-review.js +826 -5
- package/packages/client/dist/commands/qa-synthetic-backend-capture.js +266 -1
- package/packages/client/dist/commands/qa-synthetic-backend-review.js +297 -1
- package/packages/client/dist/commands/qa-synthetic-backend.js +340 -2
- package/packages/client/dist/commands/qa-synthetic-broker-port.js +85 -1
- package/packages/client/dist/commands/qa-synthetic-browser.js +39 -1
- package/packages/client/dist/commands/refactor-characterization.js +671 -21
- package/packages/client/dist/commands/refactor-commit.js +399 -13
- package/packages/client/dist/commands/refactor-control.js +142 -3
- package/packages/client/dist/commands/refactor-cpp-assertions.js +93 -3
- package/packages/client/dist/commands/refactor-review.js +283 -5
- package/packages/client/dist/commands/refactor-root.js +588 -7
- package/packages/client/dist/commands/refresh-memory.js +156 -3
- package/packages/client/dist/commands/shared-architecture-non-ui.js +24 -1
- package/packages/client/dist/commands/story-checkpoint.js +171 -1
- package/packages/client/dist/config/profile-directory.js +13 -1
- package/packages/client/dist/config/resolver-selection.js +278 -1
- package/packages/client/dist/config/secure-config.js +281 -12
- package/packages/client/dist/config.js +223 -2
- package/packages/client/dist/constants.js +25 -1
- package/packages/client/dist/context/context-collector.js +222 -2
- package/packages/client/dist/context/context-sanitizer.js +145 -1
- package/packages/client/dist/continuity/autonomous-governance.js +285 -1
- package/packages/client/dist/continuity/continuity-client-state-store.js +1587 -1
- package/packages/client/dist/continuity/invoke-hooks.js +129 -1
- package/packages/client/dist/continuity/migrations/001-initial-schema.js +12 -2
- package/packages/client/dist/continuity/migrations/002-processing-output-summary-indexes.js +12 -2
- package/packages/client/dist/continuity/migrations/003-headless-execution-attempts.js +12 -2
- package/packages/client/dist/continuity/migrations/004-outbox-delivery-state.js +12 -2
- package/packages/client/dist/continuity/migrations/005-bounded-headless-queue.js +12 -2
- package/packages/client/dist/continuity/migrations/006-native-agent-dispatches.js +10 -2
- package/packages/client/dist/continuity/native-agent-store.js +69 -1
- package/packages/client/dist/continuity/native-agent-types.js +90 -1
- package/packages/client/dist/continuity/outbox.js +117 -1
- package/packages/client/dist/continuity/runner-bootstrap-policy.js +172 -1
- package/packages/client/dist/continuity/sqlite-store.js +2536 -81
- package/packages/client/dist/effects/invoke-effect-gateways.js +62 -1
- package/packages/client/dist/errors/error-messages.js +228 -2
- package/packages/client/dist/errors/frontmatter-diagnostics.js +125 -1
- package/packages/client/dist/evidence/collector.js +347 -1
- package/packages/client/dist/evidence/index.js +1 -1
- package/packages/client/dist/evidence/types.js +2 -0
- package/packages/client/dist/fs/atomic-state-replace.js +152 -1
- package/packages/client/dist/generated/command-registry.generated.js +4076 -1
- package/packages/client/dist/generated/public-projections.generated.js +149 -1
- package/packages/client/dist/git/direct-yolo-c01-retry.js +138 -4
- package/packages/client/dist/git/direct-yolo-checkpoint.js +1234 -4
- package/packages/client/dist/git/git-lifecycle-step-ids.js +14 -1
- package/packages/client/dist/git/git-lifecycle-store.js +1938 -9
- package/packages/client/dist/git/legacy-story-branch-checkpoint.js +259 -9
- package/packages/client/dist/git/legacy-story-branch-setup.js +348 -4
- package/packages/client/dist/git/legacy-story-pr.js +3538 -70
- package/packages/client/dist/git/secure-filesystem-boundary.js +182 -5
- package/packages/client/dist/graph-retrieval/pre-command-hook.js +284 -1
- package/packages/client/dist/graph-retrieval/shared-graph-retrieval-contract.js +237 -1
- package/packages/client/dist/i18n/first-run.js +60 -2
- package/packages/client/dist/index.js +47 -1
- package/packages/client/dist/invocation/invoke-input.js +24 -1
- package/packages/client/dist/license/index.js +5 -1
- package/packages/client/dist/license/license-client.js +304 -1
- package/packages/client/dist/machine/fingerprint.js +163 -2
- package/packages/client/dist/machine/index.js +5 -1
- package/packages/client/dist/memory/project-memory-path-scope.js +62 -1
- package/packages/client/dist/memory/project-memory-writer.js +1007 -40
- package/packages/client/dist/memory/shared-project-memory-types.js +253 -2
- package/packages/client/dist/migrations/project-identity-capability.js +50 -1
- package/packages/client/dist/migrations/project-identity.js +493 -7
- package/packages/client/dist/migrations/state-json.js +344 -4
- package/packages/client/dist/policy/architecture-policy.js +184 -2
- package/packages/client/dist/policy/index.js +7 -1
- package/packages/client/dist/policy/shared-policy-types.js +38 -0
- package/packages/client/dist/policy/subagent-approval-policy.js +55 -1
- package/packages/client/dist/private-execution/clean-baseline.js +279 -2
- package/packages/client/dist/private-execution/codex-executor.js +574 -4
- package/packages/client/dist/private-execution/codex-host-runtime.js +137 -1
- package/packages/client/dist/private-execution/codex-lifecycle-guard.js +97 -1
- package/packages/client/dist/private-execution/codex-scoped-permissions.js +128 -1
- package/packages/client/dist/private-execution/delivery.js +410 -13
- package/packages/client/dist/private-execution/diagnosis-root-review.js +294 -2
- package/packages/client/dist/private-execution/frozen-handoff.js +19 -6
- package/packages/client/dist/private-execution/implementation-validation.js +106 -2
- package/packages/client/dist/private-execution/isolated-admission.js +1432 -23
- package/packages/client/dist/private-execution/isolated-session.js +725 -5
- package/packages/client/dist/private-execution/isolated-workspace.js +122 -1
- package/packages/client/dist/private-execution/pact-consumer-runtime.js +409 -3
- package/packages/client/dist/private-execution/pact-test-source.js +258 -1
- package/packages/client/dist/private-execution/pact-toolchain.js +290 -3
- package/packages/client/dist/private-execution/pact-write-set.js +172 -1
- package/packages/client/dist/private-execution/planning-diagnosis-checkpoint.js +406 -5
- package/packages/client/dist/private-execution/planning-generation-checkpoint.js +462 -5
- package/packages/client/dist/private-execution/planning-memory-checkpoint.js +139 -3
- package/packages/client/dist/private-execution/planning-research-checkpoint.js +325 -4
- package/packages/client/dist/private-execution/private-report-store.js +42 -1
- package/packages/client/dist/private-execution/property-test-candidate.js +103 -1
- package/packages/client/dist/private-execution/property-test-choices.js +147 -3
- package/packages/client/dist/private-execution/property-test-plan.js +271 -7
- package/packages/client/dist/private-execution/property-test-review.js +258 -4
- package/packages/client/dist/private-execution/property-test-runtime.js +372 -9
- package/packages/client/dist/private-execution/property-test-source.js +139 -1
- package/packages/client/dist/private-execution/root-checkpoint.js +80 -1
- package/packages/client/dist/private-execution/root-memory-git-evidence.js +135 -3
- package/packages/client/dist/private-execution/root-memory-recovery.js +93 -1
- package/packages/client/dist/private-execution/root-memory-request.js +29 -1
- package/packages/client/dist/private-execution/root-memory-scope.js +178 -1
- package/packages/client/dist/private-execution/root-memory-writer.js +102 -1
- package/packages/client/dist/private-execution/session-lease.js +63 -1
- package/packages/client/dist/private-execution/shared-private-admission-types.js +50 -1
- package/packages/client/dist/private-execution/shared-project-validation.js +66 -1
- package/packages/client/dist/private-execution/shared-root-memory-types.js +61 -1
- package/packages/client/dist/private-execution/ux-source-validation.js +372 -1
- package/packages/client/dist/private-execution/ux-write-set.js +191 -2
- package/packages/client/dist/resilience/circuit-breaker.js +170 -1
- package/packages/client/dist/resilience/degradation-manager.js +164 -1
- package/packages/client/dist/resilience/freshness-indicator.js +100 -1
- package/packages/client/dist/resilience/index.js +8 -1
- package/packages/client/dist/resilience/recovery-detector.js +74 -1
- package/packages/client/dist/resolvers/asset-resolver.js +13 -0
- package/packages/client/dist/resolvers/local-resolver.js +255 -8
- package/packages/client/dist/resolvers/remote-resolver.js +233 -1
- package/packages/client/dist/runner/binary.js +404 -1
- package/packages/client/dist/runner/cli.js +1571 -17
- package/packages/client/dist/runner/headless/adapters.js +49 -1
- package/packages/client/dist/runner/headless/claude-code-adapter.js +79 -1
- package/packages/client/dist/runner/headless/continuous-story-workspace.js +1628 -11
- package/packages/client/dist/runner/headless/epic-git-reconciliation-inventory.js +69 -1
- package/packages/client/dist/runner/headless/epic-merge-candidate-qa.js +110 -2
- package/packages/client/dist/runner/headless/epic-terminal-git-cli-adapter.js +1236 -8
- package/packages/client/dist/runner/headless/epic-terminal-git-runner.js +318 -2
- package/packages/client/dist/runner/headless/fake-adapter.js +62 -1
- package/packages/client/dist/runner/headless/managed-profile.js +132 -1
- package/packages/client/dist/runner/headless/opencode-adapter.js +145 -2
- package/packages/client/dist/runner/headless/prepared-story-bundle.js +43 -1
- package/packages/client/dist/runner/headless/resolver.js +231 -1
- package/packages/client/dist/runner/headless/run-yolo.js +885 -1
- package/packages/client/dist/runner/headless/run-yoloop.d.ts +4 -1
- package/packages/client/dist/runner/headless/run-yoloop.js +2574 -2
- package/packages/client/dist/runner/headless/types.js +574 -2
- package/packages/client/dist/runner/local-console.js +396 -13
- package/packages/client/dist/runner/portal-sync-worker.js +1487 -1
- package/packages/client/dist/runner/project-identity.js +106 -1
- package/packages/client/dist/runner/scheduler.js +995 -7
- package/packages/client/dist/runner-cli.js +18 -2
- package/packages/client/dist/state/invocation-shape.js +13 -1
- package/packages/client/dist/state/project-state-snapshot.js +1677 -1
- package/packages/client/dist/state/state-json-repair.js +785 -3
- package/packages/client/dist/state/structural-dag-projection.js +118 -1
- package/packages/client/dist/telemetry/index.js +5 -1
- package/packages/client/dist/telemetry/offline-queue.js +131 -1
- package/packages/client/dist/tier/index.js +5 -1
- package/packages/client/dist/tier/tier-aware-client.js +405 -1
- package/packages/client/dist/types/index.js +38 -1
- package/packages/client/dist/version.js +27 -1
- package/packages/client/dist/yolo/change-evidence-collector.js +126 -1
- package/packages/client/dist/yolo/invoke-envelope-capability.js +62 -1
- package/packages/client/dist/yolo/spec-envelope-collector.js +185 -5
- package/packages/client/dist/yoloop/discovery-hook.js +300 -2
- package/packages/client/dist/yoloop/index.js +8 -1
- package/packages/client/dist/yoloop/invoke-hooks.js +669 -12
- package/packages/client/dist/yoloop/shared-discover-epics.js +1007 -1
- package/packages/client/dist/yoloop/shared-yoloop-types.js +33 -1
- package/packages/client/dist/yoloop/target-normalization.js +180 -1
- package/packages/client/dist/yoloop/yoloop-client-state-store.js +1723 -1
- package/packages/shared/dist/compatibility/index.js +476 -0
- package/packages/shared/dist/yoloop/release-blocked.js +653 -0
- package/targets-stubs/antigravity/gemini.md +1 -1
- package/targets-stubs/antigravity/skill/SKILL.md +3 -2
- package/targets-stubs/claude-code/neocortex-root.agent.yaml +1 -1
- package/targets-stubs/claude-code/neocortex-root.md +5 -5
- package/targets-stubs/claude-code/neocortex.agent.yaml +1 -1
- package/targets-stubs/claude-code/neocortex.md +8 -9
- package/targets-stubs/codex/AGENTS.md +3 -3
- package/targets-stubs/cursor/agent.md +4 -3
- package/targets-stubs/gemini-cli/agent.md +5 -4
- package/targets-stubs/opencode/neocortex-root.md +3 -3
- package/targets-stubs/vscode/neocortex.agent.md +5 -4
|
@@ -1,9 +1,259 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
/** Root-owned, replayable C01 checkpoint for explicitly recorded story branches. */
|
|
2
|
+
import { execFileSync } from 'node:child_process';
|
|
3
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
4
|
+
import { closeSync, constants, existsSync, fstatSync, openSync, readFileSync, realpathSync } from 'node:fs';
|
|
5
|
+
import { join, resolve } from 'node:path';
|
|
6
|
+
import { parseDocument } from 'yaml';
|
|
7
|
+
import { resolveBranchUnit } from '../../../shared/dist/yoloop/branch-unit.js';
|
|
8
|
+
import { acquireGitLifecyclePhysicalIntegrationLock, assertGitLifecyclePrivateFile, ensureGitLifecyclePrivateChildDirectory, gitLifecycleRuntimeDirectory, releaseGitLifecyclePhysicalIntegrationLock, } from './git-lifecycle-store.js';
|
|
9
|
+
import { GIT_LIFECYCLE_SETUP_BRANCH_STEP_ID } from './git-lifecycle-step-ids.js';
|
|
10
|
+
import { anchoredAtomicWriteFile, anchoredCompareAndSwapFile } from './secure-filesystem-boundary.js';
|
|
11
|
+
import { readCompletedLegacyStoryBranchPlan } from './legacy-story-branch-setup.js';
|
|
12
|
+
function fail(reasonCode) { return { ok: false, reasonCode }; }
|
|
13
|
+
function digest(value) { return createHash('sha256').update(value).digest('hex'); }
|
|
14
|
+
function row(value) {
|
|
15
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? value : null;
|
|
16
|
+
}
|
|
17
|
+
function git(cwd, args) {
|
|
18
|
+
return execFileSync('git', [...args], { cwd, encoding: 'utf8',
|
|
19
|
+
stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 4 * 1024 * 1024 }).trim();
|
|
20
|
+
}
|
|
21
|
+
function gitRaw(cwd, args) {
|
|
22
|
+
return execFileSync('git', [...args], { cwd, encoding: 'utf8',
|
|
23
|
+
stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 4 * 1024 * 1024 });
|
|
24
|
+
}
|
|
25
|
+
function safeRead(path) {
|
|
26
|
+
const fd = openSync(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
27
|
+
try {
|
|
28
|
+
const stat = fstatSync(fd);
|
|
29
|
+
if (!stat.isFile() || stat.size > 2 * 1024 * 1024)
|
|
30
|
+
throw new Error('legacy-branch-checkpoint-file-unsafe');
|
|
31
|
+
return readFileSync(fd, 'utf8');
|
|
32
|
+
}
|
|
33
|
+
finally {
|
|
34
|
+
closeSync(fd);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function repository(cwd) {
|
|
38
|
+
const remote = git(cwd, ['remote', 'get-url', 'origin']);
|
|
39
|
+
const match = remote.match(/^(?:https:\/\/github\.com\/|git@github\.com:)([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+?)(?:\.git)?$/);
|
|
40
|
+
if (!match || match[1].includes('..') || match[2].includes('..')) {
|
|
41
|
+
throw new Error('legacy-branch-issue-repository-invalid');
|
|
42
|
+
}
|
|
43
|
+
return `${match[1]}/${match[2]}`;
|
|
44
|
+
}
|
|
45
|
+
async function ghIssueVerifier(repo, number) {
|
|
46
|
+
const raw = execFileSync('gh', ['issue', 'view', String(number), '--repo', repo,
|
|
47
|
+
'--json', 'number,title,state,url'], { encoding: 'utf8', timeout: 15_000,
|
|
48
|
+
stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 16 * 1024 });
|
|
49
|
+
return JSON.parse(raw);
|
|
50
|
+
}
|
|
51
|
+
function validateIssue(issue, repo, storyId, number, replay) {
|
|
52
|
+
if (issue.number !== number || issue.title !== `[YOLO] Story ${storyId} - Workflow Run`
|
|
53
|
+
|| (issue.state !== 'OPEN' && !(replay && issue.state === 'CLOSED'))
|
|
54
|
+
|| issue.url.toLowerCase() !== `https://github.com/${repo}/issues/${number}`.toLowerCase()) {
|
|
55
|
+
throw new Error('legacy-branch-issue-evidence-invalid');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function project(plan, number) {
|
|
59
|
+
const cwd = plan.worktreePath;
|
|
60
|
+
const stateBefore = gitRaw(cwd, ['show', 'HEAD:.neocortex/state.json']);
|
|
61
|
+
if (digest(stateBefore) !== plan.stateSha256)
|
|
62
|
+
throw new Error('legacy-branch-checkpoint-base-state-mismatch');
|
|
63
|
+
const state = row(JSON.parse(stateBefore));
|
|
64
|
+
const stories = row(state?.stories);
|
|
65
|
+
const epics = row(state?.epics);
|
|
66
|
+
const story = row(stories?.[plan.storyId]);
|
|
67
|
+
const epic = row(epics?.[plan.epicId]);
|
|
68
|
+
const epicStories = Object.entries(stories ?? {}).flatMap(([id, value]) => {
|
|
69
|
+
const item = row(value);
|
|
70
|
+
return item?.epic_id === plan.epicId ? [{ ...item, id }] : [];
|
|
71
|
+
});
|
|
72
|
+
if (!epic || epic.id !== plan.epicId || epic.branch_mode === 'epic'
|
|
73
|
+
|| resolveBranchUnit(epic, epicStories).mode !== 'story'
|
|
74
|
+
|| !story || story.id !== plan.storyId || story.epic_id !== plan.epicId
|
|
75
|
+
|| (story.status !== 'backlog' && story.status !== 'ready_to_start')
|
|
76
|
+
|| !Array.isArray(story.steps_completed) || story.steps_completed.length !== 0
|
|
77
|
+
|| story.branch_name || story.issue_number || story.last_step) {
|
|
78
|
+
throw new Error('legacy-branch-checkpoint-state-conflict');
|
|
79
|
+
}
|
|
80
|
+
story.status = 'branch-ready';
|
|
81
|
+
story.steps_completed = [GIT_LIFECYCLE_SETUP_BRANCH_STEP_ID];
|
|
82
|
+
story.last_step = GIT_LIFECYCLE_SETUP_BRANCH_STEP_ID;
|
|
83
|
+
story.branch_name = plan.branch;
|
|
84
|
+
story.issue_number = number;
|
|
85
|
+
const stateAfter = `${JSON.stringify(state, null, 2)}\n`;
|
|
86
|
+
const storyPath = `docs/stories/${plan.storyId}.story.md`;
|
|
87
|
+
const storyBefore = gitRaw(cwd, ['show', `HEAD:${storyPath}`]);
|
|
88
|
+
const frontmatter = storyBefore.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n/);
|
|
89
|
+
if (!frontmatter)
|
|
90
|
+
throw new Error('legacy-branch-checkpoint-frontmatter-invalid');
|
|
91
|
+
const document = parseDocument(frontmatter[1], { strict: true, uniqueKeys: true });
|
|
92
|
+
if (document.errors.length > 0 || document.get('id') !== plan.storyId
|
|
93
|
+
|| (document.get('epic_id') ?? document.get('epic')) !== plan.epicId) {
|
|
94
|
+
throw new Error('legacy-branch-checkpoint-frontmatter-invalid');
|
|
95
|
+
}
|
|
96
|
+
const frontmatterData = row(document.toJS());
|
|
97
|
+
const stepKeys = ['stepsCompleted', 'steps_completed'].filter((key) => document.has(key));
|
|
98
|
+
const branchKeys = ['branchName', 'branch_name'].filter((key) => document.has(key));
|
|
99
|
+
const lastKeys = ['lastStep', 'last_step'].filter((key) => document.has(key));
|
|
100
|
+
const issueKeys = ['issueNumber', 'issue_number'].filter((key) => document.has(key));
|
|
101
|
+
if (stepKeys.length > 1 || branchKeys.length > 1 || lastKeys.length > 1 || issueKeys.length > 1
|
|
102
|
+
|| (document.has('status') && !['backlog', 'ready', 'ready_to_start'].includes(String(document.get('status'))))
|
|
103
|
+
|| (document.has('currentStatus')
|
|
104
|
+
&& !['backlog', 'ready', 'ready_to_start'].includes(String(frontmatterData?.currentStatus)))
|
|
105
|
+
|| (stepKeys.length === 1 && (!Array.isArray(frontmatterData?.[stepKeys[0]])
|
|
106
|
+
|| (frontmatterData?.[stepKeys[0]]).length !== 0))
|
|
107
|
+
|| (branchKeys.length === 1 && frontmatterData?.[branchKeys[0]] != null)
|
|
108
|
+
|| (lastKeys.length === 1 && frontmatterData?.[lastKeys[0]] != null)
|
|
109
|
+
|| (issueKeys.length === 1 && frontmatterData?.[issueKeys[0]] != null)) {
|
|
110
|
+
throw new Error('legacy-branch-checkpoint-frontmatter-conflict');
|
|
111
|
+
}
|
|
112
|
+
document.set('status', 'branch-ready');
|
|
113
|
+
if (document.has('currentStatus'))
|
|
114
|
+
document.set('currentStatus', 'branch-ready');
|
|
115
|
+
document.set(stepKeys[0] ?? 'stepsCompleted', [GIT_LIFECYCLE_SETUP_BRANCH_STEP_ID]);
|
|
116
|
+
document.set(lastKeys[0] ?? 'lastStep', GIT_LIFECYCLE_SETUP_BRANCH_STEP_ID);
|
|
117
|
+
document.set(branchKeys[0] ?? 'branchName', plan.branch);
|
|
118
|
+
document.set(issueKeys[0] ?? 'issueNumber', number);
|
|
119
|
+
const storyAfter = `---\n${document.toString({ lineWidth: 0 })}---\n${storyBefore.slice(frontmatter[0].length)}`;
|
|
120
|
+
return { storyPath, stateBefore, stateAfter, storyBefore, storyAfter };
|
|
121
|
+
}
|
|
122
|
+
function physical(plan, sourceRoot, projection) {
|
|
123
|
+
const cwd = realpathSync(plan.worktreePath);
|
|
124
|
+
if (plan.epicId !== plan.storyId.split('.')[0]
|
|
125
|
+
|| plan.branch !== `story/${plan.epicId}/${plan.storyId}`
|
|
126
|
+
|| !/^[A-Za-z0-9][A-Za-z0-9_-]*$/.test(plan.epicId)
|
|
127
|
+
|| !git(sourceRoot, ['check-ref-format', '--branch', plan.branch])
|
|
128
|
+
|| !git(sourceRoot, ['check-ref-format', '--branch', plan.baseBranch])) {
|
|
129
|
+
throw new Error('legacy-branch-checkpoint-plan-invalid');
|
|
130
|
+
}
|
|
131
|
+
const common = (path) => realpathSync(resolve(path, git(path, ['rev-parse', '--git-common-dir'])));
|
|
132
|
+
const worktrees = git(sourceRoot, ['worktree', 'list', '--porcelain']).split(/\n\n+/)
|
|
133
|
+
.filter((block) => block.split('\n').includes(`branch refs/heads/${plan.branch}`));
|
|
134
|
+
if (cwd !== plan.worktreePath || worktrees.length !== 1
|
|
135
|
+
|| !worktrees[0].split('\n').includes(`worktree ${cwd}`)
|
|
136
|
+
|| worktrees[0].split('\n').some((line) => line.startsWith('locked') || line.startsWith('prunable'))
|
|
137
|
+
|| common(cwd) !== common(sourceRoot)
|
|
138
|
+
|| realpathSync(git(cwd, ['rev-parse', '--show-toplevel'])) !== cwd
|
|
139
|
+
|| git(cwd, ['symbolic-ref', '--quiet', '--short', 'HEAD']) !== plan.branch
|
|
140
|
+
|| git(cwd, ['rev-parse', 'HEAD']) !== plan.baseHeadSha
|
|
141
|
+
|| git(cwd, ['rev-parse', `refs/heads/${plan.branch}`]) !== plan.baseHeadSha
|
|
142
|
+
|| git(cwd, ['rev-parse', `refs/remotes/origin/${plan.baseBranch}`]) !== plan.baseHeadSha) {
|
|
143
|
+
throw new Error('legacy-branch-checkpoint-physical-mismatch');
|
|
144
|
+
}
|
|
145
|
+
const stateCurrent = safeRead(join(cwd, '.neocortex/state.json'));
|
|
146
|
+
const storyCurrent = safeRead(join(cwd, projection.storyPath));
|
|
147
|
+
if (![projection.stateBefore, projection.stateAfter].includes(stateCurrent)
|
|
148
|
+
|| ![projection.storyBefore, projection.storyAfter].includes(storyCurrent)) {
|
|
149
|
+
throw new Error('legacy-branch-checkpoint-preimage-conflict');
|
|
150
|
+
}
|
|
151
|
+
const statuses = gitRaw(cwd, ['status', '--porcelain=v1', '-uall']);
|
|
152
|
+
if (statuses.split('\n').filter(Boolean).some((line) => {
|
|
153
|
+
if (!line.startsWith(' M '))
|
|
154
|
+
return true;
|
|
155
|
+
const path = line.slice(3);
|
|
156
|
+
return path !== '.neocortex/state.json' && path !== projection.storyPath;
|
|
157
|
+
}))
|
|
158
|
+
throw new Error('legacy-branch-checkpoint-worktree-dirty');
|
|
159
|
+
return { stateCurrent, storyCurrent };
|
|
160
|
+
}
|
|
161
|
+
async function privateDirectory(projectRoot) {
|
|
162
|
+
return ensureGitLifecyclePrivateChildDirectory(await gitLifecycleRuntimeDirectory(projectRoot), 'legacy-story-branch-intents');
|
|
163
|
+
}
|
|
164
|
+
function journalName(storyId) { return `${digest(storyId)}.c01.json`; }
|
|
165
|
+
function acceptedName(storyId) { return `${digest(storyId)}.c01.accepted.json`; }
|
|
166
|
+
async function readPrivateJson(directory, name) {
|
|
167
|
+
const path = join(directory, name);
|
|
168
|
+
if (!existsSync(path))
|
|
169
|
+
return null;
|
|
170
|
+
await assertGitLifecyclePrivateFile(path, directory);
|
|
171
|
+
const raw = safeRead(path);
|
|
172
|
+
if (raw.length > 4096)
|
|
173
|
+
throw new Error('legacy-branch-checkpoint-journal-invalid');
|
|
174
|
+
return JSON.parse(raw);
|
|
175
|
+
}
|
|
176
|
+
async function writePrivateJson(directory, name, value) {
|
|
177
|
+
await anchoredAtomicWriteFile(directory, name, `${JSON.stringify(value)}\n`);
|
|
178
|
+
await assertGitLifecyclePrivateFile(join(directory, name), directory);
|
|
179
|
+
}
|
|
180
|
+
export async function acceptLegacyStoryBranchC01(options) {
|
|
181
|
+
if (!Number.isSafeInteger(options.issueNumber) || options.issueNumber <= 0) {
|
|
182
|
+
return fail('legacy-branch-issue-number-invalid');
|
|
183
|
+
}
|
|
184
|
+
const sessionId = `legacy-c01-${randomBytes(16).toString('hex')}`;
|
|
185
|
+
const lock = await acquireGitLifecyclePhysicalIntegrationLock(options.projectRoot, {
|
|
186
|
+
kind: 'direct', storyId: options.storyId, sessionId, idempotencyKey: sessionId,
|
|
187
|
+
expiresAt: new Date(Date.now() + 5 * 60_000).toISOString(), persistent: false,
|
|
188
|
+
});
|
|
189
|
+
if (!lock.ok)
|
|
190
|
+
return fail(lock.reasonCode);
|
|
191
|
+
try {
|
|
192
|
+
const completed = await readCompletedLegacyStoryBranchPlan(options);
|
|
193
|
+
if (!completed.ok)
|
|
194
|
+
return completed;
|
|
195
|
+
const plan = completed.value;
|
|
196
|
+
const sourceRoot = realpathSync(options.projectRoot);
|
|
197
|
+
const projection = project(plan, options.issueNumber);
|
|
198
|
+
const before = physical(plan, sourceRoot, projection);
|
|
199
|
+
const repo = repository(sourceRoot);
|
|
200
|
+
const directory = await privateDirectory(sourceRoot);
|
|
201
|
+
const journal = {
|
|
202
|
+
schemaVersion: 1, kind: 'legacy-story-c01-acceptance-intent', storyId: plan.storyId,
|
|
203
|
+
planDigest: digest(JSON.stringify(plan)), repository: repo, issueNumber: options.issueNumber,
|
|
204
|
+
stateBefore: digest(projection.stateBefore), stateAfter: digest(projection.stateAfter),
|
|
205
|
+
storyBefore: digest(projection.storyBefore), storyAfter: digest(projection.storyAfter),
|
|
206
|
+
};
|
|
207
|
+
const existing = await readPrivateJson(directory, journalName(plan.storyId));
|
|
208
|
+
if (existing && JSON.stringify(existing) !== JSON.stringify(journal)) {
|
|
209
|
+
return fail('legacy-branch-checkpoint-journal-conflict');
|
|
210
|
+
}
|
|
211
|
+
if (!existing && (before.stateCurrent !== projection.stateBefore
|
|
212
|
+
|| before.storyCurrent !== projection.storyBefore)) {
|
|
213
|
+
return fail('legacy-branch-checkpoint-unjournaled-drift');
|
|
214
|
+
}
|
|
215
|
+
const accepted = await readPrivateJson(directory, acceptedName(plan.storyId));
|
|
216
|
+
if (accepted && JSON.stringify(accepted) !== JSON.stringify(journal)) {
|
|
217
|
+
return fail('legacy-branch-checkpoint-accepted-conflict');
|
|
218
|
+
}
|
|
219
|
+
const issue = await (options.verifyIssue ?? ghIssueVerifier)(repo, options.issueNumber);
|
|
220
|
+
validateIssue(issue, repo, plan.storyId, options.issueNumber, Boolean(accepted));
|
|
221
|
+
if (!existing)
|
|
222
|
+
await writePrivateJson(directory, journalName(plan.storyId), journal);
|
|
223
|
+
const beforeWrite = physical(plan, sourceRoot, projection);
|
|
224
|
+
if (accepted && (beforeWrite.stateCurrent !== projection.stateAfter
|
|
225
|
+
|| beforeWrite.storyCurrent !== projection.storyAfter)) {
|
|
226
|
+
return fail('legacy-branch-checkpoint-accepted-physical-mismatch');
|
|
227
|
+
}
|
|
228
|
+
if (beforeWrite.stateCurrent === projection.stateBefore) {
|
|
229
|
+
await anchoredCompareAndSwapFile(join(plan.worktreePath, '.neocortex'), 'state.json', projection.stateAfter, journal.stateBefore);
|
|
230
|
+
await options.afterStatePersist?.();
|
|
231
|
+
}
|
|
232
|
+
const middle = physical(plan, sourceRoot, projection);
|
|
233
|
+
if (middle.storyCurrent === projection.storyBefore) {
|
|
234
|
+
await anchoredCompareAndSwapFile(join(plan.worktreePath, 'docs/stories'), `${plan.storyId}.story.md`, projection.storyAfter, journal.storyBefore);
|
|
235
|
+
await options.afterStoryPersist?.();
|
|
236
|
+
}
|
|
237
|
+
const after = physical(plan, sourceRoot, projection);
|
|
238
|
+
if (after.stateCurrent !== projection.stateAfter || after.storyCurrent !== projection.storyAfter) {
|
|
239
|
+
return fail('legacy-branch-checkpoint-post-write-mismatch');
|
|
240
|
+
}
|
|
241
|
+
if (!accepted)
|
|
242
|
+
await writePrivateJson(directory, acceptedName(plan.storyId), journal);
|
|
243
|
+
return { ok: true, value: Object.freeze({
|
|
244
|
+
schemaVersion: 1, kind: 'legacy-story-c01-checkpoint', storyId: plan.storyId,
|
|
245
|
+
epicId: plan.epicId, branch: plan.branch, issueNumber: options.issueNumber,
|
|
246
|
+
repository: repo, stateSha256: journal.stateAfter, storySha256: journal.storyAfter,
|
|
247
|
+
reused: Boolean(accepted), checkpointAccepted: true, localOnly: true,
|
|
248
|
+
}) };
|
|
249
|
+
}
|
|
250
|
+
catch (error) {
|
|
251
|
+
const message = error instanceof Error ? error.message : '';
|
|
252
|
+
return fail(message.startsWith('legacy-branch-') ? message
|
|
253
|
+
: message.includes('secure-filesystem-cas-conflict') ? 'legacy-branch-checkpoint-write-raced'
|
|
254
|
+
: 'legacy-branch-checkpoint-failed');
|
|
255
|
+
}
|
|
256
|
+
finally {
|
|
257
|
+
await releaseGitLifecyclePhysicalIntegrationLock(lock.path, lock.owner).catch(() => undefined);
|
|
258
|
+
}
|
|
259
|
+
}
|