openfeel 1.5.12 → 1.5.14

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 (38) hide show
  1. package/README.md +1 -1
  2. package/dist/commands/flow.d.ts.map +1 -1
  3. package/dist/commands/flow.js +138 -31
  4. package/dist/commands/flow.js.map +1 -1
  5. package/dist/core/flow-manager.d.ts +52 -1
  6. package/dist/core/flow-manager.d.ts.map +1 -1
  7. package/dist/core/flow-manager.js +117 -2
  8. package/dist/core/flow-manager.js.map +1 -1
  9. package/dist/core/i18n-data/en.d.ts.map +1 -1
  10. package/dist/core/i18n-data/en.js +8 -0
  11. package/dist/core/i18n-data/en.js.map +1 -1
  12. package/dist/core/i18n-data/zh-CN.d.ts.map +1 -1
  13. package/dist/core/i18n-data/zh-CN.js +9 -0
  14. package/dist/core/i18n-data/zh-CN.js.map +1 -1
  15. package/dist/core/preflight.d.ts +8 -0
  16. package/dist/core/preflight.d.ts.map +1 -1
  17. package/dist/core/preflight.js +25 -2
  18. package/dist/core/preflight.js.map +1 -1
  19. package/dist/core/process-health.d.ts +2 -2
  20. package/dist/core/process-health.d.ts.map +1 -1
  21. package/dist/core/process-health.js +4 -4
  22. package/dist/core/process-health.js.map +1 -1
  23. package/dist/core/template-loader.d.ts.map +1 -1
  24. package/dist/core/template-loader.js +18 -2
  25. package/dist/core/template-loader.js.map +1 -1
  26. package/dist/core/update.d.ts.map +1 -1
  27. package/dist/core/update.js +18 -2
  28. package/dist/core/update.js.map +1 -1
  29. package/dsh/ADAPTER.md +12 -4
  30. package/dsh/README.md +1 -1
  31. package/dsh/lib/adapters/cli.js +15 -0
  32. package/dsh/lib/adapters/dashboard.js +8 -1
  33. package/dsh/lib/adapters/preflight.js +23 -1
  34. package/dsh/lib/guard.js +104 -14
  35. package/dsh/lib/surface/prompt.js +1 -1
  36. package/dsh/lib/tools/index.js +1 -1
  37. package/dsh/package.json +2 -2
  38. package/package.json +1 -1
package/dsh/lib/guard.js CHANGED
@@ -118,6 +118,43 @@ export function resolveShellGate(raw) {
118
118
  };
119
119
  }
120
120
 
121
+ /**
122
+ * `OPENFEEL_SHELL_ALLOW` 白名单解析(v1.5.14 / stage-129 OF-05)。
123
+ *
124
+ * `||` 分隔多条;条目与命令在比较前都折叠空白、去首尾。只用于第 4 类
125
+ * `undecidable` 出口,且必须**整条命令全等**——绝不做子串匹配:否则白名单
126
+ * `npm run build` 会把 `rm -rf x && npm run build` 一起放行。
127
+ *
128
+ * @param {unknown} [raw]
129
+ * @returns {string[]}
130
+ */
131
+ function parseShellAllowlist(raw = process.env.OPENFEEL_SHELL_ALLOW) {
132
+ if (typeof raw !== 'string' || raw.trim() === '') return [];
133
+ return raw
134
+ .split('||')
135
+ .map((entry) => entry.replace(/\s+/g, ' ').trim())
136
+ .filter((entry) => entry !== '');
137
+ }
138
+
139
+ /** 命令与白名单条目共用的归一化:折叠连续空白 + 去首尾。 */
140
+ function collapseShellWhitespace(value) {
141
+ return String(value).replace(/\s+/g, ' ').trim();
142
+ }
143
+
144
+ /**
145
+ * 命令是否命中 `OPENFEEL_SHELL_ALLOW`(整条全等;空命令永不命中)。
146
+ *
147
+ * @param {string} command
148
+ * @param {string[]} entries
149
+ * @returns {boolean}
150
+ */
151
+ function isShellAllowlisted(command, entries) {
152
+ if (entries.length === 0 || typeof command !== 'string') return false;
153
+ const normalized = collapseShellWhitespace(command);
154
+ if (normalized === '') return false;
155
+ return entries.some((entry) => entry === normalized);
156
+ }
157
+
121
158
  /**
122
159
  * 大小写不敏感文件系统:Windows + 默认 macOS(APFS/HFS+)。
123
160
  * 在这两类平台上把路径统一小写,防止 `.OPENFEEL/FLOW.JSON` 绕过。
@@ -412,12 +449,16 @@ export function isExemptPath(absolute, cwd) {
412
449
  }
413
450
 
414
451
  /**
415
- * 审计里的命令片段(v1.5.11 D-126-02):折叠空白并截断到 200 字符。
452
+ * 审计里的命令片段(v1.5.11 D-126-02):折叠空白并截断到 500 字符。
453
+ *
454
+ * v1.5.14 / stage-129 OF-08.1:上限 200 → 500。`lastDecision`
455
+ * (`.openfeel/dev/guard-state.json`)与审计(`guard-audit.jsonl`)**共用**该上限
456
+ * (两处都走本函数,没有第二份截断逻辑);长命令的排查信息不再被腰斩。
416
457
  * @param {unknown} command
417
458
  * @param {number} [limit]
418
459
  * @returns {string | undefined}
419
460
  */
420
- function truncateCommand(command, limit = 200) {
461
+ function truncateCommand(command, limit = 500) {
421
462
  if (typeof command !== 'string') return undefined;
422
463
  const value = command.replace(/\s+/g, ' ').trim();
423
464
  if (value === '') return undefined;
@@ -432,10 +473,10 @@ function truncateCommand(command, limit = 200) {
432
473
  * —— 那恰好是最需要证据的时刻。写失败也出声(stderr)。
433
474
  *
434
475
  * 每行必须带 `cwdSource`(验收 14)与 `decision`(allow|deny|warn);shell 行
435
- * 额外带 `command`(截断 ≤200 字符),否则「门禁是否真的拦过」无法自证。
476
+ * 额外带 `command`(截断 ≤500 字符,v1.5.14 / stage-129 OF-08.1),否则「门禁是否真的拦过」无法自证。
436
477
  *
437
478
  * @param {string | null} cwd 已归一化工作区(null = 不可解析)
438
- * @param {{ event?: 'guard_allow'|'guard_deny'|'guard_shell_unresolved'|'guard_shell_downgraded', decision?: 'allow'|'deny'|'warn', tool: string, reason: string, phase: string, paths: string[], cwdSource?: string, command?: string }} event
479
+ * @param {{ event?: 'guard_allow'|'guard_deny'|'guard_shell_unresolved'|'guard_shell_downgraded'|'guard_shell_allowlisted', decision?: 'allow'|'deny'|'warn', tool: string, reason: string, phase: string, paths: string[], cwdSource?: string, command?: string }} event
439
480
  */
440
481
  function recordGuardAudit(cwd, event) {
441
482
  const entry = {
@@ -2106,7 +2147,9 @@ function coversWholeTree(token) {
2106
2147
  * 整树写(`reset --hard`/`--merge`、`stash`(含 `push`)、`clean`、`commit`、
2107
2148
  * `checkout/switch 分支`、`merge/rebase/pull/…`)需要特定相位:
2108
2149
  * - 默认要求 `exec_running`(否则「非 exec 相位用 git 还原/丢弃源码」绕过一切文件门禁);
2109
- * - `commit` 额外允许 `archiving`(op-005 / P1-4:发版提交发生在 archiving);
2150
+ * - `commit` 额外允许 `review_passed` / `test_passed` / `archiving`(op-005 / P1-4:
2151
+ * 发版提交发生在 archiving;v1.5.13 / stage-128:审完即可提交、测完即可提交);
2152
+ * 只放宽 `commit` 的 `phases`,写侧相位门槛(`decideForTargets`)仍只认 `exec_running`;
2110
2153
  * - 进入整树写前还有一道 `.openfeel/**` 无差异检查(op-005 / P1-2),见 `openfeelTreeDirty`。
2111
2154
  * @param {string[]} tokens
2112
2155
  * @param {number} start
@@ -2233,10 +2276,13 @@ function classifyGitCommand(tokens, start, baseDir) {
2233
2276
  // v1.5.12 / stage-127 C.1/C.4:`gitSubcommand` 与 `repoOverride` 供
2234
2277
  // 「无阶段纯书账」分支判定(字段白名单必须两处一并透传,见
2235
2278
  // `analyzeShellStatement` / `classifyShellCommand`)。
2279
+ // v1.5.13 / stage-128:审完即可提交(`review_passed`)/ 测完即可提交(`test_passed`),
2280
+ // `done` 仍拒(工作已收口,落地走归档提交)。**只放宽 commit**:写侧相位
2281
+ // (`decideForTargets`)与 `checkout`/`reset --hard`/`stash`/`clean` 一律不动。
2236
2282
  return {
2237
2283
  kind: 'whole-tree',
2238
2284
  detail: 'git commit',
2239
- phases: ['exec_running', 'archiving'],
2285
+ phases: ['exec_running', 'review_passed', 'test_passed', 'archiving'],
2240
2286
  preservesWorktree: true,
2241
2287
  gitSubcommand: 'commit',
2242
2288
  repoOverride,
@@ -2883,7 +2929,8 @@ function decideForTargets(context, request) {
2883
2929
  * 未初始化工作区沿用 `enforce` 语义(`always` 下 fail-closed)。
2884
2930
  * @param {string} resolvedCwd
2885
2931
  * @param {'off'|'project'|'always'} enforce
2886
- * @param {string[]} [phases] 放行的相位(缺省 `['exec_running']`;`git commit` 额外允许 `archiving`)
2932
+ * @param {string[]} [phases] 放行的相位(缺省 `['exec_running']`;`git commit` 额外允许
2933
+ * `review_passed` / `test_passed` / `archiving`)
2887
2934
  * @returns {boolean}
2888
2935
  */
2889
2936
  function allowsWholeTreeWrite(resolvedCwd, enforce, phases = ['exec_running']) {
@@ -3299,6 +3346,15 @@ export function createOpenFeelGuard(options = {}) {
3299
3346
  /** 第 4 类:默认告警放行 + 审计 + stderr 一行;`strict` 下拒绝。 */
3300
3347
  const undecidableShell = (detail, paths) => {
3301
3348
  const reason = 'shell-undecidable';
3349
+ // v1.5.14 / stage-129 OF-05:`OPENFEEL_SHELL_ALLOW` 是**用户显式配置**的整条
3350
+ // 命令白名单,只挂在这一类出口上(第 1/2 类 deny 永不触达)。整条全等才算命中
3351
+ // —— 子串匹配会让 `rm -rf x && npm run build` 被白名单 `npm run build` 顺带放行。
3352
+ // `strict` 下同样放行(这是用户显式声明的例外,不是门禁降级)。
3353
+ if (isShellAllowlisted(command, parseShellAllowlist())) {
3354
+ recordShellAudit({ event: 'guard_shell_allowlisted', decision: 'allow', reason: 'shell-allowlisted', paths });
3355
+ recordDecision('allow', { reason: 'shell-allowlisted', paths });
3356
+ return undefined;
3357
+ }
3302
3358
  if (shellGate.undecidable === 'deny') {
3303
3359
  recordShellAudit({ event: 'guard_deny', decision: 'deny', reason, paths });
3304
3360
  recordDecision('deny', { reason, paths });
@@ -3334,9 +3390,12 @@ export function createOpenFeelGuard(options = {}) {
3334
3390
  if (classification.kind === 'whole-tree') {
3335
3391
  if (!allowsWholeTreeWrite(resolvedCwd, enforce, classification.phases)) {
3336
3392
  // v1.5.12 / stage-127 §3-C(C.5/C.6)+ op-004 复审修正:无 `exec_running` /
3337
- // `archiving` 阶段时,只给「单条、直接、纯 `.openfeel/**` 书账」的
3338
- // `git commit` 开一道窄口。**条件缺一不可**(漏一条即变后门,见 plan R8):
3339
- // ① 无 exec_running/archiving 阶段 —— 上面 `allowsWholeTreeWrite` 已保证;
3393
+ // `review_passed` / `test_passed` / `archiving` 阶段时,只给「单条、直接、纯
3394
+ // `.openfeel/**` 书账」的 `git commit` 开一道窄口。**条件缺一不可**(漏一条即变后门,见 plan R8):
3395
+ // ① 无上述四相位阶段 —— 上面 `allowsWholeTreeWrite` 已保证(v1.5.13 / stage-128
3396
+ // 把 `review_passed` / `test_passed` 并入白名单后,二者不再走这道窄口,窄口只剩
3397
+ // `plan_*` / `scheme_*` / `review_pending` / `review_failed` / `test_pending` /
3398
+ // `test_failed` / `done` 七类);
3340
3399
  // ② 是项目工作区且 flow.json 可读(fail-closed:非项目 / flow 读不出
3341
3400
  // 不等于「无阶段」,不能一律当书账);
3342
3401
  // ③ 单条简单 commit(对**原始命令**判:无多语句/重定向/`$(`/反引号/进程替换);
@@ -3357,10 +3416,41 @@ export function createOpenFeelGuard(options = {}) {
3357
3416
  && flow.ok === true;
3358
3417
  const scope = canBeBookkeeping ? inspectCommitBookkeeping(resolvedCwd, baseDir) : null;
3359
3418
  if (scope !== null && scope.ok === true) return allowShell('git-commit-bookkeeping', []);
3360
- let denyMessage = t(
3361
- `OpenFeel 写入门禁:禁止在没有 exec_running 阶段时用 shell 做 git 工作区写(${classification.detail})—— 它会整树覆盖/丢弃源码或把状态直接写进仓库,等同绕过文件门禁。请先 feel_flow action=advance 推进到 exec_running;只读查询(git status / log / diff)不受影响。`,
3362
- `OpenFeel write guard: git worktree writes via the shell (${classification.detail}) are blocked without an exec_running stage — they overwrite/discard sources across the whole tree or write repo state, bypassing the file gate. Advance to exec_running with feel_flow action=advance; read-only git status / log / diff are unaffected.`,
3363
- );
3419
+ // v1.5.14 / stage-129 OF-04:归档收尾提交(idle commit)。
3420
+ //
3421
+ // 版本归档 / 收口后只剩「done 阶段」或「无阶段」,涉 docs/源码的收尾提交
3422
+ // 原本无处可走(书账窄口只认纯 `.openfeel/**`)。这里开一道**窄于四相位门**
3423
+ // 的通道,条件同样缺一不可(见 plan R1):
3424
+ // ① 与书账窄口同源的命令/项目条件(单条直连 commit、无 -C/-c、可判定、
3425
+ // 项目工作区、flow 可读);
3426
+ // ② **无任何活跃阶段**(`activeStages` 空);
3427
+ // ③ `stages` 是空集 **或** `pipeline.phase === 'done'` —— 「done 阶段但
3428
+ // pipeline 仍在跑」不满足(既有 done 负例夹具正是这种形态,仍拒);
3429
+ // ④ 实际生效仓库根 = 项目工作区(`repoMismatch !== true`)。待提交路径里的
3430
+ // offender **不构成拒绝**:这是收尾提交,本来就要提交 src/docs。
3431
+ const idleEligible = canBeBookkeeping
3432
+ && activeStages(flow.value).length === 0
3433
+ && (
3434
+ Object.keys(flow.value?.stages ?? {}).length === 0
3435
+ || flow.value?.pipeline?.phase === 'done'
3436
+ );
3437
+ if (idleEligible && scope !== null && scope.repoMismatch !== true) {
3438
+ return allowShell('git-commit-idle', []);
3439
+ }
3440
+ // v1.5.13 / stage-128:文案按子命令分叉,相位串从 `classification.phases`
3441
+ // 派生(单一真值,防数组与文案两处漂移)。**必须保留**「git 工作区写」字样
3442
+ // (既有断言 `/git 工作区写/`),非 commit 的通用文案逐字保留(stash/clean/
3443
+ // reset --hard 仍在文案里提示 advance 到 exec_running,不能谎报四相位可用)。
3444
+ const allowedPhaseList = (classification.phases ?? ['exec_running']).join(' / ');
3445
+ let denyMessage = classification.gitSubcommand === 'commit'
3446
+ ? t(
3447
+ `OpenFeel 写入门禁:禁止在当前阶段用 shell 做 git 工作区写(${classification.detail})—— git commit 只允许活跃阶段处于 ${allowedPhaseList} 之一;plan_* / scheme_* / review_pending / review_failed / test_pending / test_failed / done 一律拒绝(done 表示工作已收口,请走归档提交)。只读查询(git status / log / diff)不受影响。`,
3448
+ `OpenFeel write guard: git worktree writes via the shell (${classification.detail}) are blocked in this phase — git commit is only allowed when an active stage is in ${allowedPhaseList}; plan_* / scheme_* / review_pending / review_failed / test_pending / test_failed / done are always refused (done means the work is closed — commit through the archive flow). Read-only git status / log / diff are unaffected.`,
3449
+ )
3450
+ : t(
3451
+ `OpenFeel 写入门禁:禁止在没有 exec_running 阶段时用 shell 做 git 工作区写(${classification.detail})—— 它会整树覆盖/丢弃源码或把状态直接写进仓库,等同绕过文件门禁。请先 feel_flow action=advance 推进到 exec_running;只读查询(git status / log / diff)不受影响。`,
3452
+ `OpenFeel write guard: git worktree writes via the shell (${classification.detail}) are blocked without an exec_running stage — they overwrite/discard sources across the whole tree or write repo state, bypassing the file gate. Advance to exec_running with feel_flow action=advance; read-only git status / log / diff are unaffected.`,
3453
+ );
3364
3454
  if (scope !== null && scope.repoMismatch === true) {
3365
3455
  denyMessage += `\n${t(
3366
3456
  `待提交仓库根(${scope.repoRoot})不是项目工作区(${normalizeTarget(resolvedCwd, '.')}):workdir 指向了另一个仓库(常见于被外层 .gitignore 忽略的嵌套仓库),纯书账只对项目自身的仓库生效。`,
@@ -148,7 +148,7 @@ Feel(你)只做编排、决策与门禁判断。
148
148
 
149
149
  ## 写命令与 preflight(v1.5.5)
150
150
  - **状态写操作只能用 \`feel_*\` 工具**(\`feel_flow\` / \`feel_stage\` / \`feel_req\`);禁止用 shell 跑 \`openfeel flow/stage/req\` 写命令——那会绕过适配器与 preflight。
151
- - **先读后写**:核心写命令(advance / stage add / req add / claim)要求 10 分钟内调用过 \`feel_status\` / \`feel_next\`;遇到 preflight 拒绝先 \`feel_status\` 再重试。
151
+ - **先读后写**:核心写命令(advance / stage add / req add / claim)要求窗口内调用过 \`feel_status\` / \`feel_next\`(缺省 10 分钟;长构建可用 \`OPENFEEL_PREFLIGHT_MAX_AGE_MS\` 显式放宽);遇到 preflight 拒绝先 \`feel_status\` 再重试。适配器会在账本过期时为你真实读一次状态,但**不要**依赖它跳过读状态。
152
152
  - **审查独立**:fast 单轮审查也应由独立 reviewer 完成;Feel 自审必须在 REV 标题标注 \`self-review\`,归档摘要记录原因。
153
153
 
154
154
  ## 需求导向与流程入口(v1.5.7)
@@ -741,7 +741,7 @@ export function createTools(context) {
741
741
  parameters: {
742
742
  action: stringEnum(['list', 'create', 'publish', 'rename', 'remove', 'register', 'attempt', 'retry'], '操作。', { required: true }),
743
743
  stage: string('阶段 ID。除 retry 外必需。'),
744
- op: string('操作 ID(如 op-001,或 attempt/retry 用的完整 ID v1.2.1-stage-93.op-001)。'),
744
+ op: string('操作 ID:完整 ID `<stage>.op-001`,或阶段内短 ID `op-001`(当前阶段优先;歧义/未找到会列候选并报错)。'),
745
745
  title: string('方案标题(create/rename)。'),
746
746
  result: stringEnum(['pass', 'fail'], 'attempt 的执行结果。'),
747
747
  project: string('项目根目录。'),
package/dsh/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openfeel-dsh",
3
- "version": "1.5.12",
3
+ "version": "1.5.14",
4
4
  "description": "OpenFeel × DSH — Feel 模式适配器:把 OpenFeel 的流水线、需求分发、版本归档与知识库接入 DeepSeek Harness",
5
5
  "type": "module",
6
6
  "private": true,
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "openfeel": {
35
35
  "adapter": "dsh",
36
- "requiresCli": ">=1.5.12"
36
+ "requiresCli": ">=1.5.14"
37
37
  },
38
38
  "keywords": [
39
39
  "openfeel",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openfeel",
3
- "version": "1.5.12",
3
+ "version": "1.5.14",
4
4
  "description": "AI Agent 开发流程治理 CLI 工具",
5
5
  "type": "module",
6
6
  "private": false,