@vite-plugin-opencode-assistant/shared 1.0.65 → 1.0.67

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.
@@ -1,7 +1,6 @@
1
1
  export interface FileLogEntry {
2
2
  level: "info" | "warn" | "error";
3
3
  message: string;
4
- timestamp: string;
5
4
  source: string;
6
5
  }
7
6
  export interface LogFileOptions {
@@ -12,12 +11,10 @@ export declare function readLogFile(options: LogFileOptions & {
12
11
  projectRoot?: string;
13
12
  level?: ("info" | "warn" | "error") | ("info" | "warn" | "error")[];
14
13
  limit?: number;
15
- since?: string;
16
14
  }): Promise<FileLogEntry[]>;
17
15
  export declare function readLogFileTail(options: LogFileOptions & {
18
16
  projectRoot?: string;
19
17
  lines?: number;
20
18
  limit?: number;
21
19
  level?: ("info" | "warn" | "error") | ("info" | "warn" | "error")[];
22
- since?: string;
23
20
  }): Promise<FileLogEntry[]>;
@@ -32,32 +32,9 @@ function detectLogLevel(line) {
32
32
  }
33
33
  return "info";
34
34
  }
35
- function parseLogTimestamp(line) {
36
- const timestampPatterns = [
37
- /(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}[+-]\d{2}:\d{2})/,
38
- /(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z?)/,
39
- /(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z)/,
40
- /(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})/,
41
- /(\d{2}\/\w{3}\/\d{4}:\d{2}:\d{2}:\d{2} [+-]\d{4})/,
42
- /(\d{2}\/\d{2}\/\d{4},\s*\d{1,2}:\d{2}:\d{2}\s*(?:AM|PM))/i,
43
- /([A-Z]{3}, \d{2} \w{3} \d{4} \d{2}:\d{2}:\d{2} GMT)/,
44
- /(\[([^\]]+)\])/
45
- ];
46
- for (const pattern of timestampPatterns) {
47
- const match = line.match(pattern);
48
- if (match) {
49
- const timestampStr = match[1];
50
- const date = new Date(timestampStr);
51
- if (!isNaN(date.getTime())) {
52
- return date.toISOString();
53
- }
54
- }
55
- }
56
- return null;
57
- }
58
35
  function readLogFile(options) {
59
36
  return __async(this, null, function* () {
60
- const { name, filePath, projectRoot, level, limit, since } = options;
37
+ const { name, filePath, projectRoot, level, limit } = options;
61
38
  const resolvedPath = resolvePath(filePath, projectRoot);
62
39
  if (!fs.existsSync(resolvedPath)) {
63
40
  log.debug(`Log file does not exist: ${resolvedPath}`);
@@ -67,22 +44,12 @@ function readLogFile(options) {
67
44
  const content = yield fs.promises.readFile(resolvedPath, "utf-8");
68
45
  const lines = content.split("\n").filter((line) => line.trim());
69
46
  const entries = [];
70
- const sinceDate = since ? new Date(since) : null;
71
- let lastTimestamp = null;
72
47
  for (const line of lines) {
73
- const parsedTimestamp = parseLogTimestamp(line);
74
- if (parsedTimestamp) {
75
- lastTimestamp = parsedTimestamp;
76
- }
77
48
  const entry = {
78
49
  level: detectLogLevel(line),
79
50
  message: line,
80
- timestamp: parsedTimestamp || lastTimestamp || (/* @__PURE__ */ new Date()).toISOString(),
81
51
  source: `file:${name}`
82
52
  };
83
- if (sinceDate && new Date(entry.timestamp) < sinceDate) {
84
- continue;
85
- }
86
53
  if (level) {
87
54
  const levels = Array.isArray(level) ? level : [level];
88
55
  if (!levels.includes(entry.level)) {
@@ -103,7 +70,7 @@ function readLogFile(options) {
103
70
  }
104
71
  function readLogFileTail(options) {
105
72
  return __async(this, null, function* () {
106
- const { name, filePath, projectRoot, lines = 200, limit, level, since } = options;
73
+ const { name, filePath, projectRoot, lines = 200, limit, level } = options;
107
74
  const resolvedPath = resolvePath(filePath, projectRoot);
108
75
  if (!fs.existsSync(resolvedPath)) {
109
76
  log.debug(`Log file does not exist: ${resolvedPath}`);
@@ -115,7 +82,7 @@ function readLogFileTail(options) {
115
82
  const chunkSize = 16 * 1024;
116
83
  let position = stat.size;
117
84
  let buffer = Buffer.alloc(0);
118
- const lineCount = 0;
85
+ let lineCount = 0;
119
86
  while (position > 0 && lineCount <= lines) {
120
87
  const readSize = Math.min(chunkSize, position);
121
88
  position -= readSize;
@@ -123,6 +90,7 @@ function readLogFileTail(options) {
123
90
  fs.readSync(fd, chunk, 0, readSize, position);
124
91
  buffer = Buffer.concat([chunk, buffer]);
125
92
  const newLineCount = buffer.filter((byte) => byte === 10).length;
93
+ lineCount = newLineCount;
126
94
  if (newLineCount >= lines) {
127
95
  const linesArray = buffer.toString("utf-8").split("\n");
128
96
  const excessLines = newLineCount - lines;
@@ -143,17 +111,12 @@ function readLogFileTail(options) {
143
111
  const content = buffer.toString("utf-8").trim();
144
112
  const logLines = content.split("\n").filter((line) => line.trim());
145
113
  const entries = [];
146
- const sinceDate = since ? new Date(since) : null;
147
114
  for (const line of logLines) {
148
115
  const entry = {
149
116
  level: detectLogLevel(line),
150
117
  message: line,
151
- timestamp: parseLogTimestamp(line) || (/* @__PURE__ */ new Date()).toISOString(),
152
118
  source: `file:${name}`
153
119
  };
154
- if (sinceDate && new Date(entry.timestamp) < sinceDate) {
155
- continue;
156
- }
157
120
  if (level) {
158
121
  const levels = Array.isArray(level) ? level : [level];
159
122
  if (!levels.includes(entry.level)) {
@@ -65,32 +65,9 @@ function detectLogLevel(line) {
65
65
  }
66
66
  return "info";
67
67
  }
68
- function parseLogTimestamp(line) {
69
- const timestampPatterns = [
70
- /(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}[+-]\d{2}:\d{2})/,
71
- /(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z?)/,
72
- /(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z)/,
73
- /(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})/,
74
- /(\d{2}\/\w{3}\/\d{4}:\d{2}:\d{2}:\d{2} [+-]\d{4})/,
75
- /(\d{2}\/\d{2}\/\d{4},\s*\d{1,2}:\d{2}:\d{2}\s*(?:AM|PM))/i,
76
- /([A-Z]{3}, \d{2} \w{3} \d{4} \d{2}:\d{2}:\d{2} GMT)/,
77
- /(\[([^\]]+)\])/
78
- ];
79
- for (const pattern of timestampPatterns) {
80
- const match = line.match(pattern);
81
- if (match) {
82
- const timestampStr = match[1];
83
- const date = new Date(timestampStr);
84
- if (!isNaN(date.getTime())) {
85
- return date.toISOString();
86
- }
87
- }
88
- }
89
- return null;
90
- }
91
68
  function readLogFile(options) {
92
69
  return __async(this, null, function* () {
93
- const { name, filePath, projectRoot, level, limit, since } = options;
70
+ const { name, filePath, projectRoot, level, limit } = options;
94
71
  const resolvedPath = resolvePath(filePath, projectRoot);
95
72
  if (!import_fs.default.existsSync(resolvedPath)) {
96
73
  log.debug(`Log file does not exist: ${resolvedPath}`);
@@ -100,22 +77,12 @@ function readLogFile(options) {
100
77
  const content = yield import_fs.default.promises.readFile(resolvedPath, "utf-8");
101
78
  const lines = content.split("\n").filter((line) => line.trim());
102
79
  const entries = [];
103
- const sinceDate = since ? new Date(since) : null;
104
- let lastTimestamp = null;
105
80
  for (const line of lines) {
106
- const parsedTimestamp = parseLogTimestamp(line);
107
- if (parsedTimestamp) {
108
- lastTimestamp = parsedTimestamp;
109
- }
110
81
  const entry = {
111
82
  level: detectLogLevel(line),
112
83
  message: line,
113
- timestamp: parsedTimestamp || lastTimestamp || (/* @__PURE__ */ new Date()).toISOString(),
114
84
  source: `file:${name}`
115
85
  };
116
- if (sinceDate && new Date(entry.timestamp) < sinceDate) {
117
- continue;
118
- }
119
86
  if (level) {
120
87
  const levels = Array.isArray(level) ? level : [level];
121
88
  if (!levels.includes(entry.level)) {
@@ -136,7 +103,7 @@ function readLogFile(options) {
136
103
  }
137
104
  function readLogFileTail(options) {
138
105
  return __async(this, null, function* () {
139
- const { name, filePath, projectRoot, lines = 200, limit, level, since } = options;
106
+ const { name, filePath, projectRoot, lines = 200, limit, level } = options;
140
107
  const resolvedPath = resolvePath(filePath, projectRoot);
141
108
  if (!import_fs.default.existsSync(resolvedPath)) {
142
109
  log.debug(`Log file does not exist: ${resolvedPath}`);
@@ -148,7 +115,7 @@ function readLogFileTail(options) {
148
115
  const chunkSize = 16 * 1024;
149
116
  let position = stat.size;
150
117
  let buffer = Buffer.alloc(0);
151
- const lineCount = 0;
118
+ let lineCount = 0;
152
119
  while (position > 0 && lineCount <= lines) {
153
120
  const readSize = Math.min(chunkSize, position);
154
121
  position -= readSize;
@@ -156,6 +123,7 @@ function readLogFileTail(options) {
156
123
  import_fs.default.readSync(fd, chunk, 0, readSize, position);
157
124
  buffer = Buffer.concat([chunk, buffer]);
158
125
  const newLineCount = buffer.filter((byte) => byte === 10).length;
126
+ lineCount = newLineCount;
159
127
  if (newLineCount >= lines) {
160
128
  const linesArray = buffer.toString("utf-8").split("\n");
161
129
  const excessLines = newLineCount - lines;
@@ -176,17 +144,12 @@ function readLogFileTail(options) {
176
144
  const content = buffer.toString("utf-8").trim();
177
145
  const logLines = content.split("\n").filter((line) => line.trim());
178
146
  const entries = [];
179
- const sinceDate = since ? new Date(since) : null;
180
147
  for (const line of logLines) {
181
148
  const entry = {
182
149
  level: detectLogLevel(line),
183
150
  message: line,
184
- timestamp: parseLogTimestamp(line) || (/* @__PURE__ */ new Date()).toISOString(),
185
151
  source: `file:${name}`
186
152
  };
187
- if (sinceDate && new Date(entry.timestamp) < sinceDate) {
188
- continue;
189
- }
190
153
  if (level) {
191
154
  const levels = Array.isArray(level) ? level : [level];
192
155
  if (!levels.includes(entry.level)) {
@@ -1,7 +1,6 @@
1
1
  export interface FileLogEntry {
2
2
  level: "info" | "warn" | "error";
3
3
  message: string;
4
- timestamp: string;
5
4
  source: string;
6
5
  }
7
6
  export interface LogFileOptions {
@@ -12,12 +11,10 @@ export declare function readLogFile(options: LogFileOptions & {
12
11
  projectRoot?: string;
13
12
  level?: ("info" | "warn" | "error") | ("info" | "warn" | "error")[];
14
13
  limit?: number;
15
- since?: string;
16
14
  }): Promise<FileLogEntry[]>;
17
15
  export declare function readLogFileTail(options: LogFileOptions & {
18
16
  projectRoot?: string;
19
17
  lines?: number;
20
18
  limit?: number;
21
19
  level?: ("info" | "warn" | "error") | ("info" | "warn" | "error")[];
22
- since?: string;
23
20
  }): Promise<FileLogEntry[]>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vite-plugin-opencode-assistant/shared",
3
- "version": "1.0.65",
3
+ "version": "1.0.67",
4
4
  "type": "module",
5
5
  "main": "lib/index.cjs",
6
6
  "module": "es/index.mjs",