Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions docs/src/content/docs/docs/guides/mcp-proxy.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,10 @@ the authored URL remains its identity. Changing a tenant header selects a
separate grant. A declaration with headers may need one new sign-in when
upgrading from a version that did not partition its cache by headers.

Removing an installed or declared-only profile removes its OAuth subtree with
its other profile-owned runtime state. Cleanup rejects symbolic-link or
non-directory OAuth roots and retains retryable state on failure.
`allagents profile remove <name>` keeps the profile's OAuth subtree. Add
`--purge-session-data` to delete it for an installed or declared-only profile.
Purge rejects symbolic-link or non-directory OAuth roots and retains retryable
state on failure.

## Prerequisites

Expand Down
21 changes: 16 additions & 5 deletions docs/src/content/docs/docs/reference/cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ use [`self update`](#self-update).
allagents profile install <name> [--yes] [--dry-run] [--offline]
allagents profile list
allagents profile status [name]
allagents profile remove <name> [--yes] [--dry-run] [--offline]
allagents profile remove <name> [--yes] [--dry-run] [--offline] [--purge-session-data]
```

Profile declarations exist only in `~/.allagents/workspace.yaml`. `install`
Expand All @@ -132,10 +132,21 @@ installed, missing, drifted, partial, unsupported, and declaration-missing
resources. Omitting the name opens a selector only on an interactive terminal;
non-interactive and JSON callers must provide it.

Removal works from ownership state even after the declaration is deleted. It
deletes only unchanged managed resources, releases referenced resources, and
retains modified, shared, failed, or uncorroborated resources for inspection
and retry. There is intentionally no `allagents profile update`; use repeatable
Removal uninstalls owned launchers, plugins, and generated configuration where
ownership can be verified. It works from ownership state even after the
declaration is deleted and leaves `workspace.yaml` unchanged. Client runtime
directories, session data, and profile OAuth credentials are retained by
default, including with `--yes`.

Pass `--purge-session-data` to recursively delete eligible owned client roots
and remove the profile's OAuth state. This can delete untracked files inside
those owned roots. Roots with referenced or modified managed resources are
retained. Preview either plan with `--dry-run`, including in JSON mode.
`--yes` skips confirmation for the selected plan.

For an intentional purge, select the flag when uninstalling or when retrying a
failed purge. Successful removal releases ownership of retained client roots.
There is intentionally no `allagents profile update`; use repeatable
`allagents update --profile <name>`.

### status
Expand Down
25 changes: 13 additions & 12 deletions docs/src/content/docs/docs/reference/clients.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ remote MCP declarations share the generated `opencode.json`; portable
resolved only by the runtime.

Profile cleanup removes unchanged managed files and OpenCode's exact
runtime-generated `.gitignore`. A modified `.gitignore` or any unrelated file
retains the root and reports a partial removal instead of recursively deleting
unknown content.
runtime-generated `.gitignore` inside an owned profile root. The configuration
directory, modified files, and other runtime data are retained, including with
`--purge-session-data`.

### GitHub Copilot CLI

Expand Down Expand Up @@ -230,11 +230,12 @@ inventory inspection but are not treated as AllAgents-managed user or project
plugins.

The isolated root also holds Claude-managed credentials, sessions, trust state,
plugin caches, and runtime metadata. Removing an AllAgents-created profile
intentionally removes that isolated runtime state after native cleanup. Ambient
`~/.claude`, project files, and platform credential stores remain outside the
filesystem cleanup boundary; inherited authentication environment variables
can still override the selected profile login.
plugin caches, and runtime metadata. Profile removal retains that runtime state
by default. Use `--purge-session-data` to recursively clean up an eligible owned
root after native cleanup. Ambient `~/.claude`, project files, and platform
credential stores remain outside the filesystem cleanup boundary. Inherited
authentication environment variables can still override the selected profile
login.

### Codex

Expand Down Expand Up @@ -263,10 +264,10 @@ Isolated profile file installation does not currently translate hook
declarations; use native installation when a profile plugin requires them.

`CODEX_HOME` also contains Codex credentials, sessions, logs, and caches.
Recursive cleanup is limited to a client root AllAgents created for this
profile; removing that profile intentionally removes its isolated runtime
state. Ambient `~/.codex`, project files, and operating-system keyrings remain
outside the cleanup boundary.
Profile removal retains this runtime state by default. With
`--purge-session-data`, recursive cleanup is limited to an eligible owned
client root for the selected profile. Ambient `~/.codex`, project files, and
operating-system keyrings remain outside the cleanup boundary.

### Pi

Expand Down
4 changes: 2 additions & 2 deletions docs/src/content/docs/docs/reference/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,8 @@ never written to plans, launchers, profile state, or generated configuration.
Profile MCP is materialized inside the profile root. Codex writes
`clients/codex/home/<profile>.config.toml`; Copilot writes
`clients/copilot/home/mcp-config.json`. Proxied HTTP servers share OAuth only
inside that profile, under `oauth-proxy/<url-hash>`. Removing the profile removes
that profile-owned OAuth state.
inside that profile, under `oauth-proxy/<url-hash>`. Profile removal retains
that OAuth state by default. Pass `--purge-session-data` to delete it.

OpenCode profile settings accept `model`, `small_model`, `default_agent`,
`username`, `share`, `autoupdate`, `snapshot`, `subagent_depth`, `logLevel`,
Expand Down
7 changes: 7 additions & 0 deletions src/cli/commands/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,12 @@ type ProfileSelectionKind = 'install' | 'status' | 'remove';
function runtimeOptions(flags: {
readonly offline?: boolean;
readonly dryRun?: boolean;
readonly purgeSessionData?: boolean;
}): ProfileRuntimeOptions {
return {
...(flags.offline ? { offline: true } : {}),
...(flags.dryRun ? { dryRun: true } : {}),
...(flags.purgeSessionData ? { purgeSessionData: true } : {}),
};
}

Expand Down Expand Up @@ -240,6 +242,7 @@ async function executeMutation(
readonly yes: boolean;
readonly dryRun: boolean;
readonly offline: boolean;
readonly purgeSessionData?: boolean;
},
dependencies: ProfileCommandDependencies,
runtime: ProfileCommandRuntime,
Expand Down Expand Up @@ -443,6 +446,10 @@ export function createProfileCommand(
short: 'y',
description: 'Apply without asking for confirmation',
}),
purgeSessionData: flag({
long: 'purge-session-data',
description: 'Also delete session data in owned profile runtime roots',
}),
dryRun: flag({
long: 'dry-run',
description: 'Display the plan without making changes',
Expand Down
16 changes: 12 additions & 4 deletions src/cli/metadata/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,17 +204,25 @@ export const profileRemoveMeta: AgentCommandMeta = {
command: 'profile remove',
description: 'Remove an installed or declared global profile safely',
whenToUse:
'When you want AllAgents to remove resources and profile-owned OAuth credentials for one installed or declared user profile while retaining referenced resources',
'When you want to uninstall one profile and keep its session data. Use --purge-session-data to also delete eligible owned runtime data.',
examples: [
'allagents profile remove work',
'allagents profile remove work --dry-run',
'allagents profile remove work --yes',
'allagents --json profile remove work --yes',
'allagents --json profile remove work --purge-session-data --yes',
],
expectedOutput:
'Displays a redacted deterministic removal plan, asks before applying unless --yes is supplied, removes profile-owned OAuth credentials even for a declared-only profile, and reports removed, retained, unchanged, or failed resources.',
'Displays which resources and runtime roots will be removed or retained and asks before applying unless --yes is supplied. Keeps session data and profile OAuth credentials by default.',
positionals: profileNamePositional,
options: mutationOptions,
options: [
...mutationOptions,
{
flag: '--purge-session-data',
type: 'boolean',
description:
'Also delete eligible owned client runtime roots and profile OAuth state. Omit to keep session data.',
},
],
outputSchema: {
profile: 'string',
operation: 'remove',
Expand Down
12 changes: 5 additions & 7 deletions src/core/profile/adapters/opencode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
ProfileNameSchema,
} from '../../../models/workspace-config.js';
import type { FileOnlyProfileAdapter } from '../types.js';
import { removeManagedFile, sha256Fingerprint } from '../files.js';
import { sha256Fingerprint } from '../files.js';
import type {
ProfileClientContext,
ProfileContextOptions,
Expand Down Expand Up @@ -181,14 +181,12 @@ export class OpenCodeProfileAdapter implements FileOnlyProfileAdapter {
return null;
}

async prepareRootCleanup(context: ProfileClientContext): Promise<void> {
rootCleanupFile(context: ProfileClientContext) {
assertOpenCodeContext(context);
await removeManagedFile({
root: context.root,
return {
path: join(context.root, '.gitignore'),
ownership: 'managed',
expectedFingerprint: sha256Fingerprint(GENERATED_GITIGNORE),
});
fingerprint: sha256Fingerprint(GENERATED_GITIGNORE),
};
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/core/profile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface ProfileRuntimeOptions {
readonly platform?: NodeJS.Platform;
readonly offline?: boolean;
readonly dryRun?: boolean;
readonly purgeSessionData?: boolean;
}

export type ProfileStepKind =
Expand Down Expand Up @@ -66,7 +67,7 @@ export interface ProfilePlanClient {


export interface ProfilePlanStep {
readonly client: ClientType;
readonly client: ClientType | 'profile';
readonly kind: ProfileStepKind;
/** Display-safe native identity or absolute filesystem path. */
readonly identity: string;
Expand Down Expand Up @@ -97,7 +98,7 @@ export type ProfileApplyStepStatus =
| 'failed';

export interface ProfileApplyStep {
readonly client: ClientType;
readonly client: ProfilePlanStep['client'];
readonly kind: ProfileStepKind;
readonly identity: string;
readonly status: ProfileApplyStepStatus;
Expand Down
79 changes: 50 additions & 29 deletions src/core/profile/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import type {
ProfileApplyStepStatus,
ProfilePlan,
ProfilePlanAction,
ProfilePlanStep,
ProfileRuntimeOptions,
ProfileStatusResult,
} from './index.js';
Expand Down Expand Up @@ -83,14 +84,14 @@ function resultStatus(action: ProfilePlanAction): ProfileApplyStepStatus {
}

function appliedStep(
step: InternalProfilePlanStep,
step: ProfilePlanStep,
status: ProfileApplyStepStatus,
error?: string,
): ProfileApplyStep {
return {
client: step.public.client,
kind: step.public.kind,
identity: step.public.identity,
client: step.client,
kind: step.kind,
identity: step.identity,
status,
...(error && { error }),
};
Expand Down Expand Up @@ -184,6 +185,10 @@ async function removeEmptyManagedRoot(root: string): Promise<boolean> {
if (!entry.isDirectory() || entry.isSymbolicLink()) continue;
await removeEmptyManagedRoot(join(root, entry.name));
}
return removeEmptyDirectory(root);
}

async function removeEmptyDirectory(root: string): Promise<boolean> {
try {
await rmdir(root);
return true;
Expand All @@ -194,23 +199,6 @@ async function removeEmptyManagedRoot(root: string): Promise<boolean> {
}
}

async function removeProfileOAuthProxyRoot(profileRoot: string): Promise<void> {
const oauthProxyRoot = join(profileRoot, 'oauth-proxy');
await assertSafeProfilePath(profileRoot, oauthProxyRoot);
const stats = await lstat(oauthProxyRoot).catch((error) => {
if ((error as NodeJS.ErrnoException).code === 'ENOENT') return null;
throw error;
});
if (!stats) return;
if (stats.isSymbolicLink() || !stats.isDirectory()) {
throw new Error(
`Profile OAuth proxy root is not a real directory: ${oauthProxyRoot}`,
);
}
await assertSafeProfilePath(profileRoot, oauthProxyRoot);
await rm(oauthProxyRoot, { recursive: true, force: true });
}

async function removeOwnedManagedRoot(
root: string,
expectedRoot: string,
Expand All @@ -229,6 +217,7 @@ async function removeOwnedManagedRoot(
if (stats.isSymbolicLink() || !stats.isDirectory()) {
throw new Error(`Managed profile root is not a real directory: ${root}`);
}
await assertSafeProfilePath(expectedRoot, root);
await rm(root, { recursive: true, force: true });
}

Expand Down Expand Up @@ -271,7 +260,15 @@ async function applyOneStep(
return { status: 'removed' };
}
await assertSafeProfilePath(expectedRoot, step.path);
await adapter.prepareRootCleanup?.(step.context);
const generated = adapter.rootCleanupFile?.(step.context);
if (generated) {
await removeManagedFile({
root: step.context.root,
path: generated.path,
ownership: 'managed',
expectedFingerprint: generated.fingerprint,
});
}
return {
status: (await removeEmptyManagedRoot(step.path))
? 'removed'
Expand Down Expand Up @@ -497,8 +494,8 @@ function dryRunResult(internal: InternalProfilePlan): ProfileApplyResult {
operation: internal.public.operation,
status: internal.public.operation === 'remove' ? 'removed' : 'installed',
success: true,
steps: internal.steps.map((step) =>
appliedStep(step, resultStatus(step.public.action)),
steps: internal.public.steps.map((step) =>
appliedStep(step, resultStatus(step.action)),
),
warnings: internal.public.warnings,
};
Expand Down Expand Up @@ -570,7 +567,7 @@ export async function applyProfilePlan(
internal.public.operation === 'remove',
);
state = await checkpoint(internal, state, completed, dependencies);
results.push(appliedStep(step, applied.status));
results.push(appliedStep(step.public, applied.status));
} catch (error) {
const message = safeError(error);
const failureTransition =
Expand All @@ -587,7 +584,7 @@ export async function applyProfilePlan(
const checkpointMessage = safeError(checkpointError);
results.push(
appliedStep(
step,
step.public,
'failed',
`${message}; state checkpoint failed: ${checkpointMessage}`,
),
Expand All @@ -602,7 +599,7 @@ export async function applyProfilePlan(
error: `${message}; state checkpoint failed: ${checkpointMessage}`,
};
}
results.push(appliedStep(step, 'failed', message));
results.push(appliedStep(step.public, 'failed', message));
return {
profile: plan.profile,
operation: plan.operation,
Expand All @@ -624,8 +621,31 @@ export async function applyProfilePlan(
);
if (plan.operation === 'remove') {
if (!retainedManaged) {
const oauth = internal.oauthCleanup;
if (oauth?.action === 'remove') {
try {
await removeOwnedManagedRoot(
oauth.identity,
join(profileRoot, 'oauth-proxy'),
);
results.push(appliedStep(oauth, 'removed'));
} catch (error) {
const message = safeError(error);
results.push(appliedStep(oauth, 'failed', message));
return {
profile: plan.profile,
operation: plan.operation,
status: 'partial',
success: false,
steps: results,
warnings: plan.warnings,
error: message,
};
}
} else if (oauth) {
results.push(appliedStep(oauth, 'retained'));
}
try {
await removeProfileOAuthProxyRoot(profileRoot);
const statePath = getProfileStatePath(profileRoot);
await assertSafeProfilePath(profileRoot, statePath);
await rm(statePath, { force: true });
Expand All @@ -643,7 +663,8 @@ export async function applyProfilePlan(
}
const warnings = [...plan.warnings];
try {
await removeEmptyManagedRoot(profileRoot);
// Retained roots and even empty runtime directories may be user data.
await removeEmptyDirectory(profileRoot);
} catch (error) {
warnings.push(
`Profile resources were removed, but the empty profile directory could not be pruned: ${safeError(error)}`,
Expand Down
Loading