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
1 change: 1 addition & 0 deletions docs/apps-module-migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@
"docs/guides/operations.md",
"src/inferrsi/apps/cli/__init__.py",
"src/inferrsi/apps/workflows/campaign.py",
"src/inferrsi/apps/workflows/catalog_selection.py",
"src/inferrsi/apps/workflows/indexer_comparison.py",
"src/inferrsi/apps/workflows/session_knowledge.py",
"tests/apps/test_apps_context_provider.py",
Expand Down
360 changes: 360 additions & 0 deletions docs/catalog-selection.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/guides/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ See [round decisions](knowledge/knowledge-retrieval-trace.md#round-decisions).
| Enter an inference task or discover/read skills | CLI `skills enter` / `list` / `show` / `resource` / `reference` | Read-only | `enter` loads one primary owner's complete procedure before evidence search. `list`/ `show` inspect skill metadata and instructions. `resource`/`reference` resolve paths for your file reader. |
| Retrieve and cite external round knowledge | CLI `find --session`, then `read --session DIR --search-ref REF --locator LOCATOR` | Local evidence-writing | Requires an explicit `--cannbot-platform` at start and an approved project grant. Retains search and read metadata. Cite a delivered receipt with `round --knowledge-ref`. See [round retrieval](../benchmarks/optimization-benchmarks.md#include-cannbot-in-the-round) |
| Collect selected knowledge | CLI `collect`; Python `KnowledgeReader.collect` | Read-only | Inventory or batch assembly of known IDs, with revision pins, resources and omissions |
| Select from a frozen catalog | CLI `catalog-select`; Python `select_catalog_evidence` | Read-only | Presents scoped entries for agent selection, then delivers pinned evidence and optional decision cards within the requested budgets. See [catalog selection](../catalog-selection.md) |
| Read exact material/resources | CLI `read` / `resource`; Python `KnowledgeReader.read` / `KnowledgeReader.resource` | Read-only | Returns the requested revision or an explicit unavailable/stale error; never substitutes newer bytes |
| Export legacy cited material | CLI `context` | Read-only | Markdown export of package records selected by filters or explicit IDs |
| Create/update a store candidate | Python `KnowledgeStore.create` / `KnowledgeStore.update` | Candidate-writing | One explicitly authorized local store; expected-revision updates with reason and evidence; retained history; no promotion and no edits to package/checkout content |
Expand Down
56 changes: 56 additions & 0 deletions src/inferrsi/apps/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,56 @@ def main(
else:
_print_find(result)
return 0
if args.command == "catalog-select":
from ...knowledge.catalog_selection import encoded
from ..workflows.catalog_selection import (
complete_catalog_selection,
confirm_catalog_evidence,
open_catalog_selection,
prepare_catalog_selection,
)

catalog = open_catalog_selection(
skill_root=args.skill_root, store_root=args.store, bundled_seal=bundled_seal,
)
conditions = (json.loads(args.conditions.read_text(encoding="utf-8"))
if args.conditions else {})
scope = {"backend": args.backend, "kinds": tuple(args.kinds.split(","))}
token_counter = None
if args.tokenizer:
try:
import tiktoken
except ImportError as exc:
raise ValueError("--tokenizer requires the optional tiktoken package") from exc
encoding = tiktoken.get_encoding(args.tokenizer)
def token_counter(text):
return len(encoding.encode(text, disallowed_special=()))
prepared = prepare_catalog_selection(
catalog, args.query, token_budget=args.token_budget,
reserved_tokens=args.reserved_tokens, conditions=conditions,
token_counter=token_counter, tokenizer=args.tokenizer, projection=args.projection,
priority_questions=args.priority_question, **scope,
)
if args.selection and prepared["status"] != "fallback":
selection = json.loads(args.selection.read_text(encoding="utf-8"))
result = complete_catalog_selection(
catalog, prepared, selection, conditions=conditions,
context_bytes=args.context_bytes, expansion_depth=args.expansion_depth,
expansion_items=args.expansion_items, expansion_bytes=args.expansion_bytes,
priority_questions=args.priority_question, **scope,
)
result["retrieval"]["model"] = {
"id": selection.get("model", "unknown"), "calls": None,
"usage": selection.get("usage"), "provenance": "caller-reported",
"prompt_version": prepared["prompt_version"],
"accounting": prepared["accounting"],
}
if "assessments" in selection:
result = confirm_catalog_evidence(result, selection["assessments"])
_print(result)
else:
print(encoded(prepared).decode())
return 0
if args.command == "collect":
from .atomic_knowledge import AtomicKnowledgeCLI

Expand Down Expand Up @@ -1281,5 +1331,11 @@ def main(
0 if status.get("verdict") == "PASS" else (1 if status.get("verdict") == "FAIL" else 2)
)
except (OSError, ValueError, json.JSONDecodeError, sqlite3.Error) as exc:
if args.command == "catalog-select":
from ...knowledge.catalog_selection import SelectionError

if isinstance(exc, SelectionError):
error = {"error": {"code": exc.code, "message": str(exc)}}
argument_parser.exit(2, json.dumps(error) + "\n")
argument_parser.error(str(exc))
return 2
21 changes: 21 additions & 0 deletions src/inferrsi/apps/cli/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,27 @@ def parser(*, parser_class=argparse.ArgumentParser, historical=False,
)
find.add_argument("--json", action="store_true")

catalog_select = commands.add_parser(
"catalog-select", help="Opt-in full catalog selection by the current Agent",
)
catalog_select.add_argument("query")
catalog_select.add_argument("--selection", type=Path,
help="Agent JSON with snapshot_id and selections")
catalog_select.add_argument("--projection", choices=("full", "short"), default="full")
catalog_select.add_argument("--priority-question", action="append", default=[],
help="Blocking question in priority order (repeatable)")
catalog_select.add_argument("--conditions", type=Path, help="Known/unknown conditions JSON")
catalog_select.add_argument("--token-budget", type=int, default=262144)
catalog_select.add_argument("--tokenizer", help="Optional tiktoken encoding, e.g. o200k_base")
catalog_select.add_argument("--reserved-tokens", type=int, default=4096)
catalog_select.add_argument("--context-bytes", type=int, default=65536)
catalog_select.add_argument("--expansion-depth", type=int, default=1)
catalog_select.add_argument("--expansion-items", type=int, default=5)
catalog_select.add_argument("--expansion-bytes", type=int, default=32768)
catalog_select.add_argument("--backend", choices=BACKENDS)
catalog_select.add_argument("--kinds", default="case,skill,record")
_read_sources(catalog_select)

collect = commands.add_parser(
"collect",
help="Assemble explicit knowledge IDs or list a filtered inventory",
Expand Down
4 changes: 2 additions & 2 deletions src/inferrsi/apps/cli/atomic_knowledge.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
Corpus,
Document,
_flatten,
_skill_description,
_skill_header,
find,
launcher,
)
Expand Down Expand Up @@ -309,7 +309,7 @@ def _skill_ranking_fields(
tags = tags if isinstance(tags, list) else []
return {
"title": guide_path.parent.name.replace("-", " "),
"summary": _skill_description(body),
"summary": _skill_header(body)[0],
"tags": " ".join(tag for tag in tags if isinstance(tag, str)),
"findings": "",
"applicability": _flatten(metadata.get("applicability", {})),
Expand Down
Loading
Loading