openfeel 1.5.25 → 1.6.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/README.en.md +14 -0
- package/README.zh-CN.md +14 -0
- package/dist/commands/dashboard.d.ts.map +1 -1
- package/dist/commands/dashboard.js +10 -1
- package/dist/commands/dashboard.js.map +1 -1
- package/dist/commands/flow.d.ts.map +1 -1
- package/dist/commands/flow.js +126 -25
- package/dist/commands/flow.js.map +1 -1
- package/dist/commands/lint.d.ts +5 -1
- package/dist/commands/lint.d.ts.map +1 -1
- package/dist/commands/lint.js +373 -0
- package/dist/commands/lint.js.map +1 -1
- package/dist/commands/req.d.ts.map +1 -1
- package/dist/commands/req.js +814 -88
- 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/adherence.d.ts +135 -0
- package/dist/core/adherence.d.ts.map +1 -0
- package/dist/core/adherence.js +221 -0
- package/dist/core/adherence.js.map +1 -0
- package/dist/core/dashboard/aggregate.d.ts +39 -0
- package/dist/core/dashboard/aggregate.d.ts.map +1 -1
- package/dist/core/dashboard/aggregate.js +64 -5
- package/dist/core/dashboard/aggregate.js.map +1 -1
- package/dist/core/dashboard/render.d.ts.map +1 -1
- package/dist/core/dashboard/render.js +88 -1
- package/dist/core/dashboard/render.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 +38 -3
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +22 -3
- package/dist/core/errors.js.map +1 -1
- package/dist/core/flow/gate-override.d.ts +72 -0
- package/dist/core/flow/gate-override.d.ts.map +1 -0
- package/dist/core/flow/gate-override.js +71 -0
- package/dist/core/flow/gate-override.js.map +1 -0
- package/dist/core/flow-manager.d.ts +118 -3
- package/dist/core/flow-manager.d.ts.map +1 -1
- package/dist/core/flow-manager.js +357 -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 +96 -5
- 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 +96 -5
- 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 +103 -0
- package/dist/core/req/body-file.d.ts.map +1 -1
- package/dist/core/req/body-file.js +221 -2
- package/dist/core/req/body-file.js.map +1 -1
- package/dist/core/req/plan-file.d.ts +83 -0
- package/dist/core/req/plan-file.d.ts.map +1 -0
- package/dist/core/req/plan-file.js +205 -0
- package/dist/core/req/plan-file.js.map +1 -0
- package/dist/core/req/requirement-ops.d.ts +151 -15
- package/dist/core/req/requirement-ops.d.ts.map +1 -1
- package/dist/core/req/requirement-ops.js +402 -22
- package/dist/core/req/requirement-ops.js.map +1 -1
- package/dist/core/req/types.d.ts +63 -2
- package/dist/core/req/types.d.ts.map +1 -1
- package/dist/core/req/types.js +10 -2
- package/dist/core/req/types.js.map +1 -1
- package/dist/core/template-loader.d.ts.map +1 -1
- package/dist/core/template-loader.js +87 -0
- package/dist/core/template-loader.js.map +1 -1
- package/dist/core/templates.d.ts +1 -1
- package/dist/core/templates.d.ts.map +1 -1
- package/dist/core/templates.js +18 -0
- package/dist/core/templates.js.map +1 -1
- package/dsh/ACTION-GUIDE.md +50 -8
- package/dsh/ADAPTER.md +119 -13
- package/dsh/README.md +49 -26
- package/dsh/docs/compat/persistence.md +26 -0
- package/dsh/docs/compat/pipeline.md +24 -0
- package/dsh/docs/compat/req.md +29 -0
- package/dsh/docs/compat/stage.md +25 -0
- package/dsh/lib/adapters/dispatch-ledger.js +432 -0
- package/dsh/lib/adapters/dispatch.js +54 -6
- package/dsh/lib/adapters/next-action.js +336 -0
- package/dsh/lib/guard.js +694 -24
- package/dsh/lib/index.js +37 -0
- package/dsh/lib/surface/prompt.js +66 -178
- package/dsh/lib/tools/index.js +527 -12
- package/dsh/package.json +2 -2
- package/package.json +2 -1
package/dsh/lib/tools/index.js
CHANGED
|
@@ -11,10 +11,26 @@
|
|
|
11
11
|
* 3. 在拒绝时给出**可操作的下一步**(改哪个参数、先跑哪条命令)。
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
+
import { readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
15
|
+
import { join, relative, sep } from 'node:path';
|
|
16
|
+
import { tmpdir } from 'node:os';
|
|
17
|
+
|
|
14
18
|
import { FeelError } from '../adapters/cli.js';
|
|
15
19
|
import { legalNextPhases, planNextStep, readSnapshot } from '../adapters/dashboard.js';
|
|
16
20
|
import { readStatusSync } from '../adapters/dev-status.js';
|
|
17
21
|
import { buildDispatchTemplate } from '../adapters/dispatch.js';
|
|
22
|
+
// v1.6.0 / T10:动作型 next(`nextAction`)与每步提醒的状态喂入
|
|
23
|
+
import { deriveNextAction, nextActionLine, rememberFocus, toWireNext } from '../adapters/next-action.js';
|
|
24
|
+
// v1.6.0 / REQ-057:派发台账(与 CLI `.openfeel/dev/dispatch.jsonl` 同一文件格式)
|
|
25
|
+
import {
|
|
26
|
+
DISPATCH_LEDGER_REL_PATH,
|
|
27
|
+
DISPATCH_ROLES,
|
|
28
|
+
appendDispatch,
|
|
29
|
+
closeDispatch,
|
|
30
|
+
dispatchLedgerPath,
|
|
31
|
+
dispatchSummary,
|
|
32
|
+
readDispatches,
|
|
33
|
+
} from '../adapters/dispatch-ledger.js';
|
|
18
34
|
import { readRecovery } from '../adapters/recovery.js';
|
|
19
35
|
import { readPreflightInfo } from '../adapters/preflight.js';
|
|
20
36
|
import { buildObservability } from '../adapters/observability.js';
|
|
@@ -26,7 +42,11 @@ import { resolveGuardCwd } from '../guard.js';
|
|
|
26
42
|
import { touchSession as touchSessionCwd } from '../adapters/session-cwd-registry.js';
|
|
27
43
|
import { resolveWorkspace } from '../adapters/workspace.js';
|
|
28
44
|
// v1.5.8 / REQ-029:多会话登记(与 CLI `.openfeel/dev/sessions.json` 同一文件格式)
|
|
29
|
-
import {
|
|
45
|
+
import {
|
|
46
|
+
readSessions as readSessionEntries,
|
|
47
|
+
resolveSessionId,
|
|
48
|
+
touchSession as touchSessionFile,
|
|
49
|
+
} from '../adapters/sessions.js';
|
|
30
50
|
import {
|
|
31
51
|
boolean,
|
|
32
52
|
compileParameters,
|
|
@@ -143,6 +163,186 @@ function safeObservability(snapshot) {
|
|
|
143
163
|
}
|
|
144
164
|
}
|
|
145
165
|
|
|
166
|
+
/**
|
|
167
|
+
* 派发台账提示段(v1.6.0 / REQ-057)。
|
|
168
|
+
*
|
|
169
|
+
* **提示级,不做硬拦**(用户裁定 ②):`required` 恒 true 只表示「建议走台账」,
|
|
170
|
+
* 不阻断任何工具调用。台账读取失败降级为空台账(观测数据绝不影响 feel_status)。
|
|
171
|
+
*
|
|
172
|
+
* 形状与 `dispatchSummary` 单点对齐:`{required, total, sincePhase, open, closedRatio, missingRoles, records}`
|
|
173
|
+
* (v1.6.1 / REQ-066 A66.2 增 `open[]` / `closedRatio`;既有四键保留)。
|
|
174
|
+
*
|
|
175
|
+
* @param {string} projectRoot
|
|
176
|
+
* @param {{ stage?: string, phase?: string }} [focus]
|
|
177
|
+
* @returns {{ required: true, total: number, sincePhase: number, open: Array<Record<string, any>>, closedRatio: number | null, missingRoles: string[], records: Array<Record<string, any>> }}
|
|
178
|
+
*/
|
|
179
|
+
function safeDispatchSection(projectRoot, focus = {}) {
|
|
180
|
+
try {
|
|
181
|
+
return dispatchSummary(projectRoot, { stage: focus.stage ?? '', phase: focus.phase ?? '' });
|
|
182
|
+
} catch {
|
|
183
|
+
return {
|
|
184
|
+
required: true,
|
|
185
|
+
total: 0,
|
|
186
|
+
sincePhase: 0,
|
|
187
|
+
open: [],
|
|
188
|
+
closedRatio: null,
|
|
189
|
+
missingRoles: [...DISPATCH_ROLES],
|
|
190
|
+
records: [],
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* 写命令 + `--json`(v1.6.0 / T9)。
|
|
197
|
+
*
|
|
198
|
+
* 为什么要绕一层:`cli.json` 不跑 preflight 自愈,而 `cli.write` 只回人类文本。
|
|
199
|
+
* `req body` 是写命令且需要结构化出口(path/lines/created),所以用 `write`
|
|
200
|
+
* 保证「账本过期先真实读一次状态」的既有语义,再从 stdout 解析 JSON 文档。
|
|
201
|
+
* 解析失败不抛错(出口契约归 CLI),返回 `null` 由调用方降级。
|
|
202
|
+
*
|
|
203
|
+
* @param {import('../adapters/cli.js').FeelCli} cliInstance
|
|
204
|
+
* @param {string[]} argv 必须含 `--json`
|
|
205
|
+
* @param {object} options CLI 执行选项
|
|
206
|
+
* @returns {Promise<Record<string, any> | null>}
|
|
207
|
+
*/
|
|
208
|
+
async function writeJsonDoc(cliInstance, argv, options) {
|
|
209
|
+
const out = await cliInstance.write(argv, options);
|
|
210
|
+
const text = typeof out?.text === 'string' ? out.text.trim() : '';
|
|
211
|
+
if (text === '') return null;
|
|
212
|
+
try {
|
|
213
|
+
const doc = JSON.parse(text);
|
|
214
|
+
return doc !== null && typeof doc === 'object' && !Array.isArray(doc) ? doc : null;
|
|
215
|
+
} catch {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* 账本同步会重写的「文档类」目标(`dev_last.md` + `dev/current.md`)。
|
|
222
|
+
*
|
|
223
|
+
* **不把 `.sync.json` 算进去**:它是同步元数据(每次 sync 必写),
|
|
224
|
+
* 而 `wrote[]` 的语义是「哪些账本文档内容真的变了」(plan §5.5)。
|
|
225
|
+
*
|
|
226
|
+
* 用户目录名由 CLI 从 `.info.json` / 环境推导,适配器不重复那套规则:
|
|
227
|
+
* 直接枚举每个用户的 `dev_last.md`(`.openfeel/users/<user>/dev_last.md`,存在即纳入候选)。
|
|
228
|
+
*
|
|
229
|
+
* @param {string} projectRoot
|
|
230
|
+
* @returns {string[]} 绝对路径候选(可能不存在)
|
|
231
|
+
*/
|
|
232
|
+
function devDocCandidates(projectRoot) {
|
|
233
|
+
const files = [];
|
|
234
|
+
const usersDir = join(projectRoot, '.openfeel', 'users');
|
|
235
|
+
let entries = [];
|
|
236
|
+
try {
|
|
237
|
+
entries = readdirSync(usersDir, { withFileTypes: true });
|
|
238
|
+
} catch {
|
|
239
|
+
entries = [];
|
|
240
|
+
}
|
|
241
|
+
for (const entry of entries) {
|
|
242
|
+
if (entry.isDirectory()) files.push(join(usersDir, entry.name, 'dev_last.md'));
|
|
243
|
+
}
|
|
244
|
+
files.push(join(projectRoot, '.openfeel', 'dev', 'current.md'));
|
|
245
|
+
return files;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* 快照账本文档内容(不存在 → `null`;读失败 → `null`)。
|
|
250
|
+
* @param {string} projectRoot
|
|
251
|
+
* @returns {Map<string, string | null>}
|
|
252
|
+
*/
|
|
253
|
+
function snapshotDevDocs(projectRoot) {
|
|
254
|
+
/** @type {Map<string, string | null>} */
|
|
255
|
+
const snapshot = new Map();
|
|
256
|
+
for (const file of devDocCandidates(projectRoot)) {
|
|
257
|
+
try {
|
|
258
|
+
snapshot.set(file, readFileSync(file, 'utf-8'));
|
|
259
|
+
} catch {
|
|
260
|
+
snapshot.set(file, null);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return snapshot;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* 对比同步前后的账本文档,得出**实际变更**的相对路径(POSIX 风格)。
|
|
268
|
+
* @param {Map<string, string | null>} before
|
|
269
|
+
* @param {Map<string, string | null>} after
|
|
270
|
+
* @param {string} projectRoot
|
|
271
|
+
* @returns {string[]}
|
|
272
|
+
*/
|
|
273
|
+
function diffDevDocs(before, after, projectRoot) {
|
|
274
|
+
const wrote = [];
|
|
275
|
+
for (const [file, content] of after) {
|
|
276
|
+
if (content === null) continue;
|
|
277
|
+
if (before.get(file) === content) continue;
|
|
278
|
+
const rel = relative(projectRoot, file);
|
|
279
|
+
wrote.push(rel.split(sep).join('/'));
|
|
280
|
+
}
|
|
281
|
+
return wrote;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* `feel_dispatch` 的当前阶段/相位解析(v1.6.0 / REQ-057)。
|
|
286
|
+
*
|
|
287
|
+
* 参数显式给出时零 CLI 调用;缺省时读一次 `flow next --json`(与 feel_next 同源权威)。
|
|
288
|
+
* 无阶段上下文或 CLI 不可用时留空,台账行照样记录(不因派发工具阻塞调度)。
|
|
289
|
+
*
|
|
290
|
+
* @param {import('../adapters/cli.js').FeelCli} cli
|
|
291
|
+
* @param {object} opts CLI 执行选项
|
|
292
|
+
* @param {Record<string, any>} args
|
|
293
|
+
* @returns {Promise<{ stage: string, phase: string }>}
|
|
294
|
+
*/
|
|
295
|
+
async function resolveDispatchFocus(cli, opts, args) {
|
|
296
|
+
let stage = optionalArg(args, 'stage') ?? '';
|
|
297
|
+
let phase = optionalArg(args, 'phase') ?? '';
|
|
298
|
+
if (stage !== '' && phase !== '') return { stage, phase };
|
|
299
|
+
try {
|
|
300
|
+
const doc = await cli.json(['flow', 'next', '--json'], opts);
|
|
301
|
+
if (stage === '' && typeof doc?.stage === 'string') stage = doc.stage;
|
|
302
|
+
if (phase === '' && typeof doc?.phase === 'string') phase = doc.phase;
|
|
303
|
+
} catch {
|
|
304
|
+
// 取不到阶段 / 旧版 CLI / 未初始化:留空即可,派发记录仍然成立
|
|
305
|
+
}
|
|
306
|
+
return { stage, phase };
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* 打派发方的来源标识(v1.6.0 / REQ-057)。
|
|
311
|
+
*
|
|
312
|
+
* `origin` / `delegationDepth` 的 DSH 读取路径**尚未由 spike 验证**(plan §2 T9:
|
|
313
|
+
* 不可读则省略字段;本步按 schema 要求保留,用 `'root'` / `1` 作保守缺省,
|
|
314
|
+
* 可读时取真实值)。绝不为读这两个字段改变主流程。
|
|
315
|
+
*
|
|
316
|
+
* @param {object} exec
|
|
317
|
+
* @returns {{ origin: string, dispatchDepth: number }}
|
|
318
|
+
*/
|
|
319
|
+
function dispatchOriginOf(exec) {
|
|
320
|
+
const session = exec?.agent?.session ?? {};
|
|
321
|
+
const header = session.header ?? {};
|
|
322
|
+
const origin = typeof header.origin === 'string' && header.origin !== ''
|
|
323
|
+
? header.origin
|
|
324
|
+
: (typeof session.origin === 'string' && session.origin !== '' ? session.origin : 'root');
|
|
325
|
+
const rawDepth = header.delegationDepth ?? session.delegationDepth ?? header.delegation_depth;
|
|
326
|
+
const dispatchDepth = Number.isInteger(rawDepth) && rawDepth >= 0 ? rawDepth : 1;
|
|
327
|
+
return { origin, dispatchDepth };
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* 派发方会话标识(`exec.agent.session.id` 优先,缺省沿用 CLI 三级链的会话标识)。
|
|
332
|
+
* @param {object} exec
|
|
333
|
+
* @param {string} projectRoot
|
|
334
|
+
* @returns {string}
|
|
335
|
+
*/
|
|
336
|
+
function dispatchSessionOf(exec, projectRoot) {
|
|
337
|
+
const id = exec?.agent?.session?.id;
|
|
338
|
+
if (typeof id === 'string' && id !== '') return id;
|
|
339
|
+
try {
|
|
340
|
+
return resolveSessionId(projectRoot);
|
|
341
|
+
} catch {
|
|
342
|
+
return '';
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
146
346
|
/**
|
|
147
347
|
* 展示层对齐(v1.5.17):`feel_mode=disabled` 时 CLI 的 preflight 有效模式已降级为 warn
|
|
148
348
|
* (`src/core/preflight.ts:resolvePreflightMode`),而适配器读到的是**宿主 env**(可能仍是 strict)。
|
|
@@ -222,6 +422,10 @@ export function compactStatusSnapshot(snapshot) {
|
|
|
222
422
|
stale: snapshot?.stale === true,
|
|
223
423
|
// v1.5.8 / REQ-029:会话登记(compact 档同样暴露,体积可控——只含存活/近期会话)
|
|
224
424
|
sessions: snapshot?.sessions ?? [],
|
|
425
|
+
// v1.6.0 / REQ-057:派发台账提示段(提示级,不做硬拦;键缺失时显式 null 保持形状)
|
|
426
|
+
dispatch: snapshot?.dispatch ?? null,
|
|
427
|
+
// v1.6.0 / T10:动作型 next(`dispatch` / `command` / `idle`)——与 wire 的 `next` 同源
|
|
428
|
+
nextAction: snapshot?.nextAction ?? null,
|
|
225
429
|
};
|
|
226
430
|
// 需求概览是显式开关(with_requirements),compact 档同样只在请求时带上
|
|
227
431
|
if (snapshot?.requirements !== undefined) {
|
|
@@ -381,6 +585,17 @@ export function createTools(context) {
|
|
|
381
585
|
// touchSessionFile 内部已 try/catch 静默,读失败同样降级为 [](绝不阻断主流程)。
|
|
382
586
|
touchSessionFile(resolved.cwd, snapshot.focus?.stage ?? '');
|
|
383
587
|
snapshot.sessions = readSessionEntries(resolved.cwd);
|
|
588
|
+
// v1.6.0 / REQ-057:派发台账提示段(required / total / sincePhase / missingRoles / records)。
|
|
589
|
+
// 提示级:只告知「本相位哪些角色还没派发过」,不做任何硬拦(用户裁定 ②)。
|
|
590
|
+
snapshot.dispatch = safeDispatchSection(resolved.cwd, {
|
|
591
|
+
stage: snapshot.focus?.stage,
|
|
592
|
+
phase: snapshot.focus?.phase,
|
|
593
|
+
});
|
|
594
|
+
// v1.6.0 / T10:动作型 next(`dispatch` / `command` / `idle`)。
|
|
595
|
+
// 同时喂给每步提醒(`rememberFocus`),让「该派发了」出现在决策点。
|
|
596
|
+
snapshot.nextAction = deriveNextAction(snapshot);
|
|
597
|
+
rememberFocus(snapshot, snapshot.nextAction);
|
|
598
|
+
snapshot.recovery.nextAction = nextActionLine(snapshot.nextAction);
|
|
384
599
|
const focus = snapshot.focus;
|
|
385
600
|
// v1.5.12 / stage-127 §3-E:标题按 workflowGate.reason 选择,与 feel_next 同源(headlineWarning)
|
|
386
601
|
const gateWarning = headlineWarning(snapshot);
|
|
@@ -392,9 +607,8 @@ export function createTools(context) {
|
|
|
392
607
|
return {
|
|
393
608
|
data,
|
|
394
609
|
summary: `${staleWarning}${gateWarning}${guardWarning}pipeline=${snapshot.pipeline.phase || '(空)'} 活跃阶段=${focus.stage || '(无)'} phase=${focus.phase || '(空)'} mode=${snapshot.mode.current}(${snapshot.mode.source}) 负责=${focus.responsibleAgent} 可推进到=[${(focus.legalNextPhases ?? []).join(', ') || '无'}]`,
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
: { tool: 'feel_next', arguments: {}, why: '获取「下一步该谁做」的明确建议。' },
|
|
610
|
+
// v1.6.0 / T10:`next` 保留(旧键),内容改成动作型(dispatch/command;idle → null)
|
|
611
|
+
next: toWireNext(snapshot.nextAction),
|
|
398
612
|
};
|
|
399
613
|
});
|
|
400
614
|
},
|
|
@@ -436,12 +650,21 @@ export function createTools(context) {
|
|
|
436
650
|
snapshot.recovery = readRecovery(resolved.cwd);
|
|
437
651
|
snapshot.preflight = preflight;
|
|
438
652
|
snapshot.observability = safeObservability(snapshot);
|
|
653
|
+
// v1.6.0 / T10:动作型 next 依赖派发台账(与 feel_status 同源;读本地 jsonl,零新增 CLI)。
|
|
654
|
+
// 注意:`plan.dispatch` 是派发模板(buildDispatchTemplate),台账走 `snapshot.dispatch`。
|
|
655
|
+
snapshot.dispatch = safeDispatchSection(resolved.cwd, {
|
|
656
|
+
stage: snapshot.focus?.stage,
|
|
657
|
+
phase: snapshot.focus?.phase,
|
|
658
|
+
});
|
|
439
659
|
const plan = planNextStep(snapshot);
|
|
440
660
|
plan.workflowGate = snapshot.workflowGate;
|
|
441
661
|
plan.feelMode = snapshot.feelMode ?? null;
|
|
442
662
|
plan.guard = snapshot.guard;
|
|
443
663
|
plan.preflight = snapshot.preflight;
|
|
444
|
-
|
|
664
|
+
// v1.6.0 / T10:动作型 next(与 feel_status 同一纯函数、同一提醒状态)
|
|
665
|
+
plan.nextAction = deriveNextAction(snapshot);
|
|
666
|
+
rememberFocus(snapshot, plan.nextAction);
|
|
667
|
+
snapshot.recovery.nextAction = nextActionLine(plan.nextAction);
|
|
445
668
|
plan.recovery = snapshot.recovery;
|
|
446
669
|
plan.dispatch = buildDispatchTemplate(snapshot);
|
|
447
670
|
plan.observability = snapshot.observability;
|
|
@@ -466,9 +689,10 @@ export function createTools(context) {
|
|
|
466
689
|
return {
|
|
467
690
|
data: plan,
|
|
468
691
|
summary: plan.summary,
|
|
469
|
-
|
|
692
|
+
// v1.6.0 / T10:优先动作型 next;`idle` 时才回落到既有 toolCall(不破坏旧语义)
|
|
693
|
+
next: toWireNext(plan.nextAction) ?? (plan.toolCall === null || plan.toolCall === undefined
|
|
470
694
|
? null
|
|
471
|
-
: { tool: plan.toolCall.tool, arguments: plan.toolCall.arguments, why: `推进到 ${plan.toolCall.arguments.to}` },
|
|
695
|
+
: { tool: plan.toolCall.tool, arguments: plan.toolCall.arguments, why: `推进到 ${plan.toolCall.arguments.to}` }),
|
|
472
696
|
};
|
|
473
697
|
});
|
|
474
698
|
},
|
|
@@ -863,9 +1087,9 @@ export function createTools(context) {
|
|
|
863
1087
|
const feelReq = {
|
|
864
1088
|
name: 'feel_req',
|
|
865
1089
|
description:
|
|
866
|
-
'需求分发系统(openfeel req,7 状态)。action=add 创建需求(ID 自动分配,**单调计数器 meta.last_req_seq**:归档移走条目后也不复用 ID
|
|
1090
|
+
'需求分发系统(openfeel req,7 状态)。action=add 创建需求(ID 自动分配,**单调计数器 meta.last_req_seq**:归档移走条目后也不复用 ID;可带 summary / problem / goal / acceptance / plan 一步写入正文小节——正文门要求 `## 摘要` 与 `## 目标与验收` 都写实,缺 summary 时 add start=true 会被 REQ_BODY 拦);body 写入需求正文的业务小节(`.openfeel/requirements/*.md` 是 guard 受保护路径,`feel_req action=body` 是唯一写入口:section 必填,text 与 file 二选一,append/replace 互斥);list 过滤列表(include_archived=true 合并已随版本归档的需求);show 详情(已归档需求回退读归档文件);board 看板(7 组固定顺序);next 推荐下一个可接取需求;claim 认领(占用校验、无 TTL);release 释放;set 更新白名单字段;link 关联/解绑阶段;advance 显式推进状态(**done 门:关联阶段须已进入 exec_running 及之后相位即可完成——阶段是版本容器,不必先 done**);split 拆分(子需求直接入 scheduled,父需求仅留 parent_id 溯源);review 记录需求审查;verify 记录需求验证(**v1.5.8 完成必审验:done 门额外要求 review.result=pass 且 verification.result=pass**);release-check 发布门(软,只读):列出该版本 done / 未完成 / 其它需求;rollover 顺延:把未完成需求的 target_version 改到新版本并记录 carried_from。',
|
|
867
1091
|
parameters: {
|
|
868
|
-
action: stringEnum(['add', 'list', 'show', 'board', 'next', 'claim', 'release', 'set', 'link', 'advance', 'split', 'review', 'verify', 'complete', 'waive', 'trivial', 'release-check', 'rollover'], '操作。', { required: true }),
|
|
1092
|
+
action: stringEnum(['add', 'body', 'list', 'show', 'board', 'next', 'claim', 'release', 'set', 'link', 'advance', 'split', 'review', 'verify', 'complete', 'waive', 'trivial', 'release-check', 'rollover'], '操作。', { required: true }),
|
|
869
1093
|
id: string('需求 ID(如 REQ-001)。show/claim/release/set/advance/split/review/verify/rollover 必需(rollover 与 all 互斥)。'),
|
|
870
1094
|
title: string('需求标题(add 必需;set 为改标题)。'),
|
|
871
1095
|
target_version: string('预估版本(如 v1.3.0;纯展示/过滤维度,非门禁)。'),
|
|
@@ -890,9 +1114,22 @@ export function createTools(context) {
|
|
|
890
1114
|
evidence: string('verify 的证据(测试命令 / 报告路径)。'),
|
|
891
1115
|
independent: boolean('review 是否独立审查(缺省 false = 自我审查,须显式标注 self-review)。'),
|
|
892
1116
|
claim: boolean('add 时立即认领(v1.5.23)。'),
|
|
893
|
-
start: boolean('add 时直接进入 in_progress(自动 scheduled → in_progress;v1.5.25
|
|
1117
|
+
start: boolean('add 时直接进入 in_progress(自动 scheduled → in_progress;v1.5.25;正文未写实会被 REQ_BODY 门拒绝)。'),
|
|
1118
|
+
// v1.6.0-stage-132 / T13:add 时直接写正文业务小节(CLI `req add --summary/--problem/--goal/--acceptance/--plan`)。
|
|
1119
|
+
// 正文门(REQ_BODY_GATE)在 scheduled / in_progress / done 生效,缺省字段不传。
|
|
1120
|
+
summary: string('add 时写入正文 `## 摘要` 小节(Markdown;正文门要求它写实)。'),
|
|
1121
|
+
problem: string('add 时写入正文 `## 问题` 小节(Markdown)。'),
|
|
1122
|
+
goal: string('add 时写入正文 `## 目标与验收` 的「目标」子节(Markdown;正文门要求该节写实)。'),
|
|
1123
|
+
acceptance: string('add 时写入正文 `## 目标与验收` 的「验收」子节(Markdown;至少 1 条 `- ` / `验收` 开头的判据行)。'),
|
|
1124
|
+
plan: string('add 时写入正文 `## 初步规划` 小节(Markdown)。'),
|
|
894
1125
|
reason: string('waive / trivial 的原因(标记时必需)。'),
|
|
895
1126
|
revoke: boolean('waive / trivial 时撤销标记。'),
|
|
1127
|
+
// v1.6.0 / REQ-055(T2):需求正文的唯一写入口(`.openfeel/requirements/*.md` 是受保护路径)
|
|
1128
|
+
section: string('req body 的小节名(如 摘要 / 目标与验收;元信息小节不可写)。body 必需。'),
|
|
1129
|
+
text: string('req body 的小节正文(Markdown;与 file 二选一)。'),
|
|
1130
|
+
file: string('req body 的正文来源文件(与 text 二选一;相对路径按项目根解析)。'),
|
|
1131
|
+
append: boolean('req body 追加到该小节末尾(缺省替换整节)。'),
|
|
1132
|
+
replace: boolean('req body 显式替换整节(缺省行为;与 append 互斥)。'),
|
|
896
1133
|
project: string('项目根目录。'),
|
|
897
1134
|
},
|
|
898
1135
|
output: { schema: envelopeSchema(), render: renderEnvelope },
|
|
@@ -910,11 +1147,90 @@ export function createTools(context) {
|
|
|
910
1147
|
pushFlag(argv, '--claim', args.claim);
|
|
911
1148
|
pushOption(argv, '--stage', args.stage);
|
|
912
1149
|
pushFlag(argv, '--start', args.start);
|
|
1150
|
+
// v1.6.0-stage-132 / T13:正文业务小节在 CLI 侧先于 `--start` 落盘,
|
|
1151
|
+
// 所以「add 带 summary/goal/acceptance + start」不再被正文门(REQ_BODY)拦。
|
|
1152
|
+
pushOption(argv, '--summary', args.summary);
|
|
1153
|
+
pushOption(argv, '--problem', args.problem);
|
|
1154
|
+
pushOption(argv, '--goal', args.goal);
|
|
1155
|
+
pushOption(argv, '--acceptance', args.acceptance);
|
|
1156
|
+
pushOption(argv, '--plan', args.plan);
|
|
913
1157
|
return envelope(action, async () => {
|
|
914
1158
|
const out = await cli.write(argv, opts);
|
|
915
1159
|
return { data: { output: out.text }, summary: '需求已创建。' };
|
|
916
1160
|
});
|
|
917
1161
|
}
|
|
1162
|
+
case 'body': {
|
|
1163
|
+
// v1.6.0 / REQ-055(T2):正文写入唯一入口。
|
|
1164
|
+
// `.openfeel/requirements/*.md` 是 guard 受保护路径,agent 工具直写会被拒,
|
|
1165
|
+
// shell 跑 openfeel 写命令同样被拒 —— 这是给正文开的唯一通道。
|
|
1166
|
+
const id = requireArg(args, 'id', action);
|
|
1167
|
+
const section = requireArg(args, 'section', action);
|
|
1168
|
+
// v1.6.1 / REQ-064 A64.4:`text` **不得经 argv**(多行会被截断/转义),也不得 trim
|
|
1169
|
+
// (首尾空行 / CRLF / `###` 子标题必须原样落盘)——只判空,随后写 os.tmpdir() 临时文件走 `--file`。
|
|
1170
|
+
const text = typeof args.text === 'string' && args.text.trim() !== '' ? args.text : undefined;
|
|
1171
|
+
const file = optionalArg(args, 'file');
|
|
1172
|
+
if (text === undefined && file === undefined) {
|
|
1173
|
+
throw new FeelError('req body 需要 text 或 file 之一(小节正文来源)', {
|
|
1174
|
+
kind: 'usage',
|
|
1175
|
+
code: 'FEEL_BAD_USAGE',
|
|
1176
|
+
});
|
|
1177
|
+
}
|
|
1178
|
+
if (text !== undefined && file !== undefined) {
|
|
1179
|
+
throw new FeelError('req body 的 text 与 file 互斥:只能给一个', {
|
|
1180
|
+
kind: 'usage',
|
|
1181
|
+
code: 'FEEL_BAD_USAGE',
|
|
1182
|
+
});
|
|
1183
|
+
}
|
|
1184
|
+
if (args.append === true && args.replace === true) {
|
|
1185
|
+
throw new FeelError('req body 的 append 与 replace 互斥:只能给一个', {
|
|
1186
|
+
kind: 'usage',
|
|
1187
|
+
code: 'FEEL_BAD_USAGE',
|
|
1188
|
+
});
|
|
1189
|
+
}
|
|
1190
|
+
/** @type {string | null} */
|
|
1191
|
+
let tempFile = null;
|
|
1192
|
+
if (text !== undefined) {
|
|
1193
|
+
tempFile = join(
|
|
1194
|
+
tmpdir(),
|
|
1195
|
+
`openfeel-req-body-${process.pid}-${Date.now()}-${Math.random().toString(16).slice(2)}.md`,
|
|
1196
|
+
);
|
|
1197
|
+
try {
|
|
1198
|
+
writeFileSync(tempFile, text, 'utf-8');
|
|
1199
|
+
} catch (error) {
|
|
1200
|
+
throw new FeelError(`req body 临时正文文件写入失败:${error instanceof Error ? error.message : String(error)}`, {
|
|
1201
|
+
kind: 'internal',
|
|
1202
|
+
code: 'FEEL_INTERNAL',
|
|
1203
|
+
});
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
const argv = ['req', 'body', id, '--section', section, '--json'];
|
|
1207
|
+
// `--text` 在适配器侧**零命中**(grep 断言):多行正文一律走临时文件 `--file`
|
|
1208
|
+
pushOption(argv, '--file', tempFile ?? file);
|
|
1209
|
+
pushFlag(argv, '--append', args.append);
|
|
1210
|
+
pushFlag(argv, '--replace', args.replace);
|
|
1211
|
+
try {
|
|
1212
|
+
return await envelope(action, async () => {
|
|
1213
|
+
const doc = await writeJsonDoc(cli, argv, opts);
|
|
1214
|
+
const created = doc?.created === true;
|
|
1215
|
+
const lines = typeof doc?.lines === 'number' ? doc.lines : null;
|
|
1216
|
+
const path = typeof doc?.path === 'string' ? doc.path : null;
|
|
1217
|
+
const mode = created ? '新建小节' : (args.append === true ? '追加' : '替换');
|
|
1218
|
+
return {
|
|
1219
|
+
data: { ok: true, id, section, path, lines, created },
|
|
1220
|
+
summary: `需求 ${id} 的「${section}」已${mode}${lines === null ? '' : `(${lines} 行)`}${path === null ? '' : ` → ${path}`}。`,
|
|
1221
|
+
};
|
|
1222
|
+
});
|
|
1223
|
+
} finally {
|
|
1224
|
+
// 临时文件绝不残留(不落工作区,避免 guard / 污染;失败也清理)
|
|
1225
|
+
if (tempFile !== null) {
|
|
1226
|
+
try {
|
|
1227
|
+
rmSync(tempFile, { force: true });
|
|
1228
|
+
} catch {
|
|
1229
|
+
// 清理失败不掩盖主错误
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
918
1234
|
case 'list': {
|
|
919
1235
|
const argv = ['req', 'list', '--json'];
|
|
920
1236
|
pushOption(argv, '--status', args.status);
|
|
@@ -1369,9 +1685,9 @@ export function createTools(context) {
|
|
|
1369
1685
|
const feelVerify = {
|
|
1370
1686
|
name: 'feel_verify',
|
|
1371
1687
|
description:
|
|
1372
|
-
'健康检查与对账。action=health 全面检查 flow.json / 跨文件一致性 / 僵尸状态 / config.yaml(fix=true 时以 flow.json 为权威回写 status.md 的状态字段);action=lint 项目健康检查(i18n 键一致性 / kb 引用有效性);action=recover 跨会话上下文恢复(流水线状态、阻塞原因、待处理任务),换会话或中断后先跑它;action=project 结构化项目概览;action=config_get / config_set 读写项目配置(workflow_mode / auto_advance / merge_mode / execution_mode)。',
|
|
1688
|
+
'健康检查与对账。action=health 全面检查 flow.json / 跨文件一致性 / 僵尸状态 / config.yaml(fix=true 时以 flow.json 为权威回写 status.md 的状态字段);action=lint 项目健康检查(i18n 键一致性 / kb 引用有效性);action=adherence 遵守率四指标(主会话写占比 / 每需求 executor 派发 / 账本同步间隔 / 门禁拒绝率,每键带 definition,只读不改门禁);action=recover 跨会话上下文恢复(流水线状态、阻塞原因、待处理任务),换会话或中断后先跑它;action=project 结构化项目概览;action=config_get / config_set 读写项目配置(workflow_mode / auto_advance / merge_mode / execution_mode)。',
|
|
1373
1689
|
parameters: {
|
|
1374
|
-
action: stringEnum(['health', 'lint', 'recover', 'project', 'config_get', 'config_set', 'config_effective'], '操作。', { required: true }),
|
|
1690
|
+
action: stringEnum(['health', 'lint', 'adherence', 'recover', 'project', 'config_get', 'config_set', 'config_effective'], '操作。', { required: true }),
|
|
1375
1691
|
quick: boolean('health 仅检查关键项。'),
|
|
1376
1692
|
fix: boolean('health 以 flow.json 为权威回写 status.md 状态字段。'),
|
|
1377
1693
|
dry_run: boolean('health fix 仅预览。'),
|
|
@@ -1427,6 +1743,18 @@ export function createTools(context) {
|
|
|
1427
1743
|
return { data, summary: `lint ${target} ${ok ? '通过' : '发现问题'}(${issues} 项)。` };
|
|
1428
1744
|
});
|
|
1429
1745
|
}
|
|
1746
|
+
// v1.6.1 / REQ-066 A66.3:遵守率四指标出口(选定出口,不新增 CLI 子命令/工具;
|
|
1747
|
+
// 数据源与 CLI `lint adherence --json` 同源,只读展示、不产生任何 deny)。
|
|
1748
|
+
case 'adherence':
|
|
1749
|
+
return envelope(action, async () => {
|
|
1750
|
+
const data = await cli.json(['lint', 'adherence', '--json'], opts);
|
|
1751
|
+
const valueOf = (key) => (data?.[key] && typeof data[key] === 'object' ? data[key].value : null);
|
|
1752
|
+
const label = (value) => (value === null || value === undefined ? 'null(样本不足)' : String(value));
|
|
1753
|
+
return {
|
|
1754
|
+
data,
|
|
1755
|
+
summary: `遵守率:main_write_ratio=${label(valueOf('main_write_ratio'))} subagent_per_req=${label(valueOf('subagent_per_req'))} sync_gap=${label(valueOf('sync_gap'))} violation_rate=${label(valueOf('violation_rate'))}(definition 见 details)。`,
|
|
1756
|
+
};
|
|
1757
|
+
});
|
|
1430
1758
|
case 'recover':
|
|
1431
1759
|
return envelope(action, async () => {
|
|
1432
1760
|
const data = await cli.json(['flow', 'recover', '--json'], opts);
|
|
@@ -1665,6 +1993,191 @@ export function createTools(context) {
|
|
|
1665
1993
|
presentCall: (args) => presentCall(`Feel 模型 ${args.action}`, args.action, args.agent),
|
|
1666
1994
|
};
|
|
1667
1995
|
|
|
1996
|
+
/* ══════════════════════════ 14. feel_dispatch ══════════════════════════ */
|
|
1997
|
+
|
|
1998
|
+
const feelDispatch = {
|
|
1999
|
+
name: 'feel_dispatch',
|
|
2000
|
+
description:
|
|
2001
|
+
'派发台账:把「派给谁、派什么、允许写哪些文件」记进 `.openfeel/dev/dispatch.jsonl`(一行一条 JSON,字段见 plan §5.4)。action=record 记录一次派发(同 `leadSessionId+taskId+goal` 5 分钟内去重,返回既有 `dispatchId`);action=finish 按 `dispatchId` **原地补写**闭环字段 `closing{status,artifacts,durationMs,summary}` + 顶层 `closedAt`(行数/行序不变,重复 finish 内容相同 → 幂等 `changed:false`,未知 id → 报错);action=list 读最近 20 条。该文件受 guard 保护:只能经本工具写入,`write`/`edit`/shell 直写会被拒绝。台账是**提示级观测**(不做硬拦),`feel_status.dispatch` 汇总 `required / total / sincePhase / open / closedRatio / missingRoles / records`。',
|
|
2002
|
+
parameters: {
|
|
2003
|
+
action: stringEnum(['record', 'finish', 'list'], '操作。', { required: true }),
|
|
2004
|
+
target_agent: string('目标子 agent 名(如 executor-a-cli)。record 必需。'),
|
|
2005
|
+
role: stringEnum(DISPATCH_ROLES, '目标角色。record 必需。'),
|
|
2006
|
+
goal: string('一句话任务(含验收命令,可直接粘贴进 subagent prompt)。record 必需。'),
|
|
2007
|
+
task_id: string('任务编号(如 T9),用于 5 分钟去重。record 必需。'),
|
|
2008
|
+
files: stringArray('本任务允许写的文件 / 目录清单(可选,写入台账的 files[])。'),
|
|
2009
|
+
dispatch_id: string('要闭合的派发 ID(如 d-0001)。finish 必需。'),
|
|
2010
|
+
status: stringEnum(['done', 'failed'], '闭合状态:done=完成,failed=失败。finish 必需。'),
|
|
2011
|
+
artifacts: stringArray('本次派发产出的文件 / 证据(finish 写入 closing.artifacts[])。'),
|
|
2012
|
+
summary: string('一句话结论(finish 写入 closing.summary;≤10 行回报摘要)。'),
|
|
2013
|
+
stage: string('阶段 ID(可选;缺省取当前活跃阶段,读一次 flow next)。'),
|
|
2014
|
+
phase: string('相位(可选;缺省取当前阶段相位)。'),
|
|
2015
|
+
project: string('项目根目录。'),
|
|
2016
|
+
},
|
|
2017
|
+
output: { schema: envelopeSchema(), render: renderEnvelope },
|
|
2018
|
+
async execute(args, exec) {
|
|
2019
|
+
const resolved = target(exec, args);
|
|
2020
|
+
requireInitialized(resolved);
|
|
2021
|
+
const action = args.action;
|
|
2022
|
+
const opts = { cwd: resolved.cwd, signal: exec.signal };
|
|
2023
|
+
|
|
2024
|
+
switch (action) {
|
|
2025
|
+
case 'record': {
|
|
2026
|
+
const targetAgent = requireArg(args, 'target_agent', action);
|
|
2027
|
+
const role = requireArg(args, 'role', action);
|
|
2028
|
+
const goal = requireArg(args, 'goal', action);
|
|
2029
|
+
const taskId = requireArg(args, 'task_id', action);
|
|
2030
|
+
if (!DISPATCH_ROLES.includes(role)) {
|
|
2031
|
+
throw new FeelError(`非法 role: ${role}(合法值:${DISPATCH_ROLES.join(' / ')})`, {
|
|
2032
|
+
kind: 'usage',
|
|
2033
|
+
code: 'FEEL_INVALID_ARGUMENT',
|
|
2034
|
+
});
|
|
2035
|
+
}
|
|
2036
|
+
return envelope(action, async () => {
|
|
2037
|
+
const focus = await resolveDispatchFocus(cli, opts, args);
|
|
2038
|
+
const origin = dispatchOriginOf(exec);
|
|
2039
|
+
const result = appendDispatch(resolved.cwd, {
|
|
2040
|
+
leadSessionId: dispatchSessionOf(exec, resolved.cwd),
|
|
2041
|
+
origin: origin.origin,
|
|
2042
|
+
stage: focus.stage,
|
|
2043
|
+
phase: focus.phase,
|
|
2044
|
+
targetAgent,
|
|
2045
|
+
role,
|
|
2046
|
+
taskId,
|
|
2047
|
+
goal,
|
|
2048
|
+
files: Array.isArray(args.files) ? args.files : [],
|
|
2049
|
+
returnFormat: '≤10 行:结论/改动文件/验证/阻塞',
|
|
2050
|
+
dispatchDepth: origin.dispatchDepth,
|
|
2051
|
+
});
|
|
2052
|
+
const where = focus.stage === '' ? '(无阶段)' : `${focus.stage}/${focus.phase || '(无相位)'}`;
|
|
2053
|
+
const summary = result.duplicate
|
|
2054
|
+
? `重复派发(5 分钟内同 leadSessionId+taskId+goal):沿用 ${result.dispatchId}(${where})。`
|
|
2055
|
+
: `已记录派发 ${result.dispatchId}:${role} → ${targetAgent}(${where})。`;
|
|
2056
|
+
return {
|
|
2057
|
+
data: { dispatchId: result.dispatchId, path: result.path, duplicate: result.duplicate },
|
|
2058
|
+
summary,
|
|
2059
|
+
next: { tool: 'feel_status', arguments: {}, why: '确认 dispatch.records / missingRoles 已更新。' },
|
|
2060
|
+
};
|
|
2061
|
+
});
|
|
2062
|
+
}
|
|
2063
|
+
case 'finish': {
|
|
2064
|
+
// v1.6.1 / REQ-066 A66.1:按 dispatchId 原地补写 closing(行数/行序不变、幂等)。
|
|
2065
|
+
const dispatchId = requireArg(args, 'dispatch_id', action);
|
|
2066
|
+
const status = requireArg(args, 'status', action);
|
|
2067
|
+
if (status !== 'done' && status !== 'failed') {
|
|
2068
|
+
throw new FeelError(`非法 status: ${status}(合法值:done / failed)`, {
|
|
2069
|
+
kind: 'usage',
|
|
2070
|
+
code: 'FEEL_INVALID_ARGUMENT',
|
|
2071
|
+
});
|
|
2072
|
+
}
|
|
2073
|
+
const result = closeDispatch(resolved.cwd, dispatchId, {
|
|
2074
|
+
status,
|
|
2075
|
+
artifacts: Array.isArray(args.artifacts) ? args.artifacts : [],
|
|
2076
|
+
summary: typeof args.summary === 'string' ? args.summary : '',
|
|
2077
|
+
});
|
|
2078
|
+
if (result.ok !== true) {
|
|
2079
|
+
throw new FeelError(
|
|
2080
|
+
result.code === 'not_found'
|
|
2081
|
+
? `未找到派发 ${dispatchId}(${DISPATCH_LEDGER_REL_PATH} 无此 dispatchId;先 record 再 finish)。`
|
|
2082
|
+
: `闭合参数非法(${result.code});status 必须是 done / failed。`,
|
|
2083
|
+
{
|
|
2084
|
+
kind: 'refusal',
|
|
2085
|
+
code: result.code === 'not_found' ? 'FEEL_DISPATCH_NOT_FOUND' : 'FEEL_INVALID_ARGUMENT',
|
|
2086
|
+
detail: { dispatchId, code: result.code },
|
|
2087
|
+
},
|
|
2088
|
+
);
|
|
2089
|
+
}
|
|
2090
|
+
return envelope(action, async () => ({
|
|
2091
|
+
data: { ok: true, dispatchId: result.dispatchId, closedAt: result.closedAt, changed: result.changed },
|
|
2092
|
+
summary: result.changed
|
|
2093
|
+
? `已闭合派发 ${result.dispatchId}(status=${status},closedAt=${result.closedAt})。`
|
|
2094
|
+
: `派发 ${result.dispatchId} 已闭合且内容相同(幂等,未改写 ts/closing/closedAt)。`,
|
|
2095
|
+
next: { tool: 'feel_status', arguments: {}, why: '确认 dispatch.open[] / closedRatio 已更新。' },
|
|
2096
|
+
}));
|
|
2097
|
+
}
|
|
2098
|
+
case 'list': {
|
|
2099
|
+
return envelope(action, async () => {
|
|
2100
|
+
const all = readDispatches(resolved.cwd);
|
|
2101
|
+
const records = all.slice(-20);
|
|
2102
|
+
return {
|
|
2103
|
+
data: { total: all.length, limit: 20, path: dispatchLedgerPath(resolved.cwd), records },
|
|
2104
|
+
summary: `派发台账共 ${all.length} 条,返回最近 ${records.length} 条(${DISPATCH_LEDGER_REL_PATH})。`,
|
|
2105
|
+
};
|
|
2106
|
+
});
|
|
2107
|
+
}
|
|
2108
|
+
default:
|
|
2109
|
+
throw new FeelError(`未知 action: ${action}`, { kind: 'usage', code: 'FEEL_UNKNOWN_ACTION' });
|
|
2110
|
+
}
|
|
2111
|
+
},
|
|
2112
|
+
presentCall: (args) => presentCall('Feel 派发台账', args.action, args?.target_agent),
|
|
2113
|
+
};
|
|
2114
|
+
|
|
2115
|
+
/* ══════════════════════════ 15. feel_dev ══════════════════════════ */
|
|
2116
|
+
|
|
2117
|
+
const feelDev = {
|
|
2118
|
+
name: 'feel_dev',
|
|
2119
|
+
description:
|
|
2120
|
+
'开发账本(openfeel dev):把提示里「更新交接摘要后运行 openfeel dev sync」这条**死指令**变成可执行工具。action=sync 立即同步受管 AUTO 块(`.openfeel/users/<u>/dev_last.md` + `.openfeel/dev/current.md`)并刷新 `.openfeel/dev/.sync.json`;action=status 只读查看 lastSync / due(与 CLI `openfeel dev status` 同源 `.openfeel/dev/.sync.json`)。CLI 的 `dev status` 没有 `--json`(零 JSON 契约),所以适配器跑真实命令作权威、结构化字段直接读同一份 `.sync.json`。返回 `{ok, lastSync, due, changed, wrote[]}`。',
|
|
2121
|
+
parameters: {
|
|
2122
|
+
action: stringEnum(['sync', 'status'], '操作。sync=立即同步账本;status=只读查看是否到期。', { required: true }),
|
|
2123
|
+
project: string('项目根目录。'),
|
|
2124
|
+
},
|
|
2125
|
+
output: { schema: envelopeSchema(), render: renderEnvelope },
|
|
2126
|
+
async execute(args, exec) {
|
|
2127
|
+
const resolved = target(exec, args);
|
|
2128
|
+
requireInitialized(resolved);
|
|
2129
|
+
const action = args.action;
|
|
2130
|
+
const opts = { cwd: resolved.cwd, signal: exec.signal };
|
|
2131
|
+
|
|
2132
|
+
if (action === 'status') {
|
|
2133
|
+
return envelope(action, async () => {
|
|
2134
|
+
// 真实命令校验「CLI 可用 + 项目已初始化」;字段与 CLI 同源(同一 .sync.json)。
|
|
2135
|
+
await cli.text(['dev', 'status'], opts);
|
|
2136
|
+
const status = readStatusSync(resolved.cwd);
|
|
2137
|
+
return {
|
|
2138
|
+
data: {
|
|
2139
|
+
ok: true,
|
|
2140
|
+
lastSync: status.lastSync,
|
|
2141
|
+
due: status.due,
|
|
2142
|
+
changed: false,
|
|
2143
|
+
wrote: [],
|
|
2144
|
+
},
|
|
2145
|
+
summary: `账本同步状态:lastSync=${status.lastSync ?? '(无)'} due=${status.due}(间隔 ${status.intervalMinutes} 分钟)。`,
|
|
2146
|
+
next: status.due
|
|
2147
|
+
? { tool: 'feel_dev', arguments: { action: 'sync' }, why: '状态记录已到期:立即同步一次。' }
|
|
2148
|
+
: null,
|
|
2149
|
+
};
|
|
2150
|
+
});
|
|
2151
|
+
}
|
|
2152
|
+
|
|
2153
|
+
if (action !== 'sync') {
|
|
2154
|
+
throw new FeelError(`未知 action: ${action}`, { kind: 'usage', code: 'FEEL_UNKNOWN_ACTION' });
|
|
2155
|
+
}
|
|
2156
|
+
|
|
2157
|
+
return envelope(action, async () => {
|
|
2158
|
+
// `wrote[]` 是**观测结果**,不是承诺:状态未变时 CLI 跳过重写(blockChanged),
|
|
2159
|
+
// 因此这里用同步前后内容对比得出真实变更,不硬编码「写到哪两个文件」。
|
|
2160
|
+
const before = snapshotDevDocs(resolved.cwd);
|
|
2161
|
+
await cli.write(['dev', 'sync'], opts);
|
|
2162
|
+
const wrote = diffDevDocs(before, snapshotDevDocs(resolved.cwd), resolved.cwd);
|
|
2163
|
+
const status = readStatusSync(resolved.cwd);
|
|
2164
|
+
return {
|
|
2165
|
+
data: {
|
|
2166
|
+
ok: true,
|
|
2167
|
+
lastSync: status.lastSync,
|
|
2168
|
+
due: status.due,
|
|
2169
|
+
changed: wrote.length > 0,
|
|
2170
|
+
wrote,
|
|
2171
|
+
},
|
|
2172
|
+
summary: wrote.length === 0
|
|
2173
|
+
? `账本已同步:状态未变(无文件重写),lastSync=${status.lastSync ?? '(无)'}。`
|
|
2174
|
+
: `账本已同步:重写 ${wrote.length} 个文件(${wrote.join(' / ')}),lastSync=${status.lastSync ?? '(无)'}。`,
|
|
2175
|
+
};
|
|
2176
|
+
});
|
|
2177
|
+
},
|
|
2178
|
+
presentCall: (args) => presentCall(`Feel 账本 ${args.action}`, args.action),
|
|
2179
|
+
};
|
|
2180
|
+
|
|
1668
2181
|
const tools = [
|
|
1669
2182
|
feelStatus,
|
|
1670
2183
|
feelNext,
|
|
@@ -1679,6 +2192,8 @@ export function createTools(context) {
|
|
|
1679
2192
|
feelReview,
|
|
1680
2193
|
feelPlan,
|
|
1681
2194
|
feelModel,
|
|
2195
|
+
feelDispatch,
|
|
2196
|
+
feelDev,
|
|
1682
2197
|
// 注册表既不编译也不校验 parameters(本插件不经 defineTool),
|
|
1683
2198
|
// 因此在交给注册表前统一转成子集接受的裸 JSON Schema。
|
|
1684
2199
|
].map((tool) => ({ ...tool, parameters: compileParameters(tool.parameters) }));
|