noggin

File provider

The file provider backs a noggin with a single YAML document on disk, atomically writes on every mutation, and watches the file for outside changes so live noggins stay in sync when another process (the CLI, a peer editor) updates the same file.

At a glance

Schemefile://
Module@noggin/engine/providers/file
Loaded byCLI, MCP, desktop, extension (on import)
PersistentYes — single YAML file on disk
Read-onlyNo
Cross-processLock-coordinated atomic writes + filesystem watcher
Read accessorsSynchronous against the last-known document

When to use

This is the workhorse. Use it when you want a real noggin you can commit, share via a shared drive, edit in a text editor, or open from multiple processes simultaneously (CLI + extension + agent).

Quick start

import { openNoggin } from '@noggin/engine';
import '@noggin/engine/providers/file';

const noggin = await openNoggin('file:///work/today.yaml');
await noggin.push({ title: 'ship v1' });
await noggin.dispose();

Got a raw filesystem path (from a file-open dialog, a CLI flag, a drop event)? Use the direct factory — it accepts absolute, relative, and ~-prefixed paths and skips the URI construction:

import { openFileNoggin } from '@noggin/engine/providers/file';

const noggin = await openFileNoggin('~/.noggin.yaml');

The file is created on first write if it doesn't exist. An empty or missing file yields an empty noggin (no items, no active).

URL syntax

FormMeaning
file:///absolute/path.yamlStandard file:// URL
file://./relative/path.yamlRelative path embedded after file:// (resolved against process.cwd())
file://~/.noggin.yaml~ expansion is performed at open time

Raw filesystem paths (/abs/path.yaml, ./relative.yaml, ~/x.yaml) do not work with openNoggin — every URI requires an explicit scheme. Use openFileNoggin(path) or convert the path to a file:// URI at your host's boundary.

Persistence and behaviour

Options

openFileNoggin(path, opts?) (and the equivalent openNoggin('file://...', opts?)) accept:

OptionDefaultPurpose
watchfalseAttach the fs.watch fast-path listener. Set to true for hosts that want near-instant reaction to external writes.
pollIntervalMs2000Interval (ms) for the safety-net stat poll. Set to 0 to disable.
lockTimeout5000Max ms to wait for the cross-process advisory lock during apply() before failing with code: 'lock-timeout'.

Error codes you might see

CodeWhen
no-locationopenNoggin('file://') with no path
schema-version-mismatchThe YAML on disk declares a schemaVersion the engine doesn't know
invalid-documentThe YAML parses but fails structural validation (e.g. dangling parentKey)
lock-timeoutA peer process held the lock past the configured timeout