@restregular/dsh-team-hub 0.1.0 → 0.3.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/README.md CHANGED
@@ -1,10 +1,13 @@
1
1
  # @restregular/dsh-team-hub
2
2
 
3
- DSH 团队中枢:画布式 Agent 协作看板。
3
+ DSH 团队中枢:无限画布式 Agent 协作看板。
4
4
 
5
- - 侧边栏按钮切换到全屏团队画布,卡片可自由拖拽。
6
- - 每会话 = 一个 Agent 卡片;派任务 / 发消息 / 查状态 / 读回复 / 跳会话。
7
- - 工具层:`team_hub_list_agents` / `team_hub_send` / `team_hub_status` / `team_hub_reply` / `team_hub_create_agent`。
5
+ - 工作区行「…」→「在团队中枢打开」进入绑定工作区的画布;点击卡片气泡切回原生会话,画布缩到右侧栏。
6
+ - 无限画布:拖拽空白处平移、Ctrl+滚轮以鼠标为锚点缩放、方格背景、随缩放变化的自定义鼠标。
7
+ - 每会话 = 一个 Agent 卡片:实例化 / 刷新实例(保存与恢复进度提示词)/ 移除(自动归档会话,可恢复)/ 发消息 / 工具日志。
8
+ - 卡片上方外部聊天气泡滚动展示实时会话内容;协作仅沟通后连线并动画传递。
9
+ - 团队看板浮窗:公开团队任务 + 全 Agent 工具调用日志。
10
+ - 工具层:`team_hub_list_agents` / `find_agent` / `send` / `status` / `reply` / `create_agent` / `public_tasks` / `set_public_task`。
8
11
  - 权限:禁用工具为代码硬约束;身份与文件边界为提示词软约束。
9
12
  - 状态持久化于 `~/.dsh/team-hub/board.json`。
10
13
 
package/client.js CHANGED
@@ -155,9 +155,25 @@
155
155
  )
156
156
  }
157
157
 
158
+ /** 按缩放生成鼠标指针:白底+深色描边在深浅背景都清晰,尺寸随 zoom 变化。 */
159
+ function makeCursor(scale, grabbing) {
160
+ const s = Math.max(0.6, Math.min(2.2, scale || 1))
161
+ const size = Math.round(28 * s)
162
+ const sw = (1.6 * s).toFixed(2)
163
+ const path = grabbing
164
+ ? `M9 12 V7 a2 2 0 0 1 4 0 v4 a2 2 0 0 1 4 0 v1 a2 2 0 0 1 4 0 v5 c0 4-3 7-7 7 h-2 c-3 0-5-2-6-4 l-3-5 a2 2 0 0 1 3-2 l3 3 z`
165
+ : `M5 2 L5 22 L10 17 L14 25 L18 23 L14 15 L21 15 Z`
166
+ const raw = `<svg xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}" viewBox="0 0 28 28"><path d="${path}" fill="#ffffff" stroke="#111827" stroke-width="${sw}" stroke-linejoin="round"/></svg>`
167
+ const hx = Math.round((grabbing ? 12 : 5) * s)
168
+ const hy = Math.round((grabbing ? 8 : 2) * s)
169
+ return `url("data:image/svg+xml,${encodeURIComponent(raw)}") ${hx} ${hy}, ${grabbing ? 'grabbing' : 'grab'}`
170
+ }
171
+
158
172
  /* ------------------------------------------------------------- 样式 */
159
173
  const CSS = `
160
- .th-root { position:relative; display:flex; flex-direction:column; width:100%; height:100%; min-height:0; overflow:hidden; background:var(--dsw-alias-bg-base); color:var(--dsw-alias-label-primary); font-family:inherit; }
174
+ .th-root { position:relative; display:flex; flex-direction:column; width:100%; height:100%; min-height:0; overflow:hidden; background:var(--dsw-alias-bg-base); color:var(--dsw-alias-label-primary); font-family:inherit; user-select:none; -webkit-user-select:none; }
175
+ .th-root button, .th-root input, .th-root textarea { user-select:none; -webkit-user-select:none; }
176
+ .th-root input, .th-root textarea { user-select:text; -webkit-user-select:text; }
161
177
  .th-compact .th-bar { padding:8px 10px; gap:6px; }
162
178
  .th-compact .th-title, .th-compact .th-sub { font-size:11px; }
163
179
  .th-compact .th-ws-chip { max-width:120px; font-size:10px; }
@@ -182,10 +198,12 @@
182
198
  .th-zoom button { appearance:none; border:0; background:var(--dsw-alias-bg-layer-2); color:var(--dsw-alias-label-primary); width:26px; height:26px; font-size:14px; cursor:pointer; transition:background .16s ease; }
183
199
  .th-zoom button:hover { background:var(--dsw-alias-interactive-bg-hover); }
184
200
  .th-zoom span { min-width:46px; text-align:center; font-size:11px; color:var(--dsw-alias-label-secondary); font-variant-numeric:tabular-nums; }
185
- .th-canvas { position:relative; flex:1 1 auto; min-height:0; overflow:auto; background-color:var(--dsw-alias-bg-base); background-image:radial-gradient(var(--dsw-alias-border-l1) 1px, transparent 1px); background-size:22px 22px; cursor:grab; }
186
- .th-canvas.th-panning { cursor:grabbing; }
187
- .th-stage { position:relative; }
188
- .th-world { position:absolute; left:0; top:0; width:2400px; height:1600px; transform-origin:0 0; }
201
+ .th-canvas { position:relative; flex:1 1 auto; min-height:0; overflow:hidden; background-color:var(--dsw-alias-bg-layer-1); background-image:linear-gradient(to right, var(--dsw-alias-border-l1) 1px, transparent 1px), linear-gradient(to bottom, var(--dsw-alias-border-l1) 1px, transparent 1px); background-size:24px 24px; cursor:var(--th-cursor, grab); }
202
+ .th-canvas *, .th-node, .th-node * { cursor:var(--th-cursor, grab) !important; }
203
+ .th-canvas .th-btn, .th-canvas button { cursor:var(--th-cursor, grab) !important; }
204
+ .th-stage { position:absolute; inset:0; pointer-events:none; }
205
+ .th-world { position:absolute; left:0; top:0; transform-origin:0 0; pointer-events:none; }
206
+ .th-world > * { pointer-events:auto; }
189
207
  .th-links { position:absolute; inset:0; width:100%; height:100%; pointer-events:none; overflow:visible; }
190
208
  .th-link { stroke:var(--dsw-alias-brand-primary); stroke-width:1.8; opacity:.38; fill:none; }
191
209
  .th-packet { fill:var(--dsw-alias-brand-primary); }
@@ -229,8 +247,22 @@
229
247
  .th-modal { width:460px; max-width:92vw; max-height:86vh; overflow:auto; background:var(--dsw-alias-bg-layer-1); border:1px solid var(--dsw-alias-border-l2); border-radius:16px; padding:20px; box-shadow:0 24px 70px rgba(0,0,0,.4); animation:th-rise .24s cubic-bezier(.2,.8,.2,1) both; }
230
248
  @keyframes th-rise { from{opacity:0; transform:translateY(18px) scale(.97)} to{opacity:1; transform:none} }
231
249
  .th-modal h3 { margin:0 0 14px; font-size:16px; }
232
- .th-field { display:flex; flex-direction:column; gap:5px; margin-bottom:12px; }
250
+ .th-field { display:flex; flex-direction:column; gap:5px; margin-bottom:12px; flex:1 1 auto; min-width:0; }
233
251
  .th-field label { font-size:11px; color:var(--dsw-alias-label-secondary); }
252
+ .th-form { width:480px; padding:0; }
253
+ .th-form-head { display:flex; align-items:center; gap:10px; padding:16px 18px 12px; border-bottom:1px solid var(--dsw-alias-border-l1); }
254
+ .th-form-head h3 { margin:0; flex:1 1 auto; }
255
+ .th-form-emoji { font-size:24px; }
256
+ .th-x { appearance:none; border:0; background:transparent; color:var(--dsw-alias-label-secondary); font-size:22px; line-height:1; cursor:pointer; padding:0 4px; }
257
+ .th-x:hover { color:var(--dsw-alias-label-primary); }
258
+ .th-form-row { display:flex; gap:12px; padding:14px 18px 0; }
259
+ .th-tabs { display:flex; gap:4px; padding:0 18px; border-bottom:1px solid var(--dsw-alias-border-l1); }
260
+ .th-tab { appearance:none; border:0; border-bottom:2px solid transparent; background:transparent; color:var(--dsw-alias-label-secondary); padding:8px 14px; font-size:12px; cursor:pointer; transition:color .16s ease, border-color .16s ease; }
261
+ .th-tab.on { color:var(--dsw-alias-brand-primary); border-color:var(--dsw-alias-brand-primary); font-weight:600; }
262
+ .th-form-body { padding:14px 18px 4px; max-height:52vh; overflow:auto; }
263
+ .th-textarea.th-sm { min-height:58px; }
264
+ .th-textarea.th-xs { min-height:44px; }
265
+ .th-form .th-modal-foot { padding:0 18px 16px; }
234
266
  .th-bind { background:var(--dsw-alias-bg-layer-2); border:1px solid var(--dsw-alias-border-l1); border-radius:8px; padding:8px 10px; font-size:11.5px; color:var(--dsw-alias-label-secondary); margin-bottom:14px; }
235
267
  .th-input, .th-textarea { width:100%; box-sizing:border-box; background:var(--dsw-alias-bg-base); color:var(--dsw-alias-label-primary); border:1px solid var(--dsw-alias-border-l2); border-radius:8px; padding:8px 10px; font-size:12.5px; font-family:inherit; transition:border-color .16s ease; }
236
268
  .th-input:focus, .th-textarea:focus { outline:none; border-color:var(--dsw-alias-brand-primary); }
@@ -247,6 +279,34 @@
247
279
  @keyframes th-slide { from{opacity:0; transform:translateX(10px)} to{opacity:1; transform:none} }
248
280
  .th-log b { color:var(--dsw-alias-label-primary); font-weight:600; }
249
281
  .th-empty { position:absolute; inset:0; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:10px; color:var(--dsw-alias-label-secondary); font-size:13px; }
282
+ /* 团队看板浮窗 */
283
+ .th-board-panel { position:absolute; right:14px; top:56px; width:380px; max-height:calc(100% - 70px); overflow:auto; background:var(--dsw-alias-bg-overlay); border:1px solid var(--dsw-alias-border-l2); border-radius:14px; box-shadow:0 12px 40px rgba(0,0,0,.3); z-index:60; animation:th-rise .2s ease both; padding:14px 16px; }
284
+ .th-board-head { display:flex; align-items:center; margin-bottom:10px; }
285
+ .th-board-head h3 { margin:0; flex:1 1 auto; font-size:14px; }
286
+ .th-board-section { margin-top:12px; border-top:1px solid var(--dsw-alias-border-l1); padding-top:10px; }
287
+ .th-board-sub { font-size:11px; color:var(--dsw-alias-label-secondary); margin-bottom:8px; font-weight:600; }
288
+ .th-task-add { display:flex; gap:6px; margin-bottom:8px; }
289
+ .th-task-add .th-input { flex:1 1 auto; min-width:0; padding:5px 8px; font-size:11px; }
290
+ .th-task-add .th-btn { flex:0 0 auto; padding:4px 10px; }
291
+ .th-task-list { display:flex; flex-direction:column; gap:6px; max-height:220px; overflow:auto; }
292
+ .th-task-item { display:flex; align-items:flex-start; gap:8px; padding:7px 8px; border:1px solid var(--dsw-alias-border-l1); border-radius:8px; background:var(--dsw-alias-bg-layer-1); }
293
+ .th-task-status { flex:0 0 auto; appearance:none; border:0; border-radius:6px; font-size:10px; padding:2px 7px; cursor:pointer; background:var(--dsw-alias-bg-layer-2); color:var(--dsw-alias-label-secondary); }
294
+ .th-task-status.doing { color:var(--dsw-alias-state-warn-primary); }
295
+ .th-task-status.done { color:var(--dsw-alias-state-success-primary); }
296
+ .th-task-body { flex:1 1 auto; min-width:0; }
297
+ .th-task-title { font-size:12px; color:var(--dsw-alias-label-primary); }
298
+ .th-task-detail { font-size:10.5px; color:var(--dsw-alias-label-secondary); margin-top:2px; word-break:break-word; }
299
+ .th-muted { font-size:11px; color:var(--dsw-alias-label-secondary); text-align:center; padding:12px; }
300
+ .th-log-agents { display:flex; flex-wrap:wrap; gap:6px; margin-top:8px; }
301
+ .th-log-agents .th-btn { padding:4px 9px; font-size:11px; }
302
+ .th-logs { width:640px; padding:0; }
303
+ .th-log-list { padding:12px 18px 18px; max-height:60vh; overflow:auto; }
304
+ .th-log-item { padding:8px 10px; border:1px solid var(--dsw-alias-border-l1); border-radius:8px; margin-bottom:7px; background:var(--dsw-alias-bg-layer-1); animation:th-slide .25s ease both; }
305
+ .th-log-meta { display:flex; align-items:center; gap:10px; font-size:10.5px; }
306
+ .th-log-tool { color:var(--dsw-alias-brand-primary); font-weight:600; }
307
+ .th-log-agent { color:var(--dsw-alias-label-secondary); }
308
+ .th-log-time { margin-left:auto; color:var(--dsw-alias-label-secondary); }
309
+ .th-log-detail { margin-top:5px; font-size:11px; color:var(--dsw-alias-label-secondary); word-break:break-all; font-family:var(--dsw-font-mono, monospace); }
250
310
  /* 右侧栏里的紧凑画布 */
251
311
  .th-side { display:flex; flex-direction:column; height:100%; min-height:0; font-family:inherit; color:var(--dsw-alias-label-primary); background:var(--dsw-alias-bg-base); }
252
312
  .th-side-bar { display:flex; align-items:center; gap:8px; padding:10px 12px; border-bottom:1px solid var(--dsw-alias-border-l1); font-size:12px; flex:0 0 auto; }
@@ -309,7 +369,7 @@
309
369
  )
310
370
  }
311
371
 
312
- function AgentCard({ agent, feed, notices, onDragStart, onMessage, onOpen, onEdit, onRemove, onStatus, onInstantiate }) {
372
+ function AgentCard({ agent, feed, notices, onDragStart, onMessage, onOpen, onEdit, onRemove, onStatus, onInstantiate, onRefresh, onLogs }) {
313
373
  const status = statusOf(agent)
314
374
  const sid = agent.sessionId
315
375
  const extra = sid ? (notices[sid] || []) : []
@@ -346,9 +406,10 @@
346
406
  h('div', { className: 'th-foot' },
347
407
  h('button', { className: 'th-btn primary', onClick: () => onMessage(agent) }, '发消息'),
348
408
  h('button', { className: 'th-btn', onClick: () => onOpen(agent) }, '打开会话'),
409
+ h('button', { className: 'th-btn', onClick: () => onLogs(agent) }, '工具日志'),
349
410
  ),
350
411
  h('div', { className: 'th-foot' },
351
- h('button', { className: 'th-btn', onClick: () => onStatus(agent) }, '状态'),
412
+ h('button', { className: 'th-btn', onClick: () => onRefresh(agent) }, '刷新实例'),
352
413
  h('button', { className: 'th-btn', onClick: () => onEdit(agent) }, '编辑'),
353
414
  h('button', { className: 'th-btn danger', onClick: () => onRemove(agent) }, '移除'),
354
415
  ),
@@ -359,20 +420,43 @@
359
420
 
360
421
  function AgentForm({ agent, t, workspaceTitle, onClose, onSave }) {
361
422
  const [form, setForm] = useState(agent || { icon: '🤖', name: '', identity: '', duties: '', permissions: { denyTools: '', writeFiles: '', readFiles: '' } })
423
+ const [tab, setTab] = useState('basic')
362
424
  const set = (k, v) => setForm((f) => ({ ...f, [k]: v }))
363
425
  const setPerm = (k, v) => setForm((f) => ({ ...f, permissions: { ...f.permissions, [k]: v } }))
364
426
  const split = (v) => String(v || '').split(/[,,\n]/).map((s) => s.trim()).filter(Boolean)
427
+ const field = (label, control) => h('div', { className: 'th-field' }, h('label', null, label), control)
365
428
  return h('div', { className: 'th-overlay', onPointerDown: (e) => { if (e.target === e.currentTarget) onClose() } },
366
- h('div', { className: 'th-modal' },
367
- h('h3', null, agent ? t('editAgent') : t('newAgent')),
368
- !agent && h('div', { className: 'th-bind' }, '🔗 ', t('newAgentHint'), ':', workspaceTitle || t('noWorkspace')),
369
- h('div', { className: 'th-field' }, h('label', null, t('icon')), h('input', { className: 'th-input', value: form.icon, onChange: (e) => set('icon', e.target.value) })),
370
- h('div', { className: 'th-field' }, h('label', null, t('name')), h('input', { className: 'th-input', value: form.name, onChange: (e) => set('name', e.target.value), placeholder: '例如:研究员' })),
371
- h('div', { className: 'th-field' }, h('label', null, t('identity')), h('textarea', { className: 'th-textarea', value: form.identity, onChange: (e) => set('identity', e.target.value) })),
372
- h('div', { className: 'th-field' }, h('label', null, t('duties')), h('textarea', { className: 'th-textarea', value: form.duties, onChange: (e) => set('duties', e.target.value) })),
373
- h('div', { className: 'th-field' }, h('label', null, t('denyTools')), h('input', { className: 'th-input', value: form.permissions.denyTools || '', onChange: (e) => setPerm('denyTools', e.target.value), placeholder: 'bash, pwsh(硬约束)' })),
374
- h('div', { className: 'th-field' }, h('label', null, t('writeFiles')), h('input', { className: 'th-input', value: form.permissions.writeFiles || '', onChange: (e) => setPerm('writeFiles', e.target.value), placeholder: '仅提示词约束' })),
375
- h('div', { className: 'th-field' }, h('label', null, t('readFiles')), h('input', { className: 'th-input', value: form.permissions.readFiles || '', onChange: (e) => setPerm('readFiles', e.target.value), placeholder: '仅提示词约束' })),
429
+ h('div', { className: 'th-modal th-form' },
430
+ h('div', { className: 'th-form-head' },
431
+ h('span', { className: 'th-form-emoji' }, form.icon || '🤖'),
432
+ h('h3', null, agent ? t('editAgent') : t('newAgent')),
433
+ h('button', { className: 'th-x', onClick: onClose, title: t('cancel') }, '×'),
434
+ ),
435
+ h('div', { className: 'th-form-row' },
436
+ field(t('icon'), h('input', { className: 'th-input', value: form.icon, onChange: (e) => set('icon', e.target.value), style: { maxWidth: 72 } })),
437
+ field(t('name'), h('input', { className: 'th-input', value: form.name, onChange: (e) => set('name', e.target.value), placeholder: '例如:研究员' })),
438
+ ),
439
+ h('div', { className: 'th-tabs' },
440
+ h('button', { className: `th-tab ${tab === 'basic' ? 'on' : ''}`, onClick: () => setTab('basic') }, t('basicTab')),
441
+ h('button', { className: `th-tab ${tab === 'adv' ? 'on' : ''}`, onClick: () => setTab('adv') }, t('advTab')),
442
+ ),
443
+ h('div', { className: 'th-form-body' },
444
+ tab === 'basic'
445
+ ? h('div', null,
446
+ field(t('identity'), h('textarea', { className: 'th-textarea th-sm', value: form.identity, onChange: (e) => set('identity', e.target.value), placeholder: t('identity') })),
447
+ field(t('duties'), h('textarea', { className: 'th-textarea th-sm', value: form.duties, onChange: (e) => set('duties', e.target.value), placeholder: t('duties') })),
448
+ )
449
+ : h('div', null,
450
+ !agent && h('div', { className: 'th-bind' }, '🔗 ', t('newAgentHint'), ':', workspaceTitle || t('noWorkspace')),
451
+ field(t('savePrompt'), h('textarea', { className: 'th-textarea th-sm', value: form.savePrompt || '', onChange: (e) => set('savePrompt', e.target.value), placeholder: t('defaultSavePrompt') })),
452
+ field(t('restorePrompt'), h('textarea', { className: 'th-textarea th-sm', value: form.restorePrompt || '', onChange: (e) => set('restorePrompt', e.target.value), placeholder: t('defaultRestorePrompt') })),
453
+ field(t('denyTools'), h('textarea', { className: 'th-textarea th-xs', value: form.permissions.denyTools || '', onChange: (e) => setPerm('denyTools', e.target.value), placeholder: '每行一个工具名,如 bash / pwsh(硬约束)' })),
454
+ h('div', { className: 'th-form-row' },
455
+ field(t('writeFiles'), h('textarea', { className: 'th-textarea th-xs', value: form.permissions.writeFiles || '', onChange: (e) => setPerm('writeFiles', e.target.value), placeholder: '每行一个可写路径(提示约束)' })),
456
+ field(t('readFiles'), h('textarea', { className: 'th-textarea th-xs', value: form.permissions.readFiles || '', onChange: (e) => setPerm('readFiles', e.target.value), placeholder: '每行一个可读路径(提示约束)' })),
457
+ ),
458
+ ),
459
+ ),
376
460
  h('div', { className: 'th-modal-foot' },
377
461
  h('button', { className: 'th-btn', onClick: onClose }, t('cancel')),
378
462
  h('button', {
@@ -411,6 +495,130 @@
411
495
  )
412
496
  }
413
497
 
498
+ /** 刷新实例弹窗:设置保存/恢复进度提示词,把 Agent 换绑到新会话。 */
499
+ function RefreshModal({ agent, t, busy, onClose, onRun }) {
500
+ const [saveText, setSaveText] = useState(agent.savePrompt || t('defaultSavePrompt'))
501
+ const [restoreText, setRestoreText] = useState(agent.restorePrompt || t('defaultRestorePrompt'))
502
+ return h('div', { className: 'th-overlay', onPointerDown: (e) => { if (e.target === e.currentTarget && !busy) onClose() } },
503
+ h('div', { className: 'th-modal' },
504
+ h('h3', null, `${t('refreshInstance')} · ${agent.name}`),
505
+ h('div', { className: 'th-bind' }, t('refreshHint')),
506
+ h('div', { className: 'th-field' },
507
+ h('label', null, t('savePrompt')),
508
+ h('textarea', { className: 'th-textarea', value: saveText, onChange: (e) => setSaveText(e.target.value), disabled: busy }),
509
+ ),
510
+ h('div', { className: 'th-field' },
511
+ h('label', null, t('restorePrompt')),
512
+ h('textarea', { className: 'th-textarea', value: restoreText, onChange: (e) => setRestoreText(e.target.value), disabled: busy }),
513
+ ),
514
+ h('div', { className: 'th-modal-foot' },
515
+ h('button', { className: 'th-btn', onClick: onClose, disabled: busy }, t('cancel')),
516
+ h('button', {
517
+ className: 'th-btn primary', disabled: busy,
518
+ onClick: () => onRun({ saveText, restoreText }),
519
+ }, busy ? t('refreshing') : t('startRefresh')),
520
+ ),
521
+ ),
522
+ )
523
+ }
524
+
525
+ /** 工具调用日志查看器:可看全部 Agent 或某个 Agent 的日志。 */
526
+ function ToolLogPanel({ t, agent, onClose }) {
527
+ const [logs, setLogs] = useState([])
528
+ useEffect(() => {
529
+ let alive = true
530
+ const load = async () => {
531
+ try {
532
+ const q = agent ? `?agentId=${encodeURIComponent(agent.id)}` : ''
533
+ const d = await api('/tool-logs' + q)
534
+ if (alive) setLogs((d || []).slice().reverse())
535
+ } catch {}
536
+ }
537
+ load()
538
+ const id = setInterval(load, 4000)
539
+ return () => { alive = false; clearInterval(id) }
540
+ }, [agent])
541
+ return h('div', { className: 'th-overlay', onPointerDown: (e) => { if (e.target === e.currentTarget) onClose() } },
542
+ h('div', { className: 'th-modal th-logs' },
543
+ h('div', { className: 'th-form-head' },
544
+ h('h3', null, `${t('toolLogs')}${agent ? ` · ${agent.name}` : ''}`),
545
+ h('button', { className: 'th-x', onClick: onClose }, '×'),
546
+ ),
547
+ h('div', { className: 'th-log-list' },
548
+ logs.length === 0
549
+ ? h('div', { style: { padding: 30, textAlign: 'center', color: 'var(--dsw-alias-label-secondary)', fontSize: 12 } }, t('noLogs'))
550
+ : logs.map((l) => {
551
+ const a = agent || null
552
+ return h('div', { className: 'th-log-item', key: l.id },
553
+ h('div', { className: 'th-log-meta' },
554
+ h('span', { className: 'th-log-tool' }, l.tool),
555
+ a ? null : h('span', { className: 'th-log-agent' }, (l.agentId || '—').slice(0, 8)),
556
+ h('span', { className: 'th-log-time' }, new Date(l.at).toLocaleTimeString()),
557
+ ),
558
+ h('div', { className: 'th-log-detail' }, l.detail || '—'),
559
+ )
560
+ }),
561
+ ),
562
+ ),
563
+ )
564
+ }
565
+
566
+ /** 团队看板浮窗:公开团队任务 + 全部工具日志入口。 */
567
+ function TeamBoardPanel({ t, agents, onClose, onLogs, refreshKey }) {
568
+ const [tasks, setTasks] = useState([])
569
+ const [title, setTitle] = useState('')
570
+ const [detail, setDetail] = useState('')
571
+ const load = useCallback(async () => {
572
+ try { setTasks((await api('/public-tasks')) || []) } catch {}
573
+ }, [])
574
+ useEffect(() => { load(); const id = setInterval(load, 5000); return () => clearInterval(id) }, [load])
575
+ useEffect(() => { load() }, [refreshKey, load])
576
+ const add = async () => {
577
+ if (!title.trim()) return
578
+ try { await api('/public-task', { method: 'POST', body: { title: title.trim(), detail: detail.trim() } }); setTitle(''); setDetail(''); load() } catch {}
579
+ }
580
+ const cycle = async (task) => {
581
+ const next = task.status === 'open' ? 'doing' : task.status === 'doing' ? 'done' : 'open'
582
+ try { await api('/public-task', { method: 'POST', body: { ...task, status: next } }); load() } catch {}
583
+ }
584
+ const del = async (task) => {
585
+ try { await api('/public-task?id=' + encodeURIComponent(task.id), { method: 'DELETE' }); load() } catch {}
586
+ }
587
+ return h('div', { className: 'th-board-panel' },
588
+ h('div', { className: 'th-board-head' },
589
+ h('h3', null, t('teamBoard')),
590
+ h('button', { className: 'th-x', onClick: onClose }, '×'),
591
+ ),
592
+ h('div', { className: 'th-board-section' },
593
+ h('div', { className: 'th-board-sub' }, t('publicTasks')),
594
+ h('div', { className: 'th-task-add' },
595
+ h('input', { className: 'th-input', value: title, onChange: (e) => setTitle(e.target.value), placeholder: t('taskTitle') }),
596
+ h('input', { className: 'th-input', value: detail, onChange: (e) => setDetail(e.target.value), placeholder: t('taskDetail') }),
597
+ h('button', { className: 'th-btn primary', onClick: add, disabled: !title.trim() }, '+'),
598
+ ),
599
+ h('div', { className: 'th-task-list' },
600
+ tasks.length === 0
601
+ ? h('div', { className: 'th-muted' }, t('noTasks'))
602
+ : tasks.map((task) => h('div', { className: 'th-task-item', key: task.id },
603
+ h('button', { className: `th-task-status ${task.status}`, onClick: () => cycle(task), title: t('cycleStatus') }, task.status),
604
+ h('div', { className: 'th-task-body' },
605
+ h('div', { className: 'th-task-title' }, task.title),
606
+ task.detail ? h('div', { className: 'th-task-detail' }, task.detail) : null,
607
+ ),
608
+ h('button', { className: 'th-x', onClick: () => del(task) }, '×'),
609
+ )),
610
+ ),
611
+ ),
612
+ h('div', { className: 'th-board-section' },
613
+ h('div', { className: 'th-board-sub' }, t('toolLogs')),
614
+ h('button', { className: 'th-btn', style: { width: '100%' }, onClick: () => onLogs(null) }, `${t('allAgents')} →`),
615
+ h('div', { className: 'th-log-agents' },
616
+ agents.map((a) => h('button', { className: 'th-btn', key: a.id, onClick: () => onLogs(a) }, `${a.icon || '🤖'} ${a.name}`)),
617
+ ),
618
+ ),
619
+ )
620
+ }
621
+
414
622
  /** 右侧栏紧凑画布:与中央画布共享同一份看板数据,点击卡片打开对应原生会话。 */
415
623
  /** 右侧栏里渲染的是同一个完整画布(拖拽/缩放/气泡/连线俱全),不是列表。 */
416
624
  function SidebarCanvas(props) {
@@ -461,14 +669,23 @@
461
669
  const [toast, setToast] = useState('')
462
670
  const [form, setForm] = useState(null)
463
671
  const [composer, setComposer] = useState(null)
672
+ const [refreshing, setRefreshing] = useState(null)
673
+ const [refreshBusy, setRefreshBusy] = useState(false)
674
+ const [boardOpen, setBoardOpen] = useState(false)
675
+ const [logAgent, setLogAgent] = useState(undefined) // undefined=不显示, null=全部, 对象=某 Agent
676
+ const [boardKey, setBoardKey] = useState(0)
464
677
  const [activity, setActivity] = useState([])
465
678
  const [pulses, setPulses] = useState([])
466
679
  const [zoom, setZoom] = useState(props.compact ? 0.6 : 1)
680
+ const [pan, setPan] = useState({ x: 60, y: 60 })
681
+ const [panning, setPanning] = useState(false)
467
682
  const dragRef = useRef(null)
468
683
  const worldRef = useRef(null)
469
684
  const canvasRef = useRef(null)
470
685
  const zoomRef = useRef(zoom)
686
+ const panRef = useRef(pan)
471
687
  useEffect(() => { zoomRef.current = zoom }, [zoom])
688
+ useEffect(() => { panRef.current = pan }, [pan])
472
689
 
473
690
  const refresh = useCallback(async () => {
474
691
  try {
@@ -505,37 +722,50 @@
505
722
  }, [archivedIds, archiveReady, removedAgents])
506
723
 
507
724
  const setZoomClamped = useCallback((next) => setZoom(Math.min(2, Math.max(0.4, Math.round(next * 10) / 10))), [])
725
+ // Ctrl+滚轮:以鼠标位置为锚点缩放(无限画布,不受固定边界限制)。
508
726
  useEffect(() => {
509
727
  const el = canvasRef.current
510
728
  if (!el) return
511
729
  const onWheel = (ev) => {
512
- if (!ev.ctrlKey && !ev.metaKey) return
513
730
  ev.preventDefault()
514
- setZoomClamped(zoomRef.current + (ev.deltaY < 0 ? 0.1 : -0.1))
731
+ const rect = el.getBoundingClientRect()
732
+ const mx = ev.clientX - rect.left, my = ev.clientY - rect.top
733
+ if (ev.ctrlKey || ev.metaKey) {
734
+ const old = zoomRef.current
735
+ const next = Math.min(2, Math.max(0.4, Math.round((old + (ev.deltaY < 0 ? 0.1 : -0.1)) * 10) / 10))
736
+ if (next === old) return
737
+ const p = panRef.current
738
+ // 保持鼠标下的世界坐标不变:world = (mouse - pan)/zoom
739
+ const wx = (mx - p.x) / old, wy = (my - p.y) / old
740
+ setPan({ x: mx - wx * next, y: my - wy * next })
741
+ setZoom(next)
742
+ } else {
743
+ // 普通滚轮也可平移画布
744
+ setPan((cur) => ({ x: cur.x - ev.deltaX, y: cur.y - ev.deltaY }))
745
+ }
515
746
  }
516
747
  el.addEventListener('wheel', onWheel, { passive: false })
517
748
  return () => el.removeEventListener('wheel', onWheel)
518
- }, [setZoomClamped])
749
+ }, [])
519
750
 
520
- // 拖拽空白处平移画布(改 scrollLeft/scrollTop);点在卡片上不触发。
751
+ // 拖拽空白处平移画布(改 pan transform);点在卡片上不触发。
521
752
  useEffect(() => {
522
753
  const el = canvasRef.current
523
754
  if (!el) return
524
- let pan = null
755
+ let drag = null
525
756
  const down = (ev) => {
526
757
  if (ev.button !== 0) return
527
758
  if (ev.target.closest('.th-node')) return // 卡片拖拽交给 onDragStart
528
- pan = { x: ev.clientX, y: ev.clientY, left: el.scrollLeft, top: el.scrollTop, moved: false }
759
+ drag = { x: ev.clientX, y: ev.clientY, pan: { ...panRef.current } }
529
760
  el.classList.add('th-panning')
761
+ setPanning(true)
530
762
  }
531
763
  const move = (ev) => {
532
- if (!pan) return
533
- const dx = ev.clientX - pan.x, dy = ev.clientY - pan.y
534
- if (Math.abs(dx) + Math.abs(dy) > 3) pan.moved = true
535
- el.scrollLeft = pan.left - dx
536
- el.scrollTop = pan.top - dy
764
+ if (!drag) return
765
+ const dx = ev.clientX - drag.x, dy = ev.clientY - drag.y
766
+ setPan({ x: drag.pan.x + dx, y: drag.pan.y + dy })
537
767
  }
538
- const up = () => { pan = null; el.classList.remove('th-panning') }
768
+ const up = () => { drag = null; el.classList.remove('th-panning'); setPanning(false) }
539
769
  el.addEventListener('pointerdown', down)
540
770
  window.addEventListener('pointermove', move)
541
771
  window.addEventListener('pointerup', up)
@@ -546,6 +776,12 @@
546
776
  }
547
777
  }, [])
548
778
 
779
+ // 鼠标指针始终自定义,尺寸随 zoom 变化;用 CSS 变量覆盖整个画布子树。
780
+ useEffect(() => {
781
+ const el = canvasRef.current
782
+ if (el) el.style.setProperty('--th-cursor', makeCursor(zoom, panning))
783
+ }, [zoom, panning])
784
+
549
785
  const notify = useCallback((msg) => {
550
786
  setToast(msg)
551
787
  setTimeout(() => setToast((cur) => (cur === msg ? '' : cur)), 2600)
@@ -619,6 +855,60 @@
619
855
  } catch (e) { notify(`实例化失败: ${e.message}`) }
620
856
  }
621
857
 
858
+ /** 刷新实例:旧会话发保存进度→等其跑完→归档→建新会话→发恢复进度→重绑。 */
859
+ const runRefresh = async (agent, { saveText, restoreText }) => {
860
+ if (!agent?.sessionId) { notify('该 Agent 还未实例化'); setRefreshing(null); return }
861
+ setRefreshBusy(true)
862
+ const oldSid = agent.sessionId
863
+ const ws = agent.workspaceId || workspaceId
864
+ let step = 'start'
865
+ const trace = (s) => { step = s; log(`↳ ${s}`) }
866
+ try {
867
+ // 1) 旧会话发送保存进度提示词
868
+ trace('发送保存进度提示词')
869
+ notify('正在让旧会话保存进度…')
870
+ if (saveText.trim()) {
871
+ await ctx.sessions.using(oldSid, { source: 'teamHub' }, async (ref) => {
872
+ await ref.ready
873
+ const res = await ref.binding.session.prompt([{ type: 'text', text: saveText.trim() }], 'queue', undefined, crypto.randomUUID())
874
+ if (res && res.ok === false) throw new Error(res.error?.message || '保存提示词发送失败')
875
+ })
876
+ // 2) 等旧会话这一轮跑完(wait 在 idle / input-required / timeout 时返回)
877
+ trace('等待旧会话完成')
878
+ const waitRes = await ctx.remote.session.wait({ sessionId: oldSid, timeoutMs: 60000, maxMessages: 6 })
879
+ if (waitRes && waitRes.ok === false) throw new Error(`等待失败:${waitRes.error?.message || ''}`)
880
+ }
881
+ // 3) 归档旧会话
882
+ trace('归档旧会话')
883
+ await ctx.uiWorkspace?.archiveSession(oldSid, { stopActivity: true })
884
+ log(`<b>${agent.name}</b> 旧会话已归档`)
885
+ // 4) 建新会话
886
+ trace('创建新会话')
887
+ if (!ws) throw new Error('未绑定工作区')
888
+ const newSid = await ctx.sessions.create({ workspaceId: ws })
889
+ notify('新会话已创建,正在恢复进度…')
890
+ // 5) 新会话发恢复进度提示词
891
+ trace('发送恢复进度提示词')
892
+ await ctx.sessions.using(newSid, { source: 'teamHub' }, async (ref) => {
893
+ await ref.ready
894
+ const msgs = [{ type: 'text', text: restoreText?.trim() || t('defaultRestorePrompt') }]
895
+ const res = await ref.binding.session.prompt(msgs, 'queue', undefined, crypto.randomUUID())
896
+ if (res && res.ok === false) throw new Error(res.error?.message || '恢复提示词发送失败')
897
+ })
898
+ // 6) 重绑卡片
899
+ trace('重绑卡片')
900
+ await api('/agent', { method: 'POST', body: { ...agent, sessionId: newSid } })
901
+ log(`<b>${agent.name}</b> 已刷新实例并恢复进度`)
902
+ notify('刷新实例完成')
903
+ setRefreshing(null)
904
+ await refresh()
905
+ } catch (e) {
906
+ const msg = `刷新失败(${step}): ${e?.message || e}`
907
+ log(`<b style="color:var(--dsw-alias-state-error-primary)">${msg}</b>`)
908
+ notify(msg)
909
+ } finally { setRefreshBusy(false) }
910
+ }
911
+
622
912
  const removeAgent = async (agent) => {
623
913
  if (!window.confirm(`移除 Agent「${agent.name}」?\n其会话将被归档;之后在侧边栏恢复该会话,Agent 会自动回到画布。`)) return
624
914
  try {
@@ -686,12 +976,13 @@
686
976
  h('button', { title: '放大', onClick: () => setZoomClamped(zoom + 0.1) }, '+'),
687
977
  h('button', { title: '重置', onClick: () => setZoomClamped(1) }, '⟳'),
688
978
  ),
979
+ h('button', { className: `th-btn ${boardOpen ? 'primary' : ''}`, onClick: () => setBoardOpen((v) => !v) }, t('teamBoard')),
689
980
  h('button', { className: 'th-btn', onClick: () => { refresh(); refreshRemoved() } }, t('refresh')),
690
981
  h('button', { className: 'th-btn primary', onClick: () => setForm({}) }, t('newAgent')),
691
982
  ),
692
983
  h('div', { className: 'th-canvas', ref: canvasRef },
693
- h('div', { className: 'th-stage', style: { width: 2400 * zoom, height: 1600 * zoom } },
694
- h('div', { className: 'th-world', ref: worldRef, style: { transform: `scale(${zoom})` } },
984
+ h('div', { className: 'th-stage' },
985
+ h('div', { className: 'th-world', ref: worldRef, style: { transform: `translate(${pan.x}px, ${pan.y}px) scale(${zoom})` } },
695
986
  h('svg', { className: 'th-links' },
696
987
  links.map(({ from, to }) => {
697
988
  const p = edgePoints(from, to)
@@ -718,6 +1009,8 @@
718
1009
  onRemove: removeAgent,
719
1010
  onStatus: showStatus,
720
1011
  onInstantiate: instantiate,
1012
+ onRefresh: (ag) => setRefreshing(ag),
1013
+ onLogs: (ag) => setLogAgent(ag),
721
1014
  })),
722
1015
  activity.length > 0 && h('div', { className: 'th-activity' },
723
1016
  h('div', { style: { fontWeight: 650, marginBottom: 6 } }, t('activity')),
@@ -730,6 +1023,9 @@
730
1023
  error ? h('div', { className: 'th-toast show', style: { color: 'var(--dsw-alias-state-error-primary)' } }, error) : null,
731
1024
  form !== null ? h(AgentForm, { agent: form.id ? form : null, t, workspaceTitle, onClose: () => setForm(null), onSave: saveAgent }) : null,
732
1025
  composer ? h(Composer, { agent: composer.agent, t, onClose: () => setComposer(null), onSend: (text) => sendMessage(composer.agent, text) }) : null,
1026
+ refreshing ? h(RefreshModal, { agent: refreshing, t, busy: refreshBusy, onClose: () => setRefreshing(null), onRun: (p) => runRefresh(refreshing, p) }) : null,
1027
+ boardOpen ? h(TeamBoardPanel, { t, agents, refreshKey: boardKey, onClose: () => setBoardOpen(false), onLogs: (ag) => { setBoardOpen(false); setLogAgent(ag) } }) : null,
1028
+ logAgent !== undefined ? h(ToolLogPanel, { t, agent: logAgent, onClose: () => setLogAgent(undefined) }) : null,
733
1029
  )
734
1030
  }
735
1031
 
@@ -738,19 +1034,35 @@
738
1034
  zh: {
739
1035
  title: '团队中枢', panel: '团队画布', workspaceAction: '在团队中枢打开', refresh: '刷新', newAgent: '新建 Agent',
740
1036
  boundWorkspace: '已绑定工作区', globalWorkspace: '全局视图(未绑定工作区)',
1037
+ basicTab: '基本设定', advTab: '高级设定',
741
1038
  editAgent: '编辑 Agent', icon: '图标', name: '名称', identity: '身份设定',
742
1039
  duties: '职责边界', newAgentHint: '将在此工作区创建卡片,再点「实例化」建会话', noWorkspace: '未检测到工作区',
743
1040
  denyTools: '禁用工具(硬约束)', writeFiles: '可写文件(提示约束)', readFiles: '可读文件(提示约束)',
744
1041
  cancel: '取消', save: '保存', sendMessage: '发消息 / 派任务',
1042
+ teamBoard: '团队看板', publicTasks: '公开团队任务', taskTitle: '任务标题', taskDetail: '任务详情',
1043
+ noTasks: '暂无公开任务', cycleStatus: '点击切换状态', toolLogs: '工具调用日志', allAgents: '全部 Agent', noLogs: '暂无工具调用日志',
1044
+ refreshInstance: '刷新实例', refreshHint: '旧会话先按「保存进度提示词」收尾,等运行结束后自动归档,再在新会话发送「恢复进度提示词」。',
1045
+ savePrompt: '保存进度提示词', restorePrompt: '恢复进度提示词',
1046
+ defaultSavePrompt: '请总结当前进度与待办,写入你的记忆,方便在新会话中恢复。完成后回复“已保存”。',
1047
+ defaultRestorePrompt: '请从记忆中恢复之前的进度与待办,继续工作。',
1048
+ startRefresh: '开始刷新', refreshing: '正在刷新…',
745
1049
  activity: '协作动态', empty: '还没有 Agent,点「新建 Agent」开始搭建你的团队画布',
746
1050
  },
747
1051
  en: {
748
1052
  title: 'Team Hub', panel: 'Team canvas', workspaceAction: 'Open in Team Hub', refresh: 'Refresh', newAgent: 'New agent',
749
1053
  boundWorkspace: 'Bound workspace', globalWorkspace: 'Global view (no workspace)',
1054
+ basicTab: 'Basic', advTab: 'Advanced',
750
1055
  editAgent: 'Edit agent', icon: 'Icon', name: 'Name', identity: 'Identity',
751
1056
  duties: 'Responsibilities', newAgentHint: 'Card will be created here; click Instantiate to bind a session',
752
1057
  noWorkspace: 'No workspace detected', denyTools: 'Denied tools (hard)', writeFiles: 'Writable files (prompt)', readFiles: 'Readable files (prompt)',
753
1058
  cancel: 'Cancel', save: 'Save', sendMessage: 'Send message / task',
1059
+ teamBoard: 'Team board', publicTasks: 'Public team tasks', taskTitle: 'Task title', taskDetail: 'Task detail',
1060
+ noTasks: 'No public tasks', cycleStatus: 'Click to cycle status', toolLogs: 'Tool call logs', allAgents: 'All agents', noLogs: 'No tool call logs',
1061
+ refreshInstance: 'Refresh instance', refreshHint: 'The old session wraps up with the save-progress prompt, then is archived; a new session receives the restore-progress prompt.',
1062
+ savePrompt: 'Save-progress prompt', restorePrompt: 'Restore-progress prompt',
1063
+ defaultSavePrompt: 'Summarize your current progress and TODOs into memory so a new session can resume. Reply "saved" when done.',
1064
+ defaultRestorePrompt: 'Resume your previous progress and TODOs from memory, then continue working.',
1065
+ startRefresh: 'Start refresh', refreshing: 'Refreshing…',
754
1066
  activity: 'Activity', empty: 'No agents yet — create one to start your board',
755
1067
  },
756
1068
  }
@@ -803,7 +1115,7 @@
803
1115
  })
804
1116
  }
805
1117
 
806
- return { apply, inject: ['slots', 'locale', 'layout', 'uiWorkspace', 'sessions', 'workspaces', 'contextMenus', 'remote', 'sidebarRight', 'sidebarRightTabs'] }
1118
+ return { apply, inject: ['slots', 'locale', 'layout', 'uiWorkspace', 'sessions', 'workspaces', 'contextMenus', 'remote', 'remote.session', 'sidebarRight', 'sidebarRightTabs'] }
807
1119
  },
808
1120
  })
809
1121
  })()
package/docs/DETAIL.md CHANGED
@@ -10,14 +10,16 @@
10
10
 
11
11
  ## 能做什么
12
12
 
13
- - **团队画布**:每个会话对应一张 Agent 卡片,可自由拖拽调整位置;拖拽空白处可平移整个画布;按钮或 `Ctrl + 滚轮` 缩放画布(40%~200%)。主画布与右侧栏画布共享同一份看板数据与同一套交互。
13
+ - **团队画布**:无限延伸的画布,每个会话对应一张 Agent 卡片,可自由拖拽调整位置;拖拽空白处平移画布(普通滚轮也可平移),`Ctrl + 滚轮` 以鼠标位置为锚点缩放(40%~200%),按钮也可缩放。画布背景为透明方格,鼠标指针带深色描边在深浅背景下均清晰。主画布与右侧栏画布共享同一份看板数据与同一套交互。
14
14
  - **卡片管理**:新建 / 编辑 / 移除 Agent。新建的卡片默认「还未实例化」。
15
15
  - **实例化**:未实例化的卡片点「实例化」,在绑定工作区自动创建新会话、与卡片绑定,并把该 Agent 的身份 / 职责 / 权限设定作为初始化消息自动发进新会话。
16
+ - **刷新实例**:已实例化的卡片点「刷新实例」,可分别设置「保存进度提示词」与「恢复进度提示词」(也保存在 Agent 编辑弹窗的「高级设定」里)。流程:旧会话发送保存提示词→等其运行结束→自动归档→建新会话→发恢复提示词→卡片重绑。可在「协作动态」里看到每一步。
16
17
  - **移除与会话恢复**:移除 Agent 时自动归档其会话;之后在侧边栏恢复该会话,Agent 卡片自动回到画布。
17
18
  - **实时气泡**:卡片上方外侧有约两行高的聊天气泡,滚动展示该会话的最新内容——助手回复、用户消息、工具调用与结果、回合结束、审批请求、用户提问,各用不同样式,并展示运行状态。气泡跟随新内容向上滚动。
18
19
  - **协作连线**:卡片之间默认没有连线;只有当某个 Agent 通过沟通工具给另一个 Agent 发消息后,才会把两者用线连起来(取两卡最近边的中点),并用动画展示消息传递过程。
19
20
  - **发消息 / 派任务**:合并为一个入口,对目标 Agent 的会话发送消息。
20
21
  - **权限边界**:禁用工具由 `ctx.tools.guard()` 代码层硬拦截;身份、职责、可读写文件范围写进对应 Agent 上下文作为提示词软约束。
22
+ - **团队看板浮窗**:顶部标题栏「团队看板」按钮 toggle 一个浮窗,含两块:①公开团队任务——任何人可创建,状态点可在 open→doing→done 间循环,所有 Agent 都能通过工具查看;②工具调用日志——可查看全部 Agent 或某个 Agent 的本插件工具调用记录(工具名、调用方、参数、时间)。每张卡片上也有「工具日志」按钮直接看该 Agent 的记录。
21
23
 
22
24
  ## 给 Agent 的工具
23
25
 
@@ -27,6 +29,9 @@
27
29
  - `team_hub_status`:查会话状态。
28
30
  - `team_hub_reply`:读最近回复。
29
31
  - `team_hub_create_agent`:新建卡片。
32
+ - `team_hub_public_tasks`:列出所有公开团队任务。
33
+ - `team_hub_set_public_task`:创建或更新公开团队任务(所有 Agent 在团队看板可见)。
34
+ - 每次本插件工具调用都会自动记入工具日志,可在团队看板浮窗查看。
30
35
 
31
36
  ## 数据位置
32
37
 
package/index.js CHANGED
@@ -34,7 +34,7 @@ function boardPath() {
34
34
  }
35
35
 
36
36
  function defaultBoard() {
37
- return { version: 1, agents: [], removed: [], messages: [], tasks: [], updatedAt: 0 }
37
+ return { version: 1, agents: [], removed: [], messages: [], tasks: [], toolLogs: [], publicTasks: [], updatedAt: 0 }
38
38
  }
39
39
 
40
40
  function loadBoard(file) {
@@ -48,6 +48,8 @@ function loadBoard(file) {
48
48
  removed: Array.isArray(parsed.removed) ? parsed.removed : [],
49
49
  messages: Array.isArray(parsed.messages) ? parsed.messages : [],
50
50
  tasks: Array.isArray(parsed.tasks) ? parsed.tasks : [],
51
+ toolLogs: Array.isArray(parsed.toolLogs) ? parsed.toolLogs : [],
52
+ publicTasks: Array.isArray(parsed.publicTasks) ? parsed.publicTasks : [],
51
53
  updatedAt: Number(parsed.updatedAt) || 0,
52
54
  }
53
55
  } catch (error) {
@@ -91,6 +93,8 @@ function createStore() {
91
93
  name: String(input.name ?? existing?.name ?? 'Agent').slice(0, 80),
92
94
  identity: String(input.identity ?? existing?.identity ?? '').slice(0, 2000),
93
95
  duties: String(input.duties ?? existing?.duties ?? '').slice(0, 4000),
96
+ savePrompt: String(input.savePrompt ?? existing?.savePrompt ?? '').slice(0, 4000),
97
+ restorePrompt: String(input.restorePrompt ?? existing?.restorePrompt ?? '').slice(0, 4000),
94
98
  x: Number.isFinite(input.x) ? input.x : (existing?.x ?? 80),
95
99
  y: Number.isFinite(input.y) ? input.y : (existing?.y ?? 80),
96
100
  permissions: {
@@ -172,6 +176,54 @@ function createStore() {
172
176
  save()
173
177
  return true
174
178
  },
179
+ /** 本插件工具调用日志(每次 team_hub_* 工具执行记一条)。 */
180
+ logTool({ agentId, tool, detail }) {
181
+ board.toolLogs = Array.isArray(board.toolLogs) ? board.toolLogs : []
182
+ board.toolLogs.push({
183
+ id: randomUUID(),
184
+ agentId: agentId || null,
185
+ tool: String(tool || ''),
186
+ detail: String(detail ?? '').slice(0, 4000),
187
+ at: Date.now(),
188
+ })
189
+ if (board.toolLogs.length > 1000) board.toolLogs.splice(0, board.toolLogs.length - 1000)
190
+ save()
191
+ },
192
+ toolLogs(agentId) {
193
+ const list = Array.isArray(board.toolLogs) ? board.toolLogs : []
194
+ return agentId ? list.filter((l) => l.agentId === agentId) : list.slice()
195
+ },
196
+ /** 公开团队任务(对所有 Agent 可见)。 */
197
+ listPublicTasks() {
198
+ board.publicTasks = Array.isArray(board.publicTasks) ? board.publicTasks : []
199
+ return board.publicTasks.slice()
200
+ },
201
+ setPublicTask({ id, title, detail, status, ownerId }) {
202
+ board.publicTasks = Array.isArray(board.publicTasks) ? board.publicTasks : []
203
+ const tid = id || randomUUID()
204
+ const existing = board.publicTasks.find((t) => t.id === tid)
205
+ const task = {
206
+ id: tid,
207
+ title: String(title ?? existing?.title ?? '未命名任务').slice(0, 200),
208
+ detail: String(detail ?? existing?.detail ?? '').slice(0, 8000),
209
+ status: String(status ?? existing?.status ?? 'open'),
210
+ ownerId: ownerId ?? existing?.ownerId ?? null,
211
+ updatedAt: Date.now(),
212
+ createdAt: existing?.createdAt ?? Date.now(),
213
+ }
214
+ if (existing) Object.assign(existing, task)
215
+ else board.publicTasks.push(task)
216
+ save()
217
+ return task
218
+ },
219
+ removePublicTask(id) {
220
+ board.publicTasks = Array.isArray(board.publicTasks) ? board.publicTasks : []
221
+ const i = board.publicTasks.findIndex((t) => t.id === id)
222
+ if (i < 0) return false
223
+ board.publicTasks.splice(i, 1)
224
+ save()
225
+ return true
226
+ },
175
227
  }
176
228
  }
177
229
 
@@ -324,6 +376,18 @@ function mountApi(ctx, store) {
324
376
  if (!agent?.sessionId) return writeJson(res, { ok: true, value: '' })
325
377
  return writeJson(res, { ok: true, value: await sessionReply(ctx, agent.sessionId) })
326
378
  }
379
+ if (path === '/tool-logs' && method === 'GET') {
380
+ return writeJson(res, { ok: true, value: store.toolLogs(url.searchParams.get('agentId') || undefined) })
381
+ }
382
+ if (path === '/public-tasks' && method === 'GET') {
383
+ return writeJson(res, { ok: true, value: store.listPublicTasks() })
384
+ }
385
+ if (path === '/public-task' && method === 'POST') {
386
+ return writeJson(res, { ok: true, value: store.setPublicTask(await readBody(req)) })
387
+ }
388
+ if (path === '/public-task' && method === 'DELETE') {
389
+ return writeJson(res, { ok: true, value: store.removePublicTask(url.searchParams.get('id')) })
390
+ }
327
391
  return writeJson(res, { ok: false, error: { message: '未知接口' } }, 404)
328
392
  } catch (error) {
329
393
  writeJson(res, { ok: false, error: { message: error?.message || String(error) } }, 500)
@@ -435,13 +499,59 @@ function registerTools(ctx, store) {
435
499
  return `已创建 Agent ${agent.name},id=${agent.id}。可再绑定会话或在面板里操作。`
436
500
  },
437
501
  }),
502
+ defineTool({
503
+ name: 'team_hub_public_tasks',
504
+ description: '列出所有公开的团队任务(对所有 Agent 可见),含状态、负责人与详情。',
505
+ parameters: {},
506
+ output: jsonOut,
507
+ async execute() {
508
+ const tasks = store.listPublicTasks()
509
+ if (!tasks.length) return '目前没有公开团队任务。'
510
+ return tasks.map((t) => `[${t.status}] ${t.title}${t.ownerId ? ` (负责人 ${t.ownerId})` : ''}\n${t.detail}`).join('\n---\n')
511
+ },
512
+ }),
513
+ defineTool({
514
+ name: 'team_hub_set_public_task',
515
+ description: '创建或更新一条公开团队任务,让所有 Agent 都能在团队看板看到。提供 id 则更新,否则新建。',
516
+ parameters: {
517
+ id: { type: 'string', description: '任务 id(更新时提供,新建省略)' },
518
+ title: { type: 'string', required: true, description: '任务标题' },
519
+ detail: { type: 'string', description: '任务详情' },
520
+ status: { type: 'string', description: "状态:open / doing / done,默认 open" },
521
+ },
522
+ output: jsonOut,
523
+ async execute(args) {
524
+ const t = store.setPublicTask(args)
525
+ return `公开任务已保存:${t.title} (id=${t.id}, status=${t.status})。团队看板可见。`
526
+ },
527
+ }),
438
528
  ]
439
529
 
530
+ // 给每个工具包一层:执行后把调用记入本插件工具日志(含调用 Agent)。
531
+ const logged = tools.map((tool) => {
532
+ const orig = tool.execute
533
+ return {
534
+ ...tool,
535
+ async execute(args, exec) {
536
+ const sessionId = exec?.agent?.session?.id
537
+ const caller = sessionId && store.findBySession(sessionId)
538
+ try {
539
+ const result = await orig(args, exec)
540
+ store.logTool({ agentId: caller?.id || null, tool: tool.name, detail: JSON.stringify(args).slice(0, 2000) })
541
+ return result
542
+ } catch (error) {
543
+ store.logTool({ agentId: caller?.id || null, tool: tool.name, detail: `ERROR ${error?.message || error} | ${JSON.stringify(args).slice(0, 1500)}` })
544
+ throw error
545
+ }
546
+ },
547
+ }
548
+ })
549
+
440
550
  ctx.inject(['tools'], (svcCtx) => {
441
551
  const toolsService = svcCtx.get('tools')
442
552
  if (!toolsService?.register) return
443
553
  svcCtx.effect(() => {
444
- const disposers = tools.map((tool) => toolsService.register(tool))
554
+ const disposers = logged.map((tool) => toolsService.register(tool))
445
555
  return () => disposers.forEach((d) => d?.())
446
556
  })
447
557
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@restregular/dsh-team-hub",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "DSH 团队中枢:画布式 Agent 协作看板,支持跨会话派发任务、消息传递与权限边界管理。",
5
5
  "icon": "./icon.svg",
6
6
  "type": "module",