@magpie-community/opencode-factory-auth 0.1.21 → 0.1.23
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 +16 -1
- package/index.mjs +47 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -139,10 +139,21 @@ Standalone skill updates can instead start with the generated skill-list
|
|
|
139
139
|
header and end with a token marker, for example when leaving auto mode.
|
|
140
140
|
That complete form receives the same adaptation while retaining the skill
|
|
141
141
|
descriptions and mode-change instructions.
|
|
142
|
+
The skill list can also come alone as a `system` message, with only its
|
|
143
|
+
entries: no header, no reminder wrapper and no token marker, as text blocks
|
|
144
|
+
or a string. A `system` message that opens with an entry gets the same
|
|
145
|
+
change to the known `update-config` line; everything else in it stays.
|
|
142
146
|
When runtime notifications precede the skill update, the adapter recognizes
|
|
143
147
|
the complete skill-header and bullet-list paragraphs inside a token-terminated
|
|
144
148
|
bundle. It preserves MCP connection errors, other notifications, mode updates
|
|
145
149
|
and custom skill descriptions while adapting the known built-in description.
|
|
150
|
+
After `/compact`, Claude Code also sends the files it restores and the
|
|
151
|
+
runtime context as one turn that opens with an unwrapped restored-file note
|
|
152
|
+
or Read call, with no token marker first. When that turn also carries the
|
|
153
|
+
generated environment paragraph or a token marker before any hook output,
|
|
154
|
+
each fixed paragraph (file notes, Read calls and results, environment, model
|
|
155
|
+
line) is adapted as in a token-prefixed bundle; everything else stays
|
|
156
|
+
byte-for-byte. Quoted, incomplete and hook-owned forms are left alone.
|
|
146
157
|
|
|
147
158
|
Factory can also refuse fixed client phrases quoted in tool results, such as
|
|
148
159
|
the identity/environment definitions printed when inspecting this plugin's
|
|
@@ -170,7 +181,11 @@ Use magpie's Claude Code integration to select the Factory provider.
|
|
|
170
181
|
magpie manages the provider-specific client settings, including capability
|
|
171
182
|
and permission configuration. Fields such as `safeguards` and
|
|
172
183
|
`context_management` are forwarded for Factory to validate; the request
|
|
173
|
-
adapter preserves them along with the other request options.
|
|
184
|
+
adapter preserves them along with the other request options. One exception:
|
|
185
|
+
Factory's streaming route refuses `context_management` ("Extra inputs are
|
|
186
|
+
not permitted") while its non-streaming route takes it, so a streamed
|
|
187
|
+
request is sent without it. The server then clears nothing from the
|
|
188
|
+
context; Claude Code's own compaction still runs.
|
|
174
189
|
|
|
175
190
|
The same metadata adaptation applies to `/messages` and
|
|
176
191
|
`/messages/count_tokens`, so token counting sees the prompt used for
|
package/index.mjs
CHANGED
|
@@ -658,6 +658,15 @@ const SKILL_REMINDER = /^<system-reminder>\nThe following skills are available f
|
|
|
658
658
|
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.'
|
|
659
659
|
const CONFIG_SKILL_COMPAT = CONFIG_SKILL_METADATA.replace("not Claude", "not the assistant")
|
|
660
660
|
|
|
661
|
+
// Claude Code also sends the skill list alone as a system message: the
|
|
662
|
+
// entries only, no header, no <system-reminder> wrapper and no token tail,
|
|
663
|
+
// as text blocks or a string (#72). Only a system message that is such a
|
|
664
|
+
// list (it opens with an entry) changes, and in it only the known line.
|
|
665
|
+
function bareSkills(text) {
|
|
666
|
+
if (!text.startsWith("- ")) return text
|
|
667
|
+
return ("\n" + text).replace("\n" + CONFIG_SKILL_METADATA, "\n" + CONFIG_SKILL_COMPAT).slice(1)
|
|
668
|
+
}
|
|
669
|
+
|
|
661
670
|
// Claude 5 also sends its runtime metadata as a string-content system
|
|
662
671
|
// message, instead of user-message reminders. Preserve that role and all
|
|
663
672
|
// instructions. A model switch sends a separate update without the
|
|
@@ -685,6 +694,8 @@ const SYSTEM_SKILL_CONTEXT = /^The following skills are available for use with t
|
|
|
685
694
|
function systemContext(text) {
|
|
686
695
|
text = changedFileContext(text)
|
|
687
696
|
text = announcedSkills(text)
|
|
697
|
+
const restored = restoredContext(text)
|
|
698
|
+
if (restored !== null) return restored
|
|
688
699
|
if (SYSTEM_TOKEN_OPENING.test(text) || SYSTEM_SKILL_CONTEXT.test(text)) return announcedContext(text)
|
|
689
700
|
if (HOOK_OUTPUT.test(text) || text.startsWith(DEFERRED_TOOLS_OPENING)) {
|
|
690
701
|
const at = text.indexOf(HOOK_CONTEXT)
|
|
@@ -714,11 +725,11 @@ function announcedSkills(text) {
|
|
|
714
725
|
// Claude Code also announces several reminders as one system turn, with
|
|
715
726
|
// token context and no system-reminder wrappers. Only known metadata
|
|
716
727
|
// paragraphs change; numbered file contents and the hook's own output stay.
|
|
717
|
-
function announcedContext(text) {
|
|
728
|
+
function announcedContext(text, start = 1) {
|
|
718
729
|
const parts = changedFileContext(text).split(/\n\n(?!\.\.\. \[)/)
|
|
719
730
|
const open = "<system-reminder>\n", close = "\n</system-reminder>"
|
|
720
731
|
let quoteChangedFiles = true
|
|
721
|
-
for (let i =
|
|
732
|
+
for (let i = start; i < parts.length; i++) {
|
|
722
733
|
const part = parts[i]
|
|
723
734
|
const hook = part.replace(/^<system-reminder>\n/, "")
|
|
724
735
|
if (HOOK_OUTPUT.test(hook)) break
|
|
@@ -747,6 +758,28 @@ function announcedContext(text) {
|
|
|
747
758
|
return parts.join("\n\n")
|
|
748
759
|
}
|
|
749
760
|
|
|
761
|
+
// After /compact, Claude Code (2.1.280) sends the files it restores and the
|
|
762
|
+
// session's runtime context as one turn without reminder wrappers or an
|
|
763
|
+
// opening token marker: restored-file notes, Read calls and their results,
|
|
764
|
+
// the environment, the model line, token and date. Each fixed fragment is
|
|
765
|
+
// refused on its own (plugins#68). Require the generated restored-file
|
|
766
|
+
// opening and the generated environment paragraph or a token marker before
|
|
767
|
+
// the first hook; then each paragraph is adapted as in a token-prefixed
|
|
768
|
+
// bundle, the rest kept byte-for-byte. An adapted block no longer opens
|
|
769
|
+
// with the generated note, so a second pass leaves it as it is.
|
|
770
|
+
function restoredContext(text) {
|
|
771
|
+
const parts = text.split(/\n\n(?!\.\.\. \[)/)
|
|
772
|
+
const result = parts[0].indexOf("\n" + READ_RESULT_HEADER)
|
|
773
|
+
const opening = "<system-reminder>\n" + (result < 0 ? parts[0] : parts[0].slice(0, result)) + "\n</system-reminder>"
|
|
774
|
+
if (!COMPACT_FILE.test(opening) && !COMPACT_READ.test(opening)) return null
|
|
775
|
+
if (compactContext(opening) === opening) return null
|
|
776
|
+
for (const part of parts.slice(1)) {
|
|
777
|
+
if (HOOK_NOTIFICATION.test(part.replace(/^<system-reminder>\n/, ""))) return null
|
|
778
|
+
if (SYSTEM_ENV_CONTEXT.test(part + "\n") || /^<total_tokens>\d+ tokens left<\/total_tokens>$/.test(part)) return announcedContext(text, 0)
|
|
779
|
+
}
|
|
780
|
+
return null
|
|
781
|
+
}
|
|
782
|
+
|
|
750
783
|
function generatedContext(text) {
|
|
751
784
|
const environment = SYSTEM_ENV_CONTEXT.test(text)
|
|
752
785
|
if (!environment && !((SYSTEM_MODEL_UPDATE.test(text) || SYSTEM_ENV_UPDATE.test(text)) && SYSTEM_TOKEN_CONTEXT.test(text))) return text
|
|
@@ -801,6 +834,8 @@ function compactContext(text, quoteChangedFiles = true) {
|
|
|
801
834
|
// A translating gateway can fold an announced system turn into user text.
|
|
802
835
|
if (SYSTEM_TOKEN_OPENING.test(text) || SYSTEM_SKILL_CONTEXT.test(text)) return announcedContext(text)
|
|
803
836
|
if (HOOK_OUTPUT.test(text) || text.startsWith(DEFERRED_TOOLS_OPENING)) return systemContext(text)
|
|
837
|
+
const restored = restoredContext(text)
|
|
838
|
+
if (restored !== null) return restored
|
|
804
839
|
const result = readResultText(text)
|
|
805
840
|
if (result !== null) return result
|
|
806
841
|
const changedFile = quoteChangedFiles && text.startsWith("<system-reminder>\n") ? changedFileText(text) : null
|
|
@@ -949,7 +984,7 @@ function anthropicBody(body) {
|
|
|
949
984
|
|
|
950
985
|
for (const message of request.messages) {
|
|
951
986
|
if (message?.role === "system" && typeof message.content === "string") {
|
|
952
|
-
const adapted = clientOpening(systemContext(message.content))
|
|
987
|
+
const adapted = bareSkills(clientOpening(systemContext(message.content)))
|
|
953
988
|
if (adapted !== message.content) {
|
|
954
989
|
message.content = adapted
|
|
955
990
|
changed = true
|
|
@@ -962,7 +997,7 @@ function anthropicBody(body) {
|
|
|
962
997
|
if (message?.role === "system" && Array.isArray(message.content)) {
|
|
963
998
|
for (const block of message.content) {
|
|
964
999
|
if (block?.type !== "text" || typeof block.text !== "string") continue
|
|
965
|
-
const adapted = clientOpening(systemContext(block.text))
|
|
1000
|
+
const adapted = bareSkills(clientOpening(systemContext(block.text)))
|
|
966
1001
|
if (adapted !== block.text) {
|
|
967
1002
|
block.text = adapted
|
|
968
1003
|
changed = true
|
|
@@ -1034,6 +1069,14 @@ function anthropicBody(body) {
|
|
|
1034
1069
|
}
|
|
1035
1070
|
}
|
|
1036
1071
|
}
|
|
1072
|
+
// Factory's streaming route refuses context_management ("Extra inputs
|
|
1073
|
+
// are not permitted", #71) while its non-streaming route takes it. A
|
|
1074
|
+
// streamed request goes without it: the server then edits nothing out of
|
|
1075
|
+
// the context, and the client's own compaction still runs.
|
|
1076
|
+
if (request.stream === true && "context_management" in request) {
|
|
1077
|
+
delete request.context_management
|
|
1078
|
+
changed = true
|
|
1079
|
+
}
|
|
1037
1080
|
return changed ? JSON.stringify(request) : body
|
|
1038
1081
|
}
|
|
1039
1082
|
|