diff --git a/EVENTS.md b/EVENTS.md index a4c0ddb..b0b656f 100644 --- a/EVENTS.md +++ b/EVENTS.md @@ -34,6 +34,7 @@ Each line is a JSON object: - `BotRecv` - Message received by bot - `BotSend` - Message sent by bot - `BeadReady` - A bead transitioned to open/ready; `source` is `beads/`, `data` is full bead JSON including comments +- `BeadClaimed` - A bead was claimed by an agent; `source` is `beads/`, `data` is `{"bead_id","assignee","mount"}` ## Consuming Events diff --git a/internal/eventbus/bus.go b/internal/eventbus/bus.go index 3030edb..d2df79b 100644 --- a/internal/eventbus/bus.go +++ b/internal/eventbus/bus.go @@ -19,7 +19,8 @@ const ( EventUserSend = "UserSend" EventBotRecv = "BotRecv" EventBotSend = "BotSend" - EventBeadReady = "BeadReady" // a bead transitioned to open/ready + EventBeadReady = "BeadReady" // a bead transitioned to open/ready + EventBeadClaimed = "BeadClaimed" // a bead was claimed by an agent ) // allTopic is the single topic used for all events. diff --git a/internal/p9/beads.go b/internal/p9/beads.go index d6eb5e8..17a93e7 100644 --- a/internal/p9/beads.go +++ b/internal/p9/beads.go @@ -811,7 +811,7 @@ func (b *BeadsFS) executeCtlOnStore(store bd.Storage, mountName, cmd string) err assignee = args[1] } beadID := args[0] - return store.RunInTransaction(b.ctx, func(tx bd.Transaction) error { + if err := store.RunInTransaction(b.ctx, func(tx bd.Transaction) error { issue, err := tx.GetIssue(b.ctx, beadID) if err != nil { return err @@ -826,7 +826,17 @@ func (b *BeadsFS) executeCtlOnStore(store bd.Storage, mountName, cmd string) err "assignee": assignee, "status": bd.StatusInProgress, }, actor) - }) + }); err != nil { + return err + } + if b.eventbus != nil { + b.eventbus.Publish("beads/"+mountName, eventbus.EventBeadClaimed, map[string]string{ + "bead_id": beadID, + "assignee": assignee, + "mount": mountName, + }) + } + return nil case "complete", "close": if len(args) < 1 { diff --git a/roles/author.md b/roles/author.md index d31e7ae..e8adb76 100644 --- a/roles/author.md +++ b/roles/author.md @@ -22,6 +22,28 @@ You are NOT allowed to: - Make architectural or implementation decisions + +## Bead Loop + +You run continuously. When idle, wait for work from the event bus: + +``` +Tool: execute_code +tool: wait_for_bead.sh +args: ["--mount", "$AGENT_MOUNT"] +``` + +When a bead arrives, inspect it. If it matches your role and you can do the work: + +1. Claim it: `claim_bead.sh --mount $AGENT_MOUNT --id ` +2. Read comments for prior context if `comment_count > 0` +3. Do the work +4. Complete it: `complete_bead.sh --mount $AGENT_MOUNT --id ` +5. Return to step 1 + +If you cannot or should not do the work (wrong role, blocked, out of scope), do not claim it — return to step 1. + + ## Workflow ``` diff --git a/roles/developer.md b/roles/developer.md index 28a2452..05627ab 100644 --- a/roles/developer.md +++ b/roles/developer.md @@ -18,6 +18,28 @@ You are NOT allowed to: - Perform any other activity outside the scope of writing code + +## Bead Loop + +You run continuously. When idle, wait for work from the event bus: + +``` +Tool: execute_code +tool: wait_for_bead.sh +args: ["--mount", "$AGENT_MOUNT"] +``` + +When a bead arrives, inspect it. If it matches your role and you can do the work: + +1. Claim it: `claim_bead.sh --mount $AGENT_MOUNT --id ` +2. Read comments for prior context if `comment_count > 0` +3. Do the work +4. Complete it: `complete_bead.sh --mount $AGENT_MOUNT --id ` +5. Return to step 1 + +If you cannot or should not do the work (wrong role, blocked, out of scope), do not claim it — return to step 1. + + ## Workflow 1. Read the PROMPT_REQUEST to understand the task diff --git a/roles/devops.md b/roles/devops.md index 93ac506..8a1cfd1 100644 --- a/roles/devops.md +++ b/roles/devops.md @@ -23,6 +23,28 @@ You are NOT allowed to: - Perform testing beyond smoke/health checks - Push directly to default branches — always use a PR + +## Bead Loop + +You run continuously. When idle, wait for work from the event bus: + +``` +Tool: execute_code +tool: wait_for_bead.sh +args: ["--mount", "$AGENT_MOUNT"] +``` + +When a bead arrives, inspect it. If it matches your role and you can do the work: + +1. Claim it: `claim_bead.sh --mount $AGENT_MOUNT --id ` +2. Read comments for prior context if `comment_count > 0` +3. Do the work +4. Complete it: `complete_bead.sh --mount $AGENT_MOUNT --id ` +5. Return to step 1 + +If you cannot or should not do the work (wrong role, blocked, out of scope), do not claim it — return to step 1. + + ## Workflow 1. Read the PROMPT_REQUEST to understand the task diff --git a/roles/pkgmgr.md b/roles/pkgmgr.md index 53d81a4..b28dc7a 100644 --- a/roles/pkgmgr.md +++ b/roles/pkgmgr.md @@ -26,6 +26,28 @@ You are NOT allowed to: - Modify upstream source — only packaging metadata and build scripts + +## Bead Loop + +You run continuously. When idle, wait for work from the event bus: + +``` +Tool: execute_code +tool: wait_for_bead.sh +args: ["--mount", "$AGENT_MOUNT"] +``` + +When a bead arrives, inspect it. If it matches your role and you can do the work: + +1. Claim it: `claim_bead.sh --mount $AGENT_MOUNT --id ` +2. Read comments for prior context if `comment_count > 0` +3. Do the work +4. Complete it: `complete_bead.sh --mount $AGENT_MOUNT --id ` +5. Return to step 1 + +If you cannot or should not do the work (wrong role, blocked, out of scope), do not claim it — return to step 1. + + ## Workflow 1. Read the PROMPT_REQUEST to understand the target package, format(s), and version diff --git a/roles/researcher.md b/roles/researcher.md index 2589739..a2af41d 100644 --- a/roles/researcher.md +++ b/roles/researcher.md @@ -23,6 +23,28 @@ You are NOT allowed to: - Write or modify application code - Implement solutions or work on tasks directly + +## Bead Loop + +You run continuously. When idle, wait for work from the event bus: + +``` +Tool: execute_code +tool: wait_for_bead.sh +args: ["--mount", "$AGENT_MOUNT"] +``` + +When a bead arrives, inspect it. If it matches your role and you can do the work: + +1. Claim it: `claim_bead.sh --mount $AGENT_MOUNT --id ` +2. Read comments for prior context if `comment_count > 0` +3. Do the work +4. Complete it: `complete_bead.sh --mount $AGENT_MOUNT --id ` +5. Return to step 1 + +If you cannot or should not do the work (wrong role, blocked, out of scope), do not claim it — return to step 1. + + ## Workflow For every query, follow this sequence (least to most expensive): diff --git a/roles/tester.md b/roles/tester.md index f345aa5..98cf2da 100644 --- a/roles/tester.md +++ b/roles/tester.md @@ -20,6 +20,28 @@ You are NOT allowed to: - Perform code reviews - Implement fixes — report failures and let the developer fix them + +## Bead Loop + +You run continuously. When idle, wait for work from the event bus: + +``` +Tool: execute_code +tool: wait_for_bead.sh +args: ["--mount", "$AGENT_MOUNT"] +``` + +When a bead arrives, inspect it. If it matches your role and you can do the work: + +1. Claim it: `claim_bead.sh --mount $AGENT_MOUNT --id ` +2. Read comments for prior context if `comment_count > 0` +3. Do the work +4. Complete it: `complete_bead.sh --mount $AGENT_MOUNT --id ` +5. Return to step 1 + +If you cannot or should not do the work (wrong role, blocked, out of scope), do not claim it — return to step 1. + + ## Workflow 1. Read the APPROVAL_REQUEST to identify modified files