dsh-project-flow 0.9.2 → 0.10.1
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 +0 -0
- 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/DETAIL.md +2 -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 -8538
- 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 +136 -0
- package/runner/tools/rollback.mjs +291 -0
- package/runner/tools/run.mjs +262 -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 +2 -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 +6 -0
- package/tests/snapshot-core.test.mjs +234 -0
- package/tests/stage-model.test.mjs +2 -2
- package/tests/steer-command.test.mjs +151 -0
- package/tests/stop-resume.test.mjs +7 -2
- package/tests/watch-root.test.mjs +2 -1
- package/ui/prompt.mjs +101 -0
- package/workspace/models.mjs +111 -0
- package/workspace/panel.mjs +359 -0
- package/workspace/paths.mjs +393 -0
- package/workspace/resume.mjs +107 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 命令到底有没有把话送到模型手里。
|
|
3
|
+
*
|
|
4
|
+
* 用户报的问题(issue #1):`/flow 测试` 界面上渲染出一整段指令,模型却什么都没收到。
|
|
5
|
+
* 根因是宿主契约——`CommandResult.text` 只进 `command/done`,由界面渲染,不提交成用户消息。
|
|
6
|
+
*
|
|
7
|
+
* 这一套不验函数长得对不对,只验三件事:
|
|
8
|
+
* 1. 有 steer 的宿主上,指令真的被塞进 agent 的收件箱,且形状过了会话校验;
|
|
9
|
+
* 2. 返回值只留一句回执,不再把整段指令当 text 返回(那正是误以为成功的来源);
|
|
10
|
+
* 3. 老宿主没有 steer 时退回纯文本,不崩、也不静默。
|
|
11
|
+
*
|
|
12
|
+
* 用真插件、真命令处理器,只有 agent 和宿主校验是假的。
|
|
13
|
+
*/
|
|
14
|
+
import { test } from 'node:test'
|
|
15
|
+
import assert from 'node:assert/strict'
|
|
16
|
+
import { mkdtemp } from 'node:fs/promises'
|
|
17
|
+
import { join } from 'node:path'
|
|
18
|
+
import { tmpdir } from 'node:os'
|
|
19
|
+
import { pathToFileURL } from 'node:url'
|
|
20
|
+
import { requireTarget } from './paths.mjs'
|
|
21
|
+
|
|
22
|
+
// 不读用户自己的运行时配置:他在界面上设了哪个模型是他的事。
|
|
23
|
+
process.env.DSH_HOME = await mkdtemp(join(tmpdir(), 'pf-steer-home-'))
|
|
24
|
+
|
|
25
|
+
const mod = await import(pathToFileURL(requireTarget()).href + `?t=${Date.now()}`)
|
|
26
|
+
|
|
27
|
+
/** 假 ctx:只接住命令注册,别的按需给空实现。 */
|
|
28
|
+
function fakeCtx() {
|
|
29
|
+
const commands = new Map()
|
|
30
|
+
const ctx = {
|
|
31
|
+
tools: { register() { return () => {} } },
|
|
32
|
+
systemPrompt: { section() { return () => {} }, getSectionOrder() { return 2800 } },
|
|
33
|
+
effect(fn) { fn() },
|
|
34
|
+
inject(names, fn) {
|
|
35
|
+
if (!names.includes('commands')) return
|
|
36
|
+
fn({
|
|
37
|
+
get: key => (key === 'commands'
|
|
38
|
+
? { register(definition) { commands.set(definition.name, definition); return () => commands.delete(definition.name) } }
|
|
39
|
+
: undefined),
|
|
40
|
+
effect: inner => inner(),
|
|
41
|
+
})
|
|
42
|
+
},
|
|
43
|
+
get() { return undefined },
|
|
44
|
+
on() { return () => {} },
|
|
45
|
+
logger: { info() {}, warn() {}, error() {} },
|
|
46
|
+
root: {},
|
|
47
|
+
}
|
|
48
|
+
mod.apply(ctx, {})
|
|
49
|
+
return commands
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const commands = fakeCtx()
|
|
53
|
+
const cwd = await mkdtemp(join(tmpdir(), 'pf-steer-'))
|
|
54
|
+
|
|
55
|
+
/** 接口和真 agent 一致的最小实现:只记下 steer 收到的消息。 */
|
|
56
|
+
function fakeAgent({ withSteer = true } = {}) {
|
|
57
|
+
const steered = []
|
|
58
|
+
const agent = { session: { header: { cwd } } }
|
|
59
|
+
if (withSteer) agent.steer = message => { steered.push(message) }
|
|
60
|
+
return { agent, steered }
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 宿主会话对 user 消息的硬要求(dsh-session 的 assertMessageEventShape)。
|
|
65
|
+
* 形状不对的消息会在 append 时被拒,等于又变成「什么都没发生」。
|
|
66
|
+
*/
|
|
67
|
+
function assertShippableUserMessage(message) {
|
|
68
|
+
assert.equal(typeof message, 'object', 'steer 的参数应该是消息对象')
|
|
69
|
+
assert.equal(typeof message.id, 'string', '消息要有 id')
|
|
70
|
+
assert.ok(message.id.length > 0, 'id 不能是空串')
|
|
71
|
+
assert.equal(message.role, 'user', '这必须是 user 角色的消息')
|
|
72
|
+
assert.ok(Array.isArray(message.content), 'content 要是数组')
|
|
73
|
+
assert.ok(message.content.some(block => block.type === 'text' && typeof block.text === 'string' && block.text !== ''),
|
|
74
|
+
'content 里要有一段非空文本')
|
|
75
|
+
assert.equal(typeof message.source, 'object', 'source 要有')
|
|
76
|
+
assert.equal(typeof message.source.kind, 'string', 'source.kind 要是字符串')
|
|
77
|
+
assert.ok(message.source.kind.length > 0, 'source.kind 不能是空串')
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const textOf = message => message.content.filter(block => block.type === 'text').map(block => block.text).join('\n')
|
|
81
|
+
|
|
82
|
+
test('/flow 的指令进了 agent 的收件箱,形状过得了会话校验', async () => {
|
|
83
|
+
const { agent, steered } = fakeAgent()
|
|
84
|
+
const result = await commands.get('flow').handler({ rawInput: '给仓库加一个 CHANGELOG 段落', agent, signal: undefined })
|
|
85
|
+
assert.equal(steered.length, 1, '正好 steer 一条,不多不少')
|
|
86
|
+
assertShippableUserMessage(steered[0])
|
|
87
|
+
assert.match(textOf(steered[0]), /CHANGELOG/u, '用户输入的那句话要原样带进指令')
|
|
88
|
+
assert.match(textOf(steered[0]), /ask_user_question/u, '第 1 阶的提问要求要在指令里')
|
|
89
|
+
assert.match(textOf(steered[0]), /project_run/u, '要指明交给哪个工具')
|
|
90
|
+
assert.equal(result.kind, 'success')
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
test('/flow 的返回值只是一句回执,不再谎报整段指令', async () => {
|
|
94
|
+
const { agent } = fakeAgent()
|
|
95
|
+
const result = await commands.get('flow').handler({ rawInput: '随便一个活', agent, signal: undefined })
|
|
96
|
+
assert.ok(result.text.length < 40, `回执要短,实际是 ${result.text.length} 字`)
|
|
97
|
+
assert.ok(!result.text.includes('ask_user_question'), '门槛说明不该再出现在返回值里')
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
test('/flow 留空输入时先让模型问,而不是自己编一个任务', async () => {
|
|
101
|
+
const { agent, steered } = fakeAgent()
|
|
102
|
+
await commands.get('flow').handler({ rawInput: '', agent, signal: undefined })
|
|
103
|
+
assert.equal(steered.length, 1)
|
|
104
|
+
assert.match(textOf(steered[0]), /还没说是什么/u)
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
test('/flow 在没 steer 的老宿主上退回纯文本,不崩也不静默', async () => {
|
|
108
|
+
const { agent, steered } = fakeAgent({ withSteer: false })
|
|
109
|
+
const result = await commands.get('flow').handler({ rawInput: '老宿主', agent, signal: undefined })
|
|
110
|
+
assert.equal(steered.length, 0, '没有 steer 就什么都不该塞')
|
|
111
|
+
assert.equal(result.kind, 'success', '不能改成报错')
|
|
112
|
+
assert.match(result.text, /ask_user_question/u, '退回时要把指令原样显示出来,让用户至少能看见')
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
test('/flow-resume 带项目名时走 steer', async () => {
|
|
116
|
+
const { agent, steered } = fakeAgent()
|
|
117
|
+
const result = await commands.get('flow-resume').handler({ rawInput: '不存在的项目', agent, signal: undefined })
|
|
118
|
+
assert.equal(steered.length, 1)
|
|
119
|
+
assertShippableUserMessage(steered[0])
|
|
120
|
+
assert.match(textOf(steered[0]), /project_resume|project_doctor/u, '要指明接下来调哪个工具')
|
|
121
|
+
assert.equal(result.kind, 'success')
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
test('/flow-resume 不带项目名是纯展示:列清单,不动模型', async () => {
|
|
125
|
+
const { agent, steered } = fakeAgent()
|
|
126
|
+
const result = await commands.get('flow-resume').handler({ rawInput: '', agent, signal: undefined })
|
|
127
|
+
assert.equal(steered.length, 0, '没指定项目时不该替用户决定续哪个')
|
|
128
|
+
assert.equal(typeof result.text, 'string')
|
|
129
|
+
assert.ok(result.text.length > 0)
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
test('纯展示类命令一律不 steer', async () => {
|
|
133
|
+
const names = ['flow-status', 'flow-models', 'flow-cost', 'flow-prices', 'flow-snapshots', 'flow-patterns', 'flow-domain', 'flow-doctor', 'flow-set']
|
|
134
|
+
for (const name of names) {
|
|
135
|
+
const command = commands.get(name)
|
|
136
|
+
assert.ok(command !== undefined, `${name} 应该注册着,别在测试里凭空假设`)
|
|
137
|
+
const { agent, steered } = fakeAgent()
|
|
138
|
+
await command.handler({ rawInput: '', agent, signal: undefined })
|
|
139
|
+
assert.equal(steered.length, 0, `${name} 是纯展示,不该往对话里塞消息`)
|
|
140
|
+
}
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
test('steerInstruction 对坏输入说不,而不是抛出去', async () => {
|
|
144
|
+
assert.equal(await mod.steerInstruction(undefined, 'x'), false, '没有 agent 就交不出去')
|
|
145
|
+
assert.equal(await mod.steerInstruction({}, 'x'), false, 'agent 没有 steer 就交不出去')
|
|
146
|
+
assert.equal(await mod.steerInstruction({ steer() {} }, ' '), false, '空指令没有意义')
|
|
147
|
+
const seen = []
|
|
148
|
+
const ok = await mod.steerInstruction({ steer: message => seen.push(message) }, '一句话')
|
|
149
|
+
assert.equal(ok, true)
|
|
150
|
+
assertShippableUserMessage(seen[0])
|
|
151
|
+
})
|
|
@@ -12,9 +12,14 @@ import { existsSync } from 'node:fs'
|
|
|
12
12
|
import { join, dirname } from 'node:path'
|
|
13
13
|
import { tmpdir } from 'node:os'
|
|
14
14
|
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
15
|
+
import { LIVE_DIR } from './paths.mjs'
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
void dirname
|
|
18
|
+
void fileURLToPath
|
|
19
|
+
// 以前这里把安装路径写死了。别人下载这个包、或在开发目录里跑,都会
|
|
20
|
+
// 悄悄验到「已经装好的旧副本」——看起来全过,其实验的不是手上这份代码。
|
|
21
|
+
// 走 paths.mjs 就跟着 PF_LIVE_DIR / 包根走。
|
|
22
|
+
const LIVE = join(LIVE_DIR, 'index.js')
|
|
18
23
|
const mod = await import(pathToFileURL(LIVE).href + `?t=${Date.now()}`)
|
|
19
24
|
|
|
20
25
|
const results = []
|
|
@@ -14,9 +14,10 @@ import { mkdir, writeFile, rm, mkdtemp } from 'node:fs/promises'
|
|
|
14
14
|
import { join, dirname } from 'node:path'
|
|
15
15
|
import { tmpdir } from 'node:os'
|
|
16
16
|
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
17
|
+
import { LIVE_DIR } from './paths.mjs'
|
|
17
18
|
|
|
18
19
|
const here = dirname(fileURLToPath(import.meta.url))
|
|
19
|
-
const LIVE = '
|
|
20
|
+
const LIVE = join(LIVE_DIR, 'index.js')
|
|
20
21
|
const mod = await import(pathToFileURL(LIVE).href + `?t=${Date.now()}`)
|
|
21
22
|
|
|
22
23
|
const SETTINGS = {
|
package/ui/prompt.mjs
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 注入给模型的那段系统提示:四阶是什么、门控怎么走、按钮是什么。
|
|
3
|
+
*/
|
|
4
|
+
import { COPYRIGHT, FLOW_DIR_NAME, INTENT_CONFIDENCE_FLOOR } from '../shared/constants.mjs'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 返回卸载函数,交给调用方挂到 ctx.effect 上。
|
|
8
|
+
* 整段就是一条 ctx.inject:宿主有那个服务时才跑,服务晚到也能补上。
|
|
9
|
+
*/
|
|
10
|
+
export function createPrompt(ctx) {
|
|
11
|
+
return ctx.systemPrompt.section({
|
|
12
|
+
name: 'project-flow:policy',
|
|
13
|
+
// A renamed SECTION_ORDERS key would make this NaN and throw inside
|
|
14
|
+
// section(), taking the whole plugin down; fall back to the known value.
|
|
15
|
+
order: (ctx.systemPrompt.getSectionOrder('TOOL_SUBAGENT') ?? 2800) + 1,
|
|
16
|
+
text: () => `## 工作模式(项目流程)
|
|
17
|
+
|
|
18
|
+
**用户的命令永远排在第一位。** 这套流程只约束「怎么把活干完」,不约束「干什么」。
|
|
19
|
+
用户说停就停、说改就改、说换模型就换模型,不需要先走完手里的阶段,也不需要用流程
|
|
20
|
+
本身去论证该不该听。流程和用户指令冲突时,永远按用户的。唯一例外是用户让你做的事
|
|
21
|
+
会直接弄坏他自己的东西、而你还没说清后果——那就先说清,然后照做。
|
|
22
|
+
|
|
23
|
+
**用户说「继续」,就是在给你下一个命令,不是在征求你的意见。** 这时先看
|
|
24
|
+
\`.project-flow/\` 里有没有停住的项目(\`state.json\` 的 \`status\` 是 \`stopped\` 或
|
|
25
|
+
带 \`interruptedAt\`、且 \`stage\` 没到 4)。有就直接调 \`project_resume\`,项目名从
|
|
26
|
+
目录名取;有多个就挑 \`interruptedAt\` 最新的那个。不要重新 \`project_run\`,
|
|
27
|
+
不要重问需求,不要把已经跑过的段重做一遍。
|
|
28
|
+
|
|
29
|
+
**工作模式只在「${FLOW_DIR_NAME}」目录里开。** 这是给用户的一道分界线,不是权限墙:
|
|
30
|
+
重要的、值得留档、要复盘的任务,把工作目录切到那里再开工;不重要的直接做,不用走这套。
|
|
31
|
+
不在那个目录里时 \`project_run\` 会直接拒绝并告诉用户该去哪,你不要绕过、不要换个目录重试、
|
|
32
|
+
也不要自己手动模拟四阶流程——照直说这一句就行:「这个放普通任务里做就行,要留档的话挪到
|
|
33
|
+
${FLOW_DIR_NAME} 目录」。
|
|
34
|
+
|
|
35
|
+
遇到需要产出或改动的任务,先问用户一句「这次开工作模式吗」。开了就按四阶走,没开就正常做。
|
|
36
|
+
|
|
37
|
+
**四阶隔离,靠文件串联,上下文不进内存。** 每一阶开一个独立子会话,跑完即销毁,
|
|
38
|
+
它只拿到上一阶落盘的文件。所以文件写得好不好,直接决定下一阶跑不跑偏。
|
|
39
|
+
|
|
40
|
+
| 阶 | 谁在跑 | 读 | 写 |
|
|
41
|
+
|---|---|---|---|
|
|
42
|
+
| 1 需求 | 主对话(子会话问不了用户) | — | \`Requirement.md\` |
|
|
43
|
+
| 2 规划 | 子会话 A | \`Requirement.md\` | \`Plan.md\` |
|
|
44
|
+
| 3 实施 | 子会话 B | \`Plan.md\`(返工时加 \`QA_Report.md\`) | \`Execution_Log.md\` + 代码 |
|
|
45
|
+
| 4 质检 | 子会话 C | \`Requirement.md\` \`Plan.md\` \`Execution_Log.md\`,外加一份从快照仓库算出来的 \`git diff\` | \`QA_Report.md\` |
|
|
46
|
+
|
|
47
|
+
**第 4 阶只输出 PASS 或 FAIL,不写建议、不写「基本通过」。** 判 FAIL 时 \`reasons\` 就是下一轮的修改清单,
|
|
48
|
+
带着 \`QA_Report.md\` 回第 3 阶重跑,最多返工 \`maxRework\` 次,超了停机交给你。
|
|
49
|
+
|
|
50
|
+
**第 1 阶不是走过场,它是硬门槛。** \`project_run\` 要求你交 \`intentConfidence\`(0-100)和 \`questionsAsked\`,低于 ${INTENT_CONFIDENCE_FLOOR} 分或一个问题都没问过会直接报错、不执行。所以:
|
|
51
|
+
- 用 \`ask_user_question\` **一次只问一个**,把真问题问出来,别一次甩一串。
|
|
52
|
+
- 每答一次就重新评估把握。到了 ${INTENT_CONFIDENCE_FLOOR} 分就停手开工,别凑问题、别为了流程而问。
|
|
53
|
+
- 用户说「就按这个做、别再问了」→ 传 \`override: true\` 并在 \`overrideReason\` 里写他的原话。
|
|
54
|
+
- 你没问但按默认定了的地方,全写进 \`assumptions\`,质检时要逐条核。
|
|
55
|
+
|
|
56
|
+
**推进前必须交《需求完备度自查表》,这不是走形式,是门控。** 输出一段 JSON:
|
|
57
|
+
|
|
58
|
+
\`\`\`json
|
|
59
|
+
{
|
|
60
|
+
"score": 96,
|
|
61
|
+
"blindspots": {
|
|
62
|
+
"permissions": "谁来做、要不要授权、凭证归谁——写出实际结论",
|
|
63
|
+
"concurrency": "同时几个人用、会不会撞车、量级多大——写出实际结论",
|
|
64
|
+
"edge_cases": "出错怎么办、空数据、超时、重试、能不能回滚——写出实际结论",
|
|
65
|
+
"stack": "用什么语言框架、跑在哪、能不能加依赖——写出实际结论",
|
|
66
|
+
"data_flow": "数据从哪来到哪去、存哪儿、谁能读——写出实际结论"
|
|
67
|
+
},
|
|
68
|
+
"assumptions": ["没问、按默认值定了的地方,写清验收时怎么核"]
|
|
69
|
+
}
|
|
70
|
+
\`\`\`
|
|
71
|
+
|
|
72
|
+
然后调 \`project_run\`,把 \`intentConfidence\` 填成上面的 score,\`blindspots\` 和 \`assumptions\` 原样传上去。
|
|
73
|
+
|
|
74
|
+
判定规则(代码层执行,不是建议):
|
|
75
|
+
- **两个条件同时满足才放行**:score 达到 ${INTENT_CONFIDENCE_FLOOR} 且五个盲区全部有结论。
|
|
76
|
+
- 分数够但漏一个盲区 → 拦。**分数是自评,改个数字零成本;清单要写具体结论,编不出来。两样都要。**
|
|
77
|
+
- 盲区全填但分数不够 → 也拦。
|
|
78
|
+
- 某个维度确实问不出来,就把它写进 \`assumptions\` 并说清验收时怎么核——但别把盲区留空当作「默认没问题」。
|
|
79
|
+
- 写「已确认」三个字骗不过检验:第 4 阶质检会拿这些结论逐条核。
|
|
80
|
+
|
|
81
|
+
**开工前先调 \`project_context\`。** 这个工作流目录上次确认过的五格结论和假设都在那儿。
|
|
82
|
+
能沿用的照原样交上去,只问这次确实变了的那一格——门控要的是「五格都有具体结论」,
|
|
83
|
+
不是「每一格都要重新问一遍」。同一件事问用户两遍,比问不清楚更让人烦。
|
|
84
|
+
|
|
85
|
+
已开启时:
|
|
86
|
+
|
|
87
|
+
1. 第 1 阶在主对话完成:一次只问一个问题,问出真实意图,并和用户确认一份逐条可核对的「要求清单」。不确认完不进入第 2 段。
|
|
88
|
+
2. 第 2 至 4 段调用 \`project_run\` 一次完成:规划、实施、质检都在独立子会话里跑,彼此只传任务书,不传过程。你不参与其中,也不要把中间产物搬进对话。这三段各自用哪个模型由插件配置决定;用户问起时用 \`project_models\` 查,不要凭印象回答。
|
|
89
|
+
3. \`project_run\` 返回 \`passed\` 就结束了,没有第 5 段。给用户的汇报你自己写:说清哪几条做到了、哪几条没做到、返工几次、残留什么风险。不要只说好话,也别把 \`QA_Report.md\` 的 PASS 当成「用户一定满意」。
|
|
90
|
+
4. \`project_run\` 返回 \`stopped\` 或 \`blocked\` 时应停手把情况交给用户,不要自己加循环重跑。查进度用 \`project_status\`。
|
|
91
|
+
5. 第 1 阶和用户对话时,如果用户指定的意图模型不是当前主对话模型,提醒他先在界面顶部切换——这一段插件切不了。
|
|
92
|
+
6. 插件自带自愈:单段异常会自动重试并带超时;进程崩了、插件重载、窗口被杀之后,用 \`project_resume\` 按磁盘产物从中断那段接着跑,不要从头重来。怀疑工作区有问题(遗留锁、state.json 损坏、悬空阶段)时先跑 \`project_doctor\`,默认只报告,\`fix: true\` 才动手。
|
|
93
|
+
7. 每次实施前后会自动打快照。用户说「改废了」「回滚」「退回刚才的样子」时,先用 \`project_snapshots\` 列出目标,再用 \`project_rollback\` 干跑给 diff,用户确认后才 \`dryRun: false\` 真回滚。\`mode: "full"\` 整棵恢复、\`mode: "precise"\` 只还原那一轮动过的文件;说不清就用 full。
|
|
94
|
+
|
|
95
|
+
**输入框上方那条状态栏**显示阶段灯、各阶模型和停止/继续两个按钮。它和你是两条独立的路:用户点停止,这一轮立刻停在原地,返回 \`outcome: "stopped"\` 而不是报错;用户点继续或说「继续」,按上面说的调 \`project_resume\`。用户点的按钮不需要你复述或解释,也不要劝他改成别的方式。
|
|
96
|
+
|
|
97
|
+
子 agent 问不了用户,所以只有你能问;把答案压成要求清单再交给流程。
|
|
98
|
+
(${COPYRIGHT} · dsh-project-flow · PolyForm Small Business 1.0.0,小公司和个人可直接商用)`,
|
|
99
|
+
})
|
|
100
|
+
}
|
|
101
|
+
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 本机模型目录:装了哪些 provider、每个下面有哪些模型。只有 LLM 注册表能回答。
|
|
3
|
+
*/
|
|
4
|
+
import { resolvePriceTable } from '../watchdog.mjs'
|
|
5
|
+
import { messageOf } from '../shared/util.mjs'
|
|
6
|
+
import { pfState } from '../state/registry.mjs'
|
|
7
|
+
|
|
8
|
+
export function createModels(ctx) {
|
|
9
|
+
|
|
10
|
+
let clientModules
|
|
11
|
+
ctx.inject(['clientModules'], modulesCtx => {
|
|
12
|
+
pfState.clientModules = modulesCtx.get('clientModules')
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
// 浏览器那半边到底跑到哪一步了,从这边看不见。所以让它反过来打这个宿主路由:
|
|
16
|
+
// apply 跑起来打一次(stage=apply),第一次渲染打一次(stage=render)。
|
|
17
|
+
// 宿主记一笔,/flow-diag 读出来——不用开控制台就能分辨
|
|
18
|
+
// 「bundle 没物化」和「物化了但没渲染」这两件完全不同的事。
|
|
19
|
+
const clientHits = []
|
|
20
|
+
// LLM 注册表:本机装了哪些 provider、每个 provider 下有哪些模型,只有它能回答。
|
|
21
|
+
// 之前客户端把三个模型名写死在代码里——别人的 dsh 里可能一个都没有。
|
|
22
|
+
let llm
|
|
23
|
+
ctx.inject(['llm'], llmCtx => {
|
|
24
|
+
pfState.llm = llmCtx.get('llm')
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 活着的会话表:用它把一个 sessionId 反查成「这个会话在哪个目录」。
|
|
29
|
+
*
|
|
30
|
+
* 必须走 ctx.inject 拿到,不能直接 ctx.get('agents')——Cordis 对没在 inject
|
|
31
|
+
* 里声明的服务是「访问即抛」,外面再包 try/catch 也只会得到 undefined。
|
|
32
|
+
* 之前就是栽在这儿:状态栏只带着 sid 来问目录,宿主这边 quietly 拿不到 agents,
|
|
33
|
+
* 于是每次都回 empty,状态栏整块空着。
|
|
34
|
+
*/
|
|
35
|
+
let agents
|
|
36
|
+
ctx.inject(['agents'], agentsCtx => {
|
|
37
|
+
pfState.agents = agentsCtx.get('agents')
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
const listModelCatalog = async () => {
|
|
41
|
+
if (pfState.llm === undefined) return { providers: [], error: 'llm 服务取不到' }
|
|
42
|
+
let providers = []
|
|
43
|
+
try {
|
|
44
|
+
providers = pfState.llm.listProviders() ?? []
|
|
45
|
+
} catch (error) {
|
|
46
|
+
return { providers: [], error: `listProviders 失败:${messageOf(error)}` }
|
|
47
|
+
}
|
|
48
|
+
const groups = []
|
|
49
|
+
for (const provider of providers) {
|
|
50
|
+
try {
|
|
51
|
+
const models = await pfState.llm.listModels(provider.id)
|
|
52
|
+
groups.push({
|
|
53
|
+
id: provider.id,
|
|
54
|
+
name: typeof provider.name === 'string' ? provider.name : provider.id,
|
|
55
|
+
models: (models ?? []).map(model => ({
|
|
56
|
+
id: model.id,
|
|
57
|
+
name: typeof model.name === 'string' && model.name !== '' ? model.name : model.id,
|
|
58
|
+
})),
|
|
59
|
+
})
|
|
60
|
+
} catch {
|
|
61
|
+
// 单个 provider 挂了不该连累整张表,但要让调用方知道它存在过
|
|
62
|
+
groups.push({ id: provider.id, name: provider.id, models: [], failed: true })
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return { providers: groups.filter(group => group.models.length > 0 || group.failed === true) }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const unknownModelMessage = async model => {
|
|
69
|
+
if (typeof model !== 'string' || model.trim() === '') return undefined
|
|
70
|
+
const wanted = model.trim()
|
|
71
|
+
const catalog = await listModelCatalog()
|
|
72
|
+
const known = []
|
|
73
|
+
for (const group of catalog.providers ?? []) {
|
|
74
|
+
for (const item of group.models ?? []) {
|
|
75
|
+
if (typeof item.id !== 'string' || item.id === '') continue
|
|
76
|
+
known.push(item.id, `${group.id}/${item.id}`, `${group.id} ${item.id}`)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (known.length === 0) return undefined
|
|
80
|
+
const lower = wanted.toLowerCase()
|
|
81
|
+
if (known.some(id => id.toLowerCase() === lower)) return undefined
|
|
82
|
+
const unique = [...new Set(known)]
|
|
83
|
+
return `模型「${wanted}」不在本机可用列表里,没有写入。可用的有:\n${unique.map(id => ` ${id}`).join('\n')}`
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const refreshDetectedModels = async () => {
|
|
87
|
+
try {
|
|
88
|
+
const catalog = await listModelCatalog()
|
|
89
|
+
const ids = []
|
|
90
|
+
const seen = new Set()
|
|
91
|
+
for (const group of catalog.providers ?? []) {
|
|
92
|
+
for (const model of group.models ?? []) {
|
|
93
|
+
if (typeof model?.id !== 'string' || model.id === '' || seen.has(model.id)) continue
|
|
94
|
+
seen.add(model.id)
|
|
95
|
+
ids.push(model.id)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// 一个都没读到时别把上一次的好数据冲掉
|
|
99
|
+
if (ids.length > 0) pfState.detectedModelIds = ids
|
|
100
|
+
return { ids, error: catalog.error }
|
|
101
|
+
} catch (error) {
|
|
102
|
+
return { ids: pfState.detectedModelIds, error: messageOf(error) }
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const priceTableNow = settings => resolvePriceTable(settings.priceTable, pfState.detectedModelIds)
|
|
107
|
+
|
|
108
|
+
return { listModelCatalog, unknownModelMessage, refreshDetectedModels, priceTableNow }
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|