Merge build/107-agent-sources-and-skills: pinned Effect and Wrangler source, and four playbook skills
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by oscabriel · committed by oscabriel · parents f6da76a, 233ebe9 · Browse files · 9 files·+425 added−0 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
9 files+425 added−0 removed
- other:+425 added−0 removed
Provenance
- Commit
b8af4b1- Tree
1993cde- Author
oscabriel <oscarhernandeziv@gmail.com>- Committer
oscabriel <oscarhernandeziv@gmail.com>- Parent 1
f6da76a- Parent 2
233ebe9
9 files changed+425 added−0 removed
added:.agents/skills/add-check-kind/SKILL.md+80 added
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980---name: add-check-kinddescription: Playbook for adding a check kind, the shape an ask's check takes (redThenGreen, lintToZero, ratchet, migrate). Use when asks need a new way to judge an answer, or when changing how an existing kind runs or is classified.---
# Add a check kind
A check kind says what makes an ask's check red on main, what green for the right reason means, and which gamed answers it must refuse. It passes through five places: the schema, the builder maintainers call in their config folder, the runner, the gate's classification, and an example project.
A step marked "from W<n>" names a package a later build wave adds. If it is missing, stop at the last step whose files exist and say so in the report.
## 1. Define the kind
Write three concrete cases before any code:
- **red**: how the check fails on main, twice the same way, by an assertion or a count above zero (`GLOSSARY.md` "Red first");- **green**: what an answer changes that turns it green;- **gamed**: an answer that turns it green without the change, such as a null answer, a skipped test or a disabled rule.
Also list its inputs: the paths, commands, rules or counts a maintainer gives. A new kind is a new word: add it to `GLOSSARY.md`'s "Check kind" entry (the `domain-modeling` skill).
Done when each of the three cases is a small tree or recorded run you could commit as a fixture.
## 2. Add the schema member
Add a tagged member to `CheckSpec` in `packages/protocol/src/domain/check.ts` (from W2). Its fields are what the maintainer gives, never facts the platform derives. Wire fields follow AGENTS.md "Effect traps".
Done when a round-trip test of the new member in `packages/protocol/test/domain.test.ts` (from W2) passes, seen red first.
## 3. Add the builder
Add `check.<kind>(…)` to `packages/sdk/src/index.ts` (from W2), returning plain data. Test it in `packages/sdk/test/sdk.test.ts`: build a config that uses it, and decode the result with `Policy`.
Done when the decoded `Policy` holds the new `CheckSpec` member.
## 4. Run and classify it
In `packages/checks/src/` (from W2):
- the kind's helpers in `kinds.ts`, including its part of `checkVersion`. Verdicts are cached by tree and check version (principle 8), so a change to how a kind runs is a new version;- red first and the right reason in `classify.ts` (`redFirst`, `classifyRun`);- a static weak-shape check in `weakShapes` for each gamed case a check file can show.
Test each against step 1's fixtures: red on main is accepted, green is green for the right reason, and each gamed case is refused.
Done when every step 1 case has a passing test here.
## 5. Teach the gate
In `packages/gate/src/`:
- how a failure of this kind classifies in `classify.ts` (from W2): failed checks, a flake, a blocked verifier or a stale base;- if the kind counts something, its ratchet in `stages/ratchet.ts` (from W2);- if an answer could weaken it with a marker (a disable comment), that marker in `defaultMarkers` in `markers.ts` (from W4).
Done when gate tests cover the kind's classification, and each marker or ratchet it adds refuses a weakened answer with `Weakened`.
## 6. Show it in an example
Add an ask of this kind to an example project under `examples/` (from W5), in the project's config folder under `asks/`, with a check that is red on that project's main.
Done when the example's ask opens: its check is red on main twice the same way.
## 7. Regenerate the reference
Run `bun run gen`; the JSON Schema under `docs/reference/` gains the new member. Commit it.
Done when `bun run gen:check` passes.
## 8. Gate
`bun run fix`, then `bun run verify`; fix the cause, never weaken the fence.
## Report
- The kind, its inputs, and its red, green and gamed cases.- The `CheckSpec` member and the builder's signature.- How it is classified, its weak shapes and weakening markers, and how its check version changes.- The example ask, and whether it opened.- Each test added, and that each was seen red first; any step stopped at a missing later-wave package.added:.agents/skills/add-operation/SKILL.md+80 added
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980---name: add-operationdescription: Playbook for adding an operation, one contract the platform serves over RPC, MCP, the CLI and the web. Use when adding a contract, or when widening an existing contract's payload, success or refusals.---
# Add an operation
An operation is one contract: an `Rpc` in the one schema. Every surface is a projection of it (principle 4), so the work is the contract, its server logic and its tests; the surfaces follow from its annotations.
A step marked "from W<n>" names code a later build wave adds. If that path is missing, use the stand-in the step names and say so in the report. `Rpc` and `RpcGroup` source is in `node_modules/effect/src/rpc/`; for Effect's own tests and examples, run `bash scripts/vendor-agent-sources.sh` and read `.agent_sources/effect`.
## 1. Pin it in the group test
From W2, `packages/protocol/test/contracts.test.ts` pins every contract in a table: its tag in group order, its flags, audience and surfaces, and its error subset. Add the new contract's row there, and its example payload and success to `packages/protocol/test/contract-examples.ts` (both from W2; reuse the ids in `packages/protocol/test/examples.ts`). Run `npx vitest run test/contracts.test.ts` in `packages/protocol`.
Done when that test fails by an assertion that names the new tag. Before W2, `packages/protocol/test/annotations.test.ts` is the only group test: say so in the report.
## 2. Define the contract
- In `packages/protocol/src/contracts.ts`, write `export class <Name> extends Rpc.make("<tag>", { payload, success, error }) {}` and add it to `Contracts`' `RpcGroup.make(…)`. The tag is a camelCase verb: `listAsks`, `submitAnswer`.- Build the payload and the success from the branded ids in `packages/protocol/src/ids.ts` and the domain schemas in `packages/protocol/src/domain/` (from W2). The success is a `Schema.Struct`, because an MCP output schema needs an object at its root.- `error` is a `Schema.Union` of the refusals this contract can give, a subset of `Refusal` in `packages/protocol/src/refusal.ts`, so each handler stays exhaustive. A refusal the union lacks comes first, through the `add-refusal` skill. Leave out `Unauthenticated`: the `Authenticated` middleware adds it.- Every wire field follows AGENTS.md "Effect traps".
Done when `bun run typecheck` inside `packages/protocol` reports nothing but `Contracts.toLayer` calls that lack the new tag.
## 3. Annotate it
Each annotation in `packages/protocol/src/annotations.ts` is a `Context.Reference` with a default, set with `.annotate(Key, value)` on the `Rpc`:
- `Description`: one sentence in `GLOSSARY.md` words. Every surface shows it.- `Audience`: `public`, `signedIn` or `decider`. Only a `public` contract will answer a caller with no credential (from W3). `decider` only documents the rule: the logic checks the caller against the project's deciders and refuses with `NotDecider` (from W2), so list it in `error`.- `Visibility`: `maintainers` when the response may carry what a public reader must not see (principle 7). It only documents and keeps web caches off; the handler leaves those fields out for anyone who isn't a decider.- `ReadOnly`, `Idempotent` and `Destructive`, each set explicitly. MCP treats a tool without hints as destructive. A write is `Idempotent` only when a replay converges on the same result (principle 8): by a `RequestId`, as `submitAnswer` does, or by its nature, as a holder's re-claim returns the same claim.- `NeedsApproval` when a person must confirm. The CLI then asks for `--yes` (from W4).- `Cli` (its command name and positionals) and `Surfaces` (which of `rpc`, `mcp`, `cli` and `web` serve it). MCP is filtered by `Surfaces` from W2, and the CLI reads both from W4.
Done when `packages/protocol/test/annotations.test.ts` and step 1's test pass with the new contract in the group.
## 4. Write the server logic, then the handler
- The logic lives in the owning package, never in the app (principle 6): a method on `ProjectApi` in `packages/project/src/project.ts` (from W2), tested over `/memory` adapters in `packages/project/test/`. A read across every project comes from the front-page projection instead (from W3).- The handler in `apps/platform/src/handlers.ts` (from W3; until then `apps/platform/src/vacant.ts`) stays thin. It resolves the project, calls it, and fails only with the contract's own refusals.- `Contracts.toLayer` must name every tag, so each call gains a handler for the new one: the platform's, and the stand-ins tests build (as in `packages/protocol/test/mcp.test.ts`). `bun run typecheck` lists every call that lacks it.
Done when `bun run typecheck` passes and the logic's tests are green.
## 5. Check the projections
Projections live only in `packages/protocol/src/{cli,mcp}.ts` and `apps/*/src/surfaces.ts` (principle 4). They read the group and its annotations, so a new contract usually needs no edit there. Touch `apps/platform/src/surfaces.ts` or `apps/cli/src/surfaces.ts` only for what the group can't express, such as a stream's route.
Done when you can name each surface that serves the contract, and the annotation that put it there.
## 6. Test every surface it is on
Write each test red first: watch it fail by an assertion, then make it pass (the `tdd` skill).
- MCP: `tools/list` shows the tool with its hints, and `tools/call` returns its success and a refusal as typed JSON (`packages/protocol/test/mcp.test.ts`).- CLI: the command takes the payload as flags and prints the success (`packages/protocol/test/cli.test.ts`).- RPC: `apps/platform/test/surfaces.test.ts` calls it as the person a bearer token names.
Done when every surface in `Surfaces` has a test that fails without the contract.
## 7. Regenerate the reference
Run `bun run gen` and commit what it writes under `docs/reference/`. Those files come only from the schema; `gen:check` compares them with it.
Done when `bun run gen:check` passes.
## 8. Gate
`bun run fix`, then `bun run verify`; fix the cause, never weaken the fence.
## Report
- The contract's tag, payload, success and refusals.- Its annotations: audience, visibility, hints, approval, CLI name and surfaces.- Where its logic and its handler live, and any stand-in used for a later wave's path.- Each test added, and that each was seen red first.- The files `bun run gen` changed.added:.agents/skills/add-port/SKILL.md+71 added
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071---name: add-portdescription: Playbook for adding a port, the one job-named service an outside dependency enters through, with a memory adapter, real adapters and a shared contract suite. Use when code needs storage, a Cloudflare binding, a process, the network or another beta API, or when an existing port needs a new adapter.---
# Add a port
A port is the one place a dependency enters (principle 6): a job-named `Context.Service` in the package that owns the job, a `/memory` adapter for tests, real adapters beside it, and one contract suite every adapter passes. `RepoHost` is the reference. Read `packages/artifacts/src/repo-host.ts`, `packages/artifacts/src/repo-host/memory.ts` and `packages/artifacts/test/repo-host-contract.ts` before you start.
For a Workers binding's types and behaviour, run `bash scripts/vendor-agent-sources.sh` and read Wrangler and Miniflare in `.agent_sources/workers-sdk/packages/`.
## 1. Name the job and its owner
- Name the port for the job (`RepoHost`, `CheckRunner`, `Lander`), never for the vendor. Its Cloudflare resources carry job names too (principle 5).- Pick the one package that owns the job. Apps import packages, never the reverse (principle 6).- When a port for this job exists, add an adapter instead: go to step 3.
Done when you can name the owning package and the adapters the port needs.
## 2. Write the port
In `packages/<pkg>/src/<port>.ts`:
- `export class <Port> extends Context.Service<<Port>, { readonly <op>: (…) => Effect.Effect<A, E> }>()("<pkg>/<Port>") {}`;- its errors as `Schema.TaggedError` classes beside it, named for what went wrong in the job (`RepoNotFound`, `HostBusy`). Map the vendor's errors to them inside each adapter;- its values as Schemas or branded types, so a caller needs no vendor package to use it.
Keep the operations few and named for what callers need. Say in a doc comment what is idempotent and what is not atomic, as `RefOutcome` says a `RepoHost.push` is never atomic across refs.
Done when the port file imports no adapter.
## 3. Write the contract suite, one case at a time
In `packages/<pkg>/test/<port>-contract.ts`, export `describe<Port>(adapter, layer)`, as `describeRepoHost` does. Each case drives behaviour through the port only, so every adapter runs the same cases. For each case: write it, run it against the `/memory` adapter, watch it fail by an assertion, then make it pass (the `tdd` skill).
Done when the suite covers every operation, its errors included.
## 4. Write the adapters
- `/memory` in `packages/<pkg>/src/<port>/memory.ts` is a `Layer` over in-process state, deterministic and with no I/O (`RepoHostMemory = Layer.sync(RepoHost, make)`).- Real adapters sit beside it, named for their mechanism: `binding`, `rest`, `sqlite`, `local`, `isogit`, `worker`, `bun` or `json` (AGENTS.md "Nouns").- An adapter is Worker-safe unless its file is `local.ts` or `bun.ts`, or sits under a `local/` or `bun/` folder. Only those may import `node:child_process`, `@effect/platform-bun`, `@effect/platform-node` or OpenTUI. `bun run imports:check` follows Worker imports through package subpaths to hold this (rule `worker-host`).- Each adapter runs the suite from its own test file: `describe<Port>("<adapter>", <Layer>)`. An adapter for a live service also runs it against a fake built over the memory adapter, and against the real service only when an env flag opts in.
Done when every adapter passes the suite.
## 5. Export each adapter by its own subpath
- The package's `package.json` `exports` maps `./<port>` to `./src/<port>.ts` and `./<port>/<adapter>` to each adapter. From W2, a wildcard `"./*": "./src/*.ts"` entry covers new files.- Callers import the adapter they compose, as in `@repo/artifacts/repo-host/memory`. The port file never imports or re-exports an adapter; `bun run imports:check` refuses that (rule `adapter-through-port`).- An adapter that needs an unstable Effect module, such as `effect/sql` or `effect/process`, needs a per-path `allowedUnstableApis` override in `tsconfig.base.json`. Loosening it takes the user's sign-off (AGENTS.md "Fence").
Done when `bun run imports:check` passes.
## 6. Compose it
Provide the real adapter at the app's composition root (`apps/platform/src/platform.ts` for the platform Worker) and the memory adapter in tests.
Done when the app typechecks with the port provided and its tests pass.
## 7. Gate
`bun run fix`, then `bun run verify`; fix the cause, never weaken the fence.
## Report
- The port, its operations and errors, and the package that owns it.- Each adapter, its host (Worker, or Bun and Node), and its subpath.- The contract suite's cases, and which adapters ran it, live runs included or not.- Where it is composed.- Any `allowedUnstableApis` or dependency change, with its sign-off.added:.agents/skills/add-refusal/SKILL.md+76 added
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576---name: add-refusaldescription: Playbook for adding a refusal, a member of the closed union the platform answers with instead of landing or acting. Use when a contract, a gate stage or the git gateway needs a new way to say no, or when changing an existing refusal's fields.---
# Add a refusal
Refusals are a closed union and a public contract (principle 3). Harnesses match on `_tag`, read `retryable` and run `next`, so a new member is cheap and a changed one breaks callers. A `_tag` is renamed only with an alias: keep the old tag decoding beside the new one. No alias exists yet, so the first rename designs it, with a test that the old tag still decodes.
A step marked "from W<n>" names code a later build wave adds.
## 1. Name it
- Read the union in `packages/protocol/src/refusal.ts`. Reuse a member when one already says it.- Name the tag in PascalCase, in `GLOSSARY.md` words (`StaleBase`, `OutOfScope`).- Pick its group: the comment-headed block it joins, and its entry in `groups`. Shape refusals accumulate, so one push hears every one at once. A new group is a new block and a new `groups` entry.- Decide whether retrying the same thing can succeed later (`RepoBusy` can, `OutOfScope` can't), and which `<cli>` or `git` command the reader runs next.
Done when you can write its one-line doc comment and its `next` command.
## 2. Pin it in the closed-union test
Add the tag and its `retryable` to the table in `packages/protocol/test/refusal.test.ts` that says the union is closed. Run `npx vitest run test/refusal.test.ts` in `packages/protocol`.
Done when that test fails by an assertion that names the new tag.
## 3. Add the class
In `packages/protocol/src/refusal.ts`:
- `export class <Tag> extends Schema.TaggedError<<Tag>>()("<Tag>", { … }) {}`, with a doc comment in glossary words.- Spread `...Retryable` or `...Final`. Either fixes `retryable` for the tag and adds the optional `at` (a path and a line). `retryable` and `next` are fields, not statics, because Effect's MCP server sends only what the schema encodes.- `next`: spread `...nextIs(cli("<command>"))` when the command needs no ids. Otherwise add a `static readonly of` that builds it from them, as `NotClaimed.of(ask)` does. `cli()` takes the command name from `Brand`.- Leave out `message`. Without one, MCP sends the encoded JSON.- Give it only fields its reader may see (principle 7). A held-back check names its area and suite, never a case or an input. Wire fields follow AGENTS.md "Effect traps".- Add it to its group's array, which puts it in the `Refusal` union in the same position.
Done when the only typecheck error in `packages/protocol` is the missing reason in `render.ts`.
## 4. Render it
Add its reason to `reason` in `packages/protocol/src/render.ts`: a lowercase clause, shown on git's `remote:` lines, in the CLI and in MCP text. `protocol/render` is the one renderer, and `Match.typeTags` makes typecheck name a missing reason.
Done when `bun run typecheck` inside `packages/protocol` passes.
## 5. Add its example
Add one instance to `examples` in `packages/protocol/test/examples.ts`, in union order. The round-trip, render and group tests then cover it.
Done when every test in `packages/protocol` passes, step 2's included.
## 6. Give it to its contracts and its raisers
- Add it to the `error` union of every contract in `packages/protocol/src/contracts.ts` that can give it, and list them in the report.- Raise it where the decision is made: a gate stage in `packages/gate/src/stages/` (from W2), the gateway in `packages/git/src/gateway.ts`, or a contract's logic.- Give each raiser a test that produces the refusal, red first.
Done when each contract that lists it has a path that raises it, and a test for that path.
## 7. Regenerate the reference
Run `bun run gen`, which rewrites `docs/reference/refusals.md` from the union, and commit it.
Done when `bun run gen:check` passes.
## 8. Gate
`bun run fix`, then `bun run verify`; fix the cause, never weaken the fence.
## Report
- The tag, its group, `retryable`, `next` and its fields.- Its reason as rendered.- Every contract whose error union gained it, and every place that raises it.- Each test added, and that each was seen red first.- Whether `docs/reference/refusals.md` changed, and any tag renamed (with its alias).added:.claude/skills/add-check-kind/SKILL.md+1 added
1../../../.agents/skills/add-check-kind/SKILL.mdNo newline at end of fileadded:.claude/skills/add-operation/SKILL.md+1 added
1../../../.agents/skills/add-operation/SKILL.mdNo newline at end of fileadded:.claude/skills/add-port/SKILL.md+1 added
1../../../.agents/skills/add-port/SKILL.mdNo newline at end of fileadded:.claude/skills/add-refusal/SKILL.md+1 added
1../../../.agents/skills/add-refusal/SKILL.mdNo newline at end of fileadded:scripts/vendor-agent-sources.sh+114 added
1+#!/usr/bin/env bash2+# Ported from joelhooks/rat-stack@fba26d8 `scripts/vendor-agent-sources.sh`3+# (MIT, LICENSES/rat-stack.MIT.txt). Changes are listed in PROVENANCE.md.4+#5+# Clones the exact source of the Effect and Wrangler versions this repo pins6+# into .agent_sources/<repo>, for agents to read as API truth. Reference only:7+# nothing imports it, and .gitignore keeps it out of git.8+#9+# bash scripts/vendor-agent-sources.sh # clone what is missing or moved10+# bash scripts/vendor-agent-sources.sh --refresh # clone both again11+set -euo pipefail12+13+ROOT="$(cd "$(dirname "$0")/.." && pwd)"14+SOURCES="${ROOT}/.agent_sources"15+REFRESH=false16+17+for arg in "$@"; do18+ case "$arg" in19+ --refresh) REFRESH=true ;;20+ -h | --help)21+ echo "Usage: $0 [--refresh]"22+ echo "Clones pinned Effect and workers-sdk source into .agent_sources/."23+ exit 024+ ;;25+ *)26+ echo "Unknown arg: $arg" >&227+ exit 128+ ;;29+ esac30+done31+32+# One field of a JSON file, or an empty line when it is absent.33+json_field() {34+ node -p 'const v = require(process.argv[1]); process.argv[2].split(".").reduce((o, k) => (o == null ? undefined : o[k]), v) ?? ""' "$1" "$2"35+}36+37+# The version a package.json pins, refused unless it is one exact version.38+pin() {39+ local file="$1" field="$2" version40+ version="$(json_field "${ROOT}/${file}" "$field")"41+42+ if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then43+ echo "${file} ${field} is '${version}', not one exact version; pin it before vendoring." >&244+ exit 145+ fi46+47+ echo "$version"48+}49+50+# clone_source <repo> <remote> <tag> <package.json in the clone> <version> <note>51+clone_source() {52+ local repo="$1" remote="$2" ref="$3" manifest="$4" version="$5" note="$6"53+ local dest="${SOURCES}/${repo}"54+ local metadata="${dest}/.agent-source.json"55+ local commit cloned56+57+ # The metadata is written last, so its presence marks a finished clone.58+ if [[ "$REFRESH" != true && -f "$metadata" ]]; then59+ if [[ "$(json_field "$metadata" ref)" == "$ref" ]]; then60+ echo "skip ${repo} @ ${ref} (present; pass --refresh to clone again)"61+ return 062+ fi63+64+ echo "${repo}: the pin moved to ${ref}; cloning again"65+ fi66+67+ if ! git ls-remote --exit-code --refs "$remote" "refs/tags/${ref}" >/dev/null; then68+ echo "Cannot resolve tag ${ref} at ${remote}; refusing to fall back to another ref." >&269+ exit 170+ fi71+72+ rm -rf "$dest"73+ mkdir -p "$SOURCES"74+ echo "clone ${repo} @ ${ref}"75+ # For an annotated tag, git warns that it "is not a commit"; the checkout is76+ # still the commit the tag points at.77+ git -c advice.detachedHead=false clone --quiet --depth 1 --branch "$ref" "$remote" "$dest"78+ commit="$(git -C "$dest" rev-parse HEAD)"79+80+ cloned="$(json_field "${dest}/${manifest}" version)"81+ if [[ "$cloned" != "$version" ]]; then82+ rm -rf "$dest"83+ echo "${repo} @ ${ref} has ${manifest} at version '${cloned}', not ${version}; refusing it." >&284+ exit 185+ fi86+87+ cat >"$metadata" <<EOF88+{89+ "type": "git-source",90+ "repo": "${repo}",91+ "remote": "${remote}",92+ "ref": "${ref}",93+ "commit": "${commit}",94+ "version": "${version}",95+ "addedAt": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")",96+ "note": "${note} Refresh: bash scripts/vendor-agent-sources.sh --refresh"97+}98+EOF99+100+ echo " -> ${dest} (${commit})"101+}102+103+# The pins come from the package.json files, so a bump there is a bump here.104+EFFECT_VERSION="$(pin package.json workspaces.catalog.effect)"105+WRANGLER_VERSION="$(pin apps/platform/package.json devDependencies.wrangler)"106+107+clone_source effect https://github.com/Effect-TS/effect.git "effect@${EFFECT_VERSION}" \108+ packages/effect/package.json "$EFFECT_VERSION" \109+ "Effect v4 matching the root catalog's effect@${EFFECT_VERSION}."110+clone_source workers-sdk https://github.com/cloudflare/workers-sdk.git "wrangler@${WRANGLER_VERSION}" \111+ packages/wrangler/package.json "$WRANGLER_VERSION" \112+ "Wrangler and Miniflare matching apps/platform's wrangler@${WRANGLER_VERSION}."113+114+echo "done: agent sources under ${SOURCES}"