akm-cli 0.10.261124 → 0.10.261125

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 (44) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/cli/usage.js +4 -0
  3. package/dist/cli.js +10 -0
  4. package/dist/commands/feedback-cli.js +12 -3
  5. package/dist/commands/health/semantic-search-check.js +12 -2
  6. package/dist/commands/health.js +8 -15
  7. package/dist/commands/lint/index.js +6 -6
  8. package/dist/commands/read/knowledge.js +8 -8
  9. package/dist/commands/read/related.js +3 -9
  10. package/dist/commands/read/show.js +17 -9
  11. package/dist/commands/sources/bundle-cli.js +1 -0
  12. package/dist/commands/sources/installed-stashes.js +36 -27
  13. package/dist/core/asset/resolve-ref.js +8 -0
  14. package/dist/core/common.js +21 -0
  15. package/dist/core/endpoint-url.js +4 -4
  16. package/dist/core/events.js +8 -2
  17. package/dist/core/file-lock.js +52 -1
  18. package/dist/core/state-db.js +47 -15
  19. package/dist/core/stdio-reader-gone.js +19 -0
  20. package/dist/core/write-source.js +2 -2
  21. package/dist/indexer/index-build.js +6 -3
  22. package/dist/indexer/index-readiness.js +30 -4
  23. package/dist/indexer/indexer.js +56 -8
  24. package/dist/indexer/search/db-search.js +7 -1
  25. package/dist/indexer/search/search-source.js +23 -25
  26. package/dist/indexer/usage/usage-events.js +13 -4
  27. package/dist/indexer/vector-file.js +3 -3
  28. package/dist/registry/origin-resolve.js +2 -3
  29. package/dist/scripts/akm-migrate-node.js +136 -88
  30. package/dist/scripts/akm-migrate.js +136 -88
  31. package/dist/setup/endpoint.js +1 -1
  32. package/dist/storage/database.js +29 -36
  33. package/dist/storage/repositories/index-connection.js +44 -41
  34. package/dist/storage/repositories/index-entries-repository.js +14 -7
  35. package/dist/storage/repositories/index-entry-schema.js +7 -5
  36. package/dist/storage/repositories/index-schema.js +23 -0
  37. package/dist/storage/sqlite-read-snapshot.js +2 -2
  38. package/dist/workspace/assets.js +24 -44
  39. package/dist/workspace/bundle-files.js +2 -2
  40. package/dist/workspace/documents.js +7 -12
  41. package/dist/workspace/graph-topics.js +249 -0
  42. package/dist/workspace/graph.js +68 -4
  43. package/docs/reference/workspace.md +21 -4
  44. package/package.json +1 -1
@@ -28761,8 +28761,27 @@ function tryAcquireLockSync(lockPath, payload) {
28761
28761
  }
28762
28762
  if (snapshot.rawContent !== payload)
28763
28763
  return;
28764
+ acquiredByThisProcess.set(lockPath, payload);
28764
28765
  return { lockPath, ...snapshot };
28765
28766
  }
28767
+ function processIdentity(pid) {
28768
+ try {
28769
+ const bootId = fs4.readFileSync("/proc/sys/kernel/random/boot_id", "utf8").trim();
28770
+ const stat = fs4.readFileSync(`/proc/${pid}/stat`, "utf8");
28771
+ const startTime = stat.slice(stat.lastIndexOf(")") + 2).split(" ")[19];
28772
+ return bootId && startTime ? { bootId, startTime } : undefined;
28773
+ } catch {
28774
+ return;
28775
+ }
28776
+ }
28777
+ function holderPidReused(holderPid, recorded) {
28778
+ if (typeof recorded.bootId !== "string" || typeof recorded.startTime !== "string")
28779
+ return false;
28780
+ const current = processIdentity(holderPid);
28781
+ if (!current)
28782
+ return false;
28783
+ return current.bootId !== recorded.bootId || current.startTime !== recorded.startTime;
28784
+ }
28766
28785
  function launcherPidFromEnv() {
28767
28786
  const raw = process.env.AKM_LAUNCHER_PID;
28768
28787
  if (!raw)
@@ -28775,6 +28794,7 @@ function createLockPayload(metadata = {}) {
28775
28794
  return JSON.stringify({
28776
28795
  ...metadata,
28777
28796
  pid: process.pid,
28797
+ ...processIdentity(process.pid),
28778
28798
  ...launcherPid !== undefined ? { launcherPid } : {},
28779
28799
  lockId: randomUUID()
28780
28800
  });
@@ -28800,6 +28820,10 @@ function probeLock(lockPath) {
28800
28820
  if (!isProcessAlive(holderPid)) {
28801
28821
  return { state: "stale", reason: "pid_dead", holderPid, launcherPid, ageMs, rawContent, identity: identity3 };
28802
28822
  }
28823
+ const ownLeftover = holderPid === process.pid && acquiredByThisProcess.get(lockPath) !== rawContent;
28824
+ if (ownLeftover || holderPidReused(holderPid, parseLockJson(rawContent))) {
28825
+ return { state: "stale", reason: "pid_reused", holderPid, launcherPid, ageMs, rawContent, identity: identity3 };
28826
+ }
28803
28827
  return { state: "held", holderPid, launcherPid, ageMs, rawContent, identity: identity3 };
28804
28828
  }
28805
28829
  function reclaimStaleLock(lockPath, probe, options) {
@@ -28857,6 +28881,8 @@ function reclaimStaleLock(lockPath, probe, options) {
28857
28881
  }
28858
28882
  function releaseLock(ownership) {
28859
28883
  const { lockPath } = ownership;
28884
+ if (acquiredByThisProcess.get(lockPath) === ownership.rawContent)
28885
+ acquiredByThisProcess.delete(lockPath);
28860
28886
  let current;
28861
28887
  try {
28862
28888
  current = readLockSnapshot(lockPath);
@@ -28867,6 +28893,14 @@ function releaseLock(ownership) {
28867
28893
  releaseLockRaw(lockPath);
28868
28894
  }
28869
28895
  }
28896
+ function parseLockJson(content) {
28897
+ try {
28898
+ const parsed = JSON.parse(content);
28899
+ return typeof parsed === "object" && parsed !== null ? parsed : {};
28900
+ } catch {
28901
+ return {};
28902
+ }
28903
+ }
28870
28904
  function extractLockIdentity(content) {
28871
28905
  const trimmed = content.trim();
28872
28906
  if (!trimmed)
@@ -28887,9 +28921,10 @@ function extractLockIdentity(content) {
28887
28921
  const pid = Number.parseInt(trimmed, 10);
28888
28922
  return { holderPid: Number.isInteger(pid) && pid > 0 ? pid : undefined };
28889
28923
  }
28890
- var UNINITIALISED_LOCK_GRACE_MS = 2000;
28924
+ var acquiredByThisProcess, UNINITIALISED_LOCK_GRACE_MS = 2000;
28891
28925
  var init_file_lock = __esm(() => {
28892
28926
  init_common();
28927
+ acquiredByThisProcess = new Map;
28893
28928
  });
28894
28929
 
28895
28930
  // src/core/config/config-io.ts
@@ -30714,26 +30749,28 @@ var init_agent_builder = __esm(() => {
30714
30749
  // src/storage/database.ts
30715
30750
  import { createRequire as createRequire3 } from "node:module";
30716
30751
  function openDatabase(path13, opts) {
30717
- return isBun2 ? openBunDatabase(path13, opts) : openNodeDatabase(path13, opts);
30718
- }
30719
- function openDatabaseFinalizing(path13, opts) {
30720
- const db = openDatabase(path13, opts);
30721
- const tracked = new Set;
30722
- const origPrepare = db.prepare.bind(db);
30723
- const origClose = db.close.bind(db);
30724
- db.prepare = (sql, ...rest) => {
30725
- const stmt = origPrepare(sql, ...rest);
30726
- tracked.add(stmt);
30752
+ return isBun2 ? finalizeOnClose(openBunDatabase(path13, opts)) : openNodeDatabase(path13, opts);
30753
+ }
30754
+ function finalizeOnClose(db) {
30755
+ const live = new Set;
30756
+ const forget = new FinalizationRegistry((ref) => live.delete(ref));
30757
+ const prepare = db.prepare.bind(db);
30758
+ const close = db.close.bind(db);
30759
+ db.prepare = (sql) => {
30760
+ const stmt = prepare(sql);
30761
+ const ref = new WeakRef(stmt);
30762
+ live.add(ref);
30763
+ forget.register(stmt, ref);
30727
30764
  return stmt;
30728
30765
  };
30729
- db.close = (...args) => {
30730
- for (const stmt of tracked) {
30766
+ db.close = () => {
30767
+ for (const ref of live) {
30731
30768
  try {
30732
- stmt.finalize?.();
30769
+ ref.deref()?.finalize?.();
30733
30770
  } catch {}
30734
30771
  }
30735
- tracked.clear();
30736
- return origClose(...args);
30772
+ live.clear();
30773
+ close();
30737
30774
  };
30738
30775
  return db;
30739
30776
  }
@@ -30902,7 +30939,7 @@ function openSqliteReadSnapshot(dbPath) {
30902
30939
  let db;
30903
30940
  try {
30904
30941
  copySqliteSnapshot(dbPath, snapshotPath);
30905
- db = openDatabaseFinalizing(snapshotPath, { readonly: true, create: false });
30942
+ db = openDatabase(snapshotPath, { readonly: true, create: false });
30906
30943
  const closeSnapshot = db.close.bind(db);
30907
30944
  let closed = false;
30908
30945
  const cleanup = (bestEffort) => {
@@ -32722,7 +32759,7 @@ function sameEndpoint(a, b) {
32722
32759
  }
32723
32760
  var OPERATION_SUFFIX;
32724
32761
  var init_endpoint_url = __esm(() => {
32725
- OPERATION_SUFFIX = /\/(?:chat\/completions|embeddings)$/;
32762
+ OPERATION_SUFFIX = /\/(?:chat\/completions|completions|embeddings|models)$/i;
32726
32763
  });
32727
32764
 
32728
32765
  // src/core/config/credentials.ts
@@ -35190,16 +35227,34 @@ function migrateStateDatabase(db, dbPath) {
35190
35227
  db.exec("VACUUM");
35191
35228
  return backupPath ? { applied, backupPath } : { applied };
35192
35229
  }
35230
+ function isStateDbCorruption(error62) {
35231
+ const code = error62?.code;
35232
+ if (code === "SQLITE_NOTADB" || code === "SQLITE_CORRUPT" || code === "SQLITE_IOERR_SHORT_READ")
35233
+ return true;
35234
+ return /not a database|disk image is malformed|SQLITE_CORRUPT/i.test(error62 instanceof Error ? error62.message : String(error62));
35235
+ }
35236
+ function classifyStateDbError(error62, dbPath) {
35237
+ if (error62 instanceof ConfigError || !isStateDbCorruption(error62))
35238
+ return error62;
35239
+ return damagedStateDbError(dbPath, error62 instanceof Error ? error62.message : String(error62));
35240
+ }
35241
+ function damagedStateDbError(dbPath, detail) {
35242
+ return new ConfigError(`state.db at ${dbPath} is damaged (${detail}).`, "INVALID_CONFIG_FILE", "state.db holds non-regenerable state. Back it up, then recover it with " + '`sqlite3 -readonly state.db ".recover" | sqlite3 state.new.db`, or restore a copy; if nothing can be recovered, move it aside and the next akm command creates a new one.');
35243
+ }
35193
35244
  function openAndMigrate(dbPath) {
35194
35245
  let report = { applied: [] };
35195
- const db = openManagedDatabase({
35196
- path: dbPath,
35197
- pragmas: { dataDir: path23.dirname(dbPath) },
35198
- init: (handle) => {
35199
- report = migrateStateDatabase(handle, dbPath);
35200
- }
35201
- });
35202
- return { db, ...report };
35246
+ try {
35247
+ const db = openManagedDatabase({
35248
+ path: dbPath,
35249
+ pragmas: { dataDir: path23.dirname(dbPath) },
35250
+ init: (handle) => {
35251
+ report = migrateStateDatabase(handle, dbPath);
35252
+ }
35253
+ });
35254
+ return { db, ...report };
35255
+ } catch (error62) {
35256
+ throw classifyStateDbError(error62, dbPath);
35257
+ }
35203
35258
  }
35204
35259
  function listPendingStateMigrations(dbPath = getStateDbPath()) {
35205
35260
  if (!fs20.existsSync(dbPath))
@@ -35227,6 +35282,7 @@ var init_state_db = __esm(() => {
35227
35282
  init_sqlite_migrations();
35228
35283
  init_sqlite_pragmas();
35229
35284
  init_version2();
35285
+ init_errors();
35230
35286
  init_paths();
35231
35287
  init_migrations();
35232
35288
  init_warn();
@@ -69436,7 +69492,6 @@ var init_website_ingest = __esm(() => {
69436
69492
  });
69437
69493
 
69438
69494
  // src/indexer/search/search-source.ts
69439
- import fs47 from "node:fs";
69440
69495
  import path54 from "node:path";
69441
69496
  function implicitStashDir(config2, overrideStashDir) {
69442
69497
  if (overrideStashDir !== undefined)
@@ -69453,21 +69508,13 @@ function resolveSourceEntries(overrideStashDir, existingConfig) {
69453
69508
  if (implicitConfiguredBundle && !isBundleEnabled(config2, implicitConfiguredBundle)) {
69454
69509
  throw new ConfigError(`The requested working source is disabled as bundle ${JSON.stringify(implicitConfiguredBundle)}.`, "INVALID_CONFIG_FILE");
69455
69510
  }
69456
- const sources = implicitStash ? [{ path: implicitStash, writable: true, isDefault: true, type: "filesystem" }] : [];
69457
- const sourceIdentity = (dir) => {
69458
- const resolved = path54.resolve(dir);
69459
- try {
69460
- return fs47.realpathSync.native(resolved);
69461
- } catch {
69462
- return resolved;
69463
- }
69464
- };
69465
- const seen = new Set(implicitStash ? [sourceIdentity(implicitStash)] : []);
69511
+ const sources = implicitStash ? [{ path: safeRealpath(implicitStash), writable: true, isDefault: true, type: "filesystem" }] : [];
69512
+ const seen = new Set(implicitStash ? [safeRealpath(implicitStash)] : []);
69466
69513
  const addSource = (dir, registryId, writable, type, adapterId, unresolved = false, isDefault = false) => {
69467
69514
  const resolved = path54.resolve(dir);
69468
- const identity3 = sourceIdentity(resolved);
69515
+ const identity3 = safeRealpath(resolved);
69469
69516
  if (seen.has(identity3)) {
69470
- const existing = sources.find((source) => sourceIdentity(source.path) === identity3);
69517
+ const existing = sources.find((source) => safeRealpath(source.path) === identity3);
69471
69518
  if (existing && existing.registryId === undefined) {
69472
69519
  if (registryId)
69473
69520
  existing.registryId = registryId;
@@ -69486,7 +69533,7 @@ function resolveSourceEntries(overrideStashDir, existingConfig) {
69486
69533
  warn(`Warning: stash root "${dir}" appears to be a system directory. This may be unintentional.`);
69487
69534
  }
69488
69535
  sources.push({
69489
- path: resolved,
69536
+ path: identity3,
69490
69537
  ...registryId ? { registryId } : {},
69491
69538
  ...isDefault ? { isDefault: true } : {},
69492
69539
  writable,
@@ -69571,6 +69618,7 @@ var init_search_source = __esm(() => {
69571
69618
  // src/registry/origin-resolve.ts
69572
69619
  var init_origin_resolve = __esm(() => {
69573
69620
  init_asset_ref();
69621
+ init_common();
69574
69622
  init_installations();
69575
69623
  init_resolve();
69576
69624
  });
@@ -69642,9 +69690,9 @@ var init_env_secret_ref = __esm(() => {
69642
69690
  });
69643
69691
 
69644
69692
  // src/core/secret-value.ts
69645
- import fs48 from "node:fs";
69693
+ import fs47 from "node:fs";
69646
69694
  function readValue(secretPath) {
69647
- return fs48.readFileSync(secretPath, "utf8").trim();
69695
+ return fs47.readFileSync(secretPath, "utf8").trim();
69648
69696
  }
69649
69697
  var init_secret_value = () => {};
69650
69698
 
@@ -72858,7 +72906,7 @@ init_secret_seam();
72858
72906
 
72859
72907
  // scripts/akm-migrate/migrate/dead-residue.ts
72860
72908
  init_paths();
72861
- import fs49 from "node:fs";
72909
+ import fs48 from "node:fs";
72862
72910
  import path55 from "node:path";
72863
72911
  var DEAD_RESIDUE_PATHS = [
72864
72912
  { name: "proposals", reason: "superseded by the `proposals` table in $DATA/state.db (0.9.0)" },
@@ -72876,7 +72924,7 @@ function dirSizeBytes(target) {
72876
72924
  let total = 0;
72877
72925
  let entries;
72878
72926
  try {
72879
- entries = fs49.readdirSync(target, { withFileTypes: true });
72927
+ entries = fs48.readdirSync(target, { withFileTypes: true });
72880
72928
  } catch {
72881
72929
  return 0;
72882
72930
  }
@@ -72886,14 +72934,14 @@ function dirSizeBytes(target) {
72886
72934
  total += dirSizeBytes(entryPath);
72887
72935
  } else if (entry.isFile()) {
72888
72936
  try {
72889
- total += fs49.statSync(entryPath).size;
72937
+ total += fs48.statSync(entryPath).size;
72890
72938
  } catch {}
72891
72939
  }
72892
72940
  }
72893
72941
  return total;
72894
72942
  }
72895
72943
  function sizeOf(target) {
72896
- const st2 = fs49.statSync(target);
72944
+ const st2 = fs48.statSync(target);
72897
72945
  return st2.isDirectory() ? dirSizeBytes(target) : st2.size;
72898
72946
  }
72899
72947
  function hostResidue() {
@@ -72912,7 +72960,7 @@ function hostResidue() {
72912
72960
  const found = [];
72913
72961
  const claimed = new Set;
72914
72962
  for (const entry of named) {
72915
- if (claimed.has(entry.absolutePath) || !fs49.existsSync(entry.absolutePath))
72963
+ if (claimed.has(entry.absolutePath) || !fs48.existsSync(entry.absolutePath))
72916
72964
  continue;
72917
72965
  try {
72918
72966
  found.push({ ...entry, relativePath: entry.absolutePath, sizeBytes: sizeOf(entry.absolutePath) });
@@ -72936,7 +72984,7 @@ function hostResidue() {
72936
72984
  function findSidecars(root, depth, skip) {
72937
72985
  let entries;
72938
72986
  try {
72939
- entries = fs49.readdirSync(root, { withFileTypes: true });
72987
+ entries = fs48.readdirSync(root, { withFileTypes: true });
72940
72988
  } catch {
72941
72989
  return [];
72942
72990
  }
@@ -72958,7 +73006,7 @@ function findDeadResidueEntries(stashDir) {
72958
73006
  const akmDir = path55.join(stashDir, ".akm");
72959
73007
  let names;
72960
73008
  try {
72961
- names = fs49.readdirSync(akmDir);
73009
+ names = fs48.readdirSync(akmDir);
72962
73010
  } catch {
72963
73011
  return host;
72964
73012
  }
@@ -72984,7 +73032,7 @@ function removeDeadResidue(stashDir) {
72984
73032
  const entries = findDeadResidueEntries(stashDir);
72985
73033
  return entries.map((entry) => {
72986
73034
  try {
72987
- fs49.rmSync(entry.absolutePath, { recursive: true, force: true });
73035
+ fs48.rmSync(entry.absolutePath, { recursive: true, force: true });
72988
73036
  return { relativePath: entry.relativePath, sizeBytes: entry.sizeBytes, removed: true };
72989
73037
  } catch (error62) {
72990
73038
  return {
@@ -73014,7 +73062,7 @@ init_errors();
73014
73062
  init_write_source();
73015
73063
  init_search_source();
73016
73064
  init_lockfile();
73017
- import fs50 from "node:fs";
73065
+ import fs49 from "node:fs";
73018
73066
  import os10 from "node:os";
73019
73067
  import path56 from "node:path";
73020
73068
  function expandTilde(value) {
@@ -73026,7 +73074,7 @@ function expandTilde(value) {
73026
73074
  }
73027
73075
  function existingDirectory(target) {
73028
73076
  try {
73029
- return fs50.statSync(target).isDirectory();
73077
+ return fs49.statSync(target).isDirectory();
73030
73078
  } catch (cause) {
73031
73079
  if (cause.code === "ENOENT")
73032
73080
  return false;
@@ -73277,14 +73325,14 @@ function planEngineKeys(inputs, resolve) {
73277
73325
 
73278
73326
  // scripts/akm-migrate/migrate/engine-key-files.ts
73279
73327
  init_walker();
73280
- import fs52 from "node:fs";
73328
+ import fs51 from "node:fs";
73281
73329
  import path59 from "node:path";
73282
73330
 
73283
73331
  // scripts/akm-migrate/migrate/task-files.ts
73284
73332
  init_errors();
73285
73333
  init_task_source_v4();
73286
73334
  import crypto5 from "node:crypto";
73287
- import fs51 from "node:fs";
73335
+ import fs50 from "node:fs";
73288
73336
  import path58 from "node:path";
73289
73337
 
73290
73338
  // scripts/akm-migrate/migrate/task-to-v4.ts
@@ -74342,14 +74390,14 @@ function contained(root, candidate) {
74342
74390
  return relative === "" || !relative.startsWith("..") && !path58.isAbsolute(relative);
74343
74391
  }
74344
74392
  function realDirectory(filePath) {
74345
- const stat = fs51.lstatSync(filePath);
74393
+ const stat = fs50.lstatSync(filePath);
74346
74394
  if (stat.isSymbolicLink() || !stat.isDirectory())
74347
74395
  throw migrationError(`${filePath} must be a real directory.`);
74348
- return fs51.realpathSync(filePath);
74396
+ return fs50.realpathSync(filePath);
74349
74397
  }
74350
74398
  function isWritable(filePath) {
74351
74399
  try {
74352
- fs51.accessSync(filePath, fs51.constants.W_OK);
74400
+ fs50.accessSync(filePath, fs50.constants.W_OK);
74353
74401
  return true;
74354
74402
  } catch {
74355
74403
  return false;
@@ -74362,11 +74410,11 @@ function walkRootFiles(root, directory, extension, onLink, visit3) {
74362
74410
  throw migrationError(`${root.root} resolves outside bundle ${root.bundleId}.`);
74363
74411
  }
74364
74412
  const walk = (current) => {
74365
- const physicalDirectory = fs51.realpathSync(current);
74413
+ const physicalDirectory = fs50.realpathSync(current);
74366
74414
  if (!contained(physicalRoot, physicalDirectory)) {
74367
74415
  throw migrationError(`${current} resolves outside bundle ${root.bundleId}.`);
74368
74416
  }
74369
- for (const entry of fs51.readdirSync(current, { withFileTypes: true }).sort((a3, b) => a3.name.localeCompare(b.name))) {
74417
+ for (const entry of fs50.readdirSync(current, { withFileTypes: true }).sort((a3, b) => a3.name.localeCompare(b.name))) {
74370
74418
  const candidate = path58.join(current, entry.name);
74371
74419
  if (entry.isSymbolicLink()) {
74372
74420
  onLink(candidate);
@@ -74386,11 +74434,11 @@ function walkTasks(root, tasksDir, out) {
74386
74434
  walkRootFiles(root, tasksDir, ".yml", (link) => {
74387
74435
  throw migrationError(`task migration does not follow symbolic link ${link}.`);
74388
74436
  }, (candidate, directory) => {
74389
- const stat = fs51.lstatSync(candidate);
74437
+ const stat = fs50.lstatSync(candidate);
74390
74438
  const mode = stat.mode & 511;
74391
74439
  out.push({
74392
74440
  filePath: candidate,
74393
- bytes: fs51.readFileSync(candidate),
74441
+ bytes: fs50.readFileSync(candidate),
74394
74442
  mode,
74395
74443
  writable: root.writable,
74396
74444
  onDiskWritable: isWritable(candidate) && isWritable(directory) && (mode & 146) !== 0
@@ -74402,7 +74450,7 @@ function inspectTaskFiles(roots) {
74402
74450
  for (const root of [...roots].sort((a3, b) => a3.bundleId.localeCompare(b.bundleId))) {
74403
74451
  const tasksDir = root.layout === "akm-task" ? root.root : path58.join(root.root, "tasks");
74404
74452
  try {
74405
- const stat = fs51.lstatSync(tasksDir);
74453
+ const stat = fs50.lstatSync(tasksDir);
74406
74454
  if (stat.isSymbolicLink())
74407
74455
  throw migrationError(`task migration does not follow symbolic link ${tasksDir}.`);
74408
74456
  if (!stat.isDirectory())
@@ -74427,11 +74475,11 @@ function fsyncDirectory(directory) {
74427
74475
  if (process.platform === "win32")
74428
74476
  return;
74429
74477
  try {
74430
- const fd = fs51.openSync(directory, "r");
74478
+ const fd = fs50.openSync(directory, "r");
74431
74479
  try {
74432
- fs51.fsyncSync(fd);
74480
+ fs50.fsyncSync(fd);
74433
74481
  } finally {
74434
- fs51.closeSync(fd);
74482
+ fs50.closeSync(fd);
74435
74483
  }
74436
74484
  } catch (cause) {
74437
74485
  const code = cause.code;
@@ -74440,30 +74488,30 @@ function fsyncDirectory(directory) {
74440
74488
  }
74441
74489
  }
74442
74490
  function writeDurable(filePath, bytes, mode, exclusive = false) {
74443
- fs51.mkdirSync(path58.dirname(filePath), { recursive: true });
74444
- const fd = fs51.openSync(filePath, exclusive ? "wx" : "w", mode);
74491
+ fs50.mkdirSync(path58.dirname(filePath), { recursive: true });
74492
+ const fd = fs50.openSync(filePath, exclusive ? "wx" : "w", mode);
74445
74493
  try {
74446
- fs51.writeFileSync(fd, bytes);
74447
- fs51.fsyncSync(fd);
74494
+ fs50.writeFileSync(fd, bytes);
74495
+ fs50.fsyncSync(fd);
74448
74496
  } finally {
74449
- fs51.closeSync(fd);
74497
+ fs50.closeSync(fd);
74450
74498
  }
74451
- fs51.chmodSync(filePath, mode);
74499
+ fs50.chmodSync(filePath, mode);
74452
74500
  fsyncDirectory(path58.dirname(filePath));
74453
74501
  }
74454
74502
  function replaceAtomically(filePath, bytes, mode) {
74455
74503
  const temporary = path58.join(path58.dirname(filePath), `.${path58.basename(filePath)}.migrate-${crypto5.randomUUID()}`);
74456
74504
  try {
74457
74505
  writeDurable(temporary, bytes, mode, true);
74458
- fs51.renameSync(temporary, filePath);
74506
+ fs50.renameSync(temporary, filePath);
74459
74507
  fsyncDirectory(path58.dirname(filePath));
74460
74508
  } finally {
74461
- fs51.rmSync(temporary, { force: true });
74509
+ fs50.rmSync(temporary, { force: true });
74462
74510
  }
74463
74511
  }
74464
74512
  function holds(filePath, bytes) {
74465
74513
  try {
74466
- return fs51.readFileSync(filePath).equals(bytes);
74514
+ return fs50.readFileSync(filePath).equals(bytes);
74467
74515
  } catch {
74468
74516
  return false;
74469
74517
  }
@@ -74483,7 +74531,7 @@ function replaceFilesWithBackups(changes, backupRoot) {
74483
74531
  try {
74484
74532
  for (const change of backedUp) {
74485
74533
  if (!holds(change.filePath, change.before)) {
74486
- fs51.rmSync(taskFileBackupPath(backupRoot, change.filePath), { force: true });
74534
+ fs50.rmSync(taskFileBackupPath(backupRoot, change.filePath), { force: true });
74487
74535
  conflicts.push(change.filePath);
74488
74536
  continue;
74489
74537
  }
@@ -74494,7 +74542,7 @@ function replaceFilesWithBackups(changes, backupRoot) {
74494
74542
  const unrestored = [];
74495
74543
  for (const change of [...replaced].reverse()) {
74496
74544
  if (holds(change.filePath, change.after)) {
74497
- replaceAtomically(change.filePath, fs51.readFileSync(taskFileBackupPath(backupRoot, change.filePath)), change.mode);
74545
+ replaceAtomically(change.filePath, fs50.readFileSync(taskFileBackupPath(backupRoot, change.filePath)), change.mode);
74498
74546
  } else {
74499
74547
  unrestored.push(change.filePath);
74500
74548
  }
@@ -74540,7 +74588,7 @@ var LAYOUTS = new Map([
74540
74588
  function collect(root, directory, role, extension, out) {
74541
74589
  let top;
74542
74590
  try {
74543
- top = fs52.lstatSync(directory);
74591
+ top = fs51.lstatSync(directory);
74544
74592
  } catch (cause) {
74545
74593
  if (cause.code === "ENOENT")
74546
74594
  return;
@@ -74553,8 +74601,8 @@ function collect(root, directory, role, extension, out) {
74553
74601
  return;
74554
74602
  out.set(link, {
74555
74603
  filePath: link,
74556
- bytes: fs52.readFileSync(link),
74557
- mode: fs52.statSync(link).mode & 511,
74604
+ bytes: fs51.readFileSync(link),
74605
+ mode: fs51.statSync(link).mode & 511,
74558
74606
  role,
74559
74607
  writable: root.writable,
74560
74608
  link: true
@@ -74564,8 +74612,8 @@ function collect(root, directory, role, extension, out) {
74564
74612
  return;
74565
74613
  out.set(candidate, {
74566
74614
  filePath: candidate,
74567
- bytes: fs52.readFileSync(candidate),
74568
- mode: fs52.lstatSync(candidate).mode & 511,
74615
+ bytes: fs51.readFileSync(candidate),
74616
+ mode: fs51.lstatSync(candidate).mode & 511,
74569
74617
  role,
74570
74618
  writable: root.writable
74571
74619
  });
@@ -74698,7 +74746,7 @@ init_paths();
74698
74746
  init_walker();
74699
74747
  import { randomUUID as randomUUID4 } from "node:crypto";
74700
74748
  import { spawnSync as spawnSync6 } from "node:child_process";
74701
- import fs53 from "node:fs";
74749
+ import fs52 from "node:fs";
74702
74750
  import path61 from "node:path";
74703
74751
 
74704
74752
  // scripts/akm-migrate/migrate/content-ref-planner.ts
@@ -74762,7 +74810,7 @@ function contentRefRewriter(bundles) {
74762
74810
  // scripts/akm-migrate/content-ref-migrate.ts
74763
74811
  var TEXT_EXTENSIONS = new Set([".md", ".yml", ".yaml", ".sh", ".ts", ".js", ".json", ".txt", ".py", ".mjs", ".jsonc", ".toml", ""]);
74764
74812
  function textFiles(root) {
74765
- return walkStashFlat(root).filter((file2) => TEXT_EXTENSIONS.has(file2.ext) && fs53.lstatSync(file2.absPath).isFile()).map((file2) => file2.absPath);
74813
+ return walkStashFlat(root).filter((file2) => TEXT_EXTENSIONS.has(file2.ext) && fs52.lstatSync(file2.absPath).isFile()).map((file2) => file2.absPath);
74766
74814
  }
74767
74815
  function bundleDocuments(roots) {
74768
74816
  const bundles = new Map;
@@ -74798,7 +74846,7 @@ function gitReconcile(filePaths, backupPath) {
74798
74846
  const topOf = new Map;
74799
74847
  const byRoot = new Map;
74800
74848
  for (const filePath of filePaths) {
74801
- const real = fs53.realpathSync(filePath);
74849
+ const real = fs52.realpathSync(filePath);
74802
74850
  const dir = path61.dirname(real);
74803
74851
  if (!topOf.has(dir)) {
74804
74852
  const top = spawnSync6("git", ["-C", dir, "rev-parse", "--show-toplevel"], { encoding: "utf8", env });
@@ -74827,7 +74875,7 @@ function plan2() {
74827
74875
  if (seen.has(filePath) || !(documents.files.has(filePath) || isStructuralFile(root.root, adapterId, filePath, assetDirs)))
74828
74876
  continue;
74829
74877
  seen.add(filePath);
74830
- const before = fs53.readFileSync(filePath);
74878
+ const before = fs52.readFileSync(filePath);
74831
74879
  const text2 = before.toString("utf8");
74832
74880
  if (!Buffer.from(text2, "utf8").equals(before))
74833
74881
  continue;
@@ -74835,7 +74883,7 @@ function plan2() {
74835
74883
  if (count === 0)
74836
74884
  continue;
74837
74885
  files.push({
74838
- replacement: { filePath, before, after: Buffer.from(rewritten, "utf8"), mode: fs53.statSync(filePath).mode & 511 },
74886
+ replacement: { filePath, before, after: Buffer.from(rewritten, "utf8"), mode: fs52.statSync(filePath).mode & 511 },
74839
74887
  refs: count
74840
74888
  });
74841
74889
  }
@@ -74891,7 +74939,7 @@ init_config_io();
74891
74939
  init_errors();
74892
74940
  init_paths();
74893
74941
  import { randomUUID as randomUUID5 } from "node:crypto";
74894
- import fs54 from "node:fs";
74942
+ import fs53 from "node:fs";
74895
74943
  import path62 from "node:path";
74896
74944
  function taskRoots(config2) {
74897
74945
  return bundleRoots(config2).flatMap((root) => {
@@ -74903,7 +74951,7 @@ function taskRoot(candidate) {
74903
74951
  const { bundleId, bundleRoot, root, writable } = candidate;
74904
74952
  const adapter = candidate.adapter ?? detectAdapterId(root, "");
74905
74953
  if (!candidate.adapter && adapter === "") {
74906
- const flatTasks = fs54.readdirSync(root, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".yml")).map((entry) => entry.name).sort();
74954
+ const flatTasks = fs53.readdirSync(root, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".yml")).map((entry) => entry.name).sort();
74907
74955
  if (flatTasks.length > 0) {
74908
74956
  throw new ConfigError(`Task migration cannot classify top-level task file(s) ${flatTasks.join(", ")} in bundle ${bundleId}; configure adapter "akm-task" or move them under tasks/.`, "INVALID_CONFIG_FILE");
74909
74957
  }