kimi-code-memory-mcp-server 0.1.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/AGENTS.md +144 -0
- package/CHANGELOG.md +26 -0
- package/LICENSE +21 -0
- package/README.md +227 -0
- package/README.zh-CN.md +227 -0
- package/dist/config.d.ts +36 -0
- package/dist/config.js +63 -0
- package/dist/config.js.map +1 -0
- package/dist/context/wire-context.d.ts +171 -0
- package/dist/context/wire-context.js +586 -0
- package/dist/context/wire-context.js.map +1 -0
- package/dist/dao/index.d.ts +76 -0
- package/dist/dao/index.js +490 -0
- package/dist/dao/index.js.map +1 -0
- package/dist/dao/memory-store.d.ts +24 -0
- package/dist/dao/memory-store.js +112 -0
- package/dist/dao/memory-store.js.map +1 -0
- package/dist/refined-manager.d.ts +70 -0
- package/dist/refined-manager.js +369 -0
- package/dist/refined-manager.js.map +1 -0
- package/dist/server.d.ts +8 -0
- package/dist/server.js +71 -0
- package/dist/server.js.map +1 -0
- package/dist/theme-manager.d.ts +40 -0
- package/dist/theme-manager.js +88 -0
- package/dist/theme-manager.js.map +1 -0
- package/dist/tools/context-tools.d.ts +56 -0
- package/dist/tools/context-tools.js +332 -0
- package/dist/tools/context-tools.js.map +1 -0
- package/dist/tools/index.d.ts +835 -0
- package/dist/tools/index.js +370 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/memory-tools.d.ts +62 -0
- package/dist/tools/memory-tools.js +292 -0
- package/dist/tools/memory-tools.js.map +1 -0
- package/dist/tools/system-tools.d.ts +37 -0
- package/dist/tools/system-tools.js +195 -0
- package/dist/tools/system-tools.js.map +1 -0
- package/dist/tools/theme-tools.d.ts +34 -0
- package/dist/tools/theme-tools.js +186 -0
- package/dist/tools/theme-tools.js.map +1 -0
- package/dist/types.d.ts +93 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/frontmatter.d.ts +10 -0
- package/dist/utils/frontmatter.js +61 -0
- package/dist/utils/frontmatter.js.map +1 -0
- package/dist/utils/mutex.d.ts +11 -0
- package/dist/utils/mutex.js +17 -0
- package/dist/utils/mutex.js.map +1 -0
- package/dist/utils/paths.d.ts +19 -0
- package/dist/utils/paths.js +54 -0
- package/dist/utils/paths.js.map +1 -0
- package/dist/utils/validation.d.ts +15 -0
- package/dist/utils/validation.js +40 -0
- package/dist/utils/validation.js.map +1 -0
- package/dist/version.d.ts +9 -0
- package/dist/version.js +10 -0
- package/dist/version.js.map +1 -0
- package/docs/ARCHITECTURE.md +144 -0
- package/docs/CONTRIBUTING.md +83 -0
- package/docs/CONTRIBUTING.zh-CN.md +83 -0
- package/docs/search-logic.md +157 -0
- package/docs/search-logic.zh-CN.md +157 -0
- package/examples/README.md +34 -0
- package/examples/sample-workspace/essence/essence.md +26 -0
- package/examples/sample-workspace/index.json +36 -0
- package/examples/sample-workspace/memory/decisions/sample-decision.md +30 -0
- package/examples/sample-workspace/memory/knowledge/sample-knowledge.md +24 -0
- package/examples/sample-workspace/memory/reference/sample-reference.md +20 -0
- package/examples/sample-workspace/memory/rules/sample-rule.md +31 -0
- package/examples/sample-workspace/themes/cache-design.json +15 -0
- package/package.json +72 -0
- package/skills/memory-manage/SKILL.md +43 -0
package/dist/config.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global configuration.
|
|
3
|
+
*
|
|
4
|
+
* The store root can be overridden via the MEMORY_STORE_ROOT environment
|
|
5
|
+
* variable. When unset, it defaults to ~/.kimi-code-memory/ so that the
|
|
6
|
+
* server behaves like a user-level tool even when installed as a package.
|
|
7
|
+
*/
|
|
8
|
+
import os from 'os';
|
|
9
|
+
import path from 'path';
|
|
10
|
+
export const homedir = os.homedir();
|
|
11
|
+
export function getStoreRoot() {
|
|
12
|
+
const envRoot = process.env.MEMORY_STORE_ROOT;
|
|
13
|
+
if (envRoot) {
|
|
14
|
+
if (envRoot.includes('\0')) {
|
|
15
|
+
throw new Error('MEMORY_STORE_ROOT contains invalid null byte');
|
|
16
|
+
}
|
|
17
|
+
const resolved = path.resolve(envRoot);
|
|
18
|
+
if (!path.isAbsolute(resolved)) {
|
|
19
|
+
throw new Error(`MEMORY_STORE_ROOT must resolve to an absolute path: ${envRoot}`);
|
|
20
|
+
}
|
|
21
|
+
return resolved;
|
|
22
|
+
}
|
|
23
|
+
return path.join(homedir, '.kimi-code-memory');
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Resolve the directory where Kimi Code CLI session wires are stored.
|
|
27
|
+
*
|
|
28
|
+
* Priority:
|
|
29
|
+
* 1. MEMORY_SESSIONS_ROOT environment variable (absolute path)
|
|
30
|
+
* 2. KIMI_CODE_HOME environment variable (<KIMI_CODE_HOME>/sessions)
|
|
31
|
+
* 3. Default ~/.kimi-code/sessions
|
|
32
|
+
*/
|
|
33
|
+
export function getSessionsRoot() {
|
|
34
|
+
if (process.env.MEMORY_SESSIONS_ROOT) {
|
|
35
|
+
const resolved = path.resolve(process.env.MEMORY_SESSIONS_ROOT);
|
|
36
|
+
if (!path.isAbsolute(resolved)) {
|
|
37
|
+
throw new Error(`MEMORY_SESSIONS_ROOT must resolve to an absolute path: ${process.env.MEMORY_SESSIONS_ROOT}`);
|
|
38
|
+
}
|
|
39
|
+
return resolved;
|
|
40
|
+
}
|
|
41
|
+
if (process.env.KIMI_CODE_HOME) {
|
|
42
|
+
return path.join(path.resolve(process.env.KIMI_CODE_HOME), 'sessions');
|
|
43
|
+
}
|
|
44
|
+
return path.join(homedir, '.kimi-code', 'sessions');
|
|
45
|
+
}
|
|
46
|
+
export const DEFAULT_CONTEXT_WINDOW = {
|
|
47
|
+
detailedRounds: 3,
|
|
48
|
+
defaultSummaryRounds: 2,
|
|
49
|
+
loadMoreChunkSize: 5,
|
|
50
|
+
};
|
|
51
|
+
export const DEFAULT_RECENT_CHANGE_LIMIT = 5;
|
|
52
|
+
export const ESSENCE_SIZE_LIMIT = 15 * 1024; // 15 KB
|
|
53
|
+
/**
|
|
54
|
+
* search_context 用于把相邻 turn 聚成「簇」的默认时间间隔(秒)。
|
|
55
|
+
*
|
|
56
|
+
* 「簇」是指一小段连续的来回对话,通常围绕同一个决策或讨论展开。
|
|
57
|
+
* 如果两个相邻 turn 的时间间隔超过这个值,就认为它们属于不同的簇。
|
|
58
|
+
*
|
|
59
|
+
* 90 秒适合典型的 agent-user 对话:既能区分开不同话题,又足以保留
|
|
60
|
+
* 一段流畅讨论的完整性。每次搜索可以通过 cluster_gap_seconds 参数覆盖。
|
|
61
|
+
*/
|
|
62
|
+
export const DEFAULT_CLUSTER_GAP_SECONDS = 90;
|
|
63
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,CAAC,MAAM,OAAO,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC;AAEpC,MAAM,UAAU,YAAY;IAC1B,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;IAC9C,IAAI,OAAO,EAAE,CAAC;QACZ,IAAI,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;QAClE,CAAC;QACD,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACvC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC,uDAAuD,OAAO,EAAE,CAAC,CAAC;QACpF,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;AACjD,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe;IAC7B,IAAI,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,CAAC;QACrC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;QAChE,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC,0DAA0D,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,CAAC,CAAC;QAChH,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC;QAC/B,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,UAAU,CAAC,CAAC;IACzE,CAAC;IACD,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,YAAY,EAAE,UAAU,CAAC,CAAC;AACtD,CAAC;AAQD,MAAM,CAAC,MAAM,sBAAsB,GAAkB;IACnD,cAAc,EAAE,CAAC;IACjB,oBAAoB,EAAE,CAAC;IACvB,iBAAiB,EAAE,CAAC;CACrB,CAAC;AAEF,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAC;AAE7C,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,QAAQ;AAErD;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,EAAE,CAAC"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* wire.jsonl parsing and context recovery.
|
|
3
|
+
*
|
|
4
|
+
* This module is intentionally Kimi Code CLI specific: it understands the
|
|
5
|
+
* wire.jsonl event schema. A future abstraction layer could make this pluggable.
|
|
6
|
+
*/
|
|
7
|
+
import type { ContextWindow } from '../config.js';
|
|
8
|
+
import type { RefinedManager } from '../refined-manager.js';
|
|
9
|
+
export interface McpConfig {
|
|
10
|
+
version: number;
|
|
11
|
+
contextWindow: ContextWindow;
|
|
12
|
+
recentChangeLimit: number;
|
|
13
|
+
sessionMappings: Record<string, SessionMapping>;
|
|
14
|
+
}
|
|
15
|
+
export interface SessionMapping {
|
|
16
|
+
slugDir: string;
|
|
17
|
+
discoveredAt: string;
|
|
18
|
+
}
|
|
19
|
+
export interface WireSession {
|
|
20
|
+
sessionId: string;
|
|
21
|
+
wire: string;
|
|
22
|
+
mtime?: number;
|
|
23
|
+
slugDir?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface WireAction {
|
|
26
|
+
name: string;
|
|
27
|
+
args: string;
|
|
28
|
+
result: string;
|
|
29
|
+
}
|
|
30
|
+
export interface WireTurn {
|
|
31
|
+
turnId: string;
|
|
32
|
+
timestamp: string | null;
|
|
33
|
+
user: string;
|
|
34
|
+
agentText: string;
|
|
35
|
+
actions: WireAction[];
|
|
36
|
+
}
|
|
37
|
+
export interface CompactionSummary {
|
|
38
|
+
time: string | null;
|
|
39
|
+
summary: string;
|
|
40
|
+
}
|
|
41
|
+
export interface ContextWindowOverrides {
|
|
42
|
+
detailedRounds?: number;
|
|
43
|
+
summaryRounds?: number;
|
|
44
|
+
}
|
|
45
|
+
export interface SearchOptions {
|
|
46
|
+
limit?: number;
|
|
47
|
+
dateFrom?: string;
|
|
48
|
+
dateTo?: string;
|
|
49
|
+
refinedManager?: RefinedManager;
|
|
50
|
+
}
|
|
51
|
+
export interface SearchMatch {
|
|
52
|
+
sessionId: string;
|
|
53
|
+
turnId: number;
|
|
54
|
+
timestamp: string | null;
|
|
55
|
+
score: number;
|
|
56
|
+
user: string;
|
|
57
|
+
agent: string;
|
|
58
|
+
snippet: string;
|
|
59
|
+
actions: string[];
|
|
60
|
+
}
|
|
61
|
+
export interface SearchResult {
|
|
62
|
+
query: string;
|
|
63
|
+
totalMatches: number;
|
|
64
|
+
matches: SearchMatch[];
|
|
65
|
+
hits: Array<{
|
|
66
|
+
sessionId: string;
|
|
67
|
+
turn: WireTurn;
|
|
68
|
+
}>;
|
|
69
|
+
skippedSessionIds?: string[];
|
|
70
|
+
}
|
|
71
|
+
export interface LoadTurnOptions {
|
|
72
|
+
maxReferences?: number;
|
|
73
|
+
}
|
|
74
|
+
export interface TurnReference {
|
|
75
|
+
sessionId: string;
|
|
76
|
+
turnId: number;
|
|
77
|
+
}
|
|
78
|
+
export interface DetailedRound {
|
|
79
|
+
turnId: number;
|
|
80
|
+
timestamp: string | null;
|
|
81
|
+
user: string;
|
|
82
|
+
agent: string;
|
|
83
|
+
actions: WireAction[];
|
|
84
|
+
}
|
|
85
|
+
export interface SummaryRound {
|
|
86
|
+
turnId: number;
|
|
87
|
+
timestamp: string | null;
|
|
88
|
+
summary: string;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Load the global MCP configuration, creating defaults if absent.
|
|
92
|
+
*/
|
|
93
|
+
export declare function loadMcpConfig(): McpConfig;
|
|
94
|
+
/**
|
|
95
|
+
* Persist the global MCP configuration.
|
|
96
|
+
*/
|
|
97
|
+
export declare function saveMcpConfig(config: McpConfig): void;
|
|
98
|
+
/**
|
|
99
|
+
* Discover the active session for the current workspace and cache the mapping.
|
|
100
|
+
*/
|
|
101
|
+
export declare function discoverCurrentSession(): WireSession | null;
|
|
102
|
+
/**
|
|
103
|
+
* Resolve the active session wire path, using the cached mapping if valid.
|
|
104
|
+
*/
|
|
105
|
+
export declare function getCurrentSessionWirePath(): WireSession | null;
|
|
106
|
+
/**
|
|
107
|
+
* Find all historical sessions for the current workspace.
|
|
108
|
+
*/
|
|
109
|
+
export declare function findAllWorkspaceSessions(): WireSession[];
|
|
110
|
+
/**
|
|
111
|
+
* Parse a wire.jsonl file and return conversation turns + session-level
|
|
112
|
+
* compaction summaries.
|
|
113
|
+
*/
|
|
114
|
+
export declare function parseWireFile(wirePath: string): Promise<{
|
|
115
|
+
turns: WireTurn[];
|
|
116
|
+
compactionSummaries: CompactionSummary[];
|
|
117
|
+
}>;
|
|
118
|
+
/**
|
|
119
|
+
* Build the default context window: last N rounds detailed, preceding M rounds
|
|
120
|
+
* summarized.
|
|
121
|
+
*/
|
|
122
|
+
export declare function buildContextWindow(turns: WireTurn[], overrides?: ContextWindowOverrides): {
|
|
123
|
+
detailedRounds: DetailedRound[];
|
|
124
|
+
summaryRounds: SummaryRound[];
|
|
125
|
+
totalTurns: number;
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Load older rounds before a given turnId, summarized by default.
|
|
129
|
+
*/
|
|
130
|
+
export declare function loadMoreRounds(turns: WireTurn[], beforeTurnId: number, limit?: number): SummaryRound[];
|
|
131
|
+
/**
|
|
132
|
+
* Search across all workspace session wires for rounds matching the query.
|
|
133
|
+
*
|
|
134
|
+
* If a RefinedManager is provided, we first query the refined SQLite index for
|
|
135
|
+
* candidate turns and only parse the wires needed to return full content. This
|
|
136
|
+
* avoids parsing every historical wire on every search. When refined data is
|
|
137
|
+
* unavailable we fall back to the original full-scan behavior.
|
|
138
|
+
*/
|
|
139
|
+
export declare function searchWireContext(query: string, options?: SearchOptions): Promise<{
|
|
140
|
+
query: string;
|
|
141
|
+
totalMatches: number;
|
|
142
|
+
matches: SearchMatch[];
|
|
143
|
+
hits: Array<{
|
|
144
|
+
sessionId: string;
|
|
145
|
+
turn: WireTurn;
|
|
146
|
+
}>;
|
|
147
|
+
skippedSessionIds?: undefined;
|
|
148
|
+
} | {
|
|
149
|
+
query: string;
|
|
150
|
+
totalMatches: number;
|
|
151
|
+
matches: SearchMatch[];
|
|
152
|
+
hits: {
|
|
153
|
+
sessionId: string;
|
|
154
|
+
turn: WireTurn;
|
|
155
|
+
}[];
|
|
156
|
+
skippedSessionIds: string[];
|
|
157
|
+
}>;
|
|
158
|
+
/**
|
|
159
|
+
* Load the full detailed content of specific conversation turns.
|
|
160
|
+
*/
|
|
161
|
+
export declare function loadTurnContext(references: TurnReference[], options?: LoadTurnOptions): Promise<{
|
|
162
|
+
rounds: never[];
|
|
163
|
+
notFound: never[];
|
|
164
|
+
error: string;
|
|
165
|
+
} | {
|
|
166
|
+
rounds: ({
|
|
167
|
+
sessionId: string;
|
|
168
|
+
} & DetailedRound)[];
|
|
169
|
+
notFound: TurnReference[];
|
|
170
|
+
error?: undefined;
|
|
171
|
+
}>;
|