Add project-specific settings and SettingsManager factories

- SettingsManager now loads .pi/settings.json from cwd (project settings)
- Project settings merge with global settings (deep merge for objects)
- Setters only modify global settings, project settings are read-only
- Add static factories: SettingsManager.create(cwd?, agentDir?), SettingsManager.inMemory(settings?)
- Add applyOverrides() for programmatic overrides
- Replace 'settings' option with 'settingsManager' in CreateAgentSessionOptions
- Update examples to use new pattern

Incorporates PR #276 approach
This commit is contained in:
Mario Zechner 2025-12-22 12:23:02 +01:00
parent 05e1f31feb
commit 62c64a286b
8 changed files with 162 additions and 71 deletions

View file

@ -12,6 +12,7 @@ import {
defaultGetApiKey,
findModel,
SessionManager,
SettingsManager,
readTool,
bashTool,
type HookFactory,
@ -53,6 +54,12 @@ const statusTool: CustomAgentTool = {
const { model } = findModel("anthropic", "claude-sonnet-4-20250514");
if (!model) throw new Error("Model not found");
// In-memory settings with overrides
const settingsManager = SettingsManager.inMemory({
compaction: { enabled: false },
retry: { enabled: true, maxRetries: 2 },
});
const { session } = await createAgentSession({
cwd: process.cwd(),
agentDir: "/tmp/my-agent",
@ -71,7 +78,7 @@ Available: read, bash, status. Be concise.`,
contextFiles: [],
slashCommands: [],
sessionManager: SessionManager.inMemory(),
settings: { compaction: { enabled: false } },
settingsManager,
});
session.subscribe((event) => {