algo-cli-runtime 0.14.0__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.
- algo_cli/__init__.py +3 -0
- algo_cli/__main__.py +7 -0
- algo_cli/_internal/__init__.py +12 -0
- algo_cli/_internal/policy_chain.py +259 -0
- algo_cli/action_registry.py +1047 -0
- algo_cli/agent_blocks.py +550 -0
- algo_cli/agent_pipeline.py +1457 -0
- algo_cli/agent_threads.py +308 -0
- algo_cli/animations.py +316 -0
- algo_cli/cache_admission.py +209 -0
- algo_cli/capability_mask.py +66 -0
- algo_cli/chat_protocol.py +116 -0
- algo_cli/chatgpt_auth.py +510 -0
- algo_cli/chatgpt_client.py +657 -0
- algo_cli/code_rag.py +479 -0
- algo_cli/config.py +651 -0
- algo_cli/context_budget.py +679 -0
- algo_cli/credential_helpers.py +315 -0
- algo_cli/deliberation.py +29 -0
- algo_cli/display.py +1470 -0
- algo_cli/evals/__init__.py +21 -0
- algo_cli/evals/algorithm_effectiveness.py +560 -0
- algo_cli/evals/competitive_harness_rating.py +702 -0
- algo_cli/evals/cot_quality.py +220 -0
- algo_cli/evals/harness_retrieval_benchmark.py +401 -0
- algo_cli/evals/performance_regression.py +136 -0
- algo_cli/evals/scorecard_grading.py +308 -0
- algo_cli/evals/session_distribution.py +84 -0
- algo_cli/execution_guardrails.py +806 -0
- algo_cli/extensions_manifest.py +84 -0
- algo_cli/git_evidence.py +227 -0
- algo_cli/google_workspace.py +407 -0
- algo_cli/google_workspace_auth.py +523 -0
- algo_cli/harness.py +2587 -0
- algo_cli/identity.py +557 -0
- algo_cli/index_compute_lab.py +228 -0
- algo_cli/inference_harness.py +70 -0
- algo_cli/intelligence/__init__.py +1103 -0
- algo_cli/intelligence/acrobat_config.py +307 -0
- algo_cli/intelligence/acrobat_manifests.py +338 -0
- algo_cli/intelligence/acrobat_models.py +195 -0
- algo_cli/intelligence/acrobat_pipeline.py +295 -0
- algo_cli/intelligence/acrobat_runtime.py +302 -0
- algo_cli/intelligence/acrobat_security.py +261 -0
- algo_cli/intelligence/acrobat_workflows.py +226 -0
- algo_cli/intelligence/actionability.py +165 -0
- algo_cli/intelligence/adversarial_audit.py +136 -0
- algo_cli/intelligence/agent_arena.py +92 -0
- algo_cli/intelligence/agent_benchmark.py +236 -0
- algo_cli/intelligence/agent_runtime.py +171 -0
- algo_cli/intelligence/agents_as_tools.py +70 -0
- algo_cli/intelligence/artifact_binding.py +80 -0
- algo_cli/intelligence/autonomous_engineer.py +1976 -0
- algo_cli/intelligence/backpressure.py +99 -0
- algo_cli/intelligence/bloom_filter.py +186 -0
- algo_cli/intelligence/bonferroni.py +66 -0
- algo_cli/intelligence/boundary_compaction.py +98 -0
- algo_cli/intelligence/catalog_verifier.py +172 -0
- algo_cli/intelligence/cavecrew.py +118 -0
- algo_cli/intelligence/changelog.py +176 -0
- algo_cli/intelligence/checkpoint_resume.py +92 -0
- algo_cli/intelligence/circuit_breaker.py +88 -0
- algo_cli/intelligence/clarification_gate.py +101 -0
- algo_cli/intelligence/code_graph.py +180 -0
- algo_cli/intelligence/coderank.py +97 -0
- algo_cli/intelligence/consistent_hash.py +150 -0
- algo_cli/intelligence/consortium_synthesis.py +139 -0
- algo_cli/intelligence/construction/__init__.py +241 -0
- algo_cli/intelligence/construction/common.py +273 -0
- algo_cli/intelligence/construction/documents.py +496 -0
- algo_cli/intelligence/construction/labor_units.py +1395 -0
- algo_cli/intelligence/construction/payments.py +470 -0
- algo_cli/intelligence/construction/risk.py +784 -0
- algo_cli/intelligence/content_extractor.py +132 -0
- algo_cli/intelligence/context_adaptive.py +102 -0
- algo_cli/intelligence/context_ops.py +95 -0
- algo_cli/intelligence/count_min.py +145 -0
- algo_cli/intelligence/cow_state.py +103 -0
- algo_cli/intelligence/critic_loop.py +119 -0
- algo_cli/intelligence/cross_source.py +113 -0
- algo_cli/intelligence/daemon_mode.py +99 -0
- algo_cli/intelligence/dag_orchestration.py +151 -0
- algo_cli/intelligence/deep_research.py +155 -0
- algo_cli/intelligence/degenerate_detector.py +78 -0
- algo_cli/intelligence/delta_report.py +92 -0
- algo_cli/intelligence/discovery_event_log.py +92 -0
- algo_cli/intelligence/document_ingest.py +298 -0
- algo_cli/intelligence/dual_layer_validate.py +151 -0
- algo_cli/intelligence/echo_fidelity.py +73 -0
- algo_cli/intelligence/ema_tuning.py +104 -0
- algo_cli/intelligence/event_log.py +92 -0
- algo_cli/intelligence/evidence_graph.py +114 -0
- algo_cli/intelligence/extension_host.py +162 -0
- algo_cli/intelligence/extension_manifest.py +115 -0
- algo_cli/intelligence/falsification_suite.py +178 -0
- algo_cli/intelligence/finance/__init__.py +169 -0
- algo_cli/intelligence/finance/anomalies.py +135 -0
- algo_cli/intelligence/finance/ap_ar.py +351 -0
- algo_cli/intelligence/finance/cash.py +162 -0
- algo_cli/intelligence/finance/close.py +332 -0
- algo_cli/intelligence/finance/common.py +244 -0
- algo_cli/intelligence/finance/construction.py +135 -0
- algo_cli/intelligence/finance/controls.py +172 -0
- algo_cli/intelligence/finance/evidence.py +119 -0
- algo_cli/intelligence/finance/exceptions.py +157 -0
- algo_cli/intelligence/finance/reconciliations.py +254 -0
- algo_cli/intelligence/finance/revenue.py +109 -0
- algo_cli/intelligence/finance/tax.py +74 -0
- algo_cli/intelligence/finance/workpapers.py +111 -0
- algo_cli/intelligence/finding_record.py +120 -0
- algo_cli/intelligence/flow_dag.py +267 -0
- algo_cli/intelligence/gatherer.py +223 -0
- algo_cli/intelligence/golden_master.py +98 -0
- algo_cli/intelligence/graph_rag.py +195 -0
- algo_cli/intelligence/group_chat.py +143 -0
- algo_cli/intelligence/hash_dedup.py +145 -0
- algo_cli/intelligence/hyperloglog.py +128 -0
- algo_cli/intelligence/incremental_index.py +316 -0
- algo_cli/intelligence/index_store.py +16 -0
- algo_cli/intelligence/iteration_plan.py +133 -0
- algo_cli/intelligence/kernel_plugins.py +167 -0
- algo_cli/intelligence/lesson_catalog.py +135 -0
- algo_cli/intelligence/llm_fallback.py +169 -0
- algo_cli/intelligence/log2_histogram.py +267 -0
- algo_cli/intelligence/lsp_integration.py +147 -0
- algo_cli/intelligence/memory_evolution.py +117 -0
- algo_cli/intelligence/minhash_lsh.py +182 -0
- algo_cli/intelligence/multi_model_score.py +174 -0
- algo_cli/intelligence/multi_tier_grade.py +211 -0
- algo_cli/intelligence/negative_controls.py +113 -0
- algo_cli/intelligence/numeric_clamp.py +63 -0
- algo_cli/intelligence/occ_editor.py +66 -0
- algo_cli/intelligence/output_normalize.py +112 -0
- algo_cli/intelligence/parallel_delegation.py +98 -0
- algo_cli/intelligence/parallel_fanout.py +104 -0
- algo_cli/intelligence/permission_modes.py +105 -0
- algo_cli/intelligence/pre_push_gate.py +68 -0
- algo_cli/intelligence/prefetch.py +171 -0
- algo_cli/intelligence/process_framework.py +217 -0
- algo_cli/intelligence/project_graph.py +387 -0
- algo_cli/intelligence/query_expansion.py +146 -0
- algo_cli/intelligence/ralph_loop.py +117 -0
- algo_cli/intelligence/rate_limiter.py +153 -0
- algo_cli/intelligence/refactor_transaction.py +94 -0
- algo_cli/intelligence/research_workspace.py +108 -0
- algo_cli/intelligence/retraction_ledger.py +72 -0
- algo_cli/intelligence/saga_pattern.py +88 -0
- algo_cli/intelligence/session_fork.py +100 -0
- algo_cli/intelligence/shadow_editor.py +67 -0
- algo_cli/intelligence/shell_session.py +213 -0
- algo_cli/intelligence/source_registry.py +143 -0
- algo_cli/intelligence/spawn_scales.py +99 -0
- algo_cli/intelligence/stat_stability.py +104 -0
- algo_cli/intelligence/structural_validator.py +148 -0
- algo_cli/intelligence/subagent_spawner.py +111 -0
- algo_cli/intelligence/symmetric_verify.py +70 -0
- algo_cli/intelligence/task_classifier.py +129 -0
- algo_cli/intelligence/team_execution.py +122 -0
- algo_cli/intelligence/tiered_access.py +121 -0
- algo_cli/intelligence/utility_registry.py +159 -0
- algo_cli/intuition_engine.py +560 -0
- algo_cli/intuition_injector.py +82 -0
- algo_cli/kernels/__init__.py +5 -0
- algo_cli/kernels/manifest.py +763 -0
- algo_cli/main.py +3903 -0
- algo_cli/memory_candidates.py +541 -0
- algo_cli/memory_echo_veil.py +394 -0
- algo_cli/memory_runtime.py +112 -0
- algo_cli/model_info.py +548 -0
- algo_cli/model_profile.py +160 -0
- algo_cli/model_routing.py +74 -0
- algo_cli/oneshot.py +331 -0
- algo_cli/perf_telemetry.py +389 -0
- algo_cli/plugins.py +245 -0
- algo_cli/private_event_store.py +654 -0
- algo_cli/quantization/__init__.py +24 -0
- algo_cli/quantization/lloyd_max.py +98 -0
- algo_cli/quantization/turbo_quant.py +308 -0
- algo_cli/reasoning/__init__.py +46 -0
- algo_cli/reasoning/combinatorial.py +356 -0
- algo_cli/reasoning/graph_of_thought.py +297 -0
- algo_cli/reasoning/mcts.py +220 -0
- algo_cli/reasoning/neuro_symbolic.py +250 -0
- algo_cli/reasoning/react.py +246 -0
- algo_cli/reasoning/reflexion.py +225 -0
- algo_cli/reasoning/tree_of_thought.py +241 -0
- algo_cli/reasoning_bridge.py +150 -0
- algo_cli/reconciliation.py +284 -0
- algo_cli/reflex.py +385 -0
- algo_cli/resources/docs/ALGO.md +13958 -0
- algo_cli/resources/docs/algo-cli-algorithm-evidence-contract.md +60 -0
- algo_cli/resources/docs/algo-cli-execution-verification-contract.md +59 -0
- algo_cli/resources/docs/algo-cli-memory-lifecycle-contract.md +72 -0
- algo_cli/resources/docs/harness-extension-cleanup-recommendation.md +41 -0
- algo_cli/resources/docs/index-compute-lab-integration.md +32 -0
- algo_cli/resources/docs/inference-harness-loop-blueprint-2026-06.md +55 -0
- algo_cli/resources/docs/main-split-map.md +35 -0
- algo_cli/resources/docs/privacy-and-context.md +48 -0
- algo_cli/resources/docs/reflex-loop-v0.2.md +354 -0
- algo_cli/resources/skills/README.md +26 -0
- algo_cli/resources/skills/algo-cli.md +59 -0
- algo_cli/resources/skills/edit-file-precision.md +49 -0
- algo_cli/resources/skills/harness-search-first.md +47 -0
- algo_cli/resources/skills/memory-recall-ritual.md +51 -0
- algo_cli/resources/skills/qol-algorithms.md +224 -0
- algo_cli/resources/skills/smart-error-recovery.md +56 -0
- algo_cli/resources/skills/tool-selection-cheatsheet.md +65 -0
- algo_cli/retrieval_algorithms.py +127 -0
- algo_cli/runtime_qos.py +236 -0
- algo_cli/runtime_services.py +320 -0
- algo_cli/session_commands.py +95 -0
- algo_cli/session_mode.py +113 -0
- algo_cli/skills.py +430 -0
- algo_cli/slash_dispatch.py +1265 -0
- algo_cli/small_context.py +206 -0
- algo_cli/spawn_budget.py +89 -0
- algo_cli/task_ledger.py +84 -0
- algo_cli/task_router.py +197 -0
- algo_cli/tool_context.py +94 -0
- algo_cli/tool_contract.py +99 -0
- algo_cli/tool_policy.py +357 -0
- algo_cli/tool_runtime.py +647 -0
- algo_cli/tools.py +3056 -0
- algo_cli/url_scheme.py +174 -0
- algo_cli/verify.py +154 -0
- algo_cli/version_manifest.py +178 -0
- algo_cli/vision_screenshot_verify.py +76 -0
- algo_cli/workspace_resolver.py +68 -0
- algo_cli/x_account.py +209 -0
- algo_cli/xai_auth.py +374 -0
- algo_cli/xai_client.py +600 -0
- algo_cli_runtime-0.14.0.dist-info/METADATA +369 -0
- algo_cli_runtime-0.14.0.dist-info/RECORD +237 -0
- algo_cli_runtime-0.14.0.dist-info/WHEEL +4 -0
- algo_cli_runtime-0.14.0.dist-info/entry_points.txt +3 -0
- algo_cli_runtime-0.14.0.dist-info/licenses/LICENSE +21 -0
- ollama_cli/__init__.py +67 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""algo_cli/evals — Evaluation, scoring, and quality utilities.
|
|
2
|
+
|
|
3
|
+
This package exposes reusable evaluators that can be invoked by:
|
|
4
|
+
- the agent runtime to gate tool calls
|
|
5
|
+
- the eval suite to grade trajectories
|
|
6
|
+
- the policy chain to gather quality evidence
|
|
7
|
+
|
|
8
|
+
Modules:
|
|
9
|
+
- cot_quality: I1 + I3 — CoT proportionality and sequencing-marker scoring
|
|
10
|
+
"""
|
|
11
|
+
from .cot_quality import Band, CoTQuality, score_cot
|
|
12
|
+
from .performance_regression import CUSUMResult, RegressionState, detect_cusum
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"Band",
|
|
16
|
+
"CUSUMResult",
|
|
17
|
+
"CoTQuality",
|
|
18
|
+
"RegressionState",
|
|
19
|
+
"detect_cusum",
|
|
20
|
+
"score_cot",
|
|
21
|
+
]
|
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
"""Bounded live evidence probe for core harness and memory algorithms.
|
|
2
|
+
|
|
3
|
+
The probe deliberately exercises production functions against the current
|
|
4
|
+
harness index without calling an embedding model. The canonical ALGO record's
|
|
5
|
+
persisted embedding is used as the deterministic query vector, so an exact
|
|
6
|
+
vector hit and lexical/provenance path can be checked together.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import math
|
|
12
|
+
import json
|
|
13
|
+
import tempfile
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
from typing import Any
|
|
16
|
+
|
|
17
|
+
from .. import harness, memory_candidates
|
|
18
|
+
from ..retrieval_algorithms import FULL_SORT_THRESHOLD, stable_top_k
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
PROBE_SCHEMA_VERSION = 1
|
|
22
|
+
PROBE_NAME = "harness-algorithm-effectiveness-v2"
|
|
23
|
+
CANONICAL_ALGO_ID = "algo-cli:algorithm:ALGO.md"
|
|
24
|
+
PROBE_RESULT_LIMIT = 12
|
|
25
|
+
TOP_K_PARITY_COUNT = FULL_SORT_THRESHOLD + 257
|
|
26
|
+
TOP_K_PARITY_LIMIT = 31
|
|
27
|
+
EXACT_VECTOR_MIN_SCORE = 0.999
|
|
28
|
+
|
|
29
|
+
REQUIRED_CHECKS = (
|
|
30
|
+
"bm25_lexical",
|
|
31
|
+
"exact_vector",
|
|
32
|
+
"rrf_fusion",
|
|
33
|
+
"stable_top_k",
|
|
34
|
+
"window_tinylfu",
|
|
35
|
+
"embedding_priority",
|
|
36
|
+
"memory_admission",
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _check(passed: bool, evidence: dict[str, Any], reason: str = "") -> dict[str, Any]:
|
|
41
|
+
return {
|
|
42
|
+
"status": "pass" if passed else "fail",
|
|
43
|
+
"required": True,
|
|
44
|
+
"reason": "" if passed else reason,
|
|
45
|
+
"evidence": evidence,
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _terminal_result(status: str, reason: str) -> dict[str, Any]:
|
|
50
|
+
checks = {
|
|
51
|
+
name: {
|
|
52
|
+
"status": status,
|
|
53
|
+
"required": True,
|
|
54
|
+
"reason": reason,
|
|
55
|
+
"evidence": {},
|
|
56
|
+
}
|
|
57
|
+
for name in REQUIRED_CHECKS
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
"schema_version": PROBE_SCHEMA_VERSION,
|
|
61
|
+
"probe": PROBE_NAME,
|
|
62
|
+
"status": status,
|
|
63
|
+
"reason": reason,
|
|
64
|
+
"required_checks": list(REQUIRED_CHECKS),
|
|
65
|
+
"summary": {
|
|
66
|
+
"required": len(REQUIRED_CHECKS),
|
|
67
|
+
"passed": 0,
|
|
68
|
+
status: len(REQUIRED_CHECKS),
|
|
69
|
+
},
|
|
70
|
+
"checks": checks,
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _canonical_result(results: list[dict[str, Any]]) -> dict[str, Any] | None:
|
|
75
|
+
return next(
|
|
76
|
+
(result for result in results if str(result.get("id") or "") == CANONICAL_ALGO_ID),
|
|
77
|
+
None,
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _cache_rows(cache: Any) -> int:
|
|
82
|
+
if not isinstance(cache, tuple) or len(cache) < 2 or not isinstance(cache[1], list):
|
|
83
|
+
return 0
|
|
84
|
+
return len(cache[1])
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _matrix_dimensions(cache: Any) -> tuple[int, int]:
|
|
88
|
+
if not isinstance(cache, tuple) or len(cache) < 3:
|
|
89
|
+
return 0, 0
|
|
90
|
+
shape = getattr(cache[2], "shape", ())
|
|
91
|
+
if not isinstance(shape, tuple) or len(shape) != 2:
|
|
92
|
+
return 0, 0
|
|
93
|
+
return int(shape[0]), int(shape[1])
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _top_k_parity_check() -> dict[str, Any]:
|
|
97
|
+
# The modulo score creates many ties, so equality also verifies stable
|
|
98
|
+
# original-order tie breaking in the heap branch above the crossover.
|
|
99
|
+
candidates = list(range(TOP_K_PARITY_COUNT))
|
|
100
|
+
|
|
101
|
+
def score(item: int) -> float:
|
|
102
|
+
return float((item * 37) % 101)
|
|
103
|
+
|
|
104
|
+
expected = sorted(candidates, key=score, reverse=True)[:TOP_K_PARITY_LIMIT]
|
|
105
|
+
actual = stable_top_k(candidates, TOP_K_PARITY_LIMIT, score=score)
|
|
106
|
+
parity = actual == expected
|
|
107
|
+
return _check(
|
|
108
|
+
TOP_K_PARITY_COUNT > FULL_SORT_THRESHOLD and parity,
|
|
109
|
+
{
|
|
110
|
+
"candidate_count": TOP_K_PARITY_COUNT,
|
|
111
|
+
"full_sort_threshold": FULL_SORT_THRESHOLD,
|
|
112
|
+
"limit": TOP_K_PARITY_LIMIT,
|
|
113
|
+
"heap_branch_exercised": TOP_K_PARITY_COUNT > FULL_SORT_THRESHOLD,
|
|
114
|
+
"matches_stable_full_sort": parity,
|
|
115
|
+
"expected_prefix": expected[:5],
|
|
116
|
+
"actual_prefix": actual[:5],
|
|
117
|
+
},
|
|
118
|
+
"stable_top_k diverged from stable full-sort parity above the heap threshold",
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def _int_tier_map(value: Any) -> dict[str, int]:
|
|
123
|
+
mapping = value if isinstance(value, dict) else {}
|
|
124
|
+
return {tier: int(mapping.get(tier, 0)) for tier in harness.EMBED_PRIORITY_TIERS}
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def _embedding_priority_check(model: str, record_count: int) -> dict[str, Any]:
|
|
128
|
+
progress = harness.embedding_progress(model)
|
|
129
|
+
totals = _int_tier_map(progress.get("total_by_priority"))
|
|
130
|
+
embedded = _int_tier_map(progress.get("embedded_by_priority"))
|
|
131
|
+
pending = _int_tier_map(progress.get("pending_by_priority"))
|
|
132
|
+
high_value_tiers = harness.EMBED_PRIORITY_TIERS[:2]
|
|
133
|
+
expected_high_value_total = sum(totals[tier] for tier in high_value_tiers)
|
|
134
|
+
expected_high_value_pending = sum(pending[tier] for tier in high_value_tiers)
|
|
135
|
+
tier_arithmetic_valid = all(
|
|
136
|
+
embedded[tier] + pending[tier] == totals[tier]
|
|
137
|
+
for tier in harness.EMBED_PRIORITY_TIERS
|
|
138
|
+
)
|
|
139
|
+
passed = (
|
|
140
|
+
progress.get("policy") == harness.EMBED_PRIORITY_POLICY
|
|
141
|
+
and sum(totals.values()) == record_count
|
|
142
|
+
and tier_arithmetic_valid
|
|
143
|
+
and int(progress.get("high_value_total", -1)) == expected_high_value_total
|
|
144
|
+
and int(progress.get("high_value_pending", -1)) == expected_high_value_pending
|
|
145
|
+
)
|
|
146
|
+
return _check(
|
|
147
|
+
passed,
|
|
148
|
+
{
|
|
149
|
+
"policy": progress.get("policy"),
|
|
150
|
+
"expected_policy": harness.EMBED_PRIORITY_POLICY,
|
|
151
|
+
"total_by_priority": totals,
|
|
152
|
+
"embedded_by_priority": embedded,
|
|
153
|
+
"pending_by_priority": pending,
|
|
154
|
+
"high_value_total": int(progress.get("high_value_total", 0)),
|
|
155
|
+
"high_value_embedded": int(progress.get("high_value_embedded", 0)),
|
|
156
|
+
"high_value_pending": int(progress.get("high_value_pending", 0)),
|
|
157
|
+
"next_priority": progress.get("next_priority"),
|
|
158
|
+
"tier_total": sum(totals.values()),
|
|
159
|
+
"record_count": record_count,
|
|
160
|
+
"tier_arithmetic_valid": tier_arithmetic_valid,
|
|
161
|
+
},
|
|
162
|
+
"value-aware embedding tier totals or high-value progress are inconsistent",
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def _query_cache_check(before: dict[str, Any], after: dict[str, Any]) -> dict[str, Any]:
|
|
167
|
+
hit_delta = int(after.get("hits", 0)) - int(before.get("hits", 0))
|
|
168
|
+
miss_delta = int(after.get("misses", 0)) - int(before.get("misses", 0))
|
|
169
|
+
size = int(after.get("size", 0))
|
|
170
|
+
capacity = int(after.get("capacity", 0))
|
|
171
|
+
window_size = int(after.get("window_size", 0))
|
|
172
|
+
main_size = int(after.get("main_size", 0))
|
|
173
|
+
bounds_valid = (
|
|
174
|
+
capacity >= 1
|
|
175
|
+
and 0 <= size <= capacity
|
|
176
|
+
and window_size >= 0
|
|
177
|
+
and main_size >= 0
|
|
178
|
+
and window_size + main_size == size
|
|
179
|
+
)
|
|
180
|
+
return _check(
|
|
181
|
+
hit_delta >= 1 and bounds_valid,
|
|
182
|
+
{
|
|
183
|
+
"hits_before": int(before.get("hits", 0)),
|
|
184
|
+
"hits_after": int(after.get("hits", 0)),
|
|
185
|
+
"hit_delta": hit_delta,
|
|
186
|
+
"miss_delta": miss_delta,
|
|
187
|
+
"size": size,
|
|
188
|
+
"capacity": capacity,
|
|
189
|
+
"window_size": window_size,
|
|
190
|
+
"main_size": main_size,
|
|
191
|
+
"bounds_valid": bounds_valid,
|
|
192
|
+
},
|
|
193
|
+
"the repeated production query did not produce a cache hit or cache bounds are invalid",
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def _memory_admission_check() -> dict[str, Any]:
|
|
198
|
+
persisted: list[str] = []
|
|
199
|
+
|
|
200
|
+
def persist(text: str) -> bool:
|
|
201
|
+
persisted.append(text)
|
|
202
|
+
return True
|
|
203
|
+
|
|
204
|
+
with tempfile.TemporaryDirectory(prefix="algo-cli-memory-probe-") as tmp_dir:
|
|
205
|
+
state_path = Path(tmp_dir) / "state.json"
|
|
206
|
+
first = memory_candidates.process_memory_candidates(
|
|
207
|
+
"Remember that our standard shell is zsh.",
|
|
208
|
+
[],
|
|
209
|
+
state_path,
|
|
210
|
+
True,
|
|
211
|
+
persist,
|
|
212
|
+
daily_limit=2,
|
|
213
|
+
entry_limit=4,
|
|
214
|
+
char_limit=256,
|
|
215
|
+
)
|
|
216
|
+
duplicate = memory_candidates.process_memory_candidates(
|
|
217
|
+
"Remember that our standard shell is zsh.",
|
|
218
|
+
persisted,
|
|
219
|
+
state_path,
|
|
220
|
+
True,
|
|
221
|
+
persist,
|
|
222
|
+
daily_limit=2,
|
|
223
|
+
entry_limit=4,
|
|
224
|
+
char_limit=256,
|
|
225
|
+
)
|
|
226
|
+
privacy = memory_candidates.process_memory_candidates(
|
|
227
|
+
"Remember that " + "sk-" + "abcdefghijklmnop123456 is the API key.",
|
|
228
|
+
persisted,
|
|
229
|
+
state_path,
|
|
230
|
+
True,
|
|
231
|
+
persist,
|
|
232
|
+
daily_limit=2,
|
|
233
|
+
entry_limit=4,
|
|
234
|
+
char_limit=256,
|
|
235
|
+
)
|
|
236
|
+
state_text = state_path.read_text(encoding="utf-8")
|
|
237
|
+
state_payload = json.loads(state_text)
|
|
238
|
+
|
|
239
|
+
first_stored = int(first.get("counts", {}).get("stored") or 0)
|
|
240
|
+
duplicate_stored = int(duplicate.get("counts", {}).get("stored") or 0)
|
|
241
|
+
privacy_stored = int(privacy.get("counts", {}).get("stored") or 0)
|
|
242
|
+
duplicate_reasons = duplicate.get("reason_counts", {})
|
|
243
|
+
privacy_reasons = privacy.get("reason_counts", {})
|
|
244
|
+
accepted = state_payload.get("accepted", []) if isinstance(state_payload, dict) else []
|
|
245
|
+
metadata_only_state = (
|
|
246
|
+
"standard shell" not in state_text
|
|
247
|
+
and "abcdefghijklmnop" not in state_text
|
|
248
|
+
and isinstance(accepted, list)
|
|
249
|
+
and len(accepted) == 1
|
|
250
|
+
)
|
|
251
|
+
passed = (
|
|
252
|
+
first.get("status") == "stored"
|
|
253
|
+
and first_stored == 1
|
|
254
|
+
and duplicate_stored == 0
|
|
255
|
+
and int(duplicate_reasons.get("duplicate_fingerprint") or 0) == 1
|
|
256
|
+
and privacy_stored == 0
|
|
257
|
+
and int(privacy_reasons.get("secret") or 0) == 1
|
|
258
|
+
and len(persisted) == 1
|
|
259
|
+
and metadata_only_state
|
|
260
|
+
)
|
|
261
|
+
return _check(
|
|
262
|
+
passed,
|
|
263
|
+
{
|
|
264
|
+
"first_status": first.get("status"),
|
|
265
|
+
"first_stored": first_stored,
|
|
266
|
+
"duplicate_stored": duplicate_stored,
|
|
267
|
+
"duplicate_reason_counts": duplicate_reasons,
|
|
268
|
+
"privacy_stored": privacy_stored,
|
|
269
|
+
"privacy_reason_counts": privacy_reasons,
|
|
270
|
+
"persist_callback_count": len(persisted),
|
|
271
|
+
"state_version": state_payload.get("version") if isinstance(state_payload, dict) else None,
|
|
272
|
+
"state_entry_count": len(accepted) if isinstance(accepted, list) else 0,
|
|
273
|
+
"metadata_only_state": metadata_only_state,
|
|
274
|
+
},
|
|
275
|
+
"memory admission did not store once, reject duplicate/secret input, or keep metadata-only state",
|
|
276
|
+
)
|
|
277
|
+
def _build_probe_query(index: dict[str, Any], canonical: dict[str, Any], dimensions: int) -> str:
|
|
278
|
+
# Include index identity to avoid colliding with a user query cached under a
|
|
279
|
+
# different vector while keeping both calls in this probe identical.
|
|
280
|
+
generated = str(index.get("generated") or "unknown").replace(" ", "-")
|
|
281
|
+
source_version = str(canonical.get("file_mtime_ns") or canonical.get("updated") or "unknown")
|
|
282
|
+
return (
|
|
283
|
+
"rate your harness algorithm catalog self-evaluation "
|
|
284
|
+
f"{CANONICAL_ALGO_ID} effectiveness-probe-{generated}-{source_version}-{dimensions}"
|
|
285
|
+
)
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
def _vector_values(canonical: dict[str, Any]) -> tuple[list[float] | None, str]:
|
|
289
|
+
raw = canonical.get("embedding")
|
|
290
|
+
model = str(canonical.get("embedding_model") or "").strip()
|
|
291
|
+
if not isinstance(raw, list) or not raw or not model:
|
|
292
|
+
return None, model
|
|
293
|
+
try:
|
|
294
|
+
vector = [float(value) for value in raw]
|
|
295
|
+
except (TypeError, ValueError):
|
|
296
|
+
return None, model
|
|
297
|
+
if not all(math.isfinite(value) for value in vector):
|
|
298
|
+
return None, model
|
|
299
|
+
if math.sqrt(sum(value * value for value in vector)) <= 0.0:
|
|
300
|
+
return None, model
|
|
301
|
+
return vector, model
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
def run_algorithm_effectiveness_probe() -> dict[str, Any]:
|
|
305
|
+
"""Run the bounded live probe and return JSON-serializable evidence.
|
|
306
|
+
|
|
307
|
+
Missing index/vector/NumPy prerequisites are reported as ``unavailable``;
|
|
308
|
+
unexpected runtime exceptions are reported as ``error``. A normal run is
|
|
309
|
+
``pass`` only when every required check passes.
|
|
310
|
+
"""
|
|
311
|
+
try:
|
|
312
|
+
index = harness.load_index()
|
|
313
|
+
records = [
|
|
314
|
+
record
|
|
315
|
+
for record in (index.get("records", []) or [])
|
|
316
|
+
if isinstance(record, dict)
|
|
317
|
+
]
|
|
318
|
+
except Exception as exc:
|
|
319
|
+
return _terminal_result("error", f"harness index load failed: {type(exc).__name__}: {exc}")
|
|
320
|
+
|
|
321
|
+
if not records:
|
|
322
|
+
return _terminal_result("unavailable", "harness index has no records")
|
|
323
|
+
if not bool(getattr(harness, "_NUMPY", False)):
|
|
324
|
+
return _terminal_result("unavailable", "NumPy exact-matrix retrieval is unavailable")
|
|
325
|
+
|
|
326
|
+
canonical = next(
|
|
327
|
+
(record for record in records if str(record.get("id") or "") == CANONICAL_ALGO_ID),
|
|
328
|
+
None,
|
|
329
|
+
)
|
|
330
|
+
if canonical is None:
|
|
331
|
+
return _terminal_result("unavailable", f"canonical record is missing: {CANONICAL_ALGO_ID}")
|
|
332
|
+
query_vector, model = _vector_values(canonical)
|
|
333
|
+
if query_vector is None:
|
|
334
|
+
return _terminal_result(
|
|
335
|
+
"unavailable",
|
|
336
|
+
"canonical ALGO record has no valid persisted embedding/model",
|
|
337
|
+
)
|
|
338
|
+
|
|
339
|
+
checks: dict[str, dict[str, Any]] = {}
|
|
340
|
+
embed_calls = 0
|
|
341
|
+
|
|
342
|
+
def deterministic_embed(texts: list[str]) -> list[list[float]]:
|
|
343
|
+
nonlocal embed_calls
|
|
344
|
+
embed_calls += 1
|
|
345
|
+
return [list(query_vector) for _text in texts]
|
|
346
|
+
|
|
347
|
+
try:
|
|
348
|
+
query = _build_probe_query(index, canonical, len(query_vector))
|
|
349
|
+
query_cache_before = harness._QUERY_VEC_CACHE.snapshot()
|
|
350
|
+
|
|
351
|
+
first_results = harness.hybrid_search(
|
|
352
|
+
query,
|
|
353
|
+
deterministic_embed,
|
|
354
|
+
model,
|
|
355
|
+
k=PROBE_RESULT_LIMIT,
|
|
356
|
+
)
|
|
357
|
+
bm25_cache_first = harness._BM25_INDEX_CACHE
|
|
358
|
+
vector_cache_first = harness._VECTOR_MATRIX_CACHE
|
|
359
|
+
|
|
360
|
+
second_results = harness.hybrid_search(
|
|
361
|
+
query,
|
|
362
|
+
deterministic_embed,
|
|
363
|
+
model,
|
|
364
|
+
k=PROBE_RESULT_LIMIT,
|
|
365
|
+
)
|
|
366
|
+
bm25_cache_second = harness._BM25_INDEX_CACHE
|
|
367
|
+
vector_cache_second = harness._VECTOR_MATRIX_CACHE
|
|
368
|
+
query_cache_after = harness._QUERY_VEC_CACHE.snapshot()
|
|
369
|
+
|
|
370
|
+
first_canonical = _canonical_result(first_results)
|
|
371
|
+
second_canonical = _canonical_result(second_results)
|
|
372
|
+
first_provenance = (
|
|
373
|
+
first_canonical.get("rank_provenance", {})
|
|
374
|
+
if isinstance(first_canonical, dict)
|
|
375
|
+
and isinstance(first_canonical.get("rank_provenance"), dict)
|
|
376
|
+
else {}
|
|
377
|
+
)
|
|
378
|
+
second_provenance = (
|
|
379
|
+
second_canonical.get("rank_provenance", {})
|
|
380
|
+
if isinstance(second_canonical, dict)
|
|
381
|
+
and isinstance(second_canonical.get("rank_provenance"), dict)
|
|
382
|
+
else {}
|
|
383
|
+
)
|
|
384
|
+
|
|
385
|
+
lexical_score = float(first_provenance.get("lexical_score") or 0.0)
|
|
386
|
+
keyword_rank = int(first_provenance.get("keyword_rank") or 0)
|
|
387
|
+
bm25_cache_reused = bm25_cache_first is not None and bm25_cache_first is bm25_cache_second
|
|
388
|
+
lexical_consistent = (
|
|
389
|
+
first_provenance.get("keyword_rank") == second_provenance.get("keyword_rank")
|
|
390
|
+
and first_provenance.get("lexical_score") == second_provenance.get("lexical_score")
|
|
391
|
+
)
|
|
392
|
+
checks["bm25_lexical"] = _check(
|
|
393
|
+
first_canonical is not None
|
|
394
|
+
and second_canonical is not None
|
|
395
|
+
and keyword_rank >= 1
|
|
396
|
+
and lexical_score > 0.0
|
|
397
|
+
and bm25_cache_reused
|
|
398
|
+
and lexical_consistent,
|
|
399
|
+
{
|
|
400
|
+
"canonical_id": CANONICAL_ALGO_ID,
|
|
401
|
+
"keyword_rank": keyword_rank,
|
|
402
|
+
"lexical_score": lexical_score,
|
|
403
|
+
"provenance_present": bool(first_provenance),
|
|
404
|
+
"cache_reused": bm25_cache_reused,
|
|
405
|
+
"cache_rows": _cache_rows(bm25_cache_second),
|
|
406
|
+
"repeat_provenance_consistent": lexical_consistent,
|
|
407
|
+
},
|
|
408
|
+
"canonical lexical provenance was absent/non-positive or the BM25 corpus cache was rebuilt",
|
|
409
|
+
)
|
|
410
|
+
|
|
411
|
+
vector_score = float(first_provenance.get("vector_score") or 0.0)
|
|
412
|
+
matrix_cache_reused = (
|
|
413
|
+
vector_cache_first is not None and vector_cache_first is vector_cache_second
|
|
414
|
+
)
|
|
415
|
+
matrix_rows, matrix_dimensions = _matrix_dimensions(vector_cache_second)
|
|
416
|
+
vector_consistent = (
|
|
417
|
+
first_provenance.get("vector_rank") == second_provenance.get("vector_rank")
|
|
418
|
+
and first_provenance.get("vector_score") == second_provenance.get("vector_score")
|
|
419
|
+
)
|
|
420
|
+
checks["exact_vector"] = _check(
|
|
421
|
+
first_canonical is not None
|
|
422
|
+
and second_canonical is not None
|
|
423
|
+
and vector_score >= EXACT_VECTOR_MIN_SCORE
|
|
424
|
+
and matrix_cache_reused
|
|
425
|
+
and matrix_rows > 0
|
|
426
|
+
and matrix_dimensions == len(query_vector)
|
|
427
|
+
and vector_consistent,
|
|
428
|
+
{
|
|
429
|
+
"query_vector_source": CANONICAL_ALGO_ID,
|
|
430
|
+
"model": model,
|
|
431
|
+
"dimensions": len(query_vector),
|
|
432
|
+
"vector_rank": int(first_provenance.get("vector_rank") or 0),
|
|
433
|
+
"vector_score": vector_score,
|
|
434
|
+
"minimum_exact_score": EXACT_VECTOR_MIN_SCORE,
|
|
435
|
+
"matrix_cache_reused": matrix_cache_reused,
|
|
436
|
+
"matrix_rows": matrix_rows,
|
|
437
|
+
"matrix_dimensions": matrix_dimensions,
|
|
438
|
+
"repeat_provenance_consistent": vector_consistent,
|
|
439
|
+
"local_embed_calls": embed_calls,
|
|
440
|
+
},
|
|
441
|
+
"the canonical self-vector was not exact or the normalized matrix cache was rebuilt",
|
|
442
|
+
)
|
|
443
|
+
|
|
444
|
+
embedded, eligible = harness._retrieval_embedding_coverage(
|
|
445
|
+
model,
|
|
446
|
+
harness=None,
|
|
447
|
+
kind=None,
|
|
448
|
+
)
|
|
449
|
+
expected_mode = "rrf" if eligible > 0 and embedded == eligible else "coverage-neutral-rrf"
|
|
450
|
+
expected_coverage = round(embedded / eligible, 6) if eligible else 0.0
|
|
451
|
+
provenances = [
|
|
452
|
+
result.get("rank_provenance", {})
|
|
453
|
+
for result in [*first_results, *second_results]
|
|
454
|
+
if isinstance(result, dict) and isinstance(result.get("rank_provenance"), dict)
|
|
455
|
+
]
|
|
456
|
+
observed_modes = sorted({str(item.get("fusion_mode") or "") for item in provenances})
|
|
457
|
+
observed_coverages = sorted(
|
|
458
|
+
{round(float(item.get("embedding_coverage") or 0.0), 6) for item in provenances}
|
|
459
|
+
)
|
|
460
|
+
first_sources = list(first_canonical.get("rank_sources", [])) if first_canonical else []
|
|
461
|
+
second_sources = list(second_canonical.get("rank_sources", [])) if second_canonical else []
|
|
462
|
+
dual_source = set(first_sources) == {"keyword", "vector"} and set(second_sources) == {
|
|
463
|
+
"keyword",
|
|
464
|
+
"vector",
|
|
465
|
+
}
|
|
466
|
+
raw_rrf = float(first_provenance.get("rrf_raw_score") or 0.0)
|
|
467
|
+
fused_rrf = float(first_provenance.get("rrf_score") or 0.0)
|
|
468
|
+
expected_fused = raw_rrf if expected_mode == "rrf" else raw_rrf / 2.0
|
|
469
|
+
rrf_arithmetic_valid = math.isclose(fused_rrf, expected_fused, abs_tol=1.5e-6)
|
|
470
|
+
result_order_consistent = [item.get("id") for item in first_results] == [
|
|
471
|
+
item.get("id") for item in second_results
|
|
472
|
+
]
|
|
473
|
+
checks["rrf_fusion"] = _check(
|
|
474
|
+
first_canonical is not None
|
|
475
|
+
and second_canonical is not None
|
|
476
|
+
and eligible > 0
|
|
477
|
+
and observed_modes == [expected_mode]
|
|
478
|
+
and observed_coverages == [expected_coverage]
|
|
479
|
+
and dual_source
|
|
480
|
+
and rrf_arithmetic_valid
|
|
481
|
+
and result_order_consistent,
|
|
482
|
+
{
|
|
483
|
+
"embedded": embedded,
|
|
484
|
+
"eligible": eligible,
|
|
485
|
+
"expected_mode": expected_mode,
|
|
486
|
+
"observed_modes": observed_modes,
|
|
487
|
+
"expected_coverage": expected_coverage,
|
|
488
|
+
"observed_coverages": observed_coverages,
|
|
489
|
+
"canonical_rank_sources": first_sources,
|
|
490
|
+
"dual_source_provenance": dual_source,
|
|
491
|
+
"rrf_raw_score": raw_rrf,
|
|
492
|
+
"rrf_score": fused_rrf,
|
|
493
|
+
"rrf_arithmetic_valid": rrf_arithmetic_valid,
|
|
494
|
+
"repeat_result_order_consistent": result_order_consistent,
|
|
495
|
+
"result_count": len(first_results),
|
|
496
|
+
},
|
|
497
|
+
"RRF mode/coverage, dual-source provenance, or repeat ordering was inconsistent",
|
|
498
|
+
)
|
|
499
|
+
|
|
500
|
+
checks["stable_top_k"] = _top_k_parity_check()
|
|
501
|
+
checks["window_tinylfu"] = _query_cache_check(query_cache_before, query_cache_after)
|
|
502
|
+
checks["embedding_priority"] = _embedding_priority_check(model, len(records))
|
|
503
|
+
checks["memory_admission"] = _memory_admission_check()
|
|
504
|
+
except Exception as exc:
|
|
505
|
+
reason = f"production-path probe failed: {type(exc).__name__}: {exc}"
|
|
506
|
+
for name in REQUIRED_CHECKS:
|
|
507
|
+
checks.setdefault(
|
|
508
|
+
name,
|
|
509
|
+
{
|
|
510
|
+
"status": "error",
|
|
511
|
+
"required": True,
|
|
512
|
+
"reason": reason,
|
|
513
|
+
"evidence": {},
|
|
514
|
+
},
|
|
515
|
+
)
|
|
516
|
+
return {
|
|
517
|
+
"schema_version": PROBE_SCHEMA_VERSION,
|
|
518
|
+
"probe": PROBE_NAME,
|
|
519
|
+
"status": "error",
|
|
520
|
+
"reason": reason,
|
|
521
|
+
"required_checks": list(REQUIRED_CHECKS),
|
|
522
|
+
"summary": {
|
|
523
|
+
"required": len(REQUIRED_CHECKS),
|
|
524
|
+
"passed": sum(item.get("status") == "pass" for item in checks.values()),
|
|
525
|
+
"error": sum(item.get("status") == "error" for item in checks.values()),
|
|
526
|
+
},
|
|
527
|
+
"checks": checks,
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
passed = sum(check.get("status") == "pass" for check in checks.values())
|
|
531
|
+
overall_status = "pass" if passed == len(REQUIRED_CHECKS) else "fail"
|
|
532
|
+
return {
|
|
533
|
+
"schema_version": PROBE_SCHEMA_VERSION,
|
|
534
|
+
"probe": PROBE_NAME,
|
|
535
|
+
"status": overall_status,
|
|
536
|
+
"reason": "" if overall_status == "pass" else "one or more required algorithm checks failed",
|
|
537
|
+
"index": {
|
|
538
|
+
"generated": str(index.get("generated") or ""),
|
|
539
|
+
"record_count": len(records),
|
|
540
|
+
"canonical_id": CANONICAL_ALGO_ID,
|
|
541
|
+
"embedding_model": model,
|
|
542
|
+
"embedding_dimensions": len(query_vector),
|
|
543
|
+
},
|
|
544
|
+
"required_checks": list(REQUIRED_CHECKS),
|
|
545
|
+
"summary": {
|
|
546
|
+
"required": len(REQUIRED_CHECKS),
|
|
547
|
+
"passed": passed,
|
|
548
|
+
"failed": len(REQUIRED_CHECKS) - passed,
|
|
549
|
+
},
|
|
550
|
+
"checks": checks,
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+
__all__ = [
|
|
555
|
+
"CANONICAL_ALGO_ID",
|
|
556
|
+
"PROBE_NAME",
|
|
557
|
+
"PROBE_SCHEMA_VERSION",
|
|
558
|
+
"REQUIRED_CHECKS",
|
|
559
|
+
"run_algorithm_effectiveness_probe",
|
|
560
|
+
]
|