@pushary/agent-hooks 0.60.0 → 0.62.0
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/CHANGELOG.md +161 -0
- package/README.md +52 -9
- package/dist/bin/pushary-claude.js +6 -6
- package/dist/bin/pushary-clean.js +83 -38
- package/dist/bin/pushary-codex-hook.js +6 -6
- package/dist/bin/pushary-codex.js +4 -4
- package/dist/bin/pushary-connect.d.ts +1 -0
- package/dist/bin/pushary-connect.js +92 -0
- package/dist/bin/pushary-daemon.js +42 -5
- package/dist/bin/pushary-doctor.js +246 -71
- package/dist/bin/pushary-gemini-hook.js +6 -6
- package/dist/bin/pushary-hook.js +10 -5
- package/dist/bin/pushary-login.d.ts +1 -0
- package/dist/bin/pushary-login.js +156 -0
- package/dist/bin/pushary-logout.d.ts +1 -0
- package/dist/bin/pushary-logout.js +144 -0
- package/dist/bin/pushary-mode.js +24 -13
- package/dist/bin/pushary-notification-hook.js +4 -4
- package/dist/bin/pushary-permission-denied-hook.js +5 -5
- package/dist/bin/pushary-permission-hook.js +5 -5
- package/dist/bin/pushary-post-hook.js +4 -4
- package/dist/bin/pushary-prompt-hook.js +4 -4
- package/dist/bin/pushary-session-end-hook.js +4 -4
- package/dist/bin/pushary-session-start-hook.js +4 -4
- package/dist/bin/pushary-setup.js +769 -518
- package/dist/bin/pushary-stats.js +6 -1
- package/dist/bin/pushary-status.d.ts +1 -0
- package/dist/bin/pushary-status.js +206 -0
- package/dist/bin/pushary-stop-hook.js +4 -4
- package/dist/bin/pushary-stopfailure-hook.js +4 -4
- package/dist/bin/pushary-suggestions.js +10 -5
- package/dist/bin/pushary-upgrade.js +184 -14
- package/dist/bin/pushary-wait.js +21 -12
- package/dist/bin/pushary.js +42 -60
- package/dist/chunk-247C4RE5.js +236 -0
- package/dist/{chunk-NKXSILEW.js → chunk-2UMNXADU.js} +18 -2
- package/dist/chunk-3EGEA4KH.js +44 -0
- package/dist/chunk-3O27ZSRE.js +569 -0
- package/dist/{chunk-BE5X3WXL.js → chunk-5SO3CEGJ.js} +5 -5
- package/dist/chunk-7QLSKOSU.js +19 -0
- package/dist/chunk-E2U35RLD.js +108 -0
- package/dist/chunk-ER657KRJ.js +168 -0
- package/dist/{chunk-WNRYRN2R.js → chunk-HIIBSYFJ.js} +5 -5
- package/dist/{chunk-DWED7BS3.js → chunk-HNTKTK5B.js} +1 -1
- package/dist/chunk-IIZZYUWK.js +18 -0
- package/dist/{chunk-J7JWI3KU.js → chunk-MUEW424A.js} +19 -1
- package/dist/chunk-N4DA4CJB.js +57 -0
- package/dist/chunk-N7XJ4L2W.js +79 -0
- package/dist/chunk-ONVEYEVR.js +44 -0
- package/dist/chunk-QHOVJXOT.js +255 -0
- package/dist/chunk-SP7OZXCQ.js +224 -0
- package/dist/chunk-TX7KBKT7.js +79 -0
- package/dist/chunk-UXXRRXUS.js +93 -0
- package/dist/chunk-YJ7YZRVV.js +217 -0
- package/dist/src/index.js +5 -5
- package/package.json +11 -4
- package/dist/chunk-BQLCELYC.js +0 -332
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import {
|
|
2
|
+
HOOK_BUDGETS
|
|
3
|
+
} from "./chunk-DQAN3JQP.js";
|
|
4
|
+
|
|
5
|
+
// src/gemini-config.ts
|
|
6
|
+
var GEMINI_HOOK_BINARY = "pushary-gemini-hook";
|
|
7
|
+
var GEMINI_MCP_URL = "https://pushary.com/api/mcp/mcp";
|
|
8
|
+
var GEMINI_HOOK_EVENTS = [
|
|
9
|
+
{ event: "BeforeTool", matcher: "run_shell_command|write_file|replace", timeoutMs: HOOK_BUDGETS.gemini.budgetSeconds * 1e3 },
|
|
10
|
+
{ event: "AfterTool", matcher: "run_shell_command|write_file|replace", timeoutMs: 1e4 },
|
|
11
|
+
{ event: "BeforeAgent", timeoutMs: 1e4 },
|
|
12
|
+
{ event: "SessionStart", timeoutMs: 1e4 },
|
|
13
|
+
{ event: "SessionEnd", timeoutMs: 1e4 }
|
|
14
|
+
];
|
|
15
|
+
var asRecord = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
16
|
+
var ensureRecord = (target, key) => {
|
|
17
|
+
const existing = asRecord(target[key]);
|
|
18
|
+
if (existing) return existing;
|
|
19
|
+
const created = {};
|
|
20
|
+
target[key] = created;
|
|
21
|
+
return created;
|
|
22
|
+
};
|
|
23
|
+
var isPusharyGeminiHook = (entry) => {
|
|
24
|
+
const hooks = asRecord(entry)?.hooks;
|
|
25
|
+
if (!Array.isArray(hooks)) return false;
|
|
26
|
+
return hooks.some((hook) => String(asRecord(hook)?.command ?? "").includes(GEMINI_HOOK_BINARY));
|
|
27
|
+
};
|
|
28
|
+
var addGeminiMcpServer = (settings, apiKey) => {
|
|
29
|
+
const mcpServers = ensureRecord(settings, "mcpServers");
|
|
30
|
+
mcpServers.pushary = {
|
|
31
|
+
httpUrl: GEMINI_MCP_URL,
|
|
32
|
+
headers: { Authorization: `Bearer ${apiKey}` },
|
|
33
|
+
trust: true
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
var addGeminiHooks = (settings, command) => {
|
|
37
|
+
const hooks = ensureRecord(settings, "hooks");
|
|
38
|
+
for (const definition of GEMINI_HOOK_EVENTS) {
|
|
39
|
+
const existing = Array.isArray(hooks[definition.event]) ? hooks[definition.event] : [];
|
|
40
|
+
const entries = existing.filter((entry) => !isPusharyGeminiHook(entry));
|
|
41
|
+
entries.push({
|
|
42
|
+
...definition.matcher ? { matcher: definition.matcher } : {},
|
|
43
|
+
hooks: [{
|
|
44
|
+
name: "pushary",
|
|
45
|
+
type: "command",
|
|
46
|
+
command,
|
|
47
|
+
timeout: definition.timeoutMs
|
|
48
|
+
}]
|
|
49
|
+
});
|
|
50
|
+
hooks[definition.event] = entries;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var removeGeminiHooks = (settings) => {
|
|
54
|
+
const hooks = asRecord(settings.hooks);
|
|
55
|
+
if (!hooks) return false;
|
|
56
|
+
let changed = false;
|
|
57
|
+
for (const definition of GEMINI_HOOK_EVENTS) {
|
|
58
|
+
const entries = hooks[definition.event];
|
|
59
|
+
if (!Array.isArray(entries)) continue;
|
|
60
|
+
const filtered = entries.filter((entry) => !isPusharyGeminiHook(entry));
|
|
61
|
+
if (filtered.length !== entries.length) {
|
|
62
|
+
if (filtered.length === 0) {
|
|
63
|
+
delete hooks[definition.event];
|
|
64
|
+
} else {
|
|
65
|
+
hooks[definition.event] = filtered;
|
|
66
|
+
}
|
|
67
|
+
changed = true;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (Object.keys(hooks).length === 0) delete settings.hooks;
|
|
71
|
+
return changed;
|
|
72
|
+
};
|
|
73
|
+
var removeGeminiMcpServer = (settings) => {
|
|
74
|
+
const mcpServers = asRecord(settings.mcpServers);
|
|
75
|
+
if (!mcpServers?.pushary) return false;
|
|
76
|
+
delete mcpServers.pushary;
|
|
77
|
+
if (Object.keys(mcpServers).length === 0) delete settings.mcpServers;
|
|
78
|
+
return true;
|
|
79
|
+
};
|
|
80
|
+
var removeGeminiSettings = (settings) => {
|
|
81
|
+
const mcpRemoved = removeGeminiMcpServer(settings);
|
|
82
|
+
const hooksRemoved = removeGeminiHooks(settings);
|
|
83
|
+
return mcpRemoved || hooksRemoved;
|
|
84
|
+
};
|
|
85
|
+
var hasGeminiHooks = (settings) => {
|
|
86
|
+
const hooks = asRecord(settings.hooks);
|
|
87
|
+
if (!hooks) return false;
|
|
88
|
+
return GEMINI_HOOK_EVENTS.some((definition) => {
|
|
89
|
+
const entries = hooks[definition.event];
|
|
90
|
+
return Array.isArray(entries) && entries.some(isPusharyGeminiHook);
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
var missingGeminiHookEvents = (settings) => {
|
|
94
|
+
const hooks = asRecord(settings.hooks);
|
|
95
|
+
return GEMINI_HOOK_EVENTS.filter((definition) => {
|
|
96
|
+
const entries = hooks?.[definition.event];
|
|
97
|
+
return !Array.isArray(entries) || !entries.some(isPusharyGeminiHook);
|
|
98
|
+
}).map((definition) => definition.event);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export {
|
|
102
|
+
GEMINI_HOOK_BINARY,
|
|
103
|
+
addGeminiMcpServer,
|
|
104
|
+
addGeminiHooks,
|
|
105
|
+
removeGeminiSettings,
|
|
106
|
+
hasGeminiHooks,
|
|
107
|
+
missingGeminiHookEvents
|
|
108
|
+
};
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import {
|
|
2
|
+
HOOK_BUDGETS
|
|
3
|
+
} from "./chunk-DQAN3JQP.js";
|
|
4
|
+
|
|
5
|
+
// src/codex-config.ts
|
|
6
|
+
import { createHash } from "crypto";
|
|
7
|
+
import { homedir } from "os";
|
|
8
|
+
import { join } from "path";
|
|
9
|
+
var CODEX_HOOK_BINARY = "pushary-codex-hook";
|
|
10
|
+
var codexHome = () => codexHomeFrom(homedir());
|
|
11
|
+
var codexHomeFrom = (home) => process.env.CODEX_HOME?.trim() || join(home, ".codex");
|
|
12
|
+
var codexConfigToml = () => join(codexHome(), "config.toml");
|
|
13
|
+
var codexHooksJson = () => join(codexHome(), "hooks.json");
|
|
14
|
+
var codexAgentsMd = () => join(codexHome(), "AGENTS.md");
|
|
15
|
+
var codexSkillDir = () => join(codexHome(), "skills", "pushary");
|
|
16
|
+
var CODEX_HOOK_EVENTS = [
|
|
17
|
+
{ event: "PermissionRequest", matcher: "Bash|apply_patch", timeout: HOOK_BUDGETS.codex.budgetSeconds, statusMessage: "Waiting for your phone" },
|
|
18
|
+
{ event: "PreToolUse", matcher: "Bash|apply_patch", timeout: HOOK_BUDGETS.codex.budgetSeconds, statusMessage: "Checking Pushary policy" },
|
|
19
|
+
{ event: "PostToolUse", matcher: "Bash|apply_patch", timeout: 10 },
|
|
20
|
+
{ event: "UserPromptSubmit", timeout: 10 },
|
|
21
|
+
{ event: "Stop", timeout: 10 },
|
|
22
|
+
{ event: "SessionStart", matcher: "startup|resume", timeout: 10 }
|
|
23
|
+
];
|
|
24
|
+
var CODEX_EVENT_KEY = {
|
|
25
|
+
PermissionRequest: "permission_request",
|
|
26
|
+
PreToolUse: "pre_tool_use",
|
|
27
|
+
PostToolUse: "post_tool_use",
|
|
28
|
+
UserPromptSubmit: "user_prompt_submit",
|
|
29
|
+
Stop: "stop",
|
|
30
|
+
SessionStart: "session_start"
|
|
31
|
+
};
|
|
32
|
+
var asRecord = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
33
|
+
var ensureRecord = (target, key) => {
|
|
34
|
+
const existing = asRecord(target[key]);
|
|
35
|
+
if (existing) return existing;
|
|
36
|
+
const created = {};
|
|
37
|
+
target[key] = created;
|
|
38
|
+
return created;
|
|
39
|
+
};
|
|
40
|
+
var CODEX_MCP_URL = "https://pushary.com/api/mcp/mcp";
|
|
41
|
+
var addCodexMcpServer = (config, apiKey) => {
|
|
42
|
+
const servers = ensureRecord(config, "mcp_servers");
|
|
43
|
+
const pushary = ensureRecord(servers, "pushary");
|
|
44
|
+
pushary.url = CODEX_MCP_URL;
|
|
45
|
+
ensureRecord(pushary, "http_headers").Authorization = `Bearer ${apiKey}`;
|
|
46
|
+
pushary.default_tools_approval_mode = "approve";
|
|
47
|
+
delete pushary.bearer_token_env_var;
|
|
48
|
+
delete pushary.tools;
|
|
49
|
+
};
|
|
50
|
+
var readCodexMcpAuth = (config) => {
|
|
51
|
+
const pushary = asRecord(asRecord(config.mcp_servers)?.pushary);
|
|
52
|
+
if (!pushary) return void 0;
|
|
53
|
+
const authorization = asRecord(pushary.http_headers)?.Authorization;
|
|
54
|
+
if (typeof authorization === "string" && authorization.startsWith("Bearer ")) {
|
|
55
|
+
return { method: "embedded", key: authorization.slice("Bearer ".length).trim() };
|
|
56
|
+
}
|
|
57
|
+
if (typeof pushary.bearer_token_env_var === "string") {
|
|
58
|
+
return { method: "env", envVar: pushary.bearer_token_env_var };
|
|
59
|
+
}
|
|
60
|
+
if (typeof pushary.bearer_token === "string") return { method: "legacy-bearer" };
|
|
61
|
+
return void 0;
|
|
62
|
+
};
|
|
63
|
+
var isPusharyCodexHook = (entry) => {
|
|
64
|
+
const hooks = asRecord(entry)?.hooks;
|
|
65
|
+
if (!Array.isArray(hooks)) return false;
|
|
66
|
+
return hooks.some((hook) => String(asRecord(hook)?.command ?? "").includes(CODEX_HOOK_BINARY));
|
|
67
|
+
};
|
|
68
|
+
var addCodexHooks = (config, command) => {
|
|
69
|
+
const hooks = ensureRecord(config, "hooks");
|
|
70
|
+
for (const definition of CODEX_HOOK_EVENTS) {
|
|
71
|
+
const existing = Array.isArray(hooks[definition.event]) ? hooks[definition.event] : [];
|
|
72
|
+
const entries = existing.filter((entry) => !isPusharyCodexHook(entry));
|
|
73
|
+
entries.push({
|
|
74
|
+
...definition.matcher ? { matcher: definition.matcher } : {},
|
|
75
|
+
hooks: [{
|
|
76
|
+
type: "command",
|
|
77
|
+
command,
|
|
78
|
+
timeout: definition.timeout,
|
|
79
|
+
...definition.statusMessage ? { statusMessage: definition.statusMessage } : {}
|
|
80
|
+
}]
|
|
81
|
+
});
|
|
82
|
+
hooks[definition.event] = entries;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
var removeCodexHooks = (config) => {
|
|
86
|
+
const hooks = asRecord(config.hooks);
|
|
87
|
+
if (!hooks) return false;
|
|
88
|
+
let changed = false;
|
|
89
|
+
for (const definition of CODEX_HOOK_EVENTS) {
|
|
90
|
+
const entries = hooks[definition.event];
|
|
91
|
+
if (!Array.isArray(entries)) continue;
|
|
92
|
+
const filtered = entries.filter((entry) => !isPusharyCodexHook(entry));
|
|
93
|
+
if (filtered.length !== entries.length) {
|
|
94
|
+
if (filtered.length === 0) {
|
|
95
|
+
delete hooks[definition.event];
|
|
96
|
+
} else {
|
|
97
|
+
hooks[definition.event] = filtered;
|
|
98
|
+
}
|
|
99
|
+
changed = true;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (Object.keys(hooks).length === 0) delete config.hooks;
|
|
103
|
+
return changed;
|
|
104
|
+
};
|
|
105
|
+
var hasCodexHooks = (config) => {
|
|
106
|
+
const hooks = asRecord(config.hooks);
|
|
107
|
+
if (!hooks) return false;
|
|
108
|
+
return CODEX_HOOK_EVENTS.some((definition) => {
|
|
109
|
+
const entries = hooks[definition.event];
|
|
110
|
+
return Array.isArray(entries) && entries.some(isPusharyCodexHook);
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
var missingCodexHookEvents = (config) => {
|
|
114
|
+
const hooks = asRecord(config.hooks);
|
|
115
|
+
return CODEX_HOOK_EVENTS.filter((definition) => {
|
|
116
|
+
const entries = hooks?.[definition.event];
|
|
117
|
+
return !Array.isArray(entries) || !entries.some(isPusharyCodexHook);
|
|
118
|
+
}).map((definition) => definition.event);
|
|
119
|
+
};
|
|
120
|
+
var canonicalJson = (value) => {
|
|
121
|
+
if (value === null || typeof value !== "object") return JSON.stringify(value);
|
|
122
|
+
if (Array.isArray(value)) return "[" + value.map(canonicalJson).join(",") + "]";
|
|
123
|
+
const obj = value;
|
|
124
|
+
return "{" + Object.keys(obj).sort().map((key) => JSON.stringify(key) + ":" + canonicalJson(obj[key])).join(",") + "}";
|
|
125
|
+
};
|
|
126
|
+
var codexHookTrustHash = (definition, command) => {
|
|
127
|
+
const hook = { async: false, command, timeout: definition.timeout, type: "command" };
|
|
128
|
+
if (definition.statusMessage) hook.statusMessage = definition.statusMessage;
|
|
129
|
+
const identity = { event_name: CODEX_EVENT_KEY[definition.event], hooks: [hook] };
|
|
130
|
+
if (definition.matcher) identity.matcher = definition.matcher;
|
|
131
|
+
return "sha256:" + createHash("sha256").update(canonicalJson(identity), "utf8").digest("hex");
|
|
132
|
+
};
|
|
133
|
+
var codexHookStateKey = (hooksJsonPath, event) => `${hooksJsonPath}:${CODEX_EVENT_KEY[event]}:0:0`;
|
|
134
|
+
var untrustedCodexHookEvents = (config, hooksJsonPath, command) => {
|
|
135
|
+
const state = asRecord(asRecord(config.hooks)?.state);
|
|
136
|
+
return CODEX_HOOK_EVENTS.filter((definition) => {
|
|
137
|
+
const entry = asRecord(state?.[codexHookStateKey(hooksJsonPath, definition.event)]);
|
|
138
|
+
const stored = entry?.trusted_hash;
|
|
139
|
+
return stored !== codexHookTrustHash(definition, command);
|
|
140
|
+
}).map((definition) => definition.event);
|
|
141
|
+
};
|
|
142
|
+
var addCodexHookTrust = (config, hooksJsonPath, command) => {
|
|
143
|
+
const hooks = ensureRecord(config, "hooks");
|
|
144
|
+
const state = ensureRecord(hooks, "state");
|
|
145
|
+
for (const definition of CODEX_HOOK_EVENTS) {
|
|
146
|
+
const key = codexHookStateKey(hooksJsonPath, definition.event);
|
|
147
|
+
const existing = asRecord(state[key]) ?? {};
|
|
148
|
+
state[key] = { ...existing, trusted_hash: codexHookTrustHash(definition, command) };
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export {
|
|
153
|
+
CODEX_HOOK_BINARY,
|
|
154
|
+
codexHome,
|
|
155
|
+
codexHomeFrom,
|
|
156
|
+
codexConfigToml,
|
|
157
|
+
codexHooksJson,
|
|
158
|
+
codexAgentsMd,
|
|
159
|
+
codexSkillDir,
|
|
160
|
+
addCodexMcpServer,
|
|
161
|
+
readCodexMcpAuth,
|
|
162
|
+
addCodexHooks,
|
|
163
|
+
removeCodexHooks,
|
|
164
|
+
hasCodexHooks,
|
|
165
|
+
missingCodexHookEvents,
|
|
166
|
+
untrustedCodexHookEvents,
|
|
167
|
+
addCodexHookTrust
|
|
168
|
+
};
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getMachineId
|
|
3
|
-
} from "./chunk-RN3NOEJF.js";
|
|
4
1
|
import {
|
|
5
2
|
callMcpTool,
|
|
6
3
|
withRetry
|
|
7
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-HNTKTK5B.js";
|
|
8
5
|
import {
|
|
9
6
|
ACTION_BODY_MAX,
|
|
10
7
|
DECISION_LINE_MAX,
|
|
@@ -21,10 +18,13 @@ import {
|
|
|
21
18
|
redactSecrets,
|
|
22
19
|
redactSecretsDeep
|
|
23
20
|
} from "./chunk-DQAN3JQP.js";
|
|
21
|
+
import {
|
|
22
|
+
getMachineId
|
|
23
|
+
} from "./chunk-RN3NOEJF.js";
|
|
24
24
|
import {
|
|
25
25
|
getApiKey,
|
|
26
26
|
getBaseUrl
|
|
27
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-2UMNXADU.js";
|
|
28
28
|
|
|
29
29
|
// src/policy.ts
|
|
30
30
|
import { createHash } from "crypto";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EXIT,
|
|
3
|
+
getPackageVersion,
|
|
4
|
+
renderCommandHelp
|
|
5
|
+
} from "./chunk-SP7OZXCQ.js";
|
|
6
|
+
|
|
7
|
+
// src/cli/usage.ts
|
|
8
|
+
var exitOnHelpFlag = (command) => {
|
|
9
|
+
const args = process.argv.slice(2);
|
|
10
|
+
if (!args.includes("--help") && !args.includes("-h")) return;
|
|
11
|
+
process.stdout.write(`${renderCommandHelp(command, getPackageVersion())}
|
|
12
|
+
`);
|
|
13
|
+
process.exit(EXIT.OK);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
exitOnHelpFlag
|
|
18
|
+
};
|
|
@@ -39,11 +39,29 @@ var resolveGlobalBinDir = (probe) => {
|
|
|
39
39
|
return resolved ? resolved.slice(0, resolved.length - probe.length - 1) : void 0;
|
|
40
40
|
};
|
|
41
41
|
var quoteIfNeeded = (path) => /\s/.test(path) ? `"${path}"` : path;
|
|
42
|
+
var installState;
|
|
43
|
+
var installGlobally = (options) => {
|
|
44
|
+
if (installState) {
|
|
45
|
+
return installState.then((result) => result === "installed" ? "cached" : result);
|
|
46
|
+
}
|
|
47
|
+
const started = (async () => {
|
|
48
|
+
const pinned = process.env.PUSHARY_PIN_GLOBAL_VERSION !== "0";
|
|
49
|
+
const spec = pinned && options.version && options.version !== "0.0.0" ? `@pushary/agent-hooks@${options.version}` : "@pushary/agent-hooks@latest";
|
|
50
|
+
execNpm(`install -g --no-workspaces ${spec}`, { timeout: options.timeoutMs ?? 12e4 });
|
|
51
|
+
return "installed";
|
|
52
|
+
})();
|
|
53
|
+
installState = started;
|
|
54
|
+
started.catch(() => {
|
|
55
|
+
if (installState === started) installState = void 0;
|
|
56
|
+
});
|
|
57
|
+
return started;
|
|
58
|
+
};
|
|
42
59
|
|
|
43
60
|
export {
|
|
44
61
|
npmErrorMessage,
|
|
45
62
|
execNpm,
|
|
46
63
|
resolveGlobalBinary,
|
|
47
64
|
resolveGlobalBinDir,
|
|
48
|
-
quoteIfNeeded
|
|
65
|
+
quoteIfNeeded,
|
|
66
|
+
installGlobally
|
|
49
67
|
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {
|
|
2
|
+
UsageError
|
|
3
|
+
} from "./chunk-7QLSKOSU.js";
|
|
4
|
+
|
|
5
|
+
// src/cli/flags.ts
|
|
6
|
+
var normalize = (raw) => raw.replace(/^--?/, "");
|
|
7
|
+
var known = (spec, name) => {
|
|
8
|
+
if (spec.bools.includes(name)) return "bool";
|
|
9
|
+
if (spec.values.includes(name)) return "value";
|
|
10
|
+
return void 0;
|
|
11
|
+
};
|
|
12
|
+
var parseFlags = (argv, spec) => {
|
|
13
|
+
const bools = /* @__PURE__ */ new Set();
|
|
14
|
+
const values = /* @__PURE__ */ new Map();
|
|
15
|
+
const rest = [];
|
|
16
|
+
let command;
|
|
17
|
+
for (let i = 0; i < argv.length; i++) {
|
|
18
|
+
const token = argv[i];
|
|
19
|
+
if (token === "--") {
|
|
20
|
+
rest.push(...argv.slice(i + 1));
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
if (!token.startsWith("-")) {
|
|
24
|
+
if (command === void 0) command = token;
|
|
25
|
+
else rest.push(token);
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
const inline = token.indexOf("=");
|
|
29
|
+
const name = normalize(inline === -1 ? token : token.slice(0, inline));
|
|
30
|
+
const kind = known(spec, name);
|
|
31
|
+
if (kind === void 0) {
|
|
32
|
+
throw new UsageError(`Unknown flag: ${token}`);
|
|
33
|
+
}
|
|
34
|
+
if (kind === "bool") {
|
|
35
|
+
if (inline !== -1) throw new UsageError(`${token.slice(0, inline)} does not take a value`);
|
|
36
|
+
bools.add(name);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (inline !== -1) {
|
|
40
|
+
const value = token.slice(inline + 1);
|
|
41
|
+
if (value === "") throw new UsageError(`--${name} needs a value`);
|
|
42
|
+
values.set(name, value);
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
const next = argv[i + 1];
|
|
46
|
+
if (next === void 0 || next.startsWith("-")) {
|
|
47
|
+
throw new UsageError(`--${name} needs a value`);
|
|
48
|
+
}
|
|
49
|
+
values.set(name, next);
|
|
50
|
+
i++;
|
|
51
|
+
}
|
|
52
|
+
return { command, bools, values, rest };
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export {
|
|
56
|
+
parseFlags
|
|
57
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// src/instruction-file.ts
|
|
2
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync, rmSync } from "fs";
|
|
3
|
+
import { dirname } from "path";
|
|
4
|
+
var PUSHARY_BEGIN = "<!-- BEGIN PUSHARY (managed by @pushary/agent-hooks; do not edit this block) -->";
|
|
5
|
+
var PUSHARY_END = "<!-- END PUSHARY -->";
|
|
6
|
+
var instructionBody = (label) => `## Pushary notifications and approvals
|
|
7
|
+
|
|
8
|
+
You have Pushary MCP tools that reach the user on their phone. Use them proactively. Do not wait for the user to ask.
|
|
9
|
+
|
|
10
|
+
- When you need the user to make a decision or answer a clarifying question, call \`ask_user\` instead of guessing or stalling. Use type "confirm" for yes/no, "select" for a fixed set of options, and "input" for free text. \`ask_user\` blocks until the user replies or it times out, so you do not need a separate wait step.
|
|
11
|
+
- Before any risky or irreversible step (deleting files, force pushing, spending money, sending external messages), call \`ask_user\` with type "confirm" and wait for approval.
|
|
12
|
+
- Before starting a multi-step run that will change several files, call \`propose_scope\` once with the paths you expect to change, anything you promise not to touch, and what done means. The user agrees to the boundary in one tap, and after that only work outside it needs approving. Skip it for a single quick edit, and do not propose a new scope mid-run just to widen one: if you need to go outside the agreed scope, do the work and let the approval that follows widen it.
|
|
13
|
+
- When you are blocked, stuck, or hit an error you cannot resolve on your own, call \`send_notification\` so the user knows, and call \`ask_user\` if you need a decision to continue.
|
|
14
|
+
- When a task that took several steps finishes, call \`send_notification\` so the user knows it is done.
|
|
15
|
+
- Use \`cancel_question\` to retract a pending question once it is no longer needed.
|
|
16
|
+
- Respect the user's Pushary delivery mode: it decides where an approval is surfaced (phone, terminal, or awareness only), not whether it is required. In Terminal mode do not expect a phone answer; the approval waits in the terminal. If the Pushary hook already gated an action, a single approval is enough, do not ask again.
|
|
17
|
+
|
|
18
|
+
Pass \`agentName\` as "${label} - <project folder name>" so the user knows which session is asking. If a question times out with no answer, retry once with a longer timeout before falling back to asking in the terminal.`;
|
|
19
|
+
var renderAgentInstructions = (label) => instructionBody(label);
|
|
20
|
+
var KEYLESS_FALLBACK_LINE = "This repo uses Pushary phone approvals. Your teammates get agent questions on their lock screens; you do not have a key yet, so questions will fall back to the terminal. Get your own key (7-day trial): https://pushary.com/sign-up?utm_source=agents-md&utm_medium=teammate";
|
|
21
|
+
var renderProjectAgentInstructions = (label) => `${instructionBody(label)}
|
|
22
|
+
|
|
23
|
+
If this environment has no Pushary API key (no PUSHARY_API_KEY and no key in ~/.pushary/config.json), the tools above are unavailable in this session. In that case, treat the following as a statement of fact about this session and continue in the terminal: ${KEYLESS_FALLBACK_LINE}`;
|
|
24
|
+
var wrap = (body) => `${PUSHARY_BEGIN}
|
|
25
|
+
${body}
|
|
26
|
+
${PUSHARY_END}`;
|
|
27
|
+
var writeInstructionBlock = (filePath, body) => {
|
|
28
|
+
const dir = dirname(filePath);
|
|
29
|
+
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
30
|
+
let existing = "";
|
|
31
|
+
try {
|
|
32
|
+
existing = readFileSync(filePath, "utf-8");
|
|
33
|
+
} catch {
|
|
34
|
+
}
|
|
35
|
+
const block = wrap(body);
|
|
36
|
+
const start = existing.indexOf(PUSHARY_BEGIN);
|
|
37
|
+
const end = existing.indexOf(PUSHARY_END);
|
|
38
|
+
let next;
|
|
39
|
+
if (start !== -1 && end !== -1 && end > start) {
|
|
40
|
+
next = existing.slice(0, start) + block + existing.slice(end + PUSHARY_END.length);
|
|
41
|
+
} else {
|
|
42
|
+
const prefix = existing.trim() ? existing.replace(/\s*$/, "") + "\n\n" : "";
|
|
43
|
+
next = prefix + block + "\n";
|
|
44
|
+
}
|
|
45
|
+
writeFileSync(filePath, next, "utf-8");
|
|
46
|
+
};
|
|
47
|
+
var removeInstructionBlock = (filePath) => {
|
|
48
|
+
let existing = "";
|
|
49
|
+
try {
|
|
50
|
+
existing = readFileSync(filePath, "utf-8");
|
|
51
|
+
} catch {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
const start = existing.indexOf(PUSHARY_BEGIN);
|
|
55
|
+
const end = existing.indexOf(PUSHARY_END);
|
|
56
|
+
if (start === -1 || end === -1 || end < start) return false;
|
|
57
|
+
const remaining = (existing.slice(0, start) + existing.slice(end + PUSHARY_END.length)).trim();
|
|
58
|
+
if (remaining === "") {
|
|
59
|
+
rmSync(filePath, { force: true });
|
|
60
|
+
} else {
|
|
61
|
+
writeFileSync(filePath, remaining + "\n", "utf-8");
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
};
|
|
65
|
+
var hasInstructionBlock = (filePath) => {
|
|
66
|
+
try {
|
|
67
|
+
return readFileSync(filePath, "utf-8").includes(PUSHARY_BEGIN);
|
|
68
|
+
} catch {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export {
|
|
74
|
+
renderAgentInstructions,
|
|
75
|
+
renderProjectAgentInstructions,
|
|
76
|
+
writeInstructionBlock,
|
|
77
|
+
removeInstructionBlock,
|
|
78
|
+
hasInstructionBlock
|
|
79
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {
|
|
2
|
+
describeKeyCheck,
|
|
3
|
+
keyCheckFromResponse
|
|
4
|
+
} from "./chunk-YJ7YZRVV.js";
|
|
5
|
+
import {
|
|
6
|
+
createIo
|
|
7
|
+
} from "./chunk-TX7KBKT7.js";
|
|
8
|
+
import {
|
|
9
|
+
EXIT
|
|
10
|
+
} from "./chunk-SP7OZXCQ.js";
|
|
11
|
+
|
|
12
|
+
// src/cli/report-key.ts
|
|
13
|
+
var { dim, yellow } = createIo();
|
|
14
|
+
var printKeyCheck = (check, baseUrl) => {
|
|
15
|
+
const report = describeKeyCheck(check, baseUrl);
|
|
16
|
+
console.log(` ${yellow("!")} ${report.message}`);
|
|
17
|
+
for (const line of report.next) console.log(` ${dim(line)}`);
|
|
18
|
+
return report;
|
|
19
|
+
};
|
|
20
|
+
var exitIfKeyFailure = async (response, baseUrl) => {
|
|
21
|
+
const check = await keyCheckFromResponse(response, baseUrl);
|
|
22
|
+
if (!check) return;
|
|
23
|
+
const report = printKeyCheck(check, baseUrl);
|
|
24
|
+
process.exit(report.exitCode);
|
|
25
|
+
};
|
|
26
|
+
var responseDetail = async (response) => {
|
|
27
|
+
try {
|
|
28
|
+
const body = await response.json();
|
|
29
|
+
const text = [body.error, body.message].find((part) => typeof part === "string" && part);
|
|
30
|
+
if (typeof text === "string") return text;
|
|
31
|
+
} catch {
|
|
32
|
+
}
|
|
33
|
+
return response.statusText || `HTTP ${response.status}`;
|
|
34
|
+
};
|
|
35
|
+
var exitOnFailedResponse = async (response, baseUrl) => {
|
|
36
|
+
await exitIfKeyFailure(response, baseUrl);
|
|
37
|
+
console.log(` ${yellow("!")} Failed: ${await responseDetail(response)}`);
|
|
38
|
+
process.exit(EXIT.FAILED);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export {
|
|
42
|
+
printKeyCheck,
|
|
43
|
+
exitOnFailedResponse
|
|
44
|
+
};
|