@codemieai/code 0.0.27 → 0.0.29
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 +9 -11
- package/bin/agent-executor.js +1 -1
- package/dist/agents/codemie-code/agent.js +1 -1
- package/dist/agents/codemie-code/config.d.ts +1 -1
- package/dist/agents/codemie-code/config.d.ts.map +1 -1
- package/dist/agents/codemie-code/config.js +3 -4
- package/dist/agents/codemie-code/config.js.map +1 -1
- package/dist/agents/codemie-code/index.js +1 -1
- package/dist/agents/codemie-code/storage/todoStorage.d.ts.map +1 -1
- package/dist/agents/codemie-code/storage/todoStorage.js +2 -2
- package/dist/agents/codemie-code/storage/todoStorage.js.map +1 -1
- package/dist/agents/codemie-code/tools/index.js +1 -1
- package/dist/agents/codemie-code/tools/index.js.map +1 -1
- package/dist/agents/core/AgentCLI.d.ts.map +1 -1
- package/dist/agents/core/AgentCLI.js +6 -10
- package/dist/agents/core/AgentCLI.js.map +1 -1
- package/dist/agents/core/BaseAgentAdapter.d.ts +17 -9
- package/dist/agents/core/BaseAgentAdapter.d.ts.map +1 -1
- package/dist/agents/core/BaseAgentAdapter.js +80 -72
- package/dist/agents/core/BaseAgentAdapter.js.map +1 -1
- package/dist/agents/core/extension/BaseExtensionInstaller.d.ts +258 -0
- package/dist/agents/core/extension/BaseExtensionInstaller.d.ts.map +1 -0
- package/dist/agents/core/extension/BaseExtensionInstaller.js +522 -0
- package/dist/agents/core/extension/BaseExtensionInstaller.js.map +1 -0
- package/dist/agents/core/lifecycle-helpers.d.ts.map +1 -1
- package/dist/agents/core/lifecycle-helpers.js +16 -2
- package/dist/agents/core/lifecycle-helpers.js.map +1 -1
- package/dist/agents/core/metrics/index.d.ts +0 -2
- package/dist/agents/core/metrics/index.d.ts.map +1 -1
- package/dist/agents/core/metrics/index.js +0 -3
- package/dist/agents/core/metrics/index.js.map +1 -1
- package/dist/agents/core/metrics/types.d.ts +4 -232
- package/dist/agents/core/metrics/types.d.ts.map +1 -1
- package/dist/agents/core/metrics/types.js +2 -2
- package/dist/agents/core/session/BaseProcessor.d.ts +72 -0
- package/dist/agents/core/session/BaseProcessor.d.ts.map +1 -0
- package/dist/agents/core/session/BaseProcessor.js +9 -0
- package/dist/agents/core/session/BaseProcessor.js.map +1 -0
- package/dist/agents/core/session/BaseSessionAdapter.d.ts +99 -0
- package/dist/agents/core/session/BaseSessionAdapter.d.ts.map +1 -0
- package/dist/agents/core/session/BaseSessionAdapter.js +9 -0
- package/dist/agents/core/session/BaseSessionAdapter.js.map +1 -0
- package/dist/agents/core/session/SessionStore.d.ts +23 -0
- package/dist/agents/core/session/SessionStore.d.ts.map +1 -0
- package/dist/agents/core/session/SessionStore.js +75 -0
- package/dist/agents/core/session/SessionStore.js.map +1 -0
- package/dist/agents/core/session/session-config.d.ts +27 -0
- package/dist/agents/core/session/session-config.d.ts.map +1 -0
- package/dist/agents/core/session/session-config.js +61 -0
- package/dist/agents/core/session/session-config.js.map +1 -0
- package/dist/agents/core/session/types.d.ts +87 -0
- package/dist/agents/core/session/types.d.ts.map +1 -0
- package/dist/agents/core/session/types.js +8 -0
- package/dist/agents/core/session/types.js.map +1 -0
- package/dist/agents/core/session/utils/jsonl-reader.d.ts +15 -0
- package/dist/agents/core/session/utils/jsonl-reader.d.ts.map +1 -0
- package/dist/agents/core/session/utils/jsonl-reader.js +33 -0
- package/dist/agents/core/session/utils/jsonl-reader.js.map +1 -0
- package/dist/agents/core/session/utils/jsonl-writer.d.ts +26 -0
- package/dist/agents/core/session/utils/jsonl-writer.d.ts.map +1 -0
- package/dist/agents/core/session/utils/jsonl-writer.js +56 -0
- package/dist/agents/core/session/utils/jsonl-writer.js.map +1 -0
- package/dist/agents/core/types.d.ts +78 -11
- package/dist/agents/core/types.d.ts.map +1 -1
- package/dist/agents/plugins/claude/claude-message-types.d.ts +74 -0
- package/dist/agents/plugins/claude/claude-message-types.d.ts.map +1 -0
- package/dist/agents/plugins/claude/claude-message-types.js +8 -0
- package/dist/agents/plugins/claude/claude-message-types.js.map +1 -0
- package/dist/agents/plugins/claude/claude.plugin-installer.d.ts +53 -0
- package/dist/agents/plugins/claude/claude.plugin-installer.d.ts.map +1 -0
- package/dist/agents/plugins/claude/claude.plugin-installer.js +63 -0
- package/dist/agents/plugins/claude/claude.plugin-installer.js.map +1 -0
- package/dist/agents/plugins/claude/claude.plugin.d.ts +26 -0
- package/dist/agents/plugins/claude/claude.plugin.d.ts.map +1 -0
- package/dist/agents/plugins/{claude.plugin.js → claude/claude.plugin.js} +20 -11
- package/dist/agents/plugins/claude/claude.plugin.js.map +1 -0
- package/dist/agents/plugins/claude/claude.session.d.ts +60 -0
- package/dist/agents/plugins/claude/claude.session.d.ts.map +1 -0
- package/dist/agents/plugins/claude/claude.session.js +339 -0
- package/dist/agents/plugins/claude/claude.session.js.map +1 -0
- package/dist/agents/plugins/claude/plugin/.claude-plugin/local-install.json +15 -0
- package/dist/agents/plugins/claude/plugin/.claude-plugin/plugin.json +9 -0
- package/dist/agents/plugins/claude/plugin/README.md +299 -0
- package/dist/agents/plugins/claude/plugin/claude-templates/README.md +539 -0
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/CLAUDE.md.template +511 -0
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/INDEX.md +205 -0
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/TEMPLATE_SIZES.md +74 -0
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/api/api-patterns.md.template +207 -0
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/architecture/layered-architecture.md.template +143 -0
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/architecture/project-structure.md.template +127 -0
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/data/database-patterns.md.template +168 -0
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/development/development-practices.md.template +210 -0
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/integration/external-integrations.md.template +160 -0
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/security/security-practices.md.template +170 -0
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/standards/code-quality.md.template +150 -0
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/standards/git-workflow.md.template +177 -0
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/testing/testing-patterns.md.template +143 -0
- package/dist/agents/plugins/claude/plugin/commands/README.md +0 -0
- package/dist/agents/plugins/claude/plugin/commands/codemie-catchup.md +10 -0
- package/dist/agents/plugins/claude/plugin/commands/codemie-init.md +731 -0
- package/dist/agents/plugins/claude/plugin/commands/memory-add.md +44 -0
- package/dist/agents/plugins/claude/plugin/commands/memory-init.md +18 -0
- package/dist/agents/plugins/claude/plugin/commands/memory-refresh.md +54 -0
- package/dist/agents/plugins/claude/plugin/hooks/hooks.json +71 -0
- package/dist/agents/plugins/claude/session/processors/claude.conversations-processor.d.ts +51 -0
- package/dist/agents/plugins/claude/session/processors/claude.conversations-processor.d.ts.map +1 -0
- package/dist/agents/plugins/claude/session/processors/claude.conversations-processor.js +840 -0
- package/dist/agents/plugins/claude/session/processors/claude.conversations-processor.js.map +1 -0
- package/dist/agents/plugins/claude/session/processors/claude.metrics-processor.d.ts +37 -0
- package/dist/agents/plugins/claude/session/processors/claude.metrics-processor.d.ts.map +1 -0
- package/dist/agents/plugins/claude/session/processors/claude.metrics-processor.js +275 -0
- package/dist/agents/plugins/claude/session/processors/claude.metrics-processor.js.map +1 -0
- package/dist/agents/plugins/codemie-code.plugin.js +1 -1
- package/dist/agents/plugins/codemie-code.plugin.js.map +1 -1
- package/dist/agents/plugins/gemini/extension/README.md +88 -0
- package/dist/agents/plugins/gemini/extension/gemini-extension.json +11 -0
- package/dist/agents/plugins/gemini/extension/hooks/hooks.json +65 -0
- package/dist/agents/plugins/gemini/gemini.extension-installer.d.ts +49 -0
- package/dist/agents/plugins/gemini/gemini.extension-installer.d.ts.map +1 -0
- package/dist/agents/plugins/gemini/gemini.extension-installer.js +63 -0
- package/dist/agents/plugins/gemini/gemini.extension-installer.js.map +1 -0
- package/dist/agents/plugins/gemini/gemini.hook-transformer.d.ts +43 -0
- package/dist/agents/plugins/gemini/gemini.hook-transformer.d.ts.map +1 -0
- package/dist/agents/plugins/gemini/gemini.hook-transformer.js +57 -0
- package/dist/agents/plugins/gemini/gemini.hook-transformer.js.map +1 -0
- package/dist/agents/plugins/gemini/gemini.plugin.d.ts +32 -0
- package/dist/agents/plugins/gemini/gemini.plugin.d.ts.map +1 -0
- package/dist/agents/plugins/gemini/gemini.plugin.js +136 -0
- package/dist/agents/plugins/gemini/gemini.plugin.js.map +1 -0
- package/dist/agents/plugins/gemini/gemini.session-adapter.d.ts +68 -0
- package/dist/agents/plugins/gemini/gemini.session-adapter.d.ts.map +1 -0
- package/dist/agents/plugins/gemini/gemini.session-adapter.js +268 -0
- package/dist/agents/plugins/gemini/gemini.session-adapter.js.map +1 -0
- package/dist/agents/plugins/gemini/session/processors/gemini.conversations-processor.d.ts +36 -0
- package/dist/agents/plugins/gemini/session/processors/gemini.conversations-processor.d.ts.map +1 -0
- package/dist/agents/plugins/gemini/session/processors/gemini.conversations-processor.js +186 -0
- package/dist/agents/plugins/gemini/session/processors/gemini.conversations-processor.js.map +1 -0
- package/dist/agents/plugins/gemini/session/processors/gemini.metrics-processor.d.ts +32 -0
- package/dist/agents/plugins/gemini/session/processors/gemini.metrics-processor.d.ts.map +1 -0
- package/dist/agents/plugins/gemini/session/processors/gemini.metrics-processor.js +193 -0
- package/dist/agents/plugins/gemini/session/processors/gemini.metrics-processor.js.map +1 -0
- package/dist/agents/plugins/gemini/session/utils/token-aggregator.d.ts +26 -0
- package/dist/agents/plugins/gemini/session/utils/token-aggregator.d.ts.map +1 -0
- package/dist/agents/plugins/gemini/session/utils/token-aggregator.js +38 -0
- package/dist/agents/plugins/gemini/session/utils/token-aggregator.js.map +1 -0
- package/dist/agents/plugins/gemini/session/utils/tool-aggregator.d.ts +33 -0
- package/dist/agents/plugins/gemini/session/utils/tool-aggregator.d.ts.map +1 -0
- package/dist/agents/plugins/gemini/session/utils/tool-aggregator.js +58 -0
- package/dist/agents/plugins/gemini/session/utils/tool-aggregator.js.map +1 -0
- package/dist/agents/plugins/gemini/session/utils/turn-detector.d.ts +70 -0
- package/dist/agents/plugins/gemini/session/utils/turn-detector.d.ts.map +1 -0
- package/dist/agents/plugins/gemini/session/utils/turn-detector.js +86 -0
- package/dist/agents/plugins/gemini/session/utils/turn-detector.js.map +1 -0
- package/dist/agents/registry.d.ts +7 -2
- package/dist/agents/registry.d.ts.map +1 -1
- package/dist/agents/registry.js +17 -8
- package/dist/agents/registry.js.map +1 -1
- package/dist/cli/commands/analytics/data-loader.d.ts +1 -1
- package/dist/cli/commands/analytics/data-loader.d.ts.map +1 -1
- package/dist/cli/commands/analytics/data-loader.js +3 -3
- package/dist/cli/commands/analytics/data-loader.js.map +1 -1
- package/dist/cli/commands/analytics/index.js +1 -1
- package/dist/cli/commands/analytics/index.js.map +1 -1
- package/dist/cli/commands/doctor/checks/AIConfigCheck.js +1 -1
- package/dist/cli/commands/doctor/checks/AIConfigCheck.js.map +1 -1
- package/dist/cli/commands/doctor/checks/AwsCliCheck.js +1 -1
- package/dist/cli/commands/doctor/checks/AwsCliCheck.js.map +1 -1
- package/dist/cli/commands/doctor/checks/NpmCheck.js +1 -1
- package/dist/cli/commands/doctor/checks/NpmCheck.js.map +1 -1
- package/dist/cli/commands/doctor/checks/PythonCheck.d.ts +13 -0
- package/dist/cli/commands/doctor/checks/PythonCheck.d.ts.map +1 -1
- package/dist/cli/commands/doctor/checks/PythonCheck.js +91 -32
- package/dist/cli/commands/doctor/checks/PythonCheck.js.map +1 -1
- package/dist/cli/commands/doctor/checks/UvCheck.js +1 -1
- package/dist/cli/commands/doctor/checks/UvCheck.js.map +1 -1
- package/dist/cli/commands/doctor/types.d.ts +1 -1
- package/dist/cli/commands/doctor/types.d.ts.map +1 -1
- package/dist/cli/commands/hook.d.ts +7 -0
- package/dist/cli/commands/hook.d.ts.map +1 -0
- package/dist/cli/commands/hook.js +788 -0
- package/dist/cli/commands/hook.js.map +1 -0
- package/dist/cli/commands/profile/auth.js +1 -1
- package/dist/cli/commands/profile/auth.js.map +1 -1
- package/dist/{utils/profile-display.d.ts → cli/commands/profile/display.d.ts} +3 -3
- package/dist/cli/commands/profile/display.d.ts.map +1 -0
- package/dist/{utils/profile-display.js → cli/commands/profile/display.js} +2 -2
- package/dist/cli/commands/profile/display.js.map +1 -0
- package/dist/cli/commands/profile/index.js +2 -2
- package/dist/cli/commands/profile/index.js.map +1 -1
- package/dist/cli/commands/setup.d.ts.map +1 -1
- package/dist/cli/commands/setup.js +4 -5
- package/dist/cli/commands/setup.js.map +1 -1
- package/dist/cli/commands/update.d.ts +3 -0
- package/dist/cli/commands/update.d.ts.map +1 -0
- package/dist/cli/commands/update.js +291 -0
- package/dist/cli/commands/update.js.map +1 -0
- package/dist/cli/commands/version.js +1 -1
- package/dist/cli/commands/version.js.map +1 -1
- package/dist/{utils → cli}/first-time.d.ts +4 -0
- package/dist/cli/first-time.d.ts.map +1 -0
- package/dist/{utils → cli}/first-time.js +27 -14
- package/dist/cli/first-time.js.map +1 -0
- package/dist/cli/index.js +6 -2
- package/dist/cli/index.js.map +1 -1
- package/dist/env/manager.d.ts.map +1 -1
- package/dist/env/manager.js +3 -4
- package/dist/env/manager.js.map +1 -1
- package/dist/frameworks/core/BaseFrameworkAdapter.js +1 -1
- package/dist/frameworks/core/BaseFrameworkAdapter.js.map +1 -1
- package/dist/frameworks/core/types.d.ts +1 -1
- package/dist/frameworks/plugins/bmad.plugin.js +2 -2
- package/dist/frameworks/plugins/bmad.plugin.js.map +1 -1
- package/dist/frameworks/plugins/speckit.plugin.d.ts.map +1 -1
- package/dist/frameworks/plugins/speckit.plugin.js +2 -3
- package/dist/frameworks/plugins/speckit.plugin.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/migrations/001-config-rename.migration.d.ts.map +1 -1
- package/dist/migrations/001-config-rename.migration.js +2 -2
- package/dist/migrations/001-config-rename.migration.js.map +1 -1
- package/dist/migrations/002-consolidate-sessions.migration.d.ts +50 -0
- package/dist/migrations/002-consolidate-sessions.migration.d.ts.map +1 -0
- package/dist/migrations/002-consolidate-sessions.migration.js +220 -0
- package/dist/migrations/002-consolidate-sessions.migration.js.map +1 -0
- package/dist/migrations/index.d.ts +1 -0
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/index.js +3 -2
- package/dist/migrations/index.js.map +1 -1
- package/dist/migrations/tracker.d.ts.map +1 -1
- package/dist/migrations/tracker.js +2 -2
- package/dist/migrations/tracker.js.map +1 -1
- package/dist/providers/core/base/http-client.js +1 -1
- package/dist/providers/core/types.d.ts +1 -1
- package/dist/providers/plugins/ollama/ollama.template.d.ts.map +1 -1
- package/dist/providers/plugins/ollama/ollama.template.js +3 -1
- package/dist/providers/plugins/ollama/ollama.template.js.map +1 -1
- package/dist/providers/plugins/sso/index.d.ts +1 -1
- package/dist/providers/plugins/sso/index.d.ts.map +1 -1
- package/dist/providers/plugins/sso/index.js +1 -1
- package/dist/providers/plugins/sso/index.js.map +1 -1
- package/dist/providers/plugins/sso/proxy/plugins/index.d.ts +1 -1
- package/dist/providers/plugins/sso/proxy/plugins/index.d.ts.map +1 -1
- package/dist/providers/plugins/sso/proxy/plugins/index.js +3 -3
- package/dist/providers/plugins/sso/proxy/plugins/index.js.map +1 -1
- package/dist/providers/plugins/sso/proxy/plugins/sso.session-sync.plugin.d.ts +40 -0
- package/dist/providers/plugins/sso/proxy/plugins/sso.session-sync.plugin.d.ts.map +1 -0
- package/dist/providers/plugins/sso/proxy/plugins/sso.session-sync.plugin.js +194 -0
- package/dist/providers/plugins/sso/proxy/plugins/sso.session-sync.plugin.js.map +1 -0
- package/dist/providers/plugins/sso/proxy/proxy-http-client.d.ts +1 -0
- package/dist/providers/plugins/sso/proxy/proxy-http-client.d.ts.map +1 -1
- package/dist/providers/plugins/sso/proxy/proxy-http-client.js +40 -6
- package/dist/providers/plugins/sso/proxy/proxy-http-client.js.map +1 -1
- package/dist/providers/plugins/sso/session/BaseProcessor.d.ts +72 -0
- package/dist/providers/plugins/sso/session/BaseProcessor.d.ts.map +1 -0
- package/dist/providers/plugins/sso/session/BaseProcessor.js +9 -0
- package/dist/providers/plugins/sso/session/BaseProcessor.js.map +1 -0
- package/dist/providers/plugins/sso/session/BaseSessionAdapter.d.ts +99 -0
- package/dist/providers/plugins/sso/session/BaseSessionAdapter.d.ts.map +1 -0
- package/dist/providers/plugins/sso/session/BaseSessionAdapter.js +9 -0
- package/dist/providers/plugins/sso/session/BaseSessionAdapter.js.map +1 -0
- package/dist/providers/plugins/sso/session/SessionSyncer.d.ts +36 -0
- package/dist/providers/plugins/sso/session/SessionSyncer.d.ts.map +1 -0
- package/dist/providers/plugins/sso/session/SessionSyncer.js +140 -0
- package/dist/providers/plugins/sso/session/SessionSyncer.js.map +1 -0
- package/dist/providers/plugins/sso/session/processors/conversations/conversation-api-client.d.ts +26 -0
- package/dist/providers/plugins/sso/session/processors/conversations/conversation-api-client.d.ts.map +1 -0
- package/dist/providers/plugins/sso/session/processors/conversations/conversation-api-client.js +146 -0
- package/dist/providers/plugins/sso/session/processors/conversations/conversation-api-client.js.map +1 -0
- package/dist/providers/plugins/sso/session/processors/conversations/conversation-sync-processor.d.ts +23 -0
- package/dist/providers/plugins/sso/session/processors/conversations/conversation-sync-processor.d.ts.map +1 -0
- package/dist/providers/plugins/sso/session/processors/conversations/conversation-sync-processor.js +171 -0
- package/dist/providers/plugins/sso/session/processors/conversations/conversation-sync-processor.js.map +1 -0
- package/dist/providers/plugins/sso/session/processors/conversations/conversation-types.d.ts +69 -0
- package/dist/providers/plugins/sso/session/processors/conversations/conversation-types.d.ts.map +1 -0
- package/dist/providers/plugins/sso/session/processors/conversations/conversation-types.js +7 -0
- package/dist/providers/plugins/sso/session/processors/conversations/conversation-types.js.map +1 -0
- package/dist/providers/plugins/sso/session/processors/metrics/MetricsWriter.d.ts +30 -0
- package/dist/providers/plugins/sso/session/processors/metrics/MetricsWriter.d.ts.map +1 -0
- package/dist/providers/plugins/sso/session/processors/metrics/MetricsWriter.js +79 -0
- package/dist/providers/plugins/sso/session/processors/metrics/MetricsWriter.js.map +1 -0
- package/dist/providers/plugins/sso/{metrics/sync/sso.metrics-aggregator.d.ts → session/processors/metrics/metrics-aggregator.d.ts} +6 -5
- package/dist/providers/plugins/sso/session/processors/metrics/metrics-aggregator.d.ts.map +1 -0
- package/dist/providers/plugins/sso/{metrics/sync/sso.metrics-aggregator.js → session/processors/metrics/metrics-aggregator.js} +20 -12
- package/dist/providers/plugins/sso/session/processors/metrics/metrics-aggregator.js.map +1 -0
- package/dist/providers/plugins/sso/{metrics/sync/sso.metrics-sender.d.ts → session/processors/metrics/metrics-api-client.d.ts} +18 -11
- package/dist/providers/plugins/sso/session/processors/metrics/metrics-api-client.d.ts.map +1 -0
- package/dist/providers/plugins/sso/{metrics/sync/sso.metrics-sender.js → session/processors/metrics/metrics-api-client.js} +143 -15
- package/dist/providers/plugins/sso/session/processors/metrics/metrics-api-client.js.map +1 -0
- package/dist/providers/plugins/sso/{metrics/sync/sso.metrics-post-processor.d.ts → session/processors/metrics/metrics-post-processor.d.ts} +3 -3
- package/dist/providers/plugins/sso/session/processors/metrics/metrics-post-processor.d.ts.map +1 -0
- package/dist/providers/plugins/sso/{metrics/sync/sso.metrics-post-processor.js → session/processors/metrics/metrics-post-processor.js} +3 -3
- package/dist/providers/plugins/sso/session/processors/metrics/metrics-post-processor.js.map +1 -0
- package/dist/providers/plugins/sso/session/processors/metrics/metrics-sync-processor.d.ts +24 -0
- package/dist/providers/plugins/sso/session/processors/metrics/metrics-sync-processor.d.ts.map +1 -0
- package/dist/providers/plugins/sso/{metrics/sync/sso.metrics-sync.plugin.js → session/processors/metrics/metrics-sync-processor.js} +94 -165
- package/dist/providers/plugins/sso/session/processors/metrics/metrics-sync-processor.js.map +1 -0
- package/dist/providers/plugins/sso/{metrics/sync/sso.metrics-types.d.ts → session/processors/metrics/metrics-types.d.ts} +2 -1
- package/dist/providers/plugins/sso/session/processors/metrics/metrics-types.d.ts.map +1 -0
- package/dist/providers/plugins/sso/{metrics/sync/sso.metrics-types.js → session/processors/metrics/metrics-types.js} +1 -1
- package/dist/providers/plugins/sso/session/processors/metrics/metrics-types.js.map +1 -0
- package/dist/providers/plugins/sso/session/utils/jsonl-reader.d.ts +15 -0
- package/dist/providers/plugins/sso/session/utils/jsonl-reader.d.ts.map +1 -0
- package/dist/providers/plugins/sso/session/utils/jsonl-reader.js +33 -0
- package/dist/providers/plugins/sso/session/utils/jsonl-reader.js.map +1 -0
- package/dist/providers/plugins/sso/session/utils/jsonl-writer.d.ts +26 -0
- package/dist/providers/plugins/sso/session/utils/jsonl-writer.d.ts.map +1 -0
- package/dist/providers/plugins/sso/{metrics/sync/sso.jsonl-writer.js → session/utils/jsonl-writer.js} +11 -27
- package/dist/providers/plugins/sso/session/utils/jsonl-writer.js.map +1 -0
- package/dist/providers/plugins/sso/sso.auth.js +1 -1
- package/dist/providers/plugins/sso/sso.auth.js.map +1 -1
- package/dist/providers/plugins/sso/sso.http-client.d.ts +1 -1
- package/dist/providers/plugins/sso/sso.http-client.js +1 -1
- package/dist/providers/plugins/sso/sso.http-client.js.map +1 -1
- package/dist/providers/plugins/sso/sso.template.d.ts.map +1 -1
- package/dist/providers/plugins/sso/sso.template.js +71 -43
- package/dist/providers/plugins/sso/sso.template.js.map +1 -1
- package/dist/utils/{config-loader.d.ts → config.d.ts} +6 -1
- package/dist/utils/config.d.ts.map +1 -0
- package/dist/utils/{config-loader.js → config.js} +30 -4
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/errors.d.ts +89 -0
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/errors.js +340 -0
- package/dist/utils/errors.js.map +1 -1
- package/dist/utils/exec.d.ts +6 -0
- package/dist/utils/exec.d.ts.map +1 -1
- package/dist/utils/exec.js +6 -0
- package/dist/utils/exec.js.map +1 -1
- package/dist/utils/file-operations.d.ts +20 -0
- package/dist/utils/file-operations.d.ts.map +1 -0
- package/dist/utils/file-operations.js +48 -0
- package/dist/utils/file-operations.js.map +1 -0
- package/dist/utils/logger.d.ts +2 -1
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +15 -7
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/{json-parser.d.ts → parsers.d.ts} +1 -1
- package/dist/utils/parsers.d.ts.map +1 -0
- package/dist/utils/{json-parser.js → parsers.js} +1 -1
- package/dist/utils/parsers.js.map +1 -0
- package/dist/utils/{path-utils.d.ts → paths.d.ts} +77 -12
- package/dist/utils/paths.d.ts.map +1 -0
- package/dist/utils/{path-utils.js → paths.js} +103 -12
- package/dist/utils/paths.js.map +1 -0
- package/dist/utils/{npm.d.ts → processes.d.ts} +44 -7
- package/dist/utils/processes.d.ts.map +1 -0
- package/dist/utils/{npm.js → processes.js} +129 -10
- package/dist/utils/processes.js.map +1 -0
- package/dist/utils/profile.d.ts +1 -16
- package/dist/utils/profile.d.ts.map +1 -1
- package/dist/utils/profile.js +1 -27
- package/dist/utils/profile.js.map +1 -1
- package/dist/utils/security.d.ts +62 -0
- package/dist/utils/security.d.ts.map +1 -0
- package/dist/utils/security.js +396 -0
- package/dist/utils/security.js.map +1 -0
- package/package.json +11 -11
- package/scripts/copy-plugins.js +57 -0
- package/scripts/license-check.js +23 -0
- package/bin/codemie-codex.js +0 -18
- package/bin/codemie-deepagents.js +0 -18
- package/dist/agents/core/BaseMetricsAdapter.d.ts +0 -165
- package/dist/agents/core/BaseMetricsAdapter.d.ts.map +0 -1
- package/dist/agents/core/BaseMetricsAdapter.js +0 -308
- package/dist/agents/core/BaseMetricsAdapter.js.map +0 -1
- package/dist/agents/core/metrics/MetricsOrchestrator.d.ts +0 -81
- package/dist/agents/core/metrics/MetricsOrchestrator.d.ts.map +0 -1
- package/dist/agents/core/metrics/MetricsOrchestrator.js +0 -417
- package/dist/agents/core/metrics/MetricsOrchestrator.js.map +0 -1
- package/dist/agents/core/metrics/core/DeltaWriter.d.ts +0 -49
- package/dist/agents/core/metrics/core/DeltaWriter.d.ts.map +0 -1
- package/dist/agents/core/metrics/core/DeltaWriter.js +0 -152
- package/dist/agents/core/metrics/core/DeltaWriter.js.map +0 -1
- package/dist/agents/core/metrics/core/FileSnapshotter.d.ts +0 -22
- package/dist/agents/core/metrics/core/FileSnapshotter.d.ts.map +0 -1
- package/dist/agents/core/metrics/core/FileSnapshotter.js +0 -74
- package/dist/agents/core/metrics/core/FileSnapshotter.js.map +0 -1
- package/dist/agents/core/metrics/core/SessionCorrelator.d.ts +0 -34
- package/dist/agents/core/metrics/core/SessionCorrelator.d.ts.map +0 -1
- package/dist/agents/core/metrics/core/SessionCorrelator.js +0 -157
- package/dist/agents/core/metrics/core/SessionCorrelator.js.map +0 -1
- package/dist/agents/core/metrics/core/SyncStateManager.d.ts +0 -69
- package/dist/agents/core/metrics/core/SyncStateManager.d.ts.map +0 -1
- package/dist/agents/core/metrics/core/SyncStateManager.js +0 -283
- package/dist/agents/core/metrics/core/SyncStateManager.js.map +0 -1
- package/dist/agents/core/metrics/session/SessionStore.d.ts +0 -43
- package/dist/agents/core/metrics/session/SessionStore.d.ts.map +0 -1
- package/dist/agents/core/metrics/session/SessionStore.js +0 -146
- package/dist/agents/core/metrics/session/SessionStore.js.map +0 -1
- package/dist/agents/core/metrics-config.d.ts +0 -38
- package/dist/agents/core/metrics-config.d.ts.map +0 -1
- package/dist/agents/core/metrics-config.js +0 -95
- package/dist/agents/core/metrics-config.js.map +0 -1
- package/dist/agents/plugins/claude.metrics.d.ts +0 -102
- package/dist/agents/plugins/claude.metrics.d.ts.map +0 -1
- package/dist/agents/plugins/claude.metrics.js +0 -656
- package/dist/agents/plugins/claude.metrics.js.map +0 -1
- package/dist/agents/plugins/claude.plugin.d.ts +0 -19
- package/dist/agents/plugins/claude.plugin.d.ts.map +0 -1
- package/dist/agents/plugins/claude.plugin.js.map +0 -1
- package/dist/agents/plugins/codex.plugin.d.ts +0 -17
- package/dist/agents/plugins/codex.plugin.d.ts.map +0 -1
- package/dist/agents/plugins/codex.plugin.js +0 -386
- package/dist/agents/plugins/codex.plugin.js.map +0 -1
- package/dist/agents/plugins/deepagents.plugin.d.ts +0 -21
- package/dist/agents/plugins/deepagents.plugin.d.ts.map +0 -1
- package/dist/agents/plugins/deepagents.plugin.js +0 -104
- package/dist/agents/plugins/deepagents.plugin.js.map +0 -1
- package/dist/agents/plugins/gemini.metrics.d.ts +0 -99
- package/dist/agents/plugins/gemini.metrics.d.ts.map +0 -1
- package/dist/agents/plugins/gemini.metrics.js +0 -475
- package/dist/agents/plugins/gemini.metrics.js.map +0 -1
- package/dist/agents/plugins/gemini.plugin.d.ts +0 -16
- package/dist/agents/plugins/gemini.plugin.d.ts.map +0 -1
- package/dist/agents/plugins/gemini.plugin.js +0 -80
- package/dist/agents/plugins/gemini.plugin.js.map +0 -1
- package/dist/agents/plugins/history-parser.d.ts +0 -52
- package/dist/agents/plugins/history-parser.d.ts.map +0 -1
- package/dist/agents/plugins/history-parser.js +0 -155
- package/dist/agents/plugins/history-parser.js.map +0 -1
- package/dist/providers/plugins/sso/metrics/sync/sso.jsonl-writer.d.ts +0 -28
- package/dist/providers/plugins/sso/metrics/sync/sso.jsonl-writer.d.ts.map +0 -1
- package/dist/providers/plugins/sso/metrics/sync/sso.jsonl-writer.js.map +0 -1
- package/dist/providers/plugins/sso/metrics/sync/sso.lifecycle-handler.d.ts +0 -62
- package/dist/providers/plugins/sso/metrics/sync/sso.lifecycle-handler.d.ts.map +0 -1
- package/dist/providers/plugins/sso/metrics/sync/sso.lifecycle-handler.js +0 -157
- package/dist/providers/plugins/sso/metrics/sync/sso.lifecycle-handler.js.map +0 -1
- package/dist/providers/plugins/sso/metrics/sync/sso.metrics-aggregator.d.ts.map +0 -1
- package/dist/providers/plugins/sso/metrics/sync/sso.metrics-aggregator.js.map +0 -1
- package/dist/providers/plugins/sso/metrics/sync/sso.metrics-api-client.d.ts +0 -32
- package/dist/providers/plugins/sso/metrics/sync/sso.metrics-api-client.d.ts.map +0 -1
- package/dist/providers/plugins/sso/metrics/sync/sso.metrics-api-client.js +0 -159
- package/dist/providers/plugins/sso/metrics/sync/sso.metrics-api-client.js.map +0 -1
- package/dist/providers/plugins/sso/metrics/sync/sso.metrics-post-processor.d.ts.map +0 -1
- package/dist/providers/plugins/sso/metrics/sync/sso.metrics-post-processor.js.map +0 -1
- package/dist/providers/plugins/sso/metrics/sync/sso.metrics-sender.d.ts.map +0 -1
- package/dist/providers/plugins/sso/metrics/sync/sso.metrics-sender.js.map +0 -1
- package/dist/providers/plugins/sso/metrics/sync/sso.metrics-sync.plugin.d.ts +0 -36
- package/dist/providers/plugins/sso/metrics/sync/sso.metrics-sync.plugin.d.ts.map +0 -1
- package/dist/providers/plugins/sso/metrics/sync/sso.metrics-sync.plugin.js.map +0 -1
- package/dist/providers/plugins/sso/metrics/sync/sso.metrics-types.d.ts.map +0 -1
- package/dist/providers/plugins/sso/metrics/sync/sso.metrics-types.js.map +0 -1
- package/dist/utils/config-loader.d.ts.map +0 -1
- package/dist/utils/config-loader.js.map +0 -1
- package/dist/utils/credential-store.d.ts +0 -22
- package/dist/utils/credential-store.d.ts.map +0 -1
- package/dist/utils/credential-store.js +0 -165
- package/dist/utils/credential-store.js.map +0 -1
- package/dist/utils/dirname.d.ts +0 -7
- package/dist/utils/dirname.d.ts.map +0 -1
- package/dist/utils/dirname.js +0 -11
- package/dist/utils/dirname.js.map +0 -1
- package/dist/utils/error-context.d.ts +0 -90
- package/dist/utils/error-context.d.ts.map +0 -1
- package/dist/utils/error-context.js +0 -338
- package/dist/utils/error-context.js.map +0 -1
- package/dist/utils/first-time.d.ts.map +0 -1
- package/dist/utils/first-time.js.map +0 -1
- package/dist/utils/git.d.ts +0 -13
- package/dist/utils/git.d.ts.map +0 -1
- package/dist/utils/git.js +0 -37
- package/dist/utils/git.js.map +0 -1
- package/dist/utils/installation-id.d.ts +0 -10
- package/dist/utils/installation-id.d.ts.map +0 -1
- package/dist/utils/installation-id.js +0 -30
- package/dist/utils/installation-id.js.map +0 -1
- package/dist/utils/json-parser.d.ts.map +0 -1
- package/dist/utils/json-parser.js.map +0 -1
- package/dist/utils/npm.d.ts.map +0 -1
- package/dist/utils/npm.js.map +0 -1
- package/dist/utils/path-utils.d.ts.map +0 -1
- package/dist/utils/path-utils.js.map +0 -1
- package/dist/utils/profile-display.d.ts.map +0 -1
- package/dist/utils/profile-display.js.map +0 -1
- package/dist/utils/sanitize.d.ts +0 -28
- package/dist/utils/sanitize.d.ts.map +0 -1
- package/dist/utils/sanitize.js +0 -212
- package/dist/utils/sanitize.js.map +0 -1
- package/dist/utils/which.d.ts +0 -20
- package/dist/utils/which.d.ts.map +0 -1
- package/dist/utils/which.js +0 -54
- package/dist/utils/which.js.map +0 -1
|
@@ -0,0 +1,840 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conversations Processor (Claude-Specific)
|
|
3
|
+
*
|
|
4
|
+
* Transforms Claude session messages into conversation history format.
|
|
5
|
+
*
|
|
6
|
+
* Responsibilities:
|
|
7
|
+
* - Parse Claude messages (user, assistant, tools, agents)
|
|
8
|
+
* - Transform into conversation history format
|
|
9
|
+
* - Write payloads to JSONL with status 'pending'
|
|
10
|
+
* - Extract tool calls, agent thoughts, token usage
|
|
11
|
+
*
|
|
12
|
+
* Note: API sync is handled separately by SSO provider's ConversationSyncProcessor
|
|
13
|
+
*/
|
|
14
|
+
import { logger } from '../../../../../utils/logger.js';
|
|
15
|
+
import { getSessionConversationPath } from '../../../../core/session/session-config.js';
|
|
16
|
+
import { SessionStore } from '../../../../core/session/SessionStore.js';
|
|
17
|
+
export class ConversationsProcessor {
|
|
18
|
+
name = 'conversations';
|
|
19
|
+
priority = 2; // Run after metrics (priority 1)
|
|
20
|
+
sessionStore = new SessionStore();
|
|
21
|
+
/**
|
|
22
|
+
* Get display name for agent
|
|
23
|
+
*/
|
|
24
|
+
getAgentDisplayName(agentName) {
|
|
25
|
+
try {
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
27
|
+
const { AgentRegistry } = require('../../../../registry.js');
|
|
28
|
+
const agent = AgentRegistry.getAgent(agentName);
|
|
29
|
+
return agent?.metadata?.displayName || agentName;
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
// Fallback to agent name if registry not available
|
|
33
|
+
return agentName;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
shouldProcess(session) {
|
|
37
|
+
return session.messages && session.messages.length > 0;
|
|
38
|
+
}
|
|
39
|
+
async process(session, context) {
|
|
40
|
+
try {
|
|
41
|
+
// Transform ParsedSession.messages → generate conversation payloads
|
|
42
|
+
return await this.processMessages(session, context);
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
logger.error(`[${this.name}] Processing failed:`, error);
|
|
46
|
+
return {
|
|
47
|
+
success: false,
|
|
48
|
+
message: error instanceof Error ? error.message : 'Unknown error'
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Transform ParsedSession.messages to conversation history and write to JSONL
|
|
54
|
+
* Writes payload with status 'pending' for later sync by SSO provider
|
|
55
|
+
* Processes one turn per invocation (incremental mode for real-time hooks)
|
|
56
|
+
*/
|
|
57
|
+
async processMessages(session, context) {
|
|
58
|
+
try {
|
|
59
|
+
logger.info(`[${this.name}] Transforming ${session.messages.length} messages to conversation history`);
|
|
60
|
+
// Load sync state for incremental processing
|
|
61
|
+
const sessionMetadata = await this.sessionStore.loadSession(session.sessionId);
|
|
62
|
+
if (!sessionMetadata) {
|
|
63
|
+
logger.warn(`[${this.name}] Session metadata not found: ${session.sessionId}`);
|
|
64
|
+
return {
|
|
65
|
+
success: false,
|
|
66
|
+
message: 'Session metadata not found - session must be created before processing'
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
const syncState = {
|
|
70
|
+
lastSyncedMessageUuid: sessionMetadata.sync?.conversations?.lastSyncedMessageUuid,
|
|
71
|
+
lastSyncedHistoryIndex: sessionMetadata.sync?.conversations?.lastSyncedHistoryIndex ?? -1
|
|
72
|
+
};
|
|
73
|
+
logger.debug(`[${this.name}] Using sync state:`, {
|
|
74
|
+
lastSyncedMessageUuid: syncState.lastSyncedMessageUuid || 'none',
|
|
75
|
+
lastSyncedHistoryIndex: syncState.lastSyncedHistoryIndex
|
|
76
|
+
});
|
|
77
|
+
const conversationsPath = getSessionConversationPath(session.sessionId);
|
|
78
|
+
const { appendFile, mkdir } = await import('fs/promises');
|
|
79
|
+
const { dirname } = await import('path');
|
|
80
|
+
const { existsSync } = await import('fs');
|
|
81
|
+
const outputDir = dirname(conversationsPath);
|
|
82
|
+
if (!existsSync(outputDir)) {
|
|
83
|
+
await mkdir(outputDir, { recursive: true });
|
|
84
|
+
}
|
|
85
|
+
// Process ONE turn (incremental mode)
|
|
86
|
+
const result = await this.transformMessages(session.messages, syncState, '5a430368-9e91-4564-be20-989803bf4da2', session.agentName, context.agentSessionFile);
|
|
87
|
+
if (result.history.length === 0) {
|
|
88
|
+
logger.debug(`[${this.name}] No history generated from messages`);
|
|
89
|
+
return { success: true, message: 'No history generated', metadata: { recordsProcessed: 0 } };
|
|
90
|
+
}
|
|
91
|
+
// Extract history indices from the result
|
|
92
|
+
const historyIndices = result.history.map((entry) => entry.history_index);
|
|
93
|
+
// Create payload record with status 'pending'
|
|
94
|
+
const payloadRecord = {
|
|
95
|
+
timestamp: Date.now(),
|
|
96
|
+
isTurnContinuation: result.isTurnContinuation,
|
|
97
|
+
historyIndices,
|
|
98
|
+
messageCount: result.history.length,
|
|
99
|
+
payload: {
|
|
100
|
+
conversationId: context.agentSessionId,
|
|
101
|
+
history: result.history
|
|
102
|
+
},
|
|
103
|
+
status: 'pending'
|
|
104
|
+
};
|
|
105
|
+
await appendFile(conversationsPath, JSON.stringify(payloadRecord) + '\n');
|
|
106
|
+
// Update session sync state
|
|
107
|
+
try {
|
|
108
|
+
const currentSession = await this.sessionStore.loadSession(session.sessionId);
|
|
109
|
+
if (currentSession) {
|
|
110
|
+
currentSession.sync ??= {};
|
|
111
|
+
currentSession.sync.conversations ??= {};
|
|
112
|
+
currentSession.sync.conversations.lastSyncedMessageUuid = result.lastProcessedMessageUuid;
|
|
113
|
+
currentSession.sync.conversations.lastSyncedHistoryIndex = result.currentHistoryIndex;
|
|
114
|
+
await this.sessionStore.saveSession(currentSession);
|
|
115
|
+
logger.debug(`[${this.name}] Updated sync state: lastSyncedMessageUuid=${result.lastProcessedMessageUuid}, lastSyncedHistoryIndex=${result.currentHistoryIndex}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
logger.warn(`[${this.name}] Failed to update sync state:`, error);
|
|
120
|
+
}
|
|
121
|
+
logger.info(`[${this.name}] Generated 1 turn with ${result.history.length} conversation messages`);
|
|
122
|
+
return {
|
|
123
|
+
success: true,
|
|
124
|
+
message: 'Generated 1 turn',
|
|
125
|
+
metadata: { recordsProcessed: result.history.length }
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
logger.error(`[${this.name}] Failed to process messages:`, error);
|
|
130
|
+
return {
|
|
131
|
+
success: false,
|
|
132
|
+
message: error instanceof Error ? error.message : 'Unknown error'
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
async transformMessages(messages, syncState, assistantId, agentName, sessionFilePath) {
|
|
137
|
+
let startIndex = 0;
|
|
138
|
+
if (syncState.lastSyncedMessageUuid) {
|
|
139
|
+
const lastSyncedIndex = messages.findIndex((m) => m.uuid === syncState.lastSyncedMessageUuid);
|
|
140
|
+
if (lastSyncedIndex >= 0) {
|
|
141
|
+
startIndex = lastSyncedIndex + 1;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const newMessages = messages.slice(startIndex);
|
|
145
|
+
if (newMessages.length === 0) {
|
|
146
|
+
return {
|
|
147
|
+
history: [],
|
|
148
|
+
isTurnContinuation: false,
|
|
149
|
+
lastProcessedMessageUuid: syncState.lastSyncedMessageUuid || '',
|
|
150
|
+
currentHistoryIndex: syncState.lastSyncedHistoryIndex
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
let firstRealMessage = null;
|
|
154
|
+
for (const msg of newMessages) {
|
|
155
|
+
if (!msg.uuid)
|
|
156
|
+
continue;
|
|
157
|
+
// Skip system messages
|
|
158
|
+
if (msg.type === 'system')
|
|
159
|
+
continue;
|
|
160
|
+
// Skip non-conversational message types (progress, file-history-snapshot, queue-operation, etc.)
|
|
161
|
+
if (msg.type !== 'user' && msg.type !== 'assistant')
|
|
162
|
+
continue;
|
|
163
|
+
if (msg.type === 'user' && this.isToolResult(msg)) {
|
|
164
|
+
firstRealMessage = msg;
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
if (this.shouldFilterMessage(msg))
|
|
168
|
+
continue;
|
|
169
|
+
firstRealMessage = msg;
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
if (!firstRealMessage) {
|
|
173
|
+
let lastUuid = syncState.lastSyncedMessageUuid || '';
|
|
174
|
+
for (let i = newMessages.length - 1; i >= 0; i--) {
|
|
175
|
+
if (newMessages[i].uuid) {
|
|
176
|
+
lastUuid = newMessages[i].uuid;
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return {
|
|
181
|
+
history: [],
|
|
182
|
+
isTurnContinuation: false,
|
|
183
|
+
lastProcessedMessageUuid: lastUuid,
|
|
184
|
+
currentHistoryIndex: syncState.lastSyncedHistoryIndex
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
const isNewUserMessage = firstRealMessage.type === 'user' &&
|
|
188
|
+
!this.isToolResult(firstRealMessage);
|
|
189
|
+
const isTurnContinuation = !isNewUserMessage;
|
|
190
|
+
let currentHistoryIndex = syncState.lastSyncedHistoryIndex;
|
|
191
|
+
if (!isTurnContinuation) {
|
|
192
|
+
currentHistoryIndex++;
|
|
193
|
+
}
|
|
194
|
+
let history;
|
|
195
|
+
let lastProcessedMessageUuid = '';
|
|
196
|
+
if (isTurnContinuation) {
|
|
197
|
+
const lastSyncedIndex = syncState.lastSyncedMessageUuid
|
|
198
|
+
? messages.findIndex((m) => m.uuid === syncState.lastSyncedMessageUuid)
|
|
199
|
+
: -1;
|
|
200
|
+
let turnStartIndex = 0;
|
|
201
|
+
if (lastSyncedIndex >= 0) {
|
|
202
|
+
for (let i = lastSyncedIndex; i >= 0; i--) {
|
|
203
|
+
const msg = messages[i];
|
|
204
|
+
if (!msg.uuid)
|
|
205
|
+
continue;
|
|
206
|
+
if (msg.type === 'user' && !this.shouldFilterMessage(msg) && !this.isToolResult(msg)) {
|
|
207
|
+
turnStartIndex = i;
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
let turnEndIndex = messages.length;
|
|
213
|
+
for (let i = startIndex; i < messages.length; i++) {
|
|
214
|
+
const msg = messages[i];
|
|
215
|
+
if (!msg.uuid)
|
|
216
|
+
continue;
|
|
217
|
+
// Stop at system messages (e.g., stop hooks)
|
|
218
|
+
if (msg.type === 'system') {
|
|
219
|
+
turnEndIndex = i;
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
if (msg.type === 'user' && !this.shouldFilterMessage(msg) && !this.isToolResult(msg)) {
|
|
223
|
+
turnEndIndex = i;
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
const turnMessages = messages.slice(turnStartIndex, turnEndIndex);
|
|
228
|
+
const turnHistory = await this.transformTurn(turnMessages, currentHistoryIndex, assistantId, agentName, sessionFilePath);
|
|
229
|
+
history = turnHistory.filter((entry) => entry.role === 'Assistant');
|
|
230
|
+
for (let i = turnEndIndex - 1; i >= turnStartIndex; i--) {
|
|
231
|
+
if (messages[i].uuid) {
|
|
232
|
+
lastProcessedMessageUuid = messages[i].uuid;
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
let firstUserIndex = startIndex;
|
|
239
|
+
for (let i = startIndex; i < messages.length; i++) {
|
|
240
|
+
const msg = messages[i];
|
|
241
|
+
if (!msg.uuid)
|
|
242
|
+
continue;
|
|
243
|
+
if (msg.type === 'user' && !this.shouldFilterMessage(msg) && !this.isToolResult(msg)) {
|
|
244
|
+
firstUserIndex = i;
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
let turnEndIndex = messages.length;
|
|
249
|
+
for (let i = firstUserIndex + 1; i < messages.length; i++) {
|
|
250
|
+
const msg = messages[i];
|
|
251
|
+
if (!msg.uuid)
|
|
252
|
+
continue;
|
|
253
|
+
// Stop at system messages (e.g., stop hooks)
|
|
254
|
+
if (msg.type === 'system') {
|
|
255
|
+
turnEndIndex = i;
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
if (msg.type === 'user' && !this.shouldFilterMessage(msg) && !this.isToolResult(msg)) {
|
|
259
|
+
turnEndIndex = i;
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
const turnMessages = messages.slice(firstUserIndex, turnEndIndex);
|
|
264
|
+
history = await this.transformTurn(turnMessages, currentHistoryIndex, assistantId, agentName, sessionFilePath);
|
|
265
|
+
for (let i = turnEndIndex - 1; i >= firstUserIndex; i--) {
|
|
266
|
+
if (messages[i].uuid) {
|
|
267
|
+
lastProcessedMessageUuid = messages[i].uuid;
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return {
|
|
273
|
+
history,
|
|
274
|
+
isTurnContinuation,
|
|
275
|
+
lastProcessedMessageUuid,
|
|
276
|
+
currentHistoryIndex
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
async transformTurn(turnMessages, historyIndex, assistantId, agentName, sessionFilePath) {
|
|
280
|
+
const history = [];
|
|
281
|
+
const toolResultsMap = this.buildToolResultsMap(turnMessages);
|
|
282
|
+
let userMessage = null;
|
|
283
|
+
for (const msg of turnMessages) {
|
|
284
|
+
if (msg.type === 'user' && !this.shouldFilterMessage(msg) && !this.isToolResult(msg)) {
|
|
285
|
+
userMessage = msg;
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
if (!userMessage) {
|
|
290
|
+
return [];
|
|
291
|
+
}
|
|
292
|
+
const userText = this.extractUserMessage(userMessage);
|
|
293
|
+
history.push({
|
|
294
|
+
role: 'User',
|
|
295
|
+
message: userText,
|
|
296
|
+
history_index: historyIndex,
|
|
297
|
+
date: userMessage.timestamp,
|
|
298
|
+
message_raw: userText,
|
|
299
|
+
file_names: []
|
|
300
|
+
});
|
|
301
|
+
const assistantMessages = [];
|
|
302
|
+
const metaMessages = [];
|
|
303
|
+
const systemErrors = [];
|
|
304
|
+
for (const msg of turnMessages) {
|
|
305
|
+
if (msg.type === 'assistant') {
|
|
306
|
+
assistantMessages.push(msg);
|
|
307
|
+
}
|
|
308
|
+
else if (msg.type === 'user' && msg.isMeta) {
|
|
309
|
+
metaMessages.push(msg);
|
|
310
|
+
}
|
|
311
|
+
else if (msg.type === 'system' && msg.subtype === 'api_error') {
|
|
312
|
+
systemErrors.push(msg);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
if (assistantMessages.length > 0) {
|
|
316
|
+
const finalAssistantMsg = assistantMessages[assistantMessages.length - 1];
|
|
317
|
+
const allThoughts = [];
|
|
318
|
+
for (const metaMsg of metaMessages) {
|
|
319
|
+
const metaText = this.extractTextContent(metaMsg);
|
|
320
|
+
if (metaText.trim()) {
|
|
321
|
+
allThoughts.push(this.createCodemieThought(metaMsg.uuid, metaText, agentName || 'Claude Code', metaMsg.timestamp));
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
for (let k = 0; k < assistantMessages.length; k++) {
|
|
325
|
+
const assistantMsg = assistantMessages[k];
|
|
326
|
+
const isIntermediateMsg = k < assistantMessages.length - 1;
|
|
327
|
+
const hasError = assistantMsg.message?.Output?.__type || assistantMsg.message?.error;
|
|
328
|
+
if (hasError) {
|
|
329
|
+
const errorType = assistantMsg.message?.Output?.__type || 'Error';
|
|
330
|
+
const errorMsg = assistantMsg.message?.error?.message || errorType;
|
|
331
|
+
allThoughts.push({
|
|
332
|
+
id: assistantMsg.uuid,
|
|
333
|
+
metadata: {
|
|
334
|
+
timestamp: assistantMsg.timestamp,
|
|
335
|
+
error_type: errorType
|
|
336
|
+
},
|
|
337
|
+
in_progress: false,
|
|
338
|
+
author_type: 'Agent',
|
|
339
|
+
author_name: this.getAgentDisplayName(agentName || assistantMsg.message?.model || 'claude'),
|
|
340
|
+
message: `Error: ${errorMsg}`,
|
|
341
|
+
input_text: '',
|
|
342
|
+
output_format: 'error',
|
|
343
|
+
error: true,
|
|
344
|
+
children: []
|
|
345
|
+
});
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
const toolCalls = this.extractToolCalls(assistantMsg);
|
|
349
|
+
for (const toolCall of toolCalls) {
|
|
350
|
+
const toolResult = toolResultsMap.get(toolCall.id);
|
|
351
|
+
const shouldAddTool = toolResult !== undefined || isIntermediateMsg;
|
|
352
|
+
if (shouldAddTool) {
|
|
353
|
+
allThoughts.push(this.createToolThought(toolCall, toolResult));
|
|
354
|
+
if (toolResult?.agentId && sessionFilePath) {
|
|
355
|
+
try {
|
|
356
|
+
const subagentType = toolCall.name === 'Task' && toolCall.input?.subagent_type
|
|
357
|
+
? String(toolCall.input.subagent_type)
|
|
358
|
+
: undefined;
|
|
359
|
+
const agentFile = await this.findAgentFileByAgentId(sessionFilePath, toolResult.agentId);
|
|
360
|
+
if (agentFile) {
|
|
361
|
+
const parsed = await this.parseAgentFile(agentFile, subagentType);
|
|
362
|
+
if (parsed) {
|
|
363
|
+
const agentThought = this.createAgentThought(parsed);
|
|
364
|
+
allThoughts.push(agentThought);
|
|
365
|
+
logger.debug(`[${this.name}] Added Agent thought for ${toolResult.slug || toolResult.agentId}: ` +
|
|
366
|
+
`${parsed.toolChildren.length} tools, ${parsed.agentMessage.length} chars`);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
catch (error) {
|
|
371
|
+
logger.error(`[${this.name}] Failed to process agent file for ${toolResult.agentId}:`, error);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
if (isIntermediateMsg) {
|
|
377
|
+
const intermediateText = this.extractTextContent(assistantMsg);
|
|
378
|
+
if (intermediateText.trim()) {
|
|
379
|
+
allThoughts.push(this.createCodemieThought(assistantMsg.uuid, intermediateText, agentName || assistantMsg.message?.model || 'claude', assistantMsg.timestamp));
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
let totalInputTokens = 0;
|
|
384
|
+
let totalOutputTokens = 0;
|
|
385
|
+
let totalCacheCreationTokens = 0;
|
|
386
|
+
let totalCacheReadTokens = 0;
|
|
387
|
+
for (const assistantMsg of assistantMessages) {
|
|
388
|
+
const usage = assistantMsg.message?.usage;
|
|
389
|
+
if (usage) {
|
|
390
|
+
totalInputTokens += usage.input_tokens || 0;
|
|
391
|
+
totalOutputTokens += usage.output_tokens || 0;
|
|
392
|
+
totalCacheCreationTokens += usage.cache_creation_input_tokens || 0;
|
|
393
|
+
totalCacheReadTokens += usage.cache_read_input_tokens || 0;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
for (const thought of allThoughts) {
|
|
397
|
+
if (thought.author_type === 'Agent' && thought.metadata?.token_usage) {
|
|
398
|
+
const agentTokens = thought.metadata.token_usage;
|
|
399
|
+
totalInputTokens += agentTokens.input || 0;
|
|
400
|
+
totalOutputTokens += agentTokens.output || 0;
|
|
401
|
+
totalCacheCreationTokens += agentTokens.cacheCreation || 0;
|
|
402
|
+
totalCacheReadTokens += agentTokens.cacheRead || 0;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
const assistantText = this.extractTextContent(finalAssistantMsg);
|
|
406
|
+
const finalHasError = finalAssistantMsg.message?.Output?.__type ||
|
|
407
|
+
finalAssistantMsg.message?.error;
|
|
408
|
+
let errorMessage = finalHasError
|
|
409
|
+
? `Error: ${finalAssistantMsg.message?.Output?.__type ||
|
|
410
|
+
finalAssistantMsg.message?.error?.message || 'Unknown error'}`
|
|
411
|
+
: assistantText;
|
|
412
|
+
if (!errorMessage.trim() && allThoughts.length === 0) {
|
|
413
|
+
return history;
|
|
414
|
+
}
|
|
415
|
+
const response_time = this.calculateDuration(userMessage.timestamp, finalAssistantMsg.timestamp);
|
|
416
|
+
history.push({
|
|
417
|
+
role: 'Assistant',
|
|
418
|
+
message: errorMessage,
|
|
419
|
+
message_raw: finalHasError ? errorMessage : (assistantText || errorMessage),
|
|
420
|
+
history_index: historyIndex,
|
|
421
|
+
date: finalAssistantMsg.timestamp,
|
|
422
|
+
response_time,
|
|
423
|
+
input_tokens: totalInputTokens,
|
|
424
|
+
output_tokens: totalOutputTokens,
|
|
425
|
+
cache_creation_input_tokens: totalCacheCreationTokens,
|
|
426
|
+
cache_read_input_tokens: totalCacheReadTokens,
|
|
427
|
+
assistant_id: assistantId,
|
|
428
|
+
thoughts: allThoughts.length > 0 ? allThoughts : undefined
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
else if (systemErrors.length > 0) {
|
|
432
|
+
const errorThoughts = systemErrors.map((error) => {
|
|
433
|
+
const errorMsg = error.error?.error?.Message ||
|
|
434
|
+
error.error?.error?.message || 'Unknown error';
|
|
435
|
+
const errorStatus = error.error?.status || 'unknown';
|
|
436
|
+
return {
|
|
437
|
+
id: error.uuid,
|
|
438
|
+
metadata: {
|
|
439
|
+
timestamp: error.timestamp,
|
|
440
|
+
error_status: errorStatus
|
|
441
|
+
},
|
|
442
|
+
in_progress: false,
|
|
443
|
+
author_type: 'Agent',
|
|
444
|
+
author_name: this.getAgentDisplayName(agentName || 'claude'),
|
|
445
|
+
message: `API Error (${errorStatus}): ${errorMsg}`,
|
|
446
|
+
input_text: '',
|
|
447
|
+
output_format: 'error',
|
|
448
|
+
error: true,
|
|
449
|
+
children: []
|
|
450
|
+
};
|
|
451
|
+
});
|
|
452
|
+
const lastError = systemErrors[systemErrors.length - 1];
|
|
453
|
+
const response_time = this.calculateDuration(userMessage.timestamp, lastError.timestamp);
|
|
454
|
+
history.push({
|
|
455
|
+
role: 'Assistant',
|
|
456
|
+
message: `Failed after ${systemErrors.length} error(s): ${errorThoughts[0].message}`,
|
|
457
|
+
message_raw: `Failed after ${systemErrors.length} error(s)`,
|
|
458
|
+
history_index: historyIndex,
|
|
459
|
+
date: lastError.timestamp,
|
|
460
|
+
response_time,
|
|
461
|
+
assistant_id: assistantId,
|
|
462
|
+
thoughts: errorThoughts
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
return history;
|
|
466
|
+
}
|
|
467
|
+
shouldFilterMessage(msg) {
|
|
468
|
+
// Filter system messages (including stop hooks)
|
|
469
|
+
if (msg.type === 'system')
|
|
470
|
+
return true;
|
|
471
|
+
return this.isConversationSplitter(msg) ||
|
|
472
|
+
this.isSystemMessage(msg) ||
|
|
473
|
+
this.isToolResult(msg);
|
|
474
|
+
}
|
|
475
|
+
isConversationSplitter(msg) {
|
|
476
|
+
return this.hasCommand(msg, ['/clear']);
|
|
477
|
+
}
|
|
478
|
+
isSystemMessage(msg) {
|
|
479
|
+
if (msg.type !== 'user')
|
|
480
|
+
return false;
|
|
481
|
+
if (this.hasCommand(msg, ['/compact', '/compress'])) {
|
|
482
|
+
return true;
|
|
483
|
+
}
|
|
484
|
+
const text = this.extractTextContent(msg);
|
|
485
|
+
if (!text)
|
|
486
|
+
return false;
|
|
487
|
+
const patterns = [
|
|
488
|
+
'Caveat: The messages below were generated by the user while running local commands',
|
|
489
|
+
'<local-command-caveat>',
|
|
490
|
+
'Unknown slash command:',
|
|
491
|
+
'<local-command-stdout>',
|
|
492
|
+
'[Request interrupted by user'
|
|
493
|
+
];
|
|
494
|
+
return patterns.some(pattern => text.startsWith(pattern));
|
|
495
|
+
}
|
|
496
|
+
isToolResult(msg) {
|
|
497
|
+
if (msg.type !== 'user')
|
|
498
|
+
return false;
|
|
499
|
+
const content = msg.message?.content;
|
|
500
|
+
if (!Array.isArray(content))
|
|
501
|
+
return false;
|
|
502
|
+
const hasToolResult = content.some((item) => item.type === 'tool_result');
|
|
503
|
+
if (!hasToolResult)
|
|
504
|
+
return false;
|
|
505
|
+
const hasText = content.some((item) => item.type === 'text' && item.text?.trim());
|
|
506
|
+
return hasToolResult && !hasText;
|
|
507
|
+
}
|
|
508
|
+
hasCommand(msg, commands) {
|
|
509
|
+
if (msg.type !== 'user')
|
|
510
|
+
return false;
|
|
511
|
+
const content = msg.message?.content;
|
|
512
|
+
if (typeof content === 'string') {
|
|
513
|
+
return commands.some(cmd => content.includes(`<command-name>${cmd}</command-name>`));
|
|
514
|
+
}
|
|
515
|
+
if (Array.isArray(content)) {
|
|
516
|
+
for (const item of content) {
|
|
517
|
+
if (item.type === 'text' && item.text) {
|
|
518
|
+
if (commands.some(cmd => item.text?.includes(`<command-name>${cmd}</command-name>`))) {
|
|
519
|
+
return true;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
return false;
|
|
525
|
+
}
|
|
526
|
+
buildToolResultsMap(messages) {
|
|
527
|
+
const map = new Map();
|
|
528
|
+
for (const msg of messages) {
|
|
529
|
+
if (this.isToolResult(msg)) {
|
|
530
|
+
const content = msg.message?.content;
|
|
531
|
+
if (Array.isArray(content)) {
|
|
532
|
+
for (const item of content) {
|
|
533
|
+
if (item.type === 'tool_result') {
|
|
534
|
+
const isError = item.is_error === true || item.isError === true;
|
|
535
|
+
let textContent = '';
|
|
536
|
+
if (typeof item.content === 'string') {
|
|
537
|
+
textContent = item.content;
|
|
538
|
+
}
|
|
539
|
+
else if (Array.isArray(item.content)) {
|
|
540
|
+
textContent = item.content
|
|
541
|
+
.filter((c) => c.type === 'text')
|
|
542
|
+
.map((c) => c.text || '')
|
|
543
|
+
.join('\n\n');
|
|
544
|
+
}
|
|
545
|
+
const agentId = msg.toolUseResult?.agentId;
|
|
546
|
+
const slug = msg.toolUseResult?.slug;
|
|
547
|
+
map.set(item.tool_use_id || '', {
|
|
548
|
+
content: textContent,
|
|
549
|
+
isError,
|
|
550
|
+
agentId,
|
|
551
|
+
slug
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
return map;
|
|
559
|
+
}
|
|
560
|
+
extractUserMessage(msg) {
|
|
561
|
+
const content = msg.message?.content;
|
|
562
|
+
if (typeof content === 'string') {
|
|
563
|
+
const command = this.extractCommand(content);
|
|
564
|
+
if (command) {
|
|
565
|
+
return command;
|
|
566
|
+
}
|
|
567
|
+
return content;
|
|
568
|
+
}
|
|
569
|
+
if (Array.isArray(content)) {
|
|
570
|
+
const textParts = content
|
|
571
|
+
.filter((item) => item.type === 'text')
|
|
572
|
+
.map((item) => {
|
|
573
|
+
const text = item.text || '';
|
|
574
|
+
const command = this.extractCommand(text);
|
|
575
|
+
if (command) {
|
|
576
|
+
return command;
|
|
577
|
+
}
|
|
578
|
+
return text;
|
|
579
|
+
});
|
|
580
|
+
return textParts.join('\n\n');
|
|
581
|
+
}
|
|
582
|
+
return '';
|
|
583
|
+
}
|
|
584
|
+
extractTextContent(msg) {
|
|
585
|
+
const content = msg.message?.content;
|
|
586
|
+
if (typeof content === 'string') {
|
|
587
|
+
return content;
|
|
588
|
+
}
|
|
589
|
+
if (Array.isArray(content)) {
|
|
590
|
+
const textParts = content
|
|
591
|
+
.filter((item) => item.type === 'text' || item.type === 'thinking')
|
|
592
|
+
.map((item) => {
|
|
593
|
+
if (item.type === 'thinking') {
|
|
594
|
+
return item.thinking || '';
|
|
595
|
+
}
|
|
596
|
+
return item.text || '';
|
|
597
|
+
});
|
|
598
|
+
return textParts.join('\n\n');
|
|
599
|
+
}
|
|
600
|
+
return '';
|
|
601
|
+
}
|
|
602
|
+
extractCommand(content) {
|
|
603
|
+
const commandMatch = content.match(/<command-name>(\/[^<]+)<\/command-name>/);
|
|
604
|
+
return commandMatch ? commandMatch[1] : null;
|
|
605
|
+
}
|
|
606
|
+
extractToolCalls(msg) {
|
|
607
|
+
const content = msg.message?.content;
|
|
608
|
+
if (!Array.isArray(content))
|
|
609
|
+
return [];
|
|
610
|
+
return content.filter((item) => item.type === 'tool_use');
|
|
611
|
+
}
|
|
612
|
+
createToolThought(toolCall, toolResult) {
|
|
613
|
+
return {
|
|
614
|
+
id: toolCall.id,
|
|
615
|
+
metadata: {},
|
|
616
|
+
in_progress: false,
|
|
617
|
+
input_text: JSON.stringify(toolCall.input),
|
|
618
|
+
message: toolResult?.content || '',
|
|
619
|
+
author_type: 'Tool',
|
|
620
|
+
author_name: toolCall.name,
|
|
621
|
+
output_format: 'text',
|
|
622
|
+
error: toolResult?.isError || false,
|
|
623
|
+
children: []
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
createCodemieThought(id, message, agentName, timestamp) {
|
|
627
|
+
// Get display name from agent metadata
|
|
628
|
+
const displayName = this.getAgentDisplayName(agentName);
|
|
629
|
+
return {
|
|
630
|
+
id,
|
|
631
|
+
metadata: {
|
|
632
|
+
timestamp,
|
|
633
|
+
type: 'intermediate_response'
|
|
634
|
+
},
|
|
635
|
+
in_progress: false,
|
|
636
|
+
input_text: '',
|
|
637
|
+
message,
|
|
638
|
+
author_type: 'Agent',
|
|
639
|
+
author_name: displayName,
|
|
640
|
+
output_format: 'text',
|
|
641
|
+
error: false,
|
|
642
|
+
children: []
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
async findAgentFileByAgentId(sessionFilePath, agentId) {
|
|
646
|
+
try {
|
|
647
|
+
const { dirname, basename, join } = await import('path');
|
|
648
|
+
const { existsSync } = await import('fs');
|
|
649
|
+
const parentDir = dirname(sessionFilePath);
|
|
650
|
+
const filename = basename(sessionFilePath);
|
|
651
|
+
const sessionId = filename.replace('.jsonl', '');
|
|
652
|
+
if (!sessionId) {
|
|
653
|
+
return null;
|
|
654
|
+
}
|
|
655
|
+
const subagentsDir = join(parentDir, sessionId, 'subagents');
|
|
656
|
+
if (!existsSync(subagentsDir)) {
|
|
657
|
+
return null;
|
|
658
|
+
}
|
|
659
|
+
const agentFilePath = join(subagentsDir, `agent-${agentId}.jsonl`);
|
|
660
|
+
if (existsSync(agentFilePath)) {
|
|
661
|
+
logger.debug(`[${this.name}] Found agent file for ${agentId}: ${agentFilePath}`);
|
|
662
|
+
return agentFilePath;
|
|
663
|
+
}
|
|
664
|
+
logger.debug(`[${this.name}] Agent file not found for ${agentId} in ${subagentsDir}`);
|
|
665
|
+
return null;
|
|
666
|
+
}
|
|
667
|
+
catch (error) {
|
|
668
|
+
logger.debug(`[${this.name}] Failed to find agent file by agentId:`, error);
|
|
669
|
+
return null;
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
async parseAgentFile(agentFilePath, subagentType) {
|
|
673
|
+
try {
|
|
674
|
+
const { readFile } = await import('fs/promises');
|
|
675
|
+
const { existsSync } = await import('fs');
|
|
676
|
+
if (!existsSync(agentFilePath)) {
|
|
677
|
+
return null;
|
|
678
|
+
}
|
|
679
|
+
const content = await readFile(agentFilePath, 'utf-8');
|
|
680
|
+
const lines = content.trim().split('\n').filter(line => line.length > 0);
|
|
681
|
+
const records = [];
|
|
682
|
+
for (const line of lines) {
|
|
683
|
+
try {
|
|
684
|
+
records.push(JSON.parse(line));
|
|
685
|
+
}
|
|
686
|
+
catch (error) {
|
|
687
|
+
logger.warn(`[${this.name}] Failed to parse line in ${agentFilePath}:`, error);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
if (records.length === 0) {
|
|
691
|
+
logger.debug(`[${this.name}] Empty agent file: ${agentFilePath}`);
|
|
692
|
+
return null;
|
|
693
|
+
}
|
|
694
|
+
const firstRecord = records[0];
|
|
695
|
+
if (!firstRecord.isSidechain) {
|
|
696
|
+
logger.warn(`[${this.name}] File is not a sidechain: ${agentFilePath}`);
|
|
697
|
+
return null;
|
|
698
|
+
}
|
|
699
|
+
const agentId = firstRecord.agentId;
|
|
700
|
+
const sessionId = firstRecord.sessionId;
|
|
701
|
+
const slug = records.find((r) => r.slug)?.slug || 'Agent';
|
|
702
|
+
let agentMessage = '';
|
|
703
|
+
const toolChildren = [];
|
|
704
|
+
const tokenUsage = {
|
|
705
|
+
input: 0,
|
|
706
|
+
output: 0,
|
|
707
|
+
cacheCreation: 0,
|
|
708
|
+
cacheRead: 0
|
|
709
|
+
};
|
|
710
|
+
for (const record of records) {
|
|
711
|
+
if (record.sessionId !== sessionId) {
|
|
712
|
+
logger.warn(`[${this.name}] Session ID mismatch in ${agentFilePath}: ` +
|
|
713
|
+
`expected ${sessionId}, got ${record.sessionId}`);
|
|
714
|
+
continue;
|
|
715
|
+
}
|
|
716
|
+
const content = record.message.content;
|
|
717
|
+
if (typeof content === 'string') {
|
|
718
|
+
agentMessage += content + '\n\n';
|
|
719
|
+
}
|
|
720
|
+
else if (Array.isArray(content)) {
|
|
721
|
+
for (const item of content) {
|
|
722
|
+
if (item.type === 'text') {
|
|
723
|
+
agentMessage += (item.text || '') + '\n\n';
|
|
724
|
+
}
|
|
725
|
+
else if (item.type === 'thinking') {
|
|
726
|
+
agentMessage += (item.thinking || '') + '\n\n';
|
|
727
|
+
}
|
|
728
|
+
else if (item.type === 'tool_use') {
|
|
729
|
+
toolChildren.push({
|
|
730
|
+
id: item.id || `tool-${record.uuid}`,
|
|
731
|
+
parent_id: 'latest',
|
|
732
|
+
metadata: {
|
|
733
|
+
timestamp: record.timestamp
|
|
734
|
+
},
|
|
735
|
+
in_progress: false,
|
|
736
|
+
input_text: JSON.stringify(item.input || {}),
|
|
737
|
+
message: '',
|
|
738
|
+
author_type: 'Tool',
|
|
739
|
+
author_name: item.name || 'Unknown',
|
|
740
|
+
output_format: 'text',
|
|
741
|
+
error: false,
|
|
742
|
+
children: []
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
const usage = record.message.usage;
|
|
748
|
+
if (usage) {
|
|
749
|
+
tokenUsage.input += usage.input_tokens || 0;
|
|
750
|
+
tokenUsage.output += usage.output_tokens || 0;
|
|
751
|
+
tokenUsage.cacheCreation += usage.cache_creation_input_tokens || 0;
|
|
752
|
+
tokenUsage.cacheRead += usage.cache_read_input_tokens || 0;
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
for (const record of records) {
|
|
756
|
+
if (record.sessionId !== sessionId) {
|
|
757
|
+
continue;
|
|
758
|
+
}
|
|
759
|
+
const content = record.message.content;
|
|
760
|
+
if (Array.isArray(content)) {
|
|
761
|
+
for (const item of content) {
|
|
762
|
+
if (item.type === 'tool_result') {
|
|
763
|
+
const toolThought = toolChildren.find((t) => t.id === item.tool_use_id);
|
|
764
|
+
if (toolThought) {
|
|
765
|
+
if (typeof item.content === 'string') {
|
|
766
|
+
toolThought.message = item.content;
|
|
767
|
+
}
|
|
768
|
+
else if (Array.isArray(item.content)) {
|
|
769
|
+
toolThought.message = item.content
|
|
770
|
+
.map((c) => c.type === 'text' ? c.text : '')
|
|
771
|
+
.filter((t) => t.length > 0)
|
|
772
|
+
.join('\n\n');
|
|
773
|
+
}
|
|
774
|
+
if (item.is_error || item.isError) {
|
|
775
|
+
toolThought.error = true;
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
return {
|
|
783
|
+
agentId,
|
|
784
|
+
slug,
|
|
785
|
+
subagentType,
|
|
786
|
+
agentMessage: agentMessage.trim(),
|
|
787
|
+
toolChildren,
|
|
788
|
+
tokenUsage,
|
|
789
|
+
startTimestamp: records[0].timestamp,
|
|
790
|
+
endTimestamp: records[records.length - 1].timestamp
|
|
791
|
+
};
|
|
792
|
+
}
|
|
793
|
+
catch (error) {
|
|
794
|
+
logger.error(`[${this.name}] Failed to parse agent file ${agentFilePath}:`, error);
|
|
795
|
+
return null;
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
createAgentThought(parsed) {
|
|
799
|
+
return {
|
|
800
|
+
id: `agent-${parsed.agentId}`,
|
|
801
|
+
metadata: {
|
|
802
|
+
agent_id: parsed.agentId,
|
|
803
|
+
slug: parsed.slug,
|
|
804
|
+
subagent_type: parsed.subagentType,
|
|
805
|
+
start_timestamp: parsed.startTimestamp,
|
|
806
|
+
end_timestamp: parsed.endTimestamp,
|
|
807
|
+
token_usage: parsed.tokenUsage
|
|
808
|
+
},
|
|
809
|
+
in_progress: false,
|
|
810
|
+
input_text: '',
|
|
811
|
+
message: parsed.agentMessage,
|
|
812
|
+
author_type: 'Agent',
|
|
813
|
+
author_name: parsed.subagentType || parsed.slug,
|
|
814
|
+
output_format: 'text',
|
|
815
|
+
error: false,
|
|
816
|
+
children: parsed.toolChildren
|
|
817
|
+
};
|
|
818
|
+
}
|
|
819
|
+
calculateDuration(startTimestamp, endTimestamp) {
|
|
820
|
+
try {
|
|
821
|
+
const startMs = new Date(startTimestamp).getTime();
|
|
822
|
+
const endMs = new Date(endTimestamp).getTime();
|
|
823
|
+
if (isNaN(startMs) || isNaN(endMs)) {
|
|
824
|
+
return undefined;
|
|
825
|
+
}
|
|
826
|
+
const durationMs = endMs - startMs;
|
|
827
|
+
if (durationMs < 0) {
|
|
828
|
+
logger.warn('[conversations] Negative duration detected (clock skew?):', { startTimestamp, endTimestamp });
|
|
829
|
+
return 0;
|
|
830
|
+
}
|
|
831
|
+
const durationSec = durationMs / 1000;
|
|
832
|
+
return Math.round(durationSec * 100) / 100;
|
|
833
|
+
}
|
|
834
|
+
catch (error) {
|
|
835
|
+
logger.error('[conversations] Error calculating duration:', error);
|
|
836
|
+
return undefined;
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
//# sourceMappingURL=claude.conversations-processor.js.map
|