Skip to content

fix(omp): keep path-scoped bash.patterns and run sessionStart on session_clear - #3984

Merged
dyoshikawa merged 5 commits into
mainfrom
resolve-issue-3080-omp-scoped-bash-patterns
Nov 26, 2026
Merged

dyoshikawa merged 5 commits into
mainfrom
resolve-issue-3080-omp-scoped-bash-patterns

Conversation

@dyoshikawa

@dyoshikawa dyoshikawa commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

This PR follows up on the 2026-11-19 re-check of #3080 (oh-my-pi v18.20.x to v19.0.0). Three things change:

  • Generate no longer deletes folder-scoped bash.patterns entries.
  • Import no longer turns a folder-scoped allow into a global one.
  • sessionStart hooks now also run after /clear.

Upstream was checked against can1357/oh-my-pi@ce36c87: docs/settings.md, docs/extensions.md, and pathScopePrefixes / resolvePathScopedObjects in packages/coding-agent/src/config/settings.ts.

Changes

  • permissions, generate (src/features/permissions/omp-permissions.ts)
    • Rulesync now owns only the unscoped bash.patterns entries.
    • It keeps every existing entry scoped with path / paths / pathPrefix / pathPrefixes exactly as written. That covers both the inline { path, match, approval } form and wrappers under patterns / values / items.
    • A regenerated unscoped rule keeps the per-rule env list of the existing entry with the same normalized match, as long as its approval is unchanged.
    • bash.allowedEnvVars is a sibling key and was already kept. A test now covers it.
  • permissions, import
    • A scoped entry's deny / prompt rules, nested ones included, are imported as global bash rules.
    • Its allow rules are skipped.
    • Both cases log a warning that names the scope. toRulesyncPermissions now takes the logger.
  • hooks (pi-extension-generator.ts)
    • PiExtensionDialect gets an extraEventNames map. It is empty for Pi and { sessionStart: ["session_clear"] } for oh-my-pi, so canonical sessionStart commands also subscribe to session_clear.
    • The shared Pi map is unchanged.
  • docs: the omp permissions and hooks notes in docs/reference/file-formats.md now cover:
    • kept scoped entries and where they are placed
    • kept env lists and bash.allowedEnvVars
    • how scoped entries import
    • project and --config lists being prepended to the global list
    • a project being unable to loosen deny / prompt
    • session_clear being awaited and unable to cancel the reset
  • Tests for each item.

Design decisions

  • Where kept scoped entries go (this differs from the triage plan, which put them first). oh-my-pi uses the first matching rule. If every scoped entry led the list, a folder-scoped allow would override a Rulesync deny / prompt inside that folder. So each kept entry is placed by its most permissive rule:

    • an entry with only deny rules goes first
    • an entry whose loosest rule is prompt goes after Rulesync's denies
    • an entry with any allow goes after Rulesync's prompts, ahead of Rulesync's allows

    A scoped rule therefore never loosens a Rulesync restriction, and a scoped restriction still beats a Rulesync allow. Entries are kept whole, never split, so the user's file structure is preserved.

  • What import does with scoped entries (refines the plan's "skip everything"). Skipping a scoped deny would leave other targets more permissive inside that folder, for example a later global git * allow with no git push* deny. Restrictions are therefore folded in as global rules, which is stricter than the scope, and only allows are skipped. Nothing scoped ever comes back as a broader allow. One side effect: an import followed by a generate adds a global copy of those restrictions next to the kept scoped entry.

  • What counts as "scoped". This mirrors upstream pathScopePrefixes: an entry counts as scoped only when a path key holds a string, or an array that contains strings. An entry such as path: ~ (YAML null) is unscoped upstream and applies everywhere, so Rulesync treats it as a normal owned entry.

  • Import order (review round 1). A rule taken from a scoped entry never takes the first-match slot from a later unscoped rule for the same pattern. When both exist, the stricter one is imported (deny > ask). The import warning lists only the scoped restrictions that actually changed the imported rules.

  • Mixed scoped entries are kept whole, not split. Splitting would add a copy to the user's file, and that copy would multiply on every regenerate. So an entry that mixes allow and deny stays in the allow slot. Inside its scope, its deny loses to a matching Rulesync prompt rule and only prompts. This is documented and logs a warning. An entry that sits after a generated catch-all * deny/prompt can never be reached; that also logs a warning and is documented.

  • What env carry-over copies. Only env is copied, and only on an exact normalized match plus approval match. If the approval changes, the old allowlist is dropped.

Skipped items (still open on #3080)

  • Mapping folder-shaped canonical ask rules to tools.restrictedFolders (optional item 2 of 2026-10-27). A restricted folder is stricter than the canonical rule, so this needs a semantics decision first.
  • The notification hook. Upstream still has no ui_prompt_start equivalent.
  • Profile-aware global paths (OMP_PROFILE / PI_CODING_AGENT_DIR / getAgentDir()). These need a cross-target design for env-dependent roots.

Refs #3080

🤖 Generated with Claude Code

https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4

dyoshikawa and others added 5 commits November 26, 2026 16:41
…ion_clear

- Keep folder-scoped bash.patterns entries on generate, placed by their
  loosest rule so they never loosen a rulesync deny or prompt rule.
- Carry a per-rule env list over to a regenerated rule with the same
  match and approval.
- On import, fold scoped deny/prompt rules into global rules and skip
  scoped allow rules with a warning instead of widening them.
- Subscribe sessionStart hooks to oh-my-pi's session_clear as well.

Refs #3080

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
…p-scoped-bash-patterns

# Conflicts:
#	src/generated/docs-content.ts
- On import, a rule from a path-scoped entry no longer takes the first-match
  slot from a later unscoped rule for the same pattern; the stricter wins.
- Warn only about scoped restrictions that changed the imported rules.
- Warn when a kept scoped entry mixes allow and deny rules, or sits after
  a generated catch-all restriction, and document both.

Refs #3080

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
…p-scoped-bash-patterns

# Conflicts:
#	src/generated/docs-content.ts
…p-scoped-bash-patterns

# Conflicts:
#	src/generated/docs-content.ts
@dyoshikawa
dyoshikawa merged commit 01a0bdc into main Nov 26, 2026
10 checks passed
@dyoshikawa
dyoshikawa deleted the resolve-issue-3080-omp-scoped-bash-patterns branch November 26, 2026 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant