@wooojin/forgen 0.5.9 → 0.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 (66) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +63 -0
  3. package/README.ja.md +12 -0
  4. package/README.ko.md +12 -0
  5. package/README.md +12 -0
  6. package/README.zh.md +12 -0
  7. package/dist/checks/_shared/model-profile.d.ts +1 -1
  8. package/dist/checks/_shared/model-profile.js +9 -5
  9. package/dist/cli.js +32 -3
  10. package/dist/core/auto-compound-runner.js +20 -43
  11. package/dist/core/block-cli.d.ts +1 -0
  12. package/dist/core/block-cli.js +41 -0
  13. package/dist/core/explain-cli.js +29 -1
  14. package/dist/core/inspect-cli.js +9 -8
  15. package/dist/core/rate-limit-forecast.d.ts +113 -0
  16. package/dist/core/rate-limit-forecast.js +236 -0
  17. package/dist/core/state-gc.js +3 -0
  18. package/dist/core/stats-cli.d.ts +15 -0
  19. package/dist/core/stats-cli.js +50 -16
  20. package/dist/core/status-cli.d.ts +18 -1
  21. package/dist/core/status-cli.js +51 -2
  22. package/dist/core/statusline-cli.d.ts +58 -13
  23. package/dist/core/statusline-cli.js +164 -201
  24. package/dist/core/v1-bootstrap.js +7 -1
  25. package/dist/engine/block-judge-cli.d.ts +2 -0
  26. package/dist/engine/block-judge-cli.js +11 -0
  27. package/dist/engine/block-judge.d.ts +68 -0
  28. package/dist/engine/block-judge.js +248 -0
  29. package/dist/engine/correction-cluster-runner.d.ts +67 -0
  30. package/dist/engine/correction-cluster-runner.js +242 -5
  31. package/dist/engine/correction-clustering.d.ts +15 -0
  32. package/dist/engine/correction-clustering.js +24 -0
  33. package/dist/engine/lifecycle/lifecycle-cli.js +7 -4
  34. package/dist/engine/lifecycle/signals.d.ts +59 -2
  35. package/dist/engine/lifecycle/signals.js +193 -4
  36. package/dist/engine/lifecycle/trigger-t3-bypass.d.ts +5 -3
  37. package/dist/engine/lifecycle/trigger-t3-bypass.js +6 -4
  38. package/dist/engine/lifecycle/types.d.ts +29 -1
  39. package/dist/engine/mined-rule-merge-cli.d.ts +11 -0
  40. package/dist/engine/mined-rule-merge-cli.js +67 -0
  41. package/dist/engine/rule-relevance.d.ts +72 -0
  42. package/dist/engine/rule-relevance.js +183 -0
  43. package/dist/engine/rule-toggle-cli.d.ts +5 -0
  44. package/dist/engine/rule-toggle-cli.js +30 -0
  45. package/dist/fgx.js +1 -1
  46. package/dist/forge/evidence-processor.js +2 -0
  47. package/dist/hooks/post-tool-use.js +9 -14
  48. package/dist/hooks/pre-tool-use.js +71 -8
  49. package/dist/hooks/shared/command-parser.d.ts +11 -0
  50. package/dist/hooks/shared/command-parser.js +120 -0
  51. package/dist/hooks/solution-injector.js +13 -0
  52. package/dist/hooks/stop-guard.d.ts +18 -0
  53. package/dist/hooks/stop-guard.js +55 -10
  54. package/dist/mcp/tools.js +7 -1
  55. package/dist/renderer/inspect-renderer.js +23 -6
  56. package/dist/renderer/rule-renderer.js +4 -2
  57. package/dist/store/evidence-store.js +37 -2
  58. package/dist/store/profile-score.d.ts +55 -0
  59. package/dist/store/profile-score.js +100 -0
  60. package/dist/store/profile-store.d.ts +22 -5
  61. package/dist/store/profile-store.js +42 -6
  62. package/dist/store/rule-origin.d.ts +39 -0
  63. package/dist/store/rule-origin.js +84 -0
  64. package/dist/store/types.d.ts +24 -0
  65. package/package.json +1 -1
  66. package/plugin.json +1 -1
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Rule origin — "이 룰은 언제 어떤 교정에서 생겼는가" (ADR-017 D0)
3
+ *
4
+ * 체감의 가장 싼 레버: 차단 메시지와 룰 렌더에 룰의 출처 교정(날짜·종류·문장)을 붙인다.
5
+ * explicit_correction 룰만 대상 — 채굴 룰(behavior_inference)은 사용자가 한 말이 아니므로
6
+ * 인용하지 않는다(ADR-013 provenance 차등).
7
+ *
8
+ * 정직성 (critic D0 SEV-2-a): evidence.summary 는 correction-record 를 호출한 **모델이 쓴 문장**이고
9
+ * 실데이터 12/12 에서 rule.policy 와 동일하다. 그래서
10
+ * - raw_payload.user_quote (사용자 발화 원문, 2026-10-06 부터 저장) 가 있을 때만 "당신의 말" 로 인용하고
11
+ * - 없으면 "교정 기록 YYYY-MM-DD (kind)" 만 표기한다. summary 가 policy 와 같으면 인용문을 생략한다
12
+ * (같은 문장을 두 번 보여주는 중복 방지).
13
+ *
14
+ * 비용: evidence 파일 1개를 safeReadJSON 으로 직접 읽는다 — evidence-store 모듈 그래프(lifecycle·
15
+ * classifier 등 18모듈)를 끌어오지 않는다 (critic SEV-2-b). 모든 경로 fail-open(null).
16
+ */
17
+ import * as path from 'node:path';
18
+ import { ME_BEHAVIOR } from '../core/paths.js';
19
+ import { safeReadJSON } from '../hooks/shared/atomic-write.js';
20
+ export const MAX_QUOTE = 90;
21
+ /** 한 줄·안전한 인용문: 공백 정규화, 제어문자·꺾쇠·백틱 제거, 길이 제한 (critic SEV-2-c). */
22
+ export function sanitizeQuote(raw) {
23
+ // 제어문자(0x00-0x1f, 0x7f)는 문자 코드로 걸러낸다 — 정규식 리터럴의 제어문자 escape 는 biome 이 금지.
24
+ const noCtrl = Array.from(raw, (ch) => { const c = ch.charCodeAt(0); return c < 0x20 || c === 0x7f ? ' ' : ch; }).join('');
25
+ const oneLine = noCtrl
26
+ .replace(/[<>`]/g, '')
27
+ .replace(/\s+/g, ' ')
28
+ .trim();
29
+ return oneLine.length > MAX_QUOTE ? `${oneLine.slice(0, MAX_QUOTE - 1)}…` : oneLine;
30
+ }
31
+ function readEvidence(id) {
32
+ if (!/^[A-Za-z0-9_-]+$/.test(id))
33
+ return null; // 경로 인젝션 방지
34
+ return safeReadJSON(path.join(ME_BEHAVIOR, `${id}.json`), null);
35
+ }
36
+ export function ruleOrigin(rule) {
37
+ try {
38
+ if (rule.source !== 'explicit_correction')
39
+ return null;
40
+ // 가장 최근 교정 — append 순이 아니라 timestamp 로 고른다 (클러스터링으로 refs 가 늘면 순서 보장 없음).
41
+ let best = null;
42
+ for (const id of rule.evidence_refs ?? []) {
43
+ const ev = readEvidence(id);
44
+ if (ev?.type !== 'explicit_correction' || typeof ev.timestamp !== 'string')
45
+ continue;
46
+ if (!best || ev.timestamp > best.timestamp)
47
+ best = ev;
48
+ }
49
+ if (!best)
50
+ return null;
51
+ const date = best.timestamp.slice(0, 10);
52
+ if (!date)
53
+ return null;
54
+ const kind = typeof best.raw_payload?.kind === 'string' ? best.raw_payload.kind : undefined;
55
+ const userQuote = typeof best.raw_payload?.user_quote === 'string' ? sanitizeQuote(best.raw_payload.user_quote) : '';
56
+ if (userQuote)
57
+ return { date, kind, quote: userQuote, quoteSource: 'user' };
58
+ const summary = typeof best.summary === 'string' ? sanitizeQuote(best.summary) : '';
59
+ const policy = typeof rule.policy === 'string' ? sanitizeQuote(rule.policy) : '';
60
+ if (summary && summary !== policy)
61
+ return { date, kind, quote: summary, quoteSource: 'summary' };
62
+ return { date, kind, quote: '', quoteSource: 'none' };
63
+ }
64
+ catch {
65
+ return null;
66
+ }
67
+ }
68
+ /** 차단/안내 메시지용 한 줄. 출처가 없으면 ''. */
69
+ export function originLine(rule) {
70
+ const o = ruleOrigin(rule);
71
+ if (!o)
72
+ return '';
73
+ const kind = o.kind ? ` (${o.kind})` : '';
74
+ if (o.quoteSource === 'user')
75
+ return `[forgen] 이 룰의 출처 — ${o.date} 당신의 말${kind}: "${o.quote}"`;
76
+ if (o.quoteSource === 'summary')
77
+ return `[forgen] 이 룰의 출처 — ${o.date} 교정 기록${kind}: "${o.quote}"`;
78
+ return `[forgen] 이 룰의 출처 — ${o.date} 교정 기록${kind}`;
79
+ }
80
+ /** 룰 렌더(v1-rules.md 등)용 짧은 꼬리표. 토큰 절감을 위해 날짜만. 출처 없으면 ''. */
81
+ export function originTag(rule) {
82
+ const o = ruleOrigin(rule);
83
+ return o ? ` (교정 ${o.date})` : '';
84
+ }
@@ -106,6 +106,11 @@ export interface Rule {
106
106
  * ADR-001 §Data Model.
107
107
  */
108
108
  enforce_via?: EnforceSpec[];
109
+ /**
110
+ * ADR-017 D1: precision 자동 강등. 'advise' 면 Mech-A/B 가 차단 대신 기록(kind:'correction')만 한다.
111
+ * 하드 룰(strength 'hard')과 builtin 은 자동으로 'advise' 가 되지 않는다. 미지정 = 'block'.
112
+ */
113
+ enforce_mode?: 'block' | 'advise';
109
114
  /**
110
115
  * Lifecycle 상태. optional — 기존 rule 은 load 시 phase='active' 로 auto-initialize.
111
116
  * ADR-002 §Data Model.
@@ -117,6 +122,20 @@ export interface Rule {
117
122
  * 통합 rule 쪽에는 설정되지 않는다(원본에만). ADR-010 W3-2.
118
123
  */
119
124
  clustered_into?: string;
125
+ /**
126
+ * ADR-017 D3: 채굴(behavior_inference) 룰과 explicit 룰이 같은 개념일 때의 *링크*.
127
+ * 흡수가 아니다 — evidence_refs/strength 는 양쪽 모두 불변(ADR-013 불변식).
128
+ * - explicit 룰 쪽: 이 룰과 같은 개념으로 링크된 채굴 rule_id 목록.
129
+ * - 채굴 룰 쪽: 링크 대상 explicit rule_id(1개). status 'superseded' + clustered_into 와 함께
130
+ * 설정되어 렌더에서 숨겨지고 `forgen rule unmerge` 로 복원된다.
131
+ */
132
+ related_to?: string[];
133
+ /**
134
+ * ADR-017 D3: explicit 룰에만 설정. 이 룰과 같은 개념이 이후 세션에서 *채굴*로 관측된 횟수
135
+ * (링크된 채굴 룰의 evidence 수 + 사전 중복 검사에서 흡수된 채굴 evidence 수).
136
+ * evidence_refs 에 합산하지 않으므로 strength 산출에 영향을 주지 않는다.
137
+ */
138
+ mined_observations?: number;
120
139
  }
121
140
  export type EvidenceType = 'explicit_correction' | 'behavior_observation' | 'session_summary';
122
141
  export interface Evidence {
@@ -240,6 +259,11 @@ export interface CorrectionRequest {
240
259
  message: string;
241
260
  target: string;
242
261
  axis_hint: 'quality_safety' | 'autonomy' | 'judgment_philosophy' | 'communication_style' | null;
262
+ /**
263
+ * ADR-017 D0 (2026-10-06): 사용자 발화 **원문** (모델이 정리한 message 와 구분). 있을 때만
264
+ * 차단 메시지가 "당신의 말" 로 인용한다. <private> 필터 후 저장.
265
+ */
266
+ user_quote?: string;
243
267
  }
244
268
  export interface CorrectionResult {
245
269
  temporary_rule: Rule | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wooojin/forgen",
3
- "version": "0.5.9",
3
+ "version": "0.6.1",
4
4
  "preferGlobal": true,
5
5
  "main": "dist/lib.js",
6
6
  "types": "./dist/lib.d.ts",
package/plugin.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://claude.ai/schemas/claude-plugin.json",
3
3
  "name": "forgen",
4
- "version": "0.5.9",
4
+ "version": "0.6.1",
5
5
  "description": "Claude Code harness — the more you use Claude, the better it gets",
6
6
  "author": {
7
7
  "name": "jang-ujin",