akm-cli 0.8.0-rc.6 → 0.8.0-rc.7

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 (104) hide show
  1. package/dist/cli/shared.js +114 -0
  2. package/dist/cli.js +119 -1230
  3. package/dist/commands/add-cli.js +273 -0
  4. package/dist/commands/consolidate.js +498 -78
  5. package/dist/commands/distill.js +94 -11
  6. package/dist/commands/extract-cli.js +127 -0
  7. package/dist/commands/extract-prompt.js +204 -0
  8. package/dist/commands/extract.js +477 -0
  9. package/dist/commands/feedback-cli.js +324 -0
  10. package/dist/commands/health.js +954 -44
  11. package/dist/commands/help/help-improve.md +4 -12
  12. package/dist/commands/improve-auto-accept.js +97 -0
  13. package/dist/commands/improve-cli.js +217 -0
  14. package/dist/commands/improve-profiles.js +25 -5
  15. package/dist/commands/improve-result-file.js +64 -0
  16. package/dist/commands/improve.js +452 -262
  17. package/dist/commands/lint/index.js +10 -1
  18. package/dist/commands/reflect.js +33 -61
  19. package/dist/commands/registry-cli.js +141 -0
  20. package/dist/commands/remember-cli.js +257 -0
  21. package/dist/commands/tasks.js +3 -4
  22. package/dist/core/common.js +23 -0
  23. package/dist/core/config-migration.js +12 -15
  24. package/dist/core/config-schema.js +32 -4
  25. package/dist/core/config.js +52 -9
  26. package/dist/core/frontmatter.js +72 -2
  27. package/dist/core/proposal-quality-validators.js +22 -6
  28. package/dist/core/proposals.js +2 -0
  29. package/dist/core/state-db.js +143 -2
  30. package/dist/core/tty.js +59 -0
  31. package/dist/indexer/db-search.js +11 -1
  32. package/dist/indexer/db.js +25 -0
  33. package/dist/indexer/indexer.js +17 -10
  34. package/dist/indexer/llm-cache.js +7 -2
  35. package/dist/indexer/memory-inference.js +58 -5
  36. package/dist/indexer/semantic-status.js +1 -1
  37. package/dist/integrations/agent/index.js +1 -1
  38. package/dist/integrations/agent/prompts.js +64 -7
  39. package/dist/integrations/session-logs/index.js +1 -0
  40. package/dist/integrations/session-logs/inline-refs.js +35 -0
  41. package/dist/integrations/session-logs/pre-filter.js +152 -0
  42. package/dist/integrations/session-logs/providers/claude-code.js +223 -0
  43. package/dist/integrations/session-logs/providers/opencode.js +228 -25
  44. package/dist/llm/embedder.js +17 -10
  45. package/dist/llm/embedders/local.js +39 -1
  46. package/dist/llm/feature-gate.js +9 -3
  47. package/dist/llm/index-passes.js +39 -10
  48. package/dist/llm/memory-infer.js +25 -0
  49. package/dist/llm/prompts/extract-session.md +80 -0
  50. package/dist/output/context.js +2 -2
  51. package/dist/output/shapes/distill.js +10 -0
  52. package/dist/output/shapes/events.js +11 -0
  53. package/dist/output/shapes/helpers.js +423 -0
  54. package/dist/output/shapes/history.js +7 -0
  55. package/dist/output/shapes/passthrough.js +98 -0
  56. package/dist/output/shapes/proposal-accept.js +7 -0
  57. package/dist/output/shapes/proposal-diff.js +7 -0
  58. package/dist/output/shapes/proposal-list.js +7 -0
  59. package/dist/output/shapes/proposal-producer.js +11 -0
  60. package/dist/output/shapes/proposal-reject.js +7 -0
  61. package/dist/output/shapes/proposal-show.js +7 -0
  62. package/dist/output/shapes/registry-search.js +6 -0
  63. package/dist/output/shapes/registry.js +30 -0
  64. package/dist/output/shapes/search.js +6 -0
  65. package/dist/output/shapes/show.js +6 -0
  66. package/dist/output/shapes/vault-list.js +19 -0
  67. package/dist/output/shapes.js +32 -567
  68. package/dist/output/text/add.js +6 -0
  69. package/dist/output/text/clone.js +6 -0
  70. package/dist/output/text/config.js +6 -0
  71. package/dist/output/text/curate.js +6 -0
  72. package/dist/output/text/distill.js +7 -0
  73. package/dist/output/text/enable-disable.js +7 -0
  74. package/dist/output/text/events.js +10 -0
  75. package/dist/output/text/feedback.js +6 -0
  76. package/dist/output/text/helpers.js +1006 -0
  77. package/dist/output/text/history.js +7 -0
  78. package/dist/output/text/import.js +6 -0
  79. package/dist/output/text/index.js +6 -0
  80. package/dist/output/text/info.js +6 -0
  81. package/dist/output/text/init.js +6 -0
  82. package/dist/output/text/list.js +6 -0
  83. package/dist/output/text/proposal-producer.js +8 -0
  84. package/dist/output/text/proposal.js +11 -0
  85. package/dist/output/text/registry-commands.js +11 -0
  86. package/dist/output/text/registry.js +30 -0
  87. package/dist/output/text/remember.js +6 -0
  88. package/dist/output/text/remove.js +6 -0
  89. package/dist/output/text/save.js +6 -0
  90. package/dist/output/text/search.js +6 -0
  91. package/dist/output/text/show.js +6 -0
  92. package/dist/output/text/update.js +6 -0
  93. package/dist/output/text/upgrade.js +6 -0
  94. package/dist/output/text/vault.js +10 -0
  95. package/dist/output/text/wiki.js +15 -0
  96. package/dist/output/text/workflow.js +14 -0
  97. package/dist/output/text.js +41 -1377
  98. package/dist/scripts/migrate-storage.js +259 -50
  99. package/dist/scripts/migrations/import-fs-improve-runs-to-db.js +84 -2
  100. package/dist/sources/providers/git.js +101 -5
  101. package/dist/tasks/schedule.js +17 -1
  102. package/dist/workflows/runs.js +15 -1
  103. package/docs/README.md +1 -1
  104. package/package.json +9 -4
@@ -0,0 +1,114 @@
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
+ * Shared CLI utilities extracted from `src/cli.ts` so that individual
6
+ * command modules can import them without a circular dependency.
7
+ *
8
+ * Exported: output, runWithJsonErrors, parseAllFlagValues, emitJsonError
9
+ */
10
+ import { stringify as yamlStringify } from "yaml";
11
+ import { ConfigError, NotFoundError, UsageError } from "../core/errors";
12
+ import { getOutputMode } from "../output/context";
13
+ import { shapeForCommand } from "../output/shapes";
14
+ import { formatPlain, outputJsonl } from "../output/text";
15
+ // ── Exit codes ───────────────────────────────────────────────────────────────
16
+ const EXIT_GENERAL = 1;
17
+ const EXIT_USAGE = 2;
18
+ const EXIT_CONFIG = 78;
19
+ // ── Helpers ──────────────────────────────────────────────────────────────────
20
+ function classifyExitCode(error) {
21
+ if (error instanceof UsageError)
22
+ return EXIT_USAGE;
23
+ if (error instanceof ConfigError)
24
+ return EXIT_CONFIG;
25
+ if (error instanceof NotFoundError)
26
+ return EXIT_GENERAL;
27
+ return EXIT_GENERAL;
28
+ }
29
+ function extractHint(error) {
30
+ if (error instanceof Error && "hint" in error && typeof error.hint === "function") {
31
+ return error.hint();
32
+ }
33
+ return undefined;
34
+ }
35
+ /**
36
+ * Serialize an error to the standard JSON envelope and exit.
37
+ * Used in both the startup try/catch and `runWithJsonErrors`.
38
+ */
39
+ export function emitJsonError(error) {
40
+ const message = error instanceof Error ? error.message : String(error);
41
+ const hint = extractHint(error);
42
+ const exitCode = classifyExitCode(error);
43
+ const code = error instanceof UsageError || error instanceof ConfigError || error instanceof NotFoundError
44
+ ? error.code
45
+ : undefined;
46
+ console.error(JSON.stringify({ ok: false, error: message, ...(code ? { code } : {}), hint }, null, 2));
47
+ process.exit(exitCode);
48
+ }
49
+ /**
50
+ * Run an async function and route any thrown error through the standard JSON
51
+ * error envelope so users never see a raw stack trace.
52
+ */
53
+ export async function runWithJsonErrors(fn) {
54
+ try {
55
+ await fn();
56
+ }
57
+ catch (error) {
58
+ emitJsonError(error);
59
+ }
60
+ }
61
+ /**
62
+ * Render a command result according to the active output mode (json/jsonl/yaml/text).
63
+ */
64
+ export function output(command, result) {
65
+ const mode = getOutputMode();
66
+ const shaped = shapeForCommand(command, result, mode.detail, mode.forAgent);
67
+ if (mode.format === "jsonl") {
68
+ outputJsonl(command, shaped);
69
+ return;
70
+ }
71
+ switch (mode.format) {
72
+ case "json":
73
+ console.log(JSON.stringify(shaped, null, 2));
74
+ return;
75
+ case "yaml":
76
+ console.log(yamlStringify(shaped));
77
+ return;
78
+ case "text": {
79
+ const plain = formatPlain(command, shaped, mode.detail);
80
+ console.log(plain ?? JSON.stringify(shaped, null, 2));
81
+ return;
82
+ }
83
+ case "md":
84
+ // `--format md` is currently only consumed by `akm health` for the
85
+ // per-run / window-compare table renderings. Commands that don't
86
+ // implement an md renderer fall back to the JSON envelope so
87
+ // pipelines never get an empty stdout.
88
+ console.log(JSON.stringify(shaped, null, 2));
89
+ return;
90
+ }
91
+ }
92
+ /**
93
+ * Collect all occurrences of a repeatable flag from process.argv.
94
+ * Citty's StringArgDef only exposes the last value when a flag is repeated,
95
+ * so for repeatable CLI args (like `--tag foo --tag bar`) we read argv directly.
96
+ * Supports both `--flag value` and `--flag=value` forms.
97
+ */
98
+ export function parseAllFlagValues(flag) {
99
+ const values = [];
100
+ for (let i = 0; i < process.argv.length; i++) {
101
+ const arg = process.argv[i];
102
+ if (arg === flag && i + 1 < process.argv.length) {
103
+ values.push(process.argv[i + 1]);
104
+ // BUG-M4: skip the value index so `--tag --tag` (literal `--tag`
105
+ // value) does not double-count the second `--tag` as a separate
106
+ // flag occurrence.
107
+ i++;
108
+ }
109
+ else if (arg.startsWith(`${flag}=`)) {
110
+ values.push(arg.slice(flag.length + 1));
111
+ }
112
+ }
113
+ return values;
114
+ }