dsh-chief 1.2.0 → 1.3.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/auto-continue.js CHANGED
@@ -230,6 +230,7 @@ export function createAutoContinueEngine(options = {}) {
230
230
  getAgent,
231
231
  createMessage = null,
232
232
  isChiefStopped = () => false,
233
+ canAutoContinue = null,
233
234
  resolveRootSessionId = (sid) => sid,
234
235
  onLog = () => {},
235
236
  baseDelayMs = 1500,
@@ -309,7 +310,7 @@ export function createAutoContinueEngine(options = {}) {
309
310
  return Math.round(baseDelayMs * Math.pow(2, exp))
310
311
  }
311
312
 
312
- async function fire(sessionId, trigger, { detail = '' } = {}) {
313
+ async function fire(sessionId, trigger, { detail = '', bypassGate = false } = {}) {
313
314
  const st = getSessionState(sessionId)
314
315
  if (!st) return { ok: false, skipped: 'invalid-session' }
315
316
  st.timer = null
@@ -321,6 +322,15 @@ export function createAutoContinueEngine(options = {}) {
321
322
  return { ok: false, skipped: 'chief-stopped' }
322
323
  }
323
324
 
325
+ if (!bypassGate && typeof canAutoContinue === 'function') {
326
+ const verdict = await Promise.resolve(canAutoContinue({ sessionId, rootId, trigger, detail }))
327
+ if (verdict && verdict.allowed === false) {
328
+ st.stats.skippedStopped += 1
329
+ if (verdict.logMessage) onLog(sessionId, verdict.logMessage)
330
+ return { ok: false, skipped: verdict.skipped || 'permission-mode', approvalId: verdict.approvalId }
331
+ }
332
+ }
333
+
324
334
  if (st.consecutive >= maxConsecutive) {
325
335
  onLog(sessionId, `已达连续自动续跑上限(${maxConsecutive} 次),等待人工确认或成功回合恢复`)
326
336
  return { ok: false, skipped: 'max-consecutive' }