openfeel 1.5.24 → 1.6.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/README.en.md +7 -0
- package/README.zh-CN.md +7 -0
- package/dist/commands/flow.d.ts.map +1 -1
- package/dist/commands/flow.js +117 -23
- package/dist/commands/flow.js.map +1 -1
- package/dist/commands/lint.d.ts +3 -1
- package/dist/commands/lint.d.ts.map +1 -1
- package/dist/commands/lint.js +96 -0
- package/dist/commands/lint.js.map +1 -1
- package/dist/commands/req.d.ts.map +1 -1
- package/dist/commands/req.js +392 -17
- package/dist/commands/req.js.map +1 -1
- package/dist/commands/stage.d.ts.map +1 -1
- package/dist/commands/stage.js +19 -0
- package/dist/commands/stage.js.map +1 -1
- package/dist/core/dev-status.d.ts +25 -0
- package/dist/core/dev-status.d.ts.map +1 -1
- package/dist/core/dev-status.js +35 -0
- package/dist/core/dev-status.js.map +1 -1
- package/dist/core/errors.d.ts +13 -3
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +9 -3
- package/dist/core/errors.js.map +1 -1
- package/dist/core/flow-manager.d.ts +109 -3
- package/dist/core/flow-manager.d.ts.map +1 -1
- package/dist/core/flow-manager.js +326 -14
- package/dist/core/flow-manager.js.map +1 -1
- package/dist/core/i18n-data/en.d.ts.map +1 -1
- package/dist/core/i18n-data/en.js +56 -2
- package/dist/core/i18n-data/en.js.map +1 -1
- package/dist/core/i18n-data/zh-CN.d.ts.map +1 -1
- package/dist/core/i18n-data/zh-CN.js +56 -2
- package/dist/core/i18n-data/zh-CN.js.map +1 -1
- package/dist/core/lint-req.d.ts +17 -1
- package/dist/core/lint-req.d.ts.map +1 -1
- package/dist/core/lint-req.js +14 -2
- package/dist/core/lint-req.js.map +1 -1
- package/dist/core/plan/body-lint.d.ts +58 -0
- package/dist/core/plan/body-lint.d.ts.map +1 -0
- package/dist/core/plan/body-lint.js +197 -0
- package/dist/core/plan/body-lint.js.map +1 -0
- package/dist/core/plan/filled.d.ts +143 -0
- package/dist/core/plan/filled.d.ts.map +1 -0
- package/dist/core/plan/filled.js +244 -0
- package/dist/core/plan/filled.js.map +1 -0
- package/dist/core/plan/path.d.ts +24 -0
- package/dist/core/plan/path.d.ts.map +1 -1
- package/dist/core/plan/path.js +56 -0
- package/dist/core/plan/path.js.map +1 -1
- package/dist/core/req/aggregate.d.ts.map +1 -1
- package/dist/core/req/aggregate.js +5 -0
- package/dist/core/req/aggregate.js.map +1 -1
- package/dist/core/req/body-file.d.ts +66 -0
- package/dist/core/req/body-file.d.ts.map +1 -1
- package/dist/core/req/body-file.js +184 -2
- package/dist/core/req/body-file.js.map +1 -1
- package/dist/core/req/requirement-ops.d.ts +128 -14
- package/dist/core/req/requirement-ops.d.ts.map +1 -1
- package/dist/core/req/requirement-ops.js +341 -16
- package/dist/core/req/requirement-ops.js.map +1 -1
- package/dist/core/req/types.d.ts +55 -0
- package/dist/core/req/types.d.ts.map +1 -1
- package/dist/core/template-loader.d.ts.map +1 -1
- package/dist/core/template-loader.js +75 -0
- package/dist/core/template-loader.js.map +1 -1
- package/dsh/ACTION-GUIDE.md +41 -8
- package/dsh/ADAPTER.md +58 -13
- package/dsh/README.md +45 -24
- package/dsh/docs/compat/persistence.md +13 -0
- package/dsh/docs/compat/pipeline.md +12 -0
- package/dsh/docs/compat/req.md +14 -0
- package/dsh/docs/compat/stage.md +13 -0
- package/dsh/lib/adapters/dashboard.js +10 -0
- package/dsh/lib/adapters/dispatch-ledger.js +293 -0
- package/dsh/lib/adapters/dispatch.js +54 -6
- package/dsh/lib/adapters/next-action.js +336 -0
- package/dsh/lib/guard.js +9 -2
- package/dsh/lib/index.js +37 -0
- package/dsh/lib/surface/prompt.js +62 -173
- package/dsh/lib/tools/index.js +435 -9
- package/dsh/package.json +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 动作型 next + 每步提醒(v1.6.0 / T10,REQ-060)
|
|
3
|
+
*
|
|
4
|
+
* 两个职责,都是**纯投影**(不做 I/O、不跑 CLI):
|
|
5
|
+
*
|
|
6
|
+
* 1. `deriveNextAction(snapshot)`:把「下一步该 who do what」变成可执行动作
|
|
7
|
+
* (`dispatch` / `command` / `idle`),由 `feel_status` / `feel_next` 返回。
|
|
8
|
+
* 旧 `next` 字符串/对象保留(不破坏既有断言),内容改成动作型。
|
|
9
|
+
* 2. 运行时提醒:`rememberFocus()` 由工具层在读到快照时喂入,
|
|
10
|
+
* `noteToolCall()` 由 `dsh/lib/index.js` 的 `tools/post-execute` 观察者喂入,
|
|
11
|
+
* `reminderText()` 供 `ctx.systemPrompt.context()` 每请求取值。
|
|
12
|
+
*
|
|
13
|
+
* 为什么提醒走 `systemPrompt.context` 而不是 `additionalContexts`:
|
|
14
|
+
* `tools/post-execute` + `additionalContexts` 在宿主侧确实存在(`dsh-tools/src/events.ts`、
|
|
15
|
+
* `contracts.ts` 的 `PostToolDecision.additionalContexts`),但 `additionalContexts`
|
|
16
|
+
* 的元素必须是 `UserMessage`,只能由 `@deepseek-ai/dsh-llm` 的 `createUserMessage()`
|
|
17
|
+
* 构造;本适配器零运行时依赖(`dsh/package.json` 无 dependencies),实测
|
|
18
|
+
* `createRequire(...).resolve('@deepseek-ai/dsh-llm')` → `MODULE_NOT_FOUND`。
|
|
19
|
+
* 手搓一个 `source.kind` 未注册的 UserMessage 会流进 `agent/inbox/spliced` 持久事件,
|
|
20
|
+
* 无运行时证据前不能赌它不破坏会话。故按 plan §5.3 降级 1:`systemPrompt.context`
|
|
21
|
+
* (动态 user 快照、逐请求刷新),post-execute 只做**观察**(不构造消息、不改结果)。
|
|
22
|
+
* 证据见 `.openfeel/tmp/stage-132/spike.md`。
|
|
23
|
+
*
|
|
24
|
+
* @module openfeel-dsh/adapters/next-action
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import { buildDispatchTemplate } from './dispatch.js';
|
|
28
|
+
|
|
29
|
+
/** 提醒上下文名(`ctx.systemPrompt.context` 的唯一标识;重名会抛错)。 */
|
|
30
|
+
export const REMINDER_CONTEXT_NAME = 'openfeel-feel-next';
|
|
31
|
+
|
|
32
|
+
/** 每 N 步至少提醒一次(plan §5.3:写类工具之后 + 每 5 步)。 */
|
|
33
|
+
export const REMINDER_EVERY_STEPS = 5;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 当前阶段是否「开启」(phase 非空且非 done)。
|
|
37
|
+
* @param {unknown} phase
|
|
38
|
+
* @returns {boolean}
|
|
39
|
+
*/
|
|
40
|
+
function isOpenPhase(phase) {
|
|
41
|
+
return typeof phase === 'string' && phase !== '' && phase !== 'done';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 取当前阶段关联需求。
|
|
46
|
+
*
|
|
47
|
+
* 与 `dispatch.js` 同源口径(优先 CLI 交接标记,回退阶段条目的 `requirementId`),
|
|
48
|
+
* 但这里不 import `requirementOf`(它未导出),保持两份实现的字段读取一致即可。
|
|
49
|
+
* @param {Record<string, any>} snapshot
|
|
50
|
+
* @returns {string}
|
|
51
|
+
*/
|
|
52
|
+
function requirementOf(snapshot) {
|
|
53
|
+
const fromRecovery = snapshot?.recovery?.requirement;
|
|
54
|
+
if (typeof fromRecovery === 'string' && fromRecovery !== '') return fromRecovery;
|
|
55
|
+
const stageId = snapshot?.focus?.stage;
|
|
56
|
+
const stages = Array.isArray(snapshot?.stages) ? snapshot.stages : [];
|
|
57
|
+
const stage = stages.find((entry) => entry?.id === stageId || entry?.name === stageId);
|
|
58
|
+
return typeof stage?.requirementId === 'string' ? stage.requirementId : '';
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 相位 → 默认负责角色(只用于「本相位缺哪个角色」的判定,不替代 CLI 权威)。
|
|
63
|
+
* @param {string} phase
|
|
64
|
+
* @param {string} responsibleAgent
|
|
65
|
+
* @returns {string} planner | executor | reviewer | tester | archiver | ''
|
|
66
|
+
*/
|
|
67
|
+
function roleForPhase(phase, responsibleAgent) {
|
|
68
|
+
const byPhase =
|
|
69
|
+
phase.startsWith('plan_') ? 'planner'
|
|
70
|
+
: phase.startsWith('scheme_') ? 'planner'
|
|
71
|
+
: phase === 'exec_running' ? 'executor'
|
|
72
|
+
: phase.startsWith('review_') ? 'reviewer'
|
|
73
|
+
: phase.startsWith('test_') ? 'tester'
|
|
74
|
+
: phase === 'archiving' ? 'archiver'
|
|
75
|
+
: '';
|
|
76
|
+
if (byPhase !== '') return byPhase;
|
|
77
|
+
// CLI 的 responsibleAgent 形如 `openfeel-executor` / `feel-tester`,截取末段对齐角色闭集
|
|
78
|
+
const tail = typeof responsibleAgent === 'string' ? responsibleAgent.split('-').pop() : '';
|
|
79
|
+
return ['planner', 'schemer', 'executor', 'reviewer', 'tester', 'archiver'].includes(tail ?? '')
|
|
80
|
+
? (tail === 'schemer' ? 'planner' : tail)
|
|
81
|
+
: '';
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* 构造一条 `command` 动作。
|
|
86
|
+
* @param {string} tool
|
|
87
|
+
* @param {Record<string, any>} args
|
|
88
|
+
* @param {string} goal
|
|
89
|
+
* @param {string} reason
|
|
90
|
+
* @returns {{ kind: 'command', tool: string, args: Record<string, any>, goal: string, prompt: string, reason: string }}
|
|
91
|
+
*/
|
|
92
|
+
function command(tool, args, goal, reason) {
|
|
93
|
+
return {
|
|
94
|
+
kind: 'command',
|
|
95
|
+
tool,
|
|
96
|
+
args,
|
|
97
|
+
goal,
|
|
98
|
+
prompt: `调用 \`${tool}\`:${JSON.stringify(args)}。为什么:${reason}`,
|
|
99
|
+
reason,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* 构造一条 `idle` 动作(无可执行步骤)。
|
|
105
|
+
* @param {string} reason
|
|
106
|
+
* @returns {{ kind: 'idle', tool: null, args: {}, goal: string, prompt: string, reason: string }}
|
|
107
|
+
*/
|
|
108
|
+
function idle(reason) {
|
|
109
|
+
return { kind: 'idle', tool: null, args: {}, goal: '', prompt: '', reason };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* 由快照派生「下一步该做什么」——三态:`dispatch` / `command` / `idle`。
|
|
114
|
+
*
|
|
115
|
+
* 判定顺序(先阻塞项,后推进项):
|
|
116
|
+
* 1. 无开启阶段 → `command`(开阶段;门禁自检失败时先修门禁);
|
|
117
|
+
* 2. 本相位派发台账缺当前角色 / 尚无记录 → `dispatch`(`subagent` + `feel_dispatch` 记账);
|
|
118
|
+
* 3. `exec_running` 且已派发 → `idle`(阶段是版本容器,不催推进;等子 agent 回报或继续派发下一任务);
|
|
119
|
+
* 4. 其它相位有合法下一相位 → `command`(`feel_flow action=advance`);
|
|
120
|
+
* 5. 兜底 → `idle`。
|
|
121
|
+
*
|
|
122
|
+
* @param {Record<string, any>} snapshot `readSnapshot()` 结果(缺失字段按空处理)
|
|
123
|
+
* @returns {{ kind: 'dispatch'|'command'|'idle', tool: string|null, args: Record<string, any>, goal: string, prompt: string, reason: string }}
|
|
124
|
+
*/
|
|
125
|
+
export function deriveNextAction(snapshot) {
|
|
126
|
+
const focus = snapshot?.focus ?? {};
|
|
127
|
+
const stage = typeof focus.stage === 'string' ? focus.stage : '';
|
|
128
|
+
const phase = typeof focus.phase === 'string' ? focus.phase : '';
|
|
129
|
+
const phaseLabel = typeof focus.phaseLabel === 'string' && focus.phaseLabel !== '' ? focus.phaseLabel : phase;
|
|
130
|
+
const agent = typeof focus.responsibleAgent === 'string' && focus.responsibleAgent !== ''
|
|
131
|
+
? focus.responsibleAgent
|
|
132
|
+
: 'openfeel-executor';
|
|
133
|
+
const requirement = requirementOf(snapshot);
|
|
134
|
+
const legal = Array.isArray(focus.legalNextPhases) ? focus.legalNextPhases : [];
|
|
135
|
+
const suggested = typeof focus.suggestedCommand === 'string' && focus.suggestedCommand !== ''
|
|
136
|
+
? focus.suggestedCommand
|
|
137
|
+
: '';
|
|
138
|
+
|
|
139
|
+
/* 1) 没有开启阶段:先开阶段(门禁自检失败时先修门禁,别急着建阶段)。 */
|
|
140
|
+
if (!isOpenPhase(phase)) {
|
|
141
|
+
const gate = snapshot?.workflowGate;
|
|
142
|
+
if (gate !== null && gate !== undefined && typeof gate === 'object' && gate.required === true
|
|
143
|
+
&& typeof gate.reason === 'string' && gate.reason.startsWith('guard-')) {
|
|
144
|
+
return command(
|
|
145
|
+
'feel_status',
|
|
146
|
+
{ action: 'status' },
|
|
147
|
+
'核对写入门禁状态',
|
|
148
|
+
`写入门禁不可信(${gate.reason}):先按 guard 段的修复动作处理,再安排阶段。`,
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
return command(
|
|
152
|
+
'feel_stage',
|
|
153
|
+
{ action: 'add', workflow_mode: 'full', exec_mode: 'auto' },
|
|
154
|
+
'按当前小版本开一个阶段(保持 exec_running)',
|
|
155
|
+
'没有开启阶段(phase 为空或 done):先开阶段,再在版本下建需求;阶段是版本容器,完成需求不推进阶段。',
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/* 2) 本相位缺派发记录:必须先派子 agent(这是「调度者不是执行者」的唯一检查点)。 */
|
|
160
|
+
const ledger = snapshot?.dispatch;
|
|
161
|
+
const sincePhase = Number.isFinite(ledger?.sincePhase) ? ledger.sincePhase : 0;
|
|
162
|
+
const missingRoles = Array.isArray(ledger?.missingRoles) ? ledger.missingRoles : [];
|
|
163
|
+
const role = roleForPhase(phase, agent);
|
|
164
|
+
const roleMissing = role !== '' && missingRoles.includes(role);
|
|
165
|
+
if (sincePhase === 0 || roleMissing) {
|
|
166
|
+
const template = buildDispatchTemplate(snapshot);
|
|
167
|
+
const goal = goalFor({ stage, phase, phaseLabel, agent, requirement });
|
|
168
|
+
const dispatchReason = sincePhase === 0
|
|
169
|
+
? `phase=${phase} 尚无派发记录:任何执行都必须先派子 agent(feel_dispatch 记账)。`
|
|
170
|
+
: `phase=${phase} 缺 ${role} 角色的派发记录:先派 ${role},再动手。`;
|
|
171
|
+
return {
|
|
172
|
+
kind: 'dispatch',
|
|
173
|
+
tool: 'subagent',
|
|
174
|
+
args: {
|
|
175
|
+
goal,
|
|
176
|
+
context: template.context,
|
|
177
|
+
boundaries: template.boundaries,
|
|
178
|
+
returnFormat: template.returnFormat,
|
|
179
|
+
},
|
|
180
|
+
goal,
|
|
181
|
+
prompt: templatePrompt(goal, template),
|
|
182
|
+
reason: dispatchReason,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/* 3) exec_running 已派发:阶段长期保持,不催推进(等回报或继续派发下一个任务)。 */
|
|
187
|
+
if (phase === 'exec_running') {
|
|
188
|
+
return idle(
|
|
189
|
+
`${stage} 已在 exec_running 且本相位已派发 ${sincePhase} 条:继续派发下一个任务,或等子 agent 回报;不要为了「完成需求」推进阶段。`,
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/* 4) 其它相位:有合法下一相位就推进(命令动作)。 */
|
|
194
|
+
if (legal.length > 0) {
|
|
195
|
+
const to = legal[0];
|
|
196
|
+
return command(
|
|
197
|
+
'feel_flow',
|
|
198
|
+
{ action: 'advance', stage, to },
|
|
199
|
+
`把 ${stage} 从 ${phase} 推进到 ${to}`,
|
|
200
|
+
suggested !== '' ? suggested : `phase=${phase} 的权威合法下一相位是 ${to}。`,
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/* 5) 兜底:读一次状态,别凭记忆。 */
|
|
205
|
+
return idle(`${stage}/${phase} 已派发 ${sincePhase} 条且没有合法下一相位:用 feel_status 复核,不要凭记忆推进。`);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* 派发目标的一句话(可验收:点名阶段/相位/角色/需求)。
|
|
210
|
+
* @param {{ stage: string, phase: string, phaseLabel: string, agent: string, requirement: string }} input
|
|
211
|
+
* @returns {string}
|
|
212
|
+
*/
|
|
213
|
+
function goalFor({ stage, phase, phaseLabel, agent, requirement }) {
|
|
214
|
+
const who = requirement === '' ? '本相位产物' : `需求 ${requirement} 的本相位产物`;
|
|
215
|
+
return `在 ${stage} 的 ${phase}(${phaseLabel})由 ${agent} 交付${who};完成判据须可验收(给出命令与退出码)。`;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* 四段式派发 prompt(可直接粘贴进 `subagent`)。
|
|
220
|
+
* @param {string} goal
|
|
221
|
+
* @param {ReturnType<typeof buildDispatchTemplate>} template
|
|
222
|
+
* @returns {string}
|
|
223
|
+
*/
|
|
224
|
+
function templatePrompt(goal, template) {
|
|
225
|
+
return [
|
|
226
|
+
`goal:${goal}`,
|
|
227
|
+
`context:${template.context.join(';')}`,
|
|
228
|
+
`boundaries:写 ${JSON.stringify(template.boundaries.write)};禁读 ${template.boundaries.neverRead.join('/')};禁写 ${template.boundaries.neverWrite.join('/')}`,
|
|
229
|
+
`returnFormat:${template.returnFormat}`,
|
|
230
|
+
].join('\n');
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* 把动作对象转成工具 wire 的 `next`(`idle` → null,与既有「无建议」语义一致)。
|
|
235
|
+
* @param {ReturnType<typeof deriveNextAction> | null | undefined} action
|
|
236
|
+
* @returns {{ tool: string, arguments: Record<string, any>, why: string } | null}
|
|
237
|
+
*/
|
|
238
|
+
export function toWireNext(action) {
|
|
239
|
+
if (action === null || action === undefined || action.kind === 'idle' || typeof action.tool !== 'string') {
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
// dispatch 的完整 prompt 在 `data.nextAction.prompt` 里;wire 只给可扫读的一句话目标,
|
|
243
|
+
// 避免 `renderEnvelope` 把整段 context/boundaries 拼进「下一步建议」。
|
|
244
|
+
const args = action.kind === 'dispatch'
|
|
245
|
+
? { goal: action.goal }
|
|
246
|
+
: (action.args ?? {});
|
|
247
|
+
return { tool: action.tool, arguments: args, why: action.reason };
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* 动作型一句话(`recovery.nextAction` 字符串;保留旧键、内容换成动作)。
|
|
252
|
+
* @param {ReturnType<typeof deriveNextAction> | null | undefined} action
|
|
253
|
+
* @returns {string | null}
|
|
254
|
+
*/
|
|
255
|
+
export function nextActionLine(action) {
|
|
256
|
+
if (action === null || action === undefined || action.kind === 'idle') return null;
|
|
257
|
+
if (action.kind === 'dispatch') return `dispatch → subagent(goal:${action.goal})`;
|
|
258
|
+
return `command → ${action.tool} ${JSON.stringify(action.args ?? {})}`;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/* ─────────────── 运行时提醒状态(进程内,逐请求取值) ─────────────── */
|
|
262
|
+
|
|
263
|
+
/** @type {{ stage: string, phase: string, line: string }} */
|
|
264
|
+
let focusMemo = { stage: '', phase: '', line: '' };
|
|
265
|
+
/** 已观察到多少次工具调用(每 N 步兜底提醒一次)。 */
|
|
266
|
+
let observedSteps = 0;
|
|
267
|
+
/** 本轮是否需要注入提醒(写类工具之后 / 每 N 步)。 */
|
|
268
|
+
let pending = false;
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* 记住最近一次快照派生的动作(工具层在 `feel_status` / `feel_next` 成功后调用)。
|
|
272
|
+
* @param {Record<string, any>} snapshot
|
|
273
|
+
* @param {ReturnType<typeof deriveNextAction>} [action] 已派生的动作(省一次重算)
|
|
274
|
+
* @returns {void}
|
|
275
|
+
*/
|
|
276
|
+
export function rememberFocus(snapshot, action) {
|
|
277
|
+
try {
|
|
278
|
+
const derived = action ?? deriveNextAction(snapshot);
|
|
279
|
+
const stage = typeof snapshot?.focus?.stage === 'string' ? snapshot.focus.stage : '';
|
|
280
|
+
const phase = typeof snapshot?.focus?.phase === 'string' ? snapshot.focus.phase : '';
|
|
281
|
+
focusMemo = { stage, phase, line: reminderLineOf(stage, phase, derived) };
|
|
282
|
+
} catch {
|
|
283
|
+
/* 提醒是提示级:绝不影响工具结果 */
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* 组装提醒行:`阶段 <stage> / <phase>|下一步:subagent(goal=…)`。
|
|
289
|
+
* @param {string} stage
|
|
290
|
+
* @param {string} phase
|
|
291
|
+
* @param {ReturnType<typeof deriveNextAction>} action
|
|
292
|
+
* @returns {string}
|
|
293
|
+
*/
|
|
294
|
+
function reminderLineOf(stage, phase, action) {
|
|
295
|
+
const where = `阶段 ${stage || '(无)'} / ${phase || '(无相位)'}`;
|
|
296
|
+
if (action?.kind === 'dispatch') return `${where}|下一步:subagent(goal=${action.goal})`;
|
|
297
|
+
if (action?.kind === 'command') return `${where}|下一步:${action.tool}(${JSON.stringify(action.args ?? {})})`;
|
|
298
|
+
if (action?.kind === 'idle') return `${where}|下一步:无(等回报或继续派发)`;
|
|
299
|
+
return `${where}|下一步:先 feel_status 拿阶段/相位`;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* 观察一次工具调用(`tools/post-execute` 里调用,**只记状态**)。
|
|
304
|
+
*
|
|
305
|
+
* 触发提醒:写类工具之后(`mutatingTools` 命中)或每 `REMINDER_EVERY_STEPS` 步。
|
|
306
|
+
* @param {string} toolName
|
|
307
|
+
* @param {Iterable<string>} [mutatingTools] 写类工具名(来自 `config.mutatingTools`)
|
|
308
|
+
* @returns {void}
|
|
309
|
+
*/
|
|
310
|
+
export function noteToolCall(toolName, mutatingTools) {
|
|
311
|
+
observedSteps += 1;
|
|
312
|
+
const writes = mutatingTools === undefined
|
|
313
|
+
? new Set(['edit', 'write', 'apply_patch', 'bash', 'pwsh'])
|
|
314
|
+
: new Set(mutatingTools);
|
|
315
|
+
pending = writes.has(toolName) || observedSteps % REMINDER_EVERY_STEPS === 0;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* 取本请求要注入的提醒文本(空串 = 不注入,零 token 开销)。
|
|
320
|
+
* @returns {string}
|
|
321
|
+
*/
|
|
322
|
+
export function reminderText() {
|
|
323
|
+
if (!pending) return '';
|
|
324
|
+
if (focusMemo.line === '') return '阶段(未读) / (未读相位)|下一步:先 feel_status 拿阶段/相位';
|
|
325
|
+
return focusMemo.line;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* 复位提醒状态(仅测试用)。
|
|
330
|
+
* @returns {void}
|
|
331
|
+
*/
|
|
332
|
+
export function resetReminderState() {
|
|
333
|
+
focusMemo = { stage: '', phase: '', line: '' };
|
|
334
|
+
observedSteps = 0;
|
|
335
|
+
pending = false;
|
|
336
|
+
}
|
package/dsh/lib/guard.js
CHANGED
|
@@ -685,6 +685,9 @@ export const PROTECTED_OPENFEEL_PATHS = Object.freeze([
|
|
|
685
685
|
{ match: 'file', segments: Object.freeze(['dev', '.preflight.json']), hint: 'preflight' },
|
|
686
686
|
{ match: 'file', segments: Object.freeze(['dev', 'sessions.json']), hint: 'sessions' },
|
|
687
687
|
{ match: 'file', segments: Object.freeze(['dev', 'guard-state.json']), hint: 'guard-state' },
|
|
688
|
+
// v1.6.0 / REQ-057:派发台账由适配器 `feel_dispatch` 追加。agent 手写 = 伪造「已派发」
|
|
689
|
+
// 证据(A7 的取证对象),因此与 guard 审计同权:只允许适配器 fs 直写。
|
|
690
|
+
{ match: 'file', segments: Object.freeze(['dev', 'dispatch.jsonl']), hint: 'dispatch' },
|
|
688
691
|
{ match: 'file', segments: Object.freeze(['log', 'guard-audit.jsonl']), hint: 'audit' },
|
|
689
692
|
{ match: 'dir', segments: Object.freeze(['flow-archive']), hint: 'flow-archive' },
|
|
690
693
|
{ match: 'dir', segments: Object.freeze(['checkpoints']), hint: 'checkpoints' },
|
|
@@ -726,6 +729,10 @@ const PROTECTED_HINTS = Object.freeze({
|
|
|
726
729
|
zh: '`.openfeel/dev/guard-state.json` 是门禁自检状态,由 guard 自动写入;请看 feel_status 的 guard 段。',
|
|
727
730
|
en: '`.openfeel/dev/guard-state.json` is guard self-check state written by the guard itself; read the guard section of feel_status.',
|
|
728
731
|
},
|
|
732
|
+
dispatch: {
|
|
733
|
+
zh: '`.openfeel/dev/dispatch.jsonl` 是派发台账,由 feel_dispatch 自动追加:请勿手写或截断(它同时是 A7 的取证对象)。',
|
|
734
|
+
en: '`.openfeel/dev/dispatch.jsonl` is the dispatch ledger appended by feel_dispatch: do not hand-write or truncate it (it is also the evidence for A7).',
|
|
735
|
+
},
|
|
729
736
|
'pipeline-config': {
|
|
730
737
|
zh: '`.openfeel/pipeline.yaml`(状态机转移表)与 `.openfeel/config.yaml`(workflow_mode / auto_advance / test_enabled)是流程**规则**本身:改它们等于改判定标准(例如把 plan_pending→done 变合法)。请由人类直接修改并在改后重启会话。',
|
|
731
738
|
en: '`.openfeel/pipeline.yaml` (state machine transitions) and `.openfeel/config.yaml` (workflow_mode / auto_advance / test_enabled) are the pipeline rules themselves: editing them rewrites the criteria (e.g. making plan_pending→done legal). Only a human may edit them, then restart the session.',
|
|
@@ -747,8 +754,8 @@ const PROTECTED_HINTS = Object.freeze({
|
|
|
747
754
|
en: '`.openfeel/checkpoints/**` is checkpoint data: use feel_checkpoint.',
|
|
748
755
|
},
|
|
749
756
|
requirements: {
|
|
750
|
-
zh: '`.openfeel/requirements/*.md
|
|
751
|
-
en: '`.openfeel/requirements/*.md`
|
|
757
|
+
zh: '需求正文请用 `feel_req action=body` 写;不要手改 `.openfeel/requirements/*.md`(CLI 生成的人读副本)。元信息(状态/负责人/版本)用 feel_req action=add|set|claim。',
|
|
758
|
+
en: 'Write requirement bodies with `feel_req action=body`; do not hand-edit `.openfeel/requirements/*.md` (human-readable copies generated by the CLI). Use feel_req action=add|set|claim for metadata (status/owner/version).',
|
|
752
759
|
},
|
|
753
760
|
audit: {
|
|
754
761
|
zh: '`.openfeel/log/guard-audit.jsonl` 是门禁审计证据,由 guard 自动追加:请勿手写或截断。',
|
package/dsh/lib/index.js
CHANGED
|
@@ -36,6 +36,7 @@ import { createOpenFeelGuard, resolveShellGate } from './guard.js';
|
|
|
36
36
|
import { createFeelCommandHandler } from './surface/command.js';
|
|
37
37
|
import { FEEL_PROMPT_NAME, FEEL_PROMPT_ORDER, renderBootstrapPrompt, renderFeelPrompt } from './surface/prompt.js';
|
|
38
38
|
import { createTools } from './tools/index.js';
|
|
39
|
+
import { REMINDER_CONTEXT_NAME, noteToolCall, reminderText } from './adapters/next-action.js';
|
|
39
40
|
|
|
40
41
|
/** Loader 入口 id。 */
|
|
41
42
|
export const name = 'openfeel-dsh';
|
|
@@ -291,6 +292,42 @@ export function apply(ctx, rawConfig) {
|
|
|
291
292
|
});
|
|
292
293
|
}
|
|
293
294
|
|
|
295
|
+
/* ── 每步提醒(v1.6.0 / T10) ──────────────────────────────── */
|
|
296
|
+
|
|
297
|
+
// 首选是 `tools/post-execute` + `additionalContexts`(宿主侧确实存在:
|
|
298
|
+
// `dsh-tools/src/events.ts` 的 `tools/post-execute`、`contracts.ts` 的
|
|
299
|
+
// `PostToolDecision.additionalContexts`)。但 `additionalContexts` 的元素必须是
|
|
300
|
+
// `UserMessage`,只能由 `@deepseek-ai/dsh-llm` 的 `createUserMessage()` 构造;
|
|
301
|
+
// 本插件零运行时依赖(`dsh/package.json` 无 dependencies),实测
|
|
302
|
+
// `createRequire(<adapter>/lib/index.js).resolve('@deepseek-ai/dsh-llm')` → MODULE_NOT_FOUND。
|
|
303
|
+
// 手搓未注册 `source.kind` 的 UserMessage 会流进 `agent/inbox/spliced` 持久事件,
|
|
304
|
+
// 无运行时证据前不赌它不破坏会话。故按 plan §5.3 **降级 1**:
|
|
305
|
+
// `ctx.systemPrompt.context()`(动态 user 快照、逐请求刷新、不进 system 前缀缓存),
|
|
306
|
+
// `tools/post-execute` 只做**观察**(不构造消息、不改结果)。证据见
|
|
307
|
+
// `.openfeel/tmp/stage-132/spike.md`。
|
|
308
|
+
const reminderAvailable = config.autoPrompt && config.activation !== 'off'
|
|
309
|
+
&& typeof ctx.systemPrompt?.context === 'function';
|
|
310
|
+
if (reminderAvailable) {
|
|
311
|
+
ctx.systemPrompt.context({
|
|
312
|
+
name: REMINDER_CONTEXT_NAME,
|
|
313
|
+
order: FEEL_PROMPT_ORDER + 5,
|
|
314
|
+
// 逐请求求值:只在「写类工具之后 / 每 5 步」返回一行,其余为空串(零 token 开销)。
|
|
315
|
+
text: () => reminderText(),
|
|
316
|
+
});
|
|
317
|
+
} else if (config.autoPrompt && config.activation !== 'off') {
|
|
318
|
+
log.debug?.('宿主未提供 ctx.systemPrompt.context:每步提醒降级为无(不影响 feel_* 结果)。');
|
|
319
|
+
}
|
|
320
|
+
if (reminderAvailable && typeof ctx.on === 'function') {
|
|
321
|
+
ctx.on('tools/post-execute', (exec, _result, next) => {
|
|
322
|
+
try {
|
|
323
|
+
noteToolCall(exec?.name, config.mutatingTools);
|
|
324
|
+
} catch {
|
|
325
|
+
/* 提醒是提示级:观察失败绝不改变工具结果 */
|
|
326
|
+
}
|
|
327
|
+
return next();
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
|
|
294
331
|
/* ── 启动自检(非阻断) ─────────────────────────────────── */
|
|
295
332
|
|
|
296
333
|
void cli
|