pi-radar 0.5.1 → 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
  /**
@@ -31,16 +33,15 @@ import type {
31
33
  */
32
34
  export const RADAR_PROTOCOL_VERSION = 2;
33
35
  /**
34
- * The minimum daemon wire revision this client understands. Revision 4 is where
35
- * Pi presence and exact session release arrived; a revision-3 daemon would pass
36
- * this handshake and then refuse every presence report, leaving a Pi session
37
- * silently unmanaged instead of telling the operator to restart the daemon.
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
38
  */
39
- export const RADAR_MINIMUM_REVISION = 4;
39
+ export const RADAR_MINIMUM_REVISION = 5;
40
40
  /** Public daemon contracts this client may preflight. */
41
41
  export const RADAR_REGISTRY_CONTRACT = "registry.v1";
42
42
  export const RADAR_REGISTRY_FACTS_CONTRACT = "registry.facts.v1";
43
43
  export const RADAR_SPAWN_CONTRACT = "spawn.v1";
44
+ export const RADAR_SPAWN_LIST_CONTRACT = "spawn.list.v1";
44
45
  export const RADAR_SPAWN_CLOSE_CONTRACT = "spawn.close.v1";
45
46
  export const RADAR_SPAWN_LAUNCH_CONTEXT_CONTRACT = "spawn.launch_context.v1";
46
47
  export const RADAR_EVENTS_CONTRACT = "events.v1";
@@ -563,7 +564,6 @@ function handoffAt(value: unknown): HandoffSerialize | undefined {
563
564
  const version = numberAt(value, "version");
564
565
  const id = stringAt(value, "id");
565
566
  const sender = recordAt(value, "sender");
566
- const senderGeneration = numberAt(sender, "execution_generation");
567
567
  const target = stringAt(value, "recipient_subject_id");
568
568
  const summary = stringAt(value, "summary");
569
569
  const content = stringAt(value, "content");
@@ -574,8 +574,7 @@ function handoffAt(value: unknown): HandoffSerialize | undefined {
574
574
  if (
575
575
  version !== 1 || !isUuid(id) || !isUuid(stringAt(sender, "registration_id")) ||
576
576
  !isUuid(stringAt(sender, "session_id")) || !isUuid(stringAt(sender, "subject_id")) ||
577
- !isUuid(stringAt(sender, "execution_id")) || !Number.isSafeInteger(senderGeneration) ||
578
- (senderGeneration ?? 0) < 1 || !isUuid(target) || summary === undefined || content === undefined ||
577
+ !isUuid(stringAt(sender, "claim_id")) || !isUuid(target) || summary === undefined || content === undefined ||
579
578
  published === undefined || !Number.isSafeInteger(published) || published < 0 ||
580
579
  (correlation !== undefined && correlation !== null &&
581
580
  (typeof correlation !== "string" || correlation.length === 0 ||
@@ -588,13 +587,11 @@ function handoffReceiptAt(value: unknown): HandoffReceiptSerialize | undefined {
588
587
  const version = numberAt(value, "version");
589
588
  const handoffId = stringAt(value, "handoff_id");
590
589
  const recipient = recordAt(value, "recipient");
591
- const generation = numberAt(recipient, "execution_generation");
592
590
  const received = numberAt(value, "received_at_unix_ms");
593
591
  if (
594
592
  version !== 1 || !isUuid(handoffId) || !isUuid(stringAt(recipient, "registration_id")) ||
595
593
  !isUuid(stringAt(recipient, "session_id")) || !isUuid(stringAt(recipient, "subject_id")) ||
596
- !isUuid(stringAt(recipient, "execution_id")) || !Number.isSafeInteger(generation) ||
597
- (generation ?? 0) < 1 || received === undefined || !Number.isSafeInteger(received) || received < 0
594
+ !isUuid(stringAt(recipient, "claim_id")) || received === undefined || !Number.isSafeInteger(received) || received < 0
598
595
  ) return undefined;
599
596
  return value as HandoffReceiptSerialize;
600
597
  }
@@ -1104,6 +1101,8 @@ export type RadarClient = {
1104
1101
  env?: Record<string, string>;
1105
1102
  managed?: RadarManagedLaunchMetadata;
1106
1103
  }): Promise<RadarResult<RadarSpawnEdge>>;
1104
+ /** List launches owned by this client's registered process. */
1105
+ spawnList(request: Pick<SpawnListParamsDeserialize, "after" | "limit">): Promise<RadarResult<SpawnListPageSerialize>>;
1107
1106
  spawnGet(request_id: string): Promise<RadarResult<RadarSpawnTopology>>;
1108
1107
  /** The registered child's process verdict, read from its immutable claim. */
1109
1108
  agentGet(registration_id: string): Promise<RadarResult<RadarAgentProcess>>;
@@ -1447,6 +1446,7 @@ export function createRadarClient(options: RadarClientOptions = {}): RadarClient
1447
1446
  };
1448
1447
  return answer;
1449
1448
  };
1449
+ let processRegistrationId: string | undefined;
1450
1450
  let handshake: Promise<RadarResult<RadarHandshake>> | undefined;
1451
1451
  const negotiated = async (): Promise<RadarResult<RadarHandshake>> => {
1452
1452
  handshake ??= probe();
@@ -1552,6 +1552,7 @@ export function createRadarClient(options: RadarClientOptions = {}): RadarClient
1552
1552
  const record = (answer.value as { registration?: unknown }).registration;
1553
1553
  const agentId = stringAt(record, "registration_id");
1554
1554
  if (!isUuid(agentId)) return protocol("registration reply carries no registration_id");
1555
+ processRegistrationId = agentId;
1555
1556
  return { ok: true, value: { registration_id: agentId } };
1556
1557
  });
1557
1558
  },
@@ -1705,6 +1706,32 @@ export function createRadarClient(options: RadarClientOptions = {}): RadarClient
1705
1706
  },
1706
1707
  );
1707
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
+ },
1708
1735
  async spawnGet(requestId) {
1709
1736
  if (!isUuid(requestId))
1710
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.1",
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"