@hexdecimal16/nexo 0.4.6 → 0.4.8
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/cli/src/areas.js +49 -0
- package/cli/src/common.js +2 -1
- package/cli/src/history.js +32 -0
- package/cli/src/interactive.js +6 -1
- package/cli/src/main.js +7 -0
- package/cli/src/optimize.js +2 -5
- package/core/src/config/schema.js +1 -0
- package/core/src/engine/charged-completion.js +9 -4
- package/core/src/engine/errors.js +29 -2
- package/core/src/engine/messages.js +3 -3
- package/core/src/engine/prompts.js +1 -1
- package/core/src/engine/run.js +9 -4
- package/core/src/index.js +3 -0
- package/core/src/learn/areas.js +179 -0
- package/core/src/learn/job.js +13 -0
- package/core/src/learn/wiki.js +15 -10
- package/core/src/optimize/climb.js +0 -2
- package/core/src/optimize/optimize.js +1 -4
- package/core/src/session/mentions.js +95 -0
- package/core/src/session/prompt-history.js +13 -0
- package/core/src/session/session.js +2 -1
- package/optimize/src/engine.js +1 -22
- package/optimize/src/index.js +0 -1
- package/optimize/src/report.js +0 -2
- package/package.json +1 -1
- package/sdk/src/nexo.js +5 -1
- package/skills/bundled/wiki/SKILL.md +21 -11
- package/store/src/eval-cases.js +12 -6
- package/store/src/index.js +1 -0
- package/store/src/paths.js +1 -0
- package/store/src/prompt-history.js +64 -0
- package/tools/src/index.js +1 -0
- package/tools/src/wiki-page.js +78 -0
- package/tui/src/app.js +42 -5
- package/tui/src/file-autocomplete.js +166 -0
- package/tui/src/questions.js +31 -0
- package/web/public/area.html +23 -0
- package/web/public/cost.html +1 -1
- package/web/public/home.html +23 -0
- package/web/public/index.html +1 -1
- package/web/public/judge.html +1 -1
- package/web/public/learning.html +1 -1
- package/web/public/lib/api-types.ts +0 -2
- package/web/public/lib/optim-view.ts +1 -1
- package/web/public/lib/wikis-view.ts +3 -1
- package/web/public/optim.html +1 -1
- package/web/public/pages/area.ts +49 -0
- package/web/public/pages/home.ts +60 -0
- package/web/public/pages/wikis.ts +43 -6
- package/web/public/run.html +1 -1
- package/web/public/sessions.html +1 -1
- package/web/public/style.css +31 -0
- package/web/public/wikis.html +1 -1
- package/web/src/api.js +11 -6
- package/web/src/home-api.js +99 -0
- package/web/src/server.js +6 -0
- package/optimize/src/merge.js +0 -73
|
@@ -10,7 +10,7 @@ const pageBox = el<HTMLDivElement>("#wiki-page-container");
|
|
|
10
10
|
|
|
11
11
|
let currentWikis: string[] = [];
|
|
12
12
|
let activeWiki: string | null = null;
|
|
13
|
-
let activePath: string = "index
|
|
13
|
+
let activePath: string = "index";
|
|
14
14
|
|
|
15
15
|
function showError(error: unknown): void {
|
|
16
16
|
errorBox.innerHTML = renderError(asErrorBody(error)).value;
|
|
@@ -18,14 +18,13 @@ function showError(error: unknown): void {
|
|
|
18
18
|
|
|
19
19
|
function parseHash(): { wiki: string | null; pagePath: string } {
|
|
20
20
|
const hash = window.location.hash.replace(/^#\/?/, "");
|
|
21
|
-
if (!hash) return { wiki: null, pagePath: "index
|
|
21
|
+
if (!hash) return { wiki: null, pagePath: "index" };
|
|
22
22
|
const slash = hash.indexOf("/");
|
|
23
23
|
if (slash === -1) {
|
|
24
|
-
return { wiki: decodeURIComponent(hash), pagePath: "index
|
|
24
|
+
return { wiki: decodeURIComponent(hash), pagePath: "index" };
|
|
25
25
|
}
|
|
26
26
|
const wiki = decodeURIComponent(hash.slice(0, slash));
|
|
27
|
-
|
|
28
|
-
if (!page.endsWith(".md")) page += ".md";
|
|
27
|
+
const page = decodeURIComponent(hash.slice(slash + 1));
|
|
29
28
|
return { wiki, pagePath: page };
|
|
30
29
|
}
|
|
31
30
|
|
|
@@ -41,6 +40,7 @@ async function loadPage(wiki: string, path: string): Promise<void> {
|
|
|
41
40
|
]);
|
|
42
41
|
treeBox.innerHTML = renderWikiTree(pagesData.pages, wiki, path).value;
|
|
43
42
|
pageBox.innerHTML = renderWikiPage(pageData, wiki).value;
|
|
43
|
+
mountHtmlPage(pageData, wiki);
|
|
44
44
|
} catch (error) {
|
|
45
45
|
// If index.md doesn't exist, try loading the first available page
|
|
46
46
|
try {
|
|
@@ -51,6 +51,7 @@ async function loadPage(wiki: string, path: string): Promise<void> {
|
|
|
51
51
|
activePath = firstPage.path;
|
|
52
52
|
const pageData = await getJson<WikiPageResponse>(`/api/wikis/${encodeURIComponent(wiki)}/page?path=${encodeURIComponent(firstPage.path)}`);
|
|
53
53
|
pageBox.innerHTML = renderWikiPage(pageData, wiki).value;
|
|
54
|
+
mountHtmlPage(pageData, wiki);
|
|
54
55
|
} else {
|
|
55
56
|
pageBox.innerHTML = '<p class="muted">No pages found in this wiki.</p>';
|
|
56
57
|
}
|
|
@@ -60,7 +61,7 @@ async function loadPage(wiki: string, path: string): Promise<void> {
|
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
63
|
|
|
63
|
-
async function loadWiki(wiki: string, pagePath = "index
|
|
64
|
+
async function loadWiki(wiki: string, pagePath = "index"): Promise<void> {
|
|
64
65
|
activeWiki = wiki;
|
|
65
66
|
await loadPage(wiki, pagePath);
|
|
66
67
|
}
|
|
@@ -100,4 +101,40 @@ selectorBox.addEventListener("change", (event) => {
|
|
|
100
101
|
}
|
|
101
102
|
});
|
|
102
103
|
|
|
104
|
+
const DROP_TAGS = "script,style,iframe,object,embed,form,link,meta,base";
|
|
105
|
+
|
|
106
|
+
/** Renders an HTML wiki page inline: keeps the page body, removes active content, and rewrites relative links to viewer hashes. */
|
|
107
|
+
function mountHtmlPage(page: WikiPageResponse, wiki: string): void {
|
|
108
|
+
if (!page.path.endsWith(".html")) return;
|
|
109
|
+
const host = pageBox.querySelector<HTMLDivElement>("#wiki-html-body");
|
|
110
|
+
if (!host) return;
|
|
111
|
+
const doc = new DOMParser().parseFromString(page.content, "text/html");
|
|
112
|
+
const root = doc.querySelector("main") ?? doc.body;
|
|
113
|
+
root.querySelectorAll(DROP_TAGS).forEach((n) => n.remove());
|
|
114
|
+
root.querySelectorAll(":scope > nav, :scope > p.meta").forEach((n) => n.remove());
|
|
115
|
+
root.querySelectorAll("*").forEach((el) => {
|
|
116
|
+
for (const attr of Array.from(el.attributes)) {
|
|
117
|
+
const name = attr.name.toLowerCase();
|
|
118
|
+
if (name.startsWith("on") || name === "style") el.removeAttribute(attr.name);
|
|
119
|
+
else if ((name === "href" || name === "src" || name === "xlink:href") && /^\s*(javascript|data):/i.test(attr.value)) el.removeAttribute(attr.name);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
const base = page.path.includes("/") ? page.path.slice(0, page.path.lastIndexOf("/") + 1) : "";
|
|
123
|
+
root.querySelectorAll<HTMLAnchorElement>("a[href]").forEach((a) => {
|
|
124
|
+
const href = a.getAttribute("href") ?? "";
|
|
125
|
+
if (/^(https?:|mailto:)/i.test(href)) {
|
|
126
|
+
a.target = "_blank";
|
|
127
|
+
a.rel = "noopener noreferrer";
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (href.startsWith("#")) return;
|
|
131
|
+
const url = new URL(href, `https://wiki.invalid/${encodeURIComponent(wiki)}/${base}`);
|
|
132
|
+
const parts = url.pathname.split("/").filter(Boolean).map(decodeURIComponent);
|
|
133
|
+
const targetWiki = parts.shift() ?? wiki;
|
|
134
|
+
const slug = parts.join("/").replace(/\.(html|md)$/, "");
|
|
135
|
+
a.setAttribute("href", `#${encodeURIComponent(targetWiki)}/${slug.split("/").map(encodeURIComponent).join("/")}`);
|
|
136
|
+
});
|
|
137
|
+
host.replaceChildren(...Array.from(root.childNodes).map((n) => document.importNode(n, true)));
|
|
138
|
+
}
|
|
139
|
+
|
|
103
140
|
loadAll().catch(showError);
|
package/web/public/run.html
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
</head>
|
|
13
13
|
<body>
|
|
14
14
|
<a class="skip" href="#main">Skip to content</a>
|
|
15
|
-
<nav class="top" aria-label="Primary"><a href="/" class="brand">nexo</a><a href="/">Runs</a><a href="/sessions.html">Sessions</a><a href="/cost.html">Cost</a><a href="/learning.html">Learning</a><a href="/judge.html">Judge</a><a href="/optim.html">Optimization</a><a href="/wikis.html">Wikis</a></nav>
|
|
15
|
+
<nav class="top" aria-label="Primary"><a href="/" class="brand">nexo</a><a href="/home.html">Home</a><a href="/">Runs</a><a href="/sessions.html">Sessions</a><a href="/cost.html">Cost</a><a href="/learning.html">Learning</a><a href="/judge.html">Judge</a><a href="/optim.html">Optimization</a><a href="/wikis.html">Wikis</a></nav>
|
|
16
16
|
<main id="main" tabindex="-1">
|
|
17
17
|
<nav class="run-nav" aria-label="Run sections"><a href="#sec-timeline">Timeline</a><a href="#sec-spans">Spans</a><a href="#sec-scores">Scores</a><a href="#sec-memories">Memories</a><a href="#sec-subagents">Subagents</a><a href="#sec-files">Files</a><a href="#sec-review">Review</a></nav>
|
|
18
18
|
<div id="error"></div>
|
package/web/public/sessions.html
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
</head>
|
|
13
13
|
<body>
|
|
14
14
|
<a class="skip" href="#main">Skip to content</a>
|
|
15
|
-
<nav class="top" aria-label="Primary"><a href="/" class="brand">nexo</a><a href="/">Runs</a><a href="/sessions.html">Sessions</a><a href="/cost.html">Cost</a><a href="/learning.html">Learning</a><a href="/judge.html">Judge</a><a href="/optim.html">Optimization</a><a href="/wikis.html">Wikis</a></nav>
|
|
15
|
+
<nav class="top" aria-label="Primary"><a href="/" class="brand">nexo</a><a href="/home.html">Home</a><a href="/">Runs</a><a href="/sessions.html">Sessions</a><a href="/cost.html">Cost</a><a href="/learning.html">Learning</a><a href="/judge.html">Judge</a><a href="/optim.html">Optimization</a><a href="/wikis.html">Wikis</a></nav>
|
|
16
16
|
<main id="main" tabindex="-1">
|
|
17
17
|
<h1>Sessions</h1>
|
|
18
18
|
<p class="muted">Each chat message is a turn. Open a session to see its turns and review them.</p>
|
package/web/public/style.css
CHANGED
|
@@ -347,3 +347,34 @@ section[id] { scroll-margin-top: 96px; }
|
|
|
347
347
|
.nx-reply:empty { display: none; }
|
|
348
348
|
.nx-answer { margin: 6px 0; overflow-wrap: anywhere; white-space: pre-wrap; }
|
|
349
349
|
.nx-links { margin: 0 0 6px; padding-left: 18px; }
|
|
350
|
+
|
|
351
|
+
/* HTML wiki pages rendered inline (packages/web/public/pages/wikis.ts mountHtmlPage) */
|
|
352
|
+
.wiki-html .tldr { background: var(--bg); border: 1px solid var(--line); border-left: 4px solid var(--pen); padding: 12px 16px; border-radius: 4px; margin: 12px 0 16px; }
|
|
353
|
+
.wiki-html table { border-collapse: collapse; width: 100%; margin: 12px 0; font-size: 13px; }
|
|
354
|
+
.wiki-html th, .wiki-html td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
|
|
355
|
+
.wiki-html th { background: var(--bg); font-weight: 600; }
|
|
356
|
+
.wiki-html pre { margin: 12px 0; padding: 10px 14px; background: var(--bg); border: 1px solid var(--line); border-radius: 2px; overflow-x: auto; }
|
|
357
|
+
.wiki-html pre code { background: none; border: none; padding: 0; }
|
|
358
|
+
.wiki-html details { border: 1px solid var(--line); border-radius: 4px; padding: 8px 12px; margin: 8px 0; }
|
|
359
|
+
.wiki-html summary { cursor: pointer; font-weight: 600; }
|
|
360
|
+
.wiki-html svg { max-width: 100%; height: auto; }
|
|
361
|
+
.wiki-html a { color: var(--pen); text-decoration: underline; text-underline-offset: 3px; }
|
|
362
|
+
.wiki-html .dead { color: var(--muted); border-bottom: 1px dotted var(--muted); }
|
|
363
|
+
.wiki-html .note { border-left: 4px solid var(--line); padding: 8px 14px; background: var(--bg); }
|
|
364
|
+
.wiki-html figure { margin: 16px 0; }
|
|
365
|
+
.wiki-html figure svg { background: #fff; border: 1px solid var(--line); border-radius: 4px; }
|
|
366
|
+
.wiki-html figcaption { color: var(--muted); font-size: 12px; margin-top: 6px; }
|
|
367
|
+
|
|
368
|
+
/* Home page (packages/web/public/pages/home.ts) */
|
|
369
|
+
.home-search { width: 100%; max-width: 640px; padding: 8px 12px; margin: 8px 0 16px; border: 1px solid var(--line); border-radius: 4px; font: inherit; background: var(--bg); color: var(--fg); }
|
|
370
|
+
.home-areas { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
|
|
371
|
+
.home-area { border: 1px solid var(--line); border-radius: 6px; padding: 12px 14px; }
|
|
372
|
+
.home-area summary { cursor: pointer; }
|
|
373
|
+
.home-area h3 { font-size: 13px; margin: 14px 0 4px; }
|
|
374
|
+
.home-scope { display: block; font-size: 12px; margin-top: 4px; }
|
|
375
|
+
.home-list { margin: 4px 0; padding-left: 18px; }
|
|
376
|
+
.home-list li { margin: 4px 0; }
|
|
377
|
+
.home-tag { font-size: 11px; border: 1px solid var(--line); border-radius: 3px; padding: 0 4px; color: var(--muted); }
|
|
378
|
+
.home-note { border-left: 4px solid var(--pen); padding: 6px 12px; background: var(--bg); }
|
|
379
|
+
a.home-area { display: block; color: inherit; text-decoration: none; }
|
|
380
|
+
a.home-area:hover, a.home-area:focus-visible { border-color: var(--pen); }
|
package/web/public/wikis.html
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
</head>
|
|
13
13
|
<body>
|
|
14
14
|
<a class="skip" href="#main">Skip to content</a>
|
|
15
|
-
<nav class="top" aria-label="Primary"><a href="/" class="brand">nexo</a><a href="/">Runs</a><a href="/sessions.html">Sessions</a><a href="/cost.html">Cost</a><a href="/learning.html">Learning</a><a href="/judge.html">Judge</a><a href="/optim.html">Optimization</a><a href="/wikis.html" aria-current="page">Wikis</a></nav>
|
|
15
|
+
<nav class="top" aria-label="Primary"><a href="/" class="brand">nexo</a><a href="/home.html">Home</a><a href="/">Runs</a><a href="/sessions.html">Sessions</a><a href="/cost.html">Cost</a><a href="/learning.html">Learning</a><a href="/judge.html">Judge</a><a href="/optim.html">Optimization</a><a href="/wikis.html" aria-current="page">Wikis</a></nav>
|
|
16
16
|
<main id="main" tabindex="-1">
|
|
17
17
|
<h1>Wikis</h1>
|
|
18
18
|
<div id="error"></div>
|
package/web/src/api.js
CHANGED
|
@@ -2,7 +2,7 @@ import { closeSync, constants, createReadStream, existsSync, fstatSync, lstatSyn
|
|
|
2
2
|
import { extname, join, relative, sep } from "node:path";
|
|
3
3
|
import { agreementStats, approveOptimRun, listEvalCasesByStatus, reviewProposedCase, checkPromotion, getArtifact, getOptimRun, listOptimCandidates, queryOptimRuns, confusionMatrix, COST_DIMENSIONS, costReport, descendantRunIds, getRun, getRunWithSummary, getSpan, invalidRequest, isRunStatus, judgeDisagrees, judgeHumanPairs, latestFeedback, listCalibrations, listChildSummaries, listDisagreements, listFeedback, listScores, querySessionSummaries, MAX_RUN_PAGE, listSpans, loadSpanTree, queryRuns, RUN_STATUSES, readRunJson, recordFeedback, runNotFound, countLearnJobs, getMemory, getPlaybookItem, isSkillName, listArtifactVersions, queryLearnJobs, queryMemories, listPlaybookItems, listPlaybookSkills, memoryHistory, playbookItemHistory, publishPlaybook, retireMemory, retirePlaybookItem, transaction, resolveNexoPaths, } from "../../store/src/index.js";
|
|
4
4
|
import { NexoError } from "../../telemetry/src/index.js";
|
|
5
|
-
import { resolveConfined } from "../../tools/src/index.js";
|
|
5
|
+
import { resolveConfined, isWikiPageFile, parseWikiMeta, resolveWikiPagePath, wikiPageSlug } from "../../tools/src/index.js";
|
|
6
6
|
import { SECURITY_HEADERS } from "./http-errors.js";
|
|
7
7
|
/** Files larger than this are cut unless `?full=1` is passed; the response carries `x-nexo-truncated: <size>`. */
|
|
8
8
|
export const MAX_FILE_PREVIEW_BYTES = 1024 * 1024;
|
|
@@ -557,6 +557,9 @@ export function reviewEvalCaseResponse(ctx, id, decision) {
|
|
|
557
557
|
return { case: evalCaseItem(reviewProposedCase(ctx.db, id, decision, { redact: ctx.redact, nowIso: ctx.now().toISOString() })) };
|
|
558
558
|
}
|
|
559
559
|
function parseSummary(content) {
|
|
560
|
+
const metaSummary = parseWikiMeta(content).summary;
|
|
561
|
+
if (metaSummary)
|
|
562
|
+
return metaSummary;
|
|
560
563
|
const head = content.slice(0, 2048);
|
|
561
564
|
const match = /^---\r?\n([\s\S]*?)\r?\n---/.exec(head);
|
|
562
565
|
if (!match || !match[1])
|
|
@@ -592,7 +595,7 @@ export function listWikisResponse(ctx) {
|
|
|
592
595
|
if (!f.startsWith(".") && f !== ".git")
|
|
593
596
|
scan(fp);
|
|
594
597
|
}
|
|
595
|
-
else if (f
|
|
598
|
+
else if (isWikiPageFile(f)) {
|
|
596
599
|
pageCount++;
|
|
597
600
|
if (fst.mtime > maxModified)
|
|
598
601
|
maxModified = fst.mtime;
|
|
@@ -644,9 +647,9 @@ export function listWikiPagesResponse(ctx, wikiName) {
|
|
|
644
647
|
if (st.isDirectory()) {
|
|
645
648
|
walk(fp);
|
|
646
649
|
}
|
|
647
|
-
else if (f
|
|
650
|
+
else if (isWikiPageFile(f)) {
|
|
648
651
|
const rel = relative(wikiDir, fp).split(sep).join("/");
|
|
649
|
-
const slug = rel
|
|
652
|
+
const slug = wikiPageSlug(rel);
|
|
650
653
|
const folder = rel.includes("/") ? rel.slice(0, rel.lastIndexOf("/")) : undefined;
|
|
651
654
|
const content = readFileSync(fp, "utf8");
|
|
652
655
|
const summary = parseSummary(content);
|
|
@@ -688,8 +691,10 @@ export function wikiPageResponse(ctx, wikiName, relPath) {
|
|
|
688
691
|
throw new NexoError({ code: "NOT_FOUND", message: `Wiki "${wikiName}" does not exist`, context: { wiki: wikiName } });
|
|
689
692
|
}
|
|
690
693
|
let target;
|
|
694
|
+
let resolvedPath = relPath;
|
|
691
695
|
try {
|
|
692
|
-
|
|
696
|
+
resolvedPath = resolveWikiPagePath(wikiDir, relPath);
|
|
697
|
+
target = resolveConfined(wikiDir, resolvedPath);
|
|
693
698
|
}
|
|
694
699
|
catch (error) {
|
|
695
700
|
if (error instanceof NexoError && error.code === "TOOL_DENIED") {
|
|
@@ -705,7 +710,7 @@ export function wikiPageResponse(ctx, wikiName, relPath) {
|
|
|
705
710
|
const summary = parseSummary(content);
|
|
706
711
|
return {
|
|
707
712
|
wiki: wikiName,
|
|
708
|
-
path:
|
|
713
|
+
path: resolvedPath,
|
|
709
714
|
content,
|
|
710
715
|
summary,
|
|
711
716
|
size: st.size,
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { listSessionRows, resolveNexoPaths } from "../../store/src/index.js";
|
|
4
|
+
import { parseWikiMeta } from "../../tools/src/index.js";
|
|
5
|
+
const FEED_LIMIT = 50;
|
|
6
|
+
const DECISION_LIMIT = 50;
|
|
7
|
+
/** Reads a JSON-lines file newest first; unparseable lines are skipped. */
|
|
8
|
+
function readJsonl(file, limit) {
|
|
9
|
+
if (!existsSync(file))
|
|
10
|
+
return [];
|
|
11
|
+
const out = [];
|
|
12
|
+
for (const line of readFileSync(file, "utf8").split("\n").reverse()) {
|
|
13
|
+
if (!line.trim())
|
|
14
|
+
continue;
|
|
15
|
+
try {
|
|
16
|
+
out.push(JSON.parse(line));
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
// skip a torn or hand-edited line
|
|
20
|
+
}
|
|
21
|
+
if (out.length >= limit)
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
return out;
|
|
25
|
+
}
|
|
26
|
+
function countPages(dir) {
|
|
27
|
+
let n = 0;
|
|
28
|
+
const walk = (d) => {
|
|
29
|
+
for (const f of readdirSync(d)) {
|
|
30
|
+
if (f.startsWith(".") || f === "raw")
|
|
31
|
+
continue;
|
|
32
|
+
const p = join(d, f);
|
|
33
|
+
if (statSync(p).isDirectory())
|
|
34
|
+
walk(p);
|
|
35
|
+
else if (f.endsWith(".html") || f.endsWith(".md"))
|
|
36
|
+
n++;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
try {
|
|
40
|
+
walk(dir);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
// unreadable wiki: report what was counted
|
|
44
|
+
}
|
|
45
|
+
return n;
|
|
46
|
+
}
|
|
47
|
+
/** `GET /api/home`: approved areas with their wikis, the feed, decisions and recent sessions, read fresh on every call. */
|
|
48
|
+
export function homeResponse(ctx) {
|
|
49
|
+
const dir = ctx.wikisDir ?? resolveNexoPaths().wikis;
|
|
50
|
+
let raw = {};
|
|
51
|
+
try {
|
|
52
|
+
raw = JSON.parse(readFileSync(join(dir, "areas.json"), "utf8"));
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
raw = {};
|
|
56
|
+
}
|
|
57
|
+
const all = Array.isArray(raw.areas) ? raw.areas : [];
|
|
58
|
+
const active = all.filter((a) => a.status === "active");
|
|
59
|
+
const feed = readJsonl(join(dir, "feed.jsonl"), FEED_LIMIT).map((f) => ({ ...f, text: ctx.redact(String(f.text ?? "")) }));
|
|
60
|
+
const decisions = readJsonl(join(dir, "decisions.jsonl"), DECISION_LIMIT).map((d) => ({ ...d, choice: ctx.redact(String(d.choice ?? "")), reason: ctx.redact(String(d.reason ?? "")) }));
|
|
61
|
+
const weekAgo = ctx.now().getTime() - 7 * 86_400_000;
|
|
62
|
+
const areas = active.map((a) => ({
|
|
63
|
+
id: a.id,
|
|
64
|
+
name: a.name,
|
|
65
|
+
scope: a.scope,
|
|
66
|
+
wikis: (a.wikis ?? [])
|
|
67
|
+
.filter((w) => /^[a-z0-9-]+$/.test(w) && existsSync(join(dir, w)))
|
|
68
|
+
.map((w) => {
|
|
69
|
+
let summary;
|
|
70
|
+
try {
|
|
71
|
+
summary = parseWikiMeta(readFileSync(join(dir, w, "overview.html"), "utf8")).summary;
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
summary = undefined;
|
|
75
|
+
}
|
|
76
|
+
return { name: w, summary, pageCount: countPages(join(dir, w)) };
|
|
77
|
+
}),
|
|
78
|
+
recent: feed.filter((f) => f.areaId === a.id && Date.parse(f.at) >= weekAgo).length,
|
|
79
|
+
}));
|
|
80
|
+
const sessionArea = new Map();
|
|
81
|
+
for (const f of [...feed].reverse())
|
|
82
|
+
if (f.sessionId && f.areaId)
|
|
83
|
+
sessionArea.set(f.sessionId, f.areaId);
|
|
84
|
+
const sessions = listSessionRows(ctx.db, { limit: 15 }).map((s) => ({
|
|
85
|
+
id: s.id,
|
|
86
|
+
title: ctx.redact(s.title ?? ""),
|
|
87
|
+
cwd: s.cwd,
|
|
88
|
+
updatedAt: s.updatedAt,
|
|
89
|
+
areaId: sessionArea.get(s.id) ?? null,
|
|
90
|
+
}));
|
|
91
|
+
return {
|
|
92
|
+
areas,
|
|
93
|
+
proposed: all.filter((a) => a.status === "proposed").map((a) => ({ id: a.id, name: a.name })),
|
|
94
|
+
unsorted: Array.isArray(raw.unsorted) ? raw.unsorted.length : 0,
|
|
95
|
+
feed,
|
|
96
|
+
decisions,
|
|
97
|
+
sessions,
|
|
98
|
+
};
|
|
99
|
+
}
|
package/web/src/server.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { homeResponse } from "./home-api.js";
|
|
1
2
|
import { randomBytes, timingSafeEqual } from "node:crypto";
|
|
2
3
|
import { createServer } from "node:http";
|
|
3
4
|
import { fileURLToPath } from "node:url";
|
|
@@ -260,6 +261,11 @@ export async function startWebServer(options) {
|
|
|
260
261
|
assertWritable();
|
|
261
262
|
return sendJson(res, 200, reviewEvalCaseResponse(ctx, m[1], m[2]));
|
|
262
263
|
}
|
|
264
|
+
if (path === "/api/home") {
|
|
265
|
+
if (method !== "GET")
|
|
266
|
+
throw methodNotAllowed(method, path, "GET");
|
|
267
|
+
return sendJson(res, 200, homeResponse(ctx));
|
|
268
|
+
}
|
|
263
269
|
if (ROUTES.wikis.test(path)) {
|
|
264
270
|
if (method !== "GET")
|
|
265
271
|
throw methodNotAllowed(method, path, "GET");
|
package/optimize/src/merge.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/** Every ancestor of `id` (parents, their parents, …), not `id` itself. */
|
|
2
|
-
export function ancestors(id, nodes) {
|
|
3
|
-
const seen = new Set();
|
|
4
|
-
const stack = [...(nodes.get(id)?.parentIds ?? [])];
|
|
5
|
-
while (stack.length > 0) {
|
|
6
|
-
const next = stack.pop();
|
|
7
|
-
if (seen.has(next))
|
|
8
|
-
continue;
|
|
9
|
-
seen.add(next);
|
|
10
|
-
stack.push(...(nodes.get(next)?.parentIds ?? []));
|
|
11
|
-
}
|
|
12
|
-
return seen;
|
|
13
|
-
}
|
|
14
|
-
/** The most recent common ancestor of `a` and `b` (the latest in `nodes` order), or null. */
|
|
15
|
-
export function commonAncestor(a, b, nodes) {
|
|
16
|
-
const ofA = ancestors(a, nodes);
|
|
17
|
-
const ofB = ancestors(b, nodes);
|
|
18
|
-
let found = null;
|
|
19
|
-
for (const id of nodes.keys())
|
|
20
|
-
if (ofA.has(id) && ofB.has(id))
|
|
21
|
-
found = id;
|
|
22
|
-
return found;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* System-aware merge (GEPA): each component comes from whichever side changed it since `ancestor`. Returns null when
|
|
26
|
-
* both sides changed the same component differently, or when the result would equal one side (nothing to combine).
|
|
27
|
-
*/
|
|
28
|
-
export function mergeTexts(ancestor, a, b) {
|
|
29
|
-
const merged = {};
|
|
30
|
-
let fromA = false;
|
|
31
|
-
let fromB = false;
|
|
32
|
-
for (const component of Object.keys(ancestor)) {
|
|
33
|
-
const base = ancestor[component] ?? "";
|
|
34
|
-
const textA = a[component] ?? base;
|
|
35
|
-
const textB = b[component] ?? base;
|
|
36
|
-
const changedA = textA !== base;
|
|
37
|
-
const changedB = textB !== base;
|
|
38
|
-
if (changedA && changedB && textA !== textB)
|
|
39
|
-
return null;
|
|
40
|
-
if (changedA)
|
|
41
|
-
fromA = true;
|
|
42
|
-
if (changedB && !changedA)
|
|
43
|
-
fromB = true;
|
|
44
|
-
merged[component] = changedA ? textA : textB;
|
|
45
|
-
}
|
|
46
|
-
return fromA && fromB ? merged : null;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* The first pair of Pareto members (in order) that is not ancestor and descendant, not tried before, has a common
|
|
50
|
-
* ancestor, and merges without a conflict. `tried` holds `a|b` keys of pairs already merged or attempted.
|
|
51
|
-
*/
|
|
52
|
-
export function findMerge(members, nodes, texts, tried) {
|
|
53
|
-
for (let i = 0; i < members.length; i++) {
|
|
54
|
-
for (let j = i + 1; j < members.length; j++) {
|
|
55
|
-
const a = members[i];
|
|
56
|
-
const b = members[j];
|
|
57
|
-
if (tried.has(`${a}|${b}`))
|
|
58
|
-
continue;
|
|
59
|
-
if (ancestors(a, nodes).has(b) || ancestors(b, nodes).has(a))
|
|
60
|
-
continue;
|
|
61
|
-
const ancestor = commonAncestor(a, b, nodes);
|
|
62
|
-
const base = ancestor ? texts.get(ancestor) : undefined;
|
|
63
|
-
const ta = texts.get(a);
|
|
64
|
-
const tb = texts.get(b);
|
|
65
|
-
if (!ancestor || !base || !ta || !tb)
|
|
66
|
-
continue;
|
|
67
|
-
const merged = mergeTexts(base, ta, tb);
|
|
68
|
-
if (merged)
|
|
69
|
-
return { a, b, ancestor, texts: merged };
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return null;
|
|
73
|
-
}
|