@iworkforces/tracelattice 2.3.6 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -5
- package/dist/ServerConfig.d.ts +16 -0
- package/dist/ServerConfig.d.ts.map +1 -1
- package/dist/ServerConfig.js +11 -0
- package/dist/ServerConfig.js.map +1 -1
- package/dist/cli.js +234 -18
- package/dist/cli.js.map +1 -1
- package/dist/config/ConfigLoader.d.ts +2 -0
- package/dist/config/ConfigLoader.d.ts.map +1 -1
- package/dist/config/ConfigLoader.js +2 -0
- package/dist/config/ConfigLoader.js.map +1 -1
- package/dist/contracts/PersistenceBackend.d.ts +26 -0
- package/dist/contracts/PersistenceBackend.d.ts.map +1 -1
- package/dist/contracts/persistence-backlog.d.ts +21 -0
- package/dist/contracts/persistence-backlog.d.ts.map +1 -0
- package/dist/contracts/persistence-backlog.js +1 -0
- package/dist/core/HistoryManager.d.ts +15 -1
- package/dist/core/HistoryManager.d.ts.map +1 -1
- package/dist/core/HistoryManager.js +12 -2
- package/dist/core/HistoryManager.js.map +1 -1
- package/dist/core/IHistoryManager.d.ts +2 -0
- package/dist/core/IHistoryManager.d.ts.map +1 -1
- package/dist/core/PersistenceBuffer.d.ts +25 -0
- package/dist/core/PersistenceBuffer.d.ts.map +1 -1
- package/dist/core/PersistenceBuffer.js +27 -5
- package/dist/core/PersistenceBuffer.js.map +1 -1
- package/dist/core/PersistenceBufferErrors.d.ts +10 -0
- package/dist/core/PersistenceBufferErrors.d.ts.map +1 -1
- package/dist/core/PersistenceBufferErrors.js +13 -1
- package/dist/core/PersistenceBufferErrors.js.map +1 -1
- package/dist/core/PersistenceRestore.d.ts.map +1 -1
- package/dist/core/PersistenceRestore.js +25 -30
- package/dist/core/PersistenceRestore.js.map +1 -1
- package/dist/core/PersistenceWorkQueue.d.ts +9 -0
- package/dist/core/PersistenceWorkQueue.d.ts.map +1 -1
- package/dist/core/PersistenceWorkQueue.js +18 -0
- package/dist/core/PersistenceWorkQueue.js.map +1 -1
- package/dist/core/ThoughtEvaluator.d.ts +6 -0
- package/dist/core/ThoughtEvaluator.d.ts.map +1 -1
- package/dist/core/ThoughtEvaluator.js +15 -1
- package/dist/core/ThoughtEvaluator.js.map +1 -1
- package/dist/core/ThoughtProcessor.d.ts.map +1 -1
- package/dist/core/ThoughtProcessor.js +3 -10
- package/dist/core/ThoughtProcessor.js.map +1 -1
- package/dist/core/evaluator/VerificationLinks.d.ts +5 -0
- package/dist/core/evaluator/VerificationLinks.d.ts.map +1 -1
- package/dist/core/evaluator/VerificationLinks.js +47 -53
- package/dist/core/evaluator/VerificationLinks.js.map +1 -1
- package/dist/core/reasoning/ActiveEvidenceProjection.d.ts.map +1 -1
- package/dist/core/reasoning/ActiveEvidenceProjection.js +4 -3
- package/dist/core/reasoning/ActiveEvidenceProjection.js.map +1 -1
- package/dist/errors.d.ts +1 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +2 -1
- package/dist/errors.js.map +1 -1
- package/dist/health/HealthChecker.d.ts +42 -1
- package/dist/health/HealthChecker.d.ts.map +1 -1
- package/dist/health/HealthChecker.js +60 -8
- package/dist/health/HealthChecker.js.map +1 -1
- package/dist/lib.d.ts +2 -2
- package/dist/lib.d.ts.map +1 -1
- package/dist/lib.js +1 -0
- package/dist/lib.js.map +1 -1
- package/dist/metrics/metrics.impl.js.map +1 -1
- package/dist/persistence/FilePersistence.d.ts +2 -1
- package/dist/persistence/FilePersistence.d.ts.map +1 -1
- package/dist/persistence/FilePersistence.js +6 -1
- package/dist/persistence/FilePersistence.js.map +1 -1
- package/dist/persistence/FileSnapshotV2.d.ts +2 -0
- package/dist/persistence/FileSnapshotV2.d.ts.map +1 -1
- package/dist/persistence/FileSnapshotV2.js +39 -1
- package/dist/persistence/FileSnapshotV2.js.map +1 -1
- package/dist/persistence/MemoryPersistence.d.ts +4 -1
- package/dist/persistence/MemoryPersistence.d.ts.map +1 -1
- package/dist/persistence/MemoryPersistence.js +30 -0
- package/dist/persistence/MemoryPersistence.js.map +1 -1
- package/dist/persistence/SqlitePersistence.d.ts +6 -1
- package/dist/persistence/SqlitePersistence.d.ts.map +1 -1
- package/dist/persistence/SqlitePersistence.js +31 -4
- package/dist/persistence/SqlitePersistence.js.map +1 -1
- package/dist/transport/StreamableHttpTransport.d.ts +12 -0
- package/dist/transport/StreamableHttpTransport.d.ts.map +1 -1
- package/dist/transport/StreamableHttpTransport.js +19 -5
- package/dist/transport/StreamableHttpTransport.js.map +1 -1
- package/package.json +11 -11
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env bun\n\n// CLI entry point for tracelattice MCP server.\n// This file handles CLI argument parsing, transport selection, and signal handlers.\n// For library usage, import from './lib.js' or './index.js' instead.\n\nimport { ValibotJsonSchemaAdapter } from '@tmcp/adapter-valibot';\nimport { StdioTransport } from '@tmcp/transport-stdio';\nimport { readFileSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { McpServer } from 'tmcp';\nimport { CliLifecycle, createCliShutdownHandler } from './CliLifecycle.js';\nimport { parseCliTransportConfig } from './config/CliTransportConfig.js';\nimport type { CliHttpTransportConfig } from './config/CliTransportConfig.js';\nimport type { ToolAwareSequentialThinkingServer } from './lib.js';\nimport { initializeServer } from './lib.js';\nimport { StructuredLogger } from './logger/StructuredLogger.js';\nimport { getErrorMessage } from './errors.js';\nimport { SEQUENTIAL_THINKING_TOOL, SequentialThinkingSchema } from './schema.js';\n\n// Get version from package.json\nconst CLI_NAME = 'tracelattice' as const;\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = dirname(__filename);\nconst package_json = JSON.parse(readFileSync(join(__dirname, '../package.json'), 'utf-8'));\nconst { version } = package_json;\n// Handle CLI arguments\nconst args = process.argv.slice(2);\nconst shouldShowVersion = args.includes('--version') || args.includes('-v');\n\nif (shouldShowVersion) {\n\tconsole.log(`${CLI_NAME} v${version}`);\n\tprocess.exit(0);\n}\nasync function main() {\n\tconst adapter = new ValibotJsonSchemaAdapter();\n\tconst server = new McpServer(\n\t\t{\n\t\t\tname: CLI_NAME,\n\t\t\tversion,\n\t\t\tdescription: 'Semantic Sequential Thinking MCP Server',\n\t\t},\n\t\t{\n\t\t\tadapter,\n\t\t\tcapabilities: {\n\t\t\t\ttools: { listChanged: true },\n\t\t\t},\n\t\t}\n\t);\n\n\tconst thinkingServer = await initializeServer();\n\tconst lifecycle = new CliLifecycle(thinkingServer);\n\ttry {\n\t\tconst transportConfig = parseCliTransportConfig(process.env);\n\t\tserver.tool(\n\t\t\t{\n\t\t\t\tname: 'sequentialthinking_tools',\n\t\t\t\tdescription: SEQUENTIAL_THINKING_TOOL.description,\n\t\t\t\tschema: SequentialThinkingSchema,\n\t\t\t},\n\t\t\tasync (input) => thinkingServer.processThought(input)\n\t\t);\n\t\tif (transportConfig.kind === 'streamable-http') {\n\t\t\tawait startStreamableHttpTransport(server, thinkingServer, {\n\t\t\t\tlifecycle,\n\t\t\t\tconfig: transportConfig,\n\t\t\t});\n\t\t} else {\n\t\t\tawait startStdioTransport(server, thinkingServer, lifecycle);\n\t\t}\n\t\tregisterShutdownHandlers(lifecycle, thinkingServer, transportConfig.kind === 'stdio');\n\t} catch (error) {\n\t\tawait lifecycle.rollbackStartup(error);\n\t}\n}\n/**\n * Start Streamable HTTP transport (MCP spec recommended)\n */\nasync function startStreamableHttpTransport(\n\tserver: McpServer,\n\tthinkingServer: ToolAwareSequentialThinkingServer,\n\toptions: { readonly lifecycle: CliLifecycle; readonly config: CliHttpTransportConfig }\n): Promise<void> {\n\tconst { StreamableHttpTransport } = await import('./transport/StreamableHttpTransport.js');\n\tconst { lifecycle, config } = options;\n\tconst { port, host } = config;\n\tconst transportMetrics = thinkingServer.getContainer().resolve('Metrics');\n\tconst streamableTransport = new StreamableHttpTransport({\n\t\tport,\n\t\thost,\n\t\tcorsOrigin: config.corsOrigin,\n\t\tenableCors: config.enableCors,\n\t\tallowedHosts: config.allowedHosts,\n\t\tmetrics: transportMetrics,\n\t\tstateful: config.stateful,\n\t\t...config.retention,\n\t});\n\tlifecycle.attachTransport(streamableTransport);\n\t// Connect the Streamable HTTP transport\n\tawait streamableTransport.connect(server);\n\tthinkingServer['_logger'].info(\n\t\t`Sequential Thinking MCP Server running on Streamable HTTP transport at http://${host}:${port}`\n\t);\n}\n/**\n * Start stdio transport (default, single-user)\n */\nasync function startStdioTransport(\n\tserver: McpServer,\n\tthinkingServer: ToolAwareSequentialThinkingServer,\n\tlifecycle: CliLifecycle\n): Promise<void> {\n\tconst transport = new StdioTransport(server);\n\tconst processListeners = {\n\t\tsigint: new Set(process.listeners('SIGINT')),\n\t\tsigterm: new Set(process.listeners('SIGTERM')),\n\t\tstdinEnd: new Set(process.stdin.listeners('end')),\n\t};\n\tlifecycle.attachTransport({ stop: () => transport.close() });\n\ttransport.listen();\n\tfor (const listener of process.listeners('SIGINT')) {\n\t\tif (!processListeners.sigint.has(listener)) process.off('SIGINT', listener);\n\t}\n\tfor (const listener of process.listeners('SIGTERM')) {\n\t\tif (!processListeners.sigterm.has(listener)) process.off('SIGTERM', listener);\n\t}\n\tfor (const listener of process.stdin.listeners('end')) {\n\t\tif (!processListeners.stdinEnd.has(listener)) process.stdin.off('end', listener);\n\t}\n\tthinkingServer['_logger'].info('Sequential Thinking MCP Server running on stdio');\n}\n/**\n * Register shutdown signal handlers for a common pattern\n */\nfunction registerShutdownHandlers(\n\tlifecycle: CliLifecycle,\n\tthinkingServer: ToolAwareSequentialThinkingServer,\n\tshutdownOnStdinEnd: boolean\n): void {\n\tconst shutdown = createCliShutdownHandler(lifecycle, {\n\t\treportFailure: (error) => {\n\t\t\tthinkingServer['_logger'].error('CLI shutdown failed', failureMetadata(error));\n\t\t},\n\t\texit: (code) => process.exit(code),\n\t});\n\tconst requestShutdown = (): void => {\n\t\tvoid shutdown();\n\t};\n\tprocess.on('SIGINT', requestShutdown);\n\tprocess.on('SIGTERM', requestShutdown);\n\tif (shutdownOnStdinEnd) process.stdin.on('end', requestShutdown);\n}\n\nfunction failureMetadata(error: unknown): Record<string, unknown> {\n\tif (!(error instanceof AggregateError)) return { error: getErrorMessage(error) };\n\treturn {\n\t\terror: error.message,\n\t\tcauses: error.errors.map((cause) => getErrorMessage(cause)),\n\t};\n}\nmain().catch((error) => {\n\tconst logger = new StructuredLogger({\n\t\tlevel: 'error',\n\t\tcontext: 'SequentialThinking',\n\t\tpretty: true,\n\t});\n\tlogger.error('Fatal error running server', failureMetadata(error));\n\tprocess.exit(1);\n});\n"],"names":["CLI_NAME","__filename","fileURLToPath","__dirname","dirname","package_json","JSON","readFileSync","join","version","args","process","shouldShowVersion","console","main","adapter","ValibotJsonSchemaAdapter","server","McpServer","thinkingServer","initializeServer","lifecycle","CliLifecycle","transportConfig","parseCliTransportConfig","SEQUENTIAL_THINKING_TOOL","SequentialThinkingSchema","input","startStreamableHttpTransport","startStdioTransport","registerShutdownHandlers","error","options","StreamableHttpTransport","config","port","host","transportMetrics","streamableTransport","transport","StdioTransport","processListeners","Set","listener","shutdownOnStdinEnd","shutdown","createCliShutdownHandler","failureMetadata","code","requestShutdown","AggregateError","getErrorMessage","cause","logger","StructuredLogger"],"mappings":";;;;;;;;;;;;;AAsBA,MAAMA,WAAW;AACjB,MAAMC,eAAaC,cAAc,YAAY,GAAG;AAChD,MAAMC,cAAYC,QAAQH;AAC1B,MAAMI,eAAeC,KAAK,KAAK,CAACC,aAAaC,KAAKL,aAAW,oBAAoB;AACjF,MAAM,EAAEM,OAAO,EAAE,GAAGJ;AAEpB,MAAMK,OAAOC,QAAQ,IAAI,CAAC,KAAK,CAAC;AAChC,MAAMC,oBAAoBF,KAAK,QAAQ,CAAC,gBAAgBA,KAAK,QAAQ,CAAC;AAEtE,IAAIE,mBAAmB;IACtBC,QAAQ,GAAG,CAAC,GAAGb,SAAS,EAAE,EAAES,SAAS;IACrCE,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;IACN;IACAlC,QAAQ,EAAE,CAAC,UAAUsC;IACrBtC,QAAQ,EAAE,CAAC,WAAWsC;IACtB,IAAIL,oBAAoBjC,QAAQ,KAAK,CAAC,EAAE,CAAC,OAAOsC;AACjD;AAEA,SAASF,gBAAgBhB,KAAc;IACtC,IAAI,CAAEA,CAAAA,iBAAiBmB,cAAa,GAAI,OAAO;QAAE,OAAOC,gBAAgBpB;IAAO;IAC/E,OAAO;QACN,OAAOA,MAAM,OAAO;QACpB,QAAQA,MAAM,MAAM,CAAC,GAAG,CAAC,CAACqB,QAAUD,gBAAgBC;IACrD;AACD;AACAtC,OAAO,KAAK,CAAC,CAACiB;IACb,MAAMsB,SAAS,IAAIC,iBAAiB;QACnC,OAAO;QACP,SAAS;QACT,QAAQ;IACT;IACAD,OAAO,KAAK,CAAC,8BAA8BN,gBAAgBhB;IAC3DpB,QAAQ,IAAI,CAAC;AACd"}
|
|
1
|
+
{"version":3,"file":"cli.js","sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env bun\n\n// CLI entry point for tracelattice MCP server.\n// This file handles CLI argument parsing, transport selection, and signal handlers.\n// For library usage, import from './lib.js' or './index.js' instead.\n\nimport { ValibotJsonSchemaAdapter } from '@tmcp/adapter-valibot';\nimport { StdioTransport } from '@tmcp/transport-stdio';\nimport { readFileSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { McpServer } from 'tmcp';\nimport { CliLifecycle, createCliShutdownHandler } from './CliLifecycle.js';\nimport { parseCliTransportConfig } from './config/CliTransportConfig.js';\nimport type { CliHttpTransportConfig } from './config/CliTransportConfig.js';\nimport type { ToolAwareSequentialThinkingServer } from './lib.js';\nimport { initializeServer } from './lib.js';\nimport { StructuredLogger } from './logger/StructuredLogger.js';\nimport { getErrorMessage } from './errors.js';\nimport { HealthChecker } from './health/HealthChecker.js';\nimport { SEQUENTIAL_THINKING_TOOL, SequentialThinkingSchema } from './schema.js';\n\n// Get version from package.json\nconst CLI_NAME = 'tracelattice' as const;\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = dirname(__filename);\nconst package_json = JSON.parse(readFileSync(join(__dirname, '../package.json'), 'utf-8'));\nconst { version } = package_json;\n// Orchestrators poll /ready often; one settled probe serves every poll inside this window.\nconst READINESS_PROBE_FRESHNESS_MS = 1000;\n// Handle CLI arguments\nconst args = process.argv.slice(2);\nconst shouldShowVersion = args.includes('--version') || args.includes('-v');\n\nif (shouldShowVersion) {\n\tconsole.log(`${CLI_NAME} v${version}`);\n\tprocess.exit(0);\n}\nasync function main() {\n\tconst adapter = new ValibotJsonSchemaAdapter();\n\tconst server = new McpServer(\n\t\t{\n\t\t\tname: CLI_NAME,\n\t\t\tversion,\n\t\t\tdescription: 'Semantic Sequential Thinking MCP Server',\n\t\t},\n\t\t{\n\t\t\tadapter,\n\t\t\tcapabilities: {\n\t\t\t\ttools: { listChanged: true },\n\t\t\t},\n\t\t}\n\t);\n\n\tconst thinkingServer = await initializeServer();\n\tconst lifecycle = new CliLifecycle(thinkingServer);\n\ttry {\n\t\tconst transportConfig = parseCliTransportConfig(process.env);\n\t\tserver.tool(\n\t\t\t{\n\t\t\t\tname: 'sequentialthinking_tools',\n\t\t\t\tdescription: SEQUENTIAL_THINKING_TOOL.description,\n\t\t\t\tschema: SequentialThinkingSchema,\n\t\t\t},\n\t\t\tasync (input) => thinkingServer.processThought(input)\n\t\t);\n\t\tif (transportConfig.kind === 'streamable-http') {\n\t\t\tawait startStreamableHttpTransport(server, thinkingServer, {\n\t\t\t\tlifecycle,\n\t\t\t\tconfig: transportConfig,\n\t\t\t});\n\t\t} else {\n\t\t\tawait startStdioTransport(server, thinkingServer, lifecycle);\n\t\t}\n\t\tregisterShutdownHandlers(lifecycle, thinkingServer, transportConfig.kind === 'stdio');\n\t} catch (error) {\n\t\tawait lifecycle.rollbackStartup(error);\n\t}\n}\n/**\n * Start Streamable HTTP transport (MCP spec recommended)\n */\nasync function startStreamableHttpTransport(\n\tserver: McpServer,\n\tthinkingServer: ToolAwareSequentialThinkingServer,\n\toptions: { readonly lifecycle: CliLifecycle; readonly config: CliHttpTransportConfig }\n): Promise<void> {\n\tconst { StreamableHttpTransport } = await import('./transport/StreamableHttpTransport.js');\n\tconst { lifecycle, config } = options;\n\tconst { port, host } = config;\n\tconst container = thinkingServer.getContainer();\n\tconst healthChecker = new HealthChecker({\n\t\tpersistence: container.resolve('Persistence'),\n\t\tpersistenceBacklog: container.resolve('HistoryManager'),\n\t\tprobeFreshnessMs: READINESS_PROBE_FRESHNESS_MS,\n\t});\n\tconst streamableTransport = new StreamableHttpTransport({\n\t\tport,\n\t\thost,\n\t\tcorsOrigin: config.corsOrigin,\n\t\tenableCors: config.enableCors,\n\t\tallowedHosts: config.allowedHosts,\n\t\tmetrics: container.resolve('Metrics'),\n\t\thealthChecker,\n\t\tstateful: config.stateful,\n\t\t...config.retention,\n\t});\n\tlifecycle.attachTransport(streamableTransport);\n\t// Connect the Streamable HTTP transport\n\tawait streamableTransport.connect(server);\n\tthinkingServer['_logger'].info(\n\t\t`Sequential Thinking MCP Server running on Streamable HTTP transport at http://${host}:${port}`\n\t);\n}\n/**\n * Start stdio transport (default, single-user)\n */\nasync function startStdioTransport(\n\tserver: McpServer,\n\tthinkingServer: ToolAwareSequentialThinkingServer,\n\tlifecycle: CliLifecycle\n): Promise<void> {\n\tconst transport = new StdioTransport(server);\n\tconst processListeners = {\n\t\tsigint: new Set(process.listeners('SIGINT')),\n\t\tsigterm: new Set(process.listeners('SIGTERM')),\n\t\tstdinEnd: new Set(process.stdin.listeners('end')),\n\t};\n\tlifecycle.attachTransport({ stop: () => transport.close() });\n\ttransport.listen();\n\tfor (const listener of process.listeners('SIGINT')) {\n\t\tif (!processListeners.sigint.has(listener)) process.off('SIGINT', listener);\n\t}\n\tfor (const listener of process.listeners('SIGTERM')) {\n\t\tif (!processListeners.sigterm.has(listener)) process.off('SIGTERM', listener);\n\t}\n\tfor (const listener of process.stdin.listeners('end')) {\n\t\tif (!processListeners.stdinEnd.has(listener)) process.stdin.off('end', listener);\n\t}\n\tthinkingServer['_logger'].info('Sequential Thinking MCP Server running on stdio');\n}\n/**\n * Register shutdown signal handlers for a common pattern\n */\nfunction registerShutdownHandlers(\n\tlifecycle: CliLifecycle,\n\tthinkingServer: ToolAwareSequentialThinkingServer,\n\tshutdownOnStdinEnd: boolean\n): void {\n\tconst shutdown = createCliShutdownHandler(lifecycle, {\n\t\treportFailure: (error) => {\n\t\t\tthinkingServer['_logger'].error('CLI shutdown failed', failureMetadata(error));\n\t\t},\n\t\texit: (code) => process.exit(code),\n\t});\n\tconst requestShutdown = (): void => {\n\t\tvoid shutdown();\n\t};\n\tprocess.on('SIGINT', requestShutdown);\n\tprocess.on('SIGTERM', requestShutdown);\n\tif (shutdownOnStdinEnd) process.stdin.on('end', requestShutdown);\n}\n\nfunction failureMetadata(error: unknown): Record<string, unknown> {\n\tif (!(error instanceof AggregateError)) return { error: getErrorMessage(error) };\n\treturn {\n\t\terror: error.message,\n\t\tcauses: error.errors.map((cause) => getErrorMessage(cause)),\n\t};\n}\nmain().catch((error) => {\n\tconst logger = new StructuredLogger({\n\t\tlevel: 'error',\n\t\tcontext: 'SequentialThinking',\n\t\tpretty: true,\n\t});\n\tlogger.error('Fatal error running server', failureMetadata(error));\n\tprocess.exit(1);\n});\n"],"names":["CLI_NAME","__filename","fileURLToPath","__dirname","dirname","package_json","JSON","readFileSync","join","version","READINESS_PROBE_FRESHNESS_MS","args","process","shouldShowVersion","console","main","adapter","ValibotJsonSchemaAdapter","server","McpServer","thinkingServer","initializeServer","lifecycle","CliLifecycle","transportConfig","parseCliTransportConfig","SEQUENTIAL_THINKING_TOOL","SequentialThinkingSchema","input","startStreamableHttpTransport","startStdioTransport","registerShutdownHandlers","error","options","StreamableHttpTransport","config","port","host","container","healthChecker","HealthChecker","streamableTransport","transport","StdioTransport","processListeners","Set","listener","shutdownOnStdinEnd","shutdown","createCliShutdownHandler","failureMetadata","code","requestShutdown","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|
readonly persistenceFlushInterval?: number;
|
|
101
101
|
/** Maximum flush retries; file-only (default 3 in ServerConfig). */
|
|
102
102
|
readonly persistenceMaxRetries?: number;
|
|
103
|
+
/** Maximum unacknowledged thought writes per session; file-only (default 10000 in ServerConfig). */
|
|
104
|
+
readonly persistenceMaxPendingThoughtsPerSession?: number;
|
|
103
105
|
/**
|
|
104
106
|
* Feature flag overrides. Each field can be set independently.
|
|
105
107
|
* Can be overridden by `TRACELATTICE_FEATURES_*` environment variables.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfigLoader.d.ts","sourceRoot":"","sources":["../../src/config/ConfigLoader.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAOH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAE5E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"ConfigLoader.d.ts","sourceRoot":"","sources":["../../src/config/ConfigLoader.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAOH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAE5E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAmC9D;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,WAAW,iBAAiB;IACjC;;;OAGG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IAEjC;;;OAGG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAE9B;;;OAGG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAEhC;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,GAA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AE,MAAM;IAc/B;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,IAAI,IAAI,iBAAiB,GAAG,IAAI;IAiBhC;;;;;;;;;;;;;;;;;;;;OAoBG;IACI,yBAAyB,CAAC,MAAM,EAAE,iBAAiB,GAAG,iBAAiB;IAsF9E,OAAO,CAAC,WAAW;IAsBnB;;;;;;;OAOG;IACH,OAAO,CAAC,yBAAyB;IAuCjC;;;;;;;OAOG;IACH,OAAO,CAAC,YAAY;IAOpB;;;;;;;;;;OAUG;IACH,OAAO,CAAC,WAAW;IASnB;;;;;;;;;;;;;;;;;;OAkBG;IACH,qBAAqB,CAAC,MAAM,EAAE,iBAAiB,GAAG,mBAAmB;CAmBrE"}
|
|
@@ -26,6 +26,7 @@ const ConfigFileOptionsSchema = __rspack_external_valibot.looseObject({
|
|
|
26
26
|
persistenceBufferSize: __rspack_external_valibot.optional(__rspack_external_valibot.number()),
|
|
27
27
|
persistenceFlushInterval: __rspack_external_valibot.optional(__rspack_external_valibot.number()),
|
|
28
28
|
persistenceMaxRetries: __rspack_external_valibot.optional(__rspack_external_valibot.number()),
|
|
29
|
+
persistenceMaxPendingThoughtsPerSession: __rspack_external_valibot.optional(__rspack_external_valibot.number()),
|
|
29
30
|
features: __rspack_external_valibot.optional(__rspack_external_valibot.looseObject({})),
|
|
30
31
|
toolInterleaveTtlMs: __rspack_external_valibot.optional(__rspack_external_valibot.number()),
|
|
31
32
|
toolInterleaveSweepMs: __rspack_external_valibot.optional(__rspack_external_valibot.number()),
|
|
@@ -179,6 +180,7 @@ class ConfigLoader {
|
|
|
179
180
|
persistenceBufferSize: config.persistenceBufferSize,
|
|
180
181
|
persistenceFlushInterval: config.persistenceFlushInterval,
|
|
181
182
|
persistenceMaxRetries: config.persistenceMaxRetries,
|
|
183
|
+
persistenceMaxPendingThoughtsPerSession: config.persistenceMaxPendingThoughtsPerSession,
|
|
182
184
|
features: config.features,
|
|
183
185
|
toolInterleaveTtlMs: config.toolInterleaveTtlMs,
|
|
184
186
|
toolInterleaveSweepMs: config.toolInterleaveSweepMs,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config/ConfigLoader.js","sources":["../../src/config/ConfigLoader.ts"],"sourcesContent":["/**\n * Configuration file loading with environment variable override support.\n *\n * This module provides the `ConfigLoader` class which handles loading configuration\n * from YAML and JSON files in standard locations, with automatic environment variable\n * overrides for supported settings. Persistence buffer, flush, and retry settings are file-only.\n *\n * @module config\n */\n\nimport { existsSync, readFileSync } from 'node:fs';\nimport { homedir } from 'node:os';\nimport { join } from 'node:path';\nimport { parse as parseYaml } from 'yaml';\nimport * as v from 'valibot';\nimport type { PersistenceConfig } from '../contracts/PersistenceBackend.js';\nimport { ConfigurationError, getErrorMessage } from '../errors.js';\nimport type { FeatureFlags } from '../contracts/features.js';\nimport type { ServerConfigOptions } from '../ServerConfig.js';\nimport { parseEnvironmentInteger } from './EnvironmentInteger.js';\n\n/**\n * Lenient runtime schema for config files. Only validates top-level shape;\n * unknown extra fields are preserved by Valibot's default object behavior\n * being strict is avoided by using `v.looseObject`. All fields are optional.\n */\nconst ConfigFileOptionsSchema = v.looseObject({\n\tmaxHistorySize: v.optional(v.number()),\n\tmaxBranches: v.optional(v.number()),\n\tmaxBranchSize: v.optional(v.number()),\n\tlogLevel: v.optional(v.picklist(['debug', 'info', 'warn', 'error'])),\n\tprettyLog: v.optional(v.boolean()),\n\tskillDirs: v.optional(v.array(v.string())),\n\ttoolDirs: v.optional(v.array(v.string())),\n\tdiscoveryCache: v.optional(\n\t\tv.looseObject({\n\t\t\tttl: v.optional(v.number()),\n\t\t\tmaxSize: v.optional(v.number()),\n\t\t})\n\t),\n\tpersistence: v.optional(v.looseObject({})),\n\tpersistenceBufferSize: v.optional(v.number()),\n\tpersistenceFlushInterval: v.optional(v.number()),\n\tpersistenceMaxRetries: v.optional(v.number()),\n\tfeatures: v.optional(v.looseObject({})),\n\ttoolInterleaveTtlMs: v.optional(v.number()),\n\ttoolInterleaveSweepMs: v.optional(v.number()),\n\tmaxSessionsPerOwner: v.optional(v.number()),\n});\n\ntype Mutable<T> = { -readonly [K in keyof T]: T[K] };\n\n/**\n * Configuration options loaded from config files.\n *\n * These options represent the structure of configuration files (JSON or YAML)\n * that can be loaded from standard locations. Only supported fields have\n * environment overrides; persistence buffer, flush, and retry settings are file-only.\n *\n * @example\n * ```yaml\n * # .claude/config.yaml\n * maxHistorySize: 500\n * maxBranches: 25\n * logLevel: debug\n * prettyLog: true\n * skillDirs:\n * - ./custom-skills\n * toolDirs:\n * - ./custom-tools\n * discoveryCache:\n * ttl: 600000\n * maxSize: 200\n * persistence:\n * enabled: true\n * backend: sqlite\n * options:\n * dbPath: ./data/history.db\n * ```\n */\nexport interface ConfigFileOptions {\n\t/**\n\t * Maximum number of thoughts to keep in history.\n\t * Can be overridden by `TRACELATTICE_MAX_HISTORY_SIZE` environment variable.\n\t */\n\treadonly maxHistorySize?: number;\n\n\t/**\n\t * Maximum number of branches to maintain.\n\t * Can be overridden by `TRACELATTICE_MAX_BRANCHES` environment variable.\n\t */\n\treadonly maxBranches?: number;\n\n\t/**\n\t * Maximum size of each branch.\n\t * Can be overridden by `TRACELATTICE_MAX_BRANCH_SIZE` environment variable.\n\t */\n\treadonly maxBranchSize?: number;\n\n\t/**\n\t * Logging level for the application.\n\t * Can be overridden by `TRACELATTICE_LOG_LEVEL` environment variable.\n\t */\n\treadonly logLevel?: 'debug' | 'info' | 'warn' | 'error';\n\n\t/**\n\t * Whether to enable pretty (formatted) logging output.\n\t * Can be overridden by `TRACELATTICE_PRETTY_LOG` environment variable (set to \"false\" to disable).\n\t */\n\treadonly prettyLog?: boolean;\n\n\t/**\n\t * Directory paths to search for skills.\n\t * Can be overridden by `TRACELATTICE_SKILL_DIRS` environment variable (colon-separated).\n\t */\n\treadonly skillDirs?: string[];\n\n\t/**\n\t * Directory paths to search for tools.\n\t * Can be overridden by `TRACELATTICE_TOOL_DIRS` environment variable (colon-separated).\n\t */\n\treadonly toolDirs?: string[];\n\n\t/**\n\t * Discovery cache configuration.\n\t * Can be overridden by `TRACELATTICE_DISCOVERY_CACHE_TTL` and\n\t * `TRACELATTICE_DISCOVERY_CACHE_MAX_SIZE` environment variables.\n\t */\n\treadonly discoveryCache?: {\n\t\t/**\n\t\t * Time-to-live for cache entries in milliseconds.\n\t\t * Environment variable `TRACELATTICE_DISCOVERY_CACHE_TTL` accepts seconds.\n\t\t */\n\t\treadonly ttl?: number;\n\t\t/**\n\t\t * Maximum number of entries in the cache.\n\t\t */\n\t\treadonly maxSize?: number;\n\t};\n\n\t/**\n\t * Persistence configuration for storing history and state.\n\t */\n\treadonly persistence?: PersistenceConfig;\n\n\t/** Maximum buffered thoughts before flushing; file-only (default 100 in ServerConfig). */\n\treadonly persistenceBufferSize?: number;\n\n\t/** Periodic flush interval in milliseconds; file-only (default 1000 in ServerConfig). */\n\treadonly persistenceFlushInterval?: number;\n\n\t/** Maximum flush retries; file-only (default 3 in ServerConfig). */\n\treadonly persistenceMaxRetries?: number;\n\n\t/**\n\t * Feature flag overrides. Each field can be set independently.\n\t * Can be overridden by `TRACELATTICE_FEATURES_*` environment variables.\n\t */\n\treadonly features?: Partial<FeatureFlags>;\n\n\t/**\n\t * TTL in milliseconds for suspended tool-interleave entries.\n\t * Can be overridden by `TRACELATTICE_TOOL_INTERLEAVE_TTL_MS` environment variable.\n\t */\n\treadonly toolInterleaveTtlMs?: number;\n\n\t/**\n\t * Sweep interval in milliseconds for SuspensionStore expiration cleanup.\n\t * Can be overridden by `TRACELATTICE_TOOL_INTERLEAVE_SWEEP_MS` environment variable.\n\t */\n\treadonly toolInterleaveSweepMs?: number;\n\n\t/**\n\t * Maximum sessions per owner. Per-owner LRU bucket prevents one user from\n\t * consuming all session slots.\n\t * Can be overridden by `TRACELATTICE_SESSION_MAX_PER_OWNER` environment variable.\n\t */\n\treadonly maxSessionsPerOwner?: number;\n}\n\n/**\n * Loads configuration from files with environment variable overrides.\n *\n * This class searches for configuration files in standard locations and applies\n * environment variable overrides. Files are searched in priority order, with the\n * first valid match being used. Supported environment variables take precedence over file values.\n *\n * @remarks\n * **Config File Search Order (priority):**\n * 1. Custom path or `TRACELATTICE_CONFIG` (if present, replaces the default search list)\n * 2. `.claude/config.json` (project-local)\n * 3. `.claude/config.yaml` (project-local)\n * 4. `.claude/config.yml` (project-local)\n * 5. `~/.claude/config.json` (user-global)\n * 6. `~/.claude/config.yaml` (user-global)\n * 7. `~/.claude/config.yml` (user-global)\n *\n * **Environment Variable Overrides:**\n * | Variable | Type | Description |\n * |----------|------|-------------|\n * | `TRACELATTICE_MAX_HISTORY_SIZE` | number | Max thoughts in history |\n * | `TRACELATTICE_MAX_BRANCHES` | number | Max number of branches |\n * | `TRACELATTICE_MAX_BRANCH_SIZE` | number | Max size of each branch |\n * | `TRACELATTICE_LOG_LEVEL` | string | Logging level (debug/info/warn/error) |\n * | `TRACELATTICE_PRETTY_LOG` | string | \"false\" to disable pretty logging |\n * | `TRACELATTICE_SKILL_DIRS` | string | Colon-separated directory paths |\n * | `TRACELATTICE_TOOL_DIRS` | string | Colon-separated directory paths |\n * | `TRACELATTICE_DISCOVERY_CACHE_TTL` | number | TTL in seconds (converted to ms) |\n * | `TRACELATTICE_DISCOVERY_CACHE_MAX_SIZE` | number | Max cache entries |\n * | `TRACELATTICE_TOOL_INTERLEAVE_TTL_MS` / `TRACELATTICE_TOOL_INTERLEAVE_SWEEP_MS` | number | Milliseconds |\n * | `TRACELATTICE_SESSION_MAX_PER_OWNER` | number | Max sessions per owner |\n * | `TRACELATTICE_FEATURES_*` | boolean or strategy | Feature toggles or `sequential`/`tot` |\n *\n * Persistence buffer size, flush interval (milliseconds), and retries are file-only.\n *\n * @example\n * ```typescript\n * // Use default search paths\n * const loader1 = new ConfigLoader();\n * const config1 = loader1.load();\n *\n * // Use custom config path\n * const loader2 = new ConfigLoader('./my-config.yaml');\n * const config2 = loader2.load();\n *\n * // Convert to ServerConfig options\n * const serverOptions = loader2.toServerConfigOptions(config2);\n * ```\n */\nexport class ConfigLoader {\n\t/** Array of config file paths to search, in priority order. */\n\tprivate _configPaths: string[];\n\n\t/**\n\t * Creates a new ConfigLoader instance.\n\t *\n\t * @param customPath - Optional custom config file path. If provided, only this path will be checked.\n\t *\n\t * @example\n\t * ```typescript\n\t * // Use default search paths\n\t * const loader1 = new ConfigLoader();\n\t *\n\t * // Use a specific config file\n\t * const loader2 = new ConfigLoader('./custom-config.json');\n\t * ```\n\t */\n\tconstructor(customPath?: string) {\n\t\tconst configuredPath = customPath ?? process.env.TRACELATTICE_CONFIG;\n\t\tthis._configPaths = configuredPath\n\t\t\t? [configuredPath]\n\t\t\t: [\n\t\t\t\t\t'.claude/config.json',\n\t\t\t\t\t'.claude/config.yaml',\n\t\t\t\t\t'.claude/config.yml',\n\t\t\t\t\tjoin(homedir(), '.claude/config.json'),\n\t\t\t\t\tjoin(homedir(), '.claude/config.yaml'),\n\t\t\t\t\tjoin(homedir(), '.claude/config.yml'),\n\t\t\t\t];\n\t}\n\n\t/**\n\t * Loads configuration from files and applies environment overrides.\n\t *\n\t * Searches for config files in the configured paths (in priority order),\n\t * parses the first match, and applies environment variable overrides.\n\t * A malformed file is logged and skipped. With no valid file, applies environment\n\t * overrides to an empty object (the declared nullable return type does not return null).\n\t *\n\t * @returns The loaded configuration with environment overrides applied, or an empty/overlaid object\n\t *\n\t * @example\n\t * ```typescript\n\t * const loader = new ConfigLoader();\n\t * const config = loader.load();\n\t *\n\t * if (config) {\n\t * console.log('Max history size:', config.maxHistorySize);\n\t * console.log('Log level:', config.logLevel);\n\t * }\n\t * ```\n\t */\n\tload(): ConfigFileOptions | null {\n\t\tlet config: ConfigFileOptions | null = null;\n\n\t\tfor (const configPath of this._configPaths) {\n\t\t\tif (existsSync(configPath)) {\n\t\t\t\ttry {\n\t\t\t\t\tconfig = this.parseConfig(configPath);\n\t\t\t\t\tbreak;\n\t\t\t\t} catch (error) {\n\t\t\t\t\tconsole.error(`Failed to load config from ${configPath}:`, getErrorMessage(error));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn this.applyEnvironmentOverrides(config || {});\n\t}\n\n\t/**\n\t * Applies environment variable overrides to the configuration.\n\t *\n\t * Environment variables take precedence over file-based configuration.\n\t * Supported environment variables:\n\t * - `TRACELATTICE_MAX_HISTORY_SIZE`, `TRACELATTICE_MAX_BRANCHES`,\n\t * `TRACELATTICE_MAX_BRANCH_SIZE` (numbers)\n\t * - `TRACELATTICE_LOG_LEVEL` (debug/info/warn/error)\n\t * - `TRACELATTICE_PRETTY_LOG` (\"false\" to disable)\n\t * - `TRACELATTICE_SKILL_DIRS` (colon-separated paths)\n\t * - `TRACELATTICE_TOOL_DIRS` (colon-separated paths)\n\t * - `TRACELATTICE_DISCOVERY_CACHE_TTL` (in seconds, converted to ms)\n\t * - `TRACELATTICE_DISCOVERY_CACHE_MAX_SIZE` (number)\n\t * - `TRACELATTICE_TOOL_INTERLEAVE_TTL_MS`, `TRACELATTICE_TOOL_INTERLEAVE_SWEEP_MS` (milliseconds)\n\t * - `TRACELATTICE_SESSION_MAX_PER_OWNER` (number)\n\t * - `TRACELATTICE_FEATURES_*` (booleans true/false/1/0 or sequential/tot strategy)\n\t * Persistence buffer, flush interval, and retry settings have no environment aliases.\n\t *\n\t * @param config - The configuration to apply overrides to\n\t * @returns A new configuration object with environment overrides applied\n\t */\n\tpublic applyEnvironmentOverrides(config: ConfigFileOptions): ConfigFileOptions {\n\t\tconst result = this.cloneConfig(config);\n\n\t\tif (process.env.TRACELATTICE_MAX_HISTORY_SIZE !== undefined) {\n\t\t\tresult.maxHistorySize = parseEnvironmentInteger(\n\t\t\t\t'TRACELATTICE_MAX_HISTORY_SIZE',\n\t\t\t\tprocess.env.TRACELATTICE_MAX_HISTORY_SIZE\n\t\t\t);\n\t\t}\n\t\tif (process.env.TRACELATTICE_MAX_BRANCHES !== undefined) {\n\t\t\tresult.maxBranches = parseEnvironmentInteger(\n\t\t\t\t'TRACELATTICE_MAX_BRANCHES',\n\t\t\t\tprocess.env.TRACELATTICE_MAX_BRANCHES\n\t\t\t);\n\t\t}\n\t\tif (process.env.TRACELATTICE_MAX_BRANCH_SIZE !== undefined) {\n\t\t\tresult.maxBranchSize = parseEnvironmentInteger(\n\t\t\t\t'TRACELATTICE_MAX_BRANCH_SIZE',\n\t\t\t\tprocess.env.TRACELATTICE_MAX_BRANCH_SIZE\n\t\t\t);\n\t\t}\n\t\tif (\n\t\t\tprocess.env.TRACELATTICE_LOG_LEVEL &&\n\t\t\t['debug', 'info', 'warn', 'error'].includes(process.env.TRACELATTICE_LOG_LEVEL)\n\t\t) {\n\t\t\tresult.logLevel = process.env.TRACELATTICE_LOG_LEVEL as 'debug' | 'info' | 'warn' | 'error';\n\t\t}\n\t\tif (process.env.TRACELATTICE_PRETTY_LOG === 'false') {\n\t\t\tresult.prettyLog = false;\n\t\t}\n\t\tif (process.env.TRACELATTICE_SKILL_DIRS !== undefined) {\n\t\t\tresult.skillDirs =\n\t\t\t\tprocess.env.TRACELATTICE_SKILL_DIRS === ''\n\t\t\t\t\t? []\n\t\t\t\t\t: process.env.TRACELATTICE_SKILL_DIRS.split(':');\n\t\t}\n\t\tif (process.env.TRACELATTICE_TOOL_DIRS !== undefined) {\n\t\t\tresult.toolDirs =\n\t\t\t\tprocess.env.TRACELATTICE_TOOL_DIRS === ''\n\t\t\t\t\t? []\n\t\t\t\t\t: process.env.TRACELATTICE_TOOL_DIRS.split(':');\n\t\t}\n\t\tif (process.env.TRACELATTICE_DISCOVERY_CACHE_TTL !== undefined) {\n\t\t\tconst seconds = parseEnvironmentInteger(\n\t\t\t\t'TRACELATTICE_DISCOVERY_CACHE_TTL',\n\t\t\t\tprocess.env.TRACELATTICE_DISCOVERY_CACHE_TTL\n\t\t\t);\n\t\t\tconst ttl = seconds * 1000;\n\t\t\tif (!Number.isSafeInteger(ttl)) {\n\t\t\t\tthrow new ConfigurationError(\n\t\t\t\t\t'TRACELATTICE_DISCOVERY_CACHE_TTL exceeds the safe integer range'\n\t\t\t\t);\n\t\t\t}\n\t\t\tresult.discoveryCache = { ...result.discoveryCache, ttl };\n\t\t}\n\t\tif (process.env.TRACELATTICE_DISCOVERY_CACHE_MAX_SIZE !== undefined) {\n\t\t\tconst maxSize = parseEnvironmentInteger(\n\t\t\t\t'TRACELATTICE_DISCOVERY_CACHE_MAX_SIZE',\n\t\t\t\tprocess.env.TRACELATTICE_DISCOVERY_CACHE_MAX_SIZE\n\t\t\t);\n\t\t\tresult.discoveryCache = { ...result.discoveryCache, maxSize };\n\t\t}\n\t\tif (process.env.TRACELATTICE_TOOL_INTERLEAVE_TTL_MS !== undefined) {\n\t\t\tresult.toolInterleaveTtlMs = parseEnvironmentInteger(\n\t\t\t\t'TRACELATTICE_TOOL_INTERLEAVE_TTL_MS',\n\t\t\t\tprocess.env.TRACELATTICE_TOOL_INTERLEAVE_TTL_MS\n\t\t\t);\n\t\t}\n\t\tif (process.env.TRACELATTICE_TOOL_INTERLEAVE_SWEEP_MS !== undefined) {\n\t\t\tresult.toolInterleaveSweepMs = parseEnvironmentInteger(\n\t\t\t\t'TRACELATTICE_TOOL_INTERLEAVE_SWEEP_MS',\n\t\t\t\tprocess.env.TRACELATTICE_TOOL_INTERLEAVE_SWEEP_MS\n\t\t\t);\n\t\t}\n\t\tif (process.env.TRACELATTICE_SESSION_MAX_PER_OWNER !== undefined) {\n\t\t\tresult.maxSessionsPerOwner = parseEnvironmentInteger(\n\t\t\t\t'TRACELATTICE_SESSION_MAX_PER_OWNER',\n\t\t\t\tprocess.env.TRACELATTICE_SESSION_MAX_PER_OWNER\n\t\t\t);\n\t\t}\n\n\t\tthis.applyFeatureFlagOverrides(result);\n\n\t\treturn result;\n\t}\n\n\tprivate cloneConfig(config: ConfigFileOptions): Mutable<ConfigFileOptions> {\n\t\treturn {\n\t\t\t...config,\n\t\t\t...(config.skillDirs === undefined ? {} : { skillDirs: [...config.skillDirs] }),\n\t\t\t...(config.toolDirs === undefined ? {} : { toolDirs: [...config.toolDirs] }),\n\t\t\t...(config.discoveryCache === undefined\n\t\t\t\t? {}\n\t\t\t\t: { discoveryCache: { ...config.discoveryCache } }),\n\t\t\t...(config.persistence === undefined\n\t\t\t\t? {}\n\t\t\t\t: {\n\t\t\t\t\t\tpersistence: {\n\t\t\t\t\t\t\t...config.persistence,\n\t\t\t\t\t\t\t...(config.persistence.options === undefined\n\t\t\t\t\t\t\t\t? {}\n\t\t\t\t\t\t\t\t: { options: { ...config.persistence.options } }),\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t...(config.features === undefined ? {} : { features: { ...config.features } }),\n\t\t};\n\t}\n\n\t/**\n\t * Applies TRACELATTICE_FEATURES_* environment variable overrides for feature flags.\n\t * Booleans accept 'true'/'false'/'1'/'0' (case-insensitive).\n\t * Invalid reasoningStrategy values are rejected.\n\t *\n\t * @param result - Configuration object to mutate with feature flag overrides\n\t * @private\n\t */\n\tprivate applyFeatureFlagOverrides(result: Mutable<ConfigFileOptions>): void {\n\t\tconst boolMap: Record<string, Exclude<keyof FeatureFlags, 'reasoningStrategy'>> = {\n\t\t\tTRACELATTICE_FEATURES_DAG_EDGES: 'dagEdges',\n\t\t\tTRACELATTICE_FEATURES_CALIBRATION: 'calibration',\n\t\t\tTRACELATTICE_FEATURES_COMPRESSION: 'compression',\n\t\t\tTRACELATTICE_FEATURES_TOOL_INTERLEAVE: 'toolInterleave',\n\t\t\tTRACELATTICE_FEATURES_NEW_THOUGHT_TYPES: 'newThoughtTypes',\n\t\t\tTRACELATTICE_FEATURES_OUTCOME_RECORDING: 'outcomeRecording',\n\t\t};\n\t\tfor (const [envVar, key] of Object.entries(boolMap)) {\n\t\t\tconst raw = process.env[envVar];\n\t\t\tif (raw === undefined) continue;\n\t\t\tconst parsed = this.parseBoolean(raw);\n\t\t\tif (parsed === undefined) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`Invalid boolean value for ${envVar}: \"${raw}\" (expected true/false/1/0). Ignoring.`\n\t\t\t\t);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst features: { -readonly [K in keyof FeatureFlags]?: FeatureFlags[K] } =\n\t\t\t\tresult.features ?? {};\n\t\t\tfeatures[key] = parsed;\n\t\t\tresult.features = features;\n\t\t}\n\n\t\tconst strategyRaw = process.env.TRACELATTICE_FEATURES_REASONING_STRATEGY;\n\t\tif (strategyRaw !== undefined) {\n\t\t\tif (strategyRaw !== 'sequential' && strategyRaw !== 'tot') {\n\t\t\t\tthrow new ConfigurationError(\n\t\t\t\t\t`TRACELATTICE_FEATURES_REASONING_STRATEGY must be one of sequential, tot, got ${strategyRaw}`\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst features: { -readonly [K in keyof FeatureFlags]?: FeatureFlags[K] } =\n\t\t\t\tresult.features ?? {};\n\t\t\tfeatures.reasoningStrategy = strategyRaw;\n\t\t\tresult.features = features;\n\t\t}\n\t}\n\n\t/**\n\t * Parses a boolean from an environment variable string.\n\t * Accepts 'true'/'false'/'1'/'0' case-insensitively.\n\t *\n\t * @param raw - Raw environment variable string\n\t * @returns Parsed boolean, or undefined if the value is invalid\n\t * @private\n\t */\n\tprivate parseBoolean(raw: string): boolean | undefined {\n\t\tconst v = raw.trim().toLowerCase();\n\t\tif (v === 'true' || v === '1') return true;\n\t\tif (v === 'false' || v === '0') return false;\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Parses a configuration file (JSON or YAML).\n\t *\n\t * Detects the file type by extension and uses the appropriate parser.\n\t * Supports `.json`, `.yaml`, and `.yml` file extensions.\n\t *\n\t * @param filePath - Path to the configuration file to parse\n\t * @returns The parsed configuration object\n\t * @throws {Error} If the file cannot be parsed\n\t * @private\n\t */\n\tprivate parseConfig(filePath: string): ConfigFileOptions {\n\t\tconst content = readFileSync(filePath, 'utf-8');\n\t\tconst ext = filePath.split('.').pop()?.toLowerCase();\n\n\t\tconst raw: unknown = ext === 'yaml' || ext === 'yml' ? parseYaml(content) : JSON.parse(content);\n\n\t\treturn v.parse(ConfigFileOptionsSchema, raw) as ConfigFileOptions;\n\t}\n\n\t/**\n\t * Converts file-based configuration to ServerConfig options.\n\t *\n\t * This is a convenience method for extracting the ServerConfig-relevant\n\t * options from a file-based configuration.\n\t *\n\t * @param config - The configuration to convert\n\t * @returns An object with ServerConfig-compatible options\n\t *\n\t * @example\n\t * ```typescript\n\t * const loader = new ConfigLoader();\n\t * const config = loader.load();\n\t * if (config) {\n\t * const serverOpts = loader.toServerConfigOptions(config);\n\t * const serverConfig = new ServerConfig(serverOpts);\n\t * }\n\t * ```\n\t */\n\ttoServerConfigOptions(config: ConfigFileOptions): ServerConfigOptions {\n\t\treturn {\n\t\t\tmaxHistorySize: config.maxHistorySize,\n\t\t\tmaxBranches: config.maxBranches,\n\t\t\tmaxBranchSize: config.maxBranchSize,\n\t\t\tskillDirs: config.skillDirs,\n\t\t\ttoolDirs: config.toolDirs,\n\t\t\tdiscoveryCache: config.discoveryCache,\n\t\t\tpersistence: config.persistence,\n\t\t\tpersistenceBufferSize: config.persistenceBufferSize,\n\t\t\tpersistenceFlushInterval: config.persistenceFlushInterval,\n\t\t\tpersistenceMaxRetries: config.persistenceMaxRetries,\n\t\t\tfeatures: config.features,\n\t\t\ttoolInterleaveTtlMs: config.toolInterleaveTtlMs,\n\t\t\ttoolInterleaveSweepMs: config.toolInterleaveSweepMs,\n\t\t\tmaxSessionsPerOwner: config.maxSessionsPerOwner,\n\t\t};\n\t}\n}\n"],"names":["ConfigFileOptionsSchema","v","ConfigLoader","customPath","configuredPath","process","join","homedir","config","configPath","existsSync","error","console","getErrorMessage","result","undefined","parseEnvironmentInteger","seconds","ttl","Number","ConfigurationError","maxSize","boolMap","envVar","key","Object","raw","parsed","features","strategyRaw","filePath","content","readFileSync","ext","parseYaml","JSON"],"mappings":";;;;;;;AA0BA,MAAMA,0BAA0BC,0BAAAA,WAAa,CAAC;IAC7C,gBAAgBA,0BAAAA,QAAU,CAACA,0BAAAA,MAAQ;IACnC,aAAaA,0BAAAA,QAAU,CAACA,0BAAAA,MAAQ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,OAAO,mBAAmB;QAChD;IACD;AACD"}
|
|
1
|
+
{"version":3,"file":"config/ConfigLoader.js","sources":["../../src/config/ConfigLoader.ts"],"sourcesContent":["/**\n * Configuration file loading with environment variable override support.\n *\n * This module provides the `ConfigLoader` class which handles loading configuration\n * from YAML and JSON files in standard locations, with automatic environment variable\n * overrides for supported settings. Persistence buffer, flush, and retry settings are file-only.\n *\n * @module config\n */\n\nimport { existsSync, readFileSync } from 'node:fs';\nimport { homedir } from 'node:os';\nimport { join } from 'node:path';\nimport { parse as parseYaml } from 'yaml';\nimport * as v from 'valibot';\nimport type { PersistenceConfig } from '../contracts/PersistenceBackend.js';\nimport { ConfigurationError, getErrorMessage } from '../errors.js';\nimport type { FeatureFlags } from '../contracts/features.js';\nimport type { ServerConfigOptions } from '../ServerConfig.js';\nimport { parseEnvironmentInteger } from './EnvironmentInteger.js';\n\n/**\n * Lenient runtime schema for config files. Only validates top-level shape;\n * unknown extra fields are preserved by Valibot's default object behavior\n * being strict is avoided by using `v.looseObject`. All fields are optional.\n */\nconst ConfigFileOptionsSchema = v.looseObject({\n\tmaxHistorySize: v.optional(v.number()),\n\tmaxBranches: v.optional(v.number()),\n\tmaxBranchSize: v.optional(v.number()),\n\tlogLevel: v.optional(v.picklist(['debug', 'info', 'warn', 'error'])),\n\tprettyLog: v.optional(v.boolean()),\n\tskillDirs: v.optional(v.array(v.string())),\n\ttoolDirs: v.optional(v.array(v.string())),\n\tdiscoveryCache: v.optional(\n\t\tv.looseObject({\n\t\t\tttl: v.optional(v.number()),\n\t\t\tmaxSize: v.optional(v.number()),\n\t\t})\n\t),\n\tpersistence: v.optional(v.looseObject({})),\n\tpersistenceBufferSize: v.optional(v.number()),\n\tpersistenceFlushInterval: v.optional(v.number()),\n\tpersistenceMaxRetries: v.optional(v.number()),\n\tpersistenceMaxPendingThoughtsPerSession: v.optional(v.number()),\n\tfeatures: v.optional(v.looseObject({})),\n\ttoolInterleaveTtlMs: v.optional(v.number()),\n\ttoolInterleaveSweepMs: v.optional(v.number()),\n\tmaxSessionsPerOwner: v.optional(v.number()),\n});\n\ntype Mutable<T> = { -readonly [K in keyof T]: T[K] };\n\n/**\n * Configuration options loaded from config files.\n *\n * These options represent the structure of configuration files (JSON or YAML)\n * that can be loaded from standard locations. Only supported fields have\n * environment overrides; persistence buffer, flush, and retry settings are file-only.\n *\n * @example\n * ```yaml\n * # .claude/config.yaml\n * maxHistorySize: 500\n * maxBranches: 25\n * logLevel: debug\n * prettyLog: true\n * skillDirs:\n * - ./custom-skills\n * toolDirs:\n * - ./custom-tools\n * discoveryCache:\n * ttl: 600000\n * maxSize: 200\n * persistence:\n * enabled: true\n * backend: sqlite\n * options:\n * dbPath: ./data/history.db\n * ```\n */\nexport interface ConfigFileOptions {\n\t/**\n\t * Maximum number of thoughts to keep in history.\n\t * Can be overridden by `TRACELATTICE_MAX_HISTORY_SIZE` environment variable.\n\t */\n\treadonly maxHistorySize?: number;\n\n\t/**\n\t * Maximum number of branches to maintain.\n\t * Can be overridden by `TRACELATTICE_MAX_BRANCHES` environment variable.\n\t */\n\treadonly maxBranches?: number;\n\n\t/**\n\t * Maximum size of each branch.\n\t * Can be overridden by `TRACELATTICE_MAX_BRANCH_SIZE` environment variable.\n\t */\n\treadonly maxBranchSize?: number;\n\n\t/**\n\t * Logging level for the application.\n\t * Can be overridden by `TRACELATTICE_LOG_LEVEL` environment variable.\n\t */\n\treadonly logLevel?: 'debug' | 'info' | 'warn' | 'error';\n\n\t/**\n\t * Whether to enable pretty (formatted) logging output.\n\t * Can be overridden by `TRACELATTICE_PRETTY_LOG` environment variable (set to \"false\" to disable).\n\t */\n\treadonly prettyLog?: boolean;\n\n\t/**\n\t * Directory paths to search for skills.\n\t * Can be overridden by `TRACELATTICE_SKILL_DIRS` environment variable (colon-separated).\n\t */\n\treadonly skillDirs?: string[];\n\n\t/**\n\t * Directory paths to search for tools.\n\t * Can be overridden by `TRACELATTICE_TOOL_DIRS` environment variable (colon-separated).\n\t */\n\treadonly toolDirs?: string[];\n\n\t/**\n\t * Discovery cache configuration.\n\t * Can be overridden by `TRACELATTICE_DISCOVERY_CACHE_TTL` and\n\t * `TRACELATTICE_DISCOVERY_CACHE_MAX_SIZE` environment variables.\n\t */\n\treadonly discoveryCache?: {\n\t\t/**\n\t\t * Time-to-live for cache entries in milliseconds.\n\t\t * Environment variable `TRACELATTICE_DISCOVERY_CACHE_TTL` accepts seconds.\n\t\t */\n\t\treadonly ttl?: number;\n\t\t/**\n\t\t * Maximum number of entries in the cache.\n\t\t */\n\t\treadonly maxSize?: number;\n\t};\n\n\t/**\n\t * Persistence configuration for storing history and state.\n\t */\n\treadonly persistence?: PersistenceConfig;\n\n\t/** Maximum buffered thoughts before flushing; file-only (default 100 in ServerConfig). */\n\treadonly persistenceBufferSize?: number;\n\n\t/** Periodic flush interval in milliseconds; file-only (default 1000 in ServerConfig). */\n\treadonly persistenceFlushInterval?: number;\n\n\t/** Maximum flush retries; file-only (default 3 in ServerConfig). */\n\treadonly persistenceMaxRetries?: number;\n\n\t/** Maximum unacknowledged thought writes per session; file-only (default 10000 in ServerConfig). */\n\treadonly persistenceMaxPendingThoughtsPerSession?: number;\n\n\t/**\n\t * Feature flag overrides. Each field can be set independently.\n\t * Can be overridden by `TRACELATTICE_FEATURES_*` environment variables.\n\t */\n\treadonly features?: Partial<FeatureFlags>;\n\n\t/**\n\t * TTL in milliseconds for suspended tool-interleave entries.\n\t * Can be overridden by `TRACELATTICE_TOOL_INTERLEAVE_TTL_MS` environment variable.\n\t */\n\treadonly toolInterleaveTtlMs?: number;\n\n\t/**\n\t * Sweep interval in milliseconds for SuspensionStore expiration cleanup.\n\t * Can be overridden by `TRACELATTICE_TOOL_INTERLEAVE_SWEEP_MS` environment variable.\n\t */\n\treadonly toolInterleaveSweepMs?: number;\n\n\t/**\n\t * Maximum sessions per owner. Per-owner LRU bucket prevents one user from\n\t * consuming all session slots.\n\t * Can be overridden by `TRACELATTICE_SESSION_MAX_PER_OWNER` environment variable.\n\t */\n\treadonly maxSessionsPerOwner?: number;\n}\n\n/**\n * Loads configuration from files with environment variable overrides.\n *\n * This class searches for configuration files in standard locations and applies\n * environment variable overrides. Files are searched in priority order, with the\n * first valid match being used. Supported environment variables take precedence over file values.\n *\n * @remarks\n * **Config File Search Order (priority):**\n * 1. Custom path or `TRACELATTICE_CONFIG` (if present, replaces the default search list)\n * 2. `.claude/config.json` (project-local)\n * 3. `.claude/config.yaml` (project-local)\n * 4. `.claude/config.yml` (project-local)\n * 5. `~/.claude/config.json` (user-global)\n * 6. `~/.claude/config.yaml` (user-global)\n * 7. `~/.claude/config.yml` (user-global)\n *\n * **Environment Variable Overrides:**\n * | Variable | Type | Description |\n * |----------|------|-------------|\n * | `TRACELATTICE_MAX_HISTORY_SIZE` | number | Max thoughts in history |\n * | `TRACELATTICE_MAX_BRANCHES` | number | Max number of branches |\n * | `TRACELATTICE_MAX_BRANCH_SIZE` | number | Max size of each branch |\n * | `TRACELATTICE_LOG_LEVEL` | string | Logging level (debug/info/warn/error) |\n * | `TRACELATTICE_PRETTY_LOG` | string | \"false\" to disable pretty logging |\n * | `TRACELATTICE_SKILL_DIRS` | string | Colon-separated directory paths |\n * | `TRACELATTICE_TOOL_DIRS` | string | Colon-separated directory paths |\n * | `TRACELATTICE_DISCOVERY_CACHE_TTL` | number | TTL in seconds (converted to ms) |\n * | `TRACELATTICE_DISCOVERY_CACHE_MAX_SIZE` | number | Max cache entries |\n * | `TRACELATTICE_TOOL_INTERLEAVE_TTL_MS` / `TRACELATTICE_TOOL_INTERLEAVE_SWEEP_MS` | number | Milliseconds |\n * | `TRACELATTICE_SESSION_MAX_PER_OWNER` | number | Max sessions per owner |\n * | `TRACELATTICE_FEATURES_*` | boolean or strategy | Feature toggles or `sequential`/`tot` |\n *\n * Persistence buffer size, flush interval (milliseconds), and retries are file-only.\n *\n * @example\n * ```typescript\n * // Use default search paths\n * const loader1 = new ConfigLoader();\n * const config1 = loader1.load();\n *\n * // Use custom config path\n * const loader2 = new ConfigLoader('./my-config.yaml');\n * const config2 = loader2.load();\n *\n * // Convert to ServerConfig options\n * const serverOptions = loader2.toServerConfigOptions(config2);\n * ```\n */\nexport class ConfigLoader {\n\t/** Array of config file paths to search, in priority order. */\n\tprivate _configPaths: string[];\n\n\t/**\n\t * Creates a new ConfigLoader instance.\n\t *\n\t * @param customPath - Optional custom config file path. If provided, only this path will be checked.\n\t *\n\t * @example\n\t * ```typescript\n\t * // Use default search paths\n\t * const loader1 = new ConfigLoader();\n\t *\n\t * // Use a specific config file\n\t * const loader2 = new ConfigLoader('./custom-config.json');\n\t * ```\n\t */\n\tconstructor(customPath?: string) {\n\t\tconst configuredPath = customPath ?? process.env.TRACELATTICE_CONFIG;\n\t\tthis._configPaths = configuredPath\n\t\t\t? [configuredPath]\n\t\t\t: [\n\t\t\t\t\t'.claude/config.json',\n\t\t\t\t\t'.claude/config.yaml',\n\t\t\t\t\t'.claude/config.yml',\n\t\t\t\t\tjoin(homedir(), '.claude/config.json'),\n\t\t\t\t\tjoin(homedir(), '.claude/config.yaml'),\n\t\t\t\t\tjoin(homedir(), '.claude/config.yml'),\n\t\t\t\t];\n\t}\n\n\t/**\n\t * Loads configuration from files and applies environment overrides.\n\t *\n\t * Searches for config files in the configured paths (in priority order),\n\t * parses the first match, and applies environment variable overrides.\n\t * A malformed file is logged and skipped. With no valid file, applies environment\n\t * overrides to an empty object (the declared nullable return type does not return null).\n\t *\n\t * @returns The loaded configuration with environment overrides applied, or an empty/overlaid object\n\t *\n\t * @example\n\t * ```typescript\n\t * const loader = new ConfigLoader();\n\t * const config = loader.load();\n\t *\n\t * if (config) {\n\t * console.log('Max history size:', config.maxHistorySize);\n\t * console.log('Log level:', config.logLevel);\n\t * }\n\t * ```\n\t */\n\tload(): ConfigFileOptions | null {\n\t\tlet config: ConfigFileOptions | null = null;\n\n\t\tfor (const configPath of this._configPaths) {\n\t\t\tif (existsSync(configPath)) {\n\t\t\t\ttry {\n\t\t\t\t\tconfig = this.parseConfig(configPath);\n\t\t\t\t\tbreak;\n\t\t\t\t} catch (error) {\n\t\t\t\t\tconsole.error(`Failed to load config from ${configPath}:`, getErrorMessage(error));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn this.applyEnvironmentOverrides(config || {});\n\t}\n\n\t/**\n\t * Applies environment variable overrides to the configuration.\n\t *\n\t * Environment variables take precedence over file-based configuration.\n\t * Supported environment variables:\n\t * - `TRACELATTICE_MAX_HISTORY_SIZE`, `TRACELATTICE_MAX_BRANCHES`,\n\t * `TRACELATTICE_MAX_BRANCH_SIZE` (numbers)\n\t * - `TRACELATTICE_LOG_LEVEL` (debug/info/warn/error)\n\t * - `TRACELATTICE_PRETTY_LOG` (\"false\" to disable)\n\t * - `TRACELATTICE_SKILL_DIRS` (colon-separated paths)\n\t * - `TRACELATTICE_TOOL_DIRS` (colon-separated paths)\n\t * - `TRACELATTICE_DISCOVERY_CACHE_TTL` (in seconds, converted to ms)\n\t * - `TRACELATTICE_DISCOVERY_CACHE_MAX_SIZE` (number)\n\t * - `TRACELATTICE_TOOL_INTERLEAVE_TTL_MS`, `TRACELATTICE_TOOL_INTERLEAVE_SWEEP_MS` (milliseconds)\n\t * - `TRACELATTICE_SESSION_MAX_PER_OWNER` (number)\n\t * - `TRACELATTICE_FEATURES_*` (booleans true/false/1/0 or sequential/tot strategy)\n\t * Persistence buffer, flush interval, and retry settings have no environment aliases.\n\t *\n\t * @param config - The configuration to apply overrides to\n\t * @returns A new configuration object with environment overrides applied\n\t */\n\tpublic applyEnvironmentOverrides(config: ConfigFileOptions): ConfigFileOptions {\n\t\tconst result = this.cloneConfig(config);\n\n\t\tif (process.env.TRACELATTICE_MAX_HISTORY_SIZE !== undefined) {\n\t\t\tresult.maxHistorySize = parseEnvironmentInteger(\n\t\t\t\t'TRACELATTICE_MAX_HISTORY_SIZE',\n\t\t\t\tprocess.env.TRACELATTICE_MAX_HISTORY_SIZE\n\t\t\t);\n\t\t}\n\t\tif (process.env.TRACELATTICE_MAX_BRANCHES !== undefined) {\n\t\t\tresult.maxBranches = parseEnvironmentInteger(\n\t\t\t\t'TRACELATTICE_MAX_BRANCHES',\n\t\t\t\tprocess.env.TRACELATTICE_MAX_BRANCHES\n\t\t\t);\n\t\t}\n\t\tif (process.env.TRACELATTICE_MAX_BRANCH_SIZE !== undefined) {\n\t\t\tresult.maxBranchSize = parseEnvironmentInteger(\n\t\t\t\t'TRACELATTICE_MAX_BRANCH_SIZE',\n\t\t\t\tprocess.env.TRACELATTICE_MAX_BRANCH_SIZE\n\t\t\t);\n\t\t}\n\t\tif (\n\t\t\tprocess.env.TRACELATTICE_LOG_LEVEL &&\n\t\t\t['debug', 'info', 'warn', 'error'].includes(process.env.TRACELATTICE_LOG_LEVEL)\n\t\t) {\n\t\t\tresult.logLevel = process.env.TRACELATTICE_LOG_LEVEL as 'debug' | 'info' | 'warn' | 'error';\n\t\t}\n\t\tif (process.env.TRACELATTICE_PRETTY_LOG === 'false') {\n\t\t\tresult.prettyLog = false;\n\t\t}\n\t\tif (process.env.TRACELATTICE_SKILL_DIRS !== undefined) {\n\t\t\tresult.skillDirs =\n\t\t\t\tprocess.env.TRACELATTICE_SKILL_DIRS === ''\n\t\t\t\t\t? []\n\t\t\t\t\t: process.env.TRACELATTICE_SKILL_DIRS.split(':');\n\t\t}\n\t\tif (process.env.TRACELATTICE_TOOL_DIRS !== undefined) {\n\t\t\tresult.toolDirs =\n\t\t\t\tprocess.env.TRACELATTICE_TOOL_DIRS === ''\n\t\t\t\t\t? []\n\t\t\t\t\t: process.env.TRACELATTICE_TOOL_DIRS.split(':');\n\t\t}\n\t\tif (process.env.TRACELATTICE_DISCOVERY_CACHE_TTL !== undefined) {\n\t\t\tconst seconds = parseEnvironmentInteger(\n\t\t\t\t'TRACELATTICE_DISCOVERY_CACHE_TTL',\n\t\t\t\tprocess.env.TRACELATTICE_DISCOVERY_CACHE_TTL\n\t\t\t);\n\t\t\tconst ttl = seconds * 1000;\n\t\t\tif (!Number.isSafeInteger(ttl)) {\n\t\t\t\tthrow new ConfigurationError(\n\t\t\t\t\t'TRACELATTICE_DISCOVERY_CACHE_TTL exceeds the safe integer range'\n\t\t\t\t);\n\t\t\t}\n\t\t\tresult.discoveryCache = { ...result.discoveryCache, ttl };\n\t\t}\n\t\tif (process.env.TRACELATTICE_DISCOVERY_CACHE_MAX_SIZE !== undefined) {\n\t\t\tconst maxSize = parseEnvironmentInteger(\n\t\t\t\t'TRACELATTICE_DISCOVERY_CACHE_MAX_SIZE',\n\t\t\t\tprocess.env.TRACELATTICE_DISCOVERY_CACHE_MAX_SIZE\n\t\t\t);\n\t\t\tresult.discoveryCache = { ...result.discoveryCache, maxSize };\n\t\t}\n\t\tif (process.env.TRACELATTICE_TOOL_INTERLEAVE_TTL_MS !== undefined) {\n\t\t\tresult.toolInterleaveTtlMs = parseEnvironmentInteger(\n\t\t\t\t'TRACELATTICE_TOOL_INTERLEAVE_TTL_MS',\n\t\t\t\tprocess.env.TRACELATTICE_TOOL_INTERLEAVE_TTL_MS\n\t\t\t);\n\t\t}\n\t\tif (process.env.TRACELATTICE_TOOL_INTERLEAVE_SWEEP_MS !== undefined) {\n\t\t\tresult.toolInterleaveSweepMs = parseEnvironmentInteger(\n\t\t\t\t'TRACELATTICE_TOOL_INTERLEAVE_SWEEP_MS',\n\t\t\t\tprocess.env.TRACELATTICE_TOOL_INTERLEAVE_SWEEP_MS\n\t\t\t);\n\t\t}\n\t\tif (process.env.TRACELATTICE_SESSION_MAX_PER_OWNER !== undefined) {\n\t\t\tresult.maxSessionsPerOwner = parseEnvironmentInteger(\n\t\t\t\t'TRACELATTICE_SESSION_MAX_PER_OWNER',\n\t\t\t\tprocess.env.TRACELATTICE_SESSION_MAX_PER_OWNER\n\t\t\t);\n\t\t}\n\n\t\tthis.applyFeatureFlagOverrides(result);\n\n\t\treturn result;\n\t}\n\n\tprivate cloneConfig(config: ConfigFileOptions): Mutable<ConfigFileOptions> {\n\t\treturn {\n\t\t\t...config,\n\t\t\t...(config.skillDirs === undefined ? {} : { skillDirs: [...config.skillDirs] }),\n\t\t\t...(config.toolDirs === undefined ? {} : { toolDirs: [...config.toolDirs] }),\n\t\t\t...(config.discoveryCache === undefined\n\t\t\t\t? {}\n\t\t\t\t: { discoveryCache: { ...config.discoveryCache } }),\n\t\t\t...(config.persistence === undefined\n\t\t\t\t? {}\n\t\t\t\t: {\n\t\t\t\t\t\tpersistence: {\n\t\t\t\t\t\t\t...config.persistence,\n\t\t\t\t\t\t\t...(config.persistence.options === undefined\n\t\t\t\t\t\t\t\t? {}\n\t\t\t\t\t\t\t\t: { options: { ...config.persistence.options } }),\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t...(config.features === undefined ? {} : { features: { ...config.features } }),\n\t\t};\n\t}\n\n\t/**\n\t * Applies TRACELATTICE_FEATURES_* environment variable overrides for feature flags.\n\t * Booleans accept 'true'/'false'/'1'/'0' (case-insensitive).\n\t * Invalid reasoningStrategy values are rejected.\n\t *\n\t * @param result - Configuration object to mutate with feature flag overrides\n\t * @private\n\t */\n\tprivate applyFeatureFlagOverrides(result: Mutable<ConfigFileOptions>): void {\n\t\tconst boolMap: Record<string, Exclude<keyof FeatureFlags, 'reasoningStrategy'>> = {\n\t\t\tTRACELATTICE_FEATURES_DAG_EDGES: 'dagEdges',\n\t\t\tTRACELATTICE_FEATURES_CALIBRATION: 'calibration',\n\t\t\tTRACELATTICE_FEATURES_COMPRESSION: 'compression',\n\t\t\tTRACELATTICE_FEATURES_TOOL_INTERLEAVE: 'toolInterleave',\n\t\t\tTRACELATTICE_FEATURES_NEW_THOUGHT_TYPES: 'newThoughtTypes',\n\t\t\tTRACELATTICE_FEATURES_OUTCOME_RECORDING: 'outcomeRecording',\n\t\t};\n\t\tfor (const [envVar, key] of Object.entries(boolMap)) {\n\t\t\tconst raw = process.env[envVar];\n\t\t\tif (raw === undefined) continue;\n\t\t\tconst parsed = this.parseBoolean(raw);\n\t\t\tif (parsed === undefined) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`Invalid boolean value for ${envVar}: \"${raw}\" (expected true/false/1/0). Ignoring.`\n\t\t\t\t);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst features: { -readonly [K in keyof FeatureFlags]?: FeatureFlags[K] } =\n\t\t\t\tresult.features ?? {};\n\t\t\tfeatures[key] = parsed;\n\t\t\tresult.features = features;\n\t\t}\n\n\t\tconst strategyRaw = process.env.TRACELATTICE_FEATURES_REASONING_STRATEGY;\n\t\tif (strategyRaw !== undefined) {\n\t\t\tif (strategyRaw !== 'sequential' && strategyRaw !== 'tot') {\n\t\t\t\tthrow new ConfigurationError(\n\t\t\t\t\t`TRACELATTICE_FEATURES_REASONING_STRATEGY must be one of sequential, tot, got ${strategyRaw}`\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst features: { -readonly [K in keyof FeatureFlags]?: FeatureFlags[K] } =\n\t\t\t\tresult.features ?? {};\n\t\t\tfeatures.reasoningStrategy = strategyRaw;\n\t\t\tresult.features = features;\n\t\t}\n\t}\n\n\t/**\n\t * Parses a boolean from an environment variable string.\n\t * Accepts 'true'/'false'/'1'/'0' case-insensitively.\n\t *\n\t * @param raw - Raw environment variable string\n\t * @returns Parsed boolean, or undefined if the value is invalid\n\t * @private\n\t */\n\tprivate parseBoolean(raw: string): boolean | undefined {\n\t\tconst v = raw.trim().toLowerCase();\n\t\tif (v === 'true' || v === '1') return true;\n\t\tif (v === 'false' || v === '0') return false;\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Parses a configuration file (JSON or YAML).\n\t *\n\t * Detects the file type by extension and uses the appropriate parser.\n\t * Supports `.json`, `.yaml`, and `.yml` file extensions.\n\t *\n\t * @param filePath - Path to the configuration file to parse\n\t * @returns The parsed configuration object\n\t * @throws {Error} If the file cannot be parsed\n\t * @private\n\t */\n\tprivate parseConfig(filePath: string): ConfigFileOptions {\n\t\tconst content = readFileSync(filePath, 'utf-8');\n\t\tconst ext = filePath.split('.').pop()?.toLowerCase();\n\n\t\tconst raw: unknown = ext === 'yaml' || ext === 'yml' ? parseYaml(content) : JSON.parse(content);\n\n\t\treturn v.parse(ConfigFileOptionsSchema, raw) as ConfigFileOptions;\n\t}\n\n\t/**\n\t * Converts file-based configuration to ServerConfig options.\n\t *\n\t * This is a convenience method for extracting the ServerConfig-relevant\n\t * options from a file-based configuration.\n\t *\n\t * @param config - The configuration to convert\n\t * @returns An object with ServerConfig-compatible options\n\t *\n\t * @example\n\t * ```typescript\n\t * const loader = new ConfigLoader();\n\t * const config = loader.load();\n\t * if (config) {\n\t * const serverOpts = loader.toServerConfigOptions(config);\n\t * const serverConfig = new ServerConfig(serverOpts);\n\t * }\n\t * ```\n\t */\n\ttoServerConfigOptions(config: ConfigFileOptions): ServerConfigOptions {\n\t\treturn {\n\t\t\tmaxHistorySize: config.maxHistorySize,\n\t\t\tmaxBranches: config.maxBranches,\n\t\t\tmaxBranchSize: config.maxBranchSize,\n\t\t\tskillDirs: config.skillDirs,\n\t\t\ttoolDirs: config.toolDirs,\n\t\t\tdiscoveryCache: config.discoveryCache,\n\t\t\tpersistence: config.persistence,\n\t\t\tpersistenceBufferSize: config.persistenceBufferSize,\n\t\t\tpersistenceFlushInterval: config.persistenceFlushInterval,\n\t\t\tpersistenceMaxRetries: config.persistenceMaxRetries,\n\t\t\tpersistenceMaxPendingThoughtsPerSession: config.persistenceMaxPendingThoughtsPerSession,\n\t\t\tfeatures: config.features,\n\t\t\ttoolInterleaveTtlMs: config.toolInterleaveTtlMs,\n\t\t\ttoolInterleaveSweepMs: config.toolInterleaveSweepMs,\n\t\t\tmaxSessionsPerOwner: config.maxSessionsPerOwner,\n\t\t};\n\t}\n}\n"],"names":["ConfigFileOptionsSchema","v","ConfigLoader","customPath","configuredPath","process","join","homedir","config","configPath","existsSync","error","console","getErrorMessage","result","undefined","parseEnvironmentInteger","seconds","ttl","Number","ConfigurationError","maxSize","boolMap","envVar","key","Object","raw","parsed","features","strategyRaw","filePath","content","readFileSync","ext","parseYaml","JSON"],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aAAaA,OAAO,WAAW;YAC/B,uBAAuBA,OAAO,qBAAqB;YACnD,0BAA0BA,OAAO,wBAAwB;YACzD,uBAAuBA,OAAO,qBAAqB;YACnD,yCAAyCA,OAAO,uCAAuC;YACvF,UAAUA,OAAO,QAAQ;YACzB,qBAAqBA,OAAO,mBAAmB;YAC/C,uBAAuBA,OAAO,qBAAqB;YACnD,qBAAqBA,OAAO,mBAAmB;QAChD;IACD;AACD"}
|
|
@@ -19,6 +19,16 @@ export interface PersistenceBackend {
|
|
|
19
19
|
loadBranchForSession(sessionId: SessionId, branchId: BranchId): Promise<ThoughtData[] | undefined>;
|
|
20
20
|
listBranchesForSession(sessionId: SessionId): Promise<BranchId[]>;
|
|
21
21
|
listSessions(): Promise<SessionId[]>;
|
|
22
|
+
/**
|
|
23
|
+
* Read every durable session for startup restore from one consistent view.
|
|
24
|
+
*
|
|
25
|
+
* The result contains each session once (ascending id), with its history, branches
|
|
26
|
+
* (ascending branch id), edges and summaries. Implementations must serve the whole call from a
|
|
27
|
+
* single snapshot of storage and must not omit sessions that `listSessions()` reports. This is a
|
|
28
|
+
* required contract, including for custom backends: restore does not probe for it or fall back
|
|
29
|
+
* to the per-item loads, which remain available to other callers.
|
|
30
|
+
*/
|
|
31
|
+
loadAllSessionsForRestore(): Promise<PersistenceRestoreRead>;
|
|
22
32
|
healthy(): Promise<boolean>;
|
|
23
33
|
clearSession(sessionId: SessionId): Promise<void>;
|
|
24
34
|
clearAll(): Promise<void>;
|
|
@@ -28,6 +38,22 @@ export interface PersistenceBackend {
|
|
|
28
38
|
loadSummaries(sessionId: SessionId): Promise<Summary[]>;
|
|
29
39
|
close(): Promise<void>;
|
|
30
40
|
}
|
|
41
|
+
export interface PersistedBranchRecord {
|
|
42
|
+
readonly branchId: BranchId;
|
|
43
|
+
readonly thoughts: readonly ThoughtData[];
|
|
44
|
+
}
|
|
45
|
+
export interface PersistedSessionRecord {
|
|
46
|
+
readonly sessionId: SessionId;
|
|
47
|
+
readonly history: readonly ThoughtData[];
|
|
48
|
+
/** Ascending by branch id (code-point order). Empty when branch persistence is disabled. */
|
|
49
|
+
readonly branches: readonly PersistedBranchRecord[];
|
|
50
|
+
readonly edges: readonly Edge[];
|
|
51
|
+
readonly summaries: readonly Summary[];
|
|
52
|
+
}
|
|
53
|
+
export interface PersistenceRestoreRead {
|
|
54
|
+
/** Unique sessions in ascending id order: the union of history, branch, edge and summary sessions. */
|
|
55
|
+
readonly sessions: readonly PersistedSessionRecord[];
|
|
56
|
+
}
|
|
31
57
|
export interface PersistenceConfig {
|
|
32
58
|
enabled?: boolean;
|
|
33
59
|
backend?: 'file' | 'sqlite' | 'memory';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PersistenceBackend.d.ts","sourceRoot":"","sources":["../../src/contracts/PersistenceBackend.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAC9D,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE/D,MAAM,WAAW,kBAAkB;IAClC,qBAAqB,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjF;;;;;;;OAOG;IACH,uBAAuB,CACtB,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,WAAW,EACpB,eAAe,EAAE,SAAS,GACxB,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,qBAAqB,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;IACpE,oBAAoB,CACnB,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,SAAS,WAAW,EAAE,GAC9B,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Q,CAAC,QAAQ,EAAE,SAAS,sBAAsB,EAAE,CAAC;CACrD;AAED,MAAM,WAAW,iBAAiB;IACjC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,QAAQ,CAAC;IACvC,OAAO,CAAC,EAAE;QACT,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,eAAe,CAAC,EAAE,OAAO,CAAC;KAC1B,CAAC;CACF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read-only view of the persistence write backlog, for readiness reporting.
|
|
3
|
+
*
|
|
4
|
+
* @module contracts/persistence-backlog
|
|
5
|
+
*/
|
|
6
|
+
/** Point-in-time counts describing unflushed or failed persistence work. */
|
|
7
|
+
export interface PersistenceBacklogView {
|
|
8
|
+
/** A global reset failed, so every session is refused admission until a reset succeeds. */
|
|
9
|
+
readonly globalQuarantined: boolean;
|
|
10
|
+
/** Sessions refused admission after a failed reset or eviction barrier. */
|
|
11
|
+
readonly quarantinedSessionCount: number;
|
|
12
|
+
/** Accepted writes that exhausted their retries and wait for an explicit drain. */
|
|
13
|
+
readonly retainedFailureCount: number;
|
|
14
|
+
/** Accepted thought writes not yet acknowledged successful. */
|
|
15
|
+
readonly pendingThoughtCount: number;
|
|
16
|
+
}
|
|
17
|
+
/** Anything that can report its persistence backlog; `null` when persistence is disabled. */
|
|
18
|
+
export interface PersistenceBacklogSource {
|
|
19
|
+
getPersistenceBacklogView(): PersistenceBacklogView | null;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=persistence-backlog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"persistence-backlog.d.ts","sourceRoot":"","sources":["../../src/contracts/persistence-backlog.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,4EAA4E;AAC5E,MAAM,WAAW,sBAAsB;IACtC,2FAA2F;IAC3F,QAAQ,CAAC,iBAAiB,EAAE,OAAO,CAAC;IACpC,2EAA2E;IAC3E,QAAQ,CAAC,uBAAuB,EAAE,MAAM,CAAC;IACzC,mFAAmF;IACnF,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACtC,+DAA+D;IAC/D,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;CACrC;AAED,6FAA6F;AAC7F,MAAM,WAAW,wBAAwB;IACxC,yBAAyB,IAAI,sBAAsB,GAAG,IAAI,CAAC;CAC3D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -12,10 +12,11 @@
|
|
|
12
12
|
* @module HistoryManager
|
|
13
13
|
*/
|
|
14
14
|
import type { IEdgeStore, IMetrics, ISessionLock } from '../contracts/interfaces.js';
|
|
15
|
-
import { type BranchId, type SessionId } from '../contracts/ids.js';
|
|
15
|
+
import { type BranchId, type SessionId, type ThoughtId } from '../contracts/ids.js';
|
|
16
16
|
import type { ISummaryStore } from '../contracts/summary.js';
|
|
17
17
|
import type { Logger } from '../logger/StructuredLogger.js';
|
|
18
18
|
import type { PersistenceBackend } from '../contracts/PersistenceBackend.js';
|
|
19
|
+
import type { PersistenceBacklogView } from '../contracts/persistence-backlog.js';
|
|
19
20
|
import { type DehydrationOptions, type HydratedEntry } from './compression/DehydrationPolicy.js';
|
|
20
21
|
import type { Summary } from './compression/Summary.js';
|
|
21
22
|
import type { HistorySessionSnapshot, IHistoryManager, ThoughtAdmissionContext } from './IHistoryManager.js';
|
|
@@ -41,6 +42,8 @@ export interface HistoryManagerConfig {
|
|
|
41
42
|
persistenceFlushInterval?: number;
|
|
42
43
|
/** Max retries for failed persistence flushes. @default 3 */
|
|
43
44
|
persistenceMaxRetries?: number;
|
|
45
|
+
/** Per-session limit on unacknowledged thought writes, terminal failures included. @default 10000 */
|
|
46
|
+
persistenceMaxPendingThoughtsPerSession?: number;
|
|
44
47
|
persistenceHistorySize?: number;
|
|
45
48
|
persistBranches?: boolean;
|
|
46
49
|
eventEmitter?: PersistenceEventEmitter;
|
|
@@ -149,6 +152,13 @@ export declare class HistoryManager implements IHistoryManager {
|
|
|
149
152
|
* caches tools/skills, trims, branches, emits DAG edges, and buffers for persistence.
|
|
150
153
|
*/
|
|
151
154
|
addThought(thought: ThoughtData, context?: ThoughtAdmissionContext): void;
|
|
155
|
+
/**
|
|
156
|
+
* Pre-mutation admission guard: authorizes, rejects a duplicate thought id, then rejects when
|
|
157
|
+
* the session already holds its limit of unacknowledged persistence writes.
|
|
158
|
+
*
|
|
159
|
+
* @throws {ValidationError} If the thought id already exists in the session.
|
|
160
|
+
* @throws {PersistenceBacklogFullError} If the session persistence backlog is at its limit.
|
|
161
|
+
*/
|
|
152
162
|
assertThoughtIdentityAvailable(thought: ThoughtData): void;
|
|
153
163
|
private _addThoughtWithinOperation;
|
|
154
164
|
private _resolveAdmissionReferences;
|
|
@@ -178,6 +188,8 @@ export declare class HistoryManager implements IHistoryManager {
|
|
|
178
188
|
getBranchIds(sessionId: string): BranchId[];
|
|
179
189
|
/** Returns validation state without creating a session, binding an owner, or updating LRU data. */
|
|
180
190
|
inspectSession(sessionId: string): HistorySessionSnapshot;
|
|
191
|
+
assertSessionAccessible(sessionId: string): void;
|
|
192
|
+
getVerificationTargets(sessionId: string): ReadonlyMap<ThoughtId, ThoughtId>;
|
|
181
193
|
/** @throws {ValidationError} If branchId is empty or already exists. */
|
|
182
194
|
registerBranch(sessionId: string, branchId: BranchId): void;
|
|
183
195
|
branchExists(sessionId: string, branchId: BranchId): boolean;
|
|
@@ -217,5 +229,7 @@ export declare class HistoryManager implements IHistoryManager {
|
|
|
217
229
|
clearLiveStateAfterShutdown(): void;
|
|
218
230
|
/** Number of coordinator-owned thought writes not yet acknowledged successful. */
|
|
219
231
|
getWriteBufferLength(): number;
|
|
232
|
+
/** Persistence backlog counts for readiness probes; `null` when persistence is disabled. */
|
|
233
|
+
getPersistenceBacklogView(): PersistenceBacklogView | null;
|
|
220
234
|
}
|
|
221
235
|
//# sourceMappingURL=HistoryManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HistoryManager.d.ts","sourceRoot":"","sources":["../../src/core/HistoryManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AACrF,OAAO,EAAe,KAAK,QAAQ,EAAE,KAAK,SAAS,
|
|
1
|
+
{"version":3,"file":"HistoryManager.d.ts","sourceRoot":"","sources":["../../src/core/HistoryManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AACrF,OAAO,EAAe,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACjG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAS7D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAC7E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAClF,OAAO,EAEN,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAGxD,OAAO,KAAK,EACX,sBAAsB,EACtB,eAAe,EACf,uBAAuB,EACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAqB,KAAK,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAIzF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM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EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAW7F,iFAAiF;IACpE,2BAA2B,CACvC,SAAS,EAAE,SAAS,EACpB,mBAAmB,CAAC,EAAE,MAAM,IAAI,GAC9B,OAAO,CAAC,IAAI,CAAC;IAchB,iFAAiF;IACpE,QAAQ,CAAC,mBAAmB,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAOtE,iFAAiF;IACpE,uBAAuB,CAAC,mBAAmB,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAO9E,aAAa,IAAI,MAAM,EAAE;IAIzB,eAAe,IAAI,MAAM;IAIhC,OAAO,CAAC,cAAc;IAgCtB,4FAA4F;IAC/E,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;IAiD1C,oBAAoB,IAAI,OAAO;IAI/B,qBAAqB,IAAI,kBAAkB,GAAG,IAAI;IAIzD,sFAAsF;IAC/E,eAAe,CAAC,OAAO,EAAE,uBAAuB,GAAG,IAAI;IAK9D;;;;;;OAMG;IACI,iBAAiB,CAAC,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IAO1D,kGAAkG;IAC3F,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAQhC,4EAA4E;IAC/D,uBAAuB,IAAI,OAAO,CAAC,IAAI,CAAC;IAMrD,sFAAsF;IAC/E,2BAA2B,IAAI,IAAI;IAY1C,kFAAkF;IAC3E,oBAAoB,IAAI,MAAM;IAIrC,4FAA4F;IACrF,yBAAyB,IAAI,sBAAsB,GAAG,IAAI;CAGjE"}
|
|
@@ -81,6 +81,7 @@ class HistoryManager {
|
|
|
81
81
|
bufferSize: config.persistenceBufferSize ?? 100,
|
|
82
82
|
flushInterval: config.persistenceFlushInterval ?? 1000,
|
|
83
83
|
maxRetries: config.persistenceMaxRetries ?? 3,
|
|
84
|
+
maxPendingThoughtsPerSession: config.persistenceMaxPendingThoughtsPerSession ?? 10000,
|
|
84
85
|
durableHistorySize: config.persistenceHistorySize ?? ABSOLUTE_MAX_HISTORY_SIZE,
|
|
85
86
|
persistBranches: config.persistBranches ?? true,
|
|
86
87
|
eventEmitter: this._eventEmitter,
|
|
@@ -273,8 +274,8 @@ class HistoryManager {
|
|
|
273
274
|
assertThoughtIdentityAvailable(thought) {
|
|
274
275
|
const sessionId = asSessionId(thought.session_id);
|
|
275
276
|
this._authorizeExistingSession(sessionId, this._getCurrentOwner());
|
|
276
|
-
if (void 0 === thought.id)
|
|
277
|
-
|
|
277
|
+
if (void 0 !== thought.id && (this._referenceIndex.has(sessionId, thought.id) || this._persistenceBuffer?.hasThoughtIdentity(sessionId, thought.id) === true)) throw new ValidationError('id', `Thought id already exists in session: ${thought.id}`);
|
|
278
|
+
this._persistenceBuffer?.assertThoughtBacklogAvailable(sessionId);
|
|
278
279
|
}
|
|
279
280
|
_addThoughtWithinOperation(sessionId, thought, context) {
|
|
280
281
|
this._persistenceBuffer?.assertSessionAdmissionOpen(sessionId);
|
|
@@ -465,6 +466,12 @@ class HistoryManager {
|
|
|
465
466
|
]
|
|
466
467
|
};
|
|
467
468
|
}
|
|
469
|
+
assertSessionAccessible(sessionId) {
|
|
470
|
+
this._authorizeExistingSession(asSessionId(sessionId), this._getCurrentOwner());
|
|
471
|
+
}
|
|
472
|
+
getVerificationTargets(sessionId) {
|
|
473
|
+
return this._getSession(sessionId, this._getCurrentOwner()).verificationTargets;
|
|
474
|
+
}
|
|
468
475
|
registerBranch(sessionId, branchId) {
|
|
469
476
|
this._authorizeExistingSession(asSessionId(sessionId), this._getCurrentOwner());
|
|
470
477
|
if ('string' != typeof branchId || 0 === branchId.length) throw new ValidationError('branch_id', 'branch_id must be a non-empty string');
|
|
@@ -632,6 +639,9 @@ class HistoryManager {
|
|
|
632
639
|
getWriteBufferLength() {
|
|
633
640
|
return this._persistenceBuffer?.pendingThoughtCount ?? 0;
|
|
634
641
|
}
|
|
642
|
+
getPersistenceBacklogView() {
|
|
643
|
+
return this._persistenceBuffer?.getBacklogView() ?? null;
|
|
644
|
+
}
|
|
635
645
|
}
|
|
636
646
|
export { ABSOLUTE_MAX_HISTORY_SIZE, HistoryManager };
|
|
637
647
|
|