zen-free 0.1.21: another agent's <env> block is not taken for OpenCode's

The plugin added OpenCode's environment block unless a system message
already carried any <env> ... Working directory: ... </env>. Claude Code up
to about 2.1.100 ends its own prompt with such a block ("Here is useful
information about the environment you are running in:\n<env>\nWorking
directory: ..."), so its requests went to Zen without OpenCode's block,
while Pi's prompt, which has none, always got it. Zen gives a request
without OpenCode's block a small daily allowance on the same per-address
count, so it served Pi and answered Claude Code 429 FreeUsageLimitError
from the same machine (MrHayesLin and GuodingZ47927 on X, 2026-11-01).

Now only OpenCode's own block counts: <env>, then "  Working directory: "
two spaces in, as OpenCode 1.x and 2.x write it. Claude Code's block stays
and OpenCode's, naming the same folder, follows it. magpie's built-in Zen
path gets the same check in the same change.

Run at this tree on mote: bun test in packages/zen-free (204 pass, 0 fail),
bun scripts/check.mjs (every package ok).
Broken by hand: with the old regex the new case is red in all three
protocols (chat, responses, anthropic).
Checked by hand: Claude Code 2.0.76, 2.1.0 and 2.1.100 (npm) carry the
block; 2.1.316 (latest) has none, and its requests already got OpenCode's
block through this plugin (sandbox HOME, fake upstream).
Not tried: a request to Zen itself. Every machine here leaves from one
address whose free quota was spent today (real OpenCode 2.2.5 got the
same 429), so it can't be compared before 00:00 UTC. Why a current Claude
Code (2.1.316) is refused, if it is, is not known yet.
This commit is contained in:
yetone
2026-11-01 22:07:03 +08:00
parent df98bf6fb2
commit 0678f8613f
3 changed files with 38 additions and 2 deletions
+25
View File
@@ -836,6 +836,21 @@ const withPrompt = (protocol, prompt, user) =>
],
};
// What Claude Code 2.1.100 ends its system prompt with (cli.js, the
// environment section), for a folder that is no git repository.
const claudeCodePrompt = [
"You are Claude Code, Anthropic's official CLI for Claude.",
"Here is useful information about the environment you are running in:",
"<env>",
"Working directory: /Users/me/project",
"Is directory a git repo: No",
"Platform: darwin",
"Shell: zsh",
"OS Version: Darwin 25.2.0",
"</env>",
"You are powered by the model big-pickle.",
].join("\n");
for (const { protocol, path, model } of protocols) {
test(`${protocol}: an agent's own prompt goes with OpenCode's environment block, once`, async (t) => {
const { plugin, state, origin } = await fixture(t);
@@ -870,6 +885,16 @@ for (const { protocol, path, model } of protocols) {
const own = `${agentPrompt}\n<env>\n Working directory: /Users/me/project\n</env>`;
sent = await send(withPrompt(protocol, own, "hello"));
assert.equal(systemText(protocol, sent), own);
// Claude Code's own block (2.1.100's words) is not OpenCode's: it
// stays, and OpenCode's, naming the same folder, follows it
sent = await send(withPrompt(protocol, claudeCodePrompt, "hello"));
system = systemText(protocol, sent);
assert.ok(system.startsWith(claudeCodePrompt), system);
assert.equal(system.match(/<env>/g).length, 2);
assert.match(
system.slice(claudeCodePrompt.length),
/^\n\nHere is some useful information about the environment you are running in:\n<env>\n {2}Working directory: \/Users\/me\/project\n/,
);
});
}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-zen-free-auth",
"version": "0.1.20",
"version": "0.1.21",
"description": "OpenCode Zen free models through the public credential, with native streaming protocols",
"type": "module",
"main": "./index.mjs",
+12 -1
View File
@@ -283,7 +283,18 @@ function normalizeTools(body, protocol) {
// Zen on 2026-11-01, its temp folder line included), with the directory
// the agent's own prompt names, as OpenCode names its own, or the user's
// home folder when the prompt names none.
const HAS_ENVIRONMENT = /<env>[\s\S]*Working directory:[\s\S]*<\/env>/;
//
// Only OpenCode's own block counts as already there: `<env>` and then
// ` Working directory: `, two spaces in, as every OpenCode (1.x and 2.x)
// writes it. Another agent's block is its own text, not OpenCode's: Claude
// Code up to 2.1.100 or so ends its prompt with "Here is useful information
// about the environment you are running in:\n<env>\nWorking directory: ...",
// and with that taken for OpenCode's, its requests went to Zen without
// OpenCode's block while Pi's, which has none, got it. Zen then served Pi
// and answered Claude Code 429 FreeUsageLimitError from the same address
// (MrHayesLin on X, 2026-11-01). The agent's block stays; OpenCode's
// follows it.
const HAS_ENVIRONMENT = /<env>\r?\n {2}Working directory: [^\n]*\n[\s\S]*?<\/env>/;
// How agents name their working directory: Codex's `<cwd>`, Claude Code's
// and others' `Working directory:`, Kimi's "The current working directory
// is `...`". Only an absolute path counts.