| name | tower-consolidate |
| description | Tower ops retention-policy runner. Invoked ONLY as `/tower-consolidate` inside a Tower `internal` ops-pool session (env carries TOWER_OP_ID / TOWER_OP_ARGS / TOWER_NOTIFY_URL). When a scope's live running-log exceeds the consolidation threshold it merges/dedupes notes, archives the originals (never deletes), and re-summarizes. Not for general use. |
| version | 1.1.0 |
tower-consolidate — run the retention policy on a scope
You are a Tower ops agent in the internal project (cwd = vault root). No API
key, no claude -p (invariant 8). You RUN the retention policy on the flat,
scope-as-data vault: the live notes sit in a single flat directory and originals are
archived to <notesDir>/_archive/.
Your job comes from the environment
TOWER_OP_ID, TOWER_NOTIFY_URL as usual.
TOWER_OP_ARGS — JSON: { "scope", "key", "notesDir", "archiveDir" }.
notesDir is the leaf directory that holds the live notes directly (e.g.
memory/feature/<fid> or memory/project/<pseg>). Do NOT append /memory/ to it —
in the flat vault notesDir already IS the notes directory.
Steps
- Count live notes directly in
"$notesDir" (skip the _archive/ subdir and any
note whose frontmatter carries superseded-by). If at/under threshold, nothing to do —
report completion.
- Identify redundant / duplicate notes and write merged replacement note(s) via
the capture bus. You are a RESERVED ops session, so pass the op's target
key explicitly
(the server homes the merged note into the target scope, not your own):
POST $TOWER_NOTIFY_URL/api/memory with {sessionId: "$TOWER_SESSION", scope: "$SCOPE", key: "$KEY", text: "<merged prose>"}.
This keeps the live set small enough that bounded recall stays complete.
- Archive the originals — never delete (invariant 9). Request the mechanical
archive
op on the bus, passing the FLAT {scope, key, notesDir} + the redundant basenames:
curl -s -X POST "$TOWER_NOTIFY_URL/api/ops" -H 'content-type: application/json' \
-d "$(jq -nc --arg s "$SCOPE" --arg k "$KEY" --arg nd "$NOTES_DIR" \
--argjson notes "$REDUNDANT_JSON_ARRAY" \
'{name:"archive", scope:("consolidate:"+$s+":"+$k), args:{scope:$s, key:$k, notesDir:$nd, notes:$notes}}')"
- Optionally chain a re-summary (
POST /api/ops {name:"summarize", scope, args:{scope, key, scopeDir, level}}).
- Report completion:
curl -s -X POST "$TOWER_NOTIFY_URL/api/ops/$TOWER_OP_ID/complete" \
-H 'content-type: application/json' -d '{"ok":true}'
On failure post {"ok":false,"error":"…"}.