akm-cli 0.9.0-beta.5 → 0.9.0-beta.51

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 (221) hide show
  1. package/CHANGELOG.md +711 -0
  2. package/README.md +12 -4
  3. package/dist/akm +38 -0
  4. package/dist/akm-migrate-storage +38 -0
  5. package/dist/assets/profiles/default.json +9 -4
  6. package/dist/assets/profiles/frequent.json +1 -1
  7. package/dist/assets/profiles/memory-focus.json +1 -1
  8. package/dist/assets/profiles/quick.json +1 -1
  9. package/dist/assets/profiles/synthesize.json +15 -0
  10. package/dist/assets/profiles/thorough.json +1 -1
  11. package/dist/assets/prompts/consolidate-system.md +23 -0
  12. package/dist/assets/prompts/contradiction-judge.md +33 -0
  13. package/dist/assets/prompts/distill-knowledge-system.md +22 -0
  14. package/dist/assets/prompts/distill-lesson-system.md +36 -0
  15. package/dist/assets/prompts/extract-session.md +6 -2
  16. package/dist/assets/prompts/graph-extract-system.md +1 -0
  17. package/dist/assets/prompts/graph-extract-user-prompt.md +1 -1
  18. package/dist/assets/prompts/memory-infer-system.md +1 -0
  19. package/dist/assets/prompts/memory-infer-user.md +5 -0
  20. package/dist/assets/prompts/metadata-enhance-system.md +1 -0
  21. package/dist/assets/prompts/procedural-system.md +44 -0
  22. package/dist/assets/prompts/recombine-system.md +40 -0
  23. package/dist/assets/prompts/staleness-detect-system.md +6 -0
  24. package/dist/assets/prompts/validate-summary-judge.md +1 -0
  25. package/dist/assets/stash-skeleton/facts/conventions/assets/agent.md +38 -0
  26. package/dist/assets/stash-skeleton/facts/conventions/assets/command.md +38 -0
  27. package/dist/assets/stash-skeleton/facts/conventions/assets/fact.md +39 -0
  28. package/dist/assets/stash-skeleton/facts/conventions/assets/knowledge.md +40 -0
  29. package/dist/assets/stash-skeleton/facts/conventions/assets/lesson.md +43 -0
  30. package/dist/assets/stash-skeleton/facts/conventions/assets/memory.md +38 -0
  31. package/dist/assets/stash-skeleton/facts/conventions/assets/script.md +43 -0
  32. package/dist/assets/stash-skeleton/facts/conventions/assets/skill.md +40 -0
  33. package/dist/assets/stash-skeleton/facts/conventions/assets/workflow.md +43 -0
  34. package/dist/assets/templates/html/health.html +281 -111
  35. package/dist/assets/wiki/ingest-workflow-template.md +38 -10
  36. package/dist/cli/parse-args.js +46 -1
  37. package/dist/cli/shared.js +28 -0
  38. package/dist/cli.js +27 -11
  39. package/dist/commands/agent/agent-dispatch.js +2 -2
  40. package/dist/commands/agent/agent-support.js +0 -7
  41. package/dist/commands/agent/contribute-cli.js +17 -4
  42. package/dist/commands/config-cli.js +18 -2
  43. package/dist/commands/env/child-env.js +47 -0
  44. package/dist/commands/env/env-cli.js +33 -26
  45. package/dist/commands/env/secret-cli.js +36 -22
  46. package/dist/commands/feedback-cli.js +15 -6
  47. package/dist/commands/graph/graph-cli.js +5 -13
  48. package/dist/commands/graph/graph.js +76 -72
  49. package/dist/commands/health/checks.js +49 -1
  50. package/dist/commands/health/html-report.js +422 -80
  51. package/dist/commands/health.js +386 -9
  52. package/dist/commands/improve/calibration.js +161 -0
  53. package/dist/commands/improve/consolidate/chunking.js +141 -0
  54. package/dist/commands/improve/consolidate/eligibility.js +81 -0
  55. package/dist/commands/improve/consolidate/merge.js +145 -0
  56. package/dist/commands/improve/consolidate/sanitize.js +231 -0
  57. package/dist/commands/{lint.js → improve/consolidate/types.js} +1 -1
  58. package/dist/commands/improve/consolidate.js +635 -660
  59. package/dist/commands/improve/dedup.js +482 -0
  60. package/dist/commands/improve/distill.js +159 -69
  61. package/dist/commands/improve/eligibility.js +434 -0
  62. package/dist/commands/improve/encoding-salience.js +205 -0
  63. package/dist/commands/improve/extract-cli.js +124 -2
  64. package/dist/commands/improve/extract-prompt.js +39 -2
  65. package/dist/commands/improve/extract-watch.js +140 -0
  66. package/dist/commands/improve/extract.js +389 -40
  67. package/dist/commands/improve/feedback-valence.js +54 -0
  68. package/dist/commands/improve/homeostatic.js +467 -0
  69. package/dist/commands/improve/improve-auto-accept.js +138 -7
  70. package/dist/commands/improve/improve-cli.js +36 -61
  71. package/dist/commands/improve/improve-profiles.js +14 -0
  72. package/dist/commands/improve/improve-result-file.js +14 -25
  73. package/dist/commands/improve/improve-session.js +58 -0
  74. package/dist/commands/improve/improve.js +485 -2498
  75. package/dist/commands/improve/locks.js +154 -0
  76. package/dist/commands/improve/loop-stages.js +1083 -0
  77. package/dist/commands/improve/memory/memory-contradiction-detect.js +23 -28
  78. package/dist/commands/improve/outcome-loop.js +256 -0
  79. package/dist/commands/improve/preparation.js +1966 -0
  80. package/dist/commands/improve/proactive-maintenance.js +115 -0
  81. package/dist/commands/improve/procedural.js +418 -0
  82. package/dist/commands/improve/recombine.js +850 -0
  83. package/dist/commands/improve/reflect-noise.js +0 -0
  84. package/dist/commands/improve/reflect.js +183 -40
  85. package/dist/commands/improve/salience.js +438 -0
  86. package/dist/commands/improve/triage.js +93 -0
  87. package/dist/commands/lint/agent-linter.js +19 -24
  88. package/dist/commands/lint/base-linter.js +173 -60
  89. package/dist/commands/lint/command-linter.js +19 -24
  90. package/dist/commands/lint/env-key-rules.js +38 -1
  91. package/dist/commands/lint/fact-linter.js +39 -0
  92. package/dist/commands/lint/index.js +31 -13
  93. package/dist/commands/lint/memory-linter.js +1 -1
  94. package/dist/commands/lint/registry.js +7 -2
  95. package/dist/commands/lint/task-linter.js +3 -3
  96. package/dist/commands/lint/workflow-linter.js +26 -1
  97. package/dist/commands/proposal/drain-policies.js +5 -0
  98. package/dist/commands/proposal/drain.js +43 -50
  99. package/dist/commands/proposal/proposal-cli.js +21 -31
  100. package/dist/commands/proposal/proposal.js +5 -0
  101. package/dist/commands/proposal/propose.js +7 -2
  102. package/dist/commands/proposal/validators/proposal-quality-validators.js +9 -8
  103. package/dist/commands/proposal/validators/proposals.js +189 -63
  104. package/dist/commands/read/curate.js +414 -94
  105. package/dist/commands/read/knowledge.js +6 -3
  106. package/dist/commands/read/search-cli.js +9 -4
  107. package/dist/commands/read/search.js +10 -6
  108. package/dist/commands/read/show.js +86 -7
  109. package/dist/commands/sources/init.js +49 -17
  110. package/dist/commands/sources/installed-stashes.js +11 -3
  111. package/dist/commands/sources/schema-repair.js +43 -45
  112. package/dist/commands/sources/self-update.js +2 -2
  113. package/dist/commands/sources/source-add.js +7 -3
  114. package/dist/commands/sources/stash-cli.js +28 -40
  115. package/dist/commands/sources/stash-skeleton.js +23 -8
  116. package/dist/commands/tasks/tasks-cli.js +19 -27
  117. package/dist/commands/tasks/tasks.js +39 -11
  118. package/dist/commands/wiki-cli.js +21 -35
  119. package/dist/core/asset/asset-registry.js +3 -1
  120. package/dist/core/asset/asset-spec.js +18 -2
  121. package/dist/core/asset/frontmatter.js +166 -167
  122. package/dist/core/asset/markdown.js +8 -0
  123. package/dist/core/authoring-rules.js +92 -0
  124. package/dist/core/common.js +0 -5
  125. package/dist/core/config/config-migration.js +12 -11
  126. package/dist/core/config/config-schema.js +340 -56
  127. package/dist/core/config/config-types.js +3 -3
  128. package/dist/core/config/config.js +28 -7
  129. package/dist/core/events.js +3 -7
  130. package/dist/core/improve-types.js +11 -8
  131. package/dist/core/logs-db.js +10 -66
  132. package/dist/core/parse.js +36 -16
  133. package/dist/core/paths.js +3 -0
  134. package/dist/core/standards/resolve-standards-context.js +87 -0
  135. package/dist/core/standards/resolve-stash-standards.js +99 -0
  136. package/dist/core/standards/resolve-type-conventions.js +66 -0
  137. package/dist/core/state/migrations.js +714 -0
  138. package/dist/core/state-db.js +525 -474
  139. package/dist/indexer/db/db.js +439 -247
  140. package/dist/indexer/db/graph-db.js +129 -86
  141. package/dist/indexer/ensure-index.js +152 -17
  142. package/dist/indexer/graph/graph-boost.js +51 -41
  143. package/dist/indexer/graph/graph-extraction.js +218 -4
  144. package/dist/indexer/index-writer-lock.js +99 -0
  145. package/dist/indexer/indexer.js +123 -221
  146. package/dist/indexer/passes/dir-staleness.js +114 -0
  147. package/dist/indexer/passes/memory-inference.js +13 -5
  148. package/dist/indexer/passes/staleness-detect.js +2 -5
  149. package/dist/indexer/search/db-search.js +19 -6
  150. package/dist/indexer/search/ranking-contributors.js +22 -0
  151. package/dist/indexer/search/ranking.js +4 -0
  152. package/dist/indexer/search/search-source.js +17 -18
  153. package/dist/indexer/search/semantic-status.js +4 -0
  154. package/dist/indexer/walk/matchers.js +9 -0
  155. package/dist/integrations/agent/config.js +6 -53
  156. package/dist/integrations/agent/index.js +2 -18
  157. package/dist/integrations/agent/prompts.js +75 -9
  158. package/dist/integrations/agent/runner-dispatch.js +59 -0
  159. package/dist/integrations/harnesses/claude/session-log.js +11 -1
  160. package/dist/integrations/harnesses/index.js +2 -3
  161. package/dist/integrations/harnesses/opencode/session-log.js +173 -3
  162. package/dist/integrations/harnesses/opencode-sdk/index.js +2 -2
  163. package/dist/integrations/harnesses/opencode-sdk/sdk-runner.js +0 -2
  164. package/dist/integrations/session-logs/index.js +16 -0
  165. package/dist/llm/client.js +45 -15
  166. package/dist/llm/embedder.js +42 -3
  167. package/dist/llm/embedders/deterministic.js +66 -0
  168. package/dist/llm/embedders/local.js +66 -2
  169. package/dist/llm/feature-gate.js +8 -4
  170. package/dist/llm/graph-extract.js +67 -44
  171. package/dist/llm/memory-infer-impl.js +138 -0
  172. package/dist/llm/memory-infer.js +1 -127
  173. package/dist/llm/metadata-enhance.js +44 -31
  174. package/dist/llm/structured-call.js +49 -0
  175. package/dist/migrate-storage-node.mjs +8 -0
  176. package/dist/output/context.js +5 -5
  177. package/dist/output/renderers.js +74 -2
  178. package/dist/output/shapes/curate.js +14 -2
  179. package/dist/output/shapes/passthrough.js +0 -1
  180. package/dist/output/text/helpers.js +16 -1
  181. package/dist/registry/providers/skills-sh.js +21 -147
  182. package/dist/registry/providers/static-index.js +15 -157
  183. package/dist/registry/resolve.js +22 -9
  184. package/dist/runtime.js +25 -1
  185. package/dist/scripts/migrate-storage.js +2617 -1961
  186. package/dist/scripts/migrations/import-fs-improve-runs-to-db.js +759 -510
  187. package/dist/setup/setup.js +29 -8
  188. package/dist/sources/include.js +6 -2
  189. package/dist/sources/providers/filesystem.js +0 -1
  190. package/dist/sources/providers/git-install.js +210 -0
  191. package/dist/sources/providers/git-provider.js +234 -0
  192. package/dist/sources/providers/git-stash.js +248 -0
  193. package/dist/sources/providers/git.js +10 -661
  194. package/dist/sources/providers/npm.js +2 -6
  195. package/dist/sources/providers/provider-utils.js +13 -7
  196. package/dist/sources/providers/sync-from-ref.js +9 -1
  197. package/dist/sources/providers/tar-utils.js +16 -8
  198. package/dist/sources/providers/website.js +9 -5
  199. package/dist/sources/website-ingest.js +187 -29
  200. package/dist/sources/wiki-fetchers/registry.js +53 -0
  201. package/dist/sources/wiki-fetchers/youtube.js +239 -0
  202. package/dist/storage/database.js +45 -10
  203. package/dist/storage/managed-db.js +82 -0
  204. package/dist/storage/repositories/registry-cache.js +92 -0
  205. package/dist/storage/sqlite-pragmas.js +146 -0
  206. package/dist/tasks/backends/cron.js +1 -1
  207. package/dist/tasks/backends/launchd.js +1 -1
  208. package/dist/tasks/backends/schtasks.js +1 -1
  209. package/dist/tasks/{resolveAkmBin.js → resolve-akm-bin.js} +2 -2
  210. package/dist/tasks/runner.js +5 -13
  211. package/dist/text-import-hook.mjs +0 -0
  212. package/dist/wiki/wiki.js +37 -0
  213. package/dist/workflows/db.js +3 -4
  214. package/dist/workflows/runtime/runs.js +1 -117
  215. package/dist/workflows/runtime/workflow-asset-loader.js +125 -0
  216. package/dist/workflows/validate-summary.js +2 -7
  217. package/docs/data-and-telemetry.md +3 -2
  218. package/docs/migration/release-notes/0.9.0.md +39 -0
  219. package/package.json +13 -11
  220. package/dist/commands/db-cli.js +0 -23
  221. package/dist/indexer/db/db-backup.js +0 -376
@@ -5,20 +5,20 @@
5
5
  * Stash-lifecycle command cluster — the create/index/ingest/inspect verbs for
6
6
  * the working stash and its index database: `akm init` (create the stash +
7
7
  * persist stashDir), `akm index` (build/refresh the search index), `akm import`
8
- * (ingest a knowledge doc/URL), `akm db` (+ nested `backups` — inspect the
9
- * SQLite data dir), and `akm info` (system capabilities + index stats).
8
+ * (ingest a knowledge doc/URL), and `akm info` (system capabilities + index
9
+ * stats).
10
10
  * Extracted verbatim from src/cli.ts (WS6) so the God Module shrinks; the
11
- * `main.subCommands.{init,index,import,db,info}` keys and every subcommand's
11
+ * `main.subCommands.{init,index,import,info}` keys and every subcommand's
12
12
  * args/output shape stay byte-identical.
13
13
  *
14
14
  * These share no private helper with any command still inline in cli.ts — every
15
15
  * dependency is already exported from a shared module (core/paths, core/warn,
16
16
  * core/errors, core/events, output/context, cli/shared, cli/parse-args, plus the
17
- * per-command implementations in ./init, ./indexer, ./info, ./db-cli, ./knowledge,
17
+ * per-command implementations in ./init, ./indexer, ./info, ./knowledge,
18
18
  * ./core/asset-create, ./core/common), so the cluster moves with zero hoisting.
19
19
  *
20
20
  * The leaf handlers whose body is a plain `runWithJsonErrors(...) + output(...)`
21
- * (`init`, `import`, `info`, `db`, `db backups`) are migrated onto
21
+ * (`init`, `import`, `info`) are migrated onto
22
22
  * `defineJsonCommand`, which emits the same JSON envelope (stdout/stderr/
23
23
  * exit-code) as the inline form. `index` keeps a plain `defineCommand` wrapping
24
24
  * `runWithJsonErrors` because its body owns a spinner, an AbortController, and
@@ -27,17 +27,17 @@
27
27
  import path from "node:path";
28
28
  import * as p from "@clack/prompts";
29
29
  import { defineCommand } from "citty";
30
- import { hasSubcommand } from "../../cli/parse-args.js";
31
30
  import { defineJsonCommand, output, runWithJsonErrors } from "../../cli/shared.js";
32
31
  import { assertFlatAssetName } from "../../core/asset/asset-create.js";
33
32
  import { isHttpUrl } from "../../core/common.js";
33
+ import { loadConfig } from "../../core/config/config.js";
34
34
  import { UsageError } from "../../core/errors.js";
35
35
  import { appendEvent } from "../../core/events.js";
36
36
  import { getCacheDir } from "../../core/paths.js";
37
37
  import { clearLogFile, info, isVerbose, setLogFile } from "../../core/warn.js";
38
+ import { resolveWriteTarget } from "../../core/write-source.js";
38
39
  import { akmIndex } from "../../indexer/indexer.js";
39
40
  import { getHyphenatedBoolean, getOutputMode, parseFlagValue } from "../../output/context.js";
40
- import { akmDbBackups } from "../db-cli.js";
41
41
  import { readKnowledgeInput, writeMarkdownAsset } from "../read/knowledge.js";
42
42
  import { assembleInfo } from "./info.js";
43
43
  import { akmInit } from "./init.js";
@@ -48,12 +48,20 @@ export const initCommand = defineJsonCommand({
48
48
  },
49
49
  args: {
50
50
  dir: { type: "string", description: "Custom stash directory path (default: ~/akm)" },
51
+ "set-default": {
52
+ type: "boolean",
53
+ description: "Make --dir the default stash (write stashDir to config.json). Without this, `akm init --dir X` scaffolds X but leaves your existing default stash unchanged.",
54
+ default: false,
55
+ },
51
56
  },
52
57
  async run({ args }) {
53
58
  // Accept both historical spellings for backwards compatibility with
54
59
  // older docs/scripts that used `--stashDir`.
55
60
  const legacyDir = parseFlagValue(process.argv, "--stashDir") ?? parseFlagValue(process.argv, "--stash-dir");
56
- const result = await akmInit({ dir: args.dir ?? legacyDir });
61
+ const result = await akmInit({
62
+ dir: args.dir ?? legacyDir,
63
+ setDefault: getHyphenatedBoolean(args, "set-default"),
64
+ });
57
65
  output("init", result);
58
66
  },
59
67
  });
@@ -71,6 +79,11 @@ export const indexCommand = defineCommand({
71
79
  description: "When combined with --clean, report stale entries without deleting them.",
72
80
  default: false,
73
81
  },
82
+ background: {
83
+ type: "boolean",
84
+ description: "Run as a background process (suppresses interactive output, manages PID file).",
85
+ default: false,
86
+ },
74
87
  },
75
88
  async run({ args }) {
76
89
  await runWithJsonErrors(async () => {
@@ -80,6 +93,7 @@ export const indexCommand = defineCommand({
80
93
  if (getHyphenatedBoolean(args, "re-enrich") || parseFlagValue(process.argv, "--re-enrich") !== undefined) {
81
94
  throw new UsageError("`akm index --re-enrich` has been removed. Re-enrichment of index-time LLM passes is not exposed in this slice.");
82
95
  }
96
+ const isBackground = args.background === true;
83
97
  const outputMode = getOutputMode();
84
98
  const controller = new AbortController();
85
99
  const abort = () => controller.abort(new Error("index interrupted"));
@@ -88,7 +102,7 @@ export const indexCommand = defineCommand({
88
102
  const indexLogFile = path.join(getCacheDir(), "logs", "index", `${new Date().toISOString().replace(/[:.]/g, "-")}.log`);
89
103
  setLogFile(indexLogFile);
90
104
  const verbose = isVerbose();
91
- const spin = !verbose && outputMode.format === "text" ? p.spinner() : null;
105
+ const spin = !verbose && !isBackground && outputMode.format === "text" ? p.spinner() : null;
92
106
  if (spin) {
93
107
  spin.start(`Building search index${args.full ? " (full rebuild)" : ""}...`);
94
108
  }
@@ -114,7 +128,9 @@ export const indexCommand = defineCommand({
114
128
  if (spin) {
115
129
  spin.stop(`Indexed ${result.totalEntries} assets.`);
116
130
  }
117
- output("index", result);
131
+ if (!isBackground) {
132
+ output("index", result);
133
+ }
118
134
  }
119
135
  catch (error) {
120
136
  if (spin) {
@@ -137,35 +153,6 @@ export const infoCommand = defineJsonCommand({
137
153
  output("info", result);
138
154
  },
139
155
  });
140
- // MVP DB administration. Currently only `akm db backups`; restore is manual —
141
- // stop akm and run `scripts/migrations/restore-data-dir.sh <backup>`.
142
- // Single source of truth: the routing set is derived from the subCommands keys
143
- // (M10) so adding a subcommand can never silently desync from `hasSubcommand`.
144
- const dbSubCommands = {
145
- backups: defineJsonCommand({
146
- meta: {
147
- name: "backups",
148
- description: "List pre-upgrade snapshots of the data directory (newest first). Backups are created automatically before destructive DB version upgrades unless AKM_DB_BACKUP=0.",
149
- },
150
- run() {
151
- output("db-backups", akmDbBackups());
152
- },
153
- }),
154
- };
155
- const DB_SUBCOMMAND_SET = new Set(Object.keys(dbSubCommands));
156
- export const dbCommand = defineJsonCommand({
157
- meta: {
158
- name: "db",
159
- description: "Inspect the AKM SQLite data directory. Currently exposes `backups`; to restore from a snapshot, stop akm and run scripts/migrations/restore-data-dir.sh against the chosen backup.",
160
- },
161
- subCommands: dbSubCommands,
162
- run({ args }) {
163
- if (hasSubcommand(args, DB_SUBCOMMAND_SET))
164
- return;
165
- // Default action: list backups.
166
- output("db-backups", akmDbBackups());
167
- },
168
- });
169
156
  export const importKnowledgeCommand = defineJsonCommand({
170
157
  meta: {
171
158
  name: "import",
@@ -198,7 +185,8 @@ export const importKnowledgeCommand = defineJsonCommand({
198
185
  async run({ args }) {
199
186
  // `--name` is a flat name; subdirectory placement is `--path`'s job.
200
187
  assertFlatAssetName(args.name);
201
- const { content, preferredName } = await readKnowledgeInput(args.source);
188
+ const stashDir = resolveWriteTarget(loadConfig(), args.target).source.path;
189
+ const { content, preferredName } = await readKnowledgeInput(args.source, { stashDir });
202
190
  const result = await writeMarkdownAsset({
203
191
  type: "knowledge",
204
192
  content,
@@ -6,27 +6,42 @@ import path from "node:path";
6
6
  import { getDirname } from "../../runtime.js";
7
7
  const SKELETON_DIR = path.join(getDirname(import.meta.url), "../../assets/stash-skeleton");
8
8
  /**
9
- * Copy the default stash skeleton into a newly created stash directory.
9
+ * Copy the default stash skeleton into a stash directory.
10
10
  *
11
- * Each file in src/assets/stash-skeleton/ is written to the stash root only
12
- * if the destination does not already exist — existing files are never
13
- * overwritten. Non-fatal: if the skeleton directory is missing or a copy
14
- * fails the caller continues normally.
11
+ * The skeleton tree under src/assets/stash-skeleton/ is mirrored **recursively**
12
+ * into the stash root, preserving relative subpaths (e.g.
13
+ * `facts/conventions/assets/skill.md` lands at the matching stash subpath).
14
+ * Each file is written only if the destination does not already exist — existing
15
+ * (possibly user-edited) files are never overwritten. Intermediate directories
16
+ * are created as needed.
17
+ *
18
+ * Idempotent and absent-only: running it again on an existing stash backfills
19
+ * any skeleton files that are missing without clobbering present ones. Non-fatal:
20
+ * if the skeleton directory is missing or a copy fails the caller continues.
15
21
  */
16
22
  export function copyStashSkeleton(stashDir) {
23
+ copySkeletonDir(SKELETON_DIR, stashDir);
24
+ }
25
+ /** Recursively mirror `srcDir` into `destDir`, writing files only when absent. */
26
+ function copySkeletonDir(srcDir, destDir) {
17
27
  let entries;
18
28
  try {
19
- entries = fs.readdirSync(SKELETON_DIR);
29
+ entries = fs.readdirSync(srcDir, { withFileTypes: true });
20
30
  }
21
31
  catch {
22
32
  return;
23
33
  }
24
34
  for (const entry of entries) {
25
- const src = path.join(SKELETON_DIR, entry);
26
- const dest = path.join(stashDir, entry);
35
+ const src = path.join(srcDir, entry.name);
36
+ const dest = path.join(destDir, entry.name);
37
+ if (entry.isDirectory()) {
38
+ copySkeletonDir(src, dest);
39
+ continue;
40
+ }
27
41
  if (fs.existsSync(dest))
28
42
  continue;
29
43
  try {
44
+ fs.mkdirSync(path.dirname(dest), { recursive: true });
30
45
  fs.copyFileSync(src, dest);
31
46
  }
32
47
  catch {
@@ -13,8 +13,8 @@
13
13
  * with the family.
14
14
  */
15
15
  import { defineCommand } from "citty";
16
- import { hasSubcommand, parsePositiveIntFlag } from "../../cli/parse-args.js";
17
- import { defineJsonCommand, output, runWithJsonErrors } from "../../cli/shared.js";
16
+ import { parsePositiveIntFlag } from "../../cli/parse-args.js";
17
+ import { defineGroupCommand, defineJsonCommand, output, runWithJsonErrors } from "../../cli/shared.js";
18
18
  import { getHyphenatedArg } from "../../output/context.js";
19
19
  import { detectServerDefault, registerDefaultTasks } from "./default-tasks.js";
20
20
  import { akmTasksAdd, akmTasksDoctor, akmTasksHistory, akmTasksList, akmTasksRemove, akmTasksRun, akmTasksSetEnabled, akmTasksShow, akmTasksSync, parseTaskRef, } from "./tasks.js";
@@ -176,35 +176,27 @@ const tasksDoctorCommand = defineJsonCommand({
176
176
  output("tasks-doctor", result);
177
177
  },
178
178
  });
179
- // Single source of truth: the routing set is derived from the subCommands keys
180
- // (M10) so adding a subcommand can never silently desync from `hasSubcommand`.
181
- const tasksSubCommands = {
182
- add: tasksAddCommand,
183
- init: tasksInitCommand,
184
- list: tasksListCommand,
185
- show: tasksShowCommand,
186
- remove: tasksRemoveCommand,
187
- enable: tasksEnableCommand,
188
- disable: tasksDisableCommand,
189
- run: tasksRunCommand,
190
- history: tasksHistoryCommand,
191
- sync: tasksSyncCommand,
192
- doctor: tasksDoctorCommand,
193
- };
194
- const TASKS_SUBCOMMAND_SET = new Set(Object.keys(tasksSubCommands));
195
- export const tasksCommand = defineCommand({
179
+ export const tasksCommand = defineGroupCommand({
196
180
  meta: {
197
181
  name: "tasks",
198
182
  alias: "task",
199
183
  description: "Schedule workflows or prompts via the OS-native scheduler (cron / launchd / schtasks)",
200
184
  },
201
- subCommands: tasksSubCommands,
202
- run({ args }) {
203
- return runWithJsonErrors(async () => {
204
- if (hasSubcommand(args, TASKS_SUBCOMMAND_SET))
205
- return;
206
- const result = await akmTasksList();
207
- output("tasks-list", result);
208
- });
185
+ subCommands: {
186
+ add: tasksAddCommand,
187
+ init: tasksInitCommand,
188
+ list: tasksListCommand,
189
+ show: tasksShowCommand,
190
+ remove: tasksRemoveCommand,
191
+ enable: tasksEnableCommand,
192
+ disable: tasksDisableCommand,
193
+ run: tasksRunCommand,
194
+ history: tasksHistoryCommand,
195
+ sync: tasksSyncCommand,
196
+ doctor: tasksDoctorCommand,
197
+ },
198
+ async defaultRun() {
199
+ const result = await akmTasksList();
200
+ output("tasks-list", result);
209
201
  },
210
202
  });
@@ -16,11 +16,12 @@ import { isWithin, resolveStashDir } from "../../core/common.js";
16
16
  import { loadConfig } from "../../core/config/config.js";
17
17
  import { ConfigError, NotFoundError, UsageError } from "../../core/errors.js";
18
18
  import { getTaskHistoryDir, getTaskLogDir } from "../../core/paths.js";
19
+ import { commitWriteTargetBoundary, deleteAssetFromSource, resolveWriteTarget, writeAssetToSource, } from "../../core/write-source.js";
19
20
  import { listAgentProfileNames } from "../../integrations/agent/index.js";
20
21
  import { resolveAssetPath } from "../../sources/resolve.js";
21
22
  import { backendNameForPlatform, selectBackend } from "../../tasks/backends/index.js";
22
23
  import { parseTaskDocument } from "../../tasks/parser.js";
23
- import { resolveAkmInvocation } from "../../tasks/resolveAkmBin.js";
24
+ import { resolveAkmInvocation } from "../../tasks/resolve-akm-bin.js";
24
25
  import { exitCodeForStatus, readTaskHistory, runTask } from "../../tasks/runner.js";
25
26
  import { parseSchedule, SCHEDULE_SUPPORTED_SUBSET_HINT, translateToCron } from "../../tasks/schedule.js";
26
27
  import { validateTaskDocument } from "../../tasks/validator.js";
@@ -38,7 +39,8 @@ export async function akmTasksAdd(input) {
38
39
  // Validate the schedule for the active backend before writing anything.
39
40
  const backend = backendNameForPlatform();
40
41
  parseSchedule(input.schedule, backend);
41
- const stashDir = resolveStashDir();
42
+ const target = resolveTaskWriteTarget();
43
+ const stashDir = target.source.path;
42
44
  const typeRoot = path.join(stashDir, "tasks");
43
45
  fs.mkdirSync(typeRoot, { recursive: true });
44
46
  const assetPath = resolveAssetPathFromName("task", typeRoot, id);
@@ -64,7 +66,8 @@ export async function akmTasksAdd(input) {
64
66
  });
65
67
  const task = parseTaskDocument({ yaml, filePath: assetPath, id });
66
68
  await validateTaskDocument(task, { backend, stashDir });
67
- fs.writeFileSync(assetPath, yaml.endsWith("\n") ? yaml : `${yaml}\n`, "utf8");
69
+ const ref = taskAssetRef(id);
70
+ await writeAssetToSource(target.source, target.config, ref, yaml);
68
71
  // Install in the OS scheduler. If install fails after the file was written,
69
72
  // delete the file so the on-disk state never claims a task is registered
70
73
  // when it isn't.
@@ -74,13 +77,14 @@ export async function akmTasksAdd(input) {
74
77
  }
75
78
  catch (err) {
76
79
  try {
77
- fs.rmSync(assetPath, { force: true });
80
+ await deleteAssetFromSource(target.source, target.config, ref);
78
81
  }
79
82
  catch {
80
83
  /* ignore */
81
84
  }
82
85
  throw err;
83
86
  }
87
+ commitWriteTargetBoundary(target, `Update task:${id}`);
84
88
  return {
85
89
  id,
86
90
  ref: `task:${id}`,
@@ -192,30 +196,47 @@ export async function akmTasksShow(id) {
192
196
  }
193
197
  export async function akmTasksRemove(id) {
194
198
  const normalised = normaliseTaskId(id);
195
- const stashDir = resolveStashDir();
199
+ const target = resolveTaskWriteTarget();
200
+ const stashDir = target.source.path;
196
201
  const typeRoot = path.join(stashDir, "tasks");
197
202
  if (fs.existsSync(typeRoot))
198
203
  warnLegacyMdTaskFiles(typeRoot);
199
- const filePath = await resolveAssetPath(stashDir, "task", normalised);
204
+ await resolveAssetPath(stashDir, "task", normalised);
205
+ const ref = taskAssetRef(normalised);
200
206
  const sched = selectBackend();
207
+ let uninstallError;
208
+ let deleteError;
201
209
  try {
202
210
  await sched.uninstall(normalised);
203
211
  }
204
- finally {
205
- fs.rmSync(filePath, { force: true });
212
+ catch (err) {
213
+ uninstallError = err;
214
+ }
215
+ try {
216
+ await deleteAssetFromSource(target.source, target.config, ref);
206
217
  }
218
+ catch (err) {
219
+ deleteError = err;
220
+ }
221
+ if (uninstallError !== undefined)
222
+ throw uninstallError;
223
+ if (deleteError !== undefined)
224
+ throw deleteError;
225
+ commitWriteTargetBoundary(target, `Remove task:${normalised}`);
207
226
  return { id: normalised, removed: true, backend: sched.name };
208
227
  }
209
228
  export async function akmTasksSetEnabled(id, enabled) {
210
229
  const normalised = normaliseTaskId(id);
211
- const stashDir = resolveStashDir();
230
+ const target = resolveTaskWriteTarget();
231
+ const stashDir = target.source.path;
212
232
  const typeRoot = path.join(stashDir, "tasks");
213
233
  if (fs.existsSync(typeRoot))
214
234
  warnLegacyMdTaskFiles(typeRoot);
215
235
  const filePath = await resolveAssetPath(stashDir, "task", normalised);
216
236
  const yaml = fs.readFileSync(filePath, "utf8");
217
237
  const updated = setEnabledInYaml(yaml, enabled);
218
- fs.writeFileSync(filePath, updated, "utf8");
238
+ const ref = taskAssetRef(normalised);
239
+ await writeAssetToSource(target.source, target.config, ref, updated);
219
240
  const sched = selectBackend();
220
241
  try {
221
242
  // Reinstall from the (just-updated) definition rather than only toggling
@@ -229,9 +250,10 @@ export async function akmTasksSetEnabled(id, enabled) {
229
250
  catch (err) {
230
251
  // Roll the file back so the YAML source-of-truth and the OS
231
252
  // scheduler don't diverge silently when the backend call fails.
232
- fs.writeFileSync(filePath, yaml, "utf8");
253
+ await writeAssetToSource(target.source, target.config, ref, yaml);
233
254
  throw err;
234
255
  }
256
+ commitWriteTargetBoundary(target, `Update task:${normalised}`);
235
257
  return { id: normalised, enabled, backend: sched.name };
236
258
  }
237
259
  export async function akmTasksRun(id) {
@@ -392,6 +414,12 @@ function normaliseTaskId(raw) {
392
414
  }
393
415
  return id;
394
416
  }
417
+ function taskAssetRef(id) {
418
+ return { type: "task", name: id };
419
+ }
420
+ function resolveTaskWriteTarget() {
421
+ return resolveWriteTarget(loadConfig());
422
+ }
395
423
  function renderTaskYaml(input) {
396
424
  const obj = { schedule: input.schedule };
397
425
  if (input.workflow) {
@@ -11,9 +11,9 @@
11
11
  * `process.exit(1)` after the wrapper when findings exist.
12
12
  */
13
13
  import { defineCommand } from "citty";
14
- import { getStringArg, hasSubcommand, parsePositiveIntFlag } from "../cli/parse-args.js";
15
- import { defineJsonCommand, output, runWithJsonErrors } from "../cli/shared.js";
16
- import { isHttpUrl, resolveStashDir } from "../core/common.js";
14
+ import { getStringArg, parsePositiveIntFlag } from "../cli/parse-args.js";
15
+ import { defineGroupCommand, defineJsonCommand, output, runWithJsonErrors } from "../cli/shared.js";
16
+ import { resolveStashDir } from "../core/common.js";
17
17
  import { loadConfig, resolveConfiguredSources } from "../core/config/config.js";
18
18
  import { ConfigError, UsageError } from "../core/errors.js";
19
19
  import { getHyphenatedArg, getHyphenatedBoolean } from "../output/context.js";
@@ -168,13 +168,6 @@ const wikiStashCommand = defineJsonCommand({
168
168
  },
169
169
  async run({ args }) {
170
170
  const { stashRaw } = await import("../wiki/wiki.js");
171
- const { content, preferredName } = await (async () => {
172
- if (!isHttpUrl(args.source))
173
- return readKnowledgeInput(args.source);
174
- const { fetchWebsiteMarkdownSnapshot } = await import("../sources/website-ingest.js");
175
- const snapshot = await fetchWebsiteMarkdownSnapshot(args.source);
176
- return { content: snapshot.content, preferredName: args.as ?? snapshot.preferredName };
177
- })();
178
171
  let stashDir;
179
172
  if (args.target) {
180
173
  // Resolve the named source to its filesystem path.
@@ -193,6 +186,7 @@ const wikiStashCommand = defineJsonCommand({
193
186
  else {
194
187
  stashDir = resolveStashDir();
195
188
  }
189
+ const { content, preferredName } = await readKnowledgeInput(args.source, { stashDir });
196
190
  const result = stashRaw({
197
191
  stashDir,
198
192
  wikiName: args.name,
@@ -274,34 +268,26 @@ const wikiIngestCommand = defineJsonCommand({
274
268
  });
275
269
  },
276
270
  });
277
- // Single source of truth: the routing set is derived from the subCommands keys
278
- // (M10) so adding a subcommand can never silently desync from `hasSubcommand`.
279
- const wikiSubCommands = {
280
- create: wikiCreateCommand,
281
- register: wikiRegisterCommand,
282
- list: wikiListCommand,
283
- show: wikiShowCommand,
284
- remove: wikiRemoveCommand,
285
- pages: wikiPagesCommand,
286
- search: wikiSearchCommand,
287
- stash: wikiStashCommand,
288
- lint: wikiLintCommand,
289
- ingest: wikiIngestCommand,
290
- };
291
- const WIKI_SUBCOMMAND_SET = new Set(Object.keys(wikiSubCommands));
292
- export const wikiCommand = defineCommand({
271
+ export const wikiCommand = defineGroupCommand({
293
272
  meta: {
294
273
  name: "wiki",
295
274
  description: "Manage multiple markdown wikis (Karpathy-style). akm surfaces (lifecycle, raw/, lint, index); the agent writes pages.",
296
275
  },
297
- subCommands: wikiSubCommands,
298
- run({ args }) {
299
- return runWithJsonErrors(async () => {
300
- if (hasSubcommand(args, WIKI_SUBCOMMAND_SET))
301
- return;
302
- // Default action: list wikis
303
- const { listWikis } = await import("../wiki/wiki.js");
304
- output("wiki-list", { wikis: listWikis(resolveStashDir()) });
305
- });
276
+ subCommands: {
277
+ create: wikiCreateCommand,
278
+ register: wikiRegisterCommand,
279
+ list: wikiListCommand,
280
+ show: wikiShowCommand,
281
+ remove: wikiRemoveCommand,
282
+ pages: wikiPagesCommand,
283
+ search: wikiSearchCommand,
284
+ stash: wikiStashCommand,
285
+ lint: wikiLintCommand,
286
+ ingest: wikiIngestCommand,
287
+ },
288
+ async defaultRun() {
289
+ // Default action: list wikis
290
+ const { listWikis } = await import("../wiki/wiki.js");
291
+ output("wiki-list", { wikis: listWikis(resolveStashDir()) });
306
292
  },
307
293
  });
@@ -29,6 +29,7 @@ export const TYPE_TO_RENDERER = {
29
29
  wiki: "wiki-md",
30
30
  task: "task-yaml",
31
31
  session: "session-md",
32
+ fact: "fact-md",
32
33
  };
33
34
  /** Map asset types to action builder functions for search results. */
34
35
  export const ACTION_BUILDERS = {
@@ -40,11 +41,12 @@ export const ACTION_BUILDERS = {
40
41
  lesson: (ref) => `akm show ${ref} -> read the lesson and apply when_to_use`,
41
42
  memory: (ref) => `akm show ${ref} -> recall context`,
42
43
  workflow: (ref) => buildWorkflowAction(ref),
43
- env: (ref) => `akm show ${ref} -> inspect key names; akm env run ${ref} -- <command> -> run with the whole .env injected (the agent-safe path values never reach stdout). akm env export ${ref} --out <file> writes a sourceable script (values to a file, not stdout).`,
44
+ env: (ref) => `akm show ${ref} -> inspect key names; akm env run ${ref} -- <command> -> run with the whole .env injected (prefer --clean to minimize inherited parent env; child stdout is not redacted). akm env export ${ref} --out <file> writes a sourceable script (values to a file, not stdout).`,
44
45
  secret: (ref) => `akm show ${ref} -> name only (value never shown); akm secret path ${ref} -> file path; akm secret run ${ref} <VAR> -- <command> -> run with value injected into $VAR`,
45
46
  wiki: (ref) => `akm show ${ref} -> read the wiki page`,
46
47
  task: (ref) => `akm tasks show ${ref.replace(/^task:/, "")} -> inspect; akm tasks run <id> -> run now; akm tasks remove <id> -> unschedule`,
47
48
  session: (ref) => `akm show ${ref} -> read the session summary; follow the \`access\` frontmatter to open the raw log at \`log_path\``,
49
+ fact: (ref) => `akm show ${ref} -> read the stash fact and apply it as durable context`,
48
50
  };
49
51
  /**
50
52
  * Register a type-to-renderer mapping.
@@ -3,8 +3,10 @@
3
3
  // file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
4
  import path from "node:path";
5
5
  import { buildWorkflowAction } from "../../output/renderers.js";
6
- import { toPosix } from "../common.js";
7
6
  import { registerActionBuilder, registerTypeRenderer } from "./asset-registry.js";
7
+ function toPosix(input) {
8
+ return input.replace(/\\/g, "/");
9
+ }
8
10
  const buildTaskAction = (ref) => `akm tasks show ${ref.replace(/^task:/, "")} -> inspect; akm tasks run <id> -> run now; akm tasks remove <id> -> unschedule`;
9
11
  const markdownSpec = {
10
12
  isRelevantFile: (fileName) => path.extname(fileName).toLowerCase() === ".md",
@@ -89,7 +91,7 @@ const ASSET_SPECS_INTERNAL = {
89
91
  return path.join(typeRoot, name.endsWith(".env") ? name : `${name}.env`);
90
92
  },
91
93
  rendererName: "env-file",
92
- actionBuilder: (ref) => `akm show ${ref} -> inspect key names; akm env run ${ref} -- <command> -> run with the whole .env injected (values never reach stdout); akm env export ${ref} --out <file> -> write a sourceable script to a file`,
94
+ actionBuilder: (ref) => `akm show ${ref} -> inspect key names; akm env run ${ref} -- <command> -> run with the whole .env injected (prefer --clean to minimize inherited parent env; child stdout is not redacted); akm env export ${ref} --out <file> -> write a sourceable script to a file`,
93
95
  },
94
96
  // Secrets — a single sensitive value used on its own for authentication (a
95
97
  // PEM key, API token, TLS cert). Unlike `env` (a group of related .env
@@ -154,6 +156,20 @@ const ASSET_SPECS_INTERNAL = {
154
156
  rendererName: "session-md",
155
157
  actionBuilder: (ref) => `akm show ${ref} -> read the session summary; follow the \`access\` frontmatter to open the raw log at \`log_path\``,
156
158
  },
159
+ // Durable stash-level semantic knowledge — facts about the user, team, or
160
+ // project (personal details, team tool stacks, coding conventions /
161
+ // "constitution", and stash-meta like naming conventions or the active
162
+ // projects list). Unlike `memory` (episodic, recency-decayed) these are
163
+ // mostly-static declarations meant to be reliably surfaced as context. A
164
+ // plain markdown spec; `category` frontmatter scopes the fact and
165
+ // `pinned: true` marks the small always-injected core. See
166
+ // docs/design/fact-asset-type.md.
167
+ fact: {
168
+ stashDir: "facts",
169
+ ...markdownSpec,
170
+ rendererName: "fact-md",
171
+ actionBuilder: (ref) => `akm show ${ref} -> read the stash fact and apply it as durable context`,
172
+ },
157
173
  };
158
174
  export const ASSET_SPECS = ASSET_SPECS_INTERNAL;
159
175
  /**