@gotgenes/pi-permission-system 13.2.0 → 14.0.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/CHANGELOG.md CHANGED
@@ -5,6 +5,23 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [14.0.0](https://github.com/gotgenes/pi-packages/compare/pi-permission-system-v13.2.0...pi-permission-system-v14.0.0) (2026-06-17)
9
+
10
+
11
+ ### ⚠ BREAKING CHANGES
12
+
13
+ * project agents' `permission:` frontmatter at `<cwd>/.pi/agents/<name>.md` is now read and enforced. Previously the wrong directory (`<cwd>/.pi/agent/agents`) was checked and the frontmatter was silently ignored, so a session may become more restrictive on upgrade.
14
+
15
+ ### Bug Fixes
16
+
17
+ * correct project agents directory path to &lt;cwd&gt;/.pi/agents ([#428](https://github.com/gotgenes/pi-packages/issues/428)) ([eb5af78](https://github.com/gotgenes/pi-packages/commit/eb5af78193fa3cc574da6b8d80efd643ebce0ef9))
18
+
19
+
20
+ ### Documentation
21
+
22
+ * correct project agent override path to &lt;cwd&gt;/.pi/agents ([#428](https://github.com/gotgenes/pi-packages/issues/428)) ([d193d6a](https://github.com/gotgenes/pi-packages/commit/d193d6a61155fb4e4a064800509cdbbd84b0ceb9))
23
+ * fix stale project agents path in troubleshooting and ADR-0001 ([#428](https://github.com/gotgenes/pi-packages/issues/428)) ([95effeb](https://github.com/gotgenes/pi-packages/commit/95effebfd0b2e87db4512c91adc134b2470f26a3))
24
+
8
25
  ## [13.2.0](https://github.com/gotgenes/pi-packages/compare/pi-permission-system-v13.1.2...pi-permission-system-v13.2.0) (2026-06-17)
9
26
 
10
27
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gotgenes/pi-permission-system",
3
- "version": "13.2.0",
3
+ "version": "14.0.0",
4
4
  "description": "Permission enforcement extension for the Pi coding agent.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -21,6 +21,19 @@ export function getProjectConfigPath(cwd: string): string {
21
21
  return join(cwd, ".pi", "extensions", EXTENSION_ID, "config.json");
22
22
  }
23
23
 
24
+ /**
25
+ * Directory holding project-scoped custom agent definition files.
26
+ *
27
+ * `<cwd>/.pi/agents` is a Pi platform convention, also encoded by
28
+ * `@gotgenes/pi-subagents`' `loadCustomAgents` (`config/custom-agents.ts`).
29
+ * The two packages encode it independently — pi-permission-system has no
30
+ * dependency on pi-subagents (ADR-0002) — so this is this package's
31
+ * authoritative copy.
32
+ */
33
+ export function getProjectAgentsDir(cwd: string): string {
34
+ return join(cwd, ".pi", "agents");
35
+ }
36
+
24
37
  export function getLegacyGlobalPolicyPath(agentDir: string): string {
25
38
  return join(agentDir, "pi-permissions.jsonc");
26
39
  }
@@ -1,6 +1,10 @@
1
1
  import { join } from "node:path";
2
2
  import { isPermissionState } from "./common";
3
- import { getGlobalConfigPath, getProjectConfigPath } from "./config-paths";
3
+ import {
4
+ getGlobalConfigPath,
5
+ getProjectAgentsDir,
6
+ getProjectConfigPath,
7
+ } from "./config-paths";
4
8
  import { normalizeInput } from "./input-normalizer";
5
9
  import { normalizeFlatConfig } from "./normalize";
6
10
  import { PATH_SURFACES } from "./path-utils";
@@ -350,7 +354,7 @@ function derivePolicyLoaderOptions(
350
354
  globalConfigPath: getGlobalConfigPath(agentDir),
351
355
  agentsDir: join(agentDir, "agents"),
352
356
  projectGlobalConfigPath: cwd ? getProjectConfigPath(cwd) : undefined,
353
- projectAgentsDir: cwd ? join(cwd, ".pi", "agent", "agents") : undefined,
357
+ projectAgentsDir: cwd ? getProjectAgentsDir(cwd) : undefined,
354
358
  };
355
359
  }
356
360
 
@@ -9,6 +9,7 @@ import {
9
9
  getLegacyExtensionConfigPath,
10
10
  getLegacyGlobalPolicyPath,
11
11
  getLegacyProjectPolicyPath,
12
+ getProjectAgentsDir,
12
13
  getProjectConfigPath,
13
14
  REVIEW_LOG_FILENAME,
14
15
  } from "#src/config-paths";
@@ -42,6 +43,10 @@ describe("config-paths", () => {
42
43
  join(cwd, ".pi", "extensions", "pi-permission-system", "config.json"),
43
44
  );
44
45
  });
46
+
47
+ it("getProjectAgentsDir returns .pi/agents under cwd", () => {
48
+ expect(getProjectAgentsDir(cwd)).toBe(join(cwd, ".pi", "agents"));
49
+ });
45
50
  });
46
51
 
47
52
  describe("legacy paths", () => {
@@ -8,7 +8,11 @@ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
8
8
  import { homedir, tmpdir } from "node:os";
9
9
  import { dirname, join } from "node:path";
10
10
  import { describe, expect, it, test } from "vitest";
11
- import { getGlobalConfigPath, getProjectConfigPath } from "#src/config-paths";
11
+ import {
12
+ getGlobalConfigPath,
13
+ getProjectAgentsDir,
14
+ getProjectConfigPath,
15
+ } from "#src/config-paths";
12
16
  import {
13
17
  PermissionManager,
14
18
  type ScopedPermissionManager,
@@ -1669,6 +1673,53 @@ describe("PermissionManager — configureForCwd and agentDir option", () => {
1669
1673
  cleanup();
1670
1674
  }
1671
1675
  });
1676
+
1677
+ it("configureForCwd(cwd) derives projectAgentsDir at <cwd>/.pi/agents (regression: #428)", () => {
1678
+ // Bug: old code derived <cwd>/.pi/agent/agents instead of <cwd>/.pi/agents.
1679
+ // This test pins the correct path and verifies agentsDir is unchanged.
1680
+ const { agentDir, cwd, cleanup } = makeAgentDirSetup({
1681
+ globalPermission: { read: "allow" },
1682
+ });
1683
+ try {
1684
+ const manager = new PermissionManager({ agentDir });
1685
+ manager.configureForCwd(cwd);
1686
+ const paths = manager.getResolvedPolicyPaths();
1687
+ expect(paths.projectAgentsDir).toBe(getProjectAgentsDir(cwd));
1688
+ expect(paths.agentsDir).toBe(join(agentDir, "agents"));
1689
+ } finally {
1690
+ cleanup();
1691
+ }
1692
+ });
1693
+
1694
+ it("configureForCwd(cwd) enforces permission: frontmatter from <cwd>/.pi/agents/<agent>.md (regression: #428)", () => {
1695
+ // Bug: wrong directory meant project-agent frontmatter was never loaded.
1696
+ const { agentDir, cwd, cleanup } = makeAgentDirSetup({
1697
+ globalPermission: { read: "allow" },
1698
+ });
1699
+ try {
1700
+ // Write a project agent definition with a deny override.
1701
+ const projectAgentsDir = getProjectAgentsDir(cwd);
1702
+ mkdirSync(projectAgentsDir, { recursive: true });
1703
+ writeFileSync(
1704
+ join(projectAgentsDir, "coder.md"),
1705
+ "---\npermission:\n read: deny\n---\n# Coder\n",
1706
+ );
1707
+
1708
+ const manager = new PermissionManager({ agentDir });
1709
+ manager.configureForCwd(cwd);
1710
+
1711
+ // Without an agent name: global allow applies.
1712
+ expect(manager.checkPermission("read", { path: "foo.txt" }).state).toBe(
1713
+ "allow",
1714
+ );
1715
+ // With the "coder" agent: project-agent deny overrides global allow.
1716
+ expect(
1717
+ manager.checkPermission("read", { path: "foo.txt" }, "coder").state,
1718
+ ).toBe("deny");
1719
+ } finally {
1720
+ cleanup();
1721
+ }
1722
+ });
1672
1723
  });
1673
1724
 
1674
1725
  // ---------------------------------------------------------------------------