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,472 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* akm-bench workflow trace normalization (issue #254).
|
|
3
|
+
*
|
|
4
|
+
* Produces a single, normalized stream of `WorkflowTraceEvent`s from a finished
|
|
5
|
+
* `RunResult` so downstream consumers (#256 evaluator, workflow-compliance
|
|
6
|
+
* reports) have ONE place to ask "what did this agent actually do?" instead of
|
|
7
|
+
* scraping `events.jsonl`, agent stdout, workspace diffs, and verifier output
|
|
8
|
+
* independently.
|
|
9
|
+
*
|
|
10
|
+
* Inputs:
|
|
11
|
+
* • `RunResult.events` — structured AKM events (preferred when present).
|
|
12
|
+
* • Captured agent stdout / tool-call text (`agentStdout`).
|
|
13
|
+
* • Verifier output already lives on the run (`verifierStdout`).
|
|
14
|
+
* • Optional `workspaceWrites` — paths the harness observed touched. The
|
|
15
|
+
* normalizer will pick the first one as `first_workspace_write`.
|
|
16
|
+
* • Optional `harness` lifecycle markers (started/finished timestamps).
|
|
17
|
+
*
|
|
18
|
+
* Outputs a `WorkflowTraceResult` with a stable `schemaVersion: 1` field on the
|
|
19
|
+
* envelope so #256 (workflow evaluator, Wave 3) can pin against this contract.
|
|
20
|
+
*
|
|
21
|
+
* Design rules:
|
|
22
|
+
* • Pure: never mutates the input `RunResult` and never touches disk.
|
|
23
|
+
* • Bounded: caps total event count and per-event byte size. A pathological
|
|
24
|
+
* 1MiB stdout line CANNOT become a 1MiB event — see
|
|
25
|
+
* `MAX_EVENT_COUNT` / `MAX_EVENT_BYTES`.
|
|
26
|
+
* • Stable order: events sort by `(orderHint asc, sourceRank asc, originalIndex asc)`
|
|
27
|
+
* so the same RunResult always normalizes to the same trace.
|
|
28
|
+
* • Source attribution: every event carries a `source` so callers can tell
|
|
29
|
+
* where evidence came from when reconstructing the run.
|
|
30
|
+
*
|
|
31
|
+
* NOT in scope: live tailing, persistence, evaluation. Those belong to #256.
|
|
32
|
+
*/
|
|
33
|
+
/** Runtime set of all valid workflow trace event names. Single source of truth. */
|
|
34
|
+
export const WORKFLOW_TRACE_EVENT_NAMES = new Set([
|
|
35
|
+
"agent_started",
|
|
36
|
+
"akm_search",
|
|
37
|
+
"akm_show",
|
|
38
|
+
"akm_feedback",
|
|
39
|
+
"akm_reflect",
|
|
40
|
+
"akm_distill",
|
|
41
|
+
"akm_propose",
|
|
42
|
+
"akm_proposal_accept",
|
|
43
|
+
"akm_workflow_start",
|
|
44
|
+
"akm_workflow_next",
|
|
45
|
+
"akm_workflow_complete",
|
|
46
|
+
"akm_workflow_finish",
|
|
47
|
+
"workspace_read",
|
|
48
|
+
"workspace_write",
|
|
49
|
+
"first_workspace_write",
|
|
50
|
+
"test_run",
|
|
51
|
+
"verifier_run",
|
|
52
|
+
"agent_finished",
|
|
53
|
+
]);
|
|
54
|
+
/* ─── Caps (documented contract) ──────────────────────────────────────────── */
|
|
55
|
+
/** Hard cap on total events per trace. Prevents a noisy run from OOM-ing the harness. */
|
|
56
|
+
export const MAX_EVENT_COUNT = 4096;
|
|
57
|
+
/**
|
|
58
|
+
* Per-string-field byte cap. Applied to `query`, `assetRef`, `filePath`,
|
|
59
|
+
* `command`, and each `args[]` / `resultRefs[]` element. A pathological 1MiB
|
|
60
|
+
* stdout line cannot become a 1MiB event because every string we copy off it
|
|
61
|
+
* passes through `clamp(...)`.
|
|
62
|
+
*/
|
|
63
|
+
export const MAX_EVENT_BYTES = 4096;
|
|
64
|
+
/**
|
|
65
|
+
* Cap on bytes scanned from `agentStdout`. A runaway agent could emit GBs.
|
|
66
|
+
* 16 MiB matches `EVENTS_READ_CAP_BYTES` / `VERIFIER_STDOUT_SCAN_CAP` so the
|
|
67
|
+
* harness has a single mental model of "how much output we look at".
|
|
68
|
+
*/
|
|
69
|
+
export const MAX_STDOUT_SCAN_BYTES = 16 * 1024 * 1024;
|
|
70
|
+
const SOURCE_RANK = {
|
|
71
|
+
akm_events: 0,
|
|
72
|
+
harness: 1,
|
|
73
|
+
filesystem_diff: 2,
|
|
74
|
+
verifier: 3,
|
|
75
|
+
agent_stdout: 4,
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Normalize a `RunResult` (plus optional sidecar inputs) into a stable
|
|
79
|
+
* workflow trace. Pure function; never throws on malformed input — bad lines
|
|
80
|
+
* are skipped and a warning is appended to `options.warnings` if provided.
|
|
81
|
+
*/
|
|
82
|
+
export function normalizeRunToTrace(run, options = {}) {
|
|
83
|
+
const seeds = [];
|
|
84
|
+
let originalIndex = 0;
|
|
85
|
+
// 1) Harness lifecycle (if supplied).
|
|
86
|
+
if (options.harness?.agentStartedTs) {
|
|
87
|
+
seeds.push({
|
|
88
|
+
orderHint: options.harness.agentStartedTs,
|
|
89
|
+
sourceRank: SOURCE_RANK.harness,
|
|
90
|
+
originalIndex: originalIndex++,
|
|
91
|
+
partial: makePartial(run, options, {
|
|
92
|
+
type: "agent_started",
|
|
93
|
+
ts: options.harness.agentStartedTs,
|
|
94
|
+
source: "harness",
|
|
95
|
+
}),
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
// 2) AKM events.jsonl — preferred evidence for akm_search/show/feedback/etc.
|
|
99
|
+
for (const ev of run.events ?? []) {
|
|
100
|
+
const seed = fromAkmEvent(ev, run, options, originalIndex);
|
|
101
|
+
if (seed) {
|
|
102
|
+
seeds.push(seed);
|
|
103
|
+
originalIndex += 1;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// 3) Agent stdout — scan for `akm <verb>` invocations not already covered.
|
|
107
|
+
const stdoutSeeds = fromAgentStdout(options.agentStdout, run, options, originalIndex);
|
|
108
|
+
for (const seed of stdoutSeeds) {
|
|
109
|
+
seeds.push(seed);
|
|
110
|
+
originalIndex += 1;
|
|
111
|
+
}
|
|
112
|
+
// 4) Workspace writes — first becomes `first_workspace_write`.
|
|
113
|
+
if (options.workspaceWrites && options.workspaceWrites.length > 0) {
|
|
114
|
+
let isFirst = true;
|
|
115
|
+
for (const filePath of options.workspaceWrites) {
|
|
116
|
+
if (typeof filePath !== "string" || filePath.length === 0)
|
|
117
|
+
continue;
|
|
118
|
+
seeds.push({
|
|
119
|
+
// Workspace writes have no native timestamp; place them after akm_events
|
|
120
|
+
// by giving them a high lexical hint anchored to the run finish marker
|
|
121
|
+
// when present, else a sentinel that sorts after ISO timestamps.
|
|
122
|
+
orderHint: options.harness?.agentFinishedTs ?? "~workspace",
|
|
123
|
+
sourceRank: SOURCE_RANK.filesystem_diff,
|
|
124
|
+
originalIndex: originalIndex++,
|
|
125
|
+
partial: (() => {
|
|
126
|
+
const clampedFilePath = clamp(filePath);
|
|
127
|
+
const partial = makePartial(run, options, {
|
|
128
|
+
type: isFirst ? "first_workspace_write" : "workspace_write",
|
|
129
|
+
source: "filesystem_diff",
|
|
130
|
+
filePath: clampedFilePath.value,
|
|
131
|
+
});
|
|
132
|
+
if (clampedFilePath.truncated)
|
|
133
|
+
partial.bytesTruncated = true;
|
|
134
|
+
return partial;
|
|
135
|
+
})(),
|
|
136
|
+
});
|
|
137
|
+
isFirst = false;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// 5) Verifier — derive a single `verifier_run` event from the run envelope.
|
|
141
|
+
if (run.verifierExitCode !== undefined && run.verifierExitCode !== null) {
|
|
142
|
+
seeds.push({
|
|
143
|
+
orderHint: options.harness?.agentFinishedTs ?? "~verifier",
|
|
144
|
+
sourceRank: SOURCE_RANK.verifier,
|
|
145
|
+
originalIndex: originalIndex++,
|
|
146
|
+
partial: makePartial(run, options, {
|
|
147
|
+
type: "verifier_run",
|
|
148
|
+
source: "verifier",
|
|
149
|
+
exitCode: run.verifierExitCode,
|
|
150
|
+
}),
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
// 6) Harness finish (if supplied).
|
|
154
|
+
if (options.harness?.agentFinishedTs) {
|
|
155
|
+
seeds.push({
|
|
156
|
+
orderHint: `${options.harness.agentFinishedTs}~`,
|
|
157
|
+
sourceRank: SOURCE_RANK.harness,
|
|
158
|
+
originalIndex: originalIndex++,
|
|
159
|
+
partial: makePartial(run, options, {
|
|
160
|
+
type: "agent_finished",
|
|
161
|
+
ts: options.harness.agentFinishedTs,
|
|
162
|
+
source: "harness",
|
|
163
|
+
exitCode: run.verifierExitCode,
|
|
164
|
+
}),
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
// Stable sort: orderHint, then sourceRank, then originalIndex.
|
|
168
|
+
seeds.sort((a, b) => {
|
|
169
|
+
if (a.orderHint < b.orderHint)
|
|
170
|
+
return -1;
|
|
171
|
+
if (a.orderHint > b.orderHint)
|
|
172
|
+
return 1;
|
|
173
|
+
if (a.sourceRank !== b.sourceRank)
|
|
174
|
+
return a.sourceRank - b.sourceRank;
|
|
175
|
+
return a.originalIndex - b.originalIndex;
|
|
176
|
+
});
|
|
177
|
+
// Cap event count.
|
|
178
|
+
let truncated = false;
|
|
179
|
+
let kept = seeds;
|
|
180
|
+
if (seeds.length > MAX_EVENT_COUNT) {
|
|
181
|
+
kept = seeds.slice(0, MAX_EVENT_COUNT);
|
|
182
|
+
truncated = true;
|
|
183
|
+
if (options.warnings) {
|
|
184
|
+
options.warnings.push(`workflow trace truncated: ${seeds.length} events exceed ${MAX_EVENT_COUNT}-event cap; remainder dropped.`);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
const events = kept.map((seed, idx) => ({ id: idx, ...seed.partial }));
|
|
188
|
+
return {
|
|
189
|
+
schemaVersion: 1,
|
|
190
|
+
taskId: run.taskId,
|
|
191
|
+
arm: run.arm,
|
|
192
|
+
seed: run.seed,
|
|
193
|
+
events,
|
|
194
|
+
truncated,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
/* ─── Source: AKM events.jsonl envelopes ──────────────────────────────────── */
|
|
198
|
+
const AKM_EVENT_TYPE_MAP = {
|
|
199
|
+
search: "akm_search",
|
|
200
|
+
show: "akm_show",
|
|
201
|
+
feedback: "akm_feedback",
|
|
202
|
+
reflect_invoked: "akm_reflect",
|
|
203
|
+
distill_invoked: "akm_distill",
|
|
204
|
+
propose_invoked: "akm_propose",
|
|
205
|
+
promoted: "akm_proposal_accept",
|
|
206
|
+
workflow_started: "akm_workflow_start",
|
|
207
|
+
workflow_step_completed: "akm_workflow_complete",
|
|
208
|
+
workflow_finished: "akm_workflow_finish",
|
|
209
|
+
};
|
|
210
|
+
function fromAkmEvent(ev, run, options, originalIndex) {
|
|
211
|
+
if (!ev || typeof ev !== "object")
|
|
212
|
+
return null;
|
|
213
|
+
const envelope = ev;
|
|
214
|
+
const eventType = typeof envelope.eventType === "string" ? envelope.eventType : undefined;
|
|
215
|
+
if (!eventType)
|
|
216
|
+
return null;
|
|
217
|
+
const traceType = AKM_EVENT_TYPE_MAP[eventType];
|
|
218
|
+
if (!traceType)
|
|
219
|
+
return null; // ignore non-workflow events (add/remove/update/etc.)
|
|
220
|
+
const ts = typeof envelope.ts === "string" && envelope.ts.length > 0 ? envelope.ts : undefined;
|
|
221
|
+
const ref = typeof envelope.ref === "string" ? envelope.ref : undefined;
|
|
222
|
+
const meta = (envelope.metadata ?? undefined);
|
|
223
|
+
const partial = makePartial(run, options, {
|
|
224
|
+
type: traceType,
|
|
225
|
+
source: "akm_events",
|
|
226
|
+
ts,
|
|
227
|
+
});
|
|
228
|
+
let bytesTruncated = false;
|
|
229
|
+
if (ref) {
|
|
230
|
+
const clampedRef = clamp(ref);
|
|
231
|
+
partial.assetRef = clampedRef.value;
|
|
232
|
+
bytesTruncated ||= clampedRef.truncated;
|
|
233
|
+
}
|
|
234
|
+
// Pull useful structured fields off metadata when present. We deliberately
|
|
235
|
+
// probe a small whitelist so a malicious agent can't smuggle arbitrary
|
|
236
|
+
// payloads into the trace.
|
|
237
|
+
if (meta && typeof meta === "object") {
|
|
238
|
+
const q = meta.query;
|
|
239
|
+
if (typeof q === "string") {
|
|
240
|
+
const clampedQuery = clamp(q);
|
|
241
|
+
partial.query = clampedQuery.value;
|
|
242
|
+
bytesTruncated ||= clampedQuery.truncated;
|
|
243
|
+
}
|
|
244
|
+
const fp = meta.path ?? meta.filePath;
|
|
245
|
+
if (typeof fp === "string") {
|
|
246
|
+
const clampedFilePath = clamp(fp);
|
|
247
|
+
partial.filePath = clampedFilePath.value;
|
|
248
|
+
bytesTruncated ||= clampedFilePath.truncated;
|
|
249
|
+
}
|
|
250
|
+
const ec = meta.exitCode;
|
|
251
|
+
if (typeof ec === "number" && Number.isFinite(ec))
|
|
252
|
+
partial.exitCode = ec;
|
|
253
|
+
const refs = meta.resultRefs;
|
|
254
|
+
if (Array.isArray(refs)) {
|
|
255
|
+
partial.resultRefs = refs
|
|
256
|
+
.filter((r) => typeof r === "string")
|
|
257
|
+
.map((r) => {
|
|
258
|
+
const clampedRef = clamp(r);
|
|
259
|
+
bytesTruncated ||= clampedRef.truncated;
|
|
260
|
+
return clampedRef.value;
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
if (bytesTruncated)
|
|
265
|
+
partial.bytesTruncated = true;
|
|
266
|
+
return {
|
|
267
|
+
orderHint: ts ?? "akm-events", // events without ts sort after timestamped ones
|
|
268
|
+
sourceRank: SOURCE_RANK.akm_events,
|
|
269
|
+
originalIndex,
|
|
270
|
+
partial,
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
function fromAgentStdout(stdoutRaw, run, options, startIndex) {
|
|
274
|
+
if (!stdoutRaw)
|
|
275
|
+
return [];
|
|
276
|
+
const stdout = stdoutRaw.length > MAX_STDOUT_SCAN_BYTES ? stdoutRaw.slice(0, MAX_STDOUT_SCAN_BYTES) : stdoutRaw;
|
|
277
|
+
if (stdout.length < stdoutRaw.length && options.warnings) {
|
|
278
|
+
options.warnings.push(`workflow trace stdout truncated: ${stdoutRaw.length} chars exceeds ${MAX_STDOUT_SCAN_BYTES}-char cap; trace computed from the prefix.`);
|
|
279
|
+
}
|
|
280
|
+
const out = [];
|
|
281
|
+
let idx = startIndex;
|
|
282
|
+
// Match invocations like `akm search "query"`, `akm show skill:foo`, `akm feedback +1 skill:foo`.
|
|
283
|
+
// We scan line-by-line so position in the stdout becomes a stable order hint.
|
|
284
|
+
const lines = stdout.split("\n");
|
|
285
|
+
for (let lineNo = 0; lineNo < lines.length; lineNo += 1) {
|
|
286
|
+
const line = lines[lineNo];
|
|
287
|
+
const match = parseAkmCli(line);
|
|
288
|
+
if (!match)
|
|
289
|
+
continue;
|
|
290
|
+
const clampedCommand = clamp(match.command);
|
|
291
|
+
let bytesTruncated = clampedCommand.truncated;
|
|
292
|
+
const partial = makePartial(run, options, {
|
|
293
|
+
type: match.type,
|
|
294
|
+
source: "agent_stdout",
|
|
295
|
+
command: clampedCommand.value,
|
|
296
|
+
});
|
|
297
|
+
if (match.assetRef) {
|
|
298
|
+
const clampedRef = clamp(match.assetRef);
|
|
299
|
+
partial.assetRef = clampedRef.value;
|
|
300
|
+
bytesTruncated ||= clampedRef.truncated;
|
|
301
|
+
}
|
|
302
|
+
if (match.query) {
|
|
303
|
+
const clampedQuery = clamp(match.query);
|
|
304
|
+
partial.query = clampedQuery.value;
|
|
305
|
+
bytesTruncated ||= clampedQuery.truncated;
|
|
306
|
+
}
|
|
307
|
+
if (match.args) {
|
|
308
|
+
partial.args = match.args.map((arg) => {
|
|
309
|
+
const clampedArg = clamp(arg);
|
|
310
|
+
bytesTruncated ||= clampedArg.truncated;
|
|
311
|
+
return clampedArg.value;
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
if (bytesTruncated)
|
|
315
|
+
partial.bytesTruncated = true;
|
|
316
|
+
out.push({
|
|
317
|
+
// Stdout has no native timestamp; lexically place after timestamped events
|
|
318
|
+
// by using a leading `~` sentinel (sorts after all printable ASCII timestamps),
|
|
319
|
+
// then stable-order by line number padded to 8 digits.
|
|
320
|
+
orderHint: `~stdout-${String(lineNo).padStart(8, "0")}`,
|
|
321
|
+
sourceRank: SOURCE_RANK.agent_stdout,
|
|
322
|
+
originalIndex: idx,
|
|
323
|
+
partial,
|
|
324
|
+
});
|
|
325
|
+
idx += 1;
|
|
326
|
+
}
|
|
327
|
+
return out;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Recognise an `akm <verb> ...` invocation in a single line of agent output.
|
|
331
|
+
* Returns null when the line does not look like an akm CLI call.
|
|
332
|
+
*
|
|
333
|
+
* Supported shapes:
|
|
334
|
+
* • Bare CLI: `akm search "deploy docker"`
|
|
335
|
+
* • Tool-call: `tool: akm show skill:foo`
|
|
336
|
+
* • JSON-ish: `{"command":"akm","args":["search","deploy"]}`
|
|
337
|
+
*/
|
|
338
|
+
function parseAkmCli(line) {
|
|
339
|
+
if (!line || line.length === 0)
|
|
340
|
+
return null;
|
|
341
|
+
// Quick reject — every form contains the literal `akm` token.
|
|
342
|
+
if (line.indexOf("akm") === -1)
|
|
343
|
+
return null;
|
|
344
|
+
// JSON tool-call form first (most specific).
|
|
345
|
+
const jsonMatch = line.match(/"command"\s*:\s*"akm"\s*,\s*"args"\s*:\s*\[([^\]]*)\]/);
|
|
346
|
+
if (jsonMatch) {
|
|
347
|
+
const argList = jsonMatch[1]
|
|
348
|
+
.split(",")
|
|
349
|
+
.map((a) => a.trim().replace(/^"|"$/g, ""))
|
|
350
|
+
.filter(Boolean);
|
|
351
|
+
return classifyArgs("akm", argList);
|
|
352
|
+
}
|
|
353
|
+
// Bare CLI form: capture everything after `akm `.
|
|
354
|
+
const bareMatch = line.match(/(?:^|[\s>`'"])akm\s+(\w[\w-]*)(?:\s+([^\n]*))?/);
|
|
355
|
+
if (bareMatch) {
|
|
356
|
+
const verb = bareMatch[1];
|
|
357
|
+
const rest = (bareMatch[2] ?? "").trim();
|
|
358
|
+
const args = tokenizeArgs(rest);
|
|
359
|
+
return classifyArgs("akm", [verb, ...args]);
|
|
360
|
+
}
|
|
361
|
+
return null;
|
|
362
|
+
}
|
|
363
|
+
function classifyArgs(command, argv) {
|
|
364
|
+
if (argv.length === 0)
|
|
365
|
+
return null;
|
|
366
|
+
const verb = argv[0];
|
|
367
|
+
const rest = argv.slice(1);
|
|
368
|
+
switch (verb) {
|
|
369
|
+
case "search":
|
|
370
|
+
return { type: "akm_search", command, args: argv, query: rest.join(" ") || undefined };
|
|
371
|
+
case "show":
|
|
372
|
+
return { type: "akm_show", command, args: argv, assetRef: rest[0] };
|
|
373
|
+
case "feedback":
|
|
374
|
+
return { type: "akm_feedback", command, args: argv, assetRef: rest.find((a) => a.includes(":")) };
|
|
375
|
+
case "reflect":
|
|
376
|
+
return { type: "akm_reflect", command, args: argv };
|
|
377
|
+
case "distill":
|
|
378
|
+
return { type: "akm_distill", command, args: argv };
|
|
379
|
+
case "propose":
|
|
380
|
+
return { type: "akm_propose", command, args: argv };
|
|
381
|
+
case "workflow": {
|
|
382
|
+
const sub = rest[0];
|
|
383
|
+
if (sub === "start")
|
|
384
|
+
return { type: "akm_workflow_start", command, args: argv, assetRef: rest[1] };
|
|
385
|
+
if (sub === "next")
|
|
386
|
+
return { type: "akm_workflow_next", command, args: argv, assetRef: rest[1] };
|
|
387
|
+
if (sub === "complete")
|
|
388
|
+
return { type: "akm_workflow_complete", command, args: argv };
|
|
389
|
+
return null;
|
|
390
|
+
}
|
|
391
|
+
default:
|
|
392
|
+
return null;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Cheap shell-like tokenizer. Handles double-quoted and single-quoted strings;
|
|
397
|
+
* everything else splits on whitespace. Not a full POSIX parser — we only need
|
|
398
|
+
* "good enough" for opencode's tool-call logging.
|
|
399
|
+
*/
|
|
400
|
+
function tokenizeArgs(rest) {
|
|
401
|
+
const out = [];
|
|
402
|
+
let i = 0;
|
|
403
|
+
while (i < rest.length) {
|
|
404
|
+
while (i < rest.length && rest[i] === " ")
|
|
405
|
+
i += 1;
|
|
406
|
+
if (i >= rest.length)
|
|
407
|
+
break;
|
|
408
|
+
const ch = rest[i];
|
|
409
|
+
if (ch === '"' || ch === "'") {
|
|
410
|
+
const quote = ch;
|
|
411
|
+
i += 1;
|
|
412
|
+
const start = i;
|
|
413
|
+
while (i < rest.length && rest[i] !== quote)
|
|
414
|
+
i += 1;
|
|
415
|
+
out.push(rest.slice(start, i));
|
|
416
|
+
if (i < rest.length)
|
|
417
|
+
i += 1;
|
|
418
|
+
}
|
|
419
|
+
else {
|
|
420
|
+
const start = i;
|
|
421
|
+
while (i < rest.length && rest[i] !== " ")
|
|
422
|
+
i += 1;
|
|
423
|
+
out.push(rest.slice(start, i));
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
return out;
|
|
427
|
+
}
|
|
428
|
+
/* ─── Helpers ─────────────────────────────────────────────────────────────── */
|
|
429
|
+
function makePartial(run, options, fields) {
|
|
430
|
+
const base = {
|
|
431
|
+
taskId: run.taskId,
|
|
432
|
+
arm: run.arm,
|
|
433
|
+
seed: run.seed,
|
|
434
|
+
type: fields.type,
|
|
435
|
+
source: fields.source,
|
|
436
|
+
};
|
|
437
|
+
if (options.runId)
|
|
438
|
+
base.runId = options.runId;
|
|
439
|
+
if (fields.ts !== undefined)
|
|
440
|
+
base.ts = fields.ts;
|
|
441
|
+
if (fields.command !== undefined)
|
|
442
|
+
base.command = fields.command;
|
|
443
|
+
if (fields.args !== undefined)
|
|
444
|
+
base.args = fields.args;
|
|
445
|
+
if (fields.assetRef !== undefined)
|
|
446
|
+
base.assetRef = fields.assetRef;
|
|
447
|
+
if (fields.query !== undefined)
|
|
448
|
+
base.query = fields.query;
|
|
449
|
+
if (fields.resultRefs !== undefined)
|
|
450
|
+
base.resultRefs = fields.resultRefs;
|
|
451
|
+
if (fields.filePath !== undefined)
|
|
452
|
+
base.filePath = fields.filePath;
|
|
453
|
+
if (fields.exitCode !== undefined)
|
|
454
|
+
base.exitCode = fields.exitCode;
|
|
455
|
+
return base;
|
|
456
|
+
}
|
|
457
|
+
/** Clamp a single string to MAX_EVENT_BYTES UTF-8 bytes without splitting code points. */
|
|
458
|
+
function clamp(value) {
|
|
459
|
+
if (Buffer.byteLength(value, "utf8") <= MAX_EVENT_BYTES) {
|
|
460
|
+
return { value, truncated: false };
|
|
461
|
+
}
|
|
462
|
+
let out = "";
|
|
463
|
+
let bytes = 0;
|
|
464
|
+
for (const ch of value) {
|
|
465
|
+
const nextBytes = Buffer.byteLength(ch, "utf8");
|
|
466
|
+
if (bytes + nextBytes > MAX_EVENT_BYTES)
|
|
467
|
+
break;
|
|
468
|
+
out += ch;
|
|
469
|
+
bytes += nextBytes;
|
|
470
|
+
}
|
|
471
|
+
return { value: out, truncated: true };
|
|
472
|
+
}
|