dsh-baton-host 0.6.16 → 0.6.18

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 (2) hide show
  1. package/lib/index.js +91 -16
  2. package/package.json +2 -2
package/lib/index.js CHANGED
@@ -65,8 +65,11 @@ function normalizePath(p) {
65
65
  // one more in the sidebar for each subfolder or throw-away folder. Instead it joins:
66
66
  // - the conversation's own folder (base), when the target is inside it: a Claude Code chat in
67
67
  // Coding handing over Coding/app joins the Coding workspace;
68
+ // - for a target outside it, the nearest workspace around the target, else the conversation's
69
+ // own folder: a chat in Coding handing over a folder on another disk joins the Coding workspace;
68
70
  // - for folders clients make per conversation, one shared folder: Codex chats without a project
69
- // (Documents/Codex/<date>/<chat>), Claude scratch folders (…/scratch-workspaces/…), Claude
71
+ // (Documents/Codex/<date>/<chat>), Claude scratch folders (…/scratch-workspaces/…, Claude
72
+ // Code's <tmp>/claude-<uid>/…/scratchpad), Antigravity's scratch and brain folders, Claude
70
73
  // worktrees (<project>/.claude/worktrees/<name>, joined to the project) and Codex worktrees
71
74
  // (~/.codex/worktrees/…).
72
75
  // The session then starts in that folder and the message names the target folder.
@@ -86,8 +89,16 @@ function sharedFolder(dir) {
86
89
  if (same(at, 'worktrees') && i >= 2 && same(parts[i - 1], '.claude')) return { path: upto(i + 1), title: 'Claude worktrees' }
87
90
  if (same(at, 'worktrees') && same(parts[i - 1], '.codex')) return { path: upto(i + 1), title: 'Codex worktrees' }
88
91
  if (same(at, 'scratch-workspaces')) return { path: upto(i + 1), title: 'Claude scratch' }
92
+ // Antigravity: chats outside a project work in <data>/scratch, artifacts sit in <data>/brain/<id>.
93
+ if ((same(at, 'scratch') || same(at, 'brain')) && /^antigravity/i.test(parts[i - 1] ?? '') && same(parts[i - 2] ?? '', '.gemini')) return { path: upto(i + 1), title: 'Antigravity scratch' }
89
94
  if (same(at, 'Codex') && same(parts[i - 1], 'Documents') && DAY.test(parts[i + 1] ?? '')) return { path: upto(i + 1), title: 'Codex chats' }
90
95
  }
96
+ // Claude Code's per-conversation scratchpad: <tmp>/claude[-<uid>]/<project>/<session>/scratchpad;
97
+ // every conversation's goes to the claude[-<uid>] folder (2026-11-20: a paper review gave each
98
+ // reviewer its own scratchpad subfolder, five workspaces).
99
+ for (let s = parts.length - 1; s >= 3; s--) {
100
+ if (same(parts[s], 'scratchpad') && /^claude(-\d+)?$/i.test(parts[s - 3])) return { path: upto(s - 2), title: 'Claude scratch' }
101
+ }
91
102
  return null
92
103
  }
93
104
  // A Git worktree (its .git is a file pointing into another repository's worktrees): a checkout
@@ -98,16 +109,29 @@ function isLinkedWorktree(dir) {
98
109
  return text.startsWith('gitdir:') && /[\\/]worktrees[\\/]/.test(text)
99
110
  } catch { return false }
100
111
  }
101
- function sessionHome(target, base) {
112
+ // known: the folders that are workspaces already.
113
+ function sessionHome(target, base, known = []) {
102
114
  const usable = (dir) => dir && !same(dir, os.homedir()) && dir !== path.parse(dir).root && isDirectory(dir)
103
- if (base && !isLinkedWorktree(target)) {
104
- let b = normalizePath(base)
105
- const shared = sharedFolder(b)
106
- if (shared && isDirectory(shared.path)) b = shared.path
107
- if (usable(b) && isInside(target, b)) return { path: b, ...(shared && same(b, shared.path) && shared.title ? { title: shared.title } : {}) }
115
+ const linked = isLinkedWorktree(target)
116
+ let b
117
+ let baseShared = null
118
+ if (base && !linked) {
119
+ b = normalizePath(base)
120
+ baseShared = sharedFolder(b)
121
+ if (baseShared && isDirectory(baseShared.path)) b = baseShared.path
122
+ if (usable(b) && isInside(target, b)) return { path: b, ...(baseShared && same(b, baseShared.path) && baseShared.title ? { title: baseShared.title } : {}) }
108
123
  }
109
124
  const shared = sharedFolder(target)
110
125
  if (shared && usable(shared.path)) return shared
126
+ if (b) {
127
+ // A folder outside the conversation's folder (2026-11-20: a chat in Coding gave each reviewer
128
+ // a folder of its own on another disk, one workspace each): the nearest workspace around it,
129
+ // else the conversation's own folder. Not a chat's throw-away folder (a Codex chat without
130
+ // a project): a project handed over from there keeps a workspace of its own.
131
+ const around = known.filter((dir) => dir && usable(dir) && isInside(target, dir)).sort((x, y) => y.length - x.length)[0]
132
+ if (around) return { path: around }
133
+ if (b && !baseShared && usable(b)) return { path: b }
134
+ }
111
135
  return { path: target }
112
136
  }
113
137
 
@@ -1600,17 +1624,58 @@ export function apply(ctx) {
1600
1624
  const TEAMS_UNSUPPORTED = 'this DeepSeek Harness cannot turn Agent Teams on per session; that needs Harness 0.2.2-rc.2 or later: update Harness, or send without team'
1601
1625
  async function setTeam(sessionId, enabled) {
1602
1626
  if (typeof teamsService?.setEnabled !== 'function') throw new Error(TEAMS_UNSUPPORTED)
1603
- // The exact live Agent from Harness's registry, as its own UI lookup takes it: Team rejects
1604
- // any other object ("subagent tree access requires the exact live caller"). A session not
1605
- // loaded yet is loaded first.
1627
+ const agent = await liveAgent(sessionId)
1628
+ // A finished sub-agent's session is never loaded again: name the likely cause.
1629
+ if (!agent) throw new Error(`session ${sessionId} is not loaded in Harness; if it is a sub-agent's (teammate's) session, change Team mode on its root session instead`)
1630
+ await teamsService.setEnabled(agent, enabled)
1631
+ }
1632
+
1633
+ // The exact live Agent from Harness's registry, as its own UI lookup takes it: Team and goals
1634
+ // reject any other object ("subagent tree access requires the exact live caller"). A session
1635
+ // not loaded yet is loaded first. undefined when it cannot be loaded.
1636
+ async function liveAgent(sessionId) {
1606
1637
  let agent = agentsService?.get?.(sessionId)
1607
1638
  if (!agent && typeof controller.resolveAgent === 'function') {
1608
1639
  await controller.resolveAgent(sessionId)
1609
1640
  agent = agentsService?.get?.(sessionId)
1610
1641
  }
1611
- // A finished sub-agent's session is never loaded again: name the likely cause.
1612
- if (!agent) throw new Error(`session ${sessionId} is not loaded in Harness; if it is a sub-agent's (teammate's) session, change Team mode on its root session instead`)
1613
- await teamsService.setEnabled(agent, enabled)
1642
+ return agent
1643
+ }
1644
+
1645
+ // --- /goal ------------------------------------------------------------------------
1646
+ // Harness runs /goal as a composer command (commands.execute), not as text for the model:
1647
+ // sent as a prompt it set no goal (Windows rc.2 on 11-17, Mac rc.5 on 11-21). So a leading
1648
+ // "/goal <objective>" sets the goal through Harness's goals service, as the command does, and
1649
+ // the objective goes in as the run's message. The goal is set once Harness has taken that
1650
+ // message in, so its round driver sees a queued prompt and waits: the run's own turn comes
1651
+ // first, then Harness goes on with the goal's rounds by itself.
1652
+ const GOAL_UNSUPPORTED = 'this DeepSeek Harness cannot set a goal from a plugin (no goals service); type /goal in the Harness window, or update Harness'
1653
+ function goalCommand(message) {
1654
+ const m = /^\/goal(?:\s+([^]*))?$/i.exec(message.trim())
1655
+ if (!m) return null
1656
+ const rest = (m[1] ?? '').trim()
1657
+ const word = rest.toLowerCase()
1658
+ if (!rest || ['clear', 'pause', 'resume', 'edit'].includes(word)) return { kind: 'control', word: word || 'show' }
1659
+ if (/^edit\s/i.test(rest)) return { kind: 'edit', objective: rest.slice(4).trim() }
1660
+ return { kind: 'create', objective: rest }
1661
+ }
1662
+ const GOAL_NOTE = '(This message also set a Harness goal for this session, with the text above as its objective. When all of it is done and verified, mark the goal complete; if work remains, leave it active and Harness starts the next goal round after this turn.)'
1663
+
1664
+ async function setGoal(run, cmd, objective) {
1665
+ try {
1666
+ const agent = await liveAgent(run.sessionId)
1667
+ if (!agent) throw new Error(`session ${run.sessionId} is not loaded in Harness`)
1668
+ const current = goalsService.get(agent)
1669
+ const view = cmd.kind === 'edit' && current && current.phase !== 'complete'
1670
+ ? goalsService.edit(agent, { id: current.id, revision: current.revision }, { objective })
1671
+ : goalsService.create(agent, { objective })
1672
+ run.goalSet = { id: view.id, phase: view.phase, max_rounds: view.maxGoalRounds ?? null }
1673
+ pushEvent(run, { type: 'goal_set', goal_id: view.id, edited: cmd.kind === 'edit' && view.revision > 1 })
1674
+ } catch (error) {
1675
+ run.goalError = String(error?.message ?? error)
1676
+ pushEvent(run, { type: 'goal_failed', error: run.goalError })
1677
+ logError('set goal', error)
1678
+ }
1614
1679
  }
1615
1680
 
1616
1681
  async function send({ message, session_id, cwd, workspace_id, conversation_folder, mode: asked, sender, model, reasoning_effort, team }) {
@@ -1632,6 +1697,14 @@ export function apply(ctx) {
1632
1697
  throw new Error(`Session ${sessionId} is archived. Unarchive it in Harness, or start a new session with cwd or workspace_id.`)
1633
1698
  }
1634
1699
  if (!sessionId && !cwd && !workspace_id) throw new Error('A new session needs cwd or workspace_id. Pass session_id to continue an existing one.')
1700
+ const goalCmd = goalCommand(message)
1701
+ if (goalCmd?.kind === 'control') throw new Error(`Nothing was sent: dsh_send takes "/goal <objective>" or "/goal edit <objective>"; /goal ${goalCmd.word === 'show' ? '' : goalCmd.word} works only in the Harness window. dsh_status with session_id shows a session's goal.`)
1702
+ if (goalCmd && (typeof goalsService?.create !== 'function' || typeof agentsService?.get !== 'function')) throw new Error(`Nothing was sent: ${GOAL_UNSUPPORTED}`)
1703
+ if (goalCmd?.kind === 'create' && sessionId) {
1704
+ const current = await goalOf(sessionId)
1705
+ if (current && current.phase !== 'complete') throw new Error(`No message was sent: session ${sessionId} already has a goal (${current.phase}: ${current.objective}). Send "/goal edit <objective>" to replace its objective, or clear it in the Harness window first.`)
1706
+ }
1707
+ if (goalCmd) message = goalCmd.objective
1635
1708
  // A missing folder is not created: a mistyped path, or a project on a drive that is not
1636
1709
  // connected, would get an empty folder (under /Volumes, even). Checked before the registry,
1637
1710
  // which answers a bare ENOENT, or nothing at all for a folder registered while it was there.
@@ -1672,7 +1745,7 @@ export function apply(ctx) {
1672
1745
  const target = normalizePath(cwd)
1673
1746
  // A folder that is a workspace already (sessions from before 0.6.15) keeps it.
1674
1747
  const own = await registry.resolveByPath(target).catch(() => undefined)
1675
- const home = own ? { path: target } : sessionHome(target, conversation_folder)
1748
+ const home = own ? { path: target } : sessionHome(target, conversation_folder, registry.list().map((w) => w.path))
1676
1749
  workspace = await createWorkspace({ path: home.path, title: home.title, create_dir: false })
1677
1750
  if (!same(home.path, target)) {
1678
1751
  workFolder = target
@@ -1740,9 +1813,10 @@ export function apply(ctx) {
1740
1813
  // session after a restart) that took 2 min 35 s, and the client sat in dsh_send all along
1741
1814
  // (Mac, 2026-11-18). So the reply waits at most admitWaitMs() (10 s); Harness's answer still settles
1742
1815
  // the run when it comes (a refusal fails it, and dsh_wait says so).
1743
- const admitted = controller.prompt({ sessionId, requestId: run.requestId, content: [{ type: 'text', text: message }], mode }, signal())
1744
- .then(() => {
1816
+ const admitted = controller.prompt({ sessionId, requestId: run.requestId, content: [{ type: 'text', text: goalCmd ? `${message}\n\n${GOAL_NOTE}` : message }], mode }, signal())
1817
+ .then(async () => {
1745
1818
  run.admitted = true // in Harness's queue (or conversation) now
1819
+ if (goalCmd) await setGoal(run, goalCmd, message)
1746
1820
  if (drift) rememberDefault(drift.now)
1747
1821
  return true
1748
1822
  }, (error) => {
@@ -1763,6 +1837,7 @@ export function apply(ctx) {
1763
1837
  ...(pagePart.length ? { handover_default: pagePart } : {}),
1764
1838
  ...(modelNotes.length ? { model_note: modelNotes.join(' ') } : {}),
1765
1839
  ...(team != null ? { team } : {}),
1840
+ ...(goalCmd && answered ? (run.goalSet ? { goal_set: run.goalSet } : { goal_error: run.goalError ?? 'not set' }) : {}),
1766
1841
  ...(ahead.length ? { other_active_runs: ahead } : {}),
1767
1842
  ...(queuedBehind ? { queued_behind: true } : {}),
1768
1843
  ...(workspace ? { workspace } : {}),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-baton-host",
3
- "version": "0.6.16",
3
+ "version": "0.6.18",
4
4
  "description": "Hand coding tasks from Claude Code, Codex or Antigravity to DeepSeek Harness: they run live in the Harness window and come back with the changed files and test results. 让 Claude Code、Codex 和 Antigravity 把编码任务交给 DeepSeek Harness:在 Harness 窗口里实时跑,做完带着改动文件和测试结果交回。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -24,7 +24,7 @@
24
24
  "docs"
25
25
  ],
26
26
  "dependencies": {
27
- "dsh-baton-mcp": "0.6.16"
27
+ "dsh-baton-mcp": "0.6.18"
28
28
  },
29
29
  "license": "MIT",
30
30
  "dsh": {