@opengsd/gsd-core 1.9.0 → 1.10.0
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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +2 -3
- package/.opencode/plugins/gsd-core.js +8 -1
- package/agents/gsd-code-fixer.md +131 -34
- package/agents/gsd-debugger.md +12 -246
- package/agents/gsd-executor.md +7 -5
- package/agents/gsd-integration-checker.md +3 -0
- package/agents/gsd-plan-checker.md +9 -0
- package/agents/gsd-planner.md +5 -8
- package/agents/gsd-roadmapper.md +21 -3
- package/agents/gsd-verifier.md +14 -70
- package/bin/install.js +503 -341
- package/commands/gsd/mempalace-capture.md +1 -1
- package/commands/gsd/new-milestone.md +1 -1
- package/commands/gsd/plan-phase.md +1 -1
- package/gsd-core/bin/gsd-tools.cjs +607 -63
- package/gsd-core/bin/lib/active-workstream-store.cjs +25 -0
- package/gsd-core/bin/lib/agent-install-check.cjs +38 -6
- package/gsd-core/bin/lib/api-coverage.cjs +120 -0
- package/gsd-core/bin/lib/audit.cjs +89 -1
- package/gsd-core/bin/lib/broken-windows.cjs +36 -6
- package/gsd-core/bin/lib/capability-registry.cjs +96 -110
- package/gsd-core/bin/lib/capability-validator.cjs +12 -2
- package/gsd-core/bin/lib/check-command-router.cjs +43 -1
- package/gsd-core/bin/lib/command-aliases.cjs +72 -0
- package/gsd-core/bin/lib/commands.cjs +26 -25
- package/gsd-core/bin/lib/commonjs-marker.cjs +136 -0
- package/gsd-core/bin/lib/config-loader.cjs +1 -0
- package/gsd-core/bin/lib/config.cjs +12 -1
- package/gsd-core/bin/lib/context-composer.cjs +278 -0
- package/gsd-core/bin/lib/context-predicates.cjs +506 -0
- package/gsd-core/bin/lib/core-utils.cjs +91 -12
- package/gsd-core/bin/lib/docs.cjs +3 -2
- package/gsd-core/bin/lib/external-job.cjs +19 -4
- package/gsd-core/bin/lib/frontmatter.cjs +84 -12
- package/gsd-core/bin/lib/gate-predicate-evaluator.cjs +57 -6
- package/gsd-core/bin/lib/git-base-branch.cjs +58 -15
- package/gsd-core/bin/lib/graphify.cjs +142 -27
- package/gsd-core/bin/lib/gsd2-import.cjs +27 -4
- package/gsd-core/bin/lib/host-integration.cjs +13 -1
- package/gsd-core/bin/lib/init-command-router.cjs +83 -8
- package/gsd-core/bin/lib/init.cjs +1021 -57
- package/gsd-core/bin/lib/install-engine.cjs +64 -10
- package/gsd-core/bin/lib/install-profiles.cjs +27 -1
- package/gsd-core/bin/lib/installer-migration-authoring.cjs +3 -1
- package/gsd-core/bin/lib/installer-migration-report.cjs +4 -0
- package/gsd-core/bin/lib/installer-migrations/007-retire-config-root-commonjs-marker.cjs +149 -0
- package/gsd-core/bin/lib/installer-migrations/008-cursor-retire-commands-surface.cjs +55 -0
- package/gsd-core/bin/lib/installer-migrations/009-pi-retire-reserved-hooks-dir.cjs +199 -0
- package/gsd-core/bin/lib/installer-migrations.cjs +87 -1
- package/gsd-core/bin/lib/io.cjs +28 -3
- package/gsd-core/bin/lib/markdown-sectionizer.cjs +6 -0
- package/gsd-core/bin/lib/mcp-catalog.cjs +518 -0
- package/gsd-core/bin/lib/mcp-server.cjs +135 -3
- package/gsd-core/bin/lib/milestone.cjs +106 -51
- package/gsd-core/bin/lib/phase-id.cjs +63 -0
- package/gsd-core/bin/lib/phase-locator.cjs +138 -45
- package/gsd-core/bin/lib/phase.cjs +260 -25
- package/gsd-core/bin/lib/plan-dependency-graph.cjs +232 -0
- package/gsd-core/bin/lib/planning-workspace.cjs +4 -0
- package/gsd-core/bin/lib/project-root.cjs +48 -0
- package/gsd-core/bin/lib/prompt-budget.cjs +128 -165
- package/gsd-core/bin/lib/retired-artifact-cleanup.cjs +80 -0
- package/gsd-core/bin/lib/review-lane-descriptor.cjs +99 -0
- package/gsd-core/bin/lib/review-lane-runner.cjs +30 -6
- package/gsd-core/bin/lib/roadmap-command-router.cjs +42 -9
- package/gsd-core/bin/lib/roadmap-parser.cjs +100 -18
- package/gsd-core/bin/lib/roadmap.cjs +37 -7
- package/gsd-core/bin/lib/runtime-artifact-conversion.cjs +195 -62
- package/gsd-core/bin/lib/runtime-artifact-layout.cjs +15 -3
- package/gsd-core/bin/lib/runtime-homes.cjs +154 -41
- package/gsd-core/bin/lib/runtime-hooks-surface.cjs +105 -41
- package/gsd-core/bin/lib/section-manifest.cjs +209 -0
- package/gsd-core/bin/lib/shell-command-projection.cjs +113 -27
- package/gsd-core/bin/lib/smart-entry.cjs +12 -0
- package/gsd-core/bin/lib/state-transition.cjs +73 -8
- package/gsd-core/bin/lib/state.cjs +151 -62
- package/gsd-core/bin/lib/surface.cjs +12 -1
- package/gsd-core/bin/lib/uat-predicate.cjs +11 -1
- package/gsd-core/bin/lib/uat.cjs +320 -21
- package/gsd-core/bin/lib/unusable-input.cjs +9 -0
- package/gsd-core/bin/lib/verification.cjs +29 -12
- package/gsd-core/bin/lib/verify.cjs +29 -5
- package/gsd-core/bin/lib/workflow-fragments.cjs +557 -0
- package/gsd-core/bin/lib/workstream-inventory-builder.cjs +181 -18
- package/gsd-core/bin/lib/workstream-inventory.cjs +519 -27
- package/gsd-core/bin/lib/workstream.cjs +6 -0
- package/gsd-core/bin/lib/worktree-base-ref.cjs +50 -6
- package/gsd-core/bin/lib/worktree-safety.cjs +276 -118
- package/gsd-core/bin/shared/config-schema.manifest.json +2 -0
- package/gsd-core/references/artifact-types.md +10 -3
- package/gsd-core/references/autonomous-ui-design-contract.md +42 -0
- package/gsd-core/references/debugger-techniques.md +255 -0
- package/gsd-core/references/research-documentation-lookup.md +5 -3
- package/gsd-core/references/specless-probe-fallback.md +7 -6
- package/gsd-core/references/verifier-wiring-patterns.md +100 -0
- package/gsd-core/references/worktree-branch-check.md +2 -2
- package/gsd-core/templates/summary-complex.md +2 -0
- package/gsd-core/templates/summary-minimal.md +2 -0
- package/gsd-core/templates/summary-standard.md +2 -0
- package/gsd-core/templates/summary.md +2 -0
- package/gsd-core/workflows/audit-milestone.md +3 -0
- package/gsd-core/workflows/autonomous/steps/converge-banner.md +1 -0
- package/gsd-core/workflows/autonomous/steps/converge-dispatch-bg.md +11 -0
- package/gsd-core/workflows/autonomous/steps/converge-dispatch-inline.md +7 -0
- package/gsd-core/workflows/autonomous/steps/converge-fail-fast.md +21 -0
- package/gsd-core/workflows/autonomous/steps/converge-loop.md +7 -0
- package/gsd-core/workflows/autonomous.md +32 -69
- package/gsd-core/workflows/code-review/steps/dispatch-fix.md +39 -0
- package/gsd-core/workflows/code-review/steps/structural-pre-pass.md +83 -0
- package/gsd-core/workflows/code-review.md +42 -145
- package/gsd-core/workflows/complete-milestone/steps/git-tag.md +29 -0
- package/gsd-core/workflows/complete-milestone.md +23 -81
- package/gsd-core/workflows/debug.md +9 -12
- package/gsd-core/workflows/diagnose-issues.md +22 -0
- package/gsd-core/workflows/discovery-phase.md +4 -4
- package/gsd-core/workflows/discuss-phase-assumptions/steps/auto-advance-dispatch.md +15 -0
- package/gsd-core/workflows/discuss-phase-assumptions.md +5 -16
- package/gsd-core/workflows/docs-update/steps/dispatch-monorepo-packages.md +51 -0
- package/gsd-core/workflows/docs-update.md +8 -51
- package/gsd-core/workflows/execute-phase/steps/executor-isolation-dispatch.md +34 -2
- package/gsd-core/workflows/execute-phase/steps/gap-closure-artifacts.md +50 -0
- package/gsd-core/workflows/execute-phase/steps/partial-wave.md +31 -0
- package/gsd-core/workflows/execute-phase/steps/per-plan-worktree-gate.md +19 -0
- package/gsd-core/workflows/execute-phase/steps/regression-gate-run.md +42 -0
- package/gsd-core/workflows/execute-phase/steps/regression-gate.md +43 -37
- package/gsd-core/workflows/execute-phase.md +65 -137
- package/gsd-core/workflows/execute-plan.md +1 -1
- package/gsd-core/workflows/help/modes/full.md +6 -1
- package/gsd-core/workflows/ingest-docs.md +2 -1
- package/gsd-core/workflows/new-milestone/steps/project-md-milestone-write.md +16 -0
- package/gsd-core/workflows/new-milestone/steps/reset-phase-safety.md +19 -0
- package/gsd-core/workflows/new-milestone.md +21 -38
- package/gsd-core/workflows/new-project/steps/auto-mode-config.md +176 -0
- package/gsd-core/workflows/new-project/steps/auto-mode-detection.md +32 -0
- package/gsd-core/workflows/new-project/steps/codebase-map-offer.md +18 -0
- package/gsd-core/workflows/new-project.md +13 -226
- package/gsd-core/workflows/plan-phase/steps/adr-ingest-express-path.md +15 -0
- package/gsd-core/workflows/plan-phase/steps/chunked-planning-mode.md +110 -0
- package/gsd-core/workflows/plan-phase/steps/prd-express-gate.md +8 -0
- package/gsd-core/workflows/plan-phase/steps/research-only-early-exit.md +17 -0
- package/gsd-core/workflows/plan-phase/steps/research-only-modifiers.md +16 -0
- package/gsd-core/workflows/plan-phase/steps/reviews-prerequisite.md +17 -0
- package/gsd-core/workflows/plan-phase/steps/stall-detection-helpers.md +149 -0
- package/gsd-core/workflows/plan-phase.md +49 -193
- package/gsd-core/workflows/progress/steps/forensic-audit.md +125 -0
- package/gsd-core/workflows/progress/steps/mvp-display.md +18 -0
- package/gsd-core/workflows/progress.md +11 -153
- package/gsd-core/workflows/quick/steps/discussion-phase.md +124 -0
- package/gsd-core/workflows/quick/steps/plan-checker-loop.md +111 -0
- package/gsd-core/workflows/quick/steps/quick-verification.md +46 -0
- package/gsd-core/workflows/quick/steps/research-phase.md +72 -0
- package/gsd-core/workflows/quick/steps/worktree-pre-dispatch-commit.md +37 -0
- package/gsd-core/workflows/quick.md +20 -390
- package/gsd-core/workflows/resume-project.md +3 -0
- package/gsd-core/workflows/review/steps/reviewer-instances-note-1.md +4 -0
- package/gsd-core/workflows/review/steps/reviewer-instances-note-2.md +3 -0
- package/gsd-core/workflows/review.md +15 -8
- package/gsd-core/workflows/section-manifest.json +219 -0
- package/gsd-core/workflows/sketch.md +1 -1
- package/gsd-core/workflows/spec-phase.md +17 -14
- package/gsd-core/workflows/spike-wrap-up.md +20 -5
- package/gsd-core/workflows/spike.md +50 -16
- package/gsd-core/workflows/sync-skills.md +49 -11
- package/gsd-core/workflows/transition/steps/workstream-collision-check.md +17 -0
- package/gsd-core/workflows/transition.md +8 -21
- package/gsd-core/workflows/ui-phase.md +8 -7
- package/gsd-core/workflows/update/steps/channel-banner.md +7 -0
- package/gsd-core/workflows/update.md +18 -7
- package/gsd-core/workflows/verify-phase.md +4 -7
- package/gsd-core/workflows/verify-work/steps/automated-ui-verification.md +36 -0
- package/gsd-core/workflows/verify-work/steps/mvp-uat-framing.md +21 -0
- package/gsd-core/workflows/verify-work.md +8 -58
- package/hooks/dist/gsd-agent-isolation-guard.js +428 -0
- package/hooks/dist/gsd-check-update-worker.js +14 -5
- package/hooks/dist/gsd-cursor-subagent-start.js +532 -26
- package/hooks/dist/gsd-read-injection-scanner.js +7 -0
- package/hooks/dist/gsd-statusline.js +72 -6
- package/hooks/dist/gsd-worktree-path-guard.js +2 -1
- package/hooks/dist/gsd-write-guard.js +359 -0
- package/hooks/dist/lib/isolation-sentinel.js +268 -0
- package/hooks/dist/managed-hooks-registry.cjs +2 -0
- package/hooks/gsd-agent-isolation-guard.js +428 -0
- package/hooks/gsd-check-update-worker.js +14 -5
- package/hooks/gsd-cursor-subagent-start.js +532 -26
- package/hooks/gsd-read-injection-scanner.js +7 -0
- package/hooks/gsd-statusline.js +72 -6
- package/hooks/gsd-worktree-path-guard.js +2 -1
- package/hooks/gsd-write-guard.js +359 -0
- package/hooks/hooks.json +12 -0
- package/hooks/lib/isolation-sentinel.js +268 -0
- package/hooks/managed-hooks-registry.cjs +2 -0
- package/package.json +14 -5
- package/pi/gsd.cjs +57 -12
- package/scripts/build-hooks.js +9 -0
- package/scripts/changeset/lint.cjs +9 -2
- package/scripts/changeset/serialize.cjs +5 -1
- package/scripts/gen-capability-matrix.cjs +1 -1
- package/scripts/gen-context-index.cjs +448 -0
- package/scripts/gen-inventory-manifest.cjs +101 -1
- package/scripts/gen-prompt-budget-parity-corpus.cjs +645 -0
- package/scripts/gen-registry.cjs +39 -15
- package/scripts/gen-section-manifest.cjs +638 -0
- package/scripts/generate-package-identity.cjs +4 -2
- package/scripts/lint-allow-test-rule-refs.allowlist.json +17 -31
- package/scripts/lint-compiled-artifact-sync.cjs +6 -1
- package/scripts/lint-docs-command-form.cjs +195 -0
- package/scripts/lint-docs-required.cjs +9 -1
- package/scripts/lint-emitted-drift-ack.cjs +215 -20
- package/scripts/lint-example-parser-parity.cjs +395 -0
- package/scripts/lint-test-file-count.allowlist.json +27 -1
- package/scripts/mutation-matrix.cjs +13 -0
- package/scripts/prompt-injection-scan.sh +27 -6
- package/scripts/registry-schema.cjs +323 -94
- package/scripts/run-tests.cjs +3 -2
- package/scripts/validate-registry.cjs +10 -6
- package/skills/gsd-autonomous/SKILL.md +1 -1
- package/skills/gsd-execute-phase/SKILL.md +1 -1
- package/skills/gsd-mempalace-capture/SKILL.md +1 -1
- package/skills/gsd-new-milestone/SKILL.md +1 -1
- package/skills/gsd-plan-phase/SKILL.md +2 -2
- package/vscode/package.json +1 -1
- package/scripts/gen-emitted-baseline.cjs +0 -145
|
@@ -1,54 +1,560 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// gsd-hook-version: {{GSD_VERSION}}
|
|
3
|
-
// gsd-cursor-subagent-start.js — Cursor subagentStart hook (ADR-1239 / #2089
|
|
3
|
+
// gsd-cursor-subagent-start.js — Cursor subagentStart hook (ADR-1239 / #2089,
|
|
4
|
+
// isolation guard #3045)
|
|
4
5
|
//
|
|
5
6
|
// Cursor invokes this script when a subagent session starts.
|
|
6
7
|
// Protocol: JSON from Cursor on stdin; JSON response on stdout.
|
|
7
8
|
//
|
|
8
|
-
// Input schema (cursor subagentStart)
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
9
|
+
// Input schema (cursor subagentStart) — Cursor's hooks contract is a COMMON
|
|
10
|
+
// envelope shared by every hook, PLUS event-specific fields layered on top
|
|
11
|
+
// (cursor.com/docs/hooks, "Reference > Common schema"). A prior version of
|
|
12
|
+
// this comment documented only the envelope and omitted the event-specific
|
|
13
|
+
// fields entirely — that omission is exactly what caused #3045's isolation
|
|
14
|
+
// guard work to stall on a false schema conflict, so every field below is
|
|
15
|
+
// still read defensively (assume any of them may be absent/malformed):
|
|
16
|
+
// Common envelope (all hooks): conversation_id, generation_id, model,
|
|
17
|
+
// model_id, model_params, hook_event_name, cursor_version,
|
|
18
|
+
// workspace_roots (array of paths), user_email, transcript_path.
|
|
19
|
+
// (Some fields are omitted for app-lifecycle hooks; this script's own
|
|
20
|
+
// prior comment listed session_id/is_background_agent instead of
|
|
21
|
+
// model_id/model_params — the exact set observed is not guaranteed.)
|
|
22
|
+
// subagentStart-specific additions: subagent_id, subagent_type, task,
|
|
23
|
+
// parent_conversation_id, tool_call_id, subagent_model,
|
|
24
|
+
// is_parallel_worker, git_branch (optional).
|
|
12
25
|
//
|
|
13
26
|
// Output schema (cursor subagentStart):
|
|
14
|
-
// { additional_context?: string }
|
|
27
|
+
// { additional_context?: string, permission?: "allow"|"deny", user_message?: string }
|
|
28
|
+
// "ask" is NOT a supported permission value for subagentStart — Cursor
|
|
29
|
+
// treats it as "deny". This script only ever emits "allow" (by omitting
|
|
30
|
+
// `permission`, preserving the pre-#3045 output shape) or an explicit
|
|
31
|
+
// "deny" with `user_message`.
|
|
15
32
|
//
|
|
16
33
|
// Behaviour:
|
|
17
34
|
// - Injects a brief GSD state reminder so subagents (planner, executor,
|
|
18
|
-
// verifier) have the current phase context.
|
|
19
|
-
// -
|
|
35
|
+
// verifier) have the current phase context (unchanged since #2587).
|
|
36
|
+
// - NEW (#3045): denies spawning a GSD executor subagent when this
|
|
37
|
+
// project's dispatch isolation resolves to "harness-worktree" but the
|
|
38
|
+
// session is NOT actually running isolated from the user's primary
|
|
39
|
+
// checkout. Cursor's `--worktree` is a SESSION-level flag (no per-call
|
|
40
|
+
// isolation parameter exists on `subagentStart`, unlike Claude's
|
|
41
|
+
// `Agent(isolation=...)` kwarg), so this guard verifies EFFECTIVE STATE
|
|
42
|
+
// instead of looking for a flag — see resolveIsolationDecision() below.
|
|
43
|
+
// - Fails open on a payload it cannot parse or that carries fields it does
|
|
44
|
+
// not need: never throws, never blocks a call it cannot evaluate.
|
|
45
|
+
// Isolation resolution itself fails CLOSED (denies) for the two cases
|
|
46
|
+
// that are load-bearing and are NOT the same as "cannot parse": (a) a
|
|
47
|
+
// GSD project resolved to harness-worktree whose isolation state cannot
|
|
48
|
+
// be verified, and (b) a harness-worktree GSD project dispatch with no
|
|
49
|
+
// usable subagent_type — a guard that cannot verify must not answer
|
|
50
|
+
// "safe" (#3050).
|
|
20
51
|
//
|
|
21
52
|
// Cursor docs: https://cursor.com/docs/hooks
|
|
22
53
|
|
|
23
54
|
'use strict';
|
|
24
55
|
|
|
25
56
|
const fs = require('fs');
|
|
57
|
+
const path = require('path');
|
|
58
|
+
const os = require('os');
|
|
59
|
+
|
|
60
|
+
// Workspace resolution is shared across the Cursor hooks (#2587) — see
|
|
61
|
+
// hooks/lib/cursor-workspace.js. Staged next to these scripts by
|
|
62
|
+
// writeCursorHooksJson so the require always resolves post-install.
|
|
63
|
+
const { resolveStatePath } = require('./lib/cursor-workspace.js');
|
|
64
|
+
const { readSentinel, VALID_ISOLATION, extractDispatchIdentifiers, sentinelAppliesToDispatch } = require('./lib/isolation-sentinel.js');
|
|
26
65
|
|
|
27
66
|
const MSG_PRESENT =
|
|
28
67
|
'GSD: Subagent session started — review .planning/STATE.md for the current phase and any blockers before acting.';
|
|
29
68
|
const MSG_ABSENT =
|
|
30
69
|
'GSD: Subagent session started — no .planning/ workflow found.';
|
|
31
70
|
|
|
32
|
-
//
|
|
33
|
-
//
|
|
34
|
-
//
|
|
35
|
-
|
|
71
|
+
// GSD's Cursor agent artifacts install with `destSubpath: "agents"`,
|
|
72
|
+
// `prefix: "gsd-"`, flat nesting, via the `convertClaudeAgentToCursorAgent`
|
|
73
|
+
// converter, and `hostIntegration.dispatch.namedDispatch === true`
|
|
74
|
+
// (gsd-core/bin/lib/capability-registry.cjs, runtimes.cursor) — i.e. Cursor
|
|
75
|
+
// dispatches named subagents by their real agent name, identically to
|
|
76
|
+
// Claude. So GSD's executor surfaces as subagent_type === "gsd-executor" on
|
|
77
|
+
// Cursor too, the same identifier hooks/gsd-agent-isolation-guard.js checks
|
|
78
|
+
// for on Claude. A Set, not a bare string compare, so a future sibling
|
|
79
|
+
// executor role can be added here without touching the matching logic below.
|
|
80
|
+
const EXECUTOR_SUBAGENT_TYPES = new Set(['gsd-executor']);
|
|
36
81
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
82
|
+
/**
|
|
83
|
+
* Runs `realpathFn`, never throwing. A path that cannot be resolved (does not
|
|
84
|
+
* exist, dangling symlink, ELOOP, ...) yields `null` rather than an
|
|
85
|
+
* exception — the caller decides what "cannot resolve" means for its own
|
|
86
|
+
* verdict (#3045 finding 2).
|
|
87
|
+
*
|
|
88
|
+
* `realpathFn` is injectable (defaults to `fs.realpathSync`), per the repo's
|
|
89
|
+
* dependency-injection seam convention (mirrors the `clock` seam elsewhere in
|
|
90
|
+
* these hooks) — this lets tests exercise the realpath-based spoof-resistance
|
|
91
|
+
* logic below with a fabricated symlink-resolution mapping, without ever
|
|
92
|
+
* creating a real filesystem symlink (directory symlinks require elevated
|
|
93
|
+
* privileges on unprivileged Windows CI).
|
|
94
|
+
*/
|
|
95
|
+
function realpathOrNull(p, realpathFn) {
|
|
96
|
+
try {
|
|
97
|
+
return realpathFn(p);
|
|
98
|
+
} catch {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
41
102
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
103
|
+
/**
|
|
104
|
+
* Resolve whether `root` is running in a session Cursor ISOLATED FOR THIS
|
|
105
|
+
* DISPATCH — i.e. a worktree the harness itself created and manages, not
|
|
106
|
+
* merely "some linked git worktree".
|
|
107
|
+
*
|
|
108
|
+
* #3045 security review (finding 3): "is a linked git worktree" is NOT "is
|
|
109
|
+
* isolated from the tree the human is using". A developer who opens Cursor
|
|
110
|
+
* directly in a hand-made `git worktree add` checkout — routine, see
|
|
111
|
+
* `.claude/worktrees/` in this very repo — is not protected by anything;
|
|
112
|
+
* nothing stops them from also editing that same checkout by hand. The ONLY
|
|
113
|
+
* signal that actually proves harness isolation is that `root` resolves
|
|
114
|
+
* under Cursor's OWN managed worktree root (`<cursor config dir>/worktrees`,
|
|
115
|
+
* i.e. `~/.cursor/worktrees` by default — `getGlobalConfigDir('cursor')`
|
|
116
|
+
* honors the `CURSOR_CONFIG_DIR` env override and `~` expansion for free).
|
|
117
|
+
* That is made NECESSARY AND SUFFICIENT below. Do NOT reinstate
|
|
118
|
+
* `resolveWorktreeLinkage`'s `linked_worktree_root` mode as an alternative
|
|
119
|
+
* OR'd proof of isolation — that is precisely the bypass finding 3 closed;
|
|
120
|
+
* a future "simplification" that merges it back in re-opens unconsented
|
|
121
|
+
* writes to the human's active checkout.
|
|
122
|
+
*
|
|
123
|
+
* `resolveWorktreeLinkage` is still called, but ONLY as a diagnostic: it
|
|
124
|
+
* distinguishes "confidently not isolated" from "git could not answer
|
|
125
|
+
* (timeout) — cannot determine" so the eventual deny reason stays
|
|
126
|
+
* actionable. Its result never flips `isolated`.
|
|
127
|
+
*
|
|
128
|
+
* Both the workspace root and the managed root are realpath'd before
|
|
129
|
+
* comparison (#3045 finding 2) — lexical `path.relative` alone is spoofable
|
|
130
|
+
* by a symlink or bind mount at either location, plantable by any process
|
|
131
|
+
* running with the user's permissions (including an agent already inside a
|
|
132
|
+
* legitimately isolated worktree, which has shell access by design).
|
|
133
|
+
* `fs.realpathSync` throwing (nonexistent path) never propagates — it
|
|
134
|
+
* degrades to "cannot resolve", never to "isolated". realpath also resolves
|
|
135
|
+
* the `CURSOR_CONFIG_DIR`-derived managed root itself (not just `root`), so a
|
|
136
|
+
* symlinked or case-differing `CURSOR_CONFIG_DIR` (case-insensitive
|
|
137
|
+
* filesystems normalize to on-disk casing via realpath's dirent walk, not
|
|
138
|
+
* string comparison) is covered on BOTH sides of the comparison, not only
|
|
139
|
+
* `root`'s.
|
|
140
|
+
*
|
|
141
|
+
* Returns `{ isolated: true|false, cannotDetermine: bool, notApplicable: bool }`.
|
|
142
|
+
* `notApplicable` (#3045 MAJOR 3) is true only for a confidently-not-a-git-repo
|
|
143
|
+
* root — see the `not_git_repo` branch below.
|
|
144
|
+
*
|
|
145
|
+
* `realpath` is injectable (`(p: string) => string`, throws like
|
|
146
|
+
* `fs.realpathSync` on an unresolvable path; defaults to the real
|
|
147
|
+
* `fs.realpathSync`) per the repo's clock-seam-style dependency-injection
|
|
148
|
+
* convention. This lets tests drive the exact spoof-resistance logic this
|
|
149
|
+
* function exists for (a symlink at the managed root pointing OUTSIDE it)
|
|
150
|
+
* with an injected resolution mapping, in-process, on every platform —
|
|
151
|
+
* without creating a real directory symlink, which requires elevated
|
|
152
|
+
* privileges on unprivileged Windows CI.
|
|
153
|
+
*/
|
|
154
|
+
function resolveIsolationEvidence(root, { realpath = fs.realpathSync } = {}) {
|
|
155
|
+
let managedRoot = null;
|
|
46
156
|
try {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
|
|
157
|
+
// Sibling data/policy module, staged alongside this hook at install time
|
|
158
|
+
// (same pattern as hooks/gsd-statusline.js's requires of gsd-core/bin/lib/*).
|
|
159
|
+
const { getGlobalConfigDir } = require('../gsd-core/bin/lib/runtime-homes.cjs');
|
|
160
|
+
managedRoot = path.join(getGlobalConfigDir('cursor'), 'worktrees');
|
|
51
161
|
} catch {
|
|
52
|
-
|
|
162
|
+
managedRoot = null;
|
|
53
163
|
}
|
|
54
|
-
|
|
164
|
+
|
|
165
|
+
const realRoot = realpathOrNull(root, realpath);
|
|
166
|
+
const realManagedRoot = managedRoot === null ? null : realpathOrNull(managedRoot, realpath);
|
|
167
|
+
|
|
168
|
+
if (realRoot !== null && realManagedRoot !== null) {
|
|
169
|
+
const rel = path.relative(realManagedRoot, realRoot);
|
|
170
|
+
const underManagedRoot = rel === '' || (!rel.startsWith('..') && !path.isAbsolute(rel));
|
|
171
|
+
if (underManagedRoot) return { isolated: true, cannotDetermine: false, notApplicable: false };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Not proven isolated by the only signal that counts. Resolve the
|
|
175
|
+
// diagnostic-only linkage check purely to make the deny reason legible —
|
|
176
|
+
// see the doc comment above; this NEVER flips `isolated`.
|
|
177
|
+
let linkageReason = null;
|
|
178
|
+
try {
|
|
179
|
+
// Sibling data/policy module, staged alongside this hook at install time.
|
|
180
|
+
const { resolveWorktreeLinkage } = require('../gsd-core/bin/lib/worktree-safety.cjs');
|
|
181
|
+
linkageReason = resolveWorktreeLinkage(root).reason;
|
|
182
|
+
} catch {
|
|
183
|
+
linkageReason = null;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (realRoot === null) {
|
|
187
|
+
// `root` itself could not be resolved on disk. In the live hook this is
|
|
188
|
+
// defense in depth rather than a reachable path today: the GSD-project
|
|
189
|
+
// existence gate in resolveIsolationDecision already requires `root` to
|
|
190
|
+
// resolve (it must contain a readable `.planning/config.json`) before
|
|
191
|
+
// evidence is ever consulted, so a workspace root that plainly does not
|
|
192
|
+
// exist allows earlier as "not a GSD project" — never here. Kept anyway
|
|
193
|
+
// per finding 2's explicit directive: an unresolvable path must never
|
|
194
|
+
// silently read as "isolated".
|
|
195
|
+
return { isolated: false, cannotDetermine: true, notApplicable: false };
|
|
196
|
+
}
|
|
197
|
+
if (linkageReason === 'git_timed_out') {
|
|
198
|
+
return { isolated: false, cannotDetermine: true, notApplicable: false };
|
|
199
|
+
}
|
|
200
|
+
if (linkageReason === 'not_git_repo') {
|
|
201
|
+
// #3045 MAJOR 3: a confidently-non-git `root` has no primary git
|
|
202
|
+
// checkout to protect from an isolated-worktree bypass — Cursor's
|
|
203
|
+
// `--worktree` / `/worktree` (the deny message's own remediation) create
|
|
204
|
+
// a GIT worktree, so telling the user to start one is unactionable
|
|
205
|
+
// advice for a directory that isn't a git repo at all. Treat as INERT
|
|
206
|
+
// (allow) rather than a confident negative; this is distinct from
|
|
207
|
+
// `cannotDetermine` (git responded definitively here, it just said "not
|
|
208
|
+
// a repo") and from `isolated` (nothing was proven isolated) — it is its
|
|
209
|
+
// own "this guard's threat model does not apply" outcome.
|
|
210
|
+
return { isolated: false, cannotDetermine: false, notApplicable: true };
|
|
211
|
+
}
|
|
212
|
+
return { isolated: false, cannotDetermine: false, notApplicable: false };
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Resolve every non-empty string entry of `workspace_roots` — ALL checkout
|
|
217
|
+
* paths Cursor is operating on for this hook invocation, not just the first.
|
|
218
|
+
*
|
|
219
|
+
* #3045 security review (finding 1): a multi-root Cursor workspace whose
|
|
220
|
+
* FIRST root is a non-GSD directory (or an isolated worktree) and whose
|
|
221
|
+
* SECOND root is the GSD project in the primary checkout must still be
|
|
222
|
+
* caught — every root is a directory the dispatched subagent can reach and
|
|
223
|
+
* write to, regardless of position. `hooks/lib/cursor-workspace.js` already
|
|
224
|
+
* established the "scan every root" precedent for its own (different)
|
|
225
|
+
* purpose; this is a parallel scan for isolation applicability, not a
|
|
226
|
+
* duplicate of that module's single-root-resolution job (it resolves ONE
|
|
227
|
+
* root to report state-file presence; this resolves the full set to decide
|
|
228
|
+
* whether ANY of them is an unconsented write target).
|
|
229
|
+
*
|
|
230
|
+
* Cursor runs hooks with cwd set to its own config dir (~/.cursor), NOT the
|
|
231
|
+
* workspace (hooks/lib/cursor-workspace.js), so `workspace_roots` is the
|
|
232
|
+
* only reliable source for "what directories is this dispatch actually in".
|
|
233
|
+
*
|
|
234
|
+
* #3045 MINOR: a RELATIVE entry is rejected (`path.isAbsolute`), not merely
|
|
235
|
+
* accepted-and-hoped — every downstream consumer (`.planning/config.json`
|
|
236
|
+
* existence check, `realpathOrNull`, `resolveWorktreeLinkage`) joins/resolves
|
|
237
|
+
* it against whatever the CURRENT PROCESS cwd happens to be, which for this
|
|
238
|
+
* hook is Cursor's own config dir (~/.cursor per the comment above), NOT the
|
|
239
|
+
* workspace. A relative root would therefore resolve against the wrong
|
|
240
|
+
* directory and — because a wrong/nonexistent `.planning/config.json` path
|
|
241
|
+
* reads as "not a GSD project" — silently ALLOW a dispatch this guard should
|
|
242
|
+
* have evaluated (fail OPEN). Filtering it out here instead makes it "not a
|
|
243
|
+
* resolvable workspace root", which degrades the SAME way (allow, step 2 of
|
|
244
|
+
* resolveIsolationDecision's applicability list) but for the honest reason.
|
|
245
|
+
*/
|
|
246
|
+
function getWorkspaceRoots(data) {
|
|
247
|
+
const roots = Array.isArray(data.workspace_roots) ? data.workspace_roots : [];
|
|
248
|
+
return roots.filter((r) => typeof r === 'string' && r.length > 0 && path.isAbsolute(r));
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Decide whether to deny this subagentStart. Returns
|
|
253
|
+
* `{ action: 'allow' } | { action: 'deny', reason: string }`.
|
|
254
|
+
*
|
|
255
|
+
* Applicability (must positively determine all of the following to deny —
|
|
256
|
+
* otherwise allow):
|
|
257
|
+
* 1. `subagent_type` is not confidently a NON-executor (a present,
|
|
258
|
+
* non-empty string that isn't in EXECUTOR_SUBAGENT_TYPES short-circuits
|
|
259
|
+
* to allow immediately, before any project/isolation resolution runs —
|
|
260
|
+
* mirrors hooks/gsd-agent-isolation-guard.js checking subagent_type
|
|
261
|
+
* first, and matters here specifically: an unreadable config must never
|
|
262
|
+
* deny a dispatch this guard was never going to enforce against),
|
|
263
|
+
* 2. a workspace root is resolvable from `workspace_roots`,
|
|
264
|
+
* 3. that root is a GSD project (`.planning/config.json` exists there),
|
|
265
|
+
* 4. the resolved dispatch isolation is `harness-worktree`,
|
|
266
|
+
* 5. `subagent_type` identifies a GSD executor (or is missing/malformed —
|
|
267
|
+
* see the cannot-determine case below),
|
|
268
|
+
* 6. the session is NOT actually isolated (resolveIsolationEvidence).
|
|
269
|
+
*
|
|
270
|
+
* No workspace root at all degrades to allow (step 2), mirroring
|
|
271
|
+
* hooks/gsd-agent-isolation-guard.js's own "not a GSD project → allow"
|
|
272
|
+
* branch: project-existence is the gate that makes fail-closed apply in the
|
|
273
|
+
* first place, so being unable to even locate a candidate project is not
|
|
274
|
+
* itself a fail-closed trigger — it is the same "not a GSD project" shape
|
|
275
|
+
* that guard already treats as inert.
|
|
276
|
+
*
|
|
277
|
+
* Two DISTINCT fail-closed ("cannot determine") reasons per #3050's lesson
|
|
278
|
+
* that a guard which cannot verify must not answer "safe" — both scoped to
|
|
279
|
+
* "GSD project resolved to harness-worktree", never to a dispatch already
|
|
280
|
+
* confirmed to be a non-executor:
|
|
281
|
+
* - this project's dispatch-isolation configuration cannot be read/resolved
|
|
282
|
+
* (registry require/parse failure, or config.json unreadable),
|
|
283
|
+
* - `subagent_type` is missing or not a usable non-empty string on a
|
|
284
|
+
* dispatch this guard could not rule out as an executor.
|
|
285
|
+
*
|
|
286
|
+
* Isolation resolution (#3045 BLOCKER fix, see hooks/lib/isolation-sentinel.js):
|
|
287
|
+
* prefers the workflow's own PERSISTED per-dispatch decision (the sentinel
|
|
288
|
+
* `record-dispatch-isolation` writes) over re-deriving a host CAPABILITY from
|
|
289
|
+
* the registry. `none`/`orchestrator-worktree` from a fresh sentinel ALLOW
|
|
290
|
+
* immediately — sequential/orchestrator-managed dispatch is legitimate. An
|
|
291
|
+
* absent/stale sentinel falls back to `resolveFallbackIsolation` (registry +
|
|
292
|
+
* `workflow.use_worktrees`, runtime resolved GSD_RUNTIME env >
|
|
293
|
+
* .planning/config.json `runtime` key > 'cursor'). The default is
|
|
294
|
+
* confidently "cursor" here — UNLIKE hooks/gsd-agent-isolation-guard.js's own
|
|
295
|
+
* fallback, which must treat "no explicit signal" as cannot-determine
|
|
296
|
+
* because that hook installs across every `hostIntegration.hooksSurface ===
|
|
297
|
+
* 'settings-json'` runtime — because THIS script only ever runs as Cursor's
|
|
298
|
+
* own subagentStart hook; there is no other host it could be executing
|
|
299
|
+
* under, so defaulting to 'cursor' is a confirmed fact of the execution
|
|
300
|
+
* context, not a guess (#3045 MINOR — this note replaces a prior comment
|
|
301
|
+
* that inaccurately claimed to "mirror" runtime-slash.cjs's resolveRuntime,
|
|
302
|
+
* which defaults to 'claude'; the two intentionally diverge).
|
|
303
|
+
*
|
|
304
|
+
* #3045 security review (finding 1): applicability step 2 above now means
|
|
305
|
+
* "a workspace root is resolvable", plural — resolveIsolationDecision
|
|
306
|
+
* evaluates EVERY entry of `workspace_roots` via evaluateRootIsolation() and
|
|
307
|
+
* denies on the first one that fails. `subagent_type` is still resolved
|
|
308
|
+
* exactly once, up front, before any root is touched (applicability step 1
|
|
309
|
+
* stays a single check, not per-root — an unreadable config on one root must
|
|
310
|
+
* never even be attempted for a confirmed non-executor dispatch).
|
|
311
|
+
*/
|
|
312
|
+
function resolveIsolationDecision(data, { clock = Date, realpath = fs.realpathSync } = {}) {
|
|
313
|
+
const subagentType = data.subagent_type;
|
|
314
|
+
const isConfirmedNonExecutor = typeof subagentType === 'string'
|
|
315
|
+
&& subagentType.length > 0
|
|
316
|
+
&& !EXECUTOR_SUBAGENT_TYPES.has(subagentType);
|
|
317
|
+
if (isConfirmedNonExecutor) return { action: 'allow' };
|
|
318
|
+
|
|
319
|
+
const roots = getWorkspaceRoots(data);
|
|
320
|
+
if (roots.length === 0) return { action: 'allow' };
|
|
321
|
+
|
|
322
|
+
// #3045 SECURITY F2: best-effort plan/phase extraction from this
|
|
323
|
+
// dispatch's own `task` text (Cursor carries the same prompt content the
|
|
324
|
+
// Claude Agent() dispatch does — see extractDispatchIdentifiers), so a
|
|
325
|
+
// fresh sentinel that disagrees with THIS dispatch is treated as
|
|
326
|
+
// inapplicable rather than trusted.
|
|
327
|
+
const dispatchIds = extractDispatchIdentifiers(data.task);
|
|
328
|
+
|
|
329
|
+
for (const root of roots) {
|
|
330
|
+
const verdict = evaluateRootIsolation(root, subagentType, { clock, dispatchIds, realpath });
|
|
331
|
+
if (verdict.action === 'deny') return verdict;
|
|
332
|
+
}
|
|
333
|
+
return { action: 'allow' };
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Conservative fallback resolution used when the #3045 sentinel is absent or
|
|
338
|
+
* stale for `root`: re-derive isolation from the registry CAPABILITY, gated
|
|
339
|
+
* by `workflow.use_worktrees` (config-schema key confirmed present in
|
|
340
|
+
* gsd-core/bin/shared/config-schema.manifest.json's validKeys, so it survives
|
|
341
|
+
* loadConfig's whitelist; read directly from the raw config.json here, same
|
|
342
|
+
* side-effect-free approach cmdConfigGet itself uses).
|
|
343
|
+
*
|
|
344
|
+
* #3045 MAJOR fix ("Cursor residual false-deny"): previously defaulted
|
|
345
|
+
* confidently to 'cursor' whenever no `GSD_RUNTIME`/config.json `runtime`
|
|
346
|
+
* signal existed, purely because this script only ever executes as Cursor's
|
|
347
|
+
* OWN `subagentStart` hook — true of the PROCESS, but not evidence the
|
|
348
|
+
* PROJECT itself declared an isolation requirement this guard can verify.
|
|
349
|
+
* Combined with a stale/absent sentinel (outside `execute-phase`, after
|
|
350
|
+
* `.gsd` cleanup, a phase running past the sentinel's staleness window, or a
|
|
351
|
+
* base-check-degraded run whose sentinel went stale before a fresh one was
|
|
352
|
+
* recorded), that default made every such `gsd-executor` dispatch resolve to
|
|
353
|
+
* "harness-worktree" and then hard-DENY unless the session happened to be
|
|
354
|
+
* running under Cursor's own managed worktree root — a false-deny of
|
|
355
|
+
* otherwise legitimate dispatches, unlike `hooks/gsd-agent-isolation-guard.js`,
|
|
356
|
+
* which degrades an undeterminable runtime to inert (#3045 MAJOR 2). Aligned
|
|
357
|
+
* here: an explicit signal is now required — `GSD_RUNTIME` > config.json
|
|
358
|
+
* `runtime` key > `~/.gsd/defaults.json` `runtime` (mirrors the Claude hook's
|
|
359
|
+
* `resolveRuntimeIdentity`; `bin/install.js`'s `writeNonClaudeDefaults`
|
|
360
|
+
* persists the installed runtime there for every non-Claude install,
|
|
361
|
+
* including Cursor, so a REAL Cursor+GSD install still resolves confidently
|
|
362
|
+
* — this only stops GUESSING 'cursor' for a project that never declared any
|
|
363
|
+
* runtime signal at all).
|
|
364
|
+
*/
|
|
365
|
+
function resolveFallbackIsolation(root, configPath) {
|
|
366
|
+
const { resolveRuntimeNameFromCandidates } = require('../gsd-core/bin/lib/runtime-name-policy.cjs');
|
|
367
|
+
const { runtimes } = require('../gsd-core/bin/lib/capability-registry.cjs');
|
|
368
|
+
|
|
369
|
+
let runtimeId = resolveRuntimeNameFromCandidates(process.env.GSD_RUNTIME);
|
|
370
|
+
const rawConfig = fs.readFileSync(configPath, 'utf-8');
|
|
371
|
+
const parsedConfig = JSON.parse(rawConfig);
|
|
372
|
+
if (!runtimeId && parsedConfig && typeof parsedConfig === 'object' && 'runtime' in parsedConfig) {
|
|
373
|
+
runtimeId = resolveRuntimeNameFromCandidates(parsedConfig.runtime) || null;
|
|
374
|
+
}
|
|
375
|
+
if (!runtimeId) {
|
|
376
|
+
try {
|
|
377
|
+
const defaultsPath = path.join(os.homedir(), '.gsd', 'defaults.json');
|
|
378
|
+
const defaultsParsed = JSON.parse(fs.readFileSync(defaultsPath, 'utf-8'));
|
|
379
|
+
if (defaultsParsed && typeof defaultsParsed === 'object' && 'runtime' in defaultsParsed) {
|
|
380
|
+
runtimeId = resolveRuntimeNameFromCandidates(defaultsParsed.runtime) || null;
|
|
381
|
+
}
|
|
382
|
+
} catch {
|
|
383
|
+
// Absent/unreadable ~/.gsd/defaults.json — no signal, fall through.
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
if (!runtimeId) {
|
|
387
|
+
// No explicit signal anywhere confirms this project resolved
|
|
388
|
+
// harness-worktree — degrade to inert rather than guess 'cursor'.
|
|
389
|
+
return 'none';
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
const runtimeEntry = runtimes != null ? runtimes[runtimeId] : null;
|
|
393
|
+
const declared = runtimeEntry?.runtime?.hostIntegration?.dispatch?.isolation ?? null;
|
|
394
|
+
let declaredIsolation = (typeof declared === 'string' && VALID_ISOLATION.has(declared)) ? declared : 'none';
|
|
395
|
+
|
|
396
|
+
if (declaredIsolation === 'harness-worktree' &&
|
|
397
|
+
parsedConfig && typeof parsedConfig === 'object' && parsedConfig.workflow &&
|
|
398
|
+
typeof parsedConfig.workflow === 'object' && parsedConfig.workflow.use_worktrees === false) {
|
|
399
|
+
declaredIsolation = 'none';
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
return declaredIsolation;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Applicability + isolation verdict for a SINGLE workspace root. Returns
|
|
407
|
+
* `{ action: 'allow' } | { action: 'deny', reason: string }`. Extracted from
|
|
408
|
+
* resolveIsolationDecision (#3045 finding 1) so every root in a multi-root
|
|
409
|
+
* workspace runs the identical check.
|
|
410
|
+
*/
|
|
411
|
+
function evaluateRootIsolation(root, subagentType, { clock = Date, dispatchIds = null, realpath = fs.realpathSync } = {}) {
|
|
412
|
+
const configPath = path.join(root, '.planning', 'config.json');
|
|
413
|
+
let isGsdProject;
|
|
414
|
+
try {
|
|
415
|
+
fs.accessSync(configPath, fs.constants.F_OK);
|
|
416
|
+
isGsdProject = true;
|
|
417
|
+
} catch {
|
|
418
|
+
isGsdProject = false;
|
|
419
|
+
}
|
|
420
|
+
if (!isGsdProject) return { action: 'allow' };
|
|
421
|
+
|
|
422
|
+
let declaredIsolation;
|
|
423
|
+
try {
|
|
424
|
+
// #3045 BLOCKER fix: a fresh sentinel is authoritative for THIS
|
|
425
|
+
// dispatch's actual resolved isolation — see the doc comment above.
|
|
426
|
+
// #3045 SECURITY F2: a fresh sentinel that names a DIFFERENT
|
|
427
|
+
// plan/phase than this dispatch is not applicable to it — fall through
|
|
428
|
+
// to the conservative fallback exactly as a stale sentinel would.
|
|
429
|
+
const sentinel = readSentinel(root, { clock });
|
|
430
|
+
declaredIsolation = (sentinel.present && !sentinel.stale && sentinelAppliesToDispatch(sentinel, dispatchIds))
|
|
431
|
+
? sentinel.isolation
|
|
432
|
+
: resolveFallbackIsolation(root, configPath);
|
|
433
|
+
} catch {
|
|
434
|
+
return {
|
|
435
|
+
action: 'deny',
|
|
436
|
+
reason:
|
|
437
|
+
`GSD subagent isolation guard: could not read or resolve this project's ` +
|
|
438
|
+
`dispatch-isolation configuration ('.planning/config.json' exists under "${root}"). ` +
|
|
439
|
+
`Refusing to allow this subagent to spawn without being able to verify whether ` +
|
|
440
|
+
`isolation is required — a guard that cannot verify must not answer "safe" (#3050). ` +
|
|
441
|
+
`Retry once the project configuration is readable.`,
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
if (declaredIsolation !== 'harness-worktree') return { action: 'allow' };
|
|
446
|
+
|
|
447
|
+
// isConfirmedNonExecutor already excluded "present, non-empty, unrecognized
|
|
448
|
+
// string" above — reaching here means subagentType is either the confirmed
|
|
449
|
+
// executor or missing/malformed (cannot rule it out).
|
|
450
|
+
if (typeof subagentType !== 'string' || subagentType.length === 0) {
|
|
451
|
+
return {
|
|
452
|
+
action: 'deny',
|
|
453
|
+
reason:
|
|
454
|
+
`GSD subagent isolation guard: this project's dispatch isolation resolves to ` +
|
|
455
|
+
`"harness-worktree", but the subagentStart payload for this dispatch carries no usable ` +
|
|
456
|
+
`subagent_type. Refusing to allow it to spawn without being able to confirm whether it ` +
|
|
457
|
+
`is a GSD executor — a guard that cannot verify must not answer "safe" (#3050).`,
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
const evidence = resolveIsolationEvidence(root, { realpath });
|
|
462
|
+
if (evidence.isolated) return { action: 'allow' };
|
|
463
|
+
if (evidence.notApplicable) return { action: 'allow' };
|
|
464
|
+
|
|
465
|
+
if (evidence.cannotDetermine) {
|
|
466
|
+
return {
|
|
467
|
+
action: 'deny',
|
|
468
|
+
reason:
|
|
469
|
+
`GSD subagent isolation guard: this project's dispatch isolation resolves to ` +
|
|
470
|
+
`"harness-worktree", but whether "${root}" is running in an isolated Cursor worktree ` +
|
|
471
|
+
`could not be determined (git did not respond). Refusing to allow subagent_type=` +
|
|
472
|
+
`"${subagentType}" to spawn without being able to verify isolation — a guard that ` +
|
|
473
|
+
`cannot verify must not answer "safe" (#3050). Retry once git is responsive.`,
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
return {
|
|
478
|
+
action: 'deny',
|
|
479
|
+
reason:
|
|
480
|
+
`GSD subagent isolation guard: this project's dispatch isolation resolves to ` +
|
|
481
|
+
`"harness-worktree", but subagent_type="${subagentType}" is about to spawn in "${root}", ` +
|
|
482
|
+
`which is not an isolated Cursor worktree — it would edit the user's primary checkout ` +
|
|
483
|
+
`directly, with no consent and no warning. Start an isolated session first (the ` +
|
|
484
|
+
`"--worktree" CLI flag or the "/worktree" chat command; Cursor manages these worktrees ` +
|
|
485
|
+
`under "~/.cursor/worktrees/") and retry.`,
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/* istanbul ignore next -- stdin adapter, exercised via spawnSync in tests */
|
|
490
|
+
function main() {
|
|
491
|
+
let raw = '';
|
|
492
|
+
const stdinTimeout = setTimeout(() => {
|
|
493
|
+
process.exit(0);
|
|
494
|
+
}, 10000);
|
|
495
|
+
|
|
496
|
+
process.stdin.setEncoding('utf8');
|
|
497
|
+
process.stdin.on('data', (chunk) => { raw += chunk; });
|
|
498
|
+
process.stdin.on('end', () => {
|
|
499
|
+
clearTimeout(stdinTimeout);
|
|
500
|
+
|
|
501
|
+
let data = null;
|
|
502
|
+
try {
|
|
503
|
+
data = JSON.parse(raw);
|
|
504
|
+
} catch {
|
|
505
|
+
data = null;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
// Resolve the state-reminder context ONCE, up front, so it can ride along
|
|
509
|
+
// with EITHER outcome below (#3045 MINOR: a deny previously dropped this
|
|
510
|
+
// reminder entirely — process.stdout.write for the deny branch returned
|
|
511
|
+
// before the additional_context block ever ran — instead of preserving it
|
|
512
|
+
// alongside the deny; the subagent still benefits from phase/blocker
|
|
513
|
+
// context even when its dispatch is refused).
|
|
514
|
+
let additionalContext = null;
|
|
515
|
+
try {
|
|
516
|
+
const statePath = resolveStatePath(raw);
|
|
517
|
+
const statePresent = fs.existsSync(statePath);
|
|
518
|
+
additionalContext = statePresent ? MSG_PRESENT : MSG_ABSENT;
|
|
519
|
+
} catch {
|
|
520
|
+
additionalContext = null;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
if (data && typeof data === 'object') {
|
|
524
|
+
let decision = { action: 'allow' };
|
|
525
|
+
try {
|
|
526
|
+
decision = resolveIsolationDecision(data);
|
|
527
|
+
} catch {
|
|
528
|
+
// Defense in depth only: every verify-and-deny path above has its own
|
|
529
|
+
// explicit try/catch that resolves to a deny with a distinct reason.
|
|
530
|
+
// Anything reaching here is an unexpected failure outside those paths
|
|
531
|
+
// (e.g. malformed workspace_roots entries) — never crash the hook.
|
|
532
|
+
decision = { action: 'allow' };
|
|
533
|
+
}
|
|
534
|
+
if (decision.action === 'deny') {
|
|
535
|
+
const out = { permission: 'deny', user_message: decision.reason };
|
|
536
|
+
if (additionalContext !== null) out.additional_context = additionalContext;
|
|
537
|
+
process.stdout.write(JSON.stringify(out));
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
process.stdout.write(JSON.stringify(additionalContext !== null ? { additional_context: additionalContext } : {}));
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
if (require.main === module) {
|
|
547
|
+
main();
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
// #3045 MAJOR ("clock seam is dead code" fix): exported so tests can
|
|
551
|
+
// `require()` this module and inject a `clock` (`{now(): number}`) directly
|
|
552
|
+
// per the repo's clock-seam convention, instead of racing real `Date.now()`
|
|
553
|
+
// across a spawned subprocess boundary.
|
|
554
|
+
module.exports = {
|
|
555
|
+
resolveIsolationDecision,
|
|
556
|
+
evaluateRootIsolation,
|
|
557
|
+
resolveFallbackIsolation,
|
|
558
|
+
resolveIsolationEvidence,
|
|
559
|
+
getWorkspaceRoots,
|
|
560
|
+
};
|
|
@@ -92,6 +92,12 @@ const INJECTION_PATTERNS = [
|
|
|
92
92
|
|
|
93
93
|
const ALL_PATTERNS = [...INJECTION_PATTERNS, ...SUMMARISATION_PATTERNS];
|
|
94
94
|
|
|
95
|
+
// #3023: the staged bundle's directory name is runtime-descriptor-driven, so a
|
|
96
|
+
// literal `/<config>/hooks/` fragment cannot reliably identify GSD's own hook
|
|
97
|
+
// scripts. This module lives inside the bundle, so __dirname identifies it by
|
|
98
|
+
// construction. Normalized to forward slashes to match `p` below.
|
|
99
|
+
const OWN_BUNDLE_PREFIX = __dirname.replace(/\\/g, '/').replace(/\/+$/, '') + '/';
|
|
100
|
+
|
|
95
101
|
function isExcludedPath(filePath) {
|
|
96
102
|
const p = filePath.replace(/\\/g, '/');
|
|
97
103
|
return (
|
|
@@ -101,6 +107,7 @@ function isExcludedPath(filePath) {
|
|
|
101
107
|
/CHECKPOINT/i.test(path.basename(p)) ||
|
|
102
108
|
/[/\\](?:security|techsec|injection)[/\\.]/i.test(p) ||
|
|
103
109
|
/security\.cjs$/.test(p) ||
|
|
110
|
+
p.startsWith(OWN_BUNDLE_PREFIX) ||
|
|
104
111
|
p.includes('/.claude/hooks/')
|
|
105
112
|
);
|
|
106
113
|
}
|