Files
sproutclaw/packages/coding-agent/examples/sdk/10-settings.ts
Mario Zechner 5a4e22ea44 fix(coding-agent): remove process-cwd tool singletons and use tool-name allowlists
- switch SDK/CLI tool selection to name-based allowlists
- apply allowlists across built-in, extension, and SDK tools
- remove ambient process.cwd defaults from core tooling and resource helpers
- update tests, examples, and TUI callers for explicit cwd plumbing
- add regression coverage for extension tool filtering

closes #3452
closes #2835
2026-04-20 22:05:28 +02:00

54 lines
1.5 KiB
TypeScript

/**
* Settings Configuration
*
* Override settings using SettingsManager.
*/
import { createAgentSession, SessionManager, SettingsManager } from "@mariozechner/pi-coding-agent";
const cwd = process.cwd();
// Load current settings (merged global + project)
const settingsManagerFromDisk = SettingsManager.create(cwd);
console.log("Current settings:", JSON.stringify(settingsManagerFromDisk.getGlobalSettings(), null, 2));
// Override specific settings
const settingsManager = SettingsManager.create(cwd);
settingsManager.applyOverrides({
compaction: { enabled: false },
retry: { enabled: true, maxRetries: 5, baseDelayMs: 1000 },
});
await createAgentSession({
settingsManager,
sessionManager: SessionManager.inMemory(),
});
console.log("Session created with custom settings");
// Setters update memory immediately and queue persistence writes.
// Call flush() when you need a durability boundary.
settingsManager.setDefaultThinkingLevel("low");
await settingsManager.flush();
// Surface settings I/O errors at the app layer.
const settingsErrors = settingsManager.drainErrors();
if (settingsErrors.length > 0) {
for (const { scope, error } of settingsErrors) {
console.warn(`Warning (${scope} settings): ${error.message}`);
}
}
// For testing without file I/O:
const inMemorySettings = SettingsManager.inMemory({
compaction: { enabled: false },
retry: { enabled: false },
});
await createAgentSession({
settingsManager: inMemorySettings,
sessionManager: SessionManager.inMemory(),
});
console.log("Test session created with in-memory settings");