@aliou/pi-guardrails 0.11.2 → 0.12.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.
- package/README.md +72 -167
- package/extensions/guardrails/commands/examples/index.ts +520 -0
- package/extensions/guardrails/commands/onboarding/config.ts +54 -0
- package/{src/commands/onboarding-command.ts → extensions/guardrails/commands/onboarding/index.ts} +5 -31
- package/extensions/guardrails/commands/settings/add-rule-wizard.ts +267 -0
- package/extensions/guardrails/commands/settings/examples.ts +399 -0
- package/extensions/guardrails/commands/settings/index.ts +596 -0
- package/extensions/guardrails/commands/settings/path-list-editor.ts +158 -0
- package/extensions/guardrails/commands/settings/scope-picker-submenu.ts +69 -0
- package/extensions/guardrails/commands/settings/utils.ts +108 -0
- package/extensions/guardrails/components/onboarding-choice-step.ts +140 -0
- package/extensions/guardrails/components/onboarding-finish-step.ts +50 -0
- package/extensions/guardrails/components/onboarding-intro-step.ts +30 -0
- package/extensions/guardrails/components/onboarding-types.ts +10 -0
- package/extensions/guardrails/components/onboarding-wizard.ts +116 -0
- package/{src → extensions/guardrails}/components/pattern-editor.ts +11 -10
- package/extensions/guardrails/index.ts +106 -0
- package/extensions/guardrails/rules.test.ts +107 -0
- package/extensions/guardrails/rules.ts +119 -0
- package/extensions/guardrails/targets.test.ts +44 -0
- package/extensions/guardrails/targets.ts +66 -0
- package/extensions/path-access/grants.test.ts +47 -0
- package/extensions/path-access/grants.ts +68 -0
- package/extensions/path-access/index.ts +143 -0
- package/extensions/path-access/prompt.ts +196 -0
- package/extensions/path-access/rules.test.ts +46 -0
- package/extensions/path-access/rules.ts +37 -0
- package/extensions/path-access/targets.test.ts +40 -0
- package/extensions/path-access/targets.ts +19 -0
- package/extensions/permission-gate/grants.ts +21 -0
- package/extensions/permission-gate/index.ts +122 -0
- package/extensions/permission-gate/prompt.ts +222 -0
- package/extensions/permission-gate/rules.test.ts +132 -0
- package/extensions/permission-gate/rules.ts +72 -0
- package/package.json +18 -20
- package/schema.json +286 -0
- package/src/core/check.test.ts +169 -0
- package/src/core/check.ts +38 -0
- package/src/{hooks/permission-gate/dangerous-commands.test.ts → core/commands/dangerous.test.ts} +134 -2
- package/src/{hooks/permission-gate/dangerous-commands.ts → core/commands/dangerous.ts} +119 -1
- package/src/core/commands/index.ts +15 -0
- package/src/core/index.ts +13 -0
- package/src/{utils/path-access.test.ts → core/paths/access.test.ts} +1 -5
- package/src/core/paths/index.ts +14 -0
- package/src/{utils → core/shell}/command-args.test.ts +31 -20
- package/src/core/shell/index.ts +2 -0
- package/src/core/types.ts +55 -0
- package/src/shared/config/defaults.ts +118 -0
- package/src/shared/config/index.ts +17 -0
- package/src/shared/config/loader.ts +64 -0
- package/src/shared/config/migration/001-v0-format-upgrade.ts +107 -0
- package/src/shared/config/migration/002-strip-toolchain-fields.ts +39 -0
- package/src/shared/config/migration/003-strip-command-explainer-fields.ts +42 -0
- package/src/shared/config/migration/004-env-files-to-policies.ts +87 -0
- package/src/shared/config/migration/005-normalize-allowed-paths.ts +43 -0
- package/src/shared/config/migration/006-apply-builtin-defaults.ts +19 -0
- package/src/shared/config/migration/007-mark-onboarding-done.ts +25 -0
- package/src/shared/config/migration/index.ts +44 -0
- package/src/shared/config/migration/version.ts +7 -0
- package/src/shared/config/types.ts +141 -0
- package/src/shared/events.ts +100 -0
- package/src/shared/index.ts +6 -0
- package/src/shared/matching.test.ts +86 -0
- package/src/{utils → shared}/matching.ts +4 -4
- package/src/{utils → shared/paths}/bash-paths.test.ts +11 -2
- package/src/{utils → shared/paths}/bash-paths.ts +4 -4
- package/src/shared/paths/index.ts +1 -0
- package/src/shared/warnings.ts +17 -0
- package/docs/defaults.md +0 -140
- package/docs/examples.md +0 -170
- package/src/commands/onboarding.ts +0 -390
- package/src/commands/settings-command.ts +0 -1616
- package/src/config.ts +0 -392
- package/src/hooks/index.ts +0 -11
- package/src/hooks/path-access.ts +0 -395
- package/src/hooks/permission-gate/index.test.ts +0 -332
- package/src/hooks/permission-gate/index.ts +0 -595
- package/src/hooks/policies.ts +0 -322
- package/src/index.ts +0 -96
- package/src/lib/executor.ts +0 -280
- package/src/lib/index.ts +0 -16
- package/src/lib/model-resolver.ts +0 -47
- package/src/lib/timing.ts +0 -42
- package/src/lib/types.ts +0 -115
- package/src/utils/events.ts +0 -32
- package/src/utils/migration.test.ts +0 -58
- package/src/utils/migration.ts +0 -340
- package/src/utils/warnings.ts +0 -7
- /package/src/{utils/path-access.ts → core/paths/access.ts} +0 -0
- /package/src/{utils → core/paths}/path.test.ts +0 -0
- /package/src/{utils → core/paths}/path.ts +0 -0
- /package/src/{utils/shell-utils.ts → core/shell/ast.ts} +0 -0
- /package/src/{utils → core/shell}/command-args.ts +0 -0
- /package/src/{utils/glob-expander.ts → shared/glob.ts} +0 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module-level warnings queue for messages that arise before any session
|
|
3
|
+
* context is available (config loading, migration, pattern compilation).
|
|
4
|
+
*/
|
|
5
|
+
const pendingWarnings: string[] = [];
|
|
6
|
+
|
|
7
|
+
export function addPendingWarning(message: string): void {
|
|
8
|
+
pendingWarnings.push(message);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function getPendingWarnings(): readonly string[] {
|
|
12
|
+
return pendingWarnings;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function drainPendingWarnings(): string[] {
|
|
16
|
+
return pendingWarnings.splice(0);
|
|
17
|
+
}
|
package/docs/defaults.md
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
# Default Configuration
|
|
2
|
-
|
|
3
|
-
These are the built-in defaults that ship with guardrails. Rules marked as disabled are included but inactive by default — enable them in your config or via `/guardrails:settings`.
|
|
4
|
-
|
|
5
|
-
Source: [`src/config.ts`](../src/config.ts)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Home-directory defaults use `~` in patterns. During policy evaluation, guardrails expands `~` to the current user's home directory before checking whether a file exists or should be blocked.
|
|
9
|
-
## Default Policy Rules
|
|
10
|
-
|
|
11
|
-
### `secret-files` — Files containing secrets
|
|
12
|
-
|
|
13
|
-
Blocks access to dotenv files and similar secret-bearing files.
|
|
14
|
-
|
|
15
|
-
| Protection | Only if exists |
|
|
16
|
-
|------------|---------------|
|
|
17
|
-
| `noAccess` | yes |
|
|
18
|
-
|
|
19
|
-
**Patterns:**
|
|
20
|
-
|
|
21
|
-
| Pattern | Type |
|
|
22
|
-
|--------------------|------|
|
|
23
|
-
| `.env` | glob |
|
|
24
|
-
| `.env.local` | glob |
|
|
25
|
-
| `.env.production` | glob |
|
|
26
|
-
| `.env.prod` | glob |
|
|
27
|
-
| `.dev.vars` | glob |
|
|
28
|
-
|
|
29
|
-
**Allowed exceptions:**
|
|
30
|
-
|
|
31
|
-
| Pattern | Type |
|
|
32
|
-
|--------------------|------|
|
|
33
|
-
| `*.example.env` | glob |
|
|
34
|
-
| `*.sample.env` | glob |
|
|
35
|
-
| `*.test.env` | glob |
|
|
36
|
-
| `.env.example` | glob |
|
|
37
|
-
| `.env.sample` | glob |
|
|
38
|
-
| `.env.test` | glob |
|
|
39
|
-
|
|
40
|
-
---
|
|
41
|
-
|
|
42
|
-
### `home-ssh` — SSH directory and keys
|
|
43
|
-
|
|
44
|
-
Blocks access to SSH configuration, private keys, and related files. Disabled by default.
|
|
45
|
-
|
|
46
|
-
| Protection | Only if exists | Enabled by default |
|
|
47
|
-
|------------|---------------|-------------------|
|
|
48
|
-
| `noAccess` | yes | no |
|
|
49
|
-
|
|
50
|
-
**Patterns:**
|
|
51
|
-
|
|
52
|
-
| Pattern | Type |
|
|
53
|
-
|-----------------------|------|
|
|
54
|
-
| `~/.ssh/**` | glob |
|
|
55
|
-
| `~/.ssh/*_rsa` | glob |
|
|
56
|
-
| `~/.ssh/*_ed25519` | glob |
|
|
57
|
-
| `~/.ssh/*.pem` | glob |
|
|
58
|
-
|
|
59
|
-
**Allowed exceptions:**
|
|
60
|
-
|
|
61
|
-
| Pattern | Type |
|
|
62
|
-
|----------|------|
|
|
63
|
-
| `~/.ssh/*.pub` | glob |
|
|
64
|
-
|
|
65
|
-
---
|
|
66
|
-
|
|
67
|
-
### `home-config` — Sensitive user configuration directories
|
|
68
|
-
|
|
69
|
-
Blocks access to a small set of known sensitive config directories that commonly store credentials, tokens, or encrypted material. Disabled by default — enable it if these tools are installed and you want to protect them.
|
|
70
|
-
|
|
71
|
-
| Protection | Only if exists | Enabled by default |
|
|
72
|
-
|------------|---------------|-------------------|
|
|
73
|
-
| `noAccess` | yes | no |
|
|
74
|
-
|
|
75
|
-
**Patterns:**
|
|
76
|
-
|
|
77
|
-
| Pattern | Type |
|
|
78
|
-
|-----------------------|------|
|
|
79
|
-
| `~/.config/gh/**` | glob |
|
|
80
|
-
| `~/.config/gcloud/**` | glob |
|
|
81
|
-
| `~/.config/op/**` | glob |
|
|
82
|
-
| `~/.config/sops/**` | glob |
|
|
83
|
-
|
|
84
|
-
---
|
|
85
|
-
|
|
86
|
-
### `home-gpg` — GPG keys and configuration
|
|
87
|
-
|
|
88
|
-
Blocks access to GPG/GnuPG private keys, keyrings, and configuration. Disabled by default.
|
|
89
|
-
|
|
90
|
-
| Protection | Only if exists | Enabled by default |
|
|
91
|
-
|------------|---------------|-------------------|
|
|
92
|
-
| `noAccess` | yes | no |
|
|
93
|
-
|
|
94
|
-
**Patterns:**
|
|
95
|
-
|
|
96
|
-
| Pattern | Type |
|
|
97
|
-
|--------------------|------|
|
|
98
|
-
| `~/.gnupg/**` | glob |
|
|
99
|
-
| `~/*.gpg` | glob |
|
|
100
|
-
| `~/.gpg-agent.conf` | glob |
|
|
101
|
-
|
|
102
|
-
---
|
|
103
|
-
|
|
104
|
-
## Path Access
|
|
105
|
-
|
|
106
|
-
| Setting | Default |
|
|
107
|
-
|---|---|
|
|
108
|
-
| `features.pathAccess` | `false` |
|
|
109
|
-
| `pathAccess.mode` | `"ask"` |
|
|
110
|
-
| `pathAccess.allowedPaths` | `[]` |
|
|
111
|
-
|
|
112
|
-
Modes:
|
|
113
|
-
- `allow` — no path restrictions
|
|
114
|
-
- `ask` — prompt when accessing paths outside working directory
|
|
115
|
-
- `block` — deny all access outside working directory
|
|
116
|
-
|
|
117
|
-
Allowed paths use trailing-slash convention:
|
|
118
|
-
- `/path/to/file` — exact file match
|
|
119
|
-
- `/path/to/dir/` — directory and all descendants
|
|
120
|
-
- Supports `~/` for home directory
|
|
121
|
-
|
|
122
|
-
Limitations:
|
|
123
|
-
- Bash path extraction is best-effort (AST-based heuristics). Tokens like `application/json` may trigger false-positive prompts.
|
|
124
|
-
- Symlinks are not resolved. Lexical path comparison only.
|
|
125
|
-
- In non-interactive mode (--print), `ask` mode degrades to `block`.
|
|
126
|
-
|
|
127
|
-
---
|
|
128
|
-
|
|
129
|
-
## Default Permission Gate Patterns
|
|
130
|
-
|
|
131
|
-
These commands are detected using AST-based structural matching for accuracy.
|
|
132
|
-
|
|
133
|
-
| Pattern | Description |
|
|
134
|
-
|-----------------|--------------------------------|
|
|
135
|
-
| `rm -rf` | Recursive force delete |
|
|
136
|
-
| `sudo` | Superuser command |
|
|
137
|
-
| `dd of=` | Disk write operation |
|
|
138
|
-
| `mkfs.` | Filesystem format |
|
|
139
|
-
| `chmod -R 777` | Insecure recursive permissions |
|
|
140
|
-
| `chown -R` | Recursive ownership change |
|
package/docs/examples.md
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
# Example Presets
|
|
2
|
-
|
|
3
|
-
Pre-configured presets available in the `/guardrails:settings` Examples tab. These can be applied to any config scope (global, local, or memory).
|
|
4
|
-
|
|
5
|
-
Source: [`src/commands/settings-command.ts`](../src/commands/settings-command.ts)
|
|
6
|
-
|
|
7
|
-
## File Policy Presets
|
|
8
|
-
|
|
9
|
-
### Secrets (.env)
|
|
10
|
-
|
|
11
|
-
Block dotenv-like files using glob patterns.
|
|
12
|
-
|
|
13
|
-
| Field | Value |
|
|
14
|
-
|------------|------------------------------------|
|
|
15
|
-
| ID | `example-secret-env-files` |
|
|
16
|
-
| Protection | `noAccess` |
|
|
17
|
-
| Patterns | `.env`, `.env.*` |
|
|
18
|
-
| Exceptions | `.env.example`, `*.sample.env` |
|
|
19
|
-
|
|
20
|
-
---
|
|
21
|
-
|
|
22
|
-
### Logs (*.log)
|
|
23
|
-
|
|
24
|
-
Mark log files as read-only to prevent accidental modification.
|
|
25
|
-
|
|
26
|
-
| Field | Value |
|
|
27
|
-
|------------|---------------------------|
|
|
28
|
-
| ID | `example-log-files` |
|
|
29
|
-
| Protection | `readOnly` |
|
|
30
|
-
| Patterns | `*.log`, `*.out` |
|
|
31
|
-
|
|
32
|
-
---
|
|
33
|
-
|
|
34
|
-
### Regex env
|
|
35
|
-
|
|
36
|
-
Regex-based matching for `.env` and `.env.*` files. Demonstrates regex mode.
|
|
37
|
-
|
|
38
|
-
| Field | Value |
|
|
39
|
-
|------------|------------------------------------------|
|
|
40
|
-
| ID | `example-regex-env` |
|
|
41
|
-
| Protection | `noAccess` |
|
|
42
|
-
| Patterns | `^\.env(\..+)?$` (regex) |
|
|
43
|
-
| Exceptions | `^\.env\.example$` (regex) |
|
|
44
|
-
|
|
45
|
-
---
|
|
46
|
-
|
|
47
|
-
### SSH keys
|
|
48
|
-
|
|
49
|
-
Block access to SSH private key files.
|
|
50
|
-
|
|
51
|
-
| Field | Value |
|
|
52
|
-
|------------|--------------------------------------|
|
|
53
|
-
| ID | `example-ssh-keys` |
|
|
54
|
-
| Protection | `noAccess` |
|
|
55
|
-
| Patterns | `*.pem`, `*_rsa`, `*_ed25519` |
|
|
56
|
-
| Exceptions | `*.pub` |
|
|
57
|
-
|
|
58
|
-
---
|
|
59
|
-
|
|
60
|
-
### AWS credentials
|
|
61
|
-
|
|
62
|
-
Block AWS CLI credentials and config files.
|
|
63
|
-
|
|
64
|
-
| Field | Value |
|
|
65
|
-
|------------|----------------------------------------|
|
|
66
|
-
| ID | `example-aws-credentials` |
|
|
67
|
-
| Protection | `noAccess` |
|
|
68
|
-
| Patterns | `.aws/credentials`, `.aws/config` |
|
|
69
|
-
|
|
70
|
-
---
|
|
71
|
-
|
|
72
|
-
### Database files
|
|
73
|
-
|
|
74
|
-
Mark SQLite and database files as read-only.
|
|
75
|
-
|
|
76
|
-
| Field | Value |
|
|
77
|
-
|------------|----------------------------------------|
|
|
78
|
-
| ID | `example-database-files` |
|
|
79
|
-
| Protection | `readOnly` |
|
|
80
|
-
| Patterns | `*.db`, `*.sqlite`, `*.sqlite3` |
|
|
81
|
-
|
|
82
|
-
---
|
|
83
|
-
|
|
84
|
-
### Kubernetes secrets
|
|
85
|
-
|
|
86
|
-
Block kubeconfig and Kubernetes secret files.
|
|
87
|
-
|
|
88
|
-
| Field | Value |
|
|
89
|
-
|------------|----------------------------------------|
|
|
90
|
-
| ID | `example-k8s-secrets` |
|
|
91
|
-
| Protection | `noAccess` |
|
|
92
|
-
| Patterns | `.kube/config`, `*kubeconfig*` |
|
|
93
|
-
|
|
94
|
-
---
|
|
95
|
-
|
|
96
|
-
### Certificates
|
|
97
|
-
|
|
98
|
-
Block SSL/TLS certificate and key files.
|
|
99
|
-
|
|
100
|
-
| Field | Value |
|
|
101
|
-
|------------|----------------------------------------|
|
|
102
|
-
| ID | `example-certificates` |
|
|
103
|
-
| Protection | `noAccess` |
|
|
104
|
-
| Patterns | `*.crt`, `*.key`, `*.p12` |
|
|
105
|
-
| Exceptions | `*.csr` |
|
|
106
|
-
|
|
107
|
-
---
|
|
108
|
-
|
|
109
|
-
## Dangerous Command Presets
|
|
110
|
-
|
|
111
|
-
### General
|
|
112
|
-
|
|
113
|
-
| Label | Pattern | Description |
|
|
114
|
-
|--------------------|----------------------|----------------------------------------|
|
|
115
|
-
| Homebrew | `brew` | Homebrew package manager |
|
|
116
|
-
| git push --force | `git push --force` | Git force push |
|
|
117
|
-
| npm publish | `npm publish` | NPM package publishing |
|
|
118
|
-
| yarn publish | `yarn publish` | Yarn package publishing |
|
|
119
|
-
| pnpm publish | `pnpm publish` | PNPM package publishing |
|
|
120
|
-
| drop database | `DROP DATABASE` | SQL database drop |
|
|
121
|
-
| drop table | `DROP TABLE` | SQL table drop |
|
|
122
|
-
|
|
123
|
-
### dbt
|
|
124
|
-
|
|
125
|
-
| Label | Pattern | Description |
|
|
126
|
-
|----------|------------|------------------------|
|
|
127
|
-
| dbt run | `dbt run` | dbt model execution |
|
|
128
|
-
| dbt seed | `dbt seed` | dbt seed data loading |
|
|
129
|
-
|
|
130
|
-
### AWS
|
|
131
|
-
|
|
132
|
-
| Label | Pattern | Description |
|
|
133
|
-
|----------------------|--------------------------------|------------------------------|
|
|
134
|
-
| aws s3 rm | `aws s3 rm` | AWS S3 object deletion |
|
|
135
|
-
| aws iam | `aws iam` | AWS IAM permission changes |
|
|
136
|
-
| aws ec2 terminate | `aws ec2 terminate-instances` | AWS EC2 instance termination |
|
|
137
|
-
|
|
138
|
-
### Kubernetes
|
|
139
|
-
|
|
140
|
-
| Label | Pattern | Description |
|
|
141
|
-
|----------------|------------------|--------------------------------|
|
|
142
|
-
| kubectl delete | `kubectl delete` | Kubernetes resource deletion |
|
|
143
|
-
| kubectl apply | `kubectl apply` | Kubernetes resource application|
|
|
144
|
-
| kubectl scale | `kubectl scale` | Kubernetes scaling operation |
|
|
145
|
-
|
|
146
|
-
### Docker
|
|
147
|
-
|
|
148
|
-
| Label | Pattern | Description |
|
|
149
|
-
|----------------------|------------------------|------------------------------------------|
|
|
150
|
-
| Docker secrets | `docker inspect` | Docker inspect (may expose env vars) |
|
|
151
|
-
| docker rm | `docker rm` | Docker container removal |
|
|
152
|
-
| docker rmi | `docker rmi` | Docker image removal |
|
|
153
|
-
| docker system prune | `docker system prune` | Docker system cleanup |
|
|
154
|
-
| docker compose down | `docker compose down` | Docker Compose service teardown |
|
|
155
|
-
|
|
156
|
-
### Terraform
|
|
157
|
-
|
|
158
|
-
| Label | Pattern | Description |
|
|
159
|
-
|--------------------|----------------------|------------------------------------|
|
|
160
|
-
| Terraform apply | `terraform apply` | Terraform infrastructure changes |
|
|
161
|
-
| Terraform destroy | `terraform destroy` | Terraform infrastructure destruction|
|
|
162
|
-
| terraform import | `terraform import` | Terraform resource import |
|
|
163
|
-
|
|
164
|
-
### Google Cloud
|
|
165
|
-
|
|
166
|
-
| Label | Pattern | Description |
|
|
167
|
-
|------------------------|------------------------------------|----------------------------------|
|
|
168
|
-
| gcloud compute delete | `gcloud compute instances delete` | GCP compute instance deletion |
|
|
169
|
-
| gcloud iam | `gcloud iam` | GCP IAM permission changes |
|
|
170
|
-
| gcloud sql delete | `gcloud sql instances delete` | GCP Cloud SQL instance deletion |
|