next-issue 6.6.77 → 6.6.78

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
@@ -723,7 +723,12 @@ affect another. The worker:
723
723
  - closes once no run is going when a client with a newer version connects, so
724
724
  that the client can start the newer worker;
725
725
  - stops every agent and command and exits on `SIGTERM` or `SIGINT`, and
726
- removes its socket and lock files.
726
+ removes its socket and lock files;
727
+ - keeps `.next-issue/worker.log`, where the extension writes the output of
728
+ the worker, within 10 MiB: when it starts and once a minute while it runs,
729
+ it cuts a log of more than 10 MiB to its newest 5 MiB, from the start of a
730
+ line. It skips the cut while a command that writes to the log runs. The
731
+ run logs under `.next-issue/runs/` hold the same events.
727
732
 
728
733
  Stop the worker of a repository with `next-issue stop` in that repository.
729
734
  Workers of other repositories carry on. This sends `SIGTERM` to the process in
package/dist/exec.mjs CHANGED
@@ -7,6 +7,10 @@ let observer;
7
7
  const DEFAULT_TIMEOUT_MS = minutesToMs(10);
8
8
  const defaultTimeout = new AsyncLocalStorage();
9
9
  const STDERR_TAIL = 200_000;
10
+ let shownCommands = 0;
11
+ export function showingCommands() {
12
+ return shownCommands > 0;
13
+ }
10
14
  export function setCommandObserver(next) {
11
15
  observer = next;
12
16
  }
@@ -66,9 +70,17 @@ export function run(command, args, options = {}) {
66
70
  const output = collect(child, options);
67
71
  const timer = deadline(limit, () => killTree(child));
68
72
  let done = false;
73
+ let shown = options.show === true;
74
+ if (shown) {
75
+ shownCommands += 1;
76
+ }
69
77
  const release = () => {
70
78
  timer.clear();
71
79
  unwatch();
80
+ if (shown) {
81
+ shown = false;
82
+ shownCommands -= 1;
83
+ }
72
84
  };
73
85
  const settle = (code) => {
74
86
  release();
package/dist/serve.mjs CHANGED
@@ -11,6 +11,7 @@ import { isNewer } from './protocol.mjs';
11
11
  import { listQuestions, questionSender, send } from './questions.mjs';
12
12
  import { runRepo } from './run.mjs';
13
13
  import { packageVersion } from './version.mjs';
14
+ import { keepLogTrimmed, LOG_CHECK_MS } from './worker-log.mjs';
14
15
  import { checkSocketPath, workerPaths } from './worker-paths.mjs';
15
16
  import { active, endStatus, newRun, requestStop, runControls, runsMessage, startRefusal, stopPoint, } from './worker-run.mjs';
16
17
  import { broadcast, closer, fileId, listen, parseMessage, removeOwned, shutdown, } from './worker-server.mjs';
@@ -134,8 +135,9 @@ export async function startWorker(options) {
134
135
  idleTimer = setTimeout(closeWhenIdle, options.idleMs ?? IDLE_MS);
135
136
  return { closed, close, release: () => removeOwned(owned) };
136
137
  }
137
- export async function serve(root) {
138
- const paths = workerPaths(root);
138
+ export async function serve(root, logCheckMs = LOG_CHECK_MS) {
139
+ const { logPath, ...paths } = workerPaths(root);
140
+ const stopTrimming = keepLogTrimmed(logPath, logCheckMs);
139
141
  const worker = await startWorker({
140
142
  root,
141
143
  ...paths,
@@ -144,6 +146,7 @@ export async function serve(root) {
144
146
  questions: listQuestions,
145
147
  });
146
148
  if (worker === undefined) {
149
+ stopTrimming();
147
150
  process.stderr.write('next-issue: another worker is running\n');
148
151
  return 1;
149
152
  }
@@ -159,5 +162,6 @@ export async function serve(root) {
159
162
  process.on('SIGINT', onInterrupt);
160
163
  process.stderr.write(`next-issue: worker listening on ${paths.socketPath}\n`);
161
164
  await worker.closed;
165
+ stopTrimming();
162
166
  return 0;
163
167
  }
@@ -0,0 +1,36 @@
1
+ import { closeSync, fstatSync, ftruncateSync, openSync, readSync, writeSync } from 'node:fs';
2
+ import { showingCommands } from './exec.mjs';
3
+ export const LOG_LIMIT_BYTES = 10 * 1024 * 1024;
4
+ export const LOG_KEEP_BYTES = 5 * 1024 * 1024;
5
+ export const LOG_CHECK_MS = 60_000;
6
+ export function trimLog(path) {
7
+ if (showingCommands()) {
8
+ return;
9
+ }
10
+ try {
11
+ const file = openSync(path, 'r+');
12
+ try {
13
+ const size = fstatSync(file).size;
14
+ if (size <= LOG_LIMIT_BYTES) {
15
+ return;
16
+ }
17
+ const tail = Buffer.alloc(LOG_KEEP_BYTES);
18
+ const read = readSync(file, tail, 0, LOG_KEEP_BYTES, size - LOG_KEEP_BYTES);
19
+ const kept = tail.subarray(tail.indexOf(10) + 1, read);
20
+ writeSync(file, kept, 0, kept.length, 0);
21
+ ftruncateSync(file, kept.length);
22
+ }
23
+ finally {
24
+ closeSync(file);
25
+ }
26
+ }
27
+ catch {
28
+ return;
29
+ }
30
+ }
31
+ export function keepLogTrimmed(path, checkMs) {
32
+ trimLog(path);
33
+ const timer = setInterval(() => trimLog(path), checkMs);
34
+ timer.unref();
35
+ return () => clearInterval(timer);
36
+ }
@@ -5,6 +5,7 @@ export function workerPaths(root) {
5
5
  return {
6
6
  socketPath: join(dir, 'worker.sock'),
7
7
  lockPath: join(dir, 'worker.lock'),
8
+ logPath: join(dir, 'worker.log'),
8
9
  };
9
10
  }
10
11
  export function checkSocketPath(path, platform = process.platform) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "6.6.77",
3
+ "version": "6.6.78",
4
4
  "description": "Autonomous issue harness driven by the pi SDK",
5
5
  "keywords": [
6
6
  "github",