Abilities: look and use follow the switches; one map of keys
abilityFor maps every operation to the ability it needs (web_lookup to web, Oficina reads and writes to apps_read and apps_write, team writes to build, team_status and team_cancel and Base's reads to none, svc: providers to services); anything else is refused ability_unmapped. The registry takes a filter: look and describe leave out what is off, and a provider whose whole ability is off is never asked to list. use refuses an operation that is off with the instance's text naming it and who can turn it on, audited ability_off; Decide's refusals keep their codes. A person turn's note starts with what is off, by whom. Equipo copy gains Paul's approved plain names and abilities lines (copy review mi3kgi7nubnsf7kxn235tqwrbu), with Plan 3 inventory rows. Tests whose people use the Assistant through Base now register a host, and the in-test ledger provider is a service (svc:ledger).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
17 files changed,
+517
−8
docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md+12 −0internal/equipo/assist/filter.go+24 −0internal/equipo/assist/filter_test.go+48 −0internal/equipo/assist/registry.go+20 −2internal/equipo/chat/abilities_harness_test.go+18 −1internal/equipo/chat/abilities_note.go+38 −0internal/equipo/chat/abilities_use_test.go+192 −0internal/equipo/chat/ability_map.go+112 −0internal/equipo/chat/assistant_tools.go+17 −3internal/equipo/chat/assistant_tools_test.go+1 −1internal/equipo/chat/store.go+9 −0internal/equipo/copy.go+17 −0internal/thintest/assistant_oficina_contract_test.go+1 −0internal/thintest/assistant_ops_contract_test.go+1 −1internal/thintest/assistant_outcome_contract_test.go+2 −0internal/thintest/assistant_reply_contract_test.go+1 −0internal/thintest/assistant_team_contract_test.go+4 −0
diff --git a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md| index 05cf4945..ee361291 100644 |
| --- a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md |
| +++ b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md |
| @@ -4757,6 +4757,18 @@ All eight entries have individual `COPY REVIEW REQUIRED` markers. The API guide |
| | `access.failed` | The access request could not be completed. Ask again to make a new request. | Access request | COPY ACCEPTED BY DELEGATION (Astra, 2026-11-17) | |
| | `access.operator` | Only the agent’s operator can approve this on Amadan. | Access request | COPY ACCEPTED BY DELEGATION (Astra, 2026-11-17) | |
| | `access.continue` | Access to %s was approved. Continue the original request: %s. | Access request | COPY ACCEPTED BY DELEGATION (Astra, 2026-11-17) | |
| +| `assistant.ability.web.name` | Look things up on the web | Assistant abilities: an ability's plain name in the Assistant's refusals and notes | COPY APPROVED (Paul, 2026-11-28, copy-review mi3kgi7nubnsf7kxn235tqwrbu, unchanged) | |
| +| `assistant.ability.apps_read.name` | Read their Oficina apps | Assistant abilities | COPY APPROVED (Paul, 2026-11-28, copy-review mi3kgi7nubnsf7kxn235tqwrbu, unchanged) | |
| +| `assistant.ability.apps_write.name` | Create and edit in Oficina apps | Assistant abilities | COPY APPROVED (Paul, 2026-11-28, copy-review mi3kgi7nubnsf7kxn235tqwrbu, unchanged) | |
| +| `assistant.ability.build.name` | Build sites and apps | Assistant abilities | COPY APPROVED (Paul, 2026-11-28, copy-review mi3kgi7nubnsf7kxn235tqwrbu, unchanged) | |
| +| `assistant.ability.go_live.name` | Put things live | Assistant abilities | COPY APPROVED (Paul, 2026-11-28, copy-review mi3kgi7nubnsf7kxn235tqwrbu, unchanged) | |
| +| `assistant.ability.services.name` | Connect outside services | Assistant abilities | COPY APPROVED (Paul, 2026-11-28, copy-review mi3kgi7nubnsf7kxn235tqwrbu, unchanged) | |
| +| `assistant.ability.services_add.name` | Add services for everyone | Assistant abilities | COPY APPROVED (Paul, 2026-11-28, copy-review mi3kgi7nubnsf7kxn235tqwrbu, unchanged) | |
| +| `assistant.job.detail.ability_off` | Building is turned off for you. %s can turn it back on, or you can drop this. | Assistant abilities: a job held while building is off ({Owner} as %s) | COPY APPROVED (Paul, 2026-11-28, copy-review mi3kgi7nubnsf7kxn235tqwrbu, unchanged) | |
| +| `assistant.job.detail.ability_back` | Building is on again. You can carry on with this, or drop it. | Assistant abilities: a held job once building is on again | COPY APPROVED (Paul, 2026-11-28, copy-review mi3kgi7nubnsf7kxn235tqwrbu, unchanged) | |
| +| `assistant.job.detail.go_live_off` | Putting it live is turned off for you. %s can turn it on. | Assistant abilities: a ready job while putting live is off | COPY APPROVED (Paul, 2026-11-28, copy-review mi3kgi7nubnsf7kxn235tqwrbu, unchanged) | |
| +| `chat.card.ability_off` | Building is turned off for you, so this can't start. You can still drop it. | Assistant abilities: a job card answered in Equipo while building is off | COPY APPROVED (Paul, 2026-11-28, copy-review mi3kgi7nubnsf7kxn235tqwrbu, unchanged) | |
| +| `oficina.connect.ability_off` | Reading your Oficina apps is turned off for you. %s can turn it on. | Assistant abilities: connecting Oficina refused | COPY APPROVED (Paul, 2026-11-28, copy-review mi3kgi7nubnsf7kxn235tqwrbu, unchanged) | |
| Oficina ID consumer: COPY ACCEPTED BY DELEGATION (Astra, 2026-11-13). |
diff --git a/internal/equipo/assist/filter.go b/internal/equipo/assist/filter.go| new file mode 100644 |
| index 00000000..7be32d4d |
| --- /dev/null |
| +++ b/internal/equipo/assist/filter.go |
| @@ -0,0 +1,24 @@ |
| +package assist |
| + |
| +import "context" |
| + |
| +// Filter decides what a person may be offered and run (spec |
| +// 2026-11-26-assistant-abilities §6.1): a provider whose whole ability is |
| +// off is never asked to list (Provider false), and an operation the |
| +// person can't use isn't offered, described or run (Operation false). |
| +type Filter interface { |
| + Provider(name string) bool |
| + Operation(op Operation) bool |
| +} |
| + |
| +type filterKey struct{} |
| + |
| +// WithFilter is ctx with f applied to look, describe and invoke. |
| +func WithFilter(ctx context.Context, f Filter) context.Context { |
| + return context.WithValue(ctx, filterKey{}, f) |
| +} |
| + |
| +func filterFrom(ctx context.Context) Filter { |
| + f, _ := ctx.Value(filterKey{}).(Filter) |
| + return f |
| +} |
diff --git a/internal/equipo/assist/filter_test.go b/internal/equipo/assist/filter_test.go| new file mode 100644 |
| index 00000000..8f3a715f |
| --- /dev/null |
| +++ b/internal/equipo/assist/filter_test.go |
| @@ -0,0 +1,48 @@ |
| +package assist |
| + |
| +import ( |
| + "context" |
| + "strings" |
| + "testing" |
| +) |
| + |
| +// offFilter keeps everything but the providers and operations named. |
| +type offFilter struct{ providers, ops map[string]bool } |
| + |
| +func (f offFilter) Provider(name string) bool { return !f.providers[name] } |
| +func (f offFilter) Operation(op Operation) bool { return !f.ops[op.Name] } |
| + |
| +// look leaves out what the person can't use, so the model isn't offered |
| +// it, and describe doesn't find it either. |
| +func TestLookHidesOffOperations(t *testing.T) { |
| + a := &fake{name: "oficina", ops: map[string][]Operation{"p": {{Name: "calendar_list", ReadOnly: true}, {Name: "calendar_add"}}}} |
| + r := NewRegistry(a) |
| + ctx := WithFilter(context.Background(), offFilter{ops: map[string]bool{"calendar_add": true}}) |
| + out, _ := r.Look(ctx, "p", "") |
| + if !strings.Contains(out, "calendar_list") || strings.Contains(out, "calendar_add") { |
| + t.Errorf("look:\n%s", out) |
| + } |
| + if _, err := r.Describe(ctx, "p", "calendar_add"); err == nil { |
| + t.Error("describe found an operation the person can't use") |
| + } |
| + // Without a filter, as before. |
| + if out, _ := r.Look(context.Background(), "p", ""); !strings.Contains(out, "calendar_add") { |
| + t.Errorf("unfiltered look:\n%s", out) |
| + } |
| +} |
| + |
| +// A provider whose whole ability is off is never asked to list: a paused |
| +// connection isn't used, even to list. |
| +func TestListSkipsOffProvider(t *testing.T) { |
| + a := &fake{name: "oficina", ops: map[string][]Operation{"p": {{Name: "calendar_list", ReadOnly: true}}}} |
| + b := &fake{name: "base", ops: map[string][]Operation{"p": {{Name: "base_apps", ReadOnly: true}}}} |
| + r := NewRegistry(a, b) |
| + ctx := WithFilter(context.Background(), offFilter{providers: map[string]bool{"oficina": true}}) |
| + out, _ := r.Look(ctx, "p", "") |
| + if a.lists.Load() != 0 || strings.Contains(out, "calendar_list") || !strings.Contains(out, "base_apps") { |
| + t.Errorf("lists %d, look:\n%s", a.lists.Load(), out) |
| + } |
| + if _, err := r.Invoke(ctx, "p", "calendar_list", nil, ""); err == nil || a.lists.Load() != 0 { |
| + t.Errorf("invoke reached a provider that is off: %v", err) |
| + } |
| +} |
diff --git a/internal/equipo/assist/registry.go b/internal/equipo/assist/registry.go| index aa17857b..44840b58 100644 |
| --- a/internal/equipo/assist/registry.go |
| +++ b/internal/equipo/assist/registry.go |
| @@ -77,13 +77,17 @@ func (r *Registry) list(ctx context.Context, person string) [][]Operation { |
| // listing is list with each provider's failure, by index. |
| func (r *Registry) listing(ctx context.Context, person string) ([][]Operation, []error) { |
| out, errs := make([][]Operation, len(r.providers)), make([]error, len(r.providers)) |
| + filter := filterFrom(ctx) |
| for i, p := range r.providers { |
| + if filter != nil && !filter.Provider(p.Name()) { |
| + continue |
| + } |
| r.mu.Lock() |
| l, ok := r.cache[person][i] |
| gen := r.gen[person] |
| r.mu.Unlock() |
| if ok && r.now().Sub(l.at) < listTTL { |
| - out[i] = l.ops |
| + out[i] = filtered(filter, l.ops) |
| continue |
| } |
| ops, err := p.List(ctx, person) |
| @@ -104,11 +108,25 @@ func (r *Registry) listing(ctx context.Context, person string) ([][]Operation, [ |
| r.cache[person][i] = listing{ops: ops, at: r.now()} |
| } |
| r.mu.Unlock() |
| - out[i] = ops |
| + out[i] = filtered(filter, ops) |
| } |
| return out, errs |
| } |
| +// filtered is ops less those filter leaves out (all of them, with none). |
| +func filtered(filter Filter, ops []Operation) []Operation { |
| + if filter == nil { |
| + return ops |
| + } |
| + var out []Operation |
| + for _, op := range ops { |
| + if filter.Operation(op) { |
| + out = append(out, op) |
| + } |
| + } |
| + return out |
| +} |
| + |
| // Look returns model-facing text: one header per app and one line per |
| // operation, filtered by query when there is one. A provider the person |
| // has not connected that has a hint for query (Hinter) shows it under |
diff --git a/internal/equipo/chat/abilities_harness_test.go b/internal/equipo/chat/abilities_harness_test.go| index 09614852..8979cf6e 100644 |
| --- a/internal/equipo/chat/abilities_harness_test.go |
| +++ b/internal/equipo/chat/abilities_harness_test.go |
| @@ -153,7 +153,12 @@ func newAbilitiesHarness(t *testing.T, hosts ...string) *abilitiesHarness { |
| h.mu.Unlock() |
| return nil |
| }, |
| - Copy: func(key string) string { return key }, |
| + Copy: func(key string) string { |
| + if name, ok := abilityNames[key]; ok { |
| + return name |
| + } |
| + return key |
| + }, |
| Me: func(_ *gorm.DB, address string) (wire.Me, error) { |
| role := "member" |
| if address == "owner@example.com" { |
| @@ -254,3 +259,15 @@ func refusalCode(err error) string { |
| } |
| return "" |
| } |
| + |
| +// abilityNames are Equipo's copy for the abilities' plain names (Paul's |
| +// approved review of 2026-11-28, Base's abilities.<key>.name). |
| +var abilityNames = map[string]string{ |
| + "assistant.ability.web.name": "Look things up on the web", |
| + "assistant.ability.apps_read.name": "Read their Oficina apps", |
| + "assistant.ability.apps_write.name": "Create and edit in Oficina apps", |
| + "assistant.ability.build.name": "Build sites and apps", |
| + "assistant.ability.go_live.name": "Put things live", |
| + "assistant.ability.services.name": "Connect outside services", |
| + "assistant.ability.services_add.name": "Add services for everyone", |
| +} |
diff --git a/internal/equipo/chat/abilities_note.go b/internal/equipo/chat/abilities_note.go| new file mode 100644 |
| index 00000000..6a7e8c79 |
| --- /dev/null |
| +++ b/internal/equipo/chat/abilities_note.go |
| @@ -0,0 +1,38 @@ |
| +package chat |
| + |
| +import ( |
| + "fmt" |
| + "strings" |
| +) |
| + |
| +// The turn's note on what is on (spec 2026-11-26-assistant-abilities |
| +// §6.1): instance-written and model-facing, reviewed as code, not copy. |
| +const ( |
| + noteWebListed = "You can look things up on the public web with web_lookup. Do it for questions about the world instead of saying you can't." |
| + noteOffFormat = "Off for this person, set by %s: %s. If they ask for one of these, say in one line that you can't here and that %s can turn it on." |
| +) |
| + |
| +// abilitiesNote is the lines a person turn's note starts with: web_lookup |
| +// when it is listed for them, and what is off, by whom; "" with neither. |
| +func (t *txn) abilitiesNote(person string, listed bool) (string, error) { |
| + sw, err := t.switches(person) |
| + if err != nil { |
| + return "", err |
| + } |
| + var lines []string |
| + if listed && sw.Can("web") { |
| + lines = append(lines, noteWebListed) |
| + } |
| + if off := sw.Off(); len(off) > 0 { |
| + names := make([]string, len(off)) |
| + for i, k := range off { |
| + names[i] = t.s.abilityName(k) |
| + } |
| + ask := sw.Ask() |
| + if ask == "" { |
| + ask = "the person who runs their Base" |
| + } |
| + lines = append(lines, fmt.Sprintf(noteOffFormat, ask, strings.Join(names, ", "), ask)) |
| + } |
| + return strings.Join(lines, "\n"), nil |
| +} |
diff --git a/internal/equipo/chat/abilities_use_test.go b/internal/equipo/chat/abilities_use_test.go| new file mode 100644 |
| index 00000000..d0bc6de5 |
| --- /dev/null |
| +++ b/internal/equipo/chat/abilities_use_test.go |
| @@ -0,0 +1,192 @@ |
| +package chat |
| + |
| +import ( |
| + "context" |
| + "encoding/json" |
| + "strings" |
| + "sync/atomic" |
| + "testing" |
| + |
| + "amadan.net/oficina/equipo/internal/equipo/assist" |
| + "amadan.net/oficina/equipo/internal/wire" |
| +) |
| + |
| +// opsProvider is an in-test provider: its operations, and how often it |
| +// was asked to list and to run one. |
| +type opsProvider struct { |
| + name string |
| + ops []assist.Operation |
| + lists, invokes atomic.Int32 |
| +} |
| + |
| +func (p *opsProvider) Name() string { return p.name } |
| +func (p *opsProvider) List(context.Context, string) ([]assist.Operation, error) { |
| + p.lists.Add(1) |
| + return p.ops, nil |
| +} |
| +func (p *opsProvider) Invoke(context.Context, string, string, json.RawMessage, string) (json.RawMessage, error) { |
| + p.invokes.Add(1) |
| + return json.RawMessage(`{"ok":true}`), nil |
| +} |
| + |
| +// useRig is a person with a board from their Base and a registry of |
| +// in-test providers, one per row of abilityFor's table. |
| +func useRig(t *testing.T, off ...string) (*abilitiesHarness, map[string]*opsProvider) { |
| + t.Helper() |
| + h, base := boardBase(t) |
| + base.set(func(f *fakeBoardBase) { |
| + for _, k := range off { |
| + f.board.Abilities[k] = false |
| + } |
| + }) |
| + refresh(t, h) |
| + ps := map[string]*opsProvider{ |
| + "base": {name: "base", ops: []assist.Operation{{Name: "base_apps", ReadOnly: true}}}, |
| + "oficina": {name: "oficina", ops: []assist.Operation{{Name: "calendar_list", ReadOnly: true}, {Name: "calendar_add", Idempotent: true, KeyField: "client_id"}}}, |
| + "web": {name: "web", ops: []assist.Operation{{Name: "web_lookup", ReadOnly: true}}}, |
| + "svc": {name: "svc:ledger", ops: []assist.Operation{{Name: "ledger_read", ReadOnly: true}}}, |
| + "mystery": {name: "mystery", ops: []assist.Operation{{Name: "mystery_read", ReadOnly: true}}}, |
| + } |
| + var list []assist.Provider |
| + for _, k := range []string{"base", "oficina", "web", "svc", "mystery"} { |
| + list = append(list, ps[k]) |
| + } |
| + h.s.SetOperations(assist.NewRegistry(list...)) |
| + return h, ps |
| +} |
| + |
| +func useRow(person, op string) toolCallRecord { |
| + args, _ := json.Marshal(map[string]any{"operation": op, "input": map[string]any{}}) |
| + return toolCallRecord{CallID: "call-" + op, Person: person, Name: wire.ToolUse, Operation: op, Args: string(args), TurnID: "t1", Attempt: 1} |
| +} |
| + |
| +func lookRow(person, query string) toolCallRecord { |
| + args, _ := json.Marshal(map[string]any{"query": query}) |
| + return toolCallRecord{CallID: "look", Person: person, Name: wire.ToolLook, Args: string(args), TurnID: "t1", Attempt: 1} |
| +} |
| + |
| +// look leaves out what the person's switches turn off. |
| +func TestLookHidesOffOperationsForPerson(t *testing.T) { |
| + h, ps := useRig(t, wire.AbilityAppsWrite, wire.AbilityWeb) |
| + res, _ := h.s.runRemote(context.Background(), lookRow(abPerson, "")) |
| + for _, want := range []string{"calendar_list", "base_apps", "ledger_read"} { |
| + if !strings.Contains(res.Text, want) { |
| + t.Errorf("look lacks %s:\n%s", want, res.Text) |
| + } |
| + } |
| + for _, gone := range []string{"calendar_add", "web_lookup", "mystery_read"} { |
| + if strings.Contains(res.Text, gone) { |
| + t.Errorf("look offers %s:\n%s", gone, res.Text) |
| + } |
| + } |
| + if ps["web"].lists.Load() != 0 { |
| + t.Error("a provider whose ability is off was asked to list") |
| + } |
| +} |
| + |
| +// use refuses every operation whose ability is off, with the plain name |
| +// and who to ask, and runs nothing; with it on, it runs. |
| +func TestUseRefusesAbilityOff(t *testing.T) { |
| + for _, c := range []struct { |
| + op, provider, key string |
| + }{ |
| + {"calendar_list", "oficina", wire.AbilityAppsRead}, |
| + {"calendar_add", "oficina", wire.AbilityAppsWrite}, |
| + {"web_lookup", "web", wire.AbilityWeb}, |
| + {"ledger_read", "svc", wire.AbilityServices}, |
| + } { |
| + h, ps := useRig(t, c.key) |
| + res, _ := h.s.runRemote(context.Background(), useRow(abPerson, c.op)) |
| + if !res.IsError || res.Code != wire.CodeAbilityOff || ps[c.provider].invokes.Load() != 0 { |
| + t.Errorf("%s with %s off: %+v, invoked %d", c.op, c.key, res, ps[c.provider].invokes.Load()) |
| + } |
| + if !strings.Contains(res.Text, abilityNames["assistant.ability."+c.key+".name"]) || !strings.Contains(res.Text, "Paul") { |
| + t.Errorf("%s refusal text: %q", c.op, res.Text) |
| + } |
| + h2, ps2 := useRig(t) |
| + if res, _ := h2.s.runRemote(context.Background(), useRow(abPerson, c.op)); c.op != "calendar_add" && (res.IsError || ps2[c.provider].invokes.Load() != 1) { |
| + t.Errorf("%s with everything on: %+v", c.op, res) |
| + } |
| + } |
| + // Base's reads are always on. |
| + h, ps := useRig(t, wire.Abilities...) |
| + if res, _ := h.s.runRemote(context.Background(), useRow(abPerson, "base_apps")); res.IsError || ps["base"].invokes.Load() != 1 { |
| + t.Errorf("base_apps with everything off: %+v", res) |
| + } |
| +} |
| + |
| +// An operation no ability covers is never run. |
| +func TestUnmappedOperationRefused(t *testing.T) { |
| + h, ps := useRig(t) |
| + res, _ := h.s.runRemote(context.Background(), useRow(abPerson, "mystery_read")) |
| + if !res.IsError || res.Code != wire.CodeAbilityUnmapped || ps["mystery"].invokes.Load() != 0 { |
| + t.Errorf("unmapped: %+v", res) |
| + } |
| + for _, c := range []struct { |
| + op assist.Operation |
| + key string |
| + okay bool |
| + }{ |
| + {assist.Operation{Provider: "team", Name: "team_request"}, wire.AbilityBuild, true}, |
| + {assist.Operation{Provider: "team", Name: "team_add"}, wire.AbilityBuild, true}, |
| + {assist.Operation{Provider: "team", Name: "team_reply"}, wire.AbilityBuild, true}, |
| + {assist.Operation{Provider: "team", Name: "team_ask"}, wire.AbilityBuild, true}, |
| + {assist.Operation{Provider: "team", Name: "team_nudge"}, wire.AbilityBuild, true}, |
| + {assist.Operation{Provider: "team", Name: "team_status", ReadOnly: true}, "", true}, |
| + {assist.Operation{Provider: "team", Name: "team_cancel"}, "", true}, |
| + {assist.Operation{Provider: "team", Name: "connect_service"}, wire.AbilityServices, true}, |
| + {assist.Operation{Provider: "team", Name: "team_unknown"}, "", false}, |
| + {assist.Operation{Provider: "base", Name: "base_write"}, "", false}, |
| + {assist.Operation{Provider: "svc:x", Name: "anything"}, wire.AbilityServices, true}, |
| + {assist.Operation{Provider: "web", Name: "web_other"}, "", false}, |
| + } { |
| + key, ok := abilityFor(c.op) |
| + if key != c.key || ok != c.okay { |
| + t.Errorf("%s/%s: %q %v, want %q %v", c.op.Provider, c.op.Name, key, ok, c.key, c.okay) |
| + } |
| + } |
| +} |
| + |
| +// The turn's note says what is on and off, and follows the switches. |
| +func TestTurnNoteFollowsSwitches(t *testing.T) { |
| + h, base := boardBase(t) |
| + refresh(t, h) |
| + note := func(listed bool) string { |
| + var out string |
| + if err := h.s.tx(context.Background(), func(tx *txn) error { |
| + var err error |
| + out, err = tx.abilitiesNote(abPerson, listed) |
| + return err |
| + }); err != nil { |
| + t.Fatal(err) |
| + } |
| + return out |
| + } |
| + if got := note(false); got != "" { |
| + t.Errorf("everything on, nothing listed: %q", got) |
| + } |
| + if got := note(true); !strings.Contains(got, "web_lookup") || strings.Contains(got, "Off for this person") { |
| + t.Errorf("listed: %q", got) |
| + } |
| + base.set(func(f *fakeBoardBase) { |
| + f.board.Abilities["build"], f.board.Abilities["go_live"], f.board.Revision = false, false, 2 |
| + }) |
| + refresh(t, h) |
| + want := "Off for this person, set by Paul: Build sites and apps, Put things live. If they ask for one of these, say in one line that you can't here and that Paul can turn it on." |
| + if got := note(false); got != want { |
| + t.Errorf("note %q\nwant %q", got, want) |
| + } |
| +} |
| + |
| +// assistant.use records the refusal's code. |
| +func TestUseAuditsCode(t *testing.T) { |
| + h, _ := useRig(t, wire.AbilityAppsRead) |
| + row := useRow(abPerson, "calendar_list") |
| + res, _ := h.s.runRemote(context.Background(), row) |
| + if err := h.s.tx(context.Background(), func(tx *txn) error { return tx.auditUse(row, res) }); err != nil { |
| + t.Fatal(err) |
| + } |
| + if got := h.audited(auditAssistantUse); len(got) != 1 || !strings.HasSuffix(got[0], "calendar_list ability_off") { |
| + t.Errorf("audits %v", got) |
| + } |
| +} |
diff --git a/internal/equipo/chat/ability_map.go b/internal/equipo/chat/ability_map.go| new file mode 100644 |
| index 00000000..61453586 |
| --- /dev/null |
| +++ b/internal/equipo/chat/ability_map.go |
| @@ -0,0 +1,112 @@ |
| +package chat |
| + |
| +import ( |
| + "context" |
| + "strings" |
| + |
| + "amadan.net/oficina/equipo/internal/equipo/assist" |
| + "amadan.net/oficina/equipo/internal/wire" |
| + "gorm.io/gorm" |
| +) |
| + |
| +// abilityFor is the one map of what every operation Equipo can run needs |
| +// (spec 2026-11-26-assistant-abilities §6.1): key "" is always on, and ok |
| +// false is an operation no ability covers, which is never run. A new |
| +// provider or operation is mapped here or refused. |
| +func abilityFor(op assist.Operation) (key string, ok bool) { |
| + switch { |
| + case op.Provider == "web": |
| + if op.Name == "web_lookup" { |
| + return wire.AbilityWeb, true |
| + } |
| + case op.Provider == OficinaProvider: |
| + if op.ReadOnly { |
| + return wire.AbilityAppsRead, true |
| + } |
| + return wire.AbilityAppsWrite, true |
| + case op.Provider == "base": |
| + return "", op.ReadOnly && strings.HasPrefix(op.Name, "base_") |
| + case op.Provider == teamProvider{}.Name(): |
| + switch op.Name { |
| + case opTeamRequest, "team_add", opTeamReply, "team_ask", opTeamNudge: |
| + return wire.AbilityBuild, true |
| + case opTeamStatus, opTeamCancel: |
| + return "", true |
| + case "connect_service": |
| + return wire.AbilityServices, true |
| + } |
| + case strings.HasPrefix(op.Provider, "svc:"): |
| + return wire.AbilityServices, true |
| + } |
| + return "", false |
| +} |
| + |
| +// providerAbility is the ability a whole provider needs, "" when its |
| +// operations need different ones (or none). |
| +func providerAbility(name string) string { |
| + switch { |
| + case name == "web": |
| + return wire.AbilityWeb |
| + case name == OficinaProvider: |
| + // apps_write needs apps_read: off, the whole provider is. |
| + return wire.AbilityAppsRead |
| + case strings.HasPrefix(name, "svc:"): |
| + return wire.AbilityServices |
| + } |
| + return "" |
| +} |
| + |
| +// abilityFilter is a person's switches as the registry's filter: what |
| +// look offers and describe finds. |
| +type abilityFilter struct{ sw Switches } |
| + |
| +func (f abilityFilter) Provider(name string) bool { |
| + key := providerAbility(name) |
| + return key == "" || f.sw.Can(key) |
| +} |
| + |
| +func (f abilityFilter) Operation(op assist.Operation) bool { |
| + key, ok := abilityFor(op) |
| + return ok && (key == "" || f.sw.Can(key)) |
| +} |
| + |
| +// switchesNow reads the person's switches in a short transaction of its |
| +// own. |
| +func (s *Store) switchesNow(ctx context.Context, person string) (sw Switches, err error) { |
| + err = s.read(ctx, func(tx *gorm.DB) error { |
| + sw, err = (&txn{s: s, ctx: ctx, db: tx}).switches(person) |
| + return err |
| + }) |
| + return sw, err |
| +} |
| + |
| +// abilityOffText is the instance's model-facing refusal for an ability |
| +// that is off (§6.1), filled with its plain name and who to ask. |
| +func abilityOffText(name, ask string) string { |
| + if ask == "" { |
| + ask = "the person who runs their Base" |
| + } |
| + return "Not available: " + name + " is turned off for this person by " + ask + ". Tell them in one short line that you can't do that here and that " + ask + " can turn it on. Don't suggest a way round it." |
| +} |
| + |
| +// toolAbilityUnmapped is the refusal for an operation no ability covers. |
| +const toolAbilityUnmapped = "Not available: this can't be run from here." |
| + |
| +// abilityName is an ability's plain name (Equipo's copy, the same words |
| +// Base shows). |
| +func (s *Store) abilityName(key string) string { |
| + if s.authority.Copy != nil { |
| + if name := s.authority.Copy("assistant.ability." + key + ".name"); name != "" { |
| + return name |
| + } |
| + } |
| + return key |
| +} |
| + |
| +// abilityRefusal is the tool result refusing op under key for sw. |
| +func (s *Store) abilityRefusal(sw Switches, key string) wire.ToolResult { |
| + if code := sw.Refusal(key); code != wire.CodeAbilityOff { |
| + return refused(code, toolOpUnavailable) |
| + } |
| + return refused(wire.CodeAbilityOff, abilityOffText(s.abilityName(key), sw.Ask())) |
| +} |
diff --git a/internal/equipo/chat/assistant_tools.go b/internal/equipo/chat/assistant_tools.go| index 22b5902c..3438adb4 100644 |
| --- a/internal/equipo/chat/assistant_tools.go |
| +++ b/internal/equipo/chat/assistant_tools.go |
| @@ -657,15 +657,23 @@ func (s *Store) runRemote(ctx context.Context, row toolCallRecord) (res wire.Too |
| if ops == nil || !ok { |
| return refused("unavailable", toolOpUnavailable), false |
| } |
| + // What the person may be offered and run (spec |
| + // 2026-11-26-assistant-abilities §6.1): read once, here; the send |
| + // gate reads it again right before the request. |
| + sw, err := s.switchesNow(ctx, row.Person) |
| + if err != nil { |
| + return refused("unavailable", toolOpUnavailable), false |
| + } |
| + filtered := assist.WithFilter(ctx, abilityFilter{sw}) |
| switch row.Name { |
| case wire.ToolLook: |
| - text, err := ops.Look(withCall(ctx, row), row.Person, in.Query) |
| + text, err := ops.Look(withCall(filtered, row), row.Person, in.Query) |
| if err != nil { |
| return s.opFailed(ctx, row.Person, err), false |
| } |
| return wire.ToolResult{Code: "listed", Text: fitLook(text)}, false |
| case wire.ToolDescribe: |
| - op, err := ops.Describe(ctx, row.Person, in.Operation) |
| + op, err := ops.Describe(filtered, row.Person, in.Operation) |
| if err != nil { |
| return s.opFailed(ctx, row.Person, err), false |
| } |
| @@ -682,6 +690,12 @@ func (s *Store) runRemote(ctx context.Context, row toolCallRecord) (res wire.Too |
| if run, code := assist.Decide(op); !run { |
| return opRefused(code, ""), false |
| } |
| + switch key, ok := abilityFor(op); { |
| + case !ok: |
| + return refused(wire.CodeAbilityUnmapped, toolAbilityUnmapped), false |
| + case key != "" && !sw.Can(key): |
| + return s.abilityRefusal(sw, key), false |
| + } |
| // A turn the person did not start (a team_update) only looks, but for |
| // answering or nudging the job it tells (updateWrites). |
| if !op.ReadOnly { |
| @@ -693,7 +707,7 @@ func (s *Store) runRemote(ctx context.Context, row toolCallRecord) (res wire.Too |
| return opRefused("not_asked", ""), false |
| } |
| } |
| - out, err := ops.Invoke(withCall(ctx, row), row.Person, in.Operation, in.Input, row.LedgerKey) |
| + out, err := ops.Invoke(withCall(filtered, row), row.Person, in.Operation, in.Input, row.LedgerKey) |
| if err != nil { |
| return s.opFailed(ctx, row.Person, err), op.ReadOnly |
| } |
diff --git a/internal/equipo/chat/assistant_tools_test.go b/internal/equipo/chat/assistant_tools_test.go| index c6ffcfdc..53ff77eb 100644 |
| --- a/internal/equipo/chat/assistant_tools_test.go |
| +++ b/internal/equipo/chat/assistant_tools_test.go |
| @@ -26,7 +26,7 @@ type countingOps struct{ invokes atomic.Int32 } |
| func (o *countingOps) Look(context.Context, string, string) (string, error) { return "", nil } |
| func (o *countingOps) Describe(_ context.Context, _, op string) (assist.Operation, error) { |
| - return assist.Operation{Name: op, ReadOnly: true}, nil |
| + return assist.Operation{Name: op, ReadOnly: true, Provider: "base"}, nil |
| } |
| func (o *countingOps) Invoke(context.Context, string, string, json.RawMessage, string) (json.RawMessage, error) { |
| o.invokes.Add(1) |
diff --git a/internal/equipo/chat/store.go b/internal/equipo/chat/store.go| index 33ed71cf..24a86650 100644 |
| --- a/internal/equipo/chat/store.go |
| +++ b/internal/equipo/chat/store.go |
| @@ -438,6 +438,15 @@ func (t *txn) dispatch(r *turnRecord) error { |
| text = r.Note |
| } |
| if r.Lane == wire.LaneAssistant && r.Kind == wire.TurnPerson { |
| + // What the person's Assistant may do starts the reference |
| + // (abilities §6.1); web_lookup isn't listed yet. |
| + note, err := t.abilitiesNote(r.Person, false) |
| + if err != nil { |
| + return err |
| + } |
| + if note != "" { |
| + text += "\n\n" + note |
| + } |
| // The questions open on the person's jobs ride after their words, |
| // as reference (D8); PersonText and the stored messages stay theirs. |
| block, asked, err := t.openQuestionsNote(r.Person) |
diff --git a/internal/equipo/copy.go b/internal/equipo/copy.go| index 8f658ea9..c9f242e6 100644 |
| --- a/internal/equipo/copy.go |
| +++ b/internal/equipo/copy.go |
| @@ -2500,6 +2500,23 @@ var pageCopy = map[string]string{ |
| // stopped job card's sentence more. |
| "assistant.team.no_access": "The change is ready, but it can't go live until access to publish it is set up.", // COPY APPROVED (Paul, 2026-11-26, coordinator session, unchanged) |
| "assistant.job.detail.no_access": "It can't go live until access to publish it is set up.", // COPY APPROVED (Paul, 2026-11-26, coordinator session, unchanged) |
| + |
| + // The Assistant's abilities (spec 2026-11-26-assistant-abilities): |
| + // each ability's plain name, the same words Base shows (abilities.<key> |
| + // .name), and the lines a job, a card or a connect page says when one is |
| + // off. %s is who can turn it on (Base's owner's name). |
| + "assistant.ability.web.name": "Look things up on the web", // COPY APPROVED (Paul, 2026-11-28, copy-review mi3kgi7nubnsf7kxn235tqwrbu, unchanged) |
| + "assistant.ability.apps_read.name": "Read their Oficina apps", // COPY APPROVED (Paul, 2026-11-28, copy-review mi3kgi7nubnsf7kxn235tqwrbu, unchanged) |
| + "assistant.ability.apps_write.name": "Create and edit in Oficina apps", // COPY APPROVED (Paul, 2026-11-28, copy-review mi3kgi7nubnsf7kxn235tqwrbu, unchanged) |
| + "assistant.ability.build.name": "Build sites and apps", // COPY APPROVED (Paul, 2026-11-28, copy-review mi3kgi7nubnsf7kxn235tqwrbu, unchanged) |
| + "assistant.ability.go_live.name": "Put things live", // COPY APPROVED (Paul, 2026-11-28, copy-review mi3kgi7nubnsf7kxn235tqwrbu, unchanged) |
| + "assistant.ability.services.name": "Connect outside services", // COPY APPROVED (Paul, 2026-11-28, copy-review mi3kgi7nubnsf7kxn235tqwrbu, unchanged) |
| + "assistant.ability.services_add.name": "Add services for everyone", // COPY APPROVED (Paul, 2026-11-28, copy-review mi3kgi7nubnsf7kxn235tqwrbu, unchanged) |
| + "assistant.job.detail.ability_off": "Building is turned off for you. %s can turn it back on, or you can drop this.", // COPY APPROVED (Paul, 2026-11-28, copy-review mi3kgi7nubnsf7kxn235tqwrbu, unchanged) |
| + "assistant.job.detail.ability_back": "Building is on again. You can carry on with this, or drop it.", // COPY APPROVED (Paul, 2026-11-28, copy-review mi3kgi7nubnsf7kxn235tqwrbu, unchanged) |
| + "assistant.job.detail.go_live_off": "Putting it live is turned off for you. %s can turn it on.", // COPY APPROVED (Paul, 2026-11-28, copy-review mi3kgi7nubnsf7kxn235tqwrbu, unchanged) |
| + "chat.card.ability_off": "Building is turned off for you, so this can't start. You can still drop it.", // COPY APPROVED (Paul, 2026-11-28, copy-review mi3kgi7nubnsf7kxn235tqwrbu, unchanged) |
| + "oficina.connect.ability_off": "Reading your Oficina apps is turned off for you. %s can turn it on.", // COPY APPROVED (Paul, 2026-11-28, copy-review mi3kgi7nubnsf7kxn235tqwrbu, unchanged) |
| } |
| // pasteLabels are the paste box's words, for the shared renderer, and |
diff --git a/internal/thintest/assistant_oficina_contract_test.go b/internal/thintest/assistant_oficina_contract_test.go| index dae38219..9c8525f3 100644 |
| --- a/internal/thintest/assistant_oficina_contract_test.go |
| +++ b/internal/thintest/assistant_oficina_contract_test.go |
| @@ -470,6 +470,7 @@ func TestContractAssistantOficinaOffByDefault(t *testing.T) { |
| func TestContractAssistantOficinaSettleChecksRoster(t *testing.T) { |
| o := newOficinaRig(t) |
| ana := o.other("ana@example.com") |
| + ana.connect(o.base.Mint()) |
| ana.begin("Put lunch in my calendar.") |
| ana.tool("l1", wire.ToolLook, map[string]any{"query": "calendar"}) |
| state := func() string { |
diff --git a/internal/thintest/assistant_ops_contract_test.go b/internal/thintest/assistant_ops_contract_test.go| index 3fddb6c0..e59d9fe7 100644 |
| --- a/internal/thintest/assistant_ops_contract_test.go |
| +++ b/internal/thintest/assistant_ops_contract_test.go |
| @@ -28,7 +28,7 @@ type keyedProvider struct { |
| fail bool |
| } |
| -func (p *keyedProvider) Name() string { return "ledger" } |
| +func (p *keyedProvider) Name() string { return "svc:ledger" } |
| // failNext makes the next call fail after it is counted. |
| func (p *keyedProvider) failNext() { |
diff --git a/internal/thintest/assistant_outcome_contract_test.go b/internal/thintest/assistant_outcome_contract_test.go| index 29d1aaff..091f987c 100644 |
| --- a/internal/thintest/assistant_outcome_contract_test.go |
| +++ b/internal/thintest/assistant_outcome_contract_test.go |
| @@ -474,6 +474,7 @@ func TestContractOutcomeOnlyTheirs(t *testing.T) { |
| var id string |
| o.in(mine, func() { id = o.record("ot-own", "Quick website") }) |
| mate := &teamRig{o.other("mate@example.com")} |
| + mate.connect(o.base.Mint()) |
| mate.ask("Can we fix a bug in Tito? Login is broken") |
| request, cmd := mate.handoff("ot1", "Login is broken", "") |
| mate.in(cmd.TurnID, func() { |
| @@ -562,6 +563,7 @@ func TestContractOutcomeOnlyOwnAnswer(t *testing.T) { |
| card := o.assistantCard("the merge outcome", isMergeOutcome) |
| mate := &teamRig{o.other("mate@example.com")} |
| + mate.connect(o.base.Mint()) |
| if _, err := mate.a.Answer(o.ctx, card.ID, wire.ChoiceMerge, card.Revision); Status(err) != http.StatusNotFound { |
| t.Fatalf("another member's answer: %v", err) |
| } |
diff --git a/internal/thintest/assistant_reply_contract_test.go b/internal/thintest/assistant_reply_contract_test.go| index e26ae3af..3a3fb2ad 100644 |
| --- a/internal/thintest/assistant_reply_contract_test.go |
| +++ b/internal/thintest/assistant_reply_contract_test.go |
| @@ -305,6 +305,7 @@ func TestContractTeamReplyOnlyOwnJob(t *testing.T) { |
| o.reply(second.TurnID) |
| mate := &teamRig{o.other("mate@example.com")} |
| + mate.connect(o.base.Mint()) |
| mate.ask("Pick This for that one") |
| if res := mate.teamReply("oj-mate", mine, "This"); !res.IsError || res.Code != "not_found" { |
| t.Fatalf("another person's request %+v", res) |
diff --git a/internal/thintest/assistant_team_contract_test.go b/internal/thintest/assistant_team_contract_test.go| index a97cbc23..040e6035 100644 |
| --- a/internal/thintest/assistant_team_contract_test.go |
| +++ b/internal/thintest/assistant_team_contract_test.go |
| @@ -27,6 +27,10 @@ func newTeamRig(t *testing.T) *teamRig { return newTeamRigAt(t, wire.ProtocolJob |
| // newTeamRigAt is newTeamRig whose runner speaks protocol. |
| func newTeamRigAt(t *testing.T, protocol int) *teamRig { |
| o := newOpsRigAt(t, protocol) |
| + // The person reached the Assistant through their Base, which holds |
| + // their abilities (all on): with Base's hosts set, nothing switched |
| + // runs for anyone without one (abilities §5.3). |
| + o.connect(o.base.Token) |
| o.inst.Store.Chat().SetHousekeepingClock(daytime()) |
| if err := o.runner.Send(o.ctx, "h-team", wire.FrameHello, primaryAt(toolHello(o.runner.Welcome.Generation), protocol)); err != nil { |
| t.Fatal(err) |