@magpie-community/opencode-factory-auth 0.1.23 → 0.1.24
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 +24 -8
- package/index.mjs +74 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -129,10 +129,23 @@ continuation instructions; context without those phrases stays verbatim.
|
|
|
129
129
|
Complete generated reminders for restored Read calls and omitted files are
|
|
130
130
|
adapted too. Read arguments and file paths are preserved; quoted or incomplete
|
|
131
131
|
reminders are left alone.
|
|
132
|
+
Claude Code (2.1.291 and later) also restores skills invoked before compaction
|
|
133
|
+
as one generated reminder. Factory refuses that fixed opening, and the restored
|
|
134
|
+
skill text can quote the same client phrases as tool output. A complete
|
|
135
|
+
reminder has its opening sentence rephrased. When its skill text quotes a
|
|
136
|
+
refused phrase, that text is encoded as a JSON string with explicit skill-text
|
|
137
|
+
decoding instructions; decoding restores the skill text exactly. Skill text
|
|
138
|
+
without those phrases stays verbatim inside the rephrased reminder. Pasted
|
|
139
|
+
fragments and incomplete reminders are left untouched.
|
|
132
140
|
Claude Code can also combine reminders into a token-prefixed `system` turn
|
|
133
141
|
without the reminder wrappers. The adapter handles the known metadata
|
|
134
|
-
paragraphs in that form, including skill-list updates
|
|
135
|
-
|
|
142
|
+
paragraphs in that form, including skill-list updates and complete
|
|
143
|
+
invoked-skills reminders. A complete reminder is the fixed opening sentence
|
|
144
|
+
followed by the complete `IMPORTANT:` paragraph; skill text then runs until
|
|
145
|
+
the next known attachment (a token marker, hook, restored Read, omitted-file
|
|
146
|
+
note, Read result, environment, model line, skill-list header, changed-file
|
|
147
|
+
note, agent-type list or MCP server instructions) or the end of the turn.
|
|
148
|
+
Numbered file contents, token markers and SessionStart hook output stay.
|
|
136
149
|
The same adaptation applies when a translating gateway folds that complete
|
|
137
150
|
token-prefixed block into a user message.
|
|
138
151
|
Standalone skill updates can instead start with the generated skill-list
|
|
@@ -148,12 +161,15 @@ the complete skill-header and bullet-list paragraphs inside a token-terminated
|
|
|
148
161
|
bundle. It preserves MCP connection errors, other notifications, mode updates
|
|
149
162
|
and custom skill descriptions while adapting the known built-in description.
|
|
150
163
|
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
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
164
|
+
runtime context as one turn that opens with an unwrapped restored-file note,
|
|
165
|
+
Read call or complete invoked-skills reminder, with no token marker first.
|
|
166
|
+
A complete skills reminder is recognized even when no files were restored
|
|
167
|
+
and no environment or token paragraph follows it. A restored-file opening
|
|
168
|
+
requires the generated environment paragraph, a token marker or a complete
|
|
169
|
+
skills reminder before any hook output. Each fixed paragraph (file notes,
|
|
170
|
+
Read calls and results, skills, environment, model line) is adapted as in a
|
|
171
|
+
token-prefixed bundle; everything else stays byte-for-byte. Quoted,
|
|
172
|
+
incomplete and hook-owned forms are left alone.
|
|
157
173
|
|
|
158
174
|
Factory can also refuse fixed client phrases quoted in tool results, such as
|
|
159
175
|
the identity/environment definitions printed when inspecting this plugin's
|
package/index.mjs
CHANGED
|
@@ -736,6 +736,22 @@ function announcedContext(text, start = 1) {
|
|
|
736
736
|
// Any hook owns its file snippets. Non-startup hooks do not stop the
|
|
737
737
|
// existing adaptation of model/environment metadata that follows them.
|
|
738
738
|
if (HOOK_NOTIFICATION.test(hook)) quoteChangedFiles = false
|
|
739
|
+
// Invoked skills span several paragraphs. The refused text is the fixed
|
|
740
|
+
// opening plus the complete IMPORTANT paragraph; skill bodies follow
|
|
741
|
+
// until the next attachment this adapter already knows. A token marker
|
|
742
|
+
// after the reminder is not required: Claude Code emits one after a tool
|
|
743
|
+
// result or a user prompt, and the restored reminder usually sits among
|
|
744
|
+
// other attachments. Keep skill text out of the paragraph adapter,
|
|
745
|
+
// including on a second pass.
|
|
746
|
+
if (part.startsWith(INVOKED_SKILLS_OPENING + " ") || part.startsWith(INVOKED_SKILLS_COMPAT + " ")) {
|
|
747
|
+
let end = i + 1
|
|
748
|
+
while (end < parts.length && !invokedSkillsBoundary(parts[end])) end++
|
|
749
|
+
const wrapped = open + parts.slice(i, end).join("\n\n") + close
|
|
750
|
+
if (invokedSkillsMatch(wrapped)) {
|
|
751
|
+
parts.splice(i, end - i, invokedSkills(wrapped).slice(open.length, -close.length))
|
|
752
|
+
continue
|
|
753
|
+
}
|
|
754
|
+
}
|
|
739
755
|
const changedFile = quoteChangedFiles ? changedFileText(part) : null
|
|
740
756
|
if (changedFile !== null) {
|
|
741
757
|
parts[i] = changedFile
|
|
@@ -763,19 +779,30 @@ function announcedContext(text, start = 1) {
|
|
|
763
779
|
// opening token marker: restored-file notes, Read calls and their results,
|
|
764
780
|
// the environment, the model line, token and date. Each fixed fragment is
|
|
765
781
|
// refused on its own (plugins#68). Require the generated restored-file
|
|
766
|
-
// opening and the generated environment paragraph
|
|
767
|
-
//
|
|
768
|
-
//
|
|
769
|
-
//
|
|
782
|
+
// opening and the generated environment paragraph, a token marker or a
|
|
783
|
+
// complete invoked-skills reminder before the first hook. When no file was
|
|
784
|
+
// restored, that complete skills reminder can itself open the turn. Each
|
|
785
|
+
// paragraph is adapted as in a token-prefixed bundle, the rest kept
|
|
786
|
+
// byte-for-byte. An adapted block no longer has its generated opening,
|
|
787
|
+
// so a second pass leaves it as it is.
|
|
770
788
|
function restoredContext(text) {
|
|
771
789
|
const parts = text.split(/\n\n(?!\.\.\. \[)/)
|
|
772
790
|
const result = parts[0].indexOf("\n" + READ_RESULT_HEADER)
|
|
773
791
|
const opening = "<system-reminder>\n" + (result < 0 ? parts[0] : parts[0].slice(0, result)) + "\n</system-reminder>"
|
|
774
|
-
|
|
775
|
-
if (
|
|
776
|
-
|
|
792
|
+
const file = COMPACT_FILE.test(opening) || COMPACT_READ.test(opening)
|
|
793
|
+
if (!file && !parts[0].startsWith(INVOKED_SKILLS_OPENING + " ")) return null
|
|
794
|
+
if (file && compactContext(opening) === opening) return null
|
|
795
|
+
for (let i = 0; i < parts.length; i++) {
|
|
796
|
+
const part = parts[i]
|
|
777
797
|
if (HOOK_NOTIFICATION.test(part.replace(/^<system-reminder>\n/, ""))) return null
|
|
778
|
-
if (
|
|
798
|
+
if (part.startsWith(INVOKED_SKILLS_OPENING + " ")) {
|
|
799
|
+
let end = i + 1
|
|
800
|
+
while (end < parts.length && !invokedSkillsBoundary(parts[end])) end++
|
|
801
|
+
const wrapped = "<system-reminder>\n" + parts.slice(i, end).join("\n\n") + "\n</system-reminder>"
|
|
802
|
+
if (invokedSkillsMatch(wrapped)) return announcedContext(text, 0)
|
|
803
|
+
if (!file) return null
|
|
804
|
+
}
|
|
805
|
+
if (i > 0 && (SYSTEM_ENV_CONTEXT.test(part + "\n") || /^<total_tokens>\d+ tokens left<\/total_tokens>$/.test(part))) return announcedContext(text, 0)
|
|
779
806
|
}
|
|
780
807
|
return null
|
|
781
808
|
}
|
|
@@ -816,6 +843,43 @@ function systemModelLine(text) {
|
|
|
816
843
|
const INSTRUCTIONS_REMINDER = "<system-reminder>\nCodebase and user instructions are shown below"
|
|
817
844
|
const GLOBAL_INSTRUCTIONS = "(user's private global instructions for all projects)"
|
|
818
845
|
|
|
846
|
+
// Claude Code (2.1.291 and later) restores skills invoked before compaction
|
|
847
|
+
// as one generated reminder. Factory refuses that fixed opening, and the restored
|
|
848
|
+
// skill text can quote the same client phrases tool output does. Keep the
|
|
849
|
+
// remaining instructions and encode only a complete reminder whose body
|
|
850
|
+
// quotes them. Pasted fragments and clean skill bodies stay verbatim.
|
|
851
|
+
const INVOKED_SKILLS_OPENING = "The following skills were invoked EARLIER in this session (before the conversation was compacted), not on the current turn."
|
|
852
|
+
const INVOKED_SKILLS_COMPAT = "Skills invoked earlier in this session are listed below for context."
|
|
853
|
+
const INVOKED_SKILLS_REMINDER = /^<system-reminder>\nThe following skills were invoked EARLIER in this session \(before the conversation was compacted\), not on the current turn\. They are shown here for context only so you remain aware of their guidelines\.\n\nIMPORTANT: Do NOT re-execute these skills or perform their one-time setup actions \(e\.g\., scheduling, creating files\) again\. Any request or argument text embedded in the skill bodies below — for example under a "## User Request" or "## Input" heading — was captured when that skill was first invoked\. It is NOT the user's current message and NOT a new request: do not act on it as if it were live\. Only continue to apply ongoing behavioral guidelines from these skills where still relevant\.\n\n([\s\S]*)\n<\/system-reminder>$/
|
|
854
|
+
// The next paragraph of a bundle that already belongs to another attachment.
|
|
855
|
+
// Skill text ends here, so a following Read, environment or hook stays its
|
|
856
|
+
// own paragraph. A skill body that merely quotes one of these stays inside.
|
|
857
|
+
function invokedSkillsBoundary(part) {
|
|
858
|
+
if (SYSTEM_TOKEN_CONTEXT.test(part) || part.startsWith("<total_tokens>") || HOOK_NOTIFICATION.test(part)) return true
|
|
859
|
+
if (part.startsWith("Called the Read tool with the following input: ")) return true
|
|
860
|
+
if (part.startsWith("Note: ") && part.includes(" was read before the last conversation was summarized")) return true
|
|
861
|
+
if (part.startsWith("Result of calling the Read tool:\n")) return true
|
|
862
|
+
if (SYSTEM_ENV_CONTEXT.test(part + "\n") || SYSTEM_ENV_UPDATE.test(part + "\n")) return true
|
|
863
|
+
if (SYSTEM_MODEL_UPDATE.test(part)) return true
|
|
864
|
+
if (part === "The following skills are available for use with the Skill tool:") return true
|
|
865
|
+
if (part.startsWith("Available agent types for the Agent tool:")) return true
|
|
866
|
+
if (part.startsWith("# MCP Server Instructions")) return true
|
|
867
|
+
if (CHANGED_FILE_HEADER.test(part)) return true
|
|
868
|
+
return false
|
|
869
|
+
}
|
|
870
|
+
function invokedSkillsMatch(text) {
|
|
871
|
+
const opening = "<system-reminder>\n" + INVOKED_SKILLS_COMPAT
|
|
872
|
+
const generated = text.startsWith(opening) ? "<system-reminder>\n" + INVOKED_SKILLS_OPENING + text.slice(opening.length) : text
|
|
873
|
+
return generated.match(INVOKED_SKILLS_REMINDER)
|
|
874
|
+
}
|
|
875
|
+
function invokedSkills(text) {
|
|
876
|
+
const match = invokedSkillsMatch(text)
|
|
877
|
+
if (!match) return text
|
|
878
|
+
const quoted = quotedToolText(match[1], "Skill text encoded as a JSON string. Decode the JSON string to recover the exact original text before using it:\n")
|
|
879
|
+
const head = text.slice(0, text.length - match[1].length - "\n</system-reminder>".length)
|
|
880
|
+
return head.replace(INVOKED_SKILLS_OPENING, INVOKED_SKILLS_COMPAT) + quoted + "\n</system-reminder>"
|
|
881
|
+
}
|
|
882
|
+
|
|
819
883
|
// Factory returns 403 for Claude Code's fixed compaction opening, even
|
|
820
884
|
// without tools or other history. Match the two generated opening sentences,
|
|
821
885
|
// including the provenance prefix, without requiring a Summary label. Keep
|
|
@@ -849,6 +913,8 @@ function compactContext(text, quoteChangedFiles = true) {
|
|
|
849
913
|
}
|
|
850
914
|
const summary = piSummary(text)
|
|
851
915
|
if (summary !== text) return summary
|
|
916
|
+
const skills = invokedSkills(text)
|
|
917
|
+
if (skills !== text) return skills
|
|
852
918
|
const read = text.match(COMPACT_READ)
|
|
853
919
|
if (read) {
|
|
854
920
|
try {
|