430 lines
23 KiB
HTML
430 lines
23 KiB
HTML
<!doctype html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8" />
|
||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||
<style>
|
||
/* Font, colours, cards, buttons, fields, chips, badges, tables come from
|
||
the host's UI kit (aia-*); what's here is the plans' own layout. */
|
||
* { box-sizing: border-box; }
|
||
body { margin: 0; background: transparent; }
|
||
a { color: hsl(var(--primary)); text-decoration: none; cursor: pointer; }
|
||
a:hover { text-decoration: underline; }
|
||
.mono { font-family: var(--aia-mono); font-variant-numeric: tabular-nums; }
|
||
.aia-toolbar .search { flex: 1 1 220px; }
|
||
.pills { gap: 6px; margin-bottom: 8px; }
|
||
.grid { --aia-col: 280px; margin-top: 6px; }
|
||
.plan { display: flex; flex-direction: column; gap: 8px; }
|
||
.plan .head { display: flex; align-items: flex-start; gap: 8px; justify-content: space-between; }
|
||
.plan .aia-title { word-break: break-word; }
|
||
.tags { display: flex; flex-wrap: wrap; gap: 4px; }
|
||
.stats { display: flex; flex-wrap: wrap; gap: 10px; font-size: 11.5px; }
|
||
.stat b { font-weight: 600; color: hsl(var(--foreground)); }
|
||
.over { color: hsl(var(--destructive)) !important; }
|
||
.under { color: hsl(152 55% 40%) !important; }
|
||
.sec { margin-top: 12px; }
|
||
.sec > .aia-section { margin-top: 0; }
|
||
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }
|
||
.metric { border-radius: 10px; background: hsl(var(--muted) / .5); padding: 8px 10px; }
|
||
.metric .k { font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; color: hsl(var(--muted-foreground)); }
|
||
.metric .v { font-size: 15px; font-weight: 600; margin-top: 2px; }
|
||
.metric .a { font-size: 11.5px; margin-top: 1px; }
|
||
td.file { font-family: var(--aia-mono); font-size: 11.5px; word-break: break-all; width: 42%; }
|
||
ol.steps { margin: 0; padding-left: 20px; }
|
||
ol.steps li { margin: 0 0 6px; }
|
||
ol.steps .d { color: hsl(var(--muted-foreground)); font-size: 12px; }
|
||
.detail-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
|
||
.detail-head h1 { margin: 0; font-size: 19px; line-height: 1.25; word-break: break-word; }
|
||
.conv { display: flex; gap: 8px; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid hsl(var(--border) / .6); font-size: 12.5px; }
|
||
.conv:last-child { border-bottom: 0; }
|
||
.md { font-size: 13px; overflow-wrap: anywhere; }
|
||
.md h1, .md h2, .md h3, .md h4 { margin: 14px 0 6px; line-height: 1.3; }
|
||
.md h1 { font-size: 17px; } .md h2 { font-size: 15px; } .md h3 { font-size: 13.5px; }
|
||
.md p { margin: 6px 0; }
|
||
.md ul, .md ol { margin: 6px 0; padding-left: 20px; }
|
||
.md code { font-family: var(--aia-mono); font-size: 12px; background: hsl(var(--muted)); padding: 1px 4px; border-radius: 4px; }
|
||
.md pre { background: hsl(var(--muted) / .7); border-radius: 8px; padding: 8px 10px; overflow-x: auto; }
|
||
.md pre code { background: none; padding: 0; }
|
||
.md blockquote { margin: 6px 0; padding-left: 10px; border-left: 3px solid hsl(var(--border)); color: hsl(var(--muted-foreground)); }
|
||
.md table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
|
||
.md td, .md th { text-align: left; padding: 5px 6px; border-bottom: 1px solid hsl(var(--border) / .7); vertical-align: top; }
|
||
.md th { font-size: 11px; color: hsl(var(--muted-foreground)); font-weight: 600; }
|
||
.answers li { margin-bottom: 3px; }
|
||
#err:empty { display: none; }
|
||
#err { margin-top: 8px; }
|
||
details > summary { cursor: pointer; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: hsl(var(--muted-foreground)); }
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<div class="aia-page" id="root"></div>
|
||
<script>
|
||
(function () {
|
||
var A = window.aiAgentPlugin;
|
||
var init = (A && A.init) || {};
|
||
var root = document.getElementById("root");
|
||
var STATUSES = ["proposed", "approved", "in-progress", "done"];
|
||
|
||
function esc(s) {
|
||
return String(s == null ? "" : s).replace(/[&<>"']/g, function (c) {
|
||
return { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c];
|
||
});
|
||
}
|
||
function fmtCost(v) { return v == null ? "—" : "$" + (v >= 100 ? v.toFixed(0) : v.toFixed(2)); }
|
||
function fmtTokens(v) {
|
||
if (v == null) return "—";
|
||
if (v >= 1e6) return (v / 1e6).toFixed(1) + "M";
|
||
if (v >= 1e3) return (v / 1e3).toFixed(1) + "k";
|
||
return String(v);
|
||
}
|
||
function fmtMin(m) {
|
||
if (m == null) return "—";
|
||
if (m < 60) return Math.round(m) + " min";
|
||
var h = Math.floor(m / 60), r = Math.round(m % 60);
|
||
return h + " h" + (r ? " " + r : "");
|
||
}
|
||
function msToMin(ms) { return ms == null ? null : ms / 60000; }
|
||
function cmp(est, act) {
|
||
if (est == null || act == null || est <= 0) return "";
|
||
return act > est * 1.1 ? "over" : act < est * 0.9 ? "under" : "";
|
||
}
|
||
var TONE = { approved: "info", "in-progress": "warn", done: "success" };
|
||
function badge(st) {
|
||
return '<span class="aia-badge"' + (TONE[st] ? ' data-tone="' + TONE[st] + '"' : "") + ">" + esc(st) + "</span>";
|
||
}
|
||
function fit() {
|
||
if (A && A.resize) A.resize(Math.ceil(document.documentElement.scrollHeight) + 4);
|
||
}
|
||
if (window.ResizeObserver) new ResizeObserver(fit).observe(document.body);
|
||
|
||
// ── tiny, escaped markdown → HTML (headings, lists, fences, tables, quotes)
|
||
function inline(s) {
|
||
s = esc(s);
|
||
s = s.replace(/`([^`]+)`/g, "<code>$1</code>");
|
||
s = s.replace(/\*\*([^*]+)\*\*/g, "<strong>$1</strong>");
|
||
s = s.replace(/(^|[^*])\*([^*\s][^*]*)\*/g, "$1<em>$2</em>");
|
||
s = s.replace(/(^|\W)_([^_\s][^_]*)_(?=\W|$)/g, "$1<em>$2</em>");
|
||
s = s.replace(/\[([^\]]+)\]\((https?:\/\/[^)\s]+|\/[^)\s]*)\)/g, function (_m, t, u) {
|
||
return '<a href="#" data-href="' + u + '">' + t + "</a>";
|
||
});
|
||
return s;
|
||
}
|
||
function md(src) {
|
||
var lines = String(src || "").replace(/\r/g, "").split("\n");
|
||
var out = [], i = 0, list = null;
|
||
function closeList() { if (list) { out.push("</" + list + ">"); list = null; } }
|
||
while (i < lines.length) {
|
||
var l = lines[i];
|
||
var fence = l.match(/^\s*```/);
|
||
if (fence) {
|
||
closeList();
|
||
var buf = []; i++;
|
||
while (i < lines.length && !/^\s*```/.test(lines[i])) { buf.push(lines[i]); i++; }
|
||
i++;
|
||
out.push("<pre><code>" + esc(buf.join("\n")) + "</code></pre>");
|
||
continue;
|
||
}
|
||
var h = l.match(/^(#{1,6})\s+(.*)$/);
|
||
if (h) { closeList(); var n = Math.min(4, h[1].length); out.push("<h" + n + ">" + inline(h[2]) + "</h" + n + ">"); i++; continue; }
|
||
if (/^\s*\|/.test(l)) {
|
||
closeList();
|
||
var rows = [];
|
||
while (i < lines.length && /^\s*\|/.test(lines[i])) { rows.push(lines[i]); i++; }
|
||
var html = "<table>";
|
||
rows.forEach(function (r, k) {
|
||
var cells = r.trim().replace(/^\||\|$/g, "").split("|");
|
||
if (cells.every(function (c) { return /^\s*:?-+:?\s*$/.test(c); })) return;
|
||
var tag = k === 0 ? "th" : "td";
|
||
html += "<tr>" + cells.map(function (c) { return "<" + tag + ">" + inline(c.trim()) + "</" + tag + ">"; }).join("") + "</tr>";
|
||
});
|
||
out.push(html + "</table>");
|
||
continue;
|
||
}
|
||
var li = l.match(/^\s{0,3}([-*]|\d+[.)])\s+(.*)$/);
|
||
if (li) {
|
||
var kind = /\d/.test(li[1]) ? "ol" : "ul";
|
||
if (list !== kind) { closeList(); out.push("<" + kind + ">"); list = kind; }
|
||
var item = li[2]; i++;
|
||
while (i < lines.length && /^\s{2,}\S/.test(lines[i]) && !/^\s{0,3}([-*]|\d+[.)])\s+/.test(lines[i])) { item += " " + lines[i].trim(); i++; }
|
||
out.push("<li>" + inline(item) + "</li>");
|
||
continue;
|
||
}
|
||
if (/^>\s?/.test(l)) { closeList(); out.push("<blockquote>" + inline(l.replace(/^>\s?/, "")) + "</blockquote>"); i++; continue; }
|
||
if (!l.trim()) { closeList(); i++; continue; }
|
||
closeList();
|
||
var para = [l]; i++;
|
||
while (i < lines.length && lines[i].trim() && !/^(#{1,6}\s|\s*```|\s*\||\s{0,3}([-*]|\d+[.)])\s|>)/.test(lines[i])) { para.push(lines[i]); i++; }
|
||
out.push("<p>" + inline(para.join(" ")) + "</p>");
|
||
}
|
||
closeList();
|
||
return out.join("\n");
|
||
}
|
||
root.addEventListener("click", function (e) {
|
||
var a = e.target.closest && e.target.closest("a[data-href]");
|
||
if (!a) return;
|
||
e.preventDefault();
|
||
var href = a.getAttribute("data-href");
|
||
if (href.charAt(0) === "/") A.navigate(href);
|
||
else window.open(href, "_blank", "noopener");
|
||
});
|
||
|
||
// Reads go through the host's query (cached answer at once, then the fresh
|
||
// one; the header's refresh button re-runs them). Older hosts: an action.
|
||
function read(name, payload, cb) {
|
||
if (A.query) return A.query(name, payload || {}, cb);
|
||
var live = true;
|
||
function run() {
|
||
return A.action(name, payload || {}).then(
|
||
function (d) { if (live) cb(d, { fromCache: false, fetching: false, at: Date.now() }); },
|
||
function (e) { if (live) cb(null, { error: String((e && e.message) || e), fromCache: false, fetching: false, at: Date.now() }); });
|
||
}
|
||
run();
|
||
return { stop: function () { live = false; }, refresh: run };
|
||
}
|
||
// The app's header carries the subtitle and the page's buttons; an older
|
||
// host has none, so the page then draws its own back link / Implement.
|
||
var NATIVE = !!(A && A.setHeader);
|
||
function setHeader(h) { if (NATIVE) A.setHeader(h); }
|
||
var headerCb = null;
|
||
if (A && A.onHeaderAction) A.onHeaderAction(function (id) { if (headerCb) headerCb(id); });
|
||
function act(name, payload) { return A.action(name, payload || {}); }
|
||
function toList() { A.navigate("/plugins/plans/plans"); }
|
||
|
||
// ── gallery ────────────────────────────────────────────────────────────
|
||
var state = { q: "", status: "", repo: "", plans: null };
|
||
function repos(p) { // a repo that is both a project and a service counts once
|
||
return (p.projects || []).concat(p.services || []).filter(function (x, i, all) { return all.indexOf(x) === i; });
|
||
}
|
||
function el(id) { return document.getElementById(id); }
|
||
function mountGallery() {
|
||
// The toolbar is drawn once: a fresh answer never steals the search box's focus.
|
||
root.innerHTML = '<div class="aia-toolbar"><input class="aia-input search" id="q" type="search" placeholder="Search plans…" autocomplete="off"/>' +
|
||
'<span class="aia-small aia-muted" id="shown"></span></div>' +
|
||
'<div class="aia-row pills" id="statuses"></div><div class="aia-row pills" id="repos"></div>' +
|
||
'<div id="list"></div>';
|
||
el("q").addEventListener("input", function () { state.q = el("q").value; renderGallery(); });
|
||
root.addEventListener("click", function (e) {
|
||
var b = e.target.closest && e.target.closest("[data-status],[data-repo],.plan[data-slug]");
|
||
if (!b) return;
|
||
if (b.hasAttribute("data-status")) { state.status = b.getAttribute("data-status"); renderGallery(); }
|
||
else if (b.hasAttribute("data-repo")) { var r = b.getAttribute("data-repo"); state.repo = state.repo === r ? "" : r; renderGallery(); }
|
||
else A.navigate("/plugins/plans/plans/" + encodeURIComponent(b.getAttribute("data-slug")));
|
||
});
|
||
}
|
||
function chip(label, n, on, attr) {
|
||
return '<button class="aia-chip' + (on ? " aia-active" : "") + '" ' + attr + ">" + esc(label) +
|
||
'<span class="aia-count">' + n + "</span></button>";
|
||
}
|
||
function renderGallery() {
|
||
var all = state.plans || [];
|
||
var counts = {};
|
||
all.forEach(function (p) { counts[p.status] = (counts[p.status] || 0) + 1; });
|
||
var repoCount = {};
|
||
all.forEach(function (p) { repos(p).forEach(function (r) { repoCount[r] = (repoCount[r] || 0) + 1; }); });
|
||
var topRepos = Object.keys(repoCount).sort(function (a, b) { return repoCount[b] - repoCount[a]; }).slice(0, 14);
|
||
var q = state.q.toLowerCase();
|
||
var shown = all.filter(function (p) {
|
||
if (state.status && p.status !== state.status) return false;
|
||
if (state.repo && repos(p).indexOf(state.repo) < 0) return false;
|
||
if (q && (p.title + " " + p.slug + " " + repos(p).join(" ")).toLowerCase().indexOf(q) < 0) return false;
|
||
return true;
|
||
});
|
||
el("shown").textContent = shown.length === all.length ? "" : shown.length + " / " + all.length + " plans";
|
||
el("statuses").innerHTML = chip("All", all.length, !state.status, 'data-status=""') + STATUSES.map(function (s) {
|
||
return chip(s, counts[s] || 0, state.status === s, 'data-status="' + s + '"');
|
||
}).join("");
|
||
el("repos").innerHTML = topRepos.map(function (r) {
|
||
return chip(r, repoCount[r], state.repo === r, 'data-repo="' + esc(r) + '"');
|
||
}).join("");
|
||
el("repos").hidden = !topRepos.length;
|
||
if (!shown.length) {
|
||
el("list").innerHTML = all.length ? '<div class="aia-empty"><strong>No plan matches</strong>Try another search or filter.</div>'
|
||
: '<div class="aia-empty"><strong>No plans yet</strong>Ask Claude to plan a change (the <code>plan</code> skill).</div>';
|
||
} else {
|
||
el("list").innerHTML = '<div class="aia-grid grid">' + shown.map(cardHtml).join("") + "</div>";
|
||
}
|
||
var inProgress = counts["in-progress"] || 0;
|
||
setHeader({ subtitle: all.length + " plan" + (all.length === 1 ? "" : "s") + (inProgress ? " · " + inProgress + " in progress" : "") });
|
||
fit();
|
||
}
|
||
function cardHtml(p) {
|
||
var a = p.actual || null;
|
||
var h = '<div class="aia-card aia-link plan" data-slug="' + esc(p.slug) + '">';
|
||
h += '<div class="head"><div class="aia-title">' + esc(p.title) + "</div>" + badge(p.status) + "</div>";
|
||
h += '<div class="aia-muted aia-small">' + esc(p.created || (p.updatedAt || "").slice(0, 10)) + " · " + esc(p.slug) + "</div>";
|
||
h += '<div class="stats aia-muted">';
|
||
h += '<span class="stat">cost <b class="mono">' + fmtCost(p.estCost) + "</b>" +
|
||
(a ? ' → <b class="mono ' + cmp(p.estCost, a.cost) + '">' + fmtCost(a.cost) + "</b>" : "") + "</span>";
|
||
h += '<span class="stat">time <b class="mono">' + fmtMin(p.estTimeMinutes) + "</b>" +
|
||
(a && a.durationMs ? ' → <b class="mono ' + cmp(p.estTimeMinutes, msToMin(a.durationMs)) + '">' + fmtMin(msToMin(a.durationMs)) + "</b>" : "") + "</span>";
|
||
h += '<span class="stat"><b>' + (p.steps || 0) + "</b> steps</span>";
|
||
h += '<span class="stat"><b>' + (p.files || 0) + "</b> files</span>";
|
||
if (p.questions) h += '<span class="stat">' + (p.answered ? "✓ answered" : "<b>" + p.questions + "</b> questions") + "</span>";
|
||
h += "</div>";
|
||
var r = repos(p);
|
||
if (r.length) h += '<div class="tags">' + r.slice(0, 6).map(function (x) { return '<span class="aia-badge">' + esc(x) + "</span>"; }).join("") + "</div>";
|
||
return h + "</div>";
|
||
}
|
||
function loadGallery() {
|
||
setHeader({ subtitle: "" });
|
||
mountGallery();
|
||
read("list", { actuals: true }, function (res, meta) {
|
||
if (meta && meta.error && !res) {
|
||
if (state.plans == null) {
|
||
el("list").innerHTML = '<div class="aia-error">Couldn’t load plans: ' + esc(meta.error) + "</div>";
|
||
fit();
|
||
}
|
||
return;
|
||
}
|
||
state.plans = (res && res.plans) || [];
|
||
renderGallery();
|
||
});
|
||
}
|
||
|
||
// ── one plan ───────────────────────────────────────────────────────────
|
||
function implementPrompt(p) {
|
||
var s = "Implement the plan `data/plans/" + p.slug + ".md` — " + p.title + ".\n\n" +
|
||
"Read the plan file first and follow its steps. Set `status: in-progress` now and `status: done` " +
|
||
"when finished. (This conversation is already linked to the plan, so its actual cost joins the estimate.)";
|
||
if (p.answers && p.answers.lines && p.answers.lines.length) {
|
||
s += "\n\nDecisions from the plan's questions:\n" + p.answers.lines.join("\n");
|
||
}
|
||
return s;
|
||
}
|
||
var planQ = null, shownPlan = null, busy = false, planOpen = true;
|
||
function planHeader(p) {
|
||
setHeader({
|
||
subtitle: p ? p.status + " · " + (p.steps || 0) + " steps · " + (p.files || 0) + " files" : "",
|
||
actions: [
|
||
{ id: "back", label: "All plans", icon: "arrow-left" },
|
||
{ id: "implement", label: "Implement", icon: "play", primary: true, disabled: !p }
|
||
]
|
||
});
|
||
}
|
||
function renderPlan(p) {
|
||
shownPlan = p;
|
||
planHeader(p);
|
||
var a = p.actual || null;
|
||
var h = NATIVE ? "" : '<div class="aia-toolbar"><a data-back>← Plans</a><span class="aia-spacer"></span>' +
|
||
'<button class="aia-btn aia-btn-primary" id="implement">Implement</button></div>';
|
||
h += '<div class="detail-head"><h1>' + esc(p.title) + "</h1>";
|
||
h += '<select class="aia-select" id="status" aria-label="Status">' + STATUSES.map(function (s) {
|
||
return '<option value="' + s + '"' + (s === p.status ? " selected" : "") + ">" + s + "</option>";
|
||
}).join("") + "</select></div>";
|
||
h += '<div class="aia-muted aia-small" style="margin-top:4px">' + esc(p.created || "") + " · <span class=\"mono\">data/plans/" + esc(p.slug) + ".md</span>" +
|
||
(repos(p).length ? " · " + repos(p).map(esc).join(", ") : "") + '</div><div class="aia-error" id="err"></div>';
|
||
|
||
h += '<div class="aia-card sec"><h3 class="aia-section">Estimated vs actual</h3><div class="metrics">';
|
||
h += metric("Cost", fmtCost(p.estCost), a ? fmtCost(a.cost) : null, cmp(p.estCost, a && a.cost),
|
||
p.estCostContinue != null ? "continue: " + fmtCost(p.estCostContinue) : "");
|
||
h += metric("Time", fmtMin(p.estTimeMinutes), a && a.durationMs ? fmtMin(msToMin(a.durationMs)) : null,
|
||
cmp(p.estTimeMinutes, a && msToMin(a.durationMs)));
|
||
h += metric("Tokens", fmtTokens(p.estTokens), a ? fmtTokens(a.tokens) : null, cmp(p.estTokens, a && a.tokens));
|
||
h += metric("Steps", String(p.steps || 0), null, "", (p.files || 0) + " files");
|
||
h += "</div>";
|
||
var convs = p.conversations || [];
|
||
if (convs.length) {
|
||
h += '<div style="margin-top:10px">' + convs.map(function (c) {
|
||
return '<div class="conv"><a data-href="/conversation/' + encodeURIComponent(c.id || c.sessionId) + '">' +
|
||
esc(c.title || c.sessionId) + '</a><span class="aia-muted mono">' + fmtCost(c.cost) + " · " + fmtTokens(c.tokens) +
|
||
(c.durationMs ? " · " + fmtMin(msToMin(c.durationMs)) : "") + "</span></div>";
|
||
}).join("") + "</div>";
|
||
} else {
|
||
h += '<div class="aia-muted aia-small" style="margin-top:8px">No linked conversation found yet — actuals appear once its <code>sessionId</code> / <code>conversationIds</code> match a transcript.</div>';
|
||
}
|
||
h += "</div>";
|
||
|
||
if (p.questionForm || p.answers) {
|
||
var qf = p.questionForm;
|
||
var nq = qf ? qf.fields.filter(function (f) { return ["markdown", "html", "heading", "divider", "info"].indexOf(f.type) < 0; }).length : 0;
|
||
h += '<div class="aia-card sec"><h3 class="aia-section">Questions</h3>';
|
||
if (qf) h += "<div><b>" + esc(qf.title) + "</b>" + (qf.description ? ' <span class="aia-muted">— ' + esc(qf.description) + "</span>" : "") + '</div><div class="aia-muted aia-small">' + nq + " question" + (nq === 1 ? "" : "s") + "</div>";
|
||
if (p.answers && p.answers.lines && p.answers.lines.length) {
|
||
h += '<div class="md answers" style="margin-top:8px">' + md(p.answers.lines.join("\n")) + "</div>";
|
||
if (p.answers.at) h += '<div class="aia-muted aia-small">Answered ' + esc(p.answers.at) + "</div>";
|
||
}
|
||
if (qf) {
|
||
var f = p.askForm;
|
||
var label = p.answers ? "Re-answer questions" : f && f.status === "pending" ? "Continue answering" : "Answer questions";
|
||
h += '<div class="aia-row" style="margin-top:8px"><button class="aia-btn' + (p.answers ? "" : " aia-btn-primary") + '" id="answer">' + label + "</button>";
|
||
if (f && f.status) h += '<span class="aia-muted aia-small">form ' + esc(f.status) + "</span>";
|
||
h += "</div>";
|
||
}
|
||
h += "</div>";
|
||
}
|
||
|
||
if ((p.fileList || []).length) {
|
||
h += '<div class="aia-card sec"><h3 class="aia-section">Files changed (' + p.fileList.length + ')</h3><table class="aia-table"><tr><th>file</th><th>change</th></tr>' +
|
||
p.fileList.map(function (f) { return '<tr><td class="file">' + esc(f.file) + "</td><td>" + inline(f.change) + "</td></tr>"; }).join("") + "</table></div>";
|
||
}
|
||
if ((p.stepList || []).length) {
|
||
h += '<div class="aia-card sec"><h3 class="aia-section">Steps (' + p.stepList.length + ')</h3><ol class="steps">' +
|
||
p.stepList.map(function (s) { return "<li><b>" + esc(s.title) + "</b>" + (s.detail ? '<div class="d">' + inline(s.detail) + "</div>" : "") + "</li>"; }).join("") + "</ol></div>";
|
||
}
|
||
h += '<div class="aia-card sec"><details' + (planOpen ? " open" : "") + ' id="body"><summary>Plan</summary><div class="md">' + md(p.content) + "</div></details></div>";
|
||
root.innerHTML = h;
|
||
|
||
el("body").addEventListener("toggle", function () { planOpen = el("body").open; });
|
||
var back = root.querySelector("[data-back]");
|
||
if (back) back.addEventListener("click", function (e) { e.preventDefault(); toList(); });
|
||
var imp = el("implement");
|
||
if (imp) imp.addEventListener("click", function () { A.openComposer({ prompt: implementPrompt(p) }); });
|
||
var errEl = el("err");
|
||
var sel = el("status");
|
||
sel.addEventListener("change", function () {
|
||
sel.disabled = true; errEl.textContent = ""; busy = true;
|
||
act("set_status", { slug: p.slug, status: sel.value }).then(function () {
|
||
p.status = sel.value;
|
||
planHeader(p);
|
||
busy = false;
|
||
if (planQ) planQ.refresh();
|
||
}).catch(function (e) {
|
||
busy = false;
|
||
sel.value = p.status; errEl.textContent = e.message || String(e);
|
||
}).then(function () { sel.disabled = false; });
|
||
});
|
||
var ab = el("answer");
|
||
if (ab) ab.addEventListener("click", function () {
|
||
ab.disabled = true; errEl.textContent = "";
|
||
act("open_questions", { slug: p.slug, reopen: !!p.answers }).then(function (r) {
|
||
if (!r || !r.formId) throw new Error("no form returned");
|
||
if (planQ) planQ.refresh(); // the plan now names its form
|
||
return A.openForm(r.formId);
|
||
}).catch(function (e) { errEl.textContent = e.message || String(e); })
|
||
.then(function () { ab.disabled = false; });
|
||
});
|
||
fit();
|
||
}
|
||
function metric(k, est, actual, cls, extra) {
|
||
return '<div class="metric"><div class="k">' + esc(k) + '</div><div class="v mono">' + esc(est) + "</div>" +
|
||
(actual != null ? '<div class="a mono ' + (cls || "") + '">actual ' + esc(actual) + "</div>" : '<div class="a aia-muted">' + esc(extra || "estimated") + "</div>") +
|
||
(actual != null && extra ? '<div class="a aia-muted">' + esc(extra) + "</div>" : "") + "</div>";
|
||
}
|
||
function loadPlan(slug) {
|
||
headerCb = function (id) {
|
||
if (id === "back") toList();
|
||
else if (id === "implement" && shownPlan) A.openComposer({ prompt: implementPrompt(shownPlan) });
|
||
};
|
||
planHeader(null);
|
||
planQ = read("get", { slug: slug }, function (p, meta) {
|
||
if (meta && meta.error && !p) {
|
||
if (shownPlan) return; // keep the plan already shown
|
||
root.innerHTML = (NATIVE ? "" : '<div class="aia-toolbar"><a data-back>← Plans</a></div>') +
|
||
(/not found/i.test(meta.error) ? '<div class="aia-empty"><strong>No plan called “' + esc(slug) + '”</strong>It may have been renamed or deleted.</div>'
|
||
: '<div class="aia-error">Couldn’t load the plan: ' + esc(meta.error) + "</div>");
|
||
var back = root.querySelector("[data-back]");
|
||
if (back) back.addEventListener("click", function (e) { e.preventDefault(); toList(); });
|
||
fit();
|
||
return;
|
||
}
|
||
if (!p || busy) return; // a write in flight: its refresh brings the answer
|
||
renderPlan(p);
|
||
});
|
||
}
|
||
|
||
var sub = String(init.subpath || "").replace(/^\/+|\/+$/g, "");
|
||
if (sub) loadPlan(decodeURIComponent(sub.split("/")[0])); else loadGallery();
|
||
})();
|
||
</script>
|
||
</body>
|
||
</html>
|