@botbotgo/agent-harness 0.0.257 → 0.0.259
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 +10 -3
- package/dist/package-version.d.ts +1 -1
- package/dist/package-version.js +1 -1
- package/dist/persistence/sqlite-store.d.ts +1 -0
- package/dist/persistence/sqlite-store.js +34 -3
- package/dist/runtime/harness/run/startup-runtime.js +5 -2
- package/dist/runtime/harness.js +2 -1
- package/dist/runtime/startup-tracing.d.ts +1 -0
- package/dist/runtime/startup-tracing.js +37 -0
- package/dist/workspace/compile.js +35 -9
- package/dist/workspace/tool-hydration.js +8 -1
- package/package.json +1 -1
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
|
-
|
|
178
|
-
|
|
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.
|
|
1
|
+
export declare const AGENT_HARNESS_VERSION = "0.0.258";
|
package/dist/package-version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const AGENT_HARNESS_VERSION = "0.0.
|
|
1
|
+
export const AGENT_HARNESS_VERSION = "0.0.258";
|
|
@@ -22,6 +22,7 @@ export declare class SqlitePersistence implements RuntimePersistence {
|
|
|
22
22
|
private selectAll;
|
|
23
23
|
private mapThreadSummary;
|
|
24
24
|
private mapRunSummary;
|
|
25
|
+
private listRunSnapshots;
|
|
25
26
|
private mapApproval;
|
|
26
27
|
initialize(): Promise<void>;
|
|
27
28
|
private ensureSchemaMetadata;
|
|
@@ -6,6 +6,14 @@ import { SqliteRunContextStore } from "./sqlite-run-context-store.js";
|
|
|
6
6
|
import { SqliteRunQueueStore } from "./sqlite-run-queue-store.js";
|
|
7
7
|
const RUNTIME_SQLITE_SCHEMA_VERSION = 6;
|
|
8
8
|
const RUNTIME_SQLITE_SCHEMA_FAMILY = "agent-harness-runtime";
|
|
9
|
+
const ACTIVE_RUN_STATES = new Set([
|
|
10
|
+
"queued",
|
|
11
|
+
"claimed",
|
|
12
|
+
"running",
|
|
13
|
+
"waiting_for_approval",
|
|
14
|
+
"resuming",
|
|
15
|
+
"cancelling",
|
|
16
|
+
]);
|
|
9
17
|
function asRow(value) {
|
|
10
18
|
return value;
|
|
11
19
|
}
|
|
@@ -211,6 +219,7 @@ export class SqlitePersistence {
|
|
|
211
219
|
`);
|
|
212
220
|
await this.rawExecute("CREATE INDEX IF NOT EXISTS runs_thread_updated_idx ON runs(thread_id, updated_at DESC)");
|
|
213
221
|
await this.rawExecute("CREATE INDEX IF NOT EXISTS runs_thread_created_idx ON runs(thread_id, created_at DESC)");
|
|
222
|
+
await this.rawExecute("CREATE INDEX IF NOT EXISTS runs_updated_idx ON runs(updated_at DESC)");
|
|
214
223
|
await this.rawExecute("CREATE INDEX IF NOT EXISTS runs_state_updated_idx ON runs(state, updated_at DESC)");
|
|
215
224
|
await this.rawExecute("CREATE INDEX IF NOT EXISTS runs_agent_updated_idx ON runs(agent_id, updated_at DESC)");
|
|
216
225
|
await this.rawExecute("CREATE INDEX IF NOT EXISTS run_inspection_thread_activity_idx ON run_inspection(thread_id, last_activity_at DESC)");
|
|
@@ -434,6 +443,17 @@ export class SqlitePersistence {
|
|
|
434
443
|
...(runtimeSnapshot ? { runtimeSnapshot } : {}),
|
|
435
444
|
};
|
|
436
445
|
}
|
|
446
|
+
async listRunSnapshots(runIds) {
|
|
447
|
+
if (runIds.length === 0) {
|
|
448
|
+
return new Map();
|
|
449
|
+
}
|
|
450
|
+
const placeholders = runIds.map(() => "?").join(", ");
|
|
451
|
+
const rows = await this.selectAll(`SELECT run_id, runtime_snapshot_json
|
|
452
|
+
FROM run_inspection
|
|
453
|
+
WHERE run_id IN (${placeholders})
|
|
454
|
+
AND runtime_snapshot_json IS NOT NULL`, runIds);
|
|
455
|
+
return new Map(rows.map((row) => [asString(row.run_id), parseJson(row.runtime_snapshot_json)]));
|
|
456
|
+
}
|
|
437
457
|
mapApproval(row) {
|
|
438
458
|
return {
|
|
439
459
|
approvalId: asString(row.approval_id),
|
|
@@ -751,12 +771,23 @@ export class SqlitePersistence {
|
|
|
751
771
|
["runs.state = ?", filter.state],
|
|
752
772
|
]);
|
|
753
773
|
const rows = await this.selectAll(`SELECT runs.run_id, runs.thread_id, runs.agent_id, runs.parent_run_id, runs.execution_mode, runs.adapter_kind, runs.created_at, runs.updated_at, runs.state, runs.checkpoint_ref, runs.resumable,
|
|
754
|
-
run_inspection.started_at, run_inspection.ended_at, run_inspection.last_activity_at, run_inspection.current_agent_id, run_inspection.delegation_chain_json
|
|
774
|
+
run_inspection.started_at, run_inspection.ended_at, run_inspection.last_activity_at, run_inspection.current_agent_id, run_inspection.delegation_chain_json
|
|
755
775
|
FROM runs
|
|
756
776
|
LEFT JOIN run_inspection ON run_inspection.run_id = runs.run_id
|
|
757
777
|
${clause}
|
|
758
|
-
ORDER BY updated_at DESC`, args);
|
|
759
|
-
|
|
778
|
+
ORDER BY runs.updated_at DESC`, args);
|
|
779
|
+
const activeRunIds = rows
|
|
780
|
+
.filter((row) => ACTIVE_RUN_STATES.has(asString(row.state)))
|
|
781
|
+
.map((row) => asString(row.run_id));
|
|
782
|
+
const snapshotsByRunId = await this.listRunSnapshots(activeRunIds);
|
|
783
|
+
return rows.map((row) => {
|
|
784
|
+
const runId = asString(row.run_id);
|
|
785
|
+
const runtimeSnapshot = snapshotsByRunId.get(runId);
|
|
786
|
+
return {
|
|
787
|
+
...this.mapRunSummary(row),
|
|
788
|
+
...(runtimeSnapshot ? { runtimeSnapshot } : {}),
|
|
789
|
+
};
|
|
790
|
+
});
|
|
760
791
|
}
|
|
761
792
|
async getRun(runId) {
|
|
762
793
|
const row = await this.selectOne(`SELECT runs.run_id, runs.thread_id, runs.agent_id, runs.parent_run_id, runs.execution_mode, runs.adapter_kind, runs.created_at, runs.updated_at, runs.state, runs.checkpoint_ref, runs.resumable,
|
|
@@ -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
|
-
|
|
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) {
|
package/dist/runtime/harness.js
CHANGED
|
@@ -38,6 +38,7 @@ 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";
|
|
@@ -324,7 +325,7 @@ export class AgentHarnessRuntime {
|
|
|
324
325
|
persistence: this.persistence,
|
|
325
326
|
healthMonitor: this.healthMonitor,
|
|
326
327
|
});
|
|
327
|
-
await this.recoverStartupRuns();
|
|
328
|
+
await traceStartupStage("runtime.initialize.startupRecovery", () => this.recoverStartupRuns());
|
|
328
329
|
this.initialized = true;
|
|
329
330
|
}
|
|
330
331
|
subscribe(listener) {
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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 =
|
|
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;
|