@botbotgo/agent-harness 0.0.258 → 0.0.260

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/api.js CHANGED
@@ -6,6 +6,7 @@ import { serveAcpOverHttp } from "./protocol/acp/http.js";
6
6
  import { serveAcpOverStdio } from "./protocol/acp/stdio.js";
7
7
  import { normalizeMessageContent } from "./utils/message-content.js";
8
8
  import { loadWorkspace } from "./workspace/compile.js";
9
+ import { traceStartupStage } from "./runtime/startup-tracing.js";
9
10
  export { AgentHarnessAcpServer, createAcpServer } from "./acp.js";
10
11
  export { createAcpStdioClient } from "./protocol/acp/client.js";
11
12
  export { AgentHarnessRuntime } from "./runtime/harness.js";
@@ -173,9 +174,15 @@ function toPublicRequestSummary(run) {
173
174
  };
174
175
  }
175
176
  export async function createAgentHarness(workspaceRoot = process.cwd(), options = {}) {
176
- const workspace = await loadWorkspace(workspaceRoot, options.load ?? {});
177
- const harness = new AgentHarnessRuntime(workspace, options.adapter ?? {});
178
- await harness.initialize();
177
+ const workspace = await traceStartupStage("createAgentHarness.loadWorkspace", () => loadWorkspace(workspaceRoot, options.load ?? {}), {
178
+ workspaceRoot,
179
+ });
180
+ const harness = await traceStartupStage("createAgentHarness.constructRuntime", async () => new AgentHarnessRuntime(workspace, options.adapter ?? {}), {
181
+ workspaceRoot,
182
+ });
183
+ await traceStartupStage("createAgentHarness.initializeRuntime", () => harness.initialize(), {
184
+ workspaceRoot,
185
+ });
179
186
  return harness;
180
187
  }
181
188
  export function normalizeUserChatInput(input, options = {}) {
@@ -1 +1 @@
1
- export declare const AGENT_HARNESS_VERSION = "0.0.257";
1
+ export declare const AGENT_HARNESS_VERSION = "0.0.259";
@@ -1 +1 @@
1
- export const AGENT_HARNESS_VERSION = "0.0.257";
1
+ export const AGENT_HARNESS_VERSION = "0.0.259";
@@ -1,7 +1,10 @@
1
1
  import { recoverQueuedStartupRun, recoverResumingStartupRun, recoverRunningStartupRun, } from "./recovery.js";
2
+ import { traceStartupStage } from "../../startup-tracing.js";
2
3
  export async function initializeHarnessRuntime(input) {
3
- await input.persistence.initialize();
4
- await input.healthMonitor?.start();
4
+ await traceStartupStage("runtime.initialize.persistence", () => input.persistence.initialize());
5
+ if (input.healthMonitor) {
6
+ await traceStartupStage("runtime.initialize.healthMonitor", () => input.healthMonitor.start());
7
+ }
5
8
  }
6
9
  export async function recoverStartupRuns(input) {
7
10
  if (!input.recoveryConfig.enabled) {
@@ -24,6 +24,14 @@ const DEFAULT_HEALTH_CONFIG = {
24
24
  },
25
25
  },
26
26
  };
27
+ const ACTIVE_RUN_STATES = [
28
+ "queued",
29
+ "claimed",
30
+ "running",
31
+ "waiting_for_approval",
32
+ "resuming",
33
+ "cancelling",
34
+ ];
27
35
  function asObject(value) {
28
36
  return typeof value === "object" && value !== null && !Array.isArray(value) ? value : undefined;
29
37
  }
@@ -146,10 +154,10 @@ export class HealthMonitor {
146
154
  async evaluate(nowMs = Date.now()) {
147
155
  const updatedAt = new Date(nowMs).toISOString();
148
156
  const [runs, approvals] = await Promise.all([
149
- this.options.persistence.listRuns(),
150
- this.options.persistence.listApprovals(),
157
+ Promise.all(ACTIVE_RUN_STATES.map((state) => this.options.persistence.listRuns({ state }))).then((groups) => groups.flat()),
158
+ this.options.persistence.listApprovals({ status: "pending" }),
151
159
  ]);
152
- const pendingApprovals = approvals.filter((approval) => approval.status === "pending").length;
160
+ const pendingApprovals = approvals.length;
153
161
  const stuckRuns = this.countStuckRuns(runs, nowMs);
154
162
  const llmCheck = this.evaluateLlmCheck(updatedAt, nowMs);
155
163
  const workloadCheck = this.evaluateWorkloadCheck(updatedAt, pendingApprovals, stuckRuns);
@@ -38,10 +38,19 @@ import { consolidateStructuredMemoryScope } from "./harness/system/runtime-memor
38
38
  import { normalizeLangMemMemoryKind, readRuntimeMemoryMaintenanceConfig, readRuntimeMemoryPolicyConfig, resolveMemoryNamespace, scoreMemoryText, } from "./harness/system/runtime-memory-policy.js";
39
39
  import { resolveRuntimeAdapterOptions } from "./support/runtime-adapter-options.js";
40
40
  import { initializeHarnessRuntime, reclaimExpiredClaimedRuns as reclaimHarnessExpiredClaimedRuns, recoverStartupRuns as recoverHarnessStartupRuns, isStaleRunningRun as isHarnessStaleRunningRun, } from "./harness/run/startup-runtime.js";
41
+ import { traceStartupStage } from "./startup-tracing.js";
41
42
  import { normalizeProcessExecutablePath } from "./support/runtime-env.js";
42
43
  import { streamHarnessRun } from "./harness/run/stream-run.js";
43
44
  import { defaultRequestedAgentId, prepareRunStart } from "./harness/run/start-run.js";
44
45
  import { buildRequestInspectionRecord, buildSessionInspectionRecord, deleteSessionRecord, deleteThreadRecord, getPublicApproval, listPublicApprovals, } from "./harness/run/thread-records.js";
46
+ const ACTIVE_RUN_STATES = [
47
+ "queued",
48
+ "claimed",
49
+ "running",
50
+ "waiting_for_approval",
51
+ "resuming",
52
+ "cancelling",
53
+ ];
45
54
  function normalizeSessionListText(content, limit) {
46
55
  if (!content) {
47
56
  return undefined;
@@ -324,7 +333,7 @@ export class AgentHarnessRuntime {
324
333
  persistence: this.persistence,
325
334
  healthMonitor: this.healthMonitor,
326
335
  });
327
- await this.recoverStartupRuns();
336
+ await traceStartupStage("runtime.initialize.startupRecovery", () => this.recoverStartupRuns());
328
337
  this.initialized = true;
329
338
  }
330
339
  subscribe(listener) {
@@ -339,8 +348,8 @@ export class AgentHarnessRuntime {
339
348
  async getOperatorOverview(options) {
340
349
  const [health, runs, approvals] = await Promise.all([
341
350
  this.getHealth(),
342
- this.listRuns(),
343
- this.listApprovals(),
351
+ Promise.all(ACTIVE_RUN_STATES.map((state) => this.listRuns({ state }))).then((groups) => groups.flat()),
352
+ this.listApprovals({ status: "pending" }),
344
353
  ]);
345
354
  return projectOperatorOverview({
346
355
  health,
@@ -0,0 +1 @@
1
+ export declare function traceStartupStage<T>(stage: string, operation: () => Promise<T>, detail?: Record<string, unknown>): Promise<T>;
@@ -0,0 +1,37 @@
1
+ function startupTimingEnabled() {
2
+ return process.env.AGENT_HARNESS_STARTUP_TIMING === "1";
3
+ }
4
+ function formatDurationMs(startedAt) {
5
+ return (Date.now() - startedAt).toString();
6
+ }
7
+ function writeStartupTrace(stage, phase, durationMs, detail) {
8
+ if (!startupTimingEnabled()) {
9
+ return;
10
+ }
11
+ const fields = [
12
+ "[agent-harness.startup]",
13
+ `stage=${stage}`,
14
+ `phase=${phase}`,
15
+ ...(durationMs ? [`durationMs=${durationMs}`] : []),
16
+ ...Object.entries(detail ?? {})
17
+ .filter(([, value]) => value !== undefined && value !== null && `${value}`.length > 0)
18
+ .map(([key, value]) => `${key}=${JSON.stringify(value)}`),
19
+ ];
20
+ process.stderr.write(`${fields.join(" ")}\n`);
21
+ }
22
+ export async function traceStartupStage(stage, operation, detail) {
23
+ const startedAt = Date.now();
24
+ writeStartupTrace(stage, "start", undefined, detail);
25
+ try {
26
+ const result = await operation();
27
+ writeStartupTrace(stage, "success", formatDurationMs(startedAt), detail);
28
+ return result;
29
+ }
30
+ catch (error) {
31
+ writeStartupTrace(stage, "failure", formatDurationMs(startedAt), {
32
+ ...detail,
33
+ error: error instanceof Error ? error.message : String(error),
34
+ });
35
+ throw error;
36
+ }
37
+ }
@@ -12,6 +12,7 @@ import { discoverSubagents, ensureDiscoverySources } from "./support/discovery.j
12
12
  import { collectAgentDiscoverySourceRefs, collectToolSourceRefs } from "./support/source-collectors.js";
13
13
  import { getRoutingDefaultAgentId, getRuntimeResources, getRoutingRules, resolveRefId, } from "./support/workspace-ref-utils.js";
14
14
  import { hydrateAgentMcpTools, hydrateResourceAndExternalTools } from "./tool-hydration.js";
15
+ import { traceStartupStage } from "../runtime/startup-tracing.js";
15
16
  function collectParsedResources(refs) {
16
17
  const embeddings = new Map();
17
18
  const mcpServers = new Map();
@@ -204,22 +205,38 @@ function resolveAgentSkillNames(agents, skillRegistry, skillCollectionRoots) {
204
205
  }
205
206
  }
206
207
  export async function loadWorkspace(workspaceRoot, options = {}) {
207
- const loaded = await loadWorkspaceObjects(workspaceRoot, options);
208
- loaded.agents = await discoverSubagents(loaded.agents, workspaceRoot);
208
+ const loaded = await traceStartupStage("workspace.load.objects", () => loadWorkspaceObjects(workspaceRoot, options), {
209
+ workspaceRoot,
210
+ });
211
+ loaded.agents = await traceStartupStage("workspace.discover.subagents", () => discoverSubagents(loaded.agents, workspaceRoot), {
212
+ workspaceRoot,
213
+ });
209
214
  const discoverySourceRefs = collectAgentDiscoverySourceRefs(loaded.agents);
210
- await ensureDiscoverySources(discoverySourceRefs, workspaceRoot);
215
+ await traceStartupStage("workspace.ensure.discoverySources", () => ensureDiscoverySources(discoverySourceRefs, workspaceRoot), {
216
+ workspaceRoot,
217
+ sourceCount: discoverySourceRefs.length,
218
+ });
211
219
  for (const agent of loaded.agents) {
212
220
  loaded.refs.set(`agent/${agent.id}`, agent);
213
221
  }
214
222
  const { embeddings, mcpServers, models, vectorStores, tools } = collectParsedResources(loaded.refs);
215
- await hydrateAgentMcpTools(loaded.agents, mcpServers, tools);
223
+ await traceStartupStage("workspace.hydrate.agentMcpTools", () => hydrateAgentMcpTools(loaded.agents, mcpServers, tools), {
224
+ workspaceRoot,
225
+ agentCount: loaded.agents.length,
226
+ });
216
227
  const configuredResources = Array.from(new Set([
217
228
  ...getRuntimeResources(loaded.refs),
218
229
  ...(options.resources ?? []),
219
230
  ]));
220
- const resolvedConfiguredResources = await resolveConfiguredResources(configuredResources, workspaceRoot);
231
+ const resolvedConfiguredResources = await traceStartupStage("workspace.resolve.configuredResources", () => resolveConfiguredResources(configuredResources, workspaceRoot), {
232
+ workspaceRoot,
233
+ configuredResourceCount: configuredResources.length,
234
+ });
221
235
  for (const resource of resolvedConfiguredResources) {
222
- await registerAttachedResourceTools(tools, resource.root);
236
+ await traceStartupStage("workspace.register.attachedResourceTools", () => registerAttachedResourceTools(tools, resource.root), {
237
+ workspaceRoot,
238
+ resourceRoot: resource.root,
239
+ });
223
240
  }
224
241
  const localResourceRoot = resolveResourcePackageRoot(workspaceRoot);
225
242
  const skillCollectionRoots = [
@@ -227,15 +244,24 @@ export async function loadWorkspace(workspaceRoot, options = {}) {
227
244
  ...(localResourceRoot ? [path.join(localResourceRoot, "skills")] : []),
228
245
  ...resolvedConfiguredResources.map((resource) => path.join(resource.root, "skills")),
229
246
  ];
230
- const skillRegistry = await registerWorkspaceSkillRegistry(skillCollectionRoots);
247
+ const skillRegistry = await traceStartupStage("workspace.register.skillRegistry", () => registerWorkspaceSkillRegistry(skillCollectionRoots), {
248
+ workspaceRoot,
249
+ skillCollectionRootCount: skillCollectionRoots.length,
250
+ });
231
251
  resolveAgentSkillNames(loaded.agents, skillRegistry, skillCollectionRoots);
232
252
  const collectedResources = collectToolSourceRefs(tools, loaded.agents, {
233
253
  ...options,
234
254
  resources: configuredResources,
235
255
  });
236
256
  const externalResources = collectedResources.filter((resource) => isExternalSourceLocator(resource));
237
- await ensureResourceSources(externalResources, workspaceRoot);
238
- await hydrateResourceAndExternalTools(tools, externalResources, workspaceRoot);
257
+ await traceStartupStage("workspace.ensure.externalResourceSources", () => ensureResourceSources(externalResources, workspaceRoot), {
258
+ workspaceRoot,
259
+ externalResourceCount: externalResources.length,
260
+ });
261
+ await traceStartupStage("workspace.hydrate.externalTools", () => hydrateResourceAndExternalTools(tools, externalResources, workspaceRoot), {
262
+ workspaceRoot,
263
+ externalResourceCount: externalResources.length,
264
+ });
239
265
  validateToolNameConflicts(tools);
240
266
  const resources = Array.from(new Set([
241
267
  ...(localResourceRoot ? [localResourceRoot] : []),
@@ -72,6 +72,9 @@ function shouldIncludeRemoteMcpTool(filter, toolName) {
72
72
  }
73
73
  return true;
74
74
  }
75
+ function canResolveMcpToolsFromExplicitNamesOnly(filter) {
76
+ return filter.includeNames.size > 0 && filter.includePatterns.length === 0;
77
+ }
75
78
  function normalizeAgentMcpServerUsage(item) {
76
79
  const config = asObject(item.config);
77
80
  if (!config) {
@@ -235,7 +238,11 @@ export async function hydrateAgentMcpTools(agents, mcpServers, tools) {
235
238
  mcpServers.set(serverId, parsedServer);
236
239
  }
237
240
  const filter = compileMcpToolFilter(item);
238
- const remoteTools = await listRemoteMcpTools(toMcpServerConfig(parsedServer));
241
+ const remoteTools = canResolveMcpToolsFromExplicitNamesOnly(filter)
242
+ ? Array.from(filter.includeNames)
243
+ .filter((toolName) => shouldIncludeRemoteMcpTool(filter, toolName))
244
+ .map((toolName) => ({ name: toolName }))
245
+ : await listRemoteMcpTools(toMcpServerConfig(parsedServer));
239
246
  for (const remoteTool of remoteTools) {
240
247
  if (!shouldIncludeRemoteMcpTool(filter, remoteTool.name)) {
241
248
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botbotgo/agent-harness",
3
- "version": "0.0.258",
3
+ "version": "0.0.260",
4
4
  "description": "Workspace runtime for multi-agent applications",
5
5
  "license": "MIT",
6
6
  "type": "module",