dsh-project-flow 0.9.3 → 0.10.2
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 +225 -12
- package/README.md +25 -0
- package/checks/assertion.mjs +104 -0
- package/checks/command.mjs +416 -0
- package/checks/requirement.mjs +91 -0
- package/commands/slash.mjs +754 -0
- package/commands/steer.mjs +43 -0
- package/config/settings.mjs +217 -0
- package/docs/FEATURES.md +9 -6
- package/docs/anchors/file-whitelist.md +1 -1
- package/http/routes.mjs +252 -0
- package/index.js +173 -8612
- package/issues/issue.mjs +322 -0
- package/package.json +16 -1
- package/persistence/lock.mjs +67 -0
- package/persistence/log.mjs +43 -0
- package/persistence/recovery.mjs +118 -0
- package/persistence/state.mjs +202 -0
- package/pricing/estimate.mjs +72 -0
- package/prompts/rules.mjs +192 -0
- package/rollback/ledger.mjs +237 -0
- package/runner/pipeline.mjs +1190 -0
- package/runner/stage.mjs +370 -0
- package/runner/tools/context.mjs +64 -0
- package/runner/tools/decorate-cost.mjs +49 -0
- package/runner/tools/doctor.mjs +59 -0
- package/runner/tools/estimate.mjs +63 -0
- package/runner/tools/execute-run.mjs +255 -0
- package/runner/tools/models.mjs +55 -0
- package/runner/tools/resume.mjs +142 -0
- package/runner/tools/rollback.mjs +291 -0
- package/runner/tools/run.mjs +271 -0
- package/runner/tools/set.mjs +65 -0
- package/runner/tools/snapshots.mjs +83 -0
- package/runner/tools/status.mjs +70 -0
- package/runner/tools.mjs +94 -0
- package/shared/constants.mjs +273 -0
- package/shared/tool.mjs +32 -0
- package/shared/util.mjs +231 -0
- package/snapshot/repo.mjs +452 -0
- package/state/registry.mjs +40 -0
- package/tests/aesthetic.test.mjs +20 -12
- package/tests/apply-wiring.test.mjs +172 -0
- package/tests/assertions-e2e.mjs +2 -1
- package/tests/atomic-write.test.mjs +129 -0
- package/tests/client-bundle.test.mjs +3 -3
- package/tests/command-whitelist.test.mjs +135 -0
- package/tests/contract.test.mjs +2 -2
- package/tests/desktop.test.mjs +2 -2
- package/tests/domains.test.mjs +10 -7
- package/tests/e2e.mjs +2 -1
- package/tests/extra-phase.test.mjs +2 -2
- package/tests/feedback.test.mjs +6 -1
- package/tests/flow-gate.test.mjs +16 -56
- package/tests/issues-e2e.mjs +2 -1
- package/tests/panel-independence.test.mjs +2 -2
- package/tests/panel-report.test.mjs +2 -2
- package/tests/paths.mjs +70 -1
- package/tests/preview-path.test.mjs +2 -1
- package/tests/qa-assertions.test.mjs +10 -3
- package/tests/run-all.mjs +5 -0
- package/tests/snapshot-core.test.mjs +234 -0
- package/tests/stage-model.test.mjs +2 -2
- package/tests/stop-resume.test.mjs +10 -2
- package/tests/watch-root.test.mjs +33 -2
- package/ui/prompt.mjs +101 -0
- package/workspace/models.mjs +111 -0
- package/workspace/panel.mjs +370 -0
- package/workspace/paths.mjs +393 -0
- package/workspace/resume.mjs +107 -0
|
@@ -0,0 +1,754 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 斜杠命令:从输入框出发最快的一条路,不用面板、不用同步客户端。
|
|
3
|
+
*/
|
|
4
|
+
import { readdir, readFile } from 'node:fs/promises'
|
|
5
|
+
import { join } from 'node:path'
|
|
6
|
+
import { parseOverrideTable, priceCatalog, CONFIDENCE_LABEL } from '../prices.mjs'
|
|
7
|
+
import { libraryPath, loadLibrary, librarySummary } from '../aesthetic-library.mjs'
|
|
8
|
+
import { homedir } from 'node:os'
|
|
9
|
+
import { loadUserDomains, BUILTIN_DOMAINS, DOMAIN_IDS } from '../domains.mjs'
|
|
10
|
+
import { AESTHETIC_MODES } from '../aesthetic.mjs'
|
|
11
|
+
import { steerInstruction } from './steer.mjs'
|
|
12
|
+
import { overrideFile, settingsOf, writeOverride } from '../config/settings.mjs'
|
|
13
|
+
import { logLine } from '../persistence/log.mjs'
|
|
14
|
+
import { sweep } from '../persistence/recovery.mjs'
|
|
15
|
+
import { readState } from '../persistence/state.mjs'
|
|
16
|
+
import { AESTHETIC_CARRIER_LABELS } from '../prompts/rules.mjs'
|
|
17
|
+
import { StopRequested } from '../runner/stage.mjs'
|
|
18
|
+
import { ARTIFACT, COPYRIGHT, FLOW_GATE_MODES, INTENT_CONFIDENCE_FLOOR, LICENSE_NOTICE, STAGE_LABEL } from '../shared/constants.mjs'
|
|
19
|
+
import { messageOf } from '../shared/util.mjs'
|
|
20
|
+
import { listProjectLines, statusLine, writePanelFile } from '../workspace/panel.mjs'
|
|
21
|
+
import { cwdOf, ensureFlowRoot, flowGateMessage, flowModeOf, flowRootConfigured, insideFlow, watchRootOf } from '../workspace/paths.mjs'
|
|
22
|
+
import { buildResumePlan, pickResumable } from '../workspace/resume.mjs'
|
|
23
|
+
import { pfState } from '../state/registry.mjs'
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 返回卸载函数,交给调用方挂到 ctx.effect 上。
|
|
27
|
+
* 整段就是一条 ctx.inject:宿主有那个服务时才跑,服务晚到也能补上。
|
|
28
|
+
*/
|
|
29
|
+
export function createSlash(ctx, rt) {
|
|
30
|
+
const { executeRun, listModelCatalog, refreshDetectedModels, snapshotsTool } = rt
|
|
31
|
+
ctx.inject(['commands'], commandsCtx => {
|
|
32
|
+
const commands = commandsCtx.get('commands')
|
|
33
|
+
commandsCtx.effect(() => {
|
|
34
|
+
const offFlow = commands.register({
|
|
35
|
+
name: 'flow',
|
|
36
|
+
description: '开工作模式:把当前任务按四阶跑(需求→规划→实施→质检)',
|
|
37
|
+
input: { hint: '直接描述任务;留空则先问你' },
|
|
38
|
+
handler: async invocation => {
|
|
39
|
+
let gateCwd = cwdOf(commandsCtx, invocation.agent)
|
|
40
|
+
const gateSettings = settingsOf()
|
|
41
|
+
// 不在工作流目录里就先替他建出来,然后把这次的工作目录指过去。
|
|
42
|
+
// 之后调 project_run 时会显式带上 cwd,所以这里改的值要一路传下去。
|
|
43
|
+
//
|
|
44
|
+
// 但配了绝对 flowRoot 就不挪:那代表用户明确说了「只在那儿用」。
|
|
45
|
+
// 擅自换地方等于把他带到一个错的目录里开工,底下会另起一个
|
|
46
|
+
// .project-flow,项目就散了。
|
|
47
|
+
let created = false
|
|
48
|
+
if (!flowRootConfigured(gateSettings)
|
|
49
|
+
&& gateSettings.autoCreateFlowDir === true
|
|
50
|
+
&& flowModeOf(gateSettings) === 'strict'
|
|
51
|
+
&& !insideFlow(gateCwd, gateSettings)) {
|
|
52
|
+
const ensured = await ensureFlowRoot(gateCwd, gateSettings)
|
|
53
|
+
if (ensured.created === true) {
|
|
54
|
+
gateCwd = ensured.root
|
|
55
|
+
created = true
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (!insideFlow(gateCwd, gateSettings)) {
|
|
59
|
+
return { kind: 'error', text: flowGateMessage(gateCwd, gateSettings) }
|
|
60
|
+
}
|
|
61
|
+
// 一旦确认在工作流目录里,就把模型配置落一份:状态栏立刻从「未启用」变成可用
|
|
62
|
+
void writePanelFile(gateCwd, gateSettings)
|
|
63
|
+
const text = invocation.rawInput.trim()
|
|
64
|
+
const ask = text === ''
|
|
65
|
+
? '我要开工作模式跑一个任务,但我还没说是什么。请先问我一个问题,问出我要做什么。'
|
|
66
|
+
: `我要开工作模式跑这个任务:${text}`
|
|
67
|
+
const instruction = [
|
|
68
|
+
ask,
|
|
69
|
+
'',
|
|
70
|
+
'从现在起按工作模式执行。第 1 段是硬门槛,不是走过场:',
|
|
71
|
+
`· 用 ask_user_question 一次只问一个问题,问到你对我的真实意图有 ${INTENT_CONFIDENCE_FLOOR} 分把握为止;`,
|
|
72
|
+
'· 每答一次重新评估,够了就停,别凑问题;',
|
|
73
|
+
'· 我问过几个问题、你最后的把握是多少、哪些地方是你自己定的默认值,都要在调 project_run 时交上来,',
|
|
74
|
+
` 低于 ${INTENT_CONFIDENCE_FLOOR} 分或一个问题都没问过,工具会直接报错、不开跑;`,
|
|
75
|
+
'· 如果我说「就按这个做、别再问了」,传 override: true 并把我这句话写进 overrideReason。',
|
|
76
|
+
...(created === true
|
|
77
|
+
? [`· 调 project_run 时带上 cwd: "${gateCwd}"——工作目录已经建在这里,别再用会话默认目录。`]
|
|
78
|
+
: []),
|
|
79
|
+
].join('\n')
|
|
80
|
+
// 把指令真的交给模型。交不出去(老宿主)才退回原来的纯文本,
|
|
81
|
+
// 让界面至少有内容,别静默什么都不发生。
|
|
82
|
+
if (await steerInstruction(invocation.agent, instruction)) {
|
|
83
|
+
return { kind: 'success', text: '已开工作模式,任务已交给模型。' }
|
|
84
|
+
}
|
|
85
|
+
// 交不出去的那个老宿主:原样把指令显示在界面上,内容和 steer 出去的完全一致。
|
|
86
|
+
return { kind: 'success', text: instruction }
|
|
87
|
+
},
|
|
88
|
+
})
|
|
89
|
+
const offStatusCmd = commands.register({
|
|
90
|
+
name: 'flow-status',
|
|
91
|
+
description: '看当前项目跑到第几段、返工几次',
|
|
92
|
+
handler: async invocation => {
|
|
93
|
+
const cwd = cwdOf(commandsCtx, invocation.agent)
|
|
94
|
+
const lines = await listProjectLines(cwd)
|
|
95
|
+
return {
|
|
96
|
+
kind: 'success',
|
|
97
|
+
text: lines.length === 0 ? '还没有项目。用 /flow 开一个。' : lines.join('\n'),
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
})
|
|
101
|
+
const offModelsCmd = commands.register({
|
|
102
|
+
name: 'flow-models',
|
|
103
|
+
description: '看四阶各用什么模型',
|
|
104
|
+
handler: async () => {
|
|
105
|
+
const settings = settingsOf()
|
|
106
|
+
const route = (llmProvider, model) => (model === '' ? '继承主对话' : `${llmProvider}/${model}`)
|
|
107
|
+
// 可用模型从 LLM 注册表现读,不写死。别人的 dsh 里装了什么就显示什么。
|
|
108
|
+
const catalog = await listModelCatalog()
|
|
109
|
+
const available = catalog.providers.length === 0
|
|
110
|
+
? [` (没读到可用模型${catalog.error === undefined ? '' : `:${catalog.error}`})`]
|
|
111
|
+
: catalog.providers.map(group => group.failed === true
|
|
112
|
+
? ` ${group.name}(${group.id}):读取失败`
|
|
113
|
+
: ` ${group.name}(${group.id}):${group.models.map(model => model.id).join(', ')}`)
|
|
114
|
+
return {
|
|
115
|
+
kind: 'success',
|
|
116
|
+
text: [
|
|
117
|
+
'四阶分工与模型:',
|
|
118
|
+
`1 需求:${settings.intentModel === '' ? '主对话当前模型' : settings.intentModel}(问清你要什么;主对话模型,插件改不了)`,
|
|
119
|
+
`2 规划:${route(settings.planProvider === '' ? '默认路由' : settings.planProvider, settings.planModel)}(出施工任务书)`,
|
|
120
|
+
`3 实施:${route(settings.buildProvider === '' ? '默认路由' : settings.buildProvider, settings.buildModel)}(照任务书干活)`,
|
|
121
|
+
`4 质检:${route(settings.checkProvider === '' ? '默认路由' : settings.checkProvider, settings.checkModel)}(挑毛病,不合格打回)`,
|
|
122
|
+
`返工上限 ${settings.maxRework} 次,并发 ${settings.maxConcurrentProjects} 个项目`,
|
|
123
|
+
`自愈:单段失败重试 ${settings.maxStageRetries} 次,单段超时 ${Math.round(settings.stageTimeoutMs / 1000)} 秒,锁超过 ${Math.round(settings.staleLockMs / 60000)} 分钟无心跳算遗留`,
|
|
124
|
+
`快照:${settings.snapshotEnabled === true ? '每次实施前自动打一张,可回滚' : '已关闭(snapshotEnabled=false)'}`,
|
|
125
|
+
`审美:${settings.aesthetic === 'off'
|
|
126
|
+
? '关掉了,不注入排版规矩'
|
|
127
|
+
: settings.aesthetic === 'always'
|
|
128
|
+
? '一律注入(PPT/网页/卡片/文档的硬规矩 + 中文排版)'
|
|
129
|
+
: 'auto:只在做 PPT/网页/卡片/文档时才注入'}`,
|
|
130
|
+
'',
|
|
131
|
+
'本机可用模型(现读的,不是写死的):',
|
|
132
|
+
...available,
|
|
133
|
+
'',
|
|
134
|
+
'改模型:/flow-set 实施 hy4flash',
|
|
135
|
+
'带 provider 的模型写成:/flow-set 实施 deepseek deepseek-v4.1-flash',
|
|
136
|
+
`配置存于:${overrideFile()}`,
|
|
137
|
+
`版权:${COPYRIGHT} dsh-project-flow 由刘适开发与维护`,
|
|
138
|
+
`许可:${LICENSE_NOTICE}`,
|
|
139
|
+
].join('\n'),
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
})
|
|
143
|
+
// Continue a project that was interrupted: crash, reload, or an abnormal stop.
|
|
144
|
+
const offResumeCmd = commands.register({
|
|
145
|
+
name: 'flow-resume',
|
|
146
|
+
description: '接续被中断的项目:按磁盘上的产物重建上下文,从中断那段接着跑',
|
|
147
|
+
input: { hint: '项目名;留空则先列出所有项目' },
|
|
148
|
+
handler: async invocation => {
|
|
149
|
+
const cwd = cwdOf(commandsCtx, invocation.agent)
|
|
150
|
+
const project = invocation.rawInput.trim()
|
|
151
|
+
if (project === '') {
|
|
152
|
+
const lines = await listProjectLines(cwd)
|
|
153
|
+
return {
|
|
154
|
+
kind: 'success',
|
|
155
|
+
text: lines.length === 0
|
|
156
|
+
? '还没有项目。用 /flow 开一个。'
|
|
157
|
+
: ['要让哪个项目接着跑?用 /flow-resume 项目名', ...lines].join('\n'),
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
const state = await readState(cwd, project)
|
|
161
|
+
// 这段的每一句都是要模型去做的动作,所以整段走 steer;只留一句回执给界面。
|
|
162
|
+
const instruction = [
|
|
163
|
+
state === undefined
|
|
164
|
+
? `没找到项目「${project}」的 state.json。先调 project_doctor 看看 .project-flow 里剩下什么,别凭猜重建状态。`
|
|
165
|
+
: `项目「${project}」现在:${statusLine(state)}`,
|
|
166
|
+
'',
|
|
167
|
+
state === undefined
|
|
168
|
+
? `体检结果出来后,再决定要不要调 project_resume,project="${project}"。`
|
|
169
|
+
: `接下来调 project_resume,project="${project}"。它会把遗留锁、损坏的 state 处理掉,从中断的那一段接着跑,已经通过的段不重做。`,
|
|
170
|
+
].join('\n')
|
|
171
|
+
if (await steerInstruction(invocation.agent, instruction)) {
|
|
172
|
+
return { kind: 'success', text: `已让模型接续「${project}」。` }
|
|
173
|
+
}
|
|
174
|
+
return { kind: 'success', text: instruction }
|
|
175
|
+
},
|
|
176
|
+
})
|
|
177
|
+
const offDoctorCmd = commands.register({
|
|
178
|
+
name: 'flow-doctor',
|
|
179
|
+
description: '体检 .project-flow:遗留锁、损坏的 state.json、没收尾的阶段',
|
|
180
|
+
input: { hint: 'fix 表示顺手修;留空只报告' },
|
|
181
|
+
handler: async invocation => {
|
|
182
|
+
const cwd = cwdOf(commandsCtx, invocation.agent)
|
|
183
|
+
const fix = invocation.rawInput.trim().toLowerCase() === 'fix'
|
|
184
|
+
const actions = await sweep(cwd, settingsOf(), undefined, fix)
|
|
185
|
+
return {
|
|
186
|
+
kind: 'success',
|
|
187
|
+
text: actions.length === 0
|
|
188
|
+
? '没发现问题:没有遗留锁,state.json 都在,也没有悬空没收尾的阶段。'
|
|
189
|
+
: [actions.length + ' 处需要处理(' + (fix ? '已尝试修复' : '只报告,未改动任何文件') + '):', ...actions].join('\n'),
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
})
|
|
193
|
+
// ── 状态栏的三个动作 ────────────────────────────────────
|
|
194
|
+
// 状态栏(client.js)通过 remote.commands.execute 调这三个。
|
|
195
|
+
// 它们都是用户点的,进会话日志是该有的:用户做过什么要留痕。
|
|
196
|
+
const offStopCmd = commands.register({
|
|
197
|
+
name: 'flow-stop',
|
|
198
|
+
description: '停掉正在跑的项目:进度存盘,之后可以直接继续,已经跑过的段不重做',
|
|
199
|
+
input: { hint: '项目名;留空则停掉当前所有在跑的' },
|
|
200
|
+
handler: invocation => {
|
|
201
|
+
if (pfState.panelStops.size === 0) {
|
|
202
|
+
return { kind: 'success', text: '现在没有正在跑的项目,没有可停的。' }
|
|
203
|
+
}
|
|
204
|
+
const want = invocation.rawInput.trim()
|
|
205
|
+
const targets = want === '' ? [...pfState.panelStops.keys()] : [want]
|
|
206
|
+
const lines = []
|
|
207
|
+
for (const name of targets) {
|
|
208
|
+
const entry = pfState.panelStops.get(name)
|
|
209
|
+
if (entry === undefined) {
|
|
210
|
+
lines.push(`${name}:没在跑`)
|
|
211
|
+
continue
|
|
212
|
+
}
|
|
213
|
+
entry.controller.abort(new StopRequested(name))
|
|
214
|
+
lines.push(`${name}:已停,进度都在磁盘上。点状态栏的「继续」,或者跑 /flow-continue ${name},从断点接着来。`)
|
|
215
|
+
}
|
|
216
|
+
return { kind: 'success', text: lines.join('\n') }
|
|
217
|
+
},
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
const offContinueCmd = commands.register({
|
|
221
|
+
name: 'flow-continue',
|
|
222
|
+
description: '从断点继续一个停住的项目:已经跑过的段不重做',
|
|
223
|
+
input: { hint: '项目名;留空则自动挑最近停住的那个' },
|
|
224
|
+
handler: async invocation => {
|
|
225
|
+
const cwd = cwdOf(commandsCtx, invocation.agent)
|
|
226
|
+
const settings = settingsOf()
|
|
227
|
+
if (!insideFlow(cwd, settings)) {
|
|
228
|
+
return { kind: 'error', text: flowGateMessage(cwd, settings) }
|
|
229
|
+
}
|
|
230
|
+
const wanted = invocation.rawInput.trim()
|
|
231
|
+
const project = wanted === '' ? await pickResumable(cwd, settings) : wanted
|
|
232
|
+
if (project === undefined) {
|
|
233
|
+
return { kind: 'success', text: '没有停住的项目可续。用 /flow 开一个新的。' }
|
|
234
|
+
}
|
|
235
|
+
if (pfState.panelStops.has(project) || pfState.running.has(project)) {
|
|
236
|
+
return { kind: 'error', text: `${project} 正在跑。要重新开始就先 /flow-stop ${project}。` }
|
|
237
|
+
}
|
|
238
|
+
if (pfState.running.size >= settings.maxConcurrentProjects) {
|
|
239
|
+
return { kind: 'error', text: `同时只能跑 ${settings.maxConcurrentProjects} 个项目,先等一个跑完。` }
|
|
240
|
+
}
|
|
241
|
+
const plan = await buildResumePlan(cwd, project, settings)
|
|
242
|
+
if (plan.kind === 'no-state') {
|
|
243
|
+
return { kind: 'error', text: `找不到 ${project} 的 state.json,按产物也重建不出来。${plan.healed.join(';')}` }
|
|
244
|
+
}
|
|
245
|
+
if (plan.kind === 'no-intent') {
|
|
246
|
+
return { kind: 'error', text: `${project} 的 state.json 里没记下当初的意图和要求,接不上。` }
|
|
247
|
+
}
|
|
248
|
+
if (plan.kind === 'already-passed') {
|
|
249
|
+
return { kind: 'success', text: `${project} 四阶已经走完,没有要续的活。` }
|
|
250
|
+
}
|
|
251
|
+
if (plan.kind === 'no-ticket') {
|
|
252
|
+
return { kind: 'error', text: `${project} 没有可用的施工任务书(${ARTIFACT.plan} 缺失或格式不对),从实施段接不上。` }
|
|
253
|
+
}
|
|
254
|
+
// 不 await:命令要立刻返回,状态栏靠 .project-flow 的文件变化自己刷。
|
|
255
|
+
// 也故意不用 invocation.signal——那个信号跟着这次命令请求走,
|
|
256
|
+
// 请求一结束就把整轮续跑掐了。
|
|
257
|
+
const run = executeRun({ ...plan.options, parent: invocation.agent, signal: undefined })
|
|
258
|
+
run.catch(error => { void logLine(cwd, project, `续跑失败:${messageOf(error)}`) })
|
|
259
|
+
return {
|
|
260
|
+
kind: 'success',
|
|
261
|
+
text: `${project}:从第 ${plan.stage} 段接着跑(第${STAGE_LABEL[plan.stage] ?? '?'})。已经跑过的段不重做。`,
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* 看钱。用户明确要求过「项目完成后按各个模型的费率统计成人民币」。
|
|
268
|
+
*
|
|
269
|
+
* 数据源是 state.json 里的 cost 字段(每阶结束落盘),不是证据包——
|
|
270
|
+
* 证据包只有 PASS 之后才有,中途停住就查不到账,等于白记。
|
|
271
|
+
*/
|
|
272
|
+
const offCostCmd = commands.register({
|
|
273
|
+
name: 'flow-cost',
|
|
274
|
+
description: '看一个项目花了多少:分模型统计的 token 与人民币',
|
|
275
|
+
input: { hint: '项目名;留空则列出全部有账的项目' },
|
|
276
|
+
handler: async invocation => {
|
|
277
|
+
const cwd = cwdOf(commandsCtx, invocation.agent)
|
|
278
|
+
const wanted = invocation.rawInput.trim()
|
|
279
|
+
const money = value => `¥${Number(value ?? 0).toFixed(2)}`
|
|
280
|
+
|
|
281
|
+
const renderOne = (name, state) => {
|
|
282
|
+
const cost = state?.cost
|
|
283
|
+
if (cost === undefined || cost === null) {
|
|
284
|
+
// 还在跑、或者这个项目是旧版本跑的:没有分模型账单,只有熔断快照里的总数。
|
|
285
|
+
const spent = state?.watchdog?.spentUsd
|
|
286
|
+
return spent === undefined || spent === null
|
|
287
|
+
? `${name}:还没有花费记录(第 ${state?.stage ?? '?'} 阶)。跑到第 2 阶结束就会开始记。`
|
|
288
|
+
: `${name}:约 $${Number(spent).toFixed(4)}(旧版记录,没有分模型明细)`
|
|
289
|
+
}
|
|
290
|
+
const rows = Array.isArray(cost.breakdown) ? cost.breakdown : []
|
|
291
|
+
return [
|
|
292
|
+
`${name}:${money(cost.spentCny)}(约 $${Number(cost.spentUsd ?? 0).toFixed(4)},汇率 ${cost.cnyRate ?? 7.2})`,
|
|
293
|
+
`累计 ${Number(cost.totalTokens ?? 0).toLocaleString()} token(输入 ${Number(cost.tokens?.input ?? 0).toLocaleString()} / 输出 ${Number(cost.tokens?.output ?? 0).toLocaleString()})`,
|
|
294
|
+
...(rows.length === 0
|
|
295
|
+
? ['(没有分模型明细)']
|
|
296
|
+
: [
|
|
297
|
+
'| 模型 | 输入 | 输出 | 单价($/M 入·出) | 估算 |',
|
|
298
|
+
'|---|---|---|---|---|',
|
|
299
|
+
...rows.map(row => `| ${row.model} | ${Number(row.inputTokens).toLocaleString()} | ${Number(row.outputTokens).toLocaleString()} | ${row.priceInput}·${row.priceOutput} | ${money(row.estimatedCny)} |`),
|
|
300
|
+
]),
|
|
301
|
+
cost.updatedAt === undefined ? '' : `更新于 ${cost.updatedAt}`,
|
|
302
|
+
].filter(line => line !== '').join('\n')
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (wanted !== '') {
|
|
306
|
+
const state = await readState(cwd, wanted)
|
|
307
|
+
if (state === undefined) return { kind: 'error', text: `没有「${wanted}」这个项目。` }
|
|
308
|
+
return { kind: 'success', text: renderOne(wanted, state) }
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const watch = await watchRootOf(cwd, settingsOf())
|
|
312
|
+
let names = []
|
|
313
|
+
try {
|
|
314
|
+
const entries = await readdir(join(watch, '.project-flow'), { withFileTypes: true })
|
|
315
|
+
names = entries.filter(entry => entry.isDirectory()).map(entry => entry.name).sort()
|
|
316
|
+
} catch {
|
|
317
|
+
names = []
|
|
318
|
+
}
|
|
319
|
+
const blocks = []
|
|
320
|
+
let totalCny = 0
|
|
321
|
+
for (const name of names) {
|
|
322
|
+
const state = await readState(watch, name)
|
|
323
|
+
if (state === undefined) continue
|
|
324
|
+
if (state.cost === undefined && state.watchdog?.spentUsd === undefined) continue
|
|
325
|
+
totalCny += Number(state.cost?.spentCny ?? 0)
|
|
326
|
+
blocks.push(renderOne(name, state))
|
|
327
|
+
}
|
|
328
|
+
if (blocks.length === 0) {
|
|
329
|
+
return { kind: 'success', text: '还没有任何花费记录。跑到第 2 阶结束就会开始记。' }
|
|
330
|
+
}
|
|
331
|
+
return {
|
|
332
|
+
kind: 'success',
|
|
333
|
+
text: [...blocks, '', `合计:${money(totalCny)}`].join('\n\n'),
|
|
334
|
+
}
|
|
335
|
+
},
|
|
336
|
+
})
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* 本机每个可选模型的费率,以及这个数是怎么来的。
|
|
340
|
+
*
|
|
341
|
+
* 用户的要求是「检测设备中的可用模型,都做出费率,释放选择模型的自由」。
|
|
342
|
+
* 所以这里把注册表读到的模型逐个列出来,标清楚哪个是内置价、
|
|
343
|
+
* 哪个是估算、哪个是兜底——估的就是估的,不能让人当成报价去算预算。
|
|
344
|
+
*/
|
|
345
|
+
const offPricesCmd = commands.register({
|
|
346
|
+
name: 'flow-prices',
|
|
347
|
+
description: '看本机所有可用模型的费率:哪个是已知价、哪个是估算',
|
|
348
|
+
handler: async invocation => {
|
|
349
|
+
const settings = settingsOf()
|
|
350
|
+
const probed = await refreshDetectedModels()
|
|
351
|
+
const models = pfState.detectedModelIds
|
|
352
|
+
if (models.length === 0) {
|
|
353
|
+
return {
|
|
354
|
+
kind: 'success',
|
|
355
|
+
text: [
|
|
356
|
+
'没读到本机可用模型,价目表只能用内置的那几个。',
|
|
357
|
+
probed.error === undefined ? '' : `原因:${probed.error}`,
|
|
358
|
+
'这只影响「估价」,不影响跑任务——模型路由是 DSH 自己管的。',
|
|
359
|
+
].filter(line => line !== '').join('\n'),
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
const overrides = parseOverrideTable(settings.priceTable)
|
|
363
|
+
const catalog = priceCatalog(models, overrides)
|
|
364
|
+
const grouped = { exact: [], builtin: [], family: [], fallback: [] }
|
|
365
|
+
for (const row of catalog.rows) grouped[row.confidence].push(row)
|
|
366
|
+
|
|
367
|
+
const fmt = row => ` ${row.model} ${row.input}/${row.output} ${CONFIDENCE_LABEL[row.confidence]}${row.confidence === 'family' ? `(${row.label})` : ''}`
|
|
368
|
+
const lines = [
|
|
369
|
+
`本机可用模型 ${models.length} 个,费率单位是「美元/百万 token」,写作 输入/输出:`,
|
|
370
|
+
'',
|
|
371
|
+
...(grouped.exact.length === 0 ? [] : ['你配的:', ...grouped.exact.map(fmt)]),
|
|
372
|
+
...(grouped.builtin.length === 0 ? [] : ['内置已知价:', ...grouped.builtin.map(fmt)]),
|
|
373
|
+
...(grouped.family.length === 0 ? [] : ['按型号族估算:', ...grouped.family.map(fmt)]),
|
|
374
|
+
...(grouped.fallback.length === 0 ? [] : ['认不出型号,按最贵兜底:', ...grouped.fallback.map(fmt)]),
|
|
375
|
+
'',
|
|
376
|
+
`汇率 ${settings.cnyRate}(美元 → 人民币)。`,
|
|
377
|
+
'要精确就写进配置的 priceTable,或者:/flow-set 价格 模型名 输入价 输出价',
|
|
378
|
+
'「估算」那几档只是量级参考,不是厂商报价——按它算出来的预算要留余量。',
|
|
379
|
+
]
|
|
380
|
+
return { kind: 'success', text: lines.join('\n') }
|
|
381
|
+
},
|
|
382
|
+
})
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* 这里原来注册过一个 `/flow-panel` 命令,专门给状态栏取数据用。
|
|
386
|
+
*
|
|
387
|
+
* 已经删掉,原因很重要:命令服务每执行一次都会往会话里追加
|
|
388
|
+
* `command/run` 和带 text 的 `command/done`,界面把它们当消息渲染——
|
|
389
|
+
* 于是「打开状态栏」这个纯查看动作,会在对话框里留下一条 JSON。
|
|
390
|
+
* 用户报的「点一下对话框里就多一段看不懂的字」,根子就在这儿。
|
|
391
|
+
*
|
|
392
|
+
* 现在状态栏只走 HTTP 端口取数据,一次调用都不进会话。
|
|
393
|
+
* 这个命令不再注册,所以就算某个旧缓存的前端还在调它,
|
|
394
|
+
* 也只会得到「没有这个命令」——按宿主的规则,未知命令不写日志,
|
|
395
|
+
* 对话里不会再出现任何东西。
|
|
396
|
+
*/
|
|
397
|
+
|
|
398
|
+
// 一条命令回答「为什么看不见状态栏」,不用开浏览器控制台。
|
|
399
|
+
const offPatternsCmd = commands.register({
|
|
400
|
+
name: 'flow-patterns',
|
|
401
|
+
description: '看版式库:攒了多少条骨架、哪些真被用过并过关',
|
|
402
|
+
handler: async () => {
|
|
403
|
+
const settings = settingsOf()
|
|
404
|
+
const file = settings.aestheticLibrary === '' ? libraryPath() : settings.aestheticLibrary
|
|
405
|
+
const library = await loadLibrary(file)
|
|
406
|
+
const summary = librarySummary(library)
|
|
407
|
+
const lines = [
|
|
408
|
+
`版式库:${file}`,
|
|
409
|
+
summary.total === 0
|
|
410
|
+
? '库还是空的。做一次视觉类任务就会去网上搜骨架,搜到的会存进来。'
|
|
411
|
+
: `共 ${summary.total} 条(内置 ${summary.builtin} 条 + 采集 ${summary.learned} 条)`
|
|
412
|
+
+ ` · 按载体:${Object.entries(summary.byCarrier).map(([id, count]) => `${AESTHETIC_CARRIER_LABELS([id])} ${count}`).join(',')}`,
|
|
413
|
+
summary.total === 0 ? '' : `被用过 ${summary.tried} 条,其中过关过 ${summary.proven} 条`,
|
|
414
|
+
'',
|
|
415
|
+
...(summary.total === 0
|
|
416
|
+
? []
|
|
417
|
+
: library.patterns
|
|
418
|
+
.slice()
|
|
419
|
+
.sort((a, b) => (b.score ?? 0) - (a.score ?? 0))
|
|
420
|
+
.slice(0, 20)
|
|
421
|
+
.map(pattern => `- [${(pattern.score ?? 0) >= 0 ? '+' : ''}${pattern.score ?? 0}] ${pattern.name}(${AESTHETIC_CARRIER_LABELS([pattern.carrier])})用 ${pattern.used ?? 0} 次 / 过 ${pattern.wins ?? 0} 次:${pattern.structure}`)),
|
|
422
|
+
'',
|
|
423
|
+
`审美模式:${settings.aesthetic};采集:${settings.aestheticSearch};每次取 ${settings.aestheticPatterns} 条`,
|
|
424
|
+
]
|
|
425
|
+
return { kind: 'success', text: lines.filter(line => line !== '').join('\n') }
|
|
426
|
+
},
|
|
427
|
+
})
|
|
428
|
+
const offDomainCmd = commands.register({
|
|
429
|
+
name: 'flow-domain',
|
|
430
|
+
description: '看领域配置:内置有哪些行当、你自己加的在不在、这次会用哪个',
|
|
431
|
+
handler: async () => {
|
|
432
|
+
const settings = settingsOf()
|
|
433
|
+
const dir = settings.domainsDir === ''
|
|
434
|
+
? join(process.env.DSH_HOME ?? join(homedir(), '.dsh'), 'project-flow', 'domains')
|
|
435
|
+
: settings.domainsDir
|
|
436
|
+
const user = await loadUserDomains(readdir, readFile, dir)
|
|
437
|
+
const lines = [
|
|
438
|
+
`领域目录:${dir}`,
|
|
439
|
+
`当前配置:domain=${settings.domain}`,
|
|
440
|
+
'',
|
|
441
|
+
`内置 ${BUILTIN_DOMAINS.length} 个:${DOMAIN_IDS.join(' / ')}`,
|
|
442
|
+
...BUILTIN_DOMAINS.map(item => ` - ${item.id}(${item.name}):交付 ${item.deliverables.length} 项,验收 ${item.qaChecks.length} 条`),
|
|
443
|
+
'',
|
|
444
|
+
user.domains.length === 0
|
|
445
|
+
? '你自己加的领域:还没有。放一个 JSON 到上面那个目录就行,不用改代码。'
|
|
446
|
+
: `你自己加的 ${user.domains.length} 个:${user.domains.map(item => `${item.id}(${item.name})`).join(' / ')}`,
|
|
447
|
+
...(user.problems.length === 0 ? [] : ['', '有问题的文件:', ...user.problems.map(line => ` - ${line}`)]),
|
|
448
|
+
'',
|
|
449
|
+
'一个领域 JSON 长这样(最少这四个字段):',
|
|
450
|
+
'{',
|
|
451
|
+
' "id": "bakery",',
|
|
452
|
+
' "name": "烘焙",',
|
|
453
|
+
' "keywords": ["面包", "配方", "发酵"],',
|
|
454
|
+
' "deliverables": ["配方表", "工艺曲线"],',
|
|
455
|
+
' "planNote": ["写清发酵温度与时间"],',
|
|
456
|
+
' "buildRules": ["配方按烘焙百分比写"],',
|
|
457
|
+
' "qaChecks": ["含水率是否一致"]',
|
|
458
|
+
'}',
|
|
459
|
+
'',
|
|
460
|
+
'切法:/flow-set 领域 fashion (或 auto 让它自己认)',
|
|
461
|
+
]
|
|
462
|
+
return { kind: 'success', text: lines.join('\n') }
|
|
463
|
+
},
|
|
464
|
+
})
|
|
465
|
+
const offDiagCmd = commands.register({
|
|
466
|
+
name: 'flow-diag',
|
|
467
|
+
description: '状态栏自检:宿主有没有把 dsh-project-flow 的客户端入口放进启动图里',
|
|
468
|
+
handler: () => {
|
|
469
|
+
const lines = [`包名:dsh-project-flow(package.json 的 dsh.client 声明的客户端半边)`]
|
|
470
|
+
const applyHits = pfState.clientHits.filter(hit => hit.stage === 'apply')
|
|
471
|
+
const renderHits = pfState.clientHits.filter(hit => hit.stage === 'render')
|
|
472
|
+
if (pfState.clientHits.length === 0) {
|
|
473
|
+
lines.push('客户端回连:✗ 一次都没收到')
|
|
474
|
+
lines.push(' → 浏览器根本没执行到我的 apply。问题在物化那一步,跟槽位、样式都无关。')
|
|
475
|
+
} else {
|
|
476
|
+
const stages = [...new Set(pfState.clientHits.map(hit => hit.stage))].join(', ')
|
|
477
|
+
lines.push(`客户端回连:✓ 收到 ${pfState.clientHits.length} 次(apply ${applyHits.length} 次、render ${renderHits.length} 次,最近 ${pfState.clientHits[pfState.clientHits.length - 1].at})`)
|
|
478
|
+
lines.push(` 见过的阶段:${stages}`)
|
|
479
|
+
if (applyHits.length > 0 && renderHits.length === 0) {
|
|
480
|
+
lines.push(' → apply 跑了,但组件一次都没渲染。这是槽位挂载这一层的事。')
|
|
481
|
+
} else if (renderHits.length > 0) {
|
|
482
|
+
lines.push(' → 组件渲染过了。界面上还是没有就是样式或被裁掉。')
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
lines.push('')
|
|
486
|
+
if (pfState.clientModules === undefined) {
|
|
487
|
+
lines.push('clientModules 服务:取不到。这个 profile 可能没挂 Web 客户端,或者服务还没起来。')
|
|
488
|
+
return { kind: 'success', text: lines.join('\n') }
|
|
489
|
+
}
|
|
490
|
+
let graph
|
|
491
|
+
try {
|
|
492
|
+
graph = pfState.clientModules.graph()
|
|
493
|
+
} catch (error) {
|
|
494
|
+
lines.push(`graph() 调用失败:${messageOf(error)}`)
|
|
495
|
+
return { kind: 'success', text: lines.join('\n') }
|
|
496
|
+
}
|
|
497
|
+
const entries = Array.isArray(graph?.entries) ? graph.entries : []
|
|
498
|
+
const mine = entries.find(entry => entry?.id === 'dsh-project-flow')
|
|
499
|
+
lines.push(`启动图里的客户端入口共 ${entries.length} 个`)
|
|
500
|
+
if (mine === undefined) {
|
|
501
|
+
lines.push('')
|
|
502
|
+
lines.push('✗ 图里没有 dsh-project-flow —— 宿主没把它当成客户端插件。')
|
|
503
|
+
lines.push(' 这一侧要修的是包清单,跟浏览器无关。')
|
|
504
|
+
lines.push(` 图里现有的 id(前 40 个):${entries.slice(0, 40).map(entry => entry.id).join(', ')}`)
|
|
505
|
+
} else {
|
|
506
|
+
lines.push('')
|
|
507
|
+
lines.push('✓ 图里有 dsh-project-flow —— 宿主认了,问题在浏览器那一侧。')
|
|
508
|
+
lines.push(` url:${mine.url}`)
|
|
509
|
+
lines.push(` rev:${mine.rev}`)
|
|
510
|
+
lines.push(` immediately:${mine.immediately === true}`)
|
|
511
|
+
lines.push(` inject:${JSON.stringify(mine.inject ?? [])}`)
|
|
512
|
+
}
|
|
513
|
+
try {
|
|
514
|
+
const clientPath = pfState.clientModules.clientPath('dsh-project-flow')
|
|
515
|
+
lines.push(` clientPath:${clientPath ?? '(取不到:exports["./client"] 解析不出来)'}`)
|
|
516
|
+
} catch (error) {
|
|
517
|
+
lines.push(` clientPath 取不到:${messageOf(error)}`)
|
|
518
|
+
}
|
|
519
|
+
// 落在哪个初始批次,决定它在页面启动的哪一步被取。bootstrap 是解析阻塞那一批,
|
|
520
|
+
// 只有模块系统自己该在那儿;插件入口正常应该落在 application 里。
|
|
521
|
+
const batches = Array.isArray(graph?.batches) ? graph.batches : []
|
|
522
|
+
const mineBatch = batches.find(item => Array.isArray(item?.entries) && item.entries.includes('dsh-project-flow'))
|
|
523
|
+
lines.push(mineBatch === undefined
|
|
524
|
+
? ' 批次:不在任何初始批次里(要靠别的包带进来)'
|
|
525
|
+
: ` 批次:${mineBatch.phase} · 同批 ${mineBatch.entries.length} 个入口 · ${mineBatch.url}`)
|
|
526
|
+
const mineWait = Array.isArray(mine.inject) ? mine.inject : []
|
|
527
|
+
const missingDeps = mineWait.filter(dep => !entries.some(entry => entry?.id === dep))
|
|
528
|
+
lines.push(missingDeps.length === 0
|
|
529
|
+
? ` inject 的包都在图里:${mineWait.join(', ') || '(无)'}`
|
|
530
|
+
: ` ✗ inject 里这些包不在图里,它会一直等:${missingDeps.join(', ')}`)
|
|
531
|
+
return { kind: 'success', text: lines.join('\n') }
|
|
532
|
+
},
|
|
533
|
+
})
|
|
534
|
+
|
|
535
|
+
// Change a stage's model at runtime; no restart, no config editing.
|
|
536
|
+
const offSetCmd = commands.register({
|
|
537
|
+
name: 'flow-set',
|
|
538
|
+
description: '改某一阶段用的模型,改完立即生效不用重启',
|
|
539
|
+
input: { hint: '比如:实施 hy4flash' },
|
|
540
|
+
handler: async invocation => {
|
|
541
|
+
const settings = settingsOf()
|
|
542
|
+
const raw = invocation.rawInput.trim()
|
|
543
|
+
if (raw === '') {
|
|
544
|
+
return {
|
|
545
|
+
kind: 'success',
|
|
546
|
+
text: [
|
|
547
|
+
'当前模型:',
|
|
548
|
+
`2 规划:${settings.planModel === '' ? '继承' : settings.planModel}`,
|
|
549
|
+
`3 实施:${settings.buildModel === '' ? '继承' : settings.buildModel}`,
|
|
550
|
+
`4 质检:${settings.checkModel === '' ? '继承' : settings.checkModel}`,
|
|
551
|
+
`返工上限:${settings.maxRework} 次`,
|
|
552
|
+
'',
|
|
553
|
+
'改法(先写阶段,再写值):',
|
|
554
|
+
' /flow-set 实施 deepseek-v4.1-flash 只让实施段用这个模型',
|
|
555
|
+
' /flow-set 实施 清空 这段回到继承主对话模型',
|
|
556
|
+
' /flow-set 重试 3 返工上限',
|
|
557
|
+
' /flow-set 门控 off 关掉工作流目录检查',
|
|
558
|
+
'',
|
|
559
|
+
'模型名得是这个 profile 里真有的一个。写错了不会卡死,会自动退回主对话模型,但要多花一次调用。',
|
|
560
|
+
'注意:第 1 阶需求跑在主对话,模型只能用界面顶部的选择器切,这里改不了。',
|
|
561
|
+
].join('\n'),
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
const [stageRaw, ...rest] = raw.split(/\s+/u)
|
|
565
|
+
const value = rest.join(' ').trim()
|
|
566
|
+
const stageMap = {
|
|
567
|
+
规划: 'planModel', plan: 'planModel',
|
|
568
|
+
实施: 'buildModel', build: 'buildModel',
|
|
569
|
+
质检: 'checkModel', check: 'checkModel',
|
|
570
|
+
意图: 'intentModel', intent: 'intentModel',
|
|
571
|
+
重试: 'maxRework', rework: 'maxRework',
|
|
572
|
+
并发: 'maxConcurrentProjects', concurrent: 'maxConcurrentProjects',
|
|
573
|
+
审美: 'aesthetic', aesthetic: 'aesthetic',
|
|
574
|
+
领域: 'domain', domain: 'domain',
|
|
575
|
+
门控: 'flowGate', gate: 'flowGate',
|
|
576
|
+
价格: 'priceTable', price: 'priceTable',
|
|
577
|
+
}
|
|
578
|
+
const key = stageMap[stageRaw]
|
|
579
|
+
if (key === undefined) {
|
|
580
|
+
return { kind: 'error', text: `不认识的阶段「${stageRaw}」。用 规划 / 实施 / 质检 / 重试 / 并发 / 价格。` }
|
|
581
|
+
}
|
|
582
|
+
if (value === '') return { kind: 'error', text: `要给「${stageRaw}」一个值。` }
|
|
583
|
+
|
|
584
|
+
// 价格:/flow-set 价格 模型名 输入价 输出价
|
|
585
|
+
// 用自己配的真价覆盖估算——估算那几档只是量级参考,不能拿来对账。
|
|
586
|
+
if (key === 'priceTable') {
|
|
587
|
+
const [modelName, inputRaw, outputRaw] = value.split(/\s+/u).filter(part => part !== '')
|
|
588
|
+
if (modelName === undefined || inputRaw === undefined || outputRaw === undefined) {
|
|
589
|
+
return {
|
|
590
|
+
kind: 'error',
|
|
591
|
+
text: '写法:/flow-set 价格 模型名 输入价 输出价(单位:美元/百万 token,例如 /flow-set 价格 glm-5.3 0.69 2.76)',
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
const input = Number(inputRaw)
|
|
595
|
+
const output = Number(outputRaw)
|
|
596
|
+
if (!Number.isFinite(input) || !Number.isFinite(output) || input < 0 || output < 0) {
|
|
597
|
+
return { kind: 'error', text: `价格要两个非负数,你给的是「${inputRaw}」「${outputRaw}」。` }
|
|
598
|
+
}
|
|
599
|
+
const current = parseOverrideTable(settingsOf().priceTable)
|
|
600
|
+
const next = { ...current, [modelName]: { input, output } }
|
|
601
|
+
await writeOverride({ priceTable: JSON.stringify(next) })
|
|
602
|
+
return {
|
|
603
|
+
kind: 'success',
|
|
604
|
+
text: `已把 ${modelName} 的价设成 ${input}/${output}(美元/百万 token),下一轮生效。现在配了 ${Object.keys(next).length} 个模型的价。`,
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
if (value === '清空' || value === 'reset') {
|
|
609
|
+
await writeOverride({ [key]: '' })
|
|
610
|
+
await writePanelFile(cwdOf(commandsCtx, invocation.agent), settingsOf())
|
|
611
|
+
return { kind: 'success', text: `已把「${stageRaw}」恢复成继承当前模型。` }
|
|
612
|
+
}
|
|
613
|
+
if (key === 'flowGate') {
|
|
614
|
+
const mode = value.trim().toLowerCase()
|
|
615
|
+
if (!FLOW_GATE_MODES.includes(mode)) {
|
|
616
|
+
return {
|
|
617
|
+
kind: 'error',
|
|
618
|
+
text: `门控只认 ${FLOW_GATE_MODES.join(' / ')}。strict = 只在工作流目录里开(默认,目录会自动建),off = 不拦也不看名字。`,
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
await writeOverride({ flowGate: mode })
|
|
622
|
+
return {
|
|
623
|
+
kind: 'success',
|
|
624
|
+
text: mode === 'strict'
|
|
625
|
+
? '已开启目录门控:只在工作流目录(或配置的 flowRoot)里能开工作模式。目录还不在登记,第一次开工会自动建好。'
|
|
626
|
+
: '已关掉目录门控:哪个目录都能开工作模式,产物落在当前工作区。',
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
if (key === 'domain') {
|
|
630
|
+
// auto 或者任何已存在的领域 id(含用户自己加的)
|
|
631
|
+
if (value !== 'auto') {
|
|
632
|
+
const dir = settingsOf().domainsDir === ''
|
|
633
|
+
? join(process.env.DSH_HOME ?? join(homedir(), '.dsh'), 'project-flow', 'domains')
|
|
634
|
+
: settingsOf().domainsDir
|
|
635
|
+
const user = await loadUserDomains(readdir, readFile, dir)
|
|
636
|
+
const known = [...user.domains.map(item => item.id), ...DOMAIN_IDS]
|
|
637
|
+
if (!known.includes(value)) {
|
|
638
|
+
return {
|
|
639
|
+
kind: 'error',
|
|
640
|
+
text: `没有「${value}」这个领域。内置:${DOMAIN_IDS.join(' / ')}`
|
|
641
|
+
+ (user.domains.length === 0 ? '' : `;你自己加的:${user.domains.map(item => item.id).join(' / ')}`)
|
|
642
|
+
+ '。也可以写 auto 让它按任务内容自己认。',
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
await writeOverride({ domain: value })
|
|
647
|
+
return {
|
|
648
|
+
kind: 'success',
|
|
649
|
+
text: value === 'auto'
|
|
650
|
+
? '已设为 auto:每次按任务内容自己判断这活是哪一行当。'
|
|
651
|
+
: `已把这个插件切到「${value}」口径,下一轮生效。`,
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
if (key === 'aesthetic') {
|
|
655
|
+
// 只收三个值。写错了直接说清楚,不要静默落成 auto 让人以为设置生效了。
|
|
656
|
+
if (!AESTHETIC_MODES.includes(value)) {
|
|
657
|
+
return {
|
|
658
|
+
kind: 'error',
|
|
659
|
+
text: `「审美」只认 ${AESTHETIC_MODES.join(' / ')}。auto = 检测到视觉载体才注入,off 关掉,always 一律注入。`,
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
await writeOverride({ aesthetic: value })
|
|
663
|
+
return {
|
|
664
|
+
kind: 'success',
|
|
665
|
+
text: value === 'off'
|
|
666
|
+
? '已关掉审美约束,下一轮不再注入排版规矩。'
|
|
667
|
+
: value === 'always'
|
|
668
|
+
? '已设成一律注入审美约束,纯代码任务也会带上中文排版那几条。'
|
|
669
|
+
: '已设为 auto:只有做 PPT/网页/卡片/文档这类活时才注入审美约束。',
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
if (key === 'maxRework' || key === 'maxConcurrentProjects') {
|
|
673
|
+
const number = Number(value)
|
|
674
|
+
if (!Number.isInteger(number) || number < 0) {
|
|
675
|
+
return { kind: 'error', text: `「${stageRaw}」要一个非负整数,你给的是「${value}」。` }
|
|
676
|
+
}
|
|
677
|
+
await writeOverride({ [key]: number })
|
|
678
|
+
return { kind: 'success', text: `已设「${stageRaw}」= ${number},立即生效。` }
|
|
679
|
+
}
|
|
680
|
+
// 模型值可以是三种写法:
|
|
681
|
+
// hy4flash → 沿用当前 provider
|
|
682
|
+
// deepseek/deepseek-v4.1-flash → 斜杠写法,同时改 provider
|
|
683
|
+
// deepseek deepseek-v4.1-flash → 两个词,同时改 provider
|
|
684
|
+
// 客户端下拉给的是第三种(值和显示分开),斜杠写法留给手打。
|
|
685
|
+
const stageKeys = { plan: 'plan', build: 'build', check: 'check' }
|
|
686
|
+
const tokens = rest.filter(token => token !== '')
|
|
687
|
+
let provider = ''
|
|
688
|
+
let modelValue = value
|
|
689
|
+
if (tokens.length >= 2) {
|
|
690
|
+
provider = tokens[0]
|
|
691
|
+
modelValue = tokens.slice(1).join(' ')
|
|
692
|
+
} else if (tokens.length === 1 && tokens[0].includes('/')) {
|
|
693
|
+
const cut = tokens[0].indexOf('/')
|
|
694
|
+
provider = tokens[0].slice(0, cut)
|
|
695
|
+
modelValue = tokens[0].slice(cut + 1)
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
if (stageKeys[key] !== undefined && provider !== '') {
|
|
699
|
+
await writeOverride({ [key]: modelValue, [`${stageKeys[key]}Provider`]: provider })
|
|
700
|
+
await writePanelFile(cwdOf(commandsCtx, invocation.agent), settingsOf())
|
|
701
|
+
return {
|
|
702
|
+
kind: 'success',
|
|
703
|
+
text: `已把「${stageRaw}」设成 ${provider}/${modelValue},立即生效,不用重启。`,
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
await writeOverride({ [key]: value })
|
|
708
|
+
await writePanelFile(cwdOf(commandsCtx, invocation.agent), settingsOf())
|
|
709
|
+
return {
|
|
710
|
+
kind: 'success',
|
|
711
|
+
text: `已把「${stageRaw}」设成 ${value},立即生效,不用重启。下次跑任务就用它。`,
|
|
712
|
+
}
|
|
713
|
+
},
|
|
714
|
+
})
|
|
715
|
+
const offSnapshotsCmd = commands.register({
|
|
716
|
+
name: 'flow-snapshots',
|
|
717
|
+
description: '列出一个项目的全部快照,回滚时挑目标用',
|
|
718
|
+
input: { hint: '项目名' },
|
|
719
|
+
handler: async invocation => {
|
|
720
|
+
const cwd = cwdOf(commandsCtx, invocation.agent)
|
|
721
|
+
const project = invocation.rawInput.trim()
|
|
722
|
+
if (project === '') {
|
|
723
|
+
const lines = await listProjectLines(cwd)
|
|
724
|
+
return {
|
|
725
|
+
kind: 'success',
|
|
726
|
+
text: lines.length === 0
|
|
727
|
+
? '还没有项目。用 /flow 开一个。'
|
|
728
|
+
: ['要让哪个项目的快照?用 /flow-snapshots 项目名', ...lines].join('\n'),
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
const result = await snapshotsTool.execute({ project }, { agent: invocation.agent })
|
|
732
|
+
return { kind: 'success', text: [result.line, ...result.entries].join('\n') }
|
|
733
|
+
},
|
|
734
|
+
})
|
|
735
|
+
return () => {
|
|
736
|
+
offFlow()
|
|
737
|
+
offStatusCmd()
|
|
738
|
+
offModelsCmd()
|
|
739
|
+
offResumeCmd()
|
|
740
|
+
offDoctorCmd()
|
|
741
|
+
offStopCmd()
|
|
742
|
+
offContinueCmd()
|
|
743
|
+
offCostCmd()
|
|
744
|
+
offPricesCmd()
|
|
745
|
+
offDiagCmd()
|
|
746
|
+
offPatternsCmd()
|
|
747
|
+
offDomainCmd()
|
|
748
|
+
offSnapshotsCmd()
|
|
749
|
+
offSetCmd()
|
|
750
|
+
}
|
|
751
|
+
})
|
|
752
|
+
})
|
|
753
|
+
}
|
|
754
|
+
|