akm-cli 0.9.0-rc.2 → 0.9.0-rc.4

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 (115) hide show
  1. package/CHANGELOG.md +40 -12
  2. package/README.md +7 -8
  3. package/SECURITY.md +5 -3
  4. package/dist/akm +44 -33
  5. package/dist/akm-migrate-storage +44 -33
  6. package/dist/assets/backends/schtasks-template.xml +2 -1
  7. package/dist/assets/improve-strategies/catchup.json +3 -1
  8. package/dist/assets/improve-strategies/consolidate.json +3 -1
  9. package/dist/assets/improve-strategies/frequent.json +3 -1
  10. package/dist/assets/improve-strategies/graph-refresh.json +3 -1
  11. package/dist/assets/improve-strategies/memory-focus.json +4 -1
  12. package/dist/assets/improve-strategies/proactive-maintenance.json +1 -0
  13. package/dist/assets/improve-strategies/quick.json +3 -1
  14. package/dist/assets/improve-strategies/recombine-only.json +2 -0
  15. package/dist/assets/improve-strategies/reflect-distill.json +1 -0
  16. package/dist/assets/improve-strategies/synthesize.json +2 -0
  17. package/dist/assets/tasks/core/backup.yml +2 -2
  18. package/dist/cli/config-migrate.js +554 -26
  19. package/dist/cli.js +28 -11
  20. package/dist/commands/backup-cli.js +6 -4
  21. package/dist/commands/config-cli.js +10 -3
  22. package/dist/commands/feedback-cli.js +24 -7
  23. package/dist/commands/health/checks.js +94 -15
  24. package/dist/commands/health/html-report.js +23 -2
  25. package/dist/commands/health/improve-metrics.js +45 -6
  26. package/dist/commands/health/md-report.js +10 -1
  27. package/dist/commands/health/surfaces.js +2 -1
  28. package/dist/commands/health/windows.js +1 -1
  29. package/dist/commands/health.js +1 -1
  30. package/dist/commands/improve/anti-collapse.js +3 -3
  31. package/dist/commands/improve/collapse-detector.js +5 -5
  32. package/dist/commands/improve/consolidate.js +123 -66
  33. package/dist/commands/improve/distill/promote-memory.js +8 -6
  34. package/dist/commands/improve/distill/quality-gate.js +1 -1
  35. package/dist/commands/improve/distill-guards.js +1 -1
  36. package/dist/commands/improve/distill-promotion-policy.js +32 -26
  37. package/dist/commands/improve/distill.js +52 -36
  38. package/dist/commands/improve/eligibility.js +9 -8
  39. package/dist/commands/improve/extract-prompt.js +2 -2
  40. package/dist/commands/improve/extract.js +43 -11
  41. package/dist/commands/improve/improve-auto-accept.js +14 -28
  42. package/dist/commands/improve/improve-cli.js +4 -2
  43. package/dist/commands/improve/improve-strategies.js +2 -1
  44. package/dist/commands/improve/improve.js +49 -8
  45. package/dist/commands/improve/loop-stages.js +11 -6
  46. package/dist/commands/improve/preparation.js +51 -17
  47. package/dist/commands/improve/procedural.js +10 -6
  48. package/dist/commands/improve/recombine.js +31 -7
  49. package/dist/commands/improve/reflect.js +24 -14
  50. package/dist/commands/improve/salience.js +5 -1
  51. package/dist/commands/improve/source-identity.js +43 -0
  52. package/dist/commands/migrate-cli.js +36 -0
  53. package/dist/commands/mv-cli.js +647 -258
  54. package/dist/commands/proposal/drain.js +16 -4
  55. package/dist/commands/proposal/proposal-cli.js +3 -2
  56. package/dist/commands/proposal/proposal.js +16 -55
  57. package/dist/commands/proposal/repository.js +664 -58
  58. package/dist/commands/read/curate.js +4 -2
  59. package/dist/commands/read/knowledge.js +4 -1
  60. package/dist/commands/read/search.js +6 -2
  61. package/dist/commands/read/show.js +8 -7
  62. package/dist/commands/sources/self-update.js +156 -112
  63. package/dist/commands/sources/sources-cli.js +7 -2
  64. package/dist/commands/tasks/default-tasks.js +5 -5
  65. package/dist/commands/tasks/tasks-cli.js +7 -3
  66. package/dist/commands/tasks/tasks.js +261 -68
  67. package/dist/core/common.js +36 -3
  68. package/dist/core/config/config-io.js +2 -2
  69. package/dist/core/config/config-schema.js +15 -3
  70. package/dist/core/config/config.js +14 -13
  71. package/dist/core/file-lock.js +2 -2
  72. package/dist/core/improve-result.js +87 -7
  73. package/dist/core/migration-backup.js +816 -171
  74. package/dist/core/migration-operation.js +44 -0
  75. package/dist/core/state/migrations.js +4 -7
  76. package/dist/core/state-db.js +23 -7
  77. package/dist/core/write-source.js +86 -18
  78. package/dist/indexer/db/db.js +109 -53
  79. package/dist/indexer/index-writer-lock.js +38 -37
  80. package/dist/indexer/index-written-assets.js +73 -56
  81. package/dist/indexer/indexer.js +5 -1
  82. package/dist/indexer/search/search-source.js +2 -2
  83. package/dist/indexer/usage/usage-events.js +8 -2
  84. package/dist/integrations/agent/engine-resolution.js +14 -7
  85. package/dist/scripts/migrate-storage.js +887 -992
  86. package/dist/scripts/migrations/import-fs-improve-runs-to-db.js +494 -574
  87. package/dist/setup/detected-engines.js +7 -13
  88. package/dist/setup/engine-config.js +14 -4
  89. package/dist/setup/setup.js +1 -1
  90. package/dist/setup/steps/connection.js +1 -1
  91. package/dist/setup/steps/tasks.js +1 -1
  92. package/dist/sources/providers/git-stash.js +58 -21
  93. package/dist/sources/providers/git.js +1 -1
  94. package/dist/storage/engines/sqlite-migrations.js +138 -3
  95. package/dist/storage/repositories/events-repository.js +24 -0
  96. package/dist/storage/repositories/proposals-repository.js +14 -0
  97. package/dist/storage/repositories/task-history-repository.js +30 -3
  98. package/dist/tasks/backends/cron.js +71 -38
  99. package/dist/tasks/backends/exec-utils.js +55 -3
  100. package/dist/tasks/backends/launchd.js +241 -50
  101. package/dist/tasks/backends/schtasks.js +434 -59
  102. package/dist/tasks/command-executable.js +93 -0
  103. package/dist/tasks/embedded.js +2 -0
  104. package/dist/tasks/parser.js +142 -6
  105. package/dist/tasks/resolve-akm-bin.js +19 -4
  106. package/dist/tasks/runner.js +258 -93
  107. package/dist/tasks/schedule.js +108 -19
  108. package/dist/tasks/scheduler-invocation.js +86 -0
  109. package/dist/tasks/task-id.js +37 -0
  110. package/dist/workflows/db.js +24 -13
  111. package/dist/workflows/validator.js +24 -2
  112. package/docs/README.md +103 -0
  113. package/docs/migration/release-notes/0.9.0.md +28 -9
  114. package/docs/migration/v0.8-to-v0.9.md +186 -26
  115. package/package.json +2 -3
@@ -8,18 +8,109 @@ installation, then migrate the affected assets deliberately.
8
8
 
9
9
  ## Engine And Task Assets
10
10
 
11
- Before editing a 0.8 configuration, create a recovery bundle:
11
+ The 0.8 binary does not contain `akm migrate` or the
12
+ `upgrade --migration-config` contract. Do not attempt to invoke either command
13
+ with 0.8, and do not use 0.8 self-update to cross this boundary.
14
+
15
+ Use this package-manager/manual boundary procedure instead:
16
+
17
+ 1. Stop AKM writers, schedulers, and workflow drivers.
18
+ 2. Prepare the complete 0.9 config in a separate file. Do not replace the live
19
+ 0.8 config; AKM cannot infer names when old LLM and agent profiles collide.
20
+ 3. Take an independent filesystem backup of the live 0.8 `config.json`,
21
+ `state.db`, and `workflow.db` (including any SQLite `-wal`/`-shm` files).
22
+ Store it outside AKM's data directory and verify it before continuing.
23
+ 4. Install 0.9 with the package manager, or download, checksum, and stage the
24
+ 0.9 standalone binary. A package-manager install replaces the managed 0.8
25
+ package; a standalone operator should retain the old executable. Keep the
26
+ independent data backup in either case.
27
+ 5. Invoke the newly installed or staged 0.9 binary, whose migration startup
28
+ bypass can read the old installation without loading its config normally.
29
+ 6. After apply succeeds, run `akm tasks sync` with that same 0.9 binary and
30
+ inspect `skipped` before restarting schedulers. Sync registers the migrated
31
+ task view and quarantines the obsolete published backup task described below.
32
+
33
+ Package-manager installation examples for step 4:
34
+
35
+ Package-manager installs require Node.js >= 20.12. If Bun >= 1.0 is also on
36
+ `PATH`, the installed launcher prefers Bun after Node.js bootstraps it.
12
37
 
13
38
  ```sh
14
- akm backup create --for 0.9.0
39
+ npm install -g akm-cli@0.9.0
40
+ # or: pnpm add -g akm-cli@0.9.0
15
41
  ```
16
42
 
17
- The immutable bundle is stored under `$CACHE/migration-backups/0.9.0`
18
- (`$XDG_CACHE_HOME/akm` by default on Linux). It records both present and absent files for
19
- `config.json`, `state.db`, and `workflow.db`, verifies every captured file by
20
- SHA-256, and is created automatically before AKM first opens either canonical
21
- durable database for the 0.9 engine migrations. Do not move individual files
22
- into or out of the bundle; verification fails closed on any mismatch.
43
+ Commands for steps 5 and 6:
44
+
45
+ ```sh
46
+ # Package-manager install: this `akm` is now the 0.9 binary.
47
+ akm migrate status --config ./prepared-0.9.json
48
+ akm migrate apply --config ./prepared-0.9.json --dry-run
49
+ akm migrate apply --config ./prepared-0.9.json
50
+ akm tasks sync
51
+
52
+ # Or invoke a checksummed staged standalone binary explicitly.
53
+ ./akm-0.9 migrate status --config ./prepared-0.9.json
54
+ ./akm-0.9 migrate apply --config ./prepared-0.9.json
55
+ ./akm-0.9 tasks sync
56
+ ```
57
+
58
+ Status and dry-run perform the same read-only eligibility checks and report the
59
+ source config plus target config explicitly. Apply validates the target in
60
+ memory, creates a verified recovery run, applies pending `state.db` and
61
+ `workflow.db` migrations one transaction at a time, and atomically installs the
62
+ prepared config last. If any later artifact fails, apply restores config and
63
+ both databases from the verified run before returning. Each artifact is
64
+ classified independently, so a current config with pre-cutover databases can be
65
+ recovered safely.
66
+
67
+ Apply records durable `prepared`, `state-applied`, `workflow-applied`,
68
+ `config-applied`, `rollback-prepared`, and `committed` phases. Every phase stores
69
+ streaming size/SHA fingerprints for config, both databases, and SQLite sidecars;
70
+ a resume or rollback first requires the exact live generation. After a process
71
+ crash, ordinary config and canonical database access fail closed; `akm migrate
72
+ status` reports the pending phase and `akm migrate apply` resumes idempotently
73
+ from the retained target and verified backup. Apply also refuses before backup
74
+ while managed database handles, maintenance activities, AKM mutation locks, or
75
+ workflow claims are live.
76
+
77
+ Canonical state/workflow opens check for pending recovery both before and after
78
+ registering their maintenance activity. Config writers perform the second check
79
+ while holding the same config lock used by migration, closing the check/start
80
+ race without recreating files or accepting a write.
81
+
82
+ Each database mutation also writes an operation-specific generation marker in
83
+ the migration transaction. If the process dies after the durable mutation but
84
+ before advancing the apply journal, recovery accepts only that authenticated
85
+ one-artifact adjacent generation while every unaffected fingerprint remains
86
+ exact. Config adjacency is authenticated against the exact serialized target.
87
+ If rollback restore commits before the apply journal is removed, the next apply
88
+ authenticates the live files against the backup generation and removes only the
89
+ stale apply journal.
90
+
91
+ Once already running a contract-capable 0.9 release, future self-upgrades may
92
+ pass a prepared target through the coordinated upgrade path:
93
+
94
+ ```sh
95
+ akm upgrade --migration-config ./prepared-0.9.json
96
+ ```
97
+
98
+ This command is not the 0.8-to-0.9 procedure. The already-installed 0.8 binary
99
+ cannot contain or enforce safeguards added in 0.9, so operators must follow the
100
+ manual boundary above rather than relying on 0.8 self-update. For 0.9+ upgrades,
101
+ the current binary preflights only its current artifact state; it does not parse
102
+ a prepared config for the future release. After installation, only the new
103
+ binary receives `--config` during apply. If the active config is already current,
104
+ no migration-config flag is needed.
105
+
106
+ Recovery runs are stored under
107
+ `$DATA/backups/migrations/<installation-id>/<run-id>/`. They record present and
108
+ absent `config.json`, `state.db`, and `workflow.db` artifacts, ordered migration
109
+ ledgers, sizes, and streaming SHA-256 hashes. SQLite snapshots must also pass
110
+ `PRAGMA quick_check` and ledger-prefix validation before the manifest is
111
+ published. `akm backup create --for 0.9.0` creates an additional unique run when
112
+ an operator wants a manual snapshot. Routine config writes, telemetry, and
113
+ already-current database opens do not depend on any historical run.
23
114
 
24
115
  Replace `profiles.llm.<name>` and `profiles.agent.<name>` with one
25
116
  `engines.<name>` map. Replace `defaults.llm`, `defaults.agent`, and
@@ -31,8 +122,10 @@ Replace `profiles.llm.<name>` and `profiles.agent.<name>` with one
31
122
  Do not reuse a colliding LLM and agent profile name without deciding which new
32
123
  engine names make the distinction clear. AKM cannot safely infer that choice.
33
124
 
34
- Task files are strict YAML v2. Add `version: 2`, replace prompt `profile:` with
35
- `engine:`, and retain only fields valid for the target:
125
+ New task files use strict YAML v2. Existing valid 0.8 task files continue to
126
+ load without being rewritten: AKM normalizes their missing/`1` version,
127
+ prompt `profile:` field, permissive scalar forms, and `akm improve --profile`
128
+ commands in memory. Update user-authored files to `version: 2` when editing them:
36
129
 
37
130
  ```yaml
38
131
  version: 2
@@ -46,11 +139,55 @@ enabled: true
46
139
 
47
140
  Prompt tasks may use `engine`, `model`, `timeoutMs`, and `llm`; command tasks
48
141
  may use `timeoutMs`; workflow tasks may use `params`. Unknown and wrong-target
49
- keys are errors. `akm tasks list`, `sync`, and `doctor` report stale v1 files;
50
- `show`, `run`, `enable`, and `disable` reject them without mutation. Regenerate
51
- the known default improve tasks or replace `akm improve --profile <name>` with
52
- `akm improve --strategy <name>` yourself. AKM never rewrites arbitrary shell
53
- commands.
142
+ keys are errors in v2. Unsupported future versions are reported by `akm tasks
143
+ list`, `sync`, and `doctor`. The 0.8 reader normalization changes only the
144
+ removed AKM spellings; arbitrary shell commands and task files are never
145
+ rewritten.
146
+
147
+ For 0.8 command tasks, syntax migration and self-invocation routing are separate.
148
+ `--profile` is lowered only for a PATH-selected bare `akm`/`akm.exe`, including
149
+ when it follows supported `env` options and assignments. The scanner recognizes
150
+ citty-valid global forms before `improve`, including `--no-quiet`,
151
+ `--no-verbose`, `--quiet=false`, `--verbose=false`, and value options such as
152
+ `--format json`. An explicit `./akm`, `/opt/vendor/akm`, or other executable path
153
+ is operator-owned: it keeps selecting that exact binary and its command argv is
154
+ retained exactly. In particular, AKM does not change syntax sent to a retained
155
+ 0.8 binary. Version-2 commands receive no compatibility rewriting.
156
+
157
+ The published 0.8 core `backup.yml` is a special unsafe legacy definition. It
158
+ was enabled and ran `akm db backups`, but that command only listed snapshots; it
159
+ did not create a recurring backup. In 0.9, `tasks add` refuses the enabled exact
160
+ bare-self command before changing its source file or scheduler. `tasks sync`
161
+ reports it in `skipped`, does not install a missing entry, and disables an
162
+ existing scheduler entry while preserving the task file byte-for-byte. `tasks
163
+ enable` also refuses to re-enable it. This quarantine applies only when bare
164
+ `akm`/`akm.exe` is followed by exactly `db backups`; an explicit executable path
165
+ is operator-owned and is not quarantined. Use `akm backup create --for 0.9.0`
166
+ for an explicit migration recovery snapshot. Existing 0.8 data-directory backup
167
+ folders are left untouched by migration.
168
+
169
+ Task `enabled` state controls scheduler-originated execution, not explicit
170
+ operator invocation. `akm tasks run <id>` intentionally runs a disabled task so
171
+ manual catch-up definitions remain useful. Backend-generated invocations carry
172
+ the internal `--scheduled` marker and record a `disabled` result without running
173
+ the target. Do not use the manual command as a scheduler replacement.
174
+
175
+ Canonical task IDs contain only letters, digits, dots, underscores, and dashes,
176
+ start with a letter or digit, are at most 228 characters, omit `.yml`/`.yaml`,
177
+ and cannot use Windows device aliases such as `CON`, `NUL`, `COM1`, or `LPT1`
178
+ (including aliases followed by a dot). The 228-character limit is the final
179
+ portable bound after scheduler and filename overhead. These portability checks
180
+ apply on every platform. For command-line compatibility only, a trailing
181
+ lowercase `.yml` or legacy `.md` is stripped from an ID; a filename discovered
182
+ under `tasks/` must already be canonical and is never renamed. Sync skips a
183
+ non-portable file and disables any matching installed entry rather than guessing
184
+ a replacement ID.
185
+
186
+ Canonical migration preserves 0.8 `state.db` task-history rows and their log
187
+ paths. One historical detail cannot be recovered: published 0.8.14 stored
188
+ command-task history with `target_kind=prompt`. Because the durable row contains
189
+ no command marker, 0.9 preserves and exposes it as legacy prompt history rather
190
+ than inventing a command classification. New runs use the correct target kind.
54
191
 
55
192
  ## CLI rename table (old → new, removed 0.9.0)
56
193
 
@@ -374,19 +511,42 @@ workflow lease exists. Then, while still running the 0.9 binary, restore the
374
511
  complete pre-cutover snapshot:
375
512
 
376
513
  ```sh
377
- akm backup restore --for 0.9.0 --confirm
514
+ akm backup restore --for 0.9.0 --run <run-id> --confirm
378
515
  ```
379
516
 
380
- Restore verifies the manifest, permissions, sizes, and checksums before
381
- replacing anything. It restores each original file and removes a canonical DB
382
- that the manifest recorded as originally absent, including its WAL/SHM
383
- sidecars. Restore also holds the global maintenance barrier from its last
384
- lock/lease check through replacement, so a new index writer, improve/extract
385
- lock, lockfile writer, or workflow engine lease cannot start in that window.
386
- The recovery bundle itself remains in `$CACHE` for repeatable recovery. If
387
- verification reports corruption, preserve the bundle and recover
388
- from an independent backup; do not delete the manifest or regenerate it from a
389
- post-cutover config.
517
+ Restore verifies the selected run before changing live files and then creates a
518
+ second verified rescue run of the current installation. It stages every
519
+ replacement beside its destination, writes a durable restore journal,
520
+ quarantines each database together with its WAL/SHM sidecars, and only then
521
+ publishes clean staged files. The journal records a durable committed phase
522
+ before cleanup: an earlier interruption rolls back, while an interruption after
523
+ commit finishes cleanup without mixing generations. While either recovery phase
524
+ is pending, ordinary config and canonical database access fail closed before
525
+ accepting writes or recreating absent files. The selected and rescue runs remain
526
+ under `$DATA`; if verification reports corruption, preserve them and recover
527
+ from an independent backup.
528
+
529
+ Recovery validates the complete restore journal before removing or renaming any
530
+ path: journal format and migration version, phase, exact artifact and SQLite
531
+ sidecar set, operation-bound stage/quarantine names, path uniqueness, source
532
+ backup, and the expected prepared/committed filesystem state. A malformed or
533
+ stale journal remains in place and recovery fails closed for operator diagnosis.
534
+ Committed recovery additionally authenticates each published artifact against
535
+ the selected backup's byte size and streaming SHA-256, then reruns config-state
536
+ validation or SQLite `quick_check` and ledger validation before deleting any
537
+ quarantine or journal.
538
+
539
+ Prepared rollback is itself crash-idempotent. The journal fingerprints the
540
+ original config/database/sidecar generation before quarantine. If recovery dies
541
+ after restoring a quarantine or deleting a stage but before journal deletion,
542
+ the next recovery authenticates the already-restored destination and continues
543
+ cleanup. A same-ledger but byte-different substitution fails closed.
544
+
545
+ Migration config files, manifests, and apply/restore journals are read through
546
+ bounded readers (1 MiB each). Oversized local control files fail closed rather
547
+ than being loaded wholesale. Apply also measures the complete serialized journal
548
+ before its first write; a near-limit config whose expanded target would exceed
549
+ the same cap is rejected before any apply journal or artifact mutation.
390
550
 
391
551
  Only after restore succeeds should you install the older AKM binary. A 0.8
392
552
  binary must not run against a 0.9 config or against `state.db` migration 017 /
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akm-cli",
3
- "version": "0.9.0-rc.2",
3
+ "version": "0.9.0-rc.4",
4
4
  "type": "module",
5
5
  "description": "akm (Agent Knowledge Management) — A package manager for AI agent skills, commands, tools, and knowledge. Works with Claude Code, OpenCode, Cursor, and any AI coding assistant.",
6
6
  "keywords": [
@@ -52,7 +52,7 @@
52
52
  "akm-migrate-storage": "dist/akm-migrate-storage"
53
53
  },
54
54
  "scripts": {
55
- "preinstall": "node -e \"var ua=process.env.npm_config_user_agent||'';var v=(process.versions.node||'0').split('.').map(function(n){return parseInt(n,10)||0});var ok=v[0]>20||(v[0]===20&&(v[1]>12||(v[1]===12&&v[2]>=0)));if(process.versions.bun||ua.startsWith('bun/')||process.env.BUN_INSTALL||ok){process.exit(0)}console.error('\\n ERROR: akm-cli requires the Bun runtime (https://bun.sh), Node.js >= 20.12, or the prebuilt binary.\\n Install options:\\n 1. Bun: curl -fsSL https://bun.sh/install | bash && bun install -g akm-cli\\n 2. Node: upgrade to Node.js 20.12 or newer (https://nodejs.org)\\n 3. Binary: curl -fsSL https://github.com/itlackey/akm/releases/latest/download/install.sh | bash\\n');process.exit(1)\"",
55
+ "preinstall": "node -e \"var v=(process.versions.node||'0').split('.').map(function(n){return parseInt(n,10)||0});var ok=v[0]>20||(v[0]===20&&(v[1]>12||(v[1]===12&&v[2]>=0)));if(ok){process.exit(0)}console.error('\\n ERROR: the akm-cli npm package requires Node.js >= 20.12.\\n A working Bun >= 1.0 on PATH is optional and preferred for execution.\\n Upgrade Node.js (https://nodejs.org), or install the runtime-free standalone binary:\\n curl -fsSL https://github.com/itlackey/akm/releases/latest/download/install.sh | bash\\n');process.exit(1)\"",
56
56
  "build": "rm -rf dist && bun scripts/gen-config-schema.ts &&bun run tsc --project ./tsconfig.build.json && bun scripts/copy-assets.ts && bun scripts/fix-esm-extensions.ts",
57
57
  "check": "bun run lint && bunx tsc --noEmit && bun run test:unit && bun run test:integration",
58
58
  "check:fast": "bun run lint && bunx tsc --noEmit && bun run test:unit",
@@ -94,7 +94,6 @@
94
94
  "sqlite-vec": "^0.1.9"
95
95
  },
96
96
  "engines": {
97
- "bun": ">=1.0.0",
98
97
  "node": ">=20.12.0"
99
98
  },
100
99
  "dependencies": {