openfeel 1.5.9 → 1.5.12

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 (66) hide show
  1. package/README.md +1 -1
  2. package/dist/cli/index.d.ts.map +1 -1
  3. package/dist/cli/index.js +2 -0
  4. package/dist/cli/index.js.map +1 -1
  5. package/dist/commands/chore.d.ts +7 -0
  6. package/dist/commands/chore.d.ts.map +1 -1
  7. package/dist/commands/chore.js +43 -3
  8. package/dist/commands/chore.js.map +1 -1
  9. package/dist/commands/dashboard.d.ts +42 -0
  10. package/dist/commands/dashboard.d.ts.map +1 -0
  11. package/dist/commands/dashboard.js +170 -0
  12. package/dist/commands/dashboard.js.map +1 -0
  13. package/dist/commands/flow.d.ts +8 -0
  14. package/dist/commands/flow.d.ts.map +1 -1
  15. package/dist/commands/flow.js +2 -1
  16. package/dist/commands/flow.js.map +1 -1
  17. package/dist/commands/setup.d.ts.map +1 -1
  18. package/dist/commands/setup.js +10 -0
  19. package/dist/commands/setup.js.map +1 -1
  20. package/dist/commands/shared/json-output.d.ts.map +1 -1
  21. package/dist/commands/shared/json-output.js +1 -0
  22. package/dist/commands/shared/json-output.js.map +1 -1
  23. package/dist/core/dashboard/aggregate.d.ts +146 -0
  24. package/dist/core/dashboard/aggregate.d.ts.map +1 -0
  25. package/dist/core/dashboard/aggregate.js +231 -0
  26. package/dist/core/dashboard/aggregate.js.map +1 -0
  27. package/dist/core/dashboard/render.d.ts +12 -0
  28. package/dist/core/dashboard/render.d.ts.map +1 -0
  29. package/dist/core/dashboard/render.js +506 -0
  30. package/dist/core/dashboard/render.js.map +1 -0
  31. package/dist/core/dsh-profile.d.ts +5 -0
  32. package/dist/core/dsh-profile.d.ts.map +1 -1
  33. package/dist/core/dsh-profile.js +5 -2
  34. package/dist/core/dsh-profile.js.map +1 -1
  35. package/dist/core/i18n-data/en.d.ts +6 -0
  36. package/dist/core/i18n-data/en.d.ts.map +1 -1
  37. package/dist/core/i18n-data/en.js +64 -1
  38. package/dist/core/i18n-data/en.js.map +1 -1
  39. package/dist/core/i18n-data/zh-CN.d.ts +6 -0
  40. package/dist/core/i18n-data/zh-CN.d.ts.map +1 -1
  41. package/dist/core/i18n-data/zh-CN.js +64 -1
  42. package/dist/core/i18n-data/zh-CN.js.map +1 -1
  43. package/dist/core/i18n.js +4 -4
  44. package/dist/core/i18n.js.map +1 -1
  45. package/dist/core/setup.d.ts +10 -0
  46. package/dist/core/setup.d.ts.map +1 -1
  47. package/dist/core/setup.js +11 -1
  48. package/dist/core/setup.js.map +1 -1
  49. package/dist/core/template-loader.d.ts.map +1 -1
  50. package/dist/core/template-loader.js +29 -7
  51. package/dist/core/template-loader.js.map +1 -1
  52. package/dist/core/update.d.ts.map +1 -1
  53. package/dist/core/update.js +29 -7
  54. package/dist/core/update.js.map +1 -1
  55. package/dsh/ADAPTER.md +106 -13
  56. package/dsh/README.md +20 -11
  57. package/dsh/cordis.patch.yml +23 -3
  58. package/dsh/lib/adapters/guard-state.js +722 -0
  59. package/dsh/lib/adapters/session-cwd-registry.js +82 -0
  60. package/dsh/lib/adapters/workflow-gate.js +101 -2
  61. package/dsh/lib/adapters/workspace.js +4 -2
  62. package/dsh/lib/guard.js +3147 -206
  63. package/dsh/lib/index.js +56 -4
  64. package/dsh/lib/tools/index.js +126 -9
  65. package/dsh/package.json +2 -2
  66. package/package.json +1 -1
@@ -0,0 +1,82 @@
1
+ /**
2
+ * 会话 → 工作区 cwd 登记表(v1.5.11 D-126-01 / P1-4)
3
+ *
4
+ * 目的:给写入门禁的 cwd 解析链补上第 3 环。**只按 `sessionId` 存**,
5
+ * 不存任何「进程级最近一次 cwd」(`registry-last`):后者在多窗口/多项目时
6
+ * 会跨项目串味——窗口 A 在 P1(`exec_running`)登记过,窗口 B 在 P2
7
+ * (`review_pending`)拿不到 cwd 时就会用 P1 的 cwd 去判 B 的写入,
8
+ * 等于「按别的项目放行」,比静默放行更危险(plan §D-126-01 P1-4)。
9
+ *
10
+ * 纪律:
11
+ * - 纯内存、零依赖、全 try/catch —— 登记失败绝不影响工具/提示主流程;
12
+ * - 上限 64,LRU 淘汰(`get` 也算一次使用);
13
+ * - 只有 `sessionId` 与 `cwd` 都非空才写入(写入点不产生误记)。
14
+ *
15
+ * @module openfeel-dsh/session-cwd-registry
16
+ */
17
+
18
+ /** 登记上限(LRU)。 */
19
+ export const CWD_REGISTRY_LIMIT = 64;
20
+
21
+ /** @type {Map<string, { cwd: string, at: number }>} */
22
+ const registry = new Map();
23
+
24
+ /**
25
+ * 登记 / 刷新某会话的工作区。
26
+ * @param {unknown} sessionId
27
+ * @param {unknown} cwd
28
+ * @returns {void}
29
+ */
30
+ export function touchSession(sessionId, cwd) {
31
+ try {
32
+ if (typeof sessionId !== 'string' || sessionId.trim() === '') return;
33
+ if (typeof cwd !== 'string' || cwd.trim() === '') return;
34
+ const key = sessionId.trim();
35
+ // 重新插入以刷新 LRU 顺序
36
+ registry.delete(key);
37
+ registry.set(key, { cwd: cwd.trim(), at: Date.now() });
38
+ while (registry.size > CWD_REGISTRY_LIMIT) {
39
+ const oldest = registry.keys().next().value;
40
+ if (oldest === undefined) break;
41
+ registry.delete(oldest);
42
+ }
43
+ } catch {
44
+ /* 登记是观测手段,失败不影响主流程 */
45
+ }
46
+ }
47
+
48
+ /**
49
+ * 读取某会话登记的工作区(命中即刷新 LRU 顺序)。
50
+ * @param {unknown} sessionId
51
+ * @returns {string | null}
52
+ */
53
+ export function getSessionCwd(sessionId) {
54
+ try {
55
+ if (typeof sessionId !== 'string' || sessionId.trim() === '') return null;
56
+ const key = sessionId.trim();
57
+ const entry = registry.get(key);
58
+ if (entry === undefined) return null;
59
+ registry.delete(key);
60
+ registry.set(key, entry);
61
+ return entry.cwd;
62
+ } catch {
63
+ return null;
64
+ }
65
+ }
66
+
67
+ /**
68
+ * 当前登记的会话数(测试/诊断用)。
69
+ * @returns {number}
70
+ */
71
+ export function cwdRegistrySize() {
72
+ return registry.size;
73
+ }
74
+
75
+ /** 清空登记表(测试用)。 */
76
+ export function resetCwdRegistry() {
77
+ registry.clear();
78
+ }
79
+
80
+ /* 与 plan §3.3 的命名对齐(两种名字同义,避免各调用点各写一套)。 */
81
+ export const recordSessionCwd = touchSession;
82
+ export const lookupSessionCwd = getSessionCwd;
@@ -1,10 +1,13 @@
1
1
  /**
2
- * 流程入口闸(v1.5.2;v1.5.7 改为需求导向语义)
2
+ * 流程入口闸(v1.5.2;v1.5.7 需求导向;v1.5.11 增加门禁自检)
3
3
  *
4
4
  * 目的:把「每个需求都要建/推进阶段」纠正为「阶段是版本容器、长期保持开启」。
5
- * 无开启阶段时提示按当前小版本开一个(保持 exec_running),而不是把它当成一次性任务;
6
5
  * 已开启阶段时不做任何催促(需求在阶段内完成,阶段关闭由用户在发布节点决定)。
7
6
  *
7
+ * v1.5.11(D-126-04):若 `snapshot.guard` 显示门禁**自身**不可信
8
+ * (未注册 / cwd 解析失败 / 来自旧进程或旧适配器),优先提示它 —— 「门禁看着在跑
9
+ * 其实没生效」比「没开阶段」严重得多。**无 `guard` 字段时行为完全不变**(零回归)。
10
+ *
8
11
  * 纯函数、无 IO;由工具层在读取快照后调用。
9
12
  */
10
13
 
@@ -13,6 +16,53 @@
13
16
  * @returns {{ required: boolean, reason: string|null, message: string, actions: string[] }}
14
17
  */
15
18
  export function computeWorkflowGate(snapshot) {
19
+ const guard = snapshot?.guard;
20
+ if (guard !== null && guard !== undefined && typeof guard === 'object') {
21
+ if (guard.registered === false) {
22
+ return {
23
+ required: true,
24
+ reason: 'guard-inactive',
25
+ message:
26
+ '写入门禁未生效(guard-state 缺失或 guard 未注册,例如 profile 的 enforce=off 或宿主未加载适配器):'
27
+ + '当前对源码/文档的写入没有门禁保护。请重启宿主让适配器重新注册,或确认 enforce 不是 off。',
28
+ actions: [
29
+ '确认 profile(cordis.patch.yml)的 openfeel-feel.enforce 为 project 或 always',
30
+ '重启 DSH 宿主(guard 只在宿主启动时注册)',
31
+ 'feel_status 的 guard 段应显示 registered:true;否则看 .openfeel/dev/guard-state.json 与 ~/.openfeel/adapter-host-dsh.json',
32
+ ],
33
+ };
34
+ }
35
+ if (guard.cwd === null || guard.cwdSource === 'unresolved') {
36
+ return {
37
+ required: true,
38
+ reason: 'guard-cwd-unresolved',
39
+ message:
40
+ '写入门禁无法确定会话工作区(cwd 解析失败),已按 fail-closed 拒绝写入。'
41
+ + '修复(任一):① profile 的 cordis.patch.yml 给 openfeel-feel 配 cwd: "<项目绝对路径>";'
42
+ + '② 设环境变量 OPENFEEL_GUARD_CWD 后重启;③ 重启会话让提示装配登记 cwd。',
43
+ actions: [
44
+ 'cordis.patch.yml 配 cwd: "<项目绝对路径>" 后重启',
45
+ '或设 OPENFEEL_GUARD_CWD=<项目绝对路径> 后重启',
46
+ '重启会话让提示装配写入会话 cwd 登记表',
47
+ ],
48
+ };
49
+ }
50
+ if (guard.stale === true) {
51
+ return {
52
+ required: true,
53
+ reason: 'guard-stale',
54
+ message:
55
+ '门禁来自旧进程/旧适配器,判定不可信(适配器文件已更新但宿主仍加载旧模块,或状态来自更早的进程)。'
56
+ + '请完全重启 DSH 宿主后再写入。',
57
+ actions: [
58
+ '完全重启 DSH 宿主(不是重载会话)',
59
+ '重启后确认 feel_status.guard.stale === false',
60
+ '确认 ~/.openfeel/adapter-host-dsh.json 的 loaded_hash 与 .openfeel/dev/guard-state.json 一致',
61
+ ],
62
+ };
63
+ }
64
+ }
65
+
16
66
  const phase = snapshot?.focus?.phase;
17
67
  // v1.5.8:『开启阶段』= phase 非空且非 done。仅剩 done 阶段时同样要求开新阶段
18
68
  // (此前 done 被当成活跃阶段,导致需求导向下永远不提示开阶段)。
@@ -33,3 +83,52 @@ export function computeWorkflowGate(snapshot) {
33
83
  ],
34
84
  };
35
85
  }
86
+
87
+ /**
88
+ * 门禁标题(**单句、不带 `⚠ ` 前缀**)——`feel_status` / `feel_next` 两处共用,避免再次分叉。
89
+ *
90
+ * v1.5.12 / stage-127 §3-E:旧实现两个工具各自硬编码「⚠ 无活跃阶段:非只读任务先
91
+ * feel_status→建阶段。」,于是 `guard-stale` / `guard-inactive` / `guard-cwd-unresolved`
92
+ * 时标题与真实原因矛盾(门禁自身没生效,却在催建阶段)。
93
+ *
94
+ * 口径:
95
+ * - `no-active-stage` → 保留既有短句(仅此一条 reason 才允许出现「无活跃阶段」);
96
+ * - `guard-*` 三条 → **逐字使用 `gate.message`**(门禁原因文案;同一原因只说一次,
97
+ * 与 `guardWarnings` 的 `skipGateCovered` 配合,不重复堆两句);
98
+ * - 其它/未知 reason → 回落 `gate.message`;无 message 时空串(调用方据此不加标题)。
99
+ *
100
+ * @param {{ reason?: string|null, message?: string } | null | undefined} gate
101
+ * @returns {string}
102
+ */
103
+ export function workflowGateTitle(gate) {
104
+ if (gate === null || gate === undefined || typeof gate !== 'object') return '';
105
+ switch (gate.reason) {
106
+ case 'no-active-stage':
107
+ // 唯一允许出现「无活跃阶段」的 reason
108
+ return '无活跃阶段:非只读任务先 feel_status→建阶段。';
109
+ case 'guard-inactive':
110
+ case 'guard-cwd-unresolved':
111
+ case 'guard-stale':
112
+ // 与 gate.message 逐字一致:原因 + 修复动作全部取自单源,不在标题里另写一套
113
+ break;
114
+ default:
115
+ break;
116
+ }
117
+ return typeof gate.message === 'string' ? gate.message : '';
118
+ }
119
+
120
+ /**
121
+ * 一句话门禁告警(`⚠ ` 开头的完整标题;无告警时返回空串)。
122
+ *
123
+ * 两处调用点只做「拼到 summary 前面」,选择文案的逻辑只在 `workflowGateTitle` 一处。
124
+ *
125
+ * @param {{ workflowGate?: { required?: boolean, reason?: string|null, message?: string } } | null | undefined} snapshot
126
+ * @returns {string}
127
+ */
128
+ export function headlineWarning(snapshot) {
129
+ const gate = snapshot?.workflowGate;
130
+ if (gate === null || gate === undefined || typeof gate !== 'object' || gate.required !== true) return '';
131
+ const title = workflowGateTitle(gate);
132
+ if (title === '') return '';
133
+ return `⚠ ${title}`;
134
+ }
@@ -34,10 +34,12 @@ export const OPENFEEL_DIR = '.openfeel';
34
34
  *
35
35
  * - `flow.json`:`openfeel init` 必然创建,是核心数据存储。
36
36
  * - `config.yaml`:同为 `init` 产物(`flow.json` 被手工删除时的兜底判据)。
37
+ * - `stages` / `metrics.json`:op-005 / P2 —— `flow.json` 被删/搬走时,
38
+ * 仍有其它 init 产物可自证「这是 OpenFeel 项目」,避免误落 fail-closed 全拒。
37
39
  *
38
- * 全局家目录 `~/.openfeel/` 两者皆无,因此不会被误判。
40
+ * 全局家目录 `~/.openfeel/` 这些都没有,因此不会被误判。
39
41
  */
40
- export const PROJECT_MARKERS = /** @type {const} */ (['flow.json', 'config.yaml']);
42
+ export const PROJECT_MARKERS = /** @type {const} */ (['flow.json', 'config.yaml', 'stages', 'metrics.json']);
41
43
 
42
44
  /**
43
45
  * 从工具执行上下文解析会话工作区目录。