dsh-dev-plan-presets 0.3.0 → 0.4.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/guard.js CHANGED
@@ -13,7 +13,7 @@
13
13
  * 本文件不 import Node 内置模块,也不 import @deepseek-ai/*,便于单测。
14
14
  */
15
15
 
16
- import { routeMatches, routeOf } from './settings.js'
16
+ import { DEFAULT_SETTINGS, routeMatches, routeOf } from './settings.js'
17
17
  import { PRESET_ID } from './preset.js'
18
18
 
19
19
  const MAX_TEXT = 240
@@ -142,10 +142,12 @@ const violationText = (got, want) =>
142
142
  * agent 作用域销毁和插件卸载两边都会调用同一个幂等 disposer。
143
143
  * @returns 幂等卸载函数;注册失败时返回 undefined。
144
144
  */
145
- const installStepGuard = (ctx, agent, settings, hooks, target) => {
145
+ const installStepGuard = (ctx, agent, settings, hooks, target, onDispose) => {
146
146
  let stopped = false
147
147
  let active = true
148
148
  const handler = async (payload, next) => {
149
+ if (settings.modelGuardMode === 'off') return next()
150
+ if (stopped) return { kind: 'reject' }
149
151
  const decision = await next()
150
152
  try {
151
153
  if (decision?.kind === 'reject') return decision
@@ -185,6 +187,11 @@ const installStepGuard = (ctx, agent, settings, hooks, target) => {
185
187
  } catch {
186
188
  /* ignore */
187
189
  }
190
+ try {
191
+ if (typeof onDispose === 'function') onDispose(agent)
192
+ } catch {
193
+ /* ignore */
194
+ }
188
195
  }
189
196
  // agent 作用域销毁时也释放;插件总 disposer 会先/后调用同一个 dispose,靠 active 幂等。
190
197
  try {
@@ -202,8 +209,16 @@ const installStepGuard = (ctx, agent, settings, hooks, target) => {
202
209
  * @param {import('./settings.js').DEFAULT_SETTINGS} settings
203
210
  * @param {{ recordViolation?: Function, audit?: Function, warn?: Function }} hooks
204
211
  * @param {{ provider: string, model: string, reasoningEffort?: string }} [target]
212
+ * @param {(agent: any) => void} [onDispose]
205
213
  */
206
- export function onAgentCreated(ctx, agent, settings, hooks = {}, target = routeOf(settings)) {
214
+ export function onAgentCreated(
215
+ ctx,
216
+ agent,
217
+ settings,
218
+ hooks = {},
219
+ target = routeOf(settings),
220
+ onDispose,
221
+ ) {
207
222
  if (!agent || settings.modelGuardMode === 'off') return
208
223
  const header = agent.session?.header
209
224
  // 主会话在这里被挡掉:没有父会话,也不是 origin=subagent。
@@ -234,7 +249,7 @@ export function onAgentCreated(ctx, agent, settings, hooks = {}, target = routeO
234
249
  })()
235
250
 
236
251
  if (mode === 'audit') {
237
- const dispose = installStepGuard(ctx, agent, settings, hooks, target)
252
+ const dispose = installStepGuard(ctx, agent, settings, hooks, target, onDispose)
238
253
  hooks?.audit?.('would-pin', {
239
254
  agent: shortId(agent?.id),
240
255
  from: describeRoute(current),
@@ -260,7 +275,7 @@ export function onAgentCreated(ctx, agent, settings, hooks = {}, target = routeO
260
275
 
261
276
  // pin:守卫必须在 select 尝试之前装好。这样即使 select 不存在/抛错且 kill=false,
262
277
  // 后续 pre-step 仍能记录越界,而不是变成完全不设防。
263
- const dispose = installStepGuard(ctx, agent, settings, hooks, target)
278
+ const dispose = installStepGuard(ctx, agent, settings, hooks, target, onDispose)
264
279
 
265
280
  // 已经在目标路由上:保留守卫防后续漂移即可。
266
281
  if (routeMatches(current, target)) {
@@ -316,7 +331,9 @@ export function installModelGuard(ctx, settings, hooks = {}) {
316
331
  const listener = (payload) => {
317
332
  const agent = payload?.agent
318
333
  try {
319
- const dispose = onAgentCreated(ctx, agent, settings, hooks, target)
334
+ const dispose = onAgentCreated(ctx, agent, settings, hooks, target, (targetAgent) => {
335
+ steps.delete(targetAgent)
336
+ })
320
337
  if (typeof dispose === 'function' && agent && typeof agent === 'object') {
321
338
  release(agent)
322
339
  steps.set(agent, dispose)
@@ -362,3 +379,169 @@ export function installModelGuard(ctx, settings, hooks = {}) {
362
379
  }
363
380
  }
364
381
  }
382
+
383
+ const turnSignatureOf = (agent, payload) => {
384
+ if (payload && payload.turnId !== undefined) return `turn:${String(payload.turnId)}`
385
+ if (payload && payload.userMessageId !== undefined) {
386
+ return `userMsg:${String(payload.userMessageId)}`
387
+ }
388
+ const messages = agent?.session?.messages
389
+ if (!Array.isArray(messages)) return 'default'
390
+ let userCount = 0
391
+ let lastUserId = ''
392
+ for (const msg of messages) {
393
+ if (msg?.role === 'user' && msg?.source?.kind !== 'dev-plan-presets') {
394
+ userCount += 1
395
+ if (msg.id !== undefined) lastUserId = String(msg.id)
396
+ }
397
+ }
398
+ return `users:${userCount}:${lastUserId}`
399
+ }
400
+
401
+ /**
402
+ * 主会话步数预算软提醒(独立于 modelGuardMode)。
403
+ * 仅在 settings.mainToolMode !== 'none' 时激活;
404
+ * 仅监听非子代理且 preset=dev-plan 的主会话,在单轮连续步数超阈值时温和注入提示,
405
+ * 绝不调用 agent.model.select、绝不 cancel、绝不 reject。
406
+ *
407
+ * @returns 幂等总卸载函数。
408
+ */
409
+ export function installMainStepBudget(ctx, settings, hooks = {}) {
410
+ const mode = settings?.mainToolMode ?? DEFAULT_SETTINGS.mainToolMode
411
+ if (mode === 'none') return () => {}
412
+ const threshold =
413
+ Number.isInteger(settings?.mainStepWarnThreshold) && settings.mainStepWarnThreshold >= 2
414
+ ? settings.mainStepWarnThreshold
415
+ : 6
416
+
417
+ const tracked = new Map()
418
+ let active = true
419
+
420
+ const release = (agent) => {
421
+ const dispose = tracked.get(agent)
422
+ if (dispose === undefined) return
423
+ tracked.delete(agent)
424
+ try {
425
+ dispose()
426
+ } catch {
427
+ /* ignore */
428
+ }
429
+ }
430
+
431
+ const attach = (agent) => {
432
+ if (!agent || typeof agent.ctx?.on !== 'function') return
433
+ if (isSubagentHeader(agent.session?.header)) return
434
+ if (presetOfSession(ctx, agent.session) !== PRESET_ID) return
435
+
436
+ let stepCount = 0
437
+ let warned = false
438
+ let lastTurn = ''
439
+ let lastStepAt = 0
440
+ let stepActive = true
441
+
442
+ let off
443
+ try {
444
+ off = agent.ctx.on('agent/pre-step', async (payload, next) => {
445
+ const decision = await next()
446
+ try {
447
+ if (decision?.kind === 'reject') return decision
448
+ const now = Date.now()
449
+ const turn = turnSignatureOf(agent, payload)
450
+ if (turn !== lastTurn || (lastStepAt > 0 && now - lastStepAt > 60_000)) {
451
+ lastTurn = turn
452
+ stepCount = 0
453
+ warned = false
454
+ }
455
+ lastStepAt = now
456
+ stepCount += 1
457
+ if (stepCount > threshold && !warned) {
458
+ warned = true
459
+ const message =
460
+ `💡 [dev-plan-presets] 当前主模型在本轮已连续执行 ${stepCount} 步(提醒阈值 ${threshold}),` +
461
+ `建议将后续探索或修改转交 recon / develop 子代理以节省主模型额度。`
462
+ hooks?.audit?.('main-step-budget-warn', {
463
+ agent: shortId(agent?.id),
464
+ steps: stepCount,
465
+ threshold,
466
+ mode,
467
+ })
468
+ if (typeof agent?.inject === 'function') {
469
+ agent.inject({
470
+ content: [{ type: 'text', text: message }],
471
+ source: { kind: 'dev-plan-presets' },
472
+ })
473
+ }
474
+ }
475
+ } catch {
476
+ /* 软提醒绝不中断主会话 */
477
+ }
478
+ return decision
479
+ })
480
+ } catch {
481
+ return
482
+ }
483
+
484
+ const dispose = () => {
485
+ if (!stepActive) return
486
+ stepActive = false
487
+ tracked.delete(agent)
488
+ try {
489
+ if (typeof off === 'function') off()
490
+ } catch {
491
+ /* ignore */
492
+ }
493
+ }
494
+
495
+ release(agent)
496
+ tracked.set(agent, dispose)
497
+ try {
498
+ if (typeof agent.ctx.effect === 'function') agent.ctx.effect(() => dispose)
499
+ } catch {
500
+ /* ignore */
501
+ }
502
+ }
503
+
504
+ const createdListener = (payload) => {
505
+ try {
506
+ attach(payload?.agent)
507
+ } catch {
508
+ /* ignore */
509
+ }
510
+ }
511
+ const disposedListener = (payload) => {
512
+ try {
513
+ release(payload?.agent)
514
+ } catch {
515
+ /* ignore */
516
+ }
517
+ }
518
+
519
+ const offs = []
520
+ try {
521
+ offs.push(ctx.on('agent/created', createdListener))
522
+ offs.push(ctx.on('agent/disposed', disposedListener))
523
+ } catch (error) {
524
+ hooks?.warn?.(`无法注册主窗步数提醒:${String(error?.message ?? error)}`)
525
+ }
526
+
527
+ return () => {
528
+ if (!active) return
529
+ active = false
530
+ for (const off of offs) {
531
+ try {
532
+ if (typeof off === 'function') off()
533
+ } catch {
534
+ /* ignore */
535
+ }
536
+ }
537
+ const pending = [...tracked.values()]
538
+ tracked.clear()
539
+ for (const dispose of pending) {
540
+ try {
541
+ dispose()
542
+ } catch {
543
+ /* ignore */
544
+ }
545
+ }
546
+ }
547
+ }
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * dsh-dev-plan-presets — Host 插件入口(0.3.0)
2
+ * dsh-dev-plan-presets — Host 插件入口(0.4.0)
3
3
  *
4
4
  * 本包做四件事:
5
5
  * 1. 用 ctx.agentPresets.register() 动态注册 dev-plan preset:Cordis 配置变更后插件重建,
@@ -24,20 +24,22 @@ import {
24
24
  } from './settings.js'
25
25
  import {
26
26
  DEEP_PTC_PRESET_ID,
27
+ INTERNAL_PRESET_IDS,
27
28
  PRESET_ID,
28
29
  buildPresetDefinition,
29
30
  resolveDevelopMode,
30
31
  } from './preset.js'
31
- import { installModelGuard } from './guard.js'
32
+ import { installMainStepBudget, installModelGuard } from './guard.js'
32
33
 
33
34
  export { Config }
34
35
  export const name = 'dev-plan-presets'
35
- export const version = '0.3.0'
36
+ export const version = '0.4.0'
36
37
  export const DEEP_PTC_PACKAGE_NAME = 'dsh-deep-ptc-mode'
37
38
 
38
39
  const MAX_VIOLATIONS = 50
39
40
  const MAX_WARNINGS = 20
40
41
  const DEFAULT_VERIFY_DELAY_MS = 2000
42
+ let instanceSeq = 0
41
43
 
42
44
  const isPlainObject = (value) =>
43
45
  typeof value === 'object' && value !== null && !Array.isArray(value)
@@ -122,7 +124,7 @@ export async function probePresets(ctx, registry) {
122
124
  return { checked, timedOut, rows, ...(error === undefined ? {} : { error }) }
123
125
  }
124
126
 
125
- const send = (res, code, payload) => {
127
+ const send = (res, code, payload, extraHeaders = {}) => {
126
128
  let body
127
129
  try {
128
130
  body = JSON.stringify(payload)
@@ -134,10 +136,20 @@ const send = (res, code, payload) => {
134
136
  'content-type': 'application/json; charset=utf-8',
135
137
  'cache-control': 'no-store',
136
138
  'content-length': Buffer.byteLength(body),
139
+ ...extraHeaders,
137
140
  })
138
141
  res.end(body)
139
142
  }
140
143
 
144
+ const etagMatches = (headerValue, etag) => {
145
+ if (typeof headerValue !== 'string' || headerValue.trim().length === 0) return false
146
+ const bare = etag.replace(/^"|"$/g, '')
147
+ return headerValue
148
+ .split(',')
149
+ .map((part) => part.trim().replace(/^W\//i, ''))
150
+ .some((part) => part === '*' || part === etag || part === bare)
151
+ }
152
+
141
153
  const readBody = async (req, limit) => {
142
154
  let body = ''
143
155
  for await (const chunk of req) {
@@ -214,18 +226,26 @@ const originProblem = (req, authoritativeOrigin) => {
214
226
  * Host 插件入口。
215
227
  * @param {any} ctx Cordis Context
216
228
  * @param {any} rawConfig Loader 配置(由 Config 校验/规范化)
217
- * @param {{ verificationDelayMs?: number, now?: () => number }} [runtime] 仅测试用的运行参数
229
+ * @param {{ verificationDelayMs?: number, prewarmDelayMs?: number, prewarmModelCatalog?: boolean, now?: () => number }} [runtime] 仅测试用的运行参数
218
230
  */
219
231
  export function apply(ctx, rawConfig, runtime = {}) {
220
232
  const settings = normalizeSettings(rawConfig)
233
+ const cachedRoute = routeOf(settings)
221
234
  const now = typeof runtime?.now === 'function' ? runtime.now : () => Date.now()
235
+ const instanceId = `${++instanceSeq}-${now().toString(36)}-${Math.random().toString(36).slice(2, 6)}`
222
236
  const violations = []
223
237
  const warnings = []
238
+ let stateVersion = 1
239
+ const currentStateTag = () => `${instanceId}-${stateVersion}`
240
+ const bumpState = () => {
241
+ stateVersion += 1
242
+ }
224
243
  const state = {
225
244
  settings,
226
245
  mode: null,
227
246
  definition: null,
228
247
  preset: null,
248
+ internalPresets: { scout: false, scribe: false },
229
249
  presets: { checked: false, timedOut: false, rows: [] },
230
250
  deepPtc: { available: false, checked: false },
231
251
  registration: 'pending',
@@ -244,6 +264,7 @@ export function apply(ctx, rawConfig, runtime = {}) {
244
264
  const rememberWarning = (message) => {
245
265
  warnings.unshift(String(message))
246
266
  if (warnings.length > MAX_WARNINGS) warnings.length = MAX_WARNINGS
267
+ bumpState()
247
268
  }
248
269
 
249
270
  const audit = (event, detail) => {
@@ -254,6 +275,7 @@ export function apply(ctx, rawConfig, runtime = {}) {
254
275
  const recordViolation = (entry) => {
255
276
  violations.unshift(entry)
256
277
  if (violations.length > MAX_VIOLATIONS) violations.length = MAX_VIOLATIONS
278
+ bumpState()
257
279
  log('warn', `模型守门:${entry?.text ?? '子代理越界'}`)
258
280
  }
259
281
 
@@ -271,6 +293,19 @@ export function apply(ctx, rawConfig, runtime = {}) {
271
293
  'dev-plan-presets: model guard',
272
294
  )
273
295
 
296
+ // ── 1b. 主会话步数预算软提醒(独立于 modelGuardMode,永不改模型/不取消)────
297
+ ctx.effect(
298
+ () =>
299
+ installMainStepBudget(ctx, settings, {
300
+ audit,
301
+ warn: (message) => {
302
+ rememberWarning(message)
303
+ log('warn', message)
304
+ },
305
+ }),
306
+ 'dev-plan-presets: main step budget',
307
+ )
308
+
274
309
  // ── 2. 动态 preset 注册(等 agentPresets 服务可用)──────────────────────────
275
310
  const delayMs = Number.isFinite(runtime?.verificationDelayMs)
276
311
  ? Math.max(0, Number(runtime.verificationDelayMs))
@@ -279,10 +314,22 @@ export function apply(ctx, rawConfig, runtime = {}) {
279
314
  ctx.inject(['agentPresets'], (child) => {
280
315
  const registry = child.agentPresets
281
316
  let disposed = false
282
- let release
317
+ let releases = []
283
318
  let queue = Promise.resolve()
284
319
  let timer
285
320
 
321
+ const releaseAll = async () => {
322
+ const current = releases
323
+ releases = []
324
+ for (let i = current.length - 1; i >= 0; i -= 1) {
325
+ try {
326
+ await current[i]()
327
+ } catch (error) {
328
+ log('warn', `释放动态 preset 失败:${String(error?.message ?? error)}`)
329
+ }
330
+ }
331
+ }
332
+
286
333
  const enqueue = (task) => {
287
334
  queue = queue
288
335
  .then(async () => {
@@ -293,6 +340,7 @@ export function apply(ctx, rawConfig, runtime = {}) {
293
340
  const message = String(error?.message ?? error)
294
341
  state.registration = 'failed'
295
342
  state.error = message
343
+ bumpState()
296
344
  rememberWarning(message)
297
345
  log('error', `注册 dev-plan preset 失败:${message}`)
298
346
  })
@@ -319,7 +367,14 @@ export function apply(ctx, rawConfig, runtime = {}) {
319
367
  checked: probe?.checked === true,
320
368
  ...(probe?.timedOut ? { registryTimedOut: true } : {}),
321
369
  }
322
- const definition = buildPresetDefinition({ settings, mode })
370
+
371
+ state.internalPresets = { scout: false, scribe: false }
372
+
373
+ const definition = buildPresetDefinition({
374
+ settings,
375
+ mode,
376
+ internalPresets: state.internalPresets,
377
+ })
323
378
  if (mode.fallback) {
324
379
  const message = `施工子代理已回退 standard:${mode.reason}`
325
380
  rememberWarning(message)
@@ -329,6 +384,7 @@ export function apply(ctx, rawConfig, runtime = {}) {
329
384
  } else {
330
385
  log('info', `施工子代理使用 ${mode.effective} preset(宿主预设目录已确认可用)。`)
331
386
  }
387
+
332
388
  const unregister = await registry.register(definition)
333
389
  if (typeof unregister !== 'function') {
334
390
  throw new Error('agentPresets.register 没有返回 disposer')
@@ -337,7 +393,7 @@ export function apply(ctx, rawConfig, runtime = {}) {
337
393
  await unregister()
338
394
  return
339
395
  }
340
- release = unregister
396
+ releases = [unregister]
341
397
  state.definition = definition
342
398
  state.preset = {
343
399
  id: definition.id,
@@ -346,6 +402,7 @@ export function apply(ctx, rawConfig, runtime = {}) {
346
402
  }
347
403
  state.registration = 'active'
348
404
  state.error = null
405
+ bumpState()
349
406
  }
350
407
 
351
408
  const switchTo = async (probe) => {
@@ -373,18 +430,18 @@ export function apply(ctx, rawConfig, runtime = {}) {
373
430
  checked: probe?.checked === true,
374
431
  ...(probe?.timedOut ? { registryTimedOut: true } : {}),
375
432
  }
433
+ bumpState()
376
434
  return
377
435
  }
378
436
  // effective/fallback 相同但 reason 变了也要重新发布:description/persona 带着回退原因。
379
437
  state.registration = 'switching'
380
- const previous = release
381
- release = undefined
382
- if (previous) await previous()
438
+ bumpState()
439
+ await releaseAll()
383
440
  await publish(probe)
384
441
  }
385
442
 
386
443
  const scheduleVerification = () => {
387
- const needsRecheck = settings.developMode !== 'standard' || state.presets.checked !== true
444
+ const needsRecheck = state.mode?.fallback === true || state.presets.checked !== true
388
445
  if (!needsRecheck || delayMs <= 0) return
389
446
  timer = setTimeout(() => {
390
447
  timer = undefined
@@ -399,7 +456,7 @@ export function apply(ctx, rawConfig, runtime = {}) {
399
456
  if (typeof timer?.unref === 'function') timer.unref()
400
457
  }
401
458
 
402
- // 卸载:先标记,等队列收敛,再交还动态 preset 的 disposer。
459
+ // 卸载:先标记,等队列收敛,再按逆序交还动态 preset 的 disposer。
403
460
  child.effect(
404
461
  () =>
405
462
  async () => {
@@ -407,16 +464,9 @@ export function apply(ctx, rawConfig, runtime = {}) {
407
464
  if (timer !== undefined) clearTimeout(timer)
408
465
  timer = undefined
409
466
  await queue.catch(() => {})
410
- const current = release
411
- release = undefined
412
- if (current) {
413
- try {
414
- await current()
415
- } catch (error) {
416
- log('warn', `释放动态 preset 失败:${String(error?.message ?? error)}`)
417
- }
418
- }
467
+ await releaseAll()
419
468
  state.registration = 'disposed'
469
+ bumpState()
420
470
  },
421
471
  'dev-plan-presets: dynamic preset',
422
472
  )
@@ -453,6 +503,7 @@ export function apply(ctx, rawConfig, runtime = {}) {
453
503
  if (!llm || typeof llm.listProviders !== 'function') {
454
504
  modelCatalog = { checked: false, providers: [], failures: [], error: 'llm-unavailable' }
455
505
  modelCatalogUpdatedAt = now()
506
+ bumpState()
456
507
  return modelCatalog
457
508
  }
458
509
  let providers
@@ -466,6 +517,7 @@ export function apply(ctx, rawConfig, runtime = {}) {
466
517
  error: String(error?.message ?? error),
467
518
  }
468
519
  modelCatalogUpdatedAt = now()
520
+ bumpState()
469
521
  return modelCatalog
470
522
  }
471
523
  const normalized = (Array.isArray(providers) ? providers : [])
@@ -508,6 +560,7 @@ export function apply(ctx, rawConfig, runtime = {}) {
508
560
  .map((entry) => ({ provider: entry.provider, message: entry.failure }))
509
561
  modelCatalog = { checked: true, providers: out, failures, error: null }
510
562
  modelCatalogUpdatedAt = now()
563
+ bumpState()
511
564
  return modelCatalog
512
565
  })()
513
566
  .catch((error) => {
@@ -519,6 +572,7 @@ export function apply(ctx, rawConfig, runtime = {}) {
519
572
  error: String(error?.message ?? error).slice(0, 200),
520
573
  }
521
574
  modelCatalogUpdatedAt = now()
575
+ bumpState()
522
576
  return modelCatalog
523
577
  })
524
578
  .finally(() => {
@@ -540,11 +594,14 @@ export function apply(ctx, rawConfig, runtime = {}) {
540
594
 
541
595
  const buildState = async () => ({
542
596
  version,
597
+ stateVersion,
598
+ stateTag: currentStateTag(),
543
599
  config: state.settings,
544
- route: routeOf(state.settings),
600
+ route: cachedRoute,
545
601
  requestedMode: state.mode?.requested ?? settings.developMode,
546
602
  effectiveMode: state.mode?.effective ?? null,
547
603
  modeName: state.mode?.name ?? null,
604
+ internalPresets: { ...state.internalPresets },
548
605
  fallback: {
549
606
  active: state.mode?.fallback === true,
550
607
  reason: state.mode?.reason ?? '',
@@ -553,6 +610,7 @@ export function apply(ctx, rawConfig, runtime = {}) {
553
610
  checked: state.presets.checked === true,
554
611
  timedOut: state.presets.timedOut === true,
555
612
  selfId: PRESET_ID,
613
+ disabledIds: INTERNAL_PRESET_IDS,
556
614
  rows: state.presets.rows,
557
615
  ...(typeof state.presets.error === 'string' ? { error: state.presets.error } : {}),
558
616
  },
@@ -583,7 +641,18 @@ export function apply(ctx, rawConfig, runtime = {}) {
583
641
  return
584
642
  }
585
643
  try {
586
- send(res, 200, await buildState())
644
+ const snapshot = modelCatalogSnapshot()
645
+ void snapshot
646
+ const etag = `"${currentStateTag()}"`
647
+ if (etagMatches(req?.headers?.['if-none-match'], etag)) {
648
+ res.writeHead(304, {
649
+ etag,
650
+ 'cache-control': 'no-store',
651
+ })
652
+ res.end()
653
+ return
654
+ }
655
+ send(res, 200, await buildState(), { etag })
587
656
  } catch (error) {
588
657
  send(res, 500, { error: String(error?.message ?? error), code: 'internal-error' })
589
658
  }
@@ -680,7 +749,26 @@ export function apply(ctx, rawConfig, runtime = {}) {
680
749
  },
681
750
  })
682
751
 
752
+ const prewarmEnabled = runtime?.prewarmModelCatalog !== false
753
+ const prewarmDelayMs = Number.isFinite(runtime?.prewarmDelayMs)
754
+ ? Math.max(0, Number(runtime.prewarmDelayMs))
755
+ : 300
756
+ let prewarmTimer
757
+ if (prewarmEnabled) {
758
+ prewarmTimer = setTimeout(() => {
759
+ prewarmTimer = undefined
760
+ if (now() - modelCatalogUpdatedAt >= MODEL_CATALOG_TTL_MS) {
761
+ void refreshModelCatalog()
762
+ }
763
+ }, prewarmDelayMs)
764
+ if (typeof prewarmTimer?.unref === 'function') prewarmTimer.unref()
765
+ }
766
+
683
767
  yield () => {
768
+ if (prewarmTimer !== undefined) {
769
+ clearTimeout(prewarmTimer)
770
+ prewarmTimer = undefined
771
+ }
684
772
  try {
685
773
  offState()
686
774
  } catch {
package/locale/en.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "Development planning & delivery Mode",
4
- "description": "An expensive main model that only plans, dispatches and reviews: recon/review gather facts, scribe writes documents, and develop implements and reports back directly. standard is the default with no extra dependency; the development setup can also be chosen from presets installed on the host (such as deep-ptc), and the provider/model come from the host catalog. The model guard governs only this session's subagents by default and never the main session.",
4
+ "description": "An expensive main model for planning, delegation, review, and controlled micro-actions: recon/review/scribe run on standard using compact subagent-only templates embedded in the main preset (without cluttering the preset picker), and develop handles full implementation and Shell/tests. Main-session tool mode defaults to ask-edit (small read-only checks + local edits only after explicit user approval, never Shell), with readonly/none options and a soft step warning threshold. standard is the default with no extra dependency; the development setup can also be chosen from host presets (such as deep-ptc), while the model guard governs only this session's subagents by default and never the main session.",
5
5
  "detail": "detail.md"
6
6
  }
7
7
  }
package/locale/zh.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "开发规划与交付模式",
4
- "description": "昂贵主模型只做规划、派工与复核:查证/遍历交给 recon、review,文档落盘交给 scribe,实际施工交给 develop 并直接向主窗口汇报。施工方式默认 standard(零额外依赖),也可从宿主已安装的预设(如 deep-ptc)中选择;服务商与模型从宿主目录联动选择;模型守门默认只管本会话派出的子代理,主会话永不守门。",
4
+ "description": "昂贵主模型负责规划、派工、复核与受控微实操:recon/review/scribe 运行于 standard,并将紧凑版子代理约束融入主预设且标注仅给子代理用(不在预设列表暴露多余选项);实际施工与 Shell/测试交给 develop 并直接向主窗口汇报。主窗工具权限默认 ask-edit(小范围只读核验 + 经用户当轮明确同意后局部微改,永不挂 Shell),也可切为 readonly 或 none,并配步数提醒;施工方式默认 standard(零额外依赖),也可从宿主已安装的预设(如 deep-ptc)中选择;模型守门默认只管本会话派出的子代理,主会话永不守门。",
5
5
  "detail": "detail.md"
6
6
  }
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-dev-plan-presets",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "type": "module",