@pushary/agent-hooks 0.19.0 → 0.20.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/dist/bin/pushary-clean.js +22 -2
- package/dist/bin/pushary-doctor.js +8 -1
- package/dist/bin/pushary-setup.js +14 -2
- package/dist/chunk-UIBTFZUD.js +314 -0
- package/package.json +2 -2
|
@@ -6,8 +6,9 @@ import {
|
|
|
6
6
|
import {
|
|
7
7
|
execNpm,
|
|
8
8
|
removeCodexHooks,
|
|
9
|
-
removeGeminiSettings
|
|
10
|
-
|
|
9
|
+
removeGeminiSettings,
|
|
10
|
+
removeInstructionBlock
|
|
11
|
+
} from "../chunk-UIBTFZUD.js";
|
|
11
12
|
|
|
12
13
|
// bin/pushary-clean.ts
|
|
13
14
|
import { existsSync, readFileSync, writeFileSync, rmSync } from "fs";
|
|
@@ -135,6 +136,19 @@ var main = async () => {
|
|
|
135
136
|
} else {
|
|
136
137
|
console.log(` ${skip} Codex hooks ${dim("(not found)")}`);
|
|
137
138
|
}
|
|
139
|
+
const codexAgentsMd = join(homedir(), ".codex", "AGENTS.md");
|
|
140
|
+
if (removeInstructionBlock(codexAgentsMd)) {
|
|
141
|
+
console.log(` ${check} Codex AGENTS.md ${dim("(removed Pushary block)")}`);
|
|
142
|
+
} else {
|
|
143
|
+
console.log(` ${skip} Codex AGENTS.md ${dim("(no pushary block)")}`);
|
|
144
|
+
}
|
|
145
|
+
const codexSkillDir = join(homedir(), ".codex", "skills", "pushary");
|
|
146
|
+
if (existsSync(codexSkillDir)) {
|
|
147
|
+
rmSync(codexSkillDir, { recursive: true });
|
|
148
|
+
console.log(` ${check} Codex skill directory ${dim("(removed)")}`);
|
|
149
|
+
} else {
|
|
150
|
+
console.log(` ${skip} Codex skill directory ${dim("(not found)")}`);
|
|
151
|
+
}
|
|
138
152
|
const geminiSettingsPath = join(homedir(), ".gemini", "settings.json");
|
|
139
153
|
const geminiSettings = readJson(geminiSettingsPath);
|
|
140
154
|
if (geminiSettings) {
|
|
@@ -147,6 +161,12 @@ var main = async () => {
|
|
|
147
161
|
} else {
|
|
148
162
|
console.log(` ${skip} Gemini CLI settings ${dim("(not found)")}`);
|
|
149
163
|
}
|
|
164
|
+
const geminiMd = join(homedir(), ".gemini", "GEMINI.md");
|
|
165
|
+
if (removeInstructionBlock(geminiMd)) {
|
|
166
|
+
console.log(` ${check} Gemini GEMINI.md ${dim("(removed Pushary block)")}`);
|
|
167
|
+
} else {
|
|
168
|
+
console.log(` ${skip} Gemini GEMINI.md ${dim("(no pushary block)")}`);
|
|
169
|
+
}
|
|
150
170
|
for (const shellFile of SHELL_FILES) {
|
|
151
171
|
try {
|
|
152
172
|
const content = readFileSync(shellFile, "utf-8");
|
|
@@ -4,9 +4,10 @@ import {
|
|
|
4
4
|
execNpm,
|
|
5
5
|
hasCodexHooks,
|
|
6
6
|
hasGeminiHooks,
|
|
7
|
+
hasInstructionBlock,
|
|
7
8
|
missingCodexHookEvents,
|
|
8
9
|
missingGeminiHookEvents
|
|
9
|
-
} from "../chunk-
|
|
10
|
+
} from "../chunk-UIBTFZUD.js";
|
|
10
11
|
import {
|
|
11
12
|
callMcpTool,
|
|
12
13
|
sendMcpRequest
|
|
@@ -189,6 +190,9 @@ var main = async () => {
|
|
|
189
190
|
}
|
|
190
191
|
const codexSkillPath = join(homedir(), ".codex", "skills", "pushary", "SKILL.md");
|
|
191
192
|
check(existsSync(codexSkillPath), "Codex: skill installed");
|
|
193
|
+
const codexAgentsMd = join(homedir(), ".codex", "AGENTS.md");
|
|
194
|
+
const hasCodexInstructions = hasInstructionBlock(codexAgentsMd);
|
|
195
|
+
check(hasCodexInstructions, "Codex: proactive instructions (AGENTS.md)", hasCodexInstructions ? codexAgentsMd : "missing \u2014 re-run setup so Codex asks via push, not the terminal");
|
|
192
196
|
}
|
|
193
197
|
const geminiSettingsPath = join(homedir(), ".gemini", "settings.json");
|
|
194
198
|
const geminiSettings = readJson(geminiSettingsPath);
|
|
@@ -213,6 +217,9 @@ var main = async () => {
|
|
|
213
217
|
} else {
|
|
214
218
|
check(false, "Gemini CLI: native hooks installed", "no Pushary hooks in ~/.gemini/settings.json \u2014 re-run setup");
|
|
215
219
|
}
|
|
220
|
+
const geminiMd = join(homedir(), ".gemini", "GEMINI.md");
|
|
221
|
+
const hasGeminiInstructions = hasInstructionBlock(geminiMd);
|
|
222
|
+
check(hasGeminiInstructions, "Gemini CLI: proactive instructions (GEMINI.md)", hasGeminiInstructions ? geminiMd : "missing \u2014 re-run setup so Gemini asks via push, not the terminal");
|
|
216
223
|
}
|
|
217
224
|
const cursorPluginDir = join(homedir(), ".cursor", "plugins", "local", "pushary");
|
|
218
225
|
if (existsSync(cursorPluginDir)) {
|
|
@@ -11,8 +11,10 @@ import {
|
|
|
11
11
|
addGeminiHooks,
|
|
12
12
|
addGeminiMcpServer,
|
|
13
13
|
execNpm,
|
|
14
|
-
npmErrorMessage
|
|
15
|
-
|
|
14
|
+
npmErrorMessage,
|
|
15
|
+
renderAgentInstructions,
|
|
16
|
+
writeInstructionBlock
|
|
17
|
+
} from "../chunk-UIBTFZUD.js";
|
|
16
18
|
import {
|
|
17
19
|
isValidApiKey
|
|
18
20
|
} from "../chunk-USUCPCUC.js";
|
|
@@ -303,7 +305,9 @@ var CURSOR_USER_HOOKS = join(homedir(), ".cursor", "hooks.json");
|
|
|
303
305
|
var CLAUDE_SKILL_DIR = join(homedir(), ".claude", "skills", "pushary");
|
|
304
306
|
var CODEX_HOME = process.env.CODEX_HOME?.trim() || join(homedir(), ".codex");
|
|
305
307
|
var CODEX_SKILL_DIR = join(CODEX_HOME, "skills", "pushary");
|
|
308
|
+
var CODEX_AGENTS_MD = join(CODEX_HOME, "AGENTS.md");
|
|
306
309
|
var GEMINI_SETTINGS = join(homedir(), ".gemini", "settings.json");
|
|
310
|
+
var GEMINI_MD = join(homedir(), ".gemini", "GEMINI.md");
|
|
307
311
|
var PUSHARY_CONFIG_DIR = join(homedir(), ".pushary");
|
|
308
312
|
var PUSHARY_CONFIG_FILE = join(PUSHARY_CONFIG_DIR, "config.json");
|
|
309
313
|
var SHELL_FILES = [".zshrc", ".zprofile", ".bashrc", ".bash_profile"].map((f) => join(homedir(), f));
|
|
@@ -667,9 +671,13 @@ var setupCodex = async (_apiKey) => {
|
|
|
667
671
|
});
|
|
668
672
|
}
|
|
669
673
|
await installSkillToDir(CODEX_SKILL_DIR, "Installing Pushary skill");
|
|
674
|
+
await spinner("Teaching Codex to ask via push (~/.codex/AGENTS.md)", async () => {
|
|
675
|
+
writeInstructionBlock(CODEX_AGENTS_MD, renderAgentInstructions("Codex"));
|
|
676
|
+
});
|
|
670
677
|
console.log();
|
|
671
678
|
console.log(` ${dim2("What this configured:")}`);
|
|
672
679
|
console.log(` ${dim2("\u2022")} MCP server: Codex can send notifications and ask questions`);
|
|
680
|
+
console.log(` ${dim2("\u2022")} Proactive instructions: ~/.codex/AGENTS.md tells Codex to ask via push, not the terminal`);
|
|
673
681
|
console.log(` ${dim2("\u2022")} Auto-allowed tools: no permission prompts for Pushary MCP calls`);
|
|
674
682
|
if (hooksSupported) {
|
|
675
683
|
console.log(` ${dim2("\u2022")} Native hooks: phone approvals, policy enforcement, kill switch, session tracking`);
|
|
@@ -829,9 +837,13 @@ var setupGemini = async (apiKey) => {
|
|
|
829
837
|
await spinner(`Writing ${GEMINI_SETTINGS}`, async () => {
|
|
830
838
|
writeJson(GEMINI_SETTINGS, settings);
|
|
831
839
|
});
|
|
840
|
+
await spinner("Teaching Gemini to ask via push (~/.gemini/GEMINI.md)", async () => {
|
|
841
|
+
writeInstructionBlock(GEMINI_MD, renderAgentInstructions("Gemini"));
|
|
842
|
+
});
|
|
832
843
|
console.log();
|
|
833
844
|
console.log(` ${dim2("What this configured:")}`);
|
|
834
845
|
console.log(` ${dim2("\u2022")} MCP server: Gemini can send notifications and ask questions`);
|
|
846
|
+
console.log(` ${dim2("\u2022")} Proactive instructions: ~/.gemini/GEMINI.md tells Gemini to ask via push, not the terminal`);
|
|
835
847
|
console.log(` ${dim2("\u2022")} Hooks: phone approvals, policy enforcement, kill switch, session tracking`);
|
|
836
848
|
console.log(` ${dim2("\u2022")} Gate covers ${bold2("run_shell_command")}, ${bold2("write_file")}, and ${bold2("replace")}`);
|
|
837
849
|
console.log(` ${dim2("\u2022")} Auto-allowed tools: Pushary MCP calls run without a confirmation prompt`);
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
// src/codex-config.ts
|
|
2
|
+
import { createHash } from "crypto";
|
|
3
|
+
var CODEX_HOOK_BINARY = "pushary-codex-hook";
|
|
4
|
+
var CODEX_HOOK_EVENTS = [
|
|
5
|
+
{ event: "PermissionRequest", matcher: "Bash|apply_patch", timeout: 180, statusMessage: "Waiting for your phone" },
|
|
6
|
+
{ event: "PreToolUse", matcher: "Bash|apply_patch", timeout: 180, statusMessage: "Checking Pushary policy" },
|
|
7
|
+
{ event: "PostToolUse", matcher: "Bash|apply_patch", timeout: 10 },
|
|
8
|
+
{ event: "UserPromptSubmit", timeout: 10 },
|
|
9
|
+
{ event: "Stop", timeout: 10 },
|
|
10
|
+
{ event: "SessionStart", matcher: "startup|resume", timeout: 10 }
|
|
11
|
+
];
|
|
12
|
+
var CODEX_EVENT_KEY = {
|
|
13
|
+
PermissionRequest: "permission_request",
|
|
14
|
+
PreToolUse: "pre_tool_use",
|
|
15
|
+
PostToolUse: "post_tool_use",
|
|
16
|
+
UserPromptSubmit: "user_prompt_submit",
|
|
17
|
+
Stop: "stop",
|
|
18
|
+
SessionStart: "session_start"
|
|
19
|
+
};
|
|
20
|
+
var asRecord = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
21
|
+
var ensureRecord = (target, key) => {
|
|
22
|
+
const existing = asRecord(target[key]);
|
|
23
|
+
if (existing) return existing;
|
|
24
|
+
const created = {};
|
|
25
|
+
target[key] = created;
|
|
26
|
+
return created;
|
|
27
|
+
};
|
|
28
|
+
var isPusharyCodexHook = (entry) => {
|
|
29
|
+
const hooks = asRecord(entry)?.hooks;
|
|
30
|
+
if (!Array.isArray(hooks)) return false;
|
|
31
|
+
return hooks.some((hook) => String(asRecord(hook)?.command ?? "").includes(CODEX_HOOK_BINARY));
|
|
32
|
+
};
|
|
33
|
+
var addCodexHooks = (config, command) => {
|
|
34
|
+
const hooks = ensureRecord(config, "hooks");
|
|
35
|
+
for (const definition of CODEX_HOOK_EVENTS) {
|
|
36
|
+
const existing = Array.isArray(hooks[definition.event]) ? hooks[definition.event] : [];
|
|
37
|
+
const entries = existing.filter((entry) => !isPusharyCodexHook(entry));
|
|
38
|
+
entries.push({
|
|
39
|
+
...definition.matcher ? { matcher: definition.matcher } : {},
|
|
40
|
+
hooks: [{
|
|
41
|
+
type: "command",
|
|
42
|
+
command,
|
|
43
|
+
timeout: definition.timeout,
|
|
44
|
+
...definition.statusMessage ? { statusMessage: definition.statusMessage } : {}
|
|
45
|
+
}]
|
|
46
|
+
});
|
|
47
|
+
hooks[definition.event] = entries;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var removeCodexHooks = (config) => {
|
|
51
|
+
const hooks = asRecord(config.hooks);
|
|
52
|
+
if (!hooks) return false;
|
|
53
|
+
let changed = false;
|
|
54
|
+
for (const definition of CODEX_HOOK_EVENTS) {
|
|
55
|
+
const entries = hooks[definition.event];
|
|
56
|
+
if (!Array.isArray(entries)) continue;
|
|
57
|
+
const filtered = entries.filter((entry) => !isPusharyCodexHook(entry));
|
|
58
|
+
if (filtered.length !== entries.length) {
|
|
59
|
+
if (filtered.length === 0) {
|
|
60
|
+
delete hooks[definition.event];
|
|
61
|
+
} else {
|
|
62
|
+
hooks[definition.event] = filtered;
|
|
63
|
+
}
|
|
64
|
+
changed = true;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (Object.keys(hooks).length === 0) delete config.hooks;
|
|
68
|
+
return changed;
|
|
69
|
+
};
|
|
70
|
+
var hasCodexHooks = (config) => {
|
|
71
|
+
const hooks = asRecord(config.hooks);
|
|
72
|
+
if (!hooks) return false;
|
|
73
|
+
return CODEX_HOOK_EVENTS.some((definition) => {
|
|
74
|
+
const entries = hooks[definition.event];
|
|
75
|
+
return Array.isArray(entries) && entries.some(isPusharyCodexHook);
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
var missingCodexHookEvents = (config) => {
|
|
79
|
+
const hooks = asRecord(config.hooks);
|
|
80
|
+
return CODEX_HOOK_EVENTS.filter((definition) => {
|
|
81
|
+
const entries = hooks?.[definition.event];
|
|
82
|
+
return !Array.isArray(entries) || !entries.some(isPusharyCodexHook);
|
|
83
|
+
}).map((definition) => definition.event);
|
|
84
|
+
};
|
|
85
|
+
var canonicalJson = (value) => {
|
|
86
|
+
if (value === null || typeof value !== "object") return JSON.stringify(value);
|
|
87
|
+
if (Array.isArray(value)) return "[" + value.map(canonicalJson).join(",") + "]";
|
|
88
|
+
const obj = value;
|
|
89
|
+
return "{" + Object.keys(obj).sort().map((key) => JSON.stringify(key) + ":" + canonicalJson(obj[key])).join(",") + "}";
|
|
90
|
+
};
|
|
91
|
+
var codexHookTrustHash = (definition, command) => {
|
|
92
|
+
const hook = { async: false, command, timeout: definition.timeout, type: "command" };
|
|
93
|
+
if (definition.statusMessage) hook.statusMessage = definition.statusMessage;
|
|
94
|
+
const identity = { event_name: CODEX_EVENT_KEY[definition.event], hooks: [hook] };
|
|
95
|
+
if (definition.matcher) identity.matcher = definition.matcher;
|
|
96
|
+
return "sha256:" + createHash("sha256").update(canonicalJson(identity), "utf8").digest("hex");
|
|
97
|
+
};
|
|
98
|
+
var codexHookStateKey = (hooksJsonPath, event) => `${hooksJsonPath}:${CODEX_EVENT_KEY[event]}:0:0`;
|
|
99
|
+
var addCodexHookTrust = (config, hooksJsonPath, command) => {
|
|
100
|
+
const hooks = ensureRecord(config, "hooks");
|
|
101
|
+
const state = ensureRecord(hooks, "state");
|
|
102
|
+
for (const definition of CODEX_HOOK_EVENTS) {
|
|
103
|
+
const key = codexHookStateKey(hooksJsonPath, definition.event);
|
|
104
|
+
const existing = asRecord(state[key]) ?? {};
|
|
105
|
+
state[key] = { ...existing, trusted_hash: codexHookTrustHash(definition, command) };
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// src/gemini-config.ts
|
|
110
|
+
var GEMINI_HOOK_BINARY = "pushary-gemini-hook";
|
|
111
|
+
var GEMINI_MCP_URL = "https://pushary.com/api/mcp/mcp";
|
|
112
|
+
var GEMINI_HOOK_EVENTS = [
|
|
113
|
+
{ event: "BeforeTool", matcher: "run_shell_command|write_file|replace", timeoutMs: 18e4 },
|
|
114
|
+
{ event: "AfterTool", matcher: "run_shell_command|write_file|replace", timeoutMs: 1e4 },
|
|
115
|
+
{ event: "BeforeAgent", timeoutMs: 1e4 },
|
|
116
|
+
{ event: "SessionStart", timeoutMs: 1e4 },
|
|
117
|
+
{ event: "SessionEnd", timeoutMs: 1e4 }
|
|
118
|
+
];
|
|
119
|
+
var asRecord2 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
120
|
+
var ensureRecord2 = (target, key) => {
|
|
121
|
+
const existing = asRecord2(target[key]);
|
|
122
|
+
if (existing) return existing;
|
|
123
|
+
const created = {};
|
|
124
|
+
target[key] = created;
|
|
125
|
+
return created;
|
|
126
|
+
};
|
|
127
|
+
var isPusharyGeminiHook = (entry) => {
|
|
128
|
+
const hooks = asRecord2(entry)?.hooks;
|
|
129
|
+
if (!Array.isArray(hooks)) return false;
|
|
130
|
+
return hooks.some((hook) => String(asRecord2(hook)?.command ?? "").includes(GEMINI_HOOK_BINARY));
|
|
131
|
+
};
|
|
132
|
+
var addGeminiMcpServer = (settings, apiKey) => {
|
|
133
|
+
const mcpServers = ensureRecord2(settings, "mcpServers");
|
|
134
|
+
mcpServers.pushary = {
|
|
135
|
+
httpUrl: GEMINI_MCP_URL,
|
|
136
|
+
headers: { Authorization: `Bearer ${apiKey}` },
|
|
137
|
+
trust: true
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
var addGeminiHooks = (settings, command) => {
|
|
141
|
+
const hooks = ensureRecord2(settings, "hooks");
|
|
142
|
+
for (const definition of GEMINI_HOOK_EVENTS) {
|
|
143
|
+
const existing = Array.isArray(hooks[definition.event]) ? hooks[definition.event] : [];
|
|
144
|
+
const entries = existing.filter((entry) => !isPusharyGeminiHook(entry));
|
|
145
|
+
entries.push({
|
|
146
|
+
...definition.matcher ? { matcher: definition.matcher } : {},
|
|
147
|
+
hooks: [{
|
|
148
|
+
name: "pushary",
|
|
149
|
+
type: "command",
|
|
150
|
+
command,
|
|
151
|
+
timeout: definition.timeoutMs
|
|
152
|
+
}]
|
|
153
|
+
});
|
|
154
|
+
hooks[definition.event] = entries;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
var removeGeminiHooks = (settings) => {
|
|
158
|
+
const hooks = asRecord2(settings.hooks);
|
|
159
|
+
if (!hooks) return false;
|
|
160
|
+
let changed = false;
|
|
161
|
+
for (const definition of GEMINI_HOOK_EVENTS) {
|
|
162
|
+
const entries = hooks[definition.event];
|
|
163
|
+
if (!Array.isArray(entries)) continue;
|
|
164
|
+
const filtered = entries.filter((entry) => !isPusharyGeminiHook(entry));
|
|
165
|
+
if (filtered.length !== entries.length) {
|
|
166
|
+
if (filtered.length === 0) {
|
|
167
|
+
delete hooks[definition.event];
|
|
168
|
+
} else {
|
|
169
|
+
hooks[definition.event] = filtered;
|
|
170
|
+
}
|
|
171
|
+
changed = true;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (Object.keys(hooks).length === 0) delete settings.hooks;
|
|
175
|
+
return changed;
|
|
176
|
+
};
|
|
177
|
+
var removeGeminiMcpServer = (settings) => {
|
|
178
|
+
const mcpServers = asRecord2(settings.mcpServers);
|
|
179
|
+
if (!mcpServers?.pushary) return false;
|
|
180
|
+
delete mcpServers.pushary;
|
|
181
|
+
if (Object.keys(mcpServers).length === 0) delete settings.mcpServers;
|
|
182
|
+
return true;
|
|
183
|
+
};
|
|
184
|
+
var removeGeminiSettings = (settings) => {
|
|
185
|
+
const mcpRemoved = removeGeminiMcpServer(settings);
|
|
186
|
+
const hooksRemoved = removeGeminiHooks(settings);
|
|
187
|
+
return mcpRemoved || hooksRemoved;
|
|
188
|
+
};
|
|
189
|
+
var hasGeminiHooks = (settings) => {
|
|
190
|
+
const hooks = asRecord2(settings.hooks);
|
|
191
|
+
if (!hooks) return false;
|
|
192
|
+
return GEMINI_HOOK_EVENTS.some((definition) => {
|
|
193
|
+
const entries = hooks[definition.event];
|
|
194
|
+
return Array.isArray(entries) && entries.some(isPusharyGeminiHook);
|
|
195
|
+
});
|
|
196
|
+
};
|
|
197
|
+
var missingGeminiHookEvents = (settings) => {
|
|
198
|
+
const hooks = asRecord2(settings.hooks);
|
|
199
|
+
return GEMINI_HOOK_EVENTS.filter((definition) => {
|
|
200
|
+
const entries = hooks?.[definition.event];
|
|
201
|
+
return !Array.isArray(entries) || !entries.some(isPusharyGeminiHook);
|
|
202
|
+
}).map((definition) => definition.event);
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
// src/instruction-file.ts
|
|
206
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync, rmSync } from "fs";
|
|
207
|
+
import { dirname } from "path";
|
|
208
|
+
var PUSHARY_BEGIN = "<!-- BEGIN PUSHARY (managed by @pushary/agent-hooks; do not edit this block) -->";
|
|
209
|
+
var PUSHARY_END = "<!-- END PUSHARY -->";
|
|
210
|
+
var instructionBody = (label) => `## Pushary notifications and approvals
|
|
211
|
+
|
|
212
|
+
You have Pushary MCP tools that reach the user on their phone. Use them proactively. Do not wait for the user to ask.
|
|
213
|
+
|
|
214
|
+
- 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.
|
|
215
|
+
- 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.
|
|
216
|
+
- 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.
|
|
217
|
+
- When a task that took several steps finishes, call \`send_notification\` so the user knows it is done.
|
|
218
|
+
- Use \`cancel_question\` to retract a pending question once it is no longer needed.
|
|
219
|
+
|
|
220
|
+
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.`;
|
|
221
|
+
var renderAgentInstructions = (label) => instructionBody(label);
|
|
222
|
+
var wrap = (body) => `${PUSHARY_BEGIN}
|
|
223
|
+
${body}
|
|
224
|
+
${PUSHARY_END}`;
|
|
225
|
+
var writeInstructionBlock = (filePath, body) => {
|
|
226
|
+
const dir = dirname(filePath);
|
|
227
|
+
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
228
|
+
let existing = "";
|
|
229
|
+
try {
|
|
230
|
+
existing = readFileSync(filePath, "utf-8");
|
|
231
|
+
} catch {
|
|
232
|
+
}
|
|
233
|
+
const block = wrap(body);
|
|
234
|
+
const start = existing.indexOf(PUSHARY_BEGIN);
|
|
235
|
+
const end = existing.indexOf(PUSHARY_END);
|
|
236
|
+
let next;
|
|
237
|
+
if (start !== -1 && end !== -1 && end > start) {
|
|
238
|
+
next = existing.slice(0, start) + block + existing.slice(end + PUSHARY_END.length);
|
|
239
|
+
} else {
|
|
240
|
+
const prefix = existing.trim() ? existing.replace(/\s*$/, "") + "\n\n" : "";
|
|
241
|
+
next = prefix + block + "\n";
|
|
242
|
+
}
|
|
243
|
+
writeFileSync(filePath, next, "utf-8");
|
|
244
|
+
};
|
|
245
|
+
var removeInstructionBlock = (filePath) => {
|
|
246
|
+
let existing = "";
|
|
247
|
+
try {
|
|
248
|
+
existing = readFileSync(filePath, "utf-8");
|
|
249
|
+
} catch {
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
const start = existing.indexOf(PUSHARY_BEGIN);
|
|
253
|
+
const end = existing.indexOf(PUSHARY_END);
|
|
254
|
+
if (start === -1 || end === -1 || end < start) return false;
|
|
255
|
+
const remaining = (existing.slice(0, start) + existing.slice(end + PUSHARY_END.length)).trim();
|
|
256
|
+
if (remaining === "") {
|
|
257
|
+
rmSync(filePath, { force: true });
|
|
258
|
+
} else {
|
|
259
|
+
writeFileSync(filePath, remaining + "\n", "utf-8");
|
|
260
|
+
}
|
|
261
|
+
return true;
|
|
262
|
+
};
|
|
263
|
+
var hasInstructionBlock = (filePath) => {
|
|
264
|
+
try {
|
|
265
|
+
return readFileSync(filePath, "utf-8").includes(PUSHARY_BEGIN);
|
|
266
|
+
} catch {
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
// src/npm.ts
|
|
272
|
+
import { execSync } from "child_process";
|
|
273
|
+
var cleanNpmEnv = () => {
|
|
274
|
+
const env = {};
|
|
275
|
+
for (const [key, value] of Object.entries(process.env)) {
|
|
276
|
+
if (key.toLowerCase().startsWith("npm_config_workspace")) continue;
|
|
277
|
+
env[key] = value;
|
|
278
|
+
}
|
|
279
|
+
return env;
|
|
280
|
+
};
|
|
281
|
+
var npmErrorMessage = (err) => {
|
|
282
|
+
const e = err;
|
|
283
|
+
const text = [e?.stderr, e?.stdout].map((part) => part ? part.toString() : "").join("\n");
|
|
284
|
+
const line = text.split("\n").map((l) => l.replace(/^npm error\s*/i, "").trim()).find((l) => l && !l.startsWith("A complete log") && !/^code\s/i.test(l));
|
|
285
|
+
return line || e?.message || String(err);
|
|
286
|
+
};
|
|
287
|
+
var execNpm = (args, options = {}) => {
|
|
288
|
+
return execSync(`npm ${args}`, {
|
|
289
|
+
timeout: 12e4,
|
|
290
|
+
stdio: "pipe",
|
|
291
|
+
...options,
|
|
292
|
+
env: { ...cleanNpmEnv(), ...options.env ?? {} }
|
|
293
|
+
});
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
export {
|
|
297
|
+
addCodexHooks,
|
|
298
|
+
removeCodexHooks,
|
|
299
|
+
hasCodexHooks,
|
|
300
|
+
missingCodexHookEvents,
|
|
301
|
+
addCodexHookTrust,
|
|
302
|
+
GEMINI_HOOK_BINARY,
|
|
303
|
+
addGeminiMcpServer,
|
|
304
|
+
addGeminiHooks,
|
|
305
|
+
removeGeminiSettings,
|
|
306
|
+
hasGeminiHooks,
|
|
307
|
+
missingGeminiHookEvents,
|
|
308
|
+
renderAgentInstructions,
|
|
309
|
+
writeInstructionBlock,
|
|
310
|
+
removeInstructionBlock,
|
|
311
|
+
hasInstructionBlock,
|
|
312
|
+
npmErrorMessage,
|
|
313
|
+
execNpm
|
|
314
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pushary/agent-hooks",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"description": "Permission hooks for AI coding agents: route tool approvals through Pushary push notifications",
|
|
5
5
|
"author": "Pushary <business@pushary.com>",
|
|
6
6
|
"homepage": "https://pushary.com",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "node scripts/bundle-plugin.mjs && tsup",
|
|
40
40
|
"dev": "tsup --watch",
|
|
41
|
-
"test": "bun test src/api.test.ts && bun test src/claude-config.test.ts && bun test src/config.test.ts && bun test src/mcp-http.test.ts && bun test src/retry.test.ts && bun test src/usage.test.ts && bun test src/validate.test.ts && bun test src/policy.test.ts && bun test src/npm.test.ts && bun test src/identity.test.ts && bun test src/pending.test.ts && bun test src/events.test.ts && bun test src/describe.test.ts && bun test src/suggestions.test.ts && bun test src/safe-commands.test.ts && bun test src/hook.test.ts && bun test src/codex-adapter.test.ts && bun test src/codex-config.test.ts && bun test src/gemini-adapter.test.ts && bun test src/gemini-config.test.ts && bun test src/pairing.test.ts"
|
|
41
|
+
"test": "bun test src/api.test.ts && bun test src/claude-config.test.ts && bun test src/config.test.ts && bun test src/mcp-http.test.ts && bun test src/retry.test.ts && bun test src/usage.test.ts && bun test src/validate.test.ts && bun test src/policy.test.ts && bun test src/npm.test.ts && bun test src/identity.test.ts && bun test src/pending.test.ts && bun test src/events.test.ts && bun test src/describe.test.ts && bun test src/suggestions.test.ts && bun test src/safe-commands.test.ts && bun test src/hook.test.ts && bun test src/codex-adapter.test.ts && bun test src/codex-config.test.ts && bun test src/gemini-adapter.test.ts && bun test src/gemini-config.test.ts && bun test src/instruction-file.test.ts && bun test src/pairing.test.ts"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@inquirer/prompts": "^8.4.2",
|