next-issue 9.7.0 → 9.8.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 CHANGED
@@ -996,6 +996,10 @@ affect another. The worker:
996
996
  - refuses a `start`, `stop`, `watch`, `hunt`, `questions` or `upcoming` message whose `root` is not
997
997
  the exact path of its repository with an `error` message, and starts or
998
998
  stops nothing;
999
+ - sends each `error` as
1000
+ `{ "type": "error", "root": "<path>", "message": "<text>" }`. When a `start`,
1001
+ `stop`, `watch`, `hunt` or `refresh` message carries an `"id"`, the `error`
1002
+ that refuses it carries the same `id`;
999
1003
  - runs at most one run at a time. A client starts it with
1000
1004
  `{ "type": "start", "root": "<path>", "args": [...] }`. Each run is like
1001
1005
  `next-issue start` with those args, or with none when `args` is left out
package/dist/serve.mjs CHANGED
@@ -56,11 +56,11 @@ export async function startWorker(options) {
56
56
  broadcast(sockets, runs);
57
57
  }
58
58
  };
59
- const start = (socket, root, argv, resume) => {
59
+ const start = (refuse, root, argv, resume) => {
60
60
  const refusal = startRefusal(runs.get(root), restart !== undefined);
61
61
  if (refusal !== undefined) {
62
62
  if (!resume) {
63
- send(socket, { type: 'error', root, message: refusal });
63
+ refuse(refusal);
64
64
  }
65
65
  return;
66
66
  }
@@ -69,7 +69,7 @@ export async function startWorker(options) {
69
69
  args = parseStartArgs(argv);
70
70
  }
71
71
  catch (error) {
72
- send(socket, { type: 'error', root, message: message(error) });
72
+ refuse(message(error));
73
73
  return;
74
74
  }
75
75
  const run = newRun({ ...startProgress(args.hunt), watching: args.watch });
@@ -83,10 +83,10 @@ export async function startWorker(options) {
83
83
  .then(() => update({ ...run.progress, status: endStatus(run) }), (error) => update({ ...run.progress, status: 'failed', error: message(error) }))
84
84
  .finally(closeWhenIdle);
85
85
  };
86
- const stop = (socket, root, after) => {
86
+ const stop = (refuse, root, after) => {
87
87
  const point = stopPoint(after);
88
88
  if (point === undefined) {
89
- send(socket, { type: 'error', root, message: `stop does not take --after ${String(after)}` });
89
+ refuse(`stop does not take --after ${String(after)}`);
90
90
  return;
91
91
  }
92
92
  const run = runs.get(root);
@@ -95,18 +95,18 @@ export async function startWorker(options) {
95
95
  broadcast(sockets, runs);
96
96
  }
97
97
  };
98
- const toggle = (socket, root, on, set) => {
98
+ const toggle = (refuse, root, on, set) => {
99
99
  const run = runs.get(root);
100
100
  const refusal = switchRefusal(run);
101
101
  if (refusal !== undefined) {
102
- send(socket, { type: 'error', root, message: refusal });
102
+ refuse(refusal);
103
103
  return;
104
104
  }
105
105
  set(run, on);
106
106
  broadcast(sockets, runs);
107
107
  upgradeBetweenIssues(run);
108
108
  };
109
- const receive = (socket, value) => {
109
+ const receive = (socket, value, refuse) => {
110
110
  if (value.type === 'hello') {
111
111
  if (typeof value.version !== 'string') {
112
112
  throw new Error('a hello message needs its version as a string');
@@ -118,23 +118,19 @@ export async function startWorker(options) {
118
118
  }
119
119
  }
120
120
  else if (value.root !== options.root) {
121
- send(socket, {
122
- type: 'error',
123
- root: value.root,
124
- message: `the worker serves ${options.root} only`,
125
- });
121
+ refuse(`the worker serves ${options.root} only`);
126
122
  }
127
123
  else if (value.type === 'start') {
128
- start(socket, value.root, value.args ?? [], value.resume === true);
124
+ start(refuse, value.root, value.args ?? [], value.resume === true);
129
125
  }
130
126
  else if (value.type === 'stop') {
131
- stop(socket, value.root, value.after);
127
+ stop(refuse, value.root, value.after);
132
128
  }
133
129
  else if (value.type === 'hunt') {
134
- toggle(socket, value.root, value.on, setHunting);
130
+ toggle(refuse, value.root, value.on, setHunting);
135
131
  }
136
132
  else if (value.type === 'watch') {
137
- toggle(socket, value.root, value.on, setWatching);
133
+ toggle(refuse, value.root, value.on, setWatching);
138
134
  }
139
135
  else if (value.type === 'refresh') {
140
136
  requestRefresh(runs.get(value.root));
@@ -157,15 +153,12 @@ export async function startWorker(options) {
157
153
  if (value === undefined) {
158
154
  return;
159
155
  }
156
+ const refuse = refuser(socket, value, options.root);
160
157
  try {
161
- receive(socket, value);
158
+ receive(socket, value, refuse);
162
159
  }
163
160
  catch (error) {
164
- send(socket, {
165
- type: 'error',
166
- root: value.type === 'hello' ? options.root : value.root,
167
- message: message(error),
168
- });
161
+ refuse(message(error));
169
162
  }
170
163
  });
171
164
  });
@@ -177,6 +170,11 @@ export async function startWorker(options) {
177
170
  idleTimer = setTimeout(closeWhenIdle, options.idleMs ?? IDLE_MS);
178
171
  return { closed, close, release: () => removeOwned(owned) };
179
172
  }
173
+ function refuser(socket, value, served) {
174
+ const root = value.type === 'hello' ? served : value.root;
175
+ const id = 'id' in value ? value.id : undefined;
176
+ return (text) => send(socket, { type: 'error', root, message: text, ...(id === undefined ? {} : { id }) });
177
+ }
180
178
  export async function serve(root, logCheckMs = LOG_CHECK_MS) {
181
179
  const { logPath, ...paths } = workerPaths(root);
182
180
  const stopTrimming = keepLogTrimmed(logPath, logCheckMs);
@@ -17,12 +17,12 @@ function isClientMessage(value) {
17
17
  if (typeof value['root'] !== 'string') {
18
18
  return false;
19
19
  }
20
+ if (value['id'] !== undefined && typeof value['id'] !== 'string') {
21
+ return false;
22
+ }
20
23
  if (value['type'] === 'hunt' || value['type'] === 'watch') {
21
24
  return typeof value['on'] === 'boolean';
22
25
  }
23
- if (value['type'] === 'questions') {
24
- return value['id'] === undefined || typeof value['id'] === 'string';
25
- }
26
26
  return value['type'] !== 'start' || value['args'] === undefined || isStringArray(value['args']);
27
27
  }
28
28
  export function parseMessage(text) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "9.7.0",
3
+ "version": "9.8.0",
4
4
  "description": "Autonomous issue harness driven by the pi SDK",
5
5
  "keywords": [
6
6
  "github",