pi-radar 0.9.0 → 0.10.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.
@@ -8,11 +8,6 @@ function isUuid(value) {
8
8
  return typeof value === "string" && UUID.test(value);
9
9
  }
10
10
 
11
- // extension/radar-location.ts
12
- function radarPaneHandle(qualified) {
13
- return qualified.slice(qualified.lastIndexOf(":") + 1);
14
- }
15
-
16
11
  // extension/radar-launch.ts
17
12
  function unknownChild(reason) {
18
13
  return { kind: "unknown", diagnostic: trajectory(reason) };
@@ -104,7 +99,7 @@ async function relaunchRefusalForChild(client, agentId) {
104
99
  return `the child's registered process is ${verification === "verified" ? "still running" : "not proved gone"}`;
105
100
  }
106
101
  function refusedLaunch(message) {
107
- return { kind: "refused", message };
102
+ return { kind: "failed", message };
108
103
  }
109
104
  function unresolvedLaunch(requestId, message) {
110
105
  return {
@@ -113,14 +108,6 @@ function unresolvedLaunch(requestId, message) {
113
108
  message: `spawn ${requestId} is unresolved (${message})`
114
109
  };
115
110
  }
116
- function edgeStanding(edge) {
117
- if (edge.created === "refused" || edge.launched === "refused")
118
- return "refused";
119
- return edge.created === "completed" && edge.launched === "completed" ? "launched" : "unknown";
120
- }
121
- function edgeMessage(edge) {
122
- return `the daemon's spawn record is created ${edge.created} and launched ${edge.launched}`;
123
- }
124
111
  var PRE_EFFECT_CODES = [
125
112
  "absent",
126
113
  "unsupported",
@@ -133,14 +120,12 @@ var PRE_EFFECT_CODES = [
133
120
  "busy",
134
121
  "backend_unavailable"
135
122
  ];
136
- function spawnFailure(result, requestId) {
123
+ function launchFailure(result, requestId) {
137
124
  return PRE_EFFECT_CODES.includes(result.code) ? refusedLaunch(result.message) : unresolvedLaunch(requestId, result.message);
138
125
  }
139
126
  async function launchRadarWorker(options) {
140
127
  const { client, launch, signal } = options;
141
128
  const pollMs = options.pollMs ?? 250;
142
- const deadline = Date.now() + options.timeoutMs;
143
- const remaining = () => Math.max(0, deadline - Date.now());
144
129
  const parent = await options.publication.subject();
145
130
  if (parent === void 0 || !isUuid(parent.registration_id))
146
131
  return refusedLaunch(
@@ -171,55 +156,22 @@ async function launchRadarWorker(options) {
171
156
  ...Object.keys(launch.env).length > 0 ? { env: launch.env } : {}
172
157
  });
173
158
  if (spawned.ok === false) {
174
- const refusal = spawnFailure(spawned, launch.request_id);
175
- if (refusal.kind === "refused") return refusal;
176
- }
177
- if (spawned.ok === true) {
178
- const standing = edgeStanding(spawned.value);
179
- if (standing === "refused")
180
- return refusedLaunch(edgeMessage(spawned.value));
181
- if (standing === "unknown")
182
- return unresolvedLaunch(launch.request_id, edgeMessage(spawned.value));
159
+ const refusal = launchFailure(spawned, launch.request_id);
160
+ if (refusal.kind === "failed") return refusal;
183
161
  }
184
162
  const bound = await waitForChild(client, launch.request_id, {
185
- remaining,
186
163
  pollMs,
187
164
  ...signal !== void 0 ? { signal } : {}
188
165
  });
189
166
  if (bound.kind !== "bound") return bound;
190
- const agentId = bound.registration_id;
191
- try {
192
- const state = await options.readers.waitForState(
193
- launch.mailbox,
194
- (candidate) => options.readers.startupAckMatches(candidate, {
195
- generation: launch.generation,
196
- runId: launch.identity.runId,
197
- ownerSessionId: launch.identity.ownerSessionId,
198
- workspaceId: launch.identity.workspaceId,
199
- agentLabel: launch.identity.agentLabel,
200
- // The child writes the raw TMUX_PANE of the pane it runs in. Requiring
201
- // the pane the daemon created is what refuses a child that inherited
202
- // another process's coordinates.
203
- paneId: radarPaneHandle(bound.pane_id)
204
- }),
205
- { timeoutMs: remaining(), ...signal !== void 0 ? { signal } : {} }
206
- );
207
- return {
208
- kind: "ready",
209
- value: {
210
- request_id: launch.request_id,
211
- subject_id: bound.subject_id,
212
- pane_id: bound.pane_id,
213
- state
214
- }
215
- };
216
- } catch (error) {
217
- const claimed = options.readers.readState(launch.mailbox)?.paneId;
218
- return unresolvedLaunch(
219
- launch.request_id,
220
- claimed !== void 0 && claimed !== radarPaneHandle(bound.pane_id) ? `the bound child ${agentId} claims the pane ${claimed}, not the pane ${bound.pane_id} this launch created for it` : `the bound child ${agentId} has not acknowledged this launch's startup (${String(error)})`
221
- );
222
- }
167
+ return {
168
+ kind: "ready",
169
+ value: {
170
+ request_id: launch.request_id,
171
+ subject_id: bound.subject_id,
172
+ pane_id: bound.pane_id
173
+ }
174
+ };
223
175
  }
224
176
  async function waitForChild(client, requestId, options) {
225
177
  let last = "the daemon has not answered";
@@ -228,37 +180,21 @@ async function waitForChild(client, requestId, options) {
228
180
  return unresolvedLaunch(requestId, `the launch was cancelled (${last})`);
229
181
  const answer = await client.spawnGet(requestId);
230
182
  if (answer.ok === true) {
231
- const { edge, state, freshness } = answer.value;
232
- const standing = edgeStanding(edge);
233
- if (standing === "refused")
234
- return refusedLaunch(`${edgeMessage(edge)}`);
235
- if (standing === "unknown")
236
- return unresolvedLaunch(requestId, edgeMessage(edge));
183
+ const { edge } = answer.value;
184
+ if (edge.withdrawn !== void 0)
185
+ return refusedLaunch(`the daemon withdrew this launch: ${edge.withdrawn.reason}`);
186
+ if (edge.granted_at === void 0) {
187
+ await delay(options.pollMs);
188
+ continue;
189
+ }
237
190
  const pane = edge.location?.pane;
238
191
  if (pane === void 0 || pane === "")
239
192
  return unresolvedLaunch(
240
193
  requestId,
241
194
  "the daemon's launch recorded no pane to verify the child against"
242
195
  );
243
- if (freshness !== "fresh")
244
- return unresolvedLaunch(
245
- requestId,
246
- state === "unresolved" ? `the daemon's inventory does not report the pane ${pane} its own record names for this child` : `the daemon cannot confirm the pane ${pane} it recorded for this child`
247
- );
248
- if (edge.exit_observation?.state === "exited")
249
- return unresolvedLaunch(
250
- requestId,
251
- "the daemon observed the launched child's process exit"
252
- );
253
196
  const agentId = edge.bound?.registration_id;
254
197
  if (agentId !== void 0 && isUuid(agentId)) {
255
- const source = edge.bound?.source;
256
- const incarnation = edge.bound?.incarnation;
257
- if (source === void 0 || source === "" || incarnation === void 0 || incarnation === "")
258
- return unresolvedLaunch(
259
- requestId,
260
- `the daemon bound the child ${agentId} without recording the process it registered as`
261
- );
262
198
  const subjectId = edge.bound?.subject_id;
263
199
  if (subjectId === void 0 || !isUuid(subjectId))
264
200
  return unresolvedLaunch(
@@ -268,26 +204,21 @@ async function waitForChild(client, requestId, options) {
268
204
  return {
269
205
  kind: "bound",
270
206
  subject_id: subjectId,
271
- registration_id: agentId,
272
- pane_id: pane,
273
- source,
274
- incarnation
207
+ pane_id: pane
275
208
  };
276
209
  }
277
210
  last = "no child has registered with this launch's token yet";
278
211
  } else {
279
- last = answer.message;
212
+ return unresolvedLaunch(requestId, answer.message);
280
213
  }
281
- if (options.remaining() <= 0)
282
- return unresolvedLaunch(requestId, last);
283
- await delay(options.pollMs, void 0, {
284
- ...options.signal !== void 0 ? { signal: options.signal } : {}
285
- });
214
+ await delay(options.pollMs);
286
215
  }
287
216
  }
288
217
  export {
218
+ launchFailure,
289
219
  launchRadarWorker,
290
220
  observeRadarChild,
291
221
  readProcessGone,
292
- relaunchRefusalForChild
222
+ relaunchRefusalForChild,
223
+ waitForChild
293
224
  };
@@ -1,6 +1,6 @@
1
1
  // extension/radar-runtime.ts
2
2
  var RADAR_RUNTIME_REQUEST = "pi-radar/runtime-request";
3
- var RADAR_RUNTIME_VERSION = 3;
3
+ var RADAR_RUNTIME_VERSION = 4;
4
4
  function lazyRadarRuntime(start) {
5
5
  let pending;
6
6
  return {