@capyclaw/wall-suite 0.0.0-stage → 0.1.0
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 +20 -2
- package/composition.lock.json +48 -0
- package/contract/wall-contract.json +8 -0
- package/cordis.patch.yml +6 -0
- package/dsh-suite.json +118 -0
- package/lib/index.mjs +6 -0
- package/node_modules/@capyclaw/asset-service/README.md +48 -0
- package/node_modules/@capyclaw/asset-service/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/asset-service/dsh-suite.json +29 -0
- package/node_modules/@capyclaw/asset-service/lib/host.mjs +14 -0
- package/node_modules/@capyclaw/asset-service/package.json +59 -0
- package/node_modules/@capyclaw/asset-service/src/index.mjs +223 -0
- package/node_modules/@capyclaw/foundation/README.md +51 -0
- package/node_modules/@capyclaw/foundation/abi/bridge.mjs +86 -0
- package/node_modules/@capyclaw/foundation/abi/errors.mjs +63 -0
- package/node_modules/@capyclaw/foundation/abi/index.mjs +35 -0
- package/node_modules/@capyclaw/foundation/abi/kinds.mjs +271 -0
- package/node_modules/@capyclaw/foundation/abi/loader.mjs +345 -0
- package/node_modules/@capyclaw/foundation/abi/schema.mjs +98 -0
- package/node_modules/@capyclaw/foundation/abi/spec.mjs +255 -0
- package/node_modules/@capyclaw/foundation/abi/validate.mjs +24 -0
- package/node_modules/@capyclaw/foundation/abi/version.mjs +82 -0
- package/node_modules/@capyclaw/foundation/cordis.patch.yml +5 -0
- package/node_modules/@capyclaw/foundation/kit/index.mjs +6 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/client-panel.mjs +98 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/host-event.mjs +35 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/http-router.mjs +69 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/lifecycle-hook.mjs +55 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/own-server.mjs +113 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/raw.mjs +68 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/runtime-driver.mjs +113 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/service-provider.mjs +77 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/skill-provider.mjs +56 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/tool-provider.mjs +50 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/ui-panel.mjs +64 -0
- package/node_modules/@capyclaw/foundation/lib/ctx-service.mjs +42 -0
- package/node_modules/@capyclaw/foundation/lib/host/caps.mjs +34 -0
- package/node_modules/@capyclaw/foundation/lib/host/contract.mjs +85 -0
- package/node_modules/@capyclaw/foundation/lib/host/dsh.mjs +50 -0
- package/node_modules/@capyclaw/foundation/lib/host/memory.mjs +160 -0
- package/node_modules/@capyclaw/foundation/lib/host.mjs +23 -0
- package/node_modules/@capyclaw/foundation/lib/kernel.mjs +185 -0
- package/node_modules/@capyclaw/foundation/lib/skill/scan.mjs +87 -0
- package/node_modules/@capyclaw/foundation/lib/subsystems/events.mjs +60 -0
- package/node_modules/@capyclaw/foundation/lib/subsystems/log.mjs +51 -0
- package/node_modules/@capyclaw/foundation/lib/subsystems/net.mjs +188 -0
- package/node_modules/@capyclaw/foundation/package.json +53 -0
- package/node_modules/@capyclaw/foundation/runtime/index.mjs +20 -0
- package/node_modules/@capyclaw/plugin-kit/INTEGRATION.md +100 -0
- package/node_modules/@capyclaw/plugin-kit/README.md +70 -0
- package/node_modules/@capyclaw/plugin-kit/bin/sync.mjs +103 -0
- package/node_modules/@capyclaw/plugin-kit/package.json +69 -0
- package/node_modules/@capyclaw/plugin-kit/src/cli.mjs +56 -0
- package/node_modules/@capyclaw/plugin-kit/src/config.mjs +142 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat-worker.js +129 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/lease.mjs +139 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/shadow.mjs +219 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/transport.js +13 -0
- package/node_modules/@capyclaw/plugin-kit/src/index.mjs +13 -0
- package/node_modules/@capyclaw/plugin-kit/src/pack.mjs +230 -0
- package/node_modules/@capyclaw/plugin-kit/src/runtime/context.mjs +128 -0
- package/node_modules/@capyclaw/plugin-kit/src/self-contained.mjs +307 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/api.mjs +45 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/http.mjs +113 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/mcp-http.mjs +143 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/server.mjs +131 -0
- package/node_modules/@capyclaw/plugin-kit/src/skills/provider.mjs +82 -0
- package/node_modules/@capyclaw/plugin-kit/src/store/blob-store.mjs +109 -0
- package/node_modules/@capyclaw/plugin-kit/src/store/content-store.mjs +17 -0
- package/node_modules/@capyclaw/plugin-kit/src/store/journal-store.mjs +89 -0
- package/node_modules/@capyclaw/plugin-kit/src/tools/result.mjs +41 -0
- package/node_modules/@capyclaw/plugin-kit/src/tools/validate.mjs +150 -0
- package/node_modules/@capyclaw/plugin-kit/src/tuning.mjs +82 -0
- package/node_modules/@capyclaw/plugin-kit/src/util/fs-lock.mjs +132 -0
- package/node_modules/@capyclaw/plugin-kit/src/util/http.mjs +130 -0
- package/node_modules/@capyclaw/plugin-kit/src/workspace/manager.mjs +656 -0
- package/node_modules/@capyclaw/plugin-kit/src/zip.mjs +181 -0
- package/node_modules/@capyclaw/portal/README.md +70 -0
- package/node_modules/@capyclaw/portal/lib/index.mjs +387 -0
- package/node_modules/@capyclaw/portal/lib/ledger.mjs +194 -0
- package/node_modules/@capyclaw/portal/lib/portal-agent.ps1 +811 -0
- package/node_modules/@capyclaw/portal/lib/portal-darwin.mjs +183 -0
- package/node_modules/@capyclaw/portal/package.json +40 -0
- package/node_modules/@capyclaw/service-broker/README.md +104 -0
- package/node_modules/@capyclaw/service-broker/cordis.patch.yml +8 -0
- package/node_modules/@capyclaw/service-broker/dsh-suite.json +21 -0
- package/node_modules/@capyclaw/service-broker/lib/control.mjs +193 -0
- package/node_modules/@capyclaw/service-broker/lib/discovery.mjs +109 -0
- package/node_modules/@capyclaw/service-broker/lib/engine.mjs +1236 -0
- package/node_modules/@capyclaw/service-broker/lib/host.mjs +182 -0
- package/node_modules/@capyclaw/service-broker/lib/manifest.mjs +249 -0
- package/node_modules/@capyclaw/service-broker/lib/recovery.mjs +325 -0
- package/node_modules/@capyclaw/service-broker/lib/skills-client.mjs +28 -0
- package/node_modules/@capyclaw/service-broker/lib/spec.mjs +78 -0
- package/node_modules/@capyclaw/service-broker/package.json +65 -0
- package/node_modules/@capyclaw/service-broker/server.mjs +81 -0
- package/node_modules/@capyclaw/service-broker/service.schema.json +62 -0
- package/node_modules/@capyclaw/service-broker/services.json +3 -0
- package/node_modules/@capyclaw/service-host/README.md +86 -0
- package/node_modules/@capyclaw/service-host/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/service-host/dsh-suite.json +29 -0
- package/node_modules/@capyclaw/service-host/lib/host.mjs +22 -0
- package/node_modules/@capyclaw/service-host/package.json +60 -0
- package/node_modules/@capyclaw/service-host/src/index.mjs +571 -0
- package/node_modules/@capyclaw/service-host/src/tuning.mjs +63 -0
- package/node_modules/@capyclaw/tool-host/README.md +56 -0
- package/node_modules/@capyclaw/tool-host/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/tool-host/dsh-suite.json +30 -0
- package/node_modules/@capyclaw/tool-host/lib/host.mjs +16 -0
- package/node_modules/@capyclaw/tool-host/package.json +59 -0
- package/node_modules/@capyclaw/tool-host/src/descriptors.mjs +142 -0
- package/node_modules/@capyclaw/tool-host/src/index.mjs +390 -0
- package/node_modules/@capyclaw/wall-workbench/README.md +58 -0
- package/node_modules/@capyclaw/wall-workbench/contract/wall-contract.json +8 -0
- package/node_modules/@capyclaw/wall-workbench/lib/host.mjs +1 -0
- package/node_modules/@capyclaw/wall-workbench/package.json +63 -0
- package/node_modules/@capyclaw/wall-workbench/plugin.mjs +1 -0
- package/node_modules/@capyclaw/wall-workbench/server/constants.mjs +12 -0
- package/node_modules/@capyclaw/wall-workbench/server/contract.mjs +12 -0
- package/node_modules/@capyclaw/wall-workbench/server/embedded-host.mjs +160 -0
- package/node_modules/@capyclaw/wall-workbench/server/infra/http.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/infra/tuning.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/relay.mjs +68 -0
- package/node_modules/@capyclaw/wall-workbench/server/routes/claim.mjs +46 -0
- package/node_modules/@capyclaw/wall-workbench/server/routes/workbench.mjs +29 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/SHARED_MANIFEST.json +70 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/asset-service.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/editor-host.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/kit/editor/lease.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/kit/service/api.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/kit/service/http.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/kit/service/mcp-http.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/kit/tools/validate.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/kit/tuning.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/kit/util/fs-lock.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/service-host.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/tool-host.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/tuning.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/tools/capabilities/index.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/tools/index.mjs +12 -0
- package/node_modules/@capyclaw/wall-workbench/server/tools.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/workbench-framework.mjs +305 -0
- package/node_modules/@capyclaw/wall-workbench/ui/app.js +142 -0
- package/node_modules/@capyclaw/wall-workbench/ui/index.html +20 -0
- package/node_modules/@capyclaw/wall-workbench/ui/style.css +74 -0
- package/package.json +72 -4
- package/services.json +3 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 端口活动台账 —— 「谁被操作过、操作了多少次」的唯一事实来源。
|
|
3
|
+
*
|
|
4
|
+
* 由来:以前每次工具调用都会强弹一扇窗,很吵。现在改成:**调用只记账,不弹窗**;
|
|
5
|
+
* DSH 界面右下角有一个浮动图标(@capyclaw/portal-hud),显示最近被操作过的端口
|
|
6
|
+
* 与累计次数(封顶 99+),点端口才真的开窗。
|
|
7
|
+
*
|
|
8
|
+
* 落盘位置:`$DSH_HOME/portal-ledger.json`(缺省 `~/.dsh/portal-ledger.json`),
|
|
9
|
+
* 与 `services.json` 同级 —— 跨进程(桥 / broker / HUD 宿主)共享同一份账本。
|
|
10
|
+
*
|
|
11
|
+
* 并发:读-改-写在 4KB 级别的小文件上同步完成,原子写(tmp + rename)。
|
|
12
|
+
* 台账是「展示用的计数」,丢一次更新无伤大雅,不做文件锁。
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import fs from 'node:fs'
|
|
16
|
+
import os from 'node:os'
|
|
17
|
+
import path from 'node:path'
|
|
18
|
+
|
|
19
|
+
const VERSION = 1
|
|
20
|
+
|
|
21
|
+
/** 最多保留多少个端口(按 lastAt 排序)——浮动面板不需要无限历史。 */
|
|
22
|
+
const MAX_PORTS = 24
|
|
23
|
+
|
|
24
|
+
/** 计数上限:面板上显示 99+,但内部仍继续累加(1024 封顶,避免数字无限膨胀)。 */
|
|
25
|
+
const MAX_COUNT = 1024
|
|
26
|
+
|
|
27
|
+
function homeDir() {
|
|
28
|
+
const env = String(process.env.DSH_HOME || '').trim()
|
|
29
|
+
if (env) return env
|
|
30
|
+
return path.join(os.homedir(), '.dsh')
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** 台账文件路径;`DSH_PORTAL_LEDGER` 可覆盖(测试用)。 */
|
|
34
|
+
export function ledgerPath() {
|
|
35
|
+
const override = String(process.env.DSH_PORTAL_LEDGER || '').trim()
|
|
36
|
+
if (override) return override
|
|
37
|
+
return path.join(homeDir(), 'portal-ledger.json')
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function emptyLedger() {
|
|
41
|
+
return { version: VERSION, updatedAt: new Date().toISOString(), total: 0, ports: [] }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** 从 URL 里取端口号(`http://127.0.0.1:<port>/` → `<port>`;取不到返回 0)。 */
|
|
45
|
+
export function servicePort(url) {
|
|
46
|
+
const text = String(url || '')
|
|
47
|
+
const hit = text.match(/^https?:\/\/[^/:]+:(\d+)/i)
|
|
48
|
+
return hit ? Number(hit[1]) : 0
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function normalizeEntry(raw) {
|
|
52
|
+
if (!raw || typeof raw !== 'object') return null
|
|
53
|
+
const url = String(raw.url || '')
|
|
54
|
+
const id = String(raw.id || '')
|
|
55
|
+
if (!url && !id) return null
|
|
56
|
+
return {
|
|
57
|
+
id,
|
|
58
|
+
title: String(raw.title || id || url),
|
|
59
|
+
url,
|
|
60
|
+
port: Number(raw.port || servicePort(url) || 0) || null,
|
|
61
|
+
count: Math.max(0, Math.min(MAX_COUNT, Number(raw.count) || 0)),
|
|
62
|
+
firstAt: String(raw.firstAt || raw.lastAt || ''),
|
|
63
|
+
lastAt: String(raw.lastAt || ''),
|
|
64
|
+
window: raw.window && typeof raw.window === 'object' ? { ...raw.window } : null,
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 同一个服务重启后端口会变(`ports.main: "auto"`):台账必须按 **id** 认人,
|
|
70
|
+
* 不能按 URL 认 —— 否则旧端口的死条目会一直留在面板上,点它就是「打不开」。
|
|
71
|
+
* 读到历史遗留的重复条目时合并:计数相加,保留最新一条的地址。
|
|
72
|
+
*/
|
|
73
|
+
function mergeDuplicates(ports) {
|
|
74
|
+
const merged = []
|
|
75
|
+
const byKey = new Map()
|
|
76
|
+
for (const one of ports) {
|
|
77
|
+
const key = one.id || one.url
|
|
78
|
+
const known = byKey.get(key)
|
|
79
|
+
if (!known) {
|
|
80
|
+
byKey.set(key, one)
|
|
81
|
+
merged.push(one)
|
|
82
|
+
continue
|
|
83
|
+
}
|
|
84
|
+
const [newer, older] = String(one.lastAt) >= String(known.lastAt) ? [one, known] : [known, one]
|
|
85
|
+
newer.count = Math.min(MAX_COUNT, newer.count + older.count)
|
|
86
|
+
newer.firstAt = older.firstAt || newer.firstAt
|
|
87
|
+
if (!newer.url && older.url) {
|
|
88
|
+
newer.url = older.url
|
|
89
|
+
newer.port = older.port
|
|
90
|
+
}
|
|
91
|
+
const index = merged.indexOf(older)
|
|
92
|
+
if (index >= 0) merged[index] = newer
|
|
93
|
+
byKey.set(key, newer)
|
|
94
|
+
}
|
|
95
|
+
return merged
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** 读台账;文件不存在/损坏时返回空台账(永不抛)。 */
|
|
99
|
+
export function readLedger() {
|
|
100
|
+
const file = ledgerPath()
|
|
101
|
+
let text = ''
|
|
102
|
+
try {
|
|
103
|
+
text = fs.readFileSync(file, 'utf8')
|
|
104
|
+
} catch {
|
|
105
|
+
return emptyLedger()
|
|
106
|
+
}
|
|
107
|
+
let parsed = null
|
|
108
|
+
try {
|
|
109
|
+
parsed = JSON.parse(text)
|
|
110
|
+
} catch {
|
|
111
|
+
return emptyLedger()
|
|
112
|
+
}
|
|
113
|
+
const raw = Array.isArray(parsed?.ports) ? parsed.ports.map(normalizeEntry).filter(Boolean) : []
|
|
114
|
+
const ports = mergeDuplicates(raw)
|
|
115
|
+
ports.sort((a, b) => String(b.lastAt).localeCompare(String(a.lastAt)))
|
|
116
|
+
const total = ports.reduce((sum, one) => sum + one.count, 0)
|
|
117
|
+
return {
|
|
118
|
+
version: VERSION,
|
|
119
|
+
updatedAt: String(parsed?.updatedAt || ''),
|
|
120
|
+
total,
|
|
121
|
+
ports: ports.slice(0, MAX_PORTS),
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function writeLedger(ledger) {
|
|
126
|
+
const file = ledgerPath()
|
|
127
|
+
fs.mkdirSync(path.dirname(file), { recursive: true })
|
|
128
|
+
const tmp = `${file}.${process.pid}.tmp`
|
|
129
|
+
fs.writeFileSync(tmp, `${JSON.stringify(ledger, null, 2)}\n`, 'utf8')
|
|
130
|
+
fs.renameSync(tmp, file)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* 记一次活动:同一端口 count +1(封顶 99+ 展示)。
|
|
135
|
+
*
|
|
136
|
+
* 调用方(MCP 桥 / service-broker)在**每次**工具调用时调用它,
|
|
137
|
+
* 这里只碰一个小 JSON 文件,失败也只吞掉 —— 记账绝不能拖慢或打断工具调用。
|
|
138
|
+
*/
|
|
139
|
+
export function recordActivity(input = {}) {
|
|
140
|
+
const url = String(input.url || '')
|
|
141
|
+
const id = String(input.id || '')
|
|
142
|
+
if (!url && !id) return null
|
|
143
|
+
const at = String(input.at || new Date().toISOString())
|
|
144
|
+
const ledger = readLedger()
|
|
145
|
+
/* 按 id 认人:服务重启换了端口,是同一条记录换地址,而不是第二条端口。 */
|
|
146
|
+
const existing = id
|
|
147
|
+
? ledger.ports.find((one) => one.id === id)
|
|
148
|
+
: ledger.ports.find((one) => one.url === url)
|
|
149
|
+
if (existing) {
|
|
150
|
+
existing.count = Math.min(MAX_COUNT, existing.count + 1)
|
|
151
|
+
existing.lastAt = at
|
|
152
|
+
if (url) {
|
|
153
|
+
existing.url = url
|
|
154
|
+
existing.port = Number(input.port || servicePort(url) || 0) || existing.port || null
|
|
155
|
+
}
|
|
156
|
+
if (input.title) existing.title = String(input.title)
|
|
157
|
+
if (input.window && typeof input.window === 'object') existing.window = { ...input.window }
|
|
158
|
+
} else {
|
|
159
|
+
ledger.ports.unshift(normalizeEntry({
|
|
160
|
+
id,
|
|
161
|
+
title: input.title || id || url,
|
|
162
|
+
url,
|
|
163
|
+
port: input.port || servicePort(url),
|
|
164
|
+
count: 1,
|
|
165
|
+
firstAt: at,
|
|
166
|
+
lastAt: at,
|
|
167
|
+
window: input.window || null,
|
|
168
|
+
}))
|
|
169
|
+
}
|
|
170
|
+
ledger.ports.sort((a, b) => String(b.lastAt).localeCompare(String(a.lastAt)))
|
|
171
|
+
ledger.ports = ledger.ports.slice(0, MAX_PORTS)
|
|
172
|
+
ledger.total = ledger.ports.reduce((sum, one) => sum + one.count, 0)
|
|
173
|
+
ledger.updatedAt = at
|
|
174
|
+
try {
|
|
175
|
+
writeLedger(ledger)
|
|
176
|
+
} catch {
|
|
177
|
+
/* 记不上就算了,绝不影响调用方 */
|
|
178
|
+
}
|
|
179
|
+
const saved = id
|
|
180
|
+
? ledger.ports.find((one) => one.id === id)
|
|
181
|
+
: ledger.ports.find((one) => one.url === url)
|
|
182
|
+
return saved || null
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** 清空计数(浮动面板上的「清空」按钮)。 */
|
|
186
|
+
export function resetLedger() {
|
|
187
|
+
const ledger = emptyLedger()
|
|
188
|
+
try {
|
|
189
|
+
writeLedger(ledger)
|
|
190
|
+
} catch {
|
|
191
|
+
/* 忽略 */
|
|
192
|
+
}
|
|
193
|
+
return ledger
|
|
194
|
+
}
|