Skip to content

Commit 4efa201

Browse files
authored
Merge pull request #1 from kandotrun/fix/part-id-prefix
fix: use prt_ prefix for all part IDs (OpenCode v1.2.25+ compat)
2 parents 6bca5df + 39a873d commit 4efa201

3 files changed

Lines changed: 20 additions & 14 deletions

File tree

src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { formatContextForPrompt } from "./services/context.js";
77
import { getTags } from "./services/tags.js";
88
import { stripPrivateContent, isFullyPrivate } from "./services/privacy.js";
99
import { createCompactionHook, type CompactionContext } from "./services/compaction.js";
10+
import { generatePartId } from "./services/ids.js";
1011

1112
import { isConfigured, CONFIG } from "./config.js";
1213
import { log } from "./services/logger.js";
@@ -112,7 +113,7 @@ export const SupermemoryPlugin: Plugin = async (ctx: PluginInput) => {
112113
if (detectMemoryKeyword(userMessage)) {
113114
log("chat.message: memory keyword detected");
114115
const nudgePart: Part = {
115-
id: `supermemory-nudge-${Date.now()}`,
116+
id: generatePartId(),
116117
sessionID: input.sessionID,
117118
messageID: output.message.id,
118119
type: "text",
@@ -157,7 +158,7 @@ export const SupermemoryPlugin: Plugin = async (ctx: PluginInput) => {
157158

158159
if (memoryContext) {
159160
const contextPart: Part = {
160-
id: `supermemory-context-${Date.now()}`,
161+
id: generatePartId(),
161162
sessionID: input.sessionID,
162163
messageID: output.message.id,
163164
type: "text",

src/services/compaction.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { homedir } from "node:os";
44
import { supermemoryClient } from "./client.js";
55
import { log } from "./logger.js";
66
import { CONFIG } from "../config.js";
7+
import { generatePartId, generateMessageId } from "./ids.js";
78

89
const MESSAGE_STORAGE = join(homedir(), ".opencode", "messages");
910
const PART_STORAGE = join(homedir(), ".opencode", "parts");
@@ -152,18 +153,6 @@ function findNearestMessageWithFields(messageDir: string): StoredMessage | null
152153
return null;
153154
}
154155

155-
function generateMessageId(): string {
156-
const timestamp = Date.now().toString(16);
157-
const random = Math.random().toString(36).substring(2, 14);
158-
return `msg_${timestamp}${random}`;
159-
}
160-
161-
function generatePartId(): string {
162-
const timestamp = Date.now().toString(16);
163-
const random = Math.random().toString(36).substring(2, 10);
164-
return `prt_${timestamp}${random}`;
165-
}
166-
167156
function injectHookMessage(
168157
sessionID: string,
169158
hookContent: string,

src/services/ids.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Shared ID generation utilities.
3+
* OpenCode v1.2.25+ requires all part IDs to start with "prt".
4+
*/
5+
6+
export function generatePartId(): string {
7+
const timestamp = Date.now().toString(16);
8+
const random = Math.random().toString(36).substring(2, 10);
9+
return `prt_${timestamp}${random}`;
10+
}
11+
12+
export function generateMessageId(): string {
13+
const timestamp = Date.now().toString(16);
14+
const random = Math.random().toString(36).substring(2, 14);
15+
return `msg_${timestamp}${random}`;
16+
}

0 commit comments

Comments
 (0)