@wooojin/forgen 0.6.8 → 0.6.10

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 (221) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +27 -0
  3. package/README.ja.md +15 -10
  4. package/README.ko.md +15 -10
  5. package/README.md +19 -14
  6. package/README.zh.md +13 -8
  7. package/dist/checks/dangerous-response-pattern.d.ts +2 -1
  8. package/dist/checks/dangerous-response-pattern.js +27 -3
  9. package/dist/cli.js +133 -17
  10. package/dist/core/auto-compound-runner.js +502 -397
  11. package/dist/core/block-cli.js +7 -3
  12. package/dist/core/compound-consent.d.ts +18 -0
  13. package/dist/core/compound-consent.js +101 -6
  14. package/dist/core/compound-sweep-cli.d.ts +16 -0
  15. package/dist/core/compound-sweep-cli.js +67 -5
  16. package/dist/core/config-hooks.js +28 -10
  17. package/dist/core/correction-signals.d.ts +9 -0
  18. package/dist/core/correction-signals.js +37 -0
  19. package/dist/core/dev-cli.d.ts +1 -2
  20. package/dist/core/dev-cli.js +9 -28
  21. package/dist/core/doctor-verify.d.ts +35 -0
  22. package/dist/core/doctor-verify.js +502 -0
  23. package/dist/core/doctor.d.ts +4 -6
  24. package/dist/core/doctor.js +103 -184
  25. package/dist/core/explain-cli.js +8 -0
  26. package/dist/core/extraction-haiku.d.ts +64 -0
  27. package/dist/core/extraction-haiku.js +208 -0
  28. package/dist/core/extraction-queue.d.ts +68 -0
  29. package/dist/core/extraction-queue.js +300 -0
  30. package/dist/core/flow-status.d.ts +93 -0
  31. package/dist/core/flow-status.js +368 -0
  32. package/dist/core/harness.js +14 -42
  33. package/dist/core/inspect-cli.js +37 -13
  34. package/dist/core/lifecycle-classifier.d.ts +5 -1
  35. package/dist/core/lifecycle-classifier.js +13 -2
  36. package/dist/core/migrate-cli.d.ts +1 -1
  37. package/dist/core/migrate-cli.js +11 -11
  38. package/dist/core/migrate-tenetx.d.ts +1 -1
  39. package/dist/core/migrate-tenetx.js +2 -2
  40. package/dist/core/node-engine.d.ts +3 -0
  41. package/dist/core/node-engine.js +8 -0
  42. package/dist/core/observability-store.d.ts +15 -0
  43. package/dist/core/observability-store.js +73 -0
  44. package/dist/core/paths.d.ts +2 -0
  45. package/dist/core/paths.js +2 -0
  46. package/dist/core/rendered-rules-manifest.d.ts +7 -1
  47. package/dist/core/rendered-rules-manifest.js +45 -1
  48. package/dist/core/session-store.d.ts +13 -11
  49. package/dist/core/session-store.js +103 -119
  50. package/dist/core/settings-injector.d.ts +5 -2
  51. package/dist/core/settings-injector.js +21 -88
  52. package/dist/core/spawn.d.ts +9 -1
  53. package/dist/core/spawn.js +33 -33
  54. package/dist/core/stats-cli.d.ts +7 -0
  55. package/dist/core/stats-cli.js +66 -93
  56. package/dist/core/status-cli.d.ts +1 -1
  57. package/dist/core/status-cli.js +23 -4
  58. package/dist/core/statusline-cli.js +5 -0
  59. package/dist/core/statusline-install.d.ts +10 -2
  60. package/dist/core/statusline-install.js +27 -4
  61. package/dist/core/transcript-summary.d.ts +84 -9
  62. package/dist/core/transcript-summary.js +283 -49
  63. package/dist/core/uninstall.d.ts +4 -0
  64. package/dist/core/uninstall.js +68 -36
  65. package/dist/core/v1-bootstrap.d.ts +1 -1
  66. package/dist/core/v1-bootstrap.js +38 -9
  67. package/dist/engine/acted-on-evidence.d.ts +8 -0
  68. package/dist/engine/acted-on-evidence.js +38 -0
  69. package/dist/engine/block-judge.d.ts +3 -1
  70. package/dist/engine/block-judge.js +4 -3
  71. package/dist/engine/compound-cli.d.ts +26 -2
  72. package/dist/engine/compound-cli.js +143 -19
  73. package/dist/engine/compound-lifecycle.d.ts +36 -2
  74. package/dist/engine/compound-lifecycle.js +131 -11
  75. package/dist/engine/compound-loop.d.ts +4 -0
  76. package/dist/engine/compound-loop.js +93 -18
  77. package/dist/engine/correction-cluster-runner.d.ts +11 -1
  78. package/dist/engine/correction-cluster-runner.js +39 -15
  79. package/dist/engine/correction-clustering.d.ts +11 -0
  80. package/dist/engine/correction-clustering.js +20 -3
  81. package/dist/engine/lifecycle/lifecycle-cli.js +10 -3
  82. package/dist/engine/lifecycle/meta-reclassifier.d.ts +9 -0
  83. package/dist/engine/lifecycle/meta-reclassifier.js +15 -3
  84. package/dist/engine/lifecycle/orchestrator.js +3 -2
  85. package/dist/engine/lifecycle/signals.d.ts +19 -1
  86. package/dist/engine/lifecycle/signals.js +61 -2
  87. package/dist/engine/lifecycle/trigger-t1-correction.d.ts +1 -1
  88. package/dist/engine/lifecycle/trigger-t1-correction.js +9 -28
  89. package/dist/engine/lifecycle/trigger-t5-conflict.d.ts +8 -0
  90. package/dist/engine/lifecycle/trigger-t5-conflict.js +60 -2
  91. package/dist/engine/roi-demotion.d.ts +11 -0
  92. package/dist/engine/roi-demotion.js +50 -8
  93. package/dist/engine/rule-detectability.d.ts +39 -0
  94. package/dist/engine/rule-detectability.js +66 -0
  95. package/dist/engine/rule-project-cli.d.ts +25 -0
  96. package/dist/engine/rule-project-cli.js +148 -0
  97. package/dist/engine/rule-recovery-cli.d.ts +21 -0
  98. package/dist/engine/rule-recovery-cli.js +265 -0
  99. package/dist/engine/rule-toggle-cli.d.ts +14 -2
  100. package/dist/engine/rule-toggle-cli.js +94 -6
  101. package/dist/engine/skill-promoter.d.ts +14 -8
  102. package/dist/engine/skill-promoter.js +57 -85
  103. package/dist/engine/solution-format.d.ts +26 -1
  104. package/dist/engine/solution-format.js +65 -3
  105. package/dist/engine/solution-habit.d.ts +1 -0
  106. package/dist/engine/solution-habit.js +22 -0
  107. package/dist/engine/solution-index.d.ts +5 -0
  108. package/dist/engine/solution-index.js +32 -0
  109. package/dist/engine/solution-matcher-eval.js +4 -4
  110. package/dist/engine/solution-matcher.js +15 -13
  111. package/dist/engine/solution-scope.d.ts +11 -0
  112. package/dist/engine/solution-scope.js +19 -0
  113. package/dist/engine/solution-writer.d.ts +3 -1
  114. package/dist/engine/solution-writer.js +3 -2
  115. package/dist/engine/term-normalizer.js +49 -0
  116. package/dist/fgx.js +1 -1
  117. package/dist/forge/cli.js +51 -8
  118. package/dist/forge/evidence-processor.js +6 -0
  119. package/dist/hooks/context-guard.d.ts +0 -22
  120. package/dist/hooks/context-guard.js +22 -55
  121. package/dist/hooks/context-usage.d.ts +21 -0
  122. package/dist/hooks/context-usage.js +103 -0
  123. package/dist/hooks/dangerous-patterns.json +1 -16
  124. package/dist/hooks/db-guard.d.ts +1 -1
  125. package/dist/hooks/db-guard.js +21 -30
  126. package/dist/hooks/hook-config.d.ts +2 -0
  127. package/dist/hooks/hook-config.js +5 -1
  128. package/dist/hooks/hooks-generator.d.ts +4 -0
  129. package/dist/hooks/hooks-generator.js +10 -4
  130. package/dist/hooks/permission-handler.js +23 -3
  131. package/dist/hooks/post-tool-use.js +14 -10
  132. package/dist/hooks/pre-tool-use.d.ts +17 -3
  133. package/dist/hooks/pre-tool-use.js +145 -30
  134. package/dist/hooks/rate-limiter.js +12 -7
  135. package/dist/hooks/secret-filter.js +15 -4
  136. package/dist/hooks/session-end.d.ts +2 -2
  137. package/dist/hooks/session-end.js +13 -7
  138. package/dist/hooks/session-recovery.js +79 -50
  139. package/dist/hooks/shared/command-analyzer.d.ts +45 -0
  140. package/dist/hooks/shared/command-analyzer.js +972 -0
  141. package/dist/hooks/shared/command-parser.d.ts +5 -29
  142. package/dist/hooks/shared/command-parser.js +65 -35
  143. package/dist/hooks/shared/commit-guard.d.ts +15 -0
  144. package/dist/hooks/shared/commit-guard.js +177 -0
  145. package/dist/hooks/shared/hook-response.d.ts +12 -2
  146. package/dist/hooks/shared/hook-response.js +19 -3
  147. package/dist/hooks/shared/hook-timing.js +9 -3
  148. package/dist/hooks/shared/injection-caps.d.ts +32 -2
  149. package/dist/hooks/shared/injection-caps.js +73 -2
  150. package/dist/hooks/shared/is-main.d.ts +8 -0
  151. package/dist/hooks/shared/is-main.js +20 -0
  152. package/dist/hooks/shared/tool-response.d.ts +6 -0
  153. package/dist/hooks/shared/tool-response.js +30 -0
  154. package/dist/hooks/slop-detector.js +6 -3
  155. package/dist/hooks/solution-injector.d.ts +23 -0
  156. package/dist/hooks/solution-injector.js +102 -101
  157. package/dist/hooks/stop-guard.d.ts +11 -1
  158. package/dist/hooks/stop-guard.js +28 -11
  159. package/dist/hooks/subagent-stop-guard.js +2 -1
  160. package/dist/hooks/subagent-tracker.js +2 -1
  161. package/dist/host/capabilities-codex.js +1 -0
  162. package/dist/host/claude-shim.d.ts +24 -0
  163. package/dist/host/claude-shim.js +68 -0
  164. package/dist/host/codex-hook-shim.d.ts +3 -1
  165. package/dist/host/codex-hook-shim.js +7 -5
  166. package/dist/host/codex-notify.js +1 -1
  167. package/dist/host/codex-rules-context.d.ts +6 -4
  168. package/dist/host/codex-rules-context.js +11 -24
  169. package/dist/host/exec-host.d.ts +5 -1
  170. package/dist/host/exec-host.js +15 -4
  171. package/dist/host/install-claude.d.ts +47 -14
  172. package/dist/host/install-claude.js +302 -155
  173. package/dist/host/install-codex.d.ts +20 -0
  174. package/dist/host/install-codex.js +32 -1
  175. package/dist/host/install-opencode.d.ts +3 -1
  176. package/dist/host/install-opencode.js +6 -3
  177. package/dist/host/install-orchestrator.js +14 -1
  178. package/dist/host/opencode/translate.d.ts +1 -1
  179. package/dist/host/opencode/translate.js +5 -3
  180. package/dist/host/projection.d.ts +9 -1
  181. package/dist/host/projection.js +19 -2
  182. package/dist/mcp/server.js +5 -0
  183. package/dist/mcp/solution-reader.d.ts +5 -5
  184. package/dist/mcp/solution-reader.js +13 -35
  185. package/dist/mcp/tools.js +18 -1
  186. package/dist/renderer/inspect-renderer.js +4 -2
  187. package/dist/renderer/render-report.d.ts +22 -0
  188. package/dist/renderer/render-report.js +29 -0
  189. package/dist/renderer/rule-renderer.d.ts +28 -2
  190. package/dist/renderer/rule-renderer.js +91 -76
  191. package/dist/store/evidence-store.js +34 -6
  192. package/dist/store/rule-lifecycle.d.ts +3 -1
  193. package/dist/store/rule-lifecycle.js +10 -0
  194. package/dist/store/rule-scope.d.ts +7 -0
  195. package/dist/store/rule-scope.js +54 -0
  196. package/dist/store/rule-store.d.ts +29 -3
  197. package/dist/store/rule-store.js +110 -26
  198. package/dist/store/types.d.ts +22 -2
  199. package/dist/way/cli.d.ts +1 -0
  200. package/dist/way/cli.js +313 -0
  201. package/dist/way/compile.d.ts +22 -0
  202. package/dist/way/compile.js +408 -0
  203. package/dist/way/conflict.d.ts +2 -0
  204. package/dist/way/conflict.js +18 -0
  205. package/dist/way/draft.d.ts +43 -0
  206. package/dist/way/draft.js +335 -0
  207. package/dist/way/extract.d.ts +17 -0
  208. package/dist/way/extract.js +172 -0
  209. package/dist/way/io.d.ts +79 -0
  210. package/dist/way/io.js +425 -0
  211. package/dist/way/similar.d.ts +2 -0
  212. package/dist/way/similar.js +30 -0
  213. package/dist/way/types.d.ts +98 -0
  214. package/dist/way/types.js +2 -0
  215. package/package.json +1 -1
  216. package/plugin.json +1 -1
  217. package/scripts/postinstall.js +76 -899
  218. package/dist/core/health-cli.d.ts +0 -25
  219. package/dist/core/health-cli.js +0 -90
  220. package/dist/host/parity-harness.d.ts +0 -70
  221. package/dist/host/parity-harness.js +0 -287
@@ -1,25 +0,0 @@
1
- /**
2
- * forgen health — single-line health score (0-100).
3
- *
4
- * Combines:
5
- * - Solution utilization (7d match rate) 30%
6
- * - Block→ack effectiveness 25%
7
- * - Knowledge growth (extractions this week) 20%
8
- * - Rule coverage (active rules) 15%
9
- * - Profile completeness 10%
10
- */
11
- export interface HealthScore {
12
- total: number;
13
- components: {
14
- utilization: number;
15
- effectiveness: number;
16
- growth: number;
17
- coverage: number;
18
- profile: number;
19
- };
20
- grade: 'A' | 'B' | 'C' | 'D' | 'F';
21
- }
22
- export declare function computeHealth(): HealthScore;
23
- /** 한 줄 health 요약 — `forgen status` 요약 헤더에서 재사용. */
24
- export declare function renderHealthLine(h: HealthScore): string;
25
- export declare function handleHealth(): Promise<void>;
@@ -1,90 +0,0 @@
1
- /**
2
- * forgen health — single-line health score (0-100).
3
- *
4
- * Combines:
5
- * - Solution utilization (7d match rate) 30%
6
- * - Block→ack effectiveness 25%
7
- * - Knowledge growth (extractions this week) 20%
8
- * - Rule coverage (active rules) 15%
9
- * - Profile completeness 10%
10
- */
11
- import { computeStats } from './stats-cli.js';
12
- const isTTY = process.stdout.isTTY;
13
- const C = {
14
- reset: isTTY ? '\x1b[0m' : '',
15
- bold: isTTY ? '\x1b[1m' : '',
16
- dim: isTTY ? '\x1b[2m' : '',
17
- green: isTTY ? '\x1b[32m' : '',
18
- yellow: isTTY ? '\x1b[33m' : '',
19
- red: isTTY ? '\x1b[31m' : '',
20
- cyan: isTTY ? '\x1b[36m' : '',
21
- };
22
- export function computeHealth() {
23
- const s = computeStats();
24
- // 1. Utilization (30%): % of solutions matched in last 7d, capped at 100%
25
- const utilization = Math.min(1, s.solutionHealth.utilization7d) * 30;
26
- // 2. Effectiveness (25%): if blocks happened, what % were acknowledged
27
- let effectiveness;
28
- if (s.blocks7d === 0) {
29
- effectiveness = 25; // no blocks = no problems
30
- }
31
- else {
32
- effectiveness = (s.acks7d / s.blocks7d) * 25;
33
- }
34
- // 3. Growth (20%): extractions this week (1 extraction = 10pts, cap at 20)
35
- const growth = Math.min(20, s.weeklyTrend.extractionsThisWeek * 10);
36
- // 4. Coverage (15%): active rules (1 rule = 3pts, cap at 15)
37
- const coverage = Math.min(15, s.activeRules * 3);
38
- // 5. Profile (10%): has profile + has philosophy + axis scores populated
39
- let profile = 0;
40
- if (s.philosophy) {
41
- profile += 4; // profile exists
42
- if (s.philosophy.basePacks.length > 0)
43
- profile += 3;
44
- if (Object.keys(s.philosophy.axisScores).length >= 4)
45
- profile += 3;
46
- }
47
- // 총점은 *표시되는* 항목 점수의 합이어야 한다. 이전엔 합을 반올림(round(Σ))하고 항목은 따로 반올림해서
48
- // 실 상태에 따라 "항목 합 60 ≠ 총점 61" 이 나왔다 (tests/health-cli 가 머신 상태에 따라 간헐 실패).
49
- const components = {
50
- utilization: Math.round(utilization),
51
- effectiveness: Math.round(effectiveness),
52
- growth: Math.round(growth),
53
- coverage: Math.round(coverage),
54
- profile: Math.round(profile),
55
- };
56
- const total = components.utilization + components.effectiveness + components.growth + components.coverage + components.profile;
57
- const grade = total >= 80 ? 'A' : total >= 60 ? 'B' : total >= 40 ? 'C' : total >= 20 ? 'D' : 'F';
58
- return { total, components, grade };
59
- }
60
- function gradeColor(grade) {
61
- if (grade === 'A')
62
- return C.green;
63
- if (grade === 'B')
64
- return C.cyan;
65
- if (grade === 'C')
66
- return C.yellow;
67
- return C.red;
68
- }
69
- function bar(value, max, width = 10) {
70
- const filled = Math.round((value / max) * width);
71
- return '█'.repeat(Math.max(0, filled)) + '░'.repeat(Math.max(0, width - filled));
72
- }
73
- /** 한 줄 health 요약 — `forgen status` 요약 헤더에서 재사용. */
74
- export function renderHealthLine(h) {
75
- const gc = gradeColor(h.grade);
76
- return `\n ${C.bold}forgen status${C.reset} ${gc}${C.bold}${h.grade}${C.reset} ${gc}${h.total}/100${C.reset}`;
77
- }
78
- export async function handleHealth() {
79
- const h = computeHealth();
80
- const gc = gradeColor(h.grade);
81
- console.log('');
82
- console.log(` ${C.bold}forgen status${C.reset} ${gc}${C.bold}${h.grade}${C.reset} ${gc}${h.total}/100${C.reset}`);
83
- console.log('');
84
- console.log(` Utilization ${bar(h.components.utilization, 30)} ${h.components.utilization}/30 ${C.dim}solution match rate (7d)${C.reset}`);
85
- console.log(` Effectiveness ${bar(h.components.effectiveness, 25)} ${h.components.effectiveness}/25 ${C.dim}block→ack ratio${C.reset}`);
86
- console.log(` Growth ${bar(h.components.growth, 20)} ${h.components.growth}/20 ${C.dim}extractions this week${C.reset}`);
87
- console.log(` Coverage ${bar(h.components.coverage, 15)} ${h.components.coverage}/15 ${C.dim}active rules${C.reset}`);
88
- console.log(` Profile ${bar(h.components.profile, 10)} ${h.components.profile}/10 ${C.dim}personalization depth${C.reset}`);
89
- console.log('');
90
- }
@@ -1,70 +0,0 @@
1
- /**
2
- * BehavioralParityScenario harness — Multi-Host Core Design §10 우선순위 4
3
- *
4
- * "Claude 와 Codex 양쪽에서 같은 입력을 흘려보냈을 때 evidence 가 의미적으로 같다" 를
5
- * 검증하는 골격. P4 단계에서는 *projection 사영 후 등가성* 만 검증한다 — 실 모델 호출은
6
- * P6 (실 Codex CLI) 트랙.
7
- *
8
- * 본 harness 가 verify 하는 것:
9
- * 1. 같은 forgen hook 입력에 대해 양쪽 host 의 raw 출력을 사영하면 의미 동치한 객체가 된다.
10
- * 2. 사영 결과가 1원칙 (Claude reference) 의 행동 의도와 일치한다.
11
- *
12
- * verify 하지 않는 것 (P6 별도 트랙):
13
- * - 실제 Codex 모델이 같은 prompt 에 같은 행동을 보이는지
14
- * - 실제 Claude 모델과의 동작 동등성
15
- */
16
- import type { HookEventInput, HookEventOutput } from '../core/types.js';
17
- import type { HostId, TrustLayerIntent } from '../core/trust-layer-intent.js';
18
- /**
19
- * Parity 는 *subprocess-hook* 형태 호스트(Claude/Codex) 간 projection 등가성만 검증한다.
20
- * OpenCode(P1)는 in-process plugin 형태라 projection 이 아직 미구현(fail-loud 스텁)이므로
21
- * parity corpus 범위에서 **명시적으로 제외** — 플러그인 슬림 착지 후 별도 parity 바인딩으로
22
- * 편입한다(plan §4.3). 여기에 opencode 를 넣어 가짜 등가 주장을 만들지 않는다.
23
- */
24
- type ParityHost = Extract<HostId, 'claude' | 'codex'>;
25
- export interface BehavioralParityScenario {
26
- readonly id: string;
27
- /** 검증하려는 Trust Layer 의도. */
28
- readonly intent: TrustLayerIntent;
29
- readonly description: string;
30
- /** hook 입력 (HookEventInput 동치). */
31
- readonly input: HookEventInput;
32
- /**
33
- * 각 host 가 *내보낼 것으로 가정* 하는 raw 출력. P4 단계에서는 spec §18 source schema
34
- * 기반 직접 작성. P6 단계에서는 실 Codex CLI 출력으로 대체.
35
- */
36
- readonly hostRaw: Record<ParityHost, unknown>;
37
- /**
38
- * 사영 후 의미 동치성을 검증할 키들.
39
- * 예: ['continue', 'hookSpecificOutput.permissionDecision'].
40
- * 각 key 는 . 으로 nested path 표현.
41
- */
42
- readonly compareKeys: ReadonlyArray<string>;
43
- }
44
- export interface ParityCheckResult {
45
- readonly scenarioId: string;
46
- readonly intent: TrustLayerIntent;
47
- readonly passed: boolean;
48
- readonly diffs: ReadonlyArray<{
49
- key: string;
50
- claude: unknown;
51
- codex: unknown;
52
- }>;
53
- /** 사영 결과 자체 (디버깅용). */
54
- readonly projected: Readonly<Record<ParityHost, HookEventOutput>>;
55
- }
56
- export declare function runScenario(scenario: BehavioralParityScenario): ParityCheckResult;
57
- /**
58
- * P4 1차 시나리오 corpus — Trust Layer 7 의도 중 hook 출력으로 직접 관측 가능한 5종.
59
- * (`forge-loop-state-inject` 는 inject-context 의 특수 케이스, `self-evidence-record` 는
60
- * 파일 시스템 사이드이펙트라 본 corpus 가 아닌 별도 e2e 트랙.)
61
- *
62
- * P4 2차 추가 시나리오 (spec §10 우선순위 4 산출물, 2026-04-27):
63
- * - forge-loop-m1-inject-stale : §17.1 fact 1 / M1 hook 1KB cap + stale tag
64
- * - block-tool-use-pretool-ask : §9.0 block-tool-use row — Codex ask 값 동치
65
- * - stop-hook-reentry-guard : §15 stop_hook_active=true 즉시 approve 경로
66
- * - posttooluse-general-block-only : §9.0 secret-filter row partial — block decision 만 등가
67
- * - suppress-output-equivalence : suppressOutput 동치성
68
- */
69
- export declare const SCENARIO_CORPUS: ReadonlyArray<BehavioralParityScenario>;
70
- export {};
@@ -1,287 +0,0 @@
1
- /**
2
- * BehavioralParityScenario harness — Multi-Host Core Design §10 우선순위 4
3
- *
4
- * "Claude 와 Codex 양쪽에서 같은 입력을 흘려보냈을 때 evidence 가 의미적으로 같다" 를
5
- * 검증하는 골격. P4 단계에서는 *projection 사영 후 등가성* 만 검증한다 — 실 모델 호출은
6
- * P6 (실 Codex CLI) 트랙.
7
- *
8
- * 본 harness 가 verify 하는 것:
9
- * 1. 같은 forgen hook 입력에 대해 양쪽 host 의 raw 출력을 사영하면 의미 동치한 객체가 된다.
10
- * 2. 사영 결과가 1원칙 (Claude reference) 의 행동 의도와 일치한다.
11
- *
12
- * verify 하지 않는 것 (P6 별도 트랙):
13
- * - 실제 Codex 모델이 같은 prompt 에 같은 행동을 보이는지
14
- * - 실제 Claude 모델과의 동작 동등성
15
- */
16
- import { equal as deepEqual } from 'node:assert/strict';
17
- import { getProjection } from './projection.js';
18
- function pickPath(obj, dotted) {
19
- const parts = dotted.split('.');
20
- let cur = obj;
21
- for (const p of parts) {
22
- if (cur && typeof cur === 'object' && p in cur) {
23
- cur = cur[p];
24
- }
25
- else {
26
- return undefined;
27
- }
28
- }
29
- return cur;
30
- }
31
- function valuesSemanticEqual(a, b) {
32
- try {
33
- deepEqual(a, b);
34
- return true;
35
- }
36
- catch {
37
- return false;
38
- }
39
- }
40
- export function runScenario(scenario) {
41
- const projected = {
42
- claude: getProjection('claude')(scenario.hostRaw.claude, scenario.input),
43
- codex: getProjection('codex')(scenario.hostRaw.codex, scenario.input),
44
- };
45
- const diffs = [];
46
- for (const key of scenario.compareKeys) {
47
- const cv = pickPath(projected.claude, key);
48
- const xv = pickPath(projected.codex, key);
49
- if (!valuesSemanticEqual(cv, xv)) {
50
- diffs.push({ key, claude: cv, codex: xv });
51
- }
52
- }
53
- return {
54
- scenarioId: scenario.id,
55
- intent: scenario.intent,
56
- passed: diffs.length === 0,
57
- diffs,
58
- projected,
59
- };
60
- }
61
- /**
62
- * P4 1차 시나리오 corpus — Trust Layer 7 의도 중 hook 출력으로 직접 관측 가능한 5종.
63
- * (`forge-loop-state-inject` 는 inject-context 의 특수 케이스, `self-evidence-record` 는
64
- * 파일 시스템 사이드이펙트라 본 corpus 가 아닌 별도 e2e 트랙.)
65
- *
66
- * P4 2차 추가 시나리오 (spec §10 우선순위 4 산출물, 2026-04-27):
67
- * - forge-loop-m1-inject-stale : §17.1 fact 1 / M1 hook 1KB cap + stale tag
68
- * - block-tool-use-pretool-ask : §9.0 block-tool-use row — Codex ask 값 동치
69
- * - stop-hook-reentry-guard : §15 stop_hook_active=true 즉시 approve 경로
70
- * - posttooluse-general-block-only : §9.0 secret-filter row partial — block decision 만 등가
71
- * - suppress-output-equivalence : suppressOutput 동치성
72
- */
73
- export const SCENARIO_CORPUS = [
74
- {
75
- id: 'block-completion-stop',
76
- intent: 'block-completion',
77
- description: 'Stop hook 이 block + reason 으로 자동 continuation 트리거',
78
- input: { hookEventName: 'Stop', stop_hook_active: false },
79
- hostRaw: {
80
- claude: { decision: 'block', reason: 'tests not yet executed' },
81
- codex: { decision: 'block', reason: 'tests not yet executed' },
82
- },
83
- // ADR-015 G1: Stop block 은 top-level decision/reason 으로 전달된다 (양 host 동일 스키마).
84
- compareKeys: [
85
- 'continue',
86
- 'decision',
87
- 'reason',
88
- ],
89
- },
90
- {
91
- id: 'block-tool-use-pretool-deny',
92
- intent: 'block-tool-use',
93
- description: 'PreToolUse 가 permissionDecision:deny + reason 으로 도구 차단',
94
- input: { hookEventName: 'PreToolUse', tool_name: 'Bash' },
95
- hostRaw: {
96
- claude: {
97
- hookSpecificOutput: {
98
- hookEventName: 'PreToolUse',
99
- permissionDecision: 'deny',
100
- permissionDecisionReason: 'rm -rf / matched',
101
- },
102
- },
103
- codex: {
104
- hookSpecificOutput: {
105
- hookEventName: 'PreToolUse',
106
- permissionDecision: 'deny',
107
- permissionDecisionReason: 'rm -rf / matched',
108
- },
109
- },
110
- },
111
- // 0.5.4: Codex PostToolUse 스키마는 hookSpecificOutput.permissionDecision 을 모른다 —
112
- // 사영이 top-level decision:"block" + reason 으로 번역하므로 그 키로 동치 비교.
113
- compareKeys: [
114
- 'decision',
115
- 'reason',
116
- ],
117
- },
118
- {
119
- id: 'inject-context-session-start',
120
- intent: 'inject-context',
121
- description: 'SessionStart 가 additionalContext 로 forge-loop state 주입',
122
- input: { hookEventName: 'SessionStart' },
123
- hostRaw: {
124
- claude: {
125
- hookSpecificOutput: {
126
- hookEventName: 'SessionStart',
127
- additionalContext: '<forge-loop-state>...</forge-loop-state>',
128
- },
129
- },
130
- codex: {
131
- hookSpecificOutput: {
132
- hookEventName: 'SessionStart',
133
- additionalContext: '<forge-loop-state>...</forge-loop-state>',
134
- },
135
- },
136
- },
137
- compareKeys: [
138
- 'continue',
139
- 'hookSpecificOutput.additionalContext',
140
- ],
141
- },
142
- {
143
- id: 'observe-only-non-allowlist',
144
- intent: 'observe-only',
145
- description: 'ALLOW-LIST 외 hook 이 deny 시도 시 approve 강등',
146
- input: { hookEventName: 'PreToolUse' },
147
- hostRaw: {
148
- claude: { continue: true },
149
- codex: { continue: true },
150
- },
151
- compareKeys: ['continue'],
152
- },
153
- {
154
- id: 'secret-filter-pretooluse-block',
155
- intent: 'secret-filter',
156
- description: 'API 키 노출 차단 — PreToolUse 가드 (양쪽 동일 경로)',
157
- input: { hookEventName: 'PreToolUse', tool_name: 'Bash' },
158
- hostRaw: {
159
- claude: {
160
- hookSpecificOutput: {
161
- hookEventName: 'PreToolUse',
162
- permissionDecision: 'deny',
163
- permissionDecisionReason: 'API_KEY=... matched',
164
- },
165
- },
166
- codex: {
167
- hookSpecificOutput: {
168
- hookEventName: 'PreToolUse',
169
- permissionDecision: 'deny',
170
- permissionDecisionReason: 'API_KEY=... matched',
171
- },
172
- },
173
- },
174
- compareKeys: [
175
- 'hookSpecificOutput.permissionDecision',
176
- 'hookSpecificOutput.permissionDecisionReason',
177
- ],
178
- },
179
- // ── P4 2차 추가 시나리오 ────────────────────────────────────────────────────
180
- {
181
- id: 'forge-loop-m1-inject-stale',
182
- intent: 'forge-loop-state-inject',
183
- description: 'SessionStart 가 stale="true" 태그 포함 forge-loop-state 를 1KB cap 내에서 inject (spec §17.1 fact 1 / M1 hook)',
184
- input: { hookEventName: 'SessionStart' },
185
- hostRaw: {
186
- claude: {
187
- hookSpecificOutput: {
188
- hookEventName: 'SessionStart',
189
- additionalContext: '<forge-loop-state stale="true">{"phase":"M1","lastCompletedAt":"2026-04-26T22:00:00Z"}</forge-loop-state>',
190
- },
191
- },
192
- codex: {
193
- hookSpecificOutput: {
194
- hookEventName: 'SessionStart',
195
- additionalContext: '<forge-loop-state stale="true">{"phase":"M1","lastCompletedAt":"2026-04-26T22:00:00Z"}</forge-loop-state>',
196
- },
197
- },
198
- },
199
- compareKeys: [
200
- 'continue',
201
- 'hookSpecificOutput.additionalContext',
202
- ],
203
- },
204
- {
205
- id: 'block-tool-use-pretool-ask',
206
- intent: 'block-tool-use',
207
- description: 'Codex PreToolUse permissionDecision:"ask" 가 Claude ask 값과 의미 동치 — forgen denyOrObserve 의 ask 의도 (spec §9.0 block-tool-use row 메모)',
208
- input: { hookEventName: 'PreToolUse', tool_name: 'Bash' },
209
- hostRaw: {
210
- claude: {
211
- hookSpecificOutput: {
212
- hookEventName: 'PreToolUse',
213
- permissionDecision: 'ask',
214
- permissionDecisionReason: 'requires human confirmation',
215
- },
216
- },
217
- codex: {
218
- hookSpecificOutput: {
219
- hookEventName: 'PreToolUse',
220
- permissionDecision: 'ask',
221
- permissionDecisionReason: 'requires human confirmation',
222
- },
223
- },
224
- },
225
- compareKeys: [
226
- 'hookSpecificOutput.permissionDecision',
227
- 'hookSpecificOutput.permissionDecisionReason',
228
- ],
229
- },
230
- {
231
- id: 'stop-hook-reentry-guard',
232
- intent: 'block-completion',
233
- description: 'stop_hook_active=true 시 Stop hook 이 즉시 approve(continue:true) 로 빠지는 재진입 가드 (spec §15)',
234
- input: { hookEventName: 'Stop', stop_hook_active: true },
235
- hostRaw: {
236
- claude: { continue: true },
237
- codex: { continue: true },
238
- },
239
- compareKeys: ['continue'],
240
- },
241
- {
242
- id: 'posttooluse-general-block-only',
243
- intent: 'secret-filter',
244
- description: 'PostToolUse 일반 tool — Codex 는 redact 미보장이므로 block decision 만 양쪽 등가. updatedMCPToolOutput 없음 (spec §9.0 secret-filter row partial / §18.2 fact 4)',
245
- input: { hookEventName: 'PostToolUse', tool_name: 'Bash' },
246
- hostRaw: {
247
- claude: {
248
- hookSpecificOutput: {
249
- hookEventName: 'PostToolUse',
250
- permissionDecision: 'deny',
251
- permissionDecisionReason: 'SECRET=... detected in tool output',
252
- },
253
- },
254
- codex: {
255
- hookSpecificOutput: {
256
- hookEventName: 'PostToolUse',
257
- permissionDecision: 'deny',
258
- permissionDecisionReason: 'SECRET=... detected in tool output',
259
- },
260
- },
261
- },
262
- compareKeys: [
263
- 'hookSpecificOutput.permissionDecision',
264
- 'hookSpecificOutput.permissionDecisionReason',
265
- ],
266
- },
267
- {
268
- id: 'suppress-output-equivalence',
269
- intent: 'observe-only',
270
- description: 'PostToolUse suppressOutput=true 가 양쪽 host 에서 동치로 사영됨',
271
- input: { hookEventName: 'PostToolUse', tool_name: 'Read' },
272
- hostRaw: {
273
- claude: {
274
- continue: true,
275
- suppressOutput: true,
276
- },
277
- codex: {
278
- continue: true,
279
- suppressOutput: true,
280
- },
281
- },
282
- compareKeys: [
283
- 'continue',
284
- 'suppressOutput',
285
- ],
286
- },
287
- ];