dsh-project-flow 0.9.3 → 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 +197 -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 +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 +5 -0
- package/tests/snapshot-core.test.mjs +234 -0
- package/tests/stage-model.test.mjs +2 -2
- 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,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* snapshotsTool。正文原样搬自 runner/tools.mjs 654-723。
|
|
3
|
+
*/
|
|
4
|
+
import { assertProjectName, cwdOf } from '../../workspace/paths.mjs'
|
|
5
|
+
import { defineTool } from '../../shared/tool.mjs'
|
|
6
|
+
import { gitAvailable, listSnapshots } from '../../snapshot/repo.mjs'
|
|
7
|
+
import { isAbsolute } from 'node:path'
|
|
8
|
+
import { readState } from '../../persistence/state.mjs'
|
|
9
|
+
|
|
10
|
+
export function create(ctx, rt) {
|
|
11
|
+
const snapshotsTool = defineTool({
|
|
12
|
+
name: 'project_snapshots',
|
|
13
|
+
description: '列出某个项目的全部快照与每次实施动了哪些文件,供回滚选取目标。只读。',
|
|
14
|
+
parameters: {
|
|
15
|
+
project: {
|
|
16
|
+
type: 'string',
|
|
17
|
+
required: true,
|
|
18
|
+
description: '项目名,即 .project-flow/ 下那个目录名。',
|
|
19
|
+
},
|
|
20
|
+
limit: {
|
|
21
|
+
type: 'integer',
|
|
22
|
+
description: '最多列几条,默认 20。',
|
|
23
|
+
},
|
|
24
|
+
cwd: {
|
|
25
|
+
type: 'string',
|
|
26
|
+
description: '.project-flow 所在的绝对目录;不填就用当前对话的工作目录。',
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
output: {
|
|
30
|
+
schema: {
|
|
31
|
+
type: 'object',
|
|
32
|
+
additionalProperties: false,
|
|
33
|
+
required: ['line', 'entries'],
|
|
34
|
+
properties: {
|
|
35
|
+
line: { type: 'string' },
|
|
36
|
+
entries: { type: 'array', items: { type: 'string' } },
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
render: (_args, value) => [{
|
|
40
|
+
type: 'text',
|
|
41
|
+
text: [value.line, ...value.entries].join('\n'),
|
|
42
|
+
}],
|
|
43
|
+
},
|
|
44
|
+
async execute(args, exec) {
|
|
45
|
+
const cwd = args.cwd !== undefined && isAbsolute(args.cwd) ? args.cwd : cwdOf(ctx, exec.agent)
|
|
46
|
+
const project = assertProjectName(args.project)
|
|
47
|
+
const limit = typeof args.limit === 'number' && args.limit > 0 ? args.limit : 20
|
|
48
|
+
if (await gitAvailable() !== true) {
|
|
49
|
+
return { line: `项目 ${project}:这台机器上没有可用的 git,快照与回滚不可用。`, entries: [] }
|
|
50
|
+
}
|
|
51
|
+
const state = await readState(cwd, project)
|
|
52
|
+
const attempts = Array.isArray(state?.attempts) ? state.attempts : []
|
|
53
|
+
const snaps = await listSnapshots(cwd, project, limit)
|
|
54
|
+
if (snaps.length === 0) {
|
|
55
|
+
return {
|
|
56
|
+
line: attempts.length === 0
|
|
57
|
+
? `项目 ${project}:还没有快照(第 3 段实施前才会打第一张)。`
|
|
58
|
+
: `项目 ${project}:state.json 里有 ${attempts.length} 次实施记录,但快照仓库是空的(可能被删了)。`,
|
|
59
|
+
entries: attempts.map(a => `第 ${a.round} 轮实施:${(a.files ?? []).length} 个文件 · ${a.summary ?? ''}`),
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const roundsAt = new Map()
|
|
63
|
+
const tag = (commit, round) => {
|
|
64
|
+
if (typeof commit !== 'string' || commit === '') return
|
|
65
|
+
roundsAt.set(commit, [...(roundsAt.get(commit) ?? []), round])
|
|
66
|
+
}
|
|
67
|
+
for (const attempt of attempts) {
|
|
68
|
+
tag(attempt.before, `第 ${attempt.round} 轮实施前`)
|
|
69
|
+
tag(attempt.after, `第 ${attempt.round} 轮实施后`)
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
line: `项目 ${project}:${snaps.length} 张快照(新→旧),回滚时用 commit 或「第 N 轮」都行。`,
|
|
73
|
+
entries: snaps.map(snap => {
|
|
74
|
+
const marks = roundsAt.get(snap.commit)
|
|
75
|
+
return `${snap.commit.slice(0, 8)} ${snap.at} ${snap.label}${marks === undefined ? '' : ` ← ${marks.join(' / ')}`}`
|
|
76
|
+
}),
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
return snapshotsTool
|
|
83
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* statusTool。正文原样搬自 runner/tools.mjs 1147-1201。
|
|
3
|
+
*/
|
|
4
|
+
import { assertProjectName, cwdOf } from '../../workspace/paths.mjs'
|
|
5
|
+
import { defineTool } from '../../shared/tool.mjs'
|
|
6
|
+
import { isAbsolute, join } from 'node:path'
|
|
7
|
+
import { listProjectLines, statusLine } from '../../workspace/panel.mjs'
|
|
8
|
+
import { readEvidence, EVIDENCE_FILE, evidenceSummary } from '../../evidence.mjs'
|
|
9
|
+
import { readState } from '../../persistence/state.mjs'
|
|
10
|
+
import { stateDir } from '../../shared/util.mjs'
|
|
11
|
+
|
|
12
|
+
export function create(ctx, rt) {
|
|
13
|
+
const statusTool = defineTool({
|
|
14
|
+
name: 'project_status',
|
|
15
|
+
description: '看一个项目现在跑到第几段,或者列出全部项目。只给状态灯,不给过程日志。',
|
|
16
|
+
parameters: {
|
|
17
|
+
project: {
|
|
18
|
+
type: 'string',
|
|
19
|
+
description: '项目名;不填就列出工作目录下所有项目。',
|
|
20
|
+
},
|
|
21
|
+
cwd: {
|
|
22
|
+
type: 'string',
|
|
23
|
+
description: '.project-flow 所在的绝对目录;不填就用当前对话的工作目录。',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
output: {
|
|
27
|
+
schema: {
|
|
28
|
+
type: 'object',
|
|
29
|
+
additionalProperties: false,
|
|
30
|
+
required: ['line', 'projects'],
|
|
31
|
+
properties: {
|
|
32
|
+
line: { type: 'string' },
|
|
33
|
+
projects: { type: 'array', items: { type: 'string' } },
|
|
34
|
+
evidence: { type: 'string' },
|
|
35
|
+
evidenceText: { type: 'string' },
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
render: (_args, value) => [{
|
|
39
|
+
type: 'text',
|
|
40
|
+
text: [
|
|
41
|
+
value.projects.length === 0 ? value.line : [value.line, ...value.projects].join('\n'),
|
|
42
|
+
...(value.evidenceText === undefined || value.evidenceText === '' ? [] : ['', value.evidenceText]),
|
|
43
|
+
].join('\n'),
|
|
44
|
+
}],
|
|
45
|
+
},
|
|
46
|
+
async execute(args, exec) {
|
|
47
|
+
const cwd = args.cwd !== undefined && isAbsolute(args.cwd) ? args.cwd : cwdOf(ctx, exec.agent)
|
|
48
|
+
if (args.project !== undefined) {
|
|
49
|
+
const project = assertProjectName(args.project)
|
|
50
|
+
const state = await readState(cwd, project)
|
|
51
|
+
// 验收过的项目顺手把证据包读回来:比赛要取数,不该让人去翻目录。
|
|
52
|
+
const evidence = await readEvidence(stateDir(cwd, project))
|
|
53
|
+
const path = join(stateDir(cwd, project), EVIDENCE_FILE)
|
|
54
|
+
return {
|
|
55
|
+
line: statusLine(state),
|
|
56
|
+
projects: [],
|
|
57
|
+
evidence: evidence === undefined ? '' : path,
|
|
58
|
+
evidenceText: evidence === undefined
|
|
59
|
+
? '还没有完成证据包(跑通一次质检 PASS 才会生成)'
|
|
60
|
+
: `${evidenceSummary(evidence, path)}\n\n${JSON.stringify(evidence, null, 2)}`,
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const lines = await listProjectLines(cwd)
|
|
64
|
+
return { line: lines.length === 0 ? '还没有项目' : `${lines.length} 个项目:`, projects: lines }
|
|
65
|
+
},
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
return statusTool
|
|
70
|
+
}
|
package/runner/tools.mjs
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 十个工具的装配层。
|
|
3
|
+
*
|
|
4
|
+
* 每个工具的定义住在本目录下的一个文件里——改 project_run 的参数只动
|
|
5
|
+
* `run.mjs`,不用在 1300 行里滚。这里只做三件事:按依赖顺序建、收进一个
|
|
6
|
+
* 对象、导出去。
|
|
7
|
+
*
|
|
8
|
+
* 建的顺序有依赖:executeRun 先建(run 和 resume 都要调它),
|
|
9
|
+
* 然后才是十个工具。
|
|
10
|
+
*
|
|
11
|
+
* 正文一个字都没改,都是从原 tools.mjs 里按行区间整段搬的,
|
|
12
|
+
* 每个文件的开头注明了搬自哪几行。
|
|
13
|
+
*/
|
|
14
|
+
import { createExecuteRun } from './tools/execute-run.mjs'
|
|
15
|
+
import { create as createRun } from './tools/run.mjs'
|
|
16
|
+
import { create as createResume } from './tools/resume.mjs'
|
|
17
|
+
import { create as createDoctor } from './tools/doctor.mjs'
|
|
18
|
+
import { create as createSnapshots } from './tools/snapshots.mjs'
|
|
19
|
+
import { create as createRollback } from './tools/rollback.mjs'
|
|
20
|
+
import { create as createEstimate } from './tools/estimate.mjs'
|
|
21
|
+
import { create as createDecorateCost } from './tools/decorate-cost.mjs'
|
|
22
|
+
import { create as createContext } from './tools/context.mjs'
|
|
23
|
+
import { create as createStatus } from './tools/status.mjs'
|
|
24
|
+
import { create as createModels } from './tools/models.mjs'
|
|
25
|
+
import { create as createSet } from './tools/set.mjs'
|
|
26
|
+
import { settingsOf } from '../config/settings.mjs'
|
|
27
|
+
import { lastReadinessOf } from '../workspace/paths.mjs'
|
|
28
|
+
import { guardToolCall } from '../gate.mjs'
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param ctx 宿主上下文
|
|
32
|
+
* @param rt { runPipeline, priceTableNow, unknownModelMessage } 之类跨模块的服务
|
|
33
|
+
*/
|
|
34
|
+
export function createTools(ctx, rt) {
|
|
35
|
+
const executeRun = createExecuteRun(ctx, rt)
|
|
36
|
+
const decorateCost = createDecorateCost(ctx, rt)
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
executeRun,
|
|
40
|
+
runTool: createRun(ctx, { ...rt, executeRun, decorateCost }),
|
|
41
|
+
resumeTool: createResume(ctx, { ...rt, executeRun }),
|
|
42
|
+
doctorTool: createDoctor(ctx, rt),
|
|
43
|
+
snapshotsTool: createSnapshots(ctx, rt),
|
|
44
|
+
rollbackTool: createRollback(ctx, rt),
|
|
45
|
+
estimateTool: createEstimate(ctx, rt),
|
|
46
|
+
contextTool: createContext(ctx, rt),
|
|
47
|
+
statusTool: createStatus(ctx, rt),
|
|
48
|
+
modelsTool: createModels(ctx, rt),
|
|
49
|
+
setTool: createSet(ctx, rt),
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 注册十个工具,外加可选的意图门控。
|
|
55
|
+
*
|
|
56
|
+
* 返回值是清理函数:宿主重载插件时会调它,十个工具一起摘掉。
|
|
57
|
+
* 门控默认不注册——装上就该能用,不该先被一道门拦住;
|
|
58
|
+
* 要开就在配置里写 intentGate: 'enforce'。
|
|
59
|
+
*/
|
|
60
|
+
export function registerTools(ctx, tools) {
|
|
61
|
+
return ctx.effect(() => {
|
|
62
|
+
const offs = [
|
|
63
|
+
tools.runTool,
|
|
64
|
+
tools.resumeTool,
|
|
65
|
+
tools.doctorTool,
|
|
66
|
+
tools.snapshotsTool,
|
|
67
|
+
tools.rollbackTool,
|
|
68
|
+
tools.statusTool,
|
|
69
|
+
tools.contextTool,
|
|
70
|
+
tools.estimateTool,
|
|
71
|
+
tools.modelsTool,
|
|
72
|
+
tools.setTool,
|
|
73
|
+
].map(tool => ctx.tools.register(tool))
|
|
74
|
+
|
|
75
|
+
// 意图门控的前置拦截。
|
|
76
|
+
//
|
|
77
|
+
// 以前 gate.guardToolCall 写好了却从没接上来:只有 project_run 自己在
|
|
78
|
+
// execute 里检查 intentConfidence,模型想绕过就换个工具(比如先
|
|
79
|
+
// project_rollback 把工作区搅一遍再开跑)。接上之后任何工具调用都会先过这一关。
|
|
80
|
+
const gated = settingsOf().intentGate === 'enforce'
|
|
81
|
+
const offGuard = gated
|
|
82
|
+
? ctx.tools.guard(exec => {
|
|
83
|
+
const verdict = guardToolCall({ toolName: exec.name, readiness: lastReadinessOf(exec) })
|
|
84
|
+
if (verdict.allow) return undefined
|
|
85
|
+
return { reason: verdict.message }
|
|
86
|
+
})
|
|
87
|
+
: undefined
|
|
88
|
+
|
|
89
|
+
return () => {
|
|
90
|
+
for (const off of offs) off()
|
|
91
|
+
if (offGuard !== undefined) offGuard()
|
|
92
|
+
}
|
|
93
|
+
})
|
|
94
|
+
}
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 常量:文件名、门槛数值、白名单、默认值。改一处,全局生效。
|
|
3
|
+
*/
|
|
4
|
+
import z from '@deepseek-ai/schemastery'
|
|
5
|
+
import { SCORE_FLOOR, DIMENSIONS } from '../gate.mjs'
|
|
6
|
+
|
|
7
|
+
export const COPYRIGHT = '© 2026 刘适'
|
|
8
|
+
|
|
9
|
+
export const LICENSE_NOTICE = 'PolyForm Small Business 1.0.0;100 人以下且上一财年收入低于 100 万美元的公司与个人可直接商用,超过规模见 docs/COMMERCIAL.md'
|
|
10
|
+
|
|
11
|
+
export const Config = z.object({
|
|
12
|
+
provider: z.string().default('spawn'),
|
|
13
|
+
// 模型一律默认留空:留空就是「不覆盖父路由」,子会话直接继承主对话正在用的
|
|
14
|
+
// 模型。写死一个模型名看着省事,但换台电脑、换个 profile 就可能根本没有它,
|
|
15
|
+
// 整条流水会卡死在一句没有原因的 error 上——默认值必须是能跑的那个。
|
|
16
|
+
intentModel: z.string().default(''),
|
|
17
|
+
planModel: z.string().default(''),
|
|
18
|
+
buildModel: z.string().default(''),
|
|
19
|
+
checkModel: z.string().default(''),
|
|
20
|
+
planProvider: z.string().default(''),
|
|
21
|
+
buildProvider: z.string().default(''),
|
|
22
|
+
checkProvider: z.string().default(''),
|
|
23
|
+
maxRework: z.natural().default(2),
|
|
24
|
+
maxConcurrentProjects: z.natural().default(2),
|
|
25
|
+
// Self-healing knobs: retry a stage that ended abnormally, put a deadline on
|
|
26
|
+
// it, and treat a lock file older than staleLockMs as leftover from a crash.
|
|
27
|
+
maxStageRetries: z.natural().default(2),
|
|
28
|
+
stageRetryDelayMs: z.natural().default(3000),
|
|
29
|
+
stageTimeoutMs: z.natural().default(900000),
|
|
30
|
+
staleLockMs: z.natural().default(1800000),
|
|
31
|
+
// Snapshot / rollback knobs. Snapshots need git; without it the pipeline still
|
|
32
|
+
// runs and simply reports that rollback is unavailable.
|
|
33
|
+
snapshotEnabled: z.boolean().default(true),
|
|
34
|
+
snapshotExcludes: z.string().default(''),
|
|
35
|
+
/**
|
|
36
|
+
* 快照保留张数。每次实施前后各打一张,跑十几轮返工就上百张,只增不删会一直涨。
|
|
37
|
+
* 默认留最近 40 张,更老的截掉。设 0 = 不截断(老行为)。
|
|
38
|
+
*/
|
|
39
|
+
snapshotKeep: z.natural().default(40),
|
|
40
|
+
// 工作模式只在这个目录里开。留空就认「当前工作区下的 工作流 目录」,
|
|
41
|
+
// 填绝对路径就把整台机器的工作流固定到一个地方。
|
|
42
|
+
flowRoot: z.string().default(''),
|
|
43
|
+
/**
|
|
44
|
+
* 目录门控。三种值:
|
|
45
|
+
*
|
|
46
|
+
* off(默认)—— 不拦,装完就能用,在哪个目录都能开工作模式。这是默认值:
|
|
47
|
+
* 一个要装了就用的工具,不该先让人去建目录再切工作区。
|
|
48
|
+
* auto —— 能识别「工作流」目录就认它,识别不出来也不拦(与 off 的
|
|
49
|
+
* 区别只在「该去哪」这句提示上)。
|
|
50
|
+
* strict —— 只认「工作流」目录,别处直接拒绝。想让目录边界硬一点再开。
|
|
51
|
+
*
|
|
52
|
+
* 以前默认值是 strict 而注释写着「auto 默认不拦」,两句话互相矛盾;
|
|
53
|
+
* 'auto' 这一档甚至不在合法值里,写了会被悄悄归一成 strict。
|
|
54
|
+
*/
|
|
55
|
+
flowGate: z.string().default('off'),
|
|
56
|
+
/**
|
|
57
|
+
* 第一次在普通目录开工时,自动把「工作流」目录建出来。
|
|
58
|
+
* 只有 flowGate 为 strict 时才起作用:off / auto 下根本不会走到这一步。
|
|
59
|
+
*/
|
|
60
|
+
autoCreateFlowDir: z.boolean().default(true),
|
|
61
|
+
/**
|
|
62
|
+
* 意图门控的前置拦截强度。
|
|
63
|
+
*
|
|
64
|
+
* off(默认)—— 只由 project_run 自己检查,别处不拦。装上即可用。
|
|
65
|
+
* enforce —— 注册 ctx.tools.guard,任何推进类工具在自查表没过之前一律拦。
|
|
66
|
+
* 模型想靠换个工具绕开第 1 阶,靠这个堵。
|
|
67
|
+
*/
|
|
68
|
+
intentGate: z.string().default('off'),
|
|
69
|
+
/**
|
|
70
|
+
* 桌面工具(agent-desktop 那类插件提供的 desktop_* 工具)怎么用。
|
|
71
|
+
* auto:有视觉产出、或者行当本来就要在软件里核对时才提;on:一律提;off:不提。
|
|
72
|
+
* 没装那类插件时,写进 prompt 的也只是「没有就忽略」的条件句,不会硬要它去调。
|
|
73
|
+
*/
|
|
74
|
+
desktopTools: z.string().default('auto'),
|
|
75
|
+
/**
|
|
76
|
+
* 审美约束:auto 只在检测到视觉载体(PPT/网页/卡片/文档)时注入,
|
|
77
|
+
* always 一律注入,off 关掉。纯代码任务用 auto 就不会被塞一堆排版规矩。
|
|
78
|
+
*/
|
|
79
|
+
aesthetic: z.string().default('auto'),
|
|
80
|
+
/**
|
|
81
|
+
* 质检时把 preview/ 里的渲染图一并喂给子会话。
|
|
82
|
+
* 关掉只在「模型看不了图」的情况下有意义:那种时候喂图会直接报错。
|
|
83
|
+
*/
|
|
84
|
+
aestheticImages: z.boolean().default(true),
|
|
85
|
+
/**
|
|
86
|
+
* 开工前要不要上网搜优秀案例、把骨架攒进版式库。
|
|
87
|
+
* auto = 视觉类任务才搜;always = 一律搜;off = 不搜,只用库里已有的。
|
|
88
|
+
*/
|
|
89
|
+
aestheticSearch: z.string().default('auto'),
|
|
90
|
+
/** 每次给实施环节看几条骨架。太多会变成「都想要」。 */
|
|
91
|
+
aestheticPatterns: z.natural().min(1).max(8).default(3),
|
|
92
|
+
/** 库文件位置。留空走 DSH home 下的默认位置。 */
|
|
93
|
+
aestheticLibrary: z.string().default(''),
|
|
94
|
+
/**
|
|
95
|
+
* 这次按哪个行当的做法跑。auto = 按任务内容识别;也可以直接写 software /
|
|
96
|
+
* frontend / fashion / industrial / generic,或者你自己加在 domainsDir 里的 id。
|
|
97
|
+
*/
|
|
98
|
+
domain: z.string().default('auto'),
|
|
99
|
+
/**
|
|
100
|
+
* 自定义领域的目录,一个 JSON 一个领域。留空走 DSH home 下的默认位置。
|
|
101
|
+
* 这是给用户改插件用的入口:不用改代码,加个文件就是一套新行当的做法。
|
|
102
|
+
*/
|
|
103
|
+
domainsDir: z.string().default(''),
|
|
104
|
+
// Watchdog: three independent brakes on a run that is burning without
|
|
105
|
+
// producing. Each one aborts the stage, saves progress, and hands back.
|
|
106
|
+
watchdogEnabled: z.boolean().default(true),
|
|
107
|
+
maxRepeatErrors: z.natural().default(3),
|
|
108
|
+
silentMsPlan: z.natural().default(300000),
|
|
109
|
+
silentMsBuild: z.natural().default(900000),
|
|
110
|
+
silentMsCheck: z.natural().default(900000),
|
|
111
|
+
// 预算上限。用 z.number 而不是 z.natural:z.natural 只收整数,
|
|
112
|
+
// 想设 2.5 美元会被 schema 挡掉并报 "expected number multiple of 1"——
|
|
113
|
+
// 一个按字符估的花费上限,粒度卡在 1 美元太粗了。
|
|
114
|
+
budgetUsd: z.number().min(0).default(10),
|
|
115
|
+
// 价目表:JSON 字符串,键是模型名,值是 { input, output } 的每百万 token 美元价。
|
|
116
|
+
priceTable: z.string().default(''),
|
|
117
|
+
// 完成证据包:外部测试命令的 exit code 决定 requirement_met,
|
|
118
|
+
// 汇率只用来把估算的美元换成人民币。
|
|
119
|
+
// 默认 auto:按目录里的 package.json / pytest 配置 / 测试文件自己猜一条,
|
|
120
|
+
// 猜不到才如实写「没跑」——留空会让每个项目的证据包都显示「要求未满足」。
|
|
121
|
+
testCommand: z.string().default('auto'),
|
|
122
|
+
testTimeoutMs: z.natural().default(600000),
|
|
123
|
+
cnyRate: z.number().min(0.0001).default(7),
|
|
124
|
+
// ── 断言执行器 ──────────────────────────────────────────────
|
|
125
|
+
/**
|
|
126
|
+
* 额外放行的命令,逗号或空格分隔。默认那 9 类写死在代码里,这一项只能往上加:
|
|
127
|
+
* 白名单一旦可以被配置删空,「判据」就又回到模型嘴里了。
|
|
128
|
+
*/
|
|
129
|
+
checkAllowedCommands: z.string().default(''),
|
|
130
|
+
/**
|
|
131
|
+
* 严格判据模式:连 `node -e` / `python -c` 这类「把代码当参数」的调用也拒。
|
|
132
|
+
*
|
|
133
|
+
* 默认 false。这几个开关是写轻量判据的常见写法(`node -e "require('assert')..."`),
|
|
134
|
+
* 默认拦住等于把正常用法砍了。它挡的是手滑,不是刻意;想再紧一点再开。
|
|
135
|
+
* 注意:开了之后那些判据会记成 denied 而不是 pass,别一装上就开。
|
|
136
|
+
*/
|
|
137
|
+
checkStrictEval: z.boolean().default(false),
|
|
138
|
+
/** 单条 check 的超时。不是一轮总和:一轮里每条各自计时。 */
|
|
139
|
+
checkTimeoutMs: z.natural().default(120000),
|
|
140
|
+
/** stdout / stderr 留多少字符的尾巴。超长只留尾部——报错基本写在最后几行。 */
|
|
141
|
+
checkStdoutTailChars: z.natural().default(8000),
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
export const STAGE_LABEL = {
|
|
145
|
+
1: '需求',
|
|
146
|
+
2: '规划',
|
|
147
|
+
3: '实施',
|
|
148
|
+
4: '质检',
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export const STAGE_NO_OF = {
|
|
152
|
+
search: 2,
|
|
153
|
+
plan: 2,
|
|
154
|
+
build: 3,
|
|
155
|
+
check: 4,
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export const ARTIFACT = {
|
|
159
|
+
requirement: 'Requirement.md',
|
|
160
|
+
plan: 'Plan.md',
|
|
161
|
+
log: 'Execution_Log.md',
|
|
162
|
+
qa: 'QA_Report.md',
|
|
163
|
+
nextStep: 'Next_Step.md',
|
|
164
|
+
// 判据指纹:Requirement.md 里 check 字段的 sha256。第 2 阶入口算一次,
|
|
165
|
+
// 第 4 阶复算一次,对不上就停机——中途改判据等于自己给自己放水。
|
|
166
|
+
requirementHash: 'requirement.sha',
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export const STAGE_IO = {
|
|
170
|
+
1: { role: '需求', reads: [], writes: ['requirement'] },
|
|
171
|
+
2: { role: '规划', reads: ['requirement'], writes: ['plan'] },
|
|
172
|
+
3: { role: '实施', reads: ['plan'], writes: ['log'] },
|
|
173
|
+
4: { role: '质检', reads: ['requirement', 'plan', 'log'], writes: ['qa'] },
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export const LOG_TAIL_CHARS = 8000
|
|
177
|
+
|
|
178
|
+
export const MEDIA_TYPES = {
|
|
179
|
+
'.png': 'image/png',
|
|
180
|
+
'.jpg': 'image/jpeg',
|
|
181
|
+
'.jpeg': 'image/jpeg',
|
|
182
|
+
'.webp': 'image/webp',
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export const DIFF_LIMIT_CHARS = 24000
|
|
186
|
+
|
|
187
|
+
export const INTENT_CONFIDENCE_FLOOR = SCORE_FLOOR
|
|
188
|
+
|
|
189
|
+
export const BLINDSPOT_LABELS = Object.fromEntries(DIMENSIONS.map(dim => [dim.key, dim.label]))
|
|
190
|
+
|
|
191
|
+
export const FLOW_DIR_NAME = '工作流'
|
|
192
|
+
|
|
193
|
+
export const FLOW_GATE_MODES = ['off', 'auto', 'strict']
|
|
194
|
+
|
|
195
|
+
export const LOG_ROTATE_BYTES = 512 * 1024
|
|
196
|
+
|
|
197
|
+
export const CONTRACT_FILE = 'contract.json'
|
|
198
|
+
|
|
199
|
+
export const CONTRACT_MAX_CHARS = 1200
|
|
200
|
+
|
|
201
|
+
export const LAST_ROOT_FILE = 'project-flow.last-root'
|
|
202
|
+
|
|
203
|
+
export const CONTEXT_FILE = 'context.json'
|
|
204
|
+
|
|
205
|
+
export const LIST_SKIP_DIRS = new Set([
|
|
206
|
+
'.project-flow', '.git', '.hg', '.svn',
|
|
207
|
+
'node_modules', '.pnpm', 'bower_components',
|
|
208
|
+
'.venv', 'venv', 'env', '__pycache__', '.mypy_cache', '.pytest_cache',
|
|
209
|
+
'.next', '.nuxt', '.svelte-kit', 'dist', 'build', 'out', 'target',
|
|
210
|
+
'.cache', '.gradle', '.idea', '.vscode', 'coverage',
|
|
211
|
+
])
|
|
212
|
+
|
|
213
|
+
export const LIST_MAX_DEPTH = 4
|
|
214
|
+
|
|
215
|
+
export const LIST_MAX_ENTRIES = 4000
|
|
216
|
+
|
|
217
|
+
export const SNAPSHOT_MAX_BYTES = 2 * 1024 * 1024 * 1024
|
|
218
|
+
|
|
219
|
+
export const SNAPSHOT_MAX_FILES = 20000
|
|
220
|
+
|
|
221
|
+
export const DEFAULT_SNAPSHOT_EXCLUDES = [
|
|
222
|
+
'.project-flow/',
|
|
223
|
+
'.git/',
|
|
224
|
+
'node_modules/',
|
|
225
|
+
'.venv/',
|
|
226
|
+
'venv/',
|
|
227
|
+
'__pycache__/',
|
|
228
|
+
'.mypy_cache/',
|
|
229
|
+
'.pytest_cache/',
|
|
230
|
+
'.next/',
|
|
231
|
+
'.nuxt/',
|
|
232
|
+
'dist/',
|
|
233
|
+
'build/',
|
|
234
|
+
'.cache/',
|
|
235
|
+
'.DS_Store',
|
|
236
|
+
'Thumbs.db',
|
|
237
|
+
]
|
|
238
|
+
|
|
239
|
+
export const SEVERITIES = ['P0', 'P1', 'P2']
|
|
240
|
+
|
|
241
|
+
export const ISSUE_LIMIT = 50
|
|
242
|
+
|
|
243
|
+
export const DEFAULT_CHECK_TIMEOUT_MS = 120000
|
|
244
|
+
|
|
245
|
+
export const DEFAULT_CHECK_TAIL_CHARS = 8000
|
|
246
|
+
|
|
247
|
+
export const CHECK_MISSING_BINARY_LIMIT = 5
|
|
248
|
+
|
|
249
|
+
export const CODE_ESCAPE_FLAGS = {
|
|
250
|
+
node: ['-e', '--eval', '-p', '--print', '--experimental-loader', '--loader'],
|
|
251
|
+
python: ['-c'],
|
|
252
|
+
python3: ['-c'],
|
|
253
|
+
// 包运行器后面跟的是另一条命令,本身就是「绕过白名单去跑别的包」
|
|
254
|
+
npm: ['exec', 'x'],
|
|
255
|
+
pnpm: ['exec', 'dlx'],
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export const STRICT_ONLY_FLAGS = new Set(['node', 'python', 'python3'])
|
|
259
|
+
|
|
260
|
+
export const PACKAGE_RUNNERS = new Set(['exec', 'x', 'dlx'])
|
|
261
|
+
|
|
262
|
+
export const GIT_DANGEROUS_CONFIG = /^(core\.(pager|editor|hooksPath|sshCommand|askpass|fsmonitor)|diff\.(external|textconv)|credential\.helper|filter\.|.*\.command$)/iu
|
|
263
|
+
|
|
264
|
+
export const STAGE_TOKEN_BASELINE = {
|
|
265
|
+
2: { input: 60000, output: 12000, label: '规划' },
|
|
266
|
+
3: { input: 400000, output: 150000, label: '实施' },
|
|
267
|
+
4: { input: 220000, output: 30000, label: '质检' },
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export const FLOAT_SETTINGS = new Set(['cnyRate'])
|
|
271
|
+
|
|
272
|
+
export const DEFAULT_ALLOWED_COMMANDS = ['node', 'npm', 'pnpm', 'python', 'pytest', 'git', 'cargo', 'go', 'dotnet']
|
|
273
|
+
|
package/shared/tool.mjs
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 工具定义装配。不依赖 @deepseek-ai/dsh-tools——它不在注入包里,静态 import 会让插件起不来。
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export function defineTool(options) {
|
|
6
|
+
return {
|
|
7
|
+
name: options.name,
|
|
8
|
+
description: options.description,
|
|
9
|
+
parameters: compileParameters(options.parameters ?? {}),
|
|
10
|
+
output: options.output,
|
|
11
|
+
...(options.timeoutMs === undefined ? {} : { timeoutMs: options.timeoutMs }),
|
|
12
|
+
async execute(args, exec) {
|
|
13
|
+
return options.execute(args ?? {}, exec)
|
|
14
|
+
},
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function compileParameters(spec) {
|
|
19
|
+
const properties = {}
|
|
20
|
+
const required = []
|
|
21
|
+
for (const [key, property] of Object.entries(spec)) {
|
|
22
|
+
const { required: isRequired, description, ...schema } = property
|
|
23
|
+
properties[key] = description === undefined ? schema : { ...schema, description }
|
|
24
|
+
if (isRequired === true) required.push(key)
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
type: 'object',
|
|
28
|
+
properties,
|
|
29
|
+
...(required.length === 0 ? {} : { required }),
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|