agent-lyra 0.11.2 → 0.12.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 (39) hide show
  1. package/README.md +45 -35
  2. package/bin/agent-lyra.js +1 -1
  3. package/package.json +1 -1
  4. package/src/app-builder/init.js +3 -3
  5. package/src/framework/agent.js +19 -8
  6. package/src/framework/mda.js +5 -2
  7. package/src/framework/run.py +83 -11
  8. package/src/index.d.ts +1 -0
  9. package/src/index.js +1 -0
  10. package/src/init.js +1 -1
  11. package/src/intelligence/lifecycle.js +3 -2
  12. package/src/memory/LICENSE +1 -1
  13. package/src/memory/UPSTREAM.json +6 -3
  14. package/src/memory/external-engine.js +35 -0
  15. package/src/memory/index.js +19 -1
  16. package/src/memory/lifecycle.js +2 -1
  17. package/src/runtime/programmatic.d.ts +84 -0
  18. package/src/runtime/programmatic.js +155 -0
  19. package/src/runtime/run-agent.js +10 -2
  20. package/src/studio/browser.js +125 -19
  21. package/src/studio/export.js +7 -4
  22. package/src/studio/graphsnip-workbench.js +77 -0
  23. package/src/studio/history-panel.js +155 -0
  24. package/src/studio/ide-provider.js +65 -0
  25. package/src/studio/index.html +61 -9
  26. package/src/studio/intelligence.js +94 -0
  27. package/src/studio/local-provider.js +43 -0
  28. package/src/studio/memory-actions.js +28 -1
  29. package/src/studio/memory-panel.js +29 -5
  30. package/src/studio/mission-ui.css +52 -0
  31. package/src/studio/mission-ui.js +57 -0
  32. package/src/studio/programmatic-runner.mjs +21 -0
  33. package/src/studio/programmatic.js +58 -0
  34. package/src/studio/project.js +102 -24
  35. package/src/studio/python-agent.py +28 -4
  36. package/src/studio/run-history.js +119 -0
  37. package/src/studio/server.js +77 -8
  38. package/src/studio/session.js +1 -1
  39. package/src/studio/studio.css +76 -0
@@ -0,0 +1,155 @@
1
+ import { formatMissionDuration, missionStatusLabel, renderMissionStatus, renderMissionTimeline } from "./mission-ui.js";
2
+
3
+ const runIdPattern = /^[a-f0-9-]{36}$/i;
4
+
5
+ function element(tag, text, className) {
6
+ const node = document.createElement(tag);
7
+ if (text !== undefined) node.textContent = text;
8
+ if (className) node.className = className;
9
+ return node;
10
+ }
11
+
12
+ function link(text, href) {
13
+ const node = element("a", text);
14
+ node.href = href;
15
+ return node;
16
+ }
17
+
18
+ const date = new Intl.DateTimeFormat(undefined, { dateStyle: "medium", timeStyle: "medium" });
19
+ const historyHash = id => "#run=" + id;
20
+
21
+ function timeline(h, events) {
22
+ return renderMissionTimeline(h, events.map(event => {
23
+ const [scope, status] = event.type.split(".");
24
+ const title = scope === "step" ? "Step " + event.index : scope[0].toUpperCase() + scope.slice(1);
25
+ const description = [event.activityId,
26
+ Number.isSafeInteger(event.bytes) ? event.bytes + " context bytes" : undefined,
27
+ Number.isSafeInteger(event.tokenBudget) ? event.tokenBudget + " token budget" : undefined, Number.isSafeInteger(event.count) ? event.count + " matched" : undefined,
28
+ scope !== "step" && event.index ? "Step " + event.index : undefined, event.agentId, event.source, event.provider, event.model,
29
+ Number.isFinite(event.usage?.inputTokens) ? event.usage.inputTokens + " input tokens" : undefined,
30
+ Number.isFinite(event.usage?.outputTokens) ? event.usage.outputTokens + " output tokens" : undefined,
31
+ ].filter(Boolean).join(" · ");
32
+ return {
33
+ id: event.sequence, title, status, statusLabel: missionStatusLabel(status), description,
34
+ duration: Number.isFinite(event.durationMs) ? formatMissionDuration(event.durationMs, { showMilliseconds: true }) : undefined,
35
+ timestamp: event.timestamp, timestampLabel: date.format(new Date(event.timestamp)),
36
+ reference: event.runtimeRunId ? "Runtime run " + event.runtimeRunId : undefined,
37
+ };
38
+ }));
39
+ }
40
+
41
+ const detailSections = [
42
+ { id: "steps", title: "Steps", matches: event => /^(run|step)\./.test(event.type), empty: "No steps recorded for this run." },
43
+ { id: "activity", title: "Activity", matches: event => /^(tool|model|skill|memory|context)\./.test(event.type), empty: "No model, tool, skill, or memory activity was recorded." },
44
+ { id: "tokens", title: "Tokens", matches: event => event.type === "step.completed" &&
45
+ [event.usage?.inputTokens, event.usage?.outputTokens].some(Number.isSafeInteger), empty: "The provider did not report token usage for this run." },
46
+ { id: "evaluations", title: "Evaluations", matches: event => event.type.startsWith("evaluation."), empty: "No evaluations were recorded for this run." },
47
+ ];
48
+
49
+ function renderDetailSections(h, report, selected, choose) {
50
+ const controls = element("nav", undefined, "history-detail-tabs");
51
+ controls.setAttribute("aria-label", "Run details");
52
+ const content = element("div");
53
+ const buttons = detailSections.map(section => {
54
+ const button = element("button", section.title);
55
+ button.type = "button";
56
+ button.onclick = () => {
57
+ choose(section.id);
58
+ render(section.id);
59
+ };
60
+ return button;
61
+ });
62
+ function render(id) {
63
+ const section = detailSections.find(item => item.id === id);
64
+ for (const [index, button] of buttons.entries()) {
65
+ button.setAttribute("aria-pressed", String(detailSections[index] === section));
66
+ }
67
+ const events = report.events.filter(section.matches);
68
+ content.replaceChildren(events.length
69
+ ? timeline(h, events)
70
+ : element("p", section.empty, "lyra-mission-empty"));
71
+ }
72
+ controls.append(...buttons);
73
+ render(selected);
74
+ return [controls, content];
75
+ }
76
+
77
+ export function mountHistoryPanel(api, showMissionControl, h, openMemory) {
78
+ const panel = document.querySelector("#history-panel");
79
+ const list = panel.querySelector("#history-list");
80
+ const detail = panel.querySelector("#history-detail");
81
+ const status = panel.querySelector("#history-status");
82
+ const open = document.querySelector("#open-history");
83
+ let selection;
84
+ let section = "steps";
85
+ let request = 0;
86
+
87
+ async function refresh(id) {
88
+ const current = ++request;
89
+ if (selection !== id) section = "steps";
90
+ selection = id;
91
+ status.textContent = "Loading run history…";
92
+ try {
93
+ const [history, report] = await Promise.all([api("history"), id ? api("history/" + id) : undefined]);
94
+ if (current !== request) return;
95
+ list.replaceChildren();
96
+ detail.replaceChildren();
97
+ for (const run of history.runs) {
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."));
106
+ if (report) {
107
+ detail.append(element("h3", missionStatusLabel(report.run.status)),
108
+ element("code", report.run.id),
109
+ link("Download JSON report", "/api/history/" + report.run.id + "/report"),
110
+ report.run.status === "completed" ? h("button", {
111
+ type: "button", onClick: () => openMemory(report.run.id),
112
+ }, "Record learning") : element("span"),
113
+ ...renderDetailSections(h, report, section, id => { section = id; }));
114
+ if (report.run.status === "completed") {
115
+ const { suggestions } = await api("memory/suggestions", { runId: report.run.id }).catch(() => ({ suggestions: [] }));
116
+ if (current !== request) return;
117
+ if (suggestions.length) {
118
+ const box = element("section", undefined, "learning-suggestions");
119
+ box.append(element("h3", "Suggested learnings"));
120
+ for (const suggestion of suggestions) {
121
+ box.append(h("button", { type: "button", onClick: () => openMemory(report.run.id, suggestion) },
122
+ "Review " + suggestion.title));
123
+ }
124
+ detail.insertBefore(box, detail.querySelector(".history-detail-tabs"));
125
+ }
126
+ }
127
+ } else if (history.runs.length) {
128
+ detail.append(element("p", "Select a run to see its timeline and download a report."));
129
+ }
130
+ status.textContent = "";
131
+ } catch (error) {
132
+ if (current !== request) return;
133
+ detail.replaceChildren();
134
+ status.textContent = error.message;
135
+ }
136
+ }
137
+
138
+ function syncLocation() {
139
+ if (open.hidden) return;
140
+ const id = location.hash.startsWith("#run=") ? location.hash.slice(5) : "";
141
+ if (runIdPattern.test(id)) {
142
+ showMissionControl();
143
+ return refresh(id);
144
+ }
145
+ if (!panel.hidden) return refresh();
146
+ }
147
+
148
+ open.onclick = () => {
149
+ showMissionControl();
150
+ void syncLocation();
151
+ };
152
+ panel.querySelector("#refresh-history").onclick = () => void refresh(selection);
153
+ window.addEventListener("hashchange", syncLocation);
154
+ return syncLocation;
155
+ }
@@ -0,0 +1,65 @@
1
+ import { randomUUID } from "node:crypto";
2
+
3
+ export function ideModel() {
4
+ if (!process.connected || typeof process.send !== "function") return undefined;
5
+ try {
6
+ const model = JSON.parse(process.env.LYRA_IDE_MODEL ?? "null");
7
+ if (typeof model?.id === "string" && model.id && typeof model.name === "string" && model.name) return model;
8
+ } catch {
9
+ // The IDE provider is available only in a valid extension session.
10
+ }
11
+ return undefined;
12
+ }
13
+
14
+ export function completeIde(request, { signal, onDelta, onActivity } = {}) {
15
+ signal?.throwIfAborted();
16
+ const model = ideModel();
17
+ if (!model || request.model !== model.id) throw new Error("Choose an active VS Code model.");
18
+ const prompt = request.messages.map(({ role, content }) => role + ":\n" + content).join("\n\n");
19
+ return new Promise((resolve, reject) => {
20
+ const id = randomUUID();
21
+ const cleanup = () => {
22
+ clearTimeout(timer);
23
+ signal?.removeEventListener("abort", cancel);
24
+ process.off("message", receive);
25
+ process.off("disconnect", disconnect);
26
+ };
27
+ const receive = message => {
28
+ if (message?.id !== id) return;
29
+ if (message.type === "lyra.ide.delta" && typeof message.text === "string") {
30
+ onDelta?.(message.text);
31
+ return;
32
+ }
33
+ if (message.type === "lyra.ide.activity") {
34
+ try { onActivity?.(message.event); } catch {}
35
+ return;
36
+ }
37
+ if (message.type !== "lyra.ide.result") return;
38
+ cleanup();
39
+ if (typeof message.text === "string" && message.text.trim()) resolve({ text: message.text });
40
+ else reject(new Error("VS Code did not return model output. Check model access in the editor."));
41
+ };
42
+ const disconnect = () => {
43
+ cleanup();
44
+ reject(new Error("The VS Code session disconnected."));
45
+ };
46
+ const cancel = () => {
47
+ cleanup();
48
+ if (process.connected) process.send({ type: "lyra.ide.cancel", id }, () => {});
49
+ reject(signal.reason);
50
+ };
51
+ const timer = setTimeout(() => {
52
+ cleanup();
53
+ if (process.connected) process.send({ type: "lyra.ide.cancel", id }, () => {});
54
+ reject(new Error("The VS Code model request timed out."));
55
+ }, 60_000);
56
+ signal?.addEventListener("abort", cancel, { once: true });
57
+ process.on("message", receive);
58
+ process.once("disconnect", disconnect);
59
+ process.send({ type: "lyra.ide.request", id, prompt }, error => {
60
+ if (!error) return;
61
+ cleanup();
62
+ reject(new Error("Could not reach the VS Code model session."));
63
+ });
64
+ });
65
+ }
@@ -2,15 +2,34 @@
2
2
  <html lang="en">
3
3
  <head>
4
4
  <meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
5
- <title>AgentLyra Studio</title><link rel="stylesheet" href="/studio.css"><link rel="stylesheet" href="/agent-ui.css"><script src="/studio.js" type="module"></script>
5
+ <title>AgentLyra Workbench</title><link rel="stylesheet" href="/studio.css"><link rel="stylesheet" href="/agent-ui.css"><link rel="stylesheet" href="/mission-ui.css"><script src="/studio.js" type="module"></script>
6
6
  </head>
7
7
  <body>
8
8
  <header class="studio-header">
9
- <div class="studio-brand"><img class="studio-mark" src="/lyra-icon.png" width="34" height="34" alt=""><div><strong>AgentLyra Studio</strong><span id="project-name"></span></div></div>
10
- <nav id="studio-views" aria-label="Studio views">
11
- <button id="show-layout" type="button" aria-pressed="true">Layout</button>
12
- <button id="show-workflow" type="button" aria-pressed="false">Workflow</button>
13
- </nav><div class="toolbar"><span id="cloud-state" class="pill"></span><button id="open-memory" type="button" hidden>Memory</button> <button id="refresh">Reload agents</button> <button id="connect-cloud" type="button" hidden>Connect to Cloud</button> <button id="pull" type="button" hidden>Pull from Cloud</button> <button class="primary" id="save">Save layout</button></div></header>
9
+ <div class="studio-brand"><img class="studio-mark" src="/lyra-icon.png" width="34" height="34" alt=""><div><strong>AgentLyra Workbench</strong><span id="project-name"></span></div></div>
10
+ <div class="toolbar"><span id="cloud-state" class="pill"></span><button class="primary" id="save">Save layout</button></div>
11
+ <nav id="studio-views" aria-label="Workbench views">
12
+ <div role="group" aria-labelledby="nav-observability">
13
+ <span id="nav-observability">Observability</span>
14
+ <button id="open-history" type="button" aria-pressed="false">Mission Control</button>
15
+ </div>
16
+ <div role="group" aria-labelledby="nav-development">
17
+ <span id="nav-development">Development</span>
18
+ <button id="show-registry" type="button" aria-pressed="false">Agent Registry</button>
19
+ <button id="show-layout" type="button" aria-pressed="true">Layout</button>
20
+ <button id="show-workflow" type="button" aria-pressed="false">Workflow</button>
21
+ </div>
22
+ <div role="group" aria-labelledby="nav-intelligence">
23
+ <span id="nav-intelligence">Intelligence</span>
24
+ <button id="show-graph" type="button" aria-pressed="false">Knowledge Graph</button>
25
+ <button id="show-tokens" type="button" aria-pressed="false">Token Intelligence</button>
26
+ <button id="open-memory" type="button" hidden>Memory &amp; Learnings</button>
27
+ </div>
28
+ <div role="group" aria-labelledby="nav-configuration">
29
+ <span id="nav-configuration">Configuration</span>
30
+ <button id="show-cloud" type="button" aria-pressed="false">Cloud Sync</button>
31
+ </div>
32
+ </nav></header>
14
33
  <p role="status" id="status"></p>
15
34
  <dialog id="cloud-setup" aria-labelledby="cloud-title">
16
35
  <header><h2 id="cloud-title">Connect to AgentLyra Cloud</h2><button id="close-cloud" type="button">Close</button></header>
@@ -23,8 +42,40 @@
23
42
  <p id="cloud-error" role="status"></p>
24
43
  </form></dialog>
25
44
  <main>
45
+ <section id="history-panel" aria-labelledby="history-title" hidden>
46
+ <div class="history-heading"><div><h1 id="history-title">Mission Control</h1><p>Local run history for this project.</p></div>
47
+ <button id="refresh-history" type="button">Refresh runs</button></div>
48
+ <p id="history-status" role="status"></p>
49
+ <div class="history-content">
50
+ <nav id="history-list" aria-label="Recent runs"></nav>
51
+ <section id="history-detail" aria-label="Selected run"></section>
52
+ </div>
53
+ </section>
54
+ <section id="graph-panel" class="intelligence-panel" aria-labelledby="graph-title" hidden>
55
+ <div class="history-heading"><h1 id="graph-title">Knowledge Graph</h1>
56
+ <button id="build-graph" type="button" disabled>Build or update graph</button></div>
57
+ <div id="graph-content" aria-live="polite"></div>
58
+ </section>
59
+ <section id="token-panel" class="intelligence-panel" aria-labelledby="token-title" hidden>
60
+ <div class="history-heading"><h1 id="token-title">Token Intelligence</h1>
61
+ <button id="refresh-tokens" type="button">Refresh ledger</button></div>
62
+ <p>GraphSnip estimates context tokens against its baseline. Provider-reported usage is shown per run in Mission Control.</p>
63
+ <div id="token-content" aria-live="polite"></div>
64
+ </section>
65
+ <section id="cloud-settings" aria-labelledby="cloud-settings-title" hidden>
66
+ <h1 id="cloud-settings-title">Cloud Sync</h1>
67
+ <p id="cloud-settings-description"></p>
68
+ <div class="actions">
69
+ <button id="connect-cloud" type="button" class="primary" hidden>Connect to Cloud</button>
70
+ <button id="pull" type="button" class="primary" hidden>Pull from Cloud</button>
71
+ <button id="pause-cloud" type="button" hidden>Work locally</button>
72
+ </div>
73
+ </section>
26
74
  <aside id="library" aria-labelledby="library-title">
27
- <h2 id="library-title">Project library</h2>
75
+ <div class="history-heading">
76
+ <h2 id="library-title">Project library</h2>
77
+ <button id="refresh" type="button" hidden>Reload agents</button>
78
+ </div>
28
79
  <nav id="library-tabs" aria-label="Library categories">
29
80
  <button type="button" data-library="palette" aria-pressed="true">Components</button>
30
81
  <button type="button" data-library="agents" aria-pressed="false">Agents</button>
@@ -60,9 +111,10 @@
60
111
  <aside id="inspector-panel" aria-labelledby="inspector-title" hidden><div class="inspector-heading"><h2 id="inspector-title">Inspector</h2><button id="close-inspector" type="button">Close</button></div><div id="inspector"></div></aside>
61
112
  </main>
62
113
  <dialog id="memory-panel" aria-labelledby="memory-title">
63
- <header><h2 id="memory-title">Memory</h2><button id="close-memory" type="button">Close</button></header>
114
+ <header><h2 id="memory-title">Memory &amp; Learnings</h2><button id="close-memory" type="button">Close</button></header>
64
115
  <p>Project memories stay local until you choose to upload a verified record.</p>
65
116
  <p id="memory-status" role="status"></p>
117
+ <p id="memory-engine"></p>
66
118
  <p id="memory-summary"></p>
67
119
  <form id="memory-search"><label for="memory-query">Search project memories</label><input id="memory-query" maxlength="240"><button type="submit">Search</button></form>
68
120
  <details><summary>Record a candidate</summary><form id="memory-create">
@@ -86,5 +138,5 @@
86
138
  <label for="openai-key">OpenAI API key</label>
87
139
  <input id="openai-key" type="password" maxlength="503" autocomplete="off" spellcheck="false">
88
140
  <button id="save-openai" type="button">Save key</button><p id="openai-status" role="status"></p>
89
- </details><label id="run-input-label" for="prompt">Input</label><textarea id="prompt" maxlength="4000" rows="6" required></textarea><button class="primary" id="run">Run</button><p role="status" id="run-status"></p><pre id="run-result"></pre></form></dialog>
141
+ </details><label id="run-input-label" for="prompt">Input</label><textarea id="prompt" maxlength="4000" rows="6" required></textarea><button class="primary" id="run">Run</button><button id="cancel-run" type="button" hidden>Cancel run</button><p role="status" id="run-status"></p><pre id="run-result"></pre></form></dialog>
90
142
  </body></html>
@@ -0,0 +1,94 @@
1
+ function node(tag, text) {
2
+ const element = document.createElement(tag);
3
+ element.textContent = text;
4
+ return element;
5
+ }
6
+
7
+ const numbers = new Intl.NumberFormat();
8
+
9
+ export function mountIntelligence(api, showView) {
10
+ const graphContent = document.querySelector("#graph-content");
11
+ const tokenContent = document.querySelector("#token-content");
12
+ const build = document.querySelector("#build-graph");
13
+ let graphRequest = 0;
14
+ let tokenRequest = 0;
15
+
16
+ function renderGraph(result) {
17
+ graphContent.replaceChildren();
18
+ build.disabled = !result.installed;
19
+ if (result.issue || result.graphIssue) graphContent.append(node("p", result.issue ?? result.graphIssue));
20
+ if (!result.graph) {
21
+ if (!result.graphIssue) graphContent.append(node("p", "Build a graph to explore repository symbols and their connections."));
22
+ return;
23
+ }
24
+ const graph = result.graph;
25
+ graphContent.append(node("p", numbers.format(graph.nodeCount) + " nodes · " + numbers.format(graph.edgeCount) + " connections"));
26
+ if (!graph.nodes.length) return;
27
+ const details = node("p", "");
28
+ const related = document.createElement("ul");
29
+ const label = node("label", "Graph node");
30
+ const picker = document.createElement("select");
31
+ picker.replaceChildren(...graph.nodes.map(entry => new Option(entry.label, entry.id)));
32
+ label.append(picker);
33
+ graphContent.append(label, details, related);
34
+ const update = () => {
35
+ const id = picker.value;
36
+ const byId = new Map(graph.nodes.map(entry => [entry.id, entry.label]));
37
+ const neighbors = new Set(graph.links.flatMap(edge => edge.source === id ? [edge.target] : edge.target === id ? [edge.source] : []));
38
+ details.textContent = neighbors.size ? "Connections in this view" : "No connections in this view.";
39
+ related.replaceChildren(...[...neighbors].map(neighbor => node("li", byId.get(neighbor) ?? neighbor)));
40
+ };
41
+ picker.onchange = update;
42
+ update();
43
+ if (graph.nodes.length < graph.nodeCount || graph.links.length < graph.edgeCount) {
44
+ graphContent.append(node("p", "Showing up to 100 nodes and 300 connections. GraphSnip retains the full graph in the project."));
45
+ }
46
+ }
47
+
48
+ async function loadGraph(rebuild = false) {
49
+ const request = ++graphRequest;
50
+ build.disabled = true;
51
+ graphContent.replaceChildren(node("p", rebuild ? "Updating repository graph…" : "Checking repository graph…"));
52
+ try {
53
+ const result = await api(rebuild ? "graphsnip/build" : "graphsnip/graph", rebuild ? {} : undefined);
54
+ if (request === graphRequest) renderGraph(result);
55
+ } catch (error) {
56
+ if (request !== graphRequest) return;
57
+ graphContent.replaceChildren(node("p", error.message));
58
+ build.disabled = false;
59
+ }
60
+ }
61
+
62
+ function ledgerSection(title, stats) {
63
+ const section = node("section", "");
64
+ section.append(node("h2", title));
65
+ if (!stats?.calls) {
66
+ section.append(node("p", "No GraphSnip calls recorded."));
67
+ return section;
68
+ }
69
+ for (const [key, label] of [["calls", "Calls"], ["baseline", "Baseline estimated tokens"],
70
+ ["returned", "Returned estimated tokens"], ["saved", "Estimated tokens saved"]]) {
71
+ if (Number.isFinite(stats[key])) section.append(node("p", label + " · " + numbers.format(stats[key])));
72
+ }
73
+ return section;
74
+ }
75
+
76
+ async function loadTokens() {
77
+ const request = ++tokenRequest;
78
+ tokenContent.replaceChildren(node("p", "Reading GraphSnip ledger…"));
79
+ try {
80
+ const result = await api("graphsnip/tokens");
81
+ if (request !== tokenRequest) return;
82
+ tokenContent.replaceChildren();
83
+ if (result.issue) tokenContent.append(node("p", result.issue));
84
+ else tokenContent.append(ledgerSection("Project activity", result.live), ledgerSection("Benchmark activity", result.benchmark));
85
+ } catch (error) {
86
+ if (request === tokenRequest) tokenContent.replaceChildren(node("p", error.message));
87
+ }
88
+ }
89
+
90
+ document.querySelector("#show-graph").onclick = () => { showView("graph"); void loadGraph(); };
91
+ document.querySelector("#show-tokens").onclick = () => { showView("tokens"); void loadTokens(); };
92
+ build.onclick = () => void loadGraph(true);
93
+ document.querySelector("#refresh-tokens").onclick = () => void loadTokens();
94
+ }
@@ -0,0 +1,43 @@
1
+ export function localModelConfiguration(env = process.env) {
2
+ const address = env.LYRA_LOCAL_MODEL_URL?.trim();
3
+ if (!address) return undefined;
4
+ let url;
5
+ try { url = new URL(address); } catch {}
6
+ if (!url || !["http:", "https:"].includes(url.protocol) ||
7
+ !["127.0.0.1", "[::1]"].includes(url.hostname) || url.username || url.password ||
8
+ url.search || url.hash || !["/v1", "/v1/"].includes(url.pathname)) {
9
+ return { issue: "Set LYRA_LOCAL_MODEL_URL to a loopback OpenAI-compatible base URL ending in /v1." };
10
+ }
11
+ const models = [...new Set((env.LYRA_LOCAL_MODELS ?? "").split(",").map(value => value.trim())
12
+ .filter(value => /^[\w./:-]{1,120}$/.test(value)))];
13
+ return {
14
+ endpoint: new URL("chat/completions", url.origin + "/v1/").href,
15
+ models,
16
+ issue: models.length ? undefined : "Set LYRA_LOCAL_MODELS to the installed local model IDs.",
17
+ };
18
+ }
19
+
20
+ export function createLocalModelProvider(configuration, request = fetch) {
21
+ return {
22
+ async complete(payload, { signal } = {}) {
23
+ if (!configuration?.models?.includes(payload.model)) throw new Error("Choose a configured local model.");
24
+ const deadline = AbortSignal.timeout(60_000);
25
+ const response = await request(configuration.endpoint, {
26
+ method: "POST",
27
+ headers: { "Content-Type": "application/json" },
28
+ redirect: "error",
29
+ signal: signal ? AbortSignal.any([signal, deadline]) : deadline,
30
+ body: JSON.stringify({ ...payload, max_tokens: 1024, stream: false }),
31
+ });
32
+ if (!response.ok) throw new Error("Local model request failed (HTTP " + response.status + ").");
33
+ const result = await response.json();
34
+ const text = result.choices?.[0]?.message?.content;
35
+ if (typeof text !== "string" || !text.trim()) throw new Error("The local model returned no text.");
36
+ const { prompt_tokens: inputTokens, completion_tokens: outputTokens } = result.usage ?? {};
37
+ const usage = {};
38
+ if (Number.isSafeInteger(inputTokens) && inputTokens >= 0) usage.inputTokens = inputTokens;
39
+ if (Number.isSafeInteger(outputTokens) && outputTokens >= 0) usage.outputTokens = outputTokens;
40
+ return Object.keys(usage).length ? { text, usage } : { text };
41
+ },
42
+ };
43
+ }
@@ -1,14 +1,41 @@
1
1
  import { openMemoryStore } from "../memory/index.js";
2
+ import { eligibleText } from "../memory/validation.js";
3
+ import { openRunHistory } from "./run-history.js";
2
4
  import { syncMemory } from "../memory/sync.js";
3
5
 
4
6
  export function memoryActions(root) {
5
7
  return new Map([
6
8
  ["/api/memory/list", ({ query = "" }) => useStore(root, store => ({
7
- records: query.trim() ? store.search(query, 50) : store.list(50), stats: store.stats(),
9
+ records: query.trim() ? store.search(query, 50) : store.list(50), stats: store.stats(), engine: store.engine,
8
10
  }))],
9
11
  ["/api/memory/record", body => useStore(root, store => store.record({
10
12
  ...body, evidence: typeof body.evidence === "string" ? body.evidence.split(",").map(value => value.trim()).filter(Boolean) : body.evidence,
11
13
  }))],
14
+ ["/api/memory/suggestions", async ({ runId }) => {
15
+ if (process.env.LYRA_MEMORY === "off" || typeof runId !== "string" || !/^[a-f0-9-]{36}$/i.test(runId)) return { suggestions: [] };
16
+ const history = await openRunHistory(root);
17
+ try { return { suggestions: history.suggestions(runId) }; }
18
+ finally { history.close(); }
19
+ }],
20
+ ["/api/memory/record-run", async ({ runId, type, title, learning, evidence }) => {
21
+ if (!/^[a-f0-9-]{36}$/i.test(runId ?? "")) throw new Error("Choose a completed local run.");
22
+ if (!["corrective", "episodic", "semantic", "procedural"].includes(type)) {
23
+ throw new Error("Choose a supported memory type.");
24
+ }
25
+ if (typeof title !== "string" || typeof learning !== "string" || !eligibleText(title + " " + learning)) {
26
+ throw new Error("Use reviewed learning text without credentials or instruction overrides.");
27
+ }
28
+ const extra = typeof evidence === "string" ? evidence.split(",").map(value => value.trim()).filter(Boolean) : [];
29
+ const history = await openRunHistory(root);
30
+ try {
31
+ return await useStore(root, store => history.withCompletedRun(runId, () => {
32
+ const value = { type, title: title.trim(), learning: learning.trim() };
33
+ const existing = store.findLearning(value);
34
+ if (existing) return { ...existing, reused: true };
35
+ return store.record({ ...value, evidence: [...new Set(["run:" + runId, ...extra])] });
36
+ }));
37
+ } finally { history.close(); }
38
+ }],
12
39
  ["/api/memory/archive", ({ id }) => useStore(root, store => {
13
40
  const record = store.archive(id);
14
41
  if (!record) throw new Error("Memory record was not found.");
@@ -6,6 +6,7 @@ export function mountMemoryPanel(api) {
6
6
  const status = byId("memory-status");
7
7
  const query = byId("memory-query");
8
8
  let busy = false;
9
+ let sourceRun;
9
10
 
10
11
  function element(tag, text) {
11
12
  const node = document.createElement(tag);
@@ -31,7 +32,10 @@ export function mountMemoryPanel(api) {
31
32
  }
32
33
 
33
34
  async function reload() {
34
- const { records, stats } = await api("memory/list", { query: query.value });
35
+ const { records, stats, engine } = await api("memory/list", { query: query.value });
36
+ byId("memory-engine").textContent = engine?.source === "independent"
37
+ ? "Independent Memory Engine " + engine.version
38
+ : "Bundled Memory Engine" + (engine?.version ? " " + engine.version : "");
35
39
  byId("memory-summary").textContent = stats.candidate + " candidates · " + stats.verified + " verified · " + stats.archived + " archived";
36
40
  await loadProposals();
37
41
  lists.replaceChildren();
@@ -138,10 +142,24 @@ export function mountMemoryPanel(api) {
138
142
  }));
139
143
  }
140
144
 
141
- byId("open-memory").onclick = () => {
145
+ function open(runId, suggestion) {
146
+ sourceRun = runId;
147
+ const form = byId("memory-create");
148
+ form.reset();
149
+
150
+ if (runId) {
151
+ form.elements.evidence.value = "run:" + runId;
152
+ if (suggestion) {
153
+ form.elements.type.value = suggestion.type;
154
+ form.elements.title.value = suggestion.title;
155
+ form.elements.learning.value = suggestion.learning;
156
+ }
157
+ form.closest("details").open = true;
158
+ }
142
159
  panel.showModal();
143
160
  return run(null, reload);
144
- };
161
+ }
162
+ byId("open-memory").onclick = () => open();
145
163
  byId("close-memory").onclick = () => panel.close();
146
164
  byId("memory-search").onsubmit = event => {
147
165
  event.preventDefault();
@@ -151,11 +169,16 @@ export function mountMemoryPanel(api) {
151
169
  event.preventDefault();
152
170
  const form = event.currentTarget;
153
171
  return run(event.submitter, async () => {
154
- await api("memory/record", Object.fromEntries(new FormData(form)));
172
+ const body = Object.fromEntries(new FormData(form));
173
+ const result = sourceRun
174
+ ? await api("memory/record-run", { ...body, runId: sourceRun })
175
+ : await api("memory/record", body);
176
+ sourceRun = undefined;
177
+
155
178
  form.reset();
156
179
  query.value = "";
157
180
  await reload();
158
- return "Recorded a candidate.";
181
+ return result.reused ? "This learning already exists in this project." : "Recorded a candidate.";
159
182
  });
160
183
  };
161
184
  function compareCopies(id, copies) {
@@ -197,4 +220,5 @@ export function mountMemoryPanel(api) {
197
220
  return result.deleted ? "Applied Cloud deletion." : result.updated ? "Pulled a candidate for local review." : "Already up to date.";
198
221
  });
199
222
  };
223
+ return open;
200
224
  }
@@ -0,0 +1,52 @@
1
+ .lyra-mission-status {
2
+ --mission-dot: var(--lyra-color-text-muted, var(--studio-muted, #52675e));
3
+ --mission-tint: var(--lyra-color-surface-2, #f1f5f2);
4
+ display: inline-flex;
5
+ align-items: center;
6
+ gap: .35rem;
7
+ width: fit-content;
8
+ padding: .16rem .48rem;
9
+ border: 1px solid var(--lyra-color-border, var(--studio-line, #dce6df));
10
+ border-radius: 999px;
11
+ background: var(--mission-tint);
12
+ color: var(--mission-dot);
13
+ font-size: .75rem;
14
+ font-weight: 600;
15
+ }
16
+ .lyra-mission-status[data-state="running"] {
17
+ --mission-dot: var(--lyra-color-primary, #286b51);
18
+ --mission-tint: var(--app-primary-soft, #eef5ef);
19
+ }
20
+ .lyra-mission-status[data-state="completed"] {
21
+ --mission-dot: var(--lyra-color-success, #226142);
22
+ --mission-tint: var(--lyra-color-success-bg, #eaf5ee);
23
+ }
24
+ .lyra-mission-status[data-state="failed"] {
25
+ --mission-dot: var(--lyra-color-danger, #a22730);
26
+ --mission-tint: var(--lyra-color-danger-bg, #fbeff0);
27
+ }
28
+ .lyra-mission-status-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
29
+ .lyra-mission-timeline { margin: .65rem 0 0; padding: 0; list-style: none; }
30
+ .lyra-mission-timeline-row {
31
+ display: grid;
32
+ grid-template-columns: auto minmax(0, 1fr);
33
+ align-items: start;
34
+ gap: .65rem;
35
+ padding: .65rem 0;
36
+ border-top: 1px solid var(--lyra-color-border, var(--studio-line, #dce6df));
37
+ }
38
+ .lyra-mission-timeline-marker { width: 8px; height: 8px; margin-top: .4rem; border-radius: 50%; background: var(--lyra-color-primary, #286b51); }
39
+ .lyra-mission-timeline-body { min-width: 0; overflow-wrap: anywhere; }
40
+ .lyra-mission-timeline-title { font-size: .85rem; }
41
+ .lyra-mission-timeline-description { margin: .18rem 0; font-size: .8rem; }
42
+ .lyra-mission-timeline-meta {
43
+ display: flex;
44
+ align-items: center;
45
+ flex-wrap: wrap;
46
+ gap: .3rem .55rem;
47
+ margin-top: .25rem;
48
+ color: var(--lyra-color-text-muted, var(--studio-muted, #52675e));
49
+ font-size: .75rem;
50
+ }
51
+ .lyra-mission-timeline-reference { display: block; margin-top: .2rem; font-size: .74rem; }
52
+ .lyra-mission-empty { padding: 1rem 0; text-align: center; color: var(--lyra-color-text-muted, var(--studio-muted, #52675e)); }