akm-cli 0.9.4 → 0.9.6
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.
- package/CHANGELOG.md +265 -0
- package/dist/commands/env/env-cli.js +1 -2
- package/dist/commands/env/secret-cli.js +1 -5
- package/dist/commands/feedback-cli.js +0 -4
- package/dist/commands/health/checks.js +0 -32
- package/dist/commands/health/surfaces.js +2 -2
- package/dist/commands/health.js +6 -15
- package/dist/commands/improve/anti-collapse.js +4 -91
- package/dist/commands/improve/autonomy-gate.js +1 -1
- package/dist/commands/improve/consolidate.js +25 -26
- package/dist/commands/improve/distill.js +2 -2
- package/dist/commands/improve/extract.js +8 -1
- package/dist/commands/improve/improve.js +3 -5
- package/dist/commands/improve/locks.js +13 -5
- package/dist/commands/improve/loop-stages.js +8 -9
- package/dist/commands/improve/memory/memory-contradiction-detect.js +1 -19
- package/dist/commands/improve/outcome-loop.js +0 -6
- package/dist/commands/improve/reflect.js +20 -9
- package/dist/commands/lint/index.js +4 -6
- package/dist/commands/proposal/validators/proposal-quality-validators.js +0 -7
- package/dist/commands/proposal/validators/proposal-validators.js +12 -0
- package/dist/commands/read/search.js +14 -24
- package/dist/commands/sources/bundle-config-ops.js +9 -4
- package/dist/commands/sources/info.js +14 -10
- package/dist/commands/tasks/tasks-cli.js +56 -3
- package/dist/commands/tasks/tasks.js +101 -18
- package/dist/commands/workflow-cli.js +2 -2
- package/dist/core/adapter/adapters/akm-adapter.js +2 -0
- package/dist/core/common.js +61 -24
- package/dist/core/config/config-io.js +2 -2
- package/dist/core/config/config-sources.js +32 -2
- package/dist/core/config/config-version-shim.js +101 -0
- package/dist/core/config/config.js +7 -7
- package/dist/core/config/schema/engines.js +9 -7
- package/dist/core/config/schema/primitives.js +0 -5
- package/dist/core/config/schema/search.js +2 -1
- package/dist/core/file-lock.js +2 -1
- package/dist/core/improve-result.js +35 -14
- package/dist/core/maintenance-barrier.js +2 -14
- package/dist/core/paths.js +0 -3
- package/dist/core/redaction.js +2 -2
- package/dist/core/spawn-env.js +8 -12
- package/dist/core/state/migrations.js +1 -12
- package/dist/core/state-db.js +9 -27
- package/dist/core/write-source.js +12 -19
- package/dist/execution/directory-identity.js +36 -10
- package/dist/execution/guarded-source.js +0 -10
- package/dist/indexer/graph/graph-boost.js +0 -4
- package/dist/indexer/index-writer-lock.js +43 -24
- package/dist/indexer/index-written-assets.js +5 -6
- package/dist/indexer/indexer.js +2 -39
- package/dist/indexer/materialize-embeddings.js +85 -41
- package/dist/indexer/passes/metadata.js +12 -4
- package/dist/indexer/scan/doc-to-entry.js +2 -0
- package/dist/indexer/search/db-search.js +15 -48
- package/dist/indexer/search/ranking-contributors.js +0 -25
- package/dist/indexer/search/ranking.js +3 -13
- package/dist/indexer/search/search-fields.js +16 -1
- package/dist/integrations/agent/builder-shared.js +0 -25
- package/dist/integrations/agent/model-map.js +2 -60
- package/dist/integrations/harnesses/aider/agent-builder.js +1 -3
- package/dist/integrations/harnesses/amazonq/agent-builder.js +2 -7
- package/dist/integrations/harnesses/claude/agent-builder.js +1 -4
- package/dist/integrations/harnesses/codex/agent-builder.js +1 -4
- package/dist/integrations/harnesses/copilot/agent-builder.js +2 -6
- package/dist/integrations/harnesses/gemini/agent-builder.js +2 -7
- package/dist/integrations/harnesses/opencode/agent-builder.js +1 -4
- package/dist/integrations/harnesses/opencode-sdk/sdk-runner.js +2 -16
- package/dist/integrations/harnesses/openhands/agent-builder.js +1 -3
- package/dist/integrations/harnesses/pi/agent-builder.js +2 -4
- package/dist/integrations/session-logs/index.js +0 -9
- package/dist/llm/client.js +75 -42
- package/dist/llm/embedder.js +7 -3
- package/dist/llm/embedders/remote.js +141 -42
- package/dist/output/shapes/passthrough.js +17 -5
- package/dist/registry/network.js +5 -37
- package/dist/runtime.js +2 -10
- package/dist/scripts/akm-migrate-node.js +180 -238
- package/dist/scripts/akm-migrate.js +180 -238
- package/dist/setup/engine-config.js +2 -5
- package/dist/setup/registry-stash-loader.js +0 -8
- package/dist/setup/setup.js +9 -46
- package/dist/setup/steps/connection-shared.js +10 -13
- package/dist/sources/providers/git-install.js +1 -1
- package/dist/storage/engines/sqlite-migrations.js +20 -1
- package/dist/storage/repositories/index-entries-repository.js +0 -15
- package/dist/storage/repositories/proposals-repository.js +32 -6
- package/dist/tasks/backends/launchd.js +15 -20
- package/dist/tasks/backends/schtasks.js +18 -8
- package/dist/tasks/run/run-native-task.js +8 -6
- package/dist/tasks/scheduler-binding.js +15 -5
- package/dist/tasks/scheduler-sync-preview.js +4 -2
- package/dist/tasks/scheduler-sync.js +77 -42
- package/dist/tasks/source/bounded-document.js +2 -4
- package/dist/tasks/source/task-source-v3-frozen.js +5 -7
- package/dist/tasks/source/task-source-v4.js +5 -10
- package/dist/tasks/source/task-to-v3.js +29 -22
- package/dist/tasks/source/task-to-v4.js +1 -14
- package/dist/tasks/source-v3.js +6 -6
- package/dist/workflows/exec/native-executor.js +21 -31
- package/dist/workflows/exec/run-workflow.js +5 -6
- package/dist/workflows/exec/scheduler.js +3 -19
- package/dist/workflows/exec/step-work.js +1 -4
- package/dist/workflows/exec/unit-dispatch.js +2 -2
- package/dist/workflows/exec/worktree.js +1 -13
- package/dist/workflows/freeze/targets/child-workflow.js +2 -10
- package/dist/workflows/ir/plan-hash.js +4 -6
- package/dist/workflows/ir/schema-v4.js +0 -12
- package/dist/workflows/ir/schema.js +20 -31
- package/dist/workflows/parser.js +11 -52
- package/dist/workflows/renderer.js +2 -3
- package/dist/workflows/resource-limits.js +11 -41
- package/dist/workflows/runtime/runs.js +3 -4
- package/dist/workflows/source-ir/schema.js +14 -30
- package/dist/workflows/validator.js +1 -7
- package/docs/reference/cli.md +25 -3
- package/docs/reference/configuration.md +28 -7
- package/docs/reference/tasks.md +10 -0
- package/package.json +1 -1
- package/schemas/akm-config.json +4 -23
- package/schemas/akm-task.json +1 -2
- package/schemas/akm-workflow.json +1 -13
- package/dist/indexer/search/semantic-status.js +0 -142
|
@@ -7,11 +7,10 @@ export function readCurrentLlmEngine(config) {
|
|
|
7
7
|
const engine = name ? config.engines?.[name] : undefined;
|
|
8
8
|
if (!engine || engine.kind !== "llm")
|
|
9
9
|
return undefined;
|
|
10
|
-
const { kind: _kind,
|
|
10
|
+
const { kind: _kind, timeoutMs, ...connection } = engine;
|
|
11
11
|
return {
|
|
12
12
|
...connection,
|
|
13
13
|
...(timeoutMs !== undefined ? { timeoutMs } : {}),
|
|
14
|
-
...(supportsJsonSchema !== undefined ? { capabilities: { structuredOutput: supportsJsonSchema } } : {}),
|
|
15
14
|
};
|
|
16
15
|
}
|
|
17
16
|
export function readAgentEngineSelection(config) {
|
|
@@ -45,15 +44,13 @@ export function writeLlmEngine(config, llm) {
|
|
|
45
44
|
const endpoint = llm.endpoint.endsWith("/chat/completions")
|
|
46
45
|
? llm.endpoint
|
|
47
46
|
: `${llm.endpoint.replace(/\/$/, "")}/chat/completions`;
|
|
48
|
-
const { capabilities, ...connection } = llm;
|
|
49
47
|
return {
|
|
50
48
|
engines: {
|
|
51
49
|
...(config.engines ?? {}),
|
|
52
50
|
[name]: {
|
|
53
|
-
...
|
|
51
|
+
...llm,
|
|
54
52
|
kind: "llm",
|
|
55
53
|
endpoint,
|
|
56
|
-
...(capabilities?.structuredOutput !== undefined ? { supportsJsonSchema: capabilities.structuredOutput } : {}),
|
|
57
54
|
},
|
|
58
55
|
},
|
|
59
56
|
defaults: { ...(config.defaults ?? {}), engine: config.defaults?.engine ?? name, llmEngine: name },
|
|
@@ -17,14 +17,6 @@ import { hasRegistryUrlCredentials } from "../core/registry-url.js";
|
|
|
17
17
|
import { allowPrivateRegistryFixtureForTests, cancelRegistryResponse, fetchRegistryResponse, } from "../registry/network.js";
|
|
18
18
|
import { parseRegistryRef } from "../registry/resolve.js";
|
|
19
19
|
// ── Default selections ──────────────────────────────────────────────────────
|
|
20
|
-
/**
|
|
21
|
-
* Registry stash IDs that are pre-selected by default during setup.
|
|
22
|
-
* IDs must match the `id` field in the official registry index and have a
|
|
23
|
-
* matching target in AUTHENTICATED_DEFAULT_TARGETS.
|
|
24
|
-
*
|
|
25
|
-
* The target binding is intentionally separate from display metadata.
|
|
26
|
-
*/
|
|
27
|
-
export const DEFAULT_SELECTED_STASH_IDS = ["itlackey/akm-stash"];
|
|
28
20
|
const AUTHENTICATED_DEFAULT_TARGETS = {
|
|
29
21
|
"itlackey/akm-stash": {
|
|
30
22
|
installType: "git",
|
package/dist/setup/setup.js
CHANGED
|
@@ -29,11 +29,10 @@ import { ConfigError, UsageError } from "../core/errors.js";
|
|
|
29
29
|
import { getConfigPath, getDefaultStashDir, isTransientStashPath } from "../core/paths.js";
|
|
30
30
|
import { warn } from "../core/warn.js";
|
|
31
31
|
import { akmIndex } from "../indexer/indexer.js";
|
|
32
|
-
import { clearSemanticStatus, deriveSemanticProviderFingerprint, writeSemanticStatus, } from "../indexer/search/semantic-status.js";
|
|
33
32
|
import { detectAgentCliProfiles, pickDefaultAgentProfile } from "../integrations/agent/index.js";
|
|
34
33
|
import { defaultProfileName } from "../integrations/harnesses/index.js";
|
|
35
34
|
import { readLockfile } from "../integrations/lockfile.js";
|
|
36
|
-
import {
|
|
35
|
+
import { probeLlmReachable } from "../llm/client.js";
|
|
37
36
|
import { detectEnvironment, detectLMStudio, renderDetectionSummary, } from "./detect.js";
|
|
38
37
|
import { upsertDetectedAgentEngine, upsertDetectedLlmEngine, verifyOpenAiCompatibleEndpoint } from "./detected-engines.js";
|
|
39
38
|
import { readCurrentLlmEngine, writeAgentEngines, writeLlmEngine } from "./engine-config.js";
|
|
@@ -592,38 +591,14 @@ export async function runSetupWizard(opts) {
|
|
|
592
591
|
// Non-interactive setup paths never reach this interactive-only step.
|
|
593
592
|
p.log.step("Scheduled Tasks");
|
|
594
593
|
await stepScheduledTasks();
|
|
595
|
-
if (semanticSearchMode.mode === "off") {
|
|
596
|
-
clearSemanticStatus();
|
|
597
|
-
}
|
|
598
594
|
if (semanticSearchMode.mode === "auto") {
|
|
599
595
|
if (semanticSearchMode.prepareAssets) {
|
|
600
596
|
const ready = await prepareSemanticSearchAssets(savedConfig);
|
|
601
597
|
if (!ready.ok) {
|
|
602
|
-
writeSemanticStatus({
|
|
603
|
-
status: "blocked",
|
|
604
|
-
reason: ready.reason,
|
|
605
|
-
message: ready.message,
|
|
606
|
-
providerFingerprint: deriveSemanticProviderFingerprint(savedConfig.embedding),
|
|
607
|
-
lastCheckedAt: new Date().toISOString(),
|
|
608
|
-
});
|
|
609
598
|
p.log.warn("Semantic search remains set to auto, but is currently blocked. Re-run `akm index --full --verbose` once the issue is resolved.");
|
|
610
599
|
}
|
|
611
|
-
else {
|
|
612
|
-
writeSemanticStatus({
|
|
613
|
-
status: "pending",
|
|
614
|
-
message: "Semantic prerequisites verified. Building the index to finish activation.",
|
|
615
|
-
providerFingerprint: deriveSemanticProviderFingerprint(savedConfig.embedding),
|
|
616
|
-
lastCheckedAt: new Date().toISOString(),
|
|
617
|
-
});
|
|
618
|
-
}
|
|
619
600
|
}
|
|
620
601
|
else {
|
|
621
|
-
writeSemanticStatus({
|
|
622
|
-
status: "pending",
|
|
623
|
-
message: "Semantic search is enabled, but asset preparation was skipped.",
|
|
624
|
-
providerFingerprint: deriveSemanticProviderFingerprint(savedConfig.embedding),
|
|
625
|
-
lastCheckedAt: new Date().toISOString(),
|
|
626
|
-
});
|
|
627
602
|
p.log.info("Semantic search is set to auto, but asset preparation was skipped. Run `akm index --full --verbose` later to verify it.");
|
|
628
603
|
}
|
|
629
604
|
}
|
|
@@ -649,15 +624,6 @@ export async function runSetupWizard(opts) {
|
|
|
649
624
|
catch (err) {
|
|
650
625
|
spin.stop("Indexing failed — you can run `akm index` manually later.");
|
|
651
626
|
p.log.warn(String(err));
|
|
652
|
-
if (savedConfig.semanticSearchMode === "auto") {
|
|
653
|
-
writeSemanticStatus({
|
|
654
|
-
status: "blocked",
|
|
655
|
-
reason: "index-failed",
|
|
656
|
-
message: String(err),
|
|
657
|
-
providerFingerprint: deriveSemanticProviderFingerprint(savedConfig.embedding),
|
|
658
|
-
lastCheckedAt: new Date().toISOString(),
|
|
659
|
-
});
|
|
660
|
-
}
|
|
661
627
|
}
|
|
662
628
|
// API key reminder
|
|
663
629
|
if (embedding?.apiKey === undefined && embedding?.provider !== "ollama") {
|
|
@@ -989,22 +955,19 @@ export async function runSetupFromConfig(opts) {
|
|
|
989
955
|
merged = ctx.config;
|
|
990
956
|
}
|
|
991
957
|
// Convert the private setup draft to the persisted bundle shape.
|
|
992
|
-
|
|
958
|
+
const finalizedMerged = finalizeSetupDraft(merged);
|
|
993
959
|
// Reject an invalid merged engine graph before probing or touching the stash.
|
|
994
960
|
validateCompleteConfig(finalizedMerged);
|
|
995
|
-
// Optional probe
|
|
961
|
+
// Optional connectivity probe — informational only, never blocks or
|
|
962
|
+
// mutates config. `chatCompletion` attempts structured output fresh on
|
|
963
|
+
// every call that needs it (see `llm/client.ts`), so there is nothing to
|
|
964
|
+
// probe or persist here beyond "did the endpoint answer".
|
|
996
965
|
const mergedLlm = readCurrentLlmEngine(finalizedMerged);
|
|
997
966
|
if (opts.probe && mergedLlm) {
|
|
998
967
|
try {
|
|
999
|
-
const
|
|
1000
|
-
if (
|
|
1001
|
-
|
|
1002
|
-
...finalizedMerged,
|
|
1003
|
-
...writeLlmEngine(finalizedMerged, {
|
|
1004
|
-
...mergedLlm,
|
|
1005
|
-
capabilities: { structuredOutput: caps.structuredOutput ?? false },
|
|
1006
|
-
}),
|
|
1007
|
-
};
|
|
968
|
+
const reach = await probeLlmReachable(mergedLlm);
|
|
969
|
+
if (!reach.reachable) {
|
|
970
|
+
warn(`[akm setup] LLM endpoint not reachable${reach.error ? `: ${reach.error}` : ""}.`);
|
|
1008
971
|
}
|
|
1009
972
|
}
|
|
1010
973
|
catch {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* each step keeps its own option assembly and branching.
|
|
10
10
|
*/
|
|
11
11
|
import * as p from "../../cli/clack.js";
|
|
12
|
-
import {
|
|
12
|
+
import { probeLlmReachable } from "../../llm/client.js";
|
|
13
13
|
import { prompt, promptOrBack } from "../prompt.js";
|
|
14
14
|
// ── Derive-config ───────────────────────────────────────────────────────────
|
|
15
15
|
/** Standard chat-connection config shared by every provider branch. */
|
|
@@ -97,21 +97,18 @@ export async function promptApiKeyEnvVarName() {
|
|
|
97
97
|
}
|
|
98
98
|
// ── Probe ───────────────────────────────────────────────────────────────────
|
|
99
99
|
/**
|
|
100
|
-
* Best-effort
|
|
101
|
-
*
|
|
102
|
-
*
|
|
100
|
+
* Best-effort reachability probe — never blocks setup. Does NOT probe or
|
|
101
|
+
* cache structured-output support: `chatCompletion` now attempts
|
|
102
|
+
* `response_format: json_schema` fresh on every call that supplies a schema
|
|
103
|
+
* and falls back once per call on a 4xx (see `llm/client.ts`), so there is
|
|
104
|
+
* no verdict for setup to determine or persist here.
|
|
103
105
|
*/
|
|
104
106
|
export async function probeLlmConnection(llm) {
|
|
105
107
|
const probeSpin = p.spinner();
|
|
106
|
-
probeSpin.start("Probing LLM
|
|
107
|
-
const probe = await
|
|
108
|
-
if (probe.reachable
|
|
109
|
-
probeSpin.stop("LLM reachable
|
|
110
|
-
llm.capabilities = { ...(llm.capabilities ?? {}), structuredOutput: true };
|
|
111
|
-
}
|
|
112
|
-
else if (probe.reachable) {
|
|
113
|
-
probeSpin.stop("LLM reachable but structured-output probe failed.");
|
|
114
|
-
llm.capabilities = { ...(llm.capabilities ?? {}), structuredOutput: false };
|
|
108
|
+
probeSpin.start("Probing LLM connectivity...");
|
|
109
|
+
const probe = await probeLlmReachable(llm);
|
|
110
|
+
if (probe.reachable) {
|
|
111
|
+
probeSpin.stop("LLM reachable.");
|
|
115
112
|
}
|
|
116
113
|
else {
|
|
117
114
|
probeSpin.stop("LLM not reachable.");
|
|
@@ -1,6 +1,25 @@
|
|
|
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
|
+
/**
|
|
5
|
+
* Shared SQLite migration engine.
|
|
6
|
+
*
|
|
7
|
+
* SQLite schemas evolve through this transaction-per-migration runner backed
|
|
8
|
+
* by a `schema_migrations` ledger.
|
|
9
|
+
*
|
|
10
|
+
* This module factors that runner out once. Each caller supplies only its own
|
|
11
|
+
* `MIGRATIONS` array.
|
|
12
|
+
*
|
|
13
|
+
* Ledger/transaction contract:
|
|
14
|
+
* - `id` is permanent and must never be reused.
|
|
15
|
+
* - Applied IDs must be an exact ordered prefix of the registry.
|
|
16
|
+
* - Each `up` body and its ledger insert commit in the same transaction.
|
|
17
|
+
* - Migration bodies run only after `BEGIN IMMEDIATE` is observably active,
|
|
18
|
+
* and the transaction must remain active through the body's completion.
|
|
19
|
+
* - The caller owns semantic safety classification and any policy gate;
|
|
20
|
+
* this generic engine intentionally does not infer risk from SQL text.
|
|
21
|
+
*/
|
|
22
|
+
import { sleepSync } from "../../runtime.js";
|
|
4
23
|
export function assertMigrationRegistry(migrations) {
|
|
5
24
|
const seen = new Set();
|
|
6
25
|
for (const migration of migrations) {
|
|
@@ -152,7 +171,7 @@ function isRetryableImmediateBeginError(error) {
|
|
|
152
171
|
function sleepImmediateRetry(ms) {
|
|
153
172
|
if (ms <= 0)
|
|
154
173
|
return;
|
|
155
|
-
|
|
174
|
+
sleepSync(ms);
|
|
156
175
|
}
|
|
157
176
|
/**
|
|
158
177
|
* Run `fn` inside a `BEGIN IMMEDIATE` transaction.
|
|
@@ -354,9 +354,6 @@ function deleteEntryRows(db, rows, options = {}) {
|
|
|
354
354
|
}
|
|
355
355
|
return rows.map((row) => row.id);
|
|
356
356
|
}
|
|
357
|
-
export function deleteEntriesByDir(db, dirPath) {
|
|
358
|
-
db.transaction(() => deleteEntryRows(db, rowsInDirectory(db, dirPath)))();
|
|
359
|
-
}
|
|
360
357
|
export function deleteEntriesByDirAndBundle(db, dirPath, bundleId, options = {}) {
|
|
361
358
|
return db.transaction(() => deleteEntryRows(db, rowsInDirectory(db, dirPath, bundleId), options))();
|
|
362
359
|
}
|
|
@@ -704,18 +701,6 @@ export function getEntryRefRowsForStashRoot(db, stashRoot) {
|
|
|
704
701
|
});
|
|
705
702
|
}
|
|
706
703
|
// ── Indexer-phase helpers (moved from indexer.ts) ────────────────────────────
|
|
707
|
-
/**
|
|
708
|
-
* Compute a cheap FNV-1a hash of a buffer for source-identity tracking.
|
|
709
|
-
* Not security-sensitive; used as an incremental fast-path skip key.
|
|
710
|
-
*/
|
|
711
|
-
export function computeSourceHash(content) {
|
|
712
|
-
let hash = 0x811c9dc5;
|
|
713
|
-
for (let i = 0; i < content.length; i++) {
|
|
714
|
-
hash ^= content[i];
|
|
715
|
-
hash = Math.imul(hash, 0x01000193);
|
|
716
|
-
}
|
|
717
|
-
return (hash >>> 0).toString(16);
|
|
718
|
-
}
|
|
719
704
|
/**
|
|
720
705
|
* Return distinct zero-result search queries from the `usage_events` table
|
|
721
706
|
* within the given lookback window.
|
|
@@ -85,7 +85,7 @@ function currentProposalRef(ref, requireQualified = false) {
|
|
|
85
85
|
}
|
|
86
86
|
function currentProposalTarget(value) {
|
|
87
87
|
if (typeof value !== "object" || value === null)
|
|
88
|
-
throw new Error("Proposal metadata
|
|
88
|
+
throw new Error("Proposal metadata has an invalid proposedTarget.");
|
|
89
89
|
const target = value;
|
|
90
90
|
if (typeof target.source !== "string" ||
|
|
91
91
|
!isBundleSlug(target.source) ||
|
|
@@ -200,7 +200,13 @@ export function proposalRowToProposal(row) {
|
|
|
200
200
|
}
|
|
201
201
|
validatePresentMetadata(meta);
|
|
202
202
|
const changes = storedToChanges(meta.changes, row.content);
|
|
203
|
-
|
|
203
|
+
// #859: absent proposedTarget (~93% of the real archive's accepted/rejected
|
|
204
|
+
// rows) is envelope metadata that predates this field, not corruption — an
|
|
205
|
+
// already-decided proposal is counted/displayed, never re-applied, so
|
|
206
|
+
// decode tolerates its absence the same way it already tolerates absent
|
|
207
|
+
// `changes`. A *present but malformed* value is still corruption and
|
|
208
|
+
// throws via currentProposalTarget, same as before.
|
|
209
|
+
const proposedTarget = meta.proposedTarget !== undefined ? currentProposalTarget(meta.proposedTarget) : undefined;
|
|
204
210
|
return {
|
|
205
211
|
id: row.id,
|
|
206
212
|
ref: currentProposalRef(row.ref),
|
|
@@ -214,7 +220,7 @@ export function proposalRowToProposal(row) {
|
|
|
214
220
|
...(frontmatter !== undefined ? { frontmatter } : {}),
|
|
215
221
|
},
|
|
216
222
|
changes,
|
|
217
|
-
proposedTarget,
|
|
223
|
+
...(proposedTarget !== undefined ? { proposedTarget } : {}),
|
|
218
224
|
...(typeof meta.beforeHash === "string" ? { beforeHash: meta.beforeHash } : {}),
|
|
219
225
|
...(meta.review !== undefined ? { review: meta.review } : {}),
|
|
220
226
|
...(typeof meta.confidence === "number" ? { confidence: meta.confidence } : {}),
|
|
@@ -233,8 +239,27 @@ export function proposalRowToProposal(row) {
|
|
|
233
239
|
export function proposalToRowValues(proposal, stashDir) {
|
|
234
240
|
// Fields that have no dedicated column live in metadata_json.
|
|
235
241
|
const metaObj = {};
|
|
236
|
-
|
|
237
|
-
|
|
242
|
+
// #859: `changes` and `proposedTarget` are only enforced as REQUIRED when
|
|
243
|
+
// minting/updating a `pending` proposal — the one status createProposal
|
|
244
|
+
// ever writes, and the one status every real accept/reject transition
|
|
245
|
+
// writes FROM (a pending row always carries the full envelope; see
|
|
246
|
+
// storedToChanges / currentProposalTarget doc comments). Writing a
|
|
247
|
+
// non-pending status (accepted/rejected/reverted) is always a status
|
|
248
|
+
// TRANSITION of an already-persisted proposal, spread-copied from the row
|
|
249
|
+
// this same repository just decoded — for a legacy archived row that
|
|
250
|
+
// never had `changes`/`proposedTarget` to begin with (the pre-envelope
|
|
251
|
+
// shape), re-persisting it unchanged (e.g. `proposal revert` on an old
|
|
252
|
+
// accepted row) must not be blocked by a requirement the row never met.
|
|
253
|
+
// This does NOT weaken validation of a genuinely new proposal: every
|
|
254
|
+
// pending-status write still requires the full envelope, exactly as
|
|
255
|
+
// before.
|
|
256
|
+
if (proposal.status === "pending") {
|
|
257
|
+
if (!Array.isArray(proposal.changes) || proposal.changes.length === 0) {
|
|
258
|
+
throw new Error(`Proposal ${proposal.id} has no file changes.`);
|
|
259
|
+
}
|
|
260
|
+
if (proposal.proposedTarget === undefined) {
|
|
261
|
+
throw new Error(`Proposal ${proposal.id} is missing proposedTarget.`);
|
|
262
|
+
}
|
|
238
263
|
}
|
|
239
264
|
if (proposal.changes.some((change) => typeof change.path !== "string" ||
|
|
240
265
|
change.path.length === 0 ||
|
|
@@ -243,7 +268,8 @@ export function proposalToRowValues(proposal, stashDir) {
|
|
|
243
268
|
throw new Error(`Proposal ${proposal.id} has invalid file changes.`);
|
|
244
269
|
}
|
|
245
270
|
metaObj.changes = changesToStored(proposal.changes);
|
|
246
|
-
|
|
271
|
+
if (proposal.proposedTarget !== undefined)
|
|
272
|
+
metaObj.proposedTarget = currentProposalTarget(proposal.proposedTarget);
|
|
247
273
|
if (proposal.beforeHash !== undefined)
|
|
248
274
|
metaObj.beforeHash = proposal.beforeHash;
|
|
249
275
|
if (proposal.sourceRun !== undefined)
|
|
@@ -494,15 +494,20 @@ function assertUnrestorableLaunchdSnapshotUnchanged(entry, currentArtifacts) {
|
|
|
494
494
|
throw new ConfigError(`Loaded launchd artifact ${JSON.stringify(entry.id)} has no restorable plist and changed after its snapshot; refusing mutation.`, "INVALID_CONFIG_FILE");
|
|
495
495
|
}
|
|
496
496
|
}
|
|
497
|
+
/**
|
|
498
|
+
* Enumerate the current launchd AKM service namespace (loaded domain members,
|
|
499
|
+
* print-disabled labels, and on-disk plists) in one pass.
|
|
500
|
+
*
|
|
501
|
+
* This used to run the enumeration twice and fail closed if the two passes
|
|
502
|
+
* disagreed, guarding against launchd state mutating between the two
|
|
503
|
+
* `launchctl` shell-outs (milliseconds apart, in-process). The only actor
|
|
504
|
+
* that could cause that is another concurrent akm process or the user
|
|
505
|
+
* running launchctl by hand at that exact instant; a subsequent `task sync`
|
|
506
|
+
* (idempotent by design) reconciles any such drift on its own, so the
|
|
507
|
+
* two-pass fencing added a TOCTOU-shaped guard around a race with a working
|
|
508
|
+
* self-heal already in place, not a way to avoid one.
|
|
509
|
+
*/
|
|
497
510
|
function inspectStableLaunchdNamespace(seedIds, context) {
|
|
498
|
-
const first = captureLaunchdNamespacePass(seedIds, context);
|
|
499
|
-
const second = captureLaunchdNamespacePass(seedIds, context);
|
|
500
|
-
if (first.stabilityKey !== second.stabilityKey) {
|
|
501
|
-
throw new ConfigError("The launchd AKM service namespace changed while scheduler state was being stabilized.", "INVALID_CONFIG_FILE");
|
|
502
|
-
}
|
|
503
|
-
return second.namespace;
|
|
504
|
-
}
|
|
505
|
-
function captureLaunchdNamespacePass(seedIds, context) {
|
|
506
511
|
const domain = context.exec.run(["launchctl", "print", `gui/${context.exec.uid()}`]);
|
|
507
512
|
if (domain.status !== 0) {
|
|
508
513
|
throw new ConfigError(`launchctl failed to enumerate the loaded user domain during scheduler state inspection: ${domain.stderr || domain.stdout || "no output"}.`, "INVALID_CONFIG_FILE");
|
|
@@ -532,9 +537,6 @@ function captureLaunchdNamespacePass(seedIds, context) {
|
|
|
532
537
|
ids.add(serviceLabel.slice(LAUNCHD_LABEL_PREFIX.length));
|
|
533
538
|
for (const serviceLabel of akmDisabledLabels)
|
|
534
539
|
ids.add(serviceLabel.slice(LAUNCHD_LABEL_PREFIX.length));
|
|
535
|
-
if (ids.size > MAX_LAUNCHD_AKM_NAMESPACE_ENTRIES) {
|
|
536
|
-
throw new ConfigError(`launchd AKM scheduler inventory exceeds ${MAX_LAUNCHD_AKM_NAMESPACE_ENTRIES} namespace entries.`, "INVALID_CONFIG_FILE");
|
|
537
|
-
}
|
|
538
540
|
const plistByNativeId = new Map(plistEntries);
|
|
539
541
|
const entries = [];
|
|
540
542
|
for (const nativeId of [...ids].sort()) {
|
|
@@ -566,15 +568,8 @@ function captureLaunchdNamespacePass(seedIds, context) {
|
|
|
566
568
|
}, parsed.invocation, entry.nativeId));
|
|
567
569
|
}
|
|
568
570
|
return Object.freeze({
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
entries: Object.freeze(entries),
|
|
572
|
-
}),
|
|
573
|
-
stabilityKey: JSON.stringify({
|
|
574
|
-
loadedLabels: [...loadedLabels].sort(),
|
|
575
|
-
disabledLabels: akmDisabledLabels,
|
|
576
|
-
plistEntries,
|
|
577
|
-
}),
|
|
571
|
+
inspection: Object.freeze({ installed: Object.freeze(installed), artifacts: Object.freeze(artifacts) }),
|
|
572
|
+
entries: Object.freeze(entries),
|
|
578
573
|
});
|
|
579
574
|
}
|
|
580
575
|
function restoreLaunchdBindingEntry(entry, context, errors) {
|
|
@@ -106,7 +106,7 @@ export function SCHTASKS_BACKEND(options = {}) {
|
|
|
106
106
|
assertSchedulerMutationArtifact(current?.status === 0 && finalNativeId ? schtasksArtifact(finalNativeId, current.stdout) : undefined, expected);
|
|
107
107
|
}
|
|
108
108
|
else {
|
|
109
|
-
assertSchtasksArtifactUnchanged(exec, taskName(nativeId),
|
|
109
|
+
assertSchtasksArtifactUnchanged(exec, taskName(nativeId), nativeId, task);
|
|
110
110
|
}
|
|
111
111
|
try {
|
|
112
112
|
// /F forces overwrite if a task with the same name exists.
|
|
@@ -461,8 +461,23 @@ function parsePowerShellSingleQuotedArgs(script, start) {
|
|
|
461
461
|
}
|
|
462
462
|
return argv;
|
|
463
463
|
}
|
|
464
|
-
/**
|
|
465
|
-
|
|
464
|
+
/**
|
|
465
|
+
* Re-verify ownership of the native artifact immediately before `/Create /F`
|
|
466
|
+
* overwrites it (the read/prepare-to-/Create ownership race at the native
|
|
467
|
+
* boundary).
|
|
468
|
+
*
|
|
469
|
+
* This used to also compare the fresh query against the first read taken
|
|
470
|
+
* earlier in `install` and refuse the whole operation if anything about the
|
|
471
|
+
* XML had changed in between -- a freshness re-check on top of the identity
|
|
472
|
+
* re-check right below it. That extra comparison never caught anything the
|
|
473
|
+
* owner check didn't already cover (a foreign/changed owner still fails
|
|
474
|
+
* `assertSchedulerNativeArtifactOwner`), and `task sync` is idempotent, so a
|
|
475
|
+
* spurious refusal here only cost the user a rerun of a command they'd
|
|
476
|
+
* already asked for. Dropped; the owner re-check (the actual corruption/
|
|
477
|
+
* clobber guard -- no fallback exists if a foreign task got silently
|
|
478
|
+
* overwritten) stays.
|
|
479
|
+
*/
|
|
480
|
+
function assertSchtasksArtifactUnchanged(exec, nativeTaskName, nativeId, task) {
|
|
466
481
|
// This runs outside install's rollback region: no scheduler mutation has
|
|
467
482
|
// occurred, so a raced owner must remain untouched rather than be restored
|
|
468
483
|
// from the stale first read.
|
|
@@ -470,11 +485,6 @@ function assertSchtasksArtifactUnchanged(exec, nativeTaskName, previous, nativeI
|
|
|
470
485
|
isOk: (result) => result.status === 0 || isMissingTaskResult(result),
|
|
471
486
|
message: (result) => `schtasks /Query failed during final ownership check (exit ${result.status}): ${result.stderr || result.stdout || "no output"}.`,
|
|
472
487
|
});
|
|
473
|
-
const changed = current.status !== previous.status ||
|
|
474
|
-
(current.status === 0 && normalizeXmlForUtf16File(current.stdout) !== normalizeXmlForUtf16File(previous.stdout));
|
|
475
|
-
if (changed) {
|
|
476
|
-
throw new ConfigError(`schtasks task "${nativeTaskName}" changed while it was being prepared; refusing to replace an unverified owner.`, "INVALID_CONFIG_FILE");
|
|
477
|
-
}
|
|
478
488
|
if (current.status === 0) {
|
|
479
489
|
assertSchedulerNativeArtifactOwner(nativeId, task, extractSchtasksInvocation(current.stdout)?.invocation);
|
|
480
490
|
}
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
import path from "node:path";
|
|
21
21
|
import { assertNever } from "../../core/assert.js";
|
|
22
22
|
import { runManagedSubprocess, streamCaptureFailure } from "../../core/subprocess.js";
|
|
23
|
-
import {
|
|
23
|
+
import { assertFrozenDirectoryContained } from "../../execution/directory-identity.js";
|
|
24
24
|
import { cleanupFrozenScript, frozenScriptCommand, materializeFrozenScript } from "../frozen-script.js";
|
|
25
25
|
import { resolveAkmInvocation } from "../resolve-akm-bin.js";
|
|
26
26
|
import { finishAttempt } from "./attempt-lifecycle.js";
|
|
@@ -146,11 +146,13 @@ export async function runNativeTask(input) {
|
|
|
146
146
|
const dbLines = [{ line: header }];
|
|
147
147
|
let exitCode = null;
|
|
148
148
|
try {
|
|
149
|
-
//
|
|
150
|
-
//
|
|
151
|
-
//
|
|
152
|
-
//
|
|
153
|
-
|
|
149
|
+
// Re-resolve the authored root/cwd immediately before spawn so a
|
|
150
|
+
// symlink, ancestor, bundle-root, or directory/file swap cannot redirect
|
|
151
|
+
// execution outside that physical workspace. This is a live containment
|
|
152
|
+
// check, not an identity comparison — it does not care whether the
|
|
153
|
+
// underlying device/inode changed (e.g. a remount), only whether the
|
|
154
|
+
// resolved cwd still lives inside its root.
|
|
155
|
+
assertFrozenDirectoryContained(task.cwdIdentity);
|
|
154
156
|
if (task.kind === "script") {
|
|
155
157
|
materialized = materializeFrozenScript(task);
|
|
156
158
|
cmd = frozenScriptCommand(task, materialized.file);
|
|
@@ -159,12 +159,15 @@ export function schedulerLogicalBindingOwner(nativeId, invocation) {
|
|
|
159
159
|
return schedulerNativeArtifactOwner(nativeId, invocation)?.logicalId;
|
|
160
160
|
}
|
|
161
161
|
export function schedulerNativeArtifactOwner(nativeId, invocation) {
|
|
162
|
-
if (invocation[0] === "workflow" && invocation[1] === "run") {
|
|
163
|
-
|
|
162
|
+
if (invocation[0] === "workflow" && invocation[1] === "run" && invocation.length === 3) {
|
|
163
|
+
const ref = invocation[2];
|
|
164
|
+
if (ref && workflowRefDigestsToNativeId(ref, nativeId)) {
|
|
165
|
+
return { logicalId: nativeId, logicalKind: "workflow" };
|
|
166
|
+
}
|
|
167
|
+
return undefined;
|
|
164
168
|
}
|
|
165
169
|
const taskId = invocation[0] === "task" && invocation[1] === "run" ? invocation[2] : undefined;
|
|
166
|
-
|
|
167
|
-
if (!taskId || bundleIndex === -1 || !invocation[bundleIndex + 1])
|
|
170
|
+
if (!taskId)
|
|
168
171
|
return undefined;
|
|
169
172
|
return {
|
|
170
173
|
logicalId: schedulerNativeBindingId(taskId) === nativeId ? taskId : nativeId,
|
|
@@ -225,7 +228,6 @@ export function assertSchedulerMutationArtifact(artifact, expected) {
|
|
|
225
228
|
artifact.nativeId === expected.nativeId &&
|
|
226
229
|
artifact.bindingId === expected.bindingId &&
|
|
227
230
|
artifact.invocation !== undefined &&
|
|
228
|
-
sameInvocation(artifact.invocation, expected.invocation) &&
|
|
229
231
|
expected.fingerprint !== undefined &&
|
|
230
232
|
artifact.fingerprint === expected.fingerprint) {
|
|
231
233
|
return;
|
|
@@ -306,6 +308,14 @@ export function schedulerBindingOrdinal(bindingId, logicalSource, invocation) {
|
|
|
306
308
|
}
|
|
307
309
|
return undefined;
|
|
308
310
|
}
|
|
311
|
+
/** Whether some schedule ordinal on `ref` would digest to `nativeId` (mirrors schedulerBindingOrdinal). */
|
|
312
|
+
function workflowRefDigestsToNativeId(ref, nativeId) {
|
|
313
|
+
for (let ordinal = 0; ordinal < 4096; ordinal += 1) {
|
|
314
|
+
if (digestBindingId("workflow", ref, ordinal) === nativeId)
|
|
315
|
+
return true;
|
|
316
|
+
}
|
|
317
|
+
return false;
|
|
318
|
+
}
|
|
309
319
|
function digestBindingId(kind, ref, ordinal) {
|
|
310
320
|
const prefix = kind === "workflow" ? "wf" : "task";
|
|
311
321
|
const digest = createHash("sha256")
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* `SchedulerSyncPlan`) so a future `task prune` can build a preview from
|
|
8
8
|
* its own remove-only operation set without needing a full sync plan.
|
|
9
9
|
*/
|
|
10
|
-
export function renderSchedulerPlanPreview(backend, operations, unchanged = []) {
|
|
10
|
+
export function renderSchedulerPlanPreview(backend, operations, unchanged = [], failures = []) {
|
|
11
11
|
const adds = [];
|
|
12
12
|
const updates = [];
|
|
13
13
|
const removes = [];
|
|
@@ -18,6 +18,7 @@ export function renderSchedulerPlanPreview(backend, operations, unchanged = [])
|
|
|
18
18
|
kind: "remove",
|
|
19
19
|
nativeId: operation.nativeId,
|
|
20
20
|
...(operation.ownerBundlePath !== undefined ? { ownerBundlePath: operation.ownerBundlePath } : {}),
|
|
21
|
+
...(operation.reason !== undefined ? { reason: operation.reason } : {}),
|
|
21
22
|
});
|
|
22
23
|
}
|
|
23
24
|
else if (operation.kind === "install") {
|
|
@@ -35,9 +36,10 @@ export function renderSchedulerPlanPreview(backend, operations, unchanged = [])
|
|
|
35
36
|
removes: Object.freeze(removes),
|
|
36
37
|
unchanged: Object.freeze([...unchanged]),
|
|
37
38
|
hasRemovals: removes.length > 0,
|
|
39
|
+
failures: Object.freeze([...failures]),
|
|
38
40
|
});
|
|
39
41
|
}
|
|
40
42
|
/** Convenience wrapper for the common case: previewing a whole {@link SchedulerSyncPlan}. */
|
|
41
43
|
export function renderSchedulerSyncPlanPreview(backend, plan) {
|
|
42
|
-
return renderSchedulerPlanPreview(backend, plan.operations, plan.unchanged);
|
|
44
|
+
return renderSchedulerPlanPreview(backend, plan.operations, plan.unchanged, plan.failures);
|
|
43
45
|
}
|