codehere 0.4.0 → 0.5.0-alpha
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/LICENSE +1 -1
- package/README.md +113 -30
- package/dist/application/agents/execution-agent.js +2 -2
- package/dist/application/agents/execution-agent.js.map +1 -1
- package/dist/application/agents/multi-agent-orchestrator.d.ts +1 -0
- package/dist/application/agents/multi-agent-orchestrator.d.ts.map +1 -1
- package/dist/application/agents/multi-agent-orchestrator.js +10 -3
- package/dist/application/agents/multi-agent-orchestrator.js.map +1 -1
- package/dist/application/agents/planning-agent.d.ts.map +1 -1
- package/dist/application/agents/planning-agent.js +22 -10
- package/dist/application/agents/planning-agent.js.map +1 -1
- package/dist/application/agents/validation-agent.js +2 -2
- package/dist/application/agents/validation-agent.js.map +1 -1
- package/dist/application/reasoning/multi-model-planning-strategy.d.ts +21 -0
- package/dist/application/reasoning/multi-model-planning-strategy.d.ts.map +1 -0
- package/dist/application/reasoning/multi-model-planning-strategy.js +158 -0
- package/dist/application/reasoning/multi-model-planning-strategy.js.map +1 -0
- package/dist/application/reasoning/reasoning-config.d.ts +15 -0
- package/dist/application/reasoning/reasoning-config.d.ts.map +1 -0
- package/dist/application/reasoning/reasoning-config.js +50 -0
- package/dist/application/reasoning/reasoning-config.js.map +1 -0
- package/dist/application/reasoning/reasoning-orchestrator.d.ts +18 -0
- package/dist/application/reasoning/reasoning-orchestrator.d.ts.map +1 -0
- package/dist/application/reasoning/reasoning-orchestrator.js +170 -0
- package/dist/application/reasoning/reasoning-orchestrator.js.map +1 -0
- package/dist/application/reasoning/reasoning-strategy.interface.d.ts +24 -0
- package/dist/application/reasoning/reasoning-strategy.interface.d.ts.map +1 -0
- package/dist/application/reasoning/reasoning-strategy.interface.js +6 -0
- package/dist/application/reasoning/reasoning-strategy.interface.js.map +1 -0
- package/dist/application/reasoning/role-provider-resolver.d.ts +36 -0
- package/dist/application/reasoning/role-provider-resolver.d.ts.map +1 -0
- package/dist/application/reasoning/role-provider-resolver.js +74 -0
- package/dist/application/reasoning/role-provider-resolver.js.map +1 -0
- package/dist/application/reasoning/simple-planning-strategy.d.ts +22 -0
- package/dist/application/reasoning/simple-planning-strategy.d.ts.map +1 -0
- package/dist/application/reasoning/simple-planning-strategy.js +217 -0
- package/dist/application/reasoning/simple-planning-strategy.js.map +1 -0
- package/dist/application/reasoning/types.d.ts +65 -0
- package/dist/application/reasoning/types.d.ts.map +1 -0
- package/dist/application/reasoning/types.js +6 -0
- package/dist/application/reasoning/types.js.map +1 -0
- package/dist/application/reasoning/validator-strategy.d.ts +56 -0
- package/dist/application/reasoning/validator-strategy.d.ts.map +1 -0
- package/dist/application/reasoning/validator-strategy.js +103 -0
- package/dist/application/reasoning/validator-strategy.js.map +1 -0
- package/dist/application/services/dependency-container.d.ts +30 -6
- package/dist/application/services/dependency-container.d.ts.map +1 -1
- package/dist/application/services/dependency-container.js +96 -44
- package/dist/application/services/dependency-container.js.map +1 -1
- package/dist/application/services/intelligent-router.d.ts +6 -0
- package/dist/application/services/intelligent-router.d.ts.map +1 -1
- package/dist/application/services/intelligent-router.js +98 -9
- package/dist/application/services/intelligent-router.js.map +1 -1
- package/dist/application/use-cases/ask-question-use-case.d.ts +1 -0
- package/dist/application/use-cases/ask-question-use-case.d.ts.map +1 -1
- package/dist/application/use-cases/ask-question-use-case.js +4 -3
- package/dist/application/use-cases/ask-question-use-case.js.map +1 -1
- package/dist/application/use-cases/planning-use-case.d.ts +14 -1
- package/dist/application/use-cases/planning-use-case.d.ts.map +1 -1
- package/dist/application/use-cases/planning-use-case.js +109 -2
- package/dist/application/use-cases/planning-use-case.js.map +1 -1
- package/dist/domain/entities/memory.d.ts.map +1 -1
- package/dist/domain/entities/task.d.ts +1 -1
- package/dist/domain/entities/task.d.ts.map +1 -1
- package/dist/domain/entities/task.js +2 -2
- package/dist/domain/entities/task.js.map +1 -1
- package/dist/domain/errors/embeddings-not-found-error.d.ts +9 -0
- package/dist/domain/errors/embeddings-not-found-error.d.ts.map +1 -0
- package/dist/domain/errors/embeddings-not-found-error.js +13 -0
- package/dist/domain/errors/embeddings-not-found-error.js.map +1 -0
- package/dist/domain/interfaces/embedding-repository.interface.d.ts +5 -0
- package/dist/domain/interfaces/embedding-repository.interface.d.ts.map +1 -1
- package/dist/domain/services/environment-mode-manager.d.ts +4 -10
- package/dist/domain/services/environment-mode-manager.d.ts.map +1 -1
- package/dist/domain/services/environment-mode-manager.js +7 -22
- package/dist/domain/services/environment-mode-manager.js.map +1 -1
- package/dist/domain/services/query-intent-classifier.d.ts.map +1 -1
- package/dist/domain/services/query-intent-classifier.js +20 -1
- package/dist/domain/services/query-intent-classifier.js.map +1 -1
- package/dist/domain/services/risk-tier-detector.d.ts +8 -9
- package/dist/domain/services/risk-tier-detector.d.ts.map +1 -1
- package/dist/domain/services/risk-tier-detector.js +53 -40
- package/dist/domain/services/risk-tier-detector.js.map +1 -1
- package/dist/embed.d.ts.map +1 -1
- package/dist/embed.js +18 -8
- package/dist/embed.js.map +1 -1
- package/dist/index.js +405 -52
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/ai/cohere-ai-service.js +4 -4
- package/dist/infrastructure/ai/cohere-ai-service.js.map +1 -1
- package/dist/infrastructure/ai/provider-ai-service.d.ts.map +1 -1
- package/dist/infrastructure/ai/provider-ai-service.js +7 -7
- package/dist/infrastructure/ai/provider-ai-service.js.map +1 -1
- package/dist/infrastructure/cache/query-result-cache.d.ts +14 -55
- package/dist/infrastructure/cache/query-result-cache.d.ts.map +1 -1
- package/dist/infrastructure/cache/query-result-cache.js +40 -112
- package/dist/infrastructure/cache/query-result-cache.js.map +1 -1
- package/dist/infrastructure/cache/response-cache.d.ts +10 -78
- package/dist/infrastructure/cache/response-cache.d.ts.map +1 -1
- package/dist/infrastructure/cache/response-cache.js +22 -198
- package/dist/infrastructure/cache/response-cache.js.map +1 -1
- package/dist/infrastructure/cache/security-scan-cache.d.ts +8 -49
- package/dist/infrastructure/cache/security-scan-cache.d.ts.map +1 -1
- package/dist/infrastructure/cache/security-scan-cache.js +25 -102
- package/dist/infrastructure/cache/security-scan-cache.js.map +1 -1
- package/dist/infrastructure/completion/bash-completion.d.ts +2 -3
- package/dist/infrastructure/completion/bash-completion.d.ts.map +1 -1
- package/dist/infrastructure/completion/bash-completion.js +11 -87
- package/dist/infrastructure/completion/bash-completion.js.map +1 -1
- package/dist/infrastructure/completion/fish-completion.d.ts +2 -3
- package/dist/infrastructure/completion/fish-completion.d.ts.map +1 -1
- package/dist/infrastructure/completion/fish-completion.js +15 -58
- package/dist/infrastructure/completion/fish-completion.js.map +1 -1
- package/dist/infrastructure/completion/zsh-completion.d.ts +2 -3
- package/dist/infrastructure/completion/zsh-completion.d.ts.map +1 -1
- package/dist/infrastructure/completion/zsh-completion.js +18 -73
- package/dist/infrastructure/completion/zsh-completion.js.map +1 -1
- package/dist/infrastructure/config/config-manager.d.ts +10 -0
- package/dist/infrastructure/config/config-manager.d.ts.map +1 -1
- package/dist/infrastructure/config/config-manager.js +13 -2
- package/dist/infrastructure/config/config-manager.js.map +1 -1
- package/dist/infrastructure/context/conversation-context.d.ts +27 -31
- package/dist/infrastructure/context/conversation-context.d.ts.map +1 -1
- package/dist/infrastructure/context/conversation-context.js +95 -136
- package/dist/infrastructure/context/conversation-context.js.map +1 -1
- package/dist/infrastructure/context/session-manager.d.ts +27 -11
- package/dist/infrastructure/context/session-manager.d.ts.map +1 -1
- package/dist/infrastructure/context/session-manager.js +69 -73
- package/dist/infrastructure/context/session-manager.js.map +1 -1
- package/dist/infrastructure/protocols/a2a-metadata.js +1 -1
- package/dist/infrastructure/protocols/mcp-oauth.js +1 -1
- package/dist/infrastructure/providers/cohere-provider.d.ts.map +1 -1
- package/dist/infrastructure/providers/cohere-provider.js +102 -17
- package/dist/infrastructure/providers/cohere-provider.js.map +1 -1
- package/dist/infrastructure/providers/openrouter-provider.d.ts +42 -0
- package/dist/infrastructure/providers/openrouter-provider.d.ts.map +1 -0
- package/dist/infrastructure/providers/openrouter-provider.js +401 -0
- package/dist/infrastructure/providers/openrouter-provider.js.map +1 -0
- package/dist/infrastructure/providers/operation-provider-resolver.d.ts.map +1 -1
- package/dist/infrastructure/providers/operation-provider-resolver.js +33 -7
- package/dist/infrastructure/providers/operation-provider-resolver.js.map +1 -1
- package/dist/infrastructure/security/input-validator.d.ts.map +1 -1
- package/dist/infrastructure/security/input-validator.js +19 -6
- package/dist/infrastructure/security/input-validator.js.map +1 -1
- package/dist/infrastructure/serialization/toon-serializer.d.ts +45 -0
- package/dist/infrastructure/serialization/toon-serializer.d.ts.map +1 -0
- package/dist/infrastructure/serialization/toon-serializer.js +119 -0
- package/dist/infrastructure/serialization/toon-serializer.js.map +1 -0
- package/dist/infrastructure/storage/embeddings-path.d.ts +18 -0
- package/dist/infrastructure/storage/embeddings-path.d.ts.map +1 -0
- package/dist/infrastructure/storage/embeddings-path.js +37 -0
- package/dist/infrastructure/storage/embeddings-path.js.map +1 -0
- package/dist/infrastructure/storage/plan-repository.d.ts +2 -0
- package/dist/infrastructure/storage/plan-repository.d.ts.map +1 -1
- package/dist/infrastructure/storage/plan-repository.js +36 -73
- package/dist/infrastructure/storage/plan-repository.js.map +1 -1
- package/dist/infrastructure/storage/sqlite-embedding-repository.d.ts +10 -1
- package/dist/infrastructure/storage/sqlite-embedding-repository.d.ts.map +1 -1
- package/dist/infrastructure/storage/sqlite-embedding-repository.js +37 -3
- package/dist/infrastructure/storage/sqlite-embedding-repository.js.map +1 -1
- package/dist/infrastructure/storage/task-helpers.d.ts +12 -1
- package/dist/infrastructure/storage/task-helpers.d.ts.map +1 -1
- package/dist/infrastructure/storage/task-helpers.js +48 -8
- package/dist/infrastructure/storage/task-helpers.js.map +1 -1
- package/dist/infrastructure/storage/task-repository.d.ts +2 -1
- package/dist/infrastructure/storage/task-repository.d.ts.map +1 -1
- package/dist/infrastructure/storage/task-repository.js +14 -3
- package/dist/infrastructure/storage/task-repository.js.map +1 -1
- package/dist/infrastructure/telemetry/telemetry-service.d.ts +74 -0
- package/dist/infrastructure/telemetry/telemetry-service.d.ts.map +1 -0
- package/dist/infrastructure/telemetry/telemetry-service.js +167 -0
- package/dist/infrastructure/telemetry/telemetry-service.js.map +1 -0
- package/dist/infrastructure/ux/capability-boundaries.d.ts +9 -37
- package/dist/infrastructure/ux/capability-boundaries.d.ts.map +1 -1
- package/dist/infrastructure/ux/capability-boundaries.js +23 -148
- package/dist/infrastructure/ux/capability-boundaries.js.map +1 -1
- package/dist/infrastructure/ux/comprehensive-formatter.d.ts +12 -54
- package/dist/infrastructure/ux/comprehensive-formatter.d.ts.map +1 -1
- package/dist/infrastructure/ux/comprehensive-formatter.js +87 -182
- package/dist/infrastructure/ux/comprehensive-formatter.js.map +1 -1
- package/dist/infrastructure/ux/contextual-feature-discovery.d.ts +5 -18
- package/dist/infrastructure/ux/contextual-feature-discovery.d.ts.map +1 -1
- package/dist/infrastructure/ux/contextual-feature-discovery.js +5 -139
- package/dist/infrastructure/ux/contextual-feature-discovery.js.map +1 -1
- package/dist/infrastructure/ux/feature-discovery.d.ts +3 -33
- package/dist/infrastructure/ux/feature-discovery.d.ts.map +1 -1
- package/dist/infrastructure/ux/feature-discovery.js +5 -181
- package/dist/infrastructure/ux/feature-discovery.js.map +1 -1
- package/dist/infrastructure/ux/feedback-prompt.d.ts +15 -31
- package/dist/infrastructure/ux/feedback-prompt.d.ts.map +1 -1
- package/dist/infrastructure/ux/feedback-prompt.js +30 -166
- package/dist/infrastructure/ux/feedback-prompt.js.map +1 -1
- package/dist/infrastructure/ux/progress-indicator.d.ts +4 -6
- package/dist/infrastructure/ux/progress-indicator.d.ts.map +1 -1
- package/dist/infrastructure/ux/progress-indicator.js +35 -50
- package/dist/infrastructure/ux/progress-indicator.js.map +1 -1
- package/dist/infrastructure/ux/review-checkpoint.d.ts +3 -1
- package/dist/infrastructure/ux/review-checkpoint.d.ts.map +1 -1
- package/dist/infrastructure/ux/review-checkpoint.js +33 -80
- package/dist/infrastructure/ux/review-checkpoint.js.map +1 -1
- package/dist/infrastructure/ux/staged-feature-intro.d.ts +14 -39
- package/dist/infrastructure/ux/staged-feature-intro.d.ts.map +1 -1
- package/dist/infrastructure/ux/staged-feature-intro.js +12 -132
- package/dist/infrastructure/ux/staged-feature-intro.js.map +1 -1
- package/dist/infrastructure/ux/syntax-highlighter.d.ts +1 -2
- package/dist/infrastructure/ux/syntax-highlighter.d.ts.map +1 -1
- package/dist/infrastructure/ux/syntax-highlighter.js +67 -148
- package/dist/infrastructure/ux/syntax-highlighter.js.map +1 -1
- package/dist/infrastructure/validation/agent-feedback.d.ts +25 -89
- package/dist/infrastructure/validation/agent-feedback.d.ts.map +1 -1
- package/dist/infrastructure/validation/agent-feedback.js +32 -204
- package/dist/infrastructure/validation/agent-feedback.js.map +1 -1
- package/dist/infrastructure/validation/agent-validation-helper.d.ts +53 -53
- package/dist/infrastructure/validation/agent-validation-helper.d.ts.map +1 -1
- package/dist/infrastructure/validation/agent-validation-helper.js +110 -61
- package/dist/infrastructure/validation/agent-validation-helper.js.map +1 -1
- package/dist/infrastructure/validation/review-handler.d.ts +13 -41
- package/dist/infrastructure/validation/review-handler.d.ts.map +1 -1
- package/dist/infrastructure/validation/review-handler.js +23 -189
- package/dist/infrastructure/validation/review-handler.js.map +1 -1
- package/dist/infrastructure/validation/summary-aggregator.d.ts +25 -22
- package/dist/infrastructure/validation/summary-aggregator.d.ts.map +1 -1
- package/dist/infrastructure/validation/summary-aggregator.js +47 -133
- package/dist/infrastructure/validation/summary-aggregator.js.map +1 -1
- package/dist/infrastructure/validation/summary-extractor.d.ts +13 -48
- package/dist/infrastructure/validation/summary-extractor.d.ts.map +1 -1
- package/dist/infrastructure/validation/summary-extractor.js +32 -89
- package/dist/infrastructure/validation/summary-extractor.js.map +1 -1
- package/dist/infrastructure/validation/trace-summary.d.ts +30 -57
- package/dist/infrastructure/validation/trace-summary.d.ts.map +1 -1
- package/dist/infrastructure/validation/trace-summary.js +37 -356
- package/dist/infrastructure/validation/trace-summary.js.map +1 -1
- package/dist/monitoring.d.ts +1 -1
- package/dist/monitoring.d.ts.map +1 -1
- package/dist/monitoring.js +12 -9
- package/dist/monitoring.js.map +1 -1
- package/dist/parallel-processor.d.ts.map +1 -1
- package/dist/parallel-processor.js +124 -45
- package/dist/parallel-processor.js.map +1 -1
- package/dist/presentation/cli/commands/ask-command.d.ts +2 -0
- package/dist/presentation/cli/commands/ask-command.d.ts.map +1 -1
- package/dist/presentation/cli/commands/ask-command.js +316 -129
- package/dist/presentation/cli/commands/ask-command.js.map +1 -1
- package/dist/presentation/cli/commands/config-command.d.ts.map +1 -1
- package/dist/presentation/cli/commands/config-command.js +22 -8
- package/dist/presentation/cli/commands/config-command.js.map +1 -1
- package/dist/presentation/cli/commands/decision-command.js +23 -6
- package/dist/presentation/cli/commands/decision-command.js.map +1 -1
- package/dist/presentation/cli/commands/docs-command.d.ts +3 -1
- package/dist/presentation/cli/commands/docs-command.d.ts.map +1 -1
- package/dist/presentation/cli/commands/docs-command.js +13 -184
- package/dist/presentation/cli/commands/docs-command.js.map +1 -1
- package/dist/presentation/cli/commands/fix-command.d.ts +2 -0
- package/dist/presentation/cli/commands/fix-command.d.ts.map +1 -1
- package/dist/presentation/cli/commands/fix-command.js +61 -276
- package/dist/presentation/cli/commands/fix-command.js.map +1 -1
- package/dist/presentation/cli/commands/help-command.d.ts.map +1 -1
- package/dist/presentation/cli/commands/help-command.js +21 -1
- package/dist/presentation/cli/commands/help-command.js.map +1 -1
- package/dist/presentation/cli/commands/memory-command.d.ts +17 -0
- package/dist/presentation/cli/commands/memory-command.d.ts.map +1 -0
- package/dist/presentation/cli/commands/memory-command.js +252 -0
- package/dist/presentation/cli/commands/memory-command.js.map +1 -0
- package/dist/presentation/cli/commands/models-command.d.ts +13 -0
- package/dist/presentation/cli/commands/models-command.d.ts.map +1 -0
- package/dist/presentation/cli/commands/models-command.js +194 -0
- package/dist/presentation/cli/commands/models-command.js.map +1 -0
- package/dist/presentation/cli/commands/orchestrate-command.d.ts +1 -0
- package/dist/presentation/cli/commands/orchestrate-command.d.ts.map +1 -1
- package/dist/presentation/cli/commands/orchestrate-command.js +129 -14
- package/dist/presentation/cli/commands/orchestrate-command.js.map +1 -1
- package/dist/presentation/cli/commands/plan-command.d.ts +1 -0
- package/dist/presentation/cli/commands/plan-command.d.ts.map +1 -1
- package/dist/presentation/cli/commands/plan-command.js +134 -25
- package/dist/presentation/cli/commands/plan-command.js.map +1 -1
- package/dist/presentation/cli/commands/product-command.d.ts +6 -4
- package/dist/presentation/cli/commands/product-command.d.ts.map +1 -1
- package/dist/presentation/cli/commands/product-command.js +12 -178
- package/dist/presentation/cli/commands/product-command.js.map +1 -1
- package/dist/presentation/cli/commands/react-command.d.ts.map +1 -1
- package/dist/presentation/cli/commands/react-command.js +5 -1
- package/dist/presentation/cli/commands/react-command.js.map +1 -1
- package/dist/presentation/cli/commands/review-command.d.ts +7 -7
- package/dist/presentation/cli/commands/review-command.d.ts.map +1 -1
- package/dist/presentation/cli/commands/review-command.js +167 -16
- package/dist/presentation/cli/commands/review-command.js.map +1 -1
- package/dist/presentation/cli/commands/run-command.d.ts +6 -8
- package/dist/presentation/cli/commands/run-command.d.ts.map +1 -1
- package/dist/presentation/cli/commands/run-command.js +182 -23
- package/dist/presentation/cli/commands/run-command.js.map +1 -1
- package/dist/presentation/cli/commands/setup-command.d.ts.map +1 -1
- package/dist/presentation/cli/commands/setup-command.js +15 -0
- package/dist/presentation/cli/commands/setup-command.js.map +1 -1
- package/dist/presentation/cli/commands/smart-command.d.ts.map +1 -1
- package/dist/presentation/cli/commands/smart-command.js +74 -6
- package/dist/presentation/cli/commands/smart-command.js.map +1 -1
- package/dist/presentation/cli/commands/status-command.d.ts +3 -0
- package/dist/presentation/cli/commands/status-command.d.ts.map +1 -1
- package/dist/presentation/cli/commands/status-command.js +151 -156
- package/dist/presentation/cli/commands/status-command.js.map +1 -1
- package/dist/presentation/cli/commands/suggest-command.d.ts +3 -5
- package/dist/presentation/cli/commands/suggest-command.d.ts.map +1 -1
- package/dist/presentation/cli/commands/suggest-command.js +132 -19
- package/dist/presentation/cli/commands/suggest-command.js.map +1 -1
- package/dist/presentation/cli/error-display.d.ts.map +1 -1
- package/dist/presentation/cli/error-display.js +75 -17
- package/dist/presentation/cli/error-display.js.map +1 -1
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +6 -1
- package/dist/search.js.map +1 -1
- package/dist/session.d.ts +1 -0
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +55 -7
- package/dist/session.js.map +1 -1
- package/dist/tools/bash.d.ts.map +1 -1
- package/dist/tools/bash.js +3 -0
- package/dist/tools/bash.js.map +1 -1
- package/dist/tools/git-tool.js +7 -7
- package/dist/tools/git-tool.js.map +1 -1
- package/dist/ui.d.ts +11 -0
- package/dist/ui.d.ts.map +1 -1
- package/dist/ui.js +54 -1
- package/dist/ui.js.map +1 -1
- package/package.json +14 -4
|
@@ -1,58 +1,54 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Conversation Context Manager
|
|
3
|
-
*
|
|
3
|
+
* Manages conversation history and context for session-aware interactions
|
|
4
|
+
*
|
|
5
|
+
* Phase 1: v0.5.0-alpha.0
|
|
4
6
|
*/
|
|
5
7
|
export interface ConversationTurn {
|
|
6
8
|
query: string;
|
|
7
9
|
response: string;
|
|
8
|
-
timestamp: number;
|
|
9
|
-
entities?:
|
|
10
|
-
intent?:
|
|
10
|
+
timestamp: string | number;
|
|
11
|
+
entities?: any[];
|
|
12
|
+
intent?: any;
|
|
11
13
|
}
|
|
12
|
-
|
|
14
|
+
interface ConversationSession {
|
|
13
15
|
sessionId: string;
|
|
14
16
|
turns: ConversationTurn[];
|
|
15
|
-
currentFocus?: {
|
|
16
|
-
entity?: string;
|
|
17
|
-
filepath?: string;
|
|
18
|
-
topic?: string;
|
|
19
|
-
};
|
|
20
17
|
createdAt: number;
|
|
21
18
|
lastUpdated: number;
|
|
22
19
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
getContext(sessionId: string): ConversationContext;
|
|
31
|
-
/**
|
|
32
|
-
* Add a turn to conversation history
|
|
33
|
-
* EDGE CASE: Handles very long histories, concurrent sessions, and memory limits
|
|
34
|
-
*/
|
|
35
|
-
addTurn(sessionId: string, query: string, response: string, entities?: string[], intent?: string): void;
|
|
20
|
+
/**
|
|
21
|
+
* In-memory conversation context manager
|
|
22
|
+
* Stores conversation history per session for reference resolution
|
|
23
|
+
*/
|
|
24
|
+
declare class ConversationContextManager {
|
|
25
|
+
private sessions;
|
|
26
|
+
private readonly maxHistoryPerSession;
|
|
36
27
|
/**
|
|
37
|
-
* Get conversation history for
|
|
28
|
+
* Get conversation history for a session
|
|
38
29
|
*/
|
|
39
|
-
getHistory(sessionId: string,
|
|
30
|
+
getHistory(sessionId: string, limit?: number): ConversationTurn[];
|
|
40
31
|
/**
|
|
41
32
|
* Resolve references in query (e.g., "it", "that", "the previous")
|
|
42
33
|
*/
|
|
43
34
|
resolveReferences(sessionId: string, query: string): string;
|
|
44
35
|
/**
|
|
45
|
-
* Extract entities from
|
|
36
|
+
* Extract entities from text (simple heuristic-based extraction)
|
|
37
|
+
*/
|
|
38
|
+
extractEntities(text: string, options?: any): any[];
|
|
39
|
+
/**
|
|
40
|
+
* Add a conversation turn
|
|
46
41
|
*/
|
|
47
|
-
|
|
42
|
+
addTurn(sessionId: string, query: string, response: string, entities?: any[], intent?: any): void;
|
|
48
43
|
/**
|
|
49
|
-
* Get
|
|
44
|
+
* Get full context for a session
|
|
50
45
|
*/
|
|
51
|
-
|
|
46
|
+
getContext(sessionId: string): ConversationSession | null;
|
|
52
47
|
/**
|
|
53
|
-
* Clear conversation
|
|
48
|
+
* Clear conversation history for a session
|
|
54
49
|
*/
|
|
55
|
-
|
|
50
|
+
clear(sessionId?: string): void;
|
|
56
51
|
}
|
|
57
52
|
export declare const conversationContextManager: ConversationContextManager;
|
|
53
|
+
export {};
|
|
58
54
|
//# sourceMappingURL=conversation-context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversation-context.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/context/conversation-context.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"conversation-context.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/context/conversation-context.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,QAAQ,CAAC,EAAE,GAAG,EAAE,CAAC;IACjB,MAAM,CAAC,EAAE,GAAG,CAAC;CACd;AAED,UAAU,mBAAmB;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,gBAAgB,EAAE,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,cAAM,0BAA0B;IAC9B,OAAO,CAAC,QAAQ,CAA+C;IAC/D,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAM;IAE3C;;OAEG;IACH,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,GAAE,MAAW,GAAG,gBAAgB,EAAE;IAgBrE;;OAEG;IACH,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM;IAkC3D;;OAEG;IACH,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,GAAG,EAAE;IAqBnD;;OAEG;IACH,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,GAAE,GAAG,EAAO,EAAE,MAAM,CAAC,EAAE,GAAG,GAAG,IAAI;IA8BrG;;OAEG;IACH,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,mBAAmB,GAAG,IAAI;IAIzD;;OAEG;IACH,KAAK,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI;CAOhC;AAED,eAAO,MAAM,0BAA0B,4BAAmC,CAAC"}
|
|
@@ -1,170 +1,129 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Conversation Context Manager
|
|
3
|
-
*
|
|
3
|
+
* Manages conversation history and context for session-aware interactions
|
|
4
|
+
*
|
|
5
|
+
* Phase 1: v0.5.0-alpha.0
|
|
4
6
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
getContext(sessionId) {
|
|
13
|
-
if (!this.conversations.has(sessionId)) {
|
|
14
|
-
this.conversations.set(sessionId, {
|
|
15
|
-
sessionId,
|
|
16
|
-
turns: [],
|
|
17
|
-
createdAt: Date.now(),
|
|
18
|
-
lastUpdated: Date.now(),
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
return this.conversations.get(sessionId);
|
|
22
|
-
}
|
|
7
|
+
/**
|
|
8
|
+
* In-memory conversation context manager
|
|
9
|
+
* Stores conversation history per session for reference resolution
|
|
10
|
+
*/
|
|
11
|
+
class ConversationContextManager {
|
|
12
|
+
sessions = new Map();
|
|
13
|
+
maxHistoryPerSession = 50;
|
|
23
14
|
/**
|
|
24
|
-
*
|
|
25
|
-
* EDGE CASE: Handles very long histories, concurrent sessions, and memory limits
|
|
15
|
+
* Get conversation history for a session
|
|
26
16
|
*/
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// Keep only the most recent turns (remove oldest 25%)
|
|
32
|
-
const removeCount = Math.floor(this.maxTotalHistoryLength * 0.25);
|
|
33
|
-
context.turns = context.turns.slice(removeCount);
|
|
17
|
+
getHistory(sessionId, limit = 10) {
|
|
18
|
+
const session = this.sessions.get(sessionId);
|
|
19
|
+
if (!session) {
|
|
20
|
+
return [];
|
|
34
21
|
}
|
|
35
|
-
//
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
: response
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
timestamp: Date.now(),
|
|
44
|
-
entities: entities?.slice(0, 10), // Limit entities to prevent bloat
|
|
45
|
-
intent,
|
|
46
|
-
};
|
|
47
|
-
context.turns.push(turn);
|
|
48
|
-
// Keep only last N turns for active context
|
|
49
|
-
if (context.turns.length > this.maxHistoryLength) {
|
|
50
|
-
context.turns.shift();
|
|
51
|
-
}
|
|
52
|
-
// Update current focus based on entities
|
|
53
|
-
if (entities && entities.length > 0) {
|
|
54
|
-
context.currentFocus = {
|
|
55
|
-
entity: entities[0],
|
|
56
|
-
filepath: entities.find(e => e.includes('/') || e.endsWith('.ts') || e.endsWith('.js')) || entities[0],
|
|
57
|
-
topic: query.split(' ').slice(0, 5).join(' '), // First 5 words as topic
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
context.lastUpdated = Date.now();
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Get conversation history for context
|
|
64
|
-
*/
|
|
65
|
-
getHistory(sessionId, maxTurns = 5) {
|
|
66
|
-
const context = this.getContext(sessionId);
|
|
67
|
-
return context.turns.slice(-maxTurns);
|
|
22
|
+
// Return most recent turns, up to limit
|
|
23
|
+
const turns = session.turns.slice(-limit);
|
|
24
|
+
return turns.map(turn => ({
|
|
25
|
+
query: turn.query,
|
|
26
|
+
response: turn.response,
|
|
27
|
+
timestamp: turn.timestamp,
|
|
28
|
+
intent: turn.intent, // Include intent in history
|
|
29
|
+
}));
|
|
68
30
|
}
|
|
69
31
|
/**
|
|
70
32
|
* Resolve references in query (e.g., "it", "that", "the previous")
|
|
71
33
|
*/
|
|
72
34
|
resolveReferences(sessionId, query) {
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return query; // No history to reference
|
|
77
|
-
}
|
|
78
|
-
let resolvedQuery = query;
|
|
79
|
-
const queryLower = query.toLowerCase();
|
|
80
|
-
// Resolve "it" references
|
|
81
|
-
if (queryLower.includes(' it ') || queryLower.startsWith('it ') || queryLower.endsWith(' it')) {
|
|
82
|
-
if (context.currentFocus?.entity) {
|
|
83
|
-
resolvedQuery = resolvedQuery.replace(/\bit\b/gi, context.currentFocus.entity);
|
|
84
|
-
}
|
|
85
|
-
else if (lastTurn.entities && lastTurn.entities.length > 0) {
|
|
86
|
-
resolvedQuery = resolvedQuery.replace(/\bit\b/gi, lastTurn.entities[0]);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
// Use last query's main subject
|
|
90
|
-
const lastQueryWords = lastTurn.query.split(' ');
|
|
91
|
-
const mainSubject = lastQueryWords.find(word => word.length > 3 && !['what', 'how', 'where', 'when', 'why', 'does', 'the', 'a', 'an'].includes(word.toLowerCase())) || lastQueryWords[lastQueryWords.length - 1];
|
|
92
|
-
resolvedQuery = resolvedQuery.replace(/\bit\b/gi, mainSubject);
|
|
93
|
-
}
|
|
35
|
+
const history = this.getHistory(sessionId, 3);
|
|
36
|
+
if (history.length === 0) {
|
|
37
|
+
return query;
|
|
94
38
|
}
|
|
95
|
-
//
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
39
|
+
// Simple reference resolution - replace common references
|
|
40
|
+
let resolved = query;
|
|
41
|
+
const lastTurn = history[history.length - 1];
|
|
42
|
+
// Replace "it" with last mentioned entity/context
|
|
43
|
+
if (/\bit\b/i.test(query) && lastTurn.response) {
|
|
44
|
+
// Extract key entities from last response (simple heuristic)
|
|
45
|
+
const lastResponse = lastTurn.response;
|
|
46
|
+
const words = lastResponse.split(/\s+/).filter(w => w.length > 3);
|
|
47
|
+
if (words.length > 0) {
|
|
48
|
+
// Try to replace "it" with last significant noun phrase
|
|
49
|
+
resolved = resolved.replace(/\bit\b/gi, words[words.length - 1]);
|
|
102
50
|
}
|
|
103
51
|
}
|
|
104
|
-
//
|
|
105
|
-
if (
|
|
106
|
-
|
|
107
|
-
resolvedQuery = resolvedQuery.replace(/\b(previous|last)\s+(one|query|question|command)?\b/gi, lastTurn.query);
|
|
108
|
-
}
|
|
52
|
+
// Replace "that" with last query
|
|
53
|
+
if (/\bthat\b/i.test(query)) {
|
|
54
|
+
resolved = resolved.replace(/\bthat\b/gi, `"${lastTurn.query}"`);
|
|
109
55
|
}
|
|
110
|
-
//
|
|
111
|
-
if (
|
|
112
|
-
|
|
113
|
-
resolvedQuery = query.replace(/\s+(too|also)\b/i, '');
|
|
114
|
-
// If previous was an edit, append to same file
|
|
115
|
-
if (lastTurn.intent === 'edit' && context.currentFocus?.filepath) {
|
|
116
|
-
resolvedQuery = `Add to ${context.currentFocus.filepath}: ${resolvedQuery}`;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
56
|
+
// Replace "the previous" with last query
|
|
57
|
+
if (/\bthe previous\b/i.test(query)) {
|
|
58
|
+
resolved = resolved.replace(/\bthe previous\b/gi, `"${lastTurn.query}"`);
|
|
119
59
|
}
|
|
120
|
-
return
|
|
60
|
+
return resolved;
|
|
121
61
|
}
|
|
122
62
|
/**
|
|
123
|
-
* Extract entities from
|
|
63
|
+
* Extract entities from text (simple heuristic-based extraction)
|
|
124
64
|
*/
|
|
125
|
-
extractEntities(
|
|
65
|
+
extractEntities(text, options) {
|
|
66
|
+
// Simple entity extraction - can be enhanced later
|
|
126
67
|
const entities = [];
|
|
127
68
|
// Extract file paths
|
|
128
|
-
const
|
|
129
|
-
const filePaths =
|
|
130
|
-
|
|
131
|
-
entities.push(
|
|
69
|
+
const filePathRegex = /[\w\/\-\.]+\.(ts|js|tsx|jsx|json|md|yaml|yml|txt|py|go|rs|java|cpp|h|hpp)/g;
|
|
70
|
+
const filePaths = text.match(filePathRegex) || [];
|
|
71
|
+
filePaths.forEach(path => {
|
|
72
|
+
entities.push({ type: 'file', value: path });
|
|
73
|
+
});
|
|
74
|
+
// Extract function/class names (simple heuristic)
|
|
75
|
+
const functionRegex = /(?:function|class|const|let|var)\s+([A-Z][a-zA-Z0-9_]+|[a-z][a-zA-Z0-9_]+)/g;
|
|
76
|
+
const matches = text.matchAll(functionRegex);
|
|
77
|
+
for (const match of matches) {
|
|
78
|
+
entities.push({ type: 'symbol', value: match[1] });
|
|
132
79
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
80
|
+
return entities;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Add a conversation turn
|
|
84
|
+
*/
|
|
85
|
+
addTurn(sessionId, query, response, entities = [], intent) {
|
|
86
|
+
let session = this.sessions.get(sessionId);
|
|
87
|
+
if (!session) {
|
|
88
|
+
session = {
|
|
89
|
+
sessionId,
|
|
90
|
+
turns: [],
|
|
91
|
+
createdAt: Date.now(),
|
|
92
|
+
lastUpdated: Date.now(),
|
|
93
|
+
};
|
|
94
|
+
this.sessions.set(sessionId, session);
|
|
138
95
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
entities
|
|
96
|
+
const turn = {
|
|
97
|
+
query,
|
|
98
|
+
response,
|
|
99
|
+
timestamp: new Date().toISOString(),
|
|
100
|
+
entities,
|
|
101
|
+
intent,
|
|
102
|
+
};
|
|
103
|
+
session.turns.push(turn);
|
|
104
|
+
session.lastUpdated = Date.now();
|
|
105
|
+
// Trim history if too long
|
|
106
|
+
if (session.turns.length > this.maxHistoryPerSession) {
|
|
107
|
+
session.turns = session.turns.slice(-this.maxHistoryPerSession);
|
|
144
108
|
}
|
|
145
|
-
return [...new Set(entities)]; // Remove duplicates
|
|
146
109
|
}
|
|
147
110
|
/**
|
|
148
|
-
* Get
|
|
111
|
+
* Get full context for a session
|
|
149
112
|
*/
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
if (history.length === 0) {
|
|
153
|
-
return '';
|
|
154
|
-
}
|
|
155
|
-
const summary = history.map((turn, idx) => {
|
|
156
|
-
const turnNum = history.length - maxTurns + idx + 1;
|
|
157
|
-
return `[Previous ${turnNum}]: User asked "${turn.query}". Response: ${turn.response.substring(0, 100)}...`;
|
|
158
|
-
}).join('\n');
|
|
159
|
-
return `\n\nCONVERSATION HISTORY:\n${summary}\n`;
|
|
113
|
+
getContext(sessionId) {
|
|
114
|
+
return this.sessions.get(sessionId) || null;
|
|
160
115
|
}
|
|
161
116
|
/**
|
|
162
|
-
* Clear conversation
|
|
117
|
+
* Clear conversation history for a session
|
|
163
118
|
*/
|
|
164
|
-
|
|
165
|
-
|
|
119
|
+
clear(sessionId) {
|
|
120
|
+
if (sessionId) {
|
|
121
|
+
this.sessions.delete(sessionId);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
this.sessions.clear();
|
|
125
|
+
}
|
|
166
126
|
}
|
|
167
127
|
}
|
|
168
|
-
// Singleton instance
|
|
169
128
|
export const conversationContextManager = new ConversationContextManager();
|
|
170
129
|
//# sourceMappingURL=conversation-context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversation-context.js","sourceRoot":"","sources":["../../../src/infrastructure/context/conversation-context.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"conversation-context.js","sourceRoot":"","sources":["../../../src/infrastructure/context/conversation-context.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAiBH;;;GAGG;AACH,MAAM,0BAA0B;IACtB,QAAQ,GAAqC,IAAI,GAAG,EAAE,CAAC;IAC9C,oBAAoB,GAAG,EAAE,CAAC;IAE3C;;OAEG;IACH,UAAU,CAAC,SAAiB,EAAE,QAAgB,EAAE;QAC9C,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC7C,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,wCAAwC;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AAI,0BAA0B,EAAE,CAAC"}
|
|
@@ -1,26 +1,42 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Session Manager
|
|
3
|
-
* Manages
|
|
3
|
+
* Manages CLI sessions for context tracking
|
|
4
|
+
*
|
|
5
|
+
* Phase 1: v0.5.0-alpha.0
|
|
4
6
|
*/
|
|
5
|
-
|
|
7
|
+
interface Session {
|
|
8
|
+
sessionId: string;
|
|
9
|
+
cwd: string;
|
|
10
|
+
startedAt: number;
|
|
11
|
+
lastActivity: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Session manager for tracking CLI sessions
|
|
15
|
+
*/
|
|
16
|
+
declare class SessionManager {
|
|
6
17
|
private sessions;
|
|
7
|
-
|
|
18
|
+
private readonly sessionTimeout;
|
|
19
|
+
/**
|
|
20
|
+
* Get or create session ID for a working directory
|
|
21
|
+
*/
|
|
22
|
+
getSessionId(cwd: string): string;
|
|
8
23
|
/**
|
|
9
|
-
* Get
|
|
24
|
+
* Get current session for a working directory
|
|
10
25
|
*/
|
|
11
|
-
|
|
26
|
+
getCurrentSession(cwd: string): Session | null;
|
|
12
27
|
/**
|
|
13
|
-
*
|
|
28
|
+
* Create a new session explicitly
|
|
14
29
|
*/
|
|
15
|
-
|
|
30
|
+
createSession(cwd: string): Session;
|
|
16
31
|
/**
|
|
17
|
-
*
|
|
32
|
+
* End a session
|
|
18
33
|
*/
|
|
19
|
-
|
|
34
|
+
endSession(cwd: string): void;
|
|
20
35
|
/**
|
|
21
|
-
*
|
|
36
|
+
* Clean up expired sessions
|
|
22
37
|
*/
|
|
23
|
-
|
|
38
|
+
cleanup(): void;
|
|
24
39
|
}
|
|
25
40
|
export declare const sessionManager: SessionManager;
|
|
41
|
+
export {};
|
|
26
42
|
//# sourceMappingURL=session-manager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-manager.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/context/session-manager.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"session-manager.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/context/session-manager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,UAAU,OAAO;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,cAAM,cAAc;IAClB,OAAO,CAAC,QAAQ,CAAmC;IACnD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAuB;IAEtD;;OAEG;IACH,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IA8BjC;;OAEG;IACH,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI;IAK9C;;OAEG;IACH,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAenC;;OAEG;IACH,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAK7B;;OAEG;IACH,OAAO,IAAI,IAAI;CAShB;AAED,eAAO,MAAM,cAAc,gBAAuB,CAAC"}
|
|
@@ -1,98 +1,94 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Session Manager
|
|
3
|
-
* Manages
|
|
3
|
+
* Manages CLI sessions for context tracking
|
|
4
|
+
*
|
|
5
|
+
* Phase 1: v0.5.0-alpha.0
|
|
4
6
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const SESSION_FILE = path.join(SESSION_DIR, 'sessions.json');
|
|
10
|
-
export class SessionManager {
|
|
7
|
+
/**
|
|
8
|
+
* Session manager for tracking CLI sessions
|
|
9
|
+
*/
|
|
10
|
+
class SessionManager {
|
|
11
11
|
sessions = new Map();
|
|
12
|
-
|
|
13
|
-
this.loadSessions();
|
|
14
|
-
}
|
|
12
|
+
sessionTimeout = 24 * 60 * 60 * 1000; // 24 hours
|
|
15
13
|
/**
|
|
16
|
-
* Get or create session ID for a
|
|
14
|
+
* Get or create session ID for a working directory
|
|
17
15
|
*/
|
|
18
|
-
getSessionId(
|
|
19
|
-
// Normalize path
|
|
20
|
-
const
|
|
21
|
-
// Check if
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
this.
|
|
26
|
-
|
|
16
|
+
getSessionId(cwd) {
|
|
17
|
+
// Normalize cwd path
|
|
18
|
+
const normalizedCwd = cwd || process.cwd();
|
|
19
|
+
// Check if session exists and is still valid
|
|
20
|
+
const existingSession = this.sessions.get(normalizedCwd);
|
|
21
|
+
if (existingSession) {
|
|
22
|
+
const age = Date.now() - existingSession.lastActivity;
|
|
23
|
+
if (age < this.sessionTimeout) {
|
|
24
|
+
existingSession.lastActivity = Date.now();
|
|
25
|
+
return existingSession.sessionId;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
// Session expired, remove it
|
|
29
|
+
this.sessions.delete(normalizedCwd);
|
|
30
|
+
}
|
|
27
31
|
}
|
|
28
32
|
// Create new session
|
|
29
|
-
const sessionId = `session-${
|
|
33
|
+
const sessionId = `session-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
30
34
|
const session = {
|
|
31
35
|
sessionId,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
cwd: normalizedCwd,
|
|
37
|
+
startedAt: Date.now(),
|
|
38
|
+
lastActivity: Date.now(),
|
|
35
39
|
};
|
|
36
|
-
this.sessions.set(
|
|
37
|
-
this.saveSessions();
|
|
40
|
+
this.sessions.set(normalizedCwd, session);
|
|
38
41
|
return sessionId;
|
|
39
42
|
}
|
|
40
43
|
/**
|
|
41
|
-
*
|
|
44
|
+
* Get current session for a working directory
|
|
42
45
|
*/
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
const data = fs.readFileSync(SESSION_FILE, 'utf-8');
|
|
49
|
-
const sessions = JSON.parse(data);
|
|
50
|
-
// Clean up old sessions (older than 7 days)
|
|
51
|
-
const sevenDaysAgo = Date.now() - (7 * 24 * 60 * 60 * 1000);
|
|
52
|
-
for (const [key, session] of Object.entries(sessions)) {
|
|
53
|
-
if (session.lastUsed > sevenDaysAgo) {
|
|
54
|
-
this.sessions.set(key, session);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
// Save cleaned sessions
|
|
58
|
-
if (this.sessions.size !== Object.keys(sessions).length) {
|
|
59
|
-
this.saveSessions();
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
catch (error) {
|
|
63
|
-
// If file is corrupted or doesn't exist, start fresh
|
|
64
|
-
this.sessions.clear();
|
|
65
|
-
}
|
|
46
|
+
getCurrentSession(cwd) {
|
|
47
|
+
const normalizedCwd = cwd || process.cwd();
|
|
48
|
+
return this.sessions.get(normalizedCwd) || null;
|
|
66
49
|
}
|
|
67
50
|
/**
|
|
68
|
-
*
|
|
51
|
+
* Create a new session explicitly
|
|
69
52
|
*/
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
catch (error) {
|
|
83
|
-
// Fail silently - session persistence is not critical
|
|
84
|
-
console.warn('[SessionManager] Failed to save sessions:', error);
|
|
85
|
-
}
|
|
53
|
+
createSession(cwd) {
|
|
54
|
+
const normalizedCwd = cwd || process.cwd();
|
|
55
|
+
const sessionId = `session-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
56
|
+
const session = {
|
|
57
|
+
sessionId,
|
|
58
|
+
cwd: normalizedCwd,
|
|
59
|
+
startedAt: Date.now(),
|
|
60
|
+
lastActivity: Date.now(),
|
|
61
|
+
};
|
|
62
|
+
this.sessions.set(normalizedCwd, session);
|
|
63
|
+
return session;
|
|
86
64
|
}
|
|
87
65
|
/**
|
|
88
|
-
*
|
|
66
|
+
* End a session
|
|
89
67
|
*/
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
this.sessions.delete(
|
|
93
|
-
|
|
68
|
+
endSession(cwd) {
|
|
69
|
+
const normalizedCwd = cwd || process.cwd();
|
|
70
|
+
this.sessions.delete(normalizedCwd);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Clean up expired sessions
|
|
74
|
+
*/
|
|
75
|
+
cleanup() {
|
|
76
|
+
const now = Date.now();
|
|
77
|
+
for (const [cwd, session] of this.sessions.entries()) {
|
|
78
|
+
const age = now - session.lastActivity;
|
|
79
|
+
if (age >= this.sessionTimeout) {
|
|
80
|
+
this.sessions.delete(cwd);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
94
83
|
}
|
|
95
84
|
}
|
|
96
|
-
// Singleton instance
|
|
97
85
|
export const sessionManager = new SessionManager();
|
|
86
|
+
// Cleanup expired sessions periodically
|
|
87
|
+
// Use .unref() to allow process to exit even with timer active
|
|
88
|
+
if (typeof setInterval !== 'undefined') {
|
|
89
|
+
const cleanupInterval = setInterval(() => {
|
|
90
|
+
sessionManager.cleanup();
|
|
91
|
+
}, 60 * 60 * 1000); // Every hour
|
|
92
|
+
cleanupInterval.unref();
|
|
93
|
+
}
|
|
98
94
|
//# sourceMappingURL=session-manager.js.map
|