agent-lyra 0.6.0 → 0.6.1
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 +395 -173
- package/bin/agent-lyra.js +16 -3
- package/package.json +60 -56
- package/src/app-builder/export.js +109 -109
- package/src/app-builder/init.js +52 -52
- package/src/app-builder/preview.js +22 -22
- 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/validate.js +64 -64
- package/src/memory/cli.js +49 -0
- package/src/memory/contract.json +28 -0
- package/src/memory/index.d.ts +49 -0
- package/src/memory/index.js +259 -0
- package/src/memory/lifecycle.js +29 -0
- package/src/memory/proposals.js +84 -0
- package/src/memory/skills-cli.js +26 -0
- package/src/memory/sync.js +85 -0
- package/src/memory/validation.js +25 -0
- package/src/runtime/local-cli.js +2 -1
- package/src/studio/agent-ui.css +43 -43
- package/src/studio/agent-ui.js +32 -32
- package/src/studio/browser.js +331 -289
- package/src/studio/export.js +80 -79
- package/src/studio/index.html +37 -16
- package/src/studio/memory-actions.js +37 -0
- package/src/studio/memory-panel.js +200 -0
- package/src/studio/project.js +197 -190
- package/src/studio/pull-agent.js +72 -0
- package/src/studio/push.js +54 -0
- package/src/studio/python-agent.js +47 -47
- package/src/studio/python-agent.py +25 -25
- package/src/studio/server.js +143 -102
- package/src/studio/session.js +83 -0
- package/src/studio/studio.css +10 -7
- package/src/studio/sync.js +42 -39
- package/src/studio/workflow-sync.js +157 -0
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
const form = document.querySelector("form");
|
|
2
|
-
const button = form.querySelector("button");
|
|
3
|
-
const status = document.querySelector("#status");
|
|
4
|
-
const result = document.querySelector("#result");
|
|
5
|
-
|
|
6
|
-
fetch("/api/app").then(response => response.json()).then(({ name }) => {
|
|
7
|
-
document.title = name;
|
|
8
|
-
document.querySelector("h1").textContent = name;
|
|
9
|
-
}).catch(() => { status.textContent = "Could not load application details."; });
|
|
10
|
-
|
|
11
|
-
form.addEventListener("submit", async event => {
|
|
12
|
-
event.preventDefault();
|
|
13
|
-
button.disabled = true;
|
|
14
|
-
result.hidden = true;
|
|
15
|
-
status.textContent = "Running both agents…";
|
|
16
|
-
try {
|
|
17
|
-
const response = await fetch("/api/run", {
|
|
18
|
-
method: "POST",
|
|
19
|
-
headers: { "Content-Type": "application/json" },
|
|
20
|
-
body: JSON.stringify({ input: document.querySelector("#input").value }),
|
|
21
|
-
});
|
|
22
|
-
const data = await response.json();
|
|
23
|
-
if (!response.ok) throw new Error(data.error);
|
|
24
|
-
document.querySelector("#output").textContent = data.output;
|
|
25
|
-
document.querySelector("#first").textContent = data.firstOutput;
|
|
26
|
-
result.hidden = false;
|
|
27
|
-
status.textContent = "Workflow completed.";
|
|
28
|
-
} catch (error) {
|
|
29
|
-
status.textContent = error.message;
|
|
30
|
-
} finally {
|
|
31
|
-
button.disabled = false;
|
|
32
|
-
}
|
|
33
|
-
});
|
|
1
|
+
const form = document.querySelector("form");
|
|
2
|
+
const button = form.querySelector("button");
|
|
3
|
+
const status = document.querySelector("#status");
|
|
4
|
+
const result = document.querySelector("#result");
|
|
5
|
+
|
|
6
|
+
fetch("/api/app").then(response => response.json()).then(({ name }) => {
|
|
7
|
+
document.title = name;
|
|
8
|
+
document.querySelector("h1").textContent = name;
|
|
9
|
+
}).catch(() => { status.textContent = "Could not load application details."; });
|
|
10
|
+
|
|
11
|
+
form.addEventListener("submit", async event => {
|
|
12
|
+
event.preventDefault();
|
|
13
|
+
button.disabled = true;
|
|
14
|
+
result.hidden = true;
|
|
15
|
+
status.textContent = "Running both agents…";
|
|
16
|
+
try {
|
|
17
|
+
const response = await fetch("/api/run", {
|
|
18
|
+
method: "POST",
|
|
19
|
+
headers: { "Content-Type": "application/json" },
|
|
20
|
+
body: JSON.stringify({ input: document.querySelector("#input").value }),
|
|
21
|
+
});
|
|
22
|
+
const data = await response.json();
|
|
23
|
+
if (!response.ok) throw new Error(data.error);
|
|
24
|
+
document.querySelector("#output").textContent = data.output;
|
|
25
|
+
document.querySelector("#first").textContent = data.firstOutput;
|
|
26
|
+
result.hidden = false;
|
|
27
|
+
status.textContent = "Workflow completed.";
|
|
28
|
+
} catch (error) {
|
|
29
|
+
status.textContent = error.message;
|
|
30
|
+
} finally {
|
|
31
|
+
button.disabled = false;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
-
<title>Lyra application</title>
|
|
7
|
-
<style>
|
|
8
|
-
body { background:#f6f9f7;color:#152c23;font:1rem/1.6 system-ui,sans-serif;margin:0 }
|
|
9
|
-
main { max-width:50rem;margin:4rem auto;padding:0 1.25rem }
|
|
10
|
-
label,textarea,button { display:block;font:inherit }
|
|
11
|
-
textarea { box-sizing:border-box;width:100%;min-height:8rem;margin:.45rem 0 1rem;padding:.75rem;border:1px solid #8ea99c;border-radius:.5rem }
|
|
12
|
-
button { background:#174b38;color:white;border:0;border-radius:.5rem;padding:.6rem 1rem;cursor:pointer }
|
|
13
|
-
button:disabled { opacity:.65;cursor:wait }
|
|
14
|
-
pre { white-space:pre-wrap;overflow-wrap:anywhere;background:white;padding:1rem;border:1px solid #cfddd5;border-radius:.5rem;font:inherit }
|
|
15
|
-
</style>
|
|
16
|
-
<script src="/preview.js" defer></script>
|
|
17
|
-
</head>
|
|
18
|
-
<body><main>
|
|
19
|
-
<h1>Lyra application</h1>
|
|
20
|
-
<form><label for="input">Workflow input</label><textarea id="input" required maxlength="4000"></textarea><button>Run workflow</button></form>
|
|
21
|
-
<p role="status" id="status"></p>
|
|
22
|
-
<section hidden id="result"><h2>Final result</h2><pre id="output"></pre><details><summary>First agent output</summary><pre id="first"></pre></details></section>
|
|
23
|
-
</main></body>
|
|
24
|
-
</html>
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>Lyra application</title>
|
|
7
|
+
<style>
|
|
8
|
+
body { background:#f6f9f7;color:#152c23;font:1rem/1.6 system-ui,sans-serif;margin:0 }
|
|
9
|
+
main { max-width:50rem;margin:4rem auto;padding:0 1.25rem }
|
|
10
|
+
label,textarea,button { display:block;font:inherit }
|
|
11
|
+
textarea { box-sizing:border-box;width:100%;min-height:8rem;margin:.45rem 0 1rem;padding:.75rem;border:1px solid #8ea99c;border-radius:.5rem }
|
|
12
|
+
button { background:#174b38;color:white;border:0;border-radius:.5rem;padding:.6rem 1rem;cursor:pointer }
|
|
13
|
+
button:disabled { opacity:.65;cursor:wait }
|
|
14
|
+
pre { white-space:pre-wrap;overflow-wrap:anywhere;background:white;padding:1rem;border:1px solid #cfddd5;border-radius:.5rem;font:inherit }
|
|
15
|
+
</style>
|
|
16
|
+
<script src="/preview.js" defer></script>
|
|
17
|
+
</head>
|
|
18
|
+
<body><main>
|
|
19
|
+
<h1>Lyra application</h1>
|
|
20
|
+
<form><label for="input">Workflow input</label><textarea id="input" required maxlength="4000"></textarea><button>Run workflow</button></form>
|
|
21
|
+
<p role="status" id="status"></p>
|
|
22
|
+
<section hidden id="result"><h2>Final result</h2><pre id="output"></pre><details><summary>First agent output</summary><pre id="first"></pre></details></section>
|
|
23
|
+
</main></body>
|
|
24
|
+
</html>
|
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
import { createServer } from "node:http";
|
|
2
|
-
import { readFile } from "node:fs/promises";
|
|
3
|
-
import { createSavedAgentClient, runSavedApp, validateSavedApp } from "./saved-app.js";
|
|
4
|
-
|
|
5
|
-
export async function startSavedPreview(manifest, { port = Number(process.env.LYRA_PREVIEW_PORT ?? 4173), client } = {}) {
|
|
6
|
-
validateSavedApp(manifest);
|
|
7
|
-
client ??= createSavedAgentClient();
|
|
8
|
-
if (!Number.isInteger(port) || port < 0 || port > 65535) throw new Error("Invalid preview port.");
|
|
9
|
-
const [html, script] = await Promise.all(["saved-preview.html", "saved-preview-browser.js"].map(
|
|
10
|
-
name => readFile(new URL("./" + name, import.meta.url)),
|
|
11
|
-
));
|
|
12
|
-
const server = createServer(async (req, res) => {
|
|
13
|
-
const send = (status, body, type = "application/json; charset=utf-8") => {
|
|
14
|
-
res.writeHead(status, {
|
|
15
|
-
"Content-Type": type, "Cache-Control": "no-store", "X-Content-Type-Options": "nosniff",
|
|
16
|
-
"Content-Security-Policy": "default-src 'none'; script-src 'self'; style-src 'unsafe-inline'; connect-src 'self'; frame-ancestors 'none'",
|
|
17
|
-
});
|
|
18
|
-
res.end(type.startsWith("application/json") ? JSON.stringify(body) : body);
|
|
19
|
-
};
|
|
20
|
-
const authority = "127.0.0.1:" + server.address().port;
|
|
21
|
-
if (req.headers.host !== authority) return send(403, { error: "Use the loopback address." });
|
|
22
|
-
if (req.method === "GET" && req.url === "/") return send(200, html, "text/html; charset=utf-8");
|
|
23
|
-
if (req.method === "GET" && req.url === "/preview.js") return send(200, script, "text/javascript; charset=utf-8");
|
|
24
|
-
if (req.method === "GET" && req.url === "/api/app") return send(200, { name: manifest.application.name });
|
|
25
|
-
if (req.method !== "POST" || req.url !== "/api/run") return send(404, { error: "Not found." });
|
|
26
|
-
if (req.headers.origin !== "http://" + authority) return send(403, { error: "Use the application page to run agents." });
|
|
27
|
-
if (req.headers["content-type"]?.split(";")[0] !== "application/json") return send(415, { error: "Use application/json." });
|
|
28
|
-
|
|
29
|
-
const chunks = [];
|
|
30
|
-
let size = 0;
|
|
31
|
-
let input;
|
|
32
|
-
try {
|
|
33
|
-
for await (const chunk of req) {
|
|
34
|
-
size += chunk.length;
|
|
35
|
-
if (size > 24_576) return send(413, { error: "Input is too large." });
|
|
36
|
-
chunks.push(chunk);
|
|
37
|
-
}
|
|
38
|
-
input = JSON.parse(Buffer.concat(chunks).toString("utf8"))?.input;
|
|
39
|
-
} catch {
|
|
40
|
-
return send(400, { error: "Invalid request." });
|
|
41
|
-
}
|
|
42
|
-
if (typeof input !== "string" || !input.trim() || input.length > 4000) {
|
|
43
|
-
return send(400, { error: "Enter between 1 and 4,000 characters." });
|
|
44
|
-
}
|
|
45
|
-
try {
|
|
46
|
-
send(200, await runSavedApp(manifest, input, client));
|
|
47
|
-
} catch (error) {
|
|
48
|
-
send(502, { error: error.message });
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
server.requestTimeout = 10_000;
|
|
53
|
-
await new Promise((resolve, reject) => {
|
|
54
|
-
server.once("error", reject);
|
|
55
|
-
server.listen(port, "127.0.0.1", resolve);
|
|
56
|
-
}).catch(error => {
|
|
57
|
-
if (error.code === "EADDRINUSE") throw new Error("Preview port is busy. Set LYRA_PREVIEW_PORT=0 to pick a free port.");
|
|
58
|
-
throw error;
|
|
59
|
-
});
|
|
60
|
-
return { server, url: "http://127.0.0.1:" + server.address().port + "/" };
|
|
61
|
-
}
|
|
1
|
+
import { createServer } from "node:http";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { createSavedAgentClient, runSavedApp, validateSavedApp } from "./saved-app.js";
|
|
4
|
+
|
|
5
|
+
export async function startSavedPreview(manifest, { port = Number(process.env.LYRA_PREVIEW_PORT ?? 4173), client } = {}) {
|
|
6
|
+
validateSavedApp(manifest);
|
|
7
|
+
client ??= createSavedAgentClient();
|
|
8
|
+
if (!Number.isInteger(port) || port < 0 || port > 65535) throw new Error("Invalid preview port.");
|
|
9
|
+
const [html, script] = await Promise.all(["saved-preview.html", "saved-preview-browser.js"].map(
|
|
10
|
+
name => readFile(new URL("./" + name, import.meta.url)),
|
|
11
|
+
));
|
|
12
|
+
const server = createServer(async (req, res) => {
|
|
13
|
+
const send = (status, body, type = "application/json; charset=utf-8") => {
|
|
14
|
+
res.writeHead(status, {
|
|
15
|
+
"Content-Type": type, "Cache-Control": "no-store", "X-Content-Type-Options": "nosniff",
|
|
16
|
+
"Content-Security-Policy": "default-src 'none'; script-src 'self'; style-src 'unsafe-inline'; connect-src 'self'; frame-ancestors 'none'",
|
|
17
|
+
});
|
|
18
|
+
res.end(type.startsWith("application/json") ? JSON.stringify(body) : body);
|
|
19
|
+
};
|
|
20
|
+
const authority = "127.0.0.1:" + server.address().port;
|
|
21
|
+
if (req.headers.host !== authority) return send(403, { error: "Use the loopback address." });
|
|
22
|
+
if (req.method === "GET" && req.url === "/") return send(200, html, "text/html; charset=utf-8");
|
|
23
|
+
if (req.method === "GET" && req.url === "/preview.js") return send(200, script, "text/javascript; charset=utf-8");
|
|
24
|
+
if (req.method === "GET" && req.url === "/api/app") return send(200, { name: manifest.application.name });
|
|
25
|
+
if (req.method !== "POST" || req.url !== "/api/run") return send(404, { error: "Not found." });
|
|
26
|
+
if (req.headers.origin !== "http://" + authority) return send(403, { error: "Use the application page to run agents." });
|
|
27
|
+
if (req.headers["content-type"]?.split(";")[0] !== "application/json") return send(415, { error: "Use application/json." });
|
|
28
|
+
|
|
29
|
+
const chunks = [];
|
|
30
|
+
let size = 0;
|
|
31
|
+
let input;
|
|
32
|
+
try {
|
|
33
|
+
for await (const chunk of req) {
|
|
34
|
+
size += chunk.length;
|
|
35
|
+
if (size > 24_576) return send(413, { error: "Input is too large." });
|
|
36
|
+
chunks.push(chunk);
|
|
37
|
+
}
|
|
38
|
+
input = JSON.parse(Buffer.concat(chunks).toString("utf8"))?.input;
|
|
39
|
+
} catch {
|
|
40
|
+
return send(400, { error: "Invalid request." });
|
|
41
|
+
}
|
|
42
|
+
if (typeof input !== "string" || !input.trim() || input.length > 4000) {
|
|
43
|
+
return send(400, { error: "Enter between 1 and 4,000 characters." });
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
send(200, await runSavedApp(manifest, input, client));
|
|
47
|
+
} catch (error) {
|
|
48
|
+
send(502, { error: error.message });
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
server.requestTimeout = 10_000;
|
|
53
|
+
await new Promise((resolve, reject) => {
|
|
54
|
+
server.once("error", reject);
|
|
55
|
+
server.listen(port, "127.0.0.1", resolve);
|
|
56
|
+
}).catch(error => {
|
|
57
|
+
if (error.code === "EADDRINUSE") throw new Error("Preview port is busy. Set LYRA_PREVIEW_PORT=0 to pick a free port.");
|
|
58
|
+
throw error;
|
|
59
|
+
});
|
|
60
|
+
return { server, url: "http://127.0.0.1:" + server.address().port + "/" };
|
|
61
|
+
}
|
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
import { readAppManifest, SAVED_VERSION, validateSavedApp } from "./saved-app.js";
|
|
2
|
-
import { assertValueSchema } from "./value-schema.js";
|
|
3
|
-
|
|
4
|
-
const modes = new Set(["in-process", "local-process", "remote"]);
|
|
5
|
-
const identifier = /^[a-z][a-z0-9-]*$/;
|
|
6
|
-
const isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
7
|
-
const isIdentifier = (value) => typeof value === "string" && identifier.test(value);
|
|
8
|
-
|
|
9
|
-
export function validateAppManifest(manifest) {
|
|
10
|
-
if (!isRecord(manifest) || manifest.version !== "1.0") {
|
|
11
|
-
throw new Error('Application manifest requires version "1.0".');
|
|
12
|
-
}
|
|
13
|
-
const { application, capabilities, actions } = manifest;
|
|
14
|
-
if (!isRecord(application) || !isIdentifier(application.id) ||
|
|
15
|
-
typeof application.name !== "string" || !application.name.trim()) {
|
|
16
|
-
throw new Error("Application requires a valid id and a name.");
|
|
17
|
-
}
|
|
18
|
-
if (!Array.isArray(capabilities) || !Array.isArray(actions)) {
|
|
19
|
-
throw new Error("Capabilities and actions must be arrays.");
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const capabilityIds = new Set();
|
|
23
|
-
for (const capability of capabilities) {
|
|
24
|
-
if (!isRecord(capability) || !isIdentifier(capability.id) || !isIdentifier(capability.adapterId) ||
|
|
25
|
-
!modes.has(capability.executionMode)) {
|
|
26
|
-
throw new Error("Each capability requires an id, adapterId, and supported executionMode.");
|
|
27
|
-
}
|
|
28
|
-
if (capabilityIds.has(capability.id)) throw new Error(`Duplicate capability: ${capability.id}.`);
|
|
29
|
-
for (const key of ["inputSchema", "outputSchema"]) {
|
|
30
|
-
if (Object.hasOwn(capability, key)) assertValueSchema(capability[key], `${capability.id} ${key}`);
|
|
31
|
-
}
|
|
32
|
-
capabilityIds.add(capability.id);
|
|
33
|
-
}
|
|
34
|
-
const actionIds = new Set();
|
|
35
|
-
for (const action of actions) {
|
|
36
|
-
if (!isRecord(action) || !isIdentifier(action.id) || !isIdentifier(action.capabilityId)) {
|
|
37
|
-
throw new Error("Each action requires an id and capabilityId.");
|
|
38
|
-
}
|
|
39
|
-
if (actionIds.has(action.id)) throw new Error(`Duplicate action: ${action.id}.`);
|
|
40
|
-
if (!capabilityIds.has(action.capabilityId)) {
|
|
41
|
-
throw new Error(`Action ${action.id} refers to unknown capability ${action.capabilityId}.`);
|
|
42
|
-
}
|
|
43
|
-
actionIds.add(action.id);
|
|
44
|
-
}
|
|
45
|
-
return { id: application.id, capabilityCount: capabilityIds.size, actionCount: actionIds.size };
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export async function runAppValidation(args, output = process.stdout) {
|
|
49
|
-
if (args.length === 1 && args[0] === "--help") {
|
|
50
|
-
output.write("Usage: agent-lyra app validate <manifest.json>\n");
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
if (args.length !== 1 || args[0].startsWith("-")) {
|
|
54
|
-
throw new Error("Provide a manifest path. See agent-lyra app validate --help.");
|
|
55
|
-
}
|
|
56
|
-
const manifest = await readAppManifest(args[0]);
|
|
57
|
-
if (manifest?.version === SAVED_VERSION) {
|
|
58
|
-
validateSavedApp(manifest);
|
|
59
|
-
output.write("Valid app " + manifest.application.id + " (2 saved agents).\n");
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
const { id, capabilityCount, actionCount } = validateAppManifest(manifest);
|
|
63
|
-
output.write(`Valid app ${id} (${capabilityCount} capabilities, ${actionCount} actions).\n`);
|
|
64
|
-
}
|
|
1
|
+
import { readAppManifest, SAVED_VERSION, validateSavedApp } from "./saved-app.js";
|
|
2
|
+
import { assertValueSchema } from "./value-schema.js";
|
|
3
|
+
|
|
4
|
+
const modes = new Set(["in-process", "local-process", "remote"]);
|
|
5
|
+
const identifier = /^[a-z][a-z0-9-]*$/;
|
|
6
|
+
const isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
7
|
+
const isIdentifier = (value) => typeof value === "string" && identifier.test(value);
|
|
8
|
+
|
|
9
|
+
export function validateAppManifest(manifest) {
|
|
10
|
+
if (!isRecord(manifest) || manifest.version !== "1.0") {
|
|
11
|
+
throw new Error('Application manifest requires version "1.0".');
|
|
12
|
+
}
|
|
13
|
+
const { application, capabilities, actions } = manifest;
|
|
14
|
+
if (!isRecord(application) || !isIdentifier(application.id) ||
|
|
15
|
+
typeof application.name !== "string" || !application.name.trim()) {
|
|
16
|
+
throw new Error("Application requires a valid id and a name.");
|
|
17
|
+
}
|
|
18
|
+
if (!Array.isArray(capabilities) || !Array.isArray(actions)) {
|
|
19
|
+
throw new Error("Capabilities and actions must be arrays.");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const capabilityIds = new Set();
|
|
23
|
+
for (const capability of capabilities) {
|
|
24
|
+
if (!isRecord(capability) || !isIdentifier(capability.id) || !isIdentifier(capability.adapterId) ||
|
|
25
|
+
!modes.has(capability.executionMode)) {
|
|
26
|
+
throw new Error("Each capability requires an id, adapterId, and supported executionMode.");
|
|
27
|
+
}
|
|
28
|
+
if (capabilityIds.has(capability.id)) throw new Error(`Duplicate capability: ${capability.id}.`);
|
|
29
|
+
for (const key of ["inputSchema", "outputSchema"]) {
|
|
30
|
+
if (Object.hasOwn(capability, key)) assertValueSchema(capability[key], `${capability.id} ${key}`);
|
|
31
|
+
}
|
|
32
|
+
capabilityIds.add(capability.id);
|
|
33
|
+
}
|
|
34
|
+
const actionIds = new Set();
|
|
35
|
+
for (const action of actions) {
|
|
36
|
+
if (!isRecord(action) || !isIdentifier(action.id) || !isIdentifier(action.capabilityId)) {
|
|
37
|
+
throw new Error("Each action requires an id and capabilityId.");
|
|
38
|
+
}
|
|
39
|
+
if (actionIds.has(action.id)) throw new Error(`Duplicate action: ${action.id}.`);
|
|
40
|
+
if (!capabilityIds.has(action.capabilityId)) {
|
|
41
|
+
throw new Error(`Action ${action.id} refers to unknown capability ${action.capabilityId}.`);
|
|
42
|
+
}
|
|
43
|
+
actionIds.add(action.id);
|
|
44
|
+
}
|
|
45
|
+
return { id: application.id, capabilityCount: capabilityIds.size, actionCount: actionIds.size };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export async function runAppValidation(args, output = process.stdout) {
|
|
49
|
+
if (args.length === 1 && args[0] === "--help") {
|
|
50
|
+
output.write("Usage: agent-lyra app validate <manifest.json>\n");
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (args.length !== 1 || args[0].startsWith("-")) {
|
|
54
|
+
throw new Error("Provide a manifest path. See agent-lyra app validate --help.");
|
|
55
|
+
}
|
|
56
|
+
const manifest = await readAppManifest(args[0]);
|
|
57
|
+
if (manifest?.version === SAVED_VERSION) {
|
|
58
|
+
validateSavedApp(manifest);
|
|
59
|
+
output.write("Valid app " + manifest.application.id + " (2 saved agents).\n");
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const { id, capabilityCount, actionCount } = validateAppManifest(manifest);
|
|
63
|
+
output.write(`Valid app ${id} (${capabilityCount} capabilities, ${actionCount} actions).\n`);
|
|
64
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { syncMemory } from "./sync.js";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { openMemoryStore } from "./index.js";
|
|
4
|
+
|
|
5
|
+
export async function runMemory(args, output = process.stdout) {
|
|
6
|
+
const [action, value, flag] = args;
|
|
7
|
+
if (action === "cloud") return runCloudMemory(args.slice(1), output);
|
|
8
|
+
if (!action || action === "--help") {
|
|
9
|
+
output.write("Usage: agent-lyra memory init | record <json-file> | list | search <query> | inspect <id> | verify <id> <evidence.json> | archive <id> | consolidate <context> | stats | forget <id> --yes | cloud --help\n");
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const bare = ["init", "list", "stats"].includes(action) && args.length === 1;
|
|
13
|
+
const withValue = ["record", "search", "inspect", "archive", "consolidate"].includes(action) && args.length === 2 && value;
|
|
14
|
+
if (!bare && !withValue && !(action === "verify" && args.length === 3 && value && flag) && !(action === "forget" && args.length === 3 && flag === "--yes" && value)) {
|
|
15
|
+
throw new Error("See agent-lyra memory --help. Forget requires --yes.");
|
|
16
|
+
}
|
|
17
|
+
const store = await openMemoryStore();
|
|
18
|
+
try {
|
|
19
|
+
let result;
|
|
20
|
+
switch (action) {
|
|
21
|
+
case "init": result = { database: store.file, ...store.stats() }; break;
|
|
22
|
+
case "record": result = store.record(JSON.parse((await readFile(value, "utf8")).replace(/^\uFEFF/, ""))); break;
|
|
23
|
+
case "list": result = store.list(); break;
|
|
24
|
+
case "search": result = store.search(value); break;
|
|
25
|
+
case "inspect": result = store.get(value); break;
|
|
26
|
+
case "verify": result = store.verify(value, JSON.parse((await readFile(flag, "utf8")).replace(/^\uFEFF/, ""))); break;
|
|
27
|
+
case "consolidate": result = store.consolidate(value); break;
|
|
28
|
+
case "archive": result = store.archive(value); break;
|
|
29
|
+
case "stats": result = store.stats(); break;
|
|
30
|
+
case "forget": result = store.forget(value) ? { deleted: value } : null; break;
|
|
31
|
+
}
|
|
32
|
+
if (result === null) throw new Error("Memory record was not found.");
|
|
33
|
+
output.write(JSON.stringify(result, null, 2) + "\n");
|
|
34
|
+
} finally { store.close(); }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function runCloudMemory(args, output) {
|
|
38
|
+
const [action, id, flag] = args;
|
|
39
|
+
if (!action || action === "--help") {
|
|
40
|
+
output.write("Usage: agent-lyra memory cloud list [cursor] | preview <id> | push <id> --yes | pull <id>\n");
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const valid = (action === "list" && args.length <= 2) ||
|
|
44
|
+
(["preview", "pull"].includes(action) && args.length === 2) ||
|
|
45
|
+
(action === "push" && args.length === 3 && flag === "--yes");
|
|
46
|
+
if (!valid) throw new Error("See agent-lyra memory cloud --help.");
|
|
47
|
+
const result = await syncMemory(process.cwd(), action, id, { confirmed: flag === "--yes" });
|
|
48
|
+
output.write(JSON.stringify(result, null, 2) + "\n");
|
|
49
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 4,
|
|
3
|
+
"applicationId": 1279873601,
|
|
4
|
+
"types": [
|
|
5
|
+
"episodic",
|
|
6
|
+
"semantic",
|
|
7
|
+
"procedural",
|
|
8
|
+
"corrective"
|
|
9
|
+
],
|
|
10
|
+
"statuses": [
|
|
11
|
+
"candidate",
|
|
12
|
+
"verified",
|
|
13
|
+
"archived"
|
|
14
|
+
],
|
|
15
|
+
"limits": {
|
|
16
|
+
"records": 5000,
|
|
17
|
+
"results": 100,
|
|
18
|
+
"title": 160,
|
|
19
|
+
"learning": 4000,
|
|
20
|
+
"evidence": 16,
|
|
21
|
+
"id": 128
|
|
22
|
+
},
|
|
23
|
+
"adapters": {"coding":{"types":["corrective"],"prefix":"test:","check":"test","error":"Verification requires a linked passing coding test, a compatibility context, and explicit review."},"practice":{"types":["corrective","procedural"],"prefix":"exercise:","check":"exercise","error":"Verification requires a linked passing practice exercise, a compatibility context, and explicit review."}},
|
|
24
|
+
"migration4": "CREATE TABLE memory_cloud_links (id TEXT PRIMARY KEY, cloud_revision INTEGER NOT NULL, local_revision INTEGER NOT NULL, cloud_account TEXT NOT NULL);",
|
|
25
|
+
"migration3": "CREATE TABLE skill_proposals (id TEXT PRIMARY KEY, context TEXT NOT NULL, title TEXT NOT NULL, markdown TEXT NOT NULL, sources TEXT NOT NULL, status TEXT NOT NULL DEFAULT 'pending' CHECK(status IN ('pending','approved','rejected','withdrawn')), created_at TEXT NOT NULL, decided_at TEXT, receipt TEXT);",
|
|
26
|
+
"migration2": "ALTER TABLE memories ADD COLUMN verification TEXT; CREATE INDEX memories_verified ON memories(status, updated_at);",
|
|
27
|
+
"migration": "CREATE TABLE memories (\n id TEXT PRIMARY KEY,\n type TEXT NOT NULL,\n title TEXT NOT NULL,\n learning TEXT NOT NULL,\n evidence TEXT NOT NULL,\n scope TEXT NOT NULL DEFAULT 'project' CHECK (scope = 'project'),\n status TEXT NOT NULL DEFAULT 'candidate',\n revision INTEGER NOT NULL DEFAULT 1,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL\n);\nCREATE TABLE memory_tombstones (id TEXT PRIMARY KEY, revision INTEGER NOT NULL, deleted_at TEXT NOT NULL);\nCREATE TABLE memory_index_state (id INTEGER PRIMARY KEY CHECK (id = 1), revision INTEGER NOT NULL, indexed_revision INTEGER NOT NULL);\nINSERT INTO memory_index_state VALUES (1, 0, -1);\nCREATE INDEX memories_status_updated ON memories (status, updated_at DESC);"
|
|
28
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export type MemoryType = "episodic" | "semantic" | "procedural" | "corrective";
|
|
2
|
+
export type MemoryStatus = "candidate" | "verified" | "archived";
|
|
3
|
+
export interface MemoryInput { type: MemoryType; title: string; learning: string; evidence?: string[] }
|
|
4
|
+
export type MemoryAdapter = "coding" | "practice";
|
|
5
|
+
export type VerificationReceipt = { evidenceId: string; context: string } & (
|
|
6
|
+
{ adapter: "coding"; test: string } | { adapter: "practice"; exercise: string }
|
|
7
|
+
);
|
|
8
|
+
export interface MemoryRecord extends MemoryInput {
|
|
9
|
+
id: string;
|
|
10
|
+
evidence: string[];
|
|
11
|
+
scope: "project";
|
|
12
|
+
status: MemoryStatus;
|
|
13
|
+
revision: number;
|
|
14
|
+
createdAt: string;
|
|
15
|
+
updatedAt: string;
|
|
16
|
+
verification?: VerificationReceipt;
|
|
17
|
+
}
|
|
18
|
+
export interface SkillProposalSource { id: string; revision: number; evidenceId: string }
|
|
19
|
+
export interface SkillProposalReceipt { evidenceId: string; context: string; result: "passed"; reviewed: true }
|
|
20
|
+
export interface SkillProposal {
|
|
21
|
+
id: string;
|
|
22
|
+
context: string;
|
|
23
|
+
title: string;
|
|
24
|
+
markdown: string;
|
|
25
|
+
sources: SkillProposalSource[];
|
|
26
|
+
status: "pending" | "approved" | "rejected" | "withdrawn";
|
|
27
|
+
createdAt: string;
|
|
28
|
+
decidedAt: string | null;
|
|
29
|
+
receipt: SkillProposalReceipt | null;
|
|
30
|
+
}
|
|
31
|
+
export interface MemoryStore {
|
|
32
|
+
readonly file: string;
|
|
33
|
+
consolidate(context: string): Array<{ title: string; learning: string; sources: SkillProposalSource[] }>;
|
|
34
|
+
propose(context: string, memoryId: string): SkillProposal;
|
|
35
|
+
proposal(id: string): SkillProposal | null;
|
|
36
|
+
proposals(): SkillProposal[];
|
|
37
|
+
decideProposal(id: string, decision: "approved" | "rejected" | "withdrawn", evidence?: SkillProposalReceipt): SkillProposal;
|
|
38
|
+
close(): void;
|
|
39
|
+
get(id: string): MemoryRecord | null;
|
|
40
|
+
list(limit?: number): MemoryRecord[];
|
|
41
|
+
record(value: MemoryInput): MemoryRecord;
|
|
42
|
+
search(query: string, limit?: number): MemoryRecord[];
|
|
43
|
+
stats(): { schemaVersion: number; search: "fts5" | "keyword" } & Record<MemoryStatus, number>;
|
|
44
|
+
verify(id: string, evidence: VerificationReceipt & { result: "passed"; reviewed: true }): MemoryRecord;
|
|
45
|
+
retrieve(query: string, context: string, adapter?: MemoryAdapter): MemoryRecord[];
|
|
46
|
+
archive(id: string): MemoryRecord | null;
|
|
47
|
+
forget(id: string): boolean;
|
|
48
|
+
}
|
|
49
|
+
export function openMemoryStore(root?: string, options?: { forceKeyword?: boolean }): Promise<MemoryStore>;
|