Abilities: keys, Base's board on the wire, and its storage
wire gains the seven ability keys in the spec's order, the Base-Capabilities values, the refusal codes, Base's AbilityBoard (unknown keys dropped as it is read), AssistantAbilities and AbilitiesRefreshed. Migration 0115 (main ends at 0114) stores each person's board per origin in chat_assistant_abilities, ability_held_at on hand-offs and the newest capabilities on hosts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
8 files changed,
+221
−3
internal/equipo/chat/abilities_store.go+59 −0internal/equipo/chat/assistant_tools.go+3 −0internal/equipo/chat/handoff.go+4 −0internal/equipo/chat/models.go+1 −1internal/equipo/migrations/0115_assistant_abilities.sql+15 −0internal/equipo/migrations/schema.sql+3 −2internal/wire/abilities.go+96 −0internal/wire/abilities_test.go+40 −0
diff --git a/internal/equipo/chat/abilities_store.go b/internal/equipo/chat/abilities_store.go| new file mode 100644 |
| index 00000000..b14ce63f |
| --- /dev/null |
| +++ b/internal/equipo/chat/abilities_store.go |
| @@ -0,0 +1,59 @@ |
| +package chat |
| + |
| +import ( |
| + "encoding/json" |
| + "time" |
| + |
| + "amadan.net/oficina/equipo/internal/wire" |
| +) |
| + |
| +// The sources of a stored board. |
| +const ( |
| + // SourceBase: Base answered GET /api/v1/abilities. |
| + SourceBase = "base" |
| + // SourceLegacy: the defaults, renewed while a Base older than the |
| + // board (its board route 404, its operations 200) honours the token. |
| + SourceLegacy = "legacy" |
| +) |
| + |
| +// abilitiesRecord is a person's board as their Base last answered it |
| +// (spec §5.3), per origin. FetchSeq orders the fetches, so a slow old |
| +// answer never overwrites a newer one; ConfirmedAt is the last answer |
| +// that counted, RevokedAt a 401; AuthoritativeSeen is set once the |
| +// origin has answered the board and is never cleared. |
| +type abilitiesRecord struct { |
| + Person string `gorm:"primaryKey"` |
| + Origin string `gorm:"primaryKey"` |
| + Revision int64 |
| + Abilities string |
| + Admin bool |
| + Ask string |
| + Source string |
| + FetchSeq int64 |
| + ConfirmedAt *time.Time |
| + RevokedAt *time.Time |
| + AuthoritativeSeen bool |
| +} |
| + |
| +func (abilitiesRecord) TableName() string { return "chat_assistant_abilities" } |
| + |
| +// board is the record as Base's board: its switches, admin and ask. |
| +func (r abilitiesRecord) board() (wire.AbilityBoard, error) { |
| + b := wire.AbilityBoard{Revision: r.Revision, Admin: r.Admin, Ask: r.Ask, Abilities: map[string]bool{}} |
| + if r.Abilities == "" { |
| + return b, nil |
| + } |
| + if err := json.Unmarshal([]byte(r.Abilities), &b.Abilities); err != nil { |
| + return wire.AbilityBoard{}, err |
| + } |
| + return b, nil |
| +} |
| + |
| +// defaultBoard is every key on: what a legacy Base's members have. |
| +func defaultBoard() map[string]bool { |
| + out := map[string]bool{} |
| + for _, k := range wire.Abilities { |
| + out[k] = true |
| + } |
| + return out |
| +} |
diff --git a/internal/equipo/chat/assistant_tools.go b/internal/equipo/chat/assistant_tools.go| index 66d7b405..79514758 100644 |
| --- a/internal/equipo/chat/assistant_tools.go |
| +++ b/internal/equipo/chat/assistant_tools.go |
| @@ -94,6 +94,9 @@ type assistantHostRecord struct { |
| Token string |
| Revision int64 |
| UpdatedAt time.Time |
| + // Capabilities is the newest Base-Capabilities the person's Base |
| + // sent (noteCapabilities): presentation only, never authority. |
| + Capabilities string |
| } |
| func (assistantHostRecord) TableName() string { return "chat_assistant_hosts" } |
diff --git a/internal/equipo/chat/handoff.go b/internal/equipo/chat/handoff.go| index 199604e9..08a89094 100644 |
| --- a/internal/equipo/chat/handoff.go |
| +++ b/internal/equipo/chat/handoff.go |
| @@ -94,6 +94,10 @@ type handoffRecord struct { |
| Lane string |
| Title string |
| Nudges int64 `gorm:"not null;default:0"` |
| + // AbilityHeldAt is when the job's work was first held because its |
| + // person can't have building done (spec §6.3): set once, cleared only |
| + // by the person's Try again (resumeAbilityHold). |
| + AbilityHeldAt *time.Time |
| } |
| func (handoffRecord) TableName() string { return "chat_handoffs" } |
diff --git a/internal/equipo/chat/models.go b/internal/equipo/chat/models.go| index 1ba41f39..6539b478 100644 |
| --- a/internal/equipo/chat/models.go |
| +++ b/internal/equipo/chat/models.go |
| @@ -11,7 +11,7 @@ import ( |
| ) |
| // Models are the tables this package owns, for the migration check. |
| -var Models = append([]any{&changeDiffRecord{}, ¬ificationReceipt{}, &projectNameRecord{}, &cardVisibility{}, &cardThreadRecord{}, ©AttemptRecord{}, ©ReviewRecord{}, ©FeedbackRecord{}, &turnRecord{}, &messageRecord{}, &eventRecord{}, &commandRecord{}, &inboxRecord{}, &runnerSessionRecord{}, &projectRecord{}, &cardRecord{}, &toolCallRecord{}, &settingRecord{}, &coordinatorRecord{}, ¬ebookRecord{}, &taskRecord{}, &stepRecord{}, &entryRecord{}, &attachmentRecord{}, &starRecord{}, &questionRecord{}, &connectionRecord{}, &usageRecord{}, &distinctRecord{}, &hkRecord{}, &hkFailureRecord{}, &hkSettingsRecord{}, &fileRecord{}, &fileDataRecord{}, &transferRecord{}, &mergePolicyRecord{}, &mergeAuditRecord{}, &specialistRecord{}, &grantRecord{}, &specialistAuditRecord{}, &researchSourceRecord{}, &researchAddressRecord{}, &researchPrefixRecord{}, &researchInventoryRecord{}, &researchRecord{}, &researchFetchRecord{}, &taskFileRecord{}, &taskFileDataRecord{}, &releaseRecord{}, &adviceRecord{}, &assistantHostRecord{}, &handoffRecord{}, &handoffTurnRecord{}, &handoffTaskRecord{}, &handoffActionRecord{}, &connectTurnRecord{}, &carriedRecord{}, &zoneRecord{}, &placeRecord{}, &projectPlaceRecord{}}, push.Models...) |
| +var Models = append([]any{&changeDiffRecord{}, ¬ificationReceipt{}, &projectNameRecord{}, &cardVisibility{}, &cardThreadRecord{}, ©AttemptRecord{}, ©ReviewRecord{}, ©FeedbackRecord{}, &turnRecord{}, &messageRecord{}, &eventRecord{}, &commandRecord{}, &inboxRecord{}, &runnerSessionRecord{}, &projectRecord{}, &cardRecord{}, &toolCallRecord{}, &settingRecord{}, &coordinatorRecord{}, ¬ebookRecord{}, &taskRecord{}, &stepRecord{}, &entryRecord{}, &attachmentRecord{}, &starRecord{}, &questionRecord{}, &connectionRecord{}, &usageRecord{}, &distinctRecord{}, &hkRecord{}, &hkFailureRecord{}, &hkSettingsRecord{}, &fileRecord{}, &fileDataRecord{}, &transferRecord{}, &mergePolicyRecord{}, &mergeAuditRecord{}, &specialistRecord{}, &grantRecord{}, &specialistAuditRecord{}, &researchSourceRecord{}, &researchAddressRecord{}, &researchPrefixRecord{}, &researchInventoryRecord{}, &researchRecord{}, &researchFetchRecord{}, &taskFileRecord{}, &taskFileDataRecord{}, &releaseRecord{}, &adviceRecord{}, &assistantHostRecord{}, &abilitiesRecord{}, &handoffRecord{}, &handoffTurnRecord{}, &handoffTaskRecord{}, &handoffActionRecord{}, &connectTurnRecord{}, &carriedRecord{}, &zoneRecord{}, &placeRecord{}, &projectPlaceRecord{}}, push.Models...) |
| type turnRecord struct { |
| CreateRepo string |
diff --git a/internal/equipo/migrations/0115_assistant_abilities.sql b/internal/equipo/migrations/0115_assistant_abilities.sql| new file mode 100644 |
| index 00000000..b59712ef |
| --- /dev/null |
| +++ b/internal/equipo/migrations/0115_assistant_abilities.sql |
| @@ -0,0 +1,15 @@ |
| +-- The Assistant's abilities (spec 2026-11-26-assistant-abilities §5.3): |
| +-- each person's board as their Base last answered it, kept per person and |
| +-- origin. source is base (Base's board) or legacy (the defaults, renewed |
| +-- while a Base older than the board honours the host token). |
| +-- authoritative_seen: the origin has ever answered the board, never |
| +-- cleared. A job held because building was off records when |
| +-- (ability_held_at, §6.3), and a host the newest Base-Capabilities it |
| +-- sent (capabilities). |
| +CREATE TABLE chat_assistant_abilities ( |
| + person text, origin text, revision integer, abilities text, admin numeric, ask text, source text, |
| + fetch_seq integer, confirmed_at datetime, revoked_at datetime, authoritative_seen numeric, |
| + PRIMARY KEY (person, origin) |
| +); |
| +ALTER TABLE chat_handoffs ADD COLUMN ability_held_at datetime; |
| +ALTER TABLE chat_assistant_hosts ADD COLUMN capabilities text; |
diff --git a/internal/equipo/migrations/schema.sql b/internal/equipo/migrations/schema.sql| index a5e09fec..83612a9d 100644 |
| --- a/internal/equipo/migrations/schema.sql |
| +++ b/internal/equipo/migrations/schema.sql |
| @@ -671,8 +671,9 @@ CREATE INDEX chat_release_task ON chat_releases(task_id); |
| CREATE UNIQUE INDEX chat_release_step ON chat_releases(step_id, step_revision); |
| CREATE TABLE chat_advice (id text PRIMARY KEY, person text, key text, kind text, state text, subject text, facts text, text text, act text, dismiss text, card_id text, revision integer, created_at datetime, updated_at datetime, visible_at datetime, shown_at datetime, dismissed_at datetime); |
| CREATE INDEX chat_advice_person ON chat_advice(person, key); |
| -CREATE TABLE chat_assistant_hosts (person text PRIMARY KEY, origin text, token text, revision integer, updated_at datetime); |
| -CREATE TABLE chat_handoffs (id text PRIMARY KEY, person text, assistant_turn text, message_id text, context text, ledger_key text, state text, digest text, created_at datetime, updated_at datetime, lane text, title text, nudges integer NOT NULL DEFAULT 0); |
| +CREATE TABLE chat_assistant_hosts (person text PRIMARY KEY, origin text, token text, revision integer, updated_at datetime, capabilities text); |
| +CREATE TABLE chat_assistant_abilities (person text, origin text, revision integer, abilities text, admin numeric, ask text, source text, fetch_seq integer, confirmed_at datetime, revoked_at datetime, authoritative_seen numeric, PRIMARY KEY (person, origin)); |
| +CREATE TABLE chat_handoffs (id text PRIMARY KEY, person text, assistant_turn text, message_id text, context text, ledger_key text, state text, digest text, created_at datetime, updated_at datetime, lane text, title text, nudges integer NOT NULL DEFAULT 0, ability_held_at datetime); |
| CREATE UNIQUE INDEX chat_handoff_key ON chat_handoffs(ledger_key); |
| CREATE INDEX chat_handoff_person ON chat_handoffs(person); |
| CREATE INDEX chat_handoff_message ON chat_handoffs(message_id); |
diff --git a/internal/wire/abilities.go b/internal/wire/abilities.go| new file mode 100644 |
| index 00000000..1578c1ac |
| --- /dev/null |
| +++ b/internal/wire/abilities.go |
| @@ -0,0 +1,96 @@ |
| +package wire |
| + |
| +import ( |
| + "encoding/json" |
| + "slices" |
| +) |
| + |
| +// The Assistant's abilities (spec 2026-11-26-assistant-abilities §3): what |
| +// the Base owner can turn off for a member. Base's internal/equipo has the |
| +// same keys, in the same order. |
| +const ( |
| + AbilityWeb = "web" |
| + AbilityAppsRead = "apps_read" |
| + AbilityAppsWrite = "apps_write" |
| + AbilityBuild = "build" |
| + AbilityGoLive = "go_live" |
| + AbilityServices = "services" |
| + AbilityServicesAdd = "services_add" |
| +) |
| + |
| +// Abilities are the keys in the order Base lists them. |
| +var Abilities = []string{AbilityWeb, AbilityAppsRead, AbilityAppsWrite, AbilityBuild, AbilityGoLive, AbilityServices, AbilityServicesAdd} |
| + |
| +// KnownAbility reports whether key is one of Abilities. |
| +func KnownAbility(key string) bool { return slices.Contains(Abilities, key) } |
| + |
| +// The values of Base-Capabilities: what Base and every client its member |
| +// uses can draw. They only decide presentation, never what may happen. |
| +const ( |
| + CapJobActions = "job_actions" |
| + CapLookupAnswers = "lookup_answers" |
| +) |
| + |
| +// The codes a switched-off ability is refused with. |
| +const ( |
| + // CodeAbilityOff: the person's ability is off (Base's switch, the |
| + // operator's fixed key, or one it needs). |
| + CodeAbilityOff = "ability_off" |
| + // CodeAbilityUnmapped: an operation no ability covers is never run. |
| + CodeAbilityUnmapped = "ability_unmapped" |
| + // CodeOperationChanged: the operation resolved at send is not the one |
| + // the call was checked for. |
| + CodeOperationChanged = "operation_changed" |
| + // CodeHostUnverified: PUT host's token was not honoured by Base. |
| + CodeHostUnverified = "host_unverified" |
| + // CodeHostElsewhere: the person's Base is another, which still |
| + // honours them. |
| + CodeHostElsewhere = "host_elsewhere" |
| + // CodeResearchOff: Research for a job whose person can't have web |
| + // pages read. |
| + CodeResearchOff = "research_off" |
| +) |
| + |
| +// AbilityBoard is Base's answer to GET /api/v1/abilities with a member's |
| +// host token: the member's switches at a revision, whether they |
| +// administer Base, and who to ask. Keys Equipo doesn't know are dropped |
| +// as it is read. |
| +type AbilityBoard struct { |
| + Revision int64 `json:"revision"` |
| + Admin bool `json:"admin"` |
| + Ask string `json:"ask"` |
| + Abilities map[string]bool `json:"abilities"` |
| +} |
| + |
| +// UnmarshalJSON reads a board, keeping only known ability keys. |
| +func (b *AbilityBoard) UnmarshalJSON(raw []byte) error { |
| + type plain AbilityBoard |
| + var p plain |
| + if err := json.Unmarshal(raw, &p); err != nil { |
| + return err |
| + } |
| + known := map[string]bool{} |
| + for k, v := range p.Abilities { |
| + if KnownAbility(k) { |
| + known[k] = v |
| + } |
| + } |
| + p.Abilities = known |
| + *b = AbilityBoard(p) |
| + return nil |
| +} |
| + |
| +// AssistantAbilities is GET /api/v1/assistant/abilities: the caller's own |
| +// effective switches (every key), the keys the operator fixed for |
| +// everyone, and who can change them. |
| +type AssistantAbilities struct { |
| + Abilities map[string]bool `json:"abilities"` |
| + Fixed []string `json:"fixed"` |
| + Ask string `json:"ask"` |
| +} |
| + |
| +// AbilitiesRefreshed is POST /api/v1/assistant/abilities/refresh's 200: |
| +// the board's revision Equipo now holds for the person. |
| +type AbilitiesRefreshed struct { |
| + Revision int64 `json:"revision"` |
| +} |
diff --git a/internal/wire/abilities_test.go b/internal/wire/abilities_test.go| new file mode 100644 |
| index 00000000..2071e043 |
| --- /dev/null |
| +++ b/internal/wire/abilities_test.go |
| @@ -0,0 +1,40 @@ |
| +package wire |
| + |
| +import ( |
| + "encoding/json" |
| + "reflect" |
| + "testing" |
| +) |
| + |
| +// The ability keys, in the spec's order (§3); Base's internal/equipo |
| +// pins the same list. |
| +func TestAbilityKeysMatchSpec(t *testing.T) { |
| + want := []string{"web", "apps_read", "apps_write", "build", "go_live", "services", "services_add"} |
| + if !reflect.DeepEqual(Abilities, want) { |
| + t.Errorf("Abilities %v, want %v", Abilities, want) |
| + } |
| + for _, k := range want { |
| + if !KnownAbility(k) { |
| + t.Errorf("%s not known", k) |
| + } |
| + } |
| + if KnownAbility("future") || KnownAbility("") { |
| + t.Error("an unknown key is known") |
| + } |
| +} |
| + |
| +// Base's board keeps only the keys Equipo knows; a key Equipo doesn't |
| +// know is ignored, and a known key Base left out reads as missing. |
| +func TestAbilityBoardIgnoresUnknownKeys(t *testing.T) { |
| + var b AbilityBoard |
| + if err := json.Unmarshal([]byte(`{"revision":7,"admin":true,"ask":"Paul","abilities":{"web":true,"future":false,"build":false}}`), &b); err != nil { |
| + t.Fatal(err) |
| + } |
| + want := AbilityBoard{Revision: 7, Admin: true, Ask: "Paul", Abilities: map[string]bool{"web": true, "build": false}} |
| + if !reflect.DeepEqual(b, want) { |
| + t.Errorf("board %+v, want %+v", b, want) |
| + } |
| + if _, ok := b.Abilities["future"]; ok { |
| + t.Error("an unknown key was kept") |
| + } |
| +} |