caveat-cli 0.17.2 → 0.17.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.
@@ -15233,6 +15233,23 @@ function createKeyserverKeyProvider(opts) {
15233
15233
  };
15234
15234
  }
15235
15235
 
15236
+ // ../../packages/core/dist/platform.js
15237
+ function isWindows(platform = process.platform) {
15238
+ return platform === "win32";
15239
+ }
15240
+ function isPrivateOwnerStat(stat, uid, platform = process.platform) {
15241
+ return isWindows(platform) || (stat.mode & 63) === 0 && (uid === void 0 || stat.uid === uid);
15242
+ }
15243
+ function powershellCallPrefix(platform = process.platform) {
15244
+ return isWindows(platform) ? "& " : "";
15245
+ }
15246
+ function nodeExecutableNames(platform = process.platform) {
15247
+ return isWindows(platform) ? ["node.exe", "node.cmd", "node.bat", "node"] : ["node"];
15248
+ }
15249
+ function normalizePathCase(normalizedPath, platform = process.platform) {
15250
+ return isWindows(platform) ? normalizedPath.toLowerCase() : normalizedPath;
15251
+ }
15252
+
15236
15253
  // ../../packages/core/dist/sync.js
15237
15254
  import { existsSync as existsSync8, mkdirSync as mkdirSync5, readdirSync as readdirSync7, realpathSync, rmSync as rmSync4, writeFileSync as writeFileSync4 } from "node:fs";
15238
15255
  import { dirname as dirname4, join as join8, resolve } from "node:path";
@@ -15292,8 +15309,7 @@ var SyncError = class extends Error {
15292
15309
  code;
15293
15310
  };
15294
15311
  function normalizePath(path) {
15295
- const normalized = resolve(path).replace(/\\/g, "/");
15296
- return process.platform === "win32" ? normalized.toLowerCase() : normalized;
15312
+ return normalizePathCase(resolve(path).replace(/\\/g, "/"));
15297
15313
  }
15298
15314
  async function effectivePushUrls(git) {
15299
15315
  let raw;
@@ -16491,73 +16507,6 @@ function markHit(db, keys, now2 = () => (/* @__PURE__ */ new Date()).toISOString
16491
16507
  }
16492
16508
  }
16493
16509
 
16494
- // ../../packages/core/dist/hookQueryLog.js
16495
- import { appendFileSync, chmodSync as chmodSync2, mkdirSync as mkdirSync7, renameSync as renameSync4, statSync as statSync7, unlinkSync as unlinkSync3 } from "node:fs";
16496
- import { join as join11, resolve as resolve3 } from "node:path";
16497
- var CAVEAT_HOOK_QUERY_LOG_ENV = "CAVEAT_HOOK_QUERY_LOG";
16498
- var HOOK_QUERY_LOG_MAX_BYTES = 1024 * 1024;
16499
- var HOOK_QUERY_LOG_MAX_QUERY_CODE_UNITS = 1e3;
16500
- var fsDependencies = {
16501
- appendFileSync,
16502
- chmodSync: chmodSync2,
16503
- mkdirSync: mkdirSync7,
16504
- renameSync: renameSync4,
16505
- statSync: statSync7,
16506
- unlinkSync: unlinkSync3
16507
- };
16508
- function isMissingPathError(err) {
16509
- return err instanceof Error && "code" in err && err.code === "ENOENT";
16510
- }
16511
- function chmodExistingFile(path, dependencies) {
16512
- try {
16513
- dependencies.chmodSync(path, 384);
16514
- } catch (err) {
16515
- if (!isMissingPathError(err)) throw err;
16516
- }
16517
- }
16518
- function logHookQueryMiss(miss, dependencies = fsDependencies) {
16519
- if (process.env[CAVEAT_HOOK_QUERY_LOG_ENV] !== "on") return;
16520
- const metricsDir = join11(resolve3(miss.caveatHome), "metrics");
16521
- const activePath = join11(metricsDir, "hook-search-misses.jsonl");
16522
- const backupPath = `${activePath}.1`;
16523
- const record = JSON.stringify({
16524
- at: (/* @__PURE__ */ new Date()).toISOString(),
16525
- agent: miss.agent,
16526
- surface: miss.surface,
16527
- query: miss.query.slice(0, HOOK_QUERY_LOG_MAX_QUERY_CODE_UNITS)
16528
- }) + "\n";
16529
- dependencies.mkdirSync(metricsDir, { recursive: true, mode: 448 });
16530
- dependencies.chmodSync(metricsDir, 448);
16531
- chmodExistingFile(activePath, dependencies);
16532
- chmodExistingFile(backupPath, dependencies);
16533
- let activeSize = 0;
16534
- try {
16535
- activeSize = dependencies.statSync(activePath).size;
16536
- } catch (err) {
16537
- if (!isMissingPathError(err)) throw err;
16538
- }
16539
- if (activeSize + Buffer.byteLength(record, "utf8") > HOOK_QUERY_LOG_MAX_BYTES) {
16540
- try {
16541
- dependencies.unlinkSync(backupPath);
16542
- } catch (err) {
16543
- if (!isMissingPathError(err)) throw err;
16544
- }
16545
- try {
16546
- dependencies.renameSync(activePath, backupPath);
16547
- dependencies.chmodSync(backupPath, 384);
16548
- } catch (err) {
16549
- if (!isMissingPathError(err)) throw err;
16550
- }
16551
- }
16552
- dependencies.appendFileSync(activePath, record, { encoding: "utf8", mode: 384 });
16553
- dependencies.chmodSync(activePath, 384);
16554
- try {
16555
- dependencies.chmodSync(backupPath, 384);
16556
- } catch (err) {
16557
- if (!isMissingPathError(err)) throw err;
16558
- }
16559
- }
16560
-
16561
16510
  // ../../packages/core/dist/stale.js
16562
16511
  function listStale(db, opts = {}) {
16563
16512
  const days = opts.days ?? 90;
@@ -16591,7 +16540,7 @@ function listStale(db, opts = {}) {
16591
16540
  // ../../packages/core/dist/publishScan.js
16592
16541
  import { createHash as createHash5 } from "node:crypto";
16593
16542
  import { existsSync as existsSync14, readFileSync as readFileSync11, writeFileSync as writeFileSync7 } from "node:fs";
16594
- import { join as join12, basename as basename2 } from "node:path";
16543
+ import { join as join11, basename as basename2 } from "node:path";
16595
16544
  import { homedir as homedir2, userInfo as userInfo2 } from "node:os";
16596
16545
  var ALLOW_FILE = ".caveat-publish-allow.json";
16597
16546
  var DIGEST_RE = /^[a-f0-9]{64}$/;
@@ -16820,7 +16769,7 @@ function publishSelfIdentityTokens() {
16820
16769
  return out;
16821
16770
  }
16822
16771
  function loadPublishAllow(knowledgeRepo) {
16823
- const path = join12(knowledgeRepo, ALLOW_FILE);
16772
+ const path = join11(knowledgeRepo, ALLOW_FILE);
16824
16773
  if (!existsSync14(path)) return /* @__PURE__ */ new Set();
16825
16774
  const parsed = JSON.parse(readFileSync11(path, "utf-8"));
16826
16775
  if (!Array.isArray(parsed.allow)) throw new Error(`${ALLOW_FILE} must contain an "allow" array`);
@@ -16832,7 +16781,7 @@ function savePublishAllow(knowledgeRepo, digests) {
16832
16781
  if (DIGEST_RE.test(digestValue)) existing.add(digestValue);
16833
16782
  }
16834
16783
  const allow = [...existing].sort();
16835
- writeFileSync7(join12(knowledgeRepo, ALLOW_FILE), `${JSON.stringify({ allow }, null, 2)}
16784
+ writeFileSync7(join11(knowledgeRepo, ALLOW_FILE), `${JSON.stringify({ allow }, null, 2)}
16836
16785
  `, "utf-8");
16837
16786
  }
16838
16787
  var PublishScanError = class extends Error {
@@ -16851,8 +16800,8 @@ var PublishScanError = class extends Error {
16851
16800
 
16852
16801
  // ../../packages/core/dist/publish.js
16853
16802
  import { createHash as createHash6 } from "node:crypto";
16854
- import { existsSync as existsSync15, mkdirSync as mkdirSync8, readFileSync as readFileSync12, readdirSync as readdirSync8, rmSync as rmSync5, writeFileSync as writeFileSync8 } from "node:fs";
16855
- import { dirname as dirname7, join as join13, relative as relative3 } from "node:path";
16803
+ import { existsSync as existsSync15, mkdirSync as mkdirSync7, readFileSync as readFileSync12, readdirSync as readdirSync8, rmSync as rmSync5, writeFileSync as writeFileSync8 } from "node:fs";
16804
+ import { dirname as dirname7, join as join12, relative as relative3 } from "node:path";
16856
16805
 
16857
16806
  // ../../packages/core/dist/visibility.js
16858
16807
  function classifyVisibility(value) {
@@ -16889,7 +16838,7 @@ function collectPublishSet(entriesDir) {
16889
16838
  async function preparePublishMirror(opts) {
16890
16839
  const git = opts.git ?? createGit();
16891
16840
  if (!existsSync15(opts.mirrorDir)) {
16892
- mkdirSync8(dirname7(opts.mirrorDir), { recursive: true });
16841
+ mkdirSync7(dirname7(opts.mirrorDir), { recursive: true });
16893
16842
  await git.clone(opts.target, opts.mirrorDir);
16894
16843
  } else {
16895
16844
  const mirrorGit2 = createGit(opts.mirrorDir);
@@ -16941,17 +16890,17 @@ function buildSealedReadme(fileCount, files) {
16941
16890
  function writeSealedMirror(opts) {
16942
16891
  for (const item of readdirSync8(opts.mirrorDir, { withFileTypes: true })) {
16943
16892
  if (item.name === ".git") continue;
16944
- rmSync5(join13(opts.mirrorDir, item.name), { recursive: true, force: true });
16893
+ rmSync5(join12(opts.mirrorDir, item.name), { recursive: true, force: true });
16945
16894
  }
16946
- const bundlePath = join13(opts.mirrorDir, BUNDLE_RELPATH);
16947
- mkdirSync8(dirname7(bundlePath), { recursive: true });
16948
- writeFileSync8(join13(opts.mirrorDir, "README.md"), opts.readme, "utf-8");
16895
+ const bundlePath = join12(opts.mirrorDir, BUNDLE_RELPATH);
16896
+ mkdirSync7(dirname7(bundlePath), { recursive: true });
16897
+ writeFileSync8(join12(opts.mirrorDir, "README.md"), opts.readme, "utf-8");
16949
16898
  writeFileSync8(bundlePath, opts.bundle);
16950
16899
  }
16951
16900
  function* walkAllFiles(root) {
16952
16901
  for (const item of readdirSync8(root, { withFileTypes: true })) {
16953
16902
  if (item.name === ".git") continue;
16954
- const full = join13(root, item.name);
16903
+ const full = join12(root, item.name);
16955
16904
  if (item.isDirectory()) yield* walkAllFiles(full);
16956
16905
  else yield full;
16957
16906
  }
@@ -16963,11 +16912,11 @@ function verifySealedMirror(opts) {
16963
16912
  throw new Error(`publish mirror verification failed:
16964
16913
  unexpected sealed mirror tree: ${files.join(", ") || "(empty)"}`);
16965
16914
  }
16966
- const diskReadme = readFileSync12(join13(opts.mirrorDir, "README.md"), "utf-8");
16915
+ const diskReadme = readFileSync12(join12(opts.mirrorDir, "README.md"), "utf-8");
16967
16916
  if (diskReadme !== opts.readme) {
16968
16917
  throw new Error("publish mirror verification failed: README.md content changed after generation");
16969
16918
  }
16970
- const diskBundle = readFileSync12(join13(opts.mirrorDir, BUNDLE_RELPATH));
16919
+ const diskBundle = readFileSync12(join12(opts.mirrorDir, BUNDLE_RELPATH));
16971
16920
  if (!diskBundle.equals(opts.bundle)) {
16972
16921
  throw new Error("publish mirror verification failed: sealed bundle bytes changed after generation");
16973
16922
  }
@@ -17058,8 +17007,8 @@ async function commitSealedMirror(opts) {
17058
17007
  await opts.git.raw(["gc", "--prune=now"]).catch(() => "");
17059
17008
  }
17060
17009
  function readExistingMirror(mirrorDir) {
17061
- const readmePath = join13(mirrorDir, "README.md");
17062
- const bundlePath = join13(mirrorDir, BUNDLE_RELPATH);
17010
+ const readmePath = join12(mirrorDir, "README.md");
17011
+ const bundlePath = join12(mirrorDir, BUNDLE_RELPATH);
17063
17012
  return {
17064
17013
  readme: existsSync15(readmePath) ? readFileSync12(readmePath, "utf-8") : null,
17065
17014
  bundle: existsSync15(bundlePath) ? readFileSync12(bundlePath) : null
@@ -17353,9 +17302,9 @@ function boundedCount(value) {
17353
17302
  // ../../packages/core/dist/runtimeErrors.js
17354
17303
  import { spawnSync } from "node:child_process";
17355
17304
  import { createHash as createHash7, randomBytes as randomBytes3 } from "node:crypto";
17356
- import { closeSync as closeSync2, constants, existsSync as existsSync16, fstatSync, lstatSync, mkdirSync as mkdirSync9, openSync as openSync2, readFileSync as readFileSync13, renameSync as renameSync5, rmSync as rmSync6, statSync as statSync8, writeFileSync as writeFileSync9 } from "node:fs";
17305
+ import { closeSync as closeSync2, constants, existsSync as existsSync16, fstatSync, lstatSync, mkdirSync as mkdirSync8, openSync as openSync2, readFileSync as readFileSync13, renameSync as renameSync4, rmSync as rmSync6, statSync as statSync7, writeFileSync as writeFileSync9 } from "node:fs";
17357
17306
  import { arch as hostArch, homedir as homedir3, platform as hostPlatform } from "node:os";
17358
- import { dirname as dirname8, join as join14 } from "node:path";
17307
+ import { dirname as dirname8, join as join13 } from "node:path";
17359
17308
  import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
17360
17309
  var RUNTIME_ERRORS_SCHEMA = "caveat.runtime_errors.v1";
17361
17310
  var STATE_VERSION = "1.0";
@@ -17380,14 +17329,14 @@ var validTime = (v) => typeof v === "string" && Number.isFinite(Date.parse(v)) &
17380
17329
  var validVersion = (v) => typeof v === "string" && /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/.test(v);
17381
17330
  var validOs = (v) => typeof v === "string" && ["darwin", "linux", "windows"].includes(v);
17382
17331
  var validArch = (v) => typeof v === "string" && ["x64", "arm64", "arm", "ia32"].includes(v);
17383
- var windows = (env) => env.OS === "Windows_NT" || hostPlatform() === "win32";
17332
+ var windows = (env) => env.OS === "Windows_NT" || isWindows(hostPlatform());
17384
17333
  function defaultFactoryReporterConfigPath(env = process.env) {
17385
17334
  const home = env.HOME || env.USERPROFILE || homedir3();
17386
- return windows(env) ? join14(env.LOCALAPPDATA || join14(home, "AppData", "Local"), "dotagents", "factory-reporter", "config.json") : join14(env.XDG_CONFIG_HOME || join14(home, ".config"), "dotagents", "factory-reporter.json");
17335
+ return windows(env) ? join13(env.LOCALAPPDATA || join13(home, "AppData", "Local"), "dotagents", "factory-reporter", "config.json") : join13(env.XDG_CONFIG_HOME || join13(home, ".config"), "dotagents", "factory-reporter.json");
17387
17336
  }
17388
17337
  function runtimeErrorsStatePath(env = process.env) {
17389
17338
  const home = env.HOME || env.USERPROFILE || homedir3();
17390
- return windows(env) ? join14(env.LOCALAPPDATA || join14(home, "AppData", "Local"), "caveat", "runtime-errors.json") : join14(env.XDG_STATE_HOME || join14(home, ".local", "state"), "caveat", "runtime-errors.json");
17339
+ return windows(env) ? join13(env.LOCALAPPDATA || join13(home, "AppData", "Local"), "caveat", "runtime-errors.json") : join13(env.XDG_STATE_HOME || join13(home, ".local", "state"), "caveat", "runtime-errors.json");
17391
17340
  }
17392
17341
  function collectionEnabled(options2 = {}) {
17393
17342
  const env = options2.env ?? process.env;
@@ -17421,7 +17370,7 @@ function fingerprint(code) {
17421
17370
  }
17422
17371
  function ensureSafeDir(dir, isWin, options2 = {}) {
17423
17372
  const existed = existsSync16(dir);
17424
- mkdirSync9(dir, { recursive: true, mode: 448 });
17373
+ mkdirSync8(dir, { recursive: true, mode: 448 });
17425
17374
  const s = lstatSync(dir);
17426
17375
  if (!s.isDirectory() || s.isSymbolicLink()) throw Error("store_unsafe");
17427
17376
  if (isWin) secureWindowsAcl(dir, options2.aclRunner, true, !existed);
@@ -17442,9 +17391,9 @@ function canonicalReporting(value) {
17442
17391
  }
17443
17392
  var WINDOWS_ACL_VERIFY = String.raw`$p=$env:CAVEAT_ACL_PATH;$isDir=$env:CAVEAT_ACL_DIRECTORY -eq '1';$sid=[System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value;$acl=if($isDir){[System.IO.Directory]::GetAccessControl($p)}else{[System.IO.File]::GetAccessControl($p)};$owner=$acl.GetOwner([System.Security.Principal.SecurityIdentifier]).Value;if($owner -ne $sid){exit 41};$rules=@($acl.GetAccessRules($true,$true,[System.Security.Principal.SecurityIdentifier]));if($rules.Count -ne 1){exit 42};$r=$rules[0];if($r.IdentityReference.Value -ne $sid -or $r.AccessControlType -ne 'Allow' -or $r.IsInherited -or ($r.FileSystemRights -band [System.Security.AccessControl.FileSystemRights]::FullControl) -ne [System.Security.AccessControl.FileSystemRights]::FullControl){exit 43}`;
17444
17393
  var WINDOWS_ACL_APPLY = String.raw`$p=$env:CAVEAT_ACL_PATH;$isDir=$env:CAVEAT_ACL_DIRECTORY -eq '1';$sid=[System.Security.Principal.WindowsIdentity]::GetCurrent().User;$acl=if($isDir){New-Object System.Security.AccessControl.DirectorySecurity}else{New-Object System.Security.AccessControl.FileSecurity};$acl.SetAccessRuleProtection($true,$false);$flags=if($isDir){[System.Security.AccessControl.InheritanceFlags]'ContainerInherit, ObjectInherit'}else{[System.Security.AccessControl.InheritanceFlags]::None};$rule=New-Object System.Security.AccessControl.FileSystemAccessRule($sid,'FullControl',$flags,[System.Security.AccessControl.PropagationFlags]::None,[System.Security.AccessControl.AccessControlType]::Allow);$acl.SetOwner($sid);$acl.AddAccessRule($rule);if($isDir){[System.IO.Directory]::SetAccessControl($p,$acl)}else{[System.IO.File]::SetAccessControl($p,$acl)};` + WINDOWS_ACL_VERIFY;
17445
- var WINDOWS_ACL_TIMEOUT_MS = 15e3;
17394
+ var WINDOWS_ACL_TIMEOUT_MS = 3e4;
17446
17395
  function runWindowsAcl(path, directory, apply) {
17447
- const result = spawnSync("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", apply ? WINDOWS_ACL_APPLY : WINDOWS_ACL_VERIFY], { env: { ...process.env, CAVEAT_ACL_PATH: path, CAVEAT_ACL_DIRECTORY: directory ? "1" : "0" }, encoding: "utf-8", timeout: WINDOWS_ACL_TIMEOUT_MS, windowsHide: true });
17396
+ const result = spawnSync("powershell.exe", ["-NoLogo", "-NoProfile", "-NonInteractive", "-Command", apply ? WINDOWS_ACL_APPLY : WINDOWS_ACL_VERIFY], { env: { ...process.env, CAVEAT_ACL_PATH: path, CAVEAT_ACL_DIRECTORY: directory ? "1" : "0" }, encoding: "utf-8", timeout: WINDOWS_ACL_TIMEOUT_MS, windowsHide: true });
17448
17397
  if (result.error !== void 0) throw Error(`store_unsafe: powershell spawn ${result.error.code ?? result.error.message}`);
17449
17398
  if (result.status !== 0) throw Error(`store_unsafe: powershell exit=${result.status} signal=${result.signal ?? "none"} stderr=${(result.stderr ?? "").replace(/\s+/g, " ").trim().slice(0, 400) || "(empty)"}`);
17450
17399
  }
@@ -17462,7 +17411,7 @@ function ensureSafeFile(path, isWin, options2 = {}) {
17462
17411
  const s = lstatSync(path);
17463
17412
  if (!s.isFile() || s.isSymbolicLink()) throw Error("store_unsafe");
17464
17413
  if (isWin) secureWindowsAcl(path, options2.aclRunner);
17465
- else assertPosix(statSync8(path), 384);
17414
+ else assertPosix(statSync7(path), 384);
17466
17415
  }
17467
17416
  function validate(store) {
17468
17417
  if (!plain(store) || !exact(store, ["schema", "next_sequence", "acknowledged_through", "records"])) throw Error("state_invalid");
@@ -17498,7 +17447,7 @@ function lock(path, isWin, fn, options2 = {}) {
17498
17447
  }
17499
17448
  if (created) {
17500
17449
  if (isWin) secureWindowsAcl(lockPath2, options2.aclRunner, false, true);
17501
- else assertPosix(statSync8(lockPath2), 384);
17450
+ else assertPosix(statSync7(lockPath2), 384);
17502
17451
  } else ensureSafeFile(lockPath2, isWin, options2);
17503
17452
  const db = new DatabaseSync3(lockPath2);
17504
17453
  let begun = false;
@@ -17521,13 +17470,13 @@ function lock(path, isWin, fn, options2 = {}) {
17521
17470
  function writeStore(path, store, isWin, options2 = {}) {
17522
17471
  validate(store);
17523
17472
  ensureSafeDir(dirname8(path), isWin, options2);
17524
- const temporary = join14(dirname8(path), `.runtime-errors-${process.pid}-${randomBytes3(6).toString("hex")}`);
17473
+ const temporary = join13(dirname8(path), `.runtime-errors-${process.pid}-${randomBytes3(6).toString("hex")}`);
17525
17474
  try {
17526
17475
  writeFileSync9(temporary, `${JSON.stringify(store)}
17527
17476
  `, { mode: 384, flag: "wx" });
17528
17477
  if (isWin) secureWindowsAcl(temporary, options2.aclRunner, false, true);
17529
- else assertPosix(statSync8(temporary), 384);
17530
- renameSync5(temporary, path);
17478
+ else assertPosix(statSync7(temporary), 384);
17479
+ renameSync4(temporary, path);
17531
17480
  ensureSafeFile(path, isWin, options2);
17532
17481
  } finally {
17533
17482
  rmSync6(temporary, { force: true });
@@ -17703,7 +17652,7 @@ function generateSourceSession(now2 = () => /* @__PURE__ */ new Date()) {
17703
17652
  }
17704
17653
 
17705
17654
  // ../../packages/core/dist/writer.js
17706
- import { existsSync as existsSync17, mkdirSync as mkdirSync10, writeFileSync as writeFileSync10 } from "node:fs";
17655
+ import { existsSync as existsSync17, mkdirSync as mkdirSync9, writeFileSync as writeFileSync10 } from "node:fs";
17707
17656
  import { dirname as dirname9 } from "node:path";
17708
17657
  function buildEntry(frontmatter, sections) {
17709
17658
  const bodyParts = [];
@@ -17723,13 +17672,13 @@ ${body}${body ? "\n" : ""}`;
17723
17672
  }
17724
17673
  function writeEntryFile(filePath, content) {
17725
17674
  const dir = dirname9(filePath);
17726
- if (!existsSync17(dir)) mkdirSync10(dir, { recursive: true });
17675
+ if (!existsSync17(dir)) mkdirSync9(dir, { recursive: true });
17727
17676
  writeFileSync10(filePath, content, "utf-8");
17728
17677
  }
17729
17678
 
17730
17679
  // ../../packages/core/dist/record.js
17731
- import { statSync as statSync9 } from "node:fs";
17732
- import { join as join15 } from "node:path";
17680
+ import { statSync as statSync8 } from "node:fs";
17681
+ import { join as join14 } from "node:path";
17733
17682
  var DEFAULT_CATEGORY = "misc";
17734
17683
  function recordEntry(input, opts) {
17735
17684
  const now2 = opts.now ?? (() => /* @__PURE__ */ new Date());
@@ -17765,9 +17714,9 @@ function recordEntry(input, opts) {
17765
17714
  const built = buildEntry(frontmatter, sections);
17766
17715
  const category = input.category ?? DEFAULT_CATEGORY;
17767
17716
  const relPath = `${category}/${id}.md`;
17768
- const filePath = join15(opts.entriesRoot, relPath);
17717
+ const filePath = join14(opts.entriesRoot, relPath);
17769
17718
  writeEntryFile(filePath, built.content);
17770
- const stat = statSync9(filePath);
17719
+ const stat = statSync8(filePath);
17771
17720
  upsertEntry(opts.db, {
17772
17721
  id,
17773
17722
  source,
@@ -17795,8 +17744,8 @@ function formatYmd(d) {
17795
17744
  }
17796
17745
 
17797
17746
  // ../../packages/core/dist/update.js
17798
- import { readFileSync as readFileSync14, statSync as statSync10, writeFileSync as writeFileSync11 } from "node:fs";
17799
- import { join as join16 } from "node:path";
17747
+ import { readFileSync as readFileSync14, statSync as statSync9, writeFileSync as writeFileSync11 } from "node:fs";
17748
+ import { join as join15 } from "node:path";
17800
17749
  var IMMUTABLE_KEYS = /* @__PURE__ */ new Set([
17801
17750
  "id",
17802
17751
  "created_at",
@@ -17815,7 +17764,7 @@ function updateEntry(id, patch, opts) {
17815
17764
  throw new Error(`caveat not found: id=${id} source=${source}`);
17816
17765
  }
17817
17766
  const relPath = row.path;
17818
- const filePath = join16(opts.entriesRoot, relPath);
17767
+ const filePath = join15(opts.entriesRoot, relPath);
17819
17768
  const raw = readFileSync14(filePath, "utf-8");
17820
17769
  const parsed = parseMarkdown(raw);
17821
17770
  if (patch.frontmatter) {
@@ -17858,7 +17807,7 @@ function updateEntry(id, patch, opts) {
17858
17807
  }
17859
17808
  const built = buildEntry(mergedFrontmatter, mergedSections);
17860
17809
  writeFileSync11(filePath, built.content, "utf-8");
17861
- const stat = statSync10(filePath);
17810
+ const stat = statSync9(filePath);
17862
17811
  upsertEntry(opts.db, {
17863
17812
  id,
17864
17813
  source,
@@ -17881,6 +17830,73 @@ function formatYmd2(d) {
17881
17830
  return `${yyyy}-${mm}-${dd}`;
17882
17831
  }
17883
17832
 
17833
+ // ../../packages/core/dist/hookQueryLog.js
17834
+ import { appendFileSync, chmodSync as chmodSync2, mkdirSync as mkdirSync10, renameSync as renameSync5, statSync as statSync10, unlinkSync as unlinkSync3 } from "node:fs";
17835
+ import { join as join16, resolve as resolve3 } from "node:path";
17836
+ var CAVEAT_HOOK_QUERY_LOG_ENV = "CAVEAT_HOOK_QUERY_LOG";
17837
+ var HOOK_QUERY_LOG_MAX_BYTES = 1024 * 1024;
17838
+ var HOOK_QUERY_LOG_MAX_QUERY_CODE_UNITS = 1e3;
17839
+ var fsDependencies = {
17840
+ appendFileSync,
17841
+ chmodSync: chmodSync2,
17842
+ mkdirSync: mkdirSync10,
17843
+ renameSync: renameSync5,
17844
+ statSync: statSync10,
17845
+ unlinkSync: unlinkSync3
17846
+ };
17847
+ function isMissingPathError(err) {
17848
+ return err instanceof Error && "code" in err && err.code === "ENOENT";
17849
+ }
17850
+ function chmodExistingFile(path, dependencies) {
17851
+ try {
17852
+ dependencies.chmodSync(path, 384);
17853
+ } catch (err) {
17854
+ if (!isMissingPathError(err)) throw err;
17855
+ }
17856
+ }
17857
+ function logHookQueryMiss(miss, dependencies = fsDependencies) {
17858
+ if (process.env[CAVEAT_HOOK_QUERY_LOG_ENV] !== "on") return;
17859
+ const metricsDir = join16(resolve3(miss.caveatHome), "metrics");
17860
+ const activePath = join16(metricsDir, "hook-search-misses.jsonl");
17861
+ const backupPath = `${activePath}.1`;
17862
+ const record = JSON.stringify({
17863
+ at: (/* @__PURE__ */ new Date()).toISOString(),
17864
+ agent: miss.agent,
17865
+ surface: miss.surface,
17866
+ query: miss.query.slice(0, HOOK_QUERY_LOG_MAX_QUERY_CODE_UNITS)
17867
+ }) + "\n";
17868
+ dependencies.mkdirSync(metricsDir, { recursive: true, mode: 448 });
17869
+ dependencies.chmodSync(metricsDir, 448);
17870
+ chmodExistingFile(activePath, dependencies);
17871
+ chmodExistingFile(backupPath, dependencies);
17872
+ let activeSize = 0;
17873
+ try {
17874
+ activeSize = dependencies.statSync(activePath).size;
17875
+ } catch (err) {
17876
+ if (!isMissingPathError(err)) throw err;
17877
+ }
17878
+ if (activeSize + Buffer.byteLength(record, "utf8") > HOOK_QUERY_LOG_MAX_BYTES) {
17879
+ try {
17880
+ dependencies.unlinkSync(backupPath);
17881
+ } catch (err) {
17882
+ if (!isMissingPathError(err)) throw err;
17883
+ }
17884
+ try {
17885
+ dependencies.renameSync(activePath, backupPath);
17886
+ dependencies.chmodSync(backupPath, 384);
17887
+ } catch (err) {
17888
+ if (!isMissingPathError(err)) throw err;
17889
+ }
17890
+ }
17891
+ dependencies.appendFileSync(activePath, record, { encoding: "utf8", mode: 384 });
17892
+ dependencies.chmodSync(activePath, 384);
17893
+ try {
17894
+ dependencies.chmodSync(backupPath, 384);
17895
+ } catch (err) {
17896
+ if (!isMissingPathError(err)) throw err;
17897
+ }
17898
+ }
17899
+
17884
17900
  // ../../packages/core/dist/proposalEval.js
17885
17901
  import { createHash as createHash8 } from "node:crypto";
17886
17902
  import { isAbsolute as isAbsolute2, relative as relative4, resolve as resolve4, sep } from "node:path";
@@ -17916,6 +17932,10 @@ export {
17916
17932
  maybeSweepPendingDirs,
17917
17933
  drainPendingRemindersDetailed,
17918
17934
  createKeyserverKeyProvider,
17935
+ isWindows,
17936
+ isPrivateOwnerStat,
17937
+ powershellCallPrefix,
17938
+ nodeExecutableNames,
17919
17939
  SyncError,
17920
17940
  syncOwn,
17921
17941
  KNOWLEDGE_GITIGNORE,
@@ -17985,4 +18005,4 @@ strip-bom-string/index.js:
17985
18005
  js-yaml/dist/js-yaml.mjs:
17986
18006
  (*! js-yaml 4.1.1 https://github.com/nodeca/js-yaml @license MIT *)
17987
18007
  */
17988
- //# sourceMappingURL=chunk-TRIQ5WFY.js.map
18008
+ //# sourceMappingURL=chunk-ZBHCOA6R.js.map