shadow-claw 1.23.3 → 1.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -5
- package/bin/assert-version-bump.mjs +60 -38
- package/bin/assert-version-bump.test.mjs +74 -11
- package/bin/cli.mjs +166 -0
- package/bin/cli.test.mjs +60 -0
- package/bin/commands/backup.mjs +70 -0
- package/bin/commands/clients.mjs +41 -0
- package/bin/commands/peer-id.mjs +76 -0
- package/bin/commands/peer-id.test.mjs +104 -0
- package/bin/commands/send.mjs +51 -0
- package/bin/commands/tasks.mjs +59 -0
- package/bin/commands/webrtc-listen.mjs +254 -0
- package/bin/prerender-dsd-shell/prerender-dsd-shell.test.mjs +46 -0
- package/bin/rolldown.config.test.mjs +401 -8
- package/bin/utils/control-client.mjs +243 -0
- package/bin/utils/control-client.test.mjs +83 -0
- package/bin/utils/ulid.mjs +45 -0
- package/bin/utils/webrtc-control-client.mjs +699 -0
- package/bin/utils/webrtc-control-client.test.mjs +318 -0
- package/dist/electron/main.cjs +1 -1
- package/dist/public/AGENTS.md +5 -3
- package/dist/public/README.md +42 -5
- package/dist/public/agent.worker.js +6 -6
- package/dist/public/{app-routes-B0ePT49v.js → app-routes-Bs-riIvr.js} +1 -1
- package/dist/public/backup-controller-C_s9in2t.js +1 -0
- package/dist/public/components/settings/shadow-claw-control-plane/shadow-claw-control-plane.css +1 -0
- package/dist/public/components/settings/shadow-claw-control-plane/shadow-claw-control-plane.html +1 -0
- package/dist/public/components/settings/shadow-claw-storage/shadow-claw-storage.html +1 -1
- package/dist/public/components/settings/shadow-claw-task-server/shadow-claw-task-server.css +1 -1
- package/dist/public/components/settings/shadow-claw-task-server/shadow-claw-task-server.html +1 -1
- package/dist/public/components/shadow-claw-files/shadow-claw-files.css +1 -1
- package/dist/public/components/shadow-claw-files/shadow-claw-files.html +1 -1
- package/dist/public/components/shadow-claw-settings/shadow-claw-settings.html +1 -1
- package/dist/public/config-CrHchneq.js +1 -0
- package/dist/public/{configurePeerJs-B7kNU8AQ.js → configurePeerJs-CxpZeDJJ.js} +1 -1
- package/dist/public/{connections-xd_66YVU.js → connections-DvbgdkaB.js} +1 -1
- package/dist/public/{custom-element-security-CZ92anB8.js → custom-element-security-NCqQ5lmC.js} +1 -1
- package/dist/public/docs/README.md +3 -1
- package/dist/public/docs/architecture/overview.md +12 -12
- package/dist/public/docs/architecture/storage.md +5 -2
- package/dist/public/docs/decisions/bundled-typescript-architecture.md +1 -1
- package/dist/public/docs/decisions/indexeddb-and-opfs-storage.md +6 -3
- package/dist/public/docs/decisions/native-web-components-and-signals.md +1 -1
- package/dist/public/docs/example/article/index.html +2 -2
- package/dist/public/docs/guides/configuring-messaging-channels.md +41 -6
- package/dist/public/docs/guides/server-development-configuration.md +24 -0
- package/dist/public/docs/publishing/index.html +19 -76
- package/dist/public/docs/skill-creator/index.html +2 -2
- package/dist/public/docs/subsystems/backup.md +56 -0
- package/dist/public/docs/subsystems/cli.md +124 -0
- package/dist/public/docs/subsystems/control-plane.md +158 -0
- package/dist/public/docs/subsystems/notifications.md +54 -2
- package/dist/public/docs/subsystems/reactive-ui.md +1 -0
- package/dist/public/downloadGroupFile-By0GR6eV.js +1 -0
- package/dist/public/e2e/README.md +5 -1
- package/dist/public/{e2e-bridge-DkS5xFGX.js → e2e-bridge-IGWsRl4i.js} +1 -1
- package/dist/public/file-viewer-D0eflgt6.js +1 -0
- package/dist/public/files/main/~/docs/publishing-to-github-pages.md +17 -82
- package/dist/public/getAllTasks-vpBlgGsc.js +1 -0
- package/dist/public/getGroupDir-P1h9wl6S.js +1 -0
- package/dist/public/{git-BkjrsRXX.js → git-7Vq_SJSp.js} +2 -2
- package/dist/public/{iframe-sanitizer-L6Jyu__Z.js → iframe-sanitizer-y2Z1pPwY.js} +1 -1
- package/dist/public/index.html +2 -2
- package/dist/public/index.js +1 -1
- package/dist/public/{initChatSplitResize-BslPXAXS.js → initChatSplitResize-CzV2E7Ul.js} +1 -1
- package/dist/public/initControlPlane-C9jpnWev.js +1 -0
- package/dist/public/llms.txt +1 -1
- package/dist/public/main/index.html +2 -2
- package/dist/public/main/memory/index.html +2 -2
- package/dist/public/{markdown-6MBrIo-S.js → markdown-BnpKxSxl.js} +1 -1
- package/dist/public/mcp-reconnect-9emsqGRe.js +1 -0
- package/dist/public/{memoryStorage-CjGseKI1.js → memoryStorage-C0KvLNUp.js} +1 -1
- package/dist/public/{orchestrator-B9KmIj8Q.js → orchestrator-3h9xxHUm.js} +676 -676
- package/dist/public/orchestrator-nJj59RqD.js +15 -0
- package/dist/public/pages/main/~/docs/publishing-to-github-pages.md +17 -82
- package/dist/public/{peerjs-Dv8JNm7v.js → peerjs-BP4laMXj.js} +1 -1
- package/dist/public/{push-client-Dqq06wbB.js → push-client-CrjEXK3U.js} +1 -1
- package/dist/public/service-worker/fetch-proxy.js +1 -1
- package/dist/public/service-worker/push-handler.js +1 -1
- package/dist/public/service-worker.js +1 -1
- package/dist/public/{shadow-claw-Bd1rfuVC.js → shadow-claw-CbwETBWf.js} +2 -2
- package/dist/public/{shadow-claw-accounts-DL2l3oM0.js → shadow-claw-accounts-B4sBTQEj.js} +3 -3
- package/dist/public/{shadow-claw-channels-BGXDsQ38.js → shadow-claw-channels-BDWG5Qa3.js} +1 -1
- package/dist/public/{shadow-claw-chat-NXg6zz_l.js → shadow-claw-chat-Crv0DTCY.js} +6 -6
- package/dist/public/shadow-claw-control-plane-CX1IGbh9.js +199 -0
- package/dist/public/{shadow-claw-conversations-C8eqGpP9.js → shadow-claw-conversations-_9qAaRXk.js} +1 -1
- package/dist/public/shadow-claw-dialog-BrOwAOdk.js +1 -0
- package/dist/public/shadow-claw-file-viewer-Blf6yGVD.js +577 -0
- package/dist/public/shadow-claw-files-CYySBDCl.js +840 -0
- package/dist/public/{shadow-claw-git-C0ntz7aX.js → shadow-claw-git-v8S0JjuR.js} +3 -3
- package/dist/public/{shadow-claw-integrations-DCXV2r69.js → shadow-claw-integrations-D7ufpwhX.js} +1 -1
- package/dist/public/{shadow-claw-llm-CudgFQsS.js → shadow-claw-llm-GWgoVfhI.js} +2 -2
- package/dist/public/{shadow-claw-mcp-remote-B8RkpX28.js → shadow-claw-mcp-remote-kY4LMFNN.js} +1 -1
- package/dist/public/{shadow-claw-networking-BLiRsrsK.js → shadow-claw-networking-qHbP95z9.js} +1 -1
- package/dist/public/{shadow-claw-notifications-CQhQcjtL.js → shadow-claw-notifications-YyHOK2Fr.js} +1 -1
- package/dist/public/{shadow-claw-page-header-NeRD0tKU.js → shadow-claw-page-header-DMKbkv3s.js} +1 -1
- package/dist/public/{shadow-claw-pages-DCHnFh6r.js → shadow-claw-pages-DFZHhzFZ.js} +3 -3
- package/dist/public/{shadow-claw-settings-VAfjKFQg.js → shadow-claw-settings-DhxrKIfA.js} +10 -3
- package/dist/public/shadow-claw-storage-BFynbP0j.js +219 -0
- package/dist/public/{shadow-claw-task-server-Dk33N_1G.js → shadow-claw-task-server-3BIeb5oZ.js} +25 -4
- package/dist/public/{shadow-claw-tasks-xA1VfmWN.js → shadow-claw-tasks-Caxc9atL.js} +4 -4
- package/dist/public/{shadow-claw-terminal-Du2r0ciq.js → shadow-claw-terminal-Beb5qF-U.js} +1 -1
- package/dist/public/{shadow-claw-tools-CZj4rq7l.js → shadow-claw-tools-BfJx3A9W.js} +2 -2
- package/dist/public/{shadow-claw-webvm-JYUkWICG.js → shadow-claw-webvm-BCS8ykeP.js} +1 -1
- package/dist/public/static-main/~/docs/publishing-to-github-pages.md +17 -82
- package/dist/public/static-main-manifest.json +1 -1
- package/dist/public/{syncWebMcpRegistration-DfpvASnh.js → syncWebMcpRegistration-B_M2fCjH.js} +1 -1
- package/dist/server.js +286 -189
- package/package.json +2 -1
- package/src/__mocks__/jszip.cjs +15 -5
- package/src/components/settings/shadow-claw-accounts/shadow-claw-accounts.test.ts +35 -0
- package/src/components/settings/shadow-claw-control-plane/shadow-claw-control-plane.css +117 -0
- package/src/components/settings/shadow-claw-control-plane/shadow-claw-control-plane.html +81 -0
- package/src/components/settings/shadow-claw-control-plane/shadow-claw-control-plane.test.ts +127 -0
- package/src/components/settings/shadow-claw-control-plane/shadow-claw-control-plane.ts +292 -0
- package/src/components/settings/shadow-claw-git/shadow-claw-git.test.ts +72 -0
- package/src/components/settings/shadow-claw-integrations/connection-test-auth.test.ts +20 -30
- package/src/components/settings/shadow-claw-integrations/shadow-claw-integrations.test.ts +116 -0
- package/src/components/settings/shadow-claw-llm/model-ranking.test.ts +143 -51
- package/src/components/settings/shadow-claw-llm/shadow-claw-llm.test.ts +307 -4
- package/src/components/settings/shadow-claw-llm/shadow-claw-llm.ts +8 -8
- package/src/components/settings/shadow-claw-mcp-remote/shadow-claw-mcp-remote.test.ts +31 -0
- package/src/components/settings/shadow-claw-peerjs/shadow-claw-peerjs.test.ts +186 -0
- package/src/components/settings/shadow-claw-storage/shadow-claw-storage.html +17 -0
- package/src/components/settings/shadow-claw-storage/shadow-claw-storage.test.ts +120 -0
- package/src/components/settings/shadow-claw-storage/shadow-claw-storage.ts +56 -0
- package/src/components/settings/shadow-claw-task-server/shadow-claw-task-server.css +23 -2
- package/src/components/settings/shadow-claw-task-server/shadow-claw-task-server.html +1 -1
- package/src/components/settings/shadow-claw-task-server/shadow-claw-task-server.test.ts +19 -0
- package/src/components/settings/shadow-claw-task-server/shadow-claw-task-server.ts +2 -1
- package/src/components/shadow-claw/utils/initChatSplitResize.test.ts +180 -13
- package/src/components/shadow-claw/utils/setupEffects.test.ts +39 -0
- package/src/components/shadow-claw-a2ui/catalog/basic/shared.test.ts +117 -0
- package/src/components/shadow-claw-a2ui/shadow-claw-a2ui.test.ts +1159 -1
- package/src/components/shadow-claw-chat/shadow-claw-chat.test.ts +1523 -19
- package/src/components/shadow-claw-chat/utils/escapeHtml.test.ts +13 -0
- package/src/components/shadow-claw-chat/utils/getPeerChatDisplayStatus.test.ts +20 -0
- package/src/components/shadow-claw-conversations/shadow-claw-conversations.test.ts +494 -0
- package/src/components/shadow-claw-dialog/shadow-claw-dialog.ts +13 -2
- package/src/components/shadow-claw-file-viewer/shadow-claw-file-viewer.test.ts +378 -0
- package/src/components/shadow-claw-file-viewer/shadow-claw-file-viewer.ts +11 -9
- package/src/components/shadow-claw-files/shadow-claw-files.css +41 -17
- package/src/components/shadow-claw-files/shadow-claw-files.html +35 -0
- package/src/components/shadow-claw-files/shadow-claw-files.test.ts +627 -1
- package/src/components/shadow-claw-files/shadow-claw-files.ts +170 -6
- package/src/components/shadow-claw-pages/utils/resolveWorkspaceLinkPath.test.ts +31 -0
- package/src/components/shadow-claw-pages/utils/resolveWorkspaceLinkPath.ts +2 -1
- package/src/components/shadow-claw-pages/utils/rewriteWorkspacePreviewHtml.test.ts +15 -0
- package/src/components/shadow-claw-pdf-viewer/utils/installGetOrInsertComputedPolyfill.test.ts +65 -0
- package/src/components/shadow-claw-settings/shadow-claw-settings.html +7 -0
- package/src/components/shadow-claw-settings/shadow-claw-settings.test.ts +221 -0
- package/src/components/shadow-claw-settings/shadow-claw-settings.ts +2 -0
- package/src/components/shadow-claw-tasks/shadow-claw-tasks.test.ts +407 -0
- package/src/components/shadow-claw-terminal/utils/consumeEscapeSequence.test.ts +58 -0
- package/src/components/shadow-claw-tools/shadow-claw-tools.test.ts +80 -0
- package/src/config/config.test.ts +9 -0
- package/src/config/config.ts +15 -0
- package/src/core/app-routes.test.ts +56 -0
- package/src/core/app-routes.ts +8 -1
- package/src/core/backup-controller.test.ts +101 -0
- package/src/core/backup-controller.ts +137 -0
- package/src/core/control-plane-client.test.ts +408 -0
- package/src/core/control-plane-client.ts +425 -0
- package/src/core/orchestrator/orchestrator.ts +4 -0
- package/src/core/orchestrator/utils/compactContext.test.ts +78 -0
- package/src/core/orchestrator/utils/operations/channel.test.ts +254 -9
- package/src/core/orchestrator/utils/operations/provider.test.ts +326 -34
- package/src/core/orchestrator/utils/operations/vm.test.ts +114 -2
- package/src/core/orchestrator/utils/syncProxyConfigToServiceWorker.test.ts +60 -0
- package/src/core/utils/initControlPlane.test.ts +276 -0
- package/src/core/utils/initControlPlane.ts +437 -0
- package/src/core/utils/initializeApp.ts +18 -0
- package/src/db/getSession.test.ts +13 -1
- package/src/db/openDatabase.test.ts +10 -1
- package/src/db/openDatabase.ts +3 -1
- package/src/server/app.test.ts +12 -0
- package/src/server/app.ts +18 -8
- package/src/server/client-registry.test.ts +250 -0
- package/src/server/client-registry.ts +477 -0
- package/src/server/config.ts +15 -0
- package/src/server/control-plane-types.ts +120 -0
- package/src/server/control-plane.test.ts +472 -0
- package/src/server/control-plane.ts +581 -0
- package/src/server/routes/backup.test.ts +263 -0
- package/src/server/routes/backup.ts +262 -0
- package/src/server/routes/integrations-email.test.ts +532 -0
- package/src/server/routes/llamafile.test.ts +172 -48
- package/src/server/routes/mesh-llm.test.ts +192 -0
- package/src/server/routes/ollama.test.ts +49 -0
- package/src/server/server-peer.test.ts +86 -0
- package/src/server/server-peer.ts +330 -0
- package/src/server/server.ts +35 -0
- package/src/server/services/llamafile-manager.test.ts +230 -6
- package/src/server/services/transformers-runtime.test.ts +186 -18
- package/src/server/webrtc.test.ts +21 -0
- package/src/server/webrtc.ts +72 -0
- package/src/service-worker/fetch-proxy.test.ts +64 -1
- package/src/service-worker/push-handler.ts +39 -0
- package/src/shell/vm.test.ts +744 -12
- package/src/storage/ensureMainGroupIndex.test.ts +153 -0
- package/src/storage/getGroupFile.test.ts +66 -0
- package/src/storage/memoryStorage.test.ts +82 -2
- package/src/storage/migrateLegacyOpfs.test.ts +327 -0
- package/src/storage/migrateLegacyOpfs.ts +117 -0
- package/src/storage/writeGroupFileBytes.test.ts +143 -0
- package/src/stores/chat-ui.test.ts +20 -0
- package/src/stores/orchestrator.test.ts +134 -0
- package/src/stores/toast.test.ts +50 -0
- package/src/stores/tools.test.ts +147 -10
- package/src/subsystems/channels/imessage.test.ts +59 -0
- package/src/subsystems/channels/peerjs.test.ts +500 -62
- package/src/subsystems/channels/peerjs.ts +71 -4
- package/src/subsystems/channels/telegram.test.ts +177 -0
- package/src/subsystems/email/catalog.test.ts +1 -0
- package/src/subsystems/email/connections.test.ts +39 -1
- package/src/subsystems/git/credentials.test.ts +160 -825
- package/src/subsystems/git/git.test.ts +463 -0
- package/src/subsystems/notifications/__mocks__/node-sqlite.cjs +12 -1
- package/src/subsystems/notifications/push-routes.test.ts +33 -0
- package/src/subsystems/notifications/push-routes.ts +23 -0
- package/src/subsystems/notifications/push-store.ts +1 -1
- package/src/subsystems/providers/builtin-ai-tasks.test.ts +74 -0
- package/src/subsystems/providers/litert-lm-provider.test.ts +212 -51
- package/src/subsystems/providers/model-registry.test.ts +115 -0
- package/src/subsystems/providers/providers.test.ts +94 -1
- package/src/subsystems/providers/transformers-js-provider.test.ts +279 -0
- package/src/subsystems/providers/utils/createModelCacheFetch.test.ts +2 -2
- package/src/subsystems/providers/utils/downloadModelToCache.test.ts +2 -2
- package/src/subsystems/providers/utils/loadModelStream.test.ts +2 -2
- package/src/subsystems/skills/activateSkill.test.ts +101 -0
- package/src/subsystems/skills/discoverSkills.test.ts +251 -0
- package/src/subsystems/tools/cron.test.ts +64 -0
- package/src/subsystems/tools/declarative.test.ts +255 -89
- package/src/testing/assets/v86.9pfs/libv86.mjs +63 -0
- package/src/testing/assets/v86.ext2/libv86.mjs +3 -0
- package/src/testing/assets_missing_v86/assets/v86.9pfs/libv86.mjs +1 -0
- package/src/testing/jest-setup.ts +328 -40
- package/src/testing/mock-v86.mjs +49 -0
- package/src/ui/a2ui/types.ts +4 -3
- package/src/ui/a2ui/utils/normaliseComponentsToMap.test.ts +102 -0
- package/src/ui/a2ui/utils/resolveChildIds.test.ts +63 -0
- package/src/ui/a2ui/utils/resolveDynamicNumber.test.ts +13 -1
- package/src/worker/tools/bash/utils/waitForVMReady.test.ts +40 -0
- package/src/worker/tools/email/email.test.ts +193 -8
- package/src/worker/tools/email/utils/asEmailAttachmentInputs.test.ts +47 -0
- package/src/worker/tools/git/git.test.ts +214 -3
- package/src/worker/tools/rooms/invite-to-room.test.ts +54 -0
- package/src/worker/tools/rooms/leave-room.test.ts +40 -0
- package/src/worker/tools/rooms/list-room-members.test.ts +75 -0
- package/src/worker/tools/tasks/tasks-utils.test.ts +22 -0
- package/src/worker/tools/ui/ask-user.test.ts +50 -0
- package/src/worker/tools/ui/clear-chat.test.ts +19 -0
- package/src/worker/tools/ui/get-current-time.test.ts +19 -0
- package/src/worker/tools/ui/javascript.test.ts +116 -0
- package/src/worker/tools/ui/list-components.test.ts +10 -0
- package/src/worker/tools/ui/list-tool-profiles.test.ts +42 -0
- package/src/worker/tools/ui/manage-tools.test.ts +34 -0
- package/src/worker/tools/ui/render-component.test.ts +346 -0
- package/src/worker/tools/ui/send-notification.test.ts +40 -0
- package/src/worker/tools/ui/utils/getAllowFullInternetAccess.test.ts +31 -0
- package/src/worker/tools/ui/utils/parseBooleanConfig.test.ts +25 -0
- package/src/worker/tools/workspace/attach-file.test.ts +84 -0
- package/src/worker/tools/workspace/copy-file.test.ts +69 -0
- package/src/worker/tools/workspace/create-directory.test.ts +40 -0
- package/src/worker/tools/workspace/delete-file.test.ts +73 -0
- package/src/worker/tools/workspace/diff-files.test.ts +94 -0
- package/src/worker/tools/workspace/list-files.test.ts +36 -0
- package/src/worker/tools/workspace/move-file.test.ts +66 -0
- package/src/worker/tools/workspace/open-file.test.ts +57 -0
- package/src/worker/tools/workspace/patch-file.test.ts +81 -0
- package/src/worker/tools/workspace/read-file.test.ts +116 -0
- package/src/worker/tools/workspace/send-file.test.ts +82 -0
- package/src/worker/tools/workspace/update-memory.test.ts +29 -0
- package/src/worker/tools/workspace/write-file.test.ts +28 -0
- package/src/worker/utils/rate-limit.test.ts +199 -0
- package/src/worker/utils/tool-state.test.ts +29 -0
- package/src/worker/utils/transformers-js-utils.test.ts +59 -0
- package/dist/public/config-AL77QAx4.js +0 -1
- package/dist/public/downloadGroupFile-BABv_1mJ.js +0 -1
- package/dist/public/file-viewer-CCSABMsE.js +0 -1
- package/dist/public/mcp-reconnect-DoicazQd.js +0 -1
- package/dist/public/orchestrator-4su7iyWj.js +0 -15
- package/dist/public/shadow-claw-dialog-ByyHgxM9.js +0 -1
- package/dist/public/shadow-claw-file-viewer-9Qkwc30T.js +0 -577
- package/dist/public/shadow-claw-files-aDyq6Hv7.js +0 -781
- package/dist/public/shadow-claw-storage-Cf31np81.js +0 -202
|
@@ -35,6 +35,24 @@ export async function initializeApp(
|
|
|
35
35
|
|
|
36
36
|
await orchestratorStore.whenReady;
|
|
37
37
|
|
|
38
|
+
if (typeof window !== "undefined") {
|
|
39
|
+
try {
|
|
40
|
+
const {
|
|
41
|
+
createDefaultControlPlaneClient,
|
|
42
|
+
shouldConnectControlPlane,
|
|
43
|
+
isControlPlaneEnabledSync,
|
|
44
|
+
} = await import("./initControlPlane.js");
|
|
45
|
+
|
|
46
|
+
if (isControlPlaneEnabledSync() && shouldConnectControlPlane()) {
|
|
47
|
+
createDefaultControlPlaneClient({
|
|
48
|
+
orchestrator: uiElement.orchestrator,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
} catch (err) {
|
|
52
|
+
console.warn("[ControlPlane] Failed to initialize:", err);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
38
56
|
return { orchestrator: uiElement.orchestrator, isInitializing };
|
|
39
57
|
} catch (error) {
|
|
40
58
|
console.error("❌ Failed to initialize ShadowClaw:", error);
|
|
@@ -11,7 +11,19 @@ describe("getSession", () => {
|
|
|
11
11
|
it("reads session by group id", async () => {
|
|
12
12
|
const session: any = { groupId: "g1", messages: [], updatedAt: 1 };
|
|
13
13
|
|
|
14
|
-
(txPromise as any).
|
|
14
|
+
(txPromise as any).mockImplementation(
|
|
15
|
+
async (
|
|
16
|
+
_db: any,
|
|
17
|
+
_storeName: any,
|
|
18
|
+
_mode: any,
|
|
19
|
+
fn: (store: any) => any,
|
|
20
|
+
) => {
|
|
21
|
+
const mockStore = {
|
|
22
|
+
get: jest.fn().mockReturnValue(session),
|
|
23
|
+
};
|
|
24
|
+
return fn(mockStore);
|
|
25
|
+
},
|
|
26
|
+
);
|
|
15
27
|
|
|
16
28
|
await expect(getSession({} as any, "g1")).resolves.toEqual(session);
|
|
17
29
|
|
|
@@ -2,8 +2,15 @@ import { jest } from "@jest/globals";
|
|
|
2
2
|
|
|
3
3
|
const setDB = jest.fn();
|
|
4
4
|
|
|
5
|
+
const mockMigrateLegacyDatabase = jest.fn<any>().mockResolvedValue(undefined);
|
|
6
|
+
const mockMigrateLegacyOpfs = jest.fn<any>().mockResolvedValue(undefined);
|
|
7
|
+
|
|
5
8
|
jest.unstable_mockModule("./migrateLegacyDatabase.js", () => ({
|
|
6
|
-
migrateLegacyDatabase:
|
|
9
|
+
migrateLegacyDatabase: mockMigrateLegacyDatabase,
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
jest.unstable_mockModule("../storage/migrateLegacyOpfs.js", () => ({
|
|
13
|
+
migrateLegacyOpfs: mockMigrateLegacyOpfs,
|
|
7
14
|
}));
|
|
8
15
|
|
|
9
16
|
jest.unstable_mockModule("./db.js", () => ({
|
|
@@ -110,6 +117,8 @@ describe("openDatabase", () => {
|
|
|
110
117
|
);
|
|
111
118
|
|
|
112
119
|
expect(setDB).toHaveBeenCalledWith(database);
|
|
120
|
+
expect(mockMigrateLegacyDatabase).toHaveBeenCalledWith(database);
|
|
121
|
+
expect(mockMigrateLegacyOpfs).toHaveBeenCalledWith(database);
|
|
113
122
|
});
|
|
114
123
|
|
|
115
124
|
it("skips creating stores that already exist", async () => {
|
package/src/db/openDatabase.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { DB_VERSION, getDbName } from "../config/config.js";
|
|
2
2
|
import { setDB } from "./db.js";
|
|
3
3
|
import { migrateLegacyDatabase } from "./migrateLegacyDatabase.js";
|
|
4
|
+
import { migrateLegacyOpfs } from "../storage/migrateLegacyOpfs.js";
|
|
4
5
|
import type { ShadowClawDatabase } from "./types.js";
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -59,8 +60,9 @@ export function openDatabase(): Promise<ShadowClawDatabase> {
|
|
|
59
60
|
setDB(db);
|
|
60
61
|
try {
|
|
61
62
|
await migrateLegacyDatabase(db);
|
|
63
|
+
await migrateLegacyOpfs(db);
|
|
62
64
|
} catch (e) {
|
|
63
|
-
console.warn("Error running
|
|
65
|
+
console.warn("Error running legacy migration:", e);
|
|
64
66
|
}
|
|
65
67
|
resolve(db);
|
|
66
68
|
};
|
package/src/server/app.test.ts
CHANGED
|
@@ -43,6 +43,9 @@ describe("app", () => {
|
|
|
43
43
|
jest.unstable_mockModule("./routes/oauth.js", () => ({
|
|
44
44
|
registerOAuthRoutes: jest.fn(),
|
|
45
45
|
}));
|
|
46
|
+
jest.unstable_mockModule("./routes/backup.js", () => ({
|
|
47
|
+
registerBackupRoutes: jest.fn(),
|
|
48
|
+
}));
|
|
46
49
|
jest.unstable_mockModule("./routes/csp-report.js", () => ({
|
|
47
50
|
registerCspReportRoutes: jest.fn(),
|
|
48
51
|
}));
|
|
@@ -92,6 +95,9 @@ describe("app", () => {
|
|
|
92
95
|
jest.unstable_mockModule("./middleware/csp.js", () => ({
|
|
93
96
|
createCspReportOnlyMiddleware: jest.fn(() => () => {}),
|
|
94
97
|
}));
|
|
98
|
+
jest.unstable_mockModule("./client-registry.js", () => ({
|
|
99
|
+
openClientStore: jest.fn(),
|
|
100
|
+
}));
|
|
95
101
|
jest.unstable_mockModule("./middleware/static-files.js", () => ({
|
|
96
102
|
registerStaticFilesMiddleware: jest.fn(),
|
|
97
103
|
}));
|
|
@@ -101,9 +107,11 @@ describe("app", () => {
|
|
|
101
107
|
const { createApp } = await import("./app.js");
|
|
102
108
|
const { registerProxyRoutes } = await import("./proxy.js");
|
|
103
109
|
const { registerOAuthRoutes } = await import("./routes/oauth.js");
|
|
110
|
+
const { registerBackupRoutes } = await import("./routes/backup.js");
|
|
104
111
|
const { registerCspReportRoutes } = await import("./routes/csp-report.js");
|
|
105
112
|
const { openPushStore } =
|
|
106
113
|
await import("../subsystems/notifications/push-store.js");
|
|
114
|
+
const { openClientStore } = await import("./client-registry.js");
|
|
107
115
|
const { createCspReportOnlyMiddleware } =
|
|
108
116
|
await import("./middleware/csp.js");
|
|
109
117
|
const { registerStaticFilesMiddleware } =
|
|
@@ -118,11 +126,15 @@ describe("app", () => {
|
|
|
118
126
|
verbose: false,
|
|
119
127
|
});
|
|
120
128
|
expect(registerOAuthRoutes).toHaveBeenCalledWith(appMock);
|
|
129
|
+
expect(registerBackupRoutes).toHaveBeenCalledTimes(1);
|
|
121
130
|
expect(registerCspReportRoutes).toHaveBeenCalledTimes(1);
|
|
122
131
|
expect(createCspReportOnlyMiddleware).toHaveBeenCalledTimes(1);
|
|
123
132
|
expect(openPushStore).toHaveBeenCalledWith(
|
|
124
133
|
expect.stringContaining("push-subscriptions.db"),
|
|
125
134
|
);
|
|
135
|
+
expect(openClientStore).toHaveBeenCalledWith(
|
|
136
|
+
expect.stringContaining("clients.db"),
|
|
137
|
+
);
|
|
126
138
|
expect(registerStaticFilesMiddleware).toHaveBeenCalledWith(
|
|
127
139
|
appMock,
|
|
128
140
|
config.rootPath,
|
package/src/server/app.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
registerPushRoutes,
|
|
9
9
|
} from "../subsystems/notifications/push-routes.js";
|
|
10
10
|
import { openPushStore } from "../subsystems/notifications/push-store.js";
|
|
11
|
+
import { openClientStore } from "./client-registry.js";
|
|
11
12
|
|
|
12
13
|
import { registerTaskScheduleRoutes } from "../subsystems/notifications/task-schedule-routes.js";
|
|
13
14
|
import {
|
|
@@ -28,6 +29,7 @@ import { registerProxyRoutes } from "./proxy.js";
|
|
|
28
29
|
import { registerActivityLogRoutes } from "./routes/activity-log.js";
|
|
29
30
|
import { registerCspReportRoutes } from "./routes/csp-report.js";
|
|
30
31
|
import { registerOAuthRoutes } from "./routes/oauth.js";
|
|
32
|
+
import { registerBackupRoutes } from "./routes/backup.js";
|
|
31
33
|
|
|
32
34
|
import type { Express } from "express";
|
|
33
35
|
import type { ServerConfig } from "./config.js";
|
|
@@ -67,6 +69,15 @@ export function createApp(config: ServerConfig): {
|
|
|
67
69
|
|
|
68
70
|
app.use(express.json({ limit: "1000mb" }));
|
|
69
71
|
|
|
72
|
+
// ---------------- DATABASE & STORES ----------------
|
|
73
|
+
if (!fs.existsSync(config.databaseDir)) {
|
|
74
|
+
fs.mkdirSync(config.databaseDir, { recursive: true });
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
openPushStore(path.join(config.databaseDir, "push-subscriptions.db"));
|
|
78
|
+
openClientStore(path.join(config.databaseDir, "clients.db"));
|
|
79
|
+
openTaskScheduleStore(path.join(config.databaseDir, "scheduled-tasks.db"));
|
|
80
|
+
|
|
70
81
|
// ---------------- PROXY ROUTES ----------------
|
|
71
82
|
registerProxyRoutes(app, {
|
|
72
83
|
verbose,
|
|
@@ -81,21 +92,20 @@ export function createApp(config: ServerConfig): {
|
|
|
81
92
|
logsDir: path.resolve(config.databaseDir, "..", ".cache", "logs"),
|
|
82
93
|
});
|
|
83
94
|
|
|
95
|
+
// ---------------- BACKUP ROUTES ----------------
|
|
96
|
+
registerBackupRoutes(app, {
|
|
97
|
+
backupsDir: path.resolve(config.databaseDir, "..", ".cache", "backups"),
|
|
98
|
+
token: config.controlToken,
|
|
99
|
+
});
|
|
100
|
+
|
|
84
101
|
// ---------------- CSP REPORT ROUTES ----------------
|
|
85
102
|
registerCspReportRoutes(app, {
|
|
86
103
|
logsDir: path.resolve(config.databaseDir, "..", ".cache", "logs"),
|
|
87
104
|
logger,
|
|
88
105
|
});
|
|
89
106
|
|
|
90
|
-
// ----------------
|
|
91
|
-
if (!fs.existsSync(config.databaseDir)) {
|
|
92
|
-
fs.mkdirSync(config.databaseDir, { recursive: true });
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
openPushStore(path.join(config.databaseDir, "push-subscriptions.db"));
|
|
107
|
+
// ---------------- PUSH & TASK ROUTES ----------------
|
|
96
108
|
registerPushRoutes(app);
|
|
97
|
-
|
|
98
|
-
openTaskScheduleStore(path.join(config.databaseDir, "scheduled-tasks.db"));
|
|
99
109
|
registerTaskScheduleRoutes(app);
|
|
100
110
|
|
|
101
111
|
const scheduler = new ServerTaskScheduler({
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import {
|
|
2
|
+
openClientStore,
|
|
3
|
+
closeClientStore,
|
|
4
|
+
registerClient,
|
|
5
|
+
updateClientHeartbeat,
|
|
6
|
+
unregisterClient,
|
|
7
|
+
getClient,
|
|
8
|
+
getAllClients,
|
|
9
|
+
pruneStaleClients,
|
|
10
|
+
generateControlToken,
|
|
11
|
+
getOrCreateControlToken,
|
|
12
|
+
saveControlTokenFile,
|
|
13
|
+
readControlTokenFile,
|
|
14
|
+
getControlTokenFilePath,
|
|
15
|
+
} from "./client-registry.js";
|
|
16
|
+
import fs from "node:fs";
|
|
17
|
+
import path from "node:path";
|
|
18
|
+
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
openClientStore(":memory:");
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
afterEach(() => {
|
|
24
|
+
closeClientStore();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const MOCK_CLIENT_1 = {
|
|
28
|
+
clientId: "sc-client-alpha",
|
|
29
|
+
deviceLabel: "iPad Safari",
|
|
30
|
+
capabilities: ["opfs", "webmcp", "push"],
|
|
31
|
+
version: "1.23.4",
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const MOCK_CLIENT_2 = {
|
|
35
|
+
clientId: "sc-client-beta",
|
|
36
|
+
deviceLabel: "Desktop Chrome",
|
|
37
|
+
capabilities: ["opfs", "webmcp", "peerjs"],
|
|
38
|
+
version: "1.23.4",
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
describe("client-registry", () => {
|
|
42
|
+
describe("openClientStore", () => {
|
|
43
|
+
it("creates tables on first open", () => {
|
|
44
|
+
const db = openClientStore(":memory:");
|
|
45
|
+
const clients = db.prepare("SELECT * FROM clients").all();
|
|
46
|
+
expect(clients).toEqual([]);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("returns the existing database instance if already opened", () => {
|
|
50
|
+
const db1 = openClientStore(":memory:");
|
|
51
|
+
const db2 = openClientStore(":memory:");
|
|
52
|
+
expect(db1).toBe(db2);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe("registerClient", () => {
|
|
57
|
+
it("registers a new client with timestamps", () => {
|
|
58
|
+
const client = registerClient(MOCK_CLIENT_1);
|
|
59
|
+
expect(client.clientId).toBe(MOCK_CLIENT_1.clientId);
|
|
60
|
+
expect(client.deviceLabel).toBe(MOCK_CLIENT_1.deviceLabel);
|
|
61
|
+
expect(client.capabilities).toEqual(MOCK_CLIENT_1.capabilities);
|
|
62
|
+
expect(client.version).toBe(MOCK_CLIENT_1.version);
|
|
63
|
+
expect(typeof client.connectedAt).toBe("number");
|
|
64
|
+
expect(typeof client.lastSeen).toBe("number");
|
|
65
|
+
|
|
66
|
+
const fetched = getClient(MOCK_CLIENT_1.clientId);
|
|
67
|
+
expect(fetched).toEqual(client);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("updates existing client registration when re-registered", () => {
|
|
71
|
+
registerClient(MOCK_CLIENT_1);
|
|
72
|
+
const updated = registerClient({
|
|
73
|
+
...MOCK_CLIENT_1,
|
|
74
|
+
deviceLabel: "iPad Pro Safari (Updated)",
|
|
75
|
+
capabilities: ["opfs", "webmcp", "push", "peerjs"],
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
expect(updated.deviceLabel).toBe("iPad Pro Safari (Updated)");
|
|
79
|
+
expect(updated.capabilities).toEqual([
|
|
80
|
+
"opfs",
|
|
81
|
+
"webmcp",
|
|
82
|
+
"push",
|
|
83
|
+
"peerjs",
|
|
84
|
+
]);
|
|
85
|
+
|
|
86
|
+
const all = getAllClients();
|
|
87
|
+
expect(all).toHaveLength(1);
|
|
88
|
+
expect(all[0].deviceLabel).toBe("iPad Pro Safari (Updated)");
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe("updateClientHeartbeat", () => {
|
|
93
|
+
it("updates lastSeen timestamp for an existing client", () => {
|
|
94
|
+
registerClient(MOCK_CLIENT_1);
|
|
95
|
+
const before = getClient(MOCK_CLIENT_1.clientId)!;
|
|
96
|
+
|
|
97
|
+
const targetTime = before.lastSeen + 5000;
|
|
98
|
+
const updated = updateClientHeartbeat(MOCK_CLIENT_1.clientId, targetTime);
|
|
99
|
+
expect(updated).toBe(true);
|
|
100
|
+
|
|
101
|
+
const after = getClient(MOCK_CLIENT_1.clientId)!;
|
|
102
|
+
expect(after.lastSeen).toBe(targetTime);
|
|
103
|
+
expect(after.connectedAt).toBe(before.connectedAt);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("returns false when updating a nonexistent client", () => {
|
|
107
|
+
const updated = updateClientHeartbeat("nonexistent-client");
|
|
108
|
+
expect(updated).toBe(false);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
describe("unregisterClient", () => {
|
|
113
|
+
it("removes a registered client", () => {
|
|
114
|
+
registerClient(MOCK_CLIENT_1);
|
|
115
|
+
registerClient(MOCK_CLIENT_2);
|
|
116
|
+
expect(getAllClients()).toHaveLength(2);
|
|
117
|
+
|
|
118
|
+
const removed = unregisterClient(MOCK_CLIENT_1.clientId);
|
|
119
|
+
expect(removed).toBe(true);
|
|
120
|
+
|
|
121
|
+
expect(getClient(MOCK_CLIENT_1.clientId)).toBeNull();
|
|
122
|
+
expect(getAllClients()).toHaveLength(1);
|
|
123
|
+
expect(getAllClients()[0].clientId).toBe(MOCK_CLIENT_2.clientId);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("returns false when unregistering a nonexistent client", () => {
|
|
127
|
+
const removed = unregisterClient("nonexistent-client");
|
|
128
|
+
expect(removed).toBe(false);
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
describe("getAllClients", () => {
|
|
133
|
+
it("returns all registered clients ordered by lastSeen descending", () => {
|
|
134
|
+
registerClient(MOCK_CLIENT_1);
|
|
135
|
+
registerClient(MOCK_CLIENT_2);
|
|
136
|
+
|
|
137
|
+
updateClientHeartbeat(MOCK_CLIENT_1.clientId, 1000);
|
|
138
|
+
updateClientHeartbeat(MOCK_CLIENT_2.clientId, 2000);
|
|
139
|
+
|
|
140
|
+
const clients = getAllClients();
|
|
141
|
+
expect(clients).toHaveLength(2);
|
|
142
|
+
expect(clients[0].clientId).toBe(MOCK_CLIENT_2.clientId);
|
|
143
|
+
expect(clients[1].clientId).toBe(MOCK_CLIENT_1.clientId);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
describe("pruneStaleClients", () => {
|
|
148
|
+
it("prunes clients whose lastSeen is older than maxAgeMs", () => {
|
|
149
|
+
const now = 100_000;
|
|
150
|
+
registerClient(MOCK_CLIENT_1);
|
|
151
|
+
registerClient(MOCK_CLIENT_2);
|
|
152
|
+
|
|
153
|
+
// Client 1 was seen 50s ago, Client 2 was seen 10s ago
|
|
154
|
+
updateClientHeartbeat(MOCK_CLIENT_1.clientId, now - 50_000);
|
|
155
|
+
updateClientHeartbeat(MOCK_CLIENT_2.clientId, now - 10_000);
|
|
156
|
+
|
|
157
|
+
// Prune anything older than 30s
|
|
158
|
+
const prunedCount = pruneStaleClients(30_000, now);
|
|
159
|
+
expect(prunedCount).toBe(1);
|
|
160
|
+
|
|
161
|
+
const remaining = getAllClients();
|
|
162
|
+
expect(remaining).toHaveLength(1);
|
|
163
|
+
expect(remaining[0].clientId).toBe(MOCK_CLIENT_2.clientId);
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
describe("generateControlToken", () => {
|
|
168
|
+
it("generates a high-entropy random hex token (64 characters / 256-bit)", () => {
|
|
169
|
+
const token1 = generateControlToken();
|
|
170
|
+
const token2 = generateControlToken();
|
|
171
|
+
expect(typeof token1).toBe("string");
|
|
172
|
+
expect(token1).toHaveLength(64);
|
|
173
|
+
expect(token2).toHaveLength(64);
|
|
174
|
+
expect(token1).not.toBe(token2);
|
|
175
|
+
expect(/^[0-9a-f]{64}$/.test(token1)).toBe(true);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("supports custom byte lengths", () => {
|
|
179
|
+
const token = generateControlToken(16);
|
|
180
|
+
expect(token).toHaveLength(32);
|
|
181
|
+
expect(/^[0-9a-f]{32}$/.test(token)).toBe(true);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
describe("getOrCreateControlToken", () => {
|
|
186
|
+
let tempCacheDir: string;
|
|
187
|
+
|
|
188
|
+
beforeEach(() => {
|
|
189
|
+
tempCacheDir = path.join(
|
|
190
|
+
process.cwd(),
|
|
191
|
+
".cache",
|
|
192
|
+
"test-token-unit-" +
|
|
193
|
+
Date.now() +
|
|
194
|
+
"-" +
|
|
195
|
+
Math.random().toString(36).slice(2),
|
|
196
|
+
);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
afterEach(() => {
|
|
200
|
+
try {
|
|
201
|
+
fs.rmSync(tempCacheDir, { recursive: true, force: true });
|
|
202
|
+
} catch (_) {}
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it("generates a new token if none exists", () => {
|
|
206
|
+
const token = getOrCreateControlToken(undefined, tempCacheDir);
|
|
207
|
+
expect(typeof token).toBe("string");
|
|
208
|
+
expect(token).toHaveLength(64);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it("returns the existing token on subsequent calls", () => {
|
|
212
|
+
const token1 = getOrCreateControlToken(undefined, tempCacheDir);
|
|
213
|
+
const token2 = getOrCreateControlToken(undefined, tempCacheDir);
|
|
214
|
+
expect(token1).toBe(token2);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it("persists a custom configured token if provided", () => {
|
|
218
|
+
closeClientStore();
|
|
219
|
+
openClientStore(":memory:");
|
|
220
|
+
const customToken = "custom-secret-token-123456";
|
|
221
|
+
const token = getOrCreateControlToken(customToken, tempCacheDir);
|
|
222
|
+
expect(token).toBe(customToken);
|
|
223
|
+
|
|
224
|
+
const fetched = getOrCreateControlToken(undefined, tempCacheDir);
|
|
225
|
+
expect(fetched).toBe(customToken);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it("saves and reads token to .cache/control-token.json with timestamps", () => {
|
|
229
|
+
const saved = saveControlTokenFile(
|
|
230
|
+
"my-secret-test-token",
|
|
231
|
+
tempCacheDir,
|
|
232
|
+
1700000000000,
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
expect(saved.token).toBe("my-secret-test-token");
|
|
236
|
+
expect(saved.createdAt).toBe(1700000000000);
|
|
237
|
+
expect(saved.createdAtIso).toBe(new Date(1700000000000).toISOString());
|
|
238
|
+
|
|
239
|
+
const read = readControlTokenFile(tempCacheDir);
|
|
240
|
+
expect(read).toEqual(saved);
|
|
241
|
+
|
|
242
|
+
const filePath = getControlTokenFilePath(tempCacheDir);
|
|
243
|
+
expect(fs.existsSync(filePath)).toBe(true);
|
|
244
|
+
|
|
245
|
+
const rawJson = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
246
|
+
expect(rawJson.token).toBe("my-secret-test-token");
|
|
247
|
+
expect(rawJson.createdAt).toBe(1700000000000);
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
});
|