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: 17 additions & 4 deletions .github/workflows/auto-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ permissions:
jobs:
enable:
name: Enable auto-merge
if: >
github.event.pull_request.draft == false &&
contains(fromJSON('["OWNER", "MEMBER"]'), github.event.pull_request.author_association)
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
Expand All @@ -30,4 +27,20 @@ jobs:
# downstream push-triggered workflows such as production deployment.
GH_TOKEN: ${{ secrets.AUTOMERGE_TOKEN }}
PR_URL: ${{ github.event.pull_request.html_url }}
run: gh pr merge --auto --squash "$PR_URL"
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
PR_DRAFT: ${{ github.event.pull_request.draft }}
EVENT_AUTHOR_ASSOCIATION: ${{ github.event.pull_request.author_association }}
run: |
echo "Event author association: $EVENT_AUTHOR_ASSOCIATION"
if [ "$PR_DRAFT" = "true" ]; then
echo "Skipping draft pull request."
exit 0
fi

permission=$(gh api "repos/$GITHUB_REPOSITORY/collaborators/$PR_AUTHOR/permission" --jq '.user.permissions | .admin or .maintain or .push')
if [ "$permission" != "true" ]; then
echo "Skipping pull request from an author without write permission."
exit 0
fi

gh pr merge --auto --merge "$PR_URL"
9 changes: 8 additions & 1 deletion packages/app/src/exe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ export function herdrAgentStatus(body: string): string | null {
return match?.[1].toLowerCase() ?? null;
}

/** Codex can be alive in the pane while still waiting for an interactive startup decision. */
export function agentStartupBlocked(body: string): boolean {
const normalized = body.replace(/\x1b\[[0-?]*[ -\/]*[@-~]/g, " ").replace(/\s+/g, " ").toLowerCase();
return normalized.includes("do you trust the contents of this directory?")
|| normalized.includes("press enter to continue") && normalized.includes("yes, continue") && normalized.includes("no, quit");
}

export function agentOutputCommand(connection: ExeConnection, agentName: string): string {
return `${herdrPrefix(connection)} && ${herdrBinary(connection)} agent read ${shellAtom(agentName)} --source recent --format text`;
}
Expand Down Expand Up @@ -144,7 +151,7 @@ function herdrBinary(connection: ExeConnection): string {
function agentCommand(connection: ExeConnection, prompt?: string, cwd?: string): string {
const command = connection.agentCommand?.trim() || defaultAgentCommand(connection.agentKind);
const args = command ? shellWords(command).map(shellAtom) : [];
if (connection.agentKind === "codex" && cwd) args.push("--dangerously-bypass-hook-trust", "-c", shellAtom(`projects.${JSON.stringify(cwd)}.trust_level="trusted"`));
if (connection.agentKind === "codex" && cwd) args.push("--dangerously-bypass-hook-trust", "--cd", shellAtom(cwd), "-c", shellAtom(`projects.${JSON.stringify(cwd)}.trust_level="trusted"`));
if (prompt !== undefined) args.push("--", shellAtom(prompt));
return args.length ? ` -- ${args.join(" ")}` : "";
}
Expand Down
7 changes: 6 additions & 1 deletion packages/app/src/tenant.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DurableObject } from "cloudflare:workers";
import Mustache from "mustache";
import { decrypt, encrypt } from "./crypto";
import { agentListCommand, agentOutputCommand, agentStatusCommand, connectionCheckCommand, defaultAgentCommand, exec, garbageCollectPaneCommand, herdrAgentStatus, herdrCheckCommand, paneGetCommand, paneProcessInfoCommand, replaceForegroundCommand, startAgentCommand, startAgentInPaneCommand, stopAgentCommand, validateWorktreeLeaseCommand, type ExeConnection } from "./exe";
import { agentListCommand, agentOutputCommand, agentStartupBlocked, agentStatusCommand, connectionCheckCommand, defaultAgentCommand, exec, garbageCollectPaneCommand, herdrAgentStatus, herdrCheckCommand, paneGetCommand, paneProcessInfoCommand, replaceForegroundCommand, startAgentCommand, startAgentInPaneCommand, stopAgentCommand, validateWorktreeLeaseCommand, type ExeConnection } from "./exe";
import { findOwnedAgent, ownsPane, parseAgent, parseAgentList, parsePaneProcess, type HerdrIdentity } from "./recovery";
import { LINEAR_ISSUE_PROJECT_QUERY, LINEAR_OPTION_QUERIES, LINEAR_PROJECTS_QUERY } from "./linear";
import { matchingIssue } from "./matcher";
Expand Down Expand Up @@ -607,6 +607,11 @@ export class Tenant extends DurableObject<Env> {
}
const identity = parseAgent(verification.body);
if (!identity) return this.beginRecovery(run, pipe, connection, "agent start succeeded but its structured identity was inconsistent");
const startupOutput = await backend.readOutput(launched.handle);
this.commandActivity(run.id, "initial agent readiness", startupOutput);
if (startupOutput.ok && agentStartupBlocked(startupOutput.body)) {
return this.finishRun(run, "failed", "The agent process started but stopped at an interactive startup permission prompt.");
}
this.ctx.storage.sql.exec("UPDATE runs SET prompt_delivery_state='accepted',prompt_delivery_request=?,prompt_delivery_response=?,prompt_delivery_status=?,prompt_delivery_exit_code=?,prompt_accepted=1,updated_at=? WHERE id=?", execRequest, execResponse, result.status, result.exitCode, now(), run.id);
this.activity(run.id, "prompt_delivered_at_launch", "The initial prompt was passed as a positional harness argument in the successful Herdr launch command.");
this.persistIdentity(run.id, identity, "running");
Expand Down
8 changes: 7 additions & 1 deletion packages/app/test/workspace.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import { agentStatusCommand, connectionCheckCommand, defaultAgentCommand, garbageCollectPaneCommand, herdrAgentStatus, launchAgentCommand, promptAgentCommand, replaceForegroundCommand, shellAtom, startAgentCommand } from "../src/exe";
import { agentStartupBlocked, agentStatusCommand, connectionCheckCommand, defaultAgentCommand, garbageCollectPaneCommand, herdrAgentStatus, launchAgentCommand, promptAgentCommand, replaceForegroundCommand, shellAtom, startAgentCommand } from "../src/exe";
import { workingDirectoryFor, workspaceNameFor } from "../src/workspace";

describe("flow workspaces", () => {
Expand Down Expand Up @@ -43,6 +43,7 @@ describe("flow workspaces", () => {
expect(launch).toContain("/tmp/factorize-prompts/factorize-1/prompt.md");
expect(launch).toContain("Read and follow the complete task instructions in");
expect(launch).toContain("--dangerously-bypass-hook-trust");
expect(launch).toContain("--cd '/repo/.factorize-runs/run'");
expect(launch).toContain('projects."/repo/.factorize-runs/run".trust_level="trusted"');
expect(launch).not.toContain("agent prompt");
expect(delivery).toContain("agent prompt 'factorize-1'");
Expand Down Expand Up @@ -94,6 +95,11 @@ describe("flow workspaces", () => {
expect(herdrAgentStatus('{"result":{"agent":{"state":"idle"}}}')).toBe("idle");
});

it("detects an interactive Codex trust screen as a blocked startup", () => {
expect(agentStartupBlocked("Do you trust the contents of this directory? 1. Yes, continue 2. No, quit Press enter to continue")).toBe(true);
expect(agentStartupBlocked('{"result":{"agent":{"agent_status":"working"}}}')).toBe(false);
});

it("revalidates exact pane and process identities before bounded escalation", () => {
const command = replaceForegroundCommand("flow-1", { vmName: "vm", apiToken: "token", agentKind: "codex", cwd: "/repo" }, "pane-7");
expect(command.match(/pane process-info --pane 'pane-7'/g)).toHaveLength(2);
Expand Down