@narumitw/pi-sync-daemon 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/LICENSE +21 -0
- package/README.md +89 -2
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +128 -0
- package/dist/client.d.ts +55 -0
- package/dist/client.js +484 -0
- package/dist/consent.d.ts +24 -0
- package/dist/consent.js +205 -0
- package/dist/document.d.ts +10 -0
- package/dist/document.js +6 -0
- package/dist/endpoint.d.ts +8 -0
- package/dist/endpoint.js +91 -0
- package/dist/engine/backends/backend-factory.d.ts +6 -0
- package/dist/engine/backends/backend-factory.js +16 -0
- package/dist/engine/backends/backend-identity.d.ts +3 -0
- package/dist/engine/backends/backend-identity.js +38 -0
- package/dist/engine/backends/backend-types.d.ts +70 -0
- package/dist/engine/backends/backend-types.js +1 -0
- package/dist/engine/backends/git/git-backend.d.ts +55 -0
- package/dist/engine/backends/git/git-backend.js +700 -0
- package/dist/engine/backends/git/git-config.d.ts +5 -0
- package/dist/engine/backends/git/git-config.js +118 -0
- package/dist/engine/backends/git/git-runner.d.ts +25 -0
- package/dist/engine/backends/git/git-runner.js +232 -0
- package/dist/engine/backends/git/git-storage.d.ts +39 -0
- package/dist/engine/backends/git/git-storage.js +226 -0
- package/dist/engine/backends/s3/s3-backend.d.ts +32 -0
- package/dist/engine/backends/s3/s3-backend.js +436 -0
- package/dist/engine/backends/s3/s3-client.d.ts +36 -0
- package/dist/engine/backends/s3/s3-client.js +352 -0
- package/dist/engine/backends/s3/s3-conditions.d.ts +4 -0
- package/dist/engine/backends/s3/s3-conditions.js +66 -0
- package/dist/engine/backends/snapshot-pointer.d.ts +6 -0
- package/dist/engine/backends/snapshot-pointer.js +22 -0
- package/dist/engine/backends/sync-backend.d.ts +71 -0
- package/dist/engine/backends/sync-backend.js +23 -0
- package/dist/engine/backends/webdav/webdav-backend.d.ts +34 -0
- package/dist/engine/backends/webdav/webdav-backend.js +534 -0
- package/dist/engine/backends/webdav/webdav-client.d.ts +36 -0
- package/dist/engine/backends/webdav/webdav-client.js +326 -0
- package/dist/engine/backends/webdav/webdav-config.d.ts +5 -0
- package/dist/engine/backends/webdav/webdav-config.js +73 -0
- package/dist/engine/commands/command-types.d.ts +31 -0
- package/dist/engine/commands/command-types.js +1 -0
- package/dist/engine/host.d.ts +70 -0
- package/dist/engine/host.js +16 -0
- package/dist/engine/paths.d.ts +9 -0
- package/dist/engine/paths.js +71 -0
- package/dist/engine/settings/config-errors.d.ts +1 -0
- package/dist/engine/settings/config-errors.js +4 -0
- package/dist/engine/settings/config-file.d.ts +33 -0
- package/dist/engine/settings/config-file.js +630 -0
- package/dist/engine/settings/config.d.ts +24 -0
- package/dist/engine/settings/config.js +200 -0
- package/dist/engine/settings/settings-management.d.ts +24 -0
- package/dist/engine/settings/settings-management.js +191 -0
- package/dist/engine/settings/settings-store.d.ts +8 -0
- package/dist/engine/settings/settings-store.js +41 -0
- package/dist/engine/settings/settings-types.d.ts +134 -0
- package/dist/engine/settings/settings-types.js +1 -0
- package/dist/engine/settings/settings-validation.d.ts +15 -0
- package/dist/engine/settings/settings-validation.js +356 -0
- package/dist/engine/snapshot/session-paths.d.ts +12 -0
- package/dist/engine/snapshot/session-paths.js +91 -0
- package/dist/engine/snapshot/snapshot-apply.d.ts +22 -0
- package/dist/engine/snapshot/snapshot-apply.js +262 -0
- package/dist/engine/snapshot/snapshot-case-replacement.d.ts +15 -0
- package/dist/engine/snapshot/snapshot-case-replacement.js +82 -0
- package/dist/engine/snapshot/snapshot-codec.d.ts +6 -0
- package/dist/engine/snapshot/snapshot-codec.js +53 -0
- package/dist/engine/snapshot/snapshot-exclude-safety.d.ts +7 -0
- package/dist/engine/snapshot/snapshot-exclude-safety.js +47 -0
- package/dist/engine/snapshot/snapshot-mutation-queues.d.ts +9 -0
- package/dist/engine/snapshot/snapshot-mutation-queues.js +133 -0
- package/dist/engine/snapshot/snapshot-paths.d.ts +1 -0
- package/dist/engine/snapshot/snapshot-paths.js +11 -0
- package/dist/engine/snapshot/snapshot-root-transition.d.ts +25 -0
- package/dist/engine/snapshot/snapshot-root-transition.js +122 -0
- package/dist/engine/snapshot/snapshot-transaction-directory.d.ts +2 -0
- package/dist/engine/snapshot/snapshot-transaction-directory.js +16 -0
- package/dist/engine/snapshot/snapshot-transaction-plan.d.ts +12 -0
- package/dist/engine/snapshot/snapshot-transaction-plan.js +68 -0
- package/dist/engine/snapshot/snapshot-transaction.d.ts +15 -0
- package/dist/engine/snapshot/snapshot-transaction.js +787 -0
- package/dist/engine/snapshot/snapshot-types.d.ts +48 -0
- package/dist/engine/snapshot/snapshot-types.js +1 -0
- package/dist/engine/snapshot/snapshot.d.ts +30 -0
- package/dist/engine/snapshot/snapshot.js +364 -0
- package/dist/engine/state/json-file.d.ts +6 -0
- package/dist/engine/state/json-file.js +49 -0
- package/dist/engine/state/lock-policy.d.ts +2 -0
- package/dist/engine/state/lock-policy.js +2 -0
- package/dist/engine/state/lock.d.ts +20 -0
- package/dist/engine/state/lock.js +259 -0
- package/dist/engine/state/lockfile-fs.d.ts +13 -0
- package/dist/engine/state/lockfile-fs.js +13 -0
- package/dist/engine/state/merge-baseline-store.d.ts +11 -0
- package/dist/engine/state/merge-baseline-store.js +187 -0
- package/dist/engine/state/mutation-directory-sync.d.ts +5 -0
- package/dist/engine/state/mutation-directory-sync.js +34 -0
- package/dist/engine/state/operation-availability.d.ts +49 -0
- package/dist/engine/state/operation-availability.js +40 -0
- package/dist/engine/state/state-directory.d.ts +14 -0
- package/dist/engine/state/state-directory.js +225 -0
- package/dist/engine/state/state-types.d.ts +27 -0
- package/dist/engine/state/state-types.js +1 -0
- package/dist/engine/state/sync-state-store.d.ts +11 -0
- package/dist/engine/state/sync-state-store.js +54 -0
- package/dist/engine/sync/agent-candidate.d.ts +44 -0
- package/dist/engine/sync/agent-candidate.js +207 -0
- package/dist/engine/sync/agent-plan.d.ts +8 -0
- package/dist/engine/sync/agent-plan.js +84 -0
- package/dist/engine/sync/agent-policy.d.ts +9 -0
- package/dist/engine/sync/agent-policy.js +10 -0
- package/dist/engine/sync/agent-refusal-retry.d.ts +4 -0
- package/dist/engine/sync/agent-refusal-retry.js +39 -0
- package/dist/engine/sync/agent-request.d.ts +14 -0
- package/dist/engine/sync/agent-request.js +13 -0
- package/dist/engine/sync/agent-runner.d.ts +6 -0
- package/dist/engine/sync/agent-runner.js +183 -0
- package/dist/engine/sync/agent-store.d.ts +7 -0
- package/dist/engine/sync/agent-store.js +177 -0
- package/dist/engine/sync/agent-sync.d.ts +4 -0
- package/dist/engine/sync/agent-sync.js +132 -0
- package/dist/engine/sync/apply-review.d.ts +8 -0
- package/dist/engine/sync/apply-review.js +51 -0
- package/dist/engine/sync/conflict-artifact-ownership.d.ts +4 -0
- package/dist/engine/sync/conflict-artifact-ownership.js +53 -0
- package/dist/engine/sync/conflict-artifacts.d.ts +32 -0
- package/dist/engine/sync/conflict-artifacts.js +158 -0
- package/dist/engine/sync/conflict-groups.d.ts +9 -0
- package/dist/engine/sync/conflict-groups.js +76 -0
- package/dist/engine/sync/conflict-preview.d.ts +4 -0
- package/dist/engine/sync/conflict-preview.js +53 -0
- package/dist/engine/sync/conflict-resolution.d.ts +13 -0
- package/dist/engine/sync/conflict-resolution.js +53 -0
- package/dist/engine/sync/conflict-retention.d.ts +5 -0
- package/dist/engine/sync/conflict-retention.js +61 -0
- package/dist/engine/sync/conflict-review.d.ts +4 -0
- package/dist/engine/sync/conflict-review.js +73 -0
- package/dist/engine/sync/content-conflicts.d.ts +10 -0
- package/dist/engine/sync/content-conflicts.js +70 -0
- package/dist/engine/sync/continuous-errors.d.ts +14 -0
- package/dist/engine/sync/continuous-errors.js +66 -0
- package/dist/engine/sync/continuous-lease.d.ts +9 -0
- package/dist/engine/sync/continuous-lease.js +206 -0
- package/dist/engine/sync/continuous-record.d.ts +31 -0
- package/dist/engine/sync/continuous-record.js +199 -0
- package/dist/engine/sync/continuous-storage.d.ts +14 -0
- package/dist/engine/sync/continuous-storage.js +59 -0
- package/dist/engine/sync/continuous-sync.d.ts +15 -0
- package/dist/engine/sync/continuous-sync.js +496 -0
- package/dist/engine/sync/continuous-watch.d.ts +3 -0
- package/dist/engine/sync/continuous-watch.js +65 -0
- package/dist/engine/sync/exclude-policy.d.ts +5 -0
- package/dist/engine/sync/exclude-policy.js +79 -0
- package/dist/engine/sync/field-migration.d.ts +5 -0
- package/dist/engine/sync/field-migration.js +20 -0
- package/dist/engine/sync/file-merge-planner.d.ts +36 -0
- package/dist/engine/sync/file-merge-planner.js +123 -0
- package/dist/engine/sync/initialization.d.ts +12 -0
- package/dist/engine/sync/initialization.js +75 -0
- package/dist/engine/sync/json-document.d.ts +29 -0
- package/dist/engine/sync/json-document.js +172 -0
- package/dist/engine/sync/local-field-policy.d.ts +2 -0
- package/dist/engine/sync/local-field-policy.js +26 -0
- package/dist/engine/sync/local-fields.d.ts +9 -0
- package/dist/engine/sync/local-fields.js +116 -0
- package/dist/engine/sync/merge-apply.d.ts +5 -0
- package/dist/engine/sync/merge-apply.js +386 -0
- package/dist/engine/sync/merge-journal.d.ts +31 -0
- package/dist/engine/sync/merge-journal.js +179 -0
- package/dist/engine/sync/merge-transfer-error.d.ts +3 -0
- package/dist/engine/sync/merge-transfer-error.js +64 -0
- package/dist/engine/sync/merged-sync.d.ts +6 -0
- package/dist/engine/sync/merged-sync.js +618 -0
- package/dist/engine/sync/mutation-owner.d.ts +2 -0
- package/dist/engine/sync/mutation-owner.js +18 -0
- package/dist/engine/sync/package-merge.d.ts +3 -0
- package/dist/engine/sync/package-merge.js +82 -0
- package/dist/engine/sync/partial-progress.d.ts +15 -0
- package/dist/engine/sync/partial-progress.js +39 -0
- package/dist/engine/sync/remote-snapshot.d.ts +28 -0
- package/dist/engine/sync/remote-snapshot.js +62 -0
- package/dist/engine/sync/resolver-stream.d.ts +4 -0
- package/dist/engine/sync/resolver-stream.js +34 -0
- package/dist/engine/sync/session-merge.d.ts +3 -0
- package/dist/engine/sync/session-merge.js +178 -0
- package/dist/engine/sync/session-push.d.ts +5 -0
- package/dist/engine/sync/session-push.js +32 -0
- package/dist/engine/sync/settings-conflicts.d.ts +8 -0
- package/dist/engine/sync/settings-conflicts.js +56 -0
- package/dist/engine/sync/settings-merge.d.ts +13 -0
- package/dist/engine/sync/settings-merge.js +93 -0
- package/dist/engine/sync/signals.d.ts +2 -0
- package/dist/engine/sync/signals.js +8 -0
- package/dist/engine/sync/startup-timings.d.ts +11 -0
- package/dist/engine/sync/startup-timings.js +44 -0
- package/dist/engine/sync/sync-decision.d.ts +35 -0
- package/dist/engine/sync/sync-decision.js +66 -0
- package/dist/engine/sync/sync-error-guidance.d.ts +2 -0
- package/dist/engine/sync/sync-error-guidance.js +55 -0
- package/dist/engine/sync/sync-errors.d.ts +9 -0
- package/dist/engine/sync/sync-errors.js +18 -0
- package/dist/engine/sync/sync-inspection.d.ts +26 -0
- package/dist/engine/sync/sync-inspection.js +40 -0
- package/dist/engine/sync/sync-loaders.d.ts +7 -0
- package/dist/engine/sync/sync-loaders.js +8 -0
- package/dist/engine/sync/sync-local.d.ts +5 -0
- package/dist/engine/sync/sync-local.js +40 -0
- package/dist/engine/sync/sync-mutations.d.ts +30 -0
- package/dist/engine/sync/sync-mutations.js +589 -0
- package/dist/engine/sync/sync-operations.d.ts +2 -0
- package/dist/engine/sync/sync-operations.js +3 -0
- package/dist/engine/sync/sync-policy.d.ts +85 -0
- package/dist/engine/sync/sync-policy.js +356 -0
- package/dist/engine/sync/sync-queries.d.ts +7 -0
- package/dist/engine/sync/sync-queries.js +195 -0
- package/dist/engine/sync/sync-state.d.ts +31 -0
- package/dist/engine/sync/sync-state.js +92 -0
- package/dist/engine/sync/text-merge.d.ts +19 -0
- package/dist/engine/sync/text-merge.js +124 -0
- package/dist/engine/types.d.ts +5 -0
- package/dist/engine/types.js +2 -0
- package/dist/engine/ui/merge-review.d.ts +2 -0
- package/dist/engine/ui/merge-review.js +7 -0
- package/dist/engine/ui/merged-sync-summary.d.ts +25 -0
- package/dist/engine/ui/merged-sync-summary.js +86 -0
- package/dist/engine/ui/sync-format.d.ts +13 -0
- package/dist/engine/ui/sync-format.js +150 -0
- package/dist/engine/ui/sync-status.d.ts +9 -0
- package/dist/engine/ui/sync-status.js +30 -0
- package/dist/engine/ui/terminal-text.d.ts +3 -0
- package/dist/engine/ui/terminal-text.js +9 -0
- package/dist/engine/ui/transfer-changes.d.ts +12 -0
- package/dist/engine/ui/transfer-changes.js +24 -0
- package/dist/engine/ui/transfer-review.d.ts +3 -0
- package/dist/engine/ui/transfer-review.js +19 -0
- package/dist/engine-service.d.ts +11 -0
- package/dist/engine-service.js +315 -0
- package/dist/identity.d.ts +20 -0
- package/dist/identity.js +133 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +4 -0
- package/dist/lifecycle-log.d.ts +7 -0
- package/dist/lifecycle-log.js +53 -0
- package/dist/lifecycle.d.ts +2 -0
- package/dist/lifecycle.js +21 -0
- package/dist/model-signature.d.ts +2 -0
- package/dist/model-signature.js +7 -0
- package/dist/monitor.d.ts +11 -0
- package/dist/monitor.js +245 -0
- package/dist/participant-admission.d.ts +5 -0
- package/dist/participant-admission.js +30 -0
- package/dist/protocol.d.ts +97 -0
- package/dist/protocol.js +90 -0
- package/dist/resolver-host.d.ts +11 -0
- package/dist/resolver-host.js +78 -0
- package/dist/server.d.ts +18 -0
- package/dist/server.js +724 -0
- package/dist/service-host.d.ts +7 -0
- package/dist/service-host.js +174 -0
- package/docs/architecture.md +133 -0
- package/package.json +54 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# @narumitw/pi-sync-daemon
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 8bba72d: Extract the existing synchronization engine into the standalone TypeScript `@narumitw/sync-daemon` package and keep Pi Sync as its reviewed local API client. Share a detached root-bound owner across Pi sessions, retain existing formats and recovery safeguards, and separate service lifetime from unattended transfer and resolver permission.
|
|
8
|
+
|
|
9
|
+
Preserve reviewed external-session destinations across all participating Pi queues and setup-scoped explicit Continuous retry without resetting request accounting.
|
|
10
|
+
|
|
11
|
+
The daemon must be available before the dependent Pi client is released. Publication and real-data cutover require separate approval and the migration verification gates.
|
|
12
|
+
|
|
13
|
+
Initial development; not published.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 narumiruna
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,90 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 🔄 @narumitw/pi-sync-daemon — A local synchronization owner
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@narumitw/pi-sync-daemon)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
|
|
6
|
+
`@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.
|
|
7
|
+
|
|
8
|
+
> **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.
|
|
9
|
+
|
|
10
|
+
## ✨ Features
|
|
11
|
+
|
|
12
|
+
- One authenticated local owner per canonical agent directory, shared by multiple Pi clients.
|
|
13
|
+
- Existing Git, WebDAV, S3, and Cloudflare R2 engine formats and recovery evidence.
|
|
14
|
+
- Separate process lifetime, transfer permission, and isolated-model permission.
|
|
15
|
+
- Explicit lifecycle control without an OS service, supervisor, database, or public TCP listener.
|
|
16
|
+
|
|
17
|
+
## 📦 Install
|
|
18
|
+
|
|
19
|
+
The Pi client declares this service as a normal dependency; do not add it to `pi.extensions` or load it with `pi -e`. The npm package is `@narumitw/pi-sync-daemon`; the executable is `pi-sync-daemon`. For the previous package and executable names, see the [rename instructions](https://github.com/narumiruna/pi-extensions/blob/main/packages/pi-sync/docs/daemon-migration.md#ownership-and-upgrade).
|
|
20
|
+
|
|
21
|
+
For a local checkout, run from the repository root:
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
npm install
|
|
25
|
+
npm --workspace @narumitw/pi-sync-daemon run build
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
The build emits JavaScript, declarations, and an executable under `dist/`. A global npm installation is not required for the Pi client to locate its dependency. Registry installation remains blocked until publication rights and the dependency-first release are approved.
|
|
29
|
+
|
|
30
|
+
## 🚀 Quick start
|
|
31
|
+
|
|
32
|
+
Use an existing disposable directory for the first smoke:
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
mkdir -p /tmp/my-pi-sync-daemon-smoke
|
|
36
|
+
node packages/pi-sync-daemon/dist/cli.js start --root /tmp/my-pi-sync-daemon-smoke
|
|
37
|
+
node packages/pi-sync-daemon/dist/cli.js status --root /tmp/my-pi-sync-daemon-smoke
|
|
38
|
+
node packages/pi-sync-daemon/dist/cli.js stop --root /tmp/my-pi-sync-daemon-smoke
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`start` reports the same instance when a compatible service already owns the directory. Connecting alone does not configure a backend or authorize transfers. Use the Pi client's reviewed setup flow for synchronization.
|
|
42
|
+
|
|
43
|
+
## 💬 Commands
|
|
44
|
+
|
|
45
|
+
`pi-sync-daemon <start|status|stop|restart|serve> --root <agent-directory>` uses an explicit root. `status` and `stop` never launch an absent service. `restart` drains the compatible owner before replacement; an incompatible or unreachable live owner fails closed. `serve` is the internal foreground launch target, not an OS registration command.
|
|
46
|
+
|
|
47
|
+
Pi starts the service only after configured interactive synchronization is needed or an explicit setup/command authorizes it. Closing Pi detaches that client, not the shared service. `/new` and `/reload` attach a new session generation. Use `/sync daemon` for status, reviewed old-process handover, and setup-bound unattended authorization.
|
|
48
|
+
|
|
49
|
+
## ⚙️ Settings
|
|
50
|
+
|
|
51
|
+
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.
|
|
52
|
+
|
|
53
|
+
Automatic, Autonomous, and Continuous defaults remain unchanged. Old permission for work while Pi is open does not permit work after the last client exits. `/sync daemon allow-after-exit` reviews that extra permission for the current setup and selected independently reproducible provider/model; `/sync daemon revoke-after-exit` revokes it. Setup changes invalidate the saved digest. Changes to an interactive client’s model, working directory, or session-directory binding revoke older unattended grants, including across restart. Print/JSON never launch a service; passive attachment to an existing service protects their sessions and pauses automatic work. An idle service can remain alive without unattended permission.
|
|
54
|
+
|
|
55
|
+
## 🔒 Security and privacy
|
|
56
|
+
|
|
57
|
+
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.
|
|
58
|
+
|
|
59
|
+
Sync content, session conversations, storage credentials, and conflict evidence can be sensitive. Keep the existing secret scan, session inclusion review, exclusions, backups, and journals. A model receives isolated conflict evidence, not the parent conversation or tools. Parent-only provider registrations and runtime keys are not copied; unavailable capabilities preserve conflicts instead of selecting a fallback.
|
|
60
|
+
|
|
61
|
+
## 🚧 Limitations
|
|
62
|
+
|
|
63
|
+
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.
|
|
64
|
+
|
|
65
|
+
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.
|
|
66
|
+
|
|
67
|
+
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](https://github.com/narumiruna/pi-extensions/blob/main/packages/pi-sync/docs/daemon-migration.md).
|
|
68
|
+
|
|
69
|
+
## Recovery and development
|
|
70
|
+
|
|
71
|
+
Stop the service before package updates, local rebuilds, or rollback, verify owner exit, and preserve pending journals and backups. A compatible connection does not upgrade a running implementation; restart explicitly after installation. 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.
|
|
72
|
+
|
|
73
|
+
CLI `status` reports the private lifecycle-log path. 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.
|
|
74
|
+
|
|
75
|
+
The source-linked [architecture and safety contract](docs/architecture.md) defines ownership, resolver capability checks, write coordination, and the decision matrix. It distinguishes required checks from completed evidence.
|
|
76
|
+
|
|
77
|
+
## 🗂️ Package layout
|
|
78
|
+
|
|
79
|
+
- `src/`: lightweight public client, Node CLI, private IPC, service host, and extracted engine.
|
|
80
|
+
- `dist/`: emitted JavaScript and declarations published to npm.
|
|
81
|
+
- `docs/`: architecture, protocol, ownership, and safety guidance.
|
|
82
|
+
- `test/`: deterministic API, process, provider, and failure tests; not published.
|
|
83
|
+
|
|
84
|
+
## 🔎 Keywords
|
|
85
|
+
|
|
86
|
+
Pi, synchronization, daemon, local IPC, TypeScript, Git, WebDAV, S3, Cloudflare R2, conflict resolution.
|
|
87
|
+
|
|
88
|
+
## 📄 License
|
|
89
|
+
|
|
90
|
+
[MIT](LICENSE).
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
4
|
+
import { ensureDaemon, requestDaemon } from "./client.js";
|
|
5
|
+
import { privateDirectory, processExists, readIdentity, runtimePaths } from "./identity.js";
|
|
6
|
+
import { openLifecycleLog } from "./lifecycle-log.js";
|
|
7
|
+
import { record } from "./protocol.js";
|
|
8
|
+
export async function main(args) {
|
|
9
|
+
const [command = "help", flag, root, ...extra] = args;
|
|
10
|
+
if (["help", "--help", "-h"].includes(command)) {
|
|
11
|
+
console.log("pi-sync-daemon <start|status|stop|restart|serve> --root <canonical-agent-directory>\nLocal synchronization owner; no OS service registration. status/stop never start a service.");
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (!["start", "status", "stop", "restart", "serve"].includes(command) || flag !== "--root" || !root || extra.length)
|
|
15
|
+
throw new Error("Use pi-sync-daemon --help for the supported commands.");
|
|
16
|
+
if (command === "serve") {
|
|
17
|
+
process.send?.({ type: "booting" });
|
|
18
|
+
const { createEngineService } = await import("./engine-service.js");
|
|
19
|
+
const { startServer } = await import("./server.js");
|
|
20
|
+
const paths = await runtimePaths(root);
|
|
21
|
+
// Credential commands have one documented working directory, never a closed Pi context.
|
|
22
|
+
process.chdir(paths.root);
|
|
23
|
+
await privateDirectory(paths.directory);
|
|
24
|
+
let log;
|
|
25
|
+
const note = (phase) => {
|
|
26
|
+
try {
|
|
27
|
+
log?.write(phase);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
log?.close(); /* Never follow a replaced diagnostic path. */
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const service = createEngineService(paths.root);
|
|
34
|
+
let server;
|
|
35
|
+
try {
|
|
36
|
+
server = await startServer(paths.root, service.execute, {
|
|
37
|
+
...service.hooks,
|
|
38
|
+
close: async () => {
|
|
39
|
+
try {
|
|
40
|
+
await service.hooks.close();
|
|
41
|
+
}
|
|
42
|
+
finally {
|
|
43
|
+
note("drained");
|
|
44
|
+
log?.close();
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
// Only the published owner may open or modify its shared diagnostic file.
|
|
49
|
+
try {
|
|
50
|
+
log = openLifecycleLog(paths.directory);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
await server.close();
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
note("starting");
|
|
57
|
+
service.bind(server);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
note("failed");
|
|
61
|
+
log?.close();
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
note("ready");
|
|
65
|
+
let stopping;
|
|
66
|
+
const stop = () => {
|
|
67
|
+
stopping ??= server.close().catch(() => {
|
|
68
|
+
process.exitCode = 1;
|
|
69
|
+
});
|
|
70
|
+
return stopping;
|
|
71
|
+
};
|
|
72
|
+
process.on("SIGTERM", stop);
|
|
73
|
+
process.on("SIGINT", stop);
|
|
74
|
+
// Parent disconnect means readiness IPC ended, not service shutdown.
|
|
75
|
+
process.send?.({ type: "ready", identity: server.identity });
|
|
76
|
+
process.channel?.unref();
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (command === "start") {
|
|
80
|
+
const { identity } = await ensureDaemon(root);
|
|
81
|
+
console.log(JSON.stringify({ running: true, root: identity.root, instance: identity.instance, pid: identity.pid }));
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const paths = await runtimePaths(root);
|
|
85
|
+
const identity = await readIdentity(paths);
|
|
86
|
+
if (!identity) {
|
|
87
|
+
if (command === "restart") {
|
|
88
|
+
await main(["start", "--root", root]);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
console.log(JSON.stringify({ running: false, root: paths.root }));
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (command === "status") {
|
|
95
|
+
const status = await requestDaemon(paths, identity, "hello", {});
|
|
96
|
+
if (!record(status) || status.instance !== identity.instance)
|
|
97
|
+
throw new Error("Daemon identity mismatch; no replacement was attempted.");
|
|
98
|
+
console.log(JSON.stringify({ running: true, ...status, lifecycleLog: path.join(paths.directory, "lifecycle.log") }));
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
await requestDaemon(paths, identity, "stop", {});
|
|
102
|
+
const deadline = Date.now() + 30_000;
|
|
103
|
+
while (await readIdentity(paths)) {
|
|
104
|
+
if (Date.now() >= deadline)
|
|
105
|
+
throw new Error("Daemon did not drain; state retained. Do not force a second owner.");
|
|
106
|
+
await delay(25);
|
|
107
|
+
}
|
|
108
|
+
if (command === "restart") {
|
|
109
|
+
while (processExists(identity.pid)) {
|
|
110
|
+
if (Date.now() >= deadline)
|
|
111
|
+
throw new Error("Previous daemon is still exiting; restart was not attempted.");
|
|
112
|
+
await delay(25);
|
|
113
|
+
}
|
|
114
|
+
await main(["start", "--root", root]);
|
|
115
|
+
}
|
|
116
|
+
else
|
|
117
|
+
console.log(JSON.stringify({ stopped: true, root: paths.root }));
|
|
118
|
+
}
|
|
119
|
+
if (import.meta.main) {
|
|
120
|
+
void main(process.argv.slice(2)).catch(() => {
|
|
121
|
+
process.send?.({
|
|
122
|
+
type: "error",
|
|
123
|
+
message: "Daemon initialization failed; private state retained. Check endpoint ownership and compatible versions.",
|
|
124
|
+
});
|
|
125
|
+
console.error("pi-sync-daemon failed; private state retained. Check root, endpoint ownership, and version compatibility.");
|
|
126
|
+
process.exitCode = 1;
|
|
127
|
+
});
|
|
128
|
+
}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type RuntimePaths } from "./identity.js";
|
|
2
|
+
import { type Callback, type ClientEvent, type ClientFacts, type ClientHandoff, type Identity, type RemoteError } from "./protocol.js";
|
|
3
|
+
export declare class DaemonError extends Error {
|
|
4
|
+
readonly remote: RemoteError;
|
|
5
|
+
constructor(remote: RemoteError);
|
|
6
|
+
}
|
|
7
|
+
export declare function requestDaemon(paths: RuntimePaths, identity: Identity, method: string, params: unknown, signal?: AbortSignal): Promise<unknown>;
|
|
8
|
+
/** Explicit startup only: callers decide whether configuration or a user action authorizes it. */
|
|
9
|
+
export declare function ensureDaemon(root: string, signal?: AbortSignal): Promise<{
|
|
10
|
+
paths: import("./identity.js").DaemonPaths;
|
|
11
|
+
identity: Identity;
|
|
12
|
+
}>;
|
|
13
|
+
/** Inspect an existing compatible owner without starting one. */
|
|
14
|
+
export declare function findDaemon(root: string): Promise<{
|
|
15
|
+
paths: import("./identity.js").DaemonPaths;
|
|
16
|
+
identity: Identity;
|
|
17
|
+
} | undefined>;
|
|
18
|
+
/** Gracefully stop an existing compatible owner without creating a new service. */
|
|
19
|
+
export declare function stopDaemon(root: string): Promise<boolean>;
|
|
20
|
+
export interface ConnectionOptions {
|
|
21
|
+
callback(callback: Callback, signal: AbortSignal): Promise<unknown>;
|
|
22
|
+
event?(event: ClientEvent): void;
|
|
23
|
+
error?(error: unknown): void;
|
|
24
|
+
}
|
|
25
|
+
export declare class DaemonConnection {
|
|
26
|
+
readonly paths: RuntimePaths;
|
|
27
|
+
readonly identity: Identity;
|
|
28
|
+
readonly facts: ClientFacts;
|
|
29
|
+
private readonly options;
|
|
30
|
+
private cursor;
|
|
31
|
+
private controller;
|
|
32
|
+
private callbacks;
|
|
33
|
+
private callbackIO;
|
|
34
|
+
private callbackTasks;
|
|
35
|
+
private updates;
|
|
36
|
+
private attached;
|
|
37
|
+
private uncertain;
|
|
38
|
+
private reportedError;
|
|
39
|
+
private commits;
|
|
40
|
+
private completedCallbacks;
|
|
41
|
+
private disposing;
|
|
42
|
+
private polling;
|
|
43
|
+
private closed;
|
|
44
|
+
constructor(paths: RuntimePaths, identity: Identity, facts: ClientFacts, options: ConnectionOptions);
|
|
45
|
+
attach(): Promise<this>;
|
|
46
|
+
update(facts: ClientFacts): Promise<void>;
|
|
47
|
+
run(operation: string, payload: unknown, signal?: AbortSignal, onCommit?: () => void): Promise<unknown>;
|
|
48
|
+
private consume;
|
|
49
|
+
private performCallback;
|
|
50
|
+
private wait;
|
|
51
|
+
private reportError;
|
|
52
|
+
private poll;
|
|
53
|
+
pause(): Promise<void>;
|
|
54
|
+
dispose(handoff?: ClientHandoff): Promise<void>;
|
|
55
|
+
}
|