Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
fix(main): close the SSH-kind oracle and make every wrapper branch red-capable (review round 1)
enes2796f6a6ebec
diff --git a/src/main/index.ts b/src/main/index.tsindex 2e6256f82..6e0e3b1c0 100644--- a/src/main/index.ts+++ b/src/main/index.ts@@ -18,16 +18,14 @@ import { pickProjectIcon } from './project-icon-upload'import { allowGuestNavigation } from './webview-nav'import { BrowserControlLedger } from './browser-control-ledger'import {- grant as grantProjectTo,+ recordOpenProjectGrant,isGranted as projectGrantedTo,atCap as projectGrantsAtCap,clearCaller as clearProjectGrants,gateProjectTarget,- validateOpenProjectCwd,+ gateOpenProject,PROJECT_TARGETABLE_VERBS,- OPEN_PROJECT_LOCAL_ONLY,- OPEN_PROJECT_GRANT_CAP,- OPEN_PROJECT_CALLER_UNRESOLVED+ OPEN_PROJECT_GRANT_CAP} from './project-grants'import { BrowserLeaseManager, BrowserSession } from './browser-lease'import { CdpEventBus, type Sendable } from './browser-actions'@@ -3064,20 +3062,24 @@ app.whenReady().then(async () => {if (verb === 'open-project') {const refuse = (error: string) => ({ ok: false, error, message: error })if (!verified) return refuse(OPEN_PROJECT_CONTROL_REFUSAL)+ // The rules themselves are the PURE gateOpenProject (project-grants.ts) — caller-unresolved+ // fail-closed, SSH-caller local-only, cap-before-consent, cwd resolved once — proven+ // red-capable branch by branch in project-grants.test.ts. This wrapper only feeds it main's+ // own stores and returns its refusals unforwarded.const callerProjectId = projectIdOfNode(nodeId)- if (!callerProjectId) return refuse(OPEN_PROJECT_CALLER_UNRESOLVED)- if (workspaceStore.projectMetaFor(callerProjectId)?.ssh) {- // B5: local-only v1 — an SSH-project agent's --cwd would be a host path.- return refuse(OPEN_PROJECT_LOCAL_ONLY)- }- // Refuse the cap BEFORE the renderer would show a dialog (PR 2): a grant that cannot be- // recorded must not be consented to first.- if (projectGrantsAtCap(nodeId)) return refuse(OPEN_PROJECT_GRANT_CAP)- const cwd = validateOpenProjectCwd(args.cwd ?? '', (p) => statSync(p))- if ('error' in cwd) return refuse(cwd.error)+ const gate = gateOpenProject({+ callerProjectId,+ callerIsSsh: callerProjectId+ ? workspaceStore.projectMetaFor(callerProjectId)?.ssh+ : undefined,+ atCap: projectGrantsAtCap(nodeId),+ rawCwd: args.cwd ?? '',+ statFn: (p) => statSync(p)+ })+ if ('refuse' in gate) return refuse(gate.refuse)// The RESOLVED path — never the raw argument — is what the renderer (PR 2's dialog, the// dedupe, the store) sees. Single resolution, in main, right here.- args = { ...args, cwd: cwd.resolved }+ args = { ...args, cwd: gate.resolvedCwd }} else if (PROJECT_TARGETABLE_VERBS.has(verb) && args.project !== undefined) {// Open verbs carrying `--project`: own-or-granted only (spec §3, P2), decided against// main's own store + ledger. Anything else is refused without forwarding.@@ -3136,10 +3138,20 @@ app.whenReady().then(async () => {// carries a non-empty projectId. Inert until PR 2: today the renderer's `default:` case// answers `unknown verb: open-project` with ok: false, so nothing is ever recorded — but the// record path ships fail-closed and finished, not stubbed.- if (verb === 'open-project' && verified && result.ok) {- const opened = result.result as { projectId?: unknown } | undefined- if (typeof opened?.projectId === 'string' && opened.projectId) {- grantProjectTo(nodeId, opened.projectId)+ if (verb === 'open-project') {+ // The whole decision (verified && ok && string projectId → grant; cap race detection) is+ // the PURE recordOpenProjectGrant — proven branch by branch in project-grants.test.ts.+ // 'cap' = the pre-forward atCap() check passed but a concurrent open-project from the same+ // caller filled the last slot while this one was in flight (PR #362 review, M1): the+ // caller must NOT hear ok while holding no targeting right, so the named refusal replaces+ // the success reply. Nothing is lost — open-project is idempotent (B1), so a re-run once+ // grants have cleared returns the same project id and records the grant.+ if (recordOpenProjectGrant(nodeId, result, verified) === 'cap') {+ console.warn(+ `[project-grants] grant cap raced for caller ${nodeId}: open-project succeeded but ` ++ 'the grant was not recorded; replying open-project-grant-cap'+ )+ return { ok: false, error: OPEN_PROJECT_GRANT_CAP, message: OPEN_PROJECT_GRANT_CAP }}}return resultdiff --git a/src/main/project-grants.test.ts b/src/main/project-grants.test.tsindex 19414c323..e8c544472 100644--- a/src/main/project-grants.test.ts+++ b/src/main/project-grants.test.ts@@ -20,12 +20,17 @@ import {clearCaller,clearAll,gateProjectTarget,+ gateOpenProject,+ recordOpenProjectGrant,validateOpenProjectCwd,PROJECT_TARGETABLE_VERBS,PROJECT_TARGETING_REFUSAL,PROJECT_TARGET_REFUSED,PROJECT_TARGET_SSH_UNSUPPORTED,- OPEN_PROJECT_CWD_INVALID+ OPEN_PROJECT_CWD_INVALID,+ OPEN_PROJECT_LOCAL_ONLY,+ OPEN_PROJECT_CALLER_UNRESOLVED,+ OPEN_PROJECT_GRANT_CAP} from './project-grants'beforeEach(() => clearAll())@@ -139,11 +144,41 @@ describe('gateProjectTarget (spec §3/§5) — every branch, fail closed', () =>).toBe('allow')})- it('refuses an SSH target that is not the caller own project — even a (impossible) granted one', () => {- // Grants are only ever minted by local open-project, so a granted SSH id cannot exist; the- // SSH check running BEFORE the granted check is the belt for that invariant.+ it('allows OWN even when the meta lookup misses — own-before-unknown (review M2)', () => {+ // callerProjectId and the target meta derive from the same index scan, but if a rename+ // mid-debounce ever staggered the two read paths, a legitimate `--project <own-id>` must not+ // be spuriously refused as unknown. Still fail-closed: the id IS the caller's own project by+ // main's own caller resolution.+ expect(+ gateProjectTarget({ ...base, targetProjectId: 'proj-own', targetIsSsh: undefined })+ ).toBe('allow')+ })++ it('refuses every stranger id with byte-identical text — no existence OR kind oracle (review I3)', () => {+ // unknown, real-local-ungranted and real-SSH-ungranted must be indistinguishable to a caller+ // with no relationship to the id. Byte-for-byte, not toEqual: the property is that the WIRE+ // BYTES leak nothing.+ const refuseOf = (r: ReturnType<typeof gateProjectTarget>): string =>+ r === 'allow' ? '' : r.refuse+ const unknown = refuseOf(gateProjectTarget({ ...base, targetIsSsh: undefined }))+ const localUngranted = refuseOf(gateProjectTarget({ ...base, targetIsSsh: false }))+ const sshUngranted = refuseOf(gateProjectTarget({ ...base, targetIsSsh: true }))+ expect(unknown).toBe(PROJECT_TARGET_REFUSED)+ expect(Buffer.from(localUngranted).equals(Buffer.from(unknown))).toBe(true)+ expect(Buffer.from(sshUngranted).equals(Buffer.from(unknown))).toBe(true)+ })++ it('the SSH belt refuses a granted SSH id — and only a grant holder ever sees that wording', () => {+ // Grants are only ever minted by local open-project, so a granted SSH id cannot exist; if+ // that invariant ever breaks, the target is refused, not opened. The kind-naming wording is+ // harmless here — a grant holder was handed the id by open-project — and is reachable ONLY+ // through the granted branch (the stranger case above gets PROJECT_TARGET_REFUSED).const r = gateProjectTarget({ ...base, targetIsSsh: true, granted: true })expect(r).toEqual({ refuse: PROJECT_TARGET_SSH_UNSUPPORTED })+ // A granted id whose project has since vanished still fails closed as a stranger.+ expect(gateProjectTarget({ ...base, targetIsSsh: undefined, granted: true })).toEqual({+ refuse: PROJECT_TARGET_REFUSED+ })})it('allows a granted target and refuses an ungranted one with the named sentence', () => {@@ -205,6 +240,98 @@ describe('validateOpenProjectCwd (P7) — resolved once, statted once, fails clo})})+describe('gateOpenProject — every pre-forward branch, behaviorally red-capable (review I1/I2)', () => {+ const dirStat = { isDirectory: () => true }+ const base = {+ callerProjectId: 'proj-own' as string | undefined,+ callerIsSsh: false as boolean | undefined,+ atCap: false,+ rawCwd: '/tmp/repo',+ statFn: () => dirStat+ }++ it('refuses an unresolvable caller with the transient named error, before anything else', () => {+ // A node inside the save debounce is not in any persisted project yet: fail closed (GC 10),+ // worded transient because it genuinely is. No stat runs — the request goes nowhere.+ let stats = 0+ const r = gateOpenProject({+ ...base,+ callerProjectId: undefined,+ // Even a hostile combination (SSH + cap) must not change which refusal fires first.+ callerIsSsh: true,+ atCap: true,+ statFn: () => ((stats++, dirStat))+ })+ expect(r).toEqual({ refuse: OPEN_PROJECT_CALLER_UNRESOLVED })+ expect(stats).toBe(0)+ })++ it('refuses an SSH-project caller with open-project-local-only (B5)', () => {+ expect(gateOpenProject({ ...base, callerIsSsh: true })).toEqual({+ refuse: OPEN_PROJECT_LOCAL_ONLY+ })+ })++ it('refuses at the grant cap BEFORE the cwd is ever touched (no consent could follow)', () => {+ let stats = 0+ const r = gateOpenProject({ ...base, atCap: true, statFn: () => ((stats++, dirStat)) })+ expect(r).toEqual({ refuse: OPEN_PROJECT_GRANT_CAP })+ expect(stats).toBe(0)+ })++ it('composes with the real ledger cap and the real cwd rules', () => {+ for (let i = 0; i < GRANT_CAP; i++) grant('caller-a', `proj-${i}`)+ expect(gateOpenProject({ ...base, atCap: atCap('caller-a') })).toEqual({+ refuse: OPEN_PROJECT_GRANT_CAP+ })+ expect(gateOpenProject({ ...base, atCap: atCap('caller-b'), rawCwd: 'not/absolute' })).toEqual(+ { refuse: OPEN_PROJECT_CWD_INVALID }+ )+ })++ it('passes a clean request through with the RESOLVED cwd (P7)', () => {+ const statted: string[] = []+ const r = gateOpenProject({+ ...base,+ rawCwd: '/tmp/a/../repo/',+ statFn: (p) => ((statted.push(p), dirStat))+ })+ expect(r).toEqual({ resolvedCwd: path.resolve('/tmp/a/../repo/') })+ expect(statted).toEqual([path.resolve('/tmp/a/../repo/')])+ })+})++describe('recordOpenProjectGrant — the record decision, behaviorally (P2 record-side + review M1)', () => {+ const okReply = { ok: true, result: { projectId: 'proj-new' } }++ it('records ONLY under verified && ok && non-empty string projectId — the open-browser pattern', () => {+ // The four fail-closed legs first: none of these may mint anything.+ expect(recordOpenProjectGrant('caller-a', okReply, false)).toBe('not-applicable')+ expect(recordOpenProjectGrant('caller-a', { ok: false, result: { projectId: 'proj-new' } }, true)).toBe('not-applicable')+ expect(recordOpenProjectGrant('caller-a', { ok: true, result: {} }, true)).toBe('not-applicable')+ expect(recordOpenProjectGrant('caller-a', { ok: true, result: { projectId: '' } }, true)).toBe('not-applicable')+ expect(recordOpenProjectGrant('caller-a', { ok: true, result: { projectId: 42 } }, true)).toBe('not-applicable')+ expect(isGranted('caller-a', 'proj-new')).toBe(false)+ // The one leg that mints — and only for THIS caller.+ expect(recordOpenProjectGrant('caller-a', okReply, true)).toBe('recorded')+ expect(isGranted('caller-a', 'proj-new')).toBe(true)+ expect(isGranted('caller-b', 'proj-new')).toBe(false)+ })++ it("answers 'cap' when a concurrent open-project filled the last slot — nothing recorded", () => {+ // The M1 race: both requests passed the pre-forward atCap() check; the loser's grant() call+ // is the first place the collision is visible, and the wrapper turns 'cap' into the named+ // refusal instead of relaying ok (a caller must never hear ok while holding no right).+ for (let i = 0; i < GRANT_CAP; i++) grant('caller-a', `proj-${i}`)+ expect(recordOpenProjectGrant('caller-a', okReply, true)).toBe('cap')+ expect(isGranted('caller-a', 'proj-new')).toBe(false)+ // An id already granted re-records fine at the cap (idempotent, no new slot).+ expect(+ recordOpenProjectGrant('caller-a', { ok: true, result: { projectId: 'proj-0' } }, true)+ ).toBe('recorded')+ })+})+describe('main wiring (structural) — the wrapper records, consumes and clears correctly', () => {// Structural in the control-destructive.test.ts sense and for the same reason: the wiring lives// inside index.ts's setControlHandler wrapper and whenReady closure, which have no unit seam,@@ -213,14 +340,36 @@ describe('main wiring (structural) — the wrapper records, consumes and clears// the real functions.const src = fs.readFileSync(path.join(__dirname, 'index.ts'), 'utf8')- it('records a grant ONLY under verified && result.ok with a string projectId (the open-browser pattern)', () => {- const at = src.indexOf("verb === 'open-project' && verified && result.ok")- expect(at).toBeGreaterThan(-1)- const block = src.slice(at, at + 400)- expect(block).toContain("typeof opened?.projectId === 'string'")- expect(block).toContain('grantProjectTo(nodeId, opened.projectId)')- // No other call site mints a grant: the record path is the wrapper's, once.- expect(src.match(/grantProjectTo\(/g)?.length).toBe(1)+ it('the record path is the pure recordOpenProjectGrant, called once, with the cap race surfaced', () => {+ // The record RULES (verified && ok && string projectId; per-caller; 'cap' on the race) are+ // proven behaviorally above against the real function. Here: the wrapper routes the reply+ // through that function exactly once, with main's own verdict, and a 'cap' answer replaces+ // the success reply with the named refusal (review M1 — no ok without a recorded right).+ expect(src.match(/recordOpenProjectGrant\(/g)?.length).toBe(1)+ expect(src).toMatch(+ /if \(recordOpenProjectGrant\(nodeId, result, verified\) === 'cap'\) \{/+ )+ const at = src.indexOf("recordOpenProjectGrant(nodeId, result, verified) === 'cap'")+ const block = src.slice(at, src.indexOf('return result', at))+ expect(block).toContain('error: OPEN_PROJECT_GRANT_CAP')+ // No raw grant() call sneaks around the pure decision anywhere in main's entry.+ expect(src).not.toMatch(/\bgrantProjectTo\(|[^A-Za-z]grant\(nodeId/)+ })++ it('every open-project is routed through the pure gateOpenProject before forwarding (I1/I2)', () => {+ // The branches themselves (caller-unresolved, SSH caller, cap, cwd) are proven behaviorally+ // above; this pins that the wrapper cannot bypass them — the gate call sits inside the+ // open-project arm, its refusal returns unforwarded, and its resolved cwd is what forwards.+ const arm = src.indexOf("if (verb === 'open-project') {")+ expect(arm).toBeGreaterThan(-1)+ const block = src.slice(arm, src.indexOf('} else if (PROJECT_TARGETABLE_VERBS', arm))+ expect(block).toContain('gateOpenProject({')+ expect(block).toContain("if ('refuse' in gate) return refuse(gate.refuse)")+ expect(block).toContain('args = { ...args, cwd: gate.resolvedCwd }')+ // Its inputs come from main's own stores, never the request.+ expect(block).toMatch(/callerProjectId: projectIdOfNode\(nodeId\)|callerProjectId,/)+ expect(block).toContain('workspaceStore.projectMetaFor(callerProjectId)?.ssh')+ expect(block).toContain('atCap: projectGrantsAtCap(nodeId)')})it('consumes the ledger per-CALLER and gates before forwarding to the renderer', () => {@@ -245,9 +394,10 @@ describe('main wiring (structural) — the wrapper records, consumes and clears})it('open-project resolves + replaces the cwd in MAIN before forwarding (P7)', () => {- const at = src.indexOf('validateOpenProjectCwd(args.cwd')+ // The resolution itself lives in gateOpenProject → validateOpenProjectCwd (proven above);+ // here: the raw caller cwd enters the gate and only the gate's resolved form is forwarded.+ const at = src.indexOf('rawCwd: args.cwd')expect(at).toBeGreaterThan(-1)- // The resolved form replaces the raw argument in the forwarded args.- expect(src.slice(at, at + 400)).toContain('args = { ...args, cwd: cwd.resolved }')+ expect(src.slice(at, at + 400)).toContain('args = { ...args, cwd: gate.resolvedCwd }')})})diff --git a/src/main/project-grants.ts b/src/main/project-grants.tsindex c06658b41..623cf5dc1 100644--- a/src/main/project-grants.ts+++ b/src/main/project-grants.ts@@ -73,14 +73,22 @@ export const PROJECT_TARGETABLE_VERBS: ReadonlySet<string> = new Set([export const PROJECT_TARGETING_REFUSAL = 'Project targeting refused.'/** The named refusal for an id that is neither the caller's own project nor granted. Also the- * answer for an id main's store does not know: refusing unknown ids with the SAME sentence keeps- * this from becoming a project-existence oracle. */+ * answer for an id main's store does not know, AND for an ungranted id that happens to name an+ * SSH project: every id the caller has no relationship to refuses with these SAME BYTES, so the+ * gate is neither a project-existence oracle nor a project-KIND oracle (PR #362 review, I3 —+ * the earlier distinct SSH wording let a verified caller learn "this id is a real SSH project"+ * with no grant). */export const PROJECT_TARGET_REFUSED ='project-target-refused: you may only target your own project or a project id open-project ' +'returned to you in this session'-/** Targeting an SSH project (other than the caller's own, which takes the legacy live path) is- * not v1 (spec B5/§6): the nodes would need host-side materialization this feature defers. */+/** Targeting an SSH project is not v1 (spec B5/§6): the nodes would need host-side+ * materialization this feature defers. Shown ONLY to a caller that already holds a GRANT for+ * the id (where disclosing the project's kind is harmless — the caller was handed the id by+ * open-project). A caller with no relationship to an SSH id gets PROJECT_TARGET_REFUSED like+ * every other stranger, see above. Today this constant is pure belt: grants are only minted by+ * local open-project, so a granted SSH id cannot exist — but if that invariant ever breaks,+ * the target must still be refused, not opened. */export const PROJECT_TARGET_SSH_UNSUPPORTED ='project-target-ssh-unsupported: opening sessions into an SSH project is not supported — do not retry'@@ -113,10 +121,19 @@ export type ProjectTargetGate = 'allow' | { refuse: string }* `granted` from this module's ledger. Nothing is read off the request except the target id* being judged.*- * Branch order is load-bearing: unknown-target refuses before the own-project allow (a project- * main cannot resolve is not provably anyone's own), and the SSH refusal runs before the granted- * allow (grants are only minted by local open-project, so a granted SSH id cannot exist — this is- * the belt for that invariant).+ * Branch order is load-bearing:+ * - the OWN-project allow runs before the unknown-target refusal (PR #362 review, M2): both+ * `callerProjectId` and the target meta derive from the same index scan, but if a rename+ * mid-debounce ever let `persistedCanvases` resolve the caller one tick before+ * `projectMetaFor` finds the entry, the caller's legitimate `--project <own-id>` must not be+ * spuriously refused as unknown. Allowing OWN on the caller-resolution alone is still+ * fail-closed — the id equals the caller's own project in main's own store;+ * - every id the caller has NO relationship to (unknown, local-ungranted, SSH-ungranted)+ * refuses with the byte-identical PROJECT_TARGET_REFUSED (review I3 — no kind oracle);+ * - the SSH refusal sits INSIDE the granted allow as pure belt: a granted SSH id cannot exist+ * (grants are only minted by local open-project), but if that invariant ever breaks the+ * target is refused, not opened — and only there is the kind-naming wording harmless, because+ * a grant holder was handed the id by open-project.*/export function gateProjectTarget(input: {verified: boolean@@ -130,13 +147,67 @@ export function gateProjectTarget(input: {if (!PROJECT_TARGETABLE_VERBS.has(verb)) return 'allow'if (targetProjectId === undefined) return 'allow'if (verified !== true) return { refuse: PROJECT_TARGETING_REFUSAL }- if (targetIsSsh === undefined) return { refuse: PROJECT_TARGET_REFUSED }if (callerProjectId !== undefined && targetProjectId === callerProjectId) return 'allow'- if (targetIsSsh) return { refuse: PROJECT_TARGET_SSH_UNSUPPORTED }- if (granted) return 'allow'+ if (granted && targetIsSsh !== undefined) {+ if (targetIsSsh) return { refuse: PROJECT_TARGET_SSH_UNSUPPORTED }+ return 'allow'+ }return { refuse: PROJECT_TARGET_REFUSED }}+/**+ * The whole record-side decision for a finished `open-project` request (spec §3 "recorded", made+ * pure in the PR #362 fix round so the cap race — review M1 — is behaviorally testable).+ * `'recorded'` = the grant now exists; `'not-applicable'` = the reply mints nothing (not ok, not+ * verified, or no usable projectId — all fail closed); `'cap'` = the reply LOOKED grantable but a+ * concurrent open-project from the same caller filled the last slot while this one was in flight+ * (the pre-forward `atCap` check passed for both). On `'cap'` the wrapper must NOT relay the+ * success reply — the caller would hear ok while holding no targeting right — it answers+ * OPEN_PROJECT_GRANT_CAP instead; nothing is lost, because open-project is idempotent (B1) and a+ * re-run after grants clear returns the same id and records the grant.+ */+export function recordOpenProjectGrant(+ callerNodeId: string,+ reply: { ok: boolean; result?: unknown },+ verified: boolean+): 'recorded' | 'not-applicable' | 'cap' {+ if (verified !== true || reply.ok !== true) return 'not-applicable'+ const projectId = (reply.result as { projectId?: unknown } | undefined)?.projectId+ if (typeof projectId !== 'string' || !projectId) return 'not-applicable'+ return grant(callerNodeId, projectId) === 'cap' ? 'cap' : 'recorded'+}++/**+ * The whole main-side pre-forward gate for an `open-project` request (issue #338 Task 1.4, made+ * pure in the PR #362 fix round — review I1/I2 proved the SSH-caller and unresolved-caller+ * branches had no red-capable coverage while they lived inline in index.ts's wrapper). The+ * wrapper resolves the inputs from main's own stores (caller project by node membership in+ * `persistedCanvases`, SSH-ness via `projectMetaFor`, the cap from this module's ledger) and+ * routes EVERY open-project through here; a `refuse` answer is returned to the caller without+ * anything being forwarded to the renderer, so no dialog can be shown (PR 2) and no grant can be+ * minted for a request that failed these rules.+ *+ * Branch order: caller-unresolved (fail closed per GC 10 — a node inside the save debounce, the+ * one transient refusal here) → SSH caller (B5 local-only) → cap (refused BEFORE any consent+ * could be collected) → cwd validation (P7, resolved once). Identity is NOT re-checked here: the+ * hook-server's `requiresVerified` refuses an unverified open-project before any handler, and+ * the wrapper keeps its own belt in front of this call.+ */+export function gateOpenProject(input: {+ callerProjectId: string | undefined+ callerIsSsh: boolean | undefined+ atCap: boolean+ rawCwd: string+ statFn: (p: string) => { isDirectory(): boolean }+}): { resolvedCwd: string } | { refuse: string } {+ if (input.callerProjectId === undefined) return { refuse: OPEN_PROJECT_CALLER_UNRESOLVED }+ if (input.callerIsSsh) return { refuse: OPEN_PROJECT_LOCAL_ONLY }+ if (input.atCap) return { refuse: OPEN_PROJECT_GRANT_CAP }+ const cwd = validateOpenProjectCwd(input.rawCwd, input.statFn)+ if ('error' in cwd) return { refuse: cwd.error }+ return { resolvedCwd: cwd.resolved }+}+/*** Validate + normalize an `open-project --cwd` argument (spec §2.1 step 1, P7). The caller's path* is hostile input: it must be absolute, is resolved ONCE (`path.resolve` collapses `..`/`.`),