@yungkei/geoplana 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README-zh.md +24 -6
- package/README.md +24 -6
- package/dist/{chunk-6BJCPRH7.js → chunk-4JZEJXMA.js} +22 -3
- package/dist/chunk-4JZEJXMA.js.map +1 -0
- package/dist/{chunk-6NY3OEIW.js → chunk-5QLVGPLD.js} +8 -1
- package/dist/chunk-5QLVGPLD.js.map +1 -0
- package/dist/{chunk-ZCE6KQO5.js → chunk-CUOJUXUT.js} +33 -2
- package/dist/chunk-CUOJUXUT.js.map +1 -0
- package/dist/{chunk-3QZL6LY7.js → chunk-LSGK3SKU.js} +2 -2
- package/dist/{chunk-J3S4NJ6B.js → chunk-THMXXBZW.js} +733 -151
- package/dist/chunk-THMXXBZW.js.map +1 -0
- package/dist/cli/index.js +10 -9
- package/dist/cli/index.js.map +1 -1
- package/dist/{events-KUYZEAKG.js → events-QOMOWQVJ.js} +3 -3
- package/dist/{handler-DAOFR5JH.js → handler-ILMUSX3A.js} +7 -4
- package/dist/handler-ILMUSX3A.js.map +1 -0
- package/dist/index.d.ts +272 -8
- package/dist/index.js +8 -6
- package/dist/index.js.map +1 -1
- package/dist/{metrics-YMKFEUQK.js → metrics-CMVYA57T.js} +2 -2
- package/dist/{server-NPLFEU2Y.js → server-UK2MWDSH.js} +17 -5
- package/dist/server-UK2MWDSH.js.map +1 -0
- package/package.json +6 -3
- package/server.json +22 -0
- package/dist/chunk-6BJCPRH7.js.map +0 -1
- package/dist/chunk-6NY3OEIW.js.map +0 -1
- package/dist/chunk-J3S4NJ6B.js.map +0 -1
- package/dist/chunk-ZCE6KQO5.js.map +0 -1
- package/dist/handler-DAOFR5JH.js.map +0 -1
- package/dist/server-NPLFEU2Y.js.map +0 -1
- /package/dist/{chunk-3QZL6LY7.js.map → chunk-LSGK3SKU.js.map} +0 -0
- /package/dist/{events-KUYZEAKG.js.map → events-QOMOWQVJ.js.map} +0 -0
- /package/dist/{metrics-YMKFEUQK.js.map → metrics-CMVYA57T.js.map} +0 -0
package/README-zh.md
CHANGED
|
@@ -43,16 +43,25 @@
|
|
|
43
43
|
## 功能
|
|
44
44
|
|
|
45
45
|
- **双层存储**:提炼记忆(memories)+ 无损原始归档(episodes),SQLite + FTS5 多语言全文检索(中/日/韩/泰/俄/阿拉伯等),本地零依赖
|
|
46
|
-
- **本地查询扩展**:改写、跨语言、形态变体的查询同样能命中——内置中英概念表 +
|
|
47
|
-
-
|
|
46
|
+
- **本地查询扩展**:改写、跨语言、形态变体的查询同样能命中——内置中英概念表 + 意图相关词在匹配前扩展查询(不依赖模型、不联网);中文两字词也能命中,字面命中始终排在仅扩展命中之上
|
|
47
|
+
- **自动捕获**:用户明确表达的决策、偏好与错误按确定性规则结构化提取;工具活动只留在无损原始归档里;`<private>` 内容永不落盘
|
|
48
48
|
- **压缩抢救**:agent 上下文压缩前,完整对话快照自动归档
|
|
49
|
-
- **生命周期管理**:热/温/冷三层留存(gzip 压缩 +
|
|
49
|
+
- **生命周期管理**:热/温/冷三层留存(gzip 压缩 + 归档导出)、存储配额、遗忘曲线淘汰,以及 GC 清理活动日志记忆
|
|
50
|
+
- **基于证据的召回质量**:每次搜索都会记录查询日志(查询、完整搜索输入、评分参数快照、命中分数、扩展 provenance、带分支与 scope 标签的命中),结局会回写到找出它的那条查询命中上;`memory_stats` 输出零命中率、按查询的使用/无用率与标注覆盖率、LIKE/扩展贡献、scope 命中占比、按类型的价值统计(被读过且评为有用的决策数)、抽取与冲突消解计数、GC 活动与噪音审计(D0-D3)
|
|
50
51
|
- **使用保障**:`geoplana setup` 向 agent 指令文件(AGENTS.md / CLAUDE.md)写入记忆协议,告诉它何时检索、何时保存、冲突如何处理
|
|
51
52
|
- **冲突决策**:`memory_save` 发现相似记忆时返回 `conflicts` 而非静默覆盖;agent 向用户确认后调用 `memory_resolve`(keep-new / keep-old / keep-both)
|
|
52
|
-
- **MCP 工具**:`memory_save` / `memory_search` / `memory_get` / `memory_update` / `memory_delete` / `memory_list` / `memory_capture` / `memory_context` / `memory_resolve` / `memory_stats`
|
|
53
|
+
- **MCP 工具**:`memory_save` / `memory_search` / `memory_get` / `memory_update` / `memory_delete` / `memory_list` / `memory_capture` / `memory_context` / `memory_resolve` / `memory_feedback` / `memory_stats`
|
|
53
54
|
|
|
54
55
|
## 安装
|
|
55
56
|
|
|
57
|
+
```bash
|
|
58
|
+
npm install -g @yungkei/geoplana
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
数据存于 `~/.geoplana/geoplana.db`(环境变量 `GEOPLANA_HOME` 可覆盖)。
|
|
62
|
+
|
|
63
|
+
开发 geoplana 本身:
|
|
64
|
+
|
|
56
65
|
```bash
|
|
57
66
|
git clone https://github.com/yungkei/geoplana.git
|
|
58
67
|
cd geoplana
|
|
@@ -61,8 +70,6 @@ npm run build
|
|
|
61
70
|
npm link # 使 geoplana 命令全局可用
|
|
62
71
|
```
|
|
63
72
|
|
|
64
|
-
数据存于 `~/.geoplana/geoplana.db`(环境变量 `GEOPLANA_HOME` 可覆盖)。
|
|
65
|
-
|
|
66
73
|
## 快速开始
|
|
67
74
|
|
|
68
75
|
### 接入 claude code(纯配置,零代码)
|
|
@@ -99,6 +106,16 @@ shim 是双代同体的 —— 同一个文件在加载时自动适配 opencode
|
|
|
99
106
|
}
|
|
100
107
|
```
|
|
101
108
|
|
|
109
|
+
不做全局安装的话,直接跑已发布的包:
|
|
110
|
+
|
|
111
|
+
```json
|
|
112
|
+
{
|
|
113
|
+
"mcpServers": {
|
|
114
|
+
"geoplana": { "command": "npx", "args": ["-y", "@yungkei/geoplana", "mcp"] }
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
102
119
|
## CLI
|
|
103
120
|
|
|
104
121
|
```bash
|
|
@@ -195,6 +212,7 @@ geoplana migrate # 执行
|
|
|
195
212
|
| `maxStorageMb` | DB 体积配额,超限自动升级清理 |
|
|
196
213
|
| `evictThreshold` | 遗忘曲线淘汰阈值(pinned 记忆永不淘汰) |
|
|
197
214
|
| `autoGc` | MCP server 启动时自动执行 GC |
|
|
215
|
+
| `metrics.queryLog` | 把每次搜索记录为证据(查询、namespace、带分支标签的命中),供召回质量报告使用;`false` 关闭 |
|
|
198
216
|
|
|
199
217
|
环境变量:`GEOPLANA_HOME`(数据目录)、`GEOPLANA_CMD`(agent shim 调用的命令路径)、`GEOPLANA_RECALL=1`(opencode 每轮自动召回)、`GEOPLANA_DEBUG=1`(调试日志)。
|
|
200
218
|
|
package/README.md
CHANGED
|
@@ -43,16 +43,25 @@ When a long coding session hits the context limit, agents compact history into a
|
|
|
43
43
|
## Features
|
|
44
44
|
|
|
45
45
|
- **Two-layer storage**: curated memories + lossless episode archive. SQLite + FTS5 with multilingual full-text search (CJK/Korean/Thai/Russian/Arabic/...), fully local, zero external dependencies
|
|
46
|
-
- **Local query expansion**: paraphrased, cross-language and morphological queries still hit — a curated English/Chinese concept table plus intent-scoped terms widen the query before matching (no model, no network).
|
|
47
|
-
- **Automatic capture**: decisions,
|
|
46
|
+
- **Local query expansion**: paraphrased, cross-language and morphological queries still hit — a curated English/Chinese concept table plus intent-scoped terms widen the query before matching (no model, no network). Two-character Chinese words match too, and literal matches always rank above expansion-only ones
|
|
47
|
+
- **Automatic capture**: decisions, preferences and errors the user states are extracted with deterministic rules; tool activity stays in the lossless episode archive; `<private>` content never touches disk
|
|
48
48
|
- **Compaction rescue**: full conversation snapshot archived before the agent compacts its context
|
|
49
|
-
- **Lifecycle management**: hot/warm/cold retention tiers (gzip compression + archive export), storage quota, forgetting-curve eviction
|
|
49
|
+
- **Lifecycle management**: hot/warm/cold retention tiers (gzip compression + archive export), storage quota, forgetting-curve eviction, and GC cleanup of activity-log memories
|
|
50
|
+
- **Evidence-based recall quality**: every search is logged (query, full search input, scoring-parameter snapshot, hit scores, expansion provenance, hits tagged with branch and scope), outcomes are written back onto the query hits that surfaced them, and `memory_stats` reports the zero-hit rate, per-query used/useless rates and label coverage, LIKE/expansion contribution, scope hit-share, per-type value (decisions read and rated useful), extraction and conflict-resolution outcomes, GC activity and a noise audit (D0-D3)
|
|
50
51
|
- **Usage assurance**: `geoplana setup` writes a memory protocol into the agent's instructions file (AGENTS.md / CLAUDE.md) telling it when to search, when to save, and how to handle conflicts
|
|
51
52
|
- **Conflict resolution**: `memory_save` returns similar existing memories as `conflicts` instead of silently overwriting; the agent asks the user, then calls `memory_resolve` (keep-new / keep-old / keep-both)
|
|
52
|
-
- **MCP tools**: `memory_save` / `memory_search` / `memory_get` / `memory_update` / `memory_delete` / `memory_list` / `memory_capture` / `memory_context` / `memory_resolve` / `memory_stats`
|
|
53
|
+
- **MCP tools**: `memory_save` / `memory_search` / `memory_get` / `memory_update` / `memory_delete` / `memory_list` / `memory_capture` / `memory_context` / `memory_resolve` / `memory_feedback` / `memory_stats`
|
|
53
54
|
|
|
54
55
|
## Install
|
|
55
56
|
|
|
57
|
+
```bash
|
|
58
|
+
npm install -g @yungkei/geoplana
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Data lives in `~/.geoplana/geoplana.db` (override with the `GEOPLANA_HOME` env var).
|
|
62
|
+
|
|
63
|
+
Working on geoplana itself:
|
|
64
|
+
|
|
56
65
|
```bash
|
|
57
66
|
git clone https://github.com/yungkei/geoplana.git
|
|
58
67
|
cd geoplana
|
|
@@ -61,8 +70,6 @@ npm run build
|
|
|
61
70
|
npm link # makes the geoplana command globally available
|
|
62
71
|
```
|
|
63
72
|
|
|
64
|
-
Data lives in `~/.geoplana/geoplana.db` (override with the `GEOPLANA_HOME` env var).
|
|
65
|
-
|
|
66
73
|
## Quick start
|
|
67
74
|
|
|
68
75
|
### claude code (pure config, zero code)
|
|
@@ -99,6 +106,16 @@ The shim is dual-generation — one file adapts at load time to both the opencod
|
|
|
99
106
|
}
|
|
100
107
|
```
|
|
101
108
|
|
|
109
|
+
Without a global install, run the published package directly:
|
|
110
|
+
|
|
111
|
+
```json
|
|
112
|
+
{
|
|
113
|
+
"mcpServers": {
|
|
114
|
+
"geoplana": { "command": "npx", "args": ["-y", "@yungkei/geoplana", "mcp"] }
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
102
119
|
## CLI
|
|
103
120
|
|
|
104
121
|
```bash
|
|
@@ -195,6 +212,7 @@ geoplana migrate # apply
|
|
|
195
212
|
| `maxStorageMb` | DB size quota; GC escalates when exceeded |
|
|
196
213
|
| `evictThreshold` | Forgetting-curve eviction threshold (pinned memories are never evicted) |
|
|
197
214
|
| `autoGc` | Run GC automatically when the MCP server starts |
|
|
215
|
+
| `metrics.queryLog` | Log every search as evidence (query, namespaces, branch-tagged hits) for the recall quality report; `false` disables it |
|
|
198
216
|
|
|
199
217
|
Environment variables: `GEOPLANA_HOME` (data directory), `GEOPLANA_CMD` (command path used by agent shims), `GEOPLANA_RECALL=1` (opencode per-turn recall), `GEOPLANA_DEBUG=1` (debug logs).
|
|
200
218
|
|
|
@@ -9,7 +9,13 @@ var MEMORY_TYPES = [
|
|
|
9
9
|
"error"
|
|
10
10
|
];
|
|
11
11
|
var MemoryTypeSchema = z.enum(MEMORY_TYPES);
|
|
12
|
-
var EPISODE_KINDS = [
|
|
12
|
+
var EPISODE_KINDS = [
|
|
13
|
+
"message",
|
|
14
|
+
"tool_event",
|
|
15
|
+
"compaction_snapshot",
|
|
16
|
+
"note",
|
|
17
|
+
"query"
|
|
18
|
+
];
|
|
13
19
|
var EpisodeKindSchema = z.enum(EPISODE_KINDS);
|
|
14
20
|
var SaveMemoryInputSchema = z.object({
|
|
15
21
|
namespace: z.string().min(1),
|
|
@@ -41,7 +47,19 @@ var SearchInputSchema = z.object({
|
|
|
41
47
|
boostTypes: z.array(MemoryTypeSchema).optional(),
|
|
42
48
|
limit: z.number().int().min(1).max(100).default(10),
|
|
43
49
|
includeEpisodes: z.boolean().default(true),
|
|
44
|
-
includeSuperseded: z.boolean().default(false)
|
|
50
|
+
includeSuperseded: z.boolean().default(false),
|
|
51
|
+
/**
|
|
52
|
+
* session the search runs in; recorded on the query-log episode so the
|
|
53
|
+
* outcome attribution can tell a repeat of the same query apart from a
|
|
54
|
+
* different session asking it
|
|
55
|
+
*/
|
|
56
|
+
sessionId: z.string().optional()
|
|
57
|
+
});
|
|
58
|
+
var FeedbackInputSchema = z.object({
|
|
59
|
+
id: z.string().min(1).describe("the memory that was used"),
|
|
60
|
+
useful: z.boolean().describe(
|
|
61
|
+
"true: the memory helped; false: it was noise. Useful feedback also credits the search that surfaced the memory."
|
|
62
|
+
)
|
|
45
63
|
});
|
|
46
64
|
var CaptureInputSchema = z.object({
|
|
47
65
|
namespace: z.string().min(1),
|
|
@@ -73,8 +91,9 @@ export {
|
|
|
73
91
|
SaveMemoryInputSchema,
|
|
74
92
|
UpdateMemoryInputSchema,
|
|
75
93
|
SearchInputSchema,
|
|
94
|
+
FeedbackInputSchema,
|
|
76
95
|
CaptureInputSchema,
|
|
77
96
|
ContextInputSchema,
|
|
78
97
|
ResolveConflictInputSchema
|
|
79
98
|
};
|
|
80
|
-
//# sourceMappingURL=chunk-
|
|
99
|
+
//# sourceMappingURL=chunk-4JZEJXMA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import { z } from \"zod\"\n\n// ---------------------------------------------------------------------------\n// Enums\n// ---------------------------------------------------------------------------\n\nexport const MEMORY_TYPES = [\n \"fact\",\n \"preference\",\n \"decision\",\n \"context\",\n \"instruction\",\n \"error\",\n] as const\nexport const MemoryTypeSchema = z.enum(MEMORY_TYPES)\nexport type MemoryType = z.infer<typeof MemoryTypeSchema>\n\nexport const EPISODE_KINDS = [\n \"message\",\n \"tool_event\",\n \"compaction_snapshot\",\n \"note\",\n \"query\",\n] as const\nexport const EpisodeKindSchema = z.enum(EPISODE_KINDS)\nexport type EpisodeKind = z.infer<typeof EpisodeKindSchema>\n\n// ---------------------------------------------------------------------------\n// Entities\n// ---------------------------------------------------------------------------\n\nexport interface Memory {\n id: string\n namespace: string\n type: MemoryType\n content: string\n summary: string | null\n tags: string[]\n metadata: Record<string, unknown>\n importance: number\n pinned: boolean\n supersededBy: string | null\n sourceEpisodeId: string | null\n contentHash: string\n accessCount: number\n createdAt: number\n updatedAt: number\n lastAccessedAt: number | null\n}\n\nexport interface Episode {\n id: string\n namespace: string\n sessionId: string | null\n kind: EpisodeKind\n content: string\n metadata: Record<string, unknown>\n contentHash: string\n createdAt: number\n /** warm-tier: content stored gzipped, FTS row removed */\n compressed: boolean\n /** short excerpt kept for browsing compressed episodes */\n digest: string | null\n}\n\n// ---------------------------------------------------------------------------\n// Inputs (zod-validated at every interface boundary: MCP / HTTP / CLI)\n// ---------------------------------------------------------------------------\n\nexport const SaveMemoryInputSchema = z.object({\n namespace: z.string().min(1),\n type: MemoryTypeSchema,\n content: z.string().min(1),\n summary: z.string().optional(),\n tags: z.array(z.string()).default([]),\n metadata: z.record(z.unknown()).default({}),\n importance: z.number().min(0).max(1).default(0.5),\n pinned: z.boolean().default(false),\n supersedes: z.string().optional().describe(\"id of an existing memory this one replaces\"),\n sourceEpisodeId: z.string().optional(),\n})\nexport type SaveMemoryInput = z.input<typeof SaveMemoryInputSchema>\n\nexport const UpdateMemoryInputSchema = z.object({\n content: z.string().min(1).optional(),\n summary: z.string().nullable().optional(),\n type: MemoryTypeSchema.optional(),\n tags: z.array(z.string()).optional(),\n metadata: z.record(z.unknown()).optional(),\n importance: z.number().min(0).max(1).optional(),\n pinned: z.boolean().optional(),\n})\nexport type UpdateMemoryInput = z.input<typeof UpdateMemoryInputSchema>\n\nexport const SearchInputSchema = z.object({\n query: z.string().min(1),\n namespaces: z.array(z.string()).optional().describe(\"filter to these namespaces; omitted = all\"),\n types: z.array(MemoryTypeSchema).optional(),\n tags: z.array(z.string()).optional(),\n /** soft-relevant memory types: boosted in ranking, never filtered out */\n boostTypes: z.array(MemoryTypeSchema).optional(),\n limit: z.number().int().min(1).max(100).default(10),\n includeEpisodes: z.boolean().default(true),\n includeSuperseded: z.boolean().default(false),\n /**\n * session the search runs in; recorded on the query-log episode so the\n * outcome attribution can tell a repeat of the same query apart from a\n * different session asking it\n */\n sessionId: z.string().optional(),\n})\nexport type SearchInput = z.input<typeof SearchInputSchema>\n\nexport const FeedbackInputSchema = z.object({\n id: z.string().min(1).describe(\"the memory that was used\"),\n useful: z\n .boolean()\n .describe(\n \"true: the memory helped; false: it was noise. Useful feedback also credits the search that surfaced the memory.\",\n ),\n})\nexport type FeedbackInput = z.input<typeof FeedbackInputSchema>\n\nexport const CaptureInputSchema = z.object({\n namespace: z.string().min(1),\n sessionId: z.string().optional(),\n kind: EpisodeKindSchema,\n content: z.string().min(1),\n metadata: z.record(z.unknown()).default({}),\n extract: z.boolean().default(true).describe(\"run structured extraction into memories\"),\n})\nexport type CaptureInput = z.input<typeof CaptureInputSchema>\n\nexport const ContextInputSchema = z.object({\n namespaces: z.array(z.string()).min(1).describe(\"e.g. ['global', 'project:/repo']\"),\n maxItems: z.number().int().min(1).max(100).default(20),\n includePinned: z.boolean().default(true),\n includeRecent: z.boolean().default(true),\n})\nexport type ContextInput = z.input<typeof ContextInputSchema>\n\n// ---------------------------------------------------------------------------\n// Outputs\n// ---------------------------------------------------------------------------\n\nexport interface SearchHit {\n layer: \"memory\" | \"episode\"\n id: string\n /** higher is better */\n score: number\n snippet: string\n memory?: Memory\n episode?: Episode\n /**\n * which storage branch produced this candidate: \"fts\" = the trigram\n * index, \"like\" = the supplementary LIKE branch (the only branch that\n * can match a two-character word). The share of \"like\" hits tells\n * whether the fallback earns its keep.\n */\n branch?: \"fts\" | \"like\"\n /**\n * the kind of namespace the hit lives in (never the raw path). The\n * share of session-scoped hits at top ranks is the evidence for/against\n * a scope weight in the ranking.\n */\n nsKind?: \"global\" | \"project\" | \"session\" | \"other\"\n /**\n * true when the hit matches only expansion-added terms: without query\n * expansion this query would have found nothing. The share of these\n * hits measures what the concept table rescues.\n */\n expansionOnly?: boolean\n /** ids of co-surfacing memories that look conflicting (read-time annotation) */\n possibleConflictWith?: string[]\n}\n\nexport interface ContextBundle {\n text: string\n items: Array<{\n id: string\n type: MemoryType\n summary: string\n possibleConflictWith?: string[]\n }>\n}\n\nexport interface CaptureResult {\n episode: Episode\n deduplicated: boolean\n extracted: Memory[]\n}\n\n// ---------------------------------------------------------------------------\n// Conflict detection & resolution\n// ---------------------------------------------------------------------------\n\nexport interface ConflictCandidate {\n id: string\n type: MemoryType\n summary: string\n content: string\n importance: number\n createdAt: number\n}\n\nexport const ResolveConflictInputSchema = z.object({\n newId: z.string().describe(\"the newly saved memory\"),\n oldId: z.string().describe(\"the conflicting existing memory\"),\n action: z\n .enum([\"keep-new\", \"keep-old\", \"keep-both\"])\n .describe(\n \"keep-new: supersede the old one; keep-old: delete the new one; keep-both: leave both active\",\n ),\n})\nexport type ResolveConflictInput = z.input<typeof ResolveConflictInputSchema>\n"],"mappings":";AAAA,SAAS,SAAS;AAMX,IAAM,eAAe;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AACO,IAAM,mBAAmB,EAAE,KAAK,YAAY;AAG5C,IAAM,gBAAgB;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AACO,IAAM,oBAAoB,EAAE,KAAK,aAAa;AA6C9C,IAAM,wBAAwB,EAAE,OAAO;AAAA,EAC5C,WAAW,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EAC3B,MAAM;AAAA,EACN,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EACzB,SAAS,EAAE,OAAO,EAAE,SAAS;AAAA,EAC7B,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,CAAC;AAAA,EACpC,UAAU,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC;AAAA,EAC1C,YAAY,EAAE,OAAO,EAAE,IAAI,CAAC,EA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global") return "global";
|
|
4
|
+
if (namespace.startsWith("project:")) return "project";
|
|
5
|
+
if (namespace.startsWith("session:")) return "session";
|
|
6
|
+
return "other";
|
|
7
|
+
}
|
|
2
8
|
function normalizeProjectDir(dir) {
|
|
3
9
|
let out = dir.trim().replace(/\\/g, "/");
|
|
4
10
|
out = out.replace(/\/{2,}/g, "/");
|
|
@@ -39,6 +45,7 @@ function recallNamespaces(projectDir, sessionId) {
|
|
|
39
45
|
}
|
|
40
46
|
|
|
41
47
|
export {
|
|
48
|
+
namespaceKind,
|
|
42
49
|
normalizeProjectDir,
|
|
43
50
|
projectNamespace,
|
|
44
51
|
projectSlug,
|
|
@@ -46,4 +53,4 @@ export {
|
|
|
46
53
|
projectDirOf,
|
|
47
54
|
recallNamespaces
|
|
48
55
|
};
|
|
49
|
-
//# sourceMappingURL=chunk-
|
|
56
|
+
//# sourceMappingURL=chunk-5QLVGPLD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/scope.ts"],"sourcesContent":["import type { MemoryType } from \"../types.js\"\n\n/**\n * Memory scope model.\n *\n * global - shared by every project and session (hard rules about how to work)\n * project - shared by every session of one project (decisions, preferences)\n * session - visible only inside the session that produced it (activity log)\n *\n * Auto-extraction routes by durability: what should outlive the conversation\n * is written to a shared scope, what belongs to the conversation stays in the\n * session.\n *\n * Session scope is deliberately NOT shared. It holds the activity log -\n * commands run, files changed, compaction snapshots - and every later session\n * would have to sift through it inside a 3-slot recall budget. Project scope\n * is the unit of sharing: it is already visible to every session of that\n * repository, and it cannot leak into an unrelated one.\n */\nexport type Scope = \"global\" | \"project\" | \"session\"\n\n/**\n * The kind of a namespace, without exposing the raw (path-bearing) name.\n * A namespace kind is safe to log and to aggregate over: \"other\" covers\n * hand-written namespaces that follow none of the routing rules.\n */\nexport type NamespaceKind = \"global\" | \"project\" | \"session\" | \"other\"\n\nexport function namespaceKind(namespace: string): NamespaceKind {\n if (namespace === \"global\") return \"global\"\n if (namespace.startsWith(\"project:\")) return \"project\"\n if (namespace.startsWith(\"session:\")) return \"session\"\n return \"other\"\n}\n\n/**\n * Canonical form of a project directory: forward slashes, no trailing slash.\n *\n * The same project reaches geoplana with different separators depending on\n * the agent and the platform (\"D:\\\\repo\" vs \"D:/repo\"), and every variant\n * would otherwise become its own namespace. Case is preserved: on Windows it\n * is cosmetic, on Linux it is significant.\n */\nexport function normalizeProjectDir(dir: string): string {\n let out = dir.trim().replace(/\\\\/g, \"/\")\n out = out.replace(/\\/{2,}/g, \"/\")\n if (out.length > 1) out = out.replace(/\\/+$/, \"\")\n return out\n}\n\n/** The namespace a project's memories live in. */\nexport function projectNamespace(dir: string): string {\n return `project:${normalizeProjectDir(dir)}`\n}\n\n/** Last path segment of a project directory (the folder name). */\nexport function projectSlug(dir: string): string | null {\n const normalized = normalizeProjectDir(dir)\n if (!normalized) return null\n const parts = normalized.split(\"/\")\n const last = parts[parts.length - 1]\n return last && last !== \".\" && last !== \"..\" ? last : null\n}\n\n/**\n * Which scope a memory type belongs to.\n *\n * - decision / preference: about this project -> shared by its sessions\n * - instruction: about how to work -> shared by every project\n * - fact / error / context: about this conversation -> session only\n */\nexport function scopeForType(type: MemoryType): Scope {\n switch (type) {\n case \"decision\":\n case \"preference\":\n return \"project\"\n case \"instruction\":\n return \"global\"\n default:\n return \"session\"\n }\n}\n\n/** The project directory recorded on an episode or memory, if any. */\nexport function projectDirOf(metadata: Record<string, unknown>): string | undefined {\n const value = metadata.projectDir\n if (typeof value !== \"string\" || !value.trim()) return undefined\n return normalizeProjectDir(value)\n}\n\n/** The namespaces a session reads from: global + project + this session. */\nexport function recallNamespaces(projectDir?: string, sessionId?: string): string[] {\n const ns = [\"global\"]\n if (projectDir) ns.push(projectNamespace(projectDir))\n if (sessionId) ns.push(`session:${sessionId}`)\n return ns\n}\n"],"mappings":";AA4BO,SAAS,cAAc,WAAkC;AAC9D,MAAI,cAAc,SAAU,QAAO;AACnC,MAAI,UAAU,WAAW,UAAU,EAAG,QAAO;AAC7C,MAAI,UAAU,WAAW,UAAU,EAAG,QAAO;AAC7C,SAAO;AACT;AAUO,SAAS,oBAAoB,KAAqB;AACvD,MAAI,MAAM,IAAI,KAAK,EAAE,QAAQ,OAAO,GAAG;AACvC,QAAM,IAAI,QAAQ,WAAW,GAAG;AAChC,MAAI,IAAI,SAAS,EAAG,OAAM,IAAI,QAAQ,QAAQ,EAAE;AAChD,SAAO;AACT;AAGO,SAAS,iBAAiB,KAAqB;AACpD,SAAO,WAAW,oBAAoB,GAAG,CAAC;AAC5C;AAGO,SAAS,YAAY,KAA4B;AACtD,QAAM,aAAa,oBAAoB,GAAG;AAC1C,MAAI,CAAC,WAAY,QAAO;AACxB,QAAM,QAAQ,WAAW,MAAM,GAAG;AAClC,QAAM,OAAO,MAAM,MAAM,SAAS,CAAC;AACnC,SAAO,QAAQ,SAAS,OAAO,SAAS,OAAO,OAAO;AACxD;AASO,SAAS,aAAa,MAAyB;AACpD,UAAQ,MAAM;AAAA,IACZ,KAAK;AAAA,IACL,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EACX;AACF;AAGO,SAAS,aAAa,UAAuD;AAClF,QAAM,QAAQ,SAAS;AACvB,MAAI,OAAO,UAAU,YAAY,CAAC,MAAM,KAAK,EAAG,QAAO;AACvD,SAAO,oBAAoB,KAAK;AAClC;AAGO,SAAS,iBAAiB,YAAqB,WAA8B;AAClF,QAAM,KAAK,CAAC,QAAQ;AACpB,MAAI,WAAY,IAAG,KAAK,iBAAiB,UAAU,CAAC;AACpD,MAAI,UAAW,IAAG,KAAK,WAAW,SAAS,EAAE;AAC7C,SAAO;AACT;","names":[]}
|
|
@@ -7,7 +7,38 @@ var COUNTER_EVENTS = /* @__PURE__ */ new Set([
|
|
|
7
7
|
/** hits returned per search */
|
|
8
8
|
"search:hits",
|
|
9
9
|
/** conflicting memories reported per save */
|
|
10
|
-
"save:conflicts"
|
|
10
|
+
"save:conflicts",
|
|
11
|
+
/**
|
|
12
|
+
* a surfaced memory was used (explicit feedback or a deliberate fetch);
|
|
13
|
+
* the value is the rank it had in the search that surfaced it
|
|
14
|
+
*/
|
|
15
|
+
"recall:used",
|
|
16
|
+
/** explicit per-memory feedback */
|
|
17
|
+
"feedback:useful",
|
|
18
|
+
"feedback:useless",
|
|
19
|
+
/** candidates each extractor produced per captured episode */
|
|
20
|
+
"extract:decisionExtractor",
|
|
21
|
+
"extract:preferenceExtractor",
|
|
22
|
+
"extract:errorExtractor",
|
|
23
|
+
"extract:compactionExtractor",
|
|
24
|
+
/** promotion gate: a durable statement reached a shared scope */
|
|
25
|
+
"promote:shared",
|
|
26
|
+
/** promotion gate: a fragment stayed in the session scope */
|
|
27
|
+
"promote:blocked",
|
|
28
|
+
/** an exact-duplicate save was merged into the existing memory */
|
|
29
|
+
"save:merged",
|
|
30
|
+
/** a save replaced an older memory (churn) */
|
|
31
|
+
"save:supersedes",
|
|
32
|
+
/** conflict resolutions per action - the conflict-detection precision */
|
|
33
|
+
"resolve:keep-new",
|
|
34
|
+
"resolve:keep-old",
|
|
35
|
+
"resolve:keep-both",
|
|
36
|
+
/** retention activity per GC run */
|
|
37
|
+
"gc:compressed",
|
|
38
|
+
"gc:coldExported",
|
|
39
|
+
"gc:evicted",
|
|
40
|
+
"gc:activityLogs",
|
|
41
|
+
"gc:metricsPruned"
|
|
11
42
|
]);
|
|
12
43
|
function metricKind(event) {
|
|
13
44
|
return COUNTER_EVENTS.has(event) ? "counter" : "latency";
|
|
@@ -57,4 +88,4 @@ export {
|
|
|
57
88
|
metricKind,
|
|
58
89
|
aggregateMetrics
|
|
59
90
|
};
|
|
60
|
-
//# sourceMappingURL=chunk-
|
|
91
|
+
//# sourceMappingURL=chunk-CUOJUXUT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/metrics.ts"],"sourcesContent":["import type { MetricRow } from \"../storage/storage.js\"\n\n/**\n * What a metric row measures.\n *\n * - `latency`: the value is a duration in milliseconds\n * - `counter`: the value is an outcome count (hits, conflicts, ...)\n *\n * Both live in the same table and column, so the kind has to be explicit -\n * otherwise \"p95 = 1\" means \"1 ms\" for one event and \"1 hit\" for another.\n */\nexport type MetricKind = \"latency\" | \"counter\"\n\n/**\n * Events that record an outcome count rather than a duration.\n * Kept as a set (not a schema column) so the metric table stays unchanged.\n */\nexport const COUNTER_EVENTS = new Set([\n /** hits returned per recall */\n \"hook:recall:hits\",\n /** prompts too short to search */\n \"hook:recall:skipped\",\n /** hits returned per search */\n \"search:hits\",\n /** conflicting memories reported per save */\n \"save:conflicts\",\n /**\n * a surfaced memory was used (explicit feedback or a deliberate fetch);\n * the value is the rank it had in the search that surfaced it\n */\n \"recall:used\",\n /** explicit per-memory feedback */\n \"feedback:useful\",\n \"feedback:useless\",\n /** candidates each extractor produced per captured episode */\n \"extract:decisionExtractor\",\n \"extract:preferenceExtractor\",\n \"extract:errorExtractor\",\n \"extract:compactionExtractor\",\n /** promotion gate: a durable statement reached a shared scope */\n \"promote:shared\",\n /** promotion gate: a fragment stayed in the session scope */\n \"promote:blocked\",\n /** an exact-duplicate save was merged into the existing memory */\n \"save:merged\",\n /** a save replaced an older memory (churn) */\n \"save:supersedes\",\n /** conflict resolutions per action - the conflict-detection precision */\n \"resolve:keep-new\",\n \"resolve:keep-old\",\n \"resolve:keep-both\",\n /** retention activity per GC run */\n \"gc:compressed\",\n \"gc:coldExported\",\n \"gc:evicted\",\n \"gc:activityLogs\",\n \"gc:metricsPruned\",\n])\n\nexport function metricKind(event: string): MetricKind {\n return COUNTER_EVENTS.has(event) ? \"counter\" : \"latency\"\n}\n\nexport interface PerfSummary {\n event: string\n kind: MetricKind\n /** unit of the measured value: \"ms\" for latency, \"count\" for counters */\n unit: \"ms\" | \"count\"\n count: number\n /** mean of the measured values (rounded to 2 decimals) */\n mean: number\n min: number\n p50: number\n p95: number\n p99: number\n max: number\n /** counter events only: samples with value 0 (e.g. recalls that found nothing) */\n zeros?: number\n /** counter events only: share of samples with value 0 (0..1) */\n zeroRate?: number\n}\n\n/** nearest-rank percentile on a sorted-ascending sample list */\nfunction percentile(sorted: number[], p: number): number {\n if (sorted.length === 0) return 0\n const idx = Math.min(sorted.length - 1, Math.max(0, Math.ceil((p / 100) * sorted.length) - 1))\n return sorted[idx]!\n}\n\nfunction round2(n: number): number {\n return Math.round(n * 100) / 100\n}\n\n/**\n * Group metric samples by event and compute summary statistics.\n * Used by `geoplana stats --perf` and the `memory_stats` MCP tool.\n *\n * Latency events report duration percentiles; counter events report the\n * outcome distribution plus the zero rate, which is the production signal\n * for recall quality (a rising zero rate means the retrieval is missing).\n */\nexport function aggregateMetrics(rows: MetricRow[]): PerfSummary[] {\n const groups = new Map<string, number[]>()\n for (const row of rows) {\n const list = groups.get(row.event) ?? []\n list.push(row.durationMs)\n groups.set(row.event, list)\n }\n return [...groups.entries()]\n .map(([event, values]) => {\n const sorted = [...values].sort((a, b) => a - b)\n const sum = sorted.reduce((acc, v) => acc + v, 0)\n const kind = metricKind(event)\n const summary: PerfSummary = {\n event,\n kind,\n unit: kind === \"counter\" ? \"count\" : \"ms\",\n count: sorted.length,\n mean: round2(sorted.length > 0 ? sum / sorted.length : 0),\n min: sorted.length > 0 ? sorted[0]! : 0,\n p50: percentile(sorted, 50),\n p95: percentile(sorted, 95),\n p99: percentile(sorted, 99),\n max: sorted.length > 0 ? sorted[sorted.length - 1]! : 0,\n }\n if (kind === \"counter\") {\n const zeros = sorted.filter((v) => v === 0).length\n summary.zeros = zeros\n summary.zeroRate = round2(sorted.length > 0 ? zeros / sorted.length : 0)\n }\n return summary\n })\n .sort((a, b) => a.event.localeCompare(b.event))\n}\n"],"mappings":";AAiBO,IAAM,iBAAiB,oBAAI,IAAI;AAAA;AAAA,EAEpC;AAAA;AAAA,EAEA;AAAA;AAAA,EAEA;AAAA;AAAA,EAEA;AAAA;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA;AAAA,EAEA;AAAA,EACA;AAAA;A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AAS,CAAC;AAAA,MACxD,KAAK,OAAO,SAAS,IAAI,OAAO,CAAC,IAAK;AAAA,MACtC,KAAK,WAAW,QAAQ,EAAE;AAAA,MAC1B,KAAK,WAAW,QAAQ,EAAE;AAAA,MAC1B,KAAK,WAAW,QAAQ,EAAE;AAAA,MAC1B,KAAK,OAAO,SAAS,IAAI,OAAO,OAAO,SAAS,CAAC,IAAK;AAAA,IACxD;AACA,QAAI,SAAS,WAAW;AACtB,YAAM,QAAQ,OAAO,OAAO,CAAC,MAAM,MAAM,CAAC,EAAE;AAC5C,cAAQ,QAAQ;AAChB,cAAQ,WAAW,OAAO,OAAO,SAAS,IAAI,QAAQ,OAAO,SAAS,CAAC;AAAA,IACzE;AACA,WAAO;AAAA,EACT,CAAC,EACA,KAAK,CAAC,GAAG,MAAM,EAAE,MAAM,cAAc,EAAE,KAAK,CAAC;AAClD;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
recallNamespaces
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-5QLVGPLD.js";
|
|
4
4
|
|
|
5
5
|
// src/hooks/events.ts
|
|
6
6
|
import { existsSync, readFileSync } from "fs";
|
|
@@ -101,4 +101,4 @@ export {
|
|
|
101
101
|
normalizeClaudePayload,
|
|
102
102
|
readTranscript
|
|
103
103
|
};
|
|
104
|
-
//# sourceMappingURL=chunk-
|
|
104
|
+
//# sourceMappingURL=chunk-LSGK3SKU.js.map
|