@capyclaw/browser-suite 0.2.37 → 0.2.39
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/composition.lock.json +23 -23
- package/contract/browser-contract.json +45 -19
- package/dsh-suite.json +26 -16
- package/node_modules/@capyclaw/asset-service/dsh-suite.json +1 -1
- package/node_modules/@capyclaw/asset-service/package.json +1 -1
- package/node_modules/@capyclaw/asset-service/src/index.mjs +10 -4
- package/node_modules/@capyclaw/browser-skill-api/contract/browser-contract.json +45 -19
- package/node_modules/@capyclaw/browser-skill-api/package.json +1 -1
- package/node_modules/@capyclaw/browser-skill-api/skills/browser-api/references/tool-contract.md +1 -1
- package/node_modules/@capyclaw/browser-skill-browser/contract/browser-contract.json +45 -19
- package/node_modules/@capyclaw/browser-skill-browser/package.json +1 -1
- package/node_modules/@capyclaw/browser-skill-ops/contract/browser-contract.json +45 -19
- package/node_modules/@capyclaw/browser-skill-ops/package.json +1 -1
- package/node_modules/@capyclaw/browser-workbench/contract/browser-contract.json +45 -19
- package/node_modules/@capyclaw/browser-workbench/package.json +7 -7
- package/node_modules/@capyclaw/browser-workbench/plugin.mjs +13 -1
- package/node_modules/@capyclaw/browser-workbench/server/activate-log.mjs +66 -0
- package/node_modules/@capyclaw/browser-workbench/server/contract.mjs +1 -1
- package/node_modules/@capyclaw/browser-workbench/server/embedded-host.mjs +23 -2
- package/node_modules/@capyclaw/browser-workbench/server/engine.mjs +11 -4
- package/node_modules/@capyclaw/browser-workbench/server/routes/api.mjs +2 -2
- package/node_modules/@capyclaw/browser-workbench/server/shared/SHARED_MANIFEST.json +4 -4
- package/node_modules/@capyclaw/browser-workbench/server/workbench-framework.mjs +34 -0
- package/node_modules/@capyclaw/browser-workbench/ui/app.js +87 -10
- package/node_modules/@capyclaw/document-workbench/package.json +6 -3
- package/node_modules/@capyclaw/document-workbench/src/client/index.mjs +56 -3
- package/node_modules/@capyclaw/document-workbench/src/client/visibility.mjs +112 -0
- package/node_modules/@capyclaw/document-workbench/src/model/manifest.mjs +6 -4
- package/node_modules/@capyclaw/document-workbench/src/model/ops.mjs +7 -2
- package/node_modules/@capyclaw/document-workbench/src/session/index.mjs +8 -0
- package/node_modules/@capyclaw/document-workbench/src/store/file-backend.mjs +17 -10
- package/node_modules/@capyclaw/document-workbench/src/store/projection.mjs +39 -0
- package/node_modules/@capyclaw/document-workbench/src/testing/index.mjs +14 -11
- package/node_modules/@capyclaw/foundation/abi/assets.mjs +26 -0
- package/node_modules/@capyclaw/foundation/abi/bridge.mjs +3 -1
- package/node_modules/@capyclaw/foundation/abi/index.mjs +15 -0
- package/node_modules/@capyclaw/foundation/abi/loader.mjs +8 -1
- package/node_modules/@capyclaw/foundation/abi/spec.mjs +5 -2
- package/node_modules/@capyclaw/foundation/abi/version.mjs +63 -5
- package/node_modules/@capyclaw/foundation/abi/visibility.mjs +90 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/lifecycle-hook.mjs +21 -4
- package/node_modules/@capyclaw/foundation/lib/host/caps.mjs +5 -1
- package/node_modules/@capyclaw/foundation/lib/host/contract.mjs +5 -2
- package/node_modules/@capyclaw/foundation/lib/host/dsh.mjs +4 -0
- package/node_modules/@capyclaw/foundation/lib/host/memory.mjs +29 -2
- package/node_modules/@capyclaw/foundation/lib/kernel.mjs +13 -3
- package/node_modules/@capyclaw/foundation/lib/subsystems/net.mjs +12 -2
- package/node_modules/@capyclaw/foundation/package.json +1 -1
- package/node_modules/@capyclaw/plugin-kit/package.json +3 -1
- package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat-worker.js +5 -2
- package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat.mjs +26 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/lease.mjs +3 -82
- package/node_modules/@capyclaw/plugin-kit/src/service/static.mjs +79 -0
- package/node_modules/@capyclaw/plugin-kit/src/workspace/manager.mjs +13 -5
- package/node_modules/@capyclaw/portal/package.json +1 -1
- package/node_modules/@capyclaw/service-broker/README.md +1 -1
- package/node_modules/@capyclaw/service-broker/lib/control.mjs +23 -7
- package/node_modules/@capyclaw/service-broker/lib/engine.mjs +60 -6
- package/node_modules/@capyclaw/service-broker/lib/host.mjs +11 -6
- package/node_modules/@capyclaw/service-broker/lib/manifest.mjs +15 -2
- package/node_modules/@capyclaw/service-broker/lib/recovery.mjs +0 -50
- package/node_modules/@capyclaw/service-broker/lib/skills-client.mjs +30 -10
- package/node_modules/@capyclaw/service-broker/package.json +1 -1
- package/node_modules/@capyclaw/service-host/dsh-suite.json +1 -1
- package/node_modules/@capyclaw/service-host/package.json +1 -1
- package/node_modules/@capyclaw/service-host/src/index.mjs +18 -19
- package/node_modules/@capyclaw/tool-host/dsh-suite.json +2 -2
- package/node_modules/@capyclaw/tool-host/lib/host.mjs +34 -4
- package/node_modules/@capyclaw/tool-host/package.json +1 -1
- package/node_modules/@capyclaw/tool-host/src/admit-images.mjs +80 -0
- package/node_modules/@capyclaw/tool-host/src/caller-session.mjs +25 -0
- package/node_modules/@capyclaw/tool-host/src/index.mjs +59 -14
- package/node_modules/@capyclaw/tool-host/src/mode-gate.mjs +272 -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 +15 -14
|
@@ -39,12 +39,18 @@ export function findSuiteRoot(startDir = path.dirname(PKG_DIR)) {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
/** 读 JSON 并剥 UTF-8 BOM:带 BOM 的清单会让 JSON.parse 抛「Unexpected token」,
|
|
43
|
+
* 表现为 boot 永久失败且极难归因(文件看着完全正常)。统一在此剥掉。 */
|
|
44
|
+
function parseJsonFile(file) {
|
|
45
|
+
return JSON.parse(readFileSync(file, 'utf8').replace(/^\uFEFF/, ''))
|
|
46
|
+
}
|
|
47
|
+
|
|
42
48
|
/** 套件根判据:含 dsh-suite.json + services.json,且不是 broker 自带的 dsh-suite.json。 */
|
|
43
49
|
function isSuiteRoot(dir) {
|
|
44
50
|
const suiteFile = path.join(dir, 'dsh-suite.json')
|
|
45
51
|
if (!existsSync(suiteFile) || !existsSync(path.join(dir, 'services.json'))) return false
|
|
46
52
|
try {
|
|
47
|
-
const manifest =
|
|
53
|
+
const manifest = parseJsonFile(suiteFile)
|
|
48
54
|
return Boolean(manifest) && typeof manifest === 'object' && manifest.name !== 'dsh-service-broker-suite'
|
|
49
55
|
} catch {
|
|
50
56
|
return false
|
|
@@ -201,7 +207,7 @@ export function loadManifest(manifestPath) {
|
|
|
201
207
|
|
|
202
208
|
function loadFile(file) {
|
|
203
209
|
if (!existsSync(file)) return []
|
|
204
|
-
const raw =
|
|
210
|
+
const raw = parseJsonFile(file)
|
|
205
211
|
const services = Array.isArray(raw) ? raw : raw.services
|
|
206
212
|
if (!Array.isArray(services)) throw new Error(`manifest 格式非法(缺 services 数组): ${file}`)
|
|
207
213
|
const specErrors = validateServiceManifest(services, file)
|
|
@@ -245,5 +251,12 @@ function expandPackageDir(service, base) {
|
|
|
245
251
|
for (const key of ['url', 'cwd', 'logFile']) {
|
|
246
252
|
if (typeof out[key] === 'string') out[key] = String(out[key]).replaceAll('${PACKAGE_DIR}', base)
|
|
247
253
|
}
|
|
254
|
+
/* env 值同样展开 ${PACKAGE_DIR}:旧实现只展开 url/cwd/logFile,env 里引用
|
|
255
|
+
* ${PACKAGE_DIR} 的变量(如自定义数据目录/脚本路径)原样传给子进程 → 路径错。 */
|
|
256
|
+
for (const [key, value] of Object.entries(out.env)) {
|
|
257
|
+
if (typeof value === 'string' && value.includes('${PACKAGE_DIR}')) {
|
|
258
|
+
out.env[key] = value.replaceAll('${PACKAGE_DIR}', base)
|
|
259
|
+
}
|
|
260
|
+
}
|
|
248
261
|
return out
|
|
249
262
|
}
|
|
@@ -273,53 +273,3 @@ export async function waitReceiptResolvable(receipt, ports, timeoutMs = 3000) {
|
|
|
273
273
|
await new Promise((resolve) => setTimeout(resolve, 200))
|
|
274
274
|
}
|
|
275
275
|
}
|
|
276
|
-
|
|
277
|
-
// Caller must serialize against starting a replacement broker and supply the
|
|
278
|
-
// identity captured when it spawned this broker. An absent PID alone is not a receipt.
|
|
279
|
-
export async function recoverServices(discovery, broker) {
|
|
280
|
-
const unresolved = [], stopped = []
|
|
281
|
-
if (!broker?.pid || !broker?.marker || !broker?.recoveryMarker || !absent(broker.pid)) return { stopped, unresolved: ['broker:not-confirmed-absent'] }
|
|
282
|
-
let discovered = {}
|
|
283
|
-
try { discovered = JSON.parse(fs.readFileSync(discovery, 'utf8'))?.services || {} } catch { /* discovery 缺失时只能依赖收据自身 */ }
|
|
284
|
-
let entries
|
|
285
|
-
try { entries = fs.readdirSync(receiptDir(discovery)) } catch (e) {
|
|
286
|
-
return { stopped, unresolved: [e.code === 'ENOENT' ? 'ownership:missing' : 'ownership:unreadable'] }
|
|
287
|
-
}
|
|
288
|
-
for (const name of entries) {
|
|
289
|
-
if (!name.endsWith('.json')) { unresolved.push(`ownership:${name}:unrecognized`); continue }
|
|
290
|
-
let r
|
|
291
|
-
try { r = JSON.parse(fs.readFileSync(path.join(receiptDir(discovery), name), 'utf8')) } catch { unresolved.push(`ownership:${name}:unreadable`); continue }
|
|
292
|
-
if (!r || `${r.id}.json` !== name || !/^[a-z0-9][a-z0-9._-]*$/i.test(r.id) || r.brokerPid !== broker.pid || r.brokerMarker !== broker.recoveryMarker || r.state !== 'spawned' || !Number.isSafeInteger(r.pid) || r.pid <= 0 || !r.identity) {
|
|
293
|
-
unresolved.push(`ownership:${name}:unverified`); continue
|
|
294
|
-
}
|
|
295
|
-
if (!absent(broker.pid)) { unresolved.push('broker:not-confirmed-absent'); break }
|
|
296
|
-
if (absent(r.pid)) {
|
|
297
|
-
// Dead root: only a receipt whose declared ports are all free can be
|
|
298
|
-
// resolved; any listener may be an unverified descendant.
|
|
299
|
-
if (await waitReceiptResolvable(r, discovered[r.id]?.ports)) {
|
|
300
|
-
removeReceipt(discovery, r.id)
|
|
301
|
-
stopped.push(r.id)
|
|
302
|
-
} else unresolved.push(`service:${r.id}:already-exited-descendants-unverified`)
|
|
303
|
-
continue
|
|
304
|
-
}
|
|
305
|
-
if (!absent(r.pid)) {
|
|
306
|
-
if (marker(r.pid) !== r.identity) { unresolved.push(`service:${r.id}:identity-unverified`); continue }
|
|
307
|
-
if (process.platform === 'win32') {
|
|
308
|
-
const result = spawnSync('taskkill', ['/PID', String(r.pid), '/F'], { stdio: 'ignore', timeout: 10000, windowsHide: true })
|
|
309
|
-
if (result.status !== 0 && !absent(r.pid)) { unresolved.push(`service:${r.id}:stop-failed`); continue }
|
|
310
|
-
} else {
|
|
311
|
-
try { process.kill(r.pid, 'SIGTERM') } catch (e) { if (e.code !== 'ESRCH') { unresolved.push(`service:${r.id}:stop-failed`); continue } }
|
|
312
|
-
}
|
|
313
|
-
for (let i = 0; i < 50 && !absent(r.pid); i++) await new Promise(resolve => setTimeout(resolve, 100))
|
|
314
|
-
if (!absent(r.pid)) { unresolved.push(`service:${r.id}:still-running`); continue }
|
|
315
|
-
}
|
|
316
|
-
// Root exit alone does not prove its descendants exited. It is safe to
|
|
317
|
-
// resolve once none of the declared ports is still listening; otherwise
|
|
318
|
-
// keep the receipt as evidence (fail closed).
|
|
319
|
-
if (await waitReceiptResolvable(r, discovered[r.id]?.ports)) {
|
|
320
|
-
removeReceipt(discovery, r.id)
|
|
321
|
-
stopped.push(r.id)
|
|
322
|
-
} else unresolved.push(`service:${r.id}:descendants-unverified`)
|
|
323
|
-
}
|
|
324
|
-
return { stopped, unresolved }
|
|
325
|
-
}
|
|
@@ -1,16 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 技能瘦客户端:把独立技能服务的 HTTP 面适配成进程内形状(list/get)。
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* 定位(P1-10 决策):技能的标准路径是 skillProvider@1 进程内注册 →
|
|
5
|
+
* DSH 原生 SkillRegistry(ctx.skills);本客户端只在显式配置 skills.url 的
|
|
6
|
+
* standalone 模式下启用,默认不启用。
|
|
7
|
+
*
|
|
8
|
+
* 服务名刻意叫 **skillsHttp** 而不是 skills:'skills' 是 DSH 原生 SkillRegistry
|
|
9
|
+
* 的服务名(foundation 经 getService(ctx,'skills') 取用,skillProvider@1 靠它的
|
|
10
|
+
* registerProvider 挂载)。若本客户端 provide('skills') 会遮蔽原生注册表,且瘦
|
|
11
|
+
* 客户端没有 registerProvider,全部 skillProvider@1 插件将 E_CAP_MISSING 挂载
|
|
12
|
+
* 失败。改名后原生 ctx.skills 永不被遮蔽,两条路可共存。
|
|
13
|
+
*
|
|
14
|
+
* 服务端形状见 C/packages/capyclaw-skills-service(GET /skills、GET /skills/:name)。
|
|
7
15
|
*/
|
|
8
16
|
export function createSkillsClient(baseUrl) {
|
|
9
17
|
const root = String(baseUrl || '').replace(/\/$/, '')
|
|
10
18
|
return {
|
|
11
|
-
api: { name: '
|
|
19
|
+
api: { name: 'skillsHttp', version: '1.0.0', kind: 'thin-client' },
|
|
12
20
|
async list(signal) {
|
|
13
|
-
|
|
21
|
+
let res
|
|
22
|
+
try {
|
|
23
|
+
res = await fetch(`${root}/skills`, { signal: signal ?? AbortSignal.timeout(5000) })
|
|
24
|
+
} catch (error) {
|
|
25
|
+
throw new Error(`skills 服务不可达(${root}):${error.message}`, { cause: error })
|
|
26
|
+
}
|
|
14
27
|
if (!res.ok) throw new Error(`skills list HTTP ${res.status}`)
|
|
15
28
|
const body = await res.json()
|
|
16
29
|
return Array.isArray(body?.skills) ? body.skills : []
|
|
@@ -18,10 +31,17 @@ export function createSkillsClient(baseUrl) {
|
|
|
18
31
|
async get(candidate, options = {}) {
|
|
19
32
|
const name = typeof candidate === 'string' ? candidate : candidate?.name
|
|
20
33
|
if (!name) throw new Error('skills get: 缺 name')
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
34
|
+
let res
|
|
35
|
+
try {
|
|
36
|
+
res = await fetch(`${root}/skills/${encodeURIComponent(name)}`, {
|
|
37
|
+
signal: options.signal ?? AbortSignal.timeout(10000),
|
|
38
|
+
})
|
|
39
|
+
} catch (error) {
|
|
40
|
+
throw new Error(`skills 服务不可达(${root}):${error.message}`, { cause: error })
|
|
41
|
+
}
|
|
42
|
+
/* 只有 404 才是「未知 skill」;500/503 是服务端故障,不能误导成名字写错。 */
|
|
43
|
+
if (res.status === 404) throw new Error(`未知 skill ${name}(HTTP 404)`)
|
|
44
|
+
if (!res.ok) throw new Error(`skills get ${name} 失败(HTTP ${res.status},服务端错误)`)
|
|
25
45
|
return res.json()
|
|
26
46
|
},
|
|
27
47
|
}
|
|
@@ -19,6 +19,7 @@ import crypto from 'node:crypto'
|
|
|
19
19
|
import { listen, send, sendText, readBody } from '@capyclaw/plugin-kit/service/http'
|
|
20
20
|
import { createServiceApi } from '@capyclaw/plugin-kit/service/api'
|
|
21
21
|
import { isLoopbackOrigin as sharedIsLoopbackOrigin, mimeFor } from '@capyclaw/plugin-kit/util/http'
|
|
22
|
+
import { safeJoin, cleanStaticPrefix, staticPrefixHit, staticRelRaw, decodeStaticRel, staticFileHit, staticHitNameType, staticBaseHeaders } from '@capyclaw/plugin-kit/service/static'
|
|
22
23
|
import { tuning } from './tuning.mjs'
|
|
23
24
|
|
|
24
25
|
function slugOf(id) {
|
|
@@ -133,11 +134,7 @@ async function probeExisting(origin, healthPath, id) {
|
|
|
133
134
|
}
|
|
134
135
|
}
|
|
135
136
|
|
|
136
|
-
|
|
137
|
-
const target = path.resolve(root, `.${path.sep}${rel}`)
|
|
138
|
-
const base = path.resolve(root)
|
|
139
|
-
return target === base || target.startsWith(base + path.sep) ? target : null
|
|
140
|
-
}
|
|
137
|
+
/* safeJoin 已收敛到 @capyclaw/plugin-kit/service/static(P2-13a 静态公共核心)。 */
|
|
141
138
|
|
|
142
139
|
/**
|
|
143
140
|
* @param {{
|
|
@@ -204,20 +201,28 @@ export function createServiceApp(options = {}) {
|
|
|
204
201
|
})
|
|
205
202
|
},
|
|
206
203
|
|
|
207
|
-
/** 静态目录挂载。files 可给显式映射:{ '/': ['index.html','text/html'] }。
|
|
204
|
+
/** 静态目录挂载。files 可给显式映射:{ '/': ['index.html','text/html'] }。
|
|
205
|
+
* 路径/头部计算走 @capyclaw/plugin-kit/service/static 公共核心(P2-13a);
|
|
206
|
+
* 本宿主保留自己的响应政策:畸形编码回 400、content-type 取 mimeFor(请求 rel)、每次读盘。 */
|
|
208
207
|
static(prefix, dir, { files = null, index = 'index.html' } = {}) {
|
|
209
|
-
const cleanPrefix = prefix
|
|
208
|
+
const cleanPrefix = cleanStaticPrefix(prefix)
|
|
210
209
|
return app.use((req, res, u) => {
|
|
211
210
|
if (req.method !== 'GET' && req.method !== 'HEAD') return false
|
|
212
|
-
if (
|
|
213
|
-
const relRaw =
|
|
214
|
-
const rel = relRaw
|
|
211
|
+
if (!staticPrefixHit(u.pathname, cleanPrefix)) return false
|
|
212
|
+
const relRaw = staticRelRaw(u.pathname, cleanPrefix)
|
|
213
|
+
const rel = decodeStaticRel(relRaw, index)
|
|
214
|
+
if (rel === null) {
|
|
215
|
+
/* 畸形百分号编码 → URIError,不包会冒成 500;客户端错误回 400。 */
|
|
216
|
+
res.writeHead(400, { 'content-type': 'text/plain; charset=utf-8' })
|
|
217
|
+
res.end(req.method === 'HEAD' ? undefined : 'malformed path encoding')
|
|
218
|
+
return true
|
|
219
|
+
}
|
|
215
220
|
let file = null
|
|
216
221
|
let type = mimeFor(rel)
|
|
217
222
|
if (files) {
|
|
218
|
-
const hit = files
|
|
223
|
+
const hit = staticFileHit(files, relRaw)
|
|
219
224
|
if (!hit) return false
|
|
220
|
-
const [name, explicitType] =
|
|
225
|
+
const [name, explicitType] = staticHitNameType(hit)
|
|
221
226
|
file = safeJoin(dir, name)
|
|
222
227
|
type = explicitType || type
|
|
223
228
|
} else {
|
|
@@ -226,13 +231,7 @@ export function createServiceApp(options = {}) {
|
|
|
226
231
|
if (!file) return false
|
|
227
232
|
try {
|
|
228
233
|
const data = fs.readFileSync(file)
|
|
229
|
-
res.writeHead(200,
|
|
230
|
-
'content-type': type,
|
|
231
|
-
'content-length': data.length,
|
|
232
|
-
'x-content-type-options': 'nosniff',
|
|
233
|
-
'referrer-policy': 'no-referrer',
|
|
234
|
-
'cache-control': 'no-cache',
|
|
235
|
-
})
|
|
234
|
+
res.writeHead(200, staticBaseHeaders(type, data.length))
|
|
236
235
|
res.end(req.method === 'HEAD' ? undefined : data)
|
|
237
236
|
return true
|
|
238
237
|
} catch {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "../capyclaw-suite-kit/suite.schema.json",
|
|
3
3
|
"name": "dsh-tool-host-suite",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.0",
|
|
5
5
|
"title": "Tool Host",
|
|
6
6
|
"description": "通用工具面:能力 DSL、注册表、校验、契约、MCP 壳、跨套件能力描述符注册/发现。",
|
|
7
7
|
"packages": {
|
|
8
8
|
"@capyclaw/tool-host": {
|
|
9
9
|
"role": "provider",
|
|
10
|
-
"version": "^0.2
|
|
10
|
+
"version": "^0.3.2",
|
|
11
11
|
"path": ".",
|
|
12
12
|
"provides": {
|
|
13
13
|
"services": [
|
|
@@ -1,16 +1,46 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @capyclaw/tool-host 插件:向同进程插件提供 ctx.toolHost。
|
|
3
|
+
*
|
|
4
|
+
* 同时落地“会话模式锁”这一基础设施能力:
|
|
5
|
+
* · 把 work-store 惰性解析器注入 toolHost(模式锁的存储真源);
|
|
6
|
+
* · 给 DSH tools 服务挂全局 guard(异领域调用硬拒兜底);
|
|
7
|
+
* · 注册框架核心工具 mode_lock / mode_status(无领域,恒可见)——显式锁定入口;
|
|
8
|
+
* · 给 DSH systemPrompt 挂动态感知 section(锁定即告知模型主区工作台与交付路径)。
|
|
9
|
+
* 核心工具与 guard 的注册统一走 modeGate.install(tools)(幂等):apply 时 best-effort 挂一次,
|
|
10
|
+
* 若那一刻 tools 服务尚未就绪,首个套件注册(registerWithDsh / bridge host)会再调 install 补上,
|
|
11
|
+
* 故不依赖加载顺序。感知闸同理走 modeGate.installPrompt(systemPrompt)。
|
|
12
|
+
* 所有经 toolHost.registerWithDsh / bridge host 注册的领域能力自动受锁约束,套件零接线。
|
|
3
13
|
*/
|
|
4
14
|
import { defineDriver } from '@capyclaw/foundation/abi'
|
|
5
15
|
import { createToolHost } from '../src/index.mjs'
|
|
6
16
|
|
|
17
|
+
const safeGet = (ctx, name) => {
|
|
18
|
+
try { return ctx.reflect?.get?.(name) ?? ctx[name] } catch { return null }
|
|
19
|
+
}
|
|
20
|
+
|
|
7
21
|
export const { name, inject, apply } = defineDriver({
|
|
8
22
|
name: 'tool-host',
|
|
9
23
|
service: 'toolHost',
|
|
10
24
|
apply(ctx, config = {}) {
|
|
11
|
-
const service = createToolHost(config)
|
|
25
|
+
const service = createToolHost({ ...config, getWorkStore: () => safeGet(ctx, 'workStore') })
|
|
12
26
|
const dispose = ctx.provide('toolHost', service)
|
|
13
|
-
|
|
14
|
-
|
|
27
|
+
|
|
28
|
+
/* 模式锁兜底闸 + 核心锁定工具(幂等)。tools 缺席则降级:稍后套件注册时经 install 补挂。
|
|
29
|
+
* install 返回引用计数 disposer,必须随 driver 卸载释放,否则核心工具/guard 永驻。 */
|
|
30
|
+
const tools = safeGet(ctx, 'tools')
|
|
31
|
+
const gateDispose = (tools && typeof tools.register === 'function') ? service.modeGate.install(tools) : null
|
|
32
|
+
|
|
33
|
+
/* 感知闸(幂等):锁定会话的系统提示里注入主区工作台感知。systemPrompt 缺席则降级,
|
|
34
|
+
* 稍后套件注册时经 installPrompt 补挂。disposer 同样必须随 driver 卸载释放。 */
|
|
35
|
+
const systemPrompt = safeGet(ctx, 'systemPrompt')
|
|
36
|
+
const promptDispose = (systemPrompt && typeof systemPrompt.section === 'function')
|
|
37
|
+
? service.modeGate.installPrompt(systemPrompt) : null
|
|
38
|
+
|
|
39
|
+
console.log('[tool-host] ready (mode-gate enabled)')
|
|
40
|
+
return () => {
|
|
41
|
+
if (typeof promptDispose === 'function') promptDispose()
|
|
42
|
+
if (typeof gateDispose === 'function') gateDispose()
|
|
43
|
+
if (typeof dispose === 'function') dispose()
|
|
44
|
+
}
|
|
15
45
|
},
|
|
16
|
-
})
|
|
46
|
+
})
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 工具结果图像准入 —— DSH 原生工具面专用。
|
|
3
|
+
*
|
|
4
|
+
* 背景(2026-11-22 会话中断根因):DSH 的 ImageBlock 契约要求
|
|
5
|
+
* `{ type:'image', attachment: ImageAttachmentRef }`(见 @deepseek-ai/dsh-llm
|
|
6
|
+
* types.ts)。但部分工作台工具(rsp_screen / browser_screenshot 等)为了「图片直接
|
|
7
|
+
* 回给模型」返回了 MCP wire 形态的裸 base64 块 `{ type:'image', data, mimeType }`。
|
|
8
|
+
* 原生面 `dsh-tools/batch.ts` 把 result.content 原样写进 session 日志、不做形状校验,
|
|
9
|
+
* 于是坏块永久留在历史里;下一步构建请求时序列化器读 `block.attachment.attachmentId`
|
|
10
|
+
* 抛 TypeError(deepseek 侧包成 TRANSPORT,qwen4 侧冒泡成 UNKNOWN),该会话此后每一轮
|
|
11
|
+
* 都在发出前崩掉。
|
|
12
|
+
*
|
|
13
|
+
* 官方工具(read_image / mcp-client / office)都是自己先 `attachments.saveImage`
|
|
14
|
+
* 再回 attachment ref。这里在注册层补上同一道准入:把裸 base64 图像块持久化成
|
|
15
|
+
* attachment ref 再交给 DSH,一处修复覆盖所有 capyclaw 原生工具。
|
|
16
|
+
*
|
|
17
|
+
* 注意:只用于原生面(registerWithDsh)。MCP 面(createMcpHandler/dispatcher)必须
|
|
18
|
+
* 保留 `{data,mimeType}` wire 形态——那是 MCP 协议本身,由 dsh-mcp-client 负责落盘。
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/** 是否是一个尚未准入的裸 base64 图像块(缺 attachment、带 string data)。 */
|
|
22
|
+
function isRawImageBlock(block) {
|
|
23
|
+
return !!block && block.type === 'image' && !block.attachment && typeof block.data === 'string'
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 从执行上下文 / 注册上下文解析 attachments 服务。
|
|
28
|
+
* agent 的会话级 ctx 与 read_image 用的是同一棵上下文树,attachments 必在其上;
|
|
29
|
+
* 注册 ctx 作为兜底。cordis 未 inject 时 get 可能抛错,逐一吞掉换下一个候选。
|
|
30
|
+
* @returns {object|null} 带 saveImage 的 AttachmentStore,或 null。
|
|
31
|
+
*/
|
|
32
|
+
export function resolveAttachments(exec, ctx) {
|
|
33
|
+
for (const candidate of [exec?.agent?.ctx, ctx]) {
|
|
34
|
+
if (!candidate) continue
|
|
35
|
+
try {
|
|
36
|
+
const viaGet = typeof candidate.get === 'function' ? candidate.get('attachments') : undefined
|
|
37
|
+
const service = viaGet ?? candidate.attachments ?? candidate.reflect?.get?.('attachments')
|
|
38
|
+
if (service && typeof service.saveImage === 'function') return service
|
|
39
|
+
} catch { /* 该上下文取不到,换下一个候选 */ }
|
|
40
|
+
}
|
|
41
|
+
return null
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 把工具结果 content 里的裸 base64 图像块准入为持久 attachment ref。
|
|
46
|
+
* 非图像块、已带 attachment 的图像块原样保留;无图像块时零开销直接返回原数组。
|
|
47
|
+
*
|
|
48
|
+
* 降级原则:宁可丢图也不毒化会话——attachments 缺席或 saveImage 失败时,把该图像块
|
|
49
|
+
* 换成一条说明性 text 块(工具通常另有一条带落盘路径的 text 块,信息不丢)。
|
|
50
|
+
*
|
|
51
|
+
* @param {Array} content 归一化后的 MCP content 块数组。
|
|
52
|
+
* @param {object|null} attachments AttachmentStore(resolveAttachments 的结果)。
|
|
53
|
+
* @param {{ name?: string }} [opts] 可选显示名(写入 ref.name,绝不解释为路径)。
|
|
54
|
+
* @returns {Promise<Array>} 准入后的 content 块数组。
|
|
55
|
+
*/
|
|
56
|
+
export async function admitToolResultImages(content, attachments, { name } = {}) {
|
|
57
|
+
if (!Array.isArray(content)) return content
|
|
58
|
+
if (!content.some(isRawImageBlock)) return content
|
|
59
|
+
|
|
60
|
+
const out = []
|
|
61
|
+
for (const block of content) {
|
|
62
|
+
if (!isRawImageBlock(block)) { out.push(block); continue }
|
|
63
|
+
|
|
64
|
+
const mediaType = block.mediaType || block.mimeType || 'image/png'
|
|
65
|
+
if (!attachments) {
|
|
66
|
+
out.push({ type: 'text', text: `[image omitted: no attachment service mounted; ${mediaType}]` })
|
|
67
|
+
continue
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
const data = Buffer.from(block.data, 'base64')
|
|
71
|
+
const ref = await attachments.saveImage({ data, mediaType, ...(name ? { name } : {}) })
|
|
72
|
+
out.push({ type: 'image', attachment: ref })
|
|
73
|
+
} catch (error) {
|
|
74
|
+
const code = error?.code || error?.name || 'ERROR'
|
|
75
|
+
const message = String(error?.message || error)
|
|
76
|
+
out.push({ type: 'text', text: `[image omitted: attachment save failed (${code}): ${message}]` })
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return out
|
|
80
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 调用者会话上下文(框架级 ALS)。
|
|
3
|
+
*
|
|
4
|
+
* registerWithDsh 把每个原生工具的执行包进 runWithCallerSession(sid, …),
|
|
5
|
+
* 于是工具 handler 执行期间(哪怕 handler 只拿到 (args, ctx)、丢了 exec),
|
|
6
|
+
* 框架内部任何一层都能用 currentCallerSession() 取回“是谁在调我”。
|
|
7
|
+
*
|
|
8
|
+
* 用途:会话模式锁在能力发现面(discoverCapabilities)按调用者会话过滤异领域
|
|
9
|
+
* 描述符——conductor_discover 这类 read 工具无需自己接线 exec 即自动受约束。
|
|
10
|
+
*
|
|
11
|
+
* 无会话(HTTP/MCP 管理面、墙聚合视图)时返回 '',调用方据此降级为不过滤。
|
|
12
|
+
*/
|
|
13
|
+
import { AsyncLocalStorage } from 'node:async_hooks'
|
|
14
|
+
|
|
15
|
+
const als = new AsyncLocalStorage()
|
|
16
|
+
|
|
17
|
+
/** 在指定调用者会话上下文里执行 fn(同步/异步均可,ALS 随 await 传播)。 */
|
|
18
|
+
export function runWithCallerSession(sessionId, fn) {
|
|
19
|
+
return als.run(String(sessionId || ''), fn)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** 当前调用者会话 id;不在工具调用上下文里时返回 ''。 */
|
|
23
|
+
export function currentCallerSession() {
|
|
24
|
+
return als.getStore() || ''
|
|
25
|
+
}
|
|
@@ -12,8 +12,14 @@ import { validateToolArguments } from '@capyclaw/plugin-kit/tools/validate'
|
|
|
12
12
|
import { normalizeToolResult, resultText } from '@capyclaw/plugin-kit/tools/result'
|
|
13
13
|
import { createServiceApi } from '@capyclaw/plugin-kit/service/api'
|
|
14
14
|
import { createDescriptorRegistry } from './descriptors.mjs'
|
|
15
|
+
import { createModeGate } from './mode-gate.mjs'
|
|
16
|
+
import { runWithCallerSession, currentCallerSession } from './caller-session.mjs'
|
|
17
|
+
import { admitToolResultImages, resolveAttachments } from './admit-images.mjs'
|
|
15
18
|
|
|
19
|
+
export { admitToolResultImages, resolveAttachments } from './admit-images.mjs'
|
|
16
20
|
export { createDescriptorRegistry } from './descriptors.mjs'
|
|
21
|
+
export { createModeGate } from './mode-gate.mjs'
|
|
22
|
+
export { runWithCallerSession, currentCallerSession } from './caller-session.mjs'
|
|
17
23
|
|
|
18
24
|
const KINDS = new Set(['read', 'write', 'control'])
|
|
19
25
|
|
|
@@ -23,12 +29,13 @@ export function defineTool({
|
|
|
23
29
|
inputSchema = { type: 'object', properties: {}, additionalProperties: false },
|
|
24
30
|
kind = 'write',
|
|
25
31
|
since = '1.0.0',
|
|
32
|
+
domain = '',
|
|
26
33
|
handler,
|
|
27
34
|
} = {}) {
|
|
28
35
|
if (!name || typeof name !== 'string') throw new Error('defineTool 需要 name')
|
|
29
36
|
if (typeof handler !== 'function') throw new Error(`工具 ${name} 需要 handler`)
|
|
30
37
|
if (!KINDS.has(kind)) throw new Error(`工具 ${name} 的 kind 非法: ${kind}`)
|
|
31
|
-
return Object.freeze({ name, description, inputSchema, kind, since, handler })
|
|
38
|
+
return Object.freeze({ name, description, inputSchema, kind, since, domain: String(domain || ''), handler })
|
|
32
39
|
}
|
|
33
40
|
|
|
34
41
|
export function defineCapability({
|
|
@@ -40,6 +47,7 @@ export function defineCapability({
|
|
|
40
47
|
dependsOn = [],
|
|
41
48
|
provides = {},
|
|
42
49
|
features = [],
|
|
50
|
+
domain = '',
|
|
43
51
|
tools = [],
|
|
44
52
|
} = {}) {
|
|
45
53
|
if (!id || typeof id !== 'string') throw new Error('defineCapability 需要 id')
|
|
@@ -53,6 +61,7 @@ export function defineCapability({
|
|
|
53
61
|
dependsOn: Object.freeze([...dependsOn]),
|
|
54
62
|
provides: Object.freeze({ ...provides }),
|
|
55
63
|
features: Object.freeze([...features]),
|
|
64
|
+
domain: String(domain || ''),
|
|
56
65
|
tools: Object.freeze([...tools]),
|
|
57
66
|
})
|
|
58
67
|
}
|
|
@@ -99,7 +108,7 @@ function selectCapabilities(capabilities, enabled) {
|
|
|
99
108
|
* @param {Array} capabilities
|
|
100
109
|
* @param {{ enabled?: string[], ports?: object, report?: Function, reserved?: string[] }} options
|
|
101
110
|
*/
|
|
102
|
-
export function createRegistry(capabilities, { enabled = null, ports = null, report = null, reserved = [] } = {}) {
|
|
111
|
+
export function createRegistry(capabilities, { enabled = null, ports = null, report = null, reserved = [], domain = '' } = {}) {
|
|
103
112
|
validateCapabilities(capabilities)
|
|
104
113
|
const selected = selectCapabilities(capabilities, enabled)
|
|
105
114
|
|
|
@@ -145,11 +154,12 @@ export function createRegistry(capabilities, { enabled = null, ports = null, rep
|
|
|
145
154
|
title: cap.title,
|
|
146
155
|
description: cap.description,
|
|
147
156
|
tags: [...cap.tags],
|
|
157
|
+
domain: cap.domain || domain || '',
|
|
148
158
|
tools: cap.tools.map((tool) => tool.name),
|
|
149
159
|
})
|
|
150
160
|
for (const tool of cap.tools) {
|
|
151
161
|
TOOLS.push({ name: tool.name, description: tool.description, inputSchema: tool.inputSchema })
|
|
152
|
-
TOOL_META[tool.name] = { kind: tool.kind, since: tool.since, capability: cap.id }
|
|
162
|
+
TOOL_META[tool.name] = { kind: tool.kind, since: tool.since, capability: cap.id, domain: tool.domain || cap.domain || domain || '' }
|
|
153
163
|
TOOL_IMPL[tool.name] = (args) => tool.handler(args || {}, ctx)
|
|
154
164
|
}
|
|
155
165
|
}
|
|
@@ -174,7 +184,7 @@ export function createRegistry(capabilities, { enabled = null, ports = null, rep
|
|
|
174
184
|
if (typeof tool.handler !== 'function') throw new Error(`工具 ${tool.name} 需要 handler`)
|
|
175
185
|
if (TOOL_IMPL[tool.name]) throw new Error(`工具已存在: ${tool.name}`)
|
|
176
186
|
TOOLS.push({ name: tool.name, description: tool.description || '', inputSchema: tool.inputSchema || { type: 'object', properties: {} } })
|
|
177
|
-
TOOL_META[tool.name] = { kind: tool.kind || 'write', since: tool.since || '1.0.0', capability: capabilityId }
|
|
187
|
+
TOOL_META[tool.name] = { kind: tool.kind || 'write', since: tool.since || '1.0.0', capability: capabilityId, domain: tool.domain || domain || '' }
|
|
178
188
|
TOOL_IMPL[tool.name] = (args) => tool.handler(args || {}, ctx)
|
|
179
189
|
return true
|
|
180
190
|
}
|
|
@@ -341,17 +351,39 @@ export function buildInstructions({
|
|
|
341
351
|
*
|
|
342
352
|
* @param {object} ctx DSH cordis context
|
|
343
353
|
* @param {object} registry createRegistry() 的返回值
|
|
344
|
-
* @param {{ namespace?: string }} options
|
|
354
|
+
* @param {{ namespace?: string, domain?: string, modeGate?: object }} options
|
|
355
|
+
* domain:本 registry 的兜底领域(工具/能力未各自声明时用);
|
|
356
|
+
* modeGate:会话模式锁闸(createToolHost 服务级自动注入;独立调用可显式传)。
|
|
345
357
|
* @returns {() => void} 反注册全部工具
|
|
346
358
|
*/
|
|
347
|
-
export function registerWithDsh(ctx, registry, { namespace = '' } = {}) {
|
|
359
|
+
export function registerWithDsh(ctx, registry, { namespace = '', domain = '', modeGate = null } = {}) {
|
|
348
360
|
if (!ctx?.tools?.register) throw new Error('registerWithDsh: 当前 DSH 没有 ctx.tools.register')
|
|
361
|
+
/* 领域工具一旦注册即声明给模式锁,并挂全局 guard 兜底(幂等)。
|
|
362
|
+
* install 的引用计数 disposer 必须随本次注册一起释放(旧写法丢弃⇒核心工具/guard 泄漏)。 */
|
|
363
|
+
const gateDispose = modeGate ? modeGate.install(ctx.tools) : null
|
|
349
364
|
const disposers = []
|
|
365
|
+
if (typeof gateDispose === 'function') disposers.push(gateDispose)
|
|
366
|
+
/* 感知闸补挂(幂等):driver apply 那一刻 systemPrompt 可能尚未就绪,套件注册时再挂一次。
|
|
367
|
+
* 引用计数 disposer 随本次注册一起释放。cordis 服务缺席时访问可能抛错,try 包裹降级。 */
|
|
368
|
+
if (modeGate && typeof modeGate.installPrompt === 'function') {
|
|
369
|
+
let systemPrompt = null
|
|
370
|
+
try { systemPrompt = ctx.systemPrompt } catch { systemPrompt = null }
|
|
371
|
+
if (systemPrompt && typeof systemPrompt.section === 'function') {
|
|
372
|
+
const promptDispose = modeGate.installPrompt(systemPrompt)
|
|
373
|
+
if (typeof promptDispose === 'function') disposers.push(promptDispose)
|
|
374
|
+
}
|
|
375
|
+
}
|
|
350
376
|
try {
|
|
351
377
|
for (const tool of registry?.TOOLS || []) {
|
|
352
378
|
const impl = registry.TOOL_IMPL?.[tool.name]
|
|
353
379
|
if (typeof impl !== 'function') throw new Error(`registerWithDsh: 工具缺少实现 ${tool.name}`)
|
|
354
380
|
const name = namespace ? `${namespace}_${tool.name}` : tool.name
|
|
381
|
+
const toolDomain = registry.TOOL_META?.[tool.name]?.domain || domain || ''
|
|
382
|
+
let when
|
|
383
|
+
if (modeGate && toolDomain) {
|
|
384
|
+
modeGate.declareTools(toolDomain, [name])
|
|
385
|
+
when = modeGate.whenFor(name)
|
|
386
|
+
}
|
|
355
387
|
disposers.push(ctx.tools.register({
|
|
356
388
|
name,
|
|
357
389
|
description: tool.description || '',
|
|
@@ -364,16 +396,20 @@ export function registerWithDsh(ctx, registry, { namespace = '' } = {}) {
|
|
|
364
396
|
? value.content
|
|
365
397
|
: normalizeToolResult(value).content),
|
|
366
398
|
},
|
|
367
|
-
execute: async (args, exec) => {
|
|
399
|
+
execute: async (args, exec) => runWithCallerSession(exec?.agent?.session?.id, async () => {
|
|
368
400
|
const normalized = normalizeToolResult(await impl(args, exec))
|
|
369
401
|
/* DSH 原生面成功恒 isError:false,失败必须 throw 才走错误路径(B 轴 P0-1)。
|
|
370
402
|
* 把工具自报的 isError:true 转成 throw,与 MCP 面的失败语义对齐。 */
|
|
371
403
|
if (normalized.isError === true) {
|
|
372
404
|
throw new Error(resultText(normalized) || `工具 ${name} 执行失败`)
|
|
373
405
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
406
|
+
/* 图像准入:裸 base64 图像块(rsp_screen/browser_screenshot 等)必须先持久化成
|
|
407
|
+
* attachment ref 再入 session 日志,否则下一步序列化读 block.attachment.attachmentId
|
|
408
|
+
* 抛错、永久毒化该会话(2026-11-22 根因)。MCP 面不走这里,保留 wire 形态。 */
|
|
409
|
+
const content = await admitToolResultImages(normalized.content, resolveAttachments(exec, ctx), { name })
|
|
410
|
+
return { ...normalized, content }
|
|
411
|
+
}),
|
|
412
|
+
}, when ? { when } : {}))
|
|
377
413
|
}
|
|
378
414
|
} catch (error) {
|
|
379
415
|
/* 全有或全无:任一工具注册失败,逆序释放已注册的,避免部分注册泄漏(B 轴 P0-6)。 */
|
|
@@ -392,9 +428,14 @@ export function registerWithDsh(ctx, registry, { namespace = '' } = {}) {
|
|
|
392
428
|
export function createToolHost(config = {}) {
|
|
393
429
|
// 跨套件能力发现注册表(互联标准 §A.4/§E)。深度校验器可选注入(suite-kit)。
|
|
394
430
|
const descriptors = createDescriptorRegistry({ validate: config.validateDescriptor })
|
|
431
|
+
// 会话模式锁:全服务共享一个闸实例(所有套件的注册都经此)。getWorkStore 惰性解析
|
|
432
|
+
// (driver 注入 () => safeGet(ctx,'workStore'));底座缺席则降级为恒可见、不拒。
|
|
433
|
+
const modeGate = createModeGate({ getWorkStore: config.getWorkStore })
|
|
395
434
|
return {
|
|
396
|
-
|
|
397
|
-
version
|
|
435
|
+
// M12 对齐:自报以 package.json 为权威——dsh.apiVersion=1.1.0(对外契约,
|
|
436
|
+
// 消费者 assertServiceApi 只断言 major 1),version=0.3.1。旧自报 1.2.0/0.3.0 是漂移。
|
|
437
|
+
api: createServiceApi('toolHost', '1.1.0', ['dsl', 'registry', 'validate', 'contract', 'mcp', 'instructions', 'native-tools', 'descriptors', 'mode-gate']),
|
|
438
|
+
version: '0.3.1',
|
|
398
439
|
defineTool,
|
|
399
440
|
defineCapability,
|
|
400
441
|
createRegistry: (capabilities, options = {}) => createRegistry(capabilities, { ...config, ...options }),
|
|
@@ -402,12 +443,16 @@ export function createToolHost(config = {}) {
|
|
|
402
443
|
createToolDispatcher,
|
|
403
444
|
createCapabilityReport,
|
|
404
445
|
buildInstructions,
|
|
405
|
-
|
|
446
|
+
// 服务级注册自动带会话模式锁(when 可见性 + guard 硬拒 + 感知提示 + 调用者会话 ALS),套件零接线。
|
|
447
|
+
registerWithDsh: (ctx, registry, options = {}) => registerWithDsh(ctx, registry, { modeGate, ...options }),
|
|
406
448
|
validateToolArguments,
|
|
449
|
+
modeGate,
|
|
407
450
|
// 能力描述符注册/发现(编排器按类型动态发现,套件零互依赖)。
|
|
408
451
|
registerCapabilityDescriptor: (descriptor, options) => descriptors.register(descriptor, options),
|
|
409
452
|
unregisterCapabilityDescriptor: (name) => descriptors.unregister(name),
|
|
410
|
-
|
|
453
|
+
// 发现面按调用者会话过滤:原生工具调用里自动从 ALS 取会话(conductor_discover 无需接线);
|
|
454
|
+
// HTTP/墙等管理面无会话 → 不过滤(全局视图)。query.sessionId 可显式覆盖。
|
|
455
|
+
discoverCapabilities: (query = {}) => modeGate.filterEntries(descriptors.discover(query), query.sessionId || currentCallerSession()),
|
|
411
456
|
capabilityCatalog: () => descriptors.catalog(),
|
|
412
457
|
listSurfaces: () => descriptors.listSurfaces(),
|
|
413
458
|
}
|