From 23e7dd8f1c08d9856edffebf65790d67066ab97e Mon Sep 17 00:00:00 2001 From: Muse Sweep Date: Mon, 19 Oct 2026 19:08:25 -0500 Subject: [PATCH] docs(mcpx): re-sync story.md's AGENTS.md quote and guard it with a test story.md claimed AGENTS.md is 109 lines (twice); it is 120. Two quoted lines no longer matched the file: step 3 (now covers per-tool types and catalog --budget) and the Scripts intro (now the globalThis no-imports text). Re-sync both, correct both counts, and fix the abridgement note to name what is actually left out (profiles, script contract, secrets). Add TestStoryDocumentIsCurrent (mirrors TestParityDocumentIsCurrent): every non-empty line of story.md's quoted block must be a verbatim line of AGENTS.md, and both stated line counts must equal its real length. It fails on the pre-fix tree with exactly those four divergences. story.md joins parity.md in treefmt.toml's excludes: prettier rewrites *emphasis* to _emphasis_ inside the quoted block itself, so the file can never be prettier-formatted without breaking the verbatim quote the new test guards. Fixes #365 --- pkgs/mcpx/docs/story.md | 17 +++-- pkgs/mcpx/internal/cli/story_test.go | 92 ++++++++++++++++++++++++++++ treefmt.toml | 1 + 3 files changed, 104 insertions(+), 6 deletions(-) create mode 100644 pkgs/mcpx/internal/cli/story_test.go diff --git a/pkgs/mcpx/docs/story.md b/pkgs/mcpx/docs/story.md index 5bf1feb3a8..b3541f96e0 100644 --- a/pkgs/mcpx/docs/story.md +++ b/pkgs/mcpx/docs/story.md @@ -18,9 +18,9 @@ their schemas is in the agent's context, which is the entire point, but the agent does not know that yet. What it does have is one instruction file, [`AGENTS.md`](../AGENTS.md), -injected at session start. Abridged -- the full file is 109 lines and adds -profiles, per-tool `types`, `catalog --budget` and the `globalThis` bindings, -which this walk does not need and #264 is about -- it reads: +injected at session start. Abridged -- the full file is 120 lines and adds +profiles, the script contract and the secrets section, which this walk does +not need -- it reads: ```markdown # mcpx @@ -32,7 +32,10 @@ None of their tool schemas are in your context. You pull in only what you need. 1. `mcpx ls` — which namespaces exist. Cheap; run it whenever. 2. `mcpx search ` — find a tool by name or description. -3. `mcpx types ` — load signatures for that namespace only. +3. `mcpx types ` — load signatures for that namespace only, or + `mcpx types .` for a single tool, which is far cheaper. + `mcpx catalog [--budget N] [--bias words]` fits every namespace into a + token budget when you are still deciding. 4. `mcpx run ` or `mcpx exec ''` — do the work. Do not run `mcpx types` for every namespace. Loading one costs a few hundred @@ -51,7 +54,9 @@ Scripts are TypeScript on a real runtime (deno, else bun, else node). They get the full runtime: filesystem, network, subprocesses. Relative paths resolve against *your* working directory, not the script's. -Import the generated client, which mcpx writes next to the script: +`log`, `emit`, `tools` and every namespace are already on `globalThis`, so a +script needs no imports at all. `log(msg)` is `log.info(msg)`. Importing works +too and gives the same objects: import tools from "./mcpx-client.ts"; const pages = await tools.chrome_devtools.list_pages({}); @@ -2887,7 +2892,7 @@ else in this document is detail underneath those four verbs. - [`AGENTS.md`](../AGENTS.md) — the instruction file abridged above. This is the text to inject into an agent's session; it is deliberately short, and - 109 lines today. The quote above is not the whole of it (#264). + 120 lines today. The quote above is not the whole of it (#264). - [`ASSESSMENT.md`](../ASSESSMENT.md) — why this exists, with the measurements against the predecessor it replaced. - [`OPENCODE-V2.md`](../OPENCODE-V2.md) — how this compares to opencode v2's diff --git a/pkgs/mcpx/internal/cli/story_test.go b/pkgs/mcpx/internal/cli/story_test.go new file mode 100644 index 0000000000..bf7edd667d --- /dev/null +++ b/pkgs/mcpx/internal/cli/story_test.go @@ -0,0 +1,92 @@ +package cli + +import ( + "os" + "regexp" + "strconv" + "strings" + "testing" +) + +const ( + storyPath = "../../docs/story.md" + agentsPath = "../../AGENTS.md" +) + +// TestStoryDocumentIsCurrent fails when docs/story.md's claims about +// AGENTS.md drift from the file itself: the line counts it states, or the +// block it presents as a quote of AGENTS.md. The quote is abridged, but +// every line it does quote must be a line of AGENTS.md verbatim, and the +// counts it states ("the full file is N lines", "N lines today") must be +// the file's real length. #365: both had silently rotted once already +// (109 stated, 120 actual), the same failure TestParityDocumentIsCurrent +// guards docs/parity.md against. +func TestStoryDocumentIsCurrent(t *testing.T) { + agents, err := os.ReadFile(agentsPath) + if err != nil { + t.Fatal(err) + } + story, err := os.ReadFile(storyPath) + if err != nil { + t.Fatal(err) + } + + agentLines := strings.Split(strings.TrimSuffix(string(agents), "\n"), "\n") + inAgents := make(map[string]bool, len(agentLines)) + for _, l := range agentLines { + inAgents[l] = true + } + + // The quoted block: the first ```markdown fence in story.md. + storyLines := strings.Split(string(story), "\n") + start := -1 + for i, l := range storyLines { + if l == "```markdown" { + start = i + 1 + break + } + } + if start < 0 { + t.Fatal("docs/story.md has no ```markdown quote of AGENTS.md") + } + quoted := 0 + closed := false + for _, l := range storyLines[start:] { + if l == "```" { + closed = true + break + } + if strings.TrimSpace(l) == "" { + continue + } + quoted++ + if !inAgents[l] { + t.Errorf("docs/story.md quotes AGENTS.md as %q, which is not a line of AGENTS.md; re-sync the quote with the file", l) + } + } + if !closed { + t.Error("docs/story.md's AGENTS.md quote is never closed") + } + if quoted == 0 { + t.Error("docs/story.md's AGENTS.md quote is empty") + } + + // The stated line counts. + for _, claim := range []struct { + name string + re *regexp.Regexp + }{ + {"the full file is", regexp.MustCompile(`the full file is (\d+) lines`)}, + {"lines today", regexp.MustCompile(`(\d+) lines today`)}, + } { + for _, m := range claim.re.FindAllStringSubmatch(string(story), -1) { + n, err := strconv.Atoi(m[1]) + if err != nil { + t.Fatal(err) + } + if n != len(agentLines) { + t.Errorf("docs/story.md says AGENTS.md is %d lines (%q claim); it is %d lines", n, claim.name, len(agentLines)) + } + } + } +} diff --git a/treefmt.toml b/treefmt.toml index 89022cb283..4f0100c9c4 100755 --- a/treefmt.toml +++ b/treefmt.toml @@ -7,6 +7,7 @@ excludes = [ "pkgs/dht/**", # WIP package with syntax errors ".opencode/**", # managed by opencode, may have permission issues "pkgs/mcpx/docs/parity.md", # generated; TestParityDocumentIsCurrent compares it byte-for-byte with the generator, so prettier's table padding can never be applied + "pkgs/mcpx/docs/story.md", # quotes AGENTS.md verbatim; TestStoryDocumentIsCurrent compares the quoted lines byte-for-byte with AGENTS.md, whose *emphasis* prettier would rewrite to _emphasis_ ] # [formatter.]