akm-cli 0.9.31 → 0.10.261002-beta

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.
Files changed (270) hide show
  1. package/CHANGELOG.md +420 -0
  2. package/STABILITY.md +99 -57
  3. package/dist/api-node.mjs +20 -0
  4. package/dist/api.d.ts +23 -0
  5. package/dist/api.js +45 -0
  6. package/dist/assets/hints/cli-hints-full.md +15 -29
  7. package/dist/assets/hints/cli-hints-short.md +2 -2
  8. package/dist/assets/improve-strategies/default.json +3 -3
  9. package/dist/assets/prompts/consolidate-pair.md +9 -7
  10. package/dist/assets/stash-skeleton/README.md +1 -1
  11. package/dist/assets/tasks/improve/akm-improve-consolidate.yml +1 -1
  12. package/dist/cli/shared.js +31 -48
  13. package/dist/cli/unknown-flags.js +6 -43
  14. package/dist/cli.js +8 -34
  15. package/dist/commands/agent/contribute-cli.js +1 -1
  16. package/dist/commands/completions.js +1 -2
  17. package/dist/commands/config-cli.js +5 -28
  18. package/dist/commands/env/env-cli.js +5 -5
  19. package/dist/commands/env/secret-cli.js +2 -2
  20. package/dist/commands/feedback-cli.js +75 -49
  21. package/dist/commands/health/checks.js +41 -16
  22. package/dist/commands/health/plugin-staleness.js +52 -22
  23. package/dist/commands/improve/autonomy-gate.js +5 -3
  24. package/dist/commands/improve/consolidate/chunking.js +3 -10
  25. package/dist/commands/improve/consolidate/continuity-check.js +4 -4
  26. package/dist/commands/improve/consolidate/pair-pass.js +29 -10
  27. package/dist/commands/improve/consolidate.js +10 -65
  28. package/dist/commands/improve/distill/lesson-update.js +91 -0
  29. package/dist/commands/improve/distill-guards.js +1 -43
  30. package/dist/commands/improve/distill.js +148 -21
  31. package/dist/commands/improve/eligibility.js +14 -1
  32. package/dist/commands/improve/extract-cli.js +1 -1
  33. package/dist/commands/improve/extract-prompt.js +17 -7
  34. package/dist/commands/improve/extract.js +5 -7
  35. package/dist/commands/improve/improve-cli.js +92 -106
  36. package/dist/commands/improve/improve-strategies.js +8 -12
  37. package/dist/commands/improve/improve.js +134 -52
  38. package/dist/commands/improve/loop-stages.js +18 -5
  39. package/dist/commands/improve/planner.js +0 -1
  40. package/dist/commands/improve/preparation.js +40 -99
  41. package/dist/commands/improve/proactive-maintenance.js +2 -2
  42. package/dist/commands/improve/reflect-noise.js +3 -55
  43. package/dist/commands/improve/reflect.js +29 -34
  44. package/dist/commands/improve/retrieval-queries.js +37 -0
  45. package/dist/commands/improve/retrieval-scope.js +2 -2
  46. package/dist/commands/improve/salience.js +2 -9
  47. package/dist/commands/improve/session-asset.js +4 -1
  48. package/dist/commands/improve/stage.js +23 -12
  49. package/dist/commands/lint/index.js +5 -20
  50. package/dist/commands/observability-cli.js +3 -9
  51. package/dist/commands/proposal/drain.js +43 -6
  52. package/dist/commands/proposal/proposal-cli.js +11 -31
  53. package/dist/commands/proposal/repository.js +20 -14
  54. package/dist/commands/proposal/validators/proposal-quality-validators.js +0 -3
  55. package/dist/commands/read/knowledge.js +3 -3
  56. package/dist/commands/read/remember-cli.js +0 -13
  57. package/dist/commands/read/search-cli.js +29 -97
  58. package/dist/commands/read/search.js +0 -11
  59. package/dist/commands/read/show.js +0 -19
  60. package/dist/commands/sources/plugin-upgrade.js +164 -101
  61. package/dist/commands/sources/sources-cli.js +1 -15
  62. package/dist/commands/sources/stash-cli.js +6 -14
  63. package/dist/commands/tasks/tasks-cli.js +4 -115
  64. package/dist/commands/workflow/plan.js +11 -33
  65. package/dist/commands/workflow-cli.js +2 -7
  66. package/dist/core/adapter/adapter-ids.js +1 -2
  67. package/dist/core/adapter/adapters/agent-skills-adapter.js +0 -4
  68. package/dist/core/adapter/adapters/akm-adapter.js +9 -48
  69. package/dist/core/adapter/adapters/akm-lint.js +10 -26
  70. package/dist/core/adapter/adapters/akm-metadata.js +2 -72
  71. package/dist/core/adapter/adapters/akm-task-adapter.js +0 -5
  72. package/dist/core/adapter/adapters/akm-workflow-adapter.js +9 -28
  73. package/dist/core/adapter/adapters/dotenv-adapter.js +1 -20
  74. package/dist/core/adapter/adapters/generic-files-adapter.js +0 -10
  75. package/dist/core/adapter/adapters/llm-wiki-adapter.js +0 -4
  76. package/dist/core/adapter/adapters/tool-dir-shared.js +0 -24
  77. package/dist/core/adapter/adapters/website-snapshot-adapter.js +4 -4
  78. package/dist/core/adapter/recognize-match.js +3 -4
  79. package/dist/core/common.js +18 -2
  80. package/dist/core/config/config-schema.js +12 -15
  81. package/dist/core/config/config-types.js +6 -15
  82. package/dist/core/config/config-walker.js +6 -23
  83. package/dist/core/config/config.js +17 -80
  84. package/dist/core/config/engine-semantics.js +7 -3
  85. package/dist/core/config/schema/engines.js +7 -7
  86. package/dist/core/config/schema/improve-processes.js +10 -63
  87. package/dist/core/config/schema/improve.js +2 -21
  88. package/dist/core/config/schema/index-config.js +6 -39
  89. package/dist/core/env-secret-ref.js +2 -45
  90. package/dist/core/errors.js +1 -2
  91. package/dist/core/extra-params.js +2 -86
  92. package/dist/core/file-lock.js +2 -6
  93. package/dist/core/improve-result.js +13 -1
  94. package/dist/core/mutation-target.js +2 -2
  95. package/dist/core/paths.js +4 -0
  96. package/dist/core/recognition-util.js +4 -5
  97. package/dist/core/run-lock.js +1 -1
  98. package/dist/core/subprocess.js +49 -0
  99. package/dist/core/warn.js +21 -4
  100. package/dist/core/write-source.js +3 -3
  101. package/dist/execution/target-ref.js +1 -2
  102. package/dist/indexer/indexer.js +15 -6
  103. package/dist/indexer/passes/memory-inference.js +15 -6
  104. package/dist/indexer/search/db-search.js +49 -36
  105. package/dist/indexer/search/fts-query.js +0 -19
  106. package/dist/indexer/search/ranking.js +29 -1
  107. package/dist/indexer/usage/usage-events.js +21 -16
  108. package/dist/integrations/agent/engine-resolution.js +5 -2
  109. package/dist/integrations/agent/index.js +1 -1
  110. package/dist/integrations/agent/profiles.js +41 -98
  111. package/dist/integrations/agent/request-lowering.js +3 -3
  112. package/dist/integrations/harnesses/aider/index.js +5 -0
  113. package/dist/integrations/harnesses/amazonq/index.js +1 -0
  114. package/dist/integrations/harnesses/claude/config-import.js +2 -3
  115. package/dist/integrations/harnesses/claude/index.js +5 -0
  116. package/dist/integrations/harnesses/codex/index.js +1 -0
  117. package/dist/integrations/harnesses/copilot/index.js +1 -0
  118. package/dist/integrations/harnesses/gemini/index.js +1 -0
  119. package/dist/integrations/harnesses/index.js +18 -39
  120. package/dist/integrations/harnesses/opencode/agent-builder.js +60 -35
  121. package/dist/integrations/harnesses/opencode/config-import.js +121 -52
  122. package/dist/integrations/harnesses/opencode/index.js +22 -0
  123. package/dist/integrations/harnesses/opencode/plugin-layout.js +68 -0
  124. package/dist/integrations/harnesses/opencode/session-log-types.js +12 -0
  125. package/dist/integrations/harnesses/opencode/session-log-v1.js +72 -0
  126. package/dist/integrations/harnesses/opencode/session-log-v2.js +140 -0
  127. package/dist/integrations/harnesses/opencode/session-log.js +104 -115
  128. package/dist/integrations/harnesses/opencode/version.js +98 -0
  129. package/dist/integrations/harnesses/opencode-sdk/{harness.js → index.js} +5 -17
  130. package/dist/integrations/harnesses/opencode-sdk/sdk-runner.js +105 -206
  131. package/dist/integrations/harnesses/opencode-sdk/v1-adapter.js +199 -0
  132. package/dist/integrations/harnesses/opencode-sdk/v2-adapter.js +254 -0
  133. package/dist/integrations/harnesses/opencode-sdk/wire.js +66 -0
  134. package/dist/integrations/harnesses/openhands/index.js +1 -0
  135. package/dist/integrations/harnesses/pi/index.js +1 -0
  136. package/dist/integrations/harnesses/shared.js +2 -0
  137. package/dist/integrations/harnesses/types.js +2 -0
  138. package/dist/llm/client.js +41 -11
  139. package/dist/output/cli-hints.js +1 -1
  140. package/dist/output/context.js +10 -19
  141. package/dist/output/format-exempt.js +5 -8
  142. package/dist/output/shapes/helpers.js +1 -22
  143. package/dist/output/shapes/passthrough.js +0 -1
  144. package/dist/output/shapes.js +3 -31
  145. package/dist/output/stdout.js +5 -1
  146. package/dist/output/text/command-format.js +6 -1
  147. package/dist/output/text/workflow-format.js +4 -22
  148. package/dist/scripts/akm-migrate-node.js +15745 -16711
  149. package/dist/scripts/akm-migrate.js +16318 -17280
  150. package/dist/setup/detect.js +10 -4
  151. package/dist/setup/harness-config-import.js +5 -14
  152. package/dist/setup/setup.js +1 -1
  153. package/dist/setup/steps/tasks.js +12 -13
  154. package/dist/sources/providers/git-stash.js +113 -16
  155. package/dist/storage/repositories/index-utility-repository.js +2 -32
  156. package/dist/storage/repositories/index-vec-repository.js +4 -0
  157. package/dist/storage/repositories/task-history-repository.js +0 -5
  158. package/dist/storage/repositories/workflow-runs-repository.js +5 -15
  159. package/dist/tasks/embedded.js +2 -1
  160. package/dist/tasks/run/run-command-task.js +9 -1
  161. package/dist/tasks/run/run-workflow-task.js +4 -3
  162. package/dist/tasks/run/task-history.js +0 -2
  163. package/dist/tasks/run/task-log.js +38 -1
  164. package/dist/tasks/schedule-gates.js +39 -0
  165. package/dist/tasks/scheduler-binding.js +0 -16
  166. package/dist/tasks/scheduler-sync.js +3 -97
  167. package/dist/tasks/source/bounded-document.js +1 -1
  168. package/dist/tasks/source/task-source-v4.js +2 -12
  169. package/dist/tasks/task-run-reserved-flags.js +2 -31
  170. package/dist/workflows/authoring/authoring.js +6 -6
  171. package/dist/workflows/compile.js +8 -65
  172. package/dist/workflows/exec/child-workflow.js +22 -3
  173. package/dist/workflows/exec/native-executor.js +12 -147
  174. package/dist/workflows/exec/run-workflow.js +31 -103
  175. package/dist/workflows/exec/step-work.js +9 -178
  176. package/dist/workflows/exec/unit-dispatch.js +0 -10
  177. package/dist/workflows/freeze/environment.js +3 -44
  178. package/dist/workflows/freeze/freeze.js +8 -41
  179. package/dist/workflows/freeze/targets/child-workflow.js +27 -63
  180. package/dist/workflows/freeze/targets/command.js +2 -16
  181. package/dist/workflows/freeze/targets/shell.js +0 -2
  182. package/dist/workflows/freeze/task-bindings.js +2 -28
  183. package/dist/workflows/ir/params.js +12 -2
  184. package/dist/workflows/parser.js +82 -232
  185. package/dist/workflows/plan.js +1 -1
  186. package/dist/workflows/renderer.js +10 -19
  187. package/dist/workflows/runtime/run-plan.js +11 -53
  188. package/dist/workflows/runtime/runs.js +4 -27
  189. package/dist/workflows/source-files.js +12 -16
  190. package/dist/workflows/source-semantics.js +1 -93
  191. package/docs/README.md +1 -1
  192. package/docs/agents/README.md +3 -3
  193. package/docs/agents/agent-install.md +1 -1
  194. package/docs/architecture/0.10-process-rules.md +827 -0
  195. package/docs/architecture/adapters.md +17 -31
  196. package/docs/architecture/architecture.md +4 -5
  197. package/docs/architecture/improvement.md +115 -76
  198. package/docs/architecture/internals/improve-workflow.md +22 -16
  199. package/docs/architecture/internals/indexing.md +1 -1
  200. package/docs/architecture/internals/search.md +1 -2
  201. package/docs/architecture/internals/storage-locations.md +6 -6
  202. package/docs/architecture/persisted-data-compat.md +13 -4
  203. package/docs/architecture/specs/0.9.0-decisions.md +6 -2
  204. package/docs/architecture/specs/improve-collapse-churn-detector-design.md +2 -2
  205. package/docs/architecture/specs/workflow-format-unification.md +1 -6
  206. package/docs/architecture/testing/manual-testing-checklist.md +21 -30
  207. package/docs/architecture/testing/task-workflow-manual-tests.md +106 -203
  208. package/docs/architecture/testing/testing-workflow.md +1 -1
  209. package/docs/architecture/workflow-engine.md +5 -56
  210. package/docs/guides/author-workflows.md +39 -69
  211. package/docs/guides/bundles.md +3 -1
  212. package/docs/guides/capture-knowledge.md +1 -1
  213. package/docs/guides/claude-code-vs-akm-workflows.md +1 -2
  214. package/docs/guides/discover-and-load.md +4 -4
  215. package/docs/guides/getting-started.md +1 -1
  216. package/docs/guides/improve-the-library.md +10 -9
  217. package/docs/guides/recipes/headless-install.md +2 -2
  218. package/docs/guides/run-workflows.md +1 -1
  219. package/docs/guides/scheduling.md +9 -1
  220. package/docs/guides/use-with-any-agent.md +49 -4
  221. package/docs/integration/bundling-akm.md +7 -6
  222. package/docs/maintainers/curate-workmap.md +1 -2
  223. package/docs/maintainers/release-checklist.md +33 -1
  224. package/docs/migration/README.md +2 -0
  225. package/docs/migration/release-notes/0.10.0.md +201 -0
  226. package/docs/migration/release-notes/README.md +1 -0
  227. package/docs/migration/v0.9-to-v0.10.md +507 -0
  228. package/docs/posts/akm-command-tour.md +3 -3
  229. package/docs/product-surface.md +1 -1
  230. package/docs/reference/README.md +1 -0
  231. package/docs/reference/api.md +65 -0
  232. package/docs/reference/asset-types.md +3 -5
  233. package/docs/reference/bundle-types.md +2 -4
  234. package/docs/reference/cli.md +160 -188
  235. package/docs/reference/configuration.md +101 -20
  236. package/docs/reference/data-and-telemetry.md +2 -2
  237. package/docs/reference/env-and-secrets.md +2 -2
  238. package/docs/reference/supported-formats.md +3 -4
  239. package/docs/reference/tasks.md +12 -19
  240. package/docs/reference/website-sources.md +1 -1
  241. package/docs/reference/workflow-schema.md +89 -317
  242. package/docs/reference/workflows.md +20 -48
  243. package/package.json +12 -2
  244. package/schemas/akm-config.json +2 -243
  245. package/schemas/akm-task.json +2 -3
  246. package/schemas/akm-workflow.json +47 -84
  247. package/dist/assets/improve-strategies/catchup.json +0 -41
  248. package/dist/assets/improve-strategies/proactive-maintenance.json +0 -24
  249. package/dist/assets/improve-strategies/quick.json +0 -17
  250. package/dist/assets/improve-strategies/reflect-distill.json +0 -29
  251. package/dist/assets/improve-strategies/thorough.json +0 -49
  252. package/dist/assets/prompts/retrieval-relevance-judge.md +0 -6
  253. package/dist/assets/tasks/improve/akm-improve-catchup.yml +0 -6
  254. package/dist/assets/tasks/improve/akm-improve-frequent.yml +0 -4
  255. package/dist/assets/tasks/improve/akm-improve-nightly.yml +0 -4
  256. package/dist/cli/retired-commands.js +0 -118
  257. package/dist/commands/improve/retrieval-gate.js +0 -132
  258. package/dist/commands/tasks/validate.js +0 -176
  259. package/dist/core/config/legacy-source-shape-shim.js +0 -117
  260. package/dist/indexer/feedback/utility-policy.js +0 -75
  261. package/dist/integrations/harnesses/ids.js +0 -28
  262. package/dist/tasks/source/task-source-v3-frozen.js +0 -424
  263. package/dist/tasks/source/task-to-v4.js +0 -863
  264. package/dist/workflows/exec/worktree.js +0 -372
  265. package/dist/workflows/freeze/child-output-references.js +0 -83
  266. package/dist/workflows/freeze/identity.js +0 -22
  267. package/dist/workflows/freeze/targets/script.js +0 -50
  268. package/dist/workflows/freeze/targets/task.js +0 -124
  269. package/dist/workflows/github-yaml.js +0 -506
  270. package/dist/workflows/runtime/run-outputs.js +0 -80
@@ -22,7 +22,7 @@ import { getLiveRefSnapshot, isRefLiveInSnapshot, } from "../../storage/reposito
22
22
  import { clearAssetOutcomeMissing, countAssetOutcomeMissing, deleteAssetOutcomeMissingBefore, listAssetOutcomeMissingState, stampAssetOutcomeMissing, } from "../../storage/repositories/outcome-repository.js";
23
23
  import { clearAssetSalienceMissing, countAssetSalienceMissing, deleteAssetSalienceMissingBefore, listAssetSalienceMissingState, stampAssetSalienceMissing, } from "../../storage/repositories/salience-repository.js";
24
24
  import { readFreelistInfo, STATE_DB_VACUUMED_EVENT, vacuumIfReclaimable } from "../../storage/state-db-integrity.js";
25
- import { purgeOldTaskLogFiles } from "../../tasks/run/task-log.js";
25
+ import { purgeOldRunLogFiles, purgeOldTaskLogFiles } from "../../tasks/run/task-log.js";
26
26
  import { expireStaleProposals, purgeOrphanProposals } from "../proposal/repository.js";
27
27
  import { checkDeadUrls } from "../url-checker.js";
28
28
  import { isDistillCandidateRef } from "./eligibility.js";
@@ -148,7 +148,6 @@ async function runLoopReflectPass(planned, env, tally) {
148
148
  ...(options.sourceName && primaryStashDir ? { target: { source: options.sourceName, root: primaryStashDir } } : {}),
149
149
  ...(reflectErrors.length > 0 ? { avoidPatterns: [...reflectErrors] } : {}),
150
150
  eventSource: "improve",
151
- lowValueFilter: improveProfile.processes?.reflect?.lowValueFilter?.enabled === true,
152
151
  ...(improveProfile.processes?.reflect?.defectFilter
153
152
  ? { defectFilter: improveProfile.processes.reflect.defectFilter }
154
153
  : {}),
@@ -174,10 +173,18 @@ async function runLoopReflectPass(planned, env, tally) {
174
173
  result,
175
174
  });
176
175
  // A quality rejection recorded itself, and the judge's text is no lesson for
177
- // the next prompt; skips revisit on the `unchanged` cadence.
176
+ // the next prompt; skips revisit on the `unchanged` cadence. A transient
177
+ // failure (transport, parse, timeout, budget abort, crash) is not a verdict
178
+ // on the asset and writes no row, like distill: a `failed` row would advance
179
+ // the ledger cursor and consume the feedback that planned the ref. Only a
180
+ // guard rejection records `failed`.
178
181
  if (!result.ok && reason !== "quality_rejected") {
179
- recordLoopAttempt(planned, env, "reflect", skipped ? "unchanged" : "failed", reason);
180
- if (!skipped) {
182
+ if (skipped)
183
+ recordLoopAttempt(planned, env, "reflect", "unchanged", reason);
184
+ else if (reason === "content_policy_reject")
185
+ recordLoopAttempt(planned, env, "reflect", "failed", reason);
186
+ // A budget abort is no lesson for the next prompt either.
187
+ if (!skipped && reason !== "aborted") {
181
188
  tally.recentErrorPushes.push({
182
189
  originator: "reflect",
183
190
  message: result.error ?? reason ?? "unknown reflect error",
@@ -588,6 +595,12 @@ export function runRetentionPurgePass(ctx) {
588
595
  catch (err) {
589
596
  warnings.push(`task log files purge failed: ${errMessage(err)}`);
590
597
  }
598
+ try {
599
+ report("run_log_files_purged", "run_log_files/_purge", purgeOldRunLogFiles(retentionDays), "improve/index run log file(s)");
600
+ }
601
+ catch (err) {
602
+ warnings.push(`run log files purge failed: ${errMessage(err)}`);
603
+ }
591
604
  return { warnings };
592
605
  }
593
606
  /**
@@ -99,7 +99,6 @@ export function buildImproveExecutionPlan(input) {
99
99
  effective: { ...input.consolidation.effective },
100
100
  gates: {
101
101
  profile: { ...input.consolidation.gates.profile },
102
- minimumPool: { ...input.consolidation.gates.minimumPool },
103
102
  delta: { ...input.consolidation.gates.delta },
104
103
  },
105
104
  },
@@ -9,8 +9,8 @@
9
9
  * Candidate selection reads the improve ledger plus one set of signals: a ref
10
10
  * is eligible for a source when feedback newer than its last attempt landed and
11
11
  * no ledger window holds it, and reflect reads only negative feedback. Refs
12
- * without recent feedback can still be picked by the fallback lanes (proactive
13
- * maintenance, high salience), which only score them; the survivors are ranked
12
+ * without recent feedback can still be picked by the proactive-maintenance
13
+ * lane, which plans them with the rest; the survivors are ranked
14
14
  * by salience, checked on disk and capped. A plan-only run evaluates the same
15
15
  * selectors against read snapshots and writes nothing.
16
16
  */
@@ -35,7 +35,7 @@ import { isAutonomyLaneAllowed } from "./autonomy-gate.js";
35
35
  import { akmConsolidate, inspectConsolidationPool, loadExistingKnowledgeBodyHashes, makeConsolidateResult, } from "./consolidate.js";
36
36
  import { computeSafeChunkSize, DEFAULT_CONTEXT_LENGTH_TOKENS } from "./consolidate/chunking.js";
37
37
  import { contentHash } from "./content-hash.js";
38
- import { assetTypeOf, buildUtilityMap, dedupeRefs, findAssetFilePath, isDistillCandidateRef, isLessonCandidate, resolveImproveScope, withIndexDb, } from "./eligibility.js";
38
+ import { assetTypeOf, buildUtilityMap, dedupeRefs, findAssetFilePath, isDistillCandidateRef, isLessonCandidate, withIndexDb, } from "./eligibility.js";
39
39
  import { akmExtract, countNewExtractCandidates } from "./extract.js";
40
40
  import { computeValenceScore } from "./feedback-valence.js";
41
41
  import { isLedgerBlocked, lastAttemptByRef, ledgerRowFor, loadLedgerSnapshot, stateKey, } from "./ledger.js";
@@ -81,7 +81,7 @@ export function pickDefined(source, keys) {
81
81
  out[key] = source[key];
82
82
  return out;
83
83
  }
84
- export const CONSOLIDATION_CONFIG_KEYS = ["enabled", "minPoolSize", "limit", "maxChunkSize"];
84
+ export const CONSOLIDATION_CONFIG_KEYS = ["enabled", "limit", "maxChunkSize"];
85
85
  /** Emit an aggregate `improve_skipped` row (never one per ref). */
86
86
  export function recordImproveSkip(eventsCtx, ref, metadata) {
87
87
  appendEvent({ eventType: "improve_skipped", ref, metadata }, eventsCtx);
@@ -96,19 +96,13 @@ export function pushRecentError(recentErrors, originator, msg) {
96
96
  }
97
97
  // ── Consolidation ────────────────────────────────────────────────────────────
98
98
  /**
99
- * The consolidation gates and pool, with no model call: the profile toggle,
100
- * `minPoolSize` (not for a named strategy or ref scope, nor once the pool is
101
- * over the 100-memory volume trigger), and the ledger delta (every memory
102
- * judged recently and unchanged since means nothing to do).
99
+ * The consolidation gates and pool, with no model call: the profile toggle
100
+ * and the ledger delta (every memory judged recently and unchanged since
101
+ * means nothing to do).
103
102
  */
104
103
  function planConsolidationPass(args) {
105
- const { options, primaryStashDir, memorySummary, resolvedPlan } = args;
104
+ const { options, primaryStashDir, resolvedPlan } = args;
106
105
  const processConfig = args.improveProfile?.processes?.consolidate;
107
- const volumeTriggered = memorySummary.eligible > 100 && resolvedPlan.processes.consolidate.runner !== null;
108
- const minPoolSize = typeof processConfig?.minPoolSize === "number" ? processConfig.minPoolSize : 0;
109
- const eligiblePoolSize = typeof memorySummary.eligible === "number" ? memorySummary.eligible : 0;
110
- const userNamed = options.strategy !== undefined || resolveImproveScope(options.scope).mode === "ref";
111
- const poolBelowMinSize = !volumeTriggered && !userNamed && minPoolSize > 0 && eligiblePoolSize < minPoolSize;
112
106
  const pool = primaryStashDir
113
107
  ? inspectConsolidationPool({
114
108
  config: options.config,
@@ -127,18 +121,13 @@ function planConsolidationPass(args) {
127
121
  DEFAULT_CONTEXT_LENGTH_TOKENS, 500, processConfig?.maxChunkSize);
128
122
  const profilePassed = processConfig?.enabled !== false;
129
123
  const deltaPassed = pool.candidatePoolSize > 0 || pool.judgedUnchanged === 0;
130
- const wouldRun = profilePassed && !poolBelowMinSize && deltaPassed && pool.candidatePoolSize > 0;
131
- const belowMin = `pool ${eligiblePoolSize} is below minPoolSize ${minPoolSize}`;
124
+ const wouldRun = profilePassed && deltaPassed && pool.candidatePoolSize > 0;
132
125
  const unchanged = "every memory was judged recently and is unchanged since";
133
126
  return {
134
- poolBelowMinSize,
135
- eligiblePoolSize,
136
- minPoolSize,
137
127
  plan: {
138
128
  configured: pickDefined(processConfig, CONSOLIDATION_CONFIG_KEYS),
139
129
  effective: {
140
130
  enabled: profilePassed,
141
- minPoolSize,
142
131
  ...(processConfig?.limit !== undefined ? { limit: processConfig.limit } : {}),
143
132
  chunkSize,
144
133
  },
@@ -149,10 +138,6 @@ function planConsolidationPass(args) {
149
138
  passed: profilePassed,
150
139
  reason: profilePassed ? "consolidation enabled" : "disabled by improve profile",
151
140
  },
152
- minimumPool: {
153
- passed: !poolBelowMinSize,
154
- reason: poolBelowMinSize ? belowMin : `pool satisfies minPoolSize ${minPoolSize}`,
155
- },
156
141
  delta: {
157
142
  passed: deltaPassed,
158
143
  reason: !deltaPassed
@@ -165,13 +150,11 @@ function planConsolidationPass(args) {
165
150
  wouldRun,
166
151
  reason: !profilePassed
167
152
  ? "disabled by improve profile"
168
- : poolBelowMinSize
169
- ? belowMin
170
- : !deltaPassed
171
- ? unchanged
172
- : pool.candidatePoolSize === 0
173
- ? "candidate pool is empty after narrowing"
174
- : "all consolidation gates pass",
153
+ : !deltaPassed
154
+ ? unchanged
155
+ : pool.candidatePoolSize === 0
156
+ ? "candidate pool is empty after narrowing"
157
+ : "all consolidation gates pass",
175
158
  estimatedChunks: wouldRun ? Math.ceil(pool.candidatePoolSize / chunkSize) : 0,
176
159
  },
177
160
  };
@@ -186,14 +169,6 @@ async function runConsolidationPass(args) {
186
169
  if (!planned.plan.gates.profile.passed) {
187
170
  info("[improve] consolidation skipped (disabled by improve profile)");
188
171
  }
189
- else if (planned.poolBelowMinSize) {
190
- recordImproveSkip(eventsCtx, "memories/_consolidation", {
191
- reason: "pool_below_min_size",
192
- poolSize: planned.eligiblePoolSize,
193
- minPoolSize: planned.minPoolSize,
194
- });
195
- info(`[improve] consolidation skipped (pool ${planned.eligiblePoolSize} < minPoolSize ${planned.minPoolSize})`);
196
- }
197
172
  else if (!planned.plan.gates.delta.passed) {
198
173
  recordImproveSkip(eventsCtx, "memories/_consolidation", { reason: "consolidation_no_memory_updates" });
199
174
  info("[improve] consolidation skipped (every memory was judged recently and is unchanged)");
@@ -212,7 +187,6 @@ async function runConsolidationPass(args) {
212
187
  limit: processConfig?.limit,
213
188
  maxChunkSize: processConfig?.maxChunkSize,
214
189
  signal: args.budgetSignal,
215
- p90ChunkSecondsDefault: processConfig?.p90ChunkSecondsDefault,
216
190
  // Its read-only proposal lookups go through the run's own state.db handle.
217
191
  ...(eventsCtx?.db ? { proposalsCtx: { db: eventsCtx.db } } : {}),
218
192
  }));
@@ -671,7 +645,7 @@ export function buildSnapshotManifest(args) {
671
645
  * - distillOnlyRefs: only distill's passes (any signal, a positive or a note
672
646
  * included), on a distill candidate;
673
647
  * - noFeedbackPool: no recent feedback and no reflect window, left to the
674
- * fallback lanes, which only score them;
648
+ * proactive-maintenance lane;
675
649
  * - fullySkippedCount: feedback on record but nothing new, or a live window.
676
650
  * An explicit `--scope <ref>` bypasses every gate.
677
651
  */
@@ -722,12 +696,12 @@ export function partitionBySignalDelta(args) {
722
696
  return out;
723
697
  }
724
698
  /**
725
- * Pick the loop's refs: signal delta, the fallback lanes (unless
726
- * `--require-feedback-signal`; they score, never plan), lane attribution,
727
- * salience, the no-op-dampened ranking, the disk check and the limit.
699
+ * Pick the loop's refs: signal delta, the proactive-maintenance lane (unless
700
+ * `--require-feedback-signal`), lane attribution, salience, the no-op-dampened
701
+ * ranking, the disk check and the limit.
728
702
  */
729
703
  async function selectLoopCandidates(args, postCleanupRefs, validationFailureRefs, actions, persist) {
730
- const { scope, options, primaryStashDir, eventsCtx, improveProfile } = args;
704
+ const { scope, options, primaryStashDir, eventsCtx } = args;
731
705
  const snapshot = buildSnapshotManifest({
732
706
  postCleanupRefs,
733
707
  validationFailureRefs,
@@ -739,9 +713,8 @@ async function selectLoopCandidates(args, postCleanupRefs, validationFailureRefs
739
713
  const processableRefs = [...partition.eligibleRefs, ...partition.distillOnlyRefs];
740
714
  const signalFiltered = processableRefs.filter((c) => snapshot.feedback.get(c.ref)?.hasSignal === true);
741
715
  const signalBearingSet = new Set(signalFiltered.map((r) => r.ref));
742
- // The fallback lanes (proactive, high salience) have no usage evidence of
743
- // their own: they pick only what retrieval returned or new material improve
744
- // never processed (#986). Evaluated once per candidate.
716
+ // The proactive lane has no usage evidence of its own: it picks only what
717
+ // retrieval returned or new material improve never processed (#986). Evaluated once per candidate.
745
718
  const fallbackEligible = postCleanupRefs.filter((c) => !validationFailureRefs.has(c.ref));
746
719
  const allowFallbacks = options.requireFeedbackSignal !== true;
747
720
  const retrievalScope = scope.mode === "ref" || !allowFallbacks
@@ -753,22 +726,20 @@ async function selectLoopCandidates(args, postCleanupRefs, validationFailureRefs
753
726
  ...partition.noFeedbackPool,
754
727
  ]);
755
728
  const noFeedbackCandidates = noFeedbackPool.filter((r) => !unscoped.has(r.ref));
756
- // Only a ref no fallback lane may pick anymore is charged to the retrieval gate.
729
+ // Only a ref the proactive lane may not pick is charged to the retrieval gate.
757
730
  const outOfScope = new Set(noFeedbackPool.filter((r) => unscoped.has(r.ref)).map((r) => r.ref));
758
731
  const retrieval = fetchRetrievalSignals(options, signalFiltered, noFeedbackCandidates, eventsCtx, persist);
759
732
  const proactive = allowFallbacks
760
733
  ? selectProactiveMaintenanceLane(args, noFeedbackCandidates, snapshot, retrieval, persist)
761
734
  : { proactiveRefs: [] };
762
- const highSalienceRefs = allowFallbacks
763
- ? selectHighSalienceLane(options, improveProfile, eventsCtx, noFeedbackCandidates.filter((r) => !proactive.proactiveRefs.some((p) => p.ref === r.ref)), snapshot.lastReflectAttemptAt, persist)
764
- : [];
765
- // An explicit ref scope always acts on its ref; otherwise only feedback plans the loop. The fallback lanes'
766
- // picks are scored with it, never planned: a rewrite needs negative feedback.
767
- const signalAndRetrievalRefs = dedupeRefs([...signalFiltered, ...proactive.proactiveRefs, ...highSalienceRefs]);
768
- const mergedRefs = scope.mode === "ref" ? processableRefs : signalFiltered;
769
- const scoredRefs = scope.mode === "ref" ? processableRefs : signalAndRetrievalRefs;
770
- // Lane attribution: signal-delta, and an explicit ref scope over it.
735
+ // Planned: signal-delta refs plus the proactive lane's picks (whole-stash / type scope); an explicit ref scope
736
+ // acts on its own refs.
737
+ const mergedRefs = scope.mode === "ref" ? processableRefs : dedupeRefs([...signalFiltered, ...proactive.proactiveRefs]);
738
+ // Lane attribution, weakest first so the strongest wins: proactive < signal-delta, and an explicit ref scope
739
+ // over everything.
771
740
  const sourceByRef = new Map();
741
+ for (const r of proactive.proactiveRefs)
742
+ sourceByRef.set(r.ref, "proactive");
772
743
  for (const r of signalFiltered)
773
744
  sourceByRef.set(r.ref, "signal-delta");
774
745
  if (scope.mode === "ref")
@@ -776,7 +747,7 @@ async function selectLoopCandidates(args, postCleanupRefs, validationFailureRefs
776
747
  sourceByRef.set(r.ref, "scope");
777
748
  for (const r of mergedRefs)
778
749
  r.eligibilitySource = sourceByRef.get(r.ref) ?? "unknown";
779
- const salienceMap = scoreSalience(args, scoredRefs, snapshot.feedback, retrieval.retrievalCounts, persist);
750
+ const salienceMap = scoreSalience(args, mergedRefs, snapshot.feedback, retrieval.retrievalCounts, persist);
780
751
  // Rank by salience; a ref skipped as a no-op repeatedly sorts lower (its stored rank is untouched).
781
752
  const noOps = new Map();
782
753
  withRunState(eventsCtx, persist, (db) => {
@@ -795,8 +766,8 @@ async function selectLoopCandidates(args, postCleanupRefs, validationFailureRefs
795
766
  distillOnlyRefs: partition.distillOnlyRefs,
796
767
  limit: options.limit,
797
768
  });
798
- if (signalAndRetrievalRefs.length > 0) {
799
- info(`[improve] ${signalAndRetrievalRefs.length} refs with usage signals (${signalFiltered.length} feedback)`);
769
+ if (mergedRefs.length > 0) {
770
+ info(`[improve] ${mergedRefs.length} refs with usage signals (${signalFiltered.length} feedback)`);
800
771
  }
801
772
  if (validationFailureRefs.size > 0)
802
773
  info(`[improve] ${validationFailureRefs.size} with validation failures excluded`);
@@ -883,11 +854,11 @@ function fetchRetrievalSignals(options, signalFiltered, noFeedbackCandidates, ev
883
854
  return out;
884
855
  }
885
856
  /**
886
- * Proactive maintenance (default off, whole-stash/type runs): pick stable
887
- * assets due for a revisit. The picks are scored and never planned: improve
888
- * does not rewrite on a proactive cadence. The due gate doubles as the
889
- * rotation cooldown: a freshly reflected asset waits `dueDays` before it is
890
- * picked again.
857
+ * Proactive maintenance (default on, whole-stash/type runs): pick stable
858
+ * assets due for a revisit and plan them with the feedback-bearing refs. The
859
+ * cap against a proposal flood: `maxPerRun` limits the picks per run, the due
860
+ * gate admits only an asset not reflected or distilled for `dueDays` (so each
861
+ * comes up at most once per `dueDays`), and reflect's `limit` bounds the run.
891
862
  */
892
863
  function selectProactiveMaintenanceLane(args, candidates, snapshot, retrieval, persist) {
893
864
  if (args.scope.mode === "ref" || !args.resolvedPlan.processes.proactiveMaintenance.enabled) {
@@ -895,7 +866,7 @@ function selectProactiveMaintenanceLane(args, candidates, snapshot, retrieval, p
895
866
  }
896
867
  const pmCfg = args.improveProfile.processes?.proactiveMaintenance;
897
868
  const dueDays = pmCfg?.dueDays ?? DEFAULT_DUE_DAYS;
898
- const maxPerRun = pmCfg?.maxPerRun ?? pmCfg?.limit ?? DEFAULT_MAX_PER_RUN;
869
+ const maxPerRun = pmCfg?.maxPerRun ?? DEFAULT_MAX_PER_RUN;
899
870
  const selection = selectProactiveMaintenanceRefs({
900
871
  candidates,
901
872
  lastReflectTs: snapshot.lastReflectAttemptAt,
@@ -927,7 +898,7 @@ function selectProactiveMaintenanceLane(args, candidates, snapshot, retrieval, p
927
898
  proactiveRefs: selection.selected,
928
899
  proactiveMaintenanceSummary: { ...summary, selectedRefs },
929
900
  proactivePlan: {
930
- configured: pickDefined(pmCfg, ["dueDays", "maxPerRun", "limit"]),
901
+ configured: pickDefined(pmCfg, ["dueDays", "maxPerRun"]),
931
902
  effective: { dueDays, maxPerRun },
932
903
  candidatePool: candidates.length,
933
904
  ...summary,
@@ -935,41 +906,13 @@ function selectProactiveMaintenanceLane(args, candidates, snapshot, retrieval, p
935
906
  },
936
907
  };
937
908
  }
938
- /**
939
- * High salience: zero-feedback refs whose content-derived encoding score (not
940
- * a per-type stub) reaches `salienceThreshold` and that were never reflected,
941
- * top-N by score, capped at 10% of the effective limit. The picks are scored,
942
- * never planned.
943
- */
944
- function selectHighSalienceLane(options, improveProfile, eventsCtx, candidates, lastReflectAttemptAt, persist) {
945
- const threshold = (options.config ?? loadConfig()).improve?.salience?.salienceThreshold ?? 0.75;
946
- const effectiveLimit = options.limit ?? improveProfile?.processes?.reflect?.limit ?? improveProfile.limit ?? 10;
947
- const selected = withRunState(eventsCtx, persist, (db) => candidates
948
- .flatMap((r) => {
949
- const row = getAssetSalience(db, keyOf(r));
950
- return row &&
951
- isContentEncodingRow(row) &&
952
- row.encoding_salience >= threshold &&
953
- !lastReflectAttemptAt.has(r.ref)
954
- ? [{ ref: r, score: row.encoding_salience }]
955
- : [];
956
- })
957
- .sort((a, b) => b.score - a.score)
958
- .slice(0, Math.max(1, Math.floor(effectiveLimit * 0.1)))
959
- .map((q) => q.ref)) ?? [];
960
- if (selected.length > 0) {
961
- info(`[improve] high-salience lane admitted ${selected.length} content-scored ref(s) ` +
962
- `(threshold=${threshold}, requires content-derived encoding_source)`);
963
- }
964
- return selected;
965
- }
966
909
  /**
967
910
  * Score the merged refs: update `asset_outcome` (projected on a plan-only
968
911
  * run), compute each salience vector (keeping a stored content-derived
969
912
  * encoding score), then persist it.
970
913
  */
971
914
  function scoreSalience(args, mergedRefs, feedback, retrievalCounts, persist) {
972
- const { options, eventsCtx } = args;
915
+ const { eventsCtx } = args;
973
916
  const utilityMap = buildUtilityMap(mergedRefs, !persist);
974
917
  const lastUseMsByRef = withIndexDb(!persist, (db) => getLastUseMsByRef(db, mergedRefs)) ?? new Map();
975
918
  const outcomeSalience = updateOutcomeScores({
@@ -982,7 +925,6 @@ function scoreSalience(args, mergedRefs, feedback, retrievalCounts, persist) {
982
925
  eventsCtx,
983
926
  persist,
984
927
  });
985
- const outcomeWeightEnabled = (options.config ?? loadConfig()).improve?.salience?.outcomeWeightEnabled !== false;
986
928
  const storedEncoding = new Map();
987
929
  withRunState(eventsCtx, persist, (db) => {
988
930
  for (const r of mergedRefs) {
@@ -1005,7 +947,6 @@ function scoreSalience(args, mergedRefs, feedback, retrievalCounts, persist) {
1005
947
  outcomeSalience: outcomeSalience.get(r.ref),
1006
948
  sizeBytes: fileSize(r.filePath),
1007
949
  now,
1008
- outcomeWeightEnabled,
1009
950
  }));
1010
951
  }
1011
952
  if (persist) {
@@ -6,8 +6,8 @@ import { computeSalience } from "./salience.js";
6
6
  const DAY_MS = 86_400_000;
7
7
  /** An asset is due when last reflected/distilled more than this many days ago (or never). */
8
8
  export const DEFAULT_DUE_DAYS = 30;
9
- /** Default bound on how many assets the selector surfaces per run. */
10
- export const DEFAULT_MAX_PER_RUN = 25;
9
+ /** Fallback for `maxPerRun`; the same as the shipped `default` strategy. */
10
+ export const DEFAULT_MAX_PER_RUN = 15;
11
11
  /** Size floor for the cost term, so tiny files don't divide by ~0. */
12
12
  const SIZE_FLOOR_BYTES = 200;
13
13
  /**
@@ -19,8 +19,7 @@ import { parseFrontmatter } from "../../core/asset/frontmatter.js";
19
19
  /**
20
20
  * `noop` (identical up to trailing whitespace) and `cosmetic` (identical after
21
21
  * normalizing frontmatter as parsed YAML and prose as unwrapped text) never
22
- * become proposals. `low-value` (#639) is a small prose rewrite — few changed
23
- * words, nothing structural; the caller decides (off by default).
22
+ * become proposals.
24
23
  */
25
24
  export function classifyReflectChange(sourceContent, candidateContent) {
26
25
  if (normalizeTrailingWhitespace(sourceContent) === normalizeTrailingWhitespace(candidateContent))
@@ -32,13 +31,6 @@ export function classifyReflectChange(sourceContent, candidateContent) {
32
31
  catch {
33
32
  // unprovable → substantive
34
33
  }
35
- try {
36
- if (isLowValueChange(sourceContent, candidateContent))
37
- return "low-value";
38
- }
39
- catch {
40
- // unprovable → substantive
41
- }
42
34
  return "substantive";
43
35
  }
44
36
  /** Not TODO, TBD or FIXME: an asset may carry those on purpose, and the owner does not want them refused. */
@@ -136,7 +128,7 @@ function frontmatterCopiedIntoBody(source, candidate, keys) {
136
128
  if (keys.length === 0)
137
129
  return false;
138
130
  const keyLine = new RegExp(`^(?:${keys.map(escapeRegExp).join("|")}):(?:[ \\t].*)?$`);
139
- const keyLines = (text) => parseLowValueSections(text).proseLines.filter((line) => keyLine.test(line)).length;
131
+ const keyLines = (text) => parseSections(text).proseLines.filter((line) => keyLine.test(line)).length;
140
132
  if (keyLines(candidate) > keyLines(source))
141
133
  return true;
142
134
  const sourceBody = lettersAndDigits(splitFrontmatter(source).body);
@@ -166,44 +158,8 @@ export function splitFrontmatter(raw) {
166
158
  const m = raw.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/);
167
159
  return m ? { fmText: m[1] ?? "", body: m[2] ?? "" } : { fmText: null, body: raw };
168
160
  }
169
- /** At most this many changed words (and at least 2 — one word may be a flag flip) is low-value. */
170
- const LOW_VALUE_TOKEN_THRESHOLD = 4;
171
- /** A change to any of these is never low-value. */
172
- const NEGATION_WORDS = new Set(["never", "not", "no", "don't", "avoid", "cannot", "can't"]);
173
- /** Lines recording a decision or outcome are always significant; their words are not counted. */
174
- const DECISION_MARKER_RE = /\b(decision|outcome)\b/i;
175
- const STRUCTURAL_LINE_RE = /^\s*(#{1,6}\s|[-*+]\s|\d{1,9}[.)]\s|---+|===+|\|\s)/;
176
- function isLowValueChange(source, candidate) {
177
- const src = parseLowValueSections(source);
178
- const cnd = parseLowValueSections(candidate);
179
- // Code and frontmatter changes are always substantive.
180
- if (src.codeFences.join("\n") !== cnd.codeFences.join("\n") || src.frontmatter !== cnd.frontmatter)
181
- return false;
182
- if (Math.abs(src.proseLines.length - cnd.proseLines.length) > 2)
183
- return false;
184
- let changedTokens = 0;
185
- for (let i = 0; i < Math.max(src.proseLines.length, cnd.proseLines.length); i++) {
186
- const srcLine = src.proseLines[i] ?? "";
187
- const cndLine = cnd.proseLines[i] ?? "";
188
- if (srcLine === cndLine || DECISION_MARKER_RE.test(srcLine) || DECISION_MARKER_RE.test(cndLine))
189
- continue;
190
- if (STRUCTURAL_LINE_RE.test(cndLine) || STRUCTURAL_LINE_RE.test(srcLine))
191
- return false;
192
- const srcTokens = tokenize(srcLine);
193
- const cndTokens = tokenize(cndLine);
194
- const srcNeg = new Set(srcTokens.filter((t) => NEGATION_WORDS.has(t)));
195
- const cndNeg = new Set(cndTokens.filter((t) => NEGATION_WORDS.has(t)));
196
- if (srcNeg.size !== cndNeg.size || [...srcNeg].some((t) => !cndNeg.has(t)))
197
- return false;
198
- // max(added, removed) approximates substitutions: "is→runs" counts once.
199
- const srcSet = new Set(srcTokens);
200
- const cndSet = new Set(cndTokens);
201
- changedTokens += Math.max(cndTokens.filter((t) => !srcSet.has(t)).length, srcTokens.filter((t) => !cndSet.has(t)).length);
202
- }
203
- return changedTokens >= 2 && changedTokens < LOW_VALUE_TOKEN_THRESHOLD;
204
- }
205
161
  /** Frontmatter text, fenced code blocks, and prose lines (an unclosed fence counts as prose). */
206
- function parseLowValueSections(text) {
162
+ function parseSections(text) {
207
163
  const { fmText, body } = splitFrontmatter(normalizeTrailingWhitespace(text));
208
164
  const codeFences = [];
209
165
  const proseLines = [];
@@ -230,14 +186,6 @@ function parseLowValueSections(text) {
230
186
  proseLines.push(...fence.lines);
231
187
  return { frontmatter: fmText ?? "", codeFences, proseLines };
232
188
  }
233
- function tokenize(line) {
234
- return line
235
- .toLowerCase()
236
- .replace(/’/g, "'") // curly apostrophes still match "don't"
237
- .replace(/[^a-z0-9'-]/g, " ")
238
- .split(/\s+/)
239
- .filter((t) => t.length > 0);
240
- }
241
189
  /** CRLF → LF, no trailing spaces per line, no trailing newlines. */
242
190
  export function normalizeTrailingWhitespace(text) {
243
191
  return text
@@ -45,7 +45,6 @@ import { findAssetFilePath } from "./eligibility.js";
45
45
  import { resolveImproveExecution } from "./execution.js";
46
46
  import { recordLedgerAttempt } from "./ledger.js";
47
47
  import { classifyReflectChange, findReflectDefect, splitFrontmatter } from "./reflect-noise.js";
48
- import { loadRetrievalQueries, runRetrievalRegressionGate } from "./retrieval-gate.js";
49
48
  import { callStageOnce, errMessage, mintProposal, noticeSet, rejectedProposalContext, resolveQualityGateJudge, runReflectQualityJudge, } from "./stage.js";
50
49
  const MAX_FEEDBACK_LINES = 10;
51
50
  const MAX_GLOBAL_FEEDBACK_LINES = 20;
@@ -779,13 +778,27 @@ async function runReflectRefineIterations(args) {
779
778
  }
780
779
  return result;
781
780
  }
781
+ /**
782
+ * The judge's review band for a reflect revision: a non-pass whose mean is at or above this goes to a
783
+ * person (`judge-uncertain`); a lower one is refused. The judge's own review label starts at 2.5, but
784
+ * nothing labelled below 3.5 is worth a person's time. Labelled runs of the judge (akm-eval judge-gate,
785
+ * lab 27B Q2; ~/akm/eval/judge-gate/tuning), good / bad among non-passing verdicts:
786
+ * mean >= 3.5, frontmatter-only proposals Opus reviewed: 17 / 9 (shipped judge, 113 proposals),
787
+ * 15 / 0, 18 / 9 and 15 / 5 (earlier rubric, three runs);
788
+ * mean >= 3.5, public corpus of body rewrites: 12 / 35;
789
+ * mean < 3.5, 396 labelled body rewrites: 6 / 285 (Q4 judge 5 / 177, Q2 judge 1 / 108);
790
+ * public corpus 3 / 37; frontmatter-only proposals: 1 / 2 (shipped judge), 5 / 1 (earlier runs).
791
+ * Mean 4.0 with one criterion at 2 was good 14 / 0; mean 3.67 was 3 / 8. A rule on the lowest
792
+ * criterion did not help: a criterion at 3 or more is rare in a non-pass, and a 2 is the usual
793
+ * shape of a good one.
794
+ */
795
+ const REFLECT_REVIEW_MIN_SCORE = 3.5;
782
796
  const NOISE_SUBREASONS = {
783
797
  noop: "reflect_skipped_noop",
784
798
  cosmetic: "reflect_skipped_cosmetic",
785
- "low-value": "reflect_skipped_low_value",
786
799
  };
787
800
  /**
788
- * Apply the patch, drop a no-op/cosmetic (and optionally low-value) change,
801
+ * Apply the patch, drop a no-op/cosmetic change,
789
802
  * judge the exact content that would be persisted, then mint. A revision with a
790
803
  * deterministic defect is refused before the judge runs, whether or not the
791
804
  * gate is on.
@@ -798,15 +811,11 @@ async function finalizeReflectProposal(args) {
798
811
  // A patch that changes nothing leaves the asset as it is: an empty diff.
799
812
  const content = patched?.content ?? assetContent;
800
813
  const changeKind = classifyReflectChange(assetContent, content);
801
- if (changeKind === "noop" ||
802
- changeKind === "cosmetic" ||
803
- (changeKind === "low-value" && options.lowValueFilter === true)) {
814
+ if (changeKind === "noop" || changeKind === "cosmetic") {
804
815
  run.emitFailed("no_change", NOISE_SUBREASONS[changeKind], options.ref, { changeKind, ...telemetry });
805
816
  const what = changeKind === "noop"
806
817
  ? "identical to the current asset (empty diff)"
807
- : changeKind === "low-value"
808
- ? "a low-value prose micro-rewrite (few changed tokens, no structural changes)"
809
- : "a cosmetic-only reformat of the current asset (whitespace/fence/YAML-folding changes)";
818
+ : "a cosmetic-only reformat of the current asset (whitespace/fence/YAML-folding changes)";
810
819
  return reflectFailure(run, result, "no_change", `Reflect skipped: proposed content for ${payload.ref} is ${what}; no proposal created.`, false);
811
820
  }
812
821
  /** A judge refused the revision: record it for the ledger's rejection window and stop. */
@@ -833,6 +842,7 @@ async function finalizeReflectProposal(args) {
833
842
  return refuse(defect, { reflectDefect: defect }, `Reflect proposal refused before the judge: ${defect}`);
834
843
  let verdict;
835
844
  let judgeFailed = false;
845
+ let judgeUncertain = false;
836
846
  if (judge.enabled) {
837
847
  verdict = await runReflectQualityJudge(run.config, content, assetContent, feedback, options.chat, {
838
848
  runnerSelectionFrozen: true,
@@ -844,7 +854,9 @@ async function finalizeReflectProposal(args) {
844
854
  });
845
855
  // A judge that timed out, errored or replied unparseably gave no verdict: a person reviews the revision.
846
856
  judgeFailed = verdict.reviewNeeded === true && verdict.score === -1;
847
- if (!verdict.pass && !judgeFailed) {
857
+ // A real score in the band is uncertain, not bad: a person decides, and no window is recorded.
858
+ judgeUncertain = verdict.reviewNeeded === true && verdict.score >= REFLECT_REVIEW_MIN_SCORE;
859
+ if (!verdict.pass && !judgeFailed && !judgeUncertain) {
848
860
  return refuse(verdict.reason, {
849
861
  qualityScore: verdict.score,
850
862
  qualityReason: verdict.reason,
@@ -852,32 +864,12 @@ async function finalizeReflectProposal(args) {
852
864
  }, `Reflect proposal quality gate rejected: score=${verdict.score}, reason="${verdict.reason}"`);
853
865
  }
854
866
  }
855
- // #722: a revision of an existing asset must not grade lower on its own retrieval queries.
856
- if (verdict?.pass && judge.runner) {
857
- const retrieval = await runRetrievalRegressionGate({
858
- ref: payload.ref,
859
- before: assetContent,
860
- after: content,
861
- queries: loadRetrievalQueries({ proposalsCtx: options.ctx, eventsCtx: options.eventsCtx }, payload.ref),
862
- runner: judge.runner,
863
- ...(options.chat ? { chat: options.chat } : {}),
864
- ...(Object.hasOwn(options, "timeoutMs") ? { timeoutMs: options.timeoutMs } : {}),
865
- ...(options.signal ? { signal: options.signal } : {}),
866
- onNotices: run.notices.add,
867
- });
868
- if (!retrieval.pass) {
869
- return refuse(retrieval.reason, {
870
- retrievalRegression: true,
871
- retrievalQueries: retrieval.queries,
872
- ...(retrieval.oldMean !== undefined ? { retrievalGradeBefore: retrieval.oldMean } : {}),
873
- ...(retrieval.newMean !== undefined ? { retrievalGradeAfter: retrieval.newMean } : {}),
874
- }, `Reflect proposal refused: ${retrieval.reason}`);
875
- }
876
- }
877
867
  const reviewReasons = [
878
868
  ...(judge.skippedNoJudge ? ["no-judge-configured"] : []),
879
869
  ...(judgeFailed ? ["judge-error"] : []),
870
+ ...(judgeUncertain ? ["judge-uncertain"] : []),
880
871
  ];
872
+ const gateReview = judgeFailed || judgeUncertain;
881
873
  const proposal = mintProposal(run.stash, options.ctx, {
882
874
  ref: payload.ref,
883
875
  ...(options.target ? { target: options.target } : {}),
@@ -892,7 +884,9 @@ async function finalizeReflectProposal(args) {
892
884
  review: {
893
885
  reason: reviewReasons.join("+"),
894
886
  // The quality gate's hand-off to a person, as distill's: the triage drain leaves it alone.
895
- gate: judgeFailed ? "quality-gate" : "reflect",
887
+ gate: gateReview ? "quality-gate" : "reflect",
888
+ ...(gateReview && verdict?.criteria ? { scores: verdict.criteria } : {}),
889
+ ...(gateReview && verdict?.reason ? { judgeReason: verdict.reason } : {}),
896
890
  },
897
891
  }
898
892
  : { judged: verdict });
@@ -904,7 +898,8 @@ async function finalizeReflectProposal(args) {
904
898
  source: "reflect",
905
899
  engine: run.engineName,
906
900
  ...(judge.skippedNoJudge ? { qualityGateSkippedNoJudge: true } : {}),
907
- ...(judgeFailed ? { qualityReason: verdict?.reason } : {}),
901
+ ...(judgeFailed || judgeUncertain ? { qualityReason: verdict?.reason } : {}),
902
+ ...(judgeUncertain ? { qualityScore: verdict?.score } : {}),
908
903
  ...telemetry,
909
904
  },
910
905
  }, options.eventsCtx);
@@ -0,0 +1,37 @@
1
+ // This Source Code Form is subject to the terms of the Mozilla Public
2
+ // License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ // file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
+ /**
5
+ * An asset's own retrieval queries from the usage log, cleaned for replay.
6
+ * The consolidate continuity check replays them against a retiring asset's
7
+ * successor.
8
+ */
9
+ import { nonTaskInput } from "../../core/non-task-input.js";
10
+ import { listRetrievalQueries } from "../../indexer/usage/usage-events.js";
11
+ import { readLedgerDb, stripBundle } from "./ledger.js";
12
+ /** Queries kept per asset. */
13
+ const MAX_QUERIES = 5;
14
+ /** The retrieval suite treats a longer input as a paste, not a query. */
15
+ const MAX_QUERY_CHARS = 2000;
16
+ /** Up to five distinct task queries, in the given order, whitespace collapsed. */
17
+ export function usableRetrievalQueries(raw) {
18
+ const out = [];
19
+ for (const text of raw) {
20
+ const query = text.replace(/\s+/g, " ").trim();
21
+ if (!query || query.length > MAX_QUERY_CHARS || nonTaskInput(query) || out.includes(query))
22
+ continue;
23
+ out.push(query);
24
+ if (out.length === MAX_QUERIES)
25
+ break;
26
+ }
27
+ return out;
28
+ }
29
+ /** The asset's own retrieval queries from the usage log (none when state.db cannot be read). */
30
+ export function loadRetrievalQueries(access, ref) {
31
+ try {
32
+ return usableRetrievalQueries(readLedgerDb(access, (db) => listRetrievalQueries(db, stripBundle(ref))) ?? []);
33
+ }
34
+ catch {
35
+ return [];
36
+ }
37
+ }