stellar-memory 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +362 -0
- package/dist/api/routes/analytics.d.ts +15 -0
- package/dist/api/routes/analytics.js +131 -0
- package/dist/api/routes/analytics.js.map +1 -0
- package/dist/api/routes/conflicts.d.ts +12 -0
- package/dist/api/routes/conflicts.js +67 -0
- package/dist/api/routes/conflicts.js.map +1 -0
- package/dist/api/routes/consolidation.d.ts +11 -0
- package/dist/api/routes/consolidation.js +63 -0
- package/dist/api/routes/consolidation.js.map +1 -0
- package/dist/api/routes/constellation.d.ts +4 -0
- package/dist/api/routes/constellation.js +84 -0
- package/dist/api/routes/constellation.js.map +1 -0
- package/dist/api/routes/memories.d.ts +4 -0
- package/dist/api/routes/memories.js +219 -0
- package/dist/api/routes/memories.js.map +1 -0
- package/dist/api/routes/observations.d.ts +10 -0
- package/dist/api/routes/observations.js +42 -0
- package/dist/api/routes/observations.js.map +1 -0
- package/dist/api/routes/orbit.d.ts +4 -0
- package/dist/api/routes/orbit.js +71 -0
- package/dist/api/routes/orbit.js.map +1 -0
- package/dist/api/routes/projects.d.ts +15 -0
- package/dist/api/routes/projects.js +121 -0
- package/dist/api/routes/projects.js.map +1 -0
- package/dist/api/routes/scan.d.ts +4 -0
- package/dist/api/routes/scan.js +403 -0
- package/dist/api/routes/scan.js.map +1 -0
- package/dist/api/routes/sun.d.ts +4 -0
- package/dist/api/routes/sun.js +43 -0
- package/dist/api/routes/sun.js.map +1 -0
- package/dist/api/routes/system.d.ts +4 -0
- package/dist/api/routes/system.js +70 -0
- package/dist/api/routes/system.js.map +1 -0
- package/dist/api/routes/temporal.d.ts +13 -0
- package/dist/api/routes/temporal.js +82 -0
- package/dist/api/routes/temporal.js.map +1 -0
- package/dist/api/server.d.ts +2 -0
- package/dist/api/server.js +99 -0
- package/dist/api/server.js.map +1 -0
- package/dist/api/websocket.d.ts +53 -0
- package/dist/api/websocket.js +168 -0
- package/dist/api/websocket.js.map +1 -0
- package/dist/cli/index.d.ts +12 -0
- package/dist/cli/index.js +35 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/init.d.ts +10 -0
- package/dist/cli/init.js +163 -0
- package/dist/cli/init.js.map +1 -0
- package/dist/engine/analytics.d.ts +93 -0
- package/dist/engine/analytics.js +437 -0
- package/dist/engine/analytics.js.map +1 -0
- package/dist/engine/conflict.d.ts +54 -0
- package/dist/engine/conflict.js +322 -0
- package/dist/engine/conflict.js.map +1 -0
- package/dist/engine/consolidation.d.ts +83 -0
- package/dist/engine/consolidation.js +368 -0
- package/dist/engine/consolidation.js.map +1 -0
- package/dist/engine/constellation.d.ts +66 -0
- package/dist/engine/constellation.js +382 -0
- package/dist/engine/constellation.js.map +1 -0
- package/dist/engine/corona.d.ts +53 -0
- package/dist/engine/corona.js +181 -0
- package/dist/engine/corona.js.map +1 -0
- package/dist/engine/embedding.d.ts +44 -0
- package/dist/engine/embedding.js +168 -0
- package/dist/engine/embedding.js.map +1 -0
- package/dist/engine/gravity.d.ts +63 -0
- package/dist/engine/gravity.js +121 -0
- package/dist/engine/gravity.js.map +1 -0
- package/dist/engine/multiproject.d.ts +75 -0
- package/dist/engine/multiproject.js +241 -0
- package/dist/engine/multiproject.js.map +1 -0
- package/dist/engine/observation.d.ts +82 -0
- package/dist/engine/observation.js +357 -0
- package/dist/engine/observation.js.map +1 -0
- package/dist/engine/orbit.d.ts +91 -0
- package/dist/engine/orbit.js +249 -0
- package/dist/engine/orbit.js.map +1 -0
- package/dist/engine/planet.d.ts +64 -0
- package/dist/engine/planet.js +432 -0
- package/dist/engine/planet.js.map +1 -0
- package/dist/engine/procedural.d.ts +71 -0
- package/dist/engine/procedural.js +259 -0
- package/dist/engine/procedural.js.map +1 -0
- package/dist/engine/quality.d.ts +48 -0
- package/dist/engine/quality.js +245 -0
- package/dist/engine/quality.js.map +1 -0
- package/dist/engine/repository.d.ts +79 -0
- package/dist/engine/repository.js +13 -0
- package/dist/engine/repository.js.map +1 -0
- package/dist/engine/sun.d.ts +61 -0
- package/dist/engine/sun.js +240 -0
- package/dist/engine/sun.js.map +1 -0
- package/dist/engine/temporal.d.ts +67 -0
- package/dist/engine/temporal.js +283 -0
- package/dist/engine/temporal.js.map +1 -0
- package/dist/engine/types.d.ts +179 -0
- package/dist/engine/types.js +27 -0
- package/dist/engine/types.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +60 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/connector-registry.d.ts +20 -0
- package/dist/mcp/connector-registry.js +35 -0
- package/dist/mcp/connector-registry.js.map +1 -0
- package/dist/mcp/server.d.ts +13 -0
- package/dist/mcp/server.js +242 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/tools/daemon-tool.d.ts +16 -0
- package/dist/mcp/tools/daemon-tool.js +58 -0
- package/dist/mcp/tools/daemon-tool.js.map +1 -0
- package/dist/mcp/tools/ingestion-tools.d.ts +20 -0
- package/dist/mcp/tools/ingestion-tools.js +34 -0
- package/dist/mcp/tools/ingestion-tools.js.map +1 -0
- package/dist/mcp/tools/memory-tools.d.ts +122 -0
- package/dist/mcp/tools/memory-tools.js +1037 -0
- package/dist/mcp/tools/memory-tools.js.map +1 -0
- package/dist/scanner/cloud/github.d.ts +34 -0
- package/dist/scanner/cloud/github.js +260 -0
- package/dist/scanner/cloud/github.js.map +1 -0
- package/dist/scanner/cloud/google-drive.d.ts +30 -0
- package/dist/scanner/cloud/google-drive.js +289 -0
- package/dist/scanner/cloud/google-drive.js.map +1 -0
- package/dist/scanner/cloud/notion.d.ts +33 -0
- package/dist/scanner/cloud/notion.js +231 -0
- package/dist/scanner/cloud/notion.js.map +1 -0
- package/dist/scanner/cloud/slack.d.ts +38 -0
- package/dist/scanner/cloud/slack.js +282 -0
- package/dist/scanner/cloud/slack.js.map +1 -0
- package/dist/scanner/cloud/types.d.ts +73 -0
- package/dist/scanner/cloud/types.js +9 -0
- package/dist/scanner/cloud/types.js.map +1 -0
- package/dist/scanner/index.d.ts +35 -0
- package/dist/scanner/index.js +420 -0
- package/dist/scanner/index.js.map +1 -0
- package/dist/scanner/local/filesystem.d.ts +33 -0
- package/dist/scanner/local/filesystem.js +203 -0
- package/dist/scanner/local/filesystem.js.map +1 -0
- package/dist/scanner/local/git.d.ts +24 -0
- package/dist/scanner/local/git.js +161 -0
- package/dist/scanner/local/git.js.map +1 -0
- package/dist/scanner/local/parsers/code.d.ts +3 -0
- package/dist/scanner/local/parsers/code.js +127 -0
- package/dist/scanner/local/parsers/code.js.map +1 -0
- package/dist/scanner/local/parsers/index.d.ts +11 -0
- package/dist/scanner/local/parsers/index.js +24 -0
- package/dist/scanner/local/parsers/index.js.map +1 -0
- package/dist/scanner/local/parsers/json-parser.d.ts +3 -0
- package/dist/scanner/local/parsers/json-parser.js +117 -0
- package/dist/scanner/local/parsers/json-parser.js.map +1 -0
- package/dist/scanner/local/parsers/markdown.d.ts +3 -0
- package/dist/scanner/local/parsers/markdown.js +120 -0
- package/dist/scanner/local/parsers/markdown.js.map +1 -0
- package/dist/scanner/local/parsers/text.d.ts +3 -0
- package/dist/scanner/local/parsers/text.js +41 -0
- package/dist/scanner/local/parsers/text.js.map +1 -0
- package/dist/scanner/metadata-scanner.d.ts +67 -0
- package/dist/scanner/metadata-scanner.js +356 -0
- package/dist/scanner/metadata-scanner.js.map +1 -0
- package/dist/scanner/types.d.ts +47 -0
- package/dist/scanner/types.js +19 -0
- package/dist/scanner/types.js.map +1 -0
- package/dist/service/daemon.d.ts +23 -0
- package/dist/service/daemon.js +105 -0
- package/dist/service/daemon.js.map +1 -0
- package/dist/service/scheduler.d.ts +73 -0
- package/dist/service/scheduler.js +281 -0
- package/dist/service/scheduler.js.map +1 -0
- package/dist/storage/database.d.ts +10 -0
- package/dist/storage/database.js +265 -0
- package/dist/storage/database.js.map +1 -0
- package/dist/storage/queries.d.ts +85 -0
- package/dist/storage/queries.js +865 -0
- package/dist/storage/queries.js.map +1 -0
- package/dist/storage/sqlite-repository.d.ts +32 -0
- package/dist/storage/sqlite-repository.js +68 -0
- package/dist/storage/sqlite-repository.js.map +1 -0
- package/dist/storage/vec.d.ts +62 -0
- package/dist/storage/vec.js +111 -0
- package/dist/storage/vec.js.map +1 -0
- package/dist/utils/config.d.ts +5 -0
- package/dist/utils/config.js +60 -0
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/logger.d.ts +36 -0
- package/dist/utils/logger.js +86 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/time.d.ts +21 -0
- package/dist/utils/time.js +42 -0
- package/dist/utils/time.js.map +1 -0
- package/dist/utils/tokenizer.d.ts +13 -0
- package/dist/utils/tokenizer.js +46 -0
- package/dist/utils/tokenizer.js.map +1 -0
- package/package.json +77 -0
- package/scripts/check-node.mjs +36 -0
- package/scripts/setup.mjs +157 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* engine/repository.ts — MemoryRepository abstraction
|
|
3
|
+
*
|
|
4
|
+
* Defines the storage contract for memories and sun state.
|
|
5
|
+
* The engine and use-case layers depend only on this interface,
|
|
6
|
+
* making the concrete storage backend swappable (SQLite today,
|
|
7
|
+
* Python v1 or a remote API tomorrow).
|
|
8
|
+
*
|
|
9
|
+
* Dependency rule: this file lives in the engine layer and MUST NOT
|
|
10
|
+
* import from storage/, infrastructure, or framework packages.
|
|
11
|
+
*/
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repository.js","sourceRoot":"","sources":["../../src/engine/repository.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* sun.ts — Sun state management
|
|
3
|
+
*
|
|
4
|
+
* The "sun" is the gravitational centre of the memory system: it holds the
|
|
5
|
+
* current working context (what the AI is doing right now). Every memory
|
|
6
|
+
* planet orbits the sun at a distance inversely proportional to its relevance
|
|
7
|
+
* to the current work.
|
|
8
|
+
*
|
|
9
|
+
* Responsibilities:
|
|
10
|
+
* - commitToSun : persist a new work snapshot and create decision memories.
|
|
11
|
+
* - getSunContent: produce the formatted MCP resource text within token budget.
|
|
12
|
+
* - formatSunContent: pure formatter used by getSunContent and tests.
|
|
13
|
+
*/
|
|
14
|
+
import type { SunState, Memory } from './types.js';
|
|
15
|
+
/**
|
|
16
|
+
* Get the current sun content formatted for an MCP resource.
|
|
17
|
+
* Guaranteed to stay under the configured sunTokenBudget.
|
|
18
|
+
*/
|
|
19
|
+
export declare function getSunContent(project: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Update the sun state from a commit.
|
|
22
|
+
*
|
|
23
|
+
* Steps:
|
|
24
|
+
* 1. Fetch or initialise sun state for the project.
|
|
25
|
+
* 2. Merge the incoming data (new fields overwrite old ones).
|
|
26
|
+
* 3. Auto-create a 'decision' memory planet for each supplied decision.
|
|
27
|
+
* 4. Count tokens and persist via upsertSunState.
|
|
28
|
+
*/
|
|
29
|
+
export declare function commitToSun(project: string, data: {
|
|
30
|
+
current_work: string;
|
|
31
|
+
decisions: string[];
|
|
32
|
+
next_steps: string[];
|
|
33
|
+
errors: string[];
|
|
34
|
+
context?: string;
|
|
35
|
+
}): void;
|
|
36
|
+
/**
|
|
37
|
+
* Format sun state into readable text for the MCP resource.
|
|
38
|
+
*
|
|
39
|
+
* Sections are added in priority order. Each section is checked against the
|
|
40
|
+
* remaining token budget before being appended (progressive truncation).
|
|
41
|
+
* This ensures the most critical context always fits regardless of budget.
|
|
42
|
+
*
|
|
43
|
+
* New priority order (Corona-aware):
|
|
44
|
+
* 1. Header
|
|
45
|
+
* 2. CORE IDENTITY — core zone memories (instant recall, ~40% budget)
|
|
46
|
+
* 3. WORKING ON (current_work, ~10%)
|
|
47
|
+
* 4. ACTIVE CONTEXT — near zone memories (~25%)
|
|
48
|
+
* 5. RECENT DECISIONS / NEXT STEPS / ACTIVE ISSUES (~25%)
|
|
49
|
+
*/
|
|
50
|
+
export declare function formatSunContent(sun: SunState, coreMemories: Memory[], nearMemories: Memory[]): string;
|
|
51
|
+
/**
|
|
52
|
+
* Automatically commit the sun state from recent memories when the
|
|
53
|
+
* MCP server process is shutting down.
|
|
54
|
+
*
|
|
55
|
+
* This prevents session context from being lost when Claude's process
|
|
56
|
+
* ends (e.g., SIGTERM from Claude Desktop, pipe close from Claude Code).
|
|
57
|
+
*
|
|
58
|
+
* Uses synchronous DB calls only — async is unsafe in exit handlers.
|
|
59
|
+
*/
|
|
60
|
+
export declare function autoCommitOnClose(project: string): void;
|
|
61
|
+
//# sourceMappingURL=sun.d.ts.map
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* sun.ts — Sun state management
|
|
3
|
+
*
|
|
4
|
+
* The "sun" is the gravitational centre of the memory system: it holds the
|
|
5
|
+
* current working context (what the AI is doing right now). Every memory
|
|
6
|
+
* planet orbits the sun at a distance inversely proportional to its relevance
|
|
7
|
+
* to the current work.
|
|
8
|
+
*
|
|
9
|
+
* Responsibilities:
|
|
10
|
+
* - commitToSun : persist a new work snapshot and create decision memories.
|
|
11
|
+
* - getSunContent: produce the formatted MCP resource text within token budget.
|
|
12
|
+
* - formatSunContent: pure formatter used by getSunContent and tests.
|
|
13
|
+
*/
|
|
14
|
+
import { getSunState, upsertSunState, getRecentMemories, } from '../storage/queries.js';
|
|
15
|
+
import { estimateTokens } from '../utils/tokenizer.js';
|
|
16
|
+
import { getConfig } from '../utils/config.js';
|
|
17
|
+
import { createMemory } from './planet.js';
|
|
18
|
+
import { corona } from './corona.js';
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
// Public API
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
/**
|
|
23
|
+
* Get the current sun content formatted for an MCP resource.
|
|
24
|
+
* Guaranteed to stay under the configured sunTokenBudget.
|
|
25
|
+
*/
|
|
26
|
+
export function getSunContent(project) {
|
|
27
|
+
const sun = getSunState(project);
|
|
28
|
+
if (!sun) {
|
|
29
|
+
return `[STELLAR MEMORY - project: ${project}]\n\nNo memories committed yet. Use stellar_commit to record your current work.`;
|
|
30
|
+
}
|
|
31
|
+
// Read from the corona in-memory cache instead of hitting the DB.
|
|
32
|
+
const coreMemories = corona.getCoreMemories();
|
|
33
|
+
const nearMemories = corona.getNearMemories();
|
|
34
|
+
return formatSunContent(sun, coreMemories, nearMemories);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Update the sun state from a commit.
|
|
38
|
+
*
|
|
39
|
+
* Steps:
|
|
40
|
+
* 1. Fetch or initialise sun state for the project.
|
|
41
|
+
* 2. Merge the incoming data (new fields overwrite old ones).
|
|
42
|
+
* 3. Auto-create a 'decision' memory planet for each supplied decision.
|
|
43
|
+
* 4. Count tokens and persist via upsertSunState.
|
|
44
|
+
*/
|
|
45
|
+
export function commitToSun(project, data) {
|
|
46
|
+
const config = getConfig();
|
|
47
|
+
// Persist each decision as its own memory planet so it enters the orbital
|
|
48
|
+
// system and can be recalled later.
|
|
49
|
+
for (const decision of data.decisions) {
|
|
50
|
+
if (decision.trim().length > 0) {
|
|
51
|
+
createMemory({
|
|
52
|
+
project,
|
|
53
|
+
content: decision,
|
|
54
|
+
type: 'decision',
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// Build the updated sun state object.
|
|
59
|
+
const now = new Date().toISOString();
|
|
60
|
+
const existing = getSunState(project);
|
|
61
|
+
const updated = {
|
|
62
|
+
project,
|
|
63
|
+
content: data.current_work,
|
|
64
|
+
current_work: data.current_work,
|
|
65
|
+
recent_decisions: data.decisions,
|
|
66
|
+
next_steps: data.next_steps,
|
|
67
|
+
active_errors: data.errors,
|
|
68
|
+
project_context: data.context ?? (existing?.project_context ?? ''),
|
|
69
|
+
token_count: 0, // computed below
|
|
70
|
+
last_commit_at: now,
|
|
71
|
+
updated_at: now,
|
|
72
|
+
};
|
|
73
|
+
// Calculate token usage for the formatted sun content so the consumer can
|
|
74
|
+
// make informed truncation decisions.
|
|
75
|
+
const coreMemories = corona.getCoreMemories();
|
|
76
|
+
const nearMemories = corona.getNearMemories();
|
|
77
|
+
const formatted = formatSunContent(updated, coreMemories, nearMemories);
|
|
78
|
+
updated.token_count = estimateTokens(formatted);
|
|
79
|
+
// Warn in dev if we exceed the budget — the consumer (getSunContent) is
|
|
80
|
+
// responsible for truncation, but we record the real count here.
|
|
81
|
+
if (updated.token_count > config.sunTokenBudget) {
|
|
82
|
+
process.stderr.write(`[sun] token count ${updated.token_count} exceeds budget ${config.sunTokenBudget} for project "${project}"\n`);
|
|
83
|
+
}
|
|
84
|
+
upsertSunState(updated);
|
|
85
|
+
}
|
|
86
|
+
// ---------------------------------------------------------------------------
|
|
87
|
+
// Formatter
|
|
88
|
+
// ---------------------------------------------------------------------------
|
|
89
|
+
/**
|
|
90
|
+
* Format sun state into readable text for the MCP resource.
|
|
91
|
+
*
|
|
92
|
+
* Sections are added in priority order. Each section is checked against the
|
|
93
|
+
* remaining token budget before being appended (progressive truncation).
|
|
94
|
+
* This ensures the most critical context always fits regardless of budget.
|
|
95
|
+
*
|
|
96
|
+
* New priority order (Corona-aware):
|
|
97
|
+
* 1. Header
|
|
98
|
+
* 2. CORE IDENTITY — core zone memories (instant recall, ~40% budget)
|
|
99
|
+
* 3. WORKING ON (current_work, ~10%)
|
|
100
|
+
* 4. ACTIVE CONTEXT — near zone memories (~25%)
|
|
101
|
+
* 5. RECENT DECISIONS / NEXT STEPS / ACTIVE ISSUES (~25%)
|
|
102
|
+
*/
|
|
103
|
+
export function formatSunContent(sun, coreMemories, nearMemories) {
|
|
104
|
+
const config = getConfig();
|
|
105
|
+
const budget = config.sunTokenBudget;
|
|
106
|
+
const MAX_CORE_DISPLAY = 5;
|
|
107
|
+
const MAX_NEAR_DISPLAY = 5;
|
|
108
|
+
const SUMMARY_LIMIT = 80;
|
|
109
|
+
/** Truncate summary to SUMMARY_LIMIT characters. */
|
|
110
|
+
const truncSummary = (s) => s.length > SUMMARY_LIMIT ? s.slice(0, SUMMARY_LIMIT).trimEnd() + '…' : s;
|
|
111
|
+
// Build candidate sections in priority order.
|
|
112
|
+
const sections = [];
|
|
113
|
+
// 1. Header — always included. Add [STALE] warning if last commit > 24h ago.
|
|
114
|
+
let header = `[STELLAR MEMORY - project: ${sun.project}]`;
|
|
115
|
+
if (sun.last_commit_at) {
|
|
116
|
+
const lastCommitMs = new Date(/[Zz]$|[+-]\d{2}:\d{2}$/.test(sun.last_commit_at)
|
|
117
|
+
? sun.last_commit_at
|
|
118
|
+
: sun.last_commit_at + 'Z').getTime();
|
|
119
|
+
const hoursSince = (Date.now() - lastCommitMs) / (1000 * 60 * 60);
|
|
120
|
+
if (hoursSince > 24) {
|
|
121
|
+
header += ` [STALE — last commit ${Math.floor(hoursSince)}h ago. Run commit to refresh.]`;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
sections.push(header);
|
|
125
|
+
// 2. CORE IDENTITY — core zone memories (distance < 1.0 AU).
|
|
126
|
+
// Compressed format: [TYPE] summary (no AU distance — saves tokens)
|
|
127
|
+
if (coreMemories.length > 0) {
|
|
128
|
+
const displayed = coreMemories.slice(0, MAX_CORE_DISPLAY);
|
|
129
|
+
const lines = displayed
|
|
130
|
+
.map(m => ` [${m.type.toUpperCase()}] ${truncSummary(m.summary)}`)
|
|
131
|
+
.join('\n');
|
|
132
|
+
const overflow = coreMemories.length > MAX_CORE_DISPLAY
|
|
133
|
+
? `\n (+${coreMemories.length - MAX_CORE_DISPLAY} more)`
|
|
134
|
+
: '';
|
|
135
|
+
sections.push(`\nCORE (${coreMemories.length}):\n${lines}${overflow}`);
|
|
136
|
+
}
|
|
137
|
+
// 3. Current work.
|
|
138
|
+
if (sun.current_work && sun.current_work.trim().length > 0) {
|
|
139
|
+
sections.push(`\nWORKING ON:\n${sun.current_work.trim()}`);
|
|
140
|
+
}
|
|
141
|
+
// 4. ACTIVE CONTEXT — near zone memories (1.0-5.0 AU).
|
|
142
|
+
if (nearMemories.length > 0) {
|
|
143
|
+
const displayed = nearMemories.slice(0, MAX_NEAR_DISPLAY);
|
|
144
|
+
const lines = displayed
|
|
145
|
+
.map(m => ` [${m.type.toUpperCase()}] ${truncSummary(m.summary)}`)
|
|
146
|
+
.join('\n');
|
|
147
|
+
const overflow = nearMemories.length > MAX_NEAR_DISPLAY
|
|
148
|
+
? `\n (+${nearMemories.length - MAX_NEAR_DISPLAY} more)`
|
|
149
|
+
: '';
|
|
150
|
+
sections.push(`\nNEAR (${nearMemories.length}):\n${lines}${overflow}`);
|
|
151
|
+
}
|
|
152
|
+
// 5. Recent decisions (max 3).
|
|
153
|
+
const decisions = sun.recent_decisions.slice(0, 3);
|
|
154
|
+
if (decisions.length > 0) {
|
|
155
|
+
const lines = decisions.map((d, i) => ` ${i + 1}. ${d}`).join('\n');
|
|
156
|
+
sections.push(`\nRECENT DECISIONS:\n${lines}`);
|
|
157
|
+
}
|
|
158
|
+
// 6. Next steps (max 3).
|
|
159
|
+
const steps = sun.next_steps.slice(0, 3);
|
|
160
|
+
if (steps.length > 0) {
|
|
161
|
+
const lines = steps.map((s, i) => ` ${i + 1}. ${s}`).join('\n');
|
|
162
|
+
sections.push(`\nNEXT STEPS:\n${lines}`);
|
|
163
|
+
}
|
|
164
|
+
// 7. Active issues (max 2).
|
|
165
|
+
const errors = sun.active_errors.slice(0, 2);
|
|
166
|
+
if (errors.length > 0) {
|
|
167
|
+
const lines = errors.map((e, i) => ` ${i + 1}. ${e}`).join('\n');
|
|
168
|
+
sections.push(`\nACTIVE ISSUES:\n${lines}`);
|
|
169
|
+
}
|
|
170
|
+
// Progressive truncation: accumulate sections until we hit the token budget.
|
|
171
|
+
let result = '';
|
|
172
|
+
for (const section of sections) {
|
|
173
|
+
const candidate = result + (result.length > 0 ? '\n' : '') + section;
|
|
174
|
+
if (estimateTokens(candidate) > budget) {
|
|
175
|
+
// This section would push us over — stop here.
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
result = candidate;
|
|
179
|
+
}
|
|
180
|
+
// Always return at least the header even if it alone exceeds the budget
|
|
181
|
+
// (highly unlikely but handles pathological configs).
|
|
182
|
+
if (result.length === 0) {
|
|
183
|
+
result = sections[0] ?? `[STELLAR MEMORY - project: ${sun.project}]`;
|
|
184
|
+
}
|
|
185
|
+
return result;
|
|
186
|
+
}
|
|
187
|
+
// ---------------------------------------------------------------------------
|
|
188
|
+
// Auto-commit on process exit
|
|
189
|
+
// ---------------------------------------------------------------------------
|
|
190
|
+
/**
|
|
191
|
+
* Automatically commit the sun state from recent memories when the
|
|
192
|
+
* MCP server process is shutting down.
|
|
193
|
+
*
|
|
194
|
+
* This prevents session context from being lost when Claude's process
|
|
195
|
+
* ends (e.g., SIGTERM from Claude Desktop, pipe close from Claude Code).
|
|
196
|
+
*
|
|
197
|
+
* Uses synchronous DB calls only — async is unsafe in exit handlers.
|
|
198
|
+
*/
|
|
199
|
+
export function autoCommitOnClose(project) {
|
|
200
|
+
try {
|
|
201
|
+
const recent = getRecentMemories(project, 3);
|
|
202
|
+
if (recent.length === 0)
|
|
203
|
+
return;
|
|
204
|
+
// Group by type
|
|
205
|
+
const byType = new Map();
|
|
206
|
+
for (const m of recent) {
|
|
207
|
+
const list = byType.get(m.type) ?? [];
|
|
208
|
+
list.push(m.summary);
|
|
209
|
+
byType.set(m.type, list);
|
|
210
|
+
}
|
|
211
|
+
// Build auto-commit fields
|
|
212
|
+
const current_work = byType.get('context')?.slice(0, 3).join('; ')
|
|
213
|
+
?? byType.get('task')?.slice(0, 3).join('; ')
|
|
214
|
+
?? `${recent.length} memories from last session`;
|
|
215
|
+
const decisions = byType.get('decision')?.slice(0, 5) ?? [];
|
|
216
|
+
const next_steps = byType.get('task')?.slice(0, 5) ?? [];
|
|
217
|
+
const errors = byType.get('error')?.slice(0, 3) ?? [];
|
|
218
|
+
const now = new Date().toISOString();
|
|
219
|
+
const existing = getSunState(project);
|
|
220
|
+
const updated = {
|
|
221
|
+
project,
|
|
222
|
+
content: current_work,
|
|
223
|
+
current_work,
|
|
224
|
+
recent_decisions: decisions,
|
|
225
|
+
next_steps,
|
|
226
|
+
active_errors: errors,
|
|
227
|
+
project_context: existing?.project_context ?? '',
|
|
228
|
+
token_count: 0,
|
|
229
|
+
last_commit_at: now,
|
|
230
|
+
updated_at: now,
|
|
231
|
+
};
|
|
232
|
+
upsertSunState(updated);
|
|
233
|
+
process.stderr.write(`[stellar-memory] Auto-committed sun state on shutdown (${recent.length} recent memories)\n`);
|
|
234
|
+
}
|
|
235
|
+
catch (err) {
|
|
236
|
+
// Exit handler must never throw — silently log and continue
|
|
237
|
+
process.stderr.write(`[stellar-memory] Auto-commit failed: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
//# sourceMappingURL=sun.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sun.js","sourceRoot":"","sources":["../../src/engine/sun.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EACL,WAAW,EACX,cAAc,EACd,iBAAiB,GAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,8EAA8E;AAC9E,aAAa;AACb,8EAA8E;AAE9E;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,OAAe;IAC3C,MAAM,GAAG,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;IAEjC,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,8BAA8B,OAAO,iFAAiF,CAAC;IAChI,CAAC;IAED,kEAAkE;IAClE,MAAM,YAAY,GAAG,MAA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CAAC;QACzD,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QAEtD,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QACrC,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;QAEtC,MAAM,OAAO,GAAa;YACxB,OAAO;YACP,OAAO,EAAW,YAAY;YAC9B,YAAY;YACZ,gBAAgB,EAAE,SAAS;YAC3B,UAAU;YACV,aAAa,EAAK,MAAM;YACxB,eAAe,EAAG,QAAQ,EAAE,eAAe,IAAI,EAAE;YACjD,WAAW,EAAO,CAAC;YACnB,cAAc,EAAI,GAAG;YACrB,UAAU,EAAQ,GAAG;SACtB,CAAC;QAEF,cAAc,CAAC,OAAO,CAAC,CAAC;QAExB,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,0DAA0D,MAAM,CAAC,MAAM,qBAAqB,CAC7F,CAAC;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,4DAA4D;QAC5D,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,wCAAwC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAC7F,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* temporal.ts — Temporal Awareness engine
|
|
3
|
+
*
|
|
4
|
+
* Tracks when facts become valid/invalid over time. Memories can have
|
|
5
|
+
* temporal bounds (valid_from, valid_until) and can supersede each other
|
|
6
|
+
* when a concept evolves (e.g., "Chose Redis" → "Switched to Valkey").
|
|
7
|
+
*
|
|
8
|
+
* All functions are pure (no classes), following the project style.
|
|
9
|
+
*/
|
|
10
|
+
import type { Memory } from './types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Set temporal validity bounds on a memory.
|
|
13
|
+
*
|
|
14
|
+
* - validFrom: ISO date string. If omitted, the memory is valid from creation.
|
|
15
|
+
* - validUntil: ISO date string. Setting this marks the fact as no longer current.
|
|
16
|
+
*/
|
|
17
|
+
export declare function setTemporalBounds(memoryId: string, validFrom?: string, validUntil?: string): void;
|
|
18
|
+
/**
|
|
19
|
+
* Mark oldMemoryId as superseded by newMemoryId.
|
|
20
|
+
*
|
|
21
|
+
* Sets the old memory's valid_until to now and records superseded_by.
|
|
22
|
+
* Uses the existing queries.supersedMemory() helper.
|
|
23
|
+
*/
|
|
24
|
+
export declare function supersedeMemory(oldMemoryId: string, newMemoryId: string): void;
|
|
25
|
+
/**
|
|
26
|
+
* Return the set of memories that were active at the given timestamp.
|
|
27
|
+
*
|
|
28
|
+
* A memory is active if:
|
|
29
|
+
* valid_from IS NULL OR valid_from <= timestamp
|
|
30
|
+
* AND (valid_until IS NULL OR valid_until > timestamp)
|
|
31
|
+
*
|
|
32
|
+
* Results are sorted by importance descending.
|
|
33
|
+
*/
|
|
34
|
+
export declare function getContextAtTime(project: string, timestamp: string): Memory[];
|
|
35
|
+
/**
|
|
36
|
+
* Follow the superseded_by chain forward from memoryId and also walk
|
|
37
|
+
* backward to find the earliest ancestor.
|
|
38
|
+
*
|
|
39
|
+
* Returns the full lineage in chronological order (oldest first).
|
|
40
|
+
*/
|
|
41
|
+
export declare function getEvolutionChain(memoryId: string): Memory[];
|
|
42
|
+
/**
|
|
43
|
+
* Detect whether newMemory should supersede an existing memory.
|
|
44
|
+
*
|
|
45
|
+
* Heuristics (no LLM required):
|
|
46
|
+
* 1. Same memory type (especially 'decision')
|
|
47
|
+
* 2. High keyword overlap (>70% shared key terms)
|
|
48
|
+
* 3. Content contains a "switch" signal ("switched from", "replaced", "instead of", etc.)
|
|
49
|
+
* 4. Existing memory has not already been superseded
|
|
50
|
+
*
|
|
51
|
+
* Returns the memory that should be superseded, or null.
|
|
52
|
+
*/
|
|
53
|
+
export declare function detectSupersession(newMemory: Memory, existingMemories: Memory[]): Memory | null;
|
|
54
|
+
/**
|
|
55
|
+
* Build a concise textual summary of temporal state for the sun resource.
|
|
56
|
+
*
|
|
57
|
+
* Includes:
|
|
58
|
+
* - Count of active vs superseded memories
|
|
59
|
+
* - Recent supersession events (last 5)
|
|
60
|
+
*/
|
|
61
|
+
export declare function getTemporalSummary(project: string): string;
|
|
62
|
+
/**
|
|
63
|
+
* Extract meaningful key terms from lowercased text.
|
|
64
|
+
* Filters out common stop words and short tokens.
|
|
65
|
+
*/
|
|
66
|
+
export declare function extractKeyTerms(text: string): Set<string>;
|
|
67
|
+
//# sourceMappingURL=temporal.d.ts.map
|