@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,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 版本化文档会话的标准信封与纯状态迁移。
|
|
3
|
+
*
|
|
4
|
+
* 这层只认识 seq/cmds/ack/state/ui/shot/owner 这些协议字段;领域文档放在
|
|
5
|
+
* 调用方指定的 documentKey 下,由 adapter 负责解释。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export const SESSION_DEFAULTS = Object.freeze({
|
|
9
|
+
seq: 0,
|
|
10
|
+
cmds: [],
|
|
11
|
+
title: '',
|
|
12
|
+
applied_seq: 0,
|
|
13
|
+
applied: 0,
|
|
14
|
+
error: '',
|
|
15
|
+
updated: 0,
|
|
16
|
+
pending_since: 0,
|
|
17
|
+
state_seq: 0,
|
|
18
|
+
ui_seq: 0,
|
|
19
|
+
ui: [],
|
|
20
|
+
shot_req: 0,
|
|
21
|
+
shot: { req: 0, data: '' },
|
|
22
|
+
/* 截图渲染选项:跟请求一起送到编辑器(通用渲染参数,不认识就忽略)。 */
|
|
23
|
+
shot_opts: null,
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
export function nowSeconds() {
|
|
27
|
+
return Date.now() / 1000
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** 创建一份带标准信封的会话状态;initial 可携带领域字段(deck/doc/value)。 */
|
|
31
|
+
export function createSessionState(initial = {}) {
|
|
32
|
+
const source = initial && typeof initial === 'object' ? initial : {}
|
|
33
|
+
return {
|
|
34
|
+
...structuredClone(SESSION_DEFAULTS),
|
|
35
|
+
...structuredClone(source),
|
|
36
|
+
cmds: Array.isArray(source.cmds) ? structuredClone(source.cmds) : [],
|
|
37
|
+
ui: Array.isArray(source.ui) ? structuredClone(source.ui) : [],
|
|
38
|
+
shot: { ...SESSION_DEFAULTS.shot, ...(source.shot || {}) },
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function optionsOf(nowOrOptions) {
|
|
43
|
+
return typeof nowOrOptions === 'number' ? { now: nowOrOptions } : (nowOrOptions || {})
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** 新批次入队:seq 自增,清空上批回执,保留领域文档。 */
|
|
47
|
+
export function applyPush(doc, cmds, title, nowOrOptions = {}) {
|
|
48
|
+
const opts = optionsOf(nowOrOptions)
|
|
49
|
+
const now = opts.now ?? nowSeconds()
|
|
50
|
+
Object.assign(doc, {
|
|
51
|
+
seq: (doc.seq | 0) + 1,
|
|
52
|
+
cmds: Array.isArray(cmds) ? cmds : [],
|
|
53
|
+
title: title || '',
|
|
54
|
+
applied_seq: 0,
|
|
55
|
+
applied: 0,
|
|
56
|
+
error: '',
|
|
57
|
+
pending_since: now,
|
|
58
|
+
updated: now,
|
|
59
|
+
})
|
|
60
|
+
return doc
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** 服务端执行完成:只有当前批次可以落回执。 */
|
|
64
|
+
export function applyServer(doc, seq, applied, error, nowOrOptions = {}) {
|
|
65
|
+
const opts = optionsOf(nowOrOptions)
|
|
66
|
+
if ((doc.seq | 0) !== (seq | 0)) return doc
|
|
67
|
+
Object.assign(doc, {
|
|
68
|
+
applied_seq: seq,
|
|
69
|
+
applied: applied | 0,
|
|
70
|
+
error: error || '',
|
|
71
|
+
state_seq: seq,
|
|
72
|
+
pending_since: 0,
|
|
73
|
+
updated: opts.now ?? nowSeconds(),
|
|
74
|
+
})
|
|
75
|
+
if (typeof opts.onApplied === 'function') opts.onApplied(doc, seq)
|
|
76
|
+
if (opts.stateCompact !== false) doc.cmds = []
|
|
77
|
+
return doc
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** 编辑器回执:同样只接受当前批次。 */
|
|
81
|
+
export function applyAck(doc, seq, applied, error, nowOrOptions = {}) {
|
|
82
|
+
const opts = optionsOf(nowOrOptions)
|
|
83
|
+
if ((doc.seq | 0) !== (seq | 0)) return doc
|
|
84
|
+
Object.assign(doc, {
|
|
85
|
+
applied_seq: seq,
|
|
86
|
+
applied: applied | 0,
|
|
87
|
+
error: error || '',
|
|
88
|
+
pending_since: 0,
|
|
89
|
+
updated: opts.now ?? nowSeconds(),
|
|
90
|
+
})
|
|
91
|
+
return doc
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** 编辑器镜像:旧 seq 的镜像不能覆盖新文档。 */
|
|
95
|
+
export function applyState(doc, value, seq, nowOrOptions = {}) {
|
|
96
|
+
const opts = optionsOf(nowOrOptions)
|
|
97
|
+
if (seq != null && (seq | 0) < (doc.seq | 0)) return doc
|
|
98
|
+
const key = opts.documentKey || 'document'
|
|
99
|
+
doc[key] = value
|
|
100
|
+
if (seq != null) doc.state_seq = seq | 0
|
|
101
|
+
doc.updated = opts.now ?? nowSeconds()
|
|
102
|
+
return doc
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function applyUi(doc, cmds, nowOrOptions = {}) {
|
|
106
|
+
const opts = optionsOf(nowOrOptions)
|
|
107
|
+
doc.ui_seq = (doc.ui_seq | 0) + 1
|
|
108
|
+
doc.ui = Array.isArray(cmds) ? cmds : []
|
|
109
|
+
doc.updated = opts.now ?? nowSeconds()
|
|
110
|
+
return doc
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* 截图选项白名单:只放行通用渲染参数,其它键一律丢弃。
|
|
115
|
+
* 协议是「不认识就忽略」——老编辑器收不到也不会坏;新编辑器据此只渲染指定页。
|
|
116
|
+
*/
|
|
117
|
+
export function normalizeShotOpts(raw) {
|
|
118
|
+
if (!raw || typeof raw !== 'object') return null
|
|
119
|
+
const out = {}
|
|
120
|
+
const indices = Array.isArray(raw.indices)
|
|
121
|
+
? raw.indices
|
|
122
|
+
.map((n) => Number(n))
|
|
123
|
+
.filter((n) => Number.isInteger(n) && n >= 0)
|
|
124
|
+
.slice(0, 12)
|
|
125
|
+
: []
|
|
126
|
+
if (indices.length) out.indices = [...new Set(indices)]
|
|
127
|
+
const width = Number(raw.width)
|
|
128
|
+
if (Number.isFinite(width) && width > 0) out.width = Math.min(2400, Math.max(200, Math.round(width)))
|
|
129
|
+
const quality = Number(raw.quality)
|
|
130
|
+
if (Number.isFinite(quality) && quality > 0 && quality <= 1) out.quality = quality
|
|
131
|
+
if (typeof raw.format === 'string' && /^(png|jpe?g|webp)$/i.test(raw.format)) {
|
|
132
|
+
out.format = raw.format.toLowerCase() === 'jpg' ? 'jpeg' : raw.format.toLowerCase()
|
|
133
|
+
}
|
|
134
|
+
return Object.keys(out).length ? out : null
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function applyShotRequest(doc, opts = null, nowOrOptions = {}) {
|
|
138
|
+
const clock = optionsOf(nowOrOptions)
|
|
139
|
+
doc.shot_req = (doc.shot_req | 0) + 1
|
|
140
|
+
doc.shot = { req: 0, data: '' }
|
|
141
|
+
doc.shot_opts = normalizeShotOpts(opts)
|
|
142
|
+
doc.updated = clock.now ?? nowSeconds()
|
|
143
|
+
return doc
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function applyShotResult(doc, req, data, nowOrOptions = {}) {
|
|
147
|
+
const opts = optionsOf(nowOrOptions)
|
|
148
|
+
if ((doc.shot_req | 0) !== (req | 0)) return doc
|
|
149
|
+
doc.shot = { req, data: data || '' }
|
|
150
|
+
doc.updated = opts.now ?? nowSeconds()
|
|
151
|
+
return doc
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export function pendingOf(doc) {
|
|
155
|
+
if ((doc.seq | 0) > (doc.applied_seq | 0) && Array.isArray(doc.cmds) && doc.cmds.length) {
|
|
156
|
+
return { seq: doc.seq | 0, title: doc.title || '', cmds: doc.cmds }
|
|
157
|
+
}
|
|
158
|
+
return null
|
|
159
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/** 长轮询:seq / shot / ui 任一变化即返回。
|
|
2
|
+
*
|
|
3
|
+
* 唤醒双保险:session 带 subscribe(事件)时变化即时返回——轮询粒度不再
|
|
4
|
+
* 进入延迟路径;pollMs 定时器保留为兜底(事件丢失/老 session 无订阅面)。
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export function watchSession(session, {
|
|
8
|
+
seq = 0,
|
|
9
|
+
shot = 0,
|
|
10
|
+
ui = 0,
|
|
11
|
+
timeoutS,
|
|
12
|
+
isAborted = () => false,
|
|
13
|
+
pollMs = 75,
|
|
14
|
+
timeoutSec = 20,
|
|
15
|
+
maxTimeoutSec = 30,
|
|
16
|
+
} = {}) {
|
|
17
|
+
const poll = Math.max(10, Number(pollMs) || 75)
|
|
18
|
+
const maxTimeout = Math.max(1, Number(maxTimeoutSec) || 30)
|
|
19
|
+
const defaultTimeout = Math.max(1, Number(timeoutSec) || 20)
|
|
20
|
+
const timeout = Math.min(Math.max(Number(timeoutS) || defaultTimeout, 1), maxTimeout)
|
|
21
|
+
|
|
22
|
+
return new Promise((resolve) => {
|
|
23
|
+
const deadline = Date.now() + timeout * 1000
|
|
24
|
+
let settled = false
|
|
25
|
+
let timer = null
|
|
26
|
+
let unsubscribe = null
|
|
27
|
+
|
|
28
|
+
const finish = (value) => {
|
|
29
|
+
if (settled) return
|
|
30
|
+
settled = true
|
|
31
|
+
if (timer) clearTimeout(timer)
|
|
32
|
+
if (unsubscribe) {
|
|
33
|
+
try { unsubscribe() } catch { /* ignore */ }
|
|
34
|
+
}
|
|
35
|
+
resolve(value)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const changed = (doc) => (doc.seq | 0) !== (seq | 0)
|
|
39
|
+
|| (doc.shot_req | 0) !== (shot | 0)
|
|
40
|
+
|| (doc.ui_seq | 0) !== (ui | 0)
|
|
41
|
+
|
|
42
|
+
const check = () => {
|
|
43
|
+
if (isAborted()) return finish(null)
|
|
44
|
+
const doc = session.get()
|
|
45
|
+
if (changed(doc) || Date.now() > deadline) finish(doc)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/* 兜底轮询:事件路径正常时每次 tick 都是空检查(微秒级)。 */
|
|
49
|
+
const tick = () => {
|
|
50
|
+
if (settled) return
|
|
51
|
+
check()
|
|
52
|
+
if (!settled) timer = setTimeout(tick, poll)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (typeof session.subscribe === 'function') {
|
|
56
|
+
unsubscribe = session.subscribe(() => {
|
|
57
|
+
if (settled) return
|
|
58
|
+
check()
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
tick()
|
|
62
|
+
})
|
|
63
|
+
}
|
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 文档持久化后端:原子 JSON 状态 + append-only journal(可轮转)+ 命名 checkpoint。
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* - replayPending:崩溃后重放未完成批次
|
|
8
|
-
*
|
|
9
|
-
* 与 workspace-service 的分工:
|
|
10
|
-
* workspace 管“作品文件”(work manifest / 版本 / 归属);
|
|
11
|
-
* state 管“插件运行状态”(doc / journal / checkpoint / recovery)。
|
|
4
|
+
* 从 @capyclaw/state-service 移入 document-workbench:
|
|
5
|
+
* 桥的持久化是「文档会话」的一部分,不该让每个 workbench 都依赖 state 插件包。
|
|
6
|
+
* state-service 已于 2026-11-15 退役删包,这里是唯一实现源。
|
|
12
7
|
*/
|
|
13
8
|
import fs from 'node:fs'
|
|
14
9
|
import path from 'node:path'
|
|
15
|
-
import { createServiceApi } from '@capyclaw/plugin-kit/service/api'
|
|
16
10
|
|
|
17
11
|
export class FileStateBackend {
|
|
18
12
|
/* journalMaxBytes 默认 512KB 由 NSGA-II 进化搜索固化(evolution/,2026-11-01):
|
|
@@ -58,7 +52,7 @@ export class FileStateBackend {
|
|
|
58
52
|
this.lastStateError = { code: 'STATE_CORRUPT', message: error.message }
|
|
59
53
|
const quarantine = `${this.file}.corrupt-${Date.now()}`
|
|
60
54
|
try { fs.renameSync(this.file, quarantine) } catch { /* 隔离失败也要保持只读语义 */ }
|
|
61
|
-
console.error(`[
|
|
55
|
+
console.error(`[document-workbench] state 损坏,已隔离到 ${quarantine}: ${error.message}`)
|
|
62
56
|
return null
|
|
63
57
|
}
|
|
64
58
|
}
|
|
@@ -95,7 +89,7 @@ export class FileStateBackend {
|
|
|
95
89
|
const rotated = this.journalFile + '.1'
|
|
96
90
|
try { fs.rmSync(rotated, { force: true }) } catch { /* 忽略 */ }
|
|
97
91
|
try { fs.renameSync(this.journalFile, rotated) } catch (error) {
|
|
98
|
-
console.error('[
|
|
92
|
+
console.error('[document-workbench] journal 轮转失败(继续追加):', error.message)
|
|
99
93
|
}
|
|
100
94
|
}
|
|
101
95
|
} catch { /* journal 失败不阻塞主状态 */ }
|
|
@@ -162,88 +156,3 @@ export function checkpointName(name) {
|
|
|
162
156
|
if (!/^[a-zA-Z0-9._-]{1,64}$/.test(safe)) throw new Error('checkpoint 名称必须是 1-64 位字母/数字/._-')
|
|
163
157
|
return safe
|
|
164
158
|
}
|
|
165
|
-
|
|
166
|
-
/** 通用状态门面:业务 store 可以继承它,只写领域方法。 */
|
|
167
|
-
export class PersistentStore {
|
|
168
|
-
constructor({ backend, initialDoc = {} }) {
|
|
169
|
-
if (!backend) throw new Error('PersistentStore 需要 backend')
|
|
170
|
-
this.backend = backend
|
|
171
|
-
this.doc = backend.readState() || { ...structuredClone(initialDoc) }
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
get() { return this.doc }
|
|
175
|
-
|
|
176
|
-
save() {
|
|
177
|
-
this.backend.writeState(this.doc)
|
|
178
|
-
return this.doc
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
journal(event) {
|
|
182
|
-
this.backend.appendJournal(event)
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
journalTail(limit = 8) {
|
|
186
|
-
return this.backend.journalTail(limit)
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
checkpoint(name, payload, meta = {}) {
|
|
190
|
-
const safe = checkpointName(name)
|
|
191
|
-
const body = {
|
|
192
|
-
name: safe,
|
|
193
|
-
...payload,
|
|
194
|
-
meta: meta && typeof meta === 'object' ? meta : {},
|
|
195
|
-
createdAt: new Date().toISOString(),
|
|
196
|
-
}
|
|
197
|
-
this.backend.writeCheckpoint(safe, body)
|
|
198
|
-
this.journal({ type: 'checkpoint', name: safe })
|
|
199
|
-
return body
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
listCheckpoints() {
|
|
203
|
-
return this.backend.listCheckpoints()
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
readCheckpoint(name) {
|
|
207
|
-
return this.backend.readCheckpoint(name)
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* 崩溃恢复:把未完成批次交给 apply 重放,然后回执。
|
|
213
|
-
* @param {{ store: object, pending: () => any, apply: (cmd:any) => Promise<void>|void }} options
|
|
214
|
-
*/
|
|
215
|
-
export async function replayPending({ store, pending, apply }) {
|
|
216
|
-
const item = pending()
|
|
217
|
-
if (!item) return { recovered: 0, seq: 0, error: '' }
|
|
218
|
-
let recovered = 0
|
|
219
|
-
let error = ''
|
|
220
|
-
for (const cmd of item.cmds || []) {
|
|
221
|
-
try {
|
|
222
|
-
await apply(cmd)
|
|
223
|
-
recovered++
|
|
224
|
-
} catch (e) {
|
|
225
|
-
error = String((e && e.message) || e)
|
|
226
|
-
break
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
store.applyServer(item.seq, recovered, error)
|
|
230
|
-
return { seq: item.seq, recovered, error }
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
export function createFileBackend(file, options = {}) {
|
|
234
|
-
return new FileStateBackend(file, options)
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
export function createStateHost(config = {}) {
|
|
238
|
-
return {
|
|
239
|
-
api: createServiceApi('state', '1.0.0', ['file-backend', 'journal', 'checkpoint', 'recovery']),
|
|
240
|
-
version: '0.1.0',
|
|
241
|
-
FileStateBackend,
|
|
242
|
-
PersistentStore,
|
|
243
|
-
createFileBackend,
|
|
244
|
-
createStore({ backend, initialDoc = config.initialDoc || {} }) {
|
|
245
|
-
return new PersistentStore({ backend, initialDoc })
|
|
246
|
-
},
|
|
247
|
-
replayPending,
|
|
248
|
-
}
|
|
249
|
-
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/** 测试工具:内存 backend 与 fake editor adapter,供框架自身和消费者做一致性测试。 */
|
|
2
|
+
|
|
3
|
+
export function createMemoryBackend({ initialDoc = {} } = {}) {
|
|
4
|
+
let state = null
|
|
5
|
+
const journal = []
|
|
6
|
+
const checkpoints = new Map()
|
|
7
|
+
return {
|
|
8
|
+
dir: '',
|
|
9
|
+
file: '',
|
|
10
|
+
journalFile: '',
|
|
11
|
+
checkpointDir: '',
|
|
12
|
+
lastStateError: null,
|
|
13
|
+
readState() {
|
|
14
|
+
return state ? structuredClone(state) : null
|
|
15
|
+
},
|
|
16
|
+
writeState(doc) {
|
|
17
|
+
state = structuredClone(doc)
|
|
18
|
+
},
|
|
19
|
+
appendJournal(event) {
|
|
20
|
+
journal.push({ ...structuredClone(event), ts: Date.now() / 1000 })
|
|
21
|
+
},
|
|
22
|
+
journalTail(limit = 8) {
|
|
23
|
+
return journal.slice(-limit).map((event) => structuredClone(event))
|
|
24
|
+
},
|
|
25
|
+
writeCheckpoint(name, payload) {
|
|
26
|
+
checkpoints.set(name, structuredClone(payload))
|
|
27
|
+
},
|
|
28
|
+
listCheckpoints() {
|
|
29
|
+
return [...checkpoints.values()]
|
|
30
|
+
.map((payload) => ({
|
|
31
|
+
name: payload.name,
|
|
32
|
+
seq: payload.seq,
|
|
33
|
+
appliedSeq: payload.appliedSeq,
|
|
34
|
+
pending: !!payload.pending,
|
|
35
|
+
title: payload.title,
|
|
36
|
+
slides: payload.slides,
|
|
37
|
+
createdAt: payload.createdAt,
|
|
38
|
+
meta: payload.meta || {},
|
|
39
|
+
}))
|
|
40
|
+
.sort((a, b) => String(b.createdAt).localeCompare(String(a.createdAt)))
|
|
41
|
+
},
|
|
42
|
+
readCheckpoint(name) {
|
|
43
|
+
const payload = checkpoints.get(name)
|
|
44
|
+
if (!payload) throw new Error('checkpoint 不存在: ' + name)
|
|
45
|
+
return structuredClone(payload)
|
|
46
|
+
},
|
|
47
|
+
initialDoc,
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function createFakeEditorAdapter({
|
|
52
|
+
document = {},
|
|
53
|
+
applyCommand = (doc) => doc,
|
|
54
|
+
renderScreenshot = async () => 'data:image/png;base64,eA==',
|
|
55
|
+
} = {}) {
|
|
56
|
+
let current = structuredClone(document)
|
|
57
|
+
const listeners = new Set()
|
|
58
|
+
return {
|
|
59
|
+
isMounted: () => true,
|
|
60
|
+
load(value) { current = structuredClone(value) },
|
|
61
|
+
dump() { return structuredClone(current) },
|
|
62
|
+
async apply(commands) {
|
|
63
|
+
for (const command of commands || []) current = await applyCommand(current, command)
|
|
64
|
+
return (commands || []).length
|
|
65
|
+
},
|
|
66
|
+
async applyUi(commands) { return (commands || []).length },
|
|
67
|
+
onChange(handler) {
|
|
68
|
+
listeners.add(handler)
|
|
69
|
+
return () => listeners.delete(handler)
|
|
70
|
+
},
|
|
71
|
+
async renderScreenshot(opts) { return renderScreenshot(opts) },
|
|
72
|
+
emitChange() { for (const handler of listeners) handler() },
|
|
73
|
+
get document() { return current },
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# @capyclaw/foundation
|
|
2
|
+
|
|
3
|
+
dsh 插件基石层:接口 ABI、插件加载器与内核服务 `ctx.os`。
|
|
4
|
+
|
|
5
|
+
应用插件不再写 `inject` / `apply` / provider 装配,只声明「我实现了哪个接口」:
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
import { createPlugin, skillProvider } from '@capyclaw/foundation/abi'
|
|
9
|
+
|
|
10
|
+
export const { name, inject, apply } = createPlugin({
|
|
11
|
+
name: 'canvas',
|
|
12
|
+
requires: ['canvas.runtime@^1'],
|
|
13
|
+
implements: [skillProvider({ skill: './skills/canvas' })],
|
|
14
|
+
}, import.meta.url)
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## 四个入口
|
|
18
|
+
|
|
19
|
+
| 入口 | 内容 | 谁用 |
|
|
20
|
+
|---|---|---|
|
|
21
|
+
| `.` | Cordis 插件,产出 `ctx.os` | dsh profile |
|
|
22
|
+
| `./abi` | 描述符构建器、加载器、错误码、版本工具 | 应用插件 |
|
|
23
|
+
| `./kit` | plugin-kit 兼容导出,包含 Node/dsh 耦合,非纯函数库 | 兼容调用方 |
|
|
24
|
+
| `./runtime` | `createKernel` 等宿主 API | dsh 之外的宿主(独立技能服务、测试夹具) |
|
|
25
|
+
|
|
26
|
+
## 状态
|
|
27
|
+
|
|
28
|
+
- 包清单当前为 `0.1.6`;0.1.6 修的是「关掉插件再启用撞 E_DUP_PLUGIN」(disposer 未登记 + 失败
|
|
29
|
+
记录占名),详见下面的「生命周期」。
|
|
30
|
+
- 分层:应用插件 → ABI → 内核 → Host 适配器 → 本地 Node.js agent 运行时。
|
|
31
|
+
dsh 服务访问位于 Host 适配层;memory 只是参考实现,不证明第二个真实 agent 兼容。
|
|
32
|
+
HTTP/资源/进程仍有本地 Node 协议约束,详见 `docs/HOST-ADAPTER.md`。
|
|
33
|
+
- ABI v1,六个标准接口 + `host-event@1` + `client-panel@1` + `service-provider@1` +
|
|
34
|
+
`own-server@1` + 可执行 `raw@1`;基建插件使用 `defineDriver` 驱动入口。
|
|
35
|
+
- 能力表按 `ctx` 实际服务探测(见 `lib/kernel.mjs` 的 `detectCapabilities`),不做空头承诺。
|
|
36
|
+
- 当前仓库:27 个插件走标准接口,`raw@1` 当前为空,6 个基建插件走
|
|
37
|
+
`defineDriver` 驱动层;`meta/foundation.allowlist.json` 的模糊豁免为 0。
|
|
38
|
+
详见 `docs/POLICY.md` 与 `docs/spec/plugin-abi.md`。
|
|
39
|
+
|
|
40
|
+
设计规范见 `docs/spec/plugin-abi.md`,强制规则见 `docs/POLICY.md`。
|
|
41
|
+
|
|
42
|
+
## 生命周期(0.1.6 起)
|
|
43
|
+
|
|
44
|
+
`createPlugin().apply` 会把 `os.mount()` 的 disposer 通过 `ctx.effect(() => () => dispose())`
|
|
45
|
+
登记到本次激活的 ctx 上——**不能只靠 apply 的返回值**:Cordis 只认 `ctx.effect` 回调返回的
|
|
46
|
+
disposer,返回值不可靠。漏登记时,关掉插件后内核里的记录不会摘除,再次启用就会撞
|
|
47
|
+
`E_DUP_PLUGIN: 插件 xxx 已挂载`。
|
|
48
|
+
|
|
49
|
+
加载器侧另有两条兜底:`mount()` 遇到 `disposed` / `failed` 的旧记录会先摘掉并尽力回收;
|
|
50
|
+
`start` 失败清理完成后立即让出插件名。两者共同保证「关掉 → 再启用」可重复无数次。
|
|
51
|
+
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 桥(editor bridge)与文档模型的标准声明。
|
|
3
|
+
*
|
|
4
|
+
* 这一层只放「协议常量 + 声明校验」,不放运行时:
|
|
5
|
+
* - 常量:协议版本、模型版本、能力名(suite 清单与 healthz 都用它)
|
|
6
|
+
* - declareBridge():把工作台的声明冻结成标准形状
|
|
7
|
+
* - assertBridgeRuntime():启动/巡检时把「声明」与「运行时实际上报」对齐
|
|
8
|
+
*
|
|
9
|
+
* 运行时(relay / 队列 / 租约)仍在 @capyclaw/document-workbench + service-host,
|
|
10
|
+
* 不进 ABI 层:foundation 是所有插件的地基,不该背 HTTP/store 依赖。
|
|
11
|
+
*
|
|
12
|
+
* 能力名(与 suite 清单的 requires/provides.capabilities 对应):
|
|
13
|
+
* editor.bridge —— 插件提供一个编辑器权威桥(/healthz + /status + /watch + /ack)
|
|
14
|
+
* doc.model —— 插件提供文档模型(稳定 ID / 清单 / 定位 / 编辑计划 / 校验)
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** 桥协议版本:端点集合与状态机语义的主版本。不兼容变更才升 major。 */
|
|
18
|
+
export const BRIDGE_PROTOCOL_VERSION = '1.0.0'
|
|
19
|
+
|
|
20
|
+
/** 文档模型版本:清单字段、定位器语义、编辑 op 的主版本。 */
|
|
21
|
+
export const DOC_MODEL_VERSION = '1.0.0'
|
|
22
|
+
|
|
23
|
+
export const BRIDGE_CAPABILITY = 'editor.bridge'
|
|
24
|
+
export const DOC_MODEL_CAPABILITY = 'doc.model'
|
|
25
|
+
|
|
26
|
+
/** healthz 里桥声明的字段名(避免与既有的 bridge: '<name>' 字符串冲突)。 */
|
|
27
|
+
export const BRIDGE_INFO_FIELD = 'bridgeInfo'
|
|
28
|
+
|
|
29
|
+
const ID_RE = /^[a-z0-9][a-z0-9-]*$/
|
|
30
|
+
const VERSION_RE = /^\d+\.\d+\.\d+$/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 校验并冻结一份桥声明。
|
|
34
|
+
* @param {{ id: string, protocol?: string, model?: string|null, editor?: 'required'|'optional' }} input
|
|
35
|
+
*/
|
|
36
|
+
export function declareBridge(input = {}) {
|
|
37
|
+
const { id, protocol = BRIDGE_PROTOCOL_VERSION, model = null, editor = 'required' } = input
|
|
38
|
+
const errors = []
|
|
39
|
+
if (typeof id !== 'string' || !ID_RE.test(id)) errors.push(`id 必须是 kebab-case:${id}`)
|
|
40
|
+
if (!VERSION_RE.test(protocol)) errors.push(`protocol 版本非法:${protocol}`)
|
|
41
|
+
if (model !== null && !VERSION_RE.test(model)) errors.push(`model 版本非法:${model}`)
|
|
42
|
+
if (editor !== 'required' && editor !== 'optional') errors.push(`editor 只能是 required/optional:${editor}`)
|
|
43
|
+
if (errors.length) throw new Error(`桥声明非法:${errors.join(';')}`)
|
|
44
|
+
return Object.freeze({ id, protocol, model, editor })
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** 桥声明 → suite 清单里的 provides.capabilities。 */
|
|
48
|
+
export function bridgeCapabilities(declaration) {
|
|
49
|
+
const decl = declaration && declaration.protocol ? declaration : declareBridge(declaration)
|
|
50
|
+
return Object.freeze({
|
|
51
|
+
[BRIDGE_CAPABILITY]: decl.protocol,
|
|
52
|
+
...(decl.model ? { [DOC_MODEL_CAPABILITY]: decl.model } : {}),
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** 桥声明 → suite 清单里工具面对运行时的 requires.capabilities(skill 包用)。 */
|
|
57
|
+
export function bridgeConsumerRequirements(ns, { needsModel = false } = {}) {
|
|
58
|
+
const out = { [`${ns}.runtime`]: `^${BRIDGE_PROTOCOL_VERSION}` }
|
|
59
|
+
if (needsModel) out[DOC_MODEL_CAPABILITY] = `^${DOC_MODEL_VERSION}`
|
|
60
|
+
return Object.freeze(out)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 声明与运行时对账:启动或巡检时调用。
|
|
65
|
+
*
|
|
66
|
+
* @param {object} declaration declareBridge 的结果(来自插件代码/清单)
|
|
67
|
+
* @param {object} runtime healthz 里的 bridgeInfo(实际运行值)
|
|
68
|
+
* @returns {{ ok: boolean, issues: string[] }}
|
|
69
|
+
*/
|
|
70
|
+
export function assertBridgeRuntime(declaration, runtime) {
|
|
71
|
+
const issues = []
|
|
72
|
+
const decl = declaration && declaration.id ? declaration : declareBridge(declaration || {})
|
|
73
|
+
if (!runtime || typeof runtime !== 'object') {
|
|
74
|
+
return { ok: false, issues: [`运行时没有上报 ${BRIDGE_INFO_FIELD}`] }
|
|
75
|
+
}
|
|
76
|
+
if (runtime.id !== decl.id) issues.push(`id 不一致:声明 ${decl.id} / 运行 ${runtime.id}`)
|
|
77
|
+
if (runtime.protocol !== decl.protocol) {
|
|
78
|
+
issues.push(`协议版本不一致:声明 ${decl.protocol} / 运行 ${runtime.protocol}`)
|
|
79
|
+
}
|
|
80
|
+
const declaredModel = decl.model || null
|
|
81
|
+
const runtimeModel = runtime.model || null
|
|
82
|
+
if (declaredModel !== runtimeModel) {
|
|
83
|
+
issues.push(`模型版本不一致:声明 ${declaredModel || '无'} / 运行 ${runtimeModel || '无'}`)
|
|
84
|
+
}
|
|
85
|
+
return { ok: issues.length === 0, issues }
|
|
86
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ABI 错误模型:稳定的错误码 + 结构化 detail。
|
|
3
|
+
*
|
|
4
|
+
* 约定:
|
|
5
|
+
* - 应用插件按 code 分支,不解析 message 文案;
|
|
6
|
+
* - message 面向人,detail 面向程序;
|
|
7
|
+
* - 所有加载期失败都必须是 AbiError,不允许裸 Error 穿透。
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** 稳定错误码。新增只能追加,不得改语义。 */
|
|
11
|
+
export const ERROR_CODES = Object.freeze({
|
|
12
|
+
/** 插件入口形状不对:缺 name / 没有 implements / 导出了 apply 等。 */
|
|
13
|
+
E_PLUGIN_SHAPE: 'E_PLUGIN_SHAPE',
|
|
14
|
+
/** 插件声明的 ABI 主版本与内核不兼容。 */
|
|
15
|
+
E_ABI_MISMATCH: 'E_ABI_MISMATCH',
|
|
16
|
+
/** 描述符的 kind 不在内核认识的接口表里。 */
|
|
17
|
+
E_KIND_UNKNOWN: 'E_KIND_UNKNOWN',
|
|
18
|
+
/** 描述符字段不满足接口 schema。 */
|
|
19
|
+
E_SCHEMA: 'E_SCHEMA',
|
|
20
|
+
/** 内核没有提供该能力(通常是 os.* 子系统缺失)。 */
|
|
21
|
+
E_CAP_MISSING: 'E_CAP_MISSING',
|
|
22
|
+
/** 唯一性接口被第二个插件实现(例如同 id 的 runtime-driver)。 */
|
|
23
|
+
E_DUP_INTERFACE: 'E_DUP_INTERFACE',
|
|
24
|
+
/** 同名插件被重复挂载。 */
|
|
25
|
+
E_DUP_PLUGIN: 'E_DUP_PLUGIN',
|
|
26
|
+
/** 内核没有为这个 kind 注册适配器(接口定义存在但实现未就绪)。 */
|
|
27
|
+
E_KIND_UNAVAILABLE: 'E_KIND_UNAVAILABLE',
|
|
28
|
+
/** 适配器在编译期抛错。 */
|
|
29
|
+
E_ADAPTER_THREW: 'E_ADAPTER_THREW',
|
|
30
|
+
/** 插件入口没有拿到 baseUrl,相对路径无法解析。 */
|
|
31
|
+
E_BASE_URL_MISSING: 'E_BASE_URL_MISSING',
|
|
32
|
+
/** 运行时没有 ctx.os:foundation 未安装或未启用。 */
|
|
33
|
+
E_KERNEL_MISSING: 'E_KERNEL_MISSING',
|
|
34
|
+
E_KERNEL_CLOSED: 'E_KERNEL_CLOSED',
|
|
35
|
+
E_NOT_READY: 'E_NOT_READY',
|
|
36
|
+
E_CAP_RESERVED: 'E_CAP_RESERVED',
|
|
37
|
+
E_CAP_CONFLICT: 'E_CAP_CONFLICT',
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
export class AbiError extends Error {
|
|
41
|
+
/**
|
|
42
|
+
* @param {string} code ERROR_CODES 中的一项
|
|
43
|
+
* @param {string} message 面向人的说明
|
|
44
|
+
* @param {Record<string, unknown>} [detail] 面向程序的结构化信息
|
|
45
|
+
*/
|
|
46
|
+
constructor(code, message, detail = {}) {
|
|
47
|
+
super(`[${code}] ${message}`)
|
|
48
|
+
this.name = 'AbiError'
|
|
49
|
+
this.code = code
|
|
50
|
+
this.detail = detail
|
|
51
|
+
if (detail.cause instanceof Error) this.cause = detail.cause
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function isAbiError(error) {
|
|
56
|
+
return error instanceof AbiError
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** 把任意异常归一成 AbiError(已归一的原样返回)。 */
|
|
60
|
+
export function toAbiError(error, code = ERROR_CODES.E_ADAPTER_THREW, detail = {}) {
|
|
61
|
+
if (error instanceof AbiError) return error
|
|
62
|
+
return new AbiError(code, error?.message || String(error), { ...detail, cause: error })
|
|
63
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** 接口 ABI 的唯一入口:应用插件只需要 import 这个模块。 */
|
|
2
|
+
export { ABI_MAJOR, INTERFACE_KINDS, INTERFACE_KIND_NAMES, getInterfaceKind } from './kinds.mjs'
|
|
3
|
+
export {
|
|
4
|
+
defineInterface,
|
|
5
|
+
definePlugin,
|
|
6
|
+
createPlugin,
|
|
7
|
+
skillProvider,
|
|
8
|
+
toolProvider,
|
|
9
|
+
runtimeDriver,
|
|
10
|
+
httpRouter,
|
|
11
|
+
uiPanel,
|
|
12
|
+
lifecycleHook,
|
|
13
|
+
hostEvent,
|
|
14
|
+
clientPanel,
|
|
15
|
+
ownServer,
|
|
16
|
+
serviceProvider,
|
|
17
|
+
defineDriver,
|
|
18
|
+
rawPlugin,
|
|
19
|
+
} from './spec.mjs'
|
|
20
|
+
export { createLoader } from './loader.mjs'
|
|
21
|
+
export {
|
|
22
|
+
BRIDGE_CAPABILITY,
|
|
23
|
+
BRIDGE_INFO_FIELD,
|
|
24
|
+
BRIDGE_PROTOCOL_VERSION,
|
|
25
|
+
DOC_MODEL_CAPABILITY,
|
|
26
|
+
DOC_MODEL_VERSION,
|
|
27
|
+
assertBridgeRuntime,
|
|
28
|
+
bridgeCapabilities,
|
|
29
|
+
bridgeConsumerRequirements,
|
|
30
|
+
declareBridge,
|
|
31
|
+
} from './bridge.mjs'
|
|
32
|
+
export { validateInterface } from './validate.mjs'
|
|
33
|
+
export { AbiError, ERROR_CODES, isAbiError, toAbiError } from './errors.mjs'
|
|
34
|
+
export { validateSchema } from './schema.mjs'
|
|
35
|
+
export { parseVersion, compareVersions, satisfies } from './version.mjs'
|