@devfellowship/access 0.2.1 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @devfellowship/access
2
2
 
3
- The one fleet access decision. The gateway (S3) and `dfl-os-commands` (S2) import the same version.
3
+ The one fleet access decision. The gateway (S3) and `dfl-domain-api` (S2) import the same version.
4
4
  Plan: `20261116-fleet-access-s2-access-service` (S2-T1); parent `20261115-fleet-access-iam-gateway-flows-rules` (ADR-5, ADR-16).
5
5
 
6
6
  Pure functions. No I/O, no clock read, no DB function. The caller reads the `iam.permissions` rows with the user's own token and passes them in.
@@ -86,7 +86,7 @@ IAM "Try it" (S4-T6B) runs the same binding: `POST /v1/access/explain` with a ru
86
86
 
87
87
  ## The capability catalog (S2-T2)
88
88
 
89
- `capabilities.json` lists one capability name per MCP tool: `<domain>.<entity>.<verb>` (tool `work.create_task` -> `work.task.create`). The domain is the MCP host, the verb is the first word of the tool name, the entity is the rest. It ships in the package. `dfl-os-commands` reads it (`ACCESS_CATALOG_PATH`, or `<package>/capabilities.json`) for the IAM read endpoints (`catalog.available`).
89
+ `capabilities.json` lists one capability name per MCP tool: `<domain>.<entity>.<verb>` (tool `work.create_task` -> `work.task.create`). The domain is the MCP host, the verb is the first word of the tool name, the entity is the rest. It ships in the package. `dfl-domain-api` reads it (`ACCESS_CATALOG_PATH`, or `<package>/capabilities.json`) for the IAM read endpoints (`catalog.available`).
90
90
 
91
91
  Each capability also carries `domain_group`: the big domain of its host (`work`, `marketing`, `money`, `people`, `studio`, `engineering`), read from the fleet domain map `domains.json` of `dfl-mcp-server` (`--domains <file|url>`, default `https://mcp.devfellowship.com/domains.json`). The name keeps the host prefix (plan `20261117-fleet-domain-consolidation`, ADR-4). A host with no group fails the build. `GET /v1/access/capabilities?domain_group=money` filters by it.
92
92
 
@@ -96,7 +96,7 @@ npm run catalog:check # writes nothing; exit 1 when the file is out of date
96
96
  node scripts/build-catalog.mjs --manifest <file> --gateway-modes <oauth-tools.generated.ts>
97
97
  ```
98
98
 
99
- The build prints `tools: N` and `capabilities: N`. It exits 1 when a tool is **unmapped** (its verb is not in `VERBS`, or its name has no entity and `OVERRIDES` has no entry) or when two tools get one name. A new MCP tool with a new verb therefore fails the `catalog` CI job until someone adds the verb to `VERBS` with its mode (`read` or `write`) in `scripts/catalog-lib.mjs`. With `--gateway-modes`, the build also exits 1 when the catalog offers a write tool of the gateway registry as a read. The **mode guard** (CATALOG-READ-MODE-FIX): a tool whose name starts with `list`, `get`, `wait`, `read`, `search` or `describe` and is `write` fails the build, on the catalog and on the gateway registry, unless `READ_NAME_WRITE_ALLOWLIST` in `scripts/catalog-lib.mjs` names it with the reason it writes (an upload, a paid call, a job that registers media). An allow-list line with no reason, or for a tool that is no longer `write`, also fails. The verb `check` is `write` by default; a check that only reads gets an `OVERRIDES` entry with `mode: "read"`, and the gateway cross-check fails the build if the gateway says `write` for it. A deprecated alias adds no entry. Commands (kind `command`) enter the catalog when the first command exists (S2-T6). The kinds `table`, `rpc` and `function` come from the database surface (next section).
99
+ The build prints `tools: N` and `capabilities: N`. It exits 1 when a tool is **unmapped** (its verb is not in `VERBS`, or its name has no entity and `OVERRIDES` has no entry) or when two tools get one name. A new MCP tool with a new verb therefore fails the `catalog` CI job until someone adds the verb to `VERBS` with its mode (`read` or `write`) in `scripts/catalog-lib.mjs`. With `--gateway-modes`, the build also exits 1 when the catalog offers a write tool of the gateway registry as a read. The **mode guard** (CATALOG-READ-MODE-FIX): a tool whose name starts with `list`, `get`, `wait`, `read`, `search` or `describe` and is `write` fails the build, on the catalog and on the gateway registry, unless `READ_NAME_WRITE_ALLOWLIST` in `scripts/catalog-lib.mjs` names it with the reason it writes (an upload, a paid call, a job that registers media). An allow-list line with no reason, or for a tool that is no longer `write`, also fails. The verb `check` is `write` by default; a check that only reads gets an `OVERRIDES` entry with `mode: "read"`, and the gateway cross-check fails the build if the gateway says `write` for it. A deprecated alias adds no entry. Commands (kind `command`) enter the catalog when the first command exists (S2-T6). A command that has an MCP tool merges into that tool entry through `COMMANDS`. A command with **no** MCP tool (a UI-only write; CLAUDE.md: MCP is only for AI agents) is declared in `COMMAND_ONLY` (FIN-T4): one reviewed entry per capability with `command` (name), `route`, `mode` and `rule`; the entry gets kind `command`, doors `["commands"]`, no `tool`, and `domain_group` from `domains.json`. The build fails with the name when an MCP tool later takes the same capability; then move the entry to `COMMANDS`. An entry is a name only: it grants nothing. The gap check `services/dfl-domain-api/src/commands/access/command-catalog.test.ts` (CAMP-T4) reads the capability of every command of dfl-domain-api, with no hand-kept list, and fails with the names when one is not in `capabilities.json`: a new command with no MCP tool of the same capability name needs one `COMMAND_ONLY` entry and `npm run catalog`. The kinds `table`, `rpc` and `function` come from the database surface (next section).
100
100
 
101
101
  ## The database surface in the catalog (S7-T4)
102
102
 
@@ -126,11 +126,15 @@ npm run catalog # builds capabilities.json from the tools manifest and th
126
126
 
127
127
  ## The principal: resolvePrincipal()
128
128
 
129
- `resolvePrincipal(reads, actorId)` builds the `Principal` of `can()` and returns the lines to pass in: the actor, its role bundles, and for an agent its owner (the delegator of its one active delegation), up to `MAX_OWNER_DEPTH` layers. It does no I/O: the caller passes four reads (`readActor`, `readActorRoles`, `readActorOwners`, `readLines`), each with the caller's own token. `dfl-os-commands` passes SQL in a caller transaction; the gateway passes PostgREST reads. One copy of the owner-chain rules for both (plan `20261116-fleet-access-s3-gateway-decision`, ADR-1).
129
+ `resolvePrincipal(reads, actorId)` builds the `Principal` of `can()` and returns the lines to pass in: the actor, its role bundles, and for an agent its owner (the delegator of its one active delegation), up to `MAX_OWNER_DEPTH` layers. It does no I/O: the caller passes four reads (`readActor`, `readActorRoles`, `readActorOwners`, `readLines`), each with the caller's own token. `dfl-domain-api` passes SQL in a caller transaction; the gateway passes PostgREST reads. One copy of the owner-chain rules for both (plan `20261116-fleet-access-s3-gateway-decision`, ADR-1).
130
+
131
+ ### Agent roles (0.3.0)
132
+
133
+ An agent gets a role through a line, not through `iam.user_roles` (S2-T5; Tainan Q `18e7e16f` = A; S9 ADR-5). An in-force **allow** line `agents.role.<role_id>` with scope `all` on an **agent** actor makes `<role_id>` one of its role ids, so the role lines (`principal_role_id = <role_id>`) apply to it. `resolvePrincipal(reads, actorId, now?)` reads those role lines with one more `readLines([], newRoleIds)`. A revoked, expired, deny, scoped or malformed line gives no role. A person or a service never gets a role this way. A line read through a role never adds a role (no nesting). The agent stays under its owner (agent ∩ owner). `agentRoleOf(line)` and `AGENT_ROLE_CAPABILITY_PREFIX` are exported. The pinned consumers (the gateway) get the rule when they bump the version.
130
134
 
131
135
  ## The parity fixture
132
136
 
133
- `parity.json` (shipped, `@devfellowship/access/parity.json`) holds one world (actors, role bundles, owners, permission lines) and the decision of each case. `expected` is the answer of `dfl-os-commands` `runExplain`. Three tests assert it: `test/parity.test.mjs` here, `services/dfl-os-commands/src/commands/access/parity.test.ts` (the service), and the gateway test in `dfl-mcp-server`. A change of a rule that moves an answer changes `parity.json` in the same PR.
137
+ `parity.json` (shipped, `@devfellowship/access/parity.json`) holds one world (actors, role bundles, owners, permission lines) and the decision of each case. `expected` is the answer of `dfl-domain-api` `runExplain`. Three tests assert it: `test/parity.test.mjs` here, `services/dfl-domain-api/src/commands/access/parity.test.ts` (the service), and the gateway test in `dfl-mcp-server`. A change of a rule that moves an answer changes `parity.json` in the same PR.
134
138
 
135
139
  ## Release
136
140
 
@@ -151,3 +155,5 @@ npm test
151
155
  ```
152
156
 
153
157
  Move the corpus: `npm run pin:runtime -- --definitions-commit <sha>`, then run the corpus on a checkout at that commit.
158
+
159
+ **Automatic refresh (CAT1).** `.github/workflows/catalog-refresh.yml` runs this refresh every 30 minutes and opens or updates one PR on `auto/catalog-refresh` when the two files differ from `main`. It reads prod as `schema_catalog_ro` (repo secret `SCHEMA_CATALOG_DB_URL`) and builds the schema list of the query from `config.toml` of dfl-schema `main` (`scripts/db-surface-query.mjs`), so the hard-coded list in `db-surface.sql` is only for a refresh by hand.