Condense memory

From event4u-app/agent-config · View interactive version

Condense memory is an AI agent skill from the GitHub repository event4u-app/agent-config. When shrinking always-loaded memory files (AGENTS.md, CLAUDE.md, .cursorrules) exceeding ~150 lines or ~4,000 chars — telegraph grammar, refuses sensitive paths, .original.md round-trip.

How to use this skill

Skill file

condense-memory

<!-- cloud_safe: noop -->

Experimental. Output-side telegraph dialect did not meet the kill-criterion in CODE0 (vs_terse median −9.27 %). Input-side memory condensation is an orthogonal use case: the savings target the always-loaded memory budget, not the reply stream. Treat ship-criterion as per-target measurement, not the v1 verdict.

When to use

Use when:

Do NOT

Procedure

  1. Analyse the target first. Before any write, inspect the target with view or wc -l to confirm it is an always-loaded memory file (AGENTS.md, CLAUDE.md, .cursorrules, GEMINI.md, .windsurfrules), is not generated, and has prose paragraphs to condense (a pointer-only Thin-Root file may net near-zero). Skip the rest of the procedure if any check fails.
  2. Check denylist gate. Run ./scripts-run src/scripts/condense_memory <path> --check — exit 0 = safe; exit 2 = denylist hit, stop and surface the refusal.
  3. Record baseline. wc -c <path> — capture pre-condensation char count for the commit message.
  4. Condense. ./scripts-run src/scripts/condense_memory <path>. The script writes <path>.original.md (verbatim backup) and rewrites <path> with original_sha256: + condensed_at: frontmatter.
  5. Inspect the diff. Eyeball every Iron-Law fence, numbered-options block, code fence, backtick span, ❌/⚠️/✅ line, and frontmatter pair — all must be byte-identical. Body prose may have lost articles (the/a/an) and auxiliaries (is/are/was/be/that/which).
  6. Validate idempotency. Re-run ./scripts-run src/scripts/condense_memory <path> — clean re-run is a no-op (body hash matches). Non-zero exit = stop, escalate.
  7. Commit both files together. <path> and <path>.original.md ship as a pair. The backup is the rollback path; never commit one without the other.
  8. Rollback path. If readability fails review at step 5: ./scripts-run src/scripts/condense_memory <path> --decondense restores the backup and deletes .original.md.

Output format

The maintainer-facing report after invoking the script MUST contain, in this order:

  1. Diff line — pre/post wc -c as a single line (AGENTS.md: 2,891 → 2,453 chars (−15.1 %)).
  2. Backup path — full path of the .original.md backup so the maintainer can verify it landed on disk.
  3. Carve-out check — one line confirming the seven carve-out classes round-tripped (carve-outs: 7 classes preserved · idempotent re-run: clean).
  4. Exit-code surface — on failure, surface the verbatim exit code and exception name (SensitivePathError → exit 2, CondensationRefused → exit 3, FileNotFoundError → exit 4); do not paraphrase.

Do not narrate the algorithm, the grammar rules, or the carve-out theory — the rule and this skill document the contract; the output reports the result.

Carve-outs — byte-for-byte preserved

Mirrors the seven carve-out classes in CODE0. The condensation engine in CODE1 preserves:

  1. Triple-backtick fences — any language, any depth.
  2. Numbered-options lines — ^>?\s*\d+\.\s plus the **Recommendation:** / **Empfehlung:** label.
  3. Backtick spans — file paths, command names, identifiers inside body prose.
  4. Status / error markers — lines starting with ❌, ⚠️, ✅.
  5. Iron-Law ALL-CAPS lines — ^[A-Z][A-Z0-9 ,.\-_/']{3,}$.
  6. Frontmatter blocks — --- fence pairs at the head of the file.
  7. Mode markers per CODE0.

Mangling any of these breaks the Iron-Law surface the host tool reads. The unit tests in tests/scripts/condense_memory.test.ts lock each carve-out class as a regression case.

Idempotency contract — Step 9 guard

The script is idempotent on clean re-runs: running it twice on the same target is a no-op because the body hash matches the recondensed hash. The script refuses on body drift:

| State | Outcome |

|---|---|

| No frontmatter SHA marker | Condense + write backup + inject SHA. |

| SHA marker present, body re-condenses to same hash | No-op (return target unchanged). |

| SHA marker present, body hash diverged | Refuse with CondensationRefused exit 3. |

If you need to edit a condensed memory file, run --decondense first, edit the restored .original.md content, then re-run the condenseor. Never hand-edit the condensed body — the next CI run will either silently corrupt your edit (if it happens to re-condense to the same shape) or hard-fail the next condense pass.

Sensitive-path gate

Every read path passes through CODE0 assert_safe() before bytes leave disk. The gate is the security floor for Phase 2 (input-side condensation) per step-16-telegraph-substance.md Phase 0; rollback of the gate is rollback of this skill.

CLI exit codes:

Gotchas

Measurement — when to condense

There is no published telegraph-v2 baseline for input-side savings yet (Step 11 of step-16-telegraph-substance.md ships that). Until then, the maintainer judges per-target whether the condensation pays its readability cost. Suggested workflow:

  1. wc -c <path> before — record baseline char count.
  2. ./scripts-run src/scripts/condense_memory <path> — condense + back up.
  3. wc -c <path> after — record post-condensation char count.
  4. Eyeball the diff: does the prose stay legible? Are all Iron-Law fences intact?
  5. If yes → commit both <path> and <path>.original.md. If no → --decondense.

A future telegraph-v2.md will tabulate the realised input-token saving against the agents-md-thin-root 40 % pointer-ratio constraint so the maintainer has a numerical floor.

Cross-references

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.