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 harness/.claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "harness",
"version": "0.3.2",
"version": "0.3.3",
"description": "Integrated harness: the user's Claude rules enforced at the tool call (git, worktree, delete, venv, port, Linear, memory and order guards; a merge-and-release gate; report lint), plus session tooling and workflow automation.",
"author": {
"name": "unohee"
Expand Down
17 changes: 14 additions & 3 deletions harness/hooks/flow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ describe('guards', () => {
describe('ship-gate', () => {
test('a merged PR must close the issues the user handed over, Done and comment', async ($, on) => {
const w = world(on)
w.prView = JSON.stringify({ title: 'feat: x (QQQ-1)', body: 'also ZZZ-2', commits: [] })
w.prView = JSON.stringify({ title: 'feat: x', body: 'Closes QQQ-1. Refs ZZZ-2', commits: [] })
await start($)
await prompt($, 'QQQ-1 작업 PR 머지해줘')

Expand All @@ -137,9 +137,20 @@ describe('ship-gate', () => {
expect((await $.classic.Stop(STOP)).block).toBeUndefined()
})

test('an issue the PR only references is a toast, not a stop block', async ($, on) => {
const w = world(on)
w.prView = JSON.stringify({ title: 'feat: recovery mail (QQQ-1 W4)', body: 'Refs QQQ-1, QQQ-2', commits: [] })
await start($)
await prompt($, 'QQQ-1 QQQ-2 진행해줘')
await $.tool.call({ tool: 'Bash', command: 'gh pr merge 6 --squash' })

expect((await $.classic.Stop(STOP)).block).toBeUndefined()
expect(w.toasts.some(text => text.includes('QQQ-1') && text.includes('QQQ-2'))).toBe(true)
})

test('the stop block gives up after two tries', async ($, on) => {
const w = world(on)
w.prView = 'QQQ-1'
w.prView = 'Fixes QQQ-1'
await start($)
await prompt($, 'QQQ-1')
await $.tool.call({ tool: 'Bash', command: 'gh pr merge 5' })
Expand Down Expand Up @@ -216,7 +227,7 @@ describe('report-lint', () => {

test('one stop carries one block: report-lint first, the ship gate on the next stop', async ($, on) => {
const w = world(on, { toggles: { guards: true, shipGate: true, reportLint: true } })
w.prView = 'QQQ-1'
w.prView = 'Fixes QQQ-1'
await start($)
await prompt($, 'QQQ-1 고치고 머지')
await $.tool.call({ tool: 'Write', file_path: '/repo/a.py', content: 'x\n' })
Expand Down
8 changes: 7 additions & 1 deletion harness/hooks/pure.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { grantAllowsLinear, grantVerdict, senderName } from './grant'
import { gcSignature, gcSummary } from './memory-gc'
import { checkListIssues, checkSaveComment, checkSaveIssue, isLinearRequest, withoutReminders } from './linear-guard'
import { isEnglishLine, lintReport } from './report-lint'
import { isCodeqlAnalyze, isDoneState, isPrList, isReleaseCommand, issueIds, linearIds, mergedPr } from './ship-gate'
import { closingIds, isCodeqlAnalyze, isDoneState, isPrList, isReleaseCommand, issueIds, linearIds, mergedPr } from './ship-gate'

const ENV = { home: '/Users/u', tmpdir: '/var/folders/xx/T/', venv: '/Users/u/dev/mlx_env/bin/activate' }
const ROOT = '/Users/u/dev/repo'
Expand Down Expand Up @@ -147,6 +147,12 @@ test('port 1234 and openswarm review', async () => {
describe('ship-gate parsing', () => {
test('issue ids, merges, PR lists, CodeQL, Done states', async () => {
expect(issueIds('feat: x (INT-12)\nfixes STO-1737 and INT-12')).toEqual(['INT-12', 'STO-1737'])
expect(closingIds('feat: x (INT-12)\nfixes STO-1737 and INT-12')).toEqual(['STO-1737', 'INT-12'])
expect(closingIds('Closes: AUD-1, AUD-2 & AUD-3. Refs AUD-9')).toEqual(['AUD-1', 'AUD-2', 'AUD-3'])
expect(closingIds('Resolved AUD-4')).toEqual(['AUD-4'])
expect(closingIds('Refs AUD-1662, AUD-2209. Do not close either.')).toEqual([])
expect(closingIds('feat(recovery): mail (AUD-2374 W4)')).toEqual([])
expect(closingIds('the closest AUD-5 is a fixture')).toEqual([])
expect(mergedPr('gh pr merge 42 --squash')).toBe('42')
expect(mergedPr('cd repo && gh pr merge --squash --delete-branch')).toBe('')
expect(mergedPr('gh pr view 42')).toBeUndefined()
Expand Down
26 changes: 21 additions & 5 deletions harness/hooks/ship-gate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const envAtom = atom({ plugin: 'harness', key: 'env' } as const, {}, { shape: 'e

// Merge and release gate (rules/linear-grooming.md §5, CLAUDE.md §5):
// - after `gh pr merge`, every issue the user handed over in this session and
// named by that PR must get a Done transition and an evidence comment before
// closed by that PR (Closes/Fixes/Resolves <ID>) must get a Done transition and an evidence comment before
// the turn may stop (2026-07-08: three misses in a row);
// - an irreversible release or deploy needs `gh pr list` (open PRs) and a
// CodeQL run first (2026-07-09 release without a PR; 2026-08-14 CodeQL found
Expand All @@ -34,6 +34,19 @@ export function issueIds(text: string): string[] {
return [...new Set(text.match(ISSUE_ID) ?? [])]
}

// IDs a PR says it closes: "Closes AUD-1", "Fixes: AUD-1, AUD-2", "resolves AUD-1 and AUD-2". A bare mention
// ("Refs AUD-1", an umbrella program in a title) is a reference, not a claim to finish the issue, so it must not
// demand a Done transition (2026-11-07: umbrella issues AUD-2209/AUD-2374, named only as context, blocked every
// stop for a whole session).
const CLOSING = /\b(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)\b\s*:?\s+((?:[A-Z][A-Z0-9]{1,5}-\d+\b(?:\s*(?:,|and|&)\s*)?)+)/gi

export function closingIds(text: string): string[] {
const out: string[] = []
for (const match of text.matchAll(CLOSING)) out.push(...(match[1].match(ISSUE_ID) ?? []))

return [...new Set(out)]
}

// Only IDs the Linear workspace can have: `issue_patterns` in ~/.claude/linear.json (e.g. "AX-\\d+"). Other
// TEAM-123 shapes in a PR body (security gate IDs like HSG-01, CVE numbers) are not issues and must not block a
// stop (2026-10-27: HSG-01/HSG-05 from PR 45 blocked every stop). With no patterns configured, nothing is filtered.
Expand Down Expand Up @@ -266,12 +279,15 @@ async function trackMerge($: EngineInterface, pr: string, command: string): Prom
} catch {
// gh unavailable: nothing to track.
}
const ids = linearIds(issueIds(text), await issuePatterns($))
if (ids.length === 0) return
const patterns = await issuePatterns($)
const named = linearIds(issueIds(text), patterns)
if (named.length === 0) return
// Only issues the PR closes (Closes/Fixes/Resolves) and the user handed over are tracked; the rest is a toast.
const ids = linearIds(closingIds(text), patterns)
const ship = await read($, shipAtom)
const handed = ids.filter(id => ship.mentioned.includes(id))
const other = ids.filter(id => !ship.mentioned.includes(id))
if (other.length > 0) $.ui.toast(`Merged PR ${pr} also names ${other.join(', ')}; close them in Linear if they were yours.`)
const other = named.filter(id => !handed.includes(id))
if (other.length > 0) $.ui.toast(`Merged PR ${pr} also names ${other.join(', ')}; close them in Linear if this PR finished them.`)
if (handed.length === 0) return
await update($, shipAtom, s => ({
...s,
Expand Down
Loading