@capyclaw/core 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +59 -2
- package/cordis.patch.yml +24 -0
- package/icon.svg +1 -0
- package/index.js +92 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +52 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 maple496
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,60 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @capyclaw/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
CapyClaw 公共基建的**唯一声明点**。它几乎不含逻辑,价值在 `cordis.patch.yml`:
|
|
4
|
+
|
|
5
|
+
```yaml
|
|
6
|
+
- insert:
|
|
7
|
+
- id: capyclaw-foundation # 提供 ctx.os(内核)
|
|
8
|
+
- id: tool-host # 提供 toolHost
|
|
9
|
+
- id: service-host # 提供 serviceHost
|
|
10
|
+
- id: asset-service # 提供 assets
|
|
11
|
+
- id: service-broker # 提供 serviceBroker / skills(discover: suites)
|
|
12
|
+
- id: editor-host # 提供 editorHost
|
|
13
|
+
- id: capyclaw-core # 本包自己(诊断用)
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## 为什么要有这个包
|
|
17
|
+
|
|
18
|
+
这些行都是**服务提供者**(`ctx.provide`),Loader 按 id 只挂一个实例。问题不在运行期,而在管理期:
|
|
19
|
+
|
|
20
|
+
`@deepseek-ai/dsh-plugin-manager` 的 `removeBundle(name)` 会先停用该 bundle 并重载,然后检查它声明过的行里有没有**仍以活动 fiber 挂着**的——有就抛 `bundle-in-use` 拒绝卸载。于是只要两个 bundle 声明了同一行,卸载任一方都会失败;而且失败前它已经被 `selectBundle` 从 `dsh.profile.bundles` 里删掉了(`change()` 不回滚),实际效果是「报错 + 被静默停用」。
|
|
21
|
+
|
|
22
|
+
以前每个插件都在自己的 patch 里复制 foundation / tool-host 等公共行,所以:
|
|
23
|
+
|
|
24
|
+
- 6 个包声明 `capyclaw-foundation`,5 个声明 `service-host`……卸载任何一个都互相挡;
|
|
25
|
+
- 想卸 browser-suite,得先停用 publisher、skin-clean 等一长串。
|
|
26
|
+
|
|
27
|
+
收敛成 core 唯一声明后,公共行只有一个 owner,feature 包只声明自己那一行,**卸载 feature 不再触发校验**。
|
|
28
|
+
|
|
29
|
+
## 依赖关系
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
@capyclaw/core → foundation / tool-host / service-host / asset-service / service-broker / editor-host
|
|
33
|
+
↑
|
|
34
|
+
skin-clean · skin-aurora · publisher · scrapling · windows-control ·
|
|
35
|
+
browser-suite · canvas-suite · ppt-suite · *-workbench · ddr0-client · launch-engine ·
|
|
36
|
+
plugin-sync · port-sidebar · launchpad
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
依赖方**不再声明**公共行。代价是:单独装一个 feature 而不装 core,会在 `createPlugin()` 处明确报错
|
|
40
|
+
`ctx.os 不可用:请先安装并启用 @capyclaw/foundation`——这是有意的显式失败,而不是静默降级。
|
|
41
|
+
|
|
42
|
+
## 运行时
|
|
43
|
+
|
|
44
|
+
`index.js` 提供 `capyclawCore` 服务,用于诊断:
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
ctx.capyclawCore.rows() // [{ id, service, mounted }]
|
|
48
|
+
ctx.capyclawCore.missing() // 没挂上的行 id
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
若有行没挂上(patch 被手改、或某个 provider 加载失败),apply 时会打一条 warn。
|
|
52
|
+
|
|
53
|
+
## 开发
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
cd D/projects/capyclaw-core
|
|
57
|
+
npm run build # 生成 D/official/capyclaw-core
|
|
58
|
+
npm test # 校验清单 / patch / 运行时服务
|
|
59
|
+
npm run check # 防漂移 + 测试
|
|
60
|
+
```
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# CapyClaw 公共基建的唯一声明点。
|
|
2
|
+
#
|
|
3
|
+
# 这些行都是「服务提供者」(ctx.provide)。由 core 统一声明、其它插件不再重复声明,
|
|
4
|
+
# 卸载 feature 时才不会撞上 plugin-manager 的 bundle-in-use 守卫。
|
|
5
|
+
#
|
|
6
|
+
# 依赖方(skin / suite / publisher / workbench …)只在自己的 patch 里声明自己那一行,
|
|
7
|
+
# 并依赖本包已在同一 profile 中启用。
|
|
8
|
+
|
|
9
|
+
- insert:
|
|
10
|
+
- id: capyclaw-foundation
|
|
11
|
+
name: "@capyclaw/foundation"
|
|
12
|
+
- id: tool-host
|
|
13
|
+
name: "@capyclaw/tool-host"
|
|
14
|
+
- id: service-host
|
|
15
|
+
name: "@capyclaw/service-host"
|
|
16
|
+
- id: asset-service
|
|
17
|
+
name: "@capyclaw/asset-service"
|
|
18
|
+
- id: service-broker
|
|
19
|
+
name: "@capyclaw/service-broker"
|
|
20
|
+
config: {"discover":"suites"}
|
|
21
|
+
- id: editor-host
|
|
22
|
+
name: "@capyclaw/editor-host"
|
|
23
|
+
- id: capyclaw-core
|
|
24
|
+
name: "@capyclaw/core"
|
package/icon.svg
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="7" height="7" rx="1.5"/><rect x="14" y="3" width="7" height="7" rx="1.5"/><rect x="3" y="14" width="7" height="7" rx="1.5"/><path d="M14 17.5h7M17.5 14v7"/></svg>
|
package/index.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @capyclaw/core —— CapyClaw 公共基建的唯一声明点。
|
|
3
|
+
*
|
|
4
|
+
* 这个包本身几乎不做事:它的价值全在 cordis.patch.yml —— 由它一次性声明
|
|
5
|
+
* foundation / tool-host / service-host / asset-service / service-broker / editor-host,
|
|
6
|
+
* 其它插件只声明自己那一行,不再各自复制公共行。
|
|
7
|
+
*
|
|
8
|
+
* 为什么必须收敛成一个声明点(而不是每个插件自包含):
|
|
9
|
+
* 这些行都是服务提供者(ctx.provide),Loader 按 id 只挂一个实例。
|
|
10
|
+
* 谁都可以声明,但一旦两个 bundle 都声明同一行,卸载任意一方都会被
|
|
11
|
+
* plugin-manager 的 bundle-in-use 守卫拒绝(失败一次还会被静默停用)。
|
|
12
|
+
* 收敛到一个 owner 之后,卸载 feature 不再撞上这个守卫。
|
|
13
|
+
*
|
|
14
|
+
* 运行时这里提供 `capyclawCore` 服务,供诊断用:能看到 core 声明了哪些行、
|
|
15
|
+
* 以及当前进程里这些行是否真的挂上了(`rows()` 返回值里 mounted=false 的,
|
|
16
|
+
* 说明 patch 被改过或加载失败)。
|
|
17
|
+
*
|
|
18
|
+
* ⚠ 2026-11-08 事故与教训:第一版用 `ctx[服务名]` 探测服务,cordis 对**未声明
|
|
19
|
+
* inject** 的属性访问会直接抛 `cannot get property "os" without inject`;探测又放在
|
|
20
|
+
* queueMicrotask 里,于是变成未捕获异常,直接把宿主进程带崩(启动即崩)。
|
|
21
|
+
* 现在一律走 `ctx.reflect.get(name)`(不要求 inject、缺服务时返回 undefined),
|
|
22
|
+
* 并且整段诊断包在 try/catch 里 —— **诊断永远不允许影响启动**。
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
export const name = 'capyclaw-core'
|
|
26
|
+
|
|
27
|
+
/** core 负责声明的行(与 cordis.patch.yml 保持同步,build 会校验一致)。 */
|
|
28
|
+
export const ROWS = Object.freeze([
|
|
29
|
+
'capyclaw-foundation',
|
|
30
|
+
'tool-host',
|
|
31
|
+
'service-host',
|
|
32
|
+
'asset-service',
|
|
33
|
+
'service-broker',
|
|
34
|
+
'editor-host',
|
|
35
|
+
])
|
|
36
|
+
|
|
37
|
+
/** 这些行各自提供的服务名,诊断用。 */
|
|
38
|
+
const SERVICES = Object.freeze({
|
|
39
|
+
'capyclaw-foundation': 'os',
|
|
40
|
+
'tool-host': 'toolHost',
|
|
41
|
+
'service-host': 'serviceHost',
|
|
42
|
+
'asset-service': 'assets',
|
|
43
|
+
'service-broker': 'serviceBroker',
|
|
44
|
+
'editor-host': 'editorHost',
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 安全读服务:cordis 的 ctx 代理对未声明 inject 的访问会抛错,所以:
|
|
49
|
+
* 1. 优先走 ctx.reflect.get(name)(不需要 inject,缺服务返回 undefined);
|
|
50
|
+
* 2. 没有 reflect 时(单元测试里的假 ctx)退回普通属性访问;
|
|
51
|
+
* 3. 任何异常都吞掉 —— 这是诊断信息,不是功能依赖。
|
|
52
|
+
*/
|
|
53
|
+
function readService(ctx, serviceName) {
|
|
54
|
+
try {
|
|
55
|
+
const reflect = ctx?.reflect
|
|
56
|
+
if (reflect && typeof reflect.get === 'function') return reflect.get(serviceName)
|
|
57
|
+
return ctx?.[serviceName]
|
|
58
|
+
} catch {
|
|
59
|
+
return undefined
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function apply(ctx) {
|
|
64
|
+
const describe = () => ROWS.map((id) => {
|
|
65
|
+
const service = SERVICES[id]
|
|
66
|
+
return { id, service, mounted: service ? readService(ctx, service) !== undefined : false }
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
const service = {
|
|
70
|
+
rows: describe,
|
|
71
|
+
missing: () => describe().filter((row) => !row.mounted).map((row) => row.id),
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const dispose = ctx.provide('capyclawCore', service)
|
|
75
|
+
|
|
76
|
+
// 行是各自独立的插件,apply 顺序不保证 foundation 已经先跑完;所以延后一拍再自查。
|
|
77
|
+
// 整段必须自带兜底:诊断抛异常会变成 uncaught,直接崩掉宿主。
|
|
78
|
+
queueMicrotask(() => {
|
|
79
|
+
try {
|
|
80
|
+
const missing = service.missing()
|
|
81
|
+
if (missing.length) {
|
|
82
|
+
ctx.log?.warn?.(`[capyclaw-core] 这些行没有挂上:${missing.join(', ')}(patch 被改过,或对应服务加载失败)`)
|
|
83
|
+
}
|
|
84
|
+
} catch {
|
|
85
|
+
/* 诊断失败不影响宿主 */
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
return () => {
|
|
90
|
+
if (typeof dispose === 'function') dispose()
|
|
91
|
+
}
|
|
92
|
+
}
|
package/locale/en.json
ADDED
package/locale/zh.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,54 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capyclaw/core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.18",
|
|
4
|
+
"description": "CapyClaw 公共基建的唯一声明点:一次性挂载 foundation、tool-host、service-host、asset-service、service-broker、editor-host。",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./index.js",
|
|
9
|
+
"./locale/*.json": "./locale/*.json",
|
|
10
|
+
"./icon": "./icon.svg",
|
|
11
|
+
"./package.json": "./package.json"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"index.js",
|
|
15
|
+
"cordis.patch.yml",
|
|
16
|
+
"locale/*.json",
|
|
17
|
+
"icon.svg",
|
|
18
|
+
"README.md",
|
|
19
|
+
"LICENSE"
|
|
20
|
+
],
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@capyclaw/asset-service": "^0.1.5",
|
|
23
|
+
"@capyclaw/editor-host": "^0.1.6",
|
|
24
|
+
"@capyclaw/foundation": "^0.1.10",
|
|
25
|
+
"@capyclaw/portal": "^0.1.12",
|
|
26
|
+
"@capyclaw/service-broker": "^0.2.26",
|
|
27
|
+
"@capyclaw/service-host": "^0.1.6",
|
|
28
|
+
"@capyclaw/tool-host": "^0.3.1"
|
|
29
|
+
},
|
|
30
|
+
"dsh": {
|
|
31
|
+
"bundle": {
|
|
32
|
+
"patch": "./cordis.patch.yml"
|
|
33
|
+
},
|
|
34
|
+
"category": "service",
|
|
35
|
+
"platform": "both"
|
|
36
|
+
},
|
|
37
|
+
"meta": {
|
|
38
|
+
"title": "CapyClaw 公共基建",
|
|
39
|
+
"description": "公共服务的唯一提供方:所有 CapyClaw 插件依赖它,而不是各自重复声明。"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"dsh": "^0.2.0-rc.2",
|
|
43
|
+
"node": ">=18"
|
|
44
|
+
},
|
|
45
|
+
"author": "CapyClaw",
|
|
46
|
+
"repository": {
|
|
47
|
+
"type": "git",
|
|
48
|
+
"directory": "D/official/capyclaw-core"
|
|
49
|
+
},
|
|
50
|
+
"license": "MIT",
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"access": "public"
|
|
53
|
+
}
|
|
54
|
+
}
|