dandelion-memory 1.0.0rc15__py3-none-any.whl
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.
- benchmarks/__init__.py +3 -0
- benchmarks/adapters/__init__.py +29 -0
- benchmarks/adapters/ablations.py +406 -0
- benchmarks/adapters/base.py +72 -0
- benchmarks/adapters/controlled/__init__.py +13 -0
- benchmarks/adapters/controlled/core_archival.py +115 -0
- benchmarks/adapters/controlled/extract_resolve.py +130 -0
- benchmarks/adapters/controlled/hybrid_rag.py +120 -0
- benchmarks/adapters/controlled/no_late_binding.py +113 -0
- benchmarks/adapters/dandelion.py +94 -0
- benchmarks/adapters/native/__init__.py +31 -0
- benchmarks/adapters/native/base.py +45 -0
- benchmarks/adapters/native/dandelion_native.py +164 -0
- benchmarks/adapters/native/dandelion_native_b0.py +165 -0
- benchmarks/adapters/native/dandelion_native_b1.py +170 -0
- benchmarks/adapters/native/dandelion_native_b2.py +169 -0
- benchmarks/adapters/native/dandelion_native_b3.py +171 -0
- benchmarks/adapters/native/dandelion_native_c4.py +261 -0
- benchmarks/adapters/native/dandelion_native_c4_1.py +281 -0
- benchmarks/adapters/native/dandelion_native_c4_2.py +435 -0
- benchmarks/adapters/native/event_evidence_b2.py +616 -0
- benchmarks/adapters/native/evidence_b2.py +609 -0
- benchmarks/adapters/native/letta_native.py +253 -0
- benchmarks/adapters/native/mem0_native.py +219 -0
- benchmarks/adapters/native/store_vector_b0.py +792 -0
- benchmarks/adapters/native/store_vector_b2.py +808 -0
- benchmarks/agent_adapter_stdio_acceptance.py +86 -0
- benchmarks/bootstrap_cross_stack.py +218 -0
- benchmarks/canonical_profile_instrumentation.py +167 -0
- benchmarks/canonical_public_baseline.py +288 -0
- benchmarks/cli.py +525 -0
- benchmarks/collector_public30_offline.py +1653 -0
- benchmarks/datasets/__init__.py +45 -0
- benchmarks/datasets/conversational_generator.py +238 -0
- benchmarks/datasets/generator.py +283 -0
- benchmarks/datasets/holdout_topology_generator.py +290 -0
- benchmarks/datasets/holdout_topology_generator_v2.py +294 -0
- benchmarks/datasets/multi_world.py +1643 -0
- benchmarks/datasets/scale_generator.py +289 -0
- benchmarks/datasets/schema.py +57 -0
- benchmarks/deep_collision_stress.py +199 -0
- benchmarks/evaluators/__init__.py +12 -0
- benchmarks/evaluators/manifest.py +142 -0
- benchmarks/evaluators/metrics.py +277 -0
- benchmarks/evaluators/runner.py +258 -0
- benchmarks/f1_step0/build_dev_measurement_manifest_v1.py +127 -0
- benchmarks/f1_step0/build_dev_measurement_manifest_v2.py +127 -0
- benchmarks/f1_step0/build_dev_measurement_manifest_v3.py +146 -0
- benchmarks/f1_step0/build_ledger.py +143 -0
- benchmarks/f1_step0/build_ledger_v2.py +296 -0
- benchmarks/f1_step0/compare_dev52_readiness_v1.py +106 -0
- benchmarks/f1_step0/locator_public_smoke.py +172 -0
- benchmarks/f1_step0/prepare_dev52_owner_v1.py +133 -0
- benchmarks/f1_step0/prepare_dev52_owner_v2.py +133 -0
- benchmarks/f1_step0/public_identity_probe.py +191 -0
- benchmarks/f1_step0/public_response_mapper.py +101 -0
- benchmarks/f1_step0/real_source_public_preflight.py +244 -0
- benchmarks/f1_step0/run_exact_fusion_dev_experiment_v1.py +83 -0
- benchmarks/f1_step0/scorer.py +110 -0
- benchmarks/f1_step0/source_aware_dev_measurement_v1.py +627 -0
- benchmarks/f1_step0/source_aware_dev_measurement_v2.py +659 -0
- benchmarks/f1_step0/source_aware_dev_measurement_v3.py +776 -0
- benchmarks/f1_step0/test_public_response_mapper.py +110 -0
- benchmarks/f1_step0/test_real_source_public_preflight.py +25 -0
- benchmarks/f1_step0/test_scorer.py +158 -0
- benchmarks/f1_step0/test_source_aware_dev_measurement.py +189 -0
- benchmarks/f1_step0/test_source_aware_dev_measurement_v2.py +263 -0
- benchmarks/f1_step0/test_source_aware_dev_measurement_v3.py +334 -0
- benchmarks/f1_step0/typed_readback_public_smoke.py +181 -0
- benchmarks/forensic_c4_1_dev.py +258 -0
- benchmarks/forensic_c4_dev.py +255 -0
- benchmarks/forensic_deep25_c4_1.py +478 -0
- benchmarks/legacy_migration_acceptance.py +29 -0
- benchmarks/longmemeval_actor.py +497 -0
- benchmarks/longmemeval_agent_judge.py +593 -0
- benchmarks/longmemeval_budget.py +139 -0
- benchmarks/longmemeval_full.py +410 -0
- benchmarks/longmemeval_judge.py +327 -0
- benchmarks/longmemeval_pilot.py +316 -0
- benchmarks/longmemeval_s.py +318 -0
- benchmarks/memory_bench.py +248 -0
- benchmarks/memory_formation/__init__.py +1 -0
- benchmarks/memory_formation/audit.py +801 -0
- benchmarks/memory_formation/real_audit.py +688 -0
- benchmarks/memory_session_acceptance.py +279 -0
- benchmarks/native_codex_host.py +513 -0
- benchmarks/owner_dense_acceptance.py +126 -0
- benchmarks/pilot_seeker_vault.py +266 -0
- benchmarks/prepare_public30_ripgrep_range_owner.py +115 -0
- benchmarks/profile_canonical.py +373 -0
- benchmarks/profile_canonical_lanes.py +405 -0
- benchmarks/profile_search_chunks.py +351 -0
- benchmarks/public_ranges_faq_proof.py +121 -0
- benchmarks/public_repos/build_history_scope_v3.py +330 -0
- benchmarks/public_repos/build_oracle.py +108 -0
- benchmarks/public_repos/build_oracle_v2.py +169 -0
- benchmarks/public_repos/build_oracle_v3.py +176 -0
- benchmarks/public_repos/map_public_v2.py +296 -0
- benchmarks/public_repos/project_prompts_v2.py +31 -0
- benchmarks/public_repos/project_prompts_v3.py +29 -0
- benchmarks/public_repos/ready_admin_v2.py +214 -0
- benchmarks/public_repos/score_public_v2.py +258 -0
- benchmarks/public_repos/test_map_public_v2.py +171 -0
- benchmarks/public_repos/test_public_repo_v2.py +44 -0
- benchmarks/public_repos/test_public_repo_v3.py +46 -0
- benchmarks/public_repos/test_ready_admin_v2.py +117 -0
- benchmarks/public_repos/test_score_public_v2.py +163 -0
- benchmarks/public_repos/test_wire_v2.py +292 -0
- benchmarks/public_repos/wire_v2.py +603 -0
- benchmarks/real_blocker_fix_acceptance.py +155 -0
- benchmarks/real_scan_rescan_acceptance.py +41 -0
- benchmarks/recall_v2_20k_smoke.py +112 -0
- benchmarks/recall_v2_e1_retrieve.py +70 -0
- benchmarks/recall_v2_e1_score.py +271 -0
- benchmarks/recall_v2_e2_prepare.py +69 -0
- benchmarks/recall_v2_e2_public_score.py +91 -0
- benchmarks/recall_v2_e2_score.py +108 -0
- benchmarks/recall_v2_navigation_mcp_replay.py +308 -0
- benchmarks/recall_v2_reader_capture.py +118 -0
- benchmarks/recall_v2_reader_replay.py +136 -0
- benchmarks/run_blind_h10_holdout.py +284 -0
- benchmarks/run_blind_h9_holdout.py +275 -0
- benchmarks/run_c4_2_nightly_scale.py +446 -0
- benchmarks/run_context_scale_simulation.py +189 -0
- benchmarks/run_conversational_bench.py +170 -0
- benchmarks/run_h11_evaluation.py +316 -0
- benchmarks/run_h11_v2_evaluation.py +431 -0
- benchmarks/run_native_fixed12.py +469 -0
- benchmarks/run_native_preflight.py +280 -0
- benchmarks/run_scale_stress.py +225 -0
- benchmarks/solanazation_brownfield_01/build_oracle.py +970 -0
- benchmarks/solanazation_brownfield_01/check_level_a.py +78 -0
- benchmarks/solanazation_brownfield_01/debug_scope.py +13 -0
- benchmarks/solanazation_brownfield_01/evaluate_bootstrap_02.py +570 -0
- benchmarks/solanazation_brownfield_01/evaluate_first_pass.py +306 -0
- benchmarks/solanazation_brownfield_01/generate_dryrun_report.py +222 -0
- benchmarks/solanazation_brownfield_01/generate_manifests.py +146 -0
- benchmarks/solanazation_brownfield_01/inspect_misses.py +29 -0
- benchmarks/solanazation_brownfield_01/run_miss_forensic.py +206 -0
- benchmarks/solanazation_brownfield_01/test_facts.py +15 -0
- benchmarks/statistics/__init__.py +15 -0
- benchmarks/statistics/significance.py +326 -0
- benchmarks/test_native_mcp_preflight.py +229 -0
- benchmarks/test_prepare_public30_range_owner.py +35 -0
- benchmarks/test_public30_source_reference.py +698 -0
- benchmarks/test_recall_v2_e1_reader_input.py +89 -0
- benchmarks/test_recall_v2_navigation_mcp_replay.py +155 -0
- benchmarks/test_recall_v2_reader_replay.py +41 -0
- dandelion/__init__.py +3 -0
- dandelion/__main__.py +11 -0
- dandelion/agent_adapter.py +2369 -0
- dandelion/bootstrap/__init__.py +872 -0
- dandelion/bootstrap/alias_policy.py +50 -0
- dandelion/bootstrap/authority.py +225 -0
- dandelion/bootstrap/canonical_history.py +412 -0
- dandelion/bootstrap/classifier.py +403 -0
- dandelion/bootstrap/component_graph.py +280 -0
- dandelion/bootstrap/discovery.py +279 -0
- dandelion/bootstrap/domain_induction.py +180 -0
- dandelion/bootstrap/domain_topology.py +673 -0
- dandelion/bootstrap/evidence_envelope.py +132 -0
- dandelion/bootstrap/extractors/base.py +171 -0
- dandelion/bootstrap/extractors/exact.py +1234 -0
- dandelion/bootstrap/extractors/generic.py +100 -0
- dandelion/bootstrap/extractors/git_temporal.py +111 -0
- dandelion/bootstrap/extractors/registry.py +345 -0
- dandelion/bootstrap/extractors/relations.py +89 -0
- dandelion/bootstrap/extractors/semantic.py +424 -0
- dandelion/bootstrap/extractors/status.py +218 -0
- dandelion/bootstrap/git_sweeper.py +135 -0
- dandelion/bootstrap/manifest.py +246 -0
- dandelion/bootstrap/quarantine.py +264 -0
- dandelion/bootstrap/report.py +259 -0
- dandelion/bootstrap/root_resolver.py +221 -0
- dandelion/bootstrap/tech_profiler.py +125 -0
- dandelion/bootstrap/topology.py +75 -0
- dandelion/bootstrap/topology_index.py +110 -0
- dandelion/bootstrap/transaction.py +315 -0
- dandelion/canonical_bootstrap.py +257 -0
- dandelion/canonical_memory.py +4130 -0
- dandelion/captured_input.py +295 -0
- dandelion/cli.py +767 -0
- dandelion/config.py +40 -0
- dandelion/derived_index.py +745 -0
- dandelion/domains.py +706 -0
- dandelion/embedder.py +229 -0
- dandelion/event_evidence.py +571 -0
- dandelion/evidence.py +812 -0
- dandelion/evidence_response.py +453 -0
- dandelion/evidence_workspace.py +2360 -0
- dandelion/exact_context.py +129 -0
- dandelion/hydrator.py +124 -0
- dandelion/inspector.py +442 -0
- dandelion/inspector_assets/dandelion-mark.svg +33 -0
- dandelion/inspector_assets/dandelion_graph.js +361 -0
- dandelion/inspector_assets/inspector.css +223 -0
- dandelion/inspector_assets/inspector.html +135 -0
- dandelion/inspector_assets/inspector.js +1059 -0
- dandelion/legacy_import.py +431 -0
- dandelion/live_source_grants.py +133 -0
- dandelion/local_owner.py +114 -0
- dandelion/memory_client.py +252 -0
- dandelion/memory_contract.py +107 -0
- dandelion/memory_owner.py +560 -0
- dandelion/reader_providers.py +118 -0
- dandelion/recall_v2.py +767 -0
- dandelion/reconciler.py +219 -0
- dandelion/request_budget.py +125 -0
- dandelion/retained_basis.py +223 -0
- dandelion/retrieval.py +485 -0
- dandelion/router.py +405 -0
- dandelion/search_terms.py +53 -0
- dandelion/security.py +124 -0
- dandelion/server.py +810 -0
- dandelion/source_content_fts.py +219 -0
- dandelion/source_delivery.py +89 -0
- dandelion/source_history.py +241 -0
- dandelion/source_identity.py +88 -0
- dandelion/source_navigator.py +5 -0
- dandelion/source_reader.py +444 -0
- dandelion/source_references.py +379 -0
- dandelion/source_sections.py +265 -0
- dandelion/store_kv.py +684 -0
- dandelion/store_vector.py +1289 -0
- dandelion/studio.py +325 -0
- dandelion/wal.py +227 -0
- dandelion_memory-1.0.0rc15.dist-info/METADATA +48 -0
- dandelion_memory-1.0.0rc15.dist-info/RECORD +232 -0
- dandelion_memory-1.0.0rc15.dist-info/WHEEL +5 -0
- dandelion_memory-1.0.0rc15.dist-info/entry_points.txt +5 -0
- dandelion_memory-1.0.0rc15.dist-info/licenses/LICENSE +21 -0
- dandelion_memory-1.0.0rc15.dist-info/top_level.txt +2 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"""Create answer-only E2 inputs without opening the oracle or ledger."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import hashlib
|
|
7
|
+
import json
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from dandelion.recall_v2 import RECALL_V2_TOOL_DESCRIPTION
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
HERE = Path(__file__).parent
|
|
14
|
+
QUESTIONS = HERE / "recall_v2_e1_questions_only.json"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def main() -> None:
|
|
18
|
+
parser = argparse.ArgumentParser()
|
|
19
|
+
parser.add_argument("--retrieval", type=Path, required=True)
|
|
20
|
+
parser.add_argument("--output-dir", type=Path, required=True)
|
|
21
|
+
parser.add_argument("--set", choices=("DEV52", "PUBLIC30"), default="DEV52")
|
|
22
|
+
parser.add_argument("--repo", choices=("ripgrep", "vite", "zap"))
|
|
23
|
+
args = parser.parse_args()
|
|
24
|
+
if args.output_dir.exists():
|
|
25
|
+
raise SystemExit("E2 output directory already exists")
|
|
26
|
+
if (args.set == "PUBLIC30") != bool(args.repo):
|
|
27
|
+
raise SystemExit("public E2 requires exactly one repo")
|
|
28
|
+
questions = [row for row in json.loads(QUESTIONS.read_text(encoding="utf-8"))["questions"]
|
|
29
|
+
if row["set"] == args.set and (not args.repo or row["id"].startswith(
|
|
30
|
+
{"ripgrep": "PR-RG-", "vite": "PR-VT-", "zap": "PR-ZP-"}[args.repo]))]
|
|
31
|
+
retrieval_bytes = args.retrieval.read_bytes()
|
|
32
|
+
retrieval = json.loads(retrieval_bytes)
|
|
33
|
+
outcomes = retrieval["outcomes"]
|
|
34
|
+
expected = 52 if args.set == "DEV52" else 10
|
|
35
|
+
if (len(questions) != expected or len(outcomes) != expected or
|
|
36
|
+
retrieval["set"] != args.set or retrieval.get("repo") != args.repo):
|
|
37
|
+
raise SystemExit("E2 requires complete matching frozen retrieval")
|
|
38
|
+
if any(row["id"] != outcome["id"] for row, outcome in zip(questions, outcomes)):
|
|
39
|
+
raise SystemExit("question/retrieval order mismatch")
|
|
40
|
+
if any(outcome["response"]["status"] not in
|
|
41
|
+
{"VERIFIED_MATCHES", "UNVERIFIED_MATCHES", "NO_MATCH"} for outcome in outcomes):
|
|
42
|
+
raise SystemExit("retrieval used the obsolete status contract")
|
|
43
|
+
|
|
44
|
+
args.output_dir.mkdir(parents=True)
|
|
45
|
+
batch_size = 13 if args.set == "DEV52" else 10
|
|
46
|
+
for start in range(0, expected, batch_size):
|
|
47
|
+
rows = [{"index": index, "question": questions[index]["question"],
|
|
48
|
+
"recall_response": outcomes[index]["response"]}
|
|
49
|
+
for index in range(start, min(expected, start + batch_size))]
|
|
50
|
+
payload = {"schema": "dandelion.recall-v2.e2-agent-input.v1",
|
|
51
|
+
"model": "gpt-6-luna", "retrieval_sha256": hashlib.sha256(retrieval_bytes).hexdigest(),
|
|
52
|
+
"set": args.set, "repo": args.repo,
|
|
53
|
+
"answer_protocol": (
|
|
54
|
+
"Return index, decision, answer, cited_candidate_ids and basis. "
|
|
55
|
+
"basis is DIRECT_EVIDENCE for an answer explicitly supported by "
|
|
56
|
+
"its citations, DOC_ATTRIBUTED for a status claim explicitly "
|
|
57
|
+
"attributed to a document but not confirmed by code/config/test, "
|
|
58
|
+
"or NONE for NO_RECORD. DOC_ATTRIBUTED is not a claim about "
|
|
59
|
+
"current project status. Do not guess from related candidates."
|
|
60
|
+
),
|
|
61
|
+
"tool_description": RECALL_V2_TOOL_DESCRIPTION, "cases": rows}
|
|
62
|
+
path = args.output_dir / f"batch_{start // batch_size + 1:02}.json"
|
|
63
|
+
path.write_text(json.dumps(payload, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
|
64
|
+
print(json.dumps({"batches": (expected + batch_size - 1) // batch_size,
|
|
65
|
+
"cases": expected, "output_dir": str(args.output_dir.resolve())}))
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
if __name__ == "__main__":
|
|
69
|
+
main()
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"""Score sealed public E2 answers; semantic support still needs review."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import hashlib
|
|
7
|
+
import json
|
|
8
|
+
from collections import Counter
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
HERE = Path(__file__).parent
|
|
13
|
+
PREFIX = {"ripgrep": "RG", "vite": "VT", "zap": "ZP"}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def main() -> None:
|
|
17
|
+
parser = argparse.ArgumentParser()
|
|
18
|
+
parser.add_argument("--ripgrep", type=Path, required=True)
|
|
19
|
+
parser.add_argument("--vite", type=Path, required=True)
|
|
20
|
+
parser.add_argument("--zap", type=Path, required=True)
|
|
21
|
+
parser.add_argument("--output", type=Path, required=True)
|
|
22
|
+
args = parser.parse_args()
|
|
23
|
+
if args.output.exists():
|
|
24
|
+
raise SystemExit("scored output already exists")
|
|
25
|
+
questions = {row["id"]: row["question"] for row in json.loads(
|
|
26
|
+
(HERE / "recall_v2_e1_questions_only.json").read_text(encoding="utf-8"),
|
|
27
|
+
)["questions"] if row["set"] == "PUBLIC30"}
|
|
28
|
+
oracle = {row["fact_id"].replace("V2-", "PR-"): row for row in json.loads(
|
|
29
|
+
(HERE / "public_repos" / "oracle_dev_v3.json").read_text(encoding="utf-8"),
|
|
30
|
+
)["facts"]}
|
|
31
|
+
cases, hashes = [], {}
|
|
32
|
+
for repo in PREFIX:
|
|
33
|
+
directory = getattr(args, repo)
|
|
34
|
+
input_path, answer_path = directory / "batch_01.json", directory / "answers_batch_01.json"
|
|
35
|
+
input_bytes, answer_bytes = input_path.read_bytes(), answer_path.read_bytes()
|
|
36
|
+
hashes[repo] = {"input": hashlib.sha256(input_bytes).hexdigest(),
|
|
37
|
+
"answers": hashlib.sha256(answer_bytes).hexdigest()}
|
|
38
|
+
payload = json.loads(input_bytes)
|
|
39
|
+
answers = json.loads(answer_bytes)
|
|
40
|
+
if (payload.get("set") != "PUBLIC30" or payload.get("repo") != repo or
|
|
41
|
+
len(payload["cases"]) != 10 or len(answers) != 10):
|
|
42
|
+
raise ValueError(f"incomplete public E2 batch: {repo}")
|
|
43
|
+
by_index = {row["index"]: row for row in answers}
|
|
44
|
+
if set(by_index) != set(range(10)):
|
|
45
|
+
raise ValueError(f"invalid answer indices: {repo}")
|
|
46
|
+
for index, case in enumerate(payload["cases"]):
|
|
47
|
+
case_id = f"PR-{PREFIX[repo]}-{index + 1:02}"
|
|
48
|
+
if case["index"] != index or case["question"] != questions[case_id]:
|
|
49
|
+
raise ValueError(f"question mismatch: {case_id}")
|
|
50
|
+
answer = by_index[index]
|
|
51
|
+
decision, text = answer["decision"], answer["answer"]
|
|
52
|
+
basis = answer.get("basis")
|
|
53
|
+
citations = answer["cited_candidate_ids"]
|
|
54
|
+
visible = {row["id"]: row for row in case["recall_response"]["candidates"]}
|
|
55
|
+
if (decision not in {"ANSWER", "NO_RECORD"} or not isinstance(text, str)
|
|
56
|
+
or basis not in {None, "DIRECT_EVIDENCE", "DOC_ATTRIBUTED", "NONE"}
|
|
57
|
+
or not isinstance(citations, list)
|
|
58
|
+
or not all(isinstance(id_, str) for id_ in citations)):
|
|
59
|
+
raise ValueError(f"bad answer format: {case_id}")
|
|
60
|
+
valid = bool(citations) and set(citations) <= set(visible)
|
|
61
|
+
if decision == "NO_RECORD" and (text != "нет записи" or citations
|
|
62
|
+
or basis not in {None, "NONE"}):
|
|
63
|
+
raise ValueError(f"bad refusal format: {case_id}")
|
|
64
|
+
expected = oracle[case_id]
|
|
65
|
+
absence = expected["stratum"] == "bounded_absence"
|
|
66
|
+
literal = str(expected.get("answer", "")) in text if not absence else None
|
|
67
|
+
source_paths = {item.get("path") for item in expected["evidence"]}
|
|
68
|
+
citation_paths = {visible[id_].get("source", {}).get("path") for id_ in citations
|
|
69
|
+
if id_ in visible}
|
|
70
|
+
source_cited = bool(source_paths & citation_paths)
|
|
71
|
+
result = ("CORRECT_REFUSAL" if absence and decision == "NO_RECORD" else
|
|
72
|
+
"WRONG_ANSWER" if absence else
|
|
73
|
+
"MISSED_ANSWER" if decision == "NO_RECORD" else
|
|
74
|
+
"INVALID_CITATION" if not valid else
|
|
75
|
+
"LITERAL_WITH_SOURCE" if literal and source_cited else
|
|
76
|
+
"NEEDS_REVIEW")
|
|
77
|
+
cases.append({"id": case_id, "repo": repo, "stratum": expected["stratum"],
|
|
78
|
+
"result": result, "decision": decision, "basis": basis,
|
|
79
|
+
"citation_ids_valid": valid,
|
|
80
|
+
"source_cited": source_cited, "literal_in_answer": literal,
|
|
81
|
+
"answer": text, "cited_candidate_ids": citations})
|
|
82
|
+
report = {"schema": "dandelion.recall-v2.e2-public-mechanical.v1", "model": "gpt-6-luna",
|
|
83
|
+
"hashes": hashes, "counts": dict(Counter(row["result"] for row in cases)),
|
|
84
|
+
"warning": "NEEDS_REVIEW and LITERAL_WITH_SOURCE are not semantic correctness judgments.",
|
|
85
|
+
"cases": cases}
|
|
86
|
+
args.output.write_text(json.dumps(report, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
|
87
|
+
print(json.dumps(report["counts"], ensure_ascii=False))
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
if __name__ == "__main__":
|
|
91
|
+
main()
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"""Mechanical E2 checks after Luna answers are sealed; semantic answers need review."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import hashlib
|
|
7
|
+
import json
|
|
8
|
+
from collections import Counter
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
HERE = Path(__file__).parent
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _doc_only_status(category: str, basis: str | None,
|
|
16
|
+
cited_rows: list[dict]) -> bool:
|
|
17
|
+
return (category == "implementation_status" and basis == "DOC_ATTRIBUTED"
|
|
18
|
+
and bool(cited_rows) and
|
|
19
|
+
all(row.get("authority") == "DOC" for row in cited_rows))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def main() -> None:
|
|
23
|
+
parser = argparse.ArgumentParser()
|
|
24
|
+
parser.add_argument("--input-dir", type=Path, required=True)
|
|
25
|
+
parser.add_argument("--output", type=Path, required=True)
|
|
26
|
+
args = parser.parse_args()
|
|
27
|
+
if args.output.exists():
|
|
28
|
+
raise SystemExit("E2 score output already exists")
|
|
29
|
+
inputs, answers = [], []
|
|
30
|
+
input_hashes, answer_hashes = {}, {}
|
|
31
|
+
for batch in range(1, 5):
|
|
32
|
+
input_path = args.input_dir / f"batch_{batch:02}.json"
|
|
33
|
+
answer_path = args.input_dir / f"answers_batch_{batch:02}.json"
|
|
34
|
+
input_bytes, answer_bytes = input_path.read_bytes(), answer_path.read_bytes()
|
|
35
|
+
input_hashes[input_path.name] = hashlib.sha256(input_bytes).hexdigest()
|
|
36
|
+
answer_hashes[answer_path.name] = hashlib.sha256(answer_bytes).hexdigest()
|
|
37
|
+
inputs.extend(json.loads(input_bytes)["cases"])
|
|
38
|
+
answers.extend(json.loads(answer_bytes))
|
|
39
|
+
if len(inputs) != 52 or len(answers) != 52:
|
|
40
|
+
raise ValueError("E2 requires exactly 52 questions and 52 answers")
|
|
41
|
+
by_index = {row["index"]: row for row in answers}
|
|
42
|
+
if len(by_index) != 52 or set(by_index) != set(range(52)):
|
|
43
|
+
raise ValueError("E2 answer indices are missing or duplicated")
|
|
44
|
+
questions = [row for row in json.loads((HERE / "recall_v2_e1_questions_only.json")
|
|
45
|
+
.read_text(encoding="utf-8"))["questions"] if row["set"] == "DEV52"]
|
|
46
|
+
oracle = {row["id"]: row for row in (
|
|
47
|
+
json.loads(line) for line in (HERE / "f1_step0" / "fixtures" / "dev_oracle_80.jsonl")
|
|
48
|
+
.read_text(encoding="utf-8").splitlines() if line.strip())}
|
|
49
|
+
cases = []
|
|
50
|
+
for index, input_row in enumerate(inputs):
|
|
51
|
+
if input_row["index"] != index or input_row["question"] != questions[index]["question"]:
|
|
52
|
+
raise ValueError("E2 input order does not match the frozen questions")
|
|
53
|
+
case_id = questions[index]["id"]
|
|
54
|
+
expected = oracle[case_id]
|
|
55
|
+
answer = by_index[index]
|
|
56
|
+
basis = answer.get("basis")
|
|
57
|
+
if basis is not None and basis not in {"DIRECT_EVIDENCE", "DOC_ATTRIBUTED", "NONE"}:
|
|
58
|
+
raise ValueError(f"invalid answer basis at {index}")
|
|
59
|
+
if answer["decision"] not in {"ANSWER", "NO_RECORD"}:
|
|
60
|
+
raise ValueError(f"invalid decision at {index}")
|
|
61
|
+
cited = answer["cited_candidate_ids"]
|
|
62
|
+
if not isinstance(cited, list) or not all(isinstance(id_, str) for id_ in cited):
|
|
63
|
+
raise ValueError(f"invalid citations at {index}")
|
|
64
|
+
visible_ids = {candidate["id"] for candidate in input_row["recall_response"]["candidates"]}
|
|
65
|
+
citations_valid = set(cited) <= visible_ids
|
|
66
|
+
cited_rows = [candidate for candidate in input_row["recall_response"]["candidates"]
|
|
67
|
+
if candidate["id"] in cited]
|
|
68
|
+
doc_only_status = _doc_only_status(expected["category"], basis, cited_rows)
|
|
69
|
+
if answer["decision"] == "NO_RECORD":
|
|
70
|
+
if answer["answer"] != "нет записи" or cited or basis not in {None, "NONE"}:
|
|
71
|
+
raise ValueError(f"NO_RECORD format mismatch at {index}")
|
|
72
|
+
elif not cited:
|
|
73
|
+
citations_valid = False
|
|
74
|
+
exact = expected["category"] == "exact_current"
|
|
75
|
+
literal_value_in_answer = (str(expected.get("expected_value", "")) in answer["answer"]
|
|
76
|
+
if exact else None)
|
|
77
|
+
if expected.get("must_abstain"):
|
|
78
|
+
result = "CORRECT_REFUSAL" if answer["decision"] == "NO_RECORD" else "WRONG_ANSWER"
|
|
79
|
+
elif answer["decision"] == "NO_RECORD":
|
|
80
|
+
result = "MISSED_ANSWER"
|
|
81
|
+
elif not citations_valid:
|
|
82
|
+
result = "INVALID_CITATION"
|
|
83
|
+
elif doc_only_status:
|
|
84
|
+
result = "DOC_ATTRIBUTED_NEEDS_REVIEW"
|
|
85
|
+
elif exact and literal_value_in_answer:
|
|
86
|
+
result = "EXACT_CORRECT"
|
|
87
|
+
elif exact:
|
|
88
|
+
result = "EXACT_NEEDS_REVIEW"
|
|
89
|
+
else:
|
|
90
|
+
result = "SEMANTIC_NEEDS_REVIEW"
|
|
91
|
+
cases.append({"id": case_id, "category": expected["category"],
|
|
92
|
+
"decision": answer["decision"], "result": result,
|
|
93
|
+
"basis": basis, "doc_only_status": doc_only_status,
|
|
94
|
+
"citations_valid": citations_valid,
|
|
95
|
+
"literal_value_in_answer": literal_value_in_answer,
|
|
96
|
+
"answer": answer["answer"], "cited_candidate_ids": cited})
|
|
97
|
+
report = {"schema": "dandelion.recall-v2.e2-mechanical-score.v1",
|
|
98
|
+
"model": "gpt-6-luna", "input_sha256": input_hashes,
|
|
99
|
+
"answer_sha256": answer_hashes,
|
|
100
|
+
"counts": dict(Counter(row["result"] for row in cases)),
|
|
101
|
+
"warning": "Semantic and nonliteral exact answers remain unadjudicated; never count them as correct or wrong without review.",
|
|
102
|
+
"cases": cases}
|
|
103
|
+
args.output.write_text(json.dumps(report, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
|
104
|
+
print(json.dumps(report["counts"], ensure_ascii=False))
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
if __name__ == "__main__":
|
|
108
|
+
main()
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
"""Question-only MCP capture and prompt-bound replay for source navigation.
|
|
2
|
+
|
|
3
|
+
This small runner exercises the opt-in preview through a real authenticated
|
|
4
|
+
MemoryOwner and FastMCP Client. It never loads benchmark answers or contacts a
|
|
5
|
+
provider. Blind references are supplied separately and accepted only for the
|
|
6
|
+
exact prompt SHA-256 that produced them.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import argparse
|
|
12
|
+
import asyncio
|
|
13
|
+
import hashlib
|
|
14
|
+
import json
|
|
15
|
+
import subprocess
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
from typing import Any
|
|
18
|
+
|
|
19
|
+
from fastmcp import Client as FastMCPClient
|
|
20
|
+
|
|
21
|
+
from dandelion import agent_adapter, source_navigator
|
|
22
|
+
from dandelion.agent_adapter import bind_context, create_mcp
|
|
23
|
+
from dandelion.memory_client import MemoryClient
|
|
24
|
+
try:
|
|
25
|
+
from benchmarks.public_repos.ready_admin_v2 import canonical_snapshot
|
|
26
|
+
except ModuleNotFoundError: # direct `python benchmarks/...py` invocation
|
|
27
|
+
from public_repos.ready_admin_v2 import canonical_snapshot
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
HERE = Path(__file__).parent
|
|
31
|
+
QUESTIONS = HERE / "recall_v2_e1_questions_only.json"
|
|
32
|
+
TERMS_V2 = HERE / "recall_v2_e1_terms_v2_frozen.json"
|
|
33
|
+
TERMS_V2_SHA256 = "e8f49200814aec55f16ad7e86d38de183da45d61a7c69f85a066cbb23ebfee83"
|
|
34
|
+
PRODUCT_REVISION = "a4046b3"
|
|
35
|
+
EXPECTED_CASES = {f"PR-RG-{index:02d}" for index in range(1, 11)}
|
|
36
|
+
CODE_ROOT = HERE.parent.resolve()
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _assert_worktree_imports() -> dict[str, str]:
|
|
40
|
+
resolved = {"agent_adapter": str(Path(agent_adapter.__file__).resolve()),
|
|
41
|
+
"source_navigator": str(Path(source_navigator.__file__).resolve())}
|
|
42
|
+
for name, path in resolved.items():
|
|
43
|
+
if not Path(path).is_relative_to(CODE_ROOT):
|
|
44
|
+
raise RuntimeError(f"{name} did not import from the active harness worktree")
|
|
45
|
+
return resolved
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class PromptMismatch(ValueError):
|
|
49
|
+
"""A replay response is not bound to the current exact provider prompt."""
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _sha(data: bytes) -> str:
|
|
53
|
+
return hashlib.sha256(data).hexdigest()
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _json_bytes(value: Any) -> bytes:
|
|
57
|
+
return json.dumps(value, ensure_ascii=False, sort_keys=True, separators=(",", ":")).encode("utf-8")
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _read_inputs(question_file: Path, terms_file: Path) -> tuple[bytes, bytes, list[dict], dict]:
|
|
61
|
+
question_bytes, terms_bytes = question_file.read_bytes(), terms_file.read_bytes()
|
|
62
|
+
if _sha(terms_bytes) != TERMS_V2_SHA256:
|
|
63
|
+
raise ValueError("the frozen v2 terms SHA-256 does not match")
|
|
64
|
+
question_doc = json.loads(question_bytes)
|
|
65
|
+
terms_rows = json.loads(terms_bytes)
|
|
66
|
+
questions = [row for row in question_doc["questions"]
|
|
67
|
+
if row.get("set") == "PUBLIC30" and row.get("id") in EXPECTED_CASES]
|
|
68
|
+
if {row["id"] for row in questions} != EXPECTED_CASES or len(questions) != 10:
|
|
69
|
+
raise ValueError("expected exactly the ten frozen PR-RG cases")
|
|
70
|
+
terms = {(row["set"], row["id"]): row["terms"] for row in terms_rows}
|
|
71
|
+
if any(("PUBLIC30", row["id"]) not in terms for row in questions):
|
|
72
|
+
raise ValueError("frozen v2 terms are missing a ripgrep question")
|
|
73
|
+
return question_bytes, terms_bytes, questions, terms
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _load_replay(path: Path | None, *, phase: str,
|
|
77
|
+
prior_captures: list[Path]) -> dict[str, list[dict[str, Any]]]:
|
|
78
|
+
if path is None:
|
|
79
|
+
if phase == "capture1":
|
|
80
|
+
return {}
|
|
81
|
+
raise ValueError(f"--responses is required for {phase}")
|
|
82
|
+
document = json.loads(path.read_text(encoding="utf-8"))
|
|
83
|
+
if (document.get("schema") != "dandelion.recall-v2.navigation-blind-responses.v1"
|
|
84
|
+
or not isinstance(document.get("responses"), dict)
|
|
85
|
+
or set(document["responses"]) != EXPECTED_CASES):
|
|
86
|
+
raise ValueError("responses must contain exactly the ten case IDs in the blind response schema")
|
|
87
|
+
expected_capture_hashes = [_sha(path.read_bytes()) for path in prior_captures]
|
|
88
|
+
if document.get("capture_sha256s") != expected_capture_hashes:
|
|
89
|
+
raise ValueError("blind responses are not bound to the exact prior capture artifacts")
|
|
90
|
+
rows = document["responses"]
|
|
91
|
+
if any(not isinstance(value, list) for value in rows.values()):
|
|
92
|
+
raise ValueError("each blind response entry must be a list")
|
|
93
|
+
return rows
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _response_provider(*, phase: str, responses: list[dict[str, Any]], observed: list[dict]) -> tuple:
|
|
97
|
+
state = {"attempt": 0, "invalid": False}
|
|
98
|
+
|
|
99
|
+
def provider(prompt: str, *, temperature: int, max_output_tokens: int) -> Any:
|
|
100
|
+
if temperature != 0 or max_output_tokens != 2048:
|
|
101
|
+
raise ValueError("navigator call exceeded configured bounds")
|
|
102
|
+
attempt = state["attempt"]
|
|
103
|
+
state["attempt"] += 1
|
|
104
|
+
prompt_hash = _sha(prompt.encode("utf-8"))
|
|
105
|
+
task = ""
|
|
106
|
+
try:
|
|
107
|
+
task = str(json.loads(prompt).get("task", ""))
|
|
108
|
+
except (ValueError, TypeError):
|
|
109
|
+
pass
|
|
110
|
+
if phase == "capture1":
|
|
111
|
+
return {"actions": []} if task.startswith("Choose") else []
|
|
112
|
+
if phase == "capture2" and attempt > 0:
|
|
113
|
+
# Replay action one and abstain at action two. The final prompt
|
|
114
|
+
# belongs to capture3 because it must include action-two passages.
|
|
115
|
+
return {"actions": []} if task.startswith("Choose") else []
|
|
116
|
+
if phase == "capture3" and attempt >= 2:
|
|
117
|
+
# Both action prompts are now replayed; record, but do not answer,
|
|
118
|
+
# the final-selection prompt generated from their actual passages.
|
|
119
|
+
return []
|
|
120
|
+
if attempt >= len(responses):
|
|
121
|
+
state["invalid"] = True
|
|
122
|
+
raise PromptMismatch("no blind response is bound to this prompt")
|
|
123
|
+
item = responses[attempt]
|
|
124
|
+
if (not isinstance(item, dict) or item.get("prompt_sha256") != prompt_hash
|
|
125
|
+
or "response" not in item):
|
|
126
|
+
state["invalid"] = True
|
|
127
|
+
raise PromptMismatch("blind response prompt SHA-256 does not match")
|
|
128
|
+
return item["response"]
|
|
129
|
+
|
|
130
|
+
return provider, state
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def _git_value(root: Path, *args: str) -> str | None:
|
|
134
|
+
try:
|
|
135
|
+
result = subprocess.run(["git", "-C", str(root), *args], check=True,
|
|
136
|
+
capture_output=True, text=True, timeout=10)
|
|
137
|
+
except (OSError, subprocess.SubprocessError):
|
|
138
|
+
return None
|
|
139
|
+
return result.stdout.strip()
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def _prompt_refs(prompt: str) -> dict[str, Any]:
|
|
143
|
+
"""Retain exact source IDs/passages the blind provider actually received."""
|
|
144
|
+
try:
|
|
145
|
+
payload = json.loads(prompt)
|
|
146
|
+
except (TypeError, ValueError):
|
|
147
|
+
return {}
|
|
148
|
+
return {key: payload[key] for key in (
|
|
149
|
+
"eligible_candidates", "catalog_page", "history_catalog", "opened_passages",
|
|
150
|
+
) if key in payload}
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
async def _run_mcp(context: Any, case_rows: list[dict], terms: dict,
|
|
154
|
+
replay: dict, phase: str) -> tuple[list[dict], list[dict], bool]:
|
|
155
|
+
required_prior = {"capture2": 1, "capture3": 2}.get(phase)
|
|
156
|
+
if required_prior is not None and any(
|
|
157
|
+
len(replay.get(row["id"], [])) != required_prior for row in case_rows):
|
|
158
|
+
raise ValueError(f"{phase} requires exactly {required_prior} prior response(s) per case")
|
|
159
|
+
active: dict[str, Any] = {"calls": [], "provider": None, "state": None}
|
|
160
|
+
|
|
161
|
+
def provider(prompt: str, **kwargs: Any) -> Any:
|
|
162
|
+
return active["provider"](prompt, **kwargs)
|
|
163
|
+
|
|
164
|
+
def observer(snapshot: dict) -> None:
|
|
165
|
+
active["calls"].append(dict(snapshot))
|
|
166
|
+
|
|
167
|
+
mcp = create_mcp(context, recall_v2_preview=True,
|
|
168
|
+
source_navigator_provider=provider,
|
|
169
|
+
source_navigator_observer=observer)
|
|
170
|
+
case_results: list[dict] = []
|
|
171
|
+
blind_prompts: list[dict] = []
|
|
172
|
+
invalid = False
|
|
173
|
+
async with FastMCPClient(mcp) as client:
|
|
174
|
+
for row in case_rows:
|
|
175
|
+
case_id = row["id"]
|
|
176
|
+
observed: list[dict] = []
|
|
177
|
+
case_provider, state = _response_provider(
|
|
178
|
+
phase=phase, responses=replay.get(case_id, []), observed=observed)
|
|
179
|
+
active.update({"calls": observed, "provider": case_provider, "state": state})
|
|
180
|
+
result = await client.call_tool("recall_v2", {
|
|
181
|
+
"question": row["question"],
|
|
182
|
+
"terms": terms[("PUBLIC30", case_id)],
|
|
183
|
+
"kind": "any", "limit": 8,
|
|
184
|
+
})
|
|
185
|
+
text = next((block.text for block in result.content
|
|
186
|
+
if getattr(block, "text", None)), None)
|
|
187
|
+
if getattr(result, "is_error", False) or not isinstance(text, str):
|
|
188
|
+
raise RuntimeError(f"MCP preview failed for {case_id}")
|
|
189
|
+
decoded = json.loads(text)
|
|
190
|
+
call_records = []
|
|
191
|
+
replayed_count = {"capture2": 1, "capture3": 2,
|
|
192
|
+
"final": len(replay.get(case_id, []))}.get(phase, 0)
|
|
193
|
+
for index, snapshot in enumerate(observed):
|
|
194
|
+
prompt = snapshot.get("prompt")
|
|
195
|
+
if not isinstance(prompt, str):
|
|
196
|
+
raise ValueError("navigator observer omitted exact prompt")
|
|
197
|
+
prompt_hash = _sha(prompt.encode("utf-8"))
|
|
198
|
+
record = {**snapshot, "prompt_sha256": prompt_hash}
|
|
199
|
+
call_records.append(record)
|
|
200
|
+
include_prompt = (
|
|
201
|
+
(phase == "capture1" and index == 0)
|
|
202
|
+
or (phase == "capture2" and snapshot.get("phase") == "navigation"
|
|
203
|
+
and index == replayed_count)
|
|
204
|
+
or (phase == "capture3" and snapshot.get("phase") == "final_selection")
|
|
205
|
+
)
|
|
206
|
+
if include_prompt:
|
|
207
|
+
blind_prompts.append({"id": case_id, "phase": snapshot.get("phase"),
|
|
208
|
+
"prompt_sha256": prompt_hash, "prompt": prompt,
|
|
209
|
+
"source_refs": _prompt_refs(prompt)})
|
|
210
|
+
if phase == "final" and state["attempt"] != len(replay.get(case_id, [])):
|
|
211
|
+
state["invalid"] = True
|
|
212
|
+
invalid = invalid or state["invalid"]
|
|
213
|
+
case_results.append({"id": case_id, "calls": call_records,
|
|
214
|
+
"response": decoded,
|
|
215
|
+
"response_sha256": _sha(_json_bytes(decoded)),
|
|
216
|
+
"replay_status": "INVALID" if state["invalid"] else "VALID"})
|
|
217
|
+
return case_results, blind_prompts, invalid
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
async def run(args: argparse.Namespace) -> tuple[dict, dict]:
|
|
221
|
+
imported_modules = _assert_worktree_imports()
|
|
222
|
+
output_paths = {path.resolve() for path in
|
|
223
|
+
(args.output, args.prompts_output, args.seal_output)}
|
|
224
|
+
if len(output_paths) != 3:
|
|
225
|
+
raise ValueError("capture, blind-input, and seal paths must be distinct")
|
|
226
|
+
if args.output.exists() or args.prompts_output.exists() or args.seal_output.exists():
|
|
227
|
+
raise ValueError("capture outputs must be new paths; refusing to overwrite")
|
|
228
|
+
question_bytes, terms_bytes, questions, terms = _read_inputs(args.questions, args.terms)
|
|
229
|
+
replay = _load_replay(args.responses, phase=args.phase,
|
|
230
|
+
prior_captures=args.prior_capture)
|
|
231
|
+
memory_client = MemoryClient.for_workspace(args.owner, timeout_seconds=120)
|
|
232
|
+
context = bind_context(memory_path=args.owner, source_root=args.source_root,
|
|
233
|
+
lineage_root=args.source_root)
|
|
234
|
+
before = memory_client.call("status", {})
|
|
235
|
+
index_before = memory_client.call("index_status", {})
|
|
236
|
+
migration_marker = memory_client.call("backend_status", {})
|
|
237
|
+
canonical_before = canonical_snapshot(args.owner / ".dandelion" / "memory.sqlite3")
|
|
238
|
+
case_results, blind_prompts, invalid = await _run_mcp(
|
|
239
|
+
context, questions, terms, replay, args.phase)
|
|
240
|
+
after = memory_client.call("status", {})
|
|
241
|
+
index_after = memory_client.call("index_status", {})
|
|
242
|
+
canonical_after = canonical_snapshot(args.owner / ".dandelion" / "memory.sqlite3")
|
|
243
|
+
head = _git_value(args.source_root, "rev-parse", "HEAD")
|
|
244
|
+
dirty = _git_value(args.source_root, "status", "--porcelain", "--untracked-files=no")
|
|
245
|
+
product_revision = _git_value(HERE.parent, "rev-parse", "HEAD")
|
|
246
|
+
manifest = {
|
|
247
|
+
"schema": "dandelion.recall-v2.navigation-mcp-capture.v1",
|
|
248
|
+
"phase": args.phase, "source_repo": str(args.source_root.resolve()),
|
|
249
|
+
"source_head": head, "source_tracked_status": dirty,
|
|
250
|
+
"owner": str(args.owner.resolve()), "product_revision": PRODUCT_REVISION,
|
|
251
|
+
"harness_revision": product_revision,
|
|
252
|
+
"code_modules": imported_modules,
|
|
253
|
+
"expected_product_revision": PRODUCT_REVISION,
|
|
254
|
+
"questions_sha256": _sha(question_bytes), "terms_sha256": _sha(terms_bytes),
|
|
255
|
+
"migration_backend_marker": migration_marker,
|
|
256
|
+
"index_status_before": index_before,
|
|
257
|
+
"index_status_after": index_after,
|
|
258
|
+
"index_readiness_unchanged": index_before == index_after,
|
|
259
|
+
"canonical_status_before": before,
|
|
260
|
+
"canonical_status_before_sha256": _sha(_json_bytes(before)),
|
|
261
|
+
"canonical_status_after": after,
|
|
262
|
+
"canonical_status_after_sha256": _sha(_json_bytes(after)),
|
|
263
|
+
"canonical_status_unchanged": _json_bytes(before) == _json_bytes(after),
|
|
264
|
+
"canonical_content_fingerprint_before": canonical_before,
|
|
265
|
+
"canonical_content_fingerprint_after": canonical_after,
|
|
266
|
+
"canonical_content_unchanged": canonical_before["sha256"] == canonical_after["sha256"],
|
|
267
|
+
"canonical_fingerprint_note": "read-only SQLite mode=ro digest of canonical tables; derived projections and outbox excluded",
|
|
268
|
+
"outcome": "INVALID" if invalid else "SEALED",
|
|
269
|
+
"cases": case_results,
|
|
270
|
+
}
|
|
271
|
+
prompts = {
|
|
272
|
+
"schema": "dandelion.recall-v2.navigation-blind-input.v1",
|
|
273
|
+
"phase": args.phase, "questions_sha256": manifest["questions_sha256"],
|
|
274
|
+
"terms_sha256": manifest["terms_sha256"], "prompts": blind_prompts,
|
|
275
|
+
}
|
|
276
|
+
return manifest, prompts
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def main() -> None:
|
|
280
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
281
|
+
parser.add_argument("--owner", type=Path, required=True)
|
|
282
|
+
parser.add_argument("--source-root", type=Path, required=True)
|
|
283
|
+
parser.add_argument("--phase", choices=("capture1", "capture2", "capture3", "final"), required=True)
|
|
284
|
+
parser.add_argument("--responses", type=Path)
|
|
285
|
+
parser.add_argument("--prior-capture", type=Path, action="append", default=[])
|
|
286
|
+
parser.add_argument("--output", type=Path, required=True)
|
|
287
|
+
parser.add_argument("--prompts-output", type=Path, required=True)
|
|
288
|
+
parser.add_argument("--seal-output", type=Path, required=True)
|
|
289
|
+
parser.add_argument("--questions", type=Path, default=QUESTIONS)
|
|
290
|
+
parser.add_argument("--terms", type=Path, default=TERMS_V2)
|
|
291
|
+
args = parser.parse_args()
|
|
292
|
+
manifest, prompts = asyncio.run(run(args))
|
|
293
|
+
capture_bytes = _json_bytes(manifest) + b"\n"
|
|
294
|
+
prompts_bytes = _json_bytes(prompts) + b"\n"
|
|
295
|
+
args.output.write_bytes(capture_bytes)
|
|
296
|
+
args.prompts_output.write_bytes(prompts_bytes)
|
|
297
|
+
seal = {"schema": "dandelion.recall-v2.navigation-seal.v1",
|
|
298
|
+
"capture_sha256": _sha(capture_bytes), "prompts_sha256": _sha(prompts_bytes),
|
|
299
|
+
"phase": args.phase, "outcome": manifest["outcome"]}
|
|
300
|
+
args.seal_output.write_bytes(_json_bytes(seal) + b"\n")
|
|
301
|
+
print(json.dumps({"cases": len(manifest["cases"]), "prompts": len(prompts["prompts"]),
|
|
302
|
+
"outcome": manifest["outcome"], "capture": str(args.output.resolve()),
|
|
303
|
+
"prompts": str(args.prompts_output.resolve()),
|
|
304
|
+
"seal": str(args.seal_output.resolve())}, ensure_ascii=False))
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
if __name__ == "__main__":
|
|
308
|
+
main()
|