@pretense/cli 0.6.26 → 0.6.27

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.
@@ -17,7 +17,7 @@ function versionFromPackageJson() {
17
17
  return void 0;
18
18
  }
19
19
  }
20
- var PRETENSE_VERSION = (true ? "0.6.26" : void 0) ?? versionFromPackageJson() ?? "0.0.0-unknown";
20
+ var PRETENSE_VERSION = (true ? "0.6.27" : void 0) ?? versionFromPackageJson() ?? "0.0.0-unknown";
21
21
 
22
22
  export {
23
23
  PRETENSE_VERSION
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  PRETENSE_VERSION
4
- } from "./chunk-ZSQPYJVT.js";
4
+ } from "./chunk-6L7NU7KI.js";
5
5
  import {
6
6
  __commonJS,
7
7
  __toESM,
@@ -7837,7 +7837,9 @@ import { execSync } from "child_process";
7837
7837
 
7838
7838
  // ../apps/proxy/dist/server.js
7839
7839
  init_esm_shims();
7840
- import { resolve as resolvePath } from "path";
7840
+ import { resolve as resolvePath, join as joinPath } from "path";
7841
+ import { existsSync as existsSync24, readFileSync as readFileSync33 } from "fs";
7842
+ import { homedir as homedir3 } from "os";
7841
7843
 
7842
7844
  // ../node_modules/.pnpm/hono@4.12.9/node_modules/hono/dist/index.js
7843
7845
  init_esm_shims();
@@ -16657,11 +16659,11 @@ function versionFromCliPackageJson() {
16657
16659
  return void 0;
16658
16660
  }
16659
16661
  function productVersion() {
16660
- return override ?? (true ? "0.6.26" : void 0) ?? versionFromCliPackageJson() ?? "0.0.0-unknown";
16662
+ return override ?? (true ? "0.6.27" : void 0) ?? versionFromCliPackageJson() ?? "0.0.0-unknown";
16661
16663
  }
16662
16664
  var UNKNOWN_COMMIT = "unknown";
16663
16665
  function bakedCommitSha() {
16664
- return "91077fab39006ac43c0256257c895b5534640e17".length > 0 ? "91077fab39006ac43c0256257c895b5534640e17" : UNKNOWN_COMMIT;
16666
+ return "2899946100b26294eb8ef8dbde2d50e63a5247a9".length > 0 ? "2899946100b26294eb8ef8dbde2d50e63a5247a9" : UNKNOWN_COMMIT;
16665
16667
  }
16666
16668
  var FEATURE_TIERS = {
16667
16669
  compliance_export: "pro",
@@ -17104,7 +17106,13 @@ async function streamWithRollingBuffer(upstreamResp, map, provider, requestId) {
17104
17106
  if (provider === "anthropic" && line.includes("content_block_stop")) {
17105
17107
  const stopIndex = blockStopIndex(line);
17106
17108
  if (stopIndex !== null) {
17107
- outputLines.push(...flushBlock(stopIndex), line);
17109
+ const flushed = flushBlock(stopIndex);
17110
+ if (flushed.length > 0) {
17111
+ const header = outputLines.length > 0 && outputLines[outputLines.length - 1].startsWith("event:") ? outputLines.pop() : null;
17112
+ outputLines.push(...flushed);
17113
+ if (header !== null) outputLines.push(header);
17114
+ }
17115
+ outputLines.push(line);
17108
17116
  continue;
17109
17117
  }
17110
17118
  }
@@ -17165,7 +17173,7 @@ async function streamWithRollingBuffer(upstreamResp, map, provider, requestId) {
17165
17173
  function buildFlushEvent(text, provider, kind, index) {
17166
17174
  if (provider === "anthropic") {
17167
17175
  const delta2 = kind === "input_json" ? { type: "input_json_delta", partial_json: text } : kind === "thinking" ? { type: "thinking_delta", thinking: text } : { type: "text_delta", text };
17168
- return "data: " + JSON.stringify({ type: "content_block_delta", index, delta: delta2 });
17176
+ return "event: content_block_delta\ndata: " + JSON.stringify({ type: "content_block_delta", index, delta: delta2 });
17169
17177
  }
17170
17178
  if (provider === "google") {
17171
17179
  const part = kind === "google_thought" ? { text, thought: true } : { text };
@@ -17357,6 +17365,37 @@ var _tierCache = /* @__PURE__ */ new Map();
17357
17365
  var TIER_CACHE_OK_MS = 6e4;
17358
17366
  var TIER_CACHE_FAIL_MS = 1e4;
17359
17367
  var TIER_VALIDATE_TIMEOUT_MS = 3e3;
17368
+ var LOCAL_KEY_CACHE_MS = 3e4;
17369
+ var _localKeyCache = null;
17370
+ function underTestRunner() {
17371
+ return Boolean(process.env["VITEST"]) || process.env["NODE_ENV"] === "test";
17372
+ }
17373
+ function readLocalPretenseApiKey() {
17374
+ const now = Date.now();
17375
+ if (_localKeyCache && _localKeyCache.expiresAt > now) return _localKeyCache.key;
17376
+ let key = null;
17377
+ const fromEnv = process.env["PRETENSE_API_KEY"]?.trim();
17378
+ if (fromEnv) {
17379
+ key = fromEnv;
17380
+ } else if (!underTestRunner()) {
17381
+ const path2 = joinPath(homedir3(), ".pretense", "credentials.json");
17382
+ try {
17383
+ if (existsSync24(path2)) {
17384
+ const creds = JSON.parse(readFileSync33(path2, "utf-8"));
17385
+ const raw2 = creds["apiKey"] ?? creds["api_key"];
17386
+ if (typeof raw2 === "string" && raw2.trim().length > 0) key = raw2.trim();
17387
+ }
17388
+ } catch {
17389
+ }
17390
+ }
17391
+ _localKeyCache = { key, expiresAt: now + LOCAL_KEY_CACHE_MS };
17392
+ return key;
17393
+ }
17394
+ function resolvePretenseKeyForRequest(headerKey) {
17395
+ const explicit = headerKey?.trim();
17396
+ if (explicit) return explicit;
17397
+ return readLocalPretenseApiKey() ?? void 0;
17398
+ }
17360
17399
  function tierApiRoot() {
17361
17400
  const raw2 = (process.env["PRETENSE_API_URL"] ?? "https://api.pretense.ai").trim();
17362
17401
  const normalized = /^https?:\/\//i.test(raw2) ? raw2 : `https://${raw2}`;
@@ -17832,7 +17871,7 @@ function createProxy(opts = {}) {
17832
17871
  return c.json({ error: { type: "invalid_request", message: "Empty request body" } }, 400);
17833
17872
  }
17834
17873
  {
17835
- const _apiKey = c.req.header("x-pretense-api-key") ?? c.req.header("authorization")?.replace(/^Bearer\s+/i, "");
17874
+ const _apiKey = resolvePretenseKeyForRequest(c.req.header("x-pretense-api-key"));
17836
17875
  const _effectiveTier = await resolveKeyTier(_apiKey);
17837
17876
  const _requestEnforcer = new PlanEnforcer(_effectiveTier, planCfg.tenantId);
17838
17877
  const QUOTA_PERIOD_DAYS3 = 7;
@@ -18240,7 +18279,7 @@ ${_upgradeTier === "enterprise" ? "Enterprise offers unlimited mutations \u2014
18240
18279
  sourceIp: c.req.header("x-forwarded-for") ?? c.req.header("x-real-ip")
18241
18280
  }));
18242
18281
  if (anyTokenized) {
18243
- const usageKey = c.req.header("x-pretense-api-key") ?? c.req.header("authorization")?.replace(/^Bearer\s+/i, "");
18282
+ const usageKey = resolvePretenseKeyForRequest(c.req.header("x-pretense-api-key"));
18244
18283
  uploadProxyUsage({
18245
18284
  apiKey: usageKey,
18246
18285
  identifiersMutated: mutationsApplied,
@@ -18369,8 +18408,8 @@ async function findFreePort(start, opts = {}) {
18369
18408
  init_esm_shims();
18370
18409
  import { existsSync as existsSync8, readFileSync as readFileSync6, unlinkSync } from "fs";
18371
18410
  import { join as join7 } from "path";
18372
- import { homedir as homedir3 } from "os";
18373
- function pidFilePath(home = homedir3()) {
18411
+ import { homedir as homedir4 } from "os";
18412
+ function pidFilePath(home = homedir4()) {
18374
18413
  return join7(process.env.PRETENSE_PID_DIR ?? join7(home, ".pretense"), "proxy.pid");
18375
18414
  }
18376
18415
  function isProcessAlive(pid) {
@@ -18585,9 +18624,9 @@ import chalk3 from "chalk";
18585
18624
  init_esm_shims();
18586
18625
  import { existsSync as existsSync9, readFileSync as readFileSync7 } from "fs";
18587
18626
  import { join as join8 } from "path";
18588
- import { homedir as homedir4 } from "os";
18627
+ import { homedir as homedir5 } from "os";
18589
18628
  function credentialsPath() {
18590
- return join8(homedir4(), ".pretense", "credentials.json");
18629
+ return join8(homedir5(), ".pretense", "credentials.json");
18591
18630
  }
18592
18631
  function readApiKey() {
18593
18632
  const fromEnv = process.env["PRETENSE_API_KEY"]?.trim();
@@ -20294,7 +20333,7 @@ function configCommand() {
20294
20333
  init_esm_shims();
20295
20334
  import { Command as Command8 } from "commander";
20296
20335
  import chalk8 from "chalk";
20297
- import { homedir as homedir5 } from "os";
20336
+ import { homedir as homedir6 } from "os";
20298
20337
  import { join as join12 } from "path";
20299
20338
  function logsCommand() {
20300
20339
  return new Command8("logs").description("Show recent audit log entries").option("-l, --limit <n>", "Number of entries to show", "50").option("--json", "Output as JSON", false).action((opts) => {
@@ -20302,7 +20341,7 @@ function logsCommand() {
20302
20341
  let store;
20303
20342
  let entries;
20304
20343
  try {
20305
- store = new AuditStore(join12(homedir5(), ".pretense", "audit.db"));
20344
+ store = new AuditStore(join12(homedir6(), ".pretense", "audit.db"));
20306
20345
  entries = store.getRecentEntries(limit);
20307
20346
  store.close();
20308
20347
  } catch {
@@ -20343,7 +20382,7 @@ init_esm_shims();
20343
20382
  import { Command as Command9 } from "commander";
20344
20383
  import chalk9 from "chalk";
20345
20384
  import { join as join13 } from "path";
20346
- import { homedir as homedir6 } from "os";
20385
+ import { homedir as homedir7 } from "os";
20347
20386
  function renderBar(percent, width = 30) {
20348
20387
  const filled = Math.min(Math.round(percent / 100 * width), width);
20349
20388
  const empty = width - filled;
@@ -20398,7 +20437,7 @@ function emptyUsagePayload(resolution) {
20398
20437
  };
20399
20438
  }
20400
20439
  function usageCommand() {
20401
- return new Command9("usage").description("Show plan usage vs limits for the current billing period").option("--db <path>", "Path to audit database", join13(homedir6(), ".pretense", "audit.db")).option("--json", "Output as JSON", false).option("--offline", "Do not contact the plan service to resolve the tier", false).action(async (opts) => {
20440
+ return new Command9("usage").description("Show plan usage vs limits for the current billing period").option("--db <path>", "Path to audit database", join13(homedir7(), ".pretense", "audit.db")).option("--json", "Output as JSON", false).option("--offline", "Do not contact the plan service to resolve the tier", false).action(async (opts) => {
20402
20441
  const resolution = await resolvePlanTier({ offline: opts.offline });
20403
20442
  const tier = resolution.tier;
20404
20443
  const collected = collectUsage(opts.db);
@@ -20587,9 +20626,9 @@ import { Command as Command10 } from "commander";
20587
20626
  import chalk10 from "chalk";
20588
20627
  import { existsSync as existsSync12, readFileSync as readFileSync11, unlinkSync as unlinkSync2 } from "fs";
20589
20628
  import { join as join14 } from "path";
20590
- import { homedir as homedir7 } from "os";
20629
+ import { homedir as homedir8 } from "os";
20591
20630
  import { execSync as execSync4 } from "child_process";
20592
- var CREDENTIALS_DIR = join14(homedir7(), ".pretense");
20631
+ var CREDENTIALS_DIR = join14(homedir8(), ".pretense");
20593
20632
  var CREDENTIALS_PATH = join14(CREDENTIALS_DIR, "credentials.json");
20594
20633
  async function verifyApiKey(apiKey) {
20595
20634
  const url = `${getConfiguredApiRoot()}/api/cli/auth/validate`;
@@ -21173,9 +21212,9 @@ import { Command as Command13 } from "commander";
21173
21212
  import chalk13 from "chalk";
21174
21213
  import { appendFileSync as appendFileSync3, readFileSync as readFileSync14, existsSync as existsSync14 } from "fs";
21175
21214
  import { join as join17 } from "path";
21176
- import { homedir as homedir8 } from "os";
21215
+ import { homedir as homedir9 } from "os";
21177
21216
  var IGNORE_FILE = ".pretenseignore";
21178
- var LAST_SCAN_PATH = join17(homedir8(), ".pretense", "last-scan.json");
21217
+ var LAST_SCAN_PATH = join17(homedir9(), ".pretense", "last-scan.json");
21179
21218
  function ignorePath() {
21180
21219
  return join17(process.cwd(), IGNORE_FILE);
21181
21220
  }
@@ -21573,9 +21612,9 @@ import { resolve as resolve6, extname as extname4 } from "path";
21573
21612
  // src/secret-crypto.ts
21574
21613
  init_esm_shims();
21575
21614
  import { createCipheriv, createDecipheriv, randomBytes as randomBytes3, hkdfSync as hkdfSync2 } from "crypto";
21576
- import { homedir as homedir9 } from "os";
21615
+ import { homedir as homedir10 } from "os";
21577
21616
  import { join as join19 } from "path";
21578
- var KEYS_DIR = join19(homedir9(), ".pretense", "keys");
21617
+ var KEYS_DIR = join19(homedir10(), ".pretense", "keys");
21579
21618
  var HKDF_SALT2 = Buffer.from("pretense-maps-v1", "utf-8");
21580
21619
  var HKDF_INFO2 = Buffer.from("secret-mapping-aes-256-gcm", "utf-8");
21581
21620
  var IV_LEN = 12;
@@ -21693,12 +21732,12 @@ function ensureDefaultMapPath(absFilePath, override2) {
21693
21732
 
21694
21733
  // src/local-audit.ts
21695
21734
  init_esm_shims();
21696
- import { homedir as homedir10 } from "os";
21735
+ import { homedir as homedir11 } from "os";
21697
21736
  import { join as join24 } from "path";
21698
21737
  import { randomUUID } from "crypto";
21699
21738
  import chalk15 from "chalk";
21700
21739
  function localAuditDbPath() {
21701
- return join24(homedir10(), ".pretense", "audit.db");
21740
+ return join24(homedir11(), ".pretense", "audit.db");
21702
21741
  }
21703
21742
  function recordLocalAudit(rec, dbPath = localAuditDbPath()) {
21704
21743
  let store = null;
@@ -22696,7 +22735,7 @@ function policyCommand() {
22696
22735
  init_esm_shims();
22697
22736
  import { Command as Command20 } from "commander";
22698
22737
  import chalk20 from "chalk";
22699
- import { homedir as homedir11 } from "os";
22738
+ import { homedir as homedir12 } from "os";
22700
22739
  import { join as join25 } from "path";
22701
22740
  var VALID_FORMATS2 = ["table", "csv", "json", "jsonl"];
22702
22741
  function toSafeAuditRow(e) {
@@ -22821,7 +22860,7 @@ function auditCommand() {
22821
22860
  `));
22822
22861
  process.exit(1);
22823
22862
  }
22824
- const dbPath = opts.db ?? join25(homedir11(), ".pretense", "audit.db");
22863
+ const dbPath = opts.db ?? join25(homedir12(), ".pretense", "audit.db");
22825
22864
  let rows;
22826
22865
  try {
22827
22866
  const store = new AuditStore(dbPath);
@@ -22882,7 +22921,7 @@ init_esm_shims();
22882
22921
  import { Command as Command21 } from "commander";
22883
22922
  import chalk21 from "chalk";
22884
22923
  import { join as join26 } from "path";
22885
- import { homedir as homedir12 } from "os";
22924
+ import { homedir as homedir13 } from "os";
22886
22925
  function remaining(used, limit) {
22887
22926
  if (limit === null) return null;
22888
22927
  return Math.max(0, limit - used);
@@ -22900,7 +22939,7 @@ function bar(used, limit, width = 24) {
22900
22939
  return chalk21.green(s);
22901
22940
  }
22902
22941
  function creditsCommand() {
22903
- return new Command21("credits").alias("tokens").description("Show remaining mutation budget for the current period").option("--db <path>", "Path to audit database", join26(homedir12(), ".pretense", "audit.db")).option("--json", "Output as JSON", false).option("--offline", "Do not contact the plan service to resolve the tier", false).action(async (opts) => {
22942
+ return new Command21("credits").alias("tokens").description("Show remaining mutation budget for the current period").option("--db <path>", "Path to audit database", join26(homedir13(), ".pretense", "audit.db")).option("--json", "Output as JSON", false).option("--offline", "Do not contact the plan service to resolve the tier", false).action(async (opts) => {
22904
22943
  const resolution = await resolvePlanTier({ offline: opts.offline });
22905
22944
  const tier = resolution.tier;
22906
22945
  const collected = collectUsage(opts.db);
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  PRETENSE_VERSION
4
- } from "./chunk-ZSQPYJVT.js";
4
+ } from "./chunk-6L7NU7KI.js";
5
5
  import {
6
6
  init_esm_shims
7
7
  } from "./chunk-TWMRHZGM.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pretense/cli",
3
- "version": "0.6.26",
3
+ "version": "0.6.27",
4
4
  "description": "Local-first AI firewall that mutates proprietary code before sending to LLM APIs",
5
5
  "type": "module",
6
6
  "bin": {
@@ -23,12 +23,12 @@
23
23
  "tsx": "^4.0.0",
24
24
  "typescript": "^5.4.0",
25
25
  "vitest": "^1.0.0",
26
+ "@pretense/billing": "0.1.0",
26
27
  "@pretense/compliance-engine": "0.1.0",
27
28
  "@pretense/protocol": "0.1.0",
28
29
  "@pretense/learner": "0.2.0",
29
- "@pretense/billing": "0.1.0",
30
- "@pretense/mutator": "0.2.0",
31
30
  "@pretense/proxy": "0.1.0",
31
+ "@pretense/mutator": "0.2.0",
32
32
  "@pretense/scanner": "0.2.0",
33
33
  "@pretense/scanner-rs": "0.2.0",
34
34
  "@pretense/store": "0.2.0"