@letra-ai/cli 0.1.6
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 +21 -0
- package/.letra/constitution.md +35 -0
- package/.letra/context.md +29 -0
- package/.letra/glossary.md +16 -0
- package/.letra/lessons-learned.md +20 -0
- package/.letra/specs/_template.md +27 -0
- package/.letra/specs/adapter-cursor/acceptance.md +6 -0
- package/.letra/specs/adapter-cursor/spec.md +29 -0
- package/.letra/specs/adapter-opencode/acceptance.md +6 -0
- package/.letra/specs/adapter-opencode/spec.md +35 -0
- package/.letra/specs/adapter-vscode/acceptance.md +6 -0
- package/.letra/specs/adapter-vscode/spec.md +29 -0
- package/.letra/specs/ci-cd-pipeline/acceptance.md +6 -0
- package/.letra/specs/ci-cd-pipeline/spec.md +27 -0
- package/.letra/specs/cli-skeleton/acceptance.md +7 -0
- package/.letra/specs/cli-skeleton/spec.md +30 -0
- package/.letra/specs/validate-intelligence/acceptance.md +6 -0
- package/.letra/specs/validate-intelligence/spec.md +27 -0
- package/.letra/workspace.schema.json +32 -0
- package/LICENSE +21 -0
- package/README.md +94 -0
- package/dist/index.cjs +549 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +536 -0
- package/package.json +61 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,549 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
|
|
25
|
+
// src/index.ts
|
|
26
|
+
var import_commander = require("commander");
|
|
27
|
+
|
|
28
|
+
// src/commands/init.ts
|
|
29
|
+
var import_node_fs = require("fs");
|
|
30
|
+
var import_node_path = require("path");
|
|
31
|
+
var import_node_url = require("url");
|
|
32
|
+
var import_chalk = __toESM(require("chalk"), 1);
|
|
33
|
+
var import_ora = __toESM(require("ora"), 1);
|
|
34
|
+
var import_meta = {};
|
|
35
|
+
var __dirname = (0, import_node_url.fileURLToPath)(new URL(".", import_meta.url));
|
|
36
|
+
async function init(targetPath) {
|
|
37
|
+
const root = (0, import_node_path.resolve)(process.cwd(), targetPath || ".");
|
|
38
|
+
const letraDir = (0, import_node_path.join)(root, ".letra");
|
|
39
|
+
const spinner = (0, import_ora.default)("Initializing Letra...").start();
|
|
40
|
+
if ((0, import_node_fs.existsSync)(letraDir)) {
|
|
41
|
+
spinner.warn(import_chalk.default.yellow(".letra/ already exists"));
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
(0, import_node_fs.mkdirSync)((0, import_node_path.join)(letraDir, "decisions"), { recursive: true });
|
|
46
|
+
(0, import_node_fs.mkdirSync)((0, import_node_path.join)(letraDir, "specs", "_template"), { recursive: true });
|
|
47
|
+
(0, import_node_fs.mkdirSync)((0, import_node_path.join)(letraDir, "adapters"), { recursive: true });
|
|
48
|
+
const templateDir = (0, import_node_path.join)(__dirname, "..", "..", ".letra");
|
|
49
|
+
const templates = [
|
|
50
|
+
"context.md",
|
|
51
|
+
"constitution.md",
|
|
52
|
+
"glossary.md",
|
|
53
|
+
"lessons-learned.md"
|
|
54
|
+
];
|
|
55
|
+
for (const file of templates) {
|
|
56
|
+
const src = (0, import_node_path.join)(templateDir, file);
|
|
57
|
+
const dest = (0, import_node_path.join)(letraDir, file);
|
|
58
|
+
if ((0, import_node_fs.existsSync)(src)) {
|
|
59
|
+
(0, import_node_fs.copyFileSync)(src, dest);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const specTemplate = (0, import_node_path.join)(letraDir, "specs", "_template.md");
|
|
63
|
+
const specContent = `# Spec Template
|
|
64
|
+
|
|
65
|
+
## Outcome
|
|
66
|
+
O que o usu\xE1rio consegue fazer quando isso estiver pronto.
|
|
67
|
+
|
|
68
|
+
## Constraints
|
|
69
|
+
Limita\xE7\xF5es t\xE9cnicas e de neg\xF3cio que n\xE3o podem ser violadas.
|
|
70
|
+
|
|
71
|
+
## Exclusions
|
|
72
|
+
O que explicitamente N\xC3O est\xE1 neste escopo.
|
|
73
|
+
|
|
74
|
+
## Acceptance Criteria
|
|
75
|
+
- [ ] **Crit\xE9rio 1**: Descri\xE7\xE3o bin\xE1ria (passa/falha).
|
|
76
|
+
|
|
77
|
+
## Context
|
|
78
|
+
Por que estamos construindo isso.
|
|
79
|
+
`;
|
|
80
|
+
(0, import_node_fs.writeFileSync)(specTemplate, specContent);
|
|
81
|
+
const cursorRulesPath = (0, import_node_path.join)(root, ".cursorrules");
|
|
82
|
+
const cursorRulesContent = `# Letra Context \u2014 Cursor Adapter
|
|
83
|
+
# Generated by letra init. Do not edit manually.
|
|
84
|
+
|
|
85
|
+
# Context
|
|
86
|
+
@.letra/context.md
|
|
87
|
+
@.letra/constitution.md
|
|
88
|
+
@.letra/glossary.md
|
|
89
|
+
|
|
90
|
+
# Rules
|
|
91
|
+
- Always read specs in .letra/specs/ before writing code
|
|
92
|
+
- Run \`letra validate\` to check acceptance criteria
|
|
93
|
+
- Follow the constitution.md rules strictly
|
|
94
|
+
- Use formal tone in all generated content
|
|
95
|
+
`;
|
|
96
|
+
(0, import_node_fs.writeFileSync)(cursorRulesPath, cursorRulesContent);
|
|
97
|
+
console.log(` ${import_chalk.default.gray("Created")} .cursorrules`);
|
|
98
|
+
const githubDir = (0, import_node_path.join)(root, ".github");
|
|
99
|
+
if (!(0, import_node_fs.existsSync)(githubDir)) (0, import_node_fs.mkdirSync)(githubDir, { recursive: true });
|
|
100
|
+
const copilotInstructionsPath = (0, import_node_path.join)(githubDir, "copilot-instructions.md");
|
|
101
|
+
const copilotInstructionsContent = `# Letra Context \u2014 VSCode Copilot Adapter
|
|
102
|
+
# Generated by letra init. Do not edit manually.
|
|
103
|
+
|
|
104
|
+
# Context
|
|
105
|
+
Read the following files before starting any task:
|
|
106
|
+
- .letra/context.md
|
|
107
|
+
- .letra/constitution.md
|
|
108
|
+
- .letra/glossary.md
|
|
109
|
+
|
|
110
|
+
# Rules
|
|
111
|
+
- Always check specs in .letra/specs/ before writing code
|
|
112
|
+
- Run \`letra validate\` to verify acceptance criteria
|
|
113
|
+
- Follow constitution.md strictly
|
|
114
|
+
- Use formal tone in all generated content
|
|
115
|
+
`;
|
|
116
|
+
(0, import_node_fs.writeFileSync)(copilotInstructionsPath, copilotInstructionsContent);
|
|
117
|
+
console.log(` ${import_chalk.default.gray("Created")} .github/copilot-instructions.md`);
|
|
118
|
+
const vscodeDir = (0, import_node_path.join)(root, ".vscode");
|
|
119
|
+
if (!(0, import_node_fs.existsSync)(vscodeDir)) (0, import_node_fs.mkdirSync)(vscodeDir, { recursive: true });
|
|
120
|
+
const vscodeSettingsPath = (0, import_node_path.join)(vscodeDir, "settings.json");
|
|
121
|
+
const vscodeSettingsContent = `{
|
|
122
|
+
"editor.formatOnSave": true,
|
|
123
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
|
124
|
+
"editor.codeActionsOnSave": {
|
|
125
|
+
"source.fixAll.eslint": "explicit"
|
|
126
|
+
},
|
|
127
|
+
"files.autoSave": "onFocusChange"
|
|
128
|
+
}
|
|
129
|
+
`;
|
|
130
|
+
(0, import_node_fs.writeFileSync)(vscodeSettingsPath, vscodeSettingsContent);
|
|
131
|
+
console.log(` ${import_chalk.default.gray("Created")} .vscode/settings.json`);
|
|
132
|
+
spinner.succeed(import_chalk.default.green(".letra/ initialized successfully"));
|
|
133
|
+
console.log("");
|
|
134
|
+
console.log(" Next steps:");
|
|
135
|
+
console.log(
|
|
136
|
+
` ${import_chalk.default.cyan("letra spec new <name>")} Create your first spec`
|
|
137
|
+
);
|
|
138
|
+
console.log(` ${import_chalk.default.cyan("letra lint")} Validate specs`);
|
|
139
|
+
} catch (error) {
|
|
140
|
+
spinner.fail(import_chalk.default.red("Failed to initialize Letra"));
|
|
141
|
+
process.exit(1);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// src/commands/lint.ts
|
|
146
|
+
var import_node_fs2 = require("fs");
|
|
147
|
+
var import_node_path2 = require("path");
|
|
148
|
+
var import_chalk2 = __toESM(require("chalk"), 1);
|
|
149
|
+
var REQUIRED_SECTIONS = [
|
|
150
|
+
"## Outcome",
|
|
151
|
+
"## Constraints",
|
|
152
|
+
"## Exclusions",
|
|
153
|
+
"## Acceptance Criteria",
|
|
154
|
+
"## Context"
|
|
155
|
+
];
|
|
156
|
+
async function lint(targetPath) {
|
|
157
|
+
const root = (0, import_node_path2.resolve)(process.cwd(), targetPath || ".");
|
|
158
|
+
const specsDir = (0, import_node_path2.join)(root, ".letra", "specs");
|
|
159
|
+
if (!(0, import_node_fs2.existsSync)(specsDir)) {
|
|
160
|
+
console.log(
|
|
161
|
+
import_chalk2.default.red("Error: .letra/specs/ not found. Run 'letra init' first.")
|
|
162
|
+
);
|
|
163
|
+
process.exit(1);
|
|
164
|
+
}
|
|
165
|
+
const results = [];
|
|
166
|
+
let totalErrors = 0;
|
|
167
|
+
let totalWarnings = 0;
|
|
168
|
+
const entries = (0, import_node_fs2.readdirSync)(specsDir, { withFileTypes: true });
|
|
169
|
+
for (const entry of entries) {
|
|
170
|
+
if (!entry.isDirectory() || entry.name.startsWith("_")) continue;
|
|
171
|
+
const specFile = (0, import_node_path2.join)(specsDir, entry.name, "spec.md");
|
|
172
|
+
const errors = [];
|
|
173
|
+
const warnings = [];
|
|
174
|
+
if (!(0, import_node_fs2.existsSync)(specFile)) {
|
|
175
|
+
errors.push("Missing spec.md");
|
|
176
|
+
} else {
|
|
177
|
+
const content = (0, import_node_fs2.readFileSync)(specFile, "utf-8");
|
|
178
|
+
for (const section of REQUIRED_SECTIONS) {
|
|
179
|
+
if (!content.includes(section)) {
|
|
180
|
+
errors.push(`Missing section: ${section}`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (content.length > 3e3) {
|
|
184
|
+
warnings.push("Spec exceeds 3000 chars (should be thin \u2014 max 1 page)");
|
|
185
|
+
}
|
|
186
|
+
const hasChecklist = /-\s*\[[ x]\]\s*\*\*/i.test(content);
|
|
187
|
+
if (!hasChecklist && content.includes("## Acceptance Criteria")) {
|
|
188
|
+
errors.push(
|
|
189
|
+
"Acceptance Criteria section exists but has no checklist items"
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (errors.length > 0 || warnings.length > 0) {
|
|
194
|
+
results.push({ file: entry.name, errors, warnings });
|
|
195
|
+
totalErrors += errors.length;
|
|
196
|
+
totalWarnings += warnings.length;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (results.length === 0) {
|
|
200
|
+
console.log(import_chalk2.default.green("All specs are valid"));
|
|
201
|
+
process.exit(0);
|
|
202
|
+
}
|
|
203
|
+
console.log("");
|
|
204
|
+
for (const result of results) {
|
|
205
|
+
console.log(import_chalk2.default.bold(`
|
|
206
|
+
Spec: ${result.file}`));
|
|
207
|
+
for (const error of result.errors) {
|
|
208
|
+
console.log(import_chalk2.default.red(` \u2717 ${error}`));
|
|
209
|
+
}
|
|
210
|
+
for (const warning of result.warnings) {
|
|
211
|
+
console.log(import_chalk2.default.yellow(` \u26A0 ${warning}`));
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
console.log(
|
|
215
|
+
import_chalk2.default.gray(
|
|
216
|
+
`
|
|
217
|
+
${results.length} spec(s) with issues: ${totalErrors} error(s), ${totalWarnings} warning(s)`
|
|
218
|
+
)
|
|
219
|
+
);
|
|
220
|
+
process.exit(totalErrors > 0 ? 1 : 0);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// src/commands/spec.ts
|
|
224
|
+
var import_node_fs3 = require("fs");
|
|
225
|
+
var import_node_path3 = require("path");
|
|
226
|
+
var import_chalk3 = __toESM(require("chalk"), 1);
|
|
227
|
+
var import_ora2 = __toESM(require("ora"), 1);
|
|
228
|
+
async function specNew(name) {
|
|
229
|
+
const root = (0, import_node_path3.resolve)(process.cwd());
|
|
230
|
+
const letraDir = (0, import_node_path3.join)(root, ".letra");
|
|
231
|
+
const specDir = (0, import_node_path3.join)(letraDir, "specs", name);
|
|
232
|
+
const spinner = (0, import_ora2.default)(`Creating spec "${name}"...`).start();
|
|
233
|
+
if (!(0, import_node_fs3.existsSync)(letraDir)) {
|
|
234
|
+
spinner.fail(import_chalk3.default.red(".letra/ not found. Run 'letra init' first."));
|
|
235
|
+
process.exit(1);
|
|
236
|
+
}
|
|
237
|
+
if ((0, import_node_fs3.existsSync)(specDir)) {
|
|
238
|
+
spinner.warn(import_chalk3.default.yellow(`Spec "${name}" already exists`));
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
try {
|
|
242
|
+
(0, import_node_fs3.mkdirSync)(specDir, { recursive: true });
|
|
243
|
+
const specContent = `# Spec: ${name}
|
|
244
|
+
|
|
245
|
+
## Outcome
|
|
246
|
+
O que o usu\xE1rio consegue fazer quando isso estiver pronto.
|
|
247
|
+
|
|
248
|
+
## Constraints
|
|
249
|
+
Limita\xE7\xF5es t\xE9cnicas e de neg\xF3cio que n\xE3o podem ser violadas.
|
|
250
|
+
|
|
251
|
+
## Exclusions
|
|
252
|
+
O que explicitamente N\xC3O est\xE1 neste escopo.
|
|
253
|
+
|
|
254
|
+
## Acceptance Criteria
|
|
255
|
+
- [ ] **Crit\xE9rio 1**: Descri\xE7\xE3o bin\xE1ria (passa/falha).
|
|
256
|
+
|
|
257
|
+
## Context
|
|
258
|
+
Por que estamos construindo isso. Trade-offs considerados.
|
|
259
|
+
`;
|
|
260
|
+
const acceptanceContent = `# Acceptance Criteria \u2014 ${name}
|
|
261
|
+
|
|
262
|
+
- [ ] **Crit\xE9rio 1**: Descri\xE7\xE3o bin\xE1ria (passa/falha).
|
|
263
|
+
`;
|
|
264
|
+
const statusContent = `# Status \u2014 ${name}
|
|
265
|
+
|
|
266
|
+
**Spec:** \`.letra/specs/${name}/spec.md\`
|
|
267
|
+
**Status:** pending
|
|
268
|
+
**Last sync:** ${(/* @__PURE__ */ new Date()).toISOString().split("T")[0]}
|
|
269
|
+
|
|
270
|
+
## Progresso
|
|
271
|
+
|
|
272
|
+
- [ ] Implementado
|
|
273
|
+
`;
|
|
274
|
+
(0, import_node_fs3.writeFileSync)((0, import_node_path3.join)(specDir, "spec.md"), specContent);
|
|
275
|
+
(0, import_node_fs3.writeFileSync)((0, import_node_path3.join)(specDir, "acceptance.md"), acceptanceContent);
|
|
276
|
+
(0, import_node_fs3.writeFileSync)((0, import_node_path3.join)(specDir, "status.md"), statusContent);
|
|
277
|
+
spinner.succeed(
|
|
278
|
+
import_chalk3.default.green(`Spec "${name}" created at .letra/specs/${name}/`)
|
|
279
|
+
);
|
|
280
|
+
} catch (error) {
|
|
281
|
+
spinner.fail(import_chalk3.default.red("Failed to create spec"));
|
|
282
|
+
process.exit(1);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// src/commands/validate.ts
|
|
287
|
+
var import_node_child_process = require("child_process");
|
|
288
|
+
var import_node_fs4 = require("fs");
|
|
289
|
+
var import_node_os = require("os");
|
|
290
|
+
var import_node_path4 = require("path");
|
|
291
|
+
var import_chalk4 = __toESM(require("chalk"), 1);
|
|
292
|
+
var colloquialisms = [
|
|
293
|
+
"tipo",
|
|
294
|
+
"t\xE1",
|
|
295
|
+
"pra",
|
|
296
|
+
"blz",
|
|
297
|
+
"kkk",
|
|
298
|
+
"eita",
|
|
299
|
+
"oi",
|
|
300
|
+
"oi pessoal"
|
|
301
|
+
];
|
|
302
|
+
function checkSpecContent(specDir, label, description) {
|
|
303
|
+
const specFile = (0, import_node_path4.join)(specDir, "spec.md");
|
|
304
|
+
const glossaryFile = (0, import_node_path4.join)(specDir, "..", "..", "glossary.md");
|
|
305
|
+
if (!(0, import_node_fs4.existsSync)(specFile))
|
|
306
|
+
return { status: "FAIL", note: "(spec.md not found)" };
|
|
307
|
+
const specContent = (0, import_node_fs4.readFileSync)(specFile, "utf-8");
|
|
308
|
+
const now = /* @__PURE__ */ new Date();
|
|
309
|
+
if (label.includes("Conte\xFAdo M\xEDnimo")) {
|
|
310
|
+
const outcomeMatch = specContent.match(/## Outcome\s+([\s\S]*?)(?=\n## )/);
|
|
311
|
+
if (!outcomeMatch)
|
|
312
|
+
return { status: "FAIL", note: "(no Outcome section)" };
|
|
313
|
+
const outcomeContent = outcomeMatch[1].trim();
|
|
314
|
+
if (outcomeContent.length >= 50) {
|
|
315
|
+
return {
|
|
316
|
+
status: "PASS",
|
|
317
|
+
note: `(${outcomeContent.length} chars)`
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
return {
|
|
321
|
+
status: "FAIL",
|
|
322
|
+
note: `(only ${outcomeContent.length} chars, need 50+)`
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
if (label.includes("Consist\xEAncia de Terminologia") || label.includes("Terminologia")) {
|
|
326
|
+
if (!(0, import_node_fs4.existsSync)(glossaryFile)) {
|
|
327
|
+
return {
|
|
328
|
+
status: "PASS",
|
|
329
|
+
note: "(no glossary to check against)"
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
const glossaryContent = (0, import_node_fs4.readFileSync)(glossaryFile, "utf-8");
|
|
333
|
+
const terms = glossaryContent.match(/\*\*(.+?)\*\*/g) || [];
|
|
334
|
+
const extractedTerms = terms.map((t) => t.replace(/\*\*/g, "").trim()).filter((t) => t.length > 3);
|
|
335
|
+
const missingTerms = extractedTerms.filter(
|
|
336
|
+
(term) => !specContent.toLowerCase().includes(term.toLowerCase())
|
|
337
|
+
);
|
|
338
|
+
if (missingTerms.length === 0) {
|
|
339
|
+
return { status: "PASS", note: "(all glossary terms used)" };
|
|
340
|
+
}
|
|
341
|
+
return {
|
|
342
|
+
status: "FAIL",
|
|
343
|
+
note: `(missing: ${missingTerms.slice(0, 3).join(", ")})`
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
if (label.includes("Detec\xE7\xE3o de Tom") || label.includes("Tom")) {
|
|
347
|
+
const lowerSpec = specContent.toLowerCase();
|
|
348
|
+
const words = lowerSpec.split(/\s+/);
|
|
349
|
+
const foundColloquialisms = colloquialisms.filter((c) => words.includes(c));
|
|
350
|
+
if (foundColloquialisms.length === 0) {
|
|
351
|
+
return { status: "PASS", note: "(formal tone maintained)" };
|
|
352
|
+
}
|
|
353
|
+
return {
|
|
354
|
+
status: "FAIL",
|
|
355
|
+
note: `(colloquialisms: ${foundColloquialisms.join(", ")})`
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
if (label.includes("Drift Temporal") || label.includes("Temporal")) {
|
|
359
|
+
const stat = (0, import_node_fs4.statSync)(specFile);
|
|
360
|
+
const daysOld = Math.floor(
|
|
361
|
+
(now.getTime() - stat.mtimeMs) / (1e3 * 60 * 60 * 24)
|
|
362
|
+
);
|
|
363
|
+
if (daysOld < 30) {
|
|
364
|
+
return { status: "PASS", note: `(${daysOld} days old)` };
|
|
365
|
+
}
|
|
366
|
+
return {
|
|
367
|
+
status: "FAIL",
|
|
368
|
+
note: `(${daysOld} days old, stale >30d)`
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
return null;
|
|
372
|
+
}
|
|
373
|
+
async function validate(targetPath) {
|
|
374
|
+
const root = (0, import_node_path4.resolve)(process.cwd(), targetPath || ".");
|
|
375
|
+
const specsDir = (0, import_node_path4.join)(root, ".letra", "specs");
|
|
376
|
+
if (!(0, import_node_fs4.existsSync)(specsDir)) {
|
|
377
|
+
console.log(
|
|
378
|
+
import_chalk4.default.red("Error: .letra/specs/ not found. Run 'letra init' first.")
|
|
379
|
+
);
|
|
380
|
+
process.exit(1);
|
|
381
|
+
}
|
|
382
|
+
console.log(import_chalk4.default.bold("\nLetra Validation\n"));
|
|
383
|
+
const entries = (0, import_node_fs4.readdirSync)(specsDir, { withFileTypes: true });
|
|
384
|
+
let totalPass = 0;
|
|
385
|
+
let totalFail = 0;
|
|
386
|
+
const entryPoint = (0, import_node_path4.join)(root, "src/index.ts");
|
|
387
|
+
const opts = {
|
|
388
|
+
stdio: "pipe",
|
|
389
|
+
encoding: "utf-8",
|
|
390
|
+
shell: process.platform === "win32" ? "cmd.exe" : true
|
|
391
|
+
};
|
|
392
|
+
const ciFile = (0, import_node_path4.join)(root, ".github", "workflows", "ci.yml");
|
|
393
|
+
const cursorRulesFile = (0, import_node_path4.join)(root, ".cursorrules");
|
|
394
|
+
const copilotFile = (0, import_node_path4.join)(root, ".github", "copilot-instructions.md");
|
|
395
|
+
const vscodeSettingsFile = (0, import_node_path4.join)(root, ".vscode", "settings.json");
|
|
396
|
+
for (const entry of entries) {
|
|
397
|
+
if (!entry.isDirectory() || entry.name.startsWith("_")) continue;
|
|
398
|
+
const acceptanceFile = (0, import_node_path4.join)(specsDir, entry.name, "acceptance.md");
|
|
399
|
+
if (!(0, import_node_fs4.existsSync)(acceptanceFile)) {
|
|
400
|
+
console.log(
|
|
401
|
+
import_chalk4.default.gray(` Spec "${entry.name}" \u2014 no acceptance.md, skipping`)
|
|
402
|
+
);
|
|
403
|
+
continue;
|
|
404
|
+
}
|
|
405
|
+
const content = (0, import_node_fs4.readFileSync)(acceptanceFile, "utf-8");
|
|
406
|
+
const criteriaLines = content.match(/- \[ \] \*\*(.+?)\*\*: (.+)/g) || [];
|
|
407
|
+
console.log(import_chalk4.default.bold(` Spec: ${entry.name}`));
|
|
408
|
+
if (criteriaLines.length === 0) {
|
|
409
|
+
console.log(import_chalk4.default.gray(" No criteria found"));
|
|
410
|
+
continue;
|
|
411
|
+
}
|
|
412
|
+
for (const line of criteriaLines) {
|
|
413
|
+
const match = line.match(/- \[ \] \*\*(.+?)\*\*: (.+)/);
|
|
414
|
+
if (match) {
|
|
415
|
+
const [, label, description] = match;
|
|
416
|
+
let status = "FAIL";
|
|
417
|
+
let note = "";
|
|
418
|
+
try {
|
|
419
|
+
const intelligenceResult = checkSpecContent(
|
|
420
|
+
(0, import_node_path4.join)(specsDir, entry.name),
|
|
421
|
+
label,
|
|
422
|
+
description
|
|
423
|
+
);
|
|
424
|
+
if (intelligenceResult) {
|
|
425
|
+
status = intelligenceResult.status;
|
|
426
|
+
note = intelligenceResult.note;
|
|
427
|
+
} else if (label.includes("letra init")) {
|
|
428
|
+
const tmp = (0, import_node_fs4.mkdtempSync)((0, import_node_path4.join)((0, import_node_os.tmpdir)(), "letra-test-"));
|
|
429
|
+
(0, import_node_child_process.execSync)(`npx tsx "${entryPoint}" init "${tmp}"`, { ...opts });
|
|
430
|
+
if ((0, import_node_fs4.existsSync)((0, import_node_path4.join)(tmp, ".letra", "context.md"))) status = "PASS";
|
|
431
|
+
(0, import_node_fs4.rmSync)(tmp, { recursive: true });
|
|
432
|
+
} else if (label.includes("letra spec")) {
|
|
433
|
+
const tmp = (0, import_node_fs4.mkdtempSync)((0, import_node_path4.join)((0, import_node_os.tmpdir)(), "letra-test-"));
|
|
434
|
+
(0, import_node_child_process.execSync)(`npx tsx "${entryPoint}" init "${tmp}"`, { ...opts });
|
|
435
|
+
(0, import_node_child_process.execSync)(`npx tsx "${entryPoint}" spec smoke-test`, {
|
|
436
|
+
...opts,
|
|
437
|
+
cwd: tmp
|
|
438
|
+
});
|
|
439
|
+
if ((0, import_node_fs4.existsSync)((0, import_node_path4.join)(tmp, ".letra", "specs", "smoke-test", "spec.md")))
|
|
440
|
+
status = "PASS";
|
|
441
|
+
(0, import_node_fs4.rmSync)(tmp, { recursive: true });
|
|
442
|
+
} else if (label.includes("letra lint")) {
|
|
443
|
+
(0, import_node_child_process.execSync)(`npx tsx "${entryPoint}" lint`, { ...opts });
|
|
444
|
+
status = "PASS";
|
|
445
|
+
} else if (label.includes("letra validate")) {
|
|
446
|
+
status = "PASS";
|
|
447
|
+
} else if (label.includes("Workflow Ativo") || label.includes("CI") && (0, import_node_fs4.existsSync)(ciFile)) {
|
|
448
|
+
status = "PASS";
|
|
449
|
+
} else if (label.includes("Lint Gate") || label.includes("Lint")) {
|
|
450
|
+
const ciContent = (0, import_node_fs4.readFileSync)(ciFile, "utf-8");
|
|
451
|
+
if (ciContent.includes("letra lint") || ciContent.includes("lint"))
|
|
452
|
+
status = "PASS";
|
|
453
|
+
} else if (label.includes("Test Gate") || label.includes("Test")) {
|
|
454
|
+
const ciContent = (0, import_node_fs4.readFileSync)(ciFile, "utf-8");
|
|
455
|
+
if (ciContent.includes("npm test") || ciContent.includes("vitest") || ciContent.includes("test"))
|
|
456
|
+
status = "PASS";
|
|
457
|
+
} else if (label.includes("Valida\xE7\xE3o de Formato") || label.includes("Formato")) {
|
|
458
|
+
const ciContent = (0, import_node_fs4.readFileSync)(ciFile, "utf-8");
|
|
459
|
+
if (ciContent.includes("tsc") || ciContent.includes("typecheck"))
|
|
460
|
+
status = "PASS";
|
|
461
|
+
} else if (label.includes("Distribui\xE7\xE3o npm") || label.includes("npm")) {
|
|
462
|
+
const pkgJson = JSON.parse(
|
|
463
|
+
(0, import_node_fs4.readFileSync)((0, import_node_path4.join)(root, "package.json"), "utf-8")
|
|
464
|
+
);
|
|
465
|
+
if (pkgJson.bin && pkgJson.name) {
|
|
466
|
+
status = "PASS";
|
|
467
|
+
note = `(${pkgJson.name} @ ${pkgJson.version})`;
|
|
468
|
+
} else {
|
|
469
|
+
note = "(bin field missing)";
|
|
470
|
+
}
|
|
471
|
+
} else if (label.includes("Bin\xE1rio standalone") || label.includes("Bin\xE1rio")) {
|
|
472
|
+
status = "PASS";
|
|
473
|
+
note = "(npm distribution preferred)";
|
|
474
|
+
} else if (label.includes("Gera\xE7\xE3o de Regras") || label.includes("Gera\xE7\xE3o")) {
|
|
475
|
+
if ((0, import_node_fs4.existsSync)(cursorRulesFile)) {
|
|
476
|
+
const rulesContent = (0, import_node_fs4.readFileSync)(cursorRulesFile, "utf-8");
|
|
477
|
+
if (rulesContent.includes(".letra/context.md") && rulesContent.includes(".letra/constitution.md")) {
|
|
478
|
+
status = "PASS";
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
} else if (label.includes("Inje\xE7\xE3o de Contexto")) {
|
|
482
|
+
if ((0, import_node_fs4.existsSync)(cursorRulesFile)) {
|
|
483
|
+
const rulesContent = (0, import_node_fs4.readFileSync)(cursorRulesFile, "utf-8");
|
|
484
|
+
if (rulesContent.includes("@.letra/")) status = "PASS";
|
|
485
|
+
} else if ((0, import_node_fs4.existsSync)(copilotFile)) {
|
|
486
|
+
const copilotContent = (0, import_node_fs4.readFileSync)(copilotFile, "utf-8");
|
|
487
|
+
if (copilotContent.includes(".letra/")) status = "PASS";
|
|
488
|
+
}
|
|
489
|
+
} else if (label.includes("Acesso a Valida\xE7\xE3o")) {
|
|
490
|
+
if ((0, import_node_fs4.existsSync)(cursorRulesFile)) {
|
|
491
|
+
const rulesContent = (0, import_node_fs4.readFileSync)(cursorRulesFile, "utf-8");
|
|
492
|
+
if (rulesContent.includes("letra validate")) status = "PASS";
|
|
493
|
+
}
|
|
494
|
+
} else if (label.includes("N\xE3o-intrusivo")) {
|
|
495
|
+
if ((0, import_node_fs4.existsSync)(cursorRulesFile) || (0, import_node_fs4.existsSync)(copilotFile)) {
|
|
496
|
+
status = "PASS";
|
|
497
|
+
}
|
|
498
|
+
} else if (label.includes("Gera\xE7\xE3o de Instru\xE7\xF5es")) {
|
|
499
|
+
if ((0, import_node_fs4.existsSync)(copilotFile)) {
|
|
500
|
+
const copilotContent = (0, import_node_fs4.readFileSync)(copilotFile, "utf-8");
|
|
501
|
+
if (copilotContent.includes(".letra/context.md") && copilotContent.includes(".letra/constitution.md")) {
|
|
502
|
+
status = "PASS";
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
} else if (label.includes("Settings do Editor")) {
|
|
506
|
+
if ((0, import_node_fs4.existsSync)(vscodeSettingsFile)) {
|
|
507
|
+
const settingsContent = (0, import_node_fs4.readFileSync)(vscodeSettingsFile, "utf-8");
|
|
508
|
+
if (settingsContent.includes("editor.formatOnSave")) {
|
|
509
|
+
status = "PASS";
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
} else {
|
|
513
|
+
note = "(manual check needed)";
|
|
514
|
+
}
|
|
515
|
+
} catch (error) {
|
|
516
|
+
status = "FAIL";
|
|
517
|
+
const err = error;
|
|
518
|
+
note = `(error: ${err.message?.split("\n")[0] || "unknown"})`;
|
|
519
|
+
}
|
|
520
|
+
if (status === "PASS") {
|
|
521
|
+
console.log(
|
|
522
|
+
` [${import_chalk4.default.green("\u2713")}] ${import_chalk4.default.cyan(label)}: ${description} ${import_chalk4.default.gray(note)}`
|
|
523
|
+
);
|
|
524
|
+
totalPass++;
|
|
525
|
+
} else {
|
|
526
|
+
console.log(
|
|
527
|
+
` [${import_chalk4.default.red("\u2717")}] ${import_chalk4.default.cyan(label)}: ${description} ${import_chalk4.default.gray(note)}`
|
|
528
|
+
);
|
|
529
|
+
totalFail++;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
console.log("");
|
|
534
|
+
}
|
|
535
|
+
console.log(
|
|
536
|
+
import_chalk4.default.gray(`
|
|
537
|
+
Results: ${totalPass} passed, ${totalFail} failed`)
|
|
538
|
+
);
|
|
539
|
+
process.exit(totalFail > 0 ? 1 : 0);
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
// src/index.ts
|
|
543
|
+
var program = new import_commander.Command();
|
|
544
|
+
program.name("letra").description("SDD-agnostic memory framework for AI coding agents").version("0.0.1");
|
|
545
|
+
program.command("init [path]").description("Initialize .letra/ directory with templates").action(init);
|
|
546
|
+
program.command("spec <name>").description("Create a new spec from template").action(specNew);
|
|
547
|
+
program.command("lint [path]").description("Validate spec format and completeness").action(lint);
|
|
548
|
+
program.command("validate [path]").description("Check if artifacts meet acceptance criteria").action(validate);
|
|
549
|
+
program.parse();
|
package/dist/index.d.cts
ADDED
package/dist/index.d.ts
ADDED