@magpie-community/opencode-factory-auth 0.1.11 → 0.1.12
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/index.mjs +46 -1
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -604,7 +604,20 @@ const SYSTEM_MODEL_CONTEXT = /(^|\n\n)You are powered by the model (?:named )?[^
|
|
|
604
604
|
const SYSTEM_MODEL_UPDATE = /^You are powered by the model (?:named )?[^\n<>]+\.(?=\n\n|$)/
|
|
605
605
|
const SYSTEM_ENV_UPDATE = /^# Environment update\n(?: {1,2}- [^\n]*\n)+(?=\n|$)/
|
|
606
606
|
const SYSTEM_TOKEN_CONTEXT = /(?:^|\n\n)<total_tokens>\d+ tokens left<\/total_tokens>(?=\n\n|$)/
|
|
607
|
+
// A SessionStart hook's output comes ahead of the generated context in the
|
|
608
|
+
// same message (Claude Code 2.1.288 with a hook installed, #634): the
|
|
609
|
+
// context after it is adapted as it would be on its own, the hook's output
|
|
610
|
+
// is left as it is.
|
|
611
|
+
const HOOK_OUTPUT = /^SessionStart:[^\n]* hook success:/
|
|
612
|
+
const HOOK_CONTEXT = "\n# Environment\nYou have been invoked in the following environment:"
|
|
607
613
|
function systemContext(text) {
|
|
614
|
+
if (HOOK_OUTPUT.test(text)) {
|
|
615
|
+
const at = text.indexOf(HOOK_CONTEXT)
|
|
616
|
+
return at < 0 ? text : text.slice(0, at + 1) + generatedContext(text.slice(at + 1))
|
|
617
|
+
}
|
|
618
|
+
return generatedContext(text)
|
|
619
|
+
}
|
|
620
|
+
function generatedContext(text) {
|
|
608
621
|
const environment = SYSTEM_ENV_CONTEXT.test(text)
|
|
609
622
|
if (!environment && !((SYSTEM_MODEL_UPDATE.test(text) || SYSTEM_ENV_UPDATE.test(text)) && SYSTEM_TOKEN_CONTEXT.test(text))) return text
|
|
610
623
|
let out = text.replace(SYSTEM_MODEL_CONTEXT, (paragraph) => paragraph
|
|
@@ -624,6 +637,22 @@ function systemContext(text) {
|
|
|
624
637
|
return out
|
|
625
638
|
}
|
|
626
639
|
|
|
640
|
+
// The model line inside a system prompt (Claude Desktop's, #634) is the
|
|
641
|
+
// same generated sentence as in a reminder; only that line changes.
|
|
642
|
+
const SYSTEM_MODEL_LINE = /(^|\n)You are powered by the model [^\n<>]+/g
|
|
643
|
+
function systemModelLine(text) {
|
|
644
|
+
return text.replace(SYSTEM_MODEL_LINE, (line) => line
|
|
645
|
+
.replace("You are powered by the model named", "Current model name:")
|
|
646
|
+
.replace("You are powered by the model", "Current model:")
|
|
647
|
+
.replace("The exact model ID is", "Model ID:")
|
|
648
|
+
.replace("Assistant knowledge cutoff is", "Model knowledge cutoff:"))
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
// The reminder carrying CLAUDE.md files names the global one with a phrase
|
|
652
|
+
// Factory refuses; only that phrase in the generated reminder changes.
|
|
653
|
+
const INSTRUCTIONS_REMINDER = "<system-reminder>\nCodebase and user instructions are shown below"
|
|
654
|
+
const GLOBAL_INSTRUCTIONS = "(user's private global instructions for all projects)"
|
|
655
|
+
|
|
627
656
|
// Factory also refuses these fixed client phrases when they are quoted in
|
|
628
657
|
// tool output, e.g. while reading this adapter's source. Keep the original
|
|
629
658
|
// text recoverable: a JSON string with explicit decoding instructions,
|
|
@@ -676,6 +705,12 @@ function anthropicBody(body) {
|
|
|
676
705
|
if (block?.type === "text" && CLAUDE_IDENTITIES.has(block.text)) {
|
|
677
706
|
block.text = DROID_LINE
|
|
678
707
|
changed = true
|
|
708
|
+
} else if (block?.type === "text") {
|
|
709
|
+
const adapted = systemModelLine(block.text)
|
|
710
|
+
if (adapted !== block.text) {
|
|
711
|
+
block.text = adapted
|
|
712
|
+
changed = true
|
|
713
|
+
}
|
|
679
714
|
}
|
|
680
715
|
kept.push(block)
|
|
681
716
|
}
|
|
@@ -728,7 +763,17 @@ function anthropicBody(body) {
|
|
|
728
763
|
continue
|
|
729
764
|
}
|
|
730
765
|
if (block?.type !== "text" || typeof block.text !== "string") continue
|
|
731
|
-
if (
|
|
766
|
+
if (block.text.startsWith(INSTRUCTIONS_REMINDER) && block.text.includes(GLOBAL_INSTRUCTIONS)) {
|
|
767
|
+
block.text = block.text.replaceAll(GLOBAL_INSTRUCTIONS, "(global instructions)")
|
|
768
|
+
changed = true
|
|
769
|
+
} else if (HOOK_OUTPUT.test(block.text)) {
|
|
770
|
+
// a system message folded into the user's turn on its way here
|
|
771
|
+
const adapted = systemContext(block.text)
|
|
772
|
+
if (adapted !== block.text) {
|
|
773
|
+
block.text = adapted
|
|
774
|
+
changed = true
|
|
775
|
+
}
|
|
776
|
+
} else if (ENV_REMINDER.test(block.text)) {
|
|
732
777
|
block.text = block.text.replace("# Environment", "# Runtime context")
|
|
733
778
|
.replace("You have been invoked in the following environment:", "The session environment is:")
|
|
734
779
|
changed = true
|