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
14 changes: 14 additions & 0 deletions apps/server/src/harness/atomic/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,17 @@ export function atomicTurnExtension(policy: TurnPolicy): ExtensionFactory {
};
},
});
let stage = false;
atomic.on("session_start", (_event, ctx) => {
stage = ctx.subagentPolicy !== undefined;
});
atomic.on("before_agent_start", event => {
if (stage) {
atomic.setActiveTools(
atomic.getActiveTools().filter(name => name !== ATOMIC_RESULT_TOOL_NAME),
);
return;
}
if (!policy.full) atomic.setActiveTools(activeNames(policy));
return {
systemPrompt: policy.full
Expand All @@ -204,6 +214,10 @@ export function atomicTurnExtension(policy: TurnPolicy): ExtensionFactory {
};
});
atomic.on("tool_call", event => {
if (stage) {
if (event.toolName !== ATOMIC_RESULT_TOOL_NAME) return;
return { block: true, reason: `${event.toolName} is not available in a workflow stage.` };
}
if (policy.full && event.toolName !== ATOMIC_RESULT_TOOL_NAME) return;
if (activeNames(policy).includes(event.toolName)) return;
return { block: true, reason: `${event.toolName} is not available in this turn.` };
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/harness/atomic/full.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,8 @@ test(
)!;
expect(stage.toolNames).toContain("bash");
expect(stage.toolNames).toContain("write");
expect(stage.toolNames).not.toContain(ATOMIC_RESULT_TOOL_NAME);
expect(stage.system).not.toContain("CHOPIN-INSTRUCTIONS-MARKER");
} finally {
if (environment !== undefined) process.env.NODE_ENV = environment;
await room.close();
Expand Down
10 changes: 7 additions & 3 deletions apps/server/src/harness/atomic/full.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,10 @@ export function workflowRuns(planner: FullPlanner): ExtensionFactory {
let names = new Map<string, string>();
let parents = new Map<string, string>();
let seen = new Set<string>();
planner.rootOf = runId => parents.get(runId) ?? runId;
let stage = true;
let ready = false;
let publish = () => {
if (!ready) return;
if (stage || !ready) return;
for (let [id, card] of cards) {
if (seen.has(id) && !roots.has(id) && card.ended === undefined) {
card.status = "finished";
Expand All @@ -270,6 +270,9 @@ export function workflowRuns(planner: FullPlanner): ExtensionFactory {
for (let wake of planner.waiters ?? []) wake();
};
atomic.on("session_start", (_event, ctx) => {
stage = ctx.subagentPolicy !== undefined;
if (stage) return;
planner.rootOf = runId => parents.get(runId) ?? runId;
lease?.dispose();
lease = ctx.observeWorkflowActivity(frame => {
if (frame.kind === "snapshot") {
Expand All @@ -283,7 +286,7 @@ export function workflowRuns(planner: FullPlanner): ExtensionFactory {
});
});
atomic.on("tool_result", event => {
if (event.toolName !== "workflow" || event.input.action !== "run") return;
if (stage || event.toolName !== "workflow" || event.input.action !== "run") return;
let runId = launchedRunId(event.content);
let name = typeof event.input.workflow === "string" ? event.input.workflow : undefined;
if (!runId || !name) return;
Expand All @@ -295,6 +298,7 @@ export function workflowRuns(planner: FullPlanner): ExtensionFactory {
}
});
atomic.on("workflow_lifecycle", event => {
if (stage) return;
if (event.target.kind !== "prompt") parents.set(event.target.runId, event.rootRunId);
foldLifecycle(cards, event, names.get(event.rootRunId));
publish();
Expand Down
24 changes: 12 additions & 12 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/self-hosting.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ it. The Pi contract suite (`apps/server/src/harness/pi.contract.test.ts`)
covers this against the real Pi agent loop; run it before bumping
`@ai-sdk/harness-pi` or `@earendil-works/pi-coding-agent`.

`HARNESS=atomic` runs Atomic 0.9.31 in the Chopin server process through its
`HARNESS=atomic` runs Atomic 0.9.32 in the Chopin server process through its
headless SDK (`createAgentSession()`). It does not spawn the `atomic` CLI, use
RPC mode, or substitute Atomic for Pi's runtime.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"@ai-sdk/harness-pi": "1.0.148",
"@ai-sdk/mcp": "2.0.72",
"@ai-sdk/sandbox-just-bash": "1.0.146",
"@bastani/atomic": "0.9.31",
"@bastani/atomic": "0.9.32",
"@earendil-works/pi-coding-agent": "0.85.1",
"ai": "7.0.135",
"typebox": "1.3.7",
Expand Down
Loading