agent-lyra 0.6.2 → 0.6.3
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/LICENSE +21 -21
- package/README.md +435 -435
- package/bin/agent-lyra.js +49 -49
- package/bin/lyra-oss-preview.js +16 -14
- package/package.json +60 -60
- package/src/app-builder/export.js +109 -109
- package/src/app-builder/gateway.js +62 -62
- package/src/app-builder/init.js +52 -52
- package/src/app-builder/manifest-contract.js +46 -46
- package/src/app-builder/native-adapter.js +29 -29
- package/src/app-builder/preview.js +22 -22
- package/src/app-builder/publish.js +14 -14
- package/src/app-builder/saved-app.js +70 -70
- package/src/app-builder/saved-preview-browser.js +33 -33
- package/src/app-builder/saved-preview.html +24 -24
- package/src/app-builder/saved-preview.js +61 -61
- package/src/app-builder/support-manifest.js +50 -50
- package/src/app-builder/support-template/manifest.json +55 -55
- package/src/app-builder/support-template/support-preview.html +56 -56
- package/src/app-builder/support-template/support-preview.js +37 -37
- package/src/app-builder/support-template/support-preview.mjs +67 -67
- package/src/app-builder/support-template/support-workflow.mjs +36 -36
- package/src/app-builder/use.js +37 -37
- package/src/app-builder/validate.js +21 -21
- package/src/app-builder/value-schema.js +37 -37
- package/src/catalog.js +147 -147
- package/src/coding/catalog.js +56 -56
- package/src/coding/cloud-catalog.js +64 -44
- package/src/coding/detect-stack.mjs +110 -110
- package/src/coding/export.js +130 -130
- package/src/coding/setup.js +175 -174
- package/src/coding/skills/lyra-android/SKILL.md +37 -0
- package/src/coding/skills/lyra-angular/SKILL.md +37 -0
- package/src/coding/skills/lyra-cucumber/SKILL.md +37 -0
- package/src/coding/skills/lyra-dbt/SKILL.md +37 -0
- package/src/coding/skills/lyra-django/SKILL.md +37 -0
- package/src/coding/skills/lyra-docker/SKILL.md +37 -0
- package/src/coding/skills/lyra-dotnet/SKILL.md +37 -0
- package/src/coding/skills/lyra-express/SKILL.md +37 -0
- package/src/coding/skills/lyra-fastapi/SKILL.md +37 -0
- package/src/coding/skills/lyra-flutter/SKILL.md +37 -0
- package/src/coding/skills/lyra-github-actions/SKILL.md +37 -0
- package/src/coding/skills/lyra-gitlab-ci/SKILL.md +37 -0
- package/src/coding/skills/lyra-go/SKILL.md +37 -0
- package/src/coding/skills/lyra-ios/SKILL.md +37 -0
- package/src/coding/skills/lyra-kubernetes/SKILL.md +37 -0
- package/src/coding/skills/lyra-mongodb/SKILL.md +37 -0
- package/src/coding/skills/lyra-mysql/SKILL.md +37 -0
- package/src/coding/skills/lyra-nextjs/SKILL.md +37 -0
- package/src/coding/skills/lyra-node/SKILL.md +37 -0
- package/src/coding/skills/lyra-playwright/SKILL.md +37 -0
- package/src/coding/skills/lyra-postgresql/SKILL.md +37 -0
- package/src/coding/skills/lyra-python/SKILL.md +37 -0
- package/src/coding/skills/lyra-react/SKILL.md +37 -0
- package/src/coding/skills/lyra-react-native/SKILL.md +37 -0
- package/src/coding/skills/lyra-redis/SKILL.md +37 -0
- package/src/coding/skills/lyra-rust/SKILL.md +37 -0
- package/src/coding/skills/lyra-spark/SKILL.md +37 -0
- package/src/coding/skills/lyra-spring-boot/SKILL.md +37 -0
- package/src/coding/skills/lyra-svelte/SKILL.md +37 -0
- package/src/coding/skills/lyra-terraform/SKILL.md +37 -0
- package/src/coding/skills/lyra-typescript/SKILL.md +37 -0
- package/src/coding/skills/lyra-vue/SKILL.md +37 -0
- package/src/gated/hostedAgents.js +56 -56
- package/src/gated/index.d.ts +25 -25
- package/src/gated/index.js +5 -5
- package/src/index.d.ts +2 -2
- package/src/index.js +2 -2
- package/src/init.js +965 -965
- package/src/memory/cli.js +21 -21
- package/src/memory/contract.json +28 -28
- package/src/memory/index.d.ts +49 -49
- package/src/memory/index.js +259 -259
- package/src/memory/lifecycle.js +29 -29
- package/src/memory/local-cli.js +34 -34
- package/src/memory/proposals.js +84 -84
- package/src/memory/skills-cli.js +26 -26
- package/src/memory/sync.js +89 -89
- package/src/memory/validation.js +25 -25
- package/src/onboardingAgents.js +532 -532
- package/src/promptTemplates.js +178 -178
- package/src/runtime/contracts.d.ts +47 -47
- package/src/runtime/local-cli.js +160 -160
- package/src/runtime/mcp-stdio.js +111 -111
- package/src/runtime/orchestration.js +59 -59
- package/src/runtime/run-agent.js +43 -43
- package/src/standalone/index.d.ts +45 -45
- package/src/standalone/index.js +13 -13
- package/src/standalone/init.js +12 -0
- package/src/standalone/orchestration.js +6 -6
- package/src/standalone/rag.js +113 -113
- package/src/studio/agent-ui.css +43 -43
- package/src/studio/agent-ui.js +32 -32
- package/src/studio/browser.js +331 -331
- package/src/studio/export.js +80 -80
- package/src/studio/index.html +37 -37
- package/src/studio/memory-actions.js +37 -37
- package/src/studio/memory-panel.js +200 -200
- package/src/studio/project.js +216 -216
- package/src/studio/pull-agent.js +72 -72
- package/src/studio/push.js +54 -54
- package/src/studio/python-agent.js +47 -47
- package/src/studio/python-agent.py +25 -25
- package/src/studio/server.js +143 -143
- package/src/studio/session.js +83 -83
- package/src/studio/studio.css +10 -10
- package/src/studio/sync.js +42 -42
- package/src/studio/workflow-sync.js +157 -157
package/src/init.js
CHANGED
|
@@ -1,966 +1,966 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import process from "node:process";
|
|
4
|
-
import readline from "node:readline/promises";
|
|
5
|
-
import { emitKeypressEvents } from "node:readline";
|
|
6
|
-
import { stdin as input, stdout as output } from "node:process";
|
|
7
|
-
import { GATED_DOMAINS, STANDALONE_DOMAINS, getDomainCatalog } from "./catalog.js";
|
|
8
|
-
|
|
9
|
-
import { prepareCodingStack, recommendCodingStacks, selectCodingStack } from "./coding/setup.js";
|
|
10
|
-
|
|
11
|
-
const DEFAULT_API_BASE_URL = "https://www.agentlyra.in";
|
|
12
|
-
|
|
13
|
-
function parseArgs(argv = process.argv.slice(2)) {
|
|
14
|
-
const args = { _: [] };
|
|
15
|
-
|
|
16
|
-
for (let index = 0; index < argv.length; index += 1) {
|
|
17
|
-
const token = argv[index];
|
|
18
|
-
if (!token.startsWith("--")) {
|
|
19
|
-
args._.push(token);
|
|
20
|
-
continue;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const [flag, inlineValue] = token.split("=", 2);
|
|
24
|
-
const key = flag.slice(2);
|
|
25
|
-
const next = argv[index + 1];
|
|
26
|
-
|
|
27
|
-
if (inlineValue !== undefined) {
|
|
28
|
-
args[key] = inlineValue;
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (!next || next.startsWith("--")) {
|
|
33
|
-
args[key] = true;
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
args[key] = next;
|
|
38
|
-
index += 1;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return args;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function printUsage() {
|
|
45
|
-
output.write(`Usage:\n agent-lyra init\n lyra init\n\nOptions:\n --mode standalone|gated\n --domains coding,finance\n --stack mern,playwright\n --detect\n --api-key <key>\n --api-base-url <url>\n --dir <target-directory>\n --force\n`);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function printWelcomeBanner() {
|
|
49
|
-
output.write([
|
|
50
|
-
"",
|
|
51
|
-
" _ _ _ ",
|
|
52
|
-
" / \\\ __ _ ___ _ __ | |_ | | _ _ _ __ __ _ ",
|
|
53
|
-
" / _ \\\ / _` |/ _ \\ '_ \\| __| | | | | | | '__/ _` |",
|
|
54
|
-
" / ___ \\\ (_| | __/ | | | |_ | |__| |_| | | | (_| |",
|
|
55
|
-
"/_/ \\\_\\__, |\\___|_| |_|\\__| |_____\\__, |_| \\__,_|",
|
|
56
|
-
" |___/ |___/ ",
|
|
57
|
-
"",
|
|
58
|
-
" Local agents when you want control. Hosted agents when you want lift.",
|
|
59
|
-
"",
|
|
60
|
-
].join("\n"));
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
async function askQuestion(rl, message, { secret = false } = {}) {
|
|
64
|
-
if (!secret) {
|
|
65
|
-
return (await rl.question(message)).trim();
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const original = input.isTTY ? input.isTTY : false;
|
|
69
|
-
if (input.isTTY) {
|
|
70
|
-
input.setRawMode?.(true);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
output.write(message);
|
|
74
|
-
let buffer = "";
|
|
75
|
-
|
|
76
|
-
return await new Promise((resolve) => {
|
|
77
|
-
const onData = (chunk) => {
|
|
78
|
-
const value = String(chunk);
|
|
79
|
-
if (value === "\r" || value === "\n") {
|
|
80
|
-
input.off("data", onData);
|
|
81
|
-
output.write("\n");
|
|
82
|
-
if (input.isTTY && original) {
|
|
83
|
-
input.setRawMode?.(false);
|
|
84
|
-
}
|
|
85
|
-
resolve(buffer.trim());
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (value === "\u0003") {
|
|
90
|
-
process.exitCode = 1;
|
|
91
|
-
input.off("data", onData);
|
|
92
|
-
if (input.isTTY && original) {
|
|
93
|
-
input.setRawMode?.(false);
|
|
94
|
-
}
|
|
95
|
-
throw new Error("Cancelled.");
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (value === "\u007f") {
|
|
99
|
-
buffer = buffer.slice(0, -1);
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
buffer += value;
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
input.on("data", onData);
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
async function chooseMode(rl, currentMode) {
|
|
111
|
-
if (currentMode === "standalone" || currentMode === "gated") {
|
|
112
|
-
return currentMode;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
while (true) {
|
|
116
|
-
const answer = (await rl.question("Choose setup flow: [1] standalone [2] gated: ")).trim().toLowerCase();
|
|
117
|
-
if (answer === "1" || answer === "standalone" || answer === "s") {
|
|
118
|
-
return "standalone";
|
|
119
|
-
}
|
|
120
|
-
if (answer === "2" || answer === "gated" || answer === "g") {
|
|
121
|
-
return "gated";
|
|
122
|
-
}
|
|
123
|
-
output.write("Enter 1 for standalone or 2 for gated.\n");
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
async function chooseFlowGroup(rl) {
|
|
128
|
-
while (true) {
|
|
129
|
-
const answer = (await rl.question("Choose pack type: [1] Professional [2] Everyday: ")).trim().toLowerCase();
|
|
130
|
-
if (answer === "1" || answer === "professional" || answer === "p") {
|
|
131
|
-
return "professional";
|
|
132
|
-
}
|
|
133
|
-
if (answer === "2" || answer === "everyday" || answer === "e") {
|
|
134
|
-
return "everyday";
|
|
135
|
-
}
|
|
136
|
-
output.write("Enter 1 for Professional or 2 for Everyday.\n");
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function clearScreen() {
|
|
141
|
-
output.write("\u001Bc");
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function renderMultiSelect(title, options, cursor, selected) {
|
|
145
|
-
clearScreen();
|
|
146
|
-
output.write(`${title}\n`);
|
|
147
|
-
output.write("Use ↑/↓ to move, Space to toggle, Enter to confirm.\n\n");
|
|
148
|
-
|
|
149
|
-
options.forEach((option, index) => {
|
|
150
|
-
const marker = selected.has(option.id) ? "[x]" : "[ ]";
|
|
151
|
-
const prefix = index === cursor ? ">" : " ";
|
|
152
|
-
output.write(`${prefix} ${marker} ${option.label}\n`);
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function renderGroupedMultiSelect(title, groups, cursor, selected) {
|
|
157
|
-
const flattened = groups.flatMap((group) => group.options);
|
|
158
|
-
clearScreen();
|
|
159
|
-
output.write(`${title}\n`);
|
|
160
|
-
output.write("Use ↑/↓ to move, Space to toggle, Enter to confirm.\n\n");
|
|
161
|
-
|
|
162
|
-
let running = 0;
|
|
163
|
-
groups.forEach((group) => {
|
|
164
|
-
output.write(`${group.label}\n`);
|
|
165
|
-
group.options.forEach((option) => {
|
|
166
|
-
const marker = selected.has(option.id) ? "[x]" : "[ ]";
|
|
167
|
-
const prefix = running === cursor ? ">" : " ";
|
|
168
|
-
output.write(`${prefix} ${marker} ${option.label}${option.hint ? ` - ${option.hint}` : ""}\n`);
|
|
169
|
-
running += 1;
|
|
170
|
-
});
|
|
171
|
-
output.write("\n");
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
if (flattened.length === 0) {
|
|
175
|
-
output.write("No options available.\n");
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
async function selectManyGrouped(rl, title, groups, presetIds = []) {
|
|
180
|
-
const options = groups.flatMap((group) => group.options);
|
|
181
|
-
|
|
182
|
-
if (!input.isTTY || !output.isTTY) {
|
|
183
|
-
const answer = (await rl.question(`${title} (comma-separated ids): `)).trim();
|
|
184
|
-
const selectedIds = answer
|
|
185
|
-
? answer.split(",").map((value) => value.trim()).filter(Boolean)
|
|
186
|
-
: presetIds;
|
|
187
|
-
return options.filter((option) => selectedIds.includes(option.id));
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
emitKeypressEvents(input);
|
|
191
|
-
input.setRawMode?.(true);
|
|
192
|
-
input.resume();
|
|
193
|
-
|
|
194
|
-
const selected = new Set(presetIds);
|
|
195
|
-
let cursor = 0;
|
|
196
|
-
renderGroupedMultiSelect(title, groups, cursor, selected);
|
|
197
|
-
|
|
198
|
-
return await new Promise((resolve, reject) => {
|
|
199
|
-
const cleanup = () => {
|
|
200
|
-
input.setRawMode?.(false);
|
|
201
|
-
input.removeListener("keypress", onKeypress);
|
|
202
|
-
output.write("\n");
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
const onKeypress = (_, key) => {
|
|
206
|
-
if (key?.name === "up") {
|
|
207
|
-
cursor = cursor === 0 ? options.length - 1 : cursor - 1;
|
|
208
|
-
renderGroupedMultiSelect(title, groups, cursor, selected);
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
if (key?.name === "down") {
|
|
212
|
-
cursor = cursor === options.length - 1 ? 0 : cursor + 1;
|
|
213
|
-
renderGroupedMultiSelect(title, groups, cursor, selected);
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
if (key?.name === "space") {
|
|
217
|
-
const current = options[cursor];
|
|
218
|
-
if (!current || current.disabled) {
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
if (selected.has(current.id)) {
|
|
222
|
-
selected.delete(current.id);
|
|
223
|
-
} else {
|
|
224
|
-
selected.add(current.id);
|
|
225
|
-
}
|
|
226
|
-
renderGroupedMultiSelect(title, groups, cursor, selected);
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
if (key?.name === "return") {
|
|
230
|
-
cleanup();
|
|
231
|
-
resolve(options.filter((option) => selected.has(option.id)));
|
|
232
|
-
return;
|
|
233
|
-
}
|
|
234
|
-
if (key?.ctrl && key.name === "c") {
|
|
235
|
-
cleanup();
|
|
236
|
-
reject(new Error("Cancelled."));
|
|
237
|
-
}
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
input.on("keypress", onKeypress);
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
async function askYesNo(rl, prompt, defaultValue = false) {
|
|
245
|
-
const suffix = defaultValue ? " [Y/n]: " : " [y/N]: ";
|
|
246
|
-
const answer = (await rl.question(`${prompt}${suffix}`)).trim().toLowerCase();
|
|
247
|
-
if (!answer) return defaultValue;
|
|
248
|
-
return answer === "y" || answer === "yes";
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
async function fetchUserAgentsByApiKey(apiBaseUrl, apiKey) {
|
|
252
|
-
const baseUrl = String(apiBaseUrl || DEFAULT_API_BASE_URL).replace(/\/$/, "");
|
|
253
|
-
const response = await fetch(`${baseUrl}/api/lyra-cli/agents`, {
|
|
254
|
-
method: "GET",
|
|
255
|
-
headers: {
|
|
256
|
-
Authorization: `Bearer ${apiKey}`,
|
|
257
|
-
},
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
if (!response.ok) {
|
|
261
|
-
throw new Error(`Failed to sync agents: ${response.status}`);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
const body = await response.json();
|
|
265
|
-
return Array.isArray(body?.agents) ? body.agents : [];
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
function normalizePlatformAgents(rawAgents = []) {
|
|
269
|
-
return rawAgents
|
|
270
|
-
.filter((agent) => agent && agent.name && agent.id)
|
|
271
|
-
.map((agent) => ({
|
|
272
|
-
id: `platform-${agent.id}`,
|
|
273
|
-
label: `${agent.name} (Your agent)`,
|
|
274
|
-
mode: "standalone",
|
|
275
|
-
sourceType: "platform",
|
|
276
|
-
importPayload: {
|
|
277
|
-
schemaVersion: 1,
|
|
278
|
-
type: "platform-agent",
|
|
279
|
-
id: String(agent.id),
|
|
280
|
-
slug: String(agent.slug || agent.name).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, ""),
|
|
281
|
-
name: agent.name,
|
|
282
|
-
domain: "platform-imports",
|
|
283
|
-
category: agent.category || "custom",
|
|
284
|
-
mode: "standalone",
|
|
285
|
-
description: agent.description || "",
|
|
286
|
-
icon: null,
|
|
287
|
-
skills: Array.isArray(agent.skills) ? agent.skills : [],
|
|
288
|
-
integrations: Array.isArray(agent.integrations) ? agent.integrations : [],
|
|
289
|
-
generatedFrom: "platform-sync",
|
|
290
|
-
promptTemplateId: null,
|
|
291
|
-
systemPrompt: agent.systemPrompt || "",
|
|
292
|
-
runtime: {
|
|
293
|
-
execution: "platform",
|
|
294
|
-
source: "lyra-web",
|
|
295
|
-
defaultModel: agent.defaultModel || null,
|
|
296
|
-
maxTokens: agent.maxTokens ?? null,
|
|
297
|
-
temperature: agent.temperature ?? null,
|
|
298
|
-
},
|
|
299
|
-
repoIntelligence: {
|
|
300
|
-
enabled: true,
|
|
301
|
-
requiresScan: true,
|
|
302
|
-
scanEndpoint: "/api/repositories/:id/scan",
|
|
303
|
-
pullRequestEndpoint: "/api/repositories/:id/lyra-pr",
|
|
304
|
-
contextContract: {
|
|
305
|
-
required: [
|
|
306
|
-
"repoContext",
|
|
307
|
-
"findingsAtScanTime",
|
|
308
|
-
"responsibilities",
|
|
309
|
-
"scopedPaths",
|
|
310
|
-
"confidence",
|
|
311
|
-
],
|
|
312
|
-
},
|
|
313
|
-
},
|
|
314
|
-
outputs: {
|
|
315
|
-
format: "markdown",
|
|
316
|
-
requireCitations: false,
|
|
317
|
-
},
|
|
318
|
-
},
|
|
319
|
-
}));
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
async function selectMany(rl, title, options, presetIds = []) {
|
|
323
|
-
if (!input.isTTY || !output.isTTY) {
|
|
324
|
-
const answer = (await rl.question(`${title} (comma-separated ids): `)).trim();
|
|
325
|
-
const selectedIds = answer
|
|
326
|
-
? answer.split(",").map((value) => value.trim()).filter(Boolean)
|
|
327
|
-
: presetIds;
|
|
328
|
-
return options.filter((option) => selectedIds.includes(option.id));
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
emitKeypressEvents(input);
|
|
332
|
-
input.setRawMode?.(true);
|
|
333
|
-
input.resume();
|
|
334
|
-
|
|
335
|
-
const selected = new Set(presetIds);
|
|
336
|
-
let cursor = 0;
|
|
337
|
-
renderMultiSelect(title, options, cursor, selected);
|
|
338
|
-
|
|
339
|
-
return await new Promise((resolve, reject) => {
|
|
340
|
-
const cleanup = () => {
|
|
341
|
-
input.setRawMode?.(false);
|
|
342
|
-
input.removeListener("keypress", onKeypress);
|
|
343
|
-
output.write("\n");
|
|
344
|
-
};
|
|
345
|
-
|
|
346
|
-
const onKeypress = (_, key) => {
|
|
347
|
-
if (key?.name === "up") {
|
|
348
|
-
cursor = cursor === 0 ? options.length - 1 : cursor - 1;
|
|
349
|
-
renderMultiSelect(title, options, cursor, selected);
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
if (key?.name === "down") {
|
|
353
|
-
cursor = cursor === options.length - 1 ? 0 : cursor + 1;
|
|
354
|
-
renderMultiSelect(title, options, cursor, selected);
|
|
355
|
-
return;
|
|
356
|
-
}
|
|
357
|
-
if (key?.name === "space") {
|
|
358
|
-
const current = options[cursor];
|
|
359
|
-
if (selected.has(current.id)) {
|
|
360
|
-
selected.delete(current.id);
|
|
361
|
-
} else {
|
|
362
|
-
selected.add(current.id);
|
|
363
|
-
}
|
|
364
|
-
renderMultiSelect(title, options, cursor, selected);
|
|
365
|
-
return;
|
|
366
|
-
}
|
|
367
|
-
if (key?.name === "return") {
|
|
368
|
-
cleanup();
|
|
369
|
-
resolve(options.filter((option) => selected.has(option.id)));
|
|
370
|
-
return;
|
|
371
|
-
}
|
|
372
|
-
if (key?.ctrl && key.name === "c") {
|
|
373
|
-
cleanup();
|
|
374
|
-
reject(new Error("Cancelled."));
|
|
375
|
-
}
|
|
376
|
-
};
|
|
377
|
-
|
|
378
|
-
input.on("keypress", onKeypress);
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
async function ensureEmptyOrApproved(rl, rootDir, force) {
|
|
383
|
-
try {
|
|
384
|
-
await fs.access(rootDir);
|
|
385
|
-
if (force) {
|
|
386
|
-
await fs.rm(rootDir, { recursive: true, force: true });
|
|
387
|
-
return;
|
|
388
|
-
}
|
|
389
|
-
const answer = (await rl.question(`Directory ${rootDir} exists. Overwrite Lyra files? [y/N]: `)).trim().toLowerCase();
|
|
390
|
-
if (answer !== "y" && answer !== "yes") {
|
|
391
|
-
throw new Error("Aborted by user.");
|
|
392
|
-
}
|
|
393
|
-
await fs.rm(rootDir, { recursive: true, force: true });
|
|
394
|
-
} catch (error) {
|
|
395
|
-
if (error.code === "ENOENT") {
|
|
396
|
-
return;
|
|
397
|
-
}
|
|
398
|
-
if (error.message === "Aborted by user.") {
|
|
399
|
-
throw error;
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
function buildConfig(mode, selectedDomains, apiKeyProvided) {
|
|
405
|
-
return {
|
|
406
|
-
version: 1,
|
|
407
|
-
mode,
|
|
408
|
-
domains: selectedDomains.map((domain) => domain.id),
|
|
409
|
-
createdAt: new Date().toISOString(),
|
|
410
|
-
gated: mode === "gated"
|
|
411
|
-
? {
|
|
412
|
-
apiKeySource: apiKeyProvided ? ".lyra/credentials.json" : "env:LYRA_API_KEY",
|
|
413
|
-
verticals: selectedDomains.map((domain) => domain.id),
|
|
414
|
-
}
|
|
415
|
-
: undefined,
|
|
416
|
-
domainsMetadata: selectedDomains.map((domain) => sanitizeConfigDomainEntry(domain)),
|
|
417
|
-
};
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
function sanitizeConfigDomainEntry(entry) {
|
|
421
|
-
const agentCount = Array.isArray(entry.agents) ? entry.agents.length : Number(entry.agentCount || 0);
|
|
422
|
-
return {
|
|
423
|
-
id: entry.id,
|
|
424
|
-
label: entry.label,
|
|
425
|
-
mode: entry.mode || "standalone",
|
|
426
|
-
sourceType: entry.sourceType || "catalog",
|
|
427
|
-
agentCount,
|
|
428
|
-
};
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
function buildStandaloneAgentSpec(domain, agent) {
|
|
432
|
-
return {
|
|
433
|
-
schemaVersion: 1,
|
|
434
|
-
type: "standalone-agent",
|
|
435
|
-
id: agent.id,
|
|
436
|
-
slug: agent.slug,
|
|
437
|
-
name: agent.name,
|
|
438
|
-
domain: domain.id,
|
|
439
|
-
category: agent.category,
|
|
440
|
-
mode: "standalone",
|
|
441
|
-
description: agent.description,
|
|
442
|
-
icon: agent.icon || null,
|
|
443
|
-
skills: agent.skills || [],
|
|
444
|
-
integrations: agent.requiresIntegration || [],
|
|
445
|
-
generatedFrom: agent.generatedFrom || "onboarding-catalog",
|
|
446
|
-
promptTemplateId: agent.promptTemplateId || null,
|
|
447
|
-
systemPrompt: agent.systemPrompt || "",
|
|
448
|
-
repoIntelligence: {
|
|
449
|
-
enabled: true,
|
|
450
|
-
requiresScan: Boolean(agent.runtimeHints?.requiresRepoScan),
|
|
451
|
-
scanEndpoint: agent.runtimeHints?.suggestedScanEndpoint || "/api/repositories/:id/scan",
|
|
452
|
-
pullRequestEndpoint: agent.runtimeHints?.suggestedPrEndpoint || "/api/repositories/:id/lyra-pr",
|
|
453
|
-
contextContract: {
|
|
454
|
-
required: [
|
|
455
|
-
"repoContext",
|
|
456
|
-
"findingsAtScanTime",
|
|
457
|
-
"responsibilities",
|
|
458
|
-
"scopedPaths",
|
|
459
|
-
"confidence",
|
|
460
|
-
],
|
|
461
|
-
},
|
|
462
|
-
},
|
|
463
|
-
runtime: {
|
|
464
|
-
execution: "local",
|
|
465
|
-
orchestration: "standalone",
|
|
466
|
-
ragEnabled: true,
|
|
467
|
-
},
|
|
468
|
-
outputs: {
|
|
469
|
-
format: "markdown",
|
|
470
|
-
requireCitations: Boolean((agent.skills || []).includes("url-scraper") || (agent.skills || []).includes("web-search")),
|
|
471
|
-
},
|
|
472
|
-
};
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
function buildGatedAgentSpec(domain, agent) {
|
|
476
|
-
return {
|
|
477
|
-
schemaVersion: 1,
|
|
478
|
-
type: "hosted-agent",
|
|
479
|
-
id: agent.id,
|
|
480
|
-
slug: agent.slug,
|
|
481
|
-
name: agent.name,
|
|
482
|
-
domain: domain.id,
|
|
483
|
-
category: agent.category,
|
|
484
|
-
mode: "gated",
|
|
485
|
-
description: agent.description,
|
|
486
|
-
icon: agent.icon || null,
|
|
487
|
-
skills: agent.skills || [],
|
|
488
|
-
integrations: agent.requiresIntegration || [],
|
|
489
|
-
generatedFrom: agent.generatedFrom || "gated-vertical-catalog",
|
|
490
|
-
promptTemplateId: agent.promptTemplateId || null,
|
|
491
|
-
systemPrompt: agent.systemPrompt || "",
|
|
492
|
-
repoIntelligence: {
|
|
493
|
-
enabled: true,
|
|
494
|
-
requiresScan: false,
|
|
495
|
-
scanEndpoint: "/api/repositories/:id/scan",
|
|
496
|
-
pullRequestEndpoint: "/api/repositories/:id/lyra-pr",
|
|
497
|
-
contextContract: {
|
|
498
|
-
required: [
|
|
499
|
-
"repoContext",
|
|
500
|
-
"findingsAtScanTime",
|
|
501
|
-
"responsibilities",
|
|
502
|
-
"scopedPaths",
|
|
503
|
-
"confidence",
|
|
504
|
-
],
|
|
505
|
-
},
|
|
506
|
-
},
|
|
507
|
-
hosted: {
|
|
508
|
-
provider: "lyra",
|
|
509
|
-
vertical: agent.hosted?.vertical || domain.id,
|
|
510
|
-
defaultModel: agent.hosted?.defaultModel || null,
|
|
511
|
-
endpoint: `/agents/${agent.hosted?.vertical || domain.id}/invoke`,
|
|
512
|
-
auth: {
|
|
513
|
-
strategy: "bearer",
|
|
514
|
-
credentialsFile: ".lyra/credentials.json",
|
|
515
|
-
credentialsKey: "LYRA_API_KEY",
|
|
516
|
-
},
|
|
517
|
-
},
|
|
518
|
-
outputs: {
|
|
519
|
-
format: "json",
|
|
520
|
-
includeUsage: true,
|
|
521
|
-
},
|
|
522
|
-
};
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
function buildAgentSpec(domain, mode, agent) {
|
|
526
|
-
const effectiveMode = domain.mode || mode;
|
|
527
|
-
return effectiveMode === "gated"
|
|
528
|
-
? buildGatedAgentSpec(domain, agent)
|
|
529
|
-
: buildStandaloneAgentSpec(domain, agent);
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
function toYamlValue(value, indent = 0) {
|
|
533
|
-
const pad = " ".repeat(indent);
|
|
534
|
-
if (value === null || value === undefined) {
|
|
535
|
-
return "null";
|
|
536
|
-
}
|
|
537
|
-
if (typeof value === "string") {
|
|
538
|
-
return JSON.stringify(value);
|
|
539
|
-
}
|
|
540
|
-
if (typeof value === "number" || typeof value === "boolean") {
|
|
541
|
-
return String(value);
|
|
542
|
-
}
|
|
543
|
-
if (Array.isArray(value)) {
|
|
544
|
-
if (value.length === 0) {
|
|
545
|
-
return "[]";
|
|
546
|
-
}
|
|
547
|
-
return value
|
|
548
|
-
.map((item) => {
|
|
549
|
-
const rendered = toYamlValue(item, indent + 2);
|
|
550
|
-
if (typeof item === "object" && item !== null && !Array.isArray(item)) {
|
|
551
|
-
const lines = rendered.split("\n");
|
|
552
|
-
return `${pad}- ${lines[0]}${lines.length > 1 ? `\n${lines.slice(1).join("\n")}` : ""}`;
|
|
553
|
-
}
|
|
554
|
-
return `${pad}- ${rendered}`;
|
|
555
|
-
})
|
|
556
|
-
.join("\n");
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
const entries = Object.entries(value);
|
|
560
|
-
if (entries.length === 0) {
|
|
561
|
-
return "{}";
|
|
562
|
-
}
|
|
563
|
-
return entries
|
|
564
|
-
.map(([key, entryValue]) => {
|
|
565
|
-
if (typeof entryValue === "object" && entryValue !== null) {
|
|
566
|
-
return `${pad}${key}:\n${toYamlValue(entryValue, indent + 2)}`;
|
|
567
|
-
}
|
|
568
|
-
return `${pad}${key}: ${toYamlValue(entryValue, indent + 2)}`;
|
|
569
|
-
})
|
|
570
|
-
.join("\n");
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
function buildAgentMarkdown(spec) {
|
|
574
|
-
const frontMatter = {
|
|
575
|
-
schemaVersion: spec.schemaVersion,
|
|
576
|
-
type: spec.type,
|
|
577
|
-
id: spec.id,
|
|
578
|
-
slug: spec.slug,
|
|
579
|
-
name: spec.name,
|
|
580
|
-
domain: spec.domain,
|
|
581
|
-
category: spec.category,
|
|
582
|
-
mode: spec.mode,
|
|
583
|
-
icon: spec.icon,
|
|
584
|
-
generatedFrom: spec.generatedFrom,
|
|
585
|
-
promptTemplateId: spec.promptTemplateId,
|
|
586
|
-
skills: spec.skills,
|
|
587
|
-
integrations: spec.integrations,
|
|
588
|
-
};
|
|
589
|
-
|
|
590
|
-
const sections = [
|
|
591
|
-
"---",
|
|
592
|
-
toYamlValue(frontMatter),
|
|
593
|
-
"---",
|
|
594
|
-
"",
|
|
595
|
-
`# ${spec.name}`,
|
|
596
|
-
"",
|
|
597
|
-
"## Description",
|
|
598
|
-
spec.description || "",
|
|
599
|
-
"",
|
|
600
|
-
"## System Prompt",
|
|
601
|
-
spec.systemPrompt || "",
|
|
602
|
-
"",
|
|
603
|
-
"## Runtime Spec",
|
|
604
|
-
"```json",
|
|
605
|
-
JSON.stringify({
|
|
606
|
-
repoIntelligence: spec.repoIntelligence,
|
|
607
|
-
runtime: spec.runtime || null,
|
|
608
|
-
hosted: spec.hosted || null,
|
|
609
|
-
outputs: spec.outputs || null,
|
|
610
|
-
}, null, 2),
|
|
611
|
-
"```",
|
|
612
|
-
"",
|
|
613
|
-
];
|
|
614
|
-
|
|
615
|
-
return sections.join("\n");
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
async function writeDomainManifest(rootDir, mode, domain) {
|
|
619
|
-
const domainRoot = path.join(rootDir, "domains", domain.id);
|
|
620
|
-
const manifestPath = path.join(domainRoot, "domain.json");
|
|
621
|
-
const skillSet = new Set();
|
|
622
|
-
const integrationSet = new Set();
|
|
623
|
-
|
|
624
|
-
for (const agent of domain.agents || []) {
|
|
625
|
-
for (const skill of agent.skills || []) {
|
|
626
|
-
skillSet.add(skill);
|
|
627
|
-
}
|
|
628
|
-
for (const integration of agent.requiresIntegration || []) {
|
|
629
|
-
integrationSet.add(integration);
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
const manifest = {
|
|
634
|
-
schemaVersion: 1,
|
|
635
|
-
id: domain.id,
|
|
636
|
-
label: domain.label,
|
|
637
|
-
mode,
|
|
638
|
-
generatedFrom: domain.generatedFrom || (mode === "gated" ? "gated-vertical-catalog" : "onboarding-catalog"),
|
|
639
|
-
agentCount: (domain.agents || []).length,
|
|
640
|
-
skills: [...skillSet].sort(),
|
|
641
|
-
integrations: [...integrationSet].sort(),
|
|
642
|
-
repoIntelligence: {
|
|
643
|
-
enabled: true,
|
|
644
|
-
scanEndpoint: "/api/repositories/:id/scan",
|
|
645
|
-
pullRequestEndpoint: "/api/repositories/:id/lyra-pr",
|
|
646
|
-
notes: "These agent specs are designed to be hydrated with repository scan output and PR generation workflows.",
|
|
647
|
-
},
|
|
648
|
-
generatedAt: new Date().toISOString(),
|
|
649
|
-
};
|
|
650
|
-
|
|
651
|
-
await fs.mkdir(domainRoot, { recursive: true });
|
|
652
|
-
await fs.writeFile(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`, "utf8");
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
async function writeDomainFiles(rootDir, mode, selectedDomains) {
|
|
656
|
-
for (const domain of selectedDomains) {
|
|
657
|
-
await writeDomainManifest(rootDir, mode, domain);
|
|
658
|
-
const domainDir = path.join(rootDir, "domains", domain.id, "agents");
|
|
659
|
-
await fs.mkdir(domainDir, { recursive: true });
|
|
660
|
-
|
|
661
|
-
for (const agent of domain.agents) {
|
|
662
|
-
const filePath = path.join(domainDir, `${agent.slug}.md`);
|
|
663
|
-
const body = buildAgentSpec(domain, mode, agent);
|
|
664
|
-
await fs.writeFile(filePath, buildAgentMarkdown(body), "utf8");
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
async function writeTopLevelManifest(rootDir, mode, selectedDomains) {
|
|
670
|
-
const agentsDir = path.join(rootDir, "agents");
|
|
671
|
-
const manifestPath = path.join(rootDir, "manifest.json");
|
|
672
|
-
await fs.mkdir(agentsDir, { recursive: true });
|
|
673
|
-
|
|
674
|
-
const manifests = await Promise.all(selectedDomains.map(async (domain) => {
|
|
675
|
-
const source = domain.sourceType === "platform" ? "platform-sync" : (mode === "gated" ? "gated-catalog" : "standalone-catalog");
|
|
676
|
-
const comparisonStatus = domain.sourceType === "platform" ? "imported" : "new";
|
|
677
|
-
const complements = selectedDomains
|
|
678
|
-
.filter((candidate) => candidate.id !== domain.id && candidate.mode !== domain.mode)
|
|
679
|
-
.map((candidate) => candidate.id);
|
|
680
|
-
|
|
681
|
-
let overlapsWith = [];
|
|
682
|
-
if (domain.sourceType !== "platform") {
|
|
683
|
-
overlapsWith = selectedDomains
|
|
684
|
-
.filter((candidate) => candidate.id !== domain.id && candidate.mode === domain.mode)
|
|
685
|
-
.filter((candidate) => {
|
|
686
|
-
const left = new Set((domain.agents || []).map((agent) => agent.id));
|
|
687
|
-
const right = new Set((candidate.agents || []).map((agent) => agent.id));
|
|
688
|
-
for (const id of left) {
|
|
689
|
-
if (right.has(id)) return true;
|
|
690
|
-
}
|
|
691
|
-
return false;
|
|
692
|
-
})
|
|
693
|
-
.map((candidate) => candidate.id);
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
const agentIds = (domain.agents || []).map((agent) => agent.id);
|
|
697
|
-
return {
|
|
698
|
-
id: domain.id,
|
|
699
|
-
label: domain.label,
|
|
700
|
-
mode: domain.mode || mode,
|
|
701
|
-
source,
|
|
702
|
-
comparisonStatus,
|
|
703
|
-
overlapsWith,
|
|
704
|
-
complements,
|
|
705
|
-
agentIds,
|
|
706
|
-
generatedAt: new Date().toISOString(),
|
|
707
|
-
};
|
|
708
|
-
}));
|
|
709
|
-
|
|
710
|
-
for (const domain of selectedDomains) {
|
|
711
|
-
for (const agent of domain.agents || []) {
|
|
712
|
-
const spec = buildAgentSpec(domain, mode, agent);
|
|
713
|
-
const fileName = `${spec.slug}.md`;
|
|
714
|
-
await fs.writeFile(path.join(agentsDir, fileName), buildAgentMarkdown(spec), "utf8");
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
await fs.writeFile(
|
|
719
|
-
manifestPath,
|
|
720
|
-
`${JSON.stringify({
|
|
721
|
-
schemaVersion: 2,
|
|
722
|
-
mode,
|
|
723
|
-
generatedAt: new Date().toISOString(),
|
|
724
|
-
domains: manifests,
|
|
725
|
-
}, null, 2)}\n`,
|
|
726
|
-
"utf8",
|
|
727
|
-
);
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
async function writeScaffold({ targetDir, mode, selectedDomains, apiKey }) {
|
|
731
|
-
const lyraDir = path.join(targetDir, ".lyra");
|
|
732
|
-
await fs.mkdir(lyraDir, { recursive: true });
|
|
733
|
-
await fs.mkdir(path.join(lyraDir, "domains"), { recursive: true });
|
|
734
|
-
await fs.writeFile(path.join(lyraDir, ".gitignore"), "credentials.json\n", "utf8");
|
|
735
|
-
|
|
736
|
-
const config = buildConfig(mode, selectedDomains, Boolean(apiKey));
|
|
737
|
-
await fs.writeFile(path.join(lyraDir, "config.json"), `${JSON.stringify(config, null, 2)}\n`, "utf8");
|
|
738
|
-
|
|
739
|
-
if (mode === "gated" && apiKey) {
|
|
740
|
-
await fs.writeFile(
|
|
741
|
-
path.join(lyraDir, "credentials.json"),
|
|
742
|
-
`${JSON.stringify({ LYRA_API_KEY: apiKey }, null, 2)}\n`,
|
|
743
|
-
"utf8",
|
|
744
|
-
);
|
|
745
|
-
}
|
|
746
|
-
|
|
747
|
-
const readme = [
|
|
748
|
-
"# .lyra",
|
|
749
|
-
"",
|
|
750
|
-
`Mode: ${mode}`,
|
|
751
|
-
"",
|
|
752
|
-
"Domains:",
|
|
753
|
-
...selectedDomains.map((domain) => `- ${domain.label} (${domain.id})`),
|
|
754
|
-
"",
|
|
755
|
-
mode === "gated"
|
|
756
|
-
? "Hosted setup stores the API key in .lyra/credentials.json, which is ignored by the local .lyra/.gitignore file."
|
|
757
|
-
: "Standalone setup keeps all orchestration local and side-effect free until you invoke your own flows.",
|
|
758
|
-
].join("\n");
|
|
759
|
-
await fs.writeFile(path.join(lyraDir, "README.md"), `${readme}\n`, "utf8");
|
|
760
|
-
|
|
761
|
-
await writeDomainFiles(lyraDir, mode, selectedDomains);
|
|
762
|
-
await writeTopLevelManifest(lyraDir, mode, selectedDomains);
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
function resolvePresetDomains(rawDomains, catalog) {
|
|
766
|
-
if (!rawDomains || rawDomains === true) {
|
|
767
|
-
return [];
|
|
768
|
-
}
|
|
769
|
-
const requested = String(rawDomains)
|
|
770
|
-
.split(",")
|
|
771
|
-
.map((value) => value.trim().toLowerCase())
|
|
772
|
-
.filter(Boolean);
|
|
773
|
-
return catalog.filter((domain) => requested.includes(domain.id));
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
function applyGatedLockIfLoggedOut(selectedDomains, hasApiKey) {
|
|
777
|
-
if (hasApiKey) return selectedDomains;
|
|
778
|
-
|
|
779
|
-
return selectedDomains.map((domain) => {
|
|
780
|
-
if ((domain.mode || "standalone") !== "gated") {
|
|
781
|
-
return domain;
|
|
782
|
-
}
|
|
783
|
-
|
|
784
|
-
return {
|
|
785
|
-
...domain,
|
|
786
|
-
sourceType: domain.sourceType || "catalog",
|
|
787
|
-
lockReason: "needs-login",
|
|
788
|
-
agents: (domain.agents || []).map((agent) => ({
|
|
789
|
-
...agent,
|
|
790
|
-
hosted: {
|
|
791
|
-
...(agent.hosted || {}),
|
|
792
|
-
locked: true,
|
|
793
|
-
lockReason: "needs-login",
|
|
794
|
-
},
|
|
795
|
-
})),
|
|
796
|
-
};
|
|
797
|
-
});
|
|
798
|
-
}
|
|
799
|
-
|
|
800
|
-
export async function runInitWizard(options = {}) {
|
|
801
|
-
const rl = readline.createInterface({ input, output });
|
|
802
|
-
|
|
803
|
-
try {
|
|
804
|
-
printWelcomeBanner();
|
|
805
|
-
const stackMode = (options.stack || options.detect) && ["standalone", "gated"].includes(options.mode);
|
|
806
|
-
const wantsLogin = !stackMode && await askYesNo(rl, "Do you want to login with a Lyra API key now?", false);
|
|
807
|
-
const apiBaseUrl = options["api-base-url"] || process.env.LYRA_API_BASE_URL || DEFAULT_API_BASE_URL;
|
|
808
|
-
let apiKey = stackMode && options.mode === "standalone" ? "" : options["api-key"] || process.env.LYRA_API_KEY || "";
|
|
809
|
-
let importedAgents = [];
|
|
810
|
-
|
|
811
|
-
if (wantsLogin && !apiKey) {
|
|
812
|
-
output.write("Paste your Lyra API key (starts with lyra_).\n");
|
|
813
|
-
apiKey = await askQuestion(rl, "Lyra API key: ", { secret: true });
|
|
814
|
-
}
|
|
815
|
-
|
|
816
|
-
if (apiKey) {
|
|
817
|
-
try {
|
|
818
|
-
const agents = await fetchUserAgentsByApiKey(apiBaseUrl, apiKey);
|
|
819
|
-
importedAgents = normalizePlatformAgents(agents);
|
|
820
|
-
output.write(`Synced ${importedAgents.length} agent(s) from your Lyra account.\n`);
|
|
821
|
-
} catch (error) {
|
|
822
|
-
output.write(`Could not sync your agents: ${error.message}. Continuing with catalog selections.\n`);
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
const chosenGroup = stackMode ? undefined : await chooseFlowGroup(rl);
|
|
827
|
-
let mode = options.mode;
|
|
828
|
-
if (mode !== "standalone" && mode !== "gated") {
|
|
829
|
-
mode = chosenGroup === "everyday" ? "gated" : await chooseMode(rl, mode);
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
if (mode === "gated" && !apiKey) {
|
|
833
|
-
output.write("Hosted packs need Lyra login. You can continue, but hosted packs will be marked as locked.\n");
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
const catalog = getDomainCatalog(mode);
|
|
837
|
-
const catalogWithHints = catalog.map((item) => ({
|
|
838
|
-
...item,
|
|
839
|
-
sourceType: "catalog",
|
|
840
|
-
hint: mode === "gated" && !apiKey ? "needs login" : "",
|
|
841
|
-
}));
|
|
842
|
-
const presetDomains = resolvePresetDomains(options.domains, catalogWithHints);
|
|
843
|
-
|
|
844
|
-
const dynamicGroups = [];
|
|
845
|
-
if (importedAgents.length > 0) {
|
|
846
|
-
dynamicGroups.push({ label: "Your agents", options: importedAgents });
|
|
847
|
-
}
|
|
848
|
-
dynamicGroups.push({
|
|
849
|
-
label: mode === "gated" ? "Create new (hosted verticals)" : "Create new (catalog domains)",
|
|
850
|
-
options: catalogWithHints,
|
|
851
|
-
});
|
|
852
|
-
|
|
853
|
-
if (stackMode && !presetDomains.length) throw new Error("Use --domains with a valid Coding or Engineering domain ID.");
|
|
854
|
-
const selected = presetDomains.length > 0
|
|
855
|
-
? presetDomains
|
|
856
|
-
: await selectManyGrouped(
|
|
857
|
-
rl,
|
|
858
|
-
"Select domains and/or your synced agents",
|
|
859
|
-
dynamicGroups,
|
|
860
|
-
[],
|
|
861
|
-
);
|
|
862
|
-
|
|
863
|
-
let selectedDomains = selected.map((entry) => {
|
|
864
|
-
if (entry.sourceType === "platform") {
|
|
865
|
-
return {
|
|
866
|
-
id: entry.id,
|
|
867
|
-
label: entry.label,
|
|
868
|
-
mode: "standalone",
|
|
869
|
-
sourceType: "platform",
|
|
870
|
-
agents: [
|
|
871
|
-
{
|
|
872
|
-
id: entry.importPayload.id,
|
|
873
|
-
slug: entry.importPayload.slug,
|
|
874
|
-
name: entry.importPayload.name,
|
|
875
|
-
description: entry.importPayload.description,
|
|
876
|
-
category: entry.importPayload.category,
|
|
877
|
-
icon: entry.importPayload.icon,
|
|
878
|
-
skills: entry.importPayload.skills,
|
|
879
|
-
requiresIntegration: entry.importPayload.integrations,
|
|
880
|
-
generatedFrom: entry.importPayload.generatedFrom,
|
|
881
|
-
systemPrompt: entry.importPayload.systemPrompt,
|
|
882
|
-
promptTemplateId: entry.importPayload.promptTemplateId,
|
|
883
|
-
runtimeHints: {
|
|
884
|
-
requiresRepoScan: true,
|
|
885
|
-
suggestedScanEndpoint: "/api/repositories/:id/scan",
|
|
886
|
-
suggestedPrEndpoint: "/api/repositories/:id/lyra-pr",
|
|
887
|
-
},
|
|
888
|
-
importPayload: entry.importPayload,
|
|
889
|
-
},
|
|
890
|
-
],
|
|
891
|
-
};
|
|
892
|
-
}
|
|
893
|
-
return {
|
|
894
|
-
...entry,
|
|
895
|
-
sourceType: entry.sourceType || "catalog",
|
|
896
|
-
};
|
|
897
|
-
});
|
|
898
|
-
|
|
899
|
-
if (selectedDomains.length === 0) {
|
|
900
|
-
throw new Error("Select at least one domain.");
|
|
901
|
-
}
|
|
902
|
-
|
|
903
|
-
selectedDomains = applyGatedLockIfLoggedOut(selectedDomains, Boolean(apiKey));
|
|
904
|
-
|
|
905
|
-
if (mode === "gated" && !apiKey) {
|
|
906
|
-
output.write("Enter the Lyra API key from the Lyra login UI. It will be stored in .lyra/credentials.json and ignored by .lyra/.gitignore.\n");
|
|
907
|
-
apiKey = await askQuestion(rl, "Lyra API key: ", { secret: true });
|
|
908
|
-
if (!apiKey) {
|
|
909
|
-
throw new Error("A Lyra API key is required for gated setup.");
|
|
910
|
-
}
|
|
911
|
-
}
|
|
912
|
-
|
|
913
|
-
const targetDir = path.resolve(options.dir || process.cwd());
|
|
914
|
-
const lyraDir = path.join(targetDir, ".lyra");
|
|
915
|
-
const coding = selectedDomains.some(domain => domain.id === "coding" || domain.id === "engineering-bootstrap");
|
|
916
|
-
if (options.stack !== undefined && (!coding || typeof options.stack !== "string")) {
|
|
917
|
-
throw new Error("Use --stack with a stack name and the Coding domain.");
|
|
918
|
-
}
|
|
919
|
-
if (options.detect && (!coding || options.stack)) throw new Error("Use --detect with the Coding domain instead of --stack.");
|
|
920
|
-
let stack = options.stack;
|
|
921
|
-
if (coding && !stack) {
|
|
922
|
-
const detect = options.detect || (input.isTTY && await askYesNo(rl, "Detect technologies from this project?", false));
|
|
923
|
-
if (detect) {
|
|
924
|
-
const recommendations = await recommendCodingStacks(targetDir, output);
|
|
925
|
-
if (recommendations.length && (options.detect || await askYesNo(rl, "Use these recommendations?", true))) stack = recommendations;
|
|
926
|
-
}
|
|
927
|
-
if (!stack && input.isTTY) stack = await selectCodingStack(rl, output);
|
|
928
|
-
}
|
|
929
|
-
let applyCoding;
|
|
930
|
-
if (coding) {
|
|
931
|
-
const existing = await fs.lstat(lyraDir).catch(error => {
|
|
932
|
-
if (error.code !== "ENOENT") throw error;
|
|
933
|
-
});
|
|
934
|
-
if (existing) throw new Error("This project already has .lyra. Run agent-lyra setup coding to add packs while keeping your files.");
|
|
935
|
-
const apply = await prepareCodingStack(targetDir, stack || [], output);
|
|
936
|
-
if (!stack || options.stack || options.detect || /^y(?:es)?$/i.test(await askQuestion(rl, "Create these coding files? [y/N] "))) applyCoding = apply;
|
|
937
|
-
}
|
|
938
|
-
await ensureEmptyOrApproved(rl, lyraDir, Boolean(options.force));
|
|
939
|
-
await writeScaffold({ targetDir, mode, selectedDomains, apiKey });
|
|
940
|
-
if (applyCoding) await applyCoding();
|
|
941
|
-
|
|
942
|
-
output.write(`Created ${lyraDir} for ${mode} mode with ${selectedDomains.length} domain(s).\n`);
|
|
943
|
-
} finally {
|
|
944
|
-
rl.close();
|
|
945
|
-
}
|
|
946
|
-
}
|
|
947
|
-
|
|
948
|
-
export async function runCli(argv = process.argv.slice(2)) {
|
|
949
|
-
const args = parseArgs(argv);
|
|
950
|
-
const [first, second] = args._;
|
|
951
|
-
const command = first === "lyra" ? second : first;
|
|
952
|
-
|
|
953
|
-
if (!command || command === "help" || args.help) {
|
|
954
|
-
printUsage();
|
|
955
|
-
return;
|
|
956
|
-
}
|
|
957
|
-
|
|
958
|
-
if (command === "init") {
|
|
959
|
-
await runInitWizard(args);
|
|
960
|
-
return;
|
|
961
|
-
}
|
|
962
|
-
|
|
963
|
-
throw new Error(`Unknown command: ${command}`);
|
|
964
|
-
}
|
|
965
|
-
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import process from "node:process";
|
|
4
|
+
import readline from "node:readline/promises";
|
|
5
|
+
import { emitKeypressEvents } from "node:readline";
|
|
6
|
+
import { stdin as input, stdout as output } from "node:process";
|
|
7
|
+
import { GATED_DOMAINS, STANDALONE_DOMAINS, getDomainCatalog } from "./catalog.js";
|
|
8
|
+
|
|
9
|
+
import { prepareCodingStack, recommendCodingStacks, selectCodingStack } from "./coding/setup.js";
|
|
10
|
+
|
|
11
|
+
const DEFAULT_API_BASE_URL = "https://www.agentlyra.in";
|
|
12
|
+
|
|
13
|
+
function parseArgs(argv = process.argv.slice(2)) {
|
|
14
|
+
const args = { _: [] };
|
|
15
|
+
|
|
16
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
17
|
+
const token = argv[index];
|
|
18
|
+
if (!token.startsWith("--")) {
|
|
19
|
+
args._.push(token);
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const [flag, inlineValue] = token.split("=", 2);
|
|
24
|
+
const key = flag.slice(2);
|
|
25
|
+
const next = argv[index + 1];
|
|
26
|
+
|
|
27
|
+
if (inlineValue !== undefined) {
|
|
28
|
+
args[key] = inlineValue;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (!next || next.startsWith("--")) {
|
|
33
|
+
args[key] = true;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
args[key] = next;
|
|
38
|
+
index += 1;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return args;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function printUsage() {
|
|
45
|
+
output.write(`Usage:\n agent-lyra init\n lyra init\n\nOptions:\n --mode standalone|gated\n --domains coding,finance\n --stack mern,playwright\n --detect\n --api-key <key>\n --api-base-url <url>\n --dir <target-directory>\n --force\n`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function printWelcomeBanner() {
|
|
49
|
+
output.write([
|
|
50
|
+
"",
|
|
51
|
+
" _ _ _ ",
|
|
52
|
+
" / \\\ __ _ ___ _ __ | |_ | | _ _ _ __ __ _ ",
|
|
53
|
+
" / _ \\\ / _` |/ _ \\ '_ \\| __| | | | | | | '__/ _` |",
|
|
54
|
+
" / ___ \\\ (_| | __/ | | | |_ | |__| |_| | | | (_| |",
|
|
55
|
+
"/_/ \\\_\\__, |\\___|_| |_|\\__| |_____\\__, |_| \\__,_|",
|
|
56
|
+
" |___/ |___/ ",
|
|
57
|
+
"",
|
|
58
|
+
" Local agents when you want control. Hosted agents when you want lift.",
|
|
59
|
+
"",
|
|
60
|
+
].join("\n"));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async function askQuestion(rl, message, { secret = false } = {}) {
|
|
64
|
+
if (!secret) {
|
|
65
|
+
return (await rl.question(message)).trim();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const original = input.isTTY ? input.isTTY : false;
|
|
69
|
+
if (input.isTTY) {
|
|
70
|
+
input.setRawMode?.(true);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
output.write(message);
|
|
74
|
+
let buffer = "";
|
|
75
|
+
|
|
76
|
+
return await new Promise((resolve) => {
|
|
77
|
+
const onData = (chunk) => {
|
|
78
|
+
const value = String(chunk);
|
|
79
|
+
if (value === "\r" || value === "\n") {
|
|
80
|
+
input.off("data", onData);
|
|
81
|
+
output.write("\n");
|
|
82
|
+
if (input.isTTY && original) {
|
|
83
|
+
input.setRawMode?.(false);
|
|
84
|
+
}
|
|
85
|
+
resolve(buffer.trim());
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (value === "\u0003") {
|
|
90
|
+
process.exitCode = 1;
|
|
91
|
+
input.off("data", onData);
|
|
92
|
+
if (input.isTTY && original) {
|
|
93
|
+
input.setRawMode?.(false);
|
|
94
|
+
}
|
|
95
|
+
throw new Error("Cancelled.");
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (value === "\u007f") {
|
|
99
|
+
buffer = buffer.slice(0, -1);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
buffer += value;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
input.on("data", onData);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async function chooseMode(rl, currentMode) {
|
|
111
|
+
if (currentMode === "standalone" || currentMode === "gated") {
|
|
112
|
+
return currentMode;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
while (true) {
|
|
116
|
+
const answer = (await rl.question("Choose setup flow: [1] standalone [2] gated: ")).trim().toLowerCase();
|
|
117
|
+
if (answer === "1" || answer === "standalone" || answer === "s") {
|
|
118
|
+
return "standalone";
|
|
119
|
+
}
|
|
120
|
+
if (answer === "2" || answer === "gated" || answer === "g") {
|
|
121
|
+
return "gated";
|
|
122
|
+
}
|
|
123
|
+
output.write("Enter 1 for standalone or 2 for gated.\n");
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async function chooseFlowGroup(rl) {
|
|
128
|
+
while (true) {
|
|
129
|
+
const answer = (await rl.question("Choose pack type: [1] Professional [2] Everyday: ")).trim().toLowerCase();
|
|
130
|
+
if (answer === "1" || answer === "professional" || answer === "p") {
|
|
131
|
+
return "professional";
|
|
132
|
+
}
|
|
133
|
+
if (answer === "2" || answer === "everyday" || answer === "e") {
|
|
134
|
+
return "everyday";
|
|
135
|
+
}
|
|
136
|
+
output.write("Enter 1 for Professional or 2 for Everyday.\n");
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function clearScreen() {
|
|
141
|
+
output.write("\u001Bc");
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function renderMultiSelect(title, options, cursor, selected) {
|
|
145
|
+
clearScreen();
|
|
146
|
+
output.write(`${title}\n`);
|
|
147
|
+
output.write("Use ↑/↓ to move, Space to toggle, Enter to confirm.\n\n");
|
|
148
|
+
|
|
149
|
+
options.forEach((option, index) => {
|
|
150
|
+
const marker = selected.has(option.id) ? "[x]" : "[ ]";
|
|
151
|
+
const prefix = index === cursor ? ">" : " ";
|
|
152
|
+
output.write(`${prefix} ${marker} ${option.label}\n`);
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function renderGroupedMultiSelect(title, groups, cursor, selected) {
|
|
157
|
+
const flattened = groups.flatMap((group) => group.options);
|
|
158
|
+
clearScreen();
|
|
159
|
+
output.write(`${title}\n`);
|
|
160
|
+
output.write("Use ↑/↓ to move, Space to toggle, Enter to confirm.\n\n");
|
|
161
|
+
|
|
162
|
+
let running = 0;
|
|
163
|
+
groups.forEach((group) => {
|
|
164
|
+
output.write(`${group.label}\n`);
|
|
165
|
+
group.options.forEach((option) => {
|
|
166
|
+
const marker = selected.has(option.id) ? "[x]" : "[ ]";
|
|
167
|
+
const prefix = running === cursor ? ">" : " ";
|
|
168
|
+
output.write(`${prefix} ${marker} ${option.label}${option.hint ? ` - ${option.hint}` : ""}\n`);
|
|
169
|
+
running += 1;
|
|
170
|
+
});
|
|
171
|
+
output.write("\n");
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
if (flattened.length === 0) {
|
|
175
|
+
output.write("No options available.\n");
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
async function selectManyGrouped(rl, title, groups, presetIds = []) {
|
|
180
|
+
const options = groups.flatMap((group) => group.options);
|
|
181
|
+
|
|
182
|
+
if (!input.isTTY || !output.isTTY) {
|
|
183
|
+
const answer = (await rl.question(`${title} (comma-separated ids): `)).trim();
|
|
184
|
+
const selectedIds = answer
|
|
185
|
+
? answer.split(",").map((value) => value.trim()).filter(Boolean)
|
|
186
|
+
: presetIds;
|
|
187
|
+
return options.filter((option) => selectedIds.includes(option.id));
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
emitKeypressEvents(input);
|
|
191
|
+
input.setRawMode?.(true);
|
|
192
|
+
input.resume();
|
|
193
|
+
|
|
194
|
+
const selected = new Set(presetIds);
|
|
195
|
+
let cursor = 0;
|
|
196
|
+
renderGroupedMultiSelect(title, groups, cursor, selected);
|
|
197
|
+
|
|
198
|
+
return await new Promise((resolve, reject) => {
|
|
199
|
+
const cleanup = () => {
|
|
200
|
+
input.setRawMode?.(false);
|
|
201
|
+
input.removeListener("keypress", onKeypress);
|
|
202
|
+
output.write("\n");
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
const onKeypress = (_, key) => {
|
|
206
|
+
if (key?.name === "up") {
|
|
207
|
+
cursor = cursor === 0 ? options.length - 1 : cursor - 1;
|
|
208
|
+
renderGroupedMultiSelect(title, groups, cursor, selected);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (key?.name === "down") {
|
|
212
|
+
cursor = cursor === options.length - 1 ? 0 : cursor + 1;
|
|
213
|
+
renderGroupedMultiSelect(title, groups, cursor, selected);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
if (key?.name === "space") {
|
|
217
|
+
const current = options[cursor];
|
|
218
|
+
if (!current || current.disabled) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
if (selected.has(current.id)) {
|
|
222
|
+
selected.delete(current.id);
|
|
223
|
+
} else {
|
|
224
|
+
selected.add(current.id);
|
|
225
|
+
}
|
|
226
|
+
renderGroupedMultiSelect(title, groups, cursor, selected);
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
if (key?.name === "return") {
|
|
230
|
+
cleanup();
|
|
231
|
+
resolve(options.filter((option) => selected.has(option.id)));
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
if (key?.ctrl && key.name === "c") {
|
|
235
|
+
cleanup();
|
|
236
|
+
reject(new Error("Cancelled."));
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
input.on("keypress", onKeypress);
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
async function askYesNo(rl, prompt, defaultValue = false) {
|
|
245
|
+
const suffix = defaultValue ? " [Y/n]: " : " [y/N]: ";
|
|
246
|
+
const answer = (await rl.question(`${prompt}${suffix}`)).trim().toLowerCase();
|
|
247
|
+
if (!answer) return defaultValue;
|
|
248
|
+
return answer === "y" || answer === "yes";
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
async function fetchUserAgentsByApiKey(apiBaseUrl, apiKey) {
|
|
252
|
+
const baseUrl = String(apiBaseUrl || DEFAULT_API_BASE_URL).replace(/\/$/, "");
|
|
253
|
+
const response = await fetch(`${baseUrl}/api/lyra-cli/agents`, {
|
|
254
|
+
method: "GET",
|
|
255
|
+
headers: {
|
|
256
|
+
Authorization: `Bearer ${apiKey}`,
|
|
257
|
+
},
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
if (!response.ok) {
|
|
261
|
+
throw new Error(`Failed to sync agents: ${response.status}`);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const body = await response.json();
|
|
265
|
+
return Array.isArray(body?.agents) ? body.agents : [];
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function normalizePlatformAgents(rawAgents = []) {
|
|
269
|
+
return rawAgents
|
|
270
|
+
.filter((agent) => agent && agent.name && agent.id)
|
|
271
|
+
.map((agent) => ({
|
|
272
|
+
id: `platform-${agent.id}`,
|
|
273
|
+
label: `${agent.name} (Your agent)`,
|
|
274
|
+
mode: "standalone",
|
|
275
|
+
sourceType: "platform",
|
|
276
|
+
importPayload: {
|
|
277
|
+
schemaVersion: 1,
|
|
278
|
+
type: "platform-agent",
|
|
279
|
+
id: String(agent.id),
|
|
280
|
+
slug: String(agent.slug || agent.name).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, ""),
|
|
281
|
+
name: agent.name,
|
|
282
|
+
domain: "platform-imports",
|
|
283
|
+
category: agent.category || "custom",
|
|
284
|
+
mode: "standalone",
|
|
285
|
+
description: agent.description || "",
|
|
286
|
+
icon: null,
|
|
287
|
+
skills: Array.isArray(agent.skills) ? agent.skills : [],
|
|
288
|
+
integrations: Array.isArray(agent.integrations) ? agent.integrations : [],
|
|
289
|
+
generatedFrom: "platform-sync",
|
|
290
|
+
promptTemplateId: null,
|
|
291
|
+
systemPrompt: agent.systemPrompt || "",
|
|
292
|
+
runtime: {
|
|
293
|
+
execution: "platform",
|
|
294
|
+
source: "lyra-web",
|
|
295
|
+
defaultModel: agent.defaultModel || null,
|
|
296
|
+
maxTokens: agent.maxTokens ?? null,
|
|
297
|
+
temperature: agent.temperature ?? null,
|
|
298
|
+
},
|
|
299
|
+
repoIntelligence: {
|
|
300
|
+
enabled: true,
|
|
301
|
+
requiresScan: true,
|
|
302
|
+
scanEndpoint: "/api/repositories/:id/scan",
|
|
303
|
+
pullRequestEndpoint: "/api/repositories/:id/lyra-pr",
|
|
304
|
+
contextContract: {
|
|
305
|
+
required: [
|
|
306
|
+
"repoContext",
|
|
307
|
+
"findingsAtScanTime",
|
|
308
|
+
"responsibilities",
|
|
309
|
+
"scopedPaths",
|
|
310
|
+
"confidence",
|
|
311
|
+
],
|
|
312
|
+
},
|
|
313
|
+
},
|
|
314
|
+
outputs: {
|
|
315
|
+
format: "markdown",
|
|
316
|
+
requireCitations: false,
|
|
317
|
+
},
|
|
318
|
+
},
|
|
319
|
+
}));
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
async function selectMany(rl, title, options, presetIds = []) {
|
|
323
|
+
if (!input.isTTY || !output.isTTY) {
|
|
324
|
+
const answer = (await rl.question(`${title} (comma-separated ids): `)).trim();
|
|
325
|
+
const selectedIds = answer
|
|
326
|
+
? answer.split(",").map((value) => value.trim()).filter(Boolean)
|
|
327
|
+
: presetIds;
|
|
328
|
+
return options.filter((option) => selectedIds.includes(option.id));
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
emitKeypressEvents(input);
|
|
332
|
+
input.setRawMode?.(true);
|
|
333
|
+
input.resume();
|
|
334
|
+
|
|
335
|
+
const selected = new Set(presetIds);
|
|
336
|
+
let cursor = 0;
|
|
337
|
+
renderMultiSelect(title, options, cursor, selected);
|
|
338
|
+
|
|
339
|
+
return await new Promise((resolve, reject) => {
|
|
340
|
+
const cleanup = () => {
|
|
341
|
+
input.setRawMode?.(false);
|
|
342
|
+
input.removeListener("keypress", onKeypress);
|
|
343
|
+
output.write("\n");
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
const onKeypress = (_, key) => {
|
|
347
|
+
if (key?.name === "up") {
|
|
348
|
+
cursor = cursor === 0 ? options.length - 1 : cursor - 1;
|
|
349
|
+
renderMultiSelect(title, options, cursor, selected);
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
if (key?.name === "down") {
|
|
353
|
+
cursor = cursor === options.length - 1 ? 0 : cursor + 1;
|
|
354
|
+
renderMultiSelect(title, options, cursor, selected);
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
if (key?.name === "space") {
|
|
358
|
+
const current = options[cursor];
|
|
359
|
+
if (selected.has(current.id)) {
|
|
360
|
+
selected.delete(current.id);
|
|
361
|
+
} else {
|
|
362
|
+
selected.add(current.id);
|
|
363
|
+
}
|
|
364
|
+
renderMultiSelect(title, options, cursor, selected);
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
if (key?.name === "return") {
|
|
368
|
+
cleanup();
|
|
369
|
+
resolve(options.filter((option) => selected.has(option.id)));
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
if (key?.ctrl && key.name === "c") {
|
|
373
|
+
cleanup();
|
|
374
|
+
reject(new Error("Cancelled."));
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
input.on("keypress", onKeypress);
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
async function ensureEmptyOrApproved(rl, rootDir, force) {
|
|
383
|
+
try {
|
|
384
|
+
await fs.access(rootDir);
|
|
385
|
+
if (force) {
|
|
386
|
+
await fs.rm(rootDir, { recursive: true, force: true });
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
const answer = (await rl.question(`Directory ${rootDir} exists. Overwrite Lyra files? [y/N]: `)).trim().toLowerCase();
|
|
390
|
+
if (answer !== "y" && answer !== "yes") {
|
|
391
|
+
throw new Error("Aborted by user.");
|
|
392
|
+
}
|
|
393
|
+
await fs.rm(rootDir, { recursive: true, force: true });
|
|
394
|
+
} catch (error) {
|
|
395
|
+
if (error.code === "ENOENT") {
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
if (error.message === "Aborted by user.") {
|
|
399
|
+
throw error;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
function buildConfig(mode, selectedDomains, apiKeyProvided) {
|
|
405
|
+
return {
|
|
406
|
+
version: 1,
|
|
407
|
+
mode,
|
|
408
|
+
domains: selectedDomains.map((domain) => domain.id),
|
|
409
|
+
createdAt: new Date().toISOString(),
|
|
410
|
+
gated: mode === "gated"
|
|
411
|
+
? {
|
|
412
|
+
apiKeySource: apiKeyProvided ? ".lyra/credentials.json" : "env:LYRA_API_KEY",
|
|
413
|
+
verticals: selectedDomains.map((domain) => domain.id),
|
|
414
|
+
}
|
|
415
|
+
: undefined,
|
|
416
|
+
domainsMetadata: selectedDomains.map((domain) => sanitizeConfigDomainEntry(domain)),
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
function sanitizeConfigDomainEntry(entry) {
|
|
421
|
+
const agentCount = Array.isArray(entry.agents) ? entry.agents.length : Number(entry.agentCount || 0);
|
|
422
|
+
return {
|
|
423
|
+
id: entry.id,
|
|
424
|
+
label: entry.label,
|
|
425
|
+
mode: entry.mode || "standalone",
|
|
426
|
+
sourceType: entry.sourceType || "catalog",
|
|
427
|
+
agentCount,
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
function buildStandaloneAgentSpec(domain, agent) {
|
|
432
|
+
return {
|
|
433
|
+
schemaVersion: 1,
|
|
434
|
+
type: "standalone-agent",
|
|
435
|
+
id: agent.id,
|
|
436
|
+
slug: agent.slug,
|
|
437
|
+
name: agent.name,
|
|
438
|
+
domain: domain.id,
|
|
439
|
+
category: agent.category,
|
|
440
|
+
mode: "standalone",
|
|
441
|
+
description: agent.description,
|
|
442
|
+
icon: agent.icon || null,
|
|
443
|
+
skills: agent.skills || [],
|
|
444
|
+
integrations: agent.requiresIntegration || [],
|
|
445
|
+
generatedFrom: agent.generatedFrom || "onboarding-catalog",
|
|
446
|
+
promptTemplateId: agent.promptTemplateId || null,
|
|
447
|
+
systemPrompt: agent.systemPrompt || "",
|
|
448
|
+
repoIntelligence: {
|
|
449
|
+
enabled: true,
|
|
450
|
+
requiresScan: Boolean(agent.runtimeHints?.requiresRepoScan),
|
|
451
|
+
scanEndpoint: agent.runtimeHints?.suggestedScanEndpoint || "/api/repositories/:id/scan",
|
|
452
|
+
pullRequestEndpoint: agent.runtimeHints?.suggestedPrEndpoint || "/api/repositories/:id/lyra-pr",
|
|
453
|
+
contextContract: {
|
|
454
|
+
required: [
|
|
455
|
+
"repoContext",
|
|
456
|
+
"findingsAtScanTime",
|
|
457
|
+
"responsibilities",
|
|
458
|
+
"scopedPaths",
|
|
459
|
+
"confidence",
|
|
460
|
+
],
|
|
461
|
+
},
|
|
462
|
+
},
|
|
463
|
+
runtime: {
|
|
464
|
+
execution: "local",
|
|
465
|
+
orchestration: "standalone",
|
|
466
|
+
ragEnabled: true,
|
|
467
|
+
},
|
|
468
|
+
outputs: {
|
|
469
|
+
format: "markdown",
|
|
470
|
+
requireCitations: Boolean((agent.skills || []).includes("url-scraper") || (agent.skills || []).includes("web-search")),
|
|
471
|
+
},
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
function buildGatedAgentSpec(domain, agent) {
|
|
476
|
+
return {
|
|
477
|
+
schemaVersion: 1,
|
|
478
|
+
type: "hosted-agent",
|
|
479
|
+
id: agent.id,
|
|
480
|
+
slug: agent.slug,
|
|
481
|
+
name: agent.name,
|
|
482
|
+
domain: domain.id,
|
|
483
|
+
category: agent.category,
|
|
484
|
+
mode: "gated",
|
|
485
|
+
description: agent.description,
|
|
486
|
+
icon: agent.icon || null,
|
|
487
|
+
skills: agent.skills || [],
|
|
488
|
+
integrations: agent.requiresIntegration || [],
|
|
489
|
+
generatedFrom: agent.generatedFrom || "gated-vertical-catalog",
|
|
490
|
+
promptTemplateId: agent.promptTemplateId || null,
|
|
491
|
+
systemPrompt: agent.systemPrompt || "",
|
|
492
|
+
repoIntelligence: {
|
|
493
|
+
enabled: true,
|
|
494
|
+
requiresScan: false,
|
|
495
|
+
scanEndpoint: "/api/repositories/:id/scan",
|
|
496
|
+
pullRequestEndpoint: "/api/repositories/:id/lyra-pr",
|
|
497
|
+
contextContract: {
|
|
498
|
+
required: [
|
|
499
|
+
"repoContext",
|
|
500
|
+
"findingsAtScanTime",
|
|
501
|
+
"responsibilities",
|
|
502
|
+
"scopedPaths",
|
|
503
|
+
"confidence",
|
|
504
|
+
],
|
|
505
|
+
},
|
|
506
|
+
},
|
|
507
|
+
hosted: {
|
|
508
|
+
provider: "lyra",
|
|
509
|
+
vertical: agent.hosted?.vertical || domain.id,
|
|
510
|
+
defaultModel: agent.hosted?.defaultModel || null,
|
|
511
|
+
endpoint: `/agents/${agent.hosted?.vertical || domain.id}/invoke`,
|
|
512
|
+
auth: {
|
|
513
|
+
strategy: "bearer",
|
|
514
|
+
credentialsFile: ".lyra/credentials.json",
|
|
515
|
+
credentialsKey: "LYRA_API_KEY",
|
|
516
|
+
},
|
|
517
|
+
},
|
|
518
|
+
outputs: {
|
|
519
|
+
format: "json",
|
|
520
|
+
includeUsage: true,
|
|
521
|
+
},
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
function buildAgentSpec(domain, mode, agent) {
|
|
526
|
+
const effectiveMode = domain.mode || mode;
|
|
527
|
+
return effectiveMode === "gated"
|
|
528
|
+
? buildGatedAgentSpec(domain, agent)
|
|
529
|
+
: buildStandaloneAgentSpec(domain, agent);
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
function toYamlValue(value, indent = 0) {
|
|
533
|
+
const pad = " ".repeat(indent);
|
|
534
|
+
if (value === null || value === undefined) {
|
|
535
|
+
return "null";
|
|
536
|
+
}
|
|
537
|
+
if (typeof value === "string") {
|
|
538
|
+
return JSON.stringify(value);
|
|
539
|
+
}
|
|
540
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
541
|
+
return String(value);
|
|
542
|
+
}
|
|
543
|
+
if (Array.isArray(value)) {
|
|
544
|
+
if (value.length === 0) {
|
|
545
|
+
return "[]";
|
|
546
|
+
}
|
|
547
|
+
return value
|
|
548
|
+
.map((item) => {
|
|
549
|
+
const rendered = toYamlValue(item, indent + 2);
|
|
550
|
+
if (typeof item === "object" && item !== null && !Array.isArray(item)) {
|
|
551
|
+
const lines = rendered.split("\n");
|
|
552
|
+
return `${pad}- ${lines[0]}${lines.length > 1 ? `\n${lines.slice(1).join("\n")}` : ""}`;
|
|
553
|
+
}
|
|
554
|
+
return `${pad}- ${rendered}`;
|
|
555
|
+
})
|
|
556
|
+
.join("\n");
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
const entries = Object.entries(value);
|
|
560
|
+
if (entries.length === 0) {
|
|
561
|
+
return "{}";
|
|
562
|
+
}
|
|
563
|
+
return entries
|
|
564
|
+
.map(([key, entryValue]) => {
|
|
565
|
+
if (typeof entryValue === "object" && entryValue !== null) {
|
|
566
|
+
return `${pad}${key}:\n${toYamlValue(entryValue, indent + 2)}`;
|
|
567
|
+
}
|
|
568
|
+
return `${pad}${key}: ${toYamlValue(entryValue, indent + 2)}`;
|
|
569
|
+
})
|
|
570
|
+
.join("\n");
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
function buildAgentMarkdown(spec) {
|
|
574
|
+
const frontMatter = {
|
|
575
|
+
schemaVersion: spec.schemaVersion,
|
|
576
|
+
type: spec.type,
|
|
577
|
+
id: spec.id,
|
|
578
|
+
slug: spec.slug,
|
|
579
|
+
name: spec.name,
|
|
580
|
+
domain: spec.domain,
|
|
581
|
+
category: spec.category,
|
|
582
|
+
mode: spec.mode,
|
|
583
|
+
icon: spec.icon,
|
|
584
|
+
generatedFrom: spec.generatedFrom,
|
|
585
|
+
promptTemplateId: spec.promptTemplateId,
|
|
586
|
+
skills: spec.skills,
|
|
587
|
+
integrations: spec.integrations,
|
|
588
|
+
};
|
|
589
|
+
|
|
590
|
+
const sections = [
|
|
591
|
+
"---",
|
|
592
|
+
toYamlValue(frontMatter),
|
|
593
|
+
"---",
|
|
594
|
+
"",
|
|
595
|
+
`# ${spec.name}`,
|
|
596
|
+
"",
|
|
597
|
+
"## Description",
|
|
598
|
+
spec.description || "",
|
|
599
|
+
"",
|
|
600
|
+
"## System Prompt",
|
|
601
|
+
spec.systemPrompt || "",
|
|
602
|
+
"",
|
|
603
|
+
"## Runtime Spec",
|
|
604
|
+
"```json",
|
|
605
|
+
JSON.stringify({
|
|
606
|
+
repoIntelligence: spec.repoIntelligence,
|
|
607
|
+
runtime: spec.runtime || null,
|
|
608
|
+
hosted: spec.hosted || null,
|
|
609
|
+
outputs: spec.outputs || null,
|
|
610
|
+
}, null, 2),
|
|
611
|
+
"```",
|
|
612
|
+
"",
|
|
613
|
+
];
|
|
614
|
+
|
|
615
|
+
return sections.join("\n");
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
async function writeDomainManifest(rootDir, mode, domain) {
|
|
619
|
+
const domainRoot = path.join(rootDir, "domains", domain.id);
|
|
620
|
+
const manifestPath = path.join(domainRoot, "domain.json");
|
|
621
|
+
const skillSet = new Set();
|
|
622
|
+
const integrationSet = new Set();
|
|
623
|
+
|
|
624
|
+
for (const agent of domain.agents || []) {
|
|
625
|
+
for (const skill of agent.skills || []) {
|
|
626
|
+
skillSet.add(skill);
|
|
627
|
+
}
|
|
628
|
+
for (const integration of agent.requiresIntegration || []) {
|
|
629
|
+
integrationSet.add(integration);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
const manifest = {
|
|
634
|
+
schemaVersion: 1,
|
|
635
|
+
id: domain.id,
|
|
636
|
+
label: domain.label,
|
|
637
|
+
mode,
|
|
638
|
+
generatedFrom: domain.generatedFrom || (mode === "gated" ? "gated-vertical-catalog" : "onboarding-catalog"),
|
|
639
|
+
agentCount: (domain.agents || []).length,
|
|
640
|
+
skills: [...skillSet].sort(),
|
|
641
|
+
integrations: [...integrationSet].sort(),
|
|
642
|
+
repoIntelligence: {
|
|
643
|
+
enabled: true,
|
|
644
|
+
scanEndpoint: "/api/repositories/:id/scan",
|
|
645
|
+
pullRequestEndpoint: "/api/repositories/:id/lyra-pr",
|
|
646
|
+
notes: "These agent specs are designed to be hydrated with repository scan output and PR generation workflows.",
|
|
647
|
+
},
|
|
648
|
+
generatedAt: new Date().toISOString(),
|
|
649
|
+
};
|
|
650
|
+
|
|
651
|
+
await fs.mkdir(domainRoot, { recursive: true });
|
|
652
|
+
await fs.writeFile(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`, "utf8");
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
async function writeDomainFiles(rootDir, mode, selectedDomains) {
|
|
656
|
+
for (const domain of selectedDomains) {
|
|
657
|
+
await writeDomainManifest(rootDir, mode, domain);
|
|
658
|
+
const domainDir = path.join(rootDir, "domains", domain.id, "agents");
|
|
659
|
+
await fs.mkdir(domainDir, { recursive: true });
|
|
660
|
+
|
|
661
|
+
for (const agent of domain.agents) {
|
|
662
|
+
const filePath = path.join(domainDir, `${agent.slug}.md`);
|
|
663
|
+
const body = buildAgentSpec(domain, mode, agent);
|
|
664
|
+
await fs.writeFile(filePath, buildAgentMarkdown(body), "utf8");
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
async function writeTopLevelManifest(rootDir, mode, selectedDomains) {
|
|
670
|
+
const agentsDir = path.join(rootDir, "agents");
|
|
671
|
+
const manifestPath = path.join(rootDir, "manifest.json");
|
|
672
|
+
await fs.mkdir(agentsDir, { recursive: true });
|
|
673
|
+
|
|
674
|
+
const manifests = await Promise.all(selectedDomains.map(async (domain) => {
|
|
675
|
+
const source = domain.sourceType === "platform" ? "platform-sync" : (mode === "gated" ? "gated-catalog" : "standalone-catalog");
|
|
676
|
+
const comparisonStatus = domain.sourceType === "platform" ? "imported" : "new";
|
|
677
|
+
const complements = selectedDomains
|
|
678
|
+
.filter((candidate) => candidate.id !== domain.id && candidate.mode !== domain.mode)
|
|
679
|
+
.map((candidate) => candidate.id);
|
|
680
|
+
|
|
681
|
+
let overlapsWith = [];
|
|
682
|
+
if (domain.sourceType !== "platform") {
|
|
683
|
+
overlapsWith = selectedDomains
|
|
684
|
+
.filter((candidate) => candidate.id !== domain.id && candidate.mode === domain.mode)
|
|
685
|
+
.filter((candidate) => {
|
|
686
|
+
const left = new Set((domain.agents || []).map((agent) => agent.id));
|
|
687
|
+
const right = new Set((candidate.agents || []).map((agent) => agent.id));
|
|
688
|
+
for (const id of left) {
|
|
689
|
+
if (right.has(id)) return true;
|
|
690
|
+
}
|
|
691
|
+
return false;
|
|
692
|
+
})
|
|
693
|
+
.map((candidate) => candidate.id);
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
const agentIds = (domain.agents || []).map((agent) => agent.id);
|
|
697
|
+
return {
|
|
698
|
+
id: domain.id,
|
|
699
|
+
label: domain.label,
|
|
700
|
+
mode: domain.mode || mode,
|
|
701
|
+
source,
|
|
702
|
+
comparisonStatus,
|
|
703
|
+
overlapsWith,
|
|
704
|
+
complements,
|
|
705
|
+
agentIds,
|
|
706
|
+
generatedAt: new Date().toISOString(),
|
|
707
|
+
};
|
|
708
|
+
}));
|
|
709
|
+
|
|
710
|
+
for (const domain of selectedDomains) {
|
|
711
|
+
for (const agent of domain.agents || []) {
|
|
712
|
+
const spec = buildAgentSpec(domain, mode, agent);
|
|
713
|
+
const fileName = `${spec.slug}.md`;
|
|
714
|
+
await fs.writeFile(path.join(agentsDir, fileName), buildAgentMarkdown(spec), "utf8");
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
await fs.writeFile(
|
|
719
|
+
manifestPath,
|
|
720
|
+
`${JSON.stringify({
|
|
721
|
+
schemaVersion: 2,
|
|
722
|
+
mode,
|
|
723
|
+
generatedAt: new Date().toISOString(),
|
|
724
|
+
domains: manifests,
|
|
725
|
+
}, null, 2)}\n`,
|
|
726
|
+
"utf8",
|
|
727
|
+
);
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
async function writeScaffold({ targetDir, mode, selectedDomains, apiKey }) {
|
|
731
|
+
const lyraDir = path.join(targetDir, ".lyra");
|
|
732
|
+
await fs.mkdir(lyraDir, { recursive: true });
|
|
733
|
+
await fs.mkdir(path.join(lyraDir, "domains"), { recursive: true });
|
|
734
|
+
await fs.writeFile(path.join(lyraDir, ".gitignore"), "credentials.json\n", "utf8");
|
|
735
|
+
|
|
736
|
+
const config = buildConfig(mode, selectedDomains, Boolean(apiKey));
|
|
737
|
+
await fs.writeFile(path.join(lyraDir, "config.json"), `${JSON.stringify(config, null, 2)}\n`, "utf8");
|
|
738
|
+
|
|
739
|
+
if (mode === "gated" && apiKey) {
|
|
740
|
+
await fs.writeFile(
|
|
741
|
+
path.join(lyraDir, "credentials.json"),
|
|
742
|
+
`${JSON.stringify({ LYRA_API_KEY: apiKey }, null, 2)}\n`,
|
|
743
|
+
"utf8",
|
|
744
|
+
);
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
const readme = [
|
|
748
|
+
"# .lyra",
|
|
749
|
+
"",
|
|
750
|
+
`Mode: ${mode}`,
|
|
751
|
+
"",
|
|
752
|
+
"Domains:",
|
|
753
|
+
...selectedDomains.map((domain) => `- ${domain.label} (${domain.id})`),
|
|
754
|
+
"",
|
|
755
|
+
mode === "gated"
|
|
756
|
+
? "Hosted setup stores the API key in .lyra/credentials.json, which is ignored by the local .lyra/.gitignore file."
|
|
757
|
+
: "Standalone setup keeps all orchestration local and side-effect free until you invoke your own flows.",
|
|
758
|
+
].join("\n");
|
|
759
|
+
await fs.writeFile(path.join(lyraDir, "README.md"), `${readme}\n`, "utf8");
|
|
760
|
+
|
|
761
|
+
await writeDomainFiles(lyraDir, mode, selectedDomains);
|
|
762
|
+
await writeTopLevelManifest(lyraDir, mode, selectedDomains);
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
function resolvePresetDomains(rawDomains, catalog) {
|
|
766
|
+
if (!rawDomains || rawDomains === true) {
|
|
767
|
+
return [];
|
|
768
|
+
}
|
|
769
|
+
const requested = String(rawDomains)
|
|
770
|
+
.split(",")
|
|
771
|
+
.map((value) => value.trim().toLowerCase())
|
|
772
|
+
.filter(Boolean);
|
|
773
|
+
return catalog.filter((domain) => requested.includes(domain.id));
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
function applyGatedLockIfLoggedOut(selectedDomains, hasApiKey) {
|
|
777
|
+
if (hasApiKey) return selectedDomains;
|
|
778
|
+
|
|
779
|
+
return selectedDomains.map((domain) => {
|
|
780
|
+
if ((domain.mode || "standalone") !== "gated") {
|
|
781
|
+
return domain;
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
return {
|
|
785
|
+
...domain,
|
|
786
|
+
sourceType: domain.sourceType || "catalog",
|
|
787
|
+
lockReason: "needs-login",
|
|
788
|
+
agents: (domain.agents || []).map((agent) => ({
|
|
789
|
+
...agent,
|
|
790
|
+
hosted: {
|
|
791
|
+
...(agent.hosted || {}),
|
|
792
|
+
locked: true,
|
|
793
|
+
lockReason: "needs-login",
|
|
794
|
+
},
|
|
795
|
+
})),
|
|
796
|
+
};
|
|
797
|
+
});
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
export async function runInitWizard(options = {}) {
|
|
801
|
+
const rl = readline.createInterface({ input, output });
|
|
802
|
+
|
|
803
|
+
try {
|
|
804
|
+
printWelcomeBanner();
|
|
805
|
+
const stackMode = (options.stack || options.detect) && ["standalone", "gated"].includes(options.mode);
|
|
806
|
+
const wantsLogin = !stackMode && await askYesNo(rl, "Do you want to login with a Lyra API key now?", false);
|
|
807
|
+
const apiBaseUrl = options["api-base-url"] || process.env.LYRA_API_BASE_URL || DEFAULT_API_BASE_URL;
|
|
808
|
+
let apiKey = stackMode && options.mode === "standalone" ? "" : options["api-key"] || process.env.LYRA_API_KEY || "";
|
|
809
|
+
let importedAgents = [];
|
|
810
|
+
|
|
811
|
+
if (wantsLogin && !apiKey) {
|
|
812
|
+
output.write("Paste your Lyra API key (starts with lyra_).\n");
|
|
813
|
+
apiKey = await askQuestion(rl, "Lyra API key: ", { secret: true });
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
if (apiKey) {
|
|
817
|
+
try {
|
|
818
|
+
const agents = await fetchUserAgentsByApiKey(apiBaseUrl, apiKey);
|
|
819
|
+
importedAgents = normalizePlatformAgents(agents);
|
|
820
|
+
output.write(`Synced ${importedAgents.length} agent(s) from your Lyra account.\n`);
|
|
821
|
+
} catch (error) {
|
|
822
|
+
output.write(`Could not sync your agents: ${error.message}. Continuing with catalog selections.\n`);
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
const chosenGroup = stackMode ? undefined : await chooseFlowGroup(rl);
|
|
827
|
+
let mode = options.mode;
|
|
828
|
+
if (mode !== "standalone" && mode !== "gated") {
|
|
829
|
+
mode = chosenGroup === "everyday" ? "gated" : await chooseMode(rl, mode);
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
if (mode === "gated" && !apiKey) {
|
|
833
|
+
output.write("Hosted packs need Lyra login. You can continue, but hosted packs will be marked as locked.\n");
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
const catalog = getDomainCatalog(mode);
|
|
837
|
+
const catalogWithHints = catalog.map((item) => ({
|
|
838
|
+
...item,
|
|
839
|
+
sourceType: "catalog",
|
|
840
|
+
hint: mode === "gated" && !apiKey ? "needs login" : "",
|
|
841
|
+
}));
|
|
842
|
+
const presetDomains = resolvePresetDomains(options.domains, catalogWithHints);
|
|
843
|
+
|
|
844
|
+
const dynamicGroups = [];
|
|
845
|
+
if (importedAgents.length > 0) {
|
|
846
|
+
dynamicGroups.push({ label: "Your agents", options: importedAgents });
|
|
847
|
+
}
|
|
848
|
+
dynamicGroups.push({
|
|
849
|
+
label: mode === "gated" ? "Create new (hosted verticals)" : "Create new (catalog domains)",
|
|
850
|
+
options: catalogWithHints,
|
|
851
|
+
});
|
|
852
|
+
|
|
853
|
+
if (stackMode && !presetDomains.length) throw new Error("Use --domains with a valid Coding or Engineering domain ID.");
|
|
854
|
+
const selected = presetDomains.length > 0
|
|
855
|
+
? presetDomains
|
|
856
|
+
: await selectManyGrouped(
|
|
857
|
+
rl,
|
|
858
|
+
"Select domains and/or your synced agents",
|
|
859
|
+
dynamicGroups,
|
|
860
|
+
[],
|
|
861
|
+
);
|
|
862
|
+
|
|
863
|
+
let selectedDomains = selected.map((entry) => {
|
|
864
|
+
if (entry.sourceType === "platform") {
|
|
865
|
+
return {
|
|
866
|
+
id: entry.id,
|
|
867
|
+
label: entry.label,
|
|
868
|
+
mode: "standalone",
|
|
869
|
+
sourceType: "platform",
|
|
870
|
+
agents: [
|
|
871
|
+
{
|
|
872
|
+
id: entry.importPayload.id,
|
|
873
|
+
slug: entry.importPayload.slug,
|
|
874
|
+
name: entry.importPayload.name,
|
|
875
|
+
description: entry.importPayload.description,
|
|
876
|
+
category: entry.importPayload.category,
|
|
877
|
+
icon: entry.importPayload.icon,
|
|
878
|
+
skills: entry.importPayload.skills,
|
|
879
|
+
requiresIntegration: entry.importPayload.integrations,
|
|
880
|
+
generatedFrom: entry.importPayload.generatedFrom,
|
|
881
|
+
systemPrompt: entry.importPayload.systemPrompt,
|
|
882
|
+
promptTemplateId: entry.importPayload.promptTemplateId,
|
|
883
|
+
runtimeHints: {
|
|
884
|
+
requiresRepoScan: true,
|
|
885
|
+
suggestedScanEndpoint: "/api/repositories/:id/scan",
|
|
886
|
+
suggestedPrEndpoint: "/api/repositories/:id/lyra-pr",
|
|
887
|
+
},
|
|
888
|
+
importPayload: entry.importPayload,
|
|
889
|
+
},
|
|
890
|
+
],
|
|
891
|
+
};
|
|
892
|
+
}
|
|
893
|
+
return {
|
|
894
|
+
...entry,
|
|
895
|
+
sourceType: entry.sourceType || "catalog",
|
|
896
|
+
};
|
|
897
|
+
});
|
|
898
|
+
|
|
899
|
+
if (selectedDomains.length === 0) {
|
|
900
|
+
throw new Error("Select at least one domain.");
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
selectedDomains = applyGatedLockIfLoggedOut(selectedDomains, Boolean(apiKey));
|
|
904
|
+
|
|
905
|
+
if (mode === "gated" && !apiKey) {
|
|
906
|
+
output.write("Enter the Lyra API key from the Lyra login UI. It will be stored in .lyra/credentials.json and ignored by .lyra/.gitignore.\n");
|
|
907
|
+
apiKey = await askQuestion(rl, "Lyra API key: ", { secret: true });
|
|
908
|
+
if (!apiKey) {
|
|
909
|
+
throw new Error("A Lyra API key is required for gated setup.");
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
const targetDir = path.resolve(options.dir || process.cwd());
|
|
914
|
+
const lyraDir = path.join(targetDir, ".lyra");
|
|
915
|
+
const coding = selectedDomains.some(domain => domain.id === "coding" || domain.id === "engineering-bootstrap");
|
|
916
|
+
if (options.stack !== undefined && (!coding || typeof options.stack !== "string")) {
|
|
917
|
+
throw new Error("Use --stack with a stack name and the Coding domain.");
|
|
918
|
+
}
|
|
919
|
+
if (options.detect && (!coding || options.stack)) throw new Error("Use --detect with the Coding domain instead of --stack.");
|
|
920
|
+
let stack = options.stack;
|
|
921
|
+
if (coding && !stack) {
|
|
922
|
+
const detect = options.detect || (input.isTTY && await askYesNo(rl, "Detect technologies from this project?", false));
|
|
923
|
+
if (detect) {
|
|
924
|
+
const recommendations = await recommendCodingStacks(targetDir, output);
|
|
925
|
+
if (recommendations.length && (options.detect || await askYesNo(rl, "Use these recommendations?", true))) stack = recommendations;
|
|
926
|
+
}
|
|
927
|
+
if (!stack && input.isTTY) stack = await selectCodingStack(rl, output);
|
|
928
|
+
}
|
|
929
|
+
let applyCoding;
|
|
930
|
+
if (coding) {
|
|
931
|
+
const existing = await fs.lstat(lyraDir).catch(error => {
|
|
932
|
+
if (error.code !== "ENOENT") throw error;
|
|
933
|
+
});
|
|
934
|
+
if (existing) throw new Error("This project already has .lyra. Run agent-lyra setup coding to add packs while keeping your files.");
|
|
935
|
+
const apply = await prepareCodingStack(targetDir, stack || [], output);
|
|
936
|
+
if (!stack || options.stack || options.detect || /^y(?:es)?$/i.test(await askQuestion(rl, "Create these coding files? [y/N] "))) applyCoding = apply;
|
|
937
|
+
}
|
|
938
|
+
await ensureEmptyOrApproved(rl, lyraDir, Boolean(options.force));
|
|
939
|
+
await writeScaffold({ targetDir, mode, selectedDomains, apiKey });
|
|
940
|
+
if (applyCoding) await applyCoding();
|
|
941
|
+
|
|
942
|
+
output.write(`Created ${lyraDir} for ${mode} mode with ${selectedDomains.length} domain(s).\n`);
|
|
943
|
+
} finally {
|
|
944
|
+
rl.close();
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
export async function runCli(argv = process.argv.slice(2)) {
|
|
949
|
+
const args = parseArgs(argv);
|
|
950
|
+
const [first, second] = args._;
|
|
951
|
+
const command = first === "lyra" ? second : first;
|
|
952
|
+
|
|
953
|
+
if (!command || command === "help" || args.help) {
|
|
954
|
+
printUsage();
|
|
955
|
+
return;
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
if (command === "init") {
|
|
959
|
+
await runInitWizard(args);
|
|
960
|
+
return;
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
throw new Error(`Unknown command: ${command}`);
|
|
964
|
+
}
|
|
965
|
+
|
|
966
966
|
export { GATED_DOMAINS, STANDALONE_DOMAINS };
|