Abstract Class: DiscoveryOrchestrator<TRecord, TState>
Makaio Framework / ai-adapters-core/node / DiscoveryOrchestrator
Abstract Class: DiscoveryOrchestrator<TRecord, TState>
Section titled “Abstract Class: DiscoveryOrchestrator<TRecord, TState>”Defined in: ../../../adapters/core/src/log-importer/discovery-orchestrator.ts:46
Abstract discovery orchestrator for shallow session discovery.
Overrides handleFileChange to call importer.extractDiscoveryMetadata(filePath)
directly, bypassing the parseFile → validateRecords → extractSessionContext pipeline.
Emits only adapter.session.discovered and saves a stub cursor (bytesRead: 0)
so the full import starts from byte 0 when the user triggers lazy-load pick-up.
For files that have already been imported, the orchestrator delegates 'modified'
events to the base class for incremental processing and manages the
'imported' ↔ 'tracking' status lifecycle.
BaseLogOrchestrator - Parent class with full import behavior
Extends
Section titled “Extends”BaseLogOrchestrator<TRecord,TState>
Type Parameters
Section titled “Type Parameters”TRecord
Section titled “TRecord”TRecord
The adapter’s native log record type
TState
Section titled “TState”TState = unknown
The adapter’s resumable state type (default: unknown)
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”
protectednew DiscoveryOrchestrator<TRecord,TState>(config,importer):DiscoveryOrchestrator<TRecord,TState>
Defined in: ../../../adapters/core/src/log-importer/discovery-orchestrator.ts:69
Parameters
Section titled “Parameters”config
Section titled “config”importer
Section titled “importer”LogImporter<TRecord, TState>
Returns
Section titled “Returns”DiscoveryOrchestrator<TRecord, TState>
Overrides
Section titled “Overrides”BaseLogOrchestrator.constructor
Properties
Section titled “Properties”config
Section titled “config”
protectedreadonlyconfig:Required<Omit<LogOrchestratorConfig,"directory"|"checkMakaioManaged">> &object
Defined in: ../../../adapters/core/src/log-importer/base-orchestrator.ts:42
Type Declaration
Section titled “Type Declaration”checkMakaioManaged?
Section titled “checkMakaioManaged?”
optionalcheckMakaioManaged?: (sessionId) =>Promise<boolean>
Parameters
Section titled “Parameters”sessionId
Section titled “sessionId”string
Returns
Section titled “Returns”Promise<boolean>
directory?
Section titled “directory?”
optionaldirectory?:string
Inherited from
Section titled “Inherited from”eventQueue
Section titled “eventQueue”
protectedreadonlyeventQueue:LogImportEventQueue
Defined in: ../../../adapters/core/src/log-importer/base-orchestrator.ts:48
Inherited from
Section titled “Inherited from”BaseLogOrchestrator.eventQueue
importer
Section titled “importer”
protectedreadonlyimporter:LogImporter<TRecord,TState>
Defined in: ../../../adapters/core/src/log-importer/base-orchestrator.ts:54
Importer instance - subclasses create and manage their own typed instance.
Inherited from
Section titled “Inherited from”lastSeenMtimeMs
Section titled “lastSeenMtimeMs”
protectedreadonlylastSeenMtimeMs:Map<string,number>
Defined in: ../../../adapters/core/src/log-importer/discovery-orchestrator.ts:64
Last observed mtime (ms) per tracked file path.
Used by the polled handler to detect inactivity without re-reading disk.
logPrefix
Section titled “logPrefix”
abstractprotectedreadonlylogPrefix:string
Defined in: ../../../adapters/core/src/log-importer/base-orchestrator.ts:51
Log prefix for console output - set by subclass
Inherited from
Section titled “Inherited from”trackingFilePaths
Section titled “trackingFilePaths”
protectedreadonlytrackingFilePaths:Set<string>
Defined in: ../../../adapters/core/src/log-importer/discovery-orchestrator.ts:51
Paths of files whose adapter sessions are currently in 'tracking' status.
Maintained locally to avoid per-poll DB lookups.
trackingInactiveCount
Section titled “trackingInactiveCount”
protectedreadonlytrackingInactiveCount:Map<string,number>
Defined in: ../../../adapters/core/src/log-importer/discovery-orchestrator.ts:58
Per-file count of consecutive poll cycles with no mtime change while in
'tracking' status. Reset on each 'modified' event; incremented by the
polled handler when mtime is unchanged.
watcher
Section titled “watcher”
protectedreadonlywatcher:LogImportWatcher
Defined in: ../../../adapters/core/src/log-importer/base-orchestrator.ts:47
Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”buildCursorSessionContext()
Section titled “buildCursorSessionContext()”
protectedbuildCursorSessionContext(context):object&object
Defined in: ../../../adapters/core/src/log-importer/base-orchestrator.ts:147
Builds the serialized session context for cursor persistence.
Parameters
Section titled “Parameters”context
Section titled “context”LogImportSessionContext<TState>
The import session context to serialize.
Returns
Section titled “Returns”Serialized cursor session context.
Inherited from
Section titled “Inherited from”BaseLogOrchestrator.buildCursorSessionContext
clearTrackingState()
Section titled “clearTrackingState()”
protectedclearTrackingState(filePath):void
Defined in: ../../../adapters/core/src/log-importer/discovery-orchestrator.ts:77
Clear all in-memory tracking collections for a single file path.
Parameters
Section titled “Parameters”filePath
Section titled “filePath”string
File path to remove from local tracking state
Returns
Section titled “Returns”void
dispose()
Section titled “dispose()”dispose():
Promise<void>
Defined in: ../../../adapters/core/src/log-importer/discovery-orchestrator.ts:136
Returns
Section titled “Returns”Promise<void>
Overrides
Section titled “Overrides”getLogFilePattern()
Section titled “getLogFilePattern()”
abstractprotectedgetLogFilePattern():string
Defined in: ../../../adapters/core/src/log-importer/base-orchestrator.ts:98
Get the glob pattern for log files to watch.
Returns
Section titled “Returns”string
Inherited from
Section titled “Inherited from”BaseLogOrchestrator.getLogFilePattern
getMaxRecords()
Section titled “getMaxRecords()”
protectedgetMaxRecords():number|undefined
Defined in: ../../../adapters/core/src/log-importer/base-orchestrator.ts:138
Returns the maximum number of records to parse per file. Override in subclasses to limit parsing (e.g., discovery mode).
Returns
Section titled “Returns”number | undefined
Maximum record count, or undefined for no limit.
Inherited from
Section titled “Inherited from”BaseLogOrchestrator.getMaxRecords
handleFileChange()
Section titled “handleFileChange()”
protectedhandleFileChange(event):Promise<void>
Defined in: ../../../adapters/core/src/log-importer/discovery-orchestrator.ts:161
Simplified file change handler for discovery mode.
Dispatches to two paths:
- No cursor exists → lightweight discovery (emit
adapter.session.discovered, write stub cursor). - Cursor exists +
changeType === 'modified'+ session status is'imported'or'tracking'→ delegate to base class for incremental import, then transition status to'tracking'if it was'imported'.
All other cases (e.g., cursor exists but status is 'discovered', or
changeType is not 'modified') are silently skipped.
Parameters
Section titled “Parameters”File change event from the watcher
Returns
Section titled “Returns”Promise<void>
Overrides
Section titled “Overrides”BaseLogOrchestrator.handleFileChange
handleFirstRead()
Section titled “handleFirstRead()”
protectedhandleFirstRead(filePath,records,bytesRead,mtime,isJsonFormat,startOffset,emitLifecycleEvents?):Promise<void>
Defined in: ../../../adapters/core/src/log-importer/base-orchestrator.ts:351
Handle the first read of a log file.
Extracts session context, emits session lifecycle events, processes records, and saves the cursor. Subclasses may override to change behavior (e.g., DiscoveryOrchestrator skips message processing).
Parameters
Section titled “Parameters”filePath
Section titled “filePath”string
Path to the log file
records
Section titled “records”TRecord[]
Records parsed from the file
bytesRead
Section titled “bytesRead”number
Bytes read during this parse
Date
File modification time
isJsonFormat
Section titled “isJsonFormat”boolean
Whether the file uses JSON (mtime-based) format
startOffset
Section titled “startOffset”number
Byte offset this read started from
emitLifecycleEvents?
Section titled “emitLifecycleEvents?”boolean = true
Whether to emit session and started lifecycle events for this pass
Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”BaseLogOrchestrator.handleFirstRead
handleIncrementalRead()
Section titled “handleIncrementalRead()”
protectedhandleIncrementalRead(filePath,records,cursorContext,bytesRead,mtime,isJsonFormat,startOffset):Promise<void>
Defined in: ../../../adapters/core/src/log-importer/base-orchestrator.ts:418
Handle an incremental read of a log file.
Processes new records since the last cursor position. Subclasses may override to skip incremental processing (e.g., DiscoveryOrchestrator).
Parameters
Section titled “Parameters”filePath
Section titled “filePath”string
Path to the log file
records
Section titled “records”TRecord[]
New records since last read
cursorContext
Section titled “cursorContext”object & object
Existing cursor session context
bytesRead
Section titled “bytesRead”number
Bytes read during this parse
Date
File modification time
isJsonFormat
Section titled “isJsonFormat”boolean
Whether the file uses JSON (mtime-based) format
startOffset
Section titled “startOffset”number
Byte offset this read started from
Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”BaseLogOrchestrator.handleIncrementalRead
isEnabled()
Section titled “isEnabled()”isEnabled():
boolean
Defined in: ../../../adapters/core/src/log-importer/base-orchestrator.ts:173
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”isRunning()
Section titled “isRunning()”isRunning():
boolean
Defined in: ../../../adapters/core/src/log-importer/base-orchestrator.ts:177
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”isSessionSkipped()
Section titled “isSessionSkipped()”
protectedisSessionSkipped(adapterSessionId):Promise<boolean>
Defined in: ../../../adapters/core/src/log-importer/base-orchestrator.ts:514
Determine whether an adapter session should be skipped from import.
Delegates to the managed-session cache so concurrent checks for the same
adapterSessionId share one storage lookup and tracked skips update stats.
Parameters
Section titled “Parameters”adapterSessionId
Section titled “adapterSessionId”string
External adapter session ID being evaluated
Returns
Section titled “Returns”Promise<boolean>
Promise resolving to true when the session is Makaio-managed and should be skipped
Inherited from
Section titled “Inherited from”BaseLogOrchestrator.isSessionSkipped
maybeUpdateCursor()
Section titled “maybeUpdateCursor()”
protectedmaybeUpdateCursor(filePath,bytesRead,startOffset,mtime,isJsonFormat,sessionContext?):Promise<void>
Defined in: ../../../adapters/core/src/log-importer/base-orchestrator.ts:493
Parameters
Section titled “Parameters”filePath
Section titled “filePath”string
bytesRead
Section titled “bytesRead”number
startOffset
Section titled “startOffset”number
Date
isJsonFormat
Section titled “isJsonFormat”boolean
sessionContext?
Section titled “sessionContext?”object & object
Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”BaseLogOrchestrator.maybeUpdateCursor
onPollCycle()
Section titled “onPollCycle()”
protectedonPollCycle(trackedFilePaths):Promise<void>
Defined in: ../../../adapters/core/src/log-importer/discovery-orchestrator.ts:338
React to a completed poll cycle for inactivity-based tracking → imported transitions.
For each file in trackingFilePaths, checks if the watcher’s last-known mtime
matches our stored lastSeenMtimeMs. If unchanged, increments the inactive
counter. When the counter reaches the tracking inactivity threshold, the
adapter session reverts to 'imported' and the file is removed from tracking.
Parameters
Section titled “Parameters”trackedFilePaths
Section titled “trackedFilePaths”ReadonlySet<string>
All file paths observed by the watcher in this cycle
Returns
Section titled “Returns”Promise<void>
parseFile()
Section titled “parseFile()”
abstractprotectedparseFile(filePath,startOffset,maxRecords?):Promise<ParseFileResult<TRecord>>
Defined in: ../../../adapters/core/src/log-importer/base-orchestrator.ts:118
Parse a log file from the given byte offset.
Parameters
Section titled “Parameters”filePath
Section titled “filePath”string
Path to the log file
startOffset
Section titled “startOffset”number
Byte offset to start reading from
maxRecords?
Section titled “maxRecords?”number
Optional maximum number of records to return (for shallow discovery)
Returns
Section titled “Returns”Promise<ParseFileResult<TRecord>>
Inherited from
Section titled “Inherited from”persistImportedStatus()
Section titled “persistImportedStatus()”
protectedpersistImportedStatus(filePath):Promise<boolean>
Defined in: ../../../adapters/core/src/log-importer/discovery-orchestrator.ts:88
Persist the steady-state imported status for a tracked file.
Parameters
Section titled “Parameters”filePath
Section titled “filePath”string
Absolute path to the tracked log file
Returns
Section titled “Returns”Promise<boolean>
true when the file can be removed from local tracking state
queueCursorUpdate()
Section titled “queueCursorUpdate()”
protectedqueueCursorUpdate(filePath,bytesRead,startOffset,mtime,isJsonFormat,sessionContext?,precedingEventPromises?):Promise<void>
Defined in: ../../../adapters/core/src/log-importer/base-orchestrator.ts:549
Enqueue a cursor write as a PQueue task so it executes after all previously queued events for the same batch have been emitted.
PQueue runs tasks with concurrency=1 in FIFO order, so placing the cursor
write at the back of the queue after all queueEvent calls guarantees that
the cursor advances only once every preceding event in the batch has been
delivered. This prevents the race where a process exit after queueEvent
but before queue drain would leave events lost yet the cursor advanced.
Parameters
Section titled “Parameters”filePath
Section titled “filePath”string
Path to the log file
bytesRead
Section titled “bytesRead”number
Total bytes read at the new cursor position
startOffset
Section titled “startOffset”number
Byte offset this read started from
Date
File modification time
isJsonFormat
Section titled “isJsonFormat”boolean
Whether the file uses JSON (mtime-based) format
sessionContext?
Section titled “sessionContext?”object & object
Serialized session context for the cursor
precedingEventPromises?
Section titled “precedingEventPromises?”Promise<void>[] = []
Emission promises queued before this cursor write
Returns
Section titled “Returns”Promise<void>
Promise that resolves when the cursor write has completed
Inherited from
Section titled “Inherited from”BaseLogOrchestrator.queueCursorUpdate
queueEvent()
Section titled “queueEvent()”
protectedqueueEvent(event):Promise<void>
Defined in: ../../../adapters/core/src/log-importer/base-orchestrator.ts:527
Queue a normalized event and return its delivery promise.
Parameters
Section titled “Parameters”Normalized event to emit
Returns
Section titled “Returns”Promise<void>
Promise that resolves after delivery or rejects on emit failure
Inherited from
Section titled “Inherited from”BaseLogOrchestrator.queueEvent
restorePersistedTrackingState()
Section titled “restorePersistedTrackingState()”
protectedrestorePersistedTrackingState():Promise<void>
Defined in: ../../../adapters/core/src/log-importer/discovery-orchestrator.ts:193
Rehydrate tracking file state from persisted adapter-session rows after startup.
The watcher state is process-local, but adapter-session status is persisted.
Without this rehydration, a restart can strand sessions in 'tracking' forever
because no in-memory file state exists to drive the inactivity timeout.
Returns
Section titled “Returns”Promise<void>
shouldSkipFile()
Section titled “shouldSkipFile()”
protectedshouldSkipFile(_filePath):boolean
Defined in: ../../../adapters/core/src/log-importer/base-orchestrator.ts:108
Determine whether a discovered file should be skipped before processing.
Default implementation never skips. Subclasses may override to exclude files by name (e.g., ephemeral compaction summary files).
Parameters
Section titled “Parameters”_filePath
Section titled “_filePath”string
Absolute path to the candidate file
Returns
Section titled “Returns”boolean
true to skip the file entirely, false to process normally
Inherited from
Section titled “Inherited from”BaseLogOrchestrator.shouldSkipFile
start()
Section titled “start()”start():
Promise<void>
Defined in: ../../../adapters/core/src/log-importer/discovery-orchestrator.ts:113
Returns
Section titled “Returns”Promise<void>
Overrides
Section titled “Overrides”stop()
Section titled “stop()”stop():
Promise<void>
Defined in: ../../../adapters/core/src/log-importer/discovery-orchestrator.ts:130
Returns
Section titled “Returns”Promise<void>
Overrides
Section titled “Overrides”trackFileChange()
Section titled “trackFileChange()”
protectedtrackFileChange(event):void
Defined in: ../../../adapters/core/src/log-importer/base-orchestrator.ts:327
Track a watcher-triggered file import so shutdown can wait for any cursor work that the handler enqueues before draining the shared FIFO queue.
Parameters
Section titled “Parameters”File change event to process
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”BaseLogOrchestrator.trackFileChange
trackImportedSession()
Section titled “trackImportedSession()”
protectedtrackImportedSession(adapterSessionId):void
Defined in: ../../../adapters/core/src/log-importer/base-orchestrator.ts:401
Record that a session has been imported, updating import statistics.
Protected to allow subclasses to update stats when processing additional sessions (e.g., compress child sessions from compacted files).
Parameters
Section titled “Parameters”adapterSessionId
Section titled “adapterSessionId”string
The session ID that was imported
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”BaseLogOrchestrator.trackImportedSession
updateCursor()
Section titled “updateCursor()”
protectedupdateCursor(filePath,bytesRead,mtime,sessionContext?):Promise<void>
Defined in: ../../../adapters/core/src/log-importer/base-orchestrator.ts:251
Parameters
Section titled “Parameters”filePath
Section titled “filePath”string
bytesRead
Section titled “bytesRead”number
Date
sessionContext?
Section titled “sessionContext?”object & object
Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”BaseLogOrchestrator.updateCursor
usesJsonFormat()
Section titled “usesJsonFormat()”
protectedusesJsonFormat():boolean
Defined in: ../../../adapters/core/src/log-importer/base-orchestrator.ts:164
Check if this orchestrator uses JSON format (mtime-based cursor).
Returns
Section titled “Returns”boolean
True if JSON format, false for JSONL
Inherited from
Section titled “Inherited from”BaseLogOrchestrator.usesJsonFormat
validateRecords()
Section titled “validateRecords()”
protectedvalidateRecords(records):TRecord[]
Defined in: ../../../adapters/core/src/log-importer/base-orchestrator.ts:129
Validate and filter parsed records. Default: returns records as-is.
Parameters
Section titled “Parameters”records
Section titled “records”TRecord[]
Raw parsed records
Returns
Section titled “Returns”TRecord[]
Validated/filtered records
Inherited from
Section titled “Inherited from”BaseLogOrchestrator.validateRecords
createDefaultCheckMakaioManaged()
Section titled “createDefaultCheckMakaioManaged()”
staticcreateDefaultCheckMakaioManaged(): (sessionId) =>Promise<boolean>
Defined in: ../../../adapters/core/src/log-importer/base-orchestrator.ts:243
Returns
Section titled “Returns”Function that checks if a session is Makaio-managed.
(sessionId) => Promise<boolean>