@xmodelin/dsh-collab-sessions 0.0.2 → 0.0.4

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
@@ -252,6 +252,27 @@ Every named session row has a copy action in its hover strip, and the session
252
252
  right-click menu has **复制会话名 / Copy session name**. The action copies the
253
253
  display name to the clipboard and briefly marks the button as copied.
254
254
 
255
+ ## Diagnostics
256
+
257
+ Use `collab_doctor` for a read-only health snapshot of the collaboration session:
258
+
259
+ - registry size;
260
+ - relationship and invalid relationship counts;
261
+ - grant and invalid grant counts;
262
+ - task / active task counts;
263
+ - request / active request counts;
264
+ - audit readability.
265
+
266
+ The append-only audit log lives at:
267
+
268
+ ```text
269
+ <state>/audit.jsonl
270
+ ```
271
+
272
+ It records authorization, request acceptance, task assignment/completion/closure,
273
+ and delivery publication. Losing the audit file does not affect task or request
274
+ state.
275
+
255
276
  ## Manual state recovery
256
277
 
257
278
  State is under the DSH home:
@@ -264,6 +285,7 @@ State is under the DSH home:
264
285
  tasks.json tasks and subtasks
265
286
  requests.json requester↔supervisor requests and deliveries
266
287
  notices.json durable protocol notice outbox
288
+ audit.jsonl append-only collaboration action audit
267
289
  ```
268
290
 
269
291
  A malformed document is moved aside as:
@@ -333,6 +355,7 @@ That backup is the **bad** file, not a clean backup. Do not restore it blindly.
333
355
  | `tasks.json` | Task board shows the desired tasks/subtasks; delivery artifacts remain on disk. |
334
356
  | `requests.json` | Requester and supervisor can list the requests that still exist. |
335
357
  | `notices.json` | Pending wake-ups may be gone; the task/request stores remain authoritative. |
358
+ | `audit.jsonl` | Audit history is append-only; losing it does not affect task/request state. |
336
359
 
337
360
  ### Empty skeletons
338
361
 
package/client.js CHANGED
@@ -17,6 +17,20 @@ window.__ModuleLoader__.load({
17
17
  const React = require('react')
18
18
  const h = React.createElement
19
19
  const NS = 'dsh-collab-sessions'
20
+ /** Compatibility copy and selectors tied to DSH preset chrome. */
21
+ const COMPAT = Object.freeze({
22
+ presetText: /(协同会话|超级会话|Collab session|Supervisor session)/u,
23
+ modeChip:
24
+ 'button[aria-haspopup="menu"][title*="Agent 预设"],'
25
+ + 'button[aria-haspopup="menu"][title*="Agent preset"]',
26
+ labels: Object.freeze({
27
+ collab: '协同会话',
28
+ supervisor: '超级会话',
29
+ collabEn: 'Collab session',
30
+ supervisorEn: 'Supervisor session',
31
+ }),
32
+ })
33
+
20
34
  const BOARD_TAB_ID = '@xmodelin/dsh-collab-sessions/supervisor-tasks'
21
35
  const BOARD_TAB_KIND = 'collabSupervisorTasks'
22
36
  const WORKERS_TAB_ID = '@xmodelin/dsh-collab-sessions/supervisor-workers'
@@ -299,12 +313,7 @@ window.__ModuleLoader__.load({
299
313
  if (summary === undefined) return false
300
314
  const values = summary.projectionValues ?? state?.projectionsBySession?.[summary.id]?.values
301
315
  const preset = values?.agentPreset
302
- const workdir = typeof values?.workingDirectory === 'string'
303
- ? values.workingDirectory.replace(/\\/gu, '/')
304
- : ''
305
- return preset === 'collab'
306
- || preset === 'supervisor'
307
- || workdir.includes('.dsh-collab/sessions/')
316
+ return preset === 'collab' || preset === 'supervisor'
308
317
  }
309
318
 
310
319
  const CSS = [
@@ -711,7 +720,15 @@ window.__ModuleLoader__.load({
711
720
  ? t('panel.loading')
712
721
  : (selected.length === 2 ? null : t('panel.selectTwo'))
713
722
 
714
- const pairRows = pairs.map(pair => h('div', {
723
+ const visiblePairs = pairs.filter(pair => (
724
+ sorted.some(summary => summary.id === pair.a)
725
+ && sorted.some(summary => summary.id === pair.b)
726
+ ))
727
+ const visiblePending = pendingGrants.filter(grant => (
728
+ sorted.some(summary => summary.id === grant.from)
729
+ && sorted.some(summary => summary.id === grant.to)
730
+ ))
731
+ const pairRows = visiblePairs.map(pair => h('div', {
715
732
  key: `${pair.a}|${pair.b}`,
716
733
  className: 'dsh-collab-auth-row',
717
734
  },
@@ -732,7 +749,7 @@ window.__ModuleLoader__.load({
732
749
  },
733
750
  }, confirmRevoke === `pair:${pair.a}|${pair.b}` ? t('panel.confirmRevoke') : t('panel.revoke'))))
734
751
 
735
- const pendingRows = pendingGrants.map(grant => h('div', {
752
+ const pendingRows = visiblePending.map(grant => h('div', {
736
753
  key: `pending:${grant.from}|${grant.to}`,
737
754
  className: 'dsh-collab-auth-row',
738
755
  },
@@ -762,6 +779,7 @@ window.__ModuleLoader__.load({
762
779
  : sorted.map(summary => h('label', {
763
780
  key: summary.id,
764
781
  className: 'dsh-collab-auth-row',
782
+ 'data-collab-preset': presetOf(summary.id) ?? '',
765
783
  },
766
784
  h('input', {
767
785
  type: 'checkbox',
@@ -784,7 +802,7 @@ window.__ModuleLoader__.load({
784
802
  },
785
803
  h('div', { className: 'dsh-collab-auth-list' },
786
804
  loading ? h('p', { className: 'dsh-collab-auth-muted' }, t('panel.loading')) : null,
787
- !loading && pairs.length === 0 && pendingGrants.length === 0
805
+ !loading && visiblePairs.length === 0 && visiblePending.length === 0
788
806
  ? h('p', { className: 'dsh-collab-auth-muted' }, t('panel.emptyPairs'))
789
807
  : null,
790
808
  ...pairRows,
@@ -839,7 +857,7 @@ window.__ModuleLoader__.load({
839
857
  h('p', { className: 'dsh-collab-auth-desc' }, t('panel.description'))),
840
858
  h('div', { className: 'dsh-collab-auth-tabs-row' },
841
859
  h('div', { className: 'dsh-collab-auth-tabs', role: 'tablist' },
842
- tabButton('pairs', t('panel.pairsTab'), pairs.length),
860
+ tabButton('pairs', t('panel.pairsTab'), visiblePairs.length),
843
861
  tabButton('sessions', t('panel.sessionsTab'), sorted.length)),
844
862
  h('div', { className: 'dsh-collab-auth-tabs-actions' },
845
863
  h('button', {
@@ -1857,8 +1875,8 @@ window.__ModuleLoader__.load({
1857
1875
  React.useEffect(() => {
1858
1876
  const translatePresetCopy = () => {
1859
1877
  const pairs = [
1860
- ['协同会话', t('preset.collabName')],
1861
- ['超级会话', t('preset.supervisorName')],
1878
+ [COMPAT.labels.collab, t('preset.collabName')],
1879
+ [COMPAT.labels.supervisor, t('preset.supervisorName')],
1862
1880
  ['拥有独立的 .dsh-collab 工作目录、共享的 comm/ 目录和仅本会话可访问的 private/ 目录,并提供经过身份验证的会话间通信工具。', t('preset.collabDescription')],
1863
1881
  ['负责拆解需求、把子任务分派给已登记的功能会话、核验结果并完成交付;不提供任何实现类工具。', t('preset.supervisorDescription')],
1864
1882
  ]
@@ -1875,7 +1893,7 @@ window.__ModuleLoader__.load({
1875
1893
  // The collab entry's own dropdown also uses role=menuitem.
1876
1894
  if (node.closest('.dsh-collab-new-menu') !== null) continue
1877
1895
  const text = node.textContent ?? ''
1878
- if (!/(协同会话|超级会话|Collab session|Supervisor session)/u.test(text)) continue
1896
+ if (!COMPAT.presetText.test(text)) continue
1879
1897
  node.hidden = true
1880
1898
  node.setAttribute('aria-hidden', 'true')
1881
1899
  node.style.setProperty('display', 'none', 'important')
@@ -1902,38 +1920,32 @@ window.__ModuleLoader__.load({
1902
1920
  return () => root.removeAttribute('data-collab-preset-lock')
1903
1921
  }, [locked])
1904
1922
  return h('style', null,
1905
- 'html[data-collab-preset-lock="true"] button[aria-haspopup="menu"][title*="Agent 预设"],'
1906
- + 'html[data-collab-preset-lock="true"] button[aria-haspopup="menu"][title*="Agent preset"]{display:none!important}')
1923
+ `html[data-collab-preset-lock="true"] ${COMPAT.modeChip}{display:none!important}`)
1907
1924
  }
1908
1925
 
1909
- function CollabSupervisorTabsOnOpen(props) {
1926
+ const autoSeededSupervisorTabs = new Set()
1927
+
1928
+ function CollabSupervisorTabsAutoSeed(props) {
1910
1929
  const sessions = props.useSessions(selectSnapshot)
1911
- const summary = sessions.byId[props.sessionId]
1912
- const supervisor = isSupervisorSessionSummary(summary, sessions)
1930
+ const main = Object.values(sessions?.byId ?? {})
1931
+ .find(summary => (summary.retainedBy?.mainView ?? 0) > 0)
1932
+ const preset = main?.projectionValues?.agentPreset
1933
+ ?? sessions?.projectionsBySession?.[main?.id]?.values?.agentPreset
1934
+ const sessionId = main?.id
1913
1935
  React.useEffect(() => {
1914
- if (!supervisor) return undefined
1915
- let wasExpanded = false
1916
- const seed = () => {
1917
- const expanded = props.isExpanded()
1918
- if (!expanded) {
1919
- wasExpanded = false
1920
- return
1921
- }
1922
- if (wasExpanded) return
1923
- wasExpanded = true
1924
- props.openGuide(props.sessionId)
1925
- props.openTasks(props.sessionId)
1926
- props.openWorkers(props.sessionId)
1927
- }
1928
- seed()
1929
- const timer = setInterval(seed, 200)
1930
- return () => clearInterval(timer)
1931
- }, [supervisor, props.sessionId])
1936
+ if (preset !== 'supervisor' || sessionId === undefined) return undefined
1937
+ if (autoSeededSupervisorTabs.has(sessionId)) return undefined
1938
+ autoSeededSupervisorTabs.add(sessionId)
1939
+ props.openTasks(sessionId)
1940
+ props.openWorkers(sessionId)
1941
+ props.openGuide(sessionId)
1942
+ return undefined
1943
+ }, [preset, sessionId])
1932
1944
  return null
1933
1945
  }
1934
1946
 
1935
1947
  return {
1936
- __test: { isCollabSummary, isSupervisorSessionSummary, parseBasePromptCommand },
1948
+ __test: { isCollabSummary, isSupervisorSessionSummary, parseBasePromptCommand, COMPAT },
1937
1949
  inject: ['slots', 'locale', 'uiWorkspace', 'sessions', 'remote', 'remote.commands', 'remote.collabAuth', 'uiConversation', 'layout', 'sidebarRight', 'sidebarRightTabs'],
1938
1950
  apply(ctx) {
1939
1951
  ctx.effect(() => ctx.locale.register(NS, { zh: ZH, en: EN }), 'collab-sessions: dictionaries')
@@ -1944,8 +1956,27 @@ window.__ModuleLoader__.load({
1944
1956
  revoke: async (a, b) => ctx.remote.collabAuth === undefined ? authUnavailable : ctx.remote.collabAuth.revoke(a, b),
1945
1957
  }
1946
1958
  const callPanel = (sessionId, operation, args) => {
1947
- if (ctx.remote.collabAuth === undefined) return Promise.resolve(authUnavailable)
1948
- return ctx.remote.collabAuth.panel(sessionId, operation, JSON.stringify(args ?? {}))
1959
+ const auth = ctx.remote.collabAuth
1960
+ if (auth === undefined) return Promise.resolve(authUnavailable)
1961
+ const payload = args ?? {}
1962
+ if (operation === 'board' && typeof auth.board === 'function') return auth.board(sessionId)
1963
+ if (operation === 'link' && typeof auth.link === 'function') {
1964
+ return auth.link(sessionId, String(payload.worker ?? ''), JSON.stringify(payload.payload ?? {}))
1965
+ }
1966
+ if (operation === 'unlink' && typeof auth.unlink === 'function') {
1967
+ return auth.unlink(sessionId, String(payload.worker ?? ''))
1968
+ }
1969
+ if (operation === 'pin' && typeof auth.pin === 'function') {
1970
+ return auth.pin(sessionId, String(payload.worker ?? ''))
1971
+ }
1972
+ if (operation === 'live' && typeof auth.live === 'function') {
1973
+ return auth.live(sessionId, String(payload.worker ?? ''))
1974
+ }
1975
+ if (operation === 'baseGet' && typeof auth.baseGet === 'function') return auth.baseGet(sessionId)
1976
+ if (operation === 'baseSet' && typeof auth.baseSet === 'function') {
1977
+ return auth.baseSet(sessionId, String(payload.value ?? ''))
1978
+ }
1979
+ return auth.panel(sessionId, operation, JSON.stringify(payload))
1949
1980
  }
1950
1981
 
1951
1982
  const panelCommand = async (sessionId, operation, args) => {
@@ -2099,24 +2130,6 @@ window.__ModuleLoader__.load({
2099
2130
  order: 100,
2100
2131
  }, CollabPresetLockProbe))
2101
2132
 
2102
- ctx.slots.inject('conversation.session.header.utilities', () => ctx.slots.register({
2103
- name: 'conversation.session.header.utilities',
2104
- id: 'collab-supervisor-tabs-on-open',
2105
- order: 11,
2106
- inject: () => ({
2107
- isExpanded: () => ctx.sidebarRight.isExpanded(),
2108
- openGuide: () => ctx.sidebarRight.openTab('guide', { revealIfOpened: true }),
2109
- openTasks: (sessionId) => ctx.sidebarRight.openTab(BOARD_TAB_KIND, {
2110
- params: { sessionId },
2111
- revealIfOpened: false,
2112
- }),
2113
- openWorkers: (sessionId) => ctx.sidebarRight.openTab(WORKERS_TAB_KIND, {
2114
- params: { sessionId },
2115
- revealIfOpened: false,
2116
- }),
2117
- }),
2118
- }, CollabSupervisorTabsOnOpen))
2119
-
2120
2133
  ctx.effect(
2121
2134
  () => ctx.uiConversation.events.register(collabAuthRefusedDefinition),
2122
2135
  'collab-sessions: authorization-refusal turn data',
@@ -2145,6 +2158,16 @@ window.__ModuleLoader__.load({
2145
2158
  locale: NS,
2146
2159
  }, CollabBasePromptEditor))
2147
2160
 
2161
+ ctx.slots.inject('shell.overlay', () => ctx.slots.register({
2162
+ name: 'shell.overlay',
2163
+ id: 'collab-supervisor-tabs-auto-seed',
2164
+ inject: () => ({
2165
+ openGuide: (sessionId) => ctx.sidebarRight.openTab('guide', { params: { sessionId }, revealIfOpened: false }),
2166
+ openTasks: (sessionId) => ctx.sidebarRight.openTab(BOARD_TAB_KIND, { params: { sessionId }, revealIfOpened: false }),
2167
+ openWorkers: (sessionId) => ctx.sidebarRight.openTab(WORKERS_TAB_KIND, { params: { sessionId }, revealIfOpened: false }),
2168
+ }),
2169
+ }, CollabSupervisorTabsAutoSeed))
2170
+
2148
2171
  ctx.slots.inject('shell.overlay', () => ctx.slots.register({
2149
2172
  name: 'shell.overlay',
2150
2173
  id: 'collab-preset-menu-filter',