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(project-setup): pin shared-only hash + cancel-in-gate + ssh validation + family-wide consent payload
enescd2b490c424c
diff --git a/src/core/project-setup-handlers.ts b/src/core/project-setup-handlers.tsindex 99ad70ab0..76031e7ac 100644--- a/src/core/project-setup-handlers.ts+++ b/src/core/project-setup-handlers.ts@@ -36,15 +36,20 @@ function sanitizeTarget(v: unknown): ProjectSetupTarget | null {rootPath: t.rootPath}if (typeof t.worktreePath === 'string' && t.worktreePath) out.worktreePath = t.worktreePath- const ssh = t.ssh as Record<string, unknown> | undefined- const server = ssh?.server as Record<string, unknown> | undefined- if (- ssh &&- typeof server?.host === 'string' &&- typeof server?.user === 'string' &&- typeof ssh.remoteCwd === 'string' &&- ssh.remoteCwd- ) {+ if (t.ssh !== undefined) {+ // A malformed `ssh` is REJECTED, never stripped: dropping the field would silently downgrade a+ // remote run into a local one, executing the remote project's script on this machine — and+ // against the wrong (local) trust key.+ const ssh = typeof t.ssh === 'object' && t.ssh !== null ? (t.ssh as Record<string, unknown>) : null+ if (!ssh) return null+ const server =+ typeof ssh.server === 'object' && ssh.server !== null ? (ssh.server as Record<string, unknown>) : null+ if (!server) return null+ if (typeof server.host !== 'string' || !server.host) return null+ if (typeof server.user !== 'string' || !server.user) return null+ if (server.port !== undefined && typeof server.port !== 'number') return null+ if (server.identityFile !== undefined && typeof server.identityFile !== 'string') return null+ if (typeof ssh.remoteCwd !== 'string' || !ssh.remoteCwd) return nullout.ssh = {server: {host: server.host,diff --git a/src/core/project-setup-service.test.ts b/src/core/project-setup-service.test.tsindex 909a15077..c5d000955 100644--- a/src/core/project-setup-service.test.ts+++ b/src/core/project-setup-service.test.ts@@ -166,7 +166,13 @@ describe('ProjectSetupService — consent gate', () => {const pending = svc.run(target(), 'setup')await vi.waitFor(() => expect(consentRequests()).toHaveLength(1))const req = consentRequests()[0]- expect(req).toMatchObject({ kind: 'setup', projectName: 'App', script: 'npm ci', previouslyApproved: false })+ expect(req).toMatchObject({+ kind: 'setup',+ projectName: 'App',+ // The dialog is handed the WHOLE family, because that is what one answer approves.+ scripts: { setup: 'npm ci', archive: 'rm -rf node_modules' },+ previouslyApproved: false+ })expect(req.locationLabel).toContain('/proj/app')expect(calls).toHaveLength(0)@@ -184,6 +190,73 @@ describe('ProjectSetupService — consent gate', () => {expect(consentRequests()).toHaveLength(1)})+ it('hashes and shows the SHARED family only — a local override never enters the trust content', async () => {+ const trust = new ProjectTrustStore()+ const { calls, runner } = recorder()+ // The two documents disagree about the family's OTHER script. The merged/effective doc would+ // hash `local-archive`; only the shared doc may be approved.+ const shared: ProjectSettingsDoc = { setup: { setupScript: 'npm ci', archiveScript: 'shared-archive' } }+ const merged: ProjectSettingsDoc = { setup: { setupScript: 'npm ci', archiveScript: 'local-archive' } }+ const svc = new ProjectSetupService({+ trust,+ readSettings: async () => snapshot(sharedFile(shared), { setup: { archiveScript: 'local-archive' } }),+ runLocal: runner+ })+ const pending = svc.run(target(), 'setup')+ await vi.waitFor(() => expect(consentRequests()).toHaveLength(1))+ expect(consentRequests()[0].scripts).toEqual({ setup: 'npm ci', archive: 'shared-archive' })+ svc.submitConsent(consentRequests()[0].requestId, 'approve')+ expect(await pending).toMatchObject({ status: 'started' })+ await vi.waitFor(() => expect(calls).toHaveLength(1))++ const key = localTrustKey('/proj/app')+ const record = await trust.getRecord(key, 'setup')+ expect(record?.contentHash).toBe(hashTrustContent(projectTrustContent('setup', shared)!))+ expect(record?.contentHash).not.toBe(hashTrustContent(projectTrustContent('setup', merged)!))+ })++ it('a local override of a shared script is local-sourced: it runs promptless', async () => {+ const { calls, runner } = recorder()+ const svc = new ProjectSetupService({+ trust: new ProjectTrustStore(),+ readSettings: async () =>+ snapshot(sharedFile({ setup: { setupScript: 'npm ci' } }), { setup: { setupScript: 'my own setup' } }),+ runLocal: runner+ })+ expect(await svc.run(target(), 'setup')).toMatchObject({ status: 'started' })+ await vi.waitFor(() => expect(calls).toHaveLength(1))+ expect(calls[0].script).toBe('my own setup')+ expect(consentRequests()).toEqual([])+ })++ it('cancel while the dialog is open dismisses it, and a late approve cannot revive the run', async () => {+ const trust = new ProjectTrustStore()+ const { calls, runner } = recorder()+ const svc = new ProjectSetupService({+ trust,+ readSettings: async () => snapshot(sharedFile({ setup: { setupScript: 'npm ci' } })),+ runLocal: runner+ })+ const pending = svc.run(target(), 'setup')+ await vi.waitFor(() => expect(consentRequests()).toHaveLength(1))+ const { requestId } = consentRequests()[0]++ expect(svc.cancel(setupRunKey(target(), 'setup'))).toBe(true)+ expect(dismissed()).toEqual([requestId])+ expect(await pending).toEqual({ status: 'skipped', reason: 'declined' })++ svc.submitConsent(requestId, 'approve')+ await vi.waitFor(() => expect(consentRequests()).toHaveLength(1))+ expect(calls).toHaveLength(0)+ expect(await trust.getRecord(localTrustKey('/proj/app'), 'setup')).toBeNull()+ expect(events()).toEqual([])+ // The queue is free again: the next project still gets its dialog.+ const next = svc.run(target({ projectId: 'p2', rootPath: '/b' }), 'setup')+ await vi.waitFor(() => expect(consentRequests()).toHaveLength(2))+ svc.submitConsent(consentRequests()[1].requestId, 'skip')+ await next+ })+it('skip does not run and does not record', async () => {const trust = new ProjectTrustStore()const { calls, runner } = recorder()@@ -271,7 +344,7 @@ describe('ProjectSetupService — consent gate', () => {expect(await second).toEqual({ status: 'skipped', reason: 'declined' })// Both were asked — one after the other, never both at once (the queue order itself is not// part of the contract).- expect(consentRequests().map((r) => r.script).sort()).toEqual(['build p1', 'build p2'])+ expect(consentRequests().map((r) => r.scripts.setup).sort()).toEqual(['build p1', 'build p2'])})it('gates an ssh target on its ssh location key', async () => {@@ -436,6 +509,44 @@ describe('registerProjectSetupHandlers', () => {expect(runs).toHaveLength(1)})+ it('rejects a malformed ssh target instead of stripping it down to a LOCAL run', async () => {+ const { runs } = stub()+ const call = plat.handlers[IPC.projectSetupRun]+ const bad = [+ 'garbage',+ 7,+ { server: { host: 'h' } },+ { server: { host: 'h', user: 'u' } }, // no remoteCwd+ { server: { host: 'h', user: 'u', port: '22' }, remoteCwd: '/srv' },+ { server: { host: 'h', user: 'u', identityFile: 3 }, remoteCwd: '/srv' },+ { server: 'h@u', remoteCwd: '/srv' }+ ]+ for (const ssh of bad) {+ expect(await call({ ...target(), ssh }, 'setup')).toEqual({ status: 'skipped', reason: 'unavailable' })+ }+ expect(runs).toHaveLength(0)+ })++ it('end to end: a malformed ssh target never reaches the local runner', async () => {+ const { calls, runner } = recorder()+ const service = new ProjectSetupService({+ trust: new ProjectTrustStore(),+ readSettings: async () => snapshot(null, { setup: { setupScript: 'echo hi' } }),+ runLocal: runner+ })+ registerProjectSetupHandlers(plat, service)+ const call = plat.handlers[IPC.projectSetupRun]+ expect(await call({ ...target(), ssh: 'garbage' }, 'setup')).toEqual({+ status: 'skipped',+ reason: 'unavailable'+ })+ expect(await call({ ...target(), ssh: { server: { host: 'h' } } }, 'setup')).toEqual({+ status: 'skipped',+ reason: 'unavailable'+ })+ expect(calls).toHaveLength(0)+ })+it('cancel and consent-submit reject junk arguments', async () => {const { cancels, consents } = stub()expect(await plat.handlers[IPC.projectSetupCancel]('k1')).toBe(true)diff --git a/src/core/project-setup-service.ts b/src/core/project-setup-service.tsindex 07a43d9d5..727ca0f03 100644--- a/src/core/project-setup-service.ts+++ b/src/core/project-setup-service.ts@@ -92,6 +92,15 @@ function trustKeyFor(target: ProjectSetupTarget): string {: localTrustKey(target.rootPath)}+/** Exactly the two fields `projectTrustContent('setup', …)` hashes, from the SHARED document — so a+ * dialog rendering this shows the full extent of what one approval covers, and nothing else. */+function familyScripts(sharedDoc: ProjectSettingsDoc): ProjectSetupConsentRequest['scripts'] {+ const out: ProjectSetupConsentRequest['scripts'] = {}+ if (sharedDoc.setup?.setupScript !== undefined) out.setup = sharedDoc.setup.setupScript+ if (sharedDoc.setup?.archiveScript !== undefined) out.archive = sharedDoc.setup.archiveScript+ return out+}+function locationLabel(target: ProjectSetupTarget): string {if (target.ssh) return `${target.ssh.server.user}@${target.ssh.server.host}:${target.ssh.remoteCwd}`const abs = path.resolve(target.rootPath)@@ -106,6 +115,9 @@ interface ActiveRun {abort: AbortControllerseq: numberclosed: boolean+ /** The dialog this run is currently blocked on, so `cancel` can close it instead of leaving a+ * modal up for a run that no longer exists. */+ consentRequestId?: string}export class ProjectSetupService {@@ -152,12 +164,17 @@ export class ProjectSetupService {return abandon('unavailable')}if (!trusted) {- const answer = await this.askConsent(key, {+ const answer = await this.askConsent(entry, key, {kind,projectName: target.projectName,locationLabel: locationLabel(target),- script+ // The FAMILY is what gets approved, so the dialog is handed both scripts — and from the+ // shared document alone, so what it renders is exactly what the hash covers.+ scripts: familyScripts(sharedDoc)})+ // A cancel raised while the dialog was open already aborted this run; it must not proceed+ // on an answer (or a race with one) that arrived anyway.+ if (entry.abort.signal.aborted) return abandon('declined')if (answer !== 'approve') return abandon(answer === 'skip' ? 'declined' : 'unanswered')try {await this.deps.trust.record(key, 'setup', hash, new Date(this.now()).toISOString())@@ -169,15 +186,27 @@ export class ProjectSetupService {}}+ // Covers a cancel raised during any of the awaits above (readSettings, the trust read/write).+ if (entry.abort.signal.aborted) return abandon('declined')+void this.execute(entry, runner, script, target)return { status: 'started', runKey, waitForSetup: resolved.setup.waitForSetup?.value === true }}- /** Aborts a live run. `false` = nothing by that runKey is running (already finished, or never was). */+ /** Aborts a run — live OR still waiting at its consent dialog. `false` = nothing by that runKey+ * exists (already finished, or never did). */cancel(runKey: string): boolean {const entry = this.active.get(runKey)if (!entry) return falseentry.abort.abort()+ const requestId = entry.consentRequestId+ if (requestId) {+ // The run this dialog belonged to is gone: close it (and free the queue) rather than leave a+ // modal whose answer can no longer mean anything. Resolving the pending entry also drops it+ // from `pending`, so a late approve for it is a no-op.+ this.pending.get(requestId)?.(undefined)+ platform().broadcast(IPC.projectSetupConsentDismiss, { requestId })+ }return true}@@ -193,27 +222,34 @@ export class ProjectSetupService {}private askConsent(+ entry: ActiveRun,trustKey: string,req: Omit<ProjectSetupConsentRequest, 'requestId' | 'previouslyApproved'>): Promise<ProjectSetupConsentAnswer | undefined> {const step = this.consentQueue.then(async () => {+ // Cancelled while queued behind another dialog — never raise one for a run that is gone.+ if (entry.abort.signal.aborted) return undefined// Read at PROMPT time, not at enqueue time: an earlier prompt in the queue may have just// recorded an approval for this same location. Dialog copy only — the grant was the// `isTrusted` hash comparison, which already said no.const previouslyApproved = !!(await this.deps.trust.getRecord(trustKey, 'setup'))return new Promise<ProjectSetupConsentAnswer | undefined>((resolve) => {const requestId = randomUUID()- const timer = setTimeout(() => {+ const settle = (answer: ProjectSetupConsentAnswer | undefined): void => {this.pending.delete(requestId)+ entry.consentRequestId = undefined+ resolve(answer)+ }+ const timer = setTimeout(() => {+ settle(undefined) // expired, NOT declinedplatform().broadcast(IPC.projectSetupConsentDismiss, { requestId })- resolve(undefined) // expired, NOT declined}, CONSENT_EXPIRY_MS)timer.unref?.()this.pending.set(requestId, (answer) => {clearTimeout(timer)- this.pending.delete(requestId)- resolve(answer)+ settle(answer)})+ entry.consentRequestId = requestIdconst payload: ProjectSetupConsentRequest = { ...req, requestId, previouslyApproved }platform().broadcast(IPC.projectSetupConsentRequest, payload)})diff --git a/src/shared/project-settings.ts b/src/shared/project-settings.tsindex 7b544c8a7..28b4d1895 100644--- a/src/shared/project-settings.ts+++ b/src/shared/project-settings.ts@@ -340,17 +340,19 @@ export type ProjectTrustFamily = 'setup' | 'agents' | 'shell'/** Which of the setup family's two scripts a run executes. */export type ProjectSetupKind = 'setup' | 'archive'-/** main→renderer: raise the consent dialog for ONE shared-sourced script about to run. Approving- * covers the whole `setup` family (both scripts are hashed together), so `script` is what is about- * to run, not the full extent of what is being approved — the dialog says so. */+/** main→renderer: raise the consent dialog before a shared-sourced script runs. One answer approves+ * the whole `setup` family (both scripts are hashed together), so the payload carries BOTH — a+ * dialog must be able to show everything the approval covers, not just the half about to run. */export interface ProjectSetupConsentRequest {requestId: string+ /** Which script is about to run — the one the dialog highlights. */kind: ProjectSetupKindprojectName: string/** Human-readable location ("~/code/app" or "user@host:/srv/app"). */locationLabel: string- /** The script about to run (the family's OTHER script is covered by the same approval). */- script: string+ /** The family's full executable content, straight from the SHARED document: exactly what the+ * approved hash covers. A field is absent when that script is not set. */+ scripts: { setup?: string; archive?: string }/** A prior approval exists for this family at this location (dialog copy: "changed since you* approved"). Copy only — never a grant; the grant is the hash comparison. */previouslyApproved: boolean