@fro.bot/opencode-plugin 0.0.0-stage → 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.
- package/LICENSE +76 -0
- package/README.md +34 -2
- package/dist/index.d.mts +6 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +705 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +38 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Fro Bot <agent@fro.bot>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
This package embeds the integration method from cortexkit/orw and redistributes
|
|
26
|
+
a modified build of anomalyco/opencode. Both upstream projects are MIT-licensed.
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
cortexkit/orw (integration method)
|
|
31
|
+
MIT License
|
|
32
|
+
Copyright (c) Cortexkit
|
|
33
|
+
https://github.com/cortexkit/orw
|
|
34
|
+
|
|
35
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
36
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
37
|
+
in the Software without restriction, including without limitation the rights
|
|
38
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
39
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
40
|
+
furnished to do so, subject to the following conditions:
|
|
41
|
+
|
|
42
|
+
The above copyright notice and this permission notice shall be included in all
|
|
43
|
+
copies or substantial portions of the Software.
|
|
44
|
+
|
|
45
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
46
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
47
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
48
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
49
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
50
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
51
|
+
SOFTWARE.
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
anomalyco/opencode (modified binary distribution)
|
|
56
|
+
MIT License
|
|
57
|
+
Copyright (c) 2024 SST Inc.
|
|
58
|
+
https://github.com/anomalyco/opencode
|
|
59
|
+
|
|
60
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
61
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
62
|
+
in the Software without restriction, including without limitation the rights
|
|
63
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
64
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
65
|
+
furnished to do so, subject to the following conditions:
|
|
66
|
+
|
|
67
|
+
The above copyright notice and this permission notice shall be included in all
|
|
68
|
+
copies or substantial portions of the Software.
|
|
69
|
+
|
|
70
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
71
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
72
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
73
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
74
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
75
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
76
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,35 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @fro.bot/opencode-plugin
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Fro Bot's plugin for [OpenCode](https://opencode.ai) V2 (v2.2.0 and later in the 2.x line). It gives the agent two things:
|
|
4
|
+
|
|
5
|
+
- **Session history tools.** `session_list`, `session_read`, `session_search` and `session_info` read the sessions of the current workspace. `session_read` and `session_search` cover a session's active context window: the messages since its last compaction, plus the compaction summary. Todos come from the last completed `todowrite` call in that window.
|
|
6
|
+
- **A subagent reuse guard.** A `subagent` call that carries a `sessionID` is rejected before it runs, with a fixed message that holds no ids. Every subagent starts a fresh child session.
|
|
7
|
+
|
|
8
|
+
The plugin id is `fro-bot.opencode-plugin`. OpenCode V2 skips a plugin that fails to load and keeps serving, so anything that depends on this plugin should check `GET /api/plugin` for that id with status `active`.
|
|
9
|
+
|
|
10
|
+
## Use
|
|
11
|
+
|
|
12
|
+
Install with an exact version, then list the package in the OpenCode config:
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
opencode plugin add @fro.bot/opencode-plugin@<version>
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```json
|
|
19
|
+
{"plugins": ["@fro.bot/opencode-plugin@<version>"]}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
`effect` and `@opencode/plugin` are peer dependencies. OpenCode supplies both at load time, so the bundle never carries its own copy.
|
|
23
|
+
|
|
24
|
+
## Develop
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
bun run --filter @fro.bot/opencode-plugin test # unit tests
|
|
28
|
+
bun run --filter @fro.bot/opencode-plugin build # bundle to dist/
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
`src/integration.test.ts` loads the built bundle into a real OpenCode binary. It is skipped unless `dist/index.mjs` exists and `FRO_BOT_OPENCODE_V2_BIN` points at an OpenCode v2.2.0 executable. Download the release asset for your platform, verify it against the release's `SHA256SUMS`, unpack it into a temporary directory, and delete it afterwards.
|
|
32
|
+
|
|
33
|
+
## Release
|
|
34
|
+
|
|
35
|
+
Dispatch `.github/workflows/opencode-plugin-release.yaml` with the version to publish. It publishes with npm trusted publishing (OIDC). See [`BOOTSTRAP.md`](BOOTSTRAP.md) for the one-time setup.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Plugin } from "@opencode/plugin";
|
|
2
|
+
/** Stable plugin id; the surfaces look it up in `GET /api/plugin` to confirm the plugin is active. */
|
|
3
|
+
export declare const FRO_BOT_PLUGIN_ID = "fro-bot.opencode-plugin";
|
|
4
|
+
declare const _default: Plugin.Plugin;
|
|
5
|
+
export { _default as default };
|
|
6
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/plugin-id.ts","../src/index.ts"],"mappings":";;qBACa"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,705 @@
|
|
|
1
|
+
import { Plugin } from "@opencode/plugin";
|
|
2
|
+
import { Schema } from "effect";
|
|
3
|
+
// src/plugin-id.ts
|
|
4
|
+
/** Stable plugin id; the surfaces look it up in `GET /api/plugin` to confirm the plugin is active. */
|
|
5
|
+
const FRO_BOT_PLUGIN_ID = "fro-bot.opencode-plugin";
|
|
6
|
+
// src/session-client.ts
|
|
7
|
+
const SESSION_ID_PREFIX = "ses";
|
|
8
|
+
const NOT_FOUND_TAG = "Session.NotFoundError";
|
|
9
|
+
function isSessionNotFound(error) {
|
|
10
|
+
return typeof error === "object" && error !== null && Reflect.get(error, "_tag") === NOT_FOUND_TAG;
|
|
11
|
+
}
|
|
12
|
+
function createPluginSessionClient(session) {
|
|
13
|
+
return {
|
|
14
|
+
list: async (query) => session.list(query),
|
|
15
|
+
async get(sessionID) {
|
|
16
|
+
if (!sessionID.startsWith(SESSION_ID_PREFIX)) return null;
|
|
17
|
+
try {
|
|
18
|
+
return await session.get({ sessionID });
|
|
19
|
+
} catch (error) {
|
|
20
|
+
if (isSessionNotFound(error)) return null;
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
messages: async (sessionID) => session.context({ sessionID })
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
// ../../node_modules/@bfra.me/es/lib/chunk-XGJ2KYBN.js
|
|
28
|
+
function ok(value) {
|
|
29
|
+
return {
|
|
30
|
+
success: true,
|
|
31
|
+
data: value
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function err(error) {
|
|
35
|
+
return {
|
|
36
|
+
success: false,
|
|
37
|
+
error
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
// ../runtime/src/session/storage-mappers-v2.ts
|
|
41
|
+
const isRecord = (v) => typeof v === "object" && v != null;
|
|
42
|
+
const readString = (v) => typeof v === "string" ? v : null;
|
|
43
|
+
const readNumber = (v) => typeof v === "number" && Number.isFinite(v) ? v : null;
|
|
44
|
+
/** Strips a `{data}` envelope. A bare payload passes through. */
|
|
45
|
+
function unwrapData(v) {
|
|
46
|
+
return isRecord(v) && !Array.isArray(v) && "data" in v ? v.data : v;
|
|
47
|
+
}
|
|
48
|
+
function mapSessionInfoV2(v) {
|
|
49
|
+
const payload = unwrapData(v);
|
|
50
|
+
if (!isRecord(payload) || Array.isArray(payload)) return null;
|
|
51
|
+
const id = readString(payload.id);
|
|
52
|
+
const projectID = readString(payload.projectID);
|
|
53
|
+
const time = payload.time;
|
|
54
|
+
const location = payload.location;
|
|
55
|
+
if (id == null || projectID == null || !isRecord(time) || !isRecord(location)) return null;
|
|
56
|
+
const created = readNumber(time.created);
|
|
57
|
+
const updated = readNumber(time.updated);
|
|
58
|
+
const directory = readString(location.directory);
|
|
59
|
+
if (created == null || updated == null || directory == null) return null;
|
|
60
|
+
const parentID = readString(payload.parentID);
|
|
61
|
+
const archived = readNumber(time.archived);
|
|
62
|
+
return {
|
|
63
|
+
id,
|
|
64
|
+
projectID,
|
|
65
|
+
directory,
|
|
66
|
+
...parentID == null ? {} : { parentID },
|
|
67
|
+
title: readString(payload.title) ?? "",
|
|
68
|
+
time: {
|
|
69
|
+
created,
|
|
70
|
+
updated,
|
|
71
|
+
...archived == null ? {} : { archived }
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Maps one page of sessions. Returns `null` when the payload is not list-shaped, so a protocol change is not mistaken
|
|
77
|
+
* for "no sessions". Entries that fail to map are dropped.
|
|
78
|
+
*/
|
|
79
|
+
function mapSessionPageV2(v) {
|
|
80
|
+
const items = Array.isArray(v) ? v : isRecord(v) && Array.isArray(v.data) ? v.data : null;
|
|
81
|
+
if (items == null) return null;
|
|
82
|
+
const sessions = [];
|
|
83
|
+
for (const item of items) {
|
|
84
|
+
const mapped = mapSessionInfoV2(item);
|
|
85
|
+
if (mapped != null) sessions.push(mapped);
|
|
86
|
+
}
|
|
87
|
+
const cursor = isRecord(v) ? v.cursor : void 0;
|
|
88
|
+
const nextCursor = isRecord(cursor) ? readString(cursor.next) : null;
|
|
89
|
+
return {
|
|
90
|
+
sessions,
|
|
91
|
+
...nextCursor == null || nextCursor.length === 0 ? {} : { nextCursor }
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
// ../runtime/src/session/storage-message-mappers-v2.ts
|
|
95
|
+
const TODO_TOOL = "todowrite";
|
|
96
|
+
const TODO_STATUSES = [
|
|
97
|
+
"pending",
|
|
98
|
+
"in_progress",
|
|
99
|
+
"completed",
|
|
100
|
+
"cancelled"
|
|
101
|
+
];
|
|
102
|
+
function textPart(messageID, index, kind, text) {
|
|
103
|
+
return {
|
|
104
|
+
id: `${messageID}:${index}`,
|
|
105
|
+
kind,
|
|
106
|
+
text
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/** Joins the text items of a tool result. File items carry no searchable text. */
|
|
110
|
+
function readToolText(content) {
|
|
111
|
+
if (!Array.isArray(content)) return null;
|
|
112
|
+
const texts = content.filter(isRecord).flatMap((item) => {
|
|
113
|
+
const text = item.type === "text" ? readString(item.text) : null;
|
|
114
|
+
return text == null ? [] : [text];
|
|
115
|
+
});
|
|
116
|
+
return texts.length === 0 ? null : texts.join("\n");
|
|
117
|
+
}
|
|
118
|
+
function readTodos(input) {
|
|
119
|
+
if (!isRecord(input) || !Array.isArray(input.todos)) return null;
|
|
120
|
+
const todos = [];
|
|
121
|
+
for (const item of input.todos) {
|
|
122
|
+
if (!isRecord(item)) continue;
|
|
123
|
+
const content = readString(item.content);
|
|
124
|
+
if (content == null) continue;
|
|
125
|
+
const status = TODO_STATUSES.find((candidate) => candidate === item.status);
|
|
126
|
+
todos.push({
|
|
127
|
+
content,
|
|
128
|
+
status: status ?? "pending"
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
return todos;
|
|
132
|
+
}
|
|
133
|
+
function mapAssistantContent(messageID, content) {
|
|
134
|
+
if (!Array.isArray(content)) return { parts: [] };
|
|
135
|
+
const parts = [];
|
|
136
|
+
let todos;
|
|
137
|
+
for (const item of content) {
|
|
138
|
+
if (!isRecord(item)) continue;
|
|
139
|
+
const index = parts.length;
|
|
140
|
+
if (item.type === "text") {
|
|
141
|
+
const text = readString(item.text);
|
|
142
|
+
if (text != null) parts.push(textPart(messageID, index, "text", text));
|
|
143
|
+
} else if (item.type === "reasoning") {
|
|
144
|
+
const text = readString(item.text);
|
|
145
|
+
if (text != null) parts.push(textPart(messageID, index, "reasoning", text));
|
|
146
|
+
} else if (item.type === "tool" && isRecord(item.state) && item.state.status === "completed") {
|
|
147
|
+
const name = readString(item.name);
|
|
148
|
+
const output = readToolText(item.state.content);
|
|
149
|
+
if (name != null && output != null) parts.push(textPart(messageID, index, "tool", `${name}: ${output}`));
|
|
150
|
+
if (name === TODO_TOOL) todos = readTodos(item.state.input) ?? todos;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
parts,
|
|
155
|
+
...todos == null ? {} : { todos }
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
function mapMessageV2(v) {
|
|
159
|
+
if (!isRecord(v)) return null;
|
|
160
|
+
const id = readString(v.id);
|
|
161
|
+
const time = v.time;
|
|
162
|
+
const createdAt = isRecord(time) ? readNumber(time.created) : null;
|
|
163
|
+
if (id == null || createdAt == null) return null;
|
|
164
|
+
if (v.type === "user" || v.type === "synthetic") {
|
|
165
|
+
const text = readString(v.text);
|
|
166
|
+
return {
|
|
167
|
+
id,
|
|
168
|
+
role: "user",
|
|
169
|
+
createdAt,
|
|
170
|
+
parts: text == null ? [] : [textPart(id, 0, "text", text)]
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
if (v.type === "assistant") {
|
|
174
|
+
const agent = readString(v.agent);
|
|
175
|
+
return {
|
|
176
|
+
id,
|
|
177
|
+
role: "assistant",
|
|
178
|
+
...agent == null ? {} : { agent },
|
|
179
|
+
createdAt,
|
|
180
|
+
...mapAssistantContent(id, v.content)
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
if (v.type === "compaction" && v.status === "completed") {
|
|
184
|
+
const summary = readString(v.summary);
|
|
185
|
+
return {
|
|
186
|
+
id,
|
|
187
|
+
role: "assistant",
|
|
188
|
+
createdAt,
|
|
189
|
+
parts: summary == null ? [] : [textPart(id, 0, "text", summary)]
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
/** Maps a message list oldest-first, or `null` when the payload is not list-shaped. */
|
|
195
|
+
function mapMessagesV2(v) {
|
|
196
|
+
const items = unwrapData(v);
|
|
197
|
+
if (!Array.isArray(items)) return null;
|
|
198
|
+
const messages = [];
|
|
199
|
+
for (const item of items) {
|
|
200
|
+
const mapped = mapMessageV2(item);
|
|
201
|
+
if (mapped != null) messages.push(mapped);
|
|
202
|
+
}
|
|
203
|
+
return messages.toSorted((a, b) => a.createdAt - b.createdAt);
|
|
204
|
+
}
|
|
205
|
+
/** The todo list set by the most recent completed `todowrite` call, or an empty list. */
|
|
206
|
+
function latestTodosV2(messages) {
|
|
207
|
+
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
208
|
+
const todos = messages[index]?.todos;
|
|
209
|
+
if (todos != null) return todos;
|
|
210
|
+
}
|
|
211
|
+
return [];
|
|
212
|
+
}
|
|
213
|
+
// ../runtime/src/shared/errors.ts
|
|
214
|
+
/**
|
|
215
|
+
* Extract error message from unknown error.
|
|
216
|
+
* @param error - Unknown value from catch block
|
|
217
|
+
*/
|
|
218
|
+
function toErrorMessage(error) {
|
|
219
|
+
try {
|
|
220
|
+
if (error instanceof Error) return error.message;
|
|
221
|
+
return String(error);
|
|
222
|
+
} catch {
|
|
223
|
+
return "[unprintable error]";
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Wrap unknown error as Error instance.
|
|
228
|
+
* @param error - Unknown value from catch block
|
|
229
|
+
*/
|
|
230
|
+
function toError(error) {
|
|
231
|
+
if (error instanceof Error) return error;
|
|
232
|
+
return new Error(toErrorMessage(error));
|
|
233
|
+
}
|
|
234
|
+
// ../runtime/src/session/storage-v2.ts
|
|
235
|
+
const SESSION_LIST_PAGE_SIZE = 100;
|
|
236
|
+
/** Lists root, unarchived sessions created in `directory` (exact string match), newest first, up to a page bound. */
|
|
237
|
+
async function listSessionsForDirectoryV2(client, directory, logger) {
|
|
238
|
+
const sessions = [];
|
|
239
|
+
let cursor;
|
|
240
|
+
for (let page = 0; page < 10; page += 1) {
|
|
241
|
+
let payload;
|
|
242
|
+
try {
|
|
243
|
+
payload = await client.list({
|
|
244
|
+
directory,
|
|
245
|
+
limit: SESSION_LIST_PAGE_SIZE,
|
|
246
|
+
order: "desc",
|
|
247
|
+
parentID: null,
|
|
248
|
+
archived: false,
|
|
249
|
+
...cursor == null ? {} : { cursor }
|
|
250
|
+
});
|
|
251
|
+
} catch (error) {
|
|
252
|
+
logger.warning("V2 session list failed", {
|
|
253
|
+
source: "listSessionsForDirectoryV2",
|
|
254
|
+
error: toError(error).message
|
|
255
|
+
});
|
|
256
|
+
return err(toError(error));
|
|
257
|
+
}
|
|
258
|
+
const parsed = mapSessionPageV2(payload);
|
|
259
|
+
if (parsed == null) {
|
|
260
|
+
logger.warning("V2 session list returned a payload that is not a session list", {
|
|
261
|
+
source: "listSessionsForDirectoryV2",
|
|
262
|
+
type: typeof payload
|
|
263
|
+
});
|
|
264
|
+
return err(/* @__PURE__ */ new Error("session list response was not a session list"));
|
|
265
|
+
}
|
|
266
|
+
sessions.push(...parsed.sessions);
|
|
267
|
+
if (parsed.sessions.length === 0 || parsed.nextCursor == null || parsed.nextCursor === cursor) break;
|
|
268
|
+
cursor = parsed.nextCursor;
|
|
269
|
+
}
|
|
270
|
+
return ok(sessions);
|
|
271
|
+
}
|
|
272
|
+
/** Resolves to `ok(null)` when the session does not exist. */
|
|
273
|
+
async function getSessionV2(client, sessionID, logger) {
|
|
274
|
+
let payload;
|
|
275
|
+
try {
|
|
276
|
+
payload = await client.get(sessionID);
|
|
277
|
+
} catch (error) {
|
|
278
|
+
logger.warning("V2 session get failed", {
|
|
279
|
+
source: "getSessionV2",
|
|
280
|
+
error: toError(error).message
|
|
281
|
+
});
|
|
282
|
+
return err(toError(error));
|
|
283
|
+
}
|
|
284
|
+
if (payload == null) return ok(null);
|
|
285
|
+
const session = mapSessionInfoV2(payload);
|
|
286
|
+
if (session == null) {
|
|
287
|
+
logger.warning("V2 session get returned an unparseable payload", {
|
|
288
|
+
source: "getSessionV2",
|
|
289
|
+
type: typeof payload
|
|
290
|
+
});
|
|
291
|
+
return err(/* @__PURE__ */ new Error("session response was not a session"));
|
|
292
|
+
}
|
|
293
|
+
return ok(session);
|
|
294
|
+
}
|
|
295
|
+
async function getSessionMessagesV2(client, sessionID, logger) {
|
|
296
|
+
let payload;
|
|
297
|
+
try {
|
|
298
|
+
payload = await client.messages(sessionID);
|
|
299
|
+
} catch (error) {
|
|
300
|
+
logger.warning("V2 session messages failed", {
|
|
301
|
+
source: "getSessionMessagesV2",
|
|
302
|
+
error: toError(error).message
|
|
303
|
+
});
|
|
304
|
+
return err(toError(error));
|
|
305
|
+
}
|
|
306
|
+
const messages = mapMessagesV2(payload);
|
|
307
|
+
if (messages == null) {
|
|
308
|
+
logger.warning("V2 session messages returned a non-list payload", {
|
|
309
|
+
source: "getSessionMessagesV2",
|
|
310
|
+
type: typeof payload
|
|
311
|
+
});
|
|
312
|
+
return err(/* @__PURE__ */ new Error("session messages response was not a message list"));
|
|
313
|
+
}
|
|
314
|
+
return ok(messages);
|
|
315
|
+
}
|
|
316
|
+
const EXCERPT_CONTEXT_CHARS = 50;
|
|
317
|
+
async function listSessionsV2(client, directory, options, logger) {
|
|
318
|
+
const { limit, fromDate, toDate } = options;
|
|
319
|
+
logger.debug("Listing V2 sessions", {
|
|
320
|
+
directory,
|
|
321
|
+
limit
|
|
322
|
+
});
|
|
323
|
+
const listed = await listSessionsForDirectoryV2(client, directory, logger);
|
|
324
|
+
if (!listed.success) return listed;
|
|
325
|
+
const sorted = listed.data.filter((session) => {
|
|
326
|
+
if (session.parentID != null || session.time.archived != null) return false;
|
|
327
|
+
if (fromDate != null && session.time.created < fromDate.getTime()) return false;
|
|
328
|
+
if (toDate != null && session.time.created > toDate.getTime()) return false;
|
|
329
|
+
return true;
|
|
330
|
+
}).toSorted((a, b) => b.time.updated - a.time.updated);
|
|
331
|
+
const limited = limit == null ? sorted : sorted.slice(0, limit);
|
|
332
|
+
logger.info("Listed V2 sessions", {
|
|
333
|
+
count: limited.length,
|
|
334
|
+
directory
|
|
335
|
+
});
|
|
336
|
+
return ok(limited);
|
|
337
|
+
}
|
|
338
|
+
function uniqueAgents(messages) {
|
|
339
|
+
const agents = /* @__PURE__ */ new Set();
|
|
340
|
+
for (const message of messages) if (message.agent != null) agents.add(message.agent);
|
|
341
|
+
return [...agents];
|
|
342
|
+
}
|
|
343
|
+
function searchMessages(messages, pattern, caseSensitive) {
|
|
344
|
+
const matches = [];
|
|
345
|
+
for (const message of messages) for (const part of message.parts) {
|
|
346
|
+
const index = (caseSensitive ? part.text : part.text.toLowerCase()).indexOf(pattern);
|
|
347
|
+
if (index === -1) continue;
|
|
348
|
+
const start = Math.max(0, index - EXCERPT_CONTEXT_CHARS);
|
|
349
|
+
const end = Math.min(part.text.length, index + pattern.length + EXCERPT_CONTEXT_CHARS);
|
|
350
|
+
matches.push({
|
|
351
|
+
messageId: message.id,
|
|
352
|
+
partId: part.id,
|
|
353
|
+
excerpt: `...${part.text.slice(start, end)}...`,
|
|
354
|
+
role: message.role,
|
|
355
|
+
...message.agent == null ? {} : { agent: message.agent }
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
return matches;
|
|
359
|
+
}
|
|
360
|
+
async function searchSessionsV2(query, client, directory, options, logger) {
|
|
361
|
+
const { limit = 20, caseSensitive = false, sessionId, excludeSessionIds = [] } = options;
|
|
362
|
+
const excluded = new Set(excludeSessionIds);
|
|
363
|
+
const pattern = caseSensitive ? query : query.toLowerCase();
|
|
364
|
+
logger.debug("Searching V2 sessions", {
|
|
365
|
+
directory,
|
|
366
|
+
limit,
|
|
367
|
+
caseSensitive
|
|
368
|
+
});
|
|
369
|
+
if (sessionId != null) {
|
|
370
|
+
if (excluded.has(sessionId)) return ok([]);
|
|
371
|
+
const messages = await getSessionMessagesV2(client, sessionId, logger);
|
|
372
|
+
if (!messages.success) return messages;
|
|
373
|
+
const matches = searchMessages(messages.data, pattern, caseSensitive);
|
|
374
|
+
return ok(matches.length === 0 ? [] : [{
|
|
375
|
+
sessionId,
|
|
376
|
+
matches: matches.slice(0, limit)
|
|
377
|
+
}]);
|
|
378
|
+
}
|
|
379
|
+
const listed = await listSessionsV2(client, directory, {}, logger);
|
|
380
|
+
if (!listed.success) return listed;
|
|
381
|
+
const results = [];
|
|
382
|
+
let totalMatches = 0;
|
|
383
|
+
let attempted = 0;
|
|
384
|
+
let succeeded = 0;
|
|
385
|
+
let firstReadError;
|
|
386
|
+
for (const session of listed.data.filter((s) => !excluded.has(s.id)).slice(0, 100)) {
|
|
387
|
+
if (totalMatches >= limit) break;
|
|
388
|
+
attempted += 1;
|
|
389
|
+
const messages = await getSessionMessagesV2(client, session.id, logger);
|
|
390
|
+
if (!messages.success) {
|
|
391
|
+
firstReadError ??= messages.error;
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
succeeded += 1;
|
|
395
|
+
const matches = searchMessages(messages.data, pattern, caseSensitive);
|
|
396
|
+
if (matches.length === 0) continue;
|
|
397
|
+
const kept = matches.slice(0, limit - totalMatches);
|
|
398
|
+
results.push({
|
|
399
|
+
sessionId: session.id,
|
|
400
|
+
matches: kept
|
|
401
|
+
});
|
|
402
|
+
totalMatches += kept.length;
|
|
403
|
+
}
|
|
404
|
+
if (attempted > 0 && succeeded === 0 && firstReadError != null) return err(/* @__PURE__ */ new Error(`could not read any of ${attempted} sessions: ${firstReadError.message}`));
|
|
405
|
+
logger.info("V2 session search complete", {
|
|
406
|
+
resultCount: results.length,
|
|
407
|
+
totalMatches
|
|
408
|
+
});
|
|
409
|
+
return ok(results);
|
|
410
|
+
}
|
|
411
|
+
/** Resolves to `ok(null)` when the session does not exist. */
|
|
412
|
+
async function getSessionInfoV2(client, sessionId, logger) {
|
|
413
|
+
const session = await getSessionV2(client, sessionId, logger);
|
|
414
|
+
if (!session.success) return session;
|
|
415
|
+
if (session.data == null) return ok(null);
|
|
416
|
+
const messages = await getSessionMessagesV2(client, sessionId, logger);
|
|
417
|
+
if (!messages.success) return err(messages.error);
|
|
418
|
+
const todos = latestTodosV2(messages.data);
|
|
419
|
+
return ok({
|
|
420
|
+
session: session.data,
|
|
421
|
+
messageCount: messages.data.length,
|
|
422
|
+
agents: uniqueAgents(messages.data),
|
|
423
|
+
hasTodos: todos.length > 0,
|
|
424
|
+
todoCount: todos.length,
|
|
425
|
+
completedTodos: todos.filter((todo) => todo.status === "completed").length
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
// src/session-tools.ts
|
|
429
|
+
const UNAVAILABLE_PREFIX = "session store unavailable";
|
|
430
|
+
const REASON_MAX_CHARS = 200;
|
|
431
|
+
const SESSION_TOOL_NAMES = {
|
|
432
|
+
list: "session_list",
|
|
433
|
+
read: "session_read",
|
|
434
|
+
search: "session_search",
|
|
435
|
+
info: "session_info"
|
|
436
|
+
};
|
|
437
|
+
/** No-op logger: plugins have no logging channel. */
|
|
438
|
+
const silentLogger = {
|
|
439
|
+
debug: () => {},
|
|
440
|
+
info: () => {},
|
|
441
|
+
warning: () => {},
|
|
442
|
+
error: () => {}
|
|
443
|
+
};
|
|
444
|
+
function unavailable(reason) {
|
|
445
|
+
return `${UNAVAILABLE_PREFIX}: ${reason}`;
|
|
446
|
+
}
|
|
447
|
+
/** One line, capped. Effect tagged errors can have an empty message, so fall back to the tag. */
|
|
448
|
+
function describeFailure(error) {
|
|
449
|
+
let raw;
|
|
450
|
+
if (error instanceof Error) {
|
|
451
|
+
const tag = Reflect.get(error, "_tag");
|
|
452
|
+
raw = error.message.length > 0 ? error.message : typeof tag === "string" ? tag : error.name;
|
|
453
|
+
} else raw = typeof error === "string" ? error : "unknown error";
|
|
454
|
+
const firstLine = raw.split("\n")[0] ?? "";
|
|
455
|
+
return firstLine.length > REASON_MAX_CHARS ? `${firstLine.slice(0, REASON_MAX_CHARS)}...` : firstLine;
|
|
456
|
+
}
|
|
457
|
+
function asString(value) {
|
|
458
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
459
|
+
}
|
|
460
|
+
function asNumber(value) {
|
|
461
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
462
|
+
}
|
|
463
|
+
function asBoolean(value) {
|
|
464
|
+
return typeof value === "boolean" ? value : void 0;
|
|
465
|
+
}
|
|
466
|
+
function parseDate(value) {
|
|
467
|
+
if (value == null) return void 0;
|
|
468
|
+
const parsed = new Date(value);
|
|
469
|
+
return Number.isNaN(parsed.getTime()) ? void 0 : parsed;
|
|
470
|
+
}
|
|
471
|
+
/** Parses a `to_date` bound to the END of that day (inclusive upper bound). */
|
|
472
|
+
function parseEndOfDayDate(value) {
|
|
473
|
+
const parsed = parseDate(value);
|
|
474
|
+
if (parsed == null) return void 0;
|
|
475
|
+
const endOfDay = new Date(parsed);
|
|
476
|
+
endOfDay.setUTCHours(23, 59, 59, 999);
|
|
477
|
+
return endOfDay;
|
|
478
|
+
}
|
|
479
|
+
/** Any limit below 1 (including negative values) means "no limit". */
|
|
480
|
+
function normalizeLimit(value) {
|
|
481
|
+
return value == null || value < 1 ? void 0 : value;
|
|
482
|
+
}
|
|
483
|
+
function formatTimestamp(ms) {
|
|
484
|
+
return new Date(ms).toISOString();
|
|
485
|
+
}
|
|
486
|
+
function titleOf(session) {
|
|
487
|
+
return session.title.length > 0 ? session.title : "(untitled)";
|
|
488
|
+
}
|
|
489
|
+
function formatMessageForTranscript(message) {
|
|
490
|
+
const text = message.parts.map((part) => part.text).join(" ");
|
|
491
|
+
return text.length > 0 ? `[${message.role}] ${text}` : `[${message.role}] (no content)`;
|
|
492
|
+
}
|
|
493
|
+
/** Renders messages oldest-first, capping total rendered size so a huge transcript can't blow the response. */
|
|
494
|
+
function renderTranscript(messages) {
|
|
495
|
+
const lines = [];
|
|
496
|
+
let size = 0;
|
|
497
|
+
let shown = 0;
|
|
498
|
+
for (const message of messages) {
|
|
499
|
+
const line = ` ${formatMessageForTranscript(message)}`;
|
|
500
|
+
if (size + line.length > 48e3) break;
|
|
501
|
+
lines.push(line);
|
|
502
|
+
size += line.length;
|
|
503
|
+
shown += 1;
|
|
504
|
+
}
|
|
505
|
+
if (shown < messages.length) lines.push(` ... transcript truncated (${shown} of ${messages.length} messages shown)`);
|
|
506
|
+
return lines;
|
|
507
|
+
}
|
|
508
|
+
function sessionHeader(session) {
|
|
509
|
+
return [
|
|
510
|
+
`Session ${session.id}`,
|
|
511
|
+
`Title: ${titleOf(session)}`,
|
|
512
|
+
`Created: ${formatTimestamp(session.time.created)}`,
|
|
513
|
+
`Updated: ${formatTimestamp(session.time.updated)}`
|
|
514
|
+
];
|
|
515
|
+
}
|
|
516
|
+
const CONTEXT_WINDOW_NOTE = "Covers the session's active context window: messages since its last compaction, plus the compaction summary.";
|
|
517
|
+
const ListInput = Schema.Struct({
|
|
518
|
+
limit: Schema.optionalKey(Schema.Number).annotate({ description: "Maximum number of sessions to return." }),
|
|
519
|
+
from_date: Schema.optionalKey(Schema.String).annotate({ description: "Only include sessions created on or after this date (YYYY-MM-DD)." }),
|
|
520
|
+
to_date: Schema.optionalKey(Schema.String).annotate({ description: "Only include sessions created on or before this date (YYYY-MM-DD)." }),
|
|
521
|
+
project_path: Schema.optionalKey(Schema.String).annotate({ description: "Workspace/project directory to list sessions for." })
|
|
522
|
+
});
|
|
523
|
+
const ReadInput = Schema.Struct({
|
|
524
|
+
session_id: Schema.String.annotate({ description: "The session id to read (required)." }),
|
|
525
|
+
include_todos: Schema.optionalKey(Schema.Boolean).annotate({ description: "Include the session todo list." }),
|
|
526
|
+
include_transcript: Schema.optionalKey(Schema.Boolean).annotate({ description: "Include the message transcript." }),
|
|
527
|
+
limit: Schema.optionalKey(Schema.Number).annotate({ description: "Maximum number of transcript messages to include." })
|
|
528
|
+
});
|
|
529
|
+
const SearchInput = Schema.Struct({
|
|
530
|
+
query: Schema.String.annotate({ description: "Text to search for (required)." }),
|
|
531
|
+
session_id: Schema.optionalKey(Schema.String).annotate({ description: "Restrict the search to a single session id." }),
|
|
532
|
+
case_sensitive: Schema.optionalKey(Schema.Boolean).annotate({ description: "Match case-sensitively." }),
|
|
533
|
+
limit: Schema.optionalKey(Schema.Number).annotate({ description: "Maximum number of matches to return." })
|
|
534
|
+
});
|
|
535
|
+
const InfoInput = Schema.Struct({ session_id: Schema.String.annotate({ description: "The session id to summarize (required)." }) });
|
|
536
|
+
/**
|
|
537
|
+
* Builds the four tool definitions against an injected client. `directory` is the workspace the tools default to:
|
|
538
|
+
* `session_list` honours a `project_path` override, `session_search` always searches the workspace.
|
|
539
|
+
*/
|
|
540
|
+
function createSessionTools(options) {
|
|
541
|
+
const { client, directory } = options;
|
|
542
|
+
const logger = silentLogger;
|
|
543
|
+
return {
|
|
544
|
+
list: {
|
|
545
|
+
name: SESSION_TOOL_NAMES.list,
|
|
546
|
+
description: "List recent OpenCode sessions for the current workspace, most recently updated first.",
|
|
547
|
+
input: ListInput,
|
|
548
|
+
async run(args) {
|
|
549
|
+
try {
|
|
550
|
+
const sessions = await listSessionsV2(client, asString(args.project_path) ?? directory, {
|
|
551
|
+
limit: normalizeLimit(asNumber(args.limit)),
|
|
552
|
+
fromDate: parseDate(asString(args.from_date)),
|
|
553
|
+
toDate: parseEndOfDayDate(asString(args.to_date))
|
|
554
|
+
}, logger);
|
|
555
|
+
if (!sessions.success) return unavailable(describeFailure(sessions.error));
|
|
556
|
+
if (sessions.data.length === 0) return "No sessions found.";
|
|
557
|
+
return sessions.data.map((session) => `${session.id} ${titleOf(session)} updated ${formatTimestamp(session.time.updated)}`).join("\n");
|
|
558
|
+
} catch (error) {
|
|
559
|
+
return unavailable(describeFailure(error));
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
},
|
|
563
|
+
read: {
|
|
564
|
+
name: SESSION_TOOL_NAMES.read,
|
|
565
|
+
description: `Read a session: header, optional todos, and optional transcript. ${CONTEXT_WINDOW_NOTE}`,
|
|
566
|
+
input: ReadInput,
|
|
567
|
+
async run(args) {
|
|
568
|
+
const sessionId = asString(args.session_id);
|
|
569
|
+
if (sessionId == null) return unavailable("session_id is required");
|
|
570
|
+
try {
|
|
571
|
+
const found = await getSessionV2(client, sessionId, logger);
|
|
572
|
+
if (!found.success) return unavailable(describeFailure(found.error));
|
|
573
|
+
if (found.data == null) return `session not found: ${sessionId}`;
|
|
574
|
+
const lines = sessionHeader(found.data);
|
|
575
|
+
const includeTodos = asBoolean(args.include_todos) === true;
|
|
576
|
+
const includeTranscript = asBoolean(args.include_transcript) === true;
|
|
577
|
+
if (!includeTodos && !includeTranscript) return lines.join("\n");
|
|
578
|
+
const messages = await getSessionMessagesV2(client, sessionId, logger);
|
|
579
|
+
if (!messages.success) return unavailable(describeFailure(messages.error));
|
|
580
|
+
if (includeTodos) {
|
|
581
|
+
const todos = latestTodosV2(messages.data);
|
|
582
|
+
lines.push("", "Todos:");
|
|
583
|
+
if (todos.length === 0) lines.push(" (none)");
|
|
584
|
+
else for (const todo of todos) lines.push(` [${todo.status}] ${todo.content}`);
|
|
585
|
+
}
|
|
586
|
+
if (includeTranscript) {
|
|
587
|
+
const limit = normalizeLimit(asNumber(args.limit));
|
|
588
|
+
const sliced = limit == null ? messages.data : messages.data.slice(0, limit);
|
|
589
|
+
lines.push("", "Transcript:");
|
|
590
|
+
if (sliced.length === 0) lines.push(" (empty)");
|
|
591
|
+
else lines.push(...renderTranscript(sliced));
|
|
592
|
+
}
|
|
593
|
+
return lines.join("\n");
|
|
594
|
+
} catch (error) {
|
|
595
|
+
return unavailable(describeFailure(error));
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
},
|
|
599
|
+
search: {
|
|
600
|
+
name: SESSION_TOOL_NAMES.search,
|
|
601
|
+
description: `Search prior session content for matching text, optionally scoped to one session. ${CONTEXT_WINDOW_NOTE}`,
|
|
602
|
+
input: SearchInput,
|
|
603
|
+
async run(args) {
|
|
604
|
+
const query = asString(args.query);
|
|
605
|
+
if (query == null) return unavailable("query is required");
|
|
606
|
+
try {
|
|
607
|
+
const scopedSessionId = asString(args.session_id);
|
|
608
|
+
if (scopedSessionId != null) {
|
|
609
|
+
const found = await getSessionV2(client, scopedSessionId, logger);
|
|
610
|
+
if (!found.success) return unavailable(describeFailure(found.error));
|
|
611
|
+
if (found.data == null) return `session not found: ${scopedSessionId}`;
|
|
612
|
+
}
|
|
613
|
+
const results = await searchSessionsV2(query, client, directory, {
|
|
614
|
+
limit: normalizeLimit(asNumber(args.limit)),
|
|
615
|
+
caseSensitive: asBoolean(args.case_sensitive),
|
|
616
|
+
sessionId: scopedSessionId
|
|
617
|
+
}, logger);
|
|
618
|
+
if (!results.success) return unavailable(describeFailure(results.error));
|
|
619
|
+
if (results.data.length === 0) return "No matches found.";
|
|
620
|
+
const lines = [];
|
|
621
|
+
for (const result of results.data) {
|
|
622
|
+
lines.push(`Session ${result.sessionId}:`);
|
|
623
|
+
for (const match of result.matches) lines.push(` [${match.role}${match.agent == null ? "" : `/${match.agent}`}] ${match.excerpt}`);
|
|
624
|
+
}
|
|
625
|
+
return lines.join("\n");
|
|
626
|
+
} catch (error) {
|
|
627
|
+
return unavailable(describeFailure(error));
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
},
|
|
631
|
+
info: {
|
|
632
|
+
name: SESSION_TOOL_NAMES.info,
|
|
633
|
+
description: `Summarize a session: id, title, timestamps, message and todo counts. ${CONTEXT_WINDOW_NOTE}`,
|
|
634
|
+
input: InfoInput,
|
|
635
|
+
async run(args) {
|
|
636
|
+
const sessionId = asString(args.session_id);
|
|
637
|
+
if (sessionId == null) return unavailable("session_id is required");
|
|
638
|
+
try {
|
|
639
|
+
const details = await getSessionInfoV2(client, sessionId, logger);
|
|
640
|
+
if (!details.success) return unavailable(describeFailure(details.error));
|
|
641
|
+
if (details.data == null) return `session not found: ${sessionId}`;
|
|
642
|
+
const { session, messageCount, agents, hasTodos, todoCount, completedTodos } = details.data;
|
|
643
|
+
return [
|
|
644
|
+
...sessionHeader(session),
|
|
645
|
+
`Messages: ${messageCount}`,
|
|
646
|
+
`Agents: ${agents.length > 0 ? agents.join(", ") : "(none)"}`,
|
|
647
|
+
`Todos: ${hasTodos ? `${completedTodos}/${todoCount} completed` : "(none)"}`
|
|
648
|
+
].join("\n");
|
|
649
|
+
} catch (error) {
|
|
650
|
+
return unavailable(describeFailure(error));
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
// src/task-reuse-guard.ts
|
|
657
|
+
/** Rejects `subagent` calls that resume a child session via `sessionID`, via the `execute.before` tool hook. */
|
|
658
|
+
/** The model-visible rejection text; it carries no ids or arguments. */
|
|
659
|
+
const TASK_REUSE_REJECTION = "Session reuse is disabled in this environment. Start a new task and include the context it needs.";
|
|
660
|
+
/** A resume is any `sessionID` other than absent, null or `""` (upstream treats `""` as absent); malformed values reject. */
|
|
661
|
+
function carriesResume(input) {
|
|
662
|
+
if (input === null || typeof input !== "object" || Array.isArray(input)) return false;
|
|
663
|
+
const sessionID = Reflect.get(input, "sessionID");
|
|
664
|
+
return sessionID !== void 0 && sessionID !== null && sessionID !== "";
|
|
665
|
+
}
|
|
666
|
+
function rejectSubagentReuse(event) {
|
|
667
|
+
if (event.tool !== "subagent") return;
|
|
668
|
+
if (carriesResume(event.input)) throw new Error(TASK_REUSE_REJECTION);
|
|
669
|
+
}
|
|
670
|
+
// src/setup.ts
|
|
671
|
+
async function setupFroBotPlugin(host) {
|
|
672
|
+
await host.tool.hook("execute.before", async (event) => {
|
|
673
|
+
rejectSubagentReuse(event);
|
|
674
|
+
});
|
|
675
|
+
const tools = createSessionTools({
|
|
676
|
+
client: createPluginSessionClient(host.session),
|
|
677
|
+
directory: host.location.directory
|
|
678
|
+
});
|
|
679
|
+
await host.tool.transform((editor) => {
|
|
680
|
+
for (const spec of [
|
|
681
|
+
tools.list,
|
|
682
|
+
tools.read,
|
|
683
|
+
tools.search,
|
|
684
|
+
tools.info
|
|
685
|
+
]) {
|
|
686
|
+
const tool = {
|
|
687
|
+
name: spec.name,
|
|
688
|
+
options: { codemode: false },
|
|
689
|
+
description: spec.description,
|
|
690
|
+
input: spec.input,
|
|
691
|
+
execute: async (input) => ({ content: await spec.run(input) })
|
|
692
|
+
};
|
|
693
|
+
editor.add(tool);
|
|
694
|
+
}
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
// src/index.ts
|
|
698
|
+
/** `@fro.bot/opencode-plugin`: the session tools and the subagent session-reuse guard. */
|
|
699
|
+
var src_default = Plugin.define({
|
|
700
|
+
id: FRO_BOT_PLUGIN_ID,
|
|
701
|
+
setup: async (ctx) => setupFroBotPlugin(ctx)
|
|
702
|
+
});
|
|
703
|
+
export { FRO_BOT_PLUGIN_ID, src_default as default };
|
|
704
|
+
|
|
705
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/plugin-id.ts","../src/session-client.ts","../../../node_modules/@bfra.me/es/lib/chunk-XGJ2KYBN.js","../../runtime/src/session/storage-mappers-v2.ts","../../runtime/src/session/storage-message-mappers-v2.ts","../../runtime/src/shared/errors.ts","../../runtime/src/session/storage-v2.ts","../../runtime/src/session/search-v2.ts","../src/session-tools.ts","../src/task-reuse-guard.ts","../src/setup.ts","../src/index.ts"],"sourcesContent":["/** Stable plugin id; the surfaces look it up in `GET /api/plugin` to confirm the plugin is active. */\nexport const FRO_BOT_PLUGIN_ID = 'fro-bot.opencode-plugin'\n","/** Adapts the plugin context's `ctx.session` to the runtime's `SessionClientV2`. */\n\nimport type {SessionClientV2, SessionListQueryV2} from '@fro-bot/runtime/session-v2'\n\n/** The slice of `ctx.session` this package reads; method syntax so the branded `SessionID` parameter still fits. */\nexport interface PluginSessionApi {\n list: (query: SessionListQueryV2) => Promise<unknown>\n get: (input: {readonly sessionID: string}) => Promise<unknown>\n context: (input: {readonly sessionID: string}) => Promise<unknown>\n}\n\nconst SESSION_ID_PREFIX = 'ses'\nconst NOT_FOUND_TAG = 'Session.NotFoundError'\n\nexport function isSessionNotFound(error: unknown): boolean {\n return typeof error === 'object' && error !== null && Reflect.get(error, '_tag') === NOT_FOUND_TAG\n}\n\nexport function createPluginSessionClient(session: PluginSessionApi): SessionClientV2 {\n return {\n list: async query => session.list(query),\n async get(sessionID) {\n // The server rejects such an id with a SchemaError, which would read as an outage.\n if (!sessionID.startsWith(SESSION_ID_PREFIX)) return null\n try {\n return await session.get({sessionID})\n } catch (error) {\n if (isSessionNotFound(error)) return null\n throw error\n }\n },\n messages: async sessionID => session.context({sessionID}),\n }\n}\n","// src/result/factories.ts\nfunction ok(value) {\n return { success: true, data: value };\n}\nfunction err(error) {\n return { success: false, error };\n}\n\nexport {\n ok,\n err\n};\n//# sourceMappingURL=chunk-XGJ2KYBN.js.map","/** V2 sibling of `storage-mappers.ts`: parse raw V2 session payloads; every mapper takes `unknown` and never throws. */\n\nimport type {SessionInfoV2} from './types-v2.js'\n\nexport const isRecord = (v: unknown): v is Record<string, unknown> => typeof v === 'object' && v != null\nexport const readString = (v: unknown): string | null => (typeof v === 'string' ? v : null)\nexport const readNumber = (v: unknown): number | null => (typeof v === 'number' && Number.isFinite(v) ? v : null)\n\n/** Strips a `{data}` envelope. A bare payload passes through. */\nexport function unwrapData(v: unknown): unknown {\n return isRecord(v) && !Array.isArray(v) && 'data' in v ? v.data : v\n}\n\nexport function mapSessionInfoV2(v: unknown): SessionInfoV2 | null {\n const payload = unwrapData(v)\n if (!isRecord(payload) || Array.isArray(payload)) return null\n\n const id = readString(payload.id)\n const projectID = readString(payload.projectID)\n const time = payload.time\n const location = payload.location\n if (id == null || projectID == null || !isRecord(time) || !isRecord(location)) return null\n\n const created = readNumber(time.created)\n const updated = readNumber(time.updated)\n const directory = readString(location.directory)\n if (created == null || updated == null || directory == null) return null\n\n const parentID = readString(payload.parentID)\n const archived = readNumber(time.archived)\n return {\n id,\n projectID,\n directory,\n ...(parentID == null ? {} : {parentID}),\n title: readString(payload.title) ?? '',\n time: {created, updated, ...(archived == null ? {} : {archived})},\n }\n}\n\nexport interface SessionPageV2 {\n readonly sessions: readonly SessionInfoV2[]\n readonly nextCursor?: string\n}\n\n/**\n * Maps one page of sessions. Returns `null` when the payload is not list-shaped, so a protocol change is not mistaken\n * for \"no sessions\". Entries that fail to map are dropped.\n */\nexport function mapSessionPageV2(v: unknown): SessionPageV2 | null {\n const items = Array.isArray(v) ? v : isRecord(v) && Array.isArray(v.data) ? v.data : null\n if (items == null) return null\n\n const sessions: SessionInfoV2[] = []\n for (const item of items) {\n const mapped = mapSessionInfoV2(item)\n if (mapped != null) sessions.push(mapped)\n }\n\n const cursor = isRecord(v) ? v.cursor : undefined\n const nextCursor = isRecord(cursor) ? readString(cursor.next) : null\n return {sessions, ...(nextCursor == null || nextCursor.length === 0 ? {} : {nextCursor})}\n}\n","/** V2 sibling of `storage-message-mappers.ts`: flatten V2 session messages (user, synthetic, assistant, compaction). */\n\nimport type {MessageV2, PartV2, TodoItemV2} from './types-v2.js'\n\nimport {isRecord, readNumber, readString, unwrapData} from './storage-mappers-v2.js'\n\nconst TODO_TOOL = 'todowrite'\nconst TODO_STATUSES: readonly TodoItemV2['status'][] = ['pending', 'in_progress', 'completed', 'cancelled']\n\nfunction textPart(messageID: string, index: number, kind: PartV2['kind'], text: string): PartV2 {\n return {id: `${messageID}:${index}`, kind, text}\n}\n\n/** Joins the text items of a tool result. File items carry no searchable text. */\nfunction readToolText(content: unknown): string | null {\n if (!Array.isArray(content)) return null\n const texts = content.filter(isRecord).flatMap(item => {\n const text = item.type === 'text' ? readString(item.text) : null\n return text == null ? [] : [text]\n })\n return texts.length === 0 ? null : texts.join('\\n')\n}\n\nfunction readTodos(input: unknown): readonly TodoItemV2[] | null {\n if (!isRecord(input) || !Array.isArray(input.todos)) return null\n const todos: TodoItemV2[] = []\n for (const item of input.todos) {\n if (!isRecord(item)) continue\n const content = readString(item.content)\n if (content == null) continue\n const status = TODO_STATUSES.find(candidate => candidate === item.status)\n todos.push({content, status: status ?? 'pending'})\n }\n return todos\n}\n\nfunction mapAssistantContent(\n messageID: string,\n content: unknown,\n): {readonly parts: readonly PartV2[]; readonly todos?: readonly TodoItemV2[]} {\n if (!Array.isArray(content)) return {parts: []}\n\n const parts: PartV2[] = []\n let todos: readonly TodoItemV2[] | undefined\n for (const item of content) {\n if (!isRecord(item)) continue\n const index = parts.length\n if (item.type === 'text') {\n const text = readString(item.text)\n if (text != null) parts.push(textPart(messageID, index, 'text', text))\n } else if (item.type === 'reasoning') {\n const text = readString(item.text)\n if (text != null) parts.push(textPart(messageID, index, 'reasoning', text))\n } else if (item.type === 'tool' && isRecord(item.state) && item.state.status === 'completed') {\n const name = readString(item.name)\n const output = readToolText(item.state.content)\n if (name != null && output != null) parts.push(textPart(messageID, index, 'tool', `${name}: ${output}`))\n if (name === TODO_TOOL) todos = readTodos(item.state.input) ?? todos\n }\n }\n return {parts, ...(todos == null ? {} : {todos})}\n}\n\nfunction mapMessageV2(v: unknown): MessageV2 | null {\n if (!isRecord(v)) return null\n const id = readString(v.id)\n const time = v.time\n const createdAt = isRecord(time) ? readNumber(time.created) : null\n if (id == null || createdAt == null) return null\n\n if (v.type === 'user' || v.type === 'synthetic') {\n const text = readString(v.text)\n return {id, role: 'user', createdAt, parts: text == null ? [] : [textPart(id, 0, 'text', text)]}\n }\n if (v.type === 'assistant') {\n const agent = readString(v.agent)\n return {\n id,\n role: 'assistant',\n ...(agent == null ? {} : {agent}),\n createdAt,\n ...mapAssistantContent(id, v.content),\n }\n }\n // A completed compaction is the only record of what came before the active window, so keep its summary searchable.\n if (v.type === 'compaction' && v.status === 'completed') {\n const summary = readString(v.summary)\n return {id, role: 'assistant', createdAt, parts: summary == null ? [] : [textPart(id, 0, 'text', summary)]}\n }\n return null\n}\n\n/** Maps a message list oldest-first, or `null` when the payload is not list-shaped. */\nexport function mapMessagesV2(v: unknown): readonly MessageV2[] | null {\n const items = unwrapData(v)\n if (!Array.isArray(items)) return null\n\n const messages: MessageV2[] = []\n for (const item of items) {\n const mapped = mapMessageV2(item)\n if (mapped != null) messages.push(mapped)\n }\n return messages.toSorted((a, b) => a.createdAt - b.createdAt)\n}\n\n/** The todo list set by the most recent completed `todowrite` call, or an empty list. */\nexport function latestTodosV2(messages: readonly MessageV2[]): readonly TodoItemV2[] {\n for (let index = messages.length - 1; index >= 0; index -= 1) {\n const todos = messages[index]?.todos\n if (todos != null) return todos\n }\n return []\n}\n","/**\n * Extract error message from unknown error.\n * @param error - Unknown value from catch block\n */\nexport function toErrorMessage(error: unknown): string {\n // A payload-owned coercion path (non-callable `toString`, a null prototype, or a throwing\n // getter) can make extraction itself throw; never let that escape an error-reporting helper.\n try {\n if (error instanceof Error) {\n return error.message\n }\n return String(error)\n } catch {\n return '[unprintable error]'\n }\n}\n\n/**\n * Wrap unknown error as Error instance.\n * @param error - Unknown value from catch block\n */\nexport function toError(error: unknown): Error {\n if (error instanceof Error) {\n return error\n }\n return new Error(toErrorMessage(error))\n}\n\n/** Longest string `formatSdkError` returns; longer messages and JSON are cut with a trailing `...`. */\nexport const SDK_ERROR_MAX_LENGTH = 500\n\nfunction nonEmptyString(value: unknown): string | undefined {\n return typeof value === 'string' && value.length > 0 ? value : undefined\n}\n\nfunction bounded(text: string): string {\n return text.length > SDK_ERROR_MAX_LENGTH ? `${text.slice(0, SDK_ERROR_MAX_LENGTH - 3)}...` : text\n}\n\n/**\n * Describe the `error` of an OpenCode SDK result for a log line or an error message.\n *\n * The SDK client does not throw on an HTTP error; it returns `{error}` where `error` is the parsed response body:\n * a plain object for a JSON body (`{name: 'NotFoundError', data: {message}}`), a string for a text body. `String()`\n * of the object is `[object Object]`, which hides the cause.\n *\n * Picks, in order: `data.message`, `message`, `name`, `type`; an Error gives its message; a string is returned as\n * is. Any other object is serialised as JSON. The result is cut at `SDK_ERROR_MAX_LENGTH`. Only the value it is\n * given is read, so no request header or body can appear. Never throws: anything unreadable or unserialisable\n * (circular, BigInt, a throwing getter) is `[unprintable error]`.\n */\nexport function formatSdkError(error: unknown): string {\n try {\n if (typeof error !== 'object' || error === null || error instanceof Error) return bounded(toErrorMessage(error))\n\n const envelope = error as {\n readonly data?: unknown\n readonly message?: unknown\n readonly name?: unknown\n readonly type?: unknown\n }\n const data =\n typeof envelope.data === 'object' && envelope.data !== null\n ? (envelope.data as {readonly message?: unknown})\n : undefined\n const described =\n nonEmptyString(data?.message) ??\n nonEmptyString(envelope.message) ??\n nonEmptyString(envelope.name) ??\n nonEmptyString(envelope.type)\n return bounded(described ?? JSON.stringify(error))\n } catch {\n return '[unprintable error]'\n }\n}\n","/** V2 sibling of `storage.ts`: reads against a `SessionClientV2`, returning a `Result` so an outage is not \"no sessions\". */\n\nimport type {Result} from '@bfra.me/es/result'\nimport type {Logger} from '../shared/logger.js'\nimport type {SessionClientV2} from './backend-v2.js'\nimport type {MessageV2, SessionInfoV2, TodoItemV2} from './types-v2.js'\n\nimport {err, ok} from '@bfra.me/es/result'\nimport {toError} from '../shared/errors.js'\nimport {mapSessionInfoV2, mapSessionPageV2} from './storage-mappers-v2.js'\nimport {latestTodosV2, mapMessagesV2} from './storage-message-mappers-v2.js'\n\nconst SESSION_LIST_PAGE_SIZE = 100\n\n/** Upper bound on pages followed per listing: 10 pages of 100 sessions. */\nexport const SESSION_LIST_MAX_PAGES = 10\n\n/** Lists root, unarchived sessions created in `directory` (exact string match), newest first, up to a page bound. */\nexport async function listSessionsForDirectoryV2(\n client: SessionClientV2,\n directory: string,\n logger: Logger,\n): Promise<Result<readonly SessionInfoV2[], Error>> {\n const sessions: SessionInfoV2[] = []\n let cursor: string | undefined\n\n for (let page = 0; page < SESSION_LIST_MAX_PAGES; page += 1) {\n let payload: unknown\n try {\n payload = await client.list({\n directory,\n limit: SESSION_LIST_PAGE_SIZE,\n order: 'desc',\n parentID: null,\n archived: false,\n ...(cursor == null ? {} : {cursor}),\n })\n } catch (error) {\n logger.warning('V2 session list failed', {source: 'listSessionsForDirectoryV2', error: toError(error).message})\n return err(toError(error))\n }\n\n const parsed = mapSessionPageV2(payload)\n if (parsed == null) {\n logger.warning('V2 session list returned a payload that is not a session list', {\n source: 'listSessionsForDirectoryV2',\n type: typeof payload,\n })\n return err(new Error('session list response was not a session list'))\n }\n\n sessions.push(...parsed.sessions)\n // Stop on an empty page or a cursor that did not advance.\n if (parsed.sessions.length === 0 || parsed.nextCursor == null || parsed.nextCursor === cursor) break\n cursor = parsed.nextCursor\n }\n\n return ok(sessions)\n}\n\n/** Resolves to `ok(null)` when the session does not exist. */\nexport async function getSessionV2(\n client: SessionClientV2,\n sessionID: string,\n logger: Logger,\n): Promise<Result<SessionInfoV2 | null, Error>> {\n let payload: unknown\n try {\n payload = await client.get(sessionID)\n } catch (error) {\n logger.warning('V2 session get failed', {source: 'getSessionV2', error: toError(error).message})\n return err(toError(error))\n }\n\n if (payload == null) return ok(null)\n const session = mapSessionInfoV2(payload)\n if (session == null) {\n logger.warning('V2 session get returned an unparseable payload', {source: 'getSessionV2', type: typeof payload})\n return err(new Error('session response was not a session'))\n }\n return ok(session)\n}\n\nexport async function getSessionMessagesV2(\n client: SessionClientV2,\n sessionID: string,\n logger: Logger,\n): Promise<Result<readonly MessageV2[], Error>> {\n let payload: unknown\n try {\n payload = await client.messages(sessionID)\n } catch (error) {\n logger.warning('V2 session messages failed', {source: 'getSessionMessagesV2', error: toError(error).message})\n return err(toError(error))\n }\n\n const messages = mapMessagesV2(payload)\n if (messages == null) {\n logger.warning('V2 session messages returned a non-list payload', {\n source: 'getSessionMessagesV2',\n type: typeof payload,\n })\n return err(new Error('session messages response was not a message list'))\n }\n return ok(messages)\n}\n\n/** V2 has no todo endpoint; the list is whatever the last completed `todowrite` call in the readable messages set. */\nexport async function getSessionTodosV2(\n client: SessionClientV2,\n sessionID: string,\n logger: Logger,\n): Promise<Result<readonly TodoItemV2[], Error>> {\n const messages = await getSessionMessagesV2(client, sessionID, logger)\n return messages.success ? ok(latestTodosV2(messages.data)) : messages\n}\n","/** V2 sibling of `search.ts`: listing, content search (reads at most `SEARCH_MAX_SESSIONS` sessions) and summaries. */\n\nimport type {Result} from '@bfra.me/es/result'\nimport type {Logger} from '../shared/logger.js'\nimport type {SessionClientV2} from './backend-v2.js'\nimport type {MessageV2, SessionInfoV2, TodoItemV2} from './types-v2.js'\nimport type {SessionMatch, SessionSearchResult} from './types.js'\n\nimport {err, ok} from '@bfra.me/es/result'\nimport {latestTodosV2} from './storage-message-mappers-v2.js'\nimport {getSessionMessagesV2, getSessionV2, listSessionsForDirectoryV2} from './storage-v2.js'\n\n/** Most sessions one content search will read. */\nexport const SEARCH_MAX_SESSIONS = 100\n\nconst EXCERPT_CONTEXT_CHARS = 50\n\nexport async function listSessionsV2(\n client: SessionClientV2,\n directory: string,\n options: {readonly limit?: number; readonly fromDate?: Date; readonly toDate?: Date},\n logger: Logger,\n): Promise<Result<readonly SessionInfoV2[], Error>> {\n const {limit, fromDate, toDate} = options\n logger.debug('Listing V2 sessions', {directory, limit})\n\n const listed = await listSessionsForDirectoryV2(client, directory, logger)\n if (!listed.success) return listed\n\n // Filter again in case the server ignores the root and unarchived query filters.\n const filtered = listed.data.filter(session => {\n if (session.parentID != null || session.time.archived != null) return false\n if (fromDate != null && session.time.created < fromDate.getTime()) return false\n if (toDate != null && session.time.created > toDate.getTime()) return false\n return true\n })\n\n const sorted = filtered.toSorted((a, b) => b.time.updated - a.time.updated)\n const limited = limit == null ? sorted : sorted.slice(0, limit)\n logger.info('Listed V2 sessions', {count: limited.length, directory})\n return ok(limited)\n}\n\nfunction uniqueAgents(messages: readonly MessageV2[]): readonly string[] {\n const agents = new Set<string>()\n for (const message of messages) {\n if (message.agent != null) agents.add(message.agent)\n }\n return [...agents]\n}\n\nfunction searchMessages(\n messages: readonly MessageV2[],\n pattern: string,\n caseSensitive: boolean,\n): readonly SessionMatch[] {\n const matches: SessionMatch[] = []\n for (const message of messages) {\n for (const part of message.parts) {\n const searchText = caseSensitive ? part.text : part.text.toLowerCase()\n const index = searchText.indexOf(pattern)\n if (index === -1) continue\n\n const start = Math.max(0, index - EXCERPT_CONTEXT_CHARS)\n const end = Math.min(part.text.length, index + pattern.length + EXCERPT_CONTEXT_CHARS)\n matches.push({\n messageId: message.id,\n partId: part.id,\n excerpt: `...${part.text.slice(start, end)}...`,\n role: message.role,\n ...(message.agent == null ? {} : {agent: message.agent}),\n })\n }\n }\n return matches\n}\n\nexport async function searchSessionsV2(\n query: string,\n client: SessionClientV2,\n directory: string,\n options: {\n readonly limit?: number\n readonly caseSensitive?: boolean\n readonly sessionId?: string\n readonly excludeSessionIds?: readonly string[]\n },\n logger: Logger,\n): Promise<Result<readonly SessionSearchResult[], Error>> {\n const {limit = 20, caseSensitive = false, sessionId, excludeSessionIds = []} = options\n const excluded = new Set(excludeSessionIds)\n const pattern = caseSensitive ? query : query.toLowerCase()\n logger.debug('Searching V2 sessions', {directory, limit, caseSensitive})\n\n if (sessionId != null) {\n if (excluded.has(sessionId)) return ok([])\n const messages = await getSessionMessagesV2(client, sessionId, logger)\n if (!messages.success) return messages\n const matches = searchMessages(messages.data, pattern, caseSensitive)\n return ok(matches.length === 0 ? [] : [{sessionId, matches: matches.slice(0, limit)}])\n }\n\n const listed = await listSessionsV2(client, directory, {}, logger)\n if (!listed.success) return listed\n\n const results: SessionSearchResult[] = []\n let totalMatches = 0\n let attempted = 0\n let succeeded = 0\n let firstReadError: Error | undefined\n for (const session of listed.data.filter(s => !excluded.has(s.id)).slice(0, SEARCH_MAX_SESSIONS)) {\n if (totalMatches >= limit) break\n\n attempted += 1\n const messages = await getSessionMessagesV2(client, session.id, logger)\n if (!messages.success) {\n // already logged; one unreadable session must not sink the whole search\n firstReadError ??= messages.error\n continue\n }\n succeeded += 1\n\n const matches = searchMessages(messages.data, pattern, caseSensitive)\n if (matches.length === 0) continue\n const kept = matches.slice(0, limit - totalMatches)\n results.push({sessionId: session.id, matches: kept})\n totalMatches += kept.length\n }\n\n // Nothing was searched: \"no matches\" would be a lie.\n if (attempted > 0 && succeeded === 0 && firstReadError != null) {\n return err(new Error(`could not read any of ${attempted} sessions: ${firstReadError.message}`))\n }\n\n logger.info('V2 session search complete', {resultCount: results.length, totalMatches})\n return ok(results)\n}\n\nexport interface SessionDetailsV2 {\n readonly session: SessionInfoV2\n readonly messageCount: number\n readonly agents: readonly string[]\n readonly hasTodos: boolean\n readonly todoCount: number\n readonly completedTodos: number\n}\n\n/** Resolves to `ok(null)` when the session does not exist. */\nexport async function getSessionInfoV2(\n client: SessionClientV2,\n sessionId: string,\n logger: Logger,\n): Promise<Result<SessionDetailsV2 | null, Error>> {\n const session = await getSessionV2(client, sessionId, logger)\n if (!session.success) return session\n if (session.data == null) return ok(null)\n\n const messages = await getSessionMessagesV2(client, sessionId, logger)\n if (!messages.success) return err(messages.error)\n\n const todos: readonly TodoItemV2[] = latestTodosV2(messages.data)\n return ok({\n session: session.data,\n messageCount: messages.data.length,\n agents: uniqueAgents(messages.data),\n hasTodos: todos.length > 0,\n todoCount: todos.length,\n completedTodos: todos.filter(todo => todo.status === 'completed').length,\n })\n}\n","/**\n * The session tools `session_list`, `session_read`, `session_search` and `session_info` on the V2 session API.\n *\n * Transcripts and search read the session's active context window (messages since the last compaction, with its summary\n * standing in for older ones); todos are the list the last `todowrite` call in that window set.\n *\n * `run()` never throws: every failure returns `session store unavailable: <reason>`, one line and length-capped.\n */\n\nimport type {MessageV2, SessionClientV2, SessionInfoV2} from '@fro-bot/runtime/session-v2'\n\nimport {\n getSessionInfoV2,\n getSessionMessagesV2,\n getSessionV2,\n latestTodosV2,\n listSessionsV2,\n searchSessionsV2,\n} from '@fro-bot/runtime/session-v2'\nimport {Schema} from 'effect'\n\nconst UNAVAILABLE_PREFIX = 'session store unavailable'\nconst REASON_MAX_CHARS = 200\n\nexport const TRANSCRIPT_CHAR_CAP = 48_000\n\nexport const SESSION_TOOL_NAMES = {\n list: 'session_list',\n read: 'session_read',\n search: 'session_search',\n info: 'session_info',\n} as const\n\n/** No-op logger: plugins have no logging channel. */\nconst silentLogger = {\n debug: (): void => {},\n info: (): void => {},\n warning: (): void => {},\n error: (): void => {},\n}\n\nexport interface SessionToolSpec<Input extends Schema.Top = Schema.Top> {\n readonly name: string\n readonly description: string\n readonly input: Input\n /** Takes the decoded tool input, defensively re-checked; never throws. */\n readonly run: (args: Readonly<Record<string, unknown>>) => Promise<string>\n}\n\nexport interface SessionToolSet {\n readonly list: SessionToolSpec<typeof ListInput>\n readonly read: SessionToolSpec<typeof ReadInput>\n readonly search: SessionToolSpec<typeof SearchInput>\n readonly info: SessionToolSpec<typeof InfoInput>\n}\n\nfunction unavailable(reason: string): string {\n return `${UNAVAILABLE_PREFIX}: ${reason}`\n}\n\n/** One line, capped. Effect tagged errors can have an empty message, so fall back to the tag. */\nfunction describeFailure(error: unknown): string {\n let raw: string\n if (error instanceof Error) {\n const tag: unknown = Reflect.get(error, '_tag')\n raw = error.message.length > 0 ? error.message : typeof tag === 'string' ? tag : error.name\n } else {\n raw = typeof error === 'string' ? error : 'unknown error'\n }\n const firstLine = raw.split('\\n')[0] ?? ''\n return firstLine.length > REASON_MAX_CHARS ? `${firstLine.slice(0, REASON_MAX_CHARS)}...` : firstLine\n}\n\nfunction asString(value: unknown): string | undefined {\n return typeof value === 'string' && value.length > 0 ? value : undefined\n}\n\nfunction asNumber(value: unknown): number | undefined {\n return typeof value === 'number' && Number.isFinite(value) ? value : undefined\n}\n\nfunction asBoolean(value: unknown): boolean | undefined {\n return typeof value === 'boolean' ? value : undefined\n}\n\nfunction parseDate(value: string | undefined): Date | undefined {\n if (value == null) return undefined\n const parsed = new Date(value)\n return Number.isNaN(parsed.getTime()) ? undefined : parsed\n}\n\n/** Parses a `to_date` bound to the END of that day (inclusive upper bound). */\nfunction parseEndOfDayDate(value: string | undefined): Date | undefined {\n const parsed = parseDate(value)\n if (parsed == null) return undefined\n const endOfDay = new Date(parsed)\n endOfDay.setUTCHours(23, 59, 59, 999)\n return endOfDay\n}\n\n/** Any limit below 1 (including negative values) means \"no limit\". */\nfunction normalizeLimit(value: number | undefined): number | undefined {\n return value == null || value < 1 ? undefined : value\n}\n\nfunction formatTimestamp(ms: number): string {\n return new Date(ms).toISOString()\n}\n\nfunction titleOf(session: SessionInfoV2): string {\n return session.title.length > 0 ? session.title : '(untitled)'\n}\n\nfunction formatMessageForTranscript(message: MessageV2): string {\n const text = message.parts.map(part => part.text).join(' ')\n return text.length > 0 ? `[${message.role}] ${text}` : `[${message.role}] (no content)`\n}\n\n/** Renders messages oldest-first, capping total rendered size so a huge transcript can't blow the response. */\nfunction renderTranscript(messages: readonly MessageV2[]): string[] {\n const lines: string[] = []\n let size = 0\n let shown = 0\n\n for (const message of messages) {\n const line = ` ${formatMessageForTranscript(message)}`\n if (size + line.length > TRANSCRIPT_CHAR_CAP) break\n lines.push(line)\n size += line.length\n shown += 1\n }\n\n if (shown < messages.length) {\n lines.push(` ... transcript truncated (${shown} of ${messages.length} messages shown)`)\n }\n return lines\n}\n\nfunction sessionHeader(session: SessionInfoV2): string[] {\n return [\n `Session ${session.id}`,\n `Title: ${titleOf(session)}`,\n `Created: ${formatTimestamp(session.time.created)}`,\n `Updated: ${formatTimestamp(session.time.updated)}`,\n ]\n}\n\nconst CONTEXT_WINDOW_NOTE =\n \"Covers the session's active context window: messages since its last compaction, plus the compaction summary.\"\n\nconst ListInput = Schema.Struct({\n limit: Schema.optionalKey(Schema.Number).annotate({description: 'Maximum number of sessions to return.'}),\n from_date: Schema.optionalKey(Schema.String).annotate({\n description: 'Only include sessions created on or after this date (YYYY-MM-DD).',\n }),\n to_date: Schema.optionalKey(Schema.String).annotate({\n description: 'Only include sessions created on or before this date (YYYY-MM-DD).',\n }),\n project_path: Schema.optionalKey(Schema.String).annotate({\n description: 'Workspace/project directory to list sessions for.',\n }),\n})\n\nconst ReadInput = Schema.Struct({\n session_id: Schema.String.annotate({description: 'The session id to read (required).'}),\n include_todos: Schema.optionalKey(Schema.Boolean).annotate({description: 'Include the session todo list.'}),\n include_transcript: Schema.optionalKey(Schema.Boolean).annotate({description: 'Include the message transcript.'}),\n limit: Schema.optionalKey(Schema.Number).annotate({\n description: 'Maximum number of transcript messages to include.',\n }),\n})\n\nconst SearchInput = Schema.Struct({\n query: Schema.String.annotate({description: 'Text to search for (required).'}),\n session_id: Schema.optionalKey(Schema.String).annotate({description: 'Restrict the search to a single session id.'}),\n case_sensitive: Schema.optionalKey(Schema.Boolean).annotate({description: 'Match case-sensitively.'}),\n limit: Schema.optionalKey(Schema.Number).annotate({description: 'Maximum number of matches to return.'}),\n})\n\nconst InfoInput = Schema.Struct({\n session_id: Schema.String.annotate({description: 'The session id to summarize (required).'}),\n})\n\n/**\n * Builds the four tool definitions against an injected client. `directory` is the workspace the tools default to:\n * `session_list` honours a `project_path` override, `session_search` always searches the workspace.\n */\nexport function createSessionTools(options: {\n readonly client: SessionClientV2\n readonly directory: string\n}): SessionToolSet {\n const {client, directory} = options\n const logger = silentLogger\n\n const list: SessionToolSpec<typeof ListInput> = {\n name: SESSION_TOOL_NAMES.list,\n description: 'List recent OpenCode sessions for the current workspace, most recently updated first.',\n input: ListInput,\n async run(args) {\n try {\n const sessions = await listSessionsV2(\n client,\n asString(args.project_path) ?? directory,\n {\n limit: normalizeLimit(asNumber(args.limit)),\n fromDate: parseDate(asString(args.from_date)),\n toDate: parseEndOfDayDate(asString(args.to_date)),\n },\n logger,\n )\n if (!sessions.success) return unavailable(describeFailure(sessions.error))\n if (sessions.data.length === 0) return 'No sessions found.'\n\n return sessions.data\n .map(session => `${session.id} ${titleOf(session)} updated ${formatTimestamp(session.time.updated)}`)\n .join('\\n')\n } catch (error) {\n return unavailable(describeFailure(error))\n }\n },\n }\n\n const read: SessionToolSpec<typeof ReadInput> = {\n name: SESSION_TOOL_NAMES.read,\n description: `Read a session: header, optional todos, and optional transcript. ${CONTEXT_WINDOW_NOTE}`,\n input: ReadInput,\n async run(args) {\n const sessionId = asString(args.session_id)\n if (sessionId == null) return unavailable('session_id is required')\n\n try {\n const found = await getSessionV2(client, sessionId, logger)\n if (!found.success) return unavailable(describeFailure(found.error))\n if (found.data == null) return `session not found: ${sessionId}`\n\n const lines = sessionHeader(found.data)\n\n const includeTodos = asBoolean(args.include_todos) === true\n const includeTranscript = asBoolean(args.include_transcript) === true\n if (!includeTodos && !includeTranscript) return lines.join('\\n')\n\n // One snapshot of the active context feeds both sections.\n const messages = await getSessionMessagesV2(client, sessionId, logger)\n if (!messages.success) return unavailable(describeFailure(messages.error))\n\n if (includeTodos) {\n const todos = latestTodosV2(messages.data)\n lines.push('', 'Todos:')\n if (todos.length === 0) {\n lines.push(' (none)')\n } else {\n for (const todo of todos) lines.push(` [${todo.status}] ${todo.content}`)\n }\n }\n\n if (includeTranscript) {\n // Oldest-first; a limit returns the earliest N messages.\n const limit = normalizeLimit(asNumber(args.limit))\n const sliced = limit == null ? messages.data : messages.data.slice(0, limit)\n lines.push('', 'Transcript:')\n if (sliced.length === 0) {\n lines.push(' (empty)')\n } else {\n lines.push(...renderTranscript(sliced))\n }\n }\n\n return lines.join('\\n')\n } catch (error) {\n return unavailable(describeFailure(error))\n }\n },\n }\n\n const search: SessionToolSpec<typeof SearchInput> = {\n name: SESSION_TOOL_NAMES.search,\n description: `Search prior session content for matching text, optionally scoped to one session. ${CONTEXT_WINDOW_NOTE}`,\n input: SearchInput,\n async run(args) {\n const query = asString(args.query)\n if (query == null) return unavailable('query is required')\n\n try {\n const scopedSessionId = asString(args.session_id)\n if (scopedSessionId != null) {\n const found = await getSessionV2(client, scopedSessionId, logger)\n if (!found.success) return unavailable(describeFailure(found.error))\n if (found.data == null) return `session not found: ${scopedSessionId}`\n }\n\n // Search always scopes to the current workspace; there is no project_path.\n const results = await searchSessionsV2(\n query,\n client,\n directory,\n {\n limit: normalizeLimit(asNumber(args.limit)),\n caseSensitive: asBoolean(args.case_sensitive),\n sessionId: scopedSessionId,\n },\n logger,\n )\n if (!results.success) return unavailable(describeFailure(results.error))\n if (results.data.length === 0) return 'No matches found.'\n\n const lines: string[] = []\n for (const result of results.data) {\n lines.push(`Session ${result.sessionId}:`)\n for (const match of result.matches) {\n lines.push(` [${match.role}${match.agent == null ? '' : `/${match.agent}`}] ${match.excerpt}`)\n }\n }\n return lines.join('\\n')\n } catch (error) {\n return unavailable(describeFailure(error))\n }\n },\n }\n\n const info: SessionToolSpec<typeof InfoInput> = {\n name: SESSION_TOOL_NAMES.info,\n description: `Summarize a session: id, title, timestamps, message and todo counts. ${CONTEXT_WINDOW_NOTE}`,\n input: InfoInput,\n async run(args) {\n const sessionId = asString(args.session_id)\n if (sessionId == null) return unavailable('session_id is required')\n\n try {\n const details = await getSessionInfoV2(client, sessionId, logger)\n if (!details.success) return unavailable(describeFailure(details.error))\n if (details.data == null) return `session not found: ${sessionId}`\n\n const {session, messageCount, agents, hasTodos, todoCount, completedTodos} = details.data\n return [\n ...sessionHeader(session),\n `Messages: ${messageCount}`,\n `Agents: ${agents.length > 0 ? agents.join(', ') : '(none)'}`,\n `Todos: ${hasTodos ? `${completedTodos}/${todoCount} completed` : '(none)'}`,\n ].join('\\n')\n } catch (error) {\n return unavailable(describeFailure(error))\n }\n },\n }\n\n return {list, read, search, info}\n}\n","/** Rejects `subagent` calls that resume a child session via `sessionID`, via the `execute.before` tool hook. */\n\n/** The model-visible rejection text; it carries no ids or arguments. */\nexport const TASK_REUSE_REJECTION =\n 'Session reuse is disabled in this environment. Start a new task and include the context it needs.'\n\n/** The one tool the guard covers: a direct tool, never inside Code Mode. */\nexport const GUARDED_TOOL = 'subagent'\n\nexport interface ToolCallBefore {\n readonly tool: string\n readonly input: unknown\n}\n\n/** A resume is any `sessionID` other than absent, null or `\"\"` (upstream treats `\"\"` as absent); malformed values reject. */\nfunction carriesResume(input: unknown): boolean {\n if (input === null || typeof input !== 'object' || Array.isArray(input)) return false\n const sessionID: unknown = Reflect.get(input, 'sessionID')\n return sessionID !== undefined && sessionID !== null && sessionID !== ''\n}\n\nexport function rejectSubagentReuse(event: ToolCallBefore): void {\n if (event.tool !== GUARDED_TOOL) return\n if (carriesResume(event.input)) throw new Error(TASK_REUSE_REJECTION)\n}\n","/** Plugin setup: registers the subagent session-reuse guard, then the four session tools. */\n\nimport type {Plugin} from '@opencode/plugin'\nimport type {PluginSessionApi} from './session-client.js'\nimport type {ToolCallBefore} from './task-reuse-guard.js'\nimport {createPluginSessionClient} from './session-client.js'\nimport {createSessionTools} from './session-tools.js'\nimport {rejectSubagentReuse} from './task-reuse-guard.js'\n\ntype ToolEditor = Parameters<Parameters<Plugin.Context['tool']['transform']>[0]>[0]\ntype ToolInfo = Parameters<ToolEditor['add']>[0]\n\n/** The slice of `Plugin.Context` this plugin uses. */\nexport interface HostSurface {\n readonly location: {readonly directory: string}\n readonly session: PluginSessionApi\n readonly tool: {\n transform: (callback: (editor: Pick<ToolEditor, 'add'>) => void) => Promise<unknown>\n hook: (name: 'execute.before', callback: (event: ToolCallBefore) => Promise<void> | void) => Promise<unknown>\n }\n}\n\nexport async function setupFroBotPlugin(host: HostSurface): Promise<void> {\n // The guard goes first: if it cannot be registered the plugin fails before exposing any tool.\n await host.tool.hook('execute.before', async event => {\n rejectSubagentReuse(event)\n })\n\n const tools = createSessionTools({\n client: createPluginSessionClient(host.session),\n directory: host.location.directory,\n })\n await host.tool.transform(editor => {\n for (const spec of [tools.list, tools.read, tools.search, tools.info]) {\n const tool: ToolInfo = {\n name: spec.name,\n // Direct tools: the prompt names them, so they stay out of the Code Mode catalog.\n options: {codemode: false},\n description: spec.description,\n input: spec.input,\n execute: async (input: Readonly<Record<string, unknown>>) => ({content: await spec.run(input)}),\n }\n editor.add(tool)\n }\n })\n}\n","/** `@fro.bot/opencode-plugin`: the session tools and the subagent session-reuse guard. */\n\nimport {Plugin} from '@opencode/plugin'\nimport {FRO_BOT_PLUGIN_ID} from './plugin-id.js'\nimport {setupFroBotPlugin} from './setup.js'\n\nexport {FRO_BOT_PLUGIN_ID} from './plugin-id.js'\n\nexport default Plugin.define({\n id: FRO_BOT_PLUGIN_ID,\n setup: async ctx => setupFroBotPlugin(ctx),\n})\n"],"ignoreList":[2],"mappings":";;;;AACA,MAAa,oBAAoB;;ACUjC,MAAM,oBAAoB;AAC1B,MAAM,gBAAgB;AAEtB,SAAgB,kBAAkB,OAAyB;CACzD,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,QAAQ,IAAI,OAAO,MAAM,MAAM;AACvF;AAEA,SAAgB,0BAA0B,SAA4C;CACpF,OAAO;EACL,MAAM,OAAM,UAAS,QAAQ,KAAK,KAAK;EACvC,MAAM,IAAI,WAAW;GAEnB,IAAI,CAAC,UAAU,WAAW,iBAAiB,GAAG,OAAO;GACrD,IAAI;IACF,OAAO,MAAM,QAAQ,IAAI,EAAC,UAAS,CAAC;GACtC,SAAS,OAAO;IACd,IAAI,kBAAkB,KAAK,GAAG,OAAO;IACrC,MAAM;GACR;EACF;EACA,UAAU,OAAM,cAAa,QAAQ,QAAQ,EAAC,UAAS,CAAC;CAC1D;AACF;;AChCA,SAAS,GAAG,OAAO;CACjB,OAAO;EAAE,SAAS;EAAM,MAAM;CAAM;AACtC;AACA,SAAS,IAAI,OAAO;CAClB,OAAO;EAAE,SAAS;EAAO;CAAM;AACjC;;ACFA,MAAa,YAAY,MAA6C,OAAO,MAAM,YAAY,KAAK;AACpG,MAAa,cAAc,MAA+B,OAAO,MAAM,WAAW,IAAI;AACtF,MAAa,cAAc,MAA+B,OAAO,MAAM,YAAY,OAAO,SAAS,CAAC,IAAI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
|
|
2
2
|
"name": "@fro.bot/opencode-plugin",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Fro Bot's OpenCode V2 plugin: session history tools and the subagent session-reuse guard",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"opencode",
|
|
7
|
+
"opencode-plugin",
|
|
8
|
+
"fro-bot"
|
|
9
|
+
],
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/fro-bot/agent.git",
|
|
13
|
+
"directory": "packages/opencode-plugin"
|
|
14
|
+
},
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"author": "Fro Bot <agent@fro.bot>",
|
|
17
|
+
"type": "module",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.mts",
|
|
21
|
+
"import": "./dist/index.mjs"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"LICENSE",
|
|
26
|
+
"README.md",
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"@opencode/plugin": "^2.2.0",
|
|
31
|
+
"effect": "^4.0.0"
|
|
32
|
+
},
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=24"
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public",
|
|
38
|
+
"provenance": true
|
|
39
|
+
}
|
|
40
|
+
}
|