pi-mono-all 1.2.0 → 1.2.2

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 (27) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/node_modules/pi-mono-sentinel/.pi/extensions/sentinel.json +7 -0
  3. package/node_modules/pi-mono-sentinel/CHANGELOG.md +15 -0
  4. package/node_modules/pi-mono-sentinel/README.md +59 -0
  5. package/node_modules/pi-mono-sentinel/__tests__/config.test.ts +60 -0
  6. package/node_modules/pi-mono-sentinel/__tests__/events.test.ts +45 -0
  7. package/node_modules/pi-mono-sentinel/__tests__/path-access.test.ts +75 -0
  8. package/node_modules/pi-mono-sentinel/__tests__/permissions.test.ts +4 -0
  9. package/node_modules/pi-mono-sentinel/config.ts +193 -0
  10. package/node_modules/pi-mono-sentinel/events.ts +46 -0
  11. package/node_modules/pi-mono-sentinel/guards/execution-tracker.ts +13 -6
  12. package/node_modules/pi-mono-sentinel/guards/output-scanner.ts +75 -44
  13. package/node_modules/pi-mono-sentinel/guards/path-access.ts +102 -0
  14. package/node_modules/pi-mono-sentinel/guards/permission-gate.ts +34 -16
  15. package/node_modules/pi-mono-sentinel/index.ts +19 -3
  16. package/node_modules/pi-mono-sentinel/package.json +1 -1
  17. package/node_modules/pi-mono-sentinel/path-access.ts +74 -0
  18. package/node_modules/pi-mono-sentinel/patterns/bash-paths.ts +98 -0
  19. package/node_modules/pi-mono-sentinel/patterns/permissions.ts +146 -24
  20. package/node_modules/pi-mono-sentinel/patterns/read-targets.ts +3 -1
  21. package/node_modules/pi-mono-sentinel/session.ts +6 -1
  22. package/node_modules/pi-mono-sentinel/utils/shell.ts +172 -0
  23. package/node_modules/pi-mono-sentinel/whitelist.ts +2 -12
  24. package/node_modules/pi-mono-usage/CHANGELOG.md +8 -0
  25. package/node_modules/pi-mono-usage/index.ts +391 -48
  26. package/node_modules/pi-mono-usage/package.json +1 -1
  27. package/package.json +10 -10
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # pi-mono-all
2
2
 
3
+ ## 1.2.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Bundle `pi-mono-sentinel@1.11.0` with guardrails hardening, path-access grants, event emission, and internal simplifications.
8
+
9
+ ## 1.2.1
10
+
11
+ ### Patch Changes
12
+
13
+ - Bundle `pi-mono-usage@0.1.1` with the updated Tools view and usage dashboard refinements.
14
+
3
15
  ## 1.2.0
4
16
 
5
17
  ### Minor Changes
@@ -0,0 +1,7 @@
1
+ {
2
+ "outputScanner": {
3
+ "readAllowedPaths": [
4
+ "/safe/example-doc.md"
5
+ ]
6
+ }
7
+ }
@@ -1,5 +1,20 @@
1
1
  # pi-mono-sentinel
2
2
 
3
+ ## 1.11.0
4
+
5
+ ### Minor Changes
6
+
7
+ ### Enhanced: guardrails hardening
8
+
9
+ - Added merged Sentinel configuration scopes: global (`~/.pi/agent/extensions/sentinel.json`), local (`.pi/extensions/sentinel.json`), and session memory.
10
+ - Added optional path-access guard with allow/ask/block modes and file/directory grant persistence.
11
+ - Added `sentinel:dangerous` and `sentinel:blocked` event emission from guards.
12
+ - Added internal shell-aware bash command analysis with fallback matching.
13
+
14
+ ### Maintenance
15
+
16
+ - Simplified Sentinel config persistence, path-access grants, event emission, and shell traversal internals without changing guard behavior.
17
+
3
18
  ## 1.10.2
4
19
 
5
20
  ### Patch Changes
@@ -9,6 +9,63 @@ It addresses cross-cutting security gaps that pure command-based guardrails miss
9
9
  - **Out-of-scope operations** — a raw `bash` command performs a system-level action (sudo, `curl | bash`, `brew install`, `rm -rf /Library/...`) or a `write`/`edit` targets a file outside the project root (shell config, system directory)
10
10
  - **Credential safety** — the LLM never hardcodes API keys or secrets in tool calls
11
11
 
12
+ ## Configuration
13
+
14
+ Sentinel reads and merges optional JSON config from three scopes:
15
+
16
+ 1. Global: `$PI_CODING_AGENT_DIR/extensions/sentinel.json` or `~/.pi/agent/extensions/sentinel.json`
17
+ 2. Local/project: `.pi/extensions/sentinel.json` under the current working directory
18
+ 3. Memory: session-only grants written internally while Pi is running
19
+
20
+ Merge priority is `memory > local > global > defaults`.
21
+
22
+ ```json
23
+ {
24
+ "enabled": true,
25
+ "features": {
26
+ "outputScanner": true,
27
+ "executionTracker": true,
28
+ "permissionGate": true,
29
+ "pathAccess": false
30
+ },
31
+ "pathAccess": {
32
+ "mode": "ask",
33
+ "allowedPaths": []
34
+ },
35
+ "permissionGate": {
36
+ "requireConfirmation": true,
37
+ "allowedPatterns": [],
38
+ "autoDenyPatterns": []
39
+ },
40
+ "outputScanner": {
41
+ "readAllowedPaths": []
42
+ }
43
+ }
44
+ ```
45
+
46
+ All fields are optional. Path access is available but disabled by default to avoid surprising existing users.
47
+
48
+ ### Path access grants
49
+
50
+ When `features.pathAccess` is enabled, Sentinel checks `read`, `write`, `edit`, and path-like `bash` arguments that point outside `ctx.cwd`.
51
+
52
+ Modes:
53
+
54
+ - `allow` — no outside-project restrictions
55
+ - `ask` — prompt to allow once, allow file/directory for the session, allow file/directory always, or deny
56
+ - `block` — block outside-project paths unless they match `pathAccess.allowedPaths`
57
+
58
+ Allowed directory grants use a trailing slash, e.g. `/tmp/shared/`; exact file grants omit it.
59
+
60
+ ### Events
61
+
62
+ Sentinel emits best-effort extension events for other extensions:
63
+
64
+ - `sentinel:dangerous` when a guard detects risky content or behavior
65
+ - `sentinel:blocked` when a guard blocks a tool call
66
+
67
+ Payloads include `feature`, `toolName`, `input`, and either `description`/`labels` or `reason`/`userDenied`.
68
+
12
69
  ## Guards
13
70
 
14
71
  ### 1. output-scanner — secret detection on read
@@ -41,6 +98,8 @@ If the target file was modified after the tracked write, it is re-read and re-sc
41
98
 
42
99
  Where `execution-tracker` only fires for _session-written_ scripts, `permission-gate` intercepts every `bash` command and every `write` / `edit` and matches them against a fixed set of risk classes. It runs in addition to the other two guards.
43
100
 
101
+ Bash analysis uses Sentinel's small internal shell parser for quotes, redirects, pipelines, and command boundaries, with regex fallbacks when parsing fails.
102
+
44
103
  **Bash risk classes**
45
104
 
46
105
  | Risk class | Example |
@@ -0,0 +1,60 @@
1
+ import assert from "node:assert/strict";
2
+ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import { afterEach, beforeEach, describe, test } from "node:test";
6
+
7
+ import { SentinelConfigLoader } from "../config.ts";
8
+
9
+ describe("SentinelConfigLoader", () => {
10
+ let agentDir: string;
11
+ let cwd: string;
12
+ const originalAgentDir = process.env.PI_CODING_AGENT_DIR;
13
+
14
+ beforeEach(() => {
15
+ agentDir = mkdtempSync(join(tmpdir(), "sentinel-config-agent-"));
16
+ cwd = mkdtempSync(join(tmpdir(), "sentinel-config-cwd-"));
17
+ process.env.PI_CODING_AGENT_DIR = agentDir;
18
+ });
19
+
20
+ afterEach(() => {
21
+ if (originalAgentDir === undefined) delete process.env.PI_CODING_AGENT_DIR;
22
+ else process.env.PI_CODING_AGENT_DIR = originalAgentDir;
23
+ rmSync(agentDir, { recursive: true, force: true });
24
+ rmSync(cwd, { recursive: true, force: true });
25
+ });
26
+
27
+ test("uses defaults when no config files exist", () => {
28
+ const loader = new SentinelConfigLoader();
29
+ loader.load(cwd);
30
+ const config = loader.getConfig();
31
+ assert.equal(config.enabled, true);
32
+ assert.equal(config.features.outputScanner, true);
33
+ assert.equal(config.features.pathAccess, false);
34
+ assert.equal(config.pathAccess.mode, "ask");
35
+ });
36
+
37
+ test("merges global, local, and memory with expected precedence", () => {
38
+ const loader = new SentinelConfigLoader();
39
+ mkdirSync(join(agentDir, "extensions"), { recursive: true });
40
+ writeFileSync(loader.getConfigPath("global"), JSON.stringify({ pathAccess: { allowedPaths: ["/global"] } }), { flag: "w" });
41
+ loader.load(cwd);
42
+ mkdirSync(join(cwd, ".pi", "extensions"), { recursive: true });
43
+ writeFileSync(loader.getConfigPath("local"), JSON.stringify({ features: { pathAccess: true }, pathAccess: { allowedPaths: ["/local"] } }), { flag: "w" });
44
+ loader.load(cwd);
45
+ loader.save("memory", { pathAccess: { mode: "block", allowedPaths: ["/memory"] } });
46
+ const config = loader.getConfig();
47
+ assert.equal(config.features.pathAccess, true);
48
+ assert.equal(config.pathAccess.mode, "block");
49
+ assert.deepEqual(config.pathAccess.allowedPaths, ["/memory"]);
50
+ });
51
+
52
+ test("save writes global and local config files", () => {
53
+ const loader = new SentinelConfigLoader();
54
+ loader.load(cwd);
55
+ loader.save("global", { enabled: false });
56
+ loader.save("local", { features: { pathAccess: true } });
57
+ assert.deepEqual(loader.getRawConfig("global"), { enabled: false });
58
+ assert.deepEqual(loader.getRawConfig("local"), { features: { pathAccess: true } });
59
+ });
60
+ });
@@ -0,0 +1,45 @@
1
+ import assert from "node:assert/strict";
2
+ import { describe, test } from "node:test";
3
+
4
+ import { emitBlocked, emitDangerous } from "../events.ts";
5
+
6
+ describe("sentinel events", () => {
7
+ test("emits blocked and dangerous events", () => {
8
+ const emitted: Array<{ name: string; payload: unknown }> = [];
9
+ const pi = {
10
+ events: {
11
+ emit(name: string, payload: unknown) {
12
+ emitted.push({ name, payload });
13
+ },
14
+ },
15
+ };
16
+
17
+ emitDangerous(pi as never, {
18
+ feature: "permissionGate",
19
+ toolName: "bash",
20
+ input: { command: "sudo true" },
21
+ description: "danger",
22
+ labels: ["privilege-escalation"],
23
+ });
24
+ emitBlocked(pi as never, {
25
+ feature: "permissionGate",
26
+ toolName: "bash",
27
+ input: { command: "sudo true" },
28
+ reason: "blocked",
29
+ });
30
+
31
+ assert.equal(emitted[0].name, "sentinel:dangerous");
32
+ assert.equal(emitted[1].name, "sentinel:blocked");
33
+ });
34
+
35
+ test("does not throw when event emitter is unavailable", () => {
36
+ assert.doesNotThrow(() =>
37
+ emitBlocked({} as never, {
38
+ feature: "pathAccess",
39
+ toolName: "read",
40
+ input: {},
41
+ reason: "blocked",
42
+ }),
43
+ );
44
+ });
45
+ });
@@ -0,0 +1,75 @@
1
+ import assert from "node:assert/strict";
2
+ import { mkdtempSync, rmSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import { describe, test } from "node:test";
6
+
7
+ import { configLoader } from "../config.ts";
8
+ import {
9
+ checkPathAccess,
10
+ directoryGrantFor,
11
+ isInsideCwd,
12
+ isPathAllowed,
13
+ pathAccessGrantForChoice,
14
+ toStoragePath,
15
+ } from "../path-access.ts";
16
+
17
+ const CWD = "/tmp/sentinel-project";
18
+
19
+ describe("path-access helpers", () => {
20
+ test("allows paths inside cwd", () => {
21
+ assert.equal(isInsideCwd("/tmp/sentinel-project/src/index.ts", CWD), true);
22
+ assert.equal(checkPathAccess("/tmp/sentinel-project/src/index.ts", CWD, []).allowed, true);
23
+ });
24
+
25
+ test("detects paths outside cwd", () => {
26
+ const result = checkPathAccess("/tmp/other/file.txt", CWD, []);
27
+ assert.equal(result.allowed, false);
28
+ });
29
+
30
+ test("allows exact file grants", () => {
31
+ assert.equal(isPathAllowed("/tmp/other/file.txt", ["/tmp/other/file.txt"], CWD), true);
32
+ assert.equal(isPathAllowed("/tmp/other/else.txt", ["/tmp/other/file.txt"], CWD), false);
33
+ });
34
+
35
+ test("allows directory grants with trailing slash", () => {
36
+ assert.equal(isPathAllowed("/tmp/other/file.txt", ["/tmp/other/"], CWD), true);
37
+ assert.equal(isPathAllowed("/tmp/other/nested/file.txt", ["/tmp/other/"], CWD), true);
38
+ assert.equal(isPathAllowed("/tmp/otherness/file.txt", ["/tmp/other/"], CWD), false);
39
+ });
40
+
41
+ test("formats storage paths", () => {
42
+ assert.equal(toStoragePath("/tmp/other", true), "/tmp/other/");
43
+ assert.equal(directoryGrantFor("/tmp/other/file.txt"), "/tmp/other/");
44
+ });
45
+
46
+ test("derives and persists selected path-access grants with the correct scope and target", () => {
47
+ const cwd = mkdtempSync(join(tmpdir(), "sentinel-path-access-cwd-"));
48
+ try {
49
+ configLoader.load(cwd);
50
+ configLoader.save("memory", { features: { pathAccess: true }, pathAccess: { mode: "ask", allowedPaths: [] } });
51
+
52
+ const sessionDirectoryGrant = pathAccessGrantForChoice("allow_directory_session", "/tmp/outside-dir/file.txt", cwd);
53
+ assert.deepEqual(sessionDirectoryGrant, {
54
+ grant: "/tmp/outside-dir/",
55
+ broadCheckPath: "/tmp/outside-dir",
56
+ scope: "memory",
57
+ directory: true,
58
+ });
59
+ configLoader.addAllowedPath(sessionDirectoryGrant.scope, sessionDirectoryGrant.grant);
60
+ assert.ok(configLoader.getConfig().pathAccess.allowedPaths.includes("/tmp/outside-dir/"));
61
+
62
+ const localFileGrant = pathAccessGrantForChoice("allow_file_always", "/tmp/outside-file.txt", cwd);
63
+ assert.deepEqual(localFileGrant, {
64
+ grant: "/tmp/outside-file.txt",
65
+ broadCheckPath: "/tmp/outside-file.txt",
66
+ scope: "local",
67
+ directory: false,
68
+ });
69
+ configLoader.addAllowedPath(localFileGrant.scope, localFileGrant.grant);
70
+ assert.ok(configLoader.getRawConfig("local")?.pathAccess?.allowedPaths?.includes("/tmp/outside-file.txt"));
71
+ } finally {
72
+ rmSync(cwd, { recursive: true, force: true });
73
+ }
74
+ });
75
+ });
@@ -118,6 +118,10 @@ describe("classifyBashCommand", () => {
118
118
  assert.ok(matched.includes("remote-pipe-exec"));
119
119
  });
120
120
 
121
+ test("does NOT flag dangerous words inside quoted strings", () => {
122
+ assert.deepEqual(classifyBashCommand('echo "sudo rm -rf /Library"'), []);
123
+ });
124
+
121
125
  test("does NOT flag safe commands", () => {
122
126
  assert.deepEqual(classifyBashCommand("echo hello"), []);
123
127
  assert.deepEqual(classifyBashCommand("ls -la"), []);
@@ -0,0 +1,193 @@
1
+ import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { dirname, join } from "node:path";
4
+
5
+ export type SentinelConfigScope = "global" | "local" | "memory";
6
+ export type SentinelPathAccessMode = "allow" | "ask" | "block";
7
+
8
+ export interface SentinelConfig {
9
+ enabled?: boolean;
10
+ features?: {
11
+ outputScanner?: boolean;
12
+ executionTracker?: boolean;
13
+ permissionGate?: boolean;
14
+ pathAccess?: boolean;
15
+ };
16
+ pathAccess?: {
17
+ mode?: SentinelPathAccessMode;
18
+ allowedPaths?: string[];
19
+ };
20
+ permissionGate?: {
21
+ requireConfirmation?: boolean;
22
+ allowedPatterns?: string[];
23
+ autoDenyPatterns?: string[];
24
+ };
25
+ outputScanner?: {
26
+ readAllowedPaths?: string[];
27
+ };
28
+ }
29
+
30
+ export interface ResolvedSentinelConfig {
31
+ enabled: boolean;
32
+ features: {
33
+ outputScanner: boolean;
34
+ executionTracker: boolean;
35
+ permissionGate: boolean;
36
+ pathAccess: boolean;
37
+ };
38
+ pathAccess: {
39
+ mode: SentinelPathAccessMode;
40
+ allowedPaths: string[];
41
+ };
42
+ permissionGate: {
43
+ requireConfirmation: boolean;
44
+ allowedPatterns: string[];
45
+ autoDenyPatterns: string[];
46
+ };
47
+ outputScanner: {
48
+ readAllowedPaths: string[];
49
+ };
50
+ }
51
+
52
+ export const DEFAULT_SENTINEL_CONFIG: ResolvedSentinelConfig = {
53
+ enabled: true,
54
+ features: {
55
+ outputScanner: true,
56
+ executionTracker: true,
57
+ permissionGate: true,
58
+ pathAccess: false,
59
+ },
60
+ pathAccess: {
61
+ mode: "ask",
62
+ allowedPaths: [],
63
+ },
64
+ permissionGate: {
65
+ requireConfirmation: true,
66
+ allowedPatterns: [],
67
+ autoDenyPatterns: [],
68
+ },
69
+ outputScanner: {
70
+ readAllowedPaths: [],
71
+ },
72
+ };
73
+
74
+ export function getAgentDir(): string {
75
+ const envDir = process.env.PI_CODING_AGENT_DIR;
76
+ if (!envDir) return join(homedir(), ".pi", "agent");
77
+ if (envDir === "~") return homedir();
78
+ if (envDir.startsWith("~/")) return join(homedir(), envDir.slice(2));
79
+ return envDir;
80
+ }
81
+
82
+ function readJson(path: string): SentinelConfig | undefined {
83
+ try {
84
+ return JSON.parse(readFileSync(path, "utf-8")) as SentinelConfig;
85
+ } catch {
86
+ return undefined;
87
+ }
88
+ }
89
+
90
+ function writeJson(path: string, value: SentinelConfig): void {
91
+ mkdirSync(dirname(path), { recursive: true });
92
+ writeFileSync(path, `${JSON.stringify(value, null, 2)}\n`, "utf-8");
93
+ }
94
+
95
+ function isPlainObject(value: unknown): value is Record<string, unknown> {
96
+ return typeof value === "object" && value !== null && !Array.isArray(value);
97
+ }
98
+
99
+ function mergeConfig<T>(base: T, override?: SentinelConfig | Record<string, unknown>): T {
100
+ if (!override) return structuredClone(base);
101
+ const result = structuredClone(base) as Record<string, unknown>;
102
+ for (const [key, value] of Object.entries(override)) {
103
+ if (value === undefined) continue;
104
+ const existing = result[key];
105
+ if (isPlainObject(existing) && isPlainObject(value)) {
106
+ result[key] = mergeConfig(existing, value);
107
+ } else if (Array.isArray(value)) {
108
+ result[key] = [...value];
109
+ } else {
110
+ result[key] = value;
111
+ }
112
+ }
113
+ return result as T;
114
+ }
115
+
116
+ function dedupe(values: string[]): string[] {
117
+ return [...new Set(values.filter((v) => typeof v === "string" && v.length > 0))];
118
+ }
119
+
120
+ export class SentinelConfigLoader {
121
+ private globalConfig: SentinelConfig | undefined;
122
+ private localConfig: SentinelConfig | undefined;
123
+ private memoryConfig: SentinelConfig = {};
124
+ private resolvedConfig: ResolvedSentinelConfig | undefined;
125
+ private localCwd = process.cwd();
126
+
127
+ load(cwd = process.cwd()): void {
128
+ this.localCwd = cwd;
129
+ this.globalConfig = readJson(this.getConfigPath("global"));
130
+ this.localConfig = readJson(this.getConfigPath("local"));
131
+ this.resolvedConfig = undefined;
132
+ }
133
+
134
+ getConfig(): ResolvedSentinelConfig {
135
+ if (this.resolvedConfig) return this.resolvedConfig;
136
+ let resolved = structuredClone(DEFAULT_SENTINEL_CONFIG) as ResolvedSentinelConfig;
137
+ resolved = mergeConfig(resolved, this.globalConfig);
138
+ resolved = mergeConfig(resolved, this.localConfig);
139
+ resolved = mergeConfig(resolved, this.memoryConfig);
140
+ resolved.pathAccess.allowedPaths = dedupe(resolved.pathAccess.allowedPaths);
141
+ resolved.permissionGate.allowedPatterns = dedupe(resolved.permissionGate.allowedPatterns);
142
+ resolved.permissionGate.autoDenyPatterns = dedupe(resolved.permissionGate.autoDenyPatterns);
143
+ resolved.outputScanner.readAllowedPaths = dedupe(resolved.outputScanner.readAllowedPaths);
144
+ this.resolvedConfig = resolved;
145
+ return resolved;
146
+ }
147
+
148
+ getRawConfig(scope: SentinelConfigScope): SentinelConfig | undefined {
149
+ return scope === "global" ? this.globalConfig : scope === "local" ? this.localConfig : this.memoryConfig;
150
+ }
151
+
152
+ getConfigPath(scope: Exclude<SentinelConfigScope, "memory">): string {
153
+ return scope === "global"
154
+ ? join(getAgentDir(), "extensions", "sentinel.json")
155
+ : join(this.localCwd, ".pi", "extensions", "sentinel.json");
156
+ }
157
+
158
+ save(scope: SentinelConfigScope, partial: SentinelConfig): void {
159
+ if (scope === "memory") {
160
+ this.memoryConfig = mergeConfig(this.memoryConfig, partial);
161
+ this.resolvedConfig = undefined;
162
+ return;
163
+ }
164
+
165
+ const current = scope === "global" ? (this.globalConfig ?? {}) : (this.localConfig ?? {});
166
+ const next = mergeConfig(current, partial);
167
+ writeJson(this.getConfigPath(scope), next);
168
+ if (scope === "global") this.globalConfig = next;
169
+ else this.localConfig = next;
170
+ this.resolvedConfig = undefined;
171
+ }
172
+
173
+ private addListValue(scope: SentinelConfigScope, path: string, list: "allowedPaths" | "readAllowedPaths"): void {
174
+ const raw = this.getRawConfig(scope);
175
+ const current = list === "allowedPaths"
176
+ ? raw?.pathAccess?.allowedPaths ?? []
177
+ : raw?.outputScanner?.readAllowedPaths ?? [];
178
+ const values = dedupe([...current, path]);
179
+ this.save(scope, list === "allowedPaths"
180
+ ? { pathAccess: { allowedPaths: values } }
181
+ : { outputScanner: { readAllowedPaths: values } });
182
+ }
183
+
184
+ addAllowedPath(scope: SentinelConfigScope, path: string): void {
185
+ this.addListValue(scope, path, "allowedPaths");
186
+ }
187
+
188
+ addReadAllowedPath(scope: SentinelConfigScope, path: string): void {
189
+ this.addListValue(scope, path, "readAllowedPaths");
190
+ }
191
+ }
192
+
193
+ export const configLoader = new SentinelConfigLoader();
@@ -0,0 +1,46 @@
1
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
+
3
+ export type SentinelFeature =
4
+ | "outputScanner"
5
+ | "executionTracker"
6
+ | "permissionGate"
7
+ | "pathAccess";
8
+
9
+ export interface SentinelBlockedEvent {
10
+ feature: SentinelFeature;
11
+ toolName: string;
12
+ input: Record<string, unknown>;
13
+ reason: string;
14
+ userDenied?: boolean;
15
+ }
16
+
17
+ export interface SentinelDangerousEvent {
18
+ feature: SentinelFeature;
19
+ toolName: string;
20
+ input: Record<string, unknown>;
21
+ description: string;
22
+ labels?: string[];
23
+ }
24
+
25
+ export type SentinelBlockResult = { block: true; reason: string };
26
+
27
+ function emitSentinelEvent(pi: ExtensionAPI, name: "sentinel:blocked" | "sentinel:dangerous", event: unknown): void {
28
+ try {
29
+ pi.events?.emit?.(name, event);
30
+ } catch {
31
+ // Event emission is best-effort and must never affect guard decisions.
32
+ }
33
+ }
34
+
35
+ export function emitBlocked(pi: ExtensionAPI, event: SentinelBlockedEvent): void {
36
+ emitSentinelEvent(pi, "sentinel:blocked", event);
37
+ }
38
+
39
+ export function blockToolCall(pi: ExtensionAPI, event: SentinelBlockedEvent, reason = event.reason): SentinelBlockResult {
40
+ emitBlocked(pi, event);
41
+ return { block: true, reason };
42
+ }
43
+
44
+ export function emitDangerous(pi: ExtensionAPI, event: SentinelDangerousEvent): void {
45
+ emitSentinelEvent(pi, "sentinel:dangerous", event);
46
+ }
@@ -20,6 +20,7 @@ import { resolve } from "node:path";
20
20
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
21
21
  import { isToolCallEventType } from "@earendil-works/pi-coding-agent";
22
22
 
23
+ import { blockToolCall, emitDangerous } from "../events.js";
23
24
  import type { SentinelSession } from "../session.js";
24
25
  import type { DangerousPattern, WriteEntry } from "../types.js";
25
26
 
@@ -221,6 +222,14 @@ export function registerExecutionTracker(
221
222
  continue;
222
223
  }
223
224
 
225
+ emitDangerous(pi, {
226
+ feature: "executionTracker",
227
+ toolName: "bash",
228
+ input: event.input,
229
+ description: "Bash command executes a session-written file with dangerous content.",
230
+ labels: currentPatterns,
231
+ });
232
+
224
233
  // Dangerous content confirmed — escalate
225
234
  const message = [
226
235
  `About to execute a file written earlier in this session:`,
@@ -239,12 +248,10 @@ export function registerExecutionTracker(
239
248
  }
240
249
 
241
250
  // No UI or user denied — block
242
- return {
243
- block: true,
244
- reason:
245
- `[sentinel] Blocked: bash executes ${scriptPath}, written this session ` +
246
- `with dangerous patterns: ${currentPatterns.join(", ")}.`,
247
- };
251
+ const reason =
252
+ `[sentinel] Blocked: bash executes ${scriptPath}, written this session ` +
253
+ `with dangerous patterns: ${currentPatterns.join(", ")}.`;
254
+ return blockToolCall(pi, { feature: "executionTracker", toolName: "bash", input: event.input, reason, userDenied: ctx.hasUI });
248
255
  }
249
256
  });
250
257
  }