Skip to content

Commit af46da4

Browse files
fix: harden Claude wiki build validation
1 parent 612af20 commit af46da4

6 files changed

Lines changed: 71 additions & 4 deletions

File tree

src/codealmanac/integrations/harnesses/claude/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
from codealmanac.services.harnesses.requests import RunHarnessRequest
4343

4444
CLAUDE_COMMAND = "claude"
45-
CLAUDE_RUN_TIMEOUT_SECONDS = 900
45+
CLAUDE_RUN_TIMEOUT_SECONDS = 90 * 60
4646
CLAUDE_ALLOWED_TOOLS = (
4747
"Read",
4848
"Write",
@@ -52,6 +52,7 @@
5252
"Grep",
5353
"LS",
5454
"Bash",
55+
"Agent",
5556
)
5657
CLAUDE_MAX_TURNS = 100
5758

src/codealmanac/manual/evidence.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ Every durable claim should be supported by a named source. Use frontmatter
1313
`sources:` entries for the materials that support the page, then cite
1414
non-obvious claims inline with `[@source-id]`.
1515

16+
The `sources:` entries in frontmatter are the materials actually used and cited
17+
in the article. They are not inspiration, research notes, or a list of files
18+
that helped you understand the subject. If a source is not cited in the article
19+
with `[@source-id]`, it does not belong in `sources:`.
20+
21+
Before finishing a page, compare every `sources:` id against the body. If an id
22+
is not cited with `[@source-id]`, either cite it next to the claim it supports
23+
or remove it.
24+
1625
A page with factual code, architecture, product, workflow, or decision claims
1726
but no inline citations is suspect. Navigation pages and manual pages can be
1827
lighter when they do not make those claims.
@@ -33,6 +42,9 @@ Use precise file sources when source code supports the claim. The source entry
3342
should point to the file, directory, commit, PR, issue, transcript, manual page,
3443
or web page that would help a maintainer verify the claim.
3544

45+
Directory source paths must end with `/`, for example `src/api/v1/`. Without the
46+
trailing slash, the validator treats the path as a file.
47+
3648
When evidence conflicts, state the conflict plainly or defer the claim. Do not
3749
turn a transcript, diff, or note into source of truth for behavior the code
3850
contradicts.

src/codealmanac/manual/how-to-write.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,8 @@ Most pages should include enough connective tissue to orient the reader:
110110

111111
These are page shapes, not mandatory headings. Use the shape when it helps the
112112
reader.
113+
114+
## Frontmatter
115+
116+
Quote any frontmatter string that contains `:`, `"`, `'`, `[`, `]`, `{`, or
117+
`}`. When unsure, quote `title:` and `summary:` values.

src/codealmanac/manual/links.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ inside the same documentation neighborhood:
2626
[Page format](../reference/page-format)
2727
```
2828

29+
Markdown links should point to actual wiki pages, not folders. Folders are only
30+
for organizing page files. If no page exists for a subject, mention it as plain
31+
text instead of linking it.
32+
33+
Do not link to `README` in Markdown links. A folder README is addressed by the
34+
folder route, such as `architecture`, not `architecture/README`.
35+
36+
Use kebab-case page routes. Do not invent underscore slugs.
37+
2938
Only link real targets. Do not leave placeholder links in finished pages. If a
3039
subject is useful but does not yet deserve a page, mention it as plain text.
3140

src/codealmanac/prompts/operations/build.md

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ Make a coverage map before writing pages. Write it to
2525
`almanac/coverage-map.md`, then treat it as the contract for the rest of the
2626
run.
2727

28+
Write `coverage-map.md` with valid page frontmatter:
29+
30+
```yaml
31+
---
32+
title: Coverage Map
33+
summary: Frozen page inventory for this first wiki build.
34+
topics: [build, wiki, reference]
35+
sources: []
36+
---
37+
```
38+
39+
Even though `coverage-map.md` is working state, it lives under `almanac/` and
40+
must pass normal page validation.
41+
2842
Write `coverage-map.md` with one main section:
2943

3044
## Page Inventory
@@ -138,9 +152,29 @@ For each writing sub-agent, provide:
138152
- the evidence files listed for those pages
139153
- the planned links to nearby pages
140154

155+
Do not summarize, paraphrase, or compress the manual guidance when prompting
156+
writing sub-agents. Include the relevant manual text directly in the sub-agent
157+
prompt, including `how-to-write.md`, `evidence.md`, `links.md`, and every
158+
folder-specific manual needed for that batch.
159+
160+
Every writing sub-agent prompt must include the exact source frontmatter shape:
161+
162+
```yaml
163+
sources:
164+
- id: source-id
165+
type: file
166+
path: path/to/file.py
167+
```
168+
169+
Use `type`, not `kind`. Directory evidence is still `type: file`; mark it with a
170+
trailing slash in `path`.
171+
141172
When a batch contains pages from different folders, include every relevant
142173
folder-specific manual in the sub-agent prompt.
143174

175+
A writing batch is not fully assigned until its sub-agent prompt includes the
176+
full manual packet and the exact source schema example.
177+
144178
The sub-agent's task is to write encyclopedia-quality articles about this
145179
codebase. Each page should feel like a focused Wikipedia article for one
146180
codebase subject: it should define the subject, explain why it exists here, show
@@ -175,9 +209,10 @@ Use simple, direct prose. Avoid jargon when plain language works. Structure
175209
sections so each page has a clear through line and later sections build on
176210
earlier sections without simply repeating them.
177211

178-
Use inline citations for non-obvious claims. Use Markdown links for related
179-
wiki pages. Put relevant files and folders in `sources:` frontmatter entries
180-
with `type: file`.
212+
Use inline citations for non-obvious claims. Put only cited evidence in
213+
`sources:` frontmatter entries. Do not use `sources:` as a context list or
214+
bibliography. Every `sources:` entry must be cited in the page body with
215+
`[@source-id]`, or removed. Directory source paths must end with `/`.
181216

182217
Assign `almanac/getting-started.md` to a writing sub-agent as the front door to
183218
the finished wiki. If it is drafted early, send it back to a writing or repair
@@ -202,6 +237,10 @@ missing citations, missing links between related pages, duplicate or overlapping
202237
explanations, terminology drift, or wrong folder placement, dispatch repair
203238
sub-agents with the exact pages and changes needed.
204239

240+
Run `codealmanac validate` before committing. If validation fails, do not commit.
241+
Fix validation issues first, rerun validation, and commit only after validation
242+
passes.
243+
205244
Before stopping, make sure every missing planned page has an exact
206245
repo-evidence removal reason in `coverage-map.md`, or write the missing page.
207246

tests/test_claude_adapter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ def test_claude_sdk_client_maps_typed_message_stream(tmp_path: Path):
286286
assert options.mcp_servers == {}
287287
assert options.tools == list(CLAUDE_ALLOWED_TOOLS)
288288
assert options.allowed_tools == list(CLAUDE_ALLOWED_TOOLS)
289+
assert "Agent" in options.allowed_tools
289290

290291

291292
def test_claude_sdk_client_maps_result_failure(tmp_path: Path):

0 commit comments

Comments
 (0)