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.
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Turning a card into "open that session in its own tool".
3
+ *
4
+ * Only tools whose CLI can be asked to resume a specific session get an opener,
5
+ * and each entry carries the flag as it was verified on the machine — not as it
6
+ * is documented. A tool with no opener keeps the old behaviour (copy the
7
+ * workspace path), because a click that appears to do something and does not is
8
+ * worse than a click that copies.
9
+ *
10
+ * The id is validated rather than trusted: it reaches a command line, and these
11
+ * ids come from a store the board merely reads.
12
+ */
13
+
14
+ /** `[tool] → how to resume one of its sessions in a terminal. */
15
+ export const OPENERS = {
16
+ opencode: {
17
+ label: '在 opencode 里打开',
18
+ command: 'opencode',
19
+ // Verified: `opencode -s <sessionID>` continues that session.
20
+ args: (id) => ['-s', id],
21
+ },
22
+ codex: {
23
+ label: '在 codex 里打开',
24
+ command: 'codex',
25
+ // Verified: `codex resume [SESSION_ID]` takes a UUID.
26
+ args: (id) => ['resume', id],
27
+ },
28
+ }
29
+
30
+ /** Session ids reach a shell, so they are held to a shape that cannot escape one. */
31
+ const SAFE_ID = /^[A-Za-z0-9_-]{1,128}$/
32
+
33
+ /** A path the opener may run in: absolute Windows or POSIX, nothing else. */
34
+ function absolute(path) {
35
+ const value = String(path ?? '').trim()
36
+ if (/^[A-Za-z]:[\\/]/.test(value)) return value
37
+ if (value.startsWith('/')) return value
38
+ return undefined
39
+ }
40
+
41
+ /**
42
+ * Decide what a click on a card should run.
43
+ *
44
+ * Pure: no spawning, no filesystem. The caller turns the plan into a process,
45
+ * which is what makes this testable without opening terminals.
46
+ *
47
+ * @returns `{ ok: true, tool, command, args, cwd, label }` or `{ ok: false, reason }`
48
+ * where reason is 'no-opener' | 'bad-id'.
49
+ */
50
+ export function planOpen({ tool, openId, cwd }) {
51
+ const opener = OPENERS[String(tool ?? '')]
52
+ if (!opener) return { ok: false, reason: 'no-opener' }
53
+ const id = String(openId ?? '').trim()
54
+ if (!SAFE_ID.test(id)) return { ok: false, reason: 'bad-id' }
55
+ return {
56
+ ok: true,
57
+ tool,
58
+ command: opener.command,
59
+ args: opener.args(id),
60
+ cwd: absolute(cwd),
61
+ label: opener.label,
62
+ }
63
+ }
64
+
65
+ /** Every tool that can be opened, with the label the UI should show. */
66
+ export function openerLabels() {
67
+ return Object.fromEntries(Object.entries(OPENERS).map(([tool, opener]) => [tool, opener.label]))
68
+ }
69
+
70
+ /** Whether a tool has an opener at all, for the UI to describe the click. */
71
+ export function openerLabel(tool) {
72
+ return OPENERS[String(tool ?? '')]?.label ?? ''
73
+ }
package/lib/rules.mjs ADDED
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Field-level rules shared by every collector.
3
+ *
4
+ * Each store names and shapes these things differently, but the decision is the
5
+ * same each time: what counts as a timestamp, what counts as a title, and which
6
+ * of the three possible title sources wins. Keeping the decisions here means a
7
+ * fix lands once instead of four times — the opencode, ZCode and MiniMax stores
8
+ * are close enough that their collectors had drifted apart on details nobody
9
+ * intended.
10
+ */
11
+
12
+ /**
13
+ * Epoch milliseconds from a number, a numeric string or a date string.
14
+ *
15
+ * Stores disagree on units: some count seconds, some milliseconds, a few hand
16
+ * back ISO strings. Anything above 1e12 is already milliseconds (that is year
17
+ * 2001 in ms), so the test is a unit guess, not a range check.
18
+ */
19
+ export function toMs(value) {
20
+ if (value === null || value === undefined) return 0
21
+ if (typeof value === 'number') return value > 1e12 ? value : value * 1000
22
+ const parsed = Date.parse(String(value))
23
+ return Number.isFinite(parsed) ? parsed : 0
24
+ }
25
+
26
+ /**
27
+ * Strip the machine-instruction preamble agents put ahead of the real ask.
28
+ *
29
+ * Gemini wraps its whole rule block in leading `[..]`, and markdown headings in
30
+ * a pasted prompt are structure rather than a name.
31
+ */
32
+ export function cleanPrompt(text) {
33
+ let value = String(text ?? '').replace(/\r/g, '')
34
+ value = value.replace(/^\s*\[[^\]]*\]\s*/i, '')
35
+ value = value.replace(/^\s*#{1,6}\s*/, '')
36
+ return value.replace(/\s+/g, ' ').trim()
37
+ }
38
+
39
+ /** Cut a prompt down to title length, marking the cut. */
40
+ export function shortPrompt(text, limit = 40) {
41
+ const value = String(text ?? '')
42
+ if (value === '') return ''
43
+ return `${value.slice(0, limit)}${value.length > limit ? '…' : ''}`
44
+ }
45
+
46
+ /** A prompt as a title: rules block removed first, then shortened. */
47
+ export function titleFromPrompt(text, limit = 40) {
48
+ const clean = cleanPrompt(text)
49
+ return clean === '' ? '' : shortPrompt(clean, limit)
50
+ }
51
+
52
+ /** Whether a log line is machine instruction rather than something a person asked. */
53
+ export function isSyntheticPrompt(text) {
54
+ const value = String(text ?? '').trimStart()
55
+ return (
56
+ value.startsWith('<') ||
57
+ /^#?\s*AGENTS\.md instructions/i.test(value) ||
58
+ /^#?\s*AGENTS\.md\b/i.test(value) ||
59
+ /^(environment_context|skills_instructions|user_instructions)/i.test(value)
60
+ )
61
+ }
62
+
63
+ /**
64
+ * Names a store writes before anyone has named the session.
65
+ *
66
+ * `opencode` writes "New session - <ISO timestamp>" at creation and only
67
+ * replaces it if the user renames. Showing that as a title reads like a name
68
+ * while saying nothing, so such a name loses to the first prompt.
69
+ *
70
+ * Deliberately only this prefix: it is the shape one store actually emits.
71
+ * Guessing at other placeholder wordings would change what the other sources
72
+ * show, and "未命名 · ab12" is a label this plugin generates, not a name a
73
+ * store hands over.
74
+ */
75
+ const PLACEHOLDER_TITLE = /^new session\b/i
76
+
77
+ /** True when a store-supplied name carries no information. */
78
+ export function isPlaceholderTitle(value) {
79
+ const name = String(value ?? '').trim()
80
+ return name === '' || PLACEHOLDER_TITLE.test(name)
81
+ }
82
+
83
+ /**
84
+ * Decide which of the three title sources wins.
85
+ *
86
+ * @param declared - the name the store itself wrote (`undefined` when it has none).
87
+ * @param prompt - the first thing the user asked, already shortened.
88
+ * @param fallback - a label made from an id, for sessions with neither.
89
+ * @param distrustDeclared - the store writes placeholders, so a prompt outranks
90
+ * the name. Only `opencode` does this; the flag keeps every other source's
91
+ * behaviour exactly as it was.
92
+ */
93
+ export function resolveTitle({ declared, prompt = '', fallback = '', distrustDeclared = false }) {
94
+ const name = typeof declared === 'string' ? declared.trim() : ''
95
+ const usable = name !== '' && !(distrustDeclared && PLACEHOLDER_TITLE.test(name))
96
+ if (usable) return name
97
+ if (prompt !== '') return prompt
98
+ // A placeholder still beats "unknown", and an empty name falls back to the id.
99
+ return name !== '' ? name : fallback
100
+ }
@@ -0,0 +1,80 @@
1
+ /**
2
+ * What a session is doing right now, from its own tool calls.
3
+ *
4
+ * The log records every tool call with a `name` and an `arguments` JSON string,
5
+ * and agents put a human sentence in `arguments.description` whenever the tool
6
+ * has one — that line is written for a person to read, so it is what the board
7
+ * shows. Inventing a summary from the command line would be worse than showing
8
+ * the one the agent already wrote.
9
+ *
10
+ * Everything here is pure: the caller supplies the events.
11
+ */
12
+
13
+ /** Arguments that carry a human-readable target, most specific first. */
14
+ const TARGET_KEYS = [
15
+ 'description',
16
+ 'file_path',
17
+ 'filePath',
18
+ 'path',
19
+ 'notebook_path',
20
+ 'pattern',
21
+ 'query',
22
+ 'command',
23
+ 'url',
24
+ 'prompt',
25
+ ]
26
+
27
+ /** Longest target worth putting on a card; the drawer can show more. */
28
+ const MAX_TARGET = 120
29
+
30
+ function parseArguments(raw) {
31
+ if (typeof raw !== 'string' || raw === '') return null
32
+ try {
33
+ const parsed = JSON.parse(raw)
34
+ return parsed && typeof parsed === 'object' ? parsed : null
35
+ } catch {
36
+ return null
37
+ }
38
+ }
39
+
40
+ /**
41
+ * A short phrase describing what a tool call is aimed at.
42
+ *
43
+ * Returns '' when the arguments carry nothing usable, so callers can decide to
44
+ * show only the tool name rather than a dangling separator.
45
+ */
46
+ export function callTarget(argumentsValue) {
47
+ const args = typeof argumentsValue === 'string' ? parseArguments(argumentsValue) : argumentsValue
48
+ if (!args || typeof args !== 'object') return ''
49
+ for (const key of TARGET_KEYS) {
50
+ const value = args[key]
51
+ if (typeof value !== 'string') continue
52
+ const text = value.replace(/\s+/g, ' ').trim()
53
+ if (text !== '') return text.length > MAX_TARGET ? `${text.slice(0, MAX_TARGET)}…` : text
54
+ }
55
+ return ''
56
+ }
57
+
58
+ /**
59
+ * One `tool/call` event as the board needs it.
60
+ * @returns `{ name, target, time }` or null when the event is not a tool call.
61
+ */
62
+ export function summarizeCall(event) {
63
+ if (!event || event.type !== 'tool/call') return null
64
+ const name = typeof event.data?.name === 'string' ? event.data.name : ''
65
+ if (name === '') return null
66
+ return {
67
+ name,
68
+ target: callTarget(event.data?.arguments),
69
+ time: typeof event.time === 'number' ? event.time : 0,
70
+ }
71
+ }
72
+
73
+ /**
74
+ * The one line a running card shows: `name · target`, or just the name when the
75
+ * call carries no description.
76
+ */
77
+ export function doingLine(call) {
78
+ if (!call || !call.name) return ''
79
+ return call.target ? `${call.name} · ${call.target}` : call.name
80
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-atc",
3
- "version": "0.19.0",
3
+ "version": "0.23.0",
4
4
  "description": "Agent 空管中心 for DeepSeek Harness: one sidebar panel listing every local agent session (DSH, codex, opencode, WorkBuddy, Gemini) with attention-first grouping and folded history — zero token, host-side inference.",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -68,7 +68,8 @@
68
68
  "brand-icons:check": "node scripts/build-brand-icons.mjs --check",
69
69
  "scan-agents": "node scripts/scan-agents.mjs",
70
70
  "empty-check": "node scripts/empty-check.mjs",
71
- "sync-mirror": "node scripts/sync-mirror.mjs"
71
+ "sync-mirror": "node scripts/sync-mirror.mjs",
72
+ "board-snapshot": "node scripts/board-snapshot.mjs"
72
73
  },
73
74
  "peerDependencies": {
74
75
  "@deepseek-ai/cordis": "^4.0.1"