dsh-progress-union 0.7.8 → 0.8.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 +30 -0
- package/README.md +36 -4
- package/client.js +129 -58
- package/dsh.plugin.json +1 -1
- package/index.js +265 -68
- package/package.json +1 -1
- package/test/client.test.mjs +66 -3
- package/test/ops.test.mjs +239 -39
package/index.js
CHANGED
|
@@ -93,9 +93,22 @@ export const Config = z.object({
|
|
|
93
93
|
}).default({}),
|
|
94
94
|
// v0.7.0 R4:任务板重大(结构性)变更提醒落输入队列。
|
|
95
95
|
notifyMajorChanges: z.boolean().default(true).volatile(),
|
|
96
|
-
// v0.7.0 R3:侧边栏 LLM
|
|
96
|
+
// v0.7.0 R3:侧边栏 LLM 任务操作面(整块开关)。
|
|
97
|
+
// v0.8.0:介入范围限定——只有链上(主路由 + ops.fallbacks)显式写出的
|
|
98
|
+
// provider/model 才能动板。链为空即 403,不再悄悄沿用宿主主模型烧高价 token。
|
|
97
99
|
ops: z.object({
|
|
98
100
|
enabled: z.boolean().default(true).volatile(),
|
|
101
|
+
// 主路由(钉定才准介入):两者都必填才算配好;走宿主已注册渠道(registered)。
|
|
102
|
+
routeProvider: z.string().default('').volatile(),
|
|
103
|
+
routeModel: z.string().default('').volatile(),
|
|
104
|
+
// 本地优先:只把按名字判定的本地候选排到链首,不参与裁决、不删条目。
|
|
105
|
+
preferLocal: z.boolean().default(true).volatile(),
|
|
106
|
+
// 有序降级链(每条各享全额 timeoutMs;与主路由同 provider+model 的条目剔除)。
|
|
107
|
+
// 数组不进设置表单(宿主表单不渲染数组),真值走 cordis.patch.yml。
|
|
108
|
+
fallbacks: z.array(z.object({
|
|
109
|
+
provider: z.string().default(''),
|
|
110
|
+
model: z.string().default(''),
|
|
111
|
+
})).default([]),
|
|
99
112
|
}).default({}),
|
|
100
113
|
})
|
|
101
114
|
|
|
@@ -661,7 +674,11 @@ function resultDigest(text, failed) {
|
|
|
661
674
|
const OPS_MAX_ITEMS = 60
|
|
662
675
|
const OPS_MAX_TITLE = 180
|
|
663
676
|
const OPS_MAX_CHANGES = 8
|
|
677
|
+
const OPS_MAX_ATTEMPTS = 3
|
|
664
678
|
const OPS_KINDS = new Set(['refine', 'mutate', 'ask', 'validate'])
|
|
679
|
+
const OPS_CHANGE_KINDS = new Set(['add', 'edit', 'remove'])
|
|
680
|
+
// edit 至少要动这一个字段,否则这条改动落下去什么都没变(模型爱犯的空转)。
|
|
681
|
+
const OPS_EDIT_FIELDS = ['title', 'status', 'percent', 'current', 'next', 'note', 'order']
|
|
665
682
|
// R4:只认这三类结构性变更(增/删/排序)——它们会让「板上第几项在做什么」整体位移。
|
|
666
683
|
const MAJOR_CHANGE_TAG = 'progress-major-change'
|
|
667
684
|
const STRUCTURAL_KINDS = new Set(['add', 'remove', 'order'])
|
|
@@ -728,34 +745,154 @@ function validateBoard(input) {
|
|
|
728
745
|
return { ok: errors.length === 0, count: items.length, errors, warnings }
|
|
729
746
|
}
|
|
730
747
|
|
|
731
|
-
|
|
748
|
+
/**
|
|
749
|
+
* 校验辅助模型「这一次的输出」吃不吃得下 —— 与 validateBoard 分工不同:
|
|
750
|
+
* validateBoard 管板数据本身合不合法,validateProposal 管模型给回来的形状,
|
|
751
|
+
* 它的 errors 就是打回时要逐条喂回去的话术。绝不抛错。
|
|
752
|
+
* 拦下:非对象 / refine-mutate 缺 changes 数组 / 条目不是对象 / kind 非枚举 /
|
|
753
|
+
* edit-remove 指认板上没有的 id / add 缺 title 或 title 过长 / edit 空转 /
|
|
754
|
+
* status 非枚举 / percent 越界 / order 非数字 / ask 没给 answer。
|
|
755
|
+
* 不拦(走截断或丢弃):条数超 OPS_MAX_CHANGES(截断后仍可部分交付)、
|
|
756
|
+
* ask 硬塞 changes(路由丢弃,不改板就算通过)。
|
|
757
|
+
*/
|
|
758
|
+
function validateProposal(state, proposal, op) {
|
|
759
|
+
const errors = []
|
|
760
|
+
if (!isObject(proposal)) {
|
|
761
|
+
return { ok: false, errors: ['输出不是可解析的 JSON 对象(只许输出一个对象,不要解释或代码围栏)'] }
|
|
762
|
+
}
|
|
763
|
+
const answer = typeof proposal.answer === 'string' ? proposal.answer.trim() : ''
|
|
764
|
+
if (op === 'ask') {
|
|
765
|
+
if (!answer) errors.push('answer 必须是非空字符串(问询只回文本,不动板)')
|
|
766
|
+
return { ok: errors.length === 0, errors }
|
|
767
|
+
}
|
|
768
|
+
const raw = Array.isArray(proposal.changes)
|
|
769
|
+
? proposal.changes
|
|
770
|
+
: (isObject(proposal.board) && Array.isArray(proposal.board.changes) ? proposal.board.changes : null)
|
|
771
|
+
if (!raw) {
|
|
772
|
+
return { ok: false, errors: ['缺少 changes 数组(形状应为 {"thinking":"…","changes":[…],"answer":"…"})'] }
|
|
773
|
+
}
|
|
774
|
+
const items = state && Array.isArray(state.items) ? state.items : []
|
|
775
|
+
const byId = new Map(items.map((item) => [item.id, item]))
|
|
776
|
+
raw.slice(0, OPS_MAX_CHANGES).forEach((c, index) => {
|
|
777
|
+
const at = `第 ${index + 1} 条`
|
|
778
|
+
if (!isObject(c)) {
|
|
779
|
+
errors.push(`${at} 不是对象`)
|
|
780
|
+
return
|
|
781
|
+
}
|
|
782
|
+
const kind = String(c.kind || (c.id ? 'edit' : 'add')).toLowerCase()
|
|
783
|
+
if (!OPS_CHANGE_KINDS.has(kind)) {
|
|
784
|
+
errors.push(`${at} kind 非法:${c.kind}(合法值 add|edit|remove)`)
|
|
785
|
+
return
|
|
786
|
+
}
|
|
787
|
+
if (kind === 'add') {
|
|
788
|
+
const title = typeof c.title === 'string' ? c.title.trim() : ''
|
|
789
|
+
if (!title) errors.push(`${at} kind=add 缺少 title`)
|
|
790
|
+
else if (title.length > OPS_MAX_TITLE) errors.push(`${at} title 过长(${title.length} 字 >${OPS_MAX_TITLE})`)
|
|
791
|
+
} else if (!byId.has(String(c.id || ''))) {
|
|
792
|
+
errors.push(`${at} kind=${kind} 指认的 id 不在板上:${String(c.id || '(空)')}(只能用清单里给过的 id)`)
|
|
793
|
+
return
|
|
794
|
+
} else if (kind === 'edit' && !OPS_EDIT_FIELDS.some((field) => c[field] !== undefined && c[field] !== null && String(c[field]).trim() !== '')) {
|
|
795
|
+
errors.push(`${at} kind=edit 没有任何要改的字段`)
|
|
796
|
+
}
|
|
797
|
+
let status
|
|
798
|
+
if (c.status !== undefined && c.status !== null && String(c.status).trim() !== '') {
|
|
799
|
+
status = normalizeStatus(c.status)
|
|
800
|
+
if (status === undefined) errors.push(`${at} status 非法:${c.status}(合法值 todo|doing|done|blocked)`)
|
|
801
|
+
}
|
|
802
|
+
if (c.percent !== undefined && c.percent !== null) {
|
|
803
|
+
const pct = Number(c.percent)
|
|
804
|
+
if (!Number.isFinite(pct) || pct < 0 || pct > 100) errors.push(`${at} percent 越界:${c.percent}(应为 0-100)`)
|
|
805
|
+
}
|
|
806
|
+
if (c.order !== undefined && c.order !== null && !Number.isFinite(Number(c.order))) {
|
|
807
|
+
errors.push(`${at} order 不是数字:${c.order}`)
|
|
808
|
+
}
|
|
809
|
+
})
|
|
810
|
+
return { ok: errors.length === 0, errors }
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
// 打回时要重新要一次:把上一轮的不合规条目逐条贴回原提示之后。
|
|
814
|
+
function withOpsFeedback(prompt, errors) {
|
|
815
|
+
if (!Array.isArray(errors) || errors.length === 0) return prompt
|
|
816
|
+
return `${prompt}\n\n上一次输出不符合校验格式,逐条问题:\n${errors.map((line) => `- ${line}`).join('\n')}\n请重新只输出一个 JSON 对象(字段与格式同上),不要解释、不要代码围栏。`
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
// v0.8.0 介入范围限定:本地命名识别只用于排序与提示,**不参与裁决**。
|
|
820
|
+
// 裁决口径是白名单(ops.routeProvider/Model + ops.fallbacks),链外一律 403。
|
|
821
|
+
// 两条实际在用的本地路由都能命中:provider=local-35(LOCAL_NAME_RE)、
|
|
822
|
+
// model=qwen3.8-flash-iq2_xs(QUANT_RE)。
|
|
823
|
+
const LOCAL_NAME_RE = /(local|ollama|lm-?studio|llama\.cpp|vllm|gguf|npu|self[-_]?host|desktop)/i
|
|
824
|
+
const QUANT_RE = /(?:[:_-]|^)(?:iq[0-9][a-z0-9_]*|q[0-9](?:_[0-9])?(?:_[a-z0-9]+)?|awq|bnb|[48]bit)(?:[:_-]|$)/i
|
|
825
|
+
|
|
826
|
+
/** 该 provider/model 看上去是不是本地档(名字判定,不作裁决)。 */
|
|
827
|
+
function isLocalRouteName(provider, model) {
|
|
828
|
+
return LOCAL_NAME_RE.test(String(provider || '')) || QUANT_RE.test(String(model || ''))
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
/**
|
|
832
|
+
* 组装 ops 允许介入的路由链(纯决策,照 prime-memory buildRouteChain 的防御姿态):
|
|
833
|
+
* 主路由在前、回退条目按配置顺序在后;provider/model 任一缺失的条目剔除;
|
|
834
|
+
* 完全相同的 provider::model 只留第一条(注定失败的重复尝试不值得占位)。
|
|
835
|
+
* preferLocal=true 且链上同时有本地与云端候选时,把本地排到前面(只重排、不删)。
|
|
836
|
+
* 返回空链 = 未钉定,调用侧一律 403。
|
|
837
|
+
*/
|
|
838
|
+
function buildOpsChain(primary, fallbacks, preferLocal) {
|
|
839
|
+
const routes = []
|
|
840
|
+
const seen = new Set()
|
|
841
|
+
const push = (rawProvider, rawModel) => {
|
|
842
|
+
const provider = String(rawProvider || '').trim()
|
|
843
|
+
const model = String(rawModel || '').trim()
|
|
844
|
+
if (!provider || !model) return
|
|
845
|
+
const key = `${provider}::${model}`
|
|
846
|
+
if (seen.has(key)) return
|
|
847
|
+
seen.add(key)
|
|
848
|
+
routes.push({ provider, model, local: isLocalRouteName(provider, model) })
|
|
849
|
+
}
|
|
850
|
+
push(primary && primary.provider, primary && primary.model)
|
|
851
|
+
for (const entry of Array.isArray(fallbacks) ? fallbacks : []) {
|
|
852
|
+
push(entry && entry.provider, entry && entry.model)
|
|
853
|
+
}
|
|
854
|
+
if (preferLocal === true && routes.some((r) => r.local) && routes.some((r) => !r.local)) {
|
|
855
|
+
return routes.filter((r) => r.local).concat(routes.filter((r) => !r.local))
|
|
856
|
+
}
|
|
857
|
+
return routes
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
// ops 三路 system:严格 JSON、统一形状 `{thinking,changes,answer}`、最多 8 条改动。
|
|
732
861
|
// 只有 refine/mutate 会动板;ask 只回文本,模型若硬塞 changes 也会被路由丢掉。
|
|
862
|
+
// thinking 是给面板「思考区」看的一句话理由,不参与格式判定(缺了不打回)。
|
|
863
|
+
const OPS_JSON_SHAPE = '{"thinking":"<一句话说明你为什么这样改,与板同语言,≤200 字>",'
|
|
864
|
+
+ '"changes":[{"kind":"add|edit|remove","id"?:string,"title"?:string,"status"?:"todo|doing|done|blocked","percent"?:0-100,"current"?:string,"next"?:string,"order"?:number}],'
|
|
865
|
+
+ '"answer":"<一行结论,同语言>"}'
|
|
866
|
+
const OPS_STRICT_NOTE = ' Your output is checked line by line before it touches the board: every id must exist in the list given to you, '
|
|
867
|
+
+ 'kind must be add|edit|remove, status must be one of todo|doing|done|blocked, percent must be 0-100. '
|
|
868
|
+
+ 'If anything fails you get the exact reasons back and must output the object again.'
|
|
869
|
+
|
|
733
870
|
const OPS_REFINE_SYSTEM = 'You refine a user-facing task board so the work is easier to track. '
|
|
734
871
|
+ 'Given the board checklist and an optional focus item, split coarse items into smaller verifiable ones, '
|
|
735
872
|
+ 'give each a concrete title and (when known) current/next text. '
|
|
736
873
|
+ 'Rules: at most ' + OPS_MAX_CHANGES + ' changes; only ONE item may be doing; keep existing ids when editing; '
|
|
737
874
|
+ 'never invent completed work; never touch items outside the given board. '
|
|
738
875
|
+ 'Output strictly ONE JSON object: '
|
|
739
|
-
+
|
|
740
|
-
+ 'Respond with the JSON object only — no prose, no code fences.'
|
|
876
|
+
+ OPS_JSON_SHAPE + '.' + OPS_STRICT_NOTE
|
|
877
|
+
+ ' Respond with the JSON object only — no prose, no code fences.'
|
|
741
878
|
|
|
742
879
|
const OPS_MUTATE_SYSTEM = 'You apply one user instruction to a user-facing task board: add, edit, reorder or remove items. '
|
|
743
880
|
+ 'Rules: change only what the instruction asks for; at most ' + OPS_MAX_CHANGES + ' changes; use the ids given in the board for edit/remove; '
|
|
744
881
|
+ 'use "order" (0-based) to reorder; never invent completed work; if the instruction is not actionable on a task board, '
|
|
745
882
|
+ 'return zero changes and say why in the answer. '
|
|
746
883
|
+ 'Output strictly ONE JSON object: '
|
|
747
|
-
+
|
|
748
|
-
+ 'Respond with the JSON object only — no prose, no code fences.'
|
|
884
|
+
+ OPS_JSON_SHAPE + '.' + OPS_STRICT_NOTE
|
|
885
|
+
+ ' Respond with the JSON object only — no prose, no code fences.'
|
|
749
886
|
|
|
750
887
|
const OPS_ASK_SYSTEM = 'You answer ONE short question about a task board, using ONLY the checklist given to you. '
|
|
751
888
|
+ 'You must not change the board: always return an empty changes array. '
|
|
752
889
|
+ 'If the board does not contain the answer, say so plainly instead of guessing. '
|
|
753
890
|
+ 'Answer in the same language as the board, in at most 600 characters. '
|
|
754
|
-
+ 'Output strictly ONE JSON object: {"changes":[],"answer":"<text>"}. '
|
|
891
|
+
+ 'Output strictly ONE JSON object: {"thinking":"<你凭什么这么答,≤200 字>","changes":[],"answer":"<text>"}. '
|
|
755
892
|
+ 'Respond with the JSON object only — no prose, no code fences.'
|
|
756
893
|
|
|
757
894
|
// 纯解析函数导出(仅供 test/plan.test.mjs 单测;不在 dsh 契约面上,勿在插件间消费)。
|
|
758
|
-
export { parseChecklistMarkdown, parseSpecOutline, normalizeStatus, planDirCandidates, pickPlanDir, classifyDownload, parseProgress, unwrapAct, isDownloadItem, describeToolStep, glossCommand, resultDigest, validateBoard }
|
|
895
|
+
export { parseChecklistMarkdown, parseSpecOutline, normalizeStatus, planDirCandidates, pickPlanDir, classifyDownload, parseProgress, unwrapAct, isDownloadItem, describeToolStep, glossCommand, resultDigest, validateBoard, validateProposal, withOpsFeedback, isLocalRouteName, buildOpsChain }
|
|
759
896
|
|
|
760
897
|
const PROGRESS_POLICY = `## 进度板
|
|
761
898
|
progress_update 维护用户可见的实时进度板。每项含 title/status/percent/current/next/approach/note。
|
|
@@ -1534,7 +1671,7 @@ const DEFAULT_CONFIG = {
|
|
|
1534
1671
|
notifyMajorChanges: true,
|
|
1535
1672
|
// v0.7.0 R3:侧边栏 LLM 任务操作块。enabled=false 时 providers 面报 disabled、
|
|
1536
1673
|
// POST /ops 直接 403,客户端整块收起(不依赖 assistant 是否已配)。
|
|
1537
|
-
ops: { enabled: true },
|
|
1674
|
+
ops: { enabled: true, routeProvider: '', routeModel: '', preferLocal: true, fallbacks: [] },
|
|
1538
1675
|
// 辅助 LLM(审查/监视 + 槽位管理 + 轮次草案):
|
|
1539
1676
|
// mode: 'registered' 走宿主 llm.stream(选已注册 llm-pi-ai provider/model);
|
|
1540
1677
|
// 'direct' 走自建 OpenAI 兼容端点(baseUrl/apiKey/model);'' 关。
|
|
@@ -3302,71 +3439,88 @@ ${reason}。本回合开始前先用 progress_update 处理进度板:用户这
|
|
|
3302
3439
|
// 只复用既有辅助通道 callAssistant;不新开顶级标签、零新增依赖。
|
|
3303
3440
|
// ==========================================================================
|
|
3304
3441
|
|
|
3305
|
-
//
|
|
3306
|
-
//
|
|
3307
|
-
//
|
|
3442
|
+
// 介入范围(v0.8.0):候选**只来自配置白名单** —— ops.routeProvider/routeModel 为
|
|
3443
|
+
// 主路由,ops.fallbacks 为有序降级链。不再打宿主 llm.listProviders() 全量枚举:
|
|
3444
|
+
// 「任何注册模型都能动板」既烧钱又不可审计(prime-memory 同口径:部署上限与
|
|
3445
|
+
// 运行时选择分开,这里上限就是白名单本身)。providers 字段按 provider 聚合链上
|
|
3446
|
+
// 条目,形状与旧客户端兼容;链为空即 unconfigured。
|
|
3447
|
+
function opsChainOf() {
|
|
3448
|
+
return buildOpsChain(
|
|
3449
|
+
{ provider: cfg.ops.routeProvider, model: cfg.ops.routeModel },
|
|
3450
|
+
cfg.ops.fallbacks,
|
|
3451
|
+
cfg.ops.preferLocal,
|
|
3452
|
+
)
|
|
3453
|
+
}
|
|
3454
|
+
|
|
3308
3455
|
async function opsProviders() {
|
|
3309
3456
|
const a0 = liveAssistant()
|
|
3310
|
-
// ops.enabled=false
|
|
3311
|
-
// 直接报 disabled,客户端据此把操作块整体收起(而不是报错)。
|
|
3457
|
+
// ops.enabled=false:整块开关关掉,直接报 disabled,客户端据此把操作块整体收起。
|
|
3312
3458
|
if (cfg.ops.enabled !== true) {
|
|
3313
3459
|
return {
|
|
3314
3460
|
ok: true,
|
|
3315
3461
|
disabled: true,
|
|
3462
|
+
unconfigured: false,
|
|
3463
|
+
routes: [],
|
|
3316
3464
|
providers: [],
|
|
3317
3465
|
default: { provider: '', model: '' },
|
|
3466
|
+
host: { provider: String(a0.provider || ''), model: String(a0.model || '') },
|
|
3318
3467
|
configured: { mode: String(a0.mode || ''), provider: String(a0.provider || ''), model: String(a0.model || '') },
|
|
3319
3468
|
}
|
|
3320
3469
|
}
|
|
3321
|
-
const
|
|
3322
|
-
const
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
if (!p || typeof p !== 'object') continue
|
|
3327
|
-
const id = String(p.id ?? p.name ?? '').trim()
|
|
3328
|
-
if (!id) continue
|
|
3329
|
-
const models = (Array.isArray(p.models) ? p.models : [])
|
|
3330
|
-
.map((m) => (typeof m === 'string' ? { id: m, label: m }
|
|
3331
|
-
: (m && m.id ? { id: String(m.id), label: String(m.label ?? m.name ?? m.id) } : null)))
|
|
3332
|
-
.filter(Boolean)
|
|
3333
|
-
providers.push({ id, label: String(p.label ?? p.displayName ?? id), models })
|
|
3470
|
+
const chain = opsChainOf()
|
|
3471
|
+
const byProvider = new Map()
|
|
3472
|
+
for (const route of chain) {
|
|
3473
|
+
if (!byProvider.has(route.provider)) {
|
|
3474
|
+
byProvider.set(route.provider, { id: route.provider, label: route.provider, models: [], local: true })
|
|
3334
3475
|
}
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
}
|
|
3340
|
-
const
|
|
3341
|
-
const sel = isObject(selection) ? { provider: String(selection.provider ?? ''), model: String(selection.model ?? '') } : { provider: '', model: '' }
|
|
3476
|
+
const bucket = byProvider.get(route.provider)
|
|
3477
|
+
bucket.models.push({ id: route.model, label: route.model, local: route.local })
|
|
3478
|
+
// 同一 provider 下混了云端条目时不能整家标本地(命名只到 provider 粒度不够准)。
|
|
3479
|
+
if (route.local !== true) bucket.local = false
|
|
3480
|
+
}
|
|
3481
|
+
const head = chain.length > 0 ? chain[0] : null
|
|
3342
3482
|
return {
|
|
3343
3483
|
ok: true,
|
|
3344
3484
|
disabled: false,
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3485
|
+
// 链空 = 未钉定:客户端据此禁用按钮并给引导文案,而不是给一堆禁用下拉。
|
|
3486
|
+
unconfigured: chain.length === 0,
|
|
3487
|
+
routes: chain,
|
|
3488
|
+
providers: Array.from(byProvider.values()),
|
|
3489
|
+
default: head ? { provider: head.provider, model: head.model } : { provider: '', model: '' },
|
|
3490
|
+
// host 只作展示:面板要能说清「宿主主模型是 X,但 ops 不拿它动板」。
|
|
3491
|
+
host: { provider: String(a0.provider || ''), model: String(a0.model || '') },
|
|
3492
|
+
configured: {
|
|
3493
|
+
mode: chain.length > 0 ? 'registered' : String(a0.mode || ''),
|
|
3494
|
+
provider: head ? head.provider : '',
|
|
3495
|
+
model: head ? head.model : '',
|
|
3496
|
+
},
|
|
3348
3497
|
}
|
|
3349
3498
|
}
|
|
3350
3499
|
|
|
3351
|
-
//
|
|
3352
|
-
//
|
|
3353
|
-
|
|
3354
|
-
|
|
3500
|
+
// 选定这次动作用哪条路由(v0.8.0):面板给了 provider/model 就必须命中链上条目
|
|
3501
|
+
// (链外一律 403);没给就取链首。恒走宿主 registered —— ops 不再沿用 assistant
|
|
3502
|
+
// 的 mode,也不再用 direct 端点:白名单里的 provider 必须是宿主已注册渠道。
|
|
3503
|
+
function opsRouteChoice(body) {
|
|
3504
|
+
const chain = opsChainOf()
|
|
3505
|
+
if (chain.length === 0) return { chain, index: -1, route: null, args: null, error: 'unconfigured' }
|
|
3355
3506
|
const reqProvider = String(body && body.provider ? body.provider : '').trim()
|
|
3356
3507
|
const reqModel = String(body && body.model ? body.model : '').trim()
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3508
|
+
let index = 0
|
|
3509
|
+
if (reqProvider !== '' || reqModel !== '') {
|
|
3510
|
+
index = chain.findIndex((route) => (reqProvider === '' || route.provider === reqProvider)
|
|
3511
|
+
&& (reqModel === '' || route.model === reqModel))
|
|
3512
|
+
if (index < 0) return { chain, index: -1, route: null, args: null, error: 'off-chain' }
|
|
3513
|
+
}
|
|
3514
|
+
if (!llm || typeof llm.stream !== 'function') {
|
|
3515
|
+
return { chain, index, route: chain[index], args: null, error: 'no-llm' }
|
|
3516
|
+
}
|
|
3517
|
+
const route = chain[index]
|
|
3518
|
+
return {
|
|
3519
|
+
chain,
|
|
3520
|
+
index,
|
|
3521
|
+
route,
|
|
3522
|
+
args: { ...liveAssistant(), mode: 'registered', provider: route.provider, model: route.model, maxSlotChanges: OPS_MAX_CHANGES },
|
|
3368
3523
|
}
|
|
3369
|
-
return null
|
|
3370
3524
|
}
|
|
3371
3525
|
|
|
3372
3526
|
// 喂给模型的板必须带 id,否则它无法指认“edit/remove 哪一项”。
|
|
@@ -3453,7 +3607,8 @@ ${reason}。本回合开始前先用 progress_update 处理进度板:用户这
|
|
|
3453
3607
|
const question = text(body && body.question, 1200) || ''
|
|
3454
3608
|
const targetId = String(body && body.targetId ? body.targetId : '')
|
|
3455
3609
|
|
|
3456
|
-
// 校验是纯本地活:不进 LLM、不花 token
|
|
3610
|
+
// 校验是纯本地活:不进 LLM、不花 token。面板从 v0.7.9 起不再把它做成按钮
|
|
3611
|
+
// (体检随每次回答自动跑),但路由保留:外部消费者与单测仍能直接要一份体检结论。
|
|
3457
3612
|
if (op === 'validate') {
|
|
3458
3613
|
const v = validateBoard(state.items)
|
|
3459
3614
|
return {
|
|
@@ -3471,8 +3626,14 @@ ${reason}。本回合开始前先用 progress_update 处理进度板:用户这
|
|
|
3471
3626
|
if (op === 'mutate' && !question) badRequest('增删改操作需要一句指令')
|
|
3472
3627
|
if (op === 'ask' && !question) badRequest('问询需要一个问题')
|
|
3473
3628
|
|
|
3474
|
-
const
|
|
3475
|
-
if (
|
|
3629
|
+
const choice = opsRouteChoice(body)
|
|
3630
|
+
if (choice.error === 'unconfigured') {
|
|
3631
|
+
forbidden('ops 未钉定模型路由:请在「设置 → 进度板 → LLM 操作与队列提醒」填主路由的 provider/model,或在 cordis.patch.yml 配 ops.routeProvider / ops.routeModel 与 ops.fallbacks')
|
|
3632
|
+
}
|
|
3633
|
+
if (choice.error === 'off-chain') {
|
|
3634
|
+
forbidden(`所选模型不在 ops 允许范围内:${String(body && body.provider ? body.provider : '')}/${String(body && body.model ? body.model : '')}(链上只有 ${choice.chain.map((r) => `${r.provider}/${r.model}`).join('、')})`)
|
|
3635
|
+
}
|
|
3636
|
+
if (choice.error === 'no-llm') badRequest('宿主未暴露 llm.stream,ops 无法调用模型')
|
|
3476
3637
|
|
|
3477
3638
|
const cap = Math.max(Number(cfg.observer.maxItems) || 12, 24)
|
|
3478
3639
|
const lines = [
|
|
@@ -3494,28 +3655,57 @@ ${reason}。本回合开始前先用 progress_update 处理进度板:用户这
|
|
|
3494
3655
|
lines.push(`指令:${question}`)
|
|
3495
3656
|
}
|
|
3496
3657
|
const system = op === 'refine' ? OPS_REFINE_SYSTEM : (op === 'mutate' ? OPS_MUTATE_SYSTEM : OPS_ASK_SYSTEM)
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3658
|
+
// 两层重试(v0.8.0):内层是 0.7.9 的格式打回(同一条路由最多 OPS_MAX_ATTEMPTS 次,
|
|
3659
|
+
// 不合规就把逐条原因喂回去重新要);外层是路由降级 —— 一条路由传输失败即判死,
|
|
3660
|
+
// 切链上下一条(每条各享全额 timeoutMs,prime-memory ADR-0004 同语义);格式打回
|
|
3661
|
+
// 耗尽也切下一条。全链失败才 502,并把每条路由的失败原因汇总回去——
|
|
3662
|
+
// 「哪条路由为什么不行」是用户唯一能据此改配置的信号。
|
|
3663
|
+
const basePrompt = lines.join('\n')
|
|
3664
|
+
let proposal = null
|
|
3665
|
+
let served = null
|
|
3666
|
+
const failures = []
|
|
3667
|
+
for (let i = choice.index; i < choice.chain.length; i += 1) {
|
|
3668
|
+
const route = choice.chain[i]
|
|
3669
|
+
const a = { ...choice.args, provider: route.provider, model: route.model }
|
|
3670
|
+
let reject = null
|
|
3671
|
+
let attempts = 0
|
|
3672
|
+
let transport = ''
|
|
3673
|
+
while (attempts < OPS_MAX_ATTEMPTS) {
|
|
3674
|
+
attempts += 1
|
|
3675
|
+
let raw
|
|
3676
|
+
try {
|
|
3677
|
+
raw = await callAssistant({ system, user: withOpsFeedback(basePrompt, reject), a })
|
|
3678
|
+
} catch (err) {
|
|
3679
|
+
transport = err instanceof Error ? err.message : String(err)
|
|
3680
|
+
break
|
|
3681
|
+
}
|
|
3682
|
+
const parsed = parseProposal(raw)
|
|
3683
|
+
const check = validateProposal(state, parsed, op)
|
|
3684
|
+
if (check.ok) {
|
|
3685
|
+
proposal = parsed
|
|
3686
|
+
reject = null
|
|
3687
|
+
served = { route, index: i, attempts }
|
|
3688
|
+
break
|
|
3689
|
+
}
|
|
3690
|
+
reject = check.errors
|
|
3691
|
+
}
|
|
3692
|
+
if (proposal) break
|
|
3693
|
+
failures.push(`${route.provider}/${route.model}:${transport ? `调用失败(${transport})` : (reject || []).join(';')}`)
|
|
3504
3694
|
}
|
|
3505
|
-
const proposal = parseProposal(raw)
|
|
3506
3695
|
if (!proposal) {
|
|
3507
|
-
const error = new Error('
|
|
3696
|
+
const error = new Error(`ops 路由链上没有一条给出可用输出:${failures.join(' | ')}`)
|
|
3508
3697
|
error.statusCode = 502
|
|
3509
3698
|
throw error
|
|
3510
3699
|
}
|
|
3700
|
+
const thinking = text(String(proposal.thinking || proposal.reason || ''), 600)
|
|
3511
3701
|
const answer = text(String(proposal.answer || proposal.note || ''), 1200)
|
|
3512
3702
|
if (op === 'ask') {
|
|
3513
3703
|
// 问询只回文本:即使模型硬塞了 changes 也不落盘。
|
|
3514
|
-
return { ok: true, op, applied: false, changes: [], warnings: [], answer: answer || '(模型未给出回答)' }
|
|
3704
|
+
return { ok: true, op, applied: false, changes: [], warnings: [], thinking, attempts: served.attempts, route: served.route, routeIndex: served.index, answer: answer || '(模型未给出回答)' }
|
|
3515
3705
|
}
|
|
3516
3706
|
const mapped = opsChanges(state, proposal)
|
|
3517
3707
|
if (mapped.length === 0) {
|
|
3518
|
-
return { ok: true, op, applied: false, changes: [], warnings: answer ? [] : ['模型未提出可用改动'], answer: answer || '无需改动' }
|
|
3708
|
+
return { ok: true, op, applied: false, changes: [], warnings: answer ? [] : ['模型未提出可用改动'], thinking, attempts: served.attempts, route: served.route, routeIndex: served.index, answer: answer || '无需改动' }
|
|
3519
3709
|
}
|
|
3520
3710
|
const result = await applyChanges({ sessionId, changes: mapped, origin: 'ops' })
|
|
3521
3711
|
const post = validateBoard(result.snapshot.items)
|
|
@@ -3524,7 +3714,14 @@ ${reason}。本回合开始前先用 progress_update 处理进度板:用户这
|
|
|
3524
3714
|
op,
|
|
3525
3715
|
applied: true,
|
|
3526
3716
|
changes: result.changed,
|
|
3527
|
-
warnings:
|
|
3717
|
+
warnings: result.warnings || [],
|
|
3718
|
+
thinking,
|
|
3719
|
+
attempts: served.attempts,
|
|
3720
|
+
route: served.route,
|
|
3721
|
+
routeIndex: served.index,
|
|
3722
|
+
// 落盘后的板面体检结论:不再占一个按钮,随每次回答自动跑。
|
|
3723
|
+
// 客户端只在「不 ok 或有提醒」时才把它显示出来,顺利通过时不占输出区。
|
|
3724
|
+
validation: { ok: post.ok, count: post.count, errors: post.errors, warnings: post.warnings },
|
|
3528
3725
|
answer: answer || `已应用 ${result.changed.length} 条改动`,
|
|
3529
3726
|
notified: result.notified === true,
|
|
3530
3727
|
noticeMerged: result.noticeMerged === true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-progress-union",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "进度结合原型:dsh-progress-board 槽位真相源 × 鲸程 widget 时间/ETA 引擎;向压缩插件暴露只读三层进度锚点(service + HTTP 双平面);0.6.0 起每回合落一版会话归档(handoff + 重启注入一次)。基于 l3j3y3/dsh-progress-board (MIT) 与 uuhihj/task-progress-bar dsh-progress-widget (MIT)。",
|
|
6
6
|
"license": "MIT",
|
package/test/client.test.mjs
CHANGED
|
@@ -315,11 +315,58 @@ test('rc.3:opsOutcome 对 refine/mutate/ask 只回文本,没落地也不冒
|
|
|
315
315
|
assert.equal(warned.text, '只有 1 项在做\n同时 doing 2 项')
|
|
316
316
|
})
|
|
317
317
|
|
|
318
|
+
test('0.7.9:回执拆「思考 / 输出」两区,体检通过不占输出区,打回次数只在 >1 时出现', () => {
|
|
319
|
+
const outcome = loadOpsOutcome()
|
|
320
|
+
const t = (key) => key
|
|
321
|
+
const clean = outcome(t, {
|
|
322
|
+
op: 'refine',
|
|
323
|
+
thinking: '按数据面与展示面拆两步',
|
|
324
|
+
answer: '已拆成两步',
|
|
325
|
+
changes: [{ id: 'a' }],
|
|
326
|
+
warnings: [],
|
|
327
|
+
attempts: 1,
|
|
328
|
+
validation: { ok: true, count: 4, errors: [], warnings: [] },
|
|
329
|
+
})
|
|
330
|
+
assert.equal(clean.think, '按数据面与展示面拆两步', '思考区拿 thinking 字段')
|
|
331
|
+
assert.equal(clean.text, '已拆成两步', '体检顺利通过时不再往输出区插一行「校验通过」')
|
|
332
|
+
assert.equal(clean.kind, 'ok')
|
|
333
|
+
const retried = outcome(t, { op: 'mutate', answer: '重新给一版', changes: [{ id: 'a' }], warnings: [], attempts: 2 })
|
|
334
|
+
assert.match(retried.text, /opsRetried 1/, '被打回过一次必须告知用户重问了几轮')
|
|
335
|
+
const noRetry = outcome(t, { op: 'mutate', answer: '删掉了', changes: [{ id: 'a' }], warnings: [], attempts: 1 })
|
|
336
|
+
assert.equal(noRetry.text.includes('opsRetried'), false, '一次过的不应多一行噪声')
|
|
337
|
+
const warned = outcome(t, { op: 'refine', answer: '已落盘', changes: [{ id: 'a' }], warnings: [], attempts: 1, validation: { ok: true, count: 4, errors: [], warnings: ['同时 doing 2 项'] } })
|
|
338
|
+
assert.equal(warned.kind, 'warn', '体检有提醒 → warn 档,要落进输出区')
|
|
339
|
+
assert.match(warned.text, /同时 doing 2 项/)
|
|
340
|
+
const broken = outcome(t, { op: 'refine', answer: '已落盘', changes: [{ id: 'a' }], warnings: [], attempts: 1, validation: { ok: false, count: 61, errors: ['项数 61 超过上限'], warnings: [] } })
|
|
341
|
+
assert.equal(broken.kind, 'bad')
|
|
342
|
+
assert.match(broken.text, /opsValidBad/)
|
|
343
|
+
assert.match(broken.text, /项数 61 超过上限/)
|
|
344
|
+
const quiet = outcome(t, { op: 'ask', answer: '只有 1 项在做', changes: [], warnings: [] })
|
|
345
|
+
assert.equal(quiet.think, '', '模型没给 thinking 时思考区整块缺席,不留空框')
|
|
346
|
+
})
|
|
347
|
+
|
|
348
|
+
test('0.8.0:降级过才在输出区报一行位次,一次过不占行', () => {
|
|
349
|
+
const outcome = loadOpsOutcome()
|
|
350
|
+
// 真字典里 opsRouteDowngraded 带占位 N(zh「链上第 N 条路由」/ en「chain route N」),
|
|
351
|
+
// 客户端用 replace('N', 位次) 填数;这里用同构文案验证填位本身。
|
|
352
|
+
const t = (key) => (key === 'opsRouteDowngraded' ? 'chain route N' : key)
|
|
353
|
+
const head = outcome(t, { op: 'refine', answer: '已拆两步', changes: [{ id: 'a' }], warnings: [], attempts: 1, routeIndex: 0 })
|
|
354
|
+
assert.equal(head.text.includes('chain route'), false, '链首服务不得多一行噪声')
|
|
355
|
+
const down = outcome(t, { op: 'mutate', answer: '删掉了', changes: [{ id: 'a' }], warnings: [], attempts: 1, routeIndex: 1 })
|
|
356
|
+
assert.equal(down.text, '删掉了\nchain route 2', '链上第二条→报第 2 条')
|
|
357
|
+
assert.equal(down.kind, 'ok', '降级本身不是错误')
|
|
358
|
+
const deep = outcome(t, { op: 'refine', answer: 'x', changes: [{ id: 'a' }], warnings: [], routeIndex: 3 })
|
|
359
|
+
assert.match(deep.text, /chain route 4/)
|
|
360
|
+
})
|
|
361
|
+
|
|
318
362
|
test('rc.3:LLM 操作块只读 providers + POST /ops,不开新标签也不动路由面', () => {
|
|
319
363
|
const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
|
|
320
364
|
assert.match(src, /fetch\(`\$\{API\}\/ops\/providers`/, 'provider 下拉必须拉宿主面,不在客户端写死')
|
|
321
|
-
assert.match(src, /fetch\(`\$\{API\}\/ops`, \{\n\s+method: 'POST'/, '
|
|
322
|
-
assert.match(src, /const OPS_ACTIONS = \[\s*\['refine', 'opsRefine'\],\s*\['mutate', 'opsMutate'\],\s*\['ask', 'opsAsk'\]
|
|
365
|
+
assert.match(src, /fetch\(`\$\{API\}\/ops`, \{\n\s+method: 'POST'/, '动作统一走 POST /ops')
|
|
366
|
+
assert.match(src, /const OPS_ACTIONS = \[\s*\['refine', 'opsRefine'\],\s*\['mutate', 'opsMutate'\],\s*\['ask', 'opsAsk'\],/, '恰好三个动作——v0.7.9 起「校验」不再上按钮')
|
|
367
|
+
assert.equal(src.includes("['validate', 'opsValidate']"), false, '按钮位不得残留 validate')
|
|
368
|
+
const server = fs.readFileSync(path.join(path.dirname(clientFile), 'index.js'), 'utf8')
|
|
369
|
+
assert.ok(server.includes("if (op === 'validate')"), '服务端 validate 路由必须保留(只是面板不再露出)')
|
|
323
370
|
// 不新开顶级标签:只允许在 ProgressSidePanel 里渲染一次,且不能新增任何 tab/slot 注册
|
|
324
371
|
const panelStart = src.indexOf('function ProgressSidePanel(props) {')
|
|
325
372
|
const panelEnd = src.indexOf("inject: ['slots', 'locale'", panelStart)
|
|
@@ -340,6 +387,18 @@ test('rc.3:LLM 操作块只读 providers + POST /ops,不开新标签也不
|
|
|
340
387
|
assert.match(block, /if \(data\.disabled\) \{[\s\S]*setOff\(true\)/, 'disabled 必须先于 setProviders 短路')
|
|
341
388
|
assert.match(block, /if \(off\) return null/, '开关关掉时整个操作块不渲染')
|
|
342
389
|
assert.ok(block.indexOf('if (off) return null') > block.indexOf('useEffect('), '早退必须在全部 hooks 之后,不破坏 hook 顺序')
|
|
390
|
+
// 两区渲染:思考区只在模型给了 thinking 时出现,不留空框
|
|
391
|
+
assert.match(block, /out && out\.think \? h\(\s*'div',\s*\{ className: 'pb-ops-think' \}/, '思考区挂在输出区之前')
|
|
392
|
+
assert.match(block, /out && out\.text \? h\(\s*'div',\s*\{ className: out\.kind === 'ok' \? 'pb-ops-out'/, '结论区仍按 ok/warn/bad 三档取色')
|
|
393
|
+
// v0.8.0:未钉定路由时块照常渲染,但三个动作锁住 + 给引导文案,不发请求
|
|
394
|
+
assert.match(src, /unconfigured: !!\(body && body\.unconfigured === true\)/, 'providers 回执里的 unconfigured 必须透出来')
|
|
395
|
+
assert.match(block, /const \[unconf, setUnconf\] = useState\(false\)/, '未钉定位必须存下来')
|
|
396
|
+
assert.match(block, /const locked = Boolean\(disabled\) \|\| unconf/, '锁定位 = 开关关掉或未钉定')
|
|
397
|
+
assert.match(block, /if \(busy \|\| !sessionId \|\| unconf\) return/, '未钉定时 run 直接短路,不去撞 403')
|
|
398
|
+
assert.match(block, /unconf\b[\s\S]{0,160}\? h\('div', \{ className: 'pb-ops-note' \}, t\('opsUnconfigured'\)\)/, '未钉定时给引导行而不是空下拉')
|
|
399
|
+
assert.equal(block.includes("h('option', { value: '' }, t('opsProviderNone'))"), false, '白名单下不再有「沿用设置页」这个误导选项')
|
|
400
|
+
assert.match(block, /opsModelLabel\(t, p\)/, 'provider 候选带本地/云端标记')
|
|
401
|
+
assert.match(block, /opsIdOf\(m\), opsModelLabel\(t, m\)/, 'model 候选带本地/云端标记')
|
|
343
402
|
})
|
|
344
403
|
|
|
345
404
|
test('rc.3:操作块样式只用宿主令牌,窄屏降级', () => {
|
|
@@ -355,11 +414,15 @@ test('rc.3:操作块样式只用宿主令牌,窄屏降级', () => {
|
|
|
355
414
|
assert.match(css, /\.pb-ops-out\.warn \{[^}]*var\(--dsw-alias-state-warn-primary\)/, '可疑档用 warn 令牌')
|
|
356
415
|
assert.match(css, /@media \(max-width: 760px\) \{ \.pb-ops-hint \{ display: none; \} \}/, '窄屏收掉提示文案')
|
|
357
416
|
assert.match(css, /@media \(max-width: 520px\) \{ \.pb-ops-row \{ flex-direction: column; \} \}/, '极窄屏下拉竖排')
|
|
417
|
+
assert.match(css, /\.pb-ops-think \{[^}]*var\(--dsw-alias-border-l2\)/, '思考区左边线用次级边框令牌')
|
|
418
|
+
assert.match(css, /\.pb-ops-think-body \{[^}]*var\(--dsw-alias-label-tertiary\)/, '思考区正文用三级文字令牌(比输出区低一档)')
|
|
419
|
+
assert.match(css, /\.pb-ops-area-label \{[^}]*var\(--dsw-alias-label-tertiary\)/, '分区标题用文字令牌')
|
|
420
|
+
assert.match(css, /\.pb-ops-note \{[^}]*var\(--dsw-alias-state-warn-primary\)/, '未钉定提示行用 warn 令牌,不硬编色')
|
|
358
421
|
})
|
|
359
422
|
|
|
360
423
|
test('rc.3:操作块文案 zh/en 成对(本仓 client 只有内联 zh/en 两份字典)', () => {
|
|
361
424
|
const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
|
|
362
|
-
const keys = ['opsTitle', 'opsHint', 'opsProvider', 'opsModel', '
|
|
425
|
+
const keys = ['opsTitle', 'opsHint', 'opsProvider', 'opsModel', 'opsQuestion', 'opsRefine', 'opsMutate', 'opsAsk', 'opsBusy', 'opsNoChanges', 'opsThink', 'opsOut', 'opsRetried', 'opsValidOk', 'opsValidBad', 'opsItemsUnit', 'opsLocalTag', 'opsCloudTag', 'opsRouteDowngraded', 'opsUnconfigured']
|
|
363
426
|
for (const k of keys) {
|
|
364
427
|
const hits = src.match(new RegExp(`\\n\\s+${k}: '[^']+',`, 'g')) || []
|
|
365
428
|
assert.equal(hits.length, 2, `${k} 必须在 zh/en 各出现一次(实得 ${hits.length})`)
|