agent-lyra 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +301 -291
- package/bin/agent-lyra.js +51 -51
- package/bin/lyra-oss-preview.js +16 -16
- 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 +115 -72
- package/src/app-builder/manifest-contract.js +46 -46
- package/src/app-builder/native-adapter.js +29 -29
- package/src/app-builder/preview.js +35 -31
- 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 +31 -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 -64
- package/src/coding/detect-stack.mjs +110 -110
- package/src/coding/export.js +133 -133
- package/src/coding/setup.js +175 -175
- package/src/coding/skills/lyra-android/SKILL.md +37 -37
- package/src/coding/skills/lyra-angular/SKILL.md +37 -37
- package/src/coding/skills/lyra-cucumber/SKILL.md +37 -37
- package/src/coding/skills/lyra-dbt/SKILL.md +37 -37
- package/src/coding/skills/lyra-django/SKILL.md +37 -37
- package/src/coding/skills/lyra-docker/SKILL.md +37 -37
- package/src/coding/skills/lyra-dotnet/SKILL.md +37 -37
- package/src/coding/skills/lyra-express/SKILL.md +37 -37
- package/src/coding/skills/lyra-fastapi/SKILL.md +37 -37
- package/src/coding/skills/lyra-flutter/SKILL.md +37 -37
- package/src/coding/skills/lyra-github-actions/SKILL.md +37 -37
- package/src/coding/skills/lyra-gitlab-ci/SKILL.md +37 -37
- package/src/coding/skills/lyra-go/SKILL.md +37 -37
- package/src/coding/skills/lyra-ios/SKILL.md +37 -37
- package/src/coding/skills/lyra-kubernetes/SKILL.md +37 -37
- package/src/coding/skills/lyra-mongodb/SKILL.md +37 -37
- package/src/coding/skills/lyra-mysql/SKILL.md +37 -37
- package/src/coding/skills/lyra-nextjs/SKILL.md +37 -37
- package/src/coding/skills/lyra-node/SKILL.md +37 -37
- package/src/coding/skills/lyra-playwright/SKILL.md +37 -37
- package/src/coding/skills/lyra-postgresql/SKILL.md +37 -37
- package/src/coding/skills/lyra-python/SKILL.md +37 -37
- package/src/coding/skills/lyra-react/SKILL.md +37 -37
- package/src/coding/skills/lyra-react-native/SKILL.md +37 -37
- package/src/coding/skills/lyra-redis/SKILL.md +37 -37
- package/src/coding/skills/lyra-rust/SKILL.md +37 -37
- package/src/coding/skills/lyra-spark/SKILL.md +37 -37
- package/src/coding/skills/lyra-spring-boot/SKILL.md +37 -37
- package/src/coding/skills/lyra-svelte/SKILL.md +37 -37
- package/src/coding/skills/lyra-terraform/SKILL.md +37 -37
- package/src/coding/skills/lyra-typescript/SKILL.md +37 -37
- package/src/coding/skills/lyra-vue/SKILL.md +37 -37
- package/src/framework/agent.js +181 -181
- package/src/framework/mda.js +65 -65
- package/src/framework/run.py +111 -111
- 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 +960 -960
- package/src/intelligence/graphsnip-provider.d.ts +5 -5
- package/src/intelligence/graphsnip-provider.js +57 -57
- package/src/intelligence/lifecycle.js +25 -25
- package/src/memory/LICENSE +21 -21
- package/src/memory/README.md +5 -5
- package/src/memory/UPSTREAM.json +24 -24
- package/src/memory/bridge-cli.js +16 -16
- package/src/memory/bridge.js +18 -18
- package/src/memory/cli.js +21 -21
- package/src/memory/cloud-sync-actions.js +61 -61
- package/src/memory/contract.json +45 -45
- package/src/memory/index.d.ts +50 -50
- package/src/memory/index.js +7 -7
- package/src/memory/lifecycle.js +29 -29
- package/src/memory/local-cli.js +34 -34
- package/src/memory/local-store.js +209 -209
- package/src/memory/package.json +33 -33
- package/src/memory/proposals.js +90 -90
- package/src/memory/skills-cli.js +26 -26
- package/src/memory/standalone.d.ts +50 -50
- package/src/memory/standalone.js +1 -1
- 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/resource-files.js +18 -18
- package/src/runtime/contracts.d.ts +47 -47
- package/src/runtime/local-cli.js +161 -161
- package/src/runtime/mcp-stdio.js +111 -111
- package/src/runtime/orchestration.js +59 -59
- package/src/runtime/run-agent.js +54 -54
- package/src/standalone/index.d.ts +45 -45
- package/src/standalone/index.js +13 -13
- package/src/standalone/init.js +12 -12
- 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 +542 -345
- package/src/studio/export.js +83 -86
- package/src/studio/index.html +74 -37
- package/src/studio/memory-actions.js +37 -37
- package/src/studio/memory-panel.js +200 -200
- package/src/studio/project.js +308 -240
- 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 +164 -150
- package/src/studio/session.js +83 -83
- package/src/studio/studio.css +257 -10
- package/src/studio/sync.js +42 -42
- package/src/studio/workflow-editor.js +240 -0
- package/src/studio/workflow-sync.js +229 -157
|
@@ -1,110 +1,110 @@
|
|
|
1
|
-
import { lstat, readdir, readFile } from "node:fs/promises";
|
|
2
|
-
import { join, resolve } from "node:path";
|
|
3
|
-
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
|
-
|
|
5
|
-
const ignored = new Set(["node_modules", "dist", "build", "vendor", "coverage", "__pycache__", "target", "venv"]);
|
|
6
|
-
const signals = {
|
|
7
|
-
react: ["react"], nextjs: ["next"], typescript: ["typescript"], express: ["express"],
|
|
8
|
-
mongodb: ["mongodb", "mongoose"], postgresql: ["pg", "psycopg", "psycopg2", "asyncpg"],
|
|
9
|
-
fastapi: ["fastapi"], playwright: ["playwright", "@playwright/test", "playwright-core"],
|
|
10
|
-
cucumber: ["@cucumber/cucumber", "cucumber", "behave", "pytest-bdd"],
|
|
11
|
-
mysql: ["mysql", "mysql2", "mysqlclient", "pymysql"], redis: ["redis", "ioredis"],
|
|
12
|
-
"react-native": ["react-native"], dbt: ["dbt-core"], spark: ["pyspark"],
|
|
13
|
-
vue: ["vue"], angular: ["@angular/core"], svelte: ["svelte"], django: ["django"],
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export async function detectStack(root) {
|
|
17
|
-
const projects = new Map();
|
|
18
|
-
let visited = 0;
|
|
19
|
-
let truncated = false;
|
|
20
|
-
async function scan(folder, scope, depth) {
|
|
21
|
-
if (visited >= 400) { truncated = true; return; }
|
|
22
|
-
visited++;
|
|
23
|
-
if (!(await lstat(folder)).isDirectory()) return;
|
|
24
|
-
const entries = await readdir(folder, { withFileTypes: true });
|
|
25
|
-
entries.sort((a, b) => a.name.localeCompare(b.name, "en"));
|
|
26
|
-
const files = new Set(entries.filter(item => item.isFile()).map(item => item.name));
|
|
27
|
-
const add = (technology, file) => {
|
|
28
|
-
const evidence = scope === "." ? file : scope + "/" + file;
|
|
29
|
-
if (!projects.has(scope)) projects.set(scope, new Map());
|
|
30
|
-
const hits = projects.get(scope);
|
|
31
|
-
if (!hits.has(technology)) hits.set(technology, new Set());
|
|
32
|
-
hits.get(technology).add(evidence);
|
|
33
|
-
};
|
|
34
|
-
async function text(name) {
|
|
35
|
-
const path = join(folder, name);
|
|
36
|
-
const stat = await lstat(path);
|
|
37
|
-
if (!stat.isFile() || stat.size > 256_000) return "";
|
|
38
|
-
return (await readFile(path, "utf8")).replace(/^\uFEFF/, "");
|
|
39
|
-
}
|
|
40
|
-
for (const name of files) {
|
|
41
|
-
if (name === "package.json") {
|
|
42
|
-
let pkg;
|
|
43
|
-
try { pkg = JSON.parse(await text(name)); }
|
|
44
|
-
catch (error) { if (error instanceof SyntaxError) continue; throw error; }
|
|
45
|
-
if (!pkg || typeof pkg !== "object" || Array.isArray(pkg)) continue;
|
|
46
|
-
const deps = [pkg.dependencies, pkg.devDependencies, pkg.optionalDependencies];
|
|
47
|
-
if (!pkg.workspaces || pkg.engines?.node) add("node", name);
|
|
48
|
-
for (const [id, names] of Object.entries(signals)) {
|
|
49
|
-
if (names.some(dep => deps.some(section => section && Object.hasOwn(section, dep)))) add(id, name);
|
|
50
|
-
}
|
|
51
|
-
} else if (name === "pyproject.toml" || /^requirements(?:[-.][\w-]+)?\.txt$/.test(name)) {
|
|
52
|
-
add("python", name);
|
|
53
|
-
const content = await text(name);
|
|
54
|
-
for (const [id, names] of Object.entries(signals)) {
|
|
55
|
-
if (names.some(dep => /^[a-z][a-z0-9-]*$/.test(dep) && new RegExp("[\\s'\"]" + dep + "(?=[\\s'\"[=<>!,;~]|$)", "i").test(" " + content))) add(id, name);
|
|
56
|
-
}
|
|
57
|
-
} else if (/^playwright\.config\.[cm]?[jt]s$/.test(name)) add("playwright", name);
|
|
58
|
-
else if (/^cucumber\.(?:[cm]?js|json|ya?ml)$/.test(name)) add("cucumber", name);
|
|
59
|
-
else if (/^(?:Dockerfile(?:\..+)?|(?:docker-)?compose\.ya?ml)$/.test(name)) add("docker", name);
|
|
60
|
-
else if (name === ".gitlab-ci.yml") add("gitlab-ci", name);
|
|
61
|
-
else if (name === "go.mod") add("go", name);
|
|
62
|
-
else if (name === "Cargo.toml") add("rust", name);
|
|
63
|
-
else if (name === "pom.xml" || /^build\.gradle(?:\.kts)?$/.test(name)) {
|
|
64
|
-
const content = await text(name);
|
|
65
|
-
if (/org\.springframework\.boot/.test(content)) add("spring-boot", name);
|
|
66
|
-
if (/com\.android\.(?:application|library)/.test(content)) add("android", name);
|
|
67
|
-
}
|
|
68
|
-
else if (name === "pubspec.yaml" && /^\s*flutter:/m.test(await text(name))) add("flutter", name);
|
|
69
|
-
else if (name === "dbt_project.yml") add("dbt", name);
|
|
70
|
-
else if (name.endsWith(".tf")) add("terraform", name);
|
|
71
|
-
else if (/^kustomization\.ya?ml$/.test(name)) add("kubernetes", name);
|
|
72
|
-
else if (name.endsWith(".csproj")) add("dotnet", name);
|
|
73
|
-
}
|
|
74
|
-
if (entries.some(item => item.name === ".github" && item.isDirectory())) {
|
|
75
|
-
const workflows = join(folder, ".github", "workflows");
|
|
76
|
-
const stat = await lstat(workflows).catch(error => { if (error.code !== "ENOENT") throw error; });
|
|
77
|
-
if (stat?.isDirectory()) {
|
|
78
|
-
const workflow = (await readdir(workflows, { withFileTypes: true })).find(item => item.isFile() && /\.ya?ml$/.test(item.name));
|
|
79
|
-
if (workflow) add("github-actions", ".github/workflows/" + workflow.name);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
const xcode = entries.find(item => item.isDirectory() && item.name.endsWith(".xcodeproj"));
|
|
83
|
-
if (xcode) add("ios", xcode.name);
|
|
84
|
-
// Gherkin is a hint by itself. A project dependency or config identifies Cucumber.
|
|
85
|
-
const feature = [...files].find(name => name.endsWith(".feature"));
|
|
86
|
-
if (feature) add("gherkin", feature);
|
|
87
|
-
for (const child of entries) {
|
|
88
|
-
if (!child.isDirectory() || child.name.startsWith(".") || ignored.has(child.name)) continue;
|
|
89
|
-
if (depth >= 4 || visited >= 400) { truncated = true; continue; }
|
|
90
|
-
await scan(join(folder, child.name), scope === "." ? child.name : scope + "/" + child.name, depth + 1);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
await scan(root, ".", 0);
|
|
94
|
-
return {
|
|
95
|
-
truncated,
|
|
96
|
-
projects: [...projects].map(([scope, hits]) => ({
|
|
97
|
-
scope, technologies: [...hits].map(([id, evidence]) => ({ id, evidence: [...evidence] })),
|
|
98
|
-
})),
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) {
|
|
103
|
-
const root = resolve(process.argv[2] ?? fileURLToPath(new URL("../../", import.meta.url)));
|
|
104
|
-
try {
|
|
105
|
-
console.log(JSON.stringify(await detectStack(root), null, 2));
|
|
106
|
-
} catch (error) {
|
|
107
|
-
console.error(error.message);
|
|
108
|
-
process.exitCode = 1;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
1
|
+
import { lstat, readdir, readFile } from "node:fs/promises";
|
|
2
|
+
import { join, resolve } from "node:path";
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
|
+
|
|
5
|
+
const ignored = new Set(["node_modules", "dist", "build", "vendor", "coverage", "__pycache__", "target", "venv"]);
|
|
6
|
+
const signals = {
|
|
7
|
+
react: ["react"], nextjs: ["next"], typescript: ["typescript"], express: ["express"],
|
|
8
|
+
mongodb: ["mongodb", "mongoose"], postgresql: ["pg", "psycopg", "psycopg2", "asyncpg"],
|
|
9
|
+
fastapi: ["fastapi"], playwright: ["playwright", "@playwright/test", "playwright-core"],
|
|
10
|
+
cucumber: ["@cucumber/cucumber", "cucumber", "behave", "pytest-bdd"],
|
|
11
|
+
mysql: ["mysql", "mysql2", "mysqlclient", "pymysql"], redis: ["redis", "ioredis"],
|
|
12
|
+
"react-native": ["react-native"], dbt: ["dbt-core"], spark: ["pyspark"],
|
|
13
|
+
vue: ["vue"], angular: ["@angular/core"], svelte: ["svelte"], django: ["django"],
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export async function detectStack(root) {
|
|
17
|
+
const projects = new Map();
|
|
18
|
+
let visited = 0;
|
|
19
|
+
let truncated = false;
|
|
20
|
+
async function scan(folder, scope, depth) {
|
|
21
|
+
if (visited >= 400) { truncated = true; return; }
|
|
22
|
+
visited++;
|
|
23
|
+
if (!(await lstat(folder)).isDirectory()) return;
|
|
24
|
+
const entries = await readdir(folder, { withFileTypes: true });
|
|
25
|
+
entries.sort((a, b) => a.name.localeCompare(b.name, "en"));
|
|
26
|
+
const files = new Set(entries.filter(item => item.isFile()).map(item => item.name));
|
|
27
|
+
const add = (technology, file) => {
|
|
28
|
+
const evidence = scope === "." ? file : scope + "/" + file;
|
|
29
|
+
if (!projects.has(scope)) projects.set(scope, new Map());
|
|
30
|
+
const hits = projects.get(scope);
|
|
31
|
+
if (!hits.has(technology)) hits.set(technology, new Set());
|
|
32
|
+
hits.get(technology).add(evidence);
|
|
33
|
+
};
|
|
34
|
+
async function text(name) {
|
|
35
|
+
const path = join(folder, name);
|
|
36
|
+
const stat = await lstat(path);
|
|
37
|
+
if (!stat.isFile() || stat.size > 256_000) return "";
|
|
38
|
+
return (await readFile(path, "utf8")).replace(/^\uFEFF/, "");
|
|
39
|
+
}
|
|
40
|
+
for (const name of files) {
|
|
41
|
+
if (name === "package.json") {
|
|
42
|
+
let pkg;
|
|
43
|
+
try { pkg = JSON.parse(await text(name)); }
|
|
44
|
+
catch (error) { if (error instanceof SyntaxError) continue; throw error; }
|
|
45
|
+
if (!pkg || typeof pkg !== "object" || Array.isArray(pkg)) continue;
|
|
46
|
+
const deps = [pkg.dependencies, pkg.devDependencies, pkg.optionalDependencies];
|
|
47
|
+
if (!pkg.workspaces || pkg.engines?.node) add("node", name);
|
|
48
|
+
for (const [id, names] of Object.entries(signals)) {
|
|
49
|
+
if (names.some(dep => deps.some(section => section && Object.hasOwn(section, dep)))) add(id, name);
|
|
50
|
+
}
|
|
51
|
+
} else if (name === "pyproject.toml" || /^requirements(?:[-.][\w-]+)?\.txt$/.test(name)) {
|
|
52
|
+
add("python", name);
|
|
53
|
+
const content = await text(name);
|
|
54
|
+
for (const [id, names] of Object.entries(signals)) {
|
|
55
|
+
if (names.some(dep => /^[a-z][a-z0-9-]*$/.test(dep) && new RegExp("[\\s'\"]" + dep + "(?=[\\s'\"[=<>!,;~]|$)", "i").test(" " + content))) add(id, name);
|
|
56
|
+
}
|
|
57
|
+
} else if (/^playwright\.config\.[cm]?[jt]s$/.test(name)) add("playwright", name);
|
|
58
|
+
else if (/^cucumber\.(?:[cm]?js|json|ya?ml)$/.test(name)) add("cucumber", name);
|
|
59
|
+
else if (/^(?:Dockerfile(?:\..+)?|(?:docker-)?compose\.ya?ml)$/.test(name)) add("docker", name);
|
|
60
|
+
else if (name === ".gitlab-ci.yml") add("gitlab-ci", name);
|
|
61
|
+
else if (name === "go.mod") add("go", name);
|
|
62
|
+
else if (name === "Cargo.toml") add("rust", name);
|
|
63
|
+
else if (name === "pom.xml" || /^build\.gradle(?:\.kts)?$/.test(name)) {
|
|
64
|
+
const content = await text(name);
|
|
65
|
+
if (/org\.springframework\.boot/.test(content)) add("spring-boot", name);
|
|
66
|
+
if (/com\.android\.(?:application|library)/.test(content)) add("android", name);
|
|
67
|
+
}
|
|
68
|
+
else if (name === "pubspec.yaml" && /^\s*flutter:/m.test(await text(name))) add("flutter", name);
|
|
69
|
+
else if (name === "dbt_project.yml") add("dbt", name);
|
|
70
|
+
else if (name.endsWith(".tf")) add("terraform", name);
|
|
71
|
+
else if (/^kustomization\.ya?ml$/.test(name)) add("kubernetes", name);
|
|
72
|
+
else if (name.endsWith(".csproj")) add("dotnet", name);
|
|
73
|
+
}
|
|
74
|
+
if (entries.some(item => item.name === ".github" && item.isDirectory())) {
|
|
75
|
+
const workflows = join(folder, ".github", "workflows");
|
|
76
|
+
const stat = await lstat(workflows).catch(error => { if (error.code !== "ENOENT") throw error; });
|
|
77
|
+
if (stat?.isDirectory()) {
|
|
78
|
+
const workflow = (await readdir(workflows, { withFileTypes: true })).find(item => item.isFile() && /\.ya?ml$/.test(item.name));
|
|
79
|
+
if (workflow) add("github-actions", ".github/workflows/" + workflow.name);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const xcode = entries.find(item => item.isDirectory() && item.name.endsWith(".xcodeproj"));
|
|
83
|
+
if (xcode) add("ios", xcode.name);
|
|
84
|
+
// Gherkin is a hint by itself. A project dependency or config identifies Cucumber.
|
|
85
|
+
const feature = [...files].find(name => name.endsWith(".feature"));
|
|
86
|
+
if (feature) add("gherkin", feature);
|
|
87
|
+
for (const child of entries) {
|
|
88
|
+
if (!child.isDirectory() || child.name.startsWith(".") || ignored.has(child.name)) continue;
|
|
89
|
+
if (depth >= 4 || visited >= 400) { truncated = true; continue; }
|
|
90
|
+
await scan(join(folder, child.name), scope === "." ? child.name : scope + "/" + child.name, depth + 1);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
await scan(root, ".", 0);
|
|
94
|
+
return {
|
|
95
|
+
truncated,
|
|
96
|
+
projects: [...projects].map(([scope, hits]) => ({
|
|
97
|
+
scope, technologies: [...hits].map(([id, evidence]) => ({ id, evidence: [...evidence] })),
|
|
98
|
+
})),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) {
|
|
103
|
+
const root = resolve(process.argv[2] ?? fileURLToPath(new URL("../../", import.meta.url)));
|
|
104
|
+
try {
|
|
105
|
+
console.log(JSON.stringify(await detectStack(root), null, 2));
|
|
106
|
+
} catch (error) {
|
|
107
|
+
console.error(error.message);
|
|
108
|
+
process.exitCode = 1;
|
|
109
|
+
}
|
|
110
|
+
}
|
package/src/coding/export.js
CHANGED
|
@@ -1,133 +1,133 @@
|
|
|
1
|
-
import { lstat, readFile, readdir } from "node:fs/promises";
|
|
2
|
-
import { join, resolve, basename, dirname } from "node:path";
|
|
3
|
-
import { resourceFiles } from "../resource-files.js";
|
|
4
|
-
import { createInterface } from "node:readline/promises";
|
|
5
|
-
import { parseArgs } from "node:util";
|
|
6
|
-
import { readLocalAgent } from "../studio/project.js";
|
|
7
|
-
import { prepareProjectFiles } from "./setup.js";
|
|
8
|
-
|
|
9
|
-
const formats = {
|
|
10
|
-
claude: { marker: ".claude", skills: ".claude/skills", agents: ".claude/agents", extension: ".md" },
|
|
11
|
-
codex: { marker: ".codex", skills: ".agents/skills", agents: ".codex/agents", extension: ".toml" },
|
|
12
|
-
copilot: { marker: ".github", skills: ".github/skills", agents: ".github/agents", extension: ".agent.md" },
|
|
13
|
-
};
|
|
14
|
-
const safeName = /^[a-z0-9][a-z0-9-]{0,95}$/;
|
|
15
|
-
const missing = error => {
|
|
16
|
-
if (error.code !== "ENOENT") throw error;
|
|
17
|
-
return null;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
async function entries(path) {
|
|
21
|
-
const stat = await lstat(path).catch(missing);
|
|
22
|
-
if (!stat) return [];
|
|
23
|
-
if (!stat.isDirectory()) throw new Error("Expected a regular project directory: " + path);
|
|
24
|
-
return readdir(path, { withFileTypes: true });
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async function text(path) {
|
|
28
|
-
const stat = await lstat(path).catch(missing);
|
|
29
|
-
if (!stat?.isFile() || stat.size > 64_000) return "";
|
|
30
|
-
return (await readFile(path, "utf8")).replace(/^\uFEFF/, "").replace(/\r\n/g, "\n");
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function scalar(header, key) {
|
|
34
|
-
const value = new RegExp("^" + key + ":[ \t]*(.+)$", "m").exec(header)?.[1]?.trim();
|
|
35
|
-
if (!value) return "";
|
|
36
|
-
if (!value.startsWith('"')) return value.replace(/^'|'$/g, "");
|
|
37
|
-
try {
|
|
38
|
-
const parsed = JSON.parse(value);
|
|
39
|
-
return typeof parsed === "string" ? parsed : "";
|
|
40
|
-
} catch { return ""; }
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async function sources(root, output) {
|
|
44
|
-
await entries(join(root, ".lyra"));
|
|
45
|
-
const agents = new Map();
|
|
46
|
-
const skills = new Map();
|
|
47
|
-
const agentDir = join(root, ".lyra", "agents");
|
|
48
|
-
for (const name of await resourceFiles(agentDir, ".md")) {
|
|
49
|
-
const entry = { name };
|
|
50
|
-
const source = await text(join(agentDir, name));
|
|
51
|
-
const item = readLocalAgent(source);
|
|
52
|
-
if (!item || item.source !== "local" || !safeName.test(item.id.slice(6))) {
|
|
53
|
-
output.write("Skip unsupported agent " + JSON.stringify(entry.name) + "\n");
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
const id = item.id.slice(6);
|
|
57
|
-
if (agents.has(id)) throw new Error("Duplicate Lyra agent ID: " + id);
|
|
58
|
-
agents.set(id, item);
|
|
59
|
-
}
|
|
60
|
-
const skillDir = join(root, ".lyra", "skills");
|
|
61
|
-
for (const relative of await resourceFiles(skillDir, "SKILL.md")) {
|
|
62
|
-
if (basename(relative) !== "SKILL.md") continue;
|
|
63
|
-
const entry = { name: basename(dirname(relative)) };
|
|
64
|
-
if (!safeName.test(entry.name)) continue;
|
|
65
|
-
const source = await text(join(skillDir, relative));
|
|
66
|
-
const front = /^---\n([\s\S]*?)\n---\n/.exec(source);
|
|
67
|
-
const name = front && scalar(front[1], "name");
|
|
68
|
-
const description = front && scalar(front[1], "description");
|
|
69
|
-
if (!name || name !== entry.name || !description) {
|
|
70
|
-
output.write("Skip skill without matching name and description " + JSON.stringify(entry.name) + "\n");
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
skills.set(name, ["---", "name: " + name, "description: " + JSON.stringify(description), "---", source.slice(front[0].length)].join("\n"));
|
|
74
|
-
}
|
|
75
|
-
return { agents, skills };
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function renderAgent(target, id, agent) {
|
|
79
|
-
const description = "AgentLyra project profile for " + agent.name + ".";
|
|
80
|
-
if (target === "codex") {
|
|
81
|
-
const quoted = value => JSON.stringify(value).replace(/\u007f/g, "\\u007F");
|
|
82
|
-
return "name = " + quoted(id) + "\ndescription = " + quoted(description) +
|
|
83
|
-
"\ndeveloper_instructions = " + quoted(agent.prompt) + "\n";
|
|
84
|
-
}
|
|
85
|
-
return ["---", "name: " + id, "description: " + JSON.stringify(description), "---", "", agent.prompt, ""].join("\n");
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export async function runCodingExport(args, { input = process.stdin, output = process.stdout, root = process.cwd() } = {}) {
|
|
89
|
-
const { values } = parseArgs({ args, options: {
|
|
90
|
-
to: { type: "string" }, dir: { type: "string" }, preview: { type: "boolean" },
|
|
91
|
-
yes: { type: "boolean", short: "y" }, help: { type: "boolean", short: "h" },
|
|
92
|
-
} });
|
|
93
|
-
if (values.help) {
|
|
94
|
-
output.write("Usage: agent-lyra setup coding export [--to claude,codex,copilot] [--preview | --yes] [--dir <folder>]\n");
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
if (!input.isTTY && (!values.to || (!values.preview && !values.yes))) {
|
|
98
|
-
throw new Error("Provide --to with --preview or --yes when running without an interactive terminal.");
|
|
99
|
-
}
|
|
100
|
-
const project = resolve(root, values.dir ?? ".");
|
|
101
|
-
const rl = input.isTTY ? createInterface({ input, output }) : null;
|
|
102
|
-
try {
|
|
103
|
-
let choice = values.to;
|
|
104
|
-
if (!choice) {
|
|
105
|
-
const existing = new Set((await entries(project)).filter(item => item.isDirectory() || item.isFile()).map(item => item.name));
|
|
106
|
-
const hints = Object.entries(formats).filter(([id, { marker }]) => existing.has(marker) ||
|
|
107
|
-
(id === "codex" && existing.has(".agents")) || (id === "claude" && existing.has("CLAUDE.md")));
|
|
108
|
-
if (hints.length) output.write("Project files suggest: " + hints.map(([id]) => id).join(", ") + "\n");
|
|
109
|
-
choice = (await rl.question("Export to claude, codex, or copilot (comma separated, Enter to cancel): ")).trim();
|
|
110
|
-
if (!choice) return;
|
|
111
|
-
}
|
|
112
|
-
const targets = [...new Set(choice.split(",").map(name => name.trim().toLowerCase()))];
|
|
113
|
-
if (targets.some(target => !Object.hasOwn(formats, target))) throw new Error("Choose claude, codex, or copilot.");
|
|
114
|
-
const { agents, skills } = await sources(project, output);
|
|
115
|
-
const files = new Map();
|
|
116
|
-
for (const target of targets) {
|
|
117
|
-
const format = formats[target];
|
|
118
|
-
for (const [id, agent] of agents) files.set(format.agents + "/" + id + format.extension, renderAgent(target, id, agent));
|
|
119
|
-
for (const [name, skill] of skills) files.set(format.skills + "/" + name + "/SKILL.md", skill);
|
|
120
|
-
}
|
|
121
|
-
if (!files.size) {
|
|
122
|
-
output.write("No exportable Markdown agents or skills found in .lyra. Run setup coding first.\n");
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
output.write("Export includes instructions only. Tool permissions, hooks, scripts, and other skill resources stay in their original project files.\n");
|
|
126
|
-
const apply = await prepareProjectFiles(project, files, output);
|
|
127
|
-
if (values.preview || (!values.yes && !/^y(?:es)?$/i.test((await rl.question("Write these exports? [y/N] ")).trim()))) return;
|
|
128
|
-
await apply();
|
|
129
|
-
output.write("Assistant export complete. Existing files were preserved.\n");
|
|
130
|
-
} finally {
|
|
131
|
-
rl?.close();
|
|
132
|
-
}
|
|
133
|
-
}
|
|
1
|
+
import { lstat, readFile, readdir } from "node:fs/promises";
|
|
2
|
+
import { join, resolve, basename, dirname } from "node:path";
|
|
3
|
+
import { resourceFiles } from "../resource-files.js";
|
|
4
|
+
import { createInterface } from "node:readline/promises";
|
|
5
|
+
import { parseArgs } from "node:util";
|
|
6
|
+
import { readLocalAgent } from "../studio/project.js";
|
|
7
|
+
import { prepareProjectFiles } from "./setup.js";
|
|
8
|
+
|
|
9
|
+
const formats = {
|
|
10
|
+
claude: { marker: ".claude", skills: ".claude/skills", agents: ".claude/agents", extension: ".md" },
|
|
11
|
+
codex: { marker: ".codex", skills: ".agents/skills", agents: ".codex/agents", extension: ".toml" },
|
|
12
|
+
copilot: { marker: ".github", skills: ".github/skills", agents: ".github/agents", extension: ".agent.md" },
|
|
13
|
+
};
|
|
14
|
+
const safeName = /^[a-z0-9][a-z0-9-]{0,95}$/;
|
|
15
|
+
const missing = error => {
|
|
16
|
+
if (error.code !== "ENOENT") throw error;
|
|
17
|
+
return null;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
async function entries(path) {
|
|
21
|
+
const stat = await lstat(path).catch(missing);
|
|
22
|
+
if (!stat) return [];
|
|
23
|
+
if (!stat.isDirectory()) throw new Error("Expected a regular project directory: " + path);
|
|
24
|
+
return readdir(path, { withFileTypes: true });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function text(path) {
|
|
28
|
+
const stat = await lstat(path).catch(missing);
|
|
29
|
+
if (!stat?.isFile() || stat.size > 64_000) return "";
|
|
30
|
+
return (await readFile(path, "utf8")).replace(/^\uFEFF/, "").replace(/\r\n/g, "\n");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function scalar(header, key) {
|
|
34
|
+
const value = new RegExp("^" + key + ":[ \t]*(.+)$", "m").exec(header)?.[1]?.trim();
|
|
35
|
+
if (!value) return "";
|
|
36
|
+
if (!value.startsWith('"')) return value.replace(/^'|'$/g, "");
|
|
37
|
+
try {
|
|
38
|
+
const parsed = JSON.parse(value);
|
|
39
|
+
return typeof parsed === "string" ? parsed : "";
|
|
40
|
+
} catch { return ""; }
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function sources(root, output) {
|
|
44
|
+
await entries(join(root, ".lyra"));
|
|
45
|
+
const agents = new Map();
|
|
46
|
+
const skills = new Map();
|
|
47
|
+
const agentDir = join(root, ".lyra", "agents");
|
|
48
|
+
for (const name of await resourceFiles(agentDir, ".md")) {
|
|
49
|
+
const entry = { name };
|
|
50
|
+
const source = await text(join(agentDir, name));
|
|
51
|
+
const item = readLocalAgent(source);
|
|
52
|
+
if (!item || item.source !== "local" || !safeName.test(item.id.slice(6))) {
|
|
53
|
+
output.write("Skip unsupported agent " + JSON.stringify(entry.name) + "\n");
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const id = item.id.slice(6);
|
|
57
|
+
if (agents.has(id)) throw new Error("Duplicate Lyra agent ID: " + id);
|
|
58
|
+
agents.set(id, item);
|
|
59
|
+
}
|
|
60
|
+
const skillDir = join(root, ".lyra", "skills");
|
|
61
|
+
for (const relative of await resourceFiles(skillDir, "SKILL.md")) {
|
|
62
|
+
if (basename(relative) !== "SKILL.md") continue;
|
|
63
|
+
const entry = { name: basename(dirname(relative)) };
|
|
64
|
+
if (!safeName.test(entry.name)) continue;
|
|
65
|
+
const source = await text(join(skillDir, relative));
|
|
66
|
+
const front = /^---\n([\s\S]*?)\n---\n/.exec(source);
|
|
67
|
+
const name = front && scalar(front[1], "name");
|
|
68
|
+
const description = front && scalar(front[1], "description");
|
|
69
|
+
if (!name || name !== entry.name || !description) {
|
|
70
|
+
output.write("Skip skill without matching name and description " + JSON.stringify(entry.name) + "\n");
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
skills.set(name, ["---", "name: " + name, "description: " + JSON.stringify(description), "---", source.slice(front[0].length)].join("\n"));
|
|
74
|
+
}
|
|
75
|
+
return { agents, skills };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function renderAgent(target, id, agent) {
|
|
79
|
+
const description = "AgentLyra project profile for " + agent.name + ".";
|
|
80
|
+
if (target === "codex") {
|
|
81
|
+
const quoted = value => JSON.stringify(value).replace(/\u007f/g, "\\u007F");
|
|
82
|
+
return "name = " + quoted(id) + "\ndescription = " + quoted(description) +
|
|
83
|
+
"\ndeveloper_instructions = " + quoted(agent.prompt) + "\n";
|
|
84
|
+
}
|
|
85
|
+
return ["---", "name: " + id, "description: " + JSON.stringify(description), "---", "", agent.prompt, ""].join("\n");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export async function runCodingExport(args, { input = process.stdin, output = process.stdout, root = process.cwd() } = {}) {
|
|
89
|
+
const { values } = parseArgs({ args, options: {
|
|
90
|
+
to: { type: "string" }, dir: { type: "string" }, preview: { type: "boolean" },
|
|
91
|
+
yes: { type: "boolean", short: "y" }, help: { type: "boolean", short: "h" },
|
|
92
|
+
} });
|
|
93
|
+
if (values.help) {
|
|
94
|
+
output.write("Usage: agent-lyra setup coding export [--to claude,codex,copilot] [--preview | --yes] [--dir <folder>]\n");
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (!input.isTTY && (!values.to || (!values.preview && !values.yes))) {
|
|
98
|
+
throw new Error("Provide --to with --preview or --yes when running without an interactive terminal.");
|
|
99
|
+
}
|
|
100
|
+
const project = resolve(root, values.dir ?? ".");
|
|
101
|
+
const rl = input.isTTY ? createInterface({ input, output }) : null;
|
|
102
|
+
try {
|
|
103
|
+
let choice = values.to;
|
|
104
|
+
if (!choice) {
|
|
105
|
+
const existing = new Set((await entries(project)).filter(item => item.isDirectory() || item.isFile()).map(item => item.name));
|
|
106
|
+
const hints = Object.entries(formats).filter(([id, { marker }]) => existing.has(marker) ||
|
|
107
|
+
(id === "codex" && existing.has(".agents")) || (id === "claude" && existing.has("CLAUDE.md")));
|
|
108
|
+
if (hints.length) output.write("Project files suggest: " + hints.map(([id]) => id).join(", ") + "\n");
|
|
109
|
+
choice = (await rl.question("Export to claude, codex, or copilot (comma separated, Enter to cancel): ")).trim();
|
|
110
|
+
if (!choice) return;
|
|
111
|
+
}
|
|
112
|
+
const targets = [...new Set(choice.split(",").map(name => name.trim().toLowerCase()))];
|
|
113
|
+
if (targets.some(target => !Object.hasOwn(formats, target))) throw new Error("Choose claude, codex, or copilot.");
|
|
114
|
+
const { agents, skills } = await sources(project, output);
|
|
115
|
+
const files = new Map();
|
|
116
|
+
for (const target of targets) {
|
|
117
|
+
const format = formats[target];
|
|
118
|
+
for (const [id, agent] of agents) files.set(format.agents + "/" + id + format.extension, renderAgent(target, id, agent));
|
|
119
|
+
for (const [name, skill] of skills) files.set(format.skills + "/" + name + "/SKILL.md", skill);
|
|
120
|
+
}
|
|
121
|
+
if (!files.size) {
|
|
122
|
+
output.write("No exportable Markdown agents or skills found in .lyra. Run setup coding first.\n");
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
output.write("Export includes instructions only. Tool permissions, hooks, scripts, and other skill resources stay in their original project files.\n");
|
|
126
|
+
const apply = await prepareProjectFiles(project, files, output);
|
|
127
|
+
if (values.preview || (!values.yes && !/^y(?:es)?$/i.test((await rl.question("Write these exports? [y/N] ")).trim()))) return;
|
|
128
|
+
await apply();
|
|
129
|
+
output.write("Assistant export complete. Existing files were preserved.\n");
|
|
130
|
+
} finally {
|
|
131
|
+
rl?.close();
|
|
132
|
+
}
|
|
133
|
+
}
|