agent-lyra 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -0
- package/bin/agent-lyra.js +8 -0
- package/package.json +5 -1
- package/src/catalog.js +132 -0
- package/src/init.js +360 -0
package/README.md
CHANGED
|
@@ -19,6 +19,35 @@ Installation has zero side effects:
|
|
|
19
19
|
- no network calls by package code
|
|
20
20
|
- no postinstall hooks
|
|
21
21
|
|
|
22
|
+
Initialization is explicit and happens only when the user runs the CLI.
|
|
23
|
+
|
|
24
|
+
## Init A Repo
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npx agent-lyra init
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Or after install:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
agent-lyra init
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Flow:
|
|
37
|
+
|
|
38
|
+
- choose `standalone` or `gated`
|
|
39
|
+
- standalone: select onboarding domains with `Space`, confirm with `Enter`
|
|
40
|
+
- gated: select hosted verticals, then enter the Lyra API key from the Lyra login UI
|
|
41
|
+
- the command creates a `.lyra/` folder in the current repo only after confirmation
|
|
42
|
+
|
|
43
|
+
Generated files:
|
|
44
|
+
|
|
45
|
+
- `.lyra/config.json`
|
|
46
|
+
- `.lyra/README.md`
|
|
47
|
+
- `.lyra/domains/<domain>/agents/*.json`
|
|
48
|
+
- `.lyra/credentials.json` only for gated mode
|
|
49
|
+
- `.lyra/.gitignore` to ignore the local credentials file
|
|
50
|
+
|
|
22
51
|
## Usage
|
|
23
52
|
|
|
24
53
|
```js
|
package/package.json
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-lyra",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Two-layer Lyra SDK with standalone local primitives and gated hosted agents.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
7
7
|
"types": "./src/index.d.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"agent-lyra": "./bin/agent-lyra.js"
|
|
10
|
+
},
|
|
8
11
|
"exports": {
|
|
9
12
|
".": "./src/index.js",
|
|
10
13
|
"./standalone": "./src/standalone/index.js",
|
|
11
14
|
"./gated": "./src/gated/index.js"
|
|
12
15
|
},
|
|
13
16
|
"files": [
|
|
17
|
+
"bin",
|
|
14
18
|
"src",
|
|
15
19
|
"README.md",
|
|
16
20
|
"LICENSE"
|
package/src/catalog.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
export const STANDALONE_DOMAINS = [
|
|
2
|
+
{
|
|
3
|
+
id: "general",
|
|
4
|
+
label: "General",
|
|
5
|
+
agents: [
|
|
6
|
+
{ id: "g1", slug: "news-summariser", name: "News summariser", description: "Daily briefings from any source." },
|
|
7
|
+
{ id: "g6", slug: "email-drafter", name: "Email drafter", description: "Context-aware email writing." },
|
|
8
|
+
{ id: "g7", slug: "web-researcher", name: "Web researcher", description: "Search, summarise, and cite sources." }
|
|
9
|
+
]
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
id: "coding",
|
|
13
|
+
label: "Engineering",
|
|
14
|
+
agents: [
|
|
15
|
+
{ id: "c1", slug: "dev-agent", name: "Dev agent", description: "Write, refactor, and explain code." },
|
|
16
|
+
{ id: "c3", slug: "code-reviewer", name: "Code reviewer", description: "Review pull requests and enforce standards." },
|
|
17
|
+
{ id: "c7", slug: "security-scanner", name: "Security scanner", description: "Identify vulnerabilities and suggest fixes." }
|
|
18
|
+
]
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
id: "finance",
|
|
22
|
+
label: "Finance",
|
|
23
|
+
agents: [
|
|
24
|
+
{ id: "f1", slug: "financial-analyst", name: "Financial analyst", description: "Ratios, forecasts, and variance analysis." },
|
|
25
|
+
{ id: "f3", slug: "market-analyst", name: "Market analyst", description: "Sector trends and competitor intelligence." },
|
|
26
|
+
{ id: "f5", slug: "budget-planner", name: "Budget planner", description: "Build and track budgets." }
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
id: "product",
|
|
31
|
+
label: "Product",
|
|
32
|
+
agents: [
|
|
33
|
+
{ id: "p1", slug: "prd-writer", name: "PRD writer", description: "Write product specs and user stories." },
|
|
34
|
+
{ id: "p2", slug: "roadmap-planner", name: "Roadmap planner", description: "Prioritize features and milestones." }
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
id: "marketing",
|
|
39
|
+
label: "Marketing",
|
|
40
|
+
agents: [
|
|
41
|
+
{ id: "m1", slug: "content-writer", name: "Content writer", description: "Blog posts, newsletters, and scripts." },
|
|
42
|
+
{ id: "m2", slug: "seo-agent", name: "SEO agent", description: "Keywords, meta, and on-page audits." }
|
|
43
|
+
]
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
id: "hr",
|
|
47
|
+
label: "HR",
|
|
48
|
+
agents: [
|
|
49
|
+
{ id: "h1", slug: "jd-writer", name: "JD writer", description: "Job descriptions by role and level." },
|
|
50
|
+
{ id: "h3", slug: "onboarding-planner", name: "Onboarding planner", description: "30-60-90 day onboarding plans." }
|
|
51
|
+
]
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
id: "legal",
|
|
55
|
+
label: "Legal",
|
|
56
|
+
agents: [
|
|
57
|
+
{ id: "l1", slug: "contract-reviewer", name: "Contract reviewer", description: "Flag clauses and summarize risks." },
|
|
58
|
+
{ id: "l3", slug: "compliance-checker", name: "Compliance checker", description: "GDPR, DPDP, and SOC2 readiness." }
|
|
59
|
+
]
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
id: "founders",
|
|
63
|
+
label: "Founders",
|
|
64
|
+
agents: [
|
|
65
|
+
{ id: "fo1", slug: "pitch-writer", name: "Pitch writer", description: "Decks, one-pagers, and investor emails." },
|
|
66
|
+
{ id: "fo4", slug: "okr-planner", name: "OKR planner", description: "Set and track company OKRs." }
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
export const GATED_VERTICALS = [
|
|
72
|
+
{
|
|
73
|
+
id: "hr",
|
|
74
|
+
label: "HR",
|
|
75
|
+
agents: [
|
|
76
|
+
{ id: "hosted-hr-ops", slug: "hosted-hr-ops", name: "Hosted HR Ops", description: "Hosted HR workflows and employee support." }
|
|
77
|
+
]
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
id: "sales",
|
|
81
|
+
label: "Sales",
|
|
82
|
+
agents: [
|
|
83
|
+
{ id: "hosted-sales-ops", slug: "hosted-sales-ops", name: "Hosted Sales Ops", description: "Hosted sales pipeline and revenue workflows." }
|
|
84
|
+
]
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
id: "support",
|
|
88
|
+
label: "Support",
|
|
89
|
+
agents: [
|
|
90
|
+
{ id: "hosted-support-desk", slug: "hosted-support-desk", name: "Hosted Support Desk", description: "Hosted customer support automation." }
|
|
91
|
+
]
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
id: "finance",
|
|
95
|
+
label: "Finance",
|
|
96
|
+
agents: [
|
|
97
|
+
{ id: "hosted-finance-analyst", slug: "hosted-finance-analyst", name: "Hosted Finance Analyst", description: "Hosted finance analysis and reporting." }
|
|
98
|
+
]
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
id: "coding",
|
|
102
|
+
label: "Coding",
|
|
103
|
+
agents: [
|
|
104
|
+
{ id: "hosted-coding-copilot", slug: "hosted-coding-copilot", name: "Hosted Coding Copilot", description: "Hosted software delivery workflows." }
|
|
105
|
+
]
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
id: "legal",
|
|
109
|
+
label: "Legal",
|
|
110
|
+
agents: [
|
|
111
|
+
{ id: "hosted-legal-review", slug: "hosted-legal-review", name: "Hosted Legal Review", description: "Hosted contract and policy review." }
|
|
112
|
+
]
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
id: "news",
|
|
116
|
+
label: "News",
|
|
117
|
+
agents: [
|
|
118
|
+
{ id: "hosted-news-brief", slug: "hosted-news-brief", name: "Hosted News Brief", description: "Hosted topic tracking and daily briefings." }
|
|
119
|
+
]
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
id: "markets",
|
|
123
|
+
label: "Markets",
|
|
124
|
+
agents: [
|
|
125
|
+
{ id: "hosted-markets-monitor", slug: "hosted-markets-monitor", name: "Hosted Markets Monitor", description: "Hosted market monitoring and summaries." }
|
|
126
|
+
]
|
|
127
|
+
}
|
|
128
|
+
];
|
|
129
|
+
|
|
130
|
+
export function getDomainCatalog(mode) {
|
|
131
|
+
return mode === "gated" ? GATED_VERTICALS : STANDALONE_DOMAINS;
|
|
132
|
+
}
|
package/src/init.js
ADDED
|
@@ -0,0 +1,360 @@
|
|
|
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_VERTICALS, STANDALONE_DOMAINS, getDomainCatalog } from "./catalog.js";
|
|
8
|
+
|
|
9
|
+
function parseArgs(argv = process.argv.slice(2)) {
|
|
10
|
+
const args = { _: [] };
|
|
11
|
+
|
|
12
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
13
|
+
const token = argv[index];
|
|
14
|
+
if (!token.startsWith("--")) {
|
|
15
|
+
args._.push(token);
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const [flag, inlineValue] = token.split("=", 2);
|
|
20
|
+
const key = flag.slice(2);
|
|
21
|
+
const next = argv[index + 1];
|
|
22
|
+
|
|
23
|
+
if (inlineValue !== undefined) {
|
|
24
|
+
args[key] = inlineValue;
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (!next || next.startsWith("--")) {
|
|
29
|
+
args[key] = true;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
args[key] = next;
|
|
34
|
+
index += 1;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return args;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function printUsage() {
|
|
41
|
+
output.write(`Usage:\n agent-lyra init\n\nOptions:\n --mode standalone|gated\n --domains coding,finance\n --api-key <key>\n --dir <target-directory>\n --force\n`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function printWelcomeBanner() {
|
|
45
|
+
output.write([
|
|
46
|
+
"",
|
|
47
|
+
" _ _ _ ",
|
|
48
|
+
" / \\\ __ _ ___ _ __ | |_ | | _ _ _ __ __ _ ",
|
|
49
|
+
" / _ \\\ / _` |/ _ \\ '_ \\| __| | | | | | | '__/ _` |",
|
|
50
|
+
" / ___ \\\ (_| | __/ | | | |_ | |__| |_| | | | (_| |",
|
|
51
|
+
"/_/ \\\_\\__, |\\___|_| |_|\\__| |_____\\__, |_| \\__,_|",
|
|
52
|
+
" |___/ |___/ ",
|
|
53
|
+
"",
|
|
54
|
+
" Local agents when you want control. Hosted agents when you want lift.",
|
|
55
|
+
"",
|
|
56
|
+
].join("\n"));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function askQuestion(rl, message, { secret = false } = {}) {
|
|
60
|
+
if (!secret) {
|
|
61
|
+
return (await rl.question(message)).trim();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const original = input.isTTY ? input.isTTY : false;
|
|
65
|
+
if (input.isTTY) {
|
|
66
|
+
input.setRawMode?.(true);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
output.write(message);
|
|
70
|
+
let buffer = "";
|
|
71
|
+
|
|
72
|
+
return await new Promise((resolve) => {
|
|
73
|
+
const onData = (chunk) => {
|
|
74
|
+
const value = String(chunk);
|
|
75
|
+
if (value === "\r" || value === "\n") {
|
|
76
|
+
input.off("data", onData);
|
|
77
|
+
output.write("\n");
|
|
78
|
+
if (input.isTTY && original) {
|
|
79
|
+
input.setRawMode?.(false);
|
|
80
|
+
}
|
|
81
|
+
resolve(buffer.trim());
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (value === "\u0003") {
|
|
86
|
+
process.exitCode = 1;
|
|
87
|
+
input.off("data", onData);
|
|
88
|
+
if (input.isTTY && original) {
|
|
89
|
+
input.setRawMode?.(false);
|
|
90
|
+
}
|
|
91
|
+
throw new Error("Cancelled.");
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (value === "\u007f") {
|
|
95
|
+
buffer = buffer.slice(0, -1);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
buffer += value;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
input.on("data", onData);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async function chooseMode(rl, currentMode) {
|
|
107
|
+
if (currentMode === "standalone" || currentMode === "gated") {
|
|
108
|
+
return currentMode;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
while (true) {
|
|
112
|
+
const answer = (await rl.question("Choose setup flow: [1] standalone [2] gated: ")).trim().toLowerCase();
|
|
113
|
+
if (answer === "1" || answer === "standalone" || answer === "s") {
|
|
114
|
+
return "standalone";
|
|
115
|
+
}
|
|
116
|
+
if (answer === "2" || answer === "gated" || answer === "g") {
|
|
117
|
+
return "gated";
|
|
118
|
+
}
|
|
119
|
+
output.write("Enter 1 for standalone or 2 for gated.\n");
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function clearScreen() {
|
|
124
|
+
output.write("\u001Bc");
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function renderMultiSelect(title, options, cursor, selected) {
|
|
128
|
+
clearScreen();
|
|
129
|
+
output.write(`${title}\n`);
|
|
130
|
+
output.write("Use ↑/↓ to move, Space to toggle, Enter to confirm.\n\n");
|
|
131
|
+
|
|
132
|
+
options.forEach((option, index) => {
|
|
133
|
+
const marker = selected.has(option.id) ? "[x]" : "[ ]";
|
|
134
|
+
const prefix = index === cursor ? ">" : " ";
|
|
135
|
+
output.write(`${prefix} ${marker} ${option.label}\n`);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async function selectMany(rl, title, options, presetIds = []) {
|
|
140
|
+
if (!input.isTTY || !output.isTTY) {
|
|
141
|
+
const answer = (await rl.question(`${title} (comma-separated ids): `)).trim();
|
|
142
|
+
const selectedIds = answer
|
|
143
|
+
? answer.split(",").map((value) => value.trim()).filter(Boolean)
|
|
144
|
+
: presetIds;
|
|
145
|
+
return options.filter((option) => selectedIds.includes(option.id));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
emitKeypressEvents(input);
|
|
149
|
+
input.setRawMode?.(true);
|
|
150
|
+
input.resume();
|
|
151
|
+
|
|
152
|
+
const selected = new Set(presetIds);
|
|
153
|
+
let cursor = 0;
|
|
154
|
+
renderMultiSelect(title, options, cursor, selected);
|
|
155
|
+
|
|
156
|
+
return await new Promise((resolve, reject) => {
|
|
157
|
+
const cleanup = () => {
|
|
158
|
+
input.setRawMode?.(false);
|
|
159
|
+
input.removeListener("keypress", onKeypress);
|
|
160
|
+
output.write("\n");
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const onKeypress = (_, key) => {
|
|
164
|
+
if (key?.name === "up") {
|
|
165
|
+
cursor = cursor === 0 ? options.length - 1 : cursor - 1;
|
|
166
|
+
renderMultiSelect(title, options, cursor, selected);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (key?.name === "down") {
|
|
170
|
+
cursor = cursor === options.length - 1 ? 0 : cursor + 1;
|
|
171
|
+
renderMultiSelect(title, options, cursor, selected);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (key?.name === "space") {
|
|
175
|
+
const current = options[cursor];
|
|
176
|
+
if (selected.has(current.id)) {
|
|
177
|
+
selected.delete(current.id);
|
|
178
|
+
} else {
|
|
179
|
+
selected.add(current.id);
|
|
180
|
+
}
|
|
181
|
+
renderMultiSelect(title, options, cursor, selected);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
if (key?.name === "return") {
|
|
185
|
+
cleanup();
|
|
186
|
+
resolve(options.filter((option) => selected.has(option.id)));
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (key?.ctrl && key.name === "c") {
|
|
190
|
+
cleanup();
|
|
191
|
+
reject(new Error("Cancelled."));
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
input.on("keypress", onKeypress);
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
async function ensureEmptyOrApproved(rl, rootDir, force) {
|
|
200
|
+
try {
|
|
201
|
+
await fs.access(rootDir);
|
|
202
|
+
if (force) {
|
|
203
|
+
await fs.rm(rootDir, { recursive: true, force: true });
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const answer = (await rl.question(`Directory ${rootDir} exists. Overwrite Lyra files? [y/N]: `)).trim().toLowerCase();
|
|
207
|
+
if (answer !== "y" && answer !== "yes") {
|
|
208
|
+
throw new Error("Aborted by user.");
|
|
209
|
+
}
|
|
210
|
+
await fs.rm(rootDir, { recursive: true, force: true });
|
|
211
|
+
} catch (error) {
|
|
212
|
+
if (error.code === "ENOENT") {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (error.message === "Aborted by user.") {
|
|
216
|
+
throw error;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function buildConfig(mode, selectedDomains, apiKeyProvided) {
|
|
222
|
+
return {
|
|
223
|
+
version: 1,
|
|
224
|
+
mode,
|
|
225
|
+
domains: selectedDomains.map((domain) => domain.id),
|
|
226
|
+
createdAt: new Date().toISOString(),
|
|
227
|
+
gated: mode === "gated"
|
|
228
|
+
? {
|
|
229
|
+
apiKeySource: apiKeyProvided ? ".lyra/credentials.json" : "env:LYRA_API_KEY",
|
|
230
|
+
verticals: selectedDomains.map((domain) => domain.id),
|
|
231
|
+
}
|
|
232
|
+
: undefined,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
async function writeDomainFiles(rootDir, mode, selectedDomains) {
|
|
237
|
+
for (const domain of selectedDomains) {
|
|
238
|
+
const domainDir = path.join(rootDir, "domains", domain.id, "agents");
|
|
239
|
+
await fs.mkdir(domainDir, { recursive: true });
|
|
240
|
+
|
|
241
|
+
for (const agent of domain.agents) {
|
|
242
|
+
const filePath = path.join(domainDir, `${agent.slug}.json`);
|
|
243
|
+
const body = {
|
|
244
|
+
id: agent.id,
|
|
245
|
+
name: agent.name,
|
|
246
|
+
domain: domain.id,
|
|
247
|
+
mode,
|
|
248
|
+
description: agent.description,
|
|
249
|
+
};
|
|
250
|
+
await fs.writeFile(filePath, `${JSON.stringify(body, null, 2)}\n`, "utf8");
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
async function writeScaffold({ targetDir, mode, selectedDomains, apiKey }) {
|
|
256
|
+
const lyraDir = path.join(targetDir, ".lyra");
|
|
257
|
+
await fs.mkdir(lyraDir, { recursive: true });
|
|
258
|
+
await fs.mkdir(path.join(lyraDir, "domains"), { recursive: true });
|
|
259
|
+
await fs.writeFile(path.join(lyraDir, ".gitignore"), "credentials.json\n", "utf8");
|
|
260
|
+
|
|
261
|
+
const config = buildConfig(mode, selectedDomains, Boolean(apiKey));
|
|
262
|
+
await fs.writeFile(path.join(lyraDir, "config.json"), `${JSON.stringify(config, null, 2)}\n`, "utf8");
|
|
263
|
+
|
|
264
|
+
if (mode === "gated" && apiKey) {
|
|
265
|
+
await fs.writeFile(
|
|
266
|
+
path.join(lyraDir, "credentials.json"),
|
|
267
|
+
`${JSON.stringify({ LYRA_API_KEY: apiKey }, null, 2)}\n`,
|
|
268
|
+
"utf8",
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const readme = [
|
|
273
|
+
"# .lyra",
|
|
274
|
+
"",
|
|
275
|
+
`Mode: ${mode}`,
|
|
276
|
+
"",
|
|
277
|
+
"Domains:",
|
|
278
|
+
...selectedDomains.map((domain) => `- ${domain.label} (${domain.id})`),
|
|
279
|
+
"",
|
|
280
|
+
mode === "gated"
|
|
281
|
+
? "Hosted setup stores the API key in .lyra/credentials.json, which is ignored by the local .lyra/.gitignore file."
|
|
282
|
+
: "Standalone setup keeps all orchestration local and side-effect free until you invoke your own flows.",
|
|
283
|
+
].join("\n");
|
|
284
|
+
await fs.writeFile(path.join(lyraDir, "README.md"), `${readme}\n`, "utf8");
|
|
285
|
+
|
|
286
|
+
await writeDomainFiles(lyraDir, mode, selectedDomains);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function resolvePresetDomains(rawDomains, catalog) {
|
|
290
|
+
if (!rawDomains || rawDomains === true) {
|
|
291
|
+
return [];
|
|
292
|
+
}
|
|
293
|
+
const requested = String(rawDomains)
|
|
294
|
+
.split(",")
|
|
295
|
+
.map((value) => value.trim().toLowerCase())
|
|
296
|
+
.filter(Boolean);
|
|
297
|
+
return catalog.filter((domain) => requested.includes(domain.id));
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export async function runInitWizard(options = {}) {
|
|
301
|
+
const rl = readline.createInterface({ input, output });
|
|
302
|
+
|
|
303
|
+
try {
|
|
304
|
+
printWelcomeBanner();
|
|
305
|
+
const mode = await chooseMode(rl, options.mode);
|
|
306
|
+
const catalog = getDomainCatalog(mode);
|
|
307
|
+
const presetDomains = resolvePresetDomains(options.domains, catalog);
|
|
308
|
+
const selectedDomains = presetDomains.length > 0
|
|
309
|
+
? presetDomains
|
|
310
|
+
: await selectMany(
|
|
311
|
+
rl,
|
|
312
|
+
mode === "gated"
|
|
313
|
+
? "Select hosted verticals"
|
|
314
|
+
: "Select standalone domains from the Lyra onboarding catalog",
|
|
315
|
+
catalog,
|
|
316
|
+
[],
|
|
317
|
+
);
|
|
318
|
+
|
|
319
|
+
if (selectedDomains.length === 0) {
|
|
320
|
+
throw new Error("Select at least one domain.");
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
let apiKey = options["api-key"];
|
|
324
|
+
if (mode === "gated" && !apiKey) {
|
|
325
|
+
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");
|
|
326
|
+
apiKey = await askQuestion(rl, "Lyra API key: ", { secret: true });
|
|
327
|
+
if (!apiKey) {
|
|
328
|
+
throw new Error("A Lyra API key is required for gated setup.");
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const targetDir = path.resolve(options.dir || process.cwd());
|
|
333
|
+
const lyraDir = path.join(targetDir, ".lyra");
|
|
334
|
+
await ensureEmptyOrApproved(rl, lyraDir, Boolean(options.force));
|
|
335
|
+
await writeScaffold({ targetDir, mode, selectedDomains, apiKey });
|
|
336
|
+
|
|
337
|
+
output.write(`Created ${lyraDir} for ${mode} mode with ${selectedDomains.length} domain(s).\n`);
|
|
338
|
+
} finally {
|
|
339
|
+
rl.close();
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export async function runCli(argv = process.argv.slice(2)) {
|
|
344
|
+
const args = parseArgs(argv);
|
|
345
|
+
const [command] = args._;
|
|
346
|
+
|
|
347
|
+
if (!command || command === "help" || args.help) {
|
|
348
|
+
printUsage();
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
if (command === "init") {
|
|
353
|
+
await runInitWizard(args);
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
throw new Error(`Unknown command: ${command}`);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
export { GATED_VERTICALS, STANDALONE_DOMAINS };
|