@capyclaw/browser-workbench 0.1.0 → 0.1.18
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 +304 -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 +103 -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 +69 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/runtime-driver.mjs +120 -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 +115 -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 +150 -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 +57 -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 +166 -0
- package/node_modules/@capyclaw/tool-host/src/index.mjs +416 -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 +223 -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,271 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 接口种类表:定义「插件可以是什么」。
|
|
3
|
+
*
|
|
4
|
+
* 一条记录 = 一种插件形状。应用插件不写装配代码,只产出这里的描述符;
|
|
5
|
+
* 生命周期、注册、健康检查、日志包裹由内核的适配器统一完成。
|
|
6
|
+
*
|
|
7
|
+
* 版本规则:
|
|
8
|
+
* - 主版本写在 kind 后缀里(`skill-provider@1`),主版本不同就是不同接口;
|
|
9
|
+
* - 次版本只做增量字段,内核按主版本注册适配器;
|
|
10
|
+
* - 破坏性变更 = 新 kind(@2)+ 旧 kind 至少并存一个大版本。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const nonEmpty = { type: 'string', minLength: 1 }
|
|
14
|
+
const kebab = { type: 'string', pattern: '^[a-z0-9]+(?:-[a-z0-9]+)*$' }
|
|
15
|
+
|
|
16
|
+
export const ABI_MAJOR = 1
|
|
17
|
+
|
|
18
|
+
export const INTERFACE_KINDS = Object.freeze({
|
|
19
|
+
'skill-provider@1': Object.freeze({
|
|
20
|
+
kind: 'skill-provider@1',
|
|
21
|
+
major: 1,
|
|
22
|
+
title: '技能提供者',
|
|
23
|
+
summary: '把一个 SKILL.md 目录注册进 dsh skills 服务,可选附带契约快照与契约注记。',
|
|
24
|
+
unique: false,
|
|
25
|
+
schema: Object.freeze({
|
|
26
|
+
type: 'object',
|
|
27
|
+
required: ['skill'],
|
|
28
|
+
additionalProperties: false,
|
|
29
|
+
properties: {
|
|
30
|
+
name: kebab,
|
|
31
|
+
skill: nonEmpty,
|
|
32
|
+
contract: nonEmpty,
|
|
33
|
+
rank: { type: 'number', min: 0, max: 1000 },
|
|
34
|
+
note: { type: 'function' },
|
|
35
|
+
},
|
|
36
|
+
}),
|
|
37
|
+
}),
|
|
38
|
+
|
|
39
|
+
'tool-provider@1': Object.freeze({
|
|
40
|
+
kind: 'tool-provider@1',
|
|
41
|
+
major: 1,
|
|
42
|
+
title: '工具提供者',
|
|
43
|
+
summary: '声明一组工具并注册到工具面(注册表 / MCP 壳 / 能力报告)。',
|
|
44
|
+
unique: false,
|
|
45
|
+
schema: Object.freeze({
|
|
46
|
+
type: 'object',
|
|
47
|
+
required: ['namespace', 'provide'],
|
|
48
|
+
additionalProperties: false,
|
|
49
|
+
properties: {
|
|
50
|
+
namespace: kebab,
|
|
51
|
+
prefixNamespace: { type: 'boolean' },
|
|
52
|
+
provide: { type: 'function' },
|
|
53
|
+
instructions: nonEmpty,
|
|
54
|
+
capabilities: { type: 'object' },
|
|
55
|
+
},
|
|
56
|
+
}),
|
|
57
|
+
}),
|
|
58
|
+
|
|
59
|
+
'runtime-driver@1': Object.freeze({
|
|
60
|
+
kind: 'runtime-driver@1',
|
|
61
|
+
major: 1,
|
|
62
|
+
title: '运行时驱动',
|
|
63
|
+
summary: '一个长驻进程的启动、就绪、健康与回收;端口由内核分配,应用不自己 spawn。',
|
|
64
|
+
unique: true,
|
|
65
|
+
uniqueBy: 'id',
|
|
66
|
+
schema: Object.freeze({
|
|
67
|
+
type: 'object',
|
|
68
|
+
required: ['id', 'entry'],
|
|
69
|
+
additionalProperties: false,
|
|
70
|
+
properties: {
|
|
71
|
+
id: kebab,
|
|
72
|
+
entry: nonEmpty,
|
|
73
|
+
when: { type: 'function' },
|
|
74
|
+
args: { type: 'array', items: { type: 'string' } },
|
|
75
|
+
port: { type: ['number', 'string', 'function'] },
|
|
76
|
+
portArg: nonEmpty,
|
|
77
|
+
dir: nonEmpty,
|
|
78
|
+
env: { type: 'function' },
|
|
79
|
+
health: {
|
|
80
|
+
type: 'object',
|
|
81
|
+
required: ['path'],
|
|
82
|
+
additionalProperties: false,
|
|
83
|
+
properties: {
|
|
84
|
+
path: nonEmpty,
|
|
85
|
+
expect: { type: 'object' },
|
|
86
|
+
timeoutMs: { type: 'number', min: 1 },
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
restart: {
|
|
90
|
+
type: 'object',
|
|
91
|
+
additionalProperties: false,
|
|
92
|
+
properties: {
|
|
93
|
+
max: { type: 'integer', min: 0 },
|
|
94
|
+
backoffMs: { type: 'number', min: 0 },
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
}),
|
|
99
|
+
}),
|
|
100
|
+
|
|
101
|
+
'http-router@1': Object.freeze({
|
|
102
|
+
kind: 'http-router@1',
|
|
103
|
+
major: 1,
|
|
104
|
+
title: '路由挂载者',
|
|
105
|
+
summary: '把一组 HTTP 路由挂到内核的共享宿主上,前缀冲突由内核检测。',
|
|
106
|
+
unique: false,
|
|
107
|
+
schema: Object.freeze({
|
|
108
|
+
type: 'object',
|
|
109
|
+
required: ['mount', 'routes'],
|
|
110
|
+
additionalProperties: false,
|
|
111
|
+
properties: {
|
|
112
|
+
mount: { type: 'string', pattern: '^/' },
|
|
113
|
+
routes: { type: 'function' },
|
|
114
|
+
host: { type: 'string', enum: ['shared', 'own'] },
|
|
115
|
+
},
|
|
116
|
+
}),
|
|
117
|
+
}),
|
|
118
|
+
|
|
119
|
+
'ui-panel@1': Object.freeze({
|
|
120
|
+
kind: 'ui-panel@1',
|
|
121
|
+
major: 1,
|
|
122
|
+
title: '界面面板',
|
|
123
|
+
summary: '把静态资源目录挂到挂载点,缓存头与 404 兜底由内核处理。',
|
|
124
|
+
unique: false,
|
|
125
|
+
schema: Object.freeze({
|
|
126
|
+
type: 'object',
|
|
127
|
+
required: ['mount', 'root'],
|
|
128
|
+
additionalProperties: false,
|
|
129
|
+
properties: {
|
|
130
|
+
mount: { type: 'string', pattern: '^/' },
|
|
131
|
+
root: nonEmpty,
|
|
132
|
+
index: nonEmpty,
|
|
133
|
+
cache: { type: 'string', enum: ['no-store', 'revalidate', 'immutable'] },
|
|
134
|
+
},
|
|
135
|
+
}),
|
|
136
|
+
}),
|
|
137
|
+
|
|
138
|
+
'lifecycle-hook@1': Object.freeze({
|
|
139
|
+
kind: 'lifecycle-hook@1',
|
|
140
|
+
major: 1,
|
|
141
|
+
title: '生命周期钩子',
|
|
142
|
+
summary: '在安装 / 启动 / 停止 / 升级四个时点插入行为,时序与幂等由内核保证。',
|
|
143
|
+
unique: false,
|
|
144
|
+
schema: Object.freeze({
|
|
145
|
+
type: 'object',
|
|
146
|
+
additionalProperties: false,
|
|
147
|
+
properties: {
|
|
148
|
+
onInstall: { type: 'function' },
|
|
149
|
+
onStart: { type: 'function' },
|
|
150
|
+
onStop: { type: 'function' },
|
|
151
|
+
onUpgrade: { type: 'function' },
|
|
152
|
+
},
|
|
153
|
+
}),
|
|
154
|
+
/** schema 表达不了「至少一个钩子」,用额外校验补。 */
|
|
155
|
+
extra(impl, errors) {
|
|
156
|
+
const hooks = ['onInstall', 'onStart', 'onStop', 'onUpgrade'].filter((key) => typeof impl[key] === 'function')
|
|
157
|
+
if (!hooks.length) errors.push('$ 至少需要实现一个钩子(onInstall/onStart/onStop/onUpgrade)')
|
|
158
|
+
},
|
|
159
|
+
}),
|
|
160
|
+
|
|
161
|
+
'host-event@1': Object.freeze({
|
|
162
|
+
kind: 'host-event@1',
|
|
163
|
+
major: 1,
|
|
164
|
+
title: '宿主事件订阅',
|
|
165
|
+
summary: '订阅宿主生命周期/界面注入事件;适配器负责在插件自己的 ctx 上注册与注销。',
|
|
166
|
+
unique: false,
|
|
167
|
+
schema: Object.freeze({
|
|
168
|
+
type: 'object',
|
|
169
|
+
required: ['event', 'handler'],
|
|
170
|
+
additionalProperties: false,
|
|
171
|
+
properties: {
|
|
172
|
+
event: nonEmpty,
|
|
173
|
+
handler: { type: 'function' },
|
|
174
|
+
},
|
|
175
|
+
}),
|
|
176
|
+
}),
|
|
177
|
+
|
|
178
|
+
'client-panel@1': Object.freeze({
|
|
179
|
+
kind: 'client-panel@1',
|
|
180
|
+
major: 1,
|
|
181
|
+
title: '客户端面板',
|
|
182
|
+
summary: '声明页面开机全局变量与可选静态目录;适配器负责 webserver/index-inject 注入与静态挂载。',
|
|
183
|
+
unique: false,
|
|
184
|
+
schema: Object.freeze({
|
|
185
|
+
type: 'object',
|
|
186
|
+
additionalProperties: false,
|
|
187
|
+
properties: {
|
|
188
|
+
mount: { type: 'string', pattern: '^/' },
|
|
189
|
+
root: nonEmpty,
|
|
190
|
+
index: nonEmpty,
|
|
191
|
+
prepare: { type: 'function' },
|
|
192
|
+
bootGlobals: { type: 'function' },
|
|
193
|
+
},
|
|
194
|
+
}),
|
|
195
|
+
extra(impl, errors) {
|
|
196
|
+
if (!impl.root && !impl.prepare && !impl.bootGlobals) {
|
|
197
|
+
errors.push('$ 至少需要 root / prepare / bootGlobals 之一')
|
|
198
|
+
}
|
|
199
|
+
if (impl.root && !impl.mount) errors.push('$ 提供 root 时必须同时提供 mount')
|
|
200
|
+
},
|
|
201
|
+
}),
|
|
202
|
+
|
|
203
|
+
'own-server@1': Object.freeze({
|
|
204
|
+
kind: 'own-server@1',
|
|
205
|
+
major: 1,
|
|
206
|
+
title: '自有 HTTP 面',
|
|
207
|
+
summary: '宿主有网页端口时挂到该端口的前缀下(不新起端口),否则由 service-host 托管独立 loopback origin。',
|
|
208
|
+
unique: true,
|
|
209
|
+
uniqueBy: 'id',
|
|
210
|
+
schema: Object.freeze({
|
|
211
|
+
type: 'object',
|
|
212
|
+
required: ['id', 'handler'],
|
|
213
|
+
additionalProperties: false,
|
|
214
|
+
properties: {
|
|
215
|
+
id: kebab,
|
|
216
|
+
mount: { type: 'string', pattern: '^/' },
|
|
217
|
+
port: { type: ['number', 'string', 'function'] },
|
|
218
|
+
host: nonEmpty,
|
|
219
|
+
handler: { type: 'function' },
|
|
220
|
+
start: { type: 'function' },
|
|
221
|
+
stop: { type: 'function' },
|
|
222
|
+
},
|
|
223
|
+
}),
|
|
224
|
+
}),
|
|
225
|
+
|
|
226
|
+
'service-provider@1': Object.freeze({
|
|
227
|
+
kind: 'service-provider@1',
|
|
228
|
+
major: 1,
|
|
229
|
+
title: '宿主服务提供者',
|
|
230
|
+
summary: '向宿主 ctx 提供一个具名服务;服务工厂必须同步,异步启动放在 start 钩子里。',
|
|
231
|
+
unique: true,
|
|
232
|
+
uniqueBy: 'service',
|
|
233
|
+
schema: Object.freeze({
|
|
234
|
+
type: 'object',
|
|
235
|
+
required: ['service', 'provide'],
|
|
236
|
+
additionalProperties: false,
|
|
237
|
+
properties: {
|
|
238
|
+
service: nonEmpty,
|
|
239
|
+
provide: { type: 'function' },
|
|
240
|
+
when: { type: 'function' },
|
|
241
|
+
start: { type: 'function' },
|
|
242
|
+
stop: { type: 'function' },
|
|
243
|
+
},
|
|
244
|
+
}),
|
|
245
|
+
}),
|
|
246
|
+
|
|
247
|
+
'raw@1': Object.freeze({
|
|
248
|
+
kind: 'raw@1',
|
|
249
|
+
major: 1,
|
|
250
|
+
title: '原生插件(逃生舱)',
|
|
251
|
+
summary: '极少数需要自定义装配的插件;必须在 meta/foundation.allowlist.json 登记,且不得与其他接口混用。',
|
|
252
|
+
unique: false,
|
|
253
|
+
exclusive: true,
|
|
254
|
+
schema: Object.freeze({
|
|
255
|
+
type: 'object',
|
|
256
|
+
required: ['apply'],
|
|
257
|
+
additionalProperties: false,
|
|
258
|
+
properties: {
|
|
259
|
+
apply: { type: 'function' },
|
|
260
|
+
},
|
|
261
|
+
}),
|
|
262
|
+
}),
|
|
263
|
+
})
|
|
264
|
+
|
|
265
|
+
/** 内核当前认识的 kind 列表(供错误信息与文档生成)。 */
|
|
266
|
+
export const INTERFACE_KIND_NAMES = Object.freeze(Object.keys(INTERFACE_KINDS))
|
|
267
|
+
|
|
268
|
+
/** 取接口定义;未知 kind 返回 undefined,由调用方转成 E_KIND_UNKNOWN。 */
|
|
269
|
+
export function getInterfaceKind(kind) {
|
|
270
|
+
return INTERFACE_KINDS[kind]
|
|
271
|
+
}
|
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
/** Descriptor loader: synchronous validation/mount, observable asynchronous readiness and cleanup. */
|
|
2
|
+
import { ABI_MAJOR, getInterfaceKind } from './kinds.mjs'
|
|
3
|
+
import { validateInterface } from './validate.mjs'
|
|
4
|
+
import { AbiError, ERROR_CODES, toAbiError } from './errors.mjs'
|
|
5
|
+
import { satisfies } from './version.mjs'
|
|
6
|
+
|
|
7
|
+
const thenable = (value) => value && typeof value.then === 'function'
|
|
8
|
+
|
|
9
|
+
/** Run in order, retaining immediate effects when all operations are synchronous. */
|
|
10
|
+
function sequence(items, operation) {
|
|
11
|
+
let pending
|
|
12
|
+
for (const item of items) {
|
|
13
|
+
if (pending) pending = pending.then(() => operation(item))
|
|
14
|
+
else {
|
|
15
|
+
const result = operation(item)
|
|
16
|
+
if (thenable(result)) pending = Promise.resolve(result)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return pending
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function createLoader({ adapters = {}, capabilities = {}, log = null, abiMajor = ABI_MAJOR } = {}) {
|
|
23
|
+
const capabilityMap = () => (typeof capabilities === 'function' ? capabilities() : capabilities)
|
|
24
|
+
const plugins = new Map()
|
|
25
|
+
const uniques = new Map()
|
|
26
|
+
const providers = new Map()
|
|
27
|
+
/* 失败按插件 name 键控:同一插件重试成功后清除旧失败,健康检查不再永久红。
|
|
28
|
+
* 旧实现是只增数组,一次瞬时失败就让 failures.length===0 的断言永远失败。 */
|
|
29
|
+
const failures = new Map()
|
|
30
|
+
let shuttingDown = false
|
|
31
|
+
let shutdown
|
|
32
|
+
|
|
33
|
+
function error(code, message, detail = {}) {
|
|
34
|
+
return new AbiError(code, message, detail)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function capture(reason, plugin, kind, phase) {
|
|
38
|
+
const normalized = toAbiError(reason, ERROR_CODES.E_ADAPTER_THREW, { plugin, kind, phase })
|
|
39
|
+
normalized.detail = { ...normalized.detail, plugin, kind, phase }
|
|
40
|
+
failures.set(plugin, normalized)
|
|
41
|
+
log?.error?.(`[foundation] ${normalized.message}`)
|
|
42
|
+
return normalized
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function adapterOf(kind) {
|
|
46
|
+
const adapter = adapters[kind]
|
|
47
|
+
if (!adapter || typeof adapter.compile !== 'function') {
|
|
48
|
+
throw error(ERROR_CODES.E_KIND_UNAVAILABLE, `接口 ${kind} 已定义但内核没有注册适配器`, { kind })
|
|
49
|
+
}
|
|
50
|
+
return adapter
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function capability(name) {
|
|
54
|
+
const native = capabilityMap()[name]
|
|
55
|
+
if (native) return native
|
|
56
|
+
const owners = providers.get(name)
|
|
57
|
+
return owners?.values().next().value?.version || null
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function capabilityView() {
|
|
61
|
+
const view = { ...capabilityMap() }
|
|
62
|
+
for (const name of providers.keys()) view[name] ??= capability(name)
|
|
63
|
+
return view
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function removeProvides(record) {
|
|
67
|
+
for (const offered of record.spec.provides) {
|
|
68
|
+
const owners = providers.get(offered.name)
|
|
69
|
+
owners?.delete(record)
|
|
70
|
+
if (!owners?.size) providers.delete(offered.name)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function publishProvides(record) {
|
|
75
|
+
for (const offered of record.spec.provides) {
|
|
76
|
+
if (!providers.has(offered.name)) providers.set(offered.name, new Map())
|
|
77
|
+
providers.get(offered.name).set(record, { version: offered.range })
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function releaseClaims(record) {
|
|
82
|
+
for (const key of record.claims) {
|
|
83
|
+
if (uniques.get(key) === record) uniques.delete(key)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function cleanup(record) {
|
|
88
|
+
if (record.cleanupStarted) return record.cleanupResult || record.cleanupTask
|
|
89
|
+
record.cleanupStarted = true
|
|
90
|
+
let settle
|
|
91
|
+
record.cleanupTask = new Promise((resolve) => { settle = resolve })
|
|
92
|
+
const clean = sequence([...record.entries].reverse(), (entry) => {
|
|
93
|
+
try {
|
|
94
|
+
const result = entry.instance.dispose?.()
|
|
95
|
+
if (thenable(result)) {
|
|
96
|
+
return Promise.resolve(result).catch((reason) => {
|
|
97
|
+
record.cleanupErrors.push(capture(reason, record.spec.name, entry.impl.kind, 'dispose'))
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
} catch (reason) {
|
|
101
|
+
record.cleanupErrors.push(capture(reason, record.spec.name, entry.impl.kind, 'dispose'))
|
|
102
|
+
}
|
|
103
|
+
})
|
|
104
|
+
const done = () => {
|
|
105
|
+
record.resourcesReleased = record.cleanupErrors.length === 0
|
|
106
|
+
if (record.resourcesReleased) releaseClaims(record)
|
|
107
|
+
record.cleanupResult = { ok: record.resourcesReleased, errors: [...record.cleanupErrors] }
|
|
108
|
+
settle(record.cleanupResult)
|
|
109
|
+
return record.cleanupResult
|
|
110
|
+
}
|
|
111
|
+
if (thenable(clean)) {
|
|
112
|
+
/* done 必达:即便清理序列意外 reject,也要结算 cleanupTask,避免挂起。 */
|
|
113
|
+
clean.then(done, done)
|
|
114
|
+
return record.cleanupTask
|
|
115
|
+
}
|
|
116
|
+
return done()
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function disposeRecord(record) {
|
|
120
|
+
if (record.disposal) return record.disposal
|
|
121
|
+
let settle
|
|
122
|
+
// Publish the task before abort/cleanup callbacks; either can reenter disposal.
|
|
123
|
+
record.disposal = new Promise((resolve) => { settle = resolve })
|
|
124
|
+
record.stopRequested = true
|
|
125
|
+
record.controller.abort()
|
|
126
|
+
record.status = 'disposing'
|
|
127
|
+
removeProvides(record)
|
|
128
|
+
const finish = () => {
|
|
129
|
+
const result = cleanup(record)
|
|
130
|
+
const complete = (outcome) => {
|
|
131
|
+
record.status = outcome.ok ? 'disposed' : 'failed'
|
|
132
|
+
if (outcome.ok && plugins.get(record.spec.name) === record) plugins.delete(record.spec.name)
|
|
133
|
+
return outcome
|
|
134
|
+
}
|
|
135
|
+
return thenable(result) ? result.then(complete) : complete(result)
|
|
136
|
+
}
|
|
137
|
+
// An in-flight start must settle before stop, otherwise resources could reappear after unload.
|
|
138
|
+
const result = record.inStart ? record.startSettled.then(finish) : finish()
|
|
139
|
+
/* settle 必达:result 一旦 reject(如 startSettled 链意外抛错),旧 .then(settle)
|
|
140
|
+
* 不会执行 → disposal 永久挂起 + unhandledRejection。这里补 rejection 分支。 */
|
|
141
|
+
Promise.resolve(result).then(settle, (reason) => {
|
|
142
|
+
record.status = 'failed'
|
|
143
|
+
settle({ ok: false, errors: [toAbiError(reason, ERROR_CODES.E_ADAPTER_THREW, { plugin: record.spec.name, phase: 'dispose' })] })
|
|
144
|
+
})
|
|
145
|
+
return record.disposal
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function mount(spec, config = {}, context = {}) {
|
|
149
|
+
if (shuttingDown) throw error('E_KERNEL_CLOSED', '内核已关闭,不能挂载插件')
|
|
150
|
+
if (!spec || spec.kind !== 'plugin' || !Array.isArray(spec.implements)
|
|
151
|
+
|| !Array.isArray(spec.requires) || !Array.isArray(spec.provides)) {
|
|
152
|
+
throw error(ERROR_CODES.E_PLUGIN_SHAPE, 'mount 需要 definePlugin 产出的插件描述符')
|
|
153
|
+
}
|
|
154
|
+
if (spec.apiVersion !== abiMajor) {
|
|
155
|
+
throw error(ERROR_CODES.E_ABI_MISMATCH, `插件 ${spec.name} 声明 ABI v${spec.apiVersion},内核为 v${abiMajor}`)
|
|
156
|
+
}
|
|
157
|
+
const previous = plugins.get(spec.name)
|
|
158
|
+
if (previous && previous.status !== 'disposed' && previous.status !== 'failed') {
|
|
159
|
+
throw error(ERROR_CODES.E_DUP_PLUGIN, `插件 ${spec.name} 已挂载`)
|
|
160
|
+
}
|
|
161
|
+
if (previous) {
|
|
162
|
+
// 上一次卸载没走完(宿主没登记 disposer,或清理失败)时,残留记录会一直占着 name。
|
|
163
|
+
// 这里摘掉它并尽力回收,否则「关掉插件再启用」会永久失败在 E_DUP_PLUGIN。
|
|
164
|
+
plugins.delete(spec.name)
|
|
165
|
+
void previous.handle?.dispose?.()
|
|
166
|
+
}
|
|
167
|
+
const missing = spec.requires.filter((need) => need.name.startsWith('os.')
|
|
168
|
+
&& !satisfies(capabilityMap()[need.name] || '', need.range))
|
|
169
|
+
if (missing.length) {
|
|
170
|
+
throw error(ERROR_CODES.E_CAP_MISSING, `插件 ${spec.name} 需要的能力不可用:${missing.map((r) => r.raw).join(', ')}`,
|
|
171
|
+
{ plugin: spec.name, missing })
|
|
172
|
+
}
|
|
173
|
+
const claims = []
|
|
174
|
+
for (const impl of spec.implements) {
|
|
175
|
+
const { definition, errors } = validateInterface(impl)
|
|
176
|
+
if (!definition) throw error(ERROR_CODES.E_KIND_UNKNOWN, `未知接口种类 ${impl?.kind}`)
|
|
177
|
+
if (errors.length) throw error(ERROR_CODES.E_SCHEMA, `${impl.kind} 描述符非法:${errors.join(';')}`)
|
|
178
|
+
adapterOf(impl.kind)
|
|
179
|
+
if (definition.unique) {
|
|
180
|
+
const key = definition.uniqueBy ? `${impl.kind}:${impl[definition.uniqueBy]}` : impl.kind
|
|
181
|
+
if (uniques.has(key) || claims.includes(key)) {
|
|
182
|
+
throw error(ERROR_CODES.E_DUP_INTERFACE, `接口 ${key} 已被占用`, { key })
|
|
183
|
+
}
|
|
184
|
+
claims.push(key)
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
for (const offered of spec.provides) {
|
|
188
|
+
if (offered.name.startsWith('os.') || Object.hasOwn(capabilityMap(), offered.name)) {
|
|
189
|
+
throw error('E_CAP_RESERVED', `应用不能提供宿主保留能力 ${offered.name}`)
|
|
190
|
+
}
|
|
191
|
+
const conflicting = [...plugins.values()].find((record) => !record.resourcesReleased && record.status !== 'disposed'
|
|
192
|
+
&& record.spec.provides.some((item) => item.name === offered.name && item.range !== offered.range))
|
|
193
|
+
if (conflicting) throw error('E_CAP_CONFLICT', `能力 ${offered.name} 的提供版本冲突`, { owner: conflicting.spec.name })
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const record = {
|
|
197
|
+
spec, claims, entries: [], controller: new AbortController(), status: 'starting',
|
|
198
|
+
stopRequested: false, inStart: false, cleanupStarted: false, cleanupErrors: [], startError: null,
|
|
199
|
+
}
|
|
200
|
+
for (const key of claims) uniques.set(key, record)
|
|
201
|
+
try {
|
|
202
|
+
for (const impl of spec.implements) {
|
|
203
|
+
const instance = adapterOf(impl.kind).compile(impl, {
|
|
204
|
+
spec, config, context, log, loader: api, signal: record.controller.signal,
|
|
205
|
+
})
|
|
206
|
+
if (thenable(instance)) throw error(ERROR_CODES.E_PLUGIN_SHAPE, 'compile 必须同步返回资源实例')
|
|
207
|
+
record.entries.push({ impl, instance: instance || {} })
|
|
208
|
+
}
|
|
209
|
+
} catch (reason) {
|
|
210
|
+
const normalized = toAbiError(reason, ERROR_CODES.E_ADAPTER_THREW, { plugin: spec.name, phase: 'compile' })
|
|
211
|
+
removeProvides(record)
|
|
212
|
+
record.status = 'failed'
|
|
213
|
+
record.startSettled = Promise.resolve()
|
|
214
|
+
record.ready = record.startSettled
|
|
215
|
+
// Reserve before invoking user cleanup: a disposer may initiate global shutdown.
|
|
216
|
+
plugins.set(spec.name, record)
|
|
217
|
+
const rollback = cleanup(record)
|
|
218
|
+
const finishRollback = (result) => {
|
|
219
|
+
if (result.ok && plugins.get(spec.name) === record) plugins.delete(spec.name)
|
|
220
|
+
}
|
|
221
|
+
if (thenable(rollback)) rollback.then(finishRollback)
|
|
222
|
+
else finishRollback(rollback)
|
|
223
|
+
throw normalized
|
|
224
|
+
}
|
|
225
|
+
plugins.set(spec.name, record)
|
|
226
|
+
// Sync-only interfaces are operational after compilation, preserving existing skill registration behavior.
|
|
227
|
+
const hasStart = record.entries.some((entry) => typeof entry.instance.start === 'function')
|
|
228
|
+
if (!hasStart) {
|
|
229
|
+
record.status = 'ready'
|
|
230
|
+
failures.delete(spec.name)
|
|
231
|
+
publishProvides(record)
|
|
232
|
+
}
|
|
233
|
+
record.startSettled = Promise.resolve().then(async () => {
|
|
234
|
+
if (record.stopRequested || !hasStart) return
|
|
235
|
+
record.inStart = true
|
|
236
|
+
try {
|
|
237
|
+
for (const entry of record.entries) {
|
|
238
|
+
if (record.stopRequested) break
|
|
239
|
+
if (typeof entry.instance.start === 'function') {
|
|
240
|
+
try {
|
|
241
|
+
await entry.instance.start({ signal: record.controller.signal })
|
|
242
|
+
} catch (reason) {
|
|
243
|
+
record.startError = capture(reason, spec.name, entry.impl.kind, 'start')
|
|
244
|
+
break
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
} finally {
|
|
249
|
+
record.inStart = false
|
|
250
|
+
}
|
|
251
|
+
})
|
|
252
|
+
record.ready = record.startSettled.then(async () => {
|
|
253
|
+
if (record.stopRequested) return
|
|
254
|
+
if (record.startError) {
|
|
255
|
+
record.status = 'failed'
|
|
256
|
+
removeProvides(record)
|
|
257
|
+
await cleanup(record)
|
|
258
|
+
// 启动失败的记录必须让出 name,否则重试挂载永远撞 E_DUP_PLUGIN。
|
|
259
|
+
if (plugins.get(spec.name) === record) plugins.delete(spec.name)
|
|
260
|
+
} else {
|
|
261
|
+
record.status = 'ready'
|
|
262
|
+
failures.delete(spec.name)
|
|
263
|
+
publishProvides(record)
|
|
264
|
+
}
|
|
265
|
+
})
|
|
266
|
+
const handle = {
|
|
267
|
+
name: spec.name, spec, interfaces: record.entries.map((entry) => entry.impl.kind),
|
|
268
|
+
ready: record.ready,
|
|
269
|
+
get status() { return record.status },
|
|
270
|
+
async result() {
|
|
271
|
+
await record.ready
|
|
272
|
+
return { ok: record.status === 'ready', status: record.status, error: record.startError, cleanupErrors: [...record.cleanupErrors] }
|
|
273
|
+
},
|
|
274
|
+
async waitUntilReady() {
|
|
275
|
+
const result = await handle.result()
|
|
276
|
+
if (!result.ok) throw result.error || error('E_NOT_READY', `插件 ${spec.name} 未就绪(${result.status})`)
|
|
277
|
+
return handle
|
|
278
|
+
},
|
|
279
|
+
dispose: () => disposeRecord(record),
|
|
280
|
+
}
|
|
281
|
+
record.handle = handle
|
|
282
|
+
return handle
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function unresolved() {
|
|
286
|
+
const out = []
|
|
287
|
+
for (const { spec } of plugins.values()) {
|
|
288
|
+
for (const need of spec.requires) {
|
|
289
|
+
const actual = capability(need.name)
|
|
290
|
+
if (actual && satisfies(actual, need.range)) continue
|
|
291
|
+
out.push({ plugin: spec.name, capability: need.name, range: need.range,
|
|
292
|
+
actual, reason: actual ? 'incompatible' : 'missing' })
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
return out
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function report() {
|
|
299
|
+
return {
|
|
300
|
+
abiVersion: abiMajor,
|
|
301
|
+
plugins: [...plugins.values()].map((record) => ({
|
|
302
|
+
name: record.spec.name, status: record.status,
|
|
303
|
+
interfaces: record.entries.map((entry) => entry.impl.kind),
|
|
304
|
+
requires: record.spec.requires.map((r) => r.raw), provides: record.spec.provides.map((p) => p.raw),
|
|
305
|
+
})),
|
|
306
|
+
capabilities: capabilityView(), unresolved: unresolved(),
|
|
307
|
+
failures: [...failures.values()].map((reason) => ({ code: reason.code, message: reason.message, detail: reason.detail })),
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function disposeAll() {
|
|
312
|
+
if (shutdown) return shutdown
|
|
313
|
+
shuttingDown = true
|
|
314
|
+
const records = [...plugins.values()].reverse()
|
|
315
|
+
// Stop every pending start now, not after a preceding plugin's async cleanup.
|
|
316
|
+
for (const record of records) {
|
|
317
|
+
record.stopRequested = true
|
|
318
|
+
record.controller.abort()
|
|
319
|
+
}
|
|
320
|
+
const pending = sequence(records, (record) => disposeRecord(record))
|
|
321
|
+
shutdown = Promise.resolve(pending).then(() => ({ ok: ![...plugins.values()].some((r) => r.cleanupErrors.length) }))
|
|
322
|
+
return shutdown
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* 显式强制释放出口(运维/HMR 用):dispose 失败时「保留所有权」是有意设计,
|
|
327
|
+
* 但一次清理失败会把 name/unique 永久锁死,重挂永远撞 E_DUP_INTERFACE。
|
|
328
|
+
* 这里提供一个人工出口:释放 name/unique/provides 占用,让重挂得以进行。
|
|
329
|
+
* 它**不假装资源已清理**——cleanupErrors 原样保留并返回,调用方须知情。
|
|
330
|
+
*/
|
|
331
|
+
function forceRelease(name) {
|
|
332
|
+
const record = plugins.get(name)
|
|
333
|
+
if (!record) return { ok: false, reason: 'no-record' }
|
|
334
|
+
releaseClaims(record)
|
|
335
|
+
removeProvides(record)
|
|
336
|
+
record.resourcesReleased = true
|
|
337
|
+
record.status = 'disposed'
|
|
338
|
+
plugins.delete(name)
|
|
339
|
+
failures.delete(name)
|
|
340
|
+
return { ok: true, forced: true, cleanupErrors: [...record.cleanupErrors] }
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
const api = Object.freeze({ mount, report, capability, disposeAll, forceRelease, get size() { return plugins.size } })
|
|
344
|
+
return api
|
|
345
|
+
}
|