Skip to content
Merged
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
21 changes: 21 additions & 0 deletions script/agent.runtime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,25 @@ describe("task run --runtime parsing", () => {
parseArgs(["task", "run", "omp.paid", "--runtime", "tmux"]),
).toThrow();
});

it("parses --rex-host and --cwd for remote execution (dotfiles#209)", () => {
const action = parseArgs([
"task", "run", "omp.paid",
"--runtime", "rex",
"--rex-host", "ssh://rex-wsl",
"--cwd", "/home/basic/src/project",
"--prompt", "hi",
]);
if (action[0] !== "task" || action[1] !== "run") throw new Error("unexpected action");
expect(action[3].runtime).toBe("rex");
expect(action[3].rexHost).toBe("ssh://rex-wsl");
expect(action[3].cwd).toBe("/home/basic/src/project");
});

it("defaults rexHost/cwd to null", () => {
const action = parseArgs(["task", "run", "omp.paid"]);
if (action[0] !== "task" || action[1] !== "run") throw new Error("unexpected action");
expect(action[3].rexHost).toBeNull();
expect(action[3].cwd).toBeNull();
});
});
12 changes: 10 additions & 2 deletions script/agent/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,13 @@ function parseTaskArgs(argv: string[]): Action {
if (!route || route.startsWith("-")) {
throw new AgentError(
"usage: agent task run <harness.provider> [--model <id>] [--fallback <profile-id>] " +
"[--runtime herdr|rex] [--rex-host <label>] [--cwd <path>] " +
"[--prompt <text>] [--accept <criteria>]..."
);
}
const opts: TaskRunOptions = {
model: null, fallback: null, prompt: null, accept: [], timeoutMs: null,
allowUnobservedEffects: false, runtime: null,
allowUnobservedEffects: false, runtime: null, rexHost: null, cwd: null,
};
const rest = argv.slice(2);
for (let i = 0; i < rest.length; i++) {
Expand All @@ -143,6 +144,8 @@ function parseTaskArgs(argv: string[]): Action {
}
opts.runtime = value;
}
else if (token === "--rex-host") opts.rexHost = take();
else if (token === "--cwd") opts.cwd = take();
else if (token === "--allow-unobserved-effects") opts.allowUnobservedEffects = true;
else if (token === "--timeout") {
const raw = take();
Expand All @@ -154,7 +157,8 @@ function parseTaskArgs(argv: string[]): Action {
} else {
throw new AgentError(
`unexpected argument '${token}'; usage: agent task run <route> ` +
"[--model <id>] [--fallback <profile-id>] [--prompt <text>] " +
"[--model <id>] [--fallback <profile-id>] [--runtime herdr|rex] " +
"[--rex-host <label>] [--cwd <path>] [--prompt <text>] " +
"[--accept <criteria>]... [--timeout <ms>]"
);
}
Expand All @@ -171,6 +175,10 @@ export interface TaskRunOptions {
allowUnobservedEffects: boolean;
/** Explicit execution runtime (ADR-0021); null = herdr (default). */
runtime: "herdr" | "rex" | null;
/** Rex host label/address (dotfiles#209); requires --runtime rex. */
rexHost: string | null;
/** Worker working directory; remote hosts require an absolute remote path. */
cwd: string | null;
}

export interface TaskResumeOptions {
Expand Down
7 changes: 7 additions & 0 deletions script/agent/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,11 @@ export async function cmdTask(config: Config, action: TaskAction): Promise<numbe
// the selected runtime itself is unavailable. The default stays Herdr;
// --runtime rex selects the Rex path explicitly (ADR-0021).
const runtime = o.runtime ?? "herdr";
// --rex-host is meaningful only for the Rex runtime; silently ignoring it
// under herdr would dispatch to the wrong execution target.
if (o.rexHost && runtime !== "rex") {
throw new AgentError("--rex-host requires --runtime rex", EXIT_USAGE);
}
const { runtimeAdapter } = await import("./runtime.ts");
const rt = await runtimeAdapter(runtime).checkAvailable();
if (!rt.available) {
Expand All @@ -541,6 +546,8 @@ export async function cmdTask(config: Config, action: TaskAction): Promise<numbe
...(o.timeoutMs !== null ? { timeoutMs: o.timeoutMs } : {}),
...(o.allowUnobservedEffects ? { allowUnobservedEffects: true } : {}),
...(o.runtime ? { runtime: o.runtime } : {}),
...(o.rexHost ? { rexHost: o.rexHost } : {}),
...(o.cwd ? { cwd: o.cwd } : {}),
});
} catch (error) {
// ContractError carries the classified reason (bad route/model/profile,
Expand Down
9 changes: 4 additions & 5 deletions script/agent/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -695,16 +695,15 @@ subcommands:
agent routes route table with catalog facts (quota scopes,
rate limits, restrictions, e2e evidence);
--json emits the same data as redacted JSON
agent fallback <profile-id> [--json] resolve and display an opt-in
continuity profile for authorized same-harness
fallback (issue #136); does not execute fallback
agent fallback <profile-id> [--json] resolve and display an opt-in continuity profile for authorized same-harness fallback (#136); does not execute fallback
agent task run <route> dispatch a prompt to a worker on
<harness>.<provider>; --model picks the model
(route default); --fallback names an opt-in
continuity profile; --prompt supplies task
text (stdin when omitted); --accept verifies
criteria post-collect; --runtime herdr|rex picks
the runtime (default herdr); --fallback needs --accept, git cwd, or --allow-unobserved-effects
criteria post-collect; --runtime herdr|rex (default
herdr); --rex-host <label> runs on a remote rex host;
--fallback needs --accept, git cwd, or --allow-unobserved-effects
agent task resume <task-id> continue an attempt in place
agent task status|reconcile <task-id> durable state / resolve journal UNKNOWNs
agent help --json machine-readable help (quotes this text)
Expand Down
44 changes: 30 additions & 14 deletions script/agent/omp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ function ompCustomBaseUrl(provider: Provider): string {
* repo-shipped helper resolves the named Infisical secret with the canonical
* self-host flags (never Infisical Cloud).
*/
function ompInfisicalKeyCommand(secretName: string): string {
return `${join(import.meta.dir, "infisical-key.sh")} ${secretName}`;
function ompInfisicalKeyCommand(secretName: string, remoteHome?: string): string {
const script = remoteHome !== undefined
? join(remoteHome, ".dotfiles", "script", "agent", "infisical-key.sh")
: join(import.meta.dir, "infisical-key.sh");
return `${script} ${secretName}`;
}

function ompModelLimits(provider: Provider, modelId: string): { contextWindow?: number; maxTokens?: number } {
Expand All @@ -100,7 +103,7 @@ export function ompNeedsManagedProfile(provider: Provider): boolean {
}

/** Deterministic models.yml content for a managed OMP profile. */
export function renderOmpModelsYaml(provider: Provider): string {
export function renderOmpModelsYaml(provider: Provider, remoteHome?: string): string {
if (!ompNeedsManagedProfile(provider)) {
throw new AgentError(
`provider '${provider.key}' does not need a managed OMP profile`,
Expand All @@ -122,7 +125,7 @@ export function renderOmpModelsYaml(provider: Provider): string {
"# Managed by the dotfiles agent launcher (config/agents.toml). Do not edit.",
"providers:",
` ${provider.omp_id}:`,
` apiKey: ${JSON.stringify(`!${ompInfisicalKeyCommand(secret)}`)}`,
` apiKey: ${JSON.stringify(`!${ompInfisicalKeyCommand(secret, remoteHome)}`)}`,
"",
].join("\n");
}
Expand All @@ -142,7 +145,7 @@ export function renderOmpModelsYaml(provider: Provider): string {
// worker path. The env-name form remains for providers whose credential
// is ambient-only (no Infisical secret name).
lines.push(
` apiKey: ${JSON.stringify(`!${ompInfisicalKeyCommand(provider.secret)}`)}`
` apiKey: ${JSON.stringify(`!${ompInfisicalKeyCommand(provider.secret, remoteHome)}`)}`
);
} else {
const envName = provider.env;
Expand Down Expand Up @@ -215,7 +218,13 @@ export function ensureOmpManagedProfile(provider: Provider): OmpManagedProfile {
/** Absolute real path of the destructive guard shipped next to this launcher.
* It is loaded with --trusted-extension, which aborts when loading fails, so
* a missing file must fail before a process starts. */
function ompDestructiveGuardPath(): string {
function ompDestructiveGuardPath(remoteHome?: string): string {
if (remoteHome !== undefined) {
// Remote worker: the path must exist on the REMOTE host's dotfiles
// checkout (~/.dotfiles convention); existence is preflighted by the
// dispatcher, argv elements are exec'd without shell expansion.
return join(remoteHome, ".dotfiles", "script", OMP_DESTRUCTIVE_GUARD);
}
const candidate = join(import.meta.dir, "..", OMP_DESTRUCTIVE_GUARD);
try {
return realpathSync(candidate);
Expand All @@ -234,7 +243,10 @@ function ompDestructiveGuardPath(): string {
* `--config` loader aborts on a missing file, but the launcher must fail
* before it builds a command — without the overlay a session would start
* with MCP servers mounted. */
function ompWorkerOverlayPath(): string {
function ompWorkerOverlayPath(remoteHome?: string): string {
if (remoteHome !== undefined) {
return join(remoteHome, ".dotfiles", "script", OMP_WORKER_OVERLAY);
}
const candidate = join(import.meta.dir, "..", OMP_WORKER_OVERLAY);
try {
return realpathSync(candidate);
Expand Down Expand Up @@ -282,7 +294,10 @@ const OMP_REX_STATUS = "rex-omp-agent-state.ts";
* program-status records to the enclosing Rex block (ADR-0021). Shipped next
* to this launcher and loaded with --trusted-extension like the destructive
* guard; a missing file must fail before a process starts. */
function ompRexStatusPath(): string {
function ompRexStatusPath(remoteHome?: string): string {
if (remoteHome !== undefined) {
return join(remoteHome, ".dotfiles", "script", OMP_REX_STATUS);
}
const candidate = join(import.meta.dir, "..", OMP_REX_STATUS);
try {
return realpathSync(candidate);
Expand Down Expand Up @@ -389,8 +404,9 @@ export function ompWorkerArgs(
provider: Provider,
model: string,
prepared: OmpWorkerPreparation,
options: { rexStatus?: boolean } = {},
options: { rexStatus?: boolean; remoteHome?: string } = {},
): string[] {
const remoteHome = options.remoteHome;
const args: string[] = [
"--provider", provider.omp_id,
"--model", model,
Expand Down Expand Up @@ -418,18 +434,18 @@ export function ompWorkerArgs(
"--no-lsp",
"--no-pty",
"--no-title",
"--trusted-extension", ompDestructiveGuardPath(),
"--config", ompWorkerOverlayPath(),
"--trusted-extension", ompDestructiveGuardPath(remoteHome),
"--config", ompWorkerOverlayPath(remoteHome),
);
if (insideHerdr()) {
if (insideHerdr() && remoteHome === undefined) {
args.push("--trusted-extension", ompHerdrExtensionPath());
}
// The Rex status reporter is added for Rex-dispatched workers (explicit
// rexStatus) and for interactive launches already inside a Rex block. It
// self-disables unless REX_* env is present, so it cannot double-report
// into Herdr even if both flags were ever combined.
if (options.rexStatus || insideRex()) {
args.push("--trusted-extension", ompRexStatusPath());
if (options.rexStatus || (insideRex() && remoteHome === undefined)) {
args.push("--trusted-extension", ompRexStatusPath(remoteHome));
}
return args;
}
Expand Down
Loading
Loading