Grant card for a repository the person names; refuse invented ones (review R1, RN1-RN3)
Human
Prompt
Fable 5.2 re-review of ae6192c7 (APPROVED with R1 and RN1-RN5); controller: test-first on the same branch.
From this commit's own message. The prompt ledger has no entries for it — which is what a squashed, rebased or amended commit looks like, and what every commit looks like in a repo without a ledger.
Summary
R1: in a namespace Equipo knows nothing of, find raises the grant card only when the person's own composed words this turn name the repository (any AccessTarget spelling); otherwise unknown_namespace with no request_access sentence. request_access refuses such a target with not_named. Runners below protocol 26 get the grant card with the command and Check, as before, for a named repository. A new team whose agent reaches nothing gets the card when the person names it. RN1: test that a not-needed card does not take the turn's one card. RN2: a namespace is already reached only when held whole (CreateIn), whatever the role. RN3: 'sees no repository X there yet' instead of asserting none, and request_access no longer says it for a repository the agent reads.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 files changed,
+157
−20
internal/equipo/chat/access_need_test.go+88 −0internal/equipo/chat/access_request.go+44 −7internal/equipo/chat/access_review_test.go+2 −0internal/equipo/chat/placement_edges_test.go+5 −0internal/equipo/chat/tools.go+18 −13
diff --git a/internal/equipo/chat/access_need_test.go b/internal/equipo/chat/access_need_test.go| index 214da9fd..9523b729 100644 |
| --- a/internal/equipo/chat/access_need_test.go |
| +++ b/internal/equipo/chat/access_need_test.go |
| @@ -3,6 +3,7 @@ package chat |
| import ( |
| "context" |
| "encoding/json" |
| + "slices" |
| "strings" |
| "testing" |
| @@ -273,6 +274,12 @@ func TestTwoRepositoryTurnKeepsTheUnreachedCard(t *testing.T) { |
| if got := callTool(t, r, l, turn, "call-find", wire.ToolFind, map[string]string{"query": "tito/website"}); got.Code != "none" { |
| t.Fatalf("find: %+v", got) |
| } |
| + // The find raised its own card (review RN1). |
| + if cards := accessCards(t, r); len(cards) != 2 || !slices.ContainsFunc(cards, func(c cardRecord) bool { |
| + return c.ID != done.ID && c.State == wire.CardOpen && c.Name == "tito/website" && c.Access == "" |
| + }) { |
| + t.Fatalf("find after a not-needed card: %+v", cards) |
| + } |
| if got := callTool(t, r, l, turn, "call-ask", wire.ToolRequestAccess, map[string]string{"target": "tito/website", "reason": "I need to fix the header."}); got.Code != "asked" { |
| t.Fatalf("request: %+v", got) |
| } |
| @@ -351,3 +358,84 @@ func TestProjectTitleFromRepositoryName(t *testing.T) { |
| } |
| } |
| } |
| + |
| +// sayInTurn replaces the person's words in the rig's turn. |
| +func sayInTurn(t *testing.T, r *meteredRig, words string) { |
| + t.Helper() |
| + if err := r.s.db.G.Model(&messageRecord{}).Where("id = ?", "m_swipe").Update("text", words).Error; err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +// setHello replaces the runner's hello and protocol. |
| +func setHello(t *testing.T, r *meteredRig, h wire.Hello, protocol int) { |
| + t.Helper() |
| + raw, _ := json.Marshal(h) |
| + if err := r.s.db.G.Model(&runnerSessionRecord{}).Where("runner_id = ?", "RUNNER1").Updates(map[string]any{"hello": string(raw), "protocol": protocol}).Error; err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +// Review R1: in a namespace Equipo knows nothing of, a repository the |
| +// person named this turn gets the grant card (also on a runner without |
| +// request_access, and for a new team whose agent reaches nothing); one the |
| +// model made up gets neither a card nor a request_access suggestion, and |
| +// request_access refuses it. |
| +func TestUnknownNamespaceCardOnlyWhenThePersonNamesIt(t *testing.T) { |
| + for _, tc := range []struct { |
| + name, words string |
| + hello wire.Hello |
| + protocol int |
| + }{ |
| + {"named", "Fix the header in acme/website.", swipeHello(), wire.ProtocolCurrent}, |
| + {"named on an old runner", "Fix the header in acme/website.", swipeHello(), wire.ProtocolAccess - 1}, |
| + {"new team", "Please work on https://amadan.net/acme/website", wire.Hello{Agent: "claude~paul@keymail.dev"}, wire.ProtocolCurrent}, |
| + } { |
| + t.Run(tc.name, func(t *testing.T) { |
| + r, turn, l := swipeRig(t) |
| + sayInTurn(t, r, tc.words) |
| + setHello(t, r, tc.hello, tc.protocol) |
| + got := callTool(t, r, l, turn, "call-find", wire.ToolFind, map[string]string{"query": "acme/website"}) |
| + if got.IsError || got.Code != "none" || strings.Contains(got.Text, "request_access") != (tc.protocol >= wire.ProtocolAccess) { |
| + t.Fatalf("find: %+v", got) |
| + } |
| + if cards := accessCards(t, r); len(cards) != 1 || cards[0].Name != "acme/website" || cards[0].State != wire.CardOpen { |
| + t.Fatalf("cards: %+v", cards) |
| + } |
| + }) |
| + } |
| + r, turn, l := swipeRig(t) |
| + got := callTool(t, r, l, turn, "call-find", wire.ToolFind, map[string]string{"query": "ios/keyboard"}) |
| + if !got.IsError || got.Code != "unknown_namespace" || strings.Contains(got.Text, "request_access") { |
| + t.Fatalf("find of an invented repository: %+v", got) |
| + } |
| + got = callTool(t, r, l, turn, "call-ask", wire.ToolRequestAccess, map[string]string{"target": "ios/keyboard", "reason": "I need to fix the keyboard."}) |
| + if !got.IsError || got.Code != "not_named" { |
| + t.Fatalf("request_access for an invented repository: %+v", got) |
| + } |
| + if cards := accessCards(t, r); len(cards) != 0 { |
| + t.Fatalf("cards: %+v", cards) |
| + } |
| +} |
| + |
| +// Review RN2 and RN3: reading one repository in a namespace is not holding |
| +// the namespace, and a repository the agent reads in a namespace it holds |
| +// exists, so asking to write to it is not "no such repository". |
| +func TestRequestAccessNamespaceReaderAndReadRepository(t *testing.T) { |
| + r, turn, l := swipeRig(t) |
| + sayInTurn(t, r, "Give Equipo read access to the whole tito namespace.") |
| + if got := callTool(t, r, l, turn, "call-ns", wire.ToolRequestAccess, map[string]string{"target": "tito", "role": "reader", "reason": "I need to read everything in tito."}); got.IsError || got.Code != "asked" { |
| + t.Fatalf("namespace reader: %+v", got) |
| + } |
| + r, turn, l = swipeRig(t) |
| + h := swipeHello() |
| + h.Catalog = append(h.Catalog, wire.RepoInfo{Repo: "amadan.net/oficina/readonly", Names: []string{"readonly"}, Hints: []string{}}) |
| + setHello(t, r, h, wire.ProtocolCurrent) |
| + if got := callTool(t, r, l, turn, "call-ro", wire.ToolRequestAccess, map[string]string{"target": "oficina/readonly", "reason": "I need to fix it."}); got.IsError || got.Code != "asked" { |
| + t.Fatalf("write to a read repository in a held namespace: %+v", got) |
| + } |
| + r, turn, l = swipeRig(t) |
| + if got := callTool(t, r, l, turn, "call-find", wire.ToolFind, map[string]string{"query": "oficina/ios-keyboard"}); got.Code != "no_such_repository" || !strings.Contains(got.Text, "sees no repository oficina/ios-keyboard there yet") { |
| + t.Fatalf("find of a missing repository: %+v", got) |
| + } |
| +} |
diff --git a/internal/equipo/chat/access_request.go b/internal/equipo/chat/access_request.go| index cffc682e..4bddb123 100644 |
| --- a/internal/equipo/chat/access_request.go |
| +++ b/internal/equipo/chat/access_request.go |
| @@ -63,11 +63,19 @@ func (t *txn) requestAccess(r turnRecord, in wire.AccessRequest) (wire.ToolResul |
| if err != nil { |
| return wire.ToolResult{}, err |
| } |
| - if has(h, strings.ToLower(in.Target), in.Role) { |
| + target := strings.ToLower(in.Target) |
| + if has(h, target, in.Role) { |
| return refused("already_reached", fmt.Sprintf(toolAlreadyReached, in.Target)), nil |
| } |
| - if ns, _, ok := strings.Cut(strings.ToLower(in.Target), "/"); ok && slices.Contains(h.CreateIn, ns) { |
| - return refused("no_such_repository", fmt.Sprintf(toolNoSuchRepository, in.Target, ns)), nil |
| + if ns, _, ok := strings.Cut(target, "/"); ok { |
| + if slices.Contains(h.CreateIn, ns) && !reaches(h, target) { |
| + return refused("no_such_repository", fmt.Sprintf(toolNoSuchRepository, in.Target, ns)), nil |
| + } |
| + // In a namespace Equipo knows nothing of, only the person's own |
| + // words this turn say the repository is real (review R1). |
| + if !knownNamespace(h, ns) && !namedIn(messages, target) { |
| + return refused("not_named", fmt.Sprintf(toolNotNamed, in.Target)), nil |
| + } |
| } |
| var old []cardRecord |
| if err := t.db.Where("person = ? AND kind = ? AND coalesce(access, '') <> '' AND (turn_id = ? OR state = ?)", r.Person, wire.CardAccess, r.ID, wire.CardOpen).Find(&old).Error; err != nil { |
| @@ -259,13 +267,42 @@ func (t *txn) continueAccess(c cardRecord, h wire.Hello) error { |
| return err |
| } |
| +// personNamed reports whether the person's own words this turn name target |
| +// (AccessTarget's spelling), not text the model or Equipo wrote. |
| +func (t *txn) personNamed(r turnRecord, target string) (bool, error) { |
| + var messages []messageRecord |
| + if err := t.db.Where("person = ? AND turn_id = ? AND role = ?", r.Person, r.ID, wire.RolePerson).Order("seq").Find(&messages).Error; err != nil { |
| + return false, err |
| + } |
| + return namedIn(messages, target), nil |
| +} |
| + |
| +// namedIn reports whether one of the person's composed messages names |
| +// target as a word of its own, spelled any way AccessTarget accepts. |
| +func namedIn(messages []messageRecord, target string) bool { |
| + for _, m := range messages { |
| + if m.Origin != originComposer { |
| + continue |
| + } |
| + for _, word := range strings.Fields(m.Text) { |
| + if AccessTarget(strings.Trim(word, ".,;:!?\"'`()[]<>")) == target { |
| + return true |
| + } |
| + } |
| + } |
| + return false |
| +} |
| + |
| // has reports whether the agent already has the access a request asks |
| // for (review S1). Write work (role agent or runner) needs a repository on |
| -// the runner's list, or a namespace it holds whole; a repository it only |
| -// reads is in the catalog alone. Reading needs either. |
| +// the runner's list; a repository it only reads is in the catalog alone, |
| +// which is enough for reading. A namespace counts only held whole. |
| func has(h wire.Hello, target, role string) bool { |
| - if ns, _, ok := strings.Cut(target, "/"); !ok { |
| - return slices.Contains(h.CreateIn, target) || role == "reader" && related(h, ns) |
| + if !strings.Contains(target, "/") { |
| + // A namespace is held whole only where the agent may create; |
| + // reading one repository there is not reading the namespace |
| + // (review RN2). |
| + return slices.Contains(h.CreateIn, target) |
| } |
| if role == "reader" { |
| return reaches(h, target) |
diff --git a/internal/equipo/chat/access_review_test.go b/internal/equipo/chat/access_review_test.go| index ee4e96bc..7df55292 100644 |
| --- a/internal/equipo/chat/access_review_test.go |
| +++ b/internal/equipo/chat/access_review_test.go |
| @@ -115,6 +115,8 @@ func TestAccessFindHintHonorsNegotiatedProtocol(t *testing.T) { |
| for _, proto := range []int{25, 26} { |
| r := placementRig(t) |
| r.s.db.G.Model(&runnerSessionRecord{}).Where("runner_id = ?", "RUNNER1").Update("protocol", proto) |
| + // The person named it: carlos is a namespace Equipo knows nothing of. |
| + r.s.db.G.Create(&messageRecord{ID: "m_find", Person: hkOwner, TurnID: "find", Role: wire.RolePerson, Text: "Fix the build in carlos/platform", Origin: originComposer}) |
| if err := r.s.tx(context.Background(), func(tx *txn) error { |
| got, err := tx.find(turnRecord{ID: "find", Person: hkOwner}, "carlos/platform") |
| if strings.Contains(got.Text, "request_access") != (proto >= 26) { |
diff --git a/internal/equipo/chat/placement_edges_test.go b/internal/equipo/chat/placement_edges_test.go| index 666c0268..27ed13e2 100644 |
| --- a/internal/equipo/chat/placement_edges_test.go |
| +++ b/internal/equipo/chat/placement_edges_test.go |
| @@ -204,6 +204,11 @@ func TestPlacementMissingRepositorySharingHint(t *testing.T) { |
| if err := r.s.db.G.Model(&runnerSessionRecord{}).Where("runner_id = ?", "RUNNER1").Update("hello", string(h)).Error; err != nil { |
| t.Fatal(err) |
| } |
| + // The person named it, so a namespace Equipo knows nothing of |
| + // (carlos) still gets the grant card. |
| + if err := r.s.db.G.Create(&messageRecord{ID: "m_missing", Person: hkOwner, TurnID: "tr_missing", Role: wire.RolePerson, Text: "Work in " + query + " please", Origin: originComposer}).Error; err != nil { |
| + t.Fatal(err) |
| + } |
| if err := r.s.tx(context.Background(), func(tx *txn) error { |
| got, err := tx.find(turnRecord{ID: "tr_missing", Person: hkOwner}, query) |
| for _, want := range []string{"equipo-paul", "not shared with Equipo", "request_access", "single repository", "merging", "per-project"} { |
diff --git a/internal/equipo/chat/tools.go b/internal/equipo/chat/tools.go| index ad244255..9e0b19e4 100644 |
| --- a/internal/equipo/chat/tools.go |
| +++ b/internal/equipo/chat/tools.go |
| @@ -43,12 +43,16 @@ const ( |
| toolNotARepository = "Nothing Equipo's agent can reach matches %q, and it does not name a repository as namespace/repository, so no access card was raised. Do not search again for parts of it. File the task in one of the person's projects, or ask the person which repository this is for." |
| // toolNoSuchRepository: the repository's namespace is one the agent |
| // holds whole (CreateIn), so it would reach the repository if it existed. |
| - toolNoSuchRepository = "Equipo's agent reaches everything in %[2]s, and there is no repository %[1]s there, so no access would help and no card was raised. File the task in one of the person's projects, or ask the person which repository this is for." |
| - // toolUnknownNamespace: Equipo cannot tell whether the repository exists. |
| - // The sharing hint follows it, for a repository the person named. |
| - toolUnknownNamespace = "Equipo cannot confirm that %[1]s exists: its agent reaches nothing in %[2]s, so no access card was raised. Unless the person named it themselves, file the task in one of the person's projects, or ask the person which repository this is for. If they did name it, it may be a repository not shared with Equipo." |
| - // toolRequestAccessHint follows a sharing hint on a runner with request_access. |
| + // Its list can be a minute old, so it says "yet", never "there is none". |
| + toolNoSuchRepository = "Equipo's agent reaches everything in %[2]s and sees no repository %[1]s there yet, so no access would help and no card was raised. A repository made a moment ago shows within a minute. Otherwise file the task in one of the person's projects, or ask the person which repository this is for." |
| + // toolUnknownNamespace: Equipo cannot tell whether the repository |
| + // exists, and the person did not name it this turn. |
| + toolUnknownNamespace = "Equipo cannot confirm that %[1]s exists: its agent reaches nothing in %[2]s, and the person has not named it, so no access card was raised. File the task in one of the person's projects, or ask the person which repository this is for." |
| + // toolRequestAccessHint follows the grant hint on a runner with request_access. |
| toolRequestAccessHint = " Use request_access with the single repository, role agent unless asked otherwise, and your reason. It only raises a confirmation card, and Amadan checks the repository exists. Never retry unprompted." |
| + // toolNotNamed: request_access for a repository in a namespace Equipo |
| + // does not know, which the person did not name this turn. |
| + toolNotNamed = "Equipo cannot confirm that %s exists, and the person has not named it this turn, so no card was raised. Ask the person which repository they mean." |
| // toolReachedNoMatch: the query names a repository the agent reaches. |
| toolReachedNoMatch = "Equipo's agent already reaches %s, so it needs no access. Use it." |
| // toolAlreadyReached: request_access for something already reached. |
| @@ -1086,15 +1090,16 @@ func (t *txn) find(r turnRecord, query string) (wire.ToolResult, error) { |
| if slices.Contains(h.CreateIn, ns) { |
| return refused("no_such_repository", fmt.Sprintf(toolNoSuchRepository, target, ns)), nil |
| } |
| - share := " Mention that merging is a separate per-project setting." |
| - if h.Agent != "" { |
| - share = " The agent is " + h.Agent + "." + share |
| - } |
| - if asks { |
| - share += toolRequestAccessHint |
| - } |
| + // A namespace Equipo knows nothing of: only the person's own words |
| + // this turn say the repository is real (review R1). |
| if !knownNamespace(h, ns) { |
| - return refused("unknown_namespace", fmt.Sprintf(toolUnknownNamespace, target, ns)+share), nil |
| + named, err := t.personNamed(r, target) |
| + if err != nil { |
| + return wire.ToolResult{}, err |
| + } |
| + if !named { |
| + return refused("unknown_namespace", fmt.Sprintf(toolUnknownNamespace, target, ns)), nil |
| + } |
| } |
| namespaces := []string{} |
| for _, e := range entries { |