@magpie-community/opencode-factory-auth 0.1.23 → 0.1.25

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.
Files changed (3) hide show
  1. package/README.md +26 -10
  2. package/index.mjs +80 -9
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -63,9 +63,9 @@ Each model is served on the one API droid uses for it:
63
63
 
64
64
  | API | Models |
65
65
  |---|---|
66
- | Anthropic Messages (`/api/llm/a`) | Fable 5.1, Fable 5, Opus 5.5, Opus 5, Opus 4.8, Sonnet 5.5, Sonnet 5, Sonnet 4.6, Haiku 4.5, MiniMax M2.7 |
66
+ | Anthropic Messages (`/api/llm/a`) | Fable 5.1, Fable 5, Opus 5.5, Opus 5, Opus 4.8, Sonnet 5.5, Sonnet 5, Sonnet 4.6, Haiku 5.5, Haiku 4.5, MiniMax M2.7 |
67
67
  | OpenAI Responses (`/api/llm/o/v1`) | GPT-6.1 Sol, GPT-6 Sol/Astra/Luna, GPT-5.6 Sol/Terra/Luna, GPT-5.5, GPT-5.4, GPT-5.3-Codex, Grok 4.7, Grok 4.6 |
68
- | Chat completions (`/api/llm/o/v1`) | GLM-5.3, GLM-5.3-Flash, GLM-5.2, Kimi K3, DeepSeek V4.1 Flash, Qwen3.8 Max, MiniMax M3, Mistral Medium 3.5, Nemotron 3 Ultra |
68
+ | Chat completions (`/api/llm/o/v1`) | GLM-5.3, GLM-5.3-Flash, GLM-5.2, Kimi K3, DeepSeek V4.1 Flash, Qwen3.8 Max, MiniMax M3, Mistral Large 4, Mistral Medium 3.5, Nemotron 3 Ultra |
69
69
 
70
70
  Reasoning efforts are the variants droid offers for each model. DeepSeek V4.1
71
71
  Flash, Kimi K3 and GLM-5.2 have `none`, droid's "off": they stop thinking.
@@ -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, while retaining
135
- numbered file contents, token markers and SessionStart hook output.
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 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.
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
@@ -35,7 +35,10 @@ const E4 = ["low", "medium", "high", "xhigh"]
35
35
  // The models droid's /model picker offers, less Gemini's (sent on a route of
36
36
  // Factory's own) and auto (droid picks it client side): id, name, the wire
37
37
  // droid sends it on, the vendor it names in x-api-provider, context, output,
38
- // reasoning efforts, images.
38
+ // reasoning efforts, images. Haiku 5.5 and Mistral Large 4 are droid
39
+ // 0.240.0's (models.test.mjs reads its registry); GPT-6 Astra Ultra Fast,
40
+ // new there too, stays out: droid offers it only after the user accepts
41
+ // Factory's high-cost terms for it (explicitOptInRequirement).
39
42
  const MODELS = [
40
43
  ["claude-fable-5.1", "Fable 5.1", ANTHROPIC, "anthropic", 867000, 128000, E5, true],
41
44
  ["claude-fable-5", "Fable 5", ANTHROPIC, "anthropic", 867000, 128000, E5, true],
@@ -45,6 +48,7 @@ const MODELS = [
45
48
  ["claude-sonnet-5-5", "Sonnet 5.5", ANTHROPIC, "anthropic", 872000, 128000, E5, true],
46
49
  ["claude-sonnet-5", "Sonnet 5", ANTHROPIC, "anthropic", 872000, 128000, E5, true],
47
50
  ["claude-sonnet-4-6", "Sonnet 4.6", ANTHROPIC, "anthropic", 931000, 64000, ["low", "medium", "high", "max"], true],
51
+ ["claude-haiku-5-5", "Haiku 5.5", ANTHROPIC, "anthropic", 872000, 128000, E5, true],
48
52
  ["claude-haiku-4-5-20251001", "Haiku 4.5", ANTHROPIC, "anthropic", 0, 0, ["low", "medium", "high"], true],
49
53
  ["gpt-6.1-sol", "GPT-6.1 Sol", RESPONSES, "openai", 1050000, 128000, E5, true],
50
54
  ["gpt-6-sol", "GPT-6 Sol", RESPONSES, "openai", 1050000, 128000, E6, true],
@@ -69,6 +73,7 @@ const MODELS = [
69
73
  ["qwen3.8-max", "Qwen3.8 Max", CHAT, "fireworks", 262144, 131072, ["low", "medium", "xhigh"], false],
70
74
  ["minimax-m3", "MiniMax M3", CHAT, "fireworks", 512000, 64000, ["high"], true],
71
75
  ["minimax-m2.7", "MiniMax M2.7", ANTHROPIC, "fireworks", 196600, 64000, ["high"], false],
76
+ ["mistral-large-4", "Mistral Large 4", CHAT, "mistral", 524288, 64000, ["high"], true],
72
77
  ["mistral-medium-3.5", "Mistral Medium 3.5", CHAT, "mistral", 256000, 64000, ["high"], true],
73
78
  ["nemotron-3-ultra", "Nemotron 3 Ultra", CHAT, "baseten", 202000, 65536, ["high"], false],
74
79
  ].map(([id, name, wire, upstream, context, output, efforts, images]) => ({ id, name, wire, upstream, context, output, efforts, images }))
@@ -736,6 +741,22 @@ function announcedContext(text, start = 1) {
736
741
  // Any hook owns its file snippets. Non-startup hooks do not stop the
737
742
  // existing adaptation of model/environment metadata that follows them.
738
743
  if (HOOK_NOTIFICATION.test(hook)) quoteChangedFiles = false
744
+ // Invoked skills span several paragraphs. The refused text is the fixed
745
+ // opening plus the complete IMPORTANT paragraph; skill bodies follow
746
+ // until the next attachment this adapter already knows. A token marker
747
+ // after the reminder is not required: Claude Code emits one after a tool
748
+ // result or a user prompt, and the restored reminder usually sits among
749
+ // other attachments. Keep skill text out of the paragraph adapter,
750
+ // including on a second pass.
751
+ if (part.startsWith(INVOKED_SKILLS_OPENING + " ") || part.startsWith(INVOKED_SKILLS_COMPAT + " ")) {
752
+ let end = i + 1
753
+ while (end < parts.length && !invokedSkillsBoundary(parts[end])) end++
754
+ const wrapped = open + parts.slice(i, end).join("\n\n") + close
755
+ if (invokedSkillsMatch(wrapped)) {
756
+ parts.splice(i, end - i, invokedSkills(wrapped).slice(open.length, -close.length))
757
+ continue
758
+ }
759
+ }
739
760
  const changedFile = quoteChangedFiles ? changedFileText(part) : null
740
761
  if (changedFile !== null) {
741
762
  parts[i] = changedFile
@@ -763,19 +784,30 @@ function announcedContext(text, start = 1) {
763
784
  // opening token marker: restored-file notes, Read calls and their results,
764
785
  // the environment, the model line, token and date. Each fixed fragment is
765
786
  // 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.
787
+ // opening and the generated environment paragraph, a token marker or a
788
+ // complete invoked-skills reminder before the first hook. When no file was
789
+ // restored, that complete skills reminder can itself open the turn. Each
790
+ // paragraph is adapted as in a token-prefixed bundle, the rest kept
791
+ // byte-for-byte. An adapted block no longer has its generated opening,
792
+ // so a second pass leaves it as it is.
770
793
  function restoredContext(text) {
771
794
  const parts = text.split(/\n\n(?!\.\.\. \[)/)
772
795
  const result = parts[0].indexOf("\n" + READ_RESULT_HEADER)
773
796
  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)) {
797
+ const file = COMPACT_FILE.test(opening) || COMPACT_READ.test(opening)
798
+ if (!file && !parts[0].startsWith(INVOKED_SKILLS_OPENING + " ")) return null
799
+ if (file && compactContext(opening) === opening) return null
800
+ for (let i = 0; i < parts.length; i++) {
801
+ const part = parts[i]
777
802
  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)
803
+ if (part.startsWith(INVOKED_SKILLS_OPENING + " ")) {
804
+ let end = i + 1
805
+ while (end < parts.length && !invokedSkillsBoundary(parts[end])) end++
806
+ const wrapped = "<system-reminder>\n" + parts.slice(i, end).join("\n\n") + "\n</system-reminder>"
807
+ if (invokedSkillsMatch(wrapped)) return announcedContext(text, 0)
808
+ if (!file) return null
809
+ }
810
+ if (i > 0 && (SYSTEM_ENV_CONTEXT.test(part + "\n") || /^<total_tokens>\d+ tokens left<\/total_tokens>$/.test(part))) return announcedContext(text, 0)
779
811
  }
780
812
  return null
781
813
  }
@@ -816,6 +848,43 @@ function systemModelLine(text) {
816
848
  const INSTRUCTIONS_REMINDER = "<system-reminder>\nCodebase and user instructions are shown below"
817
849
  const GLOBAL_INSTRUCTIONS = "(user's private global instructions for all projects)"
818
850
 
851
+ // Claude Code (2.1.291 and later) restores skills invoked before compaction
852
+ // as one generated reminder. Factory refuses that fixed opening, and the restored
853
+ // skill text can quote the same client phrases tool output does. Keep the
854
+ // remaining instructions and encode only a complete reminder whose body
855
+ // quotes them. Pasted fragments and clean skill bodies stay verbatim.
856
+ const INVOKED_SKILLS_OPENING = "The following skills were invoked EARLIER in this session (before the conversation was compacted), not on the current turn."
857
+ const INVOKED_SKILLS_COMPAT = "Skills invoked earlier in this session are listed below for context."
858
+ 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>$/
859
+ // The next paragraph of a bundle that already belongs to another attachment.
860
+ // Skill text ends here, so a following Read, environment or hook stays its
861
+ // own paragraph. A skill body that merely quotes one of these stays inside.
862
+ function invokedSkillsBoundary(part) {
863
+ if (SYSTEM_TOKEN_CONTEXT.test(part) || part.startsWith("<total_tokens>") || HOOK_NOTIFICATION.test(part)) return true
864
+ if (part.startsWith("Called the Read tool with the following input: ")) return true
865
+ if (part.startsWith("Note: ") && part.includes(" was read before the last conversation was summarized")) return true
866
+ if (part.startsWith("Result of calling the Read tool:\n")) return true
867
+ if (SYSTEM_ENV_CONTEXT.test(part + "\n") || SYSTEM_ENV_UPDATE.test(part + "\n")) return true
868
+ if (SYSTEM_MODEL_UPDATE.test(part)) return true
869
+ if (part === "The following skills are available for use with the Skill tool:") return true
870
+ if (part.startsWith("Available agent types for the Agent tool:")) return true
871
+ if (part.startsWith("# MCP Server Instructions")) return true
872
+ if (CHANGED_FILE_HEADER.test(part)) return true
873
+ return false
874
+ }
875
+ function invokedSkillsMatch(text) {
876
+ const opening = "<system-reminder>\n" + INVOKED_SKILLS_COMPAT
877
+ const generated = text.startsWith(opening) ? "<system-reminder>\n" + INVOKED_SKILLS_OPENING + text.slice(opening.length) : text
878
+ return generated.match(INVOKED_SKILLS_REMINDER)
879
+ }
880
+ function invokedSkills(text) {
881
+ const match = invokedSkillsMatch(text)
882
+ if (!match) return text
883
+ 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")
884
+ const head = text.slice(0, text.length - match[1].length - "\n</system-reminder>".length)
885
+ return head.replace(INVOKED_SKILLS_OPENING, INVOKED_SKILLS_COMPAT) + quoted + "\n</system-reminder>"
886
+ }
887
+
819
888
  // Factory returns 403 for Claude Code's fixed compaction opening, even
820
889
  // without tools or other history. Match the two generated opening sentences,
821
890
  // including the provenance prefix, without requiring a Summary label. Keep
@@ -849,6 +918,8 @@ function compactContext(text, quoteChangedFiles = true) {
849
918
  }
850
919
  const summary = piSummary(text)
851
920
  if (summary !== text) return summary
921
+ const skills = invokedSkills(text)
922
+ if (skills !== text) return skills
852
923
  const read = text.match(COMPACT_READ)
853
924
  if (read) {
854
925
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magpie-community/opencode-factory-auth",
3
- "version": "0.1.23",
3
+ "version": "0.1.25",
4
4
  "description": "Sign in to a Factory (Droid) subscription from OpenCode or magpie",
5
5
  "type": "module",
6
6
  "main": "./index.mjs",