byterover-cli 1.2.1 → 1.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.
Files changed (147) hide show
  1. package/README.md +76 -8
  2. package/dist/constants.d.ts +0 -5
  3. package/dist/constants.js +0 -5
  4. package/dist/core/domain/cipher/agent/agent-info.d.ts +17 -17
  5. package/dist/core/domain/cipher/errors/file-system-error.d.ts +11 -0
  6. package/dist/core/domain/cipher/errors/file-system-error.js +17 -0
  7. package/dist/core/domain/cipher/file-system/types.d.ts +40 -6
  8. package/dist/core/domain/cipher/llm/schemas.d.ts +14 -14
  9. package/dist/core/domain/cipher/session/session-metadata.d.ts +2 -2
  10. package/dist/core/domain/entities/agent.d.ts +1 -1
  11. package/dist/core/domain/entities/agent.js +11 -6
  12. package/dist/core/domain/entities/connector-type.d.ts +2 -1
  13. package/dist/core/domain/entities/connector-type.js +2 -1
  14. package/dist/core/domain/transport/schemas.d.ts +66 -66
  15. package/dist/core/interfaces/cipher/cipher-services.d.ts +0 -3
  16. package/dist/core/interfaces/cipher/index.d.ts +0 -2
  17. package/dist/core/interfaces/connectors/i-connector.d.ts +2 -2
  18. package/dist/core/interfaces/i-file-service.d.ts +7 -0
  19. package/dist/infra/auth/oauth-service.d.ts +15 -0
  20. package/dist/infra/auth/oauth-service.js +38 -2
  21. package/dist/infra/cipher/agent/agent-schemas.d.ts +42 -42
  22. package/dist/infra/cipher/file-system/binary-utils.d.ts +15 -2
  23. package/dist/infra/cipher/file-system/binary-utils.js +26 -3
  24. package/dist/infra/cipher/file-system/file-system-service.d.ts +9 -0
  25. package/dist/infra/cipher/file-system/file-system-service.js +91 -8
  26. package/dist/infra/cipher/file-system/pdf-extractor.d.ts +100 -0
  27. package/dist/infra/cipher/file-system/pdf-extractor.js +226 -0
  28. package/dist/infra/cipher/llm/context/context-manager.js +7 -9
  29. package/dist/infra/cipher/llm/internal-llm-service.d.ts +5 -1
  30. package/dist/infra/cipher/llm/internal-llm-service.js +57 -46
  31. package/dist/infra/cipher/system-prompt/contributor-schemas.d.ts +8 -8
  32. package/dist/infra/cipher/system-prompt/schemas.d.ts +5 -5
  33. package/dist/infra/cipher/tools/implementations/read-file-tool.js +24 -4
  34. package/dist/infra/connectors/connector-manager.js +2 -0
  35. package/dist/infra/connectors/hook/hook-connector.d.ts +1 -1
  36. package/dist/infra/connectors/hook/hook-connector.js +3 -3
  37. package/dist/infra/connectors/mcp/mcp-connector.d.ts +1 -1
  38. package/dist/infra/connectors/mcp/mcp-connector.js +4 -4
  39. package/dist/infra/connectors/rules/rules-connector-config.d.ts +4 -0
  40. package/dist/infra/connectors/rules/rules-connector-config.js +4 -0
  41. package/dist/infra/connectors/rules/rules-connector.d.ts +1 -1
  42. package/dist/infra/connectors/rules/rules-connector.js +4 -4
  43. package/dist/infra/connectors/shared/template-service.js +4 -0
  44. package/dist/infra/connectors/skill/index.d.ts +1 -0
  45. package/dist/infra/connectors/skill/index.js +1 -0
  46. package/dist/infra/connectors/skill/skill-connector-config.d.ts +45 -0
  47. package/dist/infra/connectors/skill/skill-connector-config.js +26 -0
  48. package/dist/infra/connectors/skill/skill-connector.d.ts +39 -0
  49. package/dist/infra/connectors/skill/skill-connector.js +160 -0
  50. package/dist/infra/connectors/skill/skill-content-loader.d.ts +18 -0
  51. package/dist/infra/connectors/skill/skill-content-loader.js +33 -0
  52. package/dist/infra/file/fs-file-service.d.ts +7 -0
  53. package/dist/infra/file/fs-file-service.js +15 -1
  54. package/dist/infra/mcp/tools/brv-curate-tool.d.ts +10 -4
  55. package/dist/infra/mcp/tools/brv-curate-tool.js +9 -4
  56. package/dist/infra/mcp/tools/task-result-waiter.js +8 -0
  57. package/dist/infra/process/agent-worker.js +30 -14
  58. package/dist/infra/process/task-queue-manager.d.ts +23 -34
  59. package/dist/infra/process/task-queue-manager.js +57 -118
  60. package/dist/infra/process/transport-handlers.js +1 -7
  61. package/dist/infra/repl/commands/connectors-command.js +1 -1
  62. package/dist/infra/repl/commands/space/switch-command.js +0 -2
  63. package/dist/infra/usecase/connectors-use-case.js +8 -2
  64. package/dist/infra/usecase/curate-use-case.js +10 -4
  65. package/dist/infra/usecase/init-use-case.js +1 -1
  66. package/dist/infra/usecase/reset-use-case.d.ts +1 -0
  67. package/dist/infra/usecase/reset-use-case.js +4 -1
  68. package/dist/infra/usecase/space-switch-use-case.d.ts +0 -10
  69. package/dist/infra/usecase/space-switch-use-case.js +7 -37
  70. package/dist/{commands → oclif/commands}/curate.d.ts +1 -1
  71. package/dist/{commands → oclif/commands}/curate.js +6 -6
  72. package/dist/{commands → oclif/commands}/hook-prompt-submit.d.ts +1 -1
  73. package/dist/{commands → oclif/commands}/hook-prompt-submit.js +3 -3
  74. package/dist/{commands → oclif/commands}/main.js +10 -10
  75. package/dist/{commands → oclif/commands}/mcp.js +2 -2
  76. package/dist/{commands → oclif/commands}/query.d.ts +1 -1
  77. package/dist/{commands → oclif/commands}/query.js +6 -6
  78. package/dist/{commands → oclif/commands}/status.d.ts +1 -1
  79. package/dist/{commands → oclif/commands}/status.js +8 -8
  80. package/dist/oclif/constants.d.ts +11 -0
  81. package/dist/oclif/constants.js +11 -0
  82. package/dist/{hooks → oclif/hooks}/init/welcome.js +4 -17
  83. package/dist/{hooks → oclif/hooks}/prerun/validate-brv-config-version.d.ts +1 -1
  84. package/dist/{hooks → oclif/hooks}/prerun/validate-brv-config-version.js +2 -2
  85. package/dist/resources/prompts/curate.yml +1 -0
  86. package/dist/resources/tools/read_file.txt +5 -2
  87. package/dist/templates/skill/SKILL.md +91 -0
  88. package/dist/templates/skill/TROUBLESHOOTING.md +50 -0
  89. package/dist/templates/skill/WORKFLOWS.md +229 -0
  90. package/dist/utils/file-validator.js +8 -4
  91. package/dist/utils/type-guards.d.ts +11 -0
  92. package/dist/utils/type-guards.js +13 -0
  93. package/oclif.manifest.json +7 -53
  94. package/package.json +12 -10
  95. package/dist/commands/watch.d.ts +0 -25
  96. package/dist/commands/watch.js +0 -175
  97. package/dist/core/interfaces/cipher/i-coding-agent-log-parser.d.ts +0 -20
  98. package/dist/core/interfaces/cipher/i-coding-agent-log-parser.js +0 -1
  99. package/dist/core/interfaces/cipher/i-coding-agent-log-watcher.d.ts +0 -31
  100. package/dist/core/interfaces/cipher/i-coding-agent-log-watcher.js +0 -1
  101. package/dist/core/interfaces/i-file-watcher-service.d.ts +0 -41
  102. package/dist/core/interfaces/i-file-watcher-service.js +0 -1
  103. package/dist/core/interfaces/parser/i-clean-parser-service.d.ts +0 -18
  104. package/dist/core/interfaces/parser/i-clean-parser-service.js +0 -1
  105. package/dist/core/interfaces/parser/i-raw-parser-service.d.ts +0 -17
  106. package/dist/core/interfaces/parser/i-raw-parser-service.js +0 -1
  107. package/dist/core/interfaces/parser/i-session-normalizer.d.ts +0 -56
  108. package/dist/core/interfaces/parser/i-session-normalizer.js +0 -1
  109. package/dist/infra/cipher/parsers/coding-agent-log-parser.d.ts +0 -24
  110. package/dist/infra/cipher/parsers/coding-agent-log-parser.js +0 -51
  111. package/dist/infra/cipher/watcher/coding-agent-log-watcher.d.ts +0 -14
  112. package/dist/infra/cipher/watcher/coding-agent-log-watcher.js +0 -55
  113. package/dist/infra/parsers/clean/clean-claude-service.d.ts +0 -111
  114. package/dist/infra/parsers/clean/clean-claude-service.js +0 -271
  115. package/dist/infra/parsers/clean/clean-codex-service.d.ts +0 -231
  116. package/dist/infra/parsers/clean/clean-codex-service.js +0 -534
  117. package/dist/infra/parsers/clean/clean-copilot-service.d.ts +0 -255
  118. package/dist/infra/parsers/clean/clean-copilot-service.js +0 -729
  119. package/dist/infra/parsers/clean/clean-cursor-service.d.ts +0 -161
  120. package/dist/infra/parsers/clean/clean-cursor-service.js +0 -432
  121. package/dist/infra/parsers/clean/clean-parser-service-factory.d.ts +0 -54
  122. package/dist/infra/parsers/clean/clean-parser-service-factory.js +0 -80
  123. package/dist/infra/parsers/clean/shared.d.ts +0 -84
  124. package/dist/infra/parsers/clean/shared.js +0 -273
  125. package/dist/infra/parsers/raw/raw-claude-service.d.ts +0 -195
  126. package/dist/infra/parsers/raw/raw-claude-service.js +0 -548
  127. package/dist/infra/parsers/raw/raw-codex-service.d.ts +0 -313
  128. package/dist/infra/parsers/raw/raw-codex-service.js +0 -782
  129. package/dist/infra/parsers/raw/raw-copilot-service.d.ts +0 -196
  130. package/dist/infra/parsers/raw/raw-copilot-service.js +0 -558
  131. package/dist/infra/parsers/raw/raw-cursor-service.d.ts +0 -316
  132. package/dist/infra/parsers/raw/raw-cursor-service.js +0 -818
  133. package/dist/infra/parsers/raw/raw-parser-service-factory.d.ts +0 -54
  134. package/dist/infra/parsers/raw/raw-parser-service-factory.js +0 -81
  135. package/dist/infra/process/constants.d.ts +0 -1
  136. package/dist/infra/process/constants.js +0 -1
  137. package/dist/infra/watcher/file-watcher-service.d.ts +0 -10
  138. package/dist/infra/watcher/file-watcher-service.js +0 -81
  139. /package/dist/{commands → oclif/commands}/main.d.ts +0 -0
  140. /package/dist/{commands → oclif/commands}/mcp.d.ts +0 -0
  141. /package/dist/{hooks → oclif/hooks}/command_not_found/handle-invalid-commands.d.ts +0 -0
  142. /package/dist/{hooks → oclif/hooks}/command_not_found/handle-invalid-commands.js +0 -0
  143. /package/dist/{hooks → oclif/hooks}/error/clean-errors.d.ts +0 -0
  144. /package/dist/{hooks → oclif/hooks}/error/clean-errors.js +0 -0
  145. /package/dist/{hooks → oclif/hooks}/init/update-notifier.d.ts +0 -0
  146. /package/dist/{hooks → oclif/hooks}/init/update-notifier.js +0 -0
  147. /package/dist/{hooks → oclif/hooks}/init/welcome.d.ts +0 -0
@@ -1,20 +0,0 @@
1
- import type { CleanSession } from '../../domain/entities/parser.js';
2
- import { Agent } from '../../domain/entities/agent.js';
3
- /**
4
- * Interface for parsing coding agent log files.
5
- * Implementations use the raw/clean parser pipeline to process log files
6
- * from various coding agents (Claude Code, GitHub Copilot, Cursor, Codex, etc.).
7
- */
8
- export interface ICodingAgentLogParser {
9
- /**
10
- * Parses coding agent log files using the configured IDE and chat log path.
11
- *
12
- * This method follows the two-phase raw/clean parser pipeline:
13
- * 1. Raw Phase: Parse IDE-specific files, write to .brv/logs/{ide}/raw/
14
- * 2. Clean Phase: Read from .brv/logs/{ide}/raw/, normalize to CleanSession format
15
- *
16
- * @returns A promise that resolves to a frozen array of CleanSession objects
17
- * @throws Error if parsing fails at any phase
18
- */
19
- parse: (chatLogPath: string, ide: Agent) => Promise<readonly CleanSession[]>;
20
- }
@@ -1,31 +0,0 @@
1
- import type { CleanSession } from '../../domain/entities/parser.js';
2
- import { Agent } from '../../domain/entities/agent.js';
3
- /** Options for starting the coding agent log watcher. */
4
- export type CodingAgentLogWatcherOptions = {
5
- codingAgentInfo: {
6
- chatLogPath: string;
7
- name: Agent;
8
- };
9
- /** Callback invoked when sessions are parsed from log files */
10
- onCleanSession: (cleanSession: CleanSession) => Promise<void>;
11
- };
12
- /**
13
- * Interface for watching coding agent log files and processing sessions.
14
- * Implementations should handle the first watch (process existing files) differently from subsequent watches (only new/changed files).
15
- */
16
- export interface ICodingAgentLogWatcher {
17
- /**
18
- * Checks if the watcher is currently active.
19
- * @returns true if watching, false otherwise.
20
- */
21
- isWatching: () => boolean;
22
- /**
23
- * Starts watching the specified paths for coding agent log files.
24
- * On initial start, processes existing files. Subsequent watches only process new or changed files.
25
- * @param options Configuration options including paths and callback
26
- * @throws Error if already watching or if paths are invalid
27
- */
28
- start: (options: CodingAgentLogWatcherOptions) => Promise<void>;
29
- /** Stops watching for file changes and cleans up resources */
30
- stop: () => Promise<void>;
31
- }
@@ -1,41 +0,0 @@
1
- /**
2
- * Represents a file system event.
3
- */
4
- export type FileEvent = {
5
- /**
6
- * The path to the file or directory that changed.
7
- */
8
- path: string;
9
- /**
10
- * The type of event that occurred.
11
- * - add: File added
12
- * - addDir: Directory added
13
- * - change: File modified
14
- * - unlink: File deleted
15
- * - unlinkDir: Directory deleted
16
- */
17
- type: 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir';
18
- };
19
- /**
20
- * Interface for a file watcher service that monitors file system changes.
21
- */
22
- export interface IFileWatcherService {
23
- /**
24
- * Sets the handler to be called when file system events occur.
25
- * Only one handler can be registered at a time.
26
- * The handler is async to support file reading and processing.
27
- * @param handler The async callback function to invoke with file events.
28
- */
29
- setFileEventHandler: (handler: (event: FileEvent) => Promise<void>) => void;
30
- /**
31
- * Starts watching the specified paths for file system changes.
32
- * @param paths Array of directory paths to watch.
33
- * @returns Promise that resolves when watching has started.
34
- */
35
- start: (paths: string[]) => Promise<void>;
36
- /**
37
- * Stops watching and cleans up resources.
38
- * @returns Promise that resolves when cleanup is complete.
39
- */
40
- stop: () => Promise<void>;
41
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,18 +0,0 @@
1
- import type { CleanSession } from '../../domain/entities/parser.js';
2
- /**
3
- * Interface for clean parser services
4
- * Implementations handle transformation of raw IDE session data to clean normalized format
5
- */
6
- export interface ICleanParserService {
7
- /**
8
- * Parse and transform raw IDE sessions to clean normalized format
9
- *
10
- * Reads raw session files and transforms them into standardized format with
11
- * normalized messages, metadata, and workspace information.
12
- * Returns parsed sessions in-memory without writing to disk.
13
- *
14
- * @param rawDir - Path to directory containing raw IDE session files
15
- * @returns Promise resolving to array of CleanSession objects
16
- */
17
- parse: (rawDir: string) => Promise<readonly CleanSession[]>;
18
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,17 +0,0 @@
1
- /**
2
- * Interface for raw parser services
3
- * Implementations handle extraction and transformation of raw IDE session data
4
- */
5
- export interface IRawParserService {
6
- /**
7
- * Parse IDE sessions from a custom directory
8
- *
9
- * Extracts raw session data from IDE storage and writes normalized JSON files
10
- * to output directory (.brv/logs/{ide}/raw by default).
11
- *
12
- * @param customDir - Path to directory containing IDE session data
13
- * @param outputDir - Optional output directory for parsed files (defaults to process.cwd()/.brv/logs/{ide}/raw)
14
- * @returns Promise resolving to true if parsing succeeded, false otherwise
15
- */
16
- parse(customDir: string, outputDir?: string): Promise<boolean>;
17
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,56 +0,0 @@
1
- /**
2
- * Interface for session normalization utilities
3
- * Provides standardized transformation of raw session data to clean normalized format
4
- */
5
- import { CleanMessage, CleanSession, SessionType } from '../../domain/entities/parser.js';
6
- export interface ISessionNormalizer {
7
- /**
8
- * Add turn_id to each message based on order
9
- *
10
- * @param messages - Array of messages to assign turn IDs to
11
- * @returns Array of messages with turn_id property added
12
- */
13
- addTurnIds(messages: CleanMessage[]): CleanMessage[];
14
- /**
15
- * Combine tool_use and tool_result messages
16
- *
17
- * @param messages - Array of clean messages to process
18
- * @returns Array of messages with combined tool execution blocks
19
- */
20
- combineToolResults(messages: CleanMessage[]): CleanMessage[];
21
- /**
22
- * Extract unique workspace paths from session messages and metadata
23
- *
24
- * @param messages - Array of clean messages to extract paths from
25
- * @param metadata - Session metadata object (may contain cwd property)
26
- * @param existingPaths - Optional pre-existing paths to include
27
- * @returns Sorted array of unique workspace paths
28
- */
29
- extractWorkspacePaths(messages: CleanMessage[], metadata: unknown, existingPaths?: string[]): string[];
30
- /**
31
- * Normalize message content to always be an array of content blocks
32
- *
33
- * @param content - Content to normalize (can be string, array of blocks, object, or any value)
34
- * @returns Array of normalized ContentBlock objects
35
- */
36
- normalizeContent(content: unknown): unknown[];
37
- /**
38
- * Normalize a single content block
39
- *
40
- * @param block - Block to normalize (string, object, or any value)
41
- * @returns Normalized ContentBlock with proper type inference
42
- */
43
- normalizeContentBlock(block: unknown): unknown;
44
- /**
45
- * Normalize session to clean format
46
- *
47
- * Transforms raw session data into standardized CleanSession format. Normalizes message
48
- * content to content blocks, combines tool calls with results, assigns turn IDs,
49
- * and extracts workspace paths.
50
- *
51
- * @param session - Raw session object with messages and metadata
52
- * @param sessionType - Type of session (Claude, Copilot, Cursor, Codex)
53
- * @returns Normalized CleanSession with standardized format
54
- */
55
- normalizeSession(session: Record<string, unknown>, sessionType?: SessionType): CleanSession;
56
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,24 +0,0 @@
1
- /**
2
- * Coding Agent Log Parser
3
- * Parses coding agent log files using the existing raw/clean parser pipeline
4
- * Follows the same logic as the 'brv watch' command's triggerParsing method
5
- */
6
- import type { CleanSession } from '../../../core/domain/entities/parser.js';
7
- import type { ICodingAgentLogParser } from '../../../core/interfaces/cipher/i-coding-agent-log-parser.js';
8
- import { Agent } from '../../../core/domain/entities/agent.js';
9
- /**
10
- * Coding Agent Log Parser
11
- *
12
- * Reuses the existing raw/clean parser infrastructure to parse coding agent log files.
13
- * This implementation follows the same two-phase pipeline as the 'brv watch' command:
14
- *
15
- * 1. Raw Phase: Parse IDE-specific files from chatLogPath directory, write to .brv/logs/{ide}/raw/
16
- * 2. Clean Phase: Read from .brv/logs/{ide}/raw/, normalize to CleanSession format
17
- *
18
- * Note: This parser processes entire directories (not individual files) for consistency
19
- * with the existing parser architecture. When a single file changes, all files in the
20
- * directory will be re-parsed. This is inefficient but safe, and can be optimized later.
21
- */
22
- export declare class CodingAgentLogParser implements ICodingAgentLogParser {
23
- parse(chatLogPath: string, ide: Agent): Promise<readonly CleanSession[]>;
24
- }
@@ -1,51 +0,0 @@
1
- /**
2
- * Coding Agent Log Parser
3
- * Parses coding agent log files using the existing raw/clean parser pipeline
4
- * Follows the same logic as the 'brv watch' command's triggerParsing method
5
- */
6
- import { CleanParserServiceFactory } from '../../parsers/clean/clean-parser-service-factory.js';
7
- import { RawParserServiceFactory } from '../../parsers/raw/raw-parser-service-factory.js';
8
- /**
9
- * Coding Agent Log Parser
10
- *
11
- * Reuses the existing raw/clean parser infrastructure to parse coding agent log files.
12
- * This implementation follows the same two-phase pipeline as the 'brv watch' command:
13
- *
14
- * 1. Raw Phase: Parse IDE-specific files from chatLogPath directory, write to .brv/logs/{ide}/raw/
15
- * 2. Clean Phase: Read from .brv/logs/{ide}/raw/, normalize to CleanSession format
16
- *
17
- * Note: This parser processes entire directories (not individual files) for consistency
18
- * with the existing parser architecture. When a single file changes, all files in the
19
- * directory will be re-parsed. This is inefficient but safe, and can be optimized later.
20
- */
21
- export class CodingAgentLogParser {
22
- async parse(chatLogPath, ide) {
23
- if (!RawParserServiceFactory.isSupported(ide)) {
24
- throw new Error(`Unsupported IDE: ${ide}`);
25
- }
26
- if (!chatLogPath || chatLogPath.trim().length === 0) {
27
- throw new Error('Chat log path cannot be empty');
28
- }
29
- let isRawSuccess = false;
30
- try {
31
- isRawSuccess = await RawParserServiceFactory.parseConversations(ide, chatLogPath);
32
- }
33
- catch (error) {
34
- throw new Error(`Raw parsing error: ${error instanceof Error ? error.message : 'Unknown error'}`);
35
- }
36
- if (isRawSuccess) {
37
- try {
38
- const rawOutputDir = `${process.cwd()}/.brv/logs/${ide}/raw`;
39
- const cleanSessions = await CleanParserServiceFactory.parseConversations(ide, rawOutputDir);
40
- if (cleanSessions.length > 0) {
41
- return Object.freeze(cleanSessions);
42
- }
43
- throw new Error('Clean parsing returned no sessions');
44
- }
45
- catch (error) {
46
- throw new Error(`Clean parsing error: ${error instanceof Error ? error.message : 'Unknown error'}`);
47
- }
48
- }
49
- throw new Error('Raw parsing failed');
50
- }
51
- }
@@ -1,14 +0,0 @@
1
- import type { ICodingAgentLogParser } from '../../../core/interfaces/cipher/i-coding-agent-log-parser.js';
2
- import type { CodingAgentLogWatcherOptions, ICodingAgentLogWatcher } from '../../../core/interfaces/cipher/i-coding-agent-log-watcher.js';
3
- import type { IFileWatcherService } from '../../../core/interfaces/i-file-watcher-service.js';
4
- export declare class CodingAgentLogWatcher implements ICodingAgentLogWatcher {
5
- private callback;
6
- private readonly fileWatcher;
7
- private readonly parser;
8
- private watching;
9
- constructor(fileWatcher: IFileWatcherService, parser: ICodingAgentLogParser);
10
- isWatching(): boolean;
11
- start(options: CodingAgentLogWatcherOptions): Promise<void>;
12
- stop(): Promise<void>;
13
- private handleFileEvent;
14
- }
@@ -1,55 +0,0 @@
1
- export class CodingAgentLogWatcher {
2
- callback;
3
- fileWatcher;
4
- parser;
5
- watching;
6
- constructor(fileWatcher, parser) {
7
- this.watching = false;
8
- this.fileWatcher = fileWatcher;
9
- this.parser = parser;
10
- }
11
- isWatching() {
12
- return this.watching;
13
- }
14
- async start(options) {
15
- if (this.watching) {
16
- throw new Error('Already watching. Stop the watcher before starting again.');
17
- }
18
- this.callback = options.onCleanSession;
19
- this.watching = true;
20
- this.fileWatcher.setFileEventHandler(async (event) => {
21
- await this.handleFileEvent(event, options.codingAgentInfo.name);
22
- });
23
- await this.fileWatcher.start([options.codingAgentInfo.chatLogPath]);
24
- }
25
- async stop() {
26
- if (!this.watching) {
27
- return;
28
- }
29
- await this.fileWatcher.stop();
30
- this.callback = undefined;
31
- this.watching = false;
32
- }
33
- async handleFileEvent(event, codingAgent) {
34
- try {
35
- if (event.type !== 'add' && event.type !== 'change') {
36
- return;
37
- }
38
- const sessions = await this.parser.parse(event.path, codingAgent);
39
- if (this.callback !== undefined) {
40
- for (const session of sessions) {
41
- try {
42
- // eslint-disable-next-line no-await-in-loop
43
- await this.callback(session);
44
- }
45
- catch (error) {
46
- console.error(`[CodingAgentLogWatcher] Error in session callback: ${error}`);
47
- }
48
- }
49
- }
50
- }
51
- catch (error) {
52
- console.error(`[CodingAgentLogWatcher] Error processing file ${event.path}: ${error}`);
53
- }
54
- }
55
- }
@@ -1,111 +0,0 @@
1
- /**
2
- * Claude Clean Service
3
- * Transforms Claude raw parsed data to clean normalized format
4
- * Consolidates agent sessions and normalizes messages
5
- */
6
- import type { CleanSession } from '../../../core/domain/entities/parser.js';
7
- import { Agent } from '../../../core/domain/entities/agent.js';
8
- import { ICleanParserService } from '../../../core/interfaces/parser/i-clean-parser-service.js';
9
- /**
10
- * Claude Clean Service
11
- * Transforms Claude raw parsed sessions to clean normalized format
12
- */
13
- export declare class ClaudeCleanService implements ICleanParserService {
14
- private ide;
15
- /**
16
- * Initialize Claude Clean Service
17
- *
18
- * @param ide - The IDE type (Claude Code)
19
- */
20
- constructor(ide: Agent);
21
- /**
22
- * Parse and transform raw Claude sessions to clean normalized format
23
- *
24
- * Reads raw sessions organized by workspace, consolidates agent sessions into main
25
- * conversations, and normalizes message format. Returns sessions in-memory without file writing.
26
- *
27
- * @param rawDir - Path to directory containing raw Claude session files organized by workspace
28
- * @returns Promise resolving to array of clean normalized sessions
29
- */
30
- parse(rawDir: string): Promise<readonly CleanSession[]>;
31
- /**
32
- * Calculate string similarity score using word overlap method
33
- *
34
- * Computes similarity by comparing words with length > 3 characters.
35
- * Returns fraction of matching words relative to max length.
36
- *
37
- * @param str1 - First string to compare
38
- * @param str2 - Second string to compare
39
- * @returns Similarity score between 0 (no match) and 1 (perfect match)
40
- */
41
- private calculateSimilarity;
42
- /**
43
- * Consolidate agent session data into main conversation
44
- *
45
- * When main conversation contains Task subagent invocation, flattens the agent
46
- * session messages into the main message stream. Two-pass algorithm: first identify
47
- * Task invocations with matching agent sessions, then insert agent messages.
48
- *
49
- * @param mainSession - Main Claude conversation session to consolidate into
50
- * @param agentSessions - Map of agent sessions keyed by agent session ID
51
- * @returns Promise resolving to consolidated session with agent messages merged
52
- */
53
- private consolidateAgentSessions;
54
- /**
55
- * Find best matching agent session for a task description and timestamp
56
- *
57
- * Locates matching agent session using similarity scoring and timestamp proximity.
58
- * Considers both task description similarity and temporal closeness (within 5 seconds).
59
- *
60
- * @param description - Task description from Task tool_use invocation
61
- * @param messageTimestamp - Timestamp of message containing Task invocation
62
- * @param agentSessions - Map of available agent sessions
63
- * @returns Matching agent session or null if no good match found
64
- */
65
- private findMatchingAgentSession;
66
- /**
67
- * Flatten messages with agent sessions inserted after Task invocations
68
- *
69
- * Inserts agent session messages into message stream after Task tool_use invocations
70
- * that have matching agent sessions. Preserves message order.
71
- *
72
- * @param messages - Array of raw session messages
73
- * @param taskToolUseIds - Set of Task tool_use IDs that have matching agent sessions
74
- * @param agentSessions - Map of available agent sessions
75
- * @returns Flattened message array with agent messages interleaved
76
- */
77
- private flattenMessagesWithAgentSessions;
78
- /**
79
- * Identify Task tool_use IDs that have matching agent sessions
80
- *
81
- * Scans messages for Task tool_use invocations and identifies which ones
82
- * have corresponding agent sessions that can be consolidated.
83
- *
84
- * @param messages - Array of session messages
85
- * @param agentSessions - Map of available agent sessions
86
- * @returns Set of tool_use IDs that have matching agent sessions
87
- */
88
- private identifyTaskToolIds;
89
- /**
90
- * Load and organize sessions from workspace directory
91
- *
92
- * Reads JSON files from workspace directory and organizes them into main sessions
93
- * and agent sessions based on filename prefix ('agent-' for agent sessions).
94
- *
95
- * @param workspacePath - Path to workspace directory containing session files
96
- * @param jsonFiles - Array of JSON filenames to load
97
- * @returns Promise resolving to object with separated agentSessions and allSessions maps
98
- */
99
- private loadSessions;
100
- /**
101
- * Process main sessions and return normalized outputs
102
- *
103
- * Consolidates agent sessions and normalizes each session.
104
- * Returns normalized sessions in-memory without writing to disk.
105
- *
106
- * @param allSessions - Map of main sessions to process
107
- * @param agentSessions - Map of available agent sessions for consolidation
108
- * @returns Promise resolving to array of clean normalized sessions
109
- */
110
- private processMainSessions;
111
- }