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
refactor(secrets): share storage backends
Darren Kattanbfc1f0467c90
diff --git a/src/core/github/credentials.ts b/src/core/github/credentials.tsindex e37dd04f9..0115a4b1a 100644--- a/src/core/github/credentials.ts+++ b/src/core/github/credentials.ts@@ -5,6 +5,7 @@ import type {} from '../../shared/github-issues'import { execFile } from 'node:child_process'import { promisify } from 'node:util'+import type { SecretStore } from '../secret-store'export type CommandResult = { ok: boolean; stdout: string; stderr: string }export type CommandRunner = (command: string, args: string[]) => Promise<CommandResult>@@ -33,11 +34,8 @@ export const runGitHubCliCommand: CommandRunner = async (command, args) => {}}-export interface GitHubSecretStore {+export interface GitHubSecretStore extends SecretStore {readonly availability: GitHubSecretAvailability- readForHost(): Promise<string | null>- save(token: string): Promise<void>- clear(): Promise<void>}export interface ValidatedGitHubIdentity {diff --git a/src/core/secret-store.ts b/src/core/secret-store.tsnew file mode 100644index 000000000..7227d8a1c--- /dev/null+++ b/src/core/secret-store.ts@@ -0,0 +1,7 @@+/** Minimal secret-storage contract shared by feature-specific credential services. */+export interface SecretStore {+ readonly availability: 'encrypted' | 'restricted-file' | 'unavailable'+ readForHost(): Promise<string | null>+ save(secret: string): Promise<void>+ clear(): Promise<void>+}diff --git a/src/main/github-control.test.ts b/src/main/github-control.test.tsindex e2c27c71c..fa9b3e46c 100644--- a/src/main/github-control.test.ts+++ b/src/main/github-control.test.ts@@ -6,6 +6,7 @@ import { vi } from 'vitest'import { IPC } from '../shared/ipc'import {ElectronGitHubSecretStore,+ ElectronSecretStore,registerElectronGitHubControl,type SafeStorageLike} from './github-control'@@ -31,6 +32,19 @@ function safeStorage(options: { available?: boolean; backend?: string } = {}): S}describe('ElectronGitHubSecretStore', () => {+ it('keeps feature-specific secret files isolated while sharing storage semantics', async () => {+ const github = new ElectronGitHubSecretStore(userDataDir, safeStorage())+ const gateway = new ElectronSecretStore(userDataDir, safeStorage(), 'model-gateway-key.json')+ await github.save('github-secret')+ await gateway.save('gateway-secret')++ expect(await github.readForHost()).toBe('github-secret')+ expect(await gateway.readForHost()).toBe('gateway-secret')+ expect(await fs.readdir(userDataDir)).toEqual(+ expect.arrayContaining(['github-issues-token.json', 'model-gateway-key.json'])+ )+ })+it('encrypts a token and reads it only inside the host', async () => {const store = new ElectronGitHubSecretStore(userDataDir, safeStorage())await store.save('github_pat_secret')diff --git a/src/main/github-control.ts b/src/main/github-control.tsindex 3e6ad74de..75289683e 100644--- a/src/main/github-control.ts+++ b/src/main/github-control.ts@@ -1,6 +1,7 @@import { promises as fs } from 'node:fs'import path from 'node:path'import type { GitHubSecretStore } from '../core/github/credentials'+import type { SecretStore } from '../core/secret-store'import type { GitHubSecretAvailability } from '../shared/github-issues'import { IPC } from '../shared/ipc'import type { GitHubHostController } from '../core/github/host'@@ -18,7 +19,7 @@ type TokenDocument =| { version: 1; kind: 'safe-storage'; value: string }| { version: 1; kind: 'restricted-file'; token: string }-export class GitHubSecretError extends Error {+export class SecretStoreError extends Error {constructor(readonly code: 'invalid-token' | 'keyring-locked') {super(code)}@@ -88,7 +89,10 @@ async function atomicWrite(file: string, document: TokenDocument): Promise<void>await fs.chmod(file, 0o600)}-export class ElectronGitHubSecretStore implements GitHubSecretStore {+/** Generic Electron secret store: safeStorage ciphertext when a real OS keyring is available,+ * otherwise an owner-only file. GitHub and the model gateway use distinct file names but share+ * the exact same validation, atomic-write, locked-keyring, and stale-temp behavior. */+export class ElectronSecretStore implements SecretStore {/** Mutations run FIFO (the WorkspaceStore.saveChain idiom): a clear's rm must never land inside* an in-flight save's write-to-rename window — the parked rename would resurrect the PAT the* UI just reported cleared — and save's read-modify-write of the document kind stays@@ -97,7 +101,8 @@ export class ElectronGitHubSecretStore implements GitHubSecretStore {constructor(private readonly userDataDir: string,- private readonly safeStorage: SafeStorageLike+ private readonly safeStorage: SafeStorageLike,+ private readonly fileName: string) {}private chained<T>(fn: () => Promise<T>): Promise<T> {@@ -111,7 +116,7 @@ export class ElectronGitHubSecretStore implements GitHubSecretStore {}private get filePath(): string {- return path.join(this.userDataDir, FILE_NAME)+ return path.join(this.userDataDir, this.fileName)}save(token: string): Promise<void> {@@ -119,10 +124,10 @@ export class ElectronGitHubSecretStore implements GitHubSecretStore {}private async saveNow(token: string): Promise<void> {- if (!validToken(token)) throw new GitHubSecretError('invalid-token')+ if (!validToken(token)) throw new SecretStoreError('invalid-token')const current = await this.readDocument()if (current?.kind === 'safe-storage' && !this.canEncrypt()) {- throw new GitHubSecretError('keyring-locked')+ throw new SecretStoreError('keyring-locked')}const document: TokenDocument = this.canEncrypt()? {@@ -183,6 +188,12 @@ export class ElectronGitHubSecretStore implements GitHubSecretStore {}}+export class ElectronGitHubSecretStore extends ElectronSecretStore implements GitHubSecretStore {+ constructor(userDataDir: string, safeStorage: SafeStorageLike) {+ super(userDataDir, safeStorage, FILE_NAME)+ }+}+export class GitHubControlAccessError extends Error {readonly code = 'E_FORBIDDEN'diff --git a/src/server/github-control.test.ts b/src/server/github-control.test.tsindex 17dd09b25..106982880 100644--- a/src/server/github-control.test.ts+++ b/src/server/github-control.test.ts@@ -4,7 +4,11 @@ import os from 'node:os'import path from 'node:path'import { IPC } from '../shared/ipc'import { ServerPlatform } from './platform-server'-import { registerServerGitHubControl, ServerGitHubSecretStore } from './github-control'+import {+ registerServerGitHubControl,+ ServerGitHubSecretStore,+ ServerSecretStore+} from './github-control'let userDataDir: string@@ -18,6 +22,19 @@ afterEach(async () => {})describe('ServerGitHubSecretStore', () => {+ it('keeps feature-specific owner-only secret files isolated', async () => {+ const github = new ServerGitHubSecretStore(userDataDir)+ const gateway = new ServerSecretStore(userDataDir, 'model-gateway-key.json')+ await github.save('github-secret')+ await gateway.save('gateway-secret')++ expect(await github.readForHost()).toBe('github-secret')+ expect(await gateway.readForHost()).toBe('gateway-secret')+ expect((await fs.stat(path.join(userDataDir, 'model-gateway-key.json'))).mode & 0o777).toBe(+ 0o600+ )+ })+it('stores the token atomically at mode 0600 and reports restricted storage', async () => {const store = new ServerGitHubSecretStore(userDataDir)await store.save('github_pat_secret')diff --git a/src/server/github-control.ts b/src/server/github-control.tsindex 5c20578df..b2b49e4a2 100644--- a/src/server/github-control.ts+++ b/src/server/github-control.ts@@ -1,13 +1,14 @@import { promises as fs } from 'node:fs'import path from 'node:path'import type { GitHubSecretStore } from '../core/github/credentials'+import type { SecretStore } from '../core/secret-store'import type { CorePlatform } from '../core/platform'import type { GitHubHostController } from '../core/github/host'import { IPC } from '../shared/ipc'const FILE_NAME = 'github-issues-token.json'-export class ServerGitHubSecretError extends Error {+export class ServerSecretStoreError extends Error {constructor(readonly code: 'invalid-token') {super(code)}@@ -53,7 +54,9 @@ async function sweepStaleTmp(target: string): Promise<void> {}}-export class ServerGitHubSecretStore implements GitHubSecretStore {+/** Generic headless secret store. Server Edition has no OS keyring, so callers receive the same+ * owner-only atomic file semantics instead of copying the GitHub token implementation. */+export class ServerSecretStore implements SecretStore {readonly availability = 'restricted-file' as const/** Mutations run FIFO (the WorkspaceStore.saveChain idiom): a clear's rm must never land inside@@ -61,7 +64,10 @@ export class ServerGitHubSecretStore implements GitHubSecretStore {* UI just reported cleared. Each caller still sees only its own mutation's failure. */private chain: Promise<unknown> = Promise.resolve()- constructor(private readonly userDataDir: string) {}+ constructor(+ private readonly userDataDir: string,+ private readonly fileName: string+ ) {}private chained<T>(fn: () => Promise<T>): Promise<T> {const run = this.chain.then(fn)@@ -70,7 +76,7 @@ export class ServerGitHubSecretStore implements GitHubSecretStore {}private get filePath(): string {- return path.join(this.userDataDir, FILE_NAME)+ return path.join(this.userDataDir, this.fileName)}save(token: string): Promise<void> {@@ -78,7 +84,7 @@ export class ServerGitHubSecretStore implements GitHubSecretStore {}private async saveNow(token: string): Promise<void> {- if (!validToken(token)) throw new ServerGitHubSecretError('invalid-token')+ if (!validToken(token)) throw new ServerSecretStoreError('invalid-token')await fs.mkdir(this.userDataDir, { recursive: true })await sweepStaleTmp(this.filePath)// The store's per-instance chain orders this write against its sibling mutations; the per-call@@ -126,6 +132,12 @@ export class ServerGitHubSecretStore implements GitHubSecretStore {}}+export class ServerGitHubSecretStore extends ServerSecretStore implements GitHubSecretStore {+ constructor(userDataDir: string) {+ super(userDataDir, FILE_NAME)+ }+}+type Controller = Pick<GitHubHostController,'status' | 'approve' | 'revoke' | 'selectProvider' | 'saveToken' | 'clearToken'>