@tempoxyz/patron 0.0.13 → 0.0.14

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/bin.js CHANGED
@@ -4,10 +4,10 @@ const require = __patronCreateRequire(import.meta.url)
4
4
 
5
5
  // src/bin.ts
6
6
  if (process.argv[2] === "hook") {
7
- const { runHookProcess } = await import("./chunks/hook-process-TN5MFLK5.js");
7
+ const { runHookProcess } = await import("./chunks/hook-process-RURAGR7W.js");
8
8
  await runHookProcess().catch(() => void 0);
9
9
  process.exit(0);
10
10
  } else {
11
- const { run } = await import("./chunks/-ALBR7TS6.js");
11
+ const { run } = await import("./chunks/-CE2UCGLQ.js");
12
12
  process.exitCode = await run(process.argv.slice(2));
13
13
  }
@@ -37,9 +37,10 @@ import {
37
37
  upgradeCodex,
38
38
  withHooksKey,
39
39
  withPatronGroup,
40
+ withPatronStatus,
40
41
  withoutPatronHandlers,
41
42
  writeJsonObject
42
- } from "./chunk-5VAR4V2W.js";
43
+ } from "./chunk-XUDTL3AP.js";
43
44
  import {
44
45
  AGENT_IDS,
45
46
  ensureHome,
@@ -52,7 +53,7 @@ import {
52
53
  withLock,
53
54
  writeConfig,
54
55
  writePrivateFile
55
- } from "./chunk-6TTNL3HT.js";
56
+ } from "./chunk-A66D2RFJ.js";
56
57
 
57
58
  // src/index.ts
58
59
  import { readFileSync } from "node:fs";
@@ -161,22 +162,11 @@ function patronGroup(command) {
161
162
  function withPatronHook(settings, command) {
162
163
  return withPatronGroup(settings, EVENT, patronGroup(command));
163
164
  }
164
- function patronCommand(settings) {
165
- const groups = isObject(settings.hooks) ? settings.hooks[EVENT] : void 0;
166
- const handler = (Array.isArray(groups) ? groups : []).flatMap(
167
- (group) => isObject(group) && Array.isArray(group.hooks) ? group.hooks : []
168
- ).find(isPatronHandler);
169
- return typeof handler?.command === "string" ? handler.command : void 0;
170
- }
171
165
  async function upgradeClaudeHook(path) {
172
166
  const settings = await readJsonObject(path);
173
- const command = patronCommand(settings);
174
- if (!command) return false;
175
- const groups = isObject(settings.hooks) ? settings.hooks[EVENT] : void 0;
176
- const wanted = JSON.stringify(patronGroup(command));
177
- if (Array.isArray(groups) && groups.some((group) => JSON.stringify(group) === wanted))
178
- return false;
179
- await writeJsonObject(path, withPatronHook(settings, command));
167
+ const next = withPatronStatus(settings, EVENT, CLAUDE_HOOK_STATUS);
168
+ if (!next) return false;
169
+ await writeJsonObject(path, next);
180
170
  return true;
181
171
  }
182
172
  function withoutPatronHook(settings) {
@@ -624,7 +614,7 @@ ${styleText(title, "bold", color)}
624
614
  // src/purchase.ts
625
615
  var REFILL_LOCK_STALE_MS = 5 * 60 * 1e3;
626
616
  var defaultOpenWallet = async (settings, config, issuer, maxUnits) => {
627
- const { openWallet } = await import("./wallet-MEBNL43A.js");
617
+ const { openWallet } = await import("./wallet-P26QSI4Y.js");
628
618
  return openWallet(settings, config.wallet, issuer, maxUnits);
629
619
  };
630
620
  async function buyWithinBudget(settings, config, wanted, openWallet = defaultOpenWallet) {
@@ -891,7 +881,7 @@ async function setup(deps) {
891
881
  deps,
892
882
  settings.privateKey ? "Using PATRON_PRIVATE_KEY" : "Signing in with Tempo Wallet"
893
883
  );
894
- const { signIn } = await import("./wallet-MEBNL43A.js");
884
+ const { signIn } = await import("./wallet-P26QSI4Y.js");
895
885
  const account = await signIn(settings, { budgetUnits, issuer, output: deps.stdout });
896
886
  done(deps, `Signed in as ${account.address}`);
897
887
  const config = {
@@ -1005,7 +995,7 @@ async function changeBudget(deps, input) {
1005
995
  } else budget = await askBudget(deps, config.monthlyBudgetUsd);
1006
996
  if (config.wallet === "tempo" && budget > config.monthlyBudgetUsd) {
1007
997
  step(deps, "Approve the new spending limit in Tempo Wallet");
1008
- const { authorizeBudget } = await import("./wallet-MEBNL43A.js");
998
+ const { authorizeBudget } = await import("./wallet-P26QSI4Y.js");
1009
999
  const issuer = await loadIssuer(settings.home, settings.gatewayUrl, {
1010
1000
  fetch: deps.fetch
1011
1001
  });
@@ -1117,7 +1107,7 @@ async function setName(deps, name) {
1117
1107
  const issuer = await loadIssuer(settings.home, settings.gatewayUrl, {
1118
1108
  fetch: deps.fetch
1119
1109
  });
1120
- const open = deps.openWallet ?? (async (s, c, i, max) => (await import("./wallet-MEBNL43A.js")).openWallet(s, c.wallet, i, max));
1110
+ const open = deps.openWallet ?? (async (s, c, i, max) => (await import("./wallet-P26QSI4Y.js")).openWallet(s, c.wallet, i, max));
1121
1111
  const wallet = await open(settings, config, issuer, 0n);
1122
1112
  await setProfile(settings.gatewayUrl, wallet, name, deps.fetch);
1123
1113
  await writeConfig(settings.home, { ...config, name });
@@ -41,7 +41,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
41
41
  ));
42
42
 
43
43
  // src/state.ts
44
- import { chmod, mkdir, readFile, rename, writeFile } from "node:fs/promises";
44
+ import { chmod, mkdir, readFile, realpath, rename, writeFile } from "node:fs/promises";
45
45
  import { join } from "node:path";
46
46
 
47
47
  // src/lock.ts
@@ -120,7 +120,8 @@ async function readJson(path) {
120
120
  throw error;
121
121
  }
122
122
  }
123
- async function writePrivateFile(path, contents) {
123
+ async function writePrivateFile(link, contents) {
124
+ const path = await realpath(link).catch(() => link);
124
125
  const temporary = `${path}.${process.pid}.${Date.now()}.tmp`;
125
126
  await writeFile(temporary, contents, { mode: 384 });
126
127
  await chmod(temporary, 384);
@@ -10,7 +10,7 @@ import {
10
10
  statePaths,
11
11
  withLock,
12
12
  writePrivateFile
13
- } from "./chunk-6TTNL3HT.js";
13
+ } from "./chunk-A66D2RFJ.js";
14
14
 
15
15
  // ../../node_modules/.pnpm/tldts@7.4.19/node_modules/tldts/dist/cjs/index.js
16
16
  var require_cjs = __commonJS({
@@ -35772,6 +35772,24 @@ async function writeJsonObject(path, value) {
35772
35772
  await writePrivateFile(path, `${JSON.stringify(value, null, 2)}
35773
35773
  `);
35774
35774
  }
35775
+ function withPatronStatus(settings, event, status) {
35776
+ const groups = isObject2(settings.hooks) ? settings.hooks[event] : void 0;
35777
+ if (!Array.isArray(groups)) return void 0;
35778
+ let changed = false;
35779
+ const next = groups.map((group) => {
35780
+ if (!isObject2(group) || !Array.isArray(group.hooks)) return group;
35781
+ return {
35782
+ ...group,
35783
+ hooks: group.hooks.map((handler) => {
35784
+ if (!isPatronHandler(handler) || !isObject2(handler) || "statusMessage" in handler)
35785
+ return handler;
35786
+ changed = true;
35787
+ return { ...handler, statusMessage: status };
35788
+ })
35789
+ };
35790
+ });
35791
+ return changed ? withHooksKey(settings, event, next) : void 0;
35792
+ }
35775
35793
 
35776
35794
  // src/codex.ts
35777
35795
  var CODEX_NOTIFY_MARKER = "# added by patron";
@@ -35857,13 +35875,9 @@ async function installCodex(paths, command, platform = process.platform) {
35857
35875
  }
35858
35876
  async function upgradeCodex(paths) {
35859
35877
  const settings = await readJsonObject(paths.hooks);
35860
- const groups = isObject2(settings.hooks) ? settings.hooks[EVENT] : void 0;
35861
- const handler = (Array.isArray(groups) ? groups : []).flatMap(
35862
- (group) => isObject2(group) && Array.isArray(group.hooks) ? group.hooks : []
35863
- ).find(isPatronHandler);
35864
- const command = typeof handler?.command === "string" ? handler.command : void 0;
35865
- if (!command || hasStopGroup(settings, command)) return false;
35866
- await writeJsonObject(paths.hooks, withCodexStopHook(settings, command));
35878
+ const next = withPatronStatus(settings, EVENT, CODEX_HOOK_STATUS);
35879
+ if (!next) return false;
35880
+ await writeJsonObject(paths.hooks, next);
35867
35881
  return true;
35868
35882
  }
35869
35883
  async function removeCodex(paths) {
@@ -35925,6 +35939,7 @@ export {
35925
35939
  withHooksKey,
35926
35940
  readJsonObject,
35927
35941
  writeJsonObject,
35942
+ withPatronStatus,
35928
35943
  codexHome,
35929
35944
  codexPaths,
35930
35945
  installCodex,
@@ -12,14 +12,14 @@ import {
12
12
  settingsFor,
13
13
  spend,
14
14
  startRefill
15
- } from "./chunk-5VAR4V2W.js";
15
+ } from "./chunk-XUDTL3AP.js";
16
16
  import {
17
17
  readConfig,
18
18
  readUsage,
19
19
  updateUsage,
20
20
  withLock,
21
21
  writePrivateFile
22
- } from "./chunk-6TTNL3HT.js";
22
+ } from "./chunk-A66D2RFJ.js";
23
23
 
24
24
  // src/hook.ts
25
25
  import { homedir } from "node:os";
@@ -2,7 +2,7 @@ import { createRequire as __patronCreateRequire } from 'node:module'
2
2
  const require = __patronCreateRequire(import.meta.url)
3
3
  import {
4
4
  statePaths
5
- } from "./chunk-6TTNL3HT.js";
5
+ } from "./chunk-A66D2RFJ.js";
6
6
 
7
7
  // src/wallet.ts
8
8
  import { Store } from "accounts";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tempoxyz/patron",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "description": "Pay the websites your AI agents read, privately",
5
5
  "type": "module",
6
6
  "bin": {