@xynogen/pix-gate 0.1.15 → 0.2.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/package.json +3 -2
- package/src/gate.test.ts +5 -5
- package/src/index.ts +2 -2
- package/src/lib.ts +8 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xynogen/pix-gate",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Pi extension — permission gate for dangerous bash commands (confirm/block with TUI dialog)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -43,7 +43,8 @@
|
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@xynogen/pix-pretty": "^1.7.9",
|
|
46
|
-
"@xynogen/pix-data": "^0.
|
|
46
|
+
"@xynogen/pix-data": "^0.4.0",
|
|
47
|
+
"@xynogen/pix-runtime": "^0.3.0"
|
|
47
48
|
},
|
|
48
49
|
"peerDependencies": {
|
|
49
50
|
"@earendil-works/pi-coding-agent": "*",
|
package/src/gate.test.ts
CHANGED
|
@@ -105,14 +105,14 @@ describe("classify", () => {
|
|
|
105
105
|
// ── buildRules ────────────────────────────────────────────────────────────────
|
|
106
106
|
|
|
107
107
|
describe("buildRules", () => {
|
|
108
|
-
test("
|
|
109
|
-
const { rules } = buildRules({
|
|
108
|
+
test("guardrails off removes all built-in rules", () => {
|
|
109
|
+
const { rules } = buildRules({ guardrails: "off" });
|
|
110
110
|
expect(rules).toHaveLength(0);
|
|
111
111
|
});
|
|
112
112
|
|
|
113
|
-
test("extraRules are appended", () => {
|
|
113
|
+
test("extraRules are appended when guardrails are off", () => {
|
|
114
114
|
const { rules } = buildRules({
|
|
115
|
-
|
|
115
|
+
guardrails: "off",
|
|
116
116
|
extraRules: [{ pattern: "foo", severity: "risky", reason: "test" }],
|
|
117
117
|
});
|
|
118
118
|
expect(rules).toHaveLength(1);
|
|
@@ -126,7 +126,7 @@ describe("buildRules", () => {
|
|
|
126
126
|
expect(rule0.test("yarn publish")).toBe(false);
|
|
127
127
|
});
|
|
128
128
|
|
|
129
|
-
test("defaults included when
|
|
129
|
+
test("defaults included when guardrails is absent", () => {
|
|
130
130
|
const { rules } = buildRules({});
|
|
131
131
|
expect(rules.length).toBe(DEFAULT_RULES.length);
|
|
132
132
|
});
|
package/src/index.ts
CHANGED
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
* sudo — hard block, must use sudo_run tool instead (no bypass)
|
|
12
12
|
* No-UI fallback: critical/dangerous auto-block (can't show dialog)
|
|
13
13
|
*
|
|
14
|
-
* Config: ~/.pi/agent/pix
|
|
15
|
-
*
|
|
14
|
+
* Config: ~/.pi/agent/pix.json (the `gate` section)
|
|
15
|
+
* guardrails: "off" — disable built-in rules entirely
|
|
16
16
|
* extraRules: [{ pattern, flags?, severity?, reason? }] — append extra rules
|
|
17
17
|
* autoApprove: ["regex"] — bypass gate for matching commands
|
|
18
18
|
*/
|
package/src/lib.ts
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* Pure helpers for pix-gate — no Pi API deps, fully unit-testable.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { config } from "@xynogen/pix-runtime/config";
|
|
6
|
+
import { type GateRuleConfig, gateSection } from "@xynogen/pix-runtime/sections";
|
|
6
7
|
|
|
7
8
|
export type Severity = "critical" | "dangerous" | "risky";
|
|
8
9
|
|
|
@@ -19,7 +20,8 @@ export interface UserConfig {
|
|
|
19
20
|
severity?: Severity;
|
|
20
21
|
reason?: string;
|
|
21
22
|
}[];
|
|
22
|
-
|
|
23
|
+
/** Whether Pix's built-in command protections are active. Defaults to "on". */
|
|
24
|
+
guardrails?: "on" | "off";
|
|
23
25
|
/** Regex strings — commands matching any are passed through without prompting. */
|
|
24
26
|
autoApprove?: string[];
|
|
25
27
|
}
|
|
@@ -130,9 +132,9 @@ export const DEFAULT_RULES: Rule[] = [
|
|
|
130
132
|
|
|
131
133
|
export function loadUserConfig(): UserConfig {
|
|
132
134
|
// Read from ~/.pi/agent/pix.json gate section
|
|
133
|
-
const pix =
|
|
135
|
+
const pix = config(gateSection);
|
|
134
136
|
return {
|
|
135
|
-
|
|
137
|
+
guardrails: pix.guardrails,
|
|
136
138
|
autoApprove: pix.autoApprove.length > 0 ? pix.autoApprove : undefined,
|
|
137
139
|
extraRules:
|
|
138
140
|
pix.extraRules.length > 0
|
|
@@ -151,7 +153,7 @@ export function buildRules(cfg: UserConfig): {
|
|
|
151
153
|
autoApprove: RegExp[];
|
|
152
154
|
pathRules: PathRule[];
|
|
153
155
|
} {
|
|
154
|
-
const base = cfg.
|
|
156
|
+
const base = cfg.guardrails === "off" ? [] : DEFAULT_RULES.slice();
|
|
155
157
|
const extra = (cfg.extraRules ?? []).map((r) => ({
|
|
156
158
|
pattern: new RegExp(r.pattern, r.flags ?? "i"),
|
|
157
159
|
severity: (r.severity ?? "dangerous") as Severity,
|
|
@@ -159,7 +161,7 @@ export function buildRules(cfg: UserConfig): {
|
|
|
159
161
|
}));
|
|
160
162
|
const autoApprove = (cfg.autoApprove ?? []).map((s) => new RegExp(s));
|
|
161
163
|
// ponytail: path rule config extension skipped for now — add extraPathRules/disablePathDefaults to UserConfig when needed
|
|
162
|
-
const pathRules = cfg.
|
|
164
|
+
const pathRules = cfg.guardrails === "off" ? [] : DEFAULT_PATH_RULES.slice();
|
|
163
165
|
return { rules: [...base, ...extra], autoApprove, pathRules };
|
|
164
166
|
}
|
|
165
167
|
|