ever-opencode 0.0.0-stage → 0.2.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.
- package/LICENSE +203 -0
- package/README.md +240 -2
- package/dist/everos.d.ts +72 -0
- package/dist/everos.js +118 -0
- package/dist/extract.d.ts +37 -0
- package/dist/extract.js +48 -0
- package/dist/identity.d.ts +28 -0
- package/dist/identity.js +56 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +259 -0
- package/dist/inject.d.ts +18 -0
- package/dist/inject.js +49 -0
- package/dist/log.d.ts +11 -0
- package/dist/log.js +34 -0
- package/dist/tools.d.ts +63 -0
- package/dist/tools.js +155 -0
- package/dist/types.d.ts +83 -0
- package/dist/types.js +6 -0
- package/package.json +41 -4
package/dist/tools.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent-facing memory tools (OpenCode V2 `ctx.tool.transform`).
|
|
3
|
+
*
|
|
4
|
+
* The passive path (capture + recall injection) is automatic; these tools give
|
|
5
|
+
* the agent an explicit query/write surface — mirroring the mem0 plugin's
|
|
6
|
+
* tool-based memory access:
|
|
7
|
+
* everos_search — query memories on demand (BM25/vector recall server-side)
|
|
8
|
+
* everos_add — store a fact now (add + synchronous extraction via flush)
|
|
9
|
+
* everos_flush — force extraction of the session's deferred capture buffer
|
|
10
|
+
*
|
|
11
|
+
* Tool definitions are plain structural objects: `input` is a JSON Schema and
|
|
12
|
+
* `execute` returns `{content}` — no SDK runtime import, keeping the plugin
|
|
13
|
+
* unit-testable with synthetic contexts.
|
|
14
|
+
*/
|
|
15
|
+
import { formatEpisodeLines } from "./inject.js";
|
|
16
|
+
const TOOL_NAMES = ["everos_search", "everos_add", "everos_flush"];
|
|
17
|
+
function clampTopK(raw, fallback) {
|
|
18
|
+
const n = typeof raw === "number" ? raw : Number.NaN;
|
|
19
|
+
if (!Number.isFinite(n))
|
|
20
|
+
return fallback;
|
|
21
|
+
return Math.min(25, Math.max(1, Math.floor(n)));
|
|
22
|
+
}
|
|
23
|
+
/** Capture-path scope ids are derived per session; tools do the same. */
|
|
24
|
+
function sessionScope(deps, sessionID) {
|
|
25
|
+
return {
|
|
26
|
+
session_id: (sessionID ?? "everos-tools").slice(0, 128),
|
|
27
|
+
app_id: deps.scopeBase.appId,
|
|
28
|
+
project_id: deps.scopeBase.projectId,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/** Never let a tool failure crash the model turn — report it as content. */
|
|
32
|
+
async function guarded(deps, tool, fn) {
|
|
33
|
+
try {
|
|
34
|
+
return await fn();
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
const detail = err instanceof Error && err.code
|
|
38
|
+
? `${err.code}: ${err.message}`
|
|
39
|
+
: err instanceof Error
|
|
40
|
+
? err.message
|
|
41
|
+
: String(err);
|
|
42
|
+
deps.log.debug(`${tool} error: ${detail}`);
|
|
43
|
+
return { content: `everos ${tool} failed: ${detail}`, metadata: { error: true } };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function makeSearchTool(deps) {
|
|
47
|
+
return {
|
|
48
|
+
name: "everos_search",
|
|
49
|
+
description: "Search the user's persistent EverOS memory (episodes + atomic facts from previous " +
|
|
50
|
+
"sessions). Use proactively when context from past work would help — prior decisions, " +
|
|
51
|
+
"preferences, debugging history. Results are ranked server-side (BM25/vector); each " +
|
|
52
|
+
"line carries a relevance score and age.",
|
|
53
|
+
input: {
|
|
54
|
+
type: "object",
|
|
55
|
+
properties: {
|
|
56
|
+
query: { type: "string", description: "Free-text query, e.g. 'how did we fix the flaky login test'" },
|
|
57
|
+
top_k: { type: "number", description: `Max results (1-25, default ${deps.defaultTopK})` },
|
|
58
|
+
scope: {
|
|
59
|
+
type: "string",
|
|
60
|
+
enum: ["project", "global"],
|
|
61
|
+
description: '"project" (memories from this project only, default) or "global" (all projects)',
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
required: ["query"],
|
|
65
|
+
},
|
|
66
|
+
async execute(rawInput, context) {
|
|
67
|
+
const input = (rawInput ?? {});
|
|
68
|
+
const query = typeof input.query === "string" ? input.query.trim() : "";
|
|
69
|
+
if (query.length === 0) {
|
|
70
|
+
return { content: "everos_search failed: 'query' (non-empty string) is required." };
|
|
71
|
+
}
|
|
72
|
+
const global = input.scope === "global";
|
|
73
|
+
return guarded(deps, "everos_search", async () => {
|
|
74
|
+
const episodes = await deps.client.searchMemories(deps.scopeBase.userId, query, {
|
|
75
|
+
method: deps.recallMethod,
|
|
76
|
+
topK: clampTopK(input.top_k, deps.defaultTopK),
|
|
77
|
+
scope: global ? undefined : { appId: deps.scopeBase.appId, projectId: deps.scopeBase.projectId },
|
|
78
|
+
});
|
|
79
|
+
const lines = formatEpisodeLines(episodes, { topK: clampTopK(input.top_k, deps.defaultTopK) });
|
|
80
|
+
if (lines.length === 0) {
|
|
81
|
+
return { content: `No memories found for: ${query}` };
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
content: [`EverOS memories (${lines.length}, may be imperfect):`, ...lines].join("\n"),
|
|
85
|
+
metadata: { sessionID: context.sessionID, scope: global ? "global" : "project", count: lines.length },
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function makeAddTool(deps) {
|
|
92
|
+
return {
|
|
93
|
+
name: "everos_add",
|
|
94
|
+
description: "Store a durable fact in EverOS memory (decisions, preferences, learnings) so future " +
|
|
95
|
+
"sessions can recall it. One sentence per call. The fact is extracted synchronously " +
|
|
96
|
+
"but may take a few seconds before search indexes see it.",
|
|
97
|
+
input: {
|
|
98
|
+
type: "object",
|
|
99
|
+
properties: {
|
|
100
|
+
text: { type: "string", description: "The fact to remember, one sentence" },
|
|
101
|
+
},
|
|
102
|
+
required: ["text"],
|
|
103
|
+
},
|
|
104
|
+
async execute(rawInput, context) {
|
|
105
|
+
const input = (rawInput ?? {});
|
|
106
|
+
const text = typeof input.text === "string" ? input.text.trim() : "";
|
|
107
|
+
if (text.length === 0) {
|
|
108
|
+
return { content: "everos_add failed: 'text' (non-empty string) is required." };
|
|
109
|
+
}
|
|
110
|
+
return guarded(deps, "everos_add", async () => {
|
|
111
|
+
const scope = sessionScope(deps, context?.sessionID);
|
|
112
|
+
await deps.client.addMemory(scope, [{ sender_id: deps.scopeBase.userId, role: "user", timestamp: Date.now(), content: text }], { deferExtraction: true });
|
|
113
|
+
// Synchronous extraction so the new fact is queryable right away.
|
|
114
|
+
await deps.client.flushMemory(scope);
|
|
115
|
+
return {
|
|
116
|
+
content: `Remembered: ${text} (may take a few seconds to become searchable)`,
|
|
117
|
+
metadata: { sessionID: scope.session_id },
|
|
118
|
+
};
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function makeFlushTool(deps) {
|
|
124
|
+
return {
|
|
125
|
+
name: "everos_flush",
|
|
126
|
+
description: "Force EverOS to extract memories from this session's captured conversation so far. " +
|
|
127
|
+
"Useful right before asking a question about the current session's history.",
|
|
128
|
+
input: { type: "object", properties: {} },
|
|
129
|
+
async execute(_input, context) {
|
|
130
|
+
return guarded(deps, "everos_flush", async () => {
|
|
131
|
+
const scope = sessionScope(deps, context?.sessionID);
|
|
132
|
+
await deps.client.flushMemory(scope);
|
|
133
|
+
return { content: "EverOS buffer flushed (extraction complete).", metadata: { sessionID: scope.session_id } };
|
|
134
|
+
});
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
/** All tool names this plugin registers (exported for tests/diagnostics). */
|
|
139
|
+
export const everosToolNames = TOOL_NAMES;
|
|
140
|
+
/** Build the tool definitions (exported for tests). */
|
|
141
|
+
export function buildTools(deps) {
|
|
142
|
+
return [makeSearchTool(deps), makeAddTool(deps), makeFlushTool(deps)];
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Register the tools via `ctx.tool.transform`. Returns the registration, or
|
|
146
|
+
* `undefined` when the host exposes no tool domain (older hosts / tests).
|
|
147
|
+
*/
|
|
148
|
+
export async function registerTools(ctx, deps) {
|
|
149
|
+
if (!ctx.tool)
|
|
150
|
+
return undefined;
|
|
151
|
+
return ctx.tool.transform((editor) => {
|
|
152
|
+
for (const tool of buildTools(deps))
|
|
153
|
+
editor.add(tool);
|
|
154
|
+
});
|
|
155
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal structural interfaces for the subset of the OpenCode V2 plugin
|
|
3
|
+
* context this plugin uses. Kept local so the plugin core stays unit-testable
|
|
4
|
+
* with a synthetic context; the real SDK types are structurally compatible.
|
|
5
|
+
*/
|
|
6
|
+
/** Plugin options (all optional; see README / AGENTS.md). */
|
|
7
|
+
export interface EverosOptions {
|
|
8
|
+
everosUrl?: string;
|
|
9
|
+
flushEvery?: number;
|
|
10
|
+
topK?: number;
|
|
11
|
+
recallMethod?: string;
|
|
12
|
+
enabled?: boolean;
|
|
13
|
+
logLevel?: "debug" | "info" | "error" | "silent";
|
|
14
|
+
}
|
|
15
|
+
/** Subset of `ctx.storage` used here (JSON values in and out). */
|
|
16
|
+
export interface StorageLike {
|
|
17
|
+
get(key: string): Promise<unknown | undefined>;
|
|
18
|
+
set(key: string, value: unknown): Promise<void>;
|
|
19
|
+
remove(key: string): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
export interface EventSubscribeOptions {
|
|
22
|
+
readonly types?: readonly string[];
|
|
23
|
+
readonly signal?: AbortSignal;
|
|
24
|
+
}
|
|
25
|
+
/** Subset of `ctx.event`. */
|
|
26
|
+
export interface EventDomainLike {
|
|
27
|
+
subscribe(options?: EventSubscribeOptions): AsyncIterable<EverosEvent>;
|
|
28
|
+
}
|
|
29
|
+
/** OpenCode V2 event shape (subset we inspect). Resilient: extra fields ignored. */
|
|
30
|
+
export interface EverosEvent {
|
|
31
|
+
type: string;
|
|
32
|
+
data?: {
|
|
33
|
+
sessionID?: string;
|
|
34
|
+
[key: string]: unknown;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export interface RegistrationLike {
|
|
38
|
+
dispose(): Promise<void> | void;
|
|
39
|
+
}
|
|
40
|
+
/** Subset of `ctx.session`. */
|
|
41
|
+
export interface SessionDomainLike {
|
|
42
|
+
/** Register a session hook; returns a registration that can be disposed. */
|
|
43
|
+
hook(name: string, callback: (input: any) => Promise<void> | void): Promise<RegistrationLike>;
|
|
44
|
+
/** Full transcript for a session, newest appended: OpenCode `SessionMessageInfo[]`. */
|
|
45
|
+
context(input: {
|
|
46
|
+
sessionID: string;
|
|
47
|
+
}): Promise<unknown[]>;
|
|
48
|
+
}
|
|
49
|
+
/** Subset of `ctx.vcs` (optional — absent when no VCS is detected). */
|
|
50
|
+
export interface VcsDomainLike {
|
|
51
|
+
get(input?: Record<string, unknown>): Promise<unknown>;
|
|
52
|
+
}
|
|
53
|
+
/** Structural view of the V2 tool editor handed to `ctx.tool.transform`. */
|
|
54
|
+
export interface ToolEditorLike {
|
|
55
|
+
add(tool: {
|
|
56
|
+
readonly name: string;
|
|
57
|
+
readonly description: string;
|
|
58
|
+
readonly input: Record<string, unknown>;
|
|
59
|
+
execute(input: unknown, context: {
|
|
60
|
+
sessionID?: string;
|
|
61
|
+
}): Promise<{
|
|
62
|
+
content: string;
|
|
63
|
+
}>;
|
|
64
|
+
}): void;
|
|
65
|
+
}
|
|
66
|
+
/** Subset of `ctx.tool` (optional — absent on hosts without tool registration). */
|
|
67
|
+
export interface ToolDomainLike {
|
|
68
|
+
transform(callback: (editor: ToolEditorLike) => void): Promise<RegistrationLike>;
|
|
69
|
+
}
|
|
70
|
+
/** Structural view of the V2 plugin setup context. */
|
|
71
|
+
export interface PluginContext {
|
|
72
|
+
readonly options: Readonly<Record<string, unknown>>;
|
|
73
|
+
readonly location: {
|
|
74
|
+
readonly project: {
|
|
75
|
+
readonly directory: string;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
readonly storage: StorageLike;
|
|
79
|
+
readonly event: EventDomainLike;
|
|
80
|
+
readonly session: SessionDomainLike;
|
|
81
|
+
readonly vcs?: VcsDomainLike;
|
|
82
|
+
readonly tool?: ToolDomainLike;
|
|
83
|
+
}
|
package/dist/types.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ever-opencode",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "EverOS persistent memory plugin for OpenCode V2 \u2014 capture each turn, inject recall. Local-first, provider-neutral.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=18"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsc",
|
|
23
|
+
"test": "vitest run",
|
|
24
|
+
"test:integration": "EVEROS_INTEGRATION=1 vitest run integration.live",
|
|
25
|
+
"prepack": "npm run build"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@opencode/plugin": "^2.2.5"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "^24.0.0",
|
|
32
|
+
"typescript": "^5.7.0",
|
|
33
|
+
"vitest": "^3.0.0"
|
|
34
|
+
},
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "git+https://github.com/xeon826/ever-opencode.git"
|
|
38
|
+
},
|
|
39
|
+
"homepage": "https://github.com/xeon826/ever-opencode#readme",
|
|
40
|
+
"bugs": {
|
|
41
|
+
"url": "https://github.com/xeon826/ever-opencode/issues"
|
|
42
|
+
}
|
|
43
|
+
}
|