.md file to compare - side-by-side diff against journal
journal
description: "Triggers on prompt mention of 'journal'."
What it does for you
Saves a quick timestamped note to your daily log.
What it produces
A recent result, so you can see the kind of work it returns.
loading…
How to get it
These run inside the Snappy workspace. Want this working in your business? I set skills like this up with you, in one focused week.
For developers how this skill is built, graded, and how it runs
at a glance- the short version
what's inside - the parts that make up a skill 3/4 present
A skill is just a few plain-text files. Only the main one is required. The rest are optional, added as the work needs them. This is what the skill is made of; how it runs is just below.
state/skills/journal/SKILL.md
present
state/lib/journal.ts
present
state/bin/journal/
not present
state/skills/journal/AGENTS.md
present
how it's graded - what counts as a good run 4 criteria · 3 deterministic · 1 judge
Each row is one thing a good run has to get right. deterministic means a quick check decides, pass or fail. judge means the AI reads the result and rates it. Grading each piece on its own (instead of one overall score) shows exactly where a run fell short, so the fix is obvious.
how it runs - the shared frame every skill uses 5/5 present
Every skill runs the same way. One part does the work, a separate part checks it, and a short loader hands the AI exactly what it needs for the job. Anything this skill doesn't use shows a one-line note saying why, on purpose, not by accident.
state/log/evals.ndjson - Write narrative that evals.ndjson CANNOT express. Rejections-and-why, decisions-and-context, surprises. Never duplicate what the eval row already captures mechanically.
- One line per call. Past tense. If you need a paragraph, you're journaling wrong — split it or put it in a memory/YYYY-MM-DD.md hand-edit.
- UTC only. Daily files roll at UTC midnight. new Date().toISOString() is the only acceptable timestamp source.
- Append-only in spirit. Don't rewrite prior entries. If a prior entry was wrong, add a new entry that corrects it.
- Quiet entries decay. Journal only what a future turn would actually want to know.
what it has learned - fixes written back in over time sample
When a run hits something this skill didn't handle, the fix gets written back into the skill so it doesn't happen again. FIXED means it was corrected on the spot. LOGGED means it's queued for a bigger rewrite. Either way, the skill gets a little better and never makes the same mistake twice.
- Loading feedback rows…
how the work flows- who makes it, who checks it
import { journal } from "../lib/journal.ts"` then `journal("line")
SKILL.md- the skill, written out in plain English
Backed by: state/lib/journal.ts
journal
Raw daily journal. One file per day at state/memory/YYYY-MM-DD.md. Each call appends a timestamped line.
This is half of the through-line layer ported from OpenClaw:
When to use
- Robert rejects / edits / approves a draft → journal why.
- A decision is made that won't be obvious from the diff alone.
- A surprise, a broken assumption, a "huh that's weird."
- Feedback pattern that should influence future turns.
Don't journal what state/log/evals.ndjson already captures mechanically (scores, run ids, primary_issue). Daily notes are for narrative the log can't express.
Steps
import { journal } from "state/lib/journal.ts"(or callnpx tsx state/lib/journal.ts "line").- One short line, past tense. No multi-paragraph entries.
- Prefer linking to source paths when relevant - distill copies them into observations with their provenance.
Eval
Actor: the append call. Auditor: the next read (distill, or a human) confirms the row landed and parses. Shape gate: one line per call, UTC prefix, bullet form. Write shape-check result to state/log/evals.ndjson as skill journal.
Known pitfalls
- Journal noise is worse than empty. Two high-signal lines a day > twenty low-signal ones.
- UTC only. Don't use local time (daily files roll at UTC midnight).
- Append-only in spirit - hand-editing is fine but don't rewrite history.
Rubric
criteria:
- name: journal_entry_format
kind: deterministic
check: "The appended line in state/memory/YYYY-MM-DD.md must start with a UTC timestamp followed by the journal entry."
- name: journal_single_line_entry
kind: deterministic
check: "Each journal invocation must append exactly one line to state/memory/YYYY-MM-DD.md, as verified by line count difference."
- name: journal_entry_relevance
kind: judge
check: "The journal entry should provide relevant narrative context not captured by mechanical logs, explaining a decision, surprise, or feedback."
- name: journal_timestamp_is_utc
kind: deterministic
check: "The timestamp prepended to the journal entry in state/memory/YYYY-MM-DD.md must be in UTC, not local time."AGENTS.md- what the AI loads when this skill comes up
journal - loader
Per-turn rules for the journal skill. Full reference: state/skills/journal/SKILL.md. Do not skip these.
Critical Rules
- Write narrative that evals.ndjson CANNOT express. Rejections-and-why, decisions-and-context, surprises. Never duplicate what the eval row already captures mechanically.
- One line per call. Past tense. If you need a paragraph, you're journaling wrong - split it or put it in a
memory/YYYY-MM-DD.mdhand-edit. - UTC only. Daily files roll at UTC midnight.
new Date().toISOString()is the only acceptable timestamp source. - Append-only in spirit. Don't rewrite prior entries. If a prior entry was wrong, add a new entry that corrects it.
- Quiet entries decay. Journal only what a future turn would actually want to know.
Commands
| ui dashboard | state/skills/journal/resources/ui.openui | |invoke: import { journal } from "../lib/journal.ts" then journal("line") |cli: npx tsx state/lib/journal.ts "short line" |read today: import { readDay } from "../lib/journal.ts"; readDay("2026-04-23") |eval log: state/log/evals.ndjson (skill: "journal")
OpenUI Resource
- Skill-owned OpenUI Lang resource:
state/skills/journal/resources/ui.openui. Read it before rendering or editing this skill's generated component surface. - Treat this resource as a first-class artifact of the skill, not a generic chat response. Improve it when the skill's user-facing output needs to become richer.
- System resources compose OpenUI primitives and inherit SnappyChat tokens. Use
ui_contract: brandedin SKILL.md only for deliberate platform or client visuals.
Known Pitfalls
- Journaling every tool call will blow out the signal. Save for rejections, decisions, and surprises.
- The
distillskill groups by phrase patterns; consistent vocabulary helps ("rejected", "approved", "edited", "decided", "surprised"). - If the line contains a file path, include it verbatim so distill can preserve provenance.
Self-Test
An agent reading this should correctly:
- [ ] Use UTC timestamps via
new Date().toISOString()(not local time)? - [ ] Write narrative that evals.ndjson cannot express (not duplicate log data)?
- [ ] Keep entries to one past-tense line per call?
Self-report
If this loader fell short, append a line:
echo "[$(date -u +%FT%TZ)] journal: <what was missing>" >> state/log/loader-feedback.log
<!-- kernel-ok: historical attribution for the PID-loader pattern. -->
Self-correcting loader (PID feedback)
This is the rule that makes loaders learn. Ported from snappy-kernel, where it demonstrably worked: the snappy-dom-cartographer skill mapped Skool admin UI once, every later ship-agent inherited the full map for free.
Before you finish, do two things:
1. Fix gaps (P - proportional). MANDATORY. If this loader didn't cover your case - if you had to read another file, run an undocumented command, work around a wrong selector, or discover a quirk - you MUST attempt an Edit to this AGENTS.md before you log.
- Default action: edit this file. Surgical. Add the missing line, table
row, or code example where it belongs. No restructuring.
- Only
LOGGEDis allowed when: the fix needs >10 lines, spans multiple
files, or requires a structural rewrite. In that case the state/regen/drain.sh queue picks it up asynchronously.
- "I didn't have time" / "it's minor" / "the next agent will figure it out"
are NOT valid reasons. Minor gaps compound - that's the whole point of this loop.
- Concrete example of a valid P-fix: discover
agent-browser screenshot
takes path positionally not as --output <path>. One line in a table. Edit it in. Do not just log it.
- The goal: the next agent never has to leave the loader.
2. Log the result.
echo "[$(date -u +%FT%TZ)] journal: <what was missing or fixed> [FIXED|LOGGED]" >> state/log/loader-feedback.log
FIXED= you patched this loader inline (P-fix).LOGGED= too large for inline; the PostToolUse enqueue + Stop-hook drain
will rewrite the loader from scratch on next session-end.
Do not skip this. Every agent run must leave the system better than it found it. The loader is the setpoint; you are the sensor; the gap is the error signal; closing the gap is the correction.
api.ts- the code it can call
#!/usr/bin/env npx tsx
/**
* state/lib/journal.ts — append a line to today's daily note, with
* governance: audit log, rate limit, dedup, caller provenance.
*
* The through-line-of-intelligence layer ported from OpenClaw:
* memory/YYYY-MM-DD.md = raw daily journal (this lib)
* observations.md = distilled claims (distill.ts)
* log/journal.ndjson = audit trail (every call, visible in /memory UI)
*
* Write triggers are EXPLICITLY agent-initiated. No stop hook, no daemon,
* no timer. The only two ways a row lands:
*
* (1) A skill calls `journal(line, { caller })` in the current turn.
* (2) A human runs `npx tsx state/lib/journal.ts "line"` from a shell.
*
* If either feels out of control, the /memory screen shows every write
* with its caller, and the rate limit refuses excess writes with a clear
* error. SNAPPY_JOURNAL_MAX_PER_DAY overrides the 200/day default.
*
* CLI:
* npx tsx state/lib/journal.ts "Robert rejected ray-update draft"
*/
import { readFileSync, writeFileSync, existsSync, mkdirSync, appendFileSync, readdirSync } from "node:fs";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
const HERE = dirname(fileURLToPath(import.meta.url));
const REPO = resolve(HERE, "..", "..");
const MEMORY_DIR = resolve(REPO, "state", "memory");
const AUDIT_LOG = resolve(REPO, "state", "log", "journal.ndjson");
const DEFAULT_RATE_LIMIT_PER_DAY = 200;
const DEDUP_WINDOW_MS = 5 * 60 * 1000;
function todayUTC(): string {
return new Date().toISOString().slice(0, 10);
}
function nowUTC(): string {
return new Date().toISOString().replace(/\.\d{3}Z$/, "Z");
}
function ensureDay(date: string): string {
if (!existsSync(MEMORY_DIR)) mkdirSync(MEMORY_DIR, { recursive: true });
const path = resolve(MEMORY_DIR, `${date}.md`);
if (!existsSync(path)) {
writeFileSync(path, `# ${date}\n\n`, "utf8");
}
return path;
}
interface AuditRow {
ts: string;
caller: string;
line: string;
path: string;
session_id?: string;
}
function readAudit(): AuditRow[] {
if (!existsSync(AUDIT_LOG)) return [];
const body = readFileSync(AUDIT_LOG, "utf8");
const rows: AuditRow[] = [];
for (const line of body.split(/\r?\n/)) {
if (!line.trim()) continue;
try { rows.push(JSON.parse(line) as AuditRow); } catch { /* skip */ }
}
return rows;
}
function countToday(audit: AuditRow[], date: string): number {
return audit.filter(r => (r.ts || "").startsWith(date)).length;
}
function rateLimit(): number {
const env = Number(process.env.SNAPPY_JOURNAL_MAX_PER_DAY);
return Number.isFinite(env) && env > 0 ? env : DEFAULT_RATE_LIMIT_PER_DAY;
}
function recentlyWritten(audit: AuditRow[], line: string, now: number): boolean {
for (let i = audit.length - 1; i >= 0; i--) {
const r = audit[i];
if (!r.ts) continue;
const ts = Date.parse(r.ts);
if (!Number.isFinite(ts)) continue;
if (now - ts > DEDUP_WINDOW_MS) return false;
if (r.line === line) return true;
}
return false;
}
export interface JournalOptions {
date?: string;
ts?: string;
caller?: string;
session_id?: string;
force?: boolean;
}
export interface JournalResult {
path: string;
line: string;
skipped?: "dedup" | "rate-limit";
reason?: string;
}
export function journal(line: string, opts: JournalOptions = {}): JournalResult {
const date = opts.date ?? todayUTC();
const ts = opts.ts ?? nowUTC();
const caller = (opts.caller ?? process.env.SNAPPY_JOURNAL_CALLER ?? "unknown").slice(0, 40);
const session_id = opts.session_id ?? process.env.CLAUDE_SESSION_ID ?? process.env.SNAPPY_SESSION_ID;
const trimmed = line.replace(/\s+/g, " ").trim();
if (!trimmed) throw new Error("journal(): empty line");
const path = ensureDay(date);
const audit = readAudit();
if (!opts.force) {
const todayCount = countToday(audit, date);
const limit = rateLimit();
if (todayCount >= limit) {
return { path, line: "", skipped: "rate-limit", reason: `rate limit ${limit}/day reached` };
}
if (recentlyWritten(audit, trimmed, Date.parse(ts))) {
return { path, line: "", skipped: "dedup", reason: "same line written in last 5 min" };
}
}
const row = `- \`${ts}\` ${trimmed}\n`;
appendFileSync(path, row, "utf8");
const auditRow: AuditRow = { ts, caller, line: trimmed, path, session_id };
if (!existsSync(dirname(AUDIT_LOG))) mkdirSync(dirname(AUDIT_LOG), { recursive: true });
appendFileSync(AUDIT_LOG, JSON.stringify(auditRow) + "\n", "utf8");
return { path, line: row };
}
export function readDay(date: string): string {
const path = resolve(MEMORY_DIR, `${date}.md`);
return existsSync(path) ? readFileSync(path, "utf8") : "";
}
export function listDays(): string[] {
if (!existsSync(MEMORY_DIR)) return [];
return readdirSync(MEMORY_DIR)
.filter((f: string) => /^\d{4}-\d{2}-\d{2}\.md$/.test(f))
.map((f: string) => f.slice(0, 10))
.sort();
}
/**
* parseDay(date) -> structured entries for the UI.
* Reads state/memory/YYYY-MM-DD.md and matches audit rows for caller/session.
*/
export interface DayEntry {
ts: string;
text: string;
caller?: string;
session_id?: string;
}
export function parseDay(date: string): DayEntry[] {
const path = resolve(MEMORY_DIR, `${date}.md`);
if (!existsSync(path)) return [];
const body = readFileSync(path, "utf8");
const audit = readAudit();
const auditByTs = new Map<string, AuditRow>();
for (const r of audit) if (r.ts) auditByTs.set(r.ts, r);
const out: DayEntry[] = [];
for (const line of body.split(/\r?\n/)) {
const m = line.match(/^- `([^`]+)` (.+)$/);
if (!m) continue;
const ts = m[1];
const text = m[2];
const a = auditByTs.get(ts);
out.push({ ts, text, caller: a?.caller, session_id: a?.session_id });
}
return out;
}
/**
* governanceState() -> what the /memory UI shows in the Controls panel.
* Tells the operator exactly what can write, and how much has been written.
*/
export interface GovernanceState {
rate_limit_per_day: number;
today_count: number;
today_date: string;
dedup_window_ms: number;
allowed_callers: string[];
audit_log_path: string;
memory_dir: string;
last_10_audit: AuditRow[];
}
export function governanceState(): GovernanceState {
const audit = readAudit();
const date = todayUTC();
return {
rate_limit_per_day: rateLimit(),
today_count: countToday(audit, date),
today_date: date,
dedup_window_ms: DEDUP_WINDOW_MS,
allowed_callers: [
"cli — npx tsx state/lib/journal.ts \"line\"",
"skill — any skill importing journal()",
"http — POST /journal on head-screen (dev UI only)",
],
audit_log_path: AUDIT_LOG.replace(REPO + "/", ""),
memory_dir: MEMORY_DIR.replace(REPO + "/", ""),
last_10_audit: audit.slice(-10).reverse(),
};
}
if (import.meta.url === `file://${process.argv[1]}`) {
const line = process.argv.slice(2).join(" ").trim();
if (!line) {
console.error("usage: journal <line>");
process.exit(2);
}
const r = journal(line, { caller: "cli" });
if (r.skipped) {
process.stderr.write(`skipped (${r.skipped}): ${r.reason}\n`);
process.exit(1);
}
process.stdout.write(`ok: ${r.path}\n${r.line}`);
// eval row: shape check. Actor = the journal() append.
// Auditor = re-parse today's day file, confirm the just-written line is present.
const { append, newRunId } = await import("./log.ts");
const today = todayUTC();
const entries = parseDay(today);
const found = entries.some((e) => e.text === line.replace(/\s+/g, " ").trim());
const run_id = newRunId();
append("evals", {
skill: "journal",
run_id,
mode: "shape",
score: found ? 1 : 0,
entries_today: entries.length,
actor_session_id: `journal-cli-${run_id}`,
auditor_session_id: `journal-shape-${Date.now()}`,
writer_id: "state/lib/journal.ts",
notes: found ? "shape-ok: appended line parsed back" : "shape-fail: append missing on re-parse",
});
}
scripts- helper scripts it can run
prose-only skill - 1 inline code block live in SKILL.md above (no state/bin/ sidecar yet).
how we check it- the checks, plus the last 8 runs
| timestamp | verb | score | primary_issue | artifact |
|---|---|---|---|---|
| 2026-04-25 04:11Z | - | 1.00 | - | - |
| 2026-04-24 06:03Z | - | 1.00 | - | - |
| 2026-04-25 04:11Z | - | 1.00 | - | - |
| 2026-04-24 06:03Z | - | 1.00 | - | - |
| 2026-04-25 04:11Z | - | 1.00 | - | - |
| 2026-04-24 06:03Z | - | 1.00 | - | - |
| 2026-04-25 04:11Z | - | 1.00 | - | - |
| 2026-04-24 06:03Z | - | 1.00 | - | - |