@letra-ai/cli 0.5.3 → 0.6.1

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.
Files changed (100) hide show
  1. package/dist/chunk-4QDEU6KP.js +2765 -0
  2. package/dist/chunk-6HSUVCTR.js +363 -0
  3. package/dist/chunk-BKAUN5QH.js +300 -0
  4. package/dist/chunk-BTPFUKHG.js +275 -0
  5. package/dist/chunk-EDD55PWL.js +119 -0
  6. package/dist/chunk-ELBTIPYN.js +256 -0
  7. package/dist/chunk-IEFSLCJL.js +837 -0
  8. package/dist/chunk-JMIC5NKB.js +235 -0
  9. package/dist/chunk-KGQLHMGZ.js +4494 -0
  10. package/dist/chunk-MJ2QXNH6.js +130 -0
  11. package/dist/chunk-MSF44WWE.js +443 -0
  12. package/dist/chunk-PDX44BCA.js +11 -0
  13. package/dist/chunk-QIVKP3EY.js +362 -0
  14. package/dist/client/assets/index-BuABgOyz.js +232 -0
  15. package/dist/client/assets/index-CpseCZh9.css +1 -0
  16. package/dist/client/favicon.svg +16 -4
  17. package/dist/client/index.html +25 -20
  18. package/dist/fallback-UXSZ4LNR.js +47 -0
  19. package/dist/flow-serve-MTB6KZMR.js +19 -0
  20. package/dist/focus-sync-3D3XWCTI.js +17 -0
  21. package/dist/generate-N22QOXUF.js +20 -0
  22. package/dist/harness/default/v0.1.0/flows/sdlc.yaml +179 -0
  23. package/dist/harness/default/v0.1.0/gates/all-acs-passing.yaml +8 -0
  24. package/dist/harness/default/v0.1.0/gates/has-spec-file.yaml +7 -0
  25. package/dist/harness/default/v0.1.0/gates/human-approved-code.yaml +8 -0
  26. package/dist/harness/default/v0.1.0/gates/human-approved-spec.yaml +8 -0
  27. package/dist/harness/default/v0.1.0/gates/security-clear.yaml +8 -0
  28. package/dist/harness/default/v0.1.0/policies/sdlc-default.json +20 -0
  29. package/dist/harness/default/v0.1.0/roles/analyst.yaml +9 -0
  30. package/dist/harness/default/v0.1.0/roles/builder.yaml +9 -0
  31. package/dist/harness/default/v0.1.0/roles/pr-bot.yaml +8 -0
  32. package/dist/harness/default/v0.1.0/roles/reviewer.yaml +10 -0
  33. package/dist/harness/default/v0.1.0/roles/security.yaml +8 -0
  34. package/dist/harness/default/v0.1.1/flows/flow-main.yaml +61 -0
  35. package/dist/harness/default/v0.1.1/flows/sdlc.yaml +179 -0
  36. package/dist/harness/default/v0.1.1/gates/all-acs-passing.yaml +8 -0
  37. package/dist/harness/default/v0.1.1/gates/has-spec-file.yaml +7 -0
  38. package/dist/harness/default/v0.1.1/gates/human-approved-code.yaml +8 -0
  39. package/dist/harness/default/v0.1.1/gates/human-approved-spec.yaml +8 -0
  40. package/dist/harness/default/v0.1.1/gates/security-clear.yaml +8 -0
  41. package/dist/harness/default/v0.1.1/policies/sdlc-default.json +20 -0
  42. package/dist/harness/default/v0.1.1/roles/analyst.yaml +9 -0
  43. package/dist/harness/default/v0.1.1/roles/builder.yaml +9 -0
  44. package/dist/harness/default/v0.1.1/roles/pr-bot.yaml +8 -0
  45. package/dist/harness/default/v0.1.1/roles/reviewer.yaml +10 -0
  46. package/dist/harness/default/v0.1.1/roles/security.yaml +8 -0
  47. package/dist/harness/default/v0.1.2/flows/flow-main.yaml +86 -0
  48. package/dist/harness/default/v0.1.2/flows/sdlc.yaml +179 -0
  49. package/dist/harness/default/v0.1.2/gates/all-acs-passing.yaml +8 -0
  50. package/dist/harness/default/v0.1.2/gates/has-spec-file.yaml +7 -0
  51. package/dist/harness/default/v0.1.2/gates/human-approved-code.yaml +8 -0
  52. package/dist/harness/default/v0.1.2/gates/human-approved-spec.yaml +8 -0
  53. package/dist/harness/default/v0.1.2/gates/security-clear.yaml +8 -0
  54. package/dist/harness/default/v0.1.2/policies/sdlc-default.json +20 -0
  55. package/dist/harness/default/v0.1.2/roles/analyst.yaml +9 -0
  56. package/dist/harness/default/v0.1.2/roles/builder.yaml +9 -0
  57. package/dist/harness/default/v0.1.2/roles/pr-bot.yaml +8 -0
  58. package/dist/harness/default/v0.1.2/roles/reviewer.yaml +10 -0
  59. package/dist/harness/default/v0.1.2/roles/security.yaml +8 -0
  60. package/dist/harness/default/v0.1.3/flows/flow-main.yaml +90 -0
  61. package/dist/harness/default/v0.1.3/flows/sdlc.yaml +179 -0
  62. package/dist/harness/default/v0.1.3/gates/all-acs-passing.yaml +8 -0
  63. package/dist/harness/default/v0.1.3/gates/has-spec-file.yaml +7 -0
  64. package/dist/harness/default/v0.1.3/gates/human-approved-code.yaml +9 -0
  65. package/dist/harness/default/v0.1.3/gates/human-approved-spec.yaml +9 -0
  66. package/dist/harness/default/v0.1.3/gates/security-clear.yaml +8 -0
  67. package/dist/harness/default/v0.1.3/policies/sdlc-default.json +20 -0
  68. package/dist/harness/default/v0.1.3/roles/analyst.yaml +9 -0
  69. package/dist/harness/default/v0.1.3/roles/builder.yaml +9 -0
  70. package/dist/harness/default/v0.1.3/roles/pr-bot.yaml +8 -0
  71. package/dist/harness/default/v0.1.3/roles/reviewer.yaml +10 -0
  72. package/dist/harness/default/v0.1.3/roles/security.yaml +8 -0
  73. package/dist/harness/default/v0.2.0/executors/registry.yaml +51 -0
  74. package/dist/harness/default/v0.2.0/flows/flow-main.yaml +247 -0
  75. package/dist/harness/default/v0.2.0/gates/code-reviewed.yaml +7 -0
  76. package/dist/harness/default/v0.2.0/gates/human-approved.yaml +10 -0
  77. package/dist/harness/default/v0.2.0/gates/security-clear.yaml +7 -0
  78. package/dist/harness/default/v0.2.0/gates/spec-approved.yaml +10 -0
  79. package/dist/harness/default/v0.2.0/policies/sdlc-default.json +20 -0
  80. package/dist/harness/default/v0.2.0/roles/analyst.yaml +16 -0
  81. package/dist/harness/default/v0.2.0/roles/implementer.yaml +17 -0
  82. package/dist/harness/default/v0.2.0/roles/reviewer.yaml +17 -0
  83. package/dist/harness/default/v0.2.0/roles/security.yaml +17 -0
  84. package/dist/health-record-YDVXEVLR.js +21 -0
  85. package/dist/index.js +1932 -2528
  86. package/dist/init-wizard-NODBBNKO.js +178 -0
  87. package/dist/push-5JEYSXBY.js +116 -0
  88. package/dist/registry-6VPIA3EG.js +18 -0
  89. package/dist/server-FUP3APZA.js +415 -0
  90. package/dist/service-OGF7BMCQ.js +21 -0
  91. package/dist/session-log-WTQ5JBEN.js +21 -0
  92. package/dist/sitrep-DJXTP3JO.js +16 -0
  93. package/package.json +37 -28
  94. package/dist/chunk-56GTTLC4.js +0 -1322
  95. package/dist/chunk-QWT5M4XU.js +0 -643
  96. package/dist/client/assets/index-CuLfFw4K.js +0 -85
  97. package/dist/client/assets/index-iyLqZcWx.css +0 -1
  98. package/dist/generate-BF5R5GGA.js +0 -7
  99. package/dist/sitrep-SI6ZFIAM.js +0 -10
  100. package/tsup.config.ts +0 -11
@@ -1,643 +0,0 @@
1
- #!/usr/bin/env node
2
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
- }) : x)(function(x) {
5
- if (typeof require !== "undefined") return require.apply(this, arguments);
6
- throw Error('Dynamic require of "' + x + '" is not supported');
7
- });
8
-
9
- // src/adapters/generate.ts
10
- import { existsSync as existsSync4, mkdirSync as mkdirSync2, writeFileSync as writeFileSync3 } from "fs";
11
- import { join as join4 } from "path";
12
- import chalk from "chalk";
13
-
14
- // src/adapters/builder.ts
15
- import { existsSync as existsSync3, readFileSync as readFileSync3 } from "fs";
16
- import { join as join3 } from "path";
17
-
18
- // src/adapters/focus-sync.ts
19
- import { existsSync, readFileSync, unlinkSync, writeFileSync } from "fs";
20
- import { join } from "path";
21
- function syncFocus(rootDir, workflow) {
22
- const focusFile = join(rootDir, ".letra", "focus.md");
23
- const focusData = readFocusFile(rootDir);
24
- let cleared = false;
25
- let generated = false;
26
- let diverged = false;
27
- if (focusData && workflow) {
28
- const itemExists = workflow.items.some((i) => i.id === focusData.itemId);
29
- if (!itemExists) {
30
- clearFocusFile(rootDir);
31
- cleared = true;
32
- } else {
33
- const item = workflow.items.find((i) => i.id === focusData.itemId);
34
- if (item && item.spec && item.spec !== focusData.specName) {
35
- diverged = true;
36
- }
37
- }
38
- }
39
- if (!focusData && workflow) {
40
- const activeItem = findActiveItem(workflow);
41
- if (activeItem?.spec) {
42
- writeFocusFile(rootDir, activeItem.spec, activeItem.id);
43
- generated = true;
44
- }
45
- }
46
- if (focusData && !workflow) {
47
- clearFocusFile(rootDir);
48
- cleared = true;
49
- }
50
- return { cleared, generated, diverged };
51
- }
52
- function findActiveItem(workflow) {
53
- const activeStages = workflow.stages.filter((s) => s.zone === "doing" || !s.zone && s.order > 0 && s.order < workflow.stages.length - 1).map((s) => s.id);
54
- const stageSet = new Set(activeStages);
55
- if (stageSet.size === 0) {
56
- const mid = Math.floor(workflow.stages.length / 2);
57
- const stage = workflow.stages[mid];
58
- if (stage) stageSet.add(stage.id);
59
- }
60
- const items = workflow.items.filter((i) => stageSet.has(i.stage));
61
- if (items.length === 0) return null;
62
- return items.reduce((a, b) => new Date(a.createdAt) > new Date(b.createdAt) ? a : b);
63
- }
64
- function extractOutcome(rootDir, specName) {
65
- const specFile = join(rootDir, ".letra", "specs", specName, "spec.md");
66
- if (!existsSync(specFile)) return null;
67
- const content = readFileSync(specFile, "utf-8");
68
- const match = content.match(/## Outcome\s+([\s\S]*?)(?=\n## |\n*$)/);
69
- return match ? match[1].trim() : null;
70
- }
71
- function writeFocusFile(rootDir, specName, itemId) {
72
- const focusFile = join(rootDir, ".letra", "focus.md");
73
- const outcome = extractOutcome(rootDir, specName) || specName;
74
- const content = [
75
- `# Focus: ${specName}`,
76
- "",
77
- `**Path**: .letra/specs/${specName}/`,
78
- `**Item**: ${itemId}`,
79
- `**Outcome**: ${outcome}`,
80
- ""
81
- ].join("\n");
82
- writeFileSync(focusFile, content, "utf-8");
83
- }
84
- function clearFocusFile(rootDir) {
85
- const focusFile = join(rootDir, ".letra", "focus.md");
86
- if (existsSync(focusFile)) {
87
- unlinkSync(focusFile);
88
- }
89
- }
90
- function readFocusFile(rootDir) {
91
- const focusFile = join(rootDir, ".letra", "focus.md");
92
- if (!existsSync(focusFile)) return null;
93
- const content = readFileSync(focusFile, "utf-8");
94
- const specMatch = content.match(/# Focus:\s*(.+)/);
95
- const itemMatch = content.match(/\*\*Item\*\*:\s*(.+)/);
96
- const outcomeMatch = content.match(/\*\*Outcome\*\*:\s*([\s\S]*?)(?=\n\*\*|\n*$)/);
97
- if (!specMatch) return null;
98
- return {
99
- specName: specMatch[1].trim(),
100
- itemId: itemMatch ? itemMatch[1].trim() : "",
101
- outcome: outcomeMatch ? outcomeMatch[1].trim() : ""
102
- };
103
- }
104
-
105
- // src/health-record.ts
106
- import { existsSync as existsSync2, mkdirSync, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
107
- import { join as join2 } from "path";
108
- var RECORD_FILE = "health-record.json";
109
- var SCHEMA_VERSION = 1;
110
- var CLEANUP_DAYS = 90;
111
- function recordPath(root) {
112
- return join2(root, ".letra", RECORD_FILE);
113
- }
114
- function loadHealthRecord(root) {
115
- const file = recordPath(root);
116
- if (!existsSync2(file)) {
117
- return { schemaVersion: SCHEMA_VERSION, lastScanAt: (/* @__PURE__ */ new Date()).toISOString(), entries: [] };
118
- }
119
- try {
120
- const raw = readFileSync2(file, "utf-8");
121
- const record = JSON.parse(raw);
122
- if (!record.entries) record.entries = [];
123
- return record;
124
- } catch {
125
- return { schemaVersion: SCHEMA_VERSION, lastScanAt: (/* @__PURE__ */ new Date()).toISOString(), entries: [] };
126
- }
127
- }
128
- function saveHealthRecord(root, record) {
129
- const dir = join2(root, ".letra");
130
- if (!existsSync2(dir)) mkdirSync(dir, { recursive: true });
131
- record.lastScanAt = (/* @__PURE__ */ new Date()).toISOString();
132
- writeFileSync2(recordPath(root), JSON.stringify(record, null, 2), "utf-8");
133
- }
134
- function hashResult(result) {
135
- const key = `${result.detector}:${result.title}`;
136
- let hash = 0;
137
- for (let i = 0; i < key.length; i++) {
138
- const char = key.charCodeAt(i);
139
- hash = (hash << 5) - hash + char;
140
- hash |= 0;
141
- }
142
- return `hr-${Math.abs(hash).toString(16).padStart(6, "0")}`;
143
- }
144
- function severityFromType(type) {
145
- if (type === "error") return "alta";
146
- if (type === "warning") return "media";
147
- return "baixa";
148
- }
149
- function mergeScanResults(record, results) {
150
- const now = (/* @__PURE__ */ new Date()).toISOString();
151
- for (const result of results) {
152
- const id = hashResult(result);
153
- const existing = record.entries.find((e) => e.id === id);
154
- if (!existing) {
155
- record.entries.push({
156
- id,
157
- type: result.type,
158
- title: result.title,
159
- status: "novo",
160
- severity: severityFromType(result.type),
161
- source: result.detector,
162
- detectedAt: now,
163
- resolvedAt: null,
164
- dismissedAt: null,
165
- dismissReason: null,
166
- acknowledgedAt: null
167
- });
168
- } else if (existing.status === "resolvido") {
169
- existing.status = "novo";
170
- existing.detectedAt = now;
171
- existing.resolvedAt = null;
172
- }
173
- }
174
- for (const entry of record.entries) {
175
- if (entry.status === "descartado") continue;
176
- const stillPresent = results.some((r) => hashResult(r) === entry.id);
177
- if (!stillPresent && entry.status !== "resolvido") {
178
- entry.status = "resolvido";
179
- entry.resolvedAt = now;
180
- }
181
- }
182
- record.entries = cleanupOldEntries(record.entries);
183
- return record;
184
- }
185
- function cleanupOldEntries(entries) {
186
- const cutoff = Date.now() - CLEANUP_DAYS * 24 * 60 * 60 * 1e3;
187
- return entries.filter((e) => {
188
- if (e.status !== "resolvido" && e.status !== "descartado") return true;
189
- const refDate = e.resolvedAt ?? e.dismissedAt ?? e.detectedAt;
190
- return new Date(refDate).getTime() > cutoff;
191
- });
192
- }
193
- function ackEntry(record, id) {
194
- const entry = record.entries.find((e) => e.id === id);
195
- if (!entry) return false;
196
- entry.status = "ciente";
197
- entry.acknowledgedAt = (/* @__PURE__ */ new Date()).toISOString();
198
- return true;
199
- }
200
- function dismissEntry(record, id, reason) {
201
- const entry = record.entries.find((e) => e.id === id);
202
- if (!entry) return false;
203
- entry.status = "descartado";
204
- entry.dismissedAt = (/* @__PURE__ */ new Date()).toISOString();
205
- entry.dismissReason = reason ?? null;
206
- return true;
207
- }
208
- function getActiveEntries(record) {
209
- return record.entries.filter((e) => e.status === "novo" || e.status === "ciente");
210
- }
211
- function getSummary(record) {
212
- return {
213
- novo: record.entries.filter((e) => e.status === "novo").length,
214
- ciente: record.entries.filter((e) => e.status === "ciente").length,
215
- descartado: record.entries.filter((e) => e.status === "descartado").length,
216
- resolvido: record.entries.filter((e) => e.status === "resolvido").length,
217
- alta: record.entries.filter((e) => e.status === "novo" && e.severity === "alta").length
218
- };
219
- }
220
-
221
- // src/adapters/builder.ts
222
- function countACs(root, specName) {
223
- if (!specName) return { pending: 0, total: 0 };
224
- const specDir = join3(root, ".letra", "specs", specName);
225
- if (!existsSync3(specDir)) return { pending: 0, total: 0 };
226
- let content = "";
227
- const acceptancePath = join3(specDir, "acceptance.md");
228
- const specPath = join3(specDir, "spec.md");
229
- if (existsSync3(acceptancePath)) {
230
- content = readFileSync3(acceptancePath, "utf-8");
231
- } else if (existsSync3(specPath)) {
232
- content = readFileSync3(specPath, "utf-8");
233
- const acMatch = content.match(/## Acceptance Criteria\s+([\s\S]*?)(?=\n## |\n*$)/);
234
- if (acMatch) content = acMatch[1];
235
- else return { pending: 0, total: 0 };
236
- } else {
237
- return { pending: 0, total: 0 };
238
- }
239
- const total = (content.match(/- \[.?] \*\*AC/g) || []).length;
240
- const pending = (content.match(/- \[ ] \*\*AC/g) || []).length;
241
- return { pending, total };
242
- }
243
- function loadLastSession(root) {
244
- const logPath = join3(root, ".letra", "session-log.json");
245
- if (!existsSync3(logPath)) return null;
246
- try {
247
- const log = JSON.parse(readFileSync3(logPath, "utf-8"));
248
- const entries = log.entries || [];
249
- if (entries.length === 0) return null;
250
- const lastEntry = entries[0];
251
- const actions = entries.slice(0, 5).map(
252
- (e) => `${e.action}: ${e.description?.slice(0, 50)}`
253
- );
254
- return {
255
- lastDate: new Date(lastEntry.timestamp).toLocaleString("pt-BR"),
256
- actionsSummary: actions.join("\n \u2022 ")
257
- };
258
- } catch {
259
- return null;
260
- }
261
- }
262
- function buildHarnessSnapshot(root, options) {
263
- const hasFocus = existsSync3(join3(root, ".letra", "focus.md"));
264
- if (!options.workflow || !options.activeStageId) {
265
- return {
266
- workflowName: "letra",
267
- hasWorkflow: false,
268
- items: [],
269
- hasFocus,
270
- primaryItemId: null,
271
- focusSpec: null,
272
- focusPath: null,
273
- pendingACs: 0,
274
- totalACs: 0
275
- };
276
- }
277
- const { workflow, activeStageId } = options;
278
- const stage = workflow.stages.find((s) => s.id === activeStageId);
279
- const stageItems = workflow.items.filter((item) => item.stage === activeStageId);
280
- let nextStage;
281
- if (stage) {
282
- const hasOrder = workflow.stages.some((s) => s.order !== void 0);
283
- const sorted = hasOrder ? [...workflow.stages].sort((a, b) => (a.order ?? 0) - (b.order ?? 0)) : workflow.stages;
284
- const currentIdx = sorted.findIndex((s) => s.id === stage.id);
285
- if (currentIdx >= 0 && currentIdx < sorted.length - 1) {
286
- const ns = sorted[currentIdx + 1];
287
- nextStage = { id: ns.id, name: ns.name };
288
- }
289
- }
290
- let primaryItemId = null;
291
- if (options.primaryItemId && stageItems.some((i) => i.id === options.primaryItemId)) {
292
- primaryItemId = options.primaryItemId;
293
- } else if (stageItems.length > 0) {
294
- primaryItemId = stageItems[0].id;
295
- }
296
- const items = stageItems.map((item) => ({
297
- id: item.id,
298
- description: item.description,
299
- spec: item.spec,
300
- claimedBy: item.claimedBy,
301
- claimedAt: item.claimedAt
302
- }));
303
- let focusSpec = null;
304
- let focusPath = null;
305
- const parsedFocus = readFocusFile(root);
306
- if (parsedFocus) {
307
- focusSpec = parsedFocus.specName;
308
- focusPath = `.letra/specs/${parsedFocus.specName}/`;
309
- } else {
310
- const primaryItem = items.find((i) => i.id === primaryItemId);
311
- if (primaryItem?.spec) {
312
- focusSpec = primaryItem.spec;
313
- focusPath = `.letra/specs/${primaryItem.spec}/`;
314
- }
315
- }
316
- const acCounts = countACs(root, focusSpec);
317
- const lastSession = loadLastSession(root);
318
- const healthRecord = loadHealthRecord(root);
319
- const novoAlerts = healthRecord.entries.filter((e) => e.status === "novo").slice(0, 5).map((e) => ({
320
- id: e.id,
321
- severity: e.severity,
322
- title: e.title,
323
- source: e.source,
324
- detectedAt: e.detectedAt
325
- }));
326
- const totalNovo = healthRecord.entries.filter((e) => e.status === "novo").length;
327
- return {
328
- workflowName: workflow.name,
329
- hasWorkflow: true,
330
- activeStage: stage ? { id: stage.id, name: stage.name } : { id: activeStageId, name: activeStageId },
331
- nextStage,
332
- items,
333
- hasFocus,
334
- primaryItemId,
335
- focusSpec,
336
- focusPath,
337
- pendingACs: acCounts.pending,
338
- totalACs: acCounts.total,
339
- lastSession,
340
- alerts: novoAlerts.length > 0 ? [...novoAlerts, ...totalNovo > 5 ? [{ id: "...", severity: "", title: `e mais ${totalNovo - 5} alertas`, source: "", detectedAt: "" }] : []] : void 0
341
- };
342
- }
343
-
344
- // src/adapters/formatters.ts
345
- var L1_FILES = [".letra/context.md", ".letra/constitution.md", ".letra/glossary.md", ".letra/constraints.md"];
346
- function formatL1(snapshot, format) {
347
- if (format === "at") {
348
- const lines2 = L1_FILES.map((path) => `@${path}`);
349
- if (snapshot.hasFocus) lines2.push("@.letra/focus.md");
350
- return lines2.join("\n");
351
- }
352
- const lines = [...L1_FILES.map((path) => `- ${path}`)];
353
- if (snapshot.hasFocus) {
354
- lines.push("- .letra/focus.md");
355
- } else {
356
- lines.push("- .letra/focus.md");
357
- }
358
- return lines.join("\n");
359
- }
360
- function formatDate(iso) {
361
- if (!iso) return "";
362
- try {
363
- return new Date(iso).toLocaleString("pt-BR");
364
- } catch {
365
- return "";
366
- }
367
- }
368
- function formatProtocol(snapshot) {
369
- if (!snapshot.hasWorkflow) return null;
370
- const primaryItem = snapshot.primaryItemId ? snapshot.items.find((i) => i.id === snapshot.primaryItemId) : snapshot.items[0];
371
- const acLine = snapshot.totalACs > 0 ? `ACs: ${snapshot.pendingACs}/${snapshot.totalACs} pendentes` : "";
372
- const lines = [
373
- "PASSO OBRIGAT\xD3RIO #1: letra pulse \u2014 verificar estado do workspace",
374
- "PASSO OBRIGAT\xD3RIO #2: Leia .letra/context.md \u2014 contexto completo do projeto",
375
- "PASSO OBRIGAT\xD3RIO #3: Leia .letra/focus.md \u2014 foco e outcome da sess\xE3o"
376
- ];
377
- if (snapshot.focusSpec) {
378
- lines.push(`PASSO OBRIGAT\xD3RIO #4: Leia .letra/specs/${snapshot.focusSpec}/spec.md \u2014 ACs do item`);
379
- } else if (primaryItem?.spec) {
380
- lines.push(`PASSO OBRIGAT\xD3RIO #4: Leia .letra/specs/${primaryItem.spec}/spec.md \u2014 ACs do item`);
381
- } else {
382
- lines.push("PASSO OBRIGAT\xD3RIO #4: Identifique o item ativo via `letra pulse` e leia sua spec");
383
- }
384
- return lines.join("\n");
385
- }
386
- function formatFocus(snapshot) {
387
- if (!snapshot.hasWorkflow) return null;
388
- const primaryItem = snapshot.primaryItemId ? snapshot.items.find((i) => i.id === snapshot.primaryItemId) : snapshot.items[0];
389
- if (!primaryItem) return null;
390
- const lines = [
391
- `Item: ${primaryItem.id} \xB7 ${primaryItem.description}`
392
- ];
393
- if (snapshot.focusSpec) lines.push(`Spec: ${snapshot.focusSpec}`);
394
- if (snapshot.activeStage) {
395
- const stageLine = `Est\xE1gio: ${snapshot.activeStage.name}`;
396
- if (snapshot.nextStage) {
397
- lines.push(`${stageLine} \u2192 ${snapshot.nextStage.name}`);
398
- } else {
399
- lines.push(stageLine);
400
- }
401
- }
402
- if (snapshot.totalACs > 0) {
403
- lines.push(`ACs: ${snapshot.pendingACs}/${snapshot.totalACs} pendentes`);
404
- }
405
- return lines.join("\n");
406
- }
407
- function formatAlerts(snapshot) {
408
- if (!snapshot.alerts || snapshot.alerts.length === 0) return null;
409
- const lines = [];
410
- for (const alert of snapshot.alerts) {
411
- if (alert.id === "...") {
412
- lines.push(` ${alert.title}`);
413
- continue;
414
- }
415
- const severityLabel = alert.severity === "alta" ? "alta" : alert.severity === "media" ? "m\xE9dia" : "baixa";
416
- lines.push(`Alerta \xB7 severidade ${severityLabel}`);
417
- lines.push(` ID: ${alert.id}`);
418
- lines.push(` O que: ${alert.title}`);
419
- lines.push(` Onde: ${alert.source}`);
420
- lines.push(` Desde: ${formatDate(alert.detectedAt)}`);
421
- lines.push(` A\xE7\xE3o: \`letra health ack ${alert.id}\``);
422
- lines.push("");
423
- }
424
- return lines.join("\n");
425
- }
426
- function formatProhibitionRules() {
427
- return [
428
- "**Viola\xE7\xE3o = Erro Grave**",
429
- "",
430
- "- N\xE3o edite workflow.json manualmente \u2014 use `letra flow` e `letra focus`",
431
- "- N\xE3o crie specs fora de .letra/specs/ \u2014 use `letra spec new`",
432
- "- N\xE3o pule os passos obrigat\xF3rios de in\xEDcio acima",
433
- "- Execute `letra validate` antes de mover item entre est\xE1gios",
434
- "- Siga a constitution.md rigorosamente"
435
- ].join("\n");
436
- }
437
- function formatExecutionFlow() {
438
- return [
439
- "**Loop por AC**:",
440
- " 1. Implemente o AC no c\xF3digo",
441
- ` 2. \`letra ac done <AC-ID>\` \u2014 marca como conclu\xEDdo no spec.md`,
442
- " 3. `letra validate` \u2014 verifica se ACs est\xE3o consistentes",
443
- " 4. Repita at\xE9 todos os ACs do item estarem conclu\xEDdos",
444
- "",
445
- "**Ao concluir todos ACs**:",
446
- ` \u2192 \`letra pulse\` \u2014 confirma estado`,
447
- ` \u2192 \`letra sitrep\` \u2014 atualiza context.md`,
448
- ` \u2192 \`letra flow move <ITEM-ID> --auto\` \u2014 avan\xE7a para pr\xF3ximo est\xE1gio`
449
- ].join("\n");
450
- }
451
- function formatCommands() {
452
- return [
453
- "**Leitura (seguro \u2014 n\xE3o muda nada):**",
454
- " `letra pulse` \u2014 Overview do workspace",
455
- " `letra health` \u2014 Alertas ativos",
456
- " `letra flow board` \u2014 Todas as colunas do fluxo",
457
- " `letra flow backlog` \u2014 Itens no backlog",
458
- " `letra validate` \u2014 Validar specs e ACs",
459
- "",
460
- "**Escrita (muda estado):**",
461
- " `letra health ack <id>` \u2014 Reconhecer alerta",
462
- " `letra health dismiss <id>` \u2014 Descartar alerta",
463
- " `letra health scan` \u2014 Re-executar verifica\xE7\xF5es",
464
- " `letra sitrep` \u2014 Atualizar context.md",
465
- " `letra flow move <id> --to <s>` \u2014 Mover item entre est\xE1gios",
466
- " `letra focus <spec>` \u2014 Definir foco",
467
- " `letra focus --clear` \u2014 Limpar foco"
468
- ].join("\n");
469
- }
470
- function formatCompletionChecklist(snapshot) {
471
- if (!snapshot.hasWorkflow) return null;
472
- return [
473
- "1. `letra pulse --json` \u2014 veja itens, ACs, alertas, backlog",
474
- "",
475
- "2. Decida o estado:",
476
- "",
477
- " **CONTINUE** (backlog tem itens OU item atual tem ACs pendentes):",
478
- " \u2192 Relate o progresso: quais ACs fez, o que falta, onde parou",
479
- " \u2192 Se sess\xE3o >30 min, pare e relate. Caso contr\xE1rio, continue.",
480
- "",
481
- " **BLOCKED** (backlog vazio, item sem ACs pendentes, aguardando humano):",
482
- ' \u2192 Relate "Trabalho conclu\xEDdo, aguardando revis\xE3o"',
483
- " \u2192 Liste o que foi feito e decis\xF5es necess\xE1rias",
484
- "",
485
- " **ALL_DONE** (todos os itens em Done, backlog vazio):",
486
- " \u2192 Relate miss\xE3o completa: itens conclu\xEDdos, o que foi constru\xEDdo, pr\xF3ximos passos"
487
- ].join("\n");
488
- }
489
- function formatContinuity(snapshot) {
490
- if (!snapshot.lastSession) return null;
491
- return [
492
- `\xDAltima atividade: ${snapshot.lastSession.lastDate}`,
493
- `A\xE7\xF5es:
494
- \u2022 ${snapshot.lastSession.actionsSummary}`
495
- ].join("\n");
496
- }
497
- function formatAdapterContent(snapshot, format, options) {
498
- const title = snapshot.hasWorkflow ? `# Letra Session \u2014 ${snapshot.workflowName}` : `# Letra Context \u2014 ${options.displayName} Adapter`;
499
- const sections = [];
500
- if (!snapshot.hasWorkflow) {
501
- sections.push(title);
502
- if (format === "at") {
503
- sections.push(L1_FILES.map((p) => `@${p}`).join("\n"));
504
- } else {
505
- sections.push("Read the following files before starting any task:\n" + L1_FILES.map((p) => `- ${p}`).join("\n"));
506
- }
507
- if (snapshot.hasFocus) sections[1] += format === "at" ? "\n@.letra/focus.md" : "\n- .letra/focus.md";
508
- sections.push(...["", formatRulesText()]);
509
- return sections.join("\n");
510
- }
511
- sections.push(title);
512
- const protocol = formatProtocol(snapshot);
513
- if (protocol) sections.push(protocol);
514
- const focus = formatFocus(snapshot);
515
- if (focus) {
516
- sections.push(`## Foco Atual
517
-
518
- ${focus}`);
519
- }
520
- const hasGrave = snapshot.alerts?.some((a) => a.severity === "alta");
521
- if (hasGrave) {
522
- const graveAlerts = snapshot.alerts?.filter((a) => a.severity === "alta") || [];
523
- sections.push(`## \u26A0 ATEN\xC7\xC3O \u2014 Problema Grave
524
-
525
- ${formatAlerts({ ...snapshot, alerts: graveAlerts })}`);
526
- }
527
- const alerts = formatAlerts(snapshot);
528
- if (alerts && !hasGrave) {
529
- sections.push(`## Alertas
530
-
531
- ${alerts}`);
532
- } else if (alerts && hasGrave) {
533
- const nonGrave = snapshot.alerts?.filter((a) => a.severity !== "alta");
534
- if (nonGrave && nonGrave.length > 0) {
535
- sections.push(`## Alertas
536
-
537
- ${formatAlerts({ ...snapshot, alerts: nonGrave })}`);
538
- }
539
- }
540
- sections.push(`## Regras (Viola\xE7\xE3o = Erro Grave)
541
-
542
- ${formatProhibitionRules()}`);
543
- if (snapshot.hasWorkflow) {
544
- sections.push(`## Fluxo de Execu\xE7\xE3o
545
-
546
- ${formatExecutionFlow()}`);
547
- }
548
- sections.push(`## Comandos
549
-
550
- ${formatCommands()}`);
551
- const continuity = formatContinuity(snapshot);
552
- if (continuity) {
553
- sections.push(`## Continuidade
554
-
555
- ${continuity}`);
556
- }
557
- sections.push(`## Checklist de Encerramento
558
-
559
- ${formatCompletionChecklist(snapshot)}`);
560
- const refs = formatL1(snapshot, format);
561
- sections.push(`## Arquivos de Contexto
562
-
563
- ${refs}`);
564
- return `${sections.join("\n\n")}
565
- `;
566
- }
567
- function formatRulesText() {
568
- return [
569
- "# Rules",
570
- "- Always read specs in .letra/specs/ before writing code",
571
- "- Run `letra validate` to check acceptance criteria",
572
- "- Execute `letra ac done <ID>` after implementing each AC",
573
- "- Follow the constitution.md rules strictly",
574
- "- Use formal tone in all generated content"
575
- ].join("\n");
576
- }
577
-
578
- // src/adapters/generate.ts
579
- var ADAPTER_HEADER = {
580
- init: "# Generated by letra init. Do not edit manually.\n",
581
- "flow-move": "# Gerado por letra flow move. Nao edite manualmente.\n",
582
- focus: "# Gerado por letra focus. Nao edite manualmente.\n",
583
- "flow-ac": "# Gerado por letra ac. Nao edite manualmente.\n"
584
- };
585
- var TOOL_TARGETS = {
586
- cursor: { paths: [".cursorrules"], format: "at", displayName: "Cursor" },
587
- "claude-code": { paths: ["CLAUDE.md"], format: "text", displayName: "Claude Code" },
588
- windsurf: { paths: [".windsurfrules"], format: "at", displayName: "Windsurf" },
589
- vscode: {
590
- paths: [".github/copilot-instructions.md"],
591
- format: "text",
592
- displayName: "VSCode Copilot"
593
- },
594
- opencode: { paths: [".opencode/instructions.md", "AGENTS.md"], format: "text", displayName: "OpenCode" },
595
- hermes: { paths: [".hermes/instructions.md"], format: "text", displayName: "Hermes Agent" }
596
- };
597
- function generateAdapters(root, tools, options) {
598
- const snapshot = buildHarnessSnapshot(root, options);
599
- let header = ADAPTER_HEADER[options.source];
600
- const verb = options.verb ?? (options.source === "init" ? "Created" : "Updated");
601
- if (options.graveIssueCount && options.graveIssueCount > 0) {
602
- const warn = `
603
- ### \u26A0 ATEN\xC7\xC3O: ${options.graveIssueCount} problema(s) grave(s) detectado(s) pelo diagn\xF3stico autom\xE1tico
604
- Execute \`letra health\` para detalhes e \`letra health ack <id>\` para reconhecer.
605
- `;
606
- header += warn;
607
- }
608
- for (const tool of tools) {
609
- const target = TOOL_TARGETS[tool];
610
- if (!target) continue;
611
- const content = formatAdapterContent(snapshot, target.format, {
612
- source: options.source,
613
- displayName: target.displayName
614
- });
615
- for (const path of target.paths) {
616
- const filePath = join4(root, path);
617
- const dir = join4(filePath, "..");
618
- if (!existsSync4(dir)) mkdirSync2(dir, { recursive: true });
619
- writeFileSync3(filePath, header + content);
620
- if (!options.quiet) {
621
- console.log(
622
- ` ${chalk.gray(verb)} ${path}`
623
- );
624
- }
625
- }
626
- }
627
- }
628
-
629
- export {
630
- __require,
631
- syncFocus,
632
- writeFocusFile,
633
- clearFocusFile,
634
- readFocusFile,
635
- loadHealthRecord,
636
- saveHealthRecord,
637
- mergeScanResults,
638
- ackEntry,
639
- dismissEntry,
640
- getActiveEntries,
641
- getSummary,
642
- generateAdapters
643
- };