@letra-ai/cli 0.1.12 → 0.1.14
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/.letra/adapters/opencode.json +19 -19
- package/.letra/specs/decision-new/acceptance.md +7 -0
- package/.letra/specs/decision-new/spec.md +29 -0
- package/.letra/specs/init-interactive/acceptance.md +7 -0
- package/.letra/specs/init-interactive/spec.md +29 -0
- package/.letra/specs/session-focus/acceptance.md +7 -0
- package/.letra/specs/session-focus/spec.md +30 -0
- package/.letra/specs/spec-templates-domain/acceptance.md +7 -0
- package/.letra/specs/spec-templates-domain/spec.md +29 -0
- package/.letra/specs/validate-config/spec.md +32 -0
- package/.letra/specs/validate-conflict/acceptance.md +7 -0
- package/.letra/specs/validate-conflict/spec.md +29 -0
- package/.letra/specs/validate-format-pr/acceptance.md +7 -0
- package/.letra/specs/validate-format-pr/spec.md +28 -0
- package/.letra/specs/validate-intelligence/spec.md +3 -0
- package/.letra/specs/validate-watch/acceptance.md +7 -0
- package/.letra/specs/validate-watch/spec.md +29 -0
- package/.letra/workspace.schema.json +30 -30
- package/README.md +78 -1
- package/dist/index.js +1338 -329
- package/package.json +59 -59
- package/tsup.config.ts +11 -0
- package/dist/index.cjs +0 -590
- package/dist/index.d.cts +0 -2
package/dist/index.js
CHANGED
|
@@ -1,31 +1,321 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
1
3
|
// src/index.ts
|
|
2
|
-
import {
|
|
4
|
+
import { readFileSync as readFileSync7 } from "fs";
|
|
5
|
+
import { join as join8, resolve as resolve7 } from "path";
|
|
6
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
7
|
+
import { Command as Command3 } from "commander";
|
|
3
8
|
|
|
4
|
-
// src/commands/
|
|
9
|
+
// src/commands/decision.ts
|
|
5
10
|
import {
|
|
6
|
-
copyFileSync,
|
|
7
11
|
existsSync,
|
|
8
12
|
mkdirSync,
|
|
13
|
+
readFileSync,
|
|
14
|
+
readdirSync,
|
|
9
15
|
writeFileSync
|
|
10
16
|
} from "fs";
|
|
11
17
|
import { join, resolve } from "path";
|
|
12
|
-
import { fileURLToPath } from "url";
|
|
13
18
|
import chalk from "chalk";
|
|
19
|
+
import { Command } from "commander";
|
|
20
|
+
function sanitizeTitle(title) {
|
|
21
|
+
return title.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
22
|
+
}
|
|
23
|
+
function today() {
|
|
24
|
+
return (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
25
|
+
}
|
|
26
|
+
function decisionCommand() {
|
|
27
|
+
const cmd = new Command("decision");
|
|
28
|
+
cmd.command("new <title>").description("Cria um novo Architecture Decision Record").action((title) => {
|
|
29
|
+
const root = resolve(process.cwd());
|
|
30
|
+
const decisionsDir = join(root, ".letra", "decisions");
|
|
31
|
+
const slug = sanitizeTitle(title);
|
|
32
|
+
const filePath = join(decisionsDir, `${slug}.md`);
|
|
33
|
+
if (!existsSync(decisionsDir)) {
|
|
34
|
+
mkdirSync(decisionsDir, { recursive: true });
|
|
35
|
+
}
|
|
36
|
+
if (existsSync(filePath)) {
|
|
37
|
+
console.log(
|
|
38
|
+
chalk.red(
|
|
39
|
+
`Decision "${slug}" already exists at .letra/decisions/${slug}.md`
|
|
40
|
+
)
|
|
41
|
+
);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const content = `# ${title}
|
|
45
|
+
|
|
46
|
+
**Date**: ${today()}
|
|
47
|
+
**Status**: proposed
|
|
48
|
+
|
|
49
|
+
## Context
|
|
50
|
+
|
|
51
|
+
Why is this decision needed? What problem does it solve?
|
|
52
|
+
|
|
53
|
+
## Decision
|
|
54
|
+
|
|
55
|
+
What was decided?
|
|
56
|
+
|
|
57
|
+
## Consequences
|
|
58
|
+
|
|
59
|
+
What are the trade-offs? What does this enable or prevent?
|
|
60
|
+
`;
|
|
61
|
+
writeFileSync(filePath, content);
|
|
62
|
+
console.log(
|
|
63
|
+
chalk.green(
|
|
64
|
+
`Decision "${slug}" created at .letra/decisions/${slug}.md`
|
|
65
|
+
)
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
cmd.command("list").description("Lista todos os Architecture Decision Records").action(() => {
|
|
69
|
+
const root = resolve(process.cwd());
|
|
70
|
+
const decisionsDir = join(root, ".letra", "decisions");
|
|
71
|
+
if (!existsSync(decisionsDir)) {
|
|
72
|
+
console.log(
|
|
73
|
+
chalk.yellow("No decisions directory found at .letra/decisions/")
|
|
74
|
+
);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const files = readdirSync(decisionsDir).filter((f) => f.endsWith(".md")).sort();
|
|
78
|
+
if (files.length === 0) {
|
|
79
|
+
console.log(chalk.yellow("No decisions found"));
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
for (const file of files) {
|
|
83
|
+
const content = readFileSync(join(decisionsDir, file), "utf-8");
|
|
84
|
+
const firstLine = content.split("\n")[0]?.replace(/^#\s*/, "").trim() || file;
|
|
85
|
+
console.log(`${chalk.cyan(file)} ${firstLine}`);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
return cmd;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// src/commands/focus.ts
|
|
92
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2, unlinkSync, writeFileSync as writeFileSync2 } from "fs";
|
|
93
|
+
import { join as join2, resolve as resolve2 } from "path";
|
|
94
|
+
import chalk2 from "chalk";
|
|
95
|
+
import { Command as Command2 } from "commander";
|
|
96
|
+
function extractOutcome(specDir) {
|
|
97
|
+
const specFile = join2(specDir, "spec.md");
|
|
98
|
+
if (!existsSync2(specFile)) return null;
|
|
99
|
+
const content = readFileSync2(specFile, "utf-8");
|
|
100
|
+
const match = content.match(/## Outcome\s+([\s\S]*?)(?=\n## |\n*$)/);
|
|
101
|
+
return match ? match[1].trim() : null;
|
|
102
|
+
}
|
|
103
|
+
function focus_default() {
|
|
104
|
+
return new Command2("focus").argument("[spec]", "Spec name to focus on").option("--clear", "Remove focus file").action((spec, options) => {
|
|
105
|
+
const root = resolve2(process.cwd());
|
|
106
|
+
const focusFile = join2(root, ".letra", "focus.md");
|
|
107
|
+
if (options.clear) {
|
|
108
|
+
if (existsSync2(focusFile)) {
|
|
109
|
+
unlinkSync(focusFile);
|
|
110
|
+
console.log(chalk2.green("Focus removed."));
|
|
111
|
+
} else {
|
|
112
|
+
console.log(chalk2.yellow("No focus to remove."));
|
|
113
|
+
}
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (spec) {
|
|
117
|
+
const specDir = join2(root, ".letra", "specs", spec);
|
|
118
|
+
const specFile = join2(specDir, "spec.md");
|
|
119
|
+
if (!existsSync2(specFile)) {
|
|
120
|
+
console.log(chalk2.red(`Spec "${spec}" not found`));
|
|
121
|
+
process.exit(1);
|
|
122
|
+
}
|
|
123
|
+
const outcome = extractOutcome(specDir);
|
|
124
|
+
const outcomeLine = `**Outcome**: ${outcome || spec}`;
|
|
125
|
+
const focusContent = [
|
|
126
|
+
`# Focus: ${spec}`,
|
|
127
|
+
"",
|
|
128
|
+
`**Path**: .letra/specs/${spec}/`,
|
|
129
|
+
outcomeLine,
|
|
130
|
+
""
|
|
131
|
+
].join("\n");
|
|
132
|
+
writeFileSync2(focusFile, focusContent);
|
|
133
|
+
console.log(chalk2.green(`Focus set to "${spec}".`));
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (existsSync2(focusFile)) {
|
|
137
|
+
console.log(readFileSync2(focusFile, "utf-8"));
|
|
138
|
+
} else {
|
|
139
|
+
console.log("Nenhum foco definido.");
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// src/commands/init.ts
|
|
145
|
+
import {
|
|
146
|
+
copyFileSync,
|
|
147
|
+
existsSync as existsSync3,
|
|
148
|
+
mkdirSync as mkdirSync2,
|
|
149
|
+
writeFileSync as writeFileSync3
|
|
150
|
+
} from "fs";
|
|
151
|
+
import { join as join3, resolve as resolve3 } from "path";
|
|
152
|
+
import { createInterface } from "readline";
|
|
153
|
+
import { fileURLToPath } from "url";
|
|
154
|
+
import chalk3 from "chalk";
|
|
14
155
|
import ora from "ora";
|
|
15
156
|
var __dirname = fileURLToPath(new URL(".", import.meta.url));
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
157
|
+
function ask(query, options) {
|
|
158
|
+
if (!process.stdin.isTTY) return Promise.resolve(options[0]);
|
|
159
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
160
|
+
return new Promise((resolve8) => {
|
|
161
|
+
const formatted = `${chalk3.cyan(query)} ${options.map((o) => chalk3.gray(`(${o})`)).join(" ")}
|
|
162
|
+
> `;
|
|
163
|
+
rl.question(formatted, (answer) => {
|
|
164
|
+
rl.close();
|
|
165
|
+
const trimmed = answer.trim().toLowerCase();
|
|
166
|
+
if (trimmed && options.some((o) => o.toLowerCase().startsWith(trimmed))) {
|
|
167
|
+
resolve8(
|
|
168
|
+
options.find((o) => o.toLowerCase().startsWith(trimmed)) ?? options[0]
|
|
169
|
+
);
|
|
170
|
+
} else if (trimmed && options.includes(trimmed)) {
|
|
171
|
+
resolve8(trimmed);
|
|
172
|
+
} else {
|
|
173
|
+
resolve8(options[0]);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
function adaptConfig(projectType) {
|
|
179
|
+
const config = {
|
|
180
|
+
"conteudo-minimo": { severity: "warning", minChars: 50 },
|
|
181
|
+
"consistencia-terminologia": { severity: "warning" },
|
|
182
|
+
"detecao-tom": {
|
|
183
|
+
severity: "warning",
|
|
184
|
+
blacklist: [
|
|
185
|
+
"tipo",
|
|
186
|
+
"t\xE1",
|
|
187
|
+
"pra",
|
|
188
|
+
"blz",
|
|
189
|
+
"kkk",
|
|
190
|
+
"eita",
|
|
191
|
+
"oi",
|
|
192
|
+
"oi pessoal"
|
|
193
|
+
]
|
|
194
|
+
},
|
|
195
|
+
"drift-temporal": { severity: "warning", maxDays: 30 },
|
|
196
|
+
"secoes-vazias": { severity: "warning" },
|
|
197
|
+
"acs-sem-metrica": { severity: "warning" },
|
|
198
|
+
"baixa-confianca": { severity: "warning" }
|
|
199
|
+
};
|
|
200
|
+
if (projectType === "library") {
|
|
201
|
+
config["detecao-tom"] = { severity: "off" };
|
|
202
|
+
config["drift-temporal"] = { severity: "warning", maxDays: 60 };
|
|
203
|
+
} else if (projectType === "mobile") {
|
|
204
|
+
config["drift-temporal"] = { severity: "error", maxDays: 14 };
|
|
205
|
+
config["baixa-confianca"] = { severity: "error" };
|
|
206
|
+
} else if (projectType === "cli") {
|
|
207
|
+
config["detecao-tom"] = { severity: "off" };
|
|
208
|
+
}
|
|
209
|
+
return JSON.stringify({ heuristics: config }, null, 2);
|
|
210
|
+
}
|
|
211
|
+
function adaptersForTool(tool) {
|
|
212
|
+
const all = ["cursor", "claude-code", "windsurf", "vscode", "opencode"];
|
|
213
|
+
if (tool === "todos") return all;
|
|
214
|
+
const map = {
|
|
215
|
+
opencode: ["opencode"],
|
|
216
|
+
cursor: ["cursor"],
|
|
217
|
+
windsurf: ["windsurf"],
|
|
218
|
+
"claude code": ["claude-code"],
|
|
219
|
+
"vscode copilot": ["vscode"]
|
|
220
|
+
};
|
|
221
|
+
return map[tool.toLowerCase()] || all;
|
|
222
|
+
}
|
|
223
|
+
function generateAdapterFiles(root, tools) {
|
|
224
|
+
const adapters = [];
|
|
225
|
+
const baseContent = (name, format) => `# Letra Context \u2014 ${name} Adapter
|
|
226
|
+
# Generated by letra init. Do not edit manually.
|
|
227
|
+
|
|
228
|
+
${format === "at" ? "# Context\n@.letra/context.md\n@.letra/constitution.md\n@.letra/glossary.md\n@.letra/focus.md\n" : `Read the following files before starting any task:
|
|
229
|
+
- .letra/context.md
|
|
230
|
+
- .letra/constitution.md
|
|
231
|
+
- .letra/glossary.md
|
|
232
|
+
- .letra/focus.md (if exists, defines current session focus)
|
|
233
|
+
`}
|
|
234
|
+
# Rules
|
|
235
|
+
- Always read specs in .letra/specs/ before writing code
|
|
236
|
+
- Run \`letra validate\` to check acceptance criteria
|
|
237
|
+
- Follow the constitution.md rules strictly
|
|
238
|
+
- Use formal tone in all generated content
|
|
239
|
+
`;
|
|
240
|
+
for (const tool of tools) {
|
|
241
|
+
switch (tool) {
|
|
242
|
+
case "cursor":
|
|
243
|
+
adapters.push({
|
|
244
|
+
path: join3(root, ".cursorrules"),
|
|
245
|
+
content: baseContent("Cursor", "at")
|
|
246
|
+
});
|
|
247
|
+
break;
|
|
248
|
+
case "claude-code":
|
|
249
|
+
adapters.push({
|
|
250
|
+
path: join3(root, "CLAUDE.md"),
|
|
251
|
+
content: baseContent("Claude Code", "text")
|
|
252
|
+
});
|
|
253
|
+
break;
|
|
254
|
+
case "windsurf":
|
|
255
|
+
adapters.push({
|
|
256
|
+
path: join3(root, ".windsurfrules"),
|
|
257
|
+
content: baseContent("Windsurf", "at")
|
|
258
|
+
});
|
|
259
|
+
break;
|
|
260
|
+
case "vscode":
|
|
261
|
+
adapters.push({
|
|
262
|
+
path: join3(root, ".github", "copilot-instructions.md"),
|
|
263
|
+
content: baseContent("VSCode Copilot", "text")
|
|
264
|
+
});
|
|
265
|
+
break;
|
|
266
|
+
case "opencode":
|
|
267
|
+
adapters.push({
|
|
268
|
+
path: join3(root, "AGENTS.md"),
|
|
269
|
+
content: baseContent("OpenCode", "text")
|
|
270
|
+
});
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
for (const { path, content } of adapters) {
|
|
275
|
+
const dir = join3(path, "..");
|
|
276
|
+
if (!existsSync3(dir)) mkdirSync2(dir, { recursive: true });
|
|
277
|
+
writeFileSync3(path, content);
|
|
278
|
+
console.log(` ${chalk3.gray("Created")} ${path.replace(`${root}/`, "")}`);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
async function init(targetPath, options) {
|
|
282
|
+
const root = resolve3(process.cwd(), targetPath || ".");
|
|
283
|
+
const letraDir = join3(root, ".letra");
|
|
19
284
|
const spinner = ora("Initializing Letra...").start();
|
|
20
|
-
if (
|
|
21
|
-
spinner.warn(
|
|
285
|
+
if (existsSync3(letraDir)) {
|
|
286
|
+
spinner.warn(chalk3.yellow(".letra/ already exists"));
|
|
22
287
|
return;
|
|
23
288
|
}
|
|
24
289
|
try {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
290
|
+
let projectType = "web-app";
|
|
291
|
+
let tool = "cursor";
|
|
292
|
+
if (options?.yes || !process.stdin.isTTY) {
|
|
293
|
+
projectType = "web-app";
|
|
294
|
+
tool = "todos";
|
|
295
|
+
} else {
|
|
296
|
+
spinner.stop();
|
|
297
|
+
projectType = await ask("Project type?", [
|
|
298
|
+
"web-app",
|
|
299
|
+
"cli",
|
|
300
|
+
"library",
|
|
301
|
+
"mobile"
|
|
302
|
+
]);
|
|
303
|
+
const toolNames = [
|
|
304
|
+
"Cursor",
|
|
305
|
+
"Windsurf",
|
|
306
|
+
"Claude Code",
|
|
307
|
+
"VSCode Copilot",
|
|
308
|
+
"OpenCode",
|
|
309
|
+
"Todos"
|
|
310
|
+
];
|
|
311
|
+
const answer = await ask("AI coding agent?", toolNames);
|
|
312
|
+
tool = answer.toLowerCase();
|
|
313
|
+
spinner.start();
|
|
314
|
+
}
|
|
315
|
+
mkdirSync2(join3(letraDir, "decisions"), { recursive: true });
|
|
316
|
+
mkdirSync2(join3(letraDir, "specs", "_template"), { recursive: true });
|
|
317
|
+
mkdirSync2(join3(letraDir, "adapters"), { recursive: true });
|
|
318
|
+
const templateDir = join3(__dirname, "..", "..", ".letra");
|
|
29
319
|
const templates = [
|
|
30
320
|
"context.md",
|
|
31
321
|
"constitution.md",
|
|
@@ -33,13 +323,11 @@ async function init(targetPath) {
|
|
|
33
323
|
"lessons-learned.md"
|
|
34
324
|
];
|
|
35
325
|
for (const file of templates) {
|
|
36
|
-
const src =
|
|
37
|
-
const dest =
|
|
38
|
-
if (
|
|
39
|
-
copyFileSync(src, dest);
|
|
40
|
-
}
|
|
326
|
+
const src = join3(templateDir, file);
|
|
327
|
+
const dest = join3(letraDir, file);
|
|
328
|
+
if (existsSync3(src)) copyFileSync(src, dest);
|
|
41
329
|
}
|
|
42
|
-
const specTemplate =
|
|
330
|
+
const specTemplate = join3(letraDir, "specs", "_template.md");
|
|
43
331
|
const specContent = `# Spec Template
|
|
44
332
|
|
|
45
333
|
## Outcome
|
|
@@ -57,82 +345,17 @@ O que explicitamente N\xC3O est\xE1 neste escopo.
|
|
|
57
345
|
## Context
|
|
58
346
|
Por que estamos construindo isso.
|
|
59
347
|
`;
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
- Always read specs in .letra/specs/ before writing code
|
|
72
|
-
- Run \`letra validate\` to check acceptance criteria
|
|
73
|
-
- Follow the constitution.md rules strictly
|
|
74
|
-
- Use formal tone in all generated content
|
|
75
|
-
`;
|
|
76
|
-
writeFileSync(cursorRulesPath, cursorRulesContent);
|
|
77
|
-
console.log(` ${chalk.gray("Created")} .cursorrules`);
|
|
78
|
-
const claudeMdPath = join(root, "CLAUDE.md");
|
|
79
|
-
const claudeMdContent = `# Letra Context \u2014 Claude Code Adapter
|
|
80
|
-
# Generated by letra init. Do not edit manually.
|
|
81
|
-
|
|
82
|
-
Read the following files before starting any task:
|
|
83
|
-
- .letra/context.md
|
|
84
|
-
- .letra/constitution.md
|
|
85
|
-
- .letra/glossary.md
|
|
86
|
-
|
|
87
|
-
# Rules
|
|
88
|
-
- Always check specs in .letra/specs/ before writing code
|
|
89
|
-
- Run \`letra validate\` to verify acceptance criteria
|
|
90
|
-
- Follow constitution.md strictly
|
|
91
|
-
- Use formal tone in all generated content
|
|
92
|
-
`;
|
|
93
|
-
writeFileSync(claudeMdPath, claudeMdContent);
|
|
94
|
-
console.log(` ${chalk.gray("Created")} CLAUDE.md`);
|
|
95
|
-
const windsurfRulesPath = join(root, ".windsurfrules");
|
|
96
|
-
const windsurfRulesContent = `# Letra Context \u2014 Windsurf Adapter
|
|
97
|
-
# Generated by letra init. Do not edit manually.
|
|
98
|
-
|
|
99
|
-
# Context
|
|
100
|
-
@.letra/context.md
|
|
101
|
-
@.letra/constitution.md
|
|
102
|
-
@.letra/glossary.md
|
|
103
|
-
|
|
104
|
-
# Rules
|
|
105
|
-
- Always read specs in .letra/specs/ before writing code
|
|
106
|
-
- Run \`letra validate\` to check acceptance criteria
|
|
107
|
-
- Follow the constitution.md rules strictly
|
|
108
|
-
- Use formal tone in all generated content
|
|
109
|
-
`;
|
|
110
|
-
writeFileSync(windsurfRulesPath, windsurfRulesContent);
|
|
111
|
-
console.log(` ${chalk.gray("Created")} .windsurfrules`);
|
|
112
|
-
const githubDir = join(root, ".github");
|
|
113
|
-
if (!existsSync(githubDir)) mkdirSync(githubDir, { recursive: true });
|
|
114
|
-
const copilotInstructionsPath = join(githubDir, "copilot-instructions.md");
|
|
115
|
-
const copilotInstructionsContent = `# Letra Context \u2014 VSCode Copilot Adapter
|
|
116
|
-
# Generated by letra init. Do not edit manually.
|
|
117
|
-
|
|
118
|
-
# Context
|
|
119
|
-
Read the following files before starting any task:
|
|
120
|
-
- .letra/context.md
|
|
121
|
-
- .letra/constitution.md
|
|
122
|
-
- .letra/glossary.md
|
|
123
|
-
|
|
124
|
-
# Rules
|
|
125
|
-
- Always check specs in .letra/specs/ before writing code
|
|
126
|
-
- Run \`letra validate\` to verify acceptance criteria
|
|
127
|
-
- Follow constitution.md strictly
|
|
128
|
-
- Use formal tone in all generated content
|
|
129
|
-
`;
|
|
130
|
-
writeFileSync(copilotInstructionsPath, copilotInstructionsContent);
|
|
131
|
-
console.log(` ${chalk.gray("Created")} .github/copilot-instructions.md`);
|
|
132
|
-
const vscodeDir = join(root, ".vscode");
|
|
133
|
-
if (!existsSync(vscodeDir)) mkdirSync(vscodeDir, { recursive: true });
|
|
134
|
-
const vscodeSettingsPath = join(vscodeDir, "settings.json");
|
|
135
|
-
const vscodeSettingsContent = `{
|
|
348
|
+
writeFileSync3(specTemplate, specContent);
|
|
349
|
+
const configPath = join3(letraDir, "config.json");
|
|
350
|
+
writeFileSync3(configPath, adaptConfig(projectType));
|
|
351
|
+
console.log(` ${chalk3.gray("Created")} .letra/config.json`);
|
|
352
|
+
const tools = adaptersForTool(tool);
|
|
353
|
+
generateAdapterFiles(root, tools);
|
|
354
|
+
if (tool === "todos" || tool === "vscode") {
|
|
355
|
+
const vscodeDir = join3(root, ".vscode");
|
|
356
|
+
if (!existsSync3(vscodeDir)) mkdirSync2(vscodeDir, { recursive: true });
|
|
357
|
+
const vscodeSettingsPath = join3(vscodeDir, "settings.json");
|
|
358
|
+
const vscodeSettingsContent = `{
|
|
136
359
|
"editor.formatOnSave": true,
|
|
137
360
|
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
|
138
361
|
"editor.codeActionsOnSave": {
|
|
@@ -141,25 +364,26 @@ Read the following files before starting any task:
|
|
|
141
364
|
"files.autoSave": "onFocusChange"
|
|
142
365
|
}
|
|
143
366
|
`;
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
367
|
+
writeFileSync3(vscodeSettingsPath, vscodeSettingsContent);
|
|
368
|
+
console.log(` ${chalk3.gray("Created")} .vscode/settings.json`);
|
|
369
|
+
}
|
|
370
|
+
spinner.succeed(chalk3.green(".letra/ initialized successfully"));
|
|
147
371
|
console.log("");
|
|
148
372
|
console.log(" Next steps:");
|
|
149
373
|
console.log(
|
|
150
|
-
` ${
|
|
374
|
+
` ${chalk3.cyan("letra spec new <name>")} Create your first spec`
|
|
151
375
|
);
|
|
152
|
-
console.log(` ${
|
|
376
|
+
console.log(` ${chalk3.cyan("letra lint")} Validate specs`);
|
|
153
377
|
} catch (error) {
|
|
154
|
-
spinner.fail(
|
|
378
|
+
spinner.fail(chalk3.red("Failed to initialize Letra"));
|
|
155
379
|
process.exit(1);
|
|
156
380
|
}
|
|
157
381
|
}
|
|
158
382
|
|
|
159
383
|
// src/commands/lint.ts
|
|
160
|
-
import { existsSync as
|
|
161
|
-
import { join as
|
|
162
|
-
import
|
|
384
|
+
import { existsSync as existsSync4, readFileSync as readFileSync3, readdirSync as readdirSync3 } from "fs";
|
|
385
|
+
import { join as join4, resolve as resolve4 } from "path";
|
|
386
|
+
import chalk4 from "chalk";
|
|
163
387
|
var REQUIRED_SECTIONS = [
|
|
164
388
|
"## Outcome",
|
|
165
389
|
"## Constraints",
|
|
@@ -168,27 +392,27 @@ var REQUIRED_SECTIONS = [
|
|
|
168
392
|
"## Context"
|
|
169
393
|
];
|
|
170
394
|
async function lint(targetPath) {
|
|
171
|
-
const root =
|
|
172
|
-
const specsDir =
|
|
173
|
-
if (!
|
|
395
|
+
const root = resolve4(process.cwd(), targetPath || ".");
|
|
396
|
+
const specsDir = join4(root, ".letra", "specs");
|
|
397
|
+
if (!existsSync4(specsDir)) {
|
|
174
398
|
console.log(
|
|
175
|
-
|
|
399
|
+
chalk4.red("Error: .letra/specs/ not found. Run 'letra init' first.")
|
|
176
400
|
);
|
|
177
401
|
process.exit(1);
|
|
178
402
|
}
|
|
179
403
|
const results = [];
|
|
180
404
|
let totalErrors = 0;
|
|
181
405
|
let totalWarnings = 0;
|
|
182
|
-
const entries =
|
|
406
|
+
const entries = readdirSync3(specsDir, { withFileTypes: true });
|
|
183
407
|
for (const entry of entries) {
|
|
184
408
|
if (!entry.isDirectory() || entry.name.startsWith("_")) continue;
|
|
185
|
-
const specFile =
|
|
409
|
+
const specFile = join4(specsDir, entry.name, "spec.md");
|
|
186
410
|
const errors = [];
|
|
187
411
|
const warnings = [];
|
|
188
|
-
if (!
|
|
412
|
+
if (!existsSync4(specFile)) {
|
|
189
413
|
errors.push("Missing spec.md");
|
|
190
414
|
} else {
|
|
191
|
-
const content =
|
|
415
|
+
const content = readFileSync3(specFile, "utf-8");
|
|
192
416
|
for (const section of REQUIRED_SECTIONS) {
|
|
193
417
|
if (!content.includes(section)) {
|
|
194
418
|
errors.push(`Missing section: ${section}`);
|
|
@@ -211,22 +435,22 @@ async function lint(targetPath) {
|
|
|
211
435
|
}
|
|
212
436
|
}
|
|
213
437
|
if (results.length === 0) {
|
|
214
|
-
console.log(
|
|
438
|
+
console.log(chalk4.green("All specs are valid"));
|
|
215
439
|
process.exit(0);
|
|
216
440
|
}
|
|
217
441
|
console.log("");
|
|
218
442
|
for (const result of results) {
|
|
219
|
-
console.log(
|
|
443
|
+
console.log(chalk4.bold(`
|
|
220
444
|
Spec: ${result.file}`));
|
|
221
445
|
for (const error of result.errors) {
|
|
222
|
-
console.log(
|
|
446
|
+
console.log(chalk4.red(` \u2717 ${error}`));
|
|
223
447
|
}
|
|
224
448
|
for (const warning of result.warnings) {
|
|
225
|
-
console.log(
|
|
449
|
+
console.log(chalk4.yellow(` \u26A0 ${warning}`));
|
|
226
450
|
}
|
|
227
451
|
}
|
|
228
452
|
console.log(
|
|
229
|
-
|
|
453
|
+
chalk4.gray(
|
|
230
454
|
`
|
|
231
455
|
${results.length} spec(s) with issues: ${totalErrors} error(s), ${totalWarnings} warning(s)`
|
|
232
456
|
)
|
|
@@ -235,26 +459,186 @@ ${results.length} spec(s) with issues: ${totalErrors} error(s), ${totalWarnings}
|
|
|
235
459
|
}
|
|
236
460
|
|
|
237
461
|
// src/commands/spec.ts
|
|
238
|
-
import {
|
|
239
|
-
|
|
240
|
-
|
|
462
|
+
import {
|
|
463
|
+
existsSync as existsSync5,
|
|
464
|
+
mkdirSync as mkdirSync3,
|
|
465
|
+
readFileSync as readFileSync4,
|
|
466
|
+
readdirSync as readdirSync4,
|
|
467
|
+
writeFileSync as writeFileSync4
|
|
468
|
+
} from "fs";
|
|
469
|
+
import { join as join5, resolve as resolve5 } from "path";
|
|
470
|
+
import chalk5 from "chalk";
|
|
241
471
|
import ora2 from "ora";
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
472
|
+
var builtInTemplates = {
|
|
473
|
+
"web-api": {
|
|
474
|
+
spec: `# Spec: {{name}}
|
|
475
|
+
|
|
476
|
+
## Outcome
|
|
477
|
+
Usu\xE1rio consegue fazer requisi\xE7\xF5es HTTP para a API e receber respostas padronizadas.
|
|
478
|
+
|
|
479
|
+
## Constraints
|
|
480
|
+
- RESTful\u9075\u5FAA (GET, POST, PUT, DELETE)
|
|
481
|
+
- Autentica\xE7\xE3o via Bearer token JWT
|
|
482
|
+
- Rate limiting: 100 req/min por usu\xE1rio
|
|
483
|
+
- Timeout m\xE1ximo de 30s por requisi\xE7\xE3o
|
|
484
|
+
|
|
485
|
+
## Exclusions
|
|
486
|
+
- WebSocket n\xE3o est\xE1 no escopo
|
|
487
|
+
- Upload de arquivos n\xE3o est\xE1 no escopo inicial
|
|
488
|
+
|
|
489
|
+
## Acceptance Criteria
|
|
490
|
+
- [ ] **CRUD**: CRUD completo para o recurso principal (GET, POST, PUT, DELETE retornam 200/201/204).
|
|
491
|
+
- [ ] **Autentica\xE7\xE3o**: Rota sem token retorna 401, rota com token inv\xE1lido retorna 403.
|
|
492
|
+
- [ ] **Valida\xE7\xE3o**: Payload inv\xE1lido retorna 422 com mensagem de erro descritiva.
|
|
493
|
+
- [ ] **Rate Limit**: Exceder 100 req/min retorna 429 com header Retry-After.
|
|
494
|
+
- [ ] **Pagina\xE7\xE3o**: GET com ?page=2&limit=10 retorna p\xE1gina correta com total count.
|
|
495
|
+
|
|
496
|
+
## Context
|
|
497
|
+
Template para APIs REST. Adaptado para o dom\xEDnio espec\xEDfico do projeto.`,
|
|
498
|
+
acceptance: `# Acceptance Criteria \u2014 {{name}}
|
|
499
|
+
|
|
500
|
+
- [ ] **CRUD**: CRUD completo para o recurso principal (GET, POST, PUT, DELETE retornam 200/201/204).
|
|
501
|
+
- [ ] **Autentica\xE7\xE3o**: Rota sem token retorna 401, rota com token inv\xE1lido retorna 403.
|
|
502
|
+
- [ ] **Valida\xE7\xE3o**: Payload inv\xE1lido retorna 422 com mensagem de erro descritiva.
|
|
503
|
+
- [ ] **Rate Limit**: Exceder 100 req/min retorna 429 com header Retry-After.
|
|
504
|
+
- [ ] **Pagina\xE7\xE3o**: GET com ?page=2&limit=10 retorna p\xE1gina correta com total count.`
|
|
505
|
+
},
|
|
506
|
+
"cli-tool": {
|
|
507
|
+
spec: `# Spec: {{name}}
|
|
508
|
+
|
|
509
|
+
## Outcome
|
|
510
|
+
Usu\xE1rio instala e executa a CLI, recebendo output formatado no terminal.
|
|
511
|
+
|
|
512
|
+
## Constraints
|
|
513
|
+
- Node.js 22+ como runtime
|
|
514
|
+
- Deve funcionar em Windows, macOS e Linux
|
|
515
|
+
- Exit codes seguem padr\xE3o Unix (0 sucesso, 1 erro)
|
|
516
|
+
- --help deve funcionar sem argumentos
|
|
517
|
+
|
|
518
|
+
## Exclusions
|
|
519
|
+
- UI gr\xE1fica n\xE3o est\xE1 no escopo
|
|
520
|
+
- Modo servidor/daemon n\xE3o est\xE1 no escopo
|
|
521
|
+
|
|
522
|
+
## Acceptance Criteria
|
|
523
|
+
- [ ] **Instala\xE7\xE3o**: CLI execut\xE1vel via npx/npm install -g sem erros.
|
|
524
|
+
- [ ] **--help**: Roda sem argumentos, exibe ajuda com subcomandos.
|
|
525
|
+
- [ ] **Subcomando**: Subcomando principal executa sem erros e exibe output.
|
|
526
|
+
- [ ] **Erro**: Subcomando inv\xE1lido exibe erro amig\xE1vel e exit 1.
|
|
527
|
+
- [ ] **Cross-platform**: Funciona em Windows (cmd/powershell), macOS (zsh) e Linux (bash).
|
|
528
|
+
|
|
529
|
+
## Context
|
|
530
|
+
Template para ferramentas de linha de comando. Adaptado para o escopo espec\xEDfico.`,
|
|
531
|
+
acceptance: `# Acceptance Criteria \u2014 {{name}}
|
|
532
|
+
|
|
533
|
+
- [ ] **Instala\xE7\xE3o**: CLI execut\xE1vel via npx/npm install -g sem erros.
|
|
534
|
+
- [ ] **--help**: Roda sem argumentos, exibe ajuda com subcomandos.
|
|
535
|
+
- [ ] **Subcomando**: Subcomando principal executa sem erros e exibe output.
|
|
536
|
+
- [ ] **Erro**: Subcomando inv\xE1lido exibe erro amig\xE1vel e exit 1.
|
|
537
|
+
- [ ] **Cross-platform**: Funciona em Windows (cmd/powershell), macOS (zsh) e Linux (bash).`
|
|
538
|
+
},
|
|
539
|
+
"mobile-feature": {
|
|
540
|
+
spec: `# Spec: {{name}}
|
|
541
|
+
|
|
542
|
+
## Outcome
|
|
543
|
+
Usu\xE1rio consegue acessar e interagir com a nova funcionalidade no aplicativo mobile.
|
|
544
|
+
|
|
545
|
+
## Constraints
|
|
546
|
+
- Suporte a iOS 16+ e Android 13+
|
|
547
|
+
- Offline-first: funcionalidade deve funcionar sem internet
|
|
548
|
+
- Tempo de resposta < 200ms para intera\xE7\xF5es locais
|
|
549
|
+
- Acessibilidade: VoiceOver (iOS) e TalkBack (Android)
|
|
550
|
+
|
|
551
|
+
## Exclusions
|
|
552
|
+
- Vers\xE3o web n\xE3o est\xE1 no escopo (mobile-only)
|
|
553
|
+
- Suporte a tablets \xE9 desej\xE1vel mas n\xE3o obrigat\xF3rio
|
|
554
|
+
|
|
555
|
+
## Acceptance Criteria
|
|
556
|
+
- [ ] **Tela principal**: Nova funcionalidade aparece na navega\xE7\xE3o principal.
|
|
557
|
+
- [ ] **Offline**: Funcionalidade completa funciona sem conex\xE3o de rede.
|
|
558
|
+
- [ ] **Performance**: Scroll da lista com 1000+ itens mant\xE9m 60fps.
|
|
559
|
+
- [ ] **Acessibilidade**: Todos os elementos t\xEAm label de acessibilidade.
|
|
560
|
+
- [ ] **Dark Mode**: Funcionalidade respeita o tema do sistema.
|
|
561
|
+
|
|
562
|
+
## Context
|
|
563
|
+
Template para features mobile nativas. Adaptado para o framework espec\xEDfico (SwiftUI/Compose).`,
|
|
564
|
+
acceptance: `# Acceptance Criteria \u2014 {{name}}
|
|
565
|
+
|
|
566
|
+
- [ ] **Tela principal**: Nova funcionalidade aparece na navega\xE7\xE3o principal.
|
|
567
|
+
- [ ] **Offline**: Funcionalidade completa funciona sem conex\xE3o de rede.
|
|
568
|
+
- [ ] **Performance**: Scroll da lista com 1000+ itens mant\xE9m 60fps.
|
|
569
|
+
- [ ] **Acessibilidade**: Todos os elementos t\xEAm label de acessibilidade.
|
|
570
|
+
- [ ] **Dark Mode**: Funcionalidade respeita o tema do sistema.`
|
|
571
|
+
}
|
|
572
|
+
};
|
|
573
|
+
function listTemplates(root) {
|
|
574
|
+
const names = Object.keys(builtInTemplates);
|
|
575
|
+
const customDir = join5(root, ".letra", "templates");
|
|
576
|
+
if (existsSync5(customDir)) {
|
|
577
|
+
for (const file of readdirSync4(customDir)) {
|
|
578
|
+
if (file.endsWith(".md")) {
|
|
579
|
+
const name = file.replace(/\.md$/, "");
|
|
580
|
+
if (!names.includes(name)) names.push(name);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
return names;
|
|
585
|
+
}
|
|
586
|
+
function findTemplate(root, type) {
|
|
587
|
+
const lower = type.toLowerCase();
|
|
588
|
+
if (builtInTemplates[lower]) return builtInTemplates[lower];
|
|
589
|
+
const customFile = join5(root, ".letra", "templates", `${type}.md`);
|
|
590
|
+
const customAcceptance = join5(
|
|
591
|
+
root,
|
|
592
|
+
".letra",
|
|
593
|
+
"templates",
|
|
594
|
+
`${type}-acceptance.md`
|
|
595
|
+
);
|
|
596
|
+
if (existsSync5(customFile)) {
|
|
597
|
+
const spec = readFileSync4(customFile, "utf-8");
|
|
598
|
+
const acceptance = existsSync5(customAcceptance) ? readFileSync4(customAcceptance, "utf-8") : `# Acceptance Criteria \u2014 ${type}
|
|
599
|
+
|
|
600
|
+
- [ ] **Crit\xE9rio 1**: Descri\xE7\xE3o bin\xE1ria (passa/falha).
|
|
601
|
+
`;
|
|
602
|
+
return { spec, acceptance };
|
|
603
|
+
}
|
|
604
|
+
return null;
|
|
605
|
+
}
|
|
606
|
+
function applyPlaceholders(content, name) {
|
|
607
|
+
return content.replace(/\{\{name\}\}/g, name);
|
|
608
|
+
}
|
|
609
|
+
async function specNew(name, options) {
|
|
610
|
+
const root = resolve5(process.cwd());
|
|
611
|
+
const letraDir = join5(root, ".letra");
|
|
612
|
+
const specDir = join5(letraDir, "specs", name);
|
|
613
|
+
if (!existsSync5(letraDir)) {
|
|
614
|
+
console.log(chalk5.red(".letra/ not found. Run 'letra init' first."));
|
|
249
615
|
process.exit(1);
|
|
250
616
|
}
|
|
251
|
-
if (
|
|
252
|
-
|
|
617
|
+
if (existsSync5(specDir)) {
|
|
618
|
+
console.log(chalk5.yellow(`Spec "${name}" already exists`));
|
|
253
619
|
return;
|
|
254
620
|
}
|
|
621
|
+
const templateType = options?.template || "_default";
|
|
622
|
+
const template = templateType === "_default" ? null : findTemplate(root, templateType);
|
|
623
|
+
if (options?.template && !template) {
|
|
624
|
+
const available = listTemplates(root).join(", ");
|
|
625
|
+
console.log(
|
|
626
|
+
chalk5.red(
|
|
627
|
+
`Template "${options.template}" not found. Available: ${available}`
|
|
628
|
+
)
|
|
629
|
+
);
|
|
630
|
+
process.exit(1);
|
|
631
|
+
}
|
|
632
|
+
const spinner = ora2(`Creating spec "${name}"...`).start();
|
|
255
633
|
try {
|
|
256
|
-
|
|
257
|
-
|
|
634
|
+
mkdirSync3(specDir, { recursive: true });
|
|
635
|
+
if (template) {
|
|
636
|
+
const specContent = applyPlaceholders(template.spec, name);
|
|
637
|
+
const acceptanceContent = applyPlaceholders(template.acceptance, name);
|
|
638
|
+
writeFileSync4(join5(specDir, "spec.md"), specContent);
|
|
639
|
+
writeFileSync4(join5(specDir, "acceptance.md"), acceptanceContent);
|
|
640
|
+
} else {
|
|
641
|
+
const specContent = `# Spec: ${name}
|
|
258
642
|
|
|
259
643
|
## Outcome
|
|
260
644
|
O que o usu\xE1rio consegue fazer quando isso estiver pronto.
|
|
@@ -271,28 +655,18 @@ O que explicitamente N\xC3O est\xE1 neste escopo.
|
|
|
271
655
|
## Context
|
|
272
656
|
Por que estamos construindo isso. Trade-offs considerados.
|
|
273
657
|
`;
|
|
274
|
-
|
|
658
|
+
const acceptanceContent = `# Acceptance Criteria \u2014 ${name}
|
|
275
659
|
|
|
276
660
|
- [ ] **Crit\xE9rio 1**: Descri\xE7\xE3o bin\xE1ria (passa/falha).
|
|
277
661
|
`;
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
**Status:** pending
|
|
282
|
-
**Last sync:** ${(/* @__PURE__ */ new Date()).toISOString().split("T")[0]}
|
|
283
|
-
|
|
284
|
-
## Progresso
|
|
285
|
-
|
|
286
|
-
- [ ] Implementado
|
|
287
|
-
`;
|
|
288
|
-
writeFileSync2(join3(specDir, "spec.md"), specContent);
|
|
289
|
-
writeFileSync2(join3(specDir, "acceptance.md"), acceptanceContent);
|
|
290
|
-
writeFileSync2(join3(specDir, "status.md"), statusContent);
|
|
662
|
+
writeFileSync4(join5(specDir, "spec.md"), specContent);
|
|
663
|
+
writeFileSync4(join5(specDir, "acceptance.md"), acceptanceContent);
|
|
664
|
+
}
|
|
291
665
|
spinner.succeed(
|
|
292
|
-
|
|
666
|
+
chalk5.green(`Spec "${name}" created at .letra/specs/${name}/`)
|
|
293
667
|
);
|
|
294
668
|
} catch (error) {
|
|
295
|
-
spinner.fail(
|
|
669
|
+
spinner.fail(chalk5.red("Failed to create spec"));
|
|
296
670
|
process.exit(1);
|
|
297
671
|
}
|
|
298
672
|
}
|
|
@@ -300,57 +674,144 @@ Por que estamos construindo isso. Trade-offs considerados.
|
|
|
300
674
|
// src/commands/validate.ts
|
|
301
675
|
import { execSync } from "child_process";
|
|
302
676
|
import {
|
|
303
|
-
existsSync as
|
|
677
|
+
existsSync as existsSync7,
|
|
304
678
|
mkdtempSync,
|
|
305
|
-
readFileSync as
|
|
306
|
-
readdirSync as
|
|
679
|
+
readFileSync as readFileSync6,
|
|
680
|
+
readdirSync as readdirSync5,
|
|
307
681
|
rmSync,
|
|
308
|
-
statSync as statSync2
|
|
682
|
+
statSync as statSync2,
|
|
683
|
+
watch
|
|
309
684
|
} from "fs";
|
|
310
685
|
import { tmpdir } from "os";
|
|
311
|
-
import { join as
|
|
312
|
-
import
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
"
|
|
319
|
-
"
|
|
320
|
-
"
|
|
321
|
-
|
|
686
|
+
import { join as join7, resolve as resolve6 } from "path";
|
|
687
|
+
import chalk6 from "chalk";
|
|
688
|
+
|
|
689
|
+
// src/config.ts
|
|
690
|
+
import { existsSync as existsSync6, readFileSync as readFileSync5 } from "fs";
|
|
691
|
+
import { join as join6 } from "path";
|
|
692
|
+
var DEFAULT_HEURISTICS = {
|
|
693
|
+
"conteudo-minimo": { severity: "warning", minChars: 50 },
|
|
694
|
+
"consistencia-terminologia": { severity: "warning" },
|
|
695
|
+
"detecao-tom": {
|
|
696
|
+
severity: "warning",
|
|
697
|
+
blacklist: ["tipo", "t\xE1", "pra", "blz", "kkk", "eita", "oi", "oi pessoal"]
|
|
698
|
+
},
|
|
699
|
+
"drift-temporal": { severity: "warning", maxDays: 30 },
|
|
700
|
+
"secoes-vazias": { severity: "warning" },
|
|
701
|
+
"acs-sem-metrica": { severity: "warning" },
|
|
702
|
+
"baixa-confianca": { severity: "warning" },
|
|
703
|
+
"validate-conflict": { severity: "warning" }
|
|
704
|
+
};
|
|
705
|
+
function loadConfig(root) {
|
|
706
|
+
const configPath = join6(root, ".letra", "config.json");
|
|
707
|
+
const heuristics = {};
|
|
708
|
+
for (const [key, value] of Object.entries(DEFAULT_HEURISTICS)) {
|
|
709
|
+
heuristics[key] = { ...value };
|
|
710
|
+
}
|
|
711
|
+
if (existsSync6(configPath)) {
|
|
712
|
+
try {
|
|
713
|
+
const raw = JSON.parse(readFileSync5(configPath, "utf-8"));
|
|
714
|
+
if (raw.heuristics && typeof raw.heuristics === "object") {
|
|
715
|
+
for (const [key, value] of Object.entries(raw.heuristics)) {
|
|
716
|
+
if (heuristics[key]) {
|
|
717
|
+
heuristics[key] = {
|
|
718
|
+
...heuristics[key],
|
|
719
|
+
...value
|
|
720
|
+
};
|
|
721
|
+
} else {
|
|
722
|
+
heuristics[key] = value;
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
} catch {
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
return { heuristics };
|
|
730
|
+
}
|
|
731
|
+
function getHeuristicConfig(config, label) {
|
|
732
|
+
const key = heuristicKey(label);
|
|
733
|
+
return config.heuristics[key] ?? { severity: "warning" };
|
|
734
|
+
}
|
|
735
|
+
function heuristicKey(label) {
|
|
736
|
+
const lower = label.toLowerCase();
|
|
737
|
+
if (lower.includes("conteudo m\xEDnimo") || lower.includes("conteudo minimo"))
|
|
738
|
+
return "conteudo-minimo";
|
|
739
|
+
if (lower.includes("terminologia")) return "consistencia-terminologia";
|
|
740
|
+
if (lower.includes("tom")) return "detecao-tom";
|
|
741
|
+
if (lower.includes("drift temporal") || lower.includes("temporal"))
|
|
742
|
+
return "drift-temporal";
|
|
743
|
+
if (lower.includes("se\xE7\xF5es vazias") || lower.includes("secoes vazias"))
|
|
744
|
+
return "secoes-vazias";
|
|
745
|
+
if (lower.includes("acs sem m\xE9trica") || lower.includes("acs sem metrica"))
|
|
746
|
+
return "acs-sem-metrica";
|
|
747
|
+
if (lower.includes("baixa confian\xE7a") || lower.includes("baixa confianca"))
|
|
748
|
+
return "baixa-confianca";
|
|
749
|
+
if (lower.includes("validate conflict")) return "validate-conflict";
|
|
750
|
+
return lower.replace(/\s+/g, "-");
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
// src/commands/validate.ts
|
|
754
|
+
var placeholderPatterns = [
|
|
755
|
+
/o que o usu[áa]rio consegue fazer quando isso estiver pronto/i,
|
|
756
|
+
/limitaç[õo]es t[ée]cnicas e de neg[óo]cio/i,
|
|
757
|
+
/o que explicitamente n[ãa]o est[áa] neste escopo/i,
|
|
758
|
+
/descriç[ãa]o bin[áa]ria/i,
|
|
759
|
+
/por que estamos construindo isso/i
|
|
760
|
+
];
|
|
761
|
+
var vagueVerbs = [
|
|
762
|
+
"melhorar",
|
|
763
|
+
"otimizar",
|
|
764
|
+
"facilitar",
|
|
765
|
+
"aumentar",
|
|
766
|
+
"diminuir",
|
|
767
|
+
"agilizar",
|
|
768
|
+
"simplificar",
|
|
769
|
+
"aprimorar"
|
|
322
770
|
];
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
771
|
+
var lowConfidenceMarkers = [
|
|
772
|
+
"provavelmente",
|
|
773
|
+
"talvez",
|
|
774
|
+
"tentar",
|
|
775
|
+
"idealmente",
|
|
776
|
+
"possivelmente",
|
|
777
|
+
"quem sabe",
|
|
778
|
+
"de repente",
|
|
779
|
+
"teoricamente"
|
|
780
|
+
];
|
|
781
|
+
function checkSpecContent(specDir, label, description, config) {
|
|
782
|
+
const cfg = config ?? loadConfig(join7(specDir, "..", "..", ".."));
|
|
783
|
+
const specFile = join7(specDir, "spec.md");
|
|
784
|
+
const glossaryFile = join7(specDir, "..", "..", "glossary.md");
|
|
785
|
+
if (!existsSync7(specFile))
|
|
327
786
|
return { status: "FAIL", note: "(spec.md not found)" };
|
|
328
|
-
const specContent =
|
|
787
|
+
const specContent = readFileSync6(specFile, "utf-8");
|
|
329
788
|
const now = /* @__PURE__ */ new Date();
|
|
330
789
|
if (label.includes("Conte\xFAdo M\xEDnimo")) {
|
|
331
790
|
const outcomeMatch = specContent.match(/## Outcome\s+([\s\S]*?)(?=\n## )/);
|
|
332
791
|
if (!outcomeMatch)
|
|
333
792
|
return { status: "FAIL", note: "(no Outcome section)" };
|
|
334
793
|
const outcomeContent = outcomeMatch[1].trim();
|
|
335
|
-
|
|
794
|
+
const heurConfig = getHeuristicConfig(cfg, label);
|
|
795
|
+
const minChars = heurConfig.minChars ?? 50;
|
|
796
|
+
if (outcomeContent.length >= minChars) {
|
|
336
797
|
return {
|
|
337
798
|
status: "PASS",
|
|
338
|
-
note: `(${outcomeContent.length} chars)`
|
|
799
|
+
note: `(${outcomeContent.length} chars, need ${minChars})`
|
|
339
800
|
};
|
|
340
801
|
}
|
|
341
802
|
return {
|
|
342
803
|
status: "FAIL",
|
|
343
|
-
note: `(only ${outcomeContent.length} chars, need
|
|
804
|
+
note: `(only ${outcomeContent.length} chars, need ${minChars}+)`
|
|
344
805
|
};
|
|
345
806
|
}
|
|
346
807
|
if (label.includes("Consist\xEAncia de Terminologia") || label.includes("Terminologia")) {
|
|
347
|
-
if (!
|
|
808
|
+
if (!existsSync7(glossaryFile)) {
|
|
348
809
|
return {
|
|
349
810
|
status: "PASS",
|
|
350
811
|
note: "(no glossary to check against)"
|
|
351
812
|
};
|
|
352
813
|
}
|
|
353
|
-
const glossaryContent =
|
|
814
|
+
const glossaryContent = readFileSync6(glossaryFile, "utf-8");
|
|
354
815
|
const terms = glossaryContent.match(/\*\*(.+?)\*\*/g) || [];
|
|
355
816
|
const extractedTerms = terms.map((t) => t.replace(/\*\*/g, "").trim()).filter((t) => t.length > 3);
|
|
356
817
|
const missingTerms = extractedTerms.filter(
|
|
@@ -367,7 +828,18 @@ function checkSpecContent(specDir, label, description) {
|
|
|
367
828
|
if (label.includes("Detec\xE7\xE3o de Tom") || label.includes("Tom")) {
|
|
368
829
|
const lowerSpec = specContent.toLowerCase();
|
|
369
830
|
const words = lowerSpec.split(/\s+/);
|
|
370
|
-
const
|
|
831
|
+
const heurConfig = getHeuristicConfig(cfg, label);
|
|
832
|
+
const blacklist = heurConfig.blacklist ?? [
|
|
833
|
+
"tipo",
|
|
834
|
+
"t\xE1",
|
|
835
|
+
"pra",
|
|
836
|
+
"blz",
|
|
837
|
+
"kkk",
|
|
838
|
+
"eita",
|
|
839
|
+
"oi",
|
|
840
|
+
"oi pessoal"
|
|
841
|
+
];
|
|
842
|
+
const foundColloquialisms = blacklist.filter((c) => words.includes(c));
|
|
371
843
|
if (foundColloquialisms.length === 0) {
|
|
372
844
|
return { status: "PASS", note: "(formal tone maintained)" };
|
|
373
845
|
}
|
|
@@ -381,197 +853,734 @@ function checkSpecContent(specDir, label, description) {
|
|
|
381
853
|
const daysOld = Math.floor(
|
|
382
854
|
(now.getTime() - stat.mtimeMs) / (1e3 * 60 * 60 * 24)
|
|
383
855
|
);
|
|
384
|
-
|
|
856
|
+
const heurConfig = getHeuristicConfig(cfg, label);
|
|
857
|
+
const maxDays = heurConfig.maxDays ?? 30;
|
|
858
|
+
if (daysOld < maxDays) {
|
|
385
859
|
return { status: "PASS", note: `(${daysOld} days old)` };
|
|
386
860
|
}
|
|
387
861
|
return {
|
|
388
862
|
status: "FAIL",
|
|
389
|
-
note: `(${daysOld} days old, stale
|
|
863
|
+
note: `(${daysOld} days old, stale >${maxDays}d)`
|
|
390
864
|
};
|
|
391
865
|
}
|
|
392
866
|
return null;
|
|
393
867
|
}
|
|
394
|
-
|
|
395
|
-
const
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
868
|
+
function checkEmptySections(specContent) {
|
|
869
|
+
const requiredSections = [
|
|
870
|
+
"## Outcome",
|
|
871
|
+
"## Constraints",
|
|
872
|
+
"## Exclusions",
|
|
873
|
+
"## Acceptance Criteria",
|
|
874
|
+
"## Context"
|
|
875
|
+
];
|
|
876
|
+
const emptyOrPlaceholder = [];
|
|
877
|
+
for (const section of requiredSections) {
|
|
878
|
+
const escaped = section.replace(/[#]/g, "\\$&");
|
|
879
|
+
const pattern = new RegExp(`${escaped}\\s+([\\s\\S]*?)(?=\\n## |\\n*$)`);
|
|
880
|
+
const match = specContent.match(pattern);
|
|
881
|
+
if (!match) {
|
|
882
|
+
emptyOrPlaceholder.push(section.replace("## ", ""));
|
|
883
|
+
continue;
|
|
884
|
+
}
|
|
885
|
+
const content = match[1].trim();
|
|
886
|
+
if (content.length < 10) {
|
|
887
|
+
emptyOrPlaceholder.push(section.replace("## ", ""));
|
|
888
|
+
continue;
|
|
889
|
+
}
|
|
890
|
+
const hasPlaceholder = placeholderPatterns.some((p) => p.test(content));
|
|
891
|
+
if (hasPlaceholder) {
|
|
892
|
+
emptyOrPlaceholder.push(section.replace("## ", ""));
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
if (emptyOrPlaceholder.length === 0) {
|
|
896
|
+
return {
|
|
897
|
+
status: "PASS",
|
|
898
|
+
note: "(all sections have real content)"
|
|
899
|
+
};
|
|
900
|
+
}
|
|
901
|
+
return {
|
|
902
|
+
status: "FAIL",
|
|
903
|
+
note: `(empty/placeholder: ${emptyOrPlaceholder.join(", ")})`
|
|
904
|
+
};
|
|
905
|
+
}
|
|
906
|
+
function checkBinaryCriteria(specContent) {
|
|
907
|
+
const acMatch = specContent.match(
|
|
908
|
+
/## Acceptance Criteria\s+([\s\S]*?)(?=\n## |\n*$)/
|
|
909
|
+
);
|
|
910
|
+
if (!acMatch) {
|
|
911
|
+
return {
|
|
912
|
+
status: "FAIL",
|
|
913
|
+
note: "(no Acceptance Criteria section)"
|
|
914
|
+
};
|
|
915
|
+
}
|
|
916
|
+
const criteriaLines = acMatch[1].match(/- \[[ x]\] .+/g) || [];
|
|
917
|
+
if (criteriaLines.length === 0) {
|
|
918
|
+
return { status: "FAIL", note: "(no criteria items found)" };
|
|
919
|
+
}
|
|
920
|
+
const nonBinary = [];
|
|
921
|
+
for (const line of criteriaLines) {
|
|
922
|
+
const description = line.replace(/- \[[ x]\] \*\*.+?\*\*:\s*/, "");
|
|
923
|
+
const hasMetric = /\d+/.test(description);
|
|
924
|
+
const hasVagueVerb = vagueVerbs.some(
|
|
925
|
+
(v) => description.toLowerCase().includes(v)
|
|
400
926
|
);
|
|
401
|
-
|
|
927
|
+
if (!hasMetric && hasVagueVerb) {
|
|
928
|
+
const labelMatch = line.match(/\*\*(.+?)\*\*/);
|
|
929
|
+
if (labelMatch) nonBinary.push(labelMatch[1]);
|
|
930
|
+
}
|
|
402
931
|
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
932
|
+
if (nonBinary.length === 0) {
|
|
933
|
+
return {
|
|
934
|
+
status: "PASS",
|
|
935
|
+
note: "(all criteria have measurable outcomes)"
|
|
936
|
+
};
|
|
937
|
+
}
|
|
938
|
+
return {
|
|
939
|
+
status: "FAIL",
|
|
940
|
+
note: `(vague criteria: ${nonBinary.join(", ")})`
|
|
412
941
|
};
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
const
|
|
416
|
-
const
|
|
417
|
-
|
|
418
|
-
if (
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
942
|
+
}
|
|
943
|
+
function checkLowConfidence(specContent) {
|
|
944
|
+
const lower = specContent.toLowerCase();
|
|
945
|
+
const words = lower.split(/\s+/);
|
|
946
|
+
const found = lowConfidenceMarkers.filter((m) => {
|
|
947
|
+
if (m.includes(" ")) {
|
|
948
|
+
return lower.includes(m);
|
|
949
|
+
}
|
|
950
|
+
return words.includes(m);
|
|
951
|
+
});
|
|
952
|
+
if (found.length === 0) {
|
|
953
|
+
return {
|
|
954
|
+
status: "PASS",
|
|
955
|
+
note: "(no low-confidence language detected)"
|
|
956
|
+
};
|
|
957
|
+
}
|
|
958
|
+
return {
|
|
959
|
+
status: "FAIL",
|
|
960
|
+
note: `(low-confidence: ${found.join(", ")})`
|
|
961
|
+
};
|
|
962
|
+
}
|
|
963
|
+
var commonWords = [
|
|
964
|
+
"para",
|
|
965
|
+
"com",
|
|
966
|
+
"que",
|
|
967
|
+
"dos",
|
|
968
|
+
"das",
|
|
969
|
+
"uma",
|
|
970
|
+
"como",
|
|
971
|
+
"mais",
|
|
972
|
+
"mas",
|
|
973
|
+
"por",
|
|
974
|
+
"pode",
|
|
975
|
+
"ser",
|
|
976
|
+
"s\xE3o",
|
|
977
|
+
"tem",
|
|
978
|
+
"seu",
|
|
979
|
+
"sua",
|
|
980
|
+
"esta",
|
|
981
|
+
"este",
|
|
982
|
+
"isso",
|
|
983
|
+
"the",
|
|
984
|
+
"and",
|
|
985
|
+
"for",
|
|
986
|
+
"with",
|
|
987
|
+
"that",
|
|
988
|
+
"this",
|
|
989
|
+
"from",
|
|
990
|
+
"are",
|
|
991
|
+
"was"
|
|
992
|
+
];
|
|
993
|
+
function getSignificantWords(text) {
|
|
994
|
+
return text.toLowerCase().split(/\s+/).filter((w) => w.length >= 4 && !commonWords.includes(w));
|
|
995
|
+
}
|
|
996
|
+
function getPrefix(name) {
|
|
997
|
+
const idx = name.indexOf("-");
|
|
998
|
+
return idx === -1 ? name : name.slice(0, idx);
|
|
999
|
+
}
|
|
1000
|
+
function isSibling(nameA, nameB) {
|
|
1001
|
+
return getPrefix(nameA) === getPrefix(nameB);
|
|
1002
|
+
}
|
|
1003
|
+
function detectConflict(textA, textB) {
|
|
1004
|
+
const lowerA = textA.toLowerCase();
|
|
1005
|
+
const lowerB = textB.toLowerCase();
|
|
1006
|
+
const aHasNeg = /\bn[ãa]o\b/.test(lowerA) || /\bnot\b/.test(lowerA);
|
|
1007
|
+
const bHasNeg = /\bn[ãa]o\b/.test(lowerB) || /\bnot\b/.test(lowerB);
|
|
1008
|
+
if (aHasNeg !== bHasNeg) {
|
|
1009
|
+
const wordsA = getSignificantWords(lowerA);
|
|
1010
|
+
const wordsB = getSignificantWords(lowerB);
|
|
1011
|
+
const intersection = wordsA.filter((w) => wordsB.includes(w));
|
|
1012
|
+
const maxLen = Math.max(wordsA.length, wordsB.length);
|
|
1013
|
+
if (maxLen > 0 && intersection.length / maxLen > 0.6) return true;
|
|
1014
|
+
}
|
|
1015
|
+
const apenasA = lowerA.match(/(?:apenas|only)\s+(\w+)/);
|
|
1016
|
+
const apenasB = lowerB.match(/(?:apenas|only)\s+(\w+)/);
|
|
1017
|
+
if (apenasA && !apenasB) {
|
|
1018
|
+
const termA = apenasA[1];
|
|
1019
|
+
const wordsA = getSignificantWords(lowerA);
|
|
1020
|
+
const wordsB = getSignificantWords(lowerB);
|
|
1021
|
+
const shared = wordsA.filter((w) => w !== termA && wordsB.includes(w));
|
|
1022
|
+
if (shared.length > 0 && !wordsB.includes(termA)) return true;
|
|
1023
|
+
}
|
|
1024
|
+
if (apenasB && !apenasA) {
|
|
1025
|
+
const termB = apenasB[1];
|
|
1026
|
+
const wordsA = getSignificantWords(lowerA);
|
|
1027
|
+
const wordsB = getSignificantWords(lowerB);
|
|
1028
|
+
const shared = wordsB.filter((w) => w !== termB && wordsA.includes(w));
|
|
1029
|
+
if (shared.length > 0 && !wordsA.includes(termB)) return true;
|
|
1030
|
+
}
|
|
1031
|
+
if (apenasA && apenasB && apenasA[1] !== apenasB[1]) {
|
|
1032
|
+
const wordsA = getSignificantWords(lowerA);
|
|
1033
|
+
const wordsB = getSignificantWords(lowerB);
|
|
1034
|
+
const shared = wordsA.filter((w) => wordsB.includes(w));
|
|
1035
|
+
if (shared.length > 0) return true;
|
|
1036
|
+
}
|
|
1037
|
+
return false;
|
|
1038
|
+
}
|
|
1039
|
+
function checkConflicts(specsDir, config) {
|
|
1040
|
+
const results = [];
|
|
1041
|
+
const entries = readdirSync5(specsDir, { withFileTypes: true });
|
|
1042
|
+
const specDirs = entries.filter((e) => e.isDirectory() && !e.name.startsWith("_")).map((e) => e.name);
|
|
1043
|
+
const specs = [];
|
|
1044
|
+
for (const dir of specDirs) {
|
|
1045
|
+
const acceptanceFile = join7(specsDir, dir, "acceptance.md");
|
|
1046
|
+
if (!existsSync7(acceptanceFile)) continue;
|
|
1047
|
+
const content = readFileSync6(acceptanceFile, "utf-8");
|
|
1048
|
+
const acLines = content.match(/- \[[ x]\] \*\*(.+?)\*\*: (.+)/g) || [];
|
|
1049
|
+
const acs = acLines.map((line) => {
|
|
1050
|
+
const m = line.match(/- \[[ x]\] \*\*(.+?)\*\*: (.+)/);
|
|
1051
|
+
return m ? m[2].trim() : "";
|
|
1052
|
+
}).filter(Boolean);
|
|
1053
|
+
if (acs.length > 0) specs.push({ name: dir, acs });
|
|
1054
|
+
}
|
|
1055
|
+
for (let i = 0; i < specs.length; i++) {
|
|
1056
|
+
for (let j = i + 1; j < specs.length; j++) {
|
|
1057
|
+
const a = specs[i];
|
|
1058
|
+
const b = specs[j];
|
|
1059
|
+
if (isSibling(a.name, b.name)) continue;
|
|
1060
|
+
for (const acA of a.acs) {
|
|
1061
|
+
for (const acB of b.acs) {
|
|
1062
|
+
if (detectConflict(acA, acB)) {
|
|
1063
|
+
results.push({
|
|
1064
|
+
label: "Validate Conflict",
|
|
1065
|
+
passed: false,
|
|
1066
|
+
message: `Conflito: "${a.name}" AC "${acA}" vs "${b.name}" AC "${acB}"`
|
|
1067
|
+
});
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
if (results.length === 0) {
|
|
1074
|
+
results.push({
|
|
1075
|
+
label: "Validate Conflict",
|
|
1076
|
+
passed: true,
|
|
1077
|
+
message: "Nenhum conflito detectado entre specs"
|
|
1078
|
+
});
|
|
1079
|
+
}
|
|
1080
|
+
return results;
|
|
1081
|
+
}
|
|
1082
|
+
function out(format, level, spec, label, message, note) {
|
|
1083
|
+
if (format === "github-annotation") {
|
|
1084
|
+
const file = spec ? `.letra/specs/${spec}/spec.md` : "";
|
|
1085
|
+
if (level === "fail") {
|
|
1086
|
+
console.log(`::error file=${file},title=${label}::${message} ${note}`);
|
|
1087
|
+
} else if (level === "warning") {
|
|
1088
|
+
console.log(`::warning file=${file},title=${label}::${message} ${note}`);
|
|
426
1089
|
} else {
|
|
427
|
-
console.log(
|
|
428
|
-
chalk4.gray(
|
|
429
|
-
` Spec "${entry.name}" \u2014 no acceptance.md or spec.md found`
|
|
430
|
-
)
|
|
431
|
-
);
|
|
432
|
-
continue;
|
|
1090
|
+
console.log(`${label}: ${message} ${note}`);
|
|
433
1091
|
}
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
1092
|
+
return;
|
|
1093
|
+
}
|
|
1094
|
+
if (format === "junit") {
|
|
1095
|
+
return;
|
|
1096
|
+
}
|
|
1097
|
+
const icon = level === "pass" ? chalk6.green("\u2713") : level === "fail" ? chalk6.red("\u2717") : level === "warning" ? chalk6.yellow("\u26A0") : "";
|
|
1098
|
+
if (level === "info") {
|
|
1099
|
+
console.log(` ${message}`);
|
|
1100
|
+
} else {
|
|
1101
|
+
console.log(
|
|
1102
|
+
` [${icon}] ${chalk6.cyan(label)}: ${message} ${chalk6.gray(note)}`
|
|
1103
|
+
);
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
function buildJunitXml(results) {
|
|
1107
|
+
let xml = `<?xml version="1.0" encoding="UTF-8"?>
|
|
1108
|
+
`;
|
|
1109
|
+
xml += `<testsuites name="letra-validate" tests="${results.pass + results.fail + results.warning}" failures="${results.fail}">
|
|
1110
|
+
`;
|
|
1111
|
+
for (const suite of results.suites) {
|
|
1112
|
+
xml += ` <testsuite name="${suite.name}" tests="${suite.pass + suite.fail + suite.warning}" failures="${suite.fail}">
|
|
1113
|
+
`;
|
|
1114
|
+
xml += " </testsuite>\n";
|
|
1115
|
+
}
|
|
1116
|
+
xml += "</testsuites>\n";
|
|
1117
|
+
return xml;
|
|
1118
|
+
}
|
|
1119
|
+
function collectResult(results, level, spec, label, message, note) {
|
|
1120
|
+
results.push({ level, spec, label, message, note });
|
|
1121
|
+
}
|
|
1122
|
+
function flushResults(results, format, specGroups, totalPass, totalFail, totalWarning) {
|
|
1123
|
+
if (format === "junit") {
|
|
1124
|
+
const suites = [];
|
|
1125
|
+
for (const [name, counts] of specGroups) {
|
|
1126
|
+
suites.push({ name, ...counts });
|
|
439
1127
|
}
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
1128
|
+
console.log(
|
|
1129
|
+
buildJunitXml({
|
|
1130
|
+
pass: totalPass,
|
|
1131
|
+
fail: totalFail,
|
|
1132
|
+
warning: totalWarning,
|
|
1133
|
+
suites
|
|
1134
|
+
})
|
|
1135
|
+
);
|
|
1136
|
+
return;
|
|
1137
|
+
}
|
|
1138
|
+
if (format === "github-annotation") {
|
|
1139
|
+
for (const r of results) {
|
|
1140
|
+
out(format, r.level, r.spec, r.label, r.message, r.note);
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
console.log(
|
|
1144
|
+
chalk6.gray(
|
|
1145
|
+
`
|
|
1146
|
+
Results: ${totalPass} passed, ${totalFail} failed${totalWarning > 0 ? `, ${totalWarning} warnings` : ""}`
|
|
1147
|
+
)
|
|
1148
|
+
);
|
|
1149
|
+
}
|
|
1150
|
+
async function validate(targetPath, options) {
|
|
1151
|
+
const root = resolve6(process.cwd(), targetPath || ".");
|
|
1152
|
+
const specsDir = join7(root, ".letra", "specs");
|
|
1153
|
+
const fmt = options?.format || "text";
|
|
1154
|
+
if (!existsSync7(specsDir)) {
|
|
1155
|
+
const msg = "Error: .letra/specs/ not found. Run 'letra init' first.";
|
|
1156
|
+
if (fmt === "github-annotation") {
|
|
1157
|
+
console.log(`::error file=,title=Init Required::${msg}`);
|
|
1158
|
+
} else {
|
|
1159
|
+
console.log(chalk6.red(msg));
|
|
1160
|
+
}
|
|
1161
|
+
process.exit(1);
|
|
1162
|
+
}
|
|
1163
|
+
async function runValidation() {
|
|
1164
|
+
const config = loadConfig(root);
|
|
1165
|
+
const entries = readdirSync5(specsDir, { withFileTypes: true });
|
|
1166
|
+
let totalPass = 0;
|
|
1167
|
+
let totalFail = 0;
|
|
1168
|
+
let totalWarning = 0;
|
|
1169
|
+
const specGroups = /* @__PURE__ */ new Map();
|
|
1170
|
+
const allResults = [];
|
|
1171
|
+
const entryPoint = join7(root, "src/index.ts");
|
|
1172
|
+
const opts = {
|
|
1173
|
+
stdio: "pipe",
|
|
1174
|
+
encoding: "utf-8",
|
|
1175
|
+
shell: process.platform === "win32" ? "cmd.exe" : true
|
|
1176
|
+
};
|
|
1177
|
+
const ciFile = join7(root, ".github", "workflows", "ci.yml");
|
|
1178
|
+
const cursorRulesFile = join7(root, ".cursorrules");
|
|
1179
|
+
const copilotFile = join7(root, ".github", "copilot-instructions.md");
|
|
1180
|
+
const vscodeSettingsFile = join7(root, ".vscode", "settings.json");
|
|
1181
|
+
if (fmt !== "junit") {
|
|
1182
|
+
out(fmt, "info", null, "", "\nLetra Validation\n", "");
|
|
1183
|
+
}
|
|
1184
|
+
for (const entry of entries) {
|
|
1185
|
+
if (!entry.isDirectory() || entry.name.startsWith("_")) continue;
|
|
1186
|
+
const acceptanceFile = join7(specsDir, entry.name, "acceptance.md");
|
|
1187
|
+
const specFile = join7(specsDir, entry.name, "spec.md");
|
|
1188
|
+
let content;
|
|
1189
|
+
if (existsSync7(acceptanceFile)) {
|
|
1190
|
+
content = readFileSync6(acceptanceFile, "utf-8");
|
|
1191
|
+
} else if (existsSync7(specFile)) {
|
|
1192
|
+
content = readFileSync6(specFile, "utf-8");
|
|
1193
|
+
} else {
|
|
1194
|
+
out(
|
|
1195
|
+
fmt,
|
|
1196
|
+
"info",
|
|
1197
|
+
entry.name,
|
|
1198
|
+
"",
|
|
1199
|
+
`Spec "${entry.name}" \u2014 no acceptance.md or spec.md found`,
|
|
1200
|
+
""
|
|
1201
|
+
);
|
|
1202
|
+
continue;
|
|
1203
|
+
}
|
|
1204
|
+
const criteriaLines = content.match(/- \[ \] \*\*(.+?)\*\*: (.+)/g) || [];
|
|
1205
|
+
const specContent = existsSync7(specFile) ? readFileSync6(specFile, "utf-8") : null;
|
|
1206
|
+
out(fmt, "info", entry.name, "", `Spec: ${entry.name}`, "");
|
|
1207
|
+
if (criteriaLines.length === 0) {
|
|
1208
|
+
out(fmt, "info", entry.name, "", "No criteria found", "");
|
|
1209
|
+
}
|
|
1210
|
+
let specPass = 0;
|
|
1211
|
+
let specFail = 0;
|
|
1212
|
+
let specWarning = 0;
|
|
1213
|
+
for (const line of criteriaLines) {
|
|
1214
|
+
const match = line.match(/- \[ \] \*\*(.+?)\*\*: (.+)/);
|
|
1215
|
+
if (match) {
|
|
1216
|
+
const [, label, description] = match;
|
|
1217
|
+
let status = "FAIL";
|
|
1218
|
+
let note = "";
|
|
1219
|
+
let intelligenceResult = null;
|
|
1220
|
+
try {
|
|
1221
|
+
intelligenceResult = checkSpecContent(
|
|
1222
|
+
join7(specsDir, entry.name),
|
|
1223
|
+
label,
|
|
1224
|
+
description,
|
|
1225
|
+
config
|
|
1226
|
+
);
|
|
1227
|
+
if (intelligenceResult) {
|
|
1228
|
+
status = intelligenceResult.status;
|
|
1229
|
+
note = intelligenceResult.note;
|
|
1230
|
+
} else if (label.includes("letra init")) {
|
|
1231
|
+
const tmp = mkdtempSync(join7(tmpdir(), "letra-test-"));
|
|
1232
|
+
execSync(`npx tsx "${entryPoint}" init "${tmp}"`, { ...opts });
|
|
1233
|
+
if (existsSync7(join7(tmp, ".letra", "context.md")))
|
|
1234
|
+
status = "PASS";
|
|
1235
|
+
rmSync(tmp, { recursive: true });
|
|
1236
|
+
} else if (label.includes("letra spec")) {
|
|
1237
|
+
const tmp = mkdtempSync(join7(tmpdir(), "letra-test-"));
|
|
1238
|
+
execSync(`npx tsx "${entryPoint}" init "${tmp}"`, { ...opts });
|
|
1239
|
+
execSync(`npx tsx "${entryPoint}" spec smoke-test`, {
|
|
1240
|
+
...opts,
|
|
1241
|
+
cwd: tmp
|
|
1242
|
+
});
|
|
1243
|
+
if (existsSync7(
|
|
1244
|
+
join7(tmp, ".letra", "specs", "smoke-test", "spec.md")
|
|
1245
|
+
))
|
|
1246
|
+
status = "PASS";
|
|
1247
|
+
rmSync(tmp, { recursive: true });
|
|
1248
|
+
} else if (label.includes("letra lint")) {
|
|
1249
|
+
execSync(`npx tsx "${entryPoint}" lint`, { ...opts });
|
|
484
1250
|
status = "PASS";
|
|
485
|
-
|
|
486
|
-
const ciContent = readFileSync2(ciFile, "utf-8");
|
|
487
|
-
if (ciContent.includes("tsc") || ciContent.includes("typecheck"))
|
|
1251
|
+
} else if (label.includes("letra validate")) {
|
|
488
1252
|
status = "PASS";
|
|
489
|
-
|
|
490
|
-
const pkgJson = JSON.parse(
|
|
491
|
-
readFileSync2(join4(root, "package.json"), "utf-8")
|
|
492
|
-
);
|
|
493
|
-
if (pkgJson.bin && pkgJson.name) {
|
|
1253
|
+
} else if (label.includes("Workflow Ativo") || label.includes("CI") && existsSync7(ciFile)) {
|
|
494
1254
|
status = "PASS";
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
} else if (label.includes("Gera\xE7\xE3o de Regras") || label.includes("Gera\xE7\xE3o")) {
|
|
503
|
-
if (existsSync4(cursorRulesFile)) {
|
|
504
|
-
const rulesContent = readFileSync2(cursorRulesFile, "utf-8");
|
|
505
|
-
if (rulesContent.includes(".letra/context.md") && rulesContent.includes(".letra/constitution.md")) {
|
|
1255
|
+
} else if (label.includes("Lint Gate") || label.includes("Lint")) {
|
|
1256
|
+
const ciContent = readFileSync6(ciFile, "utf-8");
|
|
1257
|
+
if (ciContent.includes("letra lint") || ciContent.includes("lint"))
|
|
1258
|
+
status = "PASS";
|
|
1259
|
+
} else if (label.includes("Test Gate") || label.includes("Test")) {
|
|
1260
|
+
const ciContent = readFileSync6(ciFile, "utf-8");
|
|
1261
|
+
if (ciContent.includes("npm test") || ciContent.includes("vitest") || ciContent.includes("test"))
|
|
506
1262
|
status = "PASS";
|
|
1263
|
+
} else if (label.includes("Valida\xE7\xE3o de Formato") || label.includes("Formato")) {
|
|
1264
|
+
const ciContent = readFileSync6(ciFile, "utf-8");
|
|
1265
|
+
if (ciContent.includes("tsc") || ciContent.includes("typecheck"))
|
|
1266
|
+
status = "PASS";
|
|
1267
|
+
} else if (label.includes("Distribui\xE7\xE3o npm") || label.includes("npm")) {
|
|
1268
|
+
const pkgJson = JSON.parse(
|
|
1269
|
+
readFileSync6(join7(root, "package.json"), "utf-8")
|
|
1270
|
+
);
|
|
1271
|
+
if (pkgJson.bin && pkgJson.name) {
|
|
1272
|
+
status = "PASS";
|
|
1273
|
+
note = `(${pkgJson.name} @ ${pkgJson.version})`;
|
|
1274
|
+
} else {
|
|
1275
|
+
note = "(bin field missing)";
|
|
507
1276
|
}
|
|
508
|
-
}
|
|
509
|
-
} else if (label.includes("Inje\xE7\xE3o de Contexto")) {
|
|
510
|
-
if (existsSync4(cursorRulesFile)) {
|
|
511
|
-
const rulesContent = readFileSync2(cursorRulesFile, "utf-8");
|
|
512
|
-
if (rulesContent.includes("@.letra/")) status = "PASS";
|
|
513
|
-
} else if (existsSync4(copilotFile)) {
|
|
514
|
-
const copilotContent = readFileSync2(copilotFile, "utf-8");
|
|
515
|
-
if (copilotContent.includes(".letra/")) status = "PASS";
|
|
516
|
-
}
|
|
517
|
-
} else if (label.includes("Acesso a Valida\xE7\xE3o")) {
|
|
518
|
-
if (existsSync4(cursorRulesFile)) {
|
|
519
|
-
const rulesContent = readFileSync2(cursorRulesFile, "utf-8");
|
|
520
|
-
if (rulesContent.includes("letra validate")) status = "PASS";
|
|
521
|
-
}
|
|
522
|
-
} else if (label.includes("N\xE3o-intrusivo")) {
|
|
523
|
-
if (existsSync4(cursorRulesFile) || existsSync4(copilotFile)) {
|
|
1277
|
+
} else if (label.includes("Bin\xE1rio standalone") || label.includes("Bin\xE1rio")) {
|
|
524
1278
|
status = "PASS";
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
1279
|
+
note = "(npm distribution preferred)";
|
|
1280
|
+
} else if (label.includes("Gera\xE7\xE3o de Regras") || label.includes("Gera\xE7\xE3o")) {
|
|
1281
|
+
if (existsSync7(cursorRulesFile)) {
|
|
1282
|
+
const rulesContent = readFileSync6(cursorRulesFile, "utf-8");
|
|
1283
|
+
if (rulesContent.includes(".letra/context.md") && rulesContent.includes(".letra/constitution.md")) {
|
|
1284
|
+
status = "PASS";
|
|
1285
|
+
}
|
|
531
1286
|
}
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
if (
|
|
1287
|
+
} else if (label.includes("Inje\xE7\xE3o de Contexto")) {
|
|
1288
|
+
if (existsSync7(cursorRulesFile)) {
|
|
1289
|
+
const rulesContent = readFileSync6(cursorRulesFile, "utf-8");
|
|
1290
|
+
if (rulesContent.includes("@.letra/")) status = "PASS";
|
|
1291
|
+
} else if (existsSync7(copilotFile)) {
|
|
1292
|
+
const copilotContent = readFileSync6(copilotFile, "utf-8");
|
|
1293
|
+
if (copilotContent.includes(".letra/")) status = "PASS";
|
|
1294
|
+
}
|
|
1295
|
+
} else if (label.includes("Acesso a Valida\xE7\xE3o")) {
|
|
1296
|
+
if (existsSync7(cursorRulesFile)) {
|
|
1297
|
+
const rulesContent = readFileSync6(cursorRulesFile, "utf-8");
|
|
1298
|
+
if (rulesContent.includes("letra validate")) status = "PASS";
|
|
1299
|
+
}
|
|
1300
|
+
} else if (label.includes("N\xE3o-intrusivo")) {
|
|
1301
|
+
if (existsSync7(cursorRulesFile) || existsSync7(copilotFile)) {
|
|
537
1302
|
status = "PASS";
|
|
538
1303
|
}
|
|
1304
|
+
} else if (label.includes("Gera\xE7\xE3o de Instru\xE7\xF5es")) {
|
|
1305
|
+
if (existsSync7(copilotFile)) {
|
|
1306
|
+
const copilotContent = readFileSync6(copilotFile, "utf-8");
|
|
1307
|
+
if (copilotContent.includes(".letra/context.md") && copilotContent.includes(".letra/constitution.md")) {
|
|
1308
|
+
status = "PASS";
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
} else if (label.includes("Settings do Editor")) {
|
|
1312
|
+
if (existsSync7(vscodeSettingsFile)) {
|
|
1313
|
+
const settingsContent = readFileSync6(
|
|
1314
|
+
vscodeSettingsFile,
|
|
1315
|
+
"utf-8"
|
|
1316
|
+
);
|
|
1317
|
+
if (settingsContent.includes("editor.formatOnSave")) {
|
|
1318
|
+
status = "PASS";
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
} else if (label.includes("Arquivo de Config")) {
|
|
1322
|
+
const configFile = join7(root, ".letra", "config.json");
|
|
1323
|
+
if (existsSync7(configFile)) {
|
|
1324
|
+
const cfgContent = readFileSync6(configFile, "utf-8");
|
|
1325
|
+
try {
|
|
1326
|
+
const parsed = JSON.parse(cfgContent);
|
|
1327
|
+
if (parsed.heuristics) {
|
|
1328
|
+
status = "PASS";
|
|
1329
|
+
note = "(config.json found with heuristics)";
|
|
1330
|
+
} else {
|
|
1331
|
+
note = "(config.json missing heuristics key)";
|
|
1332
|
+
}
|
|
1333
|
+
} catch {
|
|
1334
|
+
note = "(config.json is invalid JSON)";
|
|
1335
|
+
}
|
|
1336
|
+
} else {
|
|
1337
|
+
note = "(no config.json found)";
|
|
1338
|
+
}
|
|
1339
|
+
} else if (label.includes("Backward Compatible")) {
|
|
1340
|
+
status = "PASS";
|
|
1341
|
+
note = "(all heuristics default to warning)";
|
|
1342
|
+
} else {
|
|
1343
|
+
note = "(manual check needed)";
|
|
539
1344
|
}
|
|
1345
|
+
} catch (error) {
|
|
1346
|
+
status = "FAIL";
|
|
1347
|
+
const err = error;
|
|
1348
|
+
note = `(error: ${err.message?.split("\n")[0] || "unknown"})`;
|
|
1349
|
+
}
|
|
1350
|
+
if (status === "PASS") {
|
|
1351
|
+
collectResult(
|
|
1352
|
+
allResults,
|
|
1353
|
+
"pass",
|
|
1354
|
+
entry.name,
|
|
1355
|
+
label,
|
|
1356
|
+
description,
|
|
1357
|
+
note
|
|
1358
|
+
);
|
|
1359
|
+
totalPass++;
|
|
1360
|
+
specPass++;
|
|
1361
|
+
} else if (intelligenceResult) {
|
|
1362
|
+
const heurCfg = getHeuristicConfig(config, label);
|
|
1363
|
+
if (heurCfg.severity === "warning") {
|
|
1364
|
+
collectResult(
|
|
1365
|
+
allResults,
|
|
1366
|
+
"warning",
|
|
1367
|
+
entry.name,
|
|
1368
|
+
label,
|
|
1369
|
+
description,
|
|
1370
|
+
note
|
|
1371
|
+
);
|
|
1372
|
+
totalWarning++;
|
|
1373
|
+
specWarning++;
|
|
1374
|
+
} else {
|
|
1375
|
+
collectResult(
|
|
1376
|
+
allResults,
|
|
1377
|
+
"fail",
|
|
1378
|
+
entry.name,
|
|
1379
|
+
label,
|
|
1380
|
+
description,
|
|
1381
|
+
note
|
|
1382
|
+
);
|
|
1383
|
+
totalFail++;
|
|
1384
|
+
specFail++;
|
|
1385
|
+
}
|
|
1386
|
+
} else if (note.includes("manual check needed")) {
|
|
1387
|
+
collectResult(
|
|
1388
|
+
allResults,
|
|
1389
|
+
"warning",
|
|
1390
|
+
entry.name,
|
|
1391
|
+
label,
|
|
1392
|
+
description,
|
|
1393
|
+
note
|
|
1394
|
+
);
|
|
1395
|
+
totalWarning++;
|
|
1396
|
+
specWarning++;
|
|
540
1397
|
} else {
|
|
541
|
-
|
|
1398
|
+
collectResult(
|
|
1399
|
+
allResults,
|
|
1400
|
+
"fail",
|
|
1401
|
+
entry.name,
|
|
1402
|
+
label,
|
|
1403
|
+
description,
|
|
1404
|
+
note
|
|
1405
|
+
);
|
|
1406
|
+
totalFail++;
|
|
1407
|
+
specFail++;
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
if (specContent) {
|
|
1412
|
+
const emptyCfg = getHeuristicConfig(config, "Se\xE7\xF5es Vazias");
|
|
1413
|
+
if (emptyCfg.severity !== "off") {
|
|
1414
|
+
const emptyResult = checkEmptySections(specContent);
|
|
1415
|
+
if (emptyResult.status === "FAIL") {
|
|
1416
|
+
if (emptyCfg.severity === "warning") {
|
|
1417
|
+
collectResult(
|
|
1418
|
+
allResults,
|
|
1419
|
+
"warning",
|
|
1420
|
+
entry.name,
|
|
1421
|
+
"Se\xE7\xF5es Vazias",
|
|
1422
|
+
"Se\xE7\xF5es obrigat\xF3rias com placeholder ou vazias",
|
|
1423
|
+
emptyResult.note
|
|
1424
|
+
);
|
|
1425
|
+
totalWarning++;
|
|
1426
|
+
specWarning++;
|
|
1427
|
+
} else {
|
|
1428
|
+
collectResult(
|
|
1429
|
+
allResults,
|
|
1430
|
+
"fail",
|
|
1431
|
+
entry.name,
|
|
1432
|
+
"Se\xE7\xF5es Vazias",
|
|
1433
|
+
"Se\xE7\xF5es obrigat\xF3rias com placeholder ou vazias",
|
|
1434
|
+
emptyResult.note
|
|
1435
|
+
);
|
|
1436
|
+
totalFail++;
|
|
1437
|
+
specFail++;
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
const binaryCfg = getHeuristicConfig(config, "ACs sem M\xE9trica");
|
|
1442
|
+
if (binaryCfg.severity !== "off") {
|
|
1443
|
+
const binaryResult = checkBinaryCriteria(specContent);
|
|
1444
|
+
if (binaryResult.status === "FAIL") {
|
|
1445
|
+
if (binaryCfg.severity === "warning") {
|
|
1446
|
+
collectResult(
|
|
1447
|
+
allResults,
|
|
1448
|
+
"warning",
|
|
1449
|
+
entry.name,
|
|
1450
|
+
"ACs sem M\xE9trica",
|
|
1451
|
+
"Crit\xE9rios com verbos vagos sem m\xE9trica",
|
|
1452
|
+
binaryResult.note
|
|
1453
|
+
);
|
|
1454
|
+
totalWarning++;
|
|
1455
|
+
specWarning++;
|
|
1456
|
+
} else {
|
|
1457
|
+
collectResult(
|
|
1458
|
+
allResults,
|
|
1459
|
+
"fail",
|
|
1460
|
+
entry.name,
|
|
1461
|
+
"ACs sem M\xE9trica",
|
|
1462
|
+
"Crit\xE9rios com verbos vagos sem m\xE9trica",
|
|
1463
|
+
binaryResult.note
|
|
1464
|
+
);
|
|
1465
|
+
totalFail++;
|
|
1466
|
+
specFail++;
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
const lowConfCfg = getHeuristicConfig(config, "Baixa Confian\xE7a");
|
|
1471
|
+
if (lowConfCfg.severity !== "off") {
|
|
1472
|
+
const lowConfResult = checkLowConfidence(specContent);
|
|
1473
|
+
if (lowConfResult.status === "FAIL") {
|
|
1474
|
+
if (lowConfCfg.severity === "warning") {
|
|
1475
|
+
collectResult(
|
|
1476
|
+
allResults,
|
|
1477
|
+
"warning",
|
|
1478
|
+
entry.name,
|
|
1479
|
+
"Baixa Confian\xE7a",
|
|
1480
|
+
"Spec cont\xE9m linguagem de baixa confian\xE7a",
|
|
1481
|
+
lowConfResult.note
|
|
1482
|
+
);
|
|
1483
|
+
totalWarning++;
|
|
1484
|
+
specWarning++;
|
|
1485
|
+
} else {
|
|
1486
|
+
collectResult(
|
|
1487
|
+
allResults,
|
|
1488
|
+
"fail",
|
|
1489
|
+
entry.name,
|
|
1490
|
+
"Baixa Confian\xE7a",
|
|
1491
|
+
"Spec cont\xE9m linguagem de baixa confian\xE7a",
|
|
1492
|
+
lowConfResult.note
|
|
1493
|
+
);
|
|
1494
|
+
totalFail++;
|
|
1495
|
+
specFail++;
|
|
1496
|
+
}
|
|
542
1497
|
}
|
|
543
|
-
} catch (error) {
|
|
544
|
-
status = "FAIL";
|
|
545
|
-
const err = error;
|
|
546
|
-
note = `(error: ${err.message?.split("\n")[0] || "unknown"})`;
|
|
547
1498
|
}
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
1499
|
+
}
|
|
1500
|
+
specGroups.set(entry.name, {
|
|
1501
|
+
pass: specPass,
|
|
1502
|
+
fail: specFail,
|
|
1503
|
+
warning: specWarning
|
|
1504
|
+
});
|
|
1505
|
+
}
|
|
1506
|
+
const conflictCfg = getHeuristicConfig(config, "Validate Conflict");
|
|
1507
|
+
if (conflictCfg.severity !== "off") {
|
|
1508
|
+
const conflictResults = checkConflicts(specsDir, config);
|
|
1509
|
+
for (const cr of conflictResults) {
|
|
1510
|
+
if (cr.passed) continue;
|
|
1511
|
+
const level = conflictCfg.severity === "warning" ? "warning" : "fail";
|
|
1512
|
+
collectResult(
|
|
1513
|
+
allResults,
|
|
1514
|
+
level,
|
|
1515
|
+
"(cross-spec)",
|
|
1516
|
+
cr.label,
|
|
1517
|
+
cr.message,
|
|
1518
|
+
""
|
|
1519
|
+
);
|
|
1520
|
+
if (level === "warning") {
|
|
1521
|
+
totalWarning++;
|
|
553
1522
|
} else {
|
|
554
|
-
console.log(
|
|
555
|
-
` [${chalk4.red("\u2717")}] ${chalk4.cyan(label)}: ${description} ${chalk4.gray(note)}`
|
|
556
|
-
);
|
|
557
1523
|
totalFail++;
|
|
558
1524
|
}
|
|
559
1525
|
}
|
|
560
1526
|
}
|
|
561
|
-
|
|
1527
|
+
if (fmt === "text" || fmt === "github-annotation") {
|
|
1528
|
+
for (const r of allResults) {
|
|
1529
|
+
out(fmt, r.level, r.spec, r.label, r.message, r.note);
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
1532
|
+
flushResults(
|
|
1533
|
+
allResults,
|
|
1534
|
+
fmt,
|
|
1535
|
+
specGroups,
|
|
1536
|
+
totalPass,
|
|
1537
|
+
totalFail,
|
|
1538
|
+
totalWarning
|
|
1539
|
+
);
|
|
1540
|
+
return totalFail;
|
|
1541
|
+
}
|
|
1542
|
+
const exitCode = await runValidation();
|
|
1543
|
+
if (options?.watch) {
|
|
1544
|
+
let timer = null;
|
|
1545
|
+
console.log(chalk6.gray("\nWatching for changes... (Ctrl+C to stop)"));
|
|
1546
|
+
const watcher = watch(specsDir, { recursive: true });
|
|
1547
|
+
watcher.on("change", () => {
|
|
1548
|
+
if (timer) clearTimeout(timer);
|
|
1549
|
+
timer = setTimeout(async () => {
|
|
1550
|
+
console.clear();
|
|
1551
|
+
const code = await runValidation();
|
|
1552
|
+
console.log(chalk6.gray("\nWatching for changes... (Ctrl+C to stop)"));
|
|
1553
|
+
}, 300);
|
|
1554
|
+
});
|
|
1555
|
+
process.on("SIGINT", () => {
|
|
1556
|
+
watcher.close();
|
|
1557
|
+
process.exit(0);
|
|
1558
|
+
});
|
|
1559
|
+
process.on("SIGTERM", () => {
|
|
1560
|
+
watcher.close();
|
|
1561
|
+
process.exit(0);
|
|
1562
|
+
});
|
|
1563
|
+
await new Promise(() => {
|
|
1564
|
+
});
|
|
1565
|
+
} else {
|
|
1566
|
+
process.exit(exitCode > 0 ? 1 : 0);
|
|
562
1567
|
}
|
|
563
|
-
console.log(
|
|
564
|
-
chalk4.gray(`
|
|
565
|
-
Results: ${totalPass} passed, ${totalFail} failed`)
|
|
566
|
-
);
|
|
567
|
-
process.exit(totalFail > 0 ? 1 : 0);
|
|
568
1568
|
}
|
|
569
1569
|
|
|
570
1570
|
// src/index.ts
|
|
571
|
-
var
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
1571
|
+
var __dirname2 = fileURLToPath2(new URL(".", import.meta.url));
|
|
1572
|
+
var pkg = JSON.parse(
|
|
1573
|
+
readFileSync7(join8(resolve7(__dirname2, ".."), "package.json"), "utf-8")
|
|
1574
|
+
);
|
|
1575
|
+
var program = new Command3();
|
|
1576
|
+
program.name("letra").description("SDD-agnostic memory framework for AI coding agents").version(pkg.version);
|
|
1577
|
+
program.command("init [path]").option("--yes", "Skip prompts and use defaults").description("Initialize .letra/ directory with templates").action((path, options) => init(path, { ...options }));
|
|
1578
|
+
program.command("spec <name>").option(
|
|
1579
|
+
"--template <type>",
|
|
1580
|
+
"Template type: web-api, cli-tool, mobile-feature"
|
|
1581
|
+
).description("Create a new spec from template").action((name, options) => specNew(name, { ...options }));
|
|
575
1582
|
program.command("lint [path]").description("Validate spec format and completeness").action(lint);
|
|
576
|
-
program.command("validate [path]").description("Check if artifacts meet acceptance criteria").action(validate);
|
|
1583
|
+
program.command("validate [path]").option("--watch", "Watch specs and re-validate on change").option("--format <type>", "Output format: text, github-annotation, junit").description("Check if artifacts meet acceptance criteria").action((path, options) => validate(path, { ...options }));
|
|
1584
|
+
program.addCommand(decisionCommand());
|
|
1585
|
+
program.addCommand(focus_default());
|
|
577
1586
|
program.parse();
|