diff --git a/lib/config.js b/lib/config.js index f6b0b70..4e3ff18 100644 --- a/lib/config.js +++ b/lib/config.js @@ -6,6 +6,8 @@ /** Defaults written into cordis.patch.yml; also the fallback for missing keys. */ export const DEFAULT_SETTINGS = { enabled: true, + activityEnabled: true, + memoryEnabled: true, baseUrl: 'https://your-memory-host/api/longmemory', clientId: 'dsh-desktop', requestTimeoutMs: 5000, @@ -85,6 +87,10 @@ export function settingsFromConfig(raw) { const result = {}; if (typeof source.enabled === 'boolean') result.enabled = source.enabled; + if (typeof source.activityEnabled === 'boolean') + result.activityEnabled = source.activityEnabled; + if (typeof source.memoryEnabled === 'boolean') + result.memoryEnabled = source.memoryEnabled; const baseUrl = normalizeBaseUrl(source.baseUrl); if (baseUrl !== undefined) result.baseUrl = baseUrl; diff --git a/lib/index.js b/lib/index.js index 619974d..45cea8b 100644 --- a/lib/index.js +++ b/lib/index.js @@ -53,7 +53,7 @@ export function apply(ctx, config) { }); const reporter = new Reporter({ client, - settings: () => ({ enabled: settings().enabled, clientId: settings().clientId }), + settings: () => ({ enabled: settings().activityEnabled, clientId: settings().clientId }), activityToken: () => store.activityToken(), summary: () => ({ enabled: settings().summaryEnabled, maxChars: settings().summaryMaxChars }), summaryToken: () => store.summaryToken(), @@ -120,8 +120,8 @@ export function apply(ctx, config) { const clients = new ClientRegistry(); // Announce at most once per activation so a missing token is obvious in logs. const effective = settings(); - if (!effective.enabled) { - logger.info('disabled by settings'); + if (!effective.activityEnabled) { + logger.info('turn reporting disabled by settings'); } else if (store.activityToken() === '') { logger.warn(`reporting enabled but no activity token; configure one at ${store.path} or open /dsh-brain`); @@ -151,7 +151,7 @@ export function apply(ctx, config) { remote: () => memoryRemoteFactory.current(), client: () => client, memoryToken: () => store.memoryToken(), - settings: () => ({ enabled: settings().enabled, defaultK: settings().defaultK }), + settings: () => ({ enabled: settings().memoryEnabled, defaultK: settings().defaultK }), }; for (const tool of [...createMemoryTools(toolDeps), ...createSkillTools(toolDeps)]) { toolsCtx.effect(() => tools.register(tool), `dsh-brain: tool ${tool.name}`); @@ -170,7 +170,7 @@ export function apply(ctx, config) { } ctx.effect(() => { const timer = setInterval(() => { - if (store.activityToken() !== '' && settings().enabled) { + if (store.activityToken() !== '' && settings().activityEnabled) { void reporter.flush().catch((error) => { logger.warn(`retry flush failed: ${error instanceof Error ? error.message : String(error)}`); }); diff --git a/lib/store.js b/lib/store.js index 45d50a6..0160bf8 100644 --- a/lib/store.js +++ b/lib/store.js @@ -84,6 +84,10 @@ function parseState(raw) { const state = { version: 1 }; if (typeof source.enabled === 'boolean') state.enabled = source.enabled; + if (typeof source.activityEnabled === 'boolean') + state.activityEnabled = source.activityEnabled; + if (typeof source.memoryEnabled === 'boolean') + state.memoryEnabled = source.memoryEnabled; const baseUrl = normalizeBaseUrl(source.baseUrl); if (baseUrl !== undefined) state.baseUrl = baseUrl; @@ -127,11 +131,15 @@ export class SettingsStore { state; file; configDefaults; + /** Config-level explicit values for the split gates (absent = inherit `enabled`). */ + configExplicit; constructor(rawConfig, file = settingsPath()) { this.file = file; if (file === settingsPath()) migrateLegacyFile(file, legacySettingsPath()); - this.configDefaults = { ...DEFAULT_SETTINGS, ...settingsFromConfig(rawConfig) }; + const fromConfig = settingsFromConfig(rawConfig); + this.configDefaults = { ...DEFAULT_SETTINGS, ...fromConfig }; + this.configExplicit = { activityEnabled: fromConfig.activityEnabled, memoryEnabled: fromConfig.memoryEnabled }; this.state = this.read(); } /** Absolute sidecar path (exposed for the status card). */ @@ -164,6 +172,10 @@ export class SettingsStore { const resolved = { ...this.configDefaults }; if (this.state.enabled !== undefined) resolved.enabled = this.state.enabled; + if (this.state.activityEnabled !== undefined) + resolved.activityEnabled = this.state.activityEnabled; + if (this.state.memoryEnabled !== undefined) + resolved.memoryEnabled = this.state.memoryEnabled; if (this.state.baseUrl !== undefined) resolved.baseUrl = this.state.baseUrl; if (this.state.clientId !== undefined) @@ -176,6 +188,14 @@ export class SettingsStore { resolved.summaryEnabled = this.state.summaryEnabled; if (this.state.summaryMaxChars !== undefined) resolved.summaryMaxChars = this.state.summaryMaxChars; + // The split gates inherit `enabled` unless the config or the sidecar set + // them explicitly, so an old configuration keeps its exact behaviour. + if (this.state.activityEnabled === undefined && this.configExplicit.activityEnabled === undefined) { + resolved.activityEnabled = resolved.enabled; + } + if (this.state.memoryEnabled === undefined && this.configExplicit.memoryEnabled === undefined) { + resolved.memoryEnabled = resolved.enabled; + } return resolved; } /** The activity:write bearer token (sidecar first, env fallback). */ @@ -223,6 +243,16 @@ export class SettingsStore { return { ok: false, error: 'enabled must be a boolean' }; next.enabled = patch.enabled; } + if (patch.activityEnabled !== undefined) { + if (typeof patch.activityEnabled !== 'boolean') + return { ok: false, error: 'activityEnabled must be a boolean' }; + next.activityEnabled = patch.activityEnabled; + } + if (patch.memoryEnabled !== undefined) { + if (typeof patch.memoryEnabled !== 'boolean') + return { ok: false, error: 'memoryEnabled must be a boolean' }; + next.memoryEnabled = patch.memoryEnabled; + } if (patch.baseUrl !== undefined) { const baseUrl = normalizeBaseUrl(patch.baseUrl); if (baseUrl === undefined) diff --git a/src/config.ts b/src/config.ts index c34d0af..1316b5d 100644 --- a/src/config.ts +++ b/src/config.ts @@ -7,6 +7,8 @@ /** Defaults written into cordis.patch.yml; also the fallback for missing keys. */ export const DEFAULT_SETTINGS: Settings = { enabled: true, + activityEnabled: true, + memoryEnabled: true, baseUrl: 'https://your-memory-host/api/longmemory', clientId: 'dsh-desktop', requestTimeoutMs: 5000, @@ -19,8 +21,12 @@ export const DEFAULT_SETTINGS: Settings = { /** Effective, fully-resolved settings. */ export interface Settings { - /** Master switch for turn reporting AND memory tools. */ + /** Master switch: the base gate every split switch inherits when absent. */ enabled: boolean + /** Turn reporting gate; inherits `enabled` when the config omits it. */ + activityEnabled: boolean + /** Memory tool gate; inherits `enabled` when the config omits it. */ + memoryEnabled: boolean /** Base URL of the cloud memory service, without a trailing slash. */ baseUrl: string /** Stable client identifier sent with every activity turn. */ @@ -107,6 +113,8 @@ export function settingsFromConfig(raw: unknown): Partial { const source = raw as RawConfig const result: Partial = {} if (typeof source.enabled === 'boolean') result.enabled = source.enabled + if (typeof source.activityEnabled === 'boolean') result.activityEnabled = source.activityEnabled + if (typeof source.memoryEnabled === 'boolean') result.memoryEnabled = source.memoryEnabled const baseUrl = normalizeBaseUrl(source.baseUrl) if (baseUrl !== undefined) result.baseUrl = baseUrl const clientId = shortString(source.clientId) diff --git a/src/index.ts b/src/index.ts index 76efbca..22f367f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -63,7 +63,7 @@ export function apply(ctx: CloudMemoryContext, config: unknown): void { const reporter = new Reporter({ client, - settings: () => ({ enabled: settings().enabled, clientId: settings().clientId }), + settings: () => ({ enabled: settings().activityEnabled, clientId: settings().clientId }), activityToken: () => store.activityToken(), summary: () => ({ enabled: settings().summaryEnabled, maxChars: settings().summaryMaxChars }), summaryToken: () => store.summaryToken(), @@ -138,8 +138,8 @@ export function apply(ctx: CloudMemoryContext, config: unknown): void { const clients = new ClientRegistry() // Announce at most once per activation so a missing token is obvious in logs. const effective = settings() - if (!effective.enabled) { - logger.info('disabled by settings') + if (!effective.activityEnabled) { + logger.info('turn reporting disabled by settings') } else if (store.activityToken() === '') { logger.warn(`reporting enabled but no activity token; configure one at ${store.path} or open /dsh-brain`) } else { @@ -174,7 +174,7 @@ export function apply(ctx: CloudMemoryContext, config: unknown): void { remote: () => memoryRemoteFactory.current(), client: () => client, memoryToken: () => store.memoryToken(), - settings: () => ({ enabled: settings().enabled, defaultK: settings().defaultK }), + settings: () => ({ enabled: settings().memoryEnabled, defaultK: settings().defaultK }), } for (const tool of [...createMemoryTools(toolDeps), ...createSkillTools(toolDeps)]) { toolsCtx.effect(() => tools.register(tool), `dsh-brain: tool ${tool.name}`) @@ -194,7 +194,7 @@ export function apply(ctx: CloudMemoryContext, config: unknown): void { ctx.effect(() => { const timer = setInterval(() => { - if (store.activityToken() !== '' && settings().enabled) { + if (store.activityToken() !== '' && settings().activityEnabled) { void reporter.flush().catch((error: unknown) => { logger.warn(`retry flush failed: ${error instanceof Error ? error.message : String(error)}`) }) diff --git a/src/store.ts b/src/store.ts index 71394b2..fd7b28e 100644 --- a/src/store.ts +++ b/src/store.ts @@ -20,6 +20,8 @@ import { DEFAULT_SETTINGS, isPlaceholderBaseUrl, normalizeBaseUrl, originOf, set export interface PersistedState { version: 1 enabled?: boolean + activityEnabled?: boolean + memoryEnabled?: boolean baseUrl?: string clientId?: string requestTimeoutMs?: number @@ -117,6 +119,8 @@ function parseState(raw: string): PersistedState { const source = value as Record const state: PersistedState = { version: 1 } if (typeof source.enabled === 'boolean') state.enabled = source.enabled + if (typeof source.activityEnabled === 'boolean') state.activityEnabled = source.activityEnabled + if (typeof source.memoryEnabled === 'boolean') state.memoryEnabled = source.memoryEnabled const baseUrl = normalizeBaseUrl(source.baseUrl) if (baseUrl !== undefined) state.baseUrl = baseUrl const clientId = cleanString(source.clientId) @@ -151,11 +155,15 @@ export class SettingsStore { private state: PersistedState private readonly file: string private readonly configDefaults: Settings + /** Config-level explicit values for the split gates (absent = inherit `enabled`). */ + private readonly configExplicit: { activityEnabled?: boolean; memoryEnabled?: boolean } constructor(rawConfig: unknown, file: string = settingsPath()) { this.file = file if (file === settingsPath()) migrateLegacyFile(file, legacySettingsPath()) - this.configDefaults = { ...DEFAULT_SETTINGS, ...settingsFromConfig(rawConfig) } + const fromConfig = settingsFromConfig(rawConfig) + this.configDefaults = { ...DEFAULT_SETTINGS, ...fromConfig } + this.configExplicit = { activityEnabled: fromConfig.activityEnabled, memoryEnabled: fromConfig.memoryEnabled } this.state = this.read() } @@ -189,12 +197,22 @@ export class SettingsStore { settings(): Settings { const resolved: Settings = { ...this.configDefaults } if (this.state.enabled !== undefined) resolved.enabled = this.state.enabled + if (this.state.activityEnabled !== undefined) resolved.activityEnabled = this.state.activityEnabled + if (this.state.memoryEnabled !== undefined) resolved.memoryEnabled = this.state.memoryEnabled if (this.state.baseUrl !== undefined) resolved.baseUrl = this.state.baseUrl if (this.state.clientId !== undefined) resolved.clientId = this.state.clientId if (this.state.requestTimeoutMs !== undefined) resolved.requestTimeoutMs = this.state.requestTimeoutMs if (this.state.defaultK !== undefined) resolved.defaultK = this.state.defaultK if (this.state.summaryEnabled !== undefined) resolved.summaryEnabled = this.state.summaryEnabled if (this.state.summaryMaxChars !== undefined) resolved.summaryMaxChars = this.state.summaryMaxChars + // The split gates inherit `enabled` unless the config or the sidecar set + // them explicitly, so an old configuration keeps its exact behaviour. + if (this.state.activityEnabled === undefined && this.configExplicit.activityEnabled === undefined) { + resolved.activityEnabled = resolved.enabled + } + if (this.state.memoryEnabled === undefined && this.configExplicit.memoryEnabled === undefined) { + resolved.memoryEnabled = resolved.enabled + } return resolved } @@ -246,6 +264,14 @@ export class SettingsStore { if (typeof patch.enabled !== 'boolean') return { ok: false, error: 'enabled must be a boolean' } next.enabled = patch.enabled } + if (patch.activityEnabled !== undefined) { + if (typeof patch.activityEnabled !== 'boolean') return { ok: false, error: 'activityEnabled must be a boolean' } + next.activityEnabled = patch.activityEnabled + } + if (patch.memoryEnabled !== undefined) { + if (typeof patch.memoryEnabled !== 'boolean') return { ok: false, error: 'memoryEnabled must be a boolean' } + next.memoryEnabled = patch.memoryEnabled + } if (patch.baseUrl !== undefined) { const baseUrl = normalizeBaseUrl(patch.baseUrl) if (baseUrl === undefined) return { ok: false, error: 'baseUrl must be an http(s) URL' }