dsh-baton-host 0.6.19 → 0.6.21
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 +96 -0
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -266,6 +266,7 @@ export function apply(ctx) {
|
|
|
266
266
|
...(run.humanInputs?.length ? { human_interjections: run.humanInputs } : {}),
|
|
267
267
|
...(run.approvalsAllowed?.length ? { approvals_allowed: run.approvalsAllowed } : {}),
|
|
268
268
|
...(run.question ? { question: run.question } : {}),
|
|
269
|
+
...(run.card ? { card: cardNow(run) } : {}),
|
|
269
270
|
...(tail ? { recent_events: run.events.slice(-tail) } : {}),
|
|
270
271
|
})
|
|
271
272
|
|
|
@@ -289,6 +290,7 @@ export function apply(ctx) {
|
|
|
289
290
|
function settle(run, state, extra = {}) {
|
|
290
291
|
if (!isActive(run)) return
|
|
291
292
|
Object.assign(run, extra, { state, endedAt: new Date().toISOString() })
|
|
293
|
+
if (state === 'completed' && !run.card) run.card = cardOfRun(run) ?? undefined
|
|
292
294
|
for (const resolve of waiters.get(run.id) ?? []) resolve()
|
|
293
295
|
waiters.delete(run.id)
|
|
294
296
|
persist(run)
|
|
@@ -1046,6 +1048,7 @@ export function apply(ctx) {
|
|
|
1046
1048
|
let goalsService = null
|
|
1047
1049
|
let agentsService = null
|
|
1048
1050
|
let teamsService = null
|
|
1051
|
+
let cardsService = null // Harness's actionCards (the Personalized recommendations experiment), when on
|
|
1049
1052
|
const activations = new Map() // sessionId -> 'armed' | 'disarmed', from goal/activation-changed
|
|
1050
1053
|
ctx.on('goal/activation-changed', guard('goal activation', ({ sessionId, goal } = {}) => {
|
|
1051
1054
|
if (!sessionId) return
|
|
@@ -1680,6 +1683,93 @@ export function apply(ctx) {
|
|
|
1680
1683
|
return agent
|
|
1681
1684
|
}
|
|
1682
1685
|
|
|
1686
|
+
// --- action cards ------------------------------------------------------------------
|
|
1687
|
+
// With Harness's Personalized recommendations experiment on, the model may end a turn with
|
|
1688
|
+
// one card below its answer (propose_action): a page to create, or a built-in plugin to
|
|
1689
|
+
// enable. Nothing runs until someone acts on it, and the Harness window is the only place
|
|
1690
|
+
// that shows it. A run reports the card its own turns offered (run.card), and card() acts on
|
|
1691
|
+
// it the way the card's buttons do. Harness shows no card in PTC mode.
|
|
1692
|
+
const CARD_KINDS = { create_personalized_page: 'personalized_page', enable_official_plugin: 'official_plugin' }
|
|
1693
|
+
// What can be done next, by kind and phase: the card's own buttons.
|
|
1694
|
+
const PAGE_RETRY = ['cancelled', 'failed', 'interrupted', 'unconfirmed']
|
|
1695
|
+
function cardChoices(action, phase) {
|
|
1696
|
+
if (action === 'create_personalized_page') {
|
|
1697
|
+
if (phase === 'offered' || PAGE_RETRY.includes(phase)) return ['create', 'not_now']
|
|
1698
|
+
if (phase === 'creating') return ['cancel']
|
|
1699
|
+
if (phase === 'installed') return ['undo']
|
|
1700
|
+
if (phase === 'removed') return ['restore']
|
|
1701
|
+
return []
|
|
1702
|
+
}
|
|
1703
|
+
if (action === 'enable_official_plugin') return phase === 'offered' || phase === 'failed' || phase === 'unconfirmed' ? ['enable', 'not_now'] : []
|
|
1704
|
+
return phase === 'offered' ? ['not_now'] : []
|
|
1705
|
+
}
|
|
1706
|
+
// The open session's cards, or null when this Harness has no cards or the session is not loaded.
|
|
1707
|
+
function cardView(sessionId) {
|
|
1708
|
+
try {
|
|
1709
|
+
const session = agentsService?.get?.(sessionId)?.session
|
|
1710
|
+
return session && typeof cardsService?.view === 'function' ? cardsService.view(session) : null
|
|
1711
|
+
} catch { return null }
|
|
1712
|
+
}
|
|
1713
|
+
const cardIds = (sessionId) => Object.keys(cardView(sessionId)?.proposals ?? {})
|
|
1714
|
+
function publicCard(view, callId) {
|
|
1715
|
+
const p = view?.proposals?.[callId]
|
|
1716
|
+
if (!p) return null
|
|
1717
|
+
const decision = view.decisions?.[callId]
|
|
1718
|
+
// A newer card replaces an unstarted one (Harness derives this; it is never recorded).
|
|
1719
|
+
const newer = Object.values(view.proposals).some((o) => o.turn > p.turn)
|
|
1720
|
+
const phase = decision?.phase ?? (newer ? 'replaced' : 'offered')
|
|
1721
|
+
return {
|
|
1722
|
+
call_id: callId, kind: CARD_KINDS[p.action] ?? p.action, title: p.title, brief: p.brief, details: p.details,
|
|
1723
|
+
state: phase, ...(decision?.data ? { data: decision.data } : {}), choices: cardChoices(p.action, phase),
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
// The newest card this run's turns offered, read when the run ends.
|
|
1727
|
+
function cardOfRun(run) {
|
|
1728
|
+
const view = cardView(run.sessionId)
|
|
1729
|
+
if (!view) return null
|
|
1730
|
+
const before = new Set(run.cardsBefore ?? [])
|
|
1731
|
+
const mine = Object.values(view.proposals).filter((p) => !before.has(p.callId)).sort((a, b) => b.turn - a.turn)[0]
|
|
1732
|
+
return mine ? publicCard(view, mine.callId) : null
|
|
1733
|
+
}
|
|
1734
|
+
// A run's card as it stands now (the user may have clicked it in Harness meanwhile).
|
|
1735
|
+
const cardNow = (run) => (run.card ? publicCard(cardView(run.sessionId), run.card.call_id) ?? run.card : null)
|
|
1736
|
+
|
|
1737
|
+
const CARD_VERBS = { create: 'create', enable: 'enable', not_now: 'dismiss', cancel: 'cancel', undo: 'undo', restore: 'restore' }
|
|
1738
|
+
const CARD_REFUSALS = {
|
|
1739
|
+
'not-live-root': 'the session is not open in Harness right now',
|
|
1740
|
+
unknown: 'Harness has no such card in this session',
|
|
1741
|
+
unavailable: 'the card cannot do that now (its feature may be switched off, or it was replaced or dismissed)',
|
|
1742
|
+
'access-denied': 'Harness refused the profile change',
|
|
1743
|
+
'read-only': 'the session is read-only',
|
|
1744
|
+
'invalid-location': 'the location is not one of sidebar-left, sidebar-right or page',
|
|
1745
|
+
closing: 'Harness is closing',
|
|
1746
|
+
}
|
|
1747
|
+
// choice: create | enable | not_now | cancel | undo | restore. slot / custom_location only for create.
|
|
1748
|
+
async function actOnCard({ run_id, session_id, call_id, choice, slot, custom_location } = {}) {
|
|
1749
|
+
const run = run_id ? getRun(run_id) : null
|
|
1750
|
+
const sessionId = run?.sessionId ?? session_id
|
|
1751
|
+
if (!sessionId) throw new Error('Give run_id (or session_id) of the run whose card to act on.')
|
|
1752
|
+
if (typeof cardsService?.act !== 'function') throw new Error('This Harness shows no action cards: the Personalized recommendations plugin is off.')
|
|
1753
|
+
const verb = CARD_VERBS[choice]
|
|
1754
|
+
if (!verb) throw new Error(`choice must be one of ${Object.keys(CARD_VERBS).join(', ')}`)
|
|
1755
|
+
const agent = await liveAgent(sessionId)
|
|
1756
|
+
if (!agent) throw new Error(`Session ${sessionId} cannot be opened in Harness right now.`)
|
|
1757
|
+
const view = cardsService.view(agent.session)
|
|
1758
|
+
const id = call_id ?? run?.card?.call_id ?? Object.values(view.proposals).sort((a, b) => b.turn - a.turn)[0]?.callId
|
|
1759
|
+
const proposal = id ? view.proposals[id] : null
|
|
1760
|
+
if (!proposal) throw new Error(`Session ${sessionId} has no card${call_id ? ` ${call_id}` : ''}.`)
|
|
1761
|
+
const payload = verb === 'create'
|
|
1762
|
+
? { slot: slot ?? proposal.details?.slot, ...(custom_location ? { customLocation: custom_location } : {}) }
|
|
1763
|
+
: verb === 'dismiss' && slot ? { slot } : undefined
|
|
1764
|
+
const result = await cardsService.act(agent, id, verb, payload)
|
|
1765
|
+
const card = publicCard(cardsService.view(agent.session), id)
|
|
1766
|
+
if (run?.card?.call_id === id && card) { run.card = card; persist(run) }
|
|
1767
|
+
return {
|
|
1768
|
+
session_id: sessionId, ...(run ? { run_id: run.id } : {}), status: result?.status ?? 'unknown',
|
|
1769
|
+
...(result?.reason ? { reason: CARD_REFUSALS[result.reason] ?? result.reason } : {}), card,
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1772
|
+
|
|
1683
1773
|
// --- /goal ------------------------------------------------------------------------
|
|
1684
1774
|
// Harness runs /goal as a composer command (commands.execute), not as text for the model:
|
|
1685
1775
|
// sent as a prompt it set no goal (Windows rc.2 on 11-17, Mac rc.5 on 11-21). So a leading
|
|
@@ -1854,6 +1944,7 @@ export function apply(ctx) {
|
|
|
1854
1944
|
const admitted = controller.prompt({ sessionId, requestId: run.requestId, content: [{ type: 'text', text: goalCmd ? `${message}\n\n${GOAL_NOTE}` : message }], mode }, signal())
|
|
1855
1945
|
.then(async () => {
|
|
1856
1946
|
run.admitted = true // in Harness's queue (or conversation) now
|
|
1947
|
+
run.cardsBefore = cardIds(sessionId) // a card offered later is this run's
|
|
1857
1948
|
if (goalCmd) await setGoal(run, goalCmd, message)
|
|
1858
1949
|
if (drift) rememberDefault(drift.now)
|
|
1859
1950
|
return true
|
|
@@ -2025,6 +2116,7 @@ export function apply(ctx) {
|
|
|
2025
2116
|
list_runs: ({ limit = 10, session_id } = {}) => [...runs.values()].reverse().filter((r) => !session_id || r.sessionId === session_id).slice(0, limit).map((r) => publicRun(r, 0)),
|
|
2026
2117
|
update_queued: updateQueued,
|
|
2027
2118
|
answer: answerQuestion,
|
|
2119
|
+
card: actOnCard,
|
|
2028
2120
|
}
|
|
2029
2121
|
|
|
2030
2122
|
// --- local socket (owner-only) ---------------------------------------------
|
|
@@ -2170,6 +2262,10 @@ export function apply(ctx) {
|
|
|
2170
2262
|
agentsService = child.agents
|
|
2171
2263
|
child.effect(() => () => { if (agentsService === child.agents) agentsService = null }, 'dsh-baton-host agents')
|
|
2172
2264
|
})
|
|
2265
|
+
ctx.inject(['actionCards'], (child) => {
|
|
2266
|
+
cardsService = child.actionCards
|
|
2267
|
+
child.effect(() => () => { if (cardsService === child.actionCards) cardsService = null }, 'dsh-baton-host action cards')
|
|
2268
|
+
})
|
|
2173
2269
|
ctx.inject(['agentTeams'], (child) => {
|
|
2174
2270
|
teamsService = child.agentTeams
|
|
2175
2271
|
child.effect(() => () => { if (teamsService === child.agentTeams) teamsService = null }, 'dsh-baton-host agent teams')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-baton-host",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.21",
|
|
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.21"
|
|
28
28
|
},
|
|
29
29
|
"license": "MIT",
|
|
30
30
|
"dsh": {
|