opencode-logger 0.2.0 → 0.2.1
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/dist/file-logger.d.ts +5 -2
- package/dist/file-logger.d.ts.map +1 -1
- package/dist/file-logger.js +36 -4
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/file-logger.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { PluginInput } from "@opencode-ai/plugin";
|
|
1
2
|
/**
|
|
2
3
|
* Interface representing a single log entry in the log file.
|
|
3
4
|
*/
|
|
@@ -14,16 +15,18 @@ export interface LogEntry {
|
|
|
14
15
|
*/
|
|
15
16
|
export declare class FileLogger {
|
|
16
17
|
private logFilePath;
|
|
18
|
+
private pluginInput;
|
|
17
19
|
/**
|
|
18
20
|
* Creates a new instance of FileLogger.
|
|
19
21
|
* @param projectRoot - The absolute path to the root of the project.
|
|
22
|
+
* @param pluginInput - Opencode plugin input
|
|
20
23
|
*/
|
|
21
|
-
constructor(projectRoot: string);
|
|
24
|
+
constructor(projectRoot: string, pluginInput: PluginInput);
|
|
22
25
|
private resolveLogDirectory;
|
|
23
26
|
private getLogFilename;
|
|
24
27
|
/**
|
|
25
28
|
* Initializes the logger by ensuring the log directory exists.
|
|
26
|
-
* This method
|
|
29
|
+
* This method must be called before attempting to log any events.
|
|
27
30
|
*/
|
|
28
31
|
init(): Promise<void>;
|
|
29
32
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-logger.d.ts","sourceRoot":"","sources":["../src/file-logger.ts"],"names":[],"mappings":"
|
|
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"}
|
package/dist/file-logger.js
CHANGED
|
@@ -6,14 +6,17 @@ import { DEFAULT_LOG_DIRECTORY, DEFAULT_LOG_FILENAME } from "./constants.js";
|
|
|
6
6
|
*/
|
|
7
7
|
export class FileLogger {
|
|
8
8
|
logFilePath;
|
|
9
|
+
pluginInput;
|
|
9
10
|
/**
|
|
10
11
|
* Creates a new instance of FileLogger.
|
|
11
12
|
* @param projectRoot - The absolute path to the root of the project.
|
|
13
|
+
* @param pluginInput - Opencode plugin input
|
|
12
14
|
*/
|
|
13
|
-
constructor(projectRoot) {
|
|
15
|
+
constructor(projectRoot, pluginInput) {
|
|
14
16
|
const logDir = this.resolveLogDirectory(projectRoot);
|
|
15
17
|
const logFilename = this.getLogFilename();
|
|
16
18
|
this.logFilePath = join(logDir, logFilename);
|
|
19
|
+
this.pluginInput = pluginInput;
|
|
17
20
|
}
|
|
18
21
|
resolveLogDirectory(projectRoot) {
|
|
19
22
|
const logDir =
|
|
@@ -31,15 +34,35 @@ export class FileLogger {
|
|
|
31
34
|
}
|
|
32
35
|
/**
|
|
33
36
|
* Initializes the logger by ensuring the log directory exists.
|
|
34
|
-
* This method
|
|
37
|
+
* This method must be called before attempting to log any events.
|
|
35
38
|
*/
|
|
36
39
|
async init() {
|
|
37
40
|
try {
|
|
38
41
|
const dirPath = join(this.logFilePath, "..");
|
|
39
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
|
+
}); */
|
|
40
54
|
}
|
|
41
55
|
catch (error) {
|
|
42
|
-
|
|
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
|
+
});
|
|
43
66
|
}
|
|
44
67
|
}
|
|
45
68
|
/**
|
|
@@ -58,7 +81,16 @@ export class FileLogger {
|
|
|
58
81
|
await appendFile(this.logFilePath, line, "utf-8");
|
|
59
82
|
}
|
|
60
83
|
catch (error) {
|
|
61
|
-
|
|
84
|
+
await this.pluginInput.client.app.log({
|
|
85
|
+
body: {
|
|
86
|
+
service: "opencode-logger",
|
|
87
|
+
level: "error",
|
|
88
|
+
message: "Failed to write to log file.",
|
|
89
|
+
extra: {
|
|
90
|
+
error,
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
});
|
|
62
94
|
}
|
|
63
95
|
}
|
|
64
96
|
}
|
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ export const loggerPlugin = async (ctx) => {
|
|
|
11
11
|
// ctx.directory is the project root in the context of the running plugin usually,
|
|
12
12
|
// but let's be safe and check if we need to resolve it.
|
|
13
13
|
// Based on the docs: directory: The current working directory.
|
|
14
|
-
const logger = new FileLogger(ctx.directory);
|
|
14
|
+
const logger = new FileLogger(ctx.directory, ctx);
|
|
15
15
|
await logger.init();
|
|
16
16
|
console.log("[Opencode Logger] Plugin initialized!");
|
|
17
17
|
const hooks = {
|