@letra-ai/cli 0.6.2 → 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.
- package/dist/chunk-2GRNAFBQ.js +5305 -0
- package/dist/{chunk-MJ2QXNH6.js → chunk-42RST74I.js} +1 -1
- package/dist/chunk-HC24XMPZ.js +269 -0
- package/dist/chunk-LUPN3TRC.js +554 -0
- package/dist/{chunk-URUC6ZZP.js → chunk-MUCIMQAU.js} +1735 -861
- package/dist/chunk-POGWTSEA.js +125 -0
- package/dist/chunk-TNF7XTFG.js +6178 -0
- package/dist/{chunk-BKAUN5QH.js → chunk-UMC5PDL2.js} +227 -33
- package/dist/{chunk-6HSUVCTR.js → chunk-YAQ2TKSK.js} +82 -30
- package/dist/client/assets/index-C-6kWNFi.js +232 -0
- package/dist/client/assets/index-QV-zN0V8.css +1 -0
- package/dist/client/index.html +2 -2
- package/dist/fallback-CXCCKHBA.js +56 -0
- package/dist/flow-serve-LFILD3EV.js +19 -0
- package/dist/{generate-UPFERQMD.js → generate-3R7POT7L.js} +4 -5
- package/dist/harness/default/v0.1.0/gates/all-acs-passing.yaml +1 -0
- package/dist/harness/default/v0.1.0/gates/has-spec-file.yaml +1 -0
- package/dist/harness/default/v0.1.1/gates/all-acs-passing.yaml +1 -0
- package/dist/harness/default/v0.1.1/gates/has-spec-file.yaml +1 -0
- package/dist/harness/default/v0.1.2/gates/all-acs-passing.yaml +1 -0
- package/dist/harness/default/v0.1.2/gates/has-spec-file.yaml +1 -0
- package/dist/harness/default/v0.1.3/gates/all-acs-passing.yaml +1 -0
- package/dist/harness/default/v0.1.3/gates/has-spec-file.yaml +1 -0
- package/dist/harness/default/v0.2.0/executors/registry.yaml +17 -0
- package/dist/harness/default/v0.2.0/flows/flow-main.yaml +81 -3
- package/dist/harness/default/v0.2.0/gates/code-reviewed.yaml +1 -0
- package/dist/harness/default/v0.2.0/gates/human-approved.yaml +1 -0
- package/dist/harness/default/v0.2.0/gates/security-clear.yaml +1 -0
- package/dist/{health-record-YDVXEVLR.js → health-record-JO2ZTIMR.js} +2 -2
- package/dist/index.js +2284 -1168
- package/dist/{push-VJRSQGUD.js → push-2ZCQSOHF.js} +37 -49
- package/dist/server-WUYVNSH7.js +677 -0
- package/dist/service-SVEAXQBX.js +28 -0
- package/dist/service-TOBY3OHO.js +22 -0
- package/dist/service-USTAY5E3.js +62 -0
- package/dist/{session-log-WTQ5JBEN.js → session-log-X2Q4XKQN.js} +6 -2
- package/dist/specs-CQRB7LPA.js +21 -0
- package/dist/sync-LIVPQXEW.js +21 -0
- package/package.json +1 -1
- package/dist/chunk-DMOLJWWW.js +0 -3321
- package/dist/chunk-EDD55PWL.js +0 -119
- package/dist/chunk-H64RC3YS.js +0 -254
- package/dist/chunk-L6YKDTAQ.js +0 -275
- package/dist/chunk-OIHMDOIN.js +0 -1326
- package/dist/client/assets/index-EyRsq1SH.css +0 -1
- package/dist/client/assets/index-WfKR7Xp6.js +0 -232
- package/dist/fallback-MQLGS4KL.js +0 -46
- package/dist/flow-serve-G5MSSB3G.js +0 -18
- package/dist/focus-sync-3D3XWCTI.js +0 -17
- package/dist/server-P6GKRWDX.js +0 -423
- package/dist/service-2JN2KI4D.js +0 -29
- package/dist/sitrep-OKNZJICV.js +0 -16
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
inspectWorkspaceIntegrity,
|
|
4
|
+
loadWorkflow,
|
|
5
|
+
readFocusFile,
|
|
6
|
+
renderAdapterFiles
|
|
7
|
+
} from "./chunk-2GRNAFBQ.js";
|
|
8
|
+
import {
|
|
9
|
+
ADAPTER_ARTIFACTS,
|
|
10
|
+
ADAPTER_REGISTRY
|
|
11
|
+
} from "./chunk-JMIC5NKB.js";
|
|
12
|
+
import {
|
|
13
|
+
logEntry
|
|
14
|
+
} from "./chunk-UMC5PDL2.js";
|
|
15
|
+
import {
|
|
16
|
+
LETRA_FOLDER,
|
|
17
|
+
clearWorkspaceCache,
|
|
18
|
+
getLetraDir2 as getLetraDir,
|
|
19
|
+
resolveWorkspaceRoot
|
|
20
|
+
} from "./chunk-YAQ2TKSK.js";
|
|
21
|
+
|
|
22
|
+
// src/commands/sync.ts
|
|
23
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2, copyFileSync, mkdirSync as mkdirSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
24
|
+
import { resolve, join as join2, dirname as dirname2 } from "path";
|
|
25
|
+
import { Command } from "commander";
|
|
26
|
+
import chalk from "chalk";
|
|
27
|
+
|
|
28
|
+
// src/adapters/regenerate.ts
|
|
29
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
30
|
+
import { dirname, join } from "path";
|
|
31
|
+
var LETRA_GENERATED_HEADER = /^#\s*(Generated by letra|Gerado por letra)\b/i;
|
|
32
|
+
function isLetraGenerated(path) {
|
|
33
|
+
try {
|
|
34
|
+
const firstLine = readFileSync(path, "utf8").split(/\r?\n/, 1)[0] ?? "";
|
|
35
|
+
return LETRA_GENERATED_HEADER.test(firstLine);
|
|
36
|
+
} catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
var INSTRUCTION_ARTIFACTS = Object.values(ADAPTER_ARTIFACTS).filter(
|
|
41
|
+
(artifact) => artifact.kind === "instructions"
|
|
42
|
+
);
|
|
43
|
+
function detectGeneratedArtifacts(locationPath) {
|
|
44
|
+
return INSTRUCTION_ARTIFACTS.filter((artifact) => {
|
|
45
|
+
const path = join(locationPath, artifact.path);
|
|
46
|
+
return existsSync(path) && isLetraGenerated(path);
|
|
47
|
+
}).map((artifact) => artifact.id);
|
|
48
|
+
}
|
|
49
|
+
function regenerateLocationAdapters(locationPath, options = {}) {
|
|
50
|
+
const configured = (options.tools ?? []).filter((tool) => tool in ADAPTER_REGISTRY);
|
|
51
|
+
const detected = new Set(detectGeneratedArtifacts(locationPath));
|
|
52
|
+
const configuredArtifacts = new Set(
|
|
53
|
+
configured.flatMap((tool) => [...ADAPTER_REGISTRY[tool].artifactIds])
|
|
54
|
+
);
|
|
55
|
+
const renderTools = new Set(configured);
|
|
56
|
+
for (const id of detected) {
|
|
57
|
+
for (const consumer of ADAPTER_ARTIFACTS[id].consumers) renderTools.add(consumer);
|
|
58
|
+
}
|
|
59
|
+
if (renderTools.size === 0) return { location: locationPath, files: [] };
|
|
60
|
+
const rendered = renderAdapterFiles(locationPath, [...renderTools], {
|
|
61
|
+
source: options.source ?? "sync",
|
|
62
|
+
quiet: true,
|
|
63
|
+
contentRoot: options.contentRoot
|
|
64
|
+
}).filter((file) => configuredArtifacts.has(file.artifactId) || detected.has(file.artifactId));
|
|
65
|
+
const files = [];
|
|
66
|
+
for (const file of rendered) {
|
|
67
|
+
const target = join(locationPath, file.path);
|
|
68
|
+
const artifact = ADAPTER_ARTIFACTS[file.artifactId];
|
|
69
|
+
const exists = existsSync(target);
|
|
70
|
+
if (exists && artifact.kind === "instructions" && !isLetraGenerated(target)) {
|
|
71
|
+
files.push({ path: target, artifactId: file.artifactId, action: "conflict" });
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (exists && readFileSync(target, "utf8") === file.content) {
|
|
75
|
+
files.push({ path: target, artifactId: file.artifactId, action: "unchanged" });
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
files.push({ path: target, artifactId: file.artifactId, action: exists ? "update" : "create" });
|
|
79
|
+
if (!options.dryRun) {
|
|
80
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
81
|
+
writeFileSync(target, file.content, "utf8");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return { location: locationPath, files };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// src/commands/sync.ts
|
|
88
|
+
async function validateFocus(focusSpec, items, stages) {
|
|
89
|
+
const warnings = [];
|
|
90
|
+
const doneIds = new Set(stages.filter((s) => s.id === "done").map((s) => s.id));
|
|
91
|
+
const matchingItems = items.filter((i) => i.spec === focusSpec);
|
|
92
|
+
if (matchingItems.length === 0) {
|
|
93
|
+
warnings.push(`Focus spec "${focusSpec}" does not match any item's spec in workflow`);
|
|
94
|
+
} else {
|
|
95
|
+
for (const item of matchingItems) {
|
|
96
|
+
if (doneIds.has(item.stage)) {
|
|
97
|
+
warnings.push(
|
|
98
|
+
`Focus spec "${focusSpec}" matches ${item.id} which is in "done" stage`
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return warnings;
|
|
104
|
+
}
|
|
105
|
+
function regenerateWorkspaceAdapters(rootPath, options = {}) {
|
|
106
|
+
const workflow = loadWorkflow(rootPath);
|
|
107
|
+
if (!workflow) {
|
|
108
|
+
const workflowFile = join2(getLetraDir(rootPath), "workflow.json");
|
|
109
|
+
return { ok: false, filesUpdated: [], conflicts: [], error: `No workflow found at ${workflowFile}` };
|
|
110
|
+
}
|
|
111
|
+
const resolution = resolveWorkspaceRoot(rootPath);
|
|
112
|
+
const locations = (workflow.locations ?? []).length ? (workflow.locations ?? []).map((location) => ({ path: location.path, adapters: location.adapters ?? [] })) : [{ path: resolution.locationPath, adapters: [] }];
|
|
113
|
+
const filesUpdated = [];
|
|
114
|
+
const conflicts = [];
|
|
115
|
+
for (const location of locations) {
|
|
116
|
+
if (!existsSync2(location.path)) continue;
|
|
117
|
+
const result = regenerateLocationAdapters(location.path, {
|
|
118
|
+
tools: [.../* @__PURE__ */ new Set([...workflow.tools ?? [], ...location.adapters])],
|
|
119
|
+
contentRoot: resolution.workspaceDir,
|
|
120
|
+
dryRun: options.dryRun
|
|
121
|
+
});
|
|
122
|
+
for (const file of result.files) {
|
|
123
|
+
if (file.action === "conflict") conflicts.push(file.path);
|
|
124
|
+
else if (file.action !== "unchanged") filesUpdated.push(file.path);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return { ok: true, filesUpdated, conflicts };
|
|
128
|
+
}
|
|
129
|
+
async function syncNow(rootPath, options) {
|
|
130
|
+
const workflow = loadWorkflow(rootPath);
|
|
131
|
+
if (!workflow) {
|
|
132
|
+
const workflowFile = join2(getLetraDir(rootPath), "workflow.json");
|
|
133
|
+
return { ok: false, filesUpdated: [], warnings: [], error: `No workflow found at ${workflowFile}` };
|
|
134
|
+
}
|
|
135
|
+
const warnings = [];
|
|
136
|
+
const focus = readFocusFile(rootPath);
|
|
137
|
+
if (focus?.specName) {
|
|
138
|
+
warnings.push(...await validateFocus(focus.specName, workflow.items, workflow.stages));
|
|
139
|
+
}
|
|
140
|
+
const result = regenerateWorkspaceAdapters(rootPath, { dryRun: options?.dryRun });
|
|
141
|
+
for (const path of result.conflicts) {
|
|
142
|
+
warnings.push(`Arquivo de autoria humana preservado (sem cabe\xE7alho do Letra): ${path}`);
|
|
143
|
+
}
|
|
144
|
+
return { ok: result.ok, filesUpdated: result.filesUpdated, warnings, error: result.error };
|
|
145
|
+
}
|
|
146
|
+
function syncMirror(rootPath, options) {
|
|
147
|
+
const root = resolve(rootPath);
|
|
148
|
+
const report = inspectWorkspaceIntegrity(root);
|
|
149
|
+
const linkPath = join2(report.resolution.locationPath, ".letra-link");
|
|
150
|
+
const canonicalWorkflow = join2(report.resolution.workspaceDir, "workflow.json");
|
|
151
|
+
const projectedWorkflow = join2(report.resolution.locationPath, LETRA_FOLDER, "workflow.json");
|
|
152
|
+
const filesUpdated = [];
|
|
153
|
+
const warnings = [];
|
|
154
|
+
const sameFile = (left, right) => existsSync2(left) && existsSync2(right) && readFileSync2(left, "utf8") === readFileSync2(right, "utf8");
|
|
155
|
+
const backup = (path) => {
|
|
156
|
+
if (!options.backup || !existsSync2(path)) return;
|
|
157
|
+
const destination = `${path}.backup`;
|
|
158
|
+
copyFileSync(path, destination);
|
|
159
|
+
filesUpdated.push(destination);
|
|
160
|
+
};
|
|
161
|
+
const copyChanged = (source, destination) => {
|
|
162
|
+
if (sameFile(source, destination)) return;
|
|
163
|
+
backup(destination);
|
|
164
|
+
mkdirSync2(dirname2(destination), { recursive: true });
|
|
165
|
+
copyFileSync(source, destination);
|
|
166
|
+
filesUpdated.push(destination);
|
|
167
|
+
};
|
|
168
|
+
const auditSync = (code) => {
|
|
169
|
+
try {
|
|
170
|
+
logEntry(report.resolution.workspaceDir, "system", `sync mirror: ${options.direction}`, {
|
|
171
|
+
details: { code, direction: options.direction, filesUpdated, dryRun: !!options.dryRun }
|
|
172
|
+
});
|
|
173
|
+
} catch {
|
|
174
|
+
warnings.push("AUDIT_DEGRADED: sincroniza\xE7\xE3o conclu\xEDda sem registro no sink de auditoria.");
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
if (report.code === "WORKSPACE_LINK_INVALID" && options.direction !== "link-to-workspace") {
|
|
178
|
+
return { ok: false, code: "WORKSPACE_LINK_INVALID", filesUpdated, warnings: ["O .letra-link \xE9 inv\xE1lido; corrija o destino antes de sincronizar dados."], report };
|
|
179
|
+
}
|
|
180
|
+
if (options.direction === "location-to-workspace" && report.drifts.some((drift) => drift.code === "WORKSPACE_PROJECTION_DRIFT")) {
|
|
181
|
+
return { ok: false, code: "WORKSPACE_SYNC_CONFLICT", filesUpdated, warnings: ["A proje\xE7\xE3o local diverge do workflow can\xF4nico; escolha uma dire\xE7\xE3o expl\xEDcita de recupera\xE7\xE3o antes de sobrescrever estado operacional."], report };
|
|
182
|
+
}
|
|
183
|
+
if (options.direction === "link-to-workspace") {
|
|
184
|
+
const target = report.resolution.workspaceDir.replace(/\\/g, "/");
|
|
185
|
+
if (report.resolution.errorCode === "WORKSPACE_LINK_INVALID" || !existsSync2(canonicalWorkflow)) {
|
|
186
|
+
return { ok: false, code: "WORKSPACE_LINK_INVALID", filesUpdated, warnings: ["N\xE3o h\xE1 workspace can\xF4nico v\xE1lido para reparar o link."], report };
|
|
187
|
+
}
|
|
188
|
+
if (!existsSync2(linkPath) || readFileSync2(linkPath, "utf8").trim().split("\n")[0] !== target) {
|
|
189
|
+
filesUpdated.push(linkPath);
|
|
190
|
+
if (options.dryRun && options.backup && existsSync2(linkPath)) filesUpdated.push(`${linkPath}.backup`);
|
|
191
|
+
if (!options.dryRun) {
|
|
192
|
+
backup(linkPath);
|
|
193
|
+
mkdirSync2(report.resolution.locationPath, { recursive: true });
|
|
194
|
+
writeFileSync2(linkPath, `${target}
|
|
195
|
+
`, "utf8");
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
clearWorkspaceCache();
|
|
199
|
+
const regenerated = regenerateWorkspaceAdapters(report.resolution.locationPath, { dryRun: options.dryRun });
|
|
200
|
+
filesUpdated.push(...regenerated.filesUpdated);
|
|
201
|
+
for (const path of regenerated.conflicts) warnings.push(`Arquivo de autoria humana preservado: ${path}`);
|
|
202
|
+
} else if (options.direction === "workspace-to-location") {
|
|
203
|
+
if (!existsSync2(canonicalWorkflow)) return { ok: false, code: "WORKSPACE_NOT_FOUND", filesUpdated, warnings: [], report };
|
|
204
|
+
if (!options.dryRun) copyChanged(canonicalWorkflow, projectedWorkflow);
|
|
205
|
+
else if (!sameFile(canonicalWorkflow, projectedWorkflow)) {
|
|
206
|
+
if (options.backup && existsSync2(projectedWorkflow)) filesUpdated.push(`${projectedWorkflow}.backup`);
|
|
207
|
+
filesUpdated.push(projectedWorkflow);
|
|
208
|
+
}
|
|
209
|
+
} else {
|
|
210
|
+
if (!existsSync2(projectedWorkflow)) return { ok: false, code: "WORKSPACE_PROJECTION_NOT_FOUND", filesUpdated, warnings: [], report };
|
|
211
|
+
if (!options.dryRun) copyChanged(projectedWorkflow, canonicalWorkflow);
|
|
212
|
+
else if (!sameFile(projectedWorkflow, canonicalWorkflow)) {
|
|
213
|
+
if (options.backup && existsSync2(canonicalWorkflow)) filesUpdated.push(`${canonicalWorkflow}.backup`);
|
|
214
|
+
filesUpdated.push(canonicalWorkflow);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
auditSync(options.direction === "link-to-workspace" ? "WORKSPACE_LINK_REPAIRED" : options.dryRun ? "WORKSPACE_MIRROR_DRY_RUN" : "WORKSPACE_MIRROR_COMPLETED");
|
|
218
|
+
return { ok: true, code: options.dryRun ? "WORKSPACE_SYNC_DRY_RUN" : "WORKSPACE_SYNCED", filesUpdated, warnings, report };
|
|
219
|
+
}
|
|
220
|
+
function sync_default() {
|
|
221
|
+
const cmd = new Command("sync").description("Sync workflow state to all adapters");
|
|
222
|
+
cmd.option("--dry-run", "Show what would be done without writing").option("--mirror <direction>", "Reconcile explicitly: workspace-to-location, location-to-workspace or link-to-workspace").option("--backup", "Back up the existing .letra-link before changing it").option("--fix", "Apply reconciliation (default behavior)").action(async (opts) => {
|
|
223
|
+
const root = resolve(process.cwd());
|
|
224
|
+
const isDryRun = !!opts.dryRun;
|
|
225
|
+
if (opts.mirror) {
|
|
226
|
+
const result2 = syncMirror(root, { direction: opts.mirror, dryRun: isDryRun, backup: opts.backup });
|
|
227
|
+
if (!result2.ok) {
|
|
228
|
+
console.log(chalk.red(`\u2717 ${result2.code}`));
|
|
229
|
+
for (const warning of result2.warnings) console.log(chalk.yellow(` \u26A0 ${warning}`));
|
|
230
|
+
process.exitCode = 2;
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
console.log(chalk.green(`\u2713 ${result2.code}`));
|
|
234
|
+
for (const file of result2.filesUpdated) console.log(` ${chalk.gray("\u2192")} ${file}`);
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
const result = await syncNow(root, { dryRun: isDryRun });
|
|
238
|
+
if (!result.ok) {
|
|
239
|
+
console.log(chalk.red(`\u2717 Sync failed: ${result.error ?? "unknown error"}`));
|
|
240
|
+
process.exit(1);
|
|
241
|
+
}
|
|
242
|
+
if (result.warnings.length > 0) {
|
|
243
|
+
for (const w of result.warnings) {
|
|
244
|
+
console.log(chalk.yellow(` \u26A0 ${w}`));
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
if (isDryRun) {
|
|
248
|
+
console.log(chalk.bold("\n\u{1F4CB} Simula\xE7\xE3o \u2014 dry-run\n"));
|
|
249
|
+
console.log(chalk.gray(" Seriam regenerados:"));
|
|
250
|
+
for (const f of result.filesUpdated) {
|
|
251
|
+
console.log(` ${chalk.gray("\u2192")} ${f}`);
|
|
252
|
+
}
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
console.log(chalk.green(result.filesUpdated.length ? "\u2713 Adapters regenerados" : "\u2713 Adapters j\xE1 atualizados"));
|
|
256
|
+
for (const f of result.filesUpdated) {
|
|
257
|
+
console.log(` ${chalk.gray("\u2192")} ${f}`);
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
return cmd;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export {
|
|
264
|
+
validateFocus,
|
|
265
|
+
regenerateWorkspaceAdapters,
|
|
266
|
+
syncNow,
|
|
267
|
+
syncMirror,
|
|
268
|
+
sync_default
|
|
269
|
+
};
|