dsh-chief 1.5.0 → 1.7.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/digest.js CHANGED
@@ -13,6 +13,8 @@
13
13
  * (`todo_write`, `create_goal`, `update_goal`) into the board.
14
14
  */
15
15
 
16
+ import { normalizeCursorBlocked } from './board-schema.js'
17
+
16
18
  const DIGEST_BUDGET = 2500
17
19
 
18
20
  function ownerName(id) {
@@ -115,7 +117,10 @@ function planLines(board, limit) {
115
117
  const open = steps.filter(step => !step.done)
116
118
  const shown = open.slice(0, limit)
117
119
  const lines = ['规划 ' + done + '/' + steps.length + (open.length > shown.length ? '(未完成 ' + open.length + ',此处列前 ' + shown.length + ')' : '') + ':']
118
- for (const step of shown) lines.push(' [ ] ' + clamp(step.text, 90))
120
+ for (const step of shown) {
121
+ const idx = steps.indexOf(step) + 1
122
+ lines.push(' [ ] ' + idx + '. (id:' + step.id + ') ' + clamp(step.text, 86))
123
+ }
119
124
  lines.push(
120
125
  ' ↳ 每轮先按顺序读这一段:做完的步 plan.set 标 done;新发现的步补进去;'
121
126
  + '不再做的旧步删掉;需要拆解子代理并行时用 graph.plan 建任务图并用 task.dispatch 派发。',
@@ -187,8 +192,27 @@ function subagentHeaderLines(board, extras) {
187
192
  lines.push('🤖 子代理团队 (' + running.length + ' 运行中 / 共 ' + children.length + ' 个): ' + summary + (restCount > 0 ? ' · 另有 ' + restCount + ' 个空闲成员' : ''))
188
193
  }
189
194
  }
195
+ const squad = extras && extras.bubbleSquad ? extras.bubbleSquad : null
190
196
  if (extras && Number(extras.linkedPeersCount) > 0) {
191
- lines.push('📡 跨窗口协同已开启: 已与 ' + extras.linkedPeersCount + ' 个外部主对话窗口互通,可用 chief_board({ action: "mail.send", target, text }) 跨对话递话。')
197
+ lines.push('📡 跨窗口协同已开启: 已与 ' + extras.linkedPeersCount + ' 个外部主对话窗口互通,可用 chief_board({ action: "mail.send", target, text }) 跨对话递话(target 见下方联动对话)。')
198
+ }
199
+ const enrolledHarnesses = squad && Array.isArray(squad.enrolledHarnesses) ? squad.enrolledHarnesses : []
200
+ if (enrolledHarnesses.length) {
201
+ const harnessDesc = enrolledHarnesses.map(h => {
202
+ const flag = h.running ? '运行中' : (h.configured ? '直连就绪' : '已安装待检')
203
+ return (h.label || h.provider) + '(target="' + h.provider + '", ' + flag + ')'
204
+ }).join(' · ')
205
+ lines.push('🧩 水泡外协 Harness (' + enrolledHarnesses.length + ' 编入' + (squad.locked ? ' · 🔒已锁编队' : '') + '): ' + harnessDesc + ' —— 可调 chief_board({ action: "mail.send", target, text }) 直接派单调用。')
206
+ }
207
+ const standbyCount = squad ? Number(squad.standbySessionsCount) || 0 : 0
208
+ const availHarnesses = squad && Array.isArray(squad.availableHarnesses) ? squad.availableHarnesses : []
209
+ if (standbyCount > 0 || availHarnesses.length > 0) {
210
+ const parts = []
211
+ if (standbyCount > 0) parts.push(standbyCount + ' 个未入泡独立主对话(内容已隔离,需用户手动入泡后方可见)')
212
+ if (availHarnesses.length > 0) {
213
+ parts.push(availHarnesses.length + ' 个已装待命 Harness(' + availHarnesses.slice(0, 4).map(h => h.provider).join('/') + ')')
214
+ }
215
+ lines.push('🪑 队外待命探测: 本机另有 ' + parts.join('、') + ';编队状态可调 team.list / mail.inbox 查询。')
192
216
  }
193
217
  return lines
194
218
  }
@@ -287,7 +311,7 @@ function cursorLines(board) {
287
311
  const cursor = board && board.cursor ? board.cursor : null
288
312
  const step = clamp(cursor && cursor.step, 120)
289
313
  const next = clamp(cursor && cursor.next, 160)
290
- const blocked = clamp(cursor && cursor.blocked, 120)
314
+ const blocked = clamp(normalizeCursorBlocked(cursor && cursor.blocked), 120)
291
315
  if (!step && !next && !blocked) {
292
316
  const open = (Array.isArray(board && board.plan) ? board.plan : []).filter(item => !item.done)
293
317
  if (!open.length) return []
@@ -312,10 +336,11 @@ function linkedPeersLines(extras, limit = 4) {
312
336
  const lines = ['🌐 协同网络共享进度(当前联动 ' + peers.length + ' 个主对话 · 退出协同后自动清零):']
313
337
  for (const p of shown) {
314
338
  const label = clamp(p.name || ownerName(p.rootId), 26)
339
+ const tgt = p.rootId ? ' target="' + clamp(String(p.rootId), 36) + '"' : ''
315
340
  const obj = p.objective ? '目标=' + clamp(p.objective, 52) : '暂无总目标'
316
341
  const counts = '任务 ' + (Number(p.doneCount) || 0) + '完/' + (Number(p.doingCount) || 0) + '做/' + (Number(p.blockedCount) || 0) + '阻'
317
342
  const cur = p.cursorStep ? ' · 断点=' + clamp(p.cursorStep, 36) : ''
318
- lines.push(' · [' + label + '] ' + obj + ' | ' + counts + cur)
343
+ lines.push(' · [' + label + tgt + '] ' + obj + ' | ' + counts + cur)
319
344
  }
320
345
  if (peers.length > shown.length) {
321
346
  lines.push(' …另有 ' + (peers.length - shown.length) + ' 个联动对话')
package/idle-guard.js CHANGED
@@ -121,6 +121,10 @@ const LOOP_REPEAT = 4
121
121
  /** A session's recent calls, capped, so one long turn cannot grow it forever. */
122
122
  const callTrail = new Map()
123
123
 
124
+ /** Per-session mid-turn spin & consecutive tool-error tracker (capped at 64 sessions). */
125
+ const spinState = new Map()
126
+ const MID_TURN_SPIN_COOLDOWN_MS = 15_000
127
+
124
128
  /** Tools whose identical repetition is ordinary, not a stuck loop. */
125
129
  const READ_ONLY_ACTION = /"action"\s*:\s*"(?:snapshot|memory\.ask)"/u
126
130
 
@@ -139,6 +143,47 @@ function hashCall(name, argumentsValue) {
139
143
  return hash.toString(36) + ':' + text.length.toString(36)
140
144
  }
141
145
 
146
+ function fuzzyNormalizeArgs(argumentsValue) {
147
+ let text = String(argumentsValue === undefined || argumentsValue === null ? '' : argumentsValue)
148
+ text = text.replace(/(?:^|\s)(?:\/\/|#)[^\n\r]*/g, '')
149
+ text = text.replace(/\b[0-9a-fA-F]{6,}(?:-[0-9a-fA-F]{4,}){0,4}\b/g, '#HEX#')
150
+ text = text.replace(/\d+(?:\.\d+)?/g, '#')
151
+ return text.replace(/\s+/g, ' ').trim()
152
+ }
153
+
154
+ function getSpinEntry(sessionId, create = true) {
155
+ const id = String(sessionId || '')
156
+ if (!id) return null
157
+ let st = spinState.get(id)
158
+ if (!st && create) {
159
+ st = {
160
+ consecutiveErrors: 0,
161
+ lastErrorTool: '',
162
+ lastErrorPreview: '',
163
+ callsSinceActed: 0,
164
+ lastActedAt: 0,
165
+ }
166
+ spinState.set(id, st)
167
+ if (spinState.size > 64) {
168
+ const oldest = spinState.keys().next().value
169
+ if (oldest !== undefined && oldest !== id) spinState.delete(oldest)
170
+ }
171
+ }
172
+ return st || null
173
+ }
174
+
175
+ function extractToolResultText(data) {
176
+ if (!data || typeof data !== 'object') return typeof data === 'string' ? data : ''
177
+ if (typeof data.error === 'string' && data.error) return data.error
178
+ if (data.error && typeof data.error === 'object' && typeof data.error.message === 'string') return data.error.message
179
+ const raw = data.result ?? data.output ?? data.text ?? data.content ?? ''
180
+ if (typeof raw === 'string') return raw
181
+ if (Array.isArray(raw)) {
182
+ return raw.map(b => (b && typeof b.text === 'string' ? b.text : '')).filter(Boolean).join('\n')
183
+ }
184
+ return ''
185
+ }
186
+
142
187
  export function noteCallTrail(sessionId, name, argumentsValue) {
143
188
  const id = String(sessionId || '')
144
189
  let trail = callTrail.get(id)
@@ -152,16 +197,140 @@ export function noteCallTrail(sessionId, name, argumentsValue) {
152
197
  }
153
198
  trail.push({
154
199
  key: hashCall(name, argumentsValue),
200
+ fuzzyKey: hashCall(name, fuzzyNormalizeArgs(argumentsValue)),
155
201
  name: String(name || ''),
156
202
  readOnly: isReadOnlyCall(name, argumentsValue),
203
+ planWrite: isPlanWrite(name, argumentsValue),
157
204
  preview: String(argumentsValue === undefined || argumentsValue === null ? '' : argumentsValue).slice(0, 120),
158
205
  })
159
206
  if (trail.length > 16) trail.splice(0, trail.length - 16)
207
+ const st = getSpinEntry(id, true)
208
+ if (st) st.callsSinceActed += 1
209
+ }
210
+
211
+ /** Track consecutive failing tool results so mid-turn error thrashing is caught live. */
212
+ export function noteCallResult(sessionId, data = {}) {
213
+ const id = String(sessionId || '')
214
+ if (!id) return
215
+ const st = getSpinEntry(id, true)
216
+ if (!st) return
217
+ const text = extractToolResultText(data)
218
+ const isFailure = Boolean(data && (data.isError === true || data.error))
219
+ || /^\s*(?:Error:|ENOENT\b|EPERM\b|failed\b|Exit code\b)/i.test(text)
220
+ if (isFailure) {
221
+ st.consecutiveErrors += 1
222
+ st.lastErrorTool = String((data && (data.name || data.toolName)) || st.lastErrorTool || 'tool')
223
+ st.lastErrorPreview = String(text || (data && data.message) || '').replace(/\s+/g, ' ').trim().slice(0, 120)
224
+ } else {
225
+ st.consecutiveErrors = 0
226
+ st.lastErrorTool = ''
227
+ st.lastErrorPreview = ''
228
+ }
160
229
  }
161
230
 
162
231
  /** Read-only repeats get a higher bar: re-reading after each edit is normal. */
163
232
  const LOOP_REPEAT_READ = LOOP_REPEAT + 3
164
233
 
234
+ /**
235
+ * Detect live mid-turn spinning across three patterns: exact loop, varying-arg
236
+ * polling loop (`fuzzyKey`), and consecutive failing tool calls (`error-thrash`).
237
+ */
238
+ export function detectMidTurnSpin(sessionId, { strongIntervention = false } = {}) {
239
+ const id = String(sessionId || '')
240
+ if (!id) return null
241
+ const st = getSpinEntry(id, false)
242
+ if (st && st.lastActedAt > 0 && Date.now() - st.lastActedAt < MID_TURN_SPIN_COOLDOWN_MS && st.callsSinceActed < 3) {
243
+ return null
244
+ }
245
+ const trail = callTrail.get(id)
246
+ if (trail && trail.length > 0) {
247
+ const last = trail[trail.length - 1]
248
+ let exactCount = 0
249
+ for (let index = trail.length - 1; index >= 0; index -= 1) {
250
+ if (trail[index].key !== last.key) break
251
+ exactCount += 1
252
+ }
253
+ const exactLimit = last.readOnly ? (strongIntervention ? 6 : LOOP_REPEAT_READ) : (strongIntervention ? 3 : LOOP_REPEAT)
254
+ if (exactCount >= exactLimit) {
255
+ return { kind: 'exact-loop', name: last.name, preview: last.preview, count: exactCount }
256
+ }
257
+ if (!last.planWrite) {
258
+ let fuzzyCount = 0
259
+ for (let index = trail.length - 1; index >= 0; index -= 1) {
260
+ if (trail[index].fuzzyKey !== last.fuzzyKey || trail[index].planWrite) break
261
+ fuzzyCount += 1
262
+ }
263
+ const fuzzyLimit = (strongIntervention ? 4 : 6) + (last.readOnly ? 2 : 0)
264
+ if (fuzzyCount >= fuzzyLimit) {
265
+ return { kind: 'fuzzy-loop', name: last.name, preview: last.preview, count: fuzzyCount }
266
+ }
267
+ }
268
+ }
269
+ const errLimit = strongIntervention ? 4 : 5
270
+ if (st && st.consecutiveErrors >= errLimit) {
271
+ return {
272
+ kind: 'error-thrash',
273
+ name: st.lastErrorTool || 'tool',
274
+ preview: st.lastErrorPreview || '',
275
+ count: st.consecutiveErrors,
276
+ }
277
+ }
278
+ return null
279
+ }
280
+
281
+ /** Record mid-turn intervention cooldown and trim tail repeat streak to prevent double firing. */
282
+ export function markMidTurnSpinActed(sessionId) {
283
+ const id = String(sessionId || '')
284
+ if (!id) return
285
+ const st = getSpinEntry(id, true)
286
+ if (st) {
287
+ st.lastActedAt = Date.now()
288
+ st.callsSinceActed = 0
289
+ st.consecutiveErrors = 0
290
+ }
291
+ const trail = callTrail.get(id)
292
+ if (trail && trail.length > 1) trail.splice(0, trail.length - 1)
293
+ }
294
+
295
+ /** Reset per-turn spin counters on turn/start while avoiding false positives across turns. */
296
+ export function clearMidTurnSpin(sessionId) {
297
+ const id = String(sessionId || '')
298
+ if (!id) {
299
+ spinState.clear()
300
+ callTrail.clear()
301
+ return
302
+ }
303
+ spinState.delete(id)
304
+ callTrail.delete(id)
305
+ }
306
+
307
+ /** Build steer notice for a live running agent spinning mid-turn. */
308
+ export function buildMidTurnSpinNotice(spin, board) {
309
+ const s = spin && typeof spin === 'object' ? spin : { kind: 'exact-loop', name: '?', preview: '', count: 0 }
310
+ const obj = String((board && board.objective) || '').trim().slice(0, 120)
311
+ const lines = ['[参谋看板 · 运行中空转急刹]']
312
+ if (s.kind === 'error-thrash') {
313
+ lines.push(
314
+ `检测到本轮工具已连续报错 ${s.count} 次(最近一次:${s.name}${s.preview ? ' -> ' + s.preview : ''}),继续硬撞不会成功。`,
315
+ )
316
+ } else if (s.kind === 'fuzzy-loop') {
317
+ lines.push(
318
+ `检测到你连续 ${s.count} 次以高度相似参数反复轮询/重试 ${s.name}${s.preview ? ' (' + s.preview + ')' : ''},疑似原地轮询空转。`,
319
+ )
320
+ } else {
321
+ lines.push(
322
+ `检测到同一调用连续重复 ${s.count} 次(${s.name}${s.preview ? ' ' + s.preview : ''}),没有产生新推进。`,
323
+ )
324
+ }
325
+ if (obj) lines.push(`当前锁定核心目标:${obj}`)
326
+ lines.push(
327
+ '请立刻停止同类重复尝试,马上二选一:',
328
+ '1) 读取真实错误/服务状态并切换完全不同的修复路径或参数,同时用 chief_board 更新断点进度;',
329
+ '2) 若确认当前环境或依赖已卡死无法突破,立即停止重试,用 chief_board cursor.set(blocked) 标明卡点,并直接汇报阻塞原因请求人工/参谋处理。',
330
+ )
331
+ return buildMessage(lines.join('\n'))
332
+ }
333
+
165
334
  /**
166
335
  * The tail of this Session's calls when the same (name, arguments) pair has
167
336
  * just repeated. Returns null for anything less: the same tool with different
@@ -309,7 +478,7 @@ export function turnHadToolCall(sessionId, turn, session) {
309
478
  * reader can use, which is exactly what the guard exists for.
310
479
  */
311
480
  export function readAnswer(session, turn) {
312
- const result = { hasMessage: false, chars: 0, thoughtChars: 0 }
481
+ const result = { hasMessage: false, chars: 0, thoughtChars: 0, lastText: '' }
313
482
  if (!session || typeof session.snapshotEvents !== 'function') return result
314
483
  try {
315
484
  const events = session.snapshotEvents()
@@ -321,8 +490,13 @@ export function readAnswer(session, turn) {
321
490
  if (message && Array.isArray(message.content)) {
322
491
  for (const block of message.content) {
323
492
  if (!block || typeof block.text !== 'string') continue
324
- if (block.type === 'text') result.chars += block.text.length
325
- else if (block.type === 'reasoning') result.thoughtChars += block.text.length
493
+ if (block.type === 'text') {
494
+ result.chars += block.text.length
495
+ const trimmed = block.text.trim()
496
+ if (trimmed) result.lastText = trimmed.slice(0, 400)
497
+ } else if (block.type === 'reasoning') {
498
+ result.thoughtChars += block.text.length
499
+ }
326
500
  }
327
501
  }
328
502
  }
@@ -330,6 +504,38 @@ export function readAnswer(session, turn) {
330
504
  return result
331
505
  }
332
506
 
507
+ const PREMATURE_ASK_OR_STOP_RE = /(?:请确认|请选择|是否继续|需要您|您看|请指示|请拍板|全部完成|已交付完毕|已完成交付|本轮无进展|卡住了,因为|已暂停待命|优雅退出|收工待命)/
508
+ const COMPLETED_ACTION_PHRASE_RE = /(?:(?:已|已经|刚|刚刚|刚才)?(?:重启|拉起|补跑|续跑|写入?|跑)(?:完成|完毕|好了?|了|成功)|(?:重启|补跑|拉起)前|已(?:重启|拉起|补跑|续跑|写完|完成)|无需(?:重启|补跑|继续))/g
509
+ const PREMATURE_PROMISE_CUE_RE = /(?:重启|拉起|补跑|续跑|继续跑|继续执行|开始跑|开始写|写[^\n。]{0,20}驱动|接下来(?:我|先|去|开始|将)|下面(?:我|先|开始)|马上(?:去|执行|重启|补跑|修复)|这就去|现在(?:去|开始|重启|补跑))/
510
+
511
+ /**
512
+ * Detect short wrap-up answers that merely promise the next concrete action
513
+ * (e.g. "重启 ComfyUI 补跑。" / "写 round-5 驱动。") while stopping the turn.
514
+ */
515
+ export function detectPrematurePromiseText(text) {
516
+ const clean = String(text || '').replace(/\s+/g, ' ').trim()
517
+ if (!clean || clean.length > 320) return ''
518
+ if (/[??]\s*$/.test(clean) || PREMATURE_ASK_OR_STOP_RE.test(clean)) return ''
519
+ const segs = clean.split(/[。!?\n]+/).map(s => s.trim()).filter(Boolean)
520
+ const tailSegs = segs.slice(-2)
521
+ for (let idx = tailSegs.length - 1; idx >= 0; idx -= 1) {
522
+ const seg = tailSegs[idx]
523
+ const pendingPart = seg.replace(COMPLETED_ACTION_PHRASE_RE, ' ').trim()
524
+ if (PREMATURE_PROMISE_CUE_RE.test(pendingPart)) {
525
+ return seg.slice(0, 120)
526
+ }
527
+ }
528
+ return ''
529
+ }
530
+
531
+ function resolveEffectiveMaxPerSession(limits, { strongIntervention = false, maxInterventionTurns = 0 } = {}) {
532
+ const baseMax = limits.maxPerSession
533
+ if (!strongIntervention || baseMax === 0) return baseMax
534
+ const n = Number(maxInterventionTurns)
535
+ if (n === 0) return Math.max(baseMax, 16)
536
+ return Math.max(baseMax, Math.min(20, Math.round(n || baseMax)))
537
+ }
538
+
333
539
  /** Open work on the board: unfinished plan steps and tasks that are not done. */
334
540
  export function openWork(board) {
335
541
  const steps = Array.isArray(board && board.plan) ? board.plan.filter(step => !step.done) : []
@@ -341,7 +547,7 @@ export function openWork(board) {
341
547
  * Decide whether this close is premature. Every condition must hold, so the
342
548
  * guard stays out of ordinary conversation.
343
549
  */
344
- export function shouldGuard({ board, session, sessionId, turn, settings }) {
550
+ export function shouldGuard({ board, session, sessionId, turn, settings, strongIntervention = false, maxInterventionTurns = 0 }) {
345
551
  const flags = settings || {}
346
552
  if (flags.guardIdle === false) return null
347
553
  // One nudge per turn: steering re-opens the same turn, so a second close in
@@ -350,7 +556,8 @@ export function shouldGuard({ board, session, sessionId, turn, settings }) {
350
556
 
351
557
  const used = interventions.get(String(sessionId)) || 0
352
558
  const limits = guardLimits(flags)
353
- if (used >= limits.maxPerSession) return null
559
+ const effectiveMax = resolveEffectiveMaxPerSession(limits, { strongIntervention, maxInterventionTurns })
560
+ if (used >= effectiveMax) return null
354
561
 
355
562
  const answer = readAnswer(session, turn)
356
563
  // No committed answer means the turn produced nothing for the reader yet;
@@ -378,6 +585,13 @@ export function shouldGuard({ board, session, sessionId, turn, settings }) {
378
585
  return { kind: 'no-goal', work, answer }
379
586
  }
380
587
 
588
+ // Shape 6, premature-promise: closed turn right after verbally promising the
589
+ // next concrete execution action ("重启 XX 补跑 / 写驱动"), even if it updated the board.
590
+ if (work.total > 0 || Boolean(objective)) {
591
+ const promiseCue = detectPrematurePromiseText(answer.lastText)
592
+ if (promiseCue) return { kind: 'premature-promise', work, answer, promiseCue }
593
+ }
594
+
381
595
  // Shape 3, no-plan: the board never held a plan or task graph, so nothing can
382
596
  // be "open". A turn that actually did work leaves the reader with no record
383
597
  // of what it was doing or what comes next.
@@ -414,7 +628,7 @@ export function shouldGuard({ board, session, sessionId, turn, settings }) {
414
628
  * busy turn "you did not call any tool" would be a lie the model can disprove
415
629
  * from its own transcript, which is the fastest way to lose its attention.
416
630
  */
417
- export function buildNotice({ kind, work, answer, loop, board }) {
631
+ export function buildNotice({ kind, work, answer, loop, promiseCue, board }) {
418
632
  const steps = work.steps.slice(0, 3).map(step => '· ' + String(step.text).slice(0, 80))
419
633
  const tasks = work.tasks.slice(0, 3).map(task => '· ' + String(task.title).slice(0, 80))
420
634
  const counting = '(' + work.steps.length + ' 个规划步骤 / ' + work.tasks.length + ' 条待办)'
@@ -433,6 +647,10 @@ export function buildNotice({ kind, work, answer, loop, board }) {
433
647
  + ' 项 ' + counting + ',却没有一句能说明这些动作是为了什么。'
434
648
  + '没有目标,步骤列表接着改也只是原地打转。',
435
649
  )
650
+ } else if (kind === 'premature-promise') {
651
+ lines.push(
652
+ '你刚才只用文字预告了下一步动作(『' + String(promiseCue || '').slice(0, 80) + '』),却直接结束回合而未调用工具执行,请立刻调用工具落实并验证。',
653
+ )
436
654
  } else if (kind === 'no-plan') {
437
655
  lines.push(
438
656
  '这个会话还没写过规划:这轮动手了,参谋看板上却连一条规划都没有(记忆里也没有下一步)。'
@@ -467,6 +685,12 @@ export function buildNotice({ kind, work, answer, loop, board }) {
467
685
  '2) 目标写完后,回答「目标有没有真的前进」,没前进就明说没前进、卡在哪;',
468
686
  '3) 如果这活本来就是一串可勾的步骤、不需要持续目标,用 mode.set 回到 plan,别让空目标一直挂着。',
469
687
  )
688
+ } else if (kind === 'premature-promise') {
689
+ lines.push(
690
+ '禁止只做口头预告就停手交卷。现在立刻落实:',
691
+ '1) 立即调用对应工具执行你刚才提到的操作(重启服务 / 补跑脚本 / 写入文件 / 验证结果),',
692
+ '2) 执行完毕后更新 chief_board 状态并汇报可核验证据;若确实遇外部阻塞必须由人类处理,请明确写「卡住了,因为 …」并标记 cursor.set(blocked)。',
693
+ )
470
694
  } else if (kind === 'no-plan') {
471
695
  lines.push(
472
696
  '不要就这样结束。下一步至少做一件,然后才收工:',
@@ -530,7 +754,8 @@ export function clearInterventions(sessionId) {
530
754
  }
531
755
 
532
756
  /** Whether this Session still has interventions left (for reporting). */
533
- export function remainingInterventions(sessionId, settings) {
757
+ export function remainingInterventions(sessionId, settings, opts = {}) {
534
758
  const limits = guardLimits(settings)
535
- return Math.max(0, limits.maxPerSession - (interventions.get(String(sessionId || '')) || 0))
759
+ const max = resolveEffectiveMaxPerSession(limits, opts)
760
+ return Math.max(0, max - (interventions.get(String(sessionId || '')) || 0))
536
761
  }
package/index.js CHANGED
@@ -28,6 +28,8 @@ const hostState = {
28
28
  activeRuntime: null,
29
29
  // Active host LLM service injected via ctx.inject(['llm'])
30
30
  activeLlm: null,
31
+ // Active host subprocess service injected via ctx.inject(['subprocess'])
32
+ activeSubprocess: null,
31
33
  // Active Auto-Continue engine instance cleaned up on plugin dispose
32
34
  activeAutoContinue: null,
33
35
  // Recent idle/loop steer timestamps keyed by `sessionId:turn`
@@ -36,6 +38,10 @@ const hostState = {
36
38
  subagentRootMap: new Map(),
37
39
  // Cached subagent roster rows keyed by root session id
38
40
  subagentTreeCache: new Map(),
41
+ // Dynamically discovered external Harness providers (codex / claude-code / acp / dsh-sdk)
42
+ detectedHarnessProviders: new Map(),
43
+ // In-flight external Harness activations tracked per root session for structural lock & emergency stop
44
+ activeBubbleRuns: new Map(),
39
45
  // Monotonic sequence counter for injected handover message envelopes
40
46
  handoffSeq: 0,
41
47
  }
package/locale/en.json CHANGED
@@ -1,6 +1,77 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "DSH Chief",
4
- "description": "Let AI manage AI — it minds the flow itself and stops a runaway before it costs you. No screen-sitting, no repeated confirmations; it keeps working while you are away, and asks before touching your workspace."
4
+ "description": "Right-sidebar plugin for DSH: tracks task progress, saves notes before context compaction, and asks before editing your workspace. Read-only by default."
5
+ },
6
+ "ui": {
7
+ "brandName": "DSH Chief",
8
+ "tabs": {
9
+ "chief": "Chief",
10
+ "tasks": "Tasks",
11
+ "peers": "Peers",
12
+ "archive": "Archives",
13
+ "boundaries": "Guards"
14
+ },
15
+ "runModes": {
16
+ "off": "⏸ Off",
17
+ "patrol": "🛡 Patrol",
18
+ "managed": "🤖 Managed"
19
+ },
20
+ "perms": {
21
+ "advisor": "L0 · Advisor",
22
+ "assistant": "L1 · Assistant",
23
+ "strategist": "L2 · Strategist",
24
+ "chief": "L3 · Chief"
25
+ },
26
+ "presets": {
27
+ "title": "🚀 One-Click Scenario Presets",
28
+ "observer": {
29
+ "title": "👁 Read-Only Observer",
30
+ "tag": "L0 · ⏸ Off",
31
+ "desc": "Read-only: no automatic actions or edits; gives summaries and advice when asked."
32
+ },
33
+ "collab": {
34
+ "title": "🤝 Daily Co-Pilot",
35
+ "tag": "L2 · 🛡 Patrol",
36
+ "desc": "No background model calls while idle; steps in on errors or blocked walls and asks before important changes."
37
+ },
38
+ "away": {
39
+ "title": "🚀 Away Managed",
40
+ "tag": "L3 · 🤖 Managed",
41
+ "desc": "Keeps watching progress, auto-compacts at 80%, stops after 30 calls or 300K tokens, and sends alerts at key points."
42
+ }
43
+ },
44
+ "notify": {
45
+ "title": "🔔 Away Alerts & Gentle Chime",
46
+ "desktopToggle": "Desktop notifications at key milestones",
47
+ "soundToggle": "Gentle chime sound (off by default)",
48
+ "testBtn": "Test alert",
49
+ "permGranted": "Permission granted",
50
+ "permDefault": "Click to authorize",
51
+ "permDenied": "Blocked in browser",
52
+ "permUnsupported": "In-panel toast alerts"
53
+ },
54
+ "ledger": {
55
+ "title": "📊 Chief LLM Ledger & Hard Budget Cap",
56
+ "totalCalls": "Total calls",
57
+ "totalTokens": "Total tokens",
58
+ "catChat": "Q&A",
59
+ "catReview": "Patrol",
60
+ "catDream": "Dream Roam",
61
+ "managedCallsCap": "Managed call cap / run",
62
+ "managedTokensCap": "Managed token cap / run",
63
+ "resetManaged": "Reset run counter",
64
+ "tripped": "🛑 Hard budget cap reached — auto-stopped to protect tokens"
65
+ },
66
+ "report": {
67
+ "exportMd": "📄 Export Report (.md)",
68
+ "copyMd": "📋 Copy Markdown Report"
69
+ },
70
+ "lang": {
71
+ "title": "🌐 Interface Language / 界面语言",
72
+ "auto": "Auto",
73
+ "zh": "简体中文",
74
+ "en": "English"
75
+ }
5
76
  }
6
77
  }
package/locale/zh.json CHANGED
@@ -1,6 +1,77 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "DSH 参谋长",
4
- "description": "AI 管 AI,你当甩手掌柜 —— 它自己盯流程,跑崩了先拦住。不用守着屏幕,也不用反复确认;你不在的时候它照样跑,越权改工作区会先问你。"
4
+ "description": "DSH 右侧栏插件:跟踪任务进度,压缩上下文前先存档,模型改工作区前先问你。默认只读。"
5
+ },
6
+ "ui": {
7
+ "brandName": "DSH 参谋长",
8
+ "tabs": {
9
+ "chief": "参谋",
10
+ "tasks": "任务",
11
+ "peers": "协同",
12
+ "archive": "档案",
13
+ "boundaries": "边界"
14
+ },
15
+ "runModes": {
16
+ "off": "⏸ 关停",
17
+ "patrol": "🛡 巡检",
18
+ "managed": "🤖 托管"
19
+ },
20
+ "perms": {
21
+ "advisor": "L0 · 顾问模式",
22
+ "assistant": "L1 · 助手模式",
23
+ "strategist": "L2 · 参谋模式",
24
+ "chief": "L3 · 参谋长模式"
25
+ },
26
+ "presets": {
27
+ "title": "🚀 一键开箱场景预设",
28
+ "observer": {
29
+ "title": "👁 只读旁观",
30
+ "tag": "L0 · ⏸ 关停",
31
+ "desc": "只看不改:不自动执行任何操作,需要时给摘要和建议。"
32
+ },
33
+ "collab": {
34
+ "title": "🤝 日常协作",
35
+ "tag": "L2 · 🛡 巡检",
36
+ "desc": "平时不在后台调用模型,报错或撞墙时才介入;重要改动逐项弹窗问你。"
37
+ },
38
+ "away": {
39
+ "title": "🚀 离桌托管",
40
+ "tag": "L3 · 🤖 托管",
41
+ "desc": "持续盯进度,上下文到 80% 自动压缩,30 次调用或 300K Token 后自动停,关键节点发通知。"
42
+ }
43
+ },
44
+ "notify": {
45
+ "title": "🔔 离桌通知与轻提示音",
46
+ "desktopToggle": "关键节点桌面通知",
47
+ "soundToggle": "轻柔提示音(默认关)",
48
+ "testBtn": "试响 / 测试提醒",
49
+ "permGranted": "已授权桌面通知",
50
+ "permDefault": "待点击授权",
51
+ "permDenied": "浏览器已拦截通知",
52
+ "permUnsupported": "面板 Toast 提醒"
53
+ },
54
+ "ledger": {
55
+ "title": "📊 参谋长 LLM 账本与托管硬预算",
56
+ "totalCalls": "累计调用",
57
+ "totalTokens": "累计 Token",
58
+ "catChat": "问答",
59
+ "catReview": "巡检",
60
+ "catDream": "梦境漫游",
61
+ "managedCallsCap": "单次托管次数上限",
62
+ "managedTokensCap": "单次托管 Token 上限",
63
+ "resetManaged": "重置本轮托管计数",
64
+ "tripped": "🛑 已触及硬预算上限并自动熔断停机"
65
+ },
66
+ "report": {
67
+ "exportMd": "📄 导出复盘战报 (.md)",
68
+ "copyMd": "📋 复制战报 Markdown"
69
+ },
70
+ "lang": {
71
+ "title": "🌐 界面语言 / Language",
72
+ "auto": "自动 Auto",
73
+ "zh": "简体中文",
74
+ "en": "English"
75
+ }
5
76
  }
6
77
  }