@wooojin/forgen 0.6.5 → 0.6.7
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 +41 -0
- package/README.ja.md +2 -1
- package/README.ko.md +2 -1
- package/README.md +2 -1
- package/README.zh.md +2 -1
- package/dist/cli.js +2 -2
- package/dist/core/block-cli.js +2 -4
- package/dist/core/dashboard.js +1 -1
- package/dist/core/explain-cli.js +3 -28
- package/dist/core/rate-limit-forecast.js +7 -1
- package/dist/core/state-gc.d.ts +14 -0
- package/dist/core/state-gc.js +47 -4
- package/dist/core/stats-cli.js +5 -5
- package/dist/core/statusline-cli.d.ts +24 -2
- package/dist/core/statusline-cli.js +125 -23
- package/dist/core/statusline-install.d.ts +8 -1
- package/dist/core/statusline-install.js +34 -3
- package/dist/engine/block-judge.js +4 -5
- package/dist/engine/classify-enforce-cli.js +40 -0
- package/dist/engine/context-signals.d.ts +20 -0
- package/dist/engine/context-signals.js +102 -0
- package/dist/engine/correction-cluster-runner.d.ts +3 -3
- package/dist/engine/correction-cluster-runner.js +48 -12
- package/dist/engine/correction-clustering.d.ts +27 -0
- package/dist/engine/correction-clustering.js +79 -3
- package/dist/engine/enforce-classifier.d.ts +28 -1
- package/dist/engine/enforce-classifier.js +90 -19
- package/dist/engine/ko-colloquial.d.ts +13 -0
- package/dist/engine/ko-colloquial.js +45 -0
- package/dist/engine/lifecycle/lifecycle-cli.js +25 -5
- package/dist/engine/lifecycle/meta-reclassifier.d.ts +1 -0
- package/dist/engine/lifecycle/meta-reclassifier.js +3 -21
- package/dist/engine/lifecycle/rotated-logs.d.ts +18 -0
- package/dist/engine/lifecycle/rotated-logs.js +67 -0
- package/dist/engine/lifecycle/signals.d.ts +27 -1
- package/dist/engine/lifecycle/signals.js +55 -32
- package/dist/engine/lifecycle/types.d.ts +5 -0
- package/dist/engine/match-eval-log.d.ts +2 -0
- package/dist/engine/match-eval-log.js +1 -0
- package/dist/engine/ranking-pipeline.d.ts +9 -1
- package/dist/engine/ranking-pipeline.js +24 -2
- package/dist/engine/solution-format.d.ts +2 -0
- package/dist/engine/solution-format.js +6 -2
- package/dist/engine/solution-matcher.d.ts +5 -1
- package/dist/engine/solution-matcher.js +4 -2
- package/dist/hooks/post-tool-use.js +3 -1
- package/dist/hooks/shared/stop-triggers.d.ts +32 -4
- package/dist/hooks/shared/stop-triggers.js +44 -3
- package/dist/hooks/solution-injector.js +7 -2
- package/dist/hooks/stop-guard.d.ts +2 -2
- package/dist/hooks/stop-guard.js +85 -10
- package/dist/store/rule-store.d.ts +16 -0
- package/dist/store/rule-store.js +34 -2
- package/dist/store/types.d.ts +5 -1
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/scripts/postinstall.js +23 -2
|
@@ -29,6 +29,8 @@ export function redactForReceipt(text) {
|
|
|
29
29
|
t = t.replace(/(:\/\/[^\s/:@]+:)[^\s/@]+(@)/g, '$1[REDACTED]$2');
|
|
30
30
|
return t;
|
|
31
31
|
}
|
|
32
|
+
import { listRotated, logFilesWithin, readJsonlSafe, readJsonlWindow, ROTATED_KEEP_MAX, ROTATED_KEEP_DAYS } from './rotated-logs.js';
|
|
33
|
+
export { listRotated, logFilesWithin, readJsonlSafe, readJsonlWindow, ROTATED_KEEP_MAX, ROTATED_KEEP_DAYS };
|
|
32
34
|
import { STATE_DIR as FORGEN_STATE_DIR } from '../../core/paths.js';
|
|
33
35
|
const ENFORCEMENT_DIR = path.join(FORGEN_STATE_DIR, 'enforcement');
|
|
34
36
|
const VIOLATIONS_PATH = path.join(ENFORCEMENT_DIR, 'violations.jsonl');
|
|
@@ -54,36 +56,28 @@ export function rotateIfBig(p) {
|
|
|
54
56
|
}
|
|
55
57
|
catch { /* missing → no rotate */ }
|
|
56
58
|
}
|
|
57
|
-
export function readJsonlSafe(p) {
|
|
58
|
-
if (!fs.existsSync(p))
|
|
59
|
-
return [];
|
|
60
|
-
try {
|
|
61
|
-
return fs.readFileSync(p, 'utf-8')
|
|
62
|
-
.trim()
|
|
63
|
-
.split('\n')
|
|
64
|
-
.filter(Boolean)
|
|
65
|
-
.map((line) => {
|
|
66
|
-
try {
|
|
67
|
-
return JSON.parse(line);
|
|
68
|
-
}
|
|
69
|
-
catch {
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
})
|
|
73
|
-
.filter((e) => e !== null);
|
|
74
|
-
}
|
|
75
|
-
catch {
|
|
76
|
-
return [];
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
59
|
/**
|
|
80
60
|
* ADR-017 §2 원칙 2: 훅이 session_id 없이 호출되면 'default'/'unknown' 폴백이 기록된다.
|
|
81
61
|
* 실세션(Claude·Codex 모두 session_id 전달)에서는 나오지 않으며, 실측상 전부 테스트가
|
|
82
62
|
* dist 훅을 spawn 한 흔적이었다(7d 차단 108건 중 78건). 모든 집계에서 제외한다.
|
|
83
63
|
*/
|
|
84
64
|
export const SYNTHETIC_SESSION_IDS = new Set(['default', 'unknown', '']);
|
|
65
|
+
/**
|
|
66
|
+
* 실 Claude Code(session_id) · Codex(thread id)는 전부 UUID 형식이다. eval/probe 하네스가 쓰는
|
|
67
|
+
* 'forgen-eval-<ts>-<rand>', 'repro-*', 'enforce-test' 등 임의 문자열은 UUID 가 아니므로 합성으로 본다.
|
|
68
|
+
* (실 ~/.forgen 데이터 검증: 비-default 세션 중 UUID 는 실세션 전부, 비-UUID 는 하네스 41건뿐.)
|
|
69
|
+
*/
|
|
70
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
85
71
|
export function isSyntheticSession(sessionId) {
|
|
86
|
-
return typeof sessionId !== 'string' || SYNTHETIC_SESSION_IDS.has(sessionId);
|
|
72
|
+
return typeof sessionId !== 'string' || SYNTHETIC_SESSION_IDS.has(sessionId) || !UUID_RE.test(sessionId);
|
|
73
|
+
}
|
|
74
|
+
/** FORGEN_SYNTHETIC=1 (eval/probe 러너가 설정) 이면 기록에 synthetic:true 를 붙인다. */
|
|
75
|
+
export function syntheticStamp() {
|
|
76
|
+
return process.env.FORGEN_SYNTHETIC === '1' ? { synthetic: true } : {};
|
|
77
|
+
}
|
|
78
|
+
/** 엔트리 단위 합성 판정: 명시적 synthetic 플래그 또는 합성 세션 id. */
|
|
79
|
+
export function isSyntheticEntry(e) {
|
|
80
|
+
return e.synthetic === true || isSyntheticSession(e.session_id);
|
|
87
81
|
}
|
|
88
82
|
/** 사용자 관점의 "차단": block/deny (+legacy undefined). correction/bypass_confirmed 는 아님. */
|
|
89
83
|
export function isBlockKind(kind) {
|
|
@@ -91,10 +85,10 @@ export function isBlockKind(kind) {
|
|
|
91
85
|
}
|
|
92
86
|
/** 실세션에서 일어난 실제 차단만. stats/explain/lifecycle 이 공유하는 단일 기준. */
|
|
93
87
|
export function isRealBlock(e) {
|
|
94
|
-
return isBlockKind(e.kind) && !
|
|
88
|
+
return isBlockKind(e.kind) && !isSyntheticEntry(e);
|
|
95
89
|
}
|
|
96
90
|
export function isConfirmedBypass(e) {
|
|
97
|
-
return e.kind === 'bypass_confirmed' && !
|
|
91
|
+
return e.kind === 'bypass_confirmed' && !isSyntheticEntry(e);
|
|
98
92
|
}
|
|
99
93
|
const RECEIPTS_DIR = path.join(ENFORCEMENT_DIR, 'receipts');
|
|
100
94
|
const VERDICTS_PATH = path.join(ENFORCEMENT_DIR, 'verdicts.jsonl');
|
|
@@ -130,7 +124,7 @@ export function recordViolation(entry, opts = {}) {
|
|
|
130
124
|
fs.mkdirSync(ENFORCEMENT_DIR, { recursive: true });
|
|
131
125
|
rotateIfBig(VIOLATIONS_PATH);
|
|
132
126
|
const violation_id = entry.violation_id ?? crypto.randomUUID();
|
|
133
|
-
const full = { at: new Date().toISOString(), violation_id, ...entry };
|
|
127
|
+
const full = { at: new Date().toISOString(), violation_id, ...entry, ...syntheticStamp() };
|
|
134
128
|
// 로그에 남는 프래그먼트/미리보기도 secret 마스킹 — 영수증만 가리고 로그에 키가 남으면 의미 없다.
|
|
135
129
|
if (typeof full.matched === 'string')
|
|
136
130
|
full.matched = redactForReceipt(full.matched);
|
|
@@ -158,6 +152,10 @@ export function recordViolation(entry, opts = {}) {
|
|
|
158
152
|
return '';
|
|
159
153
|
}
|
|
160
154
|
}
|
|
155
|
+
/** 위반 로그(현재 + 창 안 회전본). 기본 30일 = collectSignals 창. */
|
|
156
|
+
export function readViolationsWindow(days = VIOLATION_WINDOW_DAYS, now = Date.now()) {
|
|
157
|
+
return readJsonlWindow(VIOLATIONS_PATH, days, now);
|
|
158
|
+
}
|
|
161
159
|
export function readReceipt(violationId) {
|
|
162
160
|
if (!/^[A-Za-z0-9-]+$/.test(violationId))
|
|
163
161
|
return null;
|
|
@@ -173,12 +171,13 @@ export function setVerdict(entry) {
|
|
|
173
171
|
try {
|
|
174
172
|
fs.mkdirSync(ENFORCEMENT_DIR, { recursive: true });
|
|
175
173
|
rotateIfBig(VERDICTS_PATH);
|
|
176
|
-
fs.appendFileSync(VERDICTS_PATH, `${JSON.stringify({ at: new Date().toISOString(), ...entry })}\n`);
|
|
174
|
+
fs.appendFileSync(VERDICTS_PATH, `${JSON.stringify({ at: new Date().toISOString(), ...entry, ...syntheticStamp() })}\n`);
|
|
177
175
|
}
|
|
178
176
|
catch { /* best-effort */ }
|
|
179
177
|
}
|
|
178
|
+
/** 판정은 위반 이후에 기록되므로 30일 창(위반 조회 최대 창)이면 충분하다. */
|
|
180
179
|
export function readVerdicts() {
|
|
181
|
-
return
|
|
180
|
+
return readJsonlWindow(VERDICTS_PATH, VIOLATION_WINDOW_DAYS);
|
|
182
181
|
}
|
|
183
182
|
/** violation_id → 유효 판정 (user 가 있으면 user, 없으면 마지막 auto). */
|
|
184
183
|
export function effectiveVerdicts(verdicts = readVerdicts()) {
|
|
@@ -223,7 +222,7 @@ export function recordCheck(entry) {
|
|
|
223
222
|
try {
|
|
224
223
|
fs.mkdirSync(ENFORCEMENT_DIR, { recursive: true });
|
|
225
224
|
rotateIfBig(CHECKS_PATH);
|
|
226
|
-
fs.appendFileSync(CHECKS_PATH, `${JSON.stringify({ at: new Date().toISOString(), ...entry })}\n`);
|
|
225
|
+
fs.appendFileSync(CHECKS_PATH, `${JSON.stringify({ at: new Date().toISOString(), ...entry, ...syntheticStamp() })}\n`);
|
|
227
226
|
// 7일 TTL — 통과 기록은 턴마다 쌓이므로 1/50 확률로 압축(rotateIfBig 10MB 에 닿지 않게).
|
|
228
227
|
if (Math.random() < 0.02)
|
|
229
228
|
pruneChecks();
|
|
@@ -238,7 +237,7 @@ export function pruneChecks(now = Date.now()) {
|
|
|
238
237
|
catch { /* best-effort */ }
|
|
239
238
|
}
|
|
240
239
|
export function readChecks() {
|
|
241
|
-
return
|
|
240
|
+
return readJsonlWindow(CHECKS_PATH, CHECKS_TTL_MS / (24 * 3600 * 1000)).filter((c) => !isSyntheticEntry(c));
|
|
242
241
|
}
|
|
243
242
|
/** 정규식 매칭 프래그먼트 추출 — 영수증 `matched` 필드용. */
|
|
244
243
|
export function matchedFragment(re, text) {
|
|
@@ -257,7 +256,7 @@ export function recordBypass(entry) {
|
|
|
257
256
|
try {
|
|
258
257
|
fs.mkdirSync(ENFORCEMENT_DIR, { recursive: true });
|
|
259
258
|
rotateIfBig(BYPASS_PATH);
|
|
260
|
-
const full = { at: new Date().toISOString(), ...entry };
|
|
259
|
+
const full = { at: new Date().toISOString(), ...entry, ...syntheticStamp() };
|
|
261
260
|
fs.appendFileSync(BYPASS_PATH, `${JSON.stringify(full)}\n`);
|
|
262
261
|
}
|
|
263
262
|
catch (e) {
|
|
@@ -268,7 +267,7 @@ export function recordBypass(entry) {
|
|
|
268
267
|
}
|
|
269
268
|
export function collectSignals(rule, inputs = {}) {
|
|
270
269
|
const now = inputs.now ?? Date.now();
|
|
271
|
-
const allViolations = inputs.violations ??
|
|
270
|
+
const allViolations = inputs.violations ?? readViolationsWindow(VIOLATION_WINDOW_DAYS, now);
|
|
272
271
|
// ADR-017 D1/D2: T2 는 실제 차단만 센다 — 이전엔 kind 필터가 없어 메타가드 advise(correction)
|
|
273
272
|
// 와 테스트 유래(default 세션) 기록이 위반으로 집계돼 flag 를 조기 발화시켰다.
|
|
274
273
|
const violations = allViolations.filter(isRealBlock);
|
|
@@ -322,6 +321,30 @@ export function collectSignals(rule, inputs = {}) {
|
|
|
322
321
|
last_updated_days_ago: lastUpdatedDays,
|
|
323
322
|
};
|
|
324
323
|
}
|
|
324
|
+
/**
|
|
325
|
+
* 룰별 위반/우회 카운터를 로그에서 재계산 (lifecycle-scan --apply 가 룰 JSON 에 저장).
|
|
326
|
+
* 원천은 항상 로그다 — 룰 JSON 의 violation_count/bypass_count 는 이 값의 캐시일 뿐이며
|
|
327
|
+
* 보존된 로그 범위(회전본 포함) 안의 합계다. 훅 경로에서는 갱신하지 않는다.
|
|
328
|
+
*/
|
|
329
|
+
export function deriveRuleCounters(violations) {
|
|
330
|
+
const m = new Map();
|
|
331
|
+
for (const v of violations) {
|
|
332
|
+
const real = isRealBlock(v);
|
|
333
|
+
if (!real && !isConfirmedBypass(v))
|
|
334
|
+
continue;
|
|
335
|
+
const c = m.get(v.rule_id) ?? { violation_count: 0, bypass_count: 0 };
|
|
336
|
+
if (real) {
|
|
337
|
+
c.violation_count++;
|
|
338
|
+
if (!c.last_violation_at || v.at > c.last_violation_at)
|
|
339
|
+
c.last_violation_at = v.at;
|
|
340
|
+
}
|
|
341
|
+
else {
|
|
342
|
+
c.bypass_count++;
|
|
343
|
+
}
|
|
344
|
+
m.set(v.rule_id, c);
|
|
345
|
+
}
|
|
346
|
+
return m;
|
|
347
|
+
}
|
|
325
348
|
export function collectAllSignals(rules, inputs = {}) {
|
|
326
349
|
const map = new Map();
|
|
327
350
|
for (const r of rules) {
|
|
@@ -39,6 +39,8 @@ export interface ViolationEntry {
|
|
|
39
39
|
at: string;
|
|
40
40
|
rule_id: string;
|
|
41
41
|
session_id: string;
|
|
42
|
+
/** FORGEN_SYNTHETIC=1 하네스가 기록 — 모든 집계에서 제외. */
|
|
43
|
+
synthetic?: true;
|
|
42
44
|
source: 'stop-guard' | 'subagent-stop-guard' | 'pre-tool-guard' | 'post-tool-guard' | 'evidence-store' | 'manual';
|
|
43
45
|
/**
|
|
44
46
|
* block/deny = 실제 차단. correction = 메타가드 advise(기록만). bypass_confirmed = 사용자가
|
|
@@ -63,6 +65,7 @@ export interface VerdictEntry {
|
|
|
63
65
|
/** 사람 > 모델. user 판정은 auto 를 덮어쓴다. */
|
|
64
66
|
by: 'auto' | 'user';
|
|
65
67
|
reason?: string;
|
|
68
|
+
synthetic?: true;
|
|
66
69
|
}
|
|
67
70
|
/** D2: Stop 에서 실제 평가된 룰의 결과 (통과/위반). violations.jsonl 과 분리 — T2·explain 오염 방지. */
|
|
68
71
|
export interface CheckEntry {
|
|
@@ -70,6 +73,7 @@ export interface CheckEntry {
|
|
|
70
73
|
session_id: string;
|
|
71
74
|
rule_id: string;
|
|
72
75
|
result: 'pass' | 'violation';
|
|
76
|
+
synthetic?: true;
|
|
73
77
|
}
|
|
74
78
|
export interface BypassEntry {
|
|
75
79
|
at: string;
|
|
@@ -77,4 +81,5 @@ export interface BypassEntry {
|
|
|
77
81
|
session_id: string;
|
|
78
82
|
tool: string;
|
|
79
83
|
pattern_preview: string;
|
|
84
|
+
synthetic?: true;
|
|
80
85
|
}
|
|
@@ -179,6 +179,7 @@ export function logMatchDecision(input) {
|
|
|
179
179
|
})),
|
|
180
180
|
rankedTopN: input.rankedTopN.slice(0, MAX_CANDIDATES_LOGGED),
|
|
181
181
|
ts: new Date().toISOString(),
|
|
182
|
+
...(process.env.FORGEN_SYNTHETIC === '1' ? { synthetic: true } : {}),
|
|
182
183
|
};
|
|
183
184
|
// Serialize FIRST so any toJSON throw is caught before we touch disk.
|
|
184
185
|
const line = `${JSON.stringify(record)}\n`;
|
|
@@ -27,7 +27,15 @@ export interface RankedCandidate<T extends RankableSolution = RankableSolution>
|
|
|
27
27
|
relevance: number;
|
|
28
28
|
matchedTags: string[];
|
|
29
29
|
matchedIdentifiers: string[];
|
|
30
|
+
/** 맥락 토큰(cwd/최근 편집 파일)으로만 겹친 태그. matchedTags 와 분리 — 순위 가산(태그당 0.1, 상한 0.2)에만 쓰고 게이트엔 안 씀. */
|
|
31
|
+
contextMatchedTags: string[];
|
|
32
|
+
/** relevance 에 포함된 맥락 가산분. 주입 게이트는 relevance − contextBonus 로 비교한다(critic v0.6.6 SEV-2). */
|
|
33
|
+
contextBonus: number;
|
|
30
34
|
}
|
|
35
|
+
/** 맥락 태그 1개당 relevance 가산(프롬프트 태그 1개 ≈ 0.2 의 절반). */
|
|
36
|
+
export declare const CONTEXT_TAG_BONUS = 0.1;
|
|
37
|
+
/** 맥락 가산 총상한 — 맥락이 점수를 지배하지 못하게. */
|
|
38
|
+
export declare const CONTEXT_BONUS_CAP = 0.2;
|
|
31
39
|
/**
|
|
32
40
|
* Shared ranking core: tag-based relevance + identifier boost + top-5 sort.
|
|
33
41
|
*
|
|
@@ -42,4 +50,4 @@ export declare function rankCandidates<T extends RankableSolution>(promptTags: s
|
|
|
42
50
|
tfidf: number;
|
|
43
51
|
bm25: number;
|
|
44
52
|
bigram: number;
|
|
45
|
-
}): RankedCandidate<T>[];
|
|
53
|
+
}, contextTokens?: readonly string[]): RankedCandidate<T>[];
|
|
@@ -8,8 +8,13 @@
|
|
|
8
8
|
import { maskBlockedTokens } from './phrase-blocklist.js';
|
|
9
9
|
import { calculateRelevance } from './relevance-scorer.js';
|
|
10
10
|
import { expandCompoundTags, expandQueryBigrams, expandQueryKoreanStems } from './solution-format.js';
|
|
11
|
+
import { tagWeight } from './scoring-algorithms.js';
|
|
11
12
|
import { shouldRejectByR4T3Rules } from './precision-guards.js';
|
|
12
13
|
import { defaultNormalizer } from './term-normalizer.js';
|
|
14
|
+
/** 맥락 태그 1개당 relevance 가산(프롬프트 태그 1개 ≈ 0.2 의 절반). */
|
|
15
|
+
export const CONTEXT_TAG_BONUS = 0.1;
|
|
16
|
+
/** 맥락 가산 총상한 — 맥락이 점수를 지배하지 못하게. */
|
|
17
|
+
export const CONTEXT_BONUS_CAP = 0.2;
|
|
13
18
|
/**
|
|
14
19
|
* Shared ranking core: tag-based relevance + identifier boost + top-5 sort.
|
|
15
20
|
*
|
|
@@ -20,7 +25,7 @@ import { defaultNormalizer } from './term-normalizer.js';
|
|
|
20
25
|
* - top-5 by `relevance` descending.
|
|
21
26
|
* - duplicate names are NOT deduplicated.
|
|
22
27
|
*/
|
|
23
|
-
export function rankCandidates(promptTags, promptLower, solutions, ensembleWeights) {
|
|
28
|
+
export function rankCandidates(promptTags, promptLower, solutions, ensembleWeights, contextTokens = []) {
|
|
24
29
|
// R4-T2: mask blocked tokens before expansion/normalization
|
|
25
30
|
const maskedPromptTags = maskBlockedTokens(promptLower, promptTags);
|
|
26
31
|
if (maskedPromptTags.length === 0)
|
|
@@ -55,11 +60,28 @@ export function rankCandidates(promptTags, promptLower, solutions, ensembleWeigh
|
|
|
55
60
|
tagRelevance = 0;
|
|
56
61
|
tagMatches = [];
|
|
57
62
|
}
|
|
63
|
+
// 맥락 신호: 프롬프트로 이미 1개 이상 매칭된 후보에만 적용(맥락 단독 후보 생성 금지).
|
|
64
|
+
// 프롬프트 매칭 태그와 겹치는 맥락 토큰은 중복 가산하지 않는다.
|
|
65
|
+
const contextMatchedTags = [];
|
|
66
|
+
let contextBonus = 0;
|
|
67
|
+
if (contextTokens.length > 0 && tagMatches.length + matchedIdentifiers.length >= 1) {
|
|
68
|
+
const ctx = new Set(contextTokens);
|
|
69
|
+
const already = new Set([...tagMatches, ...maskedPromptTags]);
|
|
70
|
+
for (const t of solTagsExpanded) {
|
|
71
|
+
if (ctx.has(t) && !already.has(t) && !contextMatchedTags.includes(t)) {
|
|
72
|
+
contextMatchedTags.push(t);
|
|
73
|
+
contextBonus += CONTEXT_TAG_BONUS * tagWeight(t);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
contextBonus = Math.min(contextBonus, CONTEXT_BONUS_CAP);
|
|
77
|
+
}
|
|
58
78
|
return {
|
|
59
79
|
solution: sol,
|
|
60
|
-
relevance: tagRelevance + identifierBoost,
|
|
80
|
+
relevance: tagRelevance + identifierBoost + contextBonus,
|
|
61
81
|
matchedTags: tagMatches,
|
|
62
82
|
matchedIdentifiers,
|
|
83
|
+
contextMatchedTags,
|
|
84
|
+
contextBonus,
|
|
63
85
|
};
|
|
64
86
|
})
|
|
65
87
|
.filter((c) => c.matchedTags.length + c.matchedIdentifiers.length >= 1)
|
|
@@ -76,6 +76,8 @@ export declare function parseSolutionV3(content: string): SolutionV3 | null;
|
|
|
76
76
|
export declare function serializeSolutionV3(solution: SolutionV3): string;
|
|
77
77
|
/** Check if content is in V1 format (# Title + > Type: pattern) */
|
|
78
78
|
export declare function isV1Format(content: string): boolean;
|
|
79
|
+
/** 영어 불용어 */
|
|
80
|
+
export declare const EN_STOPWORDS: Set<string>;
|
|
79
81
|
/** 한국어 일반 조사/어미 — strip 대상 (긴 것부터 매칭)
|
|
80
82
|
*
|
|
81
83
|
* term-matcher에서 재사용 가능하도록 export — 매칭 시점과 추출 시점의 stripping
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as yaml from 'js-yaml';
|
|
2
|
+
import { normalizeColloquialKo } from './ko-colloquial.js';
|
|
2
3
|
export const DEFAULT_EVIDENCE = {
|
|
3
4
|
injected: 0,
|
|
4
5
|
reflected: 0,
|
|
@@ -334,7 +335,7 @@ const KO_STOPWORDS = new Set([
|
|
|
334
335
|
'최종',
|
|
335
336
|
]);
|
|
336
337
|
/** 영어 불용어 */
|
|
337
|
-
const EN_STOPWORDS = new Set([
|
|
338
|
+
export const EN_STOPWORDS = new Set([
|
|
338
339
|
'the',
|
|
339
340
|
'and',
|
|
340
341
|
'for',
|
|
@@ -454,7 +455,10 @@ export function extractTags(text) {
|
|
|
454
455
|
for (const w of words) {
|
|
455
456
|
const isKorean = /[가-힣]/.test(w);
|
|
456
457
|
if (isKorean && w.length >= 2) {
|
|
457
|
-
const
|
|
458
|
+
const base = normalizeColloquialKo(w);
|
|
459
|
+
if (base === null)
|
|
460
|
+
continue;
|
|
461
|
+
const stem = stripKoSuffix(base);
|
|
458
462
|
if (stem.length >= 2 && !KO_STOPWORDS.has(stem)) {
|
|
459
463
|
freq.set(stem, (freq.get(stem) ?? 0) + 1);
|
|
460
464
|
}
|
|
@@ -38,5 +38,9 @@ export interface SolutionMatch {
|
|
|
38
38
|
identifiers: string[];
|
|
39
39
|
matchedTags: string[];
|
|
40
40
|
matchedIdentifiers: string[];
|
|
41
|
+
/** 맥락 토큰(cwd/최근 편집 파일)으로만 겹친 태그 — 순위 가산에만, 게이트·단독 주입 불가. */
|
|
42
|
+
contextMatchedTags?: string[];
|
|
43
|
+
/** relevance 에 포함된 맥락 가산분 (게이트 비교에서 제외). */
|
|
44
|
+
contextBonus?: number;
|
|
41
45
|
}
|
|
42
|
-
export declare function matchSolutions(prompt: string, scope: ScopeInfo, cwd: string): SolutionMatch[];
|
|
46
|
+
export declare function matchSolutions(prompt: string, scope: ScopeInfo, cwd: string, contextTokens?: readonly string[]): SolutionMatch[];
|
|
@@ -43,7 +43,7 @@ function applyCandidateExplorationBonus(entries) {
|
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
// ── Public API ──
|
|
46
|
-
export function matchSolutions(prompt, scope, cwd) {
|
|
46
|
+
export function matchSolutions(prompt, scope, cwd, contextTokens = []) {
|
|
47
47
|
const dirs = [{ dir: ME_SOLUTIONS, scope: 'me' }];
|
|
48
48
|
if (scope.team) {
|
|
49
49
|
dirs.push({ dir: path.join(PACKS_DIR, scope.team.name, 'solutions'), scope: 'team' });
|
|
@@ -54,7 +54,7 @@ export function matchSolutions(prompt, scope, cwd) {
|
|
|
54
54
|
const promptTags = extractTags(prompt);
|
|
55
55
|
const promptLower = prompt.toLowerCase();
|
|
56
56
|
const tunedWeights = loadTunedMatcherWeights();
|
|
57
|
-
const ranked = rankCandidates(promptTags, promptLower, allSolutions, tunedWeights);
|
|
57
|
+
const ranked = rankCandidates(promptTags, promptLower, allSolutions, tunedWeights, contextTokens);
|
|
58
58
|
// ADR-010 W3-1 (F2): 저 ROI 강등 — ranking-pipeline 은 순수 유지, 여기서
|
|
59
59
|
// 후처리. surfaced≫acted_on 솔루션은 ×0.5, 2윈도 연속이면 주입 제외.
|
|
60
60
|
const matches = ranked.map((c) => ({
|
|
@@ -70,6 +70,8 @@ export function matchSolutions(prompt, scope, cwd) {
|
|
|
70
70
|
identifiers: c.solution.identifiers,
|
|
71
71
|
matchedTags: [...c.matchedTags, ...c.matchedIdentifiers],
|
|
72
72
|
matchedIdentifiers: c.matchedIdentifiers,
|
|
73
|
+
contextMatchedTags: c.contextMatchedTags,
|
|
74
|
+
contextBonus: c.contextBonus,
|
|
73
75
|
}));
|
|
74
76
|
try {
|
|
75
77
|
return applyRoiDemotions(matches, loadRoiDemotions());
|
|
@@ -25,7 +25,9 @@ import { appendImplicitFeedback } from '../store/implicit-feedback-store.js';
|
|
|
25
25
|
import { emitSolutionEvent, querySurfacedWithin } from '../core/observability-store.js';
|
|
26
26
|
import { parseSolutionV3 } from '../engine/solution-format.js';
|
|
27
27
|
import { ME_SOLUTIONS } from '../core/paths.js';
|
|
28
|
-
|
|
28
|
+
// 2026-10-07: 20→60 — critic 룰의 실행 증거 판정(stop-guard tool_evidence)이 'critic 실행 → 수정 수십 회 → 커밋' 흐름에서
|
|
29
|
+
// critic 호출이 창 밖으로 밀려 오탐하지 않도록. 측정 도구 집계는 끝에서 세므로 영향 없음.
|
|
30
|
+
const RECENT_TOOL_NAMES_WINDOW = 60;
|
|
29
31
|
/** Lightweight hash for content comparison (not cryptographic) */
|
|
30
32
|
function simpleHash(content) {
|
|
31
33
|
let hash = 0;
|
|
@@ -25,18 +25,21 @@ export declare const DEFAULT_STOP_TRIGGER_RE = "(\uC644\uB8CC\uD588|\uC644\uC131
|
|
|
25
25
|
export declare const DEFAULT_STOP_EXCLUDE_RE = "(\uCDE8\uC18C|\uCCA0\uD68C|\uC5C6\uC74C|\uC5C6\uC2B5\uB2C8\uB2E4|\uC54A\uC558|\uD558\uC9C0\\s*\uC54A|\uC544\uB2D9\uB2C8\uB2E4|not\\s*yet|no\\s*longer|retract|withdraw|\uC544\uC9C1\\s*(\uC548|\uC544))";
|
|
26
26
|
/** mock/stub/fake 감지 — R-B2 전용 pattern (자가검증 주장 차단). */
|
|
27
27
|
export declare const MOCK_TRIGGER_RE = "(mock|stub|fake)";
|
|
28
|
-
/**
|
|
29
|
-
|
|
28
|
+
/**
|
|
29
|
+
* mock trigger 의 exclude — 테스트 맥락은 정상. 2026-10-07: 문장 단위 판정으로 바뀌며 추가 —
|
|
30
|
+
* mock 을 **벗어나는** 서술(해소·제거·대체·라이브로 재검증·실제 실행·아님)은 위반 주장이 아니다(실측 오탐 예시 근거).
|
|
31
|
+
*/
|
|
32
|
+
export declare const MOCK_EXCLUDE_RE = "(\uD14C\uC2A4\uD2B8|test|vi\\.mock|jest\\.mock|spec\\.|\uD574\uC18C|\uC81C\uAC70|\uAC77\uC5B4|\uB300\uCCB4|\uAD50\uCCB4|\uB300\uC2E0|\uB77C\uC774\uBE0C|live|\uC2E4\uC81C\\s?(\uC2E4\uD589|\uB370\uC774\uD130|\uD658\uACBD)|\uC2E4\\s?(\uB370\uC774\uD130|\uC601\uC0C1|\uD658\uACBD)|\uC544\uB2C8|\uC54A|\uC5C6\uC774|\uC5C6\uC2B5\uB2C8\uB2E4|\uAE08\uC9C0|\uB8F0|\uADDC\uCE59|instead|real\\s)";
|
|
30
33
|
/**
|
|
31
34
|
* "리뷰 생략" AND "다음으로 넘어감" 이 함께 있을 때만 발화하는 결합 트리거.
|
|
32
35
|
* 두 lookahead 로 conjunction — 한쪽만 있는 경고/질문/신중 응답은 미발화(FP 0).
|
|
33
36
|
*/
|
|
34
|
-
export declare const SKIP_REVIEW_TRIGGER_RE = "(?=[\\s\\S]*?(?:(\uB9AC\uBDF0|\uAC80\uD1A0)[^.!?\\n]{0,8}(\uC0DD\uB7B5|\uAC74\uB108\uB6F0|\uC5C6\uC774|\uC2A4\uD0B5|\uD328\uC2A4|\uC548\\s*\uD558\uACE0)|skip(?:ping|s)?\\s+(?:the\\s+)?review))(?=[\\s\\S]*?(?:\uB118\uC5B4\uAC00|\uB118\uC5B4\uAC11|\uB118\uC5B4\uAC14|\uB118\uC5B4\uAC10|\uB118\uC5B4\uAC08|\uB2E4\uC74C\\s*(\uC791\uC5C5|\uAE30\uB2A5|\uB2E8\uACC4|\uC2A4\uD15D|\uAC83|\uC774\uD130\uB808\uC774\uC158)|move\\s+on|next\\s+(step|task|feature)|proceed))";
|
|
37
|
+
export declare const SKIP_REVIEW_TRIGGER_RE = "^(?=[\\s\\S]*?(?:(\uB9AC\uBDF0|\uAC80\uD1A0)[^.!?\\n]{0,8}(\uC0DD\uB7B5|\uAC74\uB108\uB6F0|\uC5C6\uC774|\uC2A4\uD0B5|\uD328\uC2A4|\uC548\\s*\uD558\uACE0)|skip(?:ping|s)?\\s+(?:the\\s+)?review))(?=[\\s\\S]*?(?:\uB118\uC5B4\uAC00|\uB118\uC5B4\uAC11|\uB118\uC5B4\uAC14|\uB118\uC5B4\uAC10|\uB118\uC5B4\uAC08|\uB2E4\uC74C\\s*(\uC791\uC5C5|\uAE30\uB2A5|\uB2E8\uACC4|\uC2A4\uD15D|\uAC83|\uC774\uD130\uB808\uC774\uC158)|move\\s+on|next\\s+(step|task|feature)|proceed))";
|
|
35
38
|
/**
|
|
36
39
|
* critic-review 룰 트리거 = 완료 선언 OR 리뷰생략-넘어감.
|
|
37
40
|
* (완료 시점 + skip 시점 양쪽에서 critic 강제. e2e/mock 룰엔 부여 안 함 — DEFAULT 만 사용.)
|
|
38
41
|
*/
|
|
39
|
-
export declare const CRITIC_STOP_TRIGGER_RE = "((\uC644\uB8CC\uD588|\uC644\uC131\uB410|\uC644\uC131\uB418|\uC644\uC131\uD588|done\\.|ready\\.|shipped\\.|LGTM|finished\\.)
|
|
42
|
+
export declare const CRITIC_STOP_TRIGGER_RE = "((\uC644\uB8CC\uD588|\uC644\uC131\uB410|\uC644\uC131\uB418|\uC644\uC131\uD588|done\\.|ready\\.|shipped\\.|LGTM|finished\\.)|^(?=[\\s\\S]*?(?:(\uB9AC\uBDF0|\uAC80\uD1A0)[^.!?\\n]{0,8}(\uC0DD\uB7B5|\uAC74\uB108\uB6F0|\uC5C6\uC774|\uC2A4\uD0B5|\uD328\uC2A4|\uC548\\s*\uD558\uACE0)|skip(?:ping|s)?\\s+(?:the\\s+)?review))(?=[\\s\\S]*?(?:\uB118\uC5B4\uAC00|\uB118\uC5B4\uAC11|\uB118\uC5B4\uAC14|\uB118\uC5B4\uAC10|\uB118\uC5B4\uAC08|\uB2E4\uC74C\\s*(\uC791\uC5C5|\uAE30\uB2A5|\uB2E8\uACC4|\uC2A4\uD15D|\uAC83|\uC774\uD130\uB808\uC774\uC158)|move\\s+on|next\\s+(step|task|feature)|proceed)))";
|
|
40
43
|
/**
|
|
41
44
|
* critic 트리거 exclude — 기본 retraction + 부정/금지/질문형 + 숙고형 보강.
|
|
42
45
|
* 주의: bare `안\s*하` 는 넣지 않는다 — "리뷰 안 하고 넘어감"(실제 skip TP)을 죽이므로.
|
|
@@ -44,3 +47,28 @@ export declare const CRITIC_STOP_TRIGGER_RE = "((\uC644\uB8CC\uD588|\uC644\uC131
|
|
|
44
47
|
* 아니라 결정 전 단계라 배제 (리뷰 SEV-3 (a)).
|
|
45
48
|
*/
|
|
46
49
|
export declare const CRITIC_STOP_EXCLUDE_RE: string;
|
|
50
|
+
/** 완료 선언 — 기존 + 실제 한국어 완료 보고 어휘(끝냈/끝났습니다/마쳤/마무리했/완료됐…). */
|
|
51
|
+
export declare const COMPLETION_TRIGGER_V2_RE = "(\uC644\uB8CC\uD588|\uC644\uB8CC\uB410|\uC644\uB8CC\uB418\uC5C8|\uC644\uB8CC\uC785\uB2C8\uB2E4|\uC644\uC131\uB410|\uC644\uC131\uB418|\uC644\uC131\uD588|\uB05D\uB0C8|\uB05D\uB0AC\uC2B5\uB2C8\uB2E4|\uB9C8\uCCE4|\uB9C8\uBB34\uB9AC\uD588|done\\.|ready\\.|shipped\\.|LGTM|finished\\.)";
|
|
52
|
+
/**
|
|
53
|
+
* 청크 경계 증거 — 커밋 해시(숫자와 a-f 를 모두 포함, 단어 경계) 또는 커밋·PR 언급·배포 동사·리뷰 생략.
|
|
54
|
+
* critic 룰은 이것이 메시지에 있을 때만 판정한다(상태 보고·대기 알림 제외). 트리거 lookahead 가 아니라
|
|
55
|
+
* verifier 의 only_if 로 선형 검사(critic SEV-2: lookahead 결합은 30k자에서 2.8s).
|
|
56
|
+
* 'feedback'(숫자 없음)·'20261007'(a-f 없음) 은 해시가 아니다.
|
|
57
|
+
*/
|
|
58
|
+
export declare const CHUNK_EVIDENCE_RE = "(\\b(?=[0-9a-f]*\\d)(?=[0-9a-f]*[a-f])[0-9a-f]{7,40}\\b|\uCEE4\uBC0B|commit|PR\\s?#?\\d+|\uCEE4\uBC0B\uD588|\uBA38\uC9C0\uD588|\uBC30\uD3EC\uD588|\uBC30\uD3EC\uAC00 \uB05D|\uD478\uC2DC\uD588|\uBC1C\uD589\uD588|\uB9B4\uB9AC\uC2A4\uD588|merged|committed|pushed|released|shipped|(\uB9AC\uBDF0|\uAC80\uD1A0)[^.!?\\n]{0,8}(\uC0DD\uB7B5|\uAC74\uB108\uB6F0|\uC5C6\uC774|\uC2A4\uD0B5|\uD328\uC2A4|\uC548\\s*\uD558\uACE0)|skip(?:ping|s)?\\s+(?:the\\s+)?review)";
|
|
59
|
+
/** critic 룰: 완료 선언 OR 커밋·머지·배포 OR (리뷰 생략 AND 넘어감). */
|
|
60
|
+
export declare const CRITIC_TRIGGER_V2_RE = "((\uC644\uB8CC\uD588|\uC644\uB8CC\uB410|\uC644\uB8CC\uB418\uC5C8|\uC644\uB8CC\uC785\uB2C8\uB2E4|\uC644\uC131\uB410|\uC644\uC131\uB418|\uC644\uC131\uD588|\uB05D\uB0C8|\uB05D\uB0AC\uC2B5\uB2C8\uB2E4|\uB9C8\uCCE4|\uB9C8\uBB34\uB9AC\uD588|done\\.|ready\\.|shipped\\.|LGTM|finished\\.)|\uCEE4\uBC0B\uD588|\uBA38\uC9C0\uD588|\uBC30\uD3EC\uD588|\uBC30\uD3EC\uAC00 \uB05D|\uD478\uC2DC\uD588|\uBC1C\uD589\uD588|\uB9B4\uB9AC\uC2A4\uD588|merged|committed|pushed|released|shipped|^(?=[\\s\\S]*?(?:(\uB9AC\uBDF0|\uAC80\uD1A0)[^.!?\\n]{0,8}(\uC0DD\uB7B5|\uAC74\uB108\uB6F0|\uC5C6\uC774|\uC2A4\uD0B5|\uD328\uC2A4|\uC548\\s*\uD558\uACE0)|skip(?:ping|s)?\\s+(?:the\\s+)?review))(?=[\\s\\S]*?(?:\uB118\uC5B4\uAC00|\uB118\uC5B4\uAC11|\uB118\uC5B4\uAC14|\uB118\uC5B4\uAC10|\uB118\uC5B4\uAC08|\uB2E4\uC74C\\s*(\uC791\uC5C5|\uAE30\uB2A5|\uB2E8\uACC4|\uC2A4\uD15D|\uAC83|\uC774\uD130\uB808\uC774\uC158)|move\\s+on|next\\s+(step|task|feature)|proceed)))";
|
|
61
|
+
/** mock 룰: 단어가 아니라 "그걸로 검증/통과했다"는 **주장**. 순서 양방향, 한 문장(40자) 안. */
|
|
62
|
+
export declare const MOCK_CLAIM_TRIGGER_RE = "((mock|stub|fake|\uBAA9\\s?\uAC1D\uCCB4|\uC2A4\uD141)[^.!?\\n]{0,40}(\uAC80\uC99D|\uD1B5\uACFC|\uD655\uC778\uD588|\uD655\uC778\uB410|\uD14C\uC2A4\uD2B8\\s?(\uD588|\uB410|\uC644\uB8CC)|verified|passed|green)|(\uAC80\uC99D|\uD1B5\uACFC|verified|passed)[^.!?\\n]{0,40}(mock|stub|fake|\uBAA9\\s?\uAC1D\uCCB4|\uC2A4\uD141))";
|
|
63
|
+
/** 격리 검증 룰: 실 데이터·프로덕션·live 에 대고 **돌렸다**는 주장. */
|
|
64
|
+
export declare const LIVE_RUN_TRIGGER_RE = "((\uC2E4\\s?(\uB370\uC774\uD130|\uD658\uACBD|\uD648|\uCFFC\uD130|\uC138\uC158)|\uD504\uB85C\uB355\uC158|\uC6B4\uC601\\s?\uD658\uACBD|live|\uB77C\uC774\uBE0C|~\\/\\.forgen|~\\/\\.claude)[^.!?\\n]{0,40}(\uB3CC\uB838|\uC2E4\uD589\uD588|\uC801\uC6A9\uD588|\uAC80\uC99D\uD588|\uBC18\uC601\uD588|ran|executed|applied))";
|
|
65
|
+
/**
|
|
66
|
+
* 구현 먼저 금지 룰: **합의 없이 바로 구현했다**는 보고 — "바로/먼저/일단 구현했", "구현부터 했".
|
|
67
|
+
* 일반 구현 보고("구현했습니다")까지 걸면 30일 실측 5.8% 턴에서 자기 신고 루프가 돌아 노이즈만 늘었다.
|
|
68
|
+
* 결정 문서·합의 언급이 메시지에 있으면 준수로 본다(부정 lookahead).
|
|
69
|
+
*/
|
|
70
|
+
export declare const IMPL_REPORT_TRIGGER_RE = "^(?![\\s\\S]*(\uACB0\uC815\\s?\uBB38\uC11C|docs\\/decisions|ADR-\\d|\uD569\uC758(\uD55C|\uB41C|\uD588|\uB97C\\s?\uAC70)|decision\\s+doc))[\\s\\S]*?((\uBC14\uB85C|\uBA3C\uC800|\uACE7\uBC14\uB85C|\uC77C\uB2E8|\uC6B0\uC120)\\s?(\uAD6C\uD604|\uCF54\uB4DC\\s?(\uB97C\\s?)?(\uC218\uC815|\uC791\uC131|\uBCC0\uACBD))(\uD588|\uD574\\s?(\uB480|\uB1A8|\uBC84\uB838))|\uAD6C\uD604\uBD80\uD130\\s?(\uD588|\uC9C4\uD589\uD588|\uC2DC\uC791\uD588))";
|
|
71
|
+
/** 기능을 빼는/보류하는 제안 어휘 — 주제 룰 결합용. */
|
|
72
|
+
export declare const DROP_PROPOSAL_RE = "\uBE7C(\uC790|\uB294\\s?\uAC8C|\uACE0|\uAE30\uB85C|\uBA74|\uACA0|\uB3C4\\s?\uB420|\uC57C)|\uBE84|\uC81C\uC678(\uD558\uC790|\uD558\uACE0|\uD558\uB294\\s?\uAC8C|\uD560|\uD558\uBA74|\uD569\uB2C8\uB2E4|\uD588|\uD558\uAE30\uB85C)|\uB4DC\uB86D|\uBBF8\uB8E8(\uC790|\uB294\\s?\uAC8C|\uACE0|\uAE30\uB85C)|drop|remove|defer";
|
|
73
|
+
/** 주제 룰: 룰이 명시한 기능 이름(topics) 중 하나 AND 빼기 제안. */
|
|
74
|
+
export declare function topicDropTrigger(topics: string[]): string;
|
|
@@ -25,8 +25,11 @@ export const DEFAULT_STOP_TRIGGER_RE = '(완료했|완성됐|완성되|완성했
|
|
|
25
25
|
export const DEFAULT_STOP_EXCLUDE_RE = '(취소|철회|없음|없습니다|않았|하지\\s*않|아닙니다|not\\s*yet|no\\s*longer|retract|withdraw|아직\\s*(안|아))';
|
|
26
26
|
/** mock/stub/fake 감지 — R-B2 전용 pattern (자가검증 주장 차단). */
|
|
27
27
|
export const MOCK_TRIGGER_RE = '(mock|stub|fake)';
|
|
28
|
-
/**
|
|
29
|
-
|
|
28
|
+
/**
|
|
29
|
+
* mock trigger 의 exclude — 테스트 맥락은 정상. 2026-10-07: 문장 단위 판정으로 바뀌며 추가 —
|
|
30
|
+
* mock 을 **벗어나는** 서술(해소·제거·대체·라이브로 재검증·실제 실행·아님)은 위반 주장이 아니다(실측 오탐 예시 근거).
|
|
31
|
+
*/
|
|
32
|
+
export const MOCK_EXCLUDE_RE = '(테스트|test|vi\\.mock|jest\\.mock|spec\\.|해소|제거|걷어|대체|교체|대신|라이브|live|실제\\s?(실행|데이터|환경)|실\\s?(데이터|영상|환경)|아니|않|없이|없습니다|금지|룰|규칙|instead|real\\s)';
|
|
30
33
|
// ── critic-review 룰 전용 트리거 (2026-07-22) ─────────────────────────────────
|
|
31
34
|
/** "리뷰/검토 생략" 시그널 (한/영). 외래어(스킵/패스)·구어(안 하고) 포함 — 리뷰 SEV-3 (a). */
|
|
32
35
|
const REVIEW_SKIP = '(리뷰|검토)[^.!?\\n]{0,8}(생략|건너뛰|없이|스킵|패스|안\\s*하고)|skip(?:ping|s)?\\s+(?:the\\s+)?review';
|
|
@@ -36,7 +39,8 @@ const MOVE_ON = '넘어가|넘어갑|넘어갔|넘어감|넘어갈|다음\\s*(
|
|
|
36
39
|
* "리뷰 생략" AND "다음으로 넘어감" 이 함께 있을 때만 발화하는 결합 트리거.
|
|
37
40
|
* 두 lookahead 로 conjunction — 한쪽만 있는 경고/질문/신중 응답은 미발화(FP 0).
|
|
38
41
|
*/
|
|
39
|
-
|
|
42
|
+
// 2026-10-07: `^` 고정 — 없으면 엔진이 모든 시작 위치에서 lookahead 를 다시 훑어 O(n²)(40k자 1s). m 플래그 없이 쓰므로 메시지 시작 1회만.
|
|
43
|
+
export const SKIP_REVIEW_TRIGGER_RE = `^(?=[\\s\\S]*?(?:${REVIEW_SKIP}))(?=[\\s\\S]*?(?:${MOVE_ON}))`;
|
|
40
44
|
/**
|
|
41
45
|
* critic-review 룰 트리거 = 완료 선언 OR 리뷰생략-넘어감.
|
|
42
46
|
* (완료 시점 + skip 시점 양쪽에서 critic 강제. e2e/mock 룰엔 부여 안 함 — DEFAULT 만 사용.)
|
|
@@ -50,3 +54,40 @@ export const CRITIC_STOP_TRIGGER_RE = `(${DEFAULT_STOP_TRIGGER_RE}|${SKIP_REVIEW
|
|
|
50
54
|
*/
|
|
51
55
|
export const CRITIC_STOP_EXCLUDE_RE = '(?:' + DEFAULT_STOP_EXCLUDE_RE +
|
|
52
56
|
'|말고|마세요|말라|안\\s*했|안\\s*해|안\\s*할|안\\s*돼|안\\s*됩|하세요|반드시|위험|should\\s*not|shouldn|don.?t|될까요|까요\\?|할지|갈지|여부|고민|결정하)';
|
|
57
|
+
// ── 2026-10-07 룰별 발동 조건 분리 (30일 대화 2,216턴 실측 근거) ─────────────────────────
|
|
58
|
+
// 실측: 모든 완료 룰이 같은 완료 어휘에 반응해 (a) 실제 답변("끝났습니다")엔 거의 안 걸리고(1.4%)
|
|
59
|
+
// (b) 걸릴 땐 룰 4개가 동시에 걸렸으며 (c) mock 룰은 단어만 있어도 발동해 무한 반복(7회)했다.
|
|
60
|
+
// 각 룰은 그 룰이 지키려는 **행동의 주장**에만 반응한다.
|
|
61
|
+
/** 완료 선언 — 기존 + 실제 한국어 완료 보고 어휘(끝냈/끝났습니다/마쳤/마무리했/완료됐…). */
|
|
62
|
+
export const COMPLETION_TRIGGER_V2_RE = '(완료했|완료됐|완료되었|완료입니다|완성됐|완성되|완성했|끝냈|끝났습니다|마쳤|마무리했|done\\.|ready\\.|shipped\\.|LGTM|finished\\.)';
|
|
63
|
+
/** 작업 청크 종료(커밋·머지·배포) — critic 룰 전용. */
|
|
64
|
+
const SHIP_VERBS = '커밋했|머지했|배포했|배포가 끝|푸시했|발행했|릴리스했|merged|committed|pushed|released|shipped';
|
|
65
|
+
/**
|
|
66
|
+
* 청크 경계 증거 — 커밋 해시(숫자와 a-f 를 모두 포함, 단어 경계) 또는 커밋·PR 언급·배포 동사·리뷰 생략.
|
|
67
|
+
* critic 룰은 이것이 메시지에 있을 때만 판정한다(상태 보고·대기 알림 제외). 트리거 lookahead 가 아니라
|
|
68
|
+
* verifier 의 only_if 로 선형 검사(critic SEV-2: lookahead 결합은 30k자에서 2.8s).
|
|
69
|
+
* 'feedback'(숫자 없음)·'20261007'(a-f 없음) 은 해시가 아니다.
|
|
70
|
+
*/
|
|
71
|
+
export const CHUNK_EVIDENCE_RE = `(\\b(?=[0-9a-f]*\\d)(?=[0-9a-f]*[a-f])[0-9a-f]{7,40}\\b|커밋|commit|PR\\s?#?\\d+|${SHIP_VERBS}|${REVIEW_SKIP})`;
|
|
72
|
+
/** critic 룰: 완료 선언 OR 커밋·머지·배포 OR (리뷰 생략 AND 넘어감). */
|
|
73
|
+
export const CRITIC_TRIGGER_V2_RE = `(${COMPLETION_TRIGGER_V2_RE}|${SHIP_VERBS}|${SKIP_REVIEW_TRIGGER_RE})`;
|
|
74
|
+
/** mock 룰: 단어가 아니라 "그걸로 검증/통과했다"는 **주장**. 순서 양방향, 한 문장(40자) 안. */
|
|
75
|
+
export const MOCK_CLAIM_TRIGGER_RE = '((mock|stub|fake|목\\s?객체|스텁)[^.!?\\n]{0,40}(검증|통과|확인했|확인됐|테스트\\s?(했|됐|완료)|verified|passed|green)|(검증|통과|verified|passed)[^.!?\\n]{0,40}(mock|stub|fake|목\\s?객체|스텁))';
|
|
76
|
+
/** 격리 검증 룰: 실 데이터·프로덕션·live 에 대고 **돌렸다**는 주장. */
|
|
77
|
+
export const LIVE_RUN_TRIGGER_RE = '((실\\s?(데이터|환경|홈|쿼터|세션)|프로덕션|운영\\s?환경|live|라이브|~\\/\\.forgen|~\\/\\.claude)[^.!?\\n]{0,40}(돌렸|실행했|적용했|검증했|반영했|ran|executed|applied))';
|
|
78
|
+
/**
|
|
79
|
+
* 구현 먼저 금지 룰: **합의 없이 바로 구현했다**는 보고 — "바로/먼저/일단 구현했", "구현부터 했".
|
|
80
|
+
* 일반 구현 보고("구현했습니다")까지 걸면 30일 실측 5.8% 턴에서 자기 신고 루프가 돌아 노이즈만 늘었다.
|
|
81
|
+
* 결정 문서·합의 언급이 메시지에 있으면 준수로 본다(부정 lookahead).
|
|
82
|
+
*/
|
|
83
|
+
export const IMPL_REPORT_TRIGGER_RE = '^(?![\\s\\S]*(결정\\s?문서|docs\\/decisions|ADR-\\d|합의(한|된|했|를\\s?거)|decision\\s+doc))[\\s\\S]*?((바로|먼저|곧바로|일단|우선)\\s?(구현|코드\\s?(를\\s?)?(수정|작성|변경))(했|해\\s?(뒀|놨|버렸))|구현부터\\s?(했|진행했|시작했))';
|
|
84
|
+
/** 기능을 빼는/보류하는 제안 어휘 — 주제 룰 결합용. */
|
|
85
|
+
// 명사로 쓰이는 '보류'(라벨 값)·'삭제'(기능 설명)는 실측 오탐이라 제외하고, 제안·결정 활용형만 본다.
|
|
86
|
+
export const DROP_PROPOSAL_RE = '빼(자|는\\s?게|고|기로|면|겠|도\\s?될|야)|뺄|제외(하자|하고|하는\\s?게|할|하면|합니다|했|하기로)|드롭|미루(자|는\\s?게|고|기로)|drop|remove|defer';
|
|
87
|
+
/** 주제 룰: 룰이 명시한 기능 이름(topics) 중 하나 AND 빼기 제안. */
|
|
88
|
+
export function topicDropTrigger(topics) {
|
|
89
|
+
const esc = topics.map((t) => t.replace(/[.*+?^${}()|[\]\\]/g, '\\$&').replace(/\s+/g, '\\s*'));
|
|
90
|
+
// 같은 문장(60자 안)에서 기능 이름과 빼기 제안이 함께 나올 때만 — 메시지 전체 결합은 실측에서 무관한 응답을 잡았다.
|
|
91
|
+
const t = `(?:${esc.join('|')})`;
|
|
92
|
+
return `(${t}[^.!?\\n]{0,60}(?:${DROP_PROPOSAL_RE})|(?:${DROP_PROPOSAL_RE})[^.!?\\n]{0,60}${t})`;
|
|
93
|
+
}
|
|
@@ -35,6 +35,7 @@ import { appendImplicitFeedback } from '../store/implicit-feedback-store.js';
|
|
|
35
35
|
import { emitSolutionEvent, querySurfacedWithin } from '../core/observability-store.js';
|
|
36
36
|
import { parseSolutionV3 } from '../engine/solution-format.js';
|
|
37
37
|
import { ME_SOLUTIONS } from '../core/paths.js';
|
|
38
|
+
import { buildContextTokens } from '../engine/context-signals.js';
|
|
38
39
|
const MAX_SOLUTIONS_PER_SESSION = 10;
|
|
39
40
|
/**
|
|
40
41
|
* Minimum relevance thresholds by fitness state (2026-04-21 gate sweep).
|
|
@@ -471,7 +472,8 @@ async function main() {
|
|
|
471
472
|
// allMatched는 backfill 용도로 보존: 이미 injected된 entry라도 같은 솔루션이
|
|
472
473
|
// 다시 매칭되면 그 정보로 cache의 missing tags를 채울 수 있다.
|
|
473
474
|
// matches는 새 주입 후보 (이미 injected는 제외).
|
|
474
|
-
const
|
|
475
|
+
const contextTokens = buildContextTokens(cwd, input.session_id);
|
|
476
|
+
const allMatched = matchSolutions(input.prompt, scope, cwd, contextTokens);
|
|
475
477
|
// Observability P1: matched emit — top-5 후보 각각 기록
|
|
476
478
|
try {
|
|
477
479
|
for (const candidate of allMatched.slice(0, 5)) {
|
|
@@ -571,10 +573,13 @@ async function main() {
|
|
|
571
573
|
for (const sol of matches) {
|
|
572
574
|
if (injected.has(sol.name))
|
|
573
575
|
continue;
|
|
574
|
-
|
|
576
|
+
// 맥락 가산은 순위에만 — relevance 하한 게이트는 가산 전 값으로 비교한다(맥락만으로 게이트 통과 금지).
|
|
577
|
+
if (sol.relevance - (sol.contextBonus ?? 0) < minRelevanceFor(sol.name))
|
|
575
578
|
continue;
|
|
576
579
|
const idMatches = sol.matchedIdentifiers?.length ?? 0;
|
|
577
580
|
const tagMatches = Math.max(0, sol.matchedTags.length - idMatches);
|
|
581
|
+
// 맥락 토큰(cwd/최근 편집 파일)은 relevance 가산에만 쓰고 이 게이트의 태그 수에는 넣지 않는다.
|
|
582
|
+
// 실측(S16): 범용 프롬프트 토큰 1개 + 맥락 3개를 0.5 가중으로 합산하면 무관한 솔루션이 통과했다.
|
|
578
583
|
if (idMatches < 1 && tagMatches < 2)
|
|
579
584
|
continue;
|
|
580
585
|
if (sol.status === 'experiment') {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
*/
|
|
21
21
|
import type { Rule } from '../store/types.js';
|
|
22
22
|
interface VerifierSpec {
|
|
23
|
-
kind: 'self_check_prompt' | 'artifact_check' | 'tool_arg_regex';
|
|
23
|
+
kind: 'self_check_prompt' | 'artifact_check' | 'tool_arg_regex' | 'tool_evidence' | 'language_ratio';
|
|
24
24
|
params: Record<string, string | number | boolean>;
|
|
25
25
|
}
|
|
26
26
|
interface SpikeRule {
|
|
@@ -56,7 +56,7 @@ interface SpikeRule {
|
|
|
56
56
|
*/
|
|
57
57
|
export declare function rulesFromStore(rules: Rule[]): SpikeRule[];
|
|
58
58
|
/** Pure core — 단위 테스트용. stdin/IO 없음. */
|
|
59
|
-
export declare function evaluateStop(lastAssistantMessage: string, rules: SpikeRule[]): {
|
|
59
|
+
export declare function evaluateStop(lastAssistantMessage: string, rules: SpikeRule[], recentTools?: string[]): {
|
|
60
60
|
action: 'approve';
|
|
61
61
|
hit: null;
|
|
62
62
|
passed: string[];
|