npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

chatluna-diary

v0.2.3

Published

Per-preset diary, conversation digest, stacked brush marks, media and scheduled writing for ChatLuna v2 WebUI.

Readme

chatluna-diary

A per-preset diary for ChatLuna v2 WebUI: read the day's real conversation digest, write or append a Markdown entry, place a stacked hand-drawn brush mark, attach images from the agent workspace, and let a scheduled job write at 22:00.

What it does

  • One book per preset under data/chatluna/diary/<presetId>/.
  • Three model-facing tools, split by intent:
    • diary_read — action: "list" | "read" | "context" | "history" | "history_diff": one paginated index page (dates, marks, titles, first lines; before/limit), existing entries (up to 7 days / ~12k chars), a bounded day digest, one page of commit history, and a bounded diff for one commit (the last two interactive chats only).
    • diary_write — action: "write" | "mark" | "attach": append/replace writing, 1–5 marks, and workspace image copy.
    • diary_manage — action: "export" | "format" | "delete" | "restore": explicit-date export, conservative formatting, deletion, and restoring the before/after side of a commit while the current content and marks still match; always offered to the AI.
  • Marks are one mark, stacked: a single hand-drawn vermilion brush circle is repeated 1–5 times for levels 1–5. The mask is shipped inline; no external image request.
  • Scheduled writing: one job per preset at local 22:00 (0 22 * * *), with the preset locked to its own book. The book header exposes run / pause / resume / permanently stop; a stop is persisted in data/chatluna/diary/.schedule-v1.json and is never resurrected by a restart.
  • History: every write, edit, delete, mark, format and restore appends a git-like commit; the history drawer shows a timeline, a bounded unified diff, and can restore either side of a change. Deleted days stay recoverable after the .md file is gone. The model sees the same log through diary_read history/history_diff and can restore the newest change of one date while nothing has changed since; older versions are restored from that day's own history in the WebUI.
  • WebUI: a V2 book page, calendar with marks, index, reading pane, media blob loading, and a hidden /diary/preview layout showcase.
  • Management: each book card has a corner menu (export all, format, delete all); the book header has a batch button for marquee-selecting days and exporting/deleting them. Day configuration lives in each entry's ... icon menu (edit/delete entry, mark level, delete day); new entries use the bottom composer. There is no all-in-one management modal, separate paper toolbar, or manual AI-write button.
  • Tool loading: all three diary tools are marked resident (deferred: false), so a scheduled run can call the ones it is allowed to see even when tool search is on.

Install

This is a ChatLuna data plugin. Place it where ChatLuna loads plugins and build the client:

cd data/chatluna/plugins/chatluna-diary
npm install
npm run build
# restart ChatLuna

The server loads index.ts; the browser bundle is dist/client.js. The package also works as an npm source package (npm i chatluna-diary) if your deployment symlinks or copies the package into the plugin directory.

Windows source

Put the checkout under the projects/ column:

New-Item -ItemType Directory -Force <workspace>\projects
Set-Location <workspace>\projects
git clone https://github.com/yabo083/chatluna-diary.git
Set-Location chatluna-diary
Set-ExecutionPolicy -Scope Process Bypass
.\scripts\windows-bootstrap.ps1 -SourceRoot (Get-Location).Path

The script installs, tests, builds, initializes git if needed, and pushes to GitHub. It never stores an npm token.

Requirements

  • ChatLuna v2 (@chatluna/* 2.0.0-alpha line)
  • Node.js 22+
  • A WebUI deployment with chatluna_webui, tools, presets, schedule services

Data layout

data/chatluna/diary/<presetId>/
  YYYY-MM-DD.md      one day, possibly several "## title" entries
  marks.json         { "version": 1, "marks": { "YYYY-MM-DD": { level, note?, updatedAt } } }
  media/             images copied by the diary_write attach action
  .history/
    commits.jsonl    append-only commit log; a torn last line is ignored
    objects/<sha256> exact day bytes, deduplicated across commits
data/chatluna/diary/.schedule-v1.json
                     per-book schedule registry and cancel tombstones

presetId is sanitized to [A-Za-z0-9][A-Za-z0-9._-]*; anything else falls back to default. A normal chat cannot write another preset's book; only the scheduled runner may pass presetId for its own job. If a conversation switched presets in place, only entries after the most recent chatluna:preset switch are eligible for the current preset; earlier segments are discarded rather than mixed into the diary.

Each day file is capped at 1 MiB for normal reads and writes. A legacy day above the cap is unreadable to read and export and is skipped by format; deleting it is refused rather than losing text the history cannot record. marks.json is capped at 1 MiB; on repair, a damaged or oversized marks file is moved aside to a timestamped backup.

Tools

| Tool | Actions | Purpose | | --- | --- | --- | | diary_read | list | One compact-index page: dates, mark levels, entry titles and first lines — no bodies; reports the whole-book total | | | read | Existing entries for the current preset (up to 7 days / ~12k chars) | | | context | Bounded digest of the day's real conversation, tool noise excluded | | | history | One page (≤8,192 UTF-8 bytes) of commit metadata (id, date/time, source, op, summary, byte sizes) for one date or the whole book; historyLimit 1–24 default 12, cursor is an opaque commit id from next=<id> (next=none when exhausted); interactive chats only | | | history_diff | Bounded unified diff for one commit id (≤12,288 UTF-8 bytes / 80 lines); a mark-only change is reported apart from a missing commit; interactive chats only | | diary_write | write | Append or replace one day's Markdown | | | mark | Set mark level 1–5 plus an optional 80-char note | | | attach | Copy a workspace image and return a diary-media: Markdown tag | | diary_manage | export | Export explicitly named dates chosen from list | | | format | Add a missing date header and normalize line endings; body syntax preserved | | | delete | Delete named dates; absent dates are reported, not errors | | | restore | Restore the before or after side of one commit id as a new commit; only while current content and marks still match the opposite side |

diary_read action list is the discovery entry. It returns at most one metadata page (before is an exclusive date, limit defaults to 30 and caps at 100), includes mark-only dates, reports the book total, and names the before value for the next older page. A day over the size cap shows as skipped.

diary_manage always exposes export, format, delete and restore to the model; there is no plugin config gate or action allow-list. export requires explicit dates picked from list — there is no implicit whole-book export — and fails explicitly when the result exceeds its output budget. format only adds a missing # YYYY-MM-DD header and normalizes line endings, preserving body syntax, code and hard breaks; it locks one day at a time, skips oversized days, and makes at most three short passes so dates created during the scan are picked up (anything still new is reported pending). delete is idempotent: each date is snapshotted into history first, then marks and files are removed under one book lock, and dates that were already absent are reported as absent rather than failing the batch. context has a bounded read deadline and retains at most 2,000 raw messages; when either limit is reached the returned text explicitly says the digest only covers what was read, and in-flight page reads stop at the next page boundary. Deletion still happens only when the user explicitly asks for it. The WebUI management menus described above are the user's own equivalent path and can still export selected days or the whole book; that download is capped at 16 MiB.

diary_read actions history and history_diff are interactive-chat only; scheduled runs never see them. history returns one page of at most 8,192 UTF-8 bytes of commit metadata for a named date or, with date omitted, the whole book plus the deleted dates history can still recover, paging with historyLimit (1–24, default 12) and the opaque commit cursor from next=<id> (next=none when exhausted). history_diff returns a unified diff for one commit, capped at 12,288 UTF-8 bytes and 80 lines, and reports a mark-only change separately from a missing commit. diary_manage action restore restores the before or after side of a commit as a new commit rather than rewinding the log; it is allowed only while the current content and recorded marks still equal the opposite side of that commit, otherwise it returns CONFLICT and the user restores from that day's own history in the WebUI. Media binaries are not versioned: a restored Markdown tag points at a file only while the media sweep has not removed it, and attached images stay capped at 8 MB.

Scheduled diary runs see only diary_read and diary_write (list included; history and history_diff are interactive-chat only and stay unavailable); diary_manage — restore included — is not registered for them.

The model-facing contract is also injected into each agent's system prompt. Keep it in sync with index.ts when tools change.

Configuration

These fields are exported as the plugin Config and appear on the ChatLuna plugin page:

  • scheduleEnabled (default on)
  • dailyCron (default 0 22 * * *)
  • defaultWriteMode (append default, or replace)
  • digestBudget (default 12000)
  • readLimit (default 12000)
  • maxBodyChars (default 32000)
  • maxImageMb (default 8)
  • mediaRetentionHours (default 24)

Disabling the schedule removes this plugin's existing jobs but keeps their registry rows as suspended; re-enabling recreates them with the status they had. Manual tool calls are unaffected.

History and recovery

Every mutation appends one commit to <book>/.history/commits.jsonl:

  • write/append, entry edit, entry delete, day replace, day delete, batch delete, format, mark changes and restores;
  • before and after point at content-addressed objects (objects/<sha256>), so identical text is stored once;
  • a null side means the day file did not exist; an empty file is a real, distinct state;
  • marks travel with the commit only when that operation changed them.

Bounds per book: 2,000 commits, 64 commits per date, 512 MiB of unique objects and 4,096 objects. The object budget covers a full 366-day batch delete even when every day is at the 1 MiB cap. Compaction runs when the log passes 16 KiB so object growth stays under budget; it keeps the newest commits per date and overall, rewrites the log atomically, and unlinks objects no retained commit references. The log is append-only and a torn last line is ignored. Deletions are recorded before the unlink, so a crash can leave a delete commit while the file survives, but can never lose the text. Ordinary edits record after the write: a crash in that window can lose one history entry, not the diary.

Restore writes a new restore commit instead of rewinding. The day view sends the revision it previewed; a mismatch returns CONFLICT, and the current state is snapshotted before any destructive restore. Book-wide history can only restore the newest side of a date; older versions must be restored from that day's own history. Media binaries are not versioned: a restored Markdown tag points at a file only if the media sweep has not removed it.

Schedule ownership

@chatluna/schedule.set() replaces a paused job with a fresh active one (its fast path only accepts status === 'active'), and a missing job is indistinguishable from a brand-new preset. The plugin therefore keeps data/chatluna/diary/.schedule-v1.json:

  • managed rows own a job id; reconciliation only calls update() for a changed cron/prompt and never touches status, so pause survives restarts and config edits;
  • a removed event for the current job, or a managed row whose job disappeared, writes a cancelled tombstone and is never recreated;
  • plugin unload/reload marks rows suspended and removes the job; the next mount recreates it with the saved status, so a reload is not a user cancel;
  • the book header controls run, pause, resume, stop and re-enable; scheduleEnabled=false suspends every row and re-enabling recreates them.

Legacy installs adopt the jobs already present in the scheduler on first run. A job removed before this registry existed cannot be distinguished from one that never existed, so the first upgrade may create it once; after that, cancels persist.

Marks

Level N renders the same brush mask N times, with small deterministic offsets/rotations, plus a centered 1–5 numeral in a local rounded font. Higher levels look denser because the ink stacks; there are no separate leaf/star/heart shapes. The mask lives at client/assets/mark-l5-mask.png and is inlined by the Vite library build.

Build and test

npm install
npm test        # node --test (all *.test.ts)
npm run build   # dist/client.* + server.js
npm pack        # verifies the published file set

Skill generation

skills/SKILL_GENERATOR.md is a meta-skill, not a fixed skill. Give it to any ChatLuna v2+ model in the target deployment; it discovers the actual tool names, presets, paths, schedule, limits and locale, then generates a deployment-specific SKILL.md. Do not copy a stale fixed diary skill across environments.

Publishing

GitHub

git init
git add .
git commit -m "feat: chatluna-diary 0.1.0"
gh repo create yabo083/chatluna-diary --public --source=. --remote=origin --push

npm (manual)

npm login
npm publish --access public

npm OIDC / trusted publishing

.github/workflows/publish.yml already requests id-token: write and runs:

npm publish --provenance --access public

On npmjs.com, open Package → Settings → Trusted publishing for chatluna-diary and add:

  • Provider: GitHub Actions
  • Repository: yabo083/chatluna-diary
  • Workflow: publish.yml
  • Environment: leave empty (or create one and match the workflow)

The first publish must exist before trusted publishing can be attached; publish 0.1.0 once manually, then release tags use OIDC. No long-lived npm token is stored in the repository.

Security notes

  • Diary tools are limited to the owner's direct chat, an authenticated WebUI conversation, or a diary-scheduled run created by this plugin. Group members sharing the preset get FORBIDDEN; the WebUI token remains the page-level authority.
  • The scheduled diary run gets a per-agent tool filter: only diary_read and diary_write are visible. Management is not available to scheduled runs — diary_manage is not registered for them. Group text is still untrusted input, but it cannot reach shell/filesystem tools through this agent.
  • In a normal direct chat or WebUI conversation, diary_manage exposes export, format, delete and restore with no config gate; restore writes a new commit and only succeeds while the current content and recorded marks still equal the opposite side of that commit; otherwise it returns CONFLICT and the user restores from that day's history in the WebUI. export requires explicit dates and fails rather than truncating over budget; format preserves body bytes apart from headers and line endings and locks one day at a time; batch delete is idempotent under one book lock: each date is snapshotted to history first, then marks and idempotent unlinks, and already-absent dates are reported as absent. A crash or failed unlink therefore converges on retry instead of losing text. It runs only on an explicit user request. The WebUI management menus remain the user's own authority; WebUI export is capped at 16 MiB.
  • Diary files are private (new files 0600, directories 0700) and capped at 1 MiB per day and 1 MiB for marks.json. An oversized legacy day is unreadable to read/export, skipped by format, and refused for replace/delete so text the history cannot record is not silently lost. The plugin writes under the ChatLuna data directory; restrict the deployment account and backups accordingly.
  • External images in diary Markdown are replaced with a blocked placeholder, so opening a page cannot probe external or localhost URLs. Links open with noopener noreferrer.
  • The digest redacts links, keys, tokens and local addresses, but it is still model input from untrusted conversations. Treat it as data, never as instructions. Scheduled prompts say the same.
  • diary_write action attach only accepts real files inside the agent workspace, rejects hardlinked files, images ≤8 MB, and the documented extensions.
  • Media is served through an authenticated WebUI action, not a public static path; files larger than 8 MB are not served.

License

MIT