@howaboua/pi-shepherdr 0.1.1 → 0.1.3

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/src/settlement.ts CHANGED
@@ -2,16 +2,23 @@ import type {
2
2
  ExtensionAPI,
3
3
  ExtensionContext,
4
4
  } from "@earendil-works/pi-coding-agent";
5
- import { activityTask, isSettledStatus } from "./activity.js";
5
+ import {
6
+ activityAttemptId,
7
+ activityExpectedUser,
8
+ activityTask,
9
+ isSettledStatus,
10
+ } from "./activity.js";
6
11
  import { getAgent, getSnapshot, sessionPath } from "./herdr.js";
7
- import type { HerdrClient } from "./herdr-client.js";
12
+ import type { HerdrConnection } from "./herdr-client.js";
8
13
  import { injectAgentEvent } from "./messages.js";
9
- import type { MonitorState } from "./monitor-state.js";
10
- import { SessionReader } from "./session-reader.js";
14
+ import type { MonitorState, WorkAttempt } from "./monitor-state.js";
15
+ import { type AssistantReader, SessionReader } from "./session-reader.js";
11
16
  import type {
12
17
  LatestAssistant,
13
18
  MonitoredAgent,
14
19
  PaneInfo,
20
+ PendingAsk,
21
+ SessionView,
15
22
  SettledAgentStatus,
16
23
  } from "./types.js";
17
24
 
@@ -20,13 +27,39 @@ interface SettlementLabels {
20
27
  workspace?: string;
21
28
  }
22
29
 
23
- export interface CollectedSettlement {
30
+ interface CollectedSettlement {
24
31
  agent: PaneInfo;
32
+ ask?: PendingAsk;
25
33
  labels: SettlementLabels;
26
34
  reply?: LatestAssistant;
27
35
  status: SettledAgentStatus;
28
36
  }
29
37
 
38
+ interface CollectedSettlementWithSession extends CollectedSettlement {
39
+ session: SessionView;
40
+ }
41
+
42
+ export interface ClaimedSettlement extends CollectedSettlement {
43
+ blockedMessage?: string;
44
+ record: MonitoredAgent;
45
+ }
46
+
47
+ interface SettlementClaim {
48
+ cleanup(): void;
49
+ reject(error: Error): void;
50
+ resolve(settlement: ClaimedSettlement): void;
51
+ }
52
+
53
+ interface SettlementRetry {
54
+ attemptId: string | undefined;
55
+ count: number;
56
+ }
57
+
58
+ const SETTLEMENT_RETRY_DELAYS_MS = [250, 500, 1_000, 2_000, 4_000] as const;
59
+ const SETTLEMENT_RETRY_WINDOW_SECONDS = Math.ceil(
60
+ SETTLEMENT_RETRY_DELAYS_MS.reduce((total, delay) => total + delay, 0) / 1_000,
61
+ );
62
+
30
63
  export interface SettlementRequest {
31
64
  blockedMessage?: string;
32
65
  record: MonitoredAgent;
@@ -42,24 +75,28 @@ export interface SettlementLifecycle {
42
75
  }
43
76
 
44
77
  export class SettlementCollector {
45
- private readonly client: HerdrClient;
46
- private readonly reader = new SessionReader();
78
+ private readonly client: HerdrConnection;
79
+ private readonly reader: AssistantReader;
47
80
 
48
- constructor(client: HerdrClient) {
81
+ constructor(
82
+ client: HerdrConnection,
83
+ reader: AssistantReader = new SessionReader(),
84
+ ) {
49
85
  this.client = client;
86
+ this.reader = reader;
50
87
  }
51
88
 
52
89
  latest(panel: PaneInfo): Promise<LatestAssistant | undefined> {
53
90
  return this.reader.latest(sessionPath(panel));
54
91
  }
55
92
 
93
+ view(panel: PaneInfo): Promise<SessionView> {
94
+ return this.reader.view(sessionPath(panel));
95
+ }
96
+
56
97
  async collect(
57
98
  record: MonitoredAgent,
58
- ): Promise<CollectedSettlement | undefined> {
59
- const agent = await getAgent(this.client, record.paneId);
60
- if (agent.terminal_id !== record.terminalId || agent.agent !== "pi") {
61
- return undefined;
62
- }
99
+ ): Promise<CollectedSettlementWithSession | undefined> {
63
100
  const [current, snapshot] = await Promise.all([
64
101
  getAgent(this.client, record.paneId),
65
102
  getSnapshot(this.client),
@@ -71,7 +108,7 @@ export class SettlementCollector {
71
108
  ) {
72
109
  return undefined;
73
110
  }
74
- const reply = await this.latest(current);
111
+ const view = await this.reader.view(sessionPath(current));
75
112
  const workspace = snapshot.workspaces.find(
76
113
  (candidate) => candidate.workspace_id === current.workspace_id,
77
114
  )?.label;
@@ -84,7 +121,11 @@ export class SettlementCollector {
84
121
  ...(workspace ? { workspace } : {}),
85
122
  ...(tab ? { tab } : {}),
86
123
  },
87
- ...(reply ? { reply } : {}),
124
+ ...(view.assistant ? { reply: view.assistant } : {}),
125
+ ...(current.agent_status === "blocked" && view.ask
126
+ ? { ask: view.ask }
127
+ : {}),
128
+ session: view,
88
129
  status: current.agent_status,
89
130
  };
90
131
  }
@@ -94,38 +135,104 @@ export class SettlementReporter {
94
135
  private readonly collector: SettlementCollector;
95
136
  private readonly persist: () => void;
96
137
  private readonly pi: ExtensionAPI;
138
+ private readonly machine: string;
139
+ private readonly operatorPrefix: string;
97
140
  private readonly reporting = new Set<string>();
141
+ private readonly claims = new Map<string, SettlementClaim>();
98
142
  private readonly retries = new Map<string, NodeJS.Timeout>();
99
143
  private readonly state: MonitorState;
100
144
 
101
145
  constructor(
102
146
  pi: ExtensionAPI,
103
- client: HerdrClient,
147
+ client: HerdrConnection,
104
148
  state: MonitorState,
105
149
  persist: () => void,
150
+ reader?: AssistantReader,
151
+ machine = "local",
152
+ operatorPrefix = "herdr",
106
153
  ) {
107
154
  this.pi = pi;
108
- this.collector = new SettlementCollector(client);
155
+ this.collector = new SettlementCollector(client, reader);
109
156
  this.state = state;
110
157
  this.persist = persist;
158
+ this.machine = machine;
159
+ this.operatorPrefix = operatorPrefix;
111
160
  }
112
161
 
113
162
  latest(panel: PaneInfo): Promise<LatestAssistant | undefined> {
114
163
  return this.collector.latest(panel);
115
164
  }
116
165
 
166
+ view(panel: PaneInfo): Promise<SessionView> {
167
+ return this.collector.view(panel);
168
+ }
169
+
117
170
  stop(): void {
118
171
  this.reporting.clear();
172
+ for (const claim of this.claims.values()) {
173
+ claim.cleanup();
174
+ claim.reject(new Error("Shepherdr monitor stopped"));
175
+ }
176
+ this.claims.clear();
119
177
  for (const timer of this.retries.values()) clearTimeout(timer);
120
178
  this.retries.clear();
121
179
  }
122
180
 
181
+ claim(attempt: WorkAttempt, signal: AbortSignal): Promise<ClaimedSettlement> {
182
+ signal.throwIfAborted();
183
+ if (this.claims.has(attempt.attemptId)) {
184
+ throw new Error(`work attempt ${attempt.attemptId} is already claimed`);
185
+ }
186
+ return new Promise<ClaimedSettlement>((resolve, reject) => {
187
+ const abort = () => {
188
+ const claim = this.claims.get(attempt.attemptId);
189
+ if (!claim) return;
190
+ this.claims.delete(attempt.attemptId);
191
+ claim.cleanup();
192
+ reject(
193
+ signal.reason instanceof Error
194
+ ? signal.reason
195
+ : new Error("Shepherdr wait aborted"),
196
+ );
197
+ };
198
+ const claim: SettlementClaim = {
199
+ cleanup: () => signal.removeEventListener("abort", abort),
200
+ reject,
201
+ resolve,
202
+ };
203
+ this.claims.set(attempt.attemptId, claim);
204
+ signal.addEventListener("abort", abort, { once: true });
205
+ });
206
+ }
207
+
208
+ releaseClaim(attempt: WorkAttempt | undefined, error: unknown): void {
209
+ if (!attempt) return;
210
+ this.releaseAttempt(attempt.attemptId, error);
211
+ }
212
+
213
+ releaseAgentClaim(record: MonitoredAgent, error: unknown): void {
214
+ const attemptId = activityAttemptId(record.activity);
215
+ if (attemptId) this.releaseAttempt(attemptId, error);
216
+ }
217
+
218
+ private releaseAttempt(attemptId: string, error: unknown): void {
219
+ const claim = this.claims.get(attemptId);
220
+ if (!claim) return;
221
+ this.claims.delete(attemptId);
222
+ claim.cleanup();
223
+ claim.reject(error instanceof Error ? error : new Error(String(error)));
224
+ }
225
+
123
226
  async report(
124
227
  lifecycle: SettlementLifecycle,
125
228
  request: SettlementRequest,
126
- retried = false,
229
+ retry?: SettlementRetry,
127
230
  ): Promise<void> {
128
231
  const task = request.task ?? activityTask(request.record.activity);
232
+ const retryState = retry ?? {
233
+ attemptId: activityAttemptId(request.record.activity),
234
+ count: 0,
235
+ };
129
236
  const key = `${lifecycle.generation}:${request.record.terminalId}`;
130
237
  if (this.reporting.has(key)) return;
131
238
  this.reporting.add(key);
@@ -134,22 +241,46 @@ export class SettlementReporter {
134
241
  if (!settlement || !lifecycle.isCurrent()) return;
135
242
  const current = this.state.byPane(settlement.agent.pane_id);
136
243
  if (!current || current.terminalId !== request.record.terminalId) return;
244
+ if (activityTask(current.activity) !== task) return;
245
+ if (activityAttemptId(current.activity) !== retryState.attemptId) return;
246
+ const retryRequest = task ? { ...request, task } : request;
247
+ const expectedUser = activityExpectedUser(current.activity);
248
+ if (
249
+ expectedUser &&
250
+ (settlement.session.assistantAfterUser !== true ||
251
+ !settlement.session.user ||
252
+ settlement.session.user.id === expectedUser.after ||
253
+ settlement.session.user.text !== expectedUser.text)
254
+ ) {
255
+ if (!this.retry(lifecycle, retryRequest, retryState)) {
256
+ this.failReconciliation(
257
+ lifecycle,
258
+ current,
259
+ "the submitted user message and reply were not persisted",
260
+ );
261
+ }
262
+ return;
263
+ }
137
264
  const newReply =
138
265
  settlement.reply?.id !== current.lastAssistantId
139
266
  ? settlement.reply
140
267
  : undefined;
141
- if (request.requireNewReply && !newReply) return;
142
- if (activityTask(current.activity) !== task) return;
143
- injectAgentEvent(this.pi, lifecycle.context, {
144
- agent: settlement.agent,
145
- ...(settlement.status === request.status && request.blockedMessage
146
- ? { blockedMessage: request.blockedMessage }
147
- : {}),
148
- labels: settlement.labels,
149
- record: current,
150
- ...(newReply ? { reply: newReply } : {}),
151
- status: settlement.status,
152
- });
268
+ if (request.requireNewReply && !newReply && !settlement.ask) {
269
+ if (!this.retry(lifecycle, retryRequest, retryState)) {
270
+ this.failReconciliation(
271
+ lifecycle,
272
+ current,
273
+ "the new assistant reply was not persisted",
274
+ );
275
+ }
276
+ return;
277
+ }
278
+ const blockedMessage =
279
+ settlement.status === request.status
280
+ ? request.blockedMessage
281
+ : undefined;
282
+ const attemptId = activityAttemptId(current.activity);
283
+ const claim = attemptId ? this.claims.get(attemptId) : undefined;
153
284
  if (
154
285
  this.state.complete(
155
286
  current.terminalId,
@@ -160,14 +291,57 @@ export class SettlementReporter {
160
291
  ) {
161
292
  this.clearRetry(current.terminalId);
162
293
  this.persist();
294
+ if (claim && attemptId) {
295
+ this.claims.delete(attemptId);
296
+ claim.cleanup();
297
+ const {
298
+ reply: _latestReply,
299
+ session: _session,
300
+ ...claimedSettlement
301
+ } = settlement;
302
+ claim.resolve({
303
+ ...claimedSettlement,
304
+ record: current,
305
+ ...(blockedMessage ? { blockedMessage } : {}),
306
+ ...(newReply ? { reply: newReply } : {}),
307
+ });
308
+ } else {
309
+ injectAgentEvent(this.pi, lifecycle.context, {
310
+ agent: settlement.agent,
311
+ agentToolName: "agents",
312
+ ...(settlement.ask ? { ask: settlement.ask } : {}),
313
+ machine: this.machine,
314
+ operatorPrefix: this.operatorPrefix,
315
+ ...(blockedMessage ? { blockedMessage } : {}),
316
+ labels: settlement.labels,
317
+ record: current,
318
+ ...(newReply ? { reply: newReply } : {}),
319
+ status: settlement.status,
320
+ });
321
+ }
163
322
  }
164
323
  } catch (error) {
165
- lifecycle.context.ui.notify(
166
- `Could not collect ${request.record.name ?? request.record.paneId}: ${error instanceof Error ? error.message : String(error)}`,
167
- "warning",
168
- );
169
- if (!retried) {
170
- this.retry(lifecycle, task ? { ...request, task } : request);
324
+ if (!lifecycle.isCurrent()) return;
325
+ if (retryState.count === 0) {
326
+ lifecycle.context.ui.notify(
327
+ `Could not collect ${request.record.name ?? request.record.paneId}: ${error instanceof Error ? error.message : String(error)}`,
328
+ "warning",
329
+ );
330
+ }
331
+ const retryRequest = task ? { ...request, task } : request;
332
+ if (!this.retry(lifecycle, retryRequest, retryState)) {
333
+ const current = this.state.byTerminal(request.record.terminalId);
334
+ if (
335
+ current &&
336
+ activityTask(current.activity) === task &&
337
+ activityAttemptId(current.activity) === retryState.attemptId
338
+ ) {
339
+ this.failReconciliation(
340
+ lifecycle,
341
+ current,
342
+ "the settlement snapshot remained unavailable",
343
+ );
344
+ }
171
345
  }
172
346
  } finally {
173
347
  this.reporting.delete(key);
@@ -183,22 +357,52 @@ export class SettlementReporter {
183
357
  private retry(
184
358
  lifecycle: SettlementLifecycle,
185
359
  request: SettlementRequest,
186
- ): void {
360
+ retry: SettlementRetry,
361
+ ): boolean {
362
+ const delay = SETTLEMENT_RETRY_DELAYS_MS[retry.count];
363
+ if (delay === undefined) return false;
364
+ const current = this.state.byTerminal(request.record.terminalId);
187
365
  if (
188
366
  !lifecycle.isCurrent() ||
189
- !this.state.byTerminal(request.record.terminalId) ||
190
- this.retries.has(request.record.terminalId)
367
+ !current ||
368
+ activityTask(current.activity) !==
369
+ (request.task ?? activityTask(request.record.activity)) ||
370
+ activityAttemptId(current.activity) !== retry.attemptId
191
371
  ) {
192
- return;
372
+ return false;
193
373
  }
374
+ if (this.retries.has(request.record.terminalId)) return true;
194
375
  const timer = setTimeout(() => {
195
376
  this.retries.delete(request.record.terminalId);
196
377
  if (!lifecycle.isCurrent()) return;
197
378
  const current = this.state.byTerminal(request.record.terminalId);
198
379
  if (!current) return;
199
- void this.report(lifecycle, { ...request, record: current }, true);
200
- }, 1_000);
380
+ void this.report(
381
+ lifecycle,
382
+ { ...request, record: current },
383
+ { ...retry, count: retry.count + 1 },
384
+ );
385
+ }, delay);
201
386
  this.retries.set(request.record.terminalId, timer);
202
387
  timer.unref();
388
+ return true;
389
+ }
390
+
391
+ private failReconciliation(
392
+ lifecycle: SettlementLifecycle,
393
+ record: MonitoredAgent,
394
+ reason: string,
395
+ ): void {
396
+ this.clearRetry(record.terminalId);
397
+ const message =
398
+ (record.name ?? record.paneId) +
399
+ " settled, but " +
400
+ reason +
401
+ " after " +
402
+ SETTLEMENT_RETRY_WINDOW_SECONDS +
403
+ " seconds";
404
+ const attemptId = activityAttemptId(record.activity);
405
+ if (attemptId) this.releaseAttempt(attemptId, new Error(message));
406
+ lifecycle.context.ui.notify(message, "warning");
203
407
  }
204
408
  }
package/src/types.ts CHANGED
@@ -4,12 +4,18 @@ export type SettledAgentStatus = Exclude<AgentStatus, "working">;
4
4
 
5
5
  export type StableAgentActivity =
6
6
  | { readonly phase: "settled"; readonly status: SettledAgentStatus }
7
- | { readonly phase: "working"; readonly task?: string };
7
+ | {
8
+ readonly attemptId?: string;
9
+ readonly expectedUserAfter?: string | null;
10
+ readonly phase: "working";
11
+ readonly task?: string;
12
+ };
8
13
 
9
14
  export type AgentActivity =
10
15
  | StableAgentActivity
11
16
  | {
12
17
  readonly attemptId: string;
18
+ readonly expectedUserAfter?: string | null;
13
19
  readonly phase: "submitting";
14
20
  readonly previous: StableAgentActivity;
15
21
  readonly task: string;
@@ -29,6 +35,7 @@ export interface PaneInfo {
29
35
  cwd?: string | null;
30
36
  foreground_cwd?: string | null;
31
37
  interactive_ready?: boolean;
38
+ label?: string | null;
32
39
  launch_pending?: boolean;
33
40
  name?: string | null;
34
41
  pane_id: string;
@@ -66,12 +73,46 @@ export interface MonitoredAgent {
66
73
  readonly workspaceId: string;
67
74
  }
68
75
 
76
+ type MachineConnectionStatus = "connected" | "connecting" | "unavailable";
77
+
78
+ export interface MachineStatus {
79
+ local: boolean;
80
+ name: string;
81
+ reason?: string;
82
+ status: MachineConnectionStatus;
83
+ }
84
+
85
+ export type ScopedMonitoredAgent = MonitoredAgent & { machine: string };
86
+
69
87
  export interface LatestAssistant {
70
88
  id: string;
71
89
  stopReason?: string;
72
90
  text: string;
73
91
  }
74
92
 
93
+ export interface LatestUser {
94
+ id: string;
95
+ text: string;
96
+ }
97
+
98
+ export interface PendingAsk {
99
+ handoff: boolean;
100
+ prompts: Array<{
101
+ body?: string;
102
+ choices: Array<{ description?: string; label: string }>;
103
+ multiple: boolean;
104
+ title: string;
105
+ }>;
106
+ toolCallId: string;
107
+ }
108
+
109
+ export interface SessionView {
110
+ ask?: PendingAsk;
111
+ assistant?: LatestAssistant;
112
+ assistantAfterUser?: boolean;
113
+ user?: LatestUser;
114
+ }
115
+
75
116
  export interface HerdrEvent {
76
117
  data: Record<string, unknown>;
77
118
  event: string;
package/src/widget.ts CHANGED
@@ -1,7 +1,11 @@
1
1
  import { basename } from "node:path";
2
2
  import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
3
3
  import { activityStatus } from "./activity.js";
4
- import type { AgentStatus, MonitoredAgent } from "./types.js";
4
+ import type {
5
+ AgentStatus,
6
+ MachineStatus,
7
+ ScopedMonitoredAgent,
8
+ } from "./types.js";
5
9
 
6
10
  const WIDGET_ID = "herdr-agents";
7
11
  const MAX_VISIBLE_AGENTS = 8;
@@ -24,24 +28,32 @@ function statusAppearance(status: AgentStatus): {
24
28
  }
25
29
  }
26
30
 
27
- function agentLine(ctx: ExtensionContext, agent: MonitoredAgent): string {
31
+ function agentLine(
32
+ ctx: ExtensionContext,
33
+ agent: ScopedMonitoredAgent,
34
+ machines: Map<string, MachineStatus>,
35
+ ): string {
28
36
  const theme = ctx.ui.theme;
29
37
  const status = activityStatus(agent.activity);
30
- const appearance = statusAppearance(status);
31
- const name = agent.name ?? agent.paneId;
38
+ const connected = machines.get(agent.machine)?.status === "connected";
39
+ const appearance = connected
40
+ ? statusAppearance(status)
41
+ : ({ icon: "?", tone: "error" } as const);
42
+ const name = `${agent.machine} / ${agent.name ?? agent.paneId}`;
32
43
  const location = agent.cwd ? basename(agent.cwd) : agent.paneId;
33
44
  return [
34
45
  theme.fg("muted", "│"),
35
46
  theme.fg(appearance.tone, appearance.icon),
36
47
  theme.fg("accent", name),
37
- theme.fg(appearance.tone, status),
48
+ theme.fg(appearance.tone, connected ? status : "offline"),
38
49
  theme.fg("dim", `· ${location}`),
39
50
  ].join(" ");
40
51
  }
41
52
 
42
53
  export function renderAgentWidget(
43
54
  ctx: ExtensionContext | undefined,
44
- agents: MonitoredAgent[],
55
+ agents: ScopedMonitoredAgent[],
56
+ machines: MachineStatus[],
45
57
  ): void {
46
58
  if (!ctx?.hasUI) return;
47
59
  if (agents.length === 0) {
@@ -55,11 +67,14 @@ export function renderAgentWidget(
55
67
  statusOrder(activityStatus(right.activity)) ||
56
68
  (left.name ?? left.paneId).localeCompare(right.name ?? right.paneId),
57
69
  );
70
+ const machinesByName = new Map(
71
+ machines.map((machine) => [machine.name, machine]),
72
+ );
58
73
  const lines = [
59
- `${theme.fg("accent", "╭─ herdr agents")} ${theme.fg("dim", String(agents.length))}`,
74
+ `${theme.fg("accent", "╭─ herdr agents")} ${theme.fg("dim", `${agents.length} · ${machines.filter((machine) => machine.status === "connected").length}/${machines.length} machines`)}`,
60
75
  ...ordered
61
76
  .slice(0, MAX_VISIBLE_AGENTS)
62
- .map((agent) => agentLine(ctx, agent)),
77
+ .map((agent) => agentLine(ctx, agent, machinesByName)),
63
78
  ];
64
79
  if (ordered.length > MAX_VISIBLE_AGENTS) {
65
80
  lines.push(
@@ -1,61 +0,0 @@
1
- import { randomUUID } from "node:crypto";
2
- import { mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
3
- import { join } from "node:path";
4
-
5
- function configPath(cwd: string): string {
6
- return join(cwd, ".pi", "shepherdr.json");
7
- }
8
-
9
- export async function isMasterDirectory(cwd: string): Promise<boolean> {
10
- const path = configPath(cwd);
11
- const value = await readConfig(path);
12
- if (!value || !("master" in value)) return false;
13
- if (typeof value["master"] === "boolean") return value["master"];
14
- throw new Error(`${path} master must be boolean`);
15
- }
16
-
17
- export async function enableMasterDirectory(cwd: string): Promise<string> {
18
- const directory = join(cwd, ".pi");
19
- const path = configPath(cwd);
20
- const value = (await readConfig(path)) ?? {};
21
- value["master"] = true;
22
- await mkdir(directory, { recursive: true });
23
- const temporaryPath = `${path}.${process.pid}.${randomUUID()}.tmp`;
24
- try {
25
- await writeFile(temporaryPath, `${JSON.stringify(value, null, 2)}\n`, {
26
- encoding: "utf8",
27
- mode: 0o600,
28
- });
29
- await rename(temporaryPath, path);
30
- } catch (error) {
31
- await unlink(temporaryPath).catch(() => undefined);
32
- throw error;
33
- }
34
- return path;
35
- }
36
-
37
- async function readConfig(
38
- path: string,
39
- ): Promise<Record<string, unknown> | undefined> {
40
- let text: string;
41
- try {
42
- text = await readFile(path, "utf8");
43
- } catch (error) {
44
- if ((error as NodeJS.ErrnoException).code === "ENOENT") return undefined;
45
- throw new Error(
46
- `could not read ${path}: ${error instanceof Error ? error.message : String(error)}`,
47
- );
48
- }
49
- let value: unknown;
50
- try {
51
- value = JSON.parse(text);
52
- } catch (error) {
53
- throw new Error(
54
- `could not parse ${path}: ${error instanceof Error ? error.message : String(error)}`,
55
- );
56
- }
57
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
58
- throw new Error(`${path} must contain a JSON object`);
59
- }
60
- return value as Record<string, unknown>;
61
- }