workq-mcp 0.1.1 → 0.1.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/lib/natural-git.mjs +173 -62
- package/package.json +1 -1
package/lib/natural-git.mjs
CHANGED
|
@@ -152,48 +152,138 @@ function compact(value, maxLength = 220) {
|
|
|
152
152
|
return `${normalized.slice(0, maxLength - 3).trim()}...`;
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
-
function
|
|
156
|
-
|
|
157
|
-
if (/^(import\s|from\s+|const\s+\w+\s*=\s*require\(|require\(|#include|using\s+|use\s+)/.test(line)) return "import";
|
|
158
|
-
if (/^(export\s|module\.exports|exports\.)/.test(line)) return "export";
|
|
159
|
-
if (/^(?:async\s+)?function\s+|^(?:export\s+)?(?:const|let|var)\s+\w+\s*=.*=>|^def\s+|^function\s+/.test(line)) return "function";
|
|
160
|
-
if (/^class\s+|^(?:export\s+)?class\s+|^(?:public\s+)?(?:final\s+)?class\s+/.test(line)) return "class";
|
|
161
|
-
if (/\bif\s*\(|^if\s+|^elif\s+|\belse\s+if\s*\(/.test(line)) return "if";
|
|
162
|
-
if (/\bfor\s*\(|^for\s+|\bwhile\s*\(|^while\s+/.test(line)) return "loop";
|
|
163
|
-
if (/\bswitch\s*\(|^match\s+/.test(line)) return "switch";
|
|
164
|
-
if (/\bcatch\s*\(|^except\s+/.test(line)) return "catch";
|
|
165
|
-
if (/^return\b/.test(line)) return "return";
|
|
166
|
-
if (/^throw\b|^raise\b/.test(line)) return "throw";
|
|
167
|
-
if (/^(const|let|var)\s+\w+\s*=|^[A-Za-z_$][\w$]*\s*=/.test(line)) return "assignment";
|
|
168
|
-
if (/\b(app|router)\.(get|post|put|patch|delete|use)\s*\(/i.test(line)) return "route";
|
|
169
|
-
if (/\.addEventListener\(/.test(line)) return "event";
|
|
170
|
-
if (/^SELECT\b|^INSERT\b|^UPDATE\b|^DELETE\b|^CREATE\b|^ALTER\b/i.test(line)) return "sql";
|
|
171
|
-
if (/^\{|\}|\]|\[|,$/.test(line)) return "structure";
|
|
172
|
-
return "statement";
|
|
155
|
+
function unique(values, limit = 40) {
|
|
156
|
+
return Array.from(new Set(values.filter(Boolean))).slice(0, limit);
|
|
173
157
|
}
|
|
174
158
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
if (
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
159
|
+
const NATURAL_SPEC_FORMAT_COMMENT = "<!-- workq-natural-spec-format: feature-v2 -->";
|
|
160
|
+
|
|
161
|
+
function stripTags(value) {
|
|
162
|
+
return value.replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function extractVisibleTexts(file) {
|
|
166
|
+
const texts = [];
|
|
167
|
+
const markupContent = file.content.replace(/<script\b[\s\S]*?<\/script>/gi, "").replace(/<style\b[\s\S]*?<\/style>/gi, "");
|
|
168
|
+
if (file.extension === ".html") {
|
|
169
|
+
for (const match of file.content.matchAll(/<title[^>]*>([\s\S]*?)<\/title>/gi)) texts.push(stripTags(match[1]));
|
|
170
|
+
for (const match of markupContent.matchAll(/>([^<>{}][^<>{}]{1,80})</g)) texts.push(stripTags(match[1]));
|
|
171
|
+
}
|
|
172
|
+
for (const match of file.content.matchAll(/\b(?:textContent|innerText|placeholder|aria-label|title)\s*=\s*["'`]([^"'`]{1,100})["'`]/g)) {
|
|
173
|
+
texts.push(stripTags(match[1]));
|
|
174
|
+
}
|
|
175
|
+
for (const match of file.content.matchAll(/<button[^>]*>([\s\S]{1,160}?)<\/button>/gi)) {
|
|
176
|
+
texts.push(stripTags(match[1]));
|
|
177
|
+
}
|
|
178
|
+
return unique(texts.map((item) => compact(item, 100)).filter((item) => item && !/^[{}()[\];,.]+$/.test(item)), 18);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function extractDesignFacts(file) {
|
|
182
|
+
if (![".css", ".html", ".tsx", ".jsx"].includes(file.extension)) return [];
|
|
183
|
+
const facts = [];
|
|
184
|
+
const colors = unique(Array.from(file.content.matchAll(/#[0-9a-fA-F]{3,8}|rgba?\([^)]+\)|hsla?\([^)]+\)/g)).map((match) => match[0]), 10);
|
|
185
|
+
const gradients = unique(Array.from(file.content.matchAll(/linear-gradient\([^)]+\)/g)).map((match) => match[0]), 6);
|
|
186
|
+
const radii = unique(Array.from(file.content.matchAll(/border-radius\s*:\s*([^;]+);/g)).map((match) => match[1].trim()), 6);
|
|
187
|
+
const shadows = unique(Array.from(file.content.matchAll(/box-shadow\s*:\s*([^;]+);/g)).map((match) => match[1].trim()), 6);
|
|
188
|
+
const layout = [];
|
|
189
|
+
if (/display\s*:\s*grid/.test(file.content)) layout.push("grid");
|
|
190
|
+
if (/display\s*:\s*flex/.test(file.content)) layout.push("flex");
|
|
191
|
+
if (/min-height\s*:\s*100vh/.test(file.content)) layout.push("full viewport height");
|
|
192
|
+
if (/justify-content\s*:\s*center|align-items\s*:\s*center/.test(file.content)) layout.push("centered alignment");
|
|
193
|
+
if (colors.length) facts.push(`색상 팔레트는 ${colors.join(", ")} 값을 포함한다.`);
|
|
194
|
+
if (gradients.length) facts.push(`그라데이션 배경/강조는 ${gradients.join(", ")} 형태를 사용한다.`);
|
|
195
|
+
if (layout.length) facts.push(`레이아웃은 ${unique(layout).join(", ")} 배치를 사용한다.`);
|
|
196
|
+
if (radii.length) facts.push(`둥근 모서리 값은 ${radii.join(", ")} 등이 관찰된다.`);
|
|
197
|
+
if (shadows.length) facts.push(`그림자 표현은 ${shadows.slice(0, 3).join(", ")} 값을 사용한다.`);
|
|
198
|
+
if (/@keyframes\s+([A-Za-z0-9_-]+)/.test(file.content)) {
|
|
199
|
+
facts.push(`애니메이션은 ${unique(Array.from(file.content.matchAll(/@keyframes\s+([A-Za-z0-9_-]+)/g)).map((match) => match[1])).join(", ")} keyframes를 사용한다.`);
|
|
200
|
+
}
|
|
201
|
+
return facts;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function extractDataModelFacts(file) {
|
|
205
|
+
const facts = [];
|
|
206
|
+
const schemaMatch = file.content.match(/new\s+mongoose\.Schema\s*\(\s*\{([\s\S]*?)\}\s*\)/m);
|
|
207
|
+
if (schemaMatch) {
|
|
208
|
+
const fields = [];
|
|
209
|
+
for (const match of schemaMatch[1].matchAll(/^\s*([A-Za-z_$][\w$]*)\s*:\s*([^,\n]+)/gm)) {
|
|
210
|
+
fields.push(`${match[1]}(${compact(match[2], 80)})`);
|
|
211
|
+
}
|
|
212
|
+
facts.push(fields.length ? `이 파일은 데이터 모델 스키마를 정의하며 필드는 ${fields.join(", ")} 이다.` : "이 파일은 데이터 모델 스키마를 정의한다.");
|
|
213
|
+
}
|
|
214
|
+
if (file.path === "package.json") {
|
|
215
|
+
const packageDoc = packageJsonDoc(file.content).split(/\r?\n/).filter((line) => line.startsWith("- `") || line.startsWith("- 패키지 이름"));
|
|
216
|
+
facts.push(...packageDoc.slice(0, 12));
|
|
217
|
+
}
|
|
218
|
+
return facts;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function extractEnvironmentFacts(file) {
|
|
222
|
+
const envVars = unique(
|
|
223
|
+
Array.from(file.content.matchAll(/process\.env(?:\.([A-Za-z_][A-Za-z0-9_]*)|\[["'`]([^"'`]+)["'`]\])/g)).map((match) => match[1] || match[2]),
|
|
224
|
+
18
|
|
225
|
+
);
|
|
226
|
+
const facts = [];
|
|
227
|
+
if (!envVars.length && !/get(DataDir|DbDir|WorkDir|AppUrl)|isMcpConfigured|getMiniAiConfig|isGithubCrudConfigured|requireEnv/.test(file.content)) return facts;
|
|
228
|
+
if (envVars.length) facts.push(`환경 변수 ${envVars.map((item) => `\`${item}\``).join(", ")} 값을 읽어 런타임 설정을 결정한다.`);
|
|
229
|
+
if (/getDataDir|getDbDir|getWorkDir/.test(file.content)) facts.push("데이터 저장 위치, SQLite DB 위치, 작업 파일 위치를 환경 변수와 기본값으로 분리한다.");
|
|
230
|
+
if (/getAppUrl/.test(file.content)) facts.push("앱 외부 URL은 환경 변수로 지정하고, 없으면 로컬 개발 URL을 기본값으로 사용한다.");
|
|
231
|
+
if (/isMcpConfigured|WORKQ_MCP_TOKEN/.test(file.content)) facts.push("MCP 토큰 설정 여부를 판단해 로컬 에이전트 연결 가능 상태를 구분한다.");
|
|
232
|
+
if (/getMiniAiConfig|isMiniAiConfigured|WORKQ_MINI_AI/.test(file.content)) facts.push("Mini AI endpoint, model, API key 설정을 하나의 구성값으로 묶어 triage 사용 가능 여부를 판단한다.");
|
|
233
|
+
if (/isGithubCrudConfigured|WORKQ_GITHUB_TOKEN/.test(file.content)) facts.push("GitHub CRUD token 존재 여부로 GitHub 작업 자동화 가능성을 판단한다.");
|
|
234
|
+
if (/requireEnv/.test(file.content)) facts.push("필수 환경 변수가 없으면 조용히 진행하지 않고 명시적인 설정 오류를 발생시킨다.");
|
|
235
|
+
return unique(facts, 10);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function extractFunctionalFacts(file, structure) {
|
|
239
|
+
const facts = [];
|
|
240
|
+
const environmentFacts = extractEnvironmentFacts(file);
|
|
241
|
+
const visibleTexts = extractVisibleTexts(file);
|
|
242
|
+
const conditionSummaries = structure.conditions
|
|
243
|
+
.map((item) => item.expression ?? item.signature ?? "")
|
|
244
|
+
.filter((item) => item && item.length <= 180 && !/[<>]/.test(item))
|
|
245
|
+
.slice(0, 10);
|
|
246
|
+
facts.push(...environmentFacts);
|
|
247
|
+
if (visibleTexts.length) facts.push(`사용자에게 보이는 주요 문구는 ${visibleTexts.map((item) => `"${item}"`).join(", ")} 이다.`);
|
|
248
|
+
if (structure.events.length) {
|
|
249
|
+
facts.push(`사용자 이벤트는 ${structure.events.map((item) => `${item.target}의 ${item.event}`).join(", ")} 흐름을 처리한다.`);
|
|
250
|
+
}
|
|
251
|
+
if (!environmentFacts.length && structure.functions.length) {
|
|
252
|
+
facts.push(`내부 동작 단위는 ${structure.functions.slice(0, 8).map((item) => `${item.name}()`).join(", ")} 등이며, 세부 구현 근거는 코드 근거 섹션에서 추적한다.`);
|
|
253
|
+
}
|
|
254
|
+
if (structure.routes.length) {
|
|
255
|
+
facts.push(`네트워크/라우트 흐름은 ${structure.routes.slice(0, 8).map((item) => `${item.kind} ${item.expression}`).join(", ")} 로 연결된다.`);
|
|
256
|
+
}
|
|
257
|
+
if (!environmentFacts.length && conditionSummaries.length) {
|
|
258
|
+
facts.push(`분기와 반복은 ${conditionSummaries.join("; ")} 조건을 기준으로 동작한다.`);
|
|
259
|
+
}
|
|
260
|
+
if (/\bfor\s*\(\s*let\s+([A-Za-z_$][\w$]*)\s*=\s*(\d+)\s*;\s*\1\s*<=\s*(\d+)/.test(file.content)) {
|
|
261
|
+
const loop = file.content.match(/\bfor\s*\(\s*let\s+([A-Za-z_$][\w$]*)\s*=\s*(\d+)\s*;\s*\1\s*<=\s*(\d+)/);
|
|
262
|
+
facts.push(`반복문은 ${loop[2]}부터 ${loop[3]}까지의 선택지 또는 결과 행을 자동 생성한다.`);
|
|
263
|
+
}
|
|
264
|
+
if (/document\.createElement\(["']button["']\)/.test(file.content)) facts.push("버튼 요소를 코드에서 자동 생성한다.");
|
|
265
|
+
if (/classList\.add\(["']active["']\)|classList\.remove\(["']active["']\)/.test(file.content)) facts.push("선택 상태는 active 클래스로 표시하고 이전 선택은 해제한다.");
|
|
266
|
+
if (/innerHTML\s*=/.test(file.content)) facts.push("사용자 선택 이후 결과 영역의 HTML을 새 내용으로 교체한다.");
|
|
267
|
+
return facts;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function buildVerificationFacts(file, structure) {
|
|
271
|
+
const facts = [];
|
|
272
|
+
if (extractVisibleTexts(file).length) facts.push("화면에 노출되는 문구와 버튼이 의도한 사용자 흐름을 설명하는지 확인한다.");
|
|
273
|
+
if (structure.events.length) facts.push("사용자 이벤트 실행 후 화면 상태와 데이터가 기대값으로 바뀌는지 확인한다.");
|
|
274
|
+
if (structure.conditions.length) facts.push("반복/조건의 경계값과 예외 흐름을 테스트한다.");
|
|
275
|
+
if (extractDataModelFacts(file).length) facts.push("저장되는 필드 이름, 타입, 필수 여부가 실제 데이터와 맞는지 확인한다.");
|
|
276
|
+
if (!facts.length) facts.push("이 파일이 제공하는 설정 또는 보조 로직이 연결된 기능에서 실제로 사용되는지 확인한다.");
|
|
277
|
+
return facts;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function sourceEvidenceFacts(file, structure) {
|
|
281
|
+
const evidence = [];
|
|
282
|
+
if (structure.functions.length) evidence.push(`함수/메서드: ${structure.functions.slice(0, 12).map((item) => `${item.name}(${item.line}행)`).join(", ")}`);
|
|
283
|
+
if (structure.variables.length) evidence.push(`주요 값: ${structure.variables.slice(0, 12).map((item) => `${item.name}(${item.line}행)`).join(", ")}`);
|
|
284
|
+
if (structure.events.length) evidence.push(`이벤트: ${structure.events.slice(0, 12).map((item) => `${item.event}(${item.line}행)`).join(", ")}`);
|
|
285
|
+
if (structure.selectors.length) evidence.push(`스타일 선택자: ${structure.selectors.slice(0, 12).join(", ")}`);
|
|
286
|
+
return evidence;
|
|
197
287
|
}
|
|
198
288
|
|
|
199
289
|
function extractStructure(lines) {
|
|
@@ -237,11 +327,20 @@ function packageJsonDoc(content) {
|
|
|
237
327
|
}
|
|
238
328
|
|
|
239
329
|
function sourceFileToDoc(file) {
|
|
240
|
-
const structure =
|
|
241
|
-
|
|
330
|
+
const structure = {
|
|
331
|
+
imports: [],
|
|
332
|
+
exports: [],
|
|
333
|
+
classes: [],
|
|
334
|
+
routes: [],
|
|
335
|
+
events: [],
|
|
336
|
+
selectors: [],
|
|
337
|
+
...extractStructure(file.lines)
|
|
338
|
+
};
|
|
242
339
|
const purpose =
|
|
243
340
|
file.path === "package.json"
|
|
244
341
|
? "패키지 이름, 실행 스크립트, 의존성, Node 런타임 조건을 정의한다."
|
|
342
|
+
: extractEnvironmentFacts(file).length
|
|
343
|
+
? "런타임 환경 변수와 기본값을 해석해 저장소, URL, MCP, Mini AI, GitHub 연결 상태를 결정한다."
|
|
245
344
|
: file.extension === ".css"
|
|
246
345
|
? "화면 요소의 레이아웃, 색상, 반응형 배치, 상호작용 상태를 정의한다."
|
|
247
346
|
: file.extension === ".html"
|
|
@@ -249,39 +348,50 @@ function sourceFileToDoc(file) {
|
|
|
249
348
|
: structure.functions.length
|
|
250
349
|
? "함수 단위로 데이터를 계산하거나 화면/파일/네트워크 동작을 수행한다."
|
|
251
350
|
: "레포 동작을 구성하는 설정, 데이터, 또는 보조 텍스트를 제공한다.";
|
|
351
|
+
const dataModelFacts = extractDataModelFacts(file);
|
|
352
|
+
const functionalFacts = extractFunctionalFacts(file, structure);
|
|
353
|
+
const designFacts = extractDesignFacts(file);
|
|
354
|
+
const verificationFacts = buildVerificationFacts(file, structure);
|
|
355
|
+
const evidenceFacts = sourceEvidenceFacts(file, structure);
|
|
356
|
+
const coreRules = unique(
|
|
357
|
+
[
|
|
358
|
+
...dataModelFacts,
|
|
359
|
+
...extractEnvironmentFacts(file),
|
|
360
|
+
...functionalFacts.filter((item) => /반복문|선택 상태|자동 생성|결과 영역|라우트|네트워크|분기/.test(item))
|
|
361
|
+
],
|
|
362
|
+
12
|
|
363
|
+
);
|
|
252
364
|
return [
|
|
253
365
|
`# ${file.path}`,
|
|
366
|
+
NATURAL_SPEC_FORMAT_COMMENT,
|
|
254
367
|
"",
|
|
255
|
-
"## 자연어 명세",
|
|
256
|
-
`이 파일은 ${file.language}
|
|
368
|
+
"## 기능 중심 자연어 명세",
|
|
369
|
+
`이 파일은 ${file.language} 파일이며, 제품 관점에서는 ${purpose}`,
|
|
257
370
|
"",
|
|
258
371
|
"## 파일 정보",
|
|
259
372
|
`- 원본 경로: \`${file.path}\``,
|
|
260
373
|
`- 언어/형식: ${file.language}`,
|
|
261
374
|
`- 총 라인 수: ${file.lines.length}`,
|
|
262
|
-
`- 감지된 함수/메서드: ${structure.functions.length}개`,
|
|
263
|
-
`- 감지된 조건/반복/예외 흐름: ${structure.conditions.length}개`,
|
|
264
375
|
"",
|
|
265
|
-
|
|
266
|
-
...
|
|
376
|
+
functionalFacts.length ? "## 사용자 기능과 동작" : "",
|
|
377
|
+
...functionalFacts.map((item) => `- ${item}`),
|
|
267
378
|
"",
|
|
268
|
-
|
|
269
|
-
...
|
|
379
|
+
coreRules.length ? "## 핵심 규칙" : "",
|
|
380
|
+
...coreRules.map((item) => `- ${item}`),
|
|
270
381
|
"",
|
|
271
|
-
|
|
272
|
-
...
|
|
382
|
+
designFacts.length ? "## 화면과 디자인 명세" : "",
|
|
383
|
+
...designFacts.map((item) => `- ${item}`),
|
|
273
384
|
"",
|
|
274
|
-
file.path
|
|
385
|
+
dataModelFacts.length && file.path !== "package.json" ? "## 데이터와 상태" : "",
|
|
386
|
+
...(file.path !== "package.json" ? dataModelFacts.map((item) => `- ${item}`) : []),
|
|
275
387
|
"",
|
|
276
|
-
"##
|
|
277
|
-
|
|
278
|
-
...lineSpec,
|
|
388
|
+
evidenceFacts.length ? "## 코드 근거" : "",
|
|
389
|
+
...evidenceFacts.map((item) => `- ${item}`),
|
|
279
390
|
"",
|
|
280
391
|
"## 검증 관점",
|
|
281
|
-
|
|
282
|
-
"- 라인별 자연어 실행 흐름은 원본 코드의 의미 있는 모든 라인을 대상으로 한다.",
|
|
392
|
+
...verificationFacts.map((item) => `- ${item}`),
|
|
283
393
|
"- 제품 의도와 코드가 다를 수 있으므로, 코드에서 관찰된 동작은 승인된 제품 의도가 아니라 검증 근거로 취급한다.",
|
|
284
|
-
"- 리포트 분류 시 이
|
|
394
|
+
"- 리포트 분류 시 이 문서는 기능 존재, 화면 동작, 입력/출력, 핵심 규칙의 근거로 사용한다."
|
|
285
395
|
].filter((line, index, array) => line || array[index - 1]).join("\n");
|
|
286
396
|
}
|
|
287
397
|
|
|
@@ -290,9 +400,10 @@ function overviewDoc({ projectKey, projectName, repository, root, sourceFiles })
|
|
|
290
400
|
for (const file of sourceFiles) byLanguage.set(file.language, (byLanguage.get(file.language) ?? 0) + 1);
|
|
291
401
|
return [
|
|
292
402
|
`# ${projectKey} 자연어 git 명세`,
|
|
403
|
+
NATURAL_SPEC_FORMAT_COMMENT,
|
|
293
404
|
"",
|
|
294
405
|
"## 의미",
|
|
295
|
-
"이 명세는 레포에 존재하는 코드 파일을
|
|
406
|
+
"이 명세는 레포에 존재하는 코드 파일을 제품 기능, 사용자 동작, 입력/출력, 화면/디자인, 데이터 규칙 중심의 자연어 Markdown 문서로 해석한 것이다. Work Q v2에서는 이 자연어 문서를 기준으로 리포트와 코드 변경을 판단한다.",
|
|
296
407
|
"",
|
|
297
408
|
"## 프로젝트",
|
|
298
409
|
`- 프로젝트 키: ${projectKey}`,
|
|
@@ -305,8 +416,8 @@ function overviewDoc({ projectKey, projectName, repository, root, sourceFiles })
|
|
|
305
416
|
...Array.from(byLanguage.entries()).map(([language, count]) => `- ${language}: ${count}개`),
|
|
306
417
|
"",
|
|
307
418
|
"## 운영 규칙",
|
|
308
|
-
"- 자연어 문서는 코드에서 관찰한
|
|
309
|
-
"- 각 코드 파일 문서는
|
|
419
|
+
"- 자연어 문서는 코드에서 관찰한 제품 기능과 검증 가능한 동작을 설명한다.",
|
|
420
|
+
"- 각 코드 파일 문서는 라인별 번역이 아니라 기능, 규칙, 화면, 데이터, 검증 관점 중심으로 작성한다.",
|
|
310
421
|
"- 코드의 현재 동작이 곧 제품 의도라는 뜻은 아니다.",
|
|
311
422
|
"- 오너가 자연어 커밋으로 승인한 내용만 다음 코드 변경의 기준이 된다.",
|
|
312
423
|
"- 코드가 바뀌면 이 자연어 git 명세도 다시 분석하거나 수정해야 한다."
|