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.
Files changed (126) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +301 -291
  3. package/bin/agent-lyra.js +51 -51
  4. package/bin/lyra-oss-preview.js +16 -16
  5. package/package.json +60 -60
  6. package/src/app-builder/export.js +109 -109
  7. package/src/app-builder/gateway.js +62 -62
  8. package/src/app-builder/init.js +115 -72
  9. package/src/app-builder/manifest-contract.js +46 -46
  10. package/src/app-builder/native-adapter.js +29 -29
  11. package/src/app-builder/preview.js +35 -31
  12. package/src/app-builder/publish.js +14 -14
  13. package/src/app-builder/saved-app.js +70 -70
  14. package/src/app-builder/saved-preview-browser.js +33 -33
  15. package/src/app-builder/saved-preview.html +24 -24
  16. package/src/app-builder/saved-preview.js +61 -61
  17. package/src/app-builder/support-manifest.js +50 -50
  18. package/src/app-builder/support-template/manifest.json +55 -55
  19. package/src/app-builder/support-template/support-preview.html +56 -56
  20. package/src/app-builder/support-template/support-preview.js +37 -37
  21. package/src/app-builder/support-template/support-preview.mjs +67 -67
  22. package/src/app-builder/support-template/support-workflow.mjs +36 -36
  23. package/src/app-builder/use.js +37 -37
  24. package/src/app-builder/validate.js +31 -21
  25. package/src/app-builder/value-schema.js +37 -37
  26. package/src/catalog.js +147 -147
  27. package/src/coding/catalog.js +56 -56
  28. package/src/coding/cloud-catalog.js +64 -64
  29. package/src/coding/detect-stack.mjs +110 -110
  30. package/src/coding/export.js +133 -133
  31. package/src/coding/setup.js +175 -175
  32. package/src/coding/skills/lyra-android/SKILL.md +37 -37
  33. package/src/coding/skills/lyra-angular/SKILL.md +37 -37
  34. package/src/coding/skills/lyra-cucumber/SKILL.md +37 -37
  35. package/src/coding/skills/lyra-dbt/SKILL.md +37 -37
  36. package/src/coding/skills/lyra-django/SKILL.md +37 -37
  37. package/src/coding/skills/lyra-docker/SKILL.md +37 -37
  38. package/src/coding/skills/lyra-dotnet/SKILL.md +37 -37
  39. package/src/coding/skills/lyra-express/SKILL.md +37 -37
  40. package/src/coding/skills/lyra-fastapi/SKILL.md +37 -37
  41. package/src/coding/skills/lyra-flutter/SKILL.md +37 -37
  42. package/src/coding/skills/lyra-github-actions/SKILL.md +37 -37
  43. package/src/coding/skills/lyra-gitlab-ci/SKILL.md +37 -37
  44. package/src/coding/skills/lyra-go/SKILL.md +37 -37
  45. package/src/coding/skills/lyra-ios/SKILL.md +37 -37
  46. package/src/coding/skills/lyra-kubernetes/SKILL.md +37 -37
  47. package/src/coding/skills/lyra-mongodb/SKILL.md +37 -37
  48. package/src/coding/skills/lyra-mysql/SKILL.md +37 -37
  49. package/src/coding/skills/lyra-nextjs/SKILL.md +37 -37
  50. package/src/coding/skills/lyra-node/SKILL.md +37 -37
  51. package/src/coding/skills/lyra-playwright/SKILL.md +37 -37
  52. package/src/coding/skills/lyra-postgresql/SKILL.md +37 -37
  53. package/src/coding/skills/lyra-python/SKILL.md +37 -37
  54. package/src/coding/skills/lyra-react/SKILL.md +37 -37
  55. package/src/coding/skills/lyra-react-native/SKILL.md +37 -37
  56. package/src/coding/skills/lyra-redis/SKILL.md +37 -37
  57. package/src/coding/skills/lyra-rust/SKILL.md +37 -37
  58. package/src/coding/skills/lyra-spark/SKILL.md +37 -37
  59. package/src/coding/skills/lyra-spring-boot/SKILL.md +37 -37
  60. package/src/coding/skills/lyra-svelte/SKILL.md +37 -37
  61. package/src/coding/skills/lyra-terraform/SKILL.md +37 -37
  62. package/src/coding/skills/lyra-typescript/SKILL.md +37 -37
  63. package/src/coding/skills/lyra-vue/SKILL.md +37 -37
  64. package/src/framework/agent.js +181 -181
  65. package/src/framework/mda.js +65 -65
  66. package/src/framework/run.py +111 -111
  67. package/src/gated/hostedAgents.js +56 -56
  68. package/src/gated/index.d.ts +25 -25
  69. package/src/gated/index.js +5 -5
  70. package/src/index.d.ts +2 -2
  71. package/src/index.js +2 -2
  72. package/src/init.js +960 -960
  73. package/src/intelligence/graphsnip-provider.d.ts +5 -5
  74. package/src/intelligence/graphsnip-provider.js +57 -57
  75. package/src/intelligence/lifecycle.js +25 -25
  76. package/src/memory/LICENSE +21 -21
  77. package/src/memory/README.md +5 -5
  78. package/src/memory/UPSTREAM.json +24 -24
  79. package/src/memory/bridge-cli.js +16 -16
  80. package/src/memory/bridge.js +18 -18
  81. package/src/memory/cli.js +21 -21
  82. package/src/memory/cloud-sync-actions.js +61 -61
  83. package/src/memory/contract.json +45 -45
  84. package/src/memory/index.d.ts +50 -50
  85. package/src/memory/index.js +7 -7
  86. package/src/memory/lifecycle.js +29 -29
  87. package/src/memory/local-cli.js +34 -34
  88. package/src/memory/local-store.js +209 -209
  89. package/src/memory/package.json +33 -33
  90. package/src/memory/proposals.js +90 -90
  91. package/src/memory/skills-cli.js +26 -26
  92. package/src/memory/standalone.d.ts +50 -50
  93. package/src/memory/standalone.js +1 -1
  94. package/src/memory/sync.js +89 -89
  95. package/src/memory/validation.js +25 -25
  96. package/src/onboardingAgents.js +532 -532
  97. package/src/promptTemplates.js +178 -178
  98. package/src/resource-files.js +18 -18
  99. package/src/runtime/contracts.d.ts +47 -47
  100. package/src/runtime/local-cli.js +161 -161
  101. package/src/runtime/mcp-stdio.js +111 -111
  102. package/src/runtime/orchestration.js +59 -59
  103. package/src/runtime/run-agent.js +54 -54
  104. package/src/standalone/index.d.ts +45 -45
  105. package/src/standalone/index.js +13 -13
  106. package/src/standalone/init.js +12 -12
  107. package/src/standalone/orchestration.js +6 -6
  108. package/src/standalone/rag.js +113 -113
  109. package/src/studio/agent-ui.css +43 -43
  110. package/src/studio/agent-ui.js +32 -32
  111. package/src/studio/browser.js +542 -345
  112. package/src/studio/export.js +83 -86
  113. package/src/studio/index.html +74 -37
  114. package/src/studio/memory-actions.js +37 -37
  115. package/src/studio/memory-panel.js +200 -200
  116. package/src/studio/project.js +308 -240
  117. package/src/studio/pull-agent.js +72 -72
  118. package/src/studio/push.js +54 -54
  119. package/src/studio/python-agent.js +47 -47
  120. package/src/studio/python-agent.py +25 -25
  121. package/src/studio/server.js +164 -150
  122. package/src/studio/session.js +83 -83
  123. package/src/studio/studio.css +257 -10
  124. package/src/studio/sync.js +42 -42
  125. package/src/studio/workflow-editor.js +240 -0
  126. package/src/studio/workflow-sync.js +229 -157
@@ -1,150 +1,164 @@
1
- import { discoverFrameworkAgents, syncFrameworkAgent } from "../framework/agent.js";
2
- import { memoryActions } from "./memory-actions.js";
3
- import { createServer } from "node:http";
4
- import { readFile } from "node:fs/promises";
5
- import { readCatalog, readLayout, runSelection, saveLayout } from "./project.js";
6
- import { readMode } from "./session.js";
7
- import { syncSkill, syncTeam, syncWorkflow } from "./workflow-sync.js";
8
- import { pullAgentEdits } from "./pull-agent.js";
9
- import { pushStudioAgent } from "./push.js";
10
- import { pullStudio } from "./sync.js";
11
-
12
- export async function startStudio(root, { port = 0, run = runSelection, pull = pullStudio, appCatalog } = {}) {
13
- const assets = new Map();
14
- for (const [route, name, mime] of [
15
- ["/memory-panel.js", "memory-panel.js", "text/javascript"],
16
- ["/agent-ui.js", "agent-ui.js", "text/javascript"], ["/agent-ui.css", "agent-ui.css", "text/css"],
17
- ["/", "index.html", "text/html"], ["/studio.js", "browser.js", "text/javascript"], ["/studio.css", "studio.css", "text/css"],
18
- ]) assets.set(route, [await readFile(new URL("./" + name, import.meta.url)), mime]);
19
-
20
- const updates = new Map([
21
- ...(appCatalog ? [] : memoryActions(root)),
22
- ["/api/framework-preview", ({ id }) => syncFrameworkAgent(root, id)],
23
- ["/api/framework-sync", ({ id, fingerprint }) => {
24
- if (typeof fingerprint !== "string") throw new Error("Preview the registration before syncing.");
25
- return syncFrameworkAgent(root, id, fingerprint);
26
- }],
27
- ["/api/save", ({ layout, revision }) => saveLayout(root, layout, revision)],
28
- ["/api/pull", () => pull(root)],
29
- ["/api/push", ({ id }) => pushStudioAgent(root, id)],
30
- ["/api/pull-agent", ({ id }) => pullAgentEdits(root, id)],
31
- ["/api/push-workflow", ({ id }) => syncWorkflow(root, id, "push")],
32
- ["/api/pull-workflow", ({ id }) => syncWorkflow(root, id, "pull")],
33
- ["/api/push-team", ({ id }) => syncTeam(root, id, "push")],
34
- ["/api/pull-team", ({ id }) => syncTeam(root, id, "pull")],
35
- ["/api/push-skill", ({ id }) => syncSkill(root, id, "push")],
36
- ["/api/pull-skill", ({ id }) => syncSkill(root, id, "pull")],
37
- ]);
38
-
39
- let running = false;
40
- let writing = false;
41
- const server = createServer(async (req, res) => {
42
- const send = (status, data, type = "application/json") => {
43
- res.writeHead(status, {
44
- "Content-Type": type + "; charset=utf-8", "Cache-Control": "no-store", "X-Content-Type-Options": "nosniff",
45
- "Content-Security-Policy": "default-src 'none'; script-src 'self'; style-src 'self'; connect-src 'self'; frame-ancestors 'none'",
46
- });
47
- res.end(type === "application/json" ? JSON.stringify(data) : data);
48
- };
49
- const host = "127.0.0.1:" + server.address().port;
50
- if (req.headers.host !== host) return send(403, { error: "Use the Studio loopback URL." });
51
- if (req.method === "GET" && assets.has(req.url)) {
52
- const [data, mime] = assets.get(req.url);
53
- return send(200, data, mime);
54
- }
55
- try {
56
- if (req.method === "GET" && req.url === "/api/project") {
57
- const catalog = appCatalog ?? await readCatalog(root);
58
- return send(200, {
59
- ...await readLayout(root),
60
- exported: Boolean(appCatalog),
61
- mode: appCatalog ? undefined : await readMode(root),
62
- agents: [...catalog.agents.values()].map(({ id, name, source, framework }) => ({ id, name, source, framework })),
63
- frameworkCandidates: appCatalog ? [] : await discoverFrameworkAgents(root).catch(() => []),
64
- workflows: catalog.workflows.map(({ id, name, runnable, source }) => ({ id, name, runnable, source })),
65
- skills: (catalog.skills ?? []).map(({ id, name, source }) => ({ id, name, source })),
66
- teams: catalog.teams.map(({ id, name, source }) => ({ id, name, source })),
67
- models: (process.env.LYRA_STUDIO_MODELS || "gpt-4o-mini").split(",").map(value => value.trim()).filter(Boolean),
68
- });
69
- }
70
- if (req.method !== "POST" || (req.url !== "/api/run" && !updates.has(req.url))) {
71
- return send(404, { error: "Not found." });
72
- }
73
- if (appCatalog && req.url !== "/api/run") return send(404, { error: "Not found." });
74
- if (req.headers.origin !== "http://" + host) return send(403, { error: "Use the Studio page to submit requests." });
75
- if (req.headers["content-type"]?.split(";")[0] !== "application/json") return send(415, { error: "Use application/json." });
76
- const chunks = [];
77
- let size = 0;
78
- for await (const chunk of req) {
79
- size += chunk.length;
80
- if (size > 65_536) return send(413, { error: "Studio request is too large." });
81
- chunks.push(chunk);
82
- }
83
- const body = JSON.parse(Buffer.concat(chunks).toString("utf8"));
84
- if (req.url === "/api/run") {
85
- if (running) return send(409, { error: "A Studio run is already in progress." });
86
- running = true;
87
- try {
88
- if (appCatalog) {
89
- const { layout } = await readLayout(root);
90
- const button = layout.find(node => ["button", "agent-card"].includes(node.kind) && node.id === body.buttonId);
91
- if (!button) return send(400, { error: "Choose a run button from the app." });
92
- body.targets = button.targets;
93
- }
94
- return send(200, await run(root, body, appCatalog));
95
- } finally { running = false; }
96
- }
97
- if (writing) return send(409, { error: "Studio is already saving or pulling files." });
98
- writing = true;
99
- try {
100
- return send(200, await updates.get(req.url)(body));
101
- } finally { writing = false; }
102
- } catch (error) {
103
- const message = error.code ? "Studio could not read or write the project." : error.message;
104
- return send(400, { error: message });
105
- }
106
- });
107
-
108
- server.requestTimeout = 10_000;
109
- await new Promise((resolve, reject) => {
110
- server.once("error", reject);
111
- server.listen(port, "127.0.0.1", resolve);
112
- });
113
- return { server, url: "http://127.0.0.1:" + server.address().port + "/" };
114
- }
115
-
116
- export async function runStudio(args, output = process.stdout) {
117
- if (args[0] === "--help") {
118
- output.write("Usage: agent-lyra studio | agent-lyra studio pull | agent-lyra studio push <local-agent-id> | agent-lyra studio pull-agent <local-agent-id> | agent-lyra studio push-workflow <workflow-id> | agent-lyra studio pull-workflow <workflow-id> | agent-lyra studio push-team <team-id> | agent-lyra studio pull-team <team-id> | agent-lyra studio push-skill <skill-id> | agent-lyra studio pull-skill <skill-id>\n");
119
- return;
120
- }
121
- if (args.length === 1 && args[0] === "pull") {
122
- const { added, preserved } = await pullStudio(process.cwd());
123
- output.write("Cloud pull: " + added + " added, " + preserved + " existing preserved.\n");
124
- return;
125
- }
126
- if (args.length === 2 && args[0] === "push") {
127
- const id = args[1].startsWith("local:") ? args[1] : "local:" + args[1];
128
- const result = await pushStudioAgent(process.cwd(), id);
129
- output.write((result.created ? "Created " : "Synced ") + result.name + " in AgentLyra Cloud.\n");
130
- return;
131
- }
132
- if (args.length === 2 && args[0] === "pull-agent") {
133
- const id = args[1].startsWith("local:") ? args[1] : "local:" + args[1];
134
- const result = await pullAgentEdits(process.cwd(), id);
135
- output.write(result.updated ? "Updated " + result.name + " from Cloud.\n" : "No Cloud edits to pull.\n");
136
- return;
137
- }
138
- if (args.length === 2 && ["push-workflow", "pull-workflow", "push-team", "pull-team", "push-skill", "pull-skill"].includes(args[0])) {
139
- const [action, resource] = args[0].split("-");
140
- const push = action === "push";
141
- const sync = { team: syncTeam, workflow: syncWorkflow, skill: syncSkill }[resource];
142
- const result = await sync(process.cwd(), args[1], action);
143
- output.write(push ? "Saved " + result.name + " in Cloud.\n"
144
- : result.updated ? "Updated " + result.name + " from Cloud.\n" : "No Cloud edits to pull.\n");
145
- return;
146
- }
147
- if (args.length) throw new Error("See agent-lyra studio --help.");
148
- const { url } = await startStudio(process.cwd());
149
- output.write("AgentLyra Studio: " + url + "\n");
150
- }
1
+ import { discoverFrameworkAgents, syncFrameworkAgent } from "../framework/agent.js";
2
+ import { memoryActions } from "./memory-actions.js";
3
+ import { createServer } from "node:http";
4
+ import { readFile } from "node:fs/promises";
5
+ import { describeRun, readCatalog, readLayout, runSelection, saveLayout, studioModels, validateRunBindings } from "./project.js";
6
+ import { readMode } from "./session.js";
7
+ import { openStudioWorkflow, saveStudioWorkflow, syncSkill, syncTeam, syncWorkflow } from "./workflow-sync.js";
8
+ import { pullAgentEdits } from "./pull-agent.js";
9
+ import { pushStudioAgent } from "./push.js";
10
+ import { pullStudio } from "./sync.js";
11
+
12
+ export async function startStudio(root, { port = 0, run = runSelection, pull = pullStudio, appCatalog, preview = false } = {}) {
13
+ const assets = new Map();
14
+ for (const [route, name, mime] of [
15
+ ["/memory-panel.js", "memory-panel.js", "text/javascript"],
16
+ ["/agent-ui.js", "agent-ui.js", "text/javascript"], ["/agent-ui.css", "agent-ui.css", "text/css"],
17
+ ["/", "index.html", "text/html"], ["/studio.js", "browser.js", "text/javascript"], ["/workflow-editor.js", "workflow-editor.js", "text/javascript"], ["/studio.css", "studio.css", "text/css"],
18
+ ]) assets.set(route, [await readFile(new URL("./" + name, import.meta.url)), mime]);
19
+
20
+ const readOnly = preview || Boolean(appCatalog);
21
+ const updates = new Map([
22
+ ...(appCatalog ? [] : memoryActions(root)),
23
+ ["/api/framework-preview", ({ id }) => syncFrameworkAgent(root, id)],
24
+ ["/api/framework-sync", ({ id, fingerprint }) => {
25
+ if (typeof fingerprint !== "string") throw new Error("Preview the registration before syncing.");
26
+ return syncFrameworkAgent(root, id, fingerprint);
27
+ }],
28
+ ["/api/save", ({ layout, revision }) => saveLayout(root, layout, revision)],
29
+ ["/api/pull", () => pull(root)],
30
+ ["/api/push", ({ id }) => pushStudioAgent(root, id)],
31
+ ["/api/pull-agent", ({ id }) => pullAgentEdits(root, id)],
32
+ ["/api/open-workflow", ({ id }) => openStudioWorkflow(root, id)],
33
+ ["/api/save-workflow", async body => saveStudioWorkflow(root, body, await readCatalog(root))],
34
+ ["/api/push-workflow", ({ id }) => syncWorkflow(root, id, "push")],
35
+ ["/api/pull-workflow", ({ id }) => syncWorkflow(root, id, "pull")],
36
+ ["/api/push-team", ({ id }) => syncTeam(root, id, "push")],
37
+ ["/api/pull-team", ({ id }) => syncTeam(root, id, "pull")],
38
+ ["/api/push-skill", ({ id }) => syncSkill(root, id, "push")],
39
+ ["/api/pull-skill", ({ id }) => syncSkill(root, id, "pull")],
40
+ ]);
41
+
42
+ async function savedActionTargets(body) {
43
+ const { layout, revision } = await readLayout(root);
44
+ if (preview && body.revision !== revision) return null;
45
+ const button = layout.find(node => ["button", "agent-card"].includes(node.kind) && node.id === body.buttonId);
46
+ if (!button) throw new Error("Choose a run button from the app.");
47
+ validateRunBindings(layout, button);
48
+ return button.targets;
49
+ }
50
+
51
+ let running = false;
52
+ let writing = false;
53
+ const server = createServer(async (req, res) => {
54
+ const send = (status, data, type = "application/json") => {
55
+ res.writeHead(status, {
56
+ "Content-Type": type + "; charset=utf-8", "Cache-Control": "no-store", "X-Content-Type-Options": "nosniff",
57
+ "Content-Security-Policy": "default-src 'none'; script-src 'self'; style-src 'self'; connect-src 'self'; frame-ancestors 'none'",
58
+ });
59
+ res.end(type === "application/json" ? JSON.stringify(data) : data);
60
+ };
61
+ const host = "127.0.0.1:" + server.address().port;
62
+ if (req.headers.host !== host) return send(403, { error: "Use the Studio loopback URL." });
63
+ if (req.method === "GET" && assets.has(req.url)) {
64
+ const [data, mime] = assets.get(req.url);
65
+ return send(200, data, mime);
66
+ }
67
+ try {
68
+ if (req.method === "GET" && req.url === "/api/project") {
69
+ const catalog = appCatalog ?? await readCatalog(root);
70
+ return send(200, {
71
+ ...await readLayout(root),
72
+ exported: Boolean(appCatalog),
73
+ preview,
74
+ mode: appCatalog ? undefined : await readMode(root),
75
+ agents: [...catalog.agents.values()].map(({ id, name, source, framework }) => ({ id, name, source, framework })),
76
+ frameworkCandidates: appCatalog ? [] : await discoverFrameworkAgents(root).catch(() => []),
77
+ workflows: catalog.workflows.map(({ id, name, runnable, source }) => ({ id, name, runnable, source })),
78
+ skills: (catalog.skills ?? []).map(({ id, name, source }) => ({ id, name, source })),
79
+ teams: catalog.teams.map(({ id, name, source }) => ({ id, name, source })),
80
+ models: studioModels(),
81
+ });
82
+ }
83
+ const runRequest = req.url === "/api/run" || req.url === "/api/run-plan";
84
+ if (req.method !== "POST" || (!runRequest && (readOnly || !updates.has(req.url)))) {
85
+ return send(404, { error: "Not found." });
86
+ }
87
+ if (req.headers.origin !== "http://" + host) return send(403, { error: "Use the Studio page to submit requests." });
88
+ if (req.headers["content-type"]?.split(";")[0] !== "application/json") return send(415, { error: "Use application/json." });
89
+ const chunks = [];
90
+ let size = 0;
91
+ for await (const chunk of req) {
92
+ size += chunk.length;
93
+ if (size > 65_536) return send(413, { error: "Studio request is too large." });
94
+ chunks.push(chunk);
95
+ }
96
+ const body = JSON.parse(Buffer.concat(chunks).toString("utf8"));
97
+ if (runRequest && readOnly) {
98
+ body.targets = await savedActionTargets(body);
99
+ if (!body.targets) return send(409, { error: "The saved layout changed. Reload the preview before running." });
100
+ }
101
+ if (req.url === "/api/run-plan") {
102
+ return send(200, await describeRun(root, body.targets, appCatalog));
103
+ }
104
+ if (req.url === "/api/run") {
105
+ if (running) return send(409, { error: "A Studio run is already in progress." });
106
+ running = true;
107
+ try {
108
+ return send(200, await run(root, body, appCatalog));
109
+ } finally { running = false; }
110
+ }
111
+ if (writing) return send(409, { error: "Studio is already saving or pulling files." });
112
+ writing = true;
113
+ try {
114
+ return send(200, await updates.get(req.url)(body));
115
+ } finally { writing = false; }
116
+ } catch (error) {
117
+ const message = error.code ? "Studio could not read or write the project." : error.message;
118
+ return send(400, { error: message, ...(error.progress ? { progress: error.progress } : {}) });
119
+ }
120
+ });
121
+
122
+ server.requestTimeout = 10_000;
123
+ await new Promise((resolve, reject) => {
124
+ server.once("error", reject);
125
+ server.listen(port, "127.0.0.1", resolve);
126
+ });
127
+ return { server, url: "http://127.0.0.1:" + server.address().port + "/" };
128
+ }
129
+
130
+ export async function runStudio(args, output = process.stdout) {
131
+ if (args[0] === "--help") {
132
+ output.write("Usage: agent-lyra studio | agent-lyra studio pull | agent-lyra studio push <local-agent-id> | agent-lyra studio pull-agent <local-agent-id> | agent-lyra studio push-workflow <workflow-id> | agent-lyra studio pull-workflow <workflow-id> | agent-lyra studio push-team <team-id> | agent-lyra studio pull-team <team-id> | agent-lyra studio push-skill <skill-id> | agent-lyra studio pull-skill <skill-id>\n");
133
+ return;
134
+ }
135
+ if (args.length === 1 && args[0] === "pull") {
136
+ const { added, preserved } = await pullStudio(process.cwd());
137
+ output.write("Cloud pull: " + added + " added, " + preserved + " existing preserved.\n");
138
+ return;
139
+ }
140
+ if (args.length === 2 && args[0] === "push") {
141
+ const id = args[1].startsWith("local:") ? args[1] : "local:" + args[1];
142
+ const result = await pushStudioAgent(process.cwd(), id);
143
+ output.write((result.created ? "Created " : "Synced ") + result.name + " in AgentLyra Cloud.\n");
144
+ return;
145
+ }
146
+ if (args.length === 2 && args[0] === "pull-agent") {
147
+ const id = args[1].startsWith("local:") ? args[1] : "local:" + args[1];
148
+ const result = await pullAgentEdits(process.cwd(), id);
149
+ output.write(result.updated ? "Updated " + result.name + " from Cloud.\n" : "No Cloud edits to pull.\n");
150
+ return;
151
+ }
152
+ if (args.length === 2 && ["push-workflow", "pull-workflow", "push-team", "pull-team", "push-skill", "pull-skill"].includes(args[0])) {
153
+ const [action, resource] = args[0].split("-");
154
+ const push = action === "push";
155
+ const sync = { team: syncTeam, workflow: syncWorkflow, skill: syncSkill }[resource];
156
+ const result = await sync(process.cwd(), args[1], action);
157
+ output.write(push ? "Saved " + result.name + " in Cloud.\n"
158
+ : result.updated ? "Updated " + result.name + " from Cloud.\n" : "No Cloud edits to pull.\n");
159
+ return;
160
+ }
161
+ if (args.length) throw new Error("See agent-lyra studio --help.");
162
+ const { url } = await startStudio(process.cwd());
163
+ output.write("AgentLyra Studio: " + url + "\n");
164
+ }
@@ -1,83 +1,83 @@
1
- import { randomUUID } from "node:crypto";
2
- import { lstat, mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
3
- import { homedir } from "node:os";
4
- import { join } from "node:path";
5
- import { createInterface } from "node:readline/promises";
6
- import { Writable } from "node:stream";
7
-
8
- const validKey = key => typeof key === "string" && /^lyra_sdk_[a-f0-9]{64}$/.test(key);
9
- const account = () => join(homedir(), ".agent-lyra");
10
- const workspace = root => join(root, ".lyra");
11
-
12
- async function readJson(path) {
13
- try {
14
- if (!(await lstat(path)).isFile()) throw new Error("Lyra settings must be a regular file.");
15
- return JSON.parse((await readFile(path, "utf8")).replace(/^\uFEFF/, ""));
16
- } catch (error) {
17
- if (error.code === "ENOENT") return {};
18
- throw error;
19
- }
20
- }
21
-
22
- async function saveJson(directory, name, data) {
23
- await mkdir(directory, { recursive: true, mode: 0o700 });
24
- if (!(await lstat(directory)).isDirectory()) throw new Error("Lyra settings must use a regular directory.");
25
- const target = join(directory, name);
26
- const temporary = target + "." + randomUUID() + ".tmp";
27
- await writeFile(temporary, JSON.stringify(data, null, 2) + "\n", { flag: "wx", mode: 0o600 });
28
- try {
29
- await rename(temporary, target);
30
- } finally {
31
- await unlink(temporary).catch(() => {});
32
- }
33
- }
34
-
35
- export async function readMode(root) {
36
- const { mode } = await readJson(join(workspace(root), "session.json"));
37
- return ["gated", "standalone"].includes(mode) ? mode : "automatic";
38
- }
39
-
40
- export async function readSdkKey(root, { home = account() } = {}) {
41
- const env = process.env.LYRA_API_KEY;
42
- if (validKey(env)) return env;
43
- const saved = (await readJson(join(home, "credentials.json"))).LYRA_API_KEY;
44
- if (validKey(saved)) return saved;
45
- const workspaceKey = (await readJson(join(workspace(root), "credentials.json"))).LYRA_API_KEY;
46
- return validKey(workspaceKey) ? workspaceKey : undefined;
47
- }
48
-
49
- async function promptKey() {
50
- if (!process.stdin.isTTY || !process.stdout.isTTY) {
51
- throw new Error("Run this command in your IDE terminal to enter an AgentLyra API key, or supply LYRA_API_KEY in the environment.");
52
- }
53
- const silent = new Writable({ write(_chunk, _encoding, done) { done(); } });
54
- const prompt = createInterface({ input: process.stdin, output: silent, terminal: true, historySize: 0 });
55
- const cancel = new AbortController();
56
- prompt.once("SIGINT", () => cancel.abort());
57
- process.stdout.write("Paste your AgentLyra API key and press Enter (input hidden): ");
58
- try {
59
- return (await prompt.question("", { signal: cancel.signal })).trim();
60
- } finally {
61
- prompt.close();
62
- process.stdout.write("\n");
63
- }
64
- }
65
-
66
- export async function switchMode(root, mode, args, { output = process.stdout, prompt = promptKey, home = account() } = {}) {
67
- const replace = mode === "gated" && args.length === 1 && args[0] === "--replace-key";
68
- if (args.length && !replace) throw new Error("Usage: agent-lyra work-locally | agent-lyra connect-cloud [--replace-key]");
69
- if (mode === "gated" && (replace || !(await readSdkKey(root, { home })))) {
70
- output.write("Generate an AgentLyra API key at https://console.agentlyra.in/mcp-servers\n");
71
- const key = await prompt();
72
- if (!validKey(key)) throw new Error("Enter an AgentLyra API key beginning with lyra_sdk_.");
73
- await saveJson(home, "credentials.json", { LYRA_API_KEY: key });
74
- }
75
- await saveJson(workspace(root), "session.json", { mode });
76
- output.write(mode === "gated"
77
- ? "Connected to Cloud. Open Studio and choose Pull from Cloud.\n"
78
- : "Working locally. Studio Cloud actions are paused.\n");
79
- }
80
-
81
- export function requireCloudMode(mode) {
82
- if (mode === "standalone") throw new Error("You’re working locally. Run connect-cloud in your project terminal to use Cloud resources.");
83
- }
1
+ import { randomUUID } from "node:crypto";
2
+ import { lstat, mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
3
+ import { homedir } from "node:os";
4
+ import { join } from "node:path";
5
+ import { createInterface } from "node:readline/promises";
6
+ import { Writable } from "node:stream";
7
+
8
+ const validKey = key => typeof key === "string" && /^lyra_sdk_[a-f0-9]{64}$/.test(key);
9
+ const account = () => join(homedir(), ".agent-lyra");
10
+ const workspace = root => join(root, ".lyra");
11
+
12
+ async function readJson(path) {
13
+ try {
14
+ if (!(await lstat(path)).isFile()) throw new Error("Lyra settings must be a regular file.");
15
+ return JSON.parse((await readFile(path, "utf8")).replace(/^\uFEFF/, ""));
16
+ } catch (error) {
17
+ if (error.code === "ENOENT") return {};
18
+ throw error;
19
+ }
20
+ }
21
+
22
+ async function saveJson(directory, name, data) {
23
+ await mkdir(directory, { recursive: true, mode: 0o700 });
24
+ if (!(await lstat(directory)).isDirectory()) throw new Error("Lyra settings must use a regular directory.");
25
+ const target = join(directory, name);
26
+ const temporary = target + "." + randomUUID() + ".tmp";
27
+ await writeFile(temporary, JSON.stringify(data, null, 2) + "\n", { flag: "wx", mode: 0o600 });
28
+ try {
29
+ await rename(temporary, target);
30
+ } finally {
31
+ await unlink(temporary).catch(() => {});
32
+ }
33
+ }
34
+
35
+ export async function readMode(root) {
36
+ const { mode } = await readJson(join(workspace(root), "session.json"));
37
+ return ["gated", "standalone"].includes(mode) ? mode : "automatic";
38
+ }
39
+
40
+ export async function readSdkKey(root, { home = account() } = {}) {
41
+ const env = process.env.LYRA_API_KEY;
42
+ if (validKey(env)) return env;
43
+ const saved = (await readJson(join(home, "credentials.json"))).LYRA_API_KEY;
44
+ if (validKey(saved)) return saved;
45
+ const workspaceKey = (await readJson(join(workspace(root), "credentials.json"))).LYRA_API_KEY;
46
+ return validKey(workspaceKey) ? workspaceKey : undefined;
47
+ }
48
+
49
+ async function promptKey() {
50
+ if (!process.stdin.isTTY || !process.stdout.isTTY) {
51
+ throw new Error("Run this command in your IDE terminal to enter an AgentLyra API key, or supply LYRA_API_KEY in the environment.");
52
+ }
53
+ const silent = new Writable({ write(_chunk, _encoding, done) { done(); } });
54
+ const prompt = createInterface({ input: process.stdin, output: silent, terminal: true, historySize: 0 });
55
+ const cancel = new AbortController();
56
+ prompt.once("SIGINT", () => cancel.abort());
57
+ process.stdout.write("Paste your AgentLyra API key and press Enter (input hidden): ");
58
+ try {
59
+ return (await prompt.question("", { signal: cancel.signal })).trim();
60
+ } finally {
61
+ prompt.close();
62
+ process.stdout.write("\n");
63
+ }
64
+ }
65
+
66
+ export async function switchMode(root, mode, args, { output = process.stdout, prompt = promptKey, home = account() } = {}) {
67
+ const replace = mode === "gated" && args.length === 1 && args[0] === "--replace-key";
68
+ if (args.length && !replace) throw new Error("Usage: agent-lyra work-locally | agent-lyra connect-cloud [--replace-key]");
69
+ if (mode === "gated" && (replace || !(await readSdkKey(root, { home })))) {
70
+ output.write("Generate an AgentLyra API key at https://console.agentlyra.in/mcp-servers\n");
71
+ const key = await prompt();
72
+ if (!validKey(key)) throw new Error("Enter an AgentLyra API key beginning with lyra_sdk_.");
73
+ await saveJson(home, "credentials.json", { LYRA_API_KEY: key });
74
+ }
75
+ await saveJson(workspace(root), "session.json", { mode });
76
+ output.write(mode === "gated"
77
+ ? "Connected to Cloud. Open Studio and choose Pull from Cloud.\n"
78
+ : "Working locally. Studio Cloud actions are paused.\n");
79
+ }
80
+
81
+ export function requireCloudMode(mode) {
82
+ if (mode === "standalone") throw new Error("You’re working locally. Run connect-cloud in your project terminal to use Cloud resources.");
83
+ }