@opengsd/gsd-pi 1.4.0-dev.c18009cd → 1.5.0-dev.4fb2d460
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/README.md +10 -10
- package/dist/resources/.managed-resources-content-hash +1 -1
- package/dist/resources/extensions/ask-user-questions.js +1 -1
- package/dist/resources/extensions/gsd/auto/closeout.js +97 -5
- package/dist/resources/extensions/gsd/auto/orchestrator.js +4 -3
- package/dist/resources/extensions/gsd/auto/pre-dispatch.js +6 -3
- package/dist/resources/extensions/gsd/auto/unit-phase.js +5 -9
- package/dist/resources/extensions/gsd/auto-artifact-paths.js +12 -3
- package/dist/resources/extensions/gsd/auto-direct-dispatch.js +11 -7
- package/dist/resources/extensions/gsd/auto-dispatch.js +16 -2
- package/dist/resources/extensions/gsd/auto-recovery.js +50 -6
- package/dist/resources/extensions/gsd/auto-start.js +4 -3
- package/dist/resources/extensions/gsd/auto-worktree-branch-lifecycle.js +189 -0
- package/dist/resources/extensions/gsd/auto-worktree-cleanup.js +133 -0
- package/dist/resources/extensions/gsd/auto-worktree-conflict-auto-resolve.js +35 -0
- package/dist/resources/extensions/gsd/auto-worktree-creation.js +130 -0
- package/dist/resources/extensions/gsd/auto-worktree-entry.js +118 -0
- package/dist/resources/extensions/gsd/auto-worktree-merge-already-merged.js +98 -0
- package/dist/resources/extensions/gsd/auto-worktree-merge-branch-head.js +52 -0
- package/dist/resources/extensions/gsd/auto-worktree-merge-cleanup.js +87 -0
- package/dist/resources/extensions/gsd/auto-worktree-merge-code-changes.js +46 -0
- package/dist/resources/extensions/gsd/auto-worktree-merge-db-ready.js +68 -0
- package/dist/resources/extensions/gsd/auto-worktree-merge-integration-branch.js +51 -0
- package/dist/resources/extensions/gsd/auto-worktree-merge-message.js +106 -0
- package/dist/resources/extensions/gsd/auto-worktree-merge-pre-teardown.js +64 -0
- package/dist/resources/extensions/gsd/auto-worktree-merge-stash.js +168 -0
- package/dist/resources/extensions/gsd/auto-worktree-merge.js +302 -0
- package/dist/resources/extensions/gsd/auto-worktree-milestone-shelter.js +119 -0
- package/dist/resources/extensions/gsd/auto-worktree-path-resolution.js +5 -0
- package/dist/resources/extensions/gsd/auto-worktree-path-utils.js +5 -0
- package/dist/resources/extensions/gsd/auto-worktree-resource-version.js +41 -0
- package/dist/resources/extensions/gsd/auto-worktree-runtime-cleanup.js +99 -0
- package/dist/resources/extensions/gsd/auto-worktree-session-registry.js +57 -0
- package/dist/resources/extensions/gsd/auto-worktree-sync.js +249 -0
- package/dist/resources/extensions/gsd/auto-worktree-teardown.js +120 -0
- package/dist/resources/extensions/gsd/auto-worktree.js +20 -2073
- package/dist/resources/extensions/gsd/auto.js +9 -3
- package/dist/resources/extensions/gsd/bootstrap/dynamic-tools.js +1 -1
- package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +20 -2
- package/dist/resources/extensions/gsd/bootstrap/system-context.js +1 -1
- package/dist/resources/extensions/gsd/bootstrap/tool-call-loop-guard.js +185 -27
- package/dist/resources/extensions/gsd/codebase-generator.js +7 -1
- package/dist/resources/extensions/gsd/commands-handlers.js +1 -1
- package/dist/resources/extensions/gsd/commands-workflow-templates.js +3 -3
- package/dist/resources/extensions/gsd/db/queries.js +9 -9
- package/dist/resources/extensions/gsd/db/writers/cascades.js +20 -2
- package/dist/resources/extensions/gsd/doctor-engine-checks.js +93 -11
- package/dist/resources/extensions/gsd/flat-phase-migration.js +32 -3
- package/dist/resources/extensions/gsd/forensics.js +1 -1
- package/dist/resources/extensions/gsd/git-conflict-resolve.js +2 -2
- package/dist/resources/extensions/gsd/git-service.js +45 -0
- package/dist/resources/extensions/gsd/gsd-db.js +23 -11
- package/dist/resources/extensions/gsd/guided-flow.js +22 -17
- package/dist/resources/extensions/gsd/markdown-renderer.js +15 -3
- package/dist/resources/extensions/gsd/md-importer.js +89 -23
- package/dist/resources/extensions/gsd/migration-auto-check.js +30 -3
- package/dist/resources/extensions/gsd/milestone-merge-transaction.js +11 -0
- package/dist/resources/extensions/gsd/milestone-settlement.js +1 -1
- package/dist/resources/extensions/gsd/parallel-merge.js +1 -1
- package/dist/resources/extensions/gsd/parallel-orchestrator.js +3 -1
- package/dist/resources/extensions/gsd/paths.js +17 -3
- package/dist/resources/extensions/gsd/preferences-skills.js +10 -16
- package/dist/resources/extensions/gsd/preferences-types.js +1 -0
- package/dist/resources/extensions/gsd/preferences-validation.js +82 -0
- package/dist/resources/extensions/gsd/preferences.js +20 -0
- package/dist/resources/extensions/gsd/prompts/system.md +6 -6
- package/dist/resources/extensions/gsd/quick.js +12 -3
- package/dist/resources/extensions/gsd/skill-discovery.js +36 -23
- package/dist/resources/extensions/gsd/slice-parallel-orchestrator.js +2 -1
- package/dist/resources/extensions/gsd/state/derive/from-db.js +88 -153
- package/dist/resources/extensions/gsd/tool-contract.js +14 -0
- package/dist/resources/extensions/gsd/tools/reopen-slice.js +5 -0
- package/dist/resources/extensions/gsd/tools/reopen-task.js +13 -5
- package/dist/resources/extensions/gsd/unit-registry.js +12 -2
- package/dist/resources/extensions/gsd/unmerged-milestone-guard.js +1 -1
- package/dist/resources/extensions/gsd/validation-block-guard.js +2 -1
- package/dist/resources/extensions/gsd/workspace-git-preflight.js +2 -2
- package/dist/resources/extensions/gsd/worktree-command.js +1 -1
- package/dist/resources/extensions/gsd/worktree-lifecycle.js +14 -9
- package/dist/resources/extensions/gsd/worktree-reentry.js +2 -1
- package/dist/resources/extensions/shared/interview-ui.js +62 -9
- package/dist/tsconfig.extensions.tsbuildinfo +1 -1
- package/dist/web/standalone/.next/BUILD_ID +1 -1
- package/dist/web/standalone/.next/app-path-routes-manifest.json +8 -8
- package/dist/web/standalone/.next/build-manifest.json +2 -2
- package/dist/web/standalone/.next/prerender-manifest.json +3 -3
- package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.html +1 -1
- package/dist/web/standalone/.next/server/app/index.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app-paths-manifest.json +8 -8
- package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
- package/dist/web/standalone/.next/server/pages/404.html +1 -1
- package/dist/web/standalone/.next/server/pages/500.html +1 -1
- package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
- package/dist/web/standalone/node_modules/@gsd/native/package.json +1 -1
- package/dist/web/standalone/node_modules/node-pty/build/Makefile +1 -1
- package/integrations/hermes/open_gsd_hermes/gsd_client.py +24 -35
- package/integrations/hermes/tests/test_gsd_client_timeout.py +4 -4
- package/package.json +6 -6
- package/packages/cloud-mcp-gateway/package.json +2 -2
- package/packages/contracts/package.json +1 -1
- package/packages/daemon/package.json +4 -4
- package/packages/gsd-agent-core/dist/export-html/template.js +53 -4
- package/packages/gsd-agent-core/package.json +5 -5
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller.d.ts.map +1 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller.js +3 -2
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller.js.map +1 -1
- package/packages/gsd-agent-modes/package.json +7 -7
- package/packages/mcp-server/package.json +4 -4
- package/packages/native/package.json +1 -1
- package/packages/pi-agent-core/dist/agent-loop.d.ts.map +1 -1
- package/packages/pi-agent-core/dist/agent-loop.js +14 -9
- package/packages/pi-agent-core/dist/agent-loop.js.map +1 -1
- package/packages/pi-agent-core/package.json +1 -1
- package/packages/pi-ai/dist/index.d.ts +1 -0
- package/packages/pi-ai/dist/index.d.ts.map +1 -1
- package/packages/pi-ai/dist/index.js +1 -0
- package/packages/pi-ai/dist/index.js.map +1 -1
- package/packages/pi-ai/dist/providers/transform-messages.d.ts.map +1 -1
- package/packages/pi-ai/dist/providers/transform-messages.js +7 -3
- package/packages/pi-ai/dist/providers/transform-messages.js.map +1 -1
- package/packages/pi-ai/dist/tool-result-content.d.ts +3 -0
- package/packages/pi-ai/dist/tool-result-content.d.ts.map +1 -0
- package/packages/pi-ai/dist/tool-result-content.js +62 -0
- package/packages/pi-ai/dist/tool-result-content.js.map +1 -0
- package/packages/pi-ai/dist/types.d.ts +8 -20
- package/packages/pi-ai/dist/types.d.ts.map +1 -1
- package/packages/pi-ai/dist/types.js.map +1 -1
- package/packages/pi-ai/package.json +1 -1
- package/packages/pi-coding-agent/dist/core/package-manager.d.ts +9 -0
- package/packages/pi-coding-agent/dist/core/package-manager.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/package-manager.js +74 -53
- package/packages/pi-coding-agent/dist/core/package-manager.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/resource-loader.d.ts +6 -0
- package/packages/pi-coding-agent/dist/core/resource-loader.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/resource-loader.js +30 -2
- package/packages/pi-coding-agent/dist/core/resource-loader.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/skill-directories.d.ts +66 -0
- package/packages/pi-coding-agent/dist/core/skill-directories.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/core/skill-directories.js +138 -0
- package/packages/pi-coding-agent/dist/core/skill-directories.js.map +1 -0
- package/packages/pi-coding-agent/dist/core/skills.d.ts +4 -1
- package/packages/pi-coding-agent/dist/core/skills.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/skills.js +4 -1
- package/packages/pi-coding-agent/dist/core/skills.js.map +1 -1
- package/packages/pi-coding-agent/dist/index.d.ts +1 -0
- package/packages/pi-coding-agent/dist/index.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/index.js +1 -0
- package/packages/pi-coding-agent/dist/index.js.map +1 -1
- package/packages/pi-coding-agent/package.json +7 -7
- package/packages/pi-tui/package.json +2 -2
- package/packages/rpc-client/package.json +2 -2
- package/pkg/dist/core/export-html/template.js +53 -4
- package/pkg/package.json +1 -1
- package/src/resources/extensions/ask-user-questions.ts +1 -1
- package/src/resources/extensions/gsd/auto/closeout.ts +114 -7
- package/src/resources/extensions/gsd/auto/orchestrator.ts +4 -3
- package/src/resources/extensions/gsd/auto/pre-dispatch.ts +6 -3
- package/src/resources/extensions/gsd/auto/unit-phase.ts +5 -9
- package/src/resources/extensions/gsd/auto-artifact-paths.ts +12 -3
- package/src/resources/extensions/gsd/auto-direct-dispatch.ts +13 -7
- package/src/resources/extensions/gsd/auto-dispatch.ts +18 -2
- package/src/resources/extensions/gsd/auto-recovery.ts +50 -6
- package/src/resources/extensions/gsd/auto-start.ts +5 -3
- package/src/resources/extensions/gsd/auto-worktree-branch-lifecycle.ts +237 -0
- package/src/resources/extensions/gsd/auto-worktree-cleanup.ts +166 -0
- package/src/resources/extensions/gsd/auto-worktree-conflict-auto-resolve.ts +37 -0
- package/src/resources/extensions/gsd/auto-worktree-creation.ts +171 -0
- package/src/resources/extensions/gsd/auto-worktree-entry.ts +154 -0
- package/src/resources/extensions/gsd/auto-worktree-merge-already-merged.ts +161 -0
- package/src/resources/extensions/gsd/auto-worktree-merge-branch-head.ts +83 -0
- package/src/resources/extensions/gsd/auto-worktree-merge-cleanup.ts +132 -0
- package/src/resources/extensions/gsd/auto-worktree-merge-code-changes.ts +71 -0
- package/src/resources/extensions/gsd/auto-worktree-merge-db-ready.ts +112 -0
- package/src/resources/extensions/gsd/auto-worktree-merge-integration-branch.ts +99 -0
- package/src/resources/extensions/gsd/auto-worktree-merge-message.ts +166 -0
- package/src/resources/extensions/gsd/auto-worktree-merge-pre-teardown.ts +93 -0
- package/src/resources/extensions/gsd/auto-worktree-merge-stash.ts +213 -0
- package/src/resources/extensions/gsd/auto-worktree-merge.ts +391 -0
- package/src/resources/extensions/gsd/auto-worktree-milestone-shelter.ts +159 -0
- package/src/resources/extensions/gsd/auto-worktree-path-resolution.ts +6 -0
- package/src/resources/extensions/gsd/auto-worktree-path-utils.ts +10 -0
- package/src/resources/extensions/gsd/auto-worktree-resource-version.ts +44 -0
- package/src/resources/extensions/gsd/auto-worktree-runtime-cleanup.ts +119 -0
- package/src/resources/extensions/gsd/auto-worktree-session-registry.ts +71 -0
- package/src/resources/extensions/gsd/auto-worktree-sync.ts +370 -0
- package/src/resources/extensions/gsd/auto-worktree-teardown.ts +161 -0
- package/src/resources/extensions/gsd/auto-worktree.ts +69 -2429
- package/src/resources/extensions/gsd/auto.ts +11 -17
- package/src/resources/extensions/gsd/bootstrap/dynamic-tools.ts +1 -1
- package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +20 -2
- package/src/resources/extensions/gsd/bootstrap/system-context.ts +1 -1
- package/src/resources/extensions/gsd/bootstrap/tool-call-loop-guard.ts +218 -27
- package/src/resources/extensions/gsd/codebase-generator.ts +7 -1
- package/src/resources/extensions/gsd/commands-handlers.ts +1 -1
- package/src/resources/extensions/gsd/commands-workflow-templates.ts +3 -3
- package/src/resources/extensions/gsd/db/queries.ts +9 -9
- package/src/resources/extensions/gsd/db/writers/cascades.ts +23 -1
- package/src/resources/extensions/gsd/doctor-engine-checks.ts +109 -10
- package/src/resources/extensions/gsd/flat-phase-migration.ts +34 -3
- package/src/resources/extensions/gsd/forensics.ts +1 -1
- package/src/resources/extensions/gsd/git-conflict-resolve.ts +2 -2
- package/src/resources/extensions/gsd/git-service.ts +53 -0
- package/src/resources/extensions/gsd/gsd-db.ts +33 -11
- package/src/resources/extensions/gsd/guided-flow.ts +26 -18
- package/src/resources/extensions/gsd/markdown-renderer.ts +15 -3
- package/src/resources/extensions/gsd/md-importer.ts +93 -22
- package/src/resources/extensions/gsd/migration-auto-check.ts +32 -3
- package/src/resources/extensions/gsd/milestone-merge-transaction.ts +15 -0
- package/src/resources/extensions/gsd/milestone-settlement.ts +1 -1
- package/src/resources/extensions/gsd/parallel-merge.ts +1 -1
- package/src/resources/extensions/gsd/parallel-orchestrator.ts +3 -1
- package/src/resources/extensions/gsd/paths.ts +21 -3
- package/src/resources/extensions/gsd/preferences-skills.ts +10 -16
- package/src/resources/extensions/gsd/preferences-types.ts +30 -0
- package/src/resources/extensions/gsd/preferences-validation.ts +69 -0
- package/src/resources/extensions/gsd/preferences.ts +20 -0
- package/src/resources/extensions/gsd/prompts/system.md +6 -6
- package/src/resources/extensions/gsd/quick.ts +11 -3
- package/src/resources/extensions/gsd/skill-discovery.ts +47 -23
- package/src/resources/extensions/gsd/slice-parallel-orchestrator.ts +3 -1
- package/src/resources/extensions/gsd/state/derive/from-db.ts +201 -157
- package/src/resources/extensions/gsd/tests/auto-artifact-paths.test.ts +169 -1
- package/src/resources/extensions/gsd/tests/auto-loop-no-copy-artifacts.test.ts +2 -1
- package/src/resources/extensions/gsd/tests/auto-recovery.test.ts +57 -0
- package/src/resources/extensions/gsd/tests/auto-start-clean-runtime-db-gated.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/auto-warning-noise-regression.test.ts +2 -1
- package/src/resources/extensions/gsd/tests/auto-worktree-auto-resolve.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/auto-worktree-merge-already-merged.test.ts +177 -0
- package/src/resources/extensions/gsd/tests/auto-worktree-merge-branch-head.test.ts +118 -0
- package/src/resources/extensions/gsd/tests/auto-worktree-merge-cleanup.test.ts +115 -0
- package/src/resources/extensions/gsd/tests/auto-worktree-merge-code-changes.test.ts +76 -0
- package/src/resources/extensions/gsd/tests/auto-worktree-merge-db-ready.test.ts +140 -0
- package/src/resources/extensions/gsd/tests/auto-worktree-merge-integration-branch.test.ts +123 -0
- package/src/resources/extensions/gsd/tests/auto-worktree-merge-message.test.ts +114 -0
- package/src/resources/extensions/gsd/tests/auto-worktree-merge-pre-teardown.test.ts +84 -0
- package/src/resources/extensions/gsd/tests/auto-worktree-merge-stash.test.ts +70 -0
- package/src/resources/extensions/gsd/tests/auto-worktree-milestone-shelter.test.ts +52 -0
- package/src/resources/extensions/gsd/tests/auto-worktree-registry.test.ts +6 -6
- package/src/resources/extensions/gsd/tests/auto-worktree-resource-version.test.ts +59 -0
- package/src/resources/extensions/gsd/tests/auto-worktree-untracked-content.test.ts +3 -1
- package/src/resources/extensions/gsd/tests/codebase-generator.test.ts +22 -0
- package/src/resources/extensions/gsd/tests/completed-units-metrics-sync.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/derive-state-db.test.ts +4 -0
- package/src/resources/extensions/gsd/tests/doctor-scope-db-unavailable.test.ts +174 -0
- package/src/resources/extensions/gsd/tests/fast-forward-reused-milestone-branch.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/flat-phase-migration.test.ts +71 -1
- package/src/resources/extensions/gsd/tests/flat-phase-renderer.test.ts +25 -1
- package/src/resources/extensions/gsd/tests/gsd-db.test.ts +40 -0
- package/src/resources/extensions/gsd/tests/import-completion-lost-update.test.ts +196 -0
- package/src/resources/extensions/gsd/tests/integration/all-milestones-complete-merge.test.ts +4 -6
- package/src/resources/extensions/gsd/tests/integration/auto-stash-merge.test.ts +2 -1
- package/src/resources/extensions/gsd/tests/integration/auto-worktree-milestone-merge.test.ts +3 -3
- package/src/resources/extensions/gsd/tests/integration/auto-worktree.test.ts +7 -8
- package/src/resources/extensions/gsd/tests/integration/feature-branch-lifecycle-integration.test.ts +2 -5
- package/src/resources/extensions/gsd/tests/integration/git-service.test.ts +76 -0
- package/src/resources/extensions/gsd/tests/integration/merge-cwd-restore.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/integration/merge-preserve-worktree-on-preteardown-error.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/integration/merge-strategy-regular.test.ts +2 -1
- package/src/resources/extensions/gsd/tests/integration/milestone-transition-worktree.test.ts +5 -7
- package/src/resources/extensions/gsd/tests/integration/workspace-collapse-integration.test.ts +2 -4
- package/src/resources/extensions/gsd/tests/journal-integration.test.ts +16 -15
- package/src/resources/extensions/gsd/tests/merge-closeout-consistency-gate.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/merge-db-cycle.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/merge-self-branch-guard.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/migration-auto-check.test.ts +91 -0
- package/src/resources/extensions/gsd/tests/milestone-merge-stash-restore.test.ts +439 -0
- package/src/resources/extensions/gsd/tests/milestone-merge-transaction.test.ts +24 -0
- package/src/resources/extensions/gsd/tests/none-mode-gates.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/originalbase-path-comparison.test.ts +3 -3
- package/src/resources/extensions/gsd/tests/parallel-worker-lock-contention.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/preferences-worktree-sync.test.ts +1 -4
- package/src/resources/extensions/gsd/tests/preferences.test.ts +19 -0
- package/src/resources/extensions/gsd/tests/prefs-wizard-coverage.test.ts +5 -0
- package/src/resources/extensions/gsd/tests/reopen-slice.test.ts +52 -0
- package/src/resources/extensions/gsd/tests/runtime-invariant-modules.test.ts +20 -0
- package/src/resources/extensions/gsd/tests/skill-discovery.test.ts +46 -0
- package/src/resources/extensions/gsd/tests/stale-worktree-cwd.test.ts +3 -5
- package/src/resources/extensions/gsd/tests/stash-pop-gsd-conflict.test.ts +2 -1
- package/src/resources/extensions/gsd/tests/stash-queued-context-files.test.ts +2 -1
- package/src/resources/extensions/gsd/tests/steer-worktree-path.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/sync-worktree-skip-current.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/system-flat-phase-layout.test.ts +33 -0
- package/src/resources/extensions/gsd/tests/teardown-chdir-failure-clears-registry.test.ts +4 -4
- package/src/resources/extensions/gsd/tests/teardown-cleanup-parity.test.ts +2 -1
- package/src/resources/extensions/gsd/tests/teardown-failure-clears-registry.test.ts +4 -4
- package/src/resources/extensions/gsd/tests/tool-call-loop-guard.test.ts +196 -0
- package/src/resources/extensions/gsd/tests/uat-stuck-loop-orphaned-worktree.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/unit-registry.test.ts +26 -1
- package/src/resources/extensions/gsd/tests/worktree-db-integration.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/worktree-db-respawn-truncation.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/worktree-db-same-file.test.ts +1 -3
- package/src/resources/extensions/gsd/tests/worktree-expected-warnings.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/worktree-git-pathspec.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/worktree-main-branch.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/worktree-preferences-sync.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/worktree-reentry.test.ts +2 -1
- package/src/resources/extensions/gsd/tests/worktree-sync-milestones.test.ts +5 -2
- package/src/resources/extensions/gsd/tests/worktree-sync-overwrite-loop.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/worktree-sync-tasks.test.ts +1 -1
- package/src/resources/extensions/gsd/tool-contract.ts +29 -0
- package/src/resources/extensions/gsd/tools/reopen-slice.ts +5 -0
- package/src/resources/extensions/gsd/tools/reopen-task.ts +13 -5
- package/src/resources/extensions/gsd/unit-registry.ts +16 -2
- package/src/resources/extensions/gsd/unmerged-milestone-guard.ts +1 -1
- package/src/resources/extensions/gsd/validation-block-guard.ts +2 -1
- package/src/resources/extensions/gsd/workspace-git-preflight.ts +2 -2
- package/src/resources/extensions/gsd/worktree-command.ts +1 -1
- package/src/resources/extensions/gsd/worktree-lifecycle.ts +19 -15
- package/src/resources/extensions/gsd/worktree-reentry.ts +2 -1
- package/src/resources/extensions/shared/interview-ui.ts +58 -11
- package/src/resources/extensions/shared/tests/interview-ui-border.test.ts +32 -0
- /package/dist/web/standalone/.next/static/{L2UMqXELiDH3oz-7yguXp → gXoWec4UNqcR0tkuHwYCr}/_buildManifest.js +0 -0
- /package/dist/web/standalone/.next/static/{L2UMqXELiDH3oz-7yguXp → gXoWec4UNqcR0tkuHwYCr}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
// gsd-pi — Auto-worktree branch lifecycle module.
|
|
2
|
+
//
|
|
3
|
+
// Owns milestone branch naming, branch-mode entry, and safe fast-forward of
|
|
4
|
+
// reused milestone branches. Worktree creation/merge code imports this module
|
|
5
|
+
// instead of keeping branch policy inside the legacy auto-worktree barrel.
|
|
6
|
+
import { GSDError, GSD_GIT_ERROR } from "./errors.js";
|
|
7
|
+
import { readIntegrationBranch } from "./git-service.js";
|
|
8
|
+
import { loadEffectiveGSDPreferences } from "./preferences.js";
|
|
9
|
+
import { debugLog } from "./debug-logger.js";
|
|
10
|
+
import { checkoutBranchWithStashGuard } from "./worktree-git-recovery.js";
|
|
11
|
+
import { nativeBranchExists, nativeBranchForceReset, nativeDetectMainBranch, nativeIsAncestor, nativeUpdateRef, nativeWorktreeList, } from "./native-git-bridge.js";
|
|
12
|
+
/** Returns the git branch name for a milestone worktree (`milestone/<MID>`). */
|
|
13
|
+
export function autoWorktreeBranch(milestoneId) {
|
|
14
|
+
return `milestone/${milestoneId}`;
|
|
15
|
+
}
|
|
16
|
+
export function _resolveAutoWorktreeStartPoint(integrationBranch, gitMainBranch, branchExists) {
|
|
17
|
+
if (integrationBranch)
|
|
18
|
+
return integrationBranch;
|
|
19
|
+
return gitMainBranch &&
|
|
20
|
+
typeof gitMainBranch === "string" &&
|
|
21
|
+
gitMainBranch.length > 0 &&
|
|
22
|
+
branchExists(gitMainBranch)
|
|
23
|
+
? gitMainBranch
|
|
24
|
+
: undefined;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Enter branch isolation mode for a milestone.
|
|
28
|
+
*
|
|
29
|
+
* Creates `milestone/<MID>` from the integration branch (if it doesn't
|
|
30
|
+
* exist yet) and checks out to it. No worktree directory is created — the
|
|
31
|
+
* project root is the working copy; only HEAD changes.
|
|
32
|
+
*
|
|
33
|
+
* Uses the same 3-tier integration-branch fallback as createAutoWorktree:
|
|
34
|
+
* 1. META.json recorded integration branch
|
|
35
|
+
* 2. git.main_branch preference
|
|
36
|
+
* 3. nativeDetectMainBranch (origin/HEAD auto-detection)
|
|
37
|
+
*/
|
|
38
|
+
export function enterBranchModeForMilestone(basePath, milestoneId) {
|
|
39
|
+
const branch = autoWorktreeBranch(milestoneId);
|
|
40
|
+
const branchExists = nativeBranchExists(basePath, branch);
|
|
41
|
+
if (!branchExists) {
|
|
42
|
+
// Create the milestone branch from the integration branch start-point.
|
|
43
|
+
const integrationBranch = readIntegrationBranch(basePath, milestoneId) ?? undefined;
|
|
44
|
+
const gitPrefs = loadEffectiveGSDPreferences()?.preferences?.git;
|
|
45
|
+
const startPoint = _resolveAutoWorktreeStartPoint(integrationBranch, gitPrefs?.main_branch, (branchName) => nativeBranchExists(basePath, branchName)) ??
|
|
46
|
+
nativeDetectMainBranch(basePath);
|
|
47
|
+
// TOCTOU ancestry guard (Issue #4980 HIGH-3).
|
|
48
|
+
//
|
|
49
|
+
// The outer `branchExists` check is racy: a concurrent process
|
|
50
|
+
// (parallel-orchestrator worker, side-by-side `gsd` instance, or manual
|
|
51
|
+
// `git branch` invocation) may have created the branch with real commits
|
|
52
|
+
// between that check and this point. `nativeBranchForceReset` does
|
|
53
|
+
// `git branch -f`, which silently overwrites the branch ref — orphaning
|
|
54
|
+
// any commits not reachable from `startPoint`. Re-check immediately
|
|
55
|
+
// before the destructive call and refuse if the branch suddenly exists
|
|
56
|
+
// with non-ancestor commits.
|
|
57
|
+
const concurrentlyCreated = nativeBranchExists(basePath, branch);
|
|
58
|
+
if (concurrentlyCreated &&
|
|
59
|
+
!nativeIsAncestor(basePath, branch, startPoint)) {
|
|
60
|
+
throw new GSDError(GSD_GIT_ERROR, `Branch "${branch}" was created concurrently with commits not reachable from "${startPoint}". ` +
|
|
61
|
+
`Refusing to force-reset — would orphan prior work. ` +
|
|
62
|
+
`Resume the existing milestone or run \`git branch -D ${branch}\` to discard.`);
|
|
63
|
+
}
|
|
64
|
+
// nativeBranchForceReset creates (or resets) branch at startPoint,
|
|
65
|
+
// then checkout switches HEAD to it.
|
|
66
|
+
nativeBranchForceReset(basePath, branch, startPoint);
|
|
67
|
+
debugLog("auto-worktree", {
|
|
68
|
+
action: "enterBranchMode",
|
|
69
|
+
milestoneId,
|
|
70
|
+
branch,
|
|
71
|
+
startPoint,
|
|
72
|
+
created: true,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
debugLog("auto-worktree", {
|
|
77
|
+
action: "enterBranchMode",
|
|
78
|
+
milestoneId,
|
|
79
|
+
branch,
|
|
80
|
+
reused: true,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
checkoutBranchWithStashGuard(basePath, branch, `enter-branch-mode:${milestoneId}`);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* True when `branch` is checked out in any worktree listed by
|
|
87
|
+
* `git worktree list --porcelain`. Used to gate ref updates that would
|
|
88
|
+
* otherwise leave a concurrent worktree's HEAD inconsistent with its
|
|
89
|
+
* index/working tree (Codex peer-review of #5538-followup).
|
|
90
|
+
*
|
|
91
|
+
* Best-effort: a `nativeWorktreeList` failure returns true so we err on
|
|
92
|
+
* the side of NOT moving the ref. Better to skip a fast-forward than to
|
|
93
|
+
* silently corrupt another worktree.
|
|
94
|
+
*/
|
|
95
|
+
export function _isBranchCheckedOutElsewhere(basePath, branch) {
|
|
96
|
+
try {
|
|
97
|
+
const entries = nativeWorktreeList(basePath);
|
|
98
|
+
return entries.some((entry) => entry.branch === branch);
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Resolve the integration branch using the same 3-tier fallback as the
|
|
106
|
+
* fresh-create path: META.json → git.main_branch preference → detected
|
|
107
|
+
* main branch. Returns null when no usable target exists.
|
|
108
|
+
*/
|
|
109
|
+
function resolveIntegrationBranchForReuse(basePath, milestoneId) {
|
|
110
|
+
const fromMeta = readIntegrationBranch(basePath, milestoneId);
|
|
111
|
+
if (fromMeta)
|
|
112
|
+
return fromMeta;
|
|
113
|
+
const gitPrefs = loadEffectiveGSDPreferences()?.preferences?.git;
|
|
114
|
+
const fromPref = gitPrefs?.main_branch &&
|
|
115
|
+
typeof gitPrefs.main_branch === "string" &&
|
|
116
|
+
gitPrefs.main_branch.length > 0 &&
|
|
117
|
+
nativeBranchExists(basePath, gitPrefs.main_branch)
|
|
118
|
+
? gitPrefs.main_branch
|
|
119
|
+
: null;
|
|
120
|
+
if (fromPref)
|
|
121
|
+
return fromPref;
|
|
122
|
+
try {
|
|
123
|
+
return nativeDetectMainBranch(basePath);
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* When reusing an existing milestone branch, fast-forward it onto the
|
|
131
|
+
* integration branch when that's safe (branch is a strict ancestor of
|
|
132
|
+
* integration — no commits would be lost). Skips when the branch has its
|
|
133
|
+
* own commits ahead of integration, when the integration branch can't be
|
|
134
|
+
* resolved, or when any git operation fails — the merge gate at milestone
|
|
135
|
+
* completion will surface real divergence as a conflict.
|
|
136
|
+
*
|
|
137
|
+
* The previous behavior re-attached the worktree to whatever stale tip
|
|
138
|
+
* the branch held, which caused new milestone work to fork from a base
|
|
139
|
+
* missing prior milestones' merges (#5538-followup).
|
|
140
|
+
*/
|
|
141
|
+
export function fastForwardReusedMilestoneBranchIfSafe(basePath, milestoneId, branch) {
|
|
142
|
+
try {
|
|
143
|
+
const integrationBranch = resolveIntegrationBranchForReuse(basePath, milestoneId);
|
|
144
|
+
if (!integrationBranch || integrationBranch === branch)
|
|
145
|
+
return;
|
|
146
|
+
if (!nativeBranchExists(basePath, integrationBranch))
|
|
147
|
+
return;
|
|
148
|
+
// Pure fast-forward only: branch must be a strict ancestor of integration.
|
|
149
|
+
// If the branch has its own commits ahead, leave it alone.
|
|
150
|
+
if (!nativeIsAncestor(basePath, branch, integrationBranch)) {
|
|
151
|
+
debugLog("createAutoWorktree", {
|
|
152
|
+
phase: "skip-ff-branch-not-ancestor",
|
|
153
|
+
milestoneId,
|
|
154
|
+
branch,
|
|
155
|
+
integration: integrationBranch,
|
|
156
|
+
});
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
// Codex peer-review: `nativeUpdateRef` succeeds even when the branch is
|
|
160
|
+
// currently checked out in another worktree, leaving that worktree's HEAD
|
|
161
|
+
// inconsistent with its index/work tree. Skip the fast-forward if any
|
|
162
|
+
// listed worktree has this branch checked out — the merge gate at
|
|
163
|
+
// milestone-completion will surface stale-base divergence as a conflict
|
|
164
|
+
// instead of silently corrupting the other worktree's state.
|
|
165
|
+
if (_isBranchCheckedOutElsewhere(basePath, branch)) {
|
|
166
|
+
debugLog("createAutoWorktree", {
|
|
167
|
+
phase: "skip-ff-branch-checked-out-elsewhere",
|
|
168
|
+
milestoneId,
|
|
169
|
+
branch,
|
|
170
|
+
});
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
nativeUpdateRef(basePath, `refs/heads/${branch}`, integrationBranch);
|
|
174
|
+
debugLog("createAutoWorktree", {
|
|
175
|
+
phase: "fast-forward-reused-branch",
|
|
176
|
+
milestoneId,
|
|
177
|
+
branch,
|
|
178
|
+
integration: integrationBranch,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
catch (err) {
|
|
182
|
+
debugLog("createAutoWorktree", {
|
|
183
|
+
phase: "fast-forward-reused-branch-failed",
|
|
184
|
+
milestoneId,
|
|
185
|
+
branch,
|
|
186
|
+
error: err instanceof Error ? err.message : String(err),
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// gsd-pi — Auto-worktree cleanup helpers.
|
|
2
|
+
//
|
|
3
|
+
// Owns shared cleanup primitives used by teardown and merge cleanup paths:
|
|
4
|
+
// same-file DB reconciliation checks, transient project-root state removal,
|
|
5
|
+
// git pathspec conversion for externally-rooted .gsd paths, and expected
|
|
6
|
+
// unlink error classification.
|
|
7
|
+
import { execFileSync } from "node:child_process";
|
|
8
|
+
import { existsSync, realpathSync, unlinkSync } from "node:fs";
|
|
9
|
+
import { isAbsolute, join, relative } from "node:path";
|
|
10
|
+
import { gsdRoot } from "./paths.js";
|
|
11
|
+
import { logWarning } from "./workflow-logger.js";
|
|
12
|
+
function isSamePath(a, b) {
|
|
13
|
+
try {
|
|
14
|
+
return realpathSync(a) === realpathSync(b);
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
if (e.code === "ENOENT")
|
|
18
|
+
return false;
|
|
19
|
+
logWarning("worktree", `isSamePath failed: ${e.message}`);
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export function _isSamePath(a, b) {
|
|
24
|
+
return isSamePath(a, b);
|
|
25
|
+
}
|
|
26
|
+
export function _shouldReconcileWorktreeDb(worktreeDbPath, mainDbPath, pathExists = existsSync, samePath = isSamePath) {
|
|
27
|
+
return pathExists(worktreeDbPath) && !samePath(worktreeDbPath, mainDbPath);
|
|
28
|
+
}
|
|
29
|
+
export function _isExpectedWorktreeUnlinkError(code) {
|
|
30
|
+
return code === "ENOENT" || code === "EISDIR";
|
|
31
|
+
}
|
|
32
|
+
function gitPathspecForWorktreePath(basePath, targetPath) {
|
|
33
|
+
let base = basePath;
|
|
34
|
+
let target = targetPath;
|
|
35
|
+
try {
|
|
36
|
+
base = execFileSync("git", ["rev-parse", "--show-toplevel"], {
|
|
37
|
+
cwd: basePath,
|
|
38
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
39
|
+
encoding: "utf-8",
|
|
40
|
+
}).trim() || basePath;
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
/* keep original */
|
|
44
|
+
void base;
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
base = realpathSync.native(base);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
/* keep original */
|
|
51
|
+
void base;
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
target = realpathSync.native(targetPath);
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
/* keep original */
|
|
58
|
+
void target;
|
|
59
|
+
}
|
|
60
|
+
const rel = relative(base, target);
|
|
61
|
+
if (rel === "" || rel.startsWith("..") || isAbsolute(rel))
|
|
62
|
+
return null;
|
|
63
|
+
return rel.replaceAll("\\", "/");
|
|
64
|
+
}
|
|
65
|
+
export function _gitPathspecForWorktreePath(basePath, targetPath) {
|
|
66
|
+
return gitPathspecForWorktreePath(basePath, targetPath);
|
|
67
|
+
}
|
|
68
|
+
export function clearProjectRootStateFiles(basePath, milestoneId) {
|
|
69
|
+
const gsdDir = gsdRoot(basePath);
|
|
70
|
+
// Phase C pt 2: auto.lock removed from this list — the file is gone
|
|
71
|
+
// (migrated to the workers + unit_dispatches + runtime_kv tables). The
|
|
72
|
+
// remaining transient files (STATE.md, {MID}-META.json) are still
|
|
73
|
+
// worth removing on teardown.
|
|
74
|
+
const transientFiles = [
|
|
75
|
+
join(gsdDir, "STATE.md"),
|
|
76
|
+
join(gsdDir, "milestones", milestoneId, `${milestoneId}-META.json`),
|
|
77
|
+
];
|
|
78
|
+
for (const file of transientFiles) {
|
|
79
|
+
try {
|
|
80
|
+
unlinkSync(file);
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
// ENOENT is expected — file may not exist (#3597)
|
|
84
|
+
if (err.code !== "ENOENT") {
|
|
85
|
+
logWarning("worktree", `file unlink failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// Clean up legacy synced milestone directories and runtime/units.
|
|
90
|
+
// Older versions copied these into the project root during execution.
|
|
91
|
+
// If they remain as untracked files when we attempt
|
|
92
|
+
// `git merge --squash`, git rejects the merge with "local changes would
|
|
93
|
+
// be overwritten", causing silent data loss (#1738).
|
|
94
|
+
const syncedDirs = [
|
|
95
|
+
join(gsdDir, "milestones", milestoneId),
|
|
96
|
+
join(gsdDir, "runtime", "units"),
|
|
97
|
+
];
|
|
98
|
+
for (const dir of syncedDirs) {
|
|
99
|
+
try {
|
|
100
|
+
if (!existsSync(dir))
|
|
101
|
+
continue;
|
|
102
|
+
const pathspec = gitPathspecForWorktreePath(basePath, dir);
|
|
103
|
+
if (!pathspec)
|
|
104
|
+
continue;
|
|
105
|
+
// Only remove files that are untracked by git — tracked files are
|
|
106
|
+
// managed by the branch checkout and should not be deleted.
|
|
107
|
+
const untrackedOutput = execFileSync("git", ["ls-files", "--others", "--exclude-standard", pathspec], {
|
|
108
|
+
cwd: basePath,
|
|
109
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
110
|
+
encoding: "utf-8",
|
|
111
|
+
}).trim();
|
|
112
|
+
if (!untrackedOutput)
|
|
113
|
+
continue;
|
|
114
|
+
for (const f of untrackedOutput.split("\n").filter(Boolean)) {
|
|
115
|
+
try {
|
|
116
|
+
unlinkSync(join(basePath, f));
|
|
117
|
+
}
|
|
118
|
+
catch (err) {
|
|
119
|
+
// ENOENT/EISDIR are expected for already-removed or
|
|
120
|
+
// directory entries (#3597).
|
|
121
|
+
const code = err.code;
|
|
122
|
+
if (!_isExpectedWorktreeUnlinkError(code)) {
|
|
123
|
+
logWarning("worktree", `untracked file unlink failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
catch (err) {
|
|
129
|
+
/* non-fatal — git command may fail if not in repo */
|
|
130
|
+
logWarning("worktree", `untracked file cleanup failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// gsd-pi — Conflict auto-resolve policy for auto-worktree merges.
|
|
2
|
+
//
|
|
3
|
+
// Owns the pure path policy for conflict paths that are safe to resolve
|
|
4
|
+
// mechanically. Git mutation stays in git-conflict-resolve.ts.
|
|
5
|
+
/** Patterns for machine-generated build artifacts that can be safely
|
|
6
|
+
* auto-resolved by accepting --theirs during merge. These files are
|
|
7
|
+
* regenerable and never contain meaningful manual edits. */
|
|
8
|
+
export const SAFE_AUTO_RESOLVE_PATTERNS = [
|
|
9
|
+
/\.tsbuildinfo$/,
|
|
10
|
+
/\.pyc$/,
|
|
11
|
+
/\/__pycache__\//,
|
|
12
|
+
/\.DS_Store$/,
|
|
13
|
+
/\.map$/,
|
|
14
|
+
// Regenerable dependency lockfiles. These are fully derivable from their
|
|
15
|
+
// manifests by the package manager, so accepting the merge side during
|
|
16
|
+
// auto-resolve clears the conflict markers without losing meaningful edits —
|
|
17
|
+
// and stops auto-mode from hard-pausing on a lockfile conflict (issue #828).
|
|
18
|
+
/(?:^|\/)pnpm-lock\.yaml$/,
|
|
19
|
+
/(?:^|\/)package-lock\.json$/,
|
|
20
|
+
/(?:^|\/)npm-shrinkwrap\.json$/,
|
|
21
|
+
/(?:^|\/)yarn\.lock$/,
|
|
22
|
+
/(?:^|\/)bun\.lockb?$/,
|
|
23
|
+
/(?:^|\/)Cargo\.lock$/,
|
|
24
|
+
/(?:^|\/)composer\.lock$/,
|
|
25
|
+
/(?:^|\/)Gemfile\.lock$/,
|
|
26
|
+
/(?:^|\/)Pipfile\.lock$/,
|
|
27
|
+
/(?:^|\/)poetry\.lock$/,
|
|
28
|
+
];
|
|
29
|
+
/** Returns true if the file path is safe to auto-resolve during merge.
|
|
30
|
+
* Covers `.gsd/` state files, common build artifacts, and regenerable
|
|
31
|
+
* dependency lockfiles. */
|
|
32
|
+
export function isSafeToAutoResolve(filePath) {
|
|
33
|
+
return filePath.startsWith(".gsd/")
|
|
34
|
+
|| SAFE_AUTO_RESOLVE_PATTERNS.some((re) => re.test(filePath));
|
|
35
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// gsd-pi — Auto-worktree creation module.
|
|
2
|
+
//
|
|
3
|
+
// Owns the creation path for milestone worktrees: repository readiness,
|
|
4
|
+
// branch reuse/start-point selection, initial untracked-content import,
|
|
5
|
+
// post-create hook, cwd transition, and session registry update.
|
|
6
|
+
import { execFileSync } from "node:child_process";
|
|
7
|
+
import { cpSync, existsSync, mkdirSync } from "node:fs";
|
|
8
|
+
import { dirname, join } from "node:path";
|
|
9
|
+
import { classifyProject } from "./detection.js";
|
|
10
|
+
import { GSDError, GSD_GIT_ERROR, GSD_IO_ERROR } from "./errors.js";
|
|
11
|
+
import { readIntegrationBranch } from "./git-service.js";
|
|
12
|
+
import { nativeBranchExists } from "./native-git-bridge.js";
|
|
13
|
+
import { loadEffectiveGSDPreferences } from "./preferences.js";
|
|
14
|
+
import { autoWorktreeBranch, fastForwardReusedMilestoneBranchIfSafe, _resolveAutoWorktreeStartPoint, } from "./auto-worktree-branch-lifecycle.js";
|
|
15
|
+
import { setActiveWorkspace } from "./auto-worktree-session-registry.js";
|
|
16
|
+
import { runWorktreePostCreateHook } from "./worktree-post-create-hook.js";
|
|
17
|
+
import { createWorktree } from "./worktree-manager.js";
|
|
18
|
+
import { nudgeGitBranchCache } from "./worktree.js";
|
|
19
|
+
import { resolveWorktreeProjectRoot } from "./worktree-root.js";
|
|
20
|
+
import { createWorkspace } from "./workspace.js";
|
|
21
|
+
import { debugLog } from "./debug-logger.js";
|
|
22
|
+
import { logWarning } from "./workflow-logger.js";
|
|
23
|
+
function importUntrackedProjectRootContentIntoEmptyWorktree(projectRoot, worktreeRoot, milestoneId) {
|
|
24
|
+
const worktreeClassification = classifyProject(worktreeRoot);
|
|
25
|
+
if (worktreeClassification.kind !== "greenfield")
|
|
26
|
+
return 0;
|
|
27
|
+
const projectRootClassification = classifyProject(projectRoot);
|
|
28
|
+
if (projectRootClassification.kind === "greenfield" ||
|
|
29
|
+
projectRootClassification.kind === "invalid-repo" ||
|
|
30
|
+
projectRootClassification.untrackedFiles.length === 0) {
|
|
31
|
+
return 0;
|
|
32
|
+
}
|
|
33
|
+
let copied = 0;
|
|
34
|
+
for (const relPath of projectRootClassification.untrackedFiles) {
|
|
35
|
+
const src = join(projectRoot, relPath);
|
|
36
|
+
if (!existsSync(src))
|
|
37
|
+
continue;
|
|
38
|
+
const dst = join(worktreeRoot, relPath);
|
|
39
|
+
if (existsSync(dst))
|
|
40
|
+
continue;
|
|
41
|
+
mkdirSync(dirname(dst), { recursive: true });
|
|
42
|
+
cpSync(src, dst, { recursive: true, force: false });
|
|
43
|
+
copied++;
|
|
44
|
+
}
|
|
45
|
+
if (copied > 0) {
|
|
46
|
+
debugLog("createAutoWorktree", {
|
|
47
|
+
phase: "import-untracked-project-content",
|
|
48
|
+
milestoneId,
|
|
49
|
+
copied,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return copied;
|
|
53
|
+
}
|
|
54
|
+
export function createAutoWorktree(basePath, milestoneId) {
|
|
55
|
+
basePath = resolveWorktreeProjectRoot(basePath);
|
|
56
|
+
// Check if repo has commits — git worktree requires a valid HEAD.
|
|
57
|
+
try {
|
|
58
|
+
execFileSync("git", ["rev-parse", "--verify", "HEAD"], {
|
|
59
|
+
cwd: basePath,
|
|
60
|
+
stdio: "pipe",
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
throw new GSDError(GSD_GIT_ERROR, "Cannot create worktree: repository has no commits yet. Worktree isolation requires at least one commit.");
|
|
65
|
+
}
|
|
66
|
+
const branch = autoWorktreeBranch(milestoneId);
|
|
67
|
+
// Check if the milestone branch already exists — it survives auto-mode
|
|
68
|
+
// stop/pause and contains committed work from prior sessions. If it exists,
|
|
69
|
+
// re-attach the worktree to it WITHOUT resetting. Only create a fresh branch
|
|
70
|
+
// from the integration branch when no prior work exists.
|
|
71
|
+
const branchExists = nativeBranchExists(basePath, branch);
|
|
72
|
+
let info;
|
|
73
|
+
if (branchExists) {
|
|
74
|
+
// #5538-followup: fast-forward the reused branch onto the integration
|
|
75
|
+
// branch when safe so the next milestone forks from up-to-date code.
|
|
76
|
+
// Without this, a milestone that was created before another milestone
|
|
77
|
+
// merged into main would carry a stale base into its worktree.
|
|
78
|
+
fastForwardReusedMilestoneBranchIfSafe(basePath, milestoneId, branch);
|
|
79
|
+
// Re-attach worktree to the existing milestone branch (preserving commits).
|
|
80
|
+
info = createWorktree(basePath, milestoneId, {
|
|
81
|
+
branch,
|
|
82
|
+
reuseExistingBranch: true,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
// Fresh start — create branch from integration branch.
|
|
87
|
+
// Use the same 3-tier fallback as mergeMilestoneToMain (#3461):
|
|
88
|
+
// 1. META.json integration branch (explicit per-milestone override)
|
|
89
|
+
// 2. git.main_branch preference (user's configured working branch)
|
|
90
|
+
// 3. nativeDetectMainBranch (origin/HEAD auto-detection)
|
|
91
|
+
// Without tier 2, projects with main_branch=dev but origin/HEAD→master
|
|
92
|
+
// would fork worktrees from the wrong (stale) branch.
|
|
93
|
+
const integrationBranch = readIntegrationBranch(basePath, milestoneId)
|
|
94
|
+
?? undefined;
|
|
95
|
+
const gitPrefs = loadEffectiveGSDPreferences()?.preferences?.git;
|
|
96
|
+
const startPoint = _resolveAutoWorktreeStartPoint(integrationBranch, gitPrefs?.main_branch, (branchName) => nativeBranchExists(basePath, branchName));
|
|
97
|
+
info = createWorktree(basePath, milestoneId, {
|
|
98
|
+
branch,
|
|
99
|
+
startPoint,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
// Phase C: copyPlanningArtifacts and reconcilePlanCheckboxes were
|
|
103
|
+
// deleted. Both addressed the same problem (worktree-local .gsd/
|
|
104
|
+
// projection lagging behind project-root state) by maintaining a stale
|
|
105
|
+
// copy. Now that auto-mode writers in workflow-projections.ts,
|
|
106
|
+
// triage-resolution.ts, rule-registry.ts, and auto-post-unit.ts route
|
|
107
|
+
// through s.canonicalProjectRoot, the worktree never needs a local
|
|
108
|
+
// .gsd/ — both reads and writes converge on the project-root .gsd/.
|
|
109
|
+
// The original concerns (#759, #778) no longer apply because there is
|
|
110
|
+
// no second copy to drift.
|
|
111
|
+
importUntrackedProjectRootContentIntoEmptyWorktree(basePath, info.path, milestoneId);
|
|
112
|
+
// Run user-configured post-create hook (#597) — e.g. copy .env, symlink assets.
|
|
113
|
+
const hookError = runWorktreePostCreateHook(basePath, info.path);
|
|
114
|
+
if (hookError) {
|
|
115
|
+
// Non-fatal — log but don't prevent worktree usage.
|
|
116
|
+
logWarning("reconcile", hookError, { worktree: info.name });
|
|
117
|
+
}
|
|
118
|
+
const previousCwd = process.cwd();
|
|
119
|
+
try {
|
|
120
|
+
process.chdir(info.path);
|
|
121
|
+
setActiveWorkspace(createWorkspace(basePath));
|
|
122
|
+
}
|
|
123
|
+
catch (err) {
|
|
124
|
+
// If chdir fails, the worktree was created but we couldn't enter it.
|
|
125
|
+
// Don't set activeWorkspace -- caller can retry or clean up.
|
|
126
|
+
throw new GSDError(GSD_IO_ERROR, `Auto-worktree created at ${info.path} but chdir failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
127
|
+
}
|
|
128
|
+
nudgeGitBranchCache(previousCwd);
|
|
129
|
+
return info.path;
|
|
130
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// gsd-pi — Auto-worktree entry and presence detection module.
|
|
2
|
+
//
|
|
3
|
+
// Owns the small interface for finding, entering, and identifying milestone
|
|
4
|
+
// worktrees. The legacy auto-worktree barrel re-exports these functions for
|
|
5
|
+
// compatibility while lifecycle callers can depend on this focused module.
|
|
6
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
import { GSDError, GSD_GIT_ERROR, GSD_IO_ERROR } from "./errors.js";
|
|
9
|
+
import { nativeGetCurrentBranch } from "./native-git-bridge.js";
|
|
10
|
+
import { worktreePath } from "./worktree-manager.js";
|
|
11
|
+
import { worktreePathFor } from "./worktree-placement.js";
|
|
12
|
+
import { nudgeGitBranchCache } from "./worktree.js";
|
|
13
|
+
import { isGsdWorktreePath, normalizeWorktreePathForCompare, resolveWorktreeProjectRoot, } from "./worktree-root.js";
|
|
14
|
+
import { getAutoWorktreeOriginalBase, setActiveWorkspace, } from "./auto-worktree-session-registry.js";
|
|
15
|
+
import { createWorkspace } from "./workspace.js";
|
|
16
|
+
import { logWarning } from "./workflow-logger.js";
|
|
17
|
+
function safeCwd(fallback) {
|
|
18
|
+
try {
|
|
19
|
+
return process.cwd();
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return fallback;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Detect if the process is currently inside an auto-worktree.
|
|
27
|
+
* Uses the current directory structure plus git branch prefix so detection
|
|
28
|
+
* still works after process restart when module state has been reset.
|
|
29
|
+
*/
|
|
30
|
+
export function isInAutoWorktree(basePath) {
|
|
31
|
+
const targetPath = isGsdWorktreePath(basePath) ? basePath : safeCwd("");
|
|
32
|
+
if (!isGsdWorktreePath(targetPath))
|
|
33
|
+
return false;
|
|
34
|
+
const storedBase = getAutoWorktreeOriginalBase();
|
|
35
|
+
const projectRoot = resolveWorktreeProjectRoot(basePath, storedBase);
|
|
36
|
+
const targetProjectRoot = resolveWorktreeProjectRoot(targetPath, storedBase);
|
|
37
|
+
if (normalizeWorktreePathForCompare(projectRoot) !==
|
|
38
|
+
normalizeWorktreePathForCompare(targetProjectRoot)) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const branch = nativeGetCurrentBranch(targetPath);
|
|
43
|
+
return branch.startsWith("milestone/");
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Get the filesystem path for an auto-worktree, or null if it doesn't exist
|
|
51
|
+
* or is not a valid git worktree.
|
|
52
|
+
*
|
|
53
|
+
* Validates that the path is a real git worktree (has a .git file with a
|
|
54
|
+
* gitdir: pointer) rather than just a stray directory. This prevents
|
|
55
|
+
* mis-detection of leftover directories as active worktrees (#695).
|
|
56
|
+
*/
|
|
57
|
+
export function getAutoWorktreePath(basePath, milestoneId) {
|
|
58
|
+
basePath = resolveWorktreeProjectRoot(basePath);
|
|
59
|
+
// basePath is already the resolved project root — go straight to placement
|
|
60
|
+
// instead of worktreePath(), which would re-resolve the root.
|
|
61
|
+
const p = worktreePathFor(basePath, milestoneId);
|
|
62
|
+
if (!existsSync(p))
|
|
63
|
+
return null;
|
|
64
|
+
// Validate this is a real git worktree, not a stray directory.
|
|
65
|
+
// A git worktree has a .git *file* (not directory) containing "gitdir: <path>".
|
|
66
|
+
const gitPath = join(p, ".git");
|
|
67
|
+
if (!existsSync(gitPath))
|
|
68
|
+
return null;
|
|
69
|
+
try {
|
|
70
|
+
const content = readFileSync(gitPath, "utf8").trim();
|
|
71
|
+
if (!content.startsWith("gitdir: "))
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
logWarning("worktree", `getAutoWorktreePath .git read failed: ${e.message}`);
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
return p;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Enter an existing auto-worktree (chdir into it, store originalBase).
|
|
82
|
+
* Use for resume -- the worktree already exists from a prior create.
|
|
83
|
+
*
|
|
84
|
+
* Atomic: chdir + originalBase update in same try block.
|
|
85
|
+
*/
|
|
86
|
+
export function enterAutoWorktree(basePath, milestoneId) {
|
|
87
|
+
basePath = resolveWorktreeProjectRoot(basePath);
|
|
88
|
+
const p = worktreePath(basePath, milestoneId);
|
|
89
|
+
if (!existsSync(p)) {
|
|
90
|
+
throw new GSDError(GSD_IO_ERROR, `Auto-worktree for ${milestoneId} does not exist at ${p}`);
|
|
91
|
+
}
|
|
92
|
+
// Validate this is a real git worktree, not a stray directory (#695)
|
|
93
|
+
const gitPath = join(p, ".git");
|
|
94
|
+
if (!existsSync(gitPath)) {
|
|
95
|
+
throw new GSDError(GSD_GIT_ERROR, `Auto-worktree path ${p} exists but is not a git worktree (no .git)`);
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
const content = readFileSync(gitPath, "utf8").trim();
|
|
99
|
+
if (!content.startsWith("gitdir: ")) {
|
|
100
|
+
throw new GSDError(GSD_GIT_ERROR, `Auto-worktree path ${p} has a .git but it is not a worktree gitdir pointer`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
if (err instanceof Error && err.message.includes("worktree"))
|
|
105
|
+
throw err;
|
|
106
|
+
throw new GSDError(GSD_IO_ERROR, `Auto-worktree path ${p} exists but .git is unreadable`);
|
|
107
|
+
}
|
|
108
|
+
const previousCwd = process.cwd();
|
|
109
|
+
try {
|
|
110
|
+
process.chdir(p);
|
|
111
|
+
setActiveWorkspace(createWorkspace(basePath));
|
|
112
|
+
}
|
|
113
|
+
catch (err) {
|
|
114
|
+
throw new GSDError(GSD_IO_ERROR, `Failed to enter auto-worktree at ${p}: ${err instanceof Error ? err.message : String(err)}`);
|
|
115
|
+
}
|
|
116
|
+
nudgeGitBranchCache(previousCwd);
|
|
117
|
+
return p;
|
|
118
|
+
}
|