@dougbots/avenor-core 0.16.0 → 0.16.1

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/dist/index.d.ts CHANGED
@@ -248,6 +248,18 @@ declare class RpcError extends Error {
248
248
  readonly data?: unknown;
249
249
  constructor(code: number, message: string, data?: unknown);
250
250
  }
251
+ /**
252
+ * A transport failure that marks the control client closed: a send refused
253
+ * because the socket is already closed, a pending call rejected because the
254
+ * read side closed, or a socket write failure. A peer's structured rejection
255
+ * (RpcError) or a call timeout do not close the client and are not classified
256
+ * here.
257
+ */
258
+ declare class ClosedSocketError extends Error {
259
+ constructor(message: string);
260
+ }
261
+ /** True when the error is a transport failure that closed the client. */
262
+ declare function isClosedSocketError(error: unknown): boolean;
251
263
  type OwnerAuthFailureKind = 'unauthenticated' | 'unsupported' | 'timeout';
252
264
  /** A classified owner-authentication rejection, not generic transport failure. */
253
265
  declare class OwnerAuthError extends Error {
@@ -1130,6 +1142,7 @@ interface PendingAsk {
1130
1142
  from_run_id: string;
1131
1143
  message_id: string;
1132
1144
  }
1145
+ declare const SUPERVISOR_RUN_ID = "supervisor";
1133
1146
  /** The broker rejected a receive because the caller's generation is stale. */
1134
1147
  declare function isGenerationMismatchError(error: unknown): boolean;
1135
1148
  interface HostProviderOptions {
@@ -1305,4 +1318,4 @@ type WorkflowCancelResult = Record<string, unknown>;
1305
1318
  declare function createWorkflowCancelTool(getSupervisorClient: GetSupervisorClient): (args: WorkflowCancelArgs) => Promise<WorkflowCancelResult>;
1306
1319
  declare const workflowCancelTool: (args: WorkflowCancelArgs) => Promise<WorkflowCancelResult>;
1307
1320
  //#endregion
1308
- export { type AskClaims, type BrokerReceiveArgs, type BrokerReceiveResult, type ChildBroker, type Client, DEFAULT_RUN_REDUCER_LIMITS, type Event, type ExecutionIdentity, ForeignPeerError, type HistoryOptions, type HistoryResult, type InboundAsk, type InspectResult, type KillResult, type KillToolArgs, MAX_FINAL_OUTPUT_RUNES, MAX_WAIT_MS, MESSAGE_OUTCOMES, type MessageCallerKind, type MessageClient, type MessageInput, type MessageOutcome, type MessageProvider, type MessageSurface, type NormalizedRunEvent, type ObserveRunOptions, type OwnerAttachOptions, OwnerAuthError, OwnerRecordMissingError, type PeerRecord, type PeersInput, type PeersProviderResult, type PeersResult, type PeersRouterResult, type PeersToolArgs, type PendingAsk, type ProviderResult, type Resolution, type ResultResult, type ResultToolArgs, RpcError, type RunChunkRole, type RunFacts, type RunIdentity, type RunInfo, type RunObserver, type RunObserverClient, type RunPermissionOption, type RunPermissionSummary, RunReducer, type RunReducerLimits, type RunSnapshot, type RunSnapshotSeed, type RunToolState, type RunToolSummary, type RunTranscriptEntry, type SpawnMetadata, type SpawnParams, type SpawnResult, type SpawnSelectionInput, type SpawnToolArgs, type SpawnToolResult, StaleOwnerRecordError, type StatusListResult, type StatusResult, type StatusToolArgs, type StatusView, type SubscribeOptions, Supervisor, type SupervisorClientOptions, type SupervisorOptions, THINKING_LEVELS, type ThinkingLevel, type ThinkingOutcome, ToolError, type WorkflowCancelArgs, type WorkflowCancelResult, type WorkflowCompleteParams, type WorkflowCompleteResult, type WorkflowCompleteToolArgs, type WorkflowControllerCreateParams, type WorkflowControllerStatusResult, type WorkflowControllerStatusToolArgs, type WorkflowEventsResult, type WorkflowEventsToolArgs, type WorkflowGateOperation, type WorkflowGateParams, type WorkflowGateResult, type WorkflowGateToolArgs, type WorkflowHeartbeatParams, type WorkflowInspectResult, type WorkflowInspectToolArgs, type WorkflowReadyResult, type WorkflowReadyToolArgs, type WorkflowStatusResult, type WorkflowStatusToolArgs, type WorkflowWaitResult, type WorkflowWaitToolArgs, answerPermissionTool, assertMessageInput, assertPeersInput, attachOwner, boundFinalOutput, brokerReceiveTool, createChildMessageProvider, createHostMessageProvider, createMessageTool, createPeersTool, createRunSnapshot, createWorkflowCancelTool, createWorkflowCompleteTool, createWorkflowControllerStatusTool, createWorkflowEventsTool, createWorkflowGateTool, createWorkflowInspectTool, createWorkflowReadyTool, createWorkflowStatusTool, createWorkflowWaitTool, dial, evaluateThinkingPolicy, eventsTool, executeMessage, executePeers, extractEventText, extractReplyMessage, extractTurnText, findAvenorBinary, getInstallDir, getSupervisorClient, getVersion, inspectTool, installAskClaims, installerBinaryPath, isGenerationMismatchError, isThinkingLevel, killTool, messageTool, newMsgID, normalizeAskTimeoutMs, normalizeRunEvent, normalizeTurnStopReason, observeRun, peersDetails, peersTool, quote, quoteList, reduceRunSnapshot, renderAskFailure, renderLast, renderOutcome, renderPeerList, repair, resultOutput, resultTool, sanitize, shutdownTool, socketsRoot, spawnTool, statusTool, validateSpawnSelection, validateThinking, validateThinkingForBackend, validateThinkingForBackendResume, workflowCancelTool, workflowCompleteTool, workflowControllerStatusTool, workflowEventsTool, workflowGateTool, workflowInspectTool, workflowReadyTool, workflowStatusTool, workflowWaitTool };
1321
+ export { type AskClaims, type BrokerReceiveArgs, type BrokerReceiveResult, type ChildBroker, type Client, ClosedSocketError, DEFAULT_RUN_REDUCER_LIMITS, type Event, type ExecutionIdentity, ForeignPeerError, type HistoryOptions, type HistoryResult, type InboundAsk, type InspectResult, type KillResult, type KillToolArgs, MAX_FINAL_OUTPUT_RUNES, MAX_WAIT_MS, MESSAGE_OUTCOMES, type MessageCallerKind, type MessageClient, type MessageInput, type MessageOutcome, type MessageProvider, type MessageSurface, type NormalizedRunEvent, type ObserveRunOptions, type OwnerAttachOptions, OwnerAuthError, OwnerRecordMissingError, type PeerRecord, type PeersInput, type PeersProviderResult, type PeersResult, type PeersRouterResult, type PeersToolArgs, type PendingAsk, type ProviderResult, type Resolution, type ResultResult, type ResultToolArgs, RpcError, type RunChunkRole, type RunFacts, type RunIdentity, type RunInfo, type RunObserver, type RunObserverClient, type RunPermissionOption, type RunPermissionSummary, RunReducer, type RunReducerLimits, type RunSnapshot, type RunSnapshotSeed, type RunToolState, type RunToolSummary, type RunTranscriptEntry, SUPERVISOR_RUN_ID, type SpawnMetadata, type SpawnParams, type SpawnResult, type SpawnSelectionInput, type SpawnToolArgs, type SpawnToolResult, StaleOwnerRecordError, type StatusListResult, type StatusResult, type StatusToolArgs, type StatusView, type SubscribeOptions, Supervisor, type SupervisorClientOptions, type SupervisorOptions, THINKING_LEVELS, type ThinkingLevel, type ThinkingOutcome, ToolError, type WorkflowCancelArgs, type WorkflowCancelResult, type WorkflowCompleteParams, type WorkflowCompleteResult, type WorkflowCompleteToolArgs, type WorkflowControllerCreateParams, type WorkflowControllerStatusResult, type WorkflowControllerStatusToolArgs, type WorkflowEventsResult, type WorkflowEventsToolArgs, type WorkflowGateOperation, type WorkflowGateParams, type WorkflowGateResult, type WorkflowGateToolArgs, type WorkflowHeartbeatParams, type WorkflowInspectResult, type WorkflowInspectToolArgs, type WorkflowReadyResult, type WorkflowReadyToolArgs, type WorkflowStatusResult, type WorkflowStatusToolArgs, type WorkflowWaitResult, type WorkflowWaitToolArgs, answerPermissionTool, assertMessageInput, assertPeersInput, attachOwner, boundFinalOutput, brokerReceiveTool, createChildMessageProvider, createHostMessageProvider, createMessageTool, createPeersTool, createRunSnapshot, createWorkflowCancelTool, createWorkflowCompleteTool, createWorkflowControllerStatusTool, createWorkflowEventsTool, createWorkflowGateTool, createWorkflowInspectTool, createWorkflowReadyTool, createWorkflowStatusTool, createWorkflowWaitTool, dial, evaluateThinkingPolicy, eventsTool, executeMessage, executePeers, extractEventText, extractReplyMessage, extractTurnText, findAvenorBinary, getInstallDir, getSupervisorClient, getVersion, inspectTool, installAskClaims, installerBinaryPath, isClosedSocketError, isGenerationMismatchError, isThinkingLevel, killTool, messageTool, newMsgID, normalizeAskTimeoutMs, normalizeRunEvent, normalizeTurnStopReason, observeRun, peersDetails, peersTool, quote, quoteList, reduceRunSnapshot, renderAskFailure, renderLast, renderOutcome, renderPeerList, repair, resultOutput, resultTool, sanitize, shutdownTool, socketsRoot, spawnTool, statusTool, validateSpawnSelection, validateThinking, validateThinkingForBackend, validateThinkingForBackendResume, workflowCancelTool, workflowCompleteTool, workflowControllerStatusTool, workflowEventsTool, workflowGateTool, workflowInspectTool, workflowReadyTool, workflowStatusTool, workflowWaitTool };
package/dist/index.js CHANGED
@@ -49,6 +49,23 @@ var CallTimeoutError = class extends Error {
49
49
  this.name = "CallTimeoutError";
50
50
  }
51
51
  };
52
+ /**
53
+ * A transport failure that marks the control client closed: a send refused
54
+ * because the socket is already closed, a pending call rejected because the
55
+ * read side closed, or a socket write failure. A peer's structured rejection
56
+ * (RpcError) or a call timeout do not close the client and are not classified
57
+ * here.
58
+ */
59
+ var ClosedSocketError = class extends Error {
60
+ constructor(message) {
61
+ super(message);
62
+ this.name = "ClosedSocketError";
63
+ }
64
+ };
65
+ /** True when the error is a transport failure that closed the client. */
66
+ function isClosedSocketError(error) {
67
+ return error instanceof ClosedSocketError;
68
+ }
52
69
  const OWNER_AUTH_VERSION = 1;
53
70
  const OWNER_UNAUTHENTICATED_CODE = -32011;
54
71
  const UNSUPPORTED_OWNER_AUTH_CODE = -32012;
@@ -169,7 +186,7 @@ var Client = class {
169
186
  this.closed = true;
170
187
  for (const [, pc] of this.pending) {
171
188
  clearTimeout(pc.timer);
172
- pc.reject(/* @__PURE__ */ new Error("read response: connection closed"));
189
+ pc.reject(new ClosedSocketError("read response: connection closed"));
173
190
  }
174
191
  this.pending.clear();
175
192
  this.eventDone = true;
@@ -232,7 +249,7 @@ var Client = class {
232
249
  if (!value || value.authenticated !== true || value.version !== OWNER_AUTH_VERSION || value.capability_id !== capability.id) throw new OwnerAuthError("unsupported", { reason: "unexpected-result" });
233
250
  }
234
251
  sendCall(method, params, timeout) {
235
- if (this.isClosed()) return Promise.reject(/* @__PURE__ */ new Error("control socket is closed"));
252
+ if (this.isClosed()) return Promise.reject(new ClosedSocketError("control socket is closed"));
236
253
  this.startReadLoop();
237
254
  const id = ++this.nextID;
238
255
  const req = {
@@ -257,7 +274,7 @@ var Client = class {
257
274
  this.closed = true;
258
275
  clearTimeout(timer);
259
276
  this.pending.delete(id);
260
- reject(/* @__PURE__ */ new Error(`write request: ${err.message}`));
277
+ reject(new ClosedSocketError(`write request: ${err.message}`));
261
278
  }
262
279
  });
263
280
  });
@@ -1712,6 +1729,13 @@ function avenorHome() {
1712
1729
  function socketsRoot() {
1713
1730
  return path.join(avenorHome(), "sockets");
1714
1731
  }
1732
+ function validateSupervisorSocketPath(supervisorId) {
1733
+ const root = fs.realpathSync(socketsRoot());
1734
+ const parent = fs.realpathSync(path.dirname(supervisorId));
1735
+ const basename = path.basename(supervisorId);
1736
+ if (parent !== root || !/^avenor-mcp-[^/\\]+\.sock$/.test(basename)) throw new Error(`invalid supervisorId: ${supervisorId}`);
1737
+ return path.join(parent, basename);
1738
+ }
1715
1739
  function runsRoot() {
1716
1740
  return path.join(avenorHome(), "runs");
1717
1741
  }
@@ -1932,7 +1956,7 @@ var Supervisor = class Supervisor {
1932
1956
  recursive: true,
1933
1957
  mode: 448
1934
1958
  });
1935
- const socketPath = path.join(socketDir, `avenor-mcp-${process.pid}.sock`);
1959
+ const socketPath = path.join(fs.realpathSync(socketDir), `avenor-mcp-${process.pid}.sock`);
1936
1960
  let socketExists = false;
1937
1961
  try {
1938
1962
  await fs.promises.access(socketPath, fs.constants.R_OK | fs.constants.W_OK);
@@ -2136,7 +2160,13 @@ var Supervisor = class Supervisor {
2136
2160
  * isCurrentInstance true while currentInstance is null.
2137
2161
  */
2138
2162
  static getInstance(supervisorId) {
2139
- return Supervisor.instance !== null && Supervisor.instance.supervisorId === supervisorId ? Supervisor.instance : null;
2163
+ if (Supervisor.instance === null) return null;
2164
+ if (Supervisor.instance.supervisorId === supervisorId) return Supervisor.instance;
2165
+ try {
2166
+ return Supervisor.instance.supervisorId === validateSupervisorSocketPath(supervisorId) ? Supervisor.instance : null;
2167
+ } catch {
2168
+ return null;
2169
+ }
2140
2170
  }
2141
2171
  static isCurrentInstance(supervisorId) {
2142
2172
  return Supervisor.getInstance(supervisorId) !== null;
@@ -2276,13 +2306,6 @@ function validateTimeout(value) {
2276
2306
  if (unit === "h") return amount * 3600;
2277
2307
  return amount;
2278
2308
  }
2279
- function validateSupervisorSocketPath(supervisorId) {
2280
- const root = fs.realpathSync(socketsRoot());
2281
- const parent = fs.realpathSync(path.dirname(supervisorId));
2282
- const basename = path.basename(supervisorId);
2283
- if (parent !== root || !/^avenor-mcp-[^/\\]+\.sock$/.test(basename)) throw new Error(`invalid supervisorId: ${supervisorId}`);
2284
- return path.join(parent, basename);
2285
- }
2286
2309
  function validateObservedAt(observedAt) {
2287
2310
  if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/.test(observedAt)) throw new Error("observed_at must be an RFC3339 timestamp");
2288
2311
  }
@@ -9498,7 +9521,7 @@ function createHostMessageProvider(options) {
9498
9521
  runId: "",
9499
9522
  match: "none"
9500
9523
  };
9501
- if (ref === SUPERVISOR_RUN_ID) return {
9524
+ if (ref === "supervisor") return {
9502
9525
  runId: SUPERVISOR_RUN_ID,
9503
9526
  label: SUPERVISOR_RUN_ID,
9504
9527
  match: "unique"
@@ -9536,8 +9559,8 @@ function createHostMessageProvider(options) {
9536
9559
  };
9537
9560
  },
9538
9561
  async state(runId) {
9539
- if (runId === SUPERVISOR_RUN_ID) {
9540
- const translation = translateRunFacts((await listedPeers()).find((entry) => entry.run_id === SUPERVISOR_RUN_ID)?.status ?? "", "");
9562
+ if (runId === "supervisor") {
9563
+ const translation = translateRunFacts((await listedPeers()).find((entry) => entry.run_id === "supervisor")?.status ?? "", "");
9541
9564
  return {
9542
9565
  live: translation.live,
9543
9566
  resumable: false,
@@ -10107,4 +10130,4 @@ function createWorkflowCancelTool(getSupervisorClient) {
10107
10130
  }
10108
10131
  const workflowCancelTool = createWorkflowCancelTool(getSupervisorClient);
10109
10132
  //#endregion
10110
- export { DEFAULT_RUN_REDUCER_LIMITS, ForeignPeerError, MAX_FINAL_OUTPUT_RUNES, MAX_WAIT_MS, MESSAGE_OUTCOMES, OwnerAuthError, OwnerRecordMissingError, RpcError, RunReducer, StaleOwnerRecordError, Supervisor, THINKING_LEVELS, ToolError, answerPermissionTool, assertMessageInput, assertPeersInput, attachOwner, boundFinalOutput, brokerReceiveTool, createChildMessageProvider, createHostMessageProvider, createMessageTool, createPeersTool, createRunSnapshot, createWorkflowCancelTool, createWorkflowCompleteTool, createWorkflowControllerStatusTool, createWorkflowEventsTool, createWorkflowGateTool, createWorkflowInspectTool, createWorkflowReadyTool, createWorkflowStatusTool, createWorkflowWaitTool, dial, evaluateThinkingPolicy, eventsTool, executeMessage, executePeers, extractEventText, extractReplyMessage, extractTurnText, findAvenorBinary, getInstallDir, getSupervisorClient, getVersion, inspectTool, installAskClaims, installerBinaryPath, isGenerationMismatchError, isThinkingLevel, killTool, messageTool, newMsgID, normalizeAskTimeoutMs, normalizeRunEvent, normalizeTurnStopReason, observeRun, peersDetails, peersTool, quote, quoteList, reduceRunSnapshot, renderAskFailure, renderLast, renderOutcome, renderPeerList, repair, resultOutput, resultTool, sanitize, shutdownTool, socketsRoot, spawnTool, statusTool, validateSpawnSelection, validateThinking, validateThinkingForBackend, validateThinkingForBackendResume, workflowCancelTool, workflowCompleteTool, workflowControllerStatusTool, workflowEventsTool, workflowGateTool, workflowInspectTool, workflowReadyTool, workflowStatusTool, workflowWaitTool };
10133
+ export { ClosedSocketError, DEFAULT_RUN_REDUCER_LIMITS, ForeignPeerError, MAX_FINAL_OUTPUT_RUNES, MAX_WAIT_MS, MESSAGE_OUTCOMES, OwnerAuthError, OwnerRecordMissingError, RpcError, RunReducer, SUPERVISOR_RUN_ID, StaleOwnerRecordError, Supervisor, THINKING_LEVELS, ToolError, answerPermissionTool, assertMessageInput, assertPeersInput, attachOwner, boundFinalOutput, brokerReceiveTool, createChildMessageProvider, createHostMessageProvider, createMessageTool, createPeersTool, createRunSnapshot, createWorkflowCancelTool, createWorkflowCompleteTool, createWorkflowControllerStatusTool, createWorkflowEventsTool, createWorkflowGateTool, createWorkflowInspectTool, createWorkflowReadyTool, createWorkflowStatusTool, createWorkflowWaitTool, dial, evaluateThinkingPolicy, eventsTool, executeMessage, executePeers, extractEventText, extractReplyMessage, extractTurnText, findAvenorBinary, getInstallDir, getSupervisorClient, getVersion, inspectTool, installAskClaims, installerBinaryPath, isClosedSocketError, isGenerationMismatchError, isThinkingLevel, killTool, messageTool, newMsgID, normalizeAskTimeoutMs, normalizeRunEvent, normalizeTurnStopReason, observeRun, peersDetails, peersTool, quote, quoteList, reduceRunSnapshot, renderAskFailure, renderLast, renderOutcome, renderPeerList, repair, resultOutput, resultTool, sanitize, shutdownTool, socketsRoot, spawnTool, statusTool, validateSpawnSelection, validateThinking, validateThinkingForBackend, validateThinkingForBackendResume, workflowCancelTool, workflowCompleteTool, workflowControllerStatusTool, workflowEventsTool, workflowGateTool, workflowInspectTool, workflowReadyTool, workflowStatusTool, workflowWaitTool };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dougbots/avenor-core",
3
- "version": "0.16.0",
3
+ "version": "0.16.1",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",