openfeel 1.6.0 → 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.
Files changed (80) hide show
  1. package/README.en.md +7 -0
  2. package/README.zh-CN.md +7 -0
  3. package/dist/commands/dashboard.d.ts.map +1 -1
  4. package/dist/commands/dashboard.js +10 -1
  5. package/dist/commands/dashboard.js.map +1 -1
  6. package/dist/commands/flow.d.ts.map +1 -1
  7. package/dist/commands/flow.js +19 -12
  8. package/dist/commands/flow.js.map +1 -1
  9. package/dist/commands/lint.d.ts +3 -1
  10. package/dist/commands/lint.d.ts.map +1 -1
  11. package/dist/commands/lint.js +279 -2
  12. package/dist/commands/lint.js.map +1 -1
  13. package/dist/commands/req.d.ts.map +1 -1
  14. package/dist/commands/req.js +470 -95
  15. package/dist/commands/req.js.map +1 -1
  16. package/dist/core/adherence.d.ts +135 -0
  17. package/dist/core/adherence.d.ts.map +1 -0
  18. package/dist/core/adherence.js +221 -0
  19. package/dist/core/adherence.js.map +1 -0
  20. package/dist/core/dashboard/aggregate.d.ts +39 -0
  21. package/dist/core/dashboard/aggregate.d.ts.map +1 -1
  22. package/dist/core/dashboard/aggregate.js +64 -5
  23. package/dist/core/dashboard/aggregate.js.map +1 -1
  24. package/dist/core/dashboard/render.d.ts.map +1 -1
  25. package/dist/core/dashboard/render.js +88 -1
  26. package/dist/core/dashboard/render.js.map +1 -1
  27. package/dist/core/errors.d.ts +27 -2
  28. package/dist/core/errors.d.ts.map +1 -1
  29. package/dist/core/errors.js +15 -2
  30. package/dist/core/errors.js.map +1 -1
  31. package/dist/core/flow/gate-override.d.ts +72 -0
  32. package/dist/core/flow/gate-override.d.ts.map +1 -0
  33. package/dist/core/flow/gate-override.js +71 -0
  34. package/dist/core/flow/gate-override.js.map +1 -0
  35. package/dist/core/flow-manager.d.ts +13 -4
  36. package/dist/core/flow-manager.d.ts.map +1 -1
  37. package/dist/core/flow-manager.js +47 -16
  38. package/dist/core/flow-manager.js.map +1 -1
  39. package/dist/core/i18n-data/en.d.ts.map +1 -1
  40. package/dist/core/i18n-data/en.js +45 -6
  41. package/dist/core/i18n-data/en.js.map +1 -1
  42. package/dist/core/i18n-data/zh-CN.d.ts.map +1 -1
  43. package/dist/core/i18n-data/zh-CN.js +45 -6
  44. package/dist/core/i18n-data/zh-CN.js.map +1 -1
  45. package/dist/core/req/body-file.d.ts +37 -0
  46. package/dist/core/req/body-file.d.ts.map +1 -1
  47. package/dist/core/req/body-file.js +39 -2
  48. package/dist/core/req/body-file.js.map +1 -1
  49. package/dist/core/req/plan-file.d.ts +83 -0
  50. package/dist/core/req/plan-file.d.ts.map +1 -0
  51. package/dist/core/req/plan-file.js +205 -0
  52. package/dist/core/req/plan-file.js.map +1 -0
  53. package/dist/core/req/requirement-ops.d.ts +25 -3
  54. package/dist/core/req/requirement-ops.d.ts.map +1 -1
  55. package/dist/core/req/requirement-ops.js +66 -11
  56. package/dist/core/req/requirement-ops.js.map +1 -1
  57. package/dist/core/req/types.d.ts +8 -2
  58. package/dist/core/req/types.d.ts.map +1 -1
  59. package/dist/core/req/types.js +10 -2
  60. package/dist/core/req/types.js.map +1 -1
  61. package/dist/core/template-loader.d.ts.map +1 -1
  62. package/dist/core/template-loader.js +12 -0
  63. package/dist/core/template-loader.js.map +1 -1
  64. package/dist/core/templates.d.ts +1 -1
  65. package/dist/core/templates.d.ts.map +1 -1
  66. package/dist/core/templates.js +18 -0
  67. package/dist/core/templates.js.map +1 -1
  68. package/dsh/ACTION-GUIDE.md +15 -6
  69. package/dsh/ADAPTER.md +62 -1
  70. package/dsh/README.md +13 -11
  71. package/dsh/docs/compat/persistence.md +13 -0
  72. package/dsh/docs/compat/pipeline.md +12 -0
  73. package/dsh/docs/compat/req.md +15 -0
  74. package/dsh/docs/compat/stage.md +12 -0
  75. package/dsh/lib/adapters/dispatch-ledger.js +149 -10
  76. package/dsh/lib/guard.js +685 -22
  77. package/dsh/lib/surface/prompt.js +4 -0
  78. package/dsh/lib/tools/index.js +113 -22
  79. package/dsh/package.json +2 -2
  80. package/package.json +2 -1
@@ -36,6 +36,8 @@ export const FEEL_BODY_ZH = `## 你的角色:调度者,不是执行者
36
36
  2. 需求没有 \`.openfeel/plan/reqs/REQ-NNN.plan.md\`(或仍是占位空壳)→ 不执行:先补正文(\`feel_req action=body\`)与需求级计划;否则被拒 \`REQ_PLAN_GATE\` / \`STAGE_PLAN_GATE\`。
37
37
  3. 要执行任何一步 → 必须派发子 agent(planner 定计划 / executor 执行 / reviewer 审查)并用 \`feel_dispatch\` 记账,主会话只收 ≤10 行回报;主会话直接改仓库即违规(台账无记录 = 未派发)。
38
38
 
39
+ 版本号默认按补丁推进(x.y.Z);结构性/行为性变更才升 minor,破坏性才升 major,小改不跳级。
40
+
39
41
  ## 兜底
40
42
  不确定时调 \`feel_status\` / \`feel_next\`,不要凭记忆;禁手改 \`flow.json\` / \`status.md\`。
41
43
  `;
@@ -52,6 +54,8 @@ Subagents write files, edit code and run tests; you decide who acts, dispatch, l
52
54
  2. No \`.openfeel/plan/reqs/REQ-NNN.plan.md\` (or placeholder) → stop; write body + plan first; else \`REQ_PLAN_GATE\` / \`STAGE_PLAN_GATE\`.
53
55
  3. Before executing → dispatch a subagent (planner / executor / reviewer) and log it with \`feel_dispatch\`; main session gets ≤10 lines; direct repo edits = violation.
54
56
 
57
+ Version: patch; minor structural; major breaking.
58
+
55
59
  Unsure? \`feel_status\` / \`feel_next\`; never memory-only. Never hand-edit \`flow.json\` / \`status.md\`.
56
60
  `;
57
61
 
@@ -11,8 +11,9 @@
11
11
  * 3. 在拒绝时给出**可操作的下一步**(改哪个参数、先跑哪条命令)。
12
12
  */
13
13
 
14
- import { readdirSync, readFileSync } from 'node:fs';
14
+ import { readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
15
15
  import { join, relative, sep } from 'node:path';
16
+ import { tmpdir } from 'node:os';
16
17
 
17
18
  import { FeelError } from '../adapters/cli.js';
18
19
  import { legalNextPhases, planNextStep, readSnapshot } from '../adapters/dashboard.js';
@@ -25,6 +26,7 @@ import {
25
26
  DISPATCH_LEDGER_REL_PATH,
26
27
  DISPATCH_ROLES,
27
28
  appendDispatch,
29
+ closeDispatch,
28
30
  dispatchLedgerPath,
29
31
  dispatchSummary,
30
32
  readDispatches,
@@ -167,17 +169,26 @@ function safeObservability(snapshot) {
167
169
  * **提示级,不做硬拦**(用户裁定 ②):`required` 恒 true 只表示「建议走台账」,
168
170
  * 不阻断任何工具调用。台账读取失败降级为空台账(观测数据绝不影响 feel_status)。
169
171
  *
170
- * 形状与 `dispatchSummary` 单点对齐:`{required, total, sincePhase, missingRoles, records}`。
172
+ * 形状与 `dispatchSummary` 单点对齐:`{required, total, sincePhase, open, closedRatio, missingRoles, records}`
173
+ * (v1.6.1 / REQ-066 A66.2 增 `open[]` / `closedRatio`;既有四键保留)。
171
174
  *
172
175
  * @param {string} projectRoot
173
176
  * @param {{ stage?: string, phase?: string }} [focus]
174
- * @returns {{ required: true, total: number, sincePhase: number, missingRoles: string[], records: Array<Record<string, any>> }}
177
+ * @returns {{ required: true, total: number, sincePhase: number, open: Array<Record<string, any>>, closedRatio: number | null, missingRoles: string[], records: Array<Record<string, any>> }}
175
178
  */
176
179
  function safeDispatchSection(projectRoot, focus = {}) {
177
180
  try {
178
181
  return dispatchSummary(projectRoot, { stage: focus.stage ?? '', phase: focus.phase ?? '' });
179
182
  } catch {
180
- return { required: true, total: 0, sincePhase: 0, missingRoles: [...DISPATCH_ROLES], records: [] };
183
+ return {
184
+ required: true,
185
+ total: 0,
186
+ sincePhase: 0,
187
+ open: [],
188
+ closedRatio: null,
189
+ missingRoles: [...DISPATCH_ROLES],
190
+ records: [],
191
+ };
181
192
  }
182
193
  }
183
194
 
@@ -1154,7 +1165,9 @@ export function createTools(context) {
1154
1165
  // shell 跑 openfeel 写命令同样被拒 —— 这是给正文开的唯一通道。
1155
1166
  const id = requireArg(args, 'id', action);
1156
1167
  const section = requireArg(args, 'section', action);
1157
- const text = optionalArg(args, 'text');
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;
1158
1171
  const file = optionalArg(args, 'file');
1159
1172
  if (text === undefined && file === undefined) {
1160
1173
  throw new FeelError('req body 需要 text 或 file 之一(小节正文来源)', {
@@ -1174,22 +1187,49 @@ export function createTools(context) {
1174
1187
  code: 'FEEL_BAD_USAGE',
1175
1188
  });
1176
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
+ }
1177
1206
  const argv = ['req', 'body', id, '--section', section, '--json'];
1178
- pushOption(argv, '--text', text);
1179
- pushOption(argv, '--file', file);
1207
+ // `--text` 在适配器侧**零命中**(grep 断言):多行正文一律走临时文件 `--file`
1208
+ pushOption(argv, '--file', tempFile ?? file);
1180
1209
  pushFlag(argv, '--append', args.append);
1181
1210
  pushFlag(argv, '--replace', args.replace);
1182
- return envelope(action, async () => {
1183
- const doc = await writeJsonDoc(cli, argv, opts);
1184
- const created = doc?.created === true;
1185
- const lines = typeof doc?.lines === 'number' ? doc.lines : null;
1186
- const path = typeof doc?.path === 'string' ? doc.path : null;
1187
- const mode = created ? '新建小节' : (args.append === true ? '追加' : '替换');
1188
- return {
1189
- data: { ok: true, id, section, path, lines, created },
1190
- summary: `需求 ${id} 的「${section}」已${mode}${lines === null ? '' : `(${lines} 行)`}${path === null ? '' : ` → ${path}`}。`,
1191
- };
1192
- });
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
+ }
1193
1233
  }
1194
1234
  case 'list': {
1195
1235
  const argv = ['req', 'list', '--json'];
@@ -1645,9 +1685,9 @@ export function createTools(context) {
1645
1685
  const feelVerify = {
1646
1686
  name: 'feel_verify',
1647
1687
  description:
1648
- '健康检查与对账。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)。',
1649
1689
  parameters: {
1650
- 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 }),
1651
1691
  quick: boolean('health 仅检查关键项。'),
1652
1692
  fix: boolean('health 以 flow.json 为权威回写 status.md 状态字段。'),
1653
1693
  dry_run: boolean('health fix 仅预览。'),
@@ -1703,6 +1743,18 @@ export function createTools(context) {
1703
1743
  return { data, summary: `lint ${target} ${ok ? '通过' : '发现问题'}(${issues} 项)。` };
1704
1744
  });
1705
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
+ });
1706
1758
  case 'recover':
1707
1759
  return envelope(action, async () => {
1708
1760
  const data = await cli.json(['flow', 'recover', '--json'], opts);
@@ -1946,14 +1998,18 @@ export function createTools(context) {
1946
1998
  const feelDispatch = {
1947
1999
  name: 'feel_dispatch',
1948
2000
  description:
1949
- '派发台账:把「派给谁、派什么、允许写哪些文件」记进 `.openfeel/dev/dispatch.jsonl`(一行一条 JSON,字段见 plan §5.4)。action=record 记录一次派发(同 `leadSessionId+taskId+goal` 5 分钟内去重,返回既有 `dispatchId`);action=list 读最近 20 条。该文件受 guard 保护:只能经本工具写入,`write`/`edit`/shell 直写会被拒绝。台账是**提示级观测**(不做硬拦),`feel_status.dispatch` 汇总 `required / total / sincePhase / missingRoles / records`。',
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`。',
1950
2002
  parameters: {
1951
- action: stringEnum(['record', 'list'], '操作。', { required: true }),
2003
+ action: stringEnum(['record', 'finish', 'list'], '操作。', { required: true }),
1952
2004
  target_agent: string('目标子 agent 名(如 executor-a-cli)。record 必需。'),
1953
2005
  role: stringEnum(DISPATCH_ROLES, '目标角色。record 必需。'),
1954
2006
  goal: string('一句话任务(含验收命令,可直接粘贴进 subagent prompt)。record 必需。'),
1955
2007
  task_id: string('任务编号(如 T9),用于 5 分钟去重。record 必需。'),
1956
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 行回报摘要)。'),
1957
2013
  stage: string('阶段 ID(可选;缺省取当前活跃阶段,读一次 flow next)。'),
1958
2014
  phase: string('相位(可选;缺省取当前阶段相位)。'),
1959
2015
  project: string('项目根目录。'),
@@ -2004,6 +2060,41 @@ export function createTools(context) {
2004
2060
  };
2005
2061
  });
2006
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
+ }
2007
2098
  case 'list': {
2008
2099
  return envelope(action, async () => {
2009
2100
  const all = readDispatches(resolved.cwd);
package/dsh/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openfeel-dsh",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
4
4
  "description": "将 OpenFeel 的工作记录与开发流程接入 DeepSeek Harness:记住项目做到哪、下一步做什么,默认自由模式,也可切到按步骤走的流程模式",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "openfeel": {
38
38
  "adapter": "dsh",
39
- "requiresCli": ">=1.6.0"
39
+ "requiresCli": ">=1.6.1"
40
40
  },
41
41
  "keywords": [
42
42
  "openfeel",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openfeel",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
4
4
  "description": "AI Agent 开发流程治理 CLI 工具",
5
5
  "type": "module",
6
6
  "private": false,
@@ -12,6 +12,7 @@
12
12
  },
13
13
  "scripts": {
14
14
  "build": "node build.js",
15
+ "release": "node scripts/release.mjs",
15
16
  "test": "vitest run",
16
17
  "test:coverage": "vitest run --coverage",
17
18
  "dev": "vitest",