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
31 changes: 31 additions & 0 deletions .github/workflows/auto-merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Auto-merge

on:
pull_request_target:
branches:
- main
types:
- opened
- reopened
- synchronize
- ready_for_review

permissions:
contents: read

jobs:
enable:
name: Enable auto-merge
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
# This workflow intentionally does not check out or execute PR code.
- name: Merge after required checks pass
env:
# A fine-grained PAT or GitHub App token is required here. The built-in
# GITHUB_TOKEN cannot add PRs to a merge queue and can suppress
# 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"
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ name: CI

on:
push:
branches:
- main
pull_request:
branches:
- main
# Run required checks again against GitHub's speculative merge-queue commit.
merge_group:
types:
- checks_requested
workflow_dispatch:

permissions:
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Deploy to Cloudflare

on:
push:
branches:
- main
workflow_dispatch:

permissions:
contents: read

concurrency:
group: production
cancel-in-progress: false

jobs:
deploy:
name: Deploy Worker
runs-on: ubuntu-latest
timeout-minutes: 15
environment: production
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: npm ci
- run: npm run build:css
- name: Deploy Worker
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: deploy
23 changes: 17 additions & 6 deletions src/tenant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { agentOutputCommand, agentStatusCommand, connectionCheckCommand, default
import { LINEAR_ISSUE_PROJECT_QUERY, LINEAR_OPTION_QUERIES, LINEAR_PROJECTS_QUERY } from "./linear";
import { matchingIssue } from "./matcher";
import type { Env, ExeConnectionInput, FilterType, MatchRule, PipeInput, RunState } from "./types";
import { workspaceNameFor } from "./workspace";
import { workingDirectoryFor, workspaceNameFor } from "./workspace";

type Row = Record<string, unknown>;
const json = (value: unknown) => Response.json(value);
Expand Down Expand Up @@ -191,13 +191,13 @@ export class Tenant extends DurableObject<Env> {
if (!linear) throw new Error("Connect Linear first");
const exe = await this.exeConnection(input.exeConnectionId);
if (!exe) throw new Error("Connect Herdr first");
if (!input.cwd) throw new Error("Choose a working directory.");
const cwd = this.cwdTemplate(input.cwd, flowId);
const workspaceName = flowId;
// These legacy fields are retained for compatibility with the v1 Durable Object schema.
// App-wide webhook verification is performed at the Worker edge before reaching this object.
this.ctx.storage.sql.exec(
"INSERT INTO pipes (id,name,project_id,team_id,filter_type,filter_target_id,max_concurrency,capability,webhook_id,signing_secret,workspace_name,agent_kind,context_template,match_rules,exe_connection_id,cwd,created_at) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
pipeId, input.name, input.projectId, "", rules[0].type, rules[0].targetId, maxConcurrency, "app-webhook", null, "app-webhook", workspaceName, exe.agentKind, this.contextTemplate(input.contextTemplate), JSON.stringify(rules), input.exeConnectionId || "default", input.cwd, now(),
pipeId, input.name, input.projectId, "", rules[0].type, rules[0].targetId, maxConcurrency, "app-webhook", null, "app-webhook", workspaceName, exe.agentKind, this.contextTemplate(input.contextTemplate), JSON.stringify(rules), input.exeConnectionId || "default", cwd, now(),
);
return Response.json({ id: pipeId }, { status: 201 });
}
Expand All @@ -212,10 +212,10 @@ export class Tenant extends DurableObject<Env> {
const workspaceName = flowId;
const exe = await this.exeConnection(input.exeConnectionId);
if (!exe) throw new Error("Choose an exe.dev connection.");
if (!input.cwd) throw new Error("Choose a working directory.");
const cwd = this.cwdTemplate(input.cwd, flowId);
this.ctx.storage.sql.exec(
"UPDATE pipes SET name=?, project_id=?, filter_type=?, filter_target_id=?, max_concurrency=?, workspace_name=?, agent_kind=?, context_template=?, match_rules=?, exe_connection_id=?, cwd=? WHERE id=?",
input.name, input.projectId, rules[0].type, rules[0].targetId, maxConcurrency, workspaceName, exe.agentKind, this.contextTemplate(input.contextTemplate), JSON.stringify(rules), input.exeConnectionId || "default", input.cwd, pipeId,
input.name, input.projectId, rules[0].type, rules[0].targetId, maxConcurrency, workspaceName, exe.agentKind, this.contextTemplate(input.contextTemplate), JSON.stringify(rules), input.exeConnectionId || "default", cwd, pipeId,
);
return json({ id: pipeId, ok: true });
}
Expand Down Expand Up @@ -420,7 +420,7 @@ export class Tenant extends DurableObject<Env> {

private async connectionForPipe(pipe: Row): Promise<ExeConnection | null> {
const connection = await this.exeConnection(String(pipe.exe_connection_id || "default"));
return connection && pipe.cwd ? { ...connection, cwd: String(pipe.cwd) } : connection;
return connection && pipe.cwd ? { ...connection, cwd: workingDirectoryFor(String(pipe.cwd), String(pipe.workspace_name)) } : connection;
}

private async upsertMember(input: unknown): Promise<Response> {
Expand Down Expand Up @@ -473,6 +473,17 @@ export class Tenant extends DurableObject<Env> {
return value;
}

private cwdTemplate(value: unknown, flowId: string): string {
if (typeof value !== "string" || !value.trim()) throw new Error("Choose a working directory.");
try {
Mustache.parse(value);
if (!workingDirectoryFor(value, flowId).trim()) throw new Error();
} catch {
throw new Error("Working directory must be a valid Mustache template that renders to a path.");
}
return value;
}

private matchRules(input: PipeInput): MatchRule[] {
const rules = Array.isArray(input.matchRules) && input.matchRules.length ? input.matchRules : input.filterType && input.filterTargetId ? [{ type: input.filterType, targetId: input.filterTargetId }] : [];
const validTypes: FilterType[] = ["owner", "creator", "status", "label", "assignee"];
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface PipeInput {
contextTemplate?: string;
/** Saved exe.dev connection selected for this flow. */
exeConnectionId?: string;
/** Working directory is flow-specific even when the VM is shared. */
/** Mustache template for the working directory; receives `flowId`. */
cwd?: string;
}

Expand Down
2 changes: 1 addition & 1 deletion src/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const flowPage = (viewer: Viewer, editFlowId?: string) => viewer ? shell(
<div class="flex items-start gap-4"><span class="grid h-8 w-8 shrink-0 place-items-center rounded-full bg-factorize-100 text-sm font-bold text-factorize-700 dark:bg-factorize-500/20 dark:text-factorize-100">2</span><div class="min-w-0 w-full"><div class="flex items-center justify-between gap-3"><h2 class="text-xl font-semibold">Exe.dev config</h2><span id="exe-status" class="rounded-full bg-stone-100 px-2.5 py-1 text-xs font-medium text-slate-500 dark:bg-slate-800 dark:text-slate-400">Checking…</span></div><p class="mt-1 text-sm text-slate-500 dark:text-slate-400">Connect to the VM where your working directory lives.</p>
<div class="mt-6 grid gap-5 sm:grid-cols-2"><label class="label sm:col-span-2">Connection<select id="exe-connection" class="field" name="exeConnection"><option value="">Loading saved connections…</option></select><span class="mt-2 block font-normal text-slate-500 dark:text-slate-400">Connections save an SSH destination and its restricted HTTPS token. Select one for this flow, or add another.</span></label></div>
<div id="exe-fields" class="mt-5 hidden grid gap-5 sm:grid-cols-2"><label class="label">SSH Destination<input class="field" name="vmName" placeholder="exedev@workbox" autocomplete="off"><span class="mt-2 block font-normal text-slate-500 dark:text-slate-400">Use the exact destination you use interactively, including its user.</span></label><label class="label">Restricted exe.dev HTTPS token<input class="field" name="apiToken" type="password" placeholder="exe1…" autocomplete="off"><span class="mt-2 block font-normal text-slate-500 dark:text-slate-400">Create a token limited to <code>ssh YOUR_SSH_DESTINATION</code>.</span></label></div>
<div class="mt-5"><label class="label">Working Directory<input class="field" name="cwd" placeholder="/home/exedev/project" autocomplete="off"><span class="mt-2 block font-normal text-slate-500 dark:text-slate-400">This is chosen per flow, so one VM connection can serve several projects.</span></label></div><div class="mt-5 flex items-center gap-2"><button id="test-exe" type="button" class="rounded-lg border border-stone-300 px-3 py-2 text-sm font-semibold hover:bg-stone-50 disabled:cursor-wait disabled:opacity-60 dark:border-slate-700 dark:hover:bg-slate-800">Test Connection</button><span id="exe-test-status" class="hidden" role="status" aria-live="polite"></span></div><pre id="exe-test-result" class="mt-3 hidden overflow-x-auto whitespace-pre-wrap rounded-lg bg-slate-950 p-3 text-xs text-slate-100"></pre>
<div class="mt-5"><label class="label">Working Directory<input class="field" name="cwd" placeholder="/home/exedev/projects/{{{flowId}}}" autocomplete="off"><span class="mt-2 block font-normal text-slate-500 dark:text-slate-400">This is chosen per flow and supports <code>{{{flowId}}}</code> as a Mustache variable, so each flow can use an isolated directory. Literal paths still work.</span></label></div><div class="mt-5 flex items-center gap-2"><button id="test-exe" type="button" class="rounded-lg border border-stone-300 px-3 py-2 text-sm font-semibold hover:bg-stone-50 disabled:cursor-wait disabled:opacity-60 dark:border-slate-700 dark:hover:bg-slate-800">Test Connection</button><span id="exe-test-status" class="hidden" role="status" aria-live="polite"></span></div><pre id="exe-test-result" class="mt-3 hidden overflow-x-auto whitespace-pre-wrap rounded-lg bg-slate-950 p-3 text-xs text-slate-100"></pre>
</div></div>
</section>
<section class="rounded-2xl border border-stone-200 bg-white p-6 shadow-sm dark:border-slate-800 dark:bg-slate-900 sm:p-8">
Expand Down
7 changes: 7 additions & 0 deletions src/workspace.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import Mustache from "mustache";

/** Turns a human flow name into a short, predictable Herdr workspace label. */
export function workspaceNameFor(value: string): string {
return value.trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 48) || "flow";
}

/** Renders a flow-specific working directory while preserving literal paths. */
export function workingDirectoryFor(template: string, flowId: string): string {
return Mustache.render(template, { flowId });
}
2 changes: 2 additions & 0 deletions test/ui.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ describe("pages", () => {
expect(html).toContain('id="exe-connection"');
expect(html).toContain("Connections save an SSH destination and its restricted HTTPS token");
expect(html).toContain("This is chosen per flow");
expect(html).toContain("/home/exedev/projects/{{{flowId}}}");
expect(html).toContain("as a Mustache variable");
expect(html).toContain("Test Connection");
expect(html).toContain('id="exe-test-status"');
expect(html).toContain("Connection successful");
Expand Down
7 changes: 6 additions & 1 deletion test/workspace.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";
import { agentStatusCommand, connectionCheckCommand, defaultAgentCommand, herdrAgentStatus, shellAtom, startAgentCommand } from "../src/exe";
import { workspaceNameFor } from "../src/workspace";
import { workingDirectoryFor, workspaceNameFor } from "../src/workspace";

describe("flow workspaces", () => {
it("uses a harmless SSH round trip for connection tests", () => {
Expand All @@ -12,6 +12,11 @@ describe("flow workspaces", () => {
expect(workspaceNameFor("!!!")).toBe("flow");
});

it("renders a flow-specific working directory from its flow ID", () => {
expect(workingDirectoryFor("/repos/{{{flowId}}}", "bug-fixes")).toBe("/repos/bug-fixes");
expect(workingDirectoryFor("/repos/shared", "bug-fixes")).toBe("/repos/shared");
});

it("passes the saved flow workspace to Herdr", () => {
const command = startAgentCommand("bug-fixes-1", { vmName: "vm", apiToken: "token", agentKind: "codex", cwd: "/repo" }, "fix it", "bug-fixes-1");
expect(command).toContain("--label 'bug-fixes-1'");
Expand Down
Loading