opencode-logger 0.1.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -0
- package/dist/constants.d.ts +2 -2
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +2 -2
- package/dist/file-logger.d.ts +2 -0
- package/dist/file-logger.d.ts.map +1 -1
- package/dist/file-logger.js +19 -3
- package/dist/index.js +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -24,4 +24,33 @@ and add:
|
|
|
24
24
|
}
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
+
## Configuration
|
|
28
|
+
|
|
29
|
+
You can customize the log directory and filename using environment variables.
|
|
30
|
+
|
|
31
|
+
| Variable | Description | Default |
|
|
32
|
+
|----------|-------------|---------|
|
|
33
|
+
| `OPENCODE_LOGGER_DIR` | The directory where logs are stored. Can be absolute or relative to project root. | `logs/opencode` |
|
|
34
|
+
| `OPENCODE_LOGGER_FILENAME` | The filename for the log file. | `log.jsonl` |
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
### Setting via CLI
|
|
39
|
+
|
|
40
|
+
You can set them when starting the Opencode client:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
OPENCODE_LOGGER_DIR=/tmp/my-logs opencode
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Setting by exporting ENV variables
|
|
47
|
+
|
|
48
|
+
Or export them, for example in your `~/.bashrc`
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
export OPENCODE_LOGGER_DIR=/tmp/my-logs
|
|
52
|
+
export OPENCODE_LOGGER_FILENAME=custom-name.jsonl
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
|
|
27
56
|
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Directory where logs will be stored relative to the project root.
|
|
3
3
|
*/
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const DEFAULT_LOG_DIRECTORY = "logs/opencode";
|
|
5
5
|
/**
|
|
6
6
|
* Filename for the log file.
|
|
7
7
|
*/
|
|
8
|
-
export declare const
|
|
8
|
+
export declare const DEFAULT_LOG_FILENAME = "log.jsonl";
|
|
9
9
|
/**
|
|
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.
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,
|
|
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"}
|
package/dist/constants.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Directory where logs will be stored relative to the project root.
|
|
3
3
|
*/
|
|
4
|
-
export const
|
|
4
|
+
export const DEFAULT_LOG_DIRECTORY = "logs/opencode";
|
|
5
5
|
/**
|
|
6
6
|
* Filename for the log file.
|
|
7
7
|
*/
|
|
8
|
-
export const
|
|
8
|
+
export const DEFAULT_LOG_FILENAME = "log.jsonl";
|
|
9
9
|
/**
|
|
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.
|
package/dist/file-logger.d.ts
CHANGED
|
@@ -19,6 +19,8 @@ export declare class FileLogger {
|
|
|
19
19
|
* @param projectRoot - The absolute path to the root of the project.
|
|
20
20
|
*/
|
|
21
21
|
constructor(projectRoot: string);
|
|
22
|
+
private resolveLogDirectory;
|
|
23
|
+
private getLogFilename;
|
|
22
24
|
/**
|
|
23
25
|
* Initializes the logger by ensuring the log directory exists.
|
|
24
26
|
* This method should be called before attempting to log any events.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-logger.d.ts","sourceRoot":"","sources":["../src/file-logger.ts"],"names":[],"mappings":"AAIA;;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;IAE5B;;;OAGG;gBACS,WAAW,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"file-logger.d.ts","sourceRoot":"","sources":["../src/file-logger.ts"],"names":[],"mappings":"AAIA;;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;IAE5B;;;OAGG;gBACS,WAAW,EAAE,MAAM;IAO/B,OAAO,CAAC,mBAAmB;IAY3B,OAAO,CAAC,cAAc;IAKtB;;;OAGG;IACG,IAAI;IAWV;;;;OAIG;IACG,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;CAe7C"}
|
package/dist/file-logger.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { appendFile, mkdir } from "node:fs/promises";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import {
|
|
2
|
+
import { isAbsolute, join, resolve } from "node:path";
|
|
3
|
+
import { DEFAULT_LOG_DIRECTORY, DEFAULT_LOG_FILENAME } from "./constants.js";
|
|
4
4
|
/**
|
|
5
5
|
* Handles initialization of the log directory and writing log entries to the file system.
|
|
6
6
|
*/
|
|
@@ -11,7 +11,23 @@ export class FileLogger {
|
|
|
11
11
|
* @param projectRoot - The absolute path to the root of the project.
|
|
12
12
|
*/
|
|
13
13
|
constructor(projectRoot) {
|
|
14
|
-
|
|
14
|
+
const logDir = this.resolveLogDirectory(projectRoot);
|
|
15
|
+
const logFilename = this.getLogFilename();
|
|
16
|
+
this.logFilePath = join(logDir, logFilename);
|
|
17
|
+
}
|
|
18
|
+
resolveLogDirectory(projectRoot) {
|
|
19
|
+
const logDir =
|
|
20
|
+
// biome-ignore lint/complexity/useLiteralKeys: process.env access
|
|
21
|
+
process.env["OPENCODE_LOGGER_DIR"] ||
|
|
22
|
+
join(projectRoot, DEFAULT_LOG_DIRECTORY);
|
|
23
|
+
// If logDir is absolute, use it directly. Otherwise, resolve it relative to projectRoot
|
|
24
|
+
// Note: The default join(projectRoot, DEFAULT_LOG_DIRECTORY) above already handles the relative default case,
|
|
25
|
+
// but we check isAbsolute here specifically for the ENV var case if the user passed a relative path.
|
|
26
|
+
return isAbsolute(logDir) ? logDir : resolve(projectRoot, logDir);
|
|
27
|
+
}
|
|
28
|
+
getLogFilename() {
|
|
29
|
+
// biome-ignore lint/complexity/useLiteralKeys: process.env access
|
|
30
|
+
return process.env["OPENCODE_LOGGER_FILENAME"] || DEFAULT_LOG_FILENAME;
|
|
15
31
|
}
|
|
16
32
|
/**
|
|
17
33
|
* Initializes the logger by ensuring the log directory exists.
|
package/dist/index.js
CHANGED
|
@@ -13,7 +13,7 @@ export const loggerPlugin = async (ctx) => {
|
|
|
13
13
|
// Based on the docs: directory: The current working directory.
|
|
14
14
|
const logger = new FileLogger(ctx.directory);
|
|
15
15
|
await logger.init();
|
|
16
|
-
console.log("Opencode Logger Plugin initialized!");
|
|
16
|
+
console.log("[Opencode Logger] Plugin initialized!");
|
|
17
17
|
const hooks = {
|
|
18
18
|
event: async ({ event }) => {
|
|
19
19
|
if (SUPPORTED_EVENTS.includes(event.type)) {
|
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.
|
|
5
|
+
"version": "0.2.0",
|
|
6
6
|
"repository": {
|
|
7
7
|
"url": "https://github.com/radekBednarik/opencode-logger.git"
|
|
8
8
|
},
|
|
@@ -18,6 +18,9 @@
|
|
|
18
18
|
"Typescript",
|
|
19
19
|
"plugin"
|
|
20
20
|
],
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@opencode-ai/plugin": "^1.1.25"
|
|
23
|
+
},
|
|
21
24
|
"devDependencies": {
|
|
22
25
|
"@biomejs/biome": "2.3.11",
|
|
23
26
|
"@types/bun": "latest",
|
|
@@ -44,8 +47,5 @@
|
|
|
44
47
|
"*.{ts,json}": [
|
|
45
48
|
"bun format"
|
|
46
49
|
]
|
|
47
|
-
},
|
|
48
|
-
"dependencies": {
|
|
49
|
-
"@opencode-ai/plugin": "^1.1.25"
|
|
50
50
|
}
|
|
51
51
|
}
|