@pushary/agent-hooks 0.27.0 → 0.28.1
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/LICENSE +21 -0
- package/README.md +111 -0
- package/dist/bin/pushary-clean.js +3 -3
- package/dist/bin/pushary-codex-hook.js +2 -2
- package/dist/bin/pushary-codex.js +2 -2
- package/dist/bin/pushary-doctor.js +2 -2
- package/dist/bin/pushary-gemini-hook.js +2 -2
- package/dist/bin/pushary-hook.js +3 -3
- package/dist/bin/pushary-post-hook.js +2 -2
- package/dist/bin/pushary-prompt-hook.js +2 -2
- package/dist/bin/pushary-setup.js +4 -4
- package/dist/bin/pushary-stop-hook.js +2 -2
- package/dist/chunk-22CV7V7A.js +38 -0
- package/dist/chunk-2BE2IPMO.js +315 -0
- package/dist/chunk-2CRLBMOX.js +244 -0
- package/dist/chunk-2HMNOZPY.js +109 -0
- package/dist/chunk-2I6DLXJN.js +219 -0
- package/dist/chunk-2Q6XPZ4Q.js +395 -0
- package/dist/chunk-3LC4YUMA.js +194 -0
- package/dist/chunk-3MIR7ODJ.js +112 -0
- package/dist/chunk-3QZESA66.js +222 -0
- package/dist/chunk-4Z4MB37G.js +96 -0
- package/dist/chunk-5GFUI5N6.js +132 -0
- package/dist/chunk-5JEDLXEC.js +99 -0
- package/dist/chunk-5LTQNC7R.js +824 -0
- package/dist/chunk-5MA3CPZB.js +141 -0
- package/dist/chunk-5QHQVXWN.js +174 -0
- package/dist/{chunk-WXWHRXDK.js → chunk-5V3XJ2ES.js} +1 -1
- package/dist/chunk-6A3WCJO2.js +416 -0
- package/dist/chunk-6QWFMVCD.js +328 -0
- package/dist/chunk-6SRXMZAN.js +99 -0
- package/dist/chunk-7OXL2QQ4.js +357 -0
- package/dist/chunk-7PTU7TGE.js +96 -0
- package/dist/chunk-AB4KX4XT.js +109 -0
- package/dist/chunk-AC4UYAGX.js +136 -0
- package/dist/chunk-ACE77TKQ.js +328 -0
- package/dist/chunk-BHAMEPOP.js +323 -0
- package/dist/chunk-BYNYYZWW.js +412 -0
- package/dist/{chunk-FDR5WYT7.js → chunk-C4BMEVK7.js} +1 -1
- package/dist/chunk-C5TFTNHG.js +244 -0
- package/dist/chunk-CH53PBQN.js +265 -0
- package/dist/chunk-DF3BM6BF.js +195 -0
- package/dist/chunk-DKZVKEOW.js +175 -0
- package/dist/chunk-EMPL27ZV.js +96 -0
- package/dist/chunk-EQJXMEIR.js +175 -0
- package/dist/{chunk-MVNOP5IZ.js → chunk-FB3N633T.js} +1 -1
- package/dist/chunk-FGZZRCOG.js +194 -0
- package/dist/chunk-FXYTRZHC.js +177 -0
- package/dist/chunk-GTJGZBTQ.js +328 -0
- package/dist/chunk-GYPPVD3P.js +1047 -0
- package/dist/chunk-HJMFYDWY.js +222 -0
- package/dist/chunk-HRQEECB6.js +315 -0
- package/dist/chunk-HWEMAAOY.js +370 -0
- package/dist/{chunk-VHD3GMZ3.js → chunk-I4GMPUYN.js} +2 -2
- package/dist/{chunk-TUILTFLS.js → chunk-IAOXM7X5.js} +1 -1
- package/dist/chunk-IBWCHA5M.js +10 -0
- package/dist/chunk-JPRRYC5X.js +328 -0
- package/dist/chunk-KTM4ZQ3W.js +96 -0
- package/dist/chunk-KTP2EPVB.js +27 -0
- package/dist/chunk-KYARP7KP.js +97 -0
- package/dist/chunk-LXUHXG2X.js +937 -0
- package/dist/chunk-M2N5DYWN.js +247 -0
- package/dist/chunk-M4GDBGXF.js +824 -0
- package/dist/chunk-M5F2L4KF.js +177 -0
- package/dist/chunk-M6S3M6E3.js +244 -0
- package/dist/chunk-N7VXDBQU.js +6 -0
- package/dist/chunk-O2QL6U6G.js +194 -0
- package/dist/chunk-O6A5RHWY.js +122 -0
- package/dist/chunk-ODUXELPM.js +219 -0
- package/dist/chunk-OF5WIOYS.js +129 -0
- package/dist/chunk-OP4QAN23.js +99 -0
- package/dist/chunk-P4JH2Q7Z.js +102 -0
- package/dist/chunk-P6QBZS27.js +231 -0
- package/dist/chunk-PMD5JSV3.js +242 -0
- package/dist/chunk-PSSHNBEL.js +177 -0
- package/dist/chunk-PZO7RZ5W.js +145 -0
- package/dist/chunk-QEPRH7JB.js +315 -0
- package/dist/chunk-QNEYHDKR.js +145 -0
- package/dist/chunk-QRXWPZKN.js +308 -0
- package/dist/chunk-QY4L6XHN.js +384 -0
- package/dist/chunk-RNWPCELY.js +176 -0
- package/dist/chunk-RSHN2AQ7.js +29 -0
- package/dist/chunk-RZLVE57X.js +38 -0
- package/dist/chunk-SDCIKREA.js +241 -0
- package/dist/chunk-SDREQWNI.js +175 -0
- package/dist/chunk-SH26ZOHU.js +159 -0
- package/dist/chunk-SJ5MC36D.js +882 -0
- package/dist/chunk-TRLBBLSS.js +176 -0
- package/dist/chunk-U6OXZPYC.js +384 -0
- package/dist/chunk-UDQZNO5H.js +231 -0
- package/dist/chunk-UIBTFZUD.js +314 -0
- package/dist/chunk-USUCPCUC.js +156 -0
- package/dist/chunk-UTK3TJC4.js +882 -0
- package/dist/chunk-V4GLWPD7.js +174 -0
- package/dist/chunk-VC6U3QGF.js +142 -0
- package/dist/chunk-VIST7ACL.js +88 -0
- package/dist/chunk-VUNL35KE.js +16 -0
- package/dist/chunk-VWBNI4SC.js +174 -0
- package/dist/chunk-W5KRWUNE.js +262 -0
- package/dist/chunk-WCGKLHCL.js +154 -0
- package/dist/chunk-WNXGIEX7.js +219 -0
- package/dist/chunk-WPVL6VIT.js +160 -0
- package/dist/chunk-X3YCHQQK.js +357 -0
- package/dist/chunk-X6LV22NZ.js +229 -0
- package/dist/chunk-XHTZ2DWC.js +206 -0
- package/dist/chunk-XPVSZIA3.js +315 -0
- package/dist/chunk-Y633ZIJF.js +384 -0
- package/dist/chunk-YCL4GUFR.js +222 -0
- package/dist/chunk-YTMKB44I.js +220 -0
- package/dist/chunk-Z5PL3K7C.js +322 -0
- package/dist/chunk-ZWBS3T7Q.js +244 -0
- package/dist/pushary-mode-T7XOPI6Z.js +83 -0
- package/dist/pushary-wait-4BUC6ZM6.js +93 -0
- package/dist/src/index.js +3 -3
- package/package.json +25 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pushary
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# @pushary/agent-hooks
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@pushary/agent-hooks)
|
|
4
|
+
[](https://www.npmjs.com/package/@pushary/agent-hooks)
|
|
5
|
+
[](./LICENSE)
|
|
6
|
+
|
|
7
|
+
Push notifications, questions, and permission approvals for AI coding agents. Get a push when your agent finishes work, answer its questions from your phone, and approve risky commands before they run. Works with Claude Code, Codex, Cursor, Gemini CLI, and Hermes.
|
|
8
|
+
|
|
9
|
+
Your agent froze waiting for a yes. This is how it reaches you.
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npx @pushary/agent-hooks@latest setup
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
One command wires up the MCP server, the permission hooks, and the agent instruction files. Then you close your laptop and the agent still reaches you.
|
|
16
|
+
|
|
17
|
+
## What it does
|
|
18
|
+
|
|
19
|
+
There are three things.
|
|
20
|
+
|
|
21
|
+
**Notify.** The agent sends a push when a long task finishes or when a build, test, or deploy fails. The notification can carry what changed, the error, and suggested next steps.
|
|
22
|
+
|
|
23
|
+
**Ask.** The agent asks you questions through push: yes/no, multiple choice, or free text. It waits for your answer. When Pushary is connected, the agent sends its questions to your phone instead of stalling in the terminal.
|
|
24
|
+
|
|
25
|
+
**Gate.** Risky shell commands (`rm -rf`, force pushes, history rewrites, database drops, deploys) are checked before they run. What happens is set by your dashboard policy: auto approve trusted read-only commands, push to your phone for approval, or hold for the phone and never auto-deny. If the check cannot run, the command is blocked instead of allowed. It fails closed.
|
|
26
|
+
|
|
27
|
+
## Setup
|
|
28
|
+
|
|
29
|
+
You need an API key. Sign up at [pushary.com](https://pushary.com/sign-up?from=npm), then run:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npx @pushary/agent-hooks@latest setup
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The wizard detects which agents you have installed and configures each one. To skip the prompts:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npx @pushary/agent-hooks@latest setup --key pk_xxx.sk_xxx --skip-phone
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Verify it worked:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npx @pushary/agent-hooks@latest doctor
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Supported agents
|
|
48
|
+
|
|
49
|
+
| Agent | Notify | Ask | Gate |
|
|
50
|
+
|-------|:------:|:---:|:----:|
|
|
51
|
+
| Claude Code | yes | yes | yes |
|
|
52
|
+
| Codex | yes | yes | yes |
|
|
53
|
+
| Cursor | yes | yes | yes |
|
|
54
|
+
| Gemini CLI | yes | yes | yes |
|
|
55
|
+
| Hermes | yes | yes | yes |
|
|
56
|
+
|
|
57
|
+
Any other MCP client can use notify and ask by pointing at the Pushary MCP endpoint directly.
|
|
58
|
+
|
|
59
|
+
## Commands
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
setup Configure Claude Code, Codex, Gemini CLI, Hermes, or Cursor with Pushary
|
|
63
|
+
doctor Verify your Pushary installation is working
|
|
64
|
+
clean Remove all Pushary configuration
|
|
65
|
+
mode Switch approval mode (push_only, push_first, terminal_only)
|
|
66
|
+
wait Show or set the "wait for your phone" ladder (pushary wait 45)
|
|
67
|
+
hook Run as a PreToolUse hook (reads stdin, writes stdout)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Examples:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
npx @pushary/agent-hooks@latest mode push_only --for 30m
|
|
74
|
+
npx @pushary/agent-hooks@latest wait 45
|
|
75
|
+
npx @pushary/agent-hooks@latest clean
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Manual MCP setup
|
|
79
|
+
|
|
80
|
+
If you only want notifications and questions (no permission gating), add Pushary to your MCP config directly:
|
|
81
|
+
|
|
82
|
+
```json
|
|
83
|
+
{
|
|
84
|
+
"mcpServers": {
|
|
85
|
+
"pushary": {
|
|
86
|
+
"type": "http",
|
|
87
|
+
"url": "https://pushary.com/api/mcp/mcp",
|
|
88
|
+
"headers": {
|
|
89
|
+
"Authorization": "Bearer YOUR_API_KEY"
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
The MCP server exposes `send_notification`, `ask_user`, `wait_for_answer`, and `cancel_question`. Full tool reference is in the [docs](https://pushary.com/docs?from=npm).
|
|
97
|
+
|
|
98
|
+
## Security
|
|
99
|
+
|
|
100
|
+
The permission gate fails closed. If a policy cannot be fetched or a hook errors, the command is blocked, not allowed. Secrets in command arguments and environment are redacted before anything is sent to a phone or stored. Read-only commands can be allowlisted so trusted work never interrupts you, while writes and destructive commands still route through approval.
|
|
101
|
+
|
|
102
|
+
## Links
|
|
103
|
+
|
|
104
|
+
- Website: [pushary.com](https://pushary.com/?from=npm)
|
|
105
|
+
- Docs: [pushary.com/docs](https://pushary.com/docs?from=npm)
|
|
106
|
+
- Sign up: [pushary.com/sign-up](https://pushary.com/sign-up?from=npm)
|
|
107
|
+
- Issues: [github.com/pushary/pushary/issues](https://github.com/pushary/pushary/issues)
|
|
108
|
+
|
|
109
|
+
## License
|
|
110
|
+
|
|
111
|
+
MIT
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
import {
|
|
3
3
|
removeClaudeMcpServers,
|
|
4
4
|
removePusharySettings
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-QNEYHDKR.js";
|
|
6
6
|
import {
|
|
7
7
|
execNpm,
|
|
8
8
|
removeCodexHooks,
|
|
9
9
|
removeGeminiSettings,
|
|
10
10
|
removeInstructionBlock
|
|
11
|
-
} from "../chunk-
|
|
12
|
-
import "../chunk-
|
|
11
|
+
} from "../chunk-X3YCHQQK.js";
|
|
12
|
+
import "../chunk-Z5PL3K7C.js";
|
|
13
13
|
|
|
14
14
|
// bin/pushary-clean.ts
|
|
15
15
|
import { existsSync, readFileSync, writeFileSync, rmSync } from "fs";
|
|
@@ -32,14 +32,14 @@ import {
|
|
|
32
32
|
toCodexWire,
|
|
33
33
|
toPolicyLookup,
|
|
34
34
|
waitForAnswer
|
|
35
|
-
} from "../chunk-
|
|
35
|
+
} from "../chunk-IAOXM7X5.js";
|
|
36
36
|
import "../chunk-DWED7BS3.js";
|
|
37
37
|
import {
|
|
38
38
|
DECISION_LINE_MAX,
|
|
39
39
|
effectiveWaitSeconds,
|
|
40
40
|
hookWaitClamped,
|
|
41
41
|
hookWaitDeadline
|
|
42
|
-
} from "../chunk-
|
|
42
|
+
} from "../chunk-Z5PL3K7C.js";
|
|
43
43
|
import {
|
|
44
44
|
getApiKey
|
|
45
45
|
} from "../chunk-NKXSILEW.js";
|
|
@@ -4,9 +4,9 @@ import {
|
|
|
4
4
|
getMachineId,
|
|
5
5
|
reportEvent,
|
|
6
6
|
waitForAnswer
|
|
7
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-IAOXM7X5.js";
|
|
8
8
|
import "../chunk-DWED7BS3.js";
|
|
9
|
-
import "../chunk-
|
|
9
|
+
import "../chunk-Z5PL3K7C.js";
|
|
10
10
|
import {
|
|
11
11
|
getApiKey
|
|
12
12
|
} from "../chunk-NKXSILEW.js";
|
|
@@ -12,12 +12,12 @@ import {
|
|
|
12
12
|
missingGeminiHookEvents,
|
|
13
13
|
readCodexMcpAuth,
|
|
14
14
|
untrustedCodexHookEvents
|
|
15
|
-
} from "../chunk-
|
|
15
|
+
} from "../chunk-X3YCHQQK.js";
|
|
16
16
|
import {
|
|
17
17
|
callMcpTool,
|
|
18
18
|
sendMcpRequest
|
|
19
19
|
} from "../chunk-DWED7BS3.js";
|
|
20
|
-
import "../chunk-
|
|
20
|
+
import "../chunk-Z5PL3K7C.js";
|
|
21
21
|
import {
|
|
22
22
|
getBaseUrl
|
|
23
23
|
} from "../chunk-NKXSILEW.js";
|
|
@@ -24,14 +24,14 @@ import {
|
|
|
24
24
|
savePendingQuestion,
|
|
25
25
|
sendNotification,
|
|
26
26
|
waitForAnswer
|
|
27
|
-
} from "../chunk-
|
|
27
|
+
} from "../chunk-IAOXM7X5.js";
|
|
28
28
|
import "../chunk-DWED7BS3.js";
|
|
29
29
|
import {
|
|
30
30
|
DECISION_LINE_MAX,
|
|
31
31
|
effectiveWaitSeconds,
|
|
32
32
|
hookWaitClamped,
|
|
33
33
|
hookWaitDeadline
|
|
34
|
-
} from "../chunk-
|
|
34
|
+
} from "../chunk-Z5PL3K7C.js";
|
|
35
35
|
import {
|
|
36
36
|
getApiKey
|
|
37
37
|
} from "../chunk-NKXSILEW.js";
|
package/dist/bin/pushary-hook.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
handlePreToolUse
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-P6QBZS27.js";
|
|
5
5
|
import "../chunk-KQYIHZ5E.js";
|
|
6
|
-
import "../chunk-
|
|
6
|
+
import "../chunk-IAOXM7X5.js";
|
|
7
7
|
import "../chunk-DWED7BS3.js";
|
|
8
|
-
import "../chunk-
|
|
8
|
+
import "../chunk-Z5PL3K7C.js";
|
|
9
9
|
import "../chunk-NKXSILEW.js";
|
|
10
10
|
|
|
11
11
|
// bin/pushary-hook.ts
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
handlePostToolUse
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-IAOXM7X5.js";
|
|
5
5
|
import "../chunk-DWED7BS3.js";
|
|
6
|
-
import "../chunk-
|
|
6
|
+
import "../chunk-Z5PL3K7C.js";
|
|
7
7
|
import "../chunk-NKXSILEW.js";
|
|
8
8
|
|
|
9
9
|
// bin/pushary-post-hook.ts
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
handleUserPrompt
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-IAOXM7X5.js";
|
|
5
5
|
import "../chunk-DWED7BS3.js";
|
|
6
|
-
import "../chunk-
|
|
6
|
+
import "../chunk-Z5PL3K7C.js";
|
|
7
7
|
import "../chunk-NKXSILEW.js";
|
|
8
8
|
|
|
9
9
|
// bin/pushary-prompt-hook.ts
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
addClaudeMcpServer,
|
|
4
4
|
addPusharyHooks,
|
|
5
5
|
addPusharyToolPermissions
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-QNEYHDKR.js";
|
|
7
7
|
import {
|
|
8
8
|
GEMINI_HOOK_BINARY,
|
|
9
9
|
addCodexHookTrust,
|
|
@@ -16,14 +16,14 @@ import {
|
|
|
16
16
|
renderAgentInstructions,
|
|
17
17
|
renderProjectAgentInstructions,
|
|
18
18
|
writeInstructionBlock
|
|
19
|
-
} from "../chunk-
|
|
19
|
+
} from "../chunk-X3YCHQQK.js";
|
|
20
20
|
import {
|
|
21
21
|
reportEvent
|
|
22
|
-
} from "../chunk-
|
|
22
|
+
} from "../chunk-IAOXM7X5.js";
|
|
23
23
|
import "../chunk-DWED7BS3.js";
|
|
24
24
|
import {
|
|
25
25
|
isValidApiKey
|
|
26
|
-
} from "../chunk-
|
|
26
|
+
} from "../chunk-Z5PL3K7C.js";
|
|
27
27
|
import "../chunk-NKXSILEW.js";
|
|
28
28
|
|
|
29
29
|
// bin/pushary-setup.ts
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
handleStop
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-IAOXM7X5.js";
|
|
5
5
|
import "../chunk-DWED7BS3.js";
|
|
6
|
-
import "../chunk-
|
|
6
|
+
import "../chunk-Z5PL3K7C.js";
|
|
7
7
|
import "../chunk-NKXSILEW.js";
|
|
8
8
|
|
|
9
9
|
// bin/pushary-stop-hook.ts
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// ../contracts/src/index.ts
|
|
2
|
+
var APPROVAL_MODES = ["push_only", "terminal_only", "push_first", "notify_only"];
|
|
3
|
+
var isApprovalMode = (value) => typeof value === "string" && APPROVAL_MODES.includes(value);
|
|
4
|
+
var MATCH_RANKS = ["none", "tool", "prefix", "exact"];
|
|
5
|
+
var matchRankWeight = (rank) => MATCH_RANKS.indexOf(rank);
|
|
6
|
+
var matchToolPattern = (pattern, toolName, arg) => {
|
|
7
|
+
const open = pattern.indexOf("(");
|
|
8
|
+
if (open === -1 || !pattern.endsWith(")")) {
|
|
9
|
+
return pattern === toolName ? "tool" : "none";
|
|
10
|
+
}
|
|
11
|
+
if (pattern.slice(0, open) !== toolName || arg === void 0) return "none";
|
|
12
|
+
const inner = pattern.slice(open + 1, -1);
|
|
13
|
+
if (inner.endsWith(":*")) {
|
|
14
|
+
return arg.startsWith(inner.slice(0, -2)) ? "prefix" : "none";
|
|
15
|
+
}
|
|
16
|
+
return arg === inner ? "exact" : "none";
|
|
17
|
+
};
|
|
18
|
+
var POLICY_ARG_KEYS = {
|
|
19
|
+
Bash: "command",
|
|
20
|
+
Edit: "file_path",
|
|
21
|
+
Write: "file_path"
|
|
22
|
+
};
|
|
23
|
+
var extractPolicyArg = (toolName, toolInput) => {
|
|
24
|
+
const key = POLICY_ARG_KEYS[toolName];
|
|
25
|
+
if (!key) return void 0;
|
|
26
|
+
const value = toolInput[key];
|
|
27
|
+
return typeof value === "string" ? value : void 0;
|
|
28
|
+
};
|
|
29
|
+
var API_KEY_PATTERN = /^pk_[a-f0-9]+\.[a-f0-9]+$/;
|
|
30
|
+
var isValidApiKey = (value) => API_KEY_PATTERN.test(value);
|
|
31
|
+
|
|
32
|
+
export {
|
|
33
|
+
isApprovalMode,
|
|
34
|
+
matchRankWeight,
|
|
35
|
+
matchToolPattern,
|
|
36
|
+
extractPolicyArg,
|
|
37
|
+
isValidApiKey
|
|
38
|
+
};
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import {
|
|
2
|
+
extractPolicyArg,
|
|
3
|
+
isApprovalMode,
|
|
4
|
+
matchRankWeight,
|
|
5
|
+
matchToolPattern
|
|
6
|
+
} from "./chunk-RZLVE57X.js";
|
|
7
|
+
import {
|
|
8
|
+
callMcpTool,
|
|
9
|
+
withRetry
|
|
10
|
+
} from "./chunk-DWED7BS3.js";
|
|
11
|
+
import {
|
|
12
|
+
getBaseUrl
|
|
13
|
+
} from "./chunk-NKXSILEW.js";
|
|
14
|
+
|
|
15
|
+
// src/validate.ts
|
|
16
|
+
var isPolicyConfig = (data) => {
|
|
17
|
+
if (!data || typeof data !== "object") return false;
|
|
18
|
+
const d = data;
|
|
19
|
+
return Array.isArray(d.policies) && typeof d.defaultTimeoutSeconds === "number" && typeof d.defaultTimeoutAction === "string";
|
|
20
|
+
};
|
|
21
|
+
var isAskUserResponse = (data) => {
|
|
22
|
+
if (!data || typeof data !== "object") return false;
|
|
23
|
+
const d = data;
|
|
24
|
+
return typeof d.correlationId === "string" && typeof d.status === "string";
|
|
25
|
+
};
|
|
26
|
+
var isWaitForAnswerResponse = (data) => {
|
|
27
|
+
if (!data || typeof data !== "object") return false;
|
|
28
|
+
const d = data;
|
|
29
|
+
return typeof d.answered === "boolean";
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// src/api.ts
|
|
33
|
+
var askUser = async (apiKey, params) => {
|
|
34
|
+
const result = await callMcpTool(apiKey, "ask_user", { ...params, wait: false }, { maxRetries: 3 });
|
|
35
|
+
if (!isAskUserResponse(result)) throw new Error("Invalid ask_user response");
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
var waitForAnswer = async (apiKey, correlationId, timeoutMs = 3e4) => {
|
|
39
|
+
const result = await callMcpTool(apiKey, "wait_for_answer", {
|
|
40
|
+
correlationId,
|
|
41
|
+
timeoutMs
|
|
42
|
+
});
|
|
43
|
+
if (!isWaitForAnswerResponse(result)) throw new Error("Invalid wait_for_answer response");
|
|
44
|
+
return result;
|
|
45
|
+
};
|
|
46
|
+
var cancelQuestion = async (apiKey, correlationId) => {
|
|
47
|
+
await callMcpTool(apiKey, "cancel_question", { correlationId });
|
|
48
|
+
};
|
|
49
|
+
var sendNotification = async (apiKey, params) => {
|
|
50
|
+
await callMcpTool(apiKey, "send_notification", { ...params }, { maxRetries: 3 });
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// src/policy.ts
|
|
54
|
+
import { createHash } from "crypto";
|
|
55
|
+
import { existsSync, readFileSync, writeFileSync } from "fs";
|
|
56
|
+
import { join } from "path";
|
|
57
|
+
import { tmpdir } from "os";
|
|
58
|
+
var CACHE_TTL_MS = 60 * 1e3;
|
|
59
|
+
var cacheFile = (apiKey) => {
|
|
60
|
+
const hash = createHash("sha256").update(apiKey).digest("hex").slice(0, 12);
|
|
61
|
+
return join(tmpdir(), `pushary-policy-${hash}.json`);
|
|
62
|
+
};
|
|
63
|
+
var fetchPolicy = async (apiKey) => {
|
|
64
|
+
return withRetry(async () => {
|
|
65
|
+
const baseUrl = getBaseUrl();
|
|
66
|
+
const response = await fetch(`${baseUrl}/api/mcp/policy`, {
|
|
67
|
+
headers: { "Authorization": `Bearer ${apiKey}` },
|
|
68
|
+
signal: AbortSignal.timeout(1e4)
|
|
69
|
+
});
|
|
70
|
+
if (!response.ok) {
|
|
71
|
+
throw new Error(`Failed to fetch policy: ${response.status}`);
|
|
72
|
+
}
|
|
73
|
+
const raw = await response.json();
|
|
74
|
+
if (!isPolicyConfig(raw)) throw new Error("Invalid policy response");
|
|
75
|
+
return raw;
|
|
76
|
+
}, { maxAttempts: 2 });
|
|
77
|
+
};
|
|
78
|
+
var getPolicy = async (apiKey, expectedVersion) => {
|
|
79
|
+
const path = cacheFile(apiKey);
|
|
80
|
+
let staleCache = null;
|
|
81
|
+
if (existsSync(path)) {
|
|
82
|
+
try {
|
|
83
|
+
const stat = readFileSync(path, "utf-8");
|
|
84
|
+
const cached = JSON.parse(stat);
|
|
85
|
+
if (!isPolicyConfig(cached)) throw new Error("Corrupted cache");
|
|
86
|
+
const versionStale = expectedVersion != null && (cached._policyVersion ?? null) !== expectedVersion;
|
|
87
|
+
const ttlFresh = !cached._cachedAt || Date.now() - cached._cachedAt < CACHE_TTL_MS;
|
|
88
|
+
if (ttlFresh && !versionStale) {
|
|
89
|
+
return cached;
|
|
90
|
+
}
|
|
91
|
+
staleCache = cached;
|
|
92
|
+
} catch {
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
const policy = await fetchPolicy(apiKey);
|
|
97
|
+
try {
|
|
98
|
+
writeFileSync(path, JSON.stringify({ ...policy, _cachedAt: Date.now(), _policyVersion: expectedVersion ?? null }), "utf-8");
|
|
99
|
+
} catch {
|
|
100
|
+
}
|
|
101
|
+
return policy;
|
|
102
|
+
} catch {
|
|
103
|
+
if (staleCache) return staleCache;
|
|
104
|
+
throw new Error("Failed to fetch policy and no cached policy available");
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
var findBestMatch = (policies, toolName, arg) => {
|
|
108
|
+
let best;
|
|
109
|
+
let bestWeight = 0;
|
|
110
|
+
let bestLength = -1;
|
|
111
|
+
for (const candidate of policies) {
|
|
112
|
+
const rank = matchToolPattern(candidate.tool, toolName, arg);
|
|
113
|
+
if (rank === "none") continue;
|
|
114
|
+
const weight = matchRankWeight(rank);
|
|
115
|
+
const length = rank === "prefix" ? candidate.tool.length : -1;
|
|
116
|
+
if (weight > bestWeight || weight === bestWeight && length > bestLength) {
|
|
117
|
+
best = candidate;
|
|
118
|
+
bestWeight = weight;
|
|
119
|
+
bestLength = length;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return best;
|
|
123
|
+
};
|
|
124
|
+
var resolvePolicy = (config, toolName, modeOverride, toolInput) => {
|
|
125
|
+
const arg = toolInput ? extractPolicyArg(toolName, toolInput) : void 0;
|
|
126
|
+
const base = findBestMatch(config.policies, toolName, arg) ?? config.policies.find((p) => p.tool === "*") ?? {
|
|
127
|
+
tool: toolName,
|
|
128
|
+
timeoutSeconds: config.defaultTimeoutSeconds,
|
|
129
|
+
timeoutAction: config.defaultTimeoutAction,
|
|
130
|
+
mode: config.defaultMode ?? "push_first",
|
|
131
|
+
pushFirstSeconds: config.defaultPushFirstSeconds ?? 20
|
|
132
|
+
};
|
|
133
|
+
const effectiveOverride = modeOverride ?? config.modeOverride;
|
|
134
|
+
if (effectiveOverride) {
|
|
135
|
+
return { ...base, mode: effectiveOverride };
|
|
136
|
+
}
|
|
137
|
+
return base;
|
|
138
|
+
};
|
|
139
|
+
var toPolicyVersion = (value) => typeof value === "string" || typeof value === "number" ? String(value) : null;
|
|
140
|
+
var fetchModeState = async (apiKey, sessionId) => {
|
|
141
|
+
try {
|
|
142
|
+
const baseUrl = getBaseUrl();
|
|
143
|
+
const url = sessionId ? `${baseUrl}/api/mcp/mode?session=${encodeURIComponent(sessionId)}` : `${baseUrl}/api/mcp/mode`;
|
|
144
|
+
const response = await fetch(url, {
|
|
145
|
+
headers: { "Authorization": `Bearer ${apiKey}` },
|
|
146
|
+
signal: AbortSignal.timeout(3e3)
|
|
147
|
+
});
|
|
148
|
+
if (!response.ok) return { mode: null, kill: false, policyVersion: null };
|
|
149
|
+
const data = await response.json();
|
|
150
|
+
const mode = data.override?.mode;
|
|
151
|
+
return {
|
|
152
|
+
mode: isApprovalMode(mode) ? mode : null,
|
|
153
|
+
kill: data.kill === true,
|
|
154
|
+
policyVersion: toPolicyVersion(data.policyVersion)
|
|
155
|
+
};
|
|
156
|
+
} catch {
|
|
157
|
+
return { mode: null, kill: false, policyVersion: null };
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
var fetchModeOverride = async (apiKey) => (await fetchModeState(apiKey)).mode;
|
|
161
|
+
|
|
162
|
+
// src/describe.ts
|
|
163
|
+
import { isAbsolute, relative } from "path";
|
|
164
|
+
var hookPrefixes = {
|
|
165
|
+
Bash: (input) => `bash: ${input.command ?? "(no command)"}`,
|
|
166
|
+
Write: (input) => `write file: ${input.file_path ?? "(unknown path)"}`,
|
|
167
|
+
Edit: (input) => `edit file: ${input.file_path ?? "(unknown path)"}`,
|
|
168
|
+
Read: (input) => `read file: ${input.file_path ?? "(unknown path)"}`
|
|
169
|
+
};
|
|
170
|
+
var eventPrefixes = {
|
|
171
|
+
Bash: (input) => `ran: ${String(input.command ?? "").slice(0, 120)}`,
|
|
172
|
+
Write: (input) => `wrote: ${input.file_path ?? "unknown"}`,
|
|
173
|
+
Edit: (input) => `edited: ${input.file_path ?? "unknown"}`,
|
|
174
|
+
Read: (input) => `read: ${input.file_path ?? "unknown"}`
|
|
175
|
+
};
|
|
176
|
+
var describeToolCall = (toolName, toolInput, format = "hook") => {
|
|
177
|
+
const prefixes = format === "hook" ? hookPrefixes : eventPrefixes;
|
|
178
|
+
const builder = prefixes[toolName];
|
|
179
|
+
if (builder) return builder(toolInput);
|
|
180
|
+
return format === "hook" ? `${toolName}: ${JSON.stringify(toolInput).slice(0, 200)}` : `${toolName}: done`;
|
|
181
|
+
};
|
|
182
|
+
var TOOL_TARGET_MAX_LENGTH = 80;
|
|
183
|
+
var deriveCommandHead = (command) => {
|
|
184
|
+
if (typeof command !== "string") return void 0;
|
|
185
|
+
const head = command.trim().split(/\s+/).slice(0, 2).join(" ");
|
|
186
|
+
return head ? head.slice(0, TOOL_TARGET_MAX_LENGTH) : void 0;
|
|
187
|
+
};
|
|
188
|
+
var deriveToolTarget = (toolName, toolInput) => {
|
|
189
|
+
if (toolName === "Bash") {
|
|
190
|
+
return deriveCommandHead(toolInput.command);
|
|
191
|
+
}
|
|
192
|
+
if (toolName === "Edit" || toolName === "Write") {
|
|
193
|
+
const filePath = toolInput.file_path;
|
|
194
|
+
if (typeof filePath !== "string") return void 0;
|
|
195
|
+
const separator = Math.max(filePath.lastIndexOf("/"), filePath.lastIndexOf("\\"));
|
|
196
|
+
const base = filePath.slice(separator + 1);
|
|
197
|
+
const dot = base.lastIndexOf(".");
|
|
198
|
+
if (dot <= 0) return void 0;
|
|
199
|
+
return base.slice(dot).slice(0, TOOL_TARGET_MAX_LENGTH);
|
|
200
|
+
}
|
|
201
|
+
return void 0;
|
|
202
|
+
};
|
|
203
|
+
var RECEIPT_TARGET_MAX_LENGTH = 256;
|
|
204
|
+
var isToolResultError = (toolResult) => {
|
|
205
|
+
try {
|
|
206
|
+
return Boolean(toolResult && ("error" in toolResult || "is_error" in toolResult));
|
|
207
|
+
} catch {
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
var relativizeReceiptPath = (filePath, cwd) => {
|
|
212
|
+
if (!cwd || !isAbsolute(filePath)) return filePath;
|
|
213
|
+
return relative(cwd, filePath);
|
|
214
|
+
};
|
|
215
|
+
var deriveReceiptMeta = (toolName, toolInput, toolResult, cwd) => {
|
|
216
|
+
try {
|
|
217
|
+
const ok = !isToolResultError(toolResult);
|
|
218
|
+
if (toolName === "Edit" || toolName === "Write") {
|
|
219
|
+
const filePath = toolInput.file_path;
|
|
220
|
+
if (typeof filePath !== "string" || !filePath) return void 0;
|
|
221
|
+
return {
|
|
222
|
+
kind: toolName === "Edit" ? "edit" : "write",
|
|
223
|
+
target: relativizeReceiptPath(filePath, cwd).slice(0, RECEIPT_TARGET_MAX_LENGTH),
|
|
224
|
+
ok
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
if (toolName === "Bash") {
|
|
228
|
+
const head = deriveCommandHead(toolInput.command);
|
|
229
|
+
if (!head) return void 0;
|
|
230
|
+
return {
|
|
231
|
+
kind: head === "git commit" ? "commit" : "bash",
|
|
232
|
+
target: head,
|
|
233
|
+
ok
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
return void 0;
|
|
237
|
+
} catch {
|
|
238
|
+
return void 0;
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
// src/identity.ts
|
|
243
|
+
import { createHash as createHash2 } from "crypto";
|
|
244
|
+
import { hostname } from "os";
|
|
245
|
+
var deriveMachineId = (host) => createHash2("sha256").update(host).digest("hex").slice(0, 8);
|
|
246
|
+
var getMachineId = () => deriveMachineId(hostname());
|
|
247
|
+
|
|
248
|
+
// src/pending.ts
|
|
249
|
+
import { join as join2 } from "path";
|
|
250
|
+
import { tmpdir as tmpdir2 } from "os";
|
|
251
|
+
import { existsSync as existsSync2, mkdirSync, writeFileSync as writeFileSync2, readdirSync, unlinkSync, rmSync, statSync } from "fs";
|
|
252
|
+
var PENDING_DIR = join2(tmpdir2(), "pushary-pending");
|
|
253
|
+
var DEFAULT_SESSION = "_no_session";
|
|
254
|
+
var GRACE_MS = 10 * 60 * 1e3;
|
|
255
|
+
var sanitize = (sessionId) => sessionId.replace(/[^A-Za-z0-9_-]/g, "_").slice(0, 128) || DEFAULT_SESSION;
|
|
256
|
+
var dirFor = (sessionId) => join2(PENDING_DIR, sanitize(sessionId));
|
|
257
|
+
var isDefaultSession = (sessionId) => sanitize(sessionId) === DEFAULT_SESSION;
|
|
258
|
+
var savePendingQuestion = (sessionId, correlationId) => {
|
|
259
|
+
const dir = dirFor(sessionId);
|
|
260
|
+
if (!existsSync2(dir)) mkdirSync(dir, { recursive: true });
|
|
261
|
+
writeFileSync2(join2(dir, correlationId), "", "utf-8");
|
|
262
|
+
};
|
|
263
|
+
var listPendingQuestions = (sessionId) => {
|
|
264
|
+
const dir = dirFor(sessionId);
|
|
265
|
+
let files;
|
|
266
|
+
try {
|
|
267
|
+
files = readdirSync(dir);
|
|
268
|
+
} catch {
|
|
269
|
+
return [];
|
|
270
|
+
}
|
|
271
|
+
if (!isDefaultSession(sessionId)) return files;
|
|
272
|
+
const cutoff = Date.now() - GRACE_MS;
|
|
273
|
+
return files.filter((name) => {
|
|
274
|
+
try {
|
|
275
|
+
return statSync(join2(dir, name)).mtimeMs < cutoff;
|
|
276
|
+
} catch {
|
|
277
|
+
return false;
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
};
|
|
281
|
+
var removePendingQuestion = (sessionId, correlationId) => {
|
|
282
|
+
try {
|
|
283
|
+
unlinkSync(join2(dirFor(sessionId), correlationId));
|
|
284
|
+
} catch {
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
var removePendingSession = (sessionId) => {
|
|
288
|
+
try {
|
|
289
|
+
rmSync(dirFor(sessionId), { recursive: true, force: true });
|
|
290
|
+
} catch {
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
export {
|
|
295
|
+
isPolicyConfig,
|
|
296
|
+
askUser,
|
|
297
|
+
waitForAnswer,
|
|
298
|
+
cancelQuestion,
|
|
299
|
+
sendNotification,
|
|
300
|
+
getPolicy,
|
|
301
|
+
resolvePolicy,
|
|
302
|
+
fetchModeState,
|
|
303
|
+
fetchModeOverride,
|
|
304
|
+
describeToolCall,
|
|
305
|
+
deriveToolTarget,
|
|
306
|
+
isToolResultError,
|
|
307
|
+
deriveReceiptMeta,
|
|
308
|
+
getMachineId,
|
|
309
|
+
DEFAULT_SESSION,
|
|
310
|
+
isDefaultSession,
|
|
311
|
+
savePendingQuestion,
|
|
312
|
+
listPendingQuestions,
|
|
313
|
+
removePendingQuestion,
|
|
314
|
+
removePendingSession
|
|
315
|
+
};
|