specstoryai/getspecstory / lore
lore
FlaggedSpecStory Lore - mine your SpecStory coding histories (any agent - Claude Code, Codex, Cursor, Gemini, and more) into a persistent corpus, surface your reproducible workflows with corroborated evidence, and interactively forge the chosen ones into skills installed across all your agent harnesses. Use when the user wants to turn past AI coding sessions into reusable skills, asks "what could I make into a skill", "mine my lore", "forge skills from my history", or points at a .specstory/history directory.
scripts/lib/db.mjs
View on GitHub// db.mjs - the lore corpus schema (SQLite via node:sqlite, Node >= 22.5; zero deps).
import { mkdirSync } from 'node:fs'
import { dirname } from 'node:path'
import { DatabaseSync } from 'node:sqlite'
// Bump whenever the PARSER's extraction behavior changes: sessions indexed under an older
// parser are automatically re-parsed on the next `index` run (no manual purge needed).
export const PARSER_VERSION = 6 // 6 = shell control-flow keywords dropped from command heads
export function openDb(path) {
mkdirSync(dirname(path), { recursive: true })
const db = new DatabaseSync(path)
// one-time migration: the unit was renamed episode -> beat (2026-06-10). In-place renames so
// existing corpora keep their expensive artifacts (themes, dossiers) without re-mining.
try { db.exec('ALTER TABLE episodes RENAME TO beats') } catch { /* already migrated or fresh */ }
for (const [t, a, b] of [['commands', 'episode_id', 'beat_id'], ['grams', 'episode_id', 'beat_id'],
['meta_hits', 'episode_id', 'beat_id'], ['themes', 'episode_keys', 'beat_keys'], ['sessions', 'episodes', 'beats']]) {
try { db.exec(`ALTER TABLE ${t} RENAME COLUMN ${a} TO ${b}`) } catch { /* already migrated or fresh */ }
}
db.exec(`
PRAGMA journal_mode=WAL;
PRAGMA busy_timeout=10000; -- concurrent runs (e.g. a session-end hook + a manual index) wait, not crash
CREATE TABLE IF NOT EXISTS sessions(
id TEXT PRIMARY KEY, project_id TEXT, project_name TEXT, path TEXT, date TEXT,
agent TEXT, size INTEGER, beats INTEGER);
CREATE TABLE IF NOT EXISTS beats(
id INTEGER PRIMARY KEY AUTOINCREMENT, session_id TEXT, ord INTEGER, start_line INTEGER,
intent_raw TEXT, intent_sig TEXT,
n_tools INTEGER, tool_mix TEXT, files TEXT, n_cmds INTEGER, exit_fails INTEGER,
outcome TEXT);
CREATE TABLE IF NOT EXISTS commands(
beat_id INTEGER, ord INTEGER, head TEXT, raw TEXT, line INTEGER);
CREATE TABLE IF NOT EXISTS grams(
beat_id INTEGER, n INTEGER, gram TEXT);
CREATE TABLE IF NOT EXISTS meta_hits(
beat_id INTEGER, meta_id TEXT, quote TEXT, line INTEGER);
CREATE INDEX IF NOT EXISTS idx_ep_session ON beats(session_id);
CREATE INDEX IF NOT EXISTS idx_grams ON grams(gram);
CREATE INDEX IF NOT EXISTS idx_meta ON meta_hits(meta_id);
CREATE INDEX IF NOT EXISTS idx_cmd_ep ON commands(beat_id);
`)
// migrations for corpora created before these columns existed
for (const col of ['mtime INTEGER DEFAULT 0', 'parser INTEGER DEFAULT 0', "author TEXT DEFAULT ''", "uuid TEXT DEFAULT ''"]) {
try { db.exec(`ALTER TABLE sessions ADD COLUMN ${col}`) } catch { /* already there */ }
}
return db
}
// ---------- the runs journal: Lore's memory of its own activity ----------
// One row per notable engine invocation (auto) plus one per /lore run (the agent's Step 6 duty).
// This is what makes "what has Lore done?" a query instead of archaeology.
export function ensureRunsTable(db) {
db.exec(`CREATE TABLE IF NOT EXISTS runs(
id INTEGER PRIMARY KEY AUTOINCREMENT, ts TEXT, cmd TEXT, scope TEXT, summary TEXT)`)
}
export function addRun(db, cmd, scope, summary) {
ensureRunsTable(db)
db.prepare('INSERT INTO runs(ts, cmd, scope, summary) VALUES(?,?,?,?)')
.run(new Date().toISOString(), cmd, scope || '', summary || '')
}
export function listRuns(db, limit = 10) {
ensureRunsTable(db)
return db.prepare('SELECT ts, cmd, scope, summary FROM runs ORDER BY id DESC LIMIT ?').all(limit)
}
// Delete a session's beat children + beats (shared by re-index and prune).
export function deleteSessionRows(db, sessionId) {
for (const r of db.prepare('SELECT id FROM beats WHERE session_id=?').all(sessionId)) {
for (const t of ['commands', 'grams', 'meta_hits']) db.prepare(`DELETE FROM ${t} WHERE beat_id=?`).run(r.id)
}
db.prepare('DELETE FROM beats WHERE session_id=?').run(sessionId)
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 471k | Updated | Claude CodeCodex | Verified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |