@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.
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +23 -0
- package/README.ja.md +15 -10
- package/README.ko.md +15 -10
- package/README.md +19 -14
- package/README.zh.md +13 -8
- package/dist/checks/dangerous-response-pattern.d.ts +2 -1
- package/dist/checks/dangerous-response-pattern.js +27 -3
- package/dist/cli.js +133 -17
- package/dist/core/auto-compound-runner.js +502 -397
- package/dist/core/block-cli.js +7 -3
- package/dist/core/compound-consent.d.ts +18 -0
- package/dist/core/compound-consent.js +101 -6
- package/dist/core/compound-sweep-cli.d.ts +16 -0
- package/dist/core/compound-sweep-cli.js +67 -5
- package/dist/core/config-hooks.js +28 -10
- package/dist/core/correction-signals.d.ts +9 -0
- package/dist/core/correction-signals.js +37 -0
- package/dist/core/dev-cli.d.ts +1 -2
- package/dist/core/dev-cli.js +9 -28
- package/dist/core/doctor-verify.d.ts +35 -0
- package/dist/core/doctor-verify.js +502 -0
- package/dist/core/doctor.d.ts +4 -6
- package/dist/core/doctor.js +103 -184
- package/dist/core/explain-cli.js +8 -0
- package/dist/core/extraction-haiku.d.ts +64 -0
- package/dist/core/extraction-haiku.js +208 -0
- package/dist/core/extraction-queue.d.ts +68 -0
- package/dist/core/extraction-queue.js +300 -0
- package/dist/core/flow-status.d.ts +93 -0
- package/dist/core/flow-status.js +368 -0
- package/dist/core/harness.js +14 -42
- package/dist/core/inspect-cli.js +37 -13
- package/dist/core/lifecycle-classifier.d.ts +5 -1
- package/dist/core/lifecycle-classifier.js +13 -2
- package/dist/core/migrate-cli.d.ts +1 -1
- package/dist/core/migrate-cli.js +11 -11
- package/dist/core/migrate-tenetx.d.ts +1 -1
- package/dist/core/migrate-tenetx.js +2 -2
- package/dist/core/node-engine.d.ts +3 -0
- package/dist/core/node-engine.js +8 -0
- package/dist/core/observability-store.d.ts +15 -0
- package/dist/core/observability-store.js +73 -0
- package/dist/core/paths.d.ts +2 -0
- package/dist/core/paths.js +2 -0
- package/dist/core/rendered-rules-manifest.d.ts +7 -1
- package/dist/core/rendered-rules-manifest.js +45 -1
- package/dist/core/session-store.d.ts +13 -11
- package/dist/core/session-store.js +103 -119
- package/dist/core/settings-injector.d.ts +5 -2
- package/dist/core/settings-injector.js +21 -88
- package/dist/core/spawn.d.ts +9 -1
- package/dist/core/spawn.js +33 -33
- package/dist/core/stats-cli.d.ts +7 -0
- package/dist/core/stats-cli.js +66 -93
- package/dist/core/status-cli.d.ts +1 -1
- package/dist/core/status-cli.js +23 -4
- package/dist/core/statusline-cli.js +5 -0
- package/dist/core/statusline-install.d.ts +10 -2
- package/dist/core/statusline-install.js +27 -4
- package/dist/core/transcript-summary.d.ts +84 -9
- package/dist/core/transcript-summary.js +283 -49
- package/dist/core/uninstall.d.ts +4 -0
- package/dist/core/uninstall.js +68 -36
- package/dist/core/v1-bootstrap.d.ts +1 -1
- package/dist/core/v1-bootstrap.js +38 -9
- package/dist/engine/acted-on-evidence.d.ts +8 -0
- package/dist/engine/acted-on-evidence.js +38 -0
- package/dist/engine/block-judge.d.ts +3 -1
- package/dist/engine/block-judge.js +4 -3
- package/dist/engine/compound-cli.d.ts +26 -2
- package/dist/engine/compound-cli.js +143 -19
- package/dist/engine/compound-lifecycle.d.ts +36 -2
- package/dist/engine/compound-lifecycle.js +131 -11
- package/dist/engine/compound-loop.d.ts +4 -0
- package/dist/engine/compound-loop.js +93 -18
- package/dist/engine/correction-cluster-runner.d.ts +11 -1
- package/dist/engine/correction-cluster-runner.js +39 -15
- package/dist/engine/correction-clustering.d.ts +11 -0
- package/dist/engine/correction-clustering.js +20 -3
- package/dist/engine/lifecycle/lifecycle-cli.js +10 -3
- package/dist/engine/lifecycle/meta-reclassifier.d.ts +9 -0
- package/dist/engine/lifecycle/meta-reclassifier.js +15 -3
- package/dist/engine/lifecycle/orchestrator.js +3 -2
- package/dist/engine/lifecycle/signals.d.ts +19 -1
- package/dist/engine/lifecycle/signals.js +61 -2
- package/dist/engine/lifecycle/trigger-t1-correction.d.ts +1 -1
- package/dist/engine/lifecycle/trigger-t1-correction.js +9 -28
- package/dist/engine/lifecycle/trigger-t5-conflict.d.ts +8 -0
- package/dist/engine/lifecycle/trigger-t5-conflict.js +60 -2
- package/dist/engine/roi-demotion.d.ts +11 -0
- package/dist/engine/roi-demotion.js +50 -8
- package/dist/engine/rule-detectability.d.ts +39 -0
- package/dist/engine/rule-detectability.js +66 -0
- package/dist/engine/rule-project-cli.d.ts +25 -0
- package/dist/engine/rule-project-cli.js +148 -0
- package/dist/engine/rule-recovery-cli.d.ts +21 -0
- package/dist/engine/rule-recovery-cli.js +265 -0
- package/dist/engine/rule-toggle-cli.d.ts +14 -2
- package/dist/engine/rule-toggle-cli.js +94 -6
- package/dist/engine/skill-promoter.d.ts +14 -8
- package/dist/engine/skill-promoter.js +57 -85
- package/dist/engine/solution-format.d.ts +26 -1
- package/dist/engine/solution-format.js +65 -3
- package/dist/engine/solution-habit.d.ts +1 -0
- package/dist/engine/solution-habit.js +22 -0
- package/dist/engine/solution-index.d.ts +5 -0
- package/dist/engine/solution-index.js +32 -0
- package/dist/engine/solution-matcher-eval.js +4 -4
- package/dist/engine/solution-matcher.js +15 -13
- package/dist/engine/solution-scope.d.ts +11 -0
- package/dist/engine/solution-scope.js +19 -0
- package/dist/engine/solution-writer.d.ts +3 -1
- package/dist/engine/solution-writer.js +3 -2
- package/dist/engine/term-normalizer.js +49 -0
- package/dist/fgx.js +1 -1
- package/dist/forge/cli.js +51 -8
- package/dist/forge/evidence-processor.js +6 -0
- package/dist/hooks/context-guard.d.ts +0 -22
- package/dist/hooks/context-guard.js +22 -55
- package/dist/hooks/context-usage.d.ts +21 -0
- package/dist/hooks/context-usage.js +103 -0
- package/dist/hooks/dangerous-patterns.json +1 -16
- package/dist/hooks/db-guard.d.ts +1 -1
- package/dist/hooks/db-guard.js +21 -30
- package/dist/hooks/hook-config.d.ts +2 -0
- package/dist/hooks/hook-config.js +5 -1
- package/dist/hooks/hooks-generator.d.ts +4 -0
- package/dist/hooks/hooks-generator.js +10 -4
- package/dist/hooks/permission-handler.js +23 -3
- package/dist/hooks/post-tool-use.js +14 -10
- package/dist/hooks/pre-tool-use.d.ts +17 -3
- package/dist/hooks/pre-tool-use.js +143 -30
- package/dist/hooks/rate-limiter.js +12 -7
- package/dist/hooks/secret-filter.js +15 -4
- package/dist/hooks/session-end.d.ts +2 -2
- package/dist/hooks/session-end.js +13 -7
- package/dist/hooks/session-recovery.js +79 -50
- package/dist/hooks/shared/command-analyzer.d.ts +45 -0
- package/dist/hooks/shared/command-analyzer.js +972 -0
- package/dist/hooks/shared/command-parser.d.ts +5 -29
- package/dist/hooks/shared/command-parser.js +65 -35
- package/dist/hooks/shared/commit-guard.d.ts +15 -0
- package/dist/hooks/shared/commit-guard.js +176 -0
- package/dist/hooks/shared/hook-response.d.ts +6 -0
- package/dist/hooks/shared/hook-response.js +12 -0
- package/dist/hooks/shared/hook-timing.js +9 -3
- package/dist/hooks/shared/injection-caps.d.ts +32 -2
- package/dist/hooks/shared/injection-caps.js +73 -2
- package/dist/hooks/shared/is-main.d.ts +8 -0
- package/dist/hooks/shared/is-main.js +20 -0
- package/dist/hooks/shared/stop-triggers.d.ts +1 -1
- package/dist/hooks/shared/stop-triggers.js +2 -1
- package/dist/hooks/shared/tool-response.d.ts +6 -0
- package/dist/hooks/shared/tool-response.js +30 -0
- package/dist/hooks/slop-detector.js +6 -3
- package/dist/hooks/solution-injector.d.ts +23 -0
- package/dist/hooks/solution-injector.js +102 -101
- package/dist/hooks/stop-guard.d.ts +11 -1
- package/dist/hooks/stop-guard.js +28 -11
- package/dist/hooks/subagent-stop-guard.js +2 -1
- package/dist/hooks/subagent-tracker.js +2 -1
- package/dist/host/capabilities-codex.js +1 -0
- package/dist/host/claude-shim.d.ts +24 -0
- package/dist/host/claude-shim.js +68 -0
- package/dist/host/codex-hook-shim.d.ts +3 -1
- package/dist/host/codex-hook-shim.js +7 -5
- package/dist/host/codex-notify.js +1 -1
- package/dist/host/codex-rules-context.d.ts +6 -4
- package/dist/host/codex-rules-context.js +11 -24
- package/dist/host/exec-host.d.ts +5 -1
- package/dist/host/exec-host.js +15 -4
- package/dist/host/install-claude.d.ts +47 -14
- package/dist/host/install-claude.js +302 -155
- package/dist/host/install-codex.d.ts +20 -0
- package/dist/host/install-codex.js +32 -1
- package/dist/host/install-opencode.d.ts +3 -1
- package/dist/host/install-opencode.js +6 -3
- package/dist/host/install-orchestrator.js +14 -1
- package/dist/host/opencode/translate.d.ts +1 -1
- package/dist/host/opencode/translate.js +5 -3
- package/dist/host/projection.d.ts +9 -1
- package/dist/host/projection.js +19 -2
- package/dist/mcp/server.js +5 -0
- package/dist/mcp/solution-reader.d.ts +5 -5
- package/dist/mcp/solution-reader.js +13 -35
- package/dist/mcp/tools.js +18 -1
- package/dist/renderer/inspect-renderer.js +4 -2
- package/dist/renderer/render-report.d.ts +22 -0
- package/dist/renderer/render-report.js +29 -0
- package/dist/renderer/rule-renderer.d.ts +28 -2
- package/dist/renderer/rule-renderer.js +91 -76
- package/dist/store/evidence-store.js +34 -6
- package/dist/store/rule-lifecycle.d.ts +3 -1
- package/dist/store/rule-lifecycle.js +10 -0
- package/dist/store/rule-scope.d.ts +7 -0
- package/dist/store/rule-scope.js +54 -0
- package/dist/store/rule-store.d.ts +29 -3
- package/dist/store/rule-store.js +110 -26
- package/dist/store/types.d.ts +22 -2
- package/dist/way/cli.d.ts +1 -0
- package/dist/way/cli.js +313 -0
- package/dist/way/compile.d.ts +22 -0
- package/dist/way/compile.js +408 -0
- package/dist/way/conflict.d.ts +2 -0
- package/dist/way/conflict.js +18 -0
- package/dist/way/draft.d.ts +43 -0
- package/dist/way/draft.js +335 -0
- package/dist/way/extract.d.ts +17 -0
- package/dist/way/extract.js +172 -0
- package/dist/way/io.d.ts +79 -0
- package/dist/way/io.js +425 -0
- package/dist/way/similar.d.ts +2 -0
- package/dist/way/similar.js +30 -0
- package/dist/way/types.d.ts +98 -0
- package/dist/way/types.js +2 -0
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/scripts/postinstall.js +78 -900
- package/dist/core/health-cli.d.ts +0 -25
- package/dist/core/health-cli.js +0 -90
- package/dist/host/parity-harness.d.ts +0 -70
- package/dist/host/parity-harness.js +0 -287
|
@@ -1,18 +1,3 @@
|
|
|
1
1
|
[
|
|
2
|
-
{ "pattern": "
|
|
3
|
-
{ "pattern": "rm\\s+(-rf|-fr)\\s+\\.\\s", "description": "rm -rf on current directory", "severity": "block" },
|
|
4
|
-
{ "pattern": "git\\s+push\\s+.*--force(?!-)", "description": "git push --force", "severity": "warn" },
|
|
5
|
-
{ "pattern": "git\\s+reset\\s+--hard", "description": "git reset --hard", "severity": "warn" },
|
|
6
|
-
{ "pattern": "git\\s+clean\\s+-[a-z]*f", "description": "git clean -f", "severity": "warn" },
|
|
7
|
-
{ "pattern": "drop\\s+(?:table|database)", "description": "DROP TABLE/DATABASE", "severity": "block", "flags": "i" },
|
|
8
|
-
{ "pattern": "truncate\\s+table", "description": "TRUNCATE TABLE", "severity": "warn", "flags": "i" },
|
|
9
|
-
{ "pattern": ">\\s*\\/dev\\/sd[a-z]", "description": "write to block device", "severity": "block" },
|
|
10
|
-
{ "pattern": "mkfs\\s", "description": "mkfs (format filesystem)", "severity": "block" },
|
|
11
|
-
{ "pattern": ":\\(\\)\\s*\\{\\s*:\\|:&\\s*\\}\\s*;:", "description": "fork bomb", "severity": "block" },
|
|
12
|
-
{ "pattern": "\\beval\\s+[\"'`]", "description": "eval with string (injection risk)", "severity": "warn", "match_target": "raw" },
|
|
13
|
-
{ "pattern": "curl\\s+.*\\|\\s*(ba)?sh", "description": "curl pipe to shell", "severity": "block" },
|
|
14
|
-
{ "pattern": "wget\\s+.*\\|\\s*(ba)?sh", "description": "wget pipe to shell", "severity": "block" },
|
|
15
|
-
{ "pattern": "python[23]?\\s+-c\\s+['\"].*(?:import\\s+os|subprocess|exec|eval)", "description": "python -c with dangerous imports", "severity": "warn", "match_target": "raw" },
|
|
16
|
-
{ "pattern": "\\bchmod\\s+[0-7]*777\\b", "description": "chmod 777 (overly permissive)", "severity": "warn" },
|
|
17
|
-
{ "pattern": "\\bdd\\s+.*of=\\/dev\\/", "description": "dd write to device", "severity": "block" }
|
|
2
|
+
{ "pattern": ":\\(\\)\\s*\\{\\s*:\\|:&\\s*\\}\\s*;:", "description": "fork bomb", "severity": "block" }
|
|
18
3
|
]
|
package/dist/hooks/db-guard.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface SqlPattern {
|
|
|
11
11
|
}
|
|
12
12
|
export declare const DANGEROUS_SQL_PATTERNS: SqlPattern[];
|
|
13
13
|
/** SQL 명령어 위험도 검사 (순수 함수) */
|
|
14
|
-
export declare function checkDangerousSql(toolName: string, toolInput: Record<string, unknown> | string): {
|
|
14
|
+
export declare function checkDangerousSql(toolName: string, toolInput: Record<string, unknown> | string, cwd?: string): {
|
|
15
15
|
action: 'block' | 'warn' | 'pass';
|
|
16
16
|
description?: string;
|
|
17
17
|
};
|
package/dist/hooks/db-guard.js
CHANGED
|
@@ -11,7 +11,7 @@ import { atomicWriteJSON } from './shared/atomic-write.js';
|
|
|
11
11
|
import { isHookEnabled } from './hook-config.js';
|
|
12
12
|
import { approve, approveWithWarning, denyOrObserve, failOpenWithTracking } from './shared/hook-response.js';
|
|
13
13
|
import { STATE_DIR } from '../core/paths.js';
|
|
14
|
-
import {
|
|
14
|
+
import { analyzeCommand } from './shared/command-analyzer.js';
|
|
15
15
|
const FAIL_COUNTER_PATH = path.join(STATE_DIR, 'db-guard-fail-counter.json');
|
|
16
16
|
const FAIL_CLOSE_THRESHOLD = 3;
|
|
17
17
|
export const DANGEROUS_SQL_PATTERNS = [
|
|
@@ -22,39 +22,30 @@ export const DANGEROUS_SQL_PATTERNS = [
|
|
|
22
22
|
{ pattern: /UPDATE\s+\w+\s+SET/i, description: 'UPDATE SET (WHERE clause required)', severity: 'warn' },
|
|
23
23
|
];
|
|
24
24
|
/** SQL 명령어 위험도 검사 (순수 함수) */
|
|
25
|
-
export function checkDangerousSql(toolName, toolInput) {
|
|
25
|
+
export function checkDangerousSql(toolName, toolInput, cwd) {
|
|
26
26
|
if (toolName !== 'Bash')
|
|
27
27
|
return { action: 'pass' };
|
|
28
28
|
const command = typeof toolInput === 'string'
|
|
29
29
|
? toolInput
|
|
30
30
|
: (toolInput.command ?? '');
|
|
31
|
-
//
|
|
32
|
-
//
|
|
33
|
-
//
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
.replace(/\/\*[\s\S]*?\*\//g, ''); // 블록 주석 제거
|
|
50
|
-
for (const { pattern, description, severity } of DANGEROUS_SQL_PATTERNS) {
|
|
51
|
-
if (pattern.test(sqlWithoutComments)) {
|
|
52
|
-
// DELETE/UPDATE — SQL 본문에서 WHERE 절이 있으면 통과
|
|
53
|
-
if (/DELETE\s+FROM/i.test(sqlWithoutComments) && /\bWHERE\s+/i.test(sqlWithoutComments))
|
|
54
|
-
continue;
|
|
55
|
-
if (/UPDATE\s+\w+\s+SET/i.test(sqlWithoutComments) && /\bWHERE\s+/i.test(sqlWithoutComments))
|
|
56
|
-
continue;
|
|
57
|
-
return { action: severity, description };
|
|
31
|
+
// D12-A: 같은 파서(command-analyzer)가 "SQL 로 실행될 수 있는 텍스트"만 골라준다 —
|
|
32
|
+
// DB CLI(psql/mysql/sqlite3/…)의 인자·heredoc·`echo … | psql` 입력, python/node -c 코드.
|
|
33
|
+
// `grep "DROP TABLE" f`, `echo DROP TABLE`, `git commit -m "…DROP TABLE…"` 은 실행 문맥이 아니라 통과한다.
|
|
34
|
+
const { sqlTexts } = analyzeCommand(command, { cwd: typeof cwd === 'string' ? cwd : undefined });
|
|
35
|
+
for (const text of sqlTexts) {
|
|
36
|
+
// 주석 제거 후 SQL에 대해 패턴 매칭 (주석 안 키워드 오차단 방지)
|
|
37
|
+
const sqlWithoutComments = text
|
|
38
|
+
.replace(/--[^\n]*/g, '') // 라인 주석 제거
|
|
39
|
+
.replace(/\/\*[\s\S]*?\*\//g, ''); // 블록 주석 제거
|
|
40
|
+
for (const { pattern, description, severity } of DANGEROUS_SQL_PATTERNS) {
|
|
41
|
+
if (pattern.test(sqlWithoutComments)) {
|
|
42
|
+
// DELETE/UPDATE — SQL 본문에서 WHERE 절이 있으면 통과
|
|
43
|
+
if (/DELETE\s+FROM/i.test(sqlWithoutComments) && /\bWHERE\s+/i.test(sqlWithoutComments))
|
|
44
|
+
continue;
|
|
45
|
+
if (/UPDATE\s+\w+\s+SET/i.test(sqlWithoutComments) && /\bWHERE\s+/i.test(sqlWithoutComments))
|
|
46
|
+
continue;
|
|
47
|
+
return { action: severity, description };
|
|
48
|
+
}
|
|
58
49
|
}
|
|
59
50
|
}
|
|
60
51
|
return { action: 'pass' };
|
|
@@ -104,7 +95,7 @@ async function main() {
|
|
|
104
95
|
}
|
|
105
96
|
const toolName = data.tool_name ?? data.toolName ?? '';
|
|
106
97
|
const toolInput = data.tool_input ?? data.toolInput ?? {};
|
|
107
|
-
const check = checkDangerousSql(toolName, toolInput);
|
|
98
|
+
const check = checkDangerousSql(toolName, toolInput, data.cwd);
|
|
108
99
|
if (check.action === 'block') {
|
|
109
100
|
console.log(denyOrObserve('db-guard', `[Forgen] Dangerous SQL blocked: ${check.description}`));
|
|
110
101
|
return;
|
|
@@ -25,6 +25,8 @@
|
|
|
25
25
|
*/
|
|
26
26
|
/** 훅 설정 파일의 전체 구조 타입 */
|
|
27
27
|
export type HookConfig = Record<string, unknown>;
|
|
28
|
+
/** FORGEN_NESTED_RUN=1 이어도 꺼지지 않는 위험 차단 훅. */
|
|
29
|
+
export declare const NESTED_SAFETY_HOOKS: ReadonlySet<string>;
|
|
28
30
|
/** 테스트/진단용: 보호된 훅 이름 집합 스냅샷. */
|
|
29
31
|
export declare function getProtectedHookNames(): string[];
|
|
30
32
|
/**
|
|
@@ -42,6 +42,8 @@ const HOOK_TIER_MAP = Object.fromEntries(HOOK_REGISTRY.map(h => [h.name, h.tier]
|
|
|
42
42
|
const PROTECTED_HOOKS = new Set(HOOK_REGISTRY
|
|
43
43
|
.filter(h => h.tier === 'compound-core' || h.compoundCritical === true)
|
|
44
44
|
.map(h => h.name));
|
|
45
|
+
/** FORGEN_NESTED_RUN=1 이어도 꺼지지 않는 위험 차단 훅. */
|
|
46
|
+
export const NESTED_SAFETY_HOOKS = new Set(['db-guard', 'secret-filter', 'pre-tool-use']);
|
|
45
47
|
/** 테스트/진단용: 보호된 훅 이름 집합 스냅샷. */
|
|
46
48
|
export function getProtectedHookNames() {
|
|
47
49
|
return [...PROTECTED_HOOKS].sort();
|
|
@@ -149,7 +151,9 @@ export function isHookEnabled(hookName) {
|
|
|
149
151
|
// -1) ADR-015 C-G1: forgen 자신이 띄운 중첩 `claude -p` 추출 실행 안에서는 모든 훅을 끈다.
|
|
150
152
|
// (--bare 는 OAuth 를 끊어 쓸 수 없음.) 이전엔 추출 run 마다 22개 훅이 재귀 발화해
|
|
151
153
|
// hook-timing / sessions / usage-telemetry 를 오염시키고 auto-compound 연쇄를 유발했다.
|
|
152
|
-
|
|
154
|
+
// D12-D: 학습·주입 훅만 끈다. 위험 차단 훅(NESTED_SAFETY_HOOKS)은 중첩 실행에서도 유지 —
|
|
155
|
+
// 중첩 호출이 위험 명령을 실행할 수 있다면 보호막이 가장 필요한 곳이기 때문이다.
|
|
156
|
+
if (process.env.FORGEN_NESTED_RUN === '1' && !NESTED_SAFETY_HOOKS.has(hookName))
|
|
153
157
|
return false;
|
|
154
158
|
// 0) compound-core 가드레일 — config 어떤 경로로도 끌 수 없음
|
|
155
159
|
if (PROTECTED_HOOKS.has(hookName))
|
|
@@ -38,7 +38,11 @@ interface GenerateOptions {
|
|
|
38
38
|
* 배포(prepack), 테스트 결정론, runtime 환경 분리에 사용.
|
|
39
39
|
*/
|
|
40
40
|
releaseMode?: boolean;
|
|
41
|
+
/** 고정 shim 경로(claude). 있으면 명령을 `"<shim>" "hooks/x.js" args` 로 만든다 — node·패키지 경로 비의존. */
|
|
42
|
+
shimPath?: string;
|
|
41
43
|
}
|
|
44
|
+
/** Claude Code 는 hook 을 sh 로 실행한다. 큰따옴표 안에서 확장되는 문자도 이스케이프한다. */
|
|
45
|
+
export declare function quoteArg(raw: string): string;
|
|
42
46
|
/**
|
|
43
47
|
* 활성 훅만 포함한 hooks.json 객체를 생성합니다.
|
|
44
48
|
*
|
|
@@ -20,12 +20,18 @@ function splitCommand(raw) {
|
|
|
20
20
|
const unquoted = tokens.map(token => token.replace(/^"/, '').replace(/"$/, ''));
|
|
21
21
|
return { script: unquoted[0] ?? '', args: unquoted.slice(1) };
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
/** Claude Code 는 hook 을 sh 로 실행한다. 큰따옴표 안에서 확장되는 문자도 이스케이프한다. */
|
|
24
|
+
export function quoteArg(raw) {
|
|
25
|
+
if (process.platform === 'win32')
|
|
26
|
+
return `"${raw.replace(/"/g, '\\"')}"`;
|
|
27
|
+
return `"${raw.replace(/([\\"$`])/g, '\\$1')}"`;
|
|
25
28
|
}
|
|
26
|
-
function buildHookCommand(pluginRoot, rawScript, runtime) {
|
|
29
|
+
function buildHookCommand(pluginRoot, rawScript, runtime, shimPath) {
|
|
27
30
|
const { script, args } = splitCommand(rawScript);
|
|
28
31
|
const quotedArgs = args.map(quoteArg).join(' ');
|
|
32
|
+
if (shimPath && runtime === 'claude') {
|
|
33
|
+
return `${quoteArg(shimPath)} ${quoteArg(script)}${quotedArgs ? ` ${quotedArgs}` : ''}`;
|
|
34
|
+
}
|
|
29
35
|
// Phase 2: host-runtime 위임 — Codex 표면 (codex-adapter 경유) 을 core 가 모르도록.
|
|
30
36
|
return getHostRuntime(runtime).wrapHookCommand(pluginRoot, script, quotedArgs);
|
|
31
37
|
}
|
|
@@ -91,7 +97,7 @@ export function generateHooksJson(options) {
|
|
|
91
97
|
hooks[event] = [...byMatcher.entries()].map(([matcher, matcherEntries]) => ({
|
|
92
98
|
matcher,
|
|
93
99
|
hooks: matcherEntries.map(h => {
|
|
94
|
-
const command = buildHookCommand(pluginRoot, h.script, runtime);
|
|
100
|
+
const command = buildHookCommand(pluginRoot, h.script, runtime, options?.shimPath);
|
|
95
101
|
const handler = { type: 'command', command, timeout: h.timeout };
|
|
96
102
|
if (runtime === 'codex' && typeof h.codex?.additionalContextLimit === 'number') {
|
|
97
103
|
handler.additionalContextLimit = h.codex.additionalContextLimit;
|
|
@@ -15,6 +15,7 @@ import { sanitizeId } from './shared/sanitize-id.js';
|
|
|
15
15
|
import { isHookEnabled } from './hook-config.js';
|
|
16
16
|
import { approve, approveWithWarning, failOpenWithTracking } from './shared/hook-response.js';
|
|
17
17
|
import { STATE_DIR } from '../core/paths.js';
|
|
18
|
+
import { analyzeCommand, worstFinding } from './shared/command-analyzer.js';
|
|
18
19
|
/** 자동 승인 가능한 안전 도구 목록 */
|
|
19
20
|
export const SAFE_TOOLS = new Set([
|
|
20
21
|
'Read', 'Glob', 'Grep', 'WebSearch', 'WebFetch',
|
|
@@ -43,14 +44,15 @@ export function classifyTool(toolName, isAutopilot) {
|
|
|
43
44
|
return 'autopilot-pass-through';
|
|
44
45
|
}
|
|
45
46
|
/** autopilot 모드 활성 여부 확인 */
|
|
46
|
-
function isAutopilotActive() {
|
|
47
|
+
function isAutopilotActive(sessionId) {
|
|
47
48
|
const modes = ['autopilot', 'ralph', 'ultrawork'];
|
|
48
49
|
for (const mode of modes) {
|
|
49
50
|
const statePath = path.join(STATE_DIR, `${mode}-state.json`);
|
|
50
51
|
try {
|
|
51
52
|
if (fs.existsSync(statePath)) {
|
|
52
53
|
const data = JSON.parse(fs.readFileSync(statePath, 'utf-8'));
|
|
53
|
-
|
|
54
|
+
// H6: 다른 세션의 autopilot 상태가 이 세션의 권한 흐름에 새지 않게 세션 범위로 한정
|
|
55
|
+
if (data.active && data.sessionId === sessionId)
|
|
54
56
|
return true;
|
|
55
57
|
}
|
|
56
58
|
}
|
|
@@ -88,6 +90,24 @@ async function main() {
|
|
|
88
90
|
}
|
|
89
91
|
const toolName = data.tool_name ?? data.toolName ?? '';
|
|
90
92
|
const sessionId = data.session_id ?? 'default';
|
|
93
|
+
// H11: 이전엔 문구(systemMessage)만 내고 결정을 내리지 않았다. 되돌릴 수 없는 위험 명령(root/home 삭제, mkfs 등)은
|
|
94
|
+
// 권한 요청 단계에서도 실제로 거부 결정을 낸다. 그 외는 Claude 기본 권한 흐름(대화상자)에 맡긴다.
|
|
95
|
+
if (toolName === 'Bash') {
|
|
96
|
+
const toolInput = data.tool_input ?? data.toolInput ?? {};
|
|
97
|
+
const command = typeof toolInput.command === 'string' ? toolInput.command : '';
|
|
98
|
+
const worst = worstFinding(analyzeCommand(command, { cwd: data.cwd }).findings);
|
|
99
|
+
if (worst && (worst.action === 'block' || worst.action === 'deny')) {
|
|
100
|
+
logPermissionRequest(sessionId, toolName, 'deny');
|
|
101
|
+
console.log(JSON.stringify({
|
|
102
|
+
continue: true,
|
|
103
|
+
hookSpecificOutput: {
|
|
104
|
+
hookEventName: 'PermissionRequest',
|
|
105
|
+
decision: { behavior: 'deny', message: `[Forgen] Dangerous command denied: ${worst.description}` },
|
|
106
|
+
},
|
|
107
|
+
}));
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
91
111
|
// Audit note #4 (2026-04-21): `approve()` / `approveWithWarning()` 둘 다
|
|
92
112
|
// Claude Code hook protocol에서 `permissionDecision: 'allow'`를 설정하지
|
|
93
113
|
// 않는다. 따라서 본 훅은 실제로 도구 실행을 "승인(force-allow)"하지 않고,
|
|
@@ -103,7 +123,7 @@ async function main() {
|
|
|
103
123
|
return;
|
|
104
124
|
}
|
|
105
125
|
// autopilot 모드가 아니면 기본 동작 (Claude Code 기본 권한 흐름)
|
|
106
|
-
if (!isAutopilotActive()) {
|
|
126
|
+
if (!isAutopilotActive(sessionId)) {
|
|
107
127
|
logPermissionRequest(sessionId, toolName, 'pass-through');
|
|
108
128
|
console.log(approve());
|
|
109
129
|
return;
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import * as fs from 'node:fs';
|
|
9
9
|
import * as path from 'node:path';
|
|
10
|
+
import { actedOnEvidence } from '../engine/acted-on-evidence.js';
|
|
10
11
|
import { createLogger } from '../core/logger.js';
|
|
11
12
|
const log = createLogger('post-tool-use');
|
|
12
13
|
import { readStdinJSON } from './shared/read-stdin.js';
|
|
@@ -24,7 +25,7 @@ import { appendImplicitFeedback } from '../store/implicit-feedback-store.js';
|
|
|
24
25
|
// ADR-010 W2-2: usage-telemetry 기록 제거 — native /usage 이관. (hot path I/O 절감)
|
|
25
26
|
import { emitSolutionEvent, querySurfacedWithin } from '../core/observability-store.js';
|
|
26
27
|
import { parseSolutionV3 } from '../engine/solution-format.js';
|
|
27
|
-
import {
|
|
28
|
+
import { defaultSolutionDirs } from '../engine/solution-index.js';
|
|
28
29
|
// 2026-10-07: 20→60 — critic 룰의 실행 증거 판정(stop-guard tool_evidence)이 'critic 실행 → 수정 수십 회 → 커밋' 흐름에서
|
|
29
30
|
// critic 호출이 창 밖으로 밀려 오탐하지 않도록. 측정 도구 집계는 끝에서 세므로 영향 없음.
|
|
30
31
|
const RECENT_TOOL_NAMES_WINDOW = 60;
|
|
@@ -283,13 +284,13 @@ async function main() {
|
|
|
283
284
|
})() || toolResponse;
|
|
284
285
|
if (target) {
|
|
285
286
|
try {
|
|
286
|
-
const [{
|
|
287
|
+
const [{ loadEnforcedRules }, { recordViolation, matchedFragment }, { compileSafeRegex, safeRegexTest }, { preprocessForMatch },] = await Promise.all([
|
|
287
288
|
import('../store/rule-store.js'),
|
|
288
289
|
import('../engine/lifecycle/signals.js'),
|
|
289
290
|
import('./shared/safe-regex.js'),
|
|
290
291
|
import('./shared/command-parser.js'),
|
|
291
292
|
]);
|
|
292
|
-
const rules =
|
|
293
|
+
const rules = loadEnforcedRules(typeof data.cwd === 'string' ? data.cwd : undefined);
|
|
293
294
|
// Mech-A pattern_match dispatcher — match_target 은 **rule-per-rule**.
|
|
294
295
|
// AWS key / DROP 류 secret/dangerous SQL 은 파일 content 에 들어있어도
|
|
295
296
|
// 실제 leak 이라 raw 검사가 맞고, rm -rf 류 shell 명령은 quote 안 본문이면
|
|
@@ -348,14 +349,17 @@ async function main() {
|
|
|
348
349
|
try {
|
|
349
350
|
const recentSurfaces = querySurfacedWithin(sessionId, 5);
|
|
350
351
|
if (recentSurfaces.length > 0 && toolName) {
|
|
351
|
-
const
|
|
352
|
+
const actionText = [toolInput.file_path, toolInput.filePath, toolInput.command, toolInput.content, toolInput.new_string, toolInput.pattern]
|
|
353
|
+
.filter((v) => typeof v === 'string').join('\n').slice(0, 20_000);
|
|
352
354
|
const seen = new Set();
|
|
353
355
|
for (const surf of recentSurfaces) {
|
|
354
356
|
if (seen.has(surf.solutionId))
|
|
355
357
|
continue;
|
|
356
358
|
seen.add(surf.solutionId);
|
|
357
|
-
|
|
358
|
-
|
|
359
|
+
// 주입기와 같은 목록(me + 설치된 팩 + cwd 프로젝트)에서 찾는다. me 만 읽으면 팩·프로젝트 솔루션은 영원히 acted_on 이 없다.
|
|
360
|
+
const filePath = defaultSolutionDirs(typeof data.cwd === 'string' ? data.cwd : undefined)
|
|
361
|
+
.map((d) => path.join(d.dir, `${surf.solutionId}.md`)).find((f) => fs.existsSync(f));
|
|
362
|
+
if (!filePath)
|
|
359
363
|
continue;
|
|
360
364
|
let raw;
|
|
361
365
|
try {
|
|
@@ -371,9 +375,9 @@ async function main() {
|
|
|
371
375
|
const identifiers = sol.frontmatter.identifiers ?? [];
|
|
372
376
|
if (tags.length === 0 && identifiers.length === 0)
|
|
373
377
|
continue;
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
if (!
|
|
378
|
+
// 도구 **이름**이 아니라 도구가 실제로 건드린 것(파일 경로·명령·쓴 내용)에서 증거를 찾는다. 증거 기준은 acted-on-evidence.ts.
|
|
379
|
+
const ev = actedOnEvidence({ tags, identifiers }, actionText);
|
|
380
|
+
if (!ev.ok)
|
|
377
381
|
continue;
|
|
378
382
|
emitSolutionEvent({
|
|
379
383
|
sessionId,
|
|
@@ -381,7 +385,7 @@ async function main() {
|
|
|
381
385
|
eventType: 'acted_on',
|
|
382
386
|
signalSource: 'tool-pattern',
|
|
383
387
|
signalScore: 0.30,
|
|
384
|
-
meta: { tool: toolName, surface_ts: surf.ts },
|
|
388
|
+
meta: { tool: toolName, surface_ts: surf.ts, evidence: ev.hits.slice(0, 4) },
|
|
385
389
|
});
|
|
386
390
|
}
|
|
387
391
|
}
|
|
@@ -20,11 +20,25 @@ interface DangerousPatternEntry {
|
|
|
20
20
|
}
|
|
21
21
|
/** 위험 Bash 명령어 패턴 (패키지 내장 + 사용자 커스텀 병합) */
|
|
22
22
|
export declare const DANGEROUS_PATTERNS: DangerousPatternEntry[];
|
|
23
|
-
/**
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
/**
|
|
24
|
+
* 위험 명령어 검사 (순수 함수).
|
|
25
|
+
*
|
|
26
|
+
* D12-A: 명령 문자열 전체에 정규식을 대던 방식을 버리고 command-analyzer 의 실제 파싱 결과를 쓴다.
|
|
27
|
+
* - block: 되돌릴 수 없는 파괴(루트/홈 재귀 삭제, mkfs, 장치 쓰기, 다운로드→셸) — 항상 차단
|
|
28
|
+
* - ask : 기본 룰 "사용자 확인 없는 rm -rf 금지" — 임시(claude-*) 경로가 아닌 재귀 삭제는 확인을 요청
|
|
29
|
+
* - warn : 정책 유지(git reset --hard, git clean -f, force push, chmod 777, eval)
|
|
30
|
+
* 정규식 테이블(dangerous-patterns.json + 사용자 커스텀)은 파서가 모르는 잔여 패턴(fork bomb 등)에만 쓴다.
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* ask 응답 문구 꼬리 — 비대화형(`claude -p`, CI)에서는 승인해 줄 사람이 없다. 호스트가 ask 를 지원하지 않아
|
|
34
|
+
* deny 로 투영되는 경우(Codex/OpenCode)에도 같은 안내가 사유에 실려 간다.
|
|
35
|
+
*/
|
|
36
|
+
export declare const ASK_NONINTERACTIVE_HINT = "\uBE44\uB300\uD654\uD615(claude -p/CI)\uC774\uBA74 \uC2B9\uC778\uD560 \uC0AC\uB78C\uC774 \uC5C6\uC2B5\uB2C8\uB2E4 \u2014 \uC758\uB3C4\uD55C \uC791\uC5C5\uC774\uBA74 FORGEN_USER_CONFIRMED=1 \uC744 \uC124\uC815\uD574 \uB2E4\uC2DC \uC2E4\uD589\uD558\uC138\uC694 (\uC6B0\uD68C\uB294 violations.jsonl \uC5D0 \uAE30\uB85D\uB428).";
|
|
37
|
+
export declare function checkDangerousCommand(toolName: string, toolInput: Record<string, unknown> | string, cwd?: string): {
|
|
38
|
+
action: 'block' | 'ask' | 'warn' | 'pass';
|
|
26
39
|
description?: string;
|
|
27
40
|
command?: string;
|
|
41
|
+
ruleId?: string;
|
|
28
42
|
};
|
|
29
43
|
/** 카운터 기반 리마인더 표시 여부 판정 (순수 함수 — I/O 없음) */
|
|
30
44
|
export declare function shouldShowReminder(count: number, interval?: number): boolean;
|