gsd-pi 2.80.0-dev.96f4d89d5 → 2.80.0-dev.b2a374d5b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/resources/.managed-resources-content-hash +1 -1
- package/dist/resources/GSD-WORKFLOW.md +2 -2
- package/dist/resources/extensions/gsd/auto/loop.js +32 -1
- package/dist/resources/extensions/gsd/auto/phases.js +37 -30
- package/dist/resources/extensions/gsd/auto-dispatch.js +10 -0
- package/dist/resources/extensions/gsd/auto-post-unit.js +10 -10
- package/dist/resources/extensions/gsd/auto-prompts.js +111 -1
- package/dist/resources/extensions/gsd/auto-recovery.js +154 -8
- package/dist/resources/extensions/gsd/auto-start.js +2 -3
- package/dist/resources/extensions/gsd/auto.js +16 -3
- package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +32 -1
- package/dist/resources/extensions/gsd/bootstrap/write-gate.js +129 -1
- package/dist/resources/extensions/gsd/clean-root-preflight.js +42 -4
- package/dist/resources/extensions/gsd/commands/dispatcher.js +5 -0
- package/dist/resources/extensions/gsd/commands-extract-learnings.js +17 -12
- package/dist/resources/extensions/gsd/crash-recovery.js +56 -10
- package/dist/resources/extensions/gsd/db-base-schema.js +14 -0
- package/dist/resources/extensions/gsd/db-migration-steps.js +16 -0
- package/dist/resources/extensions/gsd/detection.js +106 -0
- package/dist/resources/extensions/gsd/gsd-db.js +102 -2
- package/dist/resources/extensions/gsd/guided-flow.js +63 -12
- package/dist/resources/extensions/gsd/migrate/command.js +40 -1
- package/dist/resources/extensions/gsd/migration-auto-check.js +87 -0
- package/dist/resources/extensions/gsd/planning-path-scope.js +26 -0
- package/dist/resources/extensions/gsd/prompts/complete-milestone.md +7 -8
- package/dist/resources/extensions/gsd/prompts/parallel-research-slices.md +1 -1
- package/dist/resources/extensions/gsd/prompts/plan-milestone.md +3 -1
- package/dist/resources/extensions/gsd/prompts/plan-slice.md +1 -1
- package/dist/resources/extensions/gsd/prompts/quick-task.md +1 -5
- package/dist/resources/extensions/gsd/prompts/validate-milestone.md +2 -2
- package/dist/resources/extensions/gsd/quick.js +34 -2
- package/dist/resources/extensions/gsd/safety/evidence-collector.js +10 -2
- package/dist/resources/extensions/gsd/tools/plan-slice.js +9 -0
- package/dist/resources/extensions/gsd/tools/plan-task.js +9 -0
- package/dist/resources/extensions/gsd/unit-runtime.js +11 -0
- package/dist/resources/extensions/gsd/worktree-manager.js +16 -14
- 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 +13 -13
- 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 +13 -13
- 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/package.json +4 -2
- package/packages/pi-coding-agent/dist/core/agent-session.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/agent-session.js +3 -0
- package/packages/pi-coding-agent/dist/core/agent-session.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/chat-controller-ordering.test.js +76 -0
- package/packages/pi-coding-agent/dist/core/chat-controller-ordering.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/compaction/compaction.d.ts +11 -0
- package/packages/pi-coding-agent/dist/core/compaction/compaction.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/compaction/compaction.js +9 -0
- package/packages/pi-coding-agent/dist/core/compaction/compaction.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/compaction-threshold.test.d.ts +2 -0
- package/packages/pi-coding-agent/dist/core/compaction-threshold.test.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/core/compaction-threshold.test.js +103 -0
- package/packages/pi-coding-agent/dist/core/compaction-threshold.test.js.map +1 -0
- package/packages/pi-coding-agent/dist/core/db-snapshot.d.ts +15 -0
- package/packages/pi-coding-agent/dist/core/db-snapshot.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/core/db-snapshot.js +66 -0
- package/packages/pi-coding-agent/dist/core/db-snapshot.js.map +1 -0
- package/packages/pi-coding-agent/dist/core/db-snapshot.test.d.ts +2 -0
- package/packages/pi-coding-agent/dist/core/db-snapshot.test.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/core/db-snapshot.test.js +24 -0
- package/packages/pi-coding-agent/dist/core/db-snapshot.test.js.map +1 -0
- package/packages/pi-coding-agent/dist/core/extensions/runner.d.ts +3 -0
- package/packages/pi-coding-agent/dist/core/extensions/runner.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/runner.js +17 -1
- package/packages/pi-coding-agent/dist/core/extensions/runner.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/runner.test.js +99 -0
- package/packages/pi-coding-agent/dist/core/extensions/runner.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/types.d.ts +7 -0
- package/packages/pi-coding-agent/dist/core/extensions/types.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/types.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/settings-manager.d.ts +20 -0
- package/packages/pi-coding-agent/dist/core/settings-manager.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/settings-manager.js +25 -0
- package/packages/pi-coding-agent/dist/core/settings-manager.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/chat-frame-compaction-tone.test.js +6 -4
- package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/chat-frame-compaction-tone.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/tool-execution.test.js +50 -19
- package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/tool-execution.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/adaptive-layout.js +2 -2
- package/packages/pi-coding-agent/dist/modes/interactive/components/adaptive-layout.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/chat-frame.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/chat-frame.js +2 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/chat-frame.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-card-cleanup-and-success-runtime.test.js +7 -6
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-card-cleanup-and-success-runtime.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.d.ts +13 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js +77 -13
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.js +68 -2
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.test.js +53 -0
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js +3 -0
- package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/theme/themes.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/theme/themes.js +36 -27
- package/packages/pi-coding-agent/dist/modes/interactive/theme/themes.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/tui-mode.test.js +21 -0
- package/packages/pi-coding-agent/dist/modes/interactive/tui-mode.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/resources/extensions/memory/storage-safety-guard.test.d.ts +2 -0
- package/packages/pi-coding-agent/dist/resources/extensions/memory/storage-safety-guard.test.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/resources/extensions/memory/storage-safety-guard.test.js +10 -0
- package/packages/pi-coding-agent/dist/resources/extensions/memory/storage-safety-guard.test.js.map +1 -0
- package/packages/pi-coding-agent/dist/resources/extensions/memory/storage.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/resources/extensions/memory/storage.js +3 -2
- package/packages/pi-coding-agent/dist/resources/extensions/memory/storage.js.map +1 -1
- package/packages/pi-coding-agent/src/core/agent-session.ts +3 -0
- package/packages/pi-coding-agent/src/core/chat-controller-ordering.test.ts +89 -0
- package/packages/pi-coding-agent/src/core/compaction/compaction.ts +18 -0
- package/packages/pi-coding-agent/src/core/compaction-threshold.test.ts +121 -0
- package/packages/pi-coding-agent/src/core/db-snapshot.test.ts +32 -0
- package/packages/pi-coding-agent/src/core/db-snapshot.ts +66 -0
- package/packages/pi-coding-agent/src/core/extensions/runner.test.ts +110 -0
- package/packages/pi-coding-agent/src/core/extensions/runner.ts +19 -1
- package/packages/pi-coding-agent/src/core/extensions/types.ts +7 -0
- package/packages/pi-coding-agent/src/core/settings-manager.ts +39 -1
- package/packages/pi-coding-agent/src/modes/interactive/components/__tests__/chat-frame-compaction-tone.test.ts +7 -5
- package/packages/pi-coding-agent/src/modes/interactive/components/__tests__/tool-execution.test.ts +68 -19
- package/packages/pi-coding-agent/src/modes/interactive/components/adaptive-layout.ts +2 -2
- package/packages/pi-coding-agent/src/modes/interactive/components/assistant-message.ts +1 -0
- package/packages/pi-coding-agent/src/modes/interactive/components/chat-frame.ts +2 -1
- package/packages/pi-coding-agent/src/modes/interactive/components/tool-card-cleanup-and-success-runtime.test.ts +10 -9
- package/packages/pi-coding-agent/src/modes/interactive/components/tool-execution.ts +88 -13
- package/packages/pi-coding-agent/src/modes/interactive/controllers/chat-controller.test.ts +56 -0
- package/packages/pi-coding-agent/src/modes/interactive/controllers/chat-controller.ts +91 -3
- package/packages/pi-coding-agent/src/modes/interactive/interactive-mode.ts +3 -0
- package/packages/pi-coding-agent/src/modes/interactive/theme/themes.ts +36 -27
- package/packages/pi-coding-agent/src/modes/interactive/tui-mode.test.ts +25 -0
- package/packages/pi-coding-agent/src/resources/extensions/memory/storage-safety-guard.test.ts +14 -0
- package/packages/pi-coding-agent/src/resources/extensions/memory/storage.ts +3 -2
- package/packages/pi-coding-agent/tsconfig.tsbuildinfo +1 -1
- package/packages/pi-tui/dist/tui.d.ts.map +1 -1
- package/packages/pi-tui/dist/tui.js +17 -7
- package/packages/pi-tui/dist/tui.js.map +1 -1
- package/packages/pi-tui/src/tui.ts +19 -7
- package/packages/pi-tui/tsconfig.tsbuildinfo +1 -1
- package/pkg/dist/modes/interactive/theme/themes.d.ts.map +1 -1
- package/pkg/dist/modes/interactive/theme/themes.js +36 -27
- package/pkg/dist/modes/interactive/theme/themes.js.map +1 -1
- package/src/resources/GSD-WORKFLOW.md +2 -2
- package/src/resources/extensions/gsd/auto/loop-deps.ts +1 -0
- package/src/resources/extensions/gsd/auto/loop.ts +50 -8
- package/src/resources/extensions/gsd/auto/phases.ts +42 -28
- package/src/resources/extensions/gsd/auto-dispatch.ts +17 -0
- package/src/resources/extensions/gsd/auto-post-unit.ts +10 -10
- package/src/resources/extensions/gsd/auto-prompts.ts +116 -1
- package/src/resources/extensions/gsd/auto-recovery.ts +153 -7
- package/src/resources/extensions/gsd/auto-start.ts +7 -6
- package/src/resources/extensions/gsd/auto.ts +23 -3
- package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +39 -1
- package/src/resources/extensions/gsd/bootstrap/write-gate.ts +135 -1
- package/src/resources/extensions/gsd/clean-root-preflight.ts +41 -3
- package/src/resources/extensions/gsd/commands/dispatcher.ts +6 -0
- package/src/resources/extensions/gsd/commands-extract-learnings.ts +17 -12
- package/src/resources/extensions/gsd/crash-recovery.ts +67 -10
- package/src/resources/extensions/gsd/db-base-schema.ts +15 -0
- package/src/resources/extensions/gsd/db-migration-steps.ts +17 -0
- package/src/resources/extensions/gsd/detection.ts +128 -0
- package/src/resources/extensions/gsd/gsd-db.ts +119 -1
- package/src/resources/extensions/gsd/guided-flow.ts +66 -12
- package/src/resources/extensions/gsd/migrate/command.ts +47 -1
- package/src/resources/extensions/gsd/migration-auto-check.ts +129 -0
- package/src/resources/extensions/gsd/planning-path-scope.ts +35 -0
- package/src/resources/extensions/gsd/prompts/complete-milestone.md +7 -8
- package/src/resources/extensions/gsd/prompts/parallel-research-slices.md +1 -1
- package/src/resources/extensions/gsd/prompts/plan-milestone.md +3 -1
- package/src/resources/extensions/gsd/prompts/plan-slice.md +1 -1
- package/src/resources/extensions/gsd/prompts/quick-task.md +1 -5
- package/src/resources/extensions/gsd/prompts/validate-milestone.md +2 -2
- package/src/resources/extensions/gsd/quick.ts +37 -2
- package/src/resources/extensions/gsd/safety/evidence-collector.ts +11 -2
- package/src/resources/extensions/gsd/tests/auto-loop.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/auto-recovery.test.ts +170 -1
- package/src/resources/extensions/gsd/tests/clean-root-preflight.test.ts +88 -2
- package/src/resources/extensions/gsd/tests/commands-extract-learnings.test.ts +9 -0
- package/src/resources/extensions/gsd/tests/crash-handler-secondary.test.ts +55 -0
- package/src/resources/extensions/gsd/tests/crash-recovery-via-db.test.ts +22 -0
- package/src/resources/extensions/gsd/tests/db-schema-metadata.test.ts +2 -2
- package/src/resources/extensions/gsd/tests/detection.test.ts +140 -0
- package/src/resources/extensions/gsd/tests/gsd-db.test.ts +44 -0
- package/src/resources/extensions/gsd/tests/has-pending-deep-stage.test.ts +33 -1
- package/src/resources/extensions/gsd/tests/migrate-writer-integration.test.ts +48 -0
- package/src/resources/extensions/gsd/tests/migration-auto-check.test.ts +127 -0
- package/src/resources/extensions/gsd/tests/plan-slice.test.ts +50 -0
- package/src/resources/extensions/gsd/tests/plan-task.test.ts +21 -0
- package/src/resources/extensions/gsd/tests/prompt-path-audit.test.ts +40 -0
- package/src/resources/extensions/gsd/tests/quick-external-gsd.test.ts +40 -0
- package/src/resources/extensions/gsd/tests/right-sized-workflow-prompts.test.ts +192 -0
- package/src/resources/extensions/gsd/tests/safety-harness-false-positives.test.ts +29 -0
- package/src/resources/extensions/gsd/tests/smart-entry-complete.test.ts +38 -0
- package/src/resources/extensions/gsd/tests/start-auto-detached.test.ts +63 -2
- package/src/resources/extensions/gsd/tests/status-db-open.test.ts +9 -0
- package/src/resources/extensions/gsd/tests/unit-runtime.test.ts +7 -0
- package/src/resources/extensions/gsd/tests/uok-plan-v2-wiring.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/worktree-health-dispatch.test.ts +37 -6
- package/src/resources/extensions/gsd/tests/worktree-manager.test.ts +7 -0
- package/src/resources/extensions/gsd/tests/worktree-nested-git-safety.test.ts +9 -2
- package/src/resources/extensions/gsd/tests/worktree-write-gate.test.ts +179 -0
- package/src/resources/extensions/gsd/tools/plan-slice.ts +13 -0
- package/src/resources/extensions/gsd/tools/plan-task.ts +10 -0
- package/src/resources/extensions/gsd/unit-runtime.ts +14 -0
- package/src/resources/extensions/gsd/worktree-manager.ts +15 -4
- /package/dist/web/standalone/.next/static/{y7d--cnc6Cibuva-Lzzw_ → FU0iL9dhdc2IBzEYBDOlY}/_buildManifest.js +0 -0
- /package/dist/web/standalone/.next/static/{y7d--cnc6Cibuva-Lzzw_ → FU0iL9dhdc2IBzEYBDOlY}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
// GSD-2 worktree-isolation write gate (#5199).
|
|
2
|
+
//
|
|
3
|
+
// Regression coverage for shouldBlockWorktreeWrite — the helper that prevents
|
|
4
|
+
// the LLM from authoring code at the project root when `git.isolation: worktree`
|
|
5
|
+
// is configured but auto-mode (and its post-unit commit pipeline) hasn't run.
|
|
6
|
+
// Without this gate, writes silently orphan outside git history.
|
|
7
|
+
//
|
|
8
|
+
// Test setup creates a fresh temp project for each isolation case, writes a
|
|
9
|
+
// `.gsd/PREFERENCES.md` with `isolation: "worktree"`, and exercises the helper
|
|
10
|
+
// against the 9 scenarios listed in the issue. No source-grep tests — every
|
|
11
|
+
// assertion exercises the real predicate.
|
|
12
|
+
|
|
13
|
+
import { test, describe, beforeEach, afterEach } from "node:test";
|
|
14
|
+
import assert from "node:assert/strict";
|
|
15
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
16
|
+
import { tmpdir } from "node:os";
|
|
17
|
+
import { join } from "node:path";
|
|
18
|
+
|
|
19
|
+
import { shouldBlockWorktreeWrite } from "../bootstrap/write-gate.js";
|
|
20
|
+
import { invalidateAllCaches } from "../cache.js";
|
|
21
|
+
|
|
22
|
+
function makeProject(isolation: "none" | "worktree" | "branch" | null): string {
|
|
23
|
+
const root = mkdtempSync(join(tmpdir(), "wt-write-gate-"));
|
|
24
|
+
if (isolation !== null) {
|
|
25
|
+
mkdirSync(join(root, ".gsd"), { recursive: true });
|
|
26
|
+
writeFileSync(
|
|
27
|
+
join(root, ".gsd", "PREFERENCES.md"),
|
|
28
|
+
`---\ngit:\n isolation: "${isolation}"\n---\n`,
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
invalidateAllCaches();
|
|
32
|
+
return root;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const PLANNING_WRITE_TOOLS = ["write", "edit", "multi_edit", "notebook_edit"];
|
|
36
|
+
|
|
37
|
+
describe("shouldBlockWorktreeWrite (#5199)", () => {
|
|
38
|
+
let projectRoot: string;
|
|
39
|
+
let prevDisableEnv: string | undefined;
|
|
40
|
+
|
|
41
|
+
beforeEach(() => {
|
|
42
|
+
prevDisableEnv = process.env.GSD_DISABLE_WORKTREE_WRITE_GUARD;
|
|
43
|
+
delete process.env.GSD_DISABLE_WORKTREE_WRITE_GUARD;
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
afterEach(() => {
|
|
47
|
+
if (projectRoot) {
|
|
48
|
+
try { rmSync(projectRoot, { recursive: true, force: true }); } catch { /* best-effort */ }
|
|
49
|
+
}
|
|
50
|
+
if (prevDisableEnv === undefined) {
|
|
51
|
+
delete process.env.GSD_DISABLE_WORKTREE_WRITE_GUARD;
|
|
52
|
+
} else {
|
|
53
|
+
process.env.GSD_DISABLE_WORKTREE_WRITE_GUARD = prevDisableEnv;
|
|
54
|
+
}
|
|
55
|
+
invalidateAllCaches();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test("Case 1: every PLANNING_WRITE_TOOLS variant writing to <root>/app.js is blocked", () => {
|
|
59
|
+
projectRoot = makeProject("worktree");
|
|
60
|
+
for (const tool of PLANNING_WRITE_TOOLS) {
|
|
61
|
+
const result = shouldBlockWorktreeWrite(
|
|
62
|
+
tool,
|
|
63
|
+
join(projectRoot, "app.js"),
|
|
64
|
+
projectRoot,
|
|
65
|
+
/* isAutoLive */ false,
|
|
66
|
+
/* unitType */ null,
|
|
67
|
+
);
|
|
68
|
+
assert.equal(result.block, true, `tool ${tool} should be blocked`);
|
|
69
|
+
assert.match(result.reason ?? "", /HARD BLOCK/);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test("Case 2: write to <root>/.gsd/PROJECT.md is allowed", () => {
|
|
74
|
+
projectRoot = makeProject("worktree");
|
|
75
|
+
const result = shouldBlockWorktreeWrite(
|
|
76
|
+
"write",
|
|
77
|
+
join(projectRoot, ".gsd", "PROJECT.md"),
|
|
78
|
+
projectRoot,
|
|
79
|
+
false,
|
|
80
|
+
null,
|
|
81
|
+
);
|
|
82
|
+
assert.equal(result.block, false);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test("Case 3: write inside <root>/.gsd/worktrees/M001/ is allowed", () => {
|
|
86
|
+
projectRoot = makeProject("worktree");
|
|
87
|
+
const target = join(projectRoot, ".gsd", "worktrees", "M001", "src", "app.js");
|
|
88
|
+
const result = shouldBlockWorktreeWrite("edit", target, projectRoot, false, null);
|
|
89
|
+
assert.equal(result.block, false);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test("Case 4: write to <root>/.gsd/worktrees-extra/M001/app.js (prefix trick) is blocked", () => {
|
|
93
|
+
projectRoot = makeProject("worktree");
|
|
94
|
+
const target = join(projectRoot, ".gsd", "worktrees-extra", "M001", "app.js");
|
|
95
|
+
const result = shouldBlockWorktreeWrite("write", target, projectRoot, false, null);
|
|
96
|
+
assert.equal(result.block, true);
|
|
97
|
+
assert.match(result.reason ?? "", /HARD BLOCK/);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("Case 5: isolation=none → allow", () => {
|
|
101
|
+
projectRoot = makeProject("none");
|
|
102
|
+
const result = shouldBlockWorktreeWrite(
|
|
103
|
+
"write",
|
|
104
|
+
join(projectRoot, "app.js"),
|
|
105
|
+
projectRoot,
|
|
106
|
+
false,
|
|
107
|
+
null,
|
|
108
|
+
);
|
|
109
|
+
assert.equal(result.block, false);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("Case 6: isolation=worktree, auto active, effectiveBasePath inside worktree → allow", () => {
|
|
113
|
+
projectRoot = makeProject("worktree");
|
|
114
|
+
const inside = join(projectRoot, ".gsd", "worktrees", "M001");
|
|
115
|
+
mkdirSync(inside, { recursive: true });
|
|
116
|
+
const result = shouldBlockWorktreeWrite(
|
|
117
|
+
"write",
|
|
118
|
+
join(inside, "src", "app.js"),
|
|
119
|
+
inside,
|
|
120
|
+
/* isAutoLive */ true,
|
|
121
|
+
null,
|
|
122
|
+
);
|
|
123
|
+
assert.equal(result.block, false);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test("Case 7: isolation=worktree, auto active, effectiveBasePath is project root (cwd never flipped) → block", () => {
|
|
127
|
+
projectRoot = makeProject("worktree");
|
|
128
|
+
const result = shouldBlockWorktreeWrite(
|
|
129
|
+
"write",
|
|
130
|
+
join(projectRoot, "app.js"),
|
|
131
|
+
projectRoot,
|
|
132
|
+
/* isAutoLive */ true,
|
|
133
|
+
null,
|
|
134
|
+
);
|
|
135
|
+
assert.equal(result.block, true);
|
|
136
|
+
assert.match(result.reason ?? "", /HARD BLOCK/);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test("Case 8: bootstrap unit type active → allow", () => {
|
|
140
|
+
projectRoot = makeProject("worktree");
|
|
141
|
+
for (const unitType of ["discuss-milestone", "plan-milestone", "init"]) {
|
|
142
|
+
const result = shouldBlockWorktreeWrite(
|
|
143
|
+
"write",
|
|
144
|
+
join(projectRoot, "app.js"),
|
|
145
|
+
projectRoot,
|
|
146
|
+
false,
|
|
147
|
+
unitType,
|
|
148
|
+
);
|
|
149
|
+
assert.equal(result.block, false, `unit ${unitType} should bypass the guard`);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test("Case 9: GSD_DISABLE_WORKTREE_WRITE_GUARD=1 → allow", () => {
|
|
154
|
+
projectRoot = makeProject("worktree");
|
|
155
|
+
process.env.GSD_DISABLE_WORKTREE_WRITE_GUARD = "1";
|
|
156
|
+
const result = shouldBlockWorktreeWrite(
|
|
157
|
+
"write",
|
|
158
|
+
join(projectRoot, "app.js"),
|
|
159
|
+
projectRoot,
|
|
160
|
+
false,
|
|
161
|
+
null,
|
|
162
|
+
);
|
|
163
|
+
assert.equal(result.block, false);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test("non-planning tools (read/grep/bash) pass through unconditionally", () => {
|
|
167
|
+
projectRoot = makeProject("worktree");
|
|
168
|
+
for (const tool of ["read", "grep", "bash", "ls"]) {
|
|
169
|
+
const result = shouldBlockWorktreeWrite(
|
|
170
|
+
tool,
|
|
171
|
+
join(projectRoot, "app.js"),
|
|
172
|
+
projectRoot,
|
|
173
|
+
false,
|
|
174
|
+
null,
|
|
175
|
+
);
|
|
176
|
+
assert.equal(result.block, false, `tool ${tool} must not be gated`);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
});
|
|
@@ -18,6 +18,7 @@ import { renderAllProjections } from "../workflow-projections.js";
|
|
|
18
18
|
import { writeManifest } from "../workflow-manifest.js";
|
|
19
19
|
import { appendEvent } from "../workflow-events.js";
|
|
20
20
|
import { logWarning } from "../workflow-logger.js";
|
|
21
|
+
import { validatePlanningPathScope } from "../planning-path-scope.js";
|
|
21
22
|
|
|
22
23
|
export interface PlanSliceTaskInput {
|
|
23
24
|
taskId: string;
|
|
@@ -141,6 +142,18 @@ export async function handlePlanSlice(
|
|
|
141
142
|
return { error: `validation failed: ${(err as Error).message}` };
|
|
142
143
|
}
|
|
143
144
|
|
|
145
|
+
const pathScopeError = validatePlanningPathScope(
|
|
146
|
+
basePath,
|
|
147
|
+
params.tasks.flatMap((task, index) => [
|
|
148
|
+
{ field: `tasks[${index}].files`, values: task.files },
|
|
149
|
+
{ field: `tasks[${index}].inputs`, values: task.inputs },
|
|
150
|
+
{ field: `tasks[${index}].expectedOutput`, values: task.expectedOutput },
|
|
151
|
+
]),
|
|
152
|
+
);
|
|
153
|
+
if (pathScopeError) {
|
|
154
|
+
return { error: `validation failed: ${pathScopeError}` };
|
|
155
|
+
}
|
|
156
|
+
|
|
144
157
|
// ── Guards + DB writes inside a single transaction (prevents TOCTOU) ───
|
|
145
158
|
// Guards must be inside the transaction so the state they check cannot
|
|
146
159
|
// change between the read and the write (#2723).
|
|
@@ -8,6 +8,7 @@ import { renderAllProjections } from "../workflow-projections.js";
|
|
|
8
8
|
import { writeManifest } from "../workflow-manifest.js";
|
|
9
9
|
import { appendEvent } from "../workflow-events.js";
|
|
10
10
|
import { logWarning } from "../workflow-logger.js";
|
|
11
|
+
import { validatePlanningPathScope } from "../planning-path-scope.js";
|
|
11
12
|
|
|
12
13
|
export interface PlanTaskParams {
|
|
13
14
|
milestoneId: string;
|
|
@@ -66,6 +67,15 @@ export async function handlePlanTask(
|
|
|
66
67
|
return { error: `validation failed: ${(err as Error).message}` };
|
|
67
68
|
}
|
|
68
69
|
|
|
70
|
+
const pathScopeError = validatePlanningPathScope(basePath, [
|
|
71
|
+
{ field: "files", values: params.files },
|
|
72
|
+
{ field: "inputs", values: params.inputs },
|
|
73
|
+
{ field: "expectedOutput", values: params.expectedOutput },
|
|
74
|
+
]);
|
|
75
|
+
if (pathScopeError) {
|
|
76
|
+
return { error: `validation failed: ${pathScopeError}` };
|
|
77
|
+
}
|
|
78
|
+
|
|
69
79
|
// ── Guards + DB writes inside a single transaction (prevents TOCTOU) ───
|
|
70
80
|
// Guards must be inside the transaction so the state they check cannot
|
|
71
81
|
// change between the read and the write (#2723).
|
|
@@ -67,11 +67,25 @@ export type UnitRuntimePhase =
|
|
|
67
67
|
| "wrapup-warning-sent"
|
|
68
68
|
| "timeout"
|
|
69
69
|
| "finalize-timeout"
|
|
70
|
+
| "crashed"
|
|
70
71
|
| "recovered"
|
|
71
72
|
| "finalized"
|
|
72
73
|
| "paused"
|
|
73
74
|
| "skipped";
|
|
74
75
|
|
|
76
|
+
export const IN_FLIGHT_RUNTIME_PHASES: ReadonlySet<UnitRuntimePhase> = new Set([
|
|
77
|
+
"dispatched",
|
|
78
|
+
"wrapup-warning-sent",
|
|
79
|
+
"timeout",
|
|
80
|
+
"finalize-timeout",
|
|
81
|
+
"crashed",
|
|
82
|
+
"paused",
|
|
83
|
+
]);
|
|
84
|
+
|
|
85
|
+
export function isInFlightRuntimePhase(phase: UnitRuntimePhase): boolean {
|
|
86
|
+
return IN_FLIGHT_RUNTIME_PHASES.has(phase);
|
|
87
|
+
}
|
|
88
|
+
|
|
75
89
|
export interface ExecuteTaskRecoveryStatus {
|
|
76
90
|
planPath: string;
|
|
77
91
|
summaryPath: string;
|
|
@@ -70,6 +70,15 @@ export interface WorktreeDiffSummary {
|
|
|
70
70
|
removed: string[];
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
function deleteBranchIfPresent(basePath: string, branch: string, warningPrefix: string): void {
|
|
74
|
+
try {
|
|
75
|
+
if (!nativeBranchExists(basePath, branch)) return;
|
|
76
|
+
nativeBranchDelete(basePath, branch, true);
|
|
77
|
+
} catch (e) {
|
|
78
|
+
logWarning("worktree", `${warningPrefix}: ${(e as Error).message}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
73
82
|
// ─── Path Helpers ──────────────────────────────────────────────────────────
|
|
74
83
|
|
|
75
84
|
function normalizePathForComparison(path: string): string {
|
|
@@ -408,7 +417,7 @@ export function listWorktrees(basePath: string): WorktreeInfo[] {
|
|
|
408
417
|
|
|
409
418
|
/** Directories to skip when scanning for nested .git dirs. */
|
|
410
419
|
const NESTED_GIT_SKIP_DIRS = new Set([
|
|
411
|
-
".git", ".gsd", "node_modules", ".next", ".nuxt", "dist", "build",
|
|
420
|
+
".git", ".gsd", ".bg-shell", "node_modules", ".next", ".nuxt", "dist", "build",
|
|
412
421
|
"__pycache__", ".tox", ".venv", "venv", "target", "vendor",
|
|
413
422
|
]);
|
|
414
423
|
|
|
@@ -462,7 +471,9 @@ export function findNestedGitDirs(rootPath: string): string[] {
|
|
|
462
471
|
continue;
|
|
463
472
|
}
|
|
464
473
|
} catch (e) {
|
|
465
|
-
|
|
474
|
+
if ((e as NodeJS.ErrnoException).code !== "ENOENT") {
|
|
475
|
+
logWarning("worktree", `existsSync/.git check failed for ${fullPath}: ${(e as Error).message}`);
|
|
476
|
+
}
|
|
466
477
|
}
|
|
467
478
|
|
|
468
479
|
walk(fullPath, depth + 1);
|
|
@@ -535,7 +546,7 @@ export function removeWorktree(
|
|
|
535
546
|
if (!existsSync(wtPath)) {
|
|
536
547
|
nativeWorktreePrune(basePath);
|
|
537
548
|
if (deleteBranch) {
|
|
538
|
-
|
|
549
|
+
deleteBranchIfPresent(basePath, branch, "nativeBranchDelete failed");
|
|
539
550
|
}
|
|
540
551
|
return;
|
|
541
552
|
}
|
|
@@ -670,7 +681,7 @@ export function removeWorktree(
|
|
|
670
681
|
nativeWorktreePrune(basePath);
|
|
671
682
|
|
|
672
683
|
if (deleteBranch) {
|
|
673
|
-
|
|
684
|
+
deleteBranchIfPresent(basePath, branch, "final branch delete failed");
|
|
674
685
|
}
|
|
675
686
|
}
|
|
676
687
|
|
|
File without changes
|
|
File without changes
|