Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust
9.4 KB
Raw Blame
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="referrer" content="no-referrer">
<title>ai-memory setup</title>
<style nonce="__NONCE__">
:root {
  --bg: #fafaf9; --fg: #1c1917; --muted: #57534e; --line: #e7e5e4;
  --card: #ffffff; --accent: #0f766e; --accent-fg: #ffffff; --bad: #b91c1c; --good: #15803d;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1917; --fg: #f5f5f4; --muted: #a8a29e; --line: #44403c;
    --card: #292524; --accent: #2dd4bf; --accent-fg: #042f2e; --bad: #f87171; --good: #4ade80;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.5 system-ui, sans-serif; }
main { max-width: 760px; margin: 0 auto; padding: 32px 16px 64px; }
h1 { font-size: 24px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
p.lead { color: var(--muted); margin: 0 0 24px; }
section { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; margin-bottom: 16px; }
code, pre { font-family: var(--mono); font-size: 13px; }
code { overflow-wrap: anywhere; }
dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; }
dt { color: var(--muted); }
dd { margin: 0; overflow-wrap: anywhere; }
label.agent { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-top: 1px solid var(--line); }
label.agent:first-of-type { border-top: 0; }
label.agent small { display: block; color: var(--muted); overflow-wrap: anywhere; }
details summary { cursor: pointer; color: var(--muted); margin-top: 8px; }
.others { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; }
.others label { display: inline-flex; gap: 6px; align-items: center; }
button { font: inherit; border: 0; border-radius: 8px; padding: 10px 18px; background: var(--accent); color: var(--accent-fg); cursor: pointer; }
button[disabled] { opacity: .5; cursor: default; }
button.secondary { background: transparent; color: var(--fg); border: 1px solid var(--line); }
.actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.note { color: var(--muted); font-size: 13px; }
pre#log { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 12px; max-height: 360px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; margin: 12px 0 0; }
.result { font-weight: 600; margin-top: 12px; }
.result.ok { color: var(--good); }
.result.bad { color: var(--bad); }
.question { font-family: var(--mono); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; display: inline-block; margin-top: 6px; }
[hidden] { display: none !important; }
</style>
</head>
<body>
<main>
  <h1>ai-memory setup</h1>
  <p class="lead">Check the plan, choose your agents, and apply. Nothing changes until you press Apply.</p>
  <p id="loading" class="note">Loading the plan…</p>
  <p id="failed" class="result bad" hidden></p>

  <div id="plan" hidden>
    <section>
      <h2>Install</h2>
      <dl>
        <dt>Data dir</dt><dd><code id="data-dir"></code></dd>
        <dt>Config</dt><dd><code id="config-path"></code></dd>
        <dt>State</dt><dd id="fresh"></dd>
        <dt>Service</dt><dd id="service"></dd>
      </dl>
    </section>

    <section>
      <h2>Agents</h2>
      <div id="agents"></div>
      <p id="no-agents" class="note" hidden>No agent was detected. Pick one below.</p>
      <details id="others-box">
        <summary>Other supported agents</summary>
        <div class="others" id="others"></div>
      </details>
    </section>

    <section>
      <div class="actions">
        <button id="apply" type="button">Apply</button>
        <span class="note">Runs <code>ai-memory setup --yes</code> with the agents you picked, then checks the result.</span>
      </div>
      <pre id="log" hidden></pre>
      <div id="outcome" hidden>
        <p id="result" class="result"></p>
        <p id="next" hidden>Restart <span id="restart"></span>, then ask it:<br><span class="question" id="question"></span></p>
      </div>
      <div class="actions" id="finish-row" hidden>
        <button id="finish" class="secondary" type="button">Finish and close the setup server</button>
      </div>
    </section>
  </div>
  <p id="closed" class="note" hidden>The setup server has stopped. You can close this tab.</p>
</main>
<script nonce="__NONCE__">
(function () {
  "use strict";
  var base = location.pathname.replace(/\/?$/, "/");
  var csrf = "";
  var $ = function (id) { return document.getElementById(id); };
  var text = function (id, value) { $(id).textContent = value; };

  function describeFound(found) {
    if (!found) return "named on the command line";
    var what = { session_store: "session store", mcp_config: "MCP config", config_dir: "directory" }[found.kind] || found.kind;
    return "found its " + what + " at " + found.path;
  }

  function wiring(value) {
    return { plugin: "left to its enabled ai-memory plugin", "mcp+hooks+skills": "MCP + hooks + skills", "hooks+skills": "hooks + skills" }[value] || value;
  }

  function checkbox(name, checked) {
    var box = document.createElement("input");
    box.type = "checkbox";
    box.name = "agent";
    box.value = name;
    box.checked = checked;
    return box;
  }

  function render(doc) {
    var plan = doc.plan;
    csrf = doc.csrf;
    text("data-dir", plan.data_dir);
    text("config-path", plan.config_path);
    text("fresh", plan.fresh ? "new install: creates the data dir, the config and a root bearer token" : "existing install: kept as it is");
    text("service", plan.service.action === "install"
      ? "install and start a " + plan.service.manager + " at " + plan.service.path
      : plan.service.reason);
    var agents = $("agents");
    plan.agents.forEach(function (agent) {
      var label = document.createElement("label");
      label.className = "agent";
      var body = document.createElement("span");
      var name = document.createElement("strong");
      name.textContent = agent.agent;
      var detail = document.createElement("small");
      detail.textContent = wiring(agent.wiring) + "; " + describeFound(agent.found);
      body.appendChild(name);
      body.appendChild(detail);
      label.appendChild(checkbox(agent.agent, true));
      label.appendChild(body);
      agents.appendChild(label);
    });
    $("no-agents").hidden = plan.agents.length > 0;
    if (plan.agents.length === 0) $("others-box").open = true;
    var others = $("others");
    plan.other_agents.forEach(function (name) {
      var label = document.createElement("label");
      label.appendChild(checkbox(name, false));
      label.appendChild(document.createTextNode(name));
      others.appendChild(label);
    });
    text("question", plan.first_question);
    $("loading").hidden = true;
    $("plan").hidden = false;
  }

  function fail(message) {
    $("failed").textContent = message;
    $("failed").hidden = false;
  }

  function post(path, body) {
    return fetch(base + path, {
      method: "POST",
      headers: { "content-type": "application/json", "x-ai-memory-setup": csrf },
      body: JSON.stringify(body || {})
    });
  }

  function chosen() {
    return Array.prototype.slice.call(document.querySelectorAll("input[name=agent]:checked"))
      .map(function (box) { return box.value; });
  }

  function poll(from) {
    fetch(base + "progress?from=" + from).then(function (r) { return r.json(); }).then(function (p) {
      var log = $("log");
      if (p.lines.length) {
        log.textContent += p.lines.join("\n") + "\n";
        log.scrollTop = log.scrollHeight;
      }
      if (!p.done) { setTimeout(function () { poll(p.next); }, 500); return; }
      $("outcome").hidden = false;
      var result = $("result");
      if (p.ok) {
        result.className = "result ok";
        result.textContent = "ai-memory is set up.";
        text("restart", p.agents.join(", "));
        $("next").hidden = p.agents.length === 0;
      } else {
        result.className = "result bad";
        result.textContent = "Setup finished with problems; see the lines starting with \"problem:\" above, fix them, and apply again.";
        $("apply").disabled = false;
      }
      $("finish-row").hidden = false;
    }).catch(function () { setTimeout(function () { poll(from); }, 1000); });
  }

  $("apply").addEventListener("click", function () {
    var agents = chosen();
    if (agents.length === 0) { fail("Pick at least one agent."); return; }
    $("failed").hidden = true;
    $("apply").disabled = true;
    $("log").hidden = false;
    $("log").textContent = "";
    $("outcome").hidden = true;
    post("apply", { agents: agents }).then(function (r) {
      if (r.status === 202) { poll(0); return; }
      return r.text().then(function (body) { fail(body || ("The server answered " + r.status)); $("apply").disabled = false; });
    }).catch(function () { fail("The setup server did not answer."); $("apply").disabled = false; });
  });

  $("finish").addEventListener("click", function () {
    post("finish").finally(function () {
      $("plan").hidden = true;
      $("closed").hidden = false;
    });
  });

  fetch(base + "plan").then(function (r) {
    if (!r.ok) throw new Error("status " + r.status);
    return r.json();
  }).then(render).catch(function (error) {
    $("loading").hidden = true;
    fail("Could not load the plan (" + error.message + "). Is `ai-memory setup --web` still running?");
  });
})();
</script>
</body>
</html>