pi-keeper 0.0.0-stage → 0.1.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/CHANGELOG.md +141 -0
- package/LICENSE +201 -0
- package/NOTICE +36 -0
- package/README.md +71 -2
- package/extensions/ask-heartbeat.ts +55 -0
- package/extensions/ask-mailbox.ts +515 -0
- package/extensions/ask-server.ts +461 -0
- package/extensions/attention.ts +24 -0
- package/extensions/cc-extensions-compat.ts +103 -0
- package/extensions/child-auto.ts +32 -0
- package/extensions/child-cwd.ts +78 -0
- package/extensions/child-default.ts +32 -0
- package/extensions/child-lane.ts +134 -0
- package/extensions/child-plan.ts +12 -0
- package/extensions/config.ts +359 -0
- package/extensions/dialog-lock.ts +70 -0
- package/extensions/dialog.ts +420 -0
- package/extensions/index.ts +3639 -0
- package/extensions/modes.ts +1382 -0
- package/extensions/options.ts +118 -0
- package/extensions/perf.ts +54 -0
- package/extensions/plan-approval.ts +345 -0
- package/extensions/preview.ts +234 -0
- package/extensions/project-rules.ts +634 -0
- package/extensions/prompt-blocks.ts +163 -0
- package/extensions/remote-relay.ts +168 -0
- package/extensions/rtk-rewrite.ts +60 -0
- package/extensions/rulebook.ts +362 -0
- package/extensions/rules-line.ts +71 -0
- package/extensions/rules-view.ts +187 -0
- package/extensions/rules.ts +579 -0
- package/extensions/secure-file.ts +157 -0
- package/extensions/session-grant-store.ts +157 -0
- package/extensions/session-grants.ts +160 -0
- package/extensions/settings-panel.ts +252 -0
- package/extensions/shell-highlight-bridge.ts +50 -0
- package/extensions/subagents-bridge.ts +129 -0
- package/extensions/telemetry.ts +310 -0
- package/extensions/thinking.ts +62 -0
- package/extensions/title.ts +80 -0
- package/extensions/ui-relay.ts +154 -0
- package/extensions/utils.ts +4984 -0
- package/package.json +67 -5
- package/prompt-templates/new-rule.md +30 -0
- package/prompts/auto-mode.md +16 -0
- package/prompts/child-auto.md +26 -0
- package/prompts/child-default.md +21 -0
- package/prompts/child-plan.md +16 -0
- package/prompts/contract.md +29 -0
- package/prompts/default-mode.md +8 -0
- package/prompts/plan-mode.md +45 -0
- package/prompts/rule-warning.md +8 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.1 - 2026-11-18
|
|
4
|
+
|
|
5
|
+
A review of the whole package. Most entries close a way for a call to run without the
|
|
6
|
+
question it should get.
|
|
7
|
+
|
|
8
|
+
### Security
|
|
9
|
+
|
|
10
|
+
- A single `subagent` call is judged by its `gate`, `acceptance` verify commands and
|
|
11
|
+
`output` file, as workflow children already were. A `schedule.create` of a workflow
|
|
12
|
+
asks.
|
|
13
|
+
- Shell keywords (`for`, `do`, `if`, ...) are never remembered as a command prefix,
|
|
14
|
+
which let any loop body run without a question. A loop gets the exact-command options.
|
|
15
|
+
- A backslash at the end of a line joins the lines as bash does (`su\⏎do id`).
|
|
16
|
+
- Project `deny` and `ask` rules match the command by path or behind a launcher: with
|
|
17
|
+
`Bash(make deploy *)`, `/usr/bin/make deploy` and `exec make deploy` are denied too.
|
|
18
|
+
`Bash(rm:*)` is read as `Bash(rm *)`.
|
|
19
|
+
- More secret reads ask in every mode: `grep -f.env`, `git show HEAD:.env`,
|
|
20
|
+
`ls | xargs cat`, a glob under `~` that matches a secret, and environment dumps
|
|
21
|
+
(`env`, `printenv`, `/proc/*/environ`). Exclude filters (`--exclude=.env`) do not ask.
|
|
22
|
+
- `~user/...`, `~-` and a glob outside the project (`cat /etc/pass*`) count as outside.
|
|
23
|
+
- Auto mode asks before a redirection writes outside the project (`echo x > ~/notes.txt`).
|
|
24
|
+
Writes to the system temp dir ask.
|
|
25
|
+
- `sudo` and dangerous commands are seen through more launchers and shells (`exec`,
|
|
26
|
+
`find -exec`, `pwsh`, `nsenter`). `runuser` is a privilege command. `sudo` after
|
|
27
|
+
`ssh host` asks instead of being denied.
|
|
28
|
+
- Download-and-run is caught behind a wrapper or a path (`curl x | env -i bash`).
|
|
29
|
+
- More commands are never remembered as a prefix (`tsx`, `uvx`, `dotnet`, `psql`, ...).
|
|
30
|
+
`git rebase --exec`, `git submodule foreach` and `git bisect run` are never covered
|
|
31
|
+
by a rule.
|
|
32
|
+
- Smaller: an awk `/` after `x++` hid a pipe to a shell; a restored plan file path must
|
|
33
|
+
be inside the plans directory; with a git repository as home, a subagent's working
|
|
34
|
+
directory is checked against the parent's; `/rules` prints no terminal escape
|
|
35
|
+
sequences; dialogs show zero-width characters as `�`.
|
|
36
|
+
|
|
37
|
+
### Fixed
|
|
38
|
+
|
|
39
|
+
- `cd` into another repository combined with git asked again and again. The dialog now
|
|
40
|
+
offers *Yes, and allow git in `<repo>/` this session*.
|
|
41
|
+
- The session log redacts more secrets (non-bash tool input, `-u user:pass`, URL
|
|
42
|
+
passwords, token headers).
|
|
43
|
+
- A background ask larger than the mailbox limit made the child wait for the timeout.
|
|
44
|
+
It is now denied at once. Turning background asks off in `/keeper` denies pending
|
|
45
|
+
asks with "background asks were turned off in the parent session".
|
|
46
|
+
- A background ask that an open dialog already covers opens no second dialog.
|
|
47
|
+
- A malformed `trusted-rules.json` is no longer overwritten; pi-keeper warns instead.
|
|
48
|
+
- `/mode constructor` blocked every tool call.
|
|
49
|
+
- *Ignore for this session* on project rules no longer outlives `/new` and `/resume`.
|
|
50
|
+
- A glob with many `*` could freeze pi.
|
|
51
|
+
- `/rules` crashed with "Rendered line N exceeds terminal width" on long text.
|
|
52
|
+
- A command after `!` is matched by your rules like the same command alone.
|
|
53
|
+
|
|
54
|
+
### Changed
|
|
55
|
+
|
|
56
|
+
- `project-exact-commands` is **on by default**: the dialog for a command no prefix can
|
|
57
|
+
cover offers *Yes, and always allow this exact command in this project*. Not offered
|
|
58
|
+
for removals, privilege commands, program-running flags or writes outside the project.
|
|
59
|
+
- `/keeper` has two tabs: **Settings** and **Subagents**.
|
|
60
|
+
- The mode line after a switch is **off by default**; turn it on in `/keeper` (Dialog)
|
|
61
|
+
or with `modeFlashSecs`.
|
|
62
|
+
- A rulebook file with no frontmatter, or a condition that matches ordinary text, is
|
|
63
|
+
skipped with a warning.
|
|
64
|
+
|
|
65
|
+
### Added
|
|
66
|
+
|
|
67
|
+
- `BashExact(<command>)` entries in `.pi/settings.local.json` (`allow` only): this exact
|
|
68
|
+
command text runs without a question in default mode. The project option saves one
|
|
69
|
+
when the command cannot be written as `Bash(...)`, such as a `for` loop.
|
|
70
|
+
`/permissions` lists them as "(exact text)".
|
|
71
|
+
- *Yes, and allow git in `<repo>/` this session*: after `cd` into another repository,
|
|
72
|
+
git there runs without the question (dangerous git commands still ask). Session only,
|
|
73
|
+
shared with subagents, removable in `/permissions`.
|
|
74
|
+
- `/keeper mode-working-row` (`modeWorkingRow`, default off): the mode in the working
|
|
75
|
+
row (`⏵⏵ auto · Working`).
|
|
76
|
+
- `/keeper mode-status` (`modeStatus`, default on): off hides the mode in the footer.
|
|
77
|
+
- `example-rule.md`, a dummy rule that never fires, is created in
|
|
78
|
+
`~/.pi/agent/pi-keeper/rules/` when it holds no rule file.
|
|
79
|
+
- `/new-rule <what must not happen>`: the model writes a rule file and tests its regex.
|
|
80
|
+
|
|
81
|
+
## 0.1.0 - 2026-11-17
|
|
82
|
+
|
|
83
|
+
First public release.
|
|
84
|
+
|
|
85
|
+
- Three modes — `default`, `auto`, `plan` — cycled with Alt+M / Ctrl+Shift+M,
|
|
86
|
+
`/mode` or `/plan`; the mode is restored per branch on resume.
|
|
87
|
+
- Per-project rules: `allow` / `ask` / `deny` entries that persist in
|
|
88
|
+
`.pi/settings.local.json`, plus session grants and one-run grants. A rules
|
|
89
|
+
file that cannot be read or parsed makes every shell command ask.
|
|
90
|
+
- Checks fail closed: a tool call whose check throws is blocked, not run.
|
|
91
|
+
Malformed `pi-keeper.json` is never overwritten when a setting is saved.
|
|
92
|
+
- Command and path checks: `echo` and `printf` of a credential-named variable
|
|
93
|
+
ask; global options before the subcommand of `docker`, `podman`, `cargo`,
|
|
94
|
+
`gem`, `poetry`, `twine` and `gh` do not hide a dangerous subcommand;
|
|
95
|
+
`mcp` and `subagent` are never read-only by annotation; symlinks are judged
|
|
96
|
+
by their target; `$PWD` at the start of a path expands like `$HOME`; reads
|
|
97
|
+
under the system temp dir never ask, writes there still do.
|
|
98
|
+
- A glob operand is judged by what it matches on disk. `cat conf/*` asks when
|
|
99
|
+
`conf/` holds an `id_rsa`; a glob, or a plain name, that is a link leading
|
|
100
|
+
out of the project (`src/link.py` pointing at a file elsewhere) asks as an
|
|
101
|
+
outside read; a glob that matches more than 2000 files asks.
|
|
102
|
+
- `rtk grep`, `rtk rg`, `rtk find` and `rtk tree` run an unquoted glob that
|
|
103
|
+
cannot become a flag without asking: `src/*.py`, `./*.py` and
|
|
104
|
+
`--include=*.py` keep their literal prefix in every expansion. `*.py`,
|
|
105
|
+
`--pre=*.sh`, `$VAR`, `{-a,b}` and any glob that leaves the project (`../*`,
|
|
106
|
+
`/etc/pass*`, `~/*`) ask: a file named `--pre=x.sh` would reach `rg` as an
|
|
107
|
+
option.
|
|
108
|
+
- The rulebook: regex rules that fire only when the model slips, with an
|
|
109
|
+
evidence column and a warning injected into the prompt.
|
|
110
|
+
- Plan mode: the plan is written to a plan file, reviewed in the transcript and
|
|
111
|
+
approved before anything else is written.
|
|
112
|
+
- Command colors default to `shell-highlight` when pi-shell-highlight is
|
|
113
|
+
installed and to `dim` when not (resolved when each dialog opens); an explicit
|
|
114
|
+
`shell-highlight` without that package means `dim`.
|
|
115
|
+
- pi-cc-extensions' plan approval: a one-time dialog at session start offers to
|
|
116
|
+
add `exit_plan_mode` to `excludeRenderers` (apply it, put a prompt for the agent
|
|
117
|
+
in the editor, not now, or don't ask again).
|
|
118
|
+
- Subagents: children inherit the parent's mode through a bridge into
|
|
119
|
+
pi-subagents; background children can ask the parent's user. A queued ask
|
|
120
|
+
already covered by an approval in another subagent opens no dialog. A
|
|
121
|
+
background child in auto whose parent's grants cannot be read is locked.
|
|
122
|
+
- Workflow, `parallel`, `tasks` and `chain` children (pi-subagents 0.85 and
|
|
123
|
+
newer) work in every mode, plan included: the `subagent_launch` call that
|
|
124
|
+
pi-subagents makes for each child, which the model never sees, is allowed
|
|
125
|
+
under the same condition as `subagent` (the bridge must be registered) and is
|
|
126
|
+
never read-only or listable.
|
|
127
|
+
- A launch is judged by what the child leaves behind too: its `gate` and
|
|
128
|
+
`acceptance.verify` commands as bash calls and the file its `output` writes as
|
|
129
|
+
a write, with the mode's own rules; the strictest answer wins, and the dialog
|
|
130
|
+
or the deny names the step. A command that sets `env`, a command whose `cwd`
|
|
131
|
+
is outside the project, and a `commands` or `output` value of a shape the
|
|
132
|
+
check cannot read ask in every mode, even for a command the rules call
|
|
133
|
+
read-only. An `output` path whose artifact directory is a link leading out of
|
|
134
|
+
the sessions directory is not taken for the child's report.
|
|
135
|
+
- Background asks pop up as soon as no other dialog is open (*When background
|
|
136
|
+
asks pop up*: `always` by default; `idle` waits for an idle session, `badge`
|
|
137
|
+
only opens through `/approvals`).
|
|
138
|
+
- Permission telemetry in the session log, with secrets redacted from bash
|
|
139
|
+
commands, plus the `scripts/extract_flow.py` and
|
|
140
|
+
`scripts/aggregate_failures.py` readers, which live in the repository rather
|
|
141
|
+
than the npm package.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
pi-keeper
|
|
2
|
+
Copyright 2026 Daniel Blei
|
|
3
|
+
|
|
4
|
+
This product is licensed under the Apache License, Version 2.0. See LICENSE.
|
|
5
|
+
|
|
6
|
+
Third-party notices
|
|
7
|
+
-------------------
|
|
8
|
+
|
|
9
|
+
OpenCode — the COMMAND_ARITY table in extensions/modes.ts is
|
|
10
|
+
adapted from OpenCode's permission/arity.ts (MIT). Source:
|
|
11
|
+
https://github.com/anomalyco/opencode/blob/219b473e660994ac69a0c5d753ac65da951f3bf8/packages/opencode/src/permission/arity.ts
|
|
12
|
+
|
|
13
|
+
MIT License
|
|
14
|
+
|
|
15
|
+
Copyright (c) 2025 opencode
|
|
16
|
+
|
|
17
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
18
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
19
|
+
in the Software without restriction, including without limitation the rights
|
|
20
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
21
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
22
|
+
furnished to do so, subject to the following conditions:
|
|
23
|
+
|
|
24
|
+
The above copyright notice and this permission notice shall be included in all
|
|
25
|
+
copies or substantial portions of the Software.
|
|
26
|
+
|
|
27
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
28
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
29
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
30
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
31
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
32
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
33
|
+
SOFTWARE.
|
|
34
|
+
|
|
35
|
+
The @earendil-works/pi-* packages that each package lists as peer dependencies
|
|
36
|
+
are not bundled here: the pi installation that loads the package provides them.
|
package/README.md
CHANGED
|
@@ -1,3 +1,72 @@
|
|
|
1
|
-
#
|
|
1
|
+
# pi-keeper
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Permission modes and a project rulebook for pi: `default`, `auto` and `plan`, per-project rules, and a plan → execute handoff. Each mode decides which tool calls run, which ask you, and which are blocked.
|
|
4
|
+
|
|
5
|
+
> A personal project, shared as is. pi-keeper reduces accidental damage by asking before risky actions. It is not a sandbox or a security boundary. Run untrusted work in a container or a VM.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pi install npm:pi-keeper # every session; writes ~/.pi/agent/settings.json
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`pi update --extensions` picks up new releases. From a checkout, see [Working from a checkout](https://github.com/DanielBlei/pi-packages/blob/main/pi-keeper/docs/development.md#working-from-a-checkout).
|
|
14
|
+
|
|
15
|
+
## Modes
|
|
16
|
+
|
|
17
|
+
| Mode | Use it for | Runs without asking | Asks | Blocked |
|
|
18
|
+
|---|---|---|---|---|
|
|
19
|
+
| `default` (blue) | everyday work: you approve changes | reads, searches, read-only bash, anything your rules cover, read-only tools | edits, other bash, other tools | `sudo` & co |
|
|
20
|
+
| `auto` (yellow) | a trusted task you are watching | almost everything, including deletes inside the project | dangerous or destructive commands, protected paths, writes outside the project, secrets, the first outside read | `sudo` & co |
|
|
21
|
+
| `plan` (green) | researching and writing a plan | reads, read-only bash, the plan file, the scratch dir | other bash | edits, other tools, dangerous commands, `sudo` & co |
|
|
22
|
+
|
|
23
|
+
In plan mode the agent writes a plan file and calls `exit_plan_mode`; you then pick `auto`, or `default` with approval for each edit. The [guide](https://github.com/DanielBlei/pi-packages/blob/main/pi-keeper/docs/guide.md#modes-at-a-glance) has the full action-by-action matrix.
|
|
24
|
+
|
|
25
|
+
## Commands
|
|
26
|
+
|
|
27
|
+
| Command | What it does |
|
|
28
|
+
|---|---|
|
|
29
|
+
| **Alt+M**, **Ctrl+Shift+M** | Cycle `default → auto → plan` (Ctrl+Shift+M needs the kitty keyboard protocol) |
|
|
30
|
+
| `/mode` | Pick a mode |
|
|
31
|
+
| `/plan [prompt\|open]` | Start plan mode, or open the plan |
|
|
32
|
+
| `/permissions` | List every rule with its source; remove the ones you pick |
|
|
33
|
+
| `/approvals` | Open the permission asks that background subagents are waiting on |
|
|
34
|
+
| `/rules` | Open the rulebook: rules that fire when the model slips |
|
|
35
|
+
| `/keeper [setting value]` | Settings panel, or set one directly |
|
|
36
|
+
|
|
37
|
+
Dialogs offer *Yes* once, *Don't ask again this session*, or *Always allow … in this project*, which is saved to `.pi/settings.local.json` (default mode only). `ask` and `deny` rules apply in every mode; `allow` rules load after you review the file once. Details: [Managing rules](https://github.com/DanielBlei/pi-packages/blob/main/pi-keeper/docs/guide.md#managing-rules), [The dialogs](https://github.com/DanielBlei/pi-packages/blob/main/pi-keeper/docs/guide.md#the-dialogs), [/keeper](https://github.com/DanielBlei/pi-packages/blob/main/pi-keeper/docs/guide.md#keeper).
|
|
38
|
+
|
|
39
|
+
## Optional companions
|
|
40
|
+
|
|
41
|
+
| Package | What it adds |
|
|
42
|
+
|---|---|
|
|
43
|
+
| [pi-subagents](https://www.npmjs.com/package/pi-subagents) | children run in your mode, and background asks reach your dialog ([Subagents](https://github.com/DanielBlei/pi-packages/blob/main/pi-keeper/docs/guide.md#subagents-pi-subagents)) |
|
|
44
|
+
| [pi-shell-highlight](https://www.npmjs.com/package/pi-shell-highlight) | colored command names and heredocs in the permission dialog |
|
|
45
|
+
|
|
46
|
+
Without them pi-keeper works standalone.
|
|
47
|
+
|
|
48
|
+
## Security and limitations
|
|
49
|
+
|
|
50
|
+
pi-keeper decides from the command text and tool arguments. A shell is too flexible for that to be complete, so it does not guarantee a harmful command is caught.
|
|
51
|
+
|
|
52
|
+
- No mode is bulletproof; `auto` lets the most through. Prefer `plan` or `default` and add the narrowest rule that works.
|
|
53
|
+
- Read each dialog before you approve it, and review changes before you commit, push or deploy.
|
|
54
|
+
- For untrusted code or unattended runs, isolate with a container, a VM or a separate user without your credentials.
|
|
55
|
+
|
|
56
|
+
Use at your own risk. Provided "AS IS", without warranties; see sections 7 and 8 of the [LICENSE](https://github.com/DanielBlei/pi-packages/blob/main/pi-keeper/LICENSE). Full text: [guide](https://github.com/DanielBlei/pi-packages/blob/main/pi-keeper/docs/guide.md#security-and-limitations).
|
|
57
|
+
|
|
58
|
+
## Compatibility
|
|
59
|
+
|
|
60
|
+
Tested with pi 1.5.2, pi-subagents 0.89.0 and pi-cc-extensions 1.0.20. pi-cc-extensions can hide the plan row: list `exit_plan_mode` under `excludeRenderers` in its settings, or pi-keeper asks once per session. More in the [guide](https://github.com/DanielBlei/pi-packages/blob/main/pi-keeper/docs/guide.md#compatibility).
|
|
61
|
+
|
|
62
|
+
## More
|
|
63
|
+
|
|
64
|
+
[Guide](https://github.com/DanielBlei/pi-packages/blob/main/pi-keeper/docs/guide.md) (every mode, dialog, rule and setting) · [Design](https://github.com/DanielBlei/pi-packages/blob/main/pi-keeper/docs/design.md) (reasoning and threat model) · [Architecture](https://github.com/DanielBlei/pi-packages/blob/main/pi-keeper/docs/architecture.md) · [Rulebook](https://github.com/DanielBlei/pi-packages/blob/main/pi-keeper/docs/rulebook.md) · [Development](https://github.com/DanielBlei/pi-packages/blob/main/pi-keeper/docs/development.md)
|
|
65
|
+
|
|
66
|
+
## Acknowledgements
|
|
67
|
+
|
|
68
|
+
Rule spellings such as `Bash(git add:*)` and `WebFetch(domain:<host>)` are read for compatibility with the settings format [Claude Code](https://claude.com/claude-code) documents. The modes, the plan flow and everything else are written from scratch; nothing here comes from Claude Code's code or prompts. The command arity table in `extensions/modes.ts` is adapted from [OpenCode](https://github.com/anomalyco/opencode) (MIT, see [NOTICE](https://github.com/DanielBlei/pi-packages/blob/main/pi-keeper/NOTICE)). The rulebook's file shape is an idea from [oh-my-pi](https://github.com/can1357/oh-my-pi); no code was taken. Built on [pi](https://www.npmjs.com/package/@earendil-works/pi-coding-agent). Not affiliated with or endorsed by Anthropic, OpenCode, oh-my-pi or the pi project; their names are used only to say what this works with or credits.
|
|
69
|
+
|
|
70
|
+
## License
|
|
71
|
+
|
|
72
|
+
Apache-2.0, see [LICENSE](https://github.com/DanielBlei/pi-packages/blob/main/pi-keeper/LICENSE) and [NOTICE](https://github.com/DanielBlei/pi-packages/blob/main/pi-keeper/NOTICE).
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The parent's "I am listening" note for the ask mailbox: while its ask
|
|
3
|
+
* server runs, the parent keeps `<askDir>/alive` fresh (`{v:1, pid, at}`).
|
|
4
|
+
* A background child sends an ask only while the note is fresh and names the
|
|
5
|
+
* pid that published the session snapshot. Without it a child could wait out
|
|
6
|
+
* its whole timeout on a parent that never started its server (an older
|
|
7
|
+
* version, background asks off) or has stopped it. The file is removed when
|
|
8
|
+
* the server stops. Written and read with the mailbox's hardening
|
|
9
|
+
* (secure-file.ts); free of pi imports.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { rmSync } from "node:fs";
|
|
13
|
+
import { join } from "node:path";
|
|
14
|
+
import { ensureAskDir, type MailboxOptions } from "./ask-mailbox.ts";
|
|
15
|
+
import { readJsonFile, writeFileAtomic } from "./secure-file.ts";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The parent rewrites the note at most this often. Ten seconds keeps a margin of
|
|
19
|
+
* five under HEARTBEAT_STALE_MS, so a poll a little late never makes the parent
|
|
20
|
+
* look gone, while the write (create + write + rename) drops from 30 to 6 a minute.
|
|
21
|
+
*/
|
|
22
|
+
export const HEARTBEAT_EVERY_MS = 10_000;
|
|
23
|
+
/** A note older than this is stale: the parent is not listening. */
|
|
24
|
+
export const HEARTBEAT_STALE_MS = 15_000;
|
|
25
|
+
const MAX_HEARTBEAT_BYTES = 1024;
|
|
26
|
+
const MAX_AHEAD_MS = 3000;
|
|
27
|
+
|
|
28
|
+
const heartbeatFile = (dir: string): string => join(dir, "alive");
|
|
29
|
+
|
|
30
|
+
/** Parent: publish the note. Throws on an unusable mailbox. */
|
|
31
|
+
export function writeHeartbeat(dir: string, pid: number, at: number, options: MailboxOptions = {}): void {
|
|
32
|
+
ensureAskDir(dir, options);
|
|
33
|
+
writeFileAtomic(heartbeatFile(dir), JSON.stringify({ v: 1, pid, at }));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Parent: withdraw the note. Never throws. */
|
|
37
|
+
export function removeHeartbeat(dir: string): void {
|
|
38
|
+
try {
|
|
39
|
+
rmSync(heartbeatFile(dir), { force: true });
|
|
40
|
+
} catch {
|
|
41
|
+
// the note goes stale on its own
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Child: whether `pid` published a note less than HEARTBEAT_STALE_MS before `now`. Missing, malformed, foreign or stale is false. */
|
|
46
|
+
export function heartbeatFresh(dir: string, pid: number, now: number, options: MailboxOptions = {}): boolean {
|
|
47
|
+
try {
|
|
48
|
+
const value = readJsonFile(heartbeatFile(dir), MAX_HEARTBEAT_BYTES, options.uid) as { v?: unknown; pid?: unknown; at?: unknown } | null;
|
|
49
|
+
if (value === null || typeof value !== "object" || value.v !== 1 || value.pid !== pid || typeof value.at !== "number" || !Number.isFinite(value.at)) return false;
|
|
50
|
+
// a little clock skew is fine; a note from the future is not a fresh one
|
|
51
|
+
return value.at - now < MAX_AHEAD_MS && now - value.at < HEARTBEAT_STALE_MS;
|
|
52
|
+
} catch {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
}
|