Skip to content

Commit 1367c04

Browse files
committed
review: analyze PR #355 knowledge layer vs AGENTS.md efficiency
Compares the generated knowledge layer approach against existing AGENTS.md for agent task efficiency, using issue #331 as a case study. Identifies critical source path accuracy issue in family mappings. https://claude.ai/code/session_01TV838HJEfjQA397mkJzscN
1 parent 48aa329 commit 1367c04

1 file changed

Lines changed: 160 additions & 0 deletions

File tree

review-pr355-knowledge-layer.md

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# Review: PR #355 — feat: add generated repo knowledge layer
2+
3+
## Summary
4+
5+
PR #355 introduces a generated knowledge layer (`knowledge/` directory) that provides agents with pre-compiled navigation docs: per-command pages with flags/platform support, agent route maps, a platform matrix, and a JSON index. It's generated via `pnpm kb:build` and validated via `pnpm kb:check`.
6+
7+
This review evaluates the PR through the lens of the "LLM Knowledge Bases" article and compares the knowledge layer approach against the existing `AGENTS.md` for practical agent tasks.
8+
9+
---
10+
11+
## Experiment: Issue #331 (iOS legacy device discovery)
12+
13+
I ran two subagents in parallel to simulate fixing issue #331 ("devices command doesn't discover physical iOS devices running iOS <17") — one using only `AGENTS.md`, and one simulating the knowledge layer.
14+
15+
### Approach A: AGENTS.md only
16+
17+
| Metric | Value |
18+
|--------|-------|
19+
| Files read | 5 (AGENTS.md → devices.ts → test → devicectl.ts → device-ready.ts) |
20+
| Search operations | 4-5 greps |
21+
| Hops to implementation | 1 (AGENTS.md routing section → ios/devices.ts) |
22+
| Direct path from AGENTS.md? | Partial — no explicit "devices" entry, but Command Family Lookup section pointed to `src/platforms/ios/` |
23+
| Confidence in fix | 8/10 |
24+
25+
### Approach B: Knowledge layer (PR #355)
26+
27+
| Metric | Value |
28+
|--------|-------|
29+
| Files read | 3 (knowledge/commands/devices.md → devices.ts → test) |
30+
| Search operations | 2 |
31+
| Hops to implementation | 1 (knowledge page → source file) |
32+
| Direct path from knowledge? | **No — pointed to wrong files** |
33+
| Confidence in fix | Would be lower without correction |
34+
35+
### Critical Finding: The Knowledge Layer Would Misdirect
36+
37+
The generated `knowledge/commands/devices.md` lists these as primary source paths:
38+
39+
```
40+
- src/daemon/handlers/session.ts
41+
- src/daemon/session-store.ts
42+
- src/daemon/handlers/__tests__/session.test.ts
43+
```
44+
45+
**These are wrong.** The actual device discovery logic lives in:
46+
47+
```
48+
- src/platforms/ios/devices.ts
49+
- src/platforms/ios/__tests__/devices.test.ts
50+
```
51+
52+
This happens because the `FAMILY_DEFINITIONS` in `scripts/knowledge-lib.mjs` assigns `devices` to the `session` family, which maps all commands in that family to the same 3 source files. The family grouping is too coarse — `devices` shares no implementation with `session`. An agent following these links would land in the wrong module and waste tokens reading irrelevant code before having to fall back to grep anyway.
53+
54+
The same problem affects `ensure-simulator` — it points to `session.ts` instead of `src/platforms/ios/ensure-simulator.ts`.
55+
56+
---
57+
58+
## Comparison: Knowledge Layer vs AGENTS.md
59+
60+
### Where the knowledge layer adds value
61+
62+
1. **Flag documentation**: Per-command flag listings with descriptions are genuinely useful. AGENTS.md has a "Adding a New CLI Flag" checklist but doesn't enumerate existing flags per command.
63+
2. **Platform matrix**: The generated capabilities table is a quick reference that AGENTS.md doesn't have. An agent can instantly check "does `clipboard` work on iOS device?" without reading `capabilities.ts`.
64+
3. **Command catalog**: The index.md table gives agents a single-file overview of all 47 commands — useful for tasks like "which commands relate to recording?"
65+
4. **Machine-readable index**: `index.json` enables tool-based queries (the article's "extra tools" concept).
66+
67+
### Where AGENTS.md is already sufficient (or better)
68+
69+
1. **Routing**: AGENTS.md's Command Family Lookup is more accurate for finding implementation files because it was hand-curated. The knowledge layer's family-based source mapping is too coarse-grained.
70+
2. **Architectural context**: AGENTS.md explains *why* code is structured a certain way (daemon flow, iOS runner seams, dependency direction). The knowledge layer has no architectural narrative.
71+
3. **Hard rules**: AGENTS.md's constraints (use `runCmd`, keep files ≤300 LOC, capability checks) prevent common mistakes. Generated docs can't capture these.
72+
4. **Testing guidance**: The testing matrix in AGENTS.md is essential for knowing *what to verify*. The knowledge layer doesn't address validation.
73+
74+
### Token efficiency analysis
75+
76+
For issue #331 specifically:
77+
78+
| | AGENTS.md | Knowledge Layer | Delta |
79+
|---|---|---|---|
80+
| Tokens to reach correct file | ~2K (read AGENTS.md routing) | ~1.5K (read command page) **but wrong file** | Knowledge layer adds ~3K wasted tokens from misdirection |
81+
| Total tokens to fix | ~8K | ~10K (with recovery from wrong path) | AGENTS.md wins by ~20% |
82+
| Fix quality | Correct (found devices.ts directly) | Would eventually correct, but slower | Comparable after recovery |
83+
84+
For a task like "add a new flag to `screenshot`", the knowledge layer would be more efficient (~30% token savings) because the flag listing and platform matrix eliminate exploratory reads of `command-schema.ts` and `capabilities.ts`.
85+
86+
---
87+
88+
## Evaluation Through the Article's Framework
89+
90+
The article describes a full pipeline: **raw data → LLM-compiled wiki → Q&A → output → linting**. PR #355 implements a subset:
91+
92+
| Article concept | PR #355 status |
93+
|---|---|
94+
| Data ingest (raw/) | Partial — reads from source code and `command-schema.ts`, but not docs/issues/PRs |
95+
| Compiled wiki (knowledge/) | Yes — generated .md files with backlinks |
96+
| Index maintenance | Yes — `index.json` and `index.md` |
97+
| Q&A against wiki | Not implemented (would need CLI search tool) |
98+
| Linting/health checks | Yes — `kb:check` catches stale files |
99+
| Incremental enhancement | No — full rebuild only, no incremental updates |
100+
| Visual output | No — markdown only |
101+
102+
### What's missing vs the article's vision
103+
104+
1. **No semantic routing**: The article describes LLMs auto-maintaining indexes with "brief summaries." The knowledge layer uses static family assignments that don't reflect actual code ownership. A truly compiled wiki would trace imports to find the *real* handler file for each command.
105+
2. **No cross-referencing of runtime data**: Issue history, common failure patterns, and test coverage data would make the wiki much more useful for bug fixing.
106+
3. **No query interface**: The article emphasizes Q&A over the wiki. The knowledge layer is read-only docs — there's no search tool an agent can invoke.
107+
108+
---
109+
110+
## Specific Issues in PR #355
111+
112+
### 1. Incorrect source path mapping (Critical)
113+
114+
As detailed above, `FAMILY_DEFINITIONS` maps commands to families at too coarse a granularity. `devices`, `ensure-simulator`, `boot`, `install`, and others all point to `session.ts` even though they have dedicated handler files.
115+
116+
**Fix**: Either trace actual imports from `src/daemon.ts` to resolve per-command handler files, or maintain a manual override map for commands that have dedicated modules.
117+
118+
### 2. No "devices" route in agent-routes.md
119+
120+
The agent routes cover session, interaction, snapshot, selectors, and Apple runner — but there's no route for "device discovery" pointing to `src/platforms/ios/devices.ts` or `src/platforms/android/devices.ts`. This is one of the most common agent tasks.
121+
122+
### 3. knowledge-lib.mjs is 674 lines
123+
124+
This exceeds the repo's own ≤300 LOC guideline from AGENTS.md. Consider splitting into separate renderer modules.
125+
126+
### 4. Validation doesn't catch semantic errors
127+
128+
`kb:check` validates that generated files match expected output (content drift). It does not validate that source paths actually exist or that family assignments are correct. A broken link in a command page would pass validation silently.
129+
130+
**Fix**: The link validation logic exists in `buildKnowledgeFiles()` (it resolves relative links with `fs.access`), but it only runs during build, not check. Consider running it in both.
131+
132+
### 5. Duplicate family assignment check is mentioned but unclear
133+
134+
The PR description mentions "validation that fails on duplicate family assignments" but the actual check isn't visible. If command X appears in two families, which source paths win?
135+
136+
---
137+
138+
## Verdict
139+
140+
**The PR is a promising start but has a critical accuracy issue that would actively mislead agents.** The knowledge layer's primary value proposition — directing agents to the right files faster — is undermined by the coarse family-to-source mapping that points many commands to the wrong implementation files.
141+
142+
### Recommendations
143+
144+
1. **Block on fixing source path accuracy.** Either auto-resolve handler files from the daemon router or add per-command overrides. Without this, the knowledge layer is net-negative for bug-fixing tasks (the most common agent work).
145+
146+
2. **Merge the platform matrix and flag docs regardless.** These are independently valuable and don't suffer from the routing problem. Consider generating them as part of AGENTS.md itself rather than a separate knowledge/ directory.
147+
148+
3. **Add a "device discovery" route** to agent-routes.md pointing to `src/platforms/ios/devices.ts` and `src/platforms/android/devices.ts`.
149+
150+
4. **Consider the article's linting concept**: Run an LLM health check over the generated knowledge to catch inconsistencies like "devices.md points to session.ts but devices.ts exists."
151+
152+
5. **Long-term**: Build toward the article's full vision — a search CLI tool over the knowledge base, incremental updates, and cross-referencing with issue/PR history. The current implementation is a static snapshot; the article's power comes from the wiki being a living, queryable system.
153+
154+
### Bottom line for the AGENTS.md vs Knowledge Layer question
155+
156+
For **bug fixing** (like issue #331): AGENTS.md is currently more efficient because its hand-curated routing is more accurate than the generated family mappings. The knowledge layer would need per-command handler resolution to beat it.
157+
158+
For **feature additions** (like adding a new command or flag): The knowledge layer would save ~30% tokens by providing flag enumerations and platform matrices upfront, avoiding exploratory reads of schema and capability files.
159+
160+
The ideal is both: AGENTS.md for architectural context and hard rules, plus an accurate generated knowledge layer for command-specific details. They're complementary, not competing.

0 commit comments

Comments
 (0)