Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion agent-skills/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Agent Skill definitions (one `SKILL.md` per skill directory, per the [agentskill

## Ownership

`do-recall-add`, `do-recall-doctor`, `do-recall-dump`, `do-recall-loa`, `do-recall-recent`, `do-recall-scout`, `do-recall-search`, `do-recall-stats`, `do-recall-update` — each a directory containing `SKILL.md`.
`do-recall-add`, `do-recall-doctor`, `do-recall-dump`, `do-recall-loa`, `do-recall-promote`, `do-recall-recent`, `do-recall-scout`, `do-recall-search`, `do-recall-stats`, `do-recall-update` — each a directory containing `SKILL.md`.

## Local Contracts

Expand Down
67 changes: 67 additions & 0 deletions agent-skills/do-recall-promote/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
name: "do-recall-promote"
description: "Promote learned-tail notes that hold across projects into GAP by opening a pull request. Never writes main and never runs gap sync."
---

Turn Recall notes that hold across projects into a reviewed change to the shared GAP policy. This skill only opens a pull request. The user reviews and merges it, then runs `gap sync` themselves.

## What this does

1. Runs `recall promote --json`. That command is read-only: it lists tail notes that are active, seen in 3 or more distinct projects, in a Recall block written now and for 14 or more days, and not already covered by a published GAP policy file.
2. On a new branch of the GAP checkout, adds the accepted notes to `global/AGENTS.md`.
3. Opens a pull request and stops.

## Never

- Never commit to `main` or `master`, and never push to either.
- Never edit a published harness file (`~/.claude/CLAUDE.md` and the rest). `gap sync` is what publishes, and only the user runs it.
- Never run `gap sync`, `gap remove`, or any command that writes a harness file.
- Never promote a note the user did not accept, and never invent text the JSON did not return.

## Steps

1. **List the candidates.**

```bash
recall promote --json
```

The JSON has `gap`, `candidates`, and `skipped`. Each candidate carries `text`, `records` (`table` and `id`), `projects`, `firstSeen`, `lastSeen`, and `daysInTail`.

Stop and tell the user when `gap` is false (GAP is not installed), when `candidates` is empty, or when the command exits non-zero. There is nothing to promote.

2. **Ask which notes to promote.** Show each candidate's text, projects, record ids, and first/last seen dates. Promote only the ones the user accepts. If they accept none, stop.

3. **Find the GAP checkout.** Ask `gap` where it publishes from. Do not search the filesystem for another clone and do not clone the repo.

```bash
GAP_SRC="$(gap source)" && test -f "$GAP_SRC/global/AGENTS.md"
```

If `gap source` fails or is unknown (a `gap` older than this command), stop and tell the user to update gap.

4. **Branch off the published branch in a worktree.** The checkout may be on another branch or hold uncommitted work, so never switch it, stash, reset, or clean it.

```bash
BRANCH="recall-promote-$(date +%Y-%m-%d)"
git -C "$GAP_SRC" fetch origin
git -C "$GAP_SRC" worktree add "$GAP_SRC/.worktrees/$BRANCH" -b "$BRANCH" origin/HEAD
WT="$GAP_SRC/.worktrees/$BRANCH"
```

`origin/HEAD` is the branch `gap sync` publishes. If the branch or worktree already exists, stop and ask.

5. **Edit `$WT/global/AGENTS.md` only.** Add each accepted note as its own short bullet under the existing `## Work` list, in the user's words from `text`. Do not add a new section, do not touch `global/docs/agents/`, and do not edit any other file. Keep the file's style: no em dashes.

6. **Commit on the branch and open the pull request.**

```bash
git -C "$WT" add global/AGENTS.md
git -C "$WT" commit -m "docs(policy): promote recall notes"
git -C "$WT" push -u origin "$BRANCH"
(cd "$WT" && gh pr create --title "Promote recall notes into the shared policy" --body "<one bullet per note: the text, its projects, and its record ids>")
```

The pull request body lists every promoted note with its record ids (`decisions#123`) and projects, and says the user merges it and then runs `gap sync`.

7. **Stop.** Report the pull request URL and the worktree path (`$WT`), which the user removes with `git -C "$GAP_SRC" worktree remove "$WT"` after the merge. Do not merge it and do not run `gap sync`. After the user does both, the next `recall learn` sees the rule in the GAP block and drops it from the tail.
9 changes: 9 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions docs/agent-skills.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Flush the current session to the database and capture a Library of Alexandria en
**Usage:** `/do-recall-dump Session Title Here`

What it does:

1. Imports the current session's messages into SQLite
2. Creates a Curated LoA entry via the fabric Extractor (or a basic summary with `--skip-fabric`)
3. Makes everything immediately searchable
Expand All @@ -35,11 +36,20 @@ Searches messages, LoA entries, decisions, learnings, and breadcrumbs. The skill

Rule of thumb: use `-t` when you want only one table; use `--bias-type` when you want one table first without hiding other context.

### do-recall-promote

Promote learned-tail notes that hold across projects into the shared GAP policy, as a pull request.

**Usage:** `/do-recall-promote`

Runs `recall promote --json`, then edits `global/AGENTS.md` in the GAP checkout (`~/.gap/checkout`) on a new branch and opens a pull request. It never commits to `main` or `master`, never edits a published harness file, and never runs `gap sync`. The user reviews and merges the pull request, then runs `gap sync`.

### do-recall-recent

Show recent memory records.

**Usage:**

- `/do-recall-recent` — all tables
- `/do-recall-recent decisions` — specific table

Expand All @@ -48,6 +58,7 @@ Show recent memory records.
Memory-first orientation for an unfamiliar codebase. Searches Recall before touching git history or source, then produces a structured scout report in chat.

**Usage:**

- `/do-recall-scout` — scout the whole repo
- `/do-recall-scout auth` — narrow the scout to a subsystem, path, or question

Expand Down
18 changes: 17 additions & 1 deletion docs/cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,17 @@ recall recent # Recent records across all tables
recall recent decisions # Recent decisions only
recall show decisions 5 # Full record for decision #5
recall stats # Database statistics
recall browse # Read-only terminal dashboard
recall browse -p myproject # Same dashboard, one project
recall doctor # Health check all subsystems
```

`recall recent` accepts any table name: `decisions`, `learnings`, `breadcrumbs`, `loa`, `sessions`, `docs`, `telos`.
`recall recent` accepts any table name: `messages`, `decisions`, `learnings`, `breadcrumbs`, `loa`, `sessions`, `docs`, `telos`.

`recall show` displays the full record for a single row. The first argument is the table name, the second is the row ID.

`recall browse` is a read-only dashboard: `1`–`5` switch table, typing filters the current table, `enter` opens a row, `q` quits. It never writes. Piped or non-terminal output prints the decision list instead of taking over the screen. The web dashboard stays tracked in [#221](https://github.com/edheltzel/Recall/issues/221).

---

## Import
Expand Down Expand Up @@ -624,3 +628,15 @@ recall cluster --execute --threshold 0.9
```

`--threshold` is 0.85 by default (0-1).

### Learned tail

`recall learn` writes Recall's best notes into a `<!-- recall:begin -->` ... `<!-- recall:end -->` block in each global harness file, at most 15 bullets and 600 tokens. A note qualifies when it is active, not low confidence, and either has a high-confidence record at importance 8+ (or user-authored) or recurs word for word in 2+ sessions, which is how notes saved at session end reach the tail. Text in backticks keeps its case when notes are compared. With GAP installed it writes to the policy files GAP publishes (`CODEX_HOME` and `JCODE_HOME` included), never to its command files; otherwise to the built-in harness files that already exist. Only the Recall block changes, and a rerun with no change writes nothing. The Stop hook refreshes it on its own.

`recall promote` is read-only. It lists notes seen in 3+ projects that are in a Recall block written now, have been there for 14+ days, and are not already in the GAP block. A note removed from every destination starts a new 14 days when it is written back. The `do-recall-promote` skill turns the accepted ones into a GAP pull request.

```bash
recall learn --dry-run
recall learn --json
recall promote --json
```
1 change: 1 addition & 0 deletions docs/hosts/FOR_CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ These skills are available in any Claude Code session (the former `/Recall:*` sl
| `/do-recall-doctor` | Health check all subsystems |
| `/do-recall-update` | Check-only: prints current vs. latest GitHub release + `cd <path> && ./packaging/update.sh` recipe. Never rebuilds mid-session. |
| `/do-recall-loa` | Browse Library of Alexandria entries |
| `/do-recall-promote` | Open a pull request promoting cross-project learned-tail notes into GAP `global/AGENTS.md`. Never writes main and never runs `gap sync`. |

## Codebase Scouting

Expand Down
50 changes: 50 additions & 0 deletions hooks/RecallExtract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ import { getDbPath } from './lib/sqlite-writers';
import type { DualWriteResult } from './lib/extraction-parsers';
import { runExtractCore } from './lib/extract-core';
import { scrub } from './lib/write-safety';
import {
countRecordsSince,
planLearnedTail,
readTailState,
recordTailRefresh,
tailStatePath,
writeLearnedTail,
} from './lib/learned-tail';

const EXTRACT_LOG = join(process.env.HOME!, '.claude', 'MEMORY', 'EXTRACT_LOG.txt');

Expand Down Expand Up @@ -544,6 +552,42 @@ function appendErrors(fabricOutput: string, sessionLabel: string, timestamp: str
console.error(`[FabricExtract] Appended ${added} new error patterns (${lines.length - added} skipped as duplicates)`);
}

// Stop-hook learned-tail refresh (#279). Refreshes on the first Stop, once 20
// decision + learning rows landed since the last refresh (counted in the DB, so
// concurrent Stops never lose a count), or once the last refresh is 24h old. A
// refused write keeps the old refresh time so the next Stop retries. Runs on
// every Stop (parent, before any early exit) and again after a successful
// extraction lands new rows. Never runs from a session-start hook. Fail-soft: a refresh error is logged and never
// fails the extraction that already landed.
const TAIL_RECORD_INTERVAL = 20;
const TAIL_REFRESH_WINDOW_MS = 24 * 60 * 60 * 1000;

function maybeRefreshLearnedTail(): void {
try {
const dbPath = getDbPath();
if (!existsSync(dbPath)) return;
const statePath = tailStatePath(dbPath);
const state = readTailState(statePath);
const now = Date.now();
const due =
state.refreshedAt === 0 ||
now - state.refreshedAt >= TAIL_REFRESH_WINDOW_MS ||
countRecordsSince(state.refreshedAt, dbPath) >= TAIL_RECORD_INTERVAL;
if (!due) return;
const plan = planLearnedTail({ dbPath });
const writes = writeLearnedTail(plan);
const refused = writes.filter((w) => w.status === 'refused');
if (refused.length > 0) {
logExtract(`LEARNED_TAIL: refused ${refused.map((w) => `${w.path} (${w.reason})`).join(', ')}; retrying next Stop`);
}
if (recordTailRefresh(statePath, plan, writes, new Date(now))) {
logExtract('LEARNED_TAIL: refreshed');
}
} catch (error) {
logExtract(`LEARNED_TAIL: ${error}`);
}
}

/** Log the SQLite dual-write outcome (per-writer failures + per-table summary). */
function logDualWrite(result: DualWriteResult): void {
if (Object.keys(result.failures).length > 0) {
Expand Down Expand Up @@ -695,6 +739,7 @@ async function extractAndAppend(conversationPath: string, cwd: string): Promise<
return;
}
markAsExtracted(convHash);
maybeRefreshLearnedTail();

logExtract(`SUCCESS: All memory files updated for session=${sessionLabel}`);

Expand Down Expand Up @@ -837,6 +882,7 @@ async function extractAndAppendMarkdown(mdPath: string, cwd: string): Promise<vo
return;
}
markAsExtracted(convHash);
maybeRefreshLearnedTail();

logExtract(`SUCCESS (markdown): All memory files updated for ${sessionLabel} (${sessionId})`);

Expand Down Expand Up @@ -993,6 +1039,10 @@ async function main() {

const cwd = hookInput.cwd || process.cwd();

// Every Stop gets a chance to refresh the learned tail, including the
// Empryo, dedup and no-conversation exits below.
maybeRefreshLearnedTail();

// Empryo runs these Claude hooks with its own session log. Capture it as
// `empryo` and stop: the Claude JSONL fallback below would extract an
// unrelated Claude session for this cwd.
Expand Down
Loading
Loading