mirror of
https://github.com/harivansh-afk/sandbox-agent.git
synced 2026-04-17 11:04:58 +00:00
refactor: parse permissions example flags
This commit is contained in:
parent
5127b2c4ed
commit
0da44a2ff3
3 changed files with 52 additions and 21 deletions
|
|
@ -7,6 +7,7 @@
|
||||||
"typecheck": "tsc --noEmit"
|
"typecheck": "tsc --noEmit"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"commander": "^12.1.0",
|
||||||
"sandbox-agent": "workspace:*"
|
"sandbox-agent": "workspace:*"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,18 @@
|
||||||
import { createInterface } from "node:readline/promises";
|
import { createInterface } from "node:readline/promises";
|
||||||
import { stdin as input, stdout as output } from "node:process";
|
import { stdin as input, stdout as output } from "node:process";
|
||||||
|
import { Command } from "commander";
|
||||||
import {
|
import {
|
||||||
SandboxAgent,
|
SandboxAgent,
|
||||||
type PermissionReply,
|
type PermissionReply,
|
||||||
type SessionPermissionRequest,
|
type SessionPermissionRequest,
|
||||||
} from "sandbox-agent";
|
} from "sandbox-agent";
|
||||||
|
|
||||||
const agent = (process.env.PERMISSIONS_AGENT?.trim() || "claude").toLowerCase();
|
const options = parseOptions();
|
||||||
const requestedPermissionMode = process.env.PERMISSION_MODE?.trim();
|
const agent = options.agent.trim().toLowerCase();
|
||||||
const autoReply = parsePermissionReply(process.env.PERMISSION_REPLY);
|
const permissionMode = options.permissionMode.trim();
|
||||||
|
const autoReply = parsePermissionReply(options.reply);
|
||||||
const promptText =
|
const promptText =
|
||||||
process.env.PERMISSION_PROMPT?.trim() ||
|
options.prompt?.trim() ||
|
||||||
`Create ./permission-example.txt with the text 'hello from the ${agent} permissions example'.`;
|
`Create ./permission-example.txt with the text 'hello from the ${agent} permissions example'.`;
|
||||||
|
|
||||||
const sdk = await SandboxAgent.start({
|
const sdk = await SandboxAgent.start({
|
||||||
|
|
@ -30,7 +32,6 @@ try {
|
||||||
: [];
|
: [];
|
||||||
const modeOption = configOptions.find((option) => option.category === "mode");
|
const modeOption = configOptions.find((option) => option.category === "mode");
|
||||||
const availableModes = extractOptionValues(modeOption);
|
const availableModes = extractOptionValues(modeOption);
|
||||||
const permissionMode = requestedPermissionMode || modeOption?.currentValue || availableModes[0] || "default";
|
|
||||||
|
|
||||||
console.log(`Agent: ${agent}`);
|
console.log(`Agent: ${agent}`);
|
||||||
console.log(`Permission mode: ${permissionMode}`);
|
console.log(`Permission mode: ${permissionMode}`);
|
||||||
|
|
@ -159,3 +160,29 @@ function parsePermissionReply(value: string | undefined): PermissionReply | null
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseOptions(): {
|
||||||
|
agent: string;
|
||||||
|
permissionMode: string;
|
||||||
|
prompt?: string;
|
||||||
|
reply?: string;
|
||||||
|
} {
|
||||||
|
const argv = process.argv.slice(2);
|
||||||
|
const normalizedArgv = argv[0] === "--" ? argv.slice(1) : argv;
|
||||||
|
const program = new Command();
|
||||||
|
program
|
||||||
|
.name("permissions")
|
||||||
|
.description("Run a permissions example against an ACP agent session.")
|
||||||
|
.requiredOption("--agent <agent>", "Agent to run, for example 'claude' or 'codex'")
|
||||||
|
.requiredOption("--permission-mode <mode>", "Permission mode to configure for the session")
|
||||||
|
.option("--prompt <text>", "Prompt to send after the session starts")
|
||||||
|
.option("--reply <reply>", "Automatically answer permission prompts with once, always, or reject");
|
||||||
|
|
||||||
|
program.parse(normalizedArgv, { from: "user" });
|
||||||
|
return program.opts<{
|
||||||
|
agent: string;
|
||||||
|
permissionMode: string;
|
||||||
|
prompt?: string;
|
||||||
|
reply?: string;
|
||||||
|
}>();
|
||||||
|
}
|
||||||
|
|
|
||||||
35
pnpm-lock.yaml
generated
35
pnpm-lock.yaml
generated
|
|
@ -47,22 +47,6 @@ importers:
|
||||||
specifier: latest
|
specifier: latest
|
||||||
version: 5.9.3
|
version: 5.9.3
|
||||||
|
|
||||||
examples/claude-permissions:
|
|
||||||
dependencies:
|
|
||||||
sandbox-agent:
|
|
||||||
specifier: workspace:*
|
|
||||||
version: link:../../sdks/typescript
|
|
||||||
devDependencies:
|
|
||||||
'@types/node':
|
|
||||||
specifier: latest
|
|
||||||
version: 25.4.0
|
|
||||||
tsx:
|
|
||||||
specifier: latest
|
|
||||||
version: 4.21.0
|
|
||||||
typescript:
|
|
||||||
specifier: latest
|
|
||||||
version: 5.9.3
|
|
||||||
|
|
||||||
examples/cloudflare:
|
examples/cloudflare:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@cloudflare/sandbox':
|
'@cloudflare/sandbox':
|
||||||
|
|
@ -287,6 +271,25 @@ importers:
|
||||||
specifier: latest
|
specifier: latest
|
||||||
version: 5.9.3
|
version: 5.9.3
|
||||||
|
|
||||||
|
examples/permissions:
|
||||||
|
dependencies:
|
||||||
|
commander:
|
||||||
|
specifier: ^12.1.0
|
||||||
|
version: 12.1.0
|
||||||
|
sandbox-agent:
|
||||||
|
specifier: workspace:*
|
||||||
|
version: link:../../sdks/typescript
|
||||||
|
devDependencies:
|
||||||
|
'@types/node':
|
||||||
|
specifier: latest
|
||||||
|
version: 25.4.0
|
||||||
|
tsx:
|
||||||
|
specifier: latest
|
||||||
|
version: 4.21.0
|
||||||
|
typescript:
|
||||||
|
specifier: latest
|
||||||
|
version: 5.9.3
|
||||||
|
|
||||||
examples/persist-memory:
|
examples/persist-memory:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@sandbox-agent/example-shared':
|
'@sandbox-agent/example-shared':
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue