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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Forked from [nasrulhadi/proxy-commandcode](https://github.com/nasrulhadi/proxy-c
| Usage | `finish-step`/`finish` usage mapped to OpenAI `usage` (sync body; extra stream chunk with empty `choices`) |
| Finish reason | `length` / `tool_calls` / `content_filter` mapped from the upstream reason |
| Request shape | Tool-call `input` sent as an object; consecutive tool results merged; `developer` role folded into `system`; image parts use `{image, mediaType}`; `temperature` and `max_completion_tokens` passed through; `x-session-id` and `x-cli-environment` headers sent |
| System prompt | A request with no (or a blank) system message gets a one-line default (`PCMC_DEFAULT_SYSTEM`, default `You are a helpful assistant.`); otherwise the gateway injects the ~7.3K-token `cmd` agent prompt on every call |
| CLI version | `x-command-code-version` tracks `command-code@latest` on npm (checked at start and every 6 h, default `1.66.0`); set `PCMC_VERSION` to pin |
| Runtime | Logs to stdout only (no `proxy.log`, no ANSI without a TTY); Windows `netstat`/`taskkill` port handling removed; graceful `SIGTERM`; `Dockerfile` + `npm test` |

Expand Down
7 changes: 6 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ const DEFAULT_CC_VERSION = '1.66.0';
const PINNED_VERSION = process.env.PCMC_VERSION || '';
const VERSION_REFRESH_MS = 6 * 60 * 60 * 1000;
const DEBUG = process.env.PCMC_DEBUG === '1';
// With no system prompt the gateway substitutes the ~7.3K-token `cmd` agent
// prompt (CLI tools, commit rules, taste file), which costs tokens on every call
// and makes the model act as a coding agent. A blank system is rejected by some
// models, so always send a real one.
const DEFAULT_SYSTEM = (process.env.PCMC_DEFAULT_SYSTEM || '').trim() || 'You are a helpful assistant.';

let ccVersion = PINNED_VERSION || DEFAULT_CC_VERSION;

Expand Down Expand Up @@ -135,7 +140,7 @@ function transform(oaiBody) {
}));

const params = {
model, system: systemText || undefined, messages, tools: tools.length > 0 ? tools : undefined,
model, system: systemText.trim() ? systemText : DEFAULT_SYSTEM, messages, tools: tools.length > 0 ? tools : undefined,
max_tokens: oaiBody.max_completion_tokens || oaiBody.max_tokens || 32000,
// The gateway rejects stream:false; always stream upstream and buffer here.
stream: true,
Expand Down
10 changes: 10 additions & 0 deletions test/transform.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ test('builds the strict envelope and always streams upstream', () => {
assert.deepEqual(body.params.messages, [{ role: 'user', content: [{ type: 'text', text: 'hi' }] }]);
});

test('sends a default system prompt when none or a blank one is given', () => {
for (const messages of [
[{ role: 'user', content: 'q' }],
[{ role: 'system', content: ' ' }, { role: 'user', content: 'q' }],
]) {
const body = JSON.parse(transform({ messages }));
assert.equal(body.params.system, 'You are a helpful assistant.');
}
});

test('maps system/developer to params.system', () => {
const body = JSON.parse(transform({ messages: [
{ role: 'system', content: 'a' }, { role: 'developer', content: [{ type: 'text', text: 'b' }] }, { role: 'user', content: 'q' },
Expand Down
Loading