- Notifications
You must be signed in to change notification settings - Fork 1
✨ feat(cli): xmd run drives agents through ACPX (acp-stack 10)#146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /** | ||
| * Agent flag parsing for `xmd run` (specs/acp-client-spec.md | ||
| * §Command-line configuration). | ||
| * | ||
| * A pure function over the parsed flags: it reads no Context Apis, no | ||
| * environment, and no configuration. The `DEFAULT_AGENT_NAME` lookup and | ||
| * every install step stay in the CLI, so the flag-to-configuration | ||
| * mapping can be asserted on its own. | ||
| */ | ||
| import type { PermissionMode } from "@executablemd/core"; | ||
| export interface AgentFlags { | ||
| agentProvider: string; | ||
| defaultAgent: string | undefined; | ||
| /** | ||
| * The raw `--timeout` text. The argument parser coerces or drops | ||
| * lexical forms — `1e3`, `0x10`, `.5`, `+1` and `Infinity` all reach a | ||
| * number-typed field as something this grammar would have rejected — | ||
| * so the untransformed text is what gets validated. | ||
| */ | ||
| timeout: string | undefined; | ||
| approveAll: boolean; | ||
| approveReads: boolean; | ||
| denyAll: boolean; | ||
| } | ||
| export interface AgentConfig { | ||
| permissionMode: PermissionMode; | ||
| /** The `--default-agent` value; the environment fallback is applied by the caller. */ | ||
| defaultAgent: string | undefined; | ||
| timeoutMs: number | undefined; | ||
| } | ||
| /** `digits` or `digits "." digits` — nothing else is a number of seconds. */ | ||
| const SECONDS = /^\d+(\.\d+)?$/; | ||
| function parseTimeout(value: string): number | { error: string } { | ||
| const invalid = { | ||
| error: `--timeout must be a positive number of seconds, got "${value}"`, | ||
| }; | ||
| const trimmed = value.trim(); | ||
| if (!SECONDS.test(trimmed)) { | ||
| return invalid; | ||
| } | ||
| const seconds = Number(trimmed); | ||
| if (!Number.isFinite(seconds) || seconds <= 0) { | ||
| return invalid; | ||
| } | ||
| return seconds * 1000; | ||
| } | ||
| export function resolveAgentConfig(flags: AgentFlags): AgentConfig | { error: string } { | ||
| const selected = [flags.approveAll, flags.approveReads, flags.denyAll].filter(Boolean); | ||
| if (selected.length > 1) { | ||
| return { error: "--approve-all, --approve-reads, and --deny-all are mutually exclusive" }; | ||
| } | ||
| const permissionMode: PermissionMode = flags.approveAll | ||
| ? "approve-all" | ||
| : flags.denyAll | ||
| ? "deny-all" | ||
| : "approve-reads"; | ||
| let timeoutMs: number | undefined; | ||
| if (flags.timeout !== undefined) { | ||
| const parsed = parseTimeout(flags.timeout); | ||
| if (typeof parsed !== "number") { | ||
| return parsed; | ||
| } | ||
| timeoutMs = parsed; | ||
| } | ||
| return { permissionMode, defaultAgent: flags.defaultAgent, timeoutMs }; | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant comment — restates what the code does.