@phren/agent 0.3.31 → 0.3.32
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/dist/agent-loop/index.js +3 -0
- package/dist/bin.js +1 -1
- package/dist/commands/model.js +4 -5
- package/dist/config.js +21 -4
- package/dist/herdr-hooks.js +89 -9
- package/dist/index.js +52 -17
- package/dist/mcp-client.js +5 -1
- package/dist/model-discovery.js +467 -0
- package/dist/models-list.js +20 -25
- package/dist/models.js +32 -9
- package/dist/multi/model-picker.js +87 -46
- package/dist/multi/picker-navigation.js +28 -0
- package/dist/multi/provider-manager.js +27 -57
- package/dist/provider-connectors.js +89 -0
- package/dist/providers/anthropic.js +20 -9
- package/dist/providers/codex.js +7 -7
- package/dist/providers/openai-compat.js +26 -1
- package/dist/providers/openai-responses.js +270 -0
- package/dist/providers/openrouter.js +14 -6
- package/dist/providers/resolve.js +67 -30
- package/dist/repl.js +2 -1
- package/dist/settings.js +72 -3
- package/dist/tools/registry.js +6 -1
- package/dist/tui/components/ModelPicker.js +24 -5
- package/dist/tui/ink-entry.js +12 -17
- package/package.json +2 -2
package/dist/agent-loop/index.js
CHANGED
|
@@ -54,7 +54,10 @@ export function closeDanglingToolUses(session, reason = "Cancelled by user.") {
|
|
|
54
54
|
}
|
|
55
55
|
export async function runTurn(userInput, session, config, hooks) {
|
|
56
56
|
const { provider, registry, maxTurns, verbose, costTracker } = config;
|
|
57
|
+
const turnContext = await config.turnContext?.(session.log.header.sessionId);
|
|
57
58
|
let systemPrompt = config.systemPrompt;
|
|
59
|
+
if (turnContext)
|
|
60
|
+
systemPrompt += `\n\n${turnContext}`;
|
|
58
61
|
const toolDefs = registry.getDefinitions();
|
|
59
62
|
// While a plan is pending the model may look but not touch.
|
|
60
63
|
const planToolDefs = toolDefs.filter((d) => READ_ONLY_TOOLS.has(d.name));
|
package/dist/bin.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
const argv = process.argv.slice(2);
|
|
3
3
|
// `phren-agent models [--json]` lists the model catalog without loading the agent.
|
|
4
4
|
if (argv[0] === "models")
|
|
5
|
-
(await import("./models-list.js")).
|
|
5
|
+
(await import("./models-list.js")).refreshModelsCommand(argv.slice(1));
|
|
6
6
|
else
|
|
7
7
|
(await import("./index.js")).runAgentCli(argv);
|
|
8
8
|
export {};
|
package/dist/commands/model.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { listPresets, loadPreset, savePreset, deletePreset, formatPreset } from "../multi/presets.js";
|
|
2
2
|
import { showModelPicker } from "../multi/model-picker.js";
|
|
3
3
|
import { formatProviderList, formatModelAddHelp, addCustomModel, removeCustomModel } from "../multi/provider-manager.js";
|
|
4
|
-
import { normalizeReasoningEffort } from "../models.js";
|
|
4
|
+
import { getReasoningRange, normalizeReasoningEffort } from "../models.js";
|
|
5
5
|
const DIM = "\x1b[2m";
|
|
6
6
|
const GREEN = "\x1b[32m";
|
|
7
7
|
const RED = "\x1b[31m";
|
|
@@ -60,8 +60,7 @@ export function modelCommand(parts, ctx) {
|
|
|
60
60
|
if (ctx.pickModel) {
|
|
61
61
|
return ctx.pickModel().then(applyResult);
|
|
62
62
|
}
|
|
63
|
-
showModelPicker(ctx.providerName, ctx.currentModel, ctx.currentReasoning, process.stdout).then(applyResult);
|
|
64
|
-
return true;
|
|
63
|
+
return showModelPicker(ctx.providerName, ctx.currentModel, ctx.currentReasoning, process.stdout).then(applyResult);
|
|
65
64
|
}
|
|
66
65
|
/**
|
|
67
66
|
* Apply a model, provider or effort change through the host and keep the
|
|
@@ -94,12 +93,12 @@ export async function switchModel(ctx, result) {
|
|
|
94
93
|
export function reasoningCommand(parts, ctx) {
|
|
95
94
|
const arg = parts[1];
|
|
96
95
|
if (!arg) {
|
|
97
|
-
process.stderr.write(`${DIM}Reasoning: ${ctx.currentReasoning ?? "model default"}.
|
|
96
|
+
process.stderr.write(`${DIM}Reasoning: ${ctx.currentReasoning ?? "model default"}. Supported: ${getReasoningRange(ctx.providerName, ctx.currentModel ?? "").join(", ") || "model default"}.${RESET}\n`);
|
|
98
97
|
return true;
|
|
99
98
|
}
|
|
100
99
|
const level = normalizeReasoningEffort(arg);
|
|
101
100
|
if (!level) {
|
|
102
|
-
process.stderr.write(`${RED}Unknown reasoning level "${arg}". Use
|
|
101
|
+
process.stderr.write(`${RED}Unknown reasoning level "${arg}". Use low, medium, high or a supported extra: none, minimal, xhigh, max.${RESET}\n`);
|
|
103
102
|
return true;
|
|
104
103
|
}
|
|
105
104
|
return switchModel(ctx, { model: ctx.currentModel ?? "", reasoning: level });
|
package/dist/config.js
CHANGED
|
@@ -20,7 +20,7 @@ Options:
|
|
|
20
20
|
openai-compat, ollama
|
|
21
21
|
--base-url <url> Endpoint for openai-compat (or to override deepseek's)
|
|
22
22
|
--model <model> Override LLM model
|
|
23
|
-
--reasoning <level> Reasoning effort:
|
|
23
|
+
--reasoning <level> Reasoning effort: low, medium, high (model extras: none, minimal, xhigh, max)
|
|
24
24
|
--project <name> Force phren project context
|
|
25
25
|
--max-turns <n> Max tool-use turns (default: 50)
|
|
26
26
|
--max-output <n> Max output tokens per response (default: auto per model)
|
|
@@ -61,8 +61,10 @@ Options:
|
|
|
61
61
|
--strict-mcp-config Use only --mcp-config and --mcp servers, no default config files
|
|
62
62
|
--team <name> Start in team mode with named team coordination
|
|
63
63
|
--multi Start in multi-agent TUI mode
|
|
64
|
+
--append-system-prompt-file <path> Append a UTF-8 system brief
|
|
64
65
|
--dry-run Show system prompt and exit
|
|
65
66
|
--verbose Show tool calls as they execute
|
|
67
|
+
--refresh-models Refresh cached provider model catalogues and exit
|
|
66
68
|
--version Show version
|
|
67
69
|
--help Show this help
|
|
68
70
|
|
|
@@ -71,7 +73,7 @@ Providers (auto-detected from env, or use --provider):
|
|
|
71
73
|
(no API key needed, flat rate via your subscription)
|
|
72
74
|
Setup: phren-agent auth login
|
|
73
75
|
Legacy alias: codex
|
|
74
|
-
openai OPENAI_API_KEY — OpenAI direct (
|
|
76
|
+
openai OPENAI_API_KEY — OpenAI direct (discovered model catalog)
|
|
75
77
|
openrouter OPENROUTER_API_KEY — routes to any model
|
|
76
78
|
anthropic ANTHROPIC_API_KEY — Claude direct
|
|
77
79
|
deepseek DEEPSEEK_API_KEY — DeepSeek's own API (api.deepseek.com)
|
|
@@ -87,6 +89,7 @@ Environment:
|
|
|
87
89
|
PHREN_AGENT_BASE_URL Endpoint for openai-compat (and for deepseek with
|
|
88
90
|
PHREN_AGENT_PROVIDER=deepseek)
|
|
89
91
|
PHREN_AGENT_API_KEY Key for openai-compat
|
|
92
|
+
OPENCODE_BASE_URL, OPENCODE_API_KEY Reuse an OpenCode-compatible connector
|
|
90
93
|
PHREN_AGENT_CONTEXT_WINDOW, PHREN_AGENT_PRICE_IN, PHREN_AGENT_PRICE_OUT,
|
|
91
94
|
PHREN_AGENT_PRICE_CACHE Same as the flags, for every model (the flags apply
|
|
92
95
|
only to the model they were given with, and win)
|
|
@@ -96,7 +99,7 @@ Environment:
|
|
|
96
99
|
Examples:
|
|
97
100
|
phren-agent "fix the login bug"
|
|
98
101
|
phren-agent --provider openai-codex "add input validation"
|
|
99
|
-
phren-agent --model openai-codex/gpt-
|
|
102
|
+
phren-agent --model openai-codex/gpt-6.1-sol --reasoning high "add input validation"
|
|
100
103
|
phren-agent --provider anthropic --verbose "refactor the database layer"
|
|
101
104
|
`.trim();
|
|
102
105
|
export function parseArgs(argv) {
|
|
@@ -125,6 +128,7 @@ export function parseArgs(argv) {
|
|
|
125
128
|
mode: "agent",
|
|
126
129
|
help: false,
|
|
127
130
|
version: false,
|
|
131
|
+
refreshModels: false,
|
|
128
132
|
};
|
|
129
133
|
const positional = [];
|
|
130
134
|
let i = 0;
|
|
@@ -142,6 +146,9 @@ export function parseArgs(argv) {
|
|
|
142
146
|
else if (arg === "--verbose") {
|
|
143
147
|
args.verbose = true;
|
|
144
148
|
}
|
|
149
|
+
else if (arg === "--refresh-models") {
|
|
150
|
+
args.refreshModels = true;
|
|
151
|
+
}
|
|
145
152
|
else if (arg === "--interactive" || arg === "-i") {
|
|
146
153
|
args.interactive = true;
|
|
147
154
|
}
|
|
@@ -216,6 +223,11 @@ export function parseArgs(argv) {
|
|
|
216
223
|
else if (arg === "--typecheck-cmd" && argv[i + 1]) {
|
|
217
224
|
args.typecheckCmd = argv[++i];
|
|
218
225
|
}
|
|
226
|
+
else if (arg === "--append-system-prompt-file") {
|
|
227
|
+
if (!argv[i + 1] || argv[i + 1].startsWith("--"))
|
|
228
|
+
throw new Error("--append-system-prompt-file needs a path.");
|
|
229
|
+
args.appendSystemPromptFile = argv[++i];
|
|
230
|
+
}
|
|
219
231
|
else if (arg === "--mcp" && argv[i + 1]) {
|
|
220
232
|
args.mcp.push(argv[++i]);
|
|
221
233
|
}
|
|
@@ -241,7 +253,10 @@ export function parseArgs(argv) {
|
|
|
241
253
|
args.model = argv[++i];
|
|
242
254
|
}
|
|
243
255
|
else if (arg === "--reasoning" && argv[i + 1]) {
|
|
244
|
-
|
|
256
|
+
const value = argv[++i];
|
|
257
|
+
args.reasoning = normalizeReasoningEffort(value);
|
|
258
|
+
if (!args.reasoning)
|
|
259
|
+
throw new Error(`Unknown reasoning effort "${value}". Use low, medium, high, or a model-supported extra: none, minimal, xhigh, max.`);
|
|
245
260
|
}
|
|
246
261
|
else if (arg === "--project" && argv[i + 1]) {
|
|
247
262
|
args.project = argv[++i];
|
|
@@ -296,6 +311,8 @@ export function parseArgs(argv) {
|
|
|
296
311
|
}
|
|
297
312
|
if (!args.reasoning && process.env.PHREN_AGENT_REASONING) {
|
|
298
313
|
args.reasoning = normalizeReasoningEffort(process.env.PHREN_AGENT_REASONING);
|
|
314
|
+
if (!args.reasoning)
|
|
315
|
+
throw new Error("Invalid PHREN_AGENT_REASONING; use low, medium, high or a supported model extra.");
|
|
299
316
|
}
|
|
300
317
|
return args;
|
|
301
318
|
}
|
package/dist/herdr-hooks.js
CHANGED
|
@@ -7,9 +7,10 @@
|
|
|
7
7
|
* file, so it calls the installed hook bundle itself with the same JSON on
|
|
8
8
|
* stdin. That is what binds this session's event log to the pane the iPhone
|
|
9
9
|
* is looking at. Strictly best effort: no Herdr, no bundle, or a slow bundle
|
|
10
|
-
*
|
|
10
|
+
* is bounded and must never fail a turn.
|
|
11
11
|
*/
|
|
12
12
|
import { spawn } from "node:child_process";
|
|
13
|
+
import { request } from "node:http";
|
|
13
14
|
import * as fs from "node:fs";
|
|
14
15
|
import * as os from "node:os";
|
|
15
16
|
import * as path from "node:path";
|
|
@@ -31,15 +32,57 @@ export function herdrHookBundle(env = process.env) {
|
|
|
31
32
|
return null;
|
|
32
33
|
}
|
|
33
34
|
}
|
|
35
|
+
// Serialize lifecycle callbacks: a prompt must not overtake SessionStart,
|
|
36
|
+
// and a context read must wait until the Hook has bound the current log.
|
|
37
|
+
let pendingLifecycle = Promise.resolve();
|
|
34
38
|
function defaultRunner(command, args, stdin) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
pendingLifecycle = pendingLifecycle.then(() => new Promise((resolve) => {
|
|
40
|
+
const child = spawn(command, args, { stdio: ["pipe", "ignore", "ignore"], env: process.env });
|
|
41
|
+
const timer = setTimeout(() => { child.kill(); resolve(); }, HOOK_TIMEOUT_MS);
|
|
42
|
+
timer.unref();
|
|
43
|
+
const done = () => { clearTimeout(timer); resolve(); };
|
|
44
|
+
child.on("error", done);
|
|
45
|
+
child.on("exit", done);
|
|
46
|
+
child.unref();
|
|
47
|
+
child.stdin.on("error", () => { });
|
|
48
|
+
child.stdin.end(stdin);
|
|
49
|
+
})).catch(() => { });
|
|
50
|
+
}
|
|
51
|
+
/** Only the root session asks; the Hook independently proves PID, terminal
|
|
52
|
+
* and session identity. No inherited environment variable confers a role. */
|
|
53
|
+
export async function readConductorContext(sessionId) {
|
|
54
|
+
if (sessionId !== currentSession || !herdrHookBundle())
|
|
55
|
+
return undefined;
|
|
56
|
+
await pendingLifecycle;
|
|
57
|
+
const root = process.env.PHREN_BRIDGE_HOME || path.join(os.homedir(), ".local/share/phren/bridge");
|
|
58
|
+
return new Promise(resolve => {
|
|
59
|
+
const req = request({ socketPath: path.join(root, "agent.sock"), path: "/conductor-context", method: "POST" }, res => {
|
|
60
|
+
let text = "";
|
|
61
|
+
res.on("data", chunk => {
|
|
62
|
+
text += chunk;
|
|
63
|
+
if (text.length > 131_072)
|
|
64
|
+
req.destroy();
|
|
65
|
+
});
|
|
66
|
+
res.on("error", () => finish());
|
|
67
|
+
res.on("end", () => {
|
|
68
|
+
if (res.statusCode !== 200) {
|
|
69
|
+
finish();
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
const body = JSON.parse(text);
|
|
74
|
+
finish(typeof body.context === "string" ? body.context : undefined);
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
finish();
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
const timer = setTimeout(() => { req.destroy(); finish(); }, HOOK_TIMEOUT_MS);
|
|
82
|
+
function finish(context) { clearTimeout(timer); resolve(context); }
|
|
83
|
+
req.on("error", () => finish());
|
|
84
|
+
req.end(JSON.stringify({ pid: process.pid, session: sessionId }));
|
|
85
|
+
});
|
|
43
86
|
}
|
|
44
87
|
let currentSession = null;
|
|
45
88
|
/** The session whose event log later reports name. Set once at startup. */
|
|
@@ -69,3 +112,40 @@ export function emitHerdrHook(event, options = {}) {
|
|
|
69
112
|
}
|
|
70
113
|
return payload;
|
|
71
114
|
}
|
|
115
|
+
/** Ask the existing Hook approval/grant path before falling back to the
|
|
116
|
+
* terminal. Only a definite allow/deny is an answer; failure is not consent. */
|
|
117
|
+
export async function askHerdrPermission(tool, input, signal) {
|
|
118
|
+
const bundle = herdrHookBundle();
|
|
119
|
+
if (!bundle || !currentSession || signal?.aborted)
|
|
120
|
+
return undefined;
|
|
121
|
+
await pendingLifecycle;
|
|
122
|
+
return new Promise(resolve => {
|
|
123
|
+
const child = spawn(process.execPath, [bundle, "hook", "phren"], { stdio: ["pipe", "pipe", "ignore"] });
|
|
124
|
+
let output = "";
|
|
125
|
+
const finish = (answer) => {
|
|
126
|
+
clearTimeout(timer);
|
|
127
|
+
signal?.removeEventListener("abort", cancel);
|
|
128
|
+
resolve(answer);
|
|
129
|
+
};
|
|
130
|
+
const cancel = () => { child.kill(); finish(); };
|
|
131
|
+
const timer = setTimeout(cancel, 60_000);
|
|
132
|
+
signal?.addEventListener("abort", cancel, { once: true });
|
|
133
|
+
child.on("error", () => finish());
|
|
134
|
+
child.stdout.on("data", chunk => { output += chunk; if (output.length > 16_384)
|
|
135
|
+
cancel(); });
|
|
136
|
+
child.on("close", () => {
|
|
137
|
+
try {
|
|
138
|
+
const decision = JSON.parse(output).hookSpecificOutput?.decision?.behavior;
|
|
139
|
+
finish(decision === "allow" ? true : decision === "deny" ? false : undefined);
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
finish();
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
child.stdin.on("error", () => { });
|
|
146
|
+
child.stdin.end(JSON.stringify({ hook_event_name: "PermissionRequest", session_id: currentSession,
|
|
147
|
+
cwd: process.cwd(), tool_name: tool, tool_input: input }));
|
|
148
|
+
if (signal?.aborted)
|
|
149
|
+
cancel();
|
|
150
|
+
});
|
|
151
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { agentUserDir, parseArgs, printHelp, resolveStartupPermissions } from "./config.js";
|
|
3
3
|
import { randomUUID } from "crypto";
|
|
4
|
+
import * as fs from "node:fs";
|
|
4
5
|
import { loadPersistentAllowlist } from "./permissions/allowlist.js";
|
|
5
6
|
import { loadPermissionRules } from "./permissions/rules.js";
|
|
6
7
|
import { keepSessionEndpoint, resolveProvider } from "./providers/resolve.js";
|
|
@@ -13,7 +14,7 @@ import { createShellTool, taskOutputTool, taskStopTool } from "./tools/shell.js"
|
|
|
13
14
|
import { globTool } from "./tools/glob.js";
|
|
14
15
|
import { grepTool } from "./tools/grep.js";
|
|
15
16
|
import { createReadImageTool } from "./tools/read-image.js";
|
|
16
|
-
import { modelSupportsVision } from "./models.js";
|
|
17
|
+
import { modelSupportsVision, normalizeProviderId } from "./models.js";
|
|
17
18
|
import { createWebFetchTool } from "./tools/web-fetch.js";
|
|
18
19
|
import { createWebSearchTool } from "./tools/web-search.js";
|
|
19
20
|
import { createPhrenAddTaskTool } from "./tools/phren-add-task.js";
|
|
@@ -28,7 +29,7 @@ import { buildPhrenContext, buildContextSnippet, buildProjectInstructions } from
|
|
|
28
29
|
import { buildChatMemory, buildChatSystemPrompt } from "./memory/chat.js";
|
|
29
30
|
import { livePreview, previewPath, removeStalePreviews } from "./session/preview.js";
|
|
30
31
|
import { startSession, endSession, getPriorSummary, saveSessionMessages, loadLastSessionSnapshot, writeSessionNote } from "./memory/session.js";
|
|
31
|
-
import { emitHerdrHook, setHerdrHookSession } from "./herdr-hooks.js";
|
|
32
|
+
import { emitHerdrHook, setHerdrHookSession, readConductorContext, askHerdrPermission } from "./herdr-hooks.js";
|
|
32
33
|
import { loadProjectContext, evolveProjectContext } from "./memory/project-context.js";
|
|
33
34
|
import { buildSystemPrompt, buildEnvironmentBlock } from "./system-prompt.js";
|
|
34
35
|
import { loadHooksConfig, runLifecycleHooks } from "./user-hooks.js";
|
|
@@ -45,11 +46,15 @@ import { codexLogin, codexLogout } from "./providers/codex-auth.js";
|
|
|
45
46
|
import { createCheckpoint } from "./checkpoint.js";
|
|
46
47
|
import { detectLintCommand, detectTypecheckCommand, detectTestCommand } from "./tools/lint-test.js";
|
|
47
48
|
import { connectMcpServers, loadDefaultMcpConfig, loadMcpConfig, parseMcpInline } from "./mcp-client.js";
|
|
48
|
-
import { isMcpProjectTrusted, trustMcpProject } from "./settings.js";
|
|
49
|
+
import { isMcpProjectTrusted, trustMcpProject, loadModelSelection, saveModelSelection } from "./settings.js";
|
|
50
|
+
import { discoverProvider, refreshModelCatalogs } from "./model-discovery.js";
|
|
51
|
+
import { printModels } from "./models-list.js";
|
|
52
|
+
import { providerAuthStatuses } from "./provider-connectors.js";
|
|
53
|
+
import { restoreModelSelection } from "./settings.js";
|
|
49
54
|
import * as os from "os";
|
|
50
55
|
import * as path from "path";
|
|
51
56
|
import { VERSION } from "./package-metadata.js";
|
|
52
|
-
import { authProfilesPath,
|
|
57
|
+
import { authProfilesPath, removeApiKeyProfile, upsertApiKeyProfile, } from "@phren/cli/auth/profiles";
|
|
53
58
|
function parseApiKeyProvider(raw) {
|
|
54
59
|
if (raw === "openai" || raw === "openrouter" || raw === "anthropic")
|
|
55
60
|
return raw;
|
|
@@ -66,15 +71,9 @@ function envVarForApiProvider(provider) {
|
|
|
66
71
|
}
|
|
67
72
|
}
|
|
68
73
|
function printAuthStatus() {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
console.log("");
|
|
73
|
-
for (const entry of entries) {
|
|
74
|
-
const status = entry.configured ? "configured" : "not configured";
|
|
75
|
-
const source = entry.source === "none" ? "" : ` via ${entry.source}`;
|
|
76
|
-
const account = entry.accountId ? ` account=${entry.accountId}` : "";
|
|
77
|
-
console.log(`- ${entry.provider}: ${status}${source}${account}`);
|
|
74
|
+
console.log(`Provider connections (${authProfilesPath()} and ~/.phren-agent/providers.json)`);
|
|
75
|
+
for (const entry of providerAuthStatuses()) {
|
|
76
|
+
console.log(`- ${entry.provider}: ${entry.configured ? "configured" : "not configured"} via ${entry.authSource}`);
|
|
78
77
|
}
|
|
79
78
|
}
|
|
80
79
|
/**
|
|
@@ -142,11 +141,21 @@ export async function runAgentCli(raw) {
|
|
|
142
141
|
console.log(`phren-agent v${VERSION}`);
|
|
143
142
|
process.exit(0);
|
|
144
143
|
}
|
|
145
|
-
//
|
|
146
|
-
//
|
|
147
|
-
|
|
148
|
-
if (args.baseUrl)
|
|
144
|
+
// Restore fields independently: changing effort keeps the saved model,
|
|
145
|
+
// while choosing another provider never imports the old provider's model.
|
|
146
|
+
Object.assign(args, restoreModelSelection(args, loadModelSelection(process.cwd()), process.env));
|
|
147
|
+
if (args.baseUrl && normalizeProviderId(args.provider) === "openai-compat") {
|
|
149
148
|
process.env.PHREN_AGENT_BASE_URL = args.baseUrl;
|
|
149
|
+
}
|
|
150
|
+
if (args.refreshModels) {
|
|
151
|
+
const selected = normalizeProviderId(args.provider);
|
|
152
|
+
if (selected)
|
|
153
|
+
await discoverProvider(selected, { force: true, baseUrl: args.baseUrl });
|
|
154
|
+
else
|
|
155
|
+
await refreshModelCatalogs(true);
|
|
156
|
+
printModels(["--json"]);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
150
159
|
if (args.listSessions) {
|
|
151
160
|
// Without a phren store, sessions live in ~/.phren-agent, listed for this directory.
|
|
152
161
|
const ctx = await buildPhrenContext(args.project);
|
|
@@ -213,6 +222,13 @@ export async function runAgentCli(raw) {
|
|
|
213
222
|
// Resolve LLM provider
|
|
214
223
|
let provider;
|
|
215
224
|
try {
|
|
225
|
+
if (!process.env.PHREN_AGENT_REPLAY) {
|
|
226
|
+
const selected = normalizeProviderId(args.provider);
|
|
227
|
+
if (selected)
|
|
228
|
+
await discoverProvider(selected, { baseUrl: args.baseUrl });
|
|
229
|
+
else
|
|
230
|
+
await refreshModelCatalogs();
|
|
231
|
+
}
|
|
216
232
|
provider = resolveProvider(args.provider, args.model, args.maxOutput, args.reasoning, { baseUrl: args.baseUrl, contextWindow: args.contextWindow });
|
|
217
233
|
}
|
|
218
234
|
catch (err) {
|
|
@@ -220,6 +236,12 @@ export async function runAgentCli(raw) {
|
|
|
220
236
|
process.exit(1);
|
|
221
237
|
}
|
|
222
238
|
keepSessionEndpoint(provider);
|
|
239
|
+
if (!process.env.PHREN_AGENT_REPLAY && !args.dryRun)
|
|
240
|
+
saveModelSelection({
|
|
241
|
+
provider: provider.name,
|
|
242
|
+
model: provider.model,
|
|
243
|
+
reasoning: provider.reasoningEffort,
|
|
244
|
+
}, process.cwd());
|
|
223
245
|
scopeModelOverrides(provider.model ?? args.model ?? provider.name, {
|
|
224
246
|
contextWindow: args.contextWindow,
|
|
225
247
|
priceIn: args.priceIn,
|
|
@@ -289,6 +311,9 @@ export async function runAgentCli(raw) {
|
|
|
289
311
|
// across rebuilds (provider prompt caching).
|
|
290
312
|
const environment = buildEnvironmentBlock(process.cwd());
|
|
291
313
|
let promptContext = contextSnippet;
|
|
314
|
+
if (args.appendSystemPromptFile) {
|
|
315
|
+
promptContext += `\n\n${fs.readFileSync(args.appendSystemPromptFile, "utf8")}`;
|
|
316
|
+
}
|
|
292
317
|
let promptSummary = priorSummary;
|
|
293
318
|
const mcpServerNames = [];
|
|
294
319
|
// Built from the tools registered right now: call again after registering more.
|
|
@@ -299,6 +324,7 @@ export async function runAgentCli(raw) {
|
|
|
299
324
|
});
|
|
300
325
|
// Register tools
|
|
301
326
|
const registry = new ToolRegistry();
|
|
327
|
+
registry.externalApproval = askHerdrPermission;
|
|
302
328
|
registry.hookConfig = loadHooksConfig(process.cwd());
|
|
303
329
|
// SessionStart hooks: what they print joins the system prompt's context.
|
|
304
330
|
if (registry.hookConfig && !args.dryRun) {
|
|
@@ -489,12 +515,21 @@ export async function runAgentCli(raw) {
|
|
|
489
515
|
return undefined;
|
|
490
516
|
};
|
|
491
517
|
const resumedLog = args.resume ? makeResumedLog() : undefined;
|
|
518
|
+
setHerdrHookSession(logSessionId);
|
|
519
|
+
if (!phrenCtx)
|
|
520
|
+
emitHerdrHook("SessionStart");
|
|
492
521
|
/** Spawner tools, once an interactive session has a spawner. */
|
|
493
522
|
let registerSpawnerTools;
|
|
494
523
|
const agentConfig = {
|
|
495
524
|
provider,
|
|
496
525
|
registry,
|
|
497
526
|
systemPrompt,
|
|
527
|
+
turnContext: async (id) => {
|
|
528
|
+
const context = await readConductorContext(id);
|
|
529
|
+
if (context && agentConfig.mode === "chat")
|
|
530
|
+
await agentConfig.promote?.();
|
|
531
|
+
return context;
|
|
532
|
+
},
|
|
498
533
|
maxTurns: args.maxTurns,
|
|
499
534
|
verbose: args.verbose,
|
|
500
535
|
phrenCtx,
|
package/dist/mcp-client.js
CHANGED
|
@@ -9,6 +9,7 @@ import { spawn } from "child_process";
|
|
|
9
9
|
import * as fs from "fs";
|
|
10
10
|
import * as path from "path";
|
|
11
11
|
import * as readline from "readline";
|
|
12
|
+
import { fileURLToPath } from "node:url";
|
|
12
13
|
import { McpOAuthProvider } from "./mcp-oauth.js";
|
|
13
14
|
import { VERSION } from "./package-metadata.js";
|
|
14
15
|
import { scrubEnv } from "./permissions/shell-safety.js";
|
|
@@ -509,7 +510,10 @@ export async function connectMcpServers(servers, verbose = false) {
|
|
|
509
510
|
* in `untrusted`.
|
|
510
511
|
*/
|
|
511
512
|
export function loadDefaultMcpConfig(cwd, opts) {
|
|
512
|
-
const servers = {
|
|
513
|
+
const servers = {
|
|
514
|
+
phren: { command: process.execPath, args: [fileURLToPath(import.meta.resolve("@phren/cli")), "mcp"], env: { PHREN_MCP_PROFILE: "core" } },
|
|
515
|
+
...loadMcpConfig(path.join(opts.home, ".phren-agent", "mcp.json")),
|
|
516
|
+
};
|
|
513
517
|
const untrusted = [];
|
|
514
518
|
for (const file of [path.join(cwd, ".mcp.json"), path.join(cwd, ".phren-agent", "mcp.json")]) {
|
|
515
519
|
const found = loadMcpConfig(file);
|