@songsid/agend 2.4.0-beta.24 → 2.4.0-beta.25
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/README.md +1 -1
- package/README.zh-TW.md +1 -1
- package/dist/agend-home.js +5 -5
- package/dist/agend-home.js.map +1 -1
- package/dist/agent-endpoint.js +10 -0
- package/dist/agent-endpoint.js.map +1 -1
- package/dist/agent-workspace.d.ts +18 -2
- package/dist/agent-workspace.js +15 -4
- package/dist/agent-workspace.js.map +1 -1
- package/dist/backend/antigravity.js +8 -6
- package/dist/backend/antigravity.js.map +1 -1
- package/dist/backend/claude-code.js +17 -0
- package/dist/backend/claude-code.js.map +1 -1
- package/dist/backend/claude-usage-credits.d.ts +8 -0
- package/dist/backend/claude-usage-credits.js +121 -0
- package/dist/backend/claude-usage-credits.js.map +1 -0
- package/dist/backend/types.d.ts +30 -0
- package/dist/backend/types.js.map +1 -1
- package/dist/build-provenance.json +1 -1
- package/dist/channel/adapters/discord.js +7 -1
- package/dist/channel/adapters/discord.js.map +1 -1
- package/dist/channel/tool-router.js +1 -0
- package/dist/channel/tool-router.js.map +1 -1
- package/dist/cli-audited.js +9 -4
- package/dist/cli-audited.js.map +1 -1
- package/dist/cli.js +184 -21
- package/dist/cli.js.map +1 -1
- package/dist/config-validator.js +11 -1
- package/dist/config-validator.js.map +1 -1
- package/dist/config.js +2 -0
- package/dist/config.js.map +1 -1
- package/dist/contact-auth-store.d.ts +18 -0
- package/dist/contact-auth-store.js +55 -8
- package/dist/contact-auth-store.js.map +1 -1
- package/dist/contact-auth-types.d.ts +3 -0
- package/dist/contact-auth-types.js.map +1 -1
- package/dist/contact-change-proposals.d.ts +34 -0
- package/dist/contact-change-proposals.js +1 -1
- package/dist/contact-change-proposals.js.map +1 -1
- package/dist/cross-instance-notice.d.ts +1 -0
- package/dist/cross-instance-notice.js +9 -8
- package/dist/cross-instance-notice.js.map +1 -1
- package/dist/daemon.d.ts +35 -0
- package/dist/daemon.js +234 -19
- package/dist/daemon.js.map +1 -1
- package/dist/delivery-outbox.d.ts +42 -1
- package/dist/delivery-outbox.js +194 -20
- package/dist/delivery-outbox.js.map +1 -1
- package/dist/fleet-context.d.ts +8 -0
- package/dist/fleet-lock.d.ts +67 -2
- package/dist/fleet-lock.js +236 -2
- package/dist/fleet-lock.js.map +1 -1
- package/dist/fleet-manager.d.ts +163 -6
- package/dist/fleet-manager.js +1136 -75
- package/dist/fleet-manager.js.map +1 -1
- package/dist/fleet-windows-runtime.d.ts +20 -1
- package/dist/fleet-windows-runtime.js +98 -18
- package/dist/fleet-windows-runtime.js.map +1 -1
- package/dist/general-knowledge/skills/cross-instance-messaging/SKILL.md +7 -0
- package/dist/general-knowledge/skills/web-dashboard/SKILL.md +14 -4
- package/dist/home-update-lock.d.ts +35 -0
- package/dist/home-update-lock.js +81 -0
- package/dist/home-update-lock.js.map +1 -0
- package/dist/hub/compose/member.d.ts +5 -1
- package/dist/hub/compose/member.js +9 -5
- package/dist/hub/compose/member.js.map +1 -1
- package/dist/hub/member/room-ask.d.ts +5 -0
- package/dist/hub/member/room-ask.js +43 -16
- package/dist/hub/member/room-ask.js.map +1 -1
- package/dist/hub/member/room-mention-feedback.d.ts +2 -0
- package/dist/hub/member/room-mention-feedback.js +1 -1
- package/dist/hub/member/room-mention-feedback.js.map +1 -1
- package/dist/hub/member/room-post-answers.d.ts +2 -0
- package/dist/hub/member/room-post-answers.js +1 -1
- package/dist/hub/member/room-post-answers.js.map +1 -1
- package/dist/hub/member/room-post.d.ts +5 -0
- package/dist/hub/member/room-post.js +4 -1
- package/dist/hub/member/room-post.js.map +1 -1
- package/dist/hub/member/updates.d.ts +7 -1
- package/dist/hub/member/updates.js +7 -1
- package/dist/hub/member/updates.js.map +1 -1
- package/dist/hub/representative.d.ts +7 -0
- package/dist/hub/representative.js +38 -5
- package/dist/hub/representative.js.map +1 -1
- package/dist/install-lock.d.ts +15 -1
- package/dist/install-lock.js +16 -8
- package/dist/install-lock.js.map +1 -1
- package/dist/install-ownership.d.ts +165 -0
- package/dist/install-ownership.js +404 -0
- package/dist/install-ownership.js.map +1 -0
- package/dist/instance-config-impact.js +2 -0
- package/dist/instance-config-impact.js.map +1 -1
- package/dist/instructions.d.ts +4 -0
- package/dist/instructions.js +4 -0
- package/dist/instructions.js.map +1 -1
- package/dist/local-pane-endpoint.d.ts +4 -1
- package/dist/local-pane-endpoint.js +12 -2
- package/dist/local-pane-endpoint.js.map +1 -1
- package/dist/locale.js +160 -4
- package/dist/locale.js.map +1 -1
- package/dist/native-agent-admission.d.ts +7 -0
- package/dist/native-agent-admission.js +46 -3
- package/dist/native-agent-admission.js.map +1 -1
- package/dist/native-mcp.d.ts +16 -1
- package/dist/native-mcp.js +38 -5
- package/dist/native-mcp.js.map +1 -1
- package/dist/native-pane-lifecycle.d.ts +9 -0
- package/dist/native-pane-lifecycle.js +23 -0
- package/dist/native-pane-lifecycle.js.map +1 -1
- package/dist/native-pane-manager.d.ts +19 -6
- package/dist/native-pane-manager.js +79 -4
- package/dist/native-pane-manager.js.map +1 -1
- package/dist/needs-you.d.ts +8 -0
- package/dist/needs-you.js +1 -0
- package/dist/needs-you.js.map +1 -1
- package/dist/outbound-handlers.d.ts +12 -0
- package/dist/outbound-handlers.js +30 -2
- package/dist/outbound-handlers.js.map +1 -1
- package/dist/package-preimage.js +4 -0
- package/dist/package-preimage.js.map +1 -1
- package/dist/pane-port.d.ts +1 -0
- package/dist/plist-args.d.ts +9 -0
- package/dist/plist-args.js +22 -0
- package/dist/plist-args.js.map +1 -0
- package/dist/public-preview.d.ts +4 -6
- package/dist/public-preview.js +5 -2
- package/dist/public-preview.js.map +1 -1
- package/dist/public-web-gateway.js +8 -3
- package/dist/public-web-gateway.js.map +1 -1
- package/dist/public-web-link.d.ts +13 -1
- package/dist/public-web-link.js +28 -1
- package/dist/public-web-link.js.map +1 -1
- package/dist/recover.cjs +2452 -0
- package/dist/remote-card-prompt.d.ts +6 -2
- package/dist/remote-card-prompt.js +12 -3
- package/dist/remote-card-prompt.js.map +1 -1
- package/dist/reply-draft.d.ts +12 -0
- package/dist/reply-draft.js +81 -0
- package/dist/reply-draft.js.map +1 -0
- package/dist/request-contact-api.d.ts +15 -0
- package/dist/request-contact-api.js +120 -0
- package/dist/request-contact-api.js.map +1 -0
- package/dist/request-contact-card.d.ts +36 -0
- package/dist/request-contact-card.js +206 -0
- package/dist/request-contact-card.js.map +1 -0
- package/dist/request-contact-gate.d.ts +79 -0
- package/dist/request-contact-gate.js +262 -0
- package/dist/request-contact-gate.js.map +1 -0
- package/dist/request-contact-native.d.ts +52 -0
- package/dist/request-contact-native.js +83 -0
- package/dist/request-contact-native.js.map +1 -0
- package/dist/request-contact-types.d.ts +86 -0
- package/dist/request-contact-types.js +7 -0
- package/dist/request-contact-types.js.map +1 -0
- package/dist/request-context-call-protocol.d.ts +12 -0
- package/dist/request-context-call-protocol.js +14 -0
- package/dist/request-context-call-protocol.js.map +1 -0
- package/dist/request-context-call.d.ts +22 -0
- package/dist/request-context-call.js +35 -0
- package/dist/request-context-call.js.map +1 -0
- package/dist/request-context-drain.d.ts +39 -0
- package/dist/request-context-drain.js +159 -0
- package/dist/request-context-drain.js.map +1 -0
- package/dist/request-context-fence.d.ts +28 -0
- package/dist/request-context-fence.js +58 -0
- package/dist/request-context-fence.js.map +1 -0
- package/dist/request-context-migration.d.ts +64 -0
- package/dist/request-context-migration.js +158 -0
- package/dist/request-context-migration.js.map +1 -0
- package/dist/request-context-pane.d.ts +25 -0
- package/dist/request-context-pane.js +48 -0
- package/dist/request-context-pane.js.map +1 -0
- package/dist/request-context-policy.d.ts +74 -0
- package/dist/request-context-policy.js +116 -0
- package/dist/request-context-policy.js.map +1 -0
- package/dist/request-context-recovery.d.ts +14 -0
- package/dist/request-context-recovery.js +56 -0
- package/dist/request-context-recovery.js.map +1 -0
- package/dist/request-context-relay.d.ts +19 -0
- package/dist/request-context-relay.js +63 -0
- package/dist/request-context-relay.js.map +1 -0
- package/dist/request-context-returns.d.ts +67 -0
- package/dist/request-context-returns.js +211 -0
- package/dist/request-context-returns.js.map +1 -0
- package/dist/request-context-store.d.ts +2 -1
- package/dist/request-context-store.js +8 -1
- package/dist/request-context-store.js.map +1 -1
- package/dist/request-context-turns.d.ts +99 -0
- package/dist/request-context-turns.js +215 -0
- package/dist/request-context-turns.js.map +1 -0
- package/dist/request-context-view.d.ts +33 -0
- package/dist/request-context-view.js +36 -0
- package/dist/request-context-view.js.map +1 -0
- package/dist/request-hub-context.d.ts +130 -0
- package/dist/request-hub-context.js +89 -0
- package/dist/request-hub-context.js.map +1 -0
- package/dist/request-hub-output.d.ts +11 -0
- package/dist/request-hub-output.js +21 -0
- package/dist/request-hub-output.js.map +1 -0
- package/dist/runtime-cli-install.js +13 -11
- package/dist/runtime-cli-install.js.map +1 -1
- package/dist/runtime-client.d.ts +2 -0
- package/dist/runtime-client.js +17 -4
- package/dist/runtime-client.js.map +1 -1
- package/dist/runtime-coordinator.d.ts +4 -1
- package/dist/runtime-coordinator.js +10 -3
- package/dist/runtime-coordinator.js.map +1 -1
- package/dist/runtime-pane-assets.d.ts +1 -1
- package/dist/runtime-pane-assets.js +1 -1
- package/dist/runtime-pane-assets.js.map +1 -1
- package/dist/runtime-pane-host.d.ts +3 -0
- package/dist/runtime-pane-host.js +39 -21
- package/dist/runtime-pane-host.js.map +1 -1
- package/dist/runtime-pane-link.d.ts +6 -2
- package/dist/runtime-pane-link.js +17 -4
- package/dist/runtime-pane-link.js.map +1 -1
- package/dist/runtime-pane-mcp-relay.d.ts +11 -1
- package/dist/runtime-pane-mcp-relay.js +69 -3
- package/dist/runtime-pane-mcp-relay.js.map +1 -1
- package/dist/runtime-pane-mcp.d.ts +28 -1
- package/dist/runtime-pane-mcp.js +92 -15
- package/dist/runtime-pane-mcp.js.map +1 -1
- package/dist/runtime-pane-port.d.ts +6 -0
- package/dist/runtime-pane-port.js +23 -4
- package/dist/runtime-pane-port.js.map +1 -1
- package/dist/runtime-pane-protocol.d.ts +4 -0
- package/dist/runtime-pane-protocol.js +11 -4
- package/dist/runtime-pane-protocol.js.map +1 -1
- package/dist/runtime-pane-service.d.ts +1 -0
- package/dist/runtime-pane-service.js +25 -9
- package/dist/runtime-pane-service.js.map +1 -1
- package/dist/runtime-pane-stdio-protocol.d.ts +4 -0
- package/dist/runtime-pane-stdio-protocol.js +12 -5
- package/dist/runtime-pane-stdio-protocol.js.map +1 -1
- package/dist/runtime-pane-stdio.js +5 -5
- package/dist/runtime-pane-stdio.js.map +1 -1
- package/dist/runtime-protocol.d.ts +3 -0
- package/dist/runtime-protocol.js.map +1 -1
- package/dist/scheduler/scheduler.d.ts +6 -0
- package/dist/scheduler/scheduler.js +19 -1
- package/dist/scheduler/scheduler.js.map +1 -1
- package/dist/scheduler/task-board.d.ts +4 -0
- package/dist/scheduler/task-board.js +6 -0
- package/dist/scheduler/task-board.js.map +1 -1
- package/dist/scheduler/types.d.ts +1 -1
- package/dist/service-activation.js +3 -13
- package/dist/service-activation.js.map +1 -1
- package/dist/service-lock.d.ts +28 -0
- package/dist/service-lock.js +85 -0
- package/dist/service-lock.js.map +1 -0
- package/dist/settings-api.d.ts +6 -0
- package/dist/settings-api.js +35 -0
- package/dist/settings-api.js.map +1 -1
- package/dist/settings-change.js +1 -1
- package/dist/settings-change.js.map +1 -1
- package/dist/state-lease.d.ts +24 -0
- package/dist/state-lease.js +103 -0
- package/dist/state-lease.js.map +1 -0
- package/dist/tmux-binary.js +1 -1
- package/dist/tmux-binary.js.map +1 -1
- package/dist/tool-receipt-output.d.ts +2 -0
- package/dist/topic-commands.js +21 -1
- package/dist/topic-commands.js.map +1 -1
- package/dist/transcript-monitor.js +3 -0
- package/dist/transcript-monitor.js.map +1 -1
- package/dist/tunnel/named-link-test.d.ts +27 -0
- package/dist/tunnel/named-link-test.js +41 -0
- package/dist/tunnel/named-link-test.js.map +1 -1
- package/dist/types.d.ts +7 -0
- package/dist/ui/chat-store.js +5 -4
- package/dist/ui/fleet-office-card.js +15 -2
- package/dist/ui/fleet-office-skin.js +33 -9
- package/dist/ui/fleet-office-zones.js +8 -3
- package/dist/ui/fleet-office.js +136 -18
- package/dist/ui/fleet-task-files.js +1 -1
- package/dist/ui/panel-chat.js +15 -2
- package/dist/ui/panel-needs.js +22 -2
- package/dist/ui/panel-settings.js +22 -8
- package/dist/ui/settings-preview-address.js +156 -0
- package/dist/ui/settings-registry.js +2 -0
- package/dist/ui/settings-strings.js +6 -6
- package/dist/ui/shared/app.css +76 -2
- package/dist/ui/shared/chat-strings.js +6 -2
- package/dist/ui/shared/chat-thread.js +7 -1
- package/dist/ui/shared/preview-panel.js +1 -1
- package/dist/ui/shared/preview.js +11 -2
- package/dist/ui/shared/tokens.css +18 -3
- package/dist/ui/shared/ui-confirm.js +5 -4
- package/dist/ui/shared/workspace.css +7 -0
- package/dist/ui/usage-credits-card.js +84 -0
- package/dist/ui/workspace-ignored-strings.js +16 -0
- package/dist/ui/workspace-panel.js +15 -6
- package/dist/update-card.d.ts +193 -0
- package/dist/update-card.js +620 -0
- package/dist/update-card.js.map +1 -0
- package/dist/update-dispatch.d.ts +16 -1
- package/dist/update-dispatch.js +12 -4
- package/dist/update-dispatch.js.map +1 -1
- package/dist/update-forward.d.ts +73 -0
- package/dist/update-forward.js +283 -0
- package/dist/update-forward.js.map +1 -0
- package/dist/update-idle.d.ts +1 -0
- package/dist/update-idle.js +12 -3
- package/dist/update-idle.js.map +1 -1
- package/dist/update-install.d.ts +2 -1
- package/dist/update-install.js +18 -10
- package/dist/update-install.js.map +1 -1
- package/dist/update-journal.d.ts +351 -0
- package/dist/update-journal.js +717 -0
- package/dist/update-journal.js.map +1 -0
- package/dist/update-launch.js +1 -1
- package/dist/update-launch.js.map +1 -1
- package/dist/update-npm-env.d.ts +45 -12
- package/dist/update-npm-env.js +48 -0
- package/dist/update-npm-env.js.map +1 -1
- package/dist/update-package-restore.d.ts +75 -0
- package/dist/update-package-restore.js +318 -0
- package/dist/update-package-restore.js.map +1 -0
- package/dist/update-quiescence.d.ts +192 -0
- package/dist/update-quiescence.js +330 -0
- package/dist/update-quiescence.js.map +1 -0
- package/dist/update-readiness-host.d.ts +61 -0
- package/dist/update-readiness-host.js +297 -0
- package/dist/update-readiness-host.js.map +1 -0
- package/dist/update-readiness.d.ts +83 -0
- package/dist/update-readiness.js +459 -0
- package/dist/update-readiness.js.map +1 -0
- package/dist/update-recovery/kit.d.ts +35 -0
- package/dist/update-recovery/kit.js +99 -0
- package/dist/update-recovery/kit.js.map +1 -0
- package/dist/update-recovery/pre-start.d.ts +34 -0
- package/dist/update-recovery/pre-start.js +103 -0
- package/dist/update-recovery/pre-start.js.map +1 -0
- package/dist/update-recovery/recover-main.d.ts +1 -0
- package/dist/update-recovery/recover-main.js +4 -0
- package/dist/update-recovery/recover-main.js.map +1 -0
- package/dist/update-recovery/recover.d.ts +22 -0
- package/dist/update-recovery/recover.js +124 -0
- package/dist/update-recovery/recover.js.map +1 -0
- package/dist/update-recovery/route.d.ts +53 -0
- package/dist/update-recovery/route.js +262 -0
- package/dist/update-recovery/route.js.map +1 -0
- package/dist/update-recovery/runner.d.ts +58 -0
- package/dist/update-recovery/runner.js +196 -0
- package/dist/update-recovery/runner.js.map +1 -0
- package/dist/update-recovery/service-manager.d.ts +39 -0
- package/dist/update-recovery/service-manager.js +57 -0
- package/dist/update-recovery/service-manager.js.map +1 -0
- package/dist/update-restore.d.ts +44 -0
- package/dist/update-restore.js +355 -0
- package/dist/update-restore.js.map +1 -0
- package/dist/update-retained.d.ts +38 -0
- package/dist/update-retained.js +91 -0
- package/dist/update-retained.js.map +1 -0
- package/dist/update-rollback.d.ts +74 -0
- package/dist/update-rollback.js +221 -0
- package/dist/update-rollback.js.map +1 -0
- package/dist/update-settings.d.ts +36 -0
- package/dist/update-settings.js +122 -0
- package/dist/update-settings.js.map +1 -0
- package/dist/update-snapshot-manifest.d.ts +32 -0
- package/dist/update-snapshot-manifest.js +65 -0
- package/dist/update-snapshot-manifest.js.map +1 -0
- package/dist/update-snapshot-scope.d.ts +67 -0
- package/dist/update-snapshot-scope.js +172 -0
- package/dist/update-snapshot-scope.js.map +1 -0
- package/dist/update-snapshot.d.ts +34 -0
- package/dist/update-snapshot.js +246 -0
- package/dist/update-snapshot.js.map +1 -0
- package/dist/update-writers.d.ts +71 -0
- package/dist/update-writers.js +235 -0
- package/dist/update-writers.js.map +1 -0
- package/dist/web-api.d.ts +3 -0
- package/dist/web-api.js +43 -8
- package/dist/web-api.js.map +1 -1
- package/dist/web-chat-history.d.ts +7 -0
- package/dist/web-chat-history.js +15 -0
- package/dist/web-chat-history.js.map +1 -1
- package/dist/web-preview.d.ts +5 -0
- package/dist/web-preview.js +1 -1
- package/dist/web-preview.js.map +1 -1
- package/dist/web-update.d.ts +6 -0
- package/dist/windows-agents.d.ts +12 -0
- package/dist/windows-agents.js +5 -0
- package/dist/windows-agents.js.map +1 -1
- package/launcher/agend +4 -1
- package/launcher/agend-agent +4 -1
- package/launcher/agend-install.cjs +16 -8
- package/launcher/install-admission.d.cts +8 -0
- package/launcher/npm-allow-scripts.cjs +72 -0
- package/launcher/npm-global-prefix.cjs +81 -0
- package/launcher/postinstall.cjs +9 -8
- package/launcher/runtime-select.cjs +8 -2
- package/package.json +3 -2
- package/scripts/preinstall-guard.cjs +1 -1
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* M-3770 slice 2.3 (design update-transaction §5.1): what the update's snapshot covers, and who writes what.
|
|
3
|
+
*
|
|
4
|
+
* - **The scope** is an exclude list: every path in the home is included except these. `classify(rel)` answers for a
|
|
5
|
+
* path relative to the home (POSIX separators).
|
|
6
|
+
* - **The writer inventory** lists every name the code writes under the home or outside it, with its **phase**:
|
|
7
|
+
* `pre-commit` (fleet startup in trial mode, migrations, the update and rollback themselves) or `post-commit` (agent
|
|
8
|
+
* launch, CLI activity, ordinary operation). A test scans the code's path literals and fails when one isn't listed.
|
|
9
|
+
* - **Eligibility** for the transaction's automatic rollback (§5.1 rev 8): no pre-commit writer may touch excluded user
|
|
10
|
+
* state, a path outside the home that the transaction doesn't restore itself (the unit and package preimages, §6.3),
|
|
11
|
+
* or an excluded cache that an older build would refuse rather than rebuild (`olderBuildRebuilds`). Runtime files and
|
|
12
|
+
* logs are meaningless after a restore and don't count.
|
|
13
|
+
*/
|
|
14
|
+
/** Why a path is left out of the snapshot. */
|
|
15
|
+
export type ExcludeKind = "journal" | "user-state" | "cache" | "log" | "runtime" | "lease";
|
|
16
|
+
interface Rule {
|
|
17
|
+
match: (rel: string) => boolean;
|
|
18
|
+
kind: ExcludeKind;
|
|
19
|
+
rule: string;
|
|
20
|
+
}
|
|
21
|
+
/** §5.1's exclude list. Order doesn't matter: a path excluded by any rule is excluded. */
|
|
22
|
+
export declare const EXCLUDED: readonly Rule[];
|
|
23
|
+
export type Classified = {
|
|
24
|
+
included: true;
|
|
25
|
+
} | {
|
|
26
|
+
included: false;
|
|
27
|
+
kind: ExcludeKind;
|
|
28
|
+
rule: string;
|
|
29
|
+
};
|
|
30
|
+
/** §5.1: is `rel` (relative to the home, `/`-separated, no leading `./`) in the snapshot's scope? */
|
|
31
|
+
export declare function classify(rel: string): Classified;
|
|
32
|
+
export type Phase = "pre-commit" | "post-commit";
|
|
33
|
+
export interface Writer {
|
|
34
|
+
/** Home: the top-level name under the home. Outside: the path relative to the user's home directory. */
|
|
35
|
+
path: string;
|
|
36
|
+
where: "home" | "outside";
|
|
37
|
+
phase: Phase;
|
|
38
|
+
/** Who writes it (module or role), for the reader. */
|
|
39
|
+
by: string;
|
|
40
|
+
/** Outside paths the transaction restores itself (§6.3). */
|
|
41
|
+
restoredBy?: "unit-preimage" | "package-preimage";
|
|
42
|
+
/**
|
|
43
|
+
* An excluded cache written before commit: an older build that finds it rebuilds or ignores it (a schema it doesn't
|
|
44
|
+
* know, an unknown shape) rather than refusing to start. Required for any pre-commit cache writer (§5.1 rev 8).
|
|
45
|
+
*/
|
|
46
|
+
olderBuildRebuilds?: true;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The writer inventory (§5.1). Home names are top-level entries under the home. Names reached only through a helper
|
|
50
|
+
* that takes the home as a parameter (no literal join over a home root) are listed by hand, marked "via <helper>". The test
|
|
51
|
+
* `update-snapshot-scope-m3770` scans the code's `join` calls over a home root (or over the user's home directory) with a
|
|
52
|
+
* literal name, and fails when a name is missing here: a new path is classified before it ships.
|
|
53
|
+
*/
|
|
54
|
+
export declare const WRITER_INVENTORY: readonly Writer[];
|
|
55
|
+
export type Eligibility = {
|
|
56
|
+
ok: true;
|
|
57
|
+
} | {
|
|
58
|
+
ok: false;
|
|
59
|
+
offenders: Writer[];
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* §5.1 eligibility (rev 8): no pre-commit writer touches excluded user state, an outside path the transaction doesn't
|
|
63
|
+
* restore itself, or an excluded cache an older build wouldn't rebuild. Runtime files and logs don't count. (The
|
|
64
|
+
* default home under `~/.agend` is the home, so it's judged as a home path.)
|
|
65
|
+
*/
|
|
66
|
+
export declare function rollbackEligible(inventory?: readonly Writer[]): Eligibility;
|
|
67
|
+
export {};
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* M-3770 slice 2.3 (design update-transaction §5.1): what the update's snapshot covers, and who writes what.
|
|
3
|
+
*
|
|
4
|
+
* - **The scope** is an exclude list: every path in the home is included except these. `classify(rel)` answers for a
|
|
5
|
+
* path relative to the home (POSIX separators).
|
|
6
|
+
* - **The writer inventory** lists every name the code writes under the home or outside it, with its **phase**:
|
|
7
|
+
* `pre-commit` (fleet startup in trial mode, migrations, the update and rollback themselves) or `post-commit` (agent
|
|
8
|
+
* launch, CLI activity, ordinary operation). A test scans the code's path literals and fails when one isn't listed.
|
|
9
|
+
* - **Eligibility** for the transaction's automatic rollback (§5.1 rev 8): no pre-commit writer may touch excluded user
|
|
10
|
+
* state, a path outside the home that the transaction doesn't restore itself (the unit and package preimages, §6.3),
|
|
11
|
+
* or an excluded cache that an older build would refuse rather than rebuild (`olderBuildRebuilds`). Runtime files and
|
|
12
|
+
* logs are meaningless after a restore and don't count.
|
|
13
|
+
*/
|
|
14
|
+
const under = (dir) => (rel) => rel === dir || rel.startsWith(`${dir}/`);
|
|
15
|
+
const exactly = (...names) => (rel) => names.includes(rel);
|
|
16
|
+
const base = (rel) => rel.slice(rel.lastIndexOf("/") + 1);
|
|
17
|
+
/** §5.1's exclude list. Order doesn't matter: a path excluded by any rule is excluded. */
|
|
18
|
+
export const EXCLUDED = [
|
|
19
|
+
{ rule: ".update-journal/", kind: "journal", match: under(".update-journal") },
|
|
20
|
+
{ rule: "update-in-progress.json", kind: "journal", match: exactly("update-in-progress.json") },
|
|
21
|
+
{ rule: "workspaces/", kind: "user-state", match: under("workspaces") },
|
|
22
|
+
{ rule: "credential-profiles/", kind: "user-state", match: under("credential-profiles") },
|
|
23
|
+
{ rule: "cx/", kind: "user-state", match: under("cx") },
|
|
24
|
+
// muse's isolated XDG home per instance (backend/muse.ts): links into the user's ~/.config — the CLI's own config
|
|
25
|
+
// home, the same kind as cx/ and credential-profiles/ (Fable #4523 F3).
|
|
26
|
+
{ rule: "instances/*/muse-xdg/", kind: "user-state", match: rel => /^instances\/[^/]+\/muse-xdg(\/|$)/.test(rel) },
|
|
27
|
+
{ rule: "cache/", kind: "cache", match: under("cache") },
|
|
28
|
+
{ rule: "cache-codex-rollouts.json, usage-last-good.json", kind: "cache", match: exactly("cache-codex-rollouts.json", "usage-last-good.json") },
|
|
29
|
+
{ rule: "search.db*", kind: "cache", match: rel => !rel.includes("/") && rel.startsWith("search.db") },
|
|
30
|
+
{ rule: "*.log", kind: "log", match: rel => base(rel).endsWith(".log") },
|
|
31
|
+
{ rule: "profiles/", kind: "log", match: under("profiles") },
|
|
32
|
+
{ rule: "tmux/, operator/", kind: "runtime", match: rel => under("tmux")(rel) || under("operator")(rel) },
|
|
33
|
+
{ rule: "*.sock", kind: "runtime", match: rel => base(rel).endsWith(".sock") },
|
|
34
|
+
{ rule: "fleet.pid, fleet.lock (+ its reclaim/handoff/tmp files)", kind: "runtime", match: rel => rel === "fleet.pid" || rel === "fleet.lock" || rel.startsWith("fleet.lock.") },
|
|
35
|
+
{ rule: ".update.lock, .service.lock (+ reclaim markers)", kind: "runtime", match: rel => /^\.(update|service)\.lock(\.reclaim)?$/.test(rel) },
|
|
36
|
+
{ rule: "tunnel.lease, web.token, view.token", kind: "runtime", match: exactly("tunnel.lease", "web.token", "view.token") },
|
|
37
|
+
{ rule: ".state-lease.sqlite (+ -journal)", kind: "lease", match: exactly(".state-lease.sqlite", ".state-lease.sqlite-journal") },
|
|
38
|
+
];
|
|
39
|
+
/** §5.1: is `rel` (relative to the home, `/`-separated, no leading `./`) in the snapshot's scope? */
|
|
40
|
+
export function classify(rel) {
|
|
41
|
+
if (rel === "" || rel.startsWith("/") || rel.split("/").some(p => p === "" || p === "." || p === ".."))
|
|
42
|
+
throw new Error(`not a relative path in the home: ${JSON.stringify(rel)}`);
|
|
43
|
+
for (const r of EXCLUDED)
|
|
44
|
+
if (r.match(rel))
|
|
45
|
+
return { included: false, kind: r.kind, rule: r.rule };
|
|
46
|
+
return { included: true };
|
|
47
|
+
}
|
|
48
|
+
const home = (path, phase, by, extra = {}) => ({ path, where: "home", phase, by, ...extra });
|
|
49
|
+
const outside = (path, phase, by, restoredBy) => ({ path, where: "outside", phase, by, ...(restoredBy ? { restoredBy } : {}) });
|
|
50
|
+
/**
|
|
51
|
+
* The writer inventory (§5.1). Home names are top-level entries under the home. Names reached only through a helper
|
|
52
|
+
* that takes the home as a parameter (no literal join over a home root) are listed by hand, marked "via <helper>". The test
|
|
53
|
+
* `update-snapshot-scope-m3770` scans the code's `join` calls over a home root (or over the user's home directory) with a
|
|
54
|
+
* literal name, and fails when a name is missing here: a new path is classified before it ships.
|
|
55
|
+
*/
|
|
56
|
+
export const WRITER_INVENTORY = [
|
|
57
|
+
// ── Fleet startup and migrations (pre-commit: the trial fleet starts before commit) ──
|
|
58
|
+
home("fleet.yaml", "pre-commit", "config load and migrations (fleet-yaml-patch, cli)"),
|
|
59
|
+
home("fleet.pid", "pre-commit", "fleet start"),
|
|
60
|
+
home("fleet.lock", "pre-commit", "fleet start (fleet-lock)"),
|
|
61
|
+
home("fleet.lock.reclaim", "pre-commit", "fleet-lock's reclaim marker (the update's owned re-take of a dead holder)"),
|
|
62
|
+
home("fleet.log", "pre-commit", "fleet logger"),
|
|
63
|
+
home("fleet-fatal.log", "pre-commit", "fleet fatal handler"),
|
|
64
|
+
home("daemon.log", "pre-commit", "daemon logger"),
|
|
65
|
+
home("update.log", "pre-commit", "agend update"),
|
|
66
|
+
home("update-in-progress.json", "pre-commit", "agend update (marker)"),
|
|
67
|
+
home("events.db", "pre-commit", "event log (opened at start)"),
|
|
68
|
+
home("scheduler.db", "pre-commit", "scheduler (opened at start; CLI under the state lease)"),
|
|
69
|
+
home("delivery-outbox.db", "pre-commit", "delivery outbox (opened at start)"),
|
|
70
|
+
home("profiles.db", "pre-commit", "web profiles (opened at start)"),
|
|
71
|
+
home("reply-buttons.db", "pre-commit", "reply buttons (opened at start)"),
|
|
72
|
+
home("instances", "pre-commit", "instance state at start (instances/<name>/…)"),
|
|
73
|
+
home("tmux", "pre-commit", "private tmux server"),
|
|
74
|
+
home("tmux-migration.json", "pre-commit", "tmux migration"),
|
|
75
|
+
home("operator", "pre-commit", "operator socket"),
|
|
76
|
+
home("web.token", "pre-commit", "web server start"),
|
|
77
|
+
home("view.token", "pre-commit", "web server start"),
|
|
78
|
+
home("tunnel.lease", "pre-commit", "tunnel at start"),
|
|
79
|
+
home("cli-env", "pre-commit", "CLI environment files at start"),
|
|
80
|
+
home("hub-member", "pre-commit", "Hub member state at start"),
|
|
81
|
+
home("hub-member-invalidate.pending", "pre-commit", "Hub member invalidation"),
|
|
82
|
+
home("kiro-v3", "pre-commit", "kiro engine at start"),
|
|
83
|
+
home("kiro-engine-ledger.json", "pre-commit", "kiro engine at start"),
|
|
84
|
+
home("kiro-identity", "pre-commit", "kiro engine identity"),
|
|
85
|
+
home(".update-journal", "pre-commit", "the update transaction"),
|
|
86
|
+
home("host-monitoring.sqlite", "pre-commit", "host monitoring (a SQLite database opened at fleet start; §5.3 treats it as one)"),
|
|
87
|
+
home("rollback.json", "pre-commit", "tmux migration rollback (tmux-rollback)"),
|
|
88
|
+
home("kiro-classic-archives", "pre-commit", "kiro classic migration (kiro-classic-archive, kiro-migration-verify)"),
|
|
89
|
+
home("kiro-reconciliations", "pre-commit", "kiro reconcile store"),
|
|
90
|
+
home("search.db", "pre-commit", "search index (startSearchIndex at fleet start); another schema → rebuilt (search-store meta.schema)", { olderBuildRebuilds: true }),
|
|
91
|
+
home("cache-codex-rollouts.json", "pre-commit", "cache service's codex rollout metadata; unknown entries are skipped (cache-service)", { olderBuildRebuilds: true }),
|
|
92
|
+
home("usage-last-good.json", "pre-commit", "usage last-good rows; another version or shape is ignored (usage-api loadLastGood)", { olderBuildRebuilds: true }),
|
|
93
|
+
// ── Ordinary operation (post-commit) ──
|
|
94
|
+
home("workspaces", "post-commit", "agent launch (the agents' working directories)"),
|
|
95
|
+
home("credential-profiles", "post-commit", "agent launch (the CLIs' homes, each profile's .claude.json)"),
|
|
96
|
+
home("cx", "post-commit", "codex backend at agent launch"),
|
|
97
|
+
home("instances/*/muse-xdg", "post-commit", "muse backend at agent launch (its isolated XDG home: links into ~/.config)"),
|
|
98
|
+
home("cache", "post-commit", "caches"),
|
|
99
|
+
home("usage-quota-history.jsonl", "post-commit", "usage"),
|
|
100
|
+
home("quota-notices.json", "post-commit", "usage notices"),
|
|
101
|
+
home("profiles", "post-commit", "CPU profiles"),
|
|
102
|
+
home("access", "post-commit", "channel access lists"),
|
|
103
|
+
home("inbox", "post-commit", "attachments inbox"),
|
|
104
|
+
home("avatars", "post-commit", "web avatars"),
|
|
105
|
+
home("cards", "post-commit", "web cards"),
|
|
106
|
+
home("archived-topics.json", "post-commit", "topic archive"),
|
|
107
|
+
home("backend-signin-pending.json", "post-commit", "backend sign-in"),
|
|
108
|
+
home("bin", "post-commit", "cloudflared install"),
|
|
109
|
+
home(".env", "post-commit", "quickstart settings"),
|
|
110
|
+
home("classicBot.yaml", "post-commit", "ClassicBot"),
|
|
111
|
+
home("credential-vault", "post-commit", "credential vault"),
|
|
112
|
+
home("delivery-audit", "post-commit", "delivery audit"),
|
|
113
|
+
home("forged-envelope-reports.json", "post-commit", "envelope reports"),
|
|
114
|
+
home("hub-assistant", "post-commit", "Hub room assistant"),
|
|
115
|
+
home("hub-classic-private.json", "post-commit", "Hub ClassicBot sharing"),
|
|
116
|
+
home("hub-contact-windows.json", "post-commit", "Hub contact windows"),
|
|
117
|
+
home("pending-owner-notices.json", "post-commit", "owner notices"),
|
|
118
|
+
home("skipped-skills.json", "post-commit", "skill sync"),
|
|
119
|
+
home("web-app-icon", "post-commit", "web settings"),
|
|
120
|
+
home("web-authority.json", "post-commit", "web sign-in"),
|
|
121
|
+
home("web-authorizations.json", "post-commit", "web sign-in"),
|
|
122
|
+
home("web-devices.json", "post-commit", "web sign-in"),
|
|
123
|
+
home("web-host-authorized", "post-commit", "web host"),
|
|
124
|
+
home("web-mods", "post-commit", "web mods"),
|
|
125
|
+
home("web-mods.json", "post-commit", "web mods"),
|
|
126
|
+
home("web-office-skins", "post-commit", "web office"),
|
|
127
|
+
home("web-offices.json", "post-commit", "web office"),
|
|
128
|
+
home("web-owner-css", "post-commit", "web theme"),
|
|
129
|
+
home("web-pins.json", "post-commit", "web pins"),
|
|
130
|
+
home("web-sessions.json", "post-commit", "web sessions"),
|
|
131
|
+
home("web-themes", "post-commit", "web themes"),
|
|
132
|
+
home("web-themes.json", "post-commit", "web themes"),
|
|
133
|
+
home("needs-you-message.json", "post-commit", "Needs-you hub"),
|
|
134
|
+
home("agy-statusline.sh", "post-commit", "antigravity backend at agent launch"),
|
|
135
|
+
home("shared", "post-commit", "web office packs (web-office-pack-read; its stateDir is the home)"),
|
|
136
|
+
home("signin-launch", "post-commit", "web sign-in links — via web-signin-link's join over the home it is passed (cli.ts passes DATA_DIR)"),
|
|
137
|
+
// ── Outside the home ──
|
|
138
|
+
outside(".claude.json", "post-commit", "claude-code backend at agent launch (trust, onboarding); $CLAUDE_CONFIG_DIR/.claude.json when set"),
|
|
139
|
+
outside(".claude", "post-commit", "claude-code backend and usage at agent launch"),
|
|
140
|
+
outside(".codex", "post-commit", "codex backend at agent launch"),
|
|
141
|
+
outside(".gemini", "post-commit", "gemini profiles at agent launch"),
|
|
142
|
+
outside(".grok", "post-commit", "grok backend at agent launch"),
|
|
143
|
+
outside(".kiro", "post-commit", "kiro backend at agent launch"),
|
|
144
|
+
outside(".local", "post-commit", "backend CLIs' data at agent launch"),
|
|
145
|
+
outside("AppData", "post-commit", "Windows pane stdio"),
|
|
146
|
+
outside(".agend", "pre-commit", "the default AgEnD home itself (paths.ts) — the home, not outside it"),
|
|
147
|
+
outside(".config", "pre-commit", "the systemd user unit (service-installer)", "unit-preimage"),
|
|
148
|
+
outside("Library", "pre-commit", "the launchd agent plist (service-installer)", "unit-preimage"),
|
|
149
|
+
outside(".npm-global", "pre-commit", "the npm prefix (the install itself)", "package-preimage"),
|
|
150
|
+
outside(".nvm", "pre-commit", "nvm's Node prefix (the install itself)", "package-preimage"),
|
|
151
|
+
];
|
|
152
|
+
/**
|
|
153
|
+
* §5.1 eligibility (rev 8): no pre-commit writer touches excluded user state, an outside path the transaction doesn't
|
|
154
|
+
* restore itself, or an excluded cache an older build wouldn't rebuild. Runtime files and logs don't count. (The
|
|
155
|
+
* default home under `~/.agend` is the home, so it's judged as a home path.)
|
|
156
|
+
*/
|
|
157
|
+
export function rollbackEligible(inventory = WRITER_INVENTORY) {
|
|
158
|
+
const offenders = inventory.filter(w => {
|
|
159
|
+
if (w.phase !== "pre-commit")
|
|
160
|
+
return false;
|
|
161
|
+
if (w.where === "outside")
|
|
162
|
+
return w.path !== ".agend" && !w.restoredBy;
|
|
163
|
+
const c = classify(w.path);
|
|
164
|
+
if (c.included)
|
|
165
|
+
return false;
|
|
166
|
+
if (c.kind === "user-state")
|
|
167
|
+
return true;
|
|
168
|
+
return c.kind === "cache" && !w.olderBuildRebuilds; // an older build must rebuild it, never refuse it
|
|
169
|
+
});
|
|
170
|
+
return offenders.length ? { ok: false, offenders } : { ok: true };
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=update-snapshot-scope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-snapshot-scope.js","sourceRoot":"","sources":["../src/update-snapshot-scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAaH,MAAM,KAAK,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,KAAK,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC;AACzF,MAAM,OAAO,GAAG,CAAC,GAAG,KAAe,EAAE,EAAE,CAAC,CAAC,GAAW,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;AAC7E,MAAM,IAAI,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;AAElE,0FAA0F;AAC1F,MAAM,CAAC,MAAM,QAAQ,GAAoB;IACvC,EAAE,IAAI,EAAE,kBAAkB,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,CAAC,iBAAiB,CAAC,EAAE;IAC9E,EAAE,IAAI,EAAE,yBAAyB,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC,yBAAyB,CAAC,EAAE;IAC/F,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,KAAK,CAAC,YAAY,CAAC,EAAE;IACvE,EAAE,IAAI,EAAE,sBAAsB,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE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MAAM,SAAS,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE;QACrC,IAAI,CAAC,CAAC,KAAK,KAAK,YAAY;YAAE,OAAO,KAAK,CAAC;QAC3C,IAAI,CAAC,CAAC,KAAK,KAAK,SAAS;YAAE,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC;QACvE,MAAM,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAC3B,IAAI,CAAC,CAAC,QAAQ;YAAE,OAAO,KAAK,CAAC;QAC7B,IAAI,CAAC,CAAC,IAAI,KAAK,YAAY;YAAE,OAAO,IAAI,CAAC;QACzC,OAAO,CAAC,CAAC,IAAI,KAAK,OAAO,IAAI,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAU,kDAAkD;IACjH,CAAC,CAAC,CAAC;IACH,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;AACpE,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export { SNAPSHOT_DIR, SNAPSHOT_MANIFEST, readManifest, verifySnapshot, type EntryType, type ManifestEntry, type DatabaseRecord, type SnapshotManifest } from "./update-snapshot-manifest.js";
|
|
2
|
+
import { type ManifestEntry, type SnapshotManifest } from "./update-snapshot-manifest.js";
|
|
3
|
+
export type SnapshotResult = {
|
|
4
|
+
ok: true;
|
|
5
|
+
manifest: SnapshotManifest;
|
|
6
|
+
manifestSha256: string;
|
|
7
|
+
} | {
|
|
8
|
+
ok: false;
|
|
9
|
+
reason: string;
|
|
10
|
+
};
|
|
11
|
+
export interface SnapshotDeps {
|
|
12
|
+
/** §4.4: every writer of the home is gone (the exempt set aside). Called before the walk and after the copy. */
|
|
13
|
+
proveWritersGone(): {
|
|
14
|
+
ok: true;
|
|
15
|
+
} | {
|
|
16
|
+
ok: false;
|
|
17
|
+
reason: string;
|
|
18
|
+
};
|
|
19
|
+
/** Test seam: called after each file is copied. */
|
|
20
|
+
afterCopy?(rel: string): void;
|
|
21
|
+
}
|
|
22
|
+
interface Walked {
|
|
23
|
+
entries: ManifestEntry[];
|
|
24
|
+
files: string[];
|
|
25
|
+
}
|
|
26
|
+
/** §5.2: the scope, from the home's realpath, never following a link. */
|
|
27
|
+
export declare function walkScope(home: string): Walked;
|
|
28
|
+
/**
|
|
29
|
+
* §5.3: snapshot the home into `<attemptDir>/snapshot/` and `<attemptDir>/snapshot.json`. The attempt directory must
|
|
30
|
+
* exist; the snapshot directory must not (a retry starts over: the caller removes a partial one first).
|
|
31
|
+
*/
|
|
32
|
+
export declare function takeSnapshot(home: string, attemptDir: string, deps: SnapshotDeps): SnapshotResult;
|
|
33
|
+
/** The directory a manifest entry's parent is in, for callers building restore plans. */
|
|
34
|
+
export declare const parentOf: (rel: string) => string;
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* M-3770 slice 2.3 (design update-transaction §4.5, §5.2, §5.3): the update's snapshot of the home, taken in
|
|
3
|
+
* `snapshotted` while every writer is fenced (§4.2) and proven gone (§4.4; `proveWritersGone`, before and after).
|
|
4
|
+
*
|
|
5
|
+
* - **Confinement (§5.2).** The scope (§5.1) is walked from `realpath(home)` with `lstat`, never following a link. A
|
|
6
|
+
* symlink is recorded as a link with its target text. A link that resolves INSIDE the home is recorded whatever it
|
|
7
|
+
* points to (AgEnD makes such links: `instances/<name>/codex-home` → `cx/<hash>`): its target is snapshotted already
|
|
8
|
+
* or excluded on purpose. A link that resolves OUTSIDE the home to a directory or a SQLite database refuses the
|
|
9
|
+
* snapshot (Fable #4523 F2/F3): a rollback would put the link back while the newer state behind it stays — the very
|
|
10
|
+
* failure the snapshot exists to prevent. (The target is `stat`ed and its first 16 bytes peeked; it is never opened as
|
|
11
|
+
* a database, and a linked directory is never entered.) Every
|
|
12
|
+
* included regular file's components below the home are real directories (the walk only descends into those), and
|
|
13
|
+
* its realpath lies inside the home's. Anything that is neither a file, a directory nor a link refuses the snapshot.
|
|
14
|
+
* - **SQLite (§4.5).** A file is a database when it starts with SQLite's header. Each is opened alone at its confined
|
|
15
|
+
* path, its `dev`/`ino` compared before and after; `PRAGMA wal_checkpoint(TRUNCATE)` must report `busy = 0` and
|
|
16
|
+
* `log = checkpointed`; `PRAGMA quick_check` must say `ok`. Its `user_version` and a hash of its schema are recorded.
|
|
17
|
+
* Its `-wal`, `-shm` and `-journal` files are not copied: after a verified checkpoint they hold nothing it needs.
|
|
18
|
+
* - **The copy (§5.3).** Each file to `snapshot/<rel>` (a clone where the filesystem can), its mode and mtime kept,
|
|
19
|
+
* fsynced; each directory fsynced after its entries, bottom-up; links recreated with their targets. The manifest
|
|
20
|
+
* `snapshot.json` (every entry: rel, type, mode, size, sha256, target; plus the databases) is written last and
|
|
21
|
+
* fsynced, then the attempt directory. `verifySnapshot` walks the copy again and compares it with the manifest as an
|
|
22
|
+
* exact set.
|
|
23
|
+
*
|
|
24
|
+
* A failure anywhere — confinement, a database, the copy, the writers' proof — removes the partial snapshot THIS call
|
|
25
|
+
* made, and says why: the caller abandons the attempt (§2.3). A snapshot already present is never touched (§5.3: it is
|
|
26
|
+
* immutable once published). Nothing is written into the home except each database's own checkpoint (§4.5: the WAL
|
|
27
|
+
* folded into the main file and truncated, a `-shm` possibly created, a hot rollback journal rolled back).
|
|
28
|
+
*/
|
|
29
|
+
import Database from "better-sqlite3";
|
|
30
|
+
import { createHash } from "node:crypto";
|
|
31
|
+
import { closeSync, constants as fsConstants, copyFileSync, existsSync, fsyncSync, lstatSync, mkdirSync, openSync, readdirSync, readFileSync, readlinkSync, readSync, realpathSync, rmSync, statSync, symlinkSync, utimesSync, chmodSync, writeSync, renameSync } from "node:fs";
|
|
32
|
+
import { dirname, join, sep } from "node:path";
|
|
33
|
+
import { classify } from "./update-snapshot-scope.js";
|
|
34
|
+
// The manifest's types, reader and verifier live in update-snapshot-manifest.ts: free of SQLite, so the recovery kit's
|
|
35
|
+
// bundle can restore from a snapshot without loading a native module (M-3770 2.5).
|
|
36
|
+
export { SNAPSHOT_DIR, SNAPSHOT_MANIFEST, readManifest, verifySnapshot } from "./update-snapshot-manifest.js";
|
|
37
|
+
import { SNAPSHOT_DIR, SNAPSHOT_MANIFEST, verifySnapshot } from "./update-snapshot-manifest.js";
|
|
38
|
+
const SQLITE_HEADER = Buffer.from("SQLite format 3\0", "latin1");
|
|
39
|
+
const SIDECARS = ["-wal", "-shm", "-journal"];
|
|
40
|
+
const sha256File = (path) => createHash("sha256").update(readFileSync(path)).digest("hex");
|
|
41
|
+
const fsyncPath = (path) => { const fd = openSync(path, "r"); try {
|
|
42
|
+
fsyncSync(fd);
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
closeSync(fd);
|
|
46
|
+
} };
|
|
47
|
+
function isSqlite(path) {
|
|
48
|
+
const fd = openSync(path, "r");
|
|
49
|
+
try {
|
|
50
|
+
const buf = Buffer.alloc(16);
|
|
51
|
+
return readSync(fd, buf, 0, 16, 0) === 16 && buf.equals(SQLITE_HEADER);
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
closeSync(fd);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* What a link leads to that the snapshot can't protect: a directory or a SQLite database (header peeked, never opened
|
|
59
|
+
* as one) OUTSIDE the home. null: it resolves inside the home, dangles, or is a plain file — recorded as a link.
|
|
60
|
+
*/
|
|
61
|
+
function linkedTarget(link, root) {
|
|
62
|
+
let st, real;
|
|
63
|
+
try {
|
|
64
|
+
real = realpathSync(link);
|
|
65
|
+
st = statSync(link);
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
if (real === root || real.startsWith(root + sep))
|
|
71
|
+
return null;
|
|
72
|
+
if (st.isDirectory())
|
|
73
|
+
return "a directory";
|
|
74
|
+
if (st.isFile()) {
|
|
75
|
+
try {
|
|
76
|
+
if (isSqlite(link))
|
|
77
|
+
return "a SQLite database";
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return "a file that can't be read";
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
class Refused extends Error {
|
|
86
|
+
}
|
|
87
|
+
const refuse = (why) => { throw new Refused(why); };
|
|
88
|
+
/** §5.2: the scope, from the home's realpath, never following a link. */
|
|
89
|
+
export function walkScope(home) {
|
|
90
|
+
const root = realpathSync(home);
|
|
91
|
+
const entries = [], files = [];
|
|
92
|
+
const visit = (rel) => {
|
|
93
|
+
const abs = rel ? join(root, rel) : root;
|
|
94
|
+
for (const name of readdirSync(abs).sort()) {
|
|
95
|
+
const childRel = rel ? `${rel}/${name}` : name;
|
|
96
|
+
if (!classify(childRel).included)
|
|
97
|
+
continue;
|
|
98
|
+
const st = lstatSync(join(abs, name));
|
|
99
|
+
const mode = st.mode & 0o7777;
|
|
100
|
+
if (st.isSymbolicLink()) {
|
|
101
|
+
const behind = linkedTarget(join(abs, name), root);
|
|
102
|
+
if (behind)
|
|
103
|
+
refuse(`${childRel} is a link to ${behind} outside the home; the rollback couldn't restore what's behind it`);
|
|
104
|
+
entries.push({ rel: childRel, type: "link", mode, target: readlinkSync(join(abs, name)) });
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (st.isDirectory()) {
|
|
108
|
+
entries.push({ rel: childRel, type: "dir", mode });
|
|
109
|
+
visit(childRel);
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
if (!st.isFile())
|
|
113
|
+
refuse(`${childRel} is neither a file, a directory nor a link`);
|
|
114
|
+
const real = realpathSync(join(abs, name));
|
|
115
|
+
if (real !== join(root, childRel) && !real.startsWith(root + sep))
|
|
116
|
+
refuse(`${childRel} resolves outside the home`);
|
|
117
|
+
entries.push({ rel: childRel, type: "file", mode, size: st.size, mtimeMs: st.mtimeMs });
|
|
118
|
+
files.push(childRel);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
visit("");
|
|
122
|
+
return { entries, files };
|
|
123
|
+
}
|
|
124
|
+
/** §4.5: checkpoint, check and describe one database, at its confined path. */
|
|
125
|
+
function settleDatabase(path, rel) {
|
|
126
|
+
const before = statSync(path);
|
|
127
|
+
const db = new Database(path, { fileMustExist: true });
|
|
128
|
+
try {
|
|
129
|
+
const row = db.pragma("wal_checkpoint(TRUNCATE)")[0];
|
|
130
|
+
if (!row || row.busy !== 0 || row.log !== row.checkpointed)
|
|
131
|
+
refuse(`${rel}'s checkpoint is incomplete (busy ${row?.busy}, log ${row?.log}, checkpointed ${row?.checkpointed})`);
|
|
132
|
+
const check = db.pragma("quick_check", { simple: true });
|
|
133
|
+
if (check !== "ok")
|
|
134
|
+
refuse(`${rel} fails its quick_check (${String(check)})`);
|
|
135
|
+
const userVersion = Number(db.pragma("user_version", { simple: true }));
|
|
136
|
+
const schema = db.prepare("SELECT type, name, tbl_name, sql FROM sqlite_master ORDER BY type, name").all();
|
|
137
|
+
const schemaSha256 = createHash("sha256").update(JSON.stringify(schema)).digest("hex");
|
|
138
|
+
return { rel, userVersion, schemaSha256 };
|
|
139
|
+
}
|
|
140
|
+
finally {
|
|
141
|
+
db.close();
|
|
142
|
+
const after = statSync(path);
|
|
143
|
+
if (after.dev !== before.dev || after.ino !== before.ino)
|
|
144
|
+
refuse(`${rel} was replaced while it was checked`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* §5.3: snapshot the home into `<attemptDir>/snapshot/` and `<attemptDir>/snapshot.json`. The attempt directory must
|
|
149
|
+
* exist; the snapshot directory must not (a retry starts over: the caller removes a partial one first).
|
|
150
|
+
*/
|
|
151
|
+
export function takeSnapshot(home, attemptDir, deps) {
|
|
152
|
+
const out = join(attemptDir, SNAPSHOT_DIR), manifestPath = join(attemptDir, SNAPSHOT_MANIFEST);
|
|
153
|
+
// A snapshot already here is never touched (Fable #4523 F1): refused before anything is done.
|
|
154
|
+
if (existsSync(out) || existsSync(manifestPath))
|
|
155
|
+
return { ok: false, reason: "a snapshot is already here; the caller removes a partial one first" };
|
|
156
|
+
let madeDir = false, wroteManifest = false, openedTmp = null;
|
|
157
|
+
try {
|
|
158
|
+
const first = deps.proveWritersGone();
|
|
159
|
+
if (!first.ok)
|
|
160
|
+
refuse(`writers are present: ${first.reason}`);
|
|
161
|
+
const root = realpathSync(home);
|
|
162
|
+
const walked = walkScope(home);
|
|
163
|
+
// Databases first (§5.2): settled at their confined paths before anything is copied.
|
|
164
|
+
const databases = [];
|
|
165
|
+
const dbRels = new Set();
|
|
166
|
+
for (const rel of walked.files) {
|
|
167
|
+
if (SIDECARS.some(s => rel.endsWith(s)))
|
|
168
|
+
continue;
|
|
169
|
+
if (isSqlite(join(root, rel))) {
|
|
170
|
+
databases.push(settleDatabase(join(root, rel), rel));
|
|
171
|
+
dbRels.add(rel);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
const sidecarOf = (rel) => SIDECARS.some(s => rel.endsWith(s) && dbRels.has(rel.slice(0, -s.length)));
|
|
175
|
+
const entries = walked.entries.filter(e => !(e.type === "file" && sidecarOf(e.rel)));
|
|
176
|
+
mkdirSync(out, { mode: 0o700 });
|
|
177
|
+
madeDir = true;
|
|
178
|
+
const dirs = [out];
|
|
179
|
+
for (const e of entries) {
|
|
180
|
+
const src = join(root, e.rel), dst = join(out, e.rel);
|
|
181
|
+
if (e.type === "dir") {
|
|
182
|
+
mkdirSync(dst, { mode: 0o700 });
|
|
183
|
+
dirs.push(dst);
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
if (e.type === "link") {
|
|
187
|
+
symlinkSync(e.target, dst);
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
copyFileSync(src, dst, fsConstants.COPYFILE_EXCL | fsConstants.COPYFILE_FICLONE);
|
|
191
|
+
chmodSync(dst, e.mode);
|
|
192
|
+
utimesSync(dst, new Date(e.mtimeMs), new Date(e.mtimeMs));
|
|
193
|
+
fsyncPath(dst);
|
|
194
|
+
e.sha256 = sha256File(dst);
|
|
195
|
+
e.size = statSync(dst).size;
|
|
196
|
+
deps.afterCopy?.(e.rel);
|
|
197
|
+
}
|
|
198
|
+
// Directories: their modes, then fsynced bottom-up (deepest first).
|
|
199
|
+
for (const e of entries)
|
|
200
|
+
if (e.type === "dir")
|
|
201
|
+
chmodSync(join(out, e.rel), e.mode);
|
|
202
|
+
for (const d of dirs.sort((a, b) => b.length - a.length))
|
|
203
|
+
fsyncPath(d);
|
|
204
|
+
const after = deps.proveWritersGone();
|
|
205
|
+
if (!after.ok)
|
|
206
|
+
refuse(`a writer appeared during the copy: ${after.reason}`);
|
|
207
|
+
for (const e of entries)
|
|
208
|
+
delete e.mtimeMs;
|
|
209
|
+
const manifest = { schema: 1, home: root, entries, databases };
|
|
210
|
+
const text = JSON.stringify(manifest, null, 2) + "\n";
|
|
211
|
+
const tmp = `${manifestPath}.tmp-${process.pid}`;
|
|
212
|
+
const fd = openSync(tmp, "wx", 0o600);
|
|
213
|
+
openedTmp = tmp;
|
|
214
|
+
try {
|
|
215
|
+
writeSync(fd, text);
|
|
216
|
+
fsyncSync(fd);
|
|
217
|
+
}
|
|
218
|
+
finally {
|
|
219
|
+
closeSync(fd);
|
|
220
|
+
}
|
|
221
|
+
renameSync(tmp, manifestPath);
|
|
222
|
+
openedTmp = null;
|
|
223
|
+
wroteManifest = true;
|
|
224
|
+
fsyncPath(attemptDir);
|
|
225
|
+
const verified = verifySnapshot(attemptDir, manifest);
|
|
226
|
+
if (!verified.ok)
|
|
227
|
+
refuse(verified.reason);
|
|
228
|
+
return { ok: true, manifest, manifestSha256: createHash("sha256").update(text).digest("hex") };
|
|
229
|
+
}
|
|
230
|
+
catch (err) {
|
|
231
|
+
// Only what this call made is removed.
|
|
232
|
+
try {
|
|
233
|
+
if (openedTmp)
|
|
234
|
+
rmSync(openedTmp, { force: true }); // Fable #4523 N2: this call's manifest tmp
|
|
235
|
+
if (wroteManifest)
|
|
236
|
+
rmSync(manifestPath, { force: true });
|
|
237
|
+
if (madeDir)
|
|
238
|
+
rmSync(out, { recursive: true, force: true });
|
|
239
|
+
}
|
|
240
|
+
catch { /* best effort */ }
|
|
241
|
+
return { ok: false, reason: err instanceof Refused ? err.message : `the snapshot failed (${err.message})` };
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
/** The directory a manifest entry's parent is in, for callers building restore plans. */
|
|
245
|
+
export const parentOf = (rel) => (rel.includes("/") ? dirname(rel) : "");
|
|
246
|
+
//# sourceMappingURL=update-snapshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-snapshot.js","sourceRoot":"","sources":["../src/update-snapshot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,SAAS,IAAI,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EACxJ,QAAQ,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACvH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAEtD,uHAAuH;AACvH,mFAAmF;AACnF,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,YAAY,EAAE,cAAc,EAAkF,MAAM,+BAA+B,CAAC;AAC9L,OAAO,EAAE,YAA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,EAAE;YAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC1C,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;IACjG,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,uCAAuC;QACvC,IAAI,CAAC;YACH,IAAI,SAAS;gBAAE,MAAM,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAuB,2CAA2C;YACpH,IAAI,aAAa;gBAAE,MAAM,CAAC,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;YACzD,IAAI,OAAO;gBAAE,MAAM,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QAC7D,CAAC;QAAC,MAAM,CAAC,CAAC,iBAAiB,CAAC,CAAC;QAC7B,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,YAAY,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,wBAAyB,GAAa,CAAC,OAAO,GAAG,EAAE,CAAC;IACzH,CAAC;AACH,CAAC;AAED,yFAAyF;AACzF,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { ProcessStartRecord } from "./update-journal.js";
|
|
2
|
+
export interface WritersDeps {
|
|
3
|
+
/** Every pid now; null when the listing fails. */
|
|
4
|
+
listPids(): number[] | null;
|
|
5
|
+
/** The process's real uid; "gone" when it exited; null when unreadable. */
|
|
6
|
+
uidOf(pid: number): number | "gone" | null;
|
|
7
|
+
/** Its environment's AGEND_HOME (undefined: unset); "gone"; null: unreadable. */
|
|
8
|
+
agendHomeOf(pid: number): string | undefined | "gone" | null;
|
|
9
|
+
/** Its cwd; "gone"; null: unreadable. */
|
|
10
|
+
cwdOf(pid: number): string | "gone" | null;
|
|
11
|
+
/** The paths it has open (fd link targets) and mapped (maps); "gone"; null: unreadable. */
|
|
12
|
+
filesOf(pid: number): string[] | "gone" | null;
|
|
13
|
+
/** Its parent pid; "gone"; null. */
|
|
14
|
+
ppidOf(pid: number): number | "gone" | null;
|
|
15
|
+
/** `pid`'s start as install-lock records it; null when it can't be read (gone, or mid-exec). */
|
|
16
|
+
startOf(pid: number): ProcessStartRecord | null;
|
|
17
|
+
/** Wait (synchronously) between re-reads of an unreadable process. */
|
|
18
|
+
sleep(ms: number): void;
|
|
19
|
+
/**
|
|
20
|
+
* Is `pid` sealed: this uid's, but closed to this process — non-dumpable (its per-process files are root's), or
|
|
21
|
+
* holding capabilities this process doesn't (the kernel denies the read)?
|
|
22
|
+
*/
|
|
23
|
+
sealed(pid: number): false | "non-dumpable" | "privileged";
|
|
24
|
+
/** Its command name (status `Name:`), for the words; null when unknown. */
|
|
25
|
+
nameOf?(pid: number): string | null;
|
|
26
|
+
/** Does `pid`'s current start match `start`? (install-lock's identity: ticks + boot, else the lstart text.) */
|
|
27
|
+
sameProcess(pid: number, start: ProcessStartRecord): boolean;
|
|
28
|
+
uid: number;
|
|
29
|
+
platform: NodeJS.Platform;
|
|
30
|
+
}
|
|
31
|
+
export interface Identity {
|
|
32
|
+
pid: number;
|
|
33
|
+
start: ProcessStartRecord;
|
|
34
|
+
}
|
|
35
|
+
export interface Exempt {
|
|
36
|
+
updater: Identity;
|
|
37
|
+
runner: Identity | null;
|
|
38
|
+
helpers: Identity[];
|
|
39
|
+
}
|
|
40
|
+
export type WritersProof = {
|
|
41
|
+
ok: true;
|
|
42
|
+
uninspectable?: Array<{
|
|
43
|
+
pid: number;
|
|
44
|
+
name: string | null;
|
|
45
|
+
why: "non-dumpable" | "privileged";
|
|
46
|
+
}>;
|
|
47
|
+
} | {
|
|
48
|
+
ok: false;
|
|
49
|
+
incomplete: true;
|
|
50
|
+
reason: string;
|
|
51
|
+
} | {
|
|
52
|
+
ok: false;
|
|
53
|
+
incomplete: false;
|
|
54
|
+
writers: Array<{
|
|
55
|
+
pid: number;
|
|
56
|
+
why: string;
|
|
57
|
+
}>;
|
|
58
|
+
reason: string;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* The kernel's subset rule for a same-uid read (ptrace_may_access): refused when the target's permitted capabilities
|
|
62
|
+
* hold a bit the reader's don't. Each argument is a `/proc/<pid>/status` text; a missing CapPrm line reads as none.
|
|
63
|
+
*/
|
|
64
|
+
export declare function capsExceed(targetStatus: string, readerStatus: string): boolean;
|
|
65
|
+
/** Re-reads of a process of this uid that can't be read, and the wait before each (≈ 100 ms in all). */
|
|
66
|
+
export declare const UNREADABLE_RETRIES = 5;
|
|
67
|
+
export declare const UNREADABLE_BACKOFF_MS = 20;
|
|
68
|
+
/** §4.4 for `home` (any spelling; compared as realpath), with the attempt's exempt set. */
|
|
69
|
+
export declare function proveWritersGone(home: string, exempt: Exempt, d: WritersDeps): WritersProof;
|
|
70
|
+
/** Linux: `/proc`. A process that exits mid-read is "gone"; anything else unreadable is null. */
|
|
71
|
+
export declare function procWritersDeps(sameProcess: WritersDeps["sameProcess"], startOf: (pid: number) => string | null): WritersDeps;
|