@restregular/dsh-team-hub 0.1.0 → 0.2.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.
Files changed (3) hide show
  1. package/client.js +144 -19
  2. package/docs/DETAIL.md +1 -1
  3. package/package.json +1 -1
package/client.js CHANGED
@@ -155,6 +155,20 @@
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
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; }
@@ -182,10 +196,14 @@
182
196
  .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
197
  .th-zoom button:hover { background:var(--dsw-alias-interactive-bg-hover); }
184
198
  .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; }
199
+ .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:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='28' viewBox='0 0 28 28'%3E%3Cpath d='M5 2 L5 22 L10 17 L14 25 L18 23 L14 15 L21 15 Z' fill='%23ffffff' stroke='%23111827' stroke-width='1.6' stroke-linejoin='round'/%3E%3C/svg%3E") 5 2, grab; }
200
+ .th-canvas.th-panning { cursor:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='28' viewBox='0 0 28 28'%3E%3Cpath d='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' fill='%23ffffff' stroke='%23111827' stroke-width='1.6' stroke-linejoin='round'/%3E%3C/svg%3E") 12 8, grabbing; }
201
+ .th-node, .th-node * { cursor:auto; }
202
+ .th-head, .th-head * { cursor:grab !important; }
203
+ .th-head:active, .th-head:active * { cursor:grabbing !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); }
@@ -309,7 +327,7 @@
309
327
  )
310
328
  }
311
329
 
312
- function AgentCard({ agent, feed, notices, onDragStart, onMessage, onOpen, onEdit, onRemove, onStatus, onInstantiate }) {
330
+ function AgentCard({ agent, feed, notices, onDragStart, onMessage, onOpen, onEdit, onRemove, onStatus, onInstantiate, onRefresh }) {
313
331
  const status = statusOf(agent)
314
332
  const sid = agent.sessionId
315
333
  const extra = sid ? (notices[sid] || []) : []
@@ -349,6 +367,7 @@
349
367
  ),
350
368
  h('div', { className: 'th-foot' },
351
369
  h('button', { className: 'th-btn', onClick: () => onStatus(agent) }, '状态'),
370
+ h('button', { className: 'th-btn', onClick: () => onRefresh(agent) }, '刷新实例'),
352
371
  h('button', { className: 'th-btn', onClick: () => onEdit(agent) }, '编辑'),
353
372
  h('button', { className: 'th-btn danger', onClick: () => onRemove(agent) }, '移除'),
354
373
  ),
@@ -411,6 +430,33 @@
411
430
  )
412
431
  }
413
432
 
433
+ /** 刷新实例弹窗:设置保存/恢复进度提示词,把 Agent 换绑到新会话。 */
434
+ function RefreshModal({ agent, t, busy, onClose, onRun }) {
435
+ const [saveText, setSaveText] = useState(t('defaultSavePrompt'))
436
+ const [restoreText, setRestoreText] = useState(t('defaultRestorePrompt'))
437
+ return h('div', { className: 'th-overlay', onPointerDown: (e) => { if (e.target === e.currentTarget && !busy) onClose() } },
438
+ h('div', { className: 'th-modal' },
439
+ h('h3', null, `${t('refreshInstance')} · ${agent.name}`),
440
+ h('div', { className: 'th-bind' }, t('refreshHint')),
441
+ h('div', { className: 'th-field' },
442
+ h('label', null, t('savePrompt')),
443
+ h('textarea', { className: 'th-textarea', value: saveText, onChange: (e) => setSaveText(e.target.value), disabled: busy }),
444
+ ),
445
+ h('div', { className: 'th-field' },
446
+ h('label', null, t('restorePrompt')),
447
+ h('textarea', { className: 'th-textarea', value: restoreText, onChange: (e) => setRestoreText(e.target.value), disabled: busy }),
448
+ ),
449
+ h('div', { className: 'th-modal-foot' },
450
+ h('button', { className: 'th-btn', onClick: onClose, disabled: busy }, t('cancel')),
451
+ h('button', {
452
+ className: 'th-btn primary', disabled: busy,
453
+ onClick: () => onRun({ saveText, restoreText }),
454
+ }, busy ? t('refreshing') : t('startRefresh')),
455
+ ),
456
+ ),
457
+ )
458
+ }
459
+
414
460
  /** 右侧栏紧凑画布:与中央画布共享同一份看板数据,点击卡片打开对应原生会话。 */
415
461
  /** 右侧栏里渲染的是同一个完整画布(拖拽/缩放/气泡/连线俱全),不是列表。 */
416
462
  function SidebarCanvas(props) {
@@ -461,14 +507,20 @@
461
507
  const [toast, setToast] = useState('')
462
508
  const [form, setForm] = useState(null)
463
509
  const [composer, setComposer] = useState(null)
510
+ const [refreshing, setRefreshing] = useState(null)
511
+ const [refreshBusy, setRefreshBusy] = useState(false)
464
512
  const [activity, setActivity] = useState([])
465
513
  const [pulses, setPulses] = useState([])
466
514
  const [zoom, setZoom] = useState(props.compact ? 0.6 : 1)
515
+ const [pan, setPan] = useState({ x: 60, y: 60 })
516
+ const [panning, setPanning] = useState(false)
467
517
  const dragRef = useRef(null)
468
518
  const worldRef = useRef(null)
469
519
  const canvasRef = useRef(null)
470
520
  const zoomRef = useRef(zoom)
521
+ const panRef = useRef(pan)
471
522
  useEffect(() => { zoomRef.current = zoom }, [zoom])
523
+ useEffect(() => { panRef.current = pan }, [pan])
472
524
 
473
525
  const refresh = useCallback(async () => {
474
526
  try {
@@ -505,37 +557,50 @@
505
557
  }, [archivedIds, archiveReady, removedAgents])
506
558
 
507
559
  const setZoomClamped = useCallback((next) => setZoom(Math.min(2, Math.max(0.4, Math.round(next * 10) / 10))), [])
560
+ // Ctrl+滚轮:以鼠标位置为锚点缩放(无限画布,不受固定边界限制)。
508
561
  useEffect(() => {
509
562
  const el = canvasRef.current
510
563
  if (!el) return
511
564
  const onWheel = (ev) => {
512
- if (!ev.ctrlKey && !ev.metaKey) return
513
565
  ev.preventDefault()
514
- setZoomClamped(zoomRef.current + (ev.deltaY < 0 ? 0.1 : -0.1))
566
+ const rect = el.getBoundingClientRect()
567
+ const mx = ev.clientX - rect.left, my = ev.clientY - rect.top
568
+ if (ev.ctrlKey || ev.metaKey) {
569
+ const old = zoomRef.current
570
+ const next = Math.min(2, Math.max(0.4, Math.round((old + (ev.deltaY < 0 ? 0.1 : -0.1)) * 10) / 10))
571
+ if (next === old) return
572
+ const p = panRef.current
573
+ // 保持鼠标下的世界坐标不变:world = (mouse - pan)/zoom
574
+ const wx = (mx - p.x) / old, wy = (my - p.y) / old
575
+ setPan({ x: mx - wx * next, y: my - wy * next })
576
+ setZoom(next)
577
+ } else {
578
+ // 普通滚轮也可平移画布
579
+ setPan((cur) => ({ x: cur.x - ev.deltaX, y: cur.y - ev.deltaY }))
580
+ }
515
581
  }
516
582
  el.addEventListener('wheel', onWheel, { passive: false })
517
583
  return () => el.removeEventListener('wheel', onWheel)
518
- }, [setZoomClamped])
584
+ }, [])
519
585
 
520
- // 拖拽空白处平移画布(改 scrollLeft/scrollTop);点在卡片上不触发。
586
+ // 拖拽空白处平移画布(改 pan transform);点在卡片上不触发。
521
587
  useEffect(() => {
522
588
  const el = canvasRef.current
523
589
  if (!el) return
524
- let pan = null
590
+ let drag = null
525
591
  const down = (ev) => {
526
592
  if (ev.button !== 0) return
527
593
  if (ev.target.closest('.th-node')) return // 卡片拖拽交给 onDragStart
528
- pan = { x: ev.clientX, y: ev.clientY, left: el.scrollLeft, top: el.scrollTop, moved: false }
594
+ drag = { x: ev.clientX, y: ev.clientY, pan: { ...panRef.current } }
529
595
  el.classList.add('th-panning')
596
+ setPanning(true)
530
597
  }
531
598
  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
599
+ if (!drag) return
600
+ const dx = ev.clientX - drag.x, dy = ev.clientY - drag.y
601
+ setPan({ x: drag.pan.x + dx, y: drag.pan.y + dy })
537
602
  }
538
- const up = () => { pan = null; el.classList.remove('th-panning') }
603
+ const up = () => { drag = null; el.classList.remove('th-panning'); setPanning(false) }
539
604
  el.addEventListener('pointerdown', down)
540
605
  window.addEventListener('pointermove', move)
541
606
  window.addEventListener('pointerup', up)
@@ -546,6 +611,12 @@
546
611
  }
547
612
  }, [])
548
613
 
614
+ // 鼠标指针始终自定义,尺寸随 zoom 变化;inline 覆盖 CSS。
615
+ useEffect(() => {
616
+ const el = canvasRef.current
617
+ if (el) el.style.cursor = makeCursor(zoom, panning)
618
+ }, [zoom, panning])
619
+
549
620
  const notify = useCallback((msg) => {
550
621
  setToast(msg)
551
622
  setTimeout(() => setToast((cur) => (cur === msg ? '' : cur)), 2600)
@@ -619,6 +690,48 @@
619
690
  } catch (e) { notify(`实例化失败: ${e.message}`) }
620
691
  }
621
692
 
693
+ /** 刷新实例:旧会话发保存进度→等其跑完→归档→建新会话→发恢复进度→重绑。 */
694
+ const runRefresh = async (agent, { saveText, restoreText }) => {
695
+ if (!agent?.sessionId) { notify('该 Agent 还未实例化'); setRefreshing(null); return }
696
+ setRefreshBusy(true)
697
+ const oldSid = agent.sessionId
698
+ const ws = agent.workspaceId || workspaceId
699
+ try {
700
+ // 1) 旧会话发送保存进度提示词
701
+ notify('正在让旧会话保存进度…')
702
+ if (saveText.trim()) {
703
+ await ctx.sessions.using(oldSid, { source: 'teamHub' }, async (ref) => {
704
+ await ref.ready
705
+ return ref.binding.session.prompt([{ type: 'text', text: saveText.trim() }], 'queue', undefined, crypto.randomUUID())
706
+ })
707
+ // 2) 等旧会话这一轮跑完(wait 在 idle / input-required / timeout 时返回)
708
+ const waitRes = await ctx.remote.session.wait({ sessionId: oldSid, timeoutMs: 60000, maxMessages: 6 })
709
+ if (waitRes && waitRes.ok === false) notify(`等待保存完成超时/失败:${waitRes.error?.message || ''}`)
710
+ }
711
+ // 3) 归档旧会话
712
+ await ctx.uiWorkspace?.archiveSession(oldSid, { stopActivity: true })
713
+ log(`<b>${agent.name}</b> 旧会话已归档`)
714
+ // 4) 建新会话
715
+ if (!ws) throw new Error('未绑定工作区')
716
+ const newSid = await ctx.sessions.create({ workspaceId: ws })
717
+ notify('新会话已创建,正在恢复进度…')
718
+ // 5) 新会话发恢复进度提示词
719
+ await ctx.sessions.using(newSid, { source: 'teamHub' }, async (ref) => {
720
+ await ref.ready
721
+ const msgs = [{ type: 'text', text: restoreText?.trim() || t('defaultRestorePrompt') }]
722
+ return ref.binding.session.prompt(msgs, 'queue', undefined, crypto.randomUUID())
723
+ })
724
+ // 6) 重绑卡片
725
+ await api('/agent', { method: 'POST', body: { ...agent, sessionId: newSid } })
726
+ log(`<b>${agent.name}</b> 已刷新实例并恢复进度`)
727
+ notify('刷新实例完成')
728
+ setRefreshing(null)
729
+ await refresh()
730
+ } catch (e) {
731
+ notify(`刷新失败: ${e.message}`)
732
+ } finally { setRefreshBusy(false) }
733
+ }
734
+
622
735
  const removeAgent = async (agent) => {
623
736
  if (!window.confirm(`移除 Agent「${agent.name}」?\n其会话将被归档;之后在侧边栏恢复该会话,Agent 会自动回到画布。`)) return
624
737
  try {
@@ -690,8 +803,8 @@
690
803
  h('button', { className: 'th-btn primary', onClick: () => setForm({}) }, t('newAgent')),
691
804
  ),
692
805
  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})` } },
806
+ h('div', { className: 'th-stage' },
807
+ h('div', { className: 'th-world', ref: worldRef, style: { transform: `translate(${pan.x}px, ${pan.y}px) scale(${zoom})` } },
695
808
  h('svg', { className: 'th-links' },
696
809
  links.map(({ from, to }) => {
697
810
  const p = edgePoints(from, to)
@@ -718,6 +831,7 @@
718
831
  onRemove: removeAgent,
719
832
  onStatus: showStatus,
720
833
  onInstantiate: instantiate,
834
+ onRefresh: (ag) => setRefreshing(ag),
721
835
  })),
722
836
  activity.length > 0 && h('div', { className: 'th-activity' },
723
837
  h('div', { style: { fontWeight: 650, marginBottom: 6 } }, t('activity')),
@@ -730,6 +844,7 @@
730
844
  error ? h('div', { className: 'th-toast show', style: { color: 'var(--dsw-alias-state-error-primary)' } }, error) : null,
731
845
  form !== null ? h(AgentForm, { agent: form.id ? form : null, t, workspaceTitle, onClose: () => setForm(null), onSave: saveAgent }) : null,
732
846
  composer ? h(Composer, { agent: composer.agent, t, onClose: () => setComposer(null), onSend: (text) => sendMessage(composer.agent, text) }) : null,
847
+ refreshing ? h(RefreshModal, { agent: refreshing, t, busy: refreshBusy, onClose: () => setRefreshing(null), onRun: (p) => runRefresh(refreshing, p) }) : null,
733
848
  )
734
849
  }
735
850
 
@@ -742,6 +857,11 @@
742
857
  duties: '职责边界', newAgentHint: '将在此工作区创建卡片,再点「实例化」建会话', noWorkspace: '未检测到工作区',
743
858
  denyTools: '禁用工具(硬约束)', writeFiles: '可写文件(提示约束)', readFiles: '可读文件(提示约束)',
744
859
  cancel: '取消', save: '保存', sendMessage: '发消息 / 派任务',
860
+ refreshInstance: '刷新实例', refreshHint: '旧会话先按「保存进度提示词」收尾,等运行结束后自动归档,再在新会话发送「恢复进度提示词」。',
861
+ savePrompt: '保存进度提示词', restorePrompt: '恢复进度提示词',
862
+ defaultSavePrompt: '请总结当前进度与待办,写入你的记忆,方便在新会话中恢复。完成后回复“已保存”。',
863
+ defaultRestorePrompt: '请从记忆中恢复之前的进度与待办,继续工作。',
864
+ startRefresh: '开始刷新', refreshing: '正在刷新…',
745
865
  activity: '协作动态', empty: '还没有 Agent,点「新建 Agent」开始搭建你的团队画布',
746
866
  },
747
867
  en: {
@@ -751,6 +871,11 @@
751
871
  duties: 'Responsibilities', newAgentHint: 'Card will be created here; click Instantiate to bind a session',
752
872
  noWorkspace: 'No workspace detected', denyTools: 'Denied tools (hard)', writeFiles: 'Writable files (prompt)', readFiles: 'Readable files (prompt)',
753
873
  cancel: 'Cancel', save: 'Save', sendMessage: 'Send message / task',
874
+ 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.',
875
+ savePrompt: 'Save-progress prompt', restorePrompt: 'Restore-progress prompt',
876
+ defaultSavePrompt: 'Summarize your current progress and TODOs into memory so a new session can resume. Reply "saved" when done.',
877
+ defaultRestorePrompt: 'Resume your previous progress and TODOs from memory, then continue working.',
878
+ startRefresh: 'Start refresh', refreshing: 'Refreshing…',
754
879
  activity: 'Activity', empty: 'No agents yet — create one to start your board',
755
880
  },
756
881
  }
package/docs/DETAIL.md CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  ## 能做什么
12
12
 
13
- - **团队画布**:每个会话对应一张 Agent 卡片,可自由拖拽调整位置;拖拽空白处可平移整个画布;按钮或 `Ctrl + 滚轮` 缩放画布(40%~200%)。主画布与右侧栏画布共享同一份看板数据与同一套交互。
13
+ - **团队画布**:无限延伸的画布,每个会话对应一张 Agent 卡片,可自由拖拽调整位置;拖拽空白处平移画布(普通滚轮也可平移),`Ctrl + 滚轮` 以鼠标位置为锚点缩放(40%~200%),按钮也可缩放。画布背景为透明方格,鼠标指针带深色描边在深浅背景下均清晰。主画布与右侧栏画布共享同一份看板数据与同一套交互。
14
14
  - **卡片管理**:新建 / 编辑 / 移除 Agent。新建的卡片默认「还未实例化」。
15
15
  - **实例化**:未实例化的卡片点「实例化」,在绑定工作区自动创建新会话、与卡片绑定,并把该 Agent 的身份 / 职责 / 权限设定作为初始化消息自动发进新会话。
16
16
  - **移除与会话恢复**:移除 Agent 时自动归档其会话;之后在侧边栏恢复该会话,Agent 卡片自动回到画布。
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.2.0",
4
4
  "description": "DSH 团队中枢:画布式 Agent 协作看板,支持跨会话派发任务、消息传递与权限边界管理。",
5
5
  "icon": "./icon.svg",
6
6
  "type": "module",