opencode-logger 0.2.2 → 0.3.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/README.md CHANGED
@@ -26,12 +26,13 @@ and add:
26
26
 
27
27
  ## Configuration
28
28
 
29
- You can customize the log directory and filename using environment variables.
29
+ You can customize the log directory, filename, and logging scope using environment variables.
30
30
 
31
31
  | Variable | Description | Default |
32
32
  |----------|-------------|---------|
33
33
  | `OPENCODE_LOGGER_DIR` | The directory where logs are stored. Can be absolute or relative to project root. | `logs/opencode` |
34
34
  | `OPENCODE_LOGGER_FILENAME` | The filename for the log file. | `log.jsonl` |
35
+ | `OPENCODE_LOGGER_SCOPE` | Comma-separated list of event types to log. Supports wildcards (e.g., `session.*`). | `*` (Log all events) |
35
36
 
36
37
 
37
38
 
@@ -52,5 +53,21 @@ export OPENCODE_LOGGER_DIR=/tmp/my-logs
52
53
  export OPENCODE_LOGGER_FILENAME=custom-name.jsonl
53
54
  ```
54
55
 
56
+ ### Logging Scope
57
+
58
+ You can filter which events are logged using the `OPENCODE_LOGGER_SCOPE` environment variable.
59
+ It accepts a comma-separated string of event types or patterns.
60
+
61
+ - `*` (Default): Logs all events.
62
+ - `session.*`: Logs all events starting with `session.` (e.g., `session.created`, `session.updated`).
63
+ - `command.executed,file.edited`: Logs only these specific events.
64
+
65
+ **Example:**
66
+
67
+ ```bash
68
+ export OPENCODE_LOGGER_SCOPE="session.*,command.executed"
69
+ ```
70
+
71
+
55
72
 
56
73
 
@@ -10,7 +10,7 @@ export declare const DEFAULT_LOG_FILENAME = "log.jsonl";
10
10
  * List of event types supported by the logger plugin.
11
11
  * These events correspond to various lifecycle hooks and actions within the Opencode environment.
12
12
  */
13
- export declare const SUPPORTED_EVENTS: readonly ["command.executed", "file.edited", "file.watcher.updated", "installation.updated", "lsp.client.diagnostics", "lsp.updated", "message.part.removed", "message.part.updated", "message.removed", "message.updated", "permission.replied", "permission.updated", "server.connected", "session.created", "session.compacted", "session.deleted", "session.diff", "session.error", "session.idle", "session.status", "session.updated", "todo.updated", "tool.execute.after", "tool.execute.before", "tui.prompt.append", "tui.command.execute", "tui.toast.show"];
13
+ export declare const SUPPORTED_EVENTS: readonly ["command.executed", "file.edited", "file.watcher.updated", "installation.updated", "lsp.client.diagnostics", "lsp.updated", "message.part.removed", "message.part.updated", "message.removed", "message.updated", "permission.asked", "permission.replied", "server.connected", "session.created", "session.compacted", "session.deleted", "session.diff", "session.error", "session.idle", "session.status", "session.updated", "todo.updated", "tool.execute.after", "tool.execute.before", "tui.prompt.append", "tui.command.execute", "tui.toast.show"];
14
14
  /**
15
15
  * Type definition derived from the supported events constant.
16
16
  */
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,qBAAqB,kBAAkB,CAAC;AAErD;;GAEG;AACH,eAAO,MAAM,oBAAoB,cAAc,CAAC;AAEhD;;;GAGG;AACH,eAAO,MAAM,gBAAgB,yiBA4BnB,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,qBAAqB,kBAAkB,CAAC;AAErD;;GAEG;AACH,eAAO,MAAM,oBAAoB,cAAc,CAAC;AAEhD;;;GAGG;AACH,eAAO,MAAM,gBAAgB,uiBA4BnB,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC"}
package/dist/constants.js CHANGED
@@ -21,8 +21,8 @@ export const SUPPORTED_EVENTS = [
21
21
  "message.part.updated",
22
22
  "message.removed",
23
23
  "message.updated",
24
+ "permission.asked",
24
25
  "permission.replied",
25
- "permission.updated",
26
26
  "server.connected",
27
27
  "session.created",
28
28
  "session.compacted",
@@ -1 +1 @@
1
- {"version":3,"file":"file-logger.d.ts","sourceRoot":"","sources":["../src/file-logger.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGvD;;GAEG;AACH,MAAM,WAAW,QAAQ;IACxB,qDAAqD;IACrD,SAAS,EAAE,MAAM,CAAC;IAClB,uFAAuF;IACvF,SAAS,EAAE,MAAM,CAAC;IAClB,kDAAkD;IAClD,OAAO,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,qBAAa,UAAU;IACtB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,WAAW,CAAc;IAEjC;;;;OAIG;gBACS,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW;IAQzD,OAAO,CAAC,mBAAmB;IAY3B,OAAO,CAAC,cAAc;IAKtB;;;OAGG;IACG,IAAI;IA8BV;;;;OAIG;IACG,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;CAwB7C"}
1
+ {"version":3,"file":"file-logger.d.ts","sourceRoot":"","sources":["../src/file-logger.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGvD;;GAEG;AACH,MAAM,WAAW,QAAQ;IACxB,qDAAqD;IACrD,SAAS,EAAE,MAAM,CAAC;IAClB,uFAAuF;IACvF,SAAS,EAAE,MAAM,CAAC;IAClB,kDAAkD;IAClD,OAAO,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,qBAAa,UAAU;IACtB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,WAAW,CAAc;IAEjC;;;;OAIG;gBACS,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW;IAQzD,OAAO,CAAC,mBAAmB;IAY3B,OAAO,CAAC,cAAc;IAKtB;;;OAGG;IACG,IAAI;IASV;;;;OAIG;IACG,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;CAwB7C"}
@@ -40,29 +40,9 @@ export class FileLogger {
40
40
  try {
41
41
  const dirPath = join(this.logFilePath, "..");
42
42
  await mkdir(dirPath, { recursive: true });
43
- // NOTE: this opencode log call causes
44
- // the application to hang on start.
45
- // Did not see anything in the internal logs,
46
- // so this is disabled for the moment
47
- /* await this.pluginInput.client.app.log({
48
- body: {
49
- service: "opencode-logger",
50
- level: "info",
51
- message: "Plugin initialized!",
52
- },
53
- }); */
54
43
  }
55
44
  catch (error) {
56
- await this.pluginInput.client.app.log({
57
- body: {
58
- service: "opencode-logger",
59
- level: "error",
60
- message: "Failed to create log directory.",
61
- extra: {
62
- error,
63
- },
64
- },
65
- });
45
+ console.error(`[Opencode-logger]: Failed to initialize.\n${error}`);
66
46
  }
67
47
  }
68
48
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAS,MAAM,qBAAqB,CAAC;AAIzD;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,EAAE,MAe1B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAS,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAKzD;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,EAAE,MAmB1B,CAAC"}
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { SUPPORTED_EVENTS } from "./constants.js";
2
2
  import { FileLogger } from "./file-logger.js";
3
+ import { shouldLogEvent } from "./utils.js";
3
4
  /**
4
5
  * The main Opencode Logger plugin entry point.
5
6
  * Initializes the file logger and registers hooks for supported events.
@@ -13,7 +14,9 @@ export const loggerPlugin = async (ctx) => {
13
14
  console.log("[Opencode Logger] Plugin initialized!");
14
15
  const hooks = {
15
16
  event: async ({ event }) => {
16
- if (SUPPORTED_EVENTS.includes(event.type)) {
17
+ if (SUPPORTED_EVENTS.includes(event.type) &&
18
+ // biome-ignore lint/complexity/useLiteralKeys: process.env access
19
+ shouldLogEvent(event.type, process.env["OPENCODE_LOGGER_SCOPE"])) {
17
20
  await logger.log(event.type, event);
18
21
  }
19
22
  },
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Determines if a specific event type should be logged based on the configured scope.
3
+ *
4
+ * The scope is a comma-separated string that can contain:
5
+ * 1. "*" to allow all events.
6
+ * 2. Specific event names (e.g., "session.created").
7
+ * 3. Group wildcards ending in ".*" (e.g., "session.*").
8
+ *
9
+ * @param eventType - The type of the event to check.
10
+ * @param scope - The configuration string defining allowed events.
11
+ * @returns True if the event should be logged, false otherwise.
12
+ */
13
+ export declare function shouldLogEvent(eventType: string, scope?: string): boolean;
14
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CA0BzE"}
package/dist/utils.js ADDED
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Determines if a specific event type should be logged based on the configured scope.
3
+ *
4
+ * The scope is a comma-separated string that can contain:
5
+ * 1. "*" to allow all events.
6
+ * 2. Specific event names (e.g., "session.created").
7
+ * 3. Group wildcards ending in ".*" (e.g., "session.*").
8
+ *
9
+ * @param eventType - The type of the event to check.
10
+ * @param scope - The configuration string defining allowed events.
11
+ * @returns True if the event should be logged, false otherwise.
12
+ */
13
+ export function shouldLogEvent(eventType, scope) {
14
+ if (!scope || scope === "*" || scope.trim() === "") {
15
+ return true;
16
+ }
17
+ const allowedPatterns = scope.split(",").map((s) => s.trim());
18
+ for (const pattern of allowedPatterns) {
19
+ if (pattern === "*") {
20
+ return true;
21
+ }
22
+ // Check for wildcard group (e.g., "session.*")
23
+ if (pattern.endsWith(".*")) {
24
+ const prefix = pattern.slice(0, -2);
25
+ if (eventType.startsWith(`${prefix}.`)) {
26
+ return true;
27
+ }
28
+ }
29
+ if (pattern === eventType) {
30
+ return true;
31
+ }
32
+ }
33
+ return false;
34
+ }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "opencode-logger",
3
3
  "main": "dist/index.js",
4
4
  "types": "dist/index.d.ts",
5
- "version": "0.2.2",
5
+ "version": "0.3.0",
6
6
  "repository": {
7
7
  "url": "https://github.com/radekBednarik/opencode-logger.git"
8
8
  },