Spaces:
Running
Running
File size: 3,825 Bytes
8abad49 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | """SOFTWARE navigator: NAVIGATE or ABSTAIN over offered handles only.
Lexical overlap on handle notes. NEVER correctness. Never invents a nodeId.
Raw 9464-node graph is not here. Λ = Conjecture 1.
"""
from __future__ import annotations
from typing import Any
from second_brain.retrieve import tokenize
SOFTWARE_PLANNER = "SZL-BrainNavigator-R2-SOFTWARE"
CAPABILITY = "SZL-BrainNavigator-R2"
ARTIFACT = "SZLHOLDINGS/brain-navigator-r2"
BASE = "Qwen/Qwen3.5-0.8B"
# Queries that must not be grounded on the public projection, even if a
# decoy handle shares a stray token. Named-N abstain gate.
_ABSTAIN_HINTS = (
"secret launch",
"physical effector",
"unpublished earnings",
"private 9464",
"9464-node",
"owner-setup.md",
"excluded owner-setup",
"2099 world cup",
"nvml joule",
"meter that is not attached",
"invent a nodeid",
"sovereign-citizen",
"land patent that voids",
)
def _unsupported(query: str) -> bool:
q = (query or "").lower()
return any(h in q for h in _ABSTAIN_HINTS)
def _score_handle(query: str, handle: dict[str, Any]) -> float:
q = tokenize(query)
if not q:
return 0.0
note = f"{handle.get('note', '')} {handle.get('label', '')} {handle.get('nodeKind', '')}"
toks = tokenize(note)
if not toks:
return 0.0
qset = set(q)
tset = set(toks)
return float(len(qset & tset))
def plan_from_handles(
query: str,
handles: list[dict[str, Any]],
*,
kind: str = "SOFTWARE",
) -> dict[str, Any]:
offered = []
for h in handles:
offered.append(
{
"nodeId": h["nodeId"],
"nodeKind": h.get("nodeKind") or "INDEX",
"label": h.get("label") or "DECLARED",
"note": (h.get("note") or "")[:160],
}
)
ids = {h["nodeId"] for h in offered}
abstain = _unsupported(query) or not offered
best: dict[str, Any] | None = None
best_score = 0.0
if not abstain:
for h in offered:
sc = _score_handle(query, h)
if sc > best_score:
best_score = sc
best = h
if best is None or best_score <= 0:
abstain = True
if abstain or best is None or best["nodeId"] not in ids:
cite: list[str] = []
steps: list[dict[str, Any]] = []
decision = "ABSTAIN"
reason: str | None = (
"No offered handle supports the query; refusing to fabricate grounding."
)
else:
cite = [best["nodeId"]]
steps = [
{
"action": "CITE",
"nodeId": best["nodeId"],
"rationale": "offered handle note overlaps the query topic",
}
]
decision = "NAVIGATE"
reason = None
return {
"planId": "software-navigator",
"capabilityProfile": CAPABILITY,
"provenance": "SYNTHETIC" if kind == "SOFTWARE" else "MODEL_PROPOSED",
"query": query,
"contentAccess": "HANDLES_ONLY",
"candidates": offered,
"decision": decision,
"steps": steps,
"citedNodeIds": cite,
"groundedOnly": True,
"brainBinding": {
"protocol": "khipu-retrieval",
"status": "NOT_RESOLVED",
"note": "Controller resolves handles outside the weights.",
},
"controllerBoundary": (
"SOFTWARE planner proposes a route over offered handles. "
"The controller resolves content outside the weights."
),
"abstainReason": reason,
"base_model": BASE,
"artifact": ARTIFACT,
"planner": SOFTWARE_PLANNER,
"kind": kind,
"lambda": "Conjecture 1",
"raw_graph_nodes_admitted_to_gradients": 0,
}
|