loopctl-mcp-server 2.78.2 → 2.85.0

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/README.md CHANGED
@@ -135,6 +135,31 @@ autonomous agent) can self-remediate without a human. Full agent-tenant lifecycl
135
135
  > dynamically at runtime — see [Dynamic per-tenant Context Retriever
136
136
  > tools](#dynamic-per-tenant-context-retriever-tools-epic-30) below.
137
137
 
138
+ ### Design invariant: no model-visible `confirm`/`approved` argument
139
+
140
+ No loopctl MCP tool takes a `confirm`, `approved`, or `yes` argument. An argument
141
+ like that is authorization the model writes for itself: the same call that asks for
142
+ the mutation also carries its own approval, so nothing outside the caller ever sees
143
+ the proposal, and a model that decided to delete will also decide to confirm.
144
+
145
+ Set-based destructive actions therefore return a **proposal** instead. A dry-run
146
+ resolves the selector once, freezes that id-set server-side, and hands back a
147
+ single-use, TTL-bounded token; the caller replays the token to execute over exactly
148
+ the frozen set. Every property that matters follows from the shape rather than from
149
+ the caller's good behaviour: the executed set is the previewed set (rows that
150
+ started matching afterwards are never swept), the token is spendable once, it
151
+ expires, it is scoped to its tenant, and it is TYPED — by op AND by selector — so a
152
+ proposal for a reversible op cannot be replayed as an irreversible one, nor spent on
153
+ a selector it was not minted for. Selectors too large to freeze fall back to
154
+ re-confirm-on-drift, which re-resolves and refuses on any change rather than relaxing
155
+ the guarantee; its hash is keyed on the op, since with no token row it is the only
156
+ thing keeping the two flows apart. `knowledge_bulk_delete` is the surface this governs today,
157
+ on both its hard-delete path and its `tag` archive path.
158
+
159
+ The pattern is borrowed from MemoRizz, whose destructive MCP tools return a durable
160
+ single-use proposal the host approves out of band and never expose `approved` as a
161
+ tool parameter.
162
+
138
163
  ### Project Tools
139
164
 
140
165
  | Tool | Description |
@@ -243,6 +268,33 @@ Epic 39 Repo Coordination Bus — a lightweight, tenant-isolated channel for age
243
268
  | A search came back empty/thin, or you don't yet know what to ask | `knowledge_heat_index` (no query at all) |
244
269
  | Enumerate / dedup / repair, or "does X exist?" (full fields, lag-free, all-status) | `knowledge_list` |
245
270
 
271
+ **Read `meta.outcome` before you believe an empty result.** EVERY read on the knowledge,
272
+ memory and corpus surfaces carries one of `success` | `empty` | `degraded` | `fallback` |
273
+ `error`, so you never have to know which per-surface flag names a degradation — the
274
+ retrieval tools (`knowledge_search`, `knowledge_context`, `knowledge_hybrid_search`,
275
+ `knowledge_progressive_index`, `knowledge_heat_index`, `memory_recall`, `recall_context`,
276
+ `corpus_search`), the enumerations (`knowledge_list`, `knowledge_index`, `memory_list`,
277
+ `corpus_list`) and the review queues. On a catalog the value is only ever `empty` or
278
+ `success` — it discloses no degradation of its own — but the KEY is there, so an ABSENT
279
+ `outcome` means one thing and one thing only: a server older than this envelope.
280
+
281
+ | `meta.outcome` | what happened | what to do |
282
+ |---|---|---|
283
+ | `success` | ran fully; this page carries rows, or an earlier one did | use them |
284
+ | `empty` | ran fully and the whole matched set is empty | a real miss — re-route or accept it |
285
+ | `degraded` | a half was shed, capacity-limited or scan-starved | this set may be SHORT — wait, then retry (a STANDING gap — `ann_iterative_scan_unavailable` or `embedding_dimension_mismatch` — only an operator clears) |
286
+ | `fallback` | semantic ranking was unavailable, keyword-only was served | retry the SAME query, never reword |
287
+ | `error` | the retrieval could not run; an empty envelope was served in its place | fix the request, then retry |
288
+
289
+ Precedence is `error > fallback > degraded > empty > success`, so a degradation is never
290
+ hidden behind a zero count. On `knowledge_search`, `knowledge_hybrid_search` and
291
+ `knowledge_context` the MCP server also prints a leading banner for the three classes that
292
+ need a remedy; `empty` and `success` are silent by design. Since 2.85.0 the banner also
293
+ fires on `knowledge_list`, `knowledge_progressive_index`, `knowledge_heat_index`,
294
+ `memory_recall`, `recall_context` and `corpus_search`, so every read that can report a
295
+ degradation now announces one. Write tools carry no `outcome`. A page walked past the end of a non-empty set is `success`, not `empty`:
296
+ exhausting a paginated walk is not the same as the row being absent.
297
+
246
298
  | Tool | Description |
247
299
  |---|---|
248
300
  | `knowledge_index` | Browse/paginate the knowledge wiki catalog grouped by category. **Agent callers see only articles they own or marked `shared`.** Honors `category`, `tags`, `offset`, `limit` with deterministic ordering over the filtered set (`meta.categories` reports per-category totals within visibility). Use `fields` (default `id,title,category`; request `tags`/`status`/`updated_at` explicitly; `id` and `category` are always included) to keep the payload small. Optional: `project_id`, `story_id`, `category`, `tags`, `offset`, `limit`, `fields`. |
@@ -252,14 +304,14 @@ Epic 39 Repo Coordination Bus — a lightweight, tenant-isolated channel for age
252
304
  | `knowledge_stats` | Aggregate article counts (`total`, `by_category`, `by_status`) via cheap `COUNT(*) GROUP BY` within agent's visible set — no article metadata loaded. Agent callers see only their own and `shared` articles. Counts span all statuses. Optional: `project_id`. |
253
305
  | `knowledge_count` | Count articles matching filters **without returning rows** within agent's visible set. Agent callers see only their own and `shared` articles. Same filters as `knowledge_list` (`category`, `status`, `tags`, `match`, `source_type`, `source_id`, `idempotency_key`, `project_id`). With `tags`+`match: all` (+`status`) → "how many published articles tagged both X and Y (that I can see)". Returns `{ count }`. |
254
306
  | `knowledge_facets` | Count articles grouped by **distinct tag** within agent's visible set, no rows. Agent callers see only their own and `shared` articles. `tag_prefix` (e.g. `book-`) gives the distinct count of a tag family plus per-member totals. Returns `{ data: { tag: count }, meta: { distinct_count } }`. Optional: `category`, `status`, `tags`, `match`, `project_id`, `limit`. |
255
- | `knowledge_search` | Search the knowledge wiki by topic (keyword, semantic, or combined). Returns snippets. **Ranked, published-only, and LAGS writes by minutes while embeddings index — do NOT use for existence/idempotency/dedup checks (a fresh write false-negatives); use `knowledge_list` for that.** `query` (historically `q`, still accepted) is optional when `tags`/`category` are supplied — that **list mode** returns the complete filtered set paginated via `offset`/`limit` over `meta.total_count`. `meta.total_count` is mode-dependent — read `meta.total_count_scope` (`keyword_matches`/`ranked_corpus`/`merged_candidates`/`filtered_set`) and don't use a relevance-mode count to size the wiki (use `knowledge_list` or `knowledge_stats`). On the semantic/combined paths `meta.ann_iterative_scan` (`off`/`applied`/`unavailable`, with `meta.ann_iterative_scan_reason` alongside `unavailable`) discloses whether the vector read ran with pgvector's iterative scan — `unavailable` means results may be INCOMPLETE, which `meta.fallback` cannot tell you. Optional: `project_id`, `story_id` for attribution. |
256
- | `knowledge_hybrid_search` | Resolve a topic to a **single best answer with provenance** (US-31.4). Runs combined keyword+semantic over the full ranked pool, then decides whether a governed **curated** source actually answers. `meta.provenance` is `curated` (trust it — the canonical article is first in `data`, `meta.curated_article_id` points at it) or `retrieved` (best fuzzy match, `curated_article_id` null); `meta.confidence` is the winner's absolute score. Prefer over `knowledge_search` when you want one trustworthy answer, not a list to triage. Degrades to keyword-only like `knowledge_search` when embeddings are unavailable. Required: `query`. Optional: `project_id`, `category`, `tags`, `match`, `limit`, `offset`. |
257
- | `knowledge_progressive_index` | Progressive disclosure — a **cheap, capped index** of what's relevant to a topic (compact stubs: `id`/`title`/`category`/`summary`, **no bodies**), curated-preferred and hub-enriched, capped at top-K (`meta.truncated` when the pool exceeded it). Survey a topic without flooding context, then open only what you need via `knowledge_progressive_drill`. Required: `query` (historically `topic`, still accepted). Optional: `category`, `limit`. |
258
- | `knowledge_heat_index` | Browse the corpus with **no query at all** — capped compact stubs (`id`/`title`/`category`/`heat`/`summary`, **no bodies**) ranked by how many **distinct readers** (agents, not key rows — repeat reads by one reader count once, ties broken by the number of distinct days read, never by raw read count) opened each article inside a window. Every other retrieval tool starts from a query and so shares one failure mode: a paraphrase, or material topically central but lexically dissimilar to the question, comes back empty and reads as "the KB has nothing" rather than "I asked badly". Reach for it when a search came back empty or thin, or to survey what the fleet actually reads before you know what to ask. **Ordering is usage, not relevance**, and drilling a listed article (`knowledge_progressive_drill`) does not add heat to what it opened, at any scope — otherwise being shown would produce the rank that shows it. A `knowledge_get` of the same id does count. `meta` states `heat_window` (the default window is snapped to a UTC day boundary so the payload is stable between refreshes and safe in a cached prefix; an explicit `since` is served verbatim), `counted_access_types`, `char_budget`/`chars` (BYTES of the encoded stub array, framing included), `truncated` and `unresolved`. Both read tools open a stub, canonicals included — pick by what the read MEANS: a drill is uncounted, a `get` is a counted vote. Optional: `category`, `limit`, `since`. |
307
+ | `knowledge_search` | Search the knowledge wiki by topic (keyword, semantic, or combined). Returns snippets. **Ranked, published-only, and LAGS writes by minutes while embeddings index — do NOT use for existence/idempotency/dedup checks (a fresh write false-negatives); use `knowledge_list` for that.** `query` (historically `q`, still accepted) is optional when `tags`/`category` are supplied — that **list mode** returns the complete filtered set paginated via `offset`/`limit` over `meta.total_count`. `meta.total_count` is mode-dependent — read `meta.total_count_scope` (`keyword_matches`/`ranked_corpus`/`merged_candidates`/`filtered_set`) and don't use a relevance-mode count to size the wiki (use `knowledge_list` or `knowledge_stats`). On the semantic/combined paths `meta.ann_iterative_scan` (`off`/`applied`/`unavailable`, with `meta.ann_iterative_scan_reason` alongside `unavailable`) discloses whether the vector read ran with pgvector's iterative scan — `unavailable` means results may be INCOMPLETE, which `meta.fallback` cannot tell you. Optional: `project_id`, `story_id` for attribution. Carries `meta.outcome` (see the table above) — a `fallback` or `degraded` value means an empty page is not a miss. |
308
+ | `knowledge_hybrid_search` | Resolve a topic to a **single best answer with provenance** (US-31.4). Runs combined keyword+semantic over the full ranked pool, then decides whether a governed **curated** source actually answers. `meta.provenance` is `curated` (trust it — the canonical article is first in `data`, `meta.curated_article_id` points at it) or `retrieved` (best fuzzy match, `curated_article_id` null); `meta.confidence` is the winner's absolute score. Prefer over `knowledge_search` when you want one trustworthy answer, not a list to triage. Degrades to keyword-only like `knowledge_search` when embeddings are unavailable. Required: `query`. Optional: `project_id`, `category`, `tags`, `match`, `limit`, `offset`. Carries `meta.outcome` alongside `meta.provenance`: provenance says WHICH source answered, outcome says whether the retrieval that produced it ran healthily. |
309
+ | `knowledge_progressive_index` | Progressive disclosure — a **cheap, capped index** of what's relevant to a topic (compact stubs: `id`/`title`/`category`/`summary`, **no bodies**), curated-preferred and hub-enriched, capped at top-K (`meta.truncated` when the pool exceeded it). Survey a topic without flooding context, then open only what you need via `knowledge_progressive_drill`. Required: `query` (historically `topic`, still accepted). Optional: `category`, `limit`. Carries `meta.outcome`; this path discloses no degradation of its own, so an `empty` index really is an empty topic. |
310
+ | `knowledge_heat_index` | Browse the corpus with **no query at all** — capped compact stubs (`id`/`title`/`category`/`heat`/`summary`, **no bodies**) ranked by how many **distinct readers** (agents, not key rows — repeat reads by one reader count once, ties broken by the number of distinct days read, never by raw read count) opened each article inside a window. Every other retrieval tool starts from a query and so shares one failure mode: a paraphrase, or material topically central but lexically dissimilar to the question, comes back empty and reads as "the KB has nothing" rather than "I asked badly". Reach for it when a search came back empty or thin, or to survey what the fleet actually reads before you know what to ask. **Ordering is usage, not relevance**, and drilling a listed article (`knowledge_progressive_drill`) does not add heat to what it opened, at any scope — otherwise being shown would produce the rank that shows it. A `knowledge_get` of the same id does count. `meta` states `heat_window` (the default window is snapped to a UTC day boundary so the payload is stable between refreshes and safe in a cached prefix; an explicit `since` is served verbatim), `counted_access_types`, `char_budget`/`chars` (BYTES of the encoded stub array, framing included), `truncated` and `unresolved`. Both read tools open a stub, canonicals included — pick by what the read MEANS: a drill is uncounted, a `get` is a counted vote. Optional: `category`, `limit`, `since`. Carries `meta.outcome` like every other retrieval surface. |
259
311
  | `knowledge_progressive_drill` | Open one stub from `knowledge_progressive_index` or `knowledge_heat_index` — returns the **full article body** for the given id, scope-enforced. Resolves both tenant-owned articles and published system canonicals (the same set those indexes surface). Every article opened this way is recorded under an access type `knowledge_heat_index` does not count, whatever its scope, so that index can never rank on the reads it caused. `knowledge_get` reaches the same ids and DOES count — use it when the read is a deliberate vote rather than a step in following a list. Required: `article_id`. |
260
- | `knowledge_list` | List articles (`id`, `title`, `category`, `status`, `tags`, `source_type`, `source_id`, timestamps), filtered + paginated. **Body-less summary by default** (safe to page up to `limit=1000`); pass `include_body: true` to also return `body`, in which case the page is bounded by a ~5 MB byte budget — continue via `meta.next_offset` while `meta.has_more`. **Lag-free, all-status** read of the DB of record — unlike `knowledge_search` (ranked, published-only, lags writes) and `knowledge_index` (id/title/category only). The right tool to enumerate/dedup/repair and for idempotency/existence checks: filter by `tags`, `source_type`+`source_id`, or `idempotency_key` and read `meta.total_count` (exact) — `idempotency_key` is a FILTER only and is never returned in a row, so you check a key you already hold. Single full body → `knowledge_get`; relevant bodies → `knowledge_context`; bulk dump → `knowledge_export`. Optional: `project_id`, `category`, `status`, `tags`, `source_type`, `source_id`, `idempotency_key`, `offset`, `limit`, `include_body`. |
312
+ | `knowledge_list` | List articles (`id`, `title`, `category`, `status`, `tags`, `source_type`, `source_id`, timestamps), filtered + paginated. **Body-less summary by default** (safe to page up to `limit=1000`); pass `include_body: true` to also return `body`, in which case the page is bounded by a ~5 MB byte budget — continue via `meta.next_offset` while `meta.has_more`. **Lag-free, all-status** read of the DB of record — unlike `knowledge_search` (ranked, published-only, lags writes) and `knowledge_index` (id/title/category only). The right tool to enumerate/dedup/repair and for idempotency/existence checks: filter by `tags`, `source_type`+`source_id`, or `idempotency_key` and read `meta.total_count` (exact) — `idempotency_key` is a FILTER only and is never returned in a row, so you check a key you already hold. Single full body → `knowledge_get`; relevant bodies → `knowledge_context`; bulk dump → `knowledge_export`. Optional: `project_id`, `category`, `status`, `tags`, `source_type`, `source_id`, `idempotency_key`, `offset`, `limit`, `include_body`. Carries `meta.outcome`; on this lag-free enumeration path `empty` is load-bearing — the filtered set is genuinely empty, not missed by a ranker (a page past the end reads `success`). |
261
313
  | `knowledge_get` | Get full article content by ID. Use after search to read an article in detail. Resolves tenant-owned articles **and published system canonicals**, and records a COUNTED read (it feeds `knowledge_heat_index`) — reach for `knowledge_progressive_drill` instead when you are merely following an index this system just produced. Each link carries only its FAR side (`article: {id, title}`, plus `similarity` when scored); both arrays are ranked (open conflicts first, then descending similarity, then oldest-first for the unscored) and capped at 25 per direction, with `links_total` / `links_truncated` reporting the truth (`count` returns both, so one cheap call tells you whether the full fetch is capped). Pass `links: "count"` or `"none"` when you only want the text — on a well-linked hub the link block is several times the body. `potential_conflicts` is returned in all three modes, itself capped at 25 with `conflicts_total` / `conflicts_truncated`. Optional: `links`, `project_id`, `story_id` for attribution. |
262
- | `knowledge_context` | Get relevance-and-recency-ranked full articles for a task query. Best knowledge for your current context. **Agent-memory scoping**: `memory_types` (comma-separated, OR — observation/finding/summary/decision/question/task), `agents` (comma-separated agent_ids, OR), `conversation_id` (exact) filter on article `metadata` (JSONB `@>`). Optional: `project_id`, `story_id` for attribution, `limit`, `recency_weight`. |
314
+ | `knowledge_context` | Get relevance-and-recency-ranked full articles for a task query. Best knowledge for your current context. **Agent-memory scoping**: `memory_types` (comma-separated, OR — observation/finding/summary/decision/question/task), `agents` (comma-separated agent_ids, OR), `conversation_id` (exact) filter on article `metadata` (JSONB `@>`). Optional: `project_id`, `story_id` for attribution, `limit`, `recency_weight`. Carries `meta.outcome`, so an empty context pack is distinguishable from one whose underlying search fell back to keyword-only. |
263
315
  | `knowledge_graph` | Multi-hop traversal of the published article-link graph from `article_id` (depth 1–3, default 1), **bounded to agent's visible articles**. Agent callers see only their own and `shared` articles. Bidirectional, cycle-safe, bounded to 100 nodes / 500 edges (`truncated` flags a cap). Returns `nodes` (`id`/`title`/`category`/`depth`) + `edges` (`source_article_id`/`target_article_id`/`relationship_type`). Explore typed connections beyond `knowledge_context`'s 1-hop links. Required: `article_id`. Optional: `depth`, `project_id`. |
264
316
  | `knowledge_suggest_links` | Ranked typed-link **candidates** for an article by embedding similarity among **visible articles** — **read-only** (creates nothing). Excludes the article itself + any already-linked article (either direction, any type); only embedded published articles visible to the caller. Agent callers see only their own and `shared` articles. Returns `{id, title, category, similarity_score}` highest-first, to create as a **typed** link (relates_to/derived_from/contradicts/supersedes). `meta.ann_iterative_scan` (`off`/`applied`/`unavailable`, with `meta.ann_iterative_scan_reason` alongside `unavailable`) discloses whether the vector read ran with pgvector's iterative scan — `unavailable` means the list may be INCOMPLETE, which `meta.recall_truncated: false` does NOT cover, so do not read a short list as "no neighbours". Required: `article_id`. Optional: `threshold` (cosine floor 0–1, default 0.5), `limit` (default 5). |
265
317
  | `knowledge_distant_pairs` | Distant-but-bridgeable article pairs in the optimal-novelty embedding band (cosine distance, default 0.3–0.7) — the creative sweet spot. Sampled from **agent's visible published articles**; agent callers see only their own and `shared` articles. `bridge_path: true` requires a ≤2-hop link path. Returns `{a, b, distance}` pairs, paginated. Optional: `min_distance`, `max_distance`, `bridge_path`, `limit` (default 20, max 100), `offset`. |
@@ -286,11 +338,11 @@ it is enforced server-side and a no-op for a non-superadmin key — see below.)
286
338
  | Tool | Description |
287
339
  |---|---|
288
340
  | `memory_remember` | Write to your own working memory. `tier` selects the substrate: `long_term` (default; requires `text`, embedded asynchronously and later recalled by semantic similarity via `memory_recall`) or `session` (short-term; requires `session_id`, `content`, `expires_at` — pruned after expiry, not semantically recalled). Returns 201 with the stored memory. Optional: `confidence`, `tags`, `source_session_id`, `metadata` (long-term); `role` (session). |
289
- | `memory_recall` | Semantically recall your own long-term memories most similar to `query`. When embedding generation is unavailable the response degrades to a recent-first text match with `meta.fallback: true` and a stable `meta.reason` (score is `null` on that path) — check `meta.fallback` before treating a short/empty result as a genuinely empty scope. `meta.total_count`/`meta.underfilled` are also returned. On the semantic path `meta.ann_iterative_scan` (`off`/`applied`/`unavailable`, with `meta.ann_iterative_scan_reason` alongside `unavailable`) discloses whether the vector read ran with pgvector's iterative scan — `unavailable` means results may be INCOMPLETE, which `meta.fallback`/`meta.underfilled` cannot tell you. It is absent on the ILIKE fallback AND on an `include_superseded: true` recall (a bounded exact top-k, no index scan), so absence never means the fallback ran. Optional: `limit`, `include_superseded`. |
341
+ | `memory_recall` | Semantically recall your own long-term memories most similar to `query`. When embedding generation is unavailable the response degrades to a recent-first text match with `meta.fallback: true` and a stable `meta.reason` (score is `null` on that path) — check `meta.fallback` before treating a short/empty result as a genuinely empty scope. `meta.total_count`/`meta.underfilled` are also returned. On the semantic path `meta.ann_iterative_scan` (`off`/`applied`/`unavailable`, with `meta.ann_iterative_scan_reason` alongside `unavailable`) discloses whether the vector read ran with pgvector's iterative scan — `unavailable` means results may be INCOMPLETE, which `meta.fallback`/`meta.underfilled` cannot tell you. It is absent on the ILIKE fallback AND on an `include_superseded: true` recall (a bounded exact top-k, no index scan), so absence never means the fallback ran. Optional: `limit`, `include_superseded`. Carries `meta.outcome`, which is the one key to read here: a SHED read sets `meta.fallback: true` while serving no substitute lane, and is reported as `degraded` (wait, then retry), not `fallback`. |
290
342
  | `memory_list` | List your own long-term memories, newest first, paginated with `meta.total_count/limit/offset` (the true scoped count, never silently capped by `limit`). Optional: `limit`, `offset`, `include_superseded`, `all_subjects` (superadmin only; ignored for non-superadmin keys). |
291
343
  | `memory_forget` | Delete one of your own long-term memories by id. A foreign-subject, foreign-tenant, or unknown id returns 404 (no existence leak). Required: `id`. |
292
344
  | `memory_promote` | Call at session end to compile this session's short-term (`session`-tier) memory into durable `long_term` memory — unlike `memory_remember` (a single explicit write), this compiles the whole session in one shot; fire it once at session end, not per turn. Returns 202 with `{session_id, status: "enqueued"}` — promotion runs asynchronously, so the resulting memory is recallable via `memory_recall` only after the worker drains. You can only promote your own sessions (scope resolved server-side from your key). Required: `session_id`. |
293
- | `recall_context` | ONE round-trip returning the re-ranked `global ∪ active-project` union of long-term MEMORY **and** KNOWLEDGE for `query` — what you previously assembled by calling `memory_recall` and `knowledge_search` separately. Pass `project_id` (from `resolve_project`) to merge global with that project on both sides; absent → global-only. The knowledge half is combined-search *summaries* (not full bodies — use `knowledge_context` for those). Response carries merged `results` (each tagged `source: memory\|knowledge`) plus the untouched per-source `memory`/`knowledge` envelopes; `meta.degraded?` flags a one-sided degrade (the other side is still returned — never a 500). Each per-source envelope's `meta.ann_iterative_scan` describes only THAT half's vector read, and the two are resolved independently, so they may differ. A blank query, or one over 500 chars, is a `422` up front. Required: `query`. Optional: `project_id`, `limit`. |
345
+ | `recall_context` | ONE round-trip returning the re-ranked `global ∪ active-project` union of long-term MEMORY **and** KNOWLEDGE for `query` — what you previously assembled by calling `memory_recall` and `knowledge_search` separately. Pass `project_id` (from `resolve_project`) to merge global with that project on both sides; absent → global-only. The knowledge half is combined-search *summaries* (not full bodies — use `knowledge_context` for those). Response carries merged `results` (each tagged `source: memory\|knowledge`) plus the untouched per-source `memory`/`knowledge` envelopes; `meta.degraded?` flags a one-sided degrade (the other side is still returned — never a 500). Each per-source envelope's `meta.ann_iterative_scan` describes only THAT half's vector read, and the two are resolved independently, so they may differ. A blank query, or one over 500 chars, is a `422` up front. Required: `query`. Optional: `project_id`, `limit`. The top-level `meta.outcome` classifies the whole endpoint and the `memory` envelope carries its own; `meta.degraded_reason` names the strongest-remedy half when both degrade, and `meta.search_mode` names the lane that half actually served (`keyword_only`) or is `null` when it served nothing. |
294
346
  | `memory_graduate` | Graduate ONE of your long-term memories into a durable Knowledge Wiki article — the explicit, on-demand version of the hourly graduation sweep. Use when a private memory has proven valuable enough to become durable knowledge. **Visibility**: the graduated article stays **owner-visible** (`metadata.visibility: "owner"`, keyed to your subject) — discoverable by YOU, NOT peer-readable (graduation does not share a memory to teammates; `re_scope: "global"` widens only the project scope, not visibility). Scope is key-derived (you can only graduate your OWN memory; a foreign/unknown `memory_id` → 404). DEDUPED by the novelty gate: `data.verdict` is `created` (novel → published) or `gated_to_draft` (near-dup → review draft) with a new article (**201**), or `duplicate`/`deduplicated` (already represented → canonical article, nothing created) (**200**). By default the article inherits the memory's project scope; pass `re_scope: "global"` to promote a PROJECT memory to a tenant-wide article — only valid on its FIRST graduation, and only if the hourly sweep hasn't graduated it project-scoped first (`409` `already_graduated` otherwise). An already-graduated global memory re-graduates idempotently (**200**). `503` `gate_unavailable` if the embedding backend is down — retry later. Required: `memory_id`. Optional: `re_scope` (`inherit`\|`global`). |
295
347
 
296
348
  ### Knowledge Management Tools (orchestrator key)
@@ -303,7 +355,7 @@ it is enforced server-side and a no-op for a non-superadmin key — see below.)
303
355
  | `knowledge_bulk_unpublish` | **Requires `LOOPCTL_USER_KEY`.** Revert published articles to draft in bulk, partial-success style (mirror of `knowledge_bulk_publish`): per-id `unpublished`/`skipped` (already draft, or archived/superseded)/`not_found`/`errored`. No 100-id cap (auto-chunked, ≤5000); duplicates ignored; safe to retry. Not deleted (re-publish to restore; `knowledge_bulk_delete` to archive). `meta.count`/`meta.counts`/`meta.results` give the breakdown. Required: `article_ids` (array). |
304
356
  | `knowledge_archive` | Soft-delete an article (draft or published). Row retained for audit; hidden from all reads. **NOT reversible by you** — `:archived` is a TERMINAL status (no unarchive call, no outbound transition), so restoring one needs a user-role PATCH with an explicit status. Nothing is destroyed, but do not reach for this as an undoable action: for a retraction you can undo, use `knowledge_unpublish` and `knowledge_publish`. Agent role — KB-content curation, visibility-scoped (another agent's private/owner memory 404s). Required: `article_id`. |
305
357
  | `knowledge_delete` | Alias for `knowledge_archive` — DELETE verb on the REST API archives under the hood (soft delete: row retained and audited, but NOT reversible by any call you can make, since `:archived` is terminal — use `knowledge_unpublish` when you need an undoable retraction). Agent role. (Irreversible HARD delete is `knowledge_bulk_delete hard:true`, which stays `LOOPCTL_USER_KEY`.) Required: `article_id`. |
306
- | `knowledge_bulk_delete` | **Requires `LOOPCTL_USER_KEY`.** Bulk archive (default — non-destructive, but NOT reversible by any call: `:archived` is terminal and restoring needs a user-role PATCH) or IRREVERSIBLE hard-delete by selector. Provide exactly one selector: `article_ids` (list), `source_type`+`source_id` (every active article from a source), or `tag`+`confirm:true` (every active article with the tag — high blast radius). Default = set-based soft archive (idempotent; `meta.count`=archived, `meta.counts`/`meta.results` give the breakdown; ≤5000). **Dry-run** (`dry_run:true`) mutates nothing, returns `meta.would_affect` (with `hard:true` also a single-use `meta.token`, or `meta.confirm_hash` for oversized selectors). **Hard delete** (irreversible): dry-run with `hard:true` for a token, then call again with `hard:true`+`token` to FK-correctly delete the frozen id-set (links first, access events cascade). |
358
+ | `knowledge_bulk_delete` | **Requires `LOOPCTL_USER_KEY`.** Bulk archive (default — non-destructive, but NOT reversible by any call: `:archived` is terminal and restoring needs a user-role PATCH) or IRREVERSIBLE hard-delete by selector. Provide exactly one selector: `article_ids` (list), `source_type`+`source_id` (every active article from a source), or `tag` (every active article with the tag — high blast radius). **There is no `confirm` parameter** — a request carrying one is `400 confirm_removed`, never ignored; see the [Design invariant](#design-invariant-no-model-visible-confirmapproved-argument) below. Default = set-based soft archive (idempotent; `meta.count`=archived, `meta.counts`/`meta.results` give the breakdown; ≤5000); `article_ids` and `source` archive immediately. **Two-step** (the `tag` archive, and every hard delete): `dry_run:true` mutates nothing and returns `meta.would_affect` plus a single-use, TTL-bounded `meta.token` frozen over the previewed id-set; call again with the same selector plus that token to run the op over the FROZEN set — the selector is CHECKED, so a token minted for one tag is `400` on a call naming another. A call with neither is `400` (`dry_run_required` on the tag archive) unless the selector matches nothing, which stays a `200` no-op on either path. The archive and delete flows mint DIFFERENT token types, so an archive proposal is not spendable as a delete or the reverse. Oversized selectors get `meta.oversized`+`meta.confirm_hash` instead of a token — echo the hash back with the same selector and the server refuses on any drift; that hash is keyed on the op, so it does not cross flows either. Hard delete is FK-correct (links first, access events cascade). |
307
359
  | `knowledge_drafts` | List draft (unpublished) knowledge articles with pagination. Optional: `limit` (default 20, max 1000 — over-max → 400, no silent clamp), `offset` (default 0), `project_id`. Returns `meta.total_count`. |
308
360
  | `knowledge_lint` | Run a lint check on the knowledge wiki to identify stale or low-coverage articles. Optional: `project_id`, `stale_days`, `min_coverage`, `max_per_category` (default 50, max 500). True totals returned in `summary.total_per_category`. |
309
361
  | `knowledge_consolidation` | Read the nightly consolidation ("dream") report: NUMBERED proposals for reconciling the corpus, each naming the articles involved and quoting an excerpt from each as evidence. **This tool** applies nothing and recomputes nothing — it returns persisted rows. **The pass** it reports on does write: since #608 the nightly run UNPUBLISHES the losers of each `duplicate_capture` group that two consecutive reports both propose (consecutive meaning the previous report is at most 2 days older, so one skipped nightly run is tolerated and a longer outage is not). That is its only write to `articles`, it is an unpublish and never an archive (archive is terminal for an article), and it still writes no links or conflict resolutions. Classes: `duplicate_capture` (titles that collide once case/punctuation normalize away, or idempotency keys that collide under the same normalization while differing verbatim — capture tag-format drift, which the novelty gate does not catch because novelty scoring and idempotency are separate paths), `generic_title` (a placeholder title that collides on active-title uniqueness and blocks hub creation). Two classes are **RETIRED** (#605) and no longer produced, though the `class` filter still accepts them so historical reports stay readable: `contradiction_candidate` (the nightly lint judges those pairs itself now) and `stale_entry` (age is not a defect signal — for stale articles call `knowledge_lint`, which computes them with a caller-chosen `stale_days`). **Denominators:** `corpus_size` = PUBLISHED articles owned by the tenant at scan time, not its total article count; `proposal_count` = the TRUE pre-cap count of PROPOSALS, not of articles (one duplicate group of three articles is ONE proposal, and one article can appear in proposals of several classes); `persisted_count` = proposal ROWS the report carries, lower than `proposal_count` exactly when a class hit `max_per_class` (`truncated` flags which); `meta.total_count` counts persisted proposals matching the `class` filter, so it is bounded by `persisted_count`, never `proposal_count`. `review_status`/`reviewed_by`/`reviewed_at` are vestigial — nothing reads them to decide anything, there is no approve/reject surface and there will not be one (#605 supersedes #594); auto-apply is gated on reversibility and two-run agreement. They still reset to pending/null whenever the nightly pass re-derives a proposal, so refreshed machine output never inherits an earlier verdict. Requires orchestrator role. Optional: `day` (ISO8601, default most recent report), `class`, `limit` (default 50, max 500), `offset`. |
@@ -374,7 +426,7 @@ Two modes, pinned at creation:
374
426
 
375
427
  | Tool | Description |
376
428
  |---|---|
377
- | `corpus_search` | Search a corpus for POINTERS into files loopctl does not host. Returns `{source_ref, locator, snippet, score, chunk_id, corpus_id}` — a bounded excerpt, never the chunk body — so the next step is always to open the file. `server_embedded`: send `query`. `client_embedded`: send `query_vector` (length = the corpus `dim`); a query string there is `422 query_string_not_accepted` and asking for the keyword lane is `422 keyword_lane_unavailable`. Exactly one of `query`/`query_vector` (both is `422 ambiguous_query`). Scores are rank-derived (RRF) and comparable only WITHIN one result set. Agent key. |
429
+ | `corpus_search` | Search a corpus for POINTERS into files loopctl does not host. Returns `{source_ref, locator, snippet, score, chunk_id, corpus_id}` — a bounded excerpt, never the chunk body — so the next step is always to open the file. `server_embedded`: send `query`. `client_embedded`: send `query_vector` (length = the corpus `dim`); a query string there is `422 query_string_not_accepted` and asking for the keyword lane is `422 keyword_lane_unavailable`. Exactly one of `query`/`query_vector` (both is `422 ambiguous_query`). Scores are rank-derived (RRF) and comparable only WITHIN one result set. Agent key. Carries `meta.outcome`, so a short lane is distinguishable from an empty corpus without knowing that `semantic_unavailable_reason` and `semantic_under_filled` are the keys that mean "ask again". |
378
430
  | `corpus_create` | Create a corpus, pinning `mode`, `embedding_model` and `dim`. Required: `slug`, `name`, `mode`, `embedding_model`, `dim`. Optional: `description`, `allow_snippets`, `project_id`. Agent key. |
379
431
  | `corpus_index` | Index a batch of chunks. `server_embedded` chunk: `{source_ref, locator, text, ordinal?, snippet?}`. `client_embedded` chunk: `{source_ref, locator, vector, content_hash, ordinal?, snippet?}` — there is **no** `text` parameter and sending one is `422 text_not_accepted`, not ignored. Idempotent on `(corpus, source_ref, locator)`. `source_complete` is how a RE-index removes what the document no longer contains: a bare `source_ref` string means this request carries that source's complete set, `{source_ref, locators}` declares the set explicitly for a document spanning several batches. Anything under a named source that is neither carried nor declared is deleted, and `meta.pruned_by_source` reports the cost. Agent key. |
380
432
  | `corpus_list` | List this tenant's corpora, newest first. Call it before searching to learn a corpus's `mode` (which decides string vs vector) and its `dim`. Optional: `project_id`, `limit`, `offset`. Agent key. |
package/index.js CHANGED
@@ -1590,7 +1590,10 @@ async function knowledgeProgressiveIndex({ topic, query, category, limit }) {
1590
1590
  null,
1591
1591
  process.env.LOOPCTL_AGENT_KEY,
1592
1592
  );
1593
- return toContent(result);
1593
+ // A topic browse is a RETRIEVAL: it runs the same ranked pool, so it can come back
1594
+ // short or keyword-only. Without the banner a shed index reads as "the KB has no
1595
+ // articles on this topic", which is the exact misread meta.outcome exists to end.
1596
+ return withRemediationNotice(result);
1594
1597
  }
1595
1598
 
1596
1599
  async function knowledgeHeatIndex({ category, limit, since }) {
@@ -1605,7 +1608,9 @@ async function knowledgeHeatIndex({ category, limit, since }) {
1605
1608
  null,
1606
1609
  process.env.LOOPCTL_AGENT_KEY,
1607
1610
  );
1608
- return toContent(result);
1611
+ // The query-free route, reached for precisely when the query-shaped ones came back
1612
+ // empty — so an unannounced degradation here strands the agent with no route left.
1613
+ return withRemediationNotice(result);
1609
1614
  }
1610
1615
 
1611
1616
  async function knowledgeProgressiveDrill({ article_id, body_max_bytes, body_offset }) {
@@ -1661,7 +1666,9 @@ async function knowledgeList({
1661
1666
  null,
1662
1667
  process.env.LOOPCTL_AGENT_KEY,
1663
1668
  );
1664
- return toContent(result);
1669
+ // Enumeration, not ranking — but a short page still under-reports the set, and an
1670
+ // agent enumerating to decide something absent is the caller least able to tell.
1671
+ return withRemediationNotice(result);
1665
1672
  }
1666
1673
 
1667
1674
  async function knowledgeGet({
@@ -1837,9 +1844,11 @@ async function memoryRecall({ query, limit, include_superseded }) {
1837
1844
  process.env.LOOPCTL_AGENT_KEY,
1838
1845
  );
1839
1846
  // Surface meta (fallback/reason/total_count/underfilled) so the caller can tell
1840
- // a degraded recall from a genuinely empty scope (AC-28.4.4) toContent already
1841
- // preserves the full result (data + meta), we just keep this call explicit.
1842
- return toContent(result);
1847
+ // a degraded recall from a genuinely empty scope (AC-28.4.4). meta alone was not
1848
+ // enough: agents do not read it, which is the whole finding behind the banner. On
1849
+ // the MEMORY surface a shed read otherwise looks identical to an empty scope, and
1850
+ // "I have never been told this" is the most consequential thing to get wrong here.
1851
+ return withRemediationNotice(result);
1843
1852
  }
1844
1853
 
1845
1854
  async function recallContext({ query, project_id, limit }) {
@@ -1858,8 +1867,11 @@ async function recallContext({ query, project_id, limit }) {
1858
1867
  process.env.LOOPCTL_AGENT_KEY,
1859
1868
  );
1860
1869
  // Surface both per-source metas (memory fallback/underfilled + knowledge degraded)
1861
- // so the caller can tell a degraded recall from a genuinely empty scope.
1862
- return toContent(result);
1870
+ // so the caller can tell a degraded recall from a genuinely empty scope. The merged
1871
+ // meta can carry ONE half's failure beside the other half's rows, which the server
1872
+ // classifies "degraded" — a banner is the only place a caller sees that the pack it
1873
+ // is about to act on is a half.
1874
+ return withRemediationNotice(result);
1863
1875
  }
1864
1876
 
1865
1877
  async function memoryList({ limit, offset, include_superseded, all_subjects }) {
@@ -2011,12 +2023,16 @@ async function knowledgeDelete({ article_id }) {
2011
2023
  return toContent(result);
2012
2024
  }
2013
2025
 
2026
+ // There is deliberately NO `confirm` parameter here (#779). A destructive action
2027
+ // returns a server-minted proposal the caller REPLAYS; it never takes its own
2028
+ // authorization as an argument the model can fill in. The server refuses a request
2029
+ // carrying a `confirm` key with 400 confirm_removed rather than ignoring it, so a
2030
+ // stale client learns the gate moved instead of believing it passed one.
2014
2031
  async function knowledgeBulkDelete({
2015
2032
  article_ids,
2016
2033
  source_type,
2017
2034
  source_id,
2018
2035
  tag,
2019
- confirm,
2020
2036
  dry_run,
2021
2037
  hard,
2022
2038
  token,
@@ -2027,11 +2043,12 @@ async function knowledgeBulkDelete({
2027
2043
  if (source_type) payload.source_type = source_type;
2028
2044
  if (source_id) payload.source_id = source_id;
2029
2045
  if (tag) payload.tag = tag;
2030
- if (confirm) payload.confirm = confirm;
2031
- // US-27.12: dry-run preview + irreversible hard delete via a single-use frozen
2032
- // token. dry_run=true mutates nothing (returns meta.would_affect; for the hard
2033
- // path a single-use meta.token); hard=true + token performs the FK-correct
2034
- // IRREVERSIBLE delete over the frozen id-set. Oversized selectors echo
2046
+ // US-27.12 / #779: dry-run preview + a single-use frozen token, on BOTH the
2047
+ // irreversible hard delete (any selector) and the soft ARCHIVE of a `tag`
2048
+ // selector. dry_run=true mutates nothing (returns meta.would_affect plus
2049
+ // meta.token); replaying that token performs the op over the FROZEN id-set.
2050
+ // The two flows mint DIFFERENT token types, so an archive proposal is not
2051
+ // spendable as a delete or the reverse. Oversized selectors echo
2035
2052
  // meta.confirm_hash for re-confirm-on-drift instead of a token.
2036
2053
  if (dry_run) payload.dry_run = true;
2037
2054
  if (hard) payload.hard = true;
@@ -3071,8 +3088,10 @@ async function corpusSearch({ corpus_id, query, query_vector, lanes, limit }) {
3071
3088
  process.env.LOOPCTL_AGENT_KEY,
3072
3089
  );
3073
3090
  // Pointers + snippets only — the caller's next step is to open the file at
3074
- // source_ref/locator. Nothing here is auto-injected into a recall pack.
3075
- return toContent(result);
3091
+ // source_ref/locator. Nothing here is auto-injected into a recall pack, so a
3092
+ // degradation nobody announces is never noticed downstream either: this banner is
3093
+ // the only disclosure a corpus read gets.
3094
+ return withRemediationNotice(result);
3076
3095
  }
3077
3096
 
3078
3097
  async function corpusStatus({ corpus_id, limit, offset }) {
@@ -5689,15 +5708,25 @@ const TOOLS = [
5689
5708
  "of articles by selector. " +
5690
5709
  "REQUIRES LOOPCTL_USER_KEY (user role — orchestrator is NOT sufficient). Provide EXACTLY ONE " +
5691
5710
  "selector: article_ids (explicit list), source_type + source_id (every active article from " +
5692
- "that source), or tag + confirm:true (every active article carrying the tag — high blast " +
5693
- "radius, so confirm:true is required). " +
5711
+ "that source), or tag (every active article carrying the tag — high blast radius). " +
5712
+ "THERE IS NO confirm PARAMETER. Sending one is 400 confirm_removed, never ignored. A " +
5713
+ "high-blast-radius call is authorized by REPLAYING a server-minted proposal, never by a " +
5714
+ "flag in the same request that asks for the mutation. " +
5694
5715
  "DEFAULT (soft archive): rows move to archived, never dropped; set-based + idempotent; " +
5695
- "meta.count = archived, meta.counts/meta.results give the breakdown. " +
5696
- "DRY-RUN: dry_run:true mutates NOTHING and returns meta.would_affect (and, for hard, a " +
5697
- "single-use meta.token / for oversized selectors a meta.confirm_hash). " +
5698
- "HARD DELETE (irreversible): first dry_run with hard:true to get a token, then call again " +
5699
- "with hard:true + that token to FK-correctly delete the FROZEN id-set (links removed first, " +
5700
- "access events cascade). The token is single-use and TTL-bounded. Bounded to 5000 per call.",
5716
+ "meta.count = archived, meta.counts/meta.results give the breakdown. article_ids and " +
5717
+ "source archive immediately; the tag selector is TWO-STEP. " +
5718
+ "TWO-STEP (tag archive, and every hard delete): call with dry_run:true to get " +
5719
+ "meta.would_affect and a single-use, TTL-bounded meta.token frozen over the previewed " +
5720
+ "id-set, then call again with the SAME selector plus that token. The op runs over the " +
5721
+ "FROZEN set, so rows that started matching after the preview are never touched. A call " +
5722
+ "with neither dry_run nor token is 400 (dry_run_required on the tag archive) UNLESS the " +
5723
+ "selector matches nothing, which stays a 200 no-op on either path. The token is TYPED by " +
5724
+ "op AND by selector: an archive token is not spendable as a delete or the reverse, and a " +
5725
+ "token minted for one tag is 400 on a call naming another — sweeping a list of tags " +
5726
+ "needs its own dry-run per tag. Oversized selectors (over the frozen bound) get " +
5727
+ "meta.oversized + " +
5728
+ "meta.confirm_hash instead of a token; echo the hash back with the same selector and the " +
5729
+ "server refuses on any drift. Bounded to 5000 per call.",
5701
5730
  inputSchema: {
5702
5731
  type: "object",
5703
5732
  properties: {
@@ -5717,17 +5746,15 @@ const TOOLS = [
5717
5746
  tag: {
5718
5747
  type: "string",
5719
5748
  description:
5720
- "Every active article carrying this tag (selector 3). Requires confirm:true.",
5721
- },
5722
- confirm: {
5723
- type: "boolean",
5724
- description: "Required (true) when selecting by tag — guards the high blast radius.",
5749
+ "Every active article carrying this tag (selector 3). Two-step even for the soft " +
5750
+ "archive: dry_run:true for a meta.token, then replay it. There is no confirm flag.",
5725
5751
  },
5726
5752
  dry_run: {
5727
5753
  type: "boolean",
5728
5754
  description:
5729
- "Preview only — mutate nothing. Returns meta.would_affect; with hard:true also a " +
5730
- "single-use meta.token (or meta.confirm_hash for oversized selectors).",
5755
+ "Preview only — mutate nothing. Returns meta.would_affect, plus the single-use " +
5756
+ "meta.token for a hard delete or a tag archive (or meta.confirm_hash for oversized " +
5757
+ "selectors).",
5731
5758
  },
5732
5759
  hard: {
5733
5760
  type: "boolean",
@@ -5739,14 +5766,17 @@ const TOOLS = [
5739
5766
  token: {
5740
5767
  type: "string",
5741
5768
  description:
5742
- "The single-use frozen-set token from a `dry_run:true, hard:true` preview. Required " +
5743
- "for the hard delete.",
5769
+ "The single-use frozen-set token from a dry_run preview. Required for a hard delete " +
5770
+ "and for a tag archive, and replayed with the SAME selector. Typed by op AND by " +
5771
+ "selector: an archive token is not spendable as a delete, and a token minted for " +
5772
+ "one tag is refused on a call naming another.",
5744
5773
  },
5745
5774
  confirm_hash: {
5746
5775
  type: "string",
5747
5776
  description:
5748
- "For an oversized hard-delete selector (no token): the meta.confirm_hash from the " +
5749
- "dry-run, echoed back to re-confirm the id-set hasn't drifted.",
5777
+ "For an oversized selector (no token was minted): the meta.confirm_hash from the " +
5778
+ "dry-run, echoed back to re-confirm the id-set hasn't drifted. Applies to an " +
5779
+ "oversized hard delete and an oversized tag archive.",
5750
5780
  },
5751
5781
  },
5752
5782
  required: [],
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Leading notices for search results whose META carries something the agent must act on
3
- * (#658).
3
+ * (#658), now driven by the uniform tool-outcome envelope.
4
4
  *
5
5
  * THE DEFECT THIS FIXES. When semantic ranking is unavailable the server degrades to
6
6
  * keyword-only and says so LOUDLY — `meta.fallback: true`, `meta.degraded: true`,
@@ -16,15 +16,50 @@
16
16
  * The remedy the agent needs is the opposite of the obvious one: do NOT rephrase. Different
17
17
  * words cannot fix a provider timeout. Retry the SAME query.
18
18
  *
19
+ * WHAT `meta.outcome` ADDS. The knowledge, memory and corpus RETRIEVAL responses (plus the
20
+ * `knowledge_list` enumeration path) now carry one of `success | empty | degraded |
21
+ * fallback | error`, so the notice no longer has to infer the class from a handful of
22
+ * per-surface flag names. Three classes get a notice, and they get DIFFERENT ones because
23
+ * the remedies differ:
24
+ *
25
+ * - `fallback` — the semantic lane died, keyword-only was served. Retry the SAME query.
26
+ * - `degraded` — a half was shed or capacity-limited. WAIT, then retry. Retrying at once
27
+ * goes straight back into the same closed gate, which is why this is not worded as a
28
+ * fallback. Some causes are STANDING rather than transient (`STANDING_REASONS`) and
29
+ * get a remedy that does not prescribe a wait no wait can clear.
30
+ * - `error` — the retrieval never ran; the empty envelope is a placeholder and says
31
+ * NOTHING about what the corpus holds.
32
+ *
33
+ * `empty` and `success` get NO notice on purpose. A notice on every ordinary zero-result
34
+ * search is noise, and noise teaches agents to ignore the channel — the exact fate of the
35
+ * `meta` fields this exists to replace. The distinction the agent needs is still on the
36
+ * wire: the rendered JSON carries `meta.outcome: "empty"` next to a `degraded` one that
37
+ * arrives with a shouting banner above it.
38
+ *
19
39
  * This mirrors the existing BYO-LLM `no_embedding_key` ACTION REQUIRED notice, which
20
40
  * already established that a meta-only disclosure is not enough to change behaviour.
21
41
  */
22
42
 
43
+ /** The server's published vocabulary (LoopctlWeb.Outcome). */
44
+ const OUTCOMES = ["success", "empty", "degraded", "fallback", "error"];
45
+
23
46
  /** True when a result degraded to a fallback lane, whatever the cause. */
24
47
  function isDegraded(meta) {
25
48
  return Boolean(meta && (meta.fallback === true || meta.degraded === true));
26
49
  }
27
50
 
51
+ /**
52
+ * The server-declared outcome, or null when this response predates the envelope.
53
+ *
54
+ * Validated against the published list rather than passed through: an unrecognised value
55
+ * means a server newer than this client, and inventing a notice for a class we do not
56
+ * understand is worse than falling back to the flag heuristics below.
57
+ */
58
+ function outcomeOf(result) {
59
+ const value = result && result.meta && result.meta.outcome;
60
+ return OUTCOMES.includes(value) ? value : null;
61
+ }
62
+
28
63
  function resultCount(result) {
29
64
  if (!result || typeof result !== "object") return null;
30
65
  if (Array.isArray(result.data)) return result.data.length;
@@ -33,23 +68,143 @@ function resultCount(result) {
33
68
  }
34
69
 
35
70
  /**
36
- * Returns a notice string when a search DEGRADED, or null otherwise.
71
+ * The most specific bounded tag the response names, or a synthesised one.
37
72
  *
38
- * The empty case gets the strong wording because it is the one that misleads: an empty
39
- * degraded response is indistinguishable from a genuine miss. A degraded response that
40
- * still returned rows gets a softer note the results are real but the ranking was not
41
- * the one requested, so they may be incomplete.
73
+ * Every surface publishes its cause under its own key; this picks whichever is present so
74
+ * the notice can NAME the cause. An unnamed degradation is much weaker advice — "something
75
+ * was short" does not tell an agent whether to wait or to reconfigure.
76
+ */
77
+ function reasonOf(meta) {
78
+ const named =
79
+ meta.fallback_reason ||
80
+ meta.degraded_reason ||
81
+ meta.reason ||
82
+ meta.semantic_unavailable_reason ||
83
+ meta.keyword_unavailable_reason;
84
+
85
+ if (typeof named === "string" && named !== "") return named;
86
+ if (meta.semantic_under_filled === true) return "semantic_under_filled";
87
+ if (meta.ann_iterative_scan === "unavailable") return "ann_iterative_scan_unavailable";
88
+ return "unspecified";
89
+ }
90
+
91
+ function fallbackNotice(reason, count) {
92
+ if (count === 0) {
93
+ return (
94
+ `outcome: fallback — DEGRADED SEARCH, THIS IS NOT "NO RESULTS". Semantic ranking ` +
95
+ `was unavailable (${reason}), so this ran keyword-only, and the keyword lane ` +
96
+ `requires ALL terms to match — a long or specific query returns nothing even when ` +
97
+ `the answer exists. Do NOT conclude the knowledge base lacks this, and do NOT ` +
98
+ `rephrase: different words cannot fix a provider failure. RETRY THE SAME QUERY.`
99
+ );
100
+ }
101
+
102
+ return (
103
+ `outcome: fallback — PARTIAL SEARCH. Semantic ranking was unavailable (${reason}), so ` +
104
+ `these are keyword-only matches and may be incomplete. Retry the same query for full ` +
105
+ `ranking.`
106
+ );
107
+ }
108
+
109
+ /**
110
+ * Degradations that WAITING cannot clear, so the notice must not prescribe a wait.
111
+ *
112
+ * `ann_iterative_scan_unavailable` — the deployed pgvector ran the vector read without
113
+ * the iterative scan the operator enabled, and the tenant filter was applied after a
114
+ * single index batch, so the page may be short. The conclusive cause (pgvector < 0.8,
115
+ * or the extension absent) stands until the extension is upgraded.
116
+ *
117
+ * `embedding_dimension_mismatch` — the memory half's active embedding dimension does not
118
+ * match the stored one, so that half did not run at all. Beside rows from the other half
119
+ * the server classifies it `degraded` (a partial read, not a dead request), which is
120
+ * right — but only an operator can restore the half.
121
+ *
122
+ * Both re-run identically on retry and burn a heavy read for nothing.
123
+ */
124
+ const STANDING_REASONS = new Set([
125
+ "ann_iterative_scan_unavailable",
126
+ "embedding_dimension_mismatch",
127
+ ]);
128
+
129
+ function degradedNotice(reason, count) {
130
+ if (STANDING_REASONS.has(reason)) {
131
+ const scope = count === 0 ? `THIS IS NOT "NO RESULTS"` : `PARTIAL RESULTS`;
132
+
133
+ return (
134
+ `outcome: degraded — ${scope}. A half of this retrieval ran short or not at all ` +
135
+ `(${reason}), so it may have returned FEWER rows than match and its absences ` +
136
+ `prove nothing. Retrying re-runs the identical read and does NOT clear this — it ` +
137
+ `is a standing backend condition an operator has to fix. Use what you got, widen ` +
138
+ `the filters, or reach for a non-vector route (knowledge_list, knowledge_heat_index).`
139
+ );
140
+ }
141
+
142
+ if (count === 0) {
143
+ return (
144
+ `outcome: degraded — THIS IS NOT "NO RESULTS". A half of this retrieval was shed or ` +
145
+ `capacity-limited (${reason}), so the corpus was never fully read. Do NOT conclude ` +
146
+ `the knowledge base lacks this, and do NOT rephrase — the wording had no part in ` +
147
+ `it. WAIT a few seconds, then RETRY THE SAME QUERY; an immediate retry goes back ` +
148
+ `into the same closed gate.`
149
+ );
150
+ }
151
+
152
+ return (
153
+ `outcome: degraded — PARTIAL RESULTS. A half was shed or capacity-limited ` +
154
+ `(${reason}), so this set may be SHORT and its absences prove nothing. Wait a few ` +
155
+ `seconds, then retry the same query for the full set.`
156
+ );
157
+ }
158
+
159
+ function errorNotice(reason) {
160
+ return (
161
+ `outcome: error — THE RETRIEVAL DID NOT RUN (${reason}); this empty envelope was ` +
162
+ `served in its place. It says NOTHING about what the knowledge base holds. Fix the ` +
163
+ `request, then retry.`
164
+ );
165
+ }
166
+
167
+ /**
168
+ * Returns a notice string when a search needs one, or null otherwise.
169
+ *
170
+ * Prefers the server-declared `meta.outcome`; falls back to the pre-envelope flag
171
+ * heuristics so an older server still gets the #658 notice it used to.
172
+ *
173
+ * The zero-result cases get the strong wording because they are the ones that mislead: an
174
+ * empty degraded response is indistinguishable from a genuine miss. A degraded response
175
+ * that still returned rows gets a softer note — the results are real but the retrieval was
176
+ * not the one requested, so they may be incomplete.
42
177
  */
43
178
  function degradedSearchNotice(result) {
44
179
  const meta = result && result.meta;
45
- if (!isDegraded(meta)) return null;
180
+ if (!meta || typeof meta !== "object") return null;
46
181
 
47
182
  // The BYO-key case already has its own, more specific ACTION REQUIRED notice; do not
48
183
  // stack two notices on one result.
49
184
  if (meta.fallback_reason === "no_embedding_key") return null;
50
185
 
51
- const reason = meta.fallback_reason || "unknown";
52
186
  const count = resultCount(result);
187
+ const outcome = outcomeOf(result);
188
+
189
+ if (outcome) {
190
+ switch (outcome) {
191
+ case "fallback":
192
+ return fallbackNotice(reasonOf(meta), count);
193
+ case "degraded":
194
+ return degradedNotice(reasonOf(meta), count);
195
+ case "error":
196
+ return errorNotice(reasonOf(meta));
197
+ default:
198
+ // success / empty — silence is the signal, see the module header.
199
+ return null;
200
+ }
201
+ }
202
+
203
+ if (!isDegraded(meta)) return null;
204
+
205
+ // Pre-envelope server: one class, the historical wording, and no `outcome:` prefix to
206
+ // claim a classification the server never made.
207
+ const reason = meta.fallback_reason || "unknown";
53
208
 
54
209
  if (count === 0) {
55
210
  return (
@@ -67,4 +222,4 @@ function degradedSearchNotice(result) {
67
222
  );
68
223
  }
69
224
 
70
- export { degradedSearchNotice, isDegraded };
225
+ export { degradedSearchNotice, isDegraded, outcomeOf, OUTCOMES };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "loopctl-mcp-server",
3
- "version": "2.78.2",
3
+ "version": "2.85.0",
4
4
  "description": "MCP server for loopctl — structural trust for AI development loops",
5
5
  "type": "module",
6
6
  "main": "index.js",