10-settings.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * Settings Configuration
  3. *
  4. * Override settings using SettingsManager.
  5. */
  6. import { createAgentSession, SessionManager, SettingsManager } from "@earendil-works/pi-coding-agent";
  7. const cwd = process.cwd();
  8. // Load current settings (merged global + project)
  9. const settingsManagerFromDisk = SettingsManager.create(cwd);
  10. console.log("Current settings:", JSON.stringify(settingsManagerFromDisk.getGlobalSettings(), null, 2));
  11. // Override specific settings
  12. const settingsManager = SettingsManager.create(cwd);
  13. settingsManager.applyOverrides({
  14. compaction: { enabled: false },
  15. retry: { enabled: true, maxRetries: 5, baseDelayMs: 1000 },
  16. });
  17. const { session: customSettingsSession } = await createAgentSession({
  18. settingsManager,
  19. sessionManager: SessionManager.inMemory(),
  20. });
  21. console.log("Session created with custom settings");
  22. customSettingsSession.dispose();
  23. // Setters update memory immediately and queue persistence writes.
  24. // Call flush() when you need a durability boundary.
  25. settingsManager.setDefaultThinkingLevel("low");
  26. await settingsManager.flush();
  27. // Surface settings I/O errors at the app layer.
  28. const settingsErrors = settingsManager.drainErrors();
  29. if (settingsErrors.length > 0) {
  30. for (const { scope, error } of settingsErrors) {
  31. console.warn(`Warning (${scope} settings): ${error.message}`);
  32. }
  33. }
  34. // For testing without file I/O:
  35. const inMemorySettings = SettingsManager.inMemory({
  36. compaction: { enabled: false },
  37. retry: { enabled: false },
  38. });
  39. const { session: testSession } = await createAgentSession({
  40. settingsManager: inMemorySettings,
  41. sessionManager: SessionManager.inMemory(),
  42. });
  43. console.log("Test session created with in-memory settings");
  44. testSession.dispose();