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
6 changes: 6 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,12 @@ async function handleExec(
command: Command,
config: ResolvedAcpxConfig,
): Promise<void> {
if (config.disableExec) {
throw new InvalidArgumentError(
"exec is disabled by configuration (disableExec: true). Use prompt with a persistent session instead.",
);
}

const globalFlags = resolveGlobalFlags(command, config);
const outputPolicy = resolveOutputPolicy(
globalFlags.format,
Expand Down
20 changes: 20 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type ConfigFileShape = {
format?: unknown;
agents?: unknown;
auth?: unknown;
disableExec?: unknown;
};

export type ResolvedAcpxConfig = {
Expand All @@ -35,6 +36,7 @@ export type ResolvedAcpxConfig = {
format: OutputFormat;
agents: Record<string, string>;
auth: Record<string, string>;
disableExec: boolean;
globalPath: string;
projectPath: string;
hasGlobalConfig: boolean;
Expand Down Expand Up @@ -164,6 +166,16 @@ function parseOutputFormat(
return value as OutputFormat;
}

function parseDisableExec(value: unknown, sourcePath: string): boolean | undefined {
if (value == null) {
return undefined;
}
if (typeof value !== "boolean") {
throw new Error(`Invalid config disableExec in ${sourcePath}: expected boolean`);
}
return value;
}

function parseDefaultAgent(value: unknown, sourcePath: string): string | undefined {
if (value == null) {
return undefined;
Expand Down Expand Up @@ -347,6 +359,11 @@ export async function loadResolvedConfig(cwd: string): Promise<ResolvedAcpxConfi
parseAuth(projectConfig?.auth, projectPath),
);

const disableExec =
parseDisableExec(projectConfig?.disableExec, projectPath) ??
parseDisableExec(globalConfig?.disableExec, globalPath) ??
false;

return {
defaultAgent,
defaultPermissions,
Expand All @@ -357,6 +374,7 @@ export async function loadResolvedConfig(cwd: string): Promise<ResolvedAcpxConfi
format,
agents,
auth,
disableExec,
globalPath,
projectPath,
hasGlobalConfig: globalResult.exists,
Expand All @@ -372,6 +390,7 @@ export function toConfigDisplay(config: ResolvedAcpxConfig): {
ttl: number;
timeout: number | null;
format: OutputFormat;
disableExec: boolean;
agents: Record<string, ConfigAgentEntry>;
authMethods: string[];
} {
Expand All @@ -388,6 +407,7 @@ export function toConfigDisplay(config: ResolvedAcpxConfig): {
ttl: Math.round(config.ttlMs / 1_000),
timeout: config.timeoutMs == null ? null : config.timeoutMs / 1_000,
format: config.format,
disableExec: config.disableExec,
agents,
authMethods: Object.keys(config.auth).sort(),
};
Expand Down
75 changes: 75 additions & 0 deletions test/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,81 @@ test("initGlobalConfigFile creates the config once and then reports existing fil
});
});

test("disableExec defaults to false when not set", async () => {
await withTempEnv(async () => {
const cwd = await fs.mkdtemp(path.join(os.tmpdir(), "acpx-exec-"));
try {
const config = await loadResolvedConfig(cwd);
assert.equal(config.disableExec, false);
} finally {
await fs.rm(cwd, { recursive: true, force: true });
}
});
});

test("disableExec is read from global config", async () => {
await withTempEnv(async ({ homeDir }) => {
const cwd = path.join(homeDir, "workspace");
await fs.mkdir(cwd, { recursive: true });
await fs.mkdir(path.join(homeDir, ".acpx"), { recursive: true });

await fs.writeFile(
path.join(homeDir, ".acpx", "config.json"),
`${JSON.stringify({ disableExec: true }, null, 2)}\n`,
"utf8",
);

const config = await loadResolvedConfig(cwd);
assert.equal(config.disableExec, true);
});
});

test("disableExec project config overrides global config", async () => {
await withTempEnv(async ({ homeDir }) => {
const cwd = path.join(homeDir, "workspace");
await fs.mkdir(cwd, { recursive: true });
await fs.mkdir(path.join(homeDir, ".acpx"), { recursive: true });

await fs.writeFile(
path.join(homeDir, ".acpx", "config.json"),
`${JSON.stringify({ disableExec: true }, null, 2)}\n`,
"utf8",
);

await fs.writeFile(
path.join(cwd, ".acpxrc.json"),
`${JSON.stringify({ disableExec: false }, null, 2)}\n`,
"utf8",
);

const config = await loadResolvedConfig(cwd);
assert.equal(config.disableExec, false);
});
});

test("disableExec rejects non-boolean values", async () => {
await withTempEnv(async ({ homeDir }) => {
const cwd = path.join(homeDir, "workspace");
await fs.mkdir(cwd, { recursive: true });
await fs.mkdir(path.join(homeDir, ".acpx"), { recursive: true });

await fs.writeFile(
path.join(homeDir, ".acpx", "config.json"),
`${JSON.stringify({ disableExec: "yes" }, null, 2)}\n`,
"utf8",
);

await assert.rejects(
() => loadResolvedConfig(cwd),
(error: Error) => {
assert.match(error.message, /disableExec/);
assert.match(error.message, /boolean/);
return true;
},
);
});
});

async function withTempEnv(
run: (ctx: { homeDir: string }) => Promise<void>,
): Promise<void> {
Expand Down