@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.
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +27 -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 +145 -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 +177 -0
- package/dist/hooks/shared/hook-response.d.ts +12 -2
- package/dist/hooks/shared/hook-response.js +19 -3
- 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/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 +76 -899
- 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
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
function specDetectable(spec) {
|
|
2
|
+
const v = spec.verifier;
|
|
3
|
+
if (!v)
|
|
4
|
+
return false; // drift_key 만 있는 spec
|
|
5
|
+
switch (v.kind) {
|
|
6
|
+
case 'tool_arg_regex': return String(v.params?.pattern ?? '').length > 0;
|
|
7
|
+
case 'artifact_check': return String(v.params?.path ?? '').length > 0;
|
|
8
|
+
case 'tool_evidence':
|
|
9
|
+
case 'language_ratio': return true;
|
|
10
|
+
case 'self_check_prompt': return typeof v.params?.evidence_path === 'string' && v.params.evidence_path.length > 0;
|
|
11
|
+
default: return false;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 옛 분류기는 본문에 없는 증거 파일(e2e-result.json 등)을 게이트로 붙였다. 그런 게이트는 어떤 사용자에게든
|
|
16
|
+
* 모든 완료 보고를 막으므로 평가하지 않는다. 룰 파일을 고치는 마이그레이션 없이 모든 설치에 적용된다.
|
|
17
|
+
*/
|
|
18
|
+
export function artifactGateIsStale(rule, spec) {
|
|
19
|
+
if (spec.verifier?.kind !== 'artifact_check')
|
|
20
|
+
return false;
|
|
21
|
+
const file = String(spec.verifier.params?.path ?? '').split(/[\\/]/).pop() ?? '';
|
|
22
|
+
// 디렉터리·패턴처럼 구체적 파일명이 아니면 판정할 근거가 없다. 차단을 풀지 않는다.
|
|
23
|
+
if (!file || /[*?[\]{}]/.test(file))
|
|
24
|
+
return false;
|
|
25
|
+
return !`${rule.trigger ?? ''}\n${rule.policy}`.includes(file);
|
|
26
|
+
}
|
|
27
|
+
export function enforceability(rule) {
|
|
28
|
+
return (rule.enforce_via ?? []).some(specDetectable) ? 'detectable' : 'advisory';
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* 의미 룰 차단 정책 (2026-11-05 오너 결정): 키워드로 발동하는 self_check 는 실데이터 정밀도가 약 0.10 이라
|
|
32
|
+
* 기본은 주입과 기록만 한다. 차단은 (1) 사용자가 `forgen rule enforce` 로 켠 룰(enforce_mode 'block'),
|
|
33
|
+
* (2) 결정적 탐지기가 있는 spec, (3) hard 룰(ADR-002: advise 로 내릴 수 없음)에만 적용한다.
|
|
34
|
+
* 명시 enforce_mode 가 항상 우선한다.
|
|
35
|
+
*/
|
|
36
|
+
export function effectiveEnforceMode(rule, spec) {
|
|
37
|
+
if (rule.enforce_mode)
|
|
38
|
+
return rule.enforce_mode;
|
|
39
|
+
if (rule.strength === 'hard' || specDetectable(spec))
|
|
40
|
+
return 'block';
|
|
41
|
+
return 'advise';
|
|
42
|
+
}
|
|
43
|
+
/** 이 룰의 Stop spec 이 위반 시 실제로 차단하는가. Stop spec 이 없으면 false. */
|
|
44
|
+
export function stopBlocks(rule) {
|
|
45
|
+
return (rule.enforce_via ?? []).some((s) => s.hook === 'Stop' && !!s.verifier && !artifactGateIsStale(rule, s) && effectiveEnforceMode(rule, s) === 'block');
|
|
46
|
+
}
|
|
47
|
+
/** 표시용: 위반 시 실제로 막는 룰인가. Stop 은 차단 정책을, 나머지 hook 은 결정적 탐지기와 advise 여부를 본다. */
|
|
48
|
+
export function ruleEnforced(rule) {
|
|
49
|
+
return (rule.enforce_via ?? []).some((s) => {
|
|
50
|
+
if (!s.verifier || artifactGateIsStale(rule, s))
|
|
51
|
+
return false;
|
|
52
|
+
return s.hook === 'Stop' ? effectiveEnforceMode(rule, s) === 'block' : specDetectable(s) && rule.enforce_mode !== 'advise';
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/** 표시용 한 단어. */
|
|
56
|
+
export function enforceabilityLabel(rule) {
|
|
57
|
+
return enforceability(rule) === 'detectable' ? '탐지' : '자문';
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* 주제 게이트는 "의미를 코드가 못 읽는" self_check 에만 적용한다 — 결정적 탐지기(언어 비율·도구 증거 등)는 그대로.
|
|
61
|
+
* communication 룰(답변 언어·형식·길이)은 모든 응답에 적용되는 문체 규칙이라 주제로 거르면 안 된다:
|
|
62
|
+
* "영어로 답하지 말 것" 은 영어 응답(= 위반)에서 룰 용어가 하나도 안 나온다.
|
|
63
|
+
*/
|
|
64
|
+
export function topicGateApplies(kind, category) {
|
|
65
|
+
return kind === 'self_check_prompt' && category !== 'communication';
|
|
66
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Rule } from '../store/types.js';
|
|
2
|
+
export declare function setRuleProject(prefix: string, projects: string[] | null): Rule;
|
|
3
|
+
export declare function planProjectClassification(project: string, keywords: string[]): Rule[];
|
|
4
|
+
export declare function handleSetProject(args: string[]): void;
|
|
5
|
+
export declare function handleClassifyProjects(args: string[]): void;
|
|
6
|
+
export interface PackImportPlan {
|
|
7
|
+
rules: Array<{
|
|
8
|
+
file: string;
|
|
9
|
+
policy: string;
|
|
10
|
+
renderKey: string;
|
|
11
|
+
exists: boolean;
|
|
12
|
+
}>;
|
|
13
|
+
solutions: Array<{
|
|
14
|
+
file: string;
|
|
15
|
+
exists: boolean;
|
|
16
|
+
valid: boolean;
|
|
17
|
+
}>;
|
|
18
|
+
notImported: string[];
|
|
19
|
+
}
|
|
20
|
+
export declare function planPackImport(pack: string): PackImportPlan;
|
|
21
|
+
export declare function applyPackImport(pack: string, project: string): {
|
|
22
|
+
rules: number;
|
|
23
|
+
solutions: number;
|
|
24
|
+
};
|
|
25
|
+
export declare function handleImportPack(args: string[]): void;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 룰 프로젝트 범위 관리와 팩 가져오기.
|
|
3
|
+
* forgen rule set-project <id|prefix> <프로젝트키> | --global
|
|
4
|
+
* forgen rule classify-projects --project <키> --keywords a,b,c [--apply] 기본은 미리보기
|
|
5
|
+
* forgen rule import-pack <팩이름> [--project <키>] [--apply] 기본은 미리보기
|
|
6
|
+
*/
|
|
7
|
+
import * as fs from 'node:fs';
|
|
8
|
+
import { mutateSolutionFile } from './solution-writer.js';
|
|
9
|
+
import * as path from 'node:path';
|
|
10
|
+
import { ME_SOLUTIONS, PACKS_DIR } from '../core/paths.js';
|
|
11
|
+
import { createRule, findRuleByRenderKey, loadAllRules, saveRule } from '../store/rule-store.js';
|
|
12
|
+
function option(args, name) {
|
|
13
|
+
const i = args.indexOf(name);
|
|
14
|
+
return i >= 0 ? args[i + 1] : undefined;
|
|
15
|
+
}
|
|
16
|
+
function fail(message) {
|
|
17
|
+
console.error(`✗ [forgen] ${message}`);
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
export function setRuleProject(prefix, projects) {
|
|
21
|
+
const matches = loadAllRules().filter((r) => r.rule_id.startsWith(prefix));
|
|
22
|
+
if (matches.length !== 1)
|
|
23
|
+
throw new Error(matches.length ? `ambiguous prefix "${prefix}"` : `no rule matching "${prefix}"`);
|
|
24
|
+
// hard 룰은 안전장치다. 프로젝트로 좁히면 다른 곳에서 차단이 꺼진다.
|
|
25
|
+
if (projects && matches[0].strength === 'hard')
|
|
26
|
+
throw new Error(`hard rule ${matches[0].rule_id} must stay global`);
|
|
27
|
+
const next = { ...matches[0] };
|
|
28
|
+
if (projects)
|
|
29
|
+
next.projects = projects;
|
|
30
|
+
else
|
|
31
|
+
delete next.projects;
|
|
32
|
+
saveRule(next);
|
|
33
|
+
return next;
|
|
34
|
+
}
|
|
35
|
+
export function planProjectClassification(project, keywords) {
|
|
36
|
+
const lower = keywords.map((k) => k.toLowerCase());
|
|
37
|
+
return loadAllRules().filter((r) => r.status === 'active' && r.strength !== 'hard' && !r.projects?.length
|
|
38
|
+
&& lower.some((k) => r.policy.toLowerCase().includes(k)));
|
|
39
|
+
}
|
|
40
|
+
export function handleSetProject(args) {
|
|
41
|
+
const prefix = args[0];
|
|
42
|
+
const target = args[1];
|
|
43
|
+
if (!prefix || !target)
|
|
44
|
+
fail('usage: forgen rule set-project <id|prefix> <프로젝트키> | --global');
|
|
45
|
+
try {
|
|
46
|
+
const rule = setRuleProject(prefix, target === '--global' ? null : [target.toLowerCase()]);
|
|
47
|
+
console.log(`✓ [forgen] ${rule.rule_id.slice(0, 8)} → ${rule.projects?.join(',') ?? '전역'}`);
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
fail(e instanceof Error ? e.message : String(e));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export function handleClassifyProjects(args) {
|
|
54
|
+
const project = option(args, '--project')?.toLowerCase();
|
|
55
|
+
const keywords = option(args, '--keywords')?.split(',').map((k) => k.trim()).filter(Boolean);
|
|
56
|
+
if (!project || !keywords?.length)
|
|
57
|
+
fail('usage: forgen rule classify-projects --project <키> --keywords a,b [--apply]');
|
|
58
|
+
const plan = planProjectClassification(project, keywords);
|
|
59
|
+
for (const r of plan)
|
|
60
|
+
console.log(` ${r.rule_id.slice(0, 8)} [${r.strength}] ${r.policy.slice(0, 70)}`);
|
|
61
|
+
if (!args.includes('--apply')) {
|
|
62
|
+
console.log(`미리보기: ${plan.length}개를 ${project} 전용으로 바꿉니다. --apply 로 적용`);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
for (const r of plan)
|
|
66
|
+
saveRule({ ...r, projects: [project] });
|
|
67
|
+
console.log(`✓ [forgen] ${plan.length}개를 ${project} 전용으로 변경`);
|
|
68
|
+
}
|
|
69
|
+
function packRulePolicy(raw) {
|
|
70
|
+
return raw
|
|
71
|
+
.split('\n')
|
|
72
|
+
.filter((l) => !/^#\s/.test(l) && !/^>\s*(Type|Scope|Classification|Created):/.test(l))
|
|
73
|
+
.join('\n')
|
|
74
|
+
.trim();
|
|
75
|
+
}
|
|
76
|
+
export function planPackImport(pack) {
|
|
77
|
+
const root = path.join(PACKS_DIR, pack);
|
|
78
|
+
if (pack !== path.basename(pack) || !fs.existsSync(root))
|
|
79
|
+
throw new Error(`pack not found: ${pack}`);
|
|
80
|
+
const list = (d) => {
|
|
81
|
+
const dir = path.join(root, d);
|
|
82
|
+
return fs.existsSync(dir) ? fs.readdirSync(dir).filter((n) => n.endsWith('.md')) : [];
|
|
83
|
+
};
|
|
84
|
+
const rules = list('rules').map((file) => {
|
|
85
|
+
const policy = packRulePolicy(fs.readFileSync(path.join(root, 'rules', file), 'utf-8'));
|
|
86
|
+
const renderKey = `pack.${pack}.${file.replace(/\.md$/, '')}`;
|
|
87
|
+
return { file, policy, renderKey, exists: findRuleByRenderKey(renderKey) !== null };
|
|
88
|
+
}).filter((r) => r.policy.length > 0);
|
|
89
|
+
const solutions = list('solutions').map((file) => ({
|
|
90
|
+
file,
|
|
91
|
+
exists: fs.existsSync(path.join(ME_SOLUTIONS, file)),
|
|
92
|
+
valid: fs.readFileSync(path.join(root, 'solutions', file), 'utf-8').trimStart().startsWith('---'),
|
|
93
|
+
}));
|
|
94
|
+
const notImported = ['skills', 'agents', 'workflows', 'manuals', 'atoms']
|
|
95
|
+
.flatMap((d) => list(d).map((f) => `${d}/${f}`));
|
|
96
|
+
return { rules, solutions, notImported };
|
|
97
|
+
}
|
|
98
|
+
export function applyPackImport(pack, project) {
|
|
99
|
+
const plan = planPackImport(pack);
|
|
100
|
+
let rules = 0;
|
|
101
|
+
for (const r of plan.rules) {
|
|
102
|
+
if (r.exists)
|
|
103
|
+
continue;
|
|
104
|
+
saveRule(createRule({
|
|
105
|
+
category: 'workflow', scope: 'me', trigger: r.file.replace(/\.md$/, ''), policy: r.policy,
|
|
106
|
+
strength: 'default', source: 'onboarding', render_key: r.renderKey, projects: [project],
|
|
107
|
+
}));
|
|
108
|
+
rules++;
|
|
109
|
+
}
|
|
110
|
+
let solutions = 0;
|
|
111
|
+
fs.mkdirSync(ME_SOLUTIONS, { recursive: true });
|
|
112
|
+
for (const s of plan.solutions) {
|
|
113
|
+
if (s.exists || !s.valid)
|
|
114
|
+
continue;
|
|
115
|
+
const dest = path.join(ME_SOLUTIONS, s.file);
|
|
116
|
+
fs.copyFileSync(path.join(PACKS_DIR, pack, 'solutions', s.file), dest);
|
|
117
|
+
// 룰과 같은 프로젝트 키를 솔루션에도 남긴다 — 다른 프로젝트 안에서는 매칭되지 않고, 밖에서는 가중치만 낮다.
|
|
118
|
+
mutateSolutionFile(dest, (sol) => { sol.frontmatter.projects = [project]; return true; });
|
|
119
|
+
solutions++;
|
|
120
|
+
}
|
|
121
|
+
return { rules, solutions };
|
|
122
|
+
}
|
|
123
|
+
export function handleImportPack(args) {
|
|
124
|
+
const pack = args.find((a, i) => !a.startsWith('--') && args[i - 1] !== '--project');
|
|
125
|
+
if (!pack)
|
|
126
|
+
fail('usage: forgen rule import-pack <팩이름> [--project <키>] [--apply]');
|
|
127
|
+
const project = (option(args, '--project') ?? pack).toLowerCase();
|
|
128
|
+
try {
|
|
129
|
+
const plan = planPackImport(pack);
|
|
130
|
+
const newRules = plan.rules.filter((r) => !r.exists).length;
|
|
131
|
+
const newSolutions = plan.solutions.filter((s) => !s.exists && s.valid).length;
|
|
132
|
+
const broken = plan.solutions.filter((s) => !s.valid).map((s) => s.file);
|
|
133
|
+
console.log(`룰 ${newRules}개(프로젝트 ${project}), 솔루션 ${newSolutions}개`);
|
|
134
|
+
if (broken.length)
|
|
135
|
+
console.log(`형식 오류로 건너뜀(맨 앞에 YAML frontmatter 필요): ${broken.join(', ')}`);
|
|
136
|
+
if (plan.notImported.length)
|
|
137
|
+
console.log(`룰·솔루션이 아니라 가져오지 않음 ${plan.notImported.length}개: ${plan.notImported.slice(0, 8).join(', ')}`);
|
|
138
|
+
if (!args.includes('--apply')) {
|
|
139
|
+
console.log('미리보기입니다. --apply 로 적용');
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const done = applyPackImport(pack, project);
|
|
143
|
+
console.log(`✓ [forgen] 가져옴: 룰 ${done.rules}개, 솔루션 ${done.solutions}개`);
|
|
144
|
+
}
|
|
145
|
+
catch (e) {
|
|
146
|
+
fail(e instanceof Error ? e.message : String(e));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Evidence, Rule } from '../store/types.js';
|
|
2
|
+
export declare function reviveRule(prefix: string, reason: string): Rule;
|
|
3
|
+
export declare function createSnapshot(label?: string, nowIso?: string): string;
|
|
4
|
+
export declare function restoreSnapshot(name: string): {
|
|
5
|
+
safety: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function handleRuleRevive(args: string[]): void;
|
|
8
|
+
export declare function handleRuleSnapshot(): void;
|
|
9
|
+
export declare function handleRuleRestore(args: string[]): void;
|
|
10
|
+
export interface LostCorrection {
|
|
11
|
+
evidence: Evidence;
|
|
12
|
+
rule: Rule | null;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 사용자가 직접 한 교정 중 활성 룰로 남지 못한 것. 예전 버전의 세션 정리·승급 실패로 사라진 교정을
|
|
16
|
+
* 업그레이드한 사용자가 스스로 찾아 복구할 수 있게 한다. 같은 문장은 최신 1건만.
|
|
17
|
+
* 제외: fix-now(원래 세션 한정), 사용자가 직접 끈 룰, 병합돼 대표 룰이 살아 있는 룰.
|
|
18
|
+
*/
|
|
19
|
+
export declare function findLostCorrections(): LostCorrection[];
|
|
20
|
+
export declare function recoverCorrection(lost: LostCorrection, projects?: string[]): Rule;
|
|
21
|
+
export declare function handleRuleRecover(args: string[]): void;
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 룰 복구 수단.
|
|
3
|
+
* forgen rule revive <id|prefix> [--reason "..."] 비활성·보관 룰을 영구 활성 룰로 되살린다
|
|
4
|
+
* forgen rule recover [--apply <id...>] [--project <키>] 활성 룰로 남지 못한 내 교정을 찾아 복구
|
|
5
|
+
* forgen rule snapshot 룰·교정·솔루션 스냅샷
|
|
6
|
+
* forgen rule restore <이름> --yes 스냅샷으로 되돌림(직전 상태를 먼저 스냅샷)
|
|
7
|
+
*/
|
|
8
|
+
import * as fs from 'node:fs';
|
|
9
|
+
import * as path from 'node:path';
|
|
10
|
+
import { FORGEN_HOME, ME_DIR, ME_RULES, ME_RULES_ARCHIVE } from '../core/paths.js';
|
|
11
|
+
import { atomicWriteJSON, safeReadJSON } from '../hooks/shared/atomic-write.js';
|
|
12
|
+
import { withStatusChange } from '../store/rule-lifecycle.js';
|
|
13
|
+
import { createRule, saveRule } from '../store/rule-store.js';
|
|
14
|
+
import { loadEvidenceByType } from '../store/evidence-store.js';
|
|
15
|
+
import { applyProposal, classify } from './enforce-classifier.js';
|
|
16
|
+
const SNAPSHOT_ROOT = path.join(FORGEN_HOME, 'backups');
|
|
17
|
+
const SNAPSHOT_DIRS = ['rules', 'rules-archive', 'behavior', 'solutions'];
|
|
18
|
+
function candidates(prefix) {
|
|
19
|
+
const out = [];
|
|
20
|
+
for (const [dir, archived] of [[ME_RULES, false], [ME_RULES_ARCHIVE, true]]) {
|
|
21
|
+
if (!fs.existsSync(dir))
|
|
22
|
+
continue;
|
|
23
|
+
for (const name of fs.readdirSync(dir)) {
|
|
24
|
+
if (!name.endsWith('.json') || !name.startsWith(prefix))
|
|
25
|
+
continue;
|
|
26
|
+
const file = path.join(dir, name);
|
|
27
|
+
const rule = safeReadJSON(file, null);
|
|
28
|
+
if (rule)
|
|
29
|
+
out.push({ file, rule, archived });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
34
|
+
export function reviveRule(prefix, reason) {
|
|
35
|
+
const found = candidates(prefix);
|
|
36
|
+
if (found.length === 0)
|
|
37
|
+
throw new Error(`no rule matching "${prefix}" in rules or rules-archive`);
|
|
38
|
+
if (found.length > 1)
|
|
39
|
+
throw new Error(`ambiguous prefix "${prefix}": ${found.map((f) => f.rule.rule_id).join(', ')}`);
|
|
40
|
+
const { file, rule, archived } = found[0];
|
|
41
|
+
// 오너가 되살린 룰은 오너의 룰이다. 채굴 출처로 두면 TTL 로 다음 sweep 에 다시 은퇴한다.
|
|
42
|
+
const revived = {
|
|
43
|
+
...withStatusChange(rule, 'active', reason, 'cli'),
|
|
44
|
+
scope: 'me',
|
|
45
|
+
source: 'explicit_correction',
|
|
46
|
+
clustered_into: undefined,
|
|
47
|
+
lifecycle: rule.lifecycle ? { ...rule.lifecycle, phase: 'active', superseded_by: undefined, merged_into: undefined } : rule.lifecycle,
|
|
48
|
+
};
|
|
49
|
+
delete revived.session_id;
|
|
50
|
+
saveRule(revived);
|
|
51
|
+
if (archived)
|
|
52
|
+
fs.rmSync(file, { force: true });
|
|
53
|
+
return revived;
|
|
54
|
+
}
|
|
55
|
+
export function createSnapshot(label = 'manual', nowIso = new Date().toISOString()) {
|
|
56
|
+
const name = `rules-${nowIso.replace(/[:.]/g, '-')}-${label}`;
|
|
57
|
+
const target = path.join(SNAPSHOT_ROOT, name);
|
|
58
|
+
fs.mkdirSync(target, { recursive: true });
|
|
59
|
+
for (const d of SNAPSHOT_DIRS) {
|
|
60
|
+
const src = path.join(ME_DIR, d);
|
|
61
|
+
if (fs.existsSync(src))
|
|
62
|
+
fs.cpSync(src, path.join(target, d), { recursive: true });
|
|
63
|
+
}
|
|
64
|
+
atomicWriteJSON(path.join(target, 'snapshot.json'), { created_at: nowIso, label, dirs: SNAPSHOT_DIRS });
|
|
65
|
+
return name;
|
|
66
|
+
}
|
|
67
|
+
export function restoreSnapshot(name) {
|
|
68
|
+
if (name !== path.basename(name))
|
|
69
|
+
throw new Error('invalid snapshot name');
|
|
70
|
+
const source = path.join(SNAPSHOT_ROOT, name);
|
|
71
|
+
if (!fs.existsSync(path.join(source, 'snapshot.json')))
|
|
72
|
+
throw new Error(`snapshot not found: ${name}`);
|
|
73
|
+
const safety = createSnapshot('pre-restore');
|
|
74
|
+
// 전부 복사에 성공한 뒤에 바꾼다. 스냅샷에 없는 폴더는 건드리지 않는다.
|
|
75
|
+
const staged = [];
|
|
76
|
+
for (const d of SNAPSHOT_DIRS) {
|
|
77
|
+
const src = path.join(source, d);
|
|
78
|
+
if (!fs.existsSync(src))
|
|
79
|
+
continue;
|
|
80
|
+
const stage = path.join(ME_DIR, `.restore-${d}`);
|
|
81
|
+
fs.rmSync(stage, { recursive: true, force: true });
|
|
82
|
+
fs.cpSync(src, stage, { recursive: true, filter: (f) => !f.endsWith('.lock') });
|
|
83
|
+
staged.push([stage, path.join(ME_DIR, d)]);
|
|
84
|
+
}
|
|
85
|
+
for (const [stage, dest] of staged) {
|
|
86
|
+
fs.rmSync(dest, { recursive: true, force: true });
|
|
87
|
+
fs.renameSync(stage, dest);
|
|
88
|
+
}
|
|
89
|
+
return { safety };
|
|
90
|
+
}
|
|
91
|
+
function fail(message) {
|
|
92
|
+
console.error(`✗ [forgen] ${message}`);
|
|
93
|
+
process.exit(1);
|
|
94
|
+
}
|
|
95
|
+
export function handleRuleRevive(args) {
|
|
96
|
+
const reasonIdx = args.indexOf('--reason');
|
|
97
|
+
const reason = reasonIdx >= 0 ? args[reasonIdx + 1] : undefined;
|
|
98
|
+
const prefix = args.find((a, i) => !a.startsWith('--') && (reasonIdx < 0 || i !== reasonIdx + 1));
|
|
99
|
+
if (!prefix)
|
|
100
|
+
fail('usage: forgen rule revive <rule_id|prefix> [--reason "..."]');
|
|
101
|
+
try {
|
|
102
|
+
const clusteredInto = candidates(prefix)[0]?.rule.clustered_into;
|
|
103
|
+
const rule = reviveRule(prefix, `user: revive${reason ? ` — ${reason}` : ''}`);
|
|
104
|
+
console.log(`✓ [forgen] revived ${rule.rule_id} (scope=me, strength=${rule.strength})`);
|
|
105
|
+
if (clusteredInto)
|
|
106
|
+
console.log(` 참고: ${clusteredInto} 룰에 병합돼 있던 룰입니다. 같은 뜻이 중복되면 그쪽을 정리하세요.`);
|
|
107
|
+
console.log(` ${rule.policy.slice(0, 100)}`);
|
|
108
|
+
}
|
|
109
|
+
catch (e) {
|
|
110
|
+
fail(e instanceof Error ? e.message : String(e));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
export function handleRuleSnapshot() {
|
|
114
|
+
console.log(`✓ [forgen] snapshot ${createSnapshot()}`);
|
|
115
|
+
console.log(' restore: forgen rule restore <이름> --yes');
|
|
116
|
+
}
|
|
117
|
+
export function handleRuleRestore(args) {
|
|
118
|
+
const name = args.find((a) => !a.startsWith('--'));
|
|
119
|
+
if (!name) {
|
|
120
|
+
const list = fs.existsSync(SNAPSHOT_ROOT) ? fs.readdirSync(SNAPSHOT_ROOT).filter((n) => n.startsWith('rules-')).sort() : [];
|
|
121
|
+
console.log(list.length ? list.join('\n') : '(no snapshots)');
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (!args.includes('--yes'))
|
|
125
|
+
fail(`현재 룰·교정·솔루션을 ${name} 로 덮어씁니다. 진행하려면 --yes 를 붙이세요.`);
|
|
126
|
+
try {
|
|
127
|
+
const { safety } = restoreSnapshot(name);
|
|
128
|
+
console.log(`✓ [forgen] restored ${name}. 직전 상태: ${safety}`);
|
|
129
|
+
}
|
|
130
|
+
catch (e) {
|
|
131
|
+
fail(e instanceof Error ? e.message : String(e));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
const normPolicy = (s) => s.replace(/\s+/g, ' ').trim();
|
|
135
|
+
/** 사용자 룰만 읽는다. 실행 위치의 프로젝트 룰에 따라 결과가 달라지면 안 된다. */
|
|
136
|
+
function userRules() {
|
|
137
|
+
const out = [];
|
|
138
|
+
for (const dir of [ME_RULES, ME_RULES_ARCHIVE]) {
|
|
139
|
+
if (!fs.existsSync(dir))
|
|
140
|
+
continue;
|
|
141
|
+
for (const name of fs.readdirSync(dir)) {
|
|
142
|
+
if (!name.endsWith('.json'))
|
|
143
|
+
continue;
|
|
144
|
+
const rule = safeReadJSON(path.join(dir, name), null);
|
|
145
|
+
if (rule?.rule_id && typeof rule.policy === 'string')
|
|
146
|
+
out.push(rule);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return out;
|
|
150
|
+
}
|
|
151
|
+
function offByUser(rule) {
|
|
152
|
+
const last = rule.status_history?.at(-1);
|
|
153
|
+
return !!last && (last.by === 'cli' || last.reason?.startsWith('user:'));
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* 사용자가 직접 한 교정 중 활성 룰로 남지 못한 것. 예전 버전의 세션 정리·승급 실패로 사라진 교정을
|
|
157
|
+
* 업그레이드한 사용자가 스스로 찾아 복구할 수 있게 한다. 같은 문장은 최신 1건만.
|
|
158
|
+
* 제외: fix-now(원래 세션 한정), 사용자가 직접 끈 룰, 병합돼 대표 룰이 살아 있는 룰.
|
|
159
|
+
*/
|
|
160
|
+
export function findLostCorrections() {
|
|
161
|
+
const rules = userRules();
|
|
162
|
+
const byId = new Map(rules.map((r) => [r.rule_id, r]));
|
|
163
|
+
const byEvidence = new Map();
|
|
164
|
+
const byPolicy = new Map();
|
|
165
|
+
const put = (map, key, rule) => { map.set(key, [...(map.get(key) ?? []), rule]); };
|
|
166
|
+
for (const r of rules) {
|
|
167
|
+
put(byPolicy, normPolicy(r.policy), r);
|
|
168
|
+
for (const ref of r.evidence_refs ?? [])
|
|
169
|
+
put(byEvidence, ref, r);
|
|
170
|
+
}
|
|
171
|
+
const order = { suppressed: 0, superseded: 1, removed: 2 };
|
|
172
|
+
const seen = new Set();
|
|
173
|
+
const out = [];
|
|
174
|
+
const evidence = loadEvidenceByType('explicit_correction').sort((a, b) => b.timestamp.localeCompare(a.timestamp));
|
|
175
|
+
for (const ev of evidence) {
|
|
176
|
+
const text = normPolicy(ev.summary ?? '');
|
|
177
|
+
if (!text || seen.has(text))
|
|
178
|
+
continue;
|
|
179
|
+
seen.add(text);
|
|
180
|
+
if (ev.raw_payload?.kind === 'fix-now')
|
|
181
|
+
continue;
|
|
182
|
+
const same = [...new Set([...(byEvidence.get(ev.evidence_id) ?? []), ...(byPolicy.get(text) ?? [])])];
|
|
183
|
+
const alive = same.some((r) => r.status === 'active' || offByUser(r) || (r.clustered_into && byId.get(r.clustered_into)?.status === 'active'));
|
|
184
|
+
if (alive)
|
|
185
|
+
continue;
|
|
186
|
+
same.sort((a, b) => (order[a.status] ?? 9) - (order[b.status] ?? 9));
|
|
187
|
+
out.push({ evidence: ev, rule: same[0] ?? null });
|
|
188
|
+
}
|
|
189
|
+
return out.sort((a, b) => a.evidence.timestamp.localeCompare(b.evidence.timestamp));
|
|
190
|
+
}
|
|
191
|
+
export function recoverCorrection(lost, projects) {
|
|
192
|
+
const scoped = projects?.length ? { projects } : {};
|
|
193
|
+
if (lost.rule) {
|
|
194
|
+
const revived = reviveRule(lost.rule.rule_id, 'user: rule recover');
|
|
195
|
+
if (revived.strength === 'hard' || !projects?.length)
|
|
196
|
+
return revived;
|
|
197
|
+
const next = { ...revived, ...scoped };
|
|
198
|
+
saveRule(next);
|
|
199
|
+
return next;
|
|
200
|
+
}
|
|
201
|
+
const { evidence } = lost;
|
|
202
|
+
const raw = (evidence.raw_payload ?? {});
|
|
203
|
+
const axis = raw.axis_hint ?? 'workflow';
|
|
204
|
+
const target = raw.target || evidence.summary.slice(0, 80);
|
|
205
|
+
const created = createRule({
|
|
206
|
+
category: axis === 'quality_safety' ? 'quality' : axis === 'autonomy' ? 'autonomy' : 'workflow',
|
|
207
|
+
scope: 'me',
|
|
208
|
+
trigger: target,
|
|
209
|
+
policy: evidence.summary,
|
|
210
|
+
strength: raw.kind === 'avoid-this' ? 'strong' : 'default',
|
|
211
|
+
source: 'explicit_correction',
|
|
212
|
+
evidence_refs: [evidence.evidence_id],
|
|
213
|
+
render_key: `${axis}.${evidence.evidence_id.slice(0, 8)}`,
|
|
214
|
+
...scoped,
|
|
215
|
+
});
|
|
216
|
+
let rule = created;
|
|
217
|
+
try {
|
|
218
|
+
rule = applyProposal(created, classify(created));
|
|
219
|
+
}
|
|
220
|
+
catch { /* 분류 실패해도 룰은 남긴다 */ }
|
|
221
|
+
saveRule(rule);
|
|
222
|
+
return rule;
|
|
223
|
+
}
|
|
224
|
+
export function handleRuleRecover(args) {
|
|
225
|
+
const lost = findLostCorrections();
|
|
226
|
+
const projectIdx = args.indexOf('--project');
|
|
227
|
+
const project = projectIdx >= 0 ? args[projectIdx + 1]?.toLowerCase() : undefined;
|
|
228
|
+
if (projectIdx >= 0 && !project)
|
|
229
|
+
fail('usage: forgen rule recover [--apply <id...>] [--project <키>]');
|
|
230
|
+
const applyIdx = args.indexOf('--apply');
|
|
231
|
+
if (applyIdx < 0) {
|
|
232
|
+
if (lost.length === 0) {
|
|
233
|
+
console.log('복구할 교정이 없습니다.');
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
console.log(`활성 룰로 남지 못한 교정 ${lost.length}건 (미리보기)`);
|
|
237
|
+
for (const { evidence, rule } of lost) {
|
|
238
|
+
console.log(` ${evidence.evidence_id.slice(0, 8)} ${evidence.timestamp.slice(0, 10)} ${rule ? rule.status : '룰 없음'} ${evidence.summary.slice(0, 80)}`);
|
|
239
|
+
}
|
|
240
|
+
console.log('복구: forgen rule recover --apply <id...> [--project <키>] (--project 를 빼면 전역)');
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
const ids = args.slice(applyIdx + 1).filter((a, i, all) => !a.startsWith('--') && all[i - 1] !== '--project');
|
|
244
|
+
if (ids.length === 0)
|
|
245
|
+
fail('복구할 ID 를 지정하세요. 미리보기: forgen rule recover');
|
|
246
|
+
// ID 가 하나라도 잘못되면 아무것도 바꾸지 않는다. 적용 중 실패한 항목은 알리고 나머지는 계속한다.
|
|
247
|
+
const picked = ids.map((id) => {
|
|
248
|
+
const found = lost.filter((l) => l.evidence.evidence_id.startsWith(id));
|
|
249
|
+
if (found.length !== 1)
|
|
250
|
+
fail(`"${id}" 와 일치하는 복구 대상이 ${found.length}건입니다. 아무것도 복구하지 않았습니다.`);
|
|
251
|
+
return found[0];
|
|
252
|
+
});
|
|
253
|
+
for (const item of picked) {
|
|
254
|
+
try {
|
|
255
|
+
const rule = recoverCorrection(item, project ? [project] : undefined);
|
|
256
|
+
console.log(`✓ [forgen] 복구 ${rule.rule_id.slice(0, 8)} (${rule.projects?.join(',') ?? '전역'}) ${rule.policy.slice(0, 70)}`);
|
|
257
|
+
if (project && rule.strength === 'hard')
|
|
258
|
+
console.log(' hard 룰은 프로젝트로 좁힐 수 없어 전역으로 복구했습니다.');
|
|
259
|
+
}
|
|
260
|
+
catch (e) {
|
|
261
|
+
console.error(`✗ [forgen] ${item.evidence.evidence_id.slice(0, 8)} 복구 실패: ${e instanceof Error ? e.message : String(e)}`);
|
|
262
|
+
process.exitCode = 1;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
@@ -11,8 +11,20 @@
|
|
|
11
11
|
*/
|
|
12
12
|
export declare function handleSuppressRule(args: string[]): Promise<void>;
|
|
13
13
|
/**
|
|
14
|
-
* ADR-017 D1: enforce_mode 전환. `advise` = 차단 대신
|
|
15
|
-
*
|
|
14
|
+
* ADR-017 D1: enforce_mode 전환. `advise` = 차단 대신 기록만, `enforce` = 차단 켬(사용자 명시).
|
|
15
|
+
* 의미 룰(self_check)은 기본이 기록만이라 `enforce` 로 켠 것만 차단한다. 하드 룰은 advise 로 내릴 수 없다.
|
|
16
16
|
*/
|
|
17
17
|
export declare function handleEnforceMode(args: string[], mode: 'block' | 'advise'): Promise<void>;
|
|
18
18
|
export declare function handleActivateRule(args: string[]): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* D12-C: precision 판정으로 advise 강등된 룰을 한꺼번에 복구한다.
|
|
21
|
+
* 강등의 근거였던 오탐 판정 중 상당수는 "무관한 룰이 무관한 완료 보고를 막은" 주제 게이트 이전 오탐이었다.
|
|
22
|
+
* 기본은 목록만 보여주고(--apply 로 실행), 실행하면 enforce_mode 를 block 으로 되돌리고
|
|
23
|
+
* 게이트 이전 stop-guard 판정이 정밀도 계산에 다시 쓰이지 않도록 epoch 를 기록한다.
|
|
24
|
+
*/
|
|
25
|
+
export declare function handleRestoreDemoted(args: string[]): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* R9: explicit 교정 룰 병합은 자동으로 적용하지 않는다 — 제안만 쌓이고, 여기서 목록을 보고 --apply 로 확인한다.
|
|
28
|
+
* (적용 후에도 `forgen rule unmerge <id>` 로 원본 복구 가능.)
|
|
29
|
+
*/
|
|
30
|
+
export declare function handleMergeExplicit(args: string[]): Promise<void>;
|