@capyclaw/browser-workbench 0.1.0 → 0.1.17
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 +29 -7
- package/contract/browser-contract.json +484 -25
- package/demo/form.html +27 -0
- package/lib/host.mjs +1 -68
- package/node_modules/@capyclaw/asset-service/README.md +48 -0
- package/node_modules/@capyclaw/asset-service/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/asset-service/dsh-suite.json +29 -0
- package/node_modules/@capyclaw/asset-service/lib/host.mjs +14 -0
- package/node_modules/@capyclaw/asset-service/package.json +59 -0
- package/node_modules/@capyclaw/asset-service/src/index.mjs +223 -0
- package/node_modules/@capyclaw/document-workbench/README.md +125 -0
- package/node_modules/@capyclaw/document-workbench/package.json +44 -0
- package/node_modules/@capyclaw/document-workbench/src/bridge/index.mjs +321 -0
- package/node_modules/@capyclaw/document-workbench/src/client/index.mjs +625 -0
- package/node_modules/@capyclaw/document-workbench/src/client/screenshot.mjs +98 -0
- package/node_modules/@capyclaw/document-workbench/src/index.mjs +9 -0
- package/node_modules/@capyclaw/document-workbench/src/model/audit.mjs +101 -0
- package/node_modules/@capyclaw/document-workbench/src/model/conformance.mjs +92 -0
- package/node_modules/@capyclaw/document-workbench/src/model/ids.mjs +56 -0
- package/node_modules/@capyclaw/document-workbench/src/model/index.mjs +18 -0
- package/node_modules/@capyclaw/document-workbench/src/model/locate.mjs +118 -0
- package/node_modules/@capyclaw/document-workbench/src/model/manifest.mjs +148 -0
- package/node_modules/@capyclaw/document-workbench/src/model/ops.mjs +160 -0
- package/node_modules/@capyclaw/document-workbench/src/model/validate.mjs +72 -0
- package/node_modules/@capyclaw/document-workbench/src/ops/index.mjs +93 -0
- package/node_modules/@capyclaw/document-workbench/src/session/context.mjs +91 -0
- package/node_modules/@capyclaw/document-workbench/src/session/index.mjs +394 -0
- package/node_modules/@capyclaw/document-workbench/src/session/lease.mjs +105 -0
- package/node_modules/@capyclaw/document-workbench/src/session/mode.mjs +80 -0
- package/node_modules/@capyclaw/document-workbench/src/session/sanitize.mjs +107 -0
- package/node_modules/@capyclaw/document-workbench/src/session/state.mjs +159 -0
- package/node_modules/@capyclaw/document-workbench/src/session/watch.mjs +63 -0
- package/{server/shared/state-service.mjs → node_modules/@capyclaw/document-workbench/src/store/file-backend.mjs} +6 -97
- package/node_modules/@capyclaw/document-workbench/src/testing/index.mjs +75 -0
- package/node_modules/@capyclaw/foundation/README.md +51 -0
- package/node_modules/@capyclaw/foundation/abi/bridge.mjs +86 -0
- package/node_modules/@capyclaw/foundation/abi/errors.mjs +63 -0
- package/node_modules/@capyclaw/foundation/abi/index.mjs +35 -0
- package/node_modules/@capyclaw/foundation/abi/kinds.mjs +271 -0
- package/node_modules/@capyclaw/foundation/abi/loader.mjs +345 -0
- package/node_modules/@capyclaw/foundation/abi/schema.mjs +98 -0
- package/node_modules/@capyclaw/foundation/abi/spec.mjs +255 -0
- package/node_modules/@capyclaw/foundation/abi/validate.mjs +24 -0
- package/node_modules/@capyclaw/foundation/abi/version.mjs +82 -0
- package/node_modules/@capyclaw/foundation/cordis.patch.yml +5 -0
- package/node_modules/@capyclaw/foundation/kit/index.mjs +6 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/client-panel.mjs +98 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/host-event.mjs +35 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/http-router.mjs +69 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/lifecycle-hook.mjs +55 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/own-server.mjs +113 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/raw.mjs +68 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/runtime-driver.mjs +113 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/service-provider.mjs +77 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/skill-provider.mjs +56 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/tool-provider.mjs +50 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/ui-panel.mjs +64 -0
- package/node_modules/@capyclaw/foundation/lib/ctx-service.mjs +42 -0
- package/node_modules/@capyclaw/foundation/lib/host/caps.mjs +34 -0
- package/node_modules/@capyclaw/foundation/lib/host/contract.mjs +85 -0
- package/node_modules/@capyclaw/foundation/lib/host/dsh.mjs +50 -0
- package/node_modules/@capyclaw/foundation/lib/host/memory.mjs +160 -0
- package/node_modules/@capyclaw/foundation/lib/host.mjs +23 -0
- package/node_modules/@capyclaw/foundation/lib/kernel.mjs +185 -0
- package/node_modules/@capyclaw/foundation/lib/skill/scan.mjs +87 -0
- package/node_modules/@capyclaw/foundation/lib/subsystems/events.mjs +60 -0
- package/node_modules/@capyclaw/foundation/lib/subsystems/log.mjs +51 -0
- package/node_modules/@capyclaw/foundation/lib/subsystems/net.mjs +188 -0
- package/node_modules/@capyclaw/foundation/package.json +53 -0
- package/node_modules/@capyclaw/foundation/runtime/index.mjs +20 -0
- package/node_modules/@capyclaw/plugin-kit/INTEGRATION.md +100 -0
- package/node_modules/@capyclaw/plugin-kit/README.md +70 -0
- package/node_modules/@capyclaw/plugin-kit/bin/sync.mjs +103 -0
- package/node_modules/@capyclaw/plugin-kit/package.json +69 -0
- package/node_modules/@capyclaw/plugin-kit/src/cli.mjs +56 -0
- package/node_modules/@capyclaw/plugin-kit/src/config.mjs +142 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat-worker.js +129 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/lease.mjs +139 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/shadow.mjs +219 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/transport.js +13 -0
- package/node_modules/@capyclaw/plugin-kit/src/index.mjs +13 -0
- package/node_modules/@capyclaw/plugin-kit/src/pack.mjs +230 -0
- package/node_modules/@capyclaw/plugin-kit/src/runtime/context.mjs +128 -0
- package/node_modules/@capyclaw/plugin-kit/src/self-contained.mjs +307 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/api.mjs +45 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/http.mjs +113 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/mcp-http.mjs +143 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/server.mjs +131 -0
- package/node_modules/@capyclaw/plugin-kit/src/skills/provider.mjs +82 -0
- package/node_modules/@capyclaw/plugin-kit/src/store/blob-store.mjs +109 -0
- package/node_modules/@capyclaw/plugin-kit/src/store/content-store.mjs +17 -0
- package/node_modules/@capyclaw/plugin-kit/src/store/journal-store.mjs +89 -0
- package/node_modules/@capyclaw/plugin-kit/src/tools/result.mjs +41 -0
- package/node_modules/@capyclaw/plugin-kit/src/tools/validate.mjs +150 -0
- package/node_modules/@capyclaw/plugin-kit/src/tuning.mjs +82 -0
- package/node_modules/@capyclaw/plugin-kit/src/util/fs-lock.mjs +132 -0
- package/node_modules/@capyclaw/plugin-kit/src/util/http.mjs +130 -0
- package/node_modules/@capyclaw/plugin-kit/src/workspace/manager.mjs +656 -0
- package/node_modules/@capyclaw/plugin-kit/src/zip.mjs +181 -0
- package/node_modules/@capyclaw/service-host/README.md +86 -0
- package/node_modules/@capyclaw/service-host/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/service-host/dsh-suite.json +29 -0
- package/node_modules/@capyclaw/service-host/lib/host.mjs +22 -0
- package/node_modules/@capyclaw/service-host/package.json +60 -0
- package/node_modules/@capyclaw/service-host/src/index.mjs +571 -0
- package/node_modules/@capyclaw/service-host/src/tuning.mjs +63 -0
- package/node_modules/@capyclaw/tool-host/README.md +56 -0
- package/node_modules/@capyclaw/tool-host/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/tool-host/dsh-suite.json +30 -0
- package/node_modules/@capyclaw/tool-host/lib/host.mjs +16 -0
- package/node_modules/@capyclaw/tool-host/package.json +59 -0
- package/node_modules/@capyclaw/tool-host/src/descriptors.mjs +142 -0
- package/node_modules/@capyclaw/tool-host/src/index.mjs +390 -0
- package/node_modules/playwright/LICENSE +202 -0
- package/node_modules/playwright/NOTICE +5 -0
- package/node_modules/playwright/README.md +318 -0
- package/node_modules/playwright/ThirdPartyNotices.txt +14 -0
- package/node_modules/playwright/cli.js +19 -0
- package/node_modules/playwright/index.d.ts +17 -0
- package/node_modules/playwright/index.js +17 -0
- package/node_modules/playwright/index.mjs +18 -0
- package/node_modules/playwright/lib/agents/agentParser.js +89 -0
- package/node_modules/playwright/lib/agents/copilot-setup-steps.yml +34 -0
- package/node_modules/playwright/lib/agents/generateAgents.js +395 -0
- package/node_modules/playwright/lib/agents/playwright-test-coverage.prompt.md +31 -0
- package/node_modules/playwright/lib/agents/playwright-test-generate.prompt.md +8 -0
- package/node_modules/playwright/lib/agents/playwright-test-generator.agent.md +88 -0
- package/node_modules/playwright/lib/agents/playwright-test-heal.prompt.md +6 -0
- package/node_modules/playwright/lib/agents/playwright-test-healer.agent.md +56 -0
- package/node_modules/playwright/lib/agents/playwright-test-plan.prompt.md +9 -0
- package/node_modules/playwright/lib/agents/playwright-test-planner.agent.md +74 -0
- package/node_modules/playwright/lib/cli/reportActions.js +78 -0
- package/node_modules/playwright/lib/cli/testActions.js +217 -0
- package/node_modules/playwright/lib/common/index.js +2937 -0
- package/node_modules/playwright/lib/common/index.js.txt +33 -0
- package/node_modules/playwright/lib/errorContext.js +129 -0
- package/node_modules/playwright/lib/globals.js +58 -0
- package/node_modules/playwright/lib/index.js +827 -0
- package/node_modules/playwright/lib/isomorphic.js +260 -0
- package/node_modules/playwright/lib/isomorphic.js.txt +9 -0
- package/node_modules/playwright/lib/loader/loaderProcessEntry.js +34 -0
- package/node_modules/playwright/lib/loader/loaderProcessEntry.js.txt +9 -0
- package/node_modules/playwright/lib/matchers/expect.js +13496 -0
- package/node_modules/playwright/lib/matchers/expect.js.LICENSE +640 -0
- package/node_modules/playwright/lib/matchers/expect.js.txt +67 -0
- package/node_modules/playwright/lib/package.js +47 -0
- package/node_modules/playwright/lib/program.js +242 -0
- package/node_modules/playwright/lib/runner/index.js +8721 -0
- package/node_modules/playwright/lib/runner/index.js.txt +62 -0
- package/node_modules/playwright/lib/transform/babelBundle.js +72490 -0
- package/node_modules/playwright/lib/transform/babelBundle.js.LICENSE +2384 -0
- package/node_modules/playwright/lib/transform/babelBundle.js.txt +328 -0
- package/node_modules/playwright/lib/transform/esmLoader.js +8066 -0
- package/node_modules/playwright/lib/transform/esmLoader.js.LICENSE +355 -0
- package/node_modules/playwright/lib/transform/esmLoader.js.txt +60 -0
- package/node_modules/playwright/lib/util.js +373 -0
- package/node_modules/playwright/lib/worker/workerProcessEntry.js +1860 -0
- package/node_modules/playwright/lib/worker/workerProcessEntry.js.txt +19 -0
- package/node_modules/playwright/package.json +50 -0
- package/node_modules/playwright/test.d.ts +18 -0
- package/node_modules/playwright/test.js +24 -0
- package/node_modules/playwright/test.mjs +35 -0
- package/node_modules/playwright/types/test.d.ts +11191 -0
- package/node_modules/playwright/types/testReporter.d.ts +950 -0
- package/node_modules/playwright-core/LICENSE +202 -0
- package/node_modules/playwright-core/NOTICE +5 -0
- package/node_modules/playwright-core/README.md +3 -0
- package/node_modules/playwright-core/ThirdPartyNotices.txt +13 -0
- package/node_modules/playwright-core/bin/install_media_pack.ps1 +5 -0
- package/node_modules/playwright-core/bin/install_webkit_wsl.ps1 +33 -0
- package/node_modules/playwright-core/bin/reinstall_chrome_beta_linux.sh +42 -0
- package/node_modules/playwright-core/bin/reinstall_chrome_beta_mac.sh +13 -0
- package/node_modules/playwright-core/bin/reinstall_chrome_beta_win.ps1 +24 -0
- package/node_modules/playwright-core/bin/reinstall_chrome_stable_linux.sh +42 -0
- package/node_modules/playwright-core/bin/reinstall_chrome_stable_mac.sh +12 -0
- package/node_modules/playwright-core/bin/reinstall_chrome_stable_win.ps1 +24 -0
- package/node_modules/playwright-core/bin/reinstall_msedge_beta_linux.sh +48 -0
- package/node_modules/playwright-core/bin/reinstall_msedge_beta_mac.sh +11 -0
- package/node_modules/playwright-core/bin/reinstall_msedge_beta_win.ps1 +23 -0
- package/node_modules/playwright-core/bin/reinstall_msedge_dev_linux.sh +48 -0
- package/node_modules/playwright-core/bin/reinstall_msedge_dev_mac.sh +11 -0
- package/node_modules/playwright-core/bin/reinstall_msedge_dev_win.ps1 +23 -0
- package/node_modules/playwright-core/bin/reinstall_msedge_stable_linux.sh +48 -0
- package/node_modules/playwright-core/bin/reinstall_msedge_stable_mac.sh +11 -0
- package/node_modules/playwright-core/bin/reinstall_msedge_stable_win.ps1 +24 -0
- package/node_modules/playwright-core/browsers.json +52 -0
- package/node_modules/playwright-core/cli.js +22 -0
- package/node_modules/playwright-core/index.d.ts +17 -0
- package/node_modules/playwright-core/index.js +17 -0
- package/node_modules/playwright-core/index.mjs +28 -0
- package/node_modules/playwright-core/lib/bootstrap.js +149 -0
- package/node_modules/playwright-core/lib/coreBundle.js +78041 -0
- package/node_modules/playwright-core/lib/entry/cliDaemon.js +5 -0
- package/node_modules/playwright-core/lib/entry/dashboardApp.js +3 -0
- package/node_modules/playwright-core/lib/entry/mcp.js +10 -0
- package/node_modules/playwright-core/lib/entry/oopBrowserDownload.js +3 -0
- package/node_modules/playwright-core/lib/package.js +50 -0
- package/node_modules/playwright-core/lib/server/chromium/appIcon.png +0 -0
- package/node_modules/playwright-core/lib/server/electron/loader.js +123 -0
- package/node_modules/playwright-core/lib/serverRegistry.js +1939 -0
- package/node_modules/playwright-core/lib/serverRegistry.js.LICENSE +65 -0
- package/node_modules/playwright-core/lib/tools/cli-client/channelSessions.js +141 -0
- package/node_modules/playwright-core/lib/tools/cli-client/cli.js +7 -0
- package/node_modules/playwright-core/lib/tools/cli-client/help.json +808 -0
- package/node_modules/playwright-core/lib/tools/cli-client/minimist.js +128 -0
- package/node_modules/playwright-core/lib/tools/cli-client/output.js +352 -0
- package/node_modules/playwright-core/lib/tools/cli-client/program.js +422 -0
- package/node_modules/playwright-core/lib/tools/cli-client/registry.js +180 -0
- package/node_modules/playwright-core/lib/tools/cli-client/session.js +261 -0
- package/node_modules/playwright-core/lib/tools/dashboard/appIcon.png +0 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/SKILL.md +493 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/element-attributes.md +23 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/playwright-tests.md +39 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/pr-attachments.md +60 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/request-mocking.md +87 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/running-code.md +245 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/session-management.md +227 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/storage-state.md +275 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/test-generation.md +433 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/tracing.md +139 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/video-recording.md +216 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-component-testing/SKILL.md +136 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-component-testing/references/gallery-spec.md +144 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-component-testing/references/migration.md +89 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-component-testing/references/react.md +69 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-component-testing/references/typing.md +173 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-component-testing/references/vue.md +77 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-trace/SKILL.md +174 -0
- package/node_modules/playwright-core/lib/tools/utils/extension.js +112 -0
- package/node_modules/playwright-core/lib/tools/utils/socketConnection.js +108 -0
- package/node_modules/playwright-core/lib/utilsBundle.js +86078 -0
- package/node_modules/playwright-core/lib/utilsBundle.js.LICENSE +1890 -0
- package/node_modules/playwright-core/lib/vite/dashboard/assets/codeMirrorModule--QdMvsKi.css +1 -0
- package/node_modules/playwright-core/lib/vite/dashboard/assets/codeMirrorModule-CQ8RZGBm.js +32 -0
- package/node_modules/playwright-core/lib/vite/dashboard/assets/codicon-DCmgc-ay.ttf +0 -0
- package/node_modules/playwright-core/lib/vite/dashboard/assets/firefox-1bWoP6pv.svg +1 -0
- package/node_modules/playwright-core/lib/vite/dashboard/assets/firefox-beta-k3eOH_eK.svg +1 -0
- package/node_modules/playwright-core/lib/vite/dashboard/assets/firefox-nightly-Cp5nfeDT.svg +1 -0
- package/node_modules/playwright-core/lib/vite/dashboard/assets/index-AwgwcYie.css +1 -0
- package/node_modules/playwright-core/lib/vite/dashboard/assets/index-hRvO4yU2.js +12 -0
- package/node_modules/playwright-core/lib/vite/dashboard/assets/safari-na3_-uQk.svg +1 -0
- package/node_modules/playwright-core/lib/vite/dashboard/index.html +29 -0
- package/node_modules/playwright-core/lib/vite/dashboard/playwright-logo.svg +24 -0
- package/node_modules/playwright-core/lib/vite/htmlReport/index.html +16 -0
- package/node_modules/playwright-core/lib/vite/htmlReport/report.css +2 -0
- package/node_modules/playwright-core/lib/vite/htmlReport/report.js +32 -0
- package/node_modules/playwright-core/lib/vite/recorder/assets/codeMirrorModule--QdMvsKi.css +1 -0
- package/node_modules/playwright-core/lib/vite/recorder/assets/codeMirrorModule-DK72OMRi.js +32 -0
- package/node_modules/playwright-core/lib/vite/recorder/assets/codicon-DCmgc-ay.ttf +0 -0
- package/node_modules/playwright-core/lib/vite/recorder/assets/index-BZpYJZ-P.css +1 -0
- package/node_modules/playwright-core/lib/vite/recorder/assets/index-Cn0mmDuv.js +129 -0
- package/node_modules/playwright-core/lib/vite/recorder/index.html +29 -0
- package/node_modules/playwright-core/lib/vite/recorder/playwright-logo.svg +9 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/assets/codeMirrorModule-BEB2e8M3.js +32 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/assets/defaultSettingsView-D-g2vrvf.js +184 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/assets/urlMatch-L3liM589.js +1 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/assets/xtermModule-B794rD2Z.js +7 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/codeMirrorModule.-QdMvsKi.css +1 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/codicon.DCmgc-ay.ttf +0 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/defaultSettingsView.C8BeHuxd.css +1 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/index.B_TqY17P.css +1 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/index.html +44 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/index.oNry3Hjv.js +1 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/manifest.webmanifest +16 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/playwright-logo.svg +9 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/snapshot.B_Jk1wbt.js +1 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/snapshot.html +10 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/sw.bundle.js +4 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/uiMode.CYwC_gH1.js +5 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/uiMode.CyMfwkXJ.css +1 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/uiMode.html +18 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/xtermModule.kHJ-D0s7.css +1 -0
- package/node_modules/playwright-core/lib/webp_codec.LICENSE +173 -0
- package/node_modules/playwright-core/lib/webp_codec.wasm +0 -0
- package/node_modules/playwright-core/lib/xdg-open +1267 -0
- package/node_modules/playwright-core/package.json +34 -0
- package/node_modules/playwright-core/types/protocol.d.ts +24776 -0
- package/node_modules/playwright-core/types/structs.d.ts +52 -0
- package/node_modules/playwright-core/types/types.d.ts +27167 -0
- package/package.json +30 -12
- package/plugin.mjs +1 -0
- package/server/contract.mjs +3 -3
- package/server/embedded-host.mjs +247 -0
- package/server/engine.mjs +1906 -115
- package/server/governor.mjs +189 -0
- package/server/http-utils.mjs +1 -1
- package/server/human.mjs +628 -0
- package/server/infra/http.mjs +2 -113
- package/server/infra/tuning.mjs +2 -82
- package/server/input.mjs +154 -0
- package/server/login-vault.mjs +109 -0
- package/server/mcp/handler.mjs +1 -1
- package/server/mcp/instructions.mjs +5 -2
- package/server/orphans.mjs +163 -0
- package/server/relay.mjs +160 -188
- package/server/routes/api.mjs +126 -13
- package/server/routes/assets.mjs +1 -1
- package/server/session-engines.mjs +184 -0
- package/server/shared/SHARED_MANIFEST.json +47 -24
- package/server/shared/asset-service.mjs +2 -217
- package/server/shared/editor-host.mjs +2 -125
- package/server/shared/kit/editor/lease.mjs +2 -139
- package/server/shared/kit/service/api.mjs +2 -45
- package/server/shared/kit/service/http.mjs +2 -113
- package/server/shared/kit/service/mcp-http.mjs +2 -142
- package/server/shared/kit/tools/validate.mjs +2 -115
- package/server/shared/kit/tuning.mjs +2 -82
- package/server/shared/kit/util/fs-lock.mjs +2 -132
- package/server/shared/service-host.mjs +2 -511
- package/server/shared/tool-host.mjs +2 -341
- package/server/shared/tuning.mjs +2 -63
- package/server/tools/capabilities/contract.mjs +25 -5
- package/server/tools/capabilities/interaction.mjs +113 -9
- package/server/tools/capabilities/navigation.mjs +5 -2
- package/server/tools/capabilities/screenshot.mjs +25 -8
- package/server/tools/capabilities/session.mjs +13 -7
- package/server/tools/capabilities/snapshot.mjs +1 -1
- package/server/tools/capabilities/tabs.mjs +2 -2
- package/server/tools/kernel/define.mjs +1 -1
- package/server/tools/kernel/output.mjs +8 -0
- package/server/tools/kernel/ports.mjs +12 -7
- package/server/tools/kernel/registry.mjs +1 -1
- package/server/workbench-framework.mjs +305 -0
- package/ui/app.js +409 -119
- package/ui/index.html +29 -39
- package/ui/style.css +131 -63
- package/cordis.patch.yml +0 -25
|
@@ -0,0 +1,656 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 文件关系中间层(Workspace / Catalog Manager)。
|
|
3
|
+
*
|
|
4
|
+
* 职责边界:
|
|
5
|
+
* BlobStore(store/blob-store.mjs):只存对象,不认识文件名、作品、归属。
|
|
6
|
+
* WorkspaceManager(本文件):解释“哪些对象属于同一个 work、谁能改、
|
|
7
|
+
* 版本是多少、什么时候过期”,并生成可给 UI/生命周期管理读取的 catalog。
|
|
8
|
+
*
|
|
9
|
+
* 同一个 runtime 内的多个会话共享同一个 work;不同 runtime 通过 namespace
|
|
10
|
+
* token 隔离。新建文件自动归入当前 work 的 manifest,不会串到别的 runtime。
|
|
11
|
+
*/
|
|
12
|
+
import crypto from 'node:crypto'
|
|
13
|
+
import fs from 'node:fs'
|
|
14
|
+
import path from 'node:path'
|
|
15
|
+
import { BlobStore } from '../store/blob-store.mjs'
|
|
16
|
+
import { timingSafeEqualText } from '../util/http.mjs'
|
|
17
|
+
import { readJson, withFileLock, writeJsonAtomic } from '../util/fs-lock.mjs'
|
|
18
|
+
import { tuning } from '../tuning.mjs'
|
|
19
|
+
|
|
20
|
+
const ID_RE = /^[a-z0-9][a-z0-9._-]{0,63}$/
|
|
21
|
+
const KEY_RE = /^(?!\/)(?!.*(?:^|\/)\.\.(?:\/|$))[A-Za-z0-9._@/+:-]{1,512}$/
|
|
22
|
+
|
|
23
|
+
export class WorkspaceConflictError extends Error {
|
|
24
|
+
constructor(message = '内容版本冲突') {
|
|
25
|
+
super(message)
|
|
26
|
+
this.name = 'WorkspaceConflictError'
|
|
27
|
+
this.code = 'ESTALE'
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class WorkspaceAccessError extends Error {
|
|
32
|
+
constructor(message = '没有访问该 runtime namespace 的权限') {
|
|
33
|
+
super(message)
|
|
34
|
+
this.name = 'WorkspaceAccessError'
|
|
35
|
+
this.code = 'EACCES'
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function assertId(value, label) {
|
|
40
|
+
if (typeof value !== 'string' || !ID_RE.test(value)) {
|
|
41
|
+
throw new Error(`${label} 必须是 1-64 位小写字母/数字/._-: ${value}`)
|
|
42
|
+
}
|
|
43
|
+
return value
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function assertKey(key) {
|
|
47
|
+
if (typeof key !== 'string' || !KEY_RE.test(key)) throw new Error(`对象 key 非法: ${key}`)
|
|
48
|
+
if (key === 'manifest.json') throw new Error('manifest.json 是中间层保留 key')
|
|
49
|
+
return key
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function hashToken(token) {
|
|
53
|
+
return crypto.createHash('sha256').update(String(token)).digest('hex')
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function safeEqualHex(left, right) {
|
|
57
|
+
return timingSafeEqualText(left, right)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export class NamespaceRegistry {
|
|
61
|
+
constructor({ storeRoot }) {
|
|
62
|
+
this.storeRoot = path.resolve(storeRoot)
|
|
63
|
+
this.dir = path.join(this.storeRoot, 'namespaces')
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
file(runtimeId) {
|
|
67
|
+
return path.join(this.dir, `${assertId(runtimeId, 'runtimeId')}.json`)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
create(runtimeId, { token, ttlSec = 0, quotaBytes = 0, meta = {} } = {}) {
|
|
71
|
+
assertId(runtimeId, 'runtimeId')
|
|
72
|
+
fs.mkdirSync(this.dir, { recursive: true })
|
|
73
|
+
const secret = token || crypto.randomBytes(32).toString('hex')
|
|
74
|
+
const now = new Date().toISOString()
|
|
75
|
+
const record = {
|
|
76
|
+
schemaVersion: 1,
|
|
77
|
+
runtimeId,
|
|
78
|
+
tokenHash: hashToken(secret),
|
|
79
|
+
status: 'active',
|
|
80
|
+
createdAt: now,
|
|
81
|
+
lastAccessAt: now,
|
|
82
|
+
ttlSec: Number(ttlSec) || 0,
|
|
83
|
+
quotaBytes: Number(quotaBytes) || 0,
|
|
84
|
+
meta: meta && typeof meta === 'object' ? meta : {},
|
|
85
|
+
}
|
|
86
|
+
writeJsonAtomic(this.file(runtimeId), record)
|
|
87
|
+
return { runtimeId, token: secret, record }
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
read(runtimeId) {
|
|
91
|
+
return readJson(this.file(runtimeId), null)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
verify(runtimeId, token) {
|
|
95
|
+
const record = this.read(runtimeId)
|
|
96
|
+
if (!record || record.status !== 'active') throw new WorkspaceAccessError()
|
|
97
|
+
if (!safeEqualHex(record.tokenHash, hashToken(token))) throw new WorkspaceAccessError()
|
|
98
|
+
if (record.ttlSec > 0) {
|
|
99
|
+
const last = Date.parse(record.lastAccessAt || record.createdAt)
|
|
100
|
+
if (Date.now() - last > record.ttlSec * 1000) throw new WorkspaceAccessError('运行时 namespace 已过期')
|
|
101
|
+
}
|
|
102
|
+
return record
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
touch(runtimeId) {
|
|
106
|
+
const record = this.read(runtimeId)
|
|
107
|
+
if (!record) return
|
|
108
|
+
record.lastAccessAt = new Date().toISOString()
|
|
109
|
+
writeJsonAtomic(this.file(runtimeId), record)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
remove(runtimeId) {
|
|
113
|
+
fs.rmSync(this.file(runtimeId), { force: true })
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export class WorkspaceManager {
|
|
118
|
+
/* journalMaxBytes 默认 512KB:与 JournalStore / FileStateBackend 的进化固化值
|
|
119
|
+
* 保持一致(同构机制:原子 state + journal 轮转),尾读更快、磁盘更省。 */
|
|
120
|
+
constructor({ storeRoot, blobStore = null, journalMaxBytes = 512 * 1024 }) {
|
|
121
|
+
if (!storeRoot) throw new Error('WorkspaceManager 需要 storeRoot')
|
|
122
|
+
this.storeRoot = path.resolve(storeRoot)
|
|
123
|
+
this.blobs = blobStore || new BlobStore({ root: this.storeRoot }).init()
|
|
124
|
+
this.namespaces = new NamespaceRegistry({ storeRoot: this.storeRoot })
|
|
125
|
+
this.worksRoot = path.join(this.storeRoot, 'workspaces')
|
|
126
|
+
this.catalogFile = path.join(this.storeRoot, 'catalog', 'works.json')
|
|
127
|
+
this.locksRoot = path.join(this.storeRoot, 'locks')
|
|
128
|
+
this.journalMaxBytes = Math.max(64 * 1024, Number(journalMaxBytes) || 512 * 1024)
|
|
129
|
+
this._catalogTouched = new Map()
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
init() {
|
|
133
|
+
fs.mkdirSync(this.worksRoot, { recursive: true })
|
|
134
|
+
fs.mkdirSync(path.join(this.storeRoot, 'catalog'), { recursive: true })
|
|
135
|
+
fs.mkdirSync(this.locksRoot, { recursive: true })
|
|
136
|
+
return this
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
workDir(runtimeId, workId) {
|
|
140
|
+
return path.join(this.worksRoot, assertId(runtimeId, 'runtimeId'), assertId(workId, 'workId'))
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
manifestFile(runtimeId, workId) {
|
|
144
|
+
return path.join(this.workDir(runtimeId, workId), 'manifest.json')
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
lockFile(kind, runtimeId, workId = '') {
|
|
148
|
+
const parts = [assertId(runtimeId, 'runtimeId'), workId ? assertId(workId, 'workId') : ''].filter(Boolean)
|
|
149
|
+
return path.join(this.locksRoot, kind, ...parts) + '.lock'
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
emptyManifest(runtimeId, workId, title = '') {
|
|
153
|
+
const now = new Date().toISOString()
|
|
154
|
+
return {
|
|
155
|
+
schemaVersion: 1,
|
|
156
|
+
runtimeId,
|
|
157
|
+
workId,
|
|
158
|
+
title: title || workId,
|
|
159
|
+
createdAt: now,
|
|
160
|
+
updatedAt: now,
|
|
161
|
+
version: 0,
|
|
162
|
+
/* 中间层声明:这个 work 管哪些逻辑文件;allowNew 控制新 key 是否自动归属。 */
|
|
163
|
+
declaration: {
|
|
164
|
+
files: ['**'],
|
|
165
|
+
allowNew: true,
|
|
166
|
+
updatedAt: now,
|
|
167
|
+
},
|
|
168
|
+
files: {},
|
|
169
|
+
meta: {},
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* 中间层声明一个 work 的文件范围。
|
|
175
|
+
* files 支持精确 key、目录前缀(以 / 结尾)和 /** 前缀通配。
|
|
176
|
+
* 声明本身不增加内容版本号;内容写入才增加 version。
|
|
177
|
+
*/
|
|
178
|
+
declareWork(runtimeId, workId, { files = ['**'], allowNew = true, title = '', meta = {} } = {}) {
|
|
179
|
+
assertId(runtimeId, 'runtimeId')
|
|
180
|
+
assertId(workId, 'workId')
|
|
181
|
+
if (!Array.isArray(files) || files.length === 0 || files.some((item) => typeof item !== 'string' || !item)) {
|
|
182
|
+
throw new Error('declaration.files 必须是非空字符串数组')
|
|
183
|
+
}
|
|
184
|
+
return withFileLock(this.lockFile('works', runtimeId, workId), () => {
|
|
185
|
+
const manifest = this.readManifest(runtimeId, workId) || this.emptyManifest(runtimeId, workId, title)
|
|
186
|
+
manifest.title = title || manifest.title || workId
|
|
187
|
+
manifest.declaration = {
|
|
188
|
+
files: [...new Set(files)],
|
|
189
|
+
allowNew: !!allowNew,
|
|
190
|
+
updatedAt: new Date().toISOString(),
|
|
191
|
+
}
|
|
192
|
+
if (meta && typeof meta === 'object') manifest.meta = { ...(manifest.meta || {}), ...meta }
|
|
193
|
+
manifest.updatedAt = new Date().toISOString()
|
|
194
|
+
this.writeManifest(manifest, { catalog: true })
|
|
195
|
+
return manifest
|
|
196
|
+
})
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
assertDeclared(manifest, key) {
|
|
200
|
+
const declaration = manifest?.declaration
|
|
201
|
+
if (!declaration || !Array.isArray(declaration.files) || declaration.files.length === 0) return true
|
|
202
|
+
const matched = declaration.files.some((pattern) => {
|
|
203
|
+
if (pattern === '*' || pattern === '**') return true
|
|
204
|
+
if (pattern.endsWith('/**')) return key.startsWith(pattern.slice(0, -2))
|
|
205
|
+
if (pattern.endsWith('/')) return key.startsWith(pattern)
|
|
206
|
+
return key === pattern
|
|
207
|
+
})
|
|
208
|
+
if (matched) return true
|
|
209
|
+
if (declaration.allowNew) return true
|
|
210
|
+
throw new WorkspaceAccessError(`文件 ${key} 不在 work ${manifest.workId} 的声明范围内`)
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
readManifest(runtimeId, workId) {
|
|
214
|
+
return readJson(this.manifestFile(runtimeId, workId), null)
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
writeManifest(manifest, { catalog = false } = {}) {
|
|
218
|
+
writeJsonAtomic(this.manifestFile(manifest.runtimeId, manifest.workId), manifest)
|
|
219
|
+
const key = `${manifest.runtimeId}/${manifest.workId}`
|
|
220
|
+
const last = this._catalogTouched.get(key) || 0
|
|
221
|
+
/* catalog 是展示/生命周期索引,不是热路径事务日志:按节流间隔写一次,
|
|
222
|
+
* 或在少数版本节点/显式操作时刷新,避免每次 state 保存都抢全局 catalog 锁。 */
|
|
223
|
+
if (catalog || manifest.version <= 5 || manifest.version % 50 === 0 || Date.now() - last > tuning().catalogThrottleMs) {
|
|
224
|
+
this.updateCatalog(manifest)
|
|
225
|
+
this._catalogTouched.set(key, Date.now())
|
|
226
|
+
}
|
|
227
|
+
return manifest
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** catalog 损坏时按磁盘 manifest 重建,绝不能把坏文件当成空库覆盖。 */
|
|
231
|
+
_readCatalogForUpdate() {
|
|
232
|
+
try {
|
|
233
|
+
const parsed = JSON.parse(fs.readFileSync(this.catalogFile, 'utf8'))
|
|
234
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) return parsed
|
|
235
|
+
} catch (error) {
|
|
236
|
+
if (error.code !== 'ENOENT') {
|
|
237
|
+
const quarantine = `${this.catalogFile}.corrupt-${Date.now()}`
|
|
238
|
+
try { fs.renameSync(this.catalogFile, quarantine) } catch { /* 忽略 */ }
|
|
239
|
+
console.error(`[workspace] catalog 损坏,已隔离到 ${quarantine},按 manifest 重建`)
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
const works = {}
|
|
243
|
+
let runtimes = []
|
|
244
|
+
try { runtimes = fs.readdirSync(this.worksRoot, { withFileTypes: true }).filter((e) => e.isDirectory()) } catch { /* 空库 */ }
|
|
245
|
+
for (const runtime of runtimes) {
|
|
246
|
+
let entries = []
|
|
247
|
+
try { entries = fs.readdirSync(path.join(this.worksRoot, runtime.name), { withFileTypes: true }) } catch { continue }
|
|
248
|
+
for (const entry of entries) {
|
|
249
|
+
if (!entry.isDirectory()) continue
|
|
250
|
+
const manifest = this.readManifest(runtime.name, entry.name)
|
|
251
|
+
if (!manifest) continue
|
|
252
|
+
const total = Object.values(manifest.files || {}).reduce((sum, item) => sum + (Number(item.size) || 0), 0)
|
|
253
|
+
works[`${manifest.runtimeId}/${manifest.workId}`] = {
|
|
254
|
+
runtimeId: manifest.runtimeId,
|
|
255
|
+
workId: manifest.workId,
|
|
256
|
+
title: manifest.title || '',
|
|
257
|
+
version: manifest.version || 0,
|
|
258
|
+
files: Object.keys(manifest.files || {}).length,
|
|
259
|
+
size: total,
|
|
260
|
+
createdAt: manifest.createdAt,
|
|
261
|
+
updatedAt: manifest.updatedAt,
|
|
262
|
+
declaration: manifest.declaration || null,
|
|
263
|
+
meta: manifest.meta || {},
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return { schemaVersion: 1, updatedAt: '', works }
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
updateCatalog(manifest) {
|
|
271
|
+
withFileLock(path.join(this.locksRoot, 'catalog.lock'), () => {
|
|
272
|
+
const catalog = this._readCatalogForUpdate()
|
|
273
|
+
const total = Object.values(manifest.files || {}).reduce((sum, item) => sum + (Number(item.size) || 0), 0)
|
|
274
|
+
catalog.works ||= {}
|
|
275
|
+
catalog.works[`${manifest.runtimeId}/${manifest.workId}`] = {
|
|
276
|
+
runtimeId: manifest.runtimeId,
|
|
277
|
+
workId: manifest.workId,
|
|
278
|
+
title: manifest.title || '',
|
|
279
|
+
version: manifest.version || 0,
|
|
280
|
+
files: Object.keys(manifest.files || {}).length,
|
|
281
|
+
size: total,
|
|
282
|
+
createdAt: manifest.createdAt,
|
|
283
|
+
updatedAt: manifest.updatedAt,
|
|
284
|
+
declaration: manifest.declaration || null,
|
|
285
|
+
meta: manifest.meta || {},
|
|
286
|
+
}
|
|
287
|
+
catalog.updatedAt = new Date().toISOString()
|
|
288
|
+
writeJsonAtomic(this.catalogFile, catalog)
|
|
289
|
+
})
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
ensureWork(runtimeId, workId, { title = '', meta = {} } = {}) {
|
|
293
|
+
assertId(runtimeId, 'runtimeId')
|
|
294
|
+
assertId(workId, 'workId')
|
|
295
|
+
const file = this.manifestFile(runtimeId, workId)
|
|
296
|
+
if (fs.existsSync(file)) return this.readManifest(runtimeId, workId)
|
|
297
|
+
return withFileLock(this.lockFile('works', runtimeId, workId), () => {
|
|
298
|
+
/* 双重检查:两个实例同时初始化同一 work 时只允许一个写 v0。 */
|
|
299
|
+
if (fs.existsSync(file)) return this.readManifest(runtimeId, workId)
|
|
300
|
+
const manifest = this.emptyManifest(runtimeId, workId, title)
|
|
301
|
+
manifest.meta = meta && typeof meta === 'object' ? meta : {}
|
|
302
|
+
return this.writeManifest(manifest, { catalog: true })
|
|
303
|
+
})
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/** 中间层解释逻辑 key → 对象 hash;仓库只收到字节。 */
|
|
307
|
+
put(runtimeId, workId, key, data, { expectedVersion = null, contentType = 'application/octet-stream', title = '' } = {}) {
|
|
308
|
+
assertKey(key)
|
|
309
|
+
this.ensureWork(runtimeId, workId, { title })
|
|
310
|
+
return withFileLock(this.lockFile('works', runtimeId, workId), () => {
|
|
311
|
+
const manifest = this.readManifest(runtimeId, workId) || this.emptyManifest(runtimeId, workId, title)
|
|
312
|
+
if (expectedVersion != null && Number(expectedVersion) !== manifest.version) {
|
|
313
|
+
throw new WorkspaceConflictError(`版本冲突: 当前 ${manifest.version},期望 ${expectedVersion}`)
|
|
314
|
+
}
|
|
315
|
+
this.assertDeclared(manifest, key)
|
|
316
|
+
const blob = this.blobs.put(data)
|
|
317
|
+
const now = new Date().toISOString()
|
|
318
|
+
manifest.files[key] = {
|
|
319
|
+
blob: blob.hash,
|
|
320
|
+
size: blob.size,
|
|
321
|
+
contentType,
|
|
322
|
+
updatedAt: now,
|
|
323
|
+
}
|
|
324
|
+
manifest.version = (manifest.version | 0) + 1
|
|
325
|
+
manifest.updatedAt = now
|
|
326
|
+
if (title) manifest.title = title
|
|
327
|
+
this.writeManifest(manifest)
|
|
328
|
+
return { key, blob: blob.hash, size: blob.size, version: manifest.version }
|
|
329
|
+
})
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
get(runtimeId, workId, key, fallback = undefined) {
|
|
333
|
+
assertKey(key)
|
|
334
|
+
const manifest = this.readManifest(runtimeId, workId)
|
|
335
|
+
if (!manifest || !manifest.files[key]) {
|
|
336
|
+
if (fallback !== undefined) return fallback
|
|
337
|
+
throw new Error(`对象不存在: ${runtimeId}/${workId}/${key}`)
|
|
338
|
+
}
|
|
339
|
+
return this.blobs.get(manifest.files[key].blob)
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
list(runtimeId, workId) {
|
|
343
|
+
const manifest = this.readManifest(runtimeId, workId)
|
|
344
|
+
return manifest ? Object.entries(manifest.files).map(([key, item]) => ({ key, ...item })) : []
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
delete(runtimeId, workId, key, { expectedVersion = null } = {}) {
|
|
348
|
+
assertKey(key)
|
|
349
|
+
return withFileLock(this.lockFile('works', runtimeId, workId), () => {
|
|
350
|
+
const manifest = this.readManifest(runtimeId, workId)
|
|
351
|
+
if (!manifest) throw new Error(`work 不存在: ${runtimeId}/${workId}`)
|
|
352
|
+
if (expectedVersion != null && Number(expectedVersion) !== manifest.version) {
|
|
353
|
+
throw new WorkspaceConflictError(`版本冲突: 当前 ${manifest.version},期望 ${expectedVersion}`)
|
|
354
|
+
}
|
|
355
|
+
this.assertDeclared(manifest, key)
|
|
356
|
+
delete manifest.files[key]
|
|
357
|
+
manifest.version = (manifest.version | 0) + 1
|
|
358
|
+
manifest.updatedAt = new Date().toISOString()
|
|
359
|
+
this.writeManifest(manifest, { catalog: true })
|
|
360
|
+
return { key, version: manifest.version }
|
|
361
|
+
})
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
append(runtimeId, workId, key, text) {
|
|
365
|
+
assertKey(key)
|
|
366
|
+
return withFileLock(this.lockFile('works', runtimeId, workId), () => {
|
|
367
|
+
const manifest = this.readManifest(runtimeId, workId) || this.emptyManifest(runtimeId, workId)
|
|
368
|
+
this.assertDeclared(manifest, key)
|
|
369
|
+
const now = new Date().toISOString()
|
|
370
|
+
let current = Buffer.alloc(0)
|
|
371
|
+
if (manifest.files[key]) current = this.blobs.get(manifest.files[key].blob)
|
|
372
|
+
const extra = Buffer.from(text)
|
|
373
|
+
/* journal 单文件超过阈值时轮转到 .1,避免每次 append 重写无上限增长的历史。 */
|
|
374
|
+
if (key === 'journal.jsonl' && current.length && current.length + extra.length > this.journalMaxBytes) {
|
|
375
|
+
const rotated = this.blobs.put(current)
|
|
376
|
+
manifest.files['journal.jsonl.1'] = {
|
|
377
|
+
blob: rotated.hash,
|
|
378
|
+
size: rotated.size,
|
|
379
|
+
contentType: 'text/plain; charset=utf-8',
|
|
380
|
+
updatedAt: now,
|
|
381
|
+
}
|
|
382
|
+
current = Buffer.alloc(0)
|
|
383
|
+
}
|
|
384
|
+
const blob = this.blobs.put(Buffer.concat([current, extra]))
|
|
385
|
+
manifest.files[key] = {
|
|
386
|
+
blob: blob.hash,
|
|
387
|
+
size: blob.size,
|
|
388
|
+
contentType: 'text/plain; charset=utf-8',
|
|
389
|
+
updatedAt: now,
|
|
390
|
+
}
|
|
391
|
+
manifest.version = (manifest.version | 0) + 1
|
|
392
|
+
manifest.updatedAt = now
|
|
393
|
+
this.writeManifest(manifest)
|
|
394
|
+
return { key, blob: blob.hash, size: blob.size, version: manifest.version }
|
|
395
|
+
})
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
tail(runtimeId, workId, key, limit = 8) {
|
|
399
|
+
try {
|
|
400
|
+
const text = this.get(runtimeId, workId, key).toString('utf8').trim()
|
|
401
|
+
if (!text) return []
|
|
402
|
+
return text.split(/\r?\n/).filter(Boolean).slice(-limit).map((line) => {
|
|
403
|
+
try { return JSON.parse(line) } catch { return { type: 'invalid', raw: line.slice(0, 120) } }
|
|
404
|
+
})
|
|
405
|
+
} catch {
|
|
406
|
+
return []
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/** 从磁盘 manifest 重建 catalog;用于 CLI/UI 读取前刷新最终一致性索引。 */
|
|
411
|
+
refreshCatalog({ runtimeId = '' } = {}) {
|
|
412
|
+
const works = []
|
|
413
|
+
let runtimes = []
|
|
414
|
+
try { runtimes = fs.readdirSync(this.worksRoot, { withFileTypes: true }).filter((e) => e.isDirectory()) } catch { return works }
|
|
415
|
+
for (const runtime of runtimes) {
|
|
416
|
+
if (runtimeId && runtime.name !== runtimeId) continue
|
|
417
|
+
let entries = []
|
|
418
|
+
try { entries = fs.readdirSync(path.join(this.worksRoot, runtime.name), { withFileTypes: true }) } catch { continue }
|
|
419
|
+
for (const entry of entries) {
|
|
420
|
+
if (!entry.isDirectory()) continue
|
|
421
|
+
const manifest = this.readManifest(runtime.name, entry.name)
|
|
422
|
+
if (!manifest) continue
|
|
423
|
+
this.updateCatalog(manifest)
|
|
424
|
+
works.push(manifest)
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
return works
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
listWorks({ runtimeId = '' } = {}) {
|
|
431
|
+
const catalog = readJson(this.catalogFile, null)
|
|
432
|
+
if (catalog && catalog.works) {
|
|
433
|
+
return Object.values(catalog.works)
|
|
434
|
+
.filter((item) => !runtimeId || item.runtimeId === runtimeId)
|
|
435
|
+
.sort((a, b) => String(b.updatedAt).localeCompare(String(a.updatedAt)))
|
|
436
|
+
}
|
|
437
|
+
const works = []
|
|
438
|
+
let runtimes = []
|
|
439
|
+
try { runtimes = fs.readdirSync(this.worksRoot, { withFileTypes: true }).filter((e) => e.isDirectory()) } catch { /* 空库 */ }
|
|
440
|
+
for (const runtime of runtimes) {
|
|
441
|
+
if (runtimeId && runtime.name !== runtimeId) continue
|
|
442
|
+
let entries = []
|
|
443
|
+
try { entries = fs.readdirSync(path.join(this.worksRoot, runtime.name), { withFileTypes: true }) } catch { /* 忽略 */ }
|
|
444
|
+
for (const entry of entries) {
|
|
445
|
+
if (!entry.isDirectory()) continue
|
|
446
|
+
const manifest = this.readManifest(runtime.name, entry.name)
|
|
447
|
+
if (manifest) works.push(manifest)
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
return works
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
referencedHashes() {
|
|
454
|
+
const referenced = new Set()
|
|
455
|
+
for (const summary of this.listWorks()) {
|
|
456
|
+
const manifest = this.readManifest(summary.runtimeId, summary.workId)
|
|
457
|
+
for (const item of Object.values(manifest?.files || {})) if (item?.blob) referenced.add(item.blob)
|
|
458
|
+
}
|
|
459
|
+
return referenced
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
gc({ minAgeMs = 60000 } = {}) {
|
|
463
|
+
return withFileLock(path.join(this.locksRoot, 'gc.lock'), () => {
|
|
464
|
+
/* 刚写入的 blob 可能还没写进 manifest;留出宽限期防止 GC 与 put 竞态。 */
|
|
465
|
+
return this.blobs.gc(this.referencedHashes(), { minAgeMs })
|
|
466
|
+
})
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
removeWork(runtimeId, workId) {
|
|
470
|
+
fs.rmSync(this.workDir(runtimeId, workId), { recursive: true, force: true })
|
|
471
|
+
withFileLock(path.join(this.locksRoot, 'catalog.lock'), () => {
|
|
472
|
+
const catalog = this._readCatalogForUpdate()
|
|
473
|
+
delete catalog.works?.[`${runtimeId}/${workId}`]
|
|
474
|
+
catalog.updatedAt = new Date().toISOString()
|
|
475
|
+
writeJsonAtomic(this.catalogFile, catalog)
|
|
476
|
+
})
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
removeRuntime(runtimeId) {
|
|
480
|
+
assertId(runtimeId, 'runtimeId')
|
|
481
|
+
fs.rmSync(path.join(this.worksRoot, runtimeId), { recursive: true, force: true })
|
|
482
|
+
this.namespaces.remove(runtimeId)
|
|
483
|
+
withFileLock(path.join(this.locksRoot, 'catalog.lock'), () => {
|
|
484
|
+
const catalog = this._readCatalogForUpdate()
|
|
485
|
+
for (const key of Object.keys(catalog.works || {})) {
|
|
486
|
+
if (key.startsWith(`${runtimeId}/`)) delete catalog.works[key]
|
|
487
|
+
}
|
|
488
|
+
catalog.updatedAt = new Date().toISOString()
|
|
489
|
+
writeJsonAtomic(this.catalogFile, catalog)
|
|
490
|
+
})
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/** 绑定到单个 runtime / work 的客户端;每次操作校验 namespace token。 */
|
|
495
|
+
export class WorkspaceClient {
|
|
496
|
+
constructor({ manager, runtimeId, token, workId = 'main' } = {}) {
|
|
497
|
+
/* 结构化契约:允许同版本 kit 快照跨包提供 manager,不依赖类身份。 */
|
|
498
|
+
if (!manager || typeof manager.put !== 'function' || typeof manager.readManifest !== 'function') {
|
|
499
|
+
throw new Error('WorkspaceClient 需要 WorkspaceManager 兼容实现')
|
|
500
|
+
}
|
|
501
|
+
this.manager = manager
|
|
502
|
+
this.runtimeId = assertId(runtimeId, 'runtimeId')
|
|
503
|
+
this.token = token
|
|
504
|
+
this.workId = assertId(workId, 'workId')
|
|
505
|
+
this._verifiedAt = 0
|
|
506
|
+
this._verify(true)
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
_verify(force = false) {
|
|
510
|
+
const now = Date.now()
|
|
511
|
+
if (!force && this._verifiedAt && now - this._verifiedAt < tuning().tokenVerifyCacheMs) return
|
|
512
|
+
this.manager.namespaces.verify(this.runtimeId, this.token)
|
|
513
|
+
this.manager.namespaces.touch(this.runtimeId)
|
|
514
|
+
this._verifiedAt = now
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
ensureWork(workId = this.workId, options = {}) {
|
|
518
|
+
this._verify()
|
|
519
|
+
return this.manager.ensureWork(this.runtimeId, workId, options)
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
put(workId, key, data, options = {}) {
|
|
523
|
+
this._verify()
|
|
524
|
+
return this.manager.put(this.runtimeId, workId, key, data, options)
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
putJson(workId, key, value, options = {}) {
|
|
528
|
+
return this.put(workId, key, Buffer.from(JSON.stringify(value)), {
|
|
529
|
+
contentType: 'application/json; charset=utf-8',
|
|
530
|
+
...options,
|
|
531
|
+
})
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
get(workId, key, fallback = undefined) {
|
|
535
|
+
this._verify()
|
|
536
|
+
return this.manager.get(this.runtimeId, workId, key, fallback)
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
getJson(workId, key, fallback = undefined) {
|
|
540
|
+
const data = this.get(workId, key, fallback === undefined ? undefined : Buffer.from(JSON.stringify(fallback)))
|
|
541
|
+
if (data === undefined) return undefined
|
|
542
|
+
try { return JSON.parse(data.toString('utf8')) } catch { return fallback }
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
list(workId) {
|
|
546
|
+
this._verify()
|
|
547
|
+
return this.manager.list(this.runtimeId, workId)
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
delete(workId, key, options = {}) {
|
|
551
|
+
this._verify()
|
|
552
|
+
return this.manager.delete(this.runtimeId, workId, key, options)
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
append(workId, key, text) {
|
|
556
|
+
this._verify()
|
|
557
|
+
return this.manager.append(this.runtimeId, workId, key, text)
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
tail(workId, key, limit = 8) {
|
|
561
|
+
this._verify()
|
|
562
|
+
return this.manager.tail(this.runtimeId, workId, key, limit)
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
manifest(workId = this.workId) {
|
|
566
|
+
this._verify()
|
|
567
|
+
return this.manager.readManifest(this.runtimeId, workId)
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
listWorks() {
|
|
571
|
+
this._verify()
|
|
572
|
+
return this.manager.listWorks({ runtimeId: this.runtimeId })
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/** 插件的 JournalStore 持久化接口 → 中间层 workspace。 */
|
|
577
|
+
export class WorkspaceBackend {
|
|
578
|
+
constructor({ client, workId = 'main', journalPath = null }) {
|
|
579
|
+
/* 结构化契约:workspace-service 可能来自另一份 kit 快照。 */
|
|
580
|
+
if (!client || typeof client.put !== 'function' || typeof client.getJson !== 'function') {
|
|
581
|
+
throw new Error('WorkspaceBackend 需要 WorkspaceClient 兼容实现')
|
|
582
|
+
}
|
|
583
|
+
this.client = client
|
|
584
|
+
this.workId = workId
|
|
585
|
+
this.journalPath = journalPath || null
|
|
586
|
+
this.stateKey = 'state.json'
|
|
587
|
+
this.journalKey = 'journal.jsonl'
|
|
588
|
+
this.checkpointPrefix = 'checkpoints/'
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
readState() {
|
|
592
|
+
return this.client.getJson(this.workId, this.stateKey, null)
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
writeState(doc) {
|
|
596
|
+
const result = this.client.putJson(this.workId, this.stateKey, doc)
|
|
597
|
+
return { ...result, stateKey: this.stateKey }
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
appendJournal(event) {
|
|
601
|
+
try {
|
|
602
|
+
this.client.append(this.workId, this.journalKey, JSON.stringify({ ...event, ts: Date.now() / 1000 }) + '\n')
|
|
603
|
+
} catch { /* journal 失败不阻塞主状态 */ }
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
journalTail(limit = 8) {
|
|
607
|
+
const parse = (text) => String(text || '').trim().split(/\r?\n/).filter(Boolean)
|
|
608
|
+
const lines = []
|
|
609
|
+
for (const key of ['journal.jsonl.1', 'journal.jsonl']) {
|
|
610
|
+
try {
|
|
611
|
+
const data = this.client.get(this.workId, key, null)
|
|
612
|
+
if (data) lines.push(...parse(data.toString('utf8')))
|
|
613
|
+
} catch { /* 轮转文件可能不存在 */ }
|
|
614
|
+
}
|
|
615
|
+
return lines.slice(-limit).map((line) => {
|
|
616
|
+
try { return JSON.parse(line) } catch { return { type: 'invalid', raw: line.slice(0, 120) } }
|
|
617
|
+
})
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
writeCheckpoint(name, payload) {
|
|
621
|
+
const key = `${this.checkpointPrefix}${name}.json`
|
|
622
|
+
this.client.putJson(this.workId, key, payload)
|
|
623
|
+
this.appendJournal({ type: 'checkpoint', name })
|
|
624
|
+
return { name, createdAt: payload.createdAt, meta: payload.meta || {} }
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
listCheckpoints() {
|
|
628
|
+
return this.client.list(this.workId)
|
|
629
|
+
.filter((item) => item.key.startsWith(this.checkpointPrefix) && item.key.endsWith('.json'))
|
|
630
|
+
.map((item) => {
|
|
631
|
+
try {
|
|
632
|
+
const payload = this.client.getJson(this.workId, item.key)
|
|
633
|
+
if (!payload) return null
|
|
634
|
+
return {
|
|
635
|
+
name: payload.name,
|
|
636
|
+
seq: payload.seq,
|
|
637
|
+
appliedSeq: payload.appliedSeq,
|
|
638
|
+
pending: !!payload.pending,
|
|
639
|
+
title: payload.title,
|
|
640
|
+
slides: payload.slides,
|
|
641
|
+
createdAt: payload.createdAt,
|
|
642
|
+
meta: payload.meta || {},
|
|
643
|
+
}
|
|
644
|
+
} catch { return null }
|
|
645
|
+
})
|
|
646
|
+
.filter(Boolean)
|
|
647
|
+
.sort((a, b) => String(b.createdAt).localeCompare(String(a.createdAt)))
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
readCheckpoint(name) {
|
|
651
|
+
const key = `${this.checkpointPrefix}${name}.json`
|
|
652
|
+
const payload = this.client.getJson(this.workId, key, null)
|
|
653
|
+
if (!payload || !payload.deck) throw new Error('checkpoint 内容损坏: ' + name)
|
|
654
|
+
return payload
|
|
655
|
+
}
|
|
656
|
+
}
|