pi-radar 0.5.0 → 0.6.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.
@@ -11,6 +11,8 @@ import type {
11
11
  HandoffSerialize,
12
12
  ManagedLaunchMetadataDeserialize,
13
13
  SpawnExitObservationSerialize,
14
+ SpawnListParamsDeserialize,
15
+ SpawnListPageSerialize,
14
16
  } from "./generated-contracts.ts";
15
17
 
16
18
  /**
@@ -30,12 +32,16 @@ import type {
30
32
  * served under the old name.
31
33
  */
32
34
  export const RADAR_PROTOCOL_VERSION = 2;
33
- /** The minimum daemon wire revision this client understands. */
34
- export const RADAR_MINIMUM_REVISION = 3;
35
+ /**
36
+ * Revision 5 names attempts by claim_id and requires exact-claim controls.
37
+ * Earlier daemons expose different identity fields; require a coordinated update.
38
+ */
39
+ export const RADAR_MINIMUM_REVISION = 5;
35
40
  /** Public daemon contracts this client may preflight. */
36
41
  export const RADAR_REGISTRY_CONTRACT = "registry.v1";
37
42
  export const RADAR_REGISTRY_FACTS_CONTRACT = "registry.facts.v1";
38
43
  export const RADAR_SPAWN_CONTRACT = "spawn.v1";
44
+ export const RADAR_SPAWN_LIST_CONTRACT = "spawn.list.v1";
39
45
  export const RADAR_SPAWN_CLOSE_CONTRACT = "spawn.close.v1";
40
46
  export const RADAR_SPAWN_LAUNCH_CONTEXT_CONTRACT = "spawn.launch_context.v1";
41
47
  export const RADAR_EVENTS_CONTRACT = "events.v1";
@@ -558,7 +564,6 @@ function handoffAt(value: unknown): HandoffSerialize | undefined {
558
564
  const version = numberAt(value, "version");
559
565
  const id = stringAt(value, "id");
560
566
  const sender = recordAt(value, "sender");
561
- const senderGeneration = numberAt(sender, "execution_generation");
562
567
  const target = stringAt(value, "recipient_subject_id");
563
568
  const summary = stringAt(value, "summary");
564
569
  const content = stringAt(value, "content");
@@ -569,8 +574,7 @@ function handoffAt(value: unknown): HandoffSerialize | undefined {
569
574
  if (
570
575
  version !== 1 || !isUuid(id) || !isUuid(stringAt(sender, "registration_id")) ||
571
576
  !isUuid(stringAt(sender, "session_id")) || !isUuid(stringAt(sender, "subject_id")) ||
572
- !isUuid(stringAt(sender, "execution_id")) || !Number.isSafeInteger(senderGeneration) ||
573
- (senderGeneration ?? 0) < 1 || !isUuid(target) || summary === undefined || content === undefined ||
577
+ !isUuid(stringAt(sender, "claim_id")) || !isUuid(target) || summary === undefined || content === undefined ||
574
578
  published === undefined || !Number.isSafeInteger(published) || published < 0 ||
575
579
  (correlation !== undefined && correlation !== null &&
576
580
  (typeof correlation !== "string" || correlation.length === 0 ||
@@ -583,13 +587,11 @@ function handoffReceiptAt(value: unknown): HandoffReceiptSerialize | undefined {
583
587
  const version = numberAt(value, "version");
584
588
  const handoffId = stringAt(value, "handoff_id");
585
589
  const recipient = recordAt(value, "recipient");
586
- const generation = numberAt(recipient, "execution_generation");
587
590
  const received = numberAt(value, "received_at_unix_ms");
588
591
  if (
589
592
  version !== 1 || !isUuid(handoffId) || !isUuid(stringAt(recipient, "registration_id")) ||
590
593
  !isUuid(stringAt(recipient, "session_id")) || !isUuid(stringAt(recipient, "subject_id")) ||
591
- !isUuid(stringAt(recipient, "execution_id")) || !Number.isSafeInteger(generation) ||
592
- (generation ?? 0) < 1 || received === undefined || !Number.isSafeInteger(received) || received < 0
594
+ !isUuid(stringAt(recipient, "claim_id")) || received === undefined || !Number.isSafeInteger(received) || received < 0
593
595
  ) return undefined;
594
596
  return value as HandoffReceiptSerialize;
595
597
  }
@@ -1099,6 +1101,8 @@ export type RadarClient = {
1099
1101
  env?: Record<string, string>;
1100
1102
  managed?: RadarManagedLaunchMetadata;
1101
1103
  }): Promise<RadarResult<RadarSpawnEdge>>;
1104
+ /** List launches owned by this client's registered process. */
1105
+ spawnList(request: Pick<SpawnListParamsDeserialize, "after" | "limit">): Promise<RadarResult<SpawnListPageSerialize>>;
1102
1106
  spawnGet(request_id: string): Promise<RadarResult<RadarSpawnTopology>>;
1103
1107
  /** The registered child's process verdict, read from its immutable claim. */
1104
1108
  agentGet(registration_id: string): Promise<RadarResult<RadarAgentProcess>>;
@@ -1442,6 +1446,7 @@ export function createRadarClient(options: RadarClientOptions = {}): RadarClient
1442
1446
  };
1443
1447
  return answer;
1444
1448
  };
1449
+ let processRegistrationId: string | undefined;
1445
1450
  let handshake: Promise<RadarResult<RadarHandshake>> | undefined;
1446
1451
  const negotiated = async (): Promise<RadarResult<RadarHandshake>> => {
1447
1452
  handshake ??= probe();
@@ -1547,6 +1552,7 @@ export function createRadarClient(options: RadarClientOptions = {}): RadarClient
1547
1552
  const record = (answer.value as { registration?: unknown }).registration;
1548
1553
  const agentId = stringAt(record, "registration_id");
1549
1554
  if (!isUuid(agentId)) return protocol("registration reply carries no registration_id");
1555
+ processRegistrationId = agentId;
1550
1556
  return { ok: true, value: { registration_id: agentId } };
1551
1557
  });
1552
1558
  },
@@ -1700,6 +1706,32 @@ export function createRadarClient(options: RadarClientOptions = {}): RadarClient
1700
1706
  },
1701
1707
  );
1702
1708
  },
1709
+ async spawnList(request) {
1710
+ const registrationId = processRegistrationId;
1711
+ if (registrationId === undefined)
1712
+ return { ok: false, code: "refused", message: "spawn.list requires this client's process registration" };
1713
+ return withContract(RADAR_SPAWN_LIST_CONTRACT, async () => {
1714
+ const params: SpawnListParamsDeserialize = {
1715
+ registration_id: registrationId,
1716
+ ...(request.after !== undefined ? { after: request.after } : {}),
1717
+ ...(request.limit !== undefined ? { limit: request.limit } : {}),
1718
+ };
1719
+ const answer = await call("spawn.list", { ...params });
1720
+ if (answer.ok === false) return answer;
1721
+ const spawns = recordAt(answer.value, "spawns");
1722
+ const next = recordAt(answer.value, "next");
1723
+ if (!Array.isArray(spawns) || (next != null && !isUuid(next)))
1724
+ return protocol("spawn.list reply carries no valid page");
1725
+ for (const spawn of spawns) {
1726
+ const decoded = spawnTopology(spawn);
1727
+ if (decoded.ok === false) return decoded;
1728
+ if (typeof recordAt(spawn, "version") !== "number" || typeof recordAt(spawn, "recorded_at") !== "string" ||
1729
+ !["unbound", "bound", "unresolved"].includes(String(recordAt(spawn, "state"))))
1730
+ return protocol("spawn.list reply carries an incomplete topology");
1731
+ }
1732
+ return { ok: true, value: answer.value as SpawnListPageSerialize };
1733
+ });
1734
+ },
1703
1735
  async spawnGet(requestId) {
1704
1736
  if (!isUuid(requestId))
1705
1737
  return {
@@ -975,6 +975,7 @@ function createPresenceReporter(input: PresenceReporterInput): RadarPresenceRepo
975
975
  type State = {
976
976
  version: 2;
977
977
  claim_id: string;
978
+ initial_load?: boolean;
978
979
  session: string;
979
980
  registration_id?: string;
980
981
  subject_id?: string;
@@ -1032,6 +1033,13 @@ function createPresenceReporter(input: PresenceReporterInput): RadarPresenceRepo
1032
1033
  await releasePending();
1033
1034
  const registration = await input.registration();
1034
1035
  if (!registration?.process || state !== claim || stopped) return undefined;
1036
+ // The first load spends the pre-minted launch claim. Reloads get a fresh
1037
+ // claim; they must not reuse the released launch credential.
1038
+ if (claim.initial_load) {
1039
+ if (registration.spawn_token) claim.claim_id = registration.spawn_token;
1040
+ claim.initial_load = false;
1041
+ if (!save()) return undefined;
1042
+ }
1035
1043
  const answer = await client.presence({
1036
1044
  ...registration, process: registration.process,
1037
1045
  session_id: claim.session, claim_id: claim.claim_id,
@@ -1071,7 +1079,7 @@ function createPresenceReporter(input: PresenceReporterInput): RadarPresenceRepo
1071
1079
  releases.push({ registration_id: state.registration_id, claim_id: state.claim_id });
1072
1080
  }
1073
1081
  standing = undefined;
1074
- state = { version: 2, session, claim_id: randomUUID(), releases };
1082
+ state = { version: 2, session, claim_id: randomUUID(), initial_load: state === undefined, releases };
1075
1083
  save(); stopped = false;
1076
1084
  void ensure();
1077
1085
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-radar",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "type": "module",
5
5
  "description": "Radar daemon client, communication, publication, execution, location, launch and inspection surface for Pi extensions.",
6
6
  "license": "Apache-2.0",
@@ -4,13 +4,7 @@
4
4
  "additionalProperties": false,
5
5
  "description": "The current managed Pi execution that published or received a handoff.\n`subject_id` is stable across verified successors; `execution_id` and\ngeneration identify the exact execution that took the action.",
6
6
  "properties": {
7
- "execution_generation": {
8
- "format": "uint32",
9
- "maximum": 4294967295,
10
- "minimum": 1,
11
- "type": "integer"
12
- },
13
- "execution_id": {
7
+ "claim_id": {
14
8
  "type": "string"
15
9
  },
16
10
  "registration_id": {
@@ -27,8 +21,7 @@
27
21
  "registration_id",
28
22
  "session_id",
29
23
  "subject_id",
30
- "execution_id",
31
- "execution_generation"
24
+ "claim_id"
32
25
  ],
33
26
  "type": "object"
34
27
  }
@@ -4,13 +4,7 @@
4
4
  "additionalProperties": false,
5
5
  "description": "The current managed Pi execution that published or received a handoff.\n`subject_id` is stable across verified successors; `execution_id` and\ngeneration identify the exact execution that took the action.",
6
6
  "properties": {
7
- "execution_generation": {
8
- "format": "uint32",
9
- "maximum": 4294967295,
10
- "minimum": 1,
11
- "type": "integer"
12
- },
13
- "execution_id": {
7
+ "claim_id": {
14
8
  "type": "string"
15
9
  },
16
10
  "registration_id": {
@@ -27,8 +21,7 @@
27
21
  "registration_id",
28
22
  "session_id",
29
23
  "subject_id",
30
- "execution_id",
31
- "execution_generation"
24
+ "claim_id"
32
25
  ],
33
26
  "type": "object"
34
27
  }
@@ -4,13 +4,7 @@
4
4
  "additionalProperties": false,
5
5
  "description": "The current managed Pi execution that published or received a handoff.\n`subject_id` is stable across verified successors; `execution_id` and\ngeneration identify the exact execution that took the action.",
6
6
  "properties": {
7
- "execution_generation": {
8
- "format": "uint32",
9
- "maximum": 4294967295,
10
- "minimum": 1,
11
- "type": "integer"
12
- },
13
- "execution_id": {
7
+ "claim_id": {
14
8
  "type": "string"
15
9
  },
16
10
  "registration_id": {
@@ -27,8 +21,7 @@
27
21
  "registration_id",
28
22
  "session_id",
29
23
  "subject_id",
30
- "execution_id",
31
- "execution_generation"
24
+ "claim_id"
32
25
  ],
33
26
  "type": "object"
34
27
  }
@@ -4,13 +4,7 @@
4
4
  "additionalProperties": false,
5
5
  "description": "The current managed Pi execution that published or received a handoff.\n`subject_id` is stable across verified successors; `execution_id` and\ngeneration identify the exact execution that took the action.",
6
6
  "properties": {
7
- "execution_generation": {
8
- "format": "uint32",
9
- "maximum": 4294967295,
10
- "minimum": 1,
11
- "type": "integer"
12
- },
13
- "execution_id": {
7
+ "claim_id": {
14
8
  "type": "string"
15
9
  },
16
10
  "registration_id": {
@@ -27,8 +21,7 @@
27
21
  "registration_id",
28
22
  "session_id",
29
23
  "subject_id",
30
- "execution_id",
31
- "execution_generation"
24
+ "claim_id"
32
25
  ],
33
26
  "type": "object"
34
27
  }
@@ -1037,6 +1037,9 @@
1037
1037
  }
1038
1038
  ]
1039
1039
  },
1040
+ "claim_id": {
1041
+ "type": "string"
1042
+ },
1040
1043
  "identity_unresolved": {
1041
1044
  "type": "boolean"
1042
1045
  },
@@ -1067,6 +1070,7 @@
1067
1070
  },
1068
1071
  "required": [
1069
1072
  "subject_id",
1073
+ "claim_id",
1070
1074
  "process",
1071
1075
  "identity_unresolved",
1072
1076
  "metadata",
@@ -2375,6 +2379,12 @@
2375
2379
  "null"
2376
2380
  ]
2377
2381
  },
2382
+ "claim_id": {
2383
+ "type": [
2384
+ "string",
2385
+ "null"
2386
+ ]
2387
+ },
2378
2388
  "parent": {
2379
2389
  "type": "string"
2380
2390
  },
@@ -2383,12 +2393,6 @@
2383
2393
  },
2384
2394
  "state": {
2385
2395
  "$ref": "#/$defs/SpawnState"
2386
- },
2387
- "subject_id": {
2388
- "type": [
2389
- "string",
2390
- "null"
2391
- ]
2392
2396
  }
2393
2397
  },
2394
2398
  "required": [
@@ -1096,6 +1096,9 @@
1096
1096
  }
1097
1097
  ]
1098
1098
  },
1099
+ "claim_id": {
1100
+ "type": "string"
1101
+ },
1099
1102
  "identity_unresolved": {
1100
1103
  "type": "boolean"
1101
1104
  },
@@ -1126,6 +1129,7 @@
1126
1129
  },
1127
1130
  "required": [
1128
1131
  "subject_id",
1132
+ "claim_id",
1129
1133
  "process",
1130
1134
  "identity_unresolved",
1131
1135
  "metadata",
@@ -2491,6 +2495,12 @@
2491
2495
  "null"
2492
2496
  ]
2493
2497
  },
2498
+ "claim_id": {
2499
+ "type": [
2500
+ "string",
2501
+ "null"
2502
+ ]
2503
+ },
2494
2504
  "parent": {
2495
2505
  "type": "string"
2496
2506
  },
@@ -2499,18 +2509,12 @@
2499
2509
  },
2500
2510
  "state": {
2501
2511
  "$ref": "#/$defs/SpawnState"
2502
- },
2503
- "subject_id": {
2504
- "type": [
2505
- "string",
2506
- "null"
2507
- ]
2508
2512
  }
2509
2513
  },
2510
2514
  "required": [
2511
2515
  "parent",
2512
2516
  "request_id",
2513
- "subject_id",
2517
+ "claim_id",
2514
2518
  "child_source",
2515
2519
  "child_incarnation",
2516
2520
  "state"
@@ -1037,6 +1037,9 @@
1037
1037
  }
1038
1038
  ]
1039
1039
  },
1040
+ "claim_id": {
1041
+ "type": "string"
1042
+ },
1040
1043
  "identity_unresolved": {
1041
1044
  "type": "boolean"
1042
1045
  },
@@ -1067,6 +1070,7 @@
1067
1070
  },
1068
1071
  "required": [
1069
1072
  "subject_id",
1073
+ "claim_id",
1070
1074
  "process",
1071
1075
  "identity_unresolved",
1072
1076
  "metadata",
@@ -2240,6 +2244,12 @@
2240
2244
  "null"
2241
2245
  ]
2242
2246
  },
2247
+ "claim_id": {
2248
+ "type": [
2249
+ "string",
2250
+ "null"
2251
+ ]
2252
+ },
2243
2253
  "parent": {
2244
2254
  "type": "string"
2245
2255
  },
@@ -2248,12 +2258,6 @@
2248
2258
  },
2249
2259
  "state": {
2250
2260
  "$ref": "#/$defs/SpawnState"
2251
- },
2252
- "subject_id": {
2253
- "type": [
2254
- "string",
2255
- "null"
2256
- ]
2257
2261
  }
2258
2262
  },
2259
2263
  "required": [
@@ -1096,6 +1096,9 @@
1096
1096
  }
1097
1097
  ]
1098
1098
  },
1099
+ "claim_id": {
1100
+ "type": "string"
1101
+ },
1099
1102
  "identity_unresolved": {
1100
1103
  "type": "boolean"
1101
1104
  },
@@ -1126,6 +1129,7 @@
1126
1129
  },
1127
1130
  "required": [
1128
1131
  "subject_id",
1132
+ "claim_id",
1129
1133
  "process",
1130
1134
  "identity_unresolved",
1131
1135
  "metadata",
@@ -2347,6 +2351,12 @@
2347
2351
  "null"
2348
2352
  ]
2349
2353
  },
2354
+ "claim_id": {
2355
+ "type": [
2356
+ "string",
2357
+ "null"
2358
+ ]
2359
+ },
2350
2360
  "parent": {
2351
2361
  "type": "string"
2352
2362
  },
@@ -2355,18 +2365,12 @@
2355
2365
  },
2356
2366
  "state": {
2357
2367
  "$ref": "#/$defs/SpawnState"
2358
- },
2359
- "subject_id": {
2360
- "type": [
2361
- "string",
2362
- "null"
2363
- ]
2364
2368
  }
2365
2369
  },
2366
2370
  "required": [
2367
2371
  "parent",
2368
2372
  "request_id",
2369
- "subject_id",
2373
+ "claim_id",
2370
2374
  "child_source",
2371
2375
  "child_incarnation",
2372
2376
  "state"