@capyclaw/windows-control 0.1.2 → 0.1.3
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/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/adapters/raw.mjs +11 -10
- package/node_modules/@capyclaw/foundation/lib/adapters/runtime-driver.mjs +8 -1
- 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/skill/scan.mjs +31 -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/package.json +1 -1
|
@@ -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
|
}
|
package/package.json
CHANGED