Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion apps/web/agentActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,15 @@ export function createAgentPathMask(context: AgentActionContext) {

const statuses: Record<string, WebAgentActionBody['status']> = { inProgress: 'running', completed: 'done', failed: 'failed', declined: 'declined' };
// Streaming items start empty; only those that run for a while are worth a "running" row.
const startedKinds = new Set(['commandExecution', 'webSearch', 'mcpToolCall', 'dynamicToolCall', 'reasoning', 'agentMessage']);
const startedKinds = new Set(['commandExecution', 'webSearch', 'mcpToolCall', 'dynamicToolCall', 'reasoning', 'agentMessage', 'collabAgentToolCall']);
const collaborationTools = new Map([
['spawnAgent', 'spawn_agent'], ['sendInput', 'send_input'], ['resumeAgent', 'resume_agent'], ['wait', 'wait_agent'],
['closeAgent', 'close_agent'], ['sendMessage', 'send_message'], ['followupTask', 'followup_task'],
['interruptAgent', 'interrupt_agent'], ['listAgents', 'list_agents'],
]);
const subAgentActivities = new Map([
['started', 'agent_started'], ['interacted', 'agent_contacted'], ['interrupted', 'agent_interrupted'], ['completed', 'agent_turn_completed'],
]);

/** The last JSON object a command printed; the Agent's tools end with their result on one line. */
function lastJson(output: string): Item | undefined {
Expand Down Expand Up @@ -295,6 +303,20 @@ export function sanitizeAgentItem(phase: 'started' | 'completed', item: Item, co
return { ...base, kind: 'tool', status: status(failed ? 'failed' : 'done'), tool: clip(server ? `${server}.${name}` : name, 200).text,
...(args && args !== '{}' && args !== 'null' ? { arguments: args } : {}), ...(count(item.durationMs) !== undefined ? { durationMs: count(item.durationMs) } : {}) };
}
case 'collabAgentToolCall': {
const tool = collaborationTools.get(string(item.tool) ?? '');
if (!tool) return;
// Native thread ids and raw tool prompts are unnecessary for displaying the action.
return { ...base, kind: 'tool', tool: 'collaboration.' + tool,
status: item.status === 'interrupted' ? 'failed' : status('done') };
}
case 'subAgentActivity': {
const activity = subAgentActivities.get(string(item.kind) ?? ''), agent = string(item.agentPath);
if (!activity) return;
// This is a lifecycle observation, with proof acceptance reported separately by Lean.
return { ...base, kind: 'tool', tool: 'collaboration.' + activity, status: 'done',
...(agent ? { arguments: clip(shown(agent), limits.arguments).text } : {}) };
}
case 'imageView': return { ...base, kind: 'tool', status: 'done', tool: 'view_image', arguments: clip(mask(string(item.path) ?? '').text, limits.arguments).text };
case 'contextCompaction': return { ...base, kind: 'compaction', status: 'done' };
// User messages and hook prompts are the host's instructions to the Agent, not something the Agent did.
Expand Down
6 changes: 6 additions & 0 deletions scripts/codex-backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ not call a paid model or alter a running mathematical solve.
Mathematical nominations, source freezing, Lean checks and adoption remain host
operations; a native final answer does not create a proof delivery.

Pass `--team-capacity` to exercise eight writers with seven simultaneous member
requests. Pass `--large-fork` to verify that an oversized full-history fork
returns a tool error and Lead can retry with `fork_turns: "none"`. Pass
`--web-provider` to exercise proof delivery through the generated Web provider
profile, including metered requests before and after Lead cold resume.

The built runtime link installs this backend for new local CLI team runs.
The Web worker Dockerfile builds the same pinned source on Debian Bookworm
and installs a separate binary at `/opt/theoremos-codex-backend/codex`.
Expand Down
20 changes: 18 additions & 2 deletions scripts/codex-backend/agent-control.patch
Original file line number Diff line number Diff line change
Expand Up @@ -589,10 +589,10 @@ index 7c9cded4..1dada718 100644
if let Some(token_usage_turn_id) = token_usage_turn_id {
diff --git a/codex-rs/app-server/src/theoremos_agent_control.rs b/codex-rs/app-server/src/theoremos_agent_control.rs
new file mode 100644
index 00000000..dcad9fc4
index 00000000..7917d178
--- /dev/null
+++ b/codex-rs/app-server/src/theoremos_agent_control.rs
@@ -0,0 +1,860 @@
@@ -0,0 +1,876 @@
+//! Opt-in stdio transport for the native AgentControl execution contract.
+//! The model still invokes upstream collaboration handlers. The trusted host owns
+//! isolated runtimes and durable membership; it is never a dynamic-tool facade.
Expand Down Expand Up @@ -934,6 +934,22 @@ index 00000000..dcad9fc4
+ let params = TheoremosAgentControlRequestParams {
+ value: json!({"version":1,"sessionId":self.session_id,"threadId":self.thread_id,"operationId":uuid::Uuid::now_v7().to_string(),"operation":operation,"payload":payload}),
+ };
+ if operation == "spawn" {
+ // Match the host's stdio frame limit, reserving space for the
+ // request envelope and the maximum-width integer request ID.
+ const HOST_FRAME_BYTES: usize = 8 * 1024 * 1024;
+ const WIRE_OVERHEAD: usize =
+ br#"{"id":-9223372036854775808,"method":"theoremos/agentControl/request","params":}"#
+ .len();
+ if serde_json::to_vec(&params).map_err(decode_error)?.len() + WIRE_OVERHEAD
+ > HOST_FRAME_BYTES
+ {
+ return Err(CodexErr::InvalidRequest(
+ "Native spawn exceeds the 8 MiB transport limit. Retry with fork_turns=none and a short assignment."
+ .into(),
+ ));
+ }
+ }
+ let (request_id, receiver) = bridge
+ .outgoing
+ .send_request(ServerRequestPayload::TheoremosAgentControlRequest(params))
Expand Down
12 changes: 8 additions & 4 deletions scripts/mathematics/checkWestlakeProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ async function checkScenario(executable: string, scenario: Scenario): Promise<vo
onUsageIncomplete: () => { incompleteSignals++; },
requestGate,
onActivity: value => activities.push(`${value.event}:${value.itemType ?? ''}`) });
assert.equal(session.usageSource, limited ? 'upstream-requests' : undefined, 'native_usage_source_mismatch');
assert.equal(session.usageSource, limited ? 'upstream-requests' : 'native-thread-totals', 'native_usage_source_mismatch');
deadline = setTimeout(() => { void session?.close(); }, 45_000);
const status = await session.run('Run the local protocol check and report its completion marker.',
'westlake-offline-protocol-check', workspace, () => {});
Expand All @@ -246,12 +246,16 @@ async function checkScenario(executable: string, scenario: Scenario): Promise<vo
'native_budget_patch_did_not_execute');
assert.equal(activities.includes('item_completed:agentMessage'), false, 'native_budget_generated_final_message');
assert.equal(requestReceipts.length, 1, 'native_local_denial_created_request_receipt');
assert.deepEqual(requestReceipts[0], { complete: scenario.usage[0], usage: scenario.usage[0] ? {
assert.deepEqual(requestReceipts[0], { complete: scenario.usage[0], outcome: scenario.usage[0] ? 'completed' : 'failed',
...(!scenario.usage[0] ? { missingReason: 'provider-usage-missing' } : {}), usage: scenario.usage[0] ? {
inputTokens: 25, cachedInputTokens: 3, outputTokens: 8, reasoningOutputTokens: 4, totalTokens: 33,
} : undefined }, 'native_request_receipt_mismatch');
assert.deepEqual(requestRecord.requestUsageAccounting, { startedRequests: 1,
reportedRequests: Number(scenario.usage[0]), pendingRequests: 0, incomplete: !scenario.usage[0] },
const accounting = requestRecord.requestUsageAccounting!;
assert.deepEqual({ startedRequests: accounting.startedRequests, reportedRequests: accounting.reportedRequests,
pendingRequests: accounting.pendingRequests, incomplete: accounting.incomplete },
{ startedRequests: 1, reportedRequests: Number(scenario.usage[0]), pendingRequests: 0, incomplete: !scenario.usage[0] },
'native_local_denial_changed_usage_accounting');
assert.equal(accounting.receipts?.length, 1, 'native_local_denial_created_a_persisted_request_receipt');
assert.equal(requestBudget().status, scenario.usage[0] ? 'exhausted' : 'usage-unavailable', 'native_request_budget_status_mismatch');
assert.equal(requestBudget().reportedTotalTokens, scenario.usage[0] ? 33 : null, 'native_thread_counter_double_counted');
assert.equal(requestBudget().usageComplete, scenario.usage[0], 'native_request_budget_completeness_mismatch');
Expand Down
Loading
Loading