codex-blocker 0.0.7 → 0.0.8

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/bin.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  DEFAULT_PORT,
4
4
  startServer
5
- } from "./chunk-APDAIY47.js";
5
+ } from "./chunk-2Q6Z6NQH.js";
6
6
 
7
7
  // src/bin.ts
8
8
  import { createInterface } from "readline";
@@ -222,6 +222,8 @@ function parseCodexLine(line, sessionId) {
222
222
 
223
223
  // src/codex.ts
224
224
  var DEFAULT_CODEX_HOME = join(homedir(), ".codex");
225
+ var TAIL_MAX_BYTES = 64 * 1024;
226
+ var TAIL_MAX_LINES = 200;
225
227
  async function listRolloutFiles(root) {
226
228
  const files = [];
227
229
  const entries = await fs.readdir(root, { withFileTypes: true });
@@ -235,6 +237,30 @@ async function listRolloutFiles(root) {
235
237
  }
236
238
  return files;
237
239
  }
240
+ async function readTailLines(filePath, fileSize, maxBytes, maxLines) {
241
+ if (fileSize === 0) return [];
242
+ const start = Math.max(0, fileSize - maxBytes);
243
+ const end = Math.max(fileSize - 1, start);
244
+ const chunks = [];
245
+ await new Promise((resolve, reject) => {
246
+ const stream = createReadStream(filePath, { start, end });
247
+ stream.on("data", (chunk) => chunks.push(Buffer.from(chunk)));
248
+ stream.on("error", reject);
249
+ stream.on("end", resolve);
250
+ });
251
+ let content = Buffer.concat(chunks).toString("utf-8");
252
+ let lines = content.split("\n");
253
+ if (start > 0 && content[0] !== "\n") {
254
+ lines = lines.slice(1);
255
+ }
256
+ if (lines.length > 0 && lines[lines.length - 1]?.trim() === "") {
257
+ lines.pop();
258
+ }
259
+ if (lines.length > maxLines) {
260
+ lines = lines.slice(-maxLines);
261
+ }
262
+ return lines.filter((line) => line.trim().length > 0);
263
+ }
238
264
  async function readNewLines(filePath, fileState) {
239
265
  const stat = await fs.stat(filePath);
240
266
  if (stat.size < fileState.position) {
@@ -306,6 +332,15 @@ var CodexSessionWatcher = class {
306
332
  try {
307
333
  const stat = await fs.stat(filePath);
308
334
  fileState.position = stat.size;
335
+ const tailLines = await readTailLines(
336
+ filePath,
337
+ stat.size,
338
+ TAIL_MAX_BYTES,
339
+ TAIL_MAX_LINES
340
+ );
341
+ if (tailLines.length > 0) {
342
+ this.processLines(tailLines, fileState);
343
+ }
309
344
  } catch {
310
345
  continue;
311
346
  }
@@ -318,22 +353,25 @@ var CodexSessionWatcher = class {
318
353
  continue;
319
354
  }
320
355
  if (newLines.length === 0) continue;
321
- for (const line of newLines) {
322
- const parsed = parseCodexLine(line, fileState.sessionId);
323
- fileState.sessionId = parsed.sessionId;
324
- if (parsed.previousSessionId) {
325
- this.state.removeSession(parsed.previousSessionId);
326
- }
327
- this.state.markCodexSessionSeen(parsed.sessionId, parsed.cwd);
328
- if (parsed.markWorking) {
329
- this.state.handleCodexActivity({
330
- sessionId: parsed.sessionId,
331
- cwd: parsed.cwd
332
- });
333
- }
334
- if (parsed.markIdle) {
335
- this.state.setCodexIdle(parsed.sessionId, parsed.cwd);
336
- }
356
+ this.processLines(newLines, fileState);
357
+ }
358
+ }
359
+ processLines(lines, fileState) {
360
+ for (const line of lines) {
361
+ const parsed = parseCodexLine(line, fileState.sessionId);
362
+ fileState.sessionId = parsed.sessionId;
363
+ if (parsed.previousSessionId) {
364
+ this.state.removeSession(parsed.previousSessionId);
365
+ }
366
+ this.state.markCodexSessionSeen(parsed.sessionId, parsed.cwd);
367
+ if (parsed.markWorking) {
368
+ this.state.handleCodexActivity({
369
+ sessionId: parsed.sessionId,
370
+ cwd: parsed.cwd
371
+ });
372
+ }
373
+ if (parsed.markIdle) {
374
+ this.state.setCodexIdle(parsed.sessionId, parsed.cwd);
337
375
  }
338
376
  }
339
377
  }
package/dist/server.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  startServer
3
- } from "./chunk-APDAIY47.js";
3
+ } from "./chunk-2Q6Z6NQH.js";
4
4
  export {
5
5
  startServer
6
6
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codex-blocker",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "Block distracting websites unless Codex is actively running inference. Forked from Theo Browne's (T3) Claude Blocker",
5
5
  "author": "Adam Blumoff ",
6
6
  "repository": {