mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-16 04:45:33 -08:00
Ask whether to turn permission prompts off when plan2code starts an agent
AI Assisted
This commit is contained in:
1 parent
dbd31611b7
commit
03f433043e
3 files changed
+87
-17
No files matched your search
+2
-3
@@ -2317,8 +2317,8 @@ function uninstallPlan2CodeBot() {
|
||||
|
||||
/**
|
||||
* `plan2code` typed in any directory opens the dashboard skill there in Claude Code
|
||||
* (`claude /plan2code --permission-mode bypassPermissions`) or Devin
|
||||
* (`devin --permission-mode bypass -- /plan2code`), asking which when both are installed.
|
||||
* (`claude /plan2code`), Devin (`devin -- /plan2code`) or Codex (`codex $plan2code`), asking
|
||||
* which when more than one is installed, then whether to turn permission prompts off.
|
||||
* The launcher is copied out of the package into ~/.plan2code/bin/ because the installer
|
||||
* normally runs from an npx cache directory that npm is free to delete; the shims in the bin
|
||||
* directory point at that stable copy.
|
||||
@@ -2730,7 +2730,6 @@ async function installLauncher({ quiet = false, unattended = false } = {}) {
|
||||
recordInstalled('launcher');
|
||||
// The shortcut is a convenience on top of the command, so a failure here only warns.
|
||||
if (!unattended) await offerDesktopShortcut(binDir);
|
||||
console.log(` ${COLORS.YELLOW}${SYMBOLS.WARNING}${COLORS.RESET} The ${LAUNCHER_COMMAND} command starts the agent with permission prompts off (${COLORS.CYAN}--permission-mode bypassPermissions${COLORS.RESET} in Claude Code, ${COLORS.CYAN}bypass${COLORS.RESET} in Devin, ${COLORS.CYAN}--dangerously-bypass-approvals-and-sandbox${COLORS.RESET} in Codex). Run ${COLORS.CYAN}claude /plan2code${COLORS.RESET} yourself if you want prompts.`);
|
||||
console.log('');
|
||||
// Inside install() the final summary prints the steps once, after everything else.
|
||||
if (!quiet) printGettingStarted({ commandInstalled: true });
|
||||
|
||||
@@ -156,6 +156,21 @@ test("launcher: Codex gets the bypass flag, the forwarded args, then the $plan2c
|
||||
assert.deepEqual(box.argsOf("codex"), ["--dangerously-bypass-approvals-and-sandbox", "--verbose", "$plan2code"]);
|
||||
});
|
||||
|
||||
test("launcher: --keep-permissions keeps every built-in's permission prompts, and is never forwarded", (t) => {
|
||||
const box = sandbox(["claude", "devin", "codex"]);
|
||||
t.after(box.cleanup);
|
||||
const expected = {
|
||||
claude: ["/plan2code", "--verbose"],
|
||||
devin: ["--verbose", "--", "/plan2code"],
|
||||
codex: ["--verbose", "$plan2code"],
|
||||
};
|
||||
for (const [cli, args] of Object.entries(expected)) {
|
||||
const result = box.run(["--cli", cli, "--keep-permissions", "--verbose"]);
|
||||
assert.equal(result.status, 0, result.stderr);
|
||||
assert.deepEqual(box.argsOf(cli), args, cli);
|
||||
}
|
||||
});
|
||||
|
||||
test("launcher: --cli codex picks Codex when it is installed beside another CLI", (t) => {
|
||||
const box = sandbox(["claude", "codex"]);
|
||||
t.after(box.cleanup);
|
||||
@@ -672,6 +687,19 @@ test("launcher agents: --cli <custom id> starts it with args, the model through
|
||||
// No model chosen and no models flag: the model arguments are left out.
|
||||
assert.equal(box.run(["--cli=goose"]).status, 0);
|
||||
assert.deepEqual(box.argsOf("goose"), ["--yes", "/plan2code", "--bypass"]);
|
||||
// --keep-permissions leaves bypassArgs out.
|
||||
assert.equal(box.run(["--cli=goose", "--keep-permissions"]).status, 0);
|
||||
assert.deepEqual(box.argsOf("goose"), ["--yes", "/plan2code"]);
|
||||
});
|
||||
|
||||
test("launcher agents: a custom agent with no bypassArgs is never asked about prompts and starts with its own", (t) => {
|
||||
const box = sandbox(["goose"]);
|
||||
t.after(box.cleanup);
|
||||
writeAgents(box, goose({ bypassArgs: [] }));
|
||||
const result = box.run(["--cli", "goose"]);
|
||||
assert.equal(result.status, 0, result.stderr);
|
||||
assert.deepEqual(box.argsOf("goose"), ["--yes", "/plan2code"]);
|
||||
assert.doesNotMatch(result.stdout, /permission prompts off/);
|
||||
});
|
||||
|
||||
test("launcher agents: the last pick can be a custom id, and the --cli error names custom ids", (t) => {
|
||||
@@ -701,7 +729,8 @@ test("launcher agents: the model menu is the agent's own models, with no shipped
|
||||
assert.equal(hasModelFlag(["--model", "x"], "goose"), true);
|
||||
assert.equal(hasModelFlag(["-m", "x"], "goose"), false);
|
||||
// A model given on the command line goes through modelArgs, once.
|
||||
assert.deepEqual(cli.args(["--model=m2", "-x"]), ["--yes", "/plan2code", "--model", "m2", "--bypass", "-x"]);
|
||||
assert.deepEqual(cli.args(["--model=m2", "-x"], { bypass: true }), ["--yes", "/plan2code", "--model", "m2", "--bypass", "-x"]);
|
||||
assert.deepEqual(cli.args(["-x"]), ["--yes", "/plan2code", "-x"]);
|
||||
});
|
||||
|
||||
test("launcher agents: the menu lists the built-ins found first, then the custom agents that resolve", (t) => {
|
||||
|
||||
+55
-13
@@ -5,17 +5,20 @@
|
||||
* `plan2code`: open the Plan2Code dashboard skill in Claude Code, Devin or Codex, in the
|
||||
* current directory.
|
||||
*
|
||||
* Runs one of:
|
||||
* claude /plan2code --permission-mode bypassPermissions [extra args]
|
||||
* devin --permission-mode bypass [extra args] -- /plan2code
|
||||
* codex --dangerously-bypass-approvals-and-sandbox [extra args] $plan2code
|
||||
* Runs one of (the bracketed flags only when permission prompts are turned off):
|
||||
* claude /plan2code [--permission-mode bypassPermissions] [extra args]
|
||||
* devin [--permission-mode bypass] [extra args] -- /plan2code
|
||||
* codex [--dangerously-bypass-approvals-and-sandbox] [extra args] $plan2code
|
||||
*
|
||||
* Codex starts a skill with `$name` rather than `/name`. When more than one CLI is installed
|
||||
* it asks which one, with the last pick as the default; with only one installed it uses that.
|
||||
* `--cli claude` / `--cli devin` / `--cli codex` skips the question. Before starting it asks
|
||||
* which model to run, from the curated list in models.json (shipped with every install) plus
|
||||
* any models the user added in User Preferences; Enter keeps the model the CLI last used, and
|
||||
* `--model` (or Codex's `-m`) skips the question. Any other arguments are forwarded to the CLI.
|
||||
* `--model` (or Codex's `-m`) skips the question. Right after the agent is chosen, when it has a
|
||||
* flag for skipping permission prompts (every built-in does; a custom agent only with bypassArgs),
|
||||
* it asks whether to turn them off, Yes by default; `--keep-permissions` answers no, and with no
|
||||
* terminal to ask on they are off. Any other arguments are forwarded to the CLI.
|
||||
* Self-contained, Node built-ins only: install.js copies this file to ~/.plan2code/bin/ and
|
||||
* points the global shims at it.
|
||||
*
|
||||
@@ -51,6 +54,7 @@ const IS_MAC = process.platform === 'darwin';
|
||||
const PICK_FOLDER_FLAG = '--pick-folder';
|
||||
const CLI_FLAG = '--cli';
|
||||
const CLASSIC_FLAG = '--classic';
|
||||
const KEEP_PERMISSIONS_FLAG = '--keep-permissions';
|
||||
// Where install.js puts the desktop app, and the one file in it the launcher starts.
|
||||
// PLAN2CODE_APP names a different executable (the tests start a stand-in this way).
|
||||
const APP_DIR = path.join(os.homedir(), '.plan2code', 'app');
|
||||
@@ -127,7 +131,10 @@ function printIntro() {
|
||||
console.log('');
|
||||
}
|
||||
|
||||
/** The CLIs that can open the dashboard, in menu order. `args` builds the full argument list. */
|
||||
/**
|
||||
* The CLIs that can open the dashboard, in menu order. `args(extra, { bypass })` builds the full
|
||||
* argument list, with `bypassArgs` in it only when permission prompts are off.
|
||||
*/
|
||||
const CLIS = [
|
||||
{
|
||||
id: 'claude',
|
||||
@@ -135,7 +142,10 @@ const CLIS = [
|
||||
install: 'npm i -g @anthropic-ai/claude-code',
|
||||
installUrl: 'https://code.claude.com/docs/en/setup',
|
||||
prompt: '/plan2code',
|
||||
args: (extra) => ['/plan2code', '--permission-mode', 'bypassPermissions', ...extra],
|
||||
bypassArgs: ['--permission-mode', 'bypassPermissions'],
|
||||
args(extra, { bypass } = {}) {
|
||||
return ['/plan2code', ...(bypass ? this.bypassArgs : []), ...extra];
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'devin',
|
||||
@@ -143,7 +153,10 @@ const CLIS = [
|
||||
install: 'https://devin.ai',
|
||||
installUrl: 'https://docs.devin.ai/work-with-devin/devin-cli',
|
||||
prompt: '/plan2code',
|
||||
args: (extra) => ['--permission-mode', 'bypass', ...extra, '--', '/plan2code'],
|
||||
bypassArgs: ['--permission-mode', 'bypass'],
|
||||
args(extra, { bypass } = {}) {
|
||||
return [...(bypass ? this.bypassArgs : []), ...extra, '--', '/plan2code'];
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'codex',
|
||||
@@ -151,8 +164,11 @@ const CLIS = [
|
||||
install: 'npm i -g @openai/codex',
|
||||
installUrl: 'https://github.com/openai/codex',
|
||||
prompt: '$plan2code',
|
||||
bypassArgs: ['--dangerously-bypass-approvals-and-sandbox'],
|
||||
// Codex mentions a skill with `$name`; the prompt is its one positional argument.
|
||||
args: (extra) => ['--dangerously-bypass-approvals-and-sandbox', ...extra, '$plan2code'],
|
||||
args(extra, { bypass } = {}) {
|
||||
return [...(bypass ? this.bypassArgs : []), ...extra, '$plan2code'];
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
@@ -347,7 +363,8 @@ function customClis(file = USER_AGENTS_FILE, print = Boolean(process.stderr.isTT
|
||||
prompt: entry.prompt,
|
||||
custom: true,
|
||||
entry,
|
||||
args: (extra) => [...buildArgs(entry, { bypass: true, model: modelFrom(extra, entry.id) }), ...withoutModelFlag(extra)],
|
||||
bypassArgs: entry.bypassArgs,
|
||||
args: (extra, { bypass } = {}) => [...buildArgs(entry, { bypass, model: modelFrom(extra, entry.id) }), ...withoutModelFlag(extra)],
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -708,6 +725,25 @@ async function chooseCli(requested) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to start the agent with permission prompts off. Asked only for an agent that has a flag
|
||||
* for it (a custom agent may have none), with Yes as the default; `--keep-permissions` answers no
|
||||
* without asking, and with no terminal to ask on the prompts are off.
|
||||
*/
|
||||
async function chooseBypass(cli, keep) {
|
||||
if (!cli.bypassArgs || !cli.bypassArgs.length || keep) return false;
|
||||
if (!process.stdin.isTTY) return true;
|
||||
console.log('');
|
||||
console.log(c.bright(`Turn ${cli.label}'s permission prompts off?`));
|
||||
console.log(c.dim(`It would read, edit and run commands in this project without asking (${cli.bypassArgs.join(' ')}).`));
|
||||
for (;;) {
|
||||
const answer = (await ask(`Prompts off? ${c.green('[Y/n]')}: `)).trim().toLowerCase();
|
||||
if (!answer || answer === 'y' || answer === 'yes') return true;
|
||||
if (answer === 'n' || answer === 'no') return false;
|
||||
console.log(c.yellow('Type n to keep the prompts, or press Enter to turn them off.'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* True when the forwarded arguments already pick a model: `--model <name>` / `--model=<name>`,
|
||||
* and for Codex also its short form, `-m <name>` / `-m=<name>` / `-m<name>`.
|
||||
@@ -1117,8 +1153,9 @@ async function launch() {
|
||||
}
|
||||
const fromShortcut = argv.includes(PICK_FOLDER_FLAG);
|
||||
const classic = argv.includes(CLASSIC_FLAG);
|
||||
const keepPermissions = argv.includes(KEEP_PERMISSIONS_FLAG);
|
||||
const { cli: requestedCli, rest: extraArgs } = takeCliFlag(
|
||||
argv.filter((arg) => arg !== PICK_FOLDER_FLAG && arg !== CLASSIC_FLAG)
|
||||
argv.filter((arg) => arg !== PICK_FOLDER_FLAG && arg !== CLASSIC_FLAG && arg !== KEEP_PERMISSIONS_FLAG)
|
||||
);
|
||||
|
||||
printIntro();
|
||||
@@ -1127,6 +1164,11 @@ async function launch() {
|
||||
if (!cli) return exitWith(code, fromShortcut);
|
||||
saveState({ lastCli: cli.id });
|
||||
|
||||
// The app has its own permission tick on its launch card, so the question is only for the
|
||||
// terminal flow (asked late if the app fails to start).
|
||||
const app = !classic && hasDisplay() ? findApp() : null;
|
||||
let bypass = app ? null : await chooseBypass(cli, keepPermissions);
|
||||
|
||||
let cwd = process.cwd();
|
||||
if (fromShortcut) {
|
||||
const folder = await pickFolder();
|
||||
@@ -1145,13 +1187,13 @@ async function launch() {
|
||||
if (!hasModelFlag(extraArgs, cli.id)) await chooseModel(cli, extraArgs);
|
||||
|
||||
// The app takes over from here when it is installed, a window can open and --classic is absent.
|
||||
const app = !classic && hasDisplay() ? findApp() : null;
|
||||
if (app && (await startApp(app, { cwd, cliId: cli.id, model: modelFrom(extraArgs, cli.id) }))) {
|
||||
console.log(`Opened the Plan2Code app in ${c.cyan(cwd)} ${c.dim('(run `plan2code --classic` to stay in this terminal)')}`);
|
||||
return process.exit(0);
|
||||
}
|
||||
if (bypass === null) bypass = await chooseBypass(cli, keepPermissions);
|
||||
|
||||
const args = cli.args(extraArgs);
|
||||
const args = cli.args(extraArgs, { bypass });
|
||||
const options = { cwd, stdio: 'inherit', ...(cli.fullPath ? { fromFullPath: true } : {}) };
|
||||
|
||||
const child = spawnCommand(cli.path, args, options);
|
||||
|
||||
Reference in new issue
Block a user