@blueplane/opencode-capture 0.2.1 → 0.2.9
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 +18 -0
- package/package.json +1 -1
- package/plugin.ts +22 -6
- package/writer.ts +18 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Copyright © 2025 Sierra Labs LLC
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
This software and associated documentation files (the "Software") are
|
|
5
|
+
proprietary and confidential. Unauthorized copying, modification,
|
|
6
|
+
distribution, or use of the Software, in whole or in part, is strictly
|
|
7
|
+
prohibited without prior written permission from Sierra Labs LLC.
|
|
8
|
+
|
|
9
|
+
No license, express or implied, is granted to any party except as expressly
|
|
10
|
+
set forth in a written agreement with Sierra Labs LLC.
|
|
11
|
+
|
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
13
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
14
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
15
|
+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
16
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
17
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
18
|
+
DEALINGS IN THE SOFTWARE.
|
package/package.json
CHANGED
package/plugin.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
// Copyright © 2025 Sierra Labs LLC
|
|
2
|
-
// SPDX-License-Identifier: AGPL-3.0-only
|
|
3
|
-
// License-Filename: LICENSE
|
|
4
|
-
|
|
5
1
|
import type { Plugin } from "@opencode-ai/plugin";
|
|
2
|
+
import { execFileSync } from "child_process";
|
|
6
3
|
import * as path from "path";
|
|
7
4
|
import * as os from "os";
|
|
8
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
writeEvent,
|
|
7
|
+
isEventBusType,
|
|
8
|
+
isStreamingEvent,
|
|
9
|
+
type WriterConfig,
|
|
10
|
+
} from "./writer";
|
|
9
11
|
|
|
10
12
|
// ---------------------------------------------------------------------------
|
|
11
13
|
// Plugin export
|
|
@@ -20,12 +22,26 @@ const plugin: Plugin = async (_input) => {
|
|
|
20
22
|
);
|
|
21
23
|
const cfg: WriterConfig = { captureDir };
|
|
22
24
|
|
|
25
|
+
// Detect OpenCode version once at plugin init (2s timeout)
|
|
26
|
+
let platformVersion: string | null = null;
|
|
27
|
+
try {
|
|
28
|
+
const out = execFileSync("opencode", ["--version"], { timeout: 2000 }).toString();
|
|
29
|
+
const match = out.match(/(\d+\.\d+\.\d+)/);
|
|
30
|
+
if (match) platformVersion = match[1];
|
|
31
|
+
} catch { /* ignore — version detection is best-effort */ }
|
|
32
|
+
|
|
23
33
|
return {
|
|
24
34
|
event: async ({ event }) => {
|
|
25
35
|
try {
|
|
26
36
|
const hookType = event.type;
|
|
27
37
|
if (!isEventBusType(hookType)) return;
|
|
28
|
-
|
|
38
|
+
const props = (event as any).properties ?? {};
|
|
39
|
+
if (isStreamingEvent(hookType, props)) return;
|
|
40
|
+
if (hookType === "session.created" && platformVersion) {
|
|
41
|
+
writeEvent(hookType, { ...props, platform_version: platformVersion }, cfg);
|
|
42
|
+
} else {
|
|
43
|
+
writeEvent(hookType, props, cfg);
|
|
44
|
+
}
|
|
29
45
|
} catch {
|
|
30
46
|
/* fire-and-forget */
|
|
31
47
|
}
|
package/writer.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
// Copyright © 2025 Sierra Labs LLC
|
|
2
|
-
// SPDX-License-Identifier: AGPL-3.0-only
|
|
3
|
-
// License-Filename: LICENSE
|
|
4
|
-
|
|
5
1
|
import * as fs from "fs";
|
|
6
2
|
import * as path from "path";
|
|
7
3
|
import * as os from "os";
|
|
@@ -37,6 +33,8 @@ const ALLOWED_EVENT_BUS_TYPES = new Set([
|
|
|
37
33
|
"file.edited",
|
|
38
34
|
"message.removed",
|
|
39
35
|
"message.updated",
|
|
36
|
+
"message.part.updated",
|
|
37
|
+
"message.part.removed",
|
|
40
38
|
"permission.asked",
|
|
41
39
|
"permission.replied",
|
|
42
40
|
"todo.updated",
|
|
@@ -74,6 +72,22 @@ export function isEventBusType(hookType: string): boolean {
|
|
|
74
72
|
return ALLOWED_EVENT_BUS_TYPES.has(hookType);
|
|
75
73
|
}
|
|
76
74
|
|
|
75
|
+
export function isStreamingEvent(
|
|
76
|
+
hookType: string,
|
|
77
|
+
properties: Record<string, any> | undefined,
|
|
78
|
+
): boolean {
|
|
79
|
+
if (!properties) return false;
|
|
80
|
+
if (hookType === "message.part.updated" && properties.delta != null)
|
|
81
|
+
return true;
|
|
82
|
+
if (
|
|
83
|
+
hookType === "message.updated" &&
|
|
84
|
+
properties.info?.role === "assistant" &&
|
|
85
|
+
!properties.info?.finish
|
|
86
|
+
)
|
|
87
|
+
return true;
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
|
|
77
91
|
// ---------------------------------------------------------------------------
|
|
78
92
|
// Spinlock
|
|
79
93
|
// ---------------------------------------------------------------------------
|