@letra-ai/cli 0.5.3 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-6HSUVCTR.js +363 -0
- package/dist/chunk-BKAUN5QH.js +300 -0
- package/dist/chunk-DMOLJWWW.js +3321 -0
- package/dist/chunk-EDD55PWL.js +119 -0
- package/dist/chunk-H64RC3YS.js +254 -0
- package/dist/chunk-JMIC5NKB.js +235 -0
- package/dist/chunk-L6YKDTAQ.js +275 -0
- package/dist/chunk-MJ2QXNH6.js +130 -0
- package/dist/chunk-OIHMDOIN.js +1326 -0
- package/dist/chunk-PDX44BCA.js +11 -0
- package/dist/chunk-URUC6ZZP.js +4781 -0
- package/dist/client/assets/index-EyRsq1SH.css +1 -0
- package/dist/client/assets/index-WfKR7Xp6.js +232 -0
- package/dist/client/favicon.svg +16 -4
- package/dist/client/index.html +25 -20
- package/dist/fallback-MQLGS4KL.js +46 -0
- package/dist/flow-serve-G5MSSB3G.js +18 -0
- package/dist/focus-sync-3D3XWCTI.js +17 -0
- package/dist/generate-UPFERQMD.js +20 -0
- package/dist/harness/default/v0.1.0/flows/sdlc.yaml +179 -0
- package/dist/harness/default/v0.1.0/gates/all-acs-passing.yaml +8 -0
- package/dist/harness/default/v0.1.0/gates/has-spec-file.yaml +7 -0
- package/dist/harness/default/v0.1.0/gates/human-approved-code.yaml +8 -0
- package/dist/harness/default/v0.1.0/gates/human-approved-spec.yaml +8 -0
- package/dist/harness/default/v0.1.0/gates/security-clear.yaml +8 -0
- package/dist/harness/default/v0.1.0/policies/sdlc-default.json +20 -0
- package/dist/harness/default/v0.1.0/roles/analyst.yaml +9 -0
- package/dist/harness/default/v0.1.0/roles/builder.yaml +9 -0
- package/dist/harness/default/v0.1.0/roles/pr-bot.yaml +8 -0
- package/dist/harness/default/v0.1.0/roles/reviewer.yaml +10 -0
- package/dist/harness/default/v0.1.0/roles/security.yaml +8 -0
- package/dist/harness/default/v0.1.1/flows/flow-main.yaml +61 -0
- package/dist/harness/default/v0.1.1/flows/sdlc.yaml +179 -0
- package/dist/harness/default/v0.1.1/gates/all-acs-passing.yaml +8 -0
- package/dist/harness/default/v0.1.1/gates/has-spec-file.yaml +7 -0
- package/dist/harness/default/v0.1.1/gates/human-approved-code.yaml +8 -0
- package/dist/harness/default/v0.1.1/gates/human-approved-spec.yaml +8 -0
- package/dist/harness/default/v0.1.1/gates/security-clear.yaml +8 -0
- package/dist/harness/default/v0.1.1/policies/sdlc-default.json +20 -0
- package/dist/harness/default/v0.1.1/roles/analyst.yaml +9 -0
- package/dist/harness/default/v0.1.1/roles/builder.yaml +9 -0
- package/dist/harness/default/v0.1.1/roles/pr-bot.yaml +8 -0
- package/dist/harness/default/v0.1.1/roles/reviewer.yaml +10 -0
- package/dist/harness/default/v0.1.1/roles/security.yaml +8 -0
- package/dist/harness/default/v0.1.2/flows/flow-main.yaml +86 -0
- package/dist/harness/default/v0.1.2/flows/sdlc.yaml +179 -0
- package/dist/harness/default/v0.1.2/gates/all-acs-passing.yaml +8 -0
- package/dist/harness/default/v0.1.2/gates/has-spec-file.yaml +7 -0
- package/dist/harness/default/v0.1.2/gates/human-approved-code.yaml +8 -0
- package/dist/harness/default/v0.1.2/gates/human-approved-spec.yaml +8 -0
- package/dist/harness/default/v0.1.2/gates/security-clear.yaml +8 -0
- package/dist/harness/default/v0.1.2/policies/sdlc-default.json +20 -0
- package/dist/harness/default/v0.1.2/roles/analyst.yaml +9 -0
- package/dist/harness/default/v0.1.2/roles/builder.yaml +9 -0
- package/dist/harness/default/v0.1.2/roles/pr-bot.yaml +8 -0
- package/dist/harness/default/v0.1.2/roles/reviewer.yaml +10 -0
- package/dist/harness/default/v0.1.2/roles/security.yaml +8 -0
- package/dist/harness/default/v0.1.3/flows/flow-main.yaml +90 -0
- package/dist/harness/default/v0.1.3/flows/sdlc.yaml +179 -0
- package/dist/harness/default/v0.1.3/gates/all-acs-passing.yaml +8 -0
- package/dist/harness/default/v0.1.3/gates/has-spec-file.yaml +7 -0
- package/dist/harness/default/v0.1.3/gates/human-approved-code.yaml +9 -0
- package/dist/harness/default/v0.1.3/gates/human-approved-spec.yaml +9 -0
- package/dist/harness/default/v0.1.3/gates/security-clear.yaml +8 -0
- package/dist/harness/default/v0.1.3/policies/sdlc-default.json +20 -0
- package/dist/harness/default/v0.1.3/roles/analyst.yaml +9 -0
- package/dist/harness/default/v0.1.3/roles/builder.yaml +9 -0
- package/dist/harness/default/v0.1.3/roles/pr-bot.yaml +8 -0
- package/dist/harness/default/v0.1.3/roles/reviewer.yaml +10 -0
- package/dist/harness/default/v0.1.3/roles/security.yaml +8 -0
- package/dist/harness/default/v0.2.0/executors/registry.yaml +51 -0
- package/dist/harness/default/v0.2.0/flows/flow-main.yaml +249 -0
- package/dist/harness/default/v0.2.0/gates/code-reviewed.yaml +7 -0
- package/dist/harness/default/v0.2.0/gates/human-approved.yaml +10 -0
- package/dist/harness/default/v0.2.0/gates/security-clear.yaml +7 -0
- package/dist/harness/default/v0.2.0/gates/spec-approved.yaml +10 -0
- package/dist/harness/default/v0.2.0/policies/sdlc-default.json +20 -0
- package/dist/harness/default/v0.2.0/roles/analyst.yaml +16 -0
- package/dist/harness/default/v0.2.0/roles/implementer.yaml +17 -0
- package/dist/harness/default/v0.2.0/roles/reviewer.yaml +17 -0
- package/dist/harness/default/v0.2.0/roles/security.yaml +17 -0
- package/dist/health-record-YDVXEVLR.js +21 -0
- package/dist/index.js +1951 -2530
- package/dist/init-wizard-NODBBNKO.js +178 -0
- package/dist/push-VJRSQGUD.js +116 -0
- package/dist/registry-6VPIA3EG.js +18 -0
- package/dist/server-P6GKRWDX.js +423 -0
- package/dist/service-2JN2KI4D.js +29 -0
- package/dist/session-log-WTQ5JBEN.js +21 -0
- package/dist/sitrep-OKNZJICV.js +16 -0
- package/package.json +37 -28
- package/dist/chunk-56GTTLC4.js +0 -1322
- package/dist/chunk-QWT5M4XU.js +0 -643
- package/dist/client/assets/index-CuLfFw4K.js +0 -85
- package/dist/client/assets/index-iyLqZcWx.css +0 -1
- package/dist/generate-BF5R5GGA.js +0 -7
- package/dist/sitrep-SI6ZFIAM.js +0 -10
- package/tsup.config.ts +0 -11
package/dist/chunk-56GTTLC4.js
DELETED
|
@@ -1,1322 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
__require,
|
|
4
|
-
generateAdapters,
|
|
5
|
-
getSummary,
|
|
6
|
-
loadHealthRecord,
|
|
7
|
-
mergeScanResults,
|
|
8
|
-
saveHealthRecord
|
|
9
|
-
} from "./chunk-QWT5M4XU.js";
|
|
10
|
-
|
|
11
|
-
// src/commands/sitrep.ts
|
|
12
|
-
import { existsSync as existsSync12, readFileSync as readFileSync10, readdirSync as readdirSync6, statSync as statSync2, writeFileSync as writeFileSync6 } from "fs";
|
|
13
|
-
import { join as join12, resolve as resolve2 } from "path";
|
|
14
|
-
import chalk2 from "chalk";
|
|
15
|
-
import { Command } from "commander";
|
|
16
|
-
|
|
17
|
-
// src/commands/flow-init.ts
|
|
18
|
-
import { existsSync as existsSync11, mkdirSync as mkdirSync4, readFileSync as readFileSync9, writeFileSync as writeFileSync5 } from "fs";
|
|
19
|
-
import { join as join11, resolve } from "path";
|
|
20
|
-
import { createInterface } from "readline";
|
|
21
|
-
import chalk from "chalk";
|
|
22
|
-
import ora from "ora";
|
|
23
|
-
|
|
24
|
-
// src/session-log.ts
|
|
25
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
26
|
-
import { join } from "path";
|
|
27
|
-
var LOG_FILE = "session-log.json";
|
|
28
|
-
var SCHEMA_VERSION = 1;
|
|
29
|
-
var MAX_ENTRIES = 500;
|
|
30
|
-
var logCounter = 0;
|
|
31
|
-
function logPath(root) {
|
|
32
|
-
return join(root, ".letra", LOG_FILE);
|
|
33
|
-
}
|
|
34
|
-
function nextId() {
|
|
35
|
-
logCounter++;
|
|
36
|
-
const ts = Date.now().toString(36).slice(-4);
|
|
37
|
-
return `log-${ts}-${logCounter.toString(36).padStart(3, "0")}`;
|
|
38
|
-
}
|
|
39
|
-
function loadSessionLog(root) {
|
|
40
|
-
const file = logPath(root);
|
|
41
|
-
if (!existsSync(file)) {
|
|
42
|
-
return { schemaVersion: SCHEMA_VERSION, entries: [] };
|
|
43
|
-
}
|
|
44
|
-
try {
|
|
45
|
-
const raw = readFileSync(file, "utf-8");
|
|
46
|
-
const log = JSON.parse(raw);
|
|
47
|
-
if (!log.entries) log.entries = [];
|
|
48
|
-
return log;
|
|
49
|
-
} catch {
|
|
50
|
-
return { schemaVersion: SCHEMA_VERSION, entries: [] };
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
function saveSessionLog(root, log) {
|
|
54
|
-
const dir = join(root, ".letra");
|
|
55
|
-
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
56
|
-
writeFileSync(logPath(root), JSON.stringify(log, null, 2), "utf-8");
|
|
57
|
-
}
|
|
58
|
-
function logEntry(root, action, description, options) {
|
|
59
|
-
const log = loadSessionLog(root);
|
|
60
|
-
const entry = {
|
|
61
|
-
id: nextId(),
|
|
62
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
63
|
-
action,
|
|
64
|
-
description,
|
|
65
|
-
itemId: options?.itemId ?? null,
|
|
66
|
-
acId: options?.acId ?? null,
|
|
67
|
-
details: options?.details ?? {}
|
|
68
|
-
};
|
|
69
|
-
log.entries.push(entry);
|
|
70
|
-
if (log.entries.length > MAX_ENTRIES) {
|
|
71
|
-
log.entries = log.entries.slice(log.entries.length - MAX_ENTRIES);
|
|
72
|
-
}
|
|
73
|
-
saveSessionLog(root, log);
|
|
74
|
-
return entry;
|
|
75
|
-
}
|
|
76
|
-
function queryLog(root, query) {
|
|
77
|
-
const log = loadSessionLog(root);
|
|
78
|
-
let entries = [...log.entries];
|
|
79
|
-
if (query?.itemId) {
|
|
80
|
-
entries = entries.filter((e) => e.itemId === query.itemId);
|
|
81
|
-
}
|
|
82
|
-
if (query?.action) {
|
|
83
|
-
entries = entries.filter((e) => e.action === query.action);
|
|
84
|
-
}
|
|
85
|
-
if (query?.since) {
|
|
86
|
-
const sinceDate = new Date(query.since).getTime();
|
|
87
|
-
entries = entries.filter((e) => new Date(e.timestamp).getTime() >= sinceDate);
|
|
88
|
-
}
|
|
89
|
-
entries.reverse();
|
|
90
|
-
if (!query?.all) {
|
|
91
|
-
const limit = query?.limit ?? 10;
|
|
92
|
-
const offset = query?.offset ?? 0;
|
|
93
|
-
entries = entries.slice(offset, offset + limit);
|
|
94
|
-
}
|
|
95
|
-
return entries;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// src/diagnostics/engine.ts
|
|
99
|
-
import { existsSync as existsSync10, writeFileSync as writeFileSync4 } from "fs";
|
|
100
|
-
import { join as join10 } from "path";
|
|
101
|
-
|
|
102
|
-
// src/diagnostics/snapshot.ts
|
|
103
|
-
import {
|
|
104
|
-
readFileSync as readFileSync2,
|
|
105
|
-
writeFileSync as writeFileSync2,
|
|
106
|
-
mkdirSync as mkdirSync2,
|
|
107
|
-
existsSync as existsSync2,
|
|
108
|
-
readdirSync,
|
|
109
|
-
rmSync
|
|
110
|
-
} from "fs";
|
|
111
|
-
import { join as join2 } from "path";
|
|
112
|
-
var SNAPSHOTS_DIR = ".letra/snapshots";
|
|
113
|
-
var MAX_SNAPSHOTS = 20;
|
|
114
|
-
var TTL_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
115
|
-
var SnapshotStore = class {
|
|
116
|
-
rootDir;
|
|
117
|
-
snapshotsDir;
|
|
118
|
-
constructor(rootDir) {
|
|
119
|
-
this.rootDir = rootDir;
|
|
120
|
-
this.snapshotsDir = join2(rootDir, SNAPSHOTS_DIR);
|
|
121
|
-
if (!existsSync2(this.snapshotsDir)) {
|
|
122
|
-
mkdirSync2(this.snapshotsDir, { recursive: true });
|
|
123
|
-
}
|
|
124
|
-
this.cleanup();
|
|
125
|
-
this.enforceMax();
|
|
126
|
-
}
|
|
127
|
-
async save(diagnosticId, diagnosticTitle, files) {
|
|
128
|
-
if (this.isDuplicate(diagnosticId, files)) {
|
|
129
|
-
return null;
|
|
130
|
-
}
|
|
131
|
-
const id = `${Date.now()}_${diagnosticId}`;
|
|
132
|
-
const snapshot = {
|
|
133
|
-
id,
|
|
134
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
135
|
-
diagnosticId,
|
|
136
|
-
diagnosticTitle,
|
|
137
|
-
files
|
|
138
|
-
};
|
|
139
|
-
writeFileSync2(
|
|
140
|
-
join2(this.snapshotsDir, `${id}.json`),
|
|
141
|
-
JSON.stringify(snapshot, null, 0),
|
|
142
|
-
"utf-8"
|
|
143
|
-
);
|
|
144
|
-
this.enforceMax();
|
|
145
|
-
return id;
|
|
146
|
-
}
|
|
147
|
-
async restore(snapshotId) {
|
|
148
|
-
const filePath = join2(this.snapshotsDir, `${snapshotId}.json`);
|
|
149
|
-
if (!existsSync2(filePath)) {
|
|
150
|
-
return { ok: false, restoredFiles: [] };
|
|
151
|
-
}
|
|
152
|
-
const snapshot = JSON.parse(readFileSync2(filePath, "utf-8"));
|
|
153
|
-
const restoredFiles = [];
|
|
154
|
-
for (const file of snapshot.files) {
|
|
155
|
-
const absolutePath = join2(this.rootDir, file.path);
|
|
156
|
-
writeFileSync2(absolutePath, file.before, "utf-8");
|
|
157
|
-
restoredFiles.push(file.path);
|
|
158
|
-
}
|
|
159
|
-
return { ok: true, restoredFiles };
|
|
160
|
-
}
|
|
161
|
-
async redo(snapshotId) {
|
|
162
|
-
const filePath = join2(this.snapshotsDir, `${snapshotId}.json`);
|
|
163
|
-
if (!existsSync2(filePath)) {
|
|
164
|
-
return { ok: false, redoneFiles: [] };
|
|
165
|
-
}
|
|
166
|
-
const snapshot = JSON.parse(readFileSync2(filePath, "utf-8"));
|
|
167
|
-
const redoneFiles = [];
|
|
168
|
-
for (const file of snapshot.files) {
|
|
169
|
-
const absolutePath = join2(this.rootDir, file.path);
|
|
170
|
-
writeFileSync2(absolutePath, file.after, "utf-8");
|
|
171
|
-
redoneFiles.push(file.path);
|
|
172
|
-
}
|
|
173
|
-
return { ok: true, redoneFiles };
|
|
174
|
-
}
|
|
175
|
-
list() {
|
|
176
|
-
if (!existsSync2(this.snapshotsDir)) return [];
|
|
177
|
-
return readdirSync(this.snapshotsDir).filter((f) => f.endsWith(".json")).map((f) => {
|
|
178
|
-
const content = readFileSync2(join2(this.snapshotsDir, f), "utf-8");
|
|
179
|
-
return JSON.parse(content);
|
|
180
|
-
}).sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime());
|
|
181
|
-
}
|
|
182
|
-
isDuplicate(diagnosticId, files) {
|
|
183
|
-
const last = this.getLastForDiagnostic(diagnosticId);
|
|
184
|
-
if (!last) return false;
|
|
185
|
-
if (last.files.length !== files.length) return false;
|
|
186
|
-
for (let i = 0; i < files.length; i++) {
|
|
187
|
-
if (last.files[i]?.after !== files[i]?.after) return false;
|
|
188
|
-
}
|
|
189
|
-
return true;
|
|
190
|
-
}
|
|
191
|
-
getLastForDiagnostic(diagnosticId) {
|
|
192
|
-
if (!existsSync2(this.snapshotsDir)) return null;
|
|
193
|
-
const entries = readdirSync(this.snapshotsDir).filter(
|
|
194
|
-
(f) => f.endsWith(".json") && f.includes(`_${diagnosticId}`)
|
|
195
|
-
);
|
|
196
|
-
if (entries.length === 0) return null;
|
|
197
|
-
entries.sort().reverse();
|
|
198
|
-
try {
|
|
199
|
-
const content = readFileSync2(join2(this.snapshotsDir, entries[0]), "utf-8");
|
|
200
|
-
return JSON.parse(content);
|
|
201
|
-
} catch {
|
|
202
|
-
return null;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
enforceMax() {
|
|
206
|
-
if (!existsSync2(this.snapshotsDir)) return;
|
|
207
|
-
const entries = readdirSync(this.snapshotsDir).filter((f) => f.endsWith(".json")).sort();
|
|
208
|
-
while (entries.length > MAX_SNAPSHOTS) {
|
|
209
|
-
const oldest = entries.shift();
|
|
210
|
-
if (oldest) {
|
|
211
|
-
rmSync(join2(this.snapshotsDir, oldest));
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
cleanup() {
|
|
216
|
-
if (!existsSync2(this.snapshotsDir)) return;
|
|
217
|
-
const cutoff = Date.now() - TTL_MS;
|
|
218
|
-
for (const file of readdirSync(this.snapshotsDir)) {
|
|
219
|
-
if (!file.endsWith(".json")) continue;
|
|
220
|
-
try {
|
|
221
|
-
const filePath = join2(this.snapshotsDir, file);
|
|
222
|
-
const snapshot = JSON.parse(readFileSync2(filePath, "utf-8"));
|
|
223
|
-
if (new Date(snapshot.timestamp).getTime() < cutoff) {
|
|
224
|
-
rmSync(filePath);
|
|
225
|
-
}
|
|
226
|
-
} catch {
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
// src/diagnostics/detectors/ac-stale.ts
|
|
233
|
-
import { readFileSync as readFileSync4, existsSync as existsSync4 } from "fs";
|
|
234
|
-
import { join as join4 } from "path";
|
|
235
|
-
import { readdirSync as readdirSync3 } from "fs";
|
|
236
|
-
|
|
237
|
-
// src/diagnostics/shared/file-search.ts
|
|
238
|
-
import { existsSync as existsSync3, readFileSync as readFileSync3, readdirSync as readdirSync2 } from "fs";
|
|
239
|
-
import { join as join3 } from "path";
|
|
240
|
-
var SEARCH_DIRS = ["packages/cli/src", "packages/client/src", "packages/ui/src"];
|
|
241
|
-
function searchInSource(rootDir, terms, extensions = [".ts", ".tsx"]) {
|
|
242
|
-
for (const searchDir of SEARCH_DIRS) {
|
|
243
|
-
const dir = join3(rootDir, searchDir);
|
|
244
|
-
if (!existsSync3(dir)) continue;
|
|
245
|
-
try {
|
|
246
|
-
const files = walkDir(dir, extensions);
|
|
247
|
-
for (const file of files) {
|
|
248
|
-
const content = readFileSync3(file, "utf-8");
|
|
249
|
-
for (const term of terms) {
|
|
250
|
-
if (content.includes(term)) return true;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
} catch {
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
return false;
|
|
257
|
-
}
|
|
258
|
-
function walkDir(dir, extensions = [".ts", ".tsx"]) {
|
|
259
|
-
const files = [];
|
|
260
|
-
try {
|
|
261
|
-
for (const entry of readdirSync2(dir, { withFileTypes: true })) {
|
|
262
|
-
const fullPath = join3(dir, entry.name);
|
|
263
|
-
if (entry.isDirectory() && entry.name !== "node_modules") {
|
|
264
|
-
files.push(...walkDir(fullPath, extensions));
|
|
265
|
-
} else if (entry.isFile() && extensions.some((ext) => entry.name.endsWith(ext))) {
|
|
266
|
-
files.push(fullPath);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
} catch {
|
|
270
|
-
}
|
|
271
|
-
return files;
|
|
272
|
-
}
|
|
273
|
-
function escapeRegex(s) {
|
|
274
|
-
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
// src/diagnostics/detectors/ac-stale.ts
|
|
278
|
-
var STALE_AC_PATTERN = /-\s\[ \]\s\*\*`([^`]+)`\*\*/g;
|
|
279
|
-
function toCamelCase(words) {
|
|
280
|
-
return words.map((w, i) => i === 0 ? w : w.charAt(0).toUpperCase() + w.slice(1)).join("");
|
|
281
|
-
}
|
|
282
|
-
function toPascalCase(words) {
|
|
283
|
-
return words.map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join("");
|
|
284
|
-
}
|
|
285
|
-
var acStaleDetector = {
|
|
286
|
-
name: "ac-stale",
|
|
287
|
-
async run(rootDir) {
|
|
288
|
-
const results = [];
|
|
289
|
-
const specsDir = join4(rootDir, ".letra", "specs");
|
|
290
|
-
if (!existsSync4(specsDir)) return results;
|
|
291
|
-
const specDirs = readdirSync3(specsDir, { withFileTypes: true }).filter(
|
|
292
|
-
(d) => d.isDirectory() && !d.name.startsWith("_")
|
|
293
|
-
);
|
|
294
|
-
for (const dir of specDirs) {
|
|
295
|
-
const specFile = join4(specsDir, dir.name, "spec.md");
|
|
296
|
-
if (!existsSync4(specFile)) continue;
|
|
297
|
-
const content = readFileSync4(specFile, "utf-8");
|
|
298
|
-
const matches = content.matchAll(STALE_AC_PATTERN);
|
|
299
|
-
for (const match of matches) {
|
|
300
|
-
const command = match[1].trim();
|
|
301
|
-
if (!command) continue;
|
|
302
|
-
const commandWords = command.split(/\s+/);
|
|
303
|
-
const camelCaseName = toCamelCase(commandWords);
|
|
304
|
-
const pascalCaseName = toPascalCase(commandWords);
|
|
305
|
-
const foundInSource = searchInSource(rootDir, [
|
|
306
|
-
command,
|
|
307
|
-
camelCaseName,
|
|
308
|
-
pascalCaseName
|
|
309
|
-
]);
|
|
310
|
-
if (foundInSource) {
|
|
311
|
-
results.push({
|
|
312
|
-
id: `ac-stale_${dir.name}_${command.replace(/\s+/g, "-")}`,
|
|
313
|
-
type: "info",
|
|
314
|
-
title: `AC "${command}" marcado [ ] mas implementado`,
|
|
315
|
-
description: `O acceptance criteria "${command}" do spec ${dir.name} est\xE1 marcado como n\xE3o feito ([ ]), mas o c\xF3digo-fonte cont\xE9m implementa\xE7\xE3o correspondente.`,
|
|
316
|
-
certainty: 0.9,
|
|
317
|
-
detector: "ac-stale",
|
|
318
|
-
autoFix: async () => {
|
|
319
|
-
const newContent = content.replace(
|
|
320
|
-
new RegExp(
|
|
321
|
-
`(- \\[ \\] \\*\\*\`)(${escapeRegex(command)}(\\s[^*]+)?\\*\\*)`
|
|
322
|
-
),
|
|
323
|
-
(m) => m.replace("[ ]", "[x]")
|
|
324
|
-
);
|
|
325
|
-
const before = readFileSync4(specFile, "utf-8");
|
|
326
|
-
return {
|
|
327
|
-
files: [
|
|
328
|
-
{
|
|
329
|
-
path: `.letra/specs/${dir.name}/spec.md`,
|
|
330
|
-
before,
|
|
331
|
-
after: newContent
|
|
332
|
-
}
|
|
333
|
-
],
|
|
334
|
-
snapshotId: ""
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
});
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
return results;
|
|
342
|
-
}
|
|
343
|
-
};
|
|
344
|
-
|
|
345
|
-
// src/diagnostics/detectors/missing-dir.ts
|
|
346
|
-
import { existsSync as existsSync5, mkdirSync as mkdirSync3 } from "fs";
|
|
347
|
-
import { join as join5 } from "path";
|
|
348
|
-
var REQUIRED_DIRS = [
|
|
349
|
-
{
|
|
350
|
-
path: ".letra/templates",
|
|
351
|
-
spec: "spec-templates-domain",
|
|
352
|
-
description: "templates customizados de specs"
|
|
353
|
-
},
|
|
354
|
-
{ path: ".letra/brand", spec: "flow-serve", description: "logos SVG do Letra" }
|
|
355
|
-
];
|
|
356
|
-
var missingDirDetector = {
|
|
357
|
-
name: "missing-dir",
|
|
358
|
-
async run(rootDir) {
|
|
359
|
-
const results = [];
|
|
360
|
-
for (const required of REQUIRED_DIRS) {
|
|
361
|
-
const dirPath = join5(rootDir, required.path);
|
|
362
|
-
if (existsSync5(dirPath)) continue;
|
|
363
|
-
results.push({
|
|
364
|
-
id: `missing-dir_${required.path.replace(/[/.]/g, "-")}`,
|
|
365
|
-
type: "info",
|
|
366
|
-
title: `Diret\xF3rio ausente: ${required.path}/`,
|
|
367
|
-
description: `O diret\xF3rio ${required.path}/ \xE9 referenciado pelo spec ${required.spec} (${required.description}), mas n\xE3o existe.`,
|
|
368
|
-
certainty: 1,
|
|
369
|
-
detector: "missing-dir",
|
|
370
|
-
autoFix: async () => ({
|
|
371
|
-
files: [],
|
|
372
|
-
snapshotId: ""
|
|
373
|
-
})
|
|
374
|
-
});
|
|
375
|
-
}
|
|
376
|
-
for (const r of results) {
|
|
377
|
-
const originalAutoFix = r.autoFix;
|
|
378
|
-
if (!originalAutoFix) continue;
|
|
379
|
-
r.autoFix = async () => {
|
|
380
|
-
const dirs = [];
|
|
381
|
-
for (const required of REQUIRED_DIRS) {
|
|
382
|
-
const dirPath = join5(rootDir, required.path);
|
|
383
|
-
if (existsSync5(dirPath)) continue;
|
|
384
|
-
mkdirSync3(dirPath, { recursive: true });
|
|
385
|
-
dirs.push(required.path);
|
|
386
|
-
}
|
|
387
|
-
return {
|
|
388
|
-
files: [],
|
|
389
|
-
snapshotId: ""
|
|
390
|
-
};
|
|
391
|
-
};
|
|
392
|
-
}
|
|
393
|
-
return results;
|
|
394
|
-
}
|
|
395
|
-
};
|
|
396
|
-
|
|
397
|
-
// src/diagnostics/detectors/stage-drift.ts
|
|
398
|
-
import { readFileSync as readFileSync5, existsSync as existsSync6 } from "fs";
|
|
399
|
-
import { join as join6 } from "path";
|
|
400
|
-
var STALE_AC_PATTERN2 = /-\s\[ \]\s\*\*`([^`]+)`\*\*/g;
|
|
401
|
-
var DONE_AC_PATTERN = /-\s\[x\]\s\*\*`([^`]+)`\*\*/g;
|
|
402
|
-
var stageDriftDetector = {
|
|
403
|
-
name: "stage-drift",
|
|
404
|
-
async run(rootDir) {
|
|
405
|
-
const results = [];
|
|
406
|
-
const workflowFile = join6(rootDir, ".letra", "workflow.json");
|
|
407
|
-
if (!existsSync6(workflowFile)) return results;
|
|
408
|
-
const workflow = JSON.parse(readFileSync5(workflowFile, "utf-8"));
|
|
409
|
-
const items = workflow.items || [];
|
|
410
|
-
const stages = workflow.stages || [];
|
|
411
|
-
const doneStageIds = stages.filter((s) => s.zone === "done").map((s) => s.id);
|
|
412
|
-
const reviewStageIds = stages.filter(
|
|
413
|
-
(s) => s.name?.toLowerCase() === "review" || s.id === "review"
|
|
414
|
-
).map((s) => s.id);
|
|
415
|
-
for (const item of items) {
|
|
416
|
-
if (!item.spec) continue;
|
|
417
|
-
const specDir = join6(rootDir, ".letra", "specs", item.spec);
|
|
418
|
-
const specFile = join6(specDir, "spec.md");
|
|
419
|
-
if (!existsSync6(specFile)) continue;
|
|
420
|
-
const content = readFileSync5(specFile, "utf-8");
|
|
421
|
-
const staleMatches = [...content.matchAll(STALE_AC_PATTERN2)];
|
|
422
|
-
const doneMatches = [...content.matchAll(DONE_AC_PATTERN)];
|
|
423
|
-
const totalACs = staleMatches.length + doneMatches.length;
|
|
424
|
-
if (totalACs === 0) continue;
|
|
425
|
-
const pctDone = doneMatches.length / totalACs;
|
|
426
|
-
const isInReview = reviewStageIds.includes(item.stage);
|
|
427
|
-
const isInBacklog = item.stage === "backlog";
|
|
428
|
-
if (pctDone === 1 && (isInReview || isInBacklog)) {
|
|
429
|
-
results.push({
|
|
430
|
-
id: `stage-drift_${item.id}`,
|
|
431
|
-
type: "info",
|
|
432
|
-
title: `${item.id} (${item.description}) \u2014 100% ACs prontos`,
|
|
433
|
-
description: `O item ${item.id} (${item.description}) tem ${doneMatches.length}/${totalACs} ACs implementados. Est\xE1 em "${item.stage}" mas deveria estar em "done".`,
|
|
434
|
-
certainty: 0.85,
|
|
435
|
-
detector: "stage-drift",
|
|
436
|
-
autoFix: async () => {
|
|
437
|
-
const before = readFileSync5(workflowFile, "utf-8");
|
|
438
|
-
const newWorkflow = JSON.parse(before);
|
|
439
|
-
const target = newWorkflow.items.find(
|
|
440
|
-
(i) => i.id === item.id
|
|
441
|
-
);
|
|
442
|
-
if (target) {
|
|
443
|
-
target.stage = doneStageIds[0] || "done";
|
|
444
|
-
target.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
445
|
-
}
|
|
446
|
-
const after = JSON.stringify(newWorkflow, null, 2);
|
|
447
|
-
return {
|
|
448
|
-
files: [{ path: ".letra/workflow.json", before, after }],
|
|
449
|
-
snapshotId: ""
|
|
450
|
-
};
|
|
451
|
-
}
|
|
452
|
-
});
|
|
453
|
-
} else if (pctDone > 0 && pctDone < 1 && isInBacklog) {
|
|
454
|
-
results.push({
|
|
455
|
-
id: `stage-drift_${item.id}_partial`,
|
|
456
|
-
type: "info",
|
|
457
|
-
title: `${item.id} (${item.description}) \u2014 ${doneMatches.length}/${totalACs} ACs prontos`,
|
|
458
|
-
description: `O item ${item.id} tem ${doneMatches.length}/${totalACs} ACs implementados mas est\xE1 em backlog. Considere mover para "code".`,
|
|
459
|
-
certainty: 0.7,
|
|
460
|
-
detector: "stage-drift"
|
|
461
|
-
});
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
return results;
|
|
465
|
-
}
|
|
466
|
-
};
|
|
467
|
-
|
|
468
|
-
// src/diagnostics/detectors/harness-stale.ts
|
|
469
|
-
import { existsSync as existsSync7, readFileSync as readFileSync6 } from "fs";
|
|
470
|
-
import { join as join7 } from "path";
|
|
471
|
-
var ADAPTER_FILES = {
|
|
472
|
-
cursor: { path: ".cursorrules", format: "at" },
|
|
473
|
-
"claude-code": { path: "CLAUDE.md", format: "text" },
|
|
474
|
-
windsurf: { path: ".windsurfrules", format: "at" },
|
|
475
|
-
vscode: { path: ".github/copilot-instructions.md", format: "text" },
|
|
476
|
-
opencode: { path: "AGENTS.md", format: "text" },
|
|
477
|
-
hermes: { path: ".hermes/instructions.md", format: "text" }
|
|
478
|
-
};
|
|
479
|
-
var harnessStaleDetector = {
|
|
480
|
-
name: "harness-stale",
|
|
481
|
-
async run(rootDir) {
|
|
482
|
-
const results = [];
|
|
483
|
-
const workflowFile = join7(rootDir, ".letra", "workflow.json");
|
|
484
|
-
let tools = ["cursor", "opencode", "vscode"];
|
|
485
|
-
let workflow;
|
|
486
|
-
if (existsSync7(workflowFile)) {
|
|
487
|
-
try {
|
|
488
|
-
const wf = JSON.parse(readFileSync6(workflowFile, "utf-8"));
|
|
489
|
-
if (Array.isArray(wf.tools)) {
|
|
490
|
-
tools = wf.tools;
|
|
491
|
-
}
|
|
492
|
-
workflow = wf;
|
|
493
|
-
} catch {
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
const staleTools = [];
|
|
497
|
-
for (const tool of tools) {
|
|
498
|
-
const info = ADAPTER_FILES[tool];
|
|
499
|
-
if (!info) continue;
|
|
500
|
-
const filePath = join7(rootDir, info.path);
|
|
501
|
-
if (!existsSync7(filePath)) continue;
|
|
502
|
-
const content = readFileSync6(filePath, "utf-8");
|
|
503
|
-
let isStale = false;
|
|
504
|
-
if (info.format === "at") {
|
|
505
|
-
if (!content.includes("@.letra/context.md") || !content.includes("@.letra/constitution.md")) {
|
|
506
|
-
isStale = true;
|
|
507
|
-
}
|
|
508
|
-
} else {
|
|
509
|
-
if (!content.includes(".letra/context.md") || !content.includes(".letra/constitution.md")) {
|
|
510
|
-
isStale = true;
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
if (isStale) staleTools.push(tool);
|
|
514
|
-
}
|
|
515
|
-
if (staleTools.length > 0) {
|
|
516
|
-
const doneStageIds = new Set(
|
|
517
|
-
(workflow?.stages || []).filter((s) => s.id === "done" || s.zone === "done").map((s) => s.id)
|
|
518
|
-
);
|
|
519
|
-
const backlogStageIds = new Set(
|
|
520
|
-
(workflow?.stages || []).filter((s) => s.id === "backlog" || s.zone === "todo").map((s) => s.id)
|
|
521
|
-
);
|
|
522
|
-
let activeStageId;
|
|
523
|
-
let primaryItemId;
|
|
524
|
-
if (workflow) {
|
|
525
|
-
const activeItem = workflow.items.find(
|
|
526
|
-
(i) => !doneStageIds.has(i.stage) && !backlogStageIds.has(i.stage)
|
|
527
|
-
);
|
|
528
|
-
if (activeItem) {
|
|
529
|
-
activeStageId = activeItem.stage;
|
|
530
|
-
primaryItemId = activeItem.id;
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
results.push({
|
|
534
|
-
id: "harness-stale_all",
|
|
535
|
-
type: "info",
|
|
536
|
-
title: `Adaptadores desatualizados: ${staleTools.join(", ")}`,
|
|
537
|
-
description: `Regenerando ${staleTools.length} adaptador(es) sem refer\xEAncias L1.`,
|
|
538
|
-
certainty: 1,
|
|
539
|
-
detector: "harness-stale",
|
|
540
|
-
autoFix: async () => {
|
|
541
|
-
const files = [];
|
|
542
|
-
for (const tool of staleTools) {
|
|
543
|
-
const info = ADAPTER_FILES[tool];
|
|
544
|
-
if (!info) continue;
|
|
545
|
-
const fp = join7(rootDir, info.path);
|
|
546
|
-
if (existsSync7(fp)) {
|
|
547
|
-
files.push({
|
|
548
|
-
path: info.path.replace(/\\/g, "/"),
|
|
549
|
-
before: readFileSync6(fp, "utf-8"),
|
|
550
|
-
after: ""
|
|
551
|
-
});
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
const { generateAdapters: generateAdapters2 } = await import("./generate-BF5R5GGA.js");
|
|
555
|
-
generateAdapters2(rootDir, tools, {
|
|
556
|
-
source: "flow-move",
|
|
557
|
-
workflow,
|
|
558
|
-
activeStageId,
|
|
559
|
-
primaryItemId,
|
|
560
|
-
quiet: true,
|
|
561
|
-
verb: "Updated"
|
|
562
|
-
});
|
|
563
|
-
for (const file of files) {
|
|
564
|
-
file.after = readFileSync6(join7(rootDir, file.path), "utf-8");
|
|
565
|
-
}
|
|
566
|
-
return { files, snapshotId: "" };
|
|
567
|
-
}
|
|
568
|
-
});
|
|
569
|
-
}
|
|
570
|
-
return results;
|
|
571
|
-
}
|
|
572
|
-
};
|
|
573
|
-
|
|
574
|
-
// src/diagnostics/detectors/ac-false-pos.ts
|
|
575
|
-
import { readFileSync as readFileSync7, existsSync as existsSync8, readdirSync as readdirSync4 } from "fs";
|
|
576
|
-
import { join as join8 } from "path";
|
|
577
|
-
var DONE_AC_PATTERN2 = /-\s\[x\]\s\*\*`([^`]+)`\*\*/g;
|
|
578
|
-
var acFalsePosDetector = {
|
|
579
|
-
name: "ac-false-pos",
|
|
580
|
-
async run(rootDir) {
|
|
581
|
-
const results = [];
|
|
582
|
-
const specsDir = join8(rootDir, ".letra", "specs");
|
|
583
|
-
if (!existsSync8(specsDir)) return results;
|
|
584
|
-
const specDirs = readdirSync4(specsDir, { withFileTypes: true }).filter(
|
|
585
|
-
(d) => d.isDirectory() && !d.name.startsWith("_")
|
|
586
|
-
);
|
|
587
|
-
for (const dir of specDirs) {
|
|
588
|
-
const specFile = join8(specsDir, dir.name, "spec.md");
|
|
589
|
-
if (!existsSync8(specFile)) continue;
|
|
590
|
-
const content = readFileSync7(specFile, "utf-8");
|
|
591
|
-
const matches = [...content.matchAll(DONE_AC_PATTERN2)];
|
|
592
|
-
for (const match of matches) {
|
|
593
|
-
const command = match[1].trim();
|
|
594
|
-
if (!command) continue;
|
|
595
|
-
const commandWords = command.split(/\s+/);
|
|
596
|
-
const camelCaseName = commandWords.map((w, i) => i === 0 ? w : w.charAt(0).toUpperCase() + w.slice(1)).join("");
|
|
597
|
-
const pascalCaseName = commandWords.map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join("");
|
|
598
|
-
const foundInSource = searchInSource(rootDir, [
|
|
599
|
-
command,
|
|
600
|
-
camelCaseName,
|
|
601
|
-
pascalCaseName
|
|
602
|
-
]);
|
|
603
|
-
if (!foundInSource) {
|
|
604
|
-
results.push({
|
|
605
|
-
id: `ac-false-pos_${dir.name}_${command.replace(/\s+/g, "-")}`,
|
|
606
|
-
type: "warning",
|
|
607
|
-
title: `AC "${command}" marcado [x] mas n\xE3o encontrado no c\xF3digo`,
|
|
608
|
-
description: `O acceptance criteria "${command}" do spec ${dir.name} est\xE1 marcado como feito ([x]), mas o c\xF3digo-fonte n\xE3o cont\xE9m implementa\xE7\xE3o correspondente. Pode ser um falso positivo.`,
|
|
609
|
-
certainty: 0.7,
|
|
610
|
-
detector: "ac-false-pos"
|
|
611
|
-
});
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
return results;
|
|
616
|
-
}
|
|
617
|
-
};
|
|
618
|
-
|
|
619
|
-
// src/diagnostics/detectors/missing-spec-link.ts
|
|
620
|
-
import { existsSync as existsSync9, readFileSync as readFileSync8, readdirSync as readdirSync5 } from "fs";
|
|
621
|
-
import { join as join9 } from "path";
|
|
622
|
-
var missingSpecLinkDetector = {
|
|
623
|
-
name: "missing-spec-link",
|
|
624
|
-
async run(rootDir) {
|
|
625
|
-
const results = [];
|
|
626
|
-
const workflowFile = join9(rootDir, ".letra", "workflow.json");
|
|
627
|
-
if (!existsSync9(workflowFile)) return results;
|
|
628
|
-
const workflow = JSON.parse(readFileSync8(workflowFile, "utf-8"));
|
|
629
|
-
const items = workflow.items || [];
|
|
630
|
-
const stages = workflow.stages || [];
|
|
631
|
-
const specLinks = workflow.specLinks || {};
|
|
632
|
-
const backlogStageIds = new Set(
|
|
633
|
-
stages.filter((s) => s.zone === "todo" || s.id === "backlog").map((s) => s.id)
|
|
634
|
-
);
|
|
635
|
-
for (const item of items) {
|
|
636
|
-
if (backlogStageIds.has(item.stage)) continue;
|
|
637
|
-
if (!item.spec) {
|
|
638
|
-
results.push({
|
|
639
|
-
id: `missing-spec-link_${item.id}`,
|
|
640
|
-
type: "info",
|
|
641
|
-
title: `${item.id}: sem spec linkada`,
|
|
642
|
-
description: `O item ${item.id} (${item.description}) est\xE1 em "${item.stage}" mas n\xE3o tem spec associada. Link usando: letra flow edit ${item.id} --spec <nome>`,
|
|
643
|
-
certainty: 0.9,
|
|
644
|
-
detector: "missing-spec-link",
|
|
645
|
-
autoFix: async () => {
|
|
646
|
-
const kebab = item.description.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
647
|
-
const specsDir = join9(rootDir, ".letra", "specs");
|
|
648
|
-
if (!existsSync9(specsDir)) return { files: [], snapshotId: "no-op" };
|
|
649
|
-
const specDirs = readdirSync5(specsDir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name);
|
|
650
|
-
const exact = specDirs.find((d) => d === kebab);
|
|
651
|
-
if (exact) {
|
|
652
|
-
const before = readFileSync8(workflowFile, "utf-8");
|
|
653
|
-
const wf = JSON.parse(before);
|
|
654
|
-
const target = wf.items.find((i) => i.id === item.id);
|
|
655
|
-
if (target) {
|
|
656
|
-
target.spec = exact;
|
|
657
|
-
if (!wf.specLinks) wf.specLinks = {};
|
|
658
|
-
wf.specLinks[exact] = { path: `.letra/specs/${exact}/spec.md` };
|
|
659
|
-
wf.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
660
|
-
return {
|
|
661
|
-
files: [{ path: ".letra/workflow.json", before, after: JSON.stringify(wf, null, 2) }],
|
|
662
|
-
snapshotId: "auto-fix"
|
|
663
|
-
};
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
const partial = specDirs.find((d) => kebab.includes(d) || d.includes(kebab));
|
|
667
|
-
if (partial) {
|
|
668
|
-
const before = readFileSync8(workflowFile, "utf-8");
|
|
669
|
-
const wf = JSON.parse(before);
|
|
670
|
-
const target = wf.items.find((i) => i.id === item.id);
|
|
671
|
-
if (target) {
|
|
672
|
-
target.spec = partial;
|
|
673
|
-
if (!wf.specLinks) wf.specLinks = {};
|
|
674
|
-
wf.specLinks[partial] = { path: `.letra/specs/${partial}/spec.md` };
|
|
675
|
-
wf.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
676
|
-
return {
|
|
677
|
-
files: [{ path: ".letra/workflow.json", before, after: JSON.stringify(wf, null, 2) }],
|
|
678
|
-
snapshotId: "auto-fix"
|
|
679
|
-
};
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
return { files: [], snapshotId: "no-op" };
|
|
683
|
-
}
|
|
684
|
-
});
|
|
685
|
-
continue;
|
|
686
|
-
}
|
|
687
|
-
const specPath = join9(rootDir, ".letra", "specs", item.spec, "spec.md");
|
|
688
|
-
if (!existsSync9(specPath)) {
|
|
689
|
-
results.push({
|
|
690
|
-
id: `missing-spec-link_${item.id}_notfound`,
|
|
691
|
-
type: "warning",
|
|
692
|
-
title: `${item.id}: spec linkada n\xE3o encontrada em disco`,
|
|
693
|
-
description: `Item ${item.id} referencia spec "${item.spec}" mas ${specPath} n\xE3o existe.`,
|
|
694
|
-
certainty: 0.9,
|
|
695
|
-
detector: "missing-spec-link"
|
|
696
|
-
});
|
|
697
|
-
continue;
|
|
698
|
-
}
|
|
699
|
-
if (!specLinks[item.spec]) {
|
|
700
|
-
results.push({
|
|
701
|
-
id: `missing-spec-link_${item.id}_unregistered`,
|
|
702
|
-
type: "info",
|
|
703
|
-
title: `${item.id}: spec n\xE3o registrada em specLinks`,
|
|
704
|
-
description: `Item ${item.id} tem spec="${item.spec}" mas specLinks n\xE3o cont\xE9m entrada para "${item.spec}".`,
|
|
705
|
-
certainty: 0.7,
|
|
706
|
-
detector: "missing-spec-link"
|
|
707
|
-
});
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
return results;
|
|
711
|
-
}
|
|
712
|
-
};
|
|
713
|
-
|
|
714
|
-
// src/diagnostics/engine.ts
|
|
715
|
-
var DiagnosticEngine = class {
|
|
716
|
-
rootDir;
|
|
717
|
-
snapshots;
|
|
718
|
-
detectors = [
|
|
719
|
-
acStaleDetector,
|
|
720
|
-
acFalsePosDetector,
|
|
721
|
-
missingDirDetector,
|
|
722
|
-
stageDriftDetector,
|
|
723
|
-
harnessStaleDetector,
|
|
724
|
-
missingSpecLinkDetector
|
|
725
|
-
];
|
|
726
|
-
lastOutput = {
|
|
727
|
-
fixes: [],
|
|
728
|
-
suggestions: [],
|
|
729
|
-
errors: []
|
|
730
|
-
};
|
|
731
|
-
lastResults = [];
|
|
732
|
-
appliedFixes = /* @__PURE__ */ new Set();
|
|
733
|
-
constructor(rootDir) {
|
|
734
|
-
this.rootDir = rootDir;
|
|
735
|
-
this.snapshots = new SnapshotStore(rootDir);
|
|
736
|
-
}
|
|
737
|
-
getLastResults() {
|
|
738
|
-
return [...this.lastResults];
|
|
739
|
-
}
|
|
740
|
-
async runAll() {
|
|
741
|
-
const output = { fixes: [], suggestions: [], errors: [] };
|
|
742
|
-
const newApplied = /* @__PURE__ */ new Set();
|
|
743
|
-
const allResults = [];
|
|
744
|
-
for (const detector of this.detectors) {
|
|
745
|
-
try {
|
|
746
|
-
const results = await detector.run(this.rootDir);
|
|
747
|
-
allResults.push(...results);
|
|
748
|
-
for (const result of results) {
|
|
749
|
-
if (result.autoFix && result.certainty >= 0.9) {
|
|
750
|
-
if (this.appliedFixes.has(result.id)) {
|
|
751
|
-
continue;
|
|
752
|
-
}
|
|
753
|
-
try {
|
|
754
|
-
const fix = await result.autoFix();
|
|
755
|
-
if (fix.files.length === 0) continue;
|
|
756
|
-
const snapshotId = await this.snapshots.save(
|
|
757
|
-
result.id,
|
|
758
|
-
result.title,
|
|
759
|
-
fix.files
|
|
760
|
-
);
|
|
761
|
-
for (const file of fix.files) {
|
|
762
|
-
const absPath = join10(this.rootDir, file.path);
|
|
763
|
-
if (file.path === ".letra/workflow.json") {
|
|
764
|
-
const workflow = JSON.parse(file.after);
|
|
765
|
-
writeWorkflow(this.rootDir, { workflow, source: "stage-drift", skipSitrep: true, quiet: true, skipEngine: true });
|
|
766
|
-
} else {
|
|
767
|
-
writeFileSync4(absPath, file.after, "utf-8");
|
|
768
|
-
}
|
|
769
|
-
}
|
|
770
|
-
newApplied.add(result.id);
|
|
771
|
-
if (snapshotId) {
|
|
772
|
-
output.fixes.push({
|
|
773
|
-
id: result.id,
|
|
774
|
-
title: result.title,
|
|
775
|
-
description: result.description,
|
|
776
|
-
snapshotId
|
|
777
|
-
});
|
|
778
|
-
}
|
|
779
|
-
} catch (fixError) {
|
|
780
|
-
output.errors.push(
|
|
781
|
-
`Auto-fix falhou para ${result.id}: ${fixError}`
|
|
782
|
-
);
|
|
783
|
-
}
|
|
784
|
-
} else {
|
|
785
|
-
output.suggestions.push({
|
|
786
|
-
id: result.id,
|
|
787
|
-
title: result.title,
|
|
788
|
-
description: result.description,
|
|
789
|
-
type: result.type,
|
|
790
|
-
detector: result.detector
|
|
791
|
-
});
|
|
792
|
-
}
|
|
793
|
-
}
|
|
794
|
-
} catch (detError) {
|
|
795
|
-
output.errors.push(`Detector ${detector.name} falhou: ${detError}`);
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
this.appliedFixes = newApplied;
|
|
799
|
-
this.lastOutput = output;
|
|
800
|
-
this.lastResults = allResults;
|
|
801
|
-
return output;
|
|
802
|
-
}
|
|
803
|
-
getLastOutput() {
|
|
804
|
-
return this.lastOutput;
|
|
805
|
-
}
|
|
806
|
-
async undo(snapshotId) {
|
|
807
|
-
return this.snapshots.restore(snapshotId);
|
|
808
|
-
}
|
|
809
|
-
async redo(snapshotId) {
|
|
810
|
-
return this.snapshots.redo(snapshotId);
|
|
811
|
-
}
|
|
812
|
-
listSnapshots() {
|
|
813
|
-
return this.snapshots.list();
|
|
814
|
-
}
|
|
815
|
-
ensureDirs() {
|
|
816
|
-
const requiredDirs = [
|
|
817
|
-
".letra/templates",
|
|
818
|
-
".letra/brand",
|
|
819
|
-
".letra/snapshots"
|
|
820
|
-
];
|
|
821
|
-
for (const dir of requiredDirs) {
|
|
822
|
-
const fullPath = join10(this.rootDir, dir);
|
|
823
|
-
if (!existsSync10(fullPath)) {
|
|
824
|
-
try {
|
|
825
|
-
const { mkdirSync: mkdirSync5 } = __require("fs");
|
|
826
|
-
mkdirSync5(fullPath, { recursive: true });
|
|
827
|
-
} catch {
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
|
-
};
|
|
833
|
-
|
|
834
|
-
// src/commands/flow-init.ts
|
|
835
|
-
function askText(query, defaultValue) {
|
|
836
|
-
if (!process.stdin.isTTY) return Promise.resolve(defaultValue);
|
|
837
|
-
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
838
|
-
return new Promise((resolve3) => {
|
|
839
|
-
const formatted = `${chalk.cyan(query)} ${chalk.gray(`(default: ${defaultValue})`)}
|
|
840
|
-
> `;
|
|
841
|
-
rl.question(formatted, (answer) => {
|
|
842
|
-
rl.close();
|
|
843
|
-
resolve3(answer.trim() || defaultValue);
|
|
844
|
-
});
|
|
845
|
-
});
|
|
846
|
-
}
|
|
847
|
-
function detectExistingTools(root) {
|
|
848
|
-
const tools = [];
|
|
849
|
-
if (existsSync11(join11(root, ".cursorrules"))) tools.push("cursor");
|
|
850
|
-
if (existsSync11(join11(root, "CLAUDE.md"))) tools.push("claude-code");
|
|
851
|
-
if (existsSync11(join11(root, ".windsurfrules"))) tools.push("windsurf");
|
|
852
|
-
if (existsSync11(join11(root, "AGENTS.md"))) tools.push("opencode");
|
|
853
|
-
if (existsSync11(join11(root, ".github", "copilot-instructions.md"))) tools.push("vscode");
|
|
854
|
-
if (existsSync11(join11(root, ".hermes", "instructions.md"))) tools.push("hermes");
|
|
855
|
-
return tools;
|
|
856
|
-
}
|
|
857
|
-
function detectProjectName(root) {
|
|
858
|
-
const pkgPath = join11(root, "package.json");
|
|
859
|
-
if (existsSync11(pkgPath)) {
|
|
860
|
-
try {
|
|
861
|
-
const pkg = JSON.parse(readFileSync9(pkgPath, "utf-8"));
|
|
862
|
-
if (pkg.name) return pkg.name.replace(/^@[^/]+\//, "");
|
|
863
|
-
} catch {
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
return resolve(root).split(/[\\/]/).pop() || "meu-projeto";
|
|
867
|
-
}
|
|
868
|
-
function stagesFromInput(input) {
|
|
869
|
-
return input.split(",").map((s, i) => {
|
|
870
|
-
const trimmed = s.trim();
|
|
871
|
-
if (!trimmed) return null;
|
|
872
|
-
return {
|
|
873
|
-
id: trimmed.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, ""),
|
|
874
|
-
name: trimmed.charAt(0).toUpperCase() + trimmed.slice(1),
|
|
875
|
-
order: i
|
|
876
|
-
};
|
|
877
|
-
}).filter((s) => s !== null);
|
|
878
|
-
}
|
|
879
|
-
function now() {
|
|
880
|
-
return (/* @__PURE__ */ new Date()).toISOString();
|
|
881
|
-
}
|
|
882
|
-
function workflowFilePath(root) {
|
|
883
|
-
return join11(root, ".letra", "workflow.json");
|
|
884
|
-
}
|
|
885
|
-
function loadWorkflow(root) {
|
|
886
|
-
const filePath = workflowFilePath(root);
|
|
887
|
-
if (!existsSync11(filePath)) return null;
|
|
888
|
-
try {
|
|
889
|
-
return JSON.parse(readFileSync9(filePath, "utf-8"));
|
|
890
|
-
} catch {
|
|
891
|
-
return null;
|
|
892
|
-
}
|
|
893
|
-
}
|
|
894
|
-
function saveWorkflow(root, workflow) {
|
|
895
|
-
const dir = join11(root, ".letra");
|
|
896
|
-
if (!existsSync11(dir)) mkdirSync4(dir, { recursive: true });
|
|
897
|
-
const filePath = workflowFilePath(root);
|
|
898
|
-
if (existsSync11(filePath)) {
|
|
899
|
-
const backupDir = join11(root, ".letra", "backups");
|
|
900
|
-
if (!existsSync11(backupDir)) mkdirSync4(backupDir, { recursive: true });
|
|
901
|
-
const ts = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
902
|
-
const backupPath = join11(backupDir, `workflow-${ts}.json`);
|
|
903
|
-
try {
|
|
904
|
-
const existing = readFileSync9(filePath, "utf-8");
|
|
905
|
-
writeFileSync5(backupPath, existing, "utf-8");
|
|
906
|
-
} catch {
|
|
907
|
-
}
|
|
908
|
-
}
|
|
909
|
-
writeFileSync5(filePath, JSON.stringify(workflow, null, 2));
|
|
910
|
-
}
|
|
911
|
-
var ADAPTER_TARGETS = {
|
|
912
|
-
cursor: ".cursorrules",
|
|
913
|
-
opencode: "AGENTS.md",
|
|
914
|
-
vscode: ".github/copilot-instructions.md",
|
|
915
|
-
"claude-code": "CLAUDE.md",
|
|
916
|
-
windsurf: ".windsurfrules",
|
|
917
|
-
hermes: ".hermes/instructions.md"
|
|
918
|
-
};
|
|
919
|
-
async function writeWorkflow(root, options) {
|
|
920
|
-
const { workflow, source, primaryItemId, skipAdapters, skipSitrep, skipLog, skipEngine, quiet } = options;
|
|
921
|
-
if (!workflow.items || !Array.isArray(workflow.items)) {
|
|
922
|
-
return { ok: false, filesUpdated: [], error: "workflow.items must be an array" };
|
|
923
|
-
}
|
|
924
|
-
if (!workflow.stages || !Array.isArray(workflow.stages)) {
|
|
925
|
-
return { ok: false, filesUpdated: [], error: "workflow.stages must be an array" };
|
|
926
|
-
}
|
|
927
|
-
const filesUpdated = [];
|
|
928
|
-
let graveIssueCount = 0;
|
|
929
|
-
saveWorkflow(root, workflow);
|
|
930
|
-
filesUpdated.push(".letra/workflow.json");
|
|
931
|
-
if (!skipEngine) {
|
|
932
|
-
try {
|
|
933
|
-
const engine = new DiagnosticEngine(root);
|
|
934
|
-
const diagOutput = await engine.runAll();
|
|
935
|
-
const rawResults = engine.getLastResults();
|
|
936
|
-
const healthRecord = loadHealthRecord(root);
|
|
937
|
-
mergeScanResults(healthRecord, rawResults);
|
|
938
|
-
saveHealthRecord(root, healthRecord);
|
|
939
|
-
graveIssueCount = diagOutput.suggestions.filter((s) => s.type === "error").length;
|
|
940
|
-
if (diagOutput.errors.length > 0) {
|
|
941
|
-
graveIssueCount += diagOutput.errors.length;
|
|
942
|
-
}
|
|
943
|
-
if (!quiet) {
|
|
944
|
-
const totalIssues = diagOutput.fixes.length + diagOutput.suggestions.length;
|
|
945
|
-
if (totalIssues > 0) {
|
|
946
|
-
console.log(chalk.gray(` Diagn\xF3stico: ${totalIssues} issue(s), ${diagOutput.fixes.length} auto-corrigido(s)`));
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
} catch (e) {
|
|
950
|
-
if (!quiet) {
|
|
951
|
-
console.log(chalk.yellow(` Diagn\xF3stico ignorado: ${e}`));
|
|
952
|
-
}
|
|
953
|
-
}
|
|
954
|
-
}
|
|
955
|
-
if (!skipAdapters && workflow.tools && workflow.tools.length > 0) {
|
|
956
|
-
const activeStage = primaryItemId ? workflow.items.find((i) => i.id === primaryItemId)?.stage : workflow.items[0]?.stage;
|
|
957
|
-
generateAdapters(root, workflow.tools, {
|
|
958
|
-
source: "flow-move",
|
|
959
|
-
workflow: {
|
|
960
|
-
name: workflow.name,
|
|
961
|
-
stages: workflow.stages,
|
|
962
|
-
items: workflow.items
|
|
963
|
-
},
|
|
964
|
-
activeStageId: activeStage || workflow.stages[0]?.id || "backlog",
|
|
965
|
-
primaryItemId: primaryItemId || workflow.items[0]?.id,
|
|
966
|
-
graveIssueCount: graveIssueCount > 0 ? graveIssueCount : void 0
|
|
967
|
-
});
|
|
968
|
-
for (const tool of workflow.tools) {
|
|
969
|
-
const target = ADAPTER_TARGETS[tool];
|
|
970
|
-
if (target) filesUpdated.push(target);
|
|
971
|
-
}
|
|
972
|
-
}
|
|
973
|
-
if (!skipSitrep) {
|
|
974
|
-
try {
|
|
975
|
-
const { sitrep: sitrep2 } = await import("./sitrep-SI6ZFIAM.js");
|
|
976
|
-
await sitrep2(root, { quiet: true, skipLog: true });
|
|
977
|
-
} catch {
|
|
978
|
-
}
|
|
979
|
-
}
|
|
980
|
-
if (!skipLog) {
|
|
981
|
-
try {
|
|
982
|
-
logEntry(root, "system", `workflow_updated via ${source}`);
|
|
983
|
-
} catch {
|
|
984
|
-
}
|
|
985
|
-
}
|
|
986
|
-
return { ok: true, filesUpdated };
|
|
987
|
-
}
|
|
988
|
-
async function flowInit(root, options) {
|
|
989
|
-
if (!process.stdin.isTTY && !options?.quick) {
|
|
990
|
-
console.log(chalk.yellow("Non-TTY: usando defaults. Passe --quick para confirmar."));
|
|
991
|
-
return flowInitQuick(root);
|
|
992
|
-
}
|
|
993
|
-
if (options?.quick) {
|
|
994
|
-
return flowInitQuick(root);
|
|
995
|
-
}
|
|
996
|
-
const name = await askText("Workflow name?", detectProjectName(root));
|
|
997
|
-
const stagesInput = await askText(
|
|
998
|
-
"Stages (comma-separated)?",
|
|
999
|
-
"backlog, design, code, review, done"
|
|
1000
|
-
);
|
|
1001
|
-
const stages = stagesFromInput(stagesInput);
|
|
1002
|
-
const detected = detectExistingTools(root);
|
|
1003
|
-
const defaultTools = detected.length > 0 ? detected.join(", ") : "cursor, opencode";
|
|
1004
|
-
const toolsInput = await askText("Tools (comma-separated)?", defaultTools);
|
|
1005
|
-
const tools = toolsInput.split(",").map((s) => s.trim().toLowerCase()).filter(Boolean);
|
|
1006
|
-
const workflow = {
|
|
1007
|
-
version: "1.0",
|
|
1008
|
-
name,
|
|
1009
|
-
createdAt: now(),
|
|
1010
|
-
updatedAt: now(),
|
|
1011
|
-
stages,
|
|
1012
|
-
items: [],
|
|
1013
|
-
tools
|
|
1014
|
-
};
|
|
1015
|
-
return workflow;
|
|
1016
|
-
}
|
|
1017
|
-
async function flowInitQuick(root) {
|
|
1018
|
-
const defaultName = detectProjectName(root);
|
|
1019
|
-
const defaultStagesList = "backlog, design, code, review, done";
|
|
1020
|
-
const detected = detectExistingTools(root);
|
|
1021
|
-
const defaultTools = detected.length > 0 ? detected.join(", ") : "cursor, opencode";
|
|
1022
|
-
const name = await askText("Workflow name?", defaultName);
|
|
1023
|
-
const stagesInput = await askText("Stages (comma-separated)?", defaultStagesList);
|
|
1024
|
-
const stages = stagesFromInput(stagesInput);
|
|
1025
|
-
const toolsInput = await askText("Tools (comma-separated)?", defaultTools);
|
|
1026
|
-
const tools = toolsInput.split(",").map((s) => s.trim().toLowerCase()).filter(Boolean);
|
|
1027
|
-
const workflow = {
|
|
1028
|
-
version: "1.0",
|
|
1029
|
-
name,
|
|
1030
|
-
createdAt: now(),
|
|
1031
|
-
updatedAt: now(),
|
|
1032
|
-
stages,
|
|
1033
|
-
items: [],
|
|
1034
|
-
tools
|
|
1035
|
-
};
|
|
1036
|
-
return workflow;
|
|
1037
|
-
}
|
|
1038
|
-
async function flowInitAction(targetPath, options) {
|
|
1039
|
-
const root = resolve(process.cwd(), targetPath || ".");
|
|
1040
|
-
const filePath = workflowFilePath(root);
|
|
1041
|
-
if (existsSync11(filePath)) {
|
|
1042
|
-
console.log(chalk.yellow("Workflow already exists at .letra/workflow.json"));
|
|
1043
|
-
return;
|
|
1044
|
-
}
|
|
1045
|
-
const spinner = ora("Setting up workflow...").start();
|
|
1046
|
-
try {
|
|
1047
|
-
spinner.stop();
|
|
1048
|
-
const workflow = await flowInit(root, options);
|
|
1049
|
-
spinner.start();
|
|
1050
|
-
writeWorkflow(root, { workflow, source: "flow-init", skipSitrep: true });
|
|
1051
|
-
spinner.succeed(chalk.green("Workflow created at .letra/workflow.json"));
|
|
1052
|
-
console.log("");
|
|
1053
|
-
console.log(` Name: ${chalk.cyan(workflow.name)}`);
|
|
1054
|
-
console.log(` Stages: ${chalk.cyan(workflow.stages.map((s) => s.name).join(" \u2192 "))}`);
|
|
1055
|
-
console.log(` Tools: ${chalk.cyan(workflow.tools.join(", "))}`);
|
|
1056
|
-
console.log("");
|
|
1057
|
-
console.log(" Next steps:");
|
|
1058
|
-
console.log(
|
|
1059
|
-
` ${chalk.cyan("letra flow backlog add <desc>")} Add items to your backlog`
|
|
1060
|
-
);
|
|
1061
|
-
console.log(` ${chalk.cyan("letra flow board")} View your board`);
|
|
1062
|
-
} catch (error) {
|
|
1063
|
-
spinner.fail(chalk.red("Failed to create workflow"));
|
|
1064
|
-
process.exit(1);
|
|
1065
|
-
}
|
|
1066
|
-
}
|
|
1067
|
-
|
|
1068
|
-
// src/commands/sitrep.ts
|
|
1069
|
-
var START_MARKER = "<!-- sitrep:start -->";
|
|
1070
|
-
var END_MARKER = "<!-- sitrep:end -->";
|
|
1071
|
-
function getRecentDecisions(root, max) {
|
|
1072
|
-
const dir = join12(root, ".letra", "decisions");
|
|
1073
|
-
if (!existsSync12(dir)) return [];
|
|
1074
|
-
try {
|
|
1075
|
-
const files = readdirSync6(dir).filter((f) => f.endsWith(".md")).map((f) => ({
|
|
1076
|
-
name: f,
|
|
1077
|
-
mtime: statSync2(join12(dir, f)).mtimeMs
|
|
1078
|
-
})).sort((a, b) => b.mtime - a.mtime).slice(0, max);
|
|
1079
|
-
return files.map((f) => ({
|
|
1080
|
-
title: f.name.replace(/\.md$/, "").replace(/-/g, " "),
|
|
1081
|
-
date: new Date(f.mtime).toLocaleDateString("pt-BR")
|
|
1082
|
-
}));
|
|
1083
|
-
} catch {
|
|
1084
|
-
return [];
|
|
1085
|
-
}
|
|
1086
|
-
}
|
|
1087
|
-
function countItemACs(root, specName) {
|
|
1088
|
-
const specDir = join12(root, ".letra", "specs", specName);
|
|
1089
|
-
const acceptanceFile = join12(specDir, "acceptance.md");
|
|
1090
|
-
const specFile = join12(specDir, "spec.md");
|
|
1091
|
-
const countInText = (text) => {
|
|
1092
|
-
const pending = (text.match(/-\s*\[ \]\s*\*\*(.+?)\*\*/g) || []).length;
|
|
1093
|
-
const done = (text.match(/-\s*\[[xX]\]\s*\*\*(.+?)\*\*/g) || []).length;
|
|
1094
|
-
return { pending, total: pending + done };
|
|
1095
|
-
};
|
|
1096
|
-
if (existsSync12(acceptanceFile)) {
|
|
1097
|
-
return countInText(readFileSync10(acceptanceFile, "utf-8"));
|
|
1098
|
-
}
|
|
1099
|
-
if (existsSync12(specFile)) {
|
|
1100
|
-
const content = readFileSync10(specFile, "utf-8");
|
|
1101
|
-
const match = content.match(/## Acceptance Criteria\s+([\s\S]*?)(?=\n## |\n*$)/);
|
|
1102
|
-
return match ? countInText(match[1]) : { pending: 0, total: 0 };
|
|
1103
|
-
}
|
|
1104
|
-
return { pending: 0, total: 0 };
|
|
1105
|
-
}
|
|
1106
|
-
function findCurrentItem(workflow) {
|
|
1107
|
-
const activeStages = workflow.stages.filter((s) => s.zone === "doing" || !s.zone && s.order > 0 && s.order < workflow.stages.length - 1).map((s) => s.id);
|
|
1108
|
-
const stageSet = new Set(activeStages);
|
|
1109
|
-
if (stageSet.size === 0) {
|
|
1110
|
-
const mid = Math.floor(workflow.stages.length / 2);
|
|
1111
|
-
const stage = workflow.stages[mid];
|
|
1112
|
-
if (stage) stageSet.add(stage.id);
|
|
1113
|
-
}
|
|
1114
|
-
const items = workflow.items.filter((i) => stageSet.has(i.stage));
|
|
1115
|
-
if (items.length === 0) return null;
|
|
1116
|
-
return items.reduce((a, b) => new Date(a.createdAt) > new Date(b.createdAt) ? a : b);
|
|
1117
|
-
}
|
|
1118
|
-
function getStageName(stageId, workflow) {
|
|
1119
|
-
if (!workflow) return stageId;
|
|
1120
|
-
return workflow.stages?.find((s) => s.id === stageId)?.name ?? stageId;
|
|
1121
|
-
}
|
|
1122
|
-
function extractSection(content, heading) {
|
|
1123
|
-
const esc = heading.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1124
|
-
const regex = new RegExp(`## ${esc}\\s+([\\s\\S]*?)(?=\\n## |\\n*$)`);
|
|
1125
|
-
const match = content.match(regex);
|
|
1126
|
-
return match ? match[1].trim() : null;
|
|
1127
|
-
}
|
|
1128
|
-
function buildSitrepBlock(data) {
|
|
1129
|
-
const lines = [];
|
|
1130
|
-
if (data.currentItem) {
|
|
1131
|
-
lines.push(`**Est\xE1gio**: ${getStageName(data.currentItem.stage, data.workflow)}`);
|
|
1132
|
-
const item = data.currentItem;
|
|
1133
|
-
let itemLine = `**Item atual**: ${item.id} \u2014 ${item.description}`;
|
|
1134
|
-
if (item.spec) itemLine += ` (spec: ${item.spec})`;
|
|
1135
|
-
lines.push(itemLine);
|
|
1136
|
-
if (data.acCounts) {
|
|
1137
|
-
const { pending, total } = data.acCounts;
|
|
1138
|
-
const done = total - pending;
|
|
1139
|
-
lines.push(`**ACs**: ${pending}/${total} pendentes | ${done} feito(s)`);
|
|
1140
|
-
}
|
|
1141
|
-
} else if (data.workflow) {
|
|
1142
|
-
lines.push("**Est\xE1gio**: sem item ativo");
|
|
1143
|
-
} else {
|
|
1144
|
-
lines.push("**Est\xE1gio**: sem workflow definido");
|
|
1145
|
-
}
|
|
1146
|
-
const s = data.alertSummary;
|
|
1147
|
-
const alertParts = [];
|
|
1148
|
-
if (s.novo > 0) alertParts.push(`${s.novo} novo(s)`);
|
|
1149
|
-
if (s.ciente > 0) alertParts.push(`${s.ciente} em acompanhamento`);
|
|
1150
|
-
if (s.resolvido > 0) alertParts.push(`${s.resolvido} resolvido(s)`);
|
|
1151
|
-
lines.push(`**Alertas**: ${alertParts.length > 0 ? alertParts.join(" \xB7 ") : "0 alertas"}`);
|
|
1152
|
-
if (s.alta > 0) {
|
|
1153
|
-
lines.push(`\u26A0 ${s.alta} alerta(s) de severidade alta`);
|
|
1154
|
-
}
|
|
1155
|
-
if (data.decisions.length > 0) {
|
|
1156
|
-
const decStr = data.decisions.map((d) => `"${d.title}" (${d.date})`).join(", ");
|
|
1157
|
-
lines.push(`**\xDAltimas decis\xF5es**: ${decStr}`);
|
|
1158
|
-
}
|
|
1159
|
-
return lines.join("\n");
|
|
1160
|
-
}
|
|
1161
|
-
function rewriteContextFile(content, dynamicBlock, stack, restricoes, porques) {
|
|
1162
|
-
const headerMatch = content.match(/^# Context[\s\S]*?(?=\n## )/);
|
|
1163
|
-
const header = headerMatch ? headerMatch[0].trim() : "# Context";
|
|
1164
|
-
const intent = extractSection(content, "Intent");
|
|
1165
|
-
const dominio = extractSection(content, "Dom\xEDnio");
|
|
1166
|
-
const ignoreIdx = content.indexOf("<!-- sitrep:ignore -->");
|
|
1167
|
-
let ignoredContent = "";
|
|
1168
|
-
if (ignoreIdx !== -1) {
|
|
1169
|
-
ignoredContent = content.slice(ignoreIdx);
|
|
1170
|
-
}
|
|
1171
|
-
const sections = [header];
|
|
1172
|
-
if (intent) {
|
|
1173
|
-
sections.push(`## Intent
|
|
1174
|
-
|
|
1175
|
-
${intent}`);
|
|
1176
|
-
}
|
|
1177
|
-
if (dominio) {
|
|
1178
|
-
sections.push(`## Dom\xEDnio
|
|
1179
|
-
|
|
1180
|
-
${dominio}`);
|
|
1181
|
-
}
|
|
1182
|
-
sections.push(`${START_MARKER}
|
|
1183
|
-
${dynamicBlock}
|
|
1184
|
-
${END_MARKER}`);
|
|
1185
|
-
if (stack) {
|
|
1186
|
-
sections.push(`## Stack
|
|
1187
|
-
|
|
1188
|
-
${stack}`);
|
|
1189
|
-
}
|
|
1190
|
-
if (restricoes) {
|
|
1191
|
-
sections.push(`## Restri\xE7\xF5es Reais
|
|
1192
|
-
|
|
1193
|
-
${restricoes}`);
|
|
1194
|
-
}
|
|
1195
|
-
if (porques) {
|
|
1196
|
-
sections.push(`## Porqu\xEAs
|
|
1197
|
-
|
|
1198
|
-
${porques}`);
|
|
1199
|
-
}
|
|
1200
|
-
let result = sections.join("\n\n") + "\n";
|
|
1201
|
-
if (ignoredContent) {
|
|
1202
|
-
result += `
|
|
1203
|
-
${ignoredContent}
|
|
1204
|
-
`;
|
|
1205
|
-
}
|
|
1206
|
-
return result;
|
|
1207
|
-
}
|
|
1208
|
-
function showDiff(original, modified) {
|
|
1209
|
-
const origLines = original.split("\n");
|
|
1210
|
-
const modLines = modified.split("\n");
|
|
1211
|
-
const maxLen = Math.max(origLines.length, modLines.length);
|
|
1212
|
-
for (let i = 0; i < maxLen; i++) {
|
|
1213
|
-
const o = origLines[i] ?? "";
|
|
1214
|
-
const m = modLines[i] ?? "";
|
|
1215
|
-
if (o !== m) {
|
|
1216
|
-
if (i < origLines.length) {
|
|
1217
|
-
console.log(chalk2.red(`- ${o}`));
|
|
1218
|
-
}
|
|
1219
|
-
if (i < modLines.length) {
|
|
1220
|
-
console.log(chalk2.green(`+ ${m}`));
|
|
1221
|
-
}
|
|
1222
|
-
}
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
function logChanges(original, modified) {
|
|
1226
|
-
if (original === modified) {
|
|
1227
|
-
console.log(chalk2.gray(" Nenhuma altera\xE7\xE3o necess\xE1ria."));
|
|
1228
|
-
return;
|
|
1229
|
-
}
|
|
1230
|
-
const sections = [];
|
|
1231
|
-
if (original.match(/^> Updated:.*$/m) !== modified.match(/^> Updated:.*$/m)) {
|
|
1232
|
-
sections.push("Updated");
|
|
1233
|
-
}
|
|
1234
|
-
const origHasSitrep = original.includes(START_MARKER);
|
|
1235
|
-
const modHasSitrep = modified.includes(START_MARKER);
|
|
1236
|
-
if (origHasSitrep !== modHasSitrep) {
|
|
1237
|
-
sections.push(modHasSitrep ? "Bloco sitrep (inserido)" : "Bloco sitrep (removido)");
|
|
1238
|
-
} else if (origHasSitrep) {
|
|
1239
|
-
sections.push("Bloco sitrep (atualizado)");
|
|
1240
|
-
}
|
|
1241
|
-
if (sections.length > 0) {
|
|
1242
|
-
console.log(chalk2.gray(` Se\xE7\xF5es alteradas: ${sections.join(", ")}`));
|
|
1243
|
-
} else {
|
|
1244
|
-
console.log(chalk2.gray(" Apenas data atualizada."));
|
|
1245
|
-
}
|
|
1246
|
-
}
|
|
1247
|
-
async function sitrep(rootPath, options) {
|
|
1248
|
-
const contextFile = join12(rootPath, ".letra", "context.md");
|
|
1249
|
-
if (!existsSync12(contextFile)) {
|
|
1250
|
-
if (!options?.quiet) console.log(chalk2.yellow("Aviso: .letra/context.md n\xE3o encontrado"));
|
|
1251
|
-
return;
|
|
1252
|
-
}
|
|
1253
|
-
const workflow = loadWorkflow(rootPath);
|
|
1254
|
-
const healthRecord = loadHealthRecord(rootPath);
|
|
1255
|
-
const alertSummary = getSummary(healthRecord);
|
|
1256
|
-
let currentItem = null;
|
|
1257
|
-
let acCounts = null;
|
|
1258
|
-
if (workflow) {
|
|
1259
|
-
currentItem = findCurrentItem(workflow);
|
|
1260
|
-
if (currentItem?.spec) {
|
|
1261
|
-
acCounts = countItemACs(rootPath, currentItem.spec);
|
|
1262
|
-
}
|
|
1263
|
-
}
|
|
1264
|
-
const decisions = getRecentDecisions(rootPath, 4);
|
|
1265
|
-
const data = {
|
|
1266
|
-
stage: currentItem?.stage ?? "sem item ativo",
|
|
1267
|
-
currentItem,
|
|
1268
|
-
acCounts,
|
|
1269
|
-
alertSummary,
|
|
1270
|
-
decisions,
|
|
1271
|
-
workflow
|
|
1272
|
-
};
|
|
1273
|
-
const dynamicBlock = buildSitrepBlock(data);
|
|
1274
|
-
const originalContent = readFileSync10(contextFile, "utf-8");
|
|
1275
|
-
const stack = extractSection(originalContent, "Stack");
|
|
1276
|
-
const restricoes = extractSection(originalContent, "Restri\xE7\xF5es Reais");
|
|
1277
|
-
const porques = extractSection(originalContent, "Porqu\xEAs");
|
|
1278
|
-
const withUpdated = originalContent.replace(
|
|
1279
|
-
/^(> Updated:).*$/m,
|
|
1280
|
-
`$1 ${(/* @__PURE__ */ new Date()).toISOString()}`
|
|
1281
|
-
);
|
|
1282
|
-
const newContent = rewriteContextFile(withUpdated, dynamicBlock, stack, restricoes, porques);
|
|
1283
|
-
if (options?.dryRun) {
|
|
1284
|
-
console.log(chalk2.bold("\n\u{1F4CB} Simula\xE7\xE3o de atualiza\xE7\xE3o \u2014 dry-run\n"));
|
|
1285
|
-
showDiff(originalContent, newContent);
|
|
1286
|
-
return;
|
|
1287
|
-
}
|
|
1288
|
-
writeFileSync6(contextFile, newContent, "utf-8");
|
|
1289
|
-
if (!options?.quiet) {
|
|
1290
|
-
console.log(chalk2.green("\u2713 Situa\xE7\xE3o atualizada em .letra/context.md"));
|
|
1291
|
-
logChanges(originalContent, newContent);
|
|
1292
|
-
}
|
|
1293
|
-
if (!options?.skipLog) {
|
|
1294
|
-
logEntry(rootPath, "sitrep", "context.md atualizado com estado do workspace", {
|
|
1295
|
-
details: {
|
|
1296
|
-
hasItem: !!currentItem,
|
|
1297
|
-
itemId: currentItem?.id,
|
|
1298
|
-
alertsNovo: alertSummary.novo
|
|
1299
|
-
}
|
|
1300
|
-
});
|
|
1301
|
-
}
|
|
1302
|
-
}
|
|
1303
|
-
function sitrep_default() {
|
|
1304
|
-
const cmd = new Command("sitrep").description("Atualizar .letra/context.md com estado real do workspace");
|
|
1305
|
-
cmd.option("--dry-run", "Exibir diff sem modificar o arquivo").action(async (options) => {
|
|
1306
|
-
const root = resolve2(process.cwd());
|
|
1307
|
-
await sitrep(root, options);
|
|
1308
|
-
});
|
|
1309
|
-
return cmd;
|
|
1310
|
-
}
|
|
1311
|
-
|
|
1312
|
-
export {
|
|
1313
|
-
logEntry,
|
|
1314
|
-
queryLog,
|
|
1315
|
-
DiagnosticEngine,
|
|
1316
|
-
sitrep,
|
|
1317
|
-
sitrep_default,
|
|
1318
|
-
detectProjectName,
|
|
1319
|
-
loadWorkflow,
|
|
1320
|
-
writeWorkflow,
|
|
1321
|
-
flowInitAction
|
|
1322
|
-
};
|