@letra-ai/cli 0.6.1 → 0.7.0

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 (55) hide show
  1. package/dist/chunk-2GRNAFBQ.js +5305 -0
  2. package/dist/{chunk-MJ2QXNH6.js → chunk-42RST74I.js} +1 -1
  3. package/dist/chunk-HC24XMPZ.js +269 -0
  4. package/dist/chunk-LUPN3TRC.js +554 -0
  5. package/dist/{chunk-KGQLHMGZ.js → chunk-MUCIMQAU.js} +1918 -757
  6. package/dist/chunk-POGWTSEA.js +125 -0
  7. package/dist/chunk-TNF7XTFG.js +6178 -0
  8. package/dist/{chunk-BKAUN5QH.js → chunk-UMC5PDL2.js} +227 -33
  9. package/dist/{chunk-6HSUVCTR.js → chunk-YAQ2TKSK.js} +82 -30
  10. package/dist/client/assets/index-C-6kWNFi.js +232 -0
  11. package/dist/client/assets/index-QV-zN0V8.css +1 -0
  12. package/dist/client/index.html +2 -2
  13. package/dist/fallback-CXCCKHBA.js +56 -0
  14. package/dist/flow-serve-LFILD3EV.js +19 -0
  15. package/dist/{generate-N22QOXUF.js → generate-3R7POT7L.js} +4 -5
  16. package/dist/harness/default/v0.1.0/gates/all-acs-passing.yaml +1 -0
  17. package/dist/harness/default/v0.1.0/gates/has-spec-file.yaml +1 -0
  18. package/dist/harness/default/v0.1.1/gates/all-acs-passing.yaml +1 -0
  19. package/dist/harness/default/v0.1.1/gates/has-spec-file.yaml +1 -0
  20. package/dist/harness/default/v0.1.2/gates/all-acs-passing.yaml +1 -0
  21. package/dist/harness/default/v0.1.2/gates/has-spec-file.yaml +1 -0
  22. package/dist/harness/default/v0.1.3/gates/all-acs-passing.yaml +1 -0
  23. package/dist/harness/default/v0.1.3/gates/has-spec-file.yaml +1 -0
  24. package/dist/harness/default/v0.2.0/executors/registry.yaml +17 -0
  25. package/dist/harness/default/v0.2.0/flows/flow-main.yaml +84 -4
  26. package/dist/harness/default/v0.2.0/gates/code-reviewed.yaml +1 -0
  27. package/dist/harness/default/v0.2.0/gates/human-approved.yaml +4 -3
  28. package/dist/harness/default/v0.2.0/gates/security-clear.yaml +1 -0
  29. package/dist/harness/default/v0.2.0/gates/spec-approved.yaml +3 -3
  30. package/dist/{health-record-YDVXEVLR.js → health-record-JO2ZTIMR.js} +2 -2
  31. package/dist/index.js +2237 -1104
  32. package/dist/{push-5JEYSXBY.js → push-2ZCQSOHF.js} +37 -49
  33. package/dist/server-WUYVNSH7.js +677 -0
  34. package/dist/service-SVEAXQBX.js +28 -0
  35. package/dist/service-TOBY3OHO.js +22 -0
  36. package/dist/service-USTAY5E3.js +62 -0
  37. package/dist/{session-log-WTQ5JBEN.js → session-log-X2Q4XKQN.js} +6 -2
  38. package/dist/specs-CQRB7LPA.js +21 -0
  39. package/dist/sync-LIVPQXEW.js +21 -0
  40. package/package.json +1 -1
  41. package/dist/chunk-4QDEU6KP.js +0 -2765
  42. package/dist/chunk-BTPFUKHG.js +0 -275
  43. package/dist/chunk-EDD55PWL.js +0 -119
  44. package/dist/chunk-ELBTIPYN.js +0 -256
  45. package/dist/chunk-IEFSLCJL.js +0 -837
  46. package/dist/chunk-MSF44WWE.js +0 -443
  47. package/dist/chunk-QIVKP3EY.js +0 -362
  48. package/dist/client/assets/index-BuABgOyz.js +0 -232
  49. package/dist/client/assets/index-CpseCZh9.css +0 -1
  50. package/dist/fallback-UXSZ4LNR.js +0 -47
  51. package/dist/flow-serve-MTB6KZMR.js +0 -19
  52. package/dist/focus-sync-3D3XWCTI.js +0 -17
  53. package/dist/server-FUP3APZA.js +0 -415
  54. package/dist/service-OGF7BMCQ.js +0 -21
  55. package/dist/sitrep-DJXTP3JO.js +0 -16
@@ -1,362 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- validate
4
- } from "./chunk-IEFSLCJL.js";
5
- import {
6
- GateChecker,
7
- writeFocusWithRecommendations
8
- } from "./chunk-ELBTIPYN.js";
9
- import {
10
- resolveActiveFlow,
11
- resolveAgentDirection
12
- } from "./chunk-MSF44WWE.js";
13
- import {
14
- createWorkspaceBoundary,
15
- generateAdapters,
16
- loadWorkflow,
17
- writeWorkflow
18
- } from "./chunk-4QDEU6KP.js";
19
- import {
20
- logEntry
21
- } from "./chunk-BKAUN5QH.js";
22
- import {
23
- getLetraDir2 as getLetraDir
24
- } from "./chunk-6HSUVCTR.js";
25
-
26
- // src/domain-operations/service.ts
27
- import { existsSync, readFileSync, renameSync, writeFileSync } from "fs";
28
- import { join, resolve } from "path";
29
- function audit(root, action, direction, input) {
30
- return logEntry(root, action, input.reason, {
31
- itemId: input.itemId,
32
- acId: input.acId,
33
- details: {
34
- adapter: "codex",
35
- by: input.actor ?? "agent:codex",
36
- revision: direction.revision,
37
- outcome: input.outcome,
38
- reasonCode: input.reasonCode,
39
- ...input.details
40
- }
41
- });
42
- }
43
- function result(direction, entryId, outcome, reasonCode, reason, nextDirection = direction, extra = {}) {
44
- return {
45
- outcome,
46
- auditId: entryId,
47
- beforeRevision: direction.revision,
48
- afterRevision: nextDirection.revision,
49
- reasonCode,
50
- reason,
51
- nextDirection,
52
- ...extra
53
- };
54
- }
55
- function rejected(root, direction, reasonCode, reason, context, subject) {
56
- const entry = audit(root, "agent_operation_rejected", direction, {
57
- outcome: "rejected",
58
- reasonCode,
59
- reason,
60
- actor: context.actor,
61
- itemId: subject.itemId,
62
- acId: subject.acId,
63
- details: { operation: subject.operation }
64
- });
65
- return result(direction, entry.id, "rejected", reasonCode, reason);
66
- }
67
- function checkRevision(root, direction, context, subject) {
68
- if (context.expectedRevision === direction.revision) return null;
69
- return rejected(
70
- root,
71
- direction,
72
- "DIRECTION_STALE",
73
- "A dire\xE7\xE3o mudou desde a \xFAltima consulta. Consulte get_direction e tente novamente.",
74
- context,
75
- subject
76
- );
77
- }
78
- function normalizeAcId(value) {
79
- const match = value.trim().match(/^AC[\s-]?(\d+(?:\.\d+)*)$/i);
80
- return match ? `AC${match[1]}` : value.trim().toUpperCase();
81
- }
82
- function markPendingAc(content, acId) {
83
- const lines = content.split("\n");
84
- const expected = normalizeAcId(acId);
85
- const index = lines.findIndex((line) => {
86
- if (!/^\s*-\s*\[ \]\s*\*\*/.test(line)) return false;
87
- const label = line.match(/\*\*([^*]+)\*\*/)?.[1] ?? "";
88
- const id = label.match(/\bAC[\s-]?(\d+(?:\.\d+)*)\b/i);
89
- return id ? `AC${id[1]}` === expected : false;
90
- });
91
- if (index < 0) return null;
92
- lines[index] = lines[index].replace(/\[ \]/, "[x]");
93
- return lines.join("\n");
94
- }
95
- async function runValidationOperation(root, context) {
96
- const workspaceRoot = createWorkspaceBoundary(resolve(root)).root;
97
- const before = resolveAgentDirection(workspaceRoot);
98
- const stale = checkRevision(workspaceRoot, before, context, { operation: "validate" });
99
- if (stale) return stale;
100
- const validation = await validate(workspaceRoot, {
101
- format: "silent",
102
- exit: false,
103
- log: false
104
- });
105
- const after = resolveAgentDirection(workspaceRoot);
106
- const entry = audit(workspaceRoot, "agent_validation_run", before, {
107
- outcome: validation.failed === 0 ? "accepted" : "rejected",
108
- reasonCode: validation.failed === 0 ? "VALIDATION_COMPLETED" : "VALIDATION_FAILED",
109
- reason: context.reason,
110
- actor: context.actor,
111
- itemId: before.item?.id,
112
- details: { validation }
113
- });
114
- return result(
115
- before,
116
- entry.id,
117
- validation.failed === 0 ? "accepted" : "rejected",
118
- validation.failed === 0 ? "VALIDATION_COMPLETED" : "VALIDATION_FAILED",
119
- context.reason,
120
- after,
121
- { validation }
122
- );
123
- }
124
- function completeAcOperation(root, input) {
125
- const boundary = createWorkspaceBoundary(resolve(root));
126
- const workspaceRoot = boundary.root;
127
- const before = resolveAgentDirection(workspaceRoot);
128
- const subject = { itemId: before.item?.id, acId: input.acId, operation: "complete_ac" };
129
- const stale = checkRevision(workspaceRoot, before, input, subject);
130
- if (stale) return stale;
131
- const evidence = input.evidence.map((item) => item.trim()).filter(Boolean);
132
- if (evidence.length === 0) {
133
- return rejected(
134
- workspaceRoot,
135
- before,
136
- "REGRESSION_EVIDENCE_REQUIRED",
137
- "\xC9 obrigat\xF3ria ao menos uma evid\xEAncia verific\xE1vel de regress\xE3o.",
138
- input,
139
- subject
140
- );
141
- }
142
- const requestedAc = normalizeAcId(input.acId);
143
- if (!before.pendingAC || normalizeAcId(before.pendingAC.id) !== requestedAc) {
144
- return rejected(
145
- workspaceRoot,
146
- before,
147
- "AC_NOT_CURRENT",
148
- `O AC solicitado n\xE3o \xE9 o crit\xE9rio pendente vigente (${before.pendingAC?.id ?? "nenhum"}).`,
149
- input,
150
- subject
151
- );
152
- }
153
- const spec = before.item?.spec;
154
- if (!spec || !/^[a-zA-Z0-9._-]+$/.test(spec)) {
155
- return rejected(
156
- workspaceRoot,
157
- before,
158
- "ACTIVE_SPEC_REQUIRED",
159
- "O item vigente n\xE3o possui uma spec v\xE1lida vinculada.",
160
- input,
161
- subject
162
- );
163
- }
164
- const specDir = join(getLetraDir(workspaceRoot), "specs", spec);
165
- const specPath = boundary.assertPath(join(specDir, "spec.md"));
166
- if (!existsSync(specPath)) {
167
- return rejected(
168
- workspaceRoot,
169
- before,
170
- "ACTIVE_SPEC_REQUIRED",
171
- "A spec vigente n\xE3o foi encontrada no workspace.",
172
- input,
173
- subject
174
- );
175
- }
176
- const updatedSpec = markPendingAc(readFileSync(specPath, "utf-8"), requestedAc);
177
- if (!updatedSpec) {
178
- return rejected(
179
- workspaceRoot,
180
- before,
181
- "AC_NOT_PENDING",
182
- "O AC solicitado n\xE3o est\xE1 pendente na spec vigente.",
183
- input,
184
- subject
185
- );
186
- }
187
- const acceptancePath = boundary.assertPath(join(specDir, "acceptance.md"));
188
- const updatedAcceptance = existsSync(acceptancePath) ? markPendingAc(readFileSync(acceptancePath, "utf-8"), requestedAc) : null;
189
- const specTmp = `${specPath}.tmp`;
190
- writeFileSync(specTmp, updatedSpec, "utf-8");
191
- renameSync(specTmp, specPath);
192
- if (updatedAcceptance) {
193
- const acceptanceTmp = `${acceptancePath}.tmp`;
194
- writeFileSync(acceptanceTmp, updatedAcceptance, "utf-8");
195
- renameSync(acceptanceTmp, acceptancePath);
196
- }
197
- const workflow = loadWorkflow(workspaceRoot);
198
- if (workflow?.tools?.length) {
199
- generateAdapters(workspaceRoot, workflow.tools, {
200
- source: "flow-ac",
201
- quiet: true,
202
- confineWrites: true
203
- });
204
- }
205
- const after = resolveAgentDirection(workspaceRoot);
206
- const entry = audit(workspaceRoot, "agent_ac_completion_requested", before, {
207
- outcome: "accepted",
208
- reasonCode: "AC_COMPLETED",
209
- reason: input.reason,
210
- actor: input.actor,
211
- itemId: before.item?.id,
212
- acId: requestedAc,
213
- details: { spec, evidence, afterRevision: after.revision }
214
- });
215
- return result(before, entry.id, "accepted", "AC_COMPLETED", input.reason, after);
216
- }
217
- async function requestTransitionOperation(root, input) {
218
- const workspaceRoot = createWorkspaceBoundary(resolve(root)).root;
219
- const before = resolveAgentDirection(workspaceRoot);
220
- const subject = { itemId: input.itemId, operation: "request_transition" };
221
- const stale = checkRevision(workspaceRoot, before, input, subject);
222
- if (stale) return stale;
223
- if (!before.item || before.item.id !== input.itemId) {
224
- return rejected(
225
- workspaceRoot,
226
- before,
227
- "ITEM_NOT_CURRENT",
228
- "A transi\xE7\xE3o somente pode ser solicitada para o item vigente.",
229
- input,
230
- subject
231
- );
232
- }
233
- if (before.pendingAC) {
234
- return rejected(
235
- workspaceRoot,
236
- before,
237
- "PENDING_ACCEPTANCE_CRITERIA",
238
- `O item ainda possui o crit\xE9rio pendente ${before.pendingAC.id}.`,
239
- input,
240
- subject
241
- );
242
- }
243
- const workflow = loadWorkflow(workspaceRoot);
244
- const item = workflow?.items.find((candidate) => candidate.id === input.itemId);
245
- const target = workflow?.stages.find((stage) => stage.id === input.targetStageId);
246
- if (!workflow || !item || !target) {
247
- return rejected(
248
- workspaceRoot,
249
- before,
250
- "INVALID_TRANSITION",
251
- "O item ou est\xE1gio de destino n\xE3o existe no workflow vigente.",
252
- input,
253
- subject
254
- );
255
- }
256
- if (item.stage === target.id) {
257
- return rejected(
258
- workspaceRoot,
259
- before,
260
- "INVALID_TRANSITION",
261
- "O item j\xE1 est\xE1 no est\xE1gio solicitado.",
262
- input,
263
- subject
264
- );
265
- }
266
- if (before.allowedStageIds.length > 0 && !before.allowedStageIds.includes(target.id)) {
267
- return rejected(
268
- workspaceRoot,
269
- before,
270
- "STAGE_NOT_ALLOWED",
271
- "O papel vigente n\xE3o permite transi\xE7\xE3o para o est\xE1gio solicitado.",
272
- input,
273
- subject
274
- );
275
- }
276
- const activeFlow = resolveActiveFlow(workspaceRoot).flow;
277
- const sourceDefinition = activeFlow?.stages.find((stage) => stage.id === item.stage);
278
- const targetDefinition = activeFlow?.stages.find((stage) => stage.id === target.id);
279
- const blockingGate = [sourceDefinition?.gate, targetDefinition?.gate].find(
280
- (gate) => gate?.blocking
281
- );
282
- if (blockingGate) {
283
- const checker = new GateChecker(workspaceRoot);
284
- const gateResult = checker.check(blockingGate.id, item);
285
- if (blockingGate.type === "human") {
286
- const gateHint = targetDefinition?.activity?.gate;
287
- const reviewHint = targetDefinition?.activity?.review;
288
- const enriched = {
289
- ...before,
290
- allowedStageIds: targetDefinition ? [...new Set(targetDefinition.roles.flatMap((role) => role.allowedStages))] : before.allowedStageIds,
291
- prohibitions: [...gateHint?.mustNotDo ?? reviewHint?.mustNotDo ?? []],
292
- requiredEvidence: gateHint?.evidence ? [gateHint.evidence] : []
293
- };
294
- enriched.pendingAC = void 0;
295
- const entry2 = audit(workspaceRoot, "agent_transition_requested", before, {
296
- outcome: "approval-required",
297
- reasonCode: "HUMAN_APPROVAL_REQUIRED",
298
- reason: `O gate "${blockingGate.name}" exige decis\xE3o humana expl\xEDcita.`,
299
- actor: input.actor,
300
- itemId: item.id,
301
- details: { from: item.stage, to: target.id, gateId: blockingGate.id }
302
- });
303
- return result(
304
- before,
305
- entry2.id,
306
- "approval-required",
307
- "HUMAN_APPROVAL_REQUIRED",
308
- `O gate "${blockingGate.name}" exige decis\xE3o humana expl\xEDcita.`,
309
- enriched
310
- );
311
- }
312
- if (!gateResult.allowed) {
313
- return rejected(
314
- workspaceRoot,
315
- before,
316
- "BLOCKING_GATE",
317
- gateResult.reason ?? `O gate "${blockingGate.name}" deve ser satisfeito antes da transi\xE7\xE3o.`,
318
- input,
319
- subject
320
- );
321
- }
322
- }
323
- const from = item.stage;
324
- item.stage = target.id;
325
- workflow.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
326
- const writeResult = await writeWorkflow(workspaceRoot, {
327
- workflow,
328
- source: "flow-move",
329
- primaryItemId: item.id,
330
- skipSitrep: true,
331
- skipLog: true,
332
- quiet: true,
333
- confineAdapterWrites: true
334
- });
335
- if (!writeResult.ok) {
336
- return rejected(
337
- workspaceRoot,
338
- before,
339
- "TRANSITION_WRITE_FAILED",
340
- writeResult.error ?? "A persist\xEAncia da transi\xE7\xE3o falhou.",
341
- input,
342
- subject
343
- );
344
- }
345
- if (item.spec) writeFocusWithRecommendations(workspaceRoot, item.spec, item.id);
346
- const after = resolveAgentDirection(workspaceRoot);
347
- const entry = audit(workspaceRoot, "agent_transition_requested", before, {
348
- outcome: "accepted",
349
- reasonCode: "TRANSITION_COMPLETED",
350
- reason: input.reason,
351
- actor: input.actor,
352
- itemId: item.id,
353
- details: { from, to: target.id, afterRevision: after.revision }
354
- });
355
- return result(before, entry.id, "accepted", "TRANSITION_COMPLETED", input.reason, after);
356
- }
357
-
358
- export {
359
- runValidationOperation,
360
- completeAcOperation,
361
- requestTransitionOperation
362
- };