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,224 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: qol-algorithms
|
|
3
|
+
description: Quality-of-life algorithm patterns for Algo CLI that reduce friction, prevent common errors, and improve terminal UX.
|
|
4
|
+
tags: [algo-cli, qol, algorithms, ux, fuzzy-matching, configuration, suggestions]
|
|
5
|
+
created: 2026-07-02
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Quality of Life (QoL) Algorithms
|
|
9
|
+
|
|
10
|
+
A compact catalog of medium-priority UX algorithms for Algo CLI. They don't change retrieval correctness, but they make the terminal feel faster, safer, and more forgiving.
|
|
11
|
+
|
|
12
|
+
## 1. Fuzzy Slash-Command Matcher
|
|
13
|
+
|
|
14
|
+
**Use for:** turning typos like `/selfcehck`, `/harnes`, or `/modle-check` into "Did you mean `/selfcheck`, `/harness`, `/model-check`?"
|
|
15
|
+
|
|
16
|
+
**Algorithm:**
|
|
17
|
+
|
|
18
|
+
```text
|
|
19
|
+
candidates = all registered slash commands + aliases
|
|
20
|
+
for candidate in candidates:
|
|
21
|
+
d = Damerau-Levenshtein distance(query, candidate)
|
|
22
|
+
score = 1 - d / max(len(query), len(candidate))
|
|
23
|
+
rank by score descending, filter score >= 0.6
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**Why it matters:**
|
|
27
|
+
|
|
28
|
+
- Users type fast in a terminal; a single transposition shouldn't fail silently.
|
|
29
|
+
- Damerau-Levenshtein handles adjacent swaps (`selfcehck` → `selfcheck`) better than plain Levenshtein.
|
|
30
|
+
- A ranked suggestion is safer than silent auto-correction.
|
|
31
|
+
|
|
32
|
+
**Harness contract:**
|
|
33
|
+
|
|
34
|
+
- Input: mistyped slash command string, registered command list.
|
|
35
|
+
- Output: zero or more suggestions with confidence scores.
|
|
36
|
+
- Telemetry: typo count, accepted suggestion, fallback to unknown-command handler.
|
|
37
|
+
|
|
38
|
+
**Tests:**
|
|
39
|
+
|
|
40
|
+
- `/selfcehck` suggests `/selfcheck` with score >= 0.8.
|
|
41
|
+
- `/harnes` suggests `/harness` before `/harness-search`.
|
|
42
|
+
- `/totally-unknown` returns no suggestions and falls through.
|
|
43
|
+
- Suggestions are deterministic for a fixed command registry.
|
|
44
|
+
|
|
45
|
+
## 2. Layered Configuration Precedence
|
|
46
|
+
|
|
47
|
+
**Use for:** resolving defaults, config file values, environment variables, and per-command flags without surprising overrides.
|
|
48
|
+
|
|
49
|
+
**Precedence (lowest to highest):**
|
|
50
|
+
|
|
51
|
+
```text
|
|
52
|
+
built-in default
|
|
53
|
+
config file (algo_cli/config.json)
|
|
54
|
+
environment variable (ALGO_CLI_*)
|
|
55
|
+
per-command flag / runtime override
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**Why it matters:**
|
|
59
|
+
|
|
60
|
+
- Smart defaults reduce setup friction.
|
|
61
|
+
- A clear precedence order prevents "why didn't my env var work?" bugs.
|
|
62
|
+
- Makes telemetry reproducible: log the winning source for each setting.
|
|
63
|
+
|
|
64
|
+
**Harness contract:**
|
|
65
|
+
|
|
66
|
+
- Input: setting name, default value, config dict, env mapping, CLI overrides.
|
|
67
|
+
- Output: resolved value plus source provenance.
|
|
68
|
+
- Telemetry: override source counts, unknown config keys.
|
|
69
|
+
|
|
70
|
+
**Tests:**
|
|
71
|
+
|
|
72
|
+
- Default wins when no other source provides the value.
|
|
73
|
+
- Env var overrides config file.
|
|
74
|
+
- Runtime flag overrides env var.
|
|
75
|
+
- Unknown config keys are warned, not silently ignored.
|
|
76
|
+
|
|
77
|
+
## 3. Progressive Command Aliases
|
|
78
|
+
|
|
79
|
+
**Use for:** letting users type short, memorable forms (`/hs` for `/harness-search`, `/m` for `/model`) without fragmenting the command namespace.
|
|
80
|
+
|
|
81
|
+
**Algorithm:**
|
|
82
|
+
|
|
83
|
+
```text
|
|
84
|
+
alias_map = {
|
|
85
|
+
"hs": "harness-search",
|
|
86
|
+
"m": "model",
|
|
87
|
+
...
|
|
88
|
+
}
|
|
89
|
+
resolve(input):
|
|
90
|
+
if input in alias_map: return alias_map[input]
|
|
91
|
+
if input is a registered command: return input
|
|
92
|
+
else: pass to fuzzy matcher
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**Why it matters:**
|
|
96
|
+
|
|
97
|
+
- Reduces keystrokes for power users.
|
|
98
|
+
- Keeps help text and telemetry canonical by expanding aliases early.
|
|
99
|
+
- Avoids the trap of many near-duplicate commands.
|
|
100
|
+
|
|
101
|
+
**Harness contract:**
|
|
102
|
+
|
|
103
|
+
- Input: raw slash command token.
|
|
104
|
+
- Output: canonical command name or unknown.
|
|
105
|
+
- Telemetry: alias expansion count, collisions.
|
|
106
|
+
|
|
107
|
+
**Tests:**
|
|
108
|
+
|
|
109
|
+
- `/hs` resolves to `/harness-search`.
|
|
110
|
+
- Unknown alias falls through to fuzzy matcher.
|
|
111
|
+
- Alias-to-alias chains are flattened or rejected.
|
|
112
|
+
- Help text lists aliases next to canonical names.
|
|
113
|
+
|
|
114
|
+
## 4. History-Aware Command Suggestions
|
|
115
|
+
|
|
116
|
+
**Use for:** surfacing likely next commands based on the current session's command history.
|
|
117
|
+
|
|
118
|
+
**Algorithm:**
|
|
119
|
+
|
|
120
|
+
```text
|
|
121
|
+
score(cmd) = recency_weight * last_used_seconds_ago^-1
|
|
122
|
+
+ frequency_weight * count_in_session
|
|
123
|
+
+ context_weight * co_occurrence_with_last_cmd
|
|
124
|
+
return top-k, deduplicated
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
**Why it matters:**
|
|
128
|
+
|
|
129
|
+
- Repeating a recently used `/harness-search` or `/model` is common.
|
|
130
|
+
- Recency + frequency beats either signal alone.
|
|
131
|
+
- Context boost helps after multi-step workflows (e.g., `/google-login` → `/google-status`).
|
|
132
|
+
|
|
133
|
+
**Harness contract:**
|
|
134
|
+
|
|
135
|
+
- Input: session command history, current command, k.
|
|
136
|
+
- Output: ranked suggestion list.
|
|
137
|
+
- Telemetry: suggestion acceptance rate, history length.
|
|
138
|
+
|
|
139
|
+
**Tests:**
|
|
140
|
+
|
|
141
|
+
- Most recent unique command appears first.
|
|
142
|
+
- Frequent but stale command is ranked below recent frequent command.
|
|
143
|
+
- Suggestions exclude the command just typed.
|
|
144
|
+
- Empty history returns defaults or nothing.
|
|
145
|
+
|
|
146
|
+
## 5. Confidence-Gated Auto-Correction
|
|
147
|
+
|
|
148
|
+
**Use for:** automatically fixing low-risk typos (command names, common flag values) while asking the user when confidence is low.
|
|
149
|
+
|
|
150
|
+
**Algorithm:**
|
|
151
|
+
|
|
152
|
+
```text
|
|
153
|
+
if best_suggestion.score >= high_threshold (e.g. 0.85):
|
|
154
|
+
auto-correct and run
|
|
155
|
+
elif best_suggestion.score >= low_threshold (e.g. 0.60):
|
|
156
|
+
prompt user: "Did you mean X? [y/n]"
|
|
157
|
+
else:
|
|
158
|
+
report unknown command
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
**Why it matters:**
|
|
162
|
+
|
|
163
|
+
- High-confidence corrections save keystrokes.
|
|
164
|
+
- Low-confidence guesses are destructive if applied silently.
|
|
165
|
+
- A threshold makes the behavior testable and tunable.
|
|
166
|
+
|
|
167
|
+
**Harness contract:**
|
|
168
|
+
|
|
169
|
+
- Input: raw input, suggestion list, high/low thresholds.
|
|
170
|
+
- Output: corrected input, prompt, or error.
|
|
171
|
+
- Telemetry: auto-correct count, prompt count, rejection count, threshold breaches.
|
|
172
|
+
|
|
173
|
+
**Tests:**
|
|
174
|
+
|
|
175
|
+
- Score 0.90 auto-corrects without prompt.
|
|
176
|
+
- Score 0.70 prompts user.
|
|
177
|
+
- Score 0.40 reports unknown.
|
|
178
|
+
- Thresholds are configurable per command class.
|
|
179
|
+
|
|
180
|
+
## 6. Mojibake Fixer
|
|
181
|
+
|
|
182
|
+
**Use for:** cleaning UTF-8 display artifacts (`·`, `…`, `’`, `“`) in harness output.
|
|
183
|
+
|
|
184
|
+
**Algorithm:** Detect windows-1252 mojibake in otherwise UTF-8 text and replace the byte sequence with the intended Unicode glyph.
|
|
185
|
+
|
|
186
|
+
**Tests:**
|
|
187
|
+
|
|
188
|
+
- `algo-cli · wiki ·` becomes `algo-cli · wiki ·`.
|
|
189
|
+
- `periodic…` becomes `periodic…`.
|
|
190
|
+
- `don’t` becomes `don't`.
|
|
191
|
+
|
|
192
|
+
## 7. Relevance Threshold Filter
|
|
193
|
+
|
|
194
|
+
**Use for:** suppressing `## Relevant Context` blocks when none of the top-k records are actually relevant.
|
|
195
|
+
|
|
196
|
+
**Algorithm:**
|
|
197
|
+
|
|
198
|
+
```text
|
|
199
|
+
filtered = [r for r in ranked if r.score >= min_relevance]
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
**Tests:**
|
|
203
|
+
|
|
204
|
+
- If all scores < 0.3, return empty list.
|
|
205
|
+
- If top record > 0.7, include all above 0.3.
|
|
206
|
+
- Log filtered records for debugging.
|
|
207
|
+
|
|
208
|
+
## 8. Probe Query Linter
|
|
209
|
+
|
|
210
|
+
**Use for:** validating `/selfcheck` probe queries are real indexed records.
|
|
211
|
+
|
|
212
|
+
**Algorithm:** Run each probe query through `harness_search`; mark invalid any query that returns no matches.
|
|
213
|
+
|
|
214
|
+
**Tests:**
|
|
215
|
+
|
|
216
|
+
- `index-compute-lab` → valid.
|
|
217
|
+
- A retired synthetic label → invalid (no matching record).
|
|
218
|
+
- Log invalid queries to suggest replacements.
|
|
219
|
+
|
|
220
|
+
## References
|
|
221
|
+
|
|
222
|
+
- Full spec and harness contracts: `docs/ALGO.reviewed.md` Track B.
|
|
223
|
+
- Fuzzy matching background: Levenshtein and Damerau-Levenshtein edit distance.
|
|
224
|
+
- UX inspiration: fzf, git's DWIM mistyped-command wrapper, smart_config layered defaults.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: smart-error-recovery
|
|
3
|
+
description: When a tool returns an error, classify it and pick the right recovery path: tighten input, change tools, ask the user, or escalate to /reason reflexion.
|
|
4
|
+
tags: [algo-cli, error-handling, recovery, reflexion]
|
|
5
|
+
created: 2026-06-09
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Smart Error Recovery
|
|
9
|
+
|
|
10
|
+
## Trigger
|
|
11
|
+
|
|
12
|
+
Whenever a tool call returns a string starting with `Error:`.
|
|
13
|
+
|
|
14
|
+
## Steps
|
|
15
|
+
|
|
16
|
+
1. **Read the error string verbatim.** It usually contains a hint
|
|
17
|
+
(e.g. "matched 2 locations" means "tighten old_string" or
|
|
18
|
+
"pass replace_all=True"; "old_string not found" means "re-read
|
|
19
|
+
the file and check whitespace").
|
|
20
|
+
2. **Classify** the error:
|
|
21
|
+
- *Transient* (network, model timeout): retry once with same args,
|
|
22
|
+
then with timeout bump, then escalate to user.
|
|
23
|
+
- *Input validation* (empty, ambiguous, missing file): adjust the
|
|
24
|
+
input and retry.
|
|
25
|
+
- *Permission denied* (`tool_denied` event, approval needed):
|
|
26
|
+
stop and ask the user, or check whether `/auto` is on.
|
|
27
|
+
- *Logical* (no search results, hypothesis wrong): switch tools
|
|
28
|
+
or change approach.
|
|
29
|
+
3. **If the same tool fails twice in a row:** switch tools or change
|
|
30
|
+
strategy. Don't keep retrying the same broken call.
|
|
31
|
+
4. **If 3+ different tools have failed on the same goal:** switch to
|
|
32
|
+
`/reason reflexion` mode, or stop and ask the user for guidance.
|
|
33
|
+
5. **Always narrate the recovery** in the user-facing answer:
|
|
34
|
+
"I tried X, got Y, so I tried Z instead."
|
|
35
|
+
|
|
36
|
+
## Key Discoveries
|
|
37
|
+
|
|
38
|
+
- The 2,000-character tool-result cap in `tools.MAX_TOOL_RESULT` is
|
|
39
|
+
per-call. For large matches, narrow the search with `glob=` and
|
|
40
|
+
`path=` arguments rather than asking for everything at once.
|
|
41
|
+
- `harness_search` returns "No harness matches" for both "nothing in
|
|
42
|
+
the index" and "all matches were excluded by kind filter". Try
|
|
43
|
+
`kind=None` first to see what's there.
|
|
44
|
+
- `run_shell` has a hard 120s cap regardless of `timeout=` argument.
|
|
45
|
+
Long-running commands need to be backgrounded and polled, not timed
|
|
46
|
+
out at 600s and hoped for.
|
|
47
|
+
- `edit_file` is the highest-leverage recovery tool: when a `write_file`
|
|
48
|
+
call returns "file already exists" or "you need to read the file first",
|
|
49
|
+
switch to `edit_file` with the exact existing string instead.
|
|
50
|
+
- `session_command` errors with EOFError mean the user typed `/exit` —
|
|
51
|
+
do not retry, the session is over.
|
|
52
|
+
|
|
53
|
+
## Environment
|
|
54
|
+
|
|
55
|
+
algo-cli only. These heuristics are encoded in the system prompt
|
|
56
|
+
verification_layer; this skill captures the long-form reasoning.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: tool-selection-cheatsheet
|
|
3
|
+
description: Quick reference for picking the right tool — read vs search vs harness_search, edit_file vs write_file, run_shell vs session_command.
|
|
4
|
+
tags: [algo-cli, tool-selection, cheatsheet, productivity]
|
|
5
|
+
created: 2026-06-09
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Tool Selection Cheatsheet
|
|
9
|
+
|
|
10
|
+
## Trigger
|
|
11
|
+
|
|
12
|
+
When you are about to call a tool and are not 100% sure which one to use.
|
|
13
|
+
|
|
14
|
+
## Steps
|
|
15
|
+
|
|
16
|
+
1. If you are looking for **a known file** by path → `read_file` (or
|
|
17
|
+
`session_slash /read` for deterministic cwd-relative).
|
|
18
|
+
2. If you are looking for **a fact or string** inside any file →
|
|
19
|
+
`search_files` for direct grep, OR `harness_search` first if the
|
|
20
|
+
fact might be in a skill/memory/wiki.
|
|
21
|
+
3. If you are looking for **a workflow or how-to** → `harness_search
|
|
22
|
+
(kind="skill")` first. Use `query_knowledge_graph` for project/entity
|
|
23
|
+
relations only when `/icl status` reports that integration enabled and ready.
|
|
24
|
+
4. If you need to **change a single specific thing in an existing file**
|
|
25
|
+
→ `edit_file` (find/replace) with 2-5 lines of context.
|
|
26
|
+
5. If you need to **create a new file** → `write_file` (no overwrite).
|
|
27
|
+
6. If you need to **rewrite most of an existing file** → `write_file` with
|
|
28
|
+
`overwrite=True` after re-reading the target.
|
|
29
|
+
7. If you need to **run tests/builds/lint/diff/grep** → `run_shell` (safe
|
|
30
|
+
in requires_change blocks; mutations are flagged for approval).
|
|
31
|
+
8. If you need to **change session state** (model, theme, context,
|
|
32
|
+
harness refresh, route preview) → `session_command` (`/status`,
|
|
33
|
+
`/mode execute`, `/context status`, `/harness refresh`, `/route TASK`).
|
|
34
|
+
9. If you need to **fetch a URL or search the web** → `web_search` /
|
|
35
|
+
`web_fetch` (requires OLLAMA_API_KEY for Ollama Cloud).
|
|
36
|
+
10. If you are **unsure what to use** → `available_actions(topic="...")`
|
|
37
|
+
returns the relevant tools + slash commands for any focus area.
|
|
38
|
+
|
|
39
|
+
## Key Discoveries
|
|
40
|
+
|
|
41
|
+
- `edit_file` is preferred over `write_file` for ANY change to an existing
|
|
42
|
+
file. The cost is the same, but edit_file reports the affected line
|
|
43
|
+
range, fails on ambiguous matches, and uses fewer tokens (you don't
|
|
44
|
+
have to read+echo the whole file).
|
|
45
|
+
- `session_slash` is preferred over `read_file` when the path is
|
|
46
|
+
cwd-relative and the user named the file in a `/read`-style request.
|
|
47
|
+
It honors `/cd` state.
|
|
48
|
+
- `query_knowledge_graph` can be faster and more relevant than
|
|
49
|
+
`harness_search` for project/entity questions when the user enabled and
|
|
50
|
+
populated index-compute-lab. Use it for relationship questions about entities.
|
|
51
|
+
- `harness_search` is preferred over `search_files` when the file
|
|
52
|
+
might be in a skill/memory/wiki, because the indexer has already
|
|
53
|
+
parsed frontmatter and scored relevance. `search_files` is the
|
|
54
|
+
right call for raw code/text/grep across the workspace.
|
|
55
|
+
- `available_actions(topic="...")` is the meta-tool: if you find
|
|
56
|
+
yourself guessing, call it. Topics: files, shell, web, memory,
|
|
57
|
+
harness, models, reasoning, slash, documents, multimodal.
|
|
58
|
+
- `run_shell` mutations are audited and may be blocked. The `requires_change`
|
|
59
|
+
block tells you which shell commands count as mutations; everything
|
|
60
|
+
else (read-only) is fine.
|
|
61
|
+
|
|
62
|
+
## Environment
|
|
63
|
+
|
|
64
|
+
algo-cli >= 0.4. The tool inventory in `available_actions` is the
|
|
65
|
+
authoritative list; this skill captures the selection heuristics.
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"""Deterministic bounded ranking primitives used by harness retrieval."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import heapq
|
|
6
|
+
import math
|
|
7
|
+
import re
|
|
8
|
+
from collections import Counter
|
|
9
|
+
from collections.abc import Callable, Sequence
|
|
10
|
+
from typing import TypeVar
|
|
11
|
+
|
|
12
|
+
T = TypeVar("T")
|
|
13
|
+
|
|
14
|
+
TOKEN_RE = re.compile(r"[\w.-]+", re.UNICODE)
|
|
15
|
+
FULL_SORT_THRESHOLD = 8_192
|
|
16
|
+
MOJIBAKE_REPLACEMENTS = (
|
|
17
|
+
("·", "·"),
|
|
18
|
+
("…", "…"),
|
|
19
|
+
("’", "’"),
|
|
20
|
+
("“", "“"),
|
|
21
|
+
("â€", "”"),
|
|
22
|
+
("–", "–"),
|
|
23
|
+
("—", "—"),
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def lexical_tokens(text: str) -> list[str]:
|
|
28
|
+
"""Return normalized lexical tokens shared by BM25 and query parsing."""
|
|
29
|
+
return [token.lower() for token in TOKEN_RE.findall(text or "") if len(token) > 1]
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def repair_mojibake(text: str) -> str:
|
|
33
|
+
"""Repair common UTF-8-as-Windows-1252 artifacts at display boundaries."""
|
|
34
|
+
repaired = str(text or "")
|
|
35
|
+
for broken, replacement in MOJIBAKE_REPLACEMENTS:
|
|
36
|
+
repaired = repaired.replace(broken, replacement)
|
|
37
|
+
return repaired
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def bm25_scores(
|
|
41
|
+
documents: Sequence[str],
|
|
42
|
+
query_terms: Sequence[str],
|
|
43
|
+
*,
|
|
44
|
+
k1: float = 1.5,
|
|
45
|
+
b: float = 0.75,
|
|
46
|
+
) -> list[float]:
|
|
47
|
+
"""Score documents with Okapi BM25 using a query-local in-memory corpus."""
|
|
48
|
+
return BM25Index(documents, k1=k1, b=b).scores(query_terms)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class BM25Index:
|
|
52
|
+
"""Reusable exact BM25 corpus statistics for repeated queries."""
|
|
53
|
+
|
|
54
|
+
def __init__(
|
|
55
|
+
self,
|
|
56
|
+
documents: Sequence[str],
|
|
57
|
+
*,
|
|
58
|
+
k1: float = 1.5,
|
|
59
|
+
b: float = 0.75,
|
|
60
|
+
) -> None:
|
|
61
|
+
self.k1 = float(k1)
|
|
62
|
+
self.b = float(b)
|
|
63
|
+
self._counters = [Counter(lexical_tokens(document)) for document in documents]
|
|
64
|
+
self._lengths = [sum(counter.values()) for counter in self._counters]
|
|
65
|
+
self._average_length = sum(self._lengths) / max(1, len(self._lengths))
|
|
66
|
+
self._document_frequency: Counter[str] = Counter()
|
|
67
|
+
for counter in self._counters:
|
|
68
|
+
self._document_frequency.update(counter.keys())
|
|
69
|
+
|
|
70
|
+
def scores(self, query_terms: Sequence[str]) -> list[float]:
|
|
71
|
+
terms = tuple(dict.fromkeys(term.lower() for term in query_terms if term))
|
|
72
|
+
if not terms:
|
|
73
|
+
return [0.0] * len(self._counters)
|
|
74
|
+
|
|
75
|
+
document_count = len(self._counters)
|
|
76
|
+
if document_count == 0:
|
|
77
|
+
return []
|
|
78
|
+
scores: list[float] = []
|
|
79
|
+
for counter, length in zip(self._counters, self._lengths):
|
|
80
|
+
score = 0.0
|
|
81
|
+
length_normalizer = (
|
|
82
|
+
1.0 - self.b + self.b * length / max(1.0, self._average_length)
|
|
83
|
+
)
|
|
84
|
+
for term in terms:
|
|
85
|
+
frequency = counter.get(term, 0)
|
|
86
|
+
if frequency <= 0:
|
|
87
|
+
continue
|
|
88
|
+
df = self._document_frequency.get(term, 0)
|
|
89
|
+
inverse_document_frequency = math.log(
|
|
90
|
+
1.0 + (document_count - df + 0.5) / (df + 0.5)
|
|
91
|
+
)
|
|
92
|
+
score += inverse_document_frequency * (
|
|
93
|
+
frequency * (self.k1 + 1.0)
|
|
94
|
+
/ (frequency + self.k1 * length_normalizer)
|
|
95
|
+
)
|
|
96
|
+
scores.append(score)
|
|
97
|
+
return scores
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def stable_top_k(items: Sequence[T], k: int, score: Callable[[T], float]) -> list[T]:
|
|
101
|
+
"""Return stable top-k with the faster strategy for the candidate scale.
|
|
102
|
+
|
|
103
|
+
CPython's C-backed Timsort wins on the harness's bounded (<=4k) pools;
|
|
104
|
+
heap selection wins once pools are materially larger. Keep the crossover
|
|
105
|
+
explicit so a theoretically better complexity does not slow the live path.
|
|
106
|
+
"""
|
|
107
|
+
limit = max(0, int(k))
|
|
108
|
+
if limit == 0 or not items:
|
|
109
|
+
return []
|
|
110
|
+
if len(items) <= FULL_SORT_THRESHOLD:
|
|
111
|
+
return sorted(items, key=score, reverse=True)[:limit]
|
|
112
|
+
ranked = heapq.nlargest(
|
|
113
|
+
min(limit, len(items)),
|
|
114
|
+
enumerate(items),
|
|
115
|
+
key=lambda pair: (score(pair[1]), -pair[0]),
|
|
116
|
+
)
|
|
117
|
+
return [item for _index, item in ranked]
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
__all__ = [
|
|
121
|
+
"FULL_SORT_THRESHOLD",
|
|
122
|
+
"BM25Index",
|
|
123
|
+
"bm25_scores",
|
|
124
|
+
"lexical_tokens",
|
|
125
|
+
"repair_mojibake",
|
|
126
|
+
"stable_top_k",
|
|
127
|
+
]
|