Skip to content

An agent's session names the collections it can read, and a collection refusal says how to find them - #220

Merged
zlareb1 merged 8 commits into
mainfrom
feat/agents-see-collections
Nov 4, 2026
Merged

zlareb1 merged 8 commits into
mainfrom
feat/agents-see-collections

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Related: #219 (adds description to collection.list and makes the dashboard's Library the collection browser, which the refusal names; this PR merges after it)

Changelog category (leave one):

  • Improvement

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

A coding agent's session now starts with a few lines naming the shared collections its token can read, with its role and each one's description, and how to search and write them. The MCP instructions and a refused collection's error point at collection.list.

Why

An agent already searches every collection its token can read: knowledge.search and loom_search fan out over them by default (knowledge_search_fanout_kinds includes collection). But nothing told it which collections exist, so it could not do either of these without being told a col-… name:

  • add a document to one;
  • say which shared collection a hit came from.

The plugin, its skills, the mentor and the MCP tool texts never mentioned collections, and a refused col-… name said only cannot access.

The smallest change that makes them discoverable without widening anything:

  • The session-start primer lines (Claude Code and Codex plugins, lib/collections-line.mjs). It makes one collection.list call for the session's org, reading up to 1,000 rows, cached a minute per (server, org, token digest, toolset). The answer is the token's own, so two agents sharing a home with their own tokens each read their own line.
    • What it says. The lines name the collections and say nothing about how a search covers them: that is the deployment's knowledge_search_fanout_kinds, which the plugin cannot read, and the server's own instructions state it. If the caller writes one of them and the toolset is not read-only, the lines also say how to add a document when asked to (they never suggest filing one there unprompted): call knowledge.add with namespace set to the collection's name, as its own tool where the toolset lists it (Codex does), otherwise through loom_op with {"op": "knowledge.add", "arguments": {"namespace": "<name>", ...}}. A pointer to collection.list, through loom_op, follows the list when there are more.
    • What it lists. Up to six collections, those the caller holds most on (admin, then writer, then viewer) first, each with the caller's role and its description. A name chosen to sort first cannot push those off on its own. But any org member can create a collection and grant everyone admin on it, which ranks with the caller's own admin collections, so the order is a convenience, not a defence; that is why the write sentence only answers a request. Names are shown whole, since the agent uses the name it reads; a name the server would not make is left off.
    • Untrusted text. A collection's name and description are its creator's words, and any org member can create one and share it with everyone. So the list sits inside the plugin's recalled-data block, one JSON line per entry, {"collection": …, "role": …, "description": …}. The block marks it as data, and the JSON string keeps a description to its own entry. Names are held to the server's name rule. After NFKC, a description keeps only letters, marks, digits, spaces, a few ASCII punctuation marks and emoji. The okina and the modifier apostrophe become an ASCII apostrophe. Common quote, backtick and bracket lookalikes, control and format characters, and default-ignorable characters (which can hide text) become spaces. Emoji keep their joiners, skin tones and selectors. Each character, as a reader sees it, keeps at most four combining marks (an Indic conjunct needs that many); one over 16 code units is dropped; the description is cut to 60 characters.
    • What it leaves out. The user's own @me, since a session's token has none. It is silent when there are none, on an op the server does not serve, and on any error. The toolset option is read as the server reads it: parts split on +, a space or a comma, lower-cased. An unknown value takes the deployment's default on the server, which the plugin cannot know. The assistant toolset alone, which routes neither loom_search nor loom_op, gets no lines, and readonly (which routes_writes treats as the one read-only value) gets no write sentence. The Codex plugin names its toolset in its own .mcp.json and sets no option, so there the lines read the toolset as writable. LOOM_COLLECTIONS_LINE=off drops them.
  • The MCP primer (server/transport/mcp_primer.py) says that loom_search's knowledge leg covers the collections the caller can read, and that a document for a collection goes there by its name as the namespace. It names collection.list by the tool that reaches it, in the read section of the full primer, and the shorter initialize instructions on the coding toolset say that loom_search also reads the collections you can read. Both say so only while knowledge_search_fanout_kinds includes collections, and so does the MCP refusal: one helper, server.auth.fanout.knowledge_search_reads_collections, reads the setting for all three.
  • The refusals. The collection gate (server/auth/sharing.py::check) now also says the role it needs: "a collection needs a grant of at least on it or a collection above it; collection.list (or the dashboard's Library) lists the ones you can read". It names no tool route: the gate does not know the transport, and an assistant connection has no loom_op; the MCP screen says how its connection reaches the op. One helper, sharing.claim_cap, decides for the gate and the MCP screen alike when the token's own claim, rather than a missing grant, caps it: a scoped claim whose role there is short, a delegated claim that does not name it (a * claim does not, as the gate's own cap reads it), an ns_write claim that does not name it for a write, or a token whose own role is short (a viewer bot asked to write). It reads the same ceiling as the gate's cap, so the note and the refusal never disagree. Such a token is told both what it needs: which part of its claim blocks it, and that the token's own subject, which the grants are read for, must hold the grant. The words come from the token alone, never from the grants, since what a caller's grants reach on a collection its token cannot see would confirm that collection exists; so a caller who already holds the grant reads that part as already met. The gate and the MCP screen say the same, including a delegated token's creator. The parts a claim can lack: its write set (ns_write) must include the collection, its claim must name it, or name it with that role; every limit that applies is named at once, with the role it needs. A tree or grant that cannot be read still refuses, in the short words, so a caller that holds a grant retries instead of asking for one. A delegated token is also told its creator must hold the role. A caller from another org, and anyone refused someone else's personal collection (which takes no grant), gets the short refusal, with nothing added. The MCP screen's refusal of a col- name, which an agent's direct tool call meets first (server/transport/mcp_auth.py::_not_accessible_result), asks the collection's admin for a grant and points at collection.list through loom_op. A token whose claim caps it is told what its claim must say and that its own subject must hold a grant of at least viewer (directly, through a group or to everyone); a delegated token is told its creator must be active and hold a grant too. It no longer sends the agent to the Spaces page, since a collection is never joined, nor suggests omitting the namespace, which would file a write meant for the collection in the default namespace; and, for a plain namespace, it says loom_search reads the collections the agent can read. On the assistant toolset it names neither loom_search nor loom_op (that connection reaches neither); a plain namespace there keeps its default-namespace and Spaces-page advice. Someone else's personal collection gets the bare refusal, which names no grant. Both say the same words whether the collection exists or not, so they confirm nothing.

Not done, on purpose:

  • No display-name aliasing for col-… names. A second name space would add a resolver to every op and a new ambiguity.
  • No change to search scope. The fan-out already covers readable collections.

Scope and risk

  • Access is unchanged. The line lists only what collection.list returns for the session's own token (sharing.readable), which is what its grants already reach.
  • The line adds one bounded, cached call per session start, in parallel with the others. When the token reads collections, it adds about 150 tokens to the primer for one collection, and up to about 350 for six with long descriptions.
  • The refusal text is a clause longer, and the dashboard shows it after its own sentence. Nothing matches on its old wording (grep over tests/ and the clients).

Compatibility, rollout and rollback

Tests

  • integrations/claude-code-plugin/tests/collections-line.test.mjs:
    • the request reads 1,000 collections to pick the named ones from;
    • each collection is named with its role and description, and the line says how to use them;
    • the line is silent with no shared collection, with only the user's own, or on an error;
    • six are named and the line points at collection.list for the rest;
    • the line names first the collections the caller holds most on, and points at collection.list for the rest, also when only the server's cursor says there are more;
    • a description cannot break out of its quotes, the data block or its line (quotes, backticks, a closing tag, a bidi override, a line break);
    • a long description is cut on a whole character, a name never is, and a malformed name is left off;
    • the write sentence appears only when the caller writes one of the collections and the connection allows writes;
    • variation selectors are stripped, and a flag is never split;
    • the toolset is read as the server reads it, with none on assistant alone and no writes on readonly;
    • zero-width non-joiners stay in a description; quote, bracket and backtick lookalikes of any script go, each checked absent; a run of combining marks cannot swell it, neither a joiner, a non-joiner nor a skin-tone modifier restarts the per-character cap, an overlong character is dropped, a description of exactly 60 characters is shown whole, and the cut keeps whole emoji; invisible fillers, compatibility primes and NKo apostrophes go.
  • tests/unit/test_access_refusal.py: an assistant connection is pointed at no tool it cannot call (and keeps the default-namespace advice for a plain namespace), and someone else's personal collection gets no advice.
  • tests/unit/test_sharing.py: another org's caller gets the short refusal, and a token is named only when its claim is what caps it (a scoped claim that already names the collection is not; a delegated token is told its creator must hold the role; a viewer bot and a scoped writer outside its write set are told about their claim).
  • tests/unit/test_mcp_coding_toolset.py: the primer names collection.list by the tool that reaches it, and the rendered full primer and coding instructions say that loom_search reads collections.
  • tests/unit/test_access_refusal.py: a scoped token refused a collection is told its claim must name it.
  • tests/unit/test_sharing.py::test_a_refusal_points_at_the_library_and_confirms_nothing: an existing and a missing collection are refused in the same words, which name the role needed and the dashboard's Library; someone else's personal collection gets neither.
  • tests/unit/test_access_refusal.py::test_a_refused_collection_points_at_collection_list_and_a_namespace_does_not.
  • collections-line.test.mjs also passes on Node 18, the plugins' minimum, and node --check passes there on the hook.
  • tests/unit/test_mcp_coding_toolset.py also: the primers drop the collections clause when the fan-out setting leaves collections out.
  • node --test integrations/claude-code-plugin/tests/*.test.mjs (432 tests), claude plugin validate integrations/claude-code-plugin, make lint typecheck, and the sharing, access-refusal and primer unit tests (290) pass.
  • Manual: against a local server where the token reads three collections, the line named the three collections with their roles and descriptions.

🤖 Generated with Claude Code

…ys how to reach it

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 force-pushed the feat/agents-see-collections branch from 58e857d to 9a87791 Compare November 4, 2026 02:47
zlareb1 and others added 7 commits November 4, 2026 02:55
…s for no grant

The plugin cannot read the deployment's knowledge_search_fanout_kinds,
so the session-start lines say how to name a collection in a search
rather than that loom_search reads them, which the server's own
instructions state when it is true. The collection gate tells a token
its own claim keeps out only what the claim must say, as the MCP screen
does, with the role a delegated token's creator needs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ollection

A minted token is capped to its owner's grants, so telling a claim-capped
token to re-mint only helps when those grants already reach the role.
The gate and the MCP screen now read the grants before the claim's cap
(sharing.claim_advice) and give the claim's fix only then, else the
grant's. The session lines name knowledge.search for searching one
collection, since loom_search takes no namespace.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…o search

Choosing the refusal's advice from the caller's grants told a scoped
token whether a collection it cannot see exists, so the advice is read
from the token alone again: a token its claim caps is told both what it
needs, the claim that names the collection and the grant a new token is
capped to, on the gate and the MCP screen alike, with a delegated
token's creator. The session lines no longer name a search op:
knowledge.search is kept off MCP and loom_search takes no namespace,
and how a search covers collections is the server's to say.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
On a refused collection the MCP screen asks for a grant and points at
collection.list, and no longer suggests dropping the namespace, which
would file a write meant for the collection in the default namespace.
The session lines say collection.list lists collections a page at a
time.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The grant a refusal asks for is read for the token's own subject, so the
refusal names that principal rather than the token's owner, which for a
service account is someone else. The gate's refusal says collection.list
is reached through loom_op over MCP.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The gate does not know the transport, and an assistant connection has no
loom_op, so its refusal names collection.list and the dashboard's
Library only; the MCP screen says how its own connection reaches the op.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…e creator

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 merged commit c1ee693 into main Nov 4, 2026
21 of 22 checks passed
@zlareb1
zlareb1 deleted the feat/agents-see-collections branch November 4, 2026 04:41
@pufit pufit mentioned this pull request Nov 4, 2026
9 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant