@ornexus/neocortex 4.60.81 → 4.61.2

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.
Files changed (53) hide show
  1. package/dist/release-source.json +1 -1
  2. package/install.ps1 +33 -1
  3. package/install.sh +35 -1
  4. package/package.json +2 -2
  5. package/packages/client/dist/adapters/platform-detector.d.ts +1 -1
  6. package/packages/client/dist/adapters/platform-detector.js +6 -0
  7. package/packages/client/dist/cli.js +7 -0
  8. package/packages/client/dist/commands/invoke.d.ts +15 -8
  9. package/packages/client/dist/commands/invoke.js +75 -1
  10. package/packages/client/dist/commands/story-checkpoint.d.ts +2 -1
  11. package/packages/client/dist/commands/story-checkpoint.js +34 -2
  12. package/packages/client/dist/commands/story-worktree.d.ts +46 -0
  13. package/packages/client/dist/commands/story-worktree.js +258 -0
  14. package/packages/client/dist/config.js +1 -0
  15. package/packages/client/dist/git/direct-yolo-checkpoint.d.ts +46 -0
  16. package/packages/client/dist/git/direct-yolo-checkpoint.js +137 -1
  17. package/packages/client/dist/git/git-lifecycle-store.d.ts +84 -0
  18. package/packages/client/dist/git/git-lifecycle-store.js +314 -4
  19. package/packages/client/dist/git/story-worktree-cleanup.d.ts +226 -0
  20. package/packages/client/dist/git/story-worktree-cleanup.js +1058 -0
  21. package/packages/client/dist/git/story-worktree-integration.d.ts +91 -0
  22. package/packages/client/dist/git/story-worktree-integration.js +603 -0
  23. package/packages/client/dist/git/story-worktree-manager.d.ts +205 -0
  24. package/packages/client/dist/git/story-worktree-manager.js +843 -0
  25. package/packages/client/dist/git/story-worktree-paths.d.ts +65 -0
  26. package/packages/client/dist/git/story-worktree-paths.js +150 -0
  27. package/packages/client/dist/policy/subagent-approval-policy.js +3 -1
  28. package/packages/client/dist/runner/headless/continuous-story-workspace.d.ts +49 -1
  29. package/packages/client/dist/runner/headless/continuous-story-workspace.js +175 -27
  30. package/packages/client/dist/runner/headless/run-yoloop.d.ts +39 -0
  31. package/packages/client/dist/runner/headless/run-yoloop.js +71 -0
  32. package/packages/client/dist/runner-cli.js +0 -0
  33. package/packages/client/dist/state/project-state-snapshot.js +3 -0
  34. package/packages/shared/dist/yoloop/epic-terminal-git.js +27 -3
  35. package/targets-stubs/antigravity/gemini.md +1 -1
  36. package/targets-stubs/antigravity/neocortex.md +21 -0
  37. package/targets-stubs/antigravity/skill/SKILL.md +1 -1
  38. package/targets-stubs/claude-code/README.md +17 -0
  39. package/targets-stubs/claude-code/neocortex-root.agent.yaml +1 -1
  40. package/targets-stubs/claude-code/neocortex-root.md +57 -49
  41. package/targets-stubs/claude-code/neocortex.agent.yaml +1 -1
  42. package/targets-stubs/claude-code/neocortex.md +28 -25
  43. package/targets-stubs/codex/AGENTS.md +31 -30
  44. package/targets-stubs/codex/neocortex.toml +10 -0
  45. package/targets-stubs/cursor/agent.md +13 -2
  46. package/targets-stubs/deepseek-harness/SKILL.md +13 -0
  47. package/targets-stubs/gemini-cli/agent.md +23 -2
  48. package/targets-stubs/grok/SKILL.md +21 -0
  49. package/targets-stubs/kimi/neocortex.md +21 -0
  50. package/targets-stubs/openclaw/SKILL.md +21 -0
  51. package/targets-stubs/opencode/neocortex-root.md +19 -15
  52. package/targets-stubs/opencode/neocortex.md +10 -0
  53. package/targets-stubs/vscode/neocortex.agent.md +13 -2
@@ -1 +1 @@
1
- {"schemaVersion":1,"sourceRevision":"aa1f1b122b43a66839b1d6c89de1acc78e385fd1","version":"4.60.81"}
1
+ {"schemaVersion":1,"sourceRevision":"760643f0a318ff9a1931e379bdd242f509bfb438","version":"4.61.2"}
package/install.ps1 CHANGED
@@ -17,7 +17,7 @@ param(
17
17
  [string]$ServerUrl = ('https://{0}.{1}.{2}' -f 'api','neocortex','sh')
18
18
  )
19
19
 
20
- $VERSION = "4.60.81"
20
+ $VERSION = "4.61.2"
21
21
 
22
22
  # =============================================================================
23
23
  # CONFIGURACOES
@@ -469,6 +469,37 @@ function Read-HostWithTimeout {
469
469
  # BANNER
470
470
  # =============================================================================
471
471
 
472
+ # P225.09 (AC5): warn-only Git preflight for story worktrees. `worktree remove`
473
+ # and `extensions.worktreeConfig` need Git >= 2.20. Read-only: never runs
474
+ # `git config --global`, never sets core.longpaths and never changes the registry.
475
+ function Test-GitWorktreeSupport {
476
+ $minimum = [version]'2.20'
477
+ $gitCommand = Get-Command git -ErrorAction SilentlyContinue
478
+ if (-not $gitCommand) {
479
+ Write-InstallerDiagnostic -Phase "git-preflight" -Status "warning" -ReasonCode "P225_GIT_PREFLIGHT_MISSING" -Summary "git_not_found" -DocPath "docs/epics/epic-P225.md"
480
+ Write-Warn "P225_GIT_PREFLIGHT_MISSING: Git nao encontrado; worktrees paralelos por story exigem Git >= 2.20. Instalacao continua."
481
+ } else {
482
+ $versionText = ''
483
+ try { $versionText = [string](& git --version 2>$null | Select-Object -First 1) } catch { $versionText = '' }
484
+ $parsed = $null
485
+ if ($versionText -match '(\d+)\.(\d+)') { $parsed = [version]("{0}.{1}" -f $Matches[1], $Matches[2]) }
486
+ if (-not $parsed -or $parsed -lt $minimum) {
487
+ Write-InstallerDiagnostic -Phase "git-preflight" -Status "warning" -ReasonCode "P225_GIT_PREFLIGHT_VERSION_LOW" -Summary "git_version_below_minimum" -DocPath "docs/epics/epic-P225.md"
488
+ Write-Warn "P225_GIT_PREFLIGHT_VERSION_LOW: worktrees paralelos por story exigem Git >= 2.20; *yoloop mantem o plano atual. Instalacao continua."
489
+ }
490
+ }
491
+ if ([System.Environment]::OSVersion.Platform -eq [System.PlatformID]::Win32NT) {
492
+ $longPaths = $null
493
+ try {
494
+ $longPaths = (Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem' -Name 'LongPathsEnabled' -ErrorAction Stop).LongPathsEnabled
495
+ } catch { $longPaths = $null }
496
+ if ($longPaths -ne 1) {
497
+ Write-InstallerDiagnostic -Phase "git-preflight" -Status "warning" -ReasonCode "P225_WINDOWS_LONG_PATHS_DISABLED" -Summary "windows_long_paths_disabled" -DocPath "docs/epics/epic-P225.md"
498
+ Write-Warn "P225_WINDOWS_LONG_PATHS_DISABLED: caminhos longos do Windows desativados; worktrees usam caminhos curtos. Nenhuma configuracao global foi alterada."
499
+ }
500
+ }
501
+ }
502
+
472
503
  function Show-Banner {
473
504
  if ($QUIET_MODE) { return }
474
505
  if ($NO_BANNER) { return }
@@ -1959,6 +1990,7 @@ function Show-Result {
1959
1990
  # =============================================================================
1960
1991
 
1961
1992
  Show-Banner
1993
+ Test-GitWorktreeSupport
1962
1994
  Get-SourceDirectory
1963
1995
  Test-OldInstallation
1964
1996
 
package/install.sh CHANGED
@@ -4,7 +4,7 @@
4
4
  # Development Orchestrator
5
5
 
6
6
  # Versao do instalador
7
- VERSION="4.60.81"
7
+ VERSION="4.61.2"
8
8
 
9
9
  # Flags
10
10
  MIGRATION_DETECTED=false
@@ -296,6 +296,39 @@ warn_linux_root_home_context() {
296
296
  fi
297
297
  }
298
298
 
299
+ # P225.09 (AC5): warn-only Git preflight for story worktrees (`worktree remove`
300
+ # and `extensions.worktreeConfig` need Git >= 2.20). Read-only: it never runs
301
+ # `git config --global` and never changes system settings.
302
+ P225_GIT_MIN_MAJOR=2
303
+ P225_GIT_MIN_MINOR=20
304
+
305
+ git_version_supports_story_worktrees() {
306
+ local version_text="$1" major minor
307
+ version_text="${version_text#git version }"
308
+ major="$(printf '%s' "$version_text" | cut -d. -f1 | tr -cd '0-9')"
309
+ minor="$(printf '%s' "$version_text" | cut -d. -f2 | tr -cd '0-9')"
310
+ [ -n "$major" ] && [ -n "$minor" ] || return 1
311
+ [ "$major" -gt "$P225_GIT_MIN_MAJOR" ] && return 0
312
+ [ "$major" -eq "$P225_GIT_MIN_MAJOR" ] && [ "$minor" -ge "$P225_GIT_MIN_MINOR" ]
313
+ }
314
+
315
+ preflight_git_worktree_support() {
316
+ local version_text
317
+ if ! command -v git >/dev/null 2>&1; then
318
+ emit_installer_diagnostic "neocortex" "git-preflight" "warning" "P225_GIT_PREFLIGHT_MISSING" "null" "null" "false" "0" "0" "git_not_found" "docs/epics/epic-P225.md"
319
+ warn "P225_GIT_PREFLIGHT_MISSING: Git not found; parallel story worktrees need Git >= ${P225_GIT_MIN_MAJOR}.${P225_GIT_MIN_MINOR}. Installation continues."
320
+ return 0
321
+ fi
322
+ version_text="$(git --version 2>/dev/null | head -n 1)"
323
+ if ! git_version_supports_story_worktrees "$version_text"; then
324
+ emit_installer_diagnostic "neocortex" "git-preflight" "warning" "P225_GIT_PREFLIGHT_VERSION_LOW" "null" "null" "false" "0" "0" "git_version_below_minimum" "docs/epics/epic-P225.md"
325
+ warn "P225_GIT_PREFLIGHT_VERSION_LOW: parallel story worktrees need Git >= ${P225_GIT_MIN_MAJOR}.${P225_GIT_MIN_MINOR}; *yoloop keeps the current plan. Installation continues."
326
+ return 0
327
+ fi
328
+ debug "Git preflight ok for story worktrees"
329
+ return 0
330
+ }
331
+
299
332
  is_neocortex_source_project() {
300
333
  local candidate_dir="$1"
301
334
  local package_file="$candidate_dir/package.json"
@@ -1988,6 +2021,7 @@ TOTAL_STEPS=4
1988
2021
  main() {
1989
2022
  show_banner
1990
2023
  warn_linux_root_home_context
2024
+ preflight_git_worktree_support
1991
2025
  detect_source_dir
1992
2026
  detect_old_installation
1993
2027
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ornexus/neocortex",
3
- "version": "4.60.81",
4
- "description": "Neocortex v4.60.81",
3
+ "version": "4.61.2",
4
+ "description": "Neocortex v4.61.2",
5
5
  "keywords": [
6
6
  "claude",
7
7
  "claude-code",
@@ -18,7 +18,7 @@
18
18
  */
19
19
  import type { NativeHostAttestationV1 } from '../continuity/native-agent-types.js';
20
20
  /** Supported platform target identifiers */
21
- export type TargetId = 'claude-code' | 'cursor' | 'vscode' | 'gemini' | 'codex' | 'opencode' | 'github-copilot-cli' | 'kimi' | 'antigravity' | 'openclaw' | 'grok' | 'runner' | 'unknown';
21
+ export type TargetId = 'claude-code' | 'cursor' | 'vscode' | 'gemini' | 'codex' | 'opencode' | 'github-copilot-cli' | 'kimi' | 'antigravity' | 'openclaw' | 'grok' | 'deepseek' | 'runner' | 'unknown';
22
22
  /** Context provided to the platform detector */
23
23
  export interface DetectionContext {
24
24
  readonly cwd: string;
@@ -74,6 +74,7 @@ const VALID_TARGETS = new Set([
74
74
  'antigravity',
75
75
  'openclaw',
76
76
  'grok',
77
+ 'deepseek',
77
78
  'runner',
78
79
  'unknown',
79
80
  ]);
@@ -96,6 +97,11 @@ const TARGET_ALIASES = Object.freeze({
96
97
  'open-claw': 'openclaw',
97
98
  grok: 'grok',
98
99
  'grok-build': 'grok',
100
+ // P225.09 (RQ-05): explicit `--platform-target deepseek` for DeepSeek Harness.
101
+ deepseek: 'deepseek',
102
+ 'deepseek-harness': 'deepseek',
103
+ deepseek_harness: 'deepseek',
104
+ dsh: 'deepseek',
99
105
  runner: 'runner',
100
106
  unknown: 'unknown',
101
107
  });
@@ -48,6 +48,7 @@ Commands:
48
48
  planning-memory <seal|verify> Seal reviewed committed memory or reopen its physical receipt
49
49
  private-session <inspect-rejected|discard-rejected|renew-lease|accept-diagnosis|accept-research|accept-specification|accept-tasks|validate-implementation|accept-implementation|accept-refactor-advisory|accept-test-validation|accept-qa|accept-project-memory> Root recovery and phase validation
50
50
  story-checkpoint Root-owned direct-*yolo commit/checkpoint boundary
51
+ story-worktree <create|adopt|sync|status|release> P225 temporary story worktree lifecycle (public-safe JSON)
51
52
  legacy-story-branch Root-owned setup and C01 checkpoint for recorded story-branch projects
52
53
  legacy-story-pr Root-owned legacy C08/C09 checkpoint, C10 PR, C11 review and C12 merge boundary
53
54
  legacy-epic-terminal Physical C12 preflight and root QA acceptance; never releases quota
@@ -475,6 +476,12 @@ async function main() {
475
476
  process.exit(exitCode);
476
477
  break;
477
478
  }
479
+ case 'story-worktree': {
480
+ const { storyWorktreeCliHandler } = await import('./commands/story-worktree.js');
481
+ const exitCode = await storyWorktreeCliHandler(subArgs);
482
+ process.exit(exitCode);
483
+ break;
484
+ }
478
485
  case 'legacy-story-branch': {
479
486
  const { legacyStoryBranchCliHandler } = await import('./commands/legacy-story-branch.js');
480
487
  const exitCode = await legacyStoryBranchCliHandler(subArgs);
@@ -775,16 +775,23 @@ export declare function reconcileInvalidatedYoloopSession(input: {
775
775
  readonly originalInputSha256: string;
776
776
  readonly canonicalInputSha256: string;
777
777
  }): Promise<YoloopInvalidatedSessionRecoveryResultV1>;
778
+ /** One in-call wait stays below common host tool timeouts; the root re-dispatches after it. */
779
+ export declare const STORY_WORKTREE_BARRIER_CLIENT_MAX_WAIT_MS = 90000;
780
+ export declare const STORY_WORKTREE_BARRIER_CLIENT_MAX_ATTEMPTS = 6;
781
+ export declare function isStoryWorktreePhaseOneInvocation(args: unknown): args is string;
782
+ export interface StoryWorktreeBarrierPollingOptions {
783
+ readonly sleep?: (ms: number) => Promise<void>;
784
+ readonly now?: () => number;
785
+ readonly maxWaitMs?: number;
786
+ readonly maxAttempts?: number;
787
+ }
778
788
  /**
779
- * Execute the invoke command.
780
- *
781
- * Flow:
782
- * 1. Load config to get server URL
783
- * 2. Collect state snapshot from project root
784
- * 3. Check menu cache for empty invocations
785
- * 4. Send POST /api/v1/invoke
786
- * 5. Format and return result
789
+ * P225.04 (P225-CON-PHASE): bounded client polling of the server C04 barrier.
790
+ * Each attempt re-sends the identical argument bytes; the server decides. On
791
+ * exhaustion the root receives a resumable receipt and re-dispatches the same
792
+ * phase-1 prompt, which resumes at C05.
787
793
  */
794
+ export declare function pollStoryWorktreeSpecBarrier(args: string, attempt: (args: string) => Promise<InvokeResult>, options?: StoryWorktreeBarrierPollingOptions): Promise<InvokeResult>;
788
795
  export declare function invoke(options: InvokeOptions): Promise<InvokeResult>;
789
796
  /**
790
797
  * Extract the canonical trigger for client-side pre-flight checks.
@@ -72,7 +72,7 @@ import { probeProjectIdentityMigrationCapability } from '../migrations/project-i
72
72
  import { normalizeYoloopStoryPlanningEvidence } from '../../../shared/dist/yoloop/planning-graph.js';
73
73
  import { normalizeContinuousWriteRef } from '../../../shared/dist/yoloop/wave-decision-receipt.js';
74
74
  import { epicHeadReconciliationInputDigest, epicHeadReconciliationPathsDigest, epicHeadReconciliationRangeDigest, } from '../../../shared/dist/yoloop/epic-terminal-git.js';
75
- import { applyGitLifecycleRuntimeOverlay, classifyGitLifecycleStoryCheckpointProjectionSync, ensureRuntimeEpic, ensureGitLifecycleRuntimeInitialized, executeP205TransientAuthorities, persistGitLifecycleGraphAuthority, P205_COMPLETE_COMMAND, gitLifecycleStoryWriteSet, mutateGitLifecycleRuntime, projectP205TransientExecutionEvidence, readGitLifecycleRuntimeSync, verifyLegacyCheckpointMigrationCandidateSync, } from '../git/git-lifecycle-store.js';
75
+ import { applyGitLifecycleRuntimeOverlay, classifyGitLifecycleStoryCheckpointProjectionSync, ensureRuntimeEpic, ensureGitLifecycleRuntimeInitialized, executeP205TransientAuthorities, persistGitLifecycleGraphAuthority, P205_COMPLETE_COMMAND, gitLifecycleStoryWriteSet, isStoryWorktreeEvidenceContainer, mutateGitLifecycleRuntime, projectP205TransientExecutionEvidence, readGitLifecycleRuntimeSync, verifyLegacyCheckpointMigrationCandidateSync, } from '../git/git-lifecycle-store.js';
76
76
  import { verifyRootMemoryPhysicalWriteSet } from '../private-execution/root-memory-git-evidence.js';
77
77
  import { isRootProjectMemoryEffect } from '../private-execution/shared-root-memory-types.js';
78
78
  import { probeYoloInvokeEnvelopeCapability } from '../yolo/invoke-envelope-capability.js';
@@ -2216,6 +2216,11 @@ export function collectStateSnapshot(projectRoot, options = {}) {
2216
2216
  ...(sanitizeEpicHeadReconciliationReceipt(epic.head_reconciliation_receipt)
2217
2217
  ? { head_reconciliation_receipt: sanitizeEpicHeadReconciliationReceipt(epic.head_reconciliation_receipt) }
2218
2218
  : {}),
2219
+ // P225: the server reads phase receipts and spec acceptances from here;
2220
+ // the container is closed and bounded, so it is forwarded only when valid.
2221
+ ...(isStoryWorktreeEvidenceContainer(epic.story_worktree_evidence)
2222
+ ? { story_worktree_evidence: structuredClone(epic.story_worktree_evidence) }
2223
+ : {}),
2219
2224
  ...(publicNumber(epic.pr_number) ? { pr_number: publicNumber(epic.pr_number) } : {}),
2220
2225
  ...(publicString(epic.physicalMergeStatus) ? { physicalMergeStatus: publicString(epic.physicalMergeStatus) } : {}),
2221
2226
  ...(publicSha(epic.graph_revision) ? { graph_revision: publicSha(epic.graph_revision) } : {}),
@@ -4767,7 +4772,76 @@ export async function reconcileInvalidatedYoloopSession(input) {
4767
4772
  * 4. Send POST /api/v1/invoke
4768
4773
  * 5. Format and return result
4769
4774
  */
4775
+ /** P225.04: closed phase-1 child form; only this form is polled at the C04 barrier. */
4776
+ const STORY_WORKTREE_PHASE_ONE_ARGS = /^\*yolo @docs\/stories\/[A-Za-z0-9][A-Za-z0-9._-]{0,79}\.story\.md story-worktree-phase-1$/;
4777
+ /** One in-call wait stays below common host tool timeouts; the root re-dispatches after it. */
4778
+ export const STORY_WORKTREE_BARRIER_CLIENT_MAX_WAIT_MS = 90_000;
4779
+ export const STORY_WORKTREE_BARRIER_CLIENT_MAX_ATTEMPTS = 6;
4780
+ const STORY_WORKTREE_BARRIER_MIN_RETRY_MS = 1_000;
4781
+ export function isStoryWorktreePhaseOneInvocation(args) {
4782
+ return typeof args === 'string' && STORY_WORKTREE_PHASE_ONE_ARGS.test(args) && !args.includes('..');
4783
+ }
4784
+ function storyWorktreeBarrierWait(result) {
4785
+ const phase = result.metadata?.storyWorktreePhase;
4786
+ if (!result.success || !phase || typeof phase !== 'object' || Array.isArray(phase))
4787
+ return undefined;
4788
+ const record = phase;
4789
+ return record.decision === 'spec-barrier-waiting' && record.phase === 'phase-1' ? record : undefined;
4790
+ }
4791
+ /**
4792
+ * P225.04 (P225-CON-PHASE): bounded client polling of the server C04 barrier.
4793
+ * Each attempt re-sends the identical argument bytes; the server decides. On
4794
+ * exhaustion the root receives a resumable receipt and re-dispatches the same
4795
+ * phase-1 prompt, which resumes at C05.
4796
+ */
4797
+ export async function pollStoryWorktreeSpecBarrier(args, attempt, options = {}) {
4798
+ const sleep = options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
4799
+ const now = options.now ?? Date.now;
4800
+ const maxAttempts = Math.max(1, Math.min(options.maxAttempts ?? STORY_WORKTREE_BARRIER_CLIENT_MAX_ATTEMPTS, STORY_WORKTREE_BARRIER_CLIENT_MAX_ATTEMPTS));
4801
+ const clientMaxWait = Math.max(0, Math.min(options.maxWaitMs ?? STORY_WORKTREE_BARRIER_CLIENT_MAX_WAIT_MS, STORY_WORKTREE_BARRIER_CLIENT_MAX_WAIT_MS));
4802
+ const startedAt = now();
4803
+ let attempts = 0;
4804
+ for (;;) {
4805
+ const result = await attempt(args);
4806
+ attempts += 1;
4807
+ const waiting = storyWorktreeBarrierWait(result);
4808
+ if (!waiting)
4809
+ return result;
4810
+ const serverMaxWait = typeof waiting.maxWaitMs === 'number' && Number.isFinite(waiting.maxWaitMs) ? waiting.maxWaitMs : 0;
4811
+ const maxWait = Math.min(clientMaxWait, Math.max(0, serverMaxWait));
4812
+ const requested = typeof waiting.retryAfterMs === 'number' && Number.isFinite(waiting.retryAfterMs) ? waiting.retryAfterMs : 0;
4813
+ const retryAfter = Math.min(Math.max(requested, STORY_WORKTREE_BARRIER_MIN_RETRY_MS), maxWait);
4814
+ const elapsed = now() - startedAt;
4815
+ if (attempts >= maxAttempts || elapsed + retryAfter > maxWait) {
4816
+ return {
4817
+ success: true,
4818
+ instructions: '# Story-worktree spec barrier timeout\n\nThe C04 barrier did not open within the bounded wait. '
4819
+ + 'Return this resumable receipt to the root; the root re-dispatches the same phase-1 prompt, which resumes at C05. '
4820
+ + 'No C05 step was executed.\n\n[STORY_WORKTREE_SPEC_BARRIER_TIMEOUT]',
4821
+ metadata: {
4822
+ ...result.metadata,
4823
+ storyWorktreePhase: {
4824
+ ...waiting,
4825
+ decision: 'spec-barrier-timeout',
4826
+ reasonCode: 'spec-barrier-waiting',
4827
+ resumable: true,
4828
+ attempts,
4829
+ waitedMs: Math.max(0, elapsed),
4830
+ publicSafe: true,
4831
+ },
4832
+ },
4833
+ exitCode: 0,
4834
+ };
4835
+ }
4836
+ await sleep(retryAfter);
4837
+ }
4838
+ }
4770
4839
  export async function invoke(options) {
4840
+ if (!isStoryWorktreePhaseOneInvocation(options.args))
4841
+ return invokeOnce(options);
4842
+ return pollStoryWorktreeSpecBarrier(options.args, () => invokeOnce(options));
4843
+ }
4844
+ async function invokeOnce(options) {
4771
4845
  // P205.07: admission is physically first. A rejected envelope cannot reach
4772
4846
  // random IDs, config/state repair, caches, retrieval, auth, quota or network.
4773
4847
  let explicitInputEnvelope;
@@ -1,4 +1,4 @@
1
- type StoryCheckpointAction = 'setup' | 'accept-setup' | 'handoff' | 'begin' | 'finalize' | 'recover' | 'retry-c01';
1
+ type StoryCheckpointAction = 'setup' | 'accept-setup' | 'handoff' | 'begin' | 'finalize' | 'recover' | 'retry-c01' | 'integrate-worktree';
2
2
  interface StoryCheckpointCliOptions {
3
3
  readonly action: StoryCheckpointAction;
4
4
  readonly storyId: string;
@@ -11,6 +11,7 @@ interface StoryCheckpointCliOptions {
11
11
  readonly setupHandoffTokenFile?: string;
12
12
  readonly expectedHeadSha?: string;
13
13
  readonly apply?: boolean;
14
+ readonly leaseId?: string;
14
15
  }
15
16
  export declare function parseStoryCheckpointArgs(args: readonly string[]): StoryCheckpointCliOptions;
16
17
  export declare function storyCheckpointCliHandler(args: readonly string[]): Promise<number>;
@@ -2,9 +2,11 @@ import { readFile } from 'node:fs/promises';
2
2
  import { resolve } from 'node:path';
3
3
  import { acceptDirectYoloSetupCheckpoint, beginDirectYoloStoryCommit, finalizeDirectYoloStoryCheckpoint, issueDirectYoloSetupLeaseHandoff, prepareDirectYoloSetup, recoverLegacyDirectYoloStoryCheckpoint, } from '../git/direct-yolo-checkpoint.js';
4
4
  import { applyDirectYoloC01Retry, inspectDirectYoloC01Retry } from '../git/direct-yolo-c01-retry.js';
5
+ import { integrateStoryWorktree } from '../git/story-worktree-integration.js';
5
6
  export function parseStoryCheckpointArgs(args) {
6
7
  const action = args[0];
7
- if (action !== 'setup' && action !== 'accept-setup' && action !== 'handoff' && action !== 'begin' && action !== 'finalize' && action !== 'recover' && action !== 'retry-c01') {
8
+ if (action !== 'setup' && action !== 'accept-setup' && action !== 'handoff' && action !== 'begin' && action !== 'finalize'
9
+ && action !== 'recover' && action !== 'retry-c01' && action !== 'integrate-worktree') {
8
10
  throw new Error('story-checkpoint-action-invalid');
9
11
  }
10
12
  let storyId = '';
@@ -17,6 +19,7 @@ export function parseStoryCheckpointArgs(args) {
17
19
  let setupHandoffTokenFile;
18
20
  let expectedHeadSha;
19
21
  let apply = false;
22
+ let leaseId;
20
23
  for (let index = 1; index < args.length; index++) {
21
24
  const arg = args[index];
22
25
  const next = () => args[++index] ?? '';
@@ -52,6 +55,10 @@ export function parseStoryCheckpointArgs(args) {
52
55
  expectedHeadSha = arg.slice('--expected-head='.length);
53
56
  else if (arg === '--apply')
54
57
  apply = true;
58
+ else if (arg === '--lease')
59
+ leaseId = next();
60
+ else if (arg.startsWith('--lease='))
61
+ leaseId = arg.slice('--lease='.length);
55
62
  else if (arg === '--format') {
56
63
  const value = next();
57
64
  if (value !== 'json' && value !== 'plain')
@@ -76,6 +83,11 @@ export function parseStoryCheckpointArgs(args) {
76
83
  throw new Error('story-checkpoint-remote-proof-required');
77
84
  if (action === 'finalize' && !push)
78
85
  throw new Error('story-checkpoint-push-required');
86
+ if (action === 'integrate-worktree' && (!push || commitSha))
87
+ throw new Error(push ? 'story-checkpoint-option-invalid' : 'story-checkpoint-push-required');
88
+ if (leaseId !== undefined && (action !== 'integrate-worktree' || !/^swt-[a-f0-9]{24}$/.test(leaseId))) {
89
+ throw new Error('story-checkpoint-option-invalid');
90
+ }
79
91
  if (action === 'begin' && (commitSha || push || remote !== 'origin'))
80
92
  throw new Error('story-checkpoint-option-invalid');
81
93
  if ((action === 'setup' || action === 'accept-setup' || action === 'handoff') && (commitSha || push || remote !== 'origin')) {
@@ -96,7 +108,7 @@ export function parseStoryCheckpointArgs(args) {
96
108
  throw new Error('story-checkpoint-option-invalid');
97
109
  return {
98
110
  action, storyId, projectRoot: resolve(projectRoot), commitSha, remote, push, format,
99
- ...(expectedHeadSha ? { expectedHeadSha } : {}), ...(apply ? { apply } : {}),
111
+ ...(expectedHeadSha ? { expectedHeadSha } : {}), ...(apply ? { apply } : {}), ...(leaseId ? { leaseId } : {}),
100
112
  ...(setupHandoffSessionId ? { setupHandoffSessionId } : {}),
101
113
  ...(setupHandoffTokenFile ? { setupHandoffTokenFile: resolve(setupHandoffTokenFile) } : {}),
102
114
  };
@@ -137,6 +149,26 @@ export async function storyCheckpointCliHandler(args) {
137
149
  return 1;
138
150
  }
139
151
  }
152
+ if (options.action === 'integrate-worktree') {
153
+ const integrated = await integrateStoryWorktree({
154
+ projectRoot: options.projectRoot, storyId: options.storyId, push: options.push, remote: options.remote,
155
+ ...(options.leaseId ? { leaseId: options.leaseId } : {}),
156
+ });
157
+ if (options.format === 'json') {
158
+ console.log(JSON.stringify({ action: options.action, ...integrated }, null, 2));
159
+ }
160
+ else if (integrated.ok) {
161
+ console.log(`story-checkpoint ${options.action}: ${integrated.value.outcome}`);
162
+ if (integrated.value.checkpointHeadSha)
163
+ console.log(`head=${integrated.value.checkpointHeadSha}`);
164
+ for (const path of integrated.value.conflictPaths ?? [])
165
+ console.log(`conflict=${path}`);
166
+ }
167
+ else {
168
+ console.error(`story-checkpoint ${options.action}: ${integrated.reasonCode}`);
169
+ }
170
+ return integrated.ok ? 0 : 1;
171
+ }
140
172
  const result = options.action === 'setup'
141
173
  ? await prepareDirectYoloSetup(options)
142
174
  : options.action === 'accept-setup'
@@ -0,0 +1,46 @@
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
+ import { StoryWorktreeCleanup } from '../git/story-worktree-cleanup.js';
14
+ import { StoryWorktreeManager } from '../git/story-worktree-manager.js';
15
+ export declare const STORY_WORKTREE_ACTIONS: readonly ["create", "adopt", "sync", "status", "release", "cleanup", "recover", "record-push"];
16
+ export type StoryWorktreeAction = (typeof STORY_WORKTREE_ACTIONS)[number];
17
+ export interface StoryWorktreeCliOptions {
18
+ readonly action: StoryWorktreeAction;
19
+ readonly projectRoot: string;
20
+ readonly format: 'json' | 'plain';
21
+ readonly epicId?: string;
22
+ readonly storyId?: string;
23
+ readonly dispatchId?: string;
24
+ readonly baseSha?: string;
25
+ readonly graphRevision?: string;
26
+ readonly ownerId?: string;
27
+ readonly leaseId?: string;
28
+ readonly sha?: string;
29
+ readonly directiveFile?: string;
30
+ readonly worktreePath?: string;
31
+ readonly pathFile?: string;
32
+ readonly trigger?: string;
33
+ readonly remote?: string;
34
+ readonly dryRun?: boolean;
35
+ }
36
+ export declare class StoryWorktreeArgumentError extends Error {
37
+ readonly reasonCode: string;
38
+ constructor(reasonCode: string);
39
+ }
40
+ export declare function parseStoryWorktreeArgs(args: readonly string[], cwd?: string): StoryWorktreeCliOptions;
41
+ /** Execute one parsed command and return the public payload plus exit code. */
42
+ export declare function runStoryWorktreeCommand(options: StoryWorktreeCliOptions, manager?: StoryWorktreeManager, cleanup?: StoryWorktreeCleanup): Promise<{
43
+ readonly exitCode: number;
44
+ readonly payload: Record<string, unknown>;
45
+ }>;
46
+ export declare function storyWorktreeCliHandler(args: readonly string[]): Promise<number>;