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).
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
Provenance
- Commit
bbaded6- Tree
f042225- Author
oscabriel <oscarhernandeziv@gmail.com>- Committer
oscabriel <oscarhernandeziv@gmail.com>- Parent
49256fe
15 files changed+130 added−39 removed
modified:packages/agent-kit/src/agents-block.ts+1 added-1 removed
50 unmodified lines5152535455555657585973 unmodified lines50 unmodified lines
return page([ `## Contributing to ${project}`, "", `This project takes changes through ${Brand.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 ${code(contributeSkillName(project))} skill (${code(agentsPath ?? "")}).`, `This project takes changes through ${Brand.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 ${code(contributeSkillName(project))} skill (${code(agentsPath)}).`, "", ...loopSteps(), "", ...rules(policy),73 unmodified linesmodified:packages/agent-kit/src/command-doc.ts+6 added-3 removed
161 unmodified lines162 summary: "Print the JSON Schema of a command's payload.",163 },164 ];165 166-/** The contracts a local command calls in their place, by the command's name. */167-const 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+ */170+const standIns = new Set(171 localCommandDocs.flatMap(({ contract, path }) =>169- contract === undefined ? [] : [[path.join(" "), contract] as const]172+ contract === undefined ? [] : [path.join(" ")]173 )174 );175 176 /** A payload's field names, in the schema's order; none for a payload of no fields. */56 unmodified linesmodified:packages/agent-kit/src/generated-file.ts+14 added-11 removed
147 unmodified lines148 * 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 */157 export const isStale = (158 onDisk: string,159 current: GeneratedFile3 unmodified lines163 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- });169-167 const copy = readManaged(onDisk);168 169 if (Option.isNone(copy)) {173- const hash = yield* contentHash(onDisk);174-175- 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 }177 178+ const wanted = yield* Option.match(readManaged(current.content), {179+ onNone: () => contentHash(current.content),180+ onSome: ({ hash }) => Effect.succeed(hash),181+ });182+183 const { body, hash, landed } = copy.value;184 const actual = yield* contentHash(body);185 186 return actual === hash && hash === wanted3 unmodified linesmodified:packages/agent-kit/src/project-skill.ts+6 added-5 removed
24 unmodified lines25 /** The skill's name: `<project>-contribute`, its folder's name too. */26 export const contributeSkillName = (project: ProjectName) =>27 `${project}-contribute`;28 29-/** Where the skill goes: the folders harnesses read project skills from. */30-export 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. */30+export const contributeSkillPaths = (project: ProjectName) => {31+ const skill = `skills/${contributeSkillName(project)}/SKILL.md`;32 33+ return [`.agents/${skill}`, `.claude/${skill}`] as const;34+};35+36 /** What the skill's frontmatter says it is for. */37 export 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 linesmodified:packages/agent-kit/test/golden/agent-plugins-stdio.txt+1 added-1 removed
9 unmodified lines10 name: __SLUG__11 description: "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."12 metadata:13 managed-by: "__SLUG__"14- content-hash: "sha256:8a8ea9eed71ff4e3bf0de80fce9b559d693e027826022b91151ba8aae2a375c1"14+ content-hash: "sha256:__HASH__"15 ---16 # __NAME__17 18 __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 linesmodified:packages/agent-kit/test/golden/agent-plugins.txt+1 added-1 removed
10 unmodified lines11 name: __SLUG__12 description: "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."13 metadata:14 managed-by: "__SLUG__"15- content-hash: "sha256:64e2711bd027ebf274c67139c56f14d73128ffe058c57609223d3e39c08fabd3"15+ content-hash: "sha256:__HASH__"16 ---17 # __NAME__18 19 __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 linesmodified: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 datekit4 5 This 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 linesmodified:packages/agent-kit/test/golden/claude-plugin-stdio.txt+1 added-1 removed
8 unmodified lines9 name: __SLUG__10 description: "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."11 metadata:12 managed-by: "__SLUG__"13- content-hash: "sha256:8a8ea9eed71ff4e3bf0de80fce9b559d693e027826022b91151ba8aae2a375c1"13+ content-hash: "sha256:__HASH__"14 ---15 # __NAME__16 17 __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 linesmodified:packages/agent-kit/test/golden/claude-plugin.txt+1 added-1 removed
9 unmodified lines10 name: __SLUG__11 description: "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."12 metadata:13 managed-by: "__SLUG__"14- content-hash: "sha256:64e2711bd027ebf274c67139c56f14d73128ffe058c57609223d3e39c08fabd3"14+ content-hash: "sha256:__HASH__"15 ---16 # __NAME__17 18 __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 linesmodified:packages/agent-kit/test/golden/platform-skill.txt+1 added-1 removed
2 unmodified lines3 name: __SLUG__4 description: "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."5 metadata:6 managed-by: "__SLUG__"7- content-hash: "sha256:64e2711bd027ebf274c67139c56f14d73128ffe058c57609223d3e39c08fabd3"7+ content-hash: "sha256:__HASH__"8 ---9 # __NAME__10 11 __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 linesmodified:packages/agent-kit/test/golden/project-skill.txt+2 added-2 removed
3 unmodified lines4 description: "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."5 metadata:6 managed-by: "__SLUG__"7 landed: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"8- content-hash: "sha256:46fa2ac0a9b213b2e9a5f9a1c3e54246809e6c2326fc80c97a0881034932e369"8+ content-hash: "sha256:__HASH__"9 ---10 # Contribute to datekit11 12 How 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 lines115 description: "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."116 metadata:117 managed-by: "__SLUG__"118 landed: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"119- content-hash: "sha256:46fa2ac0a9b213b2e9a5f9a1c3e54246809e6c2326fc80c97a0881034932e369"119+ content-hash: "sha256:__HASH__"120 ---121 # Contribute to datekit122 123 How 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 linesmodified:packages/agent-kit/test/agents-block.test.ts+5 added-5 removed
1 unmodified line2 import { Brand } from "@repo/brand";3 import { Effect } from "effect";4 5 import { agentsBlock, upsertAgentsBlock } from "../src/agents-block.ts";6+import { contentHash } from "../src/generated-file.ts";7 import {8 landed,9 later,10 policy,76 unmodified lines87 "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);92 91- 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 linesmodified:packages/agent-kit/test/generate.test.ts+34 added
2 unmodified lines3 import { Brand } from "@repo/brand";4 import { Effect, Schema } from "effect";5 6 import { agentsBlock, upsertAgentsBlock } from "../src/agents-block.ts";7+import { contentHash } from "../src/generated-file.ts";8 import type { GeneratedFile } from "../src/generated-file.ts";9 import type { HookEvent } from "../src/hook-events.ts";10 import { claudeEventOf } from "../src/hook-events.ts";11 import {138 unmodified lines150 ),151 };152 };153 154+/** A Markdown file's body: everything after its frontmatter's closing line. */155+const bodyOf = (content: string) => {156+ const close = content.indexOf("\n---\n", 3);157+158+ return close === -1 ? content : content.slice(close + "\n---\n".length);159+};160+161+/** The hash a file's frontmatter records, read with a pattern of its own. */162+const recordedHash = (content: string) =>163+ /^ {2}content-hash: "(?<hash>sha256:[0-9a-f]{64})"$/mu.exec(content)?.groups164+ ?.hash ?? "";165+166 /** The hook entry that runs `<cli> hook <event> --json`. */167 const hookCommand = (event: HookEvent) => [168 { command: `${Brand.cli} hook ${event} --json`, type: "command" },169 ];78 unmodified lines248 );249 })250 );251 252+ it.effect("records the SHA-256 of its own body", () =>253+ Effect.gen(function* () {254+ const files = yield* skills;255+256+ expect(files.length).toBeGreaterThan(0);257+258+ const computed = yield* Effect.forEach(files, ({ content, path }) =>259+ contentHash(bodyOf(content)).pipe(260+ Effect.map((hash) => ({ hash, path }))261+ )262+ );263+264+ expect(265+ files.map(({ content, path }) => ({266+ hash: recordedHash(content),267+ path,268+ }))269+ ).toStrictEqual(computed);270+ })271+ );272+273 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 linesmodified: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 */10 import { expect } from "@effect/vitest";11 import { Brand } from "@repo/brand";12 import { Config, Effect, FileSystem } from "effect";20 unmodified lines33 .replaceAll("__NAME__", Brand.name)34 .replaceAll("__CLI__", Brand.cli)35 .replaceAll("__SLUG__", Brand.slug);36 37+// The hex of a frontmatter's `content-hash: "sha256:…"` or an AGENTS.md38+// marker's `content-hash: sha256:…`.39+const HASH = /(?<=content-hash: "?sha256:)[0-9a-f]{64}/gu;40+41+/** Generated text with each content hash as `__HASH__`. */42+const unhashed = (text: string) => text.replaceAll(HASH, "__HASH__");43+34-/** 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. */45 const unbranded = (text: string) =>36- text46+ unhashed(text)47 .replaceAll(NAME, "__NAME__")48 .replaceAll(CLI, "__CLI__")49 .replaceAll(SLUG, "__SLUG__");50 1 unmodified line52 export const transcript = (files: readonly GeneratedFile[]) =>53 files.map(({ content, path }) => `==> ${path} <==\n${content}`).join("\n");54 55 /**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 */60 export const expectGolden = (name: string, actual: string) =>61 Effect.gen(function* () {62 const fs = yield* FileSystem.FileSystem;18 unmodified lines81 ).toBe(true);82 83 const golden = yield* fs.readFileString(file);84 74- 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 lines191 Option.some({ hash: helloDigest, landed: Option.none() })192 );193 })194 );195+196+ 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 });201+202+ const body = Option.map(203+ readManaged(current.content),204+ (managed) => managed.body205+ );206+207+ expect(Option.isSome(body)).toBeTruthy();208+209+ const bare = Option.getOrElse(body, () => "");210+211+ expect(yield* isStale(bare, current)).toStrictEqual(212+ Option.some({213+ hash: recordedHash(current.content),214+ landed: Option.none(),215+ })216+ );217+ })218+ );219+220+ 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" };225+226+ 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 });