dsh-baton-host 0.6.17 → 0.6.19
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/index.js +133 -20
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -28,6 +28,10 @@ const ACTIVITY_MAX_ERRORS = 10
|
|
|
28
28
|
// A run taken up after a plugin reload whose message Harness had not admitted yet.
|
|
29
29
|
const TAKE_UP_RETRY_MS = 3000
|
|
30
30
|
const takeUpAdmitMs = () => Number(process.env.DSH_BATON_TAKE_UP_ADMIT_MS) || 5 * 60_000
|
|
31
|
+
// How long a run whose own turn ended waits for background jobs or reminders (not sub-agents,
|
|
32
|
+
// which are part of the task) before it completes anyway, saying what is left (left_running).
|
|
33
|
+
// A search over the whole home folder held a reply back for 15 minutes (Mac, 2026-11-22).
|
|
34
|
+
const jobWaitMs = () => Number(process.env.DSH_BATON_JOB_WAIT_MS) || 5 * 60_000
|
|
31
35
|
const MAX_REQUEST_BYTES = 4 * 1024 * 1024
|
|
32
36
|
const MAX_WAIT_S = 24 * 3600
|
|
33
37
|
const MAX_HUMAN_INPUTS = 10
|
|
@@ -65,8 +69,11 @@ function normalizePath(p) {
|
|
|
65
69
|
// one more in the sidebar for each subfolder or throw-away folder. Instead it joins:
|
|
66
70
|
// - the conversation's own folder (base), when the target is inside it: a Claude Code chat in
|
|
67
71
|
// Coding handing over Coding/app joins the Coding workspace;
|
|
72
|
+
// - for a target outside it, the nearest workspace around the target, else the conversation's
|
|
73
|
+
// own folder: a chat in Coding handing over a folder on another disk joins the Coding workspace;
|
|
68
74
|
// - for folders clients make per conversation, one shared folder: Codex chats without a project
|
|
69
|
-
// (Documents/Codex/<date>/<chat>), Claude scratch folders (…/scratch-workspaces
|
|
75
|
+
// (Documents/Codex/<date>/<chat>), Claude scratch folders (…/scratch-workspaces/…, Claude
|
|
76
|
+
// Code's <tmp>/claude-<uid>/…/scratchpad), Antigravity's scratch and brain folders, Claude
|
|
70
77
|
// worktrees (<project>/.claude/worktrees/<name>, joined to the project) and Codex worktrees
|
|
71
78
|
// (~/.codex/worktrees/…).
|
|
72
79
|
// The session then starts in that folder and the message names the target folder.
|
|
@@ -86,8 +93,16 @@ function sharedFolder(dir) {
|
|
|
86
93
|
if (same(at, 'worktrees') && i >= 2 && same(parts[i - 1], '.claude')) return { path: upto(i + 1), title: 'Claude worktrees' }
|
|
87
94
|
if (same(at, 'worktrees') && same(parts[i - 1], '.codex')) return { path: upto(i + 1), title: 'Codex worktrees' }
|
|
88
95
|
if (same(at, 'scratch-workspaces')) return { path: upto(i + 1), title: 'Claude scratch' }
|
|
96
|
+
// Antigravity: chats outside a project work in <data>/scratch, artifacts sit in <data>/brain/<id>.
|
|
97
|
+
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
98
|
if (same(at, 'Codex') && same(parts[i - 1], 'Documents') && DAY.test(parts[i + 1] ?? '')) return { path: upto(i + 1), title: 'Codex chats' }
|
|
90
99
|
}
|
|
100
|
+
// Claude Code's per-conversation scratchpad: <tmp>/claude[-<uid>]/<project>/<session>/scratchpad;
|
|
101
|
+
// every conversation's goes to the claude[-<uid>] folder (2026-11-20: a paper review gave each
|
|
102
|
+
// reviewer its own scratchpad subfolder, five workspaces).
|
|
103
|
+
for (let s = parts.length - 1; s >= 3; s--) {
|
|
104
|
+
if (same(parts[s], 'scratchpad') && /^claude(-\d+)?$/i.test(parts[s - 3])) return { path: upto(s - 2), title: 'Claude scratch' }
|
|
105
|
+
}
|
|
91
106
|
return null
|
|
92
107
|
}
|
|
93
108
|
// A Git worktree (its .git is a file pointing into another repository's worktrees): a checkout
|
|
@@ -98,16 +113,29 @@ function isLinkedWorktree(dir) {
|
|
|
98
113
|
return text.startsWith('gitdir:') && /[\\/]worktrees[\\/]/.test(text)
|
|
99
114
|
} catch { return false }
|
|
100
115
|
}
|
|
101
|
-
|
|
116
|
+
// known: the folders that are workspaces already.
|
|
117
|
+
function sessionHome(target, base, known = []) {
|
|
102
118
|
const usable = (dir) => dir && !same(dir, os.homedir()) && dir !== path.parse(dir).root && isDirectory(dir)
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
119
|
+
const linked = isLinkedWorktree(target)
|
|
120
|
+
let b
|
|
121
|
+
let baseShared = null
|
|
122
|
+
if (base && !linked) {
|
|
123
|
+
b = normalizePath(base)
|
|
124
|
+
baseShared = sharedFolder(b)
|
|
125
|
+
if (baseShared && isDirectory(baseShared.path)) b = baseShared.path
|
|
126
|
+
if (usable(b) && isInside(target, b)) return { path: b, ...(baseShared && same(b, baseShared.path) && baseShared.title ? { title: baseShared.title } : {}) }
|
|
108
127
|
}
|
|
109
128
|
const shared = sharedFolder(target)
|
|
110
129
|
if (shared && usable(shared.path)) return shared
|
|
130
|
+
if (b) {
|
|
131
|
+
// A folder outside the conversation's folder (2026-11-20: a chat in Coding gave each reviewer
|
|
132
|
+
// a folder of its own on another disk, one workspace each): the nearest workspace around it,
|
|
133
|
+
// else the conversation's own folder. Not a chat's throw-away folder (a Codex chat without
|
|
134
|
+
// a project): a project handed over from there keeps a workspace of its own.
|
|
135
|
+
const around = known.filter((dir) => dir && usable(dir) && isInside(target, dir)).sort((x, y) => y.length - x.length)[0]
|
|
136
|
+
if (around) return { path: around }
|
|
137
|
+
if (b && !baseShared && usable(b)) return { path: b }
|
|
138
|
+
}
|
|
111
139
|
return { path: target }
|
|
112
140
|
}
|
|
113
141
|
|
|
@@ -233,6 +261,7 @@ export function apply(ctx) {
|
|
|
233
261
|
...(run.sender ? { sender: run.sender } : {}),
|
|
234
262
|
...(run.model ? { model: run.model } : {}),
|
|
235
263
|
...(run.waitingOn ? { waiting_on: run.waitingOn } : {}),
|
|
264
|
+
...(run.leftRunning ? { left_running: run.leftRunning } : {}),
|
|
236
265
|
...(run.supersededBy ? { superseded_by: run.supersededBy } : {}),
|
|
237
266
|
...(run.humanInputs?.length ? { human_interjections: run.humanInputs } : {}),
|
|
238
267
|
...(run.approvalsAllowed?.length ? { approvals_allowed: run.approvalsAllowed } : {}),
|
|
@@ -523,7 +552,12 @@ export function apply(ctx) {
|
|
|
523
552
|
// completed one ends it only once the session is quiet (no sub-agents or jobs
|
|
524
553
|
// left), because Harness wakes the agent again when those report back.
|
|
525
554
|
const reason = data.reason ?? null
|
|
526
|
-
for (const run of receivers) {
|
|
555
|
+
for (const run of receivers) {
|
|
556
|
+
// The reply of the run's own turn, kept apart from what later wake-up turns say.
|
|
557
|
+
if (!run.turnEnd && (!reason?.kind || reason.kind === 'completed')) run.turnText = run.finalText ?? null
|
|
558
|
+
run.turnEnd = reason
|
|
559
|
+
persist(run)
|
|
560
|
+
}
|
|
527
561
|
if (reason?.kind && reason.kind !== 'completed') for (const run of receivers) settle(run, 'failed')
|
|
528
562
|
else scheduleQuietCheck(session.id, 1000)
|
|
529
563
|
turns.delete(session.id)
|
|
@@ -573,8 +607,16 @@ export function apply(ctx) {
|
|
|
573
607
|
// Closed runs: the running turn belongs to a newer run, so only their
|
|
574
608
|
// background work (sub-agents, jobs, reminders) keeps them open.
|
|
575
609
|
const background = items.filter((g) => g.kind !== 'turn')
|
|
610
|
+
// Only jobs or reminders left, past the limit since the run's own turn ended: done anyway.
|
|
611
|
+
const outlasted = (run) => {
|
|
612
|
+
if (!background.length || items.some((g) => g.kind === 'turn' || g.kind === 'subagent')) { delete run.jobsSince; return false }
|
|
613
|
+
run.jobsSince ??= Date.now()
|
|
614
|
+
return Date.now() - run.jobsSince >= jobWaitMs()
|
|
615
|
+
}
|
|
576
616
|
for (const run of receivers.filter((r) => r.outputClosed)) {
|
|
577
|
-
|
|
617
|
+
noteWaited(run, background)
|
|
618
|
+
if (background.length === 0) finishQuiet(run)
|
|
619
|
+
else if (outlasted(run)) finishQuiet(run, { leftRunning: summary(background) })
|
|
578
620
|
else { run.waitingOn = summary(background); persist(run) }
|
|
579
621
|
}
|
|
580
622
|
// A run whose own turn has not ended (and that has not seen the agent idle) is not done yet.
|
|
@@ -591,14 +633,34 @@ export function apply(ctx) {
|
|
|
591
633
|
return
|
|
592
634
|
}
|
|
593
635
|
quietSinceBySession.delete(sessionId)
|
|
594
|
-
for (const run of open)
|
|
636
|
+
for (const run of open) finishQuiet(run)
|
|
595
637
|
return
|
|
596
638
|
}
|
|
597
639
|
quietSinceBySession.delete(sessionId)
|
|
598
|
-
for (const run of open) run
|
|
640
|
+
for (const run of open) noteWaited(run, items)
|
|
641
|
+
const late = open.filter((r) => r.turnEnd && outlasted(r))
|
|
642
|
+
for (const run of late) finishQuiet(run, { leftRunning: summary(background) })
|
|
643
|
+
for (const run of open.filter((r) => !late.includes(r))) run.waitingOn = items.length ? summary(items) : run.waitingOn
|
|
599
644
|
if (receiversFor(sessionId).length) scheduleQuietCheck(sessionId, 3000)
|
|
600
645
|
}
|
|
601
646
|
|
|
647
|
+
// The kinds of background work a run has waited for, to tell what its later turns are about.
|
|
648
|
+
function noteWaited(run, list) {
|
|
649
|
+
const kinds = list.map((g) => g.kind).filter((k) => k !== 'turn' && !(run.waitedKinds ?? []).includes(k))
|
|
650
|
+
if (kinds.length) run.waitedKinds = [...(run.waitedKinds ?? []), ...kinds]
|
|
651
|
+
}
|
|
652
|
+
// A run that waited for sub-agents ends with their summary turn as its reply. One that waited
|
|
653
|
+
// only for jobs or reminders keeps its own turn's reply, with what the later turns said after it:
|
|
654
|
+
// a turn woken by a job is about that job, and replacing the reply with it lost a whole
|
|
655
|
+
// review (Antigravity, 2026-11-22).
|
|
656
|
+
function finishQuiet(run, extra = {}) {
|
|
657
|
+
const reply = run.turnText
|
|
658
|
+
const later = run.finalText
|
|
659
|
+
const kinds = run.waitedKinds ?? []
|
|
660
|
+
const keep = reply && later && later !== reply && kinds.length && !kinds.includes('subagent')
|
|
661
|
+
settle(run, 'completed', { waitingOn: null, error: null, ...(keep ? { finalText: `${reply}\n\n${later}` } : {}), ...extra })
|
|
662
|
+
}
|
|
663
|
+
|
|
602
664
|
ctx.effect(() => () => { for (const t of quietTimers.values()) clearTimeout(t) }, 'dsh-baton-host quiet timers')
|
|
603
665
|
|
|
604
666
|
ctx.on('agent/status', guard('agent/status', ({ agent, status }) => {
|
|
@@ -1600,17 +1662,58 @@ export function apply(ctx) {
|
|
|
1600
1662
|
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
1663
|
async function setTeam(sessionId, enabled) {
|
|
1602
1664
|
if (typeof teamsService?.setEnabled !== 'function') throw new Error(TEAMS_UNSUPPORTED)
|
|
1603
|
-
|
|
1604
|
-
//
|
|
1605
|
-
|
|
1665
|
+
const agent = await liveAgent(sessionId)
|
|
1666
|
+
// A finished sub-agent's session is never loaded again: name the likely cause.
|
|
1667
|
+
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`)
|
|
1668
|
+
await teamsService.setEnabled(agent, enabled)
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
// The exact live Agent from Harness's registry, as its own UI lookup takes it: Team and goals
|
|
1672
|
+
// reject any other object ("subagent tree access requires the exact live caller"). A session
|
|
1673
|
+
// not loaded yet is loaded first. undefined when it cannot be loaded.
|
|
1674
|
+
async function liveAgent(sessionId) {
|
|
1606
1675
|
let agent = agentsService?.get?.(sessionId)
|
|
1607
1676
|
if (!agent && typeof controller.resolveAgent === 'function') {
|
|
1608
1677
|
await controller.resolveAgent(sessionId)
|
|
1609
1678
|
agent = agentsService?.get?.(sessionId)
|
|
1610
1679
|
}
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1680
|
+
return agent
|
|
1681
|
+
}
|
|
1682
|
+
|
|
1683
|
+
// --- /goal ------------------------------------------------------------------------
|
|
1684
|
+
// Harness runs /goal as a composer command (commands.execute), not as text for the model:
|
|
1685
|
+
// sent as a prompt it set no goal (Windows rc.2 on 11-17, Mac rc.5 on 11-21). So a leading
|
|
1686
|
+
// "/goal <objective>" sets the goal through Harness's goals service, as the command does, and
|
|
1687
|
+
// the objective goes in as the run's message. The goal is set once Harness has taken that
|
|
1688
|
+
// message in, so its round driver sees a queued prompt and waits: the run's own turn comes
|
|
1689
|
+
// first, then Harness goes on with the goal's rounds by itself.
|
|
1690
|
+
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'
|
|
1691
|
+
function goalCommand(message) {
|
|
1692
|
+
const m = /^\/goal(?:\s+([^]*))?$/i.exec(message.trim())
|
|
1693
|
+
if (!m) return null
|
|
1694
|
+
const rest = (m[1] ?? '').trim()
|
|
1695
|
+
const word = rest.toLowerCase()
|
|
1696
|
+
if (!rest || ['clear', 'pause', 'resume', 'edit'].includes(word)) return { kind: 'control', word: word || 'show' }
|
|
1697
|
+
if (/^edit\s/i.test(rest)) return { kind: 'edit', objective: rest.slice(4).trim() }
|
|
1698
|
+
return { kind: 'create', objective: rest }
|
|
1699
|
+
}
|
|
1700
|
+
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.)'
|
|
1701
|
+
|
|
1702
|
+
async function setGoal(run, cmd, objective) {
|
|
1703
|
+
try {
|
|
1704
|
+
const agent = await liveAgent(run.sessionId)
|
|
1705
|
+
if (!agent) throw new Error(`session ${run.sessionId} is not loaded in Harness`)
|
|
1706
|
+
const current = goalsService.get(agent)
|
|
1707
|
+
const view = cmd.kind === 'edit' && current && current.phase !== 'complete'
|
|
1708
|
+
? goalsService.edit(agent, { id: current.id, revision: current.revision }, { objective })
|
|
1709
|
+
: goalsService.create(agent, { objective })
|
|
1710
|
+
run.goalSet = { id: view.id, phase: view.phase, max_rounds: view.maxGoalRounds ?? null }
|
|
1711
|
+
pushEvent(run, { type: 'goal_set', goal_id: view.id, edited: cmd.kind === 'edit' && view.revision > 1 })
|
|
1712
|
+
} catch (error) {
|
|
1713
|
+
run.goalError = String(error?.message ?? error)
|
|
1714
|
+
pushEvent(run, { type: 'goal_failed', error: run.goalError })
|
|
1715
|
+
logError('set goal', error)
|
|
1716
|
+
}
|
|
1614
1717
|
}
|
|
1615
1718
|
|
|
1616
1719
|
async function send({ message, session_id, cwd, workspace_id, conversation_folder, mode: asked, sender, model, reasoning_effort, team }) {
|
|
@@ -1632,6 +1735,14 @@ export function apply(ctx) {
|
|
|
1632
1735
|
throw new Error(`Session ${sessionId} is archived. Unarchive it in Harness, or start a new session with cwd or workspace_id.`)
|
|
1633
1736
|
}
|
|
1634
1737
|
if (!sessionId && !cwd && !workspace_id) throw new Error('A new session needs cwd or workspace_id. Pass session_id to continue an existing one.')
|
|
1738
|
+
const goalCmd = goalCommand(message)
|
|
1739
|
+
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.`)
|
|
1740
|
+
if (goalCmd && (typeof goalsService?.create !== 'function' || typeof agentsService?.get !== 'function')) throw new Error(`Nothing was sent: ${GOAL_UNSUPPORTED}`)
|
|
1741
|
+
if (goalCmd?.kind === 'create' && sessionId) {
|
|
1742
|
+
const current = await goalOf(sessionId)
|
|
1743
|
+
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.`)
|
|
1744
|
+
}
|
|
1745
|
+
if (goalCmd) message = goalCmd.objective
|
|
1635
1746
|
// A missing folder is not created: a mistyped path, or a project on a drive that is not
|
|
1636
1747
|
// connected, would get an empty folder (under /Volumes, even). Checked before the registry,
|
|
1637
1748
|
// which answers a bare ENOENT, or nothing at all for a folder registered while it was there.
|
|
@@ -1672,7 +1783,7 @@ export function apply(ctx) {
|
|
|
1672
1783
|
const target = normalizePath(cwd)
|
|
1673
1784
|
// A folder that is a workspace already (sessions from before 0.6.15) keeps it.
|
|
1674
1785
|
const own = await registry.resolveByPath(target).catch(() => undefined)
|
|
1675
|
-
const home = own ? { path: target } : sessionHome(target, conversation_folder)
|
|
1786
|
+
const home = own ? { path: target } : sessionHome(target, conversation_folder, registry.list().map((w) => w.path))
|
|
1676
1787
|
workspace = await createWorkspace({ path: home.path, title: home.title, create_dir: false })
|
|
1677
1788
|
if (!same(home.path, target)) {
|
|
1678
1789
|
workFolder = target
|
|
@@ -1740,9 +1851,10 @@ export function apply(ctx) {
|
|
|
1740
1851
|
// session after a restart) that took 2 min 35 s, and the client sat in dsh_send all along
|
|
1741
1852
|
// (Mac, 2026-11-18). So the reply waits at most admitWaitMs() (10 s); Harness's answer still settles
|
|
1742
1853
|
// 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(() => {
|
|
1854
|
+
const admitted = controller.prompt({ sessionId, requestId: run.requestId, content: [{ type: 'text', text: goalCmd ? `${message}\n\n${GOAL_NOTE}` : message }], mode }, signal())
|
|
1855
|
+
.then(async () => {
|
|
1745
1856
|
run.admitted = true // in Harness's queue (or conversation) now
|
|
1857
|
+
if (goalCmd) await setGoal(run, goalCmd, message)
|
|
1746
1858
|
if (drift) rememberDefault(drift.now)
|
|
1747
1859
|
return true
|
|
1748
1860
|
}, (error) => {
|
|
@@ -1763,6 +1875,7 @@ export function apply(ctx) {
|
|
|
1763
1875
|
...(pagePart.length ? { handover_default: pagePart } : {}),
|
|
1764
1876
|
...(modelNotes.length ? { model_note: modelNotes.join(' ') } : {}),
|
|
1765
1877
|
...(team != null ? { team } : {}),
|
|
1878
|
+
...(goalCmd && answered ? (run.goalSet ? { goal_set: run.goalSet } : { goal_error: run.goalError ?? 'not set' }) : {}),
|
|
1766
1879
|
...(ahead.length ? { other_active_runs: ahead } : {}),
|
|
1767
1880
|
...(queuedBehind ? { queued_behind: true } : {}),
|
|
1768
1881
|
...(workspace ? { workspace } : {}),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-baton-host",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.19",
|
|
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.
|
|
27
|
+
"dsh-baton-mcp": "0.6.19"
|
|
28
28
|
},
|
|
29
29
|
"license": "MIT",
|
|
30
30
|
"dsh": {
|