factory: a skill list Claude Code sends alone as a system message is no longer refused over update-config's "not Claude" (#72, Vigilans)

Claude Code also sends the skill list as a standalone system message with
only its entries: no header, no <system-reminder> wrapper, no
<total_tokens> tail, as text blocks and (later in the same session) as a
plain string. The adapter only knew the headed and token-terminated forms,
so the update-config line went through unchanged and Factory answered
403; the reporter got 200 with only "not Claude" -> "not the assistant".

bareSkills applies that same known-line change to a system message that
opens with a "- " entry, both content shapes. User messages, quoted lists
and other skills' lines are left alone.

Run: HOME=<tmp> bun test in packages/factory, 118 pass (2 new, the
reporter's body byte for byte as fixture). With bareSkills made a no-op
by hand the new test goes red. Not sent to Factory: no Factory account
here.
This commit is contained in:
yetone
2026-10-10 17:55:26 +08:00
parent 00b06db784
commit 9d4bc83400
3 changed files with 53 additions and 2 deletions
+4
View File
@@ -139,6 +139,10 @@ Standalone skill updates can instead start with the generated skill-list
header and end with a token marker, for example when leaving auto mode.
That complete form receives the same adaptation while retaining the skill
descriptions and mode-change instructions.
The skill list can also come alone as a `system` message, with only its
entries: no header, no reminder wrapper and no token marker, as text blocks
or a string. A `system` message that opens with an entry gets the same
change to the known `update-config` line; everything else in it stays.
When runtime notifications precede the skill update, the adapter recognizes
the complete skill-header and bullet-list paragraphs inside a token-terminated
bundle. It preserves MCP connection errors, other notifications, mode updates
+11 -2
View File
@@ -658,6 +658,15 @@ const SKILL_REMINDER = /^<system-reminder>\nThe following skills are available f
const CONFIG_SKILL_METADATA = '- update-config: Use this skill to configure the Claude Code harness via settings.json. Automated behaviors ("from now on when X", "each time X", "whenever X", "before/after X") require hooks configured in settings.json - the harness executes these, not Claude, so memory/preferences cannot fulfill them.'
const CONFIG_SKILL_COMPAT = CONFIG_SKILL_METADATA.replace("not Claude", "not the assistant")
// Claude Code also sends the skill list alone as a system message: the
// entries only, no header, no <system-reminder> wrapper and no token tail,
// as text blocks or a string (#72). Only a system message that is such a
// list (it opens with an entry) changes, and in it only the known line.
function bareSkills(text) {
if (!text.startsWith("- ")) return text
return ("\n" + text).replace("\n" + CONFIG_SKILL_METADATA, "\n" + CONFIG_SKILL_COMPAT).slice(1)
}
// Claude 5 also sends its runtime metadata as a string-content system
// message, instead of user-message reminders. Preserve that role and all
// instructions. A model switch sends a separate update without the
@@ -975,7 +984,7 @@ function anthropicBody(body) {
for (const message of request.messages) {
if (message?.role === "system" && typeof message.content === "string") {
const adapted = clientOpening(systemContext(message.content))
const adapted = bareSkills(clientOpening(systemContext(message.content)))
if (adapted !== message.content) {
message.content = adapted
changed = true
@@ -988,7 +997,7 @@ function anthropicBody(body) {
if (message?.role === "system" && Array.isArray(message.content)) {
for (const block of message.content) {
if (block?.type !== "text" || typeof block.text !== "string") continue
const adapted = clientOpening(systemContext(block.text))
const adapted = bareSkills(clientOpening(systemContext(block.text)))
if (adapted !== block.text) {
block.text = adapted
changed = true
+38
View File
@@ -1258,3 +1258,41 @@ test("preserves quoted, incomplete and hook-owned restored-context turns", async
await l.fetch(url, { method: "POST", body })
expect(seen.at(-1).body).toBe(body)
})
// #72 (Vigilans): Claude Code 2.1.x sends the skill list alone as a system
// message, entries only, as text blocks and later as a string. The
// reporter's reduced body, byte for byte; Factory answered it 403 and gave
// 200 with "not Claude" as "not the assistant".
const bareConfigSkill = '- update-config: Use this skill to configure the Claude Code harness via settings.json. Automated behaviors ("from now on when X", "each time X", "whenever X", "before/after X") require hooks configured in settings.json - the harness executes these, not Claude, so memory/preferences cannot fulfill them. Also use for: permissions ("allow X", "add permission", "move permission to"), env vars ("set X=Y"), hook troubleshooting, or any changes to settings.json/settings.local.json files. Examples: "allow npm commands", "add bq permission to global", "move permission to user settings", "set DEBUG=true", "when claude stops show X". For simple settings like theme/model, suggest the /config command.'
test("a skill list sent alone as a system message has the update-config line adapted (#72)", async () => {
const { l, seen } = await loaded()
const fixed = bareConfigSkill.replace("not Claude", "not the assistant")
const list = "- custom: Keep not Claude in this user's description.\n" + bareConfigSkill + "\n- other: Another skill."
for (const [text, want] of [[bareConfigSkill, fixed], [list, list.replace(bareConfigSkill, fixed)]]) {
for (const content of [[{ type: "text", text }], text]) {
const request = { model: "factory/claude-opus-5-5", max_tokens: 32, stream: true, messages: [
{ role: "user", content: [{ type: "text", text: "hi" }] },
{ role: "system", content },
] }
await l.fetch(url, { method: "POST", body: JSON.stringify(request) })
const sent = JSON.parse(seen.at(-1).body)
expect(sent.messages[1].content).toEqual(typeof content === "string" ? want : [{ type: "text", text: want }])
expect(sent.messages[0]).toEqual(request.messages[0])
expect(JSON.stringify(sent)).not.toContain("not Claude, so")
}
}
})
test("only a system message that is a skill list is adapted (#72)", async () => {
const { l, seen } = await loaded()
for (const [role, text] of [
["user", bareConfigSkill],
["system", "Explain this:\n" + bareConfigSkill],
["system", bareConfigSkill.replace("- update-config:", "- custom-config:")],
]) {
const request = { model: "factory/claude-opus-5-5", max_tokens: 32, messages: [{ role: "user", content: "hi" }, { role, content: text }] }
await l.fetch(url, { method: "POST", body: JSON.stringify(request) })
expect(JSON.parse(seen.at(-1).body).messages[1].content).toBe(text)
}
})