opencode-graphiti 0.0.0-development

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 (179) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +358 -0
  3. package/esm/_dnt.polyfills.d.ts +166 -0
  4. package/esm/_dnt.polyfills.d.ts.map +1 -0
  5. package/esm/_dnt.polyfills.js +177 -0
  6. package/esm/_dnt.shims.d.ts +6 -0
  7. package/esm/_dnt.shims.d.ts.map +1 -0
  8. package/esm/_dnt.shims.js +61 -0
  9. package/esm/deno.d.ts +45 -0
  10. package/esm/deno.d.ts.map +1 -0
  11. package/esm/deno.js +39 -0
  12. package/esm/mod.d.ts +3 -0
  13. package/esm/mod.d.ts.map +1 -0
  14. package/esm/mod.js +2 -0
  15. package/esm/package.json +3 -0
  16. package/esm/src/config.d.ts +20 -0
  17. package/esm/src/config.d.ts.map +1 -0
  18. package/esm/src/config.js +246 -0
  19. package/esm/src/handlers/chat.d.ts +14 -0
  20. package/esm/src/handlers/chat.d.ts.map +1 -0
  21. package/esm/src/handlers/chat.js +60 -0
  22. package/esm/src/handlers/compacting.d.ts +9 -0
  23. package/esm/src/handlers/compacting.d.ts.map +1 -0
  24. package/esm/src/handlers/compacting.js +30 -0
  25. package/esm/src/handlers/event.d.ts +22 -0
  26. package/esm/src/handlers/event.d.ts.map +1 -0
  27. package/esm/src/handlers/event.js +287 -0
  28. package/esm/src/handlers/messages.d.ts +9 -0
  29. package/esm/src/handlers/messages.d.ts.map +1 -0
  30. package/esm/src/handlers/messages.js +93 -0
  31. package/esm/src/index.d.ts +5 -0
  32. package/esm/src/index.d.ts.map +1 -0
  33. package/esm/src/index.js +153 -0
  34. package/esm/src/services/batch-drain.d.ts +23 -0
  35. package/esm/src/services/batch-drain.d.ts.map +1 -0
  36. package/esm/src/services/batch-drain.js +217 -0
  37. package/esm/src/services/connection-manager.d.ts +104 -0
  38. package/esm/src/services/connection-manager.d.ts.map +1 -0
  39. package/esm/src/services/connection-manager.js +621 -0
  40. package/esm/src/services/constants.d.ts +7 -0
  41. package/esm/src/services/constants.d.ts.map +1 -0
  42. package/esm/src/services/constants.js +6 -0
  43. package/esm/src/services/context-limit.d.ts +3 -0
  44. package/esm/src/services/context-limit.d.ts.map +1 -0
  45. package/esm/src/services/context-limit.js +44 -0
  46. package/esm/src/services/event-extractor.d.ts +29 -0
  47. package/esm/src/services/event-extractor.d.ts.map +1 -0
  48. package/esm/src/services/event-extractor.js +659 -0
  49. package/esm/src/services/graphiti-async.d.ts +22 -0
  50. package/esm/src/services/graphiti-async.d.ts.map +1 -0
  51. package/esm/src/services/graphiti-async.js +219 -0
  52. package/esm/src/services/graphiti-mcp.d.ts +57 -0
  53. package/esm/src/services/graphiti-mcp.d.ts.map +1 -0
  54. package/esm/src/services/graphiti-mcp.js +194 -0
  55. package/esm/src/services/logger.d.ts +9 -0
  56. package/esm/src/services/logger.d.ts.map +1 -0
  57. package/esm/src/services/logger.js +104 -0
  58. package/esm/src/services/opencode-warning.d.ts +8 -0
  59. package/esm/src/services/opencode-warning.d.ts.map +1 -0
  60. package/esm/src/services/opencode-warning.js +104 -0
  61. package/esm/src/services/redis-cache.d.ts +27 -0
  62. package/esm/src/services/redis-cache.d.ts.map +1 -0
  63. package/esm/src/services/redis-cache.js +215 -0
  64. package/esm/src/services/redis-client.d.ts +89 -0
  65. package/esm/src/services/redis-client.d.ts.map +1 -0
  66. package/esm/src/services/redis-client.js +906 -0
  67. package/esm/src/services/redis-events.d.ts +46 -0
  68. package/esm/src/services/redis-events.d.ts.map +1 -0
  69. package/esm/src/services/redis-events.js +517 -0
  70. package/esm/src/services/redis-snapshot.d.ts +16 -0
  71. package/esm/src/services/redis-snapshot.d.ts.map +1 -0
  72. package/esm/src/services/redis-snapshot.js +184 -0
  73. package/esm/src/services/render-utils.d.ts +23 -0
  74. package/esm/src/services/render-utils.d.ts.map +1 -0
  75. package/esm/src/services/render-utils.js +149 -0
  76. package/esm/src/services/runtime-teardown.d.ts +23 -0
  77. package/esm/src/services/runtime-teardown.d.ts.map +1 -0
  78. package/esm/src/services/runtime-teardown.js +119 -0
  79. package/esm/src/services/sdk-normalize.d.ts +55 -0
  80. package/esm/src/services/sdk-normalize.d.ts.map +1 -0
  81. package/esm/src/services/sdk-normalize.js +61 -0
  82. package/esm/src/session.d.ts +74 -0
  83. package/esm/src/session.d.ts.map +1 -0
  84. package/esm/src/session.js +694 -0
  85. package/esm/src/types/index.d.ts +120 -0
  86. package/esm/src/types/index.d.ts.map +1 -0
  87. package/esm/src/types/index.js +28 -0
  88. package/esm/src/utils.d.ts +27 -0
  89. package/esm/src/utils.d.ts.map +1 -0
  90. package/esm/src/utils.js +76 -0
  91. package/package.json +59 -0
  92. package/script/_dnt.polyfills.d.ts +166 -0
  93. package/script/_dnt.polyfills.d.ts.map +1 -0
  94. package/script/_dnt.polyfills.js +180 -0
  95. package/script/_dnt.shims.d.ts +6 -0
  96. package/script/_dnt.shims.d.ts.map +1 -0
  97. package/script/_dnt.shims.js +65 -0
  98. package/script/deno.d.ts +45 -0
  99. package/script/deno.d.ts.map +1 -0
  100. package/script/deno.js +41 -0
  101. package/script/mod.d.ts +3 -0
  102. package/script/mod.d.ts.map +1 -0
  103. package/script/mod.js +6 -0
  104. package/script/package.json +3 -0
  105. package/script/src/config.d.ts +20 -0
  106. package/script/src/config.d.ts.map +1 -0
  107. package/script/src/config.js +256 -0
  108. package/script/src/handlers/chat.d.ts +14 -0
  109. package/script/src/handlers/chat.d.ts.map +1 -0
  110. package/script/src/handlers/chat.js +63 -0
  111. package/script/src/handlers/compacting.d.ts +9 -0
  112. package/script/src/handlers/compacting.d.ts.map +1 -0
  113. package/script/src/handlers/compacting.js +33 -0
  114. package/script/src/handlers/event.d.ts +22 -0
  115. package/script/src/handlers/event.d.ts.map +1 -0
  116. package/script/src/handlers/event.js +290 -0
  117. package/script/src/handlers/messages.d.ts +9 -0
  118. package/script/src/handlers/messages.d.ts.map +1 -0
  119. package/script/src/handlers/messages.js +96 -0
  120. package/script/src/index.d.ts +5 -0
  121. package/script/src/index.d.ts.map +1 -0
  122. package/script/src/index.js +159 -0
  123. package/script/src/services/batch-drain.d.ts +23 -0
  124. package/script/src/services/batch-drain.d.ts.map +1 -0
  125. package/script/src/services/batch-drain.js +221 -0
  126. package/script/src/services/connection-manager.d.ts +104 -0
  127. package/script/src/services/connection-manager.d.ts.map +1 -0
  128. package/script/src/services/connection-manager.js +635 -0
  129. package/script/src/services/constants.d.ts +7 -0
  130. package/script/src/services/constants.d.ts.map +1 -0
  131. package/script/src/services/constants.js +9 -0
  132. package/script/src/services/context-limit.d.ts +3 -0
  133. package/script/src/services/context-limit.d.ts.map +1 -0
  134. package/script/src/services/context-limit.js +47 -0
  135. package/script/src/services/event-extractor.d.ts +29 -0
  136. package/script/src/services/event-extractor.d.ts.map +1 -0
  137. package/script/src/services/event-extractor.js +669 -0
  138. package/script/src/services/graphiti-async.d.ts +22 -0
  139. package/script/src/services/graphiti-async.d.ts.map +1 -0
  140. package/script/src/services/graphiti-async.js +223 -0
  141. package/script/src/services/graphiti-mcp.d.ts +57 -0
  142. package/script/src/services/graphiti-mcp.d.ts.map +1 -0
  143. package/script/src/services/graphiti-mcp.js +198 -0
  144. package/script/src/services/logger.d.ts +9 -0
  145. package/script/src/services/logger.d.ts.map +1 -0
  146. package/script/src/services/logger.js +142 -0
  147. package/script/src/services/opencode-warning.d.ts +8 -0
  148. package/script/src/services/opencode-warning.d.ts.map +1 -0
  149. package/script/src/services/opencode-warning.js +114 -0
  150. package/script/src/services/redis-cache.d.ts +27 -0
  151. package/script/src/services/redis-cache.d.ts.map +1 -0
  152. package/script/src/services/redis-cache.js +219 -0
  153. package/script/src/services/redis-client.d.ts +89 -0
  154. package/script/src/services/redis-client.d.ts.map +1 -0
  155. package/script/src/services/redis-client.js +943 -0
  156. package/script/src/services/redis-events.d.ts +46 -0
  157. package/script/src/services/redis-events.d.ts.map +1 -0
  158. package/script/src/services/redis-events.js +535 -0
  159. package/script/src/services/redis-snapshot.d.ts +16 -0
  160. package/script/src/services/redis-snapshot.d.ts.map +1 -0
  161. package/script/src/services/redis-snapshot.js +189 -0
  162. package/script/src/services/render-utils.d.ts +23 -0
  163. package/script/src/services/render-utils.d.ts.map +1 -0
  164. package/script/src/services/render-utils.js +165 -0
  165. package/script/src/services/runtime-teardown.d.ts +23 -0
  166. package/script/src/services/runtime-teardown.d.ts.map +1 -0
  167. package/script/src/services/runtime-teardown.js +155 -0
  168. package/script/src/services/sdk-normalize.d.ts +55 -0
  169. package/script/src/services/sdk-normalize.d.ts.map +1 -0
  170. package/script/src/services/sdk-normalize.js +67 -0
  171. package/script/src/session.d.ts +74 -0
  172. package/script/src/session.d.ts.map +1 -0
  173. package/script/src/session.js +698 -0
  174. package/script/src/types/index.d.ts +120 -0
  175. package/script/src/types/index.d.ts.map +1 -0
  176. package/script/src/types/index.js +33 -0
  177. package/script/src/utils.d.ts +27 -0
  178. package/script/src/utils.d.ts.map +1 -0
  179. package/script/src/utils.js +87 -0
@@ -0,0 +1,120 @@
1
+ /** Redis hot-tier configuration. */
2
+ export interface RedisConfig {
3
+ endpoint: string;
4
+ batchSize: number;
5
+ batchMaxBytes: number;
6
+ sessionTtlSeconds: number;
7
+ cacheTtlSeconds: number;
8
+ drainRetryMax: number;
9
+ }
10
+ /** Legacy nested FalkorDB compatibility config. */
11
+ export interface FalkorDbConfig {
12
+ redisEndpoint?: string;
13
+ batchSize?: number;
14
+ batchMaxBytes?: number;
15
+ sessionTtlSeconds?: number;
16
+ cacheTtlSeconds?: number;
17
+ drainRetryMax?: number;
18
+ }
19
+ /** Graphiti async-tier configuration. */
20
+ export interface GraphitiServiceConfig {
21
+ endpoint: string;
22
+ groupIdPrefix: string;
23
+ driftThreshold: number;
24
+ }
25
+ /** Plugin configuration for hot-tier + Graphiti async integration. */
26
+ export interface GraphitiConfig {
27
+ redis: RedisConfig;
28
+ graphiti: GraphitiServiceConfig;
29
+ falkordb?: FalkorDbConfig;
30
+ endpoint?: string;
31
+ groupIdPrefix?: string;
32
+ driftThreshold?: number;
33
+ }
34
+ /** A fact retrieved from the Graphiti knowledge graph. */
35
+ export interface GraphitiFact {
36
+ uuid: string;
37
+ fact: string;
38
+ valid_at?: string;
39
+ invalid_at?: string;
40
+ source_node?: {
41
+ name: string;
42
+ uuid: string;
43
+ };
44
+ target_node?: {
45
+ name: string;
46
+ uuid: string;
47
+ };
48
+ }
49
+ /** A node retrieved from the Graphiti knowledge graph. */
50
+ export interface GraphitiNode {
51
+ uuid: string;
52
+ name: string;
53
+ summary?: string;
54
+ labels?: string[];
55
+ }
56
+ /** A recent episode retrieved from Graphiti memory. */
57
+ export interface GraphitiEpisode {
58
+ uuid: string;
59
+ name: string;
60
+ content: string;
61
+ source?: string;
62
+ sourceDescription?: string;
63
+ created_at?: string;
64
+ labels?: string[];
65
+ }
66
+ export type EventCategory = "task.create" | "task.update" | "task.complete" | "decision" | "preference" | "rule.load" | "file.read" | "file.write" | "file.edit" | "file.search" | "cwd.change" | "env.change" | "git.activity" | "error" | "subagent.start" | "subagent.finish" | "integration.call" | "intent" | "data.import" | "discovery" | "message" | "session.meta";
67
+ export type SessionEventSourceKind = "user-request" | "assistant-response" | "tool-activity" | "system-state";
68
+ export interface SessionEvent {
69
+ id: string;
70
+ ts: number;
71
+ category: EventCategory;
72
+ priority: 0 | 1 | 2 | 3 | 4;
73
+ role: "user" | "assistant" | "tool" | "system";
74
+ summary: string;
75
+ body?: string;
76
+ detail?: string;
77
+ continuityText?: string;
78
+ keywords?: string[];
79
+ sourceKind?: SessionEventSourceKind;
80
+ refs?: string[];
81
+ metadata?: Record<string, unknown>;
82
+ }
83
+ export declare const getSessionEventPrimaryText: (event: SessionEvent, fallback?: string) => string;
84
+ export declare const getSessionEventRecallText: (event: SessionEvent) => string;
85
+ export interface PersistentMemoryCacheEntry {
86
+ query: string;
87
+ refreshedAt: number;
88
+ nodes: GraphitiNode[];
89
+ episodeSummaries?: string[];
90
+ nodeRefs: string[];
91
+ }
92
+ export interface PersistentMemoryCacheMeta {
93
+ lastQuery?: string;
94
+ lastRefresh?: number;
95
+ }
96
+ export type CacheRefreshClassification = "miss" | "stale" | "primer-only" | "aligned" | "drifted";
97
+ export interface CacheRefreshDecision {
98
+ classification: CacheRefreshClassification;
99
+ shouldRefresh: boolean;
100
+ similarity: number;
101
+ threshold: number;
102
+ cachedQuery: string | null;
103
+ }
104
+ export interface DrainQueueEntry {
105
+ sessionId: string;
106
+ groupId: string;
107
+ event: SessionEvent;
108
+ }
109
+ export interface ClaimedDrainBatch {
110
+ claimToken: string;
111
+ claimKey: string;
112
+ lockTtlSeconds: number;
113
+ entries: DrainQueueEntry[];
114
+ }
115
+ export interface PreparedSessionMemory {
116
+ envelope: string;
117
+ nodeRefs: string[];
118
+ refreshDecision: CacheRefreshDecision;
119
+ }
120
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/types/index.ts"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,mDAAmD;AACnD,MAAM,WAAW,cAAc;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,yCAAyC;AACzC,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAA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ED,MAAM,WAAW,yBAAyB;IACxC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,MAAM,0BAA0B,GAClC,MAAM,GACN,OAAO,GACP,aAAa,GACb,SAAS,GACT,SAAS,CAAC;AAEd,MAAM,WAAW,oBAAoB;IACnC,cAAc,EAAE,0BAA0B,CAAC;IAC3C,aAAa,EAAE,OAAO,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,YAAY,CAAC;CACrB;AAED,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,eAAe,EAAE,CAAC;CAC5B;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,eAAe,EAAE,oBAAoB,CAAC;CACvC"}
@@ -0,0 +1,28 @@
1
+ const compactEventText = (values) => [...new Set(values.map((value) => value?.trim()).filter(Boolean))]
2
+ .join(" ")
3
+ .trim();
4
+ const metadataRecallText = (metadata) => {
5
+ if (!metadata)
6
+ return "";
7
+ const values = [];
8
+ for (const [key, value] of Object.entries(metadata).filter(([, value]) => typeof value === "string" || typeof value === "number" ||
9
+ typeof value === "boolean")) {
10
+ if (/^(eventType|tool|integration|cwd|status|result|reason)$/i.test(key)) {
11
+ values.push(String(value));
12
+ }
13
+ }
14
+ return values.join(" ");
15
+ };
16
+ export const getSessionEventPrimaryText = (event, fallback) => event.continuityText?.trim() || event.detail?.trim() ||
17
+ event.summary.trim() ||
18
+ event.body?.trim() || fallback || "";
19
+ export const getSessionEventRecallText = (event) => compactEventText([
20
+ event.summary,
21
+ event.continuityText,
22
+ event.detail,
23
+ event.refs?.join(" "),
24
+ event.keywords?.join(" "),
25
+ metadataRecallText(event.metadata),
26
+ event.category,
27
+ event.sourceKind,
28
+ ]);
@@ -0,0 +1,27 @@
1
+ import type { Part } from "@opencode-ai/sdk";
2
+ /**
3
+ * Build a sanitized Graphiti group ID from a prefix and project directory.
4
+ */
5
+ export declare const makeGroupId: (prefix?: string, directory?: string) => string;
6
+ /**
7
+ * Build a sanitized Graphiti group ID from a prefix and user home directory.
8
+ */
9
+ export declare const makeUserGroupId: (prefix?: string, directory?: string) => string;
10
+ /**
11
+ * Narrow an OpenCode Part to a non-synthetic text part.
12
+ */
13
+ export declare const isTextPart: (value: unknown) => value is Part & {
14
+ type: "text";
15
+ text: string;
16
+ };
17
+ /**
18
+ * Extract and join text from OpenCode message parts.
19
+ */
20
+ export declare const extractTextFromParts: (parts: Part[]) => string;
21
+ /**
22
+ * Truncate `text` to at most `budget` characters without cutting mid-line.
23
+ * Prefers to break at the last newline within the budget window; falls back
24
+ * to a raw slice only when the candidate contains no newline.
25
+ */
26
+ export declare const truncateAtLineBoundary: (text: string, budget: number) => string;
27
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AA0C7C;;GAEG;AACH,eAAO,MAAM,WAAW,GACtB,SAAS,MAAM,EACf,YAAW,MAAsB,KAChC,MAMF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,GAC1B,SAAS,MAAM,EACf,YAAW,MAAsB,KAChC,MAQF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,UAAU,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,IAAI,GAAG;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CAMd,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB,GAAI,OAAO,IAAI,EAAE,KAAG,MACe,CAAC;AAErE;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GACjC,MAAM,MAAM,EACZ,QAAQ,MAAM,KACb,MAKF,CAAC"}
@@ -0,0 +1,76 @@
1
+ import os from "node:os";
2
+ import path from "node:path";
3
+ import process from "node:process";
4
+ const getPathBasename = (value) => {
5
+ const trimmed = value.trim();
6
+ if (!trimmed)
7
+ return "";
8
+ const normalized = trimmed.replaceAll("\\", "/");
9
+ return path.posix.basename(normalized);
10
+ };
11
+ const getProjectName = (directory) => getPathBasename(directory) || "default";
12
+ const toPascalCaseSegment = (value) => {
13
+ const words = value.match(/[\p{L}\p{N}]+/gu) ?? [];
14
+ const pascal = words.map((word) => {
15
+ if (!word)
16
+ return "";
17
+ const [first = "", ...rest] = Array.from(word);
18
+ return first.toLocaleUpperCase() + rest.join("").toLocaleLowerCase();
19
+ }).join("");
20
+ return pascal || "Default";
21
+ };
22
+ const sanitizeGroupSegment = (value) => value.replace(/[^A-Za-z0-9_]/g, "_");
23
+ const sanitizeProjectSegment = (value) => value.replace(/[^\p{L}\p{N}_]/gu, "_");
24
+ const getHomeDirectory = () => {
25
+ try {
26
+ return os.homedir();
27
+ }
28
+ catch {
29
+ return undefined;
30
+ }
31
+ };
32
+ const getUserName = () => getPathBasename(getHomeDirectory() ?? "") || undefined;
33
+ /**
34
+ * Build a sanitized Graphiti group ID from a prefix and project directory.
35
+ */
36
+ export const makeGroupId = (prefix, directory = process.cwd()) => {
37
+ const projectName = sanitizeProjectSegment(toPascalCaseSegment(getProjectName(directory)));
38
+ const prefixPart = prefix ? `${sanitizeGroupSegment(prefix)}_` : "";
39
+ return `${prefixPart}${projectName}__main`;
40
+ };
41
+ /**
42
+ * Build a sanitized Graphiti group ID from a prefix and user home directory.
43
+ */
44
+ export const makeUserGroupId = (prefix, directory = process.cwd()) => {
45
+ const projectName = sanitizeProjectSegment(toPascalCaseSegment(getProjectName(directory)));
46
+ const userName = getUserName() ?? "unknown";
47
+ const prefixPart = prefix ? `${sanitizeGroupSegment(prefix)}_` : "";
48
+ const userSegment = sanitizeGroupSegment(userName);
49
+ return `${prefixPart}${projectName}__user_${userSegment}`;
50
+ };
51
+ /**
52
+ * Narrow an OpenCode Part to a non-synthetic text part.
53
+ */
54
+ export const isTextPart = (value) => {
55
+ if (!value || typeof value !== "object")
56
+ return false;
57
+ const part = value;
58
+ return part.type === "text" && typeof part.text === "string" &&
59
+ !part.synthetic;
60
+ };
61
+ /**
62
+ * Extract and join text from OpenCode message parts.
63
+ */
64
+ export const extractTextFromParts = (parts) => parts.filter(isTextPart).map((part) => part.text).join(" ").trim();
65
+ /**
66
+ * Truncate `text` to at most `budget` characters without cutting mid-line.
67
+ * Prefers to break at the last newline within the budget window; falls back
68
+ * to a raw slice only when the candidate contains no newline.
69
+ */
70
+ export const truncateAtLineBoundary = (text, budget) => {
71
+ if (text.length <= budget)
72
+ return text;
73
+ const candidate = text.slice(0, budget);
74
+ const lastNl = candidate.lastIndexOf("\n");
75
+ return lastNl > 0 ? candidate.slice(0, lastNl) : candidate;
76
+ };
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "opencode-graphiti",
3
+ "version": "0.0.0-development",
4
+ "description": "OpenCode plugin for persistent memory via Graphiti knowledge graph",
5
+ "keywords": [
6
+ "opencode",
7
+ "graphiti",
8
+ "knowledge-graph",
9
+ "persistent-memory",
10
+ "plugin",
11
+ "mcp",
12
+ "ai",
13
+ "context"
14
+ ],
15
+ "author": "Vicary A. <vicary.archangel@member.mensa.org>",
16
+ "homepage": "https://github.com/vicary/opencode-graphiti#readme",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/vicary/opencode-graphiti.git"
20
+ },
21
+ "license": "MIT",
22
+ "bugs": {
23
+ "url": "https://github.com/vicary/opencode-graphiti/issues"
24
+ },
25
+ "main": "./esm/mod.js",
26
+ "module": "./esm/mod.js",
27
+ "types": "./esm/mod.d.ts",
28
+ "exports": {
29
+ ".": {
30
+ "import": "./esm/mod.js",
31
+ "require": "./script/mod.js"
32
+ }
33
+ },
34
+ "scripts": {},
35
+ "engines": {
36
+ "node": ">=20"
37
+ },
38
+ "opencode": {
39
+ "type": "plugin",
40
+ "hooks": [
41
+ "chat.message",
42
+ "event",
43
+ "experimental.session.compacting",
44
+ "experimental.chat.messages.transform"
45
+ ]
46
+ },
47
+ "dependencies": {
48
+ "@modelcontextprotocol/sdk": "^1.25.2",
49
+ "@opencode-ai/plugin": "1.2.26",
50
+ "@opencode-ai/sdk": "1.2.26",
51
+ "cosmiconfig": "9.0.0",
52
+ "ioredis": "^5.7.0",
53
+ "@deno/shim-deno": "~0.18.0"
54
+ },
55
+ "devDependencies": {
56
+ "@types/node": "^20.9.0"
57
+ },
58
+ "_generatedBy": "dnt@dev"
59
+ }
@@ -0,0 +1,166 @@
1
+ declare global {
2
+ interface Array<T> {
3
+ /**
4
+ * Returns the value of the last element in the array where predicate is true, and undefined
5
+ * otherwise.
6
+ * @param predicate find calls predicate once for each element of the array, in ascending
7
+ * order, until it finds one where predicate returns true. If such an element is found, find
8
+ * immediately returns that element value. Otherwise, find returns undefined.
9
+ * @param thisArg If provided, it will be used as the this value for each invocation of
10
+ * predicate. If it is not provided, undefined is used instead.
11
+ */
12
+ findLast<S extends T>(predicate: (this: void, value: T, index: number, obj: T[]) => value is S, thisArg?: any): S | undefined;
13
+ findLast(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): T | undefined;
14
+ /**
15
+ * Returns the index of the last element in the array where predicate is true, and -1
16
+ * otherwise.
17
+ * @param predicate find calls predicate once for each element of the array, in ascending
18
+ * order, until it finds one where predicate returns true. If such an element is found,
19
+ * findIndex immediately returns that element index. Otherwise, findIndex returns -1.
20
+ * @param thisArg If provided, it will be used as the this value for each invocation of
21
+ * predicate. If it is not provided, undefined is used instead.
22
+ */
23
+ findLastIndex(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): number;
24
+ }
25
+ interface Uint8Array {
26
+ /**
27
+ * Returns the value of the last element in the array where predicate is true, and undefined
28
+ * otherwise.
29
+ * @param predicate findLast calls predicate once for each element of the array, in descending
30
+ * order, until it finds one where predicate returns true. If such an element is found, findLast
31
+ * immediately returns that element value. Otherwise, findLast returns undefined.
32
+ * @param thisArg If provided, it will be used as the this value for each invocation of
33
+ * predicate. If it is not provided, undefined is used instead.
34
+ */
35
+ findLast<S extends number>(predicate: (value: number, index: number, array: Uint8Array) => value is S, thisArg?: any): S | undefined;
36
+ findLast(predicate: (value: number, index: number, array: Uint8Array) => unknown, thisArg?: any): number | undefined;
37
+ /**
38
+ * Returns the index of the last element in the array where predicate is true, and -1
39
+ * otherwise.
40
+ * @param predicate findLastIndex calls predicate once for each element of the array, in descending
41
+ * order, until it finds one where predicate returns true. If such an element is found,
42
+ * findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.
43
+ * @param thisArg If provided, it will be used as the this value for each invocation of
44
+ * predicate. If it is not provided, undefined is used instead.
45
+ */
46
+ findLastIndex(predicate: (value: number, index: number, array: Uint8Array) => unknown, thisArg?: any): number;
47
+ }
48
+ }
49
+ export {};
50
+ declare global {
51
+ interface Object {
52
+ /**
53
+ * Determines whether an object has a property with the specified name.
54
+ * @param o An object.
55
+ * @param v A property name.
56
+ */
57
+ hasOwn(o: object, v: PropertyKey): boolean;
58
+ }
59
+ }
60
+ export {};
61
+ declare global {
62
+ interface Error {
63
+ cause?: unknown;
64
+ }
65
+ }
66
+ export {};
67
+ /**
68
+ * Based on [import-meta-ponyfill](https://github.com/gaubee/import-meta-ponyfill),
69
+ * but instead of using npm to install additional dependencies,
70
+ * this approach manually consolidates cjs/mjs/d.ts into a single file.
71
+ *
72
+ * Note that this code might be imported multiple times
73
+ * (for example, both dnt.test.polyfills.ts and dnt.polyfills.ts contain this code;
74
+ * or Node.js might dynamically clear the cache and then force a require).
75
+ * Therefore, it's important to avoid redundant writes to global objects.
76
+ * Additionally, consider that commonjs is used alongside esm,
77
+ * so the two ponyfill functions are stored independently in two separate global objects.
78
+ */
79
+ import { createRequire } from "node:module";
80
+ import { type URL } from "node:url";
81
+ declare global {
82
+ interface ImportMeta {
83
+ /** A string representation of the fully qualified module URL. When the
84
+ * module is loaded locally, the value will be a file URL (e.g.
85
+ * `file:///path/module.ts`).
86
+ *
87
+ * You can also parse the string as a URL to determine more information about
88
+ * how the current module was loaded. For example to determine if a module was
89
+ * local or not:
90
+ *
91
+ * ```ts
92
+ * const url = new URL(import.meta.url);
93
+ * if (url.protocol === "file:") {
94
+ * console.log("this module was loaded locally");
95
+ * }
96
+ * ```
97
+ */
98
+ url: string;
99
+ /**
100
+ * A function that returns resolved specifier as if it would be imported
101
+ * using `import(specifier)`.
102
+ *
103
+ * ```ts
104
+ * console.log(import.meta.resolve("./foo.js"));
105
+ * // file:///dev/foo.js
106
+ * ```
107
+ *
108
+ * @param specifier The module specifier to resolve relative to `parent`.
109
+ * @param parent The absolute parent module URL to resolve from.
110
+ * @returns The absolute (`file:`) URL string for the resolved module.
111
+ */
112
+ resolve(specifier: string, parent?: string | URL | undefined): string;
113
+ /** A flag that indicates if the current module is the main module that was
114
+ * called when starting the program under Deno.
115
+ *
116
+ * ```ts
117
+ * if (import.meta.main) {
118
+ * // this was loaded as the main module, maybe do some bootstrapping
119
+ * }
120
+ * ```
121
+ */
122
+ main: boolean;
123
+ /** The absolute path of the current module.
124
+ *
125
+ * This property is only provided for local modules (ie. using `file://` URLs).
126
+ *
127
+ * Example:
128
+ * ```
129
+ * // Unix
130
+ * console.log(import.meta.filename); // /home/alice/my_module.ts
131
+ *
132
+ * // Windows
133
+ * console.log(import.meta.filename); // C:\alice\my_module.ts
134
+ * ```
135
+ */
136
+ filename: string;
137
+ /** The absolute path of the directory containing the current module.
138
+ *
139
+ * This property is only provided for local modules (ie. using `file://` URLs).
140
+ *
141
+ * * Example:
142
+ * ```
143
+ * // Unix
144
+ * console.log(import.meta.dirname); // /home/alice
145
+ *
146
+ * // Windows
147
+ * console.log(import.meta.dirname); // C:\alice
148
+ * ```
149
+ */
150
+ dirname: string;
151
+ }
152
+ }
153
+ type NodeRequest = ReturnType<typeof createRequire>;
154
+ type NodeModule = NonNullable<NodeRequest["main"]>;
155
+ interface ImportMetaPonyfillCommonjs {
156
+ (require: NodeRequest, module: NodeModule): ImportMeta;
157
+ }
158
+ interface ImportMetaPonyfillEsmodule {
159
+ (importMeta: ImportMeta): ImportMeta;
160
+ }
161
+ interface ImportMetaPonyfill extends ImportMetaPonyfillCommonjs, ImportMetaPonyfillEsmodule {
162
+ }
163
+ export declare let import_meta_ponyfill_commonjs: ImportMetaPonyfillCommonjs;
164
+ export declare let import_meta_ponyfill_esmodule: ImportMetaPonyfillEsmodule;
165
+ export declare let import_meta_ponyfill: ImportMetaPonyfill;
166
+ //# sourceMappingURL=_dnt.polyfills.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_dnt.polyfills.d.ts","sourceRoot":"","sources":["../src/_dnt.polyfills.ts"],"names":[],"mappings":"AACA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK,CAAC,CAAC;QACf;;;;;;;;WAQG;QACH,QAAQ,CAAC,CAAC,SAAS,CAAC,EAClB,SAAS,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC,EACxE,OAAO,CAAC,EAAE,GAAG,GACZ,CAAC,GAAG,SAAS,CAAC;QACjB,QAAQ,CACN,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,OAAO,EACzD,OAAO,CAAC,EAAE,GAAG,GACZ,CAAC,GAAG,SAAS,CAAC;QAEjB;;;;;;;;WAQG;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,CAAC,MAAM,CAAC;IACb,UAAU,UAAU;QAClB;;;;;;;;;;;;;;WAcG;QACH,GAAG,EAAE,MAAM,CAAC;QACZ;;;;;;;;;;;;WAYG;QACH,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS,GAAG,MAAM,CAAC;QACtE;;;;;;;;WAQG;QACH,IAAI,EAAE,OAAO,CAAC;QAEd;;;;;;;;;;;;WAYG;QACH,QAAQ,EAAE,MAAM,CAAC;QAEjB;;;;;;;;;;;;WAYG;QACH,OAAO,EAAE,MAAM,CAAC;KACjB;CACF;AAED,KAAK,WAAW,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;AACpD,KAAK,UAAU,GAAG,WAAW,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;AACnD,UAAU,0BAA0B;IAClC,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC;CACxD;AACD,UAAU,0BAA0B;IAClC,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,CAAC;CACtC;AACD,UAAU,kBACR,SAAQ,0BAA0B,EAAE,0BAA0B;CAC/D;AAiBD,eAAO,IAAI,6BAA6B,EA2BnC,0BAA0B,CAAC;AAMhC,eAAO,IAAI,6BAA6B,EA4DnC,0BAA0B,CAAC;AAMhC,eAAO,IAAI,oBAAoB,EAoB1B,kBAAkB,CAAC"}
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.import_meta_ponyfill = exports.import_meta_ponyfill_esmodule = exports.import_meta_ponyfill_commonjs = void 0;
4
+ function findLastIndex(self, callbackfn, that) {
5
+ const boundFunc = that === undefined ? callbackfn : callbackfn.bind(that);
6
+ let index = self.length - 1;
7
+ while (index >= 0) {
8
+ const result = boundFunc(self[index], index, self);
9
+ if (result) {
10
+ return index;
11
+ }
12
+ index--;
13
+ }
14
+ return -1;
15
+ }
16
+ function findLast(self, callbackfn, that) {
17
+ const index = self.findLastIndex(callbackfn, that);
18
+ return index === -1 ? undefined : self[index];
19
+ }
20
+ if (!Array.prototype.findLastIndex) {
21
+ Array.prototype.findLastIndex = function (callbackfn, that) {
22
+ return findLastIndex(this, callbackfn, that);
23
+ };
24
+ }
25
+ if (!Array.prototype.findLast) {
26
+ Array.prototype.findLast = function (callbackfn, that) {
27
+ return findLast(this, callbackfn, that);
28
+ };
29
+ }
30
+ if (!Uint8Array.prototype.findLastIndex) {
31
+ Uint8Array.prototype.findLastIndex = function (callbackfn, that) {
32
+ return findLastIndex(this, callbackfn, that);
33
+ };
34
+ }
35
+ if (!Uint8Array.prototype.findLast) {
36
+ Uint8Array.prototype.findLast = function (callbackfn, that) {
37
+ return findLast(this, callbackfn, that);
38
+ };
39
+ }
40
+ // https://github.com/tc39/proposal-accessible-object-hasownproperty/blob/main/polyfill.js
41
+ if (!Object.hasOwn) {
42
+ Object.defineProperty(Object, "hasOwn", {
43
+ value: function (object, property) {
44
+ if (object == null) {
45
+ throw new TypeError("Cannot convert undefined or null to object");
46
+ }
47
+ return Object.prototype.hasOwnProperty.call(Object(object), property);
48
+ },
49
+ configurable: true,
50
+ enumerable: false,
51
+ writable: true,
52
+ });
53
+ }
54
+ /**
55
+ * Based on [import-meta-ponyfill](https://github.com/gaubee/import-meta-ponyfill),
56
+ * but instead of using npm to install additional dependencies,
57
+ * this approach manually consolidates cjs/mjs/d.ts into a single file.
58
+ *
59
+ * Note that this code might be imported multiple times
60
+ * (for example, both dnt.test.polyfills.ts and dnt.polyfills.ts contain this code;
61
+ * or Node.js might dynamically clear the cache and then force a require).
62
+ * Therefore, it's important to avoid redundant writes to global objects.
63
+ * Additionally, consider that commonjs is used alongside esm,
64
+ * so the two ponyfill functions are stored independently in two separate global objects.
65
+ */
66
+ //@ts-ignore
67
+ const node_module_1 = require("node:module");
68
+ //@ts-ignore
69
+ const node_url_1 = require("node:url");
70
+ //@ts-ignore
71
+ const node_path_1 = require("node:path");
72
+ const defineGlobalPonyfill = (symbolFor, fn) => {
73
+ if (!Reflect.has(globalThis, Symbol.for(symbolFor))) {
74
+ Object.defineProperty(globalThis, Symbol.for(symbolFor), {
75
+ configurable: true,
76
+ get() {
77
+ return fn;
78
+ },
79
+ });
80
+ }
81
+ };
82
+ exports.import_meta_ponyfill_commonjs = (Reflect.get(globalThis, Symbol.for("import-meta-ponyfill-commonjs")) ??
83
+ (() => {
84
+ const moduleImportMetaWM = new WeakMap();
85
+ return (require, module) => {
86
+ let importMetaCache = moduleImportMetaWM.get(module);
87
+ if (importMetaCache == null) {
88
+ const importMeta = Object.assign(Object.create(null), {
89
+ url: (0, node_url_1.pathToFileURL)(module.filename).href,
90
+ main: require.main == module,
91
+ resolve: (specifier, parentURL = importMeta.url) => {
92
+ return (0, node_url_1.pathToFileURL)((importMeta.url === parentURL
93
+ ? require
94
+ : (0, node_module_1.createRequire)(parentURL))
95
+ .resolve(specifier)).href;
96
+ },
97
+ filename: module.filename,
98
+ dirname: module.path,
99
+ });
100
+ moduleImportMetaWM.set(module, importMeta);
101
+ importMetaCache = importMeta;
102
+ }
103
+ return importMetaCache;
104
+ };
105
+ })());
106
+ defineGlobalPonyfill("import-meta-ponyfill-commonjs", exports.import_meta_ponyfill_commonjs);
107
+ exports.import_meta_ponyfill_esmodule = (Reflect.get(globalThis, Symbol.for("import-meta-ponyfill-esmodule")) ??
108
+ ((importMeta) => {
109
+ const resolveFunStr = String(importMeta.resolve);
110
+ const shimWs = new WeakSet();
111
+ //@ts-ignore
112
+ const mainUrl = ("file:///" + process.argv[1].replace(/\\/g, "/"))
113
+ .replace(/\/{3,}/, "///");
114
+ const commonShim = (importMeta) => {
115
+ if (typeof importMeta.main !== "boolean") {
116
+ importMeta.main = importMeta.url === mainUrl;
117
+ }
118
+ if (typeof importMeta.filename !== "string") {
119
+ importMeta.filename = (0, node_url_1.fileURLToPath)(importMeta.url);
120
+ importMeta.dirname = (0, node_path_1.dirname)(importMeta.filename);
121
+ }
122
+ };
123
+ if (
124
+ // v16.2.0+, v14.18.0+: Add support for WHATWG URL object to parentURL parameter.
125
+ resolveFunStr === "undefined" ||
126
+ // v20.0.0+, v18.19.0+"" This API now returns a string synchronously instead of a Promise.
127
+ resolveFunStr.startsWith("async")
128
+ // enable by --experimental-import-meta-resolve flag
129
+ ) {
130
+ exports.import_meta_ponyfill_esmodule = (importMeta) => {
131
+ if (!shimWs.has(importMeta)) {
132
+ shimWs.add(importMeta);
133
+ const importMetaUrlRequire = {
134
+ url: importMeta.url,
135
+ require: (0, node_module_1.createRequire)(importMeta.url),
136
+ };
137
+ importMeta.resolve = function resolve(specifier, parentURL = importMeta.url) {
138
+ return (0, node_url_1.pathToFileURL)((importMetaUrlRequire.url === parentURL
139
+ ? importMetaUrlRequire.require
140
+ : (0, node_module_1.createRequire)(parentURL)).resolve(specifier)).href;
141
+ };
142
+ commonShim(importMeta);
143
+ }
144
+ return importMeta;
145
+ };
146
+ }
147
+ else {
148
+ /// native support
149
+ exports.import_meta_ponyfill_esmodule = (importMeta) => {
150
+ if (!shimWs.has(importMeta)) {
151
+ shimWs.add(importMeta);
152
+ commonShim(importMeta);
153
+ }
154
+ return importMeta;
155
+ };
156
+ }
157
+ return (0, exports.import_meta_ponyfill_esmodule)(importMeta);
158
+ }));
159
+ defineGlobalPonyfill("import-meta-ponyfill-esmodule", exports.import_meta_ponyfill_esmodule);
160
+ exports.import_meta_ponyfill = ((...args) => {
161
+ const _MODULE = (() => {
162
+ if (typeof require === "function" && typeof module === "object") {
163
+ return "commonjs";
164
+ }
165
+ else {
166
+ // eval("typeof import.meta");
167
+ return "esmodule";
168
+ }
169
+ })();
170
+ if (_MODULE === "commonjs") {
171
+ //@ts-ignore
172
+ exports.import_meta_ponyfill = (r, m) => (0, exports.import_meta_ponyfill_commonjs)(r, m);
173
+ }
174
+ else {
175
+ //@ts-ignore
176
+ exports.import_meta_ponyfill = (im) => (0, exports.import_meta_ponyfill_esmodule)(im);
177
+ }
178
+ //@ts-ignore
179
+ return (0, exports.import_meta_ponyfill)(...args);
180
+ });