Skip to content
Myr

Hold the generators' goldens to a renamed brand, and call a skill copy with its frontmatter taken off stale

Before adoption: this commit came in with the history the project adopted, so no landing records it.

- Golden files hold `sha256:__HASH__` where a content hash stood: each hash covers text that spells the brand, so a random rename (principle 5, the acceptance script) failed all seven generator goldens. Reproduced with a temporary rename; with the placeholder they pass under it. - What the literal hex pinned is now a named behaviour: every SKILL.md records the SHA-256 of its own body, and the AGENTS.md block's first marker carries its body's SHA-256 exactly (the test only matched the shape before). Both fail on a planted wrong hash. Well-known digests stay literal: their input spells no brand. - isStale: a copy without frontmatter is current only when it is the current file's exact text. Before, a bare body matched the current file's recorded hash and read as fresh, though a harness won't load it as a skill. Tests: a stripped copy is Some; a generated file without frontmatter compares as it stands. - contributeSkillPaths returns a typed pair, so the AGENTS.md block needs no `?? ""`; command-doc's stand-ins are a set of command names (the map's values were never read).

authored by oscabriel · committed by oscabriel · parent 49256fe · Browse files · 15 files+130 added−39 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

15 files+130 added−39 removed

  • tests:+103 added−19 removed
  • other:+27 added−20 removed

15 files+130 added−39 removed

modified:packages/agent-kit/src/agents-block.ts+1 added-1 removed
modified:packages/agent-kit/src/command-doc.ts+6 added-3 removed
161 unmodified lines
162 summary: "Print the JSON Schema of a command's payload.",163 },164];165166/** The contracts a local command calls in their place, by the command's name. */167const standIns = new Map(166/**167 * The names of the local commands that call a contract: a contract whose168 * CLI name is one of them is that command, so it gets no row of its own.169 */170const standIns = new Set(171 localCommandDocs.flatMap(({ contract, path }) =>169 contract === undefined ? [] : [[path.join(" "), contract] as const]172 contract === undefined ? [] : [path.join(" ")]173 )174);175176/** A payload's field names, in the schema's order; none for a payload of no fields. */
56 unmodified lines
modified:packages/agent-kit/src/generated-file.ts+14 added-11 removed
147 unmodified lines
148 * its body hashes to something other than what it records (edited by hand),149 * or what it records is not the current body's hash (generated from other150 * text). The landing alone never makes a copy stale: a landing that left151 * the text alone leaves the copy current. Some names the copy's own landing152 * and recorded hash; a copy without the frontmatter has no landing, and its153 * hash is the whole file's.152 * and recorded hash. A copy without the frontmatter has no landing, and its153 * hash is the whole file's: it is current only when the current file has no154 * frontmatter either and the two are the same text, so a copy whose155 * frontmatter was taken off is stale.156 */157export const isStale = (158 onDisk: string,159 current: GeneratedFile
3 unmodified lines
163 readonly hash: string;164 }>165> =>166 Effect.gen(function* () {165 const wanted = yield* Option.match(readManaged(current.content), {166 onNone: () => contentHash(current.content),167 onSome: ({ hash }) => Effect.succeed(hash),168 });169167 const copy = readManaged(onDisk);168169 if (Option.isNone(copy)) {173 const hash = yield* contentHash(onDisk);174175 return hash === wanted170 return onDisk === current.content171 ? Option.none()177 : Option.some({ hash, landed: Option.none() });172 : Option.some({173 hash: yield* contentHash(onDisk),174 landed: Option.none(),175 });176 }177178 const wanted = yield* Option.match(readManaged(current.content), {179 onNone: () => contentHash(current.content),180 onSome: ({ hash }) => Effect.succeed(hash),181 });182183 const { body, hash, landed } = copy.value;184 const actual = yield* contentHash(body);185186 return actual === hash && hash === wanted
3 unmodified lines
modified:packages/agent-kit/src/project-skill.ts+6 added-5 removed
24 unmodified lines
25/** The skill's name: `<project>-contribute`, its folder's name too. */26export const contributeSkillName = (project: ProjectName) =>27 `${project}-contribute`;2829/** Where the skill goes: the folders harnesses read project skills from. */30export const contributeSkillPaths = (project: ProjectName) =>31 [".agents", ".claude"].map(32 (root) => `${root}/skills/${contributeSkillName(project)}/SKILL.md`33 );29/** Where the skill goes: the folders harnesses read project skills from, `.agents` first. */30export const contributeSkillPaths = (project: ProjectName) => {31 const skill = `skills/${contributeSkillName(project)}/SKILL.md`;3233 return [`.agents/${skill}`, `.claude/${skill}`] as const;34};3536/** What the skill's frontmatter says it is for. */37export const contributeDescription = (project: ProjectName) =>38 `Answer one of ${project}'s asks on ${Brand.name}: claim it, change only its territory, run \`${Brand.cli} check\`, push it to your fork, and read the verdict. Use when working on ${project}, or when a push to it was refused.`;39
41 unmodified lines
modified:packages/agent-kit/test/golden/agent-plugins-stdio.txt+1 added-1 removed
9 unmodified lines
10name: __SLUG__11description: "Contribute to projects on __NAME__ with the `__SLUG__` CLI: find an ask, claim it, check your answer locally, push it to your fork, and read the verdict. Use when a repo's remote is on __NAME__, or when a push was refused with a refusal such as OutOfScope or StaleBase."12metadata:13 managed-by: "__SLUG__"14 content-hash: "sha256:8a8ea9eed71ff4e3bf0de80fce9b559d693e027826022b91151ba8aae2a375c1"14 content-hash: "sha256:__HASH__"15---16# __NAME__1718__NAME__ is a git platform where a change lands only by passing a typed gate. A project states each change it wants as an ask; you answer one with a commit pushed to your claim's fork, and the platform checks it and lands it, or answers with refusals that say what to do next.
79 unmodified lines
modified:packages/agent-kit/test/golden/agent-plugins.txt+1 added-1 removed
10 unmodified lines
11name: __SLUG__12description: "Contribute to projects on __NAME__ with the `__SLUG__` CLI: find an ask, claim it, check your answer locally, push it to your fork, and read the verdict. Use when a repo's remote is on __NAME__, or when a push was refused with a refusal such as OutOfScope or StaleBase."13metadata:14 managed-by: "__SLUG__"15 content-hash: "sha256:64e2711bd027ebf274c67139c56f14d73128ffe058c57609223d3e39c08fabd3"15 content-hash: "sha256:__HASH__"16---17# __NAME__1819__NAME__ is a git platform where a change lands only by passing a typed gate. A project states each change it wants as an ask; you answer one with a commit pushed to your claim's fork, and the platform checks it and lands it, or answers with refusals that say what to do next.
76 unmodified lines
modified:packages/agent-kit/test/golden/agents-block.txt+1 added-1 removed
1==> AGENTS.md <==2<!-- BEGIN __SLUG__ contribute (generated; content-hash: sha256:8bc87e18feaa6e1f6a121ec99a78a92f3edaa1fdc2eead4181dee67ee60b7b71) -->2<!-- BEGIN __SLUG__ contribute (generated; content-hash: sha256:__HASH__) -->3## Contributing to datekit45This project takes changes through __NAME__: an answer to one of its asks lands only by passing the gate. This block is generated from the config folder, and the gate decides what lands. The full guide is the `datekit-contribute` skill (`.agents/skills/datekit-contribute/SKILL.md`).6
17 unmodified lines
modified:packages/agent-kit/test/golden/claude-plugin-stdio.txt+1 added-1 removed
8 unmodified lines
9name: __SLUG__10description: "Contribute to projects on __NAME__ with the `__SLUG__` CLI: find an ask, claim it, check your answer locally, push it to your fork, and read the verdict. Use when a repo's remote is on __NAME__, or when a push was refused with a refusal such as OutOfScope or StaleBase."11metadata:12 managed-by: "__SLUG__"13 content-hash: "sha256:8a8ea9eed71ff4e3bf0de80fce9b559d693e027826022b91151ba8aae2a375c1"13 content-hash: "sha256:__HASH__"14---15# __NAME__1617__NAME__ is a git platform where a change lands only by passing a typed gate. A project states each change it wants as an ask; you answer one with a commit pushed to your claim's fork, and the platform checks it and lands it, or answers with refusals that say what to do next.
114 unmodified lines
modified:packages/agent-kit/test/golden/claude-plugin.txt+1 added-1 removed
9 unmodified lines
10name: __SLUG__11description: "Contribute to projects on __NAME__ with the `__SLUG__` CLI: find an ask, claim it, check your answer locally, push it to your fork, and read the verdict. Use when a repo's remote is on __NAME__, or when a push was refused with a refusal such as OutOfScope or StaleBase."12metadata:13 managed-by: "__SLUG__"14 content-hash: "sha256:64e2711bd027ebf274c67139c56f14d73128ffe058c57609223d3e39c08fabd3"14 content-hash: "sha256:__HASH__"15---16# __NAME__1718__NAME__ is a git platform where a change lands only by passing a typed gate. A project states each change it wants as an ask; you answer one with a commit pushed to your claim's fork, and the platform checks it and lands it, or answers with refusals that say what to do next.
112 unmodified lines
modified:packages/agent-kit/test/golden/platform-skill.txt+1 added-1 removed
2 unmodified lines
3name: __SLUG__4description: "Contribute to projects on __NAME__ with the `__SLUG__` CLI: find an ask, claim it, check your answer locally, push it to your fork, and read the verdict. Use when a repo's remote is on __NAME__, or when a push was refused with a refusal such as OutOfScope or StaleBase."5metadata:6 managed-by: "__SLUG__"7 content-hash: "sha256:64e2711bd027ebf274c67139c56f14d73128ffe058c57609223d3e39c08fabd3"7 content-hash: "sha256:__HASH__"8---9# __NAME__1011__NAME__ is a git platform where a change lands only by passing a typed gate. A project states each change it wants as an ask; you answer one with a commit pushed to your claim's fork, and the platform checks it and lands it, or answers with refusals that say what to do next.
65 unmodified lines
modified:packages/agent-kit/test/golden/project-skill.txt+2 added-2 removed
3 unmodified lines
4description: "Answer one of datekit's asks on __NAME__: claim it, change only its territory, run `__CLI__ check`, push it to your fork, and read the verdict. Use when working on datekit, or when a push to it was refused."5metadata:6 managed-by: "__SLUG__"7 landed: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"8 content-hash: "sha256:46fa2ac0a9b213b2e9a5f9a1c3e54246809e6c2326fc80c97a0881034932e369"8 content-hash: "sha256:__HASH__"9---10# Contribute to datekit1112How to answer datekit's asks on __NAME__. It is generated from datekit's config folder: the gate decides what lands, and where this text and the gate differ, the gate wins. Don't edit it by hand; it is regenerated when the config changes.
102 unmodified lines
115description: "Answer one of datekit's asks on __NAME__: claim it, change only its territory, run `__CLI__ check`, push it to your fork, and read the verdict. Use when working on datekit, or when a push to it was refused."116metadata:117 managed-by: "__SLUG__"118 landed: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"119 content-hash: "sha256:46fa2ac0a9b213b2e9a5f9a1c3e54246809e6c2326fc80c97a0881034932e369"119 content-hash: "sha256:__HASH__"120---121# Contribute to datekit122123How to answer datekit's asks on __NAME__. It is generated from datekit's config folder: the gate decides what lands, and where this text and the gate differ, the gate wins. Don't edit it by hand; it is regenerated when the config changes.
98 unmodified lines
modified:packages/agent-kit/test/agents-block.test.ts+5 added-5 removed
1 unmodified line
2import { Brand } from "@repo/brand";3import { Effect } from "effect";45import { agentsBlock, upsertAgentsBlock } from "../src/agents-block.ts";6import { contentHash } from "../src/generated-file.ts";7import {8 landed,9 later,10 policy,
76 unmodified lines
87 "brackets its body between markers, the first carrying the body's hash",88 () =>89 Effect.gen(function* () {90 const generated = yield* agentsBlock({ landed, policy, project });91 const hash = yield* contentHash(generated.body);9291 expect(generated.begin).toMatch(92 new RegExp(93 `^<!-- BEGIN ${Brand.slug} contribute \\(generated; content-hash: sha256:[0-9a-f]{64}\\) -->$`,94 "u"95 )93 expect(hash).toMatch(/^sha256:[0-9a-f]{64}$/u);94 expect(generated.begin).toBe(95 `<!-- BEGIN ${Brand.slug} contribute (generated; content-hash: ${hash}) -->`96 );97 expect(generated.end).toBe(end);98 expect(generated.body).toContain(`${Brand.cli} check`);99 })
21 unmodified lines
modified:packages/agent-kit/test/generate.test.ts+34 added
2 unmodified lines
3import { Brand } from "@repo/brand";4import { Effect, Schema } from "effect";56import { agentsBlock, upsertAgentsBlock } from "../src/agents-block.ts";7import { contentHash } from "../src/generated-file.ts";8import type { GeneratedFile } from "../src/generated-file.ts";9import type { HookEvent } from "../src/hook-events.ts";10import { claudeEventOf } from "../src/hook-events.ts";11import {
138 unmodified lines
150 ),151 };152};153154/** A Markdown file's body: everything after its frontmatter's closing line. */155const bodyOf = (content: string) => {156 const close = content.indexOf("\n---\n", 3);157158 return close === -1 ? content : content.slice(close + "\n---\n".length);159};160161/** The hash a file's frontmatter records, read with a pattern of its own. */162const recordedHash = (content: string) =>163 /^ {2}content-hash: "(?<hash>sha256:[0-9a-f]{64})"$/mu.exec(content)?.groups164 ?.hash ?? "";165166/** The hook entry that runs `<cli> hook <event> --json`. */167const hookCommand = (event: HookEvent) => [168 { command: `${Brand.cli} hook ${event} --json`, type: "command" },169];
78 unmodified lines
248 );249 })250 );251252 it.effect("records the SHA-256 of its own body", () =>253 Effect.gen(function* () {254 const files = yield* skills;255256 expect(files.length).toBeGreaterThan(0);257258 const computed = yield* Effect.forEach(files, ({ content, path }) =>259 contentHash(bodyOf(content)).pipe(260 Effect.map((hash) => ({ hash, path }))261 )262 );263264 expect(265 files.map(({ content, path }) => ({266 hash: recordedHash(content),267 path,268 }))269 ).toStrictEqual(computed);270 })271 );272273 it.effect("names the landing it came from when it came from one", () =>274 Effect.gen(function* () {275 const [contribute] = yield* projectSkill({ landed, policy, project });276 const [own] = yield* platformSkill({ commands });
150 unmodified lines
modified:packages/agent-kit/test/golden.ts+17 added-6 removed
1/**2 * Golden files for the generators: each generator's files in one3 * `test/golden/<name>.txt`, with the product's name as placeholders so no4 * golden file spells it (`brand:check`) and a renamed brand still matches.5 * A `content-hash` covers text that spells the name, so it changes with the6 * brand: the golden file holds `__HASH__` there, and the generator tests7 * hold each recorded hash to its body instead. `UPDATE_GOLDEN=1` rewrites5 * `UPDATE_GOLDEN=1` rewrites them; read the diff before committing it.8 * them; read the diff before committing it.9 */10import { expect } from "@effect/vitest";11import { Brand } from "@repo/brand";12import { Config, Effect, FileSystem } from "effect";
20 unmodified lines
33 .replaceAll("__NAME__", Brand.name)34 .replaceAll("__CLI__", Brand.cli)35 .replaceAll("__SLUG__", Brand.slug);3637// The hex of a frontmatter's `content-hash: "sha256:…"` or an AGENTS.md38// marker's `content-hash: sha256:…`.39const HASH = /(?<=content-hash: "?sha256:)[0-9a-f]{64}/gu;4041/** Generated text with each content hash as `__HASH__`. */42const unhashed = (text: string) => text.replaceAll(HASH, "__HASH__");4334/** Generated text as a golden file holds it: the brand as placeholders. */44/** Generated text as a golden file holds it: the brand and hashes as placeholders. */45const unbranded = (text: string) =>36 text46 unhashed(text)47 .replaceAll(NAME, "__NAME__")48 .replaceAll(CLI, "__CLI__")49 .replaceAll(SLUG, "__SLUG__");50
1 unmodified line
52export const transcript = (files: readonly GeneratedFile[]) =>53 files.map(({ content, path }) => `==> ${path} <==\n${content}`).join("\n");5455/**46 * Asserts that `actual` is `test/golden/<name>.txt` with its placeholders47 * filled in, byte for byte. Under `UPDATE_GOLDEN=1` it writes the file.56 * Asserts that `actual`, with its content hashes as `__HASH__`, is57 * `test/golden/<name>.txt` with its brand placeholders filled in, byte for58 * byte. Under `UPDATE_GOLDEN=1` it writes the file.59 */60export const expectGolden = (name: string, actual: string) =>61 Effect.gen(function* () {62 const fs = yield* FileSystem.FileSystem;
18 unmodified lines
81 ).toBe(true);8283 const golden = yield* fs.readFileString(file);8474 expect(actual).toBe(branded(golden));85 expect(unhashed(actual)).toBe(branded(golden));86 }).pipe(Effect.orDie);
modified:packages/agent-kit/test/stale.test.ts+39 added
190 unmodified lines
191 Option.some({ hash: helloDigest, landed: Option.none() })192 );193 })194 );195196 it.effect(197 "is Some for a copy whose frontmatter was taken off, though its body is current",198 () =>199 Effect.gen(function* () {200 const current = yield* contributeSkill({ landed, policy });201202 const body = Option.map(203 readManaged(current.content),204 (managed) => managed.body205 );206207 expect(Option.isSome(body)).toBeTruthy();208209 const bare = Option.getOrElse(body, () => "");210211 expect(yield* isStale(bare, current)).toStrictEqual(212 Option.some({213 hash: recordedHash(current.content),214 landed: Option.none(),215 })216 );217 })218 );219220 it.effect(221 "compares a file the generators give without frontmatter as it stands",222 () =>223 Effect.gen(function* () {224 const current = { content: "# Ours\n", path: "AGENTS.md" };225226 expect(yield* isStale("# Ours\n", current)).toStrictEqual(227 Option.none()228 );229 expect(yield* isStale("hello\n", current)).toStrictEqual(230 Option.some({ hash: helloDigest, landed: Option.none() })231 );232 })233 );234});