Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions pkgs/mcpx/docs/story.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <words>` — find a tool by name or description.
3. `mcpx types <namespace>` — load signatures for that namespace only.
3. `mcpx types <namespace>` — load signatures for that namespace only, or
`mcpx types <namespace>.<tool>` 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 <name>` or `mcpx exec '<code>'` — do the work.

Do not run `mcpx types` for every namespace. Loading one costs a few hundred
Expand All @@ -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({});
Expand Down Expand Up @@ -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
Expand Down
92 changes: 92 additions & 0 deletions pkgs/mcpx/internal/cli/story_test.go
Original file line number Diff line number Diff line change
@@ -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
}
Comment on lines +35 to +38

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve quote ordering when validating source lines

If AGENTS.md later reorders existing lines while story.md retains their old order, this test still passes because it reduces the source to an unordered set and checks only membership; the same is true if the quote duplicates any valid line. That leaves the new drift guard green even though the fenced block no longer represents an abridged verbatim quote. Validate the quoted lines as an ordered subsequence of AGENTS.md instead.

Useful? React with 👍 / 👎.


// 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))
}
}
}
}
1 change: 1 addition & 0 deletions treefmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.<name>]
Expand Down
Loading