psmux-plugins icon indicating copy to clipboard operation
psmux-plugins copied to clipboard

Support `#branch` suffix and 3-segment monorepo notation in `@plugin` specs

Open MattKotsenas opened this issue 6 months ago • 2 comments

Scenario

While drafting #15 against psmux-continuum, I forked the monorepo to MattKotsenas/psmux-plugins to validate my fix end-to-end before opening the PR. Today's @plugin syntax can't address a monorepo subdir from an arbitrary owner: the short form psmux-plugins/psmux-continuum only resolves because PPM has a hardcoded MONOREPO_MAP entry mapping psmux-plugins to psmux/psmux-plugins. To install the same plugin from my fork's monorepo subdir, I had to edit ppm.ps1 directly:

 $script:MONOREPO_MAP = @{
     'psmux-plugins' = 'psmux/psmux-plugins'
+    'mattkotsenas'  = 'MattKotsenas/psmux-plugins'
 }

That feels like the wrong shape - editing the package manager's source to register a new plugin source isn't additive in spirit, and there's no documented extension point.

Additionally, even after the MONOREPO_MAP edit, PPM does shallow clones of the default branch only (no --branch support). So the fix has to live on the fork's main, not a feature branch - polluting main and breaking my ability to track the fix branch as it evolves.

Proposed direction (inspired by TPM)

Two small additive features that together solve this cleanly.

A. #branch suffix. Port of TPM's install_plugins.sh: split the spec on #, pass the second half to git clone -b. Same syntax in PPM:

set -g @plugin 'MattKotsenas/psmux-continuum#fix-branch'

B. 3-segment subdir notation. TPM doesn't face the monorepo problem (each tmux plugin is its own repo). For PPM's monorepo model, let the spec self-describe:

set -g @plugin 'MattKotsenas/psmux-plugins/psmux-continuum'

Three segments -> <owner>/<monorepo>/<subdir> -> routes through the existing Install-FromMonorepo with an explicit source instead of a MONOREPO_MAP lookup.

Combined, the original scenario collapses to one config line - no ppm.ps1 edits, no fork-main pollution:

set -g @plugin 'MattKotsenas/psmux-plugins/psmux-continuum#fix-branch'

Resolution order

The spec is split on # first into (base, branch_or_null). The base is then resolved by shape:

Form Behavior
https://... / git@... Clone URL directly
owner/repo/subdir (3 segments, new) Clone github.com/owner/repo.git, extract subdir subdir. No probe, no MONOREPO_MAP involvement.
owner/repo (2 segments) (existing) Try github.com/owner/repo.git; on failure, if owner is in MONOREPO_MAP, clone map[owner] and extract subdir repo.
Bare name (existing) Treated as psmux-plugins/<name>.

If branch_or_null is set, --branch <name> is appended to whichever clone the above runs.

In effect, a MONOREPO_MAP entry 'X' = 'A/B' becomes shorthand for the 3-segment form: X/Y is equivalent to A/B/Y (modulo the leading probe for backward compat). Users addressing any other monorepo just use the 3-segment form - no map entry needed.

Note on the probe-first ordering for 2-segment specs. This proposal preserves today's "try direct clone, fall back to map" order to avoid a behavior change. An alternative ordering - map-first when owner matches MONOREPO_MAP, else probe - would (a) skip a guaranteed 404 git request per psmux-plugins/* install, and (b) close a potential squatting vector where someone publishes github.com/psmux-plugins/<name> as a real repo and PPM silently prefers it over the legit monorepo subdir. The cost is a potential behavior change for anyone who actually intended the direct repo to win. Raising as a follow-up consideration rather than bundling here.

Considered alternative

A configurable MONOREPO_MAP via psmux options (e.g. set -g @ppm-monorepo-<alias> '...') would also work, but seems strictly less powerful than B and adds config state.

Question

Does this direction align with your vision for PPM? If so, happy to send one PR covering A + B. If you'd prefer them sequential, or have a different model in mind, let me know. Thanks!

MattKotsenas avatar May 13 '26 05:05 MattKotsenas

@MattKotsenas, I’ve reviewed the proposal, and I think this is the right mechanical path forward. Please proceed with a PR for review.

From a long-term strategy perspective, this change is more than just a convenience fix; it effectively democratizes the psmux ecosystem. By allowing the @plugin spec to self-describe its location (owner/repo/subdir), we decouple the plugin lifecycle from the main repository. This allows developers to host, version, and share their own plugins without needing to be "registered" in a central map. It also significantly lowers the friction for testing forks and feature branches, as you’ve already demonstrated.

However, as we move toward this "open federation" model, we should consider the inherent trade-offs:

  • Security & Trust: In the current centralized model, a user knows that any plugin they install has been "vetted" by virtue of it being in the official monorepo. Opening this up makes it easier for users to accidentally point to malicious or unmaintained third-party repositories.
  • Ecosystem Fragmentation: With democratization comes the risk of "plugin sprawl." If everyone hosts their own version of a common tool, discoverability becomes harder for the end-user compared to a single, unified source of truth.
  • Maintenance Overhead: Supporting a 3-segment notation adds complexity to the PPM logic. We need to ensure the resolution order (direct clone vs. map fallback) is robust so we don't introduce breaking changes or performance regressions during the "probe" phase.

I’m willing to accept these trade-offs in exchange for the flexibility and growth this enables. When you submit the PR, let's ensure the documentation clearly reflects how these new paths are resolved.

Looking forward to the review!

@psmux, what do you think?

tarikguney avatar May 16 '26 00:05 tarikguney

Hey @MattKotsenas, this is implemented now in commit 21acab7. Thank you for such a thorough proposal, it made this a very clean implementation, I basically just translated your resolution table directly into ppm.ps1.

Exact syntax examples now supported:

set -g @plugin 'MattKotsenas/psmux-continuum#fix-branch'
set -g @plugin 'MattKotsenas/psmux-plugins/psmux-continuum'
set -g @plugin 'MattKotsenas/psmux-plugins/psmux-continuum#fix-branch'

Resolution order as shipped, matching your table exactly:

  1. The spec is split on # first into (base, branch). branch, when present, is passed as git clone --branch <branch> to whichever clone the resolved base triggers.
  2. https://... or git@... clones the URL directly.
  3. owner/repo/subdir (3 segments) clones github.com/owner/repo.git and extracts subdir. No probe, no MONOREPO_MAP involvement at all.
  4. owner/repo (2 segments) and bare names keep their existing behavior, with one change noted below.

On your map first note. I actually ended up shipping that as part of fixing #25 (a user was hitting an interactive GitHub sign in prompt because the probe clone for psmux-plugins/<name> always returns a 401 before GitHub reveals the 404, and without a cached credential that pops Git Credential Manager's sign in window). Since your proposal called this out as the sane follow up, I folded it into the same underlying MapFirst mechanism that now also drives the 3-segment routing here. So today, owner/repo where owner is a known MONOREPO_MAP alias skips the probe and clones the monorepo directly, exactly as you suggested. Unmapped owners still probe first with a fallback, so the behavior change is scoped to the case that was always going to 404 anyway, nothing that could have "won" a real repo lookup changes.

@tarikguney, replying to your points from the review:

Security and trust: agreed this is the real tradeoff of opening up arbitrary owner/repo/subdir specs. I did not add any extra vetting on top of what git clone itself provides. The mitigation ppm now has is on the failure side rather than the trust side: every clone ppm runs (probe, monorepo, or explicit 3-segment) goes through a wrapper that disables interactive credential prompts, so a bad or malicious-looking spec fails fast and visibly instead of ever silently prompting the user for GitHub credentials.

Ecosystem fragmentation: no code mitigation for this one, it is a real tradeoff of the design as you said. I did keep psmux-plugins/<name> as the privileged short form for the official monorepo so there is still one canonical, low friction path for anything that is actually in the monorepo, forks are opt in and require the extra typing of the fork owner.

Maintenance overhead: the resolution order table is now the single source of truth in both ppm/ppm.ps1 (as a comment above Resolve-PluginSpec) and ppm/README.md, so there is one place to update if this evolves further. I added tests/test_ppm_spec_resolution.ps1 covering all four resolution shapes plus branch splitting as unit style cases, and one real install against MattKotsenas/psmux-plugins/psmux-continuum#feat/ppm-branch-and-subdir-syntax (including a negative test with a bogus branch name to prove --branch is genuinely enforced, not silently dropped), so regressions in the probe versus map ordering should show up immediately.

Docs are updated in ppm/README.md with the full table and examples.

Closing this out now, thanks again both of you for the design work here.

psmux avatar Jul 17 '26 19:07 psmux