akm-cli 0.9.0-beta.53 → 0.9.0-beta.55

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 (123) hide show
  1. package/dist/cli/clack.js +56 -0
  2. package/dist/cli/confirm.js +1 -1
  3. package/dist/cli.js +5 -3
  4. package/dist/commands/agent/contribute-cli.js +2 -3
  5. package/dist/commands/env/env-cli.js +187 -202
  6. package/dist/commands/env/secret-cli.js +109 -121
  7. package/dist/commands/feedback-cli.js +152 -155
  8. package/dist/commands/health/advisories.js +151 -0
  9. package/dist/commands/health/html-report.js +33 -10
  10. package/dist/commands/health/improve-metrics.js +754 -0
  11. package/dist/commands/health/llm-usage.js +65 -0
  12. package/dist/commands/health/md-report.js +103 -0
  13. package/dist/commands/health/metrics.js +278 -0
  14. package/dist/commands/health/task-runs.js +135 -0
  15. package/dist/commands/health/types.js +18 -0
  16. package/dist/commands/health/windows.js +196 -0
  17. package/dist/commands/health.js +15 -1492
  18. package/dist/commands/improve/anti-collapse.js +170 -0
  19. package/dist/commands/improve/collapse-detector.js +3 -2
  20. package/dist/commands/improve/consolidate.js +636 -633
  21. package/dist/commands/improve/dedup.js +1 -1
  22. package/dist/commands/improve/distill/content-repair.js +202 -0
  23. package/dist/commands/improve/distill/promote-memory.js +228 -0
  24. package/dist/commands/improve/distill/quality-gate.js +233 -0
  25. package/dist/commands/improve/distill-guards.js +127 -0
  26. package/dist/commands/improve/distill.js +49 -575
  27. package/dist/commands/improve/extract-cli.js +74 -76
  28. package/dist/commands/improve/extract.js +6 -4
  29. package/dist/commands/improve/hot-probation.js +45 -0
  30. package/dist/commands/improve/improve-auto-accept.js +3 -2
  31. package/dist/commands/improve/improve-cli.js +14 -13
  32. package/dist/commands/improve/improve-result-file.js +2 -1
  33. package/dist/commands/improve/improve.js +6 -5
  34. package/dist/commands/improve/loop-stages.js +19 -21
  35. package/dist/commands/improve/outcome-loop.js +18 -16
  36. package/dist/commands/improve/preparation.js +23 -5
  37. package/dist/commands/improve/procedural.js +10 -31
  38. package/dist/commands/improve/recombine.js +19 -43
  39. package/dist/commands/improve/reflect.js +1 -1
  40. package/dist/commands/improve/schema-similarity-gate.js +168 -0
  41. package/dist/commands/improve/shared.js +48 -0
  42. package/dist/commands/observability-cli.js +4 -4
  43. package/dist/commands/proposal/drain-policies.js +2 -2
  44. package/dist/commands/proposal/drain.js +1 -1
  45. package/dist/commands/proposal/legacy-import.js +115 -0
  46. package/dist/commands/proposal/proposal-cli.js +3 -3
  47. package/dist/commands/proposal/proposal.js +2 -1
  48. package/dist/commands/proposal/propose.js +1 -1
  49. package/dist/commands/proposal/repository.js +829 -0
  50. package/dist/commands/proposal/validators/proposals.js +5 -920
  51. package/dist/commands/read/curate.js +4 -4
  52. package/dist/commands/read/remember-cli.js +132 -137
  53. package/dist/commands/read/search-cli.js +7 -5
  54. package/dist/commands/read/search.js +7 -3
  55. package/dist/commands/read/show.js +3 -5
  56. package/dist/commands/registry-cli.js +76 -87
  57. package/dist/commands/sources/add-cli.js +91 -95
  58. package/dist/commands/sources/history.js +1 -1
  59. package/dist/commands/sources/init.js +12 -0
  60. package/dist/commands/sources/schema-repair.js +1 -1
  61. package/dist/commands/sources/sources-cli.js +3 -3
  62. package/dist/commands/sources/stash-cli.js +2 -2
  63. package/dist/commands/tasks/default-tasks.js +12 -0
  64. package/dist/commands/tasks/tasks-cli.js +1 -2
  65. package/dist/commands/wiki-cli.js +2 -3
  66. package/dist/core/common.js +3 -3
  67. package/dist/core/config/config-schema.js +6 -0
  68. package/dist/core/config/config.js +12 -0
  69. package/dist/core/deep-merge.js +38 -0
  70. package/dist/core/events.js +2 -1
  71. package/dist/core/logs-db.js +8 -13
  72. package/dist/core/paths.js +14 -14
  73. package/dist/core/state-db.js +13 -1140
  74. package/dist/core/warn.js +21 -0
  75. package/dist/indexer/db/db.js +72 -709
  76. package/dist/indexer/db/entry-mapper.js +41 -0
  77. package/dist/indexer/db/schema.js +516 -0
  78. package/dist/indexer/ensure-index.js +3 -2
  79. package/dist/indexer/feedback/utility-policy.js +85 -0
  80. package/dist/indexer/graph/graph-extraction.js +2 -1
  81. package/dist/indexer/index-writer-lock.js +18 -0
  82. package/dist/indexer/indexer.js +94 -27
  83. package/dist/indexer/read-preflight.js +23 -0
  84. package/dist/indexer/search/fts-query.js +51 -0
  85. package/dist/indexer/walk/walker.js +21 -13
  86. package/dist/integrations/agent/detect.js +9 -0
  87. package/dist/integrations/agent/index.js +1 -1
  88. package/dist/integrations/agent/spawn.js +15 -66
  89. package/dist/llm/client.js +12 -0
  90. package/dist/llm/embedder.js +26 -2
  91. package/dist/llm/embedders/local.js +7 -1
  92. package/dist/output/text/helpers.js +13 -0
  93. package/dist/scripts/migrate-storage.js +6903 -7424
  94. package/dist/scripts/migrations/import-fs-improve-runs-to-db.js +49 -44
  95. package/dist/setup/detect.js +9 -0
  96. package/dist/setup/legacy-config.js +106 -0
  97. package/dist/setup/prompt.js +57 -0
  98. package/dist/setup/providers.js +14 -0
  99. package/dist/setup/registry-stash-loader.js +12 -0
  100. package/dist/setup/semantic-assets.js +124 -0
  101. package/dist/setup/setup.js +25 -1608
  102. package/dist/setup/steps/connection.js +734 -0
  103. package/dist/setup/steps/output.js +31 -0
  104. package/dist/setup/steps/platforms.js +124 -0
  105. package/dist/setup/steps/semantic.js +27 -0
  106. package/dist/setup/steps/sources.js +222 -0
  107. package/dist/setup/steps/stashdir.js +42 -0
  108. package/dist/setup/steps/tasks.js +152 -0
  109. package/dist/storage/repositories/canaries-repository.js +107 -0
  110. package/dist/storage/repositories/consolidation-repository.js +38 -0
  111. package/dist/storage/repositories/embeddings-repository.js +72 -0
  112. package/dist/storage/repositories/events-repository.js +187 -0
  113. package/dist/storage/repositories/extract-sessions-repository.js +96 -0
  114. package/dist/storage/repositories/improve-runs-repository.js +130 -0
  115. package/dist/storage/repositories/index-db.js +4 -7
  116. package/dist/storage/repositories/proposals-repository.js +220 -0
  117. package/dist/storage/repositories/recombine-repository.js +213 -0
  118. package/dist/storage/repositories/task-history-repository.js +93 -0
  119. package/dist/storage/sqlite-pragmas.js +3 -3
  120. package/dist/tasks/backends/index.js +9 -0
  121. package/dist/tasks/runner.js +11 -1
  122. package/package.json +2 -2
  123. package/dist/commands/improve/homeostatic.js +0 -497
@@ -0,0 +1,127 @@
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
+ * WS-3b distill-stage guards.
6
+ *
7
+ * **CLS interleaving (step 9)**
8
+ * distill/memoryInference prompts include embedding-retrieved adjacent
9
+ * lessons/knowledge so the pipeline doesn't overwrite prior generalizations.
10
+ *
11
+ * **Distill→source fidelity (step 10)**
12
+ * After a distill proposal, check it against cited source memories; a
13
+ * contradiction flag routes to human review.
14
+ *
15
+ * @module distill-guards
16
+ */
17
+ // ── CLS adjacent lesson context (step 9) ─────────────────────────────────────
18
+ /** Default number of adjacent lessons/knowledge for CLS interleaving. */
19
+ export const DEFAULT_CLS_ADJACENT_COUNT = 3;
20
+ /**
21
+ * Build a CLS (Complementary Learning System) context snippet for injection
22
+ * into distill/memoryInference prompts.
23
+ *
24
+ * Given a list of embedding-retrieved adjacent lessons/knowledge, formats them
25
+ * as a markdown section to append to the prompt so the LLM avoids overwriting
26
+ * prior generalizations.
27
+ *
28
+ * Returns an empty string when CLS is disabled or no adjacent items are found.
29
+ *
30
+ * @param adjacentItems - Top-N adjacent lessons/knowledge retrieved by embedding.
31
+ * @param config - CLS config.
32
+ */
33
+ export function buildClsContext(adjacentItems, config) {
34
+ if (!config.enabled || adjacentItems.length === 0)
35
+ return "";
36
+ const lines = [
37
+ "",
38
+ "## Existing adjacent lessons / knowledge (CLS context)",
39
+ "The following are semantically related entries already in the stash.",
40
+ "Your proposal MUST NOT contradict or silently overwrite these — if you",
41
+ "disagree with one, flag it as contradicted (do not ignore it).",
42
+ "",
43
+ ];
44
+ for (const item of adjacentItems) {
45
+ lines.push(`### ${item.ref}`);
46
+ // Truncate to 400 chars to keep the prompt size reasonable.
47
+ lines.push(item.content.trim().slice(0, 400));
48
+ lines.push("");
49
+ }
50
+ return lines.join("\n");
51
+ }
52
+ /**
53
+ * Check a distill proposal against its cited source memories for contradictions.
54
+ *
55
+ * Uses a simple heuristic: looks for explicit negation of key claims in the
56
+ * proposal body that appear in the source bodies. A full LLM-based
57
+ * contradiction check is expensive (one LLM call per proposal); this cheap
58
+ * heuristic catches the most obvious cases and flags them for human review.
59
+ *
60
+ * When `fidelityCheck.enabled` is false, returns `{ contradictionDetected: false }`
61
+ * immediately (no work done).
62
+ *
63
+ * @param proposalBody - The stripped body of the distill proposal.
64
+ * @param sourceBodies - The stripped bodies of the cited source memories.
65
+ * @param config - Fidelity check config.
66
+ */
67
+ export function checkDistillFidelity(proposalBody, sourceBodies, config) {
68
+ if (!config.enabled || sourceBodies.length === 0) {
69
+ return { contradictionDetected: false };
70
+ }
71
+ // Heuristic: detect explicit negation of "never" / "always" / "must" claims.
72
+ // A proposal that says "always X" while the source says "never X" (or vice
73
+ // versa) is a clear contradiction worth flagging.
74
+ //
75
+ // This is intentionally conservative: it only flags when both the proposal
76
+ // AND the source contain the opposing polarity of the same key term. False
77
+ // negatives (missed contradictions) are preferred over false positives
78
+ // (blocking valid proposals) since the consequence of a false positive is
79
+ // a human review request, while the cost of a false negative is a slightly
80
+ // degraded stash.
81
+ const proposalLow = proposalBody.toLowerCase();
82
+ // Extract "always/never/must/must not" claims from the proposal.
83
+ const strongClaims = extractStrongClaims(proposalLow);
84
+ if (strongClaims.length === 0)
85
+ return { contradictionDetected: false };
86
+ for (const sourceBody of sourceBodies) {
87
+ const sourceLow = sourceBody.toLowerCase();
88
+ for (const { polarity, term } of strongClaims) {
89
+ const oppositePolarity = polarity === "positive" ? "negative" : "positive";
90
+ const sourceHasOpposite = hasStrongClaim(sourceLow, term, oppositePolarity);
91
+ if (sourceHasOpposite) {
92
+ return {
93
+ contradictionDetected: true,
94
+ reason: `Proposal makes a ${polarity} strong claim about "${term}" that conflicts with an opposing claim in a cited source. Route to human review.`,
95
+ };
96
+ }
97
+ }
98
+ }
99
+ // Also flag proposals whose source_refs are empty (broken provenance).
100
+ // This is a degradation signal, not a contradiction, but worth surfacing.
101
+ return { contradictionDetected: false };
102
+ }
103
+ function extractStrongClaims(text) {
104
+ const claims = [];
105
+ // Match "always <term>", "never <term>", "must <term>", "must not <term>".
106
+ const patterns = [
107
+ { polarity: "positive", re: /\b(?:always|must)\s+(\w+)/g },
108
+ { polarity: "negative", re: /\b(?:never|must\s+not|should\s+not)\s+(\w+)/g },
109
+ ];
110
+ for (const { polarity, re } of patterns) {
111
+ re.lastIndex = 0;
112
+ let m = re.exec(text);
113
+ while (m !== null) {
114
+ const term = m[1];
115
+ if (term && term.length > 2)
116
+ claims.push({ polarity, term });
117
+ m = re.exec(text);
118
+ }
119
+ }
120
+ return claims;
121
+ }
122
+ function hasStrongClaim(text, term, polarity) {
123
+ if (polarity === "positive") {
124
+ return /\b(?:always|must)\s/.test(text) && text.includes(term);
125
+ }
126
+ return /\b(?:never|must\s+not|should\s+not)\s/.test(text) && text.includes(term);
127
+ }