gsd-pi 2.29.0-dev.49d972f → 2.29.0-dev.4c155ee
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 +24 -17
- package/dist/headless.js +4 -0
- package/dist/resources/extensions/bg-shell/process-manager.ts +13 -0
- package/dist/resources/extensions/gsd/auto-dashboard.ts +217 -65
- package/dist/resources/extensions/gsd/auto-dispatch.ts +32 -3
- package/dist/resources/extensions/gsd/auto-post-unit.ts +44 -12
- package/dist/resources/extensions/gsd/auto-prompts.ts +40 -17
- package/dist/resources/extensions/gsd/auto-recovery.ts +2 -1
- package/dist/resources/extensions/gsd/auto-start.ts +18 -32
- package/dist/resources/extensions/gsd/auto-worktree.ts +21 -182
- package/dist/resources/extensions/gsd/auto.ts +2 -9
- package/dist/resources/extensions/gsd/captures.ts +4 -10
- package/dist/resources/extensions/gsd/commands-handlers.ts +2 -1
- package/dist/resources/extensions/gsd/commands-prefs-wizard.ts +44 -14
- package/dist/resources/extensions/gsd/commands-workflow-templates.ts +544 -0
- package/dist/resources/extensions/gsd/commands.ts +55 -2
- package/dist/resources/extensions/gsd/detection.ts +2 -1
- package/dist/resources/extensions/gsd/doctor-checks.ts +49 -1
- package/dist/resources/extensions/gsd/doctor-types.ts +3 -1
- package/dist/resources/extensions/gsd/forensics.ts +2 -2
- package/dist/resources/extensions/gsd/git-service.ts +3 -2
- package/dist/resources/extensions/gsd/gitignore.ts +9 -63
- package/dist/resources/extensions/gsd/gsd-db.ts +1 -165
- package/dist/resources/extensions/gsd/guided-flow.ts +8 -5
- package/dist/resources/extensions/gsd/index.ts +3 -3
- package/dist/resources/extensions/gsd/md-importer.ts +3 -2
- package/dist/resources/extensions/gsd/mechanical-completion.ts +430 -0
- package/dist/resources/extensions/gsd/migrate/command.ts +3 -2
- package/dist/resources/extensions/gsd/migrate/writer.ts +2 -1
- package/dist/resources/extensions/gsd/migrate-external.ts +123 -0
- package/dist/resources/extensions/gsd/paths.ts +24 -2
- package/dist/resources/extensions/gsd/post-unit-hooks.ts +6 -5
- package/dist/resources/extensions/gsd/preferences-models.ts +7 -1
- package/dist/resources/extensions/gsd/preferences-validation.ts +2 -1
- package/dist/resources/extensions/gsd/preferences.ts +10 -5
- package/dist/resources/extensions/gsd/prompts/discuss-headless.md +4 -2
- package/dist/resources/extensions/gsd/prompts/guided-discuss-milestone.md +1 -1
- package/dist/resources/extensions/gsd/prompts/plan-milestone.md +26 -2
- package/dist/resources/extensions/gsd/prompts/plan-slice.md +15 -1
- package/dist/resources/extensions/gsd/prompts/workflow-start.md +28 -0
- package/dist/resources/extensions/gsd/repo-identity.ts +148 -0
- package/dist/resources/extensions/gsd/resource-version.ts +99 -0
- package/dist/resources/extensions/gsd/session-forensics.ts +4 -3
- package/dist/resources/extensions/gsd/tests/activity-log.test.ts +2 -2
- package/dist/resources/extensions/gsd/tests/auto-recovery.test.ts +3 -3
- package/dist/resources/extensions/gsd/tests/auto-worktree.test.ts +0 -58
- package/dist/resources/extensions/gsd/tests/doctor-runtime.test.ts +3 -4
- package/dist/resources/extensions/gsd/tests/extension-selector-separator.test.ts +60 -38
- package/dist/resources/extensions/gsd/tests/feature-branch-lifecycle-integration.test.ts +5 -18
- package/dist/resources/extensions/gsd/tests/git-service.test.ts +10 -37
- package/dist/resources/extensions/gsd/tests/knowledge.test.ts +4 -4
- package/dist/resources/extensions/gsd/tests/mechanical-completion.test.ts +356 -0
- package/dist/resources/extensions/gsd/tests/plan-slice-prompt.test.ts +1 -0
- package/dist/resources/extensions/gsd/tests/token-profile.test.ts +14 -16
- package/dist/resources/extensions/gsd/tests/workflow-templates.test.ts +173 -0
- package/dist/resources/extensions/gsd/triage-resolution.ts +2 -1
- package/dist/resources/extensions/gsd/types.ts +2 -0
- package/dist/resources/extensions/gsd/workflow-templates/bugfix.md +87 -0
- package/dist/resources/extensions/gsd/workflow-templates/dep-upgrade.md +74 -0
- package/dist/resources/extensions/gsd/workflow-templates/full-project.md +41 -0
- package/dist/resources/extensions/gsd/workflow-templates/hotfix.md +45 -0
- package/dist/resources/extensions/gsd/workflow-templates/refactor.md +83 -0
- package/dist/resources/extensions/gsd/workflow-templates/registry.json +85 -0
- package/dist/resources/extensions/gsd/workflow-templates/security-audit.md +73 -0
- package/dist/resources/extensions/gsd/workflow-templates/small-feature.md +81 -0
- package/dist/resources/extensions/gsd/workflow-templates/spike.md +69 -0
- package/dist/resources/extensions/gsd/workflow-templates.ts +241 -0
- package/dist/resources/extensions/gsd/worktree-command.ts +1 -11
- package/dist/resources/extensions/gsd/worktree-manager.ts +3 -2
- package/dist/resources/extensions/gsd/worktree.ts +42 -5
- package/dist/resources/extensions/mcp-client/index.ts +459 -0
- package/dist/resources/skills/create-gsd-extension/SKILL.md +87 -0
- package/dist/resources/skills/create-gsd-extension/references/compaction-session-control.md +77 -0
- package/dist/resources/skills/create-gsd-extension/references/custom-commands.md +139 -0
- package/dist/resources/skills/create-gsd-extension/references/custom-rendering.md +108 -0
- package/dist/resources/skills/create-gsd-extension/references/custom-tools.md +183 -0
- package/dist/resources/skills/create-gsd-extension/references/custom-ui.md +490 -0
- package/dist/resources/skills/create-gsd-extension/references/events-reference.md +126 -0
- package/dist/resources/skills/create-gsd-extension/references/extension-lifecycle.md +64 -0
- package/dist/resources/skills/create-gsd-extension/references/extensionapi-reference.md +75 -0
- package/dist/resources/skills/create-gsd-extension/references/extensioncontext-reference.md +53 -0
- package/dist/resources/skills/create-gsd-extension/references/key-rules-gotchas.md +36 -0
- package/dist/resources/skills/create-gsd-extension/references/mode-behavior.md +32 -0
- package/dist/resources/skills/create-gsd-extension/references/model-provider-management.md +89 -0
- package/dist/resources/skills/create-gsd-extension/references/packaging-distribution.md +55 -0
- package/dist/resources/skills/create-gsd-extension/references/remote-execution-overrides.md +90 -0
- package/dist/resources/skills/create-gsd-extension/references/state-management.md +70 -0
- package/dist/resources/skills/create-gsd-extension/references/system-prompt-modification.md +52 -0
- package/dist/resources/skills/create-gsd-extension/templates/extension-skeleton.ts +51 -0
- package/dist/resources/skills/create-gsd-extension/templates/stateful-tool-skeleton.ts +143 -0
- package/dist/resources/skills/create-gsd-extension/workflows/add-capability.md +57 -0
- package/dist/resources/skills/create-gsd-extension/workflows/create-extension.md +156 -0
- package/dist/resources/skills/create-gsd-extension/workflows/debug-extension.md +74 -0
- package/dist/resources/skills/create-skill/SKILL.md +184 -0
- package/dist/resources/skills/create-skill/references/api-security.md +226 -0
- package/dist/resources/skills/create-skill/references/be-clear-and-direct.md +531 -0
- package/dist/resources/skills/create-skill/references/common-patterns.md +595 -0
- package/dist/resources/skills/create-skill/references/core-principles.md +437 -0
- package/dist/resources/skills/create-skill/references/executable-code.md +175 -0
- package/dist/resources/skills/create-skill/references/gsd-skill-ecosystem.md +68 -0
- package/dist/resources/skills/create-skill/references/iteration-and-testing.md +474 -0
- package/dist/resources/skills/create-skill/references/recommended-structure.md +168 -0
- package/dist/resources/skills/create-skill/references/skill-structure.md +372 -0
- package/dist/resources/skills/create-skill/references/use-xml-tags.md +466 -0
- package/dist/resources/skills/create-skill/references/using-scripts.md +113 -0
- package/dist/resources/skills/create-skill/references/using-templates.md +112 -0
- package/dist/resources/skills/create-skill/references/workflows-and-validation.md +510 -0
- package/dist/resources/skills/create-skill/templates/router-skill.md +73 -0
- package/dist/resources/skills/create-skill/templates/simple-skill.md +33 -0
- package/dist/resources/skills/create-skill/workflows/add-reference.md +96 -0
- package/dist/resources/skills/create-skill/workflows/add-script.md +93 -0
- package/dist/resources/skills/create-skill/workflows/add-template.md +74 -0
- package/dist/resources/skills/create-skill/workflows/add-workflow.md +120 -0
- package/dist/resources/skills/create-skill/workflows/audit-skill.md +148 -0
- package/dist/resources/skills/create-skill/workflows/create-new-skill.md +196 -0
- package/dist/resources/skills/create-skill/workflows/get-guidance.md +121 -0
- package/dist/resources/skills/create-skill/workflows/upgrade-to-router.md +161 -0
- package/dist/resources/skills/create-skill/workflows/verify-skill.md +204 -0
- package/dist/resources/skills/react-best-practices/SKILL.md +1 -1
- package/package.json +1 -1
- package/packages/native/dist/native.d.ts +2 -0
- package/packages/native/dist/native.js +19 -5
- package/packages/native/src/native.ts +23 -9
- package/packages/pi-coding-agent/dist/core/extensions/loader.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/loader.js +13 -0
- package/packages/pi-coding-agent/dist/core/extensions/loader.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/client.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/client.js +3 -0
- package/packages/pi-coding-agent/dist/core/lsp/client.js.map +1 -1
- package/packages/pi-coding-agent/src/core/extensions/loader.ts +13 -0
- package/packages/pi-coding-agent/src/core/lsp/client.ts +3 -0
- package/src/resources/extensions/bg-shell/process-manager.ts +13 -0
- package/src/resources/extensions/gsd/auto-dashboard.ts +217 -65
- package/src/resources/extensions/gsd/auto-dispatch.ts +32 -3
- package/src/resources/extensions/gsd/auto-post-unit.ts +44 -12
- package/src/resources/extensions/gsd/auto-prompts.ts +40 -17
- package/src/resources/extensions/gsd/auto-recovery.ts +2 -1
- package/src/resources/extensions/gsd/auto-start.ts +18 -32
- package/src/resources/extensions/gsd/auto-worktree.ts +21 -182
- package/src/resources/extensions/gsd/auto.ts +2 -9
- package/src/resources/extensions/gsd/captures.ts +4 -10
- package/src/resources/extensions/gsd/commands-handlers.ts +2 -1
- package/src/resources/extensions/gsd/commands-prefs-wizard.ts +44 -14
- package/src/resources/extensions/gsd/commands-workflow-templates.ts +544 -0
- package/src/resources/extensions/gsd/commands.ts +55 -2
- package/src/resources/extensions/gsd/detection.ts +2 -1
- package/src/resources/extensions/gsd/doctor-checks.ts +49 -1
- package/src/resources/extensions/gsd/doctor-types.ts +3 -1
- package/src/resources/extensions/gsd/forensics.ts +2 -2
- package/src/resources/extensions/gsd/git-service.ts +3 -2
- package/src/resources/extensions/gsd/gitignore.ts +9 -63
- package/src/resources/extensions/gsd/gsd-db.ts +1 -165
- package/src/resources/extensions/gsd/guided-flow.ts +8 -5
- package/src/resources/extensions/gsd/index.ts +3 -3
- package/src/resources/extensions/gsd/md-importer.ts +3 -2
- package/src/resources/extensions/gsd/mechanical-completion.ts +430 -0
- package/src/resources/extensions/gsd/migrate/command.ts +3 -2
- package/src/resources/extensions/gsd/migrate/writer.ts +2 -1
- package/src/resources/extensions/gsd/migrate-external.ts +123 -0
- package/src/resources/extensions/gsd/paths.ts +24 -2
- package/src/resources/extensions/gsd/post-unit-hooks.ts +6 -5
- package/src/resources/extensions/gsd/preferences-models.ts +7 -1
- package/src/resources/extensions/gsd/preferences-validation.ts +2 -1
- package/src/resources/extensions/gsd/preferences.ts +10 -5
- package/src/resources/extensions/gsd/prompts/discuss-headless.md +4 -2
- package/src/resources/extensions/gsd/prompts/guided-discuss-milestone.md +1 -1
- package/src/resources/extensions/gsd/prompts/plan-milestone.md +26 -2
- package/src/resources/extensions/gsd/prompts/plan-slice.md +15 -1
- package/src/resources/extensions/gsd/prompts/workflow-start.md +28 -0
- package/src/resources/extensions/gsd/repo-identity.ts +148 -0
- package/src/resources/extensions/gsd/resource-version.ts +99 -0
- package/src/resources/extensions/gsd/session-forensics.ts +4 -3
- package/src/resources/extensions/gsd/tests/activity-log.test.ts +2 -2
- package/src/resources/extensions/gsd/tests/auto-recovery.test.ts +3 -3
- package/src/resources/extensions/gsd/tests/auto-worktree.test.ts +0 -58
- package/src/resources/extensions/gsd/tests/doctor-runtime.test.ts +3 -4
- package/src/resources/extensions/gsd/tests/extension-selector-separator.test.ts +60 -38
- package/src/resources/extensions/gsd/tests/feature-branch-lifecycle-integration.test.ts +5 -18
- package/src/resources/extensions/gsd/tests/git-service.test.ts +10 -37
- package/src/resources/extensions/gsd/tests/knowledge.test.ts +4 -4
- package/src/resources/extensions/gsd/tests/mechanical-completion.test.ts +356 -0
- package/src/resources/extensions/gsd/tests/plan-slice-prompt.test.ts +1 -0
- package/src/resources/extensions/gsd/tests/token-profile.test.ts +14 -16
- package/src/resources/extensions/gsd/tests/workflow-templates.test.ts +173 -0
- package/src/resources/extensions/gsd/triage-resolution.ts +2 -1
- package/src/resources/extensions/gsd/types.ts +2 -0
- package/src/resources/extensions/gsd/workflow-templates/bugfix.md +87 -0
- package/src/resources/extensions/gsd/workflow-templates/dep-upgrade.md +74 -0
- package/src/resources/extensions/gsd/workflow-templates/full-project.md +41 -0
- package/src/resources/extensions/gsd/workflow-templates/hotfix.md +45 -0
- package/src/resources/extensions/gsd/workflow-templates/refactor.md +83 -0
- package/src/resources/extensions/gsd/workflow-templates/registry.json +85 -0
- package/src/resources/extensions/gsd/workflow-templates/security-audit.md +73 -0
- package/src/resources/extensions/gsd/workflow-templates/small-feature.md +81 -0
- package/src/resources/extensions/gsd/workflow-templates/spike.md +69 -0
- package/src/resources/extensions/gsd/workflow-templates.ts +241 -0
- package/src/resources/extensions/gsd/worktree-command.ts +1 -11
- package/src/resources/extensions/gsd/worktree-manager.ts +3 -2
- package/src/resources/extensions/gsd/worktree.ts +42 -5
- package/src/resources/extensions/mcp-client/index.ts +459 -0
- package/src/resources/skills/create-gsd-extension/SKILL.md +87 -0
- package/src/resources/skills/create-gsd-extension/references/compaction-session-control.md +77 -0
- package/src/resources/skills/create-gsd-extension/references/custom-commands.md +139 -0
- package/src/resources/skills/create-gsd-extension/references/custom-rendering.md +108 -0
- package/src/resources/skills/create-gsd-extension/references/custom-tools.md +183 -0
- package/src/resources/skills/create-gsd-extension/references/custom-ui.md +490 -0
- package/src/resources/skills/create-gsd-extension/references/events-reference.md +126 -0
- package/src/resources/skills/create-gsd-extension/references/extension-lifecycle.md +64 -0
- package/src/resources/skills/create-gsd-extension/references/extensionapi-reference.md +75 -0
- package/src/resources/skills/create-gsd-extension/references/extensioncontext-reference.md +53 -0
- package/src/resources/skills/create-gsd-extension/references/key-rules-gotchas.md +36 -0
- package/src/resources/skills/create-gsd-extension/references/mode-behavior.md +32 -0
- package/src/resources/skills/create-gsd-extension/references/model-provider-management.md +89 -0
- package/src/resources/skills/create-gsd-extension/references/packaging-distribution.md +55 -0
- package/src/resources/skills/create-gsd-extension/references/remote-execution-overrides.md +90 -0
- package/src/resources/skills/create-gsd-extension/references/state-management.md +70 -0
- package/src/resources/skills/create-gsd-extension/references/system-prompt-modification.md +52 -0
- package/src/resources/skills/create-gsd-extension/templates/extension-skeleton.ts +51 -0
- package/src/resources/skills/create-gsd-extension/templates/stateful-tool-skeleton.ts +143 -0
- package/src/resources/skills/create-gsd-extension/workflows/add-capability.md +57 -0
- package/src/resources/skills/create-gsd-extension/workflows/create-extension.md +156 -0
- package/src/resources/skills/create-gsd-extension/workflows/debug-extension.md +74 -0
- package/src/resources/skills/create-skill/SKILL.md +184 -0
- package/src/resources/skills/create-skill/references/api-security.md +226 -0
- package/src/resources/skills/create-skill/references/be-clear-and-direct.md +531 -0
- package/src/resources/skills/create-skill/references/common-patterns.md +595 -0
- package/src/resources/skills/create-skill/references/core-principles.md +437 -0
- package/src/resources/skills/create-skill/references/executable-code.md +175 -0
- package/src/resources/skills/create-skill/references/gsd-skill-ecosystem.md +68 -0
- package/src/resources/skills/create-skill/references/iteration-and-testing.md +474 -0
- package/src/resources/skills/create-skill/references/recommended-structure.md +168 -0
- package/src/resources/skills/create-skill/references/skill-structure.md +372 -0
- package/src/resources/skills/create-skill/references/use-xml-tags.md +466 -0
- package/src/resources/skills/create-skill/references/using-scripts.md +113 -0
- package/src/resources/skills/create-skill/references/using-templates.md +112 -0
- package/src/resources/skills/create-skill/references/workflows-and-validation.md +510 -0
- package/src/resources/skills/create-skill/templates/router-skill.md +73 -0
- package/src/resources/skills/create-skill/templates/simple-skill.md +33 -0
- package/src/resources/skills/create-skill/workflows/add-reference.md +96 -0
- package/src/resources/skills/create-skill/workflows/add-script.md +93 -0
- package/src/resources/skills/create-skill/workflows/add-template.md +74 -0
- package/src/resources/skills/create-skill/workflows/add-workflow.md +120 -0
- package/src/resources/skills/create-skill/workflows/audit-skill.md +148 -0
- package/src/resources/skills/create-skill/workflows/create-new-skill.md +196 -0
- package/src/resources/skills/create-skill/workflows/get-guidance.md +121 -0
- package/src/resources/skills/create-skill/workflows/upgrade-to-router.md +161 -0
- package/src/resources/skills/create-skill/workflows/verify-skill.md +204 -0
- package/src/resources/skills/react-best-practices/SKILL.md +1 -1
- package/dist/resources/extensions/gsd/auto-worktree-sync.ts +0 -199
- package/dist/resources/extensions/gsd/tests/worktree-db-integration.test.ts +0 -205
- package/dist/resources/extensions/gsd/tests/worktree-db.test.ts +0 -442
- package/dist/resources/extensions/mcporter/index.ts +0 -525
- package/src/resources/extensions/gsd/auto-worktree-sync.ts +0 -199
- package/src/resources/extensions/gsd/tests/worktree-db-integration.test.ts +0 -205
- package/src/resources/extensions/gsd/tests/worktree-db.test.ts +0 -442
- package/src/resources/extensions/mcporter/index.ts +0 -525
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Worktree ↔ project root state synchronization for auto-mode.
|
|
3
|
-
*
|
|
4
|
-
* When auto-mode runs inside a worktree, dispatch-critical state files
|
|
5
|
-
* (.gsd/ metadata) diverge between the worktree (where work happens)
|
|
6
|
-
* and the project root (where startAutoMode reads initial state on restart).
|
|
7
|
-
* Without syncing, restarting auto-mode reads stale state from the project
|
|
8
|
-
* root and re-dispatches already-completed units.
|
|
9
|
-
*
|
|
10
|
-
* Also contains resource staleness detection and stale worktree escape.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import { existsSync, mkdirSync, readFileSync, cpSync, unlinkSync, readdirSync } from "node:fs";
|
|
14
|
-
import { loadJsonFileOrNull } from "./json-persistence.js";
|
|
15
|
-
import { join, sep as pathSep } from "node:path";
|
|
16
|
-
import { homedir } from "node:os";
|
|
17
|
-
import { safeCopy, safeCopyRecursive } from "./safe-fs.js";
|
|
18
|
-
import { atomicWriteSync } from "./atomic-write.js";
|
|
19
|
-
|
|
20
|
-
// ─── Project Root → Worktree Sync ─────────────────────────────────────────
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Sync milestone artifacts from project root INTO worktree before deriveState.
|
|
24
|
-
* Covers the case where the LLM wrote artifacts to the main repo filesystem
|
|
25
|
-
* (e.g. via absolute paths) but the worktree has stale data. Also deletes
|
|
26
|
-
* gsd.db in the worktree so it rebuilds from fresh disk state (#853).
|
|
27
|
-
* Non-fatal — sync failure should never block dispatch.
|
|
28
|
-
*/
|
|
29
|
-
export function syncProjectRootToWorktree(projectRoot: string, worktreePath: string, milestoneId: string | null): void {
|
|
30
|
-
if (!worktreePath || !projectRoot || worktreePath === projectRoot) return;
|
|
31
|
-
if (!milestoneId) return;
|
|
32
|
-
|
|
33
|
-
const prGsd = join(projectRoot, ".gsd");
|
|
34
|
-
const wtGsd = join(worktreePath, ".gsd");
|
|
35
|
-
|
|
36
|
-
// Copy milestone directory from project root to worktree if the project root
|
|
37
|
-
// has newer artifacts (e.g. slices that don't exist in the worktree yet)
|
|
38
|
-
safeCopyRecursive(join(prGsd, "milestones", milestoneId), join(wtGsd, "milestones", milestoneId))
|
|
39
|
-
|
|
40
|
-
// Copy living documents from project root to worktree so agents have the
|
|
41
|
-
// latest decisions, requirements, project state, and knowledge.
|
|
42
|
-
for (const doc of ["DECISIONS.md", "REQUIREMENTS.md", "PROJECT.md", "KNOWLEDGE.md"]) {
|
|
43
|
-
safeCopy(join(prGsd, doc), join(wtGsd, doc), { force: true });
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Delete worktree gsd.db so it rebuilds from the freshly synced files.
|
|
47
|
-
// Stale DB rows are the root cause of the infinite skip loop (#853).
|
|
48
|
-
try {
|
|
49
|
-
const wtDb = join(wtGsd, "gsd.db");
|
|
50
|
-
if (existsSync(wtDb)) {
|
|
51
|
-
unlinkSync(wtDb);
|
|
52
|
-
}
|
|
53
|
-
} catch { /* non-fatal */ }
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// ─── Worktree → Project Root Sync ─────────────────────────────────────────
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Sync dispatch-critical .gsd/ state files from worktree to project root.
|
|
60
|
-
* Only runs when inside an auto-worktree (worktreePath differs from projectRoot).
|
|
61
|
-
* Copies: STATE.md + active milestone directory (roadmap, slice plans, task summaries).
|
|
62
|
-
* Non-fatal — sync failure should never block dispatch.
|
|
63
|
-
*/
|
|
64
|
-
export function syncStateToProjectRoot(worktreePath: string, projectRoot: string, milestoneId: string | null): void {
|
|
65
|
-
if (!worktreePath || !projectRoot || worktreePath === projectRoot) return;
|
|
66
|
-
if (!milestoneId) return;
|
|
67
|
-
|
|
68
|
-
const wtGsd = join(worktreePath, ".gsd");
|
|
69
|
-
const prGsd = join(projectRoot, ".gsd");
|
|
70
|
-
|
|
71
|
-
// 1. STATE.md — the quick-glance status used by initial deriveState()
|
|
72
|
-
safeCopy(join(wtGsd, "STATE.md"), join(prGsd, "STATE.md"), { force: true })
|
|
73
|
-
|
|
74
|
-
// 2. Milestone directory — ROADMAP, slice PLANs, task summaries
|
|
75
|
-
// Copy the entire milestone .gsd subtree so deriveState reads current checkboxes
|
|
76
|
-
safeCopyRecursive(join(wtGsd, "milestones", milestoneId), join(prGsd, "milestones", milestoneId), { force: true })
|
|
77
|
-
|
|
78
|
-
// 3. Merge completed-units.json (set-union of both locations)
|
|
79
|
-
// Prevents already-completed units from being re-dispatched after crash/restart.
|
|
80
|
-
const srcKeysFile = join(wtGsd, "completed-units.json");
|
|
81
|
-
const dstKeysFile = join(prGsd, "completed-units.json");
|
|
82
|
-
if (existsSync(srcKeysFile)) {
|
|
83
|
-
try {
|
|
84
|
-
const srcKeys: string[] = JSON.parse(readFileSync(srcKeysFile, "utf8"));
|
|
85
|
-
let dstKeys: string[] = [];
|
|
86
|
-
if (existsSync(dstKeysFile)) {
|
|
87
|
-
try { dstKeys = JSON.parse(readFileSync(dstKeysFile, "utf8")); } catch { /* ignore corrupt dst */ }
|
|
88
|
-
}
|
|
89
|
-
const merged = [...new Set([...dstKeys, ...srcKeys])];
|
|
90
|
-
atomicWriteSync(dstKeysFile, JSON.stringify(merged, null, 2));
|
|
91
|
-
} catch { /* non-fatal */ }
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// 4. Runtime records — unit dispatch state used by selfHealRuntimeRecords().
|
|
95
|
-
// Without this, a crash during a unit leaves the runtime record only in the
|
|
96
|
-
// worktree. If the next session resolves basePath before worktree re-entry,
|
|
97
|
-
// selfHeal can't find or clear the stale record (#769).
|
|
98
|
-
safeCopyRecursive(join(wtGsd, "runtime", "units"), join(prGsd, "runtime", "units"), { force: true })
|
|
99
|
-
|
|
100
|
-
// 5. Living documents — decisions, requirements, project description, knowledge.
|
|
101
|
-
// Agents update these during slice execution. Without syncing, a new session
|
|
102
|
-
// reads stale copies from the project root, losing architectural decisions,
|
|
103
|
-
// requirement status updates, and accumulated knowledge (#1168).
|
|
104
|
-
for (const doc of ["DECISIONS.md", "REQUIREMENTS.md", "PROJECT.md", "KNOWLEDGE.md"]) {
|
|
105
|
-
safeCopy(join(wtGsd, doc), join(prGsd, doc), { force: true });
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// ─── Resource Staleness ───────────────────────────────────────────────────
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Read the resource version (semver) from the managed-resources manifest.
|
|
113
|
-
* Uses gsdVersion instead of syncedAt so that launching a second session
|
|
114
|
-
* doesn't falsely trigger staleness (#804).
|
|
115
|
-
*/
|
|
116
|
-
function isManifestWithVersion(data: unknown): data is { gsdVersion: string } {
|
|
117
|
-
return data !== null && typeof data === "object" && "gsdVersion" in data! && typeof (data as Record<string, unknown>).gsdVersion === "string";
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export function readResourceVersion(): string | null {
|
|
121
|
-
const agentDir = process.env.GSD_CODING_AGENT_DIR || join(homedir(), ".gsd", "agent");
|
|
122
|
-
const manifestPath = join(agentDir, "managed-resources.json");
|
|
123
|
-
const manifest = loadJsonFileOrNull(manifestPath, isManifestWithVersion);
|
|
124
|
-
return manifest?.gsdVersion ?? null;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Check if managed resources have been updated since session start.
|
|
129
|
-
* Returns a warning message if stale, null otherwise.
|
|
130
|
-
*/
|
|
131
|
-
export function checkResourcesStale(versionOnStart: string | null): string | null {
|
|
132
|
-
if (versionOnStart === null) return null;
|
|
133
|
-
const current = readResourceVersion();
|
|
134
|
-
if (current === null) return null;
|
|
135
|
-
if (current !== versionOnStart) {
|
|
136
|
-
return "GSD resources were updated since this session started. Restart gsd to load the new code.";
|
|
137
|
-
}
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// ─── Stale Worktree Escape ────────────────────────────────────────────────
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Detect and escape a stale worktree cwd (#608).
|
|
145
|
-
*
|
|
146
|
-
* After milestone completion + merge, the worktree directory is removed but
|
|
147
|
-
* the process cwd may still point inside `.gsd/worktrees/<MID>/`.
|
|
148
|
-
* When a new session starts, `process.cwd()` is passed as `base` to startAuto
|
|
149
|
-
* and all subsequent writes land in the wrong directory. This function detects
|
|
150
|
-
* that scenario and chdir back to the project root.
|
|
151
|
-
*
|
|
152
|
-
* Returns the corrected base path.
|
|
153
|
-
*/
|
|
154
|
-
export function escapeStaleWorktree(base: string): string {
|
|
155
|
-
const marker = `${pathSep}.gsd${pathSep}worktrees${pathSep}`;
|
|
156
|
-
const idx = base.indexOf(marker);
|
|
157
|
-
if (idx === -1) return base;
|
|
158
|
-
|
|
159
|
-
// base is inside .gsd/worktrees/<something> — extract the project root
|
|
160
|
-
const projectRoot = base.slice(0, idx);
|
|
161
|
-
try {
|
|
162
|
-
process.chdir(projectRoot);
|
|
163
|
-
} catch {
|
|
164
|
-
// If chdir fails, return the original — caller will handle errors downstream
|
|
165
|
-
return base;
|
|
166
|
-
}
|
|
167
|
-
return projectRoot;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Clean stale runtime unit files for completed milestones.
|
|
172
|
-
*
|
|
173
|
-
* After restart, stale runtime/units/*.json from prior milestones can
|
|
174
|
-
* cause deriveState to resume the wrong milestone (#887). Removes files
|
|
175
|
-
* for milestones that have a SUMMARY (fully complete).
|
|
176
|
-
*/
|
|
177
|
-
export function cleanStaleRuntimeUnits(
|
|
178
|
-
gsdRootPath: string,
|
|
179
|
-
hasMilestoneSummary: (mid: string) => boolean,
|
|
180
|
-
): number {
|
|
181
|
-
const runtimeUnitsDir = join(gsdRootPath, "runtime", "units");
|
|
182
|
-
if (!existsSync(runtimeUnitsDir)) return 0;
|
|
183
|
-
|
|
184
|
-
let cleaned = 0;
|
|
185
|
-
try {
|
|
186
|
-
for (const file of readdirSync(runtimeUnitsDir)) {
|
|
187
|
-
if (!file.endsWith(".json")) continue;
|
|
188
|
-
const midMatch = file.match(/(M\d+(?:-[a-z0-9]{6})?)/);
|
|
189
|
-
if (!midMatch) continue;
|
|
190
|
-
if (hasMilestoneSummary(midMatch[1])) {
|
|
191
|
-
try {
|
|
192
|
-
unlinkSync(join(runtimeUnitsDir, file));
|
|
193
|
-
cleaned++;
|
|
194
|
-
} catch { /* non-fatal */ }
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
} catch { /* non-fatal */ }
|
|
198
|
-
return cleaned;
|
|
199
|
-
}
|
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* worktree-db-integration.test.ts
|
|
3
|
-
*
|
|
4
|
-
* Integration tests for the worktree DB copy and reconcile hooks.
|
|
5
|
-
* Uses real temp git repos and real SQLite databases.
|
|
6
|
-
*
|
|
7
|
-
* Test cases:
|
|
8
|
-
* 1. Copy: createAutoWorktree seeds .gsd/gsd.db into the worktree when main has one
|
|
9
|
-
* 2. Copy-skip: createAutoWorktree silently skips when main has no gsd.db
|
|
10
|
-
* 3. Reconcile: reconcileWorktreeDb merges worktree rows into main DB
|
|
11
|
-
* 4. Reconcile-skip: reconcileWorktreeDb is non-fatal when both paths are nonexistent
|
|
12
|
-
* 5. Failure path: reconcileWorktreeDb emits to stderr on open failure (observable)
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
import { mkdtempSync, mkdirSync, writeFileSync, rmSync, existsSync, realpathSync } from "node:fs";
|
|
16
|
-
import { join } from "node:path";
|
|
17
|
-
import { tmpdir } from "node:os";
|
|
18
|
-
import { execSync } from "node:child_process";
|
|
19
|
-
|
|
20
|
-
import { createAutoWorktree } from "../auto-worktree.ts";
|
|
21
|
-
import { worktreePath } from "../worktree-manager.ts";
|
|
22
|
-
import {
|
|
23
|
-
copyWorktreeDb,
|
|
24
|
-
reconcileWorktreeDb,
|
|
25
|
-
openDatabase,
|
|
26
|
-
closeDatabase,
|
|
27
|
-
upsertDecision,
|
|
28
|
-
getActiveDecisions,
|
|
29
|
-
isDbAvailable,
|
|
30
|
-
} from "../gsd-db.ts";
|
|
31
|
-
|
|
32
|
-
import { createTestContext } from "./test-helpers.ts";
|
|
33
|
-
|
|
34
|
-
const { assertEq, assertTrue, report } = createTestContext();
|
|
35
|
-
|
|
36
|
-
function run(command: string, cwd: string): string {
|
|
37
|
-
return execSync(command, { cwd, stdio: ["ignore", "pipe", "pipe"], encoding: "utf-8" }).trim();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function createTempRepo(): string {
|
|
41
|
-
const dir = realpathSync(mkdtempSync(join(tmpdir(), "wt-db-int-test-")));
|
|
42
|
-
run("git init", dir);
|
|
43
|
-
run("git config user.email test@test.com", dir);
|
|
44
|
-
run("git config user.name Test", dir);
|
|
45
|
-
writeFileSync(join(dir, "README.md"), "# test\n");
|
|
46
|
-
run("git add .", dir);
|
|
47
|
-
run("git commit -m init", dir);
|
|
48
|
-
run("git branch -M main", dir);
|
|
49
|
-
return dir;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async function main(): Promise<void> {
|
|
53
|
-
const savedCwd = process.cwd();
|
|
54
|
-
const tempDirs: string[] = [];
|
|
55
|
-
|
|
56
|
-
function makeTempDir(): string {
|
|
57
|
-
const dir = realpathSync(mkdtempSync(join(tmpdir(), "wt-db-int-")));
|
|
58
|
-
tempDirs.push(dir);
|
|
59
|
-
return dir;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
try {
|
|
63
|
-
|
|
64
|
-
// ─── Test 1: copy on worktree creation ───────────────────────────
|
|
65
|
-
console.log("\n=== Test 1: copy on worktree creation ===");
|
|
66
|
-
{
|
|
67
|
-
const tempDir = createTempRepo();
|
|
68
|
-
tempDirs.push(tempDir);
|
|
69
|
-
|
|
70
|
-
// Seed a gsd.db in the main repo
|
|
71
|
-
const gsdDir = join(tempDir, ".gsd");
|
|
72
|
-
mkdirSync(gsdDir, { recursive: true });
|
|
73
|
-
const mainDbPath = join(gsdDir, "gsd.db");
|
|
74
|
-
openDatabase(mainDbPath);
|
|
75
|
-
closeDatabase();
|
|
76
|
-
|
|
77
|
-
// Commit so createAutoWorktree can copy planning artifacts
|
|
78
|
-
run("git add .", tempDir);
|
|
79
|
-
run('git commit -m "add gsd dir"', tempDir);
|
|
80
|
-
|
|
81
|
-
// createAutoWorktree should copy the DB into the worktree
|
|
82
|
-
const wtPath = createAutoWorktree(tempDir, "M004");
|
|
83
|
-
|
|
84
|
-
const worktreeDbPath = join(worktreePath(tempDir, "M004"), ".gsd", "gsd.db");
|
|
85
|
-
assertTrue(
|
|
86
|
-
existsSync(worktreeDbPath),
|
|
87
|
-
"gsd.db exists in worktree .gsd after createAutoWorktree",
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
// Restore cwd for next test
|
|
91
|
-
process.chdir(savedCwd);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// ─── Test 2: copy skip when no source DB ─────────────────────────
|
|
95
|
-
console.log("\n=== Test 2: copy skip when no source DB ===");
|
|
96
|
-
{
|
|
97
|
-
const tempDir = createTempRepo();
|
|
98
|
-
tempDirs.push(tempDir);
|
|
99
|
-
|
|
100
|
-
// No gsd.db — just a bare repo
|
|
101
|
-
let threw = false;
|
|
102
|
-
let wtPath: string | null = null;
|
|
103
|
-
try {
|
|
104
|
-
wtPath = createAutoWorktree(tempDir, "M004");
|
|
105
|
-
} catch (err) {
|
|
106
|
-
threw = true;
|
|
107
|
-
console.error(" Unexpected throw:", err);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
assertTrue(!threw, "createAutoWorktree does not throw when no source DB");
|
|
111
|
-
|
|
112
|
-
const worktreeDbPath = join(worktreePath(tempDir, "M004"), ".gsd", "gsd.db");
|
|
113
|
-
assertTrue(
|
|
114
|
-
!existsSync(worktreeDbPath),
|
|
115
|
-
"gsd.db is absent in worktree when source had none",
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
process.chdir(savedCwd);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// ─── Test 3: reconcile inserts worktree rows into main ───────────
|
|
122
|
-
console.log("\n=== Test 3: reconcile merges worktree rows into main ===");
|
|
123
|
-
{
|
|
124
|
-
const mainDbPath = join(makeTempDir(), "main.db");
|
|
125
|
-
const worktreeDbPath = join(makeTempDir(), "wt.db");
|
|
126
|
-
|
|
127
|
-
// Seed main DB (empty schema)
|
|
128
|
-
openDatabase(mainDbPath);
|
|
129
|
-
closeDatabase();
|
|
130
|
-
|
|
131
|
-
// Seed worktree DB with one decision
|
|
132
|
-
openDatabase(worktreeDbPath);
|
|
133
|
-
upsertDecision({
|
|
134
|
-
id: "D-WT-001",
|
|
135
|
-
when_context: "integration test",
|
|
136
|
-
scope: "test",
|
|
137
|
-
decision: "use reconcile",
|
|
138
|
-
choice: "reconcile on merge",
|
|
139
|
-
rationale: "test coverage",
|
|
140
|
-
revisable: "no",
|
|
141
|
-
superseded_by: null,
|
|
142
|
-
});
|
|
143
|
-
closeDatabase();
|
|
144
|
-
|
|
145
|
-
// Reconcile worktree → main
|
|
146
|
-
const result = reconcileWorktreeDb(mainDbPath, worktreeDbPath);
|
|
147
|
-
assertTrue(result.decisions >= 1, "reconcile reports at least 1 decision merged");
|
|
148
|
-
|
|
149
|
-
// Open main DB and verify the row is present
|
|
150
|
-
openDatabase(mainDbPath);
|
|
151
|
-
const decisions = getActiveDecisions();
|
|
152
|
-
closeDatabase();
|
|
153
|
-
|
|
154
|
-
const found = decisions.some((d) => d.id === "D-WT-001");
|
|
155
|
-
assertTrue(found, "worktree decision D-WT-001 present in main DB after reconcile");
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// ─── Test 4: reconcile non-fatal when both paths nonexistent ─────
|
|
159
|
-
console.log("\n=== Test 4: reconcile non-fatal on nonexistent paths ===");
|
|
160
|
-
{
|
|
161
|
-
let threw = false;
|
|
162
|
-
try {
|
|
163
|
-
reconcileWorktreeDb("/nonexistent/path/gsd.db", "/also/nonexistent/gsd.db");
|
|
164
|
-
} catch {
|
|
165
|
-
threw = true;
|
|
166
|
-
}
|
|
167
|
-
assertTrue(!threw, "reconcileWorktreeDb does not throw when worktree DB is absent");
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// ─── Test 5: failure path observable via stderr (diagnostic) ─────
|
|
171
|
-
// reconcileWorktreeDb emits to stderr on reconciliation failures.
|
|
172
|
-
// We can't easily intercept stderr in this test harness, but we verify
|
|
173
|
-
// that the function returns the zero-result shape (not undefined/throws)
|
|
174
|
-
// when the worktree DB is missing — confirming the failure path is non-fatal
|
|
175
|
-
// and returns a structured result.
|
|
176
|
-
console.log("\n=== Test 5: reconcile returns zero-shape when worktree DB absent ===");
|
|
177
|
-
{
|
|
178
|
-
const mainDbPath = join(makeTempDir(), "main2.db");
|
|
179
|
-
openDatabase(mainDbPath);
|
|
180
|
-
closeDatabase();
|
|
181
|
-
|
|
182
|
-
const result = reconcileWorktreeDb(mainDbPath, "/definitely/does/not/exist.db");
|
|
183
|
-
assertEq(result.decisions, 0, "decisions is 0 when worktree DB absent");
|
|
184
|
-
assertEq(result.requirements, 0, "requirements is 0 when worktree DB absent");
|
|
185
|
-
assertEq(result.artifacts, 0, "artifacts is 0 when worktree DB absent");
|
|
186
|
-
assertEq(result.conflicts.length, 0, "conflicts is empty when worktree DB absent");
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
} finally {
|
|
190
|
-
// Always restore cwd
|
|
191
|
-
process.chdir(savedCwd);
|
|
192
|
-
// Ensure DB is closed
|
|
193
|
-
if (isDbAvailable()) closeDatabase();
|
|
194
|
-
// Remove all temp dirs
|
|
195
|
-
for (const dir of tempDirs) {
|
|
196
|
-
if (existsSync(dir)) {
|
|
197
|
-
rmSync(dir, { recursive: true, force: true });
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
report();
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
main();
|