@wooojin/forgen 0.3.0 → 0.3.2

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 (86) hide show
  1. package/.claude-plugin/plugin.json +7 -2
  2. package/CHANGELOG.md +132 -0
  3. package/README.ja.md +29 -0
  4. package/README.ko.md +29 -0
  5. package/README.md +36 -3
  6. package/README.zh.md +29 -0
  7. package/agents/solution-evolver.md +115 -0
  8. package/dist/cli.js +11 -3
  9. package/dist/core/auto-compound-runner.js +6 -3
  10. package/dist/core/dashboard.js +57 -4
  11. package/dist/core/doctor.d.ts +6 -1
  12. package/dist/core/doctor.js +21 -1
  13. package/dist/core/global-config.d.ts +2 -2
  14. package/dist/core/global-config.js +6 -14
  15. package/dist/core/harness.d.ts +3 -5
  16. package/dist/core/harness.js +34 -338
  17. package/dist/core/installer.d.ts +10 -0
  18. package/dist/core/installer.js +185 -0
  19. package/dist/core/paths.d.ts +25 -34
  20. package/dist/core/paths.js +25 -35
  21. package/dist/core/settings-injector.d.ts +13 -0
  22. package/dist/core/settings-injector.js +167 -0
  23. package/dist/core/settings-lock.d.ts +35 -2
  24. package/dist/core/settings-lock.js +65 -7
  25. package/dist/core/spawn.js +100 -39
  26. package/dist/core/state-gc.d.ts +30 -0
  27. package/dist/core/state-gc.js +119 -0
  28. package/dist/core/uninstall.js +12 -4
  29. package/dist/core/v1-bootstrap.js +2 -2
  30. package/dist/engine/compound-cli.d.ts +27 -2
  31. package/dist/engine/compound-cli.js +69 -16
  32. package/dist/engine/compound-export.d.ts +15 -0
  33. package/dist/engine/compound-export.js +32 -5
  34. package/dist/engine/compound-loop.js +3 -2
  35. package/dist/engine/learn-cli.d.ts +1 -0
  36. package/dist/engine/learn-cli.js +234 -0
  37. package/dist/engine/match-eval-log.js +45 -0
  38. package/dist/engine/solution-candidate.d.ts +30 -0
  39. package/dist/engine/solution-candidate.js +124 -0
  40. package/dist/engine/solution-fitness.d.ts +52 -0
  41. package/dist/engine/solution-fitness.js +95 -0
  42. package/dist/engine/solution-fixup.d.ts +30 -0
  43. package/dist/engine/solution-fixup.js +116 -0
  44. package/dist/engine/solution-format.d.ts +8 -2
  45. package/dist/engine/solution-format.js +38 -27
  46. package/dist/engine/solution-index.js +10 -0
  47. package/dist/engine/solution-matcher.d.ts +8 -0
  48. package/dist/engine/solution-matcher.js +27 -1
  49. package/dist/engine/solution-outcomes.d.ts +74 -0
  50. package/dist/engine/solution-outcomes.js +319 -0
  51. package/dist/engine/solution-quarantine.d.ts +36 -0
  52. package/dist/engine/solution-quarantine.js +172 -0
  53. package/dist/engine/solution-weakness.d.ts +45 -0
  54. package/dist/engine/solution-weakness.js +225 -0
  55. package/dist/engine/solution-writer.d.ts +9 -1
  56. package/dist/engine/solution-writer.js +44 -2
  57. package/dist/fgx.js +9 -2
  58. package/dist/forge/cli.js +7 -7
  59. package/dist/hooks/context-guard.js +15 -1
  60. package/dist/hooks/hook-config.d.ts +9 -1
  61. package/dist/hooks/hook-config.js +25 -3
  62. package/dist/hooks/internal/run-lifecycle-check.d.ts +2 -0
  63. package/dist/hooks/internal/run-lifecycle-check.js +32 -0
  64. package/dist/hooks/notepad-injector.js +6 -3
  65. package/dist/hooks/permission-handler.d.ts +10 -2
  66. package/dist/hooks/permission-handler.js +31 -12
  67. package/dist/hooks/post-tool-failure.js +7 -0
  68. package/dist/hooks/pre-tool-use.js +10 -4
  69. package/dist/hooks/secret-filter.js +6 -0
  70. package/dist/hooks/session-recovery.js +15 -7
  71. package/dist/hooks/shared/hook-response.d.ts +0 -2
  72. package/dist/hooks/shared/hook-response.js +3 -8
  73. package/dist/hooks/shared/hook-timing.js +10 -1
  74. package/dist/hooks/solution-injector.d.ts +21 -0
  75. package/dist/hooks/solution-injector.js +80 -1
  76. package/dist/mcp/solution-reader.d.ts +2 -0
  77. package/dist/mcp/solution-reader.js +28 -1
  78. package/dist/mcp/tools.js +13 -2
  79. package/dist/preset/preset-manager.js +12 -2
  80. package/dist/store/evidence-store.js +5 -5
  81. package/dist/store/profile-store.d.ts +9 -0
  82. package/dist/store/profile-store.js +25 -4
  83. package/dist/store/rule-store.js +8 -8
  84. package/package.json +1 -1
  85. package/plugin.json +7 -2
  86. package/scripts/postinstall.js +52 -5
@@ -334,10 +334,16 @@ async function main() {
334
334
  log.debug('compound reflection check 실패', e);
335
335
  }
336
336
  // 활성 모드 리마인더 (10회 호출당 1회 — 결정적 카운터 기반)
337
- const reminders = getActiveReminders();
338
- if (reminders.length > 0 && shouldShowReminderIO()) {
339
- console.log(approveWithWarning(`<compound-reminder>\n${reminders.join('\n')}\n</compound-reminder>`));
340
- return;
337
+ // P0-4 fix (2026-04-20): 과거에는 getActiveReminders()로 STATE_DIR을 먼저
338
+ // readdir + N회 readFileSync한 뒤에야 shouldShowReminderIO 카운터를 체크했다.
339
+ // 그래서 "리마인더를 보여줄 호출이 아닌" 90%에서도 디렉터리 스캔이 발생.
340
+ // 이제 shouldShowReminderIO를 먼저 체크해 표시 회차일 때만 스캔한다.
341
+ if (shouldShowReminderIO()) {
342
+ const reminders = getActiveReminders();
343
+ if (reminders.length > 0) {
344
+ console.log(approveWithWarning(`<compound-reminder>\n${reminders.join('\n')}\n</compound-reminder>`));
345
+ return;
346
+ }
341
347
  }
342
348
  console.log(approve());
343
349
  }
@@ -16,6 +16,12 @@ export const SECRET_PATTERNS = [
16
16
  { name: 'Password', pattern: /(password|passwd|pwd)\s*[=:]\s*["']?[^\s"']{8,}/i },
17
17
  { name: 'Private Key', pattern: /-----BEGIN (RSA |EC |DSA )?PRIVATE KEY-----/ },
18
18
  { name: 'Connection String', pattern: /(mongodb|postgres|mysql|redis):\/\/\w+:[^@]+@/ },
19
+ // 2026-04-21 follow-up audit #B: vendor-specific prefixes the generic
20
+ // `(sk|pk|api-key)[_-]` pattern does NOT match. Real-world leaks
21
+ // overwhelmingly use these formats.
22
+ { name: 'GitHub Token', pattern: /\b(ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9]{36,}\b/ },
23
+ { name: 'Google API Key', pattern: /\bAIza[0-9A-Za-z_-]{35}\b/ },
24
+ { name: 'Slack Token', pattern: /\bxox[abpors]-[A-Za-z0-9-]{10,}/ },
19
25
  ];
20
26
  /** 텍스트에서 민감 정보 패턴 감지 (순수 함수) */
21
27
  export function detectSecrets(text) {
@@ -378,7 +378,6 @@ async function main() {
378
378
  // v1: regex 기반 패턴 학습(prompt-learner) 제거. Evidence 기반으로 전환됨.
379
379
  // Compound v3: Run lifecycle check once per day
380
380
  try {
381
- const lifecycleModulePath = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'engine', 'compound-lifecycle.js');
382
381
  const lastLifecyclePath = path.join(STATE_DIR, 'last-lifecycle.json');
383
382
  let shouldRun = true;
384
383
  try {
@@ -390,13 +389,22 @@ async function main() {
390
389
  }
391
390
  catch { /* last-lifecycle.json parse failure — run lifecycle check anyway */ }
392
391
  if (shouldRun) {
393
- // B-4: detached background spawn으로 분리 — hook timeout 초과 방지
392
+ // B-4: detached background spawn — hook timeout 초과 방지.
393
+ //
394
+ // Audit fix #5 (2026-04-21): prior invocation interpolated
395
+ // `sessionId` into a `-e` template literal
396
+ // `import('${path}').then(m => m.runLifecycleCheck('${sessionId}'))`
397
+ // which created a code-injection surface (a crafted sessionId
398
+ // could break out of the single quotes and execute arbitrary JS
399
+ // under the user's Claude-Code privileges). The runner was moved
400
+ // to a dedicated script file and the id is now passed via argv —
401
+ // no shell, no eval, no interpolation.
402
+ const runnerPath = path.join(path.dirname(fileURLToPath(import.meta.url)), 'internal', 'run-lifecycle-check.js');
394
403
  const { spawn: spawnLifecycle } = await import('node:child_process');
395
- const lifecycleRunner = spawnLifecycle('node', [
396
- '--input-type=module',
397
- '-e',
398
- `import('${lifecycleModulePath.replace(/\\/g, '/')}').then(m => m.runLifecycleCheck('${sessionId}'))`,
399
- ], { detached: true, stdio: 'ignore' });
404
+ const lifecycleRunner = spawnLifecycle('node', [runnerPath, sessionId], {
405
+ detached: true,
406
+ stdio: 'ignore',
407
+ });
400
408
  lifecycleRunner.unref();
401
409
  const { atomicWriteJSON: writeJSON } = await import('./shared/atomic-write.js');
402
410
  writeJSON(lastLifecyclePath, { lastRun: new Date().toISOString() });
@@ -29,8 +29,6 @@ export declare function approveWithWarning(warning: string): string;
29
29
  export declare function deny(reason: string): string;
30
30
  /** 사용자 확인 요청 (PreToolUse 전용) */
31
31
  export declare function ask(reason: string): string;
32
- /** fail-open: 에러 시 안전하게 통과 */
33
- export declare function failOpen(): string;
34
32
  /**
35
33
  * fail-open with error tracking: 에러 시 안전하게 통과하되, 실패 정보를 기록.
36
34
  * forgen doctor의 Hook Health 섹션에서 실패 이력을 표시할 수 있도록 JSONL 로그에 기록.
@@ -14,8 +14,8 @@
14
14
  * 모델에 컨텍스트를 주입하려면 반드시 additionalContext를 사용해야 함.
15
15
  */
16
16
  import * as fs from 'node:fs';
17
- import * as os from 'node:os';
18
17
  import * as path from 'node:path';
18
+ import { STATE_DIR } from '../../core/paths.js';
19
19
  /** 통과 응답 (컨텍스트 없음, 모든 이벤트 공통) */
20
20
  export function approve() {
21
21
  return JSON.stringify({ continue: true });
@@ -59,10 +59,6 @@ export function ask(reason) {
59
59
  },
60
60
  });
61
61
  }
62
- /** fail-open: 에러 시 안전하게 통과 */
63
- export function failOpen() {
64
- return JSON.stringify({ continue: true });
65
- }
66
62
  /**
67
63
  * fail-open with error tracking: 에러 시 안전하게 통과하되, 실패 정보를 기록.
68
64
  * forgen doctor의 Hook Health 섹션에서 실패 이력을 표시할 수 있도록 JSONL 로그에 기록.
@@ -71,9 +67,8 @@ export function failOpen() {
71
67
  */
72
68
  export function failOpenWithTracking(hookName) {
73
69
  try {
74
- const stateDir = path.join(os.homedir(), '.forgen', 'state');
75
- fs.mkdirSync(stateDir, { recursive: true });
76
- const logPath = path.join(stateDir, 'hook-errors.jsonl');
70
+ fs.mkdirSync(STATE_DIR, { recursive: true });
71
+ const logPath = path.join(STATE_DIR, 'hook-errors.jsonl');
77
72
  const entry = JSON.stringify({ hook: hookName, at: Date.now() });
78
73
  fs.appendFileSync(logPath, entry + '\n');
79
74
  }
@@ -9,13 +9,22 @@ import * as path from 'node:path';
9
9
  import { STATE_DIR } from '../../core/paths.js';
10
10
  const TIMING_LOG = path.join(STATE_DIR, 'hook-timing.jsonl');
11
11
  const MAX_LINES = 500;
12
+ // P0-2 fix (2026-04-20): rotate를 size gate로 보호. 이전에는 매 hook 완료마다
13
+ // full-file read + length split + write까지 실행해 steady-state(500줄 근처)에서
14
+ // 매 tool call당 ~40KB의 불필요 I/O가 발생했다. statSync 한 번으로 크기만 보고
15
+ // threshold 이하면 read/write 둘 다 skip한다. threshold는 ~80바이트/엔트리 기준
16
+ // MAX_LINES × 1.5 여유를 둠.
17
+ const ROTATE_SIZE_BYTES = MAX_LINES * 80 * 2; // ~80KB
12
18
  export function recordHookTiming(hookName, durationMs, event) {
13
19
  try {
14
20
  fs.mkdirSync(STATE_DIR, { recursive: true });
15
21
  const entry = JSON.stringify({ hook: hookName, ms: durationMs, event, at: Date.now() });
16
22
  fs.appendFileSync(TIMING_LOG, entry + '\n');
17
- // Rotate if too large
23
+ // Rotate if too large — size-gated (statSync only, skip read/write 대부분의 호출)
18
24
  try {
25
+ const size = fs.statSync(TIMING_LOG).size;
26
+ if (size < ROTATE_SIZE_BYTES)
27
+ return;
19
28
  const content = fs.readFileSync(TIMING_LOG, 'utf-8');
20
29
  const lines = content.trim().split('\n');
21
30
  if (lines.length > MAX_LINES) {
@@ -7,6 +7,27 @@
7
7
  *
8
8
  * knowledge-comes-to-you 원칙: 필요한 지식은 찾아와야 한다
9
9
  */
10
+ /**
11
+ * Minimum relevance thresholds by fitness state (2026-04-21 gate sweep).
12
+ *
13
+ * Motivation: a flat 0.3 floor gave 100% precision but 60% recall on a
14
+ * synthetic 40-query workload — 10 legitimate matches that scored
15
+ * 0.25-0.30 were blocked alongside noise. A pure 0.25 floor pushed recall
16
+ * to 84% but stripped noise protection for unverified solutions.
17
+ *
18
+ * Champion-aware solution: trust graduates more. Solutions whose fitness
19
+ * classification is `champion` or `active` (accept/correct ratio has
20
+ * survived ≥5 injections under the v0.3.2 gates) earn a lower 0.25
21
+ * injection floor; everything else stays at 0.3. On the sweep this hit
22
+ * precision 95.5% / recall 84% / off-topic specificity 100% — best
23
+ * trade in the variant set.
24
+ *
25
+ * If fitness data is unavailable (fresh install, empty outcomes/),
26
+ * every solution falls into the default 0.3 bucket — identical to the
27
+ * pre-0.3.2 gate. No cold-start regression.
28
+ */
29
+ export declare const MIN_INJECT_RELEVANCE = 0.3;
30
+ export declare const MIN_INJECT_RELEVANCE_TRUSTED = 0.25;
10
31
  interface SessionCacheCommitResult {
11
32
  /**
12
33
  * commit 상태:
@@ -28,7 +28,29 @@ import { writeSignal } from './shared/plugin-signal.js';
28
28
  import { approve, approveWithContext, failOpenWithTracking } from './shared/hook-response.js';
29
29
  import { STATE_DIR } from '../core/paths.js';
30
30
  import { recordHookTiming } from './shared/hook-timing.js';
31
+ import { appendPending, flushAccept } from '../engine/solution-outcomes.js';
31
32
  const MAX_SOLUTIONS_PER_SESSION = 10;
33
+ /**
34
+ * Minimum relevance thresholds by fitness state (2026-04-21 gate sweep).
35
+ *
36
+ * Motivation: a flat 0.3 floor gave 100% precision but 60% recall on a
37
+ * synthetic 40-query workload — 10 legitimate matches that scored
38
+ * 0.25-0.30 were blocked alongside noise. A pure 0.25 floor pushed recall
39
+ * to 84% but stripped noise protection for unverified solutions.
40
+ *
41
+ * Champion-aware solution: trust graduates more. Solutions whose fitness
42
+ * classification is `champion` or `active` (accept/correct ratio has
43
+ * survived ≥5 injections under the v0.3.2 gates) earn a lower 0.25
44
+ * injection floor; everything else stays at 0.3. On the sweep this hit
45
+ * precision 95.5% / recall 84% / off-topic specificity 100% — best
46
+ * trade in the variant set.
47
+ *
48
+ * If fitness data is unavailable (fresh install, empty outcomes/),
49
+ * every solution falls into the default 0.3 bucket — identical to the
50
+ * pre-0.3.2 gate. No cold-start regression.
51
+ */
52
+ export const MIN_INJECT_RELEVANCE = 0.3;
53
+ export const MIN_INJECT_RELEVANCE_TRUSTED = 0.25;
32
54
  /** 세션별 이미 주입된 솔루션 추적 (중복 방지) */
33
55
  function getSessionCachePath(sessionId) {
34
56
  return path.join(STATE_DIR, `solution-cache-${sanitizeId(sessionId)}.json`);
@@ -298,12 +320,50 @@ async function main() {
298
320
  console.log(approve());
299
321
  return;
300
322
  }
301
- // 어댑티브 프롬프트당 솔루션 수 제한, experiment는 1개 제한
323
+ // 어댑티브 프롬프트당 솔루션 수 제한, experiment는 1개 제한.
324
+ // 2026-04-21: MIN_INJECT_RELEVANCE 게이트 추가. 과거 0.15~0.21짜리 저신뢰 매칭이
325
+ // 거의 모든 세션에 주입되어 error 귀속의 80%를 차지했음.
326
+ //
327
+ // 2026-04-21 (precision audit follow-up): 단일 태그 매칭은 주입 차단.
328
+ // ~/.forgen/state/match-eval-log.jsonl 7406 queries 분석 결과, top-1의
329
+ // 33.5%가 "forgen", "type", "file" 같은 공통 단어 한 개로 매칭되어 희귀
330
+ // 태그 BM25 boost로 0.5~0.8 점수를 받고 사용자 컨텍스트를 오염시켰다.
331
+ // Matcher는 top-5 recall 유지를 위해 permissive 하게 두고 (bootstrap eval
332
+ // 호환), 주입 직전에만 엄격히:
333
+ // - identifier match ≥ 1 (함수/파일 이름 리터럴 매칭 — 강한 신호) OR
334
+ // - matched tags ≥ 2 (의도 교차점 2개 이상)
335
+ // 둘 중 하나를 만족해야 주입.
336
+ // 2026-04-21 (champion-aware gate): fitness 상태가 champion/active인 솔루션은
337
+ // 검증된 신호가 있으므로 임계값 0.25로 완화. draft/underperform 은 0.3 그대로.
338
+ // Fitness 데이터가 없으면 전체 default 0.3 (cold-start 회귀 없음).
339
+ // Gate sweep 결과: precision 95.5% / recall 84% / off-topic specificity 100%.
340
+ const fitnessStateMap = new Map();
341
+ try {
342
+ const { computeFitness } = await import('../engine/solution-fitness.js');
343
+ for (const r of computeFitness()) {
344
+ fitnessStateMap.set(r.solution, r.state);
345
+ }
346
+ }
347
+ catch (e) {
348
+ log.debug('fitness state load 실패 — default 0.3 적용', e);
349
+ }
350
+ function minRelevanceFor(name) {
351
+ const state = fitnessStateMap.get(name);
352
+ return (state === 'champion' || state === 'active')
353
+ ? MIN_INJECT_RELEVANCE_TRUSTED
354
+ : MIN_INJECT_RELEVANCE;
355
+ }
302
356
  let experimentCount = 0;
303
357
  const toInject = [];
304
358
  for (const sol of matches) {
305
359
  if (injected.has(sol.name))
306
360
  continue;
361
+ if (sol.relevance < minRelevanceFor(sol.name))
362
+ continue;
363
+ const idMatches = sol.matchedIdentifiers?.length ?? 0;
364
+ const tagMatches = Math.max(0, sol.matchedTags.length - idMatches);
365
+ if (idMatches < 1 && tagMatches < 2)
366
+ continue;
307
367
  if (sol.status === 'experiment') {
308
368
  if (experimentCount >= 1)
309
369
  continue;
@@ -451,6 +511,25 @@ async function main() {
451
511
  catch (e) {
452
512
  log.debug('plugin signal 기록 실패', e);
453
513
  }
514
+ // Outcome tracking (Phase 1): flush previous pending as `accept` (silence
515
+ // = consent), then record this round's injections as new pending. Both
516
+ // calls are fail-open — a tracking crash must not block injection.
517
+ try {
518
+ flushAccept(sessionId);
519
+ }
520
+ catch (e) {
521
+ log.debug('outcome flushAccept 실패', e);
522
+ }
523
+ try {
524
+ appendPending(sessionId, effectiveToInject.map((sol) => ({
525
+ solution: sol.name,
526
+ match_score: sol.relevance,
527
+ injected_chars: (summaries.get(sol.name) ?? sol.name).length,
528
+ })));
529
+ }
530
+ catch (e) {
531
+ log.debug('outcome appendPending 실패', e);
532
+ }
454
533
  console.log(approveWithContext(fullInjection, 'UserPromptSubmit'));
455
534
  }
456
535
  finally {
@@ -53,6 +53,8 @@ export interface SolutionDetail {
53
53
  }
54
54
  export interface SolutionStats {
55
55
  total: number;
56
+ retiredCount: number;
57
+ extractionPrecision: number | null;
56
58
  byStatus: Record<SolutionStatus, number>;
57
59
  byType: Record<SolutionType, number>;
58
60
  byScope: Record<'me' | 'team' | 'project' | 'universal', number>;
@@ -18,7 +18,7 @@ import * as path from 'node:path';
18
18
  import { ME_SOLUTIONS, PACKS_DIR } from '../core/paths.js';
19
19
  import { logMatchDecision } from '../engine/match-eval-log.js';
20
20
  import { maskBlockedTokens } from '../engine/phrase-blocklist.js';
21
- import { expandCompoundTags, expandQueryBigrams, extractTags, parseSolutionV3, } from '../engine/solution-format.js';
21
+ import { expandCompoundTags, expandQueryBigrams, extractTags, parseFrontmatterOnly, parseSolutionV3, } from '../engine/solution-format.js';
22
22
  import { getOrBuildIndex } from '../engine/solution-index.js';
23
23
  import { calculateRelevance, shouldRejectByR4T3Rules } from '../engine/solution-matcher.js';
24
24
  import { mutateSolutionFile } from '../engine/solution-writer.js';
@@ -257,8 +257,30 @@ export function readSolution(name, options) {
257
257
  export function getSolutionStats(options) {
258
258
  const dirs = options?.dirs ?? defaultSolutionDirs();
259
259
  const index = getOrBuildIndex(dirs);
260
+ // retired 카운트: 인덱스에서 제외되므로 디렉토리를 직접 스캔
261
+ let retiredCount = 0;
262
+ for (const { dir } of dirs) {
263
+ if (!fs.existsSync(dir))
264
+ continue;
265
+ try {
266
+ const files = fs.readdirSync(dir).filter((f) => f.endsWith('.md'));
267
+ for (const file of files) {
268
+ try {
269
+ const content = fs.readFileSync(path.join(dir, file), 'utf-8');
270
+ const fm = parseFrontmatterOnly(content);
271
+ if (fm?.status === 'retired')
272
+ retiredCount++;
273
+ }
274
+ catch { /* ignore */ }
275
+ }
276
+ }
277
+ catch { /* ignore */ }
278
+ }
279
+ // extractionPrecision: verified+mature / (total active + retired)
260
280
  const stats = {
261
281
  total: index.entries.length,
282
+ retiredCount,
283
+ extractionPrecision: null,
262
284
  // retired는 인덱스에서 제외되므로 항상 0 (solution-index.ts:73)
263
285
  byStatus: { experiment: 0, candidate: 0, verified: 0, mature: 0, retired: 0 },
264
286
  byType: {
@@ -279,5 +301,10 @@ export function getSolutionStats(options) {
279
301
  if (entry.scope in stats.byScope)
280
302
  stats.byScope[entry.scope]++;
281
303
  }
304
+ const highConfidence = stats.byStatus.verified + stats.byStatus.mature;
305
+ const denominator = index.entries.length + retiredCount;
306
+ if (denominator > 0) {
307
+ stats.extractionPrecision = Math.round((highConfidence / denominator) * 100);
308
+ }
282
309
  return stats;
283
310
  }
package/dist/mcp/tools.js CHANGED
@@ -158,7 +158,10 @@ export function registerTools(server) {
158
158
  dirs: defaultSolutionDirs(getCwd()),
159
159
  });
160
160
  const lines = [
161
- `Total solutions: ${stats.total}`,
161
+ `Total solutions: ${stats.total} active + ${stats.retiredCount} retired`,
162
+ stats.extractionPrecision !== null
163
+ ? `Extraction precision: ${stats.extractionPrecision}%`
164
+ : '',
162
165
  '',
163
166
  'By status:',
164
167
  ...Object.entries(stats.byStatus)
@@ -174,7 +177,7 @@ export function registerTools(server) {
174
177
  ...Object.entries(stats.byScope)
175
178
  .filter(([, count]) => count > 0)
176
179
  .map(([scope, count]) => ` ${scope}: ${count}`),
177
- ];
180
+ ].filter((l) => l !== undefined);
178
181
  return {
179
182
  content: [{
180
183
  type: 'text',
@@ -273,6 +276,14 @@ export function registerTools(server) {
273
276
  target,
274
277
  axis_hint: axis_hint,
275
278
  });
279
+ // Outcome tracking (Phase 1): attribute this correction to any
280
+ // pending injections in the session. Fail-open — attribution is a
281
+ // best-effort signal, never block the correction record itself.
282
+ try {
283
+ const { attributeCorrection } = await import('../engine/solution-outcomes.js');
284
+ attributeCorrection(effectiveSessionId);
285
+ }
286
+ catch { /* ignore */ }
276
287
  const lines = [
277
288
  `Evidence recorded: ${result.evidence_event_id}`,
278
289
  ];
@@ -76,8 +76,18 @@ export function computeEffectiveTrust(desired, runtime) {
76
76
  };
77
77
  }
78
78
  if (runtimeRank > desiredRank) {
79
- // runtime > desired → 조용히 진행, effective만 상향
80
- return { effective: runtimeTrust, warning: null };
79
+ // runtime > desired → 에스컬레이션.
80
+ //
81
+ // Audit fix #3 (2026-04-21): 이전에는 `warning: null`로 조용히 진행했다.
82
+ // 사용자가 `가드레일 우선`을 선택했는데 runtime에서 `--dangerously-skip-
83
+ // permissions`가 주입되면 effective가 `완전 신뢰 실행`로 무경고 상승해
84
+ // audit 로그와 대시보드가 실제 실행 신뢰도와 어긋났다. 이제는 상승 이유를
85
+ // warning으로 반환해 session state에 기록하고 사용자에게 표시한다.
86
+ return {
87
+ effective: runtimeTrust,
88
+ warning: `Trust 상승: desired=${desired}, runtime=${runtimeTrust} (${runtime.permission_mode}) ` +
89
+ `— runtime 권한이 더 관대합니다. --dangerously-skip-permissions나 config가 이번 세션을 덮어썼습니다.`,
90
+ };
81
91
  }
82
92
  return { effective: desired, warning: null };
83
93
  }
@@ -7,11 +7,11 @@
7
7
  import * as fs from 'node:fs';
8
8
  import * as path from 'node:path';
9
9
  import * as crypto from 'node:crypto';
10
- import { V1_EVIDENCE_DIR } from '../core/paths.js';
10
+ import { ME_BEHAVIOR } from '../core/paths.js';
11
11
  import { atomicWriteJSON, safeReadJSON } from '../hooks/shared/atomic-write.js';
12
12
  import { createRule, saveRule, loadActiveRules } from './rule-store.js';
13
13
  function evidencePath(evidenceId) {
14
- return path.join(V1_EVIDENCE_DIR, `${evidenceId}.json`);
14
+ return path.join(ME_BEHAVIOR, `${evidenceId}.json`);
15
15
  }
16
16
  export function createEvidence(params) {
17
17
  return {
@@ -34,13 +34,13 @@ export function loadEvidence(evidenceId) {
34
34
  return safeReadJSON(evidencePath(evidenceId), null);
35
35
  }
36
36
  export function loadAllEvidence() {
37
- if (!fs.existsSync(V1_EVIDENCE_DIR))
37
+ if (!fs.existsSync(ME_BEHAVIOR))
38
38
  return [];
39
39
  const items = [];
40
- for (const file of fs.readdirSync(V1_EVIDENCE_DIR)) {
40
+ for (const file of fs.readdirSync(ME_BEHAVIOR)) {
41
41
  if (!file.endsWith('.json'))
42
42
  continue;
43
- const ev = safeReadJSON(path.join(V1_EVIDENCE_DIR, file), null);
43
+ const ev = safeReadJSON(path.join(ME_BEHAVIOR, file), null);
44
44
  if (ev)
45
45
  items.push(ev);
46
46
  }
@@ -7,6 +7,15 @@
7
7
  import type { Profile, QualityPack, AutonomyPack, JudgmentPack, CommunicationPack, TrustPolicy } from './types.js';
8
8
  export declare function createProfile(userId: string, qualityPack: QualityPack, autonomyPack: AutonomyPack, trustPolicy: TrustPolicy, trustSource: Profile['trust_preferences']['source'], judgmentPack?: JudgmentPack, communicationPack?: CommunicationPack): Profile;
9
9
  export declare function loadProfile(): Profile | null;
10
+ export declare function loadProfileRaw(): unknown;
10
11
  export declare function saveProfile(profile: Profile): void;
12
+ /**
13
+ * File existence probe. NOTE: this returns `true` even if the on-disk
14
+ * file is legacy/invalid — callers that need "valid v1 profile present"
15
+ * should combine this with `loadProfile() !== null`. The raw existence
16
+ * check is kept for bootstrap logic that explicitly differentiates
17
+ * "file exists but legacy" from "no file at all" (e.g. to decide
18
+ * whether to run `runLegacyCutover`).
19
+ */
11
20
  export declare function profileExists(): boolean;
12
21
  export declare function isV1Profile(data: unknown): data is Profile;
@@ -5,7 +5,7 @@
5
5
  * Authoritative schema: docs/plans/2026-04-03-forgen-data-model-storage-spec.md §2
6
6
  */
7
7
  import * as fs from 'node:fs';
8
- import { V1_PROFILE } from '../core/paths.js';
8
+ import { FORGE_PROFILE } from '../core/paths.js';
9
9
  import { atomicWriteJSON, safeReadJSON } from '../hooks/shared/atomic-write.js';
10
10
  import { qualityCentroid, autonomyCentroid, judgmentCentroid, communicationCentroid, } from '../preset/facet-catalog.js';
11
11
  const MODEL_VERSION = '2.0';
@@ -36,14 +36,35 @@ export function createProfile(userId, qualityPack, autonomyPack, trustPolicy, tr
36
36
  };
37
37
  }
38
38
  export function loadProfile() {
39
- return safeReadJSON(V1_PROFILE, null);
39
+ const raw = safeReadJSON(FORGE_PROFILE, null);
40
+ if (raw === null)
41
+ return null;
42
+ // Audit fix #6 (2026-04-21): 이전에는 disk 내용을 그대로 Profile로
43
+ // 타입 단언해 반환 → legacy-shaped JSON (model_version 없음 / 1.x / 잘못된 모양)
44
+ // 이 downstream으로 흘러들어가 facets/trust_preferences 접근 시 undefined
45
+ // 참조가 되었다. isV1Profile 가드를 통과한 경우에만 반환, 아니면 null로
46
+ // 취급하여 v1-bootstrap이 cutover 흐름을 재실행하게 한다.
47
+ if (!isV1Profile(raw))
48
+ return null;
49
+ return raw;
50
+ }
51
+ export function loadProfileRaw() {
52
+ return safeReadJSON(FORGE_PROFILE, null);
40
53
  }
41
54
  export function saveProfile(profile) {
42
55
  profile.metadata.updated_at = new Date().toISOString();
43
- atomicWriteJSON(V1_PROFILE, profile, { pretty: true });
56
+ atomicWriteJSON(FORGE_PROFILE, profile, { pretty: true });
44
57
  }
58
+ /**
59
+ * File existence probe. NOTE: this returns `true` even if the on-disk
60
+ * file is legacy/invalid — callers that need "valid v1 profile present"
61
+ * should combine this with `loadProfile() !== null`. The raw existence
62
+ * check is kept for bootstrap logic that explicitly differentiates
63
+ * "file exists but legacy" from "no file at all" (e.g. to decide
64
+ * whether to run `runLegacyCutover`).
65
+ */
45
66
  export function profileExists() {
46
- return fs.existsSync(V1_PROFILE);
67
+ return fs.existsSync(FORGE_PROFILE);
47
68
  }
48
69
  export function isV1Profile(data) {
49
70
  if (!data || typeof data !== 'object')
@@ -7,10 +7,10 @@
7
7
  import * as fs from 'node:fs';
8
8
  import * as path from 'node:path';
9
9
  import * as crypto from 'node:crypto';
10
- import { V1_RULES_DIR } from '../core/paths.js';
10
+ import { ME_RULES } from '../core/paths.js';
11
11
  import { atomicWriteJSON, safeReadJSON } from '../hooks/shared/atomic-write.js';
12
12
  function rulePath(ruleId) {
13
- return path.join(V1_RULES_DIR, `${ruleId}.json`);
13
+ return path.join(ME_RULES, `${ruleId}.json`);
14
14
  }
15
15
  export function createRule(params) {
16
16
  const now = new Date().toISOString();
@@ -37,13 +37,13 @@ export function loadRule(ruleId) {
37
37
  return safeReadJSON(rulePath(ruleId), null);
38
38
  }
39
39
  export function loadAllRules() {
40
- if (!fs.existsSync(V1_RULES_DIR))
40
+ if (!fs.existsSync(ME_RULES))
41
41
  return [];
42
42
  const rules = [];
43
- for (const file of fs.readdirSync(V1_RULES_DIR)) {
43
+ for (const file of fs.readdirSync(ME_RULES)) {
44
44
  if (!file.endsWith('.json'))
45
45
  continue;
46
- const rule = safeReadJSON(path.join(V1_RULES_DIR, file), null);
46
+ const rule = safeReadJSON(path.join(ME_RULES, file), null);
47
47
  if (rule)
48
48
  rules.push(rule);
49
49
  }
@@ -65,13 +65,13 @@ export function updateRuleStatus(ruleId, status) {
65
65
  * 이전 세션의 임시 규칙이 새 세션에서 영향을 미치지 않도록 정리.
66
66
  */
67
67
  export function cleanupStaleSessionRules(_currentSessionId) {
68
- if (!fs.existsSync(V1_RULES_DIR))
68
+ if (!fs.existsSync(ME_RULES))
69
69
  return 0;
70
70
  let cleaned = 0;
71
- for (const file of fs.readdirSync(V1_RULES_DIR)) {
71
+ for (const file of fs.readdirSync(ME_RULES)) {
72
72
  if (!file.endsWith('.json'))
73
73
  continue;
74
- const filePath = path.join(V1_RULES_DIR, file);
74
+ const filePath = path.join(ME_RULES, file);
75
75
  const rule = safeReadJSON(filePath, null);
76
76
  if (rule && rule.scope === 'session' && rule.status === 'active') {
77
77
  rule.status = 'suppressed';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wooojin/forgen",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
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": "5.1.2",
4
+ "version": "0.3.2",
5
5
  "description": "Claude Code harness — the more you use Claude, the better it gets",
6
6
  "author": {
7
7
  "name": "jang-ujin",
@@ -10,7 +10,12 @@
10
10
  "repository": "https://github.com/wooo-jin/forgen",
11
11
  "homepage": "https://github.com/wooo-jin/forgen",
12
12
  "license": "MIT",
13
- "keywords": ["claude-code", "harness", "personalization", "forge"],
13
+ "keywords": [
14
+ "claude-code",
15
+ "harness",
16
+ "personalization",
17
+ "forge"
18
+ ],
14
19
  "skills": "./skills/",
15
20
  "agents": "agents/",
16
21
  "statusLine": {