dsh-chief 1.4.0 → 1.5.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/CHANGELOG.md +42 -0
- package/README.en.md +66 -50
- package/README.md +67 -50
- package/api-routes.js +165 -3
- package/archive-core.js +136 -8
- package/archive-dossiers.js +450 -20
- package/archive-precipitated.js +115 -36
- package/auto-continue.js +13 -5
- package/board-actions.js +59 -4
- package/board-schema.js +1 -1
- package/chief-approvals.js +176 -11
- package/chief-archives.js +157 -30
- package/chief-commands.js +565 -101
- package/chief-models.js +158 -28
- package/chief-review.js +211 -70
- package/chief-state.js +362 -32
- package/chief-view.js +17 -14
- package/client.js +3744 -2207
- package/digest.js +18 -9
- package/model-tools.js +15 -5
- package/package.json +9 -4
- package/runtime-hooks.js +115 -12
- package/subagent-runtime.js +257 -1
package/chief-models.js
CHANGED
|
@@ -10,6 +10,8 @@ import {
|
|
|
10
10
|
SUMMARY_MAX_TOKENS,
|
|
11
11
|
SUMMARY_RETRY_MAX_TOKENS,
|
|
12
12
|
clamp,
|
|
13
|
+
normalizeThinkingEffort,
|
|
14
|
+
resolveAlignedModelEffort,
|
|
13
15
|
resolveWorkspaceConfig,
|
|
14
16
|
loadChiefState,
|
|
15
17
|
mutateChiefState,
|
|
@@ -180,6 +182,75 @@ function profileDefaultModelRef(runtime) {
|
|
|
180
182
|
return ''
|
|
181
183
|
}
|
|
182
184
|
|
|
185
|
+
const modelEffortCache = new Map()
|
|
186
|
+
|
|
187
|
+
export function decideAdaptiveChiefEffort({
|
|
188
|
+
reasonKind = '',
|
|
189
|
+
userText = '',
|
|
190
|
+
isBlankContext = false,
|
|
191
|
+
tactical = {},
|
|
192
|
+
} = {}) {
|
|
193
|
+
const rk = String(reasonKind || '').trim().toLowerCase()
|
|
194
|
+
const txt = String(userText || '').trim()
|
|
195
|
+
|
|
196
|
+
if (rk === 'chat_summary' || rk === 'dream_roam' || rk === 'quick_status' || rk === 'auto_summary') {
|
|
197
|
+
return 'off'
|
|
198
|
+
}
|
|
199
|
+
if (rk === 'hazard_diagnosis' || rk === 'multi_wall_collision') {
|
|
200
|
+
return 'xhigh'
|
|
201
|
+
}
|
|
202
|
+
if (
|
|
203
|
+
rk === 'blank_explore'
|
|
204
|
+
|| rk === 'wall_blocked'
|
|
205
|
+
|| rk === 'strong_intervention'
|
|
206
|
+
|| rk === 'precipitate'
|
|
207
|
+
|| rk === 'distill'
|
|
208
|
+
|| rk === 'craft_wall'
|
|
209
|
+
|| isBlankContext === true
|
|
210
|
+
) {
|
|
211
|
+
if (tactical && tactical.intervention && /(?:架构|根因|死锁|并发|重构|安全审计)/.test(txt)) {
|
|
212
|
+
return 'xhigh'
|
|
213
|
+
}
|
|
214
|
+
return 'high'
|
|
215
|
+
}
|
|
216
|
+
if (txt && /(?:深度|全面|彻底|根因|重构|架构|死锁|并发|安全审计|复盘|仔细想|好好想|正则墙|物理墙)/.test(txt)) {
|
|
217
|
+
return 'high'
|
|
218
|
+
}
|
|
219
|
+
if (rk === 'ask_chat' && txt && txt.length <= 28 && /^(?:在吗|进度|到哪一步|怎么样|状态|你好|看看)/.test(txt)) {
|
|
220
|
+
return 'low'
|
|
221
|
+
}
|
|
222
|
+
return 'medium'
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export async function resolveRouteCapabilities(llm, provider, model) {
|
|
226
|
+
const ref = provider && model ? `${provider}/${model}` : ''
|
|
227
|
+
if (ref && modelEffortCache.has(ref)) {
|
|
228
|
+
const cached = modelEffortCache.get(ref)
|
|
229
|
+
if (Date.now() - cached.at < CATALOG_TTL_MS * 6) return cached.data
|
|
230
|
+
}
|
|
231
|
+
const data = { defaultMaxTokens: 0, efforts: [], defaultEffort: '' }
|
|
232
|
+
try {
|
|
233
|
+
if (llm && typeof llm.resolveModelInfo === 'function' && provider && model) {
|
|
234
|
+
const info = await llm.resolveModelInfo(provider, model)
|
|
235
|
+
if (typeof info?.defaultMaxTokens === 'number' && info.defaultMaxTokens > 0) {
|
|
236
|
+
data.defaultMaxTokens = info.defaultMaxTokens
|
|
237
|
+
}
|
|
238
|
+
if (Array.isArray(info?.reasoning?.efforts)) {
|
|
239
|
+
data.efforts = info.reasoning.efforts.map(e => (
|
|
240
|
+
typeof e === 'string'
|
|
241
|
+
? { id: e, name: e }
|
|
242
|
+
: { id: String(e?.id || ''), name: String(e?.name || e?.id || ''), description: String(e?.description || '') }
|
|
243
|
+
)).filter(e => e.id)
|
|
244
|
+
}
|
|
245
|
+
if (typeof info?.reasoning?.defaultEffort === 'string') {
|
|
246
|
+
data.defaultEffort = info.reasoning.defaultEffort
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
} catch {}
|
|
250
|
+
if (ref) modelEffortCache.set(ref, { at: Date.now(), data })
|
|
251
|
+
return data
|
|
252
|
+
}
|
|
253
|
+
|
|
183
254
|
export async function listChiefModels(deps, fresh = false, sessionId = '') {
|
|
184
255
|
const llm = deps.getLlm ? deps.getLlm() : null
|
|
185
256
|
const runtime = deps.runtime
|
|
@@ -297,6 +368,16 @@ export async function listChiefModels(deps, fresh = false, sessionId = '') {
|
|
|
297
368
|
|
|
298
369
|
const picked = pickRouteFromItems(items, selectedRef, followRef, deps, sessionId, registeredProviderIds)
|
|
299
370
|
const resolvedRef = (picked && picked.ref) || selectedRef || followRef || ''
|
|
371
|
+
let supportedEfforts = []
|
|
372
|
+
let defaultEffort = ''
|
|
373
|
+
if (resolvedRef) {
|
|
374
|
+
const parsedResolved = splitModelRef(resolvedRef)
|
|
375
|
+
if (parsedResolved) {
|
|
376
|
+
const caps = await resolveRouteCapabilities(llm, parsedResolved.provider, parsedResolved.model)
|
|
377
|
+
supportedEfforts = caps.efforts || []
|
|
378
|
+
defaultEffort = caps.defaultEffort || ''
|
|
379
|
+
}
|
|
380
|
+
}
|
|
300
381
|
return {
|
|
301
382
|
available: items.length > 0 || Boolean(resolvedRef),
|
|
302
383
|
selectedRef,
|
|
@@ -305,6 +386,8 @@ export async function listChiefModels(deps, fresh = false, sessionId = '') {
|
|
|
305
386
|
defaultRef: followRef,
|
|
306
387
|
resolvedRef,
|
|
307
388
|
resolvedLabel: formatChiefModelLabel(resolvedRef, items, rawProviders, true),
|
|
389
|
+
supportedEfforts,
|
|
390
|
+
defaultEffort,
|
|
308
391
|
models: items,
|
|
309
392
|
}
|
|
310
393
|
}
|
|
@@ -397,21 +480,11 @@ function pickRouteFromItems(items, selectedRef, followRef, deps, sessionId, regi
|
|
|
397
480
|
return queue[0] || null
|
|
398
481
|
}
|
|
399
482
|
|
|
400
|
-
async function callOneRoute(llm, route, system, userText, maxTokens = SUMMARY_MAX_TOKENS, sessionId = '', imageBlocks = []) {
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
const info = await llm.resolveModelInfo(route.provider, route.model)
|
|
406
|
-
if (typeof info?.defaultMaxTokens === 'number' && info.defaultMaxTokens > 0) {
|
|
407
|
-
modelDefaultMaxTokens = info.defaultMaxTokens
|
|
408
|
-
}
|
|
409
|
-
const efforts = info?.reasoning?.efforts
|
|
410
|
-
if (Array.isArray(efforts) && efforts.length > 0) {
|
|
411
|
-
effort = efforts.some(e => e.id === 'off') ? 'off' : efforts[0]?.id
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
} catch {}
|
|
483
|
+
async function callOneRoute(llm, route, system, userText, maxTokens = SUMMARY_MAX_TOKENS, sessionId = '', imageBlocks = [], desiredEffort = 'medium') {
|
|
484
|
+
const caps = await resolveRouteCapabilities(llm, route.provider, route.model)
|
|
485
|
+
const modelDefaultMaxTokens = caps.defaultMaxTokens || 0
|
|
486
|
+
const efforts = Array.isArray(caps.efforts) ? caps.efforts : []
|
|
487
|
+
const effort = resolveAlignedModelEffort(desiredEffort, efforts)
|
|
415
488
|
|
|
416
489
|
const targetBudget = Math.max(Number(maxTokens) || 0, SUMMARY_MAX_TOKENS)
|
|
417
490
|
const firstBudget = modelDefaultMaxTokens ? Math.min(modelDefaultMaxTokens, targetBudget) : targetBudget
|
|
@@ -450,7 +523,7 @@ async function callOneRoute(llm, route, system, userText, maxTokens = SUMMARY_MA
|
|
|
450
523
|
.map(b => b.text)
|
|
451
524
|
.join('\n')
|
|
452
525
|
.trim()
|
|
453
|
-
return { text, finishKind: finish?.kind || '', modelRef: route.ref }
|
|
526
|
+
return { text, finishKind: finish?.kind || '', modelRef: route.ref, thinkingEffort: effort || 'none' }
|
|
454
527
|
}
|
|
455
528
|
|
|
456
529
|
// Pure standalone fallback stream reader (for unit tests / lightweight hosts)
|
|
@@ -472,18 +545,18 @@ async function callOneRoute(llm, route, system, userText, maxTokens = SUMMARY_MA
|
|
|
472
545
|
}
|
|
473
546
|
}
|
|
474
547
|
}
|
|
475
|
-
return { text: parts.join('').trim(), finishKind, modelRef: route.ref }
|
|
548
|
+
return { text: parts.join('').trim(), finishKind, modelRef: route.ref, thinkingEffort: effort || 'none' }
|
|
476
549
|
}
|
|
477
550
|
|
|
478
|
-
let lastRes = { text: '', finishKind: '', modelRef: route.ref }
|
|
551
|
+
let lastRes = { text: '', finishKind: '', modelRef: route.ref, thinkingEffort: effort || 'none' }
|
|
479
552
|
for (let i = 0; i < budgets.length; i += 1) {
|
|
480
553
|
const res = await runOnce(budgets[i])
|
|
481
554
|
lastRes = res
|
|
482
555
|
if (res.text && res.finishKind !== 'max-tokens') {
|
|
483
|
-
return { text: res.text, modelRef: res.modelRef }
|
|
556
|
+
return { text: res.text, modelRef: res.modelRef, thinkingEffort: res.thinkingEffort }
|
|
484
557
|
}
|
|
485
558
|
}
|
|
486
|
-
return { text: lastRes.text, modelRef: lastRes.modelRef }
|
|
559
|
+
return { text: lastRes.text, modelRef: lastRes.modelRef, thinkingEffort: lastRes.thinkingEffort }
|
|
487
560
|
}
|
|
488
561
|
|
|
489
562
|
async function filterVisionRoutes(llm, queue) {
|
|
@@ -515,14 +588,51 @@ export async function callChiefLlm(deps, {
|
|
|
515
588
|
maxTokens = SUMMARY_MAX_TOKENS,
|
|
516
589
|
imageBlocks = [],
|
|
517
590
|
allowTextFallbackOnVisionMiss = false,
|
|
591
|
+
reasonKind = '',
|
|
592
|
+
userText = '',
|
|
593
|
+
isBlankContext = false,
|
|
594
|
+
tactical = null,
|
|
595
|
+
effortOverride = '',
|
|
518
596
|
}) {
|
|
519
597
|
const safeImages = Array.isArray(imageBlocks) ? imageBlocks : []
|
|
598
|
+
const rootSid = (deps && deps.resolveRootSessionId ? deps.resolveRootSessionId(sessionId) : '') || String(sessionId || '').trim()
|
|
599
|
+
const st = loadChiefState()
|
|
600
|
+
const effCfg = resolveWorkspaceConfig(st, rootSid)
|
|
601
|
+
const cfgEffort = normalizeThinkingEffort(effortOverride || effCfg.thinkingEffort || 'auto')
|
|
602
|
+
const thinkingEffortMode = cfgEffort === 'auto' ? 'auto' : 'manual'
|
|
603
|
+
const desiredEffort = cfgEffort === 'auto'
|
|
604
|
+
? decideAdaptiveChiefEffort({
|
|
605
|
+
reasonKind,
|
|
606
|
+
userText: userText || prompt,
|
|
607
|
+
isBlankContext,
|
|
608
|
+
tactical: tactical || effCfg.tacticalModes || {},
|
|
609
|
+
})
|
|
610
|
+
: cfgEffort
|
|
611
|
+
|
|
520
612
|
if (deps && typeof deps.callLlmOverride === 'function') {
|
|
521
|
-
|
|
613
|
+
const overrideRes = await deps.callLlmOverride({
|
|
614
|
+
sessionId,
|
|
615
|
+
system,
|
|
616
|
+
prompt,
|
|
617
|
+
maxTokens,
|
|
618
|
+
imageBlocks: safeImages,
|
|
619
|
+
allowTextFallbackOnVisionMiss,
|
|
620
|
+
reasonKind,
|
|
621
|
+
desiredEffort,
|
|
622
|
+
thinkingEffortMode,
|
|
623
|
+
})
|
|
624
|
+
if (overrideRes && typeof overrideRes === 'object') {
|
|
625
|
+
return {
|
|
626
|
+
thinkingEffort: overrideRes.thinkingEffort || desiredEffort,
|
|
627
|
+
thinkingEffortMode: overrideRes.thinkingEffortMode || thinkingEffortMode,
|
|
628
|
+
...overrideRes,
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
return overrideRes
|
|
522
632
|
}
|
|
523
633
|
const llm = deps.getLlm ? deps.getLlm() : null
|
|
524
634
|
if (!llm || typeof llm.stream !== 'function') {
|
|
525
|
-
return { ok: false, error: '当前环境未挂载 LLM 服务' }
|
|
635
|
+
return { ok: false, error: '当前环境未挂载 LLM 服务', thinkingEffort: desiredEffort, thinkingEffortMode }
|
|
526
636
|
}
|
|
527
637
|
const catalog = await listChiefModels(deps, false, sessionId)
|
|
528
638
|
const regSet = typeof llm.listProviders === 'function'
|
|
@@ -530,7 +640,7 @@ export async function callChiefLlm(deps, {
|
|
|
530
640
|
: null
|
|
531
641
|
const baseQueue = buildRouteQueue(catalog.models, catalog.selectedRef, catalog.followRef || catalog.defaultRef, deps, sessionId, regSet)
|
|
532
642
|
if (!baseQueue.length) {
|
|
533
|
-
return { ok: false, error: '未找到可用的参谋长模型,请在 DSH 设置中配置模型供应商' }
|
|
643
|
+
return { ok: false, error: '未找到可用的参谋长模型,请在 DSH 设置中配置模型供应商', thinkingEffort: desiredEffort, thinkingEffortMode }
|
|
534
644
|
}
|
|
535
645
|
|
|
536
646
|
let queue = baseQueue
|
|
@@ -548,6 +658,8 @@ export async function callChiefLlm(deps, {
|
|
|
548
658
|
return {
|
|
549
659
|
ok: false,
|
|
550
660
|
error: '当前参谋长及备选模型均不支持图片输入(仅纯文本),请在右上角切换支持视觉的多模态模型(如 Gemini / Claude / GPT-4o / Qwen-VL 等)后再试。',
|
|
661
|
+
thinkingEffort: desiredEffort,
|
|
662
|
+
thinkingEffortMode,
|
|
551
663
|
}
|
|
552
664
|
}
|
|
553
665
|
}
|
|
@@ -555,22 +667,40 @@ export async function callChiefLlm(deps, {
|
|
|
555
667
|
let lastError = '模型返回内容为空'
|
|
556
668
|
for (const route of queue.slice(0, 4)) {
|
|
557
669
|
try {
|
|
558
|
-
const res = await callOneRoute(llm, route, system, prompt, maxTokens, sessionId, sendImages)
|
|
559
|
-
if (res.text)
|
|
670
|
+
const res = await callOneRoute(llm, route, system, prompt, maxTokens, sessionId, sendImages, desiredEffort)
|
|
671
|
+
if (res.text) {
|
|
672
|
+
return {
|
|
673
|
+
ok: true,
|
|
674
|
+
text: res.text,
|
|
675
|
+
modelRef: res.modelRef,
|
|
676
|
+
degradedToTextOnly,
|
|
677
|
+
thinkingEffort: res.thinkingEffort || desiredEffort,
|
|
678
|
+
thinkingEffortMode,
|
|
679
|
+
}
|
|
680
|
+
}
|
|
560
681
|
lastError = `${route.ref} 返回内容为空`
|
|
561
682
|
markRouteFailure(route, new Error(lastError))
|
|
562
683
|
} catch (err) {
|
|
563
684
|
lastError = String(err && err.message ? err.message : err)
|
|
564
685
|
if (sendImages.length > 0 && allowTextFallbackOnVisionMiss) {
|
|
565
686
|
try {
|
|
566
|
-
const textRes = await callOneRoute(llm, route, system, prompt, maxTokens, sessionId, [])
|
|
567
|
-
if (textRes.text)
|
|
687
|
+
const textRes = await callOneRoute(llm, route, system, prompt, maxTokens, sessionId, [], desiredEffort)
|
|
688
|
+
if (textRes.text) {
|
|
689
|
+
return {
|
|
690
|
+
ok: true,
|
|
691
|
+
text: textRes.text,
|
|
692
|
+
modelRef: textRes.modelRef,
|
|
693
|
+
degradedToTextOnly: true,
|
|
694
|
+
thinkingEffort: textRes.thinkingEffort || desiredEffort,
|
|
695
|
+
thinkingEffortMode,
|
|
696
|
+
}
|
|
697
|
+
}
|
|
568
698
|
} catch {}
|
|
569
699
|
}
|
|
570
700
|
markRouteFailure(route, err)
|
|
571
701
|
}
|
|
572
702
|
}
|
|
573
|
-
return { ok: false, error: lastError, degradedToTextOnly }
|
|
703
|
+
return { ok: false, error: lastError, degradedToTextOnly, thinkingEffort: desiredEffort, thinkingEffortMode }
|
|
574
704
|
}
|
|
575
705
|
|
|
576
706
|
/* -------------------------------------------------------------------------- */
|