Spaces:
Running
Running
File size: 24,344 Bytes
bc630c6 8b02c3d bc630c6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 | (function () {
"use strict";
let MANIFEST = null;
const PAGE_CACHE = {};
const UNFURL_CACHE = {};
function esc(s) {
return String(s)
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">");
}
function flattenTree(node, depth, acc) {
acc.push({ node: node, depth: depth });
(node.children || []).forEach((c) => flattenTree(c, depth + 1, acc));
return acc;
}
function findNode(node, slug) {
if (node.slug === slug) return node;
for (const c of node.children || []) {
const hit = findNode(c, slug);
if (hit) return hit;
}
return null;
}
/* -------------------- minimal markdown -------------------- */
function inline(text) {
let t = esc(text);
t = t.replace(/`([^`]+)`/g, (_, c) => `<code>${c}</code>`);
t = t.replace(/\*\*([^*]+)\*\*/g, (_, c) => `<strong>${c}</strong>`);
t = t.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_, txt, url) => {
const safe = esc(url);
const attrs = /^https?:/.test(url) ? ' target="_blank" rel="noopener"' : "";
return `<a href="${safe}"${attrs}>${txt}</a>`;
});
t = t.replace(/(^|[\s(])(https?:\/\/[^\s<)]+)/g, (m, pre, url) => {
return `${pre}<a href="${url}" target="_blank" rel="noopener">${url}</a>`;
});
return t;
}
const URL_ONLY = /^(https?:\/\/[^\s]+)$/;
function renderMarkdown(md, container) {
const lines = md.replace(/<!--[\s\S]*?-->/g, "").split("\n");
let i = 0;
let para = [];
function flushPara() {
if (!para.length) return;
const joined = para.join(" ").trim();
para = [];
if (!joined) return;
if (URL_ONLY.test(joined) || IMG_PATH.test(joined)) {
container.appendChild(unfurl(joined));
return;
}
const p = document.createElement("p");
p.innerHTML = inline(joined);
container.appendChild(p);
}
while (i < lines.length) {
const line = lines[i];
const trimmed = line.trim();
if (trimmed === "") {
flushPara();
i++;
continue;
}
const fence = trimmed.match(/^(`{3,}|~{3,})(.*)$/);
if (fence) {
flushPara();
const marker = fence[1][0];
const closeRe = new RegExp("^" + marker + "{" + fence[1].length + ",}\\s*$");
const info = fence[2].trim();
const buf = [];
i++;
while (i < lines.length && !closeRe.test(lines[i].trim())) {
buf.push(lines[i]);
i++;
}
i++;
const lang = (info.split(/\s+/)[0] || "").toLowerCase();
const tm = info.match(/title=(\S+)/);
container.appendChild(
renderCode(buf.join("\n"), lang, tm ? tm[1] : null)
);
continue;
}
if (trimmed === "---") {
flushPara();
container.appendChild(document.createElement("hr"));
i++;
continue;
}
const h = trimmed.match(/^(#{1,4})\s+(.*)$/);
if (h) {
flushPara();
const el = document.createElement("h" + h[1].length);
el.innerHTML = inline(h[2]);
container.appendChild(el);
i++;
continue;
}
if (
trimmed.startsWith("|") &&
i + 1 < lines.length &&
/^\|?[\s:|-]*-{2,}[\s:|-]*\|?$/.test(lines[i + 1].trim())
) {
flushPara();
const rows = [];
while (i < lines.length && lines[i].trim().startsWith("|")) {
rows.push(parseRow(lines[i].trim()));
i++;
}
renderTable(rows, container);
continue;
}
if (trimmed.startsWith("> ")) {
flushPara();
const bq = document.createElement("blockquote");
bq.innerHTML = inline(trimmed.slice(2));
container.appendChild(bq);
i++;
continue;
}
if (/^`[^`]+`$/.test(trimmed)) {
flushPara();
const el = document.createElement("div");
el.className = "ts";
el.textContent = trimmed.replace(/`/g, "");
container.appendChild(el);
i++;
continue;
}
if (trimmed.startsWith("- ")) {
flushPara();
const items = [];
while (i < lines.length && lines[i].trim().startsWith("- ")) {
items.push(lines[i].trim().slice(2).trim());
i++;
}
renderList(items, container);
continue;
}
para.push(trimmed);
i++;
}
flushPara();
}
function parseRow(line) {
let s = line.trim();
if (s.startsWith("|")) s = s.slice(1);
if (s.endsWith("|")) s = s.slice(0, -1);
return s.split(/(?<!\\)\|/).map((c) => c.replace(/\\\|/g, "|").trim());
}
const TRUTHY = ["x", "β", "β", "yes", "done", "true", "[x]"];
const CHIP_COLORS = [
["#e7f0ff", "#2158d0"],
["#fde8ec", "#c62a4b"],
["#e6f7ee", "#1a8a55"],
["#fdf0e0", "#b26a12"],
["#efe9ff", "#5b3bd6"],
["#e6f6f8", "#127b88"],
];
function chipColor(name) {
let h = 0;
for (let i = 0; i < name.length; i++) h = (h * 31 + name.charCodeAt(i)) >>> 0;
return CHIP_COLORS[h % CHIP_COLORS.length];
}
const STATUS_MAP = {
"": ["Planned", "gray"],
planned: ["Planned", "gray"],
todo: ["Planned", "gray"],
"to do": ["Planned", "gray"],
backlog: ["Planned", "gray"],
"in progress": ["In progress", "amber"],
"in-progress": ["In progress", "amber"],
wip: ["In progress", "amber"],
running: ["In progress", "amber"],
active: ["In progress", "amber"],
done: ["Done", "green"],
complete: ["Done", "green"],
completed: ["Done", "green"],
blocked: ["Blocked", "red"],
failed: ["Failed", "red"],
abandoned: ["Abandoned", "gray"],
};
function statusBadge(val) {
const [label, tone] = STATUS_MAP[val.toLowerCase()] || [val || "β", "gray"];
return `<span class="badge ${tone}">${esc(label)}</span>`;
}
function renderTable(rows, container) {
if (rows.length < 2) return;
const header = rows[0];
const body = rows.slice(2);
const roles = header.map((h) => {
const t = h.toLowerCase();
if (t.includes("status") || t.includes("state")) return "status";
if (t.includes("progress") || t.includes("complete") || t.includes("done"))
return "check";
if (t === "who" || t.includes("assign") || t.includes("owner")) return "who";
return "text";
});
const table = document.createElement("table");
table.className = "board";
const thead = document.createElement("thead");
const htr = document.createElement("tr");
header.forEach((h, c) => {
const th = document.createElement("th");
th.textContent = h;
if (roles[c] === "check") th.className = "col-check";
htr.appendChild(th);
});
thead.appendChild(htr);
table.appendChild(thead);
const tbody = document.createElement("tbody");
body.forEach((cells) => {
const nonEmpty = cells.filter((x) => x !== "").length;
if (nonEmpty === 1 && cells[0]) {
const tr = document.createElement("tr");
tr.className = "section-row";
const td = document.createElement("td");
td.colSpan = header.length;
td.innerHTML = inline(cells[0]);
tr.appendChild(td);
tbody.appendChild(tr);
return;
}
const tr = document.createElement("tr");
header.forEach((_, c) => {
const td = document.createElement("td");
const val = (cells[c] || "").trim();
if (roles[c] === "status") {
td.className = "col-status";
td.innerHTML = statusBadge(val);
} else if (roles[c] === "check") {
td.className = "col-check";
const on = TRUTHY.indexOf(val.toLowerCase()) !== -1;
td.innerHTML = `<span class="box ${on ? "on" : ""}">${on ? "β" : ""}</span>`;
} else if (roles[c] === "who") {
if (!val || /^to assign$/i.test(val)) {
td.innerHTML = `<span class="who-chip muted">${esc(val || "β")}</span>`;
} else {
const [bg, fg] = chipColor(val);
td.innerHTML = `<span class="who-chip" style="background:${bg};color:${fg}">${esc(val)}</span>`;
}
} else {
td.innerHTML = inline(val);
}
tr.appendChild(td);
});
const link = tr.querySelector('a[href^="#/"]');
if (link) {
tr.classList.add("linked-row");
tr.addEventListener("click", (e) => {
if (e.target.tagName !== "A") location.hash = link.getAttribute("href");
});
}
tbody.appendChild(tr);
});
table.appendChild(tbody);
const wrap = document.createElement("div");
wrap.className = "board-wrap";
wrap.appendChild(table);
container.appendChild(wrap);
}
const HL_RULES = {
python: [
["comment", /#[^\n]*/],
["string", /'''[\s\S]*?'''|"""[\s\S]*?"""|'(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"/],
[
"keyword",
/\b(?:def|class|return|if|elif|else|for|while|import|from|as|with|try|except|finally|raise|in|not|and|or|is|None|True|False|lambda|yield|global|nonlocal|assert|pass|break|continue|async|await|print)\b/,
],
["number", /\b\d[\d_.eE+-]*\b/],
],
bash: [
["comment", /#[^\n]*/],
["string", /'(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"/],
["keyword", /\b(?:if|then|else|fi|for|in|do|done|while|case|esac|function|export|source|echo|cd|return|local)\b/],
["number", /(?<=\s)-{1,2}[a-zA-Z][\w-]*/],
],
json: [
["string", /"(?:\\.|[^"\\])*"/],
["keyword", /\b(?:true|false|null)\b/],
["number", /-?\b\d[\d.eE+-]*\b/],
],
yaml: [
["comment", /#[^\n]*/],
["string", /'(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"/],
["keyword", /\b(?:true|false|null|yes|no)\b/],
["number", /-?\b\d[\d.eE+-]*\b/],
],
};
HL_RULES.javascript = HL_RULES.python;
HL_RULES.typescript = HL_RULES.python;
HL_RULES.sql = [
["comment", /--[^\n]*/],
["string", /'(?:\\.|[^'\\])*'/],
[
"keyword",
/\b(?:SELECT|FROM|WHERE|JOIN|LEFT|RIGHT|INNER|OUTER|ON|GROUP|BY|ORDER|LIMIT|INSERT|INTO|VALUES|UPDATE|SET|DELETE|CREATE|TABLE|AS|AND|OR|NOT|NULL|COUNT|DISTINCT|IN)\b/i,
],
["number", /\b\d[\d.]*\b/],
];
function highlightCode(code, lang) {
const rules = HL_RULES[lang];
if (!rules) return esc(code);
const combined = new RegExp(rules.map((r) => "(" + r[1].source + ")").join("|"), "g");
let out = "";
let last = 0;
let m;
while ((m = combined.exec(code))) {
if (m[0] === "") {
combined.lastIndex++;
continue;
}
out += esc(code.slice(last, m.index));
let gi = 1;
while (gi < m.length && m[gi] === undefined) gi++;
out += `<span class="tok-${rules[gi - 1][0]}">${esc(m[0])}</span>`;
last = m.index + m[0].length;
}
out += esc(code.slice(last));
return out;
}
function renderCode(code, lang, title) {
const pre = document.createElement("pre");
pre.className = "hl";
const c = document.createElement("code");
c.innerHTML = highlightCode(code, lang);
pre.appendChild(c);
if (!title) return pre;
const det = document.createElement("details");
det.className = "code-accordion";
const sum = document.createElement("summary");
sum.innerHTML = `<span class="code-ico"></></span> ${esc(title)}`;
det.appendChild(sum);
det.appendChild(pre);
return det;
}
const IMG_PATH = /^[^\s]+\.(png|jpe?g|gif|svg|webp)$/i;
function renderList(items, container) {
let ul = null;
items.forEach((item) => {
if (URL_ONLY.test(item) || IMG_PATH.test(item)) {
ul = null;
container.appendChild(unfurl(item));
} else if (item.indexOf("π¦ Artifact") !== -1) {
ul = null;
const div = document.createElement("div");
div.className = "artifact-chip";
div.innerHTML = inline(item);
container.appendChild(div);
} else {
if (!ul) {
ul = document.createElement("ul");
container.appendChild(ul);
}
const li = document.createElement("li");
li.innerHTML = inline(item);
ul.appendChild(li);
}
});
}
/* -------------------- unfurl providers -------------------- */
function card(url, kind, icon, title, desc, chips) {
const a = document.createElement("a");
a.className = "unfurl";
a.href = url;
a.target = "_blank";
a.rel = "noopener";
const chipHtml = (chips || [])
.filter(Boolean)
.map((c) => `<span class="chip">${esc(c)}</span>`)
.join("");
a.innerHTML =
`<div class="unfurl-body">` +
`<div class="unfurl-ico">${icon}</div>` +
`<div class="unfurl-main">` +
`<div class="unfurl-kind">${esc(kind)}</div>` +
`<div class="unfurl-title">${esc(title)}</div>` +
(desc ? `<div class="unfurl-desc">${esc(desc)}</div>` : "") +
(chipHtml ? `<div class="unfurl-meta">${chipHtml}</div>` : "") +
`</div></div>` +
`<div class="unfurl-raw">${esc(url)}</div>`;
return a;
}
function fmt(n) {
if (n == null) return null;
if (n >= 1e6) return (n / 1e6).toFixed(1) + "M";
if (n >= 1e3) return (n / 1e3).toFixed(1) + "k";
return String(n);
}
const providers = [
{
test: (u) => /\.(png|jpe?g|gif|svg|webp)(\?|$)/i.test(u) || /\/artifact_blob\//.test(u),
render: (u, el) => {
el.className = "unfurl image";
el.href = u;
const img = document.createElement("img");
img.loading = "lazy";
img.src = u;
img.alt = "artifact image";
el.appendChild(img);
},
},
{
test: (u) => /huggingface\.co\/datasets\//.test(u),
render: async (u, el) => {
const id = u.split("/datasets/")[1].split(/[?#]/)[0].replace(/\/$/, "");
base(el, u, "HF Dataset", "π", id, "Hugging Face dataset");
const d = await getJSON(`https://huggingface.co/api/datasets/${id}`);
if (d)
fill(el, id, d.cardData?.pretty_name || id, [
`β ${fmt(d.downloads)}`,
`β₯ ${fmt(d.likes)}`,
...(d.tags || []).filter((t) => !t.includes(":")).slice(0, 3),
]);
},
},
{
test: (u) => /huggingface\.co\/spaces\//.test(u),
embed: true,
render: (u, el) => {
const id = u.split("/spaces/")[1].split(/[?#]/)[0].replace(/\/$/, "");
const sub = id.toLowerCase().replace(/[^a-z0-9-]/g, "-");
el.classList.add("embed");
el.innerHTML =
`<div class="embed-head">` +
`<span class="unfurl-kind">π HF Space</span>` +
`<a class="embed-title" href="${esc(u)}" target="_blank" rel="noopener">${esc(id)}</a>` +
`<a class="embed-open" href="${esc(u)}" target="_blank" rel="noopener">Open β</a>` +
`</div>` +
`<iframe class="embed-frame" src="https://${sub}.hf.space/?sidebar=hidden&navbar=hidden" loading="lazy" ` +
`allow="clipboard-read; clipboard-write; fullscreen"></iframe>`;
},
},
{
test: (u) => /huggingface\.co\/jobs\//.test(u),
render: (u, el) => {
const rest = u.split("/jobs/")[1].split(/[?#]/)[0].replace(/\/$/, "");
const parts = rest.split("/");
const jid = parts[1] || "";
base(
el,
u,
"HF Job",
"βοΈ",
`${parts[0]} Β· ${jid.slice(0, 12)}${jid.length > 12 ? "β¦" : ""}`,
"Hugging Face Job β open to view status & logs"
);
},
},
{
test: (u) => /huggingface\.co\/buckets\//.test(u),
render: (u, el) => {
const id = u.split("/buckets/")[1].split(/[?#]/)[0].replace(/\/$/, "");
base(el, u, "HF Bucket", "πͺ£", id, "Hugging Face Bucket β stored artifacts & data");
},
},
{
test: (u) => /arxiv\.org\/(abs|pdf)\//.test(u),
render: (u, el) => {
const id = u.split(/\/(abs|pdf)\//)[2].replace(/\.pdf$/, "");
base(el, u, "arXiv", "π", `arXiv:${id}`, "Preprint");
},
},
{
test: (u) => /github\.com\/[^/]+\/[^/]+/.test(u),
render: async (u, el) => {
const m = u.match(/github\.com\/([^/]+)\/([^/?#]+)/);
const id = `${m[1]}/${m[2]}`;
base(el, u, "GitHub", "π", id, "Repository");
const d = await getJSON(`https://api.github.com/repos/${id}`);
if (d)
fill(el, id, d.description, [
`β
${fmt(d.stargazers_count)}`,
d.language,
]);
},
},
{
test: (u) => /huggingface\.co\/[^/]+\/[^/]+/.test(u),
render: async (u, el) => {
const id = u.split("huggingface.co/")[1].split(/[?#]/)[0].replace(/\/$/, "");
base(el, u, "HF Model", "π€", id, "Model on the Hugging Face Hub");
const d = await getJSON(`https://huggingface.co/api/models/${id}`);
if (d)
fill(el, id, d.pipeline_tag ? `Task: ${d.pipeline_tag}` : null, [
`β ${fmt(d.downloads)}`,
`β₯ ${fmt(d.likes)}`,
...(d.tags || []).filter((t) => !t.includes(":")).slice(0, 2),
]);
},
},
];
function base(el, url, kind, icon, title, desc) {
el.className = "unfurl";
el.href = url;
el.innerHTML =
`<div class="unfurl-body"><div class="unfurl-ico">${icon}</div>` +
`<div class="unfurl-main"><div class="unfurl-kind">${esc(kind)}</div>` +
`<div class="unfurl-title">${esc(title)}</div>` +
`<div class="unfurl-desc">${esc(desc)}</div>` +
`<div class="unfurl-meta"></div></div></div>` +
`<div class="unfurl-raw">${esc(url)}</div>`;
}
function fill(el, title, desc, chips) {
if (title) el.querySelector(".unfurl-title").textContent = title;
const d = el.querySelector(".unfurl-desc");
if (desc) d.textContent = desc;
const meta = el.querySelector(".unfurl-meta");
meta.innerHTML = (chips || [])
.filter(Boolean)
.map((c) => `<span class="chip">${esc(c)}</span>`)
.join("");
}
async function getJSON(url) {
if (UNFURL_CACHE[url] !== undefined) return UNFURL_CACHE[url];
try {
const r = await fetch(url);
if (!r.ok) throw new Error(r.status);
const j = await r.json();
UNFURL_CACHE[url] = j;
return j;
} catch (e) {
UNFURL_CACHE[url] = null;
return null;
}
}
function unfurl(url) {
const provider = providers.find((p) => p.test(url));
const el = document.createElement(provider && provider.embed ? "div" : "a");
el.className = "unfurl";
if (el.tagName === "A") {
el.href = url;
el.target = "_blank";
el.rel = "noopener";
}
if (provider) {
const out = provider.render(url, el);
if (out && typeof out.then === "function") out.catch(() => {});
} else {
let host = url;
try {
host = new URL(url).hostname.replace(/^www\./, "");
} catch (e) {}
base(el, url, "Link", "π", host, url);
}
return el;
}
/* -------------------- routing / render -------------------- */
function buildTree() {
const tree = document.getElementById("tree");
tree.innerHTML = "";
const nodes = [];
(MANIFEST.root.children || []).forEach((c) => flattenTree(c, 0, nodes));
nodes.forEach(({ node, depth }) => {
const a = document.createElement("a");
a.href = "#/" + node.slug;
a.textContent = node.title;
a.className = "depth-" + depth;
a.dataset.slug = node.slug;
tree.appendChild(a);
});
}
function highlight(slug) {
document
.querySelectorAll("#tree a")
.forEach((a) => a.classList.toggle("active", a.dataset.slug === slug));
document
.getElementById("book-head")
.classList.toggle("active", slug === MANIFEST.root.slug);
}
async function loadPage(slug) {
const node = findNode(MANIFEST.root, slug) || MANIFEST.root;
const page = document.getElementById("page");
page.innerHTML = "";
if (!PAGE_CACHE[node.file]) {
try {
const r = await fetch("./" + node.file);
PAGE_CACHE[node.file] = await r.text();
} catch (e) {
PAGE_CACHE[node.file] = "# " + node.title + "\n\n_Could not load page._";
}
}
renderMarkdown(PAGE_CACHE[node.file], page);
highlight(node.slug);
document.getElementById("content").scrollTo(0, 0);
window.scrollTo(0, 0);
}
function route() {
const slug = (location.hash || "").replace(/^#\//, "") || MANIFEST.root.slug;
loadPage(slug);
}
function setupConnect() {
const space = MANIFEST.space_id;
if (!space) return;
const steps = [
{ t: "Install Trackio, if you don't have it yet.", c: "uv tool install trackio" },
{ t: "Add the Trackio skill for your agent, then reload it.", c: "trackio skills add" },
{ t: "Connect to this logbook.", c: `trackio logbook open ${space}` },
];
const ol = document.getElementById("connect-steps");
steps.forEach((s, i) => {
const li = document.createElement("li");
const title = document.createElement("div");
title.className = "step-title";
title.textContent = `${i + 1}. ${s.t}`;
const block = document.createElement("div");
block.className = "codeblock";
const code = document.createElement("code");
code.textContent = s.c;
const copy = document.createElement("button");
copy.className = "copy";
copy.type = "button";
copy.title = "Copy";
copy.textContent = "β§";
copy.addEventListener("click", () => copyText(s.c, copy, "β§"));
block.appendChild(code);
block.appendChild(copy);
li.appendChild(title);
li.appendChild(block);
ol.appendChild(li);
});
const agentPrompt =
`Read and help maintain this Trackio experiment logbook ("${MANIFEST.title}").\n\n` +
"1. If you don't have Trackio, install it: uv tool install trackio\n" +
"2. Add the Trackio skill for your agent: trackio skills add (then reload)\n" +
`3. Connect to this logbook: trackio logbook open ${space}\n\n` +
"You'll get a compact, token-efficient copy you can read. If I've given you " +
'write access to the Space, add findings with `trackio logbook note "..." ' +
'--experiment "..."` and they will sync back automatically.';
const foot = document.getElementById("sidebar-foot");
foot.hidden = false;
const modal = document.getElementById("modal");
const open = () => (modal.hidden = false);
const close = () => (modal.hidden = true);
document.getElementById("connect-btn").addEventListener("click", open);
document.getElementById("modal-close").addEventListener("click", close);
modal.querySelector(".modal-backdrop").addEventListener("click", close);
document.addEventListener("keydown", (e) => {
if (e.key === "Escape") close();
});
const agentBtn = document.getElementById("copy-agent");
agentBtn.addEventListener("click", () =>
copyText(agentPrompt, agentBtn, "Copy for agent")
);
}
function copyText(text, btn, restore) {
const done = () => {
const prev = btn.textContent;
btn.textContent = restore === "β§" ? "β" : "Copied!";
btn.classList.add("copied");
setTimeout(() => {
btn.textContent = restore;
btn.classList.remove("copied");
}, 1400);
void prev;
};
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(text).then(done, done);
} else {
const ta = document.createElement("textarea");
ta.value = text;
document.body.appendChild(ta);
ta.select();
try {
document.execCommand("copy");
} catch (e) {}
document.body.removeChild(ta);
done();
}
}
async function init() {
MANIFEST = await (await fetch("./logbook.json")).json();
document.title = MANIFEST.title + " Β· Trackio Logbook";
document.getElementById("book-title").textContent = MANIFEST.title;
document.getElementById("book-head").addEventListener("click", () => {
location.hash = "#/" + MANIFEST.root.slug;
});
buildTree();
setupConnect();
window.addEventListener("hashchange", route);
route();
}
init();
})();
|