veto-leash 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/IMPLEMENTATION_PLAN.md +2194 -0
  2. package/LICENSE +201 -0
  3. package/README.md +260 -0
  4. package/dist/audit/index.d.ts +38 -0
  5. package/dist/audit/index.d.ts.map +1 -0
  6. package/dist/audit/index.js +132 -0
  7. package/dist/audit/index.js.map +1 -0
  8. package/dist/cli.d.ts +3 -0
  9. package/dist/cli.d.ts.map +1 -0
  10. package/dist/cli.js +406 -0
  11. package/dist/cli.js.map +1 -0
  12. package/dist/cloud/index.d.ts +40 -0
  13. package/dist/cloud/index.d.ts.map +1 -0
  14. package/dist/cloud/index.js +115 -0
  15. package/dist/cloud/index.js.map +1 -0
  16. package/dist/compiler/builtins.d.ts +6 -0
  17. package/dist/compiler/builtins.d.ts.map +1 -0
  18. package/dist/compiler/builtins.js +129 -0
  19. package/dist/compiler/builtins.js.map +1 -0
  20. package/dist/compiler/cache.d.ts +6 -0
  21. package/dist/compiler/cache.d.ts.map +1 -0
  22. package/dist/compiler/cache.js +49 -0
  23. package/dist/compiler/cache.js.map +1 -0
  24. package/dist/compiler/index.d.ts +3 -0
  25. package/dist/compiler/index.d.ts.map +1 -0
  26. package/dist/compiler/index.js +48 -0
  27. package/dist/compiler/index.js.map +1 -0
  28. package/dist/compiler/llm.d.ts +3 -0
  29. package/dist/compiler/llm.d.ts.map +1 -0
  30. package/dist/compiler/llm.js +69 -0
  31. package/dist/compiler/llm.js.map +1 -0
  32. package/dist/compiler/prompt.d.ts +2 -0
  33. package/dist/compiler/prompt.d.ts.map +1 -0
  34. package/dist/compiler/prompt.js +37 -0
  35. package/dist/compiler/prompt.js.map +1 -0
  36. package/dist/config/loader.d.ts +22 -0
  37. package/dist/config/loader.d.ts.map +1 -0
  38. package/dist/config/loader.js +100 -0
  39. package/dist/config/loader.js.map +1 -0
  40. package/dist/config/schema.d.ts +42 -0
  41. package/dist/config/schema.d.ts.map +1 -0
  42. package/dist/config/schema.js +93 -0
  43. package/dist/config/schema.js.map +1 -0
  44. package/dist/matcher.d.ts +22 -0
  45. package/dist/matcher.d.ts.map +1 -0
  46. package/dist/matcher.js +69 -0
  47. package/dist/matcher.js.map +1 -0
  48. package/dist/native/aider.d.ts +10 -0
  49. package/dist/native/aider.d.ts.map +1 -0
  50. package/dist/native/aider.js +120 -0
  51. package/dist/native/aider.js.map +1 -0
  52. package/dist/native/claude-code.d.ts +14 -0
  53. package/dist/native/claude-code.d.ts.map +1 -0
  54. package/dist/native/claude-code.js +273 -0
  55. package/dist/native/claude-code.js.map +1 -0
  56. package/dist/native/cursor.d.ts +11 -0
  57. package/dist/native/cursor.d.ts.map +1 -0
  58. package/dist/native/cursor.js +105 -0
  59. package/dist/native/cursor.js.map +1 -0
  60. package/dist/native/index.d.ts +35 -0
  61. package/dist/native/index.d.ts.map +1 -0
  62. package/dist/native/index.js +171 -0
  63. package/dist/native/index.js.map +1 -0
  64. package/dist/native/opencode.d.ts +22 -0
  65. package/dist/native/opencode.d.ts.map +1 -0
  66. package/dist/native/opencode.js +225 -0
  67. package/dist/native/opencode.js.map +1 -0
  68. package/dist/native/windsurf.d.ts +14 -0
  69. package/dist/native/windsurf.d.ts.map +1 -0
  70. package/dist/native/windsurf.js +198 -0
  71. package/dist/native/windsurf.js.map +1 -0
  72. package/dist/types.d.ts +38 -0
  73. package/dist/types.d.ts.map +1 -0
  74. package/dist/types.js +11 -0
  75. package/dist/types.js.map +1 -0
  76. package/dist/ui/colors.d.ts +21 -0
  77. package/dist/ui/colors.d.ts.map +1 -0
  78. package/dist/ui/colors.js +41 -0
  79. package/dist/ui/colors.js.map +1 -0
  80. package/dist/watchdog/index.d.ts +25 -0
  81. package/dist/watchdog/index.d.ts.map +1 -0
  82. package/dist/watchdog/index.js +57 -0
  83. package/dist/watchdog/index.js.map +1 -0
  84. package/dist/watchdog/restore.d.ts +16 -0
  85. package/dist/watchdog/restore.d.ts.map +1 -0
  86. package/dist/watchdog/restore.js +56 -0
  87. package/dist/watchdog/restore.js.map +1 -0
  88. package/dist/watchdog/snapshot.d.ts +38 -0
  89. package/dist/watchdog/snapshot.d.ts.map +1 -0
  90. package/dist/watchdog/snapshot.js +166 -0
  91. package/dist/watchdog/snapshot.js.map +1 -0
  92. package/dist/watchdog/watcher.d.ts +28 -0
  93. package/dist/watchdog/watcher.d.ts.map +1 -0
  94. package/dist/watchdog/watcher.js +117 -0
  95. package/dist/watchdog/watcher.js.map +1 -0
  96. package/dist/wrapper/daemon.d.ts +12 -0
  97. package/dist/wrapper/daemon.d.ts.map +1 -0
  98. package/dist/wrapper/daemon.js +103 -0
  99. package/dist/wrapper/daemon.js.map +1 -0
  100. package/dist/wrapper/shims.d.ts +4 -0
  101. package/dist/wrapper/shims.d.ts.map +1 -0
  102. package/dist/wrapper/shims.js +390 -0
  103. package/dist/wrapper/shims.js.map +1 -0
  104. package/dist/wrapper/spawn.d.ts +4 -0
  105. package/dist/wrapper/spawn.d.ts.map +1 -0
  106. package/dist/wrapper/spawn.js +35 -0
  107. package/dist/wrapper/spawn.js.map +1 -0
  108. package/package.json +46 -0
  109. package/src/audit/index.ts +172 -0
  110. package/src/cli.ts +503 -0
  111. package/src/cloud/index.ts +139 -0
  112. package/src/compiler/builtins.ts +137 -0
  113. package/src/compiler/cache.ts +51 -0
  114. package/src/compiler/index.ts +59 -0
  115. package/src/compiler/llm.ts +83 -0
  116. package/src/compiler/prompt.ts +37 -0
  117. package/src/config/loader.ts +126 -0
  118. package/src/config/schema.ts +136 -0
  119. package/src/matcher.ts +89 -0
  120. package/src/native/aider.ts +150 -0
  121. package/src/native/claude-code.ts +308 -0
  122. package/src/native/cursor.ts +131 -0
  123. package/src/native/index.ts +233 -0
  124. package/src/native/opencode.ts +310 -0
  125. package/src/native/windsurf.ts +231 -0
  126. package/src/types.ts +48 -0
  127. package/src/ui/colors.ts +50 -0
  128. package/src/watchdog/index.ts +82 -0
  129. package/src/watchdog/restore.ts +74 -0
  130. package/src/watchdog/snapshot.ts +209 -0
  131. package/src/watchdog/watcher.ts +150 -0
  132. package/src/wrapper/daemon.ts +133 -0
  133. package/src/wrapper/shims.ts +409 -0
  134. package/src/wrapper/spawn.ts +47 -0
  135. package/tsconfig.json +20 -0
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" 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 Support. 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 2026 Plaw, Inc.
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/README.md ADDED
@@ -0,0 +1,260 @@
1
+ # veto-leash
2
+
3
+ **sudo for AI agents**
4
+
5
+ Your AI agent has root access to your codebase. You have... vibes.
6
+
7
+ ```bash
8
+ leash cc "don't delete test files"
9
+ ```
10
+
11
+ Now every destructive action requires explicit policy. No regex. No config files. Just English.
12
+
13
+ ## The Problem
14
+
15
+ AI coding agents can delete your test files, wipe your .env, run arbitrary migrations. Current permission systems require you to write regex patterns and understand glob syntax. You want to say "protect my tests" and be done.
16
+
17
+ ## The Solution
18
+
19
+ veto-leash compiles natural language restrictions into precise policies **once**, then enforces them at runtime with zero LLM latency.
20
+
21
+ ```
22
+ "don't delete test files"
23
+
24
+
25
+ ┌─────────────────────────────────────┐
26
+ │ Semantic Compilation (100ms) │
27
+ │ • Understands "test files" = test │
28
+ │ source code, not test-results.xml│
29
+ │ • Gemini 2.0 Flash + JSON Schema │
30
+ │ • Cached for instant reuse │
31
+ └─────────────────────────────────────┘
32
+
33
+
34
+ ┌─────────────────────────────────────┐
35
+ │ Policy │
36
+ │ action: delete │
37
+ │ include: *.test.*, *.spec.*, │
38
+ │ __tests__/**, test/** │
39
+ │ exclude: test-results.*, coverage/ │
40
+ └─────────────────────────────────────┘
41
+
42
+
43
+ Enforcement (0ms per check)
44
+ ```
45
+
46
+ ## Quick Start
47
+
48
+ ```bash
49
+ # Install
50
+ npm install -g veto-leash
51
+
52
+ # Get free Gemini API key (optional - builtins work without it)
53
+ # https://aistudio.google.com/apikey
54
+ export GEMINI_API_KEY="your-key"
55
+
56
+ # Use it
57
+ leash cc "don't delete test files"
58
+ ```
59
+
60
+ That's it. Your Claude Code session now blocks test file deletions.
61
+
62
+ ## How It Works
63
+
64
+ ### Three Enforcement Modes
65
+
66
+ | Mode | Use Case | How |
67
+ |------|----------|-----|
68
+ | **Wrapper** | Any agent | PATH hijacking, TCP daemon |
69
+ | **Native** | Claude Code, Windsurf, OpenCode | Hooks directly into agent |
70
+ | **Watchdog** | Background protection | File system monitoring, auto-restore |
71
+
72
+ ### Native Integrations
73
+
74
+ ```bash
75
+ # Claude Code - PreToolUse hooks
76
+ leash add "don't delete test files"
77
+ leash install cc
78
+
79
+ # Windsurf - Cascade hooks
80
+ leash add "protect .env"
81
+ leash install windsurf
82
+
83
+ # OpenCode - permission.bash rules
84
+ leash add "no migrations"
85
+ leash install oc
86
+ ```
87
+
88
+ ### Wrapper Mode (Works with anything)
89
+
90
+ ```bash
91
+ # Works with ANY CLI agent
92
+ leash cc "don't delete test files"
93
+ leash opencode "protect .env"
94
+ leash cursor "no database migrations"
95
+ leash aider "read-only src/core"
96
+ leash my-custom-agent "protect config"
97
+ ```
98
+
99
+ ### Watchdog Mode (Catches everything)
100
+
101
+ ```bash
102
+ # Background file protection - catches programmatic changes too
103
+ leash watch "protect test files"
104
+ ```
105
+
106
+ ## Supported Agents
107
+
108
+ | Agent | Native | Wrapper | Notes |
109
+ |-------|--------|---------|-------|
110
+ | Claude Code | PreToolUse hooks | PATH shims | Best support |
111
+ | Windsurf | Cascade hooks | PATH shims | Full support |
112
+ | OpenCode | permission.bash | PATH shims | Full support |
113
+ | Cursor | .cursorrules | PATH shims | Guidance only |
114
+ | Aider | .aider.conf.yml | PATH shims | Read-only files |
115
+ | Codex CLI | - | Watchdog | OS sandbox |
116
+ | GitHub Copilot | - | Wrapper | No hooks |
117
+ | Any CLI tool | - | PATH shims | Universal |
118
+
119
+ ## Project Configuration
120
+
121
+ Create a `.leash` file for team-wide policies:
122
+
123
+ ```yaml
124
+ # .leash
125
+ version: 1
126
+
127
+ policies:
128
+ - "don't delete test files"
129
+ - "protect .env"
130
+ - "no database migrations"
131
+
132
+ settings:
133
+ fail_closed: true
134
+ audit_log: true
135
+ ```
136
+
137
+ Then sync to your agents:
138
+
139
+ ```bash
140
+ leash sync cc
141
+ leash sync windsurf
142
+ ```
143
+
144
+ ## Commands
145
+
146
+ ```
147
+ leash <agent> "<restriction>" Wrap agent with policy
148
+ leash watch "<restriction>" Background file protection
149
+ leash explain "<restriction>" Preview policy without installing
150
+ leash add "<restriction>" Save policy for native install
151
+ leash init Create .leash config file
152
+ leash sync [agent] Apply .leash policies
153
+ leash install <agent> Install native hooks
154
+ leash uninstall <agent> Remove native hooks
155
+ leash list Show saved policies
156
+ leash audit [--tail] [--clear] View audit log
157
+ leash login Leash Cloud (coming soon)
158
+ leash status Show active sessions
159
+ leash clear Clear compilation cache
160
+ ```
161
+
162
+ ## Built-in Patterns
163
+
164
+ These work instantly without an API key:
165
+
166
+ | Phrase | What It Protects |
167
+ |--------|-----------------|
168
+ | `test files` | `*.test.*`, `*.spec.*`, `__tests__/**` |
169
+ | `.env` | `.env`, `.env.*`, excluding `.env.example` |
170
+ | `migrations` | `**/migrations/**`, `prisma/migrations/**` |
171
+ | `config` | `*.config.*`, `tsconfig*`, `.eslintrc*` |
172
+ | `lock files` | `package-lock.json`, `yarn.lock`, etc. |
173
+
174
+ ## Examples
175
+
176
+ ```bash
177
+ # Preview what a policy protects
178
+ leash explain "don't delete test files"
179
+
180
+ # Wrapper mode - intercepts shell commands
181
+ leash cc "don't delete test files"
182
+
183
+ # Native mode - integrates with agent's permission system
184
+ leash add "don't delete test files"
185
+ leash add "protect .env"
186
+ leash install cc
187
+
188
+ # Watchdog mode - file system monitoring
189
+ leash watch "protect test files"
190
+
191
+ # Team config
192
+ leash init # Creates .leash
193
+ leash sync windsurf # Applies to agent
194
+ ```
195
+
196
+ ## Environment Variables
197
+
198
+ | Variable | Description |
199
+ |----------|-------------|
200
+ | `GEMINI_API_KEY` | Required for custom restrictions (not builtins) |
201
+ | `LEASH_CLOUD_URL` | Leash Cloud API endpoint (coming soon) |
202
+ | `LEASH_API_KEY` | Leash Cloud API key (coming soon) |
203
+
204
+ ## Leash Cloud (Coming Soon)
205
+
206
+ - Team-wide policy sync
207
+ - Centralized audit logs
208
+ - LLM credits for compilation
209
+ - Policy analytics
210
+
211
+ Join the waitlist: https://leash.cloud
212
+
213
+ ## Philosophy
214
+
215
+ 1. **Semantic over syntactic** - "test files" means test source code, not files with "test" in the name
216
+ 2. **Compile once, enforce always** - LLM runs once at startup, enforcement is instant
217
+ 3. **Fail closed** - If the daemon is unreachable, commands are blocked
218
+ 4. **Defense in depth** - Native hooks + wrapper mode + watchdog = comprehensive protection
219
+ 5. **No config tax** - Natural language in, protection out
220
+
221
+ ## How veto-leash Protects Files
222
+
223
+ When you run `leash cc "don't delete test files"`:
224
+
225
+ 1. **Compile**: Natural language → glob patterns (via Gemini 2.0 Flash)
226
+ 2. **Start daemon**: TCP server on localhost (random port)
227
+ 3. **Create shims**: Shell wrappers for `rm`, `git rm`, etc.
228
+ 4. **Launch agent**: With modified PATH
229
+ 5. **Intercept**: Every shell command checks daemon first
230
+ 6. **Block or allow**: Based on policy
231
+
232
+ The agent never knows veto-leash is there - it just sees commands failing with clear error messages.
233
+
234
+ ## Security Model
235
+
236
+ - Localhost only (`127.0.0.1`)
237
+ - Random port each session
238
+ - Temp directory cleaned on exit
239
+ - No eval - patterns validated with micromatch
240
+ - Fail closed by default
241
+ - API key from environment only
242
+
243
+ ## Platform Support
244
+
245
+ - macOS
246
+ - Linux
247
+ - Windows (PowerShell shims)
248
+ - WSL
249
+
250
+ ## License
251
+
252
+ MIT
253
+
254
+ ## Credits
255
+
256
+ Built by [Plaw, Inc.](https://plaw.io) for the [Veto](https://veto.dev) product line.
257
+
258
+ ---
259
+
260
+ Ship faster. Sleep better.
@@ -0,0 +1,38 @@
1
+ export interface AuditEntry {
2
+ timestamp: string;
3
+ action: 'blocked' | 'allowed' | 'restored';
4
+ event: string;
5
+ target: string;
6
+ policy?: string;
7
+ agent?: string;
8
+ session_id?: string;
9
+ }
10
+ /**
11
+ * Log an audit entry
12
+ */
13
+ export declare function logAudit(entry: Omit<AuditEntry, 'timestamp'>): void;
14
+ /**
15
+ * Log a blocked action
16
+ */
17
+ export declare function logBlocked(target: string, action: string, policy: string, agent?: string): void;
18
+ /**
19
+ * Log an allowed action
20
+ */
21
+ export declare function logAllowed(target: string, action: string, reason?: string): void;
22
+ /**
23
+ * Log a restored file (watchdog mode)
24
+ */
25
+ export declare function logRestored(target: string, event: string, policy: string): void;
26
+ /**
27
+ * Read recent audit entries
28
+ */
29
+ export declare function readAuditLog(limit?: number): Promise<AuditEntry[]>;
30
+ /**
31
+ * Print audit log to console
32
+ */
33
+ export declare function printAuditLog(limit?: number, tail?: boolean): Promise<void>;
34
+ /**
35
+ * Clear the audit log
36
+ */
37
+ export declare function clearAuditLog(): void;
38
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/audit/index.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,UAAU,CAAC;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC,GAAG,IAAI,CAYnE;AAED;;GAEG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,KAAK,CAAC,EAAE,MAAM,GACb,IAAI,CAQN;AAED;;GAEG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,MAAM,GACd,IAAI,CAON;AAED;;GAEG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb,IAAI,CAON;AAED;;GAEG;AACH,wBAAsB,YAAY,CAAC,KAAK,GAAE,MAAW,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAkC5E;AAED;;GAEG;AACH,wBAAsB,aAAa,CAAC,KAAK,GAAE,MAAW,EAAE,IAAI,GAAE,OAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CA8B5F;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,IAAI,CAKpC"}
@@ -0,0 +1,132 @@
1
+ // src/audit/index.ts
2
+ // Audit logging for veto-leash actions
3
+ import { existsSync, appendFileSync, mkdirSync, createReadStream } from 'fs';
4
+ import { join } from 'path';
5
+ import { homedir } from 'os';
6
+ import { createInterface } from 'readline';
7
+ import { COLORS, SYMBOLS } from '../ui/colors.js';
8
+ const AUDIT_DIR = join(homedir(), '.config', 'veto-leash');
9
+ const AUDIT_FILE = join(AUDIT_DIR, 'audit.jsonl');
10
+ /**
11
+ * Log an audit entry
12
+ */
13
+ export function logAudit(entry) {
14
+ const fullEntry = {
15
+ timestamp: new Date().toISOString(),
16
+ ...entry,
17
+ };
18
+ try {
19
+ mkdirSync(AUDIT_DIR, { recursive: true });
20
+ appendFileSync(AUDIT_FILE, JSON.stringify(fullEntry) + '\n');
21
+ }
22
+ catch {
23
+ // Silently fail - audit logging should never block operations
24
+ }
25
+ }
26
+ /**
27
+ * Log a blocked action
28
+ */
29
+ export function logBlocked(target, action, policy, agent) {
30
+ logAudit({
31
+ action: 'blocked',
32
+ event: action,
33
+ target,
34
+ policy,
35
+ agent,
36
+ });
37
+ }
38
+ /**
39
+ * Log an allowed action
40
+ */
41
+ export function logAllowed(target, action, reason) {
42
+ logAudit({
43
+ action: 'allowed',
44
+ event: action,
45
+ target,
46
+ policy: reason,
47
+ });
48
+ }
49
+ /**
50
+ * Log a restored file (watchdog mode)
51
+ */
52
+ export function logRestored(target, event, policy) {
53
+ logAudit({
54
+ action: 'restored',
55
+ event,
56
+ target,
57
+ policy,
58
+ });
59
+ }
60
+ /**
61
+ * Read recent audit entries
62
+ */
63
+ export async function readAuditLog(limit = 50) {
64
+ if (!existsSync(AUDIT_FILE)) {
65
+ return [];
66
+ }
67
+ const entries = [];
68
+ return new Promise((resolve) => {
69
+ const rl = createInterface({
70
+ input: createReadStream(AUDIT_FILE),
71
+ crlfDelay: Infinity,
72
+ });
73
+ rl.on('line', (line) => {
74
+ try {
75
+ const entry = JSON.parse(line);
76
+ entries.push(entry);
77
+ // Keep only the last N entries
78
+ if (entries.length > limit) {
79
+ entries.shift();
80
+ }
81
+ }
82
+ catch {
83
+ // Skip malformed lines
84
+ }
85
+ });
86
+ rl.on('close', () => {
87
+ resolve(entries);
88
+ });
89
+ rl.on('error', () => {
90
+ resolve([]);
91
+ });
92
+ });
93
+ }
94
+ /**
95
+ * Print audit log to console
96
+ */
97
+ export async function printAuditLog(limit = 50, tail = false) {
98
+ const entries = await readAuditLog(limit);
99
+ if (entries.length === 0) {
100
+ console.log(`\n${COLORS.dim}No audit entries found.${COLORS.reset}\n`);
101
+ return;
102
+ }
103
+ console.log(`\n${COLORS.bold}Audit Log${COLORS.reset} (${entries.length} entries)`);
104
+ console.log('\u2550'.repeat(60) + '\n');
105
+ const displayEntries = tail ? entries.slice(-limit) : entries;
106
+ for (const entry of displayEntries) {
107
+ const time = new Date(entry.timestamp).toLocaleString();
108
+ const actionColor = entry.action === 'blocked' ? COLORS.error :
109
+ entry.action === 'restored' ? COLORS.warning :
110
+ COLORS.success;
111
+ const actionSymbol = entry.action === 'blocked' ? SYMBOLS.blocked :
112
+ entry.action === 'restored' ? SYMBOLS.warning :
113
+ SYMBOLS.success;
114
+ console.log(`${COLORS.dim}${time}${COLORS.reset}`);
115
+ console.log(` ${actionColor}${actionSymbol} ${entry.action.toUpperCase()}${COLORS.reset} ${entry.event}`);
116
+ console.log(` ${COLORS.dim}Target:${COLORS.reset} ${entry.target}`);
117
+ if (entry.policy) {
118
+ console.log(` ${COLORS.dim}Policy:${COLORS.reset} ${entry.policy}`);
119
+ }
120
+ console.log('');
121
+ }
122
+ }
123
+ /**
124
+ * Clear the audit log
125
+ */
126
+ export function clearAuditLog() {
127
+ if (existsSync(AUDIT_FILE)) {
128
+ require('fs').writeFileSync(AUDIT_FILE, '');
129
+ console.log(`${COLORS.success}${SYMBOLS.success} Audit log cleared${COLORS.reset}`);
130
+ }
131
+ }
132
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/audit/index.ts"],"names":[],"mappings":"AAAA,qBAAqB;AACrB,uCAAuC;AAEvC,OAAO,EAAE,UAAU,EAAE,cAAc,EAAgB,SAAS,EAAE,gBAAgB,EAAE,MAAM,IAAI,CAAC;AAC3F,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAElD,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,YAAY,CAAC,CAAC;AAC3D,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;AAYlD;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAoC;IAC3D,MAAM,SAAS,GAAe;QAC5B,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACnC,GAAG,KAAK;KACT,CAAC;IAEF,IAAI,CAAC;QACH,SAAS,CAAC,SAAS,EAAE,EAAE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