agent-lyra 0.12.0 → 0.14.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/README.md +43 -25
- package/bin/agent-lyra.js +4 -1
- package/bin/lyra-oss-preview.js +3 -1
- package/package.json +1 -1
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/init.js +13 -1
- package/src/intelligence/graph-setup.js +125 -0
- package/src/intelligence/lifecycle.js +2 -1
- package/src/runtime/mcp-tool.d.ts +24 -0
- package/src/runtime/mcp-tool.js +39 -0
- package/src/standalone/init.js +4 -2
- package/src/studio/browser.js +100 -5
- package/src/studio/code-discovery.js +81 -0
- package/src/studio/export.js +3 -3
- package/src/studio/graphsnip-workbench.js +21 -26
- package/src/studio/history-panel.js +51 -13
- package/src/studio/index.html +26 -3
- package/src/studio/intelligence.js +18 -2
- package/src/studio/mcp-bridge.mjs +11 -0
- package/src/studio/mcp-connection.js +167 -0
- package/src/studio/mcp-panel.js +97 -0
- package/src/studio/programmatic.js +22 -14
- package/src/studio/project.js +2 -2
- package/src/studio/python-agent.py +3 -0
- package/src/studio/run-history.js +11 -2
- package/src/studio/server.js +45 -7
- package/src/studio/studio.css +62 -0
package/src/studio/browser.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { mountMcpPanel } from "./mcp-panel.js";
|
|
1
2
|
import { mountIntelligence } from "./intelligence.js";
|
|
2
3
|
import { mountWorkflowEditor } from "./workflow-editor.js";
|
|
3
4
|
import { mountHistoryPanel } from "./history-panel.js";
|
|
@@ -48,12 +49,14 @@ async function api(path, data) {
|
|
|
48
49
|
return payload;
|
|
49
50
|
}
|
|
50
51
|
|
|
52
|
+
const openMcpPanel = mountMcpPanel(api, () => project);
|
|
51
53
|
const openMemoryPanel = mountMemoryPanel(api);
|
|
52
54
|
const workbenchViews = {
|
|
53
55
|
mission: ["open-history", "history-panel"],
|
|
54
56
|
registry: ["show-registry", "library"],
|
|
55
57
|
layout: ["show-layout", "canvas-panel"],
|
|
56
58
|
workflow: ["show-workflow", "workflow-panel"],
|
|
59
|
+
tools: ["show-tools", "mcp-panel"],
|
|
57
60
|
cloud: ["show-cloud", "cloud-settings"],
|
|
58
61
|
graph: ["show-graph", "graph-panel"],
|
|
59
62
|
tokens: ["show-tokens", "token-panel"],
|
|
@@ -61,6 +64,70 @@ const workbenchViews = {
|
|
|
61
64
|
let view = "layout";
|
|
62
65
|
let layoutLibraryView = libraryView;
|
|
63
66
|
let layoutSearch = "";
|
|
67
|
+
let registrySource = "";
|
|
68
|
+
let discoveryRequest = 0;
|
|
69
|
+
|
|
70
|
+
async function refreshDiscovery() {
|
|
71
|
+
const current = ++discoveryRequest;
|
|
72
|
+
const region = $("#discovery-status");
|
|
73
|
+
region.replaceChildren(element("p", "Discovering code-defined agents…"));
|
|
74
|
+
try {
|
|
75
|
+
const { candidates } = await api("code-agents");
|
|
76
|
+
if (current !== discoveryRequest) return;
|
|
77
|
+
region.replaceChildren();
|
|
78
|
+
if (!candidates.length) return;
|
|
79
|
+
const review = $("#discovery-review");
|
|
80
|
+
region.append(dom("div", { className: "discovery-callout" },
|
|
81
|
+
dom("div", {}, element("strong", candidates.length + (candidates.length === 1 ? " agent ready to add" : " agents ready to add")),
|
|
82
|
+
element("p", "Found code-defined agents in this project.")),
|
|
83
|
+
button("Review and add", () => {
|
|
84
|
+
const items = $("#discovery-items");
|
|
85
|
+
const submit = $("#add-discovered");
|
|
86
|
+
const close = $("#close-discovery");
|
|
87
|
+
const error = $("#discovery-error");
|
|
88
|
+
items.replaceChildren();
|
|
89
|
+
error.textContent = "";
|
|
90
|
+
const checks = candidates.map(candidate => {
|
|
91
|
+
const input = dom("input", { type: "checkbox", value: candidate.id });
|
|
92
|
+
input.checked = true;
|
|
93
|
+
items.append(dom("label", { className: "discovery-option" }, input,
|
|
94
|
+
dom("span", {}, element("strong", candidate.name), element("code", candidate.file))));
|
|
95
|
+
return input;
|
|
96
|
+
});
|
|
97
|
+
const selected = () => checks.filter(input => input.checked).map(input => input.value);
|
|
98
|
+
const update = () => {
|
|
99
|
+
const count = selected().length;
|
|
100
|
+
submit.disabled = !count;
|
|
101
|
+
submit.textContent = "Add " + count + (count === 1 ? " agent" : " agents");
|
|
102
|
+
};
|
|
103
|
+
checks.forEach(input => { input.onchange = update; });
|
|
104
|
+
close.onclick = () => review.close();
|
|
105
|
+
submit.onclick = async () => {
|
|
106
|
+
const ids = selected();
|
|
107
|
+
submit.disabled = close.disabled = true;
|
|
108
|
+
checks.forEach(input => { input.disabled = true; });
|
|
109
|
+
submit.textContent = "Adding " + ids.length + (ids.length === 1 ? " agent…" : " agents…");
|
|
110
|
+
error.textContent = "";
|
|
111
|
+
try {
|
|
112
|
+
const { added } = await api("code-agents/add", { ids });
|
|
113
|
+
await load({ catalogOnly: true });
|
|
114
|
+
review.close();
|
|
115
|
+
announce(added ? "Added " + added + " to Agent Registry." : "Registry is already up to date.");
|
|
116
|
+
void refreshDiscovery();
|
|
117
|
+
} catch (failure) { error.textContent = failure.message; }
|
|
118
|
+
finally {
|
|
119
|
+
close.disabled = false;
|
|
120
|
+
checks.forEach(input => { input.disabled = false; });
|
|
121
|
+
update();
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
update();
|
|
125
|
+
review.showModal();
|
|
126
|
+
})));
|
|
127
|
+
} catch (error) {
|
|
128
|
+
if (current === discoveryRequest) region.replaceChildren(element("p", error.message));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
64
131
|
|
|
65
132
|
function showView(next) {
|
|
66
133
|
const search = $("#library-search");
|
|
@@ -84,6 +151,9 @@ function showView(next) {
|
|
|
84
151
|
$("#library").classList.toggle("registry-view", next === "registry");
|
|
85
152
|
$("#library-title").textContent = next === "registry" ? "Agent Registry" : "Project library";
|
|
86
153
|
$("#library-tabs").hidden = next === "registry";
|
|
154
|
+
$("#discovery-status").hidden = next !== "registry";
|
|
155
|
+
if (next === "registry") void refreshDiscovery();
|
|
156
|
+
if (next === "tools") void openMcpPanel();
|
|
87
157
|
$("#refresh").hidden = next !== "registry";
|
|
88
158
|
$("#save").hidden = next !== "layout";
|
|
89
159
|
if (next !== "layout") closeInspector();
|
|
@@ -275,11 +345,22 @@ function renderCatalog() {
|
|
|
275
345
|
const id = libraryView;
|
|
276
346
|
const section = $("#" + id);
|
|
277
347
|
const query = search.value.trim().toLowerCase();
|
|
278
|
-
const
|
|
348
|
+
const inRegistry = view === "registry" && id === "agents";
|
|
349
|
+
const rows = project[id].filter(row => !row.linkedLocalId && (!inRegistry || !registrySource || (registrySource === "cloud" ? row.source === "cloud" : row.source !== "cloud")) && [row.name, row.source, row.framework, agentSources[row.source]]
|
|
279
350
|
.some(value => value?.toLowerCase().includes(query)));
|
|
280
351
|
const expanded = new Set([...section.querySelectorAll(".agent-options[open]")].map(item => item.dataset.agent));
|
|
281
352
|
section.replaceChildren();
|
|
282
|
-
|
|
353
|
+
const grid = inRegistry ? dom("div", { className: "registry-grid" }) : section;
|
|
354
|
+
if (inRegistry) {
|
|
355
|
+
const filters = dom("div", { className: "workbench-filters", "aria-label": "Agent source filters" });
|
|
356
|
+
for (const [value, label] of [["", "All"], ["local", "Local"], ["cloud", "Cloud"]]) {
|
|
357
|
+
const control = button(label, () => { registrySource = value; renderCatalog(); });
|
|
358
|
+
control.setAttribute("aria-pressed", String(registrySource === value));
|
|
359
|
+
filters.append(control);
|
|
360
|
+
}
|
|
361
|
+
section.append(filters, grid);
|
|
362
|
+
}
|
|
363
|
+
if (id === "agents" && !project.cloudConnected && !inRegistry) {
|
|
283
364
|
const callout = dom("div", { className: "cloud-callout" },
|
|
284
365
|
element("p", "Connect to AgentLyra Cloud to pull, push, and sync agents."),
|
|
285
366
|
button("Open Cloud Sync", () => showView("cloud")));
|
|
@@ -335,15 +416,28 @@ function renderCatalog() {
|
|
|
335
416
|
run.append(dom("span", { className: "play-icon" }));
|
|
336
417
|
const entry = dom("article", { className: "library-entry" },
|
|
337
418
|
dom("div", { className: "agent-row" }, dom("div", { className: "agent-label" }, name, metadata), run));
|
|
419
|
+
let options;
|
|
338
420
|
if (push || pull || sync) {
|
|
339
421
|
const control = dom("summary", { className: "agent-icon", title: "Cloud actions",
|
|
340
422
|
"aria-label": "Cloud actions for " + row.name }, "⋯");
|
|
341
|
-
|
|
423
|
+
options = dom("details", { className: "agent-options", open: expanded.has(row.id) },
|
|
342
424
|
control, dom("div", { className: "actions" }, push, pull, sync));
|
|
343
425
|
options.dataset.agent = row.id;
|
|
344
426
|
entry.append(options);
|
|
345
427
|
}
|
|
346
|
-
|
|
428
|
+
if (inRegistry) {
|
|
429
|
+
const description = row.description || row.file || ({
|
|
430
|
+
local: "Text agent in this project", cloud: "Agent from your Cloud workspace",
|
|
431
|
+
programmatic: "Code-defined agent in this project", framework: "Registered framework agent", python: "Python agent in this project",
|
|
432
|
+
})[row.source];
|
|
433
|
+
grid.append(renderAgentCard(dom, { name: row.name, source,
|
|
434
|
+
header: dom("div", { className: "registry-card-heading" },
|
|
435
|
+
dom("span", { className: "registry-icon", "aria-hidden": "true" }, row.file ? "‹/›" : "◇"),
|
|
436
|
+
dom("div", {}, name, metadata)),
|
|
437
|
+
details: element("p", description), extraAction: options,
|
|
438
|
+
runIcon: dom("span", { className: "play-icon", "aria-hidden": "true" }), onRun: () => openRun([row.id]),
|
|
439
|
+
}));
|
|
440
|
+
} else section.append(entry);
|
|
347
441
|
continue;
|
|
348
442
|
}
|
|
349
443
|
const card = element("article");
|
|
@@ -699,8 +793,9 @@ $("#canvas").ondrop = event => {
|
|
|
699
793
|
change();
|
|
700
794
|
};
|
|
701
795
|
$("#show-registry").onclick = () => showView("registry");
|
|
796
|
+
$("#show-tools").onclick = () => showView("tools");
|
|
702
797
|
$("#show-cloud").onclick = () => showView("cloud");
|
|
703
|
-
$("#refresh").onclick = () => load({ catalogOnly: true }).then(() => announce("Project refreshed.")).catch(error => announce(error.message));
|
|
798
|
+
$("#refresh").onclick = () => load({ catalogOnly: true }).then(() => { announce("Project refreshed."); if (view === "registry") void refreshDiscovery(); }).catch(error => announce(error.message));
|
|
704
799
|
function openCloudSetup() {
|
|
705
800
|
$("#cloud-key").value = "";
|
|
706
801
|
$("#cloud-key").required = !project.hasCloudKey;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { lstat, mkdir, readdir, readFile, writeFile } from "node:fs/promises";
|
|
3
|
+
import { basename, join } from "node:path";
|
|
4
|
+
|
|
5
|
+
const excluded = new Set(["node_modules", "vendor", "dist", "build", "coverage", "graphify-out", "__pycache__"]);
|
|
6
|
+
const sourcePath = /^(?:[a-zA-Z0-9_.-]+\/)*[a-zA-Z0-9_-]+\.(?:mjs|js|mts|ts|py)$/;
|
|
7
|
+
|
|
8
|
+
export async function resolveAgentSource(root, file, projectRelative = false) {
|
|
9
|
+
if (!sourcePath.test(file) || file.split("/").some(part => part === "." || part === "..")) {
|
|
10
|
+
throw new Error("Use a project-relative agent source path.");
|
|
11
|
+
}
|
|
12
|
+
const parts = projectRelative ? file.split("/") : [".lyra", "agents", file];
|
|
13
|
+
let current = root;
|
|
14
|
+
for (const [index, part] of parts.entries()) {
|
|
15
|
+
current = join(current, part);
|
|
16
|
+
const stat = await lstat(current);
|
|
17
|
+
if (index === parts.length - 1 ? !stat.isFile() : !stat.isDirectory()) {
|
|
18
|
+
throw new Error("Use a regular agent source file inside this project.");
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return current;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function discoverCodeAgents(root, agents) {
|
|
25
|
+
const entries = new Set([...agents.values()].filter(agent => agent.source === "programmatic")
|
|
26
|
+
.map(agent => agent.projectRelative ? agent.file : ".lyra/agents/" + agent.file));
|
|
27
|
+
const found = [];
|
|
28
|
+
let scanned = 0;
|
|
29
|
+
const queue = [{ path: "", depth: 0 }];
|
|
30
|
+
while (queue.length && found.length < 40 && scanned < 1500) {
|
|
31
|
+
const { path, depth } = queue.shift();
|
|
32
|
+
const directory = join(root, path);
|
|
33
|
+
if (!(await lstat(directory).catch(() => null))?.isDirectory()) continue;
|
|
34
|
+
for (const entry of await readdir(directory, { withFileTypes: true }).catch(() => [])) {
|
|
35
|
+
if (++scanned > 1500 || found.length >= 40) break;
|
|
36
|
+
const file = path ? path + "/" + entry.name : entry.name;
|
|
37
|
+
if (entry.isDirectory() && depth < 5 && queue.length < 300 && !excluded.has(entry.name) &&
|
|
38
|
+
(!entry.name.startsWith(".") || [".lyra", ".lyra/agents"].includes(file)) &&
|
|
39
|
+
(path !== ".lyra" || entry.name === "agents")) queue.push({ path: file, depth: depth + 1 });
|
|
40
|
+
if (!entry.isFile() || !sourcePath.test(file) || entries.has(file)) continue;
|
|
41
|
+
const full = join(root, file);
|
|
42
|
+
const stat = await lstat(full).catch(() => null);
|
|
43
|
+
if (!stat?.isFile() || stat.size > 128 * 1024) continue;
|
|
44
|
+
const source = await readFile(full, "utf8").catch(() => "");
|
|
45
|
+
const python = file.endsWith(".py");
|
|
46
|
+
if (python ? !/^from lyra import [^\n]*\bAgent\b/m.test(source) || !/^agent\s*=\s*Agent\(/m.test(source)
|
|
47
|
+
: !/import\s*\{[^}]*\bAgent\b[^}]*\}\s*from\s*["']agent-lyra["']/.test(source) ||
|
|
48
|
+
!/^\s*export\s+const\s+agent\s*=\s*new\s+Agent(?:<[^\r\n>]{1,200}>)?\s*\(/m.test(source)) continue;
|
|
49
|
+
const id = "code-" + createHash("sha256").update(file).digest("hex").slice(0, 20);
|
|
50
|
+
const name = basename(file).replace(/\.[^.]+$/, "").replace(/[-_]+/g, " ");
|
|
51
|
+
found.push({ id, name, file, runtime: python ? "lyra-python" : "lyra-node", projectRelative: true,
|
|
52
|
+
input: /\b(?:inputSchema\s*:|input_schema\s*=)\s*\{\s*["']?type["']?\s*:\s*["'](?:object|array|number|integer|boolean|null)["']/.test(source) ? "json" : "text" });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return found;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export async function registerCodeAgents(root, ids, agents) {
|
|
59
|
+
if (!Array.isArray(ids) || !ids.length || ids.length > 40 || ids.some(id => !/^code-[a-f\d]{20}$/.test(id))) {
|
|
60
|
+
throw new Error("Select discovered agents to add.");
|
|
61
|
+
}
|
|
62
|
+
const candidates = await discoverCodeAgents(root, agents);
|
|
63
|
+
const chosen = candidates.filter(candidate => ids.includes(candidate.id));
|
|
64
|
+
const folder = join(root, ".lyra");
|
|
65
|
+
const directory = join(folder, "agents");
|
|
66
|
+
for (const path of [folder, directory]) {
|
|
67
|
+
await mkdir(path).catch(error => { if (error.code !== "EEXIST") throw error; });
|
|
68
|
+
if (!(await lstat(path)).isDirectory()) throw new Error("Use regular .lyra/agents directories.");
|
|
69
|
+
}
|
|
70
|
+
let added = 0;
|
|
71
|
+
for (const candidate of chosen) {
|
|
72
|
+
try {
|
|
73
|
+
await resolveAgentSource(root, candidate.file, true);
|
|
74
|
+
await writeFile(join(directory, candidate.id + ".json"), JSON.stringify(candidate, null, 2) + "\n", { flag: "wx" });
|
|
75
|
+
added++;
|
|
76
|
+
} catch (error) {
|
|
77
|
+
if (!["EEXIST", "ENOENT"].includes(error.code)) throw error;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return { added };
|
|
81
|
+
}
|
package/src/studio/export.js
CHANGED
|
@@ -5,11 +5,11 @@ import { readCatalog, resolveSequence, validateLayout, validateRunBindings } fro
|
|
|
5
5
|
|
|
6
6
|
const runtime = [
|
|
7
7
|
"resource-files.js",
|
|
8
|
-
"studio/server.js", "studio/memory-actions.js", "studio/memory-panel.js", "studio/history-panel.js", "studio/intelligence.js", "studio/graphsnip-workbench.js", "studio/mission-ui.js", "studio/mission-ui.css", "studio/project.js", "studio/sync.js", "studio/index.html", "studio/lyra-icon.png",
|
|
9
|
-
"studio/browser.js", "studio/workflow-editor.js", "studio/cli-providers.js", "studio/ide-provider.js", "studio/local-provider.js", "studio/run-history.js", "studio/studio.css", "studio/agent-ui.js", "studio/agent-ui.css", "app-builder/saved-app.js",
|
|
8
|
+
"studio/server.js", "studio/mcp-connection.js", "studio/mcp-panel.js", "studio/mcp-bridge.mjs", "studio/memory-actions.js", "studio/memory-panel.js", "studio/history-panel.js", "studio/intelligence.js", "studio/graphsnip-workbench.js", "studio/mission-ui.js", "studio/mission-ui.css", "studio/project.js", "studio/sync.js", "studio/index.html", "studio/lyra-icon.png",
|
|
9
|
+
"studio/browser.js", "studio/workflow-editor.js", "studio/cli-providers.js", "studio/ide-provider.js", "studio/local-provider.js", "studio/run-history.js", "studio/studio.css", "studio/agent-ui.js", "studio/agent-ui.css", "studio/code-discovery.js", "app-builder/saved-app.js",
|
|
10
10
|
"memory/index.js", "memory/external-engine.js", "memory/UPSTREAM.json", "memory/local-store.js", "memory/cloud-sync-actions.js", "memory/validation.js", "memory/proposals.js", "memory/sync.js", "memory/lifecycle.js", "memory/contract.json",
|
|
11
11
|
"framework/agent.js", "framework/run.py", "framework/mda.js",
|
|
12
|
-
"intelligence/lifecycle.js", "intelligence/graphsnip-provider.js",
|
|
12
|
+
"intelligence/lifecycle.js", "intelligence/graphsnip-provider.js", "intelligence/graph-setup.js",
|
|
13
13
|
"runtime/local-cli.js", "runtime/run-agent.js", "studio/session.js", "studio/push.js", "studio/workflow-sync.js", "studio/pull-agent.js", "studio/python-agent.js", "studio/python-agent.py", "studio/programmatic.js", "studio/programmatic-runner.mjs",
|
|
14
14
|
];
|
|
15
15
|
|
|
@@ -1,33 +1,27 @@
|
|
|
1
|
-
import { execFile } from "node:child_process";
|
|
2
1
|
import { lstat, readFile } from "node:fs/promises";
|
|
3
2
|
import { join } from "node:path";
|
|
4
|
-
import {
|
|
3
|
+
import { graphSnipCommand, graphSnipStatus, refreshGraphSnip } from "../intelligence/graph-setup.js";
|
|
5
4
|
|
|
6
|
-
const exec = promisify(execFile);
|
|
7
|
-
const graphsnipVersion = "0.3.0";
|
|
8
5
|
const name = value => typeof value === "string" ? value.slice(0, 160) : String(value ?? "").slice(0, 160);
|
|
9
6
|
|
|
10
|
-
async function
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
async function graphReportFile(root) {
|
|
8
|
+
const folder = join(root, ".graphsnip");
|
|
9
|
+
const path = join(folder, "dashboard.html");
|
|
10
|
+
try {
|
|
11
|
+
if (!(await lstat(folder)).isDirectory()) return null;
|
|
12
|
+
const stat = await lstat(path);
|
|
13
|
+
if (!stat.isFile() || stat.size > 4 * 1024 * 1024) return null;
|
|
14
|
+
return { path, updatedAt: stat.mtimeMs };
|
|
15
|
+
} catch { return null; }
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
async function
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
// The upstream 0.3.0 wheel still reports 0.2.1 from its CLI.
|
|
21
|
-
return ["graphsnip 0.2.1", "graphsnip " + graphsnipVersion].includes(actual)
|
|
22
|
-
? { installed: true, version: actual.slice("graphsnip ".length) }
|
|
23
|
-
: { installed: false, issue: "Workbench supports GraphSnip " + graphsnipVersion + "." };
|
|
24
|
-
} catch {
|
|
25
|
-
return { installed: false, issue: "Install GraphSnip " + graphsnipVersion + " or set LYRA_GRAPHSNIP_EXECUTABLE to its executable." };
|
|
26
|
-
}
|
|
18
|
+
export async function readGraphReport(root) {
|
|
19
|
+
const report = await graphReportFile(root);
|
|
20
|
+
return report ? readFile(report.path, "utf8") : null;
|
|
27
21
|
}
|
|
28
22
|
|
|
29
23
|
export async function knowledgeGraph(root) {
|
|
30
|
-
const dependency = await
|
|
24
|
+
const dependency = await graphSnipStatus(root);
|
|
31
25
|
const folder = join(root, "graphify-out");
|
|
32
26
|
const path = join(folder, "graph.json");
|
|
33
27
|
try {
|
|
@@ -46,28 +40,29 @@ export async function knowledgeGraph(root) {
|
|
|
46
40
|
if (ids.has(source) && ids.has(target)) links.push({ source, target });
|
|
47
41
|
if (links.length >= 300) break;
|
|
48
42
|
}
|
|
49
|
-
|
|
43
|
+
const report = await graphReportFile(root);
|
|
44
|
+
return { ...dependency, report: report && { updatedAt: report.updatedAt, stale: report.updatedAt < file.mtimeMs }, graph: { nodeCount: graph.nodes.length, edgeCount: edges.length, nodes, links } };
|
|
50
45
|
} catch (error) {
|
|
51
46
|
return { ...dependency, graph: null, ...(error.code === "ENOENT" ? {} : { graphIssue: "The graph is unreadable or exceeds the Workbench size limit." }) };
|
|
52
47
|
}
|
|
53
48
|
}
|
|
54
49
|
|
|
55
50
|
export async function buildKnowledgeGraph(root) {
|
|
56
|
-
const dependency = await
|
|
51
|
+
const dependency = await graphSnipStatus(root);
|
|
57
52
|
if (!dependency.installed) throw new Error(dependency.issue);
|
|
58
53
|
try {
|
|
59
|
-
await
|
|
54
|
+
await refreshGraphSnip(root);
|
|
60
55
|
} catch {
|
|
61
|
-
throw new Error("GraphSnip could not update the graph. Run
|
|
56
|
+
throw new Error("GraphSnip could not update the graph or report. Run agent-lyra graph build and agent-lyra graph report in the project terminal for details.");
|
|
62
57
|
}
|
|
63
58
|
return knowledgeGraph(root);
|
|
64
59
|
}
|
|
65
60
|
|
|
66
61
|
export async function graphTokenLedger(root) {
|
|
67
|
-
const dependency = await
|
|
62
|
+
const dependency = await graphSnipStatus(root);
|
|
68
63
|
if (!dependency.installed) return dependency;
|
|
69
64
|
try {
|
|
70
|
-
const result = JSON.parse(await
|
|
65
|
+
const result = JSON.parse(await graphSnipCommand(root, ["stats", "--json"]));
|
|
71
66
|
const projectLedger = group => Object.fromEntries(["calls", "baseline", "returned", "saved", "pct", "usd_saved"]
|
|
72
67
|
.filter(key => Number.isFinite(group?.[key])).map(key => [key, group[key]]));
|
|
73
68
|
return { ...dependency, live: projectLedger(result.live), benchmark: projectLedger(result.bench) };
|
|
@@ -80,7 +80,44 @@ export function mountHistoryPanel(api, showMissionControl, h, openMemory) {
|
|
|
80
80
|
const detail = panel.querySelector("#history-detail");
|
|
81
81
|
const status = panel.querySelector("#history-status");
|
|
82
82
|
const open = document.querySelector("#open-history");
|
|
83
|
+
const summary = panel.querySelector("#history-summary");
|
|
84
|
+
const search = panel.querySelector("#history-search");
|
|
85
|
+
const filter = panel.querySelector("#history-filter");
|
|
86
|
+
let runs = [];
|
|
83
87
|
let selection;
|
|
88
|
+
function duration(run) { return run.endedAt ? Date.parse(run.endedAt) - Date.parse(run.startedAt) : undefined; }
|
|
89
|
+
function renderRuns() {
|
|
90
|
+
const today = new Date().toDateString();
|
|
91
|
+
const current = runs.filter(run => new Date(run.endedAt).toDateString() === today);
|
|
92
|
+
const durations = current.map(duration).filter(Number.isFinite);
|
|
93
|
+
const mean = durations.length ? formatMissionDuration(durations.reduce((sum, value) => sum + value, 0) / durations.length) : "—";
|
|
94
|
+
summary.replaceChildren(...[
|
|
95
|
+
["Running", runs.filter(run => run.status === "running").length],
|
|
96
|
+
["Completed today", current.filter(run => run.status === "completed").length],
|
|
97
|
+
["Failed today", current.filter(run => run.status === "failed").length], ["Avg duration today", mean],
|
|
98
|
+
].map(([label, value]) => h("div", {}, element("span", label), element("strong", String(value)))));
|
|
99
|
+
const query = search.value.trim().toLowerCase();
|
|
100
|
+
const visible = runs.filter(run => (!filter.value || filter.value === run.status) &&
|
|
101
|
+
[run.agentName, run.id, run.source].some(value => value?.toLowerCase().includes(query)));
|
|
102
|
+
list.replaceChildren();
|
|
103
|
+
if (!visible.length) {
|
|
104
|
+
list.append(element("p", runs.length ? "No matching runs." : "No runs in this project yet."));
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const table = element("table", undefined, "workbench-run-table");
|
|
108
|
+
table.append(h("thead", {}, h("tr", {}, ...["Run", "Source", "Status", "Started", "Duration"].map(title => h("th", { scope: "col" }, title)))));
|
|
109
|
+
table.append(h("tbody", {}, ...visible.map(run => {
|
|
110
|
+
const item = link(run.agentName || "Run " + run.id.slice(0, 8), historyHash(run.id));
|
|
111
|
+
if (run.id === selection) item.setAttribute("aria-current", "true");
|
|
112
|
+
return h("tr", { className: run.id === selection ? "selected-run" : "" },
|
|
113
|
+
h("td", {}, item, run.steps > 1 ? element("small", run.steps + " steps") : undefined),
|
|
114
|
+
h("td", {}, ({ cloud: "Cloud agent", local: "Local text", programmatic: "Local code", framework: "Local framework", python: "Python" })[run.source] ?? "—"),
|
|
115
|
+
h("td", {}, renderMissionStatus(h, run.status)),
|
|
116
|
+
h("td", {}, date.format(new Date(run.startedAt))), h("td", {}, formatMissionDuration(duration(run))));
|
|
117
|
+
})));
|
|
118
|
+
list.append(table);
|
|
119
|
+
}
|
|
120
|
+
search.oninput = filter.onchange = renderRuns;
|
|
84
121
|
let section = "steps";
|
|
85
122
|
let request = 0;
|
|
86
123
|
|
|
@@ -92,19 +129,16 @@ export function mountHistoryPanel(api, showMissionControl, h, openMemory) {
|
|
|
92
129
|
try {
|
|
93
130
|
const [history, report] = await Promise.all([api("history"), id ? api("history/" + id) : undefined]);
|
|
94
131
|
if (current !== request) return;
|
|
95
|
-
|
|
132
|
+
runs = history.runs;
|
|
133
|
+
renderRuns();
|
|
96
134
|
detail.replaceChildren();
|
|
97
|
-
|
|
98
|
-
const row = link("", historyHash(run.id));
|
|
99
|
-
row.className = "history-row";
|
|
100
|
-
if (run.id === id) row.setAttribute("aria-current", "true");
|
|
101
|
-
row.append(renderMissionStatus(h, run.status),
|
|
102
|
-
element("span", date.format(new Date(run.startedAt))), element("code", run.id.slice(0, 8)));
|
|
103
|
-
list.append(row);
|
|
104
|
-
}
|
|
105
|
-
if (!history.runs.length) list.append(element("p", "No runs in this project yet."));
|
|
135
|
+
if (!report && detail.open) detail.close();
|
|
106
136
|
if (report) {
|
|
107
|
-
|
|
137
|
+
const run = runs.find(item => item.id === id);
|
|
138
|
+
const close = h("button", { type: "button", onClick: () => detail.close() }, "Close");
|
|
139
|
+
if (!detail.open) detail.show();
|
|
140
|
+
detail.append(h("header", {}, element("h2", run?.agentName || "Run details"), close),
|
|
141
|
+
renderMissionStatus(h, report.run.status),
|
|
108
142
|
element("code", report.run.id),
|
|
109
143
|
link("Download JSON report", "/api/history/" + report.run.id + "/report"),
|
|
110
144
|
report.run.status === "completed" ? h("button", {
|
|
@@ -124,8 +158,6 @@ export function mountHistoryPanel(api, showMissionControl, h, openMemory) {
|
|
|
124
158
|
detail.insertBefore(box, detail.querySelector(".history-detail-tabs"));
|
|
125
159
|
}
|
|
126
160
|
}
|
|
127
|
-
} else if (history.runs.length) {
|
|
128
|
-
detail.append(element("p", "Select a run to see its timeline and download a report."));
|
|
129
161
|
}
|
|
130
162
|
status.textContent = "";
|
|
131
163
|
} catch (error) {
|
|
@@ -135,6 +167,12 @@ export function mountHistoryPanel(api, showMissionControl, h, openMemory) {
|
|
|
135
167
|
}
|
|
136
168
|
}
|
|
137
169
|
|
|
170
|
+
detail.addEventListener("close", () => {
|
|
171
|
+
if (location.hash.startsWith("#run=")) history.replaceState(history.state, "", location.pathname + location.search);
|
|
172
|
+
selection = undefined;
|
|
173
|
+
renderRuns();
|
|
174
|
+
});
|
|
175
|
+
|
|
138
176
|
function syncLocation() {
|
|
139
177
|
if (open.hidden) return;
|
|
140
178
|
const id = location.hash.startsWith("#run=") ? location.hash.slice(5) : "";
|
package/src/studio/index.html
CHANGED
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
<div role="group" aria-labelledby="nav-development">
|
|
17
17
|
<span id="nav-development">Development</span>
|
|
18
18
|
<button id="show-registry" type="button" aria-pressed="false">Agent Registry</button>
|
|
19
|
+
<button id="show-tools" type="button" aria-pressed="false">Tools</button>
|
|
20
|
+
</div>
|
|
21
|
+
<div role="group" aria-labelledby="nav-app-builder">
|
|
22
|
+
<span id="nav-app-builder">App Builder</span>
|
|
19
23
|
<button id="show-layout" type="button" aria-pressed="true">Layout</button>
|
|
20
24
|
<button id="show-workflow" type="button" aria-pressed="false">Workflow</button>
|
|
21
25
|
</div>
|
|
@@ -45,15 +49,17 @@
|
|
|
45
49
|
<section id="history-panel" aria-labelledby="history-title" hidden>
|
|
46
50
|
<div class="history-heading"><div><h1 id="history-title">Mission Control</h1><p>Local run history for this project.</p></div>
|
|
47
51
|
<button id="refresh-history" type="button">Refresh runs</button></div>
|
|
52
|
+
<div id="history-summary" class="workbench-metrics"></div>
|
|
53
|
+
<div class="workbench-filters"><input id="history-search" type="search" aria-label="Search runs" placeholder="Search runs…"><select id="history-filter" aria-label="Filter runs"><option value="">All runs</option><option value="running">Running</option><option value="completed">Completed</option><option value="failed">Failed</option></select></div>
|
|
48
54
|
<p id="history-status" role="status"></p>
|
|
49
55
|
<div class="history-content">
|
|
50
56
|
<nav id="history-list" aria-label="Recent runs"></nav>
|
|
51
|
-
<
|
|
57
|
+
<dialog id="history-detail" aria-label="Run details"></dialog>
|
|
52
58
|
</div>
|
|
53
59
|
</section>
|
|
54
60
|
<section id="graph-panel" class="intelligence-panel" aria-labelledby="graph-title" hidden>
|
|
55
61
|
<div class="history-heading"><h1 id="graph-title">Knowledge Graph</h1>
|
|
56
|
-
<button id="build-graph" type="button" disabled>Build
|
|
62
|
+
<button id="build-graph" type="button" disabled>Build graph and report</button></div>
|
|
57
63
|
<div id="graph-content" aria-live="polite"></div>
|
|
58
64
|
</section>
|
|
59
65
|
<section id="token-panel" class="intelligence-panel" aria-labelledby="token-title" hidden>
|
|
@@ -62,6 +68,21 @@
|
|
|
62
68
|
<p>GraphSnip estimates context tokens against its baseline. Provider-reported usage is shown per run in Mission Control.</p>
|
|
63
69
|
<div id="token-content" aria-live="polite"></div>
|
|
64
70
|
</section>
|
|
71
|
+
<section id="mcp-panel" aria-labelledby="mcp-title" hidden>
|
|
72
|
+
<h1 id="mcp-title">Tools</h1>
|
|
73
|
+
<p>Inspect a local MCP server and grant specific tools to a registered executable agent.</p>
|
|
74
|
+
<form id="mcp-connect" class="mcp-connect">
|
|
75
|
+
<label for="mcp-endpoint">Local MCP server URL</label>
|
|
76
|
+
<input id="mcp-endpoint" type="url" required maxlength="512" placeholder="http://127.0.0.1:3001/mcp">
|
|
77
|
+
<div class="actions"><button id="mcp-inspect" class="primary" type="submit">Inspect server</button>
|
|
78
|
+
<button id="mcp-disconnect" type="button" hidden>Disconnect</button></div>
|
|
79
|
+
</form>
|
|
80
|
+
<p id="mcp-status" role="status"></p>
|
|
81
|
+
<label for="mcp-agent">Executable agent</label>
|
|
82
|
+
<select id="mcp-agent"></select>
|
|
83
|
+
<div id="mcp-tool-list"></div>
|
|
84
|
+
<button type="button" id="mcp-save" class="primary" disabled>Save tool access</button>
|
|
85
|
+
</section>
|
|
65
86
|
<section id="cloud-settings" aria-labelledby="cloud-settings-title" hidden>
|
|
66
87
|
<h1 id="cloud-settings-title">Cloud Sync</h1>
|
|
67
88
|
<p id="cloud-settings-description"></p>
|
|
@@ -85,6 +106,8 @@
|
|
|
85
106
|
</nav>
|
|
86
107
|
<label id="library-search-label" for="library-search" hidden>Search library</label>
|
|
87
108
|
<input id="library-search" type="search" placeholder="Search by name or source" hidden>
|
|
109
|
+
<div id="discovery-status" aria-live="polite" hidden></div>
|
|
110
|
+
<dialog id="discovery-review" aria-labelledby="discovery-title"><header><h2 id="discovery-title">Add to Registry</h2><button id="close-discovery" type="button">Close</button></header><p>These registrations are saved in this project.</p><div id="discovery-items"></div><p id="discovery-error" role="status"></p><button id="add-discovered" type="button" class="primary">Add selected agents</button></dialog>
|
|
88
111
|
<div id="library-content"><div id="palette"></div><div id="agents" hidden></div><div id="workflows" hidden></div><div id="teams" hidden></div><div id="skills" hidden></div></div>
|
|
89
112
|
</aside>
|
|
90
113
|
<section id="workflow-panel" aria-labelledby="workflow-title" hidden>
|
|
@@ -133,7 +156,7 @@
|
|
|
133
156
|
<details><summary>Skill proposals</summary><section id="memory-proposals" aria-label="Skill proposals"></section></details>
|
|
134
157
|
</dialog>
|
|
135
158
|
<button id="resume-run" type="button" class="primary" hidden>Resume run</button>
|
|
136
|
-
<dialog id="drawer" aria-labelledby="run-title"><form id="runner"><div id="run-header"></div><button id="minimize-run" type="button">Minimize</button><section id="run-plan" aria-label="Execution steps" hidden></section><label for="execution-provider" hidden>
|
|
159
|
+
<dialog id="drawer" aria-labelledby="run-title"><form id="runner"><div id="run-header"></div><button id="minimize-run" type="button">Minimize</button><section id="run-plan" aria-label="Execution steps" hidden></section><label for="execution-provider" hidden>Execution provider</label><select id="execution-provider" hidden></select><label for="model" hidden>Local OpenAI model</label><select id="model" hidden></select><details id="openai-setup" hidden><summary>Add OpenAI API key</summary>
|
|
137
160
|
<p>Save the key on this computer for Studio and Lyra SDK commands run from your VS Code terminal.</p>
|
|
138
161
|
<label for="openai-key">OpenAI API key</label>
|
|
139
162
|
<input id="openai-key" type="password" maxlength="503" autocomplete="off" spellcheck="false">
|
|
@@ -21,9 +21,24 @@ export function mountIntelligence(api, showView) {
|
|
|
21
21
|
if (!result.graphIssue) graphContent.append(node("p", "Build a graph to explore repository symbols and their connections."));
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
|
+
const report = node("section", "");
|
|
25
|
+
report.append(node("h2", "GraphSnip report"));
|
|
26
|
+
if (result.report) {
|
|
27
|
+
const updated = new Date(result.report.updatedAt).toLocaleString();
|
|
28
|
+
report.append(node("p", "Generated " + updated + (result.report.stale ? " · Graph has changed since this report." : "")));
|
|
29
|
+
const frame = document.createElement("iframe");
|
|
30
|
+
frame.title = "GraphSnip report";
|
|
31
|
+
frame.className = "graphsnip-report";
|
|
32
|
+
frame.setAttribute("sandbox", "");
|
|
33
|
+
frame.referrerPolicy = "no-referrer";
|
|
34
|
+
frame.src = "/api/graphsnip/report";
|
|
35
|
+
report.append(frame);
|
|
36
|
+
} else {
|
|
37
|
+
report.append(node("p", "Refresh the graph and report, or run agent-lyra graph report in the project terminal."));
|
|
38
|
+
}
|
|
24
39
|
const graph = result.graph;
|
|
25
40
|
graphContent.append(node("p", numbers.format(graph.nodeCount) + " nodes · " + numbers.format(graph.edgeCount) + " connections"));
|
|
26
|
-
if (!graph.nodes.length) return;
|
|
41
|
+
if (!graph.nodes.length) { graphContent.append(report); return; }
|
|
27
42
|
const details = node("p", "");
|
|
28
43
|
const related = document.createElement("ul");
|
|
29
44
|
const label = node("label", "Graph node");
|
|
@@ -43,12 +58,13 @@ export function mountIntelligence(api, showView) {
|
|
|
43
58
|
if (graph.nodes.length < graph.nodeCount || graph.links.length < graph.edgeCount) {
|
|
44
59
|
graphContent.append(node("p", "Showing up to 100 nodes and 300 connections. GraphSnip retains the full graph in the project."));
|
|
45
60
|
}
|
|
61
|
+
graphContent.append(report);
|
|
46
62
|
}
|
|
47
63
|
|
|
48
64
|
async function loadGraph(rebuild = false) {
|
|
49
65
|
const request = ++graphRequest;
|
|
50
66
|
build.disabled = true;
|
|
51
|
-
graphContent.replaceChildren(node("p", rebuild ? "Updating
|
|
67
|
+
graphContent.replaceChildren(node("p", rebuild ? "Updating graph and report…" : "Checking repository graph…"));
|
|
52
68
|
try {
|
|
53
69
|
const result = await api(rebuild ? "graphsnip/build" : "graphsnip/graph", rebuild ? {} : undefined);
|
|
54
70
|
if (request === graphRequest) renderGraph(result);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { callGrantedMcpTool } from "./mcp-connection.js";
|
|
2
|
+
|
|
3
|
+
try {
|
|
4
|
+
let input = "";
|
|
5
|
+
for await (const chunk of process.stdin.setEncoding("utf8")) input += chunk;
|
|
6
|
+
const { name, arguments: args } = JSON.parse(input);
|
|
7
|
+
const config = JSON.parse(process.env.LYRA_WORKBENCH_MCP_GRANT ?? "null");
|
|
8
|
+
process.stdout.write(JSON.stringify(await callGrantedMcpTool(config, name, args)));
|
|
9
|
+
} catch {
|
|
10
|
+
process.exitCode = 1;
|
|
11
|
+
}
|