This commit is contained in:
ZacharyZhang-NY committed 2026-04-05 23:47:56 -04:00
1 parent 9145572422
commit 72157f0703
10 files changed
+1157 -527

No files matched your search

+1 -1
View File
@@ -29,7 +29,7 @@ const claudeCompatModule: ServerAdapterModule = {
execute: claudeExecute,
testEnvironment: claudeTestEnvironment,
sessionCodec: claudeSessionCodec,
nativeContextManagement: true,
nativeContextManagement: false,
models: claudeModels,
};
+58
View File
@@ -0,0 +1,58 @@
/**
* Run-log noise filter.
*
* CLI adapters emit stdout/stderr containing system-level JSON messages,
* hook lifecycle events, skill injection notices, and assistant internals
* (thinking/tool_use). This module strips those lines before they reach
* the user-facing run log on disk.
*/
const RE_SKILL_INJECTION = /^\[agent-company\] Injected managed skill /;
const RE_OMC_HOOK = /^\[omc:hooks\]/;
const RE_AGENT_COMPANY_LOG = /^\[agent-company\] (?:heartbeat|hook_|system_)/;
/** Matches system JSON except `init` subtype (which carries session metadata). */
const RE_SYSTEM_JSON = /^\{"type"\s*:\s*"system"\s*,\s*"subtype"\s*:\s*"(?!init")/;
/** Matches assistant thinking/tool_use JSON — internal reasoning, not user-visible output. */
const RE_ASSISTANT_INTERNAL =
/^\{"type"\s*:\s*"assistant"\s*,\s*"subtype"\s*:\s*"(?:thinking|tool_use)"/;
const RE_COMPACTING = /^Compacting conversation\.\.\./;
function isNoisyLine(line: string): boolean {
const trimmed = line.trimStart();
if (trimmed.length === 0) return false;
return (
RE_SKILL_INJECTION.test(trimmed) ||
RE_OMC_HOOK.test(trimmed) ||
RE_AGENT_COMPANY_LOG.test(trimmed) ||
RE_SYSTEM_JSON.test(trimmed) ||
RE_ASSISTANT_INTERNAL.test(trimmed) ||
RE_COMPACTING.test(trimmed)
);
}
/**
* Filters a raw log chunk by removing noisy lines.
* @returns The cleaned chunk, or `null` if the entire chunk is noise.
*/
export function filterRunLogChunk(
_stream: "stdout" | "stderr",
chunk: string,
): string | null {
const lines = chunk.split("\n");
const kept: string[] = [];
for (const line of lines) {
if (!isNoisyLine(line)) {
kept.push(line);
}
}
if (kept.length === 0) return null;
const result = kept.join("\n");
return result.length === 0 ? null : result;
}
+7 -3
View File
@@ -3,6 +3,7 @@ import { getConnectorDefinition } from "../connectors";
import type { WorkerServiceDependencies, workerMessageSchema } from "./worker-types";
import { createCircuitBreaker } from "./circuit-breaker";
import { handleFailureEscalation, handleSuccessReset } from "./failure-escalation";
import { filterRunLogChunk } from "./run-log-filter";
const LEASE_RENEWAL_INTERVAL_MS = 5 * 60 * 1000; // 5 minutes
@@ -61,7 +62,10 @@ export async function handleWorkerMessage(
}
if (event.type === "run-log") {
await db.appendRunLog(event.runId, event.stream, event.chunk);
const filtered = filterRunLogChunk(event.stream, event.chunk);
if (filtered === null) return;
await db.appendRunLog(event.runId, event.stream, filtered);
const runState = db.getRunAuthState(event.runId);
if (runState) {
persistRunEvent(db, logger, {
@@ -70,10 +74,10 @@ export async function handleWorkerMessage(
agentId: runState.agentId,
eventType: "run_log",
stream: event.stream,
message: event.chunk,
message: filtered,
});
}
emitEvent(event);
emitEvent({ ...event, chunk: filtered });
// Throttled lease renewal: keep execution lock alive for long-running tasks.
// Without this, tasks exceeding the 15-minute stale lock timeout get reclaimed.