Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions docs/guides/knowledge/external-channels.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ different defaults, Find requires an explicit backend before calling any source.
`--no-external` runs Find without using the registry.

CANNBot serves Ascend and uses its native indexed query and exact-page read
through the approved checkout's worker. Managed rounds select that source from
through the approved checkout's worker. Ordinary Find also includes MindIE when
the current checkout's independent grant opts in to [default navigation](../plugins/codex-plugin.md#find-navigation).
Managed rounds select CANNBot from
the registry for the Git project frozen at session start, and check the grant
again for both search and read. See [managed round retrieval](../../benchmarks/optimization-benchmarks.md#include-cannbot-in-the-round).

Expand Down Expand Up @@ -154,7 +156,7 @@ register owned resources. Python cannot forcibly stop arbitrary in-process threa

| Task backend | Channels searched |
| --- | --- |
| `ascend` | `cannbot-knowledge`, plus any platform-neutral channel |
| `ascend` | Eligible CANNBot and opted-in MindIE grants, plus any platform-neutral channel |
| `cuda`, `mlx`, `rocm`, `cpu` | none — an Ascend source must not answer a CUDA task |
| not declared, no grant | none; each channel reports `backend_unknown` |

Expand Down Expand Up @@ -232,7 +234,7 @@ conclusion.
| `cannbot enable / disable / describe / search / read` | implemented |
| `find` integration with gating, budgets, per-channel states | implemented |
| Managed CANNBot benchmark and AB/BA round query, read and Dashboard attribution | implemented |
| MindIE native navigation | Explicit opt-in for [standalone Find](../plugins/codex-plugin.md#find-navigation) under an approved Ascend project. Returns navigation references. |
| MindIE native navigation | Project default or per-call selection in [standalone Find](../plugins/codex-plugin.md#find-navigation) under an approved Ascend project. Returns versioned references and condition exclusion counts. |
| `cannbot serve` (stdio MCP proxying `discover` / `search` / `read_card`) | not yet |
| `campaign import-cannbot` (receipts into evidence) | not yet |
| Automatic clone, index build or deployment | deliberately absent |
Expand Down
14 changes: 11 additions & 3 deletions docs/guides/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,17 +312,25 @@ to regenerate the index, then retry.
searches the packaged corpus. See [fresh-install output and setup](knowledge/external-channels.md#a-fresh-install-has-no-external-channel)
for the explicit per-checkout grant and source access requirements.

Ordinary Find can query CANNBot and MindIE together. MindIE requires a separate
checkout grant with `mindie enable --domain operators --default-find --backend ascend`.
Follow the [MindIE rollout and navigation guide](plugins/codex-plugin.md#find-navigation)
before enabling default queries in a project. Existing grants still support
`find --external-source mindie-agent --backend ascend` for explicit MindIE navigation.

- **Inputs:** `--backend <name>` declares the task backend; **without it and
without an approved grant, no channel is searched** and each one reports
`backend_unknown`. `--no-external` skips all channels for CI and offline runs.
its gate status. Conflicting grant backends require an explicit `--backend`.
`--no-external` skips all channels for CI and offline runs.
`--external-limit <N>` overrides the per-channel cap (`cannbot-knowledge` 100,
`mindie-agent` 5). `--external-timeout <S>` bounds discovery and search
together (8s default); `--platform` overrides the upstream platform in the grant.
under one deadline (8s default). `--platform` overrides the CANNBot grant's platform.
- **Output:** `external[]` sits beside `items`, never inside it. Each entry
carries `state`, `revision`, `elapsed_ms`, `score_scale` and `count`. A state
other than `ok` (`not_enabled`, `unreachable`, `index_stale`, `timeout`,
`version_mismatch`, `rejected`, `backend_unknown`) means the channel did not
answer — it is **not** the same as answering with no hits.
answer. MindIE lists versioned matched refs and shows condition exclusions by
reason in `withheld`. These counts describe the native domain gate before ranking.
- **Side effects:** none on this repository. A channel reads an external
checkout that the person approved; nothing is copied into the package, a
wheel or `evidence/`.
Expand Down
31 changes: 27 additions & 4 deletions docs/guides/plugins/codex-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,24 @@ when the MindIE adapter is installed outside its default location. Run

### Find navigation

Select MindIE for one Find from the approved checkout.
To include MindIE in ordinary Find, opt in from the approved checkout after
the maintainer records verification of the authorized catalog in
[the rollout issue](https://github.com/InferMatrixLab/InferRSI/issues/711).

```sh
inferrsi mindie enable --domain operators --default-find --backend ascend
inferrsi find "Ascend operator tiling"
```

Ordinary Find returns local results and MindIE navigation, with CANNBot cards
when its own grant is enabled and eligible. `mindie describe` shows
`default_find_backend` for an opted-in grant. Re-run `mindie enable` without
the two Find options to keep the domain grant for explicit use. `mindie disable`
revokes the grant and stops default queries. Existing grants retain per-call
selection until re-enabled with `--default-find`.

To select only MindIE alongside the local corpus for one Find, use the explicit
form from the approved checkout.

```sh
inferrsi find "Ascend operator tiling" --backend ascend --external-source mindie-agent
Expand All @@ -183,9 +200,15 @@ Find keeps the local results and shows the approved domain's versioned MindIE
references in native order. It includes a reference only when the native card
reports `match_status="matched"`. It uses up to 8,000 native tokens and returns up
to five references by default. `--external-limit` can raise the cap to 20, and
`--external-timeout` covers both the availability check and the query.
The MindIE section contains navigation metadata only. The plain Find command
selects CANNBot when eligible. Use `--no-external` for local results alone.
`--external-timeout` gives both sources a shared deadline for discovery and query.
An explicit `--backend` takes precedence. Conflicting project defaults require an
explicit `--backend`. `--platform` applies to CANNBot in ordinary Find.

The MindIE section shows matched references and `withheld` counts for
`condition_unknown` and `mismatched`. The native condition gate counts exclusions
in the approved domain before ranking, so these counts describe domain filtering.
Use `mindie explain` with an exact versioned ref to inspect a hit. Use
`--no-external` for local results alone.

### MCP configuration and queries

Expand Down
10 changes: 7 additions & 3 deletions src/inferrsi/apps/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@ def _clip(value: str, limit: int = 160) -> str:
return text if len(text) <= limit else text[: limit - 1].rstrip() + "…"


def _channels(*, source: str | None = None):
def _channels(*, source: str | None = None, standalone_find: bool = False):
from ..integrations.external_channels import external_channels

return external_channels(source=source)
return external_channels(source=source, standalone_find=standalone_find)


def _print_external(result: dict) -> None:
Expand All @@ -224,6 +224,9 @@ def _print_external(result: dict) -> None:
revision = (entry.get("revision") or "")[:12] or "unpinned"
heading += f" @ {revision}\t[{entry['score_scale']}]"
print(f" {heading}\t{entry.get('count', 0)} hit(s)\t{entry.get('elapsed_ms', 0)} ms")
if (withheld := entry.get("withheld")) is not None:
counts = ", ".join(f"{count} {reason}" for reason, count in withheld.items())
print(f" withheld by conditions: {counts}")
for item in entry.get("items", []):
score = f"{item['score']}\t" if "score" in item else ""
print(f" {score}{_clip(item['title'], 60)}\t{item['locator']}")
Expand Down Expand Up @@ -683,7 +686,8 @@ def main(argv: list[str] | None = None) -> int:
args.skill_root, kinds=kinds, searchspace_index=searchspace_index,
),
limit=args.limit, explain=args.explain, decision_cards=args.decision_cards,
registry=None if args.no_external else _channels(source=args.external_source),
registry=(None if args.no_external else
_channels(source=args.external_source, standalone_find=True)),
backend=args.backend, platform=args.platform,
external_limit=args.external_limit,
external_timeout=args.external_timeout,
Expand Down
15 changes: 12 additions & 3 deletions src/inferrsi/apps/cli/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,14 @@ def parser(*, parser_class=argparse.ArgumentParser) -> argparse.ArgumentParser:
mindie_actions = mindie.add_subparsers(dest="mindie_action", required=True)
enable = mindie_actions.add_parser("enable", help="Approve a MindIE domain for this checkout")
enable.add_argument("--domain", default="operators")
enable.add_argument(
"--default-find", action="store_true",
help="Include this MindIE grant in ordinary Find; requires --backend ascend",
)
enable.add_argument(
"--backend", choices=("ascend",),
help="Declare the checkout's default task backend for --default-find",
)
enable.add_argument(
"--adapter-config", type=Path, default=Path.home() / ".config/mindie-agent/codex.json",
help="Installed MindIE Codex adapter configuration",
Expand Down Expand Up @@ -791,10 +799,11 @@ def parser(*, parser_class=argparse.ArgumentParser) -> argparse.ArgumentParser:
help="Declare the task backend once, e.g. ascend; external channels run only "
"for a declared backend and are never inferred from the query",
)
find.add_argument("--platform", help="Override the grant’s upstream platform, e.g. a2")
find.add_argument("--platform", help="Override the CANNBot grant’s platform, e.g. a2")
find.add_argument(
"--external-source", choices=("mindie-agent",),
help="Explicitly select MindIE navigation for this Find; requires --backend ascend",
help="Select only MindIE for this Find; requires --backend ascend. Ordinary Find "
"includes project grants enabled with mindie enable --default-find",
)
find.add_argument(
"--no-external", action="store_true",
Expand All @@ -806,7 +815,7 @@ def parser(*, parser_class=argparse.ArgumentParser) -> argparse.ArgumentParser:
)
find.add_argument(
"--external-timeout", type=float, default=8.0,
help="Per-channel budget in seconds; a timeout is reported, never shown as no hit",
help="Shared discovery and query deadline in seconds for the external sources",
)
find.add_argument("--json", action="store_true")

Expand Down
11 changes: 10 additions & 1 deletion src/inferrsi/apps/integrations/external_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

def external_channels(
*, root: Path | None = None, expected_checkout: dict | None = None, source: str | None = None,
standalone_find: bool = False,
) -> ChannelRegistry:
if source is not None:
from .mindie.navigation import MindieNavigationChannel
Expand All @@ -26,11 +27,19 @@ def external_channels(
if expected_checkout is not None else channel_type(root=root)
for channel_type in _SOURCES
]
if standalone_find:
from .mindie.navigation import MindieNavigationChannel

mindie = MindieNavigationChannel(root=root, expected_checkout=expected_checkout)
if mindie.declared_backend is not None:
channels.append(mindie)
# A project grant can declare the task backend when Find has no explicit
# --backend. Conflicting grant defaults leave it undeclared.
defaults = {getattr(channel, "declared_backend", None) for channel in channels} - {None}
backend = next(iter(defaults)) if len(defaults) == 1 else None
return ChannelRegistry(channels, declared_backend=backend)
return ChannelRegistry(
channels, declared_backend=backend, conflicting_defaults=len(defaults) > 1,
)


def freeze_project(start: Path | None = None) -> dict | None:
Expand Down
41 changes: 30 additions & 11 deletions src/inferrsi/apps/integrations/mindie/navigation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Explicit, project-authorized MindIE navigation for standalone Find."""
"""Project-authorized MindIE navigation for standalone Find."""

from __future__ import annotations

Expand Down Expand Up @@ -105,12 +105,15 @@ def read_output():
request.finish(process)


def _navigation_hits(payload: dict, *, domain: str, limit: int) -> tuple[ChannelHit, ...]:
def _navigation_results(
payload: dict, *, domain: str, limit: int,
) -> tuple[tuple[ChannelHit, ...], dict[str, int]]:
# The pinned graded repository returns ordered cards in navigation mode.
rows = payload.get("cards")
if not isinstance(rows, list):
raise _NavigationFailure(_BAD_RESPONSE)
hits = {}
withheld_refs = {"condition_unknown": set(), "mismatched": set()}
valid = False
for row in rows:
ref = row.get("ref") if isinstance(row, dict) else None
Expand All @@ -125,20 +128,32 @@ def _navigation_hits(payload: dict, *, domain: str, limit: int) -> tuple[Channel
if status not in ("matched", "mismatched", "condition_unknown"):
continue
valid = True
if status != "matched" or ref in hits:
continue
hits[ref] = ChannelHit(ref, match["id"], score=None, score_scale="", status=status)
if len(hits) == limit:
break
if status == "matched":
if ref not in hits and len(hits) < limit:
hits[ref] = ChannelHit(ref, match["id"], score=None, score_scale="", status=status)
else:
withheld_refs[status].add(ref)
if rows and not valid:
raise _NavigationFailure(_BAD_RESPONSE)
return tuple(hits.values())
# v0.13.13 filters conditions before scoring. Its counts describe the
# native condition gate for this domain, not the number of lexical hits.
excluded = payload.get("excluded_conditions", {})
if not isinstance(excluded, dict):
raise _NavigationFailure(_BAD_RESPONSE)
withheld = {}
for reason, upstream in (("condition_unknown", "unknown"), ("mismatched", "mismatch")):
count = excluded.get(upstream, len(withheld_refs[reason]))
if type(count) is not int or count < 0:
raise _NavigationFailure(_BAD_RESPONSE)
withheld[reason] = count
return tuple(hits.values()), withheld


class MindieNavigationChannel:
name = "mindie-agent"
backend = "ascend"
backend = project.FIND_BACKEND
navigation_only = True
accepts_platform = False

def __init__(self, *, root: Path | None = None, expected_checkout: dict | None = None):
self._root = None
Expand All @@ -154,6 +169,10 @@ def __init__(self, *, root: Path | None = None, expected_checkout: dict | None =
except (OSError, ValueError, RuntimeError):
pass

@property
def declared_backend(self) -> str | None:
return self._grant.get("default_find_backend") if self._grant is not None else None

def _approved(self) -> dict:
if self._root is None or self._checkout is None or self._grant is None:
raise _NavigationFailure(_NOT_ENABLED)
Expand Down Expand Up @@ -228,10 +247,10 @@ def search(
project._check_arguments("query", arguments, domain)
payload = self._run("query", {**arguments, "include_archived": False}, request)
self._approved()
hits = _navigation_hits(payload, domain=domain, limit=limit)
hits, withheld = _navigation_results(payload, domain=domain, limit=limit)
except _NavigationFailure as exc:
return ChannelResult(self.name, exc.status)
return ChannelResult(self.name, ChannelStatus("ok"), hits)
return ChannelResult(self.name, ChannelStatus("ok"), hits, withheld=withheld)

def read(self, locator: str, *, expected_sha256: str | None = None,
expected_revision: str | None = None) -> str:
Expand Down
25 changes: 21 additions & 4 deletions src/inferrsi/apps/integrations/mindie/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from .context import MAX_BYTES, _parse

_SCHEMA = "inferrsi-mindie-project/1"
FIND_BACKEND = "ascend"
_DOMAIN = re.compile(r"[a-z][a-z0-9-]{0,63}")
_WORKER = Path(__file__).with_name("read_worker.py")
_REF_ID = r"[A-Za-z0-9_.-]+@[1-9][0-9]*"
Expand Down Expand Up @@ -86,6 +87,7 @@ def _load_grant(root: Path) -> dict:
if (grant.get("schema") != _SCHEMA or grant.get("project_root") != str(root)
or grant.get("checkout") != checkout
or not isinstance(grant.get("domain"), str) or not _DOMAIN.fullmatch(grant["domain"])
or grant.get("default_find_backend", FIND_BACKEND) != FIND_BACKEND
or any(not isinstance(grant.get(key), str) or not Path(grant[key]).is_absolute()
for key in ("python", "engine"))):
raise ValueError("The MindIE grant does not match this project")
Expand Down Expand Up @@ -129,8 +131,14 @@ def _worker(grant: dict, action: str, arguments: bytes) -> bytes:
return result.stdout


def enable(adapter: Path, domain: str) -> dict:
def enable(
adapter: Path, domain: str, *, default_find: bool = False, backend: str | None = None,
) -> dict:
"""Approve this checkout for one installed, already synced MindIE domain."""
if default_find and backend != FIND_BACKEND:
raise ValueError("--default-find requires --backend ascend")
if not default_find and backend is not None:
raise ValueError("--backend requires --default-find")
root = project_root()
if not _DOMAIN.fullmatch(domain):
raise ValueError("Invalid MindIE domain")
Expand All @@ -146,6 +154,8 @@ def enable(adapter: Path, domain: str) -> dict:
schema=_SCHEMA, project_root=str(root), checkout=_checkout_identity(root),
python=python, engine=str(Path(engine).resolve(strict=True)), domain=domain,
)
if default_find:
grant["default_find_backend"] = backend
info = _parse(_worker(grant, "describe", b"{}"))
path = _grant_path(root)
path.parent.mkdir(mode=0o700, parents=True, exist_ok=True)
Expand All @@ -157,7 +167,7 @@ def enable(adapter: Path, domain: str) -> dict:
pending.replace(path)
finally:
pending.unlink(missing_ok=True)
return {"available": True, **info}
return {"available": True, **info, **_find_setting(grant)}


def disable() -> dict:
Expand All @@ -171,7 +181,13 @@ def describe() -> dict:
info = _parse(_worker(grant, "describe", b"{}"))
except ValueError as exc:
return {"available": False, "reason": str(exc)}
return {"available": True, "tools": ["knowledge_query", "knowledge_explain"], **info}
return {"available": True, "tools": ["knowledge_query", "knowledge_explain"],
**info, **_find_setting(grant)}


def _find_setting(grant: dict) -> dict:
backend = grant.get("default_find_backend")
return {"default_find_backend": backend} if backend is not None else {}


def _check_arguments(action: str, arguments: dict, domain: str) -> None:
Expand Down Expand Up @@ -242,7 +258,8 @@ def call(action: str, arguments: dict, *, session: str | None = None) -> dict:

def dispatch(args) -> dict | None:
if args.mindie_action == "enable":
return enable(args.adapter_config, args.domain)
return enable(args.adapter_config, args.domain,
default_find=args.default_find, backend=args.backend)
if args.mindie_action == "disable":
return disable()
if args.mindie_action == "describe":
Expand Down
Loading
Loading