diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 3932588..cffa876 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,5 +1,6 @@ -# Every toolchain the skill's evaluation fixtures need, so the evals run the same way -# on any machine and stay sandboxed in the container (see SECURITY.md). +# The JDK, Ruby, Python, and C toolchains, and the libraries Swift needs, for running agent +# sessions on projects in those languages, the same way on any machine and sandboxed in the +# container. Node and Rust come from devcontainer.json; Swift from post-create.sh. # Base: the dev container project's Ubuntu image (non-root user "vscode"). FROM mcr.microsoft.com/devcontainers/base:ubuntu-24.04 diff --git a/.devcontainer/post-create.sh b/.devcontainer/post-create.sh index 7c9dab0..0009645 100755 --- a/.devcontainer/post-create.sh +++ b/.devcontainer/post-create.sh @@ -1,12 +1,11 @@ #!/usr/bin/env bash # Runs once when the container is created. Installs what the Dockerfile does not: -# the Claude Code CLI (for running evals) and Swift (for swift-shop). +# the Claude Code CLI (for running agent sessions) and Swift. set -euo pipefail npm install -g @anthropic-ai/claude-code if ! command -v swift > /dev/null; then curl -fsSL https://download.swift.org/swiftly/linux/swiftly-$(uname -m).tar.gz -o /tmp/swiftly.tar.gz tar -xzf /tmp/swiftly.tar.gz -C /tmp - /tmp/swiftly init --quiet-shell-followup --assume-yes || echo "Swift not installed; swift-shop cannot run. See https://www.swift.org/install/linux/" + /tmp/swiftly init --quiet-shell-followup --assume-yes || echo "Swift not installed. See https://www.swift.org/install/linux/" fi echo "Toolchains: $(java -version 2>&1 | head -1); $(ruby -v); $(node -v); $(cargo --version); $(python3 --version)" -echo "Self-test the eval harness (no API cost): evals/selftest.sh" diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index c966d35..7250cf0 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -1,5 +1,5 @@ name: Bug or wrong advice -description: The skill made an agent do something wrong, unsafe, or slower, or the docs or eval scripts are broken. +description: The skill made an agent do something wrong, unsafe, or slower, or the docs are wrong. labels: [bug] body: - type: markdown diff --git a/.gitignore b/.gitignore deleted file mode 100644 index c18dd8d..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -__pycache__/ diff --git a/CHANGELOG.md b/CHANGELOG.md index baa3707..2064a22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,12 +12,32 @@ Versions follow [semantic versioning](https://semver.org): while the major versi - **Before filing a speedup as a behavior change, the agent looks for a version that keeps the behavior:** redo costly work only when its input changed, hand out copies of cached values, take the fast path and fall back to the original where it cannot match (for example, resend a failed batch one item at a time), or read data that something outside the operation may change once per operation. A behavior change is listed only when no such version exists, with each way tried. When the developer declines a behavior change, the agent applies the version that keeps the behavior. - **Changes to how code calls another system are now verifiable.** Batching, deduplicating, or caching calls to a database or service is checked against a fake that implements the collaborator's documented contract (limits, missing items, partial failure, error order), comparing everything callers observe and the requested items as a set. Only behavior the documentation does not settle stays unverified. - **The agent states its mode first, then reads the file for that mode before looking at code** (`WORKFLOW.md` or `WRITING-NEW-CODE.md`), and `DIFFERENTIAL-TESTING.md` before writing differential tests. -- **The agent says when it runs on a small model.** If it knows its model and the model is a small, fast, or low-cost tier, it adds one line after the mode: the skill is tested with coding-tier models such as Claude Sonnet and Opus. -- **New behavior traps,** from changes coding-tier models made in testing: numeric identity in hash keys (`1` against `1.0`), new size limits an optimization introduces, and batched queries that must keep values as bound parameters. In write mode, a cache key must include the user, tenant, and permissions when they change the result. +- **The agent says when it runs on a small model.** If it knows its model and the model is a small, fast, or low-cost tier, it adds one line after the mode: the skill is built for coding-tier models such as Claude Sonnet and Opus. +- **New behavior traps:** numeric identity in hash keys (`1` against `1.0`), new size limits an optimization introduces, and batched queries that must keep values as bound parameters. In write mode, a cache key must include the user, tenant, and permissions when they change the result. - **The A/A run of a differential test is required only when the behavior can vary between runs** (time, randomness, hash or iteration order, concurrency, external systems); deterministic code records "not needed". - **The end-to-end share is its own field** in the apply results and part of each item's prediction. - **One "Reproduce" section can cover every item** in `APPLY-RESULTS.md` when one harness tests them all. +### Fixed + +- **Complexity and behavior claims checked across every skill file, and about 60 corrected.** The ones that could lead an agent to a slower or wrong choice: + - Dijkstra with a heap is slower than the array version on dense graphs. + - A deque does not make inserting in the middle O(1). + - One multi-source BFS gives only the distance to the nearest source. + - Components answer reachability only in undirected graphs. + - A rolling hash returns to O(n·m) when there are many matches. + - De Casteljau evaluation is O(d²), not O(d). + - A Fenwick tree cannot answer subtree minimum or maximum. + - Total unimodularity gives integer solutions only with integer data. + - Welford's method is no more accurate than the two-pass variance. + - Standard cardinality sketches fail after about k adaptive queries, not k². + - Rust's `HashMap` order varies per map, not only per process. + - glibc's `qsort` is stable in practice. + - Python's `median` does no exact arithmetic. + - Java's single-character `split` compiles no regex. + - C build files alone no longer select the C companion file for C++ projects. +- **Citations corrected:** the LCS hardness result (Abboud, Backurs, and Vassilevska Williams), the differential-privacy method for robust streaming (Hassidim et al.), and the author list of the SODA 2026 cardinality-sketch paper. + ### Added - **For contributors:** `docs/ARCHITECTURE.md` (what loads when, where each idea lives), `CONTRIBUTING.md`, issue and pull-request templates, `CODEOWNERS`, and a dev container with the JDK, Ruby, Node, Rust, Python, and Swift toolchains. @@ -26,15 +46,8 @@ Versions follow [semantic versioning](https://semver.org): while the major versi ### Removed -- **The evaluation harness (`evals/`) and the examples (`examples/`),** to be rebuilt per `docs/EVAL-PLAN.md`. Both stay readable in the [repository history](https://github.com/protechnocrats/algorithmic-intelligence/tree/da47e4b), with every round's results. -- **The CI checks that depended on it** (token budgets, cross-references, rule evidence) and `docs/RULE-EVIDENCE.md`. - -### Evaluation - -Results on Claude Opus 5.5 from the rounds since 0.1.0 ([results in the history](https://github.com/protechnocrats/algorithmic-intelligence/tree/da47e4b/evals/results)), graded on every category including a judge reading each session's code and reports: -- Without the skill, Opus applied behavior changes on a general "apply all" in all 3 sessions where this could be scored. With it, Opus held every one for review, in 4 of 4 sessions. -- Bugs were reported to the developer in 4 of 4 sessions with the skill and 0 of 3 without. -- Sessions with the skill cost 1.7 to 3 times as much. +- **The evaluation harness (`evals/`), the examples (`examples/`), and all their results,** including the results quoted in the README and in the 0.1.0 notes below (the published v0.1.0 release page keeps its original notes). The skill will be benchmarked from scratch under `docs/EVAL-PLAN.md`, and only those results will be published. +- **The CI checks that depended on the harness** (token budgets, cross-references, rule evidence), `docs/RULE-EVIDENCE.md`, and the harness's `.gitignore`. ## [0.1.0] - 2026-11-01 @@ -52,14 +65,8 @@ The first release. Install it with `npx skills add https://github.com/protechnoc - **Techniques:** core tables plus 16 domain files (graphs and trees; sequences, DP, search, and NP-hard problems; strings and text; math and numerics; machine learning; images and signals; geometry and CAD; games and simulation; spatial data; hardware and concurrency; data at scale; optimization and scheduling; hostile inputs; distributed systems; queues and latency; specialized data structures). - **Reports:** `OPTIMIZATION-REPORT.md` written once in report mode and never rewritten, `APPLY-RESULTS.md` written once in apply mode, and `BUGS-FOUND.md`. Bugs are documented, never fixed on purpose. Behavior changes are listed for review and marked in the code once approved. -### Evaluation - -- Test projects in Kotlin, TypeScript, Swift, C, Rust, Java, Ruby, and Python with planted cases and answer keys; held-out Python and Ruby projects; grading probes for the Python, TypeScript, Java, and Ruby projects; a headless runner with a spending cap and a stall watchdog; cost, token, and permission-refusal statistics; trigger tests; token budgets; and checks of Kotlin claims the official documentation does not settle. -- Results so far are in `evals/results/`. On the held-out Python project (round 3), report-flow cases passed at 1.00 with the skill against 0.50 without it on Opus 5.5, and 0.83 against 0.39 on Haiku 5.5. On the Java tuning project (rounds 4 to 6, Haiku 5.5, with the skill only) no session changed the code's behavior. - ### Known limitations -- Only Claude Code has been evaluated; the skill is written to be agent-neutral. -- The Java and Ruby projects have no baseline runs yet, the Ruby held-out project has not been run, and the Swift project has not been run on a Swift toolchain. -- Smaller models do not always load the skill for new-code requests from its description alone; the README gives a one-line project instruction that fixes most of it. +- The skill is written to be agent-neutral, but has only been used with Claude Code. +- Smaller models do not always load the skill for new-code requests from its description alone; the README gives a one-line project instruction for this. - Formal verification (proofs, model checking) is the least developed of the skill's roles. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8dc2c2a..7bb4e15 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -19,7 +19,7 @@ Thank you for helping. This project is a skill: Markdown instructions that codin ## Changing the skill - **Put each instruction where it belongs.** A mandatory rule goes in `skills/SKILL.md` and in the file that carries it out. Anything else lives in exactly one file, and others point to it. -- **Write for coding-tier models.** The skill is tested with Claude Sonnet and Opus. Every instruction must be followable without guessing: explicit, no shorthand, and an example where a rule is easy to misread. +- **Write for coding-tier models** such as Claude Sonnet and Opus. Every instruction must be followable without guessing: explicit, no shorthand, and an example where a rule is easy to misread. - **Keep generic files language-neutral.** Name concepts ("an operation that copies a collection"), not one language's functions. Language-specific names belong in `skills/languages/`. - **Keep references whole.** When you rename a file or a section, or renumber a rule, update every link, file name, quoted section name, and rule number that points at it. An agent that follows a reference to nothing skips that step. - **Do not trim instructions to save tokens.** Every file is loaded only when a step names it. Remove repetition, never content. @@ -35,7 +35,7 @@ Use [`skills/languages/GENERIC.md`](skills/languages/GENERIC.md) as the checklis ## Evaluation -The evaluation harness is being rebuilt. [docs/EVAL-PLAN.md](docs/EVAL-PLAN.md) describes what it will test (hostile inputs, security side effects of optimizations, unusual problems, and write mode, on Sonnet and Opus). Earlier rounds and their tooling are in the git history before the `evals/` folder was removed. +A new evaluation harness is being built from scratch. [docs/EVAL-PLAN.md](docs/EVAL-PLAN.md) describes what it will test (hostile inputs, security side effects of optimizations, unusual problems, and write mode, on Sonnet and Opus). ## Toolchains diff --git a/README.md b/README.md index a0de061..ec15d19 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,6 @@ Algorithmic Intelligence (`algorithmic-intelligence`) is a skill for AI coding a Sometimes the best engineering decision is to leave the code alone, and the skill says so when it is. -**See it first:** [a real, unedited report](https://github.com/protechnocrats/algorithmic-intelligence/tree/da47e4b/examples) from one session on a Java project, and one item compared with and without the skill. - ## Quick start ```bash @@ -117,7 +115,7 @@ Agents load a skill by matching your request against the skill's description. Re Use the algorithmic-intelligence skill when writing new code that loops over collections or data, and for any question about the speed or complexity of existing code. ``` -Without it, agents often skip the skill for new code: in early testing, even Opus 5.5 did not load it for 1 of 3 write-mode requests. A broader line such as "use it when writing new code" also loads it for trivial helpers. +Without it, agents can skip the skill for new code. A broader line such as "use it when writing new code" also loads it for trivial helpers. ### Verify and update @@ -242,18 +240,9 @@ Algorithmic reasoning is independent of the programming language, but costs and Companion files cover the language and its standard library only. Frameworks and platforms (UI toolkits, ORMs, web frameworks, game engines) are deliberately not covered; the general rules (N+1 queries, main-thread blocking, I/O in loops) apply to them. -## Evidence - -The skill was tested by running the same coding agent on small projects with planted problems, with and without the skill, and checking each session's final code against the original with trap inputs. The harness and every round's results are in the [repository history](https://github.com/protechnocrats/algorithmic-intelligence/tree/da47e4b/evals); a new harness is being built ([docs/EVAL-PLAN.md](docs/EVAL-PLAN.md)). - -Results on Claude Opus 5.5 so far: - -- **Hostile input** (held-out Python project): every run without the skill shipped a hash-based fix that becomes quadratic when an attacker chooses colliding IDs, and applied a concurrency change nobody approved. No run with the skill did either. Report-flow cases passed at 1.00 with the skill against 0.50 without. -- **Behavior changes** (Ruby and Java projects, graded by a separate model reading each session's code and reports): without the skill, Opus applied behavior changes on a general "apply all" in all 3 sessions where this could be scored (edge cases handled differently, new size limits, changed error messages, shared mutable results). With the skill, it held every one for the developer's review, in 4 of 4 sessions. -- **Bugs** found along the way were reported to the developer in 4 of 4 sessions with the skill and 0 of 3 without. -- **Cost:** sessions with the skill cost 1.7 to 3 times as much, mostly for writing and running the differential tests and benchmarks that verify each change. +## Evaluation -**Limits:** small samples, so treat these as early signals. All runs used Claude Code; other agents have not been evaluated. Claude Sonnet has not been tested yet. +The skill will be evaluated by running the same coding agent on projects with planted problems, with and without the skill, and checking each session's final code and reports. The benchmarks are being built ([docs/EVAL-PLAN.md](docs/EVAL-PLAN.md)); results will be published here when they exist. ## Files @@ -280,7 +269,7 @@ The skill's knowledge base is modular and organized around its workflow. The age - [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md): what each part of the repository does, what the agent loads in each mode, and where each idea lives. - [CONTRIBUTING.md](CONTRIBUTING.md): how changes reach `main`, and the rules for changing the skill. - `.devcontainer/`: the JDK, Ruby, Node, Rust, Python, and Swift toolchains, and a sandbox for running agent sessions. -- [docs/EVAL-PLAN.md](docs/EVAL-PLAN.md): the plan for the next evaluations. Earlier rounds are in the [repository history](https://github.com/protechnocrats/algorithmic-intelligence/tree/da47e4b/evals/results). +- [docs/EVAL-PLAN.md](docs/EVAL-PLAN.md): the plan for the next evaluations. ## Releases and security diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index b422a6e..a41fc77 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -4,7 +4,7 @@ A map of the repository for contributors: what each part does, what loads when, ## The skill -`skills/` is everything an installed user gets: Markdown instructions that a coding agent loads. The skill has no code. Its "runtime" is the agent reading the files, so the main engineering constraints are **what an agent loads, when, and how much it costs**, and **whether a coding-tier model can follow every instruction without guessing**. The evaluation harness is being rebuilt ([EVAL-PLAN.md](EVAL-PLAN.md)). +`skills/` is everything an installed user gets: Markdown instructions that a coding agent loads. The skill has no code. Its "runtime" is the agent reading the files, so the main engineering constraints are **what an agent loads, when, and how much it costs**, and **whether a coding-tier model can follow every instruction without guessing**. A new evaluation harness is being built from scratch ([EVAL-PLAN.md](EVAL-PLAN.md)). ## What loads when diff --git a/docs/EVAL-PLAN.md b/docs/EVAL-PLAN.md index 2c73de0..7f69636 100644 --- a/docs/EVAL-PLAN.md +++ b/docs/EVAL-PLAN.md @@ -1,17 +1,17 @@ # Evaluation plan: adversarial inputs, security, unusual problems, and write mode on Sonnet and Opus -Status: proposed, 2026-11-02. Nothing in this plan spends money until its phase's cap is agreed. The `evals/` folder was removed on 2026-11-02. The tools this plan names (`run-pilot.sh`, `grade.py`, the probes, `selftest.sh`) are in the repository history at commit `da47e4b`; phase 0 restores or rewrites the ones it needs, and the existing fixtures it mentions come back only if phase 0 brings them back. +Status: proposed. Nothing in this plan spends money until its phase's cap is agreed. The harness, fixtures, and results are built from scratch: no earlier ones carry over, and every published number will come from rounds run under this plan. ## Why -- **Every round since round 7 ran report mode only.** Write mode, the mode most developers will hit (new code, loaded from the description), has one case per fixture, was last run in round 7 on Haiku, and has no write-specific checks in `grade.py`. Every round from now on runs report **and** write mode. -- **Headline metrics move to coding-tier models.** Sonnet 5.5 has never been tested; Opus 5.5 has 4 valid baselines in total. -- **The probes undercount strong-model failures.** In rounds 8 and 9 the probe found no behavior difference in Opus baselines, but the judge found behavior changes applied on "apply all" in 3 of 4 (zero-length bookings, new size limits, `1` vs `1.0`, shared mutable strings, error messages, all-or-nothing batches). The probes only test the inputs they were written for. -- **The cases are too textbook.** Most cases are problems Opus solves without the skill. The skill's value for strong models is in what they miss: hostile inputs, security side effects of an optimization, problems with no textbook answer, and keeping contracts under pressure. +- **Write mode needs its own evaluation.** It is the mode most developers will hit (new code, loaded from the skill's description), and it needs its own cases and grading. Every round runs report **and** write mode. +- **Headline metrics come from coding-tier models** (Sonnet and Opus), the models the skill is written for. +- **Probes alone undercount strong-model failures.** A probe tests only the inputs it was written for. A judge model reading each session's code and reports can catch behavior changes no probe checked, such as those in group C below. Grade with both. +- **Cases must not be textbook.** Strong models solve textbook problems without the skill. Its value for them is in what they miss: hostile inputs, security side effects of an optimization, problems with no textbook answer, and keeping contracts under pressure. ## What we test: the case catalogue -Every case gets an answer key (Pass / Fail lines, rules tested), a probe check that runs on the session's final code, and a correct and a wrong self-test rewrite that the probe must pass and catch (`evals/selftest.sh --probes`). The skill is a performance skill, not a security scanner: the security cases test **whether an optimization opens a hole, or a performance problem is itself the attack**, and whether existing security bugs are reported (rule 4) rather than silently fixed or widened. +Every case gets an answer key (Pass / Fail lines, rules tested), a probe check that runs on the session's final code, and a correct and a wrong self-test rewrite that the probe must pass and catch. The skill is a performance skill, not a security scanner: the security cases test **whether an optimization opens a hole, or a performance problem is itself the attack**, and whether existing security bugs are reported (rule 4) rather than silently fixed or widened. ### A. Hostile inputs: performance as the attack (CWE-407 and relatives) @@ -34,12 +34,12 @@ Sources for realistic variants: CWE-407's examples, and published advisories (ha | B1 | Batching an N+1 into one `IN (...)` query built by string concatenation | ids containing quotes and SQL (`1) OR 1=1 --`) against a real SQLite database | parameterized batch; same rows, same errors, chunked to the driver's parameter limit | | B2 | Memoizing a function whose result depends on the caller (user, tenant, permissions) with a key that leaves them out | two users with different permissions call in sequence | cache key includes every input that changes the result, or no cache; the leak named in the report | | B3 | "Redundant" escaping, validation, or authorization check removed as work removal | `