@magpie-community/opencode-factory-auth 0.1.9 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -3
- package/index.mjs +41 -3
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -77,9 +77,10 @@ magpie plugin login factory
|
|
|
77
77
|
Factory's Anthropic route requires Droid's fixed client preamble and
|
|
78
78
|
refuses some of Claude Code's fixed environment, model and built-in skill
|
|
79
79
|
metadata. The plugin adapts that metadata while preserving the coding
|
|
80
|
-
instructions, environment values, tool definitions,
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
instructions, environment values, tool definitions, images and reasoning
|
|
81
|
+
options. Ordinary Droid requests remain unchanged, and OpenAI routes keep
|
|
82
|
+
their existing request adapter. Quoted fixed metadata in tool results is
|
|
83
|
+
handled as described below.
|
|
83
84
|
|
|
84
85
|
For the built-in `update-config` skill, the adapter changes only the known
|
|
85
86
|
self-reference "not Claude" to "not the assistant" inside a complete
|
|
@@ -95,6 +96,17 @@ without the initial environment paragraph. Updates beginning with the known
|
|
|
95
96
|
model paragraph and containing complete generated token metadata are
|
|
96
97
|
adapted too, including accumulated switches when resuming a conversation.
|
|
97
98
|
Token budgets, permission instructions and conversation history are preserved.
|
|
99
|
+
The same model-update adaptation covers updates that start with the complete
|
|
100
|
+
generated `# Environment update` block after a working-directory change.
|
|
101
|
+
|
|
102
|
+
Factory can also refuse fixed client phrases quoted in tool results, such as
|
|
103
|
+
the identity/environment definitions printed when inspecting this plugin's
|
|
104
|
+
source. Those text results are represented as JSON strings with explicit
|
|
105
|
+
decoding instructions and Unicode escapes for the fixed phrases. Decoding
|
|
106
|
+
the string recovers the exact original output, including quotes, backslashes
|
|
107
|
+
and Unicode; the plugin does not delete the output or replace its identities
|
|
108
|
+
with different ones. Tool ids, cache/error markers and non-text blocks stay
|
|
109
|
+
unchanged. Ordinary tool results are forwarded as before.
|
|
98
110
|
|
|
99
111
|
Use magpie's Claude Code integration to select the Factory provider.
|
|
100
112
|
magpie manages the provider-specific client settings, including capability
|
package/index.mjs
CHANGED
|
@@ -592,15 +592,17 @@ const CONFIG_SKILL_COMPAT = CONFIG_SKILL_METADATA.replace("not Claude", "not the
|
|
|
592
592
|
// Claude 5 also sends its runtime metadata as a string-content system
|
|
593
593
|
// message, instead of user-message reminders. Preserve that role and all
|
|
594
594
|
// instructions. A model switch sends a separate update without the
|
|
595
|
-
// environment paragraph
|
|
596
|
-
// generated token context before
|
|
595
|
+
// environment paragraph, sometimes following a working-directory update;
|
|
596
|
+
// require the generated opening block and complete token context before
|
|
597
|
+
// adapting either update shape.
|
|
597
598
|
const SYSTEM_ENV_CONTEXT = /^# Environment\nYou have been invoked in the following environment:[ \t]*\n(?: {1,2}- [^\n]*\n)+(?=\n|$)/
|
|
598
599
|
const SYSTEM_MODEL_CONTEXT = /(^|\n\n)You are powered by the model (?:named )?[^\n<>]+\.(?=\n\n|$)/g
|
|
599
600
|
const SYSTEM_MODEL_UPDATE = /^You are powered by the model (?:named )?[^\n<>]+\.(?=\n\n|$)/
|
|
601
|
+
const SYSTEM_ENV_UPDATE = /^# Environment update\n(?: {1,2}- [^\n]*\n)+(?=\n|$)/
|
|
600
602
|
const SYSTEM_TOKEN_CONTEXT = /(?:^|\n\n)<total_tokens>\d+ tokens left<\/total_tokens>(?=\n\n|$)/
|
|
601
603
|
function systemContext(text) {
|
|
602
604
|
const environment = SYSTEM_ENV_CONTEXT.test(text)
|
|
603
|
-
if (!environment && !(SYSTEM_MODEL_UPDATE.test(text) && SYSTEM_TOKEN_CONTEXT.test(text))) return text
|
|
605
|
+
if (!environment && !((SYSTEM_MODEL_UPDATE.test(text) || SYSTEM_ENV_UPDATE.test(text)) && SYSTEM_TOKEN_CONTEXT.test(text))) return text
|
|
604
606
|
let out = text.replace(SYSTEM_MODEL_CONTEXT, (paragraph) => paragraph
|
|
605
607
|
.replace("You are powered by the model named", "Current model name:")
|
|
606
608
|
.replace("You are powered by the model", "Current model:")
|
|
@@ -618,6 +620,23 @@ function systemContext(text) {
|
|
|
618
620
|
return out
|
|
619
621
|
}
|
|
620
622
|
|
|
623
|
+
// Factory also refuses these fixed client phrases when they are quoted in
|
|
624
|
+
// tool output, e.g. while reading this adapter's source. Keep the original
|
|
625
|
+
// text recoverable: a JSON string with explicit decoding instructions,
|
|
626
|
+
// rather than deleting or rewriting the file's contents. Other output and
|
|
627
|
+
// the tool's id, error/cache markers and non-text blocks stay untouched.
|
|
628
|
+
const QUOTED_TOOL_PREFIX = "Tool output encoded as a JSON string. Decode the JSON string to recover the exact original text before using it:\n"
|
|
629
|
+
function quotedToolText(text) {
|
|
630
|
+
if (![...CLAUDE_IDENTITIES].some((identity) => text.includes(identity)) &&
|
|
631
|
+
!text.includes("You have been invoked in the following environment:") &&
|
|
632
|
+
!text.includes("x-anthropic-billing-header: cc_version=")) return text
|
|
633
|
+
let encoded = JSON.stringify(text)
|
|
634
|
+
for (const phrase of ["You are", "You have", "x-anthropic-billing-header", "system-reminder"]) {
|
|
635
|
+
encoded = encoded.replaceAll(phrase, "\\u" + phrase.charCodeAt(0).toString(16).padStart(4, "0") + phrase.slice(1))
|
|
636
|
+
}
|
|
637
|
+
return QUOTED_TOOL_PREFIX + encoded
|
|
638
|
+
}
|
|
639
|
+
|
|
621
640
|
function anthropicBody(body) {
|
|
622
641
|
let request
|
|
623
642
|
try {
|
|
@@ -685,6 +704,25 @@ function anthropicBody(body) {
|
|
|
685
704
|
}
|
|
686
705
|
if (message?.role !== "user" || !Array.isArray(message.content)) continue
|
|
687
706
|
for (const block of message.content) {
|
|
707
|
+
if (block?.type === "tool_result") {
|
|
708
|
+
if (typeof block.content === "string") {
|
|
709
|
+
const adapted = quotedToolText(block.content)
|
|
710
|
+
if (adapted !== block.content) {
|
|
711
|
+
block.content = adapted
|
|
712
|
+
changed = true
|
|
713
|
+
}
|
|
714
|
+
} else if (Array.isArray(block.content)) {
|
|
715
|
+
for (const part of block.content) {
|
|
716
|
+
if (part?.type !== "text" || typeof part.text !== "string") continue
|
|
717
|
+
const adapted = quotedToolText(part.text)
|
|
718
|
+
if (adapted !== part.text) {
|
|
719
|
+
part.text = adapted
|
|
720
|
+
changed = true
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
continue
|
|
725
|
+
}
|
|
688
726
|
if (block?.type !== "text" || typeof block.text !== "string") continue
|
|
689
727
|
if (ENV_REMINDER.test(block.text)) {
|
|
690
728
|
block.text = block.text.replace("# Environment", "# Runtime context")
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@magpie-community/opencode-factory-auth",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"description": "Sign in to a Factory (Droid) subscription from OpenCode or magpie",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.mjs",
|
|
7
7
|
"files": ["index.mjs", "README.md"],
|
|
8
8
|
"keywords": ["opencode", "opencode-plugin", "magpie", "factory", "droid"],
|
|
9
|
-
"license": "MIT"
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": { "type": "git", "url": "git+https://github.com/magpie-community/plugins.git", "directory": "packages/factory" }
|
|
10
11
|
}
|