@wooojin/forgen 0.6.7 → 0.6.9

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 (223) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +23 -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 +143 -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 +176 -0
  145. package/dist/hooks/shared/hook-response.d.ts +6 -0
  146. package/dist/hooks/shared/hook-response.js +12 -0
  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/stop-triggers.d.ts +1 -1
  153. package/dist/hooks/shared/stop-triggers.js +2 -1
  154. package/dist/hooks/shared/tool-response.d.ts +6 -0
  155. package/dist/hooks/shared/tool-response.js +30 -0
  156. package/dist/hooks/slop-detector.js +6 -3
  157. package/dist/hooks/solution-injector.d.ts +23 -0
  158. package/dist/hooks/solution-injector.js +102 -101
  159. package/dist/hooks/stop-guard.d.ts +11 -1
  160. package/dist/hooks/stop-guard.js +28 -11
  161. package/dist/hooks/subagent-stop-guard.js +2 -1
  162. package/dist/hooks/subagent-tracker.js +2 -1
  163. package/dist/host/capabilities-codex.js +1 -0
  164. package/dist/host/claude-shim.d.ts +24 -0
  165. package/dist/host/claude-shim.js +68 -0
  166. package/dist/host/codex-hook-shim.d.ts +3 -1
  167. package/dist/host/codex-hook-shim.js +7 -5
  168. package/dist/host/codex-notify.js +1 -1
  169. package/dist/host/codex-rules-context.d.ts +6 -4
  170. package/dist/host/codex-rules-context.js +11 -24
  171. package/dist/host/exec-host.d.ts +5 -1
  172. package/dist/host/exec-host.js +15 -4
  173. package/dist/host/install-claude.d.ts +47 -14
  174. package/dist/host/install-claude.js +302 -155
  175. package/dist/host/install-codex.d.ts +20 -0
  176. package/dist/host/install-codex.js +32 -1
  177. package/dist/host/install-opencode.d.ts +3 -1
  178. package/dist/host/install-opencode.js +6 -3
  179. package/dist/host/install-orchestrator.js +14 -1
  180. package/dist/host/opencode/translate.d.ts +1 -1
  181. package/dist/host/opencode/translate.js +5 -3
  182. package/dist/host/projection.d.ts +9 -1
  183. package/dist/host/projection.js +19 -2
  184. package/dist/mcp/server.js +5 -0
  185. package/dist/mcp/solution-reader.d.ts +5 -5
  186. package/dist/mcp/solution-reader.js +13 -35
  187. package/dist/mcp/tools.js +18 -1
  188. package/dist/renderer/inspect-renderer.js +4 -2
  189. package/dist/renderer/render-report.d.ts +22 -0
  190. package/dist/renderer/render-report.js +29 -0
  191. package/dist/renderer/rule-renderer.d.ts +28 -2
  192. package/dist/renderer/rule-renderer.js +91 -76
  193. package/dist/store/evidence-store.js +34 -6
  194. package/dist/store/rule-lifecycle.d.ts +3 -1
  195. package/dist/store/rule-lifecycle.js +10 -0
  196. package/dist/store/rule-scope.d.ts +7 -0
  197. package/dist/store/rule-scope.js +54 -0
  198. package/dist/store/rule-store.d.ts +29 -3
  199. package/dist/store/rule-store.js +110 -26
  200. package/dist/store/types.d.ts +22 -2
  201. package/dist/way/cli.d.ts +1 -0
  202. package/dist/way/cli.js +313 -0
  203. package/dist/way/compile.d.ts +22 -0
  204. package/dist/way/compile.js +408 -0
  205. package/dist/way/conflict.d.ts +2 -0
  206. package/dist/way/conflict.js +18 -0
  207. package/dist/way/draft.d.ts +43 -0
  208. package/dist/way/draft.js +335 -0
  209. package/dist/way/extract.d.ts +17 -0
  210. package/dist/way/extract.js +172 -0
  211. package/dist/way/io.d.ts +79 -0
  212. package/dist/way/io.js +425 -0
  213. package/dist/way/similar.d.ts +2 -0
  214. package/dist/way/similar.js +30 -0
  215. package/dist/way/types.d.ts +98 -0
  216. package/dist/way/types.js +2 -0
  217. package/package.json +1 -1
  218. package/plugin.json +1 -1
  219. package/scripts/postinstall.js +78 -900
  220. package/dist/core/health-cli.d.ts +0 -25
  221. package/dist/core/health-cli.js +0 -90
  222. package/dist/host/parity-harness.d.ts +0 -70
  223. package/dist/host/parity-harness.js +0 -287
@@ -15,7 +15,7 @@ const log = createLogger('session-recovery');
15
15
  import { atomicWriteJSON } from './shared/atomic-write.js';
16
16
  import { sanitizeId } from './shared/sanitize-id.js';
17
17
  import { isHookEnabled } from './hook-config.js';
18
- import { approve, approveWithContext, failOpenWithTracking } from './shared/hook-response.js';
18
+ import { approve, approveWithContext, approveWithWarning, failOpenWithTracking } from './shared/hook-response.js';
19
19
  import { HANDOFFS_DIR, STATE_DIR } from '../core/paths.js';
20
20
  import { recordHookTiming } from './shared/hook-timing.js';
21
21
  /** 체크포인트 저장 */
@@ -153,25 +153,28 @@ async function main() {
153
153
  // 이전엔 prepareHarness (fgx/forgen wrapper) 만 호출 → 직접 claude/codex 호출 시
154
154
  // ~/.forgen/state/sessions/<id>.json 미생성. SessionStart hook 에서도 호출하여
155
155
  // 양쪽 진입 경로 모두에서 session state 박제.
156
+ // doctor 프로브(FORGEN_DOCTOR_PROBE=1): 세션 상태 기록·백그라운드 스폰 등 부작용 경로를 건너뛴다.
157
+ const doctorProbe = process.env.FORGEN_DOCTOR_PROBE === '1';
156
158
  let v1RenderedRules = null;
157
159
  try {
160
+ if (doctorProbe)
161
+ throw new Error('doctor probe — 세션 상태 기록 생략');
158
162
  const { bootstrapV1Session } = await import('../core/v1-bootstrap.js');
159
- v1RenderedRules = bootstrapV1Session().renderedRules;
163
+ v1RenderedRules = bootstrapV1Session(sessionContext.cwd).renderedRules;
160
164
  }
161
165
  catch (e) {
162
166
  log.debug('v1-bootstrap SessionStart 호출 실패 (fail-open)', e);
163
167
  }
164
- // ADR-014 D1 — Codex 에는 .claude/rules/ 로드 표면이 없으므로 같은 룰을 SessionStart
165
- // additionalContext 로 주입한다 (Claude 세션은 파일 경로로 이미 로드되므로 skip).
166
- const codexRulesBlock = await (async () => {
168
+ // 모든 호스트가 같은 경로로 룰을 받는다(ADR-014 D1 확장). 래퍼 없이 실행해도 매 세션 최신 룰이 들어간다.
169
+ const rulesBlock = await (async () => {
167
170
  try {
168
- const { isCodexRuntime, buildCodexRulesContext } = await import('../host/codex-rules-context.js');
169
- if (!isCodexRuntime())
170
- return null;
171
- return await buildCodexRulesContext(sessionContext.cwd, v1RenderedRules);
171
+ const { isCodexRuntime, buildRulesContext } = await import('../host/codex-rules-context.js');
172
+ const { reclaimRenderedRuleFiles } = await import('../core/rendered-rules-manifest.js');
173
+ reclaimRenderedRuleFiles(sessionContext.cwd);
174
+ return await buildRulesContext(sessionContext.cwd, v1RenderedRules, isCodexRuntime() ? 'codex' : 'claude');
172
175
  }
173
176
  catch (e) {
174
- log.debug('codex rules inject 실패 (fail-open)', e);
177
+ log.debug('rules block 생성 실패 (fail-open)', e);
175
178
  return null;
176
179
  }
177
180
  })();
@@ -194,6 +197,13 @@ async function main() {
194
197
  const state = parsed;
195
198
  if (!state.active)
196
199
  continue;
200
+ // H6: 키워드로 켜진 모드 상태는 그 세션의 것이다. 다른 세션(새 세션)에 "이전 세션에서 복구됨"으로 주입하면
201
+ // 오너가 요청하지 않은 autopilot/ralph 지시가 새 세션을 지배한다. resume/compact 는 같은 session_id 를 쓰므로
202
+ // 같은 세션일 때만 복구하고, sessionId 가 없거나 다르면 건너뛴다.
203
+ if (!state.sessionId || state.sessionId !== sessionContext.sessionId) {
204
+ log.debug(`${mode} 상태는 다른 세션(${state.sessionId ?? 'unknown'}) 소유 — 복구 주입 생략`);
205
+ continue;
206
+ }
197
207
  // 24시간 이상 경과한 상태는 만료
198
208
  const startedAt = new Date(state.startedAt).getTime();
199
209
  const elapsed = Date.now() - startedAt;
@@ -369,42 +379,48 @@ async function main() {
369
379
  .filter(f => f.endsWith('.jsonl') && f !== `${sessionId}.jsonl`) // 현재 세션 제외
370
380
  .map(f => ({ name: f, mtime: fs.statSync(path.join(projectDir, f)).mtimeMs }))
371
381
  .sort((a, b) => b.mtime - a.mtime);
372
- if (transcripts.length > 0) {
373
- const prevTranscript = path.join(projectDir, transcripts[0].name);
374
- const lastCompoundPath = path.join(STATE_DIR, 'last-auto-compound.json');
375
- let lastCompoundedSession = '';
382
+ // D9: 직전 1개만 보던 단일 슬롯 판정 대신, 최근 7일 안의 미처리/자란 transcript 를 최대 3개까지 전수 확인한다.
383
+ // 처리 여부는 세션별 러너 기록(sessionNeedsRun: 마지막 실행 이후 transcript 크기)으로 판정 — 길이 게이트 없음.
384
+ // 러너는 승급·인덱싱이 멱등이고 Haiku 는 새 구간만 읽으므로 중복 비용이 없다.
385
+ const { sessionNeedsRun, transcriptSignature } = await import('../core/extraction-queue.js');
386
+ const WEEK_MS = 7 * 24 * 60 * 60 * 1000;
387
+ let spawned = 0;
388
+ for (const t of transcripts) {
389
+ if (spawned >= 3 || doctorProbe)
390
+ break;
391
+ if (Date.now() - t.mtime > WEEK_MS)
392
+ break; // mtime 내림차순 — 이후는 더 오래됨
393
+ const prevTranscript = path.join(projectDir, t.name);
394
+ const prevSessionId = t.name.replace('.jsonl', '');
395
+ let size = 0;
376
396
  try {
377
- lastCompoundedSession = JSON.parse(fs.readFileSync(lastCompoundPath, 'utf-8')).sessionId ?? '';
397
+ size = fs.statSync(prevTranscript).size;
378
398
  }
379
- catch { /* first time */ }
380
- const prevSessionId = transcripts[0].name.replace('.jsonl', '');
381
- if (prevSessionId !== lastCompoundedSession) {
382
- // 이전 세션이 compound 안 된 상태 — 메시지 수 확인
383
- // W-D2: 대용량 transcript 보호 — 앞 200KB만 읽어 메시지 수 추정
384
- const fd = fs.openSync(prevTranscript, 'r');
385
- const buf = Buffer.alloc(200 * 1024);
386
- const bytesRead = fs.readSync(fd, buf, 0, buf.length, 0);
387
- fs.closeSync(fd);
388
- const content = buf.toString('utf-8', 0, bytesRead);
389
- const userMsgCount = content.split('\n')
390
- .filter(l => { try {
391
- const t = JSON.parse(l).type;
392
- return t === 'user' || t === 'queue-operation';
393
- }
394
- catch {
395
- return false;
396
- } })
397
- .length;
398
- if (userMsgCount >= 10) {
399
- // background로 auto-compound 실행 (hook timeout과 무관)
400
- const { spawn: spawnProcess } = await import('node:child_process');
401
- const autoCompound = spawnProcess('node', [
402
- path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'core', 'auto-compound-runner.js'),
403
- cwd, prevTranscript, prevSessionId,
404
- ], { detached: true, stdio: 'ignore' });
405
- autoCompound.unref();
406
- log.debug(`이전 세션 auto-compound 시작: ${prevSessionId} (${userMsgCount} messages)`);
407
- }
399
+ catch {
400
+ continue;
401
+ }
402
+ if (size === 0 || !sessionNeedsRun(prevSessionId, size, { sig: transcriptSignature(prevTranscript) }))
403
+ continue;
404
+ const { spawn: spawnProcess } = await import('node:child_process');
405
+ const autoCompound = spawnProcess(process.execPath, [
406
+ path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'core', 'auto-compound-runner.js'),
407
+ cwd, prevTranscript, prevSessionId, '0', 'final',
408
+ ], { detached: true, stdio: 'ignore' });
409
+ autoCompound.unref();
410
+ spawned++;
411
+ log.debug(`이전 세션 auto-compound 시작: ${prevSessionId}`);
412
+ }
413
+ // D4: 새로 처리할 세션이 없어도 대기열(타임아웃·실패로 밀린 추출)에 기한이 된 항목이 있으면 재시도 러너를 띄운다.
414
+ if (spawned === 0 && !doctorProbe) {
415
+ const { readQueue } = await import('../core/extraction-queue.js');
416
+ const now = Date.now();
417
+ if (readQueue().some((e) => e.nextAt <= now && (e.claimedUntil ?? 0) <= now)) {
418
+ const { spawn: spawnProcess } = await import('node:child_process');
419
+ const q = spawnProcess(process.execPath, [
420
+ path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'core', 'auto-compound-runner.js'),
421
+ cwd, '-', 'queue-retry',
422
+ ], { detached: true, stdio: 'ignore' });
423
+ q.unref();
408
424
  }
409
425
  }
410
426
  }
@@ -425,7 +441,7 @@ async function main() {
425
441
  }
426
442
  }
427
443
  catch { /* last-lifecycle.json parse failure — run lifecycle check anyway */ }
428
- if (shouldRun) {
444
+ if (shouldRun && !doctorProbe) {
429
445
  // B-4: detached background spawn — hook timeout 초과 방지.
430
446
  //
431
447
  // Audit fix #5 (2026-04-21): prior invocation interpolated
@@ -438,7 +454,7 @@ async function main() {
438
454
  // no shell, no eval, no interpolation.
439
455
  const runnerPath = path.join(path.dirname(fileURLToPath(import.meta.url)), 'internal', 'run-lifecycle-check.js');
440
456
  const { spawn: spawnLifecycle } = await import('node:child_process');
441
- const lifecycleRunner = spawnLifecycle('node', [runnerPath, sessionId], {
457
+ const lifecycleRunner = spawnLifecycle(process.execPath, [runnerPath, sessionId], {
442
458
  detached: true,
443
459
  stdio: 'ignore',
444
460
  });
@@ -450,10 +466,23 @@ async function main() {
450
466
  catch (e) {
451
467
  log.debug('lifecycle check 실패', e);
452
468
  }
453
- if (codexRulesBlock)
454
- recoveryMessages.unshift(codexRulesBlock);
455
- if (recoveryMessages.length > 0) {
456
- console.log(approveWithContext(recoveryMessages.join('\n\n'), 'SessionStart'));
469
+ // D2: 최초 1회 Haiku 전송 안내 / 호출 불가 사유 — 사용자 화면(systemMessage)에 보인다.
470
+ let haikuNotice = null;
471
+ if (!doctorProbe) {
472
+ try {
473
+ const { takeSessionStartNotice } = await import('../core/compound-consent.js');
474
+ haikuNotice = await takeSessionStartNotice();
475
+ }
476
+ catch (e) {
477
+ log.debug('Haiku 안내 생성 실패', e);
478
+ }
479
+ }
480
+ if (rulesBlock || recoveryMessages.length > 0) {
481
+ const { fitSessionContext } = await import('./shared/injection-caps.js');
482
+ console.log(approveWithContext(fitSessionContext(rulesBlock, recoveryMessages), 'SessionStart', haikuNotice ?? undefined));
483
+ }
484
+ else if (haikuNotice) {
485
+ console.log(approveWithWarning(haikuNotice));
457
486
  }
458
487
  else {
459
488
  console.log(approve());
@@ -0,0 +1,45 @@
1
+ export type FindingAction = 'block' | 'deny' | 'ask' | 'warn';
2
+ export interface CommandFinding {
3
+ id: string;
4
+ action: FindingAction;
5
+ description: string;
6
+ targets?: string[];
7
+ }
8
+ export interface GitOp {
9
+ sub: string;
10
+ args: string[];
11
+ /** `git -C <dir>` 값 (있으면). */
12
+ dir?: string;
13
+ /** 문장 시점의 cwd (같은 명령 안 `cd` 반영). */
14
+ cwd: string;
15
+ }
16
+ export interface AnalysisResult {
17
+ findings: CommandFinding[];
18
+ /** git add/commit/push 호출 — commit-guard 가 실제 staged 내용을 확인하는 데 쓴다. */
19
+ gitOps: GitOp[];
20
+ /** SQL 로 실행될 수 있는 텍스트(DB CLI 인자·heredoc·파이프 입력, python/node -c 코드). */
21
+ sqlTexts: string[];
22
+ }
23
+ export interface AnalyzeOptions {
24
+ cwd?: string;
25
+ home?: string;
26
+ }
27
+ interface Word {
28
+ text: string;
29
+ quoted: boolean;
30
+ dynamic: boolean;
31
+ }
32
+ /** 입력 길이 상한 — 초과는 분석하지 않고 ask (fail-open 금지). pre-tool-use 의 정규식 경로도 같은 상한을 쓴다. */
33
+ export declare const MAX_COMMAND_LENGTH = 50000;
34
+ interface Stmt {
35
+ words: Word[];
36
+ sepBefore: string;
37
+ heredocs: string[];
38
+ subs: string[];
39
+ procSubs: string[];
40
+ hereStrings: Word[];
41
+ }
42
+ export declare function tokenize(src: string): Stmt[];
43
+ export declare function analyzeCommand(cmd: string, opts?: AnalyzeOptions): AnalysisResult;
44
+ export declare function worstFinding(findings: CommandFinding[]): CommandFinding | undefined;
45
+ export {};