Skip to content

Commit 4fbd406

Browse files
committed
feat: Enhance system prompt handling and introduce client system prompt support
- Add new GPT 6.1 Sol - Added `clientSystemPrompt` option to `AgentLoopOptions` to allow host-supplied prompts. - Implemented `appendClientSystemPrompt` function to format and append client prompts with a heading. - Updated `runAgentLoop` to incorporate client system prompts into the model request. - Enhanced tests to validate the behavior of host system prompts, ensuring they are appended correctly and not stored in the transcript. - Introduced pooling for Codex app-server processes to improve performance by reusing instances across sessions. - Updated Codex app-server provider to handle session management and error handling more effectively. - Bumped `@anthropic-ai/claude-agent-sdk` dependency to version 0.3.282 for improved functionality.
1 parent 849008e commit 4fbd406

17 files changed

Lines changed: 483 additions & 90 deletions

‎crewcoder-agent/docs/ACP_ADAPTER.md‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,15 @@ see "Deliberate deviations" below.
6161
| `session/set_approval_mode` | Switches the active session approval/sandbox mode without respawning CrewCoder |
6262
| `session/set_external_directories` | Replaces and persists the session's explicitly granted filesystem roots |
6363
| `session/compact` | Compacts the durable CrewCoder session in place and returns the summary |
64+
| `session/set_system_prompt` | Sets a host-supplied system prompt for the session. Routed through `extMethod` |
6465
| `authenticate` | No-op; credentials are managed by `crewcoder auth` |
6566

6667
Capabilities are reported **honestly**: `loadSession: true`,
6768
`promptCapabilities.image: false`. CrewCoder takes images as on-disk paths, not
6869
inline base64, so advertising the ACP image block would invite a request it cannot
69-
serve. Manual compact is advertised on `initialize._meta["crewcoder/sessionCompact"]`,
70-
not as a standard ACP session capability.
70+
serve. Manual compact is advertised on `initialize._meta["crewcoder/sessionCompact"]`
71+
and the host system prompt on `initialize._meta["crewcoder/sessionSystemPrompt"]`,
72+
not as standard ACP session capabilities.
7173

7274
## Deliberate deviations from the 1.x schema
7375

@@ -102,6 +104,27 @@ dangerous-command tripwire should keep CrewCoder in `review` and auto-resolve or
102104
permission requests instead; setting `full-access` makes Codex unrestricted and prevents that
103105
host from inspecting provider-native commands before execution.
104106

107+
`session/set_system_prompt` is an additive extension for hosts that give CrewCoder an
108+
identity or role of their own (for example a Supervisor persona). It accepts
109+
`{ sessionId, systemPrompt }`, where `systemPrompt` is a string of at most 262,144
110+
characters. An empty string clears it. The response is
111+
`{ applied: true, length, appliesTo: "next_prompt" }`.
112+
113+
The prompt is appended to CrewCoder's system field under a "Host application system
114+
prompt" heading on every model request. It is never written to the transcript, so a host
115+
does not need to repeat identity context inside each user message, the transcript does not
116+
accumulate duplicate copies, and compaction cannot summarize it away. Where it defines
117+
identity, role, or voice it takes precedence over CrewCoder's default identity; tool policy,
118+
approvals, and sandbox rules still apply.
119+
120+
The value is held in memory for the live ACP session and is **not persisted**. Hosts must
121+
send it after every `session/new` and `session/load`, and again whenever it changes. A turn
122+
that is already running keeps the system field it started with. Changing the prompt changes
123+
the request prefix, so the next request cannot reuse the provider prompt cache, and the
124+
Codex app-server provider starts a fresh native thread because its continuation contract
125+
hash covers the system prompt. `initialize._meta["crewcoder/sessionSystemPrompt"]`
126+
advertises `{ method: "session/set_system_prompt", maxChars: 262144, persisted: false }`.
127+
105128
`session/compact` is the host compact-button path. It is an additive extension method
106129
routed through `extMethod`, same as `session/set_model`. `initialize._meta["crewcoder/sessionCompact"]`
107130
advertises `{ method: "session/compact", preview: true, editedSummary: true }` so CrewCode can

‎crewcoder-agent/docs/CODEX_TRANSPORT.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,24 @@ On later prompts—even in a new process—it calls `thread/resume` and sends on
5151
If the native thread was pruned or cannot be resumed, CrewCoder starts a replacement thread and
5252
seeds it from the current compacted CrewCoder history.
5353

54+
### Pooled app-server under ACP
55+
56+
One-shot commands (`crewcoder run`, print mode) still start one app-server per turn. `crewcoder acp`
57+
is long-lived, so it keeps **one app-server process per CrewCoder session** (same working directory,
58+
launch arguments, and Codex home) and reuses it across turns:
59+
60+
- A thread already loaded in that process under the same continuation contract goes straight to
61+
`turn/start`; `thread/resume` is skipped. Every resume makes Codex rebuild its world state
62+
(skills, plugins, environment). With a fresh process per turn, that rebuild raced remote plugin
63+
loading, the skill list differed between turns, and Codex re-sent the entire skills catalog to the
64+
model, roughly 2,300 to 3,000 extra tokens per affected turn.
65+
- A process that did not finish its turn cleanly (abort, transport error, early failure) is closed
66+
and never reused. The next turn starts a fresh process and resumes the thread normally.
67+
- A concurrent turn for a session whose process is busy runs on a separate, unpooled process.
68+
- Idle processes close after 10 minutes, and the pool is closed when the ACP server's stdin ends or
69+
the CrewCoder process exits.
70+
- Refreshed app-server credentials are still copied back to CrewCoder's auth store after every turn.
71+
5472
The persisted continuation includes a hash of the stable request contract: model, system prompt,
5573
working roots, and tool definitions. A contract change starts a fresh native thread instead of
5674
silently attaching incompatible context. Compaction clears the native thread ID, as it does for

‎crewcoder-agent/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
},
5858
"dependencies": {
5959
"@agentclientprotocol/sdk": "^1.3.0",
60-
"@anthropic-ai/claude-agent-sdk": "0.3.179",
60+
"@anthropic-ai/claude-agent-sdk": "0.3.282",
6161
"@openai/codex": "0.156.1",
6262
"commander": "^12.1.0",
6363
"fs-extra": "^11.2.0",

‎crewcoder-agent/src/acp/acp-agent.ts‎

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ import { DEFAULT_AGENT_MODE } from "../core/mode-router.js";
3737
import type { AgentEvent } from "../core/events.js";
3838
import type { ApprovalMode } from "../core/approval.js";
3939
import type { AgentMode } from "../core/types.js";
40-
import { HeuristicModelClient, type ModelQuestion } from "../core/model-client.js";
40+
import { HeuristicModelClient, type ModelClient, type ModelQuestion } from "../core/model-client.js";
41+
import { CLIENT_SYSTEM_PROMPT_MAX_CHARS } from "../core/system-prompt.js";
4142
import type { ApprovalControlDecision } from "../core/stdin-control.js";
4243
import { ProviderModelClient } from "../providers/provider-model-client.js";
4344
import { listBuiltinProviderModels, resolveModel } from "../providers/model-registry.js";
@@ -52,6 +53,8 @@ export type AcpAgentOptions = {
5253
mode?: AgentMode;
5354
/** Hard cap on model turns. 0/omitted means unlimited, per CrewCoder's default. */
5455
maxIterations?: number;
56+
/** Replaces the provider model client for prompt turns. Used by tests to observe model input. */
57+
modelClient?: ModelClient;
5558
};
5659

5760
type AcpSession = {
@@ -73,6 +76,11 @@ type AcpSession = {
7376
/** Instructions queued by session/follow_up while the agent loop is active. */
7477
followUpSignal: { messages: string[] };
7578
providerQuestionSequence: number;
79+
/**
80+
* Host-supplied system prompt from `session/set_system_prompt`. Held in
81+
* memory only: hosts re-send it after `session/new` or `session/load`.
82+
*/
83+
systemPrompt?: string;
7684
};
7785

7886
/**
@@ -89,7 +97,15 @@ export const CREWCODER_SESSION_COMPACT_META = {
8997
editedSummary: true
9098
} as const;
9199

100+
/** Advertised on `initialize._meta` so hosts can move identity context out of user messages. */
101+
export const CREWCODER_SESSION_SYSTEM_PROMPT_META = {
102+
method: "session/set_system_prompt",
103+
maxChars: CLIENT_SYSTEM_PROMPT_MAX_CHARS,
104+
persisted: false
105+
} as const;
106+
92107
const EXT_METHODS = new Set([
108+
"session/set_system_prompt",
93109
"session/set_model",
94110
"session/set_reasoning_effort",
95111
"session/set_approval_mode",
@@ -138,7 +154,10 @@ export class CrewCoderAcpAgent implements Agent {
138154
}
139155
},
140156
authMethods: [],
141-
_meta: { "crewcoder/sessionCompact": CREWCODER_SESSION_COMPACT_META }
157+
_meta: {
158+
"crewcoder/sessionCompact": CREWCODER_SESSION_COMPACT_META,
159+
"crewcoder/sessionSystemPrompt": CREWCODER_SESSION_SYSTEM_PROMPT_META
160+
}
142161
};
143162
}
144163

@@ -205,6 +224,10 @@ export class CrewCoderAcpAgent implements Agent {
205224
return this.compactSession(session, params);
206225
}
207226

227+
if (method === "session/set_system_prompt") {
228+
return this.setSystemPrompt(session, params);
229+
}
230+
208231
if (method === "session/follow_up") {
209232
const message = typeof params.message === "string" ? params.message.trim() : "";
210233
if (!message) throw RequestError.invalidParams({ reason: "message is required" });
@@ -260,6 +283,20 @@ export class CrewCoderAcpAgent implements Agent {
260283
return {};
261284
}
262285

286+
private setSystemPrompt(session: AcpSession, params: Record<string, unknown>): Record<string, unknown> {
287+
if (typeof params.systemPrompt !== "string") {
288+
throw RequestError.invalidParams({ reason: "systemPrompt must be a string (empty clears it)" });
289+
}
290+
if (params.systemPrompt.length > CLIENT_SYSTEM_PROMPT_MAX_CHARS) {
291+
throw RequestError.invalidParams({ reason: `systemPrompt exceeds ${CLIENT_SYSTEM_PROMPT_MAX_CHARS} characters` });
292+
}
293+
// A running turn already built its system field. The new value applies from
294+
// the next prompt, which keeps one turn under one consistent instruction set.
295+
const systemPrompt = params.systemPrompt.trim();
296+
session.systemPrompt = systemPrompt || undefined;
297+
return { applied: true, length: systemPrompt.length, appliesTo: "next_prompt" };
298+
}
299+
263300
private async compactSession(session: AcpSession, params: Record<string, unknown>): Promise<Record<string, unknown>> {
264301
if (session.abort) {
265302
throw RequestError.invalidParams({ reason: "Cannot compact while a prompt is running. Wait for the current turn to finish." });
@@ -343,9 +380,10 @@ export class CrewCoderAcpAgent implements Agent {
343380
contextWindow,
344381
approvalMode: session.approvalMode,
345382
maxIterations: this.options.maxIterations,
346-
modelClient: this.options.heuristic
383+
modelClient: this.options.modelClient ?? (this.options.heuristic
347384
? undefined
348-
: new ProviderModelClient(session.providerId, session.cwd, session.model, undefined, session.reasoningEffort),
385+
: new ProviderModelClient(session.providerId, session.cwd, session.model, undefined, session.reasoningEffort)),
386+
clientSystemPrompt: session.systemPrompt,
349387
approvalSignal,
350388
followUpSignal: session.followUpSignal,
351389
signal: abort.signal,

‎crewcoder-agent/src/acp/acp-server.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import { AgentSideConnection, ndJsonStream } from "@agentclientprotocol/sdk";
99
import { CrewCoderAcpAgent, type AcpAgentOptions } from "./acp-agent.js";
1010
import { claimStdout } from "./stdio.js";
11+
import { closeCodexAppServerPool, enableCodexAppServerPooling } from "../providers/codex-app-server-provider.js";
1112

1213
export type AcpServerOptions = AcpAgentOptions & {
1314
output: WritableStream<Uint8Array>;
@@ -25,13 +26,16 @@ export function createAcpServer(options: AcpServerOptions): AgentSideConnection
2526
/** Runs the ACP server over stdio until stdin closes. */
2627
export async function runAcpStdioServer(options: AcpAgentOptions = {}): Promise<void> {
2728
const { output, input, release } = claimStdout();
29+
// ACP hosts drive many turns per process, so Codex app-servers are kept per session.
30+
enableCodexAppServerPooling();
2831
createAcpServer({ ...options, output, input });
2932
try {
3033
await new Promise<void>((resolve) => {
3134
process.stdin.once("end", resolve);
3235
process.stdin.once("close", resolve);
3336
});
3437
} finally {
38+
closeCodexAppServerPool();
3539
release();
3640
}
3741
}

‎crewcoder-agent/src/core/agent-loop.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import type { CrewCoderExtSessionEntry } from "../extensions/api.js";
2020
import type { ExtensionUiBridge } from "./extension-ui-bridge.js";
2121
import { embeddedCrewCodeDocs, type EmbeddedDoc } from "../knowledge/crewcode-docs.js";
2222
import { embeddedCrewCoderExtensionDocs } from "../knowledge/crewcoder-extension-docs.js";
23-
import { appendCustomSystemPrompt, buildSystemPrompt } from "./system-prompt.js";
23+
import { appendClientSystemPrompt, appendCustomSystemPrompt, buildSystemPrompt } from "./system-prompt.js";
2424
import { getSystemPrompt } from "./system-prompt-store.js";
2525
import { createModelClientFromEnv, type ModelClient, type ModelQuestion } from "./model-client.js";
2626
import { createSessionId, saveSession, type SessionModelTurn } from "./session-store.js";
@@ -102,6 +102,11 @@ export type AgentLoopOptions = {
102102
resumeContext?: string;
103103
dumpModelInput?: boolean;
104104
systemPromptName?: string;
105+
/**
106+
* Host-supplied system prompt (ACP `session/set_system_prompt`). Appended to
107+
* the system field on every model request; never written to the transcript.
108+
*/
109+
clientSystemPrompt?: string;
105110
workerName?: string;
106111
workerDelegationDepth?: number;
107112
maxChildWorkerDepth?: number;
@@ -329,7 +334,10 @@ export async function runAgentLoop(request: AgentRequest, options: AgentLoopOpti
329334
buildSystemPrompt({ mode, skills, docs, identityPrompt: buildIdentityPrompt(activeWorker), crewTasksPrompt, extensionContext }),
330335
formatExternalDirectories(externalDirectories)
331336
].filter(Boolean).join("\n\n");
332-
const systemPrompt = appendCustomSystemPrompt(defaultSystemPrompt, selectedSystemPrompt?.content);
337+
const systemPrompt = appendClientSystemPrompt(
338+
appendCustomSystemPrompt(defaultSystemPrompt, selectedSystemPrompt?.content),
339+
options.clientSystemPrompt
340+
);
333341
const sandbox = buildSandboxContext(approvalMode, request.cwd, externalDirectories);
334342
const workerDelegationDepth = options.workerDelegationDepth ?? 0;
335343
const maxChildWorkerDepth = options.maxChildWorkerDepth ?? 1;

‎crewcoder-agent/src/core/system-prompt.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,24 @@ export function appendCustomSystemPrompt(defaultPrompt: string, customPrompt?: s
7676
if (!custom) return base;
7777
return [base, "Custom system prompt:", custom].join("\n\n");
7878
}
79+
80+
/** Upper bound for a host-supplied system prompt, in characters. */
81+
export const CLIENT_SYSTEM_PROMPT_MAX_CHARS = 262_144;
82+
83+
export const CLIENT_SYSTEM_PROMPT_HEADING = [
84+
"Host application system prompt:",
85+
"The application embedding CrewCoder supplied the instructions below. Where they define your identity, role, or voice, they take precedence over the default identity above. CrewCoder tool policy, approvals, and sandbox rules still apply."
86+
].join("\n");
87+
88+
/**
89+
* Appends a system prompt supplied by an embedding client (for example over
90+
* ACP `session/set_system_prompt`). It lives in the system field, which is
91+
* rebuilt on every request and never persisted into the transcript, so hosts
92+
* do not have to re-send identity context inside each user message.
93+
*/
94+
export function appendClientSystemPrompt(basePrompt: string, clientPrompt?: string | null): string {
95+
const base = basePrompt.trim();
96+
const client = clientPrompt?.trim();
97+
if (!client) return base;
98+
return [base, CLIENT_SYSTEM_PROMPT_HEADING, client].join("\n\n");
99+
}

‎crewcoder-agent/src/providers/builtins.ts‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const directCapabilities = {
1111

1212
const codexModelCatalog: ProviderModel[] = [
1313
{ id: "gpt-6-astra", contextWindow: 1_050_000 },
14+
{ id: "gpt-6.1-sol", contextWindow: 1_050_000 },
1415
{ id: "gpt-6-sol", contextWindow: 1_050_000 },
1516
{ id: "gpt-6-luna", contextWindow: 1_050_000 },
1617
{ id: "gpt-5.6-sol", contextWindow: 1_050_000 },
@@ -22,9 +23,12 @@ const codexModelCatalog: ProviderModel[] = [
2223
];
2324

2425
const claudeModelCatalog: ProviderModel[] = [
25-
{ id: "claude-sonnet-5", contextWindow: 1_000_000 },
26+
{ id: "claude-opus-5-5", contextWindow: 1_000_000 },
27+
{ id: "claude-fable-5-1", contextWindow: 1_000_000 },
28+
{ id: "claude-sonnet-5-5", contextWindow: 1_000_000 },
29+
{ id: "claude-sonnet-5", contextWindow: 1_000_000 },
30+
{ id: "claude-haiku-4-5", contextWindow: 200_000 },
2631
{ id: "claude-opus-5", contextWindow: 1_000_000 },
27-
{ id: "claude-haiku-4-5", contextWindow: 200_000 },
2832
{ id: "claude-opus-4-8", contextWindow: 1_000_000 },
2933
{ id: "claude-sonnet-4-6", contextWindow: 1_000_000 }
3034
];
@@ -38,7 +42,7 @@ export const builtinProviders: ProviderDefinition[] = [
3842
command: "http",
3943
args: [],
4044
endpoint: process.env.CREWCODER_CODEX_ENDPOINT ?? "https://chatgpt.com/backend-api/codex/responses",
41-
models: ["gpt-6-astra", "gpt-6-sol", "gpt-6-luna", "gpt-5.6-sol", "gpt-5.6-terra", "gpt-5.6-luna", "gpt-5.5", "gpt-5.4", "gpt-5.4-mini"],
45+
models: ["gpt-6-astra", "gpt-6.1-sol", "gpt-6-sol", "gpt-6-luna", "gpt-5.6-sol", "gpt-5.6-terra", "gpt-5.6-luna", "gpt-5.5", "gpt-5.4", "gpt-5.4-mini"],
4246
modelCatalog: codexModelCatalog,
4347
defaultModel: "gpt-5.6-luna",
4448
capabilities: directCapabilities,
@@ -52,9 +56,9 @@ export const builtinProviders: ProviderDefinition[] = [
5256
runtime: "claude-agent-sdk",
5357
command: "sdk",
5458
args: [],
55-
models: ["claude-sonnet-5", "claude-opus-5", "claude-haiku-4-5", "claude-opus-4-8", "claude-sonnet-4-6"],
59+
models: ["claude-opus-5-5", "claude-opus-5", "claude-fable-5-1", "claude-sonnet-5-5", "claude-sonnet-5", "claude-haiku-4-5", "claude-opus-4-8", "claude-sonnet-4-6"],
5660
modelCatalog: claudeModelCatalog,
57-
defaultModel: "claude-sonnet-5",
61+
defaultModel: "claude-sonnet-5-5",
5862
capabilities: directCapabilities,
5963
transport: { channel: "process", continuation: "provider-session", replay: "never" },
6064
description: "- Claude Code Agent SDK using the local Claude login. Run Claude Code login first."
@@ -112,9 +116,9 @@ export const builtinProviders: ProviderDefinition[] = [
112116
endpoint: process.env.CREWCODER_ANTHROPIC_ENDPOINT ?? "https://api.anthropic.com/v1/messages",
113117
apiKeyEnv: "ANTHROPIC_API_KEY",
114118
authScheme: "anthropic-key",
115-
models: ["claude-sonnet-5", "claude-opus-5", "claude-haiku-4-5", "claude-opus-4-8", "claude-sonnet-4-6"],
119+
models: ["claude-opus-5-5", "claude-opus-5", "claude-fable-5-1", "claude-sonnet-5-5", "claude-sonnet-5", "claude-haiku-4-5", "claude-opus-4-8", "claude-sonnet-4-6"],
116120
modelCatalog: claudeModelCatalog,
117-
defaultModel: "claude-sonnet-5",
121+
defaultModel: "claude-sonnet-5-5",
118122
capabilities: directCapabilities,
119123
transport: { channel: "http-sse", continuation: "none", replay: "pre-stream-only" },
120124
description: "- Official Anthropic Messages API. Set ANTHROPIC_API_KEY."

0 commit comments

Comments
 (0)