@zeldrisho/pi-gate 0.0.0 → 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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +31 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeldrisho/pi-gate",
3
- "version": "0.0.0",
3
+ "version": "0.1.0",
4
4
  "description": "Pi extension that blocks or confirms bash commands based on a user-provided JSON configuration",
5
5
  "keywords": [
6
6
  "command-blocking",
package/src/index.ts CHANGED
@@ -48,18 +48,39 @@ const EXAMPLE_CONFIG: GateConfig = {
48
48
  },
49
49
  };
50
50
 
51
+ /**
52
+ * Returns the directory where pi-gate configuration files are stored.
53
+ *
54
+ * @returns The absolute path to the agent configuration directory
55
+ */
51
56
  function agentDir(): string {
52
57
  return process.env.PI_CODING_AGENT_DIR ?? join(homedir(), ".pi", "agent");
53
58
  }
54
59
 
60
+ /**
61
+ * Returns the full path to the pi-gate configuration file.
62
+ *
63
+ * @returns The absolute path to pi-gate.json
64
+ */
55
65
  function configPath(): string {
56
66
  return join(agentDir(), CONFIG_FILE_NAME);
57
67
  }
58
68
 
69
+ /**
70
+ * Returns the full path to the example pi-gate configuration file.
71
+ *
72
+ * @returns The absolute path to pi-gate.json.example
73
+ */
59
74
  function examplePath(): string {
60
75
  return join(agentDir(), EXAMPLE_FILE_NAME);
61
76
  }
62
77
 
78
+ /**
79
+ * Type guard that checks if an unknown value is a valid Action.
80
+ *
81
+ * @param value - The value to check
82
+ * @returns `true` if the value is one of "prompt", "block", or "allow"
83
+ */
63
84
  // oxlint-disable-next-line anti-slop/no-unknown-parameters -- type-guard helper intentionally narrows untrusted JSON values at the parse boundary
64
85
  function isAction(value: unknown): value is Action {
65
86
  return (
@@ -71,6 +92,12 @@ function isAction(value: unknown): value is Action {
71
92
  );
72
93
  }
73
94
 
95
+ /**
96
+ * Type guard that checks if an unknown value is a plain JSON object.
97
+ *
98
+ * @param value - The value to check
99
+ * @returns `true` if the value is a non-null object and not an array
100
+ */
74
101
  // oxlint-disable-next-line anti-slop/no-unknown-parameters, anti-slop/no-unsafe-dictionary-type -- type-guard helper intentionally narrows untrusted JSON values at the parse boundary
75
102
  function isJsonObject(value: unknown): value is Record<string, unknown> {
76
103
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -152,6 +179,10 @@ export function ensureExampleConfig(): void {
152
179
  * Returns `null` when no rule matches, in which case the caller should let the
153
180
  * command through. When multiple rules match, the longest pattern wins so
154
181
  * that narrow rules can override broader ones.
182
+ *
183
+ * @param command - The bash command to evaluate against the rules
184
+ * @param rules - A map of pattern strings to actions
185
+ * @returns The action to take, or `null` if no rule matches
155
186
  */
156
187
  export function resolveAction(command: string, rules: Record<string, Action>): Action | null {
157
188
  let bestPattern: string | null = null;