@mcowger/pi-plexus 1.10.0 → 1.12.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.
@@ -0,0 +1,51 @@
1
+ # Models-refresh event API
2
+
3
+ `plexus-pi` owns the committed Plexus catalog, so it accepts a versioned event-bus command that forces a live `/v1/models` refresh. This is the programmatic equivalent of `/plexus refresh`.
4
+
5
+ The API is versioned in its channel names and payloads, and follows the same request/reply and broadcast rules as the provider's other channels.
6
+
7
+ ## Channels and payloads
8
+
9
+ Send a refresh command on `plexus:models:refresh:v1`:
10
+
11
+ ```ts
12
+ interface ModelsRefresh {
13
+ version: 1;
14
+ requestId: string;
15
+ }
16
+ ```
17
+
18
+ Listen for a reply or broadcast on `plexus:models:state:v1`:
19
+
20
+ ```ts
21
+ interface ModelsState {
22
+ version: 1;
23
+ publisherId: string;
24
+ revision: number;
25
+ requestId?: string;
26
+ status: "idle" | "refreshing" | "ready" | "error";
27
+ modelCount?: number;
28
+ reason?: string;
29
+ }
30
+ ```
31
+
32
+ Incoming commands and outgoing states are validated with Zod. Malformed commands are ignored without a reply. Unknown keys are rejected.
33
+
34
+ ## Behavior
35
+
36
+ - A valid command forces a live refresh through Pi's `ModelRegistry` (`{ providers: ["plexus"], force: true }`), reusing the extension's existing catalog fetch, persistence, and publication path. The refresh re-evaluates the context and service-tier policy for the active model (see [policy-control.md](./policy-control.md)).
37
+ - The publisher moves through `refreshing` while the fetch runs, then `ready` with the committed `modelCount`, or `error` with a safe `reason`.
38
+ - Concurrent commands are coalesced: while a refresh is in flight, additional commands share it and each still receives a correlated reply. A command that arrives after the refresh completed starts a new one.
39
+ - A valid command always receives a correlated reply that echoes `requestId`. A reply does not advance `revision`; only a state change does.
40
+ - State changes are also broadcast without `requestId`. States are complete immutable replacements, never deltas, and are capped at 1 MiB. Invalid or oversized state becomes a small `error` state with no fabricated values.
41
+ - The `publisherId` is a UUID stable for the extension load; `revision` starts at `1` and increases monotonically.
42
+ - The command listener is installed during extension initialization and removed on `session_shutdown`.
43
+
44
+ ## Failure and availability
45
+
46
+ - If no publisher is loaded (an older `plexus-pi` or none at all), the command receives no reply. Hosts must treat silence as unavailable rather than assuming a refresh happened.
47
+ - A refresh that cannot start — for example before the session has started, when no registry is bound — fails through the same `error` state with a safe `reason`. Credentials, URLs, request headers, and raw backend errors are never published.
48
+
49
+ ## Manual refresh
50
+
51
+ `/plexus refresh` remains the interactive path and reports its result through the command UI. The event-bus command is intended for hosts that need to trigger a refresh programmatically.
package/package.json CHANGED
@@ -1,12 +1,16 @@
1
1
  {
2
2
  "name": "@mcowger/pi-plexus",
3
- "version": "1.10.0",
3
+ "version": "1.12.0",
4
4
  "description": "Plexus AI proxy plugin for the pi coding agent",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist/extension.js",
8
8
  "package.json",
9
- "README.md"
9
+ "README.md",
10
+ "context-policy.md",
11
+ "service-tiers.md",
12
+ "policy-control.md",
13
+ "models-control.md"
10
14
  ],
11
15
  "keywords": [
12
16
  "plexus",
@@ -38,5 +42,8 @@
38
42
  "url": "https://github.com/mcowger/plexus-agent-plugins.git",
39
43
  "directory": "packages/plexus-pi"
40
44
  },
41
- "license": "MIT"
45
+ "license": "MIT",
46
+ "dependencies": {
47
+ "zod": "^4.6.4"
48
+ }
42
49
  }
@@ -0,0 +1,97 @@
1
+ # Policy-control event API
2
+
3
+ `plexus-pi` publishes the context and service-tier advertisement for the committed Plexus catalog (see [context-policy.md](./context-policy.md) and [service-tiers.md](./service-tiers.md)). It also accepts a control command that selects, for the active session and model, which advertised context budget applies and which advertised service tier is active.
4
+
5
+ The API is versioned in its channel names and payloads.
6
+
7
+ ## Channels and payloads
8
+
9
+ Send a control command on `plexus:policy:set:v1`:
10
+
11
+ ```ts
12
+ interface PolicySet {
13
+ version: 1;
14
+ requestId: string;
15
+ longContext?: boolean; // at least one of longContext/serviceTier is required
16
+ serviceTier?: string | null; // null clears the tier
17
+ }
18
+ ```
19
+
20
+ Listen for a reply or broadcast on `plexus:policy:state:v1`:
21
+
22
+ ```ts
23
+ interface PolicyState {
24
+ version: 1;
25
+ publisherId: string;
26
+ revision: number;
27
+ requestId?: string;
28
+ applied: {
29
+ longContext: boolean;
30
+ serviceTier: string | null;
31
+ contextWindow?: number;
32
+ };
33
+ available: {
34
+ longContext: boolean;
35
+ serviceTier: boolean;
36
+ };
37
+ reason?: string;
38
+ }
39
+ ```
40
+
41
+ The extension validates incoming commands and outgoing state with Zod. Malformed commands are ignored without a reply. Strict objects: unknown keys are rejected.
42
+
43
+ ## Semantics
44
+
45
+ - The command always applies to the **active session and model** as observed by `plexus-pi`; it carries no model identifier.
46
+ - `longContext: true` selects the model's advertised maximum context budget (`maxContextTokens`). `longContext: false` selects the advertised short budget (`shortContextBudgetTokens`).
47
+ - `serviceTier` selects one of the model's advertised `serviceTiers`. `serviceTier: null` clears the selection back to the provider default. Omitting the field leaves it unchanged.
48
+ - A command must contain at least one of `longContext` or `serviceTier`.
49
+ - Defaults for the active model are `longContext: true` (the catalog behavior) and `serviceTier: null`. Nothing changes until a command selects otherwise.
50
+ - Selection is in-memory and session-scoped. It never writes the committed catalog or persisted defaults, and it resets on extension reload or when the active model changes.
51
+
52
+ ## Availability
53
+
54
+ `available` describes what the active model's committed advertisement supports:
55
+
56
+ - `available.longContext` is `true` only when the model advertises both limits and `shortContextBudgetTokens < maxContextTokens`, so there is a distinct short/max choice.
57
+ - `available.serviceTier` is `true` only when the model advertises at least one service tier.
58
+
59
+ The publisher never fabricates limits or tiers. When the active model has no qualifying advertisement — or the extension version has no policy publisher at all — the host observes `available: { longContext: false, serviceTier: false }` and a safe `reason`, or receives no reply, rather than a defaulted or invented value.
60
+
61
+ ## Validation and rejection
62
+
63
+ A command is validated against the current advertisement before anything is applied:
64
+
65
+ - A `longContext` selection is rejected when the model has no context policy, or when the short and maximum budgets are not distinct.
66
+ - A non-null `serviceTier` is rejected when the model has no service-tier policy or does not advertise that tier.
67
+ - Rejection is atomic: when any field fails validation, no field is applied. No partial application occurs.
68
+ - A rejection produces a correlated reply carrying the current state, an unchanged `revision`, and a safe `reason`. It does not broadcast.
69
+
70
+ ## Reply and broadcast rules
71
+
72
+ The rules match the existing snapshot channels:
73
+
74
+ - A valid command receives a correlated reply that echoes `requestId`, within the event handler's `emit()` call chain.
75
+ - A correlated reply never advances `revision`; only a state change does.
76
+ - The `publisherId` is a UUID that is stable for the extension load, and `revision` starts at `1` and increases monotonically.
77
+ - When a command changes the published state, the publisher also broadcasts the new state without `requestId`.
78
+ - Snapshots are complete immutable replacements, never deltas. Serialized state is capped at 1 MiB; invalid or oversized state becomes a small `unavailable` state with no fabricated values.
79
+ - The command listener is installed during extension initialization and removed on `session_shutdown`.
80
+
81
+ ## Visible effect
82
+
83
+ The selected state takes effect for the active model:
84
+
85
+ - The selected advertised tier is sent as `service_tier` on requests to the `plexus` provider for that model.
86
+ - The selected context mode changes the session's **effective context window** to the short budget or the maximum. This is a session-scoped model override: the committed catalog model and persisted defaults are unchanged, and the override is not persisted.
87
+
88
+ ## Reconciliation
89
+
90
+ The committed advertisement can change under a running session. On every catalog update (startup, cached restore, live refresh), `plexus-pi` re-evaluates the active model:
91
+
92
+ - If a refresh removes the context policy or makes the short and maximum budgets identical while the short budget was selected, the selection resets to the maximum and the override is cleared.
93
+ - If a refresh lowers the short budget, the new value is re-applied to the effective context window.
94
+ - If a refresh removes the selected service tier from the advertisement, the tier selection clears.
95
+ - Any resulting change advances `revision` and is broadcast with a safe `reason`.
96
+
97
+ A refresh that leaves the active model's advertisement unchanged produces no broadcast.
@@ -0,0 +1,57 @@
1
+ # Service-tier event API
2
+
3
+ `plexus-pi` publishes the advertised service tiers for models in the committed Plexus catalog over Pi's cross-extension event bus.
4
+
5
+ ## Channels and payloads
6
+
7
+ Request a snapshot on `plexus:service-tiers:request:v1`:
8
+
9
+ ```ts
10
+ { version: 1, requestId: string }
11
+ ```
12
+
13
+ Listen for a reply or broadcast on `plexus:service-tiers:snapshot:v1`:
14
+
15
+ ```ts
16
+ interface ServiceTierPolicy {
17
+ provider: string;
18
+ modelId: string;
19
+ serviceTiers: string[];
20
+ }
21
+
22
+ interface ServiceTiersSnapshot {
23
+ version: 1;
24
+ publisherId: string;
25
+ revision: number;
26
+ requestId?: string;
27
+ status: "ready" | "loading" | "unavailable";
28
+ policies: ServiceTierPolicy[];
29
+ fetchedAt?: number;
30
+ cached?: boolean;
31
+ reason?: string;
32
+ }
33
+ ```
34
+
35
+ Incoming requests and outgoing snapshots are validated with Zod. Invalid requests are ignored without logging their payload. A valid request receives the current in-memory snapshot synchronously during `pi.events.emit()` and echoes `requestId`; it never starts or waits for a network request. Replies do not advance the revision. Broadcasts omit `requestId` and replace the full previous snapshot.
36
+
37
+ ## Policy semantics
38
+
39
+ - `provider` and `modelId` are the IDs registered with Pi. For Plexus, the provider is `plexus` and `modelId` is the raw model ID, not its display name.
40
+ - `serviceTiers` is copied from the model's `service_tiers` array. Names are preserved as advertised. Empty, duplicate, malformed, or missing tier lists are not advertised.
41
+ - If the raw model has no `service_tiers` field, Plexus says that model does not support service tiers, so it gets no policy. A successful catalog with no models advertising tiers has `status: "ready"` and `policies: []`.
42
+ - Policies are emitted only for models included in the committed Pi catalog. Suppressed or removed models disappear from the next snapshot.
43
+ - Service-tier metadata is stored with each committed model, including an explicit marker for models with no advertised tiers. This lets a cached catalog distinguish known lack of support from an older cache that never stored service-tier metadata.
44
+
45
+ ## Lifecycle
46
+
47
+ - Each extension load creates a UUID `publisherId` and starts at revision `1`.
48
+ - `loading` is used while no usable catalog state is available. `unavailable` has no policies and includes a safe reason when metadata cannot be supplied. Both states have empty policy arrays.
49
+ - The revision advances only when the published state changes. Request/reply alone does not increment it.
50
+ - `fetchedAt` is the successful `/v1/models` fetch time, in Unix milliseconds. Cached snapshots set `cached: true` and preserve the original timestamp.
51
+ - A failed refresh retains the last committed snapshot. Catalog state changes are applied only inside Pi's generation-checked `context.publish()` transaction, so stale refreshes cannot replace a newer committed catalog.
52
+ - Snapshots are immutable complete replacements, validated before emission, and capped at 1 MiB. Oversized or invalid state becomes a small `unavailable` snapshot; policies are never truncated.
53
+ - The request listener is installed during extension initialization and removed on `session_shutdown` with the unsubscribe function from `pi.events.on()`.
54
+
55
+ Snapshots contain tier metadata only. They never include credentials, URLs, request headers, or raw backend errors.
56
+
57
+ A control command can select which advertised tier is active for the active session and model; see [policy-control.md](./policy-control.md).