feat(beads): Add hq- prefix helpers for town-level beads (gt-y24km, gt-qgmyz)
Phase 1: Create agent_ids.go with town-level bead ID helpers - MayorBeadIDTown(), DeaconBeadIDTown(), DogBeadIDTown() - RoleBeadIDTown() and role-specific helpers (hq-*-role) - Add deprecation notices to old gt-* prefix functions Phase 2: Create town-level agent beads during gt install - initTownAgentBeads() creates hq-mayor, hq-deacon agent beads - Creates role beads: hq-mayor-role, hq-deacon-role, etc. - Update rig/manager.go to use rig beads for Witness/Refinery This aligns with the two-level beads architecture: - Town beads (~/gt/.beads/): hq-* prefix for Mayor, Deacon, roles - Rig beads (<rig>/.beads/): <prefix>-* for Witness, Refinery, Polecats 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -329,21 +329,22 @@ exit 1
|
||||
}
|
||||
}
|
||||
|
||||
func TestInitAgentBeadsUsesTownBeadsDir(t *testing.T) {
|
||||
// Agent beads use town beads (gt-* prefix) for cross-rig coordination.
|
||||
// The Manager.townRoot determines where agent beads are created.
|
||||
func TestInitAgentBeadsUsesRigBeadsDir(t *testing.T) {
|
||||
// Rig-level agent beads (witness, refinery) are stored in rig beads.
|
||||
// Town-level agents (mayor, deacon) are created by gt install in town beads.
|
||||
// This test verifies that rig agent beads are created in the rig directory,
|
||||
// without an explicit BEADS_DIR override (uses cwd-based discovery).
|
||||
townRoot := t.TempDir()
|
||||
townBeadsDir := filepath.Join(townRoot, ".beads")
|
||||
rigPath := filepath.Join(townRoot, "testrip")
|
||||
mayorRigPath := filepath.Join(rigPath, "mayor", "rig")
|
||||
rigBeadsDir := filepath.Join(rigPath, ".beads")
|
||||
|
||||
if err := os.MkdirAll(townBeadsDir, 0755); err != nil {
|
||||
t.Fatalf("mkdir town beads dir: %v", err)
|
||||
}
|
||||
if err := os.MkdirAll(mayorRigPath, 0755); err != nil {
|
||||
t.Fatalf("mkdir mayor rig: %v", err)
|
||||
if err := os.MkdirAll(rigBeadsDir, 0755); err != nil {
|
||||
t.Fatalf("mkdir rig beads dir: %v", err)
|
||||
}
|
||||
|
||||
// Track which agent IDs were created
|
||||
var createdAgents []string
|
||||
|
||||
script := `#!/usr/bin/env bash
|
||||
set -e
|
||||
if [[ "$1" == "--no-daemon" ]]; then
|
||||
@@ -353,17 +354,10 @@ cmd="$1"
|
||||
shift
|
||||
case "$cmd" in
|
||||
show)
|
||||
if [[ "$BEADS_DIR" != "$EXPECT_BEADS_DIR" ]]; then
|
||||
echo "BEADS_DIR mismatch" >&2
|
||||
exit 1
|
||||
fi
|
||||
# Return empty to indicate agent doesn't exist yet
|
||||
echo "[]"
|
||||
;;
|
||||
create)
|
||||
if [[ "$BEADS_DIR" != "$EXPECT_BEADS_DIR" ]]; then
|
||||
echo "BEADS_DIR mismatch" >&2
|
||||
exit 1
|
||||
fi
|
||||
id=""
|
||||
title=""
|
||||
for arg in "$@"; do
|
||||
@@ -372,13 +366,12 @@ case "$cmd" in
|
||||
--title=*) title="${arg#--title=}" ;;
|
||||
esac
|
||||
done
|
||||
# Log the created agent ID for verification
|
||||
echo "$id" >> "$AGENT_LOG"
|
||||
printf '{"id":"%s","title":"%s","description":"","issue_type":"agent"}' "$id" "$title"
|
||||
;;
|
||||
slot)
|
||||
if [[ "$BEADS_DIR" != "$EXPECT_BEADS_DIR" ]]; then
|
||||
echo "BEADS_DIR mismatch" >&2
|
||||
exit 1
|
||||
fi
|
||||
# Accept slot commands
|
||||
;;
|
||||
*)
|
||||
echo "unexpected command: $cmd" >&2
|
||||
@@ -388,12 +381,38 @@ esac
|
||||
`
|
||||
|
||||
binDir := writeFakeBD(t, script)
|
||||
agentLog := filepath.Join(t.TempDir(), "agents.log")
|
||||
t.Setenv("PATH", binDir+string(os.PathListSeparator)+os.Getenv("PATH"))
|
||||
t.Setenv("EXPECT_BEADS_DIR", townBeadsDir)
|
||||
t.Setenv("BEADS_DIR", "")
|
||||
t.Setenv("AGENT_LOG", agentLog)
|
||||
t.Setenv("BEADS_DIR", "") // Clear any existing BEADS_DIR
|
||||
|
||||
manager := &Manager{townRoot: townRoot}
|
||||
if err := manager.initAgentBeads(rigPath, "demo", "gt", false); err != nil {
|
||||
t.Fatalf("initAgentBeads: %v", err)
|
||||
}
|
||||
|
||||
// Verify the expected rig-level agents were created
|
||||
data, err := os.ReadFile(agentLog)
|
||||
if err != nil {
|
||||
t.Fatalf("reading agent log: %v", err)
|
||||
}
|
||||
createdAgents = strings.Split(strings.TrimSpace(string(data)), "\n")
|
||||
|
||||
// Should create witness and refinery for the rig
|
||||
expectedAgents := map[string]bool{
|
||||
"gt-demo-witness": false,
|
||||
"gt-demo-refinery": false,
|
||||
}
|
||||
|
||||
for _, id := range createdAgents {
|
||||
if _, ok := expectedAgents[id]; ok {
|
||||
expectedAgents[id] = true
|
||||
}
|
||||
}
|
||||
|
||||
for id, found := range expectedAgents {
|
||||
if !found {
|
||||
t.Errorf("expected agent %s was not created", id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user