@narumitw/pi-sync-daemon
v0.16.4
Published
A local synchronization daemon with a versioned client API.
Readme
🔄 @narumitw/pi-sync-daemon — A local synchronization owner
@narumitw/pi-sync-daemon runs the existing Pi Sync engine in a separate Node.js process. Pi remains the interface for setup, exact reviews, commands, and live-session integration.
Experimental and not release-ready. Complete the migration and verification gates before using this checkout with real data. This change does not publish the package or verify npm scope permissions. Installation runs code with your user permissions.
✨ Features
- One authenticated local owner per canonical agent directory, shared by multiple Pi clients.
- Existing Git, WebDAV, S3, and Cloudflare R2 engine formats and recovery evidence.
- Enforces optional per-file and per-directory limits on the selected bytes of new transfers, without changing snapshot formats.
- Separates service lifetime from transfer permission and retains reviewed revocation of legacy grants.
- Explicit lifecycle control without an OS service, supervisor, database, or public TCP listener.
📦 Install
Use Node.js 22.19.0 or later. The Pi Sync npm package includes its own daemon build, so you do not need to install this standalone package to use Pi Sync. To install the standalone CLI:
npm install --global @narumitw/pi-sync-daemonTo try the standalone CLI without installing it globally:
npm exec --package=@narumitw/pi-sync-daemon -- pi-sync-daemon --helpThis package is not an extension; do not add it to pi.extensions or load it with pi -e. See the daemon CLI guide for the previous executable name and for running the copy bundled with Pi Sync.
For a local checkout, run from the repository root:
npm install
npm --workspace @narumitw/pi-sync-daemon run buildThe build emits JavaScript, declarations, and the executable dist/cli.js.
🚀 Quick start
Use an existing disposable directory for the first smoke:
mkdir -p /tmp/my-pi-sync-daemon-smoke
node packages/pi-sync-daemon/dist/cli.js start --root /tmp/my-pi-sync-daemon-smoke
node packages/pi-sync-daemon/dist/cli.js status --root /tmp/my-pi-sync-daemon-smoke
node packages/pi-sync-daemon/dist/cli.js stop --root /tmp/my-pi-sync-daemon-smokestart reuses a compatible owner on the same or a newer build. It stops an older owner and waits
for it to exit before launching the new build, unless the stop cannot be verified or unattended
permission needs review. Connecting alone does not configure a backend or authorize transfers. Use the Pi client's reviewed setup flow for synchronization.
💬 Commands
pi-sync-daemon <start|status|stop|restart|repair-upgrade|serve> --root <agent-directory> uses an explicit root. status, stop, and repair-upgrade never launch a service. start upgrades older owners that support guarded upgrades, but defers while sync work is active. restart uses the same startup lock and exit checks and can replace a same-version owner. For older owners without guarded upgrades, run explicit restart only after sync work has finished. Replacement cannot downgrade a newer owner or bypass incompatible or unreachable ownership, retained unattended permission, or unresolved recovery. serve is the internal foreground launch target, not an OS registration command. Use repair-upgrade only for a blocked, pending upgrade. It verifies the old owner's exit, revokes all retained unattended grants for the root, and archives the recovery records.
Pi starts the service only after configured interactive synchronization is needed or an explicit setup/command authorizes it. Closing Pi detaches that client; the daemon owns the shared lifetime decision. After no registered live client PID remains for that canonical root, a fixed 30-second grace period starts. Explicit CLI start without clients follows the same rule. A client arriving before shutdown becomes final cancels automatic exit. /new, /reload, fork, and resume retain protection while their Pi process is alive. Use /sync daemon for status, reviewed old-process handover, and revocation of legacy unattended grants.
The daemon keeps its status and doctor sync operations for supported IPC peers. The Pi Sync check-command migration applies to the extension's slash commands and menu, not the daemon CLI or those IPC operations.
⚙️ Settings
Breaking change: This daemon rejects retired ignore-file settings, v6/v7 snapshots, and pending ignore-file recovery without converting them. Run /skill:configure-pi-sync in Pi or follow the manual recovery guide.
Existing pi-sync.json, canonical pi-sync/, and legacy .pisync/ remain in the selected agent directory. There is no second backend or credential configuration format. The daemon is the authoritative Pi Sync settings writer; stale reviews must reopen rather than overwrite a newer document. Settings version 7 and snapshot version 5 support agent-directory scope. Older clients must refuse these formats, and existing selected-path setups do not change scope automatically.
Retired: Autonomous sync, Continuous sync, and unattended sync no longer run. The daemon accepts but ignores existing sync.agentMode and sync.continuous booleans; it does not enable Startup transfer on their behalf. Retained after-exit grants still block replacement of an older owner until safely revoked. See the daemon upgrade guide. Print/JSON never launch a service. Registered live PIDs still keep it alive, including passive, disconnected, publishing, and orderly retired clients.
Transfer size limits
The daemon enforces each setup's configured file and directory size limits before new local applies and remote publications, including automatic work. It checks each affected side separately after selection and portable field projection. Old destination bytes outside the proposed image, backups, and retained History do not count. These limits default to Off and do not replace existing scan, decode, merge, or backend bounds.
Enabling either limit requires settings document version 9 for the whole agent directory. Close or upgrade older Pi Sync clients and daemon owners on that root before enabling a limit. Older builds refuse the entire document, including other setups, and clearing the limits does not make version 9 readable by older builds. Other devices enforce only their own limits. See the Pi Sync settings reference for settings values and safe recovery.
Debug mode
The daemon reads the top-level debug boolean in pi-sync.json for its agent directory (--root in the CLI). It defaults to false. Use /sync → Settings → Debug mode in Pi or edit the settings file. The daemon applies the validated value at its next owner or job boundary; no restart is needed.
When enabled, the owner appends selected lifecycle, startup timing, check, and job records to the private <agent-directory>/pi-sync.log. Filter the JSON lines by source to isolate pi-sync-daemon records from pi-sync client records.
The file is local-only. Records omit raw errors, credentials, addresses, paths, synced contents, and model data. The daemon attempts to write inspection records before it returns the result. Logging is best effort, not a recovery journal; a skipped or failed write does not change the inspection result. Turning it off leaves existing records in place; retention is manual. See the Pi Sync Debug mode reference for cleanup and older snapshots.
🔒 Security and privacy
IPC uses a private root-bound Unix socket on POSIX or a user/root-bound named pipe on Windows. Requests negotiate protocol, instance, root, and a private capability token. Do not share runtime identity files. The service has the same filesystem and network permissions as your user.
Sync content, session conversations, storage credentials, and conflict evidence can be sensitive. Keep the secret scan, session inclusion review, exclusions, backups, and journals. The daemon does not send conflict evidence to a model.
🚧 Limitations
A daemon does not lock every editor or shell command. Cooperating Pi clients reserve their actual public mutation queues; unregistered writers still require freshness checks and can cause safe refusal. Active sessions remain protected when contact is lost but their process is still alive. A heartbeat timeout is not proof of process exit.
Pi core's missing-settings.json write branch cannot be made safe with the existing file lock alone. The daemon refuses to create that file while a participating Pi is alive; create it through Pi first. Existing-file writes use the actual Pi settings-file lock.
Close or upgrade every old Pi process before reviewed handover. An absent operation lock does not prove an idle old process is absent. Native Windows/macOS process and permission guarantees require native evidence; see the retained migration and release restrictions.
Recovery and development
Automatic exit first stops new automatic work, cancels cancellable work, and drains writes, queue-release acknowledgements, persistence, and owned callbacks before releasing ownership. It adds no final sync or model request. Uncertain consent publication, failed revocation, or cleanup failure keeps the owner paused with evidence retained; automatic restart must not restore an older grant. Repair persistence and use the existing revocation/repair path before explicit restart. The next eligible interactive client or explicit command can restart through singleton startup only after the old owner's exit is proven; print/JSON never launch a replacement.
The standalone package is versioned and released independently. Updating it does not change the daemon bundled in an installed Pi Sync package. Update Pi Sync to get a newer bundled build.
Stop the service and verify owner exit before an in-place rebuild or rollback. Preserve pending journals and backups. Rebuilding without changing the package version does not replace the running owner. See the daemon upgrade guide for package updates and manual recovery. Do not downgrade over pending/newer recovery evidence or restore old settings over newer bytes. Expired or old-instance operation IDs must reconcile existing journals rather than replay a possible commit. The bounded per-instance result ledger requires an explicit drained restart when full.
CLI status reports recordedPid from a validated identity file and pid only after a verified handshake. It compares the verified buildVersion and buildId with expectedBuildVersion and expectedBuildId from the CLI. buildComparison distinguishes older, newer, same-version matching or different, unversioned, and unverified builds. A pending upgrade has a separate pendingUpgradePid. running: null means the handshake failed, with or without a pending upgrade. Unknown status proves neither exit nor compatibility. Use diagnostics from an already available compatible version; if you cannot identify the owner, stop and preserve the records. Status does not expose the IPC token.
Pi Sync's manager can recover eligible file-queue failures in the original Push or Pull action. It does not replay a verified or uncertain write. If automatic recovery cannot verify cleanup, /sync daemon recover remains available to review and stop the existing daemon. The client library exposes inspectDaemonRecovery(root) and stopDaemonForRecovery(target) for that flow. Inspection does not start the daemon. A successful stop verifies identity release and process exit without starting a replacement. Keep recovery evidence and follow the cleanup recovery guide if the stop cannot be verified.
After a successful handshake, CLI status reports the lifecycleLog path in the daemon's private runtime directory. New owners write pi-sync-lifecycle.log; older owners write lifecycle.log. Existing legacy logs are left untouched. This log is separate from pi-sync.log and is not controlled by Debug mode. It retains at most 8 KiB of timestamps and lifecycle phases, not exception text, credentials, model output, or sync content; older entries roll over. It is diagnostic evidence, not a recovery journal. Child stdio is detached and discarded.
The source-linked architecture and safety contract defines ownership, resolver capability checks, write coordination, and the decision matrix. It distinguishes required checks from completed evidence.
🗂️ Package layout
src/: lightweight public client, Node CLI, private IPC, service host, and extracted engine.dist/: emitted JavaScript and declarations published to npm.docs/: architecture, protocol, ownership, and safety guidance.test/: deterministic API, process, provider, and failure tests; not published.
🔎 Keywords
Pi, synchronization, daemon, local IPC, TypeScript, Git, WebDAV, S3, Cloudflare R2, conflict resolution.
📄 License
MIT.
