@triflux/core 10.50.1 → 10.50.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/hub/index.mjs +2 -8
- package/hub/lib/cto-env.mjs +0 -23
- package/hub/paths.mjs +0 -6
- package/hub/pipeline/index.mjs +0 -190
- package/hub/pipeline/transitions.mjs +0 -10
- package/hub/reflexion.mjs +1 -84
- package/hud/cli-policy.mjs +1 -5
- package/hud/colors.mjs +0 -13
- package/hud/constants.mjs +4 -135
- package/hud/context-monitor.mjs +3 -64
- package/hud/hud-qos-status.mjs +43 -225
- package/hud/providers/claude.mjs +4 -16
- package/hud/providers/gemini.mjs +7 -698
- package/hud/renderers.mjs +40 -294
- package/hud/terminal.mjs +1 -63
- package/hud/utils.mjs +0 -24
- package/package.json +1 -2
- package/scripts/lib/gemini-profiles.mjs +1 -1
- package/scripts/lib/legacy-mcp-cleanup.mjs +14 -3
- package/scripts/lib/psmux-info.mjs +18 -49
- package/scripts/lib/skill-template.mjs +0 -26
- package/hub/codex-compat.mjs +0 -12
- package/hub/fullcycle.mjs +0 -113
- package/hub/gemini-adapter.mjs +0 -174
- package/hub/intent.mjs +0 -321
- package/hub/lib/mcp-response-cache.mjs +0 -239
- package/hub/lib/path-utils.mjs +0 -165
- package/hub/lib/timeline-adapter.mjs +0 -190
- package/hub/pipeline/gates/confidence.mjs +0 -75
- package/hub/pipeline/gates/consensus.mjs +0 -106
- package/hub/pipeline/gates/index.mjs +0 -9
- package/hub/pipeline/gates/selfcheck.mjs +0 -120
- package/hub/quality/deslop.mjs +0 -274
- package/hub/research.mjs +0 -155
- package/hub/role-control-events.mjs +0 -113
- package/hub/routing/complexity.mjs +0 -269
- package/hub/routing/index.mjs +0 -122
- package/hub/routing/q-learning.mjs +0 -387
- package/hub/token-mode.mjs +0 -228
- package/hud/mission-board.mjs +0 -56
- package/hud/providers/cto.mjs +0 -76
- package/scripts/lib/agent-json.mjs +0 -27
- package/scripts/lib/async.mjs +0 -174
- package/scripts/lib/cli-agy.mjs +0 -85
- package/scripts/lib/cli-codex.mjs +0 -62
- package/scripts/lib/cli-gemini.mjs +0 -37
- package/scripts/lib/env.mjs +0 -14
- package/scripts/lib/hub.mjs +0 -48
- package/scripts/lib/pid.mjs +0 -63
- package/scripts/lib/quota.mjs +0 -47
- package/scripts/lib/skill-state.mjs +0 -220
- package/scripts/lib/team.mjs +0 -75
- package/scripts/lib/timeout.mjs +0 -66
- package/scripts/lib/tmp.mjs +0 -26
- package/scripts/lib/toml.mjs +0 -132
package/hub/lib/path-utils.mjs
DELETED
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
// hub/lib/path-utils.mjs — Windows/POSIX 경로 변환 유틸리티
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Windows 경로를 Git Bash 스타일 POSIX 경로로 변환한다.
|
|
5
|
-
* C:\foo\bar → /c/foo/bar
|
|
6
|
-
* 이미 POSIX 경로면 그대로 반환.
|
|
7
|
-
* null/undefined → 빈 문자열
|
|
8
|
-
* @param {string|null|undefined} windowsPath
|
|
9
|
-
* @returns {string}
|
|
10
|
-
*/
|
|
11
|
-
export function toPosixPath(windowsPath) {
|
|
12
|
-
if (windowsPath == null) return "";
|
|
13
|
-
const p = String(windowsPath);
|
|
14
|
-
if (!p) return "";
|
|
15
|
-
|
|
16
|
-
// 이미 POSIX 경로 (/ 로 시작하거나 드라이브 레터 없음)
|
|
17
|
-
const winDriveMatch = p.match(/^([A-Za-z]):[/\\](.*)/);
|
|
18
|
-
if (!winDriveMatch) {
|
|
19
|
-
// 백슬래시만 있는 상대 경로도 forward slash로 변환
|
|
20
|
-
return p.replace(/\\/g, "/");
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const drive = winDriveMatch[1].toLowerCase();
|
|
24
|
-
const rest = winDriveMatch[2].replace(/\\/g, "/");
|
|
25
|
-
return `/${drive}/${rest}`;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* POSIX 경로(Git Bash 스타일)를 Windows 경로로 변환한다.
|
|
30
|
-
* /c/foo/bar → C:\foo\bar
|
|
31
|
-
* 이미 Windows 경로면 그대로 반환.
|
|
32
|
-
* null/undefined → 빈 문자열
|
|
33
|
-
* @param {string|null|undefined} posixPath
|
|
34
|
-
* @returns {string}
|
|
35
|
-
*/
|
|
36
|
-
export function toWindowsPath(posixPath) {
|
|
37
|
-
if (posixPath == null) return "";
|
|
38
|
-
const p = String(posixPath);
|
|
39
|
-
if (!p) return "";
|
|
40
|
-
|
|
41
|
-
// 이미 Windows 경로
|
|
42
|
-
if (/^[A-Za-z]:/.test(p)) {
|
|
43
|
-
return p.replace(/\//g, "\\");
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Git Bash 스타일: /c/foo/bar
|
|
47
|
-
const gitBashMatch = p.match(/^\/([a-zA-Z])(\/.*)?$/);
|
|
48
|
-
if (gitBashMatch) {
|
|
49
|
-
const drive = gitBashMatch[1].toUpperCase();
|
|
50
|
-
const rest = gitBashMatch[2] ? gitBashMatch[2].replace(/\//g, "\\") : "\\";
|
|
51
|
-
return `${drive}:${rest}`;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return p;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* 현재 OS에 맞게 경로를 정규화한다.
|
|
59
|
-
* win32: backslash, 그 외: forward slash
|
|
60
|
-
* @param {string|null|undefined} p
|
|
61
|
-
* @returns {string}
|
|
62
|
-
*/
|
|
63
|
-
export function normalizePath(p) {
|
|
64
|
-
if (p == null) return "";
|
|
65
|
-
const str = String(p);
|
|
66
|
-
if (process.platform === "win32") {
|
|
67
|
-
return str.replace(/\//g, "\\");
|
|
68
|
-
}
|
|
69
|
-
return str.replace(/\\/g, "/");
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* 쉘 타입에 맞는 경로로 변환한다.
|
|
74
|
-
* @param {string|null|undefined} path
|
|
75
|
-
* @param {'git-bash'|'wsl'|'cmd'|'powershell'} shellType
|
|
76
|
-
* @returns {string}
|
|
77
|
-
*/
|
|
78
|
-
export function resolveShellPath(path, shellType) {
|
|
79
|
-
if (path == null) return "";
|
|
80
|
-
const p = String(path);
|
|
81
|
-
|
|
82
|
-
switch (shellType) {
|
|
83
|
-
case "git-bash":
|
|
84
|
-
return toPosixPath(p);
|
|
85
|
-
|
|
86
|
-
case "wsl": {
|
|
87
|
-
// Git Bash 경로를 먼저 Windows로 변환 후 WSL 형식으로
|
|
88
|
-
const winPath = /^[A-Za-z]:/.test(p) ? p : toWindowsPath(p);
|
|
89
|
-
const wslDriveMatch = winPath.match(/^([A-Za-z]):[/\\](.*)/);
|
|
90
|
-
if (wslDriveMatch) {
|
|
91
|
-
const drive = wslDriveMatch[1].toLowerCase();
|
|
92
|
-
const rest = wslDriveMatch[2].replace(/\\/g, "/");
|
|
93
|
-
return rest ? `/mnt/${drive}/${rest}` : `/mnt/${drive}`;
|
|
94
|
-
}
|
|
95
|
-
// 이미 /mnt/ 형식이면 그대로
|
|
96
|
-
if (p.startsWith("/mnt/")) return p;
|
|
97
|
-
return p.replace(/\\/g, "/");
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
case "cmd":
|
|
101
|
-
case "powershell":
|
|
102
|
-
return toWindowsPath(p);
|
|
103
|
-
|
|
104
|
-
default:
|
|
105
|
-
return p;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* 환경 변수와 플랫폼 정보로 현재 쉘 타입을 추론한다.
|
|
111
|
-
* @returns {'git-bash'|'wsl'|'cmd'|'powershell'|'unix'}
|
|
112
|
-
*/
|
|
113
|
-
export function detectShellType() {
|
|
114
|
-
// WSL 감지: WSL_DISTRO_NAME 또는 WSLENV
|
|
115
|
-
if (process.env.WSL_DISTRO_NAME || process.env.WSLENV) {
|
|
116
|
-
return "wsl";
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// Windows 플랫폼
|
|
120
|
-
if (process.platform === "win32") {
|
|
121
|
-
const shell = process.env.SHELL || "";
|
|
122
|
-
const term = process.env.TERM || "";
|
|
123
|
-
const msystem = process.env.MSYSTEM || "";
|
|
124
|
-
|
|
125
|
-
// Git Bash 감지: SHELL=/usr/bin/bash + MSYSTEM=MINGW64 등
|
|
126
|
-
if (
|
|
127
|
-
shell.includes("bash") ||
|
|
128
|
-
msystem.startsWith("MINGW") ||
|
|
129
|
-
msystem.startsWith("MSYS") ||
|
|
130
|
-
term === "xterm"
|
|
131
|
-
) {
|
|
132
|
-
return "git-bash";
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// PowerShell 감지
|
|
136
|
-
if (process.env.PSModulePath || process.env.PSHOME) {
|
|
137
|
-
return "powershell";
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
return "cmd";
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// 비-Windows
|
|
144
|
-
return "unix";
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* WSL 경로 여부를 확인한다 (/mnt/ 시작).
|
|
149
|
-
* @param {string|null|undefined} p
|
|
150
|
-
* @returns {boolean}
|
|
151
|
-
*/
|
|
152
|
-
export function isWslPath(p) {
|
|
153
|
-
if (p == null) return false;
|
|
154
|
-
return String(p).startsWith("/mnt/");
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Git Bash 경로 여부를 확인한다 (/c/ 또는 /d/ 등 단일 소문자 드라이브 레터).
|
|
159
|
-
* @param {string|null|undefined} p
|
|
160
|
-
* @returns {boolean}
|
|
161
|
-
*/
|
|
162
|
-
export function isGitBashPath(p) {
|
|
163
|
-
if (p == null) return false;
|
|
164
|
-
return /^\/[a-zA-Z](\/|$)/.test(String(p));
|
|
165
|
-
}
|
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
import { execFile } from "node:child_process";
|
|
2
|
-
import { existsSync } from "node:fs";
|
|
3
|
-
import { appendFile, mkdir, readFile } from "node:fs/promises";
|
|
4
|
-
import os from "node:os";
|
|
5
|
-
import path from "node:path";
|
|
6
|
-
import { promisify } from "node:util";
|
|
7
|
-
|
|
8
|
-
const execFileAsync = promisify(execFile);
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @typedef {object} TimelineEvent
|
|
12
|
-
* @property {string} skill
|
|
13
|
-
* @property {string} event
|
|
14
|
-
* @property {string} branch
|
|
15
|
-
* @property {string} session
|
|
16
|
-
* @property {string | undefined} [outcome]
|
|
17
|
-
* @property {number | undefined} [durationS]
|
|
18
|
-
* @property {string} ts
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @typedef {object} LogEventInput
|
|
23
|
-
* @property {string} skill
|
|
24
|
-
* @property {string} event
|
|
25
|
-
* @property {string} branch
|
|
26
|
-
* @property {string} session
|
|
27
|
-
* @property {string | undefined} [outcome]
|
|
28
|
-
* @property {number | undefined} [durationS]
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* @typedef {object} LastSessionQuery
|
|
33
|
-
* @property {string} branch
|
|
34
|
-
* @property {string | undefined} [skill]
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* @typedef {object} TimelineAdapter
|
|
39
|
-
* @property {(event: LogEventInput) => Promise<void>} logEvent
|
|
40
|
-
* @property {(n?: number) => Promise<TimelineEvent[]>} readRecent
|
|
41
|
-
* @property {(query: LastSessionQuery) => Promise<TimelineEvent | null>} getLastSession
|
|
42
|
-
*/
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* @typedef {object} DetectedTimelineAdapter
|
|
46
|
-
* @property {TimelineAdapter} adapter
|
|
47
|
-
* @property {"gstack" | "null"} kind
|
|
48
|
-
*/
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* @param {string} filePath
|
|
52
|
-
* @returns {Promise<TimelineEvent[]>}
|
|
53
|
-
*/
|
|
54
|
-
async function readTimeline(filePath) {
|
|
55
|
-
try {
|
|
56
|
-
const content = await readFile(filePath, "utf8");
|
|
57
|
-
/** @type {TimelineEvent[]} */
|
|
58
|
-
const events = [];
|
|
59
|
-
|
|
60
|
-
for (const line of content.split(/\r?\n/)) {
|
|
61
|
-
if (!line.trim()) continue;
|
|
62
|
-
|
|
63
|
-
try {
|
|
64
|
-
events.push(JSON.parse(line));
|
|
65
|
-
} catch {
|
|
66
|
-
// Skip malformed lines to preserve remaining timeline history.
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return events;
|
|
71
|
-
} catch (error) {
|
|
72
|
-
if (
|
|
73
|
-
error &&
|
|
74
|
-
typeof error === "object" &&
|
|
75
|
-
"code" in error &&
|
|
76
|
-
error.code === "ENOENT"
|
|
77
|
-
) {
|
|
78
|
-
return [];
|
|
79
|
-
}
|
|
80
|
-
throw error;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* @param {string} filePath
|
|
86
|
-
* @param {LogEventInput} event
|
|
87
|
-
* @returns {Promise<void>}
|
|
88
|
-
*/
|
|
89
|
-
async function appendTimeline(filePath, event) {
|
|
90
|
-
await mkdir(path.dirname(filePath), { recursive: true });
|
|
91
|
-
const entry = {
|
|
92
|
-
...event,
|
|
93
|
-
ts: new Date().toISOString(),
|
|
94
|
-
};
|
|
95
|
-
await appendFile(filePath, `${JSON.stringify(entry)}\n`, "utf8");
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* @param {() => Promise<string>} resolveFilePath
|
|
100
|
-
* @returns {TimelineAdapter}
|
|
101
|
-
*/
|
|
102
|
-
function createTimelineAdapter(resolveFilePath) {
|
|
103
|
-
return {
|
|
104
|
-
async logEvent(event) {
|
|
105
|
-
const filePath = await resolveFilePath();
|
|
106
|
-
await appendTimeline(filePath, event);
|
|
107
|
-
},
|
|
108
|
-
|
|
109
|
-
async readRecent(n = 10) {
|
|
110
|
-
const filePath = await resolveFilePath();
|
|
111
|
-
const events = await readTimeline(filePath);
|
|
112
|
-
const limit = Number.isFinite(n) ? Math.trunc(n) : 10;
|
|
113
|
-
if (limit <= 0) return [];
|
|
114
|
-
return events.slice(-limit);
|
|
115
|
-
},
|
|
116
|
-
|
|
117
|
-
async getLastSession({ branch, skill }) {
|
|
118
|
-
const filePath = await resolveFilePath();
|
|
119
|
-
const events = await readTimeline(filePath);
|
|
120
|
-
|
|
121
|
-
for (let index = events.length - 1; index >= 0; index -= 1) {
|
|
122
|
-
const entry = events[index];
|
|
123
|
-
if (!entry?.session) continue;
|
|
124
|
-
if (entry.branch !== branch) continue;
|
|
125
|
-
if (skill && entry.skill !== skill) continue;
|
|
126
|
-
return entry;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return null;
|
|
130
|
-
},
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* @returns {Promise<string>}
|
|
136
|
-
*/
|
|
137
|
-
async function resolveRepoSlug() {
|
|
138
|
-
const { stdout } = await execFileAsync(
|
|
139
|
-
"git",
|
|
140
|
-
["rev-parse", "--show-toplevel"],
|
|
141
|
-
{
|
|
142
|
-
cwd: process.cwd(),
|
|
143
|
-
encoding: "utf8",
|
|
144
|
-
},
|
|
145
|
-
);
|
|
146
|
-
return path.basename(stdout.trim());
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* @returns {Promise<string>}
|
|
151
|
-
*/
|
|
152
|
-
async function resolveGstackTimelinePath() {
|
|
153
|
-
const slug = await resolveRepoSlug();
|
|
154
|
-
return path.join(os.homedir(), ".gstack", "projects", slug, "timeline.jsonl");
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* @returns {Promise<string>}
|
|
159
|
-
*/
|
|
160
|
-
async function resolveNullTimelinePath() {
|
|
161
|
-
return path.join(process.cwd(), ".omc", "timeline.jsonl");
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/** @type {TimelineAdapter} */
|
|
165
|
-
export const gstackTimelineAdapter = createTimelineAdapter(
|
|
166
|
-
resolveGstackTimelinePath,
|
|
167
|
-
);
|
|
168
|
-
|
|
169
|
-
/** @type {TimelineAdapter} */
|
|
170
|
-
export const nullTimelineAdapter = createTimelineAdapter(
|
|
171
|
-
resolveNullTimelinePath,
|
|
172
|
-
);
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* @returns {DetectedTimelineAdapter}
|
|
176
|
-
*/
|
|
177
|
-
export function detectAdapter() {
|
|
178
|
-
const gstackRoot = path.join(os.homedir(), ".gstack");
|
|
179
|
-
if (existsSync(gstackRoot)) {
|
|
180
|
-
return {
|
|
181
|
-
adapter: gstackTimelineAdapter,
|
|
182
|
-
kind: "gstack",
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
return {
|
|
187
|
-
adapter: nullTimelineAdapter,
|
|
188
|
-
kind: "null",
|
|
189
|
-
};
|
|
190
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
// hub/pipeline/gates/confidence.mjs — Pre-Execution Confidence Gate
|
|
2
|
-
//
|
|
3
|
-
// plan → prd → [confidence] → exec
|
|
4
|
-
// 5단계 확신도 검증: >=90% proceed / 70-89% alternative / <70% abort
|
|
5
|
-
|
|
6
|
-
export const CRITERIA = [
|
|
7
|
-
{ id: "no_duplicate", label: "중복 구현 없는지?", weight: 0.25 },
|
|
8
|
-
{ id: "architecture", label: "아키텍처 준수?", weight: 0.25 },
|
|
9
|
-
{ id: "docs_verified", label: "공식 문서 확인?", weight: 0.2 },
|
|
10
|
-
{ id: "oss_reference", label: "OSS 레퍼런스?", weight: 0.15 },
|
|
11
|
-
{ id: "root_cause", label: "근본 원인 파악?", weight: 0.15 },
|
|
12
|
-
];
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* 확신도 검증 실행
|
|
16
|
-
* @param {string|object} planArtifact - plan 단계에서 생성된 구현 계획
|
|
17
|
-
* @param {object} context - { checks?, codebaseFiles?, existingTests? }
|
|
18
|
-
* @param {object} [context.checks] - 각 기준별 점수 (boolean 또는 0-1 숫자)
|
|
19
|
-
* @returns {{ score: number, breakdown: Array, decision: string, reasoning: string }}
|
|
20
|
-
*/
|
|
21
|
-
export function runConfidenceCheck(planArtifact, context = {}) {
|
|
22
|
-
if (!planArtifact) {
|
|
23
|
-
return {
|
|
24
|
-
score: 0,
|
|
25
|
-
breakdown: CRITERIA.map((c) => ({
|
|
26
|
-
id: c.id,
|
|
27
|
-
label: c.label,
|
|
28
|
-
weight: c.weight,
|
|
29
|
-
score: 0,
|
|
30
|
-
passed: false,
|
|
31
|
-
})),
|
|
32
|
-
decision: "abort",
|
|
33
|
-
reasoning: "planArtifact가 제공되지 않았습니다.",
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const checks = context.checks || {};
|
|
38
|
-
|
|
39
|
-
const breakdown = CRITERIA.map((c) => {
|
|
40
|
-
const raw = checks[c.id];
|
|
41
|
-
const score =
|
|
42
|
-
typeof raw === "number" ? Math.max(0, Math.min(1, raw)) : raw ? 1 : 0;
|
|
43
|
-
return {
|
|
44
|
-
id: c.id,
|
|
45
|
-
label: c.label,
|
|
46
|
-
weight: c.weight,
|
|
47
|
-
score,
|
|
48
|
-
passed: score >= 0.7,
|
|
49
|
-
};
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
const totalScore = Math.round(
|
|
53
|
-
breakdown.reduce((sum, b) => sum + b.score * b.weight, 0) * 100,
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
let decision, reasoning;
|
|
57
|
-
if (totalScore >= 90) {
|
|
58
|
-
decision = "proceed";
|
|
59
|
-
reasoning = `확신도 ${totalScore}%: 모든 기준 충족. 실행 진행.`;
|
|
60
|
-
} else if (totalScore >= 70) {
|
|
61
|
-
decision = "alternative";
|
|
62
|
-
reasoning = `확신도 ${totalScore}%: 일부 기준 미달. 대안 검토 필요.`;
|
|
63
|
-
} else {
|
|
64
|
-
decision = "abort";
|
|
65
|
-
reasoning = `확신도 ${totalScore}%: 기준 미달. 실행 중단.`;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return {
|
|
69
|
-
score: totalScore,
|
|
70
|
-
breakdown,
|
|
71
|
-
decision,
|
|
72
|
-
reasoning,
|
|
73
|
-
needsReview: decision === "alternative",
|
|
74
|
-
};
|
|
75
|
-
}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
// hub/pipeline/gates/consensus.mjs — Consensus Quality Gate
|
|
2
|
-
//
|
|
3
|
-
// N개 결과의 합의도를 평가하여 5단계 분기 결정
|
|
4
|
-
// proceed(>=90%) / proceed_warn(>=75%) / retry(<75%+재시도) / escalate(<75%+감독) / abort
|
|
5
|
-
|
|
6
|
-
/** 단계별 합의 임계값 (%) */
|
|
7
|
-
export const STAGE_THRESHOLDS = {
|
|
8
|
-
plan: 50,
|
|
9
|
-
define: 75,
|
|
10
|
-
execute: 75,
|
|
11
|
-
verify: 80,
|
|
12
|
-
security: 100,
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
/** 환경변수 기반 기본 임계값 (기본 75) */
|
|
16
|
-
function getDefaultThreshold() {
|
|
17
|
-
const env =
|
|
18
|
-
typeof process !== "undefined" && process.env?.TRIFLUX_CONSENSUS_THRESHOLD;
|
|
19
|
-
if (env != null && env !== "") {
|
|
20
|
-
const parsed = Number(env);
|
|
21
|
-
if (!Number.isNaN(parsed) && parsed >= 0 && parsed <= 100) return parsed;
|
|
22
|
-
}
|
|
23
|
-
return 75;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* 성공률 기반 5단계 분기 결정
|
|
28
|
-
* @param {number} successRate - 합의 성공률 (0-100)
|
|
29
|
-
* @param {number} retryCount - 현재 재시도 횟수
|
|
30
|
-
* @param {number} maxRetries - 최대 재시도 횟수
|
|
31
|
-
* @param {string} [mode] - 실행 모드 ('supervised' | 기타)
|
|
32
|
-
* @returns {'proceed' | 'proceed_warn' | 'retry' | 'escalate' | 'abort'}
|
|
33
|
-
*/
|
|
34
|
-
export function evaluateQualityBranch(
|
|
35
|
-
successRate,
|
|
36
|
-
retryCount,
|
|
37
|
-
maxRetries,
|
|
38
|
-
mode,
|
|
39
|
-
) {
|
|
40
|
-
if (successRate >= 90) return "proceed";
|
|
41
|
-
if (successRate >= 75) return "proceed_warn";
|
|
42
|
-
|
|
43
|
-
// <75%: 재시도 가능 여부에 따라 분기
|
|
44
|
-
if (retryCount < maxRetries) return "retry";
|
|
45
|
-
if (mode === "supervised") return "escalate";
|
|
46
|
-
return "abort";
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* N개 결과의 합의도 평가
|
|
51
|
-
* @param {Array<{ success: boolean }>} results - 평가 대상 결과 배열
|
|
52
|
-
* @param {object} [options]
|
|
53
|
-
* @param {string} [options.stage] - 파이프라인 단계 (STAGE_THRESHOLDS 키)
|
|
54
|
-
* @param {number} [options.threshold] - 합의 임계값 직접 지정 (stage보다 우선)
|
|
55
|
-
* @param {number} [options.retryCount=0] - 현재 재시도 횟수
|
|
56
|
-
* @param {number} [options.maxRetries=2] - 최대 재시도 횟수
|
|
57
|
-
* @param {string} [options.mode] - 실행 모드 ('supervised' 등)
|
|
58
|
-
* @returns {{ successRate: number, threshold: number, decision: string, reasoning: string, results: Array }}
|
|
59
|
-
*/
|
|
60
|
-
export function evaluateConsensus(results, options = {}) {
|
|
61
|
-
if (!Array.isArray(results) || results.length === 0) {
|
|
62
|
-
return {
|
|
63
|
-
successRate: 0,
|
|
64
|
-
threshold: options.threshold ?? getDefaultThreshold(),
|
|
65
|
-
decision: "abort",
|
|
66
|
-
reasoning: "평가 대상 결과가 없습니다.",
|
|
67
|
-
results: [],
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const retryCount = options.retryCount ?? 0;
|
|
72
|
-
const maxRetries = options.maxRetries ?? 2;
|
|
73
|
-
const mode = options.mode;
|
|
74
|
-
|
|
75
|
-
// 임계값 결정: 직접 지정 > stage별 > 환경변수 > 기본 75
|
|
76
|
-
const threshold =
|
|
77
|
-
options.threshold ??
|
|
78
|
-
(options.stage && STAGE_THRESHOLDS[options.stage]) ??
|
|
79
|
-
getDefaultThreshold();
|
|
80
|
-
|
|
81
|
-
const successCount = results.filter((r) => r.success).length;
|
|
82
|
-
const successRate = Math.round((successCount / results.length) * 100);
|
|
83
|
-
|
|
84
|
-
const decision = evaluateQualityBranch(
|
|
85
|
-
successRate,
|
|
86
|
-
retryCount,
|
|
87
|
-
maxRetries,
|
|
88
|
-
mode,
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
const reasoningMap = {
|
|
92
|
-
proceed: `합의율 ${successRate}% (>= 90%): 전원 합의. 진행.`,
|
|
93
|
-
proceed_warn: `합의율 ${successRate}% (>= 75%): 부분 합의. 경고와 함께 진행.`,
|
|
94
|
-
retry: `합의율 ${successRate}% (< 75%): 재시도 ${retryCount + 1}/${maxRetries} 가능.`,
|
|
95
|
-
escalate: `합의율 ${successRate}% (< 75%): 감독 모드 에스컬레이션.`,
|
|
96
|
-
abort: `합의율 ${successRate}% (< 75%): 합의 실패. 중단.`,
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
return {
|
|
100
|
-
successRate,
|
|
101
|
-
threshold,
|
|
102
|
-
decision,
|
|
103
|
-
reasoning: reasoningMap[decision],
|
|
104
|
-
results,
|
|
105
|
-
};
|
|
106
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
// hub/pipeline/gates/index.mjs — Quality Gates re-export
|
|
2
|
-
|
|
3
|
-
export { CRITERIA, runConfidenceCheck } from "./confidence.mjs";
|
|
4
|
-
export {
|
|
5
|
-
evaluateConsensus,
|
|
6
|
-
evaluateQualityBranch,
|
|
7
|
-
STAGE_THRESHOLDS,
|
|
8
|
-
} from "./consensus.mjs";
|
|
9
|
-
export { QUESTIONS, RED_FLAGS, runSelfCheck } from "./selfcheck.mjs";
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
// hub/pipeline/gates/selfcheck.mjs — Post-Execution Self-Check (Hallucination Detection)
|
|
2
|
-
//
|
|
3
|
-
// exec → verify → [selfcheck] → complete/fix
|
|
4
|
-
// 4대 필수 질문 + 7대 할루시네이션 Red Flag 탐지
|
|
5
|
-
|
|
6
|
-
export const RED_FLAGS = [
|
|
7
|
-
{
|
|
8
|
-
id: "test_pass_no_output",
|
|
9
|
-
pattern: /테스트\s*(?:가\s*)?통과/,
|
|
10
|
-
label: '"테스트 통과" (출력 없이)',
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
id: "everything_works",
|
|
14
|
-
pattern: /모든\s*게?\s*작동/,
|
|
15
|
-
label: '"모든게 작동" (증거 없이)',
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
id: "no_changes_with_diff",
|
|
19
|
-
pattern: /변경\s*(?:사항\s*)?없/,
|
|
20
|
-
label: '"변경 없음" (diff 있는데)',
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
id: "backward_compatible",
|
|
24
|
-
pattern: /호환성\s*(?:이\s*)?유지/,
|
|
25
|
-
label: '"호환성 유지" (검증 없이)',
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
id: "performance_improved",
|
|
29
|
-
pattern: /성능\s*(?:이\s*)?개선/,
|
|
30
|
-
label: '"성능 개선" (벤치마크 없이)',
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
id: "security_enhanced",
|
|
34
|
-
pattern: /보안\s*(?:이\s*)?강화/,
|
|
35
|
-
label: '"보안 강화" (증거 없이)',
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
id: "error_handling_done",
|
|
39
|
-
pattern: /에러\s*처리\s*(?:가\s*)?완료/,
|
|
40
|
-
label: '"에러 처리 완료" (catch 블록만)',
|
|
41
|
-
},
|
|
42
|
-
];
|
|
43
|
-
|
|
44
|
-
export const QUESTIONS = [
|
|
45
|
-
{
|
|
46
|
-
id: "tests_passing",
|
|
47
|
-
label: "모든 테스트 통과?",
|
|
48
|
-
evidenceKey: "testOutput",
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
id: "requirements_met",
|
|
52
|
-
label: "모든 요구사항 충족?",
|
|
53
|
-
evidenceKey: "requirementChecklist",
|
|
54
|
-
},
|
|
55
|
-
{ id: "no_assumptions", label: "검증 없는 가정?", evidenceKey: "references" },
|
|
56
|
-
{ id: "evidence_provided", label: "증거 있는가?", evidenceKey: "artifacts" },
|
|
57
|
-
];
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Red Flag 스캔 — 텍스트에서 할루시네이션 패턴 탐지
|
|
61
|
-
* @param {string} text - 스캔 대상 텍스트
|
|
62
|
-
* @param {object} context - { hasDiff?, evidence? }
|
|
63
|
-
* @returns {Array<{ id: string, label: string }>}
|
|
64
|
-
*/
|
|
65
|
-
function detectRedFlags(text, context = {}) {
|
|
66
|
-
const flags = [];
|
|
67
|
-
const evidence = context.evidence || {};
|
|
68
|
-
|
|
69
|
-
for (const rf of RED_FLAGS) {
|
|
70
|
-
if (!rf.pattern.test(text)) continue;
|
|
71
|
-
|
|
72
|
-
// "변경 없음"은 실제 diff가 있을 때만 Red Flag
|
|
73
|
-
if (rf.id === "no_changes_with_diff" && !context.hasDiff) continue;
|
|
74
|
-
|
|
75
|
-
// "테스트 통과"는 testOutput 증거가 없을 때만 Red Flag
|
|
76
|
-
if (rf.id === "test_pass_no_output" && evidence.testOutput) continue;
|
|
77
|
-
|
|
78
|
-
// 기타 Red Flag는 해당 id의 반증이 있으면 스킵
|
|
79
|
-
if (evidence[rf.id]) continue;
|
|
80
|
-
|
|
81
|
-
flags.push({ id: rf.id, label: rf.label });
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return flags;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Self-Check 실행
|
|
89
|
-
* @param {string|object} execResult - 실행 결과 (텍스트 또는 객체)
|
|
90
|
-
* @param {string|object} verifyResult - 검증 결과 (텍스트 또는 객체)
|
|
91
|
-
* @param {object} requirements - { hasDiff?, evidence? }
|
|
92
|
-
* @param {boolean} [requirements.hasDiff] - diff 존재 여부
|
|
93
|
-
* @param {object} [requirements.evidence] - { testOutput, requirementChecklist, references, artifacts }
|
|
94
|
-
* @returns {{ passed: boolean, score: number, flags: Array, checklist: Array }}
|
|
95
|
-
*/
|
|
96
|
-
export function runSelfCheck(execResult, verifyResult, requirements = {}) {
|
|
97
|
-
const normalize = (v) =>
|
|
98
|
-
typeof v === "string" ? v : v != null ? JSON.stringify(v) : "";
|
|
99
|
-
const text = [normalize(execResult), normalize(verifyResult)].join("\n");
|
|
100
|
-
|
|
101
|
-
const flags = detectRedFlags(text, requirements);
|
|
102
|
-
|
|
103
|
-
const evidence = requirements.evidence || {};
|
|
104
|
-
const checklist = QUESTIONS.map((q) => {
|
|
105
|
-
const ev = evidence[q.evidenceKey];
|
|
106
|
-
const passed =
|
|
107
|
-
ev != null && (typeof ev === "string" ? ev.trim().length > 0 : true);
|
|
108
|
-
return { id: q.id, label: q.label, passed, evidence: ev || null };
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
const allQuestionsPassed = checklist.every((q) => q.passed);
|
|
112
|
-
const passed = flags.length === 0 && allQuestionsPassed;
|
|
113
|
-
|
|
114
|
-
// 점수: 기본 100, Red Flag당 -15, 실패 질문당 -20
|
|
115
|
-
const flagPenalty = flags.length * 15;
|
|
116
|
-
const questionPenalty = checklist.filter((q) => !q.passed).length * 20;
|
|
117
|
-
const score = Math.max(0, 100 - flagPenalty - questionPenalty);
|
|
118
|
-
|
|
119
|
-
return { passed, score, flags, checklist };
|
|
120
|
-
}
|