@capyclaw/capyclaw-workbench 0.1.6 → 0.1.7
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 +23 -32
- package/lib/host.mjs +114 -64
- package/lib/running-tabs.mjs +154 -0
- package/lib/session-port.mjs +13 -17
- package/lib/tab-store.mjs +112 -0
- package/node_modules/@capyclaw/foundation/package.json +1 -1
- package/node_modules/@capyclaw/plugin-kit/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 +123 -11
- package/node_modules/@capyclaw/service-host/src/tuning.mjs +64 -2
- package/node_modules/@capyclaw/suite-kit/package.json +1 -1
- package/node_modules/@capyclaw/tool-host/dsh-suite.json +1 -1
- package/node_modules/@capyclaw/tool-host/package.json +1 -1
- package/package.json +4 -9
- package/plugin.mjs +4 -5
- package/contract/capabilities.json +0 -178
- package/lib/descriptors.mjs +0 -33
- package/lib/tools.mjs +0 -166
- package/lib/workbench.mjs +0 -133
- package/ui/app.js +0 -114
- package/ui/index.html +0 -64
- package/ui/style.css +0 -54
package/lib/tools.mjs
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* capyclaw_* 工具面:子会话生命周期 + DSH 设置。
|
|
3
|
-
* 全部经 tool-host DSL 声明;handler 闭包 sessionPort/ledger,不依赖 DSH exec。
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @param {{ toolHost:object, sessionPort:object, ledger:object, mountPath:string, guiUrl:string }} deps
|
|
8
|
-
*/
|
|
9
|
-
export function createCapyclawCapabilities({ toolHost, sessionPort, ledger, mountPath = '/capyclaw/capyclaw', guiUrl = '/' }) {
|
|
10
|
-
const { defineTool, defineCapability } = toolHost
|
|
11
|
-
|
|
12
|
-
const openSession = defineTool({
|
|
13
|
-
name: 'capyclaw_open_session',
|
|
14
|
-
description: '创建一个 DSH 子会话(同一宿主进程,非独立 dsh)。可选立即发一条启动消息。新会话会自动出现在 GUI 会话列表;返回 sessionId 供后续 send_message/transcript 使用。',
|
|
15
|
-
kind: 'control',
|
|
16
|
-
since: '0.1.0',
|
|
17
|
-
inputSchema: {
|
|
18
|
-
type: 'object',
|
|
19
|
-
properties: {
|
|
20
|
-
title: { type: 'string', description: '给子会话起的标题(仅本套件账本记录)' },
|
|
21
|
-
cwd: { type: 'string', description: '子会话工作目录(与 workspaceId 互斥)' },
|
|
22
|
-
workspaceId: { type: 'string', description: '工作区 id(与 cwd 互斥)' },
|
|
23
|
-
agentPreset: { type: 'string', description: 'agent 预设' },
|
|
24
|
-
prompt: { type: 'string', description: '创建后立即发送的启动消息(可选)' },
|
|
25
|
-
},
|
|
26
|
-
additionalProperties: false,
|
|
27
|
-
},
|
|
28
|
-
handler: async (args) => {
|
|
29
|
-
const { sessionId, agentPreset } = await sessionPort.createSession({
|
|
30
|
-
cwd: args.cwd, workspaceId: args.workspaceId, agentPreset: args.agentPreset,
|
|
31
|
-
})
|
|
32
|
-
const title = args.title || `子会话 ${sessionId.slice(0, 8)}`
|
|
33
|
-
ledger.record(sessionId, { title, cwd: args.cwd || null, agentPreset, parent: 'capyclaw' })
|
|
34
|
-
let accepted = null
|
|
35
|
-
if (args.prompt) {
|
|
36
|
-
const r = await sessionPort.prompt({ sessionId, text: args.prompt })
|
|
37
|
-
accepted = r.accepted
|
|
38
|
-
}
|
|
39
|
-
return {
|
|
40
|
-
ok: true, sessionId, title, agentPreset, accepted,
|
|
41
|
-
consoleUrl: mountPath, guiUrl,
|
|
42
|
-
note: 'GUI 无会话深链:新会话已进 GUI 列表;用 capyclaw_send_message 驱动,或在套娃控制台查看转录。',
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
const sendMessage = defineTool({
|
|
48
|
-
name: 'capyclaw_send_message',
|
|
49
|
-
description: '向指定子会话发送一条用户消息,启动一轮 agent 工作。',
|
|
50
|
-
kind: 'write',
|
|
51
|
-
since: '0.1.0',
|
|
52
|
-
inputSchema: {
|
|
53
|
-
type: 'object',
|
|
54
|
-
properties: {
|
|
55
|
-
sessionId: { type: 'string', description: '目标子会话 id' },
|
|
56
|
-
text: { type: 'string', description: '消息文本' },
|
|
57
|
-
mode: { type: 'string', enum: ['queue', 'steer'], description: 'queue=排队新轮;steer=转向当前轮' },
|
|
58
|
-
},
|
|
59
|
-
required: ['sessionId', 'text'],
|
|
60
|
-
additionalProperties: false,
|
|
61
|
-
},
|
|
62
|
-
handler: async (args) => {
|
|
63
|
-
const r = await sessionPort.prompt({ sessionId: args.sessionId, text: args.text, mode: args.mode || 'queue' })
|
|
64
|
-
return { ok: true, ...r }
|
|
65
|
-
},
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
const listSessions = defineTool({
|
|
69
|
-
name: 'capyclaw_list_sessions',
|
|
70
|
-
description: '列出 DSH 会话(最新在前),并附上本套件账本里的标题/来源标记。',
|
|
71
|
-
kind: 'read',
|
|
72
|
-
since: '0.1.0',
|
|
73
|
-
inputSchema: { type: 'object', properties: {}, additionalProperties: false },
|
|
74
|
-
handler: async () => {
|
|
75
|
-
const records = await sessionPort.listSessions()
|
|
76
|
-
const items = (Array.isArray(records) ? records : []).map((rec) => {
|
|
77
|
-
const id = rec.sessionId || rec.id
|
|
78
|
-
const meta = ledger.get(id) || {}
|
|
79
|
-
return { sessionId: id, title: meta.title || rec.title || null, cwd: meta.cwd ?? rec.cwd ?? null, fromCapyclaw: !!meta, closed: !!meta.closed, raw: rec }
|
|
80
|
-
})
|
|
81
|
-
return { ok: true, count: items.length, items }
|
|
82
|
-
},
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
const transcript = defineTool({
|
|
86
|
-
name: 'capyclaw_session_transcript',
|
|
87
|
-
description: '读取指定子会话的转录/事件(供编排器或用户查看进展)。',
|
|
88
|
-
kind: 'read',
|
|
89
|
-
since: '0.1.0',
|
|
90
|
-
inputSchema: {
|
|
91
|
-
type: 'object',
|
|
92
|
-
properties: { sessionId: { type: 'string', description: '目标子会话 id' } },
|
|
93
|
-
required: ['sessionId'],
|
|
94
|
-
additionalProperties: false,
|
|
95
|
-
},
|
|
96
|
-
handler: async (args) => {
|
|
97
|
-
const data = await sessionPort.readSession(args.sessionId)
|
|
98
|
-
return { ok: true, sessionId: args.sessionId, transcript: data }
|
|
99
|
-
},
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
const closeSession = defineTool({
|
|
103
|
-
name: 'capyclaw_close_session',
|
|
104
|
-
description: '关闭子会话:取消当前轮(best-effort)并在账本标记 closed。DSH 无显式销毁,会话记录仍保留。',
|
|
105
|
-
kind: 'control',
|
|
106
|
-
since: '0.1.0',
|
|
107
|
-
inputSchema: {
|
|
108
|
-
type: 'object',
|
|
109
|
-
properties: { sessionId: { type: 'string', description: '目标子会话 id' } },
|
|
110
|
-
required: ['sessionId'],
|
|
111
|
-
additionalProperties: false,
|
|
112
|
-
},
|
|
113
|
-
handler: async (args) => {
|
|
114
|
-
const r = await sessionPort.cancel(args.sessionId)
|
|
115
|
-
ledger.markClosed(args.sessionId)
|
|
116
|
-
return { ok: true, ...r, closed: true }
|
|
117
|
-
},
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
const settingsGet = defineTool({
|
|
121
|
-
name: 'capyclaw_settings_get',
|
|
122
|
-
description: '读取 DSH 设置快照(describe)。帮用户查看当前配置。',
|
|
123
|
-
kind: 'read',
|
|
124
|
-
since: '0.1.0',
|
|
125
|
-
inputSchema: { type: 'object', properties: {}, additionalProperties: false },
|
|
126
|
-
handler: async () => ({ ok: true, settings: await sessionPort.describeSettings() }),
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
const settingsSet = defineTool({
|
|
130
|
-
name: 'capyclaw_settings_set',
|
|
131
|
-
description: '更新 DSH 设置(稀疏合并)。ns=profile 条目 id;高风险操作,需确认。revision 不符会抛 SETTINGS_CONFLICT。',
|
|
132
|
-
kind: 'write',
|
|
133
|
-
since: '0.1.0',
|
|
134
|
-
inputSchema: {
|
|
135
|
-
type: 'object',
|
|
136
|
-
properties: {
|
|
137
|
-
ns: { type: 'string', description: '设置命名空间(profile 条目 id)' },
|
|
138
|
-
patch: { type: 'object', description: '要合并的设置补丁', additionalProperties: true },
|
|
139
|
-
expectedRevision: { type: 'string', description: '乐观锁 revision(可选)' },
|
|
140
|
-
},
|
|
141
|
-
required: ['ns', 'patch'],
|
|
142
|
-
additionalProperties: false,
|
|
143
|
-
},
|
|
144
|
-
handler: async (args) => {
|
|
145
|
-
const value = await sessionPort.updateSettings({ ns: args.ns, patch: args.patch, expectedRevision: args.expectedRevision })
|
|
146
|
-
return { ok: true, ns: args.ns, value }
|
|
147
|
-
},
|
|
148
|
-
})
|
|
149
|
-
|
|
150
|
-
return [
|
|
151
|
-
defineCapability({
|
|
152
|
-
id: 'capyclaw.sessions',
|
|
153
|
-
title: '子会话生命周期',
|
|
154
|
-
description: '在同一宿主进程内创建/驱动/查询/关闭 DSH 子会话(俄罗斯套娃的控制面)。',
|
|
155
|
-
tags: ['session', 'subagent'],
|
|
156
|
-
tools: [openSession, sendMessage, listSessions, transcript, closeSession],
|
|
157
|
-
}),
|
|
158
|
-
defineCapability({
|
|
159
|
-
id: 'capyclaw.settings',
|
|
160
|
-
title: 'DSH 设置',
|
|
161
|
-
description: '读取/更新 DSH 设置,帮用户完成配置。',
|
|
162
|
-
tags: ['settings'],
|
|
163
|
-
tools: [settingsGet, settingsSet],
|
|
164
|
-
}),
|
|
165
|
-
]
|
|
166
|
-
}
|
package/lib/workbench.mjs
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* capyclaw-workbench 可单测核心:会话控制台 + 套娃呈现 + MCP/HTTP 能力面。
|
|
3
|
-
* 不依赖 cordis ctx;服务(toolHost/serviceHost/sessionPort)全部注入。
|
|
4
|
-
* host.mjs 负责把它接进 DSH(listen + registerWithDsh + 描述符发布)。
|
|
5
|
-
*/
|
|
6
|
-
import path from 'node:path'
|
|
7
|
-
import { fileURLToPath } from 'node:url'
|
|
8
|
-
import { send, readBody } from '@capyclaw/plugin-kit/service/http'
|
|
9
|
-
import { attachSurface } from '@capyclaw/suite-kit/surface'
|
|
10
|
-
import { createCapyclawCapabilities } from './tools.mjs'
|
|
11
|
-
import { registerCapyclawDescriptors, CAPYCLAW_CONTRACT_VERSION } from './descriptors.mjs'
|
|
12
|
-
|
|
13
|
-
const HERE = path.dirname(fileURLToPath(import.meta.url))
|
|
14
|
-
const DEFAULT_UI_DIR = path.join(HERE, '..', 'ui')
|
|
15
|
-
|
|
16
|
-
/** 子会话账本:标题/来源/closed 标记(DSH create 不收 title,这里补记)。 */
|
|
17
|
-
export function createLedger() {
|
|
18
|
-
const map = new Map()
|
|
19
|
-
return {
|
|
20
|
-
record(id, meta) { map.set(id, { ...map.get(id), ...meta, createdAt: map.get(id)?.createdAt || Date.now() }) },
|
|
21
|
-
get(id) { return map.get(id) || null },
|
|
22
|
-
markClosed(id) { if (map.has(id)) map.set(id, { ...map.get(id), closed: true }) },
|
|
23
|
-
all() { return [...map.entries()].map(([id, m]) => ({ sessionId: id, ...m })) },
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function statusFor(code) {
|
|
28
|
-
if (code === 'ARG_INVALID' || code === 'BAD_JSON') return 400
|
|
29
|
-
if (code === 'SESSION_SERVICE_UNAVAILABLE') return 503
|
|
30
|
-
return 500
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @param {{ toolHost:object, serviceHost:object, sessionPort:object,
|
|
35
|
-
* config?:{ mountPath?:string, guiUrl?:string, version?:string, uiDir?:string } }} deps
|
|
36
|
-
*/
|
|
37
|
-
export function createCapyclawWorkbench({ toolHost, serviceHost, sessionPort, config = {} }) {
|
|
38
|
-
const mountPath = config.mountPath || '/capyclaw/capyclaw'
|
|
39
|
-
const guiUrl = config.guiUrl || '/'
|
|
40
|
-
const version = config.version || '0.1.0'
|
|
41
|
-
const uiDir = config.uiDir || DEFAULT_UI_DIR
|
|
42
|
-
const ledger = createLedger()
|
|
43
|
-
|
|
44
|
-
const capabilities = createCapyclawCapabilities({ toolHost, sessionPort, ledger, mountPath, guiUrl })
|
|
45
|
-
const registry = toolHost.createRegistry(capabilities)
|
|
46
|
-
const mcpHandler = toolHost.createMcpHandler({
|
|
47
|
-
tools: registry.TOOLS,
|
|
48
|
-
// 结构化结果序列化为 JSON 文本:编排器(conductor)经 HTTP MCP tools/call
|
|
49
|
-
// 拿到的必须是可解析的 {ok,sessionId,...},而不是默认包装的 "ok"。
|
|
50
|
-
callTool: async (name, args, context) => {
|
|
51
|
-
const out = await registry.TOOL_IMPL[name](args, context)
|
|
52
|
-
const text = typeof out === 'string' ? out : JSON.stringify(out ?? null)
|
|
53
|
-
return { content: [{ type: 'text', text }] }
|
|
54
|
-
},
|
|
55
|
-
serverInfo: { name: 'capyclaw-workbench', version },
|
|
56
|
-
instructions: toolHost.buildInstructions({
|
|
57
|
-
title: 'CapyClaw 子会话工作台',
|
|
58
|
-
intro: '在同一宿主进程内创建/驱动 DSH 子会话(俄罗斯套娃),并可读写 DSH 设置。',
|
|
59
|
-
capabilities: registry.CAPABILITIES,
|
|
60
|
-
rules: ['GUI 无会话深链:新会话自动进 GUI 列表;用 sessionId 驱动与查转录。', 'settings_set 为高风险,需确认。'],
|
|
61
|
-
}),
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
const app = serviceHost.createApp({
|
|
65
|
-
id: 'capyclaw-workbench',
|
|
66
|
-
title: 'CapyClaw 子会话工作台',
|
|
67
|
-
version,
|
|
68
|
-
contractVersion: CAPYCLAW_CONTRACT_VERSION,
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
const guard = (handler) => async (req, res, u) => {
|
|
72
|
-
try { await handler(req, res, u) } catch (err) {
|
|
73
|
-
send(req, res, statusFor(err?.code), { ok: false, error: err?.message || String(err), code: err?.code || 'INTERNAL' })
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
const mergeList = async () => {
|
|
77
|
-
let records = []
|
|
78
|
-
try { records = await sessionPort.listSessions() } catch { records = [] }
|
|
79
|
-
const byId = new Map()
|
|
80
|
-
for (const rec of Array.isArray(records) ? records : []) {
|
|
81
|
-
const id = rec.sessionId || rec.id
|
|
82
|
-
byId.set(id, { sessionId: id, ...rec, ...(ledger.get(id) || {}) })
|
|
83
|
-
}
|
|
84
|
-
for (const entry of ledger.all()) if (!byId.has(entry.sessionId)) byId.set(entry.sessionId, entry)
|
|
85
|
-
return [...byId.values()]
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
app.get('/api/sessions', guard(async (req, res) => send(req, res, 200, { ok: true, items: await mergeList() })))
|
|
89
|
-
app.post('/api/sessions', guard(async (req, res) => {
|
|
90
|
-
const body = await readBody(req)
|
|
91
|
-
const { sessionId, agentPreset } = await sessionPort.createSession({ cwd: body.cwd, workspaceId: body.workspaceId, agentPreset: body.agentPreset })
|
|
92
|
-
const title = body.title || `子会话 ${sessionId.slice(0, 8)}`
|
|
93
|
-
ledger.record(sessionId, { title, cwd: body.cwd || null, agentPreset, parent: 'capyclaw' })
|
|
94
|
-
let accepted = null
|
|
95
|
-
if (body.prompt) accepted = (await sessionPort.prompt({ sessionId, text: body.prompt })).accepted
|
|
96
|
-
send(req, res, 200, { ok: true, sessionId, title, accepted })
|
|
97
|
-
}))
|
|
98
|
-
app.post('/api/sessions/prompt', guard(async (req, res) => {
|
|
99
|
-
const body = await readBody(req)
|
|
100
|
-
send(req, res, 200, { ok: true, ...(await sessionPort.prompt({ sessionId: body.sessionId, text: body.text, mode: body.mode })) })
|
|
101
|
-
}))
|
|
102
|
-
app.get('/api/sessions/transcript', guard(async (req, res, u) => {
|
|
103
|
-
const sessionId = u.searchParams.get('sessionId')
|
|
104
|
-
send(req, res, 200, { ok: true, sessionId, transcript: await sessionPort.readSession(sessionId) })
|
|
105
|
-
}))
|
|
106
|
-
app.post('/api/sessions/close', guard(async (req, res) => {
|
|
107
|
-
const body = await readBody(req)
|
|
108
|
-
const r = await sessionPort.cancel(body.sessionId)
|
|
109
|
-
ledger.markClosed(body.sessionId)
|
|
110
|
-
send(req, res, 200, { ok: true, ...r, closed: true })
|
|
111
|
-
}))
|
|
112
|
-
app.get('/api/settings', guard(async (req, res) => send(req, res, 200, { ok: true, settings: await sessionPort.describeSettings() })))
|
|
113
|
-
app.post('/api/settings', guard(async (req, res) => {
|
|
114
|
-
const body = await readBody(req)
|
|
115
|
-
send(req, res, 200, { ok: true, value: await sessionPort.updateSettings({ ns: body.ns, patch: body.patch, expectedRevision: body.expectedRevision }) })
|
|
116
|
-
}))
|
|
117
|
-
app.get('/api/capabilities', guard(async (req, res) => send(req, res, 200, {
|
|
118
|
-
ok: true, contract: registry.ctx.contract.report(mountPath), available: sessionPort.services,
|
|
119
|
-
})))
|
|
120
|
-
app.get('/api/config', guard(async (req, res) => send(req, res, 200, { ok: true, mountPath, guiUrl, version, available: sessionPort.services })))
|
|
121
|
-
app.post('/mcp', guard(async (req, res) => { await mcpHandler(req, res) }))
|
|
122
|
-
// 呈现面接线(标准 §C.7):/embed.js 握手客户端 + /api/surface 自描述,单一真源在 suite-kit。
|
|
123
|
-
attachSurface(app, { suite: 'capyclaw', embedPath: mountPath })
|
|
124
|
-
app.static('/', uiDir)
|
|
125
|
-
|
|
126
|
-
return {
|
|
127
|
-
app, registry, ledger, mountPath, guiUrl, sessionPort,
|
|
128
|
-
/** listen 后由 host 调:把描述符 + 调用地址登记进公共注册表。 */
|
|
129
|
-
publishDescriptors(baseUrl, { validate } = {}) {
|
|
130
|
-
return registerCapyclawDescriptors(toolHost, { baseUrl, validate })
|
|
131
|
-
},
|
|
132
|
-
}
|
|
133
|
-
}
|
package/ui/app.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
/* CapyClaw 子会话工作台 UI。控制面与呈现面分离:工具/HTTP 同一接口,模式只是呈现层状态。 */
|
|
2
|
-
(function () {
|
|
3
|
-
const $ = (s, r) => (r || document).querySelector(s)
|
|
4
|
-
const $$ = (s, r) => [...(r || document).querySelectorAll(s)]
|
|
5
|
-
const esc = (s) => String(s ?? '').replace(/[&<>"]/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"' }[c]))
|
|
6
|
-
let CFG = { guiUrl: '/', mountPath: '/capyclaw/capyclaw', available: {} }
|
|
7
|
-
|
|
8
|
-
if (window.CapyclawEmbed) window.CapyclawEmbed.setSuite('capyclaw')
|
|
9
|
-
const emit = (kind, payload) => { try { window.CapyclawEmbed && window.CapyclawEmbed.sendEvent({ kind, suite: 'capyclaw', at: Date.now(), ...payload }) } catch {} }
|
|
10
|
-
|
|
11
|
-
function toast(msg, isErr) {
|
|
12
|
-
const t = $('#toast'); t.textContent = msg; t.className = 'toast show' + (isErr ? ' err' : '')
|
|
13
|
-
clearTimeout(t._h); t._h = setTimeout(() => { t.className = 'toast' }, 2600)
|
|
14
|
-
}
|
|
15
|
-
async function api(method, url, body) {
|
|
16
|
-
const opt = { method, headers: {} }
|
|
17
|
-
if (body !== undefined) { opt.headers['content-type'] = 'application/json'; opt.body = JSON.stringify(body) }
|
|
18
|
-
const res = await fetch(url, opt)
|
|
19
|
-
let data = {}; try { data = await res.json() } catch {}
|
|
20
|
-
if (!res.ok || data.ok === false) throw new Error(data.error || ('HTTP ' + res.status))
|
|
21
|
-
return data
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// ---- 配置 / 可用性 ----
|
|
25
|
-
async function loadConfig() {
|
|
26
|
-
try {
|
|
27
|
-
CFG = await api('GET', './api/config')
|
|
28
|
-
$('#gui').src = CFG.guiUrl || '/'
|
|
29
|
-
$('#gui-open').href = CFG.guiUrl || '/'
|
|
30
|
-
const a = CFG.available || {}
|
|
31
|
-
const on = a.sessionController
|
|
32
|
-
const pill = $('#avail'); pill.textContent = on ? '会话服务可用' : '会话服务不可用'
|
|
33
|
-
pill.className = 'pill ' + (on ? 'ok' : 'bad')
|
|
34
|
-
} catch (e) { toast('配置加载失败:' + e.message, true) }
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// ---- 子会话 ----
|
|
38
|
-
async function loadSessions() {
|
|
39
|
-
const box = $('#session-list')
|
|
40
|
-
try {
|
|
41
|
-
const { items } = await api('GET', './api/sessions')
|
|
42
|
-
if (!items.length) { box.innerHTML = '<div class="empty">还没有子会话。创建一个,让 AI 在同一宿主里替你干活。</div>'; return }
|
|
43
|
-
box.innerHTML = items.map((s) => {
|
|
44
|
-
const id = esc(s.sessionId || s.id)
|
|
45
|
-
return `<div class="session ${s.closed ? 'closed' : ''}" data-id="${id}">
|
|
46
|
-
<div class="s-title"><span>${esc(s.title || '子会话')}</span>${s.closed ? '<span class="pill">已关闭</span>' : ''}</div>
|
|
47
|
-
<div class="s-id">${id}</div>
|
|
48
|
-
<div class="s-prompt"><input placeholder="下发指令…" data-act="prompt-input"><button class="btn small" data-act="send">发送</button></div>
|
|
49
|
-
<div class="s-actions">
|
|
50
|
-
<button class="btn small" data-act="transcript">转录</button>
|
|
51
|
-
<button class="btn small" data-act="close">关闭</button>
|
|
52
|
-
</div>
|
|
53
|
-
<details hidden><pre class="code" data-out></pre></details>
|
|
54
|
-
</div>`
|
|
55
|
-
}).join('')
|
|
56
|
-
} catch (e) { box.innerHTML = '<div class="empty">加载失败:' + esc(e.message) + '</div>' }
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
$('#create-form').addEventListener('submit', async (ev) => {
|
|
60
|
-
ev.preventDefault()
|
|
61
|
-
const f = ev.target
|
|
62
|
-
const body = { title: f.title.value.trim() || undefined, cwd: f.cwd.value.trim() || undefined, prompt: f.prompt.value.trim() || undefined }
|
|
63
|
-
try {
|
|
64
|
-
const r = await api('POST', './api/sessions', body)
|
|
65
|
-
toast('已创建 ' + r.sessionId.slice(0, 8)); emit('result', { action: 'session.open', sessionId: r.sessionId })
|
|
66
|
-
f.reset(); await loadSessions()
|
|
67
|
-
} catch (e) { toast('创建失败:' + e.message, true); emit('error', { action: 'session.open', message: e.message }) }
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
$('#session-list').addEventListener('click', async (ev) => {
|
|
71
|
-
const btn = ev.target.closest('[data-act]'); if (!btn) return
|
|
72
|
-
const card = btn.closest('.session'); const id = card.dataset.id; const act = btn.dataset.act
|
|
73
|
-
try {
|
|
74
|
-
if (act === 'send') {
|
|
75
|
-
const input = $('[data-act="prompt-input"]', card); const text = input.value.trim()
|
|
76
|
-
if (!text) return toast('先写指令', true)
|
|
77
|
-
const r = await api('POST', './api/sessions/prompt', { sessionId: id, text })
|
|
78
|
-
input.value = ''; toast(r.accepted ? '已下发' : '已排队'); emit('progress', { action: 'session.prompt', sessionId: id })
|
|
79
|
-
} else if (act === 'transcript') {
|
|
80
|
-
const det = $('details', card); const out = $('[data-out]', card)
|
|
81
|
-
const r = await api('GET', './api/sessions/transcript?sessionId=' + encodeURIComponent(id))
|
|
82
|
-
out.textContent = JSON.stringify(r.transcript, null, 2); det.hidden = false
|
|
83
|
-
} else if (act === 'close') {
|
|
84
|
-
await api('POST', './api/sessions/close', { sessionId: id })
|
|
85
|
-
toast('已关闭'); emit('result', { action: 'session.close', sessionId: id }); await loadSessions()
|
|
86
|
-
}
|
|
87
|
-
} catch (e) { toast(e.message, true); emit('error', { action: act, sessionId: id, message: e.message }) }
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
// ---- 设置 ----
|
|
91
|
-
$('#settings-load').addEventListener('click', async () => {
|
|
92
|
-
try { const r = await api('GET', './api/settings'); $('#settings-view').textContent = JSON.stringify(r.settings, null, 2) }
|
|
93
|
-
catch (e) { toast('读取失败:' + e.message, true) }
|
|
94
|
-
})
|
|
95
|
-
$('#settings-form').addEventListener('submit', async (ev) => {
|
|
96
|
-
ev.preventDefault(); const f = ev.target
|
|
97
|
-
let patch; try { patch = JSON.parse(f.patch.value || '{}') } catch { return toast('patch 不是合法 JSON', true) }
|
|
98
|
-
if (!confirm('设置更新为高风险操作,确认提交?')) return
|
|
99
|
-
try {
|
|
100
|
-
const r = await api('POST', './api/settings', { ns: f.ns.value.trim(), patch })
|
|
101
|
-
$('#settings-view').textContent = JSON.stringify(r.value, null, 2)
|
|
102
|
-
toast('设置已更新'); emit('result', { action: 'settings.set', ns: f.ns.value.trim() })
|
|
103
|
-
} catch (e) { toast('更新失败:' + e.message, true); emit('error', { action: 'settings.set', message: e.message }) }
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
// ---- tabs / refresh ----
|
|
107
|
-
$$('.tab').forEach((t) => t.addEventListener('click', () => {
|
|
108
|
-
$$('.tab').forEach((x) => x.classList.toggle('active', x === t))
|
|
109
|
-
$$('.tabpane').forEach((p) => p.classList.toggle('active', p.id === 'tab-' + t.dataset.tab))
|
|
110
|
-
}))
|
|
111
|
-
$('#refresh').addEventListener('click', loadSessions)
|
|
112
|
-
|
|
113
|
-
loadConfig().then(loadSessions)
|
|
114
|
-
})()
|
package/ui/index.html
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="zh">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
-
<title>CapyClaw 子会话工作台</title>
|
|
7
|
-
<link rel="stylesheet" href="./style.css">
|
|
8
|
-
</head>
|
|
9
|
-
<body>
|
|
10
|
-
<header class="topbar standalone-chrome">
|
|
11
|
-
<div class="brand">🪆 CapyClaw <span class="sub">子会话工作台 · 同一宿主进程</span></div>
|
|
12
|
-
<div class="top-actions">
|
|
13
|
-
<span id="avail" class="pill">检测中…</span>
|
|
14
|
-
<button id="refresh" class="btn ghost">刷新</button>
|
|
15
|
-
</div>
|
|
16
|
-
</header>
|
|
17
|
-
|
|
18
|
-
<div class="layout">
|
|
19
|
-
<aside class="panel">
|
|
20
|
-
<nav class="tabs">
|
|
21
|
-
<button class="tab active" data-tab="sessions">子会话</button>
|
|
22
|
-
<button class="tab" data-tab="settings">DSH 设置</button>
|
|
23
|
-
</nav>
|
|
24
|
-
|
|
25
|
-
<section id="tab-sessions" class="tabpane active">
|
|
26
|
-
<form id="create-form" class="card">
|
|
27
|
-
<h3>发起子会话</h3>
|
|
28
|
-
<label>标题<input name="title" placeholder="例如:调研竞品"></label>
|
|
29
|
-
<label>工作目录 cwd<input name="cwd" placeholder="留空=宿主默认"></label>
|
|
30
|
-
<label>首条指令<textarea name="prompt" rows="2" placeholder="可选:创建后立即下发"></textarea></label>
|
|
31
|
-
<button class="btn primary" type="submit">创建</button>
|
|
32
|
-
</form>
|
|
33
|
-
<div id="session-list" class="list"></div>
|
|
34
|
-
</section>
|
|
35
|
-
|
|
36
|
-
<section id="tab-settings" class="tabpane">
|
|
37
|
-
<div class="card">
|
|
38
|
-
<h3>读取设置</h3>
|
|
39
|
-
<button id="settings-load" class="btn">加载 describe</button>
|
|
40
|
-
<pre id="settings-view" class="code"></pre>
|
|
41
|
-
</div>
|
|
42
|
-
<form id="settings-form" class="card">
|
|
43
|
-
<h3>更新设置(高风险,需确认)</h3>
|
|
44
|
-
<label>命名空间 ns<input name="ns" placeholder="profile 条目 id"></label>
|
|
45
|
-
<label>patch(JSON)<textarea name="patch" rows="3" placeholder='{"key":"value"}'></textarea></label>
|
|
46
|
-
<button class="btn danger" type="submit">提交更新</button>
|
|
47
|
-
</form>
|
|
48
|
-
</section>
|
|
49
|
-
</aside>
|
|
50
|
-
|
|
51
|
-
<main class="stage">
|
|
52
|
-
<div class="stage-head standalone-chrome">
|
|
53
|
-
<span>宿主 GUI(俄罗斯套娃 · 同源嵌入)</span>
|
|
54
|
-
<a id="gui-open" class="btn ghost" target="_blank" rel="noopener">新窗打开</a>
|
|
55
|
-
</div>
|
|
56
|
-
<iframe id="gui" class="gui" title="DSH GUI" src="about:blank"></iframe>
|
|
57
|
-
</main>
|
|
58
|
-
</div>
|
|
59
|
-
|
|
60
|
-
<div id="toast" class="toast"></div>
|
|
61
|
-
<script src="./embed.js"></script>
|
|
62
|
-
<script src="./app.js"></script>
|
|
63
|
-
</body>
|
|
64
|
-
</html>
|
package/ui/style.css
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
:root{
|
|
2
|
-
--bg:#0f1117; --panel:#161a23; --card:#1d2230; --line:#2a3040;
|
|
3
|
-
--ink:#e6e9f0; --mut:#8b93a7; --acc:#5b9bd5; --ok:#3fb96f; --warn:#e0a34e; --bad:#e05b6f;
|
|
4
|
-
--r:10px;
|
|
5
|
-
}
|
|
6
|
-
*{box-sizing:border-box}
|
|
7
|
-
html,body{height:100%;margin:0}
|
|
8
|
-
body{background:var(--bg);color:var(--ink);font:14px/1.5 system-ui,"Segoe UI",Roboto,"Noto Sans SC",sans-serif;display:flex;flex-direction:column}
|
|
9
|
-
.topbar{display:flex;align-items:center;justify-content:space-between;padding:10px 16px;border-bottom:1px solid var(--line);background:var(--panel)}
|
|
10
|
-
.brand{font-weight:700;font-size:16px}
|
|
11
|
-
.brand .sub{font-weight:400;color:var(--mut);font-size:12px;margin-left:8px}
|
|
12
|
-
.top-actions{display:flex;gap:8px;align-items:center}
|
|
13
|
-
.pill{font-size:12px;color:var(--mut);border:1px solid var(--line);border-radius:999px;padding:2px 10px}
|
|
14
|
-
.pill.ok{color:var(--ok);border-color:var(--ok)}
|
|
15
|
-
.pill.bad{color:var(--bad);border-color:var(--bad)}
|
|
16
|
-
.layout{flex:1;display:flex;min-height:0}
|
|
17
|
-
.panel{width:340px;min-width:280px;border-right:1px solid var(--line);background:var(--panel);display:flex;flex-direction:column;overflow:hidden}
|
|
18
|
-
.tabs{display:flex;border-bottom:1px solid var(--line)}
|
|
19
|
-
.tab{flex:1;background:none;border:none;color:var(--mut);padding:10px;cursor:pointer;font-size:14px;border-bottom:2px solid transparent}
|
|
20
|
-
.tab.active{color:var(--ink);border-bottom-color:var(--acc)}
|
|
21
|
-
.tabpane{display:none;overflow-y:auto;padding:12px;flex:1}
|
|
22
|
-
.tabpane.active{display:block}
|
|
23
|
-
.card{background:var(--card);border:1px solid var(--line);border-radius:var(--r);padding:12px;margin-bottom:12px}
|
|
24
|
-
.card h3{margin:0 0 10px;font-size:13px;color:var(--mut);font-weight:600}
|
|
25
|
-
label{display:block;font-size:12px;color:var(--mut);margin-bottom:8px}
|
|
26
|
-
input,textarea{width:100%;margin-top:4px;background:var(--bg);border:1px solid var(--line);border-radius:6px;color:var(--ink);padding:7px 9px;font:inherit;resize:vertical}
|
|
27
|
-
input:focus,textarea:focus{outline:none;border-color:var(--acc)}
|
|
28
|
-
.btn{background:var(--card);border:1px solid var(--line);color:var(--ink);border-radius:6px;padding:7px 12px;cursor:pointer;font:inherit}
|
|
29
|
-
.btn:hover{border-color:var(--acc)}
|
|
30
|
-
.btn.primary{background:var(--acc);border-color:var(--acc);color:#fff;width:100%}
|
|
31
|
-
.btn.danger{background:var(--bad);border-color:var(--bad);color:#fff;width:100%}
|
|
32
|
-
.btn.ghost{background:transparent}
|
|
33
|
-
.btn.small{padding:3px 8px;font-size:12px}
|
|
34
|
-
.list{display:flex;flex-direction:column;gap:8px}
|
|
35
|
-
.session{background:var(--card);border:1px solid var(--line);border-radius:var(--r);padding:10px}
|
|
36
|
-
.session.closed{opacity:.55}
|
|
37
|
-
.session .s-title{font-weight:600;display:flex;justify-content:space-between;align-items:center}
|
|
38
|
-
.session .s-id{font-size:11px;color:var(--mut);font-family:ui-monospace,monospace;word-break:break-all}
|
|
39
|
-
.session .s-actions{display:flex;gap:6px;margin-top:8px;flex-wrap:wrap}
|
|
40
|
-
.session .s-prompt{display:flex;gap:6px;margin-top:8px}
|
|
41
|
-
.session .s-prompt input{flex:1;margin:0}
|
|
42
|
-
.session details{margin-top:8px}
|
|
43
|
-
.session pre{max-height:220px;overflow:auto}
|
|
44
|
-
.code{background:var(--bg);border:1px solid var(--line);border-radius:6px;padding:8px;font:12px/1.5 ui-monospace,monospace;white-space:pre-wrap;word-break:break-word;max-height:260px;overflow:auto;margin:8px 0 0}
|
|
45
|
-
.stage{flex:1;display:flex;flex-direction:column;min-width:0}
|
|
46
|
-
.stage-head{display:flex;justify-content:space-between;align-items:center;padding:8px 14px;border-bottom:1px solid var(--line);color:var(--mut);font-size:12px;background:var(--panel)}
|
|
47
|
-
.gui{flex:1;border:none;width:100%;background:#fff}
|
|
48
|
-
.toast{position:fixed;left:50%;bottom:22px;transform:translateX(-50%);background:var(--card);border:1px solid var(--line);border-radius:8px;padding:9px 16px;opacity:0;pointer-events:none;transition:opacity .2s;max-width:80vw}
|
|
49
|
-
.toast.show{opacity:1}
|
|
50
|
-
.toast.err{border-color:var(--bad);color:var(--bad)}
|
|
51
|
-
.empty{color:var(--mut);text-align:center;padding:20px;font-size:13px}
|
|
52
|
-
/* 嵌入模式:隐藏 standalone chrome,交给父窗编排(标准 §C.7) */
|
|
53
|
-
body.capyclaw-embedded .standalone-chrome{display:none}
|
|
54
|
-
body.capyclaw-embedded .panel{width:300px}
|