@tempoxyz/patron 0.0.11 → 0.0.13
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-
|
|
7
|
+
const { runHookProcess } = await import("./chunks/hook-process-TN5MFLK5.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/-ALBR7TS6.js");
|
|
12
12
|
process.exitCode = await run(process.argv.slice(2));
|
|
13
13
|
}
|
|
@@ -34,11 +34,12 @@ import {
|
|
|
34
34
|
startRefill,
|
|
35
35
|
tipTokens,
|
|
36
36
|
tokensToUnits,
|
|
37
|
+
upgradeCodex,
|
|
37
38
|
withHooksKey,
|
|
38
39
|
withPatronGroup,
|
|
39
40
|
withoutPatronHandlers,
|
|
40
41
|
writeJsonObject
|
|
41
|
-
} from "./chunk-
|
|
42
|
+
} from "./chunk-5VAR4V2W.js";
|
|
42
43
|
import {
|
|
43
44
|
AGENT_IDS,
|
|
44
45
|
ensureHome,
|
|
@@ -114,6 +115,15 @@ async function installAmpPlugin(path, command) {
|
|
|
114
115
|
await writePrivateFile(path, source);
|
|
115
116
|
return "installed";
|
|
116
117
|
}
|
|
118
|
+
async function upgradeAmpPlugin(path) {
|
|
119
|
+
const current = await readText(path);
|
|
120
|
+
if (current === void 0 || !current.startsWith(AMP_PLUGIN_MARKER)) return false;
|
|
121
|
+
const literal = /^const COMMAND = (".*")$/m.exec(current)?.[1];
|
|
122
|
+
if (!literal) return false;
|
|
123
|
+
const command = JSON.parse(literal);
|
|
124
|
+
if (typeof command !== "string") return false;
|
|
125
|
+
return await installAmpPlugin(path, command) === "installed";
|
|
126
|
+
}
|
|
117
127
|
async function removeAmpPlugin(path) {
|
|
118
128
|
const current = await readText(path);
|
|
119
129
|
if (current === void 0 || !current.startsWith(AMP_PLUGIN_MARKER)) return "missing";
|
|
@@ -133,11 +143,41 @@ async function readText(path) {
|
|
|
133
143
|
var CLAUDE_MATCHER = "WebFetch|WebSearch";
|
|
134
144
|
var HOOK_TIMEOUT_SECONDS = 30;
|
|
135
145
|
var EVENT = "PostToolUse";
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
146
|
+
var CLAUDE_HOOK_STATUS = "Patron: pay the site this read";
|
|
147
|
+
function patronGroup(command) {
|
|
148
|
+
return {
|
|
149
|
+
hooks: [
|
|
150
|
+
{
|
|
151
|
+
async: true,
|
|
152
|
+
command,
|
|
153
|
+
statusMessage: CLAUDE_HOOK_STATUS,
|
|
154
|
+
timeout: HOOK_TIMEOUT_SECONDS,
|
|
155
|
+
type: "command"
|
|
156
|
+
}
|
|
157
|
+
],
|
|
139
158
|
matcher: CLAUDE_MATCHER
|
|
140
|
-
}
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function withPatronHook(settings, command) {
|
|
162
|
+
return withPatronGroup(settings, EVENT, patronGroup(command));
|
|
163
|
+
}
|
|
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
|
+
async function upgradeClaudeHook(path) {
|
|
172
|
+
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));
|
|
180
|
+
return true;
|
|
141
181
|
}
|
|
142
182
|
function withoutPatronHook(settings) {
|
|
143
183
|
return withoutPatronHandlers(settings, EVENT);
|
|
@@ -301,7 +341,8 @@ var ADAPTERS = {
|
|
|
301
341
|
install: async (command, { env, home }) => ({
|
|
302
342
|
state: await installAmpPlugin(ampPluginPath(env, home), command)
|
|
303
343
|
}),
|
|
304
|
-
remove: ({ env, home }) => removeAmpPlugin(ampPluginPath(env, home))
|
|
344
|
+
remove: ({ env, home }) => removeAmpPlugin(ampPluginPath(env, home)),
|
|
345
|
+
upgrade: ({ env, home }) => upgradeAmpPlugin(ampPluginPath(env, home))
|
|
305
346
|
},
|
|
306
347
|
"claude-code": {
|
|
307
348
|
files: (environment) => [claudeSettingsPath(environment)],
|
|
@@ -309,13 +350,15 @@ var ADAPTERS = {
|
|
|
309
350
|
install: async (command, environment) => ({
|
|
310
351
|
state: await installClaudeHook(claudeSettingsPath(environment), command)
|
|
311
352
|
}),
|
|
312
|
-
remove: (environment) => removeClaudeHook(claudeSettingsPath(environment))
|
|
353
|
+
remove: (environment) => removeClaudeHook(claudeSettingsPath(environment)),
|
|
354
|
+
upgrade: (environment) => upgradeClaudeHook(claudeSettingsPath(environment))
|
|
313
355
|
},
|
|
314
356
|
codex: {
|
|
315
357
|
files: ({ env, home }) => Object.values(codexPaths(env, home)),
|
|
316
358
|
detect: async ({ env, home }) => await exists(codexHome(env, home)) || await onPath(["codex"], env.PATH ?? ""),
|
|
317
359
|
install: (command, { env, home }) => installCodex(codexPaths(env, home), command),
|
|
318
|
-
remove: ({ env, home }) => removeCodex(codexPaths(env, home))
|
|
360
|
+
remove: ({ env, home }) => removeCodex(codexPaths(env, home)),
|
|
361
|
+
upgrade: ({ env, home }) => upgradeCodex(codexPaths(env, home))
|
|
319
362
|
},
|
|
320
363
|
cursor: {
|
|
321
364
|
files: ({ home }) => [cursorHooksPath(home)],
|
|
@@ -357,6 +400,14 @@ async function installAgents(agents, command, environment) {
|
|
|
357
400
|
})
|
|
358
401
|
);
|
|
359
402
|
}
|
|
403
|
+
async function upgradeAgents(agents, environment) {
|
|
404
|
+
const changed = await Promise.all(
|
|
405
|
+
agents.map(
|
|
406
|
+
async (agent) => await ADAPTERS[agent].upgrade?.(environment).catch(() => false) ? agent : void 0
|
|
407
|
+
)
|
|
408
|
+
);
|
|
409
|
+
return changed.filter((agent) => agent !== void 0);
|
|
410
|
+
}
|
|
360
411
|
async function removeAgents(environment) {
|
|
361
412
|
const store = originalsStore(environment);
|
|
362
413
|
return Promise.all(
|
|
@@ -798,6 +849,14 @@ async function main(deps) {
|
|
|
798
849
|
await status(deps, deps.interactive);
|
|
799
850
|
}
|
|
800
851
|
async function syncAgents(deps, config) {
|
|
852
|
+
const upgraded = await upgradeAgents(config.agents, deps.agents);
|
|
853
|
+
if (upgraded.length > 0) {
|
|
854
|
+
const names = upgraded.map((agent) => AGENT_LABELS[agent]).join(", ");
|
|
855
|
+
say(deps, `Updated Patron for ${names}.`);
|
|
856
|
+
if (upgraded.includes("codex"))
|
|
857
|
+
say(deps, " Codex: trust the hook again in /hooks when it asks.");
|
|
858
|
+
say(deps);
|
|
859
|
+
}
|
|
801
860
|
const added = (await detectAgents(deps.agents)).filter(
|
|
802
861
|
(agent) => !config.agents.includes(agent)
|
|
803
862
|
);
|
|
@@ -35855,6 +35855,17 @@ async function installCodex(paths, command, platform = process.platform) {
|
|
|
35855
35855
|
const state = hookChanged || notify === "installed" ? "installed" : "unchanged";
|
|
35856
35856
|
return notify === "taken" ? { note: "open /hooks in Codex and trust it to start paying", state } : { note: "trust it in /hooks when Codex asks", state };
|
|
35857
35857
|
}
|
|
35858
|
+
async function upgradeCodex(paths) {
|
|
35859
|
+
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));
|
|
35867
|
+
return true;
|
|
35868
|
+
}
|
|
35858
35869
|
async function removeCodex(paths) {
|
|
35859
35870
|
let removed = false;
|
|
35860
35871
|
const settings = await readJsonObject(paths.hooks);
|
|
@@ -35917,6 +35928,7 @@ export {
|
|
|
35917
35928
|
codexHome,
|
|
35918
35929
|
codexPaths,
|
|
35919
35930
|
installCodex,
|
|
35931
|
+
upgradeCodex,
|
|
35920
35932
|
removeCodex,
|
|
35921
35933
|
loadIssuer,
|
|
35922
35934
|
resolveSettings,
|