Repository navigation
docs(architecture): split into a lean always-loaded core + on-demand area files (#2306) - #2495
Conversation
…area files (#2306) `docs/memory/architecture.md` is `@`-imported by CLAUDE.md, so every session paid it in full: 2,973 lines / 574 KB, 92.6% of all auto-loaded context, and growing ~50 lines a week against its own stated "~1000 lines max" budget. Most sessions touch one or two subsystems. Split it the way #1406 split the requirements monolith — a lean core plus per-area files read on demand: core 2,973 -> 181 lines (574 KB -> 48 KB, 91.6% cut) areas 14 files under docs/memory/architecture/, referenced by path, never `@`-imported The core keeps the system overview, technology stack, all Architectural Invariants verbatim, network topology, dev environment, data persistence, and a new Architecture Map. Everything else moved; nothing was summarized away. The move was mechanical, not retyped: a splitter routed every heading-delimited block to exactly one destination and asserted byte conservation, so no block could be dropped or duplicated. Verified against origin/dev afterwards — the only prose removed is the two rewritten preamble lines, the three now-orphaned container headings the map replaces, and their obsolete intra-file pointer. Two additions beyond the filed ACs, because a split alone does not make the right file get opened: 1. Index lines state a consequence, not a topic. A row names the owning code paths and the concrete regression that reading the file prevents. "retention — see retention.md" gives an agent no reason to spend a tool call; "OPS_SETTINGS_DEFAULTS is a safety floor, not a knob — #1638 hard-DELETEd a live instance's history and shipped green" does. Every consequence is extracted from incident refs already in the moved prose, and the test requires each to cite an issue or invariant. 2. A PreToolUse hook, not more prose. scripts/docs/architecture_context_hook.py maps the edited file to its owning area and injects the pointer on first touch, so loading follows what the session is actually editing. Strengthening "always check" wording is the approach that fails here — it makes an agent assert having checked. The hook parses the core's own map table and holds no map of its own, so the two cannot drift; it is advisory (never blocks a tool call), most-specific-wins (so the 90 KB catalog is not cited on every service edit), once per area per session, and exits silently on any error. Also fixed three anchors that were already broken on dev (a numbered heading, an em-dash slug, and #network-topology-issue-589), and repointed 79 in-page anchors the split turned into cross-file links. tests/unit/test_2306_architecture_split.py guards the parts that fail silently: the line budget, map/disk bijection, consequence quality, area-file headers, the hook-vs-table anti-drift property, routing and specificity, once-per-session, fail-open behaviour, and dangling anchors across the new file boundary. enterprise-docs-guard.yml needs no change — it greps `docs/` recursively, so docs/memory/architecture/ is already in scope. Verified locally: 0 hits. Follow-up: skills in the private .claude submodule that read this doc (/validate-architecture, /update-docs, /sync-feature-flows, /autoplan context loading) need a bump for the new layout. Closes #2306 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01NqkwYug8AWgQSz34c59oiu
Now conflicts with
|
Content on dev |
From | New home in this PR |
|---|---|---|
redis_breaker_util.py row — adds agent_service/deploy (agent:deploy_op:{base_name}) to the SingleFlightLock consumer list |
#2060 / #2485 | architecture/backend.md |
Library system-install section (ent#126) — YamlEditor.vue + EditorHelpPanel.vue were deleted in the dead-component sweep; CSP rationale kept as permanent |
#2492 / #2496 | architecture/frontend.md |
agents.ts MCP tools row — deploy_local_agent embedded-manifest contract |
#2060 / #2485 | architecture/mcp-server.md |
New row POST /api/agents/deploy-local in the agents endpoint table |
#2060 / #2485 | architecture/api-endpoints.md |
Single-flight lock consolidation (#1920) — adds agent:deploy_op:{base_name} to the site list |
#2060 / #2485 | architecture/database.md |
No content needs re-writing; each edit moves verbatim into the file that already owns that section.
Heads-up on ordering
#2264 is still open and also edits architecture.md. If it merges first there will be a second, similarly small pass — worth rebasing once after it lands rather than twice.
Merge blocker
Branch protection on dev requires one approving review and this PR has none. CI is fully green (all three pytest head seeds, schema-parity, both Analyze jobs, gitleaks, regression diff), and validation found no security, packaging, or config-drift issues. It also edits CLAUDE.md and adds scripts/docs/architecture_context_hook.py, so it changes what auto-loads into every session — that is the part worth a human read rather than a rubber stamp.
|
Resolve by running |
|
Resolve by merging |
Resolve the architecture.md conflict by routing dev's changes into the area
files this branch creates, rather than back into the monolith.
dev's 13 hunks land as follows — none touch content the lean core retains
(overview, stack, invariants, topology, dev env, data persistence), so the
core file is unchanged by the merge:
backend.md redis_breaker_util SingleFlightLock consumer list gains
agent_service/deploy (#2060); new runtime_secret_scrub.py
service row (ent#279)
frontend.md Library system-install section (YamlEditor.vue and
EditorHelpPanel.vue deleted in the #2492 sweep); Dashboard
Grid and List view rows
mcp-server.md agents.ts deploy_local_agent embedded-manifest contract
api-endpoints.md POST /api/agents/deploy-local row; operator_response
stranded-for-pull-mode paragraph rewritten for #2391
workspace.md briefing hydration moved off the roster critical path
(#2163) — three edits plus the new 44-line section
database.md skill_sources tag-pinning site list gains
agent:deploy_op:{base_name}
Verified by content-line bag comparison against origin/dev: the only lines not
carried over are the same anchor rewrites and four orphaned container headings
the split already documented.
Also fix 64 relative links the split left un-rebased for the extra directory
level: feature-flows/ -> ../feature-flows/ (60), and ../{migrations,schemas,
QUERYING_LOGS.md,TRINITY_COMPATIBLE_AGENT_GUIDE.md,harness-authoring-guide.md}
-> ../../ (4). Every relative link in the architecture set now resolves. The
voice_reply_service pointer, which the split had aimed at the core's map after
its #cross-cutting-subsystems target was dissolved, now points at backend.md
where that service is actually described.
tests/unit/test_2306_architecture_split.py: 22 passed.
enterprise-docs-guard pattern run locally against this tree: 0 hits.
Full tests/unit: 13742 passed, 21 failed — all 21 are the local IPv6/DNS
mapped-address failures that reproduce identically on origin/dev.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015cMEDUYWG3KFADyxrEtfde
Rebased onto
|
Content on dev |
From | Landed in |
|---|---|---|
redis_breaker_util.py — SingleFlightLock consumers gain agent_service/deploy |
#2060 / #2485 | backend.md |
New runtime_secret_scrub.py service row |
ent#279 / #2264 | backend.md |
Library system-install section — YamlEditor.vue + EditorHelpPanel.vue deleted |
#2492 / #2496 | frontend.md |
| Dashboard Grid + Dashboard List view rows | #2519 / #2500 | frontend.md |
agents.ts — deploy_local_agent embedded-manifest contract |
#2060 / #2485 | mcp-server.md |
New POST /api/agents/deploy-local row |
#2060 / #2485 | api-endpoints.md |
operator_response "stranded for pull mode" rewritten — structural → a choice |
#2391 / #2513 | api-endpoints.md |
| Briefing hydration off the roster critical path — 3 edits + a new 44-line section | #2163 / #2518 | workspace.md |
skill_sources tag-pinning — agent:deploy_op:{base_name} |
#2060 / #2485 | database.md |
Checked rather than asserted, same method as the original split: a content-line bag comparison against origin/dev shows the only lines not carried over are the anchor rewrites and the four orphaned container headings this PR already documented.
Also fixed: 64 relative links the split left un-rebased
Found while verifying the merge, and it is a genuine defect in the original push rather than fallout from it. The area files sit one directory deeper than the monolith did, so every relative link needed re-basing and 64 did not get it:
](feature-flows/…)→](../feature-flows/…)— 60 links, each of which resolved to the non-existentdocs/memory/architecture/feature-flows/](../{migrations,schemas,QUERYING_LOGS.md,TRINITY_COMPATIBLE_AGENT_GUIDE.md,harness-authoring-guide.md})→](../../…)— 4 links
Every relative link in the architecture set now resolves; verified by walking each one against disk. One pointer also got aimed better: voice_reply_service had been repointed at the core's Architecture Map when its #cross-cutting-subsystems target dissolved, and now points at backend.md, where that service is actually described.
The in-page ](#anchor) links that remain are correct — all four target headings in their own file.
Verification
tests/unit/test_2306_architecture_split.py— 22 passedenterprise-docs-guardpattern run locally against this tree — 0 hits, no workflow change needed- Full
tests/unit— 13742 passed, 21 failed; all 21 are the local IPv6 mapped-address / DNS failures that reproduce identically onorigin/dev(test_736_a2a_outbound_*,test_ent14_registry_url_ssrf,test_ent399_ipv6_origin,test_mcp_validator), so they are environmental and unrelated to this branch PreToolUsehook smoke-tested against acleanup_service.pyedit — emits thereliability.mdpointer
Still needs one approving review before it can merge; deliberately not self-merging.
# Conflicts: # docs/memory/architecture.md
One conflict: docs/memory/architecture.md, because #2516 (ent#437 opt-in telemetry) added content to the monolith this branch splits. Resolved semantically rather than textually. The lean core is kept as-is and all four of #2516's edits are re-homed into the area files that own them: backend.md `settings.py` catalog entry (Tier-2 sharing routes) backend.md new "Opt-in Instance Telemetry (ent#437)" section agent-lifecycle.md the First-Run "Collateral" paragraph (FinishSetupCard) api-endpoints.md the /api/settings/feature-flags row The telemetry section goes to backend.md rather than beside the neighbours it had in the monolith (#2380/#2381 in agent-lifecycle.md, or reliability.md, which owns the section it was inserted before). The deciding rule is that the PreToolUse hook routes by PATH: `services/telemetry_sharing_service.py` matches backend.md's `src/backend/services/**` glob, so an engineer sent to backend.md must find the prose there. Placing it by monolith adjacency would point the hook at a file that does not describe it. Verified by the branch's own suite — 22 passed, including test_no_dangling_anchor_links_across_the_split (which proves the re-homed cross-references still resolve) and test_core_within_line_budget (core unchanged at 181 lines). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01HAw7x7VwACVjc58pPPi3Th
Same shape as the previous merge: the only conflict is docs/memory/architecture.md, because #2526 (loops terminal-driven) edited the monolith this branch splits. Only one line changed on dev — the "Startup hook (#740)" sentence, rewritten to describe LoopService.reconcile_after_restart() replacing mark_orphan_loops_interrupted(). Re-homed into reliability.md, which owns cleanup_service and carries that sentence after the split, rather than resolved textually against the core. Core unchanged at 181 lines. Branch suite: 22 passed, including test_no_dangling_anchor_links_across_the_split. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01HAw7x7VwACVjc58pPPi3Th
Rebased onto
|
| From | Content | Re-homed to |
|---|---|---|
| #2516 | settings.py catalog entry (Tier-2 sharing routes) |
backend.md |
| #2516 | new "Opt-in Instance Telemetry (ent#437)" section | backend.md |
| #2516 | First-Run "Collateral" paragraph (FinishSetupCard) | agent-lifecycle.md |
| #2516 | /api/settings/feature-flags row |
api-endpoints.md |
| #2526 | "Startup hook (#740)" rewrite (reconcile_after_restart) |
reliability.md |
One placement call worth recording. The telemetry section sat between #2380 and #2216 in the monolith, whose sections are now in agent-lifecycle.md and reliability.md respectively — so adjacency argued for either of those. I put it in backend.md instead, because the PreToolUse hook routes by path: services/telemetry_sharing_service.py matches backend.md's src/backend/services/** glob, so that is where an engineer editing it gets sent. Placing prose by monolith adjacency would point the hook at a file that does not describe the thing.
That is really an argument for the design in this PR: the map made the question answerable at all, and test_no_dangling_anchor_links_across_the_split then proved the re-homed cross-references still resolve.
Core stays at 181 lines. Branch suite: 22 passed.
Approving — merging once CI is green.
vybe
left a comment
There was a problem hiding this comment.
Validated via /validate-pr. Docs-only change (plus one hook script and its test), so the security, packaging and migration gates are all not-applicable; scan of the diff is clean (no secrets, emails, public IPs, host paths or mode changes).
What makes this worth merging beyond the line count. The measured problem is that architecture.md is @-imported by CLAUDE.md, so every session pays for all ~3,200 lines whether or not it touches the subsystem. The split takes the core to 181 lines and moves the rest behind a map.
Two design choices carry it, and both are enforced rather than documented:
- The map's third column names the regression each file prevents, not the topic — which is what gives an agent a reason to spend the tool call.
database.md's entry is literally the two-heads hazard, which #2526 hit in this same batch: two revisions sharing adown_revisionapply zero revisions while git reports no conflict. - The
PreToolUsehook parses that table and has no map of its own, so there is one source and no second copy to drift.test_hook_parse_matches_the_published_tablere-parses it independently and requires agreement, andtest_hook_never_blocks_an_editpins that malformed or foreign input exits 0 — advisory, never a gate.
Coverage is the right shape for a docs refactor, where the real risks are content loss and broken cross-references: bijection between map rows and area files, test_no_dangling_anchor_links_across_the_split, a core line budget stated in the file itself rather than only in the test, and most-specific-owner routing.
I resolved the two dev conflicts myself (see the comment above) — semantically, re-homing each addition into its owning area file, since a textual resolution here silently drops content. Merging once green.
Splits
docs/memory/architecture.mdinto a lean always-loaded core over per-area files read on demand, mirroring the #1406 requirements split.The problem, measured
The file is
@-imported byCLAUDE.md, so every session pays it in full — while most sessions touch one or two subsystems.2,973 lines against its own stated "~1000 lines max", growing ~50 lines/week (it gained 305 lines between this issue being filed and this branch being cut).
Result
architecture.mddocs/memory/architecture/, path-referenced, never importedCore keeps: system overview + diagram, technology stack, all Architectural Invariants verbatim, network topology, dev environment, data persistence, and the new Architecture Map. Everything else moved. Nothing was summarized away or dropped.
No content was lost, and that is checked rather than asserted
The move was mechanical. A splitter routed every heading-delimited block to exactly one destination and asserted byte conservation, so no block could be dropped or duplicated. Verified afterwards against
origin/devby content-line bag comparison: the only prose removed is the two rewritten preamble lines, the three now-orphaned container headings the map replaces (## Component Details,## Cross-Cutting Subsystems,## API Endpoints), and one obsolete intra-file pointer. Every other differing line is an anchor rewrite with identical prose.Two additions beyond the filed ACs
AC 1 asks the core to keep "enough of the map that an agent knows what exists and exactly which file to open". That is the right requirement, but a topic index satisfies it on paper and does not bind in practice — the failure mode is documented in this repo's own learnings: an agent that half-remembers a subsystem answers instead of reading, and strengthening the "always check" prose makes it assert having checked. Lazy loading only pays if the right file gets opened, so:
1. Index rows state a consequence, not a topic. Each row carries the owning code paths and the concrete regression that reading the file prevents. Compare:
against the shipped row for
reliability.md:Every consequence is extracted from incident refs already present in the prose being moved — this is not new invention — and
test_every_map_row_carries_owned_paths_and_a_consequencerequires each to cite an issue or an invariant, so a future row cannot degrade back into a label.2. A
PreToolUsehook, not more prose.scripts/docs/architecture_context_hook.pymaps the file being edited to its owning area and injects the pointer the first time a session touches it — so correct loading follows what the session is actually editing rather than the agent choosing to look. Same shape as the fix that worked previously when injected data beat instruction prose.Properties, each deliberate:
test_hook_has_no_map_of_its_ownwalks the AST (so comments and docstrings are exempt by construction) and fails if an area filename appears in executable string data.additionalContext, never blocks. Any error — malformed table, moved doc, unreadable state — exits 0 with no output. The failure mode is "back to today's behaviour", never "cannot edit".cleanup_service.pyis also matched bybackend.md's broadsrc/backend/services/**catalog glob; citing the 90 KB catalog on every service edit is the noise that gets a hook switched off, so only the tightest owner fires..claude/settings.json, which is core-team-only, so OSS clones simply run without it. Snippet is in the core's Hook setup section.Also fixed
(#anchor)links the split turned into cross-file links, repointed by a resolver rather than by hand.dev: a numbered heading (#agent-mcp-keys-agent--trinity-mcp), an em-dash slug (#first-run-provisioning-honest-setup_completed-2381), and#network-topology-issue-589.harness-authoring-guide.md, three feature-flow docs, andtests/security/README.md.ACs
CLAUDE.md@-imports only the core (test_only_the_core_is_auto_imported)enterprise-docs-guard.ymlscope verified — it grepsdocs/recursively, sodocs/memory/architecture/is already covered. No workflow change. Ran the guard's exact pattern locally against this tree: 0 hitsFollow-up (not in this PR)
Skills in the private
.claudesubmodule that consume the doc need a bump for the new layout:/validate-architecture,/update-docs,/sync-feature-flows, and/autoplancontext loading. Flagged in the issue's own Technical Notes. None of them hard-fail on the new layout (the core still exists at the same path), but they will only see the core until bumped.Tests
tests/unit/test_2306_architecture_split.py— 22 tests, all green, guarding the parts that fail silently: line budget, map/disk bijection, consequence quality, area-file headers, hook-vs-table anti-drift, routing + specificity, once-per-session, fail-open on malformed input, and dangling anchors across the new file boundary.Closes #2306
🤖 Generated with Claude Code
https://claude.ai/code/session_01NqkwYug8AWgQSz34c59oiu