Summary
This issue proposes a pragmatic agent skill, tentatively named repository-memory.
The central idea is not to generate repository documentation in a separate phase. It is to preserve the smallest durable semantic discoveries agents make while doing verified engineering work:
As agents develop a repository, they selectively promote non-obvious, durable knowledge into tiny, scoped capsules. Future agents retrieve only relevant capsules that pass freshness checks; when validation is uncertain, they fall back to investigating the repository.
Most tasks should produce no memory update. A capsule is created or changed only when an agent had to reconstruct knowledge that would be expensive and useful to reconstruct again.
This is specialized living documentation distinguished by its protocol and governance: admission during real work, minimal deltas, explicit invalidation dependencies, human review, selective retrieval, and refusal of uncertain memory.
Problem
Agents repeatedly inspect the same files to rediscover:
- what a subsystem is responsible for;
- how control flows across several files;
- which invariants must remain true;
- which boundaries and dependencies are non-obvious;
- which recurring failure modes have already required investigation.
Code remains the source of truth, but this knowledge is often distributed across implementation, tests, configuration, and architecture decisions. Once a task ends, the reconstructed mental model disappears and the next agent pays the same discovery cost.
A broad repository overview is not an adequate substitute: it is loaded too often, contains irrelevant information, and becomes stale as a large unit.
Core workflow
Colocate semantic capsules with the high-value subsystems or code scopes they describe:
src/
├── auth/
│ ├── AGENT_MEMORY.md
│ ├── session.ts
│ └── oauth-state.ts
├── billing/
│ ├── AGENT_MEMORY.md
│ └── reconciliation.ts
└── jobs/
├── AGENT_MEMORY.md
└── scheduler.ts
Do not create one capsule per folder. Add AGENT_MEMORY.md only when real development work exposes durable knowledge worth preserving for that area. Cross-cutting knowledge belongs at the nearest common ancestor of the code it describes, with explicit scope metadata.
DEVELOP normally
→ DISCOVER a non-obvious fact
→ VERIFY it against current code, tests, configuration, or an ADR
→ DECIDE whether it is durable and likely to prevent future rediscovery
→ PROPOSE the smallest possible capsule delta
→ REVIEW it with the code change
→ RETRIEVE it selectively in future tasks
→ WITHHOLD it when its supporting code changes or validation is uncertain
The unit of learning is not the completed task. It is the smallest durable semantic delta discovered during that task.
Capsule format
A capsule should normally remain around 100–150 words. It may contain subsystem responsibility, cross-file flow, invariants, boundaries, recurring failure modes, and evidence. Paths and stable symbols are preferable to line numbers.
---
scope:
- src/auth/**
evidence:
- src/auth/session.ts#SessionService
- src/routes/oauth-callback.ts#restoreDestination
- tests/auth/oauth-callback.test.ts
invalidated_by:
- src/auth/oauth-state.ts
- src/routes/oauth-callback.ts
claims:
- statement: The OAuth callback restores the original destination.
verifier: tests/auth/oauth-callback.test.ts
---
# How this part of authentication works
- Token renewal happens only in `SessionService`; route handlers delegate the operation to it.
- Before sending the user to the OAuth provider, the system stores the page they requested.
- When the user returns from the provider, the callback retrieves that page and redirects them to it.
- If the OAuth callback or the stored-state format changes, this capsule must be revalidated.
Claim-level verification is useful for critical invariants and observable behavior, but should not be required for every architectural statement.
The minimal schema is typed as follows:
scope: one or more repository-relative files or globs defining where the capsule applies;
evidence: one or more repository-relative files, optionally followed by #symbol for human navigation;
invalidated_by: optional additional repository-relative files or globs whose changes may falsify the capsule;
claims: optional objects containing a descriptive statement and a repository-relative verifier file, never a command.
The checker strips #symbol before path validation. Unknown keys, absolute paths, URLs, and parent-directory traversal are rejected.
Promotion gate
An agent may propose a capsule delta only when the knowledge is:
- Non-obvious: not recoverable from one obvious local file.
- Reusable: likely to matter in another task touching the same scope.
- Durable: about the repository, not the current task or conversation.
- Supported: tied to code, tests, configuration, or an architectural decision.
- Falsifiable: mapped to changes that require revalidation.
- Minimal: expressible as a small delta rather than a broad rewrite.
If any condition fails, do not write repository memory. The information belongs in a task handoff, temporary investigation notes, code comments, or nowhere.
Continuous learning must not become automatic summarization after every task.
Proposed v1
The first version would contain only:
- a
SKILL.md defining discovery, promotion, review, retrieval, corroboration, and pruning;
- a minimal capsule schema with required
scope and evidence, plus optional invalidated_by and claims;
- a required
check-memory.sh step before retrieval, returning machine-readable state;
- fixture-based evals covering correct admission, no-op tasks, selective retrieval, stale capsules, and structurally unsafe metadata.
It would not include a knowledge graph, daemon, vector database, automatic documentation generator, or enforced harness integration.
Example checker output:
{
"state": "stale",
"usable": false,
"changed_paths": ["src/auth/session.ts"]
}
The checker would validate metadata, require repository-relative paths, compare mapped paths against Git changes, identify declared verifier files, and return JSON. It would never execute commands embedded in a capsule.
For v1, freshness would use one conservative algorithm:
- the repository owner configures a trusted base ref, such as
origin/main;
- the capsule must exist on that ref and the working-tree copy must be byte-identical, otherwise it is
proposed;
- the checker finds the last commit on the trusted ref that changed that capsule;
- the invalidation set is the union of path portions from
scope, evidence, invalidated_by, and claim verifiers;
- the checker compares that commit’s tree with the current HEAD, index, working tree, and relevant untracked files;
- any modification, addition, deletion, or rename in the invalidation set returns
stale; an unresolved ref, invalid glob, missing evidence, or indeterminate comparison returns unknown.
Globs are expanded against both the trusted commit and current workspace. Tree comparison rather than commit counting makes squash, rebase, and nonlinear history conservative: uncertainty returns unknown, never usable content.
Task-to-capsule matching would begin from task paths when known, then be recomputed after initial repository localization. The agent discovers conventional AGENT_MEMORY.md files colocated with candidate directories and their ancestors, then filters them by declared scope. Overlapping capsules would all be candidates; no capsule would override another silently.
Computed state and human approval
State should be computed rather than trusted from editable frontmatter:
proposed: the capsule is absent from or differs from the configured trusted base ref;
verified: the capsule is byte-identical to its trusted-base version and no path in its invalidation set has changed since the commit that last modified it;
stale: a mapped path changed, was renamed, or was deleted;
unknown: Git history, metadata, or validation could not be resolved.
Only verified is eligible for retrieval. proposed, stale, and unknown return no capsule content.
A new or changed capsule should be reviewed in the same pull request as the code that motivated it. The checker only knows whether the capsule exists on the configured trusted ref; it cannot prove that the branch is protected or that a human approved the merge. Human review and branch protection are explicit external governance assumptions. Platform attestations or API verification may be considered later. No self-authored status: verified field is trusted.
Retrieval and safety contract
Before using repository memory, an agent must:
- locate matching capsules;
- run the checker;
- retrieve content only for
verified results;
- use it as an investigation hypothesis, not as authority;
- corroborate any claim that materially affects the planned change.
The v1 contract is procedural, not a hard access-control guarantee:
When the skill is followed, no capsule that differs from the trusted-base version, has changed declared dependencies, or has uncertain state is returned for use.
A future harness could enforce retrieval exclusively through the checker. That stronger boundary is outside v1.
The threat model should also state:
- capsules are descriptive data, never executable instructions or directives that override the task;
- paths must remain inside the repository;
- embedded commands are never executed;
- the Markdown body is untrusted descriptive data; instruction-like content is ignored and surfaced for review, but v1 does not claim deterministic prompt-injection detection;
- human approval reduces risk but does not prove semantic truth;
- incomplete
invalidated_by declarations remain a known limitation.
Relationship to existing work
context-engineering selects context for the current task; this proposal governs which verified codebase knowledge is worth preserving and when it must be withheld.
- #15 concerns learning from sessions and feedback; these capsules store semantic knowledge about the current codebase.
- #18 concerns project conventions; capsules describe a particular subsystem.
- #274 and PR #237 concern episodic handoff state; capsules are durable and code-scoped.
- PR #253 proposes a broader agent harness; this issue isolates the promotion, retrieval, and invalidation of tiny repository-semantic deltas.
The issue should determine whether this becomes a separate skill, an extension of context-engineering, or a protocol reused by a broader harness skill.
Evaluation and safety objective
The desired outcome is that stale memory does not degrade performance relative to working without memory. A Markdown skill cannot guarantee this for every task: dependency declarations may be incomplete, an approved claim may be wrong, and an agent may fail to follow the workflow.
Evaluation should compare:
- repository only;
- repository plus a generic overview;
- repository plus selectively promoted and retrieved capsules.
Use sequential tasks over evolving repository versions, including useful rediscovery, irrelevant memory, no-op promotion, changed dependencies, incomplete invalidation metadata, structurally unsafe metadata, instruction-like body text, and a critical claim with a verifier.
Measure task correctness, rediscovery tool calls and tokens, stale-memory retrieval, false writes, and review cost. Any non-inferiority study must predefine its primary correctness metric, acceptable regression margin, number of runs, and confidence interval; absence of a statistically significant difference is not sufficient.
The initial acceptance criterion should be narrower and deterministic: every fixture with a changed declared dependency, unsafe path, malformed capsule, or unresolved state must return no capsule content.
Non-goals
- A summary for every directory or an update after every task.
- Agent transcripts or chain of thought.
- Replacing code, tests, ADRs, API documentation, or handoffs.
- Loading repository-wide memory into every task.
- Trusting fresh metadata as proof of semantic truth.
- Building a repository knowledge graph or long-running memory service in v1.
Research grounding
Related work includes generic repository-context evaluation (Evaluating AGENTS.md), change-aware modular documentation (RepoDoc), explicit memory admission (A-MAC), risks from repeated consolidation (Useful Memories Become Faulty), and longitudinal coding-agent evaluation (SWE-Bench-CL).
The individual mechanisms are not scientifically new. The potentially distinctive contribution here is a small, specific workflow in which tiny semantic capsules emerge incrementally from verified development work and are governed by selective admission, human approval, scoped retrieval, and conservative invalidation.
Open questions
- Is this distinct enough for
repository-memory, or should it extend context-engineering?
- Is
AGENT_MEMORY.md the right conventional filename, and is the nearest common ancestor the right location for cross-cutting capsules?
- Should 100–150 words be guidance or an enforced budget?
- What minimum evidence and invalidation metadata is required?
- Should future versions use hosting-platform attestations to verify human approval?
- Should allowlisted project-specific verifier commands be considered after v1?
Pre-flight note
The catalog, related open issues, and open pull requests were searched before drafting this proposal. The items above are the closest overlaps found and should be treated as related work.
Summary
This issue proposes a pragmatic agent skill, tentatively named
repository-memory.The central idea is not to generate repository documentation in a separate phase. It is to preserve the smallest durable semantic discoveries agents make while doing verified engineering work:
Most tasks should produce no memory update. A capsule is created or changed only when an agent had to reconstruct knowledge that would be expensive and useful to reconstruct again.
This is specialized living documentation distinguished by its protocol and governance: admission during real work, minimal deltas, explicit invalidation dependencies, human review, selective retrieval, and refusal of uncertain memory.
Problem
Agents repeatedly inspect the same files to rediscover:
Code remains the source of truth, but this knowledge is often distributed across implementation, tests, configuration, and architecture decisions. Once a task ends, the reconstructed mental model disappears and the next agent pays the same discovery cost.
A broad repository overview is not an adequate substitute: it is loaded too often, contains irrelevant information, and becomes stale as a large unit.
Core workflow
Colocate semantic capsules with the high-value subsystems or code scopes they describe:
Do not create one capsule per folder. Add
AGENT_MEMORY.mdonly when real development work exposes durable knowledge worth preserving for that area. Cross-cutting knowledge belongs at the nearest common ancestor of the code it describes, with explicit scope metadata.The unit of learning is not the completed task. It is the smallest durable semantic delta discovered during that task.
Capsule format
A capsule should normally remain around 100–150 words. It may contain subsystem responsibility, cross-file flow, invariants, boundaries, recurring failure modes, and evidence. Paths and stable symbols are preferable to line numbers.
Claim-level verification is useful for critical invariants and observable behavior, but should not be required for every architectural statement.
The minimal schema is typed as follows:
scope: one or more repository-relative files or globs defining where the capsule applies;evidence: one or more repository-relative files, optionally followed by#symbolfor human navigation;invalidated_by: optional additional repository-relative files or globs whose changes may falsify the capsule;claims: optional objects containing a descriptivestatementand a repository-relativeverifierfile, never a command.The checker strips
#symbolbefore path validation. Unknown keys, absolute paths, URLs, and parent-directory traversal are rejected.Promotion gate
An agent may propose a capsule delta only when the knowledge is:
If any condition fails, do not write repository memory. The information belongs in a task handoff, temporary investigation notes, code comments, or nowhere.
Continuous learning must not become automatic summarization after every task.
Proposed v1
The first version would contain only:
SKILL.mddefining discovery, promotion, review, retrieval, corroboration, and pruning;scopeandevidence, plus optionalinvalidated_byandclaims;check-memory.shstep before retrieval, returning machine-readable state;It would not include a knowledge graph, daemon, vector database, automatic documentation generator, or enforced harness integration.
Example checker output:
{ "state": "stale", "usable": false, "changed_paths": ["src/auth/session.ts"] }The checker would validate metadata, require repository-relative paths, compare mapped paths against Git changes, identify declared verifier files, and return JSON. It would never execute commands embedded in a capsule.
For v1, freshness would use one conservative algorithm:
origin/main;proposed;scope,evidence,invalidated_by, and claim verifiers;stale; an unresolved ref, invalid glob, missing evidence, or indeterminate comparison returnsunknown.Globs are expanded against both the trusted commit and current workspace. Tree comparison rather than commit counting makes squash, rebase, and nonlinear history conservative: uncertainty returns
unknown, never usable content.Task-to-capsule matching would begin from task paths when known, then be recomputed after initial repository localization. The agent discovers conventional
AGENT_MEMORY.mdfiles colocated with candidate directories and their ancestors, then filters them by declared scope. Overlapping capsules would all be candidates; no capsule would override another silently.Computed state and human approval
State should be computed rather than trusted from editable frontmatter:
proposed: the capsule is absent from or differs from the configured trusted base ref;verified: the capsule is byte-identical to its trusted-base version and no path in its invalidation set has changed since the commit that last modified it;stale: a mapped path changed, was renamed, or was deleted;unknown: Git history, metadata, or validation could not be resolved.Only
verifiedis eligible for retrieval.proposed,stale, andunknownreturn no capsule content.A new or changed capsule should be reviewed in the same pull request as the code that motivated it. The checker only knows whether the capsule exists on the configured trusted ref; it cannot prove that the branch is protected or that a human approved the merge. Human review and branch protection are explicit external governance assumptions. Platform attestations or API verification may be considered later. No self-authored
status: verifiedfield is trusted.Retrieval and safety contract
Before using repository memory, an agent must:
verifiedresults;The v1 contract is procedural, not a hard access-control guarantee:
A future harness could enforce retrieval exclusively through the checker. That stronger boundary is outside v1.
The threat model should also state:
invalidated_bydeclarations remain a known limitation.Relationship to existing work
context-engineeringselects context for the current task; this proposal governs which verified codebase knowledge is worth preserving and when it must be withheld.The issue should determine whether this becomes a separate skill, an extension of
context-engineering, or a protocol reused by a broader harness skill.Evaluation and safety objective
The desired outcome is that stale memory does not degrade performance relative to working without memory. A Markdown skill cannot guarantee this for every task: dependency declarations may be incomplete, an approved claim may be wrong, and an agent may fail to follow the workflow.
Evaluation should compare:
Use sequential tasks over evolving repository versions, including useful rediscovery, irrelevant memory, no-op promotion, changed dependencies, incomplete invalidation metadata, structurally unsafe metadata, instruction-like body text, and a critical claim with a verifier.
Measure task correctness, rediscovery tool calls and tokens, stale-memory retrieval, false writes, and review cost. Any non-inferiority study must predefine its primary correctness metric, acceptable regression margin, number of runs, and confidence interval; absence of a statistically significant difference is not sufficient.
The initial acceptance criterion should be narrower and deterministic: every fixture with a changed declared dependency, unsafe path, malformed capsule, or unresolved state must return no capsule content.
Non-goals
Research grounding
Related work includes generic repository-context evaluation (Evaluating AGENTS.md), change-aware modular documentation (RepoDoc), explicit memory admission (A-MAC), risks from repeated consolidation (Useful Memories Become Faulty), and longitudinal coding-agent evaluation (SWE-Bench-CL).
The individual mechanisms are not scientifically new. The potentially distinctive contribution here is a small, specific workflow in which tiny semantic capsules emerge incrementally from verified development work and are governed by selective admission, human approval, scoped retrieval, and conservative invalidation.
Open questions
repository-memory, or should it extendcontext-engineering?AGENT_MEMORY.mdthe right conventional filename, and is the nearest common ancestor the right location for cross-cutting capsules?Pre-flight note
The catalog, related open issues, and open pull requests were searched before drafting this proposal. The items above are the closest overlaps found and should be treated as related work.