@pi-kaush/pi-agent-mode 0.2.0 → 0.2.1

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
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ - Refresh Pi's local model catalog before `/agent` model selection and baseline
6
+ restoration, so a long-lived session sees newly configured profile candidates
7
+ without using the parent's model-cycling scope. Report refresh failures without
8
+ changing the active agent.
5
9
  - Add `profile` frontmatter: activate a named model profile from the shared machine-local `~/.pi/agent/profiles.yaml` (`@pi-kaush/pi-model-profiles`), walking candidates in order and applying the first available model and thinking level.
6
10
  - Reject agents declaring both `profile` and `model`; precedence is explicit: profile first, then model, then the session default.
7
11
  - Load `@pi-kaush/pi-model-profiles` lazily so a missing library degrades only profile support; `/agent` remains fully functional without it.
package/README.md CHANGED
@@ -48,10 +48,12 @@ Agent frontmatter may declare a `model` (exact model, optional thinking
48
48
  suffix) or a `profile` — a named entry in the shared machine-local
49
49
  `~/.pi/agent/profiles.yaml` maintained by
50
50
  [@pi-kaush/pi-model-profiles](../pi-model-profiles). An agent must not declare
51
- both. Profile candidates are walked in order at activation and the first
52
- model that exists and is authenticated wins; once the session is running,
53
- models never switch mid-request. Agents without either keep the current
54
- session model.
51
+ both. Before selecting a model, `/agent` refreshes Pi's local model catalog so
52
+ models added during a long-lived session can be used; the parent session's
53
+ `enabledModels` / `--models` cycling scope does not limit profile candidates.
54
+ Profile candidates are walked in order at activation and the first model that
55
+ exists and is authenticated wins; once the session is running, models never
56
+ switch mid-request. Agents without either keep the current session model.
55
57
 
56
58
  `pi-agent-mode` loads `@pi-kaush/pi-model-profiles` lazily: if the library is
57
59
  missing, only agents that declare `profile:` fail (with an install hint) and
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-kaush/pi-agent-mode",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Activate a configured Pi agent as a persistent mode in the current session.",
5
5
  "license": "MIT",
6
6
  "author": "Kaushik Gopal",
package/src/index.ts CHANGED
@@ -148,6 +148,26 @@ export function registerAgentMode(pi: ExtensionAPI) {
148
148
  pi.appendEntry(PI_AGENT_MODE_STATE_TYPE, state);
149
149
  }
150
150
 
151
+ async function refreshModelCatalog(ctx: ExtensionContext): Promise<boolean> {
152
+ try {
153
+ // Activation may happen after models.json changes in a long-lived session.
154
+ // Pi 0.80 accepts no options; newer Pi can suppress remote catalog fetches.
155
+ // The cycling scope is independent of the models an agent may select.
156
+ await (
157
+ ctx.modelRegistry.refresh as (options: {
158
+ allowNetwork: boolean;
159
+ }) => void | Promise<unknown>
160
+ )({ allowNetwork: false });
161
+ return true;
162
+ } catch (error) {
163
+ ctx.ui.notify(
164
+ `Could not refresh model catalog: ${error instanceof Error ? error.message : error}`,
165
+ "error",
166
+ );
167
+ return false;
168
+ }
169
+ }
170
+
151
171
  function findModel(modelSpec: string, ctx: ExtensionContext) {
152
172
  const spec = modelSpec.trim();
153
173
  const separator = spec.indexOf("/");
@@ -175,6 +195,7 @@ export function registerAgentMode(pi: ExtensionAPI) {
175
195
  if (ctx.model?.provider === model.provider && ctx.model.id === model.id)
176
196
  return true;
177
197
 
198
+ if (!(await refreshModelCatalog(ctx))) return false;
178
199
  const resolved = ctx.modelRegistry.find(model.provider, model.id);
179
200
  if (!resolved) {
180
201
  ctx.ui.notify(
@@ -290,6 +311,8 @@ export function registerAgentMode(pi: ExtensionAPI) {
290
311
  );
291
312
  return false;
292
313
  }
314
+ if ((agent.profile || agent.model) && !(await refreshModelCatalog(ctx)))
315
+ return false;
293
316
  if (agent.profile) {
294
317
  const applied = await applyProfileModels(agent, ctx);
295
318
  if (!applied) return false;