dsh-atc 0.19.0 → 0.23.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/lib/collect.mjs CHANGED
@@ -13,7 +13,20 @@ import { closeSync, existsSync, openSync, readFileSync, readSync, readdirSync, s
13
13
  import { homedir } from 'node:os'
14
14
  import { join } from 'node:path'
15
15
  import { zstdDecompressSync } from 'node:zlib'
16
+ import { openSqlite, readSqliteSource } from './capabilities.mjs'
16
17
  import { collectDiscovered } from './generic.mjs'
18
+ import {
19
+ cleanPrompt,
20
+ isSyntheticPrompt,
21
+ resolveTitle,
22
+ shortPrompt,
23
+ titleFromPrompt,
24
+ toMs,
25
+ } from './rules.mjs'
26
+ import { doingLine, summarizeCall } from './tool-calls.mjs'
27
+
28
+ // Re-exported: the helpers moved to rules.mjs, their callers did not move.
29
+ export { toMs }
17
30
 
18
31
  /** Defaults; override any key with `$DSH_HOME/atc.json`. */
19
32
  export const DEFAULTS = {
@@ -69,12 +82,6 @@ export function tunables() {
69
82
  }
70
83
 
71
84
  /** Normalize epoch-seconds, epoch-ms, or an ISO string to epoch-ms. */
72
- export function toMs(value) {
73
- if (value === null || value === undefined) return 0
74
- if (typeof value === 'number') return value > 1e12 ? value : value * 1000
75
- const parsed = Date.parse(String(value))
76
- return Number.isFinite(parsed) ? parsed : 0
77
- }
78
85
 
79
86
  /**
80
87
  * Infer a coarse state from the store's own status plus how recently the
@@ -295,7 +302,7 @@ function readDshLog(file) {
295
302
  try {
296
303
  info = statSync(file)
297
304
  } catch {
298
- return { title: '', lastStart: 0, lastEnd: null }
305
+ return { title: '', lastStart: 0, lastEnd: null, lastCall: null }
299
306
  }
300
307
  const memo = logMemo.get(file)
301
308
  if (memo && memo.mtime === info.mtimeMs) return memo.value
@@ -303,6 +310,7 @@ function readDshLog(file) {
303
310
  let title = ''
304
311
  let lastStart = 0
305
312
  let lastEnd = null
313
+ let lastCall = null
306
314
  try {
307
315
  const headLength = Math.min(info.size, HEAD_WINDOW)
308
316
  const head = readWindow(file, info.size, 0, headLength)
@@ -332,6 +340,12 @@ function readDshLog(file) {
332
340
  let scanned = 0
333
341
  for (let index = tailFrames.length - 1; index >= 1 && scanned < 24; index -= 1, scanned += 1) {
334
342
  for (const event of eventsOfFrame(tail, tailFrames[index])) {
343
+ if (event?.type === 'tool/call') {
344
+ // The walk goes newest frame first, so the newest call wins even
345
+ // though every candidate is compared rather than taken first.
346
+ const call = summarizeCall(event)
347
+ if (call && (!lastCall || call.time > lastCall.time)) lastCall = call
348
+ }
335
349
  if (event?.type === 'turn/start' && typeof event.time === 'number') {
336
350
  lastStart = Math.max(lastStart, event.time)
337
351
  }
@@ -349,7 +363,7 @@ function readDshLog(file) {
349
363
  /* unreadable log means no title and no turn facts, not a failed session */
350
364
  }
351
365
 
352
- const value = { title, lastStart, lastEnd }
366
+ const value = { title, lastStart, lastEnd, lastCall }
353
367
  logMemo.set(file, { mtime: info.mtimeMs, value })
354
368
  return value
355
369
  }
@@ -401,8 +415,10 @@ function collectDsh(now, conf) {
401
415
  rows.push({
402
416
  tool: 'dsh',
403
417
  workspace: knownWorkspaces.get(id) ?? workspaceLabel(decodeDshWorkspace(workspace.name)),
404
- title: log.title || `未命名 · ${id.slice(0, 4)}`,
418
+ title: resolveTitle({ declared: log.title, fallback: `未命名 · ${id.slice(0, 4)}` }),
405
419
  detail: '',
420
+ // Only a session with an open turn has a "right now" worth showing.
421
+ doing: status === 'running' ? doingLine(log.lastCall) : '',
406
422
  // Full id the host's sessions service accepts for navigation.
407
423
  sessionId: session.name.startsWith('session-') ? session.name : `session-${session.name}`,
408
424
  lastActivity: mtime,
@@ -479,20 +495,21 @@ function collectCodex(now, conf) {
479
495
  } else {
480
496
  for (const line of head.split('\n')) {
481
497
  if (!line.includes('"role":"user"')) continue
498
+ let record
482
499
  try {
483
- const record = JSON.parse(line)
484
- const payload = record?.payload
485
- if (payload?.type !== 'message' || payload.role !== 'user') continue
486
- const text = (Array.isArray(payload.content) ? payload.content : [])
487
- .map((part) => part?.text ?? '')
488
- .join(' ')
489
- const clean = cleanPrompt(text)
490
- if (clean === '' || isSyntheticPrompt(text)) continue
491
- prompt = text
492
- break
500
+ record = JSON.parse(line)
493
501
  } catch {
494
- /* a line cut off by the head limit is not a prompt */
502
+ continue // a line cut off by the head limit is not a prompt
495
503
  }
504
+ const payload = record?.payload
505
+ if (payload?.type !== 'message' || payload.role !== 'user') continue
506
+ const text = (Array.isArray(payload.content) ? payload.content : [])
507
+ .map((part) => part?.text ?? '')
508
+ .join(' ')
509
+ const clean = cleanPrompt(text)
510
+ if (clean === '' || isSyntheticPrompt(text)) continue
511
+ prompt = text
512
+ break
496
513
  }
497
514
  textMemo.set(full, { mtime, prompt })
498
515
  }
@@ -500,7 +517,12 @@ function collectCodex(now, conf) {
500
517
  rows.push({
501
518
  tool: 'codex',
502
519
  workspace: workspaceLabel(cwd?.replace(/\\\\/g, '\\')),
503
- title: titleFromPrompt(prompt) || (sessionId ? sessionId.slice(0, 8) : full.slice(-20, -6)),
520
+ title: resolveTitle({
521
+ prompt: titleFromPrompt(prompt),
522
+ fallback: sessionId ? sessionId.slice(0, 8) : full.slice(-20, -6),
523
+ }),
524
+ cwd: cwd?.replace(/\\\\/g, '\\'),
525
+ openId: sessionId,
504
526
  detail: provider ?? '',
505
527
  lastActivity: mtime,
506
528
  status: inferStatus(mtime, '', now, conf),
@@ -510,25 +532,17 @@ function collectCodex(now, conf) {
510
532
  return { tool: 'codex', available: true, count: found.length, items: rows }
511
533
  }
512
534
 
513
- /** Open one SQLite file read-only through the built-in driver. */
514
- async function openSqlite(path) {
515
- const { DatabaseSync } = await import('node:sqlite')
516
- try {
517
- return new DatabaseSync(path, { readOnly: true })
518
- } catch {
519
- return new DatabaseSync(path)
520
- }
521
- }
522
535
 
523
- async function collectOpencode(now, conf) {
524
- const path = join(homedir(), '.local', 'share', 'opencode', 'opencode.db')
525
- if (!existsSync(path)) return { tool: 'opencode', available: false, reason: 'no opencode.db' }
526
- let db
527
- try {
528
- db = await openSqlite(path)
529
- const rows = db
530
- .prepare(
531
- `SELECT s.id AS id, s.directory AS dir, s.title AS title, MAX(m.time_updated) AS t,
536
+ /** opencode / ZCode-shaped store: `session` joined to `message`, plus todos. */
537
+ function collectOpencode(now, conf) {
538
+ return readSqliteSource({
539
+ tool: 'opencode',
540
+ now,
541
+ conf,
542
+ candidates: [join(homedir(), '.local', 'share', 'opencode', 'opencode.db')],
543
+ missing: 'no opencode.db',
544
+ countSql: 'SELECT COUNT(*) AS n FROM session',
545
+ rowSql: `SELECT s.id AS id, s.directory AS dir, s.title AS title, MAX(m.time_updated) AS t,
532
546
  (SELECT COUNT(*) FROM todo WHERE session_id = s.id) AS todos,
533
547
  (SELECT COUNT(*) FROM todo WHERE session_id = s.id AND status != 'completed') AS open_todos,
534
548
  (SELECT json_extract(p.data, '$.text')
@@ -539,43 +553,32 @@ async function collectOpencode(now, conf) {
539
553
  ORDER BY pm.time_created, p.time_created LIMIT 1) AS first_text
540
554
  FROM session s LEFT JOIN message m ON m.session_id = s.id
541
555
  GROUP BY s.id ORDER BY t DESC LIMIT ?`,
542
- )
543
- .all(conf.perSource)
544
- const total = db.prepare('SELECT COUNT(*) AS n FROM session').get()?.n ?? rows.length
545
- const items = rows.map((row) => {
556
+ map: (row, { now: at, conf: settings }) => {
546
557
  const last = toMs(row.t)
547
558
  const open = Number(row.open_todos) || 0
548
559
  const all = Number(row.todos) || 0
549
- // opencode names a fresh session "New session - <timestamp>"; that is a
550
- // placeholder, not a name, so prefer the first thing the user asked.
560
+ // opencode names a fresh session "New session - <timestamp>" at
561
+ // creation; that is a placeholder, not a name, so the first prompt wins.
551
562
  const declared = String(row.title ?? '')
552
- const placeholder = declared === '' || /^new session\b/i.test(declared)
553
563
  const prompt = String(row.first_text ?? '').replace(/\s+/g, ' ').trim()
554
- const title = placeholder
555
- ? prompt
556
- ? `${prompt.slice(0, 40)}${prompt.length > 40 ? '…' : ''}`
557
- : declared || String(row.id).slice(0, 8)
558
- : declared
559
564
  return {
560
565
  tool: 'opencode',
561
566
  workspace: workspaceLabel(row.dir),
562
- title,
567
+ title: resolveTitle({
568
+ declared,
569
+ prompt: shortPrompt(prompt),
570
+ fallback: String(row.id).slice(0, 8),
571
+ distrustDeclared: true,
572
+ }),
573
+ cwd: row.dir,
574
+ openId: row.id,
563
575
  detail: open > 0 ? `todo ${open}/${all}` : '',
564
576
  lastActivity: last,
565
- status: inferStatus(last, '', now, conf),
577
+ status: inferStatus(last, '', at, settings),
566
578
  key: row.id,
567
579
  }
568
- })
569
- return { tool: 'opencode', available: true, count: Number(total), items }
570
- } catch (error) {
571
- return { tool: 'opencode', available: false, reason: String(error?.message ?? error) }
572
- } finally {
573
- try {
574
- db?.close()
575
- } catch {
576
- /* already gone */
577
- }
578
- }
580
+ },
581
+ })
579
582
  }
580
583
 
581
584
  /** Context pressure and credits from WorkBuddy's own usage table, when present. */
@@ -599,45 +602,36 @@ function usageDetail(row) {
599
602
  return parts.join(' · ')
600
603
  }
601
604
 
602
- async function collectWorkbuddy(now, conf) {
603
- const path = join(homedir(), '.workbuddy', 'workbuddy.db')
604
- if (!existsSync(path)) return { tool: 'workbuddy', available: false, reason: 'no workbuddy.db' }
605
- let db
606
- try {
607
- db = await openSqlite(path)
608
- const rows = db
609
- .prepare(
610
- `SELECT s.id AS id, s.cwd AS cwd, s.title AS title, s.status AS status,
605
+ /** WorkBuddy: `sessions` with the spend in a side table. */
606
+ function collectWorkbuddy(now, conf) {
607
+ return readSqliteSource({
608
+ tool: 'workbuddy',
609
+ now,
610
+ conf,
611
+ candidates: [join(homedir(), '.workbuddy', 'workbuddy.db')],
612
+ missing: 'no workbuddy.db',
613
+ countSql: 'SELECT COUNT(*) AS n FROM sessions WHERE deleted_at IS NULL',
614
+ rowSql: `SELECT s.id AS id, s.cwd AS cwd, s.title AS title, s.status AS status,
611
615
  s.last_activity_at AS last_activity_at, s.updated_at AS updated_at,
612
616
  u.used AS used, u.size AS size, u.credit_json AS credit_json
613
617
  FROM sessions s LEFT JOIN session_usage u ON u.session_id = s.id
614
618
  WHERE s.deleted_at IS NULL
615
619
  ORDER BY COALESCE(s.last_activity_at, s.updated_at) DESC LIMIT ?`,
616
- )
617
- .all(conf.perSource)
618
- const total = db.prepare('SELECT COUNT(*) AS n FROM sessions WHERE deleted_at IS NULL').get()?.n ?? rows.length
619
- const items = rows.map((row) => {
620
+ map: (row, { now: at, conf: settings }) => {
620
621
  const last = toMs(row.last_activity_at) || toMs(row.updated_at)
621
622
  return {
622
623
  tool: 'workbuddy',
623
624
  workspace: workspaceLabel(row.cwd),
624
- title: row.title || String(row.id).slice(0, 8),
625
+ title: resolveTitle({ declared: row.title, fallback: String(row.id).slice(0, 8) }),
626
+ cwd: row.cwd,
627
+ openId: row.id,
625
628
  detail: usageDetail(row),
626
629
  lastActivity: last,
627
- status: inferStatus(last, row.status, now, conf),
630
+ status: inferStatus(last, row.status, at, settings),
628
631
  key: row.id,
629
632
  }
630
- })
631
- return { tool: 'workbuddy', available: true, count: Number(total), items }
632
- } catch (error) {
633
- return { tool: 'workbuddy', available: false, reason: String(error?.message ?? error) }
634
- } finally {
635
- try {
636
- db?.close()
637
- } catch {
638
- /* already gone */
639
- }
640
- }
633
+ },
634
+ })
641
635
  }
642
636
 
643
637
  /**
@@ -648,34 +642,6 @@ async function collectWorkbuddy(now, conf) {
648
642
  /** Memo for derived titles of formats that need a parse (gemini, codex). */
649
643
  const textMemo = new Map()
650
644
 
651
- /** Strip the machine-instruction preamble agents inject ahead of the real ask. */
652
- function cleanPrompt(text) {
653
- let value = String(text ?? '').replace(/\r/g, '')
654
- // Gemini puts its rules in a leading [..] block; markdown headings are noise.
655
- value = value.replace(/^\s*\[[^\]]*\]\s*/i, '')
656
- value = value.replace(/^\s*#{1,6}\s*/, '')
657
- value = value.replace(/\s+/g, ' ').trim()
658
- return value
659
- }
660
-
661
- /** Shorten a prompt into a title, or '' when there is nothing usable. */
662
- function titleFromPrompt(text, limit = 40) {
663
- const clean = cleanPrompt(text)
664
- if (clean === '') return ''
665
- return `${clean.slice(0, limit)}${clean.length > limit ? '…' : ''}`
666
- }
667
-
668
- /** Whether a log line is machine instruction rather than something a person asked. */
669
- function isSyntheticPrompt(text) {
670
- const value = String(text ?? '').trimStart()
671
- return (
672
- value.startsWith('<') ||
673
- /^#?\s*AGENTS\.md instructions/i.test(value) ||
674
- /^#?\s*AGENTS\.md\b/i.test(value) ||
675
- /^(environment_context|skills_instructions|user_instructions)/i.test(value)
676
- )
677
- }
678
-
679
645
  function collectGemini(now, conf) {
680
646
  const root = join(homedir(), '.gemini', 'tmp')
681
647
  if (!existsSync(root)) return { tool: 'gemini', available: false, reason: 'no ~/.gemini/tmp' }
@@ -730,7 +696,10 @@ function collectGemini(now, conf) {
730
696
  rows.push({
731
697
  tool: 'gemini',
732
698
  workspace: workspaceLabel(projectRoot) || project.name,
733
- title: titleFromPrompt(prompt) || chat.name.replace(/^session-/, '').replace(/\.json$/, '').slice(0, 16),
699
+ title: resolveTitle({
700
+ prompt: titleFromPrompt(prompt),
701
+ fallback: chat.name.replace(/^session-/, '').replace(/\.json$/, '').slice(0, 16),
702
+ }),
734
703
  detail: '',
735
704
  lastActivity: mtime,
736
705
  status: inferStatus(mtime, '', now, conf),
@@ -751,42 +720,33 @@ function collectGemini(now, conf) {
751
720
  * ZCode keeps an opencode-shaped SQLite store: `session` (title, directory)
752
721
  * joined with `message` for the last activity time.
753
722
  */
754
- async function collectZcode(now, conf) {
755
- const path = join(homedir(), '.zcode', 'cli', 'db', 'db.sqlite')
756
- if (!existsSync(path)) return { tool: 'zcode', available: false, reason: 'no ~/.zcode/cli/db' }
757
- let db
758
- try {
759
- db = await openSqlite(path)
760
- const rows = db
761
- .prepare(
762
- `SELECT s.id AS id, s.title AS title, s.directory AS dir, MAX(m.time_updated) AS t
723
+ /** ZCode: same `session` + `message` shape as opencode, without the todos. */
724
+ function collectZcode(now, conf) {
725
+ return readSqliteSource({
726
+ tool: 'zcode',
727
+ now,
728
+ conf,
729
+ candidates: [join(homedir(), '.zcode', 'cli', 'db', 'db.sqlite')],
730
+ missing: 'no ~/.zcode/cli/db',
731
+ countSql: 'SELECT COUNT(*) AS n FROM session',
732
+ rowSql: `SELECT s.id AS id, s.title AS title, s.directory AS dir, MAX(m.time_updated) AS t
763
733
  FROM session s LEFT JOIN message m ON m.session_id = s.id
764
734
  GROUP BY s.id ORDER BY t DESC LIMIT ?`,
765
- )
766
- .all(conf.perSource)
767
- const total = db.prepare('SELECT COUNT(*) AS n FROM session').get()?.n ?? rows.length
768
- const items = rows.map((row) => {
735
+ map: (row, { now: at, conf: settings }) => {
769
736
  const last = toMs(row.t)
770
737
  return {
771
738
  tool: 'zcode',
772
739
  workspace: workspaceLabel(row.dir),
773
- title: row.title || String(row.id).slice(0, 12),
740
+ title: resolveTitle({ declared: row.title, fallback: String(row.id).slice(0, 12) }),
741
+ cwd: row.dir,
742
+ openId: row.id,
774
743
  detail: '',
775
744
  lastActivity: last,
776
- status: inferStatus(last, '', now, conf),
745
+ status: inferStatus(last, '', at, settings),
777
746
  key: row.id,
778
747
  }
779
- })
780
- return { tool: 'zcode', available: true, count: Number(total), items }
781
- } catch (error) {
782
- return { tool: 'zcode', available: false, reason: String(error?.message ?? error) }
783
- } finally {
784
- try {
785
- db?.close()
786
- } catch {
787
- /* already gone */
788
- }
789
- }
748
+ },
749
+ })
790
750
  }
791
751
 
792
752
  /**
@@ -794,19 +754,19 @@ async function collectZcode(now, conf) {
794
754
  * store; the row keeps both a status column and a JSON record with the
795
755
  * workspace directory.
796
756
  */
797
- async function collectMinimax(now, conf) {
798
- const candidates = [
799
- join(homedir(), '.minimax', 'v2', 'sqlite', 'runtime-state.sqlite'),
800
- join(homedir(), '.mavis', 'v2', 'sqlite', 'runtime-state.sqlite'),
801
- ]
802
- const path = candidates.find((candidate) => existsSync(candidate))
803
- if (!path) return { tool: 'minimax', available: false, reason: 'no minimax runtime state' }
804
- let db
805
- try {
806
- db = await openSqlite(path)
807
- const rows = db
808
- .prepare(
809
- `SELECT session_id AS id, agent_name AS agent, status AS status,
757
+ /** MiniMax / Mavis runtime state: sessions plus their first user message. */
758
+ function collectMinimax(now, conf) {
759
+ return readSqliteSource({
760
+ tool: 'minimax',
761
+ now,
762
+ conf,
763
+ candidates: [
764
+ join(homedir(), '.minimax', 'v2', 'sqlite', 'runtime-state.sqlite'),
765
+ join(homedir(), '.mavis', 'v2', 'sqlite', 'runtime-state.sqlite'),
766
+ ],
767
+ missing: 'no minimax runtime state',
768
+ countSql: 'SELECT COUNT(*) AS n FROM local_runtime_sessions WHERE archived = 0',
769
+ rowSql: `SELECT session_id AS id, agent_name AS agent, status AS status,
810
770
  updated_at_ms AS t, record_json AS record,
811
771
  (SELECT json_extract(m.data_json, '$.msg_content')
812
772
  FROM local_runtime_message_rows m
@@ -815,12 +775,7 @@ async function collectMinimax(now, conf) {
815
775
  FROM local_runtime_sessions s
816
776
  WHERE archived = 0
817
777
  ORDER BY updated_at_ms DESC LIMIT ?`,
818
- )
819
- .all(conf.perSource)
820
- const total =
821
- db.prepare('SELECT COUNT(*) AS n FROM local_runtime_sessions WHERE archived = 0').get()?.n ??
822
- rows.length
823
- const items = rows.map((row) => {
778
+ map: (row, { now: at, conf: settings }) => {
824
779
  const last = toMs(row.t)
825
780
  const record = String(row.record ?? '')
826
781
  const workspace = /"workspaceDir"\s*:\s*"((?:[^"\\]|\\.)*)"/.exec(record)?.[1]
@@ -828,27 +783,23 @@ async function collectMinimax(now, conf) {
828
783
  // the same fallback DSH itself uses before the model names a session.
829
784
  const recorded = /"title"\s*:\s*"((?:[^"\\]|\\.)*)"/.exec(record)?.[1]
830
785
  const prompt = String(row.first_prompt ?? '').replace(/\s+/g, ' ').trim()
831
- const title = recorded || (prompt ? `${prompt.slice(0, 40)}${prompt.length > 40 ? '…' : ''}` : '')
832
786
  return {
833
787
  tool: 'minimax',
834
788
  workspace: workspaceLabel(workspace?.replace(/\\\\/g, '\\')),
835
- title: title || `${row.agent ?? 'minimax'} · ${String(row.id).slice(-8)}`,
789
+ title: resolveTitle({
790
+ declared: recorded,
791
+ prompt: shortPrompt(prompt),
792
+ fallback: `${row.agent ?? 'minimax'} · ${String(row.id).slice(-8)}`,
793
+ }),
794
+ cwd: workspace, // already normalised above; the opener needs an absolute path
795
+ openId: row.id,
836
796
  detail: row.agent ? String(row.agent) : '',
837
797
  lastActivity: last,
838
- status: inferStatus(last, row.status, now, conf),
798
+ status: inferStatus(last, row.status, at, settings),
839
799
  key: row.id,
840
800
  }
841
- })
842
- return { tool: 'minimax', available: true, count: Number(total), items }
843
- } catch (error) {
844
- return { tool: 'minimax', available: false, reason: String(error?.message ?? error) }
845
- } finally {
846
- try {
847
- db?.close()
848
- } catch {
849
- /* already gone */
850
- }
851
- }
801
+ },
802
+ })
852
803
  }
853
804
 
854
805
  /**
@@ -898,7 +849,10 @@ function collectClaude(now, conf) {
898
849
  rows.push({
899
850
  tool: 'claude',
900
851
  workspace: workspaceLabel(cwd?.replace(/\\\\/g, '\\')),
901
- title: summary || full.split(/[\\/]/).pop().replace(/\.jsonl$/, '').slice(0, 8),
852
+ title: resolveTitle({
853
+ declared: summary,
854
+ fallback: full.split(/[\\/]/).pop().replace(/\.jsonl$/, '').slice(0, 8),
855
+ }),
902
856
  detail: '',
903
857
  lastActivity: mtime,
904
858
  status: inferStatus(mtime, '', now, conf),
@@ -955,7 +909,7 @@ function collectTraeCli(now, conf) {
955
909
  rows.push({
956
910
  tool: 'trae',
957
911
  workspace: workspaceLabel(cwd?.replace(/\\\\/g, '\\')),
958
- title: id ? id.slice(0, 8) : full.slice(-20, -6),
912
+ title: resolveTitle({ fallback: id ? id.slice(0, 8) : full.slice(-20, -6) }),
959
913
  detail: 'cli',
960
914
  lastActivity: mtime,
961
915
  status: inferStatus(mtime, '', now, conf),
@@ -970,34 +924,44 @@ function collectTraeCli(now, conf) {
970
924
  * `available: false` instead of failing the whole board.
971
925
  * @returns the normalized board payload.
972
926
  */
927
+ /**
928
+ * The sources the board reads, in the order they appear in the payload.
929
+ *
930
+ * A table rather than nine hand-written promise wrappers: each wrapper existed
931
+ * only to turn "one source failed" into "one source unavailable", and two of
932
+ * the nine (opencode, workbuddy) had been left out of it — a throw from either
933
+ * took the whole board down instead of degrading one row of the footer.
934
+ */
935
+ const COLLECTORS = [
936
+ ['dsh', collectDsh],
937
+ ['codex', collectCodex],
938
+ ['opencode', collectOpencode],
939
+ ['workbuddy', collectWorkbuddy],
940
+ ['gemini', collectGemini],
941
+ ['zcode', collectZcode],
942
+ ['minimax', collectMinimax],
943
+ ['claude', collectClaude],
944
+ ['trae', collectTraeCli],
945
+ ]
946
+
947
+ /**
948
+ * Run one collector, reporting a failure as an unavailable source rather than
949
+ * as a failed board.
950
+ */
951
+ async function runCollector(tool, collect, now, conf) {
952
+ try {
953
+ return await collect(now, conf)
954
+ } catch (error) {
955
+ return { tool, available: false, reason: String(error?.message ?? error) }
956
+ }
957
+ }
958
+
973
959
  export async function collectBoard(extraSources = []) {
974
960
  const now = Date.now()
975
961
  const conf = tunables()
976
- const sources = await Promise.all([
977
- Promise.resolve()
978
- .then(() => collectDsh(now, conf))
979
- .catch((error) => ({ tool: 'dsh', available: false, reason: String(error?.message ?? error) })),
980
- Promise.resolve()
981
- .then(() => collectCodex(now, conf))
982
- .catch((error) => ({ tool: 'codex', available: false, reason: String(error?.message ?? error) })),
983
- collectOpencode(now, conf),
984
- collectWorkbuddy(now, conf),
985
- Promise.resolve()
986
- .then(() => collectGemini(now, conf))
987
- .catch((error) => ({ tool: 'gemini', available: false, reason: String(error?.message ?? error) })),
988
- Promise.resolve()
989
- .then(() => collectZcode(now, conf))
990
- .catch((error) => ({ tool: 'zcode', available: false, reason: String(error?.message ?? error) })),
991
- Promise.resolve()
992
- .then(() => collectMinimax(now, conf))
993
- .catch((error) => ({ tool: 'minimax', available: false, reason: String(error?.message ?? error) })),
994
- Promise.resolve()
995
- .then(() => collectClaude(now, conf))
996
- .catch((error) => ({ tool: 'claude', available: false, reason: String(error?.message ?? error) })),
997
- Promise.resolve()
998
- .then(() => collectTraeCli(now, conf))
999
- .catch((error) => ({ tool: 'trae', available: false, reason: String(error?.message ?? error) })),
1000
- ])
962
+ const sources = await Promise.all(
963
+ COLLECTORS.map(([tool, collect]) => runCollector(tool, collect, now, conf)),
964
+ )
1001
965
  // Stores discovery matched but nobody wrote a collector for: one generic
1002
966
  // query each, capped, and only when the shape is fully verified.
1003
967
  if (conf.autoDiscover !== false && extraSources.length > 0) {