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
2 changes: 1 addition & 1 deletion auto-claude/.claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "auto-claude",
"version": "1.1.0",
"version": "1.2.0",
"description": "Finishes a repository's work unattended and live: Claude plans the long-term end state, its milestones and how it deploys; the built-in loop builds each milestone in its own worktree and judges it; auto-claude ships it (push, PR, CI, merge when green), deploys and smoke-checks it, and a watchdog keeps the run moving until the final check passes. Absorbs goal-mode's loop (1.0.0).",
"author": {
"name": "unohee"
Expand Down
12 changes: 12 additions & 0 deletions auto-claude/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ A committed `.claude/auto-deploy.json` takes precedence: the person decided. The
- It is merged like any milestone, and the deploy then runs again.
- 3 deploys failing in a row stop the run. Nothing more is merged on top of a broken live service.

## Linear

A run keeps the repository's Linear project in step, through the session's own `linear-server` MCP connection (no API key is read). Only a repository mapped to a project syncs: `repo_mapping.<folder name>.projectId` or `projectName` in `~/.claude/linear.json`. A team alone is shared by many repositories, so it is not enough. An unmapped repository syncs nothing, and `status` says `linear: off`.

- **Planning.** The planning prompt (and each replan) lists the project's open issues: triage, backlog, unstarted and started. A milestone that resolves issues starts with their IDs: `- [ ] [AX-12] <end state> :: check: <command>`. An open issue the plan leaves out gets a line under `## Decisions`.
- **While the run goes.** Every 10 minutes, and once more before the run may finish, the driver reads the open issues. It also reads the newest comments on the 25 most recently changed issues and on every issue the run has a line for. A new comment on an older issue waits until the issue itself changes. Every open issue counts as covered from the moment the run starts, so comments written before it never count. A run that started unmapped (or under an older version) adopts the project on its next tick. Comments do not move an issue's `updatedAt` (measured 2026-11-13), so they are read on their own. An issue that is new or changed since the run last covered it gets a queue line, at most 5 per sync. The line has no check, so the evaluator judges it: `- [ ] [AX-12] <title>: what Linear AX-12 asks is resolved on this branch (…)`. A change to an issue whose line is still pending is covered by that line. A change to an issue being built or shipped is looked at when it merges. Each issue gets at most 2 follow-up lines.
- **Closed issues.** An issue closed while its line waits (cancelled, done elsewhere) blocks that line. The driver never moves a closed issue back to `started`. At merge, a closed issue only gets the evidence comment.
- **No new issues during a run.** The model is told not to create issues, and harness refuses an unrequested create while a run owns the repository. Otherwise a new issue would become a milestone of the same run.
- **Write-back.** A milestone that starts moves its issues to `started`. One that merges moves them to `completed`, with a comment naming the PR. If the issue changed in Linear while the milestone was built, it stays open instead, with a comment and a follow-up line. A held or blocked milestone gets a comment only. The driver's comments start with `[auto-claude]` and never count as changes. The model is told never to change these issues' state or comment on them.
- **Signal for other mods.** Each tick writes `.claude/auto-claude.on` (`{ on, phase, at }`, git-excluded). harness reads it, and leaves issue states to the driver while a run owns the repository.
- `--queue` runs neither read nor write Linear.

## Autonomy and its limits

- **Choices.** Claude decides every choice itself and records it under `## Decisions`. Irreversible steps (credentials, payment, deleting data, a new public release) go through `mcp__auto-claude__defer_goal` and are never taken.
Expand Down
108 changes: 108 additions & 0 deletions auto-claude/hooks/auto.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1158,3 +1158,111 @@ describe('a directory with no git repository', () => {
expect(w.runs.some(a => a.includes(' init'))).toBe(false)
})
})

describe('Linear sync', () => {
// A fake Linear behind $.mcp.call: issues, comments and every write.
function linear(on: On, w: W) {
const l = {
issues: [{ id: 'KT-1', title: 'add() is wrong', updatedAt: '2026-11-13T10:00:00Z', status: 'Todo', statusType: 'unstarted' }] as Array<Record<string, string>>,
comments: {} as Record<string, Array<{ body: string; createdAt: string }>>,
writes: [] as string[],
}
w.files.set('/home/.claude/linear.json', JSON.stringify({ repo_mapping: { repo: { team: 'T', projectName: 'Repo' } } }))
const text = (v: unknown) => ({ value: { content: [{ type: 'text' as const, text: JSON.stringify(v) }], isError: false } })
on('mcp.call', (_, e) => {
const a = e.args
if (e.tool === 'list_issues') return text({ issues: l.issues.filter(i => i.statusType === a.state), hasNextPage: false })
if (e.tool === 'list_comments') return text({ comments: l.comments[String(a.issueId)] ?? [] })
if (e.tool === 'get_issue') return text(l.issues.find(i => i.id === a.id) ?? {})
if (e.tool === 'save_issue') {
l.writes.push(`state ${String(a.id)} ${String(a.state)}`)
const issue = l.issues.find(i => i.id === a.id)
// A write moves updatedAt, as Linear does.
if (issue !== undefined) Object.assign(issue, { updatedAt: '2026-11-13T11:00:00Z', statusType: a.state === 'completed' ? 'completed' : 'started' })
return text(issue ?? {})
}
if (e.tool === 'save_comment') {
l.writes.push(`comment ${String(a.issueId)} ${String(a.body)}`)
;(l.comments[String(a.issueId)] ??= []).push({ body: String(a.body), createdAt: '2026-11-13T11:00:00Z' })
return text({ id: 'c' })
}
return { value: { content: [{ type: 'text' as const, text: 'unknown tool' }], isError: true } }
})
return l
}

test('the planning prompt lists open issues; a milestone naming one moves it to started, and its merge to Done with evidence', async ($, on) => {
const w = world(on)
const l = linear(on, w)
await $.session.start({ cwd: '/repo', surface: 'terminal', isInteractive: true })
await cmd($, 'start')
await w.clock.advance(200)
expect(w.prompts[0]).toContain('Linear project "Repo" has 1 open issue(s)')
expect(w.prompts[0]).toContain('KT-1 [Todo] add() is wrong')
w.files.set('/repo/.claude/auto-plan.md', PLAN)
w.files.set(GOALS, QUEUE.replace('- [ ] add()', '- [ ] [KT-1] add()'))
await ready($)
await w.clock.advance(1_200)
await w.clock.advance(TICK)
expect(l.writes).toContain('state KT-1 started')

await meet($, w)
await w.clock.advance(TICK)
expect(l.writes).toContain('state KT-1 completed')
expect(l.writes.find(x => x.startsWith('comment KT-1'))).toContain('[auto-claude] Merged into main')
expect((await cmd($, 'status')).text).toContain('linear: project Repo')
})

test('an issue opened or commented on mid-run is queued as a milestone; the driver\'s own comments are not changes', async ($, on) => {
const w = world(on)
const l = linear(on, w)
await planned($, w)
// A new issue, and a person's comment on the one the plan saw.
l.issues.push({ id: 'KT-2', title: 'sub() needs docs', updatedAt: '2026-11-13T12:00:00Z', status: 'Todo', statusType: 'unstarted' })
l.comments['KT-1'] = [{ body: 'also handle floats', createdAt: '2026-11-13T12:30:00Z' }, { body: '[auto-claude] noise', createdAt: '2026-11-13T13:00:00Z' }]
await w.clock.advance(11 * MIN)
const queue = w.files.get(GOALS) ?? ''
expect(queue).toContain('- [ ] [KT-2] sub() needs docs: what Linear KT-2 asks is resolved on this branch')
expect(queue).toContain('- [ ] [KT-1] add() is wrong: the comments and changes on KT-1 since 2026-11-13T10:00:00Z are handled')
// The lines parse back to one condition each, with no check.
expect(parseQueue(queue).filter(i => i.condition.startsWith('[KT-')).every(i => i.check === undefined)).toBe(true)
// Nothing new: the next sync queues nothing more.
await w.clock.advance(11 * MIN)
expect(parseQueue(w.files.get(GOALS) ?? '').filter(i => i.condition.startsWith('[KT-')).length).toBe(2)
})

test('a pending line whose issue was closed is blocked, and a closed issue is never moved to started', async ($, on) => {
const w = world(on)
const l = linear(on, w)
l.issues.push({ id: 'KT-3', title: 'sub', updatedAt: '2026-11-13T10:00:00Z', status: 'Todo', statusType: 'unstarted' })
await $.session.start({ cwd: '/repo', surface: 'terminal', isInteractive: true })
await cmd($, 'start')
w.files.set('/repo/.claude/auto-plan.md', PLAN)
w.files.set(GOALS, QUEUE.replace('- [ ] sub()', '- [ ] [KT-3] sub()'))
await ready($)
await w.clock.advance(1_200)
// The person cancels KT-3 while milestone 1 is built.
Object.assign(l.issues[1]!, { statusType: 'canceled', status: 'Canceled' })
await w.clock.advance(11 * MIN)
expect(w.files.get(GOALS)).toMatch(/- \[!\] \[KT-3\] sub\(\).*Linear KT-3 was closed \(Canceled\)/)
expect(l.writes.filter(x => x.startsWith('state KT-3'))).toEqual([])
})

test('a run that started without Linear adopts the project on a tick once the repo is mapped', async ($, on) => {
const w = world(on)
linear(on, w)
const mapping = w.files.get('/home/.claude/linear.json')!
w.files.delete('/home/.claude/linear.json')
await planned($, w)
expect((await cmd($, 'status')).text).toContain('linear: off')
w.files.set('/home/.claude/linear.json', mapping)
await w.clock.advance(TICK)
expect((await cmd($, 'status')).text).toContain('linear: project Repo')
})

test('a repository mapped to no project syncs nothing and says so', async ($, on) => {
const w = world(on)
await planned($, w)
expect((await cmd($, 'status')).text).toContain('linear: off')
})
})
Loading
Loading