@chendpoc/pi-memory 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.
Files changed (177) hide show
  1. package/README.md +180 -0
  2. package/dist/adapters/piComplete.d.ts +17 -0
  3. package/dist/adapters/piComplete.d.ts.map +1 -0
  4. package/dist/adapters/piComplete.js +169 -0
  5. package/dist/adapters/piComplete.js.map +1 -0
  6. package/dist/bundle/install.d.ts +34 -0
  7. package/dist/bundle/install.d.ts.map +1 -0
  8. package/dist/bundle/install.js +183 -0
  9. package/dist/bundle/install.js.map +1 -0
  10. package/dist/cli.d.ts +3 -0
  11. package/dist/cli.d.ts.map +1 -0
  12. package/dist/cli.js +245 -0
  13. package/dist/cli.js.map +1 -0
  14. package/dist/config.d.ts +27 -0
  15. package/dist/config.d.ts.map +1 -0
  16. package/dist/config.js +49 -0
  17. package/dist/config.js.map +1 -0
  18. package/dist/errclass.d.ts +7 -0
  19. package/dist/errclass.d.ts.map +1 -0
  20. package/dist/errclass.js +32 -0
  21. package/dist/errclass.js.map +1 -0
  22. package/dist/extension.d.ts +24 -0
  23. package/dist/extension.d.ts.map +1 -0
  24. package/dist/extension.js +7 -0
  25. package/dist/extension.js.map +1 -0
  26. package/dist/fallback/index.d.ts +11 -0
  27. package/dist/fallback/index.d.ts.map +1 -0
  28. package/dist/fallback/index.js +16 -0
  29. package/dist/fallback/index.js.map +1 -0
  30. package/dist/fallback/llmRerank.d.ts +19 -0
  31. package/dist/fallback/llmRerank.d.ts.map +1 -0
  32. package/dist/fallback/llmRerank.js +60 -0
  33. package/dist/fallback/llmRerank.js.map +1 -0
  34. package/dist/fallback/memoryMd.d.ts +6 -0
  35. package/dist/fallback/memoryMd.d.ts.map +1 -0
  36. package/dist/fallback/memoryMd.js +35 -0
  37. package/dist/fallback/memoryMd.js.map +1 -0
  38. package/dist/fallback/sessionIndex.d.ts +35 -0
  39. package/dist/fallback/sessionIndex.d.ts.map +1 -0
  40. package/dist/fallback/sessionIndex.js +222 -0
  41. package/dist/fallback/sessionIndex.js.map +1 -0
  42. package/dist/fallback/sessionSearch.d.ts +18 -0
  43. package/dist/fallback/sessionSearch.d.ts.map +1 -0
  44. package/dist/fallback/sessionSearch.js +161 -0
  45. package/dist/fallback/sessionSearch.js.map +1 -0
  46. package/dist/index.d.ts +25 -0
  47. package/dist/index.d.ts.map +1 -0
  48. package/dist/index.js +24 -0
  49. package/dist/index.js.map +1 -0
  50. package/dist/paths.d.ts +7 -0
  51. package/dist/paths.d.ts.map +1 -0
  52. package/dist/paths.js +26 -0
  53. package/dist/paths.js.map +1 -0
  54. package/dist/pi-extension.d.ts +6 -0
  55. package/dist/pi-extension.d.ts.map +1 -0
  56. package/dist/pi-extension.js +224 -0
  57. package/dist/pi-extension.js.map +1 -0
  58. package/dist/preflight/detectIntents.d.ts +102 -0
  59. package/dist/preflight/detectIntents.d.ts.map +1 -0
  60. package/dist/preflight/detectIntents.js +624 -0
  61. package/dist/preflight/detectIntents.js.map +1 -0
  62. package/dist/preflight/hook.d.ts +58 -0
  63. package/dist/preflight/hook.d.ts.map +1 -0
  64. package/dist/preflight/hook.js +77 -0
  65. package/dist/preflight/hook.js.map +1 -0
  66. package/dist/preflight/render.d.ts +21 -0
  67. package/dist/preflight/render.d.ts.map +1 -0
  68. package/dist/preflight/render.js +132 -0
  69. package/dist/preflight/render.js.map +1 -0
  70. package/dist/preflight/strip.d.ts +11 -0
  71. package/dist/preflight/strip.d.ts.map +1 -0
  72. package/dist/preflight/strip.js +46 -0
  73. package/dist/preflight/strip.js.map +1 -0
  74. package/dist/service.d.ts +56 -0
  75. package/dist/service.d.ts.map +1 -0
  76. package/dist/service.js +158 -0
  77. package/dist/service.js.map +1 -0
  78. package/dist/sidecar/bundle.d.ts +19 -0
  79. package/dist/sidecar/bundle.d.ts.map +1 -0
  80. package/dist/sidecar/bundle.js +39 -0
  81. package/dist/sidecar/bundle.js.map +1 -0
  82. package/dist/sidecar/client.d.ts +17 -0
  83. package/dist/sidecar/client.d.ts.map +1 -0
  84. package/dist/sidecar/client.js +107 -0
  85. package/dist/sidecar/client.js.map +1 -0
  86. package/dist/sidecar/process.d.ts +14 -0
  87. package/dist/sidecar/process.d.ts.map +1 -0
  88. package/dist/sidecar/process.js +126 -0
  89. package/dist/sidecar/process.js.map +1 -0
  90. package/dist/tools/memoryAppend.d.ts +37 -0
  91. package/dist/tools/memoryAppend.d.ts.map +1 -0
  92. package/dist/tools/memoryAppend.js +99 -0
  93. package/dist/tools/memoryAppend.js.map +1 -0
  94. package/dist/tools/memoryRecall.d.ts +113 -0
  95. package/dist/tools/memoryRecall.d.ts.map +1 -0
  96. package/dist/tools/memoryRecall.js +325 -0
  97. package/dist/tools/memoryRecall.js.map +1 -0
  98. package/dist/trainer/bundleBuilder.d.ts +30 -0
  99. package/dist/trainer/bundleBuilder.d.ts.map +1 -0
  100. package/dist/trainer/bundleBuilder.js +106 -0
  101. package/dist/trainer/bundleBuilder.js.map +1 -0
  102. package/dist/trainer/bundleLoader.d.ts +12 -0
  103. package/dist/trainer/bundleLoader.d.ts.map +1 -0
  104. package/dist/trainer/bundleLoader.js +59 -0
  105. package/dist/trainer/bundleLoader.js.map +1 -0
  106. package/dist/trainer/deltaMerge.d.ts +38 -0
  107. package/dist/trainer/deltaMerge.d.ts.map +1 -0
  108. package/dist/trainer/deltaMerge.js +183 -0
  109. package/dist/trainer/deltaMerge.js.map +1 -0
  110. package/dist/trainer/entityResolver.d.ts +27 -0
  111. package/dist/trainer/entityResolver.d.ts.map +1 -0
  112. package/dist/trainer/entityResolver.js +92 -0
  113. package/dist/trainer/entityResolver.js.map +1 -0
  114. package/dist/trainer/extractFacts.d.ts +67 -0
  115. package/dist/trainer/extractFacts.d.ts.map +1 -0
  116. package/dist/trainer/extractFacts.js +213 -0
  117. package/dist/trainer/extractFacts.js.map +1 -0
  118. package/dist/trainer/index.d.ts +54 -0
  119. package/dist/trainer/index.d.ts.map +1 -0
  120. package/dist/trainer/index.js +82 -0
  121. package/dist/trainer/index.js.map +1 -0
  122. package/dist/trainer/llmExtractor.d.ts +16 -0
  123. package/dist/trainer/llmExtractor.d.ts.map +1 -0
  124. package/dist/trainer/llmExtractor.js +146 -0
  125. package/dist/trainer/llmExtractor.js.map +1 -0
  126. package/dist/trainer/marker.d.ts +10 -0
  127. package/dist/trainer/marker.d.ts.map +1 -0
  128. package/dist/trainer/marker.js +28 -0
  129. package/dist/trainer/marker.js.map +1 -0
  130. package/dist/trainer/scheduler.d.ts +31 -0
  131. package/dist/trainer/scheduler.d.ts.map +1 -0
  132. package/dist/trainer/scheduler.js +72 -0
  133. package/dist/trainer/scheduler.js.map +1 -0
  134. package/dist/trainer/sessionLoader.d.ts +23 -0
  135. package/dist/trainer/sessionLoader.d.ts.map +1 -0
  136. package/dist/trainer/sessionLoader.js +106 -0
  137. package/dist/trainer/sessionLoader.js.map +1 -0
  138. package/dist/types.d.ts +135 -0
  139. package/dist/types.d.ts.map +1 -0
  140. package/dist/types.js +8 -0
  141. package/dist/types.js.map +1 -0
  142. package/package.json +78 -0
  143. package/src/adapters/piComplete.ts +233 -0
  144. package/src/bundle/install.ts +206 -0
  145. package/src/cli.ts +254 -0
  146. package/src/config.ts +92 -0
  147. package/src/errclass.ts +37 -0
  148. package/src/extension.ts +23 -0
  149. package/src/fallback/index.ts +24 -0
  150. package/src/fallback/llmRerank.ts +90 -0
  151. package/src/fallback/memoryMd.ts +36 -0
  152. package/src/fallback/sessionIndex.ts +289 -0
  153. package/src/fallback/sessionSearch.ts +181 -0
  154. package/src/index.ts +213 -0
  155. package/src/paths.ts +28 -0
  156. package/src/pi-extension.ts +276 -0
  157. package/src/preflight/detectIntents.ts +654 -0
  158. package/src/preflight/hook.ts +136 -0
  159. package/src/preflight/render.ts +185 -0
  160. package/src/preflight/strip.ts +50 -0
  161. package/src/service.ts +202 -0
  162. package/src/sidecar/bundle.ts +52 -0
  163. package/src/sidecar/client.ts +166 -0
  164. package/src/sidecar/process.ts +145 -0
  165. package/src/tools/memoryAppend.ts +113 -0
  166. package/src/tools/memoryRecall.ts +364 -0
  167. package/src/trainer/bundleBuilder.ts +192 -0
  168. package/src/trainer/bundleLoader.ts +105 -0
  169. package/src/trainer/deltaMerge.ts +221 -0
  170. package/src/trainer/entityResolver.ts +140 -0
  171. package/src/trainer/extractFacts.ts +312 -0
  172. package/src/trainer/index.ts +147 -0
  173. package/src/trainer/llmExtractor.ts +206 -0
  174. package/src/trainer/marker.ts +30 -0
  175. package/src/trainer/scheduler.ts +104 -0
  176. package/src/trainer/sessionLoader.ts +139 -0
  177. package/src/types.ts +168 -0
package/src/types.ts ADDED
@@ -0,0 +1,168 @@
1
+ /** Wire types mirroring Kocoro internal/memory/types.go (TLM sidecar contract). */
2
+
3
+ export type QueryMode =
4
+ | "direct_relation"
5
+ | "path_query"
6
+ | "typed_neighborhood";
7
+
8
+ export interface QueryIntent {
9
+ mode: QueryMode;
10
+ anchor_mentions: string[];
11
+ relation_constraints?: string[];
12
+ candidate_type?: string | null;
13
+ scope_filter?: string[];
14
+ target_slot?: "" | "head" | "tail";
15
+ time_window?: string | null;
16
+ evidence_budget?: number;
17
+ result_limit?: number;
18
+ }
19
+
20
+ export interface QueryRequest {
21
+ intent: QueryIntent;
22
+ user_id?: string | null;
23
+ request_id?: string | null;
24
+ }
25
+
26
+ export interface HopRecord {
27
+ from_entity_id: string;
28
+ from_label: string;
29
+ relation: string;
30
+ direction: string;
31
+ to_entity_id: string;
32
+ to_label: string;
33
+ supporting_event_ids: string[];
34
+ }
35
+
36
+ export interface QueryCandidate {
37
+ value: string;
38
+ score: number;
39
+ evidence: string;
40
+ supporting_event_ids: string[];
41
+ support_count?: number | null;
42
+ distinct_session_count?: number | null;
43
+ entity_id?: string | null;
44
+ scope?: string | null;
45
+ observed_path?: HopRecord[];
46
+ path_collision_count?: number;
47
+ }
48
+
49
+ export interface MemoryCandidateGroup {
50
+ value: string;
51
+ score: number;
52
+ evidence: string;
53
+ support_count: number;
54
+ supporting_event_ids: string[];
55
+ entity_ids: string[];
56
+ scopes: string[];
57
+ via_relations: string[];
58
+ via_anchor_entity_ids: string[];
59
+ observed_path: HopRecord[];
60
+ path_collision_count: number;
61
+ }
62
+
63
+ export interface MemoryBlock {
64
+ groups: MemoryCandidateGroup[];
65
+ no_data_reason?: string | null;
66
+ notes: string[];
67
+ }
68
+
69
+ export interface Warning {
70
+ code: string;
71
+ message: string;
72
+ }
73
+
74
+ export interface ErrorObject {
75
+ code: string;
76
+ message: string;
77
+ details?: Record<string, unknown>;
78
+ }
79
+
80
+ export function errorSubCode(err: ErrorObject | null | undefined): string {
81
+ if (!err?.details) return "";
82
+ const v = err.details.sub_code;
83
+ return typeof v === "string" ? v : "";
84
+ }
85
+
86
+ export interface ResponseEnvelope {
87
+ protocol_version: number;
88
+ bundle_version?: string;
89
+ bundle_created_at?: string | null;
90
+ bundle_dir?: string;
91
+ request_id: string;
92
+ candidates: QueryCandidate[];
93
+ memory_block?: MemoryBlock | null;
94
+ warnings: Warning[];
95
+ reason: string;
96
+ error?: ErrorObject | null;
97
+ latency_ms: number;
98
+ }
99
+
100
+ export interface ReloadResponse {
101
+ protocol_version: number;
102
+ request_id: string;
103
+ swapped: boolean;
104
+ trigger: string;
105
+ reason: string;
106
+ previous_bundle_dir?: string | null;
107
+ current_bundle_dir?: string | null;
108
+ reload_duration_ms: number;
109
+ warnings: Warning[];
110
+ error?: ErrorObject | null;
111
+ }
112
+
113
+ export interface HealthPayload {
114
+ ready: boolean;
115
+ compatibility: string;
116
+ bundle_version?: string;
117
+ bundle_created_at?: string | null;
118
+ bundle_dir?: string;
119
+ last_reload_age_secs?: number | null;
120
+ last_reload_trigger?: string | null;
121
+ protocol_version: number;
122
+ uptime_secs: number;
123
+ error?: ErrorObject | null;
124
+ status_message?: string;
125
+ }
126
+
127
+ export type ServiceStatus =
128
+ | "disabled"
129
+ | "initializing"
130
+ | "ready"
131
+ | "degraded"
132
+ | "unavailable";
133
+
134
+ export interface MemoryRecallArgs {
135
+ mode?: string;
136
+ anchor_mentions: string[];
137
+ relation_constraints?: string[];
138
+ candidate_type?: string | null;
139
+ scope_filter?: string[];
140
+ target_slot?: string;
141
+ time_window?: string | null;
142
+ evidence_budget?: number;
143
+ result_limit?: number;
144
+ }
145
+
146
+ export interface ToolResult {
147
+ content: string;
148
+ isError?: boolean;
149
+ }
150
+
151
+ export type ErrorClass = "ok" | "retryable" | "permanent" | "unavailable";
152
+
153
+ export interface MemoryQuerier {
154
+ status(): ServiceStatus;
155
+ query(
156
+ intent: QueryIntent,
157
+ signal?: AbortSignal,
158
+ ): Promise<{
159
+ env: ResponseEnvelope | null;
160
+ errorClass: ErrorClass;
161
+ transportError?: Error;
162
+ }>;
163
+ }
164
+
165
+ export interface FallbackQuery {
166
+ sessionKeyword(query: string, limit: number): Promise<unknown[]>;
167
+ memoryFileSnippet(query: string): Promise<string>;
168
+ }