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,228 @@
|
|
|
1
|
+
"""Bridge to index-compute-lab ranked association graph for automatic turn context."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
import os
|
|
7
|
+
import subprocess
|
|
8
|
+
import sys
|
|
9
|
+
import time
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from .config import CONFIG_DIR, _atomic_write_text
|
|
12
|
+
|
|
13
|
+
MAX_INJECT_CHARS = 4_000
|
|
14
|
+
QUERY_TIMEOUT_SECONDS = 12.0
|
|
15
|
+
DEFAULT_LIMIT = 6
|
|
16
|
+
|
|
17
|
+
_GRAPH_REBRAND_NOTE = (
|
|
18
|
+
"Note: canonical product concept in the graph is concept:algo-cli; "
|
|
19
|
+
"ollama-cli / ollama-cli-concept in output are legacy cluster labels only. "
|
|
20
|
+
"Current product: Algo CLI (`algo-cli`, package `algo_cli`). Prefer algo-cli for new work.\n\n"
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
# (question_hash, ranked_mtime_ns) -> (monotonic_expiry, text)
|
|
24
|
+
_QUERY_CACHE: dict[tuple[str, int], tuple[float, str]] = {}
|
|
25
|
+
_CACHE_TTL_SECONDS = 120.0
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def resolve_lab_root() -> Path:
|
|
29
|
+
explicit = (
|
|
30
|
+
os.environ.get("ALGO_CLI_INDEX_COMPUTE_LAB_ROOT")
|
|
31
|
+
or os.environ.get("INDEX_COMPUTE_LAB_ROOT")
|
|
32
|
+
)
|
|
33
|
+
if explicit:
|
|
34
|
+
return Path(explicit).expanduser()
|
|
35
|
+
return (Path.home() / "index-compute-lab").expanduser()
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def lab_assets() -> tuple[Path, Path, Path] | None:
|
|
39
|
+
root = resolve_lab_root()
|
|
40
|
+
query_script = root / "query.py"
|
|
41
|
+
ranked = root / "atoms" / "ranked-association-map.json"
|
|
42
|
+
aliases = root / "atoms" / "alias-table.json"
|
|
43
|
+
if not query_script.is_file() or not ranked.is_file() or not aliases.is_file():
|
|
44
|
+
return None
|
|
45
|
+
return root, ranked, aliases
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def lab_available() -> bool:
|
|
49
|
+
return lab_assets() is not None
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def ranked_mtime_ns() -> int:
|
|
53
|
+
assets = lab_assets()
|
|
54
|
+
if assets is None:
|
|
55
|
+
return 0
|
|
56
|
+
try:
|
|
57
|
+
return assets[1].stat().st_mtime_ns
|
|
58
|
+
except OSError:
|
|
59
|
+
return 0
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def run_ask(question: str, *, limit: int = DEFAULT_LIMIT, timeout: float = QUERY_TIMEOUT_SECONDS) -> str:
|
|
63
|
+
"""Run `query.py ask` and return stdout (or error text)."""
|
|
64
|
+
text = (question or "").strip()
|
|
65
|
+
if not text:
|
|
66
|
+
return ""
|
|
67
|
+
assets = lab_assets()
|
|
68
|
+
if assets is None:
|
|
69
|
+
root = resolve_lab_root()
|
|
70
|
+
return f"Error: index-compute-lab not ready under {root} (need query.py + atoms/*.json)"
|
|
71
|
+
root, _ranked, _aliases = assets
|
|
72
|
+
bounded = max(1, min(int(limit), 20))
|
|
73
|
+
command = [sys.executable, str(root / "query.py"), "ask", text, "--limit", str(bounded)]
|
|
74
|
+
try:
|
|
75
|
+
result = subprocess.run(
|
|
76
|
+
command,
|
|
77
|
+
cwd=root,
|
|
78
|
+
capture_output=True,
|
|
79
|
+
text=True,
|
|
80
|
+
encoding="utf-8",
|
|
81
|
+
errors="replace",
|
|
82
|
+
timeout=timeout,
|
|
83
|
+
)
|
|
84
|
+
except subprocess.TimeoutExpired:
|
|
85
|
+
return f"Error: knowledge graph query timed out after {timeout:.0f}s"
|
|
86
|
+
except Exception as exc:
|
|
87
|
+
return f"Error running knowledge graph query: {exc}"
|
|
88
|
+
output = (result.stdout or result.stderr or "").strip()
|
|
89
|
+
if result.returncode != 0:
|
|
90
|
+
return f"Error: knowledge graph query failed ({result.returncode}): {output or 'no output'}"
|
|
91
|
+
return output
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def context_for_query(question: str, *, limit: int = DEFAULT_LIMIT, use_cache: bool = True) -> str:
|
|
95
|
+
"""Ranked-graph context for injection into the user turn (empty if unavailable)."""
|
|
96
|
+
text = (question or "").strip()
|
|
97
|
+
if not text or not lab_available():
|
|
98
|
+
return ""
|
|
99
|
+
mtime = ranked_mtime_ns()
|
|
100
|
+
key = (hashlib.sha256(text.encode("utf-8")).hexdigest()[:16], mtime)
|
|
101
|
+
if use_cache:
|
|
102
|
+
cached = _QUERY_CACHE.get(key)
|
|
103
|
+
if cached and cached[0] > time.monotonic():
|
|
104
|
+
return cached[1]
|
|
105
|
+
raw = run_ask(text, limit=limit)
|
|
106
|
+
if raw and "Filtered edges (0):" in raw and "aggregated)" in raw:
|
|
107
|
+
fallback = run_ask(f"about {text}", limit=limit, timeout=QUERY_TIMEOUT_SECONDS)
|
|
108
|
+
if fallback and not fallback.startswith("Error:") and "Co-occurring" in fallback:
|
|
109
|
+
raw = fallback
|
|
110
|
+
if not raw or raw.startswith("Error:"):
|
|
111
|
+
return ""
|
|
112
|
+
if len(raw) > MAX_INJECT_CHARS:
|
|
113
|
+
raw = raw[:MAX_INJECT_CHARS].rstrip() + "\n...[truncated]"
|
|
114
|
+
lower = raw.lower()
|
|
115
|
+
if "ollama-cli" in lower or "ollama_cli" in lower:
|
|
116
|
+
raw = _GRAPH_REBRAND_NOTE + raw
|
|
117
|
+
if use_cache:
|
|
118
|
+
_QUERY_CACHE[key] = (time.monotonic() + _CACHE_TTL_SECONDS, raw)
|
|
119
|
+
return raw
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def atoms_dir() -> Path | None:
|
|
123
|
+
root = resolve_lab_root()
|
|
124
|
+
atoms = root / "atoms"
|
|
125
|
+
return atoms if atoms.is_dir() else None
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def ensure_harness_roots_file() -> bool:
|
|
129
|
+
"""Keep harness_roots.json free of index-compute-lab entries.
|
|
130
|
+
|
|
131
|
+
The live lab path is registered dynamically by harness.all_source_roots()
|
|
132
|
+
via atoms_dir(). Writing the same root into harness_roots.json previously
|
|
133
|
+
double-indexed agent-notes and other atoms markdown. This helper now removes
|
|
134
|
+
any legacy ICL entries so refresh/index stays single-copy.
|
|
135
|
+
"""
|
|
136
|
+
EXTRA = CONFIG_DIR / "harness_roots.json"
|
|
137
|
+
if not EXTRA.exists():
|
|
138
|
+
return False
|
|
139
|
+
try:
|
|
140
|
+
import json
|
|
141
|
+
|
|
142
|
+
loaded = json.loads(EXTRA.read_text(encoding="utf-8"))
|
|
143
|
+
except (OSError, json.JSONDecodeError):
|
|
144
|
+
return False
|
|
145
|
+
if not isinstance(loaded, list):
|
|
146
|
+
return False
|
|
147
|
+
filtered = [
|
|
148
|
+
item
|
|
149
|
+
for item in loaded
|
|
150
|
+
if not (isinstance(item, dict) and str(item.get("harness")) == "index-compute-lab")
|
|
151
|
+
]
|
|
152
|
+
if len(filtered) == len(loaded):
|
|
153
|
+
return False
|
|
154
|
+
if filtered:
|
|
155
|
+
_atomic_write_text(EXTRA, json.dumps(filtered, indent=2) + "\n")
|
|
156
|
+
else:
|
|
157
|
+
try:
|
|
158
|
+
EXTRA.unlink()
|
|
159
|
+
except OSError:
|
|
160
|
+
_atomic_write_text(EXTRA, "[]\n")
|
|
161
|
+
return True
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
PIPELINE_STEPS: tuple[tuple[str, list[str]], ...] = (
|
|
166
|
+
("association_atoms", ["association_atoms.py"]),
|
|
167
|
+
("atom_association_map", ["atom_association_map.py"]),
|
|
168
|
+
("key_index", ["key_index.py"]),
|
|
169
|
+
("normalizer", ["normalizer.py"]),
|
|
170
|
+
("resolver", ["resolver.py"]),
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def _run_lab_script(root: Path, script: str, extra_args: list[str] | None = None, *, timeout: float = 600.0) -> str:
|
|
175
|
+
command = [sys.executable, str(root / script), *(extra_args or [])]
|
|
176
|
+
try:
|
|
177
|
+
result = subprocess.run(
|
|
178
|
+
command,
|
|
179
|
+
cwd=root,
|
|
180
|
+
capture_output=True,
|
|
181
|
+
text=True,
|
|
182
|
+
encoding="utf-8",
|
|
183
|
+
errors="replace",
|
|
184
|
+
timeout=timeout,
|
|
185
|
+
)
|
|
186
|
+
except subprocess.TimeoutExpired:
|
|
187
|
+
return f"Error: timed out running {script}"
|
|
188
|
+
except Exception as exc:
|
|
189
|
+
return f"Error running {script}: {exc}"
|
|
190
|
+
output = ((result.stdout or "") + (result.stderr or "")).strip()
|
|
191
|
+
if result.returncode != 0:
|
|
192
|
+
return f"Error: {script} failed ({result.returncode}): {output or 'no output'}"
|
|
193
|
+
return output or f"OK: {script}"
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def run_pipeline(*, include_removable_seed: bool = False, removable_scopes: list[str] | None = None) -> str:
|
|
197
|
+
"""Run index-compute-lab graph rebuild steps after optional removable re-seed."""
|
|
198
|
+
assets = lab_assets()
|
|
199
|
+
if assets is None:
|
|
200
|
+
return f"Error: index-compute-lab not ready under {resolve_lab_root()}"
|
|
201
|
+
root, _ranked, _aliases = assets
|
|
202
|
+
lines: list[str] = []
|
|
203
|
+
if include_removable_seed:
|
|
204
|
+
args: list[str] = []
|
|
205
|
+
for scope in removable_scopes or []:
|
|
206
|
+
args.extend(["--scope", scope])
|
|
207
|
+
lines.append(_run_lab_script(root, "removable_drive_atoms.py", args, timeout=1800.0))
|
|
208
|
+
for step_name, scripts in PIPELINE_STEPS:
|
|
209
|
+
for script in scripts:
|
|
210
|
+
lines.append(f"## {step_name}")
|
|
211
|
+
lines.append(_run_lab_script(root, script, timeout=1800.0))
|
|
212
|
+
_QUERY_CACHE.clear()
|
|
213
|
+
return "\n".join(lines)
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def write_graph_note(title: str, body: str) -> str:
|
|
217
|
+
"""Write a durable markdown note under atoms/ for harness RAG + human audit."""
|
|
218
|
+
assets = lab_assets()
|
|
219
|
+
if assets is None:
|
|
220
|
+
return f"Error: index-compute-lab not ready under {resolve_lab_root()}"
|
|
221
|
+
root, _ranked, _aliases = assets
|
|
222
|
+
safe = "".join(ch if ch.isalnum() or ch in "-_" else "-" for ch in title.lower()).strip("-") or "note"
|
|
223
|
+
notes_dir = root / "atoms" / "agent-notes"
|
|
224
|
+
notes_dir.mkdir(parents=True, exist_ok=True)
|
|
225
|
+
path = notes_dir / f"{safe}.md"
|
|
226
|
+
text = f"# {title.strip()}\n\n{(body or '').strip()}\n"
|
|
227
|
+
_atomic_write_text(path, text)
|
|
228
|
+
return f"Wrote {path} ({len(text)} chars). Run harness_refresh to embed for retrieval."
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""Inference-engine guidance injected into relevant Agent Block runs."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
_INFERENCE_TERMS = (
|
|
9
|
+
"eosd",
|
|
10
|
+
"entropy-optimal speculative depth",
|
|
11
|
+
"speculative decoding",
|
|
12
|
+
"draft length",
|
|
13
|
+
"alk",
|
|
14
|
+
"alk-delta",
|
|
15
|
+
"alk-d",
|
|
16
|
+
"low-rank kv",
|
|
17
|
+
"kv cache",
|
|
18
|
+
"certified attention",
|
|
19
|
+
"avee",
|
|
20
|
+
"early exit",
|
|
21
|
+
"e-process",
|
|
22
|
+
"cpdi",
|
|
23
|
+
"prefill",
|
|
24
|
+
"decode interleaving",
|
|
25
|
+
"vllm",
|
|
26
|
+
"sglang",
|
|
27
|
+
"inference gateway",
|
|
28
|
+
"inference engine",
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
_WORD_RE = re.compile(r"[a-z0-9][a-z0-9_-]*")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def should_inject(task: str) -> bool:
|
|
35
|
+
"""Return True when a task needs inference-harness architecture guidance."""
|
|
36
|
+
|
|
37
|
+
lowered = (task or "").lower()
|
|
38
|
+
if not lowered.strip():
|
|
39
|
+
return False
|
|
40
|
+
if any(term in lowered for term in _INFERENCE_TERMS):
|
|
41
|
+
return True
|
|
42
|
+
words = set(_WORD_RE.findall(lowered))
|
|
43
|
+
return bool({"decoding", "scheduler", "kv", "attention"} & words and {"harness", "agent", "loop"} & words)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def context_block() -> str:
|
|
47
|
+
"""Prompt block for routing inference-level algorithm work correctly."""
|
|
48
|
+
|
|
49
|
+
return """## Inference Harness Integration Contract
|
|
50
|
+
EOSD, ALK-delta, and AVEE are inference-engine changes, not ordinary API-layer agent behavior. CPDI is a serving scheduler change. Wire them through a two-tier contract:
|
|
51
|
+
|
|
52
|
+
- Harness / agent loop: orchestration, policies, request metadata, telemetry consumption, fallback decisions.
|
|
53
|
+
- Inference gateway: OpenAI/Anthropic-compatible facade that routes to hosted APIs or a local engine and normalizes provenance.
|
|
54
|
+
- Local engine: vLLM/SGLang fork or adapter where decode loop, KV manager, model forward pass, and scheduler changes live.
|
|
55
|
+
|
|
56
|
+
Algorithm placement:
|
|
57
|
+
- EOSD: decode loop before each speculative draft round. Choose k from prefix-observed entropy via calibrated beta_hat = g(H). Expose realized k, acceptance rate, tokens/sec. It is the only lossless optimization here when k is chosen before drafting.
|
|
58
|
+
- ALK-delta: KV cache manager / PagedAttention layer. Keep anchors, low-rank factors, sparse residuals, and expose a per-request certified attention-output perturbation bound. Harness policy may fall back or disable compression when the bound is too high.
|
|
59
|
+
- AVEE: model forward pass with calibrated auxiliary exit heads. Harness supplies risk_delta; engine returns exit-layer telemetry. Use only for open-weight models with calibration.
|
|
60
|
+
- CPDI: serving scheduler. Harness supplies priority_weight; scheduler allocates prefill/decode work using normalized remaining work and emits latency/queue telemetry.
|
|
61
|
+
|
|
62
|
+
Gateway request fields should stay small: model alias, messages, risk_delta, priority_weight, and lossless_required. Gateway response provenance should include realized speedup, EOSD acceptance stats, KV certificate, AVEE exit histogram, scheduler queue/latency data, engine route, and fallback reason when used.
|
|
63
|
+
|
|
64
|
+
Build order for implementation plans:
|
|
65
|
+
1. Stand up a vanilla local-engine route behind the gateway and prove routing, telemetry, and hosted fallback.
|
|
66
|
+
2. Add EOSD first with exact-output regression tests against fixed speculative sampling for deterministic seeds.
|
|
67
|
+
3. Add CPDI scheduler experiments.
|
|
68
|
+
4. Add ALK-delta and AVEE last because they require cache/kernel work and calibration.
|
|
69
|
+
|
|
70
|
+
Do not claim these algorithms can be implemented through hosted Anthropic/OpenAI API calls alone. For user-facing or high-stakes tasks, prefer hosted or uncompressed/full-depth routes unless the local certificate and risk settings satisfy policy."""
|