Skip to content

The fastest browser for AI agents to run browser automation, built for sharing your logged-in browser state with your AI agents, like Codex or Claude Code, without disturbing you. Zero cost, zero config.

feat(tools): add `reset <ID> [--remote]` to forget a ticket and start it over

Zhuowei Wang24e029c752d3
diff --git a/tools/linear-autofix/README.md b/tools/linear-autofix/README.md
index 008635c..6ccac43 100644
--- a/tools/linear-autofix/README.md
+++ b/tools/linear-autofix/README.md
@@ -142,7 +142,8 @@ node src/cli.mjs status
node src/cli.mjs stop # STOP file: running tick finishes its step, later ticks exit
node src/cli.mjs resume
node src/cli.mjs publish CITRO-2908 # push failed (E2E)? fix the host, then redo only push + PR
-node src/cli.mjs retry CITRO-2908 # start over: re-triage and re-implement
+node src/cli.mjs retry CITRO-2908 # start over: re-triage and re-implement (keeps worktree and branch)
+node src/cli.mjs reset CITRO-2908 --remote # forget the ticket entirely: record, worktree, branches, bot labels
launchctl bootout gui/$(id -u)/com.citrolabs.linear-autofix # uninstall the schedule
```
diff --git a/tools/linear-autofix/src/cli.mjs b/tools/linear-autofix/src/cli.mjs
index 62705bb..ef636bc 100755
--- a/tools/linear-autofix/src/cli.mjs
+++ b/tools/linear-autofix/src/cli.mjs
@@ -4,11 +4,15 @@ import * as linear from "./linear.mjs";
import {
load,
loadAll,
+ remove,
setStop,
stopRequested,
transition,
upsertFromIssue,
+ worktreePath,
} from "./state.mjs";
+import * as git from "./git.mjs";
+import * as github from "./github.mjs";
import { daemon, reconcile, tick } from "./tick.mjs";
import { triage } from "./triage.mjs";
import { implement, publish } from "./implement.mjs";
@@ -25,6 +29,8 @@ Usage:
linear-autofix review <ID> run one review-loop check for a ticket's PR
linear-autofix publish <ID> push the worktree and open the PR again (after a failed push)
linear-autofix retry <ID> reset a skipped/escalated ticket to "new" (re-triage, re-implement)
+ linear-autofix reset <ID> [--remote] forget a ticket: record, worktree, local branch, bot labels
+ (--remote also deletes the branch on origin; refuses while its PR is open)
linear-autofix status list tracked tickets and their stage
linear-autofix stop | resume create / remove the STOP file (kill switch)
@@ -56,6 +62,54 @@ async function one(identifier) {
return { issue, record: reconcile(upsertFromIssue(issue), issue) };
}
+/**
+ * Forget everything the bot did for one ticket so the next tick starts from
+ * triage: the record, the worktree, the local branch and the bot's Linear
+ * labels. The remote branch goes only with --remote, and only when no PR on
+ * it is open.
+ */
+async function reset(identifier, deleteRemote) {
+ if (!identifier) throw new Error("issue identifier required");
+ const record = load(identifier);
+ const issue = await linear.fetchIssue(identifier);
+ if (!issue) throw new Error(`Linear has no issue ${identifier}`);
+ const branch = record?.branch ?? issue.branchName;
+ const ref = {
+ id: issue.id,
+ identifier: issue.identifier,
+ teamId: issue.team?.id,
+ };
+
+ const pr = await github.findPr(branch);
+ if (pr?.state === "OPEN") {
+ throw new Error(
+ `${pr.url} is still open; close it before resetting ${identifier}`,
+ );
+ }
+ const dir = worktreePath(identifier);
+ await git.removeWorktree(dir);
+ console.log(`worktree removed: ${dir}`);
+ if (await git.deleteLocalBranch(branch))
+ console.log(`local branch deleted: ${branch}`);
+ if (deleteRemote) {
+ await git.deleteRemoteBranch(branch);
+ console.log(`remote branch deleted: ${config.remote}/${branch}`);
+ } else if (await git.remoteBranchExists(branch)) {
+ console.warn(
+ `${config.remote}/${branch} still exists; the next implementation would start from it. Rerun with --remote to delete it.`,
+ );
+ }
+ for (const label of [
+ config.labels.fix,
+ config.labels.skipped,
+ config.labels.escalated,
+ ]) {
+ await linear.removeLabel(ref, label);
+ }
+ remove(identifier);
+ console.log(`${identifier} forgotten; the next tick triages it again`);
+}
+
function status() {
const records = loadAll().sort(
(a, b) =>
@@ -106,6 +160,8 @@ async function main([command, arg]) {
);
return logged(`publish ${arg}`, () => publish(record));
}
+ case "reset":
+ return reset(arg, process.argv.includes("--remote"));
case "retry": {
const record = load(arg);
if (!record) throw new Error(`no record for ${arg}`);
diff --git a/tools/linear-autofix/src/git.mjs b/tools/linear-autofix/src/git.mjs
index 179244a..d24fc31 100644
--- a/tools/linear-autofix/src/git.mjs
+++ b/tools/linear-autofix/src/git.mjs
@@ -155,3 +155,29 @@ export async function installDeps(dir) {
timeoutMs: 15 * 60_000,
});
}
+
+/** Delete the local branch unless a worktree still has it checked out. */
+export async function deleteLocalBranch(branch) {
+ const { code, stderr } = await git(["branch", "-D", branch], {
+ allowFailure: true,
+ });
+ if (code !== 0 && !/not found/.test(stderr)) throw new Error(stderr.trim());
+ return code === 0;
+}
+
+/** Delete the branch on the remote. Human-invoked only (`reset --remote`). */
+export async function deleteRemoteBranch(branch) {
+ if (config.dryRun) {
+ console.log(`[dry-run] git push ${config.remote} --delete ${branch}`);
+ return;
+ }
+ await git(["push", config.remote, "--delete", branch], { timeoutMs: 60_000 });
+}
+
+export async function remoteBranchExists(branch) {
+ const { stdout } = await git(
+ ["ls-remote", "--heads", config.remote, branch],
+ { timeoutMs: 60_000 },
+ );
+ return stdout.trim() !== "";
+}
diff --git a/tools/linear-autofix/src/state.mjs b/tools/linear-autofix/src/state.mjs
index 8197a33..4e4f06b 100644
--- a/tools/linear-autofix/src/state.mjs
+++ b/tools/linear-autofix/src/state.mjs
@@ -35,6 +35,10 @@ export function load(identifier) {
}
}
+export function remove(identifier) {
+ fs.rmSync(recordPath(identifier), { force: true });
+}
+
export function loadAll() {
ensureStateDir();
return fs