mirror of
https://bitbucket.org/siakitem/my-pi.git
synced 2026-08-28 16:45:22 +00:00
107 lines
10 KiB
Markdown
107 lines
10 KiB
Markdown
---
|
|
issue: 438
|
|
issue_title: "pi-permission-system: Session approval for path-bearing tools on files in the current working directory never matches (always re-prompts)"
|
|
---
|
|
|
|
# Retro: #438 — Bound session approval for current-directory files
|
|
|
|
## Stage: Planning (2026-06-20T01:37:22Z)
|
|
|
|
### Session summary
|
|
|
|
Planned the fix for the dead session-approval rule on CWD-root files.
|
|
Confirmed the root cause: `deriveApprovalPattern("index.html")` returns `"./*"` (because `dirname` is `"."`), which never matches the policy values `["<abs-cwd>/index.html", "index.html"]` that carry no `"./"` prefix.
|
|
Wrote `packages/pi-permission-system/docs/plans/0438-bound-session-approval-cwd-root-files.md` with a four-step TDD plan.
|
|
|
|
### Observations
|
|
|
|
- This is a **third-party** issue (author `Alexoidus` ≠ the gh CLI user), so the `ask-user` direction gate was mandatory.
|
|
The operator chose the **bounded** fix (`<cwd>/*`) over the issue's literal suggestion (`return "*"`), which would have over-approved every path — including files outside CWD — for the rest of the session, conflicting with the package's least-privilege priority.
|
|
- The issue's reproduction configures the `edit` **tool** surface (`edit: { "*": "ask" }`), so the **primary** affected gate is the per-tool gate (`describeToolGate` → `suggestSessionPattern`), not the cross-cutting `path` gate the issue's "Affected code" section emphasizes.
|
|
The cross-cutting `path` gate (`path.ts`) and the bash `path` gate (`bash-path.ts`) are the same root-relative bug, so all three thread `tcc.cwd`.
|
|
- Chose **Strategy 2** (only the `dirname === "."` branch changes) over Strategy 1 (derive every pattern from the absolute path).
|
|
Strategy 1 would have changed the readable sub-directory dialog label from `edit "src/*"` to `edit "/Users/.../project/src/*"` — a UX regression for the common case.
|
|
Only the currently-broken root branch shows the absolute CWD glob, which is unavoidable for boundedness.
|
|
- `external-directory.ts` already passes the absolute path to `deriveApprovalPattern`, so external-directory approvals were never affected — a useful precedent the fix mirrors.
|
|
- Verified no import cycle: `session-rules.ts` will import `normalizePathForComparison` from `path-utils.ts`, and `path-utils` imports neither `session-rules` nor `pattern-suggest`.
|
|
- The `cwd`-absent edge keeps its safe-but-re-prompting `"./*"` output (no absolute policy value exists to bind to); flagged as a Non-Goal rather than over-approving with `"*"`.
|
|
- Release: ship independently — not part of any roadmap phase or release batch.
|
|
|
|
## Stage: Implementation — TDD (2026-06-20T01:48:25Z)
|
|
|
|
### Session summary
|
|
|
|
Fixed the dead session-approval rule for current-directory files by making every path gate derive the approval pattern from the canonical (cwd-resolved, absolute) path, so the pattern matches the policy values a later call produces.
|
|
`deriveApprovalPattern` and `suggestSessionPattern` stay single-arg pure functions; the per-tool gate (`tool.ts`), cross-cutting `path` gate (`path.ts`), and bash `path` gate (`bash-path.ts`) resolve to the canonical path before deriving — the tool/path gates via `normalizePathForComparison(path, tcc.cwd)` (mirroring the existing `external-directory.ts`), and the bash gate from its already-captured `policyValues[0]`.
|
|
Test count `pi-permission-system` 2029 → 2033 (+4); full suite, `check`, root `lint`, and `fallow dead-code` all green.
|
|
|
|
### Observations
|
|
|
|
- **Design pivot mid-session.**
|
|
The first implementation threaded an optional `{ cwd }` parameter down into `deriveApprovalPattern` (and `suggestSessionPattern`).
|
|
On review this was judged a design degradation — optionality on a core leaf function where none existed — so it was reworked into resolve-at-gate before shipping.
|
|
The unpushed commits were collapsed (`git reset --mixed` to the planning-retro commit) into one clean `fix:` so the abandoned approach does not pollute history or the changelog.
|
|
- **Root structural cause.**
|
|
The bug was drift between two representations of the same path — the approval *pattern* (derived without cwd → `./*`) and the policy *values* (derived with cwd → `[<abs>/index.html, index.html]`).
|
|
Binding both to the canonical absolute form removes the drift class, not just the root-file symptom.
|
|
`external-directory.ts` already did this; `path.ts`/`bash-path.ts` were the inconsistent gates.
|
|
- **Tradeoff accepted (operator-confirmed via `ask_user`).**
|
|
Canonicalizing for matching also makes the "for this session" dialog label absolute (`edit "src/*"` → `edit "/…/project/*"`).
|
|
Judged acceptable/clearer for a permission grant; the alternative (a `PathApprovalTarget` value object separating match-pattern from display-label) was offered and declined as more surface area than warranted.
|
|
- **Bash token nuance.**
|
|
A bare `index.html` (no leading `.`, no `/`) is rejected by `classifyTokenAsRuleCandidate`, so the realistic bash root-relative case is a dotfile (`cat .env`); the test uses that.
|
|
Deriving from `policyValues[0]` also tightens cd-offset cases (`cd sub && cat .env` → `/…/project/sub/*`) for free.
|
|
- The pure functions `deriveApprovalPattern` / `suggestSessionPattern` reverted to their original signatures (only a doc-comment contract added); no architecture-doc update needed (bug fix, not a roadmap step).
|
|
- A fresh pre-completion review should run against the final design before `/ship-issue` (the earlier PASS was for the superseded optional-param implementation).
|
|
|
|
## Stage: Final Retrospective (2026-06-20T02:24:01Z)
|
|
|
|
### Session summary
|
|
|
|
Shipped #438 as `pi-permission-system` v15.0.1 — a bug fix so "Allow for this session" sticks for files in the current working directory.
|
|
The full arc spanned planning, four TDD cycles, a mid-session design pivot (optional-`cwd`-parameter → resolve-at-gate), and a clean independent release.
|
|
The defining event was a user-caught design degradation that triggered a full re-implementation of already-reviewed, already-green code.
|
|
|
|
### Observations
|
|
|
|
#### What went well
|
|
|
|
- The mid-session design pause produced a strictly better design: resolve-at-gate removed the entire pattern/values drift *class* (not just the root-file symptom) and unified the three path gates with the existing `external-directory.ts` precedent.
|
|
- Clean unpushed-history hygiene — the abandoned optional-param commits were collapsed via `git reset --mixed` (twice: once for the rework, once to fold in the WARN-fix test), so the changelog shows a single `fix:` with no dead-end churn.
|
|
This exercised the `AGENTS.md` "reorder unpushed commits with `git reset` + re-commit" guidance under real rework, including the re-split discipline (mixed reset, then `git add` per commit).
|
|
- Verification ran incrementally throughout TDD (`check` after the signature-changing step, targeted file tests per cycle), so no end-only feedback gap.
|
|
|
|
#### What caused friction (agent side)
|
|
|
|
- `instruction-violation` (user-caught) — during planning I loaded `package-pi-permission-system`, `colgrep`, `markdown-conventions`, and `testing`, but **not** `code-design` or `design-review`, both of which `plan-issue` instructs loading (`design-review`'s checklist is mandated for layer-wiring changes).
|
|
The optional-`cwd` design is a textbook `code-design` "Parameter relay" smell — `suggestSessionPattern` purely relayed `cwd` to `deriveApprovalPattern` — which that check would likely have flagged.
|
|
Impact: the smell passed planning → four TDD commits → a PASS pre-completion review before the user caught it; cost a full re-implementation (revert both leaf functions to single-arg, resolve-at-gate in three gates), a second pre-completion review, and two `git reset` re-folds.
|
|
The single largest rework of the issue.
|
|
- `premature-convergence` — at planning I explicitly weighed Strategy 1 (resolve to absolute everywhere) against Strategy 2 (optional `cwd` param on the `dirname === "."` branch) and chose Strategy 2 to preserve a cosmetic dialog label (`edit "src/*"` rather than an absolute path).
|
|
I optimized a label nicety over a structural principle, and decided the fork unilaterally.
|
|
Impact: the same rework above; the label tradeoff I was protecting was ultimately accepted as absolute anyway.
|
|
- `wrong-abstraction` — the plan's `ask_user` gate surfaced the security tradeoff (bounded `<cwd>/*` vs universal `*`), which I had already resolved correctly, but silently decided the higher-cost structural tradeoff (optional param vs resolve-at-gate).
|
|
I asked the operator about the wrong axis.
|
|
|
|
#### What caused friction (user side)
|
|
|
|
- The design intervention was strategic and high-value, but arrived after TDD and a PASS review.
|
|
The plan had already documented the Strategy 1 vs Strategy 2 fork in prose; had that fork been routed through the plan's `ask_user` gate, the operator could have redirected before any code was written.
|
|
Opportunity: when a plan records competing design strategies, surface the highest-cost one through `ask_user` so review happens at plan time, not post-implementation.
|
|
|
|
### Diagnostic details
|
|
|
|
- **Model-performance correlation** — judgment-heavy stages (planning, TDD, design rework, this retro) ran on `claude-opus-4-8`; the mechanical ship stage ran on `claude-sonnet-4-6`.
|
|
Appropriate split.
|
|
The `pre-completion-reviewer` subagent ran twice (fresh context); its first PASS validated conformance to an already-endorsed plan and did not flag the optionality smell — a reminder that a fresh-context reviewer checking against the plan inherits the plan's blind spots.
|
|
No model mismatch.
|
|
- **Escalation-delay** — no rabbit-holes; the one test miss (`cat index.html` — a bare token rejected by `classifyTokenAsRuleCandidate` — switched to `cat .env`) resolved in a single iteration.
|
|
- **Unused-tool** — the `design-review` skill was the available, prompt-mandated check not run at planning time; it is the root of the agent-side friction.
|
|
- **Feedback-loop** — incremental verification per TDD cycle, plus full suite + `check` + root `lint` + `fallow dead-code` after the rework.
|
|
No gap.
|
|
|
|
### Changes made
|
|
|
|
1. `.pi/skills/design-review/SKILL.md` — added a "When to invoke" bullet so a change that reads as a localized bug fix but adds or relays a parameter across functions triggers the review (a bug fix can be a wiring change).
|
|
First placed in `.pi/prompts/plan-issue.md` and relocated here on review: the skill owns its own applicability criteria, its existing triggers were all framed around refactors/plans (the gap this closes), and `plan-issue` already loads it for "change to shared interfaces or layer wiring."
|