synabun 2.4.1 → 2.4.2
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 +30 -0
- package/README.md +1 -1
- package/browser-extension/content.js +56 -14
- package/browser-extension/engine.js +158 -8
- package/browser-extension/manifest.json +3 -1
- package/browser-extension/protocol.js +91 -6
- package/browser-extension/service-worker.js +13 -5
- package/browser-extension/tokens.css +1 -1
- package/docs/browser-extension-bridge.md +24 -4
- package/lib/data-home-files.js +4 -2
- package/lib/first-launch-protection.js +8 -2
- package/lib/update-snapshot.js +11 -4
- package/mcp-server/dist/http.d.ts.map +1 -1
- package/mcp-server/dist/http.js +25 -2
- package/mcp-server/dist/http.js.map +1 -1
- package/mcp-server/dist/index.d.ts.map +1 -1
- package/mcp-server/dist/index.js +62 -17
- package/mcp-server/dist/index.js.map +1 -1
- package/mcp-server/dist/services/browser-bench.d.ts +22 -22
- package/mcp-server/dist/services/memory-maintenance.d.ts +1 -0
- package/mcp-server/dist/services/memory-maintenance.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-maintenance.js +34 -45
- package/mcp-server/dist/services/memory-maintenance.js.map +1 -1
- package/mcp-server/dist/services/memory-migration-copy.d.ts +144 -0
- package/mcp-server/dist/services/memory-migration-copy.d.ts.map +1 -0
- package/mcp-server/dist/services/memory-migration-copy.js +467 -0
- package/mcp-server/dist/services/memory-migration-copy.js.map +1 -0
- package/mcp-server/dist/services/memory-migration-worker.d.ts +2 -0
- package/mcp-server/dist/services/memory-migration-worker.d.ts.map +1 -0
- package/mcp-server/dist/services/memory-migration-worker.js +60 -0
- package/mcp-server/dist/services/memory-migration-worker.js.map +1 -0
- package/mcp-server/dist/services/memory-retrieval.d.ts +4 -0
- package/mcp-server/dist/services/memory-retrieval.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-retrieval.js +188 -40
- package/mcp-server/dist/services/memory-retrieval.js.map +1 -1
- package/mcp-server/dist/services/memory-schema.d.ts +58 -2
- package/mcp-server/dist/services/memory-schema.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-schema.js +190 -13
- package/mcp-server/dist/services/memory-schema.js.map +1 -1
- package/mcp-server/dist/services/memory-sessions.d.ts +19 -1
- package/mcp-server/dist/services/memory-sessions.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-sessions.js +56 -20
- package/mcp-server/dist/services/memory-sessions.js.map +1 -1
- package/mcp-server/dist/services/memory-verification.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-verification.js +8 -5
- package/mcp-server/dist/services/memory-verification.js.map +1 -1
- package/mcp-server/dist/services/neural-interface.d.ts +5 -0
- package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
- package/mcp-server/dist/services/neural-interface.js +19 -2
- package/mcp-server/dist/services/neural-interface.js.map +1 -1
- package/mcp-server/dist/services/retrieval-reader-worker.d.ts +2 -0
- package/mcp-server/dist/services/retrieval-reader-worker.d.ts.map +1 -0
- package/mcp-server/dist/services/retrieval-reader-worker.js +76 -0
- package/mcp-server/dist/services/retrieval-reader-worker.js.map +1 -0
- package/mcp-server/dist/services/retrieval-reader.d.ts +38 -0
- package/mcp-server/dist/services/retrieval-reader.d.ts.map +1 -0
- package/mcp-server/dist/services/retrieval-reader.js +145 -0
- package/mcp-server/dist/services/retrieval-reader.js.map +1 -0
- package/mcp-server/dist/services/sqlite-write.d.ts +14 -0
- package/mcp-server/dist/services/sqlite-write.d.ts.map +1 -0
- package/mcp-server/dist/services/sqlite-write.js +94 -0
- package/mcp-server/dist/services/sqlite-write.js.map +1 -0
- package/mcp-server/dist/services/sqlite.d.ts +39 -0
- package/mcp-server/dist/services/sqlite.d.ts.map +1 -1
- package/mcp-server/dist/services/sqlite.js +249 -8
- package/mcp-server/dist/services/sqlite.js.map +1 -1
- package/mcp-server/dist/services/tool-catalog.d.ts +1 -1
- package/mcp-server/dist/services/typesafe-config.d.ts +7 -1
- package/mcp-server/dist/services/typesafe-config.d.ts.map +1 -1
- package/mcp-server/dist/services/typesafe-config.js +32 -10
- package/mcp-server/dist/services/typesafe-config.js.map +1 -1
- package/mcp-server/dist/services/typesafe.d.ts.map +1 -1
- package/mcp-server/dist/services/typesafe.js +9 -7
- package/mcp-server/dist/services/typesafe.js.map +1 -1
- package/mcp-server/dist/services/vector-cache.d.ts +32 -0
- package/mcp-server/dist/services/vector-cache.d.ts.map +1 -1
- package/mcp-server/dist/services/vector-cache.js +161 -8
- package/mcp-server/dist/services/vector-cache.js.map +1 -1
- package/mcp-server/dist/tools/agent-definition.d.ts +2 -2
- package/mcp-server/dist/tools/agents.d.ts +11 -7
- package/mcp-server/dist/tools/agents.d.ts.map +1 -1
- package/mcp-server/dist/tools/agents.js +27 -9
- package/mcp-server/dist/tools/agents.js.map +1 -1
- package/mcp-server/dist/tools/browser-advanced.d.ts +1 -1
- package/mcp-server/dist/tools/browser-advanced.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-advanced.js +10 -3
- package/mcp-server/dist/tools/browser-advanced.js.map +1 -1
- package/mcp-server/dist/tools/browser-extension-setup.d.ts +5 -0
- package/mcp-server/dist/tools/browser-extension-setup.d.ts.map +1 -0
- package/mcp-server/dist/tools/browser-extension-setup.js +23 -0
- package/mcp-server/dist/tools/browser-extension-setup.js.map +1 -0
- package/mcp-server/dist/tools/browser-interact.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-interact.js +6 -1
- package/mcp-server/dist/tools/browser-interact.js.map +1 -1
- package/mcp-server/dist/tools/fb-groups.d.ts +2 -2
- package/mcp-server/dist/tools/skill-tools.d.ts +4 -4
- package/mcp-server/dist/tools/tool-groups.d.ts +1 -1
- package/mcp-server/package-lock.json +2 -2
- package/mcp-server/package.json +1 -1
- package/mcp-server/src/http.ts +20 -2
- package/mcp-server/src/index.ts +59 -17
- package/mcp-server/src/services/memory-maintenance.ts +31 -28
- package/mcp-server/src/services/memory-migration-copy.ts +419 -0
- package/mcp-server/src/services/memory-migration-worker.ts +55 -0
- package/mcp-server/src/services/memory-retrieval.ts +173 -32
- package/mcp-server/src/services/memory-schema.ts +194 -12
- package/mcp-server/src/services/memory-sessions.ts +54 -21
- package/mcp-server/src/services/memory-verification.ts +7 -4
- package/mcp-server/src/services/neural-interface.ts +22 -2
- package/mcp-server/src/services/retrieval-reader-worker.ts +67 -0
- package/mcp-server/src/services/retrieval-reader.ts +131 -0
- package/mcp-server/src/services/sqlite-write.ts +60 -0
- package/mcp-server/src/services/sqlite.ts +246 -8
- package/mcp-server/src/services/typesafe-config.ts +25 -6
- package/mcp-server/src/services/typesafe.ts +9 -7
- package/mcp-server/src/services/vector-cache.ts +154 -9
- package/mcp-server/src/tools/agents.ts +26 -9
- package/mcp-server/src/tools/browser-advanced.ts +10 -3
- package/mcp-server/src/tools/browser-extension-setup.ts +30 -0
- package/mcp-server/src/tools/browser-interact.ts +5 -1
- package/neural-interface/i18n/en.json +263 -1
- package/neural-interface/i18n/pt-BR.json +264 -2
- package/neural-interface/lib/agents/split.js +32 -4
- package/neural-interface/lib/assistant-api.js +19 -8
- package/neural-interface/lib/assistant-brains/claude.js +2 -0
- package/neural-interface/lib/assistant-catalog.js +2 -2
- package/neural-interface/lib/assistant-config.js +0 -7
- package/neural-interface/lib/assistant-dispatch.js +257 -95
- package/neural-interface/lib/assistant-persona.js +16 -4
- package/neural-interface/lib/assistant-pricing.js +65 -14
- package/neural-interface/lib/assistant-router.js +131 -47
- package/neural-interface/lib/assistant-run-wait.js +45 -28
- package/neural-interface/lib/assistant-runtime.js +39 -33
- package/neural-interface/lib/backup-contents.js +158 -0
- package/neural-interface/lib/backup-crypto-io.js +330 -0
- package/neural-interface/lib/backup-crypto-worker.js +130 -0
- package/neural-interface/lib/backup-crypto.js +525 -0
- package/neural-interface/lib/backup-download.js +268 -0
- package/neural-interface/lib/backup-encryption.js +318 -0
- package/neural-interface/lib/backup-groups.js +287 -0
- package/neural-interface/lib/backup-restore-session.js +176 -0
- package/neural-interface/lib/backup-restore-stage.js +60 -0
- package/neural-interface/lib/backup-service.js +788 -233
- package/neural-interface/lib/backup-zip-reader.js +30 -18
- package/neural-interface/lib/backup-zip-writer.js +34 -10
- package/neural-interface/lib/browser-extension-adapter.js +89 -13
- package/neural-interface/lib/browser-extension-bridge.js +18 -7
- package/neural-interface/lib/claude-agent-bridge.js +1 -0
- package/neural-interface/lib/claude-session-cleanup.js +5 -1
- package/neural-interface/lib/cli-update-planner.js +105 -6
- package/neural-interface/lib/client-diagnostics.js +42 -0
- package/neural-interface/lib/confined-fs.js +7 -2
- package/neural-interface/lib/coordination/README.md +8 -2
- package/neural-interface/lib/coordination/contract.js +161 -0
- package/neural-interface/lib/coordination/database.js +999 -0
- package/neural-interface/lib/coordination/operations.js +436 -0
- package/neural-interface/lib/coordination/service.js +68 -537
- package/neural-interface/lib/coordination/storage-worker.js +101 -0
- package/neural-interface/lib/coordination/store.js +219 -1111
- package/neural-interface/lib/db.js +70 -32
- package/neural-interface/lib/health-count.js +37 -0
- package/neural-interface/lib/loop-stall.js +139 -0
- package/neural-interface/lib/maritaca/client.js +2 -2
- package/neural-interface/lib/maritaca/models.js +12 -17
- package/neural-interface/lib/maritaca/opencode.js +4 -2
- package/neural-interface/lib/memory-api.js +9 -1
- package/neural-interface/lib/memory-session-capture.js +42 -10
- package/neural-interface/lib/memory-store-gate.js +313 -0
- package/neural-interface/lib/memory-store-migrate.js +65 -0
- package/neural-interface/lib/memory-timers.js +7 -7
- package/neural-interface/lib/native-loop-providers.js +13 -16
- package/neural-interface/lib/native-loop-runtime.js +28 -7
- package/neural-interface/lib/opencode-build-preflight.js +18 -1
- package/neural-interface/lib/opencode-native-boundary.js +69 -8
- package/neural-interface/lib/opencode-provider-view.js +14 -3
- package/neural-interface/lib/opencode-v2-ws-requests.js +31 -1
- package/neural-interface/lib/opencode2-client.js +2 -1
- package/neural-interface/lib/recall-impact.js +122 -0
- package/neural-interface/lib/scratch-evidence.js +420 -0
- package/neural-interface/lib/scratch-process-guard.js +139 -0
- package/neural-interface/lib/scratch-references.js +279 -0
- package/neural-interface/lib/scratch-retention-core.js +385 -0
- package/neural-interface/lib/scratch-retention-worker.js +37 -0
- package/neural-interface/lib/scratch-retention.js +151 -0
- package/neural-interface/lib/session-cache-builder.js +31 -43
- package/neural-interface/lib/session-cache-worker.js +157 -0
- package/neural-interface/lib/session-indexer.js +28 -21
- package/neural-interface/lib/session-search-index.js +85 -0
- package/neural-interface/lib/skills/creation.js +1 -1
- package/neural-interface/lib/sqlite-integrity-worker.js +3 -1
- package/neural-interface/lib/style-guide/store.js +43 -3
- package/neural-interface/lib/system-restore.js +50 -0
- package/neural-interface/lib/teams/api.js +15 -6
- package/neural-interface/lib/teams/claims.js +67 -31
- package/neural-interface/lib/teams/index.js +7 -7
- package/neural-interface/lib/teams/integration.js +40 -40
- package/neural-interface/lib/teams/landing.js +6 -6
- package/neural-interface/lib/teams/recovery.js +24 -23
- package/neural-interface/lib/teams/scheduler.js +194 -95
- package/neural-interface/lib/teams/state.js +14 -14
- package/neural-interface/lib/teams/worktrees.js +27 -27
- package/neural-interface/lib/whatsapp/bridge.js +2 -1
- package/neural-interface/lib/worker-confinement.js +47 -2
- package/neural-interface/lib/worker-mcp-channel.js +2 -0
- package/neural-interface/lib/worker-resume.js +5 -0
- package/neural-interface/lib/worker-stop.js +86 -0
- package/neural-interface/package-lock.json +2 -2
- package/neural-interface/package.json +1 -1
- package/neural-interface/public/index.html +233 -24
- package/neural-interface/public/onboarding.html +259 -34
- package/neural-interface/public/shared/agents/studio/ax-library.js +0 -6
- package/neural-interface/public/shared/agents/studio/ax-main.js +14 -7
- package/neural-interface/public/shared/agy/agy-options.js +11 -0
- package/neural-interface/public/shared/agy/agy-panel.js +29 -10
- package/neural-interface/public/shared/agy/agy-styles.js +14 -12
- package/neural-interface/public/shared/agy/agy-tabs-logic.js +4 -1
- package/neural-interface/public/shared/api.js +1 -1
- package/neural-interface/public/shared/assistant/asst-api.js +3 -3
- package/neural-interface/public/shared/assistant/asst-brain-picker.js +13 -6
- package/neural-interface/public/shared/assistant/asst-control.js +2 -0
- package/neural-interface/public/shared/assistant/asst-motion-gate.js +78 -4
- package/neural-interface/public/shared/assistant/asst-panel.js +18 -2
- package/neural-interface/public/shared/assistant/asst-rack-styles.js +4 -0
- package/neural-interface/public/shared/assistant/asst-render.js +105 -38
- package/neural-interface/public/shared/assistant/asst-route.js +100 -21
- package/neural-interface/public/shared/assistant/asst-routes-editor.js +1 -1
- package/neural-interface/public/shared/assistant/asst-sidepanel.js +4 -2
- package/neural-interface/public/shared/assistant/asst-state.js +11 -0
- package/neural-interface/public/shared/assistant/asst-styles.js +10 -23
- package/neural-interface/public/shared/assistant/route-identity.js +2 -1
- package/neural-interface/public/shared/cdx/cdx-render.js +9 -0
- package/neural-interface/public/shared/cdx/cdx-settings.js +3 -1
- package/neural-interface/public/shared/cdx/cdx-styles.js +6 -0
- package/neural-interface/public/shared/cdx/cdx-tabs.js +29 -9
- package/neural-interface/public/shared/client-diagnostics.js +94 -0
- package/neural-interface/public/shared/cp/cp-markdown.js +7 -2
- package/neural-interface/public/shared/cp/cp-styles.js +1 -1
- package/neural-interface/public/shared/effort-i18n.js +118 -0
- package/neural-interface/public/shared/html-shell.js +4 -52
- package/neural-interface/public/shared/loading-diagnostic-entry.js +64 -0
- package/neural-interface/public/shared/memory-store-wait.js +52 -0
- package/neural-interface/public/shared/morelogin-profile-field.js +1 -1
- package/neural-interface/public/shared/mtc/mtc-logic.js +2 -1
- package/neural-interface/public/shared/mtc/mtc-panel.js +8 -1
- package/neural-interface/public/shared/mtc/mtc-styles.js +13 -12
- package/neural-interface/public/shared/ocp-v2/ocp-v2-childpanel.js +7 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-location-logic.js +109 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-modelpicker.js +8 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-panel.js +118 -6
- package/neural-interface/public/shared/ocp-v2/ocp-v2-render.js +27 -3
- package/neural-interface/public/shared/ocp-v2/ocp-v2-send.js +13 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-session-actions.js +2 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-styles.js +27 -93
- package/neural-interface/public/shared/ocp-v2/ocp-v2-variantpicker.js +17 -6
- package/neural-interface/public/shared/output-format.js +294 -0
- package/neural-interface/public/shared/provider-icons.js +6 -0
- package/neural-interface/public/shared/schedules-view.js +2 -1
- package/neural-interface/public/shared/server-presence.js +77 -0
- package/neural-interface/public/shared/settings/settings-backup-contents.js +241 -0
- package/neural-interface/public/shared/settings/settings-backup-download.js +298 -0
- package/neural-interface/public/shared/settings/settings-backup-encryption-pane.js +335 -0
- package/neural-interface/public/shared/settings/settings-backup-encryption.js +545 -0
- package/neural-interface/public/shared/settings/settings-ia.js +1 -1
- package/neural-interface/public/shared/skills/studio/sx-geometry.js +12 -3
- package/neural-interface/public/shared/skills/studio/sx-main.js +14 -7
- package/neural-interface/public/shared/studio-attention.js +6 -0
- package/neural-interface/public/shared/styles.css +341 -437
- package/neural-interface/public/shared/transcript-rows.js +28 -3
- package/neural-interface/public/shared/tray-auto-close.js +18 -5
- package/neural-interface/public/shared/ui-agents.js +1 -2
- package/neural-interface/public/shared/ui-automation-studio.js +168 -108
- package/neural-interface/public/shared/ui-claude-panel.js +42 -65
- package/neural-interface/public/shared/ui-loading.js +124 -17
- package/neural-interface/public/shared/ui-native-loop-router.js +10 -0
- package/neural-interface/public/shared/ui-navbar.js +2 -1
- package/neural-interface/public/shared/ui-output.js +533 -0
- package/neural-interface/public/shared/ui-schedules-studio.js +165 -128
- package/neural-interface/public/shared/ui-scroll-follow.js +97 -6
- package/neural-interface/public/shared/ui-sessions.js +2 -2
- package/neural-interface/public/shared/ui-settings-entry.js +18 -0
- package/neural-interface/public/shared/ui-settings.js +224 -65
- package/neural-interface/public/shared/ui-sidepanel-tray.js +3 -2
- package/neural-interface/public/shared/ui-tooltip.js +16 -0
- package/neural-interface/public/shared/ui-tutorial.js +5 -6
- package/neural-interface/public/shared/ui-worker-end.js +27 -8
- package/neural-interface/public/shared/worker-end.js +9 -4
- package/neural-interface/public/variant/2d/main.js +5 -0
- package/neural-interface/public/variant/3d/app.js +10 -0
- package/neural-interface/public/variant/3d/main.js +5 -1
- package/neural-interface/scripts/scratch-retention.mjs +20 -0
- package/neural-interface/server.js +477 -139
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/scripts/restore-data-home-from-backup.mjs +175 -8
- package/setup.js +18 -4
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "synabun",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.2",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "synabun",
|
|
9
|
-
"version": "2.4.
|
|
9
|
+
"version": "2.4.2",
|
|
10
10
|
"hasInstallScript": true,
|
|
11
11
|
"license": "Apache-2.0",
|
|
12
12
|
"dependencies": {
|
package/package.json
CHANGED
|
@@ -6,9 +6,20 @@
|
|
|
6
6
|
* The archive is fully checksum-verified before extraction. Restore happens in
|
|
7
7
|
* a sibling staging directory; the existing target is renamed (never deleted)
|
|
8
8
|
* immediately before the staged tree is atomically activated.
|
|
9
|
+
*
|
|
10
|
+
* A backup that says it leaves groups out (Settings → Backups → What to back up; `groups` in its manifest) restores
|
|
11
|
+
* only what it holds: everything of the present data home that belongs to a group it does not contain is carried
|
|
12
|
+
* into the restored one (moved out of the displaced copy), and a backup without the memories leaves the present
|
|
13
|
+
* memory database in place. A backup from before groups restores as it always did.
|
|
14
|
+
*
|
|
15
|
+
* An encrypted backup (Settings → Backups → Password protection; docs/backup-encryption.md) is opened with the
|
|
16
|
+
* password it was made with, typed at a hidden prompt or written to standard input (--password-stdin), never given
|
|
17
|
+
* as an argument or an environment variable. A wrong password stops before anything is written. The archive inside
|
|
18
|
+
* is read through the decrypting reader: no plaintext copy of it is made.
|
|
9
19
|
*/
|
|
10
20
|
|
|
11
21
|
import {
|
|
22
|
+
chmodSync,
|
|
12
23
|
existsSync,
|
|
13
24
|
mkdirSync,
|
|
14
25
|
readFileSync,
|
|
@@ -31,6 +42,10 @@ import {
|
|
|
31
42
|
readBackupManifest,
|
|
32
43
|
verifyBackupChecksums,
|
|
33
44
|
} from '../neural-interface/lib/backup-zip-reader.js';
|
|
45
|
+
import { BACKUP_ENCRYPTION_FILE, backupGroupOf, checkManifestGroups, isBackupEncryptionFile, readManifestGroups } from '../neural-interface/lib/backup-groups.js';
|
|
46
|
+
import { BackupEncryptionError, isEncryptedBackupFile } from '../neural-interface/lib/backup-crypto.js';
|
|
47
|
+
import { openEncryptedBackupSource } from '../neural-interface/lib/backup-crypto-io.js';
|
|
48
|
+
import { makePrivateRestoreStage, restoreStagePath, sweepRestoreStages } from '../neural-interface/lib/backup-restore-stage.js';
|
|
34
49
|
|
|
35
50
|
function pathIsInside(candidate, parent) {
|
|
36
51
|
const rel = relative(resolve(parent), resolve(candidate));
|
|
@@ -41,9 +56,61 @@ function timestamp(date) {
|
|
|
41
56
|
return date.toISOString().replace(/[:.]/g, '-');
|
|
42
57
|
}
|
|
43
58
|
|
|
59
|
+
/**
|
|
60
|
+
* The password of an encrypted backup, from the person at the terminal: typed without echo, or the first line of
|
|
61
|
+
* standard input when `fromStdin` (a password manager's output piped in). Never an argument, never the environment.
|
|
62
|
+
*/
|
|
63
|
+
export async function readBackupPassword({ fromStdin = false, input = process.stdin, output = process.stderr, prompt = 'Backup password: ' } = {}) {
|
|
64
|
+
if (fromStdin) {
|
|
65
|
+
let text = '';
|
|
66
|
+
input.setEncoding('utf8');
|
|
67
|
+
for await (const chunk of input) {
|
|
68
|
+
text += chunk;
|
|
69
|
+
if (text.length > 8192) break;
|
|
70
|
+
}
|
|
71
|
+
return text.split(/\r?\n/)[0];
|
|
72
|
+
}
|
|
73
|
+
if (!input.isTTY || typeof input.setRawMode !== 'function') {
|
|
74
|
+
throw new BackupEncryptionError('BACKUP_PASSWORD_REQUIRED', 'This backup is encrypted. Run the command in a terminal to type its password, or add --password-stdin and write the password to standard input.', { status: 401 });
|
|
75
|
+
}
|
|
76
|
+
output.write(prompt);
|
|
77
|
+
return new Promise((resolvePassword, reject) => {
|
|
78
|
+
let typed = '';
|
|
79
|
+
const finish = (settle, value) => {
|
|
80
|
+
input.off('data', onData);
|
|
81
|
+
input.setRawMode(false);
|
|
82
|
+
input.pause();
|
|
83
|
+
output.write('\n');
|
|
84
|
+
settle(value);
|
|
85
|
+
};
|
|
86
|
+
function onData(chunk) {
|
|
87
|
+
for (const char of String(chunk)) {
|
|
88
|
+
if (char === '\r' || char === '\n' || char === '\u0004') { finish(resolvePassword, typed); return; }
|
|
89
|
+
if (char === '\u0003') { finish(reject, new Error('Cancelled.')); return; }
|
|
90
|
+
if (char === '\u007f' || char === '\b') typed = typed.slice(0, -1);
|
|
91
|
+
else typed += char;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
input.setRawMode(true);
|
|
95
|
+
input.setEncoding('utf8');
|
|
96
|
+
input.resume();
|
|
97
|
+
input.on('data', onData);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** The archive opened as a ZIP: the file itself, or the ZIP inside an encrypted backup once its password opened it. */
|
|
102
|
+
async function openArchive(backupPath, { password, readPassword }) {
|
|
103
|
+
if (!(await isEncryptedBackupFile(backupPath))) return openZipArchive(backupPath);
|
|
104
|
+
const given = password ?? (typeof readPassword === 'function' ? await readPassword() : null);
|
|
105
|
+
if (given == null) throw new BackupEncryptionError('BACKUP_PASSWORD_REQUIRED', 'This backup is encrypted: its password is needed to restore it.', { status: 401 });
|
|
106
|
+
// This command has no server thread to keep free: it decrypts on its own.
|
|
107
|
+
const source = await openEncryptedBackupSource(backupPath, { password: given, inline: true });
|
|
108
|
+
return openZipArchive(backupPath, { source });
|
|
109
|
+
}
|
|
110
|
+
|
|
44
111
|
/** Open the archive and stream-verify every checksum before anything is extracted. */
|
|
45
|
-
async function parseArchive(backupPath) {
|
|
46
|
-
const zip = await
|
|
112
|
+
async function parseArchive(backupPath, keys = {}) {
|
|
113
|
+
const zip = await openArchive(backupPath, keys);
|
|
47
114
|
try {
|
|
48
115
|
const found = await readBackupManifest(zip);
|
|
49
116
|
if (!found || !found.prefix) throw new Error('Invalid backup: manifest.json is missing');
|
|
@@ -51,7 +118,12 @@ async function parseArchive(backupPath) {
|
|
|
51
118
|
if (![2, 3].includes(manifest.version)) {
|
|
52
119
|
throw new Error(`Unsupported backup version: ${manifest.version}. Expected v2 or v3.`);
|
|
53
120
|
}
|
|
121
|
+
// An archive that records its groups holds exactly those, or nothing of it is restored.
|
|
122
|
+
const problems = checkManifestGroups(manifest, zip.entries.filter(entry => !entry.isDirectory).map(entry => entry.name), prefix);
|
|
123
|
+
if (problems.length) throw new Error(`Invalid backup: ${problems[0]}`);
|
|
54
124
|
await verifyBackupChecksums(zip, { prefix, manifest, label: 'Invalid backup' });
|
|
125
|
+
// An encrypted backup: every part of the file has now passed its check, the ones no entry reaches too.
|
|
126
|
+
if (zip.encrypted) await zip.source.authenticateRest();
|
|
55
127
|
return { zip, entries: zip.entries, manifest, prefix };
|
|
56
128
|
} catch (error) {
|
|
57
129
|
await zip.close().catch(() => {});
|
|
@@ -63,6 +135,8 @@ function restoredRelativePath(entryName, prefix) {
|
|
|
63
135
|
const rel = entryName.slice(`${prefix}/`.length);
|
|
64
136
|
if (rel === 'env.bak') return '.env';
|
|
65
137
|
if (rel === 'database/memory.db') return 'mcp-data/memory.db';
|
|
138
|
+
// The backup-encryption key file is the installation's own: no archive brings one (backup-groups.js).
|
|
139
|
+
if (isBackupEncryptionFile(basename(rel))) return null;
|
|
66
140
|
if (rel.startsWith('data/') || rel.startsWith('mcp-data/')) return rel;
|
|
67
141
|
return null;
|
|
68
142
|
}
|
|
@@ -129,8 +203,58 @@ function findInvalidJson(stageRoot) {
|
|
|
129
203
|
return invalid;
|
|
130
204
|
}
|
|
131
205
|
|
|
132
|
-
|
|
206
|
+
/**
|
|
207
|
+
* What of the present data home a backup that leaves groups out does not replace: [{ rel, group }] with `rel` the
|
|
208
|
+
* path inside the data home (a top-level entry of data/ or mcp-data/, the memory database with its WAL files, the
|
|
209
|
+
* .env). Empty for a backup that holds every group, and for one from before groups.
|
|
210
|
+
*/
|
|
211
|
+
export function entriesToKeep(targetRoot, manifest) {
|
|
212
|
+
const contents = readManifestGroups(manifest);
|
|
213
|
+
if (!contents.recorded || !contents.excluded.length || !existsSync(targetRoot)) return [];
|
|
214
|
+
const left = new Set(contents.excluded);
|
|
215
|
+
const keep = [];
|
|
216
|
+
if (left.has('settings') && existsSync(resolve(targetRoot, '.env'))) keep.push({ rel: '.env', group: 'settings' });
|
|
217
|
+
for (const dir of ['data', 'mcp-data']) {
|
|
218
|
+
const root = resolve(targetRoot, dir);
|
|
219
|
+
let names = [];
|
|
220
|
+
try { names = readdirSync(root).sort(); } catch { /* no such folder here */ }
|
|
221
|
+
for (const name of names) {
|
|
222
|
+
let isDir = false;
|
|
223
|
+
try { isDir = statSync(resolve(root, name)).isDirectory(); } catch { continue; }
|
|
224
|
+
// The memory database lives in mcp-data/ and is archived as database/memory.db, with its WAL beside it.
|
|
225
|
+
const group = dir === 'mcp-data' && /^memory\.db(?:-wal|-shm|-journal)?$/i.test(name)
|
|
226
|
+
? 'memories'
|
|
227
|
+
: backupGroupOf(`${dir}/${name}${isDir ? '/.' : ''}`);
|
|
228
|
+
if (group && left.has(group)) keep.push({ rel: `${dir}/${name}`, group });
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return keep;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** Move what the backup does not contain out of the displaced data home into the restored one. Never overwrites. */
|
|
235
|
+
function carryOver(displacedRoot, targetRoot, keep) {
|
|
236
|
+
const kept = [];
|
|
237
|
+
const notKept = [];
|
|
238
|
+
for (const { rel, group } of keep) {
|
|
239
|
+
const from = resolve(displacedRoot, rel);
|
|
240
|
+
const to = resolve(targetRoot, rel);
|
|
241
|
+
try {
|
|
242
|
+
if (!existsSync(from)) continue;
|
|
243
|
+
if (existsSync(to)) { notKept.push({ path: rel, group, error: 'the backup holds a file of that name' }); continue; }
|
|
244
|
+
mkdirSync(dirname(to), { recursive: true });
|
|
245
|
+
renameSync(from, to);
|
|
246
|
+
kept.push(rel);
|
|
247
|
+
} catch (error) {
|
|
248
|
+
notKept.push({ path: rel, group, error: error.message });
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return { kept, notKept };
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function validateStage(stageRoot, { requireDatabase = true } = {}) {
|
|
133
255
|
const dbPath = resolve(stageRoot, 'mcp-data', 'memory.db');
|
|
256
|
+
// A backup without the memories: the present database stays (entriesToKeep), there is none to check here.
|
|
257
|
+
if (!existsSync(dbPath) && !requireDatabase) return null;
|
|
134
258
|
if (!existsSync(dbPath)) throw new Error('Backup does not contain database/memory.db');
|
|
135
259
|
let database;
|
|
136
260
|
try {
|
|
@@ -152,6 +276,9 @@ export async function restoreDataHomeFromBackup({
|
|
|
152
276
|
targetRoot,
|
|
153
277
|
legacyRoot = null,
|
|
154
278
|
apply = false,
|
|
279
|
+
// An encrypted backup: its password, or a function that asks for it (called only when the backup is encrypted).
|
|
280
|
+
password = null,
|
|
281
|
+
readPassword = null,
|
|
155
282
|
now = () => new Date(),
|
|
156
283
|
} = {}) {
|
|
157
284
|
if (!backupPath || !targetRoot) throw new Error('backupPath and targetRoot are required');
|
|
@@ -159,20 +286,47 @@ export async function restoreDataHomeFromBackup({
|
|
|
159
286
|
const target = resolve(targetRoot);
|
|
160
287
|
if (!existsSync(backup)) throw new Error(`Backup not found: ${backup}`);
|
|
161
288
|
|
|
162
|
-
|
|
289
|
+
// A wrong password, a damaged file or a changed one stops here: nothing has been created or moved yet.
|
|
290
|
+
const parsed = await parseArchive(backup, { password, readPassword });
|
|
163
291
|
const createdAt = now();
|
|
164
292
|
const targetName = basename(target).replace(/^\.+/, '') || 'synabun';
|
|
165
293
|
const parent = dirname(target);
|
|
166
|
-
|
|
294
|
+
// What a killed restore left: decrypted files, in a folder nobody will come back to.
|
|
295
|
+
try { sweepRestoreStages(target); } catch { /* a parent folder that cannot be listed: the mkdir below says so */ }
|
|
296
|
+
const stage = restoreStagePath(target);
|
|
167
297
|
const displacedTarget = resolve(parent, `.${targetName}.pre-restore-${timestamp(createdAt)}`);
|
|
168
298
|
let activated = false;
|
|
169
299
|
let targetMoved = false;
|
|
170
300
|
try {
|
|
171
301
|
mkdirSync(parent, { recursive: true });
|
|
172
|
-
|
|
302
|
+
// Private (0700): what is extracted here is the backup in plaintext, the .env and the account files included.
|
|
303
|
+
makePrivateRestoreStage(stage);
|
|
173
304
|
const restoredFiles = await writeSelectedEntries({ ...parsed, stageRoot: stage });
|
|
305
|
+
const contents = readManifestGroups(parsed.manifest);
|
|
306
|
+
const keep = entriesToKeep(target, parsed.manifest);
|
|
307
|
+
// A backup without the settings keeps the present .env: its keys are carried into the stage before the four
|
|
308
|
+
// path values are set, so they are never replaced by an empty file.
|
|
309
|
+
const keepsEnv = keep.some(item => item.rel === '.env');
|
|
310
|
+
if (keepsEnv && !existsSync(resolve(stage, '.env'))) writeFileSync(resolve(stage, '.env'), readFileSync(resolve(target, '.env')));
|
|
174
311
|
normalizeEnv(stage, target);
|
|
175
|
-
|
|
312
|
+
// Backup encryption is the installation's own setting, in no archive: the present key file is carried into the
|
|
313
|
+
// restored data home, so a restore never turns encryption off. Where there is none and this backup is encrypted,
|
|
314
|
+
// its key is kept (the password that just opened it), so the backups made after this restore are encrypted too.
|
|
315
|
+
const encryption = { encrypted: parsed.zip.encrypted === true, keyId: parsed.zip.source?.keyId || null, key: null };
|
|
316
|
+
const presentKey = resolve(target, 'data', BACKUP_ENCRYPTION_FILE);
|
|
317
|
+
const stagedKey = resolve(stage, 'data', BACKUP_ENCRYPTION_FILE);
|
|
318
|
+
if (existsSync(presentKey)) {
|
|
319
|
+
mkdirSync(dirname(stagedKey), { recursive: true });
|
|
320
|
+
writeFileSync(stagedKey, readFileSync(presentKey), { mode: 0o600 });
|
|
321
|
+
encryption.key = 'kept';
|
|
322
|
+
} else if (encryption.encrypted) {
|
|
323
|
+
const stamp = createdAt.toISOString();
|
|
324
|
+
mkdirSync(dirname(stagedKey), { recursive: true });
|
|
325
|
+
writeFileSync(stagedKey, `${JSON.stringify({ version: 1, recipient: parsed.zip.source.recipientForAdoption(), createdAt: stamp, changedAt: stamp }, null, 2)}\n`, { mode: 0o600 });
|
|
326
|
+
encryption.key = 'adopted';
|
|
327
|
+
}
|
|
328
|
+
if (encryption.key && process.platform !== 'win32') chmodSync(stagedKey, 0o600);
|
|
329
|
+
const database = validateStage(stage, { requireDatabase: !contents.recorded || contents.included.includes('memories') });
|
|
176
330
|
const invalidJson = findInvalidJson(stage);
|
|
177
331
|
const existingManifest = existsSync(resolve(target, '.synabun-data-home.json'))
|
|
178
332
|
? JSON.parse(readFileSync(resolve(target, '.synabun-data-home.json'), 'utf-8'))
|
|
@@ -199,16 +353,28 @@ export async function restoreDataHomeFromBackup({
|
|
|
199
353
|
database,
|
|
200
354
|
invalidJson,
|
|
201
355
|
restoredFiles,
|
|
356
|
+
// Whether the backup was encrypted, and what became of this installation's backup encryption: 'kept' (its own
|
|
357
|
+
// key file), 'adopted' (none here: the backup's key, same password), or null (no encryption either side).
|
|
358
|
+
encryption,
|
|
359
|
+
// What the backup holds by group, and what of the present data home it therefore leaves in place.
|
|
360
|
+
contents,
|
|
361
|
+
keeps: keep.filter(item => item.rel !== '.env' || !keepsEnv).map(item => item.rel).concat(keepsEnv ? ['.env'] : []),
|
|
202
362
|
};
|
|
203
363
|
if (!apply) return result;
|
|
204
364
|
|
|
365
|
+
// The restored folder keeps the mode the data home had; only its time as a stage is private.
|
|
366
|
+
const targetMode = existsSync(target) ? statSync(target).mode & 0o777 : 0o777 & ~process.umask();
|
|
205
367
|
if (existsSync(target)) {
|
|
206
368
|
renameSync(target, displacedTarget);
|
|
207
369
|
targetMoved = true;
|
|
208
370
|
}
|
|
209
371
|
renameSync(stage, target);
|
|
210
372
|
activated = true;
|
|
211
|
-
|
|
373
|
+
if (process.platform !== 'win32') chmodSync(target, targetMode);
|
|
374
|
+
// The groups the backup does not contain: moved back from the displaced copy. One that cannot be moved stays
|
|
375
|
+
// there, untouched, and is named (`notKept`): nothing is ever deleted.
|
|
376
|
+
const carried = targetMoved ? carryOver(displacedTarget, target, keep.filter(item => item.rel !== '.env')) : { kept: [], notKept: [] };
|
|
377
|
+
return { ...result, applied: true, kept: [...(keepsEnv ? ['.env'] : []), ...carried.kept], notKept: carried.notKept };
|
|
212
378
|
} catch (error) {
|
|
213
379
|
if (targetMoved && !existsSync(target) && existsSync(displacedTarget)) renameSync(displacedTarget, target);
|
|
214
380
|
throw error;
|
|
@@ -230,6 +396,7 @@ if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.ur
|
|
|
230
396
|
targetRoot: option('--target'),
|
|
231
397
|
legacyRoot: option('--legacy-root'),
|
|
232
398
|
apply: process.argv.includes('--apply'),
|
|
399
|
+
readPassword: () => readBackupPassword({ fromStdin: process.argv.includes('--password-stdin') }),
|
|
233
400
|
});
|
|
234
401
|
console.log(JSON.stringify(result, null, 2));
|
|
235
402
|
} catch (error) {
|
package/setup.js
CHANGED
|
@@ -539,6 +539,8 @@ function usage(version) {
|
|
|
539
539
|
' copy an older install\'s data into the data folder (a dry run without --apply)',
|
|
540
540
|
' synabun restore-backup --from <backup.zip> [--apply]',
|
|
541
541
|
' check a backup; --apply restores it',
|
|
542
|
+
' (an encrypted backup asks for its password;',
|
|
543
|
+
' --password-stdin reads it from standard input)',
|
|
542
544
|
' synabun version the installed version',
|
|
543
545
|
' synabun help this list',
|
|
544
546
|
'',
|
|
@@ -583,20 +585,32 @@ async function main() {
|
|
|
583
585
|
}
|
|
584
586
|
if (cmd === 'restore-backup') {
|
|
585
587
|
const backupPath = readOption('--from') || readOption('--backup');
|
|
586
|
-
if (!backupPath) throw new Error('Usage: synabun restore-backup --from <backup.zip> [--apply]');
|
|
587
|
-
const { restoreDataHomeFromBackup } = await import('./scripts/restore-data-home-from-backup.mjs');
|
|
588
|
+
if (!backupPath) throw new Error('Usage: synabun restore-backup --from <backup.zip> [--apply] [--password-stdin]');
|
|
589
|
+
const { restoreDataHomeFromBackup, readBackupPassword } = await import('./scripts/restore-data-home-from-backup.mjs');
|
|
588
590
|
const result = await restoreDataHomeFromBackup({
|
|
589
591
|
backupPath,
|
|
590
592
|
targetRoot: DATA_HOME,
|
|
591
593
|
legacyRoot: PACKAGE_ROOT,
|
|
592
594
|
apply: process.argv.includes('--apply'),
|
|
595
|
+
// An encrypted backup: its password is typed at a hidden prompt, or read from standard input with
|
|
596
|
+
// --password-stdin. Never an argument or an environment variable (both show in process lists and histories).
|
|
597
|
+
readPassword: () => readBackupPassword({ fromStdin: process.argv.includes('--password-stdin') }),
|
|
593
598
|
});
|
|
599
|
+
if (result.encryption?.encrypted) info('This backup is encrypted; its password opened it.');
|
|
600
|
+
if (result.encryption?.key === 'adopted') info('Backup encryption was not set up here: this backup\'s key is kept, so new backups are encrypted with the same password.');
|
|
594
601
|
for (const item of result.invalidJson || []) warn(`Restored as backed up, but not valid JSON: ${item.path} (${item.error})`);
|
|
602
|
+
// A backup that leaves groups out (Settings → Backups → What to back up) restores only what it holds: say what
|
|
603
|
+
// it holds, and what of the present data it therefore leaves in place.
|
|
604
|
+
const partial = result.contents?.recorded && result.contents.excluded.length;
|
|
605
|
+
if (partial) info(`This backup contains: ${result.contents.included.join(', ')}. It does not contain: ${result.contents.excluded.join(', ')}; that data stays as it is.`);
|
|
595
606
|
if (!result.applied) {
|
|
596
|
-
info(
|
|
607
|
+
info(result.database
|
|
608
|
+
? `Verified backup: ${result.database.memories} memories, SQLite ${result.database.integrity}`
|
|
609
|
+
: 'Verified backup: it does not contain the memories; the present memory database stays.');
|
|
597
610
|
info('Dry run only. Re-run with --apply after stopping SynaBun MCP/server processes.');
|
|
598
611
|
} else {
|
|
599
|
-
ok(`Restored ${result.database.memories} memories to ${result.targetRoot}`);
|
|
612
|
+
ok(result.database ? `Restored ${result.database.memories} memories to ${result.targetRoot}` : `Restored to ${result.targetRoot}; the memories were not in this backup and were left as they are`);
|
|
613
|
+
for (const item of result.notKept || []) warn(`Could not be carried over and is still in ${result.displacedTarget}: ${item.path} (${item.error})`);
|
|
600
614
|
if (result.displacedTarget) info(`Previous external state preserved at ${result.displacedTarget}`);
|
|
601
615
|
}
|
|
602
616
|
process.exit(0);
|