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 docs/AGENT_BOARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ A claim has a kind and a key, and each key has one holder at a time:
| Kind | Key | Example |
| --- | --- | --- |
| `module` | machine and module id | `octatrack/tape-echo`, `digitone/swarm` |
| `hook` | machine and hook or table index: its `index` in `sdk/machines/octatrack/events.json`, or its place in the core's `interface.json` on the elemod machines. Consecutive new indices are one claim on a run, which `pr:ready` makes and which takes the place of your own claims inside it | `octatrack/39`, `octatrack/38-51`, `digitakt/events/7`, `digitakt/tables/1` |
| `hook` | machine and hook or table index: its `index` in `sdk/machines/octatrack/events.json`, or its place in the core's `interface.json` on the elemod machines. Consecutive new indices are one claim on a run, which `pr:ready` makes and which takes the place of your own claims inside it. A run claimed ahead of the work also covers a branch that adds only part of it | `octatrack/39`, `octatrack/38-51`, `digitakt/events/7`, `digitakt/tables/1` |
| `migration` | D1 migration number | `0085` |
| `dsp-region` | machine and DSP memory claim name; no file declares these yet, so they are claimed by hand | `octatrack/fx2-delay-line` |
| `machine-id` | machine and the id a manifest takes in `platform.claims` (`machine:<id>`); kits store it, so like a hook index it is never renumbered | `digitakt/10` |
Expand Down
10 changes: 6 additions & 4 deletions scripts/agent-board.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ export function neededClaims({ root, base, head = 'HEAD' }) {

const hookSpan = key => { const [, list, first, last] = /^(.+)\/(\d+)(?:-(\d+))?$/.exec(key); return { list, first: Number(first), last: Number(last ?? first) } }
const overlaps = (a, b) => { const x = hookSpan(a), y = hookSpan(b); return x.list === y.list && x.first <= y.last && y.first <= x.last }
const covers = (a, b) => { const x = hookSpan(a), y = hookSpan(b); return x.list === y.list && x.first <= y.first && y.last <= x.last }
/** Consecutive new hook indices of one list become one claim (octatrack/38-51): a base change may add more hooks than
* one person may hold claims. */
function hookRuns(items) {
Expand All @@ -224,13 +225,14 @@ export async function compareClaims(needed, login, { pullRequest, ...options } =
const claims = await listClaims({}, options), byKey = new Map(claims.map(item => [item.kind + ' ' + item.key, item]))
const result = { mine: [], others: [], free: [], unknown: [] }
for (const item of needed) {
// Hook claims overlap by index; the holder's own inside a run give way to it when the run is claimed.
// Hook claims overlap by index; the holder's own inside a run give way to it when the run is claimed. A run claimed
// ahead of the work (tables/4-6 while the branch adds 4-5 so far) covers the part a branch adds.
const near = item.kind === 'hook' ? claims.filter(claim => claim.kind === 'hook' && overlaps(claim.key, item.key)) : [byKey.get(item.kind + ' ' + item.key)].filter(Boolean)
const theirs = login && near.find(claim => claim.holder !== login.toLowerCase() && !(pullRequest && claim.pullRequest === pullRequest)), exact = near.find(claim => claim.key === item.key)
const theirs = login && near.find(claim => claim.holder !== login.toLowerCase() && !(pullRequest && claim.pullRequest === pullRequest)), held = near.find(claim => claim.key === item.key) ?? (item.kind === 'hook' ? near.find(claim => covers(claim.key, item.key)) : undefined)
if (!near.length) result.free.push(item)
else if (!login) result.unknown.push({ ...item, claim: near[0] })
else if (theirs) result.others.push({ ...item, claim: theirs })
else if (exact) result.mine.push({ ...item, claim: exact })
else if (held) result.mine.push({ ...item, claim: held })
else result.free.push(item)
}
return result
Expand Down Expand Up @@ -375,7 +377,7 @@ export function branchVerdict(compared, { requireClaims = false } = {}) {
const lines = []
for (const item of compared.others) lines.push(`✗ ${item.kind} ${item.key} (${item.why}) is claimed by ${describeClaim(item.claim)}. Ask them, or renumber / rename.`)
for (const item of compared.unknown) lines.push(`· ${item.kind} ${item.key} is claimed by ${describeClaim(item.claim)}; sign in (npm run board -- login) so the check can tell whether that is you.`)
for (const item of compared.mine) lines.push(`✓ ${item.kind} ${item.key}: yours.`)
for (const item of compared.mine) lines.push(`✓ ${item.kind} ${item.key}: yours${item.claim && item.claim.key !== item.key ? ' (claim ' + item.claim.key + ')' : ''}.`)
for (const item of compared.free) lines.push(requireClaims
? `✗ ${item.kind} ${item.key} (${item.why}) is unclaimed. Claim it so nobody else starts the same work: npm run board -- login once, then npm run pr:ready (it claims what the branch adds) or npm run board -- claim ${item.kind} ${item.key}. Then rerun this check.`
: `· ${item.kind} ${item.key} (${item.why}) is unclaimed: npm run board -- claim ${item.kind} ${item.key}`)
Expand Down
17 changes: 17 additions & 0 deletions scripts/agent-board.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ describe('the board client', () => {
expect((await compare(claimRow('hook', 'octatrack/38-51', 'ada'))).mine).toHaveLength(1)
expect((await compare(claimRow('hook', 'octatrack/events/40', 'bo'), claimRow('hook', 'octatrack/52', 'bo'))).free).toHaveLength(1)
})
it('counts a run claimed ahead of the work as covering the part a branch adds', async () => {
const needed = [{ kind: 'hook', key: 'digitakt-ii/tables/4-5' }]
const compare = (claims, pullRequest) => board.compareClaims(needed, 'Ada', { fetch: answer(200, { claims }), pullRequest })
expect((await compare([claimRow('hook', 'digitakt-ii/tables/4-6', 'ada')])).mine[0].claim.key).toBe('digitakt-ii/tables/4-6')
expect((await compare([{ ...claimRow('hook', 'digitakt-ii/tables/4-6', 'claptom'), pullRequest: 1999 }], 1999)).mine).toHaveLength(1)
expect((await compare([claimRow('hook', 'digitakt-ii/tables/4-6', 'bo')])).others).toHaveLength(1)
expect((await compare([claimRow('hook', 'digitakt-ii/tables/4', 'ada')])).free).toHaveLength(1)
expect((await compare([claimRow('hook', 'digitakt-ii/tables/5-6', 'ada')])).free).toHaveLength(1)
expect((await compare([claimRow('hook', 'digitakt-ii/events/4-6', 'ada')])).free).toHaveLength(1)
expect(board.branchVerdict(await compare([claimRow('hook', 'digitakt-ii/tables/4-6', 'ada')]), { requireClaims: true })).toEqual({ ok: true, lines: ['✓ hook digitakt-ii/tables/4-5: yours (claim digitakt-ii/tables/4-6).'] })
})
it('fails an unclaimed item only in a pull request run, and someone else\'s claim always', () => {
const free = { mine: [], others: [], unknown: [], free: [{ kind: 'module', key: 'octatrack/drummap', why: 'new module' }] }
expect(board.branchVerdict(free).ok).toBe(true)
Expand Down Expand Up @@ -227,6 +238,12 @@ describe('pr:ready and the board', () => {
expect(await run({ claims: [handWritten] })).toEqual([{ kind: 'module', key: 'octatrack/slicer', branch: 'work', note: 'Slices a loop.' }, { kind: 'module', key: 'octatrack/echo', branch: 'work' }])
expect((await run({ refuseNotes: true })).map(item => item.key + (item.note ? ' + note' : ''))).toEqual(['octatrack/slicer + note', 'octatrack/slicer', 'octatrack/echo + note', 'octatrack/echo'])
})
it('renews a covering run whole instead of claiming only the part the branch adds', async () => {
const { taken, module } = fake({ claims: [claimRow('hook', 'octatrack/36-38', 'ada')] })
const result = await boardClaims('.', 'main', module)
expect(taken.map(item => item.key)).toEqual(['0084', 'octatrack/36-38'])
expect(result.notes).toContain('Board: claimed hook octatrack/36-38 for @ada.')
})
it('only notes an unreachable board', async () => {
const result = await boardClaims('.', 'main', fake({ fail: true }).module)
expect(readiness({ board: result })).toMatchObject({ ok: true, notes: expect.arrayContaining([expect.stringContaining('claims not checked')]) })
Expand Down
5 changes: 3 additions & 2 deletions scripts/pr-ready.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,10 @@ export async function boardClaims(root, base, board) {
else for (const item of open) {
try {
// A claim says what the work is; a note its holder wrote by hand stays, and one the server refuses never costs the claim.
const request = { kind: item.kind, key: item.key, branch: board.currentBranch(root) }, note = item.claim?.note ? '' : item.note
// A run you hold that covers this item is renewed whole, so claiming the part never gives up the rest of the run.
const request = { kind: item.kind, key: item.claim?.key ?? item.key, branch: board.currentBranch(root) }, note = item.claim?.note ? '' : item.note
const result = note ? await board.claim({ ...request, note }).catch(error => { if (error instanceof board.BoardError && error.status === 400) return board.claim(request); throw error }) : await board.claim(request)
notes.push((result.renewed ? 'Board: renewed your claim on ' : 'Board: claimed ') + item.kind + ' ' + item.key + ' for @' + login + '.')
notes.push((result.renewed ? 'Board: renewed your claim on ' : 'Board: claimed ') + item.kind + ' ' + request.key + ' for @' + login + '.')
} catch (error) {
if (error instanceof board.BoardUnavailable) { notes.push('Board: could not claim ' + item.kind + ' ' + item.key + '. ' + error.message); continue }
problems.push('Board: ' + item.kind + ' ' + item.key + ': ' + error.message)
Expand Down
Loading