akm-cli 0.9.0 → 0.9.1-beta.2

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 (140) hide show
  1. package/CHANGELOG.md +724 -0
  2. package/README.md +28 -63
  3. package/STABILITY.md +4 -2
  4. package/dist/cli/parse-args.js +7 -1
  5. package/dist/commands/agent/contribute-cli.js +1 -1
  6. package/dist/commands/env/child-env.js +14 -0
  7. package/dist/commands/feedback-cli.js +7 -1
  8. package/dist/commands/health/llm-usage.js +2 -1
  9. package/dist/commands/health/surfaces.js +4 -77
  10. package/dist/commands/health.js +65 -11
  11. package/dist/commands/improve/distill/quality-gate.js +6 -1
  12. package/dist/commands/improve/eligibility.js +7 -1
  13. package/dist/commands/improve/eval-cases.js +2 -0
  14. package/dist/commands/improve/improve.js +126 -10
  15. package/dist/commands/improve/locks.js +7 -0
  16. package/dist/commands/improve/memory/memory-improve.js +9 -0
  17. package/dist/commands/improve/run-context.js +5 -0
  18. package/dist/commands/improve/session-asset.js +4 -0
  19. package/dist/commands/lint/base-linter.js +31 -7
  20. package/dist/commands/lint/index.js +205 -51
  21. package/dist/commands/lint/types.js +22 -1
  22. package/dist/commands/proposal/repository.js +17 -1
  23. package/dist/commands/sources/add-cli.js +8 -2
  24. package/dist/commands/sources/info.js +12 -2
  25. package/dist/commands/sources/installed-stashes.js +6 -1
  26. package/dist/commands/sources/migration-help.js +12 -3
  27. package/dist/commands/sources/self-update.js +9 -1
  28. package/dist/commands/tasks/tasks.js +8 -2
  29. package/dist/commands/workflow-cli.js +17 -11
  30. package/dist/core/abort-deadline.js +28 -0
  31. package/dist/core/adapter/adapters/agent-skills-adapter.js +83 -5
  32. package/dist/core/adapter/adapters/akm-adapter.js +13 -10
  33. package/dist/core/adapter/adapters/akm-lint.js +78 -22
  34. package/dist/core/adapter/adapters/akm-task-adapter.js +43 -20
  35. package/dist/core/adapter/adapters/dotenv-adapter.js +21 -0
  36. package/dist/core/adapter/adapters/tool-dir-shared.js +5 -3
  37. package/dist/core/asset/frontmatter.js +10 -1
  38. package/dist/core/common.js +147 -9
  39. package/dist/core/concurrent.js +32 -0
  40. package/dist/core/config/config-io.js +5 -45
  41. package/dist/core/config/schema/engines.js +14 -3
  42. package/dist/core/config/schema/workflow.js +11 -0
  43. package/dist/core/errors.js +25 -0
  44. package/dist/core/events.js +30 -24
  45. package/dist/core/extra-params.js +11 -0
  46. package/dist/core/file-lock.js +7 -1
  47. package/dist/core/fs-txn.js +15 -2
  48. package/dist/core/improve-result.js +5 -0
  49. package/dist/core/json-schema.js +344 -9
  50. package/dist/core/loopback.js +89 -0
  51. package/dist/core/migration-operation.js +17 -2
  52. package/dist/core/path-access.js +107 -0
  53. package/dist/core/paths.js +16 -2
  54. package/dist/core/redaction.js +86 -18
  55. package/dist/core/spawn-env.js +234 -0
  56. package/dist/core/state-db-scope.js +134 -0
  57. package/dist/core/state-db.js +1 -0
  58. package/dist/core/subprocess.js +181 -37
  59. package/dist/core/write-provenance.js +85 -0
  60. package/dist/core/write-source.js +33 -2
  61. package/dist/indexer/db/graph-db.js +17 -6
  62. package/dist/indexer/ensure-index.js +10 -3
  63. package/dist/indexer/index-written-assets.js +17 -2
  64. package/dist/indexer/indexer.js +86 -21
  65. package/dist/indexer/passes/memory-inference.js +4 -0
  66. package/dist/indexer/search/db-search.js +25 -17
  67. package/dist/indexer/walk/walker.js +6 -1
  68. package/dist/integrations/agent/detect.js +13 -1
  69. package/dist/integrations/agent/engine-resolution.js +24 -11
  70. package/dist/integrations/agent/model-aliases.js +1 -1
  71. package/dist/integrations/agent/profiles.js +9 -1
  72. package/dist/integrations/agent/spawn.js +15 -87
  73. package/dist/integrations/harnesses/opencode-sdk/sdk-runner.js +21 -0
  74. package/dist/integrations/lockfile.js +55 -2
  75. package/dist/llm/client.js +14 -19
  76. package/dist/llm/embedder.js +23 -3
  77. package/dist/llm/embedders/remote.js +27 -2
  78. package/dist/output/html-render.js +40 -1
  79. package/dist/output/text/lint-format.js +17 -4
  80. package/dist/runtime.js +23 -1
  81. package/dist/scripts/akm-migrate-node.js +1714 -836
  82. package/dist/scripts/akm-migrate.js +1682 -804
  83. package/dist/setup/setup.js +22 -7
  84. package/dist/sources/providers/git-install.js +25 -2
  85. package/dist/sources/providers/git-stash.js +19 -0
  86. package/dist/sources/providers/git.js +1 -1
  87. package/dist/sources/snapshot-fetchers/content-extract.js +63 -1
  88. package/dist/sources/snapshot-fetchers/website-ingest.js +126 -20
  89. package/dist/storage/database.js +71 -7
  90. package/dist/storage/engines/sqlite-migrations.js +61 -2
  91. package/dist/storage/managed-db.js +19 -0
  92. package/dist/storage/repositories/index-connection.js +39 -4
  93. package/dist/storage/repositories/index-entries-repository.js +6 -1
  94. package/dist/storage/repositories/index-meta-repository.js +11 -0
  95. package/dist/storage/repositories/index-schema.js +17 -2
  96. package/dist/storage/repositories/index-vec-repository.js +43 -5
  97. package/dist/storage/repositories/workflow-runs-repository.js +66 -13
  98. package/dist/storage/sqlite-pragmas.js +12 -1
  99. package/dist/tasks/log-redaction.js +156 -0
  100. package/dist/tasks/parser.js +82 -5
  101. package/dist/tasks/runner.js +222 -17
  102. package/dist/tasks/scheduler-invocation.js +19 -0
  103. package/dist/tasks/schema.js +86 -1
  104. package/dist/text-import-hook.mjs +1 -1
  105. package/dist/workflows/concurrency-policy.js +95 -1
  106. package/dist/workflows/exec/dispatch-redaction.js +114 -0
  107. package/dist/workflows/exec/exec-unit.js +542 -0
  108. package/dist/workflows/exec/frozen-judge.js +114 -42
  109. package/dist/workflows/exec/native-executor.js +465 -238
  110. package/dist/workflows/exec/param-secrets.js +4 -3
  111. package/dist/workflows/exec/run-workflow.js +424 -219
  112. package/dist/workflows/exec/step-work.js +506 -167
  113. package/dist/workflows/exec/unit-dispatch.js +31 -1
  114. package/dist/workflows/exec/unit-writer.js +53 -13
  115. package/dist/workflows/exec/worktree.js +454 -41
  116. package/dist/workflows/ir/compile.js +26 -2
  117. package/dist/workflows/ir/freeze.js +82 -15
  118. package/dist/workflows/ir/schema.js +105 -20
  119. package/dist/workflows/parser.js +242 -19
  120. package/dist/workflows/program/schema.js +24 -0
  121. package/dist/workflows/renderer.js +32 -4
  122. package/dist/workflows/resource-limits.js +182 -0
  123. package/dist/workflows/runtime/runs.js +146 -6
  124. package/dist/workflows/validate-summary.js +17 -2
  125. package/docs/README.md +74 -32
  126. package/docs/migration/release-notes/0.9.0.md +2 -1
  127. package/docs/migration/v0.7-to-v0.8.md +2 -1
  128. package/docs/migration/v0.8-to-v0.9.md +3 -1
  129. package/docs/reference/README.md +11 -4
  130. package/docs/reference/bundle-types.md +19 -0
  131. package/docs/reference/cli.md +105 -16
  132. package/docs/reference/configuration.md +15 -2
  133. package/docs/reference/data-and-telemetry.md +30 -10
  134. package/docs/reference/supported-formats.md +50 -0
  135. package/docs/reference/workflow-schema.md +1014 -0
  136. package/docs/reference/workflows.md +37 -633
  137. package/package.json +13 -6
  138. package/schemas/akm-config.json +18 -5
  139. package/schemas/akm-task.json +27 -5
  140. package/schemas/akm-workflow.json +92 -13
@@ -1,4 +1,34 @@
1
1
  // This Source Code Form is subject to the terms of the Mozilla Public
2
2
  // License, v. 2.0. If a copy of the MPL was not distributed with this
3
3
  // file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
- export {};
4
+ import { deepMergeConfig } from "../../core/config/deep-merge.js";
5
+ import { resolveCredentialFromEnv } from "../../integrations/agent/engine-resolution.js";
6
+ /**
7
+ * Materialize a frozen llm engine snapshot into a live connection: resolve the
8
+ * credential out of `process.env`, then apply the invocation's model/llm
9
+ * overrides. The ONE definition — the default dispatcher's llm runner and the
10
+ * frozen gate judge both dispatch through it, so credential resolution and
11
+ * connection-field mapping cannot drift between the two llm dispatch paths.
12
+ *
13
+ * The credential read itself is {@link resolveCredentialFromEnv}, shared with
14
+ * the live-config dispatch boundary (`materializeLlmConnection`): a frozen
15
+ * snapshot's `credential` and a resolved engine's `CredentialDescriptor` are the
16
+ * same descriptor, so lookup order and the "required … is not set" failure are
17
+ * one implementation, not two that happen to agree.
18
+ */
19
+ export function materializeFrozenLlm(snapshot, invocation) {
20
+ const apiKey = resolveCredentialFromEnv(snapshot.credential);
21
+ const base = {
22
+ provider: snapshot.provider,
23
+ endpoint: snapshot.endpoint,
24
+ model: invocation?.model ?? snapshot.model,
25
+ ...(snapshot.temperature !== undefined ? { temperature: snapshot.temperature } : {}),
26
+ ...(snapshot.maxTokens !== undefined ? { maxTokens: snapshot.maxTokens } : {}),
27
+ ...(snapshot.supportsJsonSchema !== undefined ? { supportsJsonSchema: snapshot.supportsJsonSchema } : {}),
28
+ ...(snapshot.extraParams ? { extraParams: snapshot.extraParams } : {}),
29
+ ...(snapshot.contextLength !== undefined ? { contextLength: snapshot.contextLength } : {}),
30
+ ...(snapshot.enableThinking !== undefined ? { enableThinking: snapshot.enableThinking } : {}),
31
+ ...(apiKey ? { apiKey } : {}),
32
+ };
33
+ return invocation?.llm ? deepMergeConfig(base, invocation.llm) : base;
34
+ }
@@ -5,19 +5,59 @@
5
5
  * Serialized writer queue for `workflow_run_units` (orchestration plan,
6
6
  * *Persistence changes*).
7
7
  *
8
- * `withWorkflowRunsRepo` opens a fresh SQLite connection per call, so N
9
- * parallel units completing at once would contend on SQLite's single writer
10
- * and burn the 30 s busy_timeout. Bun is single-threaded, so a promise-chained
11
- * in-process queue is sufficient: every unit write is appended to one chain
12
- * and executes strictly in enqueue order. Reads and gate evaluation stay OFF
13
- * this queue only writes serialize.
14
- *
15
- * A failed write rejects its own caller but never wedges the chain.
8
+ * ## What the chain actually protects
9
+ *
10
+ * SQLite allows exactly ONE writer per database FILE. Outside a
11
+ * `withWorkflowRunsConnection` scope, `withWorkflowRunsRepo` opens a fresh
12
+ * connection per call, so N units completing at once would be N separate
13
+ * connections racing for the same file's write lock, burning the 30 s
14
+ * `busy_timeout` on contention we created ourselves. Bun runs a single-threaded
15
+ * event loop, so an in-process promise chain is a sufficient (and free)
16
+ * admission control: every unit write executes strictly in enqueue order.
17
+ *
18
+ * That is the ONLY invariant the chain owns. In particular it does NOT own
19
+ * per-unit insert→finish ordering: `dispatchJournaledAttempt` awaits its insert
20
+ * before it dispatches and only finishes after the dispatch resolves, so a
21
+ * unit's own writes are ordered by program order, not by queue position. The
22
+ * queue could be reordered arbitrarily between units without breaking
23
+ * `finishUnitFromDispatch`'s row-conditional logic.
24
+ *
25
+ * ## Scope of the serialization (issue B)
26
+ *
27
+ * The chain is keyed by DATABASE PATH, not global, because the resource being
28
+ * protected is one SQLite file's write lock. Two runs against two different
29
+ * data dirs (`AKM_DATA_DIR` isolation, a test sandbox, a second stash) share no
30
+ * write lock and must not queue behind each other. Narrowing further — per run
31
+ * — would be unsound: two runs in the SAME state.db still contend for that one
32
+ * file's writer, which is precisely what the chain exists to avoid.
33
+ *
34
+ * Inside a `withWorkflowRunsConnection` scope the chain also becomes nearly
35
+ * free: every write goes through the same handle, so each queued task is a
36
+ * synchronous statement (or a synchronous `BEGIN IMMEDIATE … COMMIT`) that
37
+ * settles in microseconds rather than a per-call open/migrate-preflight/close.
38
+ * The queue depth stops gating unit completion in practice, without weakening
39
+ * anything.
40
+ *
41
+ * Reads and gate evaluation stay OFF this queue — only writes serialize.
42
+ *
43
+ * A failed write rejects its own caller but never wedges its chain.
44
+ */
45
+ import { serializeByKey } from "../../core/concurrent.js";
46
+ import { getStateDbPath } from "../../core/state-db.js";
47
+ /**
48
+ * One promise chain per database path ({@link serializeByKey}). Entries are
49
+ * pruned when their chain drains, so a long-lived process that touches many
50
+ * data dirs (the test harness swaps `AKM_DATA_DIR` per test) does not
51
+ * accumulate one resolved promise per path forever.
52
+ */
53
+ const chains = new Map();
54
+ /**
55
+ * Enqueue a `workflow_run_units` write behind every write already queued for
56
+ * the same state.db. The key is the current state.db path — the file whose one
57
+ * write lock this exists to protect — and is not a caller's choice: a caller
58
+ * writing somewhere else is not on this queue at all, and wants
59
+ * {@link serializeByKey} with its own chain map.
16
60
  */
17
- let tail = Promise.resolve();
18
61
  export function enqueueUnitWrite(fn) {
19
- const run = tail.then(() => fn());
20
- // Keep the chain alive regardless of individual outcomes.
21
- tail = run.then(() => undefined, () => undefined);
22
- return run;
62
+ return serializeByKey(chains, getStateDbPath(), fn);
23
63
  }