pi-robot-hand 0.2.1 → 0.2.2

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.
Files changed (2) hide show
  1. package/README.md +33 -130
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -2,50 +2,22 @@
2
2
 
3
3
  The lazy kit for [pi](https://pi.dev): too lazy to open an IDE, too lazy to copy and paste, not lazy enough to switch off the safety net.
4
4
 
5
- When the agent cannot or should not run something itself (a `/reload`, a `sudo` command, an interactive login, a secret going into a config file), you still do not want to leave the conversation. pi-robot-hand moves the command or the secret to you in one keystroke and brings the result back to the agent, while the guards that keep the agent away from dangerous commands and secret files stay on:
5
+ Some things the agent cannot or should not do itself: `/reload`, a `sudo` command, an `ssh` login, a token that belongs in `.env`.
6
+ pi-robot-hand hands them to you in one keystroke and brings the result back to the agent:
6
7
 
7
- - **`robot_hand`**: the agent hands you a command. Pick where it goes: your pi prompt, the clipboard, or a new Herdr pane. The agent never runs it.
8
- - **`!` follow-up**: after a `!command` you type finishes, the agent reads its output and answers, without another message from you.
9
- - **`secret_drop`**: you type a secret into a masked dialog and apply it with a `!` command you can read. The agent never sees the value.
10
-
11
- You are the one who runs every command, so a command-guarding extension such as [cc-safety-net](https://github.com/kenryu42/cc-safety-net) keeps checking everything the agent itself runs.
12
-
13
- ## Install
8
+ - **`robot_hand`**: the agent hands you a command for your pi prompt, the clipboard, or a new Herdr pane. The agent never runs it.
9
+ - **`!` follow-up**: after a `!command` you type finishes, the agent reads its output and answers.
10
+ - **`secret_drop`**: you type a secret into a masked dialog. The agent never sees the value.
14
11
 
15
12
  ```bash
16
13
  pi install npm:pi-robot-hand
17
14
  ```
18
15
 
19
- The package ships three extensions and a `secret-drop` skill that teaches the agent to use `secret_drop` and to let programs consume secret files.
20
-
21
- ### Upgrading from pi-secret-drop
22
-
23
- `secret_drop` used to be the separate `pi-secret-drop` package. Both packages register the same tool, which pi refuses to load, so while `pi-secret-drop` is still in your settings pi-robot-hand leaves `secret_drop` to it and shows a warning with the exact command to remove it:
24
-
25
- ```bash
26
- pi remove npm:pi-secret-drop@0.1.6 # the source as listed in your settings
27
- ```
28
-
29
- Protected destinations and their registry in `~/.pi/agent/secret-drop/` carry over unchanged.
16
+ ## `robot_hand`
30
17
 
31
- ## `robot_hand`: hand the user a command
32
-
33
- 1. The agent calls `robot_hand` with a command and a one-line reason.
34
- 2. Pi shows an inline selector in place of the prompt, with the reason and exactly what you would run.
35
- 3. You pick one:
36
- - **Put it in my prompt**: a shell command lands as `! command`, a pi slash command such as `/reload` lands as-is. Pressing Enter runs it; a `!` command's output returns to the conversation and the agent answers it.
37
- - **Copy it to the clipboard**: the raw shell command, for another terminal.
38
- - **Type it into a new Herdr pane (I press Enter)**: when pi runs inside [Herdr](https://herdr.dev), a pane opens below pi with the command on an editable line. Edit it if needed and press Enter, or Ctrl+C to cancel.
39
- - **Run it in a new Herdr pane**: the same pane, with the command started at once.
40
- - **No, thanks**: nothing is placed.
41
- 4. The tool returns the choice. After a hand-over the agent's turn ends, so the next move is yours.
42
-
43
- A Herdr pane is a real terminal, so password prompts, `sudo`, confirmations, `ssh`, and full-screen programs work there; pi's `!` has no terminal input. When the command finishes, the pane closes and its output (the last 200 lines) and exit code arrive as a message that starts the agent's next turn. Cancelling, or closing the pane yourself, also reports back.
18
+ The agent calls `robot_hand` with a command and a one-line reason, and pi shows a selector:
44
19
 
45
20
  ```
46
- robot_hand 需要 sudo 重啟服務
47
- ! sudo systemctl restart nginx
48
- ──────────────────────────────────────────────
49
21
  Robot Hand — 需要 sudo 重啟服務
50
22
 
51
23
  ! sudo systemctl restart nginx
@@ -55,115 +27,48 @@ A Herdr pane is a real terminal, so password prompts, `sudo`, confirmations, `ss
55
27
  Copy it to the clipboard
56
28
  Run it in a new Herdr pane
57
29
  No, thanks
58
-
59
- ↑↓ navigate enter select escape/ctrl+c cancel
60
- ──────────────────────────────────────────────
61
30
  ```
62
31
 
63
- | Parameter | Description |
64
- |---|---|
65
- | `command` | The command. Shell commands go without a leading `!`; pi commands start with `/`. |
66
- | `reason` | One short line telling the user why, in the user's language. |
67
- | `kind` | `shell` (default) or `pi`. |
68
- | `default` | The option the selector starts on: `prompt` (default), `clipboard`, `herdr-type`, or `herdr-run`. The agent picks `herdr-type` for commands that need terminal input. An option this session cannot offer falls back along `herdr-run` → `herdr-type` → `clipboard` → `prompt`. |
32
+ - **Prompt**: the command lands in your prompt as `! command`, or as-is for a pi command such as `/reload`. Press Enter to run it.
33
+ - **Clipboard**: the raw command, for another terminal.
34
+ - **Herdr pane**: when pi runs inside [Herdr](https://herdr.dev), a pane opens below pi with the command ready to edit and run, or already running. The pane is a real terminal, so password prompts, `y/N` confirmations, `ssh`, and full-screen programs work. When the command finishes, the pane closes and its output and exit code come back to the agent.
69
35
 
70
- When the prompt already holds a draft, the prompt option says it replaces the draft. The clipboard and Herdr options appear only for shell commands in the terminal UI, and the Herdr options only inside Herdr. RPC clients get the prompt option; modes without a UI make the tool fail so the agent shows the command in chat.
71
-
72
- The Herdr pane runs a short wrapper script (zsh, or bash 4+ when zsh is missing) from a private temporary directory, which is removed when the run is reported. The command runs in a non-interactive shell, so your shell aliases and functions are not loaded.
36
+ The agent sets `default` to choose which option the selector starts on, and picks the Herdr pane for commands that need terminal input.
37
+ Options this session cannot offer are hidden: the clipboard outside the terminal UI, Herdr outside Herdr.
38
+ The pane runs the command with your `PATH` but without your `.zshrc`, so shell aliases are not available.
73
39
 
74
40
  ## `!` follow-up
75
41
 
76
- Pi records the output of a `!command` but does not start a turn. With pi-robot-hand, once a `!command` typed while the agent is idle finishes, the agent reads its output and answers. Pi still runs the command, so output streams live and other `user_bash` extensions keep working. `!!` commands, cancelled commands, commands typed while the agent is busy, and commands overtaken by a prompt you send meanwhile keep pi's behavior.
77
-
78
- ## `secret_drop`: put a secret in without the agent seeing it
42
+ Pi records a `!command`'s output but waits for your next message.
43
+ With pi-robot-hand, the agent answers as soon as the command finishes.
44
+ `!!` commands, cancelled commands, and commands typed while the agent is busy keep pi's behavior.
79
45
 
80
- 1. The agent calls `secret_drop` with a destination, a placement, and the steps to get the secret.
81
- 2. Pi opens a masked dialog that shows those steps, where the value will go, and what happens next. The user types or pastes the secret, or presses Tab to ask the agent a question instead.
82
- 3. The value is staged in `~/.pi/agent/secret-drop/staging/` (mode 600), and pi pre-fills a `!` command in the user's prompt:
83
-
84
- ```
85
- ! node ~/.pi/agent/npm/node_modules/pi-robot-hand/dist/apply.js env ./.env DB_PASSWORD --from ~/.pi/agent/secret-drop/staging/64770-948e1cb74b5a
86
- ```
46
+ ## `secret_drop`
87
47
 
88
- 4. The user reviews it and presses Enter. The apply script writes the destination, deletes the staged file, and prints only a report:
48
+ 1. The agent calls `secret_drop` with where the secret goes and the steps to get it.
49
+ 2. You type or paste the secret into a masked dialog, or press Tab to ask the agent a question instead.
50
+ 3. Your prompt now holds a `!` command that applies it. Press Enter:
89
51
 
90
52
  ```
91
53
  ✓ secret-drop: updated DB_PASSWORD (1 line) in ./.env (env DB_PASSWORD, mode 644) — length check passed (28 chars)
92
54
  ```
93
55
 
94
- 5. The tool, which has been waiting, returns that report and the agent continues.
95
-
96
- The agent never opens the destination: the user runs the write with a command they can read. That also keeps secret-guarding extensions such as [cc-safety-net](https://github.com/kenryu42/cc-safety-net) in charge of the agent's tool calls, since pi's `!` commands are the user's own.
97
-
98
- ```
99
- ╭─ Secret Drop ──────────────────────────────────────────────────────────────╮
100
- │ Staging database password │
101
- │ │
102
- │ How to get it │
103
- │ 1. Open the staging project in 1Password │
104
- │ 2. Copy the password of the "db-staging" item │
105
- │ │
106
- │ Goes to ./.env (env DB_PASSWORD) │
107
- │ Next Enter here stages the value. Your prompt then holds a ! command; │
108
- │ press Enter on it to apply. The agent never sees the value. │
109
- │ │
110
- │ › •••••••••••••••••••••••••••• │
111
- │ 28 chars │
112
- │ │
113
- │ Enter stage · Tab ask a question instead · Esc cancel · Ctrl+R show/hide · │
114
- │ Ctrl+U clear │
115
- │ Stuck or unsure? Press Tab and ask; the dialog closes and the agent │
116
- │ answers. │
117
- ╰────────────────────────────────────────────────────────────────────────────╯
118
- ```
119
-
120
- Tab opens a visible question field. Enter there closes the dialog without staging anything, discards what was typed in the secret field, and returns the question to the agent, which answers and calls `secret_drop` again. When the steps do not fit the terminal, the dialog shortens them; the tool call in the chat shows them in full.
121
-
122
- ### With cc-safety-net
123
-
124
- The two cover different halves of the problem:
56
+ The agent sees only that report. Afterwards it cannot read the destination, and the value is redacted from tool output.
57
+ It can set a `.env` key, replace a regex match, write a whole file, or feed the secret to a command such as `gh secret set`.
58
+ `/secret-drop` lists protected files.
59
+ See [docs/secret-drop.md](https://github.com/wayne930242/pi-robot-hand/blob/main/docs/secret-drop.md) for parameters, protection details, and limits.
125
60
 
126
- - **cc-safety-net keeps the agent out of secrets that already exist.** It blocks the agent's shell and file tools from reading `.env` files, SSH keys, `~/.aws`, and other well-known credential locations, whether or not secret_drop wrote them.
127
- - **secret_drop gets new secrets in without the agent seeing them.** It protects the destinations it writes, including files outside cc-safety-net's patterns such as `config.yml`, and redacts the values from tool output.
61
+ ## Safety
128
62
 
129
- They do not conflict. cc-safety-net inspects the agent's tool calls; the apply command is the user's own `!` command, so the write goes through while the agent stays blocked from reading the result.
63
+ pi-robot-hand depends on no other extension.
64
+ You run every command it hands over, so command guards such as [cc-safety-net](https://github.com/kenryu42/cc-safety-net) keep checking everything the agent runs, and the two work side by side.
65
+ A guard that scans tool input may block `robot_hand` when a command names a sensitive path such as `.env`; the agent then writes the command in chat for you to run.
130
66
 
131
- ### Parameters
67
+ ## Upgrading from pi-secret-drop
132
68
 
133
- | Parameter | Meaning |
134
- |---|---|
135
- | `label` | What the user should enter, in the user's language. |
136
- | `instructions` | Required. Numbered steps, in the user's language: where to go (URL or menu path), what to fill in, and what to copy. One step for a value the user already knows. |
137
- | `url` | The page where the user creates or finds the secret. |
138
- | `format` | `env`, `regex`, `file`, or `command`. Defaults to `env` when `key` is set, `command` when `command` is set, else `file`. |
139
- | `destination` | `env` / `regex` / `file`: target file, relative to the working directory. Missing directories are created. |
140
- | `key`, `quote` | `env`: variable name and quoting (`auto`, `none`, `single`, `double`). Existing `KEY=` / `export KEY=` lines are replaced, keeping trailing `# comments` and CRLF endings; otherwise the line is appended. Use `none` for files read by `docker --env-file`, which keeps quotes as part of the value. |
141
- | `regex`, `flags` | `regex`: replaces capture group 1, or the whole match, in an existing file. `g` replaces every match. |
142
- | `fileMode` | Octal permissions. New files default to `600`; existing files keep their mode. |
143
- | `overwrite` | `file`: allow replacing an existing destination, for rotating single-value files such as keys. Without it an existing destination is refused; with it the dialog warns in red. |
144
- | `command` | `command`: shell command reading the staged file `{secret}`, e.g. `ansible-vault encrypt_string --stdin-name db_password < {secret} >> vault.yml`. Stdout is discarded; stderr is shown with the value redacted when the command fails. |
145
-
146
- Writes are atomic (temp file + rename) and verified by re-reading the destination. When verification fails, the original content and mode are restored from memory (a newly created file is removed); no backup file is written, so no copy of a secret is left outside the protected destination. The staged file is overwritten and deleted after every apply attempt, and when the tool is cancelled or aborted. Staged files left by pi processes that have exited are removed at session start.
147
-
148
- ### Protection after the write
149
-
150
- - **Blocked reads.** `read`, `edit`, `write`, and `grep` on a destination or the staging area are blocked. In bash, each simple command is checked on its own: it is blocked when a protected path is an argument of a command that prints, copies, or opens files (`cat`, `head`, `grep`, `sed`, `cp`, `base64`, …, also behind `sudo`, `env`, `timeout`, `xargs`), a `<` or `>` redirection target, or inside `sh -c`, `eval`, `$(…)`, or backticks. Commands that only pass the path to a consumer, such as `--env-file .env` or `test -s .env`, still run.
151
- - **Redaction.** Any tool result or context message containing a secret value is rewritten to `[REDACTED]`. Values are reloaded from protected destinations at session start.
152
- - **Registry.** Protected locations (never values) live in `~/.pi/agent/secret-drop/registry.json`. `/secret-drop` lists them; `/secret-drop forget <path>` removes one.
153
-
154
- ### Limits
155
-
156
- - Requires the interactive terminal UI. In RPC, JSON, and print modes the tool fails instead of falling back to a plain-text prompt.
157
- - The dialog is a centered overlay, which pi-tui cannot draw over rows holding terminal images. Set `PI_ASK_USER_DISPLAY_MODE=inline` (the variable pi-ask-user reads) in the shell that launches pi to render it inline instead.
158
- - The bash guard parses command lines, not programs. It stops accidental reads, not a determined agent: an indirect path (a variable, a glob, a script or `python -c` that prints the file) passes through. Redaction is the second layer for that output.
159
- - The rename replaces the destination's inode: hard links to it break and the file becomes owned by the user who runs the apply command. Symlinks are resolved and kept.
160
- - A multi-line quoted `KEY="…` value is replaced on its first line only.
161
- - Values shorter than 4 characters are not redacted. Values applied with `format: "command"` are redacted for the rest of the session only.
162
- - The apply command is shown before it runs; review it, since a `command` can send the staged value anywhere.
163
-
164
- ## Other safety extensions
165
-
166
- pi-robot-hand depends on no other extension and runs alongside command guards such as cc-safety-net. A guard that scans every tool call's input may block `robot_hand` when the text of a command names a sensitive path such as `.env`, even though `robot_hand` only displays it. When that happens, the agent writes the command in chat and you run it yourself.
69
+ `secret_drop` used to be the separate `pi-secret-drop` package.
70
+ While it is still installed, pi-robot-hand leaves `secret_drop` to it and warns you to remove it with `pi remove npm:pi-secret-drop`.
71
+ Protected files carry over.
167
72
 
168
73
  ## Development
169
74
 
@@ -173,9 +78,7 @@ npm run check # tsc --noEmit
173
78
  npm test # builds dist/, then node --test
174
79
  ```
175
80
 
176
- `lib/` holds the secret placement and write logic shared by the extension and the apply script. The extension imports it as TypeScript, so pi's `/reload` picks up an upgrade; Node caches `.js` and `.mjs` modules for the life of the process. `npm run build` compiles `lib/` to `dist/` for the apply script, which runs with plain `node` because Node does not strip TypeScript types under `node_modules`. `npm pack` and `npm publish` build first.
177
-
178
- Releases publish from GitHub Actions through npm trusted publishing: bump `version` in `package.json`, commit, and push a matching `v<version>` tag.
81
+ Push a `v<version>` tag matching `package.json` to publish through GitHub Actions.
179
82
 
180
83
  ## License
181
84
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-robot-hand",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "The lazy kit for pi: no IDE, no copy-paste, safety net still on. The agent hands you commands (prompt, clipboard, or a Herdr pane that reports back), answers your ! commands, and takes secrets through a masked dialog it never sees",
5
5
  "type": "module",
6
6
  "license": "MIT",