@scitrera/memorylayer-opencode-plugin 0.1.22
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.md +178 -0
- package/dist/src/hooks/event.d.ts +15 -0
- package/dist/src/hooks/event.d.ts.map +1 -0
- package/dist/src/hooks/event.js +53 -0
- package/dist/src/hooks/event.js.map +1 -0
- package/dist/src/hooks/message.d.ts +20 -0
- package/dist/src/hooks/message.d.ts.map +1 -0
- package/dist/src/hooks/message.js +128 -0
- package/dist/src/hooks/message.js.map +1 -0
- package/dist/src/hooks/session.d.ts +20 -0
- package/dist/src/hooks/session.d.ts.map +1 -0
- package/dist/src/hooks/session.js +121 -0
- package/dist/src/hooks/session.js.map +1 -0
- package/dist/src/hooks/tool.d.ts +23 -0
- package/dist/src/hooks/tool.d.ts.map +1 -0
- package/dist/src/hooks/tool.js +168 -0
- package/dist/src/hooks/tool.js.map +1 -0
- package/dist/src/index.d.ts +31 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +176 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/shared/client.d.ts +27 -0
- package/dist/src/shared/client.d.ts.map +1 -0
- package/dist/src/shared/client.js +69 -0
- package/dist/src/shared/client.js.map +1 -0
- package/dist/src/shared/formatters.d.ts +33 -0
- package/dist/src/shared/formatters.d.ts.map +1 -0
- package/dist/src/shared/formatters.js +187 -0
- package/dist/src/shared/formatters.js.map +1 -0
- package/dist/src/shared/observation.d.ts +59 -0
- package/dist/src/shared/observation.d.ts.map +1 -0
- package/dist/src/shared/observation.js +406 -0
- package/dist/src/shared/observation.js.map +1 -0
- package/dist/src/shared/state.d.ts +66 -0
- package/dist/src/shared/state.d.ts.map +1 -0
- package/dist/src/shared/state.js +144 -0
- package/dist/src/shared/state.js.map +1 -0
- package/dist/src/shared/types.d.ts +141 -0
- package/dist/src/shared/types.d.ts.map +1 -0
- package/dist/src/shared/types.js +9 -0
- package/dist/src/shared/types.js.map +1 -0
- package/opencode.example.json +15 -0
- package/package.json +52 -0
- package/src/commands/recall.md +55 -0
- package/src/commands/remember.md +37 -0
- package/src/commands/setup.md +47 -0
- package/src/commands/status.md +59 -0
- package/src/hooks/event.ts +63 -0
- package/src/hooks/message.ts +147 -0
- package/src/hooks/session.ts +127 -0
- package/src/hooks/tool.ts +207 -0
- package/src/index.ts +197 -0
- package/src/shared/client.ts +73 -0
- package/src/shared/formatters.ts +237 -0
- package/src/shared/observation.ts +447 -0
- package/src/shared/state.ts +159 -0
- package/src/shared/types.ts +144 -0
- package/tsconfig.json +24 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for MemoryLayer OpenCode plugin.
|
|
3
|
+
*
|
|
4
|
+
* OpenCode plugins receive a PluginInput context and return a Hooks object.
|
|
5
|
+
* Hooks follow an (input, output) => Promise<void> pattern where you mutate
|
|
6
|
+
* the output object to inject changes.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { Memory, RecallResult, ToolResponse } from "@scitrera/memorylayer-mcp-server";
|
|
10
|
+
|
|
11
|
+
// Re-export MCP server types used by formatters
|
|
12
|
+
export type { Memory, RecallResult, ToolResponse };
|
|
13
|
+
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
// OpenCode Plugin Types (based on @opencode-ai/plugin v1.3.x)
|
|
16
|
+
// Defined here to avoid hard dependency on @opencode-ai/plugin at runtime.
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
|
|
19
|
+
/** Context provided to the plugin server function */
|
|
20
|
+
export interface PluginInput {
|
|
21
|
+
/** OpenCode SDK client */
|
|
22
|
+
client: unknown;
|
|
23
|
+
/** Project metadata */
|
|
24
|
+
project: Record<string, unknown>;
|
|
25
|
+
/** Current working directory */
|
|
26
|
+
directory: string;
|
|
27
|
+
/** Git worktree root */
|
|
28
|
+
worktree: string;
|
|
29
|
+
/** OpenCode server URL */
|
|
30
|
+
serverUrl: URL;
|
|
31
|
+
/** Bun shell instance */
|
|
32
|
+
$: unknown;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Optional plugin configuration from opencode.json */
|
|
36
|
+
export type PluginOptions = Record<string, unknown>;
|
|
37
|
+
|
|
38
|
+
/** Message part for context injection */
|
|
39
|
+
export interface Part {
|
|
40
|
+
type: "text";
|
|
41
|
+
text: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Model descriptor */
|
|
45
|
+
export interface Model {
|
|
46
|
+
providerID: string;
|
|
47
|
+
modelID: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Hook definitions returned by the plugin.
|
|
52
|
+
* Only the hooks we actually implement are typed here.
|
|
53
|
+
*/
|
|
54
|
+
export interface MemoryLayerHooks {
|
|
55
|
+
/** Listen to OpenCode events (session lifecycle, etc.) */
|
|
56
|
+
event?: (input: { event: OpenCodeEvent }) => Promise<void>;
|
|
57
|
+
|
|
58
|
+
/** Modify the system prompt to inject memory context */
|
|
59
|
+
"experimental.chat.system.transform"?: (
|
|
60
|
+
input: { sessionID?: string; model: Model },
|
|
61
|
+
output: { system: string[] },
|
|
62
|
+
) => Promise<void>;
|
|
63
|
+
|
|
64
|
+
/** Hook into user messages to perform recall */
|
|
65
|
+
"chat.message"?: (
|
|
66
|
+
input: {
|
|
67
|
+
sessionID: string;
|
|
68
|
+
agent?: string;
|
|
69
|
+
model?: { providerID: string; modelID: string };
|
|
70
|
+
messageID?: string;
|
|
71
|
+
variant?: string;
|
|
72
|
+
},
|
|
73
|
+
output: { message: UserMessage; parts: Part[] },
|
|
74
|
+
) => Promise<void>;
|
|
75
|
+
|
|
76
|
+
/** Modify tool arguments before execution */
|
|
77
|
+
"tool.execute.before"?: (
|
|
78
|
+
input: { tool: string; sessionID: string; callID: string },
|
|
79
|
+
output: { args: Record<string, unknown> },
|
|
80
|
+
) => Promise<void>;
|
|
81
|
+
|
|
82
|
+
/** Capture tool output after execution */
|
|
83
|
+
"tool.execute.after"?: (
|
|
84
|
+
input: { tool: string; sessionID: string; callID: string; args: Record<string, unknown> },
|
|
85
|
+
output: { title: string; output: string; metadata: Record<string, unknown> },
|
|
86
|
+
) => Promise<void>;
|
|
87
|
+
|
|
88
|
+
/** Inject context before context compaction */
|
|
89
|
+
"experimental.session.compacting"?: (
|
|
90
|
+
input: { sessionID: string },
|
|
91
|
+
output: { context: string[]; prompt?: string },
|
|
92
|
+
) => Promise<void>;
|
|
93
|
+
|
|
94
|
+
/** Inject environment variables into shell commands */
|
|
95
|
+
"shell.env"?: (
|
|
96
|
+
input: { cwd: string; sessionID?: string; callID?: string },
|
|
97
|
+
output: { env: Record<string, string> },
|
|
98
|
+
) => Promise<void>;
|
|
99
|
+
|
|
100
|
+
/** Register custom tools */
|
|
101
|
+
tool?: Record<string, unknown>;
|
|
102
|
+
|
|
103
|
+
/** Intercept slash commands */
|
|
104
|
+
"command.execute.before"?: (
|
|
105
|
+
input: { command: string; sessionID: string; arguments: string },
|
|
106
|
+
output: { parts: Part[] },
|
|
107
|
+
) => Promise<void>;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** OpenCode event structure */
|
|
111
|
+
export interface OpenCodeEvent {
|
|
112
|
+
type: string;
|
|
113
|
+
properties: Record<string, unknown>;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** User message structure */
|
|
117
|
+
export interface UserMessage {
|
|
118
|
+
role: "user";
|
|
119
|
+
parts: Part[];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// ---------------------------------------------------------------------------
|
|
123
|
+
// Hook State (shared with CC plugin pattern)
|
|
124
|
+
// ---------------------------------------------------------------------------
|
|
125
|
+
|
|
126
|
+
/** State tracked between hook invocations */
|
|
127
|
+
export interface HookState {
|
|
128
|
+
/** Current session ID */
|
|
129
|
+
sessionId?: string;
|
|
130
|
+
/** Workspace ID being used */
|
|
131
|
+
workspaceId?: string;
|
|
132
|
+
/** Whether recall has been done this conversation turn */
|
|
133
|
+
recallDoneThisTurn: boolean;
|
|
134
|
+
/** Timestamp of last recall */
|
|
135
|
+
lastRecallAt?: string;
|
|
136
|
+
/** Query used for last recall */
|
|
137
|
+
lastRecallQuery?: string;
|
|
138
|
+
/** Queries already performed this turn (for query-aware dedup) */
|
|
139
|
+
recallQueriesThisTurn?: string[];
|
|
140
|
+
/** User's current topic from most recent prompt */
|
|
141
|
+
currentTopic?: string;
|
|
142
|
+
/** User's current prompt text for intent detection */
|
|
143
|
+
currentPrompt?: string;
|
|
144
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"lib": ["ES2022"],
|
|
7
|
+
"outDir": "dist",
|
|
8
|
+
"rootDir": ".",
|
|
9
|
+
"declaration": true,
|
|
10
|
+
"declarationMap": true,
|
|
11
|
+
"sourceMap": true,
|
|
12
|
+
"strict": true,
|
|
13
|
+
"esModuleInterop": true,
|
|
14
|
+
"skipLibCheck": true,
|
|
15
|
+
"forceConsistentCasingInFileNames": true,
|
|
16
|
+
"resolveJsonModule": true,
|
|
17
|
+
"isolatedModules": true,
|
|
18
|
+
"noUnusedLocals": true,
|
|
19
|
+
"noUnusedParameters": true,
|
|
20
|
+
"noImplicitReturns": true
|
|
21
|
+
},
|
|
22
|
+
"include": ["src/**/*.ts"],
|
|
23
|
+
"exclude": ["node_modules", "dist"]
|
|
24
|
+
}
|