opsward.memory_audit#
Memory audit: fleet-wide rules stranded in project-local auto-memory, and who should own them.
Claude Code’s auto-memory is keyed by working directory: a feedback memory written in one
project loads only in sessions started there. A rule that holds for every project is stranded
in that one. This audit lists every memory of the chosen kinds, then for each one:
scope:
projectorfleet, with the reason (classify(), a heuristic; passclassify=to use a judge instead);duplicates: memories in other directories that say nearly the same thing (
similarity(), lexical, replaceable);owner: for a fleet-wide one, the installed skill whose name and description match it best, else
~/.claude/CLAUDE.md, and whether the owner already says it;stub: a memory that only says it moved elsewhere, listed for deletion.
Report-only: it never writes, moves or deletes a memory. The user curates the table.
>>> parse_frontmatter("---\nname: x\nmetadata:\n type: feedback\n---\nbody")
({'name': 'x', 'type': 'feedback'}, 'body')
Module Attributes
Two memories in different directories at or above this similarity are reported as duplicates. |
|
A skill must match a fleet-wide memory at least this well to be proposed as its owner. |
|
Share of a memory's distinctive words its owner must already hold to say "already there". |
|
Words that mark a rule as a habit for every project. |
|
How many lines of each transcript |
Functions
|
Audit the memories ( |
|
|
|
A memory that says it moved: the marker in its name or opening, or anywhere in a short one. |
|
Every memory of |
|
Whether |
|
|
|
The working directory a project folder is for, read from its transcripts, else |
|
The project a directory names: the last part of its real |
|
Claude Code's folder name for a working directory: every non-alphanumeric is |
|
The audit as a markdown page: fleet-wide memories and their proposed owner first. |
|
Jaccard similarity of two texts' distinctive words. |
|
|
|
The distinctive words of |
Classes
|
One memory file. |
- opsward.memory_audit.COVERED_AT = 0.6#
Share of a memory’s distinctive words its owner must already hold to say “already there”.
- opsward.memory_audit.CWD_SCAN_LINES = 200#
How many lines of each transcript
project_dir()reads looking for acwd.
- opsward.memory_audit.DUPLICATE_AT = 0.45#
Two memories in different directories at or above this similarity are reported as duplicates.
- opsward.memory_audit.FLEET_CUES = re.compile('\\b(always|never|every (?:project|repo|package|session)|in general|whenever|by default|from now on|across (?:the )?(?:fleet|projects|repos))\\b', re.IGNORECASE)#
Words that mark a rule as a habit for every project.
- class opsward.memory_audit.Memory(path, project, kind, name, description, body, modified, project_dir='', scope='', reason='', duplicates=list(), owner='', owner_score=0.0, covered=False, stub=False)[source]#
Bases:
objectOne memory file.
- opsward.memory_audit.OWNER_AT = 0.08#
A skill must match a fleet-wide memory at least this well to be proposed as its owner.
- opsward.memory_audit.audit(*, home=None, kinds=('feedback', ), found=None, skills_dirs=None, global_claude_md=None, read_owner=None, classify=<function classify>, similarity=<function similarity>, duplicate_at=0.45, owner_at=0.08)[source]#
Audit the memories (
found, default:memories()ofhomeandkinds).read_owner(owner)returns an owner’s text, to say whether it already holds the rule (default: the skill’sSKILL.md, or the globalCLAUDE.md).- Return type:
- opsward.memory_audit.classify(memory)[source]#
(scope, reason):projectwhen the memory names its own project (and is not phrased as a habit), elsefleetorprojectby its wording.>>> m = Memory("p", "-x-t-priv", "feedback", "n", "", "Always route LLM calls through aix.", "") >>> classify(m) ('fleet', "worded as a habit ('Always') and does not name priv") >>> classify(Memory("p", "-x-t-priv", "feedback", "n", "", "In priv, the CLI golden must be re-recorded.", "")) ('project', 'names its own project (priv)')
- opsward.memory_audit.is_stub(memory, *, short=400, head=200)[source]#
A memory that says it moved: the marker in its name or opening, or anywhere in a short one.
>>> is_stub(Memory("p", "x", "feedback", "old-rule-SUPERSEDED", "", "x " * 400, "")) True >>> is_stub(Memory("p", "x", "feedback", "rule", "", "Prefer dol. " * 50 + "It replaced by hand.", "")) False
- Return type:
- opsward.memory_audit.memories(home=None, *, kinds=('feedback',))[source]#
Every memory of
kindsunderhome’s project folders (MEMORY.mdindexes excluded).
- opsward.memory_audit.names_project(text, name)[source]#
Whether
textnames the projectname, with-,_and space equivalent and no letter or digit on either side.>>> names_project("Deploys of tw-platform go through deploy.py.", "tw_platform") True >>> names_project("In tw_platform, never rsync.", "platform") True >>> names_project("the iq_platformer tool", "iq_platform") False
- Return type:
- opsward.memory_audit.parse_frontmatter(text)[source]#
(fields, body): flatkey: valuefields of a---block, nestedmetadatakeys lifted to the top (metadata: type: feedbackgivestype).
- opsward.memory_audit.project_dir(folder, *, scan_lines=200)[source]#
The working directory a project folder is for, read from its transcripts, else
"".The folder’s name is a lossy slug (
tw_platformandtw-platformboth givetw-platform), but each transcript records the realcwd. The first one whose slug is the folder’s name wins, newest transcript first.- Return type:
- opsward.memory_audit.project_name(slug, cwd='')[source]#
The project a directory names: the last part of its real
cwdwhen known, else the last part of the slug (lossy:tw_platformcomes back asplatform).>>> project_name("-Users-me-Dropbox-py-proj-t-priv") 'priv' >>> project_name("-Users-me-proj-tt-tw-platform", "/Users/me/proj/tt/tw_platform") 'tw_platform'
- Return type:
- opsward.memory_audit.project_slug(path)[source]#
Claude Code’s folder name for a working directory: every non-alphanumeric is
-.>>> project_slug("/Users/me/proj/tt/tw_platform") '-Users-me-proj-tt-tw-platform'
- Return type:
- opsward.memory_audit.render(result, *, home=None)[source]#
The audit as a markdown page: fleet-wide memories and their proposed owner first.
- Return type:
- opsward.memory_audit.similarity(a, b)[source]#
Jaccard similarity of two texts’ distinctive words.
>>> similarity("prefer the storage facade dol", "the dol storage facade, always") 1.0 >>> similarity("route calls through aix", "route storage through dol") 0.333
- Return type: