Skip to content
Open
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
59 changes: 59 additions & 0 deletions docs/apps-module-migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -321,5 +321,64 @@
"tests/test_apps_module_migrations.py",
"tests/test_benchmark_compare.py"
]
},
{
"old": "inferrsi.apps.cannbot",
"canonical": "inferrsi.apps.integrations.cannbot",
"exports": [
"CannbotChannel",
"project"
],
"consumers": [
"src/inferrsi/apps/cli/__init__.py",
"tests/check_installed.py",
"tests/test_apps_module_migrations.py"
],
"package": true,
"module_exports": {
"project": {
"old": "inferrsi.apps.cannbot.project",
"canonical": "inferrsi.apps.integrations.cannbot.project"
}
}
},
{
"old": "inferrsi.apps.cannbot.project",
"canonical": "inferrsi.apps.integrations.cannbot.project",
"exports": [
"MAX_BYTES",
"PLATFORMS",
"ChannelFailure",
"project_root",
"load_grant",
"describe",
"search",
"read",
"enable",
"disable"
],
"consumers": [
"src/inferrsi/apps/integrations/cannbot/__init__.py",
"tests/check_installed.py",
"tests/test_apps_module_migrations.py",
"tests/test_cannbot_boundaries.py"
]
},
{
"old": "inferrsi.apps.cannbot.read_worker",
"canonical": "inferrsi.apps.integrations.cannbot.read_worker",
"exports": [
"OutputLimitError",
"capture",
"discover",
"search",
"read"
],
"consumers": [
"src/inferrsi/apps/integrations/cannbot/project.py",
"tests/check_installed.py",
"tests/test_apps_module_migrations.py",
"tests/test_cannbot_boundaries.py"
]
}
]
5 changes: 5 additions & 0 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ src/inferrsi/
skill_evaluation.py Composed bundle export, trial run and summary
skill_eval_engineering.py Composed artifact check: task rules around sandbox replay
improvement.py Composed assessment, selection, rerun and holdout acceptance
integrations/
cannbot/
__init__.py CannbotChannel implementation and channel result adaptation
project.py Opt-in checkout/interpreter grant and read-only operations
read_worker.py Standalone worker run by the approved Cannbot interpreter
mindie/
project.py Opt-in per-checkout grant, the worker launch and the recorded read
context.py Export supplied MindIE reads into a caller-reviewed campaign trace
Expand Down
32 changes: 29 additions & 3 deletions docs/module-layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ its dashboard views and templates are in `apps/views/`, and the
collected-context projection is in `knowledge/context_projection.py`.
#371 owns the Apps composition. Its accepted directory follow-up
[#490](https://github.com/InferMatrixLab/InferRSI/issues/490) groups the implemented
storage, handoff and workflows slices described below.
storage, handoff, workflows and Cannbot integrations slices described below.

The old `run` chain is split by owner. Its gates are in
`benchmark/legacy_run_v0.py`, its execution facts stay in `harness/`, and
Expand Down Expand Up @@ -41,8 +41,8 @@ through these exports; new pickles use the canonical definition. The retired
root `inferrsi.evidence_paths` has no alias and remains unavailable.

Shim removal requires a separate reviewed PR recording consumer migration,
wheel and plugin validation, and the first removal version. Integrations and
integrated acceptance remain subsequent #490 slices.
wheel and plugin validation, and the first removal version. MindIE integration
and integrated acceptance remain subsequent #490 slices.

### Apps handoff migration

Expand Down Expand Up @@ -89,6 +89,32 @@ map remains incompatible with a new runtime, including for `status` and `recover
Do not edit a frozen plan to bypass this check. Use the original pinned runtime
to resume, following [release-boundary recovery](optimization-workflow-unification.md#release-boundary-recovery).

### Apps Cannbot integration migration

`apps/integrations/cannbot/` owns the Cannbot channel, project grant and reader
worker. Its CLI commands import the canonical implementation on demand. The new
`integrations` initializer imports nothing. Cannbot retains its existing
`CannbotChannel` definition in the package initializer; importing it does not
read grants or start workers. MindIE remains in `apps/mindie/` until its separate
integration slice.

The [migration inventory](apps-module-migrations.json) records packages with
`package: true`. Compatibility packages and modules use explicit static imports
and literal `__all__`. Cannbot historically exports a `project` module, so
`module_exports` records its two-level mapping: the old package exports its old
project shim, whose public functions and classes are the canonical objects.
The shim and implementation retain their own module identities; no module alias
is installed. Both parent-first and child-first imports preserve that binding.
Private helper patches use the canonical modules.

The Cannbot project adapter resolves its sibling worker in the canonical
directory. Registered launchers use that file with the approved interpreter and
the existing `-I -B` flags. The worker loads without InferRSI installed or a
package context, and its top-level imports are standard-library-only. The legacy
worker path retains Python import compatibility; external interpreters use the
canonical file. Grant schemas, read-only access, limits, revocation and receipts
are unchanged.

### Core and technical packages

The four target modules are peers: `knowledge`, `harness`, `benchmark`, and
Expand Down
105 changes: 2 additions & 103 deletions src/inferrsi/apps/cannbot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,107 +1,6 @@
"""The cannbot-knowledge channel: an external read-only corpus beside ours."""
"""Compatibility exports for :mod:`inferrsi.apps.integrations.cannbot`."""

from __future__ import annotations

import time
from pathlib import Path

from ...knowledge.channels import (
ChannelHit,
ChannelRequest,
ChannelResult,
ChannelStatus,
)
from ..integrations.cannbot import CannbotChannel
from . import project

__all__ = ["CannbotChannel", "project"]

SCORE_SCALE = "cannbot/knowledge-search.v5"


class CannbotChannel:
"""Approved cannbot-knowledge checkout, queried through its own interpreter."""

def __init__(self, *, root: Path | None = None, timeout: float = 8.0):
from . import project

self._project = project
self.root = root
self.timeout = timeout
# `hint` records why this channel cannot answer before any search runs.
# Keeping it lets `find` report "not enabled" instead of telling the
# caller to declare a backend for a source that is not approved yet.
self.hint: ChannelStatus | None = None
try:
grant = project.load_grant(root)
except project.ChannelFailure as exc:
grant = {}
self.hint = ChannelStatus(exc.state, detail=str(exc), fix=exc.fix)
except (OSError, ValueError) as exc:
grant = {}
self.hint = ChannelStatus("rejected", detail=str(exc))
self.backend = "ascend"
self.declared_backend = grant.get("backend")
self.name = "cannbot-knowledge"

def describe(self, *, request: ChannelRequest) -> ChannelStatus:
try:
info = self._project.describe(self.root, timeout=request.remaining(), request=request)
except self._project.ChannelFailure as exc:
return ChannelStatus(exc.state, detail=str(exc), fix=exc.fix)
state = info.get("state", "rejected")
if state != "ok":
return ChannelStatus(
state if state != "rejected" else "rejected",
detail=str(info.get("detail") or ""), fix=str(info.get("fix") or ""),
)
return ChannelStatus("ok", revision=info.get("revision"))

def search(
self, query: str, *, platform: str | None, limit: int, request: ChannelRequest
) -> ChannelResult:
started = time.monotonic()
try:
payload = self._project.search(
query, platform=platform, limit=limit, root=self.root,
timeout=request.remaining(), request=request,
)
except self._project.ChannelFailure as exc:
return ChannelResult(
name=self.name, status=ChannelStatus(
exc.state, detail=str(exc), fix=exc.fix,
),
elapsed_ms=max(1, int((time.monotonic() - started) * 1000)),
)
elapsed = int((time.monotonic() - started) * 1000)
items = tuple(
ChannelHit(
locator=str(row.get("locator") or ""),
title=str(row.get("title") or ""),
summary=str(row.get("summary") or ""),
score=float(row.get("score") or 0),
score_scale=str(payload.get("score_scale") or SCORE_SCALE),
status=str(row.get("status") or ""),
platforms=tuple(row.get("platforms") or ()),
card_sha256=str(row.get("card_sha256") or ""),
source_card_sha256=str(row.get("source_card_sha256") or ""),
)
for row in payload.get("items") or []
if row.get("locator")
)
return ChannelResult(
name=self.name,
status=ChannelStatus("ok", revision=payload.get("revision")),
items=items,
elapsed_ms=elapsed,
score_scale=str(payload.get("score_scale") or SCORE_SCALE),
read_prefix="inferrsi cannbot read",
)

def read(self, locator: str, *, expected_sha256: str | None = None,
expected_revision: str | None = None) -> str:
payload = self._project.read(
locator, expected_sha256=expected_sha256, root=self.root,
expected_revision=expected_revision,
timeout=max(self.timeout, 15.0),
)
return str(payload.get("text") or "")
Loading
Loading