@phren/agent 0.3.31 → 0.3.33

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.
@@ -1,5 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Box, Text, useInput } from "ink";
3
+ import { useState } from "react";
4
+ import { pickerRows, movePicker, pickerWindow } from "../../multi/picker-navigation.js";
3
5
  import { REASONING_LEVELS } from "../../models.js";
4
6
  function meter(level, theme) {
5
7
  if (!level)
@@ -9,21 +11,31 @@ function meter(level, theme) {
9
11
  return "\u25cf".repeat(filled) + "\u25cb".repeat(5 - filled);
10
12
  }
11
13
  export function ModelPicker({ state, theme, onMove, onReasoning, onSelect, onCancel }) {
14
+ const [query, setQuery] = useState("");
15
+ const rows = pickerRows(state.models, query);
16
+ const visible = pickerWindow(rows, state.cursor, Math.max(3, Math.min(12, (process.stdout.rows || 24) - 10)));
17
+ const search = (next) => {
18
+ setQuery(next);
19
+ const matches = pickerRows(state.models, next);
20
+ if (matches.length && !matches.includes(state.cursor))
21
+ onMove(matches[0] - state.cursor);
22
+ };
12
23
  useInput((input, key) => {
13
24
  if (key.escape) {
14
25
  onCancel();
15
26
  return;
16
27
  }
17
28
  if (key.return) {
18
- onSelect();
29
+ if (rows.length)
30
+ onSelect();
19
31
  return;
20
32
  }
21
33
  if (key.upArrow) {
22
- onMove(-1);
34
+ onMove(movePicker(rows, state.cursor, -1) - state.cursor);
23
35
  return;
24
36
  }
25
37
  if (key.downArrow) {
26
- onMove(1);
38
+ onMove(movePicker(rows, state.cursor, 1) - state.cursor);
27
39
  return;
28
40
  }
29
41
  if (key.leftArrow) {
@@ -34,10 +46,17 @@ export function ModelPicker({ state, theme, onMove, onReasoning, onSelect, onCan
34
46
  onReasoning(1);
35
47
  return;
36
48
  }
49
+ if (key.backspace || key.delete) {
50
+ search(query.slice(0, -1));
51
+ return;
52
+ }
53
+ if (input && !key.ctrl && !key.meta && !/[\x00-\x1f\x7f]/.test(input))
54
+ search((query + input).slice(0, 100));
37
55
  });
38
56
  const accent = theme?.statusBar.accent ?? "cyan";
39
- return (_jsxs(Box, { flexDirection: "column", borderStyle: "round", borderColor: accent, paddingX: 1, marginTop: 1, children: [_jsxs(Box, { children: [_jsx(Text, { bold: true, children: "Select model " }), _jsx(Text, { dimColor: true, children: "\u2191\u2193 navigate \u00b7 \u2190\u2192 reasoning \u00b7 enter select \u00b7 esc cancel" })] }), state.models.map((model, i) => {
57
+ return (_jsxs(Box, { flexDirection: "column", borderStyle: "round", borderColor: accent, paddingX: 1, marginTop: 1, children: [_jsxs(Box, { children: [_jsx(Text, { bold: true, children: "Select model " }), _jsx(Text, { dimColor: true, children: "\u2191\u2193 navigate \u00b7 \u2190\u2192 reasoning \u00b7 enter select \u00b7 esc cancel" })] }), _jsxs(Text, { dimColor: true, children: ["Search: ", query || "type to filter", " \u00B7 ", rows.length, " models"] }), !rows.length && _jsx(Text, { dimColor: true, children: "No matching models." }), visible.map(i => {
58
+ const model = state.models[i];
40
59
  const selected = i === state.cursor;
41
- return (_jsxs(Text, { color: selected ? accent : undefined, dimColor: !selected, children: [selected ? "\u25b8 " : " ", model.label, _jsxs(Text, { dimColor: true, children: [" ", meter(state.reasoning[i], theme), state.reasoning[i] ? ` ${state.reasoning[i]}` : ""] }), _jsxs(Text, { dimColor: true, children: [" ", Math.round(model.contextWindow / 1000), "k"] })] }, model.id));
60
+ return (_jsxs(Text, { wrap: "truncate-end", color: selected ? accent : undefined, dimColor: !selected, children: [selected ? "\u25b8 " : " ", model.label, _jsxs(Text, { dimColor: true, children: [" ", meter(state.reasoning[i], theme), state.reasoning[i] ? ` ${state.reasoning[i]}` : ""] }), _jsxs(Text, { dimColor: true, children: [" ", model.contextWindow ? `${Math.round(model.contextWindow / 1000)}k` : "? context"] })] }, `${model.provider}/${model.id}`));
42
61
  })] }));
43
62
  }
@@ -1,4 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { moveReasoning } from "../multi/picker-navigation.js";
2
3
  import { render } from "ink";
3
4
  import { createSession, runTurn } from "../agent-loop.js";
4
5
  import { emitHerdrHook, setHerdrHookSession } from "../herdr-hooks.js";
@@ -11,7 +12,7 @@ import * as os from "os";
11
12
  import * as fs from "node:fs";
12
13
  import { execSync } from "node:child_process";
13
14
  import * as path from "node:path";
14
- import { loadInputMode, saveInputMode, savePermissionMode, loadTheme, saveTheme, loadInputHistory, saveInputHistory } from "../settings.js";
15
+ import { loadInputMode, saveInputMode, savePermissionMode, loadTheme, saveTheme, loadInputHistory, saveInputHistory, saveModelSelection } from "../settings.js";
15
16
  import { contextTokens } from "../context/usage.js";
16
17
  import { READ_ONLY_TOOLS } from "../permissions/checker.js";
17
18
  import { nextPermissionMode } from "./ansi.js";
@@ -20,8 +21,7 @@ import { createRequire } from "node:module";
20
21
  import { randomUUID } from "node:crypto";
21
22
  import { persistFork } from "../session/persist.js";
22
23
  import { getTheme, THEME_NAMES } from "./themes.js";
23
- import { getAvailableModels } from "../multi/model-picker.js";
24
- import { REASONING_LEVELS } from "../models.js";
24
+ import { discoverAvailableModels } from "../multi/model-picker.js";
25
25
  const _require = createRequire(import.meta.url);
26
26
  const AGENT_VERSION = _require("../../package.json").version;
27
27
  export async function startInkTui(config, spawner) {
@@ -257,18 +257,20 @@ export async function startInkTui(config, spawner) {
257
257
  update();
258
258
  resolve?.(index);
259
259
  }
260
- function openModelPicker() {
260
+ async function openModelPicker() {
261
261
  const providerName = config.provider.name;
262
262
  if (!providerName)
263
263
  return Promise.resolve(null);
264
264
  const currentModel = config.provider.model;
265
- const models = getAvailableModels(providerName, currentModel);
265
+ const models = await discoverAvailableModels(providerName, currentModel);
266
266
  if (models.length === 0)
267
267
  return Promise.resolve(null);
268
- let cursor = models.findIndex((m) => m.id === currentModel);
268
+ let cursor = models.findIndex((m) => m.provider === providerName && m.id === currentModel);
269
269
  if (cursor < 0)
270
270
  cursor = 0;
271
- const reasoning = models.map((m) => m.id === currentModel ? (config.provider.reasoningEffort ?? m.reasoning) : m.reasoning);
271
+ const reasoning = models.map((m) => m.provider === providerName && m.id === currentModel && config.provider.reasoningEffort && m.reasoningRange.includes(config.provider.reasoningEffort)
272
+ ? config.provider.reasoningEffort
273
+ : m.reasoning);
272
274
  modelPicker = { models, cursor, reasoning };
273
275
  update();
274
276
  return new Promise((resolve) => { modelPickerResolve = resolve; });
@@ -293,16 +295,8 @@ export async function startInkTui(config, spawner) {
293
295
  const model = modelPicker.models[modelPicker.cursor];
294
296
  if (model.reasoningRange.length === 0)
295
297
  return;
296
- const current = modelPicker.reasoning[modelPicker.cursor];
297
- const index = current ? REASONING_LEVELS.indexOf(current) : -1;
298
- const rangeIndices = model.reasoningRange.map((level) => REASONING_LEVELS.indexOf(level));
299
- const candidate = delta > 0
300
- ? rangeIndices.find((ri) => ri > index)
301
- : [...rangeIndices].reverse().find((ri) => ri < index);
302
- if (candidate === undefined)
303
- return;
304
298
  const reasoning = [...modelPicker.reasoning];
305
- reasoning[modelPicker.cursor] = REASONING_LEVELS[candidate];
299
+ reasoning[modelPicker.cursor] = moveReasoning(model.reasoningRange, reasoning[modelPicker.cursor], delta);
306
300
  modelPicker = { ...modelPicker, reasoning };
307
301
  update();
308
302
  }
@@ -310,7 +304,7 @@ export async function startInkTui(config, spawner) {
310
304
  if (!modelPicker)
311
305
  return;
312
306
  const model = modelPicker.models[modelPicker.cursor];
313
- const result = { model: model.id, reasoning: modelPicker.reasoning[modelPicker.cursor] };
307
+ const result = { provider: model.provider, model: model.id, reasoning: modelPicker.reasoning[modelPicker.cursor] };
314
308
  closeModelPicker(result);
315
309
  }
316
310
  function openToolDetail() {
@@ -401,6 +395,7 @@ export async function startInkTui(config, spawner) {
401
395
  const { resolveProvider } = await import("../providers/resolve.js");
402
396
  const newProvider = resolveProvider(result.provider ?? config.provider.name, result.model || undefined, undefined, result.reasoning ?? undefined);
403
397
  config.provider = newProvider;
398
+ saveModelSelection({ provider: newProvider.name, model: newProvider.model, reasoning: newProvider.reasoningEffort }, process.cwd());
404
399
  config.costTracker?.reprice(newProvider.model ?? newProvider.name, newProvider.name, newProvider.baseUrl);
405
400
  const { buildSystemPrompt } = await import("../system-prompt.js");
406
401
  config.systemPrompt = config.rebuildSystemPrompt
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phren/agent",
3
- "version": "0.3.31",
3
+ "version": "0.3.33",
4
4
  "description": "phren's coding agent: starts every session knowing your project's memory, tasks and decisions",
5
5
  "type": "module",
6
6
  "bin": {
@@ -15,7 +15,7 @@
15
15
  ],
16
16
  "dependencies": {
17
17
  "@modelcontextprotocol/sdk": "^1.32.0",
18
- "@phren/cli": "0.3.31",
18
+ "@phren/cli": "0.3.33",
19
19
  "ajv": "^8.20.0",
20
20
  "ink": "^8.0.0",
21
21
  "react": "^19.3.0"