mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 20:03:05 +00:00
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:
parent
05e1f31feb
commit
62c64a286b
8 changed files with 162 additions and 71 deletions
|
|
@ -1,33 +1,38 @@
|
|||
/**
|
||||
* Settings Configuration
|
||||
*
|
||||
* Override settings from agentDir/settings.json.
|
||||
* Override settings using SettingsManager.
|
||||
*/
|
||||
|
||||
import { createAgentSession, loadSettings, SessionManager } from "../../src/index.js";
|
||||
import { createAgentSession, loadSettings, SessionManager, SettingsManager } from "../../src/index.js";
|
||||
|
||||
// Load current settings
|
||||
// Load current settings (merged global + project)
|
||||
const settings = loadSettings();
|
||||
console.log("Current settings:", JSON.stringify(settings, null, 2));
|
||||
|
||||
// Override specific settings
|
||||
const settingsManager = SettingsManager.create();
|
||||
settingsManager.applyOverrides({
|
||||
compaction: { enabled: false },
|
||||
retry: { enabled: true, maxRetries: 5, baseDelayMs: 1000 },
|
||||
});
|
||||
|
||||
const { session } = await createAgentSession({
|
||||
settings: {
|
||||
// Disable auto-compaction
|
||||
compaction: { enabled: false },
|
||||
|
||||
// Custom retry behavior
|
||||
retry: {
|
||||
enabled: true,
|
||||
maxRetries: 5,
|
||||
baseDelayMs: 1000,
|
||||
},
|
||||
|
||||
// Terminal options
|
||||
terminal: { showImages: true },
|
||||
hideThinkingBlock: true,
|
||||
},
|
||||
settingsManager,
|
||||
sessionManager: SessionManager.inMemory(),
|
||||
});
|
||||
|
||||
console.log("Session created with custom settings");
|
||||
|
||||
// For testing without file I/O:
|
||||
const inMemorySettings = SettingsManager.inMemory({
|
||||
compaction: { enabled: false },
|
||||
retry: { enabled: false },
|
||||
});
|
||||
|
||||
const { session: testSession } = await createAgentSession({
|
||||
settingsManager: inMemorySettings,
|
||||
sessionManager: SessionManager.inMemory(),
|
||||
});
|
||||
|
||||
console.log("Test session created with in-memory settings");
|
||||
|
|
|
|||
|
|
@ -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) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue