@tempoxyz/patron 0.0.13 → 0.0.15
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 +2 -2
- package/dist/chunks/{-ALBR7TS6.js → -OLXWVEEQ.js} +14 -20
- package/dist/chunks/{chunk-6TTNL3HT.js → chunk-FXE4CGY7.js} +43 -7
- package/dist/chunks/{chunk-5VAR4V2W.js → chunk-REXWTXUY.js} +23 -8
- package/dist/chunks/{hook-process-TN5MFLK5.js → hook-process-BWDVTYRO.js} +2 -2
- package/dist/chunks/{wallet-MEBNL43A.js → wallet-JDUPZN7E.js} +1 -1
- package/package.json +1 -1
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-
|
|
7
|
+
const { runHookProcess } = await import("./chunks/hook-process-BWDVTYRO.js");
|
|
8
8
|
await runHookProcess().catch(() => void 0);
|
|
9
9
|
process.exit(0);
|
|
10
10
|
} else {
|
|
11
|
-
const { run } = await import("./chunks/-
|
|
11
|
+
const { run } = await import("./chunks/-OLXWVEEQ.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-
|
|
43
|
+
} from "./chunk-REXWTXUY.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-
|
|
56
|
+
} from "./chunk-FXE4CGY7.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
|
|
174
|
-
if (!
|
|
175
|
-
|
|
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-
|
|
617
|
+
const { openWallet } = await import("./wallet-JDUPZN7E.js");
|
|
628
618
|
return openWallet(settings, config.wallet, issuer, maxUnits);
|
|
629
619
|
};
|
|
630
620
|
async function buyWithinBudget(settings, config, wanted, openWallet = defaultOpenWallet) {
|
|
@@ -845,6 +835,10 @@ function done(deps, message) {
|
|
|
845
835
|
async function main(deps) {
|
|
846
836
|
const config = await readConfig(deps.settings.home);
|
|
847
837
|
if (!config) return setup(deps);
|
|
838
|
+
if (deps.interactive) {
|
|
839
|
+
say(deps, scrollBanner(VERSION, deps.color));
|
|
840
|
+
say(deps);
|
|
841
|
+
}
|
|
848
842
|
await syncAgents(deps, config);
|
|
849
843
|
await status(deps, deps.interactive);
|
|
850
844
|
}
|
|
@@ -891,7 +885,7 @@ async function setup(deps) {
|
|
|
891
885
|
deps,
|
|
892
886
|
settings.privateKey ? "Using PATRON_PRIVATE_KEY" : "Signing in with Tempo Wallet"
|
|
893
887
|
);
|
|
894
|
-
const { signIn } = await import("./wallet-
|
|
888
|
+
const { signIn } = await import("./wallet-JDUPZN7E.js");
|
|
895
889
|
const account = await signIn(settings, { budgetUnits, issuer, output: deps.stdout });
|
|
896
890
|
done(deps, `Signed in as ${account.address}`);
|
|
897
891
|
const config = {
|
|
@@ -1005,7 +999,7 @@ async function changeBudget(deps, input) {
|
|
|
1005
999
|
} else budget = await askBudget(deps, config.monthlyBudgetUsd);
|
|
1006
1000
|
if (config.wallet === "tempo" && budget > config.monthlyBudgetUsd) {
|
|
1007
1001
|
step(deps, "Approve the new spending limit in Tempo Wallet");
|
|
1008
|
-
const { authorizeBudget } = await import("./wallet-
|
|
1002
|
+
const { authorizeBudget } = await import("./wallet-JDUPZN7E.js");
|
|
1009
1003
|
const issuer = await loadIssuer(settings.home, settings.gatewayUrl, {
|
|
1010
1004
|
fetch: deps.fetch
|
|
1011
1005
|
});
|
|
@@ -1117,7 +1111,7 @@ async function setName(deps, name) {
|
|
|
1117
1111
|
const issuer = await loadIssuer(settings.home, settings.gatewayUrl, {
|
|
1118
1112
|
fetch: deps.fetch
|
|
1119
1113
|
});
|
|
1120
|
-
const open = deps.openWallet ?? (async (s, c, i, max) => (await import("./wallet-
|
|
1114
|
+
const open = deps.openWallet ?? (async (s, c, i, max) => (await import("./wallet-JDUPZN7E.js")).openWallet(s, c.wallet, i, max));
|
|
1121
1115
|
const wallet = await open(settings, config, issuer, 0n);
|
|
1122
1116
|
await setProfile(settings.gatewayUrl, wallet, name, deps.fetch);
|
|
1123
1117
|
await writeConfig(settings.home, { ...config, name });
|
|
@@ -41,8 +41,17 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
41
41
|
));
|
|
42
42
|
|
|
43
43
|
// src/state.ts
|
|
44
|
-
import {
|
|
45
|
-
|
|
44
|
+
import {
|
|
45
|
+
chmod,
|
|
46
|
+
lstat,
|
|
47
|
+
mkdir,
|
|
48
|
+
readFile,
|
|
49
|
+
readlink,
|
|
50
|
+
rename,
|
|
51
|
+
rm as rm2,
|
|
52
|
+
writeFile
|
|
53
|
+
} from "node:fs/promises";
|
|
54
|
+
import { dirname, join, resolve } from "node:path";
|
|
46
55
|
|
|
47
56
|
// src/lock.ts
|
|
48
57
|
import { open, rm, stat } from "node:fs/promises";
|
|
@@ -65,7 +74,7 @@ async function withLock(path, fn, options = {}) {
|
|
|
65
74
|
continue;
|
|
66
75
|
}
|
|
67
76
|
if (Date.now() > deadline) throw new Error(`Patron state is busy: ${path}`);
|
|
68
|
-
await new Promise((
|
|
77
|
+
await new Promise((resolve2) => setTimeout(resolve2, 10 + Math.random() * 20));
|
|
69
78
|
}
|
|
70
79
|
}
|
|
71
80
|
try {
|
|
@@ -120,11 +129,38 @@ async function readJson(path) {
|
|
|
120
129
|
throw error;
|
|
121
130
|
}
|
|
122
131
|
}
|
|
123
|
-
async function writePrivateFile(
|
|
132
|
+
async function writePrivateFile(link, contents) {
|
|
133
|
+
const target = await symlinkTarget(link);
|
|
134
|
+
if (target !== link) {
|
|
135
|
+
try {
|
|
136
|
+
return await replaceFile(target, contents);
|
|
137
|
+
} catch (error) {
|
|
138
|
+
const code = error.code;
|
|
139
|
+
if (code !== "EACCES" && code !== "EROFS" && code !== "EPERM") throw error;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
await replaceFile(link, contents);
|
|
143
|
+
}
|
|
144
|
+
async function symlinkTarget(path, depth = 0) {
|
|
145
|
+
if (depth > 8) return path;
|
|
146
|
+
try {
|
|
147
|
+
const stats = await lstat(path);
|
|
148
|
+
if (!stats.isSymbolicLink()) return path;
|
|
149
|
+
return symlinkTarget(resolve(dirname(path), await readlink(path)), depth + 1);
|
|
150
|
+
} catch {
|
|
151
|
+
return path;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
async function replaceFile(path, contents) {
|
|
124
155
|
const temporary = `${path}.${process.pid}.${Date.now()}.tmp`;
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
156
|
+
try {
|
|
157
|
+
await writeFile(temporary, contents, { mode: 384 });
|
|
158
|
+
await chmod(temporary, 384);
|
|
159
|
+
await rename(temporary, path);
|
|
160
|
+
} catch (error) {
|
|
161
|
+
await rm2(temporary, { force: true }).catch(() => void 0);
|
|
162
|
+
throw error;
|
|
163
|
+
}
|
|
128
164
|
}
|
|
129
165
|
async function readConfig(home) {
|
|
130
166
|
const value = await readJson(statePaths(home).config).catch(() => void 0);
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
statePaths,
|
|
11
11
|
withLock,
|
|
12
12
|
writePrivateFile
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-FXE4CGY7.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
|
|
35861
|
-
|
|
35862
|
-
|
|
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-
|
|
15
|
+
} from "./chunk-REXWTXUY.js";
|
|
16
16
|
import {
|
|
17
17
|
readConfig,
|
|
18
18
|
readUsage,
|
|
19
19
|
updateUsage,
|
|
20
20
|
withLock,
|
|
21
21
|
writePrivateFile
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-FXE4CGY7.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-
|
|
5
|
+
} from "./chunk-FXE4CGY7.js";
|
|
6
6
|
|
|
7
7
|
// src/wallet.ts
|
|
8
8
|
import { Store } from "accounts";
|