@opengsd/gsd-pi 1.4.0-dev.c18009cd → 1.5.0-dev.553dc518
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/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-direct-dispatch.js +4 -5
- package/dist/resources/extensions/gsd/auto-start.js +3 -2
- 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 +19 -1
- package/dist/resources/extensions/gsd/bootstrap/system-context.js +1 -1
- package/dist/resources/extensions/gsd/bootstrap/tool-call-loop-guard.js +118 -21
- 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/doctor-engine-checks.js +93 -11
- package/dist/resources/extensions/gsd/flat-phase-migration.js +14 -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 +11 -0
- package/dist/resources/extensions/gsd/guided-flow.js +6 -10
- package/dist/resources/extensions/gsd/markdown-renderer.js +15 -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/preferences-types.js +1 -0
- package/dist/resources/extensions/gsd/preferences-validation.js +82 -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/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/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/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/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/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-direct-dispatch.ts +4 -5
- package/src/resources/extensions/gsd/auto-start.ts +4 -2
- 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 +19 -1
- package/src/resources/extensions/gsd/bootstrap/system-context.ts +1 -1
- package/src/resources/extensions/gsd/bootstrap/tool-call-loop-guard.ts +152 -21
- 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/doctor-engine-checks.ts +109 -10
- package/src/resources/extensions/gsd/flat-phase-migration.ts +14 -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 +13 -0
- package/src/resources/extensions/gsd/guided-flow.ts +7 -11
- package/src/resources/extensions/gsd/markdown-renderer.ts +15 -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/preferences-types.ts +30 -0
- package/src/resources/extensions/gsd/preferences-validation.ts +69 -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/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-loop-no-copy-artifacts.test.ts +2 -1
- 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/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 +44 -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/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/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/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/prefs-wizard-coverage.test.ts +5 -0
- package/src/resources/extensions/gsd/tests/runtime-invariant-modules.test.ts +20 -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 +103 -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/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/dist/web/standalone/.next/static/{L2UMqXELiDH3oz-7yguXp → ZpFDazP-38PXBPiI_LdZf}/_buildManifest.js +0 -0
- /package/dist/web/standalone/.next/static/{L2UMqXELiDH3oz-7yguXp → ZpFDazP-38PXBPiI_LdZf}/_ssgManifest.js +0 -0
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// gsd-pi — Already-merged milestone merge fast path.
|
|
2
|
+
//
|
|
3
|
+
// Owns the safety invariant for milestone branches already reachable from the
|
|
4
|
+
// integration branch: skip the squash merge only when milestone-touched code is
|
|
5
|
+
// still anchored on the current integration branch, then run normal cleanup.
|
|
6
|
+
import { execFileSync } from "node:child_process";
|
|
7
|
+
import { debugLog } from "./debug-logger.js";
|
|
8
|
+
import { GSDError, GSD_GIT_ERROR } from "./errors.js";
|
|
9
|
+
import { nativeDiffNumstat, nativeIsAncestor, } from "./native-git-bridge.js";
|
|
10
|
+
import { cleanupMergedMilestoneWorktree } from "./auto-worktree-merge-cleanup.js";
|
|
11
|
+
import { logWarning } from "./workflow-logger.js";
|
|
12
|
+
export function finalizeAlreadyMergedMilestoneIfReachable(request) {
|
|
13
|
+
const { projectRoot, milestoneId, milestoneBranch, mainBranch, previousCwd, commitMessage, } = request;
|
|
14
|
+
if (!nativeIsAncestor(projectRoot, milestoneBranch, mainBranch)) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
assertNoUnanchoredRegularMergeCodeChanges({
|
|
18
|
+
projectRoot,
|
|
19
|
+
milestoneBranch,
|
|
20
|
+
mainBranch,
|
|
21
|
+
previousCwd,
|
|
22
|
+
});
|
|
23
|
+
debugLog("mergeMilestoneToMain", {
|
|
24
|
+
action: "skip-squash-already-merged",
|
|
25
|
+
milestoneId,
|
|
26
|
+
milestoneBranch,
|
|
27
|
+
mainBranch,
|
|
28
|
+
});
|
|
29
|
+
cleanupMergedMilestoneWorktree({
|
|
30
|
+
projectRoot,
|
|
31
|
+
milestoneId,
|
|
32
|
+
milestoneBranch,
|
|
33
|
+
previousCwd,
|
|
34
|
+
clearProjectRootState: true,
|
|
35
|
+
chdirWarningContext: "after already-merged cleanup",
|
|
36
|
+
});
|
|
37
|
+
return { commitMessage, pushed: false, prCreated: false, codeFilesChanged: true };
|
|
38
|
+
}
|
|
39
|
+
function assertNoUnanchoredRegularMergeCodeChanges(request) {
|
|
40
|
+
const { projectRoot, milestoneBranch, mainBranch, previousCwd } = request;
|
|
41
|
+
const codeChanges = nativeDiffNumstat(projectRoot, mainBranch, milestoneBranch).filter((entry) => !entry.path.startsWith(".gsd/"));
|
|
42
|
+
if (codeChanges.length === 0)
|
|
43
|
+
return;
|
|
44
|
+
const regularMergeChangedPaths = findRegularMergeChangedPaths(projectRoot, milestoneBranch, mainBranch);
|
|
45
|
+
const unanchoredCodeChanges = codeChanges.filter((entry) => regularMergeChangedPaths.has(entry.path));
|
|
46
|
+
if (unanchoredCodeChanges.length === 0)
|
|
47
|
+
return;
|
|
48
|
+
process.chdir(previousCwd);
|
|
49
|
+
throw new GSDError(GSD_GIT_ERROR, `Milestone branch "${milestoneBranch}" is reachable from "${mainBranch}" ` +
|
|
50
|
+
`but has ${unanchoredCodeChanges.length} milestone-touched code file(s) not on current "${mainBranch}". ` +
|
|
51
|
+
`Aborting worktree teardown to prevent data loss.`);
|
|
52
|
+
}
|
|
53
|
+
function findRegularMergeChangedPaths(basePath, milestoneBranch, mainBranch) {
|
|
54
|
+
const changedPaths = new Set();
|
|
55
|
+
let mergeLog = "";
|
|
56
|
+
try {
|
|
57
|
+
mergeLog = execFileSync("git", ["rev-list", "--merges", "--parents", mainBranch], {
|
|
58
|
+
cwd: basePath,
|
|
59
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
60
|
+
encoding: "utf-8",
|
|
61
|
+
}).trim();
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
logWarning("worktree", `regular merge lookup failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
65
|
+
return changedPaths;
|
|
66
|
+
}
|
|
67
|
+
for (const line of mergeLog.split("\n").filter(Boolean)) {
|
|
68
|
+
const [mergeCommit, firstParent, ...otherParents] = line.split(" ");
|
|
69
|
+
if (!mergeCommit || !firstParent || otherParents.length === 0)
|
|
70
|
+
continue;
|
|
71
|
+
const mergedMilestone = otherParents.some((parent) => {
|
|
72
|
+
try {
|
|
73
|
+
return nativeIsAncestor(basePath, milestoneBranch, parent);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
if (!mergedMilestone)
|
|
80
|
+
continue;
|
|
81
|
+
try {
|
|
82
|
+
const output = execFileSync("git", ["diff", "--name-only", firstParent, mergeCommit], {
|
|
83
|
+
cwd: basePath,
|
|
84
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
85
|
+
encoding: "utf-8",
|
|
86
|
+
}).trim();
|
|
87
|
+
for (const path of output.split("\n").filter(Boolean)) {
|
|
88
|
+
if (!path.startsWith(".gsd/"))
|
|
89
|
+
changedPaths.add(path);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
logWarning("worktree", `regular merge diff lookup failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
94
|
+
}
|
|
95
|
+
return changedPaths;
|
|
96
|
+
}
|
|
97
|
+
return changedPaths;
|
|
98
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// gsd-pi — Milestone branch/head reconciliation before merge.
|
|
2
|
+
//
|
|
3
|
+
// Owns the data-loss guard that keeps the named milestone branch aligned with
|
|
4
|
+
// the actual worktree HEAD. Detached worktree commits can otherwise sit beyond
|
|
5
|
+
// the branch ref and be silently omitted from the integration merge.
|
|
6
|
+
import { execFileSync } from "node:child_process";
|
|
7
|
+
import { debugLog } from "./debug-logger.js";
|
|
8
|
+
import { GSDError, GSD_GIT_ERROR } from "./errors.js";
|
|
9
|
+
import { nativeIsAncestor, nativeUpdateRef, } from "./native-git-bridge.js";
|
|
10
|
+
export function reconcileMilestoneBranchHead(request) {
|
|
11
|
+
const { projectRoot, worktreeCwd, milestoneBranch, previousCwd } = request;
|
|
12
|
+
if (worktreeCwd === projectRoot) {
|
|
13
|
+
return { checked: false, updated: false, reason: "not-worktree" };
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
const worktreeHead = gitRevParse(worktreeCwd, "HEAD");
|
|
17
|
+
const branchHead = gitRevParse(projectRoot, milestoneBranch);
|
|
18
|
+
if (!worktreeHead || !branchHead || worktreeHead === branchHead) {
|
|
19
|
+
return { checked: true, updated: false, reason: "already-current" };
|
|
20
|
+
}
|
|
21
|
+
if (nativeIsAncestor(projectRoot, branchHead, worktreeHead)) {
|
|
22
|
+
nativeUpdateRef(projectRoot, `refs/heads/${milestoneBranch}`, worktreeHead);
|
|
23
|
+
debugLog("mergeMilestoneToMain", {
|
|
24
|
+
action: "fast-forward-branch-ref",
|
|
25
|
+
milestoneBranch,
|
|
26
|
+
oldRef: branchHead.slice(0, 8),
|
|
27
|
+
newRef: worktreeHead.slice(0, 8),
|
|
28
|
+
});
|
|
29
|
+
return { checked: true, updated: true, reason: "fast-forwarded" };
|
|
30
|
+
}
|
|
31
|
+
process.chdir(previousCwd);
|
|
32
|
+
throw new GSDError(GSD_GIT_ERROR, `Worktree HEAD (${worktreeHead.slice(0, 8)}) diverged from ` +
|
|
33
|
+
`${milestoneBranch} (${branchHead.slice(0, 8)}). ` +
|
|
34
|
+
`Manual reconciliation required before merge.`);
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
if (err instanceof GSDError)
|
|
38
|
+
throw err;
|
|
39
|
+
debugLog("mergeMilestoneToMain", {
|
|
40
|
+
action: "reconcile-skipped",
|
|
41
|
+
reason: String(err),
|
|
42
|
+
});
|
|
43
|
+
return { checked: false, updated: false, reason: "lookup-failed" };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function gitRevParse(cwd, ref) {
|
|
47
|
+
return execFileSync("git", ["rev-parse", ref], {
|
|
48
|
+
cwd,
|
|
49
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
50
|
+
encoding: "utf-8",
|
|
51
|
+
}).trim();
|
|
52
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// gsd-pi — Milestone merge cleanup module.
|
|
2
|
+
//
|
|
3
|
+
// Owns the teardown ordering after a milestone has safely reached the
|
|
4
|
+
// integration branch: clear transient state, remove the worktree, delete the
|
|
5
|
+
// milestone branch only after removal succeeds, clear process-local workspace
|
|
6
|
+
// state, and anchor cwd back at the project root.
|
|
7
|
+
import { nativeBranchDelete } from "./native-git-bridge.js";
|
|
8
|
+
import { clearProjectRootStateFiles } from "./auto-worktree-cleanup.js";
|
|
9
|
+
import { setActiveWorkspace } from "./auto-worktree-session-registry.js";
|
|
10
|
+
import { removeWorktree } from "./worktree-manager.js";
|
|
11
|
+
import { nudgeGitBranchCache } from "./worktree.js";
|
|
12
|
+
import { debugLog } from "./debug-logger.js";
|
|
13
|
+
import { logWarning } from "./workflow-logger.js";
|
|
14
|
+
const defaultDeps = {
|
|
15
|
+
clearProjectRootStateFiles,
|
|
16
|
+
removeWorktree,
|
|
17
|
+
nativeBranchDelete,
|
|
18
|
+
setActiveWorkspace,
|
|
19
|
+
nudgeGitBranchCache,
|
|
20
|
+
chdir: process.chdir.bind(process),
|
|
21
|
+
};
|
|
22
|
+
let deps = defaultDeps;
|
|
23
|
+
export function _setMilestoneCleanupDepsForTests(overrides) {
|
|
24
|
+
deps = { ...defaultDeps, ...overrides };
|
|
25
|
+
}
|
|
26
|
+
export function _resetMilestoneCleanupDepsForTests() {
|
|
27
|
+
deps = defaultDeps;
|
|
28
|
+
}
|
|
29
|
+
export function cleanupMergedMilestoneWorktree(request) {
|
|
30
|
+
const { projectRoot, milestoneId, milestoneBranch, previousCwd, clearProjectRootState = false, chdirWarningContext = "after milestone cleanup", } = request;
|
|
31
|
+
if (clearProjectRootState) {
|
|
32
|
+
try {
|
|
33
|
+
deps.clearProjectRootStateFiles(projectRoot, milestoneId);
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
logWarning("worktree", `clearProjectRootStateFiles failed during milestone cleanup: ${err instanceof Error ? err.message : String(err)}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
let worktreeRemoved = true;
|
|
40
|
+
try {
|
|
41
|
+
worktreeRemoved = deps.removeWorktree(projectRoot, milestoneId, {
|
|
42
|
+
branch: milestoneBranch,
|
|
43
|
+
deleteBranch: false,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
worktreeRemoved = false;
|
|
48
|
+
logWarning("worktree", `worktree removal failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
49
|
+
}
|
|
50
|
+
if (!worktreeRemoved) {
|
|
51
|
+
logWarning("worktree", `Skipping milestone branch deletion for ${milestoneBranch}; worktree removal was aborted to preserve uncommitted milestone work.`);
|
|
52
|
+
deps.nudgeGitBranchCache(previousCwd);
|
|
53
|
+
chdirToProjectRoot(projectRoot, chdirWarningContext);
|
|
54
|
+
return {
|
|
55
|
+
worktreeRemoved: false,
|
|
56
|
+
branchDeleteAttempted: false,
|
|
57
|
+
activeWorkspaceCleared: false,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
deps.nativeBranchDelete(projectRoot, milestoneBranch);
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
logWarning("worktree", `git branch-delete failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
65
|
+
}
|
|
66
|
+
deps.setActiveWorkspace(null);
|
|
67
|
+
deps.nudgeGitBranchCache(previousCwd);
|
|
68
|
+
chdirToProjectRoot(projectRoot, chdirWarningContext);
|
|
69
|
+
return {
|
|
70
|
+
worktreeRemoved: true,
|
|
71
|
+
branchDeleteAttempted: true,
|
|
72
|
+
activeWorkspaceCleared: true,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function chdirToProjectRoot(projectRoot, context) {
|
|
76
|
+
try {
|
|
77
|
+
deps.chdir(projectRoot);
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
logWarning("worktree", `chdir to project root ${context} failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
81
|
+
debugLog("mergeMilestoneToMain", {
|
|
82
|
+
phase: "post-merge-chdir-failed",
|
|
83
|
+
target: projectRoot,
|
|
84
|
+
error: err instanceof Error ? err.message : String(err),
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// gsd-pi — Code-change safety checks for auto-worktree merge closeout.
|
|
2
|
+
//
|
|
3
|
+
// Owns the git diff policy that decides whether a completed milestone actually
|
|
4
|
+
// changed user code, and whether an empty merge result is safe to clean up.
|
|
5
|
+
import { execFileSync } from "node:child_process";
|
|
6
|
+
import { GSDError, GSD_GIT_ERROR } from "./errors.js";
|
|
7
|
+
import { nativeDiffNumstat } from "./native-git-bridge.js";
|
|
8
|
+
import { logWarning } from "./workflow-logger.js";
|
|
9
|
+
const GIT_EMPTY_TREE = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
|
|
10
|
+
export function assertNoUnanchoredCodeChangesAfterEmptyMerge(basePath, mainBranch, milestoneBranch, effectiveStrategy, nothingToCommit) {
|
|
11
|
+
if (!nothingToCommit)
|
|
12
|
+
return;
|
|
13
|
+
const codeChanges = nativeDiffNumstat(basePath, mainBranch, milestoneBranch)
|
|
14
|
+
.filter((entry) => !entry.path.startsWith(".gsd/"));
|
|
15
|
+
if (codeChanges.length === 0)
|
|
16
|
+
return;
|
|
17
|
+
throw new GSDError(GSD_GIT_ERROR, `${effectiveStrategy === "merge" ? "Merge" : "Squash merge"} produced nothing to commit but milestone branch "${milestoneBranch}" ` +
|
|
18
|
+
`has ${codeChanges.length} code file(s) not on "${mainBranch}". ` +
|
|
19
|
+
`Aborting worktree teardown to prevent data loss.`);
|
|
20
|
+
}
|
|
21
|
+
export function detectMergedCodeFilesChanged(basePath, nothingToCommit) {
|
|
22
|
+
if (nothingToCommit)
|
|
23
|
+
return false;
|
|
24
|
+
try {
|
|
25
|
+
const diffTreeOutput = execFileSync("git", ["diff-tree", "--root", "--no-commit-id", "-r", "--name-only", "HEAD"], { cwd: basePath, stdio: ["ignore", "pipe", "pipe"], encoding: "utf-8" }).trim();
|
|
26
|
+
return containsCodeFile(diffTreeOutput);
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
return detectCodeFilesChangedFromEmptyTree(basePath, err);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function detectCodeFilesChangedFromEmptyTree(basePath, originalError) {
|
|
33
|
+
try {
|
|
34
|
+
const fallbackOutput = execFileSync("git", ["diff", "--name-only", GIT_EMPTY_TREE, "HEAD"], { cwd: basePath, stdio: ["ignore", "pipe", "pipe"], encoding: "utf-8" }).trim();
|
|
35
|
+
return containsCodeFile(fallbackOutput);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// Truly unable to determine — assume code was changed to avoid silent data loss.
|
|
39
|
+
logWarning("worktree", `diff-tree and empty-tree fallback both failed (assuming code changed): ${originalError instanceof Error ? originalError.message : String(originalError)}`);
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function containsCodeFile(output) {
|
|
44
|
+
const files = output ? output.split("\n").filter(Boolean) : [];
|
|
45
|
+
return files.some((file) => !file.startsWith(".gsd/"));
|
|
46
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// gsd-pi — Milestone merge DB readiness guard.
|
|
2
|
+
//
|
|
3
|
+
// Owns the invariant that, before leaving worktree context for a milestone
|
|
4
|
+
// merge, the project DB is the active DB, worktree DB state is reconciled, and
|
|
5
|
+
// canonical closeout state proves the milestone is safe to merge.
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import { CLOSEOUT_CONSISTENCY_BLOCKED_REASON } from "./closeout-consistency-gate.js";
|
|
8
|
+
import { closeWorkflowDatabase, getWorkflowDatabasePath, openWorkflowDatabasePath, } from "./db-workspace.js";
|
|
9
|
+
import { GSDError, GSD_GIT_ERROR } from "./errors.js";
|
|
10
|
+
import { isDbAvailable, reconcileWorktreeDb, } from "./gsd-db.js";
|
|
11
|
+
import { formatCloseoutProofBlock, proveMilestoneCloseout, } from "./milestone-closeout-proof.js";
|
|
12
|
+
import { resolveGsdPathContract } from "./paths.js";
|
|
13
|
+
import { _shouldReconcileWorktreeDb } from "./auto-worktree-cleanup.js";
|
|
14
|
+
import { logError } from "./workflow-logger.js";
|
|
15
|
+
const defaultDeps = {
|
|
16
|
+
closeWorkflowDatabase,
|
|
17
|
+
formatCloseoutProofBlock,
|
|
18
|
+
getWorkflowDatabasePath,
|
|
19
|
+
isDbAvailable,
|
|
20
|
+
logError,
|
|
21
|
+
openWorkflowDatabasePath,
|
|
22
|
+
proveMilestoneCloseout,
|
|
23
|
+
reconcileWorktreeDb,
|
|
24
|
+
resolveGsdPathContract,
|
|
25
|
+
shouldReconcileWorktreeDb: _shouldReconcileWorktreeDb,
|
|
26
|
+
};
|
|
27
|
+
let deps = defaultDeps;
|
|
28
|
+
export function _setMergeDbReadyDepsForTests(overrides) {
|
|
29
|
+
deps = { ...defaultDeps, ...overrides };
|
|
30
|
+
}
|
|
31
|
+
export function _resetMergeDbReadyDepsForTests() {
|
|
32
|
+
deps = defaultDeps;
|
|
33
|
+
}
|
|
34
|
+
function reconcileWorktreeDatabase(request) {
|
|
35
|
+
const { milestoneId, projectRoot, worktreeCwd } = request;
|
|
36
|
+
const contract = deps.resolveGsdPathContract(worktreeCwd, projectRoot);
|
|
37
|
+
const worktreeDbPath = join(contract.worktreeGsd ?? join(worktreeCwd, ".gsd"), "gsd.db");
|
|
38
|
+
const mainDbPath = contract.projectDb;
|
|
39
|
+
try {
|
|
40
|
+
const activeDbPath = deps.getWorkflowDatabasePath();
|
|
41
|
+
if (activeDbPath && deps.shouldReconcileWorktreeDb(activeDbPath, mainDbPath)) {
|
|
42
|
+
deps.closeWorkflowDatabase();
|
|
43
|
+
if (!deps.openWorkflowDatabasePath(mainDbPath)) {
|
|
44
|
+
throw new Error(`cannot open project DB at ${mainDbPath}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (deps.shouldReconcileWorktreeDb(worktreeDbPath, mainDbPath)) {
|
|
48
|
+
deps.reconcileWorktreeDb(mainDbPath, worktreeDbPath);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
const message = `DB reconciliation failed before milestone ${milestoneId} merge: ${err instanceof Error ? err.message : String(err)}`;
|
|
53
|
+
deps.logError("worktree", message);
|
|
54
|
+
throw new GSDError(GSD_GIT_ERROR, `${message}. Recovery reason: ${CLOSEOUT_CONSISTENCY_BLOCKED_REASON}.`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function assertCloseoutProof(milestoneId) {
|
|
58
|
+
const closeoutProof = deps.proveMilestoneCloseout(milestoneId);
|
|
59
|
+
if (!closeoutProof.ok) {
|
|
60
|
+
throw new GSDError(GSD_GIT_ERROR, deps.formatCloseoutProofBlock(closeoutProof));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export function assertMilestoneDbReadyForMerge(request) {
|
|
64
|
+
if (!deps.isDbAvailable())
|
|
65
|
+
return;
|
|
66
|
+
reconcileWorktreeDatabase(request);
|
|
67
|
+
assertCloseoutProof(request.milestoneId);
|
|
68
|
+
}
|