@stackmemoryai/stackmemory 0.5.31 → 0.5.34
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/dist/agents/core/agent-task-manager.js.map +1 -1
- package/dist/cli/claude-sm.js +199 -16
- package/dist/cli/claude-sm.js.map +2 -2
- package/dist/cli/commands/clear.js +1 -1
- package/dist/cli/commands/clear.js.map +1 -1
- package/dist/cli/commands/context.js +1 -12
- package/dist/cli/commands/context.js.map +2 -2
- package/dist/cli/commands/dashboard.js.map +1 -1
- package/dist/cli/commands/discovery.js +1 -1
- package/dist/cli/commands/discovery.js.map +1 -1
- package/dist/cli/commands/handoff.js +1 -1
- package/dist/cli/commands/handoff.js.map +1 -1
- package/dist/cli/commands/linear.js +1 -14
- package/dist/cli/commands/linear.js.map +2 -2
- package/dist/cli/commands/login.js +32 -10
- package/dist/cli/commands/login.js.map +2 -2
- package/dist/cli/commands/migrate.js +80 -22
- package/dist/cli/commands/migrate.js.map +2 -2
- package/dist/cli/commands/model.js +533 -0
- package/dist/cli/commands/model.js.map +7 -0
- package/dist/cli/commands/monitor.js +1 -1
- package/dist/cli/commands/monitor.js.map +1 -1
- package/dist/cli/commands/quality.js +1 -1
- package/dist/cli/commands/quality.js.map +1 -1
- package/dist/cli/commands/ralph.js +93 -28
- package/dist/cli/commands/ralph.js.map +2 -2
- package/dist/cli/commands/service.js +10 -3
- package/dist/cli/commands/service.js.map +2 -2
- package/dist/cli/commands/skills.js +61 -11
- package/dist/cli/commands/skills.js.map +2 -2
- package/dist/cli/commands/sms-notify.js +342 -22
- package/dist/cli/commands/sms-notify.js.map +3 -3
- package/dist/cli/commands/workflow.js +1 -1
- package/dist/cli/commands/workflow.js.map +1 -1
- package/dist/cli/commands/worktree.js +1 -1
- package/dist/cli/commands/worktree.js.map +1 -1
- package/dist/cli/index.js +3 -1
- package/dist/cli/index.js.map +2 -2
- package/dist/core/context/auto-context.js.map +1 -1
- package/dist/core/context/compaction-handler.js.map +2 -2
- package/dist/core/context/context-bridge.js.map +2 -2
- package/dist/core/context/dual-stack-manager.js +24 -8
- package/dist/core/context/dual-stack-manager.js.map +2 -2
- package/dist/core/context/enhanced-rehydration.js.map +1 -1
- package/dist/core/context/frame-database.js +41 -5
- package/dist/core/context/frame-database.js.map +2 -2
- package/dist/core/context/frame-digest.js +6 -1
- package/dist/core/context/frame-digest.js.map +2 -2
- package/dist/core/context/frame-handoff-manager.js.map +1 -1
- package/dist/core/context/frame-lifecycle-hooks.js +119 -0
- package/dist/core/context/frame-lifecycle-hooks.js.map +7 -0
- package/dist/core/context/frame-manager.js +56 -9
- package/dist/core/context/frame-manager.js.map +2 -2
- package/dist/core/context/frame-stack.js +29 -0
- package/dist/core/context/frame-stack.js.map +2 -2
- package/dist/core/context/incremental-gc.js.map +2 -2
- package/dist/core/context/index.js +4 -22
- package/dist/core/context/index.js.map +2 -2
- package/dist/core/context/permission-manager.js +0 -11
- package/dist/core/context/permission-manager.js.map +2 -2
- package/dist/core/context/recursive-context-manager.js +15 -9
- package/dist/core/context/recursive-context-manager.js.map +2 -2
- package/dist/core/context/refactored-frame-manager.js +140 -34
- package/dist/core/context/refactored-frame-manager.js.map +3 -3
- package/dist/core/context/shared-context-layer.js +0 -11
- package/dist/core/context/shared-context-layer.js.map +2 -2
- package/dist/core/context/stack-merge-resolver.js.map +1 -1
- package/dist/core/context/validation.js +6 -1
- package/dist/core/context/validation.js.map +2 -2
- package/dist/core/database/database-adapter.js.map +1 -1
- package/dist/core/database/paradedb-adapter.js.map +1 -1
- package/dist/core/database/query-router.js.map +1 -1
- package/dist/core/database/sqlite-adapter.js.map +1 -1
- package/dist/core/digest/frame-digest-integration.js.map +1 -1
- package/dist/core/digest/hybrid-digest-generator.js.map +1 -1
- package/dist/core/digest/types.js.map +1 -1
- package/dist/core/errors/index.js +249 -0
- package/dist/core/errors/index.js.map +2 -2
- package/dist/core/frame/workflow-templates.js.map +2 -2
- package/dist/core/merge/conflict-detector.js.map +1 -1
- package/dist/core/merge/resolution-engine.js.map +1 -1
- package/dist/core/merge/stack-diff.js.map +1 -1
- package/dist/core/models/fallback-monitor.js +229 -0
- package/dist/core/models/fallback-monitor.js.map +7 -0
- package/dist/core/models/model-router.js +340 -0
- package/dist/core/models/model-router.js.map +7 -0
- package/dist/core/monitoring/error-handler.js +37 -270
- package/dist/core/monitoring/error-handler.js.map +3 -3
- package/dist/core/monitoring/session-monitor.js.map +1 -1
- package/dist/core/performance/lazy-context-loader.js.map +1 -1
- package/dist/core/performance/optimized-frame-context.js.map +1 -1
- package/dist/core/retrieval/context-retriever.js.map +1 -1
- package/dist/core/retrieval/graph-retrieval.js.map +1 -1
- package/dist/core/retrieval/hierarchical-retrieval.js.map +1 -1
- package/dist/core/retrieval/llm-context-retrieval.js.map +1 -1
- package/dist/core/retrieval/retrieval-benchmarks.js.map +1 -1
- package/dist/core/retrieval/summary-generator.js.map +1 -1
- package/dist/core/retrieval/types.js.map +1 -1
- package/dist/core/storage/chromadb-adapter.js.map +1 -1
- package/dist/core/storage/infinite-storage.js.map +1 -1
- package/dist/core/storage/two-tier-storage.js.map +1 -1
- package/dist/features/tasks/task-aware-context.js.map +1 -1
- package/dist/features/web/server/index.js +1 -1
- package/dist/features/web/server/index.js.map +1 -1
- package/dist/hooks/claude-code-whatsapp-hook.js +197 -0
- package/dist/hooks/claude-code-whatsapp-hook.js.map +7 -0
- package/dist/hooks/linear-task-picker.js +1 -1
- package/dist/hooks/linear-task-picker.js.map +2 -2
- package/dist/hooks/schemas.js +105 -1
- package/dist/hooks/schemas.js.map +2 -2
- package/dist/hooks/session-summary.js +5 -1
- package/dist/hooks/session-summary.js.map +2 -2
- package/dist/hooks/sms-action-runner.js +16 -1
- package/dist/hooks/sms-action-runner.js.map +2 -2
- package/dist/hooks/sms-notify.js +4 -2
- package/dist/hooks/sms-notify.js.map +2 -2
- package/dist/hooks/sms-webhook.js +23 -2
- package/dist/hooks/sms-webhook.js.map +2 -2
- package/dist/hooks/whatsapp-commands.js +516 -0
- package/dist/hooks/whatsapp-commands.js.map +7 -0
- package/dist/hooks/whatsapp-scheduler.js +317 -0
- package/dist/hooks/whatsapp-scheduler.js.map +7 -0
- package/dist/hooks/whatsapp-sync.js +409 -0
- package/dist/hooks/whatsapp-sync.js.map +7 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/integrations/mcp/handlers/context-handlers.js.map +1 -1
- package/dist/integrations/mcp/handlers/discovery-handlers.js.map +1 -1
- package/dist/integrations/mcp/server.js +1 -1
- package/dist/integrations/mcp/server.js.map +1 -1
- package/dist/integrations/ralph/bridge/ralph-stackmemory-bridge.js +1 -1
- package/dist/integrations/ralph/bridge/ralph-stackmemory-bridge.js.map +1 -1
- package/dist/integrations/ralph/context/stackmemory-context-loader.js +1 -1
- package/dist/integrations/ralph/context/stackmemory-context-loader.js.map +1 -1
- package/dist/integrations/ralph/learning/pattern-learner.js +1 -1
- package/dist/integrations/ralph/learning/pattern-learner.js.map +1 -1
- package/dist/integrations/ralph/orchestration/multi-loop-orchestrator.js +1 -1
- package/dist/integrations/ralph/orchestration/multi-loop-orchestrator.js.map +1 -1
- package/dist/integrations/ralph/swarm/swarm-coordinator.js +1 -1
- package/dist/integrations/ralph/swarm/swarm-coordinator.js.map +1 -1
- package/dist/integrations/ralph/visualization/ralph-debugger.js +1 -1
- package/dist/integrations/ralph/visualization/ralph-debugger.js.map +1 -1
- package/dist/mcp/stackmemory-mcp-server.js +1 -1
- package/dist/mcp/stackmemory-mcp-server.js.map +1 -1
- package/dist/skills/claude-skills.js.map +1 -1
- package/dist/skills/recursive-agent-orchestrator.js.map +1 -1
- package/dist/skills/unified-rlm-orchestrator.js.map +1 -1
- package/package.json +2 -3
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
ErrorCode
|
|
12
12
|
} from "../errors/index.js";
|
|
13
13
|
import { FrameQueryMode } from "../session/index.js";
|
|
14
|
+
import { frameLifecycleHooks } from "./frame-lifecycle-hooks.js";
|
|
14
15
|
const MAX_FRAME_DEPTH = 100;
|
|
15
16
|
const DEFAULT_MAX_DEPTH = 100;
|
|
16
17
|
import { FrameDatabase } from "./frame-database.js";
|
|
@@ -212,6 +213,10 @@ class RefactoredFrameManager {
|
|
|
212
213
|
});
|
|
213
214
|
this.frameStack.popFrame(targetFrameId);
|
|
214
215
|
this.closeChildFrames(targetFrameId);
|
|
216
|
+
const events = this.frameDb.getFrameEvents(targetFrameId);
|
|
217
|
+
const anchors = this.frameDb.getFrameAnchors(targetFrameId);
|
|
218
|
+
frameLifecycleHooks.triggerClose({ frame: { ...frame, state: "closed" }, events, anchors }).catch(() => {
|
|
219
|
+
});
|
|
215
220
|
logger.info("Closed frame", {
|
|
216
221
|
frameId: targetFrameId,
|
|
217
222
|
name: frame.name,
|
|
@@ -468,6 +473,14 @@ class RefactoredFrameManager {
|
|
|
468
473
|
);
|
|
469
474
|
}
|
|
470
475
|
if (newParentFrameId) {
|
|
476
|
+
const newParentFrame = this.frameDb.getFrame(newParentFrameId);
|
|
477
|
+
if (!newParentFrame) {
|
|
478
|
+
throw new FrameError(
|
|
479
|
+
`Parent frame not found: ${newParentFrameId}`,
|
|
480
|
+
ErrorCode.FRAME_NOT_FOUND,
|
|
481
|
+
{ frameId, newParentFrameId }
|
|
482
|
+
);
|
|
483
|
+
}
|
|
471
484
|
const cycle = this.detectCycle(frameId, newParentFrameId);
|
|
472
485
|
if (cycle) {
|
|
473
486
|
throw new FrameError(
|
|
@@ -481,25 +494,30 @@ class RefactoredFrameManager {
|
|
|
481
494
|
}
|
|
482
495
|
);
|
|
483
496
|
}
|
|
497
|
+
const newDepth2 = newParentFrame.depth + 1;
|
|
498
|
+
if (newDepth2 > this.maxFrameDepth) {
|
|
499
|
+
throw new FrameError(
|
|
500
|
+
`Cannot set parent: would exceed maximum frame depth`,
|
|
501
|
+
ErrorCode.FRAME_STACK_OVERFLOW,
|
|
502
|
+
{
|
|
503
|
+
frameId,
|
|
504
|
+
newParentFrameId,
|
|
505
|
+
newDepth: newDepth2,
|
|
506
|
+
maxDepth: this.maxFrameDepth
|
|
507
|
+
}
|
|
508
|
+
);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
let newDepth = 0;
|
|
512
|
+
if (newParentFrameId) {
|
|
484
513
|
const newParentFrame = this.frameDb.getFrame(newParentFrameId);
|
|
485
514
|
if (newParentFrame) {
|
|
486
|
-
|
|
487
|
-
if (newDepth > this.maxFrameDepth) {
|
|
488
|
-
throw new FrameError(
|
|
489
|
-
`Cannot set parent: would exceed maximum frame depth`,
|
|
490
|
-
ErrorCode.FRAME_STACK_OVERFLOW,
|
|
491
|
-
{
|
|
492
|
-
frameId,
|
|
493
|
-
newParentFrameId,
|
|
494
|
-
newDepth,
|
|
495
|
-
maxDepth: this.maxFrameDepth
|
|
496
|
-
}
|
|
497
|
-
);
|
|
498
|
-
}
|
|
515
|
+
newDepth = newParentFrame.depth + 1;
|
|
499
516
|
}
|
|
500
517
|
}
|
|
501
518
|
this.frameDb.updateFrame(frameId, {
|
|
502
|
-
parent_frame_id: newParentFrameId
|
|
519
|
+
parent_frame_id: newParentFrameId,
|
|
520
|
+
depth: newDepth
|
|
503
521
|
});
|
|
504
522
|
logger.info("Updated parent frame", {
|
|
505
523
|
frameId,
|
|
@@ -558,28 +576,116 @@ class RefactoredFrameManager {
|
|
|
558
576
|
warnings
|
|
559
577
|
};
|
|
560
578
|
}
|
|
579
|
+
/**
|
|
580
|
+
* Set query mode for frame retrieval
|
|
581
|
+
*/
|
|
582
|
+
setQueryMode(mode) {
|
|
583
|
+
this.queryMode = mode;
|
|
584
|
+
this.frameStack.setQueryMode(mode);
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* Get recent frames for context sharing
|
|
588
|
+
*/
|
|
589
|
+
async getRecentFrames(limit = 100) {
|
|
590
|
+
try {
|
|
591
|
+
const frames = this.frameDb.getFramesByProject(this.projectId);
|
|
592
|
+
return frames.sort((a, b) => (b.created_at || 0) - (a.created_at || 0)).slice(0, limit).map((frame) => ({
|
|
593
|
+
...frame,
|
|
594
|
+
// Add compatibility fields
|
|
595
|
+
frameId: frame.frame_id,
|
|
596
|
+
runId: frame.run_id,
|
|
597
|
+
projectId: frame.project_id,
|
|
598
|
+
parentFrameId: frame.parent_frame_id,
|
|
599
|
+
title: frame.name,
|
|
600
|
+
timestamp: frame.created_at,
|
|
601
|
+
metadata: {
|
|
602
|
+
tags: this.extractTagsFromFrame(frame),
|
|
603
|
+
importance: this.calculateFrameImportance(frame)
|
|
604
|
+
},
|
|
605
|
+
data: {
|
|
606
|
+
inputs: frame.inputs,
|
|
607
|
+
outputs: frame.outputs,
|
|
608
|
+
digest: frame.digest_json
|
|
609
|
+
}
|
|
610
|
+
}));
|
|
611
|
+
} catch (error) {
|
|
612
|
+
logger.error("Failed to get recent frames", error);
|
|
613
|
+
return [];
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* Add context metadata to the current frame
|
|
618
|
+
*/
|
|
619
|
+
async addContext(key, value) {
|
|
620
|
+
const currentFrameId = this.frameStack.getCurrentFrameId();
|
|
621
|
+
if (!currentFrameId) return;
|
|
622
|
+
try {
|
|
623
|
+
const frame = this.frameDb.getFrame(currentFrameId);
|
|
624
|
+
if (!frame) return;
|
|
625
|
+
const metadata = frame.outputs || {};
|
|
626
|
+
metadata[key] = value;
|
|
627
|
+
this.frameDb.updateFrame(currentFrameId, {
|
|
628
|
+
outputs: metadata
|
|
629
|
+
});
|
|
630
|
+
} catch (error) {
|
|
631
|
+
logger.warn("Failed to add context to frame", { error, key });
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
/**
|
|
635
|
+
* Delete a frame completely from the database (used in handoffs)
|
|
636
|
+
*/
|
|
637
|
+
deleteFrame(frameId) {
|
|
638
|
+
try {
|
|
639
|
+
this.frameStack.removeFrame(frameId);
|
|
640
|
+
this.frameDb.deleteFrame(frameId);
|
|
641
|
+
logger.debug("Deleted frame completely", { frameId });
|
|
642
|
+
} catch (error) {
|
|
643
|
+
logger.error("Failed to delete frame", { frameId, error });
|
|
644
|
+
throw error;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
648
|
+
* Extract tags from frame for categorization
|
|
649
|
+
*/
|
|
650
|
+
extractTagsFromFrame(frame) {
|
|
651
|
+
const tags = [];
|
|
652
|
+
if (frame.type) tags.push(frame.type);
|
|
653
|
+
if (frame.name) {
|
|
654
|
+
const nameLower = frame.name.toLowerCase();
|
|
655
|
+
if (nameLower.includes("error")) tags.push("error");
|
|
656
|
+
if (nameLower.includes("fix")) tags.push("resolution");
|
|
657
|
+
if (nameLower.includes("decision")) tags.push("decision");
|
|
658
|
+
if (nameLower.includes("milestone")) tags.push("milestone");
|
|
659
|
+
}
|
|
660
|
+
try {
|
|
661
|
+
if (frame.digest_json && typeof frame.digest_json === "object") {
|
|
662
|
+
const digest = frame.digest_json;
|
|
663
|
+
if (Array.isArray(digest.tags)) {
|
|
664
|
+
tags.push(...digest.tags);
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
} catch {
|
|
668
|
+
}
|
|
669
|
+
return [...new Set(tags)];
|
|
670
|
+
}
|
|
671
|
+
/**
|
|
672
|
+
* Calculate frame importance for prioritization
|
|
673
|
+
*/
|
|
674
|
+
calculateFrameImportance(frame) {
|
|
675
|
+
if (frame.type === "milestone" || frame.name?.includes("decision")) {
|
|
676
|
+
return "high";
|
|
677
|
+
}
|
|
678
|
+
if (frame.type === "error" || frame.type === "resolution") {
|
|
679
|
+
return "medium";
|
|
680
|
+
}
|
|
681
|
+
if (frame.closed_at && frame.created_at) {
|
|
682
|
+
const duration = frame.closed_at - frame.created_at;
|
|
683
|
+
if (duration > 300) return "medium";
|
|
684
|
+
}
|
|
685
|
+
return "low";
|
|
686
|
+
}
|
|
561
687
|
}
|
|
562
|
-
import {
|
|
563
|
-
Frame as Frame2,
|
|
564
|
-
FrameContext as FrameContext2,
|
|
565
|
-
Anchor as Anchor2,
|
|
566
|
-
Event as Event2,
|
|
567
|
-
FrameType as FrameType2,
|
|
568
|
-
FrameState as FrameState2,
|
|
569
|
-
FrameCreationOptions as FrameCreationOptions2,
|
|
570
|
-
FrameManagerConfig as FrameManagerConfig2,
|
|
571
|
-
DigestResult as DigestResult2
|
|
572
|
-
} from "./frame-types.js";
|
|
573
688
|
export {
|
|
574
|
-
Anchor2 as Anchor,
|
|
575
|
-
DigestResult2 as DigestResult,
|
|
576
|
-
Event2 as Event,
|
|
577
|
-
Frame2 as Frame,
|
|
578
|
-
FrameContext2 as FrameContext,
|
|
579
|
-
FrameCreationOptions2 as FrameCreationOptions,
|
|
580
|
-
FrameManagerConfig2 as FrameManagerConfig,
|
|
581
|
-
FrameState2 as FrameState,
|
|
582
|
-
FrameType2 as FrameType,
|
|
583
689
|
RefactoredFrameManager
|
|
584
690
|
};
|
|
585
691
|
//# sourceMappingURL=refactored-frame-manager.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/core/context/refactored-frame-manager.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Refactored Frame Manager - Modular Implementation\n * Main orchestrator that uses focused modules for frame management\n */\n\nimport Database from 'better-sqlite3';\nimport { v4 as uuidv4 } from 'uuid';\nimport { logger } from '../monitoring/logger.js';\nimport { trace } from '../trace/index.js';\nimport {\n FrameError,\n SystemError,\n ErrorCode,\n wrapError,\n createErrorHandler,\n} from '../errors/index.js';\nimport { retry, withTimeout } from '../errors/recovery.js';\nimport { sessionManager, FrameQueryMode } from '../session/index.js';\n\n// Constants for frame validation\nconst MAX_FRAME_DEPTH = 100; // Maximum allowed frame depth\nconst DEFAULT_MAX_DEPTH = 100; // Default if not configured\n\n// Import refactored modules\nimport {\n Frame,\n FrameContext,\n Anchor,\n Event,\n FrameType,\n FrameState,\n FrameCreationOptions,\n FrameManagerConfig,\n DigestResult,\n} from './frame-types.js';\nimport { FrameDatabase } from './frame-database.js';\nimport { FrameStack } from './frame-stack.js';\nimport { FrameDigestGenerator } from './frame-digest.js';\n\nexport class RefactoredFrameManager {\n private frameDb: FrameDatabase;\n private frameStack: FrameStack;\n private digestGenerator: FrameDigestGenerator;\n\n private currentRunId: string;\n private sessionId: string;\n private projectId: string;\n private queryMode: FrameQueryMode = FrameQueryMode.PROJECT_ACTIVE;\n private config: FrameManagerConfig;\n private maxFrameDepth: number = DEFAULT_MAX_DEPTH;\n\n constructor(\n db: Database.Database,\n projectId: string,\n config?: Partial<FrameManagerConfig>\n ) {\n this.projectId = projectId;\n this.config = {\n projectId,\n runId: config?.runId || uuidv4(),\n sessionId: config?.sessionId || uuidv4(),\n maxStackDepth: config?.maxStackDepth || 50,\n };\n \n // Set max frame depth from config if provided\n this.maxFrameDepth = config?.maxStackDepth || DEFAULT_MAX_DEPTH;\n\n this.currentRunId = this.config.runId!;\n this.sessionId = this.config.sessionId!;\n\n // Initialize modules\n this.frameDb = new FrameDatabase(db);\n this.frameStack = new FrameStack(\n this.frameDb,\n projectId,\n this.currentRunId\n );\n this.digestGenerator = new FrameDigestGenerator(this.frameDb);\n\n // Initialize database schema\n this.frameDb.initSchema();\n\n logger.info('RefactoredFrameManager initialized', {\n projectId: this.projectId,\n runId: this.currentRunId,\n sessionId: this.sessionId,\n });\n }\n\n /**\n * Initialize the frame manager\n */\n async initialize(): Promise<void> {\n try {\n await this.frameStack.initialize();\n\n logger.info('Frame manager initialization completed', {\n stackDepth: this.frameStack.getDepth(),\n });\n } catch (error: unknown) {\n throw new SystemError(\n 'Failed to initialize frame manager',\n ErrorCode.SYSTEM_INIT_FAILED,\n { projectId: this.projectId },\n error instanceof Error ? error : undefined\n );\n }\n }\n\n /**\n * Create a new frame\n */\n createFrame(options: FrameCreationOptions): string;\n createFrame(\n type: FrameType,\n name: string,\n inputs?: Record<string, any>,\n parentFrameId?: string\n ): string;\n createFrame(\n typeOrOptions: FrameType | FrameCreationOptions,\n name?: string,\n inputs?: Record<string, any>,\n parentFrameId?: string\n ): string {\n return trace.traceSync(\n 'function',\n 'FrameManager.createFrame',\n { typeOrOptions, name },\n () => this._createFrame(typeOrOptions, name, inputs, parentFrameId)\n );\n }\n\n private _createFrame(\n typeOrOptions: FrameType | FrameCreationOptions,\n name?: string,\n inputs?: Record<string, any>,\n parentFrameId?: string\n ): string {\n let frameOptions: FrameCreationOptions;\n\n // Handle both function signatures\n if (typeof typeOrOptions === 'string') {\n frameOptions = {\n type: typeOrOptions,\n name: name!,\n inputs: inputs || {},\n parentFrameId,\n };\n } else {\n frameOptions = typeOrOptions;\n }\n\n // Validate inputs\n if (!frameOptions.name || frameOptions.name.trim().length === 0) {\n throw new FrameError(\n 'Frame name is required',\n ErrorCode.FRAME_INVALID_INPUT,\n { frameOptions }\n );\n }\n\n // Check stack depth limit\n if (this.frameStack.getDepth() >= this.config.maxStackDepth!) {\n throw new FrameError(\n `Maximum stack depth reached: ${this.config.maxStackDepth}`,\n ErrorCode.FRAME_STACK_OVERFLOW,\n { currentDepth: this.frameStack.getDepth() }\n );\n }\n\n // Determine parent frame\n const resolvedParentId =\n frameOptions.parentFrameId || this.frameStack.getCurrentFrameId();\n \n // Get depth from parent frame, not from stack position\n let depth = 0;\n if (resolvedParentId) {\n const parentFrame = this.frameDb.getFrame(resolvedParentId);\n depth = parentFrame ? parentFrame.depth + 1 : 0;\n }\n\n // Check for depth limit\n if (depth > this.maxFrameDepth) {\n throw new FrameError(\n `Maximum frame depth exceeded: ${depth} > ${this.maxFrameDepth}`,\n ErrorCode.FRAME_STACK_OVERFLOW,\n {\n currentDepth: depth,\n maxDepth: this.maxFrameDepth,\n frameName: frameOptions.name,\n parentFrameId: resolvedParentId,\n }\n );\n }\n\n // Check for circular reference before creating frame\n if (resolvedParentId) {\n const cycle = this.detectCycle(uuidv4(), resolvedParentId);\n if (cycle) {\n throw new FrameError(\n `Circular reference detected in frame hierarchy`,\n ErrorCode.FRAME_CYCLE_DETECTED,\n {\n parentFrameId: resolvedParentId,\n cycle,\n frameName: frameOptions.name,\n }\n );\n }\n }\n\n // Create frame data\n const frameId = uuidv4();\n const frame: Omit<Frame, 'created_at' | 'closed_at'> = {\n frame_id: frameId,\n run_id: this.currentRunId,\n project_id: this.projectId,\n parent_frame_id: resolvedParentId,\n depth,\n type: frameOptions.type,\n name: frameOptions.name,\n state: 'active',\n inputs: frameOptions.inputs || {},\n outputs: {},\n digest_json: {},\n };\n\n // Insert into database\n const createdFrame = this.frameDb.insertFrame(frame);\n\n // Add to stack\n this.frameStack.pushFrame(frameId);\n\n logger.info('Created frame', {\n frameId,\n name: frameOptions.name,\n type: frameOptions.type,\n parentFrameId: resolvedParentId,\n stackDepth: this.frameStack.getDepth(),\n });\n\n return frameId;\n }\n\n /**\n * Close a frame and generate digest\n */\n closeFrame(frameId?: string, outputs?: Record<string, any>): void {\n trace.traceSync(\n 'function',\n 'FrameManager.closeFrame',\n { frameId, outputs },\n () => this._closeFrame(frameId, outputs)\n );\n }\n\n private _closeFrame(frameId?: string, outputs?: Record<string, any>): void {\n const targetFrameId = frameId || this.frameStack.getCurrentFrameId();\n if (!targetFrameId) {\n throw new FrameError(\n 'No active frame to close',\n ErrorCode.FRAME_INVALID_STATE,\n {\n operation: 'closeFrame',\n stackDepth: this.frameStack.getDepth(),\n }\n );\n }\n\n // Get frame details\n const frame = this.frameDb.getFrame(targetFrameId);\n if (!frame) {\n throw new FrameError(\n `Frame not found: ${targetFrameId}`,\n ErrorCode.FRAME_NOT_FOUND,\n {\n frameId: targetFrameId,\n operation: 'closeFrame',\n runId: this.currentRunId,\n }\n );\n }\n\n if (frame.state === 'closed') {\n logger.warn('Attempted to close already closed frame', {\n frameId: targetFrameId,\n });\n return;\n }\n\n // Generate digest before closing\n const digest = this.digestGenerator.generateDigest(targetFrameId);\n const finalOutputs = { ...outputs, ...digest.structured };\n\n // Update frame to closed state\n this.frameDb.updateFrame(targetFrameId, {\n state: 'closed',\n outputs: finalOutputs,\n digest_text: digest.text,\n digest_json: digest.structured,\n closed_at: Math.floor(Date.now() / 1000),\n });\n\n // Remove from stack (this will also remove any child frames)\n this.frameStack.popFrame(targetFrameId);\n\n // Close all child frames recursively\n this.closeChildFrames(targetFrameId);\n\n logger.info('Closed frame', {\n frameId: targetFrameId,\n name: frame.name,\n duration: Math.floor(Date.now() / 1000) - frame.created_at,\n digestLength: digest.text.length,\n stackDepth: this.frameStack.getDepth(),\n });\n }\n\n /**\n * Add an event to the current frame\n */\n addEvent(\n eventType: Event['event_type'],\n payload: Record<string, any>,\n frameId?: string\n ): string {\n return trace.traceSync(\n 'function',\n 'FrameManager.addEvent',\n { eventType, frameId },\n () => this._addEvent(eventType, payload, frameId)\n );\n }\n\n private _addEvent(\n eventType: Event['event_type'],\n payload: Record<string, any>,\n frameId?: string\n ): string {\n const targetFrameId = frameId || this.frameStack.getCurrentFrameId();\n if (!targetFrameId) {\n throw new FrameError(\n 'No active frame for event',\n ErrorCode.FRAME_INVALID_STATE,\n {\n eventType,\n operation: 'addEvent',\n }\n );\n }\n\n const eventId = uuidv4();\n const sequence = this.frameDb.getNextEventSequence(targetFrameId);\n\n const event: Omit<Event, 'ts'> = {\n event_id: eventId,\n frame_id: targetFrameId,\n run_id: this.currentRunId,\n seq: sequence,\n event_type: eventType,\n payload,\n };\n\n const createdEvent = this.frameDb.insertEvent(event);\n\n logger.debug('Added event', {\n eventId,\n frameId: targetFrameId,\n eventType,\n sequence,\n });\n\n return eventId;\n }\n\n /**\n * Add an anchor (important fact) to current frame\n */\n addAnchor(\n type: Anchor['type'],\n text: string,\n priority: number = 5,\n metadata: Record<string, any> = {},\n frameId?: string\n ): string {\n return trace.traceSync(\n 'function',\n 'FrameManager.addAnchor',\n { type, frameId },\n () => this._addAnchor(type, text, priority, metadata, frameId)\n );\n }\n\n private _addAnchor(\n type: Anchor['type'],\n text: string,\n priority: number,\n metadata: Record<string, any>,\n frameId?: string\n ): string {\n const targetFrameId = frameId || this.frameStack.getCurrentFrameId();\n if (!targetFrameId) {\n throw new FrameError(\n 'No active frame for anchor',\n ErrorCode.FRAME_INVALID_STATE,\n {\n anchorType: type,\n operation: 'addAnchor',\n }\n );\n }\n\n const anchorId = uuidv4();\n const anchor: Omit<Anchor, 'created_at'> = {\n anchor_id: anchorId,\n frame_id: targetFrameId,\n type,\n text,\n priority,\n metadata,\n };\n\n const createdAnchor = this.frameDb.insertAnchor(anchor);\n\n logger.debug('Added anchor', {\n anchorId,\n frameId: targetFrameId,\n type,\n priority,\n });\n\n return anchorId;\n }\n\n /**\n * Get hot stack context\n */\n getHotStackContext(maxEvents: number = 20): FrameContext[] {\n return this.frameStack.getHotStackContext(maxEvents);\n }\n\n /**\n * Get active frame path (root to current)\n */\n getActiveFramePath(): Frame[] {\n return this.frameStack.getStackFrames();\n }\n\n /**\n * Get current frame ID\n */\n getCurrentFrameId(): string | undefined {\n return this.frameStack.getCurrentFrameId();\n }\n\n /**\n * Get stack depth\n */\n getStackDepth(): number {\n return this.frameStack.getDepth();\n }\n\n /**\n * Get frame by ID\n */\n getFrame(frameId: string): Frame | undefined {\n return this.frameDb.getFrame(frameId);\n }\n\n /**\n * Get frame events\n */\n getFrameEvents(frameId: string, limit?: number): Event[] {\n return this.frameDb.getFrameEvents(frameId, limit);\n }\n\n /**\n * Get frame anchors\n */\n getFrameAnchors(frameId: string): Anchor[] {\n return this.frameDb.getFrameAnchors(frameId);\n }\n\n /**\n * Generate digest for a frame\n */\n generateDigest(frameId: string): DigestResult {\n return this.digestGenerator.generateDigest(frameId);\n }\n\n /**\n * Validate stack consistency\n */\n validateStack(): { isValid: boolean; errors: string[] } {\n return this.frameStack.validateStack();\n }\n\n /**\n * Get database statistics\n */\n getStatistics(): Record<string, number> {\n return this.frameDb.getStatistics();\n }\n\n /**\n * Close all child frames recursively\n */\n private closeChildFrames(parentFrameId: string): void {\n try {\n const activeFrames = this.frameDb.getFramesByProject(\n this.projectId,\n 'active'\n );\n const childFrames = activeFrames.filter(\n (f: any) => f.parent_frame_id === parentFrameId\n );\n\n for (const childFrame of childFrames) {\n if (this.frameStack.isFrameActive(childFrame.frame_id)) {\n this.closeFrame(childFrame.frame_id);\n }\n }\n } catch (error: unknown) {\n logger.warn('Failed to close child frames', { parentFrameId, error });\n }\n }\n\n /**\n * Extract active artifacts from frame events\n */\n getActiveArtifacts(frameId: string): string[] {\n const events = this.frameDb.getFrameEvents(frameId);\n const artifacts: string[] = [];\n\n for (const event of events) {\n if (event.event_type === 'artifact' && event.payload.path) {\n artifacts.push(event.payload.path);\n }\n }\n\n return [...new Set(artifacts)];\n }\n\n /**\n * Extract constraints from frame inputs\n */\n extractConstraints(inputs: Record<string, any>): string[] {\n const constraints: string[] = [];\n\n if (inputs.constraints && Array.isArray(inputs.constraints)) {\n constraints.push(...inputs.constraints);\n }\n\n if (inputs.requirements && Array.isArray(inputs.requirements)) {\n constraints.push(...inputs.requirements);\n }\n\n if (inputs.limitations && Array.isArray(inputs.limitations)) {\n constraints.push(...inputs.limitations);\n }\n\n return constraints;\n }\n\n /**\n * Detect if setting a parent frame would create a cycle in the frame hierarchy.\n * Returns the cycle path if detected, or null if no cycle.\n * @param childFrameId - The frame that would be the child\n * @param parentFrameId - The proposed parent frame\n * @returns Array of frame IDs forming the cycle, or null if no cycle\n */\n private detectCycle(\n childFrameId: string,\n parentFrameId: string\n ): string[] | null {\n const visited = new Set<string>();\n const path: string[] = [];\n\n // Start from the proposed parent and traverse up the hierarchy\n let currentId: string | undefined = parentFrameId;\n \n while (currentId) {\n // If we've seen this frame before, we have a cycle\n if (visited.has(currentId)) {\n // Build the cycle path\n const cycleStart = path.indexOf(currentId);\n return path.slice(cycleStart).concat(currentId);\n }\n\n // If the current frame is the child we're trying to add, it's a cycle\n if (currentId === childFrameId) {\n return path.concat([currentId, childFrameId]);\n }\n\n visited.add(currentId);\n path.push(currentId);\n\n // Move to the parent of current frame\n const frame = this.frameDb.getFrame(currentId);\n if (!frame) {\n // Frame not found, no cycle possible through this path\n break;\n }\n currentId = frame.parent_frame_id;\n\n // Safety check: if we've traversed too many levels, something is wrong\n if (path.length > this.maxFrameDepth) {\n throw new FrameError(\n `Frame hierarchy traversal exceeded maximum depth during cycle detection`,\n ErrorCode.FRAME_STACK_OVERFLOW,\n {\n depth: path.length,\n maxDepth: this.maxFrameDepth,\n path,\n }\n );\n }\n }\n\n return null; // No cycle detected\n }\n\n /**\n * Update parent frame of an existing frame (with cycle detection)\n * @param frameId - The frame to update\n * @param newParentFrameId - The new parent frame ID (null to make it a root frame)\n */\n public updateParentFrame(frameId: string, newParentFrameId: string | null): void {\n // Check if frame exists\n const frame = this.frameDb.getFrame(frameId);\n if (!frame) {\n throw new FrameError(\n `Frame not found: ${frameId}`,\n ErrorCode.FRAME_NOT_FOUND,\n { frameId }\n );\n }\n\n // If setting a parent, check for cycles\n if (newParentFrameId) {\n const cycle = this.detectCycle(frameId, newParentFrameId);\n if (cycle) {\n throw new FrameError(\n `Cannot set parent: would create circular reference`,\n ErrorCode.FRAME_CYCLE_DETECTED,\n {\n frameId,\n newParentFrameId,\n cycle,\n currentParentId: frame.parent_frame_id,\n }\n );\n }\n\n // Check depth after parent change\n const newParentFrame = this.frameDb.getFrame(newParentFrameId);\n if (newParentFrame) {\n const newDepth = newParentFrame.depth + 1;\n if (newDepth > this.maxFrameDepth) {\n throw new FrameError(\n `Cannot set parent: would exceed maximum frame depth`,\n ErrorCode.FRAME_STACK_OVERFLOW,\n {\n frameId,\n newParentFrameId,\n newDepth,\n maxDepth: this.maxFrameDepth,\n }\n );\n }\n }\n }\n\n // Update the frame's parent (this would need to be implemented in FrameDatabase)\n this.frameDb.updateFrame(frameId, {\n parent_frame_id: newParentFrameId,\n });\n\n logger.info('Updated parent frame', {\n frameId,\n oldParentId: frame.parent_frame_id,\n newParentId: newParentFrameId,\n });\n }\n\n /**\n * Validate the entire frame hierarchy for cycles and depth violations\n * @returns Validation result with any detected issues\n */\n public validateFrameHierarchy(): {\n isValid: boolean;\n errors: string[];\n warnings: string[];\n } {\n const errors: string[] = [];\n const warnings: string[] = [];\n const allFrames = this.frameDb.getFramesByProject(this.projectId);\n \n // Check each frame for depth violations\n for (const frame of allFrames) {\n if (frame.depth > this.maxFrameDepth) {\n errors.push(\n `Frame ${frame.frame_id} exceeds max depth: ${frame.depth} > ${this.maxFrameDepth}`\n );\n }\n \n // Warn about deep frames approaching the limit\n if (frame.depth > this.maxFrameDepth * 0.8) {\n warnings.push(\n `Frame ${frame.frame_id} is deep in hierarchy: ${frame.depth}/${this.maxFrameDepth}`\n );\n }\n }\n \n // Check for cycles by traversing from each root\n const rootFrames = allFrames.filter(f => !f.parent_frame_id);\n const visited = new Set<string>();\n const visiting = new Set<string>();\n \n const checkForCycle = (frameId: string): boolean => {\n if (visiting.has(frameId)) {\n errors.push(`Cycle detected involving frame ${frameId}`);\n return true;\n }\n \n if (visited.has(frameId)) {\n return false;\n }\n \n visiting.add(frameId);\n \n // Check all children\n const children = allFrames.filter(f => f.parent_frame_id === frameId);\n for (const child of children) {\n if (checkForCycle(child.frame_id)) {\n return true;\n }\n }\n \n visiting.delete(frameId);\n visited.add(frameId);\n return false;\n };\n \n // Check from each root\n for (const root of rootFrames) {\n checkForCycle(root.frame_id);\n }\n \n return {\n isValid: errors.length === 0,\n errors,\n warnings,\n };\n }\n}\n\n// Re-export types for compatibility\nexport {\n Frame,\n FrameContext,\n Anchor,\n Event,\n FrameType,\n FrameState,\n FrameCreationOptions,\n FrameManagerConfig,\n DigestResult,\n} from './frame-types.js';\n"],
|
|
5
|
-
"mappings": ";;;;AAMA,SAAS,MAAM,cAAc;AAC7B,SAAS,cAAc;AACvB,SAAS,aAAa;AACtB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAEP,SAAyB,sBAAsB;AAG/C,MAAM,kBAAkB;AACxB,MAAM,oBAAoB;AAc1B,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB;AAC3B,SAAS,4BAA4B;AAE9B,MAAM,uBAAuB;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EA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"names": ["
|
|
4
|
+
"sourcesContent": ["/**\n * Refactored Frame Manager - Modular Implementation\n * Main orchestrator that uses focused modules for frame management\n */\n\nimport Database from 'better-sqlite3';\nimport { v4 as uuidv4 } from 'uuid';\nimport { logger } from '../monitoring/logger.js';\nimport { trace } from '../trace/index.js';\nimport {\n FrameError,\n SystemError,\n ErrorCode,\n wrapError,\n createErrorHandler,\n} from '../errors/index.js';\nimport { retry, withTimeout } from '../errors/recovery.js';\nimport { sessionManager, FrameQueryMode } from '../session/index.js';\nimport { frameLifecycleHooks } from './frame-lifecycle-hooks.js';\n\n// Constants for frame validation\nconst MAX_FRAME_DEPTH = 100; // Maximum allowed frame depth\nconst DEFAULT_MAX_DEPTH = 100; // Default if not configured\n\n// Import refactored modules\nimport {\n Frame,\n FrameContext,\n Anchor,\n Event,\n FrameType,\n FrameState,\n FrameCreationOptions,\n FrameManagerConfig,\n DigestResult,\n} from './frame-types.js';\nimport { FrameDatabase } from './frame-database.js';\nimport { FrameStack } from './frame-stack.js';\nimport { FrameDigestGenerator } from './frame-digest.js';\n\nexport class RefactoredFrameManager {\n private frameDb: FrameDatabase;\n private frameStack: FrameStack;\n private digestGenerator: FrameDigestGenerator;\n\n private currentRunId: string;\n private sessionId: string;\n private projectId: string;\n private queryMode: FrameQueryMode = FrameQueryMode.PROJECT_ACTIVE;\n private config: FrameManagerConfig;\n private maxFrameDepth: number = DEFAULT_MAX_DEPTH;\n\n constructor(\n db: Database.Database,\n projectId: string,\n config?: Partial<FrameManagerConfig>\n ) {\n this.projectId = projectId;\n this.config = {\n projectId,\n runId: config?.runId || uuidv4(),\n sessionId: config?.sessionId || uuidv4(),\n maxStackDepth: config?.maxStackDepth || 50,\n };\n \n // Set max frame depth from config if provided\n this.maxFrameDepth = config?.maxStackDepth || DEFAULT_MAX_DEPTH;\n\n this.currentRunId = this.config.runId!;\n this.sessionId = this.config.sessionId!;\n\n // Initialize modules\n this.frameDb = new FrameDatabase(db);\n this.frameStack = new FrameStack(\n this.frameDb,\n projectId,\n this.currentRunId\n );\n this.digestGenerator = new FrameDigestGenerator(this.frameDb);\n\n // Initialize database schema\n this.frameDb.initSchema();\n\n logger.info('RefactoredFrameManager initialized', {\n projectId: this.projectId,\n runId: this.currentRunId,\n sessionId: this.sessionId,\n });\n }\n\n /**\n * Initialize the frame manager\n */\n async initialize(): Promise<void> {\n try {\n await this.frameStack.initialize();\n\n logger.info('Frame manager initialization completed', {\n stackDepth: this.frameStack.getDepth(),\n });\n } catch (error: unknown) {\n throw new SystemError(\n 'Failed to initialize frame manager',\n ErrorCode.SYSTEM_INIT_FAILED,\n { projectId: this.projectId },\n error instanceof Error ? error : undefined\n );\n }\n }\n\n /**\n * Create a new frame\n */\n createFrame(options: FrameCreationOptions): string;\n createFrame(\n type: FrameType,\n name: string,\n inputs?: Record<string, any>,\n parentFrameId?: string\n ): string;\n createFrame(\n typeOrOptions: FrameType | FrameCreationOptions,\n name?: string,\n inputs?: Record<string, any>,\n parentFrameId?: string\n ): string {\n return trace.traceSync(\n 'function',\n 'FrameManager.createFrame',\n { typeOrOptions, name },\n () => this._createFrame(typeOrOptions, name, inputs, parentFrameId)\n );\n }\n\n private _createFrame(\n typeOrOptions: FrameType | FrameCreationOptions,\n name?: string,\n inputs?: Record<string, any>,\n parentFrameId?: string\n ): string {\n let frameOptions: FrameCreationOptions;\n\n // Handle both function signatures\n if (typeof typeOrOptions === 'string') {\n frameOptions = {\n type: typeOrOptions,\n name: name!,\n inputs: inputs || {},\n parentFrameId,\n };\n } else {\n frameOptions = typeOrOptions;\n }\n\n // Validate inputs\n if (!frameOptions.name || frameOptions.name.trim().length === 0) {\n throw new FrameError(\n 'Frame name is required',\n ErrorCode.FRAME_INVALID_INPUT,\n { frameOptions }\n );\n }\n\n // Check stack depth limit\n if (this.frameStack.getDepth() >= this.config.maxStackDepth!) {\n throw new FrameError(\n `Maximum stack depth reached: ${this.config.maxStackDepth}`,\n ErrorCode.FRAME_STACK_OVERFLOW,\n { currentDepth: this.frameStack.getDepth() }\n );\n }\n\n // Determine parent frame\n const resolvedParentId =\n frameOptions.parentFrameId || this.frameStack.getCurrentFrameId();\n \n // Get depth from parent frame, not from stack position\n let depth = 0;\n if (resolvedParentId) {\n const parentFrame = this.frameDb.getFrame(resolvedParentId);\n depth = parentFrame ? parentFrame.depth + 1 : 0;\n }\n\n // Check for depth limit\n if (depth > this.maxFrameDepth) {\n throw new FrameError(\n `Maximum frame depth exceeded: ${depth} > ${this.maxFrameDepth}`,\n ErrorCode.FRAME_STACK_OVERFLOW,\n {\n currentDepth: depth,\n maxDepth: this.maxFrameDepth,\n frameName: frameOptions.name,\n parentFrameId: resolvedParentId,\n }\n );\n }\n\n // Check for circular reference before creating frame\n if (resolvedParentId) {\n const cycle = this.detectCycle(uuidv4(), resolvedParentId);\n if (cycle) {\n throw new FrameError(\n `Circular reference detected in frame hierarchy`,\n ErrorCode.FRAME_CYCLE_DETECTED,\n {\n parentFrameId: resolvedParentId,\n cycle,\n frameName: frameOptions.name,\n }\n );\n }\n }\n\n // Create frame data\n const frameId = uuidv4();\n const frame: Omit<Frame, 'created_at' | 'closed_at'> = {\n frame_id: frameId,\n run_id: this.currentRunId,\n project_id: this.projectId,\n parent_frame_id: resolvedParentId,\n depth,\n type: frameOptions.type,\n name: frameOptions.name,\n state: 'active',\n inputs: frameOptions.inputs || {},\n outputs: {},\n digest_json: {},\n };\n\n // Insert into database\n const createdFrame = this.frameDb.insertFrame(frame);\n\n // Add to stack\n this.frameStack.pushFrame(frameId);\n\n logger.info('Created frame', {\n frameId,\n name: frameOptions.name,\n type: frameOptions.type,\n parentFrameId: resolvedParentId,\n stackDepth: this.frameStack.getDepth(),\n });\n\n return frameId;\n }\n\n /**\n * Close a frame and generate digest\n */\n closeFrame(frameId?: string, outputs?: Record<string, any>): void {\n trace.traceSync(\n 'function',\n 'FrameManager.closeFrame',\n { frameId, outputs },\n () => this._closeFrame(frameId, outputs)\n );\n }\n\n private _closeFrame(frameId?: string, outputs?: Record<string, any>): void {\n const targetFrameId = frameId || this.frameStack.getCurrentFrameId();\n if (!targetFrameId) {\n throw new FrameError(\n 'No active frame to close',\n ErrorCode.FRAME_INVALID_STATE,\n {\n operation: 'closeFrame',\n stackDepth: this.frameStack.getDepth(),\n }\n );\n }\n\n // Get frame details\n const frame = this.frameDb.getFrame(targetFrameId);\n if (!frame) {\n throw new FrameError(\n `Frame not found: ${targetFrameId}`,\n ErrorCode.FRAME_NOT_FOUND,\n {\n frameId: targetFrameId,\n operation: 'closeFrame',\n runId: this.currentRunId,\n }\n );\n }\n\n if (frame.state === 'closed') {\n logger.warn('Attempted to close already closed frame', {\n frameId: targetFrameId,\n });\n return;\n }\n\n // Generate digest before closing\n const digest = this.digestGenerator.generateDigest(targetFrameId);\n const finalOutputs = { ...outputs, ...digest.structured };\n\n // Update frame to closed state\n this.frameDb.updateFrame(targetFrameId, {\n state: 'closed',\n outputs: finalOutputs,\n digest_text: digest.text,\n digest_json: digest.structured,\n closed_at: Math.floor(Date.now() / 1000),\n });\n\n // Remove from stack (this will also remove any child frames)\n this.frameStack.popFrame(targetFrameId);\n\n // Close all child frames recursively\n this.closeChildFrames(targetFrameId);\n\n // Trigger lifecycle hooks (fire and forget)\n const events = this.frameDb.getFrameEvents(targetFrameId);\n const anchors = this.frameDb.getFrameAnchors(targetFrameId);\n frameLifecycleHooks\n .triggerClose({ frame: { ...frame, state: 'closed' }, events, anchors })\n .catch(() => {\n // Silently ignore errors - hooks are non-critical\n });\n\n logger.info('Closed frame', {\n frameId: targetFrameId,\n name: frame.name,\n duration: Math.floor(Date.now() / 1000) - frame.created_at,\n digestLength: digest.text.length,\n stackDepth: this.frameStack.getDepth(),\n });\n }\n\n /**\n * Add an event to the current frame\n */\n addEvent(\n eventType: Event['event_type'],\n payload: Record<string, any>,\n frameId?: string\n ): string {\n return trace.traceSync(\n 'function',\n 'FrameManager.addEvent',\n { eventType, frameId },\n () => this._addEvent(eventType, payload, frameId)\n );\n }\n\n private _addEvent(\n eventType: Event['event_type'],\n payload: Record<string, any>,\n frameId?: string\n ): string {\n const targetFrameId = frameId || this.frameStack.getCurrentFrameId();\n if (!targetFrameId) {\n throw new FrameError(\n 'No active frame for event',\n ErrorCode.FRAME_INVALID_STATE,\n {\n eventType,\n operation: 'addEvent',\n }\n );\n }\n\n const eventId = uuidv4();\n const sequence = this.frameDb.getNextEventSequence(targetFrameId);\n\n const event: Omit<Event, 'ts'> = {\n event_id: eventId,\n frame_id: targetFrameId,\n run_id: this.currentRunId,\n seq: sequence,\n event_type: eventType,\n payload,\n };\n\n const createdEvent = this.frameDb.insertEvent(event);\n\n logger.debug('Added event', {\n eventId,\n frameId: targetFrameId,\n eventType,\n sequence,\n });\n\n return eventId;\n }\n\n /**\n * Add an anchor (important fact) to current frame\n */\n addAnchor(\n type: Anchor['type'],\n text: string,\n priority: number = 5,\n metadata: Record<string, any> = {},\n frameId?: string\n ): string {\n return trace.traceSync(\n 'function',\n 'FrameManager.addAnchor',\n { type, frameId },\n () => this._addAnchor(type, text, priority, metadata, frameId)\n );\n }\n\n private _addAnchor(\n type: Anchor['type'],\n text: string,\n priority: number,\n metadata: Record<string, any>,\n frameId?: string\n ): string {\n const targetFrameId = frameId || this.frameStack.getCurrentFrameId();\n if (!targetFrameId) {\n throw new FrameError(\n 'No active frame for anchor',\n ErrorCode.FRAME_INVALID_STATE,\n {\n anchorType: type,\n operation: 'addAnchor',\n }\n );\n }\n\n const anchorId = uuidv4();\n const anchor: Omit<Anchor, 'created_at'> = {\n anchor_id: anchorId,\n frame_id: targetFrameId,\n type,\n text,\n priority,\n metadata,\n };\n\n const createdAnchor = this.frameDb.insertAnchor(anchor);\n\n logger.debug('Added anchor', {\n anchorId,\n frameId: targetFrameId,\n type,\n priority,\n });\n\n return anchorId;\n }\n\n /**\n * Get hot stack context\n */\n getHotStackContext(maxEvents: number = 20): FrameContext[] {\n return this.frameStack.getHotStackContext(maxEvents);\n }\n\n /**\n * Get active frame path (root to current)\n */\n getActiveFramePath(): Frame[] {\n return this.frameStack.getStackFrames();\n }\n\n /**\n * Get current frame ID\n */\n getCurrentFrameId(): string | undefined {\n return this.frameStack.getCurrentFrameId();\n }\n\n /**\n * Get stack depth\n */\n getStackDepth(): number {\n return this.frameStack.getDepth();\n }\n\n /**\n * Get frame by ID\n */\n getFrame(frameId: string): Frame | undefined {\n return this.frameDb.getFrame(frameId);\n }\n\n /**\n * Get frame events\n */\n getFrameEvents(frameId: string, limit?: number): Event[] {\n return this.frameDb.getFrameEvents(frameId, limit);\n }\n\n /**\n * Get frame anchors\n */\n getFrameAnchors(frameId: string): Anchor[] {\n return this.frameDb.getFrameAnchors(frameId);\n }\n\n /**\n * Generate digest for a frame\n */\n generateDigest(frameId: string): DigestResult {\n return this.digestGenerator.generateDigest(frameId);\n }\n\n /**\n * Validate stack consistency\n */\n validateStack(): { isValid: boolean; errors: string[] } {\n return this.frameStack.validateStack();\n }\n\n /**\n * Get database statistics\n */\n getStatistics(): Record<string, number> {\n return this.frameDb.getStatistics();\n }\n\n /**\n * Close all child frames recursively\n */\n private closeChildFrames(parentFrameId: string): void {\n try {\n const activeFrames = this.frameDb.getFramesByProject(\n this.projectId,\n 'active'\n );\n const childFrames = activeFrames.filter(\n (f: any) => f.parent_frame_id === parentFrameId\n );\n\n for (const childFrame of childFrames) {\n if (this.frameStack.isFrameActive(childFrame.frame_id)) {\n this.closeFrame(childFrame.frame_id);\n }\n }\n } catch (error: unknown) {\n logger.warn('Failed to close child frames', { parentFrameId, error });\n }\n }\n\n /**\n * Extract active artifacts from frame events\n */\n getActiveArtifacts(frameId: string): string[] {\n const events = this.frameDb.getFrameEvents(frameId);\n const artifacts: string[] = [];\n\n for (const event of events) {\n if (event.event_type === 'artifact' && event.payload.path) {\n artifacts.push(event.payload.path);\n }\n }\n\n return [...new Set(artifacts)];\n }\n\n /**\n * Extract constraints from frame inputs\n */\n extractConstraints(inputs: Record<string, any>): string[] {\n const constraints: string[] = [];\n\n if (inputs.constraints && Array.isArray(inputs.constraints)) {\n constraints.push(...inputs.constraints);\n }\n\n if (inputs.requirements && Array.isArray(inputs.requirements)) {\n constraints.push(...inputs.requirements);\n }\n\n if (inputs.limitations && Array.isArray(inputs.limitations)) {\n constraints.push(...inputs.limitations);\n }\n\n return constraints;\n }\n\n /**\n * Detect if setting a parent frame would create a cycle in the frame hierarchy.\n * Returns the cycle path if detected, or null if no cycle.\n * @param childFrameId - The frame that would be the child\n * @param parentFrameId - The proposed parent frame\n * @returns Array of frame IDs forming the cycle, or null if no cycle\n */\n private detectCycle(\n childFrameId: string,\n parentFrameId: string\n ): string[] | null {\n const visited = new Set<string>();\n const path: string[] = [];\n\n // Start from the proposed parent and traverse up the hierarchy\n let currentId: string | undefined = parentFrameId;\n \n while (currentId) {\n // If we've seen this frame before, we have a cycle\n if (visited.has(currentId)) {\n // Build the cycle path\n const cycleStart = path.indexOf(currentId);\n return path.slice(cycleStart).concat(currentId);\n }\n\n // If the current frame is the child we're trying to add, it's a cycle\n if (currentId === childFrameId) {\n return path.concat([currentId, childFrameId]);\n }\n\n visited.add(currentId);\n path.push(currentId);\n\n // Move to the parent of current frame\n const frame = this.frameDb.getFrame(currentId);\n if (!frame) {\n // Frame not found, no cycle possible through this path\n break;\n }\n currentId = frame.parent_frame_id;\n\n // Safety check: if we've traversed too many levels, something is wrong\n if (path.length > this.maxFrameDepth) {\n throw new FrameError(\n `Frame hierarchy traversal exceeded maximum depth during cycle detection`,\n ErrorCode.FRAME_STACK_OVERFLOW,\n {\n depth: path.length,\n maxDepth: this.maxFrameDepth,\n path,\n }\n );\n }\n }\n\n return null; // No cycle detected\n }\n\n /**\n * Update parent frame of an existing frame (with cycle detection)\n * @param frameId - The frame to update\n * @param newParentFrameId - The new parent frame ID (null to make it a root frame)\n */\n public updateParentFrame(frameId: string, newParentFrameId: string | null): void {\n // Check if frame exists\n const frame = this.frameDb.getFrame(frameId);\n if (!frame) {\n throw new FrameError(\n `Frame not found: ${frameId}`,\n ErrorCode.FRAME_NOT_FOUND,\n { frameId }\n );\n }\n\n // If setting a parent, validate and check for cycles\n if (newParentFrameId) {\n // Verify the new parent exists\n const newParentFrame = this.frameDb.getFrame(newParentFrameId);\n if (!newParentFrame) {\n throw new FrameError(\n `Parent frame not found: ${newParentFrameId}`,\n ErrorCode.FRAME_NOT_FOUND,\n { frameId, newParentFrameId }\n );\n }\n\n const cycle = this.detectCycle(frameId, newParentFrameId);\n if (cycle) {\n throw new FrameError(\n `Cannot set parent: would create circular reference`,\n ErrorCode.FRAME_CYCLE_DETECTED,\n {\n frameId,\n newParentFrameId,\n cycle,\n currentParentId: frame.parent_frame_id,\n }\n );\n }\n\n // Check depth after parent change\n const newDepth = newParentFrame.depth + 1;\n if (newDepth > this.maxFrameDepth) {\n throw new FrameError(\n `Cannot set parent: would exceed maximum frame depth`,\n ErrorCode.FRAME_STACK_OVERFLOW,\n {\n frameId,\n newParentFrameId,\n newDepth,\n maxDepth: this.maxFrameDepth,\n }\n );\n }\n }\n\n // Calculate new depth based on parent\n let newDepth = 0;\n if (newParentFrameId) {\n const newParentFrame = this.frameDb.getFrame(newParentFrameId);\n if (newParentFrame) {\n newDepth = newParentFrame.depth + 1;\n }\n }\n\n // Update the frame's parent and depth\n this.frameDb.updateFrame(frameId, {\n parent_frame_id: newParentFrameId,\n depth: newDepth,\n });\n\n logger.info('Updated parent frame', {\n frameId,\n oldParentId: frame.parent_frame_id,\n newParentId: newParentFrameId,\n });\n }\n\n /**\n * Validate the entire frame hierarchy for cycles and depth violations\n * @returns Validation result with any detected issues\n */\n public validateFrameHierarchy(): {\n isValid: boolean;\n errors: string[];\n warnings: string[];\n } {\n const errors: string[] = [];\n const warnings: string[] = [];\n const allFrames = this.frameDb.getFramesByProject(this.projectId);\n \n // Check each frame for depth violations\n for (const frame of allFrames) {\n if (frame.depth > this.maxFrameDepth) {\n errors.push(\n `Frame ${frame.frame_id} exceeds max depth: ${frame.depth} > ${this.maxFrameDepth}`\n );\n }\n \n // Warn about deep frames approaching the limit\n if (frame.depth > this.maxFrameDepth * 0.8) {\n warnings.push(\n `Frame ${frame.frame_id} is deep in hierarchy: ${frame.depth}/${this.maxFrameDepth}`\n );\n }\n }\n \n // Check for cycles by traversing from each root\n const rootFrames = allFrames.filter(f => !f.parent_frame_id);\n const visited = new Set<string>();\n const visiting = new Set<string>();\n \n const checkForCycle = (frameId: string): boolean => {\n if (visiting.has(frameId)) {\n errors.push(`Cycle detected involving frame ${frameId}`);\n return true;\n }\n \n if (visited.has(frameId)) {\n return false;\n }\n \n visiting.add(frameId);\n \n // Check all children\n const children = allFrames.filter(f => f.parent_frame_id === frameId);\n for (const child of children) {\n if (checkForCycle(child.frame_id)) {\n return true;\n }\n }\n \n visiting.delete(frameId);\n visited.add(frameId);\n return false;\n };\n \n // Check from each root\n for (const root of rootFrames) {\n checkForCycle(root.frame_id);\n }\n \n return {\n isValid: errors.length === 0,\n errors,\n warnings,\n };\n }\n\n /**\n * Set query mode for frame retrieval\n */\n setQueryMode(mode: FrameQueryMode): void {\n this.queryMode = mode;\n // Reinitialize stack with new query mode\n this.frameStack.setQueryMode(mode);\n }\n\n /**\n * Get recent frames for context sharing\n */\n async getRecentFrames(limit: number = 100): Promise<Frame[]> {\n try {\n const frames = this.frameDb.getFramesByProject(this.projectId);\n\n // Sort by created_at descending and limit\n return frames\n .sort((a, b) => (b.created_at || 0) - (a.created_at || 0))\n .slice(0, limit)\n .map((frame) => ({\n ...frame,\n // Add compatibility fields\n frameId: frame.frame_id,\n runId: frame.run_id,\n projectId: frame.project_id,\n parentFrameId: frame.parent_frame_id,\n title: frame.name,\n timestamp: frame.created_at,\n metadata: {\n tags: this.extractTagsFromFrame(frame),\n importance: this.calculateFrameImportance(frame),\n },\n data: {\n inputs: frame.inputs,\n outputs: frame.outputs,\n digest: frame.digest_json,\n },\n }));\n } catch (error: unknown) {\n logger.error('Failed to get recent frames', error as Error);\n return [];\n }\n }\n\n /**\n * Add context metadata to the current frame\n */\n async addContext(key: string, value: any): Promise<void> {\n const currentFrameId = this.frameStack.getCurrentFrameId();\n if (!currentFrameId) return;\n\n try {\n const frame = this.frameDb.getFrame(currentFrameId);\n if (!frame) return;\n\n const metadata = frame.outputs || {};\n metadata[key] = value;\n\n this.frameDb.updateFrame(currentFrameId, {\n outputs: metadata,\n });\n } catch (error: unknown) {\n logger.warn('Failed to add context to frame', { error, key });\n }\n }\n\n /**\n * Delete a frame completely from the database (used in handoffs)\n */\n deleteFrame(frameId: string): void {\n try {\n // Remove from active stack if present\n this.frameStack.removeFrame(frameId);\n\n // Delete the frame and related data (cascades via FrameDatabase)\n this.frameDb.deleteFrame(frameId);\n\n logger.debug('Deleted frame completely', { frameId });\n } catch (error: unknown) {\n logger.error('Failed to delete frame', { frameId, error });\n throw error;\n }\n }\n\n /**\n * Extract tags from frame for categorization\n */\n private extractTagsFromFrame(frame: Frame): string[] {\n const tags: string[] = [];\n\n if (frame.type) tags.push(frame.type);\n\n if (frame.name) {\n const nameLower = frame.name.toLowerCase();\n if (nameLower.includes('error')) tags.push('error');\n if (nameLower.includes('fix')) tags.push('resolution');\n if (nameLower.includes('decision')) tags.push('decision');\n if (nameLower.includes('milestone')) tags.push('milestone');\n }\n\n try {\n if (frame.digest_json && typeof frame.digest_json === 'object') {\n const digest = frame.digest_json as Record<string, unknown>;\n if (Array.isArray(digest.tags)) {\n tags.push(...(digest.tags as string[]));\n }\n }\n } catch {\n // Ignore parse errors\n }\n\n return [...new Set(tags)];\n }\n\n /**\n * Calculate frame importance for prioritization\n */\n private calculateFrameImportance(frame: Frame): 'high' | 'medium' | 'low' {\n if (frame.type === 'milestone' || frame.name?.includes('decision')) {\n return 'high';\n }\n\n if (frame.type === 'error' || frame.type === 'resolution') {\n return 'medium';\n }\n\n if (frame.closed_at && frame.created_at) {\n const duration = frame.closed_at - frame.created_at;\n if (duration > 300) return 'medium';\n }\n\n return 'low';\n }\n}\n\n// Re-export types for compatibility (type-only, no runtime value)\nexport type {\n Frame,\n FrameContext,\n Anchor,\n Event,\n FrameType,\n FrameState,\n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OAAO,EAAG,MAAK,KAAK,OAAO;AAClD,UAAI,UAAU,SAAS,KAAK,EAAG,MAAK,KAAK,YAAY;AACrD,UAAI,UAAU,SAAS,UAAU,EAAG,MAAK,KAAK,UAAU;AACxD,UAAI,UAAU,SAAS,WAAW,EAAG,MAAK,KAAK,WAAW;AAAA,IAC5D;AAEA,QAAI;AACF,UAAI,MAAM,eAAe,OAAO,MAAM,gBAAgB,UAAU;AAC9D,cAAM,SAAS,MAAM;AACrB,YAAI,MAAM,QAAQ,OAAO,IAAI,GAAG;AAC9B,eAAK,KAAK,GAAI,OAAO,IAAiB;AAAA,QACxC;AAAA,MACF;AAAA,IACF,QAAQ;AAAA,IAER;AAEA,WAAO,CAAC,GAAG,IAAI,IAAI,IAAI,CAAC;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA,EAKQ,yBAAyB,OAAyC;AACxE,QAAI,MAAM,SAAS,eAAe,MAAM,MAAM,SAAS,UAAU,GAAG;AAClE,aAAO;AAAA,IACT;AAEA,QAAI,MAAM,SAAS,WAAW,MAAM,SAAS,cAAc;AACzD,aAAO;AAAA,IACT;AAEA,QAAI,MAAM,aAAa,MAAM,YAAY;AACvC,YAAM,WAAW,MAAM,YAAY,MAAM;AACzC,UAAI,WAAW,IAAK,QAAO;AAAA,IAC7B;AAEA,WAAO;AAAA,EACT;AACF;",
|
|
6
|
+
"names": ["newDepth"]
|
|
7
7
|
}
|
|
@@ -6,17 +6,6 @@ import { v4 as uuidv4 } from "uuid";
|
|
|
6
6
|
import * as fs from "fs/promises";
|
|
7
7
|
import * as path from "path";
|
|
8
8
|
import { sessionManager } from "../session/session-manager.js";
|
|
9
|
-
function getEnv(key, defaultValue) {
|
|
10
|
-
const value = process.env[key];
|
|
11
|
-
if (value === void 0) {
|
|
12
|
-
if (defaultValue !== void 0) return defaultValue;
|
|
13
|
-
throw new Error(`Environment variable ${key} is required`);
|
|
14
|
-
}
|
|
15
|
-
return value;
|
|
16
|
-
}
|
|
17
|
-
function getOptionalEnv(key) {
|
|
18
|
-
return process.env[key];
|
|
19
|
-
}
|
|
20
9
|
class SharedContextLayer {
|
|
21
10
|
static instance;
|
|
22
11
|
contextDir;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/core/context/shared-context-layer.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Shared Context Layer for Cross-Session Reference\n *\n * This layer maintains a lightweight shared context across sessions while\n * preserving run_id isolation for write operations. It enables:\n * - Read access to frames from other sessions\n * - Automatic context inheritance\n * - Efficient caching and indexing\n * - Safe concurrent access\n */\n\nimport { v4 as uuidv4 } from 'uuid';\nimport * as fs from 'fs/promises';\nimport * as path from 'path';\nimport { logger } from '../monitoring/logger.js';\nimport { sessionManager } from '../session/session-manager.js';\nimport type { Frame } from '../frame-manager/frame-manager.js';\n// Type-safe environment variable access\nfunction getEnv(key: string, defaultValue?: string): string {\n const value = process.env[key];\n if (value === undefined) {\n if (defaultValue !== undefined) return defaultValue;\n throw new Error(`Environment variable ${key} is required`);\n }\n return value;\n}\n\nfunction getOptionalEnv(key: string): string | undefined {\n return process.env[key];\n}\n\nexport interface SharedContext {\n projectId: string;\n branch?: string;\n lastUpdated: number;\n sessions: SharedSessionContext[];\n globalPatterns: ContextPattern[];\n decisionLog: Decision[];\n referenceIndex: ReferenceIndex;\n}\n\nexport interface SharedSessionContext {\n sessionId: string;\n runId: string;\n summary: string;\n keyFrames: FrameSummary[];\n createdAt: number;\n lastActiveAt: number;\n metadata: Record<string, any>;\n}\n\nexport interface FrameSummary {\n frameId: string;\n title: string;\n type: string;\n score: number;\n tags: string[];\n summary?: string;\n createdAt: number;\n}\n\nexport interface ContextPattern {\n pattern: string;\n type: 'error' | 'success' | 'decision' | 'learning';\n frequency: number;\n lastSeen: number;\n resolution?: string;\n}\n\nexport interface Decision {\n id: string;\n decision: string;\n reasoning: string;\n timestamp: number;\n sessionId: string;\n outcome?: 'success' | 'failure' | 'pending';\n}\n\nexport interface ReferenceIndex {\n byTag: Map<string, string[]>;\n byType: Map<string, string[]>;\n byScore: string[];\n recentlyAccessed: string[];\n}\n\nexport class SharedContextLayer {\n private static instance: SharedContextLayer;\n private contextDir: string;\n private cache: Map<string, SharedContext> = new Map();\n private readonly MAX_CACHE_SIZE = 100;\n private readonly CACHE_TTL = 5 * 60 * 1000; // 5 minutes\n private lastCacheClean = Date.now();\n\n private constructor() {\n const homeDir = process.env['HOME'] || process.env['USERPROFILE'] || '';\n this.contextDir = path.join(homeDir, '.stackmemory', 'shared-context');\n }\n\n static getInstance(): SharedContextLayer {\n if (!SharedContextLayer.instance) {\n SharedContextLayer.instance = new SharedContextLayer();\n }\n return SharedContextLayer.instance;\n }\n\n async initialize(): Promise<void> {\n await fs.mkdir(this.contextDir, { recursive: true });\n await fs.mkdir(path.join(this.contextDir, 'projects'), { recursive: true });\n await fs.mkdir(path.join(this.contextDir, 'patterns'), { recursive: true });\n await fs.mkdir(path.join(this.contextDir, 'decisions'), {\n recursive: true,\n });\n }\n\n /**\n * Get or create shared context for current project/branch\n */\n async getSharedContext(options?: {\n projectId?: string;\n branch?: string;\n includeOtherBranches?: boolean;\n }): Promise<SharedContext> {\n const session = sessionManager.getCurrentSession();\n const projectId = options?.projectId || session?.projectId || 'global';\n const branch = options?.branch || session?.branch;\n\n const cacheKey = `${projectId}:${branch || 'main'}`;\n\n // Check cache first\n if (this.cache.has(cacheKey)) {\n const cached = this.cache.get(cacheKey)!;\n if (Date.now() - cached.lastUpdated < this.CACHE_TTL) {\n return cached;\n }\n }\n\n // Load from disk\n const context = await this.loadProjectContext(projectId, branch);\n\n // Include other branches if requested\n if (options?.includeOtherBranches) {\n const otherBranches = await this.loadOtherBranchContexts(\n projectId,\n branch\n );\n context.sessions.push(...otherBranches);\n }\n\n // Update cache\n this.cache.set(cacheKey, context);\n this.cleanCache();\n\n return context;\n }\n\n /**\n * Add current session's important frames to shared context\n */\n async addToSharedContext(\n frames: Frame[],\n options?: {\n minScore?: number;\n tags?: string[];\n }\n ): Promise<void> {\n const session = sessionManager.getCurrentSession();\n if (!session) return;\n\n const context = await this.getSharedContext();\n const minScore = options?.minScore || 0.7;\n\n // Filter important frames\n const importantFrames = frames.filter((f) => {\n const score = this.calculateFrameScore(f);\n return score >= minScore;\n });\n\n // Create session context\n const sessionContext: SharedSessionContext = {\n sessionId: session.sessionId,\n runId: session.runId,\n summary: this.generateSessionSummary(importantFrames),\n keyFrames: importantFrames.map((f) => this.summarizeFrame(f)),\n createdAt: session.startedAt,\n lastActiveAt: Date.now(),\n metadata: session.metadata,\n };\n\n // Update or add session context\n const existingIndex = context.sessions.findIndex(\n (s) => s.sessionId === session.sessionId\n );\n if (existingIndex >= 0) {\n context.sessions[existingIndex] = sessionContext;\n } else {\n context.sessions.push(sessionContext);\n }\n\n // Update patterns\n this.updatePatterns(context, importantFrames);\n\n // Update reference index\n this.updateReferenceIndex(context, importantFrames);\n\n // Save context\n await this.saveProjectContext(context);\n }\n\n /**\n * Query shared context for relevant frames\n */\n async querySharedContext(query: {\n tags?: string[];\n type?: string;\n minScore?: number;\n sessionId?: string;\n limit?: number;\n }): Promise<FrameSummary[]> {\n const context = await this.getSharedContext({ includeOtherBranches: true });\n let results: FrameSummary[] = [];\n\n // Collect all frames from all sessions\n for (const session of context.sessions) {\n if (query.sessionId && session.sessionId !== query.sessionId) continue;\n\n // Skip sessions without keyFrames\n if (!session.keyFrames || !Array.isArray(session.keyFrames)) continue;\n\n const filtered = session.keyFrames.filter((f) => {\n if (query.tags && !query.tags.some((tag) => f.tags.includes(tag)))\n return false;\n if (query.type && f.type !== query.type) return false;\n if (query.minScore && f.score < query.minScore) return false;\n return true;\n });\n\n results.push(...filtered);\n }\n\n // Sort by score and recency\n results.sort((a, b) => {\n const scoreWeight = 0.7;\n const recencyWeight = 0.3;\n\n const aScore =\n a.score * scoreWeight +\n (1 - (Date.now() - a.createdAt) / (30 * 24 * 60 * 60 * 1000)) *\n recencyWeight;\n const bScore =\n b.score * scoreWeight +\n (1 - (Date.now() - b.createdAt) / (30 * 24 * 60 * 60 * 1000)) *\n recencyWeight;\n\n return bScore - aScore;\n });\n\n // Apply limit\n if (query.limit) {\n results = results.slice(0, query.limit);\n }\n\n // Update recently accessed\n const index = context.referenceIndex;\n if (!index.recentlyAccessed) {\n index.recentlyAccessed = [];\n }\n\n // Add frameIds to recently accessed, removing duplicates\n if (results.length > 0) {\n const frameIds = results.map((r) => r.frameId);\n index.recentlyAccessed = [\n ...frameIds,\n ...index.recentlyAccessed.filter((id: any) => !frameIds.includes(id)),\n ].slice(0, 100);\n\n // Save the updated context with recently accessed frames\n await this.saveProjectContext(context);\n }\n\n return results;\n }\n\n /**\n * Get relevant patterns from shared context\n */\n async getPatterns(type?: ContextPattern['type']): Promise<ContextPattern[]> {\n const context = await this.getSharedContext();\n\n if (type) {\n return context.globalPatterns.filter((p) => p.type === type);\n }\n\n return context.globalPatterns;\n }\n\n /**\n * Add a decision to the shared context\n */\n async addDecision(\n decision: Omit<Decision, 'id' | 'timestamp' | 'sessionId'>\n ): Promise<void> {\n const session = sessionManager.getCurrentSession();\n if (!session) return;\n\n const context = await this.getSharedContext();\n\n const newDecision: Decision = {\n id: uuidv4(),\n timestamp: Date.now(),\n sessionId: session.sessionId,\n outcome: 'pending',\n ...decision,\n };\n\n context.decisionLog.push(newDecision);\n\n // Keep only last 100 decisions\n if (context.decisionLog.length > 100) {\n context.decisionLog = context.decisionLog.slice(-100);\n }\n\n await this.saveProjectContext(context);\n }\n\n /**\n * Get recent decisions from shared context\n */\n async getDecisions(limit: number = 10): Promise<Decision[]> {\n const context = await this.getSharedContext();\n return context.decisionLog.slice(-limit);\n }\n\n /**\n * Automatic context discovery on CLI startup\n */\n async autoDiscoverContext(): Promise<{\n hasSharedContext: boolean;\n sessionCount: number;\n recentPatterns: ContextPattern[];\n lastDecisions: Decision[];\n suggestedFrames: FrameSummary[];\n }> {\n const context = await this.getSharedContext({\n includeOtherBranches: false,\n });\n\n // Get recent patterns (last 7 days)\n const recentPatterns = context.globalPatterns\n .filter((p) => Date.now() - p.lastSeen < 7 * 24 * 60 * 60 * 1000)\n .sort((a, b) => b.frequency - a.frequency)\n .slice(0, 5);\n\n // Get last 5 decisions\n const lastDecisions = context.decisionLog.slice(-5);\n\n // Get suggested frames based on recent access and score\n const suggestedFrames = await this.querySharedContext({\n minScore: 0.8,\n limit: 5,\n });\n\n return {\n hasSharedContext: context.sessions.length > 0,\n sessionCount: context.sessions.length,\n recentPatterns,\n lastDecisions,\n suggestedFrames,\n };\n }\n\n private async loadProjectContext(\n projectId: string,\n branch?: string\n ): Promise<SharedContext> {\n const contextFile = path.join(\n this.contextDir,\n 'projects',\n `${projectId}_${branch || 'main'}.json`\n );\n\n try {\n const data = await fs.readFile(contextFile, 'utf-8');\n const context = JSON.parse(data);\n\n // Reconstruct Maps\n context.referenceIndex.byTag = new Map(\n Object.entries(context.referenceIndex.byTag || {})\n );\n context.referenceIndex.byType = new Map(\n Object.entries(context.referenceIndex.byType || {})\n );\n\n return context;\n } catch {\n // Return empty context if file doesn't exist\n return {\n projectId,\n branch,\n lastUpdated: Date.now(),\n sessions: [],\n globalPatterns: [],\n decisionLog: [],\n referenceIndex: {\n byTag: new Map(),\n byType: new Map(),\n byScore: [],\n recentlyAccessed: [],\n },\n };\n }\n }\n\n private async saveProjectContext(context: SharedContext): Promise<void> {\n const contextFile = path.join(\n this.contextDir,\n 'projects',\n `${context.projectId}_${context.branch || 'main'}.json`\n );\n\n // Convert Maps to objects for JSON serialization\n const serializable = {\n ...context,\n lastUpdated: Date.now(),\n referenceIndex: {\n ...context.referenceIndex,\n byTag: Object.fromEntries(context.referenceIndex.byTag),\n byType: Object.fromEntries(context.referenceIndex.byType),\n },\n };\n\n await fs.writeFile(contextFile, JSON.stringify(serializable, null, 2));\n }\n\n private async loadOtherBranchContexts(\n projectId: string,\n currentBranch?: string\n ): Promise<SharedSessionContext[]> {\n const projectsDir = path.join(this.contextDir, 'projects');\n const files = await fs.readdir(projectsDir);\n const sessions: SharedSessionContext[] = [];\n\n for (const file of files) {\n if (\n file.startsWith(`${projectId}_`) &&\n !file.includes(currentBranch || 'main')\n ) {\n try {\n const data = await fs.readFile(path.join(projectsDir, file), 'utf-8');\n const context = JSON.parse(data);\n sessions.push(...context.sessions);\n } catch {\n // Skip invalid files\n }\n }\n }\n\n return sessions;\n }\n\n private calculateFrameScore(frame: Frame): number {\n // Simple scoring algorithm\n let score = 0.5;\n\n // Boost for certain types\n if (frame.type === 'task' || frame.type === 'review') score += 0.2;\n if (frame.type === 'debug' || frame.type === 'write') score += 0.15;\n if (frame.type === 'error') score += 0.15; // Error frames are important for pattern extraction\n\n // Check for data property (used in tests)\n const frameWithData = frame as any;\n if (frameWithData.data) score += 0.2;\n\n // Boost for having outputs (indicates completion/results)\n if (frame.outputs && Object.keys(frame.outputs).length > 0) score += 0.2;\n if (\n frame.digest_text ||\n (frame.digest_json && Object.keys(frame.digest_json).length > 0)\n )\n score += 0.1;\n\n // Time decay (reduce score for older frames) - but handle missing created_at\n if (frame.created_at) {\n const age = Date.now() - frame.created_at;\n const daysSinceCreation = age / (24 * 60 * 60 * 1000);\n score *= Math.max(0.3, 1 - daysSinceCreation / 30);\n }\n\n return Math.min(1, score);\n }\n\n private summarizeFrame(frame: Frame): FrameSummary {\n return {\n frameId: frame.frame_id,\n title: frame.name,\n type: frame.type,\n score: this.calculateFrameScore(frame),\n tags: [],\n summary: this.generateFrameSummary(frame),\n createdAt: frame.created_at,\n };\n }\n\n private generateFrameSummary(frame: Frame): string {\n // Generate a brief summary of the frame\n const parts = [];\n const frameWithData = frame as any;\n\n if (frame.type) parts.push(`[${frame.type}]`);\n if (frame.name) parts.push(frame.name);\n if (frameWithData.title) parts.push(frameWithData.title);\n if (frameWithData.data?.error)\n parts.push(`Error: ${frameWithData.data.error}`);\n if (frameWithData.data?.resolution)\n parts.push(`Resolution: ${frameWithData.data.resolution}`);\n\n return parts.join(' - ').slice(0, 200);\n }\n\n private generateSessionSummary(frames: Frame[]): string {\n const types = [...new Set(frames.map((f) => f.type))];\n return `Session with ${frames.length} key frames: ${types.join(', ')}`;\n }\n\n private updatePatterns(context: SharedContext, frames: Frame[]): void {\n for (const frame of frames) {\n // Extract patterns from frame data\n // Handle frames with a data property (used in tests)\n const frameWithData = frame as any;\n if (frameWithData.data?.error) {\n this.addPattern(\n context,\n frameWithData.data.error,\n 'error',\n frameWithData.data?.resolution\n );\n } else if (frame.type === 'error' && frame.name) {\n // Only extract from name/outputs if no data.error property\n const errorText = frame.outputs?.error || frame.name;\n const resolution = frame.outputs?.resolution;\n if (errorText) {\n this.addPattern(context, errorText, 'error', resolution);\n }\n }\n\n if (frame.type === 'decision' && frameWithData.data?.decision) {\n this.addPattern(context, frameWithData.data.decision, 'decision');\n } else if (frame.digest_json?.decision) {\n // Only extract from digest_json if no data.decision\n this.addPattern(context, frame.digest_json.decision, 'decision');\n }\n }\n }\n\n private addPattern(\n context: SharedContext,\n pattern: string,\n type: ContextPattern['type'],\n resolution?: string\n ): void {\n const existing = context.globalPatterns.find(\n (p) => p.pattern === pattern && p.type === type\n );\n\n if (existing) {\n existing.frequency++;\n existing.lastSeen = Date.now();\n if (resolution) existing.resolution = resolution;\n } else {\n context.globalPatterns.push({\n pattern,\n type,\n frequency: 1,\n lastSeen: Date.now(),\n resolution,\n });\n }\n\n // Keep only top 100 patterns\n if (context.globalPatterns.length > 100) {\n context.globalPatterns.sort((a, b) => b.frequency - a.frequency);\n context.globalPatterns = context.globalPatterns.slice(0, 100);\n }\n }\n\n private updateReferenceIndex(context: SharedContext, frames: Frame[]): void {\n for (const frame of frames) {\n const summary = this.summarizeFrame(frame);\n\n // Index by tags\n for (const tag of summary.tags) {\n if (!context.referenceIndex.byTag.has(tag)) {\n context.referenceIndex.byTag.set(tag, []);\n }\n context.referenceIndex.byTag.get(tag)!.push(frame.frameId);\n }\n\n // Index by type\n if (!context.referenceIndex.byType.has(frame.type)) {\n context.referenceIndex.byType.set(frame.type, []);\n }\n context.referenceIndex.byType.get(frame.type)!.push(frame.frameId);\n\n // Update score index\n const scoreIndex = context.referenceIndex.byScore;\n const insertIndex = scoreIndex.findIndex((id) => {\n const otherFrame = context.sessions\n .flatMap((s) => s.keyFrames)\n .find((f) => f.frameId === id);\n return otherFrame && otherFrame.score < summary.score;\n });\n\n if (insertIndex >= 0) {\n scoreIndex.splice(insertIndex, 0, frame.frameId);\n } else {\n scoreIndex.push(frame.frameId);\n }\n\n // Keep only top 1000 by score\n context.referenceIndex.byScore = scoreIndex.slice(0, 1000);\n }\n }\n\n private cleanCache(): void {\n if (Date.now() - this.lastCacheClean < 60000) return; // Clean every minute\n\n if (this.cache.size > this.MAX_CACHE_SIZE) {\n const entries = Array.from(this.cache.entries()).sort(\n (a, b) => b[1].lastUpdated - a[1].lastUpdated\n );\n\n this.cache = new Map(entries.slice(0, this.MAX_CACHE_SIZE / 2));\n }\n\n this.lastCacheClean = Date.now();\n }\n}\n\nexport const sharedContextLayer = SharedContextLayer.getInstance();\n\n// Export for testing\nexport {\n SharedContext,\n SharedSessionContext,\n FrameSummary,\n ContextPattern,\n Decision,\n ReferenceIndex,\n};\n"],
|
|
5
|
-
"mappings": ";;;;AAWA,SAAS,MAAM,cAAc;AAC7B,YAAY,QAAQ;AACpB,YAAY,UAAU;
|
|
4
|
+
"sourcesContent": ["/**\n * Shared Context Layer for Cross-Session Reference\n *\n * This layer maintains a lightweight shared context across sessions while\n * preserving run_id isolation for write operations. It enables:\n * - Read access to frames from other sessions\n * - Automatic context inheritance\n * - Efficient caching and indexing\n * - Safe concurrent access\n */\n\nimport { v4 as uuidv4 } from 'uuid';\nimport * as fs from 'fs/promises';\nimport * as path from 'path';\nimport { sessionManager } from '../session/session-manager.js';\nimport type { Frame } from './frame-types.js';\n\n// Type-safe environment variable access\n\nexport interface SharedContext {\n projectId: string;\n branch?: string;\n lastUpdated: number;\n sessions: SharedSessionContext[];\n globalPatterns: ContextPattern[];\n decisionLog: Decision[];\n referenceIndex: ReferenceIndex;\n}\n\nexport interface SharedSessionContext {\n sessionId: string;\n runId: string;\n summary: string;\n keyFrames: FrameSummary[];\n createdAt: number;\n lastActiveAt: number;\n metadata: Record<string, any>;\n}\n\nexport interface FrameSummary {\n frameId: string;\n title: string;\n type: string;\n score: number;\n tags: string[];\n summary?: string;\n createdAt: number;\n}\n\nexport interface ContextPattern {\n pattern: string;\n type: 'error' | 'success' | 'decision' | 'learning';\n frequency: number;\n lastSeen: number;\n resolution?: string;\n}\n\nexport interface Decision {\n id: string;\n decision: string;\n reasoning: string;\n timestamp: number;\n sessionId: string;\n outcome?: 'success' | 'failure' | 'pending';\n}\n\nexport interface ReferenceIndex {\n byTag: Map<string, string[]>;\n byType: Map<string, string[]>;\n byScore: string[];\n recentlyAccessed: string[];\n}\n\nexport class SharedContextLayer {\n private static instance: SharedContextLayer;\n private contextDir: string;\n private cache: Map<string, SharedContext> = new Map();\n private readonly MAX_CACHE_SIZE = 100;\n private readonly CACHE_TTL = 5 * 60 * 1000; // 5 minutes\n private lastCacheClean = Date.now();\n\n private constructor() {\n const homeDir = process.env['HOME'] || process.env['USERPROFILE'] || '';\n this.contextDir = path.join(homeDir, '.stackmemory', 'shared-context');\n }\n\n static getInstance(): SharedContextLayer {\n if (!SharedContextLayer.instance) {\n SharedContextLayer.instance = new SharedContextLayer();\n }\n return SharedContextLayer.instance;\n }\n\n async initialize(): Promise<void> {\n await fs.mkdir(this.contextDir, { recursive: true });\n await fs.mkdir(path.join(this.contextDir, 'projects'), { recursive: true });\n await fs.mkdir(path.join(this.contextDir, 'patterns'), { recursive: true });\n await fs.mkdir(path.join(this.contextDir, 'decisions'), {\n recursive: true,\n });\n }\n\n /**\n * Get or create shared context for current project/branch\n */\n async getSharedContext(options?: {\n projectId?: string;\n branch?: string;\n includeOtherBranches?: boolean;\n }): Promise<SharedContext> {\n const session = sessionManager.getCurrentSession();\n const projectId = options?.projectId || session?.projectId || 'global';\n const branch = options?.branch || session?.branch;\n\n const cacheKey = `${projectId}:${branch || 'main'}`;\n\n // Check cache first\n if (this.cache.has(cacheKey)) {\n const cached = this.cache.get(cacheKey)!;\n if (Date.now() - cached.lastUpdated < this.CACHE_TTL) {\n return cached;\n }\n }\n\n // Load from disk\n const context = await this.loadProjectContext(projectId, branch);\n\n // Include other branches if requested\n if (options?.includeOtherBranches) {\n const otherBranches = await this.loadOtherBranchContexts(\n projectId,\n branch\n );\n context.sessions.push(...otherBranches);\n }\n\n // Update cache\n this.cache.set(cacheKey, context);\n this.cleanCache();\n\n return context;\n }\n\n /**\n * Add current session's important frames to shared context\n */\n async addToSharedContext(\n frames: Frame[],\n options?: {\n minScore?: number;\n tags?: string[];\n }\n ): Promise<void> {\n const session = sessionManager.getCurrentSession();\n if (!session) return;\n\n const context = await this.getSharedContext();\n const minScore = options?.minScore || 0.7;\n\n // Filter important frames\n const importantFrames = frames.filter((f) => {\n const score = this.calculateFrameScore(f);\n return score >= minScore;\n });\n\n // Create session context\n const sessionContext: SharedSessionContext = {\n sessionId: session.sessionId,\n runId: session.runId,\n summary: this.generateSessionSummary(importantFrames),\n keyFrames: importantFrames.map((f) => this.summarizeFrame(f)),\n createdAt: session.startedAt,\n lastActiveAt: Date.now(),\n metadata: session.metadata,\n };\n\n // Update or add session context\n const existingIndex = context.sessions.findIndex(\n (s) => s.sessionId === session.sessionId\n );\n if (existingIndex >= 0) {\n context.sessions[existingIndex] = sessionContext;\n } else {\n context.sessions.push(sessionContext);\n }\n\n // Update patterns\n this.updatePatterns(context, importantFrames);\n\n // Update reference index\n this.updateReferenceIndex(context, importantFrames);\n\n // Save context\n await this.saveProjectContext(context);\n }\n\n /**\n * Query shared context for relevant frames\n */\n async querySharedContext(query: {\n tags?: string[];\n type?: string;\n minScore?: number;\n sessionId?: string;\n limit?: number;\n }): Promise<FrameSummary[]> {\n const context = await this.getSharedContext({ includeOtherBranches: true });\n let results: FrameSummary[] = [];\n\n // Collect all frames from all sessions\n for (const session of context.sessions) {\n if (query.sessionId && session.sessionId !== query.sessionId) continue;\n\n // Skip sessions without keyFrames\n if (!session.keyFrames || !Array.isArray(session.keyFrames)) continue;\n\n const filtered = session.keyFrames.filter((f) => {\n if (query.tags && !query.tags.some((tag) => f.tags.includes(tag)))\n return false;\n if (query.type && f.type !== query.type) return false;\n if (query.minScore && f.score < query.minScore) return false;\n return true;\n });\n\n results.push(...filtered);\n }\n\n // Sort by score and recency\n results.sort((a, b) => {\n const scoreWeight = 0.7;\n const recencyWeight = 0.3;\n\n const aScore =\n a.score * scoreWeight +\n (1 - (Date.now() - a.createdAt) / (30 * 24 * 60 * 60 * 1000)) *\n recencyWeight;\n const bScore =\n b.score * scoreWeight +\n (1 - (Date.now() - b.createdAt) / (30 * 24 * 60 * 60 * 1000)) *\n recencyWeight;\n\n return bScore - aScore;\n });\n\n // Apply limit\n if (query.limit) {\n results = results.slice(0, query.limit);\n }\n\n // Update recently accessed\n const index = context.referenceIndex;\n if (!index.recentlyAccessed) {\n index.recentlyAccessed = [];\n }\n\n // Add frameIds to recently accessed, removing duplicates\n if (results.length > 0) {\n const frameIds = results.map((r) => r.frameId);\n index.recentlyAccessed = [\n ...frameIds,\n ...index.recentlyAccessed.filter((id: any) => !frameIds.includes(id)),\n ].slice(0, 100);\n\n // Save the updated context with recently accessed frames\n await this.saveProjectContext(context);\n }\n\n return results;\n }\n\n /**\n * Get relevant patterns from shared context\n */\n async getPatterns(type?: ContextPattern['type']): Promise<ContextPattern[]> {\n const context = await this.getSharedContext();\n\n if (type) {\n return context.globalPatterns.filter((p) => p.type === type);\n }\n\n return context.globalPatterns;\n }\n\n /**\n * Add a decision to the shared context\n */\n async addDecision(\n decision: Omit<Decision, 'id' | 'timestamp' | 'sessionId'>\n ): Promise<void> {\n const session = sessionManager.getCurrentSession();\n if (!session) return;\n\n const context = await this.getSharedContext();\n\n const newDecision: Decision = {\n id: uuidv4(),\n timestamp: Date.now(),\n sessionId: session.sessionId,\n outcome: 'pending',\n ...decision,\n };\n\n context.decisionLog.push(newDecision);\n\n // Keep only last 100 decisions\n if (context.decisionLog.length > 100) {\n context.decisionLog = context.decisionLog.slice(-100);\n }\n\n await this.saveProjectContext(context);\n }\n\n /**\n * Get recent decisions from shared context\n */\n async getDecisions(limit: number = 10): Promise<Decision[]> {\n const context = await this.getSharedContext();\n return context.decisionLog.slice(-limit);\n }\n\n /**\n * Automatic context discovery on CLI startup\n */\n async autoDiscoverContext(): Promise<{\n hasSharedContext: boolean;\n sessionCount: number;\n recentPatterns: ContextPattern[];\n lastDecisions: Decision[];\n suggestedFrames: FrameSummary[];\n }> {\n const context = await this.getSharedContext({\n includeOtherBranches: false,\n });\n\n // Get recent patterns (last 7 days)\n const recentPatterns = context.globalPatterns\n .filter((p) => Date.now() - p.lastSeen < 7 * 24 * 60 * 60 * 1000)\n .sort((a, b) => b.frequency - a.frequency)\n .slice(0, 5);\n\n // Get last 5 decisions\n const lastDecisions = context.decisionLog.slice(-5);\n\n // Get suggested frames based on recent access and score\n const suggestedFrames = await this.querySharedContext({\n minScore: 0.8,\n limit: 5,\n });\n\n return {\n hasSharedContext: context.sessions.length > 0,\n sessionCount: context.sessions.length,\n recentPatterns,\n lastDecisions,\n suggestedFrames,\n };\n }\n\n private async loadProjectContext(\n projectId: string,\n branch?: string\n ): Promise<SharedContext> {\n const contextFile = path.join(\n this.contextDir,\n 'projects',\n `${projectId}_${branch || 'main'}.json`\n );\n\n try {\n const data = await fs.readFile(contextFile, 'utf-8');\n const context = JSON.parse(data);\n\n // Reconstruct Maps\n context.referenceIndex.byTag = new Map(\n Object.entries(context.referenceIndex.byTag || {})\n );\n context.referenceIndex.byType = new Map(\n Object.entries(context.referenceIndex.byType || {})\n );\n\n return context;\n } catch {\n // Return empty context if file doesn't exist\n return {\n projectId,\n branch,\n lastUpdated: Date.now(),\n sessions: [],\n globalPatterns: [],\n decisionLog: [],\n referenceIndex: {\n byTag: new Map(),\n byType: new Map(),\n byScore: [],\n recentlyAccessed: [],\n },\n };\n }\n }\n\n private async saveProjectContext(context: SharedContext): Promise<void> {\n const contextFile = path.join(\n this.contextDir,\n 'projects',\n `${context.projectId}_${context.branch || 'main'}.json`\n );\n\n // Convert Maps to objects for JSON serialization\n const serializable = {\n ...context,\n lastUpdated: Date.now(),\n referenceIndex: {\n ...context.referenceIndex,\n byTag: Object.fromEntries(context.referenceIndex.byTag),\n byType: Object.fromEntries(context.referenceIndex.byType),\n },\n };\n\n await fs.writeFile(contextFile, JSON.stringify(serializable, null, 2));\n }\n\n private async loadOtherBranchContexts(\n projectId: string,\n currentBranch?: string\n ): Promise<SharedSessionContext[]> {\n const projectsDir = path.join(this.contextDir, 'projects');\n const files = await fs.readdir(projectsDir);\n const sessions: SharedSessionContext[] = [];\n\n for (const file of files) {\n if (\n file.startsWith(`${projectId}_`) &&\n !file.includes(currentBranch || 'main')\n ) {\n try {\n const data = await fs.readFile(path.join(projectsDir, file), 'utf-8');\n const context = JSON.parse(data);\n sessions.push(...context.sessions);\n } catch {\n // Skip invalid files\n }\n }\n }\n\n return sessions;\n }\n\n private calculateFrameScore(frame: Frame): number {\n // Simple scoring algorithm\n let score = 0.5;\n\n // Boost for certain types\n if (frame.type === 'task' || frame.type === 'review') score += 0.2;\n if (frame.type === 'debug' || frame.type === 'write') score += 0.15;\n if (frame.type === 'error') score += 0.15; // Error frames are important for pattern extraction\n\n // Check for data property (used in tests)\n const frameWithData = frame as any;\n if (frameWithData.data) score += 0.2;\n\n // Boost for having outputs (indicates completion/results)\n if (frame.outputs && Object.keys(frame.outputs).length > 0) score += 0.2;\n if (\n frame.digest_text ||\n (frame.digest_json && Object.keys(frame.digest_json).length > 0)\n )\n score += 0.1;\n\n // Time decay (reduce score for older frames) - but handle missing created_at\n if (frame.created_at) {\n const age = Date.now() - frame.created_at;\n const daysSinceCreation = age / (24 * 60 * 60 * 1000);\n score *= Math.max(0.3, 1 - daysSinceCreation / 30);\n }\n\n return Math.min(1, score);\n }\n\n private summarizeFrame(frame: Frame): FrameSummary {\n return {\n frameId: frame.frame_id,\n title: frame.name,\n type: frame.type,\n score: this.calculateFrameScore(frame),\n tags: [],\n summary: this.generateFrameSummary(frame),\n createdAt: frame.created_at,\n };\n }\n\n private generateFrameSummary(frame: Frame): string {\n // Generate a brief summary of the frame\n const parts = [];\n const frameWithData = frame as any;\n\n if (frame.type) parts.push(`[${frame.type}]`);\n if (frame.name) parts.push(frame.name);\n if (frameWithData.title) parts.push(frameWithData.title);\n if (frameWithData.data?.error)\n parts.push(`Error: ${frameWithData.data.error}`);\n if (frameWithData.data?.resolution)\n parts.push(`Resolution: ${frameWithData.data.resolution}`);\n\n return parts.join(' - ').slice(0, 200);\n }\n\n private generateSessionSummary(frames: Frame[]): string {\n const types = [...new Set(frames.map((f) => f.type))];\n return `Session with ${frames.length} key frames: ${types.join(', ')}`;\n }\n\n private updatePatterns(context: SharedContext, frames: Frame[]): void {\n for (const frame of frames) {\n // Extract patterns from frame data\n // Handle frames with a data property (used in tests)\n const frameWithData = frame as any;\n if (frameWithData.data?.error) {\n this.addPattern(\n context,\n frameWithData.data.error,\n 'error',\n frameWithData.data?.resolution\n );\n } else if (frame.type === 'error' && frame.name) {\n // Only extract from name/outputs if no data.error property\n const errorText = frame.outputs?.error || frame.name;\n const resolution = frame.outputs?.resolution;\n if (errorText) {\n this.addPattern(context, errorText, 'error', resolution);\n }\n }\n\n if (frame.type === 'decision' && frameWithData.data?.decision) {\n this.addPattern(context, frameWithData.data.decision, 'decision');\n } else if (frame.digest_json?.decision) {\n // Only extract from digest_json if no data.decision\n this.addPattern(context, frame.digest_json.decision, 'decision');\n }\n }\n }\n\n private addPattern(\n context: SharedContext,\n pattern: string,\n type: ContextPattern['type'],\n resolution?: string\n ): void {\n const existing = context.globalPatterns.find(\n (p) => p.pattern === pattern && p.type === type\n );\n\n if (existing) {\n existing.frequency++;\n existing.lastSeen = Date.now();\n if (resolution) existing.resolution = resolution;\n } else {\n context.globalPatterns.push({\n pattern,\n type,\n frequency: 1,\n lastSeen: Date.now(),\n resolution,\n });\n }\n\n // Keep only top 100 patterns\n if (context.globalPatterns.length > 100) {\n context.globalPatterns.sort((a, b) => b.frequency - a.frequency);\n context.globalPatterns = context.globalPatterns.slice(0, 100);\n }\n }\n\n private updateReferenceIndex(context: SharedContext, frames: Frame[]): void {\n for (const frame of frames) {\n const summary = this.summarizeFrame(frame);\n\n // Index by tags\n for (const tag of summary.tags) {\n if (!context.referenceIndex.byTag.has(tag)) {\n context.referenceIndex.byTag.set(tag, []);\n }\n context.referenceIndex.byTag.get(tag)!.push(frame.frameId);\n }\n\n // Index by type\n if (!context.referenceIndex.byType.has(frame.type)) {\n context.referenceIndex.byType.set(frame.type, []);\n }\n context.referenceIndex.byType.get(frame.type)!.push(frame.frameId);\n\n // Update score index\n const scoreIndex = context.referenceIndex.byScore;\n const insertIndex = scoreIndex.findIndex((id) => {\n const otherFrame = context.sessions\n .flatMap((s) => s.keyFrames)\n .find((f) => f.frameId === id);\n return otherFrame && otherFrame.score < summary.score;\n });\n\n if (insertIndex >= 0) {\n scoreIndex.splice(insertIndex, 0, frame.frameId);\n } else {\n scoreIndex.push(frame.frameId);\n }\n\n // Keep only top 1000 by score\n context.referenceIndex.byScore = scoreIndex.slice(0, 1000);\n }\n }\n\n private cleanCache(): void {\n if (Date.now() - this.lastCacheClean < 60000) return; // Clean every minute\n\n if (this.cache.size > this.MAX_CACHE_SIZE) {\n const entries = Array.from(this.cache.entries()).sort(\n (a, b) => b[1].lastUpdated - a[1].lastUpdated\n );\n\n this.cache = new Map(entries.slice(0, this.MAX_CACHE_SIZE / 2));\n }\n\n this.lastCacheClean = Date.now();\n }\n}\n\nexport const sharedContextLayer = SharedContextLayer.getInstance();\n\n// Export for testing\nexport {\n SharedContext,\n SharedSessionContext,\n FrameSummary,\n ContextPattern,\n Decision,\n ReferenceIndex,\n};\n"],
|
|
5
|
+
"mappings": ";;;;AAWA,SAAS,MAAM,cAAc;AAC7B,YAAY,QAAQ;AACpB,YAAY,UAAU;AACtB,SAAS,sBAAsB;AA2DxB,MAAM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