@omnicross/daemon 0.1.4 → 0.1.5

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/dist/cli.cjs CHANGED
@@ -934,7 +934,7 @@ async function keysRevoke(db, id) {
934
934
  // src/commands/launch.ts
935
935
  var import_node_child_process2 = require("child_process");
936
936
  var import_node_fs21 = require("fs");
937
- var import_node_path13 = require("path");
937
+ var import_node_path14 = require("path");
938
938
  var import_node_util3 = require("util");
939
939
  var import_cli_launcher2 = require("@omnicross/cli-launcher");
940
940
 
@@ -2213,12 +2213,16 @@ function preserveWebhookSecrets(incoming, current) {
2213
2213
  }
2214
2214
 
2215
2215
  // src/audit/auditRuntime.ts
2216
+ var import_node_path4 = require("path");
2216
2217
  var import_auditSink = require("@omnicross/core/pipeline/auditSink");
2218
+ var import_upstreamTrace = require("@omnicross/core/pipeline/upstreamTrace");
2217
2219
  var writer = null;
2218
2220
  var sweeper = null;
2219
- function setAuditRuntime(w, s) {
2221
+ var auditDir = "";
2222
+ function setAuditRuntime(w, s, dir) {
2220
2223
  writer = w;
2221
2224
  sweeper = s;
2225
+ auditDir = dir;
2222
2226
  }
2223
2227
  function applyAuditConfig(config) {
2224
2228
  const enabled = config?.enabled === true && writer !== null;
@@ -2230,9 +2234,11 @@ function applyAuditConfig(config) {
2230
2234
  sweeper.configure(config);
2231
2235
  sweeper.start();
2232
2236
  }
2237
+ (0, import_upstreamTrace.setUpstreamTracePath)(config.captureBodies ? (0, import_node_path4.join)(auditDir, "upstream-trace.jsonl") : null);
2233
2238
  } else {
2234
2239
  (0, import_auditSink.setAuditCaptureConfig)(null);
2235
2240
  (0, import_auditSink.setAuditSink)(null);
2241
+ (0, import_upstreamTrace.setUpstreamTracePath)(null);
2236
2242
  if (sweeper) {
2237
2243
  if (config) sweeper.configure(config);
2238
2244
  sweeper.dispose();
@@ -4096,7 +4102,7 @@ function proxyToOutbound(res, outboundPort, path2, key, body) {
4096
4102
  var import_node_fs6 = require("fs");
4097
4103
  var import_promises = require("fs/promises");
4098
4104
  var import_node_module = require("module");
4099
- var import_node_path4 = __toESM(require("path"), 1);
4105
+ var import_node_path5 = __toESM(require("path"), 1);
4100
4106
  var import_meta = {};
4101
4107
  var CONTENT_TYPES = {
4102
4108
  ".html": "text/html; charset=utf-8",
@@ -4117,13 +4123,13 @@ var CONTENT_TYPES = {
4117
4123
  function resolveUiDist() {
4118
4124
  const fromEnv = process.env["OMNICROSS_UI_DIST"];
4119
4125
  if (fromEnv) {
4120
- return (0, import_node_fs6.existsSync)(import_node_path4.default.join(fromEnv, "index.html")) ? import_node_path4.default.resolve(fromEnv) : null;
4126
+ return (0, import_node_fs6.existsSync)(import_node_path5.default.join(fromEnv, "index.html")) ? import_node_path5.default.resolve(fromEnv) : null;
4121
4127
  }
4122
4128
  try {
4123
4129
  const req = (0, import_node_module.createRequire)(typeof __filename !== "undefined" ? __filename : import_meta.url);
4124
4130
  const pkgJson = req.resolve("@omnicross/ui/package.json");
4125
- const dist = import_node_path4.default.join(import_node_path4.default.dirname(pkgJson), "dist");
4126
- return (0, import_node_fs6.existsSync)(import_node_path4.default.join(dist, "index.html")) ? dist : null;
4131
+ const dist = import_node_path5.default.join(import_node_path5.default.dirname(pkgJson), "dist");
4132
+ return (0, import_node_fs6.existsSync)(import_node_path5.default.join(dist, "index.html")) ? dist : null;
4127
4133
  } catch {
4128
4134
  return null;
4129
4135
  }
@@ -4165,16 +4171,16 @@ async function handleUiStatic(req, res, urlPath, uiDist) {
4165
4171
  res.end(JSON.stringify({ error: { type: "bad_request", message: "invalid path" } }));
4166
4172
  return true;
4167
4173
  }
4168
- const filePath = import_node_path4.default.resolve(uiDist, rel === "" ? "index.html" : rel);
4169
- if (filePath !== uiDist && !filePath.startsWith(uiDist + import_node_path4.default.sep)) {
4174
+ const filePath = import_node_path5.default.resolve(uiDist, rel === "" ? "index.html" : rel);
4175
+ if (filePath !== uiDist && !filePath.startsWith(uiDist + import_node_path5.default.sep)) {
4170
4176
  res.writeHead(403, { "Content-Type": "application/json" });
4171
4177
  res.end(JSON.stringify({ error: { type: "forbidden", message: "path outside ui root" } }));
4172
4178
  return true;
4173
4179
  }
4174
4180
  let target = filePath;
4175
4181
  if (!(0, import_node_fs6.existsSync)(target) || (0, import_node_fs6.statSync)(target).isDirectory()) {
4176
- if (import_node_path4.default.extname(rel) === "") {
4177
- target = import_node_path4.default.join(uiDist, "index.html");
4182
+ if (import_node_path5.default.extname(rel) === "") {
4183
+ target = import_node_path5.default.join(uiDist, "index.html");
4178
4184
  } else {
4179
4185
  res.writeHead(404, { "Content-Type": "application/json" });
4180
4186
  res.end(JSON.stringify({ error: { type: "not_found", message: "no such ui asset" } }));
@@ -4182,14 +4188,14 @@ async function handleUiStatic(req, res, urlPath, uiDist) {
4182
4188
  }
4183
4189
  }
4184
4190
  const body = await (0, import_promises.readFile)(target);
4185
- const type = CONTENT_TYPES[import_node_path4.default.extname(target).toLowerCase()] ?? "application/octet-stream";
4191
+ const type = CONTENT_TYPES[import_node_path5.default.extname(target).toLowerCase()] ?? "application/octet-stream";
4186
4192
  res.writeHead(200, { "Content-Type": type, "Content-Length": body.length });
4187
4193
  res.end(req.method === "HEAD" ? void 0 : body);
4188
4194
  return true;
4189
4195
  }
4190
4196
 
4191
4197
  // src/admin/version.ts
4192
- var DAEMON_VERSION = true ? "0.1.4" : "0.0.0-dev";
4198
+ var DAEMON_VERSION = true ? "0.1.5" : "0.0.0-dev";
4193
4199
 
4194
4200
  // src/admin/AdminServer.ts
4195
4201
  var LOOPBACK_ADDR = "127.0.0.1";
@@ -5442,7 +5448,7 @@ var JsonVoucherDb = class {
5442
5448
 
5443
5449
  // src/ports/JsonSubscriptionCredentialStore.ts
5444
5450
  var import_node_fs14 = require("fs");
5445
- var import_node_path7 = require("path");
5451
+ var import_node_path8 = require("path");
5446
5452
  var import_SubscriptionAccountHealth = require("@omnicross/core/pipeline/SubscriptionAccountHealth");
5447
5453
  var import_upstreamFetch3 = require("@omnicross/core/pipeline/upstreamFetch");
5448
5454
  var import_SubscriptionIdentityStore = require("@omnicross/core/provider-proxy/identity/SubscriptionIdentityStore");
@@ -5524,9 +5530,9 @@ function findDuplicateCredentialIds(accounts) {
5524
5530
  // src/ports/external-cli-credentials.ts
5525
5531
  var import_node_fs12 = require("fs");
5526
5532
  var import_node_os2 = require("os");
5527
- var import_node_path5 = require("path");
5533
+ var import_node_path6 = require("path");
5528
5534
  function externalStorePath(provider, home = (0, import_node_os2.homedir)()) {
5529
- return provider === "claude" ? (0, import_node_path5.join)(home, ".claude", ".credentials.json") : (0, import_node_path5.join)(home, ".codex", "auth.json");
5535
+ return provider === "claude" ? (0, import_node_path6.join)(home, ".claude", ".credentials.json") : (0, import_node_path6.join)(home, ".codex", "auth.json");
5530
5536
  }
5531
5537
  function decodeJwtExpiryMs(token) {
5532
5538
  try {
@@ -5589,7 +5595,7 @@ function readExternalCliCredentials(provider, home = (0, import_node_os2.homedir
5589
5595
  // src/ports/external-cli-store.ts
5590
5596
  var import_node_fs13 = require("fs");
5591
5597
  var import_node_os3 = require("os");
5592
- var import_node_path6 = require("path");
5598
+ var import_node_path7 = require("path");
5593
5599
  function markerPath(provider, home) {
5594
5600
  return `${externalStorePath(provider, home)}.omnicross-managed`;
5595
5601
  }
@@ -5624,7 +5630,7 @@ function readExistingObject(path2) {
5624
5630
  }
5625
5631
  }
5626
5632
  function writeAtomic(path2, content) {
5627
- (0, import_node_fs13.mkdirSync)((0, import_node_path6.dirname)(path2), { recursive: true });
5633
+ (0, import_node_fs13.mkdirSync)((0, import_node_path7.dirname)(path2), { recursive: true });
5628
5634
  const temp = `${path2}.omnicross-tmp`;
5629
5635
  (0, import_node_fs13.writeFileSync)(temp, content, "utf8");
5630
5636
  (0, import_node_fs13.renameSync)(temp, path2);
@@ -6295,7 +6301,7 @@ var JsonSubscriptionCredentialStore = class {
6295
6301
  * → `enc:v1:`; already-`enc:`/`$ENV` untouched) before serializing, so any
6296
6302
  * write — incl. child 4's future refresh writes — lands encrypted. */
6297
6303
  persist(config) {
6298
- (0, import_node_fs14.mkdirSync)((0, import_node_path7.dirname)(this.tokensPath), { recursive: true });
6304
+ (0, import_node_fs14.mkdirSync)((0, import_node_path8.dirname)(this.tokensPath), { recursive: true });
6299
6305
  const encrypted = encryptTokens(config, this.box);
6300
6306
  (0, import_node_fs14.writeFileSync)(this.tokensPath, JSON.stringify(encrypted, null, 2) + "\n", "utf8");
6301
6307
  }
@@ -6645,7 +6651,7 @@ var AccountHealthSweeper = class {
6645
6651
 
6646
6652
  // src/audit/AuditPruneSweeper.ts
6647
6653
  var import_node_fs15 = require("fs");
6648
- var import_node_path8 = require("path");
6654
+ var import_node_path9 = require("path");
6649
6655
 
6650
6656
  // src/audit/auditFiles.ts
6651
6657
  var AUDIT_FILE_RE = /^audit-(\d{4})-(\d{2})-(\d{2})\.jsonl$/;
@@ -6671,8 +6677,8 @@ function auditFileDateMs(fileName) {
6671
6677
  var DAY_MS = 24 * 60 * 6e4;
6672
6678
  var SWEEP_INTERVAL_MS2 = 60 * 6e4;
6673
6679
  var AuditPruneSweeper = class {
6674
- constructor(auditDir, logger, config, intervalMs = SWEEP_INTERVAL_MS2, now = Date.now) {
6675
- this.auditDir = auditDir;
6680
+ constructor(auditDir2, logger, config, intervalMs = SWEEP_INTERVAL_MS2, now = Date.now) {
6681
+ this.auditDir = auditDir2;
6676
6682
  this.logger = logger;
6677
6683
  this.config = config;
6678
6684
  this.intervalMs = intervalMs;
@@ -6728,7 +6734,7 @@ var AuditPruneSweeper = class {
6728
6734
  const dateMs = auditFileDateMs(file);
6729
6735
  if (dateMs === null || dateMs >= cutoff) continue;
6730
6736
  try {
6731
- (0, import_node_fs15.unlinkSync)((0, import_node_path8.join)(this.auditDir, file));
6737
+ (0, import_node_fs15.unlinkSync)((0, import_node_path9.join)(this.auditDir, file));
6732
6738
  removed += 1;
6733
6739
  } catch (error) {
6734
6740
  this.logger.warn("[AuditPruneSweeper] failed to unlink expired audit file", {
@@ -6752,14 +6758,14 @@ var AuditPruneSweeper = class {
6752
6758
 
6753
6759
  // src/audit/auditReader.ts
6754
6760
  var import_node_fs16 = require("fs");
6755
- var import_node_path9 = require("path");
6761
+ var import_node_path10 = require("path");
6756
6762
  var DEFAULT_LIMIT = 200;
6757
6763
  var MAX_LIMIT = 2e3;
6758
- function readAuditRecords(auditDir, query = {}) {
6759
- if (!(0, import_node_fs16.existsSync)(auditDir)) return [];
6764
+ function readAuditRecords(auditDir2, query = {}) {
6765
+ if (!(0, import_node_fs16.existsSync)(auditDir2)) return [];
6760
6766
  let files;
6761
6767
  try {
6762
- files = (0, import_node_fs16.readdirSync)(auditDir).filter((f) => AUDIT_FILE_RE.test(f));
6768
+ files = (0, import_node_fs16.readdirSync)(auditDir2).filter((f) => AUDIT_FILE_RE.test(f));
6763
6769
  } catch {
6764
6770
  return [];
6765
6771
  }
@@ -6770,7 +6776,7 @@ function readAuditRecords(auditDir, query = {}) {
6770
6776
  for (const file of files.sort().reverse()) {
6771
6777
  let raw;
6772
6778
  try {
6773
- raw = (0, import_node_fs16.readFileSync)((0, import_node_path9.join)(auditDir, file), "utf8");
6779
+ raw = (0, import_node_fs16.readFileSync)((0, import_node_path10.join)(auditDir2, file), "utf8");
6774
6780
  } catch {
6775
6781
  continue;
6776
6782
  }
@@ -6800,10 +6806,10 @@ function isAuditRecord(value) {
6800
6806
 
6801
6807
  // src/audit/AuditWriter.ts
6802
6808
  var import_node_fs17 = require("fs");
6803
- var import_node_path10 = require("path");
6809
+ var import_node_path11 = require("path");
6804
6810
  var AuditWriter = class {
6805
- constructor(auditDir, logger, defer = (fn) => setTimeout(fn, 0)) {
6806
- this.auditDir = auditDir;
6811
+ constructor(auditDir2, logger, defer = (fn) => setTimeout(fn, 0)) {
6812
+ this.auditDir = auditDir2;
6807
6813
  this.logger = logger;
6808
6814
  this.defer = defer;
6809
6815
  }
@@ -6836,7 +6842,7 @@ var AuditWriter = class {
6836
6842
  (0, import_node_fs17.mkdirSync)(this.auditDir, { recursive: true });
6837
6843
  this.dirEnsured = true;
6838
6844
  }
6839
- const file = (0, import_node_path10.join)(this.auditDir, auditFileName(record.ts));
6845
+ const file = (0, import_node_path11.join)(this.auditDir, auditFileName(record.ts));
6840
6846
  (0, import_node_fs17.appendFileSync)(file, JSON.stringify(record) + "\n", "utf8");
6841
6847
  }
6842
6848
  };
@@ -6844,7 +6850,7 @@ var AuditWriter = class {
6844
6850
  // src/billing/BillingPublisher.ts
6845
6851
  var import_node_fs18 = require("fs");
6846
6852
  var import_node_crypto10 = require("crypto");
6847
- var import_node_path11 = require("path");
6853
+ var import_node_path12 = require("path");
6848
6854
  var import_upstreamFetch5 = require("@omnicross/core/pipeline/upstreamFetch");
6849
6855
 
6850
6856
  // src/billing/billingFiles.ts
@@ -6915,7 +6921,7 @@ var BillingPublisher = class {
6915
6921
  */
6916
6922
  appendNow(event) {
6917
6923
  this.ensureDir();
6918
- const file = (0, import_node_path11.join)(this.billingDir, billingFileName(event.ts));
6924
+ const file = (0, import_node_path12.join)(this.billingDir, billingFileName(event.ts));
6919
6925
  (0, import_node_fs18.appendFileSync)(file, JSON.stringify(event) + "\n", "utf8");
6920
6926
  }
6921
6927
  /**
@@ -6965,7 +6971,7 @@ var BillingPublisher = class {
6965
6971
  markDelivered(event) {
6966
6972
  try {
6967
6973
  this.ensureDir();
6968
- const file = (0, import_node_path11.join)(this.billingDir, deliveredFileName(event.ts));
6974
+ const file = (0, import_node_path12.join)(this.billingDir, deliveredFileName(event.ts));
6969
6975
  (0, import_node_fs18.appendFileSync)(file, JSON.stringify({ id: event.id, deliveredAt: this.now() }) + "\n", "utf8");
6970
6976
  } catch (error) {
6971
6977
  this.logger.warn("[BillingPublisher] failed to append delivery marker", {
@@ -6982,7 +6988,7 @@ var BillingPublisher = class {
6982
6988
 
6983
6989
  // src/billing/billingReader.ts
6984
6990
  var import_node_fs19 = require("fs");
6985
- var import_node_path12 = require("path");
6991
+ var import_node_path13 = require("path");
6986
6992
  function readBillingLedger(billingDir) {
6987
6993
  const view = { events: [], deliveredIds: /* @__PURE__ */ new Set() };
6988
6994
  if (!(0, import_node_fs19.existsSync)(billingDir)) return view;
@@ -7019,7 +7025,7 @@ function readBillingStatus(billingDir) {
7019
7025
  function parseLines(dir, file) {
7020
7026
  let raw;
7021
7027
  try {
7022
- raw = (0, import_node_fs19.readFileSync)((0, import_node_path12.join)(dir, file), "utf8");
7028
+ raw = (0, import_node_fs19.readFileSync)((0, import_node_path13.join)(dir, file), "utf8");
7023
7029
  } catch {
7024
7030
  return [];
7025
7031
  }
@@ -7460,7 +7466,7 @@ function buildDaemon(config, paths) {
7460
7466
  // lines through the injected logger (honors level/format/file sink).
7461
7467
  logger
7462
7468
  });
7463
- const auditDir = defaultAuditDir(paths.configPath);
7469
+ const auditDir2 = defaultAuditDir(paths.configPath);
7464
7470
  const billingDir = defaultBillingDir(paths.configPath);
7465
7471
  const adminServer = new AdminServer({
7466
7472
  configPath: paths.configPath,
@@ -7536,7 +7542,7 @@ function buildDaemon(config, paths) {
7536
7542
  // date-rotated audit store. Bound to the store dir here so the AdminServer
7537
7543
  // carries no path/store coupling. Records hold IP/UA/bodies → admin-only,
7538
7544
  // NEVER unauth, NEVER on `/health`. Routed in `AdminServer` (not `adminApi.ts`).
7539
- auditReader: (query) => readAuditRecords(auditDir, query),
7545
+ auditReader: (query) => readAuditRecords(auditDir2, query),
7540
7546
  // billing-event-stream: the AUTHED `GET /admin/api/billing-status` returns the
7541
7547
  // secret-free total/delivered/pending counts of the durable ledger.
7542
7548
  billingStatusReader: () => readBillingStatus(billingDir)
@@ -7546,9 +7552,9 @@ function buildDaemon(config, paths) {
7546
7552
  fetchImpl: (url, init) => (0, import_upstreamFetch7.fetchUpstream)(url, init)
7547
7553
  });
7548
7554
  setWebhookRuntime(webhookDispatcher, (0, import_SubscriptionAccountHealth2.getSharedAccountHealth)());
7549
- const auditWriter = new AuditWriter(auditDir, logger);
7550
- const auditPruneSweeper = new AuditPruneSweeper(auditDir, logger, import_audit_types.DEFAULT_AUDIT_CONFIG);
7551
- setAuditRuntime(auditWriter, auditPruneSweeper);
7555
+ const auditWriter = new AuditWriter(auditDir2, logger);
7556
+ const auditPruneSweeper = new AuditPruneSweeper(auditDir2, logger, import_audit_types.DEFAULT_AUDIT_CONFIG);
7557
+ setAuditRuntime(auditWriter, auditPruneSweeper, auditDir2);
7552
7558
  const billingPublisher = new BillingPublisher(billingDir, logger);
7553
7559
  const billingRetrySweeper = new BillingRetrySweeper(
7554
7560
  billingDir,
@@ -7637,9 +7643,9 @@ function buildCliSpawnPlan(opts) {
7637
7643
  };
7638
7644
  }
7639
7645
  function resolveInPathDefault(candidate) {
7640
- const segments = (process.env["PATH"] ?? "").split(import_node_path13.delimiter).filter(Boolean);
7646
+ const segments = (process.env["PATH"] ?? "").split(import_node_path14.delimiter).filter(Boolean);
7641
7647
  for (const seg of segments) {
7642
- const full = (0, import_node_path13.join)(seg, candidate);
7648
+ const full = (0, import_node_path14.join)(seg, candidate);
7643
7649
  if ((0, import_node_fs21.existsSync)(full)) return full;
7644
7650
  }
7645
7651
  return null;
package/dist/cli.js CHANGED
@@ -911,7 +911,7 @@ async function keysRevoke(db, id) {
911
911
  // src/commands/launch.ts
912
912
  import { spawn as spawn2 } from "child_process";
913
913
  import { existsSync as existsSync15 } from "fs";
914
- import { delimiter as delimiter2, join as join10 } from "path";
914
+ import { delimiter as delimiter2, join as join11 } from "path";
915
915
  import { parseArgs as parseArgs3 } from "util";
916
916
  import {
917
917
  buildChatCliLaunchConfig as buildChatCliLaunchConfig2,
@@ -2234,12 +2234,16 @@ function preserveWebhookSecrets(incoming, current) {
2234
2234
  }
2235
2235
 
2236
2236
  // src/audit/auditRuntime.ts
2237
+ import { join as join4 } from "path";
2237
2238
  import { setAuditCaptureConfig, setAuditSink } from "@omnicross/core/pipeline/auditSink";
2239
+ import { setUpstreamTracePath } from "@omnicross/core/pipeline/upstreamTrace";
2238
2240
  var writer = null;
2239
2241
  var sweeper = null;
2240
- function setAuditRuntime(w, s) {
2242
+ var auditDir = "";
2243
+ function setAuditRuntime(w, s, dir) {
2241
2244
  writer = w;
2242
2245
  sweeper = s;
2246
+ auditDir = dir;
2243
2247
  }
2244
2248
  function applyAuditConfig(config) {
2245
2249
  const enabled = config?.enabled === true && writer !== null;
@@ -2251,9 +2255,11 @@ function applyAuditConfig(config) {
2251
2255
  sweeper.configure(config);
2252
2256
  sweeper.start();
2253
2257
  }
2258
+ setUpstreamTracePath(config.captureBodies ? join4(auditDir, "upstream-trace.jsonl") : null);
2254
2259
  } else {
2255
2260
  setAuditCaptureConfig(null);
2256
2261
  setAuditSink(null);
2262
+ setUpstreamTracePath(null);
2257
2263
  if (sweeper) {
2258
2264
  if (config) sweeper.configure(config);
2259
2265
  sweeper.dispose();
@@ -4209,7 +4215,7 @@ async function handleUiStatic(req, res, urlPath, uiDist) {
4209
4215
  }
4210
4216
 
4211
4217
  // src/admin/version.ts
4212
- var DAEMON_VERSION = true ? "0.1.4" : "0.0.0-dev";
4218
+ var DAEMON_VERSION = true ? "0.1.5" : "0.0.0-dev";
4213
4219
 
4214
4220
  // src/admin/AdminServer.ts
4215
4221
  var LOOPBACK_ADDR = "127.0.0.1";
@@ -5551,9 +5557,9 @@ function findDuplicateCredentialIds(accounts) {
5551
5557
  // src/ports/external-cli-credentials.ts
5552
5558
  import { existsSync as existsSync8, readFileSync as readFileSync9 } from "fs";
5553
5559
  import { homedir as homedir2 } from "os";
5554
- import { join as join4 } from "path";
5560
+ import { join as join5 } from "path";
5555
5561
  function externalStorePath(provider, home = homedir2()) {
5556
- return provider === "claude" ? join4(home, ".claude", ".credentials.json") : join4(home, ".codex", "auth.json");
5562
+ return provider === "claude" ? join5(home, ".claude", ".credentials.json") : join5(home, ".codex", "auth.json");
5557
5563
  }
5558
5564
  function decodeJwtExpiryMs(token) {
5559
5565
  try {
@@ -6672,7 +6678,7 @@ var AccountHealthSweeper = class {
6672
6678
 
6673
6679
  // src/audit/AuditPruneSweeper.ts
6674
6680
  import { existsSync as existsSync11, readdirSync, unlinkSync } from "fs";
6675
- import { join as join5 } from "path";
6681
+ import { join as join6 } from "path";
6676
6682
 
6677
6683
  // src/audit/auditFiles.ts
6678
6684
  var AUDIT_FILE_RE = /^audit-(\d{4})-(\d{2})-(\d{2})\.jsonl$/;
@@ -6698,8 +6704,8 @@ function auditFileDateMs(fileName) {
6698
6704
  var DAY_MS = 24 * 60 * 6e4;
6699
6705
  var SWEEP_INTERVAL_MS2 = 60 * 6e4;
6700
6706
  var AuditPruneSweeper = class {
6701
- constructor(auditDir, logger, config, intervalMs = SWEEP_INTERVAL_MS2, now = Date.now) {
6702
- this.auditDir = auditDir;
6707
+ constructor(auditDir2, logger, config, intervalMs = SWEEP_INTERVAL_MS2, now = Date.now) {
6708
+ this.auditDir = auditDir2;
6703
6709
  this.logger = logger;
6704
6710
  this.config = config;
6705
6711
  this.intervalMs = intervalMs;
@@ -6755,7 +6761,7 @@ var AuditPruneSweeper = class {
6755
6761
  const dateMs = auditFileDateMs(file);
6756
6762
  if (dateMs === null || dateMs >= cutoff) continue;
6757
6763
  try {
6758
- unlinkSync(join5(this.auditDir, file));
6764
+ unlinkSync(join6(this.auditDir, file));
6759
6765
  removed += 1;
6760
6766
  } catch (error) {
6761
6767
  this.logger.warn("[AuditPruneSweeper] failed to unlink expired audit file", {
@@ -6779,14 +6785,14 @@ var AuditPruneSweeper = class {
6779
6785
 
6780
6786
  // src/audit/auditReader.ts
6781
6787
  import { existsSync as existsSync12, readdirSync as readdirSync2, readFileSync as readFileSync12 } from "fs";
6782
- import { join as join6 } from "path";
6788
+ import { join as join7 } from "path";
6783
6789
  var DEFAULT_LIMIT = 200;
6784
6790
  var MAX_LIMIT = 2e3;
6785
- function readAuditRecords(auditDir, query = {}) {
6786
- if (!existsSync12(auditDir)) return [];
6791
+ function readAuditRecords(auditDir2, query = {}) {
6792
+ if (!existsSync12(auditDir2)) return [];
6787
6793
  let files;
6788
6794
  try {
6789
- files = readdirSync2(auditDir).filter((f) => AUDIT_FILE_RE.test(f));
6795
+ files = readdirSync2(auditDir2).filter((f) => AUDIT_FILE_RE.test(f));
6790
6796
  } catch {
6791
6797
  return [];
6792
6798
  }
@@ -6797,7 +6803,7 @@ function readAuditRecords(auditDir, query = {}) {
6797
6803
  for (const file of files.sort().reverse()) {
6798
6804
  let raw;
6799
6805
  try {
6800
- raw = readFileSync12(join6(auditDir, file), "utf8");
6806
+ raw = readFileSync12(join7(auditDir2, file), "utf8");
6801
6807
  } catch {
6802
6808
  continue;
6803
6809
  }
@@ -6827,10 +6833,10 @@ function isAuditRecord(value) {
6827
6833
 
6828
6834
  // src/audit/AuditWriter.ts
6829
6835
  import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync4 } from "fs";
6830
- import { join as join7 } from "path";
6836
+ import { join as join8 } from "path";
6831
6837
  var AuditWriter = class {
6832
- constructor(auditDir, logger, defer = (fn) => setTimeout(fn, 0)) {
6833
- this.auditDir = auditDir;
6838
+ constructor(auditDir2, logger, defer = (fn) => setTimeout(fn, 0)) {
6839
+ this.auditDir = auditDir2;
6834
6840
  this.logger = logger;
6835
6841
  this.defer = defer;
6836
6842
  }
@@ -6863,7 +6869,7 @@ var AuditWriter = class {
6863
6869
  mkdirSync4(this.auditDir, { recursive: true });
6864
6870
  this.dirEnsured = true;
6865
6871
  }
6866
- const file = join7(this.auditDir, auditFileName(record.ts));
6872
+ const file = join8(this.auditDir, auditFileName(record.ts));
6867
6873
  appendFileSync2(file, JSON.stringify(record) + "\n", "utf8");
6868
6874
  }
6869
6875
  };
@@ -6871,7 +6877,7 @@ var AuditWriter = class {
6871
6877
  // src/billing/BillingPublisher.ts
6872
6878
  import { appendFileSync as appendFileSync3, mkdirSync as mkdirSync5 } from "fs";
6873
6879
  import { createHmac } from "crypto";
6874
- import { join as join8 } from "path";
6880
+ import { join as join9 } from "path";
6875
6881
  import { fetchUpstream as fetchUpstream4 } from "@omnicross/core/pipeline/upstreamFetch";
6876
6882
 
6877
6883
  // src/billing/billingFiles.ts
@@ -6942,7 +6948,7 @@ var BillingPublisher = class {
6942
6948
  */
6943
6949
  appendNow(event) {
6944
6950
  this.ensureDir();
6945
- const file = join8(this.billingDir, billingFileName(event.ts));
6951
+ const file = join9(this.billingDir, billingFileName(event.ts));
6946
6952
  appendFileSync3(file, JSON.stringify(event) + "\n", "utf8");
6947
6953
  }
6948
6954
  /**
@@ -6992,7 +6998,7 @@ var BillingPublisher = class {
6992
6998
  markDelivered(event) {
6993
6999
  try {
6994
7000
  this.ensureDir();
6995
- const file = join8(this.billingDir, deliveredFileName(event.ts));
7001
+ const file = join9(this.billingDir, deliveredFileName(event.ts));
6996
7002
  appendFileSync3(file, JSON.stringify({ id: event.id, deliveredAt: this.now() }) + "\n", "utf8");
6997
7003
  } catch (error) {
6998
7004
  this.logger.warn("[BillingPublisher] failed to append delivery marker", {
@@ -7009,7 +7015,7 @@ var BillingPublisher = class {
7009
7015
 
7010
7016
  // src/billing/billingReader.ts
7011
7017
  import { existsSync as existsSync13, readdirSync as readdirSync3, readFileSync as readFileSync13 } from "fs";
7012
- import { join as join9 } from "path";
7018
+ import { join as join10 } from "path";
7013
7019
  function readBillingLedger(billingDir) {
7014
7020
  const view = { events: [], deliveredIds: /* @__PURE__ */ new Set() };
7015
7021
  if (!existsSync13(billingDir)) return view;
@@ -7046,7 +7052,7 @@ function readBillingStatus(billingDir) {
7046
7052
  function parseLines(dir, file) {
7047
7053
  let raw;
7048
7054
  try {
7049
- raw = readFileSync13(join9(dir, file), "utf8");
7055
+ raw = readFileSync13(join10(dir, file), "utf8");
7050
7056
  } catch {
7051
7057
  return [];
7052
7058
  }
@@ -7487,7 +7493,7 @@ function buildDaemon(config, paths) {
7487
7493
  // lines through the injected logger (honors level/format/file sink).
7488
7494
  logger
7489
7495
  });
7490
- const auditDir = defaultAuditDir(paths.configPath);
7496
+ const auditDir2 = defaultAuditDir(paths.configPath);
7491
7497
  const billingDir = defaultBillingDir(paths.configPath);
7492
7498
  const adminServer = new AdminServer({
7493
7499
  configPath: paths.configPath,
@@ -7563,7 +7569,7 @@ function buildDaemon(config, paths) {
7563
7569
  // date-rotated audit store. Bound to the store dir here so the AdminServer
7564
7570
  // carries no path/store coupling. Records hold IP/UA/bodies → admin-only,
7565
7571
  // NEVER unauth, NEVER on `/health`. Routed in `AdminServer` (not `adminApi.ts`).
7566
- auditReader: (query) => readAuditRecords(auditDir, query),
7572
+ auditReader: (query) => readAuditRecords(auditDir2, query),
7567
7573
  // billing-event-stream: the AUTHED `GET /admin/api/billing-status` returns the
7568
7574
  // secret-free total/delivered/pending counts of the durable ledger.
7569
7575
  billingStatusReader: () => readBillingStatus(billingDir)
@@ -7573,9 +7579,9 @@ function buildDaemon(config, paths) {
7573
7579
  fetchImpl: (url, init) => fetchUpstream6(url, init)
7574
7580
  });
7575
7581
  setWebhookRuntime(webhookDispatcher, getSharedAccountHealth2());
7576
- const auditWriter = new AuditWriter(auditDir, logger);
7577
- const auditPruneSweeper = new AuditPruneSweeper(auditDir, logger, DEFAULT_AUDIT_CONFIG);
7578
- setAuditRuntime(auditWriter, auditPruneSweeper);
7582
+ const auditWriter = new AuditWriter(auditDir2, logger);
7583
+ const auditPruneSweeper = new AuditPruneSweeper(auditDir2, logger, DEFAULT_AUDIT_CONFIG);
7584
+ setAuditRuntime(auditWriter, auditPruneSweeper, auditDir2);
7579
7585
  const billingPublisher = new BillingPublisher(billingDir, logger);
7580
7586
  const billingRetrySweeper = new BillingRetrySweeper(
7581
7587
  billingDir,
@@ -7666,7 +7672,7 @@ function buildCliSpawnPlan(opts) {
7666
7672
  function resolveInPathDefault(candidate) {
7667
7673
  const segments = (process.env["PATH"] ?? "").split(delimiter2).filter(Boolean);
7668
7674
  for (const seg of segments) {
7669
- const full = join10(seg, candidate);
7675
+ const full = join11(seg, candidate);
7670
7676
  if (existsSync15(full)) return full;
7671
7677
  }
7672
7678
  return null;
package/dist/index.cjs CHANGED
@@ -1903,12 +1903,16 @@ function preserveWebhookSecrets(incoming, current) {
1903
1903
  }
1904
1904
 
1905
1905
  // src/audit/auditRuntime.ts
1906
+ var import_node_path3 = require("path");
1906
1907
  var import_auditSink = require("@omnicross/core/pipeline/auditSink");
1908
+ var import_upstreamTrace = require("@omnicross/core/pipeline/upstreamTrace");
1907
1909
  var writer = null;
1908
1910
  var sweeper = null;
1909
- function setAuditRuntime(w, s) {
1911
+ var auditDir = "";
1912
+ function setAuditRuntime(w, s, dir) {
1910
1913
  writer = w;
1911
1914
  sweeper = s;
1915
+ auditDir = dir;
1912
1916
  }
1913
1917
  function applyAuditConfig(config) {
1914
1918
  const enabled = config?.enabled === true && writer !== null;
@@ -1920,9 +1924,11 @@ function applyAuditConfig(config) {
1920
1924
  sweeper.configure(config);
1921
1925
  sweeper.start();
1922
1926
  }
1927
+ (0, import_upstreamTrace.setUpstreamTracePath)(config.captureBodies ? (0, import_node_path3.join)(auditDir, "upstream-trace.jsonl") : null);
1923
1928
  } else {
1924
1929
  (0, import_auditSink.setAuditCaptureConfig)(null);
1925
1930
  (0, import_auditSink.setAuditSink)(null);
1931
+ (0, import_upstreamTrace.setUpstreamTracePath)(null);
1926
1932
  if (sweeper) {
1927
1933
  if (config) sweeper.configure(config);
1928
1934
  sweeper.dispose();
@@ -1932,9 +1938,11 @@ function applyAuditConfig(config) {
1932
1938
  function resetAuditRuntimeForTests() {
1933
1939
  (0, import_auditSink.setAuditCaptureConfig)(null);
1934
1940
  (0, import_auditSink.setAuditSink)(null);
1941
+ (0, import_upstreamTrace.setUpstreamTracePath)(null);
1935
1942
  if (sweeper) sweeper.dispose();
1936
1943
  writer = null;
1937
1944
  sweeper = null;
1945
+ auditDir = "";
1938
1946
  }
1939
1947
 
1940
1948
  // src/billing/billingRuntime.ts
@@ -3800,7 +3808,7 @@ function proxyToOutbound(res, outboundPort, path2, key, body) {
3800
3808
  var import_node_fs4 = require("fs");
3801
3809
  var import_promises = require("fs/promises");
3802
3810
  var import_node_module = require("module");
3803
- var import_node_path3 = __toESM(require("path"), 1);
3811
+ var import_node_path4 = __toESM(require("path"), 1);
3804
3812
  var import_meta = {};
3805
3813
  var CONTENT_TYPES = {
3806
3814
  ".html": "text/html; charset=utf-8",
@@ -3821,13 +3829,13 @@ var CONTENT_TYPES = {
3821
3829
  function resolveUiDist() {
3822
3830
  const fromEnv = process.env["OMNICROSS_UI_DIST"];
3823
3831
  if (fromEnv) {
3824
- return (0, import_node_fs4.existsSync)(import_node_path3.default.join(fromEnv, "index.html")) ? import_node_path3.default.resolve(fromEnv) : null;
3832
+ return (0, import_node_fs4.existsSync)(import_node_path4.default.join(fromEnv, "index.html")) ? import_node_path4.default.resolve(fromEnv) : null;
3825
3833
  }
3826
3834
  try {
3827
3835
  const req = (0, import_node_module.createRequire)(typeof __filename !== "undefined" ? __filename : import_meta.url);
3828
3836
  const pkgJson = req.resolve("@omnicross/ui/package.json");
3829
- const dist = import_node_path3.default.join(import_node_path3.default.dirname(pkgJson), "dist");
3830
- return (0, import_node_fs4.existsSync)(import_node_path3.default.join(dist, "index.html")) ? dist : null;
3837
+ const dist = import_node_path4.default.join(import_node_path4.default.dirname(pkgJson), "dist");
3838
+ return (0, import_node_fs4.existsSync)(import_node_path4.default.join(dist, "index.html")) ? dist : null;
3831
3839
  } catch {
3832
3840
  return null;
3833
3841
  }
@@ -3869,16 +3877,16 @@ async function handleUiStatic(req, res, urlPath, uiDist) {
3869
3877
  res.end(JSON.stringify({ error: { type: "bad_request", message: "invalid path" } }));
3870
3878
  return true;
3871
3879
  }
3872
- const filePath = import_node_path3.default.resolve(uiDist, rel === "" ? "index.html" : rel);
3873
- if (filePath !== uiDist && !filePath.startsWith(uiDist + import_node_path3.default.sep)) {
3880
+ const filePath = import_node_path4.default.resolve(uiDist, rel === "" ? "index.html" : rel);
3881
+ if (filePath !== uiDist && !filePath.startsWith(uiDist + import_node_path4.default.sep)) {
3874
3882
  res.writeHead(403, { "Content-Type": "application/json" });
3875
3883
  res.end(JSON.stringify({ error: { type: "forbidden", message: "path outside ui root" } }));
3876
3884
  return true;
3877
3885
  }
3878
3886
  let target = filePath;
3879
3887
  if (!(0, import_node_fs4.existsSync)(target) || (0, import_node_fs4.statSync)(target).isDirectory()) {
3880
- if (import_node_path3.default.extname(rel) === "") {
3881
- target = import_node_path3.default.join(uiDist, "index.html");
3888
+ if (import_node_path4.default.extname(rel) === "") {
3889
+ target = import_node_path4.default.join(uiDist, "index.html");
3882
3890
  } else {
3883
3891
  res.writeHead(404, { "Content-Type": "application/json" });
3884
3892
  res.end(JSON.stringify({ error: { type: "not_found", message: "no such ui asset" } }));
@@ -3886,14 +3894,14 @@ async function handleUiStatic(req, res, urlPath, uiDist) {
3886
3894
  }
3887
3895
  }
3888
3896
  const body = await (0, import_promises.readFile)(target);
3889
- const type = CONTENT_TYPES[import_node_path3.default.extname(target).toLowerCase()] ?? "application/octet-stream";
3897
+ const type = CONTENT_TYPES[import_node_path4.default.extname(target).toLowerCase()] ?? "application/octet-stream";
3890
3898
  res.writeHead(200, { "Content-Type": type, "Content-Length": body.length });
3891
3899
  res.end(req.method === "HEAD" ? void 0 : body);
3892
3900
  return true;
3893
3901
  }
3894
3902
 
3895
3903
  // src/admin/version.ts
3896
- var DAEMON_VERSION = true ? "0.1.4" : "0.0.0-dev";
3904
+ var DAEMON_VERSION = true ? "0.1.5" : "0.0.0-dev";
3897
3905
 
3898
3906
  // src/admin/AdminServer.ts
3899
3907
  var LOOPBACK_ADDR = "127.0.0.1";
@@ -4275,21 +4283,21 @@ function createPoolKeysLoader(getProviderRow, autoDisabled) {
4275
4283
  }
4276
4284
 
4277
4285
  // src/commands/paths.ts
4278
- var import_node_path4 = require("path");
4286
+ var import_node_path5 = require("path");
4279
4287
  function defaultVouchersPath(configPath) {
4280
- return (0, import_node_path4.join)((0, import_node_path4.dirname)(configPath), "vouchers.json");
4288
+ return (0, import_node_path5.join)((0, import_node_path5.dirname)(configPath), "vouchers.json");
4281
4289
  }
4282
4290
  function defaultPricingPath(configPath) {
4283
- return (0, import_node_path4.join)((0, import_node_path4.dirname)(configPath), "pricing.json");
4291
+ return (0, import_node_path5.join)((0, import_node_path5.dirname)(configPath), "pricing.json");
4284
4292
  }
4285
4293
  function defaultUsageEventsPath(configPath) {
4286
- return (0, import_node_path4.join)((0, import_node_path4.dirname)(configPath), "usage-events.jsonl");
4294
+ return (0, import_node_path5.join)((0, import_node_path5.dirname)(configPath), "usage-events.jsonl");
4287
4295
  }
4288
4296
  function defaultAuditDir(configPath) {
4289
- return (0, import_node_path4.join)((0, import_node_path4.dirname)(configPath), "audit");
4297
+ return (0, import_node_path5.join)((0, import_node_path5.dirname)(configPath), "audit");
4290
4298
  }
4291
4299
  function defaultBillingDir(configPath) {
4292
- return (0, import_node_path4.join)((0, import_node_path4.dirname)(configPath), "billing");
4300
+ return (0, import_node_path5.join)((0, import_node_path5.dirname)(configPath), "billing");
4293
4301
  }
4294
4302
 
4295
4303
  // src/ports/ConfigFileProviderConfigSource.ts
@@ -5286,7 +5294,7 @@ var JsonVoucherDb = class {
5286
5294
 
5287
5295
  // src/ports/JsonSubscriptionCredentialStore.ts
5288
5296
  var import_node_fs13 = require("fs");
5289
- var import_node_path7 = require("path");
5297
+ var import_node_path8 = require("path");
5290
5298
  var import_SubscriptionAccountHealth = require("@omnicross/core/pipeline/SubscriptionAccountHealth");
5291
5299
  var import_upstreamFetch3 = require("@omnicross/core/pipeline/upstreamFetch");
5292
5300
  var import_SubscriptionIdentityStore = require("@omnicross/core/provider-proxy/identity/SubscriptionIdentityStore");
@@ -5368,9 +5376,9 @@ function findDuplicateCredentialIds(accounts) {
5368
5376
  // src/ports/external-cli-credentials.ts
5369
5377
  var import_node_fs11 = require("fs");
5370
5378
  var import_node_os2 = require("os");
5371
- var import_node_path5 = require("path");
5379
+ var import_node_path6 = require("path");
5372
5380
  function externalStorePath(provider, home = (0, import_node_os2.homedir)()) {
5373
- return provider === "claude" ? (0, import_node_path5.join)(home, ".claude", ".credentials.json") : (0, import_node_path5.join)(home, ".codex", "auth.json");
5381
+ return provider === "claude" ? (0, import_node_path6.join)(home, ".claude", ".credentials.json") : (0, import_node_path6.join)(home, ".codex", "auth.json");
5374
5382
  }
5375
5383
  function decodeJwtExpiryMs(token) {
5376
5384
  try {
@@ -5433,7 +5441,7 @@ function readExternalCliCredentials(provider, home = (0, import_node_os2.homedir
5433
5441
  // src/ports/external-cli-store.ts
5434
5442
  var import_node_fs12 = require("fs");
5435
5443
  var import_node_os3 = require("os");
5436
- var import_node_path6 = require("path");
5444
+ var import_node_path7 = require("path");
5437
5445
  function markerPath(provider, home) {
5438
5446
  return `${externalStorePath(provider, home)}.omnicross-managed`;
5439
5447
  }
@@ -5468,7 +5476,7 @@ function readExistingObject(path2) {
5468
5476
  }
5469
5477
  }
5470
5478
  function writeAtomic(path2, content) {
5471
- (0, import_node_fs12.mkdirSync)((0, import_node_path6.dirname)(path2), { recursive: true });
5479
+ (0, import_node_fs12.mkdirSync)((0, import_node_path7.dirname)(path2), { recursive: true });
5472
5480
  const temp = `${path2}.omnicross-tmp`;
5473
5481
  (0, import_node_fs12.writeFileSync)(temp, content, "utf8");
5474
5482
  (0, import_node_fs12.renameSync)(temp, path2);
@@ -6139,7 +6147,7 @@ var JsonSubscriptionCredentialStore = class {
6139
6147
  * → `enc:v1:`; already-`enc:`/`$ENV` untouched) before serializing, so any
6140
6148
  * write — incl. child 4's future refresh writes — lands encrypted. */
6141
6149
  persist(config) {
6142
- (0, import_node_fs13.mkdirSync)((0, import_node_path7.dirname)(this.tokensPath), { recursive: true });
6150
+ (0, import_node_fs13.mkdirSync)((0, import_node_path8.dirname)(this.tokensPath), { recursive: true });
6143
6151
  const encrypted = encryptTokens(config, this.box);
6144
6152
  (0, import_node_fs13.writeFileSync)(this.tokensPath, JSON.stringify(encrypted, null, 2) + "\n", "utf8");
6145
6153
  }
@@ -6489,7 +6497,7 @@ var AccountHealthSweeper = class {
6489
6497
 
6490
6498
  // src/audit/AuditPruneSweeper.ts
6491
6499
  var import_node_fs14 = require("fs");
6492
- var import_node_path8 = require("path");
6500
+ var import_node_path9 = require("path");
6493
6501
 
6494
6502
  // src/audit/auditFiles.ts
6495
6503
  var AUDIT_FILE_RE = /^audit-(\d{4})-(\d{2})-(\d{2})\.jsonl$/;
@@ -6515,8 +6523,8 @@ function auditFileDateMs(fileName) {
6515
6523
  var DAY_MS = 24 * 60 * 6e4;
6516
6524
  var SWEEP_INTERVAL_MS2 = 60 * 6e4;
6517
6525
  var AuditPruneSweeper = class {
6518
- constructor(auditDir, logger, config, intervalMs = SWEEP_INTERVAL_MS2, now = Date.now) {
6519
- this.auditDir = auditDir;
6526
+ constructor(auditDir2, logger, config, intervalMs = SWEEP_INTERVAL_MS2, now = Date.now) {
6527
+ this.auditDir = auditDir2;
6520
6528
  this.logger = logger;
6521
6529
  this.config = config;
6522
6530
  this.intervalMs = intervalMs;
@@ -6572,7 +6580,7 @@ var AuditPruneSweeper = class {
6572
6580
  const dateMs = auditFileDateMs(file);
6573
6581
  if (dateMs === null || dateMs >= cutoff) continue;
6574
6582
  try {
6575
- (0, import_node_fs14.unlinkSync)((0, import_node_path8.join)(this.auditDir, file));
6583
+ (0, import_node_fs14.unlinkSync)((0, import_node_path9.join)(this.auditDir, file));
6576
6584
  removed += 1;
6577
6585
  } catch (error) {
6578
6586
  this.logger.warn("[AuditPruneSweeper] failed to unlink expired audit file", {
@@ -6596,14 +6604,14 @@ var AuditPruneSweeper = class {
6596
6604
 
6597
6605
  // src/audit/auditReader.ts
6598
6606
  var import_node_fs15 = require("fs");
6599
- var import_node_path9 = require("path");
6607
+ var import_node_path10 = require("path");
6600
6608
  var DEFAULT_LIMIT = 200;
6601
6609
  var MAX_LIMIT = 2e3;
6602
- function readAuditRecords(auditDir, query = {}) {
6603
- if (!(0, import_node_fs15.existsSync)(auditDir)) return [];
6610
+ function readAuditRecords(auditDir2, query = {}) {
6611
+ if (!(0, import_node_fs15.existsSync)(auditDir2)) return [];
6604
6612
  let files;
6605
6613
  try {
6606
- files = (0, import_node_fs15.readdirSync)(auditDir).filter((f) => AUDIT_FILE_RE.test(f));
6614
+ files = (0, import_node_fs15.readdirSync)(auditDir2).filter((f) => AUDIT_FILE_RE.test(f));
6607
6615
  } catch {
6608
6616
  return [];
6609
6617
  }
@@ -6614,7 +6622,7 @@ function readAuditRecords(auditDir, query = {}) {
6614
6622
  for (const file of files.sort().reverse()) {
6615
6623
  let raw;
6616
6624
  try {
6617
- raw = (0, import_node_fs15.readFileSync)((0, import_node_path9.join)(auditDir, file), "utf8");
6625
+ raw = (0, import_node_fs15.readFileSync)((0, import_node_path10.join)(auditDir2, file), "utf8");
6618
6626
  } catch {
6619
6627
  continue;
6620
6628
  }
@@ -6644,10 +6652,10 @@ function isAuditRecord(value) {
6644
6652
 
6645
6653
  // src/audit/AuditWriter.ts
6646
6654
  var import_node_fs16 = require("fs");
6647
- var import_node_path10 = require("path");
6655
+ var import_node_path11 = require("path");
6648
6656
  var AuditWriter = class {
6649
- constructor(auditDir, logger, defer = (fn) => setTimeout(fn, 0)) {
6650
- this.auditDir = auditDir;
6657
+ constructor(auditDir2, logger, defer = (fn) => setTimeout(fn, 0)) {
6658
+ this.auditDir = auditDir2;
6651
6659
  this.logger = logger;
6652
6660
  this.defer = defer;
6653
6661
  }
@@ -6680,7 +6688,7 @@ var AuditWriter = class {
6680
6688
  (0, import_node_fs16.mkdirSync)(this.auditDir, { recursive: true });
6681
6689
  this.dirEnsured = true;
6682
6690
  }
6683
- const file = (0, import_node_path10.join)(this.auditDir, auditFileName(record.ts));
6691
+ const file = (0, import_node_path11.join)(this.auditDir, auditFileName(record.ts));
6684
6692
  (0, import_node_fs16.appendFileSync)(file, JSON.stringify(record) + "\n", "utf8");
6685
6693
  }
6686
6694
  };
@@ -6688,7 +6696,7 @@ var AuditWriter = class {
6688
6696
  // src/billing/BillingPublisher.ts
6689
6697
  var import_node_fs17 = require("fs");
6690
6698
  var import_node_crypto10 = require("crypto");
6691
- var import_node_path11 = require("path");
6699
+ var import_node_path12 = require("path");
6692
6700
  var import_upstreamFetch5 = require("@omnicross/core/pipeline/upstreamFetch");
6693
6701
 
6694
6702
  // src/billing/billingFiles.ts
@@ -6759,7 +6767,7 @@ var BillingPublisher = class {
6759
6767
  */
6760
6768
  appendNow(event) {
6761
6769
  this.ensureDir();
6762
- const file = (0, import_node_path11.join)(this.billingDir, billingFileName(event.ts));
6770
+ const file = (0, import_node_path12.join)(this.billingDir, billingFileName(event.ts));
6763
6771
  (0, import_node_fs17.appendFileSync)(file, JSON.stringify(event) + "\n", "utf8");
6764
6772
  }
6765
6773
  /**
@@ -6809,7 +6817,7 @@ var BillingPublisher = class {
6809
6817
  markDelivered(event) {
6810
6818
  try {
6811
6819
  this.ensureDir();
6812
- const file = (0, import_node_path11.join)(this.billingDir, deliveredFileName(event.ts));
6820
+ const file = (0, import_node_path12.join)(this.billingDir, deliveredFileName(event.ts));
6813
6821
  (0, import_node_fs17.appendFileSync)(file, JSON.stringify({ id: event.id, deliveredAt: this.now() }) + "\n", "utf8");
6814
6822
  } catch (error) {
6815
6823
  this.logger.warn("[BillingPublisher] failed to append delivery marker", {
@@ -6826,7 +6834,7 @@ var BillingPublisher = class {
6826
6834
 
6827
6835
  // src/billing/billingReader.ts
6828
6836
  var import_node_fs18 = require("fs");
6829
- var import_node_path12 = require("path");
6837
+ var import_node_path13 = require("path");
6830
6838
  function readBillingLedger(billingDir) {
6831
6839
  const view = { events: [], deliveredIds: /* @__PURE__ */ new Set() };
6832
6840
  if (!(0, import_node_fs18.existsSync)(billingDir)) return view;
@@ -6863,7 +6871,7 @@ function readBillingStatus(billingDir) {
6863
6871
  function parseLines(dir, file) {
6864
6872
  let raw;
6865
6873
  try {
6866
- raw = (0, import_node_fs18.readFileSync)((0, import_node_path12.join)(dir, file), "utf8");
6874
+ raw = (0, import_node_fs18.readFileSync)((0, import_node_path13.join)(dir, file), "utf8");
6867
6875
  } catch {
6868
6876
  return [];
6869
6877
  }
@@ -7304,7 +7312,7 @@ function buildDaemon(config, paths) {
7304
7312
  // lines through the injected logger (honors level/format/file sink).
7305
7313
  logger
7306
7314
  });
7307
- const auditDir = defaultAuditDir(paths.configPath);
7315
+ const auditDir2 = defaultAuditDir(paths.configPath);
7308
7316
  const billingDir = defaultBillingDir(paths.configPath);
7309
7317
  const adminServer = new AdminServer({
7310
7318
  configPath: paths.configPath,
@@ -7380,7 +7388,7 @@ function buildDaemon(config, paths) {
7380
7388
  // date-rotated audit store. Bound to the store dir here so the AdminServer
7381
7389
  // carries no path/store coupling. Records hold IP/UA/bodies → admin-only,
7382
7390
  // NEVER unauth, NEVER on `/health`. Routed in `AdminServer` (not `adminApi.ts`).
7383
- auditReader: (query) => readAuditRecords(auditDir, query),
7391
+ auditReader: (query) => readAuditRecords(auditDir2, query),
7384
7392
  // billing-event-stream: the AUTHED `GET /admin/api/billing-status` returns the
7385
7393
  // secret-free total/delivered/pending counts of the durable ledger.
7386
7394
  billingStatusReader: () => readBillingStatus(billingDir)
@@ -7390,9 +7398,9 @@ function buildDaemon(config, paths) {
7390
7398
  fetchImpl: (url, init) => (0, import_upstreamFetch7.fetchUpstream)(url, init)
7391
7399
  });
7392
7400
  setWebhookRuntime(webhookDispatcher, (0, import_SubscriptionAccountHealth2.getSharedAccountHealth)());
7393
- const auditWriter = new AuditWriter(auditDir, logger);
7394
- const auditPruneSweeper = new AuditPruneSweeper(auditDir, logger, import_audit_types.DEFAULT_AUDIT_CONFIG);
7395
- setAuditRuntime(auditWriter, auditPruneSweeper);
7401
+ const auditWriter = new AuditWriter(auditDir2, logger);
7402
+ const auditPruneSweeper = new AuditPruneSweeper(auditDir2, logger, import_audit_types.DEFAULT_AUDIT_CONFIG);
7403
+ setAuditRuntime(auditWriter, auditPruneSweeper, auditDir2);
7396
7404
  const billingPublisher = new BillingPublisher(billingDir, logger);
7397
7405
  const billingRetrySweeper = new BillingRetrySweeper(
7398
7406
  billingDir,
package/dist/index.js CHANGED
@@ -1888,12 +1888,16 @@ function preserveWebhookSecrets(incoming, current) {
1888
1888
  }
1889
1889
 
1890
1890
  // src/audit/auditRuntime.ts
1891
+ import { join as join3 } from "path";
1891
1892
  import { setAuditCaptureConfig, setAuditSink } from "@omnicross/core/pipeline/auditSink";
1893
+ import { setUpstreamTracePath } from "@omnicross/core/pipeline/upstreamTrace";
1892
1894
  var writer = null;
1893
1895
  var sweeper = null;
1894
- function setAuditRuntime(w, s) {
1896
+ var auditDir = "";
1897
+ function setAuditRuntime(w, s, dir) {
1895
1898
  writer = w;
1896
1899
  sweeper = s;
1900
+ auditDir = dir;
1897
1901
  }
1898
1902
  function applyAuditConfig(config) {
1899
1903
  const enabled = config?.enabled === true && writer !== null;
@@ -1905,9 +1909,11 @@ function applyAuditConfig(config) {
1905
1909
  sweeper.configure(config);
1906
1910
  sweeper.start();
1907
1911
  }
1912
+ setUpstreamTracePath(config.captureBodies ? join3(auditDir, "upstream-trace.jsonl") : null);
1908
1913
  } else {
1909
1914
  setAuditCaptureConfig(null);
1910
1915
  setAuditSink(null);
1916
+ setUpstreamTracePath(null);
1911
1917
  if (sweeper) {
1912
1918
  if (config) sweeper.configure(config);
1913
1919
  sweeper.dispose();
@@ -1917,9 +1923,11 @@ function applyAuditConfig(config) {
1917
1923
  function resetAuditRuntimeForTests() {
1918
1924
  setAuditCaptureConfig(null);
1919
1925
  setAuditSink(null);
1926
+ setUpstreamTracePath(null);
1920
1927
  if (sweeper) sweeper.dispose();
1921
1928
  writer = null;
1922
1929
  sweeper = null;
1930
+ auditDir = "";
1923
1931
  }
1924
1932
 
1925
1933
  // src/billing/billingRuntime.ts
@@ -3877,7 +3885,7 @@ async function handleUiStatic(req, res, urlPath, uiDist) {
3877
3885
  }
3878
3886
 
3879
3887
  // src/admin/version.ts
3880
- var DAEMON_VERSION = true ? "0.1.4" : "0.0.0-dev";
3888
+ var DAEMON_VERSION = true ? "0.1.5" : "0.0.0-dev";
3881
3889
 
3882
3890
  // src/admin/AdminServer.ts
3883
3891
  var LOOPBACK_ADDR = "127.0.0.1";
@@ -4259,21 +4267,21 @@ function createPoolKeysLoader(getProviderRow, autoDisabled) {
4259
4267
  }
4260
4268
 
4261
4269
  // src/commands/paths.ts
4262
- import { dirname as dirname2, join as join3 } from "path";
4270
+ import { dirname as dirname2, join as join4 } from "path";
4263
4271
  function defaultVouchersPath(configPath) {
4264
- return join3(dirname2(configPath), "vouchers.json");
4272
+ return join4(dirname2(configPath), "vouchers.json");
4265
4273
  }
4266
4274
  function defaultPricingPath(configPath) {
4267
- return join3(dirname2(configPath), "pricing.json");
4275
+ return join4(dirname2(configPath), "pricing.json");
4268
4276
  }
4269
4277
  function defaultUsageEventsPath(configPath) {
4270
- return join3(dirname2(configPath), "usage-events.jsonl");
4278
+ return join4(dirname2(configPath), "usage-events.jsonl");
4271
4279
  }
4272
4280
  function defaultAuditDir(configPath) {
4273
- return join3(dirname2(configPath), "audit");
4281
+ return join4(dirname2(configPath), "audit");
4274
4282
  }
4275
4283
  function defaultBillingDir(configPath) {
4276
- return join3(dirname2(configPath), "billing");
4284
+ return join4(dirname2(configPath), "billing");
4277
4285
  }
4278
4286
 
4279
4287
  // src/ports/ConfigFileProviderConfigSource.ts
@@ -5359,9 +5367,9 @@ function findDuplicateCredentialIds(accounts) {
5359
5367
  // src/ports/external-cli-credentials.ts
5360
5368
  import { existsSync as existsSync8, readFileSync as readFileSync8 } from "fs";
5361
5369
  import { homedir as homedir2 } from "os";
5362
- import { join as join4 } from "path";
5370
+ import { join as join5 } from "path";
5363
5371
  function externalStorePath(provider, home = homedir2()) {
5364
- return provider === "claude" ? join4(home, ".claude", ".credentials.json") : join4(home, ".codex", "auth.json");
5372
+ return provider === "claude" ? join5(home, ".claude", ".credentials.json") : join5(home, ".codex", "auth.json");
5365
5373
  }
5366
5374
  function decodeJwtExpiryMs(token) {
5367
5375
  try {
@@ -6480,7 +6488,7 @@ var AccountHealthSweeper = class {
6480
6488
 
6481
6489
  // src/audit/AuditPruneSweeper.ts
6482
6490
  import { existsSync as existsSync11, readdirSync, unlinkSync } from "fs";
6483
- import { join as join5 } from "path";
6491
+ import { join as join6 } from "path";
6484
6492
 
6485
6493
  // src/audit/auditFiles.ts
6486
6494
  var AUDIT_FILE_RE = /^audit-(\d{4})-(\d{2})-(\d{2})\.jsonl$/;
@@ -6506,8 +6514,8 @@ function auditFileDateMs(fileName) {
6506
6514
  var DAY_MS = 24 * 60 * 6e4;
6507
6515
  var SWEEP_INTERVAL_MS2 = 60 * 6e4;
6508
6516
  var AuditPruneSweeper = class {
6509
- constructor(auditDir, logger, config, intervalMs = SWEEP_INTERVAL_MS2, now = Date.now) {
6510
- this.auditDir = auditDir;
6517
+ constructor(auditDir2, logger, config, intervalMs = SWEEP_INTERVAL_MS2, now = Date.now) {
6518
+ this.auditDir = auditDir2;
6511
6519
  this.logger = logger;
6512
6520
  this.config = config;
6513
6521
  this.intervalMs = intervalMs;
@@ -6563,7 +6571,7 @@ var AuditPruneSweeper = class {
6563
6571
  const dateMs = auditFileDateMs(file);
6564
6572
  if (dateMs === null || dateMs >= cutoff) continue;
6565
6573
  try {
6566
- unlinkSync(join5(this.auditDir, file));
6574
+ unlinkSync(join6(this.auditDir, file));
6567
6575
  removed += 1;
6568
6576
  } catch (error) {
6569
6577
  this.logger.warn("[AuditPruneSweeper] failed to unlink expired audit file", {
@@ -6587,14 +6595,14 @@ var AuditPruneSweeper = class {
6587
6595
 
6588
6596
  // src/audit/auditReader.ts
6589
6597
  import { existsSync as existsSync12, readdirSync as readdirSync2, readFileSync as readFileSync11 } from "fs";
6590
- import { join as join6 } from "path";
6598
+ import { join as join7 } from "path";
6591
6599
  var DEFAULT_LIMIT = 200;
6592
6600
  var MAX_LIMIT = 2e3;
6593
- function readAuditRecords(auditDir, query = {}) {
6594
- if (!existsSync12(auditDir)) return [];
6601
+ function readAuditRecords(auditDir2, query = {}) {
6602
+ if (!existsSync12(auditDir2)) return [];
6595
6603
  let files;
6596
6604
  try {
6597
- files = readdirSync2(auditDir).filter((f) => AUDIT_FILE_RE.test(f));
6605
+ files = readdirSync2(auditDir2).filter((f) => AUDIT_FILE_RE.test(f));
6598
6606
  } catch {
6599
6607
  return [];
6600
6608
  }
@@ -6605,7 +6613,7 @@ function readAuditRecords(auditDir, query = {}) {
6605
6613
  for (const file of files.sort().reverse()) {
6606
6614
  let raw;
6607
6615
  try {
6608
- raw = readFileSync11(join6(auditDir, file), "utf8");
6616
+ raw = readFileSync11(join7(auditDir2, file), "utf8");
6609
6617
  } catch {
6610
6618
  continue;
6611
6619
  }
@@ -6635,10 +6643,10 @@ function isAuditRecord(value) {
6635
6643
 
6636
6644
  // src/audit/AuditWriter.ts
6637
6645
  import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync4 } from "fs";
6638
- import { join as join7 } from "path";
6646
+ import { join as join8 } from "path";
6639
6647
  var AuditWriter = class {
6640
- constructor(auditDir, logger, defer = (fn) => setTimeout(fn, 0)) {
6641
- this.auditDir = auditDir;
6648
+ constructor(auditDir2, logger, defer = (fn) => setTimeout(fn, 0)) {
6649
+ this.auditDir = auditDir2;
6642
6650
  this.logger = logger;
6643
6651
  this.defer = defer;
6644
6652
  }
@@ -6671,7 +6679,7 @@ var AuditWriter = class {
6671
6679
  mkdirSync4(this.auditDir, { recursive: true });
6672
6680
  this.dirEnsured = true;
6673
6681
  }
6674
- const file = join7(this.auditDir, auditFileName(record.ts));
6682
+ const file = join8(this.auditDir, auditFileName(record.ts));
6675
6683
  appendFileSync2(file, JSON.stringify(record) + "\n", "utf8");
6676
6684
  }
6677
6685
  };
@@ -6679,7 +6687,7 @@ var AuditWriter = class {
6679
6687
  // src/billing/BillingPublisher.ts
6680
6688
  import { appendFileSync as appendFileSync3, mkdirSync as mkdirSync5 } from "fs";
6681
6689
  import { createHmac } from "crypto";
6682
- import { join as join8 } from "path";
6690
+ import { join as join9 } from "path";
6683
6691
  import { fetchUpstream as fetchUpstream4 } from "@omnicross/core/pipeline/upstreamFetch";
6684
6692
 
6685
6693
  // src/billing/billingFiles.ts
@@ -6750,7 +6758,7 @@ var BillingPublisher = class {
6750
6758
  */
6751
6759
  appendNow(event) {
6752
6760
  this.ensureDir();
6753
- const file = join8(this.billingDir, billingFileName(event.ts));
6761
+ const file = join9(this.billingDir, billingFileName(event.ts));
6754
6762
  appendFileSync3(file, JSON.stringify(event) + "\n", "utf8");
6755
6763
  }
6756
6764
  /**
@@ -6800,7 +6808,7 @@ var BillingPublisher = class {
6800
6808
  markDelivered(event) {
6801
6809
  try {
6802
6810
  this.ensureDir();
6803
- const file = join8(this.billingDir, deliveredFileName(event.ts));
6811
+ const file = join9(this.billingDir, deliveredFileName(event.ts));
6804
6812
  appendFileSync3(file, JSON.stringify({ id: event.id, deliveredAt: this.now() }) + "\n", "utf8");
6805
6813
  } catch (error) {
6806
6814
  this.logger.warn("[BillingPublisher] failed to append delivery marker", {
@@ -6817,7 +6825,7 @@ var BillingPublisher = class {
6817
6825
 
6818
6826
  // src/billing/billingReader.ts
6819
6827
  import { existsSync as existsSync13, readdirSync as readdirSync3, readFileSync as readFileSync12 } from "fs";
6820
- import { join as join9 } from "path";
6828
+ import { join as join10 } from "path";
6821
6829
  function readBillingLedger(billingDir) {
6822
6830
  const view = { events: [], deliveredIds: /* @__PURE__ */ new Set() };
6823
6831
  if (!existsSync13(billingDir)) return view;
@@ -6854,7 +6862,7 @@ function readBillingStatus(billingDir) {
6854
6862
  function parseLines(dir, file) {
6855
6863
  let raw;
6856
6864
  try {
6857
- raw = readFileSync12(join9(dir, file), "utf8");
6865
+ raw = readFileSync12(join10(dir, file), "utf8");
6858
6866
  } catch {
6859
6867
  return [];
6860
6868
  }
@@ -7295,7 +7303,7 @@ function buildDaemon(config, paths) {
7295
7303
  // lines through the injected logger (honors level/format/file sink).
7296
7304
  logger
7297
7305
  });
7298
- const auditDir = defaultAuditDir(paths.configPath);
7306
+ const auditDir2 = defaultAuditDir(paths.configPath);
7299
7307
  const billingDir = defaultBillingDir(paths.configPath);
7300
7308
  const adminServer = new AdminServer({
7301
7309
  configPath: paths.configPath,
@@ -7371,7 +7379,7 @@ function buildDaemon(config, paths) {
7371
7379
  // date-rotated audit store. Bound to the store dir here so the AdminServer
7372
7380
  // carries no path/store coupling. Records hold IP/UA/bodies → admin-only,
7373
7381
  // NEVER unauth, NEVER on `/health`. Routed in `AdminServer` (not `adminApi.ts`).
7374
- auditReader: (query) => readAuditRecords(auditDir, query),
7382
+ auditReader: (query) => readAuditRecords(auditDir2, query),
7375
7383
  // billing-event-stream: the AUTHED `GET /admin/api/billing-status` returns the
7376
7384
  // secret-free total/delivered/pending counts of the durable ledger.
7377
7385
  billingStatusReader: () => readBillingStatus(billingDir)
@@ -7381,9 +7389,9 @@ function buildDaemon(config, paths) {
7381
7389
  fetchImpl: (url, init) => fetchUpstream6(url, init)
7382
7390
  });
7383
7391
  setWebhookRuntime(webhookDispatcher, getSharedAccountHealth2());
7384
- const auditWriter = new AuditWriter(auditDir, logger);
7385
- const auditPruneSweeper = new AuditPruneSweeper(auditDir, logger, DEFAULT_AUDIT_CONFIG);
7386
- setAuditRuntime(auditWriter, auditPruneSweeper);
7392
+ const auditWriter = new AuditWriter(auditDir2, logger);
7393
+ const auditPruneSweeper = new AuditPruneSweeper(auditDir2, logger, DEFAULT_AUDIT_CONFIG);
7394
+ setAuditRuntime(auditWriter, auditPruneSweeper, auditDir2);
7387
7395
  const billingPublisher = new BillingPublisher(billingDir, logger);
7388
7396
  const billingRetrySweeper = new BillingRetrySweeper(
7389
7397
  billingDir,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnicross/daemon",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Omnicross standalone daemon 鈥?the bare-Node embedder of @omnicross/core with an admin HTTP API + dashboard.",
5
5
  "license": "MIT",
6
6
  "author": "Sayo (https://github.com/Dumoedss)",