akm-cli 0.6.1 → 0.7.0
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.
- package/CHANGELOG.md +66 -0
- package/dist/{cli.js → src/cli.js} +712 -34
- package/dist/{commands → src/commands}/config-cli.js +47 -4
- package/dist/src/commands/distill.js +283 -0
- package/dist/src/commands/events.js +108 -0
- package/dist/src/commands/history.js +191 -0
- package/dist/{commands → src/commands}/installed-stashes.js +1 -1
- package/dist/src/commands/proposal.js +119 -0
- package/dist/src/commands/propose.js +171 -0
- package/dist/src/commands/reflect.js +193 -0
- package/dist/{commands → src/commands}/registry-search.js +71 -7
- package/dist/{commands → src/commands}/remember.js +12 -0
- package/dist/{commands → src/commands}/search.js +104 -4
- package/dist/{commands → src/commands}/self-update.js +4 -3
- package/dist/{commands → src/commands}/show.js +73 -0
- package/dist/{commands → src/commands}/source-add.js +5 -1
- package/dist/{commands → src/commands}/source-manage.js +7 -1
- package/dist/{core → src/core}/asset-ref.js +5 -5
- package/dist/{core → src/core}/asset-spec.js +12 -0
- package/dist/{core → src/core}/common.js +1 -1
- package/dist/{core → src/core}/config.js +203 -121
- package/dist/{core → src/core}/errors.js +4 -0
- package/dist/src/core/events.js +239 -0
- package/dist/src/core/lesson-lint.js +86 -0
- package/dist/src/core/proposals.js +406 -0
- package/dist/src/core/warn.js +72 -0
- package/dist/{core → src/core}/write-source.js +80 -5
- package/dist/{indexer → src/indexer}/db-search.js +114 -24
- package/dist/{indexer → src/indexer}/db.js +76 -23
- package/dist/{indexer → src/indexer}/file-context.js +0 -3
- package/dist/src/indexer/graph-boost.js +179 -0
- package/dist/src/indexer/graph-extraction.js +212 -0
- package/dist/{indexer → src/indexer}/indexer.js +88 -7
- package/dist/{indexer → src/indexer}/matchers.js +1 -1
- package/dist/src/indexer/memory-inference.js +263 -0
- package/dist/{indexer → src/indexer}/metadata.js +111 -3
- package/dist/{indexer → src/indexer}/search-source.js +4 -2
- package/dist/src/integrations/agent/config.js +292 -0
- package/dist/src/integrations/agent/detect.js +94 -0
- package/dist/src/integrations/agent/index.js +17 -0
- package/dist/src/integrations/agent/profiles.js +65 -0
- package/dist/src/integrations/agent/prompts.js +167 -0
- package/dist/src/integrations/agent/spawn.js +272 -0
- package/dist/{integrations → src/integrations}/github.js +9 -3
- package/dist/{integrations → src/integrations}/lockfile.js +0 -26
- package/dist/{llm → src/llm}/client.js +33 -2
- package/dist/{llm → src/llm}/embedders/remote.js +37 -3
- package/dist/src/llm/feature-gate.js +108 -0
- package/dist/src/llm/graph-extract.js +107 -0
- package/dist/src/llm/index-passes.js +35 -0
- package/dist/src/llm/memory-infer.js +86 -0
- package/dist/{output → src/output}/cli-hints.js +15 -2
- package/dist/{output → src/output}/renderers.js +63 -2
- package/dist/src/output/shapes.js +523 -0
- package/dist/src/output/text.js +1116 -0
- package/dist/{registry → src/registry}/build-index.js +19 -8
- package/dist/{registry → src/registry}/factory.js +0 -8
- package/dist/{registry → src/registry}/providers/static-index.js +6 -3
- package/dist/{registry → src/registry}/resolve.js +68 -2
- package/dist/{setup → src/setup}/setup.js +52 -5
- package/dist/{sources → src/sources}/providers/git.js +7 -15
- package/dist/{wiki → src/wiki}/wiki.js +54 -6
- package/dist/{workflows → src/workflows}/runs.js +37 -3
- package/dist/tests/add-website-source.test.js +119 -0
- package/dist/tests/agent/agent-config-loader.test.js +70 -0
- package/dist/tests/agent/agent-config.test.js +221 -0
- package/dist/tests/agent/agent-detect.test.js +100 -0
- package/dist/tests/agent/agent-spawn.test.js +234 -0
- package/dist/tests/agent-output.test.js +186 -0
- package/dist/tests/architecture/agent-no-llm-sdk-guard.test.js +103 -0
- package/dist/tests/architecture/agent-spawn-seam.test.js +193 -0
- package/dist/tests/architecture/llm-stateless-seam.test.js +112 -0
- package/dist/tests/asset-ref.test.js +192 -0
- package/dist/tests/asset-registry.test.js +103 -0
- package/dist/tests/asset-spec.test.js +241 -0
- package/dist/tests/bench/attribution.test.js +996 -0
- package/dist/tests/bench/cleanup-sigint.test.js +83 -0
- package/dist/tests/bench/cleanup.js +234 -0
- package/dist/tests/bench/cleanup.test.js +166 -0
- package/dist/tests/bench/cli.js +1018 -0
- package/dist/tests/bench/cli.test.js +445 -0
- package/dist/tests/bench/compare.test.js +556 -0
- package/dist/tests/bench/corpus.js +317 -0
- package/dist/tests/bench/corpus.test.js +258 -0
- package/dist/tests/bench/doctor.js +525 -0
- package/dist/tests/bench/driver.js +401 -0
- package/dist/tests/bench/driver.test.js +584 -0
- package/dist/tests/bench/environment.js +233 -0
- package/dist/tests/bench/environment.test.js +199 -0
- package/dist/tests/bench/evolve-metrics.js +179 -0
- package/dist/tests/bench/evolve-metrics.test.js +187 -0
- package/dist/tests/bench/evolve.js +647 -0
- package/dist/tests/bench/evolve.test.js +624 -0
- package/dist/tests/bench/failure-modes.test.js +349 -0
- package/dist/tests/bench/feedback-integrity.test.js +457 -0
- package/dist/tests/bench/leakage.test.js +228 -0
- package/dist/tests/bench/learning-curve.test.js +134 -0
- package/dist/tests/bench/metrics.js +2395 -0
- package/dist/tests/bench/metrics.test.js +1150 -0
- package/dist/tests/bench/no-os-tmpdir-invariant.test.js +43 -0
- package/dist/tests/bench/opencode-config.js +194 -0
- package/dist/tests/bench/opencode-config.test.js +370 -0
- package/dist/tests/bench/report.js +1885 -0
- package/dist/tests/bench/report.test.js +1038 -0
- package/dist/tests/bench/run-config.js +355 -0
- package/dist/tests/bench/run-config.test.js +298 -0
- package/dist/tests/bench/run-curate-test.js +32 -0
- package/dist/tests/bench/run-failing-tasks.js +56 -0
- package/dist/tests/bench/run-full-bench.js +51 -0
- package/dist/tests/bench/run-items36-targeted.js +69 -0
- package/dist/tests/bench/run-nano-quick.js +42 -0
- package/dist/tests/bench/run-waveg-targeted.js +62 -0
- package/dist/tests/bench/runner.js +699 -0
- package/dist/tests/bench/runner.test.js +958 -0
- package/dist/tests/bench/search-bridge.test.js +331 -0
- package/dist/tests/bench/tmp.js +131 -0
- package/dist/tests/bench/trajectory.js +116 -0
- package/dist/tests/bench/trajectory.test.js +127 -0
- package/dist/tests/bench/verifier.js +114 -0
- package/dist/tests/bench/verifier.test.js +118 -0
- package/dist/tests/bench/workflow-evaluator.js +557 -0
- package/dist/tests/bench/workflow-evaluator.test.js +421 -0
- package/dist/tests/bench/workflow-spec.js +345 -0
- package/dist/tests/bench/workflow-spec.test.js +363 -0
- package/dist/tests/bench/workflow-trace.js +472 -0
- package/dist/tests/bench/workflow-trace.test.js +254 -0
- package/dist/tests/benchmark-search-quality.js +536 -0
- package/dist/tests/benchmark-suite.js +1441 -0
- package/dist/tests/capture-cli.test.js +112 -0
- package/dist/tests/cli-errors.test.js +204 -0
- package/dist/tests/commands/events.test.js +370 -0
- package/dist/tests/commands/history.test.js +418 -0
- package/dist/tests/commands/import.test.js +103 -0
- package/dist/tests/commands/proposal-cli.test.js +209 -0
- package/dist/tests/commands/reflect-propose-cli.test.js +333 -0
- package/dist/tests/commands/remember.test.js +97 -0
- package/dist/tests/commands/scope-flags.test.js +300 -0
- package/dist/tests/commands/search.test.js +537 -0
- package/dist/tests/commands/show-indexer-parity.test.js +117 -0
- package/dist/tests/commands/show.test.js +294 -0
- package/dist/tests/common.test.js +266 -0
- package/dist/tests/completions.test.js +142 -0
- package/dist/tests/config-cli.test.js +193 -0
- package/dist/tests/config-llm-features.test.js +139 -0
- package/dist/tests/config.test.js +569 -0
- package/dist/tests/contracts/migration-baseline.test.js +43 -0
- package/dist/tests/contracts/reflect-propose-envelope.test.js +139 -0
- package/dist/tests/contracts/spec-helpers.js +46 -0
- package/dist/tests/contracts/v1-spec-section-11-proposal-queue.test.js +228 -0
- package/dist/tests/contracts/v1-spec-section-12-agent-config.test.js +56 -0
- package/dist/tests/contracts/v1-spec-section-13-lesson-type.test.js +34 -0
- package/dist/tests/contracts/v1-spec-section-14-llm-features.test.js +94 -0
- package/dist/tests/contracts/v1-spec-section-4-1-asset-types.test.js +39 -0
- package/dist/tests/contracts/v1-spec-section-4-2-quality-rules.test.js +44 -0
- package/dist/tests/contracts/v1-spec-section-5-configuration.test.js +47 -0
- package/dist/tests/contracts/v1-spec-section-6-orchestration.test.js +40 -0
- package/dist/tests/contracts/v1-spec-section-7-module-layout.test.js +58 -0
- package/dist/tests/contracts/v1-spec-section-8-extension-points.test.js +34 -0
- package/dist/tests/contracts/v1-spec-section-9-4-cli-surface.test.js +75 -0
- package/dist/tests/contracts/v1-spec-section-9-7-llm-agent-boundary.test.js +36 -0
- package/dist/tests/core/write-source.test.js +366 -0
- package/dist/tests/curate-command.test.js +87 -0
- package/dist/tests/db-scoring.test.js +201 -0
- package/dist/tests/db.test.js +654 -0
- package/dist/tests/distill-cli-flag.test.js +208 -0
- package/dist/tests/distill.test.js +515 -0
- package/dist/tests/docker-install.test.js +120 -0
- package/dist/tests/e2e.test.js +1419 -0
- package/dist/tests/embedder.test.js +340 -0
- package/dist/tests/embedding-model-config.test.js +379 -0
- package/dist/tests/feedback-command.test.js +172 -0
- package/dist/tests/file-context.test.js +552 -0
- package/dist/tests/fixtures/scripts/git/summarize-diff.js +9 -0
- package/dist/tests/fixtures/scripts/lint/eslint-check.js +7 -0
- package/dist/tests/fixtures/stashes/load.js +166 -0
- package/dist/tests/fixtures/stashes/load.test.js +97 -0
- package/dist/tests/fixtures/stashes/ranking-baseline/scripts/mem0-search.js +12 -0
- package/dist/tests/frontmatter.test.js +190 -0
- package/dist/tests/fts-field-weighting.test.js +254 -0
- package/dist/tests/fuzzy-search.test.js +230 -0
- package/dist/tests/git-provider-clone.test.js +45 -0
- package/dist/tests/github.test.js +161 -0
- package/dist/tests/graph-boost-ranking.test.js +305 -0
- package/dist/tests/graph-extraction.test.js +282 -0
- package/dist/tests/helpers/usage-events.js +8 -0
- package/dist/tests/index-pass-llm.test.js +161 -0
- package/dist/tests/indexer.test.js +570 -0
- package/dist/tests/info-command.test.js +166 -0
- package/dist/tests/init.test.js +69 -0
- package/dist/tests/install-script.test.js +246 -0
- package/dist/tests/integration/agent-real-profile.test.js +94 -0
- package/dist/tests/issue-36-repro.test.js +304 -0
- package/dist/tests/issues-191-194.test.js +160 -0
- package/dist/tests/lesson-lint.test.js +111 -0
- package/dist/tests/llm-client.test.js +115 -0
- package/dist/tests/llm-feature-gate.test.js +151 -0
- package/dist/tests/llm.test.js +139 -0
- package/dist/tests/lockfile.test.js +216 -0
- package/dist/tests/manifest.test.js +205 -0
- package/dist/tests/markdown.test.js +126 -0
- package/dist/tests/matchers-unit.test.js +189 -0
- package/dist/tests/memory-inference.test.js +299 -0
- package/dist/tests/merge-scoring.test.js +136 -0
- package/dist/tests/metadata.test.js +313 -0
- package/dist/tests/migration-help.test.js +89 -0
- package/dist/tests/origin-resolve.test.js +124 -0
- package/dist/tests/output-baseline.test.js +218 -0
- package/dist/tests/output-shapes-unit.test.js +478 -0
- package/dist/tests/parallel-search.test.js +272 -0
- package/dist/tests/parameter-metadata.test.js +365 -0
- package/dist/tests/paths.test.js +177 -0
- package/dist/tests/progressive-disclosure.test.js +280 -0
- package/dist/tests/proposals.test.js +279 -0
- package/dist/tests/proposed-quality.test.js +271 -0
- package/dist/tests/provider-registry.test.js +32 -0
- package/dist/tests/ranking-regression.test.js +548 -0
- package/dist/tests/reflect-propose.test.js +455 -0
- package/dist/tests/registry-build-index.test.js +394 -0
- package/dist/tests/registry-cli.test.js +290 -0
- package/dist/tests/registry-index-v2.test.js +430 -0
- package/dist/tests/registry-install.test.js +728 -0
- package/dist/tests/registry-providers/parity.test.js +189 -0
- package/dist/tests/registry-providers/skills-sh.test.js +309 -0
- package/dist/tests/registry-providers/static-index.test.js +238 -0
- package/dist/tests/registry-resolve.test.js +126 -0
- package/dist/tests/registry-search.test.js +923 -0
- package/dist/tests/remember-frontmatter.test.js +378 -0
- package/dist/tests/remember-unit.test.js +123 -0
- package/dist/tests/ripgrep-install.test.js +251 -0
- package/dist/tests/ripgrep-resolve.test.js +108 -0
- package/dist/tests/ripgrep.test.js +163 -0
- package/dist/tests/save-command.test.js +94 -0
- package/dist/tests/save-trust-qa-fixes.test.js +270 -0
- package/dist/tests/scoring-pipeline.test.js +648 -0
- package/dist/tests/search-include-proposed-cli.test.js +118 -0
- package/dist/tests/self-update.test.js +442 -0
- package/dist/tests/semantic-search-e2e.test.js +512 -0
- package/dist/tests/semantic-status.test.js +471 -0
- package/dist/tests/setup-run.integration.js +877 -0
- package/dist/tests/setup-wizard.test.js +198 -0
- package/dist/tests/setup.test.js +131 -0
- package/dist/tests/source-add.test.js +11 -0
- package/dist/tests/source-clone.test.js +254 -0
- package/dist/tests/source-manage.test.js +366 -0
- package/dist/tests/source-providers/filesystem.test.js +82 -0
- package/dist/tests/source-providers/git.test.js +252 -0
- package/dist/tests/source-providers/website.test.js +128 -0
- package/dist/tests/source-qa-fixes.test.js +286 -0
- package/dist/tests/source-registry.test.js +350 -0
- package/dist/tests/source-resolve.test.js +100 -0
- package/dist/tests/source-source.test.js +281 -0
- package/dist/tests/source.test.js +533 -0
- package/dist/tests/tar-utils-scan.test.js +73 -0
- package/dist/tests/toggle-components.test.js +73 -0
- package/dist/tests/usage-telemetry.test.js +265 -0
- package/dist/tests/utility-scoring.test.js +558 -0
- package/dist/tests/vault-load-error.test.js +78 -0
- package/dist/tests/vault-qa-fixes.test.js +194 -0
- package/dist/tests/vault.test.js +429 -0
- package/dist/tests/vector-search.test.js +608 -0
- package/dist/tests/walker.test.js +252 -0
- package/dist/tests/wave2-cluster-bc.test.js +228 -0
- package/dist/tests/wave2-cluster-d.test.js +180 -0
- package/dist/tests/wave2-cluster-e.test.js +179 -0
- package/dist/tests/wiki-qa-fixes.test.js +270 -0
- package/dist/tests/wiki.test.js +529 -0
- package/dist/tests/workflow-cli.test.js +271 -0
- package/dist/tests/workflow-markdown.test.js +171 -0
- package/dist/tests/workflow-path-escape.test.js +132 -0
- package/dist/tests/workflow-qa-fixes.test.js +395 -0
- package/dist/tests/workflows/indexer-rejection.test.js +213 -0
- package/docs/README.md +8 -0
- package/docs/migration/release-notes/0.7.0.md +244 -0
- package/package.json +2 -2
- package/dist/core/warn.js +0 -27
- package/dist/output/shapes.js +0 -212
- package/dist/output/text.js +0 -520
- /package/dist/{commands → src/commands}/completions.js +0 -0
- /package/dist/{commands → src/commands}/curate.js +0 -0
- /package/dist/{commands → src/commands}/info.js +0 -0
- /package/dist/{commands → src/commands}/init.js +0 -0
- /package/dist/{commands → src/commands}/install-audit.js +0 -0
- /package/dist/{commands → src/commands}/migration-help.js +0 -0
- /package/dist/{commands → src/commands}/source-clone.js +0 -0
- /package/dist/{commands → src/commands}/vault.js +0 -0
- /package/dist/{core → src/core}/asset-registry.js +0 -0
- /package/dist/{core → src/core}/frontmatter.js +0 -0
- /package/dist/{core → src/core}/markdown.js +0 -0
- /package/dist/{core → src/core}/paths.js +0 -0
- /package/dist/{indexer → src/indexer}/manifest.js +0 -0
- /package/dist/{indexer → src/indexer}/search-fields.js +0 -0
- /package/dist/{indexer → src/indexer}/semantic-status.js +0 -0
- /package/dist/{indexer → src/indexer}/usage-events.js +0 -0
- /package/dist/{indexer → src/indexer}/walker.js +0 -0
- /package/dist/{llm → src/llm}/embedder.js +0 -0
- /package/dist/{llm → src/llm}/embedders/cache.js +0 -0
- /package/dist/{llm → src/llm}/embedders/local.js +0 -0
- /package/dist/{llm → src/llm}/embedders/types.js +0 -0
- /package/dist/{llm → src/llm}/metadata-enhance.js +0 -0
- /package/dist/{output → src/output}/context.js +0 -0
- /package/dist/{registry → src/registry}/create-provider-registry.js +0 -0
- /package/dist/{registry → src/registry}/origin-resolve.js +0 -0
- /package/dist/{registry → src/registry}/providers/index.js +0 -0
- /package/dist/{registry → src/registry}/providers/skills-sh.js +0 -0
- /package/dist/{registry → src/registry}/providers/types.js +0 -0
- /package/dist/{registry → src/registry}/types.js +0 -0
- /package/dist/{setup → src/setup}/detect.js +0 -0
- /package/dist/{setup → src/setup}/ripgrep-install.js +0 -0
- /package/dist/{setup → src/setup}/ripgrep-resolve.js +0 -0
- /package/dist/{setup → src/setup}/steps.js +0 -0
- /package/dist/{sources → src/sources}/include.js +0 -0
- /package/dist/{sources → src/sources}/provider-factory.js +0 -0
- /package/dist/{sources → src/sources}/provider.js +0 -0
- /package/dist/{sources → src/sources}/providers/filesystem.js +0 -0
- /package/dist/{sources → src/sources}/providers/index.js +0 -0
- /package/dist/{sources → src/sources}/providers/install-types.js +0 -0
- /package/dist/{sources → src/sources}/providers/npm.js +0 -0
- /package/dist/{sources → src/sources}/providers/provider-utils.js +0 -0
- /package/dist/{sources → src/sources}/providers/sync-from-ref.js +0 -0
- /package/dist/{sources → src/sources}/providers/tar-utils.js +0 -0
- /package/dist/{sources → src/sources}/providers/website.js +0 -0
- /package/dist/{sources → src/sources}/resolve.js +0 -0
- /package/dist/{sources → src/sources}/types.js +0 -0
- /package/dist/{templates → src/templates}/wiki-templates.js +0 -0
- /package/dist/{version.js → src/version.js} +0 -0
- /package/dist/{workflows → src/workflows}/authoring.js +0 -0
- /package/dist/{workflows → src/workflows}/cli.js +0 -0
- /package/dist/{workflows → src/workflows}/db.js +0 -0
- /package/dist/{workflows → src/workflows}/document-cache.js +0 -0
- /package/dist/{workflows → src/workflows}/parser.js +0 -0
- /package/dist/{workflows → src/workflows}/renderer.js +0 -0
- /package/dist/{workflows → src/workflows}/schema.js +0 -0
- /package/dist/{workflows → src/workflows}/validator.js +0 -0
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* akm-bench corpus loader (spec §5.4 + §13.1).
|
|
3
|
+
*
|
|
4
|
+
* Tasks live at `tests/fixtures/bench/tasks/<domain>/<task-id>/task.yaml`. Each
|
|
5
|
+
* task is a flat YAML record (see §13.1). The schema lands in #237 and grows
|
|
6
|
+
* over time; #236 only ships the loader and one sample task fixture.
|
|
7
|
+
*
|
|
8
|
+
* The `tests/fixtures/bench/tasks/` directory may not exist on `release/0.7.0`
|
|
9
|
+
* yet — that's #237's deliverable. `listTasks()` MUST return `[]` cleanly when
|
|
10
|
+
* the directory is missing rather than throwing, so consumers degrade gracefully.
|
|
11
|
+
*/
|
|
12
|
+
import { createHash } from "node:crypto";
|
|
13
|
+
import fs from "node:fs";
|
|
14
|
+
import path from "node:path";
|
|
15
|
+
import { parse as parseYaml } from "yaml";
|
|
16
|
+
/**
|
|
17
|
+
* Closed set of memory-operation labels (#262).
|
|
18
|
+
*
|
|
19
|
+
* Each value names the kind of memory / knowledge ability the task exercises:
|
|
20
|
+
* - `procedural_lookup` — find and apply a single procedural skill.
|
|
21
|
+
* - `multi_asset_composition` — combine guidance from two+ assets.
|
|
22
|
+
* - `temporal_update` — apply the most recent guidance over older versions.
|
|
23
|
+
* - `conflict_resolution` — choose between conflicting assets.
|
|
24
|
+
* - `abstention` — recognise no relevant asset exists and decline to load.
|
|
25
|
+
* - `noisy_retrieval` — succeed despite distractor / irrelevant assets.
|
|
26
|
+
*
|
|
27
|
+
* Adding a value here is a CORPUS-schema change; callers iterate the closed
|
|
28
|
+
* set when laying out coverage tables.
|
|
29
|
+
*/
|
|
30
|
+
export const MEMORY_ABILITY_VALUES = [
|
|
31
|
+
"procedural_lookup",
|
|
32
|
+
"multi_asset_composition",
|
|
33
|
+
"temporal_update",
|
|
34
|
+
"conflict_resolution",
|
|
35
|
+
"abstention",
|
|
36
|
+
"noisy_retrieval",
|
|
37
|
+
];
|
|
38
|
+
const TASKS_ROOT = path.resolve(__dirname, "..", "fixtures", "bench", "tasks");
|
|
39
|
+
/** Public for tests; resolves the corpus root in case callers need to assert it. */
|
|
40
|
+
export function getTasksRoot() {
|
|
41
|
+
return TASKS_ROOT;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Compute a deterministic SHA-256 hash over a selected task corpus (#250).
|
|
45
|
+
*
|
|
46
|
+
* Two reports with the same selected task IDs and the same task body bytes
|
|
47
|
+
* produce the same hash. The hash is order-independent: callers may pass IDs
|
|
48
|
+
* in any order — the function sorts them lexicographically before hashing.
|
|
49
|
+
*
|
|
50
|
+
* The `taskBodies` map is keyed by task id and carries the raw `task.yaml`
|
|
51
|
+
* bytes (or any deterministic per-task identity payload). Tasks present in
|
|
52
|
+
* `taskIds` but missing from `taskBodies` are hashed with an empty body so
|
|
53
|
+
* the hash still distinguishes the selection.
|
|
54
|
+
*
|
|
55
|
+
* Encoding (per id, in sorted order):
|
|
56
|
+
* `<id>\0<body-bytes>\0`
|
|
57
|
+
*
|
|
58
|
+
* Used by `bench compare` to refuse mismatched corpora unless the operator
|
|
59
|
+
* explicitly opts in via `--allow-corpus-mismatch`.
|
|
60
|
+
*/
|
|
61
|
+
export function computeTaskCorpusHash(taskIds, taskBodies) {
|
|
62
|
+
const sortedIds = [...taskIds].sort();
|
|
63
|
+
const hash = createHash("sha256");
|
|
64
|
+
for (const id of sortedIds) {
|
|
65
|
+
hash.update(id);
|
|
66
|
+
hash.update("\0");
|
|
67
|
+
hash.update(taskBodies.get(id) ?? "");
|
|
68
|
+
hash.update("\0");
|
|
69
|
+
}
|
|
70
|
+
return hash.digest("hex");
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Read the raw `task.yaml` bytes for a task whose `taskDir` is known. Returns
|
|
74
|
+
* the empty string when the file is missing — callers should still hash the
|
|
75
|
+
* id so the selection's identity is preserved.
|
|
76
|
+
*/
|
|
77
|
+
export function readTaskBody(taskDir) {
|
|
78
|
+
const yamlPath = path.join(taskDir, "task.yaml");
|
|
79
|
+
try {
|
|
80
|
+
return fs.readFileSync(yamlPath, "utf8");
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return "";
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The `_example/` task tree is reserved for loader unit tests; real corpus
|
|
88
|
+
* statistics must exclude it. The path-prefix check matches both POSIX (`/`)
|
|
89
|
+
* and Windows (`\`) separators.
|
|
90
|
+
*/
|
|
91
|
+
const EXAMPLE_PREFIX = `${path.sep}_example${path.sep}`;
|
|
92
|
+
function isExampleTaskDir(dir) {
|
|
93
|
+
return dir.includes(EXAMPLE_PREFIX);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Load a single task by id. Walks the tasks tree until a directory whose
|
|
97
|
+
* `task.yaml` carries the requested `id` is found. By default the
|
|
98
|
+
* `_example/` tree is skipped; pass `{ includeExamples: true }` to load
|
|
99
|
+
* tasks under that prefix (used by loader-unit tests).
|
|
100
|
+
*
|
|
101
|
+
* Throws if the corpus directory is missing or no task matches.
|
|
102
|
+
*/
|
|
103
|
+
export function loadTask(taskId, options = {}) {
|
|
104
|
+
if (!fs.existsSync(TASKS_ROOT)) {
|
|
105
|
+
throw new Error(`bench corpus directory missing: ${TASKS_ROOT}`);
|
|
106
|
+
}
|
|
107
|
+
for (const candidate of walkTaskDirs(TASKS_ROOT)) {
|
|
108
|
+
if (!options.includeExamples && isExampleTaskDir(candidate))
|
|
109
|
+
continue;
|
|
110
|
+
const meta = readTask(candidate);
|
|
111
|
+
if (meta && meta.id === taskId)
|
|
112
|
+
return meta;
|
|
113
|
+
}
|
|
114
|
+
throw new Error(`task not found: ${taskId}`);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Return every task in the corpus, optionally filtered by `slice`. When the
|
|
118
|
+
* corpus directory is missing this returns `[]`. By default tasks under the
|
|
119
|
+
* `_example/` tree are excluded; pass `{ includeExamples: true }` to include
|
|
120
|
+
* them.
|
|
121
|
+
*/
|
|
122
|
+
export function listTasks(options = {}) {
|
|
123
|
+
if (!fs.existsSync(TASKS_ROOT))
|
|
124
|
+
return [];
|
|
125
|
+
const out = [];
|
|
126
|
+
for (const dir of walkTaskDirs(TASKS_ROOT)) {
|
|
127
|
+
if (!options.includeExamples && isExampleTaskDir(dir))
|
|
128
|
+
continue;
|
|
129
|
+
const meta = readTask(dir);
|
|
130
|
+
if (!meta)
|
|
131
|
+
continue;
|
|
132
|
+
if (options.slice) {
|
|
133
|
+
// Tasks without an explicit `slice:` are partitioned by id-hash so the
|
|
134
|
+
// filter behaves consistently with `partitionSlice()`. Without this,
|
|
135
|
+
// an unsliced task would always pass through both `slice: "train"` and
|
|
136
|
+
// `slice: "eval"` filters, double-counting in evaluation reports.
|
|
137
|
+
if (effectiveSlice(meta) !== options.slice)
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
out.push(meta);
|
|
141
|
+
}
|
|
142
|
+
out.sort((a, b) => a.id.localeCompare(b.id));
|
|
143
|
+
return out;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Partition a list of tasks into train/eval slices. Tasks declaring an explicit
|
|
147
|
+
* `slice:` are honoured; tasks that don't are placed by `id-hash mod 2 === 0`
|
|
148
|
+
* → train, else eval. The hash is SHA-1 of the id (deterministic across hosts).
|
|
149
|
+
*/
|
|
150
|
+
export function partitionSlice(tasks) {
|
|
151
|
+
const train = [];
|
|
152
|
+
const evalSlice = [];
|
|
153
|
+
for (const task of tasks) {
|
|
154
|
+
const slice = effectiveSlice(task);
|
|
155
|
+
if (slice === "train")
|
|
156
|
+
train.push(task);
|
|
157
|
+
else
|
|
158
|
+
evalSlice.push(task);
|
|
159
|
+
}
|
|
160
|
+
return { train, eval: evalSlice };
|
|
161
|
+
}
|
|
162
|
+
function assignSliceByHash(id) {
|
|
163
|
+
// SHA-1 first byte parity is stable, fast, and uniformly distributed enough
|
|
164
|
+
// for slice partitioning. We avoid `node:crypto.randomInt` (non-deterministic).
|
|
165
|
+
const digest = createHash("sha1").update(id).digest();
|
|
166
|
+
return digest[0] % 2 === 0 ? "train" : "eval";
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Resolve a task's effective slice. If `task.yaml` declares `slice:` we honour
|
|
170
|
+
* it; otherwise the id-hash partition assigns one deterministically. Exported
|
|
171
|
+
* so that consumers (and tests) can ask "which slice would this task fall in?"
|
|
172
|
+
* without re-running `partitionSlice()`.
|
|
173
|
+
*/
|
|
174
|
+
export function effectiveSlice(task) {
|
|
175
|
+
return task.slice ?? assignSliceByHash(task.id);
|
|
176
|
+
}
|
|
177
|
+
/** Walk the corpus tree depth-first, yielding every directory containing a `task.yaml`. */
|
|
178
|
+
function* walkTaskDirs(root) {
|
|
179
|
+
const stack = [root];
|
|
180
|
+
while (stack.length > 0) {
|
|
181
|
+
const dir = stack.pop();
|
|
182
|
+
if (!dir)
|
|
183
|
+
continue;
|
|
184
|
+
let entries;
|
|
185
|
+
try {
|
|
186
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
187
|
+
}
|
|
188
|
+
catch {
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
if (entries.some((e) => e.isFile() && e.name === "task.yaml")) {
|
|
192
|
+
yield dir;
|
|
193
|
+
continue; // Don't recurse beneath a task directory.
|
|
194
|
+
}
|
|
195
|
+
for (const entry of entries) {
|
|
196
|
+
if (entry.isDirectory())
|
|
197
|
+
stack.push(path.join(dir, entry.name));
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
function readTask(taskDir) {
|
|
202
|
+
const yamlPath = path.join(taskDir, "task.yaml");
|
|
203
|
+
let text;
|
|
204
|
+
try {
|
|
205
|
+
text = fs.readFileSync(yamlPath, "utf8");
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
return undefined;
|
|
209
|
+
}
|
|
210
|
+
return parseTaskYaml(text, taskDir);
|
|
211
|
+
}
|
|
212
|
+
export function parseTaskYaml(text, taskDir) {
|
|
213
|
+
let raw;
|
|
214
|
+
try {
|
|
215
|
+
raw = parseYaml(text);
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
return undefined;
|
|
219
|
+
}
|
|
220
|
+
if (!raw || typeof raw !== "object")
|
|
221
|
+
return undefined;
|
|
222
|
+
const id = asString(raw.id);
|
|
223
|
+
const title = asString(raw.title);
|
|
224
|
+
const domain = asString(raw.domain);
|
|
225
|
+
const difficulty = asEnum(raw.difficulty, ["easy", "medium", "hard"]);
|
|
226
|
+
const stash = asString(raw.stash);
|
|
227
|
+
const verifier = asEnum(raw.verifier, ["script", "pytest", "regex"]);
|
|
228
|
+
const tokens = asNumber(raw.budget?.tokens);
|
|
229
|
+
const wallMs = asNumber(raw.budget?.wallMs);
|
|
230
|
+
if (!id || !title || !domain || !difficulty || !stash || !verifier || tokens === undefined || wallMs === undefined) {
|
|
231
|
+
return undefined;
|
|
232
|
+
}
|
|
233
|
+
const slice = raw.slice === undefined ? undefined : asEnum(raw.slice, ["train", "eval"]);
|
|
234
|
+
const goldRef = asString(raw.gold_ref);
|
|
235
|
+
const stashOverlay = asString(raw.stash_overlay);
|
|
236
|
+
const expectedMatch = asString(raw.expected_match);
|
|
237
|
+
const meta = {
|
|
238
|
+
id,
|
|
239
|
+
title,
|
|
240
|
+
domain,
|
|
241
|
+
difficulty,
|
|
242
|
+
stash,
|
|
243
|
+
verifier,
|
|
244
|
+
budget: { tokens, wallMs },
|
|
245
|
+
taskDir,
|
|
246
|
+
};
|
|
247
|
+
if (slice !== undefined)
|
|
248
|
+
meta.slice = slice;
|
|
249
|
+
if (goldRef !== undefined)
|
|
250
|
+
meta.goldRef = goldRef;
|
|
251
|
+
if (stashOverlay !== undefined)
|
|
252
|
+
meta.stashOverlay = stashOverlay;
|
|
253
|
+
if (expectedMatch !== undefined)
|
|
254
|
+
meta.expectedMatch = expectedMatch;
|
|
255
|
+
// #262 memory-operation tags. Each tag is OPTIONAL — invalid values are
|
|
256
|
+
// silently ignored so a malformed tag never breaks an existing task. This
|
|
257
|
+
// matches the broader "loader returns undefined on bad core fields, drops
|
|
258
|
+
// bad tags" contract documented in the §13.1 schema.
|
|
259
|
+
const memoryAbility = asEnum(raw.memory_ability, MEMORY_ABILITY_VALUES);
|
|
260
|
+
if (memoryAbility !== undefined)
|
|
261
|
+
meta.memoryAbility = memoryAbility;
|
|
262
|
+
const workflowFocus = asString(raw.workflow_focus);
|
|
263
|
+
if (workflowFocus !== undefined)
|
|
264
|
+
meta.workflowFocus = workflowFocus;
|
|
265
|
+
const taskFamily = asString(raw.task_family);
|
|
266
|
+
if (taskFamily !== undefined)
|
|
267
|
+
meta.taskFamily = taskFamily;
|
|
268
|
+
const expectedTransferFrom = asStringArray(raw.expected_transfer_from);
|
|
269
|
+
if (expectedTransferFrom !== undefined)
|
|
270
|
+
meta.expectedTransferFrom = expectedTransferFrom;
|
|
271
|
+
const abstentionCase = asBoolean(raw.abstention_case);
|
|
272
|
+
if (abstentionCase !== undefined)
|
|
273
|
+
meta.abstentionCase = abstentionCase;
|
|
274
|
+
const conflictCase = asBoolean(raw.conflict_case);
|
|
275
|
+
if (conflictCase !== undefined)
|
|
276
|
+
meta.conflictCase = conflictCase;
|
|
277
|
+
const staleGuidanceCase = asBoolean(raw.stale_guidance_case);
|
|
278
|
+
if (staleGuidanceCase !== undefined)
|
|
279
|
+
meta.staleGuidanceCase = staleGuidanceCase;
|
|
280
|
+
const akmKeywords = asString(raw.akm_keywords);
|
|
281
|
+
if (akmKeywords !== undefined)
|
|
282
|
+
meta.akmKeywords = akmKeywords;
|
|
283
|
+
return meta;
|
|
284
|
+
}
|
|
285
|
+
function asBoolean(value) {
|
|
286
|
+
if (typeof value === "boolean")
|
|
287
|
+
return value;
|
|
288
|
+
return undefined;
|
|
289
|
+
}
|
|
290
|
+
function asStringArray(value) {
|
|
291
|
+
if (!Array.isArray(value))
|
|
292
|
+
return undefined;
|
|
293
|
+
const out = [];
|
|
294
|
+
for (const entry of value) {
|
|
295
|
+
if (typeof entry === "string" && entry.length > 0)
|
|
296
|
+
out.push(entry);
|
|
297
|
+
}
|
|
298
|
+
return out;
|
|
299
|
+
}
|
|
300
|
+
function asString(value) {
|
|
301
|
+
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
302
|
+
}
|
|
303
|
+
function asNumber(value) {
|
|
304
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
305
|
+
return value;
|
|
306
|
+
if (typeof value === "string") {
|
|
307
|
+
const parsed = Number.parseFloat(value);
|
|
308
|
+
if (Number.isFinite(parsed))
|
|
309
|
+
return parsed;
|
|
310
|
+
}
|
|
311
|
+
return undefined;
|
|
312
|
+
}
|
|
313
|
+
function asEnum(value, allowed) {
|
|
314
|
+
if (typeof value !== "string")
|
|
315
|
+
return undefined;
|
|
316
|
+
return allowed.includes(value) ? value : undefined;
|
|
317
|
+
}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for the bench corpus loader.
|
|
3
|
+
*
|
|
4
|
+
* • `listTasks()` returns `[]` cleanly when the corpus dir is missing.
|
|
5
|
+
* • The shipped sample task at `_example/example-task` is excluded by
|
|
6
|
+
* default but loadable via `{ includeExamples: true }`.
|
|
7
|
+
* • The seeded corpus contains 23 tasks (issue #237 seeded 17 across
|
|
8
|
+
* three domains; #259 added six workflow-compliance tasks) and every
|
|
9
|
+
* entry validates against the §13.1 schema.
|
|
10
|
+
* • `partitionSlice` is deterministic — same input → same partitioning
|
|
11
|
+
* across calls.
|
|
12
|
+
*/
|
|
13
|
+
import { describe, expect, test } from "bun:test";
|
|
14
|
+
import fs from "node:fs";
|
|
15
|
+
import path from "node:path";
|
|
16
|
+
import { computeTaskCorpusHash, effectiveSlice, getTasksRoot, listTasks, loadTask, MEMORY_ABILITY_VALUES, parseTaskYaml, partitionSlice, readTaskBody, } from "./corpus";
|
|
17
|
+
import { benchMkdtemp } from "./tmp";
|
|
18
|
+
describe("listTasks", () => {
|
|
19
|
+
test("the corpus root resolves under tests/fixtures/bench/tasks", () => {
|
|
20
|
+
expect(getTasksRoot()).toMatch(/tests[\\/]+fixtures[\\/]+bench[\\/]+tasks$/);
|
|
21
|
+
});
|
|
22
|
+
test("returns an array (possibly empty) without throwing", () => {
|
|
23
|
+
const tasks = listTasks();
|
|
24
|
+
expect(Array.isArray(tasks)).toBe(true);
|
|
25
|
+
});
|
|
26
|
+
test("excludes `_example/` tasks by default", () => {
|
|
27
|
+
const tasks = listTasks();
|
|
28
|
+
expect(tasks.find((t) => t.id.startsWith("_example/"))).toBeUndefined();
|
|
29
|
+
});
|
|
30
|
+
test("loads `_example/` when includeExamples is set", () => {
|
|
31
|
+
const tasks = listTasks({ includeExamples: true });
|
|
32
|
+
const sample = tasks.find((t) => t.id === "_example/example-task");
|
|
33
|
+
expect(sample).toBeDefined();
|
|
34
|
+
expect(sample?.title).toContain("Example task");
|
|
35
|
+
expect(sample?.stash).toBe("minimal");
|
|
36
|
+
expect(sample?.verifier).toBe("script");
|
|
37
|
+
expect(sample?.budget.tokens).toBe(1000);
|
|
38
|
+
expect(sample?.budget.wallMs).toBe(30_000);
|
|
39
|
+
});
|
|
40
|
+
test("seeds hand-authored tasks across all domains", () => {
|
|
41
|
+
const tasks = listTasks();
|
|
42
|
+
expect(tasks).toHaveLength(40);
|
|
43
|
+
const byDomain = new Map();
|
|
44
|
+
for (const task of tasks) {
|
|
45
|
+
const list = byDomain.get(task.domain) ?? [];
|
|
46
|
+
list.push(task);
|
|
47
|
+
byDomain.set(task.domain, list);
|
|
48
|
+
}
|
|
49
|
+
expect(new Set(byDomain.keys())).toEqual(new Set(["docker-homelab", "az-cli", "opencode", "workflow-compliance", "drillbit", "inkwell"]));
|
|
50
|
+
expect(byDomain.get("docker-homelab")).toHaveLength(6);
|
|
51
|
+
expect(byDomain.get("az-cli")).toHaveLength(6);
|
|
52
|
+
expect(byDomain.get("opencode")).toHaveLength(6);
|
|
53
|
+
expect(byDomain.get("workflow-compliance")).toHaveLength(6);
|
|
54
|
+
expect(byDomain.get("drillbit")).toHaveLength(7);
|
|
55
|
+
expect(byDomain.get("inkwell")).toHaveLength(9);
|
|
56
|
+
});
|
|
57
|
+
test("every task validates against the §13.1 schema", () => {
|
|
58
|
+
const ID_RE = /^[a-z0-9][a-z0-9-]*\/[a-z0-9][a-z0-9-]*$/;
|
|
59
|
+
for (const task of listTasks()) {
|
|
60
|
+
expect(task.id).toMatch(ID_RE);
|
|
61
|
+
expect(task.title.length).toBeGreaterThan(0);
|
|
62
|
+
expect(["easy", "medium", "hard"]).toContain(task.difficulty);
|
|
63
|
+
expect(["train", "eval"]).toContain(task.slice);
|
|
64
|
+
expect(["pytest", "script", "regex"]).toContain(task.verifier);
|
|
65
|
+
expect(typeof task.stash).toBe("string");
|
|
66
|
+
expect(task.budget.tokens).toBeGreaterThan(0);
|
|
67
|
+
expect(task.budget.wallMs).toBeGreaterThan(0);
|
|
68
|
+
if (task.verifier === "regex") {
|
|
69
|
+
expect(task.expectedMatch).toBeDefined();
|
|
70
|
+
expect((task.expectedMatch ?? "").length).toBeGreaterThan(0);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
test("filters by slice when requested", () => {
|
|
75
|
+
const train = listTasks({ slice: "train" });
|
|
76
|
+
const evalTasks = listTasks({ slice: "eval" });
|
|
77
|
+
expect(train.every((t) => t.slice === "train")).toBe(true);
|
|
78
|
+
expect(evalTasks.every((t) => t.slice === "eval")).toBe(true);
|
|
79
|
+
// 23 train (19 + 2 drillbit train + 2 inkwell train)
|
|
80
|
+
// 17 eval (15 prior + 2 new: inkwell/full-config + opencode/select-correct-skill)
|
|
81
|
+
expect(train).toHaveLength(23);
|
|
82
|
+
expect(evalTasks).toHaveLength(17);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
describe("loadTask", () => {
|
|
86
|
+
test("loads a real corpus task by id", () => {
|
|
87
|
+
const meta = loadTask("docker-homelab/redis-healthcheck");
|
|
88
|
+
expect(meta.title).toContain("Redis healthcheck");
|
|
89
|
+
expect(meta.taskDir).toContain("docker-homelab/redis-healthcheck");
|
|
90
|
+
expect(meta.verifier).toBe("pytest");
|
|
91
|
+
});
|
|
92
|
+
test("loads the example task only with includeExamples", () => {
|
|
93
|
+
expect(() => loadTask("_example/example-task")).toThrow();
|
|
94
|
+
const meta = loadTask("_example/example-task", { includeExamples: true });
|
|
95
|
+
expect(meta.taskDir).toContain("_example/example-task");
|
|
96
|
+
});
|
|
97
|
+
test("throws on unknown id", () => {
|
|
98
|
+
expect(() => loadTask("does/not/exist")).toThrow();
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
describe("partitionSlice", () => {
|
|
102
|
+
function fakeTask(id, slice) {
|
|
103
|
+
return {
|
|
104
|
+
id,
|
|
105
|
+
title: id,
|
|
106
|
+
domain: "test",
|
|
107
|
+
difficulty: "easy",
|
|
108
|
+
stash: "minimal",
|
|
109
|
+
verifier: "regex",
|
|
110
|
+
budget: { tokens: 1000, wallMs: 1000 },
|
|
111
|
+
taskDir: "/tmp/none",
|
|
112
|
+
...(slice ? { slice } : {}),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
test("explicit slice fields are honoured", () => {
|
|
116
|
+
const tasks = [fakeTask("a", "train"), fakeTask("b", "eval"), fakeTask("c", "train")];
|
|
117
|
+
const { train, eval: evalSlice } = partitionSlice(tasks);
|
|
118
|
+
expect(train.map((t) => t.id).sort()).toEqual(["a", "c"]);
|
|
119
|
+
expect(evalSlice.map((t) => t.id)).toEqual(["b"]);
|
|
120
|
+
});
|
|
121
|
+
test("tasks without explicit slice get a deterministic assignment", () => {
|
|
122
|
+
const tasks = [fakeTask("alpha"), fakeTask("beta"), fakeTask("gamma"), fakeTask("delta"), fakeTask("epsilon")];
|
|
123
|
+
const a = partitionSlice(tasks);
|
|
124
|
+
const b = partitionSlice(tasks);
|
|
125
|
+
expect(a.train.map((t) => t.id)).toEqual(b.train.map((t) => t.id));
|
|
126
|
+
expect(a.eval.map((t) => t.id)).toEqual(b.eval.map((t) => t.id));
|
|
127
|
+
// Sanity: every task ends up in exactly one slice.
|
|
128
|
+
expect(a.train.length + a.eval.length).toBe(tasks.length);
|
|
129
|
+
});
|
|
130
|
+
test("partition of the real corpus is stable across calls", () => {
|
|
131
|
+
const corpus = listTasks();
|
|
132
|
+
const a = partitionSlice(corpus);
|
|
133
|
+
const b = partitionSlice(corpus);
|
|
134
|
+
expect(a.train.map((t) => t.id)).toEqual(b.train.map((t) => t.id));
|
|
135
|
+
expect(a.eval.map((t) => t.id)).toEqual(b.eval.map((t) => t.id));
|
|
136
|
+
});
|
|
137
|
+
test("computeTaskCorpusHash is deterministic and order-independent (#250)", () => {
|
|
138
|
+
const bodies = new Map([
|
|
139
|
+
["a/one", "id: a/one\ntitle: One\n"],
|
|
140
|
+
["b/two", "id: b/two\ntitle: Two\n"],
|
|
141
|
+
]);
|
|
142
|
+
const h1 = computeTaskCorpusHash(["a/one", "b/two"], bodies);
|
|
143
|
+
const h2 = computeTaskCorpusHash(["b/two", "a/one"], bodies);
|
|
144
|
+
expect(h1).toBe(h2);
|
|
145
|
+
expect(h1).toMatch(/^[0-9a-f]{64}$/);
|
|
146
|
+
// Body change → hash change.
|
|
147
|
+
const altBodies = new Map(bodies);
|
|
148
|
+
altBodies.set("a/one", "id: a/one\ntitle: Different\n");
|
|
149
|
+
const h3 = computeTaskCorpusHash(["a/one", "b/two"], altBodies);
|
|
150
|
+
expect(h3).not.toBe(h1);
|
|
151
|
+
// ID-set change → hash change.
|
|
152
|
+
const h4 = computeTaskCorpusHash(["a/one"], bodies);
|
|
153
|
+
expect(h4).not.toBe(h1);
|
|
154
|
+
// readTaskBody returns "" for a missing taskDir without throwing.
|
|
155
|
+
expect(readTaskBody("/does/not/exist")).toBe("");
|
|
156
|
+
});
|
|
157
|
+
test("a task without explicit slice is bucketed deterministically and goes to exactly one slice", () => {
|
|
158
|
+
// This guards against the regression where `listTasks({ slice })` would
|
|
159
|
+
// pass an unsliced task through *both* the train and eval filters because
|
|
160
|
+
// the early code only excluded tasks whose explicit slice differed.
|
|
161
|
+
const synthetic = {
|
|
162
|
+
id: "synthetic/no-slice-task",
|
|
163
|
+
title: "Synthetic task with no explicit slice",
|
|
164
|
+
domain: "synthetic",
|
|
165
|
+
difficulty: "easy",
|
|
166
|
+
stash: "minimal",
|
|
167
|
+
verifier: "regex",
|
|
168
|
+
budget: { tokens: 1000, wallMs: 1000 },
|
|
169
|
+
taskDir: "/tmp/none",
|
|
170
|
+
};
|
|
171
|
+
const slice = effectiveSlice(synthetic);
|
|
172
|
+
expect(["train", "eval"]).toContain(slice);
|
|
173
|
+
// Re-running must give the same bucket.
|
|
174
|
+
expect(effectiveSlice(synthetic)).toBe(slice);
|
|
175
|
+
// partitionSlice and effectiveSlice must agree.
|
|
176
|
+
const { train, eval: evalSlice } = partitionSlice([synthetic]);
|
|
177
|
+
if (slice === "train") {
|
|
178
|
+
expect(train.map((t) => t.id)).toEqual([synthetic.id]);
|
|
179
|
+
expect(evalSlice).toEqual([]);
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
expect(evalSlice.map((t) => t.id)).toEqual([synthetic.id]);
|
|
183
|
+
expect(train).toEqual([]);
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
// ── Memory-operation tags (#262) ───────────────────────────────────────────
|
|
188
|
+
describe("memory-operation tags (#262)", () => {
|
|
189
|
+
test("MEMORY_ABILITY_VALUES is the documented closed set", () => {
|
|
190
|
+
expect(new Set(MEMORY_ABILITY_VALUES)).toEqual(new Set([
|
|
191
|
+
"procedural_lookup",
|
|
192
|
+
"multi_asset_composition",
|
|
193
|
+
"temporal_update",
|
|
194
|
+
"conflict_resolution",
|
|
195
|
+
"abstention",
|
|
196
|
+
"noisy_retrieval",
|
|
197
|
+
]));
|
|
198
|
+
});
|
|
199
|
+
test("loader leaves tag fields undefined for legacy tasks (without new fields)", () => {
|
|
200
|
+
// The shipped `_example/example-task` carries no #262 tags — it
|
|
201
|
+
// continues to load cleanly with every new field undefined.
|
|
202
|
+
const meta = loadTask("_example/example-task", { includeExamples: true });
|
|
203
|
+
expect(meta.memoryAbility).toBeUndefined();
|
|
204
|
+
expect(meta.taskFamily).toBeUndefined();
|
|
205
|
+
expect(meta.workflowFocus).toBeUndefined();
|
|
206
|
+
expect(meta.expectedTransferFrom).toBeUndefined();
|
|
207
|
+
expect(meta.abstentionCase).toBeUndefined();
|
|
208
|
+
expect(meta.conflictCase).toBeUndefined();
|
|
209
|
+
expect(meta.staleGuidanceCase).toBeUndefined();
|
|
210
|
+
});
|
|
211
|
+
test("loader parses memory_ability + task_family from a tagged task", () => {
|
|
212
|
+
// Every seeded corpus task is tagged with at least these two fields by
|
|
213
|
+
// #262. Pick a representative entry and assert the round-trip.
|
|
214
|
+
const meta = loadTask("docker-homelab/restart-policy");
|
|
215
|
+
expect(meta.memoryAbility).toBe("procedural_lookup");
|
|
216
|
+
expect(meta.taskFamily).toBe("docker-homelab/compose-basics");
|
|
217
|
+
});
|
|
218
|
+
test("every seeded corpus task carries memory_ability + task_family", () => {
|
|
219
|
+
for (const task of listTasks()) {
|
|
220
|
+
expect(task.memoryAbility).toBeDefined();
|
|
221
|
+
expect(MEMORY_ABILITY_VALUES).toContain(task.memoryAbility);
|
|
222
|
+
expect(task.taskFamily).toBeDefined();
|
|
223
|
+
expect(task.taskFamily).toMatch(/^[a-z0-9][a-z0-9-]*\/[a-z0-9][a-z0-9-]*$/);
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
test("invalid memory_ability values are dropped (loader stays permissive)", () => {
|
|
227
|
+
const dir = benchMkdtemp("akm-bench-tag-");
|
|
228
|
+
try {
|
|
229
|
+
const taskDir = path.join(dir, "_example", "bad-tag");
|
|
230
|
+
fs.mkdirSync(taskDir, { recursive: true });
|
|
231
|
+
// Write a clone of `_example/example-task` augmented with a bogus tag.
|
|
232
|
+
const yaml = [
|
|
233
|
+
"id: _example/bad-tag",
|
|
234
|
+
'title: "Bogus tag"',
|
|
235
|
+
"domain: _example",
|
|
236
|
+
"difficulty: easy",
|
|
237
|
+
"slice: train",
|
|
238
|
+
"stash: minimal",
|
|
239
|
+
"verifier: script",
|
|
240
|
+
"budget:",
|
|
241
|
+
" tokens: 1000",
|
|
242
|
+
" wallMs: 30000",
|
|
243
|
+
"memory_ability: not_a_real_ability",
|
|
244
|
+
"task_family: _example/bad",
|
|
245
|
+
"",
|
|
246
|
+
].join("\n");
|
|
247
|
+
fs.writeFileSync(path.join(taskDir, "task.yaml"), yaml, "utf8");
|
|
248
|
+
const parsed = parseTaskYaml(readTaskBody(taskDir), taskDir);
|
|
249
|
+
expect(parsed).toBeDefined();
|
|
250
|
+
expect(parsed?.id).toBe("_example/bad-tag");
|
|
251
|
+
expect(parsed?.memoryAbility).toBeUndefined();
|
|
252
|
+
expect(parsed?.taskFamily).toBe("_example/bad");
|
|
253
|
+
}
|
|
254
|
+
finally {
|
|
255
|
+
fs.rmSync(dir, { recursive: true });
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
});
|