1 min read
kevin-wiki / scripts/lib
Purpose
The reusable core behind scripts/. CLIs stay thin; the real logic — state
tracking, source absorption, integration persistence, auth, agent-config
symlinking, and the bookmark-enrichment pipeline — lives here as pure,
unit-tested modules.
Mental model & key files
update-state.ts— single writer forstate.json(freshness source of truth).absorb-log.ts— tracks whichraw/sources became which wiki pages.integration-db.ts— PGlite state shared by calendar/email/meeting syncs.google-auth.ts— OAuth for Google integrations.agent-config-links.ts/agent-config-sync.ts— the 7 canonical~/.cursor/~/.claudesymlinks (bootstrap). Covered by__tests__/agent-config-sync.test.ts.enrich/— bookmark/article enrichment:fetchers/(article, github, youtube),pool.ts,thread.ts, with__tests__/.
Patterns to follow / invariants
- Pure where possible; side effects (fs, network) isolated and injectable.
- One writer per resource — e.g. all
state.jsonwrites go throughupdate-state.ts. - Parallelize independent async (fetchers) and reuse clients rather than re-initializing per call.
- Tests live in
__tests__/and run vianode --import tsx --test.
Common tasks → first action
- Add a helper → create the module here, export pure functions, add a
__tests__test, call it from the relevantscripts/*.ts. - Add a source fetcher → extend the
enrich/fetchers/pattern (base-fetcher + registry).
Gotchas
integration-db.tshistorically used~/.my-wiki/; the canonical path is~/.kevin-wiki/— symlink legacy installs.- Don't import these from a CLI's function body — import at module top (ESM).