@pushary/agent-hooks 1.9.150 → 1.9.151
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 +9 -0
- package/data/openclaw-plugin/README.md +39 -2
- package/data/openclaw-plugin/dist/approval-hook.js +8 -4
- package/data/openclaw-plugin/dist/approval-question.js +100 -33
- package/data/openclaw-plugin/dist/command-preview.js +65 -0
- package/data/openclaw-plugin/dist/file-change-preview.js +109 -0
- package/data/openclaw-plugin/dist/gate-result.js +11 -4
- package/data/openclaw-plugin/dist/parameter-redaction.js +28 -0
- package/data/openclaw-plugin/dist/protected-writes.js +18 -4
- package/data/openclaw-plugin/dist/settings.js +7 -1
- package/data/openclaw-plugin/dist/visible-text.js +5 -0
- package/data/openclaw-plugin/openclaw.plugin.json +1 -1
- package/data/openclaw-plugin/package.json +1 -1
- package/dist/bin/pushary-clean.js +1 -1
- package/dist/bin/pushary-codex-hook.js +1 -1
- package/dist/bin/pushary-daemon.js +2 -2
- package/dist/bin/pushary-doctor.js +3 -3
- package/dist/bin/pushary-session-start-hook.js +2 -2
- package/dist/bin/pushary-setup.js +3 -3
- package/dist/bin/pushary-upgrade.js +3 -3
- package/dist/{chunk-BDF74W2U.js → chunk-DNK4E5CE.js} +1 -1
- package/dist/{chunk-53URUFUJ.js → chunk-FSEOIGZX.js} +1 -1
- package/dist/{chunk-TR35RG7D.js → chunk-RJAQ2447.js} +14 -3
- package/dist/{chunk-KACTUGKV.js → chunk-WQ66RQRF.js} +1 -1
- package/dist/{reapply-UKREFK55.js → reapply-AFG7K4KS.js} +2 -2
- package/package.json +1 -1
- package/data/cursor-plugin/scripts/pushary-gate.test.mjs +0 -150
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.9.151
|
|
4
|
+
|
|
5
|
+
- This CLI carries the OpenClaw plugin 0.1.3. An `exec` approval now shows the environment the call sets and every other parameter, such as `host`, `node`, `security` and `ask`, before the command, and the question names the environment variables. Before, it showed only the command, so a `git status` with `GIT_CONFIG_*` variables could run another command after one yes. Values named like a credential are redacted.
|
|
6
|
+
- The plugin asks before a `write`, `edit` or `apply_patch` into the workspace `.openclaw` folder, for every spelling of the path. OpenClaw loads plugins from `<workspace>/.openclaw/extensions` before the installed ones, so an agent could otherwise put its own plugin with the id `pushary` there and switch off the gate at the next gateway start.
|
|
7
|
+
- The plugin asks before every `sessions_spawn` with `runtime: "acp"`, whose harness runs its own tools where the plugin cannot see them, and before every `nodes` action except its reads, including `run` on a paired machine and `approve` for a new one.
|
|
8
|
+
- The plugin 0.1.2 changes reach setup too. A gated call longer than 4,000 characters once secrets are redacted is blocked instead of being asked about in part. A file change shows the path and the lines it removes and adds. A `.env` file's values are never sent. Hidden characters are shown as codes.
|
|
9
|
+
- `pushary upgrade` tries the OpenClaw plugin reinstall again when OpenClaw refused it the last time. Before, it recorded the new copy as installed before OpenClaw accepted it, so a refused reinstall kept the older plugin until a later CLI carried another one.
|
|
10
|
+
- The editor plugins this CLI carries no longer include their test files.
|
|
11
|
+
|
|
3
12
|
## 1.9.150
|
|
4
13
|
|
|
5
14
|
- Claude Code: the `PermissionRequest` hook allows Pushary's own tools, under `mcp__pushary__`, the claude.ai Pushary connector (`mcp__claude_ai_Pushary__`) and the Pushary plugin (`mcp__plugin_pushary_pushary__`), without a key and without asking pushary.com. Before, it left `mcp__pushary__` to Claude Code's own prompt and judged the other two like any tool. Claude Code adds your claude.ai connectors to every session, so with this CLI's hooks installed and the connector enabled, its prompt for the connector's `ask_user` could push an approval for Pushary's own question to your phone, and a standing `*` deny refused it. A plugin user, who has no allow rule from setup, would have had the prompt for the agent's own question wait in the terminal while they were away. The `PermissionDenied` hook leaves all three alone. `PreToolUse` is unchanged.
|
|
@@ -6,6 +6,8 @@ It is built for an OpenClaw that runs for you alone, often always on, on a small
|
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
|
+
### With the Pushary CLI (recommended)
|
|
10
|
+
|
|
9
11
|
Run the Pushary CLI on the machine that runs OpenClaw, as the user the gateway runs as:
|
|
10
12
|
|
|
11
13
|
```bash
|
|
@@ -33,6 +35,17 @@ If the gateway runs as another user, or as a service without that home folder, p
|
|
|
33
35
|
PUSHARY_API_KEY=pk_your_key
|
|
34
36
|
```
|
|
35
37
|
|
|
38
|
+
### From ClawHub or npm
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
openclaw plugins install @pushary/openclaw # ClawHub
|
|
42
|
+
openclaw plugins install npm:@pushary/openclaw # npm
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Then give it a key. Create one at [pushary.com/dashboard/agent/settings](https://pushary.com/dashboard/agent/settings), add `PUSHARY_API_KEY=pk_your_key` to `~/.openclaw/.env`, connect your phone on the same page, and restart the gateway. Until it has a key, every gated call is blocked and the reason says how to add one. `openclaw plugins update pushary` follows newer releases.
|
|
46
|
+
|
|
47
|
+
Running `pushary setup` later installs the CLI's own copy over a ClawHub or npm install. Both use the plugin id `pushary`, so only one is ever loaded.
|
|
48
|
+
|
|
36
49
|
## What it gates
|
|
37
50
|
|
|
38
51
|
- Every `exec` call.
|
|
@@ -41,8 +54,10 @@ PUSHARY_API_KEY=pk_your_key
|
|
|
41
54
|
|
|
42
55
|
- Every `automations` (also called `cron`) action except `status`, `list`, `get`, `runs` and `next_check`. A scheduled job can run a command outside `before_tool_call`, so adding, changing, running or waking one asks.
|
|
43
56
|
- Every `terminal` action except `read` and `list`. `terminal input` types into a shared operator terminal.
|
|
44
|
-
-
|
|
45
|
-
- Every `
|
|
57
|
+
- Every `nodes` action except the reads: `status`, `describe`, `pending`, `notify`, `camera_list`, `notifications_list` and the `device_*` reads. `nodes run` runs a command on a paired machine, `approve` pairs a new one, and the camera, screen and location actions take data from it.
|
|
58
|
+
- Every `sessions_spawn` with `runtime: "acp"`. An ACP session runs Codex, Claude Code or another harness, whose own tool calls never reach this plugin, so starting one asks.
|
|
59
|
+
- A `sessions_spawn` with a `cwd` outside the agent's workspace or in its `hooks` or `.openclaw` folder, or with a `projectId`, `projectGitUrl` or `worktree`. The question names the folder.
|
|
60
|
+
- Every `write`, `edit` or `apply_patch` into OpenClaw's own files: anything inside an OpenClaw state directory, `~/.config/openclaw` (where Linux keeps `gateway.env`), `~/.pushary`, the `.env` in the gateway's working folder, the config file set by `OPENCLAW_CONFIG_PATH`, and the launchd and systemd files OpenClaw installs for its gateway. The one exception is the agent's own workspace when it lives inside the state directory, which is OpenClaw's default (`~/.openclaw/workspace`). The workspace `hooks` and `.openclaw` folders always ask, wherever the workspace is, because OpenClaw loads code from them: hooks from `hooks`, and plugins from `.openclaw/extensions`, which it finds before the installed ones. The plugin resolves `~`, `@` references, `file://` paths, relative paths against the agent's workspace, and symlinks before it decides, and a path it cannot resolve asks. Writes anywhere else run without asking.
|
|
46
61
|
|
|
47
62
|
To gate more tools, list their OpenClaw tool ids. The list adds to the defaults above; it never replaces them:
|
|
48
63
|
|
|
@@ -72,10 +87,31 @@ Ids are read the way OpenClaw names its tools: `bash` means `exec`, `cron` means
|
|
|
72
87
|
| The agent was stopped from Pushary | Blocked |
|
|
73
88
|
| No phone, browser or Slack is connected | Blocked, with a link to connect one |
|
|
74
89
|
| Pushary cannot be reached, rejects the key or sends a reply the plugin cannot read | Blocked |
|
|
90
|
+
| The call is longer than 4,000 characters once secrets are redacted | Blocked without asking, because Pushary could not show all of it |
|
|
75
91
|
| Your delivery mode keeps approvals off the phone, or a When away push window passes with no answer | Withdrawn in Pushary and handed to OpenClaw's own approval prompt, which blocks the call when nobody can answer there. On an OpenClaw older than 2026.11.3 the call is blocked instead |
|
|
76
92
|
|
|
77
93
|
A missing answer never becomes an approval. A plugin error or timeout blocks the call: OpenClaw fails closed when a `before_tool_call` hook throws or runs out of time, and the plugin turns its own errors into a block rather than relying on that.
|
|
78
94
|
|
|
95
|
+
## What is sent to Pushary
|
|
96
|
+
|
|
97
|
+
For each gated call, the plugin sends one `ask_user` request to `https://pushary.com/api/mcp/mcp`, with your key in the `Authorization` header. It holds:
|
|
98
|
+
|
|
99
|
+
- **The question.** For a command, its first 160 characters, with a note when the command is longer. For a file change, the path. This is what the notification shows; open the request to read the whole call before you answer.
|
|
100
|
+
- **The full call.** For `exec`, the whole command, and before it the environment it sets and every other parameter, such as `host`, `node`, `security` and `ask`. The question names the environment variables. For `write`, `edit` and `apply_patch`, the path, the number of lines or changes, and the lines removed and added. For every other tool, its parameters as JSON.
|
|
101
|
+
- **Where it comes from.** The agent name (`OpenClaw`, or `OpenClaw - <agent id>`), the tool name, the working directory and whether it asked for elevated mode, the OpenClaw session id or key (hashed when it is longer than 128 characters), a machine id (the one `pushary setup` saved in `~/.pushary/machine-id`, or else a hash of the host name), a random request id, and when the plugin stops waiting.
|
|
102
|
+
|
|
103
|
+
Before anything is sent, the plugin removes what it can recognise as a secret:
|
|
104
|
+
|
|
105
|
+
- Key and token formats it knows: Pushary keys, `sk-` keys (OpenAI, Anthropic), Stripe, GitHub, GitLab, Slack, Google, AWS access key ids, npm, xAI and JWTs, plus private key blocks and long base64-like strings of 40 or more characters.
|
|
106
|
+
- Passwords in URLs, `Bearer` and `Authorization` values, and the value of anything named like a password, token, secret, API key, access key, client secret or private key. In JSON this holds at any depth, whatever the value.
|
|
107
|
+
- Every value in a `.env` file (`.env`, `.env.*` or a name ending in `.env`, such as `gateway.env`). Only the variable names are sent.
|
|
108
|
+
|
|
109
|
+
Redaction works from these patterns. A secret in a command that matches none of them, such as a password with spaces passed to a flag of its own, is sent as written. The plugin leaves the rest of a command as it is so you can see what will run.
|
|
110
|
+
|
|
111
|
+
Characters you could not see, such as zero-width spaces, text direction overrides and terminal escape codes, are sent as visible codes like `\u{202E}`.
|
|
112
|
+
|
|
113
|
+
While it waits, the plugin sends only the question id, to check for your answer or to withdraw the question. It sends no analytics and talks to no other host.
|
|
114
|
+
|
|
79
115
|
## How long it waits
|
|
80
116
|
|
|
81
117
|
The plugin asks OpenClaw for a five minute `before_tool_call` budget and stops waiting ten seconds before it, so it has time to withdraw the question. If you set `plugins.entries.pushary.hooks.timeouts.before_tool_call` or `hooks.timeoutMs`, the plugin reads that value and ends its wait before it instead.
|
|
@@ -99,6 +135,7 @@ Clean uninstalls the plugin and puts back the `plugins.entries.pushary` settings
|
|
|
99
135
|
|
|
100
136
|
- The gate covers the tools listed above and any you add. It does not see other tools: for example the file-transfer plugin's `file_write` is not gated unless you add it to `gatedTools`.
|
|
101
137
|
- ACP sessions set to approve everything, and CLI backends, run tools inside the external harness. Those tool calls never reach `before_tool_call`, so the plugin cannot gate them.
|
|
138
|
+
- A command that runs a script file shows the command, not what the script contains. A call longer than 4,000 characters is blocked, so an agent may split it this way: read the script before you approve it.
|
|
102
139
|
- This is an approval layer, not a sandbox. Pair it with OpenClaw's own sandboxing and `tools.fs.workspaceOnly`.
|
|
103
140
|
- The plugin talks only to `https://pushary.com` and `https://www.pushary.com`, the hosts the CLI uses. Any other `PUSHARY_BASE_URL` blocks every gated call, so a changed setting cannot point it at a server that always says yes.
|
|
104
141
|
- The plugin is not told which folder a tool runs in. It resolves a relative path against the agent's workspace, any folder inside it, and the gateway's working folder, and a spawned session in any other folder asks first. A run started some other way in a folder inside OpenClaw's state is not covered.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
-
import {
|
|
2
|
+
import { approvalPreviewFor } from './approval-question.js';
|
|
3
3
|
import { runApprovalGate } from './gate.js';
|
|
4
|
-
import { notConnectedResultFor, openClawResultFor } from './gate-result.js';
|
|
4
|
+
import { notConnectedResultFor, openClawResultFor, tooLongToReviewResultFor } from './gate-result.js';
|
|
5
5
|
import { holdMsWithin, hookBudgetFrom, REQUESTED_HOOK_TIMEOUT_MS } from './hook-budget.js';
|
|
6
6
|
import { BEFORE_TOOL_CALL_HOOK, } from './host-api.js';
|
|
7
7
|
import { handsBackToTheHost, hostSupportFrom, MIN_HOST_VERSION } from './host-version.js';
|
|
@@ -20,10 +20,14 @@ export const createApprovalGateHandler = (options, environment) => async (event,
|
|
|
20
20
|
if (!needsApproval(options.settings, event) && !reachesOpenClawState)
|
|
21
21
|
return undefined;
|
|
22
22
|
const agentName = askingAgentName(context.agentId);
|
|
23
|
-
const
|
|
23
|
+
const preview = approvalPreviewFor(event, agentName);
|
|
24
24
|
const reading = environment.readConnection();
|
|
25
|
+
const toolName = preview.kind === 'reviewable' ? preview.question.toolName : preview.toolName;
|
|
25
26
|
if (reading.kind !== 'ready')
|
|
26
|
-
return notConnectedResultFor(reading.kind,
|
|
27
|
+
return notConnectedResultFor(reading.kind, toolName);
|
|
28
|
+
if (preview.kind === 'too_long')
|
|
29
|
+
return tooLongToReviewResultFor(toolName, preview.length);
|
|
30
|
+
const { question } = preview;
|
|
27
31
|
const sessionId = sessionIdOf(context);
|
|
28
32
|
const outcome = await runApprovalGate({
|
|
29
33
|
question,
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { commandPreviewOf } from './command-preview.js';
|
|
2
|
+
import { fileChangePreviewOf } from './file-change-preview.js';
|
|
3
|
+
import { serializedWithCredentialsRedacted } from './parameter-redaction.js';
|
|
1
4
|
import { redactSecrets, redactSecretsDeep } from './redaction.js';
|
|
2
|
-
import { SESSIONS_SPAWN_TOOL, SPAWN_FOLDER_PARAMETER } from './protected-writes.js';
|
|
3
|
-
import { AGENT_LABEL } from './settings.js';
|
|
5
|
+
import { SESSIONS_SPAWN_TOOL, SPAWN_FOLDER_PARAMETER, startsAnAcpSession } from './protected-writes.js';
|
|
6
|
+
import { AGENT_LABEL, hostToolId } from './settings.js';
|
|
7
|
+
import { withHiddenCharactersShown } from './visible-text.js';
|
|
4
8
|
export const QUESTION_SUMMARY_MAX = 160;
|
|
5
9
|
export const CONTEXT_MAX = 500;
|
|
6
10
|
export const ACTION_MAX = 500;
|
|
@@ -9,58 +13,121 @@ export const TOOL_TARGET_MAX = 80;
|
|
|
9
13
|
export const TOOL_NAME_MAX = 100;
|
|
10
14
|
export const APPROVAL_TITLE_MAX = 80;
|
|
11
15
|
export const APPROVAL_DESCRIPTION_MAX = 512;
|
|
12
|
-
const COMMAND_PARAMETERS = ['command', 'code'];
|
|
13
16
|
const WORKDIR_PARAMETER = 'workdir';
|
|
17
|
+
const ELEVATED_PARAMETER = 'elevated';
|
|
18
|
+
const SPAWN_AGENT_PARAMETER = 'agentId';
|
|
19
|
+
const PARAMETERS_THE_CONTEXT_SHOWS = [WORKDIR_PARAMETER, ELEVATED_PARAMETER];
|
|
14
20
|
const TARGET_WORDS = 2;
|
|
15
21
|
const ELLIPSIS = '…';
|
|
16
22
|
const collapsed = (text) => text.split(/\s+/).filter(Boolean).join(' ');
|
|
17
23
|
export const truncated = (text, max) => text.length <= max ? text : `${text.slice(0, max - ELLIPSIS.length)}${ELLIPSIS}`;
|
|
24
|
+
export const characterCount = (length) => length.toLocaleString('en-US');
|
|
18
25
|
const stringParameter = (params, name) => {
|
|
19
26
|
const value = params[name];
|
|
20
27
|
return typeof value === 'string' && value.trim().length > 0 ? value : undefined;
|
|
21
28
|
};
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
return
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return '';
|
|
29
|
+
const describedCall = (event) => {
|
|
30
|
+
const preview = commandPreviewOf(event.params, PARAMETERS_THE_CONTEXT_SHOWS);
|
|
31
|
+
if (preview !== null)
|
|
32
|
+
return { kind: 'command', preview };
|
|
33
|
+
const change = fileChangePreviewOf(hostToolId(event.toolName), event.params);
|
|
34
|
+
if (change !== null)
|
|
35
|
+
return { kind: 'file_change', change };
|
|
36
|
+
const visible = withHiddenCharactersShown(serializedWithCredentialsRedacted(event.params));
|
|
37
|
+
return { kind: 'parameters', line: redactSecrets(visible), body: redactSecretsDeep(visible) };
|
|
38
|
+
};
|
|
39
|
+
const READ_IT_ALL = 'Read all of it before you answer.';
|
|
40
|
+
const shortenedNote = (what, length) => ` Shortened here: the ${what} is ${characterCount(length)} characters. ${READ_IT_ALL}`;
|
|
41
|
+
const summaryOf = (line) => {
|
|
42
|
+
const whole = collapsed(line);
|
|
43
|
+
return { text: truncated(whole, QUESTION_SUMMARY_MAX), shortened: whole.length > QUESTION_SUMMARY_MAX };
|
|
44
|
+
};
|
|
45
|
+
const hasMoreThanTheCommand = (preview) => preview.environmentNames.length > 0 || preview.otherParameters !== null;
|
|
46
|
+
const commandQuestion = (preview) => {
|
|
47
|
+
const summary = summaryOf(preview.command);
|
|
48
|
+
const extras = hasMoreThanTheCommand(preview);
|
|
49
|
+
const environment = preview.environmentNames.length > 0 ? ` with ${truncated(preview.environmentNames.join(', '), QUESTION_SUMMARY_MAX)} set` : '';
|
|
50
|
+
const note = summary.shortened
|
|
51
|
+
? shortenedNote(extras ? 'full call' : 'command', preview.body.length)
|
|
52
|
+
: extras ? ' Read the full call before you answer.' : '';
|
|
53
|
+
return `Allow ${AGENT_LABEL} to run \`${summary.text}\`${environment}?${note}`;
|
|
54
|
+
};
|
|
55
|
+
const quotedList = (paths) => truncated(paths.map(path => `\`${collapsed(path)}\``).join(', '), QUESTION_SUMMARY_MAX);
|
|
56
|
+
const fileChangeQuestion = (change) => {
|
|
57
|
+
const targets = quotedList(change.paths);
|
|
58
|
+
const asked = change.operation === 'patch' ? `apply a patch to ${targets}` : `${change.operation} ${targets}`;
|
|
59
|
+
return `Allow ${AGENT_LABEL} to ${asked}? Read the change before you answer.`;
|
|
60
|
+
};
|
|
61
|
+
const quotedForQuestion = (text) => `\`${truncated(collapsed(redactSecrets(withHiddenCharactersShown(text))), QUESTION_SUMMARY_MAX)}\``;
|
|
62
|
+
const spawnQuestion = (event, note) => {
|
|
63
|
+
if (event.toolName !== SESSIONS_SPAWN_TOOL)
|
|
64
|
+
return null;
|
|
65
|
+
const folder = stringParameter(event.params, SPAWN_FOLDER_PARAMETER);
|
|
66
|
+
const where = folder === undefined ? '' : ` in ${quotedForQuestion(folder)}`;
|
|
67
|
+
if (startsAnAcpSession(event.params)) {
|
|
68
|
+
const agent = stringParameter(event.params, SPAWN_AGENT_PARAMETER);
|
|
69
|
+
const harness = agent === undefined ? '' : ` with ${quotedForQuestion(agent)}`;
|
|
70
|
+
return `Allow ${AGENT_LABEL} to start an outside agent session (ACP)${harness}${where}? Pushary does not see the tool calls that session makes.${note}`;
|
|
29
71
|
}
|
|
72
|
+
return folder === undefined ? null : `Allow ${AGENT_LABEL} to start a session${where}?${note}`;
|
|
73
|
+
};
|
|
74
|
+
const parametersQuestion = (toolName, description, event) => {
|
|
75
|
+
const summary = summaryOf(description.line);
|
|
76
|
+
const note = summary.shortened ? shortenedNote('request', description.body.length) : '';
|
|
77
|
+
return spawnQuestion(event, note) ?? `Allow ${AGENT_LABEL} to use ${toolName}${summary.text ? `: \`${summary.text}\`` : ''}?${note}`;
|
|
30
78
|
};
|
|
31
|
-
const questionFor = (toolName,
|
|
32
|
-
if (
|
|
33
|
-
return
|
|
34
|
-
if (
|
|
35
|
-
return
|
|
36
|
-
return
|
|
79
|
+
const questionFor = (toolName, description, event) => {
|
|
80
|
+
if (description.kind === 'command')
|
|
81
|
+
return commandQuestion(description.preview);
|
|
82
|
+
if (description.kind === 'file_change')
|
|
83
|
+
return fileChangeQuestion(description.change);
|
|
84
|
+
return parametersQuestion(toolName, description, event);
|
|
37
85
|
};
|
|
38
|
-
const contextLines = (event, agentName) => {
|
|
86
|
+
const contextLines = (event, agentName, description) => {
|
|
39
87
|
const workdir = stringParameter(event.params, WORKDIR_PARAMETER) ?? stringParameter(event.params, SPAWN_FOLDER_PARAMETER);
|
|
88
|
+
const otherParameters = description.kind === 'command' ? description.preview.otherParameters : null;
|
|
40
89
|
return [
|
|
41
90
|
`${agentName} wants to use its ${event.toolName} tool.`,
|
|
42
91
|
...(workdir ? [`Working directory: ${workdir}`] : []),
|
|
43
|
-
...(event.params
|
|
92
|
+
...(event.params[ELEVATED_PARAMETER] === true ? ['It asked for elevated mode, outside the sandbox.'] : []),
|
|
93
|
+
...(otherParameters === null ? [] : [`Other parameters: ${otherParameters}`]),
|
|
44
94
|
];
|
|
45
95
|
};
|
|
46
|
-
const targetOf = (
|
|
47
|
-
if (
|
|
96
|
+
const targetOf = (description) => {
|
|
97
|
+
if (description.kind !== 'command')
|
|
48
98
|
return undefined;
|
|
49
|
-
const head = collapsed(command).split(' ').slice(0, TARGET_WORDS).join(' ');
|
|
99
|
+
const head = collapsed(description.preview.command).split(' ').slice(0, TARGET_WORDS).join(' ');
|
|
50
100
|
return head ? truncated(head, TOOL_TARGET_MAX) : undefined;
|
|
51
101
|
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
102
|
+
const actionLineOf = (description) => {
|
|
103
|
+
if (description.kind === 'command')
|
|
104
|
+
return description.preview.line;
|
|
105
|
+
if (description.kind === 'file_change')
|
|
106
|
+
return `${description.change.operation} ${description.change.paths.join(', ')}`;
|
|
107
|
+
return description.line;
|
|
108
|
+
};
|
|
109
|
+
const actionBodyOf = (description) => {
|
|
110
|
+
if (description.kind === 'command')
|
|
111
|
+
return description.preview.body;
|
|
112
|
+
if (description.kind === 'file_change')
|
|
113
|
+
return description.change.body;
|
|
114
|
+
return description.body;
|
|
115
|
+
};
|
|
116
|
+
export const approvalPreviewFor = (event, agentName) => {
|
|
117
|
+
const toolName = truncated(withHiddenCharactersShown(event.toolName.trim()), TOOL_NAME_MAX);
|
|
118
|
+
const description = describedCall(event);
|
|
119
|
+
const actionBody = actionBodyOf(description);
|
|
120
|
+
if (actionBody.length > ACTION_BODY_MAX)
|
|
121
|
+
return { kind: 'too_long', toolName, length: actionBody.length };
|
|
58
122
|
return {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
123
|
+
kind: 'reviewable',
|
|
124
|
+
question: {
|
|
125
|
+
question: questionFor(toolName, description, event),
|
|
126
|
+
context: truncated(redactSecrets(withHiddenCharactersShown(contextLines(event, agentName, description).join(' '))), CONTEXT_MAX),
|
|
127
|
+
toolName,
|
|
128
|
+
toolTarget: targetOf(description),
|
|
129
|
+
action: truncated(collapsed(actionLineOf(description)), ACTION_MAX),
|
|
130
|
+
actionBody,
|
|
131
|
+
},
|
|
65
132
|
};
|
|
66
133
|
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { isCredentialName, isRecord, REDACTED_VALUE, serializedWithCredentialsRedacted } from './parameter-redaction.js';
|
|
2
|
+
import { redactSecrets, redactSecretsDeep } from './redaction.js';
|
|
3
|
+
import { withHiddenCharactersShown } from './visible-text.js';
|
|
4
|
+
const COMMAND_PARAMETERS = ['command', 'code'];
|
|
5
|
+
const ENV_PARAMETER = 'env';
|
|
6
|
+
const ASSIGNMENT_SEPARATOR = '=';
|
|
7
|
+
const commandParameterOf = (params) => {
|
|
8
|
+
for (const name of COMMAND_PARAMETERS) {
|
|
9
|
+
const value = params[name];
|
|
10
|
+
if (typeof value === 'string' && value.trim().length > 0)
|
|
11
|
+
return { name, command: value };
|
|
12
|
+
}
|
|
13
|
+
return null;
|
|
14
|
+
};
|
|
15
|
+
const environmentValueText = (value) => typeof value === 'string' ? value : serializedWithCredentialsRedacted(value);
|
|
16
|
+
const environmentEntryOf = (name, value) => ({
|
|
17
|
+
name,
|
|
18
|
+
assignment: `${name}${ASSIGNMENT_SEPARATOR}${isCredentialName(name) ? REDACTED_VALUE : environmentValueText(value)}`,
|
|
19
|
+
});
|
|
20
|
+
const environmentEntryOfAssignment = (assignment) => {
|
|
21
|
+
const separator = assignment.indexOf(ASSIGNMENT_SEPARATOR);
|
|
22
|
+
return separator === -1
|
|
23
|
+
? { name: assignment, assignment }
|
|
24
|
+
: environmentEntryOf(assignment.slice(0, separator), assignment.slice(separator + ASSIGNMENT_SEPARATOR.length));
|
|
25
|
+
};
|
|
26
|
+
const isListOfText = (value) => Array.isArray(value) && value.every(item => typeof item === 'string');
|
|
27
|
+
const environmentOf = (value) => {
|
|
28
|
+
if (isRecord(value))
|
|
29
|
+
return Object.entries(value).map(([name, entry]) => environmentEntryOf(name, entry));
|
|
30
|
+
if (isListOfText(value))
|
|
31
|
+
return value.map(environmentEntryOfAssignment);
|
|
32
|
+
return null;
|
|
33
|
+
};
|
|
34
|
+
const otherParametersOf = (params, skipped) => {
|
|
35
|
+
const others = Object.entries(params).filter(([name]) => !skipped.has(name));
|
|
36
|
+
return others.length === 0 ? null : serializedWithCredentialsRedacted(Object.fromEntries(others));
|
|
37
|
+
};
|
|
38
|
+
const sectionsOf = (environment, otherParameters, command) => {
|
|
39
|
+
if (environment.length === 0 && otherParameters === null)
|
|
40
|
+
return command;
|
|
41
|
+
return [
|
|
42
|
+
...(environment.length > 0 ? ['Environment:', ...environment.map(entry => entry.assignment), ''] : []),
|
|
43
|
+
...(otherParameters === null ? [] : [`Other parameters: ${otherParameters}`, '']),
|
|
44
|
+
'Command:',
|
|
45
|
+
command,
|
|
46
|
+
].join('\n');
|
|
47
|
+
};
|
|
48
|
+
const oneLineOf = (environment, otherParameters, command) => [...environment.map(entry => entry.assignment), command, ...(otherParameters === null ? [] : [`(${otherParameters})`])].join(' ');
|
|
49
|
+
const displayed = (text) => redactSecrets(withHiddenCharactersShown(text));
|
|
50
|
+
export const commandPreviewOf = (params, shownElsewhere) => {
|
|
51
|
+
const found = commandParameterOf(params);
|
|
52
|
+
if (found === null)
|
|
53
|
+
return null;
|
|
54
|
+
const environment = environmentOf(params[ENV_PARAMETER]);
|
|
55
|
+
const skipped = new Set([found.name, ...shownElsewhere, ...(environment === null ? [] : [ENV_PARAMETER])]);
|
|
56
|
+
const entries = environment ?? [];
|
|
57
|
+
const otherParameters = otherParametersOf(params, skipped);
|
|
58
|
+
return {
|
|
59
|
+
command: displayed(found.command),
|
|
60
|
+
line: displayed(oneLineOf(entries, otherParameters, found.command)),
|
|
61
|
+
body: redactSecretsDeep(withHiddenCharactersShown(sectionsOf(entries, otherParameters, found.command))),
|
|
62
|
+
environmentNames: entries.map(entry => displayed(entry.name)),
|
|
63
|
+
otherParameters: otherParameters === null ? null : displayed(otherParameters),
|
|
64
|
+
};
|
|
65
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { basename } from 'node:path';
|
|
2
|
+
import { APPLY_PATCH_TOOL, EDIT_TOOL, patchTargetsOf, WRITE_TOOL } from './protected-writes.js';
|
|
3
|
+
import { redactSecrets, redactSecretsDeep } from './redaction.js';
|
|
4
|
+
import { withHiddenCharactersShown } from './visible-text.js';
|
|
5
|
+
const PATH_PARAMETER = 'path';
|
|
6
|
+
const CONTENT_PARAMETER = 'content';
|
|
7
|
+
const EDITS_PARAMETER = 'edits';
|
|
8
|
+
const PATCH_PARAMETER = 'input';
|
|
9
|
+
const OLD_TEXT_PARAMETER = 'oldText';
|
|
10
|
+
const NEW_TEXT_PARAMETER = 'newText';
|
|
11
|
+
const ENV_FILE_NAME = '.env';
|
|
12
|
+
const ENV_ASSIGNMENT = /^([+\- ]?[ \t]*(?:export[ \t]+)?[A-Za-z_][A-Za-z0-9_.-]*[ \t]*=[ \t]*)\S.*$/gm;
|
|
13
|
+
const HIDDEN_VALUE = '[value not sent]';
|
|
14
|
+
const REMOVED_LINE_PREFIX = '- ';
|
|
15
|
+
const ADDED_LINE_PREFIX = '+ ';
|
|
16
|
+
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
17
|
+
const textParameter = (params, name) => {
|
|
18
|
+
const value = params[name];
|
|
19
|
+
return typeof value === 'string' ? value : undefined;
|
|
20
|
+
};
|
|
21
|
+
const pathParameter = (params) => {
|
|
22
|
+
const path = textParameter(params, PATH_PARAMETER)?.trim();
|
|
23
|
+
return path ? path : undefined;
|
|
24
|
+
};
|
|
25
|
+
export const isEnvFile = (path) => {
|
|
26
|
+
const name = basename(path.trim()).toLowerCase();
|
|
27
|
+
return name.endsWith(ENV_FILE_NAME) || name.startsWith(`${ENV_FILE_NAME}.`);
|
|
28
|
+
};
|
|
29
|
+
const withEnvValuesHidden = (text) => text.replace(ENV_ASSIGNMENT, `$1${HIDDEN_VALUE}`);
|
|
30
|
+
const sendableText = (text, hidesEnvValues) => {
|
|
31
|
+
const visible = withHiddenCharactersShown(text);
|
|
32
|
+
return redactSecretsDeep(hidesEnvValues ? withEnvValuesHidden(visible) : visible);
|
|
33
|
+
};
|
|
34
|
+
const sendablePath = (path) => redactSecrets(withHiddenCharactersShown(path));
|
|
35
|
+
const lineCountOf = (text) => {
|
|
36
|
+
if (text.length === 0)
|
|
37
|
+
return 0;
|
|
38
|
+
const lines = text.split('\n').length;
|
|
39
|
+
return text.endsWith('\n') ? lines - 1 : lines;
|
|
40
|
+
};
|
|
41
|
+
const plural = (count, word) => `${count} ${word}${count === 1 ? '' : 's'}`;
|
|
42
|
+
const prefixedLines = (text, prefix) => text.split('\n').map(line => `${prefix}${line}`).join('\n');
|
|
43
|
+
const textEditOf = (value) => {
|
|
44
|
+
if (!isRecord(value))
|
|
45
|
+
return null;
|
|
46
|
+
const oldText = textParameter(value, OLD_TEXT_PARAMETER);
|
|
47
|
+
const newText = textParameter(value, NEW_TEXT_PARAMETER);
|
|
48
|
+
return oldText === undefined || newText === undefined ? null : { oldText, newText };
|
|
49
|
+
};
|
|
50
|
+
const textEditsOf = (params) => {
|
|
51
|
+
const listed = params[EDITS_PARAMETER];
|
|
52
|
+
const candidates = Array.isArray(listed) ? listed : [params];
|
|
53
|
+
const edits = [];
|
|
54
|
+
for (const candidate of candidates) {
|
|
55
|
+
const edit = textEditOf(candidate);
|
|
56
|
+
if (edit === null)
|
|
57
|
+
return null;
|
|
58
|
+
edits.push(edit);
|
|
59
|
+
}
|
|
60
|
+
return edits.length > 0 ? edits : null;
|
|
61
|
+
};
|
|
62
|
+
const writePreviewOf = (params) => {
|
|
63
|
+
const path = pathParameter(params);
|
|
64
|
+
const content = textParameter(params, CONTENT_PARAMETER);
|
|
65
|
+
if (path === undefined || content === undefined)
|
|
66
|
+
return null;
|
|
67
|
+
const shownPath = sendablePath(path);
|
|
68
|
+
return {
|
|
69
|
+
operation: 'write',
|
|
70
|
+
paths: [shownPath],
|
|
71
|
+
body: `Write ${shownPath}, ${plural(lineCountOf(content), 'line')}:\n\n${sendableText(content, isEnvFile(path))}`,
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
const shownEdit = (edit, hidesEnvValues) => [prefixedLines(sendableText(edit.oldText, hidesEnvValues), REMOVED_LINE_PREFIX), prefixedLines(sendableText(edit.newText, hidesEnvValues), ADDED_LINE_PREFIX)].join('\n');
|
|
75
|
+
const editPreviewOf = (params) => {
|
|
76
|
+
const path = pathParameter(params);
|
|
77
|
+
const edits = textEditsOf(params);
|
|
78
|
+
if (path === undefined || edits === null)
|
|
79
|
+
return null;
|
|
80
|
+
const shownPath = sendablePath(path);
|
|
81
|
+
const hidesEnvValues = isEnvFile(path);
|
|
82
|
+
return {
|
|
83
|
+
operation: 'edit',
|
|
84
|
+
paths: [shownPath],
|
|
85
|
+
body: `Edit ${shownPath}, ${plural(edits.length, 'change')}:\n\n${edits.map(edit => shownEdit(edit, hidesEnvValues)).join('\n\n')}`,
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
const patchPreviewOf = (params) => {
|
|
89
|
+
const patch = textParameter(params, PATCH_PARAMETER);
|
|
90
|
+
if (patch === undefined)
|
|
91
|
+
return null;
|
|
92
|
+
const targets = patchTargetsOf(patch);
|
|
93
|
+
if (targets.length === 0)
|
|
94
|
+
return null;
|
|
95
|
+
return {
|
|
96
|
+
operation: 'patch',
|
|
97
|
+
paths: targets.map(sendablePath),
|
|
98
|
+
body: sendableText(patch, targets.some(isEnvFile)),
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
export const fileChangePreviewOf = (toolId, params) => {
|
|
102
|
+
if (toolId === WRITE_TOOL)
|
|
103
|
+
return writePreviewOf(params);
|
|
104
|
+
if (toolId === EDIT_TOOL)
|
|
105
|
+
return editPreviewOf(params);
|
|
106
|
+
if (toolId === APPLY_PATCH_TOOL)
|
|
107
|
+
return patchPreviewOf(params);
|
|
108
|
+
return null;
|
|
109
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { APPROVAL_DESCRIPTION_MAX, APPROVAL_TITLE_MAX, truncated } from './approval-question.js';
|
|
1
|
+
import { ACTION_BODY_MAX, APPROVAL_DESCRIPTION_MAX, APPROVAL_TITLE_MAX, characterCount, truncated } from './approval-question.js';
|
|
2
2
|
import { API_KEY_VARIABLE, BASE_URL_VARIABLE } from './connection.js';
|
|
3
3
|
import { MIN_HOST_VERSION } from './host-version.js';
|
|
4
|
-
export const SETUP_COMMAND = 'npx pushary@latest setup';
|
|
4
|
+
export const SETUP_COMMAND = 'npx pushary@latest setup --agents openclaw';
|
|
5
5
|
export const DEVICES_URL = 'https://pushary.com/dashboard/agent/settings';
|
|
6
6
|
export const HAND_BACK_DECISIONS = ['allow-once', 'deny'];
|
|
7
7
|
const SECONDS_PER_MINUTE = 60;
|
|
@@ -23,10 +23,16 @@ const unavailableReason = (toolName, outcome) => {
|
|
|
23
23
|
}
|
|
24
24
|
return `Pushary could not be reached, so nobody could approve this ${toolName} call and it was blocked. Nothing ran. Try again in a moment.`;
|
|
25
25
|
};
|
|
26
|
+
const shortenedDescription = (text) => {
|
|
27
|
+
if (text.length <= APPROVAL_DESCRIPTION_MAX)
|
|
28
|
+
return text;
|
|
29
|
+
const notice = ` (shortened from ${characterCount(text.length)} characters: read the whole call in OpenClaw before you allow it)`;
|
|
30
|
+
return `${truncated(text, APPROVAL_DESCRIPTION_MAX - notice.length)}${notice}`;
|
|
31
|
+
};
|
|
26
32
|
const handedBack = (question) => ({
|
|
27
33
|
requireApproval: {
|
|
28
34
|
title: truncated(question.question, APPROVAL_TITLE_MAX),
|
|
29
|
-
description:
|
|
35
|
+
description: shortenedDescription(`${question.context} ${question.action}`),
|
|
30
36
|
severity: 'warning',
|
|
31
37
|
allowedDecisions: [...HAND_BACK_DECISIONS],
|
|
32
38
|
},
|
|
@@ -53,6 +59,7 @@ export const openClawResultFor = (outcome, question, handBackSurface) => {
|
|
|
53
59
|
return blocked(unavailableReason(tool, outcome));
|
|
54
60
|
}
|
|
55
61
|
};
|
|
62
|
+
export const tooLongToReviewResultFor = (toolName, length) => blocked(`This ${toolName} call is too long to show in full: ${characterCount(length)} characters, and Pushary shows at most ${characterCount(ACTION_BODY_MAX)}. It was blocked, not sent for an approval nobody could read. Nothing ran. Split it into smaller steps.`);
|
|
56
63
|
export const notConnectedResultFor = (problem, toolName) => problem === 'missing_api_key'
|
|
57
|
-
? blocked(`Pushary is not set up for OpenClaw on this machine: ${API_KEY_VARIABLE} is missing, so this ${toolName} call was blocked. Run ${SETUP_COMMAND}, or add ${API_KEY_VARIABLE} to ~/.openclaw/.env, then restart the OpenClaw gateway.`)
|
|
64
|
+
? blocked(`Pushary is not set up for OpenClaw on this machine: ${API_KEY_VARIABLE} is missing, so this ${toolName} call was blocked. Run ${SETUP_COMMAND}, or create an API key at ${DEVICES_URL} and add ${API_KEY_VARIABLE}=<key> to ~/.openclaw/.env, then restart the OpenClaw gateway.`)
|
|
58
65
|
: blocked(`${BASE_URL_VARIABLE} is not https://pushary.com or https://www.pushary.com, so this ${toolName} call was blocked. Remove it, then restart the OpenClaw gateway.`);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { redactSecrets } from './redaction.js';
|
|
2
|
+
export const REDACTED_VALUE = '[redacted]';
|
|
3
|
+
const REDACTION_PROBE = 'x';
|
|
4
|
+
export const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
5
|
+
export const isCredentialName = (key) => redactSecrets(`${key}=${REDACTION_PROBE}`) !== `${key}=${REDACTION_PROBE}`;
|
|
6
|
+
const withCredentialValuesRedacted = (value, ancestors) => {
|
|
7
|
+
if (typeof value !== 'object' || value === null)
|
|
8
|
+
return value;
|
|
9
|
+
if (ancestors.has(value))
|
|
10
|
+
throw new TypeError('circular parameters');
|
|
11
|
+
const inside = new Set([...ancestors, value]);
|
|
12
|
+
if (Array.isArray(value))
|
|
13
|
+
return value.map(item => withCredentialValuesRedacted(item, inside));
|
|
14
|
+
if (!isRecord(value))
|
|
15
|
+
return value;
|
|
16
|
+
return Object.fromEntries(Object.entries(value).map(([key, entry]) => [
|
|
17
|
+
key,
|
|
18
|
+
isCredentialName(key) ? REDACTED_VALUE : withCredentialValuesRedacted(entry, inside),
|
|
19
|
+
]));
|
|
20
|
+
};
|
|
21
|
+
export const serializedWithCredentialsRedacted = (value) => {
|
|
22
|
+
try {
|
|
23
|
+
return JSON.stringify(withCredentialValuesRedacted(value, new Set())) ?? '';
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return '';
|
|
27
|
+
}
|
|
28
|
+
};
|
|
@@ -14,6 +14,8 @@ const FILE_REFERENCE_PREFIX = '@';
|
|
|
14
14
|
const HOME_PREFIX = '~';
|
|
15
15
|
const MISSING_PATH_CODES = new Set(['ENOENT', 'ENOTDIR']);
|
|
16
16
|
const WORKSPACE_HOOKS_DIRECTORY = 'hooks';
|
|
17
|
+
const WORKSPACE_OPENCLAW_DIRECTORY = '.openclaw';
|
|
18
|
+
const WORKSPACE_FOLDERS_OPENCLAW_LOADS = [WORKSPACE_HOOKS_DIRECTORY, WORKSPACE_OPENCLAW_DIRECTORY];
|
|
17
19
|
const RISKY_RELATIVE_STARTS = ['.pushary', '.config'];
|
|
18
20
|
const errorCodeOf = (error) => typeof error === 'object' && error !== null && 'code' in error && typeof error.code === 'string' ? error.code : null;
|
|
19
21
|
const canonicalPathOf = (path, system) => {
|
|
@@ -61,6 +63,7 @@ const comparablePathsFor = (locations, system, agentId) => {
|
|
|
61
63
|
protectedTrees: spellingsOfAll(locations.protectedTrees, system),
|
|
62
64
|
serviceFiles: locations.serviceFiles.flatMap(location => spellingsOfLocation(location.directory, system).map(directory => ({ directory, namePrefix: comparable(location.namePrefix, system) }))),
|
|
63
65
|
workspace: workspaceCanonical === null ? null : comparable(workspaceCanonical, system),
|
|
66
|
+
workspaceFoldersOpenClawLoads: WORKSPACE_FOLDERS_OPENCLAW_LOADS.map(folder => comparable(folder, system)),
|
|
64
67
|
riskyRelativeStarts: new Set([
|
|
65
68
|
...locations.stateDirectories.map(state => comparable(basename(state), system)),
|
|
66
69
|
...locations.configFiles.map(file => comparable(basename(file), system)),
|
|
@@ -69,7 +72,12 @@ const comparablePathsFor = (locations, system, agentId) => {
|
|
|
69
72
|
};
|
|
70
73
|
};
|
|
71
74
|
const isServiceFile = (path, services) => services.some(service => firstComponentUnder(path, service.directory)?.startsWith(service.namePrefix) === true);
|
|
72
|
-
const
|
|
75
|
+
const isInAWorkspaceFolderOpenClawLoads = (path, paths) => {
|
|
76
|
+
if (paths.workspace === null)
|
|
77
|
+
return false;
|
|
78
|
+
const component = firstComponentUnder(path, paths.workspace);
|
|
79
|
+
return component !== null && paths.workspaceFoldersOpenClawLoads.includes(component);
|
|
80
|
+
};
|
|
73
81
|
const isInWorkspaceUnderState = (path, paths) => {
|
|
74
82
|
const { workspace } = paths;
|
|
75
83
|
if (workspace === null || !isSameOrInside(path, workspace))
|
|
@@ -83,7 +91,7 @@ const isProtectedLocation = (path, paths) => {
|
|
|
83
91
|
return true;
|
|
84
92
|
if (isServiceFile(path, paths.serviceFiles))
|
|
85
93
|
return true;
|
|
86
|
-
if (
|
|
94
|
+
if (isInAWorkspaceFolderOpenClawLoads(path, paths))
|
|
87
95
|
return true;
|
|
88
96
|
if (!paths.stateDirectories.some(state => isSameOrInside(path, state)))
|
|
89
97
|
return false;
|
|
@@ -189,6 +197,12 @@ export const writesIntoOpenClaw = (locations, system, call) => {
|
|
|
189
197
|
export const SESSIONS_SPAWN_TOOL = 'sessions_spawn';
|
|
190
198
|
export const SPAWN_FOLDER_PARAMETER = 'cwd';
|
|
191
199
|
const SPAWN_SOURCES_IT_CANNOT_SEE = ['projectId', 'projectGitUrl', 'worktree'];
|
|
200
|
+
const SPAWN_RUNTIME_PARAMETER = 'runtime';
|
|
201
|
+
const ACP_RUNTIME = 'acp';
|
|
202
|
+
export const startsAnAcpSession = (params) => {
|
|
203
|
+
const runtime = params[SPAWN_RUNTIME_PARAMETER];
|
|
204
|
+
return typeof runtime === 'string' && runtime.trim().toLowerCase() === ACP_RUNTIME;
|
|
205
|
+
};
|
|
192
206
|
const namesAFolderItCannotSee = (params) => SPAWN_SOURCES_IT_CANNOT_SEE.some(name => params[name] !== undefined && params[name] !== false);
|
|
193
207
|
const spawnFolderVerdict = (raw, paths, system) => {
|
|
194
208
|
if (typeof raw !== 'string' || raw.trim().length === 0 || paths.workspace === null)
|
|
@@ -202,13 +216,13 @@ const spawnFolderVerdict = (raw, paths, system) => {
|
|
|
202
216
|
const folder = comparable(canonical, system);
|
|
203
217
|
if (!isSameOrInside(folder, paths.workspace))
|
|
204
218
|
return 'protected';
|
|
205
|
-
return
|
|
219
|
+
return isInAWorkspaceFolderOpenClawLoads(folder, paths) ? 'protected' : 'clear';
|
|
206
220
|
};
|
|
207
221
|
export const spawnsOutsideTheWorkspace = (locations, system, call) => {
|
|
208
222
|
if (call.toolId !== SESSIONS_SPAWN_TOOL)
|
|
209
223
|
return false;
|
|
210
224
|
const { params } = call.event;
|
|
211
|
-
if (namesAFolderItCannotSee(params))
|
|
225
|
+
if (startsAnAcpSession(params) || namesAFolderItCannotSee(params))
|
|
212
226
|
return true;
|
|
213
227
|
if (params[SPAWN_FOLDER_PARAMETER] === undefined)
|
|
214
228
|
return false;
|
|
@@ -11,6 +11,7 @@ export const GATEWAY_TOOL = 'gateway';
|
|
|
11
11
|
export const OPENCLAW_SYSTEM_TOOL = 'openclaw';
|
|
12
12
|
export const AUTOMATIONS_TOOL = 'automations';
|
|
13
13
|
export const TERMINAL_TOOL = 'terminal';
|
|
14
|
+
export const NODES_TOOL = 'nodes';
|
|
14
15
|
export const TOOL_ACTION_PARAMETER = 'action';
|
|
15
16
|
const TOOL_ID_PATTERN = /^[a-z0-9][a-z0-9_.:-]{0,99}$/;
|
|
16
17
|
const AGENT_NAME_SEPARATOR = ' - ';
|
|
@@ -35,6 +36,10 @@ const OPENCLAW_SYSTEM_ACTIONS_WITHOUT_APPROVAL = new Set([
|
|
|
35
36
|
]);
|
|
36
37
|
const AUTOMATIONS_ACTIONS_WITHOUT_APPROVAL = new Set(['status', 'list', 'get', 'runs', 'next_check']);
|
|
37
38
|
const TERMINAL_ACTIONS_WITHOUT_APPROVAL = new Set(['read', 'list']);
|
|
39
|
+
const NODES_ACTIONS_WITHOUT_APPROVAL = new Set([
|
|
40
|
+
'status', 'describe', 'pending', 'notify', 'camera_list', 'notifications_list',
|
|
41
|
+
'device_status', 'device_info', 'device_permissions', 'device_health',
|
|
42
|
+
]);
|
|
38
43
|
const ACTIONS_WITHOUT_APPROVAL_BY_TOOL = new Map([
|
|
39
44
|
[PROCESS_TOOL, PROCESS_ACTIONS_WITHOUT_APPROVAL],
|
|
40
45
|
[PLUGINS_TOOL, PLUGINS_ACTIONS_WITHOUT_APPROVAL],
|
|
@@ -42,8 +47,9 @@ const ACTIONS_WITHOUT_APPROVAL_BY_TOOL = new Map([
|
|
|
42
47
|
[OPENCLAW_SYSTEM_TOOL, OPENCLAW_SYSTEM_ACTIONS_WITHOUT_APPROVAL],
|
|
43
48
|
[AUTOMATIONS_TOOL, AUTOMATIONS_ACTIONS_WITHOUT_APPROVAL],
|
|
44
49
|
[TERMINAL_TOOL, TERMINAL_ACTIONS_WITHOUT_APPROVAL],
|
|
50
|
+
[NODES_TOOL, NODES_ACTIONS_WITHOUT_APPROVAL],
|
|
45
51
|
]);
|
|
46
|
-
export const DEFAULT_GATED_TOOLS = [EXEC_TOOL, PROCESS_TOOL, PLUGINS_TOOL, GATEWAY_TOOL, OPENCLAW_SYSTEM_TOOL, AUTOMATIONS_TOOL, TERMINAL_TOOL];
|
|
52
|
+
export const DEFAULT_GATED_TOOLS = [EXEC_TOOL, PROCESS_TOOL, PLUGINS_TOOL, GATEWAY_TOOL, OPENCLAW_SYSTEM_TOOL, AUTOMATIONS_TOOL, TERMINAL_TOOL, NODES_TOOL];
|
|
47
53
|
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
48
54
|
export const hostToolId = (name) => {
|
|
49
55
|
const lowered = name.trim().toLowerCase();
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
const WINDOWS_LINE_BREAK = /\r\n/g;
|
|
2
|
+
const HIDDEN_CHARACTERS = /[\u0000-\u0008\u000B-\u001F\u007F-\u009F---\u{E0000}-\u{E007F}]/gu;
|
|
3
|
+
const CODE_POINT_DIGITS = 4;
|
|
4
|
+
const visibleCodeOf = (character) => `\\u{${(character.codePointAt(0) ?? 0).toString(16).toUpperCase().padStart(CODE_POINT_DIGITS, '0')}}`;
|
|
5
|
+
export const withHiddenCharactersShown = (text) => text.replace(WINDOWS_LINE_BREAK, '\n').replace(HIDDEN_CHARACTERS, visibleCodeOf);
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"uiHints": {
|
|
12
12
|
"gatedTools": {
|
|
13
13
|
"label": "More tools that need your approval",
|
|
14
|
-
"help": "OpenClaw tool ids to gate on top of the defaults (exec, process input,
|
|
14
|
+
"help": "OpenClaw tool ids to gate on top of the defaults (exec, process input, the plugins, gateway and openclaw actions that change OpenClaw, automations, terminal input, and nodes actions such as run), for example message or browser."
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
"configSchema": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pushary/openclaw",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Phone approvals for OpenClaw. Pushary asks you before your AI agent runs a gated tool call, and blocks the call unless you approve it.",
|
|
5
5
|
"author": "Pushary <business@pushary.com>",
|
|
6
6
|
"homepage": "https://pushary.com/human-in-the-loop-openclaw",
|
|
@@ -822,7 +822,7 @@ var decidePreToolUse = async (input) => {
|
|
|
822
822
|
};
|
|
823
823
|
var repairCodexHoldsQuietly = async () => {
|
|
824
824
|
try {
|
|
825
|
-
const { repairCodexHolds } = await import("../reapply-
|
|
825
|
+
const { repairCodexHolds } = await import("../reapply-AFG7K4KS.js");
|
|
826
826
|
repairCodexHolds();
|
|
827
827
|
} catch {
|
|
828
828
|
return;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
inspectConfiguredManagedProviders
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-FSEOIGZX.js";
|
|
5
5
|
import {
|
|
6
6
|
readHookWiring,
|
|
7
7
|
readHookWiringSafely
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
HERMES_INSTALL_MARKER_FILE,
|
|
25
25
|
defaultHermesHome,
|
|
26
26
|
parseHermesInstallMarker
|
|
27
|
-
} from "../chunk-
|
|
27
|
+
} from "../chunk-RJAQ2447.js";
|
|
28
28
|
import {
|
|
29
29
|
writeHuman
|
|
30
30
|
} from "../chunk-QCGNGEGE.js";
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
openClawRepairStep,
|
|
5
5
|
readHermesShellGate,
|
|
6
6
|
readSetupFailure
|
|
7
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-WQ66RQRF.js";
|
|
8
8
|
import {
|
|
9
9
|
CODEX_HOOK_REMEDY,
|
|
10
10
|
HERMES_RESTART_COMMAND,
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
describeHermesShellGate,
|
|
13
13
|
describeHermesState,
|
|
14
14
|
hermesRepairStep
|
|
15
|
-
} from "../chunk-
|
|
15
|
+
} from "../chunk-DNK4E5CE.js";
|
|
16
16
|
import {
|
|
17
17
|
describeWaitLadder
|
|
18
18
|
} from "../chunk-CVWG2N3Y.js";
|
|
@@ -85,7 +85,7 @@ import {
|
|
|
85
85
|
routesHermesQuestions,
|
|
86
86
|
runsAnOlderPlugin,
|
|
87
87
|
shippedHermesPlugin
|
|
88
|
-
} from "../chunk-
|
|
88
|
+
} from "../chunk-RJAQ2447.js";
|
|
89
89
|
import "../chunk-QCGNGEGE.js";
|
|
90
90
|
import {
|
|
91
91
|
findOpenClawLauncher,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
reapplyClaudeForVersion
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-FSEOIGZX.js";
|
|
5
5
|
import "../chunk-I3CN7BGN.js";
|
|
6
|
-
import "../chunk-
|
|
6
|
+
import "../chunk-RJAQ2447.js";
|
|
7
7
|
import "../chunk-5D57GAKF.js";
|
|
8
8
|
import "../chunk-7XFEV7ML.js";
|
|
9
9
|
import "../chunk-ZMEI3EG4.js";
|
|
@@ -62,7 +62,7 @@ import {
|
|
|
62
62
|
gateHermesShell,
|
|
63
63
|
readHermesShellGate,
|
|
64
64
|
saveSetupFailure
|
|
65
|
-
} from "../chunk-
|
|
65
|
+
} from "../chunk-WQ66RQRF.js";
|
|
66
66
|
import {
|
|
67
67
|
CODEX_NEEDS_A_NEWER_VERSION,
|
|
68
68
|
CODEX_SETTINGS_STOP_A_HOOK,
|
|
@@ -76,7 +76,7 @@ import {
|
|
|
76
76
|
describeHermesState,
|
|
77
77
|
hermesGateShellCommand,
|
|
78
78
|
needsCodexTrustStep
|
|
79
|
-
} from "../chunk-
|
|
79
|
+
} from "../chunk-DNK4E5CE.js";
|
|
80
80
|
import {
|
|
81
81
|
describeWaitLadder
|
|
82
82
|
} from "../chunk-CVWG2N3Y.js";
|
|
@@ -170,7 +170,7 @@ import {
|
|
|
170
170
|
routesHermesQuestions,
|
|
171
171
|
runsAnOlderPlugin,
|
|
172
172
|
shippedHermesPlugin
|
|
173
|
-
} from "../chunk-
|
|
173
|
+
} from "../chunk-RJAQ2447.js";
|
|
174
174
|
import {
|
|
175
175
|
setHumanStream
|
|
176
176
|
} from "../chunk-QCGNGEGE.js";
|
|
@@ -28,11 +28,11 @@ import {
|
|
|
28
28
|
import {
|
|
29
29
|
ensureCodexTrustAfterReapply,
|
|
30
30
|
reapplyAllAgents
|
|
31
|
-
} from "../chunk-
|
|
31
|
+
} from "../chunk-FSEOIGZX.js";
|
|
32
32
|
import {
|
|
33
33
|
HERMES_RESTART_COMMAND,
|
|
34
34
|
describeCodexTrustConfirmation
|
|
35
|
-
} from "../chunk-
|
|
35
|
+
} from "../chunk-DNK4E5CE.js";
|
|
36
36
|
import "../chunk-AWC7MXLX.js";
|
|
37
37
|
import {
|
|
38
38
|
keepLinuxDaemonAfterLogout,
|
|
@@ -46,7 +46,7 @@ import {
|
|
|
46
46
|
readMacAppAgentKey
|
|
47
47
|
} from "../chunk-3XIHKIDX.js";
|
|
48
48
|
import "../chunk-J6LZ4G5G.js";
|
|
49
|
-
import "../chunk-
|
|
49
|
+
import "../chunk-RJAQ2447.js";
|
|
50
50
|
import "../chunk-5D57GAKF.js";
|
|
51
51
|
import {
|
|
52
52
|
FX_RELOAD_AFTER_BRIDGE,
|
|
@@ -3597,6 +3597,11 @@ var readInstallMarker = (directory) => {
|
|
|
3597
3597
|
return typeof marker.version === "string" && typeof marker.digest === "string" ? { owner: INSTALL_MARKER_OWNER, version: marker.version, digest: marker.digest } : null;
|
|
3598
3598
|
};
|
|
3599
3599
|
var ownedFolderIsCurrent = (directory, bundle) => readInstallMarker(directory)?.digest === bundle.digest;
|
|
3600
|
+
var recordOwnedFolderInstalled = (directory, bundle) => {
|
|
3601
|
+
const marker = { owner: INSTALL_MARKER_OWNER, version: bundle.version, digest: bundle.digest };
|
|
3602
|
+
writeFileSync2(join2(directory, OPENCLAW_INSTALL_MARKER_FILE), `${JSON.stringify(marker, null, 2)}
|
|
3603
|
+
`);
|
|
3604
|
+
};
|
|
3600
3605
|
var isDirectory = (path) => {
|
|
3601
3606
|
try {
|
|
3602
3607
|
return statSync2(path).isDirectory();
|
|
@@ -3610,9 +3615,6 @@ var writeOwnedPluginFolder = (bundle, target) => {
|
|
|
3610
3615
|
rmSync3(staging, { recursive: true, force: true });
|
|
3611
3616
|
mkdirSync2(dirname2(target), { recursive: true });
|
|
3612
3617
|
cpSync(bundle.directory, staging, { recursive: true, filter: (path) => !path.endsWith(OPENCLAW_INSTALL_MARKER_FILE) });
|
|
3613
|
-
const marker = { owner: INSTALL_MARKER_OWNER, version: bundle.version, digest: bundle.digest };
|
|
3614
|
-
writeFileSync2(join2(staging, OPENCLAW_INSTALL_MARKER_FILE), `${JSON.stringify(marker, null, 2)}
|
|
3615
|
-
`);
|
|
3616
3618
|
rmSync3(previous, { recursive: true, force: true });
|
|
3617
3619
|
const hadTarget = isDirectory(target);
|
|
3618
3620
|
if (hadTarget) renameSync2(target, previous);
|
|
@@ -3719,6 +3721,13 @@ var writeOwnedFolder = (bundle, folder) => {
|
|
|
3719
3721
|
return false;
|
|
3720
3722
|
}
|
|
3721
3723
|
};
|
|
3724
|
+
var recordInstalled = (bundle, folder) => {
|
|
3725
|
+
try {
|
|
3726
|
+
recordOwnedFolderInstalled(folder, bundle);
|
|
3727
|
+
} catch {
|
|
3728
|
+
return;
|
|
3729
|
+
}
|
|
3730
|
+
};
|
|
3722
3731
|
var installOpenClawPlugin = async (request) => {
|
|
3723
3732
|
const launcher = launcherFor(request.launcher, findOpenClawLauncher);
|
|
3724
3733
|
if (launcher === null) return { kind: "no_launcher" };
|
|
@@ -3738,6 +3747,7 @@ var installOpenClawPlugin = async (request) => {
|
|
|
3738
3747
|
if (installed.kind === "failed") {
|
|
3739
3748
|
return { kind: "failed", reason: installed.timedOut ? "install_timed_out" : "install_failed", detail: failureDetail(installed) };
|
|
3740
3749
|
}
|
|
3750
|
+
recordInstalled(bundle, request.files.ownedFolder);
|
|
3741
3751
|
const enabled = await enableOpenClawPlugin(session);
|
|
3742
3752
|
if (enabled.kind === "failed") return { kind: "failed", reason: "enable_failed", detail: failureDetail(enabled) };
|
|
3743
3753
|
return { kind: "installed", inspection: await inspectWith(session, true), version: bundle.version };
|
|
@@ -3760,6 +3770,7 @@ var refreshOpenClawPlugin = async (request) => {
|
|
|
3760
3770
|
const results = [];
|
|
3761
3771
|
for (const receipt of receipts) results.push(await reinstallInto(launcher, receipt, request.files.ownedFolder));
|
|
3762
3772
|
if (results.includes("failed")) return "failed";
|
|
3773
|
+
recordInstalled(bundle, request.files.ownedFolder);
|
|
3763
3774
|
return results.includes("refreshed") ? "refreshed" : "not_set_up";
|
|
3764
3775
|
};
|
|
3765
3776
|
var restoreEntry = async (session, receipt, entryNow) => {
|
|
@@ -12,9 +12,9 @@ import {
|
|
|
12
12
|
reapplyOpenCodePlugin,
|
|
13
13
|
reapplyVsCodePlugin,
|
|
14
14
|
repairCodexHolds
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-FSEOIGZX.js";
|
|
16
16
|
import "./chunk-I3CN7BGN.js";
|
|
17
|
-
import "./chunk-
|
|
17
|
+
import "./chunk-RJAQ2447.js";
|
|
18
18
|
import "./chunk-5D57GAKF.js";
|
|
19
19
|
import "./chunk-7XFEV7ML.js";
|
|
20
20
|
import "./chunk-ZMEI3EG4.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pushary/agent-hooks",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.151",
|
|
4
4
|
"description": "Human-in-the-loop (HITL) for AI agents: ask a person for approvals or answers by push notification. One command connects Claude Code, Codex, Cursor, Gemini CLI and more.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pushary",
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
// What is left to test in the gate itself.
|
|
2
|
-
//
|
|
3
|
-
// This file used to cover the vendored policy engine: pattern matching, argument
|
|
4
|
-
// rules, the destructive ceiling and repo scoping. None of that lives here any
|
|
5
|
-
// more. The gate asks POST /api/agent/gate, which runs the same `resolveGate` as
|
|
6
|
-
// every other client, and those behaviours are tested once against the engine in
|
|
7
|
-
// packages/contracts/src/gate.test.ts rather than once per copy.
|
|
8
|
-
//
|
|
9
|
-
// What remains is the one thing a server cannot answer: which repository this
|
|
10
|
-
// checkout is in. Deriving it means walking parent directories for a `.git` and
|
|
11
|
-
// reading its config, so the gate still does it and sends the result.
|
|
12
|
-
//
|
|
13
|
-
// Run: node --test scripts/pushary-gate.test.mjs
|
|
14
|
-
|
|
15
|
-
import assert from 'node:assert/strict'
|
|
16
|
-
import { describe, it } from 'node:test'
|
|
17
|
-
import { describeRequest, normalizeRepoRemote, redactSecrets, timeoutActionWithoutLocalPrompt } from './pushary-gate.mjs'
|
|
18
|
-
|
|
19
|
-
describe('repo identity', () => {
|
|
20
|
-
it('collapses the forms of one remote', () => {
|
|
21
|
-
for (const r of ['https://github.com/acme/api.git', 'git@github.com:acme/api.git', 'ssh://git@github.com:22/acme/api.git']) {
|
|
22
|
-
assert.equal(normalizeRepoRemote(r), 'github.com/acme/api', r)
|
|
23
|
-
}
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
it('never lets a credential survive', () => {
|
|
27
|
-
const key = normalizeRepoRemote('https://user:ghp_SECRET@github.com/acme/api.git')
|
|
28
|
-
assert.equal(key, 'github.com/acme/api')
|
|
29
|
-
assert.ok(!key.includes('ghp_') && !key.includes('@'))
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
it('returns undefined without a stable identity', () => {
|
|
33
|
-
for (const r of ['', '../rel', 'file:///Users/dev/repo']) assert.equal(normalizeRepoRemote(r), undefined, r)
|
|
34
|
-
})
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
// The gate answers two Cursor events now, and they arrive on the same stdin with
|
|
38
|
-
// different fields. What each one turns into is the only thing standing between
|
|
39
|
-
// an MCP call and being gated as if it were a shell command.
|
|
40
|
-
describe('what the gate was asked about', () => {
|
|
41
|
-
it('names an MCP call the way every other agent names one', () => {
|
|
42
|
-
const request = describeRequest({
|
|
43
|
-
hook_event_name: 'beforeMCPExecution',
|
|
44
|
-
tool_name: 'create_issue',
|
|
45
|
-
mcp_server_name: 'github',
|
|
46
|
-
tool_input: '{"title":"x"}',
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
// `mcp__<server>__<tool>` is what `validateToolPattern` accepts and what
|
|
50
|
-
// Claude Code sends, so one policy rule covers the tool on both agents. A
|
|
51
|
-
// Cursor-only spelling would silently miss every rule a user already wrote.
|
|
52
|
-
assert.equal(request.toolName, 'mcp__github__create_issue')
|
|
53
|
-
assert.deepEqual(request.toolInputs, [{ tool: 'mcp__github__create_issue', params: '{"title":"x"}' }])
|
|
54
|
-
assert.match(request.display, /create_issue/)
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
it('still reads a shell command, including from a payload with no event name', () => {
|
|
58
|
-
const named = describeRequest({ hook_event_name: 'beforeShellExecution', command: ' rm -rf /tmp/x ' })
|
|
59
|
-
assert.equal(named.toolName, 'Bash')
|
|
60
|
-
assert.equal(named.toolTarget, 'rm -rf')
|
|
61
|
-
|
|
62
|
-
// An older Cursor that omits `hook_event_name` must keep working exactly as
|
|
63
|
-
// it did when shell was the only registered event.
|
|
64
|
-
assert.equal(describeRequest({ command: 'git push' }).toolName, 'Bash')
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* `beforeMCPExecution` is registered with NO matcher, so every MCP call in the
|
|
69
|
-
* editor reaches this gate, ours included. Gating our own tools deadlocks: the
|
|
70
|
-
* approval for `ask_user` cannot reach the phone until the `ask_user` call it
|
|
71
|
-
* is gating goes through. With `failClosed: true` on that entry it is worse
|
|
72
|
-
* than a hang, because a timeout turns into a denial of the user's own
|
|
73
|
-
* question.
|
|
74
|
-
*
|
|
75
|
-
* The Claude hook carries this guard three times over and calls it a
|
|
76
|
-
* precaution, because its matcher does not route these there. Here it is the
|
|
77
|
-
* only thing standing between the two.
|
|
78
|
-
*/
|
|
79
|
-
it('never gates Pushary\'s own MCP tools', () => {
|
|
80
|
-
for (const tool of ['ask_user', 'wait_for_answer', 'send_notification', 'propose_scope']) {
|
|
81
|
-
assert.equal(
|
|
82
|
-
describeRequest({
|
|
83
|
-
hook_event_name: 'beforeMCPExecution',
|
|
84
|
-
tool_name: tool,
|
|
85
|
-
mcp_server_name: 'pushary',
|
|
86
|
-
tool_input: '{}',
|
|
87
|
-
}),
|
|
88
|
-
null,
|
|
89
|
-
`mcp__pushary__${tool} must reach Cursor's own prompt, not ours`,
|
|
90
|
-
)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// A neighbour whose name merely starts the same way is still gated. The
|
|
94
|
-
// guard is on the `mcp__pushary__` prefix, not on "contains pushary".
|
|
95
|
-
assert.equal(
|
|
96
|
-
describeRequest({
|
|
97
|
-
hook_event_name: 'beforeMCPExecution',
|
|
98
|
-
tool_name: 'run',
|
|
99
|
-
mcp_server_name: 'pushary-clone',
|
|
100
|
-
tool_input: '{}',
|
|
101
|
-
}).toolName,
|
|
102
|
-
'mcp__pushary-clone__run',
|
|
103
|
-
)
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
it('declines an event it does not gate rather than calling it Bash', () => {
|
|
107
|
-
// beforeReadFile is registered by nobody here on purpose: its response
|
|
108
|
-
// schema has no `ask`, so the no-opinion path this gate takes on every error
|
|
109
|
-
// has nothing to return. If one ever arrives, it must not be mistaken for a
|
|
110
|
-
// shell command carrying no command.
|
|
111
|
-
assert.equal(describeRequest({ hook_event_name: 'beforeReadFile', file_path: '/etc/passwd' }), null)
|
|
112
|
-
assert.equal(describeRequest({ hook_event_name: 'beforeMCPExecution' }), null)
|
|
113
|
-
assert.equal(describeRequest({}), null)
|
|
114
|
-
})
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
describe('approval text redaction', () => {
|
|
118
|
-
it('shows a command whole when a credential name only sits next to shell syntax', () => {
|
|
119
|
-
for (const command of [
|
|
120
|
-
'echo "password=" && rm -rf ~ && echo "x"',
|
|
121
|
-
'find / -name "token:" -o -delete -o -name "x"',
|
|
122
|
-
"grep -rl foo'password=' . | xargs rm -f 'important file'",
|
|
123
|
-
'grep "authorization:";rm important-file',
|
|
124
|
-
'echo "-----BEGIN PRIVATE KEY-----" && rm -rf ~ && echo "-----END PRIVATE KEY-----"',
|
|
125
|
-
'password= reboot',
|
|
126
|
-
]) {
|
|
127
|
-
assert.equal(redactSecrets(command), command)
|
|
128
|
-
}
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
it('stops a hidden value at the first space, quote or piece of shell syntax', () => {
|
|
132
|
-
assert.equal(redactSecrets('eval TOKEN="x; rm -rf ~"'), 'eval TOKEN="[redacted]; rm -rf ~"')
|
|
133
|
-
assert.equal(redactSecrets('TOKEN=abc;rm file'), 'TOKEN=[redacted];rm file')
|
|
134
|
-
assert.equal(redactSecrets('rm -rf {password=x,/}'), 'rm -rf {password=[redacted],/}')
|
|
135
|
-
assert.equal(redactSecrets('export API_KEY="abc123" && rm -rf build'), 'export API_KEY="[redacted]" && rm -rf build')
|
|
136
|
-
})
|
|
137
|
-
})
|
|
138
|
-
|
|
139
|
-
describe('a rule that approves on timeout, for a file hook with no prompt of its own', () => {
|
|
140
|
-
it('approves only under Every time, and is refused under When I am out', () => {
|
|
141
|
-
assert.equal(timeoutActionWithoutLocalPrompt({ mode: 'push_only', timeoutAction: 'approve' }), 'approve')
|
|
142
|
-
assert.equal(timeoutActionWithoutLocalPrompt({ mode: 'push_first', timeoutAction: 'approve' }), 'deny')
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
it('leaves every other timeout action as the rule wrote it', () => {
|
|
146
|
-
for (const timeoutAction of ['deny', 'escalate', 'wait']) {
|
|
147
|
-
assert.equal(timeoutActionWithoutLocalPrompt({ mode: 'push_first', timeoutAction }), timeoutAction)
|
|
148
|
-
}
|
|
149
|
-
})
|
|
150
|
-
})
|