Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

refactor(console): call an agent's working directory its workdir

Petr Bauchd3843e59744f
diff --git a/console/apps/switch-console-desktop/src/main/core/agents/add-agent.test.ts b/console/apps/switch-console-desktop/src/main/core/agents/add-agent.test.ts
index cd31ca8a4..777dd23c4 100644
--- a/console/apps/switch-console-desktop/src/main/core/agents/add-agent.test.ts
+++ b/console/apps/switch-console-desktop/src/main/core/agents/add-agent.test.ts
@@ -28,7 +28,7 @@ function fakeFs(seed: Record<string, string> = {}): PluginFs {
const h = vi.hoisted(() => {
const writeDefinition = vi.fn(async () => {});
// A faithful-enough stand-in for a repo-agents provider: the config sync
- // renders the definition and writes it through the workspace fs, so the mock
+ // renders the definition and writes it through the workdir fs, so the mock
// has to answer where it goes and what it looks like.
const repoAgents = {
writeDefinition,
@@ -40,11 +40,11 @@ const h = vi.hoisted(() => {
readDefinition: async () => null,
};
const state: {
- workspace: PluginFs | null;
+ workdir: PluginFs | null;
repoAgents: object | null;
nameTaken: boolean;
} = {
- workspace: null,
+ workdir: null,
repoAgents,
nameTaken: false,
};
@@ -67,9 +67,9 @@ vi.mock('@main/core/providers/plugin-registry', () => ({
}));
vi.mock('./register-agent-identity', () => ({ registerAgentIdentity: h.registerAgentIdentity }));
vi.mock('./createAgent', () => ({ createAgent: h.createAgent }));
-vi.mock('./agent-workspace-fs', () => ({
- resolveWorkspaceFsFor: vi.fn(async () => ({
- fs: h.state.workspace as PluginFs,
+vi.mock('./agent-workdir-fs', () => ({
+ resolveWorkdirFsFor: vi.fn(async () => ({
+ fs: h.state.workdir as PluginFs,
close: vi.fn(),
})),
}));
@@ -141,7 +141,7 @@ describe('addAgent', () => {
vi.clearAllMocks();
h.state.nameTaken = false;
h.state.repoAgents = h.repoAgents;
- h.state.workspace = fakeFs();
+ h.state.workdir = fakeFs();
h.registerAgentIdentity.mockResolvedValue({ kind: 'created', id: 'sw-1', apiKey: 'tok-123' });
// `clearAllMocks` resets call records but not implementations: without a
// default, whichever test last set one decides the answer for the rest.
@@ -187,7 +187,7 @@ describe('addAgent', () => {
// unconditional it got no credentials on disk at all, so its sessions
// authenticated to Switch as whatever was in settings.local.json.
h.state.repoAgents = null;
- const fs = h.state.workspace as PluginFs;
+ const fs = h.state.workdir as PluginFs;
const result = await addAgent(params());
@@ -201,7 +201,7 @@ describe('addAgent', () => {
});
it('writes both credentials and an on-disk definition for a repo-agents provider', async () => {
- const fs = h.state.workspace as PluginFs;
+ const fs = h.state.workdir as PluginFs;
await addAgent(params({ providerId: 'claude', name: 'cc-hoot' }));
@@ -212,7 +212,7 @@ describe('addAgent', () => {
});
it('records the agent’s instructions in its committed config file', async () => {
- const fs = h.state.workspace as PluginFs;
+ const fs = h.state.workdir as PluginFs;
await addAgent(params({ providerId: 'claude', name: 'cc-hoot', instructions: 'Be careful.' }));
@@ -223,7 +223,7 @@ describe('addAgent', () => {
});
it('git-ignores the credentials directory so the token never enters VCS', async () => {
- const fs = h.state.workspace as PluginFs;
+ const fs = h.state.workdir as PluginFs;
await addAgent(params());
expect(await fs.read('.switch/agents/.gitignore')).toBe('*\n');
});
@@ -242,9 +242,9 @@ describe('addAgent', () => {
);
});
- it('writes nothing to the workspace when registration fails', async () => {
+ it('writes nothing to the workdir when registration fails', async () => {
h.registerAgentIdentity.mockResolvedValue({ kind: 'name-conflict' } as never);
- const fs = h.state.workspace as PluginFs;
+ const fs = h.state.workdir as PluginFs;
expect((await addAgent(params())).kind).toBe('name-conflict');
expect(await fs.read(agentSettingsRelativePath('codex-hoot'))).toBeNull();
@@ -263,7 +263,7 @@ describe('addAgent', () => {
SWITCH_AGENT_ID: 'their-agent',
},
});
- h.state.workspace = fakeFs({ [agentSettingsRelativePath('codex-hoot')]: theirs });
+ h.state.workdir = fakeFs({ [agentSettingsRelativePath('codex-hoot')]: theirs });
const result = await addAgent(params());
@@ -273,9 +273,9 @@ describe('addAgent', () => {
});
expect(h.registerAgentIdentity).not.toHaveBeenCalled();
expect(h.createAgent).not.toHaveBeenCalled();
- expect(
- await (h.state.workspace as PluginFs).read(agentSettingsRelativePath('codex-hoot'))
- ).toBe(theirs);
+ expect(await (h.state.workdir as PluginFs).read(agentSettingsRelativePath('codex-hoot'))).toBe(
+ theirs
+ );
});
it('refuses when same-server credentials exist but the agent is unknown to this install (CHOO-2560)', async () => {
@@ -290,7 +290,7 @@ describe('addAgent', () => {
SWITCH_AGENT_ID: 'colleague-agent',
},
});
- h.state.workspace = fakeFs({ [agentSettingsRelativePath('codex-hoot')]: colleague });
+ h.state.workdir = fakeFs({ [agentSettingsRelativePath('codex-hoot')]: colleague });
const result = await addAgent(params());
@@ -298,9 +298,9 @@ describe('addAgent', () => {
expect(h.registerAgentIdentity).not.toHaveBeenCalled();
expect(h.createAgent).not.toHaveBeenCalled();
// The colleague's file is intact.
- expect(
- await (h.state.workspace as PluginFs).read(agentSettingsRelativePath('codex-hoot'))
- ).toBe(colleague);
+ expect(await (h.state.workdir as PluginFs).read(agentSettingsRelativePath('codex-hoot'))).toBe(
+ colleague
+ );
});
it('refuses a name already taken in the location, without minting an identity', async () => {
diff --git a/console/apps/switch-console-desktop/src/main/core/agents/add-agent.ts b/console/apps/switch-console-desktop/src/main/core/agents/add-agent.ts
index 469f6a013..4e9d27df8 100644
--- a/console/apps/switch-console-desktop/src/main/core/agents/add-agent.ts
+++ b/console/apps/switch-console-desktop/src/main/core/agents/add-agent.ts
@@ -32,7 +32,7 @@ import { syncAgentConfig } from './agent-config-sync';
import { foreignCredentialsOwner, sameEndpointAgentId } from './agent-credentials-slot';
import { agentEvents } from './agent-events';
import { agentNameTaken } from './agent-name-taken';
-import { resolveWorkspaceFsFor } from './agent-workspace-fs';
+import { resolveWorkdirFsFor } from './agent-workdir-fs';
import { createAgent } from './createAgent';
import { knownAgentTypeForProvider } from './known-agent-type';
import { registerAgentIdentity } from './register-agent-identity';
@@ -270,14 +270,14 @@ async function runAddAgent(params: AddAgentParams): Promise<AddAgentResult> {
if (registered.kind !== 'created') return reportFailedCreate(params, registered);
const behavior = getPlugin(params.providerId).behavior.repoAgents;
- const workspace = await resolveWorkspaceFsFor(params.sshHost, params.dir);
+ const workdir = await resolveWorkdirFsFor(params.sshHost, params.dir);
try {
// Writing the per-agent Switch credentials is unconditional core behavior for
// every provider, keyed by the agent's `name` — the single key-space every
// reader (launch path, auto-session watcher, notification poller) uses
// (CHOO-1440). Providers with repo-agent definitions (Claude) layer their
// on-disk definition on top; that's the only provider-specific extra.
- await writeNeutralAgentSettingsFs(workspace.fs, {
+ await writeNeutralAgentSettingsFs(workdir.fs, {
slug: params.name,
apiEndpoint: server.apiUrl,
apiToken: registered.apiKey,
@@ -286,19 +286,19 @@ async function runAddAgent(params: AddAgentParams): Promise<AddAgentResult> {
});
// The config file is the agent's configuration; the provider's own file is
// generated from it, here and on every later edit.
- await writeAgentConfigFile(workspace.fs, params.name, {
+ await writeAgentConfigFile(workdir.fs, params.name, {
instructions: params.instructions,
settings: params.definitionAttributes,
...(params.templateOrigin ? { template: params.templateOrigin } : {}),
});
await syncAgentConfig({
- workspaceFs: workspace.fs,
+ workdirFs: workdir.fs,
repoAgents: behavior ?? null,
name: params.name,
description: params.description,
});
} finally {
- workspace.close();
+ workdir.close();
}
const location = await ensureLocation({
diff --git a/console/apps/switch-console-desktop/src/main/core/agents/agent-config-sync.test.ts b/console/apps/switch-console-desktop/src/main/core/agents/agent-config-sync.test.ts
index 8066db2c1..f8921fd2e 100644
--- a/console/apps/switch-console-desktop/src/main/core/agents/agent-config-sync.test.ts
+++ b/console/apps/switch-console-desktop/src/main/core/agents/agent-config-sync.test.ts
@@ -25,7 +25,7 @@ const claudeRepoAgents = getPlugin('claude').behavior.repoAgents ?? null;
function sync(pluginFs = createPluginFs(dir)) {
return syncAgentConfig({
- workspaceFs: pluginFs,
+ workdirFs: pluginFs,
repoAgents: claudeRepoAgents,
name: NAME,
description: DESCRIPTION,
@@ -42,7 +42,7 @@ describe('syncAgentConfig', () => {
await writeAgentConfigFile(pluginFs, NAME, { instructions: 'be terse' });
const result = await syncAgentConfig({
- workspaceFs: pluginFs,
+ workdirFs: pluginFs,
repoAgents: null,
name: NAME,
description: DESCRIPTION,
diff --git a/console/apps/switch-console-desktop/src/main/core/agents/agent-config-sync.ts b/console/apps/switch-console-desktop/src/main/core/agents/agent-config-sync.ts
index bff18ec81..7425750c2 100644
--- a/console/apps/switch-console-desktop/src/main/core/agents/agent-config-sync.ts
+++ b/console/apps/switch-console-desktop/src/main/core/agents/agent-config-sync.ts
@@ -37,7 +37,7 @@ export type AgentConfigSyncResult = {
};
export async function syncAgentConfig(params: {
- workspaceFs: PluginFs;
+ workdirFs: PluginFs;
/** Null for a provider with no repository definitions (Codex, OpenCode). */
repoAgents: IRepoAgentsBehavior | null;
/** The agent's name, which is both its config-file key and its definition stem. */
@@ -45,16 +45,16 @@ export async function syncAgentConfig(params: {
/** The agent's description, which the definition carries in its frontmatter. */
description: string;
}): Promise<AgentConfigSyncResult> {
- const { workspaceFs, repoAgents, name, description } = params;
+ const { workdirFs, repoAgents, name, description } = params;
- const config = (await readAgentConfigFile(workspaceFs, name)) ?? {};
+ const config = (await readAgentConfigFile(workdirFs, name)) ?? {};
if (!repoAgents) return { config, action: 'not-applicable' };
const definitionPath = repoAgents.definitionPath(name);
const generated = repoAgents.renderDefinition(
definitionAttributes({ config, name, description })
);
- const current = await workspaceFs.read(definitionPath);
+ const current = await workdirFs.read(definitionPath);
const action = decideArtifactSync({
current,
@@ -65,16 +65,16 @@ export async function syncAgentConfig(params: {
if (action === 'in-sync') return { config, action };
if (action === 'adopt') {
- const adopted = await adoptDefinition({ workspaceFs, repoAgents, name, config });
+ const adopted = await adoptDefinition({ workdirFs, repoAgents, name, config });
return { config: adopted, action: 'adopted' };
}
- await workspaceFs.write(definitionPath, generated);
+ await workdirFs.write(definitionPath, generated);
const written: AgentConfigFile = {
...config,
rendered: { ...config.rendered, [definitionPath]: fingerprintArtifact(generated) },
};
- await writeAgentConfigFile(workspaceFs, name, written);
+ await writeAgentConfigFile(workdirFs, name, written);
return { config: written, action: 'written' };
}
@@ -88,14 +88,14 @@ export async function syncAgentConfig(params: {
* meaningful instead of reporting a hand edit forever.
*/
async function adoptDefinition(params: {
- workspaceFs: PluginFs;
+ workdirFs: PluginFs;
repoAgents: IRepoAgentsBehavior;
name: string;
config: AgentConfigFile;
}): Promise<AgentConfigFile> {
- const { workspaceFs, repoAgents, name, config } = params;
+ const { workdirFs, repoAgents, name, config } = params;
- const attributes = await repoAgents.readDefinition(workspaceFs, name);
+ const attributes = await repoAgents.readDefinition(workdirFs, name);
if (attributes === null) {
throw new Error(`Agent ${name} has a definition that could not be read back.`);
}
@@ -115,13 +115,13 @@ async function adoptDefinition(params: {
description: typeof description === 'string' ? description : '',
})
);
- await workspaceFs.write(definitionPath, generated);
+ await workdirFs.write(definitionPath, generated);
const result: AgentConfigFile = {
...adopted,
rendered: { ...config.rendered, [definitionPath]: fingerprintArtifact(generated) },
};
- await writeAgentConfigFile(workspaceFs, name, result);
+ await writeAgentConfigFile(workdirFs, name, result);
return result;
}
diff --git a/console/apps/switch-console-desktop/src/main/core/agents/agent-config.test.ts b/console/apps/switch-console-desktop/src/main/core/agents/agent-config.test.ts
index e8a5c332d..7b447dbc7 100644
--- a/console/apps/switch-console-desktop/src/main/core/agents/agent-config.test.ts
+++ b/console/apps/switch-console-desktop/src/main/core/agents/agent-config.test.ts
@@ -42,8 +42,8 @@ vi.mock('./getAgentById', () => ({
vi.mock('./agent-location', () => ({
getAgentLocation: async () => ({ id: 'loc-1', dir: '/repo', sshHost: 'vm-1' }),
}));
-vi.mock('./agent-workspace-fs', () => ({
- resolveWorkspaceFsFor: async () => ({ fs: fakeFs(), close: () => {} }),
+vi.mock('./agent-workdir-fs', () => ({
+ resolveWorkdirFsFor: async () => ({ fs: fakeFs(), close: () => {} }),
}));
vi.mock('./setAgentProviderConfig', () => ({
setAgentProviderConfig: (params: unknown) => setAgentProviderConfig(params),
diff --git a/console/apps/switch-console-desktop/src/main/core/agents/agent-config.ts b/console/apps/switch-console-desktop/src/main/core/agents/agent-config.ts
index c1c37ccb3..bead9516f 100644
--- a/console/apps/switch-console-desktop/src/main/core/agents/agent-config.ts
+++ b/console/apps/switch-console-desktop/src/main/core/agents/agent-config.ts
@@ -5,7 +5,7 @@ import type { Agent } from '@shared/core/agents/agents';
import type { AgentConfigFile } from './agent-config-file';
import { writeAgentConfigFile, type AgentTemplateOrigin } from './agent-config-file';
import { syncAgentConfig } from './agent-config-sync';
-import { withAgentWorkspace } from './agent-launch-config';
+import { withAgentWorkdir } from './agent-launch-config';
import { getAgentById } from './getAgentById';
import { setAgentProviderConfig } from './setAgentProviderConfig';
@@ -31,7 +31,7 @@ import { setAgentProviderConfig } from './setAgentProviderConfig';
* that is not what the agent will actually launch with.
*/
export async function readAgentConfig(agentId: string): Promise<AgentConfigFile> {
- return withAgentWorkspace(agentId, (agent, fs) => reconcile(agent, fs));
+ return withAgentWorkdir(agentId, (agent, fs) => reconcile(agent, fs));
}
/**
@@ -46,7 +46,7 @@ export async function writeAgentConfig(params: {
agentId: string;
config: AgentConfigFile;
}): Promise<AgentConfigFile> {
- return withAgentWorkspace(params.agentId, async (agent, fs) => {
+ return withAgentWorkdir(params.agentId, async (agent, fs) => {
await writeAgentConfigFile(fs, agent.name, params.config);
return reconcile(agent, fs);
});
@@ -92,7 +92,7 @@ export async function setAgentSettings(params: {
}
/**
- * Read, change, write — in one workspace session.
+ * Read, change, write — in one workdir session.
*
* Not read-then-write through the public helpers: over SSH that opens the
* working directory twice, and it would reconcile twice for one edit.
@@ -101,7 +101,7 @@ async function updateAgentConfig(
agentId: string,
change: (config: AgentConfigFile) => AgentConfigFile
): Promise<AgentConfigFile> {
- const config = await withAgentWorkspace(agentId, async (agent, fs) => {
+ const config = await withAgentWorkdir(agentId, async (agent, fs) => {
const current = await reconcile(agent, fs);
await writeAgentConfigFile(fs, agent.name, change(current));
return reconcile(agent, fs);
@@ -158,7 +158,7 @@ async function reconcile(agent: Agent, fs: PluginFs): Promise<AgentConfigFile> {
const description = typeof existing?.description === 'string' ? existing.description : '';
const { config } = await syncAgentConfig({
- workspaceFs: fs,
+ workdirFs: fs,
repoAgents,
name: agent.name,
description,
diff --git a/console/apps/switch-console-desktop/src/main/core/agents/agent-credentials-slot.ts b/console/apps/switch-console-desktop/src/main/core/agents/agent-credentials-slot.ts
index 81bafcd68..1fcf30ba1 100644
--- a/console/apps/switch-console-desktop/src/main/core/agents/agent-credentials-slot.ts
+++ b/console/apps/switch-console-desktop/src/main/core/agents/agent-credentials-slot.ts
@@ -1,4 +1,4 @@
-import { resolveWorkspaceFsFor } from './agent-workspace-fs';
+import { resolveWorkdirFsFor } from './agent-workdir-fs';
import { agentSettingsRelativePath } from './switch-settings-paths';
import { existingAgentIdInSlot, foreignCredentialsOwnerFs } from './write-switch-settings';
@@ -22,11 +22,11 @@ export async function foreignCredentialsOwner(
slug: string,
apiEndpoint: string
): Promise<string | null> {
- const workspace = await resolveWorkspaceFsFor(sshHost, dir);
+ const workdir = await resolveWorkdirFsFor(sshHost, dir);
try {
- return await foreignCredentialsOwnerFs(workspace.fs, slug, apiEndpoint);
+ return await foreignCredentialsOwnerFs(workdir.fs, slug, apiEndpoint);
} finally {
- workspace.close();
+ workdir.close();
}
}
@@ -46,11 +46,11 @@ export async function sameEndpointAgentId(
slug: string,
apiEndpoint: string
): Promise<string | null> {
- const workspace = await resolveWorkspaceFsFor(sshHost, dir);
+ const workdir = await resolveWorkdirFsFor(sshHost, dir);
try {
- const existingRaw = await workspace.fs.read(agentSettingsRelativePath(slug));
+ const existingRaw = await workdir.fs.read(agentSettingsRelativePath(slug));
return existingAgentIdInSlot(existingRaw, apiEndpoint);
} finally {
- workspace.close();
+ workdir.close();
}
}
diff --git a/console/apps/switch-console-desktop/src/main/core/agents/agent-definition.ts b/console/apps/switch-console-desktop/src/main/core/agents/agent-definition.ts
index 255f3c594..4d72c54a3 100644
--- a/console/apps/switch-console-desktop/src/main/core/agents/agent-definition.ts
+++ b/console/apps/switch-console-desktop/src/main/core/agents/agent-definition.ts
@@ -1,7 +1,7 @@
import type { RepoAgentAttributes } from '@switch-console/core/agents/plugins';
import { getPlugin } from '@main/core/providers/plugin-registry';
import { getAgentLocation } from './agent-location';
-import { resolveWorkspaceFsFor } from './agent-workspace-fs';
+import { resolveWorkdirFsFor } from './agent-workdir-fs';
import { getAgentById } from './getAgentById';
/**
@@ -19,11 +19,11 @@ export async function readAgentDefinition(agentId: string): Promise<RepoAgentAtt
if (!behavior || !agent.name) return null;
const location = await getAgentLocation(agent);
- const workspace = await resolveWorkspaceFsFor(location.sshHost, location.dir);
+ const workdir = await resolveWorkdirFsFor(location.sshHost, location.dir);
try {
- return await behavior.readDefinition(workspace.fs, agent.name);
+ return await behavior.readDefinition(workdir.fs, agent.name);
} finally {
- workspace.close();
+ workdir.close();
}
}
@@ -47,16 +47,16 @@ export async function updateAgentDefinition(params: {
}
const location = await getAgentLocation(agent);
- const workspace = await resolveWorkspaceFsFor(location.sshHost, location.dir);
+ const workdir = await resolveWorkdirFsFor(location.sshHost, location.dir);
try {
- const current = await behavior.readDefinition(workspace.fs, agent.name);
+ const current = await behavior.readDefinition(workdir.fs, agent.name);
const description = typeof current?.description === 'string' ? current.description : '';
- await behavior.writeDefinition(workspace.fs, {
+ await behavior.writeDefinition(workdir.fs, {
...params.attributes,
name: agent.name,
description,
});
} finally {
- workspace.close();
+ workdir.close();
}
}
diff --git a/console/apps/switch-console-desktop/src/main/core/agents/agent-launch-config.ts b/console/apps/switch-console-desktop/src/main/core/agents/agent-launch-config.ts
index 1fe040bba..21ac9ed6a 100644
--- a/console/apps/switch-console-desktop/src/main/core/agents/agent-launch-config.ts
+++ b/console/apps/switch-console-desktop/src/main/core/agents/agent-launch-config.ts
@@ -3,7 +3,7 @@ import type { Agent } from '@shared/core/agents/agents';
import type { AgentConfigFile } from './agent-config-file';
import { readAgentConfigFile } from './agent-config-file';
import { getAgentLocation } from './agent-location';
-import { resolveWorkspaceFsFor } from './agent-workspace-fs';
+import { resolveWorkdirFsFor } from './agent-workdir-fs';
import { getAgentById } from './getAgentById';
/**
@@ -18,7 +18,7 @@ import { getAgentById } from './getAgentById';
/** Read launch settings from the execution host; transport failures must stop launch. */
export async function readAgentConfigForLaunch(agentId: string): Promise<AgentConfigFile> {
- return withAgentWorkspace(
+ return withAgentWorkdir(
agentId,
async (agent, fs) => (await readAgentConfigFile(fs, agent.name)) ?? {}
);
@@ -46,7 +46,7 @@ export async function agentLaunchSpecialization(
}
/** Run `run` against the agent's working directory, local or over SFTP. */
-export async function withAgentWorkspace<T>(
+export async function withAgentWorkdir<T>(
agentId: string,
run: (agent: Agent, fs: PluginFs) => Promise<T>
): Promise<T> {
@@ -54,10 +54,10 @@ export async function withAgentWorkspace<T>(
if (!agent) throw new Error(`No agent with id ${agentId}`);
const location = await getAgentLocation(agent);
- const workspace = await resolveWorkspaceFsFor(location.sshHost, location.dir);
+ const workdir = await resolveWorkdirFsFor(location.sshHost, location.dir);
try {
- return await run(agent, workspace.fs);
+ return await run(agent, workdir.fs);
} finally {
- workspace.close();
+ workdir.close();
}
}
diff --git a/console/apps/switch-console-desktop/src/main/core/agents/agent-workspace-fs.ts b/console/apps/switch-console-desktop/src/main/core/agents/agent-workdir-fs.ts
similarity index 90%
rename from console/apps/switch-console-desktop/src/main/core/agents/agent-workspace-fs.ts
rename to console/apps/switch-console-desktop/src/main/core/agents/agent-workdir-fs.ts
index 0697b8af9..a0c9e2002 100644
--- a/console/apps/switch-console-desktop/src/main/core/agents/agent-workspace-fs.ts
+++ b/console/apps/switch-console-desktop/src/main/core/agents/agent-workdir-fs.ts
@@ -12,7 +12,7 @@ import { ensureSshConnected } from '@main/core/ssh/connect/connect-agent-ssh';
* Callers MUST invoke `close()` in a `finally` — a leaked SFTP channel
* eventually exhausts the host's MaxSessions.
*/
-export type WorkspaceFs = {
+export type WorkdirFs = {
/** FS rooted at the working dir — local disk or the remote repo dir. */
fs: PluginFs;
/** FS for user-scoped (`~/.claude`) definitions; empty for remote agents. */
@@ -34,15 +34,12 @@ const EMPTY_PLUGIN_FS: PluginFs = {
};
/**
- * Open a {@link WorkspaceFs} for a working directory identified by run location
+ * Open a {@link WorkdirFs} for a working directory identified by run location
* (ssh host + dir) rather than an existing agent row — used at create/onboard
* time before a row exists. Local dirs resolve on disk; remote dirs open an
* SFTP channel to the host.
*/
-export async function resolveWorkspaceFsFor(
- sshHost: string | null,
- dir: string
-): Promise<WorkspaceFs> {
+export async function resolveWorkdirFsFor(sshHost: string | null, dir: string): Promise<WorkdirFs> {
if (sshHost === null) {
return { fs: createPluginFs(dir), homeFs: createPluginFs(homedir()), close: () => {} };
}
diff --git a/console/apps/switch-console-desktop/src/main/core/agents/attach-configured-agents.test.ts b/console/apps/switch-console-desktop/src/main/core/agents/attach-configured-agents.test.ts
index f39bba2c5..104079989 100644
--- a/console/apps/switch-console-desktop/src/main/core/agents/attach-configured-agents.test.ts
+++ b/console/apps/switch-console-desktop/src/main/core/agents/attach-configured-agents.test.ts
@@ -10,8 +10,8 @@ function readOnlyFs(seed: Record<string, string>): PluginFs {
const files = new Map<string, string>(Object.entries(seed));
return {
read: (p) => Promise.resolve(files.get(p) ?? null),
- write: (p) => Promise.reject(new Error(`attach wrote to the workspace: ${p}`)),
- delete: (p) => Promise.reject(new Error(`attach deleted from the workspace: ${p}`)),
+ write: (p) => Promise.reject(new Error(`attach wrote to the workdir: ${p}`)),
+ delete: (p) => Promise.reject(new Error(`attach deleted from the workdir: ${p}`)),
exists: (p) => Promise.resolve(files.has(p)),
list: (dir) => {
const prefix = `${dir}/`;
@@ -44,12 +44,12 @@ const h = vi.hoisted(() => {
}
}
const state: {
- workspace: PluginFs | null;
+ workdir: PluginFs | null;
/** Agent-row names already in the directory, per Switch server. */
agentNamesByWorkspace: Record<string, string[]>;
existsOnServer: boolean;
existsThrows: Error | null;
- } = { workspace: null, agentNamesByWorkspace: {}, existsOnServer: true, existsThrows: null };
+ } = { workdir: null, agentNamesByWorkspace: {}, existsOnServer: true, existsThrows: null };
return {
state,
GatewayError,
@@ -76,9 +76,9 @@ vi.mock('./getAgents', () => ({
vi.mock('@main/core/workspaces/workspaces-store', () => ({
requireSoleWorkspaceForServer: vi.fn(async (serverId: string) => ({ id: `ws-${serverId}` })),
}));
-vi.mock('./agent-workspace-fs', () => ({
- resolveWorkspaceFsFor: vi.fn(async () => ({
- fs: h.state.workspace as PluginFs,
+vi.mock('./agent-workdir-fs', () => ({
+ resolveWorkdirFsFor: vi.fn(async () => ({
+ fs: h.state.workdir as PluginFs,
homeFs: null,
close: vi.fn(),
})),
@@ -121,7 +121,7 @@ describe('attachConfiguredAgents', () => {
h.state.agentNamesByWorkspace = {};
h.state.existsOnServer = true;
h.state.existsThrows = null;
- h.state.workspace = readOnlyFs({ '.switch/agents/theirs.json': creds('sw-theirs') });
+ h.state.workdir = readOnlyFs({ '.switch/agents/theirs.json': creds('sw-theirs') });
});
it('adopts the existing Switch identity instead of minting a new one', async () => {
@@ -140,7 +140,7 @@ describe('attachConfiguredAgents', () => {
});
it('writes nothing to the working directory', async () => {
- // The workspace belongs to whichever install set the agent up. Any write
+ // The workdir belongs to whichever install set the agent up. Any write
// here rejects, so this passing means attach touched none of their state.
await expect(
attachConfiguredAgents(params([{ name: 'theirs', providerId: 'codex' }]))
@@ -202,7 +202,7 @@ describe('attachConfiguredAgents', () => {
// One Switch server can be reachable at two URLs. The launch path reads the
// endpoint from the same file as the token, so the directory's value is what
// the session will really use — surfaced, never corrected.
- h.state.workspace = readOnlyFs({
+ h.state.workdir = readOnlyFs({
'.switch/agents/theirs.json': creds('sw-theirs', 'https://switch.internal:8443'),
});
diff --git a/console/apps/switch-console-desktop/src/main/core/agents/attach-configured-agents.ts b/console/apps/switch-console-desktop/src/main/core/agents/attach-configured-agents.ts
index b81e989a9..db4b6e7b0 100644
--- a/console/apps/switch-console-desktop/src/main/core/agents/attach-configured-agents.ts
+++ b/console/apps/switch-console-desktop/src/main/core/agents/attach-configured-agents.ts
@@ -48,7 +48,7 @@ export type AttachConfiguredAgentsResult = Result<Agent[], OnboardAgentError>;
* provider config — the directory is another install's state and this operation
* treats it as read-only. That is possible because the API token is never needed
* here: it stays where it already is, and the launch path reads it from disk when
- * a session spawns. This module deliberately imports no workspace writer, so the
+ * a session spawns. This module deliberately imports no workdir writer, so the
* guarantee is structural rather than a matter of care.
*
* An identity that no longer exists on the chosen server fails the attach loudly
diff --git a/console/apps/switch-console-desktop/src/main/core/agents/deleteAgent.test.ts b/console/apps/switch-console-desktop/src/main/core/agents/deleteAgent.test.ts
index a0c85a369..a4b58f4ee 100644
--- a/console/apps/switch-console-desktop/src/main/core/agents/deleteAgent.test.ts
+++ b/console/apps/switch-console-desktop/src/main/core/agents/deleteAgent.test.ts
@@ -49,8 +49,8 @@ vi.mock('@main/core/sdk-host/shared-watcher', () => ({
vi.mock('@main/core/providers/plugin-registry', () => ({
getPlugin: () => ({ behavior: { repoAgents: h.state.repoAgents } }),
}));
-vi.mock('./agent-workspace-fs', () => ({
- resolveWorkspaceFsFor: vi.fn(async () => ({ fs: h.state.fs, close: vi.fn() })),
+vi.mock('./agent-workdir-fs', () => ({
+ resolveWorkdirFsFor: vi.fn(async () => ({ fs: h.state.fs, close: vi.fn() })),
}));
vi.mock('./agent-location', () => ({
getAgentLocation: vi.fn(async () => ({ sshHost: h.state.sshHost, dir: '/repo' })),
diff --git a/console/apps/switch-console-desktop/src/main/core/agents/deleteAgent.ts b/console/apps/switch-console-desktop/src/main/core/agents/deleteAgent.ts
index 15378d295..9fca99885 100644
--- a/console/apps/switch-console-desktop/src/main/core/agents/deleteAgent.ts
+++ b/console/apps/switch-console-desktop/src/main/core/agents/deleteAgent.ts
@@ -29,7 +29,7 @@ import type { Location } from '@shared/core/locations/locations';
import { sessionRuntimeManager } from '../sessions/session-runtime-manager';
import { agentEvents } from './agent-events';
import { getAgentLocation } from './agent-location';
-import { resolveWorkspaceFsFor } from './agent-workspace-fs';
+import { resolveWorkdirFsFor } from './agent-workdir-fs';
import { getAgentById } from './getAgentById';
import { stopRemoteWatcher } from './remote-watcher';
import { removeAgentLaunchProfile } from './remove-launch-profile';
@@ -126,7 +126,7 @@ async function deleteAgentInSwitch(agent: Agent): Promise<void> {
* (visibly) rather than thrown — the credentials being torn down are already dead.
*/
async function removeProvisionedFiles(agent: Agent, location: Location): Promise<void> {
- const ctx = await resolveWorkspaceFsFor(location.sshHost, location.dir);
+ const ctx = await resolveWorkdirFsFor(location.sshHost, location.dir);
try {
const behavior = getPlugin(agent.providerId).behavior.repoAgents;
if (behavior && agent.name) {
diff --git a/console/apps/switch-console-desktop/src/main/core/agents/discover-configured-agents.test.ts b/console/apps/switch-console-desktop/src/main/core/agents/discover-configured-agents.test.ts
index 5b198be0a..a53f765b4 100644
--- a/console/apps/switch-console-desktop/src/main/core/agents/discover-configured-agents.test.ts
+++ b/console/apps/switch-console-desktop/src/main/core/agents/discover-configured-agents.test.ts
@@ -50,13 +50,13 @@ function launchSpec(providerId: string) {
const h = vi.hoisted(() => {
const state: {
- workspace: PluginFs | null;
+ workdir: PluginFs | null;
location: { id: string } | undefined;
/** Agent-row names already in the directory, per Switch server. */
agentNamesByWorkspace: Record<string, string[]>;
claudeDefinitions: Array<{ name: string; description: string | null }>;
} = {
- workspace: null,
+ workdir: null,
location: { id: 'loc-1' },
agentNamesByWorkspace: {},
claudeDefinitions: [],
@@ -75,9 +75,9 @@ vi.mock('./getAgents', () => ({
vi.mock('@main/core/workspaces/workspaces-store', () => ({
requireSoleWorkspaceForServer: vi.fn(async (serverId: string) => ({ id: `ws-${serverId}` })),
}));
-vi.mock('./agent-workspace-fs', () => ({
- resolveWorkspaceFsFor: vi.fn(async () => ({
- fs: h.state.workspace as PluginFs,
+vi.mock('./agent-workdir-fs', () => ({
+ resolveWorkdirFsFor: vi.fn(async () => ({
+ fs: h.state.workdir as PluginFs,
homeFs: null,
close: vi.fn(),
})),
@@ -106,14 +106,14 @@ describe('discoverConfiguredAgents', () => {
h.state.location = { id: 'loc-1' };
h.state.agentNamesByWorkspace = {};
h.state.claudeDefinitions = [];
- h.state.workspace = fakeFs();
+ h.state.workdir = fakeFs();
});
it('finds a Codex agent from credentials alone', async () => {
// The gap this feature closes: Codex has no repo-agent definitions, so the
// definition-based scan sees nothing. The provider-neutral credentials file
// is written for every provider, so it finds the agent anyway.
- h.state.workspace = fakeFs({
+ h.state.workdir = fakeFs({
'.switch/agents/.gitignore': '*\n',
'.switch/agents/codex-hoot.json': creds('sw-codex'),
'.switchdash/agents/codex-hoot/agent-launch-spec.json': launchSpec('codex'),
@@ -133,7 +133,7 @@ describe('discoverConfiguredAgents', () => {
it('never surfaces the API token', async () => {
// Attaching must not need the secret: it stays on disk for the launch path.
- h.state.workspace = fakeFs({
+ h.state.workdir = fakeFs({
'.switch/agents/hoot.json': creds('sw-1', 'https://switch.example.com', 'tok-do-not-leak'),
});
@@ -142,7 +142,7 @@ describe('discoverConfiguredAgents', () => {
it('falls back to the owning provider definition, then to unknown', async () => {
h.state.claudeDefinitions = [{ name: 'cc-hoot', description: null }];
- h.state.workspace = fakeFs({
+ h.state.workdir = fakeFs({
'.switch/agents/cc-hoot.json': creds('sw-cc'),
'.switch/agents/mystery.json': creds('sw-my'),
});
@@ -160,7 +160,7 @@ describe('discoverConfiguredAgents', () => {
it('uses the provider definition and ignores obsolete sidecar launch specs', async () => {
h.state.claudeDefinitions = [{ name: 'hoot', description: null }];
- h.state.workspace = fakeFs({
+ h.state.workdir = fakeFs({
'.switch/agents/hoot.json': creds('sw-1'),
'.switchdash/agents/hoot/agent-launch-spec.json': launchSpec('codex'),
});
@@ -170,7 +170,7 @@ describe('discoverConfiguredAgents', () => {
it('marks agents this Switch Console already has a row for', async () => {
h.state.agentNamesByWorkspace = { 'ws-srv-a': ['mine'] };
- h.state.workspace = fakeFs({
+ h.state.workdir = fakeFs({
'.switch/agents/mine.json': creds('sw-mine'),
'.switch/agents/theirs.json': creds('sw-theirs'),
});
@@ -185,7 +185,7 @@ describe('discoverConfiguredAgents', () => {
// for server A says nothing about server B, and treating it as "already got
// this" is what silently emptied the onboarding list.
h.state.agentNamesByWorkspace = { 'ws-srv-a': ['shared'] };
- h.state.workspace = fakeFs({ '.switch/agents/shared.json': creds('sw-shared') });
+ h.state.workdir = fakeFs({ '.switch/agents/shared.json': creds('sw-shared') });
expect((await scan('srv-a'))[0]).toMatchObject({ name: 'shared', alreadyAgent: true });
expect((await scan('srv-b'))[0]).toMatchObject({ name: 'shared', alreadyAgent: false });
@@ -197,13 +197,13 @@ describe('discoverConfiguredAgents', () => {
it('reports nothing for an unknown location rather than failing', async () => {
h.state.location = undefined;
- h.state.workspace = fakeFs({ '.switch/agents/hoot.json': creds('sw-1') });
+ h.state.workdir = fakeFs({ '.switch/agents/hoot.json': creds('sw-1') });
expect((await scan())[0]).toMatchObject({ name: 'hoot', alreadyAgent: false });
});
it('skips unusable credentials files instead of inventing an identity', async () => {
- h.state.workspace = fakeFs({
+ h.state.workdir = fakeFs({
'.switch/agents/broken.json': '{ not json',
'.switch/agents/no-id.json': JSON.stringify({ env: { SWITCH_API_ENDPOINT: 'https://x' } }),
'.switch/agents/good.json': creds('sw-good'),
@@ -214,7 +214,7 @@ describe('discoverConfiguredAgents', () => {
});
it('ignores non-JSON entries such as the .gitignore', async () => {
- h.state.workspace = fakeFs({
+ h.state.workdir = fakeFs({
'.switch/agents/.gitignore': '*\n',
'.switch/agents/hoot.json': creds('sw-1'),
});
diff --git a/console/apps/switch-console-desktop/src/main/core/agents/discover-configured-agents.ts b/console/apps/switch-console-desktop/src/main/core/agents/discover-configured-agents.ts
index 186969d3c..87bb5d308 100644
--- a/console/apps/switch-console-desktop/src/main/core/agents/discover-configured-agents.ts
+++ b/console/apps/switch-console-desktop/src/main/core/agents/discover-configured-agents.ts
@@ -7,7 +7,7 @@ import {
isValidProviderId,
type AgentProviderId,
} from '@shared/core/providers/agent-provider-registry';
-import { resolveWorkspaceFsFor } from './agent-workspace-fs';
+import { resolveWorkdirFsFor } from './agent-workdir-fs';
import { getLocationAgentsInWorkspace } from './getAgents';
import { SWITCH_AGENTS_DIR_RELATIVE } from './switch-settings-paths';
@@ -74,13 +74,13 @@ function parseCredentialIdentity(raw: string | null, name: string): CredentialId
* concept at all. Built once per scan: each provider answers with its own
* discovery rather than this module hardcoding any provider's on-disk layout.
*/
-async function definitionOwners(workspaceFs: PluginFs): Promise<Map<string, AgentProviderId>> {
+async function definitionOwners(workdirFs: PluginFs): Promise<Map<string, AgentProviderId>> {
const owners = new Map<string, AgentProviderId>();
for (const plugin of listPlugins()) {
const behavior = plugin.behavior.repoAgents;
if (!behavior) continue;
try {
- for (const def of await behavior.discoverDefinitions(workspaceFs)) {
+ for (const def of await behavior.discoverDefinitions(workdirFs)) {
if (!owners.has(def.name) && isValidProviderId(plugin.metadata.id)) {
owners.set(def.name, plugin.metadata.id);
}
@@ -131,21 +131,21 @@ export async function discoverConfiguredAgents(params: {
)
: new Set<string>();
- const workspace = await resolveWorkspaceFsFor(params.sshHost, params.dir);
+ const workdir = await resolveWorkdirFsFor(params.sshHost, params.dir);
try {
- const names = (await workspace.fs.list(SWITCH_AGENTS_DIR_RELATIVE))
+ const names = (await workdir.fs.list(SWITCH_AGENTS_DIR_RELATIVE))
.filter((entry) => entry.endsWith('.json'))
.map((entry) => entry.slice(0, -'.json'.length))
.filter((name) => name.length > 0)
.sort((a, b) => a.localeCompare(b));
if (names.length === 0) return [];
- const owners = await definitionOwners(workspace.fs);
+ const owners = await definitionOwners(workdir.fs);
const discovered: DiscoveredConfiguredAgent[] = [];
for (const name of names) {
const identity = parseCredentialIdentity(
- await workspace.fs.read(`${SWITCH_AGENTS_DIR_RELATIVE}/${name}.json`),
+ await workdir.fs.read(`${SWITCH_AGENTS_DIR_RELATIVE}/${name}.json`),
name
);
if (!identity) continue;
@@ -164,6 +164,6 @@ export async function discoverConfiguredAgents(params: {
}
return discovered;
} finally {
- workspace.close();
+ workdir.close();
}
}
diff --git a/console/apps/switch-console-desktop/src/main/core/agents/discover-location-agents.ts b/console/apps/switch-console-desktop/src/main/core/agents/discover-location-agents.ts
index 0df24255a..3c0814922 100644
--- a/console/apps/switch-console-desktop/src/main/core/agents/discover-location-agents.ts
+++ b/console/apps/switch-console-desktop/src/main/core/agents/discover-location-agents.ts
@@ -2,7 +2,7 @@ import { getLocationByHostDir } from '@main/core/locations/store';
import { getPlugin } from '@main/core/providers/plugin-registry';
import { requireSoleWorkspaceForServer } from '@main/core/workspaces/workspaces-store';
import type { AgentProviderId } from '@shared/core/providers/agent-provider-registry';
-import { resolveWorkspaceFsFor } from './agent-workspace-fs';
+import { resolveWorkdirFsFor } from './agent-workdir-fs';
import { getLocationAgentsInWorkspace } from './getAgents';
export type DiscoveredLocationAgent = {
@@ -55,10 +55,10 @@ export async function discoverLocationAgents(params: {
)
: new Set<string>();
- const workspace = await resolveWorkspaceFsFor(params.sshHost, params.dir);
+ const workdir = await resolveWorkdirFsFor(params.sshHost, params.dir);
try {
- const definitions = await behavior.discoverDefinitions(workspace.fs);
- const local = await behavior.discoverLocal(workspace.fs, workspace.homeFs);
+ const definitions = await behavior.discoverDefinitions(workdir.fs);
+ const local = await behavior.discoverLocal(workdir.fs, workdir.homeFs);
const credentialled = new Map(
local.filter((l) => l.switchAgentId !== null).map((l) => [l.name, l.apiEndpoint])
);
@@ -71,6 +71,6 @@ export async function discoverLocationAgents(params: {
alreadyAgent: existing.has(def.name),
}));
} finally {
- workspace.close();
+ workdir.close();
}
}
diff --git a/console/apps/switch-console-desktop/src/main/core/agents/migrate-agent-storage.test.ts b/console/apps/switch-console-desktop/src/main/core/agents/migrate-agent-storage.test.ts
index eb7780a03..d2ba105c7 100644
--- a/console/apps/switch-console-desktop/src/main/core/agents/migrate-agent-storage.test.ts
+++ b/console/apps/switch-console-desktop/src/main/core/agents/migrate-agent-storage.test.ts
@@ -40,7 +40,7 @@ function credsJson(agentId: string): string {
}
// Shared mock state + spies. Hoisted so the vi.mock factories (which are lifted
-// above imports) can reference them. `agents`/`workspace` are set per test.
+// above imports) can reference them. `agents`/`workdir` are set per test.
// `repoAgents` is the behavior `getPlugin` returns — set it to null in a test to
// simulate a provider without repo-agent definitions (e.g. Codex).
const h = vi.hoisted(() => {
@@ -65,11 +65,11 @@ const h = vi.hoisted(() => {
};
const state: {
agents: Array<Record<string, unknown>>;
- workspace: PluginFs | null;
+ workdir: PluginFs | null;
repoAgents: object | null;
} = {
agents: [],
- workspace: null,
+ workdir: null,
repoAgents: defaultRepoAgents,
};
return {
@@ -91,10 +91,10 @@ vi.mock('@main/core/providers/plugin-registry', () => ({
vi.mock('@main/core/locations/store', () => ({
getLocationById: vi.fn(async () => ({ id: 'loc', sshHost: null, dir: '/repo' })),
}));
-vi.mock('./agent-workspace-fs', () => ({
- resolveWorkspaceFsFor: vi.fn(async () => ({
- fs: h.state.workspace,
- homeFs: h.state.workspace,
+vi.mock('./agent-workdir-fs', () => ({
+ resolveWorkdirFsFor: vi.fn(async () => ({
+ fs: h.state.workdir,
+ homeFs: h.state.workdir,
close: () => {},
})),
}));
@@ -134,7 +134,7 @@ describe('migrateAgentStorage', () => {
'.switch/agents/agent-id-1.json': credsJson('sw-1'),
'.claude/agents/cc-hoot-main.md': '# def',
});
- h.state.workspace = ws;
+ h.state.workdir = ws;
await migrateAgentStorage();
@@ -152,7 +152,7 @@ describe('migrateAgentStorage', () => {
h.state.agents = [{ ...baseAgent, providerId: 'codex', name: 'codex-hoot' }];
h.state.repoAgents = null;
const ws = fakeFs({ '.switch/agents/agent-id-1.json': credsJson('sw-1') });
- h.state.workspace = ws;
+ h.state.workdir = ws;
await migrateAgentStorage();
@@ -172,7 +172,7 @@ describe('migrateAgentStorage', () => {
'.claude/settings.local.json': credsJson('sw-1'),
'.claude/agents/cc-hoot-main.md': '# def',
});
- h.state.workspace = ws;
+ h.state.workdir = ws;
await migrateAgentStorage();
@@ -195,7 +195,7 @@ describe('migrateAgentStorage', () => {
h.state.repoAgents = null;
const ws = fakeFs({ '.claude/settings.local.json': credsJson('sw-CLAUDE-MAIN') });
const read = vi.spyOn(ws, 'read');
- h.state.workspace = ws;
+ h.state.workdir = ws;
await migrateAgentStorage();
@@ -212,7 +212,7 @@ describe('migrateAgentStorage', () => {
];
h.state.repoAgents = null;
const ws = fakeFs({ '.claude/settings.local.json': credsJson('sw-CLAUDE-MAIN') });
- h.state.workspace = ws;
+ h.state.workdir = ws;
await migrateAgentStorage();
@@ -226,7 +226,7 @@ describe('migrateAgentStorage', () => {
'.claude/settings.local.json': credsJson('sw-other'),
'.claude/agents/cc-hoot-main.md': '# def',
});
- h.state.workspace = ws;
+ h.state.workdir = ws;
await migrateAgentStorage();
@@ -248,7 +248,7 @@ describe('migrateAgentStorage', () => {
h.state.agents = [{ ...baseAgent, providerId: 'codex', name: 'codex-hoot' }];
h.state.repoAgents = null;
const ws = fakeFs({ '.switch/agents/agent-id-1.json': credsJson('sw-other') });
- h.state.workspace = ws;
+ h.state.workdir = ws;
await migrateAgentStorage();
@@ -269,7 +269,7 @@ describe('migrateAgentStorage', () => {
'.claude/agents/cc-hoot-main.md': '# def',
};
const ws = fakeFs({ ...seed });
- h.state.workspace = ws;
+ h.state.workdir = ws;
await migrateAgentStorage();
@@ -281,33 +281,33 @@ describe('migrateAgentStorage', () => {
it('writes no credentials when none exist anywhere (unrecoverable token)', async () => {
const ws = fakeFs({ '.claude/agents/cc-hoot-main.md': '# def' });
- h.state.workspace = ws;
+ h.state.workdir = ws;
await migrateAgentStorage();
expect(await ws.exists('.switch/agents/cc-hoot-main.json')).toBe(false);
});
- it('skips the whole pass (no workspace opened) once the current generation is latched', async () => {
+ it('skips the whole pass (no workdir opened) once the current generation is latched', async () => {
h.completedGeneration.mockResolvedValueOnce(2);
- const resolveWorkspaceFsFor = (await import('./agent-workspace-fs')).resolveWorkspaceFsFor;
+ const resolveWorkdirFsFor = (await import('./agent-workdir-fs')).resolveWorkdirFsFor;
await migrateAgentStorage();
- expect(resolveWorkspaceFsFor).not.toHaveBeenCalled();
+ expect(resolveWorkdirFsFor).not.toHaveBeenCalled();
expect(h.markComplete).not.toHaveBeenCalled();
});
- it('re-running for generation 2 opens no workspace for a provider generation 1 already did', async () => {
+ it('re-running for generation 2 opens no workdir for a provider generation 1 already did', async () => {
// Generation 2 only broadened the credential step to providers WITHOUT a
- // behavior, so re-opening a Claude agent's workspace — an SSH connect and an
+ // behavior, so re-opening a Claude agent's workdir — an SSH connect and an
// SFTP channel for a remote one — could not change anything.
h.completedGeneration.mockResolvedValueOnce(1);
- const resolveWorkspaceFsFor = (await import('./agent-workspace-fs')).resolveWorkspaceFsFor;
+ const resolveWorkdirFsFor = (await import('./agent-workdir-fs')).resolveWorkdirFsFor;
await migrateAgentStorage();
- expect(resolveWorkspaceFsFor).not.toHaveBeenCalled();
+ expect(resolveWorkdirFsFor).not.toHaveBeenCalled();
expect(h.markComplete).toHaveBeenCalledTimes(1);
});
@@ -316,7 +316,7 @@ describe('migrateAgentStorage', () => {
h.state.agents = [{ ...baseAgent, providerId: 'codex', name: 'codex-hoot' }];
h.state.repoAgents = null;
const ws = fakeFs({ '.switch/agents/agent-id-1.json': credsJson('sw-1') });
- h.state.workspace = ws;
+ h.state.workdir = ws;
await migrateAgentStorage();
@@ -324,7 +324,7 @@ describe('migrateAgentStorage', () => {
});
it('latches the marker after a clean pass', async () => {
- h.state.workspace = fakeFs({
+ h.state.workdir = fakeFs({
'.switch/agents/cc-hoot-main.json': credsJson('sw-1'),
'.claude/agents/cc-hoot-main.md': '# def',
});
@@ -335,7 +335,7 @@ describe('migrateAgentStorage', () => {
});
it('does not latch the marker when an agent migration throws', async () => {
- h.state.workspace = fakeFs({
+ h.state.workdir = fakeFs({
'.switch/agents/cc-hoot-main.json': credsJson('sw-1'),
'.claude/agents/cc-hoot-main.md': '# def',
});
diff --git a/console/apps/switch-console-desktop/src/main/core/agents/migrate-agent-storage.ts b/console/apps/switch-console-desktop/src/main/core/agents/migrate-agent-storage.ts
index 51a370cdc..9ca238177 100644
--- a/console/apps/switch-console-desktop/src/main/core/agents/migrate-agent-storage.ts
+++ b/console/apps/switch-console-desktop/src/main/core/agents/migrate-agent-storage.ts
@@ -11,7 +11,7 @@ import {
completedAgentStorageMigrationGeneration,
markAgentStorageMigrationComplete,
} from './agent-storage-migration-marker';
-import { resolveWorkspaceFsFor } from './agent-workspace-fs';
+import { resolveWorkdirFsFor } from './agent-workdir-fs';
import { getAgents } from './getAgents';
import { agentSettingsRelativePath, SWITCH_SETTINGS_RELATIVE_PATH } from './switch-settings-paths';
import { writeNeutralAgentSettingsFs } from './write-switch-settings';
@@ -32,7 +32,7 @@ import { writeNeutralAgentSettingsFs } from './write-switch-settings';
*/
export async function migrateAgentStorage(): Promise<void> {
// Once a full pass has migrated every agent, never re-run: the steady-state
- // migration re-opens each agent's workspace filesystem (an SSH/SFTP round trip
+ // migration re-opens each agent's workdir filesystem (an SSH/SFTP round trip
// per remote agent) on every boot for no benefit.
const completed = await completedAgentStorageMigrationGeneration();
if (completed >= AGENT_STORAGE_MIGRATION_GENERATION) return;
@@ -65,7 +65,7 @@ export async function migrateAgentStorage(): Promise<void> {
*
* `completedGeneration` is the generation this install already finished, so a
* re-run can skip agents the new generation cannot change — the check happens
- * before the workspace filesystem is opened, which for a remote agent is an SSH
+ * before the workdir filesystem is opened, which for a remote agent is an SSH
* connect and an SFTP channel.
*/
async function migrateOne(agent: Agent, completedGeneration: number): Promise<boolean> {
@@ -78,13 +78,13 @@ async function migrateOne(agent: Agent, completedGeneration: number): Promise<bo
// Generation 2 only broadened step 1 to providers WITHOUT a behavior; for one
// that has it, every step is what generation 1 already ran. Skipping here is
- // what keeps the generation bump from re-opening a workspace per Claude agent.
+ // what keeps the generation bump from re-opening a workdir per Claude agent.
if (completedGeneration >= 1 && behavior) return false;
const location = await getLocationById(agent.locationId);
if (!location) return false;
- const workspace = await resolveWorkspaceFsFor(location.sshHost, location.dir);
+ const workdir = await resolveWorkdirFsFor(location.sshHost, location.dir);
try {
// The agent's identity is its single `name` (CHOO-1440): the creds/definition
// stem on disk. It is authoritative — earlier migrations, and the 0041 SQL
@@ -111,13 +111,13 @@ async function migrateOne(agent: Agent, completedGeneration: number): Promise<bo
// to recover it — nothing can reconstruct it from the gateway.
const idKeyedRelPath = agentSettingsRelativePath(agent.id);
const namedRelPath = agentSettingsRelativePath(name);
- const neutral = name === agent.id ? null : await workspace.fs.read(namedRelPath);
+ const neutral = name === agent.id ? null : await workdir.fs.read(namedRelPath);
if (neutral === null) {
const recovered =
- parseSwitchAgentCredentials(await workspace.fs.read(idKeyedRelPath), log) ??
- (behavior ? toCreds(await behavior.readLaunchEnv(workspace.fs, name)) : null) ??
+ parseSwitchAgentCredentials(await workdir.fs.read(idKeyedRelPath), log) ??
+ (behavior ? toCreds(await behavior.readLaunchEnv(workdir.fs, name)) : null) ??
(behavior
- ? parseSwitchAgentCredentials(await workspace.fs.read(SWITCH_SETTINGS_RELATIVE_PATH), log)
+ ? parseSwitchAgentCredentials(await workdir.fs.read(SWITCH_SETTINGS_RELATIVE_PATH), log)
: null);
if (recovered && !belongsToAgent(agent, recovered)) {
log.warn('migrateAgentStorage: recovered credentials name a different Switch agent', {
@@ -128,7 +128,7 @@ async function migrateOne(agent: Agent, completedGeneration: number): Promise<bo
foundSwitchAgentId: recovered.agentId,
});
} else if (recovered) {
- await writeNeutralAgentSettingsFs(workspace.fs, {
+ await writeNeutralAgentSettingsFs(workdir.fs, {
slug: name,
apiEndpoint: recovered.apiEndpoint,
apiToken: recovered.token,
@@ -141,9 +141,9 @@ async function migrateOne(agent: Agent, completedGeneration: number): Promise<bo
// Remove the stale ID-keyed neutral file once the name-keyed one is in place:
// an incomplete leftover there otherwise shadows the real creds in the
// session preflight (which scans both), and a complete one is now redundant.
- if (name !== agent.id && (await workspace.fs.read(namedRelPath)) !== null) {
- if ((await workspace.fs.read(idKeyedRelPath)) !== null) {
- await workspace.fs.delete(idKeyedRelPath);
+ if (name !== agent.id && (await workdir.fs.read(namedRelPath)) !== null) {
+ if ((await workdir.fs.read(idKeyedRelPath)) !== null) {
+ await workdir.fs.delete(idKeyedRelPath);
changed = true;
}
}
@@ -151,14 +151,14 @@ async function migrateOne(agent: Agent, completedGeneration: number): Promise<bo
// 2. Definition: ensure the provider has an on-disk definition for this agent
// so it runs as a named repository-defined agent. Behavior providers only —
// a provider without definitions (Codex) has nothing to write here.
- if (behavior && (await behavior.readDefinition(workspace.fs, name)) === null) {
- await behavior.writeDefinition(workspace.fs, { name, description });
+ if (behavior && (await behavior.readDefinition(workdir.fs, name)) === null) {
+ await behavior.writeDefinition(workdir.fs, { name, description });
changed = true;
}
return changed;
} finally {
- workspace.close();
+ workdir.close();
}
}
diff --git a/console/apps/switch-console-desktop/src/main/core/agents/onboard-location-agents.test.ts b/console/apps/switch-console-desktop/src/main/core/agents/onboard-location-agents.test.ts
index a5c1ed637..9f9019727 100644
--- a/console/apps/switch-console-desktop/src/main/core/agents/onboard-location-agents.test.ts
+++ b/console/apps/switch-console-desktop/src/main/core/agents/onboard-location-agents.test.ts
@@ -51,8 +51,8 @@ vi.mock('./getAgents', () => ({
vi.mock('@main/core/workspaces/workspaces-store', () => ({
requireSoleWorkspaceForServer: vi.fn(async (serverId: string) => ({ id: `ws-${serverId}` })),
}));
-vi.mock('./agent-workspace-fs', () => ({
- resolveWorkspaceFsFor: vi.fn(async () => ({
+vi.mock('./agent-workdir-fs', () => ({
+ resolveWorkdirFsFor: vi.fn(async () => ({
fs: {} as PluginFs,
homeFs: {} as PluginFs,
close: vi.fn(),
diff --git a/console/apps/switch-console-desktop/src/main/core/agents/onboard-location-agents.ts b/console/apps/switch-console-desktop/src/main/core/agents/onboard-location-agents.ts
index 27eeb1a53..6a9c81c9a 100644
--- a/console/apps/switch-console-desktop/src/main/core/agents/onboard-location-agents.ts
+++ b/console/apps/switch-console-desktop/src/main/core/agents/onboard-location-agents.ts
@@ -17,7 +17,7 @@ import type { AgentProviderId } from '@shared/core/providers/agent-provider-regi
import type { SwitchServer } from '@shared/core/switch-servers/switch-servers';
import { basenameFromAnyPath } from '@shared/path-name';
import { agentEvents } from './agent-events';
-import { resolveWorkspaceFsFor, type WorkspaceFs } from './agent-workspace-fs';
+import { resolveWorkdirFsFor, type WorkdirFs } from './agent-workdir-fs';
import { createAgent } from './createAgent';
import { getLocationAgentsInWorkspace } from './getAgents';
import { registerAgentIdentity } from './register-agent-identity';
@@ -85,7 +85,7 @@ async function resolveIdentity(
description: string | null,
ctx: {
server: SwitchServer;
- workspace: WorkspaceFs;
+ workdir: WorkdirFs;
credsByName: Map<string, { switchAgentId: string | null; apiEndpoint: string | null }>;
dir: string;
}
@@ -147,7 +147,7 @@ async function resolveIdentity(
};
}
- await writeNeutralAgentSettingsFs(ctx.workspace.fs, {
+ await writeNeutralAgentSettingsFs(ctx.workdir.fs, {
slug: name,
apiEndpoint: ctx.server.apiUrl,
apiToken: registered.apiKey,
@@ -202,11 +202,11 @@ export async function onboardLocationAgents(
(await getLocationAgentsInWorkspace(location.id, targetWorkspace.id)).map((a) => a.name)
);
- const workspace = await resolveWorkspaceFsFor(params.sshHost, params.dir);
+ const workdir = await resolveWorkdirFsFor(params.sshHost, params.dir);
const created: Agent[] = [];
try {
- const definitions = await behavior.discoverDefinitions(workspace.fs);
- const local = await behavior.discoverLocal(workspace.fs, workspace.homeFs);
+ const definitions = await behavior.discoverDefinitions(workdir.fs);
+ const local = await behavior.discoverLocal(workdir.fs, workdir.homeFs);
const credsByName = new Map(local.map((l) => [l.name, l]));
// Onboardable = a definition that can join Switch and isn't already a row.
@@ -236,7 +236,7 @@ export async function onboardLocationAgents(
for (const def of selected) {
const resolved = await resolveIdentity(def.name, def.description, {
server,
- workspace,
+ workdir,
credsByName,
dir: params.dir,
});
@@ -263,7 +263,7 @@ export async function onboardLocationAgents(
});
}
} finally {
- workspace.close();
+ workdir.close();
}
if (created.length === 0) {
diff --git a/console/apps/switch-console-desktop/src/main/core/agents/remove-launch-profile.ts b/console/apps/switch-console-desktop/src/main/core/agents/remove-launch-profile.ts
index 42da7f49e..b3b4dd2ee 100644
--- a/console/apps/switch-console-desktop/src/main/core/agents/remove-launch-profile.ts
+++ b/console/apps/switch-console-desktop/src/main/core/agents/remove-launch-profile.ts
@@ -15,7 +15,7 @@ import { connectRemoteAgent } from './connect-remote-agent';
*
* The profile lives in the home scope, not the working dir, so it is reached
* through the same home filesystem that wrote it: local disk for a local agent,
- * and the exec-backed remote home for a remote one (the repo-dir `WorkspaceFs`
+ * and the exec-backed remote home for a remote one (the repo-dir `WorkdirFs`
* used elsewhere in teardown deliberately has no writable home for remote
* agents). Best-effort and isolated: a filesystem or connection failure is
* logged, not thrown, so the rest of the agent's teardown still runs — but it is
diff --git a/console/apps/switch-console-desktop/src/main/core/agents/remove-loadable-agent-config.ts b/console/apps/switch-console-desktop/src/main/core/agents/remove-loadable-agent-config.ts
index dafa03c4e..931491e8e 100644
--- a/console/apps/switch-console-desktop/src/main/core/agents/remove-loadable-agent-config.ts
+++ b/console/apps/switch-console-desktop/src/main/core/agents/remove-loadable-agent-config.ts
@@ -1,5 +1,5 @@
import { log } from '@main/lib/logger';
-import { resolveWorkspaceFsFor } from './agent-workspace-fs';
+import { resolveWorkdirFsFor } from './agent-workdir-fs';
import { agentSettingsRelativePath } from './switch-settings-paths';
export type RemoveLoadableAgentConfigParams = {
@@ -27,7 +27,7 @@ export async function removeLoadableAgentConfig(
params: RemoveLoadableAgentConfigParams
): Promise<RemoveLoadableAgentConfigResult> {
const relPath = agentSettingsRelativePath(params.name);
- const ctx = await resolveWorkspaceFsFor(params.sshHost, params.dir);
+ const ctx = await resolveWorkdirFsFor(params.sshHost, params.dir);
try {
const existing = await ctx.fs.read(relPath);
if (existing === null) return { removed: false, reason: 'not-found' };
diff --git a/console/apps/switch-console-desktop/src/main/core/agents/renameAgent.test.ts b/console/apps/switch-console-desktop/src/main/core/agents/renameAgent.test.ts
index 747a85b0b..70483a665 100644
--- a/console/apps/switch-console-desktop/src/main/core/agents/renameAgent.test.ts
+++ b/console/apps/switch-console-desktop/src/main/core/agents/renameAgent.test.ts
@@ -44,8 +44,8 @@ vi.mock('./agent-location', () => ({
getAgentLocation: vi.fn(async () => ({ sshHost: null, dir: '/repo' })),
getRemoteAgentLocation: vi.fn(async () => null),
}));
-vi.mock('./agent-workspace-fs', () => ({
- resolveWorkspaceFsFor: vi.fn(async () => ({ fs: h.state.fs, close: vi.fn() })),
+vi.mock('./agent-workdir-fs', () => ({
+ resolveWorkdirFsFor: vi.fn(async () => ({ fs: h.state.fs, close: vi.fn() })),
}));
vi.mock('./getAgentById', () => ({
getAgentById: vi.fn(async () => ({
diff --git a/console/apps/switch-console-desktop/src/main/core/agents/renameAgent.ts b/console/apps/switch-console-desktop/src/main/core/agents/renameAgent.ts
index d3d232f77..51c9ce549 100644
--- a/console/apps/switch-console-desktop/src/main/core/agents/renameAgent.ts
+++ b/console/apps/switch-console-desktop/src/main/core/agents/renameAgent.ts
@@ -10,7 +10,7 @@ import type { Agent, RenameAgentParams } from '@shared/core/agents/agents';
import { agentEvents } from './agent-events';
import { getAgentLocation } from './agent-location';
import { agentNameTaken } from './agent-name-taken';
-import { resolveWorkspaceFsFor } from './agent-workspace-fs';
+import { resolveWorkdirFsFor } from './agent-workdir-fs';
import { getAgentById } from './getAgentById';
import { ensureRemoteWatcher } from './remote-watcher';
import { removeAgentLaunchProfile } from './remove-launch-profile';
@@ -32,14 +32,14 @@ async function moveSidecarToNewName(_previous: Agent, renamed: Agent): Promise<v
* is using.
*/
async function foreignCredentialsOwnerForMove(
- workspaceFs: PluginFs,
+ workdirFs: PluginFs,
credsRaw: string,
to: string
): Promise<string | null> {
const source = parseSwitchAgentCredentials(credsRaw, log);
if (!source) return null;
return foreignCredentialsEndpoint(
- await workspaceFs.read(agentSettingsRelativePath(to)),
+ await workdirFs.read(agentSettingsRelativePath(to)),
source.apiEndpoint
);
}
@@ -58,7 +58,7 @@ async function foreignCredentialsAtNewName(agent: Agent, to: string): Promise<st
if ((agent.name ?? agent.id) === to) return null;
try {
const location = await getAgentLocation(agent);
- const ctx = await resolveWorkspaceFsFor(location.sshHost, location.dir);
+ const ctx = await resolveWorkdirFsFor(location.sshHost, location.dir);
try {
const creds = await ctx.fs.read(agentSettingsRelativePath(agent.name ?? agent.id));
return creds === null ? null : await foreignCredentialsOwnerForMove(ctx.fs, creds, to);
@@ -100,7 +100,7 @@ async function moveProvisionedFiles(previous: Agent, renamed: Agent): Promise<vo
try {
const location = await getAgentLocation(previous);
- const ctx = await resolveWorkspaceFsFor(location.sshHost, location.dir);
+ const ctx = await resolveWorkdirFsFor(location.sshHost, location.dir);
try {
const creds = await ctx.fs.read(agentSettingsRelativePath(from));
if (creds !== null) {
@@ -134,7 +134,7 @@ async function moveProvisionedFiles(previous: Agent, renamed: Agent): Promise<vo
// A launch profile (Codex) is keyed on the agent name, so the rename orphans
// the old-named one; it is rewritten under the new name on the next launch,
// so just drop the stale file. Reached through its own home filesystem (the
- // repo-dir workspace fs above has no writable home for a remote agent).
+ // repo-dir workdir fs above has no writable home for a remote agent).
await removeAgentLaunchProfile(previous, location, from);
} catch (error) {
log.warn('renameAgent: failed to move the agent files to the new name', {
diff --git a/console/apps/switch-console-desktop/src/main/core/agents/write-switch-settings.test.ts b/console/apps/switch-console-desktop/src/main/core/agents/write-switch-settings.test.ts
index ecbfeb293..d0fc69f1f 100644
--- a/console/apps/switch-console-desktop/src/main/core/agents/write-switch-settings.test.ts
+++ b/console/apps/switch-console-desktop/src/main/core/agents/write-switch-settings.test.ts
@@ -259,19 +259,15 @@ describe('writeNeutralAgentSettingsFs, against another install of Switch Console
it('reports the owning server through foreignCredentialsOwnerFs, for a caller checking before it registers', async () => {
await seed('shared-name', otherInstall);
- const workspaceFs = createPluginFs(dir);
+ const workdirFs = createPluginFs(dir);
expect(
- await foreignCredentialsOwnerFs(workspaceFs, 'shared-name', 'https://switch.example.com')
+ await foreignCredentialsOwnerFs(workdirFs, 'shared-name', 'https://switch.example.com')
).toBe('https://other-switch.example.com');
expect(
- await foreignCredentialsOwnerFs(
- workspaceFs,
- 'shared-name',
- 'https://other-switch.example.com'
- )
+ await foreignCredentialsOwnerFs(workdirFs, 'shared-name', 'https://other-switch.example.com')
).toBeNull();
- expect(await foreignCredentialsOwnerFs(workspaceFs, 'absent', 'https://switch.example.com')) //
+ expect(await foreignCredentialsOwnerFs(workdirFs, 'absent', 'https://switch.example.com')) //
.toBeNull();
});
});
diff --git a/console/apps/switch-console-desktop/src/main/core/agents/write-switch-settings.ts b/console/apps/switch-console-desktop/src/main/core/agents/write-switch-settings.ts
index 1db3963d3..2f9b8d22e 100644
--- a/console/apps/switch-console-desktop/src/main/core/agents/write-switch-settings.ts
+++ b/console/apps/switch-console-desktop/src/main/core/agents/write-switch-settings.ts
@@ -405,11 +405,11 @@ export class ExistingAgentCredentialsError extends Error {
* below re-checks, so a path that skips this one still cannot clobber.
*/
export async function foreignCredentialsOwnerFs(
- workspaceFs: PluginFs,
+ workdirFs: PluginFs,
slug: string,
apiEndpoint: string
): Promise<string | null> {
- const existingRaw = await workspaceFs.read(agentSettingsRelativePath(slug));
+ const existingRaw = await workdirFs.read(agentSettingsRelativePath(slug));
return foreignCredentialsEndpoint(existingRaw, apiEndpoint);
}
@@ -474,11 +474,11 @@ export function existingAgentIdInSlot(
* before the token reaches disk.
*/
export async function writeNeutralAgentSettingsFs(
- workspaceFs: PluginFs,
+ workdirFs: PluginFs,
params: { slug: string; expectedAgentId?: string } & SwitchSettingsCredentials
): Promise<void> {
const relPath = agentSettingsRelativePath(params.slug);
- const existingRaw = await workspaceFs.read(relPath);
+ const existingRaw = await workdirFs.read(relPath);
const existingEndpoint = foreignCredentialsEndpoint(existingRaw, params.apiEndpoint);
if (existingEndpoint !== null) {
throw new ForeignAgentCredentialsError({
@@ -508,8 +508,8 @@ export async function writeNeutralAgentSettingsFs(
});
}
- if (!(await workspaceFs.exists(SWITCH_AGENTS_GITIGNORE_RELATIVE))) {
- await workspaceFs.write(SWITCH_AGENTS_GITIGNORE_RELATIVE, '*\n');
+ if (!(await workdirFs.exists(SWITCH_AGENTS_GITIGNORE_RELATIVE))) {
+ await workdirFs.write(SWITCH_AGENTS_GITIGNORE_RELATIVE, '*\n');
}
- await workspaceFs.write(relPath, mergeAgentCredentials(existingRaw, params));
+ await workdirFs.write(relPath, mergeAgentCredentials(existingRaw, params));
}
diff --git a/console/apps/switch-console-desktop/src/main/core/switch-rooms/switch-credentials.ts b/console/apps/switch-console-desktop/src/main/core/switch-rooms/switch-credentials.ts
index 1e53e273f..d3986f655 100644
--- a/console/apps/switch-console-desktop/src/main/core/switch-rooms/switch-credentials.ts
+++ b/console/apps/switch-console-desktop/src/main/core/switch-rooms/switch-credentials.ts
@@ -102,12 +102,12 @@ export async function readAgentSwitchEnv(
* the agent, so the miss is warned about here rather than at each call site.
*/
export async function readAgentSwitchEnvFromFs(
- workspaceFs: PluginFs,
+ workdirFs: PluginFs,
slug: string,
log: CredentialsLogger
): Promise<Record<string, string>> {
const relPath = agentSettingsRelativePath(slug);
- const env = credentialsAsEnv(parseSwitchAgentCredentials(await workspaceFs.read(relPath), log));
+ const env = credentialsAsEnv(parseSwitchAgentCredentials(await workdirFs.read(relPath), log));
if (Object.keys(env).length === 0) {
log.warn(
'readAgentSwitchEnvFromFs: no Switch identity for agent; session will not authenticate as it',
diff --git a/console/apps/switch-console-desktop/src/main/core/switch-servers/controller.ts b/console/apps/switch-console-desktop/src/main/core/switch-servers/controller.ts
index 3da6c8e02..b4db6d50f 100644
--- a/console/apps/switch-console-desktop/src/main/core/switch-servers/controller.ts
+++ b/console/apps/switch-console-desktop/src/main/core/switch-servers/controller.ts
@@ -672,7 +672,7 @@ export const switchServersController = createRPCController({
/**
* Search a bridge's own user directory so the signed-in user can find
- * themselves before they have ever posted in the workspace (CHOO-2137).
+ * themselves before they have ever posted in the chat workspace (CHOO-2137).
*/
searchBridgeDirectory: async (params: {
serverId: string;
diff --git a/console/packages/core/src/agents/plugins/capabilities/repo-agents.ts b/console/packages/core/src/agents/plugins/capabilities/repo-agents.ts
index 5bfc7052f..9ff5b50c2 100644
--- a/console/packages/core/src/agents/plugins/capabilities/repo-agents.ts
+++ b/console/packages/core/src/agents/plugins/capabilities/repo-agents.ts
@@ -127,19 +127,19 @@ export type RepoAgentAttributes = Record<string, RepoAgentAttributeValue>;
* provider's business and lives behind this behavior; the main process supplies a
* `PluginFs` for the IO and owns the provider-neutral gateway reconciliation.
*
- * `workspaceFs` is rooted at the agent's working directory; `homeFs` at the user's
+ * `workdirFs` is rooted at the agent's working directory; `homeFs` at the user's
* home — definitions may resolve in either scope.
*/
export type IRepoAgentsBehavior = {
/** Runnable agents, from the working dir's on-disk credentials + definitions. */
- discoverLocal(workspaceFs: PluginFs, homeFs: PluginFs): Promise<LocalRepoAgent[]>;
+ discoverLocal(workdirFs: PluginFs, homeFs: PluginFs): Promise<LocalRepoAgent[]>;
/** Agent definitions in the working dir, for onboarding (project scope). */
- discoverDefinitions(workspaceFs: PluginFs): Promise<RepoAgentDefinition[]>;
+ discoverDefinitions(workdirFs: PluginFs): Promise<RepoAgentDefinition[]>;
/** Provider-specific CLI args that run the CLI as the named agent. Pure — the
* caller passes them to `buildCommand` as `agentArgs` (not user extra args). */
launchArgs(workingDir: string, agentName: string): string[];
/** The named agent's Switch credentials as env vars, for the launched session. */
- readLaunchEnv(workspaceFs: PluginFs, agentName: string): Promise<Record<string, string>>;
+ readLaunchEnv(workdirFs: PluginFs, agentName: string): Promise<Record<string, string>>;
/** The attribute fields this provider supports, in display order. Drives the
* create/edit form; the first two are always `name` and `description`. */
attributeFields(): RepoAgentField[];
@@ -155,16 +155,16 @@ export type IRepoAgentsBehavior = {
/** The definition file's path, relative to the working directory. */
definitionPath(name: string): string;
/** Create or overwrite a named agent's on-disk definition from its attributes
- * (workspace scope). `attributes.name` selects the agent. */
- writeDefinition(workspaceFs: PluginFs, attributes: RepoAgentAttributes): Promise<void>;
+ * (workdir scope). `attributes.name` selects the agent. */
+ writeDefinition(workdirFs: PluginFs, attributes: RepoAgentAttributes): Promise<void>;
/** The current attribute values for an existing agent definition, keyed to
* {@link attributeFields}, or null if no definition exists. */
- readDefinition(workspaceFs: PluginFs, name: string): Promise<RepoAgentAttributes | null>;
+ readDefinition(workdirFs: PluginFs, name: string): Promise<RepoAgentAttributes | null>;
/** Remove a named agent's provider-specific files — its definition and any
- * legacy per-agent settings (workspace scope). The provider-neutral Switch
+ * legacy per-agent settings (workdir scope). The provider-neutral Switch
* credentials are not this hook's to remove: they are written for every
* provider, so they are torn down by the caller for every provider too. */
- removeLocal(workspaceFs: PluginFs, name: string): Promise<void>;
+ removeLocal(workdirFs: PluginFs, name: string): Promise<void>;
};
/**
diff --git a/console/packages/plugins/src/agents/impl/claude/subagents.test.ts b/console/packages/plugins/src/agents/impl/claude/subagents.test.ts
index 785b787db..c333c4261 100644
--- a/console/packages/plugins/src/agents/impl/claude/subagents.test.ts
+++ b/console/packages/plugins/src/agents/impl/claude/subagents.test.ts
@@ -56,7 +56,7 @@ describe('claudeRepoAgentsBehavior.launchArgs', () => {
describe('claudeRepoAgentsBehavior.discoverDefinitions', () => {
it('parses definitions, eligibility, and registered state', async () => {
- const workspaceFs = fakeFs({
+ const workdirFs = fakeFs({
[defRel('reviewer')]:
'---\nname: reviewer\ndescription: Reviews code\nmodel: opus\n---\nbody',
// No `tools` line → eligible (inherits all tools), and registered (creds exist).
@@ -65,7 +65,7 @@ describe('claudeRepoAgentsBehavior.discoverDefinitions', () => {
[defRel('linter')]: '---\ndescription: Lints\ntools: Read, Edit\n---\n',
});
- const defs = await claudeRepoAgentsBehavior.discoverDefinitions(workspaceFs);
+ const defs = await claudeRepoAgentsBehavior.discoverDefinitions(workdirFs);
expect(defs).toEqual([
{ name: 'linter', description: 'Lints', model: null, eligible: false, registered: false },
@@ -82,7 +82,7 @@ describe('claudeRepoAgentsBehavior.discoverDefinitions', () => {
describe('claudeRepoAgentsBehavior.discoverLocal', () => {
it('reads creds env and definition meta, project scope then home', async () => {
- const workspaceFs = fakeFs({
+ const workdirFs = fakeFs({
[settingsRel('reviewer')]:
'{"env":{"SWITCH_AGENT_ID":"a1","SWITCH_API_ENDPOINT":"https://s"}}',
[defRel('reviewer')]: '---\ndescription: Reviews\nmodel: opus\n---\n',
@@ -92,7 +92,7 @@ describe('claudeRepoAgentsBehavior.discoverLocal', () => {
[defRel('helper')]: '---\ndescription: From home\n---\n',
});
- const local = await claudeRepoAgentsBehavior.discoverLocal(workspaceFs, homeFs);
+ const local = await claudeRepoAgentsBehavior.discoverLocal(workdirFs, homeFs);
expect(local).toEqual([
{
@@ -115,12 +115,12 @@ describe('claudeRepoAgentsBehavior.discoverLocal', () => {
describe('claudeRepoAgentsBehavior.readLaunchEnv', () => {
it('returns only non-empty SWITCH_* keys', async () => {
- const workspaceFs = fakeFs({
+ const workdirFs = fakeFs({
[settingsRel('reviewer')]:
'{"env":{"SWITCH_AGENT_ID":"a1","SWITCH_API_TOKEN":"t","SWITCH_API_ENDPOINT":" ","OTHER":"x"}}',
});
- expect(await claudeRepoAgentsBehavior.readLaunchEnv(workspaceFs, 'reviewer')).toEqual({
+ expect(await claudeRepoAgentsBehavior.readLaunchEnv(workdirFs, 'reviewer')).toEqual({
SWITCH_AGENT_ID: 'a1',
SWITCH_API_TOKEN: 't',
});
@@ -133,22 +133,22 @@ describe('claudeRepoAgentsBehavior.readLaunchEnv', () => {
describe('claudeRepoAgentsBehavior.writeDefinition / readDefinition', () => {
it('writes frontmatter + body without a tools line, and round-trips attributes', async () => {
- const workspaceFs = fakeFs({});
- await claudeRepoAgentsBehavior.writeDefinition(workspaceFs, {
+ const workdirFs = fakeFs({});
+ await claudeRepoAgentsBehavior.writeDefinition(workdirFs, {
name: 'reviewer',
description: 'Reviews diffs',
model: 'opus',
instructions: 'You are a careful reviewer.',
});
- const raw = await workspaceFs.read(defRel('reviewer'));
+ const raw = await workdirFs.read(defRel('reviewer'));
expect(raw).toBe(
'---\nname: reviewer\ndescription: Reviews diffs\nmodel: opus\n---\n\nYou are a careful reviewer.\n'
);
// No `tools:` line → the subagent inherits all tools and is Switch-eligible.
expect(raw).not.toContain('tools:');
- const attrs = await claudeRepoAgentsBehavior.readDefinition(workspaceFs, 'reviewer');
+ const attrs = await claudeRepoAgentsBehavior.readDefinition(workdirFs, 'reviewer');
expect(attrs).toMatchObject({
name: 'reviewer',
description: 'Reviews diffs',
@@ -159,14 +159,14 @@ describe('claudeRepoAgentsBehavior.writeDefinition / readDefinition', () => {
});
it('falls back to the description for the body when there are no instructions', async () => {
- const workspaceFs = fakeFs({});
- await claudeRepoAgentsBehavior.writeDefinition(workspaceFs, {
+ const workdirFs = fakeFs({});
+ await claudeRepoAgentsBehavior.writeDefinition(workdirFs, {
name: 'reviewer',
description: 'Reviews diffs',
});
// Claude Code reads the body as the system prompt, so it cannot be empty.
- expect(await workspaceFs.read(defRel('reviewer'))).toBe(
+ expect(await workdirFs.read(defRel('reviewer'))).toBe(
'---\nname: reviewer\ndescription: Reviews diffs\n---\n\nReviews diffs\n'
);
});
@@ -174,13 +174,13 @@ describe('claudeRepoAgentsBehavior.writeDefinition / readDefinition', () => {
it('does not read the description stand-in back as instructions', async () => {
// Otherwise the round trip invents a prompt the user never wrote, and the
// next write pins it as if they had.
- const workspaceFs = fakeFs({});
- await claudeRepoAgentsBehavior.writeDefinition(workspaceFs, {
+ const workdirFs = fakeFs({});
+ await claudeRepoAgentsBehavior.writeDefinition(workdirFs, {
name: 'reviewer',
description: 'Reviews diffs',
});
- const attrs = await claudeRepoAgentsBehavior.readDefinition(workspaceFs, 'reviewer');
+ const attrs = await claudeRepoAgentsBehavior.readDefinition(workdirFs, 'reviewer');
expect(attrs?.instructions).toBe('');
});
@@ -204,24 +204,24 @@ describe('claudeRepoAgentsBehavior.writeDefinition / readDefinition', () => {
});
it('always merges the Switch tools into a non-empty tools list', async () => {
- const workspaceFs = fakeFs({});
- await claudeRepoAgentsBehavior.writeDefinition(workspaceFs, {
+ const workdirFs = fakeFs({});
+ await claudeRepoAgentsBehavior.writeDefinition(workdirFs, {
name: 'reviewer',
description: 'Reviews diffs',
tools: ['Read', 'Grep'],
instructions: 'body',
});
- const raw = (await workspaceFs.read(defRel('reviewer'))) ?? '';
+ const raw = (await workdirFs.read(defRel('reviewer'))) ?? '';
expect(raw).toContain('tools: Read, Grep, mcp__switch');
// Read-back strips the Switch rules so the form shows only the user's tools.
- const attrs = await claudeRepoAgentsBehavior.readDefinition(workspaceFs, 'reviewer');
+ const attrs = await claudeRepoAgentsBehavior.readDefinition(workdirFs, 'reviewer');
expect(attrs?.tools).toEqual(['Read', 'Grep']);
});
it('strips the retired connector-plugin rules an older Switch Console wrote', async () => {
- const workspaceFs = fakeFs({
+ const workdirFs = fakeFs({
[defRel('reviewer')]: [
'---',
'name: reviewer',
@@ -233,20 +233,20 @@ describe('claudeRepoAgentsBehavior.writeDefinition / readDefinition', () => {
].join('\n'),
});
- const attrs = await claudeRepoAgentsBehavior.readDefinition(workspaceFs, 'reviewer');
+ const attrs = await claudeRepoAgentsBehavior.readDefinition(workdirFs, 'reviewer');
expect(attrs?.tools).toEqual(['Read']);
// And it is not written back: only the rule Switch Console still authors is.
- await claudeRepoAgentsBehavior.writeDefinition(workspaceFs, attrs ?? {});
- const raw = (await workspaceFs.read(defRel('reviewer'))) ?? '';
+ await claudeRepoAgentsBehavior.writeDefinition(workdirFs, attrs ?? {});
+ const raw = (await workdirFs.read(defRel('reviewer'))) ?? '';
expect(raw).toContain('tools: Read, mcp__switch\n');
expect(raw).not.toContain('switch-connector');
expect(raw).not.toContain('switch-channel');
});
it('serialises optional scalar, number, and boolean fields and omits empty ones', async () => {
- const workspaceFs = fakeFs({});
- await claudeRepoAgentsBehavior.writeDefinition(workspaceFs, {
+ const workdirFs = fakeFs({});
+ await claudeRepoAgentsBehavior.writeDefinition(workdirFs, {
name: 'worker',
description: 'line one\nline two',
model: '',
@@ -257,7 +257,7 @@ describe('claudeRepoAgentsBehavior.writeDefinition / readDefinition', () => {
instructions: 'do work',
});
- const raw = (await workspaceFs.read(defRel('worker'))) ?? '';
+ const raw = (await workdirFs.read(defRel('worker'))) ?? '';
expect(raw).toContain('description: line one line two');
expect(raw).toContain('color: blue');
expect(raw).toContain('maxTurns: 5');
@@ -265,7 +265,7 @@ describe('claudeRepoAgentsBehavior.writeDefinition / readDefinition', () => {
expect(raw).not.toContain('model:');
expect(raw).not.toContain('permissionMode:');
- const attrs = await claudeRepoAgentsBehavior.readDefinition(workspaceFs, 'worker');
+ const attrs = await claudeRepoAgentsBehavior.readDefinition(workdirFs, 'worker');
expect(attrs).toMatchObject({ color: 'blue', maxTurns: 5, background: true, model: '' });
});
@@ -285,26 +285,26 @@ describe('claudeRepoAgentsBehavior.attributeFields', () => {
describe('claudeRepoAgentsBehavior.removeLocal', () => {
it('deletes the definition and the legacy per-agent settings', async () => {
- const workspaceFs = fakeFs({
+ const workdirFs = fakeFs({
[defRel('reviewer')]: '---\nname: reviewer\ndescription: x\n---\n',
[settingsRel('reviewer')]: '{"env":{}}',
});
- await claudeRepoAgentsBehavior.removeLocal(workspaceFs, 'reviewer');
+ await claudeRepoAgentsBehavior.removeLocal(workdirFs, 'reviewer');
- expect(await workspaceFs.exists(defRel('reviewer'))).toBe(false);
- expect(await workspaceFs.exists(settingsRel('reviewer'))).toBe(false);
+ expect(await workdirFs.exists(defRel('reviewer'))).toBe(false);
+ expect(await workdirFs.exists(settingsRel('reviewer'))).toBe(false);
});
it('leaves the provider-neutral credentials to the caller, which removes them for every provider', async () => {
const neutralRel = '.switch/agents/reviewer.json';
- const workspaceFs = fakeFs({
+ const workdirFs = fakeFs({
[defRel('reviewer')]: '---\nname: reviewer\ndescription: x\n---\n',
[neutralRel]: '{"env":{}}',
});
- await claudeRepoAgentsBehavior.removeLocal(workspaceFs, 'reviewer');
+ await claudeRepoAgentsBehavior.removeLocal(workdirFs, 'reviewer');
- expect(await workspaceFs.exists(neutralRel)).toBe(true);
+ expect(await workdirFs.exists(neutralRel)).toBe(true);
});
});
diff --git a/console/packages/plugins/src/agents/impl/claude/subagents.ts b/console/packages/plugins/src/agents/impl/claude/subagents.ts
index c15828049..d623b86ed 100644
--- a/console/packages/plugins/src/agents/impl/claude/subagents.ts
+++ b/console/packages/plugins/src/agents/impl/claude/subagents.ts
@@ -356,12 +356,12 @@ function neutralSettingsRelPath(name: string): string {
* yet migrated (CHOO-1440).
*/
async function readCredsObject(
- workspaceFs: PluginFs,
+ workdirFs: PluginFs,
name: string
): Promise<Record<string, unknown>> {
- const neutral = await workspaceFs.read(neutralSettingsRelPath(name));
+ const neutral = await workdirFs.read(neutralSettingsRelPath(name));
if (neutral !== null) return parseSettingsObject(neutral);
- return parseSettingsObject(await workspaceFs.read(settingsRelPath(name)));
+ return parseSettingsObject(await workdirFs.read(settingsRelPath(name)));
}
function definitionRelPath(name: string): string {
@@ -370,11 +370,11 @@ function definitionRelPath(name: string): string {
/** Description/model from a subagent's definition, project scope then user scope. */
async function readDefinitionMeta(
- workspaceFs: PluginFs,
+ workdirFs: PluginFs,
homeFs: PluginFs,
name: string
): Promise<{ description: string | null; model: string | null }> {
- const project = await workspaceFs.read(definitionRelPath(name));
+ const project = await workdirFs.read(definitionRelPath(name));
if (project !== null) {
const fm = parseFrontmatter(project);
return { description: fm.description, model: fm.model };
@@ -388,27 +388,27 @@ async function readDefinitionMeta(
}
export const claudeRepoAgentsBehavior: IRepoAgentsBehavior = {
- async discoverLocal(workspaceFs, homeFs): Promise<LocalRepoAgent[]> {
+ async discoverLocal(workdirFs, homeFs): Promise<LocalRepoAgent[]> {
// Names come from either credentials location — the neutral `.switch/agents`
// dir and the legacy `.claude/switch-subagents` dir — so both migrated and
// un-migrated installs are discovered (CHOO-1440). Plain agents' creds files
// live in the neutral dir too (keyed by agent id, no `.claude/agents/<name>.md`
// definition); a neutral file counts as a subagent only when it has a
// definition, so those are filtered out here.
- const neutralCandidates = (await workspaceFs.list(SWITCH_AGENT_SETTINGS_DIR))
+ const neutralCandidates = (await workdirFs.list(SWITCH_AGENT_SETTINGS_DIR))
.filter((entry) => entry.endsWith('.json'))
.map((entry) => entry.slice(0, -'.json'.length))
.filter((name) => name.length > 0);
const neutralNames: string[] = [];
for (const name of neutralCandidates) {
if (
- (await workspaceFs.exists(definitionRelPath(name))) ||
+ (await workdirFs.exists(definitionRelPath(name))) ||
(await homeFs.exists(definitionRelPath(name)))
) {
neutralNames.push(name);
}
}
- const legacyNames = (await workspaceFs.list(CLAUDE_SUBAGENTS.dirRelative))
+ const legacyNames = (await workdirFs.list(CLAUDE_SUBAGENTS.dirRelative))
.filter((entry) => entry.endsWith(CLAUDE_SUBAGENTS.settingsSuffix))
.map((entry) => entry.slice(0, -CLAUDE_SUBAGENTS.settingsSuffix.length));
const names = [...new Set([...neutralNames, ...legacyNames])]
@@ -417,9 +417,9 @@ export const claudeRepoAgentsBehavior: IRepoAgentsBehavior = {
return Promise.all(
names.map(async (name) => {
- const settings = await readCredsObject(workspaceFs, name);
+ const settings = await readCredsObject(workdirFs, name);
const env = (settings.env ?? {}) as Record<string, unknown>;
- const { description, model } = await readDefinitionMeta(workspaceFs, homeFs, name);
+ const { description, model } = await readDefinitionMeta(workdirFs, homeFs, name);
return {
name,
description,
@@ -431,8 +431,8 @@ export const claudeRepoAgentsBehavior: IRepoAgentsBehavior = {
);
},
- async discoverDefinitions(workspaceFs): Promise<RepoAgentDefinition[]> {
- const entries = await workspaceFs.list(CLAUDE_SUBAGENTS.definitionsDirRelative);
+ async discoverDefinitions(workdirFs): Promise<RepoAgentDefinition[]> {
+ const entries = await workdirFs.list(CLAUDE_SUBAGENTS.definitionsDirRelative);
const files = entries
.filter((entry) => entry.endsWith(MD_SUFFIX))
.sort((a, b) => a.localeCompare(b));
@@ -440,10 +440,10 @@ export const claudeRepoAgentsBehavior: IRepoAgentsBehavior = {
return Promise.all(
files.map(async (file) => {
const content =
- (await workspaceFs.read(`${CLAUDE_SUBAGENTS.definitionsDirRelative}/${file}`)) ?? '';
+ (await workdirFs.read(`${CLAUDE_SUBAGENTS.definitionsDirRelative}/${file}`)) ?? '';
const fm = parseFrontmatter(content);
const name = fm.name ?? file.slice(0, -MD_SUFFIX.length);
- const registered = await workspaceFs.exists(settingsRelPath(name));
+ const registered = await workdirFs.exists(settingsRelPath(name));
return {
name,
description: fm.description,
@@ -468,8 +468,8 @@ export const claudeRepoAgentsBehavior: IRepoAgentsBehavior = {
];
},
- async readLaunchEnv(workspaceFs, agentName): Promise<Record<string, string>> {
- const settings = await readCredsObject(workspaceFs, agentName);
+ async readLaunchEnv(workdirFs, agentName): Promise<Record<string, string>> {
+ const settings = await readCredsObject(workdirFs, agentName);
const env = (settings.env ?? {}) as Record<string, unknown>;
const result: Record<string, string> = {};
for (const key of SWITCH_ENV_KEYS) {
@@ -491,13 +491,13 @@ export const claudeRepoAgentsBehavior: IRepoAgentsBehavior = {
return definitionRelPath(name);
},
- async writeDefinition(workspaceFs, attributes: RepoAgentAttributes): Promise<void> {
+ async writeDefinition(workdirFs, attributes: RepoAgentAttributes): Promise<void> {
const name = toScalar(attributes.name);
- await workspaceFs.write(definitionRelPath(name), serializeDefinition(attributes));
+ await workdirFs.write(definitionRelPath(name), serializeDefinition(attributes));
},
- async readDefinition(workspaceFs, name): Promise<RepoAgentAttributes | null> {
- const content = await workspaceFs.read(definitionRelPath(name));
+ async readDefinition(workdirFs, name): Promise<RepoAgentAttributes | null> {
+ const content = await workdirFs.read(definitionRelPath(name));
if (content === null) return null;
const fields = parseFrontmatterFields(content);
@@ -529,8 +529,8 @@ export const claudeRepoAgentsBehavior: IRepoAgentsBehavior = {
return attributes;
},
- async removeLocal(workspaceFs, name): Promise<void> {
- await workspaceFs.delete(definitionRelPath(name));
- await workspaceFs.delete(settingsRelPath(name));
+ async removeLocal(workdirFs, name): Promise<void> {
+ await workdirFs.delete(definitionRelPath(name));
+ await workdirFs.delete(settingsRelPath(name));
},
};