Skip to content

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

Rust
8.1 KB
Raw Blame
{% extends "base.html" %}

{% block title %}Search: {{ query }} — ai-memory{% endblock %}

{% block content %}
<nav aria-label="Breadcrumb" class="mb-6 flex items-center gap-1 text-sm text-slate-500 dark:text-slate-400">
  <a href="." class="hover:text-blue-600 dark:hover:text-blue-400">home</a>
  <span aria-hidden="true">/</span>
  {% if self.scoped() %}
  <a href="{{ project_href }}" class="hover:text-blue-600 dark:hover:text-blue-400">{{ workspace }}/{{ project }}</a>
  <span aria-hidden="true">/</span>
  {% endif %}
  <span aria-current="page" class="text-slate-700 dark:text-slate-200 font-medium">search</span>
</nav>

<div class="mb-6">
  <h1 class="text-2xl font-bold text-slate-900 dark:text-slate-100">
    {% if query != "" %}
    Search: <span class="text-blue-600 dark:text-blue-400">{{ query }}</span>
    {% else %}
    Search
    {% endif %}
  </h1>
  {% if self.scoped() %}
  <p class="mt-2 text-sm">
    <span class="inline-flex items-center gap-1 rounded-full bg-slate-100 dark:bg-slate-800 pl-3 pr-1 py-0.5 text-slate-700 dark:text-slate-300">
      in {{ workspace }}/{{ project }}
      <a href="{{ global_href }}" aria-label="Search every project" class="rounded-full px-1.5 hover:bg-slate-200 dark:hover:bg-slate-700">×</a>
    </span>
  </p>
  {% endif %}
</div>

<form action="search" method="get" class="mb-8 flex flex-wrap items-center gap-2">
  <label for="search-scope" class="sr-only">Search in</label>
  <select
    id="search-scope"
    name="scope"
    class="rounded-md border border-slate-300 dark:border-slate-700 bg-white dark:bg-slate-900 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
  >
    <option value=""{% if !self.scoped() %} selected{% endif %}>All projects</option>
    {% for group in scope_groups %}
    <optgroup label="{{ group.workspace }}">
      {% for option in group.projects %}
      <option value="{{ option.value }}"{% if option.selected %} selected{% endif %}>{{ option.label }}</option>
      {% endfor %}
    </optgroup>
    {% endfor %}
  </select>
  <label for="search-kind" class="sr-only">Kind</label>
  <select
    id="search-kind"
    name="kind"
    class="rounded-md border border-slate-300 dark:border-slate-700 bg-white dark:bg-slate-900 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
  >
    <option value="">Any kind</option>
    {% for option in kind_options %}
    <option value="{{ option.value }}"{% if option.selected %} selected{% endif %}>{{ option.value }}</option>
    {% endfor %}
  </select>
  <label for="search-tier" class="sr-only">Tier</label>
  <select
    id="search-tier"
    name="tier"
    class="rounded-md border border-slate-300 dark:border-slate-700 bg-white dark:bg-slate-900 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
  >
    <option value="">Any tier</option>
    {% for option in tier_options %}
    <option value="{{ option.value }}"{% if option.selected %} selected{% endif %}>{{ option.value }}</option>
    {% endfor %}
  </select>
  <label for="search-q" class="sr-only">Search pages</label>
  <input
    id="search-q"
    name="q"
    type="search"
    value="{{ query }}"
    placeholder="Search pages…"
    class="flex-1 max-w-md rounded-md border border-slate-300 dark:border-slate-700 bg-white dark:bg-slate-900 px-3 py-2 text-sm placeholder-slate-500 dark:placeholder-slate-400 focus:outline-none focus:ring-2 focus:ring-blue-500"
  >
  <label class="flex items-center gap-1 text-sm text-slate-600 dark:text-slate-400">
    <input type="checkbox" name="explain" value="1"{% if explain %} checked{% endif %}>
    Explain ranking
  </label>
  <button type="submit" class="rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white hover:bg-blue-700">
    Search
  </button>
</form>

{% if explain && query != "" %}
<section class="mb-8 rounded-md border border-slate-200 dark:border-slate-800 p-4 text-sm" aria-label="Recall trace">
  <h2 class="text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400 mb-2">Recall trace</h2>
  {% if self.scoped() %}
  <p class="text-slate-600 dark:text-slate-400">Hybrid ranker (the one <code>memory_query</code> uses for a project). Streams: <span class="font-mono">{{ streams_active }}</span></p>
  <p class="text-slate-600 dark:text-slate-400">Embedder: <span class="font-mono">{{ embedder }}</span> · Reranker: <span class="font-mono">{{ reranker }}</span></p>
  {% else %}
  <p class="text-slate-600 dark:text-slate-400">Cross-project search is FTS5 only, like <code>memory_query(global=true)</code>, so hits carry no per-stream details. Search from a project page to see the full trace.</p>
  {% endif %}
  {% if !timings.is_empty() %}
  <table class="mt-3 text-xs">
    <thead><tr><th class="pr-4 text-left font-medium text-slate-500">Stream</th><th class="text-right font-medium text-slate-500">ms</th></tr></thead>
    <tbody>
      {% for t in timings %}
      <tr><td class="pr-4 font-mono">{{ t.stream }}</td><td class="text-right font-mono">{{ t.ms }}</td></tr>
      {% endfor %}
    </tbody>
  </table>
  {% endif %}
</section>
{% endif %}

{% if query == "" %}
<p class="text-sm text-slate-500 dark:text-slate-400">Enter a search term above.</p>
{% else if hits.is_empty() %}
<p class="text-sm text-slate-500 dark:text-slate-400">No results for <strong>{{ query }}</strong>{% if filtered %} with these filters{% endif %}.
  {% if unknown_kind != "" %}<code>{{ unknown_kind }}</code> is not a standard page kind; check the spelling.{% endif %}
  {% if self.scoped() %}
  <a href="{{ global_href }}" class="ml-2 inline-block rounded-md border border-slate-300 dark:border-slate-700 px-3 py-1 text-slate-700 dark:text-slate-300 hover:bg-slate-50 dark:hover:bg-slate-900">Search all projects</a>
  {% endif %}
</p>
{% else %}
{% if truncated %}
<p class="text-sm text-slate-500 dark:text-slate-400 mb-4">Showing the first {{ max_results }} results. Refine your search to narrow them.</p>
{% else %}
<p class="text-sm text-slate-500 dark:text-slate-400 mb-4">{{ hit_count }} result{% if hit_count != 1 %}s{% endif %}</p>
{% endif %}
<ul class="divide-y divide-slate-100 dark:divide-slate-800">
  {% for hit in hits %}
  <li class="py-4" data-hit-path="{{ hit.path }}">
    <a href="{{ hit.href }}"
       class="text-base font-medium text-blue-700 dark:text-blue-400 hover:underline block mb-1">
      {{ hit.title }}
    </a>
    <div class="text-sm text-slate-600 dark:text-slate-400 mb-1">{{ hit.snippet|safe }}</div>
    <div class="text-xs text-slate-500 dark:text-slate-400">{{ hit.workspace }}/{{ hit.project }} · {{ hit.path }}</div>
    {% if let Some(trace) = hit.trace %}
    <div class="mt-2 overflow-x-auto" data-trace>
      <p class="text-xs text-slate-500 dark:text-slate-400">#{{ trace.position }} · rank <span class="font-mono">{{ trace.rank }}</span> · fused <span class="font-mono">{{ trace.fused }}</span> · authority <span class="font-mono">{{ trace.authority }}</span>{% if let Some(boost) = trace.intent_boost %} · intent boost <span class="font-mono">{{ boost }}</span>{% endif %}{% if let Some(score) = trace.rerank_score %} · rerank <span class="font-mono">{{ score }}</span>{% endif %}</p>
      <table class="mt-1 text-xs">
        <thead><tr><th class="pr-4 text-left font-medium text-slate-500">Stream</th><th class="pr-4 text-right font-medium text-slate-500">Rank</th><th class="pr-4 text-right font-medium text-slate-500">Raw score</th><th class="text-right font-medium text-slate-500">RRF</th></tr></thead>
        <tbody>
          {% for row in trace.streams %}
          <tr><td class="pr-4 font-mono">{{ row.stream }}</td><td class="pr-4 text-right font-mono">{{ row.rank }}</td><td class="pr-4 text-right font-mono">{{ row.raw }}</td><td class="text-right font-mono">{{ row.rrf }}</td></tr>
          {% endfor %}
        </tbody>
      </table>
      {% if trace.matched_entities != "" %}<p class="text-xs text-slate-500 dark:text-slate-400">Matched entities: {{ trace.matched_entities }}</p>{% endif %}
      {% if let Some(via) = trace.graph_via %}<p class="text-xs text-slate-500 dark:text-slate-400">Reached through: {{ via }}</p>{% endif %}
    </div>
    {% endif %}
  </li>
  {% endfor %}
</ul>
{% endif %}
{% endblock %}