tweakcc-fixed 2.8.33 → 2.8.34
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 +3 -3
- package/dist/{config-C9otuZ77.mjs → config-BtsLmuMm.mjs} +5 -5
- package/dist/{content-9sLxokYs.mjs → content-BaKE4TNH.mjs} +1 -1
- package/dist/index.mjs +1 -1
- package/dist/lib/index.mjs +1 -1
- package/dist/{nativeInstallation-3XrBDjAe.mjs → nativeInstallation-B2MV4mSJ.mjs} +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
[](https://www.npmjs.com/package/tweakcc-fixed)
|
|
8
8
|
[](https://www.npmjs.com/package/tweakcc-fixed)
|
|
9
|
-
[](https://github.com/anthropics/claude-code)
|
|
10
10
|
[](#credit--license)
|
|
11
11
|
|
|
12
12
|
**[Install](#install) · [Customize](#what-you-can-customize) · [The fork](#what-this-fork-adds) · [How it works](#how-it-works)**
|
|
@@ -57,8 +57,8 @@ The biggest difference is coverage. Its extractor pulls over ten times the promp
|
|
|
57
57
|
|
|
58
58
|
| | tweakcc-fixed | upstream |
|
|
59
59
|
| ---------------------------- | :-----------: | :-------: |
|
|
60
|
-
| Prompt sites (CC 2.1.
|
|
61
|
-
| Unique prompt IDs | **9,
|
|
60
|
+
| Prompt sites (CC 2.1.288) | **10,388** | 827 |
|
|
61
|
+
| Unique prompt IDs | **9,883** | 827 |
|
|
62
62
|
| Patches | **64** | 49 |
|
|
63
63
|
| Overrides on native installs | **yes** | gated off |
|
|
64
64
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{createRequire as e}from"node:module";import t from"chalk";import*as n from"node:os";import r,{EOL as i}from"node:os";import*as a from"node:fs/promises";import o from"node:fs/promises";import*as s from"node:fs";import c,{createReadStream as l}from"node:fs";import*as u from"node:path";import d from"node:path";import*as f from"fs";import*as p from"path";import*as m from"os";import*as h from"child_process";import*as g from"crypto";import{execFile as _,spawnSync as v}from"node:child_process";import y from"gray-matter";import*as b from"node:crypto";import{randomUUID as x}from"node:crypto";import{fileURLToPath as S}from"node:url";import{Worker as C}from"node:worker_threads";import{diffWordsWithSpace as w}from"diff";const T=e(import.meta.url),E=(()=>{try{return T(`../package.json`)}catch{return T(`../../package.json`)}})(),D=E.version,O=E.supportedClaudeCode;let k=null;async function A(){if(k!==null)return k;try{return await import(`node-lief`),k=await import(`./nativeInstallation-
|
|
1
|
+
import{createRequire as e}from"node:module";import t from"chalk";import*as n from"node:os";import r,{EOL as i}from"node:os";import*as a from"node:fs/promises";import o from"node:fs/promises";import*as s from"node:fs";import c,{createReadStream as l}from"node:fs";import*as u from"node:path";import d from"node:path";import*as f from"fs";import*as p from"path";import*as m from"os";import*as h from"child_process";import*as g from"crypto";import{execFile as _,spawnSync as v}from"node:child_process";import y from"gray-matter";import*as b from"node:crypto";import{randomUUID as x}from"node:crypto";import{fileURLToPath as S}from"node:url";import{Worker as C}from"node:worker_threads";import{diffWordsWithSpace as w}from"diff";const T=e(import.meta.url),E=(()=>{try{return T(`../package.json`)}catch{return T(`../../package.json`)}})(),D=E.version,O=E.supportedClaudeCode;let k=null;async function A(){if(k!==null)return k;try{return await import(`node-lief`),k=await import(`./nativeInstallation-B2MV4mSJ.mjs`),k}catch(e){return J(`Error loading native installation module: ${e instanceof Error?e.message:String(e)}`),e instanceof Error&&J(e),null}}async function j(e,t){let n=await A();return n?n.extractClaudeJsFromNativeInstallation(e,t):{data:null,clearBytecode:!1,error:`node-lief native module unavailable on this platform/runtime (cannot extract from native installs)`}}async function M(e,t,n,r){let i=await A();if(!i)throw Error("`repackNativeInstallation()` called but `node-lief` is not available. This is unexpected - `extractClaudeJsFromNativeInstallation()` should have been called first.");i.repackNativeInstallation(e,t,n,r)}async function N(e){let t=await A();return t?t.resolveNixBinaryWrapper(e):null}const ee=[{id:`routine`,label:`Routine`,effort:`low`,help:`The requested result and method are already clear. The remaining work needs little inference; correctness is readily checked against supplied facts or an established procedure. Further investigation is unnecessary.`},{id:`standard`,label:`Standard`,effort:`medium`,help:`The normal working budget for substantive day-to-day work. Some judgment, information gathering and validation are needed, but ordinary investigation and checks can complete the requested scope. A task need not be trivial or fully specified to fit this level.`},{id:`hard`,label:`Hard`,effort:`high`,help:`Additional independent judgment or verification is materially necessary. Interacting uncertainties or hidden failure modes warrant deeper investigation and cross-checking than ordinary work, even if the overall method is known. More effort is expected to improve correctness, not simply expand the scope.`},{id:`frontier`,label:`Frontier`,effort:`max`,help:`A demanding end-to-end handoff warrants the greatest independent judgment, persistence and extensive verification, with little user iteration to catch omissions. Substantial difficulty remains that high effort is unlikely to resolve adequately. Mere breadth or importance is insufficient; an explicit maximum-effort preference also qualifies.`}],te=`You are a difficulty router for an AI coding agent. Each turn you get a compact running SUMMARY of the session, a CONTEXT block (the model in use and the level you assigned last turn), the most recent exchange (the previous user message and the assistant reply), and the user NEW message. Do two things and output ONLY a JSON object with the keys level and summary - no prose, no code fence.
|
|
2
2
|
|
|
3
3
|
# level
|
|
4
4
|
Pick the integer effort level (0 = least effort, {MAX} = most) for the NEW message, judged IN CONTEXT of the summary, the context block, and the recent exchange:
|
|
@@ -780,7 +780,7 @@ const filtered=chunk
|
|
|
780
780
|
return _origStdoutWrite.call(process.stdout,filtered,encoding,cb);
|
|
781
781
|
};
|
|
782
782
|
// SCROLLING FIX PATCH END
|
|
783
|
-
`,r=e.slice(0,t)+n+e.slice(t);return B(e,r,n,t,t),r},is=e=>{let t=e.match(/function [$\w]+\(\)\{return [$\w]+\("tengu_worktree_mode"/);if(!t||t.index===void 0)return e.includes(`EnterWorktree`)?(console.log(`patch: worktreeMode: EnterWorktree present, tengu_worktree_mode gate gone — no-op`),e):(console.error(`patch: worktreeMode: failed to find worktree gate function pattern`),null);let n=t.index+t[0].indexOf(`{`)+1,r=`return !0;`,i=e.slice(0,n)+r+e.slice(n);return B(e,i,r,n,n),i},as=e=>{let t=/(\{name:"(?:cc-plugin-)?responsive-mode",description:)("(?:[^"\\]|\\.)*")((?:,defaultEnabled:![01])?,isAvailable:([$\w]+)(?:,defaultEnabled:![01])?\})/,n=e.match(t);if(!n||n.index===void 0)return/"(?:cc-plugin-)?responsive-mode"/.test(e)?(console.error(`patch: responsiveMode: failed to find the responsive-mode plugin listing`),null):(console.log(`patch: responsiveMode: this CC build ships no responsive-mode plugin — no-op`),e);let r=n[4].replace(/[$]/g,`\\$`);if(RegExp(`var ${r}=\\(\\)=>(?:!?[$\\w]+\\(\\)&&)*!?[$\\w]+\\(\\);`).test(e)&&n[0].includes(`defaultEnabled`))return e;let i=[RegExp(`(var ${r}=\\(\\)=>)((?:!?[$\\w]+\\(\\)&&)*!?[$\\w]+\\(\\))&&[$\\w]+\\("([a-z0-9_]+)",[$\\w]+\\(\\)\\);`),RegExp(`(var ${r}=\\(\\)=>)([$\\w]+\\(\\))&&[$\\w]+\\("([a-z0-9_]+)",[$\\w]+\\(\\)\\);`)],a=null;for(let t of i)if(a=e.match(t),a)break;if(!a||a.index===void 0)return console.error(`patch: responsiveMode: failed to find the responsive-mode availability gate`),null;let o=e,s=`${a[1]}${a[2]};`;o=o.slice(0,a.index)+s+o.slice(a.index+a[0].length),B(e,o,s,a.index,a.index+a[0].length);let c=o.match(t);if(!c||c.index===void 0)return console.error(`patch: responsiveMode: listing vanished after the gate rewrite`),null;if(!c[0].includes(`defaultEnabled`)){let e=o,t=`${c[1]}${c[2]},defaultEnabled:!1${c[3]}`;o=o.slice(0,c.index)+t+o.slice(c.index+c[0].length),B(e,o,t,c.index,c.index+c[0].length)}return o},os=e=>{let t=e,n=t.match(/,model:([$\w]+)\.enum\(([$\w]+)\)\.optional\(\)/);if(!n||n.index===void 0)return t.match(/let\s+[$\w]+\s*=\s*([$\w]+)\s*&&\s*typeof\s+\1\s*===\s*"string"\s*&&\s*[$\w]+\.includes\(\1\)/)?(console.error(`patch: allowCustomAgentModels: failed to find Zod enum pattern`),null):(J(`patch: allowCustomAgentModels: enum/includes gate removed in this CC build — no-op`),t);let r=n[1],i=n[2],a=`,model:${r}.string().optional()`,o=n.index,s=o+n[0].length;t=t.slice(0,o)+a+t.slice(s),B(e,t,a,o,s);let c=i.replace(/\$/g,`\\$`),l=RegExp(`([;)}])let\\s+([\\$\\w]+)\\s*=\\s*([\\$\\w]+)\\s*&&\\s*typeof\\s+\\3\\s*===\\s*"string"\\s*&&\\s*${c}\\.includes\\(\\3\\)`),u=t,d=t.match(l);if(!d||d.index===void 0)return console.error(`patch: allowCustomAgentModels: failed to find model validation flag pattern`),null;let f=d[1],p=d[2],m=d[3],h=`${f}let ${p}=${m}&&typeof ${m}==="string"`,g=d.index,_=g+d[0].length;return t=t.slice(0,g)+h+t.slice(_),B(u,t,h,g,_),t},ss=e=>{let t=e;{let e=!1;for(let n of[`claude-opus-4-8`,`claude-opus-4-7`]){let r=RegExp(`(id:"${n}"(?:(?!id:"claude-)[\\s\\S]){0,4000}?default_effort:)"(?:high|xhigh)"`),i=t.match(r);if(i&&i.index!==void 0){let n=`${i[1]}"max"`,r=t.slice(0,i.index)+n+t.slice(i.index+i[0].length);B(t,r,n,i.index,i.index+i[0].length),t=r,e=!0}}if(e)return t;if(/id:"claude-opus-4-[78]"(?:(?!id:"claude-)[\s\S]){0,4000}?default_effort:"max"/.test(t))return J(`patch: maxEffortDefault: catalog default_effort already "max" — skipping`),t}let n=/function\s+([$\w]+)\s*\(\s*([$\w]+)\s*\)\s*\{\s*if\s*\(\s*([$\w]+)\s*\(\s*\2\s*\)\s*===\s*"claude-opus-4-7"\s*\)\s*return\s*"xhigh"\s*;\s*return\s*"high"\s*\}/,r=t.match(/function\s+([$\w]+)\s*\(\s*([$\w]+)\s*\)\s*\{\s*if\s*\(\s*([$\w]+)\s*\(\s*\2\s*\)\s*===\s*"claude-opus-4-8"\s*\)\s*return\s*"high"\s*;\s*if\s*\(\s*\3\s*\(\s*\2\s*\)\s*===\s*"claude-opus-4-7"\s*\)\s*return\s*"xhigh"\s*;\s*return\s*"high"\s*\}/),i=r||t.match(n);if(i&&i.index!==void 0){let[e,n,a,o]=i,s=r?`function ${n}(${a}){if(${o}(${a})==="claude-opus-4-8")return"max";if(${o}(${a})==="claude-opus-4-7")return"max";return"high"}`:`function ${n}(${a}){if(${o}(${a})==="claude-opus-4-7")return"max";return"high"}`,c=t.slice(0,i.index)+s+t.slice(i.index+e.length);B(t,c,s,i.index,i.index+e.length),t=c}else if(/===\s*"claude-opus-4-8"\s*\)\s*return\s*"max"/.test(t)||/function\s+[$\w]+\s*\(\s*[$\w]+\s*\)\s*\{\s*if\s*\(\s*[$\w]+\s*\(\s*[$\w]+\s*\)\s*===\s*"claude-opus-4-7"\s*\)\s*return\s*"max"\s*;\s*return\s*"high"\s*\}/.test(t))J(`patch: maxEffortDefault: per-model default already "max" — skipping`);else return console.error(`patch: maxEffortDefault: failed to find Opus per-model effort default`),null;return t},cs=e=>{let t=e.match(/function\s+([$\w]+)\s*\(\s*([$\w]+)\s*\)\s*\{\s*if\s*\(\s*\2\s*===\s*"claude-fable-5"\s*\|\|\s*\2\s*===\s*"claude-mythos-5"\s*\)\s*return\s*!0\s*;\s*return\s*!1\s*\}/)||e.match(/function\s+([$\w]+)\s*\(\s*([$\w]+)\s*\)\s*\{\s*if\s*\(\s*[$\w]+\s*\(\s*\2\s*,\s*"fable_5_mitigations"\s*\)\s*\|\|\s*\2\s*===\s*"claude-mythos-5"\s*\)\s*return\s*!0\s*;\s*return\s*!1\s*\}/)||e.match(/function\s+([$\w]+)\s*\(\s*([$\w]+)\s*(?:,\s*[$\w]+\s*)?\)\s*\{\s*if\s*\(\s*[$\w]+\s*\(\s*\2\s*,\s*"fable_5_mitigations"\s*(?:,\s*[$\w]+\s*)?\)\s*\|\|\s*\2\s*===\s*"claude-mythos-5"\s*\)\s*return\s*!0\s*;\s*return\s*!1\s*\}/)||e.match(/function\s+([$\w]+)\s*\(\s*([$\w]+)\s*(?:,\s*[$\w]+\s*)?\)\s*\{\s*let\s+([$\w]+)\s*=\s*[$\w]+\s*\(\s*\2\s*,\s*"fable_5_mitigations"\s*(?:,\s*[$\w]+\s*)?\)\s*;\s*if\s*\(\s*\3\s*!==\s*void\s*0\s*\)\s*return\s*\3\s*;\s*if\s*\(\s*\2\s*===\s*"claude-mythos-5"\s*\)\s*return\s*!0\s*;\s*return\s*!1\s*\}/);if(!t||t.index===void 0)return/"claude-mythos-5"\s*\)\s*return\s*!0\s*;\s*return\s*!0\s*\}/.test(e)?(J(`patch: autonomousOperationAllModels: model-family gate already flipped — skipping`),e):/"claude-fable-5"/.test(e)?(console.error(`patch: autonomousOperationAllModels: found the fable/mythos model ids but not the expected gate shape — needs a new match method`),null):(console.log(`patch: autonomousOperationAllModels: fable/mythos model-family gate not present in this CC build — no-op`),e);let[n]=t,r=n.replace(/return\s*!1\s*\}$/,`return!0}`),i=e.slice(0,t.index)+r+e.slice(t.index+n.length);return B(e,i,r,t.index,t.index+n.length),i},ls=`globalThis.__tweakccRefusalFallbackReturn`,us=`globalThis.__tweakccRefusalFallbackOnReturn`,ds=`globalThis.__tweakccRefusalFallbackLine`,fs=`globalThis.__tweakccRefusalFallbackMessage`,ps=`globalThis.__tweakccRefusalFallbackEvent`,ms=`__tweakccRefusalFallbackApplyOnReset`,hs=`/*@@TWEAKCC_MODULE:`,gs=(e,t)=>{let n=e.lastIndexOf(hs,t),r=e.indexOf(hs,n===-1?0:n+1);return[n===-1?0:n,r===-1?e.length:r]},_s=e=>e.replace(/\$/g,`\\$`),U=(e,t,n,r)=>{let i=e.slice(0,t)+r+e.slice(t+n);return B(e,i,r,t,t+n),i},vs=e=>{let t={},n=e.match(/function [$\w]+\(([$\w]+)\)\{return\(typeof \1==="string"\?\[\1\]:\1\)\.slice\(0,([$\w]+)\)\}/);if(n?.index!==void 0){let[r,i]=gs(e,n.index),a=e.slice(r,i).match(RegExp(`(?<![$\\w.])${_s(n[2])}=(\\d+)(?![\\d.])`));a&&(t.chainLength=Number(a[1]))}let r=e.match(/function [$\w]+\(([$\w]+)\)\{return ([$\w]+)\(\1\)\|\|([$\w]+)\(\1\)\?\1:"other"\}/);if(r?.index!==void 0){let[n,i]=gs(e,r.index),a=e.slice(n,i),o=new Set;for(let e of[r[2],r[3]]){let n=a.match(RegExp(`function ${_s(e)}\\(([$\\w]+)\\)\\{return ([^}]*)\\}`));if(!n)return t;for(let e of n[2].matchAll(RegExp(`${_s(n[1])}==="([^"]+)"`,`g`)))o.add(e[1])}o.size>0&&(t.categories=o)}return t},ys=(e,t)=>{let n=Object.create(null);if(e==null)return n;if(typeof e!=`object`||Array.isArray(e))return console.warn(`patch: refusalFallbackModel: refusalFallbackRoutes should map a refusal category to a model id or a list of them; ignoring it`),n;for(let[r,i]of Object.entries(e)){let e=Array.isArray(i)?i:[i];if(!e.every(e=>typeof e==`string`)){console.warn(`patch: refusalFallbackModel: skipping refusalFallbackRoutes.${r}: a route is a model id or a non-empty list of model ids`);continue}let a=e.map(e=>e.trim()),o=a.filter(e=>e!==``);if(o.length===0){console.warn(`patch: refusalFallbackModel: skipping refusalFallbackRoutes.${r}: a route is a model id or a non-empty list of model ids`);continue}o.length<a.length&&console.warn(`patch: refusalFallbackModel: refusalFallbackRoutes.${r} has an empty model id; skipping it`),t.categories&&!t.categories.has(r)&&console.warn(`patch: refusalFallbackModel: refusalFallbackRoutes.${r} is not a refusal category this Claude Code knows (${[...t.categories].join(`, `)}), so it never matches`),t.chainLength!==void 0&&o.length>t.chainLength&&console.warn(`patch: refusalFallbackModel: refusalFallbackRoutes.${r} lists ${o.length} models, and Claude Code tries only the first ${t.chainLength}`),n[r]=Array.isArray(i)?o:o[0]}return n},bs=e=>e===void 0?1:e===null?null:typeof e==`number`&&Number.isInteger(e)&&e>=0?e:(console.warn(`patch: refusalFallbackModel: refusalFallbackMaxReturns should be a whole number of returns or null; using 1`),1),xs=e=>{let t=e.match(/(function ([$\w]+)\(([$\w]+)\)\{let\{originalModelCanonical:([$\w]+),apiRefusalCategory:[$\w]+\}=\3,[$\w]+=)\3\.routesOverride\?\?([$\w]+)\(\4\)/);if(!t||t.index===void 0)return null;let[n,r,i,a,o,s]=t;return{index:t.index,length:n.length,head:r,walker:i,arg:a,model:o,table:s}},Ss=`((__tweakccD,__tweakccO)=>{`,Cs=e=>{let t=xs(e);if(!t)return e.includes(Ss)?(J(`patch: refusalFallbackModel: routes already merged, skipping`),e):(console.error(`patch: refusalFallbackModel: failed to find the refusal route walker`),null);let{head:n,arg:r,model:i,table:a}=t;return U(e,t.index,t.length,`${n}${Ss}let __tweakccM=Object.assign(Object.create(null),__tweakccD);if(__tweakccO)for(let __tweakccK of Object.keys(__tweakccO))__tweakccM[__tweakccK]=[...new Set([].concat(__tweakccO[__tweakccK],Object.hasOwn(__tweakccD,__tweakccK)?__tweakccD[__tweakccK]:[]))];return __tweakccM})(${a}(${i}),${r}.routesOverride)`)},ws=e=>{let t=[...e.matchAll(/function ([$\w]+)\(\)\{return\}/g)].find(t=>t[1]!==void 0&&e.includes(`routesOverride:${t[1]}()`));return!t||t.index===void 0?null:{index:t.index,length:t[0].length,name:t[1]}},Ts=(e,t)=>{let n=`{return JSON.parse(${JSON.stringify(JSON.stringify(t))})}`;if(e.includes(n))return J(`patch: refusalFallbackModel: routes already supplied, skipping`),e;let r=ws(e);return r?U(e,r.index,r.length,`function ${r.name}()${n}`):(console.error(`patch: refusalFallbackModel: failed to find the refusal routes supplier`),null)},Es=(e,t)=>`(globalThis.__tweakccRefusalFallbackHub??=new ${e}(()=>${t}()))`,Ds=(e,t,n,r,i)=>{let a=i===null?``:`if(__tweakccR.returns>=${i}){if(__tweakccR.held)return;__tweakccR.held=!0;return{held:!0,returns:__tweakccR.returns,model:__tweakccL.previousOverride??__tweakccL.previousModelForSession??__tweakccL.previousAppStateModel,fallback:__tweakccL.fallbackModel}}`;return`${us}=(__tweakccF)=>${Es(n,r)}.of(${e}()).subscribe(__tweakccF);${ls}=(__tweakccQ)=>{let __tweakccS=${e}(),__tweakccL=__tweakccS.modelSelection.refusalFallbackModelLatch(),__tweakccR=(globalThis.__tweakccRefusalFallbackRuns??=new ${n}(()=>({}))).of(__tweakccS);if(__tweakccR.session!==__tweakccS.id){__tweakccR.session=__tweakccS.id;__tweakccR.returns=0;__tweakccR.held=!1}if(!__tweakccL){if(__tweakccQ){__tweakccR.returns=0;__tweakccR.held=!1}return}`+a+`let __tweakccT=${t}();if(!__tweakccT)return;__tweakccR.returns++;${Es(n,r)}.of(__tweakccS).emit(__tweakccT);return{held:!1,returns:__tweakccR.returns,model:__tweakccT.overrideValue??__tweakccT.forSessionValue??__tweakccT.appStateModel,fallback:__tweakccT.fallbackModel}};`},Os=(e,t)=>{if(e.includes(`${ls}=`))return J(`patch: refusalFallbackModel: return already published, skipping`),e;let n=e.match(/function ([$\w]+)\(\)\{let ([$\w]+)=([$\w]+)\(\),([$\w]+)=\2\.modelSelection\.refusalFallbackModelLatch\(\);if\(\2\.modelSelection\.unlatchRefusalFallbackModel\(\),!\4\|\|\2\.modelSelection\.mainLoopModelOverride\(\)!==\4\.fallbackModel\)return;return \2\.modelSelection\.overrideMainLoopModel\(\4\.previousOverride\)/);if(!n||n.index===void 0)return console.error(`patch: refusalFallbackModel: failed to find the fallback-restore function`),null;let[r,i]=gs(e,n.index),a=[...e.slice(r,i).matchAll(/var ([$\w]+)=new ([$\w]+)\(\(\)=>([$\w]+)\(\)\);function [$\w]+\(([$\w]+)\)\{return \1\.of\(([$\w]+)\(\)\)\.subscribe\(\4\)\}/g)].find(e=>e[5]===n[3]);return a?U(e,n.index,0,Ds(n[3],n[1],a[2],a[3],t)):(console.error(`patch: refusalFallbackModel: failed to find the reset event's hub in the restore's module`),null)},ks=e=>{if(e.includes(`function ${ms}(`))return J(`patch: refusalFallbackModel: restore callbacks already subscribed, skipping`),e;let t=e.match(/function ([$\w]+)\(([$\w]+)\)\{return ([$\w]+)\(\(([$\w]+),([$\w]+),([$\w]+)\)=>\{if\(!\6\)return;([$\w]+)\(\6,\2\),[$\w]+\("tengu_refusal_fallback_latch_reset",/);if(!t||t.index===void 0)return console.error(`patch: refusalFallbackModel: failed to find the restore's app-state registration`),null;let[,n,r,i,,,,a]=t,[o,s]=gs(e,t.index),c=[...e.slice(o,s).matchAll(RegExp(`function ([$\\w]+)\\(([$\\w]+)\\)\\{return ${_s(i)}\\(\\(([$\\w]+),([$\\w]+),([$\\w]+)\\)=>\\{if\\(\\5\\)\\2\\(\\)\\}\\)\\}`,`g`))];if(c.length!==1||c[0].index===void 0)return console.error(`patch: refusalFallbackModel: failed to find headless's model-drop registration`),null;let[,l,u]=c[0],d=o+c[0].index,[f,p]=d>t.index?[{at:d,name:l,param:u,kind:`drop`},{at:t.index,name:n,param:r,kind:`apply`}]:[{at:t.index,name:n,param:r,kind:`apply`},{at:d,name:l,param:u,kind:`drop`}],m=e;for(let e of[f,p]){let t=e.kind===`apply`?ms:`__tweakccRefusalFallbackDropOnReset`,n=e.kind===`apply`?`(__tweakccT)=>${a}(__tweakccT,${e.param})`:`()=>${e.param}()`,r=`function ${e.name}(${e.param}){`;m=U(m,e.at,r.length,`${r}let __tweakccU=${t}(${e.param}),__tweakccV=${us}?.(${n});return()=>{__tweakccV?.(),__tweakccU()}}function ${t}(${e.param}){`)}return m},As=e=>{if(e.includes(`${ds}=`))return J(`patch: refusalFallbackModel: line already published, skipping`),e;let t=e.match(/function [$\w]+\(([$\w]+),([$\w]+),([$\w]+)\)\{return [$\w]+\("switched",\{model:([$\w]+)\(\1\),fallback:\2\},\1,\3\)\?\?`Switched to \$\{\2\}\.`\}/);if(!t||t.index===void 0)return console.error(`patch: refusalFallbackModel: failed to find the fallback's switch message`),null;let n=t[4],r=`${ds}=(__tweakccN)=>{let __tweakccM=__tweakccN.model==null?"the default model":${n}(__tweakccN.model),__tweakccF=${n}(__tweakccN.fallback);return __tweakccN.held?{content:"Staying on "+__tweakccF+" for this session \\xB7 "+(__tweakccN.returns?__tweakccM+" was flagged again after switching back \\xB7 ":"")+"/model to change",level:"warning"}:{content:"Switched back to "+__tweakccM+".",level:"notice"}};`;return U(e,t.index,0,r)},js=e=>{if(e.includes(`${fs}=`))return J(`patch: refusalFallbackModel: message constructor already published, skipping`),e;let t=e.match(/function ([$\w]+)\(([$\w]+),([$\w]+)\)\{return\{type:"system",subtype:"informational",content:\2,isMeta:!1,timestamp:new Date\(\)\.toISOString\(\),uuid:[$\w]+\(\),level:\3\}\}/);return!t||t.index===void 0?(console.error(`patch: refusalFallbackModel: failed to find the system-message constructor`),null):U(e,t.index,0,`${fs}=${t[1]};`)},Ms=e=>{if(e.includes(`${ps}=`))return J(`patch: refusalFallbackModel: event queue already published, skipping`),e;let t=e.match(/function [$\w]+\([$\w]+\)\{([$\w]+)\(\)\.setEnqueueListener\([$\w]+\)\}function ([$\w]+)\(([$\w]+)\)\{\1\(\)\.enqueue\(\3\)\}/);return!t||t.index===void 0?(console.error(`patch: refusalFallbackModel: failed to find the SDK event queue`),null):U(e,t.index,0,`${ps}=${t[2]};`)},Ns=e=>{let t=`}finally{try{let __tweakccN=${ls}`;if(e.includes(t))return J(`patch: refusalFallbackModel: REPL turn end already spliced, skipping`),e;let n=e.match(/([$\w.]+)=await this\._runImpl\([$\w]+,[^)]*\)\}finally\{/);if(!n||n.index===void 0)return console.error(`patch: refusalFallbackModel: failed to find the REPL's turn-end finally`),null;let r=n.index+n[0].length,i=e.slice(r,r+2e3).match(/([$\w]+)\(\{type:"append",messages:this\.stream\.pendingPreservedInsert\.preserved\}\)/);return i?U(e,r,0,`try{let __tweakccN=${ls}?.(${n[1]}?.num_turns>0);if(__tweakccN){let __tweakccL=${ds}?.(__tweakccN),__tweakccM=__tweakccL&&${fs}?.(__tweakccL.content,__tweakccL.level);if(__tweakccM)${i[1]}({type:"append",messages:[__tweakccM]})}}catch{}`):(console.error(`patch: refusalFallbackModel: failed to find the REPL's transcript append`),null)},Ps=e=>{let t=e.match(/noteTurnEnded\(([$\w]+),([$\w]+),([$\w]+)\)\{if\(this\.selector\.noteTurnEnded\(\1\),\1\|\|\3\.num_turns>0\)\{/);return!t||t.index===void 0?/noteTurnEnded\([$\w]+,[$\w]+,[$\w]+\)\{try\{let __tweakccN=/.test(e)?(J(`patch: refusalFallbackModel: headless turn end already spliced, skipping`),e):(console.error(`patch: refusalFallbackModel: failed to find the dispatcher's noteTurnEnded`),null):U(e,t.index+`noteTurnEnded(${t[1]},${t[2]},${t[3]}){`.length,0,`try{let __tweakccN=${ls}?.(${t[3]}?.num_turns>0);if(__tweakccN){let __tweakccL=${ds}?.(__tweakccN);if(__tweakccL)${ps}?.({type:"system",subtype:"informational",content:__tweakccL.content,level:__tweakccL.level})}}catch{}`)},Fs=(e,t={},n=1)=>{let r=bs(n),i=ys(t,vs(e)),a=[Cs,e=>Ts(e,i),e=>Os(e,r),ks,As,js,Ms,Ns,Ps],o=e;for(let e of a)if(o=e(o),o===null)return null;return o},Is=e=>{let t=e,n=t.match(/\(\{filePath:([$\w]+),frontmatter:([$\w]+),content:([$\w]+),source:([$\w]+),baseDir:([$\w]+)\}\)=>\{([\s\S]{0,800}?)return\{name:([$\w]+),description:([$\w]+),prompt:\3\.trim\(\),source:\4,baseDir:\5,keepCodingInstructions:([$\w]+)\}/);if(n&&n.index!==void 0){let e=n[2],r=`,turnReminder:typeof ${e}["turn-reminder"]==="string"?${e}["turn-reminder"]:typeof ${e}.turnReminder==="string"?${e}.turnReminder:typeof ${e}.turnreminder==="string"?${e}.turnreminder:void 0`,i=n.index+n[0].length;t=t.slice(0,i-1)+r+t.slice(i-1)}else t.includes(`turnReminder:typeof`)||console.error(`patch: outputStyleTurnReminder: custom-style loader shape not found; frontmatter turn-reminder will not thread (fallback reminder still applies)`);let r=t.match(/([$\w]+)\[([$\w]+)\.name\]=\{name:\2\.name,description:\2\.description,prompt:\2\.prompt,source:\2\.source,keepCodingInstructions:\2\.keepCodingInstructions,forceForPlugin:\2\.forceForPlugin\}/);if(r&&r.index!==void 0){let e=r[2],n=r.index+r[0].length;t=t.slice(0,n-1)+`,turnReminder:${e}.turnReminder`+t.slice(n-1)}else /forceForPlugin:[$\w]+\.forceForPlugin,turnReminder:/.test(t)||console.error(`patch: outputStyleTurnReminder: style-table merge shape not found; frontmatter turn-reminder will not thread (fallback reminder still applies)`);return t},Ls=e=>{let t=e.match(/output_style:\(([$\w]+)\)=>\{let ([$\w]+)=([$\w]+)\[\1\.style\];if\(!\2\)return\[\];return ([$\w]+)\(\[([$\w]+)\(\{content:`\$\{\2\.name\} output style is active\. \$\{\1\.turnReminder\?\?"([^"]*)"\}`,isMeta:!0\}\)\]\)\}/);if(!t||t.index===void 0)return/\.style\}\.name\?\?|outputStyleName_tweakcc/.test(e)?(console.log(`patch: outputStyleTurnReminder: renderer already patched — threading only`),Is(e)):/output_style:\(([$\w]+)\)=>\{if\(typeof \1\.style!=="string"/.test(e)?(console.log(`patch: outputStyleTurnReminder: renderer promoted in this CC build — threading only`),Is(e)):(console.error(`patch: outputStyleTurnReminder: failed to find the output-style reminder renderer`),null);let[,n,r,i,a,o]=t,s=`output_style:(${n})=>{let ${r}=${i}[${n}.style];let outputStyleName_tweakcc=${r}?.name??${n}.style;if(!outputStyleName_tweakcc)return[];return ${a}([${o}({content:\`\${outputStyleName_tweakcc} output style is active. \${${n}.turnReminder??"Write this reply the way that style describes, including its rules on what to leave out."}\`,isMeta:!0})])}`,c=e.slice(0,t.index)+s+e.slice(t.index+t[0].length);return B(e,c,s,t.index,t.index+s.length),Is(c)},Rs={sonnet:`claude-sonnet-4-6`,haiku:`claude-haiku-4-5`},zs=(e,t)=>{if(t===`default`)return e;let n=Rs[t],r=e.match(/function ([$\w]+)\(\)\{(?:(?!function )[\s\S])*?modelByMainModel(?:(?!function )[\s\S])*?return\{value:[^{}]*,src:"default"\}\}/);if(r&&r.index!==void 0){let t=r[1],i=`function ${t}(){return{value:"${n}",src:"default"}}`,a=r.index,o=a+r[0].length,s=e.slice(0,a)+i+e.slice(o);return J(`patch: autoModeClassifierModel: matched modelByMainModel resolver ${t} -> ${n}`),B(e,s,i,a,o),s}let i=/function\s+([$\w]+)\s*\(\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*([$\w]+)\s*\(\s*"tengu_auto_mode_config"\s*,\s*\{\s*\}\s*\)\s*;\s*if\s*\(\s*\2\s*\?\.\s*model\s*\)\s*return\s+\2\s*\.\s*model\s*;\s*return\s+([$\w]+)\s*\(\s*\)\s*\}/,a=/function\s+([$\w]+)\s*\(\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*([$\w]+)\s*\(\s*\)\s*;\s*if\s*\(\s*([$\w]+)\s*\(\s*\2\s*\)\s*===\s*"claude-opus-4-8"\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*([$\w]+)\s*\(\s*"tengu_cedar_hollow_7m"\s*,\s*\{\s*\}\s*\)\s*;\s*if\s*\(\s*\5\s*\?\.\s*model\s*\)\s*return\s+\5\s*\.\s*model\s*\}\s*let\s+([$\w]+)\s*=\s*([$\w]+)\s*\(\s*"tengu_auto_mode_config"\s*,\s*\{\s*\}\s*\)\s*;\s*if\s*\(\s*\7\s*\?\.\s*model\s*\)\s*return\s+\7\s*\.\s*model\s*;\s*return\s+\2\s*\}/,o=/function\s+([$\w]+)\s*\(\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*[$\w]+\s*\(\s*\)\s*,\s*([$\w]+)\s*=\s*[$\w]+\s*\(\s*"tengu_auto_mode_config"\s*,\s*\{\s*\}\s*\)\s*,\s*([$\w]+)\s*=\s*\3\s*\?\.\s*modelByMainModel\s*;\s*if\s*\(\s*\4\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*[$\w]+\s*\(\s*\2\s*\)\s*\.\s*replace\([^)]*\)\s*;\s*if\s*\(\s*[$\w]+\s*\(\s*\2\s*\)\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*\4\s*\[\s*`[^`]*`\s*\]\s*;\s*if\s*\(\s*\6\s*\)\s*return\s+\6\s*\}\s*let\s+([$\w]+)\s*=\s*\4\s*\[\s*\5\s*\]\s*;\s*if\s*\(\s*\7\s*\)\s*return\s+\7\s*\}\s*if\s*\(\s*\3\s*\?\.\s*model\s*\)\s*return\s+\3\s*\.\s*model\s*;\s*return\s+\2\s*\}/,s=/function\s+([$\w]+)\s*\(\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*[$\w]+\s*\(\s*\)\s*,\s*([$\w]+)\s*=\s*[$\w]+\s*\(\s*"tengu_auto_mode_config"\s*,\s*\{\s*\}\s*\)\s*,\s*([$\w]+)\s*=\s*\3\s*\?\.\s*modelByMainModel\s*;\s*if\s*\(\s*\4\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*[$\w]+\s*\(\s*\2\s*\)\s*\.\s*replace\([^)]*\)\s*;\s*if\s*\(\s*[$\w]+\s*\(\s*\2\s*\)\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*\4\s*\[\s*`[^`]*`\s*\]\s*;\s*if\s*\(\s*\6\s*\)\s*return\s+\6\s*\}\s*let\s+([$\w]+)\s*=\s*\4\s*\[\s*\5\s*\]\s*;\s*if\s*\(\s*\7\s*\)\s*return\s+\7\s*\}\s*if\s*\(\s*\3\s*\?\.\s*model\s*\)\s*return\s+\3\s*\.\s*model\s*;\s*if\s*\(\s*[$\w]+\s*\(\s*\2\s*\)\s*\|\|\s*[$\w]+\s*\(\s*\2\s*\)\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*[$\w]+\s*\.\s*ANTHROPIC_DEFAULT_OPUS_MODEL\s*\?\?\s*[$\w]+\s*\(\s*\)\s*\.\s*[$\w]+\s*;\s*if\s*\(\s*\(\s*[$\w]+\s*\(\s*\2\s*\)\s*\|\|\s*[$\w]+\s*\(\s*\2\s*\)\s*\)\s*&&\s*!\s*[$\w]+\s*\(\s*\8\s*\)\s*&&\s*!\s*[$\w]+\s*\(\s*\8\s*\)\s*\)\s*return\s+\8\s*\+\s*"\[1m\]"\s*;\s*return\s+\8\s*\}\s*return\s+\2\s*\}/,c=/function\s+([$\w]+)\s*\(\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*[$\w]+\s*\(\s*\)\s*,\s*([$\w]+)\s*=\s*[$\w]+\s*\(\s*"tengu_auto_mode_config"\s*,\s*\{\s*\}\s*\)\s*,\s*([$\w]+)\s*=\s*\3\s*\?\.\s*modelByMainModel\s*;\s*if\s*\(\s*\4\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*[$\w]+\s*\(\s*[$\w]+\s*\(\s*\2\s*\)\s*\)\s*;\s*if\s*\(\s*[$\w]+\s*\(\s*\2\s*\)\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*\4\s*\[\s*`[^`]*`\s*\]\s*;\s*if\s*\(\s*\6\s*\)\s*return\s+\6\s*\}\s*let\s+([$\w]+)\s*=\s*\4\s*\[\s*\5\s*\]\s*;\s*if\s*\(\s*\7\s*\)\s*return\s+\7\s*\}\s*if\s*\(\s*\3\s*\?\.\s*model\s*\)\s*return\s+\3\s*\.\s*model\s*;\s*if\s*\(\s*[$\w]+\s*\(\s*\2\s*\)\s*\|\|\s*[$\w]+\s*\(\s*\2\s*\)\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*[$\w]+\s*\.\s*ANTHROPIC_DEFAULT_OPUS_MODEL\s*\?\?\s*[$\w]+\s*\(\s*\)\s*\.\s*[$\w]+\s*;\s*if\s*\(\s*\(\s*[$\w]+\s*\(\s*\2\s*\)\s*\|\|\s*[$\w]+\s*\(\s*\2\s*\)\s*\)\s*&&\s*!\s*[$\w]+\s*\(\s*\8\s*\)\s*&&\s*!\s*[$\w]+\s*\(\s*\8\s*\)\s*\)\s*return\s+\8\s*\+\s*"\[1m\]"\s*;\s*return\s+\8\s*\}\s*return\s+\2\s*\}/,l=/function\s+([$\w]+)\s*\(\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*[$\w]+\s*\(\s*\)\s*,\s*([$\w]+)\s*=\s*[$\w]+\s*\(\s*"tengu_auto_mode_config"\s*,\s*\{\s*\}\s*\)\s*,\s*([$\w]+)\s*=\s*\3\s*\?\.\s*modelByMainModel\s*;\s*if\s*\(\s*\4\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*[$\w]+\s*\(\s*[$\w]+\s*\(\s*\2\s*\)\s*\)\s*;\s*if\s*\(\s*[$\w]+\s*\(\s*\2\s*\)\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*\4\s*\[\s*`[^`]*`\s*\]\s*;\s*if\s*\(\s*\6\s*\)\s*return\s+\6\s*\}\s*let\s+([$\w]+)\s*=\s*\4\s*\[\s*\5\s*\]\s*;\s*if\s*\(\s*\7\s*\)\s*return\s+\7\s*\}\s*if\s*\(\s*\3\s*\?\.\s*model\s*\)\s*return\s+\3\s*\.\s*model\s*;\s*if\s*\(\s*[$\w]+\s*\(\s*\2\s*\)\s*\|\|\s*[$\w]+\s*\(\s*\2\s*\)\s*\)\s*return\s+[$\w]+\s*\(\s*\2\s*\)\s*;\s*return\s+\2\s*\}/,u=/function\s+([$\w]+)\s*\(\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*[$\w]+\s*\(\s*\)\s*,\s*([$\w]+)\s*=\s*[$\w]+\s*\(\s*"tengu_auto_mode_config"\s*,\s*\{\s*\}\s*\)\s*,\s*([$\w]+)\s*=\s*\3\s*\?\.\s*modelByMainModel\s*;\s*if\s*\(\s*\4\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*[$\w]+\s*\(\s*[$\w]+\s*\(\s*\2\s*\)\s*\)\s*;\s*if\s*\(\s*[$\w]+\s*\(\s*\2\s*\)\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*\4\s*\[\s*`[^`]*`\s*\]\s*;\s*if\s*\(\s*\6\s*\)\s*return\s*\{\s*value\s*:\s*\6\s*,\s*src\s*:\s*"gb"\s*\}\s*\}\s*let\s+([$\w]+)\s*=\s*\4\s*\[\s*\5\s*\]\s*;\s*if\s*\(\s*\7\s*\)\s*return\s*\{\s*value\s*:\s*\7\s*,\s*src\s*:\s*"gb"\s*\}\s*\}\s*if\s*\(\s*\3\s*\?\.\s*model\s*\)\s*return\s*\{\s*value\s*:\s*\3\s*\.\s*model\s*,\s*src\s*:\s*"gb"\s*\}\s*;\s*if\s*\(\s*[$\w]+\s*\(\s*\2\s*\)\s*\|\|\s*[$\w]+\s*\(\s*\2\s*\)\s*\)\s*return\s*\{\s*value\s*:\s*[$\w]+\s*\(\s*\2\s*\)\s*,\s*src\s*:\s*"default"\s*\}\s*;\s*return\s*\{\s*value\s*:\s*\2\s*,\s*src\s*:\s*"default"\s*\}\s*\}/,d=/function\s+([$\w]+)\s*\(\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*[$\w]+\s*\(\s*\)\s*,\s*([$\w]+)\s*=\s*[$\w]+\s*\(\s*"tengu_auto_mode_config"\s*,\s*\{\s*\}\s*\)\s*,\s*([$\w]+)\s*=\s*[$\w]+\s*\(\s*\3\s*\?\.\s*modelByMainModel\s*\)\s*;\s*if\s*\(\s*\4\s*\)\s*return\s*\{\s*value\s*:\s*\4\s*,\s*src\s*:\s*"gb"\s*\}\s*;\s*if\s*\(\s*\3\s*\?\.\s*model\s*\)\s*return\s*\{\s*value\s*:\s*\3\s*\.\s*model\s*,\s*src\s*:\s*"gb"\s*\}\s*;\s*if\s*\(\s*[$\w]+\s*\(\s*\2\s*\)\s*\|\|\s*[$\w]+\s*\(\s*\2\s*\)\s*\)\s*return\s*\{\s*value\s*:\s*[$\w]+\s*\(\s*\2\s*\)\s*,\s*src\s*:\s*"default"\s*\}\s*;\s*return\s*\{\s*value\s*:\s*\2\s*,\s*src\s*:\s*"default"\s*\}\s*\}/,f=/function\s+([$\w]+)\s*\(\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*[$\w]+\s*\(\s*\)\s*,\s*([$\w]+)\s*=\s*[$\w]+\s*\(\s*"tengu_auto_mode_config"\s*,\s*\{\s*\}\s*\)\s*,\s*([$\w]+)\s*=\s*[$\w]+\s*\(\s*\3\s*\?\.\s*modelByMainModel\s*\)\s*;\s*if\s*\(\s*\4\s*\)\s*return\s*\{\s*value\s*:\s*\4\s*,\s*src\s*:\s*"gb"\s*\}\s*;\s*if\s*\(\s*\3\s*\?\.\s*model\s*\)\s*return\s*\{\s*value\s*:\s*\3\s*\.\s*model\s*,\s*src\s*:\s*"gb"\s*\}\s*;\s*if\s*\(\s*[$\w]+\s*!==\s*"demoted"\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*[$\w]+\s*\(\s*\2\s*\)\s*;\s*if\s*\(\s*\5\s*\)\s*return\s*\{\s*value\s*:\s*\5\s*,\s*src\s*:\s*"default"\s*,\s*externalDefault\s*:\s*!0\s*\}\s*\}\s*return\s*\{\s*value\s*:\s*[$\w]+\s*\(\s*\2\s*\)\s*,\s*src\s*:\s*"default"\s*\}\s*\}/,p=e.match(/function\s+([$\w]+)\s*\(\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*[$\w]+\s*\(\s*\)\s*,\s*([$\w]+)\s*=\s*[$\w]+\s*\(\s*"tengu_auto_mode_config"\s*,\s*\{\s*\}\s*\)\s*,\s*([$\w]+)\s*=\s*[$\w]+\s*\(\s*\3\s*\?\.\s*modelByMainModel\s*,\s*\{\s*vet\s*:\s*\(\s*([$\w]+)\s*\)\s*=>\s*[$\w]+\s*\(\s*\5\s*,\s*"modelByMainModel"\s*\)\s*\}\s*\)\s*\?\?\s*[$\w]+\s*\(\s*\3\s*\?\.\s*model\s*,\s*"model"\s*\)\s*;\s*if\s*\(\s*\4\s*\)\s*return\s*\{\s*value\s*:\s*\4\s*,\s*src\s*:\s*"gb"\s*\}\s*;\s*if\s*\(\s*[$\w]+\s*!==\s*"demoted"\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*[$\w]+\s*\(\s*\2\s*\)\s*;\s*if\s*\(\s*\6\s*\)\s*return\s*\{\s*value\s*:\s*\6\s*,\s*src\s*:\s*"default"\s*,\s*externalDefault\s*:\s*!0\s*\}\s*\}\s*return\s*\{\s*value\s*:\s*[$\w]+\s*\(\s*\2\s*\)\s*,\s*src\s*:\s*"default"\s*\}\s*\}/);if(p&&p.index!==void 0){let[t,r]=p,i=`function ${r}(){return{value:"${n}",src:"default"}}`,a=e.slice(0,p.index)+i+e.slice(p.index+t.length);return B(e,a,i,p.index,p.index+t.length),a}let m=e.match(f);if(m&&m.index!==void 0){let[t,r]=m,i=`function ${r}(){return{value:"${n}",src:"default"}}`,a=e.slice(0,m.index)+i+e.slice(m.index+t.length);return B(e,a,i,m.index,m.index+t.length),a}let h=e.match(d);if(h&&h.index!==void 0){let[t,r]=h,i=`function ${r}(){return{value:"${n}",src:"default"}}`,a=e.slice(0,h.index)+i+e.slice(h.index+t.length);return B(e,a,i,h.index,h.index+t.length),a}let g=e.match(u);if(g&&g.index!==void 0){let[t,r]=g,i=`function ${r}(){return{value:"${n}",src:"default"}}`,a=e.slice(0,g.index)+i+e.slice(g.index+t.length);return B(e,a,i,g.index,g.index+t.length),a}let _=e.match(l)||e.match(c)||e.match(s)||e.match(o)||e.match(a)||e.match(i);if(_&&_.index!==void 0){let[t,r]=_,i=`function ${r}(){return "${n}"}`,a=e.slice(0,_.index)+i+e.slice(_.index+t.length);return B(e,a,i,_.index,_.index+t.length),a}return/function\s+[$\w]+\s*\(\s*\)\s*\{\s*return\s*"claude-(opus|sonnet|haiku)-[0-9a-z-]+"\s*\}/.test(e)||/function\s+[$\w]+\s*\(\s*\)\s*\{\s*return\s*\{\s*value\s*:\s*"claude-(opus|sonnet|haiku)-[0-9a-z-]+"\s*,\s*src\s*:\s*"default"\s*\}\s*\}/.test(e)?(J(`patch: autoModeClassifierModel: classifier-model resolver already patched — skipping`),e):e.includes(`"tengu_auto_mode_config"`)?(console.error(`patch: autoModeClassifierModel: failed to find auto-mode classifier resolver`),null):(J(`patch: autoModeClassifierModel: tengu_auto_mode_config not present in this CC build — no-op`),e)},Bs=`/*@@TWEAKCC_MODULE:`,Vs=e=>e.includes(Bs);function Hs(e,t){if(!Vs(e))return{file:e,helpers:t};let n=[],r=(t,r,i)=>{if(r===void 0)return null;let a=e.lastIndexOf(Bs,r),o=e.indexOf(`@@*/`,a);return a<0||o<0||e.slice(a+19,o).indexOf(`:`)<0?null:(n.push({at:r,text:`globalThis.${i}=${t};`}),`globalThis.${i}`)},i=r(t.gB,t.gBIndex,`__tweakccRouterHaiku`),a=r(t.km,t.kmIndex,`__tweakccRouterAgentContext`);if(!i||!a)return null;for(let t of n.sort((e,t)=>t.at-e.at))e=e.slice(0,t.at)+t.text+e.slice(t.at);return{file:e,helpers:{gB:i,km:a}}}const Us=`tweakcc-fixed.typesafe`,Ws=`api-key`,Gs=1500;function Ks(e){return/^[\x21-\x7e]{1,1024}$/.test(e)}function qs(e,t){if(process.platform===`darwin`)return e===`write`?{executable:`/usr/bin/security`,args:[`-i`],input:`add-generic-password -U -s ${Us} -a ${Ws} -w "${t.replace(/[\\"]/g,`\\$&`)}"\n`}:{executable:`/usr/bin/security`,args:[e===`read`?`find-generic-password`:`delete-generic-password`,`-s`,Us,`-a`,Ws,...e===`read`?[`-w`]:[]]};if(process.platform===`linux`)return{executable:`secret-tool`,args:[e===`read`?`lookup`:e===`write`?`store`:`clear`,...e===`write`?[`--label=tweakcc TypeSafe API key`]:[],`service`,Us,`account`,Ws],...e===`write`?{input:t}:{}};throw Error(`Native credential storage is unavailable on this platform. Supply TYPESAFE_API_KEY through your environment or secret manager.`)}function Js(e,t){return new Promise((n,r)=>{let i=_(e.executable,e.args,{encoding:`utf8`,timeout:t,killSignal:`SIGKILL`,maxBuffer:8192,windowsHide:!0},(e,t)=>{e?r(Error(`Could not access the OS credential store. Unlock your keychain, or install secret-tool and unlock Secret Service on Linux. Headless systems can supply TYPESAFE_API_KEY through a secret manager.`)):n(t.trim())});i.stdin?.on(`error`,()=>{}),i.stdin?.end(e.input)})}async function Ys(e){if(!Ks(e))throw Error(`The API key must contain 1–1024 printable ASCII characters without spaces.`);if(await Js(qs(`write`,e),15e3),await Js(qs(`read`),15e3)!==e)throw Error(`The OS credential store did not retain the API key. Unlock your keychain and try again, or supply TYPESAFE_API_KEY through a secret manager.`)}async function Xs(){await Js(qs(`delete`),15e3)}async function Zs(){let e=process.env.TYPESAFE_API_KEY;if(e)return Ks(e);try{return Ks(await Js(qs(`read`),Gs))}catch{return!1}}function Qs(e){return`async function __tweakccRouterApiKey(){
|
|
783
|
+
`,r=e.slice(0,t)+n+e.slice(t);return B(e,r,n,t,t),r},is=e=>{let t=e.match(/function [$\w]+\(\)\{return [$\w]+\("tengu_worktree_mode"/);if(!t||t.index===void 0)return e.includes(`EnterWorktree`)?(console.log(`patch: worktreeMode: EnterWorktree present, tengu_worktree_mode gate gone — no-op`),e):(console.error(`patch: worktreeMode: failed to find worktree gate function pattern`),null);let n=t.index+t[0].indexOf(`{`)+1,r=`return !0;`,i=e.slice(0,n)+r+e.slice(n);return B(e,i,r,n,n),i},as=e=>{let t=/(\{name:"(?:cc-plugin-)?responsive-mode",description:)("(?:[^"\\]|\\.)*")((?:,defaultEnabled:![01])?,isAvailable:([$\w]+)(?:,defaultEnabled:![01])?\})/,n=e.match(t);if(!n||n.index===void 0)return/"(?:cc-plugin-)?responsive-mode"/.test(e)?(console.error(`patch: responsiveMode: failed to find the responsive-mode plugin listing`),null):(console.log(`patch: responsiveMode: this CC build ships no responsive-mode plugin — no-op`),e);let r=n[4].replace(/[$]/g,`\\$`);if(RegExp(`var ${r}=\\(\\)=>(?:!?[$\\w]+\\(\\)&&)*!?[$\\w]+\\(\\);`).test(e)&&n[0].includes(`defaultEnabled`))return e;let i=[RegExp(`(var ${r}=\\(\\)=>)((?:!?[$\\w]+\\(\\)&&)*!?[$\\w]+\\(\\))&&[$\\w]+\\("([a-z0-9_]+)",[$\\w]+\\(\\)\\);`),RegExp(`(var ${r}=\\(\\)=>)([$\\w]+\\(\\))&&[$\\w]+\\("([a-z0-9_]+)",[$\\w]+\\(\\)\\);`)],a=null;for(let t of i)if(a=e.match(t),a)break;if(!a||a.index===void 0)return console.error(`patch: responsiveMode: failed to find the responsive-mode availability gate`),null;let o=e,s=`${a[1]}${a[2]};`;o=o.slice(0,a.index)+s+o.slice(a.index+a[0].length),B(e,o,s,a.index,a.index+a[0].length);let c=o.match(t);if(!c||c.index===void 0)return console.error(`patch: responsiveMode: listing vanished after the gate rewrite`),null;if(!c[0].includes(`defaultEnabled`)){let e=o,t=`${c[1]}${c[2]},defaultEnabled:!1${c[3]}`;o=o.slice(0,c.index)+t+o.slice(c.index+c[0].length),B(e,o,t,c.index,c.index+c[0].length)}return o},os=e=>{let t=e,n=t.match(/,model:([$\w]+)\.enum\(([$\w]+)\)\.optional\(\)/);if(!n||n.index===void 0)return t.match(/let\s+[$\w]+\s*=\s*([$\w]+)\s*&&\s*typeof\s+\1\s*===\s*"string"\s*&&\s*[$\w]+\.includes\(\1\)/)?(console.error(`patch: allowCustomAgentModels: failed to find Zod enum pattern`),null):(J(`patch: allowCustomAgentModels: enum/includes gate removed in this CC build — no-op`),t);let r=n[1],i=n[2],a=`,model:${r}.string().optional()`,o=n.index,s=o+n[0].length;t=t.slice(0,o)+a+t.slice(s),B(e,t,a,o,s);let c=i.replace(/\$/g,`\\$`),l=RegExp(`([;)}])let\\s+([\\$\\w]+)\\s*=\\s*([\\$\\w]+)\\s*&&\\s*typeof\\s+\\3\\s*===\\s*"string"\\s*&&\\s*${c}\\.includes\\(\\3\\)`),u=t,d=t.match(l);if(!d||d.index===void 0)return console.error(`patch: allowCustomAgentModels: failed to find model validation flag pattern`),null;let f=d[1],p=d[2],m=d[3],h=`${f}let ${p}=${m}&&typeof ${m}==="string"`,g=d.index,_=g+d[0].length;return t=t.slice(0,g)+h+t.slice(_),B(u,t,h,g,_),t},ss=e=>{let t=e;{let e=!1;for(let n of[`claude-opus-4-8`,`claude-opus-4-7`]){let r=RegExp(`(id:"${n}"(?:(?!id:"claude-)[\\s\\S]){0,4000}?default_effort:)"(?:high|xhigh)"`),i=t.match(r);if(i&&i.index!==void 0){let n=`${i[1]}"max"`,r=t.slice(0,i.index)+n+t.slice(i.index+i[0].length);B(t,r,n,i.index,i.index+i[0].length),t=r,e=!0}}if(e)return t;if(/id:"claude-opus-4-[78]"(?:(?!id:"claude-)[\s\S]){0,4000}?default_effort:"max"/.test(t))return J(`patch: maxEffortDefault: catalog default_effort already "max" — skipping`),t}let n=/function\s+([$\w]+)\s*\(\s*([$\w]+)\s*\)\s*\{\s*if\s*\(\s*([$\w]+)\s*\(\s*\2\s*\)\s*===\s*"claude-opus-4-7"\s*\)\s*return\s*"xhigh"\s*;\s*return\s*"high"\s*\}/,r=t.match(/function\s+([$\w]+)\s*\(\s*([$\w]+)\s*\)\s*\{\s*if\s*\(\s*([$\w]+)\s*\(\s*\2\s*\)\s*===\s*"claude-opus-4-8"\s*\)\s*return\s*"high"\s*;\s*if\s*\(\s*\3\s*\(\s*\2\s*\)\s*===\s*"claude-opus-4-7"\s*\)\s*return\s*"xhigh"\s*;\s*return\s*"high"\s*\}/),i=r||t.match(n);if(i&&i.index!==void 0){let[e,n,a,o]=i,s=r?`function ${n}(${a}){if(${o}(${a})==="claude-opus-4-8")return"max";if(${o}(${a})==="claude-opus-4-7")return"max";return"high"}`:`function ${n}(${a}){if(${o}(${a})==="claude-opus-4-7")return"max";return"high"}`,c=t.slice(0,i.index)+s+t.slice(i.index+e.length);B(t,c,s,i.index,i.index+e.length),t=c}else if(/===\s*"claude-opus-4-8"\s*\)\s*return\s*"max"/.test(t)||/function\s+[$\w]+\s*\(\s*[$\w]+\s*\)\s*\{\s*if\s*\(\s*[$\w]+\s*\(\s*[$\w]+\s*\)\s*===\s*"claude-opus-4-7"\s*\)\s*return\s*"max"\s*;\s*return\s*"high"\s*\}/.test(t))J(`patch: maxEffortDefault: per-model default already "max" — skipping`);else return console.error(`patch: maxEffortDefault: failed to find Opus per-model effort default`),null;return t},cs=e=>{let t=e.match(/function\s+([$\w]+)\s*\(\s*([$\w]+)\s*\)\s*\{\s*if\s*\(\s*\2\s*===\s*"claude-fable-5"\s*\|\|\s*\2\s*===\s*"claude-mythos-5"\s*\)\s*return\s*!0\s*;\s*return\s*!1\s*\}/)||e.match(/function\s+([$\w]+)\s*\(\s*([$\w]+)\s*\)\s*\{\s*if\s*\(\s*[$\w]+\s*\(\s*\2\s*,\s*"fable_5_mitigations"\s*\)\s*\|\|\s*\2\s*===\s*"claude-mythos-5"\s*\)\s*return\s*!0\s*;\s*return\s*!1\s*\}/)||e.match(/function\s+([$\w]+)\s*\(\s*([$\w]+)\s*(?:,\s*[$\w]+\s*)?\)\s*\{\s*if\s*\(\s*[$\w]+\s*\(\s*\2\s*,\s*"fable_5_mitigations"\s*(?:,\s*[$\w]+\s*)?\)\s*\|\|\s*\2\s*===\s*"claude-mythos-5"\s*\)\s*return\s*!0\s*;\s*return\s*!1\s*\}/)||e.match(/function\s+([$\w]+)\s*\(\s*([$\w]+)\s*(?:,\s*[$\w]+\s*)?\)\s*\{\s*let\s+([$\w]+)\s*=\s*[$\w]+\s*\(\s*\2\s*,\s*"fable_5_mitigations"\s*(?:,\s*[$\w]+\s*)?\)\s*;\s*if\s*\(\s*\3\s*!==\s*void\s*0\s*\)\s*return\s*\3\s*;\s*if\s*\(\s*\2\s*===\s*"claude-mythos-5"\s*\)\s*return\s*!0\s*;\s*return\s*!1\s*\}/);if(!t||t.index===void 0)return/"claude-mythos-5"\s*\)\s*return\s*!0\s*;\s*return\s*!0\s*\}/.test(e)?(J(`patch: autonomousOperationAllModels: model-family gate already flipped — skipping`),e):/"claude-fable-5"/.test(e)?(console.error(`patch: autonomousOperationAllModels: found the fable/mythos model ids but not the expected gate shape — needs a new match method`),null):(console.log(`patch: autonomousOperationAllModels: fable/mythos model-family gate not present in this CC build — no-op`),e);let[n]=t,r=n.replace(/return\s*!1\s*\}$/,`return!0}`),i=e.slice(0,t.index)+r+e.slice(t.index+n.length);return B(e,i,r,t.index,t.index+n.length),i},ls=`globalThis.__tweakccRefusalFallbackReturn`,us=`globalThis.__tweakccRefusalFallbackOnReturn`,ds=`globalThis.__tweakccRefusalFallbackLine`,fs=`globalThis.__tweakccRefusalFallbackMessage`,ps=`globalThis.__tweakccRefusalFallbackEvent`,ms=`__tweakccRefusalFallbackApplyOnReset`,hs=`/*@@TWEAKCC_MODULE:`,gs=(e,t)=>{let n=e.lastIndexOf(hs,t),r=e.indexOf(hs,n===-1?0:n+1);return[n===-1?0:n,r===-1?e.length:r]},_s=e=>e.replace(/\$/g,`\\$`),U=(e,t,n,r)=>{let i=e.slice(0,t)+r+e.slice(t+n);return B(e,i,r,t,t+n),i},vs=e=>{let t={},n=e.match(/function [$\w]+\(([$\w]+)\)\{return\(typeof \1==="string"\?\[\1\]:\1\)\.slice\(0,([$\w]+)\)\}/);if(n?.index!==void 0){let[r,i]=gs(e,n.index),a=e.slice(r,i).match(RegExp(`(?<![$\\w.])${_s(n[2])}=(\\d+)(?![\\d.])`));a&&(t.chainLength=Number(a[1]))}let r=e.match(/function [$\w]+\(([$\w]+)\)\{return ([$\w]+)\(\1\)\|\|([$\w]+)\(\1\)\?\1:"other"\}/);if(r?.index!==void 0){let[n,i]=gs(e,r.index),a=e.slice(n,i),o=new Set;for(let e of[r[2],r[3]]){let n=a.match(RegExp(`function ${_s(e)}\\(([$\\w]+)\\)\\{return ([^}]*)\\}`));if(!n)return t;for(let e of n[2].matchAll(RegExp(`${_s(n[1])}==="([^"]+)"`,`g`)))o.add(e[1])}o.size>0&&(t.categories=o)}return t},ys=(e,t)=>{let n=Object.create(null);if(e==null)return n;if(typeof e!=`object`||Array.isArray(e))return console.warn(`patch: refusalFallbackModel: refusalFallbackRoutes should map a refusal category to a model id or a list of them; ignoring it`),n;for(let[r,i]of Object.entries(e)){let e=Array.isArray(i)?i:[i];if(!e.every(e=>typeof e==`string`)){console.warn(`patch: refusalFallbackModel: skipping refusalFallbackRoutes.${r}: a route is a model id or a non-empty list of model ids`);continue}let a=e.map(e=>e.trim()),o=a.filter(e=>e!==``);if(o.length===0){console.warn(`patch: refusalFallbackModel: skipping refusalFallbackRoutes.${r}: a route is a model id or a non-empty list of model ids`);continue}o.length<a.length&&console.warn(`patch: refusalFallbackModel: refusalFallbackRoutes.${r} has an empty model id; skipping it`),t.categories&&!t.categories.has(r)&&console.warn(`patch: refusalFallbackModel: refusalFallbackRoutes.${r} is not a refusal category this Claude Code knows (${[...t.categories].join(`, `)}), so it never matches`),t.chainLength!==void 0&&o.length>t.chainLength&&console.warn(`patch: refusalFallbackModel: refusalFallbackRoutes.${r} lists ${o.length} models, and Claude Code tries only the first ${t.chainLength}`),n[r]=Array.isArray(i)?o:o[0]}return n},bs=e=>e===void 0?1:e===null?null:typeof e==`number`&&Number.isInteger(e)&&e>=0?e:(console.warn(`patch: refusalFallbackModel: refusalFallbackMaxReturns should be a whole number of returns or null; using 1`),1),xs=e=>{let t=e.match(/(function ([$\w]+)\(([$\w]+)\)\{let\{originalModelCanonical:([$\w]+),apiRefusalCategory:[$\w]+\}=\3,[$\w]+=)\3\.routesOverride\?\?([$\w]+)\(\4\)/);if(!t||t.index===void 0)return null;let[n,r,i,a,o,s]=t;return{index:t.index,length:n.length,head:r,walker:i,arg:a,model:o,table:s}},Ss=`((__tweakccD,__tweakccO)=>{`,Cs=e=>{let t=xs(e);if(!t)return e.includes(Ss)?(J(`patch: refusalFallbackModel: routes already merged, skipping`),e):(console.error(`patch: refusalFallbackModel: failed to find the refusal route walker`),null);let{head:n,arg:r,model:i,table:a}=t;return U(e,t.index,t.length,`${n}${Ss}let __tweakccM=Object.assign(Object.create(null),__tweakccD);if(__tweakccO)for(let __tweakccK of Object.keys(__tweakccO))__tweakccM[__tweakccK]=[...new Set([].concat(__tweakccO[__tweakccK],Object.hasOwn(__tweakccD,__tweakccK)?__tweakccD[__tweakccK]:[]))];return __tweakccM})(${a}(${i}),${r}.routesOverride)`)},ws=e=>{let t=[...e.matchAll(/function ([$\w]+)\(\)\{return\}/g)].find(t=>t[1]!==void 0&&e.includes(`routesOverride:${t[1]}()`));return!t||t.index===void 0?null:{index:t.index,length:t[0].length,name:t[1]}},Ts=(e,t)=>{let n=`{return JSON.parse(${JSON.stringify(JSON.stringify(t))})}`;if(e.includes(n))return J(`patch: refusalFallbackModel: routes already supplied, skipping`),e;let r=ws(e);return r?U(e,r.index,r.length,`function ${r.name}()${n}`):(console.error(`patch: refusalFallbackModel: failed to find the refusal routes supplier`),null)},Es=(e,t)=>`(globalThis.__tweakccRefusalFallbackHub??=new ${e}(()=>${t}()))`,Ds=(e,t,n,r,i)=>{let a=i===null?``:`if(__tweakccR.returns>=${i}){if(__tweakccR.held)return;__tweakccR.held=!0;return{held:!0,returns:__tweakccR.returns,model:__tweakccL.previousOverride??__tweakccL.previousModelForSession??__tweakccL.previousAppStateModel,fallback:__tweakccL.fallbackModel}}`;return`${us}=(__tweakccF)=>${Es(n,r)}.of(${e}()).subscribe(__tweakccF);${ls}=(__tweakccQ)=>{let __tweakccS=${e}(),__tweakccL=__tweakccS.modelSelection.refusalFallbackModelLatch(),__tweakccR=(globalThis.__tweakccRefusalFallbackRuns??=new ${n}(()=>({}))).of(__tweakccS);if(__tweakccR.session!==__tweakccS.id){__tweakccR.session=__tweakccS.id;__tweakccR.returns=0;__tweakccR.held=!1}if(!__tweakccL){if(__tweakccQ){__tweakccR.returns=0;__tweakccR.held=!1}return}`+a+`let __tweakccT=${t}();if(!__tweakccT)return;__tweakccR.returns++;${Es(n,r)}.of(__tweakccS).emit(__tweakccT);return{held:!1,returns:__tweakccR.returns,model:__tweakccT.overrideValue??__tweakccT.forSessionValue??__tweakccT.appStateModel,fallback:__tweakccT.fallbackModel}};`},Os=(e,t)=>{if(e.includes(`${ls}=`))return J(`patch: refusalFallbackModel: return already published, skipping`),e;let n=e.match(/function ([$\w]+)\(\)\{let ([$\w]+)=([$\w]+)\(\),([$\w]+)=\2\.modelSelection\.refusalFallbackModelLatch\(\);if\(\2\.modelSelection\.unlatchRefusalFallbackModel\((?:"[^"]*")?\),!\4\|\|\2\.modelSelection\.mainLoopModelOverride\(\)!==\4\.fallbackModel\)return;return \2\.modelSelection\.overrideMainLoopModel\(\4\.previousOverride\)/);if(!n||n.index===void 0)return console.error(`patch: refusalFallbackModel: failed to find the fallback-restore function`),null;let[r,i]=gs(e,n.index),a=[...e.slice(r,i).matchAll(/var ([$\w]+)=new ([$\w]+)\(\(\)=>([$\w]+)\(\)\);function [$\w]+\(([$\w]+)\)\{return \1\.of\(([$\w]+)\(\)\)\.subscribe\(\4\)\}/g)].find(e=>e[5]===n[3]);return a?U(e,n.index,0,Ds(n[3],n[1],a[2],a[3],t)):(console.error(`patch: refusalFallbackModel: failed to find the reset event's hub in the restore's module`),null)},ks=e=>{if(e.includes(`function ${ms}(`))return J(`patch: refusalFallbackModel: restore callbacks already subscribed, skipping`),e;let t=e.match(/function ([$\w]+)\(([$\w]+)\)\{return ([$\w]+)\(\(([$\w]+),([$\w]+),([$\w]+)\)=>\{if\(!\6\)return;([$\w]+)\(\6,\2\),[$\w]+\("tengu_refusal_fallback_latch_reset",/);if(!t||t.index===void 0)return console.error(`patch: refusalFallbackModel: failed to find the restore's app-state registration`),null;let[,n,r,i,,,,a]=t,[o,s]=gs(e,t.index),c=[...e.slice(o,s).matchAll(RegExp(`function ([$\\w]+)\\(([$\\w]+)\\)\\{return ${_s(i)}\\(\\(([$\\w]+),([$\\w]+),([$\\w]+)\\)=>\\{if\\(\\5\\)\\2\\(\\)\\}\\)\\}`,`g`))];if(c.length!==1||c[0].index===void 0)return console.error(`patch: refusalFallbackModel: failed to find headless's model-drop registration`),null;let[,l,u]=c[0],d=o+c[0].index,[f,p]=d>t.index?[{at:d,name:l,param:u,kind:`drop`},{at:t.index,name:n,param:r,kind:`apply`}]:[{at:t.index,name:n,param:r,kind:`apply`},{at:d,name:l,param:u,kind:`drop`}],m=e;for(let e of[f,p]){let t=e.kind===`apply`?ms:`__tweakccRefusalFallbackDropOnReset`,n=e.kind===`apply`?`(__tweakccT)=>${a}(__tweakccT,${e.param})`:`()=>${e.param}()`,r=`function ${e.name}(${e.param}){`;m=U(m,e.at,r.length,`${r}let __tweakccU=${t}(${e.param}),__tweakccV=${us}?.(${n});return()=>{__tweakccV?.(),__tweakccU()}}function ${t}(${e.param}){`)}return m},As=e=>{if(e.includes(`${ds}=`))return J(`patch: refusalFallbackModel: line already published, skipping`),e;let t=e.match(/function [$\w]+\(([$\w]+),([$\w]+),([$\w]+)\)\{return [$\w]+\("switched",\{model:([$\w]+)\(\1\),fallback:\2\},\1,\3\)\?\?`Switched to \$\{\2\}\.`\}/);if(!t||t.index===void 0)return console.error(`patch: refusalFallbackModel: failed to find the fallback's switch message`),null;let n=t[4],r=`${ds}=(__tweakccN)=>{let __tweakccM=__tweakccN.model==null?"the default model":${n}(__tweakccN.model),__tweakccF=${n}(__tweakccN.fallback);return __tweakccN.held?{content:"Staying on "+__tweakccF+" for this session \\xB7 "+(__tweakccN.returns?__tweakccM+" was flagged again after switching back \\xB7 ":"")+"/model to change",level:"warning"}:{content:"Switched back to "+__tweakccM+".",level:"notice"}};`;return U(e,t.index,0,r)},js=e=>{if(e.includes(`${fs}=`))return J(`patch: refusalFallbackModel: message constructor already published, skipping`),e;let t=e.match(/function ([$\w]+)\(([$\w]+),([$\w]+)(?:,([$\w]+))?\)\{return\{type:"system",subtype:"informational",content:\2,isMeta:!1,timestamp:new Date\(\)\.toISOString\(\),uuid:[$\w]+\(\),level:\3(?:,\.\.\.\4&&\{[$\w]+:\4\})?\}\}/);return!t||t.index===void 0?(console.error(`patch: refusalFallbackModel: failed to find the system-message constructor`),null):U(e,t.index,0,`${fs}=${t[1]};`)},Ms=e=>{if(e.includes(`${ps}=`))return J(`patch: refusalFallbackModel: event queue already published, skipping`),e;let t=e.match(/function [$\w]+\([$\w]+\)\{([$\w]+)\(\)\.setEnqueueListener\([$\w]+\)\}function ([$\w]+)\(([$\w]+)\)\{\1\(\)\.enqueue\(\3\)\}/);return!t||t.index===void 0?(console.error(`patch: refusalFallbackModel: failed to find the SDK event queue`),null):U(e,t.index,0,`${ps}=${t[2]};`)},Ns=e=>{let t=`}finally{try{let __tweakccN=${ls}`;if(e.includes(t))return J(`patch: refusalFallbackModel: REPL turn end already spliced, skipping`),e;let n=e.match(/([$\w.]+)=await this\._runImpl\([$\w]+,[^)]*\)\}finally\{/);if(!n||n.index===void 0)return console.error(`patch: refusalFallbackModel: failed to find the REPL's turn-end finally`),null;let r=n.index+n[0].length,i=e.slice(r,r+2e3).match(/([$\w]+)\(\{type:"append",messages:this\.stream\.pendingPreservedInsert\.preserved\}\)/);return i?U(e,r,0,`try{let __tweakccN=${ls}?.(${n[1]}?.num_turns>0);if(__tweakccN){let __tweakccL=${ds}?.(__tweakccN),__tweakccM=__tweakccL&&${fs}?.(__tweakccL.content,__tweakccL.level);if(__tweakccM)${i[1]}({type:"append",messages:[__tweakccM]})}}catch{}`):(console.error(`patch: refusalFallbackModel: failed to find the REPL's transcript append`),null)},Ps=e=>{let t=e.match(/noteTurnEnded\(([$\w]+),([$\w]+),([$\w]+)\)\{if\(this\.selector\.noteTurnEnded\(\1\),\1\|\|\3\.num_turns>0\)\{/);return!t||t.index===void 0?/noteTurnEnded\([$\w]+,[$\w]+,[$\w]+\)\{try\{let __tweakccN=/.test(e)?(J(`patch: refusalFallbackModel: headless turn end already spliced, skipping`),e):(console.error(`patch: refusalFallbackModel: failed to find the dispatcher's noteTurnEnded`),null):U(e,t.index+`noteTurnEnded(${t[1]},${t[2]},${t[3]}){`.length,0,`try{let __tweakccN=${ls}?.(${t[3]}?.num_turns>0);if(__tweakccN){let __tweakccL=${ds}?.(__tweakccN);if(__tweakccL)${ps}?.({type:"system",subtype:"informational",content:__tweakccL.content,level:__tweakccL.level})}}catch{}`)},Fs=(e,t={},n=1)=>{let r=bs(n),i=ys(t,vs(e)),a=[Cs,e=>Ts(e,i),e=>Os(e,r),ks,As,js,Ms,Ns,Ps],o=e;for(let e of a)if(o=e(o),o===null)return null;return o},Is=e=>{let t=e,n=t.match(/\(\{filePath:([$\w]+),frontmatter:([$\w]+),content:([$\w]+),source:([$\w]+),baseDir:([$\w]+)\}\)=>\{([\s\S]{0,800}?)return\{name:([$\w]+),description:([$\w]+),prompt:\3\.trim\(\),source:\4,baseDir:\5,keepCodingInstructions:([$\w]+)\}/);if(n&&n.index!==void 0){let e=n[2],r=`,turnReminder:typeof ${e}["turn-reminder"]==="string"?${e}["turn-reminder"]:typeof ${e}.turnReminder==="string"?${e}.turnReminder:typeof ${e}.turnreminder==="string"?${e}.turnreminder:void 0`,i=n.index+n[0].length;t=t.slice(0,i-1)+r+t.slice(i-1)}else t.includes(`turnReminder:typeof`)||console.error(`patch: outputStyleTurnReminder: custom-style loader shape not found; frontmatter turn-reminder will not thread (fallback reminder still applies)`);let r=t.match(/([$\w]+)\[([$\w]+)\.name\]=\{name:\2\.name,description:\2\.description,prompt:\2\.prompt,source:\2\.source,keepCodingInstructions:\2\.keepCodingInstructions,forceForPlugin:\2\.forceForPlugin\}/);if(r&&r.index!==void 0){let e=r[2],n=r.index+r[0].length;t=t.slice(0,n-1)+`,turnReminder:${e}.turnReminder`+t.slice(n-1)}else /forceForPlugin:[$\w]+\.forceForPlugin,turnReminder:/.test(t)||console.error(`patch: outputStyleTurnReminder: style-table merge shape not found; frontmatter turn-reminder will not thread (fallback reminder still applies)`);return t},Ls=e=>{let t=e.match(/output_style:\(([$\w]+)\)=>\{let ([$\w]+)=([$\w]+)\[\1\.style\];if\(!\2\)return\[\];return ([$\w]+)\(\[([$\w]+)\(\{content:`\$\{\2\.name\} output style is active\. \$\{\1\.turnReminder\?\?"([^"]*)"\}`,isMeta:!0\}\)\]\)\}/);if(!t||t.index===void 0)return/\.style\}\.name\?\?|outputStyleName_tweakcc/.test(e)?(console.log(`patch: outputStyleTurnReminder: renderer already patched — threading only`),Is(e)):/output_style:\(([$\w]+)\)=>\{if\(typeof \1\.style!=="string"/.test(e)?(console.log(`patch: outputStyleTurnReminder: renderer promoted in this CC build — threading only`),Is(e)):(console.error(`patch: outputStyleTurnReminder: failed to find the output-style reminder renderer`),null);let[,n,r,i,a,o]=t,s=`output_style:(${n})=>{let ${r}=${i}[${n}.style];let outputStyleName_tweakcc=${r}?.name??${n}.style;if(!outputStyleName_tweakcc)return[];return ${a}([${o}({content:\`\${outputStyleName_tweakcc} output style is active. \${${n}.turnReminder??"Write this reply the way that style describes, including its rules on what to leave out."}\`,isMeta:!0})])}`,c=e.slice(0,t.index)+s+e.slice(t.index+t[0].length);return B(e,c,s,t.index,t.index+s.length),Is(c)},Rs={sonnet:`claude-sonnet-4-6`,haiku:`claude-haiku-4-5`},zs=(e,t)=>{if(t===`default`)return e;let n=Rs[t],r=e.match(/function ([$\w]+)\(\)\{(?:(?!function )[\s\S])*?modelByMainModel(?:(?!function )[\s\S])*?return\{value:[^{}]*,src:"default"\}\}/);if(r&&r.index!==void 0){let t=r[1],i=`function ${t}(){return{value:"${n}",src:"default"}}`,a=r.index,o=a+r[0].length,s=e.slice(0,a)+i+e.slice(o);return J(`patch: autoModeClassifierModel: matched modelByMainModel resolver ${t} -> ${n}`),B(e,s,i,a,o),s}let i=/function\s+([$\w]+)\s*\(\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*([$\w]+)\s*\(\s*"tengu_auto_mode_config"\s*,\s*\{\s*\}\s*\)\s*;\s*if\s*\(\s*\2\s*\?\.\s*model\s*\)\s*return\s+\2\s*\.\s*model\s*;\s*return\s+([$\w]+)\s*\(\s*\)\s*\}/,a=/function\s+([$\w]+)\s*\(\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*([$\w]+)\s*\(\s*\)\s*;\s*if\s*\(\s*([$\w]+)\s*\(\s*\2\s*\)\s*===\s*"claude-opus-4-8"\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*([$\w]+)\s*\(\s*"tengu_cedar_hollow_7m"\s*,\s*\{\s*\}\s*\)\s*;\s*if\s*\(\s*\5\s*\?\.\s*model\s*\)\s*return\s+\5\s*\.\s*model\s*\}\s*let\s+([$\w]+)\s*=\s*([$\w]+)\s*\(\s*"tengu_auto_mode_config"\s*,\s*\{\s*\}\s*\)\s*;\s*if\s*\(\s*\7\s*\?\.\s*model\s*\)\s*return\s+\7\s*\.\s*model\s*;\s*return\s+\2\s*\}/,o=/function\s+([$\w]+)\s*\(\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*[$\w]+\s*\(\s*\)\s*,\s*([$\w]+)\s*=\s*[$\w]+\s*\(\s*"tengu_auto_mode_config"\s*,\s*\{\s*\}\s*\)\s*,\s*([$\w]+)\s*=\s*\3\s*\?\.\s*modelByMainModel\s*;\s*if\s*\(\s*\4\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*[$\w]+\s*\(\s*\2\s*\)\s*\.\s*replace\([^)]*\)\s*;\s*if\s*\(\s*[$\w]+\s*\(\s*\2\s*\)\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*\4\s*\[\s*`[^`]*`\s*\]\s*;\s*if\s*\(\s*\6\s*\)\s*return\s+\6\s*\}\s*let\s+([$\w]+)\s*=\s*\4\s*\[\s*\5\s*\]\s*;\s*if\s*\(\s*\7\s*\)\s*return\s+\7\s*\}\s*if\s*\(\s*\3\s*\?\.\s*model\s*\)\s*return\s+\3\s*\.\s*model\s*;\s*return\s+\2\s*\}/,s=/function\s+([$\w]+)\s*\(\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*[$\w]+\s*\(\s*\)\s*,\s*([$\w]+)\s*=\s*[$\w]+\s*\(\s*"tengu_auto_mode_config"\s*,\s*\{\s*\}\s*\)\s*,\s*([$\w]+)\s*=\s*\3\s*\?\.\s*modelByMainModel\s*;\s*if\s*\(\s*\4\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*[$\w]+\s*\(\s*\2\s*\)\s*\.\s*replace\([^)]*\)\s*;\s*if\s*\(\s*[$\w]+\s*\(\s*\2\s*\)\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*\4\s*\[\s*`[^`]*`\s*\]\s*;\s*if\s*\(\s*\6\s*\)\s*return\s+\6\s*\}\s*let\s+([$\w]+)\s*=\s*\4\s*\[\s*\5\s*\]\s*;\s*if\s*\(\s*\7\s*\)\s*return\s+\7\s*\}\s*if\s*\(\s*\3\s*\?\.\s*model\s*\)\s*return\s+\3\s*\.\s*model\s*;\s*if\s*\(\s*[$\w]+\s*\(\s*\2\s*\)\s*\|\|\s*[$\w]+\s*\(\s*\2\s*\)\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*[$\w]+\s*\.\s*ANTHROPIC_DEFAULT_OPUS_MODEL\s*\?\?\s*[$\w]+\s*\(\s*\)\s*\.\s*[$\w]+\s*;\s*if\s*\(\s*\(\s*[$\w]+\s*\(\s*\2\s*\)\s*\|\|\s*[$\w]+\s*\(\s*\2\s*\)\s*\)\s*&&\s*!\s*[$\w]+\s*\(\s*\8\s*\)\s*&&\s*!\s*[$\w]+\s*\(\s*\8\s*\)\s*\)\s*return\s+\8\s*\+\s*"\[1m\]"\s*;\s*return\s+\8\s*\}\s*return\s+\2\s*\}/,c=/function\s+([$\w]+)\s*\(\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*[$\w]+\s*\(\s*\)\s*,\s*([$\w]+)\s*=\s*[$\w]+\s*\(\s*"tengu_auto_mode_config"\s*,\s*\{\s*\}\s*\)\s*,\s*([$\w]+)\s*=\s*\3\s*\?\.\s*modelByMainModel\s*;\s*if\s*\(\s*\4\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*[$\w]+\s*\(\s*[$\w]+\s*\(\s*\2\s*\)\s*\)\s*;\s*if\s*\(\s*[$\w]+\s*\(\s*\2\s*\)\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*\4\s*\[\s*`[^`]*`\s*\]\s*;\s*if\s*\(\s*\6\s*\)\s*return\s+\6\s*\}\s*let\s+([$\w]+)\s*=\s*\4\s*\[\s*\5\s*\]\s*;\s*if\s*\(\s*\7\s*\)\s*return\s+\7\s*\}\s*if\s*\(\s*\3\s*\?\.\s*model\s*\)\s*return\s+\3\s*\.\s*model\s*;\s*if\s*\(\s*[$\w]+\s*\(\s*\2\s*\)\s*\|\|\s*[$\w]+\s*\(\s*\2\s*\)\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*[$\w]+\s*\.\s*ANTHROPIC_DEFAULT_OPUS_MODEL\s*\?\?\s*[$\w]+\s*\(\s*\)\s*\.\s*[$\w]+\s*;\s*if\s*\(\s*\(\s*[$\w]+\s*\(\s*\2\s*\)\s*\|\|\s*[$\w]+\s*\(\s*\2\s*\)\s*\)\s*&&\s*!\s*[$\w]+\s*\(\s*\8\s*\)\s*&&\s*!\s*[$\w]+\s*\(\s*\8\s*\)\s*\)\s*return\s+\8\s*\+\s*"\[1m\]"\s*;\s*return\s+\8\s*\}\s*return\s+\2\s*\}/,l=/function\s+([$\w]+)\s*\(\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*[$\w]+\s*\(\s*\)\s*,\s*([$\w]+)\s*=\s*[$\w]+\s*\(\s*"tengu_auto_mode_config"\s*,\s*\{\s*\}\s*\)\s*,\s*([$\w]+)\s*=\s*\3\s*\?\.\s*modelByMainModel\s*;\s*if\s*\(\s*\4\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*[$\w]+\s*\(\s*[$\w]+\s*\(\s*\2\s*\)\s*\)\s*;\s*if\s*\(\s*[$\w]+\s*\(\s*\2\s*\)\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*\4\s*\[\s*`[^`]*`\s*\]\s*;\s*if\s*\(\s*\6\s*\)\s*return\s+\6\s*\}\s*let\s+([$\w]+)\s*=\s*\4\s*\[\s*\5\s*\]\s*;\s*if\s*\(\s*\7\s*\)\s*return\s+\7\s*\}\s*if\s*\(\s*\3\s*\?\.\s*model\s*\)\s*return\s+\3\s*\.\s*model\s*;\s*if\s*\(\s*[$\w]+\s*\(\s*\2\s*\)\s*\|\|\s*[$\w]+\s*\(\s*\2\s*\)\s*\)\s*return\s+[$\w]+\s*\(\s*\2\s*\)\s*;\s*return\s+\2\s*\}/,u=/function\s+([$\w]+)\s*\(\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*[$\w]+\s*\(\s*\)\s*,\s*([$\w]+)\s*=\s*[$\w]+\s*\(\s*"tengu_auto_mode_config"\s*,\s*\{\s*\}\s*\)\s*,\s*([$\w]+)\s*=\s*\3\s*\?\.\s*modelByMainModel\s*;\s*if\s*\(\s*\4\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*[$\w]+\s*\(\s*[$\w]+\s*\(\s*\2\s*\)\s*\)\s*;\s*if\s*\(\s*[$\w]+\s*\(\s*\2\s*\)\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*\4\s*\[\s*`[^`]*`\s*\]\s*;\s*if\s*\(\s*\6\s*\)\s*return\s*\{\s*value\s*:\s*\6\s*,\s*src\s*:\s*"gb"\s*\}\s*\}\s*let\s+([$\w]+)\s*=\s*\4\s*\[\s*\5\s*\]\s*;\s*if\s*\(\s*\7\s*\)\s*return\s*\{\s*value\s*:\s*\7\s*,\s*src\s*:\s*"gb"\s*\}\s*\}\s*if\s*\(\s*\3\s*\?\.\s*model\s*\)\s*return\s*\{\s*value\s*:\s*\3\s*\.\s*model\s*,\s*src\s*:\s*"gb"\s*\}\s*;\s*if\s*\(\s*[$\w]+\s*\(\s*\2\s*\)\s*\|\|\s*[$\w]+\s*\(\s*\2\s*\)\s*\)\s*return\s*\{\s*value\s*:\s*[$\w]+\s*\(\s*\2\s*\)\s*,\s*src\s*:\s*"default"\s*\}\s*;\s*return\s*\{\s*value\s*:\s*\2\s*,\s*src\s*:\s*"default"\s*\}\s*\}/,d=/function\s+([$\w]+)\s*\(\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*[$\w]+\s*\(\s*\)\s*,\s*([$\w]+)\s*=\s*[$\w]+\s*\(\s*"tengu_auto_mode_config"\s*,\s*\{\s*\}\s*\)\s*,\s*([$\w]+)\s*=\s*[$\w]+\s*\(\s*\3\s*\?\.\s*modelByMainModel\s*\)\s*;\s*if\s*\(\s*\4\s*\)\s*return\s*\{\s*value\s*:\s*\4\s*,\s*src\s*:\s*"gb"\s*\}\s*;\s*if\s*\(\s*\3\s*\?\.\s*model\s*\)\s*return\s*\{\s*value\s*:\s*\3\s*\.\s*model\s*,\s*src\s*:\s*"gb"\s*\}\s*;\s*if\s*\(\s*[$\w]+\s*\(\s*\2\s*\)\s*\|\|\s*[$\w]+\s*\(\s*\2\s*\)\s*\)\s*return\s*\{\s*value\s*:\s*[$\w]+\s*\(\s*\2\s*\)\s*,\s*src\s*:\s*"default"\s*\}\s*;\s*return\s*\{\s*value\s*:\s*\2\s*,\s*src\s*:\s*"default"\s*\}\s*\}/,f=/function\s+([$\w]+)\s*\(\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*[$\w]+\s*\(\s*\)\s*,\s*([$\w]+)\s*=\s*[$\w]+\s*\(\s*"tengu_auto_mode_config"\s*,\s*\{\s*\}\s*\)\s*,\s*([$\w]+)\s*=\s*[$\w]+\s*\(\s*\3\s*\?\.\s*modelByMainModel\s*\)\s*;\s*if\s*\(\s*\4\s*\)\s*return\s*\{\s*value\s*:\s*\4\s*,\s*src\s*:\s*"gb"\s*\}\s*;\s*if\s*\(\s*\3\s*\?\.\s*model\s*\)\s*return\s*\{\s*value\s*:\s*\3\s*\.\s*model\s*,\s*src\s*:\s*"gb"\s*\}\s*;\s*if\s*\(\s*[$\w]+\s*!==\s*"demoted"\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*[$\w]+\s*\(\s*\2\s*\)\s*;\s*if\s*\(\s*\5\s*\)\s*return\s*\{\s*value\s*:\s*\5\s*,\s*src\s*:\s*"default"\s*,\s*externalDefault\s*:\s*!0\s*\}\s*\}\s*return\s*\{\s*value\s*:\s*[$\w]+\s*\(\s*\2\s*\)\s*,\s*src\s*:\s*"default"\s*\}\s*\}/,p=e.match(/function\s+([$\w]+)\s*\(\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*[$\w]+\s*\(\s*\)\s*,\s*([$\w]+)\s*=\s*[$\w]+\s*\(\s*"tengu_auto_mode_config"\s*,\s*\{\s*\}\s*\)\s*,\s*([$\w]+)\s*=\s*[$\w]+\s*\(\s*\3\s*\?\.\s*modelByMainModel\s*,\s*\{\s*vet\s*:\s*\(\s*([$\w]+)\s*\)\s*=>\s*[$\w]+\s*\(\s*\5\s*,\s*"modelByMainModel"\s*\)\s*\}\s*\)\s*\?\?\s*[$\w]+\s*\(\s*\3\s*\?\.\s*model\s*,\s*"model"\s*\)\s*;\s*if\s*\(\s*\4\s*\)\s*return\s*\{\s*value\s*:\s*\4\s*,\s*src\s*:\s*"gb"\s*\}\s*;\s*if\s*\(\s*[$\w]+\s*!==\s*"demoted"\s*\)\s*\{\s*let\s+([$\w]+)\s*=\s*[$\w]+\s*\(\s*\2\s*\)\s*;\s*if\s*\(\s*\6\s*\)\s*return\s*\{\s*value\s*:\s*\6\s*,\s*src\s*:\s*"default"\s*,\s*externalDefault\s*:\s*!0\s*\}\s*\}\s*return\s*\{\s*value\s*:\s*[$\w]+\s*\(\s*\2\s*\)\s*,\s*src\s*:\s*"default"\s*\}\s*\}/);if(p&&p.index!==void 0){let[t,r]=p,i=`function ${r}(){return{value:"${n}",src:"default"}}`,a=e.slice(0,p.index)+i+e.slice(p.index+t.length);return B(e,a,i,p.index,p.index+t.length),a}let m=e.match(f);if(m&&m.index!==void 0){let[t,r]=m,i=`function ${r}(){return{value:"${n}",src:"default"}}`,a=e.slice(0,m.index)+i+e.slice(m.index+t.length);return B(e,a,i,m.index,m.index+t.length),a}let h=e.match(d);if(h&&h.index!==void 0){let[t,r]=h,i=`function ${r}(){return{value:"${n}",src:"default"}}`,a=e.slice(0,h.index)+i+e.slice(h.index+t.length);return B(e,a,i,h.index,h.index+t.length),a}let g=e.match(u);if(g&&g.index!==void 0){let[t,r]=g,i=`function ${r}(){return{value:"${n}",src:"default"}}`,a=e.slice(0,g.index)+i+e.slice(g.index+t.length);return B(e,a,i,g.index,g.index+t.length),a}let _=e.match(l)||e.match(c)||e.match(s)||e.match(o)||e.match(a)||e.match(i);if(_&&_.index!==void 0){let[t,r]=_,i=`function ${r}(){return "${n}"}`,a=e.slice(0,_.index)+i+e.slice(_.index+t.length);return B(e,a,i,_.index,_.index+t.length),a}return/function\s+[$\w]+\s*\(\s*\)\s*\{\s*return\s*"claude-(opus|sonnet|haiku)-[0-9a-z-]+"\s*\}/.test(e)||/function\s+[$\w]+\s*\(\s*\)\s*\{\s*return\s*\{\s*value\s*:\s*"claude-(opus|sonnet|haiku)-[0-9a-z-]+"\s*,\s*src\s*:\s*"default"\s*\}\s*\}/.test(e)?(J(`patch: autoModeClassifierModel: classifier-model resolver already patched — skipping`),e):e.includes(`"tengu_auto_mode_config"`)?(console.error(`patch: autoModeClassifierModel: failed to find auto-mode classifier resolver`),null):(J(`patch: autoModeClassifierModel: tengu_auto_mode_config not present in this CC build — no-op`),e)},Bs=`/*@@TWEAKCC_MODULE:`,Vs=e=>e.includes(Bs);function Hs(e,t){if(!Vs(e))return{file:e,helpers:t};let n=[],r=(t,r,i)=>{if(r===void 0)return null;let a=e.lastIndexOf(Bs,r),o=e.indexOf(`@@*/`,a);return a<0||o<0||e.slice(a+19,o).indexOf(`:`)<0?null:(n.push({at:r,text:`globalThis.${i}=${t};`}),`globalThis.${i}`)},i=r(t.gB,t.gBIndex,`__tweakccRouterHaiku`),a=r(t.km,t.kmIndex,`__tweakccRouterAgentContext`);if(!i||!a)return null;for(let t of n.sort((e,t)=>t.at-e.at))e=e.slice(0,t.at)+t.text+e.slice(t.at);return{file:e,helpers:{gB:i,km:a}}}const Us=`tweakcc-fixed.typesafe`,Ws=`api-key`,Gs=1500;function Ks(e){return/^[\x21-\x7e]{1,1024}$/.test(e)}function qs(e,t){if(process.platform===`darwin`)return e===`write`?{executable:`/usr/bin/security`,args:[`-i`],input:`add-generic-password -U -s ${Us} -a ${Ws} -w "${t.replace(/[\\"]/g,`\\$&`)}"\n`}:{executable:`/usr/bin/security`,args:[e===`read`?`find-generic-password`:`delete-generic-password`,`-s`,Us,`-a`,Ws,...e===`read`?[`-w`]:[]]};if(process.platform===`linux`)return{executable:`secret-tool`,args:[e===`read`?`lookup`:e===`write`?`store`:`clear`,...e===`write`?[`--label=tweakcc TypeSafe API key`]:[],`service`,Us,`account`,Ws],...e===`write`?{input:t}:{}};throw Error(`Native credential storage is unavailable on this platform. Supply TYPESAFE_API_KEY through your environment or secret manager.`)}function Js(e,t){return new Promise((n,r)=>{let i=_(e.executable,e.args,{encoding:`utf8`,timeout:t,killSignal:`SIGKILL`,maxBuffer:8192,windowsHide:!0},(e,t)=>{e?r(Error(`Could not access the OS credential store. Unlock your keychain, or install secret-tool and unlock Secret Service on Linux. Headless systems can supply TYPESAFE_API_KEY through a secret manager.`)):n(t.trim())});i.stdin?.on(`error`,()=>{}),i.stdin?.end(e.input)})}async function Ys(e){if(!Ks(e))throw Error(`The API key must contain 1–1024 printable ASCII characters without spaces.`);if(await Js(qs(`write`,e),15e3),await Js(qs(`read`),15e3)!==e)throw Error(`The OS credential store did not retain the API key. Unlock your keychain and try again, or supply TYPESAFE_API_KEY through a secret manager.`)}async function Xs(){await Js(qs(`delete`),15e3)}async function Zs(){let e=process.env.TYPESAFE_API_KEY;if(e)return Ks(e);try{return Ks(await Js(qs(`read`),Gs))}catch{return!1}}function Qs(e){return`async function __tweakccRouterApiKey(){
|
|
784
784
|
const valid=k=>typeof k==="string"&&/^[\\x21-\\x7e]{1,1024}$/.test(k);
|
|
785
785
|
const env=process.env.TYPESAFE_API_KEY;
|
|
786
786
|
if(env)return valid(env)?env:null;
|
|
@@ -1036,7 +1036,7 @@ globalThis.__tweakccRouterState=__tweakccRouterState;
|
|
|
1036
1036
|
globalThis.__tweakccRouterClassify=__tweakccRouterClassify;
|
|
1037
1037
|
globalThis.__tweakccRouterObserve=__tweakccRouterObserve;
|
|
1038
1038
|
globalThis.__tweakccRouterInvalidate=__tweakccRouterInvalidate;
|
|
1039
|
-
`)},ec=e=>{if(e.includes(`function __tweakccRouterMessageKey(`)||!e.includes(`subtype:"turn_duration"`))return e;let t=e.match(/function ([$\w]+)\(([$\w]+),([$\w]+),([$\w]+),([$\w]+),([$\w]+)\)\{return\{type:"system",subtype:"turn_duration",durationMs:\2,/),n=e.match(/([$\w]+)\(\(\)=>(([$\w]+)\(([$\w]+),([$\w]+)\.effortValue,\{turnEffort:\5\.turnEffort,hookEffortValue:\5\.hookEffortValue\}\))\)/),r=e.match(/children:`\$\{([$\w]+)\} for \$\{([$\w]+)\}\$\{([$\w]+)\?` \\xB7 done \$\{\3\}`:""\}`/);if(!t||!n||!r)return console.error(`patch: complexityRouter: failed to find turn status anchors`),null;let i=[...e.slice(0,n.index).matchAll(/function\*[$\w]+\(([$\w]+),[$\w]+,[$\w]+,[$\w]+,[$\w]+,([$\w]+)\)\{/g)].at(-1),a=[...e.slice(Math.max(0,r.index-7e3),r.index).matchAll(/\{message:([$\w]+),addMargin:[$\w]+,verb:[$\w]+\}/g)].at(-1)?.[1],
|
|
1039
|
+
`)},ec=e=>{if(e.includes(`function __tweakccRouterMessageKey(`)||!e.includes(`subtype:"turn_duration"`))return e;let t=e.match(/function ([$\w]+)\(([$\w]+),([$\w]+),([$\w]+),([$\w]+),([$\w]+)\)\{return\{type:"system",subtype:"turn_duration",durationMs:\2,/),n=e.match(/([$\w]+)\(\(\)=>(([$\w]+)\(([$\w]+),([$\w]+)\.effortValue,\{turnEffort:\5\.turnEffort,hookEffortValue:\5\.hookEffortValue(?:,carriedEffort:(?!null\})[$\w]+)?\}\))\)/),r=e.match(/children:`\$\{([$\w]+)\} for \$\{([$\w]+)\}\$\{([$\w]+)\?` \\xB7 done \$\{\3\}`:""\}`/);if(!t||!n||!r)return console.error(`patch: complexityRouter: failed to find turn status anchors`),null;let i=[...e.slice(0,n.index).matchAll(/function\*[$\w]+\(([$\w]+),[$\w]+,[$\w]+,[$\w]+,[$\w]+,(?:([$\w]+)|\{(?:[$\w]+:[$\w]+,)*\.\.\.([$\w]+)\})\)\{/g)].at(-1),a=i?i[2]??i[3]:void 0,o=[...e.slice(Math.max(0,r.index-7e3),r.index).matchAll(/\{message:([$\w]+),addMargin:[$\w]+,verb:[$\w]+\}/g)].at(-1)?.[1],s=e=>e.replace(/\$/g,`\\$`),c=!!i&&!!a&&(a===n[5]||RegExp(`[,{]${s(n[5])}=[$\\w]+===${s(a)}\\.fallbackModel\\?${s(a)}:\\{\\.\\.\\.${s(a)},`).test(e.slice(i.index,n.index)));if(!i||!c||!o)return console.error(`patch: complexityRouter: failed to find turn status scopes`),null;let l=[...e.matchAll(RegExp(`${t[1].replace(/\$/g,`\\$`)}\\(([$\\w]+(?:\\.durationMs)?),([$\\w]+),([$\\w]+)\\(((?:[$\\w]+(?:\\([^()]*\\))?)(?:\\.[$\\w]+(?:\\([^()]*\\))?)*),([$\\w]+)\\)(,[$\\w]+\\.pendingBackgroundAgentCount,[$\\w]+\\.pendingWorkflowCount)?\\)`,`g`))];if(l.length===0)return console.error(`patch: complexityRouter: failed to find turn status emission`),null;let u=[{index:t.index,old:t[0],replacement:`
|
|
1040
1040
|
function __tweakccRouterMessageKey(messages){
|
|
1041
1041
|
if(!Array.isArray(messages))return;
|
|
1042
1042
|
for(var i=messages.length-1;i>=0;i--){var m=messages[i],c=m?.message?.content??m?.content;if(m?.type!=="user"||m.isMeta||typeof m.uuid!=="string")continue;if(typeof c==="string"||Array.isArray(c)&&c.some(p=>p?.type==="text"||p?.type==="image")&&!c.some(p=>p?.type==="tool_result"))return m.uuid}
|
|
@@ -1054,8 +1054,8 @@ globalThis.__tweakccRouterRecordTurn=function(messages,options,effort,resolution
|
|
|
1054
1054
|
globalThis.__tweakccRouterSnapshotTurn=function(messages){
|
|
1055
1055
|
var snapshot=__tweakccRouterTurnHistory.get(__tweakccRouterMessageKey(messages));return snapshot?{...snapshot}:void 0;
|
|
1056
1056
|
};
|
|
1057
|
-
`+t[0].replace(`){return{`,`,__tweakccRouterSnapshot){return{...(__tweakccRouterSnapshot?{tweakccRouter:__tweakccRouterSnapshot}:{}),`)},{index:n.index,old:n[0],replacement:`${n[1]}(()=>{globalThis.__tweakccRouterResolution=void 0;let __tweakccResolved=${n[2].slice(0,-1)},${n[5]});globalThis.__tweakccRouterRecordTurn?.(${i[1]},${n[5]},__tweakccResolved,globalThis.__tweakccRouterResolution);return __tweakccResolved})`},{index:r.index,old:r[0],replacement:r[0].slice(0,-1)+`\${${
|
|
1058
|
-
`),p=(typeof e.systemPrompt==`string`&&e.systemPrompt.trim()?e.systemPrompt:te).replace(/\{LEVELS\}/g,f).replace(/\{MAX\}/g,String(d)),m=X(JSON.stringify(p)),h=X(JSON.stringify(e.levels.map(e=>e.label)));return`function __tweakccRouterState(){return globalThis.__tweakccRouter||(globalThis.__tweakccRouter={level:void 0,effort:void 0,baseline:void 0,summary:void 0,prevUser:void 0,prevAssistant:void 0,pendingCompaction:void 0,pendingRewindCut:void 0,log:void 0,model:void 0,loaded:!1})}function __tweakccRouterSyncSelection(){var selected=null;try{selected=globalThis.__tweakccRouterSelectedModel?.()||null}catch(e){}var s=__tweakccRouterState();if(s.selectedModel!==selected){if(s.selectedModel!==void 0){s.generation=(s.generation||0)+1;s.routeAbort?.abort();s.level=void 0;s.effort=void 0;s.baseline=void 0;s.prevUser=void 0;s.prevAssistant=void 0;}s.selectedModel=selected;}return selected}globalThis.__tweakccRouterSyncSelection=__tweakccRouterSyncSelection;function __tweakccRouterTrunc(__s,__cap){if(typeof __s!=="string")return"";if(__s.length<=__cap)return __s;var __mk="\\n...["+(__s.length-__cap)+" chars omitted from the middle]...\\n";var __b=__cap-__mk.length;if(__b<0)__b=0;var __h=Math.floor(__b/2);return __s.slice(0,__h)+__mk+__s.slice(__s.length-(__b-__h))}function __tweakccRouterSid(){try{var __s=${u};return typeof __s==="string"&&__s?__s:null}catch(__e){return null}}function __tweakccRouterDir(){var __p=${r}("path"),__o=${r}("os");return __p.join(__o.homedir(),".tweakcc","router-state")}function __tweakccRouterFile(__sid){return ${r}("path").join(__tweakccRouterDir(),__sid+".json")}function __tweakccRouterLoad(__st){if(__st.loaded)return;__st.loaded=!0;try{var __sid=__tweakccRouterSid();if(!__sid)return;var __fs=${r}("fs"),__f=__tweakccRouterFile(__sid);if(__fs.existsSync(__f)){var __d=JSON.parse(__fs.readFileSync(__f,"utf8"));if(__d){if(typeof __d.summary==="string")__st.summary=__d.summary;if(Number.isInteger(__d.level))__st.level=__d.level;if(Array.isArray(__d.log))__st.log=__d.log}}__tweakccRouterPrune(__fs)}catch(__e){}}function __tweakccRouterSave(__st){try{var __sid=__tweakccRouterSid();if(!__sid)return;var __fs=${r}("fs"),__dir=__tweakccRouterDir(),__j=JSON.stringify({summary:__st.summary,level:__st.level,log:Array.isArray(__st.log)?__st.log:[],updatedAt:Date.now()});__fs.mkdir(__dir,{recursive:!0},function(){try{__fs.writeFile(__tweakccRouterFile(__sid),__j,function(){})}catch(__e){}})}catch(__e){}}function __tweakccRouterDrop(__st){try{var __sid=__tweakccRouterSid();if(!__sid)return;var __fs=${r}("fs"),__f=__tweakccRouterFile(__sid);if(__fs.existsSync(__f))__fs.unlinkSync(__f)}catch(__e){}}function __tweakccRouterPrune(__fs){try{var __dir=__tweakccRouterDir(),__ns=__fs.readdirSync(__dir),__now=Date.now(),__ttl=12096e5;for(var __i=0;__i<__ns.length;__i++){try{var __ff=${r}("path").join(__dir,__ns[__i]);if(__now-__fs.statSync(__ff).mtimeMs>__ttl)__fs.unlinkSync(__ff)}catch(__e){}}}catch(__e){}}function __tweakccRouterReadResult(__r){try{if(__r==null)return null;if(typeof __r==="object"&&typeof __r.level==="number")return{level:__r.level,summary:typeof __r.summary==="string"?__r.summary:void 0};var __x;if(typeof __r==="string")__x=__r;else{var __c=(__r.message&&__r.message.content)||__r.content;__x=(Array.isArray(__c)&&__c[0]&&typeof __c[0].text==="string")?__c[0].text:(typeof __r.text==="string"?__r.text:"")}if(!__x)return null;try{var __o=JSON.parse(__x);if(__o&&typeof __o.level==="number")return{level:__o.level,summary:typeof __o.summary==="string"?__o.summary:void 0}}catch(__e){}var __m=__x.match(/-?\\d+/);if(__m)return{level:parseInt(__m[0],10),summary:void 0};return null}catch(__e){return null}}async function __tweakccRouterClassifyLlm(__input,__max){var __schema={type:"object",properties:{level:{type:"integer",description:"effort level, 0 (least) to "+__max+" (most)"},summary:{type:"string",description:"the updated running TL;DR summary"}},required:["level","summary"],additionalProperties:false};var __sys=${m};var __ac=new AbortController();__tweakccRouterState().routeAbort=__ac;var __to=setTimeout(function(){try{__ac.abort()}catch(__e){}},${l});try{var __res=await ${t.gB}({systemPrompt:[__sys],userPrompt:__input,outputFormat:{type:"json_schema",schema:__schema},signal:__ac.signal,options:{querySource:"route_complexity",agents:[],isNonInteractiveSession:!1,hasAppendSystemPrompt:!1,mcpTools:[],agentContext:${t.km}()}});return __tweakccRouterReadResult(__res)}finally{clearTimeout(__to)}}async function ${tc}(__text,__mode,__model){try{var __selected=__tweakccRouterSyncSelection();if(!__selected)return;var __ef=${a},__pin=${o},__max=__ef.length-1,__labels=${h};if(!__ef||!__ef.length)return;var __st=__tweakccRouterState();if(typeof __text!=="string")return;var __tr=__text.replace(/^\\s+/,"");if(/^\\/clear(\\s|$)/.test(__tr)){__st.level=void 0;__st.effort=void 0;__st.baseline=void 0;__st.summary=void 0;__st.prevUser=void 0;__st.prevAssistant=void 0;__st.pendingCompaction=void 0;__st.pendingRewindCut=void 0;__st.log=void 0;__st.model=void 0;__tweakccRouterDrop(__st);return}if(__tr.charAt(0)==="/")return;if(__mode!==void 0&&__mode!=="prompt")return;__tweakccRouterLoad(__st);if(__st.pendingRewindCut!=null){var __rt=__st.pendingRewindCut;__st.pendingRewindCut=void 0;var __rms=typeof __rt==="number"?__rt:Date.parse(__rt),__ci=-1;if(__rms===__rms&&Array.isArray(__st.log))for(var __i=__st.log.length-1;__i>=0;__i--){if(__st.log[__i]&&__st.log[__i].ts<=__rms){__ci=__i;break}}if(__ci>=0){var __pe=__st.log[__ci];__st.summary=__pe.summary;__st.level=__pe.level;__st.log=__st.log.slice(0,__ci)}else{__st.summary=void 0;__st.level=void 0}__st.prevUser=void 0;__st.prevAssistant=void 0;__st.pendingCompaction=void 0;if(process.env.TWEAKCC_ROUTER_DEBUG)try{process.stderr.write("[tweakcc-router] rewind cut to "+__rt+" ("+(__ci>=0?"restored":"reset")+")\\n")}catch(__e){}}if(typeof __st.pendingCompaction==="string"){__st.summary=__st.pendingCompaction;__st.prevUser=void 0;__st.prevAssistant=void 0;__st.level=void 0;__st.pendingCompaction=void 0}if(!Array.isArray(__st.log))__st.log=[];__st.log.push({ts:Date.now(),summary:typeof __st.summary==="string"?__st.summary:"",level:__st.level});if(__st.log.length>${nc})__st.log.splice(0,__st.log.length-${nc});var __plv=__st.level,__pmod=__st.model;var __mch=__pmod&&__model&&__pmod!==__model;var __ctx="model in use: "+(__model||"unknown")+(__mch?" (switched from "+__pmod+" this turn)":"")+"\\nlevel you assigned last turn: "+(__plv!==void 0?__plv+" ("+(__labels[__plv]||"?")+")":"none yet - this is the first routed turn");var __nm=__tweakccRouterTrunc(__text,${s});var __pu=__tweakccRouterTrunc(__st.prevUser,${s});var __pa=__tweakccRouterTrunc(typeof __st.prevAssistant==="string"?__st.prevAssistant:"",${c});var __input="<summary>\\n"+(__st.summary||"(none - first turn of the session)")+"\\n</summary>\\n<context>\\n"+__ctx+"\\n</context>\\n<recent_exchange>\\nuser: "+(__pu||"(none)")+"\\nassistant: "+(__pa||"(none)")+"\\n</recent_exchange>\\n<new_message>\\n"+__nm+"\\n</new_message>";var __generation=__st.generation,__res=null;try{__res=await __tweakccRouterClassifyLlm(__input,__max)}catch(__e){__res=null}if(__tweakccRouterSyncSelection()!==__selected||__st.generation!==__generation)return;__st.routeAbort=null;var __hi=__ef.indexOf("high");if(__hi<0)__hi=Math.min(2,__max);var __lv,__sm=__st.summary;if(__res&&typeof __res.summary==="string"&&__res.summary)__sm=__res.summary;if(__res&&Number.isInteger(__res.level))__lv=__res.level;else __lv=(__st.level!==void 0?__st.level:__hi);if(__pin&&__st.level!==void 0&&__lv<__st.level)__lv=__st.level;if(__lv<0)__lv=0;if(__lv>__max)__lv=__max;__st.level=__lv;__st.effort=__ef[__lv];__st.summary=__sm;__st.prevUser=__text;__st.model=__model;__tweakccRouterSave(__st);if(process.env.TWEAKCC_ROUTER_DEBUG)try{process.stderr.write("[tweakcc-router] level="+__lv+" effort="+__st.effort+" chars="+__text.length+"\\n")}catch(__e){}}catch(__e){}}`},ic=(e,t,n,r)=>{let i=/(function [$\w]+\(([$\w]+),([$\w]+),\{honorLaunchPin:[$\w]+=!0\}=\{\}\)\{if\(![$\w]+\(\2\)\)return;let [$\w]+=[$\w]+&&[$\w]+\(\2\),[$\w]+=[$\w]+\(\2\),([$\w]+)=[$\w]+\(\);)if\(\4===null&&![$\w]+\)return;return ([$\w]+)\(\4\?\?\([$\w]+\?[$\w]+:void 0\)\?\?\3\?\?[$\w]+,\2\)\}/,a=/(function [$\w]+\(([$\w]+),([$\w]+)\)\{if\(![$\w]+\(\2\)\)return;let [$\w]+=[$\w]+\(\2\),[$\w]+=[$\w]+\(\2\),([$\w]+)=[$\w]+\(\);)if\(\4===null&&![$\w]+\)return;return ([$\w]+)\(\4\?\?\([$\w]+\?[$\w]+:void 0\)\?\?\3\?\?[$\w]+,\2\)\}/,o=/(function [$\w]+\(([$\w]+),([$\w]+)\)\{if\(![$\w]+\(\2\)\)return;let [$\w]+=[$\w]+\(\2\),[$\w]+=[$\w]+\(\2\),([$\w]+)=[$\w]+\(\);)if\(\4===null&&![$\w]+\)return;let ([$\w]+)=\4\?\?\([$\w]+\?[$\w]+:void 0\)\?\?\3\?\?[$\w]+;(?:if\(typeof \5==="string"&&[$\w]+\(\5\)\)\5=[$\w]+\(\5,\2\);)?if\(\5==="max"&&!([$\w]+)\(\2\)\)\5="high";if\(\5==="xhigh"&&!([$\w]+)\(\2\)\)\5="high";return \5\}/,s=/(function [$\w]+\(([$\w]+),([$\w]+)\)\{if\(![$\w]+\(\2\)\)return;let [$\w]+=[$\w]+\(\2\),[$\w]+=[$\w]+\(\2\),([$\w]+)=[$\w]+\(\);)if\(\4===null\)return [$\w]+\?[$\w]+:void 0;let ([$\w]+)=\4\?\?\([$\w]+\?[$\w]+:void 0\)\?\?\3\?\?[$\w]+;if\(\5==="max"&&!([$\w]+)\(\2\)\)return"high";if\(\5==="xhigh"&&!([$\w]+)\(\2\)\)return"high";return \5\}/,c=e.match(/(function [$\w]+\(([$\w]+),([$\w]+),\{turnEffort:([$\w]+),hookEffortValue:[$\w]+\}=\{\}\)\{if\(![$\w]+\(\2\)\)return;let [$\w]+=[$\w]+\(\2\)!==null;if\([$\w]+!==void 0\)\{let [$\w]+=typeof [$\w]+==="number"&&[$\w]+\?[$\w]+\([$\w]+\):[$\w]+;return [$\w]+\([$\w]+,\2\)\}let ([$\w]+)=[$\w]+\(\);)if\(\5===null&&![$\w]+\)return;let [$\w]+=[$\w]+\(\2\),([$\w]+)=\5\?\?\(\5===null\?[$\w]+:void 0\)\?\?\4\?\?\3\?\?[$\w]+;if\(typeof \6==="number"&&[$\w]+\)\6=[$\w]+\(\6\);return ([$\w]+)\(\6,\2\)\}/)||e.match(/(function [$\w]+\(([$\w]+),([$\w]+),\{honorLaunchPin:[$\w]+=!0,turnEffort:([$\w]+),hookEffortValue:[$\w]+\}=\{\}\)\{if\(![$\w]+\(\2\)\)return;let [$\w]+=[$\w]+\(\2\)!==null;if\([$\w]+!==void 0\)\{let [$\w]+=typeof [$\w]+==="number"&&[$\w]+\?[$\w]+\([$\w]+\):[$\w]+;return [$\w]+\([$\w]+,\2\)\}let [$\w]+=[$\w]+&&[$\w]+\(\2\),[$\w]+=[$\w]+\(\2\),([$\w]+)=[$\w]+\(\);)if\(\5===null&&![$\w]+&&![$\w]+\)return;let ([$\w]+)=\5\?\?\(\5===null\?[$\w]+:void 0\)\?\?\4\?\?\([$\w]+\?[$\w]+:void 0\)\?\?\3\?\?[$\w]+;if\(typeof \6==="number"&&[$\w]+\)\6=[$\w]+\(\6\);return ([$\w]+)\(\6,\2\)\}/)||e.match(/(function [$\w]+\(([$\w]+),([$\w]+),\{honorLaunchPin:[$\w]+=!0,turnEffort:([$\w]+)\}=\{\}\)\{if\(![$\w]+\(\2\)\)return;let [$\w]+=[$\w]+&&[$\w]+\(\2\),[$\w]+=[$\w]+\(\2\),([$\w]+)=[$\w]+\(\),[$\w]+=[$\w]+\(\2\)!==null;)if\(\5===null&&![$\w]+&&![$\w]+\)return;let ([$\w]+)=\5\?\?\(\5===null\?[$\w]+:void 0\)\?\?\4\?\?\([$\w]+\?[$\w]+:void 0\)\?\?\3\?\?[$\w]+;if\(typeof \6==="number"&&[$\w]+\)\6=[$\w]+\(\6\);return ([$\w]+)\(\6,\2\)\}/),l=c?null:e.match(i)||e.match(a),u=c||l||e.match(o)||e.match(s);if(!u||u.index===void 0)return e.includes(`CLAUDE_CODE_EFFORT_LEVEL`)?(console.error(`patch: complexityRouter: failed to find effort resolver (XQ shape)`),null):(J(`patch: complexityRouter: effort resolver absent in this CC build - no-op`),e);let d=u[1],f=u[2],p=u[3],m=c?c[4]:null,h=c?c[5]:u[4],g=u[6],_=u[7],v=c?c[7]:l?.[5];if(v){let t=v.replace(/[$]/g,`\\$`),n=RegExp(`function ${t}\\(([$\\w]+),([$\\w]+)\\)\\{let ([$\\w]+)=\\1;(?:if\\(typeof \\3==="string"&&[$\\w]+\\(\\3\\)\\)\\3=[$\\w]+\\(\\3,\\2\\);)?if\\(\\3==="max"&&!([$\\w]+)\\(\\2\\)\\)\\3="high";if\\(\\3==="xhigh"&&!([$\\w]+)\\(\\2\\)\\)\\3="high";return \\3\\}`),r=e.match(n);if(!r)return console.error(`patch: complexityRouter: failed to find effort normalizer (support guards)`),null;g=r[4],_=r[5]}let y=`var __request=arguments[3];if(!__request||(!__request.agentId&&(__request.querySource?.startsWith("repl_main_thread")||__request.querySource==="sdk"))){var __selected=__tweakccRouterSyncSelection();var __st=__tweakccRouterState();if(__selected===${f}&&__st.baseline===void 0)__st.baseline=(${p}==null?null:${p});let __twkRE=__selected===${f}?__st.effort:void 0;if(__twkRE&&${h}==null${m?`&&${m}==null`:``}&&(${p}==null||${p}===__st.baseline)){if(__twkRE==="max"&&!${g}(${f}))__twkRE="high";if(__twkRE==="xhigh"&&!${_}(${f}))__twkRE="high";globalThis.__tweakccRouterResolution={effort:__twkRE};return __twkRE}}`,b=(t.provider===`jev`?$s:rc)(t,n,r,Vs(e)?`process.getBuiltinModule`:Fl(e));Vs(e)&&t.provider!==`jev`&&(b+=`globalThis.__tweakccRouterState=__tweakccRouterState;globalThis.__tweakccRouterClassify=__tweakccRouterClassify;`);let x=b+d+y+u[0].slice(d.length),S=u.index,C=S+u[0].length,w=e.slice(0,S)+x+e.slice(C);return B(e,w,x,S,C),w},ac=(e,t)=>{let n=e.match(/if\(([$\w]+)===null&&([$\w]+)!=="prompt"\)throw Error\(`Mode: \$\{\2\} requires a string input\.`\);/);if(!n||n.index===void 0)return e.includes(`requires a string input.`)?(console.error(`patch: complexityRouter: failed to find submit handler throw-guard`),null):(J(`patch: complexityRouter: submit handler absent in this CC build - no-op`),e);let r=n[1],i=n[2],a=[...e.slice(Math.max(0,n.index-4e3),n.index).matchAll(/([$\w]+)\.options\.mainLoopModel/g)],o=a[a.length-1],s=o?`${o[1]}.options.mainLoopModel`:`void 0`,c=o?`${o[1]}.messages`:`void 0`,l=o?`${o[1]}.session?.id`:`void 0`,u=`await ${Vs(e)?`globalThis.${tc}`:tc}(${`${r},${i},${s}${t?`,${c},${l}`:``}`});`,d=t?`try{${o?`if(!${o[1]}.agentId)`:``}{${o?`${o[1]}.__tweakccRouterTurn=`:``}${u}}}catch(__tweakccRouterError){}`:u,f=n.index+n[0].length,p=e.slice(0,f)+d+e.slice(f);return B(e,p,d,f,f),p},oc=e=>{if(e.includes(`function __tweakccRouterObserve(`)){let t=e.match(/let [$\w]+;if\(([$\w]+)\.gates\.emitToolUseSummaries&&[$\w]+\.length>0&&!([$\w]+)\.abortController\.signal\.aborted&&!\2\.agentId\)\{let [$\w]+=([$\w]+)\.at\(-1\)/);if(t?.index!==void 0){let n=e.slice(t.index,t.index+2e3).match(/([$\w]+)\.find\(\([$\w]+\)=>[$\w]+\.type==="user"&&Array\.isArray/),r=Vs(e)?`globalThis.__tweakccRouterObserve`:`__tweakccRouterObserve`,i=`try{if(!${t[2]}.agentId)${r}(${t[3]}${n?`.concat(${n[1]})`:``},${t[2]}.session?.id,${t[2]}.__tweakccRouterTurn);}catch(__tweakccRouterError){}`;return e.slice(0,t.index)+i+e.slice(t.index)}return J(`patch: complexityRouter: round capture absent - transcript refresh occurs at submit`),e}let t=e.match(/([$\w]+)=([$\w]+)\.at\(-1\),([$\w]+);if\(\1\)\{let ([$\w]+)=\1\.message\.content\.filter\(\(([$\w]+)\)=>\5\.type==="text"\);if\(\4\.length>0\)\{let ([$\w]+)=\4\.at\(-1\);if\(\6&&"text"in \6\)\3=\6\.text\}\}/);if(!t||t.index===void 0)return J(`patch: complexityRouter: prev-assistant capture site absent - router runs without prior-assistant context`),e;let n=`try{var __twr=globalThis.__tweakccRouter;if(__twr&&globalThis.__tweakccRouterSyncSelection?.())__twr.prevAssistant=${t[3]}}catch(__e){}`,r=t.index+t[0].length,i=e.slice(0,r)+n+e.slice(r);return B(e,i,n,r,r),i},sc=e=>{let t=e.match(/return\{ok:!0,summaryText:([$\w]+),/);if(!t||t.index===void 0)return J(`patch: complexityRouter: compaction summary site absent - no compaction reseed`),e;let n=t[1],r=`return globalThis.__tweakccRouter&&((typeof globalThis.__tweakccRouterInvalidate==="function"&&globalThis.__tweakccRouterInvalidate(globalThis.__tweakccRouter),globalThis.__tweakccRouter.pendingCompaction=${n})),{ok:!0,summaryText:${n},`,i=t.index,a=i+t[0].length,o=e.slice(0,i)+r+e.slice(a);return B(e,o,r,i,a),o},cc=e=>{let t=e.match(/onRestoreMessage:\(([$\w]+)\)=>([$\w]+(?:\.[$\w]+)?)\(\1,"message_selector"\)/);if(!t||t.index===void 0)return J(`patch: complexityRouter: restore-conversation site absent - no rewind cut`),e;let n=t[1],r=`onRestoreMessage:(${n})=>(globalThis.__tweakccRouter&&((typeof globalThis.__tweakccRouterInvalidate==="function"&&globalThis.__tweakccRouterInvalidate(globalThis.__tweakccRouter),globalThis.__tweakccRouter.pendingRewindCut=${n}&&${n}.timestamp)),${t[2]}(${n},"message_selector"))`,i=t.index,a=i+t[0].length,o=e.slice(0,i)+r+e.slice(a);return B(e,o,r,i,a),o},lc=e=>{let t=e.match(/function ([$\w]+)\(\)\{return\{agentType:"main",agentId:[$\w]+\(\)\}\}/);if(!t)return null;let n=e.match(/async function ([$\w]+)\(([$\w]+)\)\{(let ([$\w]+)=)([$\w]+\([$\w]+\(\)\)),[\s\S]{0,600}?return await [$\w]+\(\2,[$\w]+\[[$\w]+\],[$\w]+\[[$\w]+\+1\]\)/);if(n){let[e,r,i,a,,o]=n,s=`async function ${r}(${i}){${a}${o},`;return{gB:r,km:t[1],gBIndex:n.index,kmIndex:t.index,gBSource:e,gBOptions:`${i}.options`,gBPatched:`async function ${r}(${i}){${a}${i}.options.querySource==="route_complexity"?"claude-haiku-4-5":${o},`+e.slice(s.length)}}let r=e.match(/async function ([$\w]+)\(\{systemPrompt:[$\w]+=[$\w]+\(\[\]\),userPrompt:[$\w]+,outputFormat:[$\w]+,signal:[$\w]+,options:([$\w]+)\}\)\{return\(await [$\w]+\([\s\S]{0,500}?,model:[$\w]+\(\),enablePromptCaching:/);return r?{gB:r[1],km:t[1],gBIndex:r.index,kmIndex:t.index,gBSource:r[0],gBOptions:r[2],gBPatched:r[0].replace(/model:([$\w]+)\(\),enablePromptCaching:$/,`model:${r[2]}.querySource==="route_complexity"?"claude-haiku-4-5":$1(),enablePromptCaching:`)}:null},uc=e=>{let t=e.match(/getSessionId\(\)\{return ([$\w]+)\(\)\}/);return t?t[1]:null},dc=(e,t)=>{if(e.includes(tc))return J(`patch: complexityRouter: already patched - skipping`),e;let n=lc(e);if(!n)return console.warn(`patch: complexityRouter: gB/km side-call helpers not found in this CC build - cannot maintain routing context; skipping the router`),e;let r=uc(e);r||J(`patch: complexityRouter: session-id accessor not found - cross-session summary persistence disabled (in-memory only)`);let i=Hs(e,n);if(!i)return null;i.file=i.file.replace(n.gBSource,()=>n.gBPatched);let a=ic(i.file,t,i.helpers,r);if(a===null)return null;if(a===i.file)return e;let o=ac(a,t.provider===`jev`);if(o===null)return null;if(o===a)return J(`patch: complexityRouter: submit handler absent - reverting the resolver wrap too (all-or-nothing no-op)`),e;let s=oc(o);return ec(cc(t.provider===`jev`?s:sc(s)))},fc=[[`opusrouter`,`claude-opus-5-5`,`Opus 5.5 + Effort Router`],[`fablerouter`,`claude-fable-5-1`,`Fable 5.1 + Effort Router`]],pc=e=>`(${e}==="opusrouter"||${e}==="fablerouter")`,mc=(e,t,n,r)=>{let i=e.match(t);if(!i||i.index===void 0)return console.error(`patch: complexityRouterModels: failed to find ${r}`),null;let a=X(n(i)),o=e.slice(0,i.index)+a+e.slice(i.index+i[0].length);return B(e,o,a,i.index,i.index+i[0].length),o},hc=e=>{let t=mc(e,/(=[$\w]+\(\(([$\w]+)\)=>\{let ([$\w]+)=[$\w]+\(\),([$\w]+)=[$\w]+\.find\(\(([$\w]+)\)=>\5\.value===\3\);if\(\4===void 0\|\|\4\.disabled===!0\)return;)/,e=>`${e[0]}if(${pc(e[3])})return;`,`picker effort adjustment`);if(t===null)return null;let n=/(([$\w]+)!==void 0&&![$\w]+&&[$\w]+\([$\w]+,\{marginBottom:1,flexDirection:"column",children:)/,r=t.match(/([$\w]+)\(([$\w]+),\{color:"subtle",children:\[[$\w]+\([$\w]+,\{effort:void 0\}\)," Effort not supported"/);if(!r||(t=mc(t,n,e=>`${e[0]}${pc(e[2])}?${r[1]}(${r[2]},{color:"subtle",children:"Automatic effort"+(globalThis.__tweakccRouterState?.()?.effort?" · currently "+globalThis.__tweakccRouterState().effort:"")}):`,`picker effort display`),t===null))return null;let i=[/(function ([$\w]+)\(([$\w]+)\)\{)((?:if\(\3==="fableplan"\)\{[$\w]+\(\3,void 0\);return\})?let ([$\w]+)=[$\w]+\(\3\),(?:[$\w]+=[$\w]+\(\),)*[$\w]+=\5&&([$\w]+)!==void 0\?[$\w]+\(\6,\5\):\6;[$\w]+\("tengu_model_command_menu_effort")/,/(function ([$\w]+)\(([$\w]+)\)\{)((?:if\(\3==="fableplan"\)\{[$\w]+\(\3,void 0\);return\})?let ([$\w]+)=[$\w]+\(\3\),(?:[$\w]+=[$\w]+\(\),)*[$\w]+=\5&&([$\w]+)!==void 0&&\6!=="ultracode"\?[$\w]+\(\6,\5\):\6;[$\w]+\("tengu_model_command_menu_effort")/],a=i.find(e=>e.test(t))??i[i.length-1];return mc(t,a,e=>{let n=t.slice(e.index+e[0].length).match(RegExp(`^(?:(?!function )[^])*?if\\(${e[3].replace(/\$/g,`\\$`)}===[$\\w]+\\)\\{([$\\w]+)\\(null,[$\\w]+\\);return\\}`));if(!n)throw Error(`Router picker apply call is missing`);return`${e[1]}if(${pc(e[3])}){${n[1]}(${e[3]},void 0);return}${e[4]}`},`picker model commit`)},gc=e=>{if(e.includes(`globalThis.__tweakccRouterSelectedModel=function(`))return e;if(!e.includes(`"claude-opus-5-5"`))return J(`patch: complexityRouterModels: verified models unavailable — no-op`),e;let t=e.match(/function ([$\w]+)\(([$\w]+)\)\{let [$\w]+=\2\.trim\(\)[\s\S]{0,120}?if\([$\w]+\(([$\w]+)\)\)switch\(\3\)\{/);if(!t)return null;let n=fc.map(([e,t])=>`case"${e}":return"${t}";`).join(``),r=mc(e,/(\[(?:"[\w[\]]+",)*"opusplan"(?:,"[\w[\]]+")*\])(\s*,\s*[$\w]+\s*=\s*\["sonnet","opus","haiku")/,e=>`${e[1].slice(0,-1)},"opusrouter","fablerouter"]${e[2]}`,`model alias whitelist`);if(r===null)return null;let i=r.indexOf(t[0]),a=r.replace(t[0],t[0]+n);if(B(r,a,t[0]+n,i,i+t[0].length),r=a,r=mc(r,/(function [$\w]+\([$\w]+\)\{let [$\w]+=[$\w]+\(\);switch\([$\w]+\)\{case"opus":return [$\w]+\([$\w]+\);)/,e=>e[0]+n,`builtin model defaults`),r===null||(r=mc(r,/function ([$\w]+)\(\)\{let ([$\w]+)=[$\w]+\(\);if\(\2!==void 0\)return [$\w]+\(\2,"explicit"\);return [$\w]+\(\)\}/,e=>`globalThis.__tweakccRouterSelectedModel=function(){let __tweakccSelected=${e[1]}();return __tweakccSelected==="opusrouter"?"claude-opus-5-5":__tweakccSelected==="fablerouter"?"claude-fable-5-1":null};${e[0]}`,`live selected model getter`),r===null))return null;for(let e of[`overrideMainLoopModel`,`replaceInitialMainLoopModel`])if(r=mc(r,RegExp(`(${e}\\(([$\\w]+)\\)\\{this\\.#[$\\w]+=\\2)\\}`),e=>`${e[1]};queueMicrotask(()=>globalThis.__tweakccRouterSyncSelection?.())}`,`selected model setter`),r===null)return null;if(r=mc(r,/function ([$\w]+)\(([$\w]+)=!1,([$\w]+)=null\)\{let ([$\w]+)=new Set,([$\w]+)=[$\w]+\(\2,\3\)\.filter\(\(([$\w]+)\)=>\{if\(\6\.value===null\)return!0;if\(\4\.has\(\6\.value\)\)/,e=>`function ${e[1]}(${e[2]}=!1,${e[3]}=null){let rows=__tweakccRouterBasePicker(${e[2]},${e[3]});let clean=rows.filter(row=>!${pc(`row.value`)});for(let [alias,model,label] of ${JSON.stringify(fc)}){let index=clean.findIndex(row=>typeof row.value==="string"&&row.disabled!==!0&&${t[1]}(row.value)===model);if(index!==-1)clean.splice(index+1,0,{...clean[index],value:alias,label,description:"Automatic effort selected for each message"})}return clean}function __tweakccRouterBasePicker`+e[0].slice(`function ${e[1]}`.length),`filtered model picker`),r===null)return null;try{return hc(r)}catch{return console.error(`patch: complexityRouterModels: failed to find picker apply`),null}},W=`fableplan`,_c=`globalThis.__tweakccFablePlanModel`,vc=e=>{let t=e.match(/(\[(?:"[\w[\]]+",)*"opusplan"(?:,"[\w[\]]+")*\])(\s*,\s*[$\w]+\s*=\s*\["sonnet","opus","haiku")/);if(t&&t[1].includes(`"${W}"`))return J(`patch: fablePlan: alias already in the whitelist — skipping`),e;if(!t||t.index===void 0)return console.error(`patch: fablePlan: failed to find the model alias whitelist`),null;let n=t[1].slice(0,-1)+`,"${W}"]`+t[2],r=e.slice(0,t.index)+n+e.slice(t.index+t[0].length);return B(e,r,n,t.index,t.index+t[0].length),r},yc=(e,t,n)=>{let r=e.match(/(function ([$\w]+)\(([$\w]+)\)\{let\{permissionMode:([$\w]+),mainLoopModel:([$\w]+),exceeds200kTokens:([$\w]+)=!1\}=\3;)(if\(\4!=="plan"\)return\{model:\5,clampWarning:null\};let [$\w]+=([$\w]+)\(\),)/),i=r?null:e.match(/(function ([$\w]+)\(([$\w]+)\)\{let\{permissionMode:([$\w]+),mainLoopModel:([$\w]+),exceeds200kTokens:([$\w]+)=!1\}=\3;)(if\(\4!=="plan"\)return \5;let [$\w]+=([$\w]+)\(\),)/),a=r||i?null:e.match(/(function ([$\w]+)\(([$\w]+)\)\{let\{permissionMode:([$\w]+),mainLoopModel:([$\w]+),exceeds200kTokens:([$\w]+)=!1\}=\3,([$\w]+)=([$\w]+)\(\);)/),o=r??i??a;if(!o||o.index===void 0)return console.error(`patch: fablePlan: failed to find the plan-mode model resolver (uM shape)`),null;let s=o[1],c=o[4],l=r??i,u=l?`${o[8]}()`:o[7],d=l?o[7]:``,f=s+`if(${u}==="${W}"){${_c}=${`${n}(${c}==="plan"?"${t.planModel}":"${t.execModel}")`};${r?`return{model:${_c},clampWarning:null}`:`return ${_c}`}}${_c}=void 0;`+d,p=e.slice(0,o.index)+f+e.slice(o.index+o[0].length);return B(e,p,f,o.index,o.index+o[0].length),p},bc=(e,t)=>{let n=RegExp(`(switch\\(([$\\w]+)\\)\\{(?:case"[\\w]+":return [$\\w]+\\([$\\w]+\\);)*?case"${t.execModel}":return ([$\\w]+)\\(([$\\w]+)\\);)`),r=e.match(n);if(!r||r.index===void 0)return console.error(`patch: fablePlan: failed to find the builtin-default alias switch`),null;let i=`${r[1]}case"${W}":return ${r[3]}(${r[4]});`,a=e.slice(0,r.index)+i+e.slice(r.index+r[0].length);return B(e,a,i,r.index,r.index+r[0].length),a},xc=(e,t)=>{let n=RegExp(`function ([$\\w]+)\\(([$\\w]+)\\)\\{let [$\\w]+=\\2\\.trim\\(\\)[\\s\\S]{0,120}?if\\([$\\w]+\\(([$\\w]+)\\)\\)switch\\(\\3\\)\\{([\\s\\S]{0,600}?case"${t.execModel}":(return [^;]+;))`),r=e.match(n);if(!r||r.index===void 0)return console.error(`patch: fablePlan: failed to find the alias-to-model resolver (as shape)`),null;let i=r[1],a=r[0],o=`${a}case"${W}":${r[5]}`,s=e.slice(0,r.index)+o+e.slice(r.index+a.length);return B(e,s,o,r.index,r.index+a.length),{file:s,resolver:i}},Sc=(e,t)=>{let n=/(function [$\w]+\(([$\w]+),([$\w]+)\)\{let ([$\w]+)=[$\w]+\(\2\),([$\w]+)=[$\w]+\.ANTHROPIC_CUSTOM_MODEL_OPTION;)/,r=e.match(/(function [$\w]+\(([$\w]+),([$\w]+)\)\{let ([$\w]+)=[$\w]+\(\2,\3\),([$\w]+)=\4\?\?[$\w]+\(\2\),[^;]*;)(?=(?:(?!function )[^])*?[$\w]+\.ANTHROPIC_CUSTOM_MODEL_OPTION;)/)??e.match(/(function [$\w]+\(([$\w]+),([$\w]+)\)\{let ([$\w]+)=[$\w]+\(\2,\3\),([$\w]+)=\4\?\?[$\w]+\(\2\),([$\w]+)=[$\w]+\.ANTHROPIC_CUSTOM_MODEL_OPTION;)/),i=r??e.match(n);if(!i||i.index===void 0)return console.error(`patch: fablePlan: failed to find the model picker options`),null;let a=r?i[5]:i[4],o=`${Ec(t.planModel)} Plan Mode`,s=`Use ${Ec(t.planModel)} in plan mode, ${Ec(t.execModel)} otherwise`,c=`if(!${a}.some((z)=>z.value==="${W}"))${a}.push(${JSON.stringify({value:W,label:o,description:s})});`,l=i[1]+c,u=e.slice(0,i.index)+l+e.slice(i.index+i[0].length);return B(e,u,l,i.index,i.index+i[0].length),u},Cc=e=>{if(e.includes(`settingsEffortTable,${_c}??`))return J(`patch: fablePlan: effort lookup already keyed — skipping`),e;let t=e.match(/(case"inherit":if\(([$\w]+)\.settingsEffortTable===void 0\)return;if\(!?[$\w]+\(\2\.settingsEffortTable\)\)return \2\.settingsEffortTable\.default;return [$\w]+\(\2\.settingsEffortTable,)/);if(!t||t.index===void 0)return e.includes(`settingsEffortTable`)?(console.error(`patch: fablePlan: failed to find the per-model effort lookup`),null):(J(`patch: fablePlan: no per-model effort table in this build — effort follows the session`),e);let n=`${t[1]}${_c}??`,r=e.slice(0,t.index)+n+e.slice(t.index+t[0].length);return B(e,r,n,t.index,t.index+t[0].length),r},wc=(e,t)=>{if(!e.includes(`"modelPicker:decreaseEffort"`))return J(`patch: fablePlan: no model-picker effort control in this build`),e;if(e.includes(`==="${W}")return;let `))return J(`patch: fablePlan: picker effort row already handled — skipping`),e;let n=/(=[$\w]+\(\(([$\w]+)\)=>\{let ([$\w]+)=[$\w]+\(\),([$\w]+)=[$\w]+\.find\(\(([$\w]+)\)=>\5\.value===\3\);if\(\4===void 0\|\|\4\.disabled===!0\)return;)(let ([$\w]+)=[$\w]+\(\3\);if\(!\7\.supportsEffort\)return;)/,r=/(([$\w]+)!==void 0&&![$\w]+&&[$\w]+\([$\w]+,\{marginBottom:1,flexDirection:"column",children:)([$\w]+\?)/,i=/([$\w]+)\(([$\w]+),\{color:"subtle",children:\[[$\w]+\([$\w]+,\{effort:void 0\}\)," Effort not supported"/,a=[/(function ([$\w]+)\(([$\w]+)\)\{)(let ([$\w]+)=[$\w]+\(\3\),(?:[$\w]+=[$\w]+\(\),)*[$\w]+=\5&&([$\w]+)!==void 0\?[$\w]+\(\6,\5\):\6;[$\w]+\("tengu_model_command_menu_effort")/,/(function ([$\w]+)\(([$\w]+)\)\{)(let ([$\w]+)=[$\w]+\(\3\),(?:[$\w]+=[$\w]+\(\),)*[$\w]+=\5&&([$\w]+)!==void 0&&\6!=="ultracode"\?[$\w]+\(\6,\5\):\6;[$\w]+\("tengu_model_command_menu_effort")/,/(function ([$\w]+)\(([$\w]+)\)\{)(let ([$\w]+)=[$\w]+\(\3\),[$\w]+=\5&&[$\w]+!==void 0&&[$\w]+!=="ultracode"\?[$\w]+\([$\w]+,\5\):[$\w]+;if\([$\w]+\("tengu_model_command_menu_effort")/],o=e.match(n),s=e.match(r),c=e.match(i),l=null;for(let t of a)if(l=e.match(t),l)break;if(!o||o.index===void 0||!s||s.index===void 0||!c||!l||l.index===void 0)return console.error(`patch: fablePlan: failed to find the model picker effort control`),null;let u=e.slice(l.index+l[1].length).match(RegExp(`^(?:(?!function )[^])*?if\\(${l[3].replace(/\$/g,`\\$`)}===[$\\w]+\\)\\{([$\\w]+)\\(null,[$\\w]+\\);return\\}`));if(!u)return console.error(`patch: fablePlan: failed to find the model picker apply call`),null;let d=JSON.stringify(`${Ec(t.planModel)} and ${Ec(t.execModel)} each use their own effort (set it on their rows)`),f=[[o.index,o.index+o[0].length,`${o[1]}if(${o[3]}==="${W}")return;${o[6]}`],[s.index,s.index+s[0].length,`${s[1]}${s[2]}==="${W}"?${c[1]}(${c[2]},{color:"subtle",children:[${d}]}):${s[3]}`],[l.index,l.index+l[0].length,`${l[1]}if(${l[3]}==="${W}"){${u[1]}(${l[3]},void 0);return}${l[4]}`]],p=e;for(let[e,t,n]of f.sort((e,t)=>t[0]-e[0]))p=p.slice(0,e)+n+p.slice(t);return B(e,p,f.map(e=>e[2]).join(` … `),o.index,o.index),p},Tc=e=>{let t=e.match(/(=[$\w]+\(\([$\w]+\)=>[$\w]+\.settings\.showClearContextOnPlanAccept\)\?\?)!1/);if(!t||t.index===void 0)return J(`patch: fablePlan: showClearContextOnPlanAccept gate not present — no-op`),e;let n=`${t[1]}!0`,r=e.slice(0,t.index)+n+e.slice(t.index+t[0].length);return B(e,r,n,t.index,t.index+t[0].length),r},Ec=e=>e.charAt(0).toUpperCase()+e.slice(1),Dc=RegExp(`\\["sonnet",(?:"[\\w[\\]]+",)*"${W}"[,\\]]`),Oc=(e,t)=>{if(Dc.test(e))return J(`patch: fablePlan: already applied — no-op`),e;if(t.planModel===t.execModel)return console.error(`patch: fablePlan: planModel and execModel are the same — nothing to pair`),null;let n=xc(e,t);if(!n)return null;let r=n.file,i=vc(r);if(!i)return null;r=i;let a=yc(r,t,n.resolver);if(!a)return null;r=a;let o=bc(r,t);if(!o)return null;r=o;let s=Sc(r,t);if(!s)return null;r=s;let c=Cc(r);if(!c)return null;r=c;let l=wc(r,t);if(!l)return null;if(r=l,t.offerClearContextOnPlanAccept){let e=Tc(r);if(!e)return null;r=e}return r},kc=(e,t)=>{let n=`return !0;`,r=e.slice(0,t)+n+e.slice(t);return B(e,r,n,t,t),r},Ac=e=>{let t=e.indexOf(`"allow_voice_mode"`);if(t!==-1){let n=Math.max(0,t-800),r=e.slice(n,t+400).match(/function ([$\w]+)\(\)\{return [$\w]+\(\)&&[$\w]+\(\)\}/);if(r&&r.index!==void 0){let t=n+r.index,i=e.indexOf(`{`,t);if(i!==-1)return e.startsWith(`return !0;`,i+1)?e:kc(e,i+1)}let i=e.match(/name:"voice",description:"Toggle voice mode"[\s\S]{0,500}?get isHidden\(\)\{return![$\w]+\(\)\}/);if(i&&i.index!==void 0){let t=i[0].replace(/get isHidden\(\)\{return![$\w]+\(\)\}/,`get isHidden(){return!1}`);if(i[0]===t)return e;let n=e.slice(0,i.index)+t+e.slice(i.index+i[0].length);return B(e,n,t,i.index,i.index+i[0].length),n}}let n=e.match(/function [$\w]+\(\)\{return [$\w]+\("tengu_amber_quartz"/);if(n&&n.index!==void 0){let t=n.index+n[0].indexOf(`{`)+1,r=`return !0;`,i=e.slice(0,t)+r+e.slice(t);return B(e,i,r,t,t),i}let r=e.match(/function [$\w]+\(\)\{return![$\w]+\("tengu_amber_quartz_disabled"/);if(r&&r.index!==void 0){let t=r.index+r[0].indexOf(`{`)+1,n=`return !0;`,i=e.slice(0,t)+n+e.slice(t);return B(e,i,n,t,t),i}let i=e.match(/name:"voice",description:"Toggle voice mode"[\s\S]{0,500}?get isHidden\(\)\{return!([$\w]+)\(\)\}/);if(i&&i.index!==void 0){let t=i[1].replace(/[$]/g,`\\$`),n=RegExp(`function ${t}\\(\\)\\{`),r=e.match(n);if(r&&r.index!==void 0){let t=r.index+r[0].length,n=`return !0;`,i=e.slice(0,t)+n+e.slice(t);return B(e,i,n,t,t),i}}return console.error(`patch: voiceMode: failed to find tengu_amber_quartz gate`),null},jc=e=>{let t=e.match(/if\([$\w]+\("tengu_sotto_voce",!1\)\)/);if(!t||t.index===void 0)return e;let n=`if(!0)`,r=e.slice(0,t.index)+n+e.slice(t.index+t[0].length);return B(e,r,n,t.index,t.index+t[0].length),r},Mc=(e,t)=>{let n=Ac(e);return!n||t&&(n=jc(n),!n)?null:n},Nc=e=>{let t=e.match(/function [$\w]+\(\)\{return [$\w]+\("tengu_harbor",!1\)/);if(!t||t.index===void 0)return console.error(`patch: channelsMode: failed to find tengu_harbor gate`),null;let n=t.index+t[0].indexOf(`{`)+1,r=`return !0;`,i=e.slice(0,n)+r+e.slice(n);return B(e,i,r,n,n),i},Pc=e=>{let t=e.match(/reason:"server did not declare claude\/channel capability"\};?/);if(!t||t.index===void 0)return console.error(`patch: channelsMode: failed to find gateChannelServer capability check`),null;let n=t.index+t[0].length,r=`return{action:"register"};`,i=e.slice(0,n)+r+e.slice(n);return B(e,i,r,n,n),i},Fc=e=>{let t=e.match(/function [$\w]+\(\)\{return [$\w]+\("tengu_harbor_permissions",!1\)/);if(!t||t.index===void 0)return console.error(`patch: channelsMode: failed to find tengu_harbor_permissions gate`),null;let n=t.index+t[0].indexOf(`{`)+1,r=`return !0;`,i=e.slice(0,n)+r+e.slice(n);return B(e,i,r,n,n),i},Ic=e=>{let t=e.match(/"Channels \(experimental\) messages from ",([$\w]+),"[^"]*restart without "/);if(t&&t.index!==void 0){let n=`"Channels active \\xB7 messages from ",${t[1]}," \\xB7 restart without "`,r=t.index,i=r+t[0].length,a=e.slice(0,r)+n+e.slice(i);return B(e,a,n,r,i),a}let n=e.match(/Experimental[^"]*?inbound messages will be pushed into this session, this carries prompt injection risks\. Restart Claude Code without /);if(n&&n.index!==void 0){let t=`Channels active. Restart Claude Code without `,r=n.index,i=r+n[0].length,a=e.slice(0,r)+t+e.slice(i);return B(e,a,t,r,i),a}return console.error(`patch: channelsMode: failed to find ChannelsNotice warning text`),null},Lc=e=>{let t=e.match(/if\(![$\w]+\.dev\)[$\w]+\.push\(\{[$\w]+:[$\w]+,[$\w]+:"server: entries need --dangerously-load-development-channels"\}\)/);if(!t||t.index===void 0)return console.error(`patch: channelsMode: failed to find server dev-flag warning block`),null;let n=t.index,r=n+t[0].length,i=e.slice(0,n)+``+e.slice(r);return B(e,i,``,n,r),i},Rc=e=>{let t=Nc(e);return!t||(t=Pc(t),!t)||(t=Fc(t),!t)||(t=Ic(t),!t)||(t=Lc(t),!t)?null:t},zc=e=>{if(/name:"clear-screen"/.test(e))return e;let t=e.match(/([,;{}])(function [$\w]+\(\)\{)([$\w]+\(\))\.get\(process\.stdout\)\?\.forceRedraw\(\)\}/)||e.match(/([,;{}])(function [$\w]+\(\)\{)([$\w]+)\.get\(process\.stdout\)\?\.forceRedraw\(\)\}/);if(!t||t.index===void 0)return J(`patch: clearScreen: failed to find forceRedraw function`),null;let n=`${t[1]}globalThis.__tweakccForceRedraw=()=>${t[3]}.get(process.stdout)?.forceRedraw();`+t[0].slice(1),r=e.slice(0,t.index)+n+e.slice(t.index+t[0].length);B(e,r,n,t.index,t.index+t[0].length);let i=Bc(r);return i?(r=i,Hi(r,`,{type:"local",name:"clear-screen",description:"Clear screen without resetting conversation context",supportsNonInteractive:!1,load:()=>Promise.resolve().then(()=>({call:(H,$)=>{$.setMessages(m=>{globalThis.__tweakccHiddenUUIDs=new Set(m.map(x=>x.uuid?.slice(0,24)).filter(Boolean));return[...m]});process.stdout.write("\\x1b[2J\\x1b[H\\x1b[3J");globalThis.__tweakccForceRedraw?.();return{type:"skip"}}}))}`)||(J(`patch: clearScreen: failed to register slash command`),null)):(J(`patch: clearScreen: failed to patch render filter g97`),null)},Bc=e=>{let t=e.match(/([,;{}])(function [$\w]+\(([$\w]+),[$\w]+\)\{)if\(\3\.type!=="user"\)return!0;if\(\3\.isMeta\)/);if(!t||t.index===void 0)return null;let n=t[1],r=t[2],i=`${n}${r}if(globalThis.__tweakccHiddenUUIDs?.has(${t[3]}.uuid?.slice(0,24)))return!1;`+t[0].slice(n.length+r.length),a=e.slice(0,t.index)+i+e.slice(t.index+t[0].length);return B(e,a,i,t.index,t.index+t[0].length),a},Vc=[`red`,`blue`,`green`,`yellow`,`purple`,`orange`,`pink`,`cyan`],Hc=/\.\.\.([$\w]+)&&\{standaloneAgentContext:\{name:\1\}\}/,Uc=e=>`,...(()=>{let __c=process.env.TWEAKCC_SESSION_COLOR;if(!__c||!${JSON.stringify(Vc)}.includes(__c))return{};queueMicrotask(()=>{if(globalThis.__tweakccSaveAgentColor)globalThis.__tweakccSaveAgentColor(__c)});let __n=${e?`(typeof ${e}==="undefined"?"":${e}||"")`:`""`};return{standaloneAgentContext:{name:__n,color:__c}}})()`,Wc=e=>{if(e.includes(`let __c=process.env.TWEAKCC_SESSION_COLOR;if(!__c`))return e;let t=Uc(e.match(Hc)?.[1]??null),n=e.match(/,activeOverlays:new Set,fastMode:[$\w]+\([$\w]+\)/);if(!n||n.index===void 0)return console.error(`patch: sessionColor: failed to find the app state init`),null;let r=e.slice(0,n.index)+t+e.slice(n.index);return B(e,r,t,n.index,n.index+n[0].length),Gc(r)||(J(`patch: sessionColor: no saveAgentColor anchor; color applies without cross-session persistence`),r)},Gc=e=>{let t=RegExp(`([,;{}])(async function ([$\\w]+)\\(([$\\w]+),([$\\w]+),([$\\w]+)(?:,[$\\w]+)?\\)\\{let [$\\w]+=\\6\\?\\?[$\\w]+\\(\\4\\);try\\{await [$\\w]+\\([$\\w]+,\\{type:"agent-color",agentColor:\\5,sessionId:\\4\\}(?:,[$\\w]+)?\\)\\}catch\\([$\\w]+\\)\\{[\\s\\S]*?\\}if\\(\\4===([$\\w]+)\\(\\)\\))`),n=e.match(t);if(!n||n.index===void 0)return null;let r=n[1],i=n[2],a=`globalThis.__tweakccSaveAgentColor=(c)=>${n[3]}(${n[7]}(),c);`,o=`${r}${a}${i}`,s=e.slice(0,n.index)+o+e.slice(n.index+n[0].length);return B(e,s,a,n.index,n.index+n[0].length),s},Kc=e=>{let t=e.match(/=2000,([$\w]+)="Read a file from the local filesystem\./);if(!t||t.index===void 0)return/=\(\+process\.env\.CLAUDE_CODE_READ_DEFAULT_LINES/.test(e)?e:(console.error(`patch: readDefaultLines: failed to find =2000 near Read tool prompt anchor`),null);let n=t.index,r=n+5,i=`=(+process.env.CLAUDE_CODE_READ_DEFAULT_LINES||2000)`,a=e.slice(0,n)+i+e.slice(r);return B(e,a,i,n,n+52),a},qc=e=>X(JSON.stringify(e)).replace(/`/g,"\\`").replace(/\$\{/g,"\\${"),Jc=`"$_cc_bin"`,Yc=/\{mode:"embedded",command:process\.execPath,args:\[[^\]]*\],argv0:"rg"\}/,Xc=`Search backend note (fff):`;``+Xc;const Zc=`most-relevant-first`;``+Zc;const Qc=(e,t)=>{let n=qc(t);if(e.includes(`ARGV0=\${t} ${n}`)||e.includes(`exec -a \${t} ${n}`))return e;if(e.split(Jc).length-1==0)return console.error(`patch: swapRipgrepForFff: bash-search shadow anchor "$_cc_bin" not found`),null;let r=e.split(Jc).join(n),i=`[[ ! -x $_cc_bin ]]`;return r.includes(i)&&(r=r.split(i).join(`[[ ! -x $_cc_bin || ! -x ${n} ]]`)),B(e,r,n,e.indexOf(Jc),e.indexOf(Jc)+10),r},$c=(e,t)=>{if(e.includes(`--fff-claude-bin=`))return e;let n=e.indexOf(`{mode:"embedded",command:process.execPath,args:["--no-config"],argv0:"rg"}`),r=n===-1?-1:n+74;if(n===-1){let t=e.match(Yc);if(!t||t.index===void 0)return J(`patch: swapRipgrepForFff: ripgrep resolver descriptor not found; skipping rg repoint`),e;n=t.index,r=t.index+t[0].length}let i=`{mode:"system",command:${X(JSON.stringify(t))},args:["--fff-claude-bin="+process.execPath]}`,a=e.slice(0,n)+i+e.slice(r);return B(e,a,i,n,r),a},el=(e,t)=>{let n=e[t];for(t++;t<e.length;)if(e[t]===`\\`)t+=2;else if(e[t]===n)return t;else t++;return t},tl=(e,t)=>{let n=[{k:`tpl`}];for(let r=t;r<e.length;r++){let t=n[n.length-1],i=e[r];if(i===`\\`){r++;continue}if(t.k===`tpl`){if(i==="`"){if(n.pop(),n.length===0)return r;continue}i===`$`&&e[r+1]===`{`&&(n.push({k:`expr`,b:0}),r++);continue}if(i==="`"){n.push({k:`tpl`});continue}if(i===`"`||i===`'`){r=el(e,r);continue}if(i===`{`){t.b++;continue}if(i===`}`){t.b===0?n.pop():t.b--;continue}}return-1},nl=(e,t,n,r,i)=>{if(e.includes(r))return e;if(n.includes("`"))return console.error(`patch: swapRipgrepForFff: ${i} guidance contains a backtick; skipping (would break template parity)`),e;let a=[],o=0;for(;;){let n=e.indexOf(t,o);if(n===-1)break;let r=tl(e,n);r===-1?console.error(`patch: swapRipgrepForFff: ${i} anchor at ${n} has no balanced closing backtick; skipping this site`):a.push(r),o=n+t.length}if(a.length===0)return J(`patch: swapRipgrepForFff: ${i} anchor not found; skipping`),e;let s=e;for(let e of a.sort((e,t)=>t-e))s=s.slice(0,e)+n+s.slice(e);return B(e,s,n,a[a.length-1],a[0]),s},rl=(e,t)=>{let n=Qc(e,t);if(n===null)return null;let r=n;return r=$c(r,t),r=nl(r,`built on ripgrep`,`
|
|
1057
|
+
`+t[0].replace(`){return{`,`,__tweakccRouterSnapshot){return{...(__tweakccRouterSnapshot?{tweakccRouter:__tweakccRouterSnapshot}:{}),`)},{index:n.index,old:n[0],replacement:`${n[1]}(()=>{globalThis.__tweakccRouterResolution=void 0;let __tweakccResolved=${n[2].slice(0,-1)},${n[5]});globalThis.__tweakccRouterRecordTurn?.(${i[1]},${n[5]},__tweakccResolved,globalThis.__tweakccRouterResolution);return __tweakccResolved})`},{index:r.index,old:r[0],replacement:r[0].slice(0,-1)+`\${${o}.tweakccRouter?.effort?" \\xB7 Router \\u2192 "+${o}.tweakccRouter.effort+(${o}.tweakccRouter.source==="fallback"?" (fallback)":${o}.tweakccRouter.source==="pinned"?" (pinned)":${o}.tweakccRouter.source==="omitted"?" (incomplete input)":typeof ${o}.tweakccRouter.confidence==="number"&&Number.isFinite(${o}.tweakccRouter.confidence)&&${o}.tweakccRouter.confidence>=0&&${o}.tweakccRouter.confidence<=1?" (confidence "+Math.round(${o}.tweakccRouter.confidence*100)+"%)":""):""}\``},...l.map(e=>({index:e.index,old:e[0],replacement:e[0].slice(0,-1)+`${e[6]?``:`,void 0,void 0`},globalThis.__tweakccRouterSnapshotTurn?.(${e[4]}))`}))].sort((e,t)=>t.index-e.index),d=e;for(let e of u){let t=d.slice(0,e.index)+e.replacement+d.slice(e.index+e.old.length);B(d,t,e.replacement,e.index,e.index+e.old.length),d=t}return d},tc=`__tweakccRouterClassify`,nc=1e3,rc=(e,t,n,r)=>{let i=e.levels.map(e=>e.effort),a=JSON.stringify(i),o=e.pinPerTask?`true`:`false`,s=e.messageCap||1e5,c=e.assistantCap||1e5,l=e.timeoutMs||15e3,u=n?`${n}()`:`null`,d=i.length-1,f=e.levels.map((e,t)=>`Level ${t} (${e.label}): ${e.help}`).join(`
|
|
1058
|
+
`),p=(typeof e.systemPrompt==`string`&&e.systemPrompt.trim()?e.systemPrompt:te).replace(/\{LEVELS\}/g,f).replace(/\{MAX\}/g,String(d)),m=X(JSON.stringify(p)),h=X(JSON.stringify(e.levels.map(e=>e.label)));return`function __tweakccRouterState(){return globalThis.__tweakccRouter||(globalThis.__tweakccRouter={level:void 0,effort:void 0,baseline:void 0,summary:void 0,prevUser:void 0,prevAssistant:void 0,pendingCompaction:void 0,pendingRewindCut:void 0,log:void 0,model:void 0,loaded:!1})}function __tweakccRouterSyncSelection(){var selected=null;try{selected=globalThis.__tweakccRouterSelectedModel?.()||null}catch(e){}var s=__tweakccRouterState();if(s.selectedModel!==selected){if(s.selectedModel!==void 0){s.generation=(s.generation||0)+1;s.routeAbort?.abort();s.level=void 0;s.effort=void 0;s.baseline=void 0;s.prevUser=void 0;s.prevAssistant=void 0;}s.selectedModel=selected;}return selected}globalThis.__tweakccRouterSyncSelection=__tweakccRouterSyncSelection;function __tweakccRouterTrunc(__s,__cap){if(typeof __s!=="string")return"";if(__s.length<=__cap)return __s;var __mk="\\n...["+(__s.length-__cap)+" chars omitted from the middle]...\\n";var __b=__cap-__mk.length;if(__b<0)__b=0;var __h=Math.floor(__b/2);return __s.slice(0,__h)+__mk+__s.slice(__s.length-(__b-__h))}function __tweakccRouterSid(){try{var __s=${u};return typeof __s==="string"&&__s?__s:null}catch(__e){return null}}function __tweakccRouterDir(){var __p=${r}("path"),__o=${r}("os");return __p.join(__o.homedir(),".tweakcc","router-state")}function __tweakccRouterFile(__sid){return ${r}("path").join(__tweakccRouterDir(),__sid+".json")}function __tweakccRouterLoad(__st){if(__st.loaded)return;__st.loaded=!0;try{var __sid=__tweakccRouterSid();if(!__sid)return;var __fs=${r}("fs"),__f=__tweakccRouterFile(__sid);if(__fs.existsSync(__f)){var __d=JSON.parse(__fs.readFileSync(__f,"utf8"));if(__d){if(typeof __d.summary==="string")__st.summary=__d.summary;if(Number.isInteger(__d.level))__st.level=__d.level;if(Array.isArray(__d.log))__st.log=__d.log}}__tweakccRouterPrune(__fs)}catch(__e){}}function __tweakccRouterSave(__st){try{var __sid=__tweakccRouterSid();if(!__sid)return;var __fs=${r}("fs"),__dir=__tweakccRouterDir(),__j=JSON.stringify({summary:__st.summary,level:__st.level,log:Array.isArray(__st.log)?__st.log:[],updatedAt:Date.now()});__fs.mkdir(__dir,{recursive:!0},function(){try{__fs.writeFile(__tweakccRouterFile(__sid),__j,function(){})}catch(__e){}})}catch(__e){}}function __tweakccRouterDrop(__st){try{var __sid=__tweakccRouterSid();if(!__sid)return;var __fs=${r}("fs"),__f=__tweakccRouterFile(__sid);if(__fs.existsSync(__f))__fs.unlinkSync(__f)}catch(__e){}}function __tweakccRouterPrune(__fs){try{var __dir=__tweakccRouterDir(),__ns=__fs.readdirSync(__dir),__now=Date.now(),__ttl=12096e5;for(var __i=0;__i<__ns.length;__i++){try{var __ff=${r}("path").join(__dir,__ns[__i]);if(__now-__fs.statSync(__ff).mtimeMs>__ttl)__fs.unlinkSync(__ff)}catch(__e){}}}catch(__e){}}function __tweakccRouterReadResult(__r){try{if(__r==null)return null;if(typeof __r==="object"&&typeof __r.level==="number")return{level:__r.level,summary:typeof __r.summary==="string"?__r.summary:void 0};var __x;if(typeof __r==="string")__x=__r;else{var __c=(__r.message&&__r.message.content)||__r.content;__x=(Array.isArray(__c)&&__c[0]&&typeof __c[0].text==="string")?__c[0].text:(typeof __r.text==="string"?__r.text:"")}if(!__x)return null;try{var __o=JSON.parse(__x);if(__o&&typeof __o.level==="number")return{level:__o.level,summary:typeof __o.summary==="string"?__o.summary:void 0}}catch(__e){}var __m=__x.match(/-?\\d+/);if(__m)return{level:parseInt(__m[0],10),summary:void 0};return null}catch(__e){return null}}async function __tweakccRouterClassifyLlm(__input,__max){var __schema={type:"object",properties:{level:{type:"integer",description:"effort level, 0 (least) to "+__max+" (most)"},summary:{type:"string",description:"the updated running TL;DR summary"}},required:["level","summary"],additionalProperties:false};var __sys=${m};var __ac=new AbortController();__tweakccRouterState().routeAbort=__ac;var __to=setTimeout(function(){try{__ac.abort()}catch(__e){}},${l});try{var __res=await ${t.gB}({systemPrompt:[__sys],userPrompt:__input,outputFormat:{type:"json_schema",schema:__schema},signal:__ac.signal,options:{querySource:"route_complexity",agents:[],isNonInteractiveSession:!1,hasAppendSystemPrompt:!1,mcpTools:[],agentContext:${t.km}()}});return __tweakccRouterReadResult(__res)}finally{clearTimeout(__to)}}async function ${tc}(__text,__mode,__model){try{var __selected=__tweakccRouterSyncSelection();if(!__selected)return;var __ef=${a},__pin=${o},__max=__ef.length-1,__labels=${h};if(!__ef||!__ef.length)return;var __st=__tweakccRouterState();if(typeof __text!=="string")return;var __tr=__text.replace(/^\\s+/,"");if(/^\\/clear(\\s|$)/.test(__tr)){__st.level=void 0;__st.effort=void 0;__st.baseline=void 0;__st.summary=void 0;__st.prevUser=void 0;__st.prevAssistant=void 0;__st.pendingCompaction=void 0;__st.pendingRewindCut=void 0;__st.log=void 0;__st.model=void 0;__tweakccRouterDrop(__st);return}if(__tr.charAt(0)==="/")return;if(__mode!==void 0&&__mode!=="prompt")return;__tweakccRouterLoad(__st);if(__st.pendingRewindCut!=null){var __rt=__st.pendingRewindCut;__st.pendingRewindCut=void 0;var __rms=typeof __rt==="number"?__rt:Date.parse(__rt),__ci=-1;if(__rms===__rms&&Array.isArray(__st.log))for(var __i=__st.log.length-1;__i>=0;__i--){if(__st.log[__i]&&__st.log[__i].ts<=__rms){__ci=__i;break}}if(__ci>=0){var __pe=__st.log[__ci];__st.summary=__pe.summary;__st.level=__pe.level;__st.log=__st.log.slice(0,__ci)}else{__st.summary=void 0;__st.level=void 0}__st.prevUser=void 0;__st.prevAssistant=void 0;__st.pendingCompaction=void 0;if(process.env.TWEAKCC_ROUTER_DEBUG)try{process.stderr.write("[tweakcc-router] rewind cut to "+__rt+" ("+(__ci>=0?"restored":"reset")+")\\n")}catch(__e){}}if(typeof __st.pendingCompaction==="string"){__st.summary=__st.pendingCompaction;__st.prevUser=void 0;__st.prevAssistant=void 0;__st.level=void 0;__st.pendingCompaction=void 0}if(!Array.isArray(__st.log))__st.log=[];__st.log.push({ts:Date.now(),summary:typeof __st.summary==="string"?__st.summary:"",level:__st.level});if(__st.log.length>${nc})__st.log.splice(0,__st.log.length-${nc});var __plv=__st.level,__pmod=__st.model;var __mch=__pmod&&__model&&__pmod!==__model;var __ctx="model in use: "+(__model||"unknown")+(__mch?" (switched from "+__pmod+" this turn)":"")+"\\nlevel you assigned last turn: "+(__plv!==void 0?__plv+" ("+(__labels[__plv]||"?")+")":"none yet - this is the first routed turn");var __nm=__tweakccRouterTrunc(__text,${s});var __pu=__tweakccRouterTrunc(__st.prevUser,${s});var __pa=__tweakccRouterTrunc(typeof __st.prevAssistant==="string"?__st.prevAssistant:"",${c});var __input="<summary>\\n"+(__st.summary||"(none - first turn of the session)")+"\\n</summary>\\n<context>\\n"+__ctx+"\\n</context>\\n<recent_exchange>\\nuser: "+(__pu||"(none)")+"\\nassistant: "+(__pa||"(none)")+"\\n</recent_exchange>\\n<new_message>\\n"+__nm+"\\n</new_message>";var __generation=__st.generation,__res=null;try{__res=await __tweakccRouterClassifyLlm(__input,__max)}catch(__e){__res=null}if(__tweakccRouterSyncSelection()!==__selected||__st.generation!==__generation)return;__st.routeAbort=null;var __hi=__ef.indexOf("high");if(__hi<0)__hi=Math.min(2,__max);var __lv,__sm=__st.summary;if(__res&&typeof __res.summary==="string"&&__res.summary)__sm=__res.summary;if(__res&&Number.isInteger(__res.level))__lv=__res.level;else __lv=(__st.level!==void 0?__st.level:__hi);if(__pin&&__st.level!==void 0&&__lv<__st.level)__lv=__st.level;if(__lv<0)__lv=0;if(__lv>__max)__lv=__max;__st.level=__lv;__st.effort=__ef[__lv];__st.summary=__sm;__st.prevUser=__text;__st.model=__model;__tweakccRouterSave(__st);if(process.env.TWEAKCC_ROUTER_DEBUG)try{process.stderr.write("[tweakcc-router] level="+__lv+" effort="+__st.effort+" chars="+__text.length+"\\n")}catch(__e){}}catch(__e){}}`},ic=(e,t,n,r)=>{let i=/(function [$\w]+\(([$\w]+),([$\w]+),\{honorLaunchPin:[$\w]+=!0\}=\{\}\)\{if\(![$\w]+\(\2\)\)return;let [$\w]+=[$\w]+&&[$\w]+\(\2\),[$\w]+=[$\w]+\(\2\),([$\w]+)=[$\w]+\(\);)if\(\4===null&&![$\w]+\)return;return ([$\w]+)\(\4\?\?\([$\w]+\?[$\w]+:void 0\)\?\?\3\?\?[$\w]+,\2\)\}/,a=/(function [$\w]+\(([$\w]+),([$\w]+)\)\{if\(![$\w]+\(\2\)\)return;let [$\w]+=[$\w]+\(\2\),[$\w]+=[$\w]+\(\2\),([$\w]+)=[$\w]+\(\);)if\(\4===null&&![$\w]+\)return;return ([$\w]+)\(\4\?\?\([$\w]+\?[$\w]+:void 0\)\?\?\3\?\?[$\w]+,\2\)\}/,o=/(function [$\w]+\(([$\w]+),([$\w]+)\)\{if\(![$\w]+\(\2\)\)return;let [$\w]+=[$\w]+\(\2\),[$\w]+=[$\w]+\(\2\),([$\w]+)=[$\w]+\(\);)if\(\4===null&&![$\w]+\)return;let ([$\w]+)=\4\?\?\([$\w]+\?[$\w]+:void 0\)\?\?\3\?\?[$\w]+;(?:if\(typeof \5==="string"&&[$\w]+\(\5\)\)\5=[$\w]+\(\5,\2\);)?if\(\5==="max"&&!([$\w]+)\(\2\)\)\5="high";if\(\5==="xhigh"&&!([$\w]+)\(\2\)\)\5="high";return \5\}/,s=/(function [$\w]+\(([$\w]+),([$\w]+)\)\{if\(![$\w]+\(\2\)\)return;let [$\w]+=[$\w]+\(\2\),[$\w]+=[$\w]+\(\2\),([$\w]+)=[$\w]+\(\);)if\(\4===null\)return [$\w]+\?[$\w]+:void 0;let ([$\w]+)=\4\?\?\([$\w]+\?[$\w]+:void 0\)\?\?\3\?\?[$\w]+;if\(\5==="max"&&!([$\w]+)\(\2\)\)return"high";if\(\5==="xhigh"&&!([$\w]+)\(\2\)\)return"high";return \5\}/,c=e.match(/(function [$\w]+\(([$\w]+),([$\w]+),\{turnEffort:([$\w]+),hookEffortValue:[$\w]+,carriedEffort:[$\w]+=[$\w]+\(\2\)\}=\{\}\)\{if\(![$\w]+\(\2\)\)return;let [$\w]+=[$\w]+\(\2\)!==null;if\([$\w]+!==void 0\)\{let [$\w]+=typeof [$\w]+==="number"&&[$\w]+\?[$\w]+\([$\w]+\):[$\w]+;return [$\w]+\([$\w]+,\2\)\}let ([$\w]+)=[$\w]+\(\);)if\(\5===null&&![$\w]+\)return;let [$\w]+=[$\w]+\(\2,[$\w]+\),([$\w]+)=\5\?\?\(\5===null\?[$\w]+:void 0\)\?\?\4\?\?\3\?\?[$\w]+;if\(typeof \6==="number"&&[$\w]+\)\6=[$\w]+\(\6\);return ([$\w]+)\(\6,\2\)\}/)||e.match(/(function [$\w]+\(([$\w]+),([$\w]+),\{turnEffort:([$\w]+),hookEffortValue:[$\w]+\}=\{\}\)\{if\(![$\w]+\(\2\)\)return;let [$\w]+=[$\w]+\(\2\)!==null;if\([$\w]+!==void 0\)\{let [$\w]+=typeof [$\w]+==="number"&&[$\w]+\?[$\w]+\([$\w]+\):[$\w]+;return [$\w]+\([$\w]+,\2\)\}let ([$\w]+)=[$\w]+\(\);)if\(\5===null&&![$\w]+\)return;let [$\w]+=[$\w]+\(\2\),([$\w]+)=\5\?\?\(\5===null\?[$\w]+:void 0\)\?\?\4\?\?\3\?\?[$\w]+;if\(typeof \6==="number"&&[$\w]+\)\6=[$\w]+\(\6\);return ([$\w]+)\(\6,\2\)\}/)||e.match(/(function [$\w]+\(([$\w]+),([$\w]+),\{honorLaunchPin:[$\w]+=!0,turnEffort:([$\w]+),hookEffortValue:[$\w]+\}=\{\}\)\{if\(![$\w]+\(\2\)\)return;let [$\w]+=[$\w]+\(\2\)!==null;if\([$\w]+!==void 0\)\{let [$\w]+=typeof [$\w]+==="number"&&[$\w]+\?[$\w]+\([$\w]+\):[$\w]+;return [$\w]+\([$\w]+,\2\)\}let [$\w]+=[$\w]+&&[$\w]+\(\2\),[$\w]+=[$\w]+\(\2\),([$\w]+)=[$\w]+\(\);)if\(\5===null&&![$\w]+&&![$\w]+\)return;let ([$\w]+)=\5\?\?\(\5===null\?[$\w]+:void 0\)\?\?\4\?\?\([$\w]+\?[$\w]+:void 0\)\?\?\3\?\?[$\w]+;if\(typeof \6==="number"&&[$\w]+\)\6=[$\w]+\(\6\);return ([$\w]+)\(\6,\2\)\}/)||e.match(/(function [$\w]+\(([$\w]+),([$\w]+),\{honorLaunchPin:[$\w]+=!0,turnEffort:([$\w]+)\}=\{\}\)\{if\(![$\w]+\(\2\)\)return;let [$\w]+=[$\w]+&&[$\w]+\(\2\),[$\w]+=[$\w]+\(\2\),([$\w]+)=[$\w]+\(\),[$\w]+=[$\w]+\(\2\)!==null;)if\(\5===null&&![$\w]+&&![$\w]+\)return;let ([$\w]+)=\5\?\?\(\5===null\?[$\w]+:void 0\)\?\?\4\?\?\([$\w]+\?[$\w]+:void 0\)\?\?\3\?\?[$\w]+;if\(typeof \6==="number"&&[$\w]+\)\6=[$\w]+\(\6\);return ([$\w]+)\(\6,\2\)\}/),l=c?null:e.match(i)||e.match(a),u=c||l||e.match(o)||e.match(s);if(!u||u.index===void 0)return e.includes(`CLAUDE_CODE_EFFORT_LEVEL`)?(console.error(`patch: complexityRouter: failed to find effort resolver (XQ shape)`),null):(J(`patch: complexityRouter: effort resolver absent in this CC build - no-op`),e);let d=u[1],f=u[2],p=u[3],m=c?c[4]:null,h=c?c[5]:u[4],g=u[6],_=u[7],v=c?c[7]:l?.[5];if(v){let t=v.replace(/[$]/g,`\\$`),n=RegExp(`function ${t}\\(([$\\w]+),([$\\w]+)\\)\\{let ([$\\w]+)=\\1;(?:if\\(typeof \\3==="string"&&[$\\w]+\\(\\3\\)\\)\\3=[$\\w]+\\(\\3,\\2\\);)?if\\(\\3==="max"&&!([$\\w]+)\\(\\2\\)\\)\\3="high";if\\(\\3==="xhigh"&&!([$\\w]+)\\(\\2\\)\\)\\3="high";return \\3\\}`),r=e.match(n);if(!r)return console.error(`patch: complexityRouter: failed to find effort normalizer (support guards)`),null;g=r[4],_=r[5]}let y=`var __request=arguments[3];if(!__request||(!__request.agentId&&(__request.querySource?.startsWith("repl_main_thread")||__request.querySource==="sdk"))){var __selected=__tweakccRouterSyncSelection();var __st=__tweakccRouterState();if(__selected===${f}&&__st.baseline===void 0)__st.baseline=(${p}==null?null:${p});let __twkRE=__selected===${f}?__st.effort:void 0;if(__twkRE&&${h}==null${m?`&&${m}==null`:``}&&(${p}==null||${p}===__st.baseline)){if(__twkRE==="max"&&!${g}(${f}))__twkRE="high";if(__twkRE==="xhigh"&&!${_}(${f}))__twkRE="high";globalThis.__tweakccRouterResolution={effort:__twkRE};return __twkRE}}`,b=(t.provider===`jev`?$s:rc)(t,n,r,Vs(e)?`process.getBuiltinModule`:Fl(e));Vs(e)&&t.provider!==`jev`&&(b+=`globalThis.__tweakccRouterState=__tweakccRouterState;globalThis.__tweakccRouterClassify=__tweakccRouterClassify;`);let x=b+d+y+u[0].slice(d.length),S=u.index,C=S+u[0].length,w=e.slice(0,S)+x+e.slice(C);return B(e,w,x,S,C),w},ac=(e,t)=>{let n=e.match(/if\(([$\w]+)===null&&([$\w]+)!=="prompt"\)throw Error\(`Mode: \$\{\2\} requires a string input\.`\);/);if(!n||n.index===void 0)return e.includes(`requires a string input.`)?(console.error(`patch: complexityRouter: failed to find submit handler throw-guard`),null):(J(`patch: complexityRouter: submit handler absent in this CC build - no-op`),e);let r=n[1],i=n[2],a=[...e.slice(Math.max(0,n.index-4e3),n.index).matchAll(/([$\w]+)\.options\.mainLoopModel/g)],o=a[a.length-1],s=o?`${o[1]}.options.mainLoopModel`:`void 0`,c=o?`${o[1]}.messages`:`void 0`,l=o?`${o[1]}.session?.id`:`void 0`,u=`await ${Vs(e)?`globalThis.${tc}`:tc}(${`${r},${i},${s}${t?`,${c},${l}`:``}`});`,d=t?`try{${o?`if(!${o[1]}.agentId)`:``}{${o?`${o[1]}.__tweakccRouterTurn=`:``}${u}}}catch(__tweakccRouterError){}`:u,f=n.index+n[0].length,p=e.slice(0,f)+d+e.slice(f);return B(e,p,d,f,f),p},oc=e=>{if(e.includes(`function __tweakccRouterObserve(`)){let t=e.match(/let [$\w]+;if\(([$\w]+)\.gates\.emitToolUseSummaries&&[$\w]+\.length>0&&!([$\w]+)\.abortController\.signal\.aborted&&!\2\.agentId\)\{let [$\w]+=([$\w]+)\.at\(-1\)/);if(t?.index!==void 0){let n=e.slice(t.index,t.index+2e3).match(/([$\w]+)\.find\(\([$\w]+\)=>[$\w]+\.type==="user"&&Array\.isArray/),r=Vs(e)?`globalThis.__tweakccRouterObserve`:`__tweakccRouterObserve`,i=`try{if(!${t[2]}.agentId)${r}(${t[3]}${n?`.concat(${n[1]})`:``},${t[2]}.session?.id,${t[2]}.__tweakccRouterTurn);}catch(__tweakccRouterError){}`;return e.slice(0,t.index)+i+e.slice(t.index)}return J(`patch: complexityRouter: round capture absent - transcript refresh occurs at submit`),e}let t=e.match(/([$\w]+)=([$\w]+)\.at\(-1\),([$\w]+);if\(\1\)\{let ([$\w]+)=\1\.message\.content\.filter\(\(([$\w]+)\)=>\5\.type==="text"\);if\(\4\.length>0\)\{let ([$\w]+)=\4\.at\(-1\);if\(\6&&"text"in \6\)\3=\6\.text\}\}/);if(!t||t.index===void 0)return J(`patch: complexityRouter: prev-assistant capture site absent - router runs without prior-assistant context`),e;let n=`try{var __twr=globalThis.__tweakccRouter;if(__twr&&globalThis.__tweakccRouterSyncSelection?.())__twr.prevAssistant=${t[3]}}catch(__e){}`,r=t.index+t[0].length,i=e.slice(0,r)+n+e.slice(r);return B(e,i,n,r,r),i},sc=e=>{let t=e.match(/return\{ok:!0,summaryText:([$\w]+),/);if(!t||t.index===void 0)return J(`patch: complexityRouter: compaction summary site absent - no compaction reseed`),e;let n=t[1],r=`return globalThis.__tweakccRouter&&((typeof globalThis.__tweakccRouterInvalidate==="function"&&globalThis.__tweakccRouterInvalidate(globalThis.__tweakccRouter),globalThis.__tweakccRouter.pendingCompaction=${n})),{ok:!0,summaryText:${n},`,i=t.index,a=i+t[0].length,o=e.slice(0,i)+r+e.slice(a);return B(e,o,r,i,a),o},cc=e=>{let t=e.match(/onRestoreMessage:\(([$\w]+)\)=>([$\w]+(?:\.[$\w]+)?)\(\1,"message_selector"\)/);if(!t||t.index===void 0)return J(`patch: complexityRouter: restore-conversation site absent - no rewind cut`),e;let n=t[1],r=`onRestoreMessage:(${n})=>(globalThis.__tweakccRouter&&((typeof globalThis.__tweakccRouterInvalidate==="function"&&globalThis.__tweakccRouterInvalidate(globalThis.__tweakccRouter),globalThis.__tweakccRouter.pendingRewindCut=${n}&&${n}.timestamp)),${t[2]}(${n},"message_selector"))`,i=t.index,a=i+t[0].length,o=e.slice(0,i)+r+e.slice(a);return B(e,o,r,i,a),o},lc=e=>{let t=e.match(/function ([$\w]+)\(\)\{return\{agentType:"main",agentId:[$\w]+\(\)\}\}/);if(!t)return null;let n=e.match(/async function ([$\w]+)\(([$\w]+)\)\{(let ([$\w]+)=)([$\w]+\([$\w]+\(\)\)),[\s\S]{0,600}?return await [$\w]+\(\2,[$\w]+\[[$\w]+\],[$\w]+\[[$\w]+\+1\]\)/);if(n){let[e,r,i,a,,o]=n,s=`async function ${r}(${i}){${a}${o},`;return{gB:r,km:t[1],gBIndex:n.index,kmIndex:t.index,gBSource:e,gBOptions:`${i}.options`,gBPatched:`async function ${r}(${i}){${a}${i}.options.querySource==="route_complexity"?"claude-haiku-4-5":${o},`+e.slice(s.length)}}let r=e.match(/async function ([$\w]+)\(\{systemPrompt:[$\w]+=[$\w]+\(\[\]\),userPrompt:[$\w]+,outputFormat:[$\w]+,signal:[$\w]+,options:([$\w]+)\}\)\{return\(await [$\w]+\([\s\S]{0,500}?,model:[$\w]+\(\),enablePromptCaching:/);return r?{gB:r[1],km:t[1],gBIndex:r.index,kmIndex:t.index,gBSource:r[0],gBOptions:r[2],gBPatched:r[0].replace(/model:([$\w]+)\(\),enablePromptCaching:$/,`model:${r[2]}.querySource==="route_complexity"?"claude-haiku-4-5":$1(),enablePromptCaching:`)}:null},uc=e=>{let t=e.match(/getSessionId\(\)\{return ([$\w]+)\(\)\}/);return t?t[1]:null},dc=(e,t)=>{if(e.includes(tc))return J(`patch: complexityRouter: already patched - skipping`),e;let n=lc(e);if(!n)return console.warn(`patch: complexityRouter: gB/km side-call helpers not found in this CC build - cannot maintain routing context; skipping the router`),e;let r=uc(e);r||J(`patch: complexityRouter: session-id accessor not found - cross-session summary persistence disabled (in-memory only)`);let i=Hs(e,n);if(!i)return null;i.file=i.file.replace(n.gBSource,()=>n.gBPatched);let a=ic(i.file,t,i.helpers,r);if(a===null)return null;if(a===i.file)return e;let o=ac(a,t.provider===`jev`);if(o===null)return null;if(o===a)return J(`patch: complexityRouter: submit handler absent - reverting the resolver wrap too (all-or-nothing no-op)`),e;let s=oc(o);return ec(cc(t.provider===`jev`?s:sc(s)))},fc=[[`opusrouter`,`claude-opus-5-5`,`Opus 5.5 + Effort Router`],[`fablerouter`,`claude-fable-5-1`,`Fable 5.1 + Effort Router`]],pc=e=>`(${e}==="opusrouter"||${e}==="fablerouter")`,mc=(e,t,n,r)=>{let i=e.match(t);if(!i||i.index===void 0)return console.error(`patch: complexityRouterModels: failed to find ${r}`),null;let a=X(n(i)),o=e.slice(0,i.index)+a+e.slice(i.index+i[0].length);return B(e,o,a,i.index,i.index+i[0].length),o},hc=e=>{let t=mc(e,/(=[$\w]+\(\(([$\w]+)\)=>\{let ([$\w]+)=[$\w]+\(\),([$\w]+)=[$\w]+\.find\(\(([$\w]+)\)=>\5\.value===\3\);if\(\4===void 0\|\|\4\.disabled===!0\)return;)/,e=>`${e[0]}if(${pc(e[3])})return;`,`picker effort adjustment`);if(t===null)return null;let n=/(([$\w]+)!==void 0&&![$\w]+&&[$\w]+\([$\w]+,\{marginBottom:1,flexDirection:"column",children:)/,r=t.match(/([$\w]+)\(([$\w]+),\{color:"subtle",children:\[[$\w]+\([$\w]+,\{effort:void 0\}\)," Effort not supported"/);if(!r||(t=mc(t,n,e=>`${e[0]}${pc(e[2])}?${r[1]}(${r[2]},{color:"subtle",children:"Automatic effort"+(globalThis.__tweakccRouterState?.()?.effort?" · currently "+globalThis.__tweakccRouterState().effort:"")}):`,`picker effort display`),t===null))return null;let i=[/(function ([$\w]+)\(([$\w]+)\)\{)((?:if\(\3==="fableplan"\)\{[$\w]+\(\3,void 0\);return\})?let ([$\w]+)=[$\w]+\(\3\),(?:[$\w]+=[$\w]+\(\),)*[$\w]+=\5&&([$\w]+)!==void 0\?[$\w]+\(\6,\5\):\6;[$\w]+\("tengu_model_command_menu_effort")/,/(function ([$\w]+)\(([$\w]+)\)\{)((?:if\(\3==="fableplan"\)\{[$\w]+\(\3,void 0\);return\})?let ([$\w]+)=[$\w]+\(\3\),(?:[$\w]+=[$\w]+\(\),)*[$\w]+=\5&&([$\w]+)!==void 0&&\6!=="ultracode"\?[$\w]+\(\6,\5\):\6;[$\w]+\("tengu_model_command_menu_effort")/],a=i.find(e=>e.test(t))??i[i.length-1];return mc(t,a,e=>{let n=t.slice(e.index+e[0].length).match(RegExp(`^(?:(?!function )[^])*?if\\(${e[3].replace(/\$/g,`\\$`)}===[$\\w]+\\)\\{([$\\w]+)\\(null,[$\\w]+\\);return\\}`));if(!n)throw Error(`Router picker apply call is missing`);return`${e[1]}if(${pc(e[3])}){${n[1]}(${e[3]},void 0);return}${e[4]}`},`picker model commit`)},gc=e=>{if(e.includes(`globalThis.__tweakccRouterSelectedModel=function(`))return e;if(!e.includes(`"claude-opus-5-5"`))return J(`patch: complexityRouterModels: verified models unavailable — no-op`),e;let t=e.match(/function ([$\w]+)\(([$\w]+)\)\{let [$\w]+=\2\.trim\(\)[\s\S]{0,120}?if\([$\w]+\(([$\w]+)\)\)switch\(\3\)\{/);if(!t)return null;let n=fc.map(([e,t])=>`case"${e}":return"${t}";`).join(``),r=mc(e,/(\[(?:"[\w[\]]+",)*"opusplan"(?:,"[\w[\]]+")*\])(\s*,\s*[$\w]+\s*=\s*\["sonnet","opus","haiku")/,e=>`${e[1].slice(0,-1)},"opusrouter","fablerouter"]${e[2]}`,`model alias whitelist`);if(r===null)return null;let i=r.indexOf(t[0]),a=r.replace(t[0],t[0]+n);if(B(r,a,t[0]+n,i,i+t[0].length),r=a,r=mc(r,/(function [$\w]+\([$\w]+\)\{let [$\w]+=[$\w]+\(\);switch\([$\w]+\)\{case"opus":return [$\w]+\([$\w]+\);)/,e=>e[0]+n,`builtin model defaults`),r===null||(r=mc(r,/function ([$\w]+)\(\)\{let ([$\w]+)=[$\w]+\(\);if\(\2!==void 0\)return [$\w]+\(\2,"explicit"\);return [$\w]+\(\)\}/,e=>`globalThis.__tweakccRouterSelectedModel=function(){let __tweakccSelected=${e[1]}();return __tweakccSelected==="opusrouter"?"claude-opus-5-5":__tweakccSelected==="fablerouter"?"claude-fable-5-1":null};${e[0]}`,`live selected model getter`),r===null))return null;for(let e of[`overrideMainLoopModel`,`replaceInitialMainLoopModel`])if(r=mc(r,RegExp(`(${e}\\(([$\\w]+)\\)\\{this\\.#[$\\w]+=\\2)\\}`),e=>`${e[1]};queueMicrotask(()=>globalThis.__tweakccRouterSyncSelection?.())}`,`selected model setter`),r===null)return null;if(r=mc(r,/function ([$\w]+)\(([$\w]+)=!1,([$\w]+)=null\)\{let ([$\w]+)=new Set,([$\w]+)=[$\w]+\(\2,\3\)\.filter\(\(([$\w]+)\)=>\{if\(\6\.value===null\)return!0;if\(\4\.has\(\6\.value\)\)/,e=>`function ${e[1]}(${e[2]}=!1,${e[3]}=null){let rows=__tweakccRouterBasePicker(${e[2]},${e[3]});let clean=rows.filter(row=>!${pc(`row.value`)});for(let [alias,model,label] of ${JSON.stringify(fc)}){let index=clean.findIndex(row=>typeof row.value==="string"&&row.disabled!==!0&&${t[1]}(row.value)===model);if(index!==-1)clean.splice(index+1,0,{...clean[index],value:alias,label,description:"Automatic effort selected for each message"})}return clean}function __tweakccRouterBasePicker`+e[0].slice(`function ${e[1]}`.length),`filtered model picker`),r===null)return null;try{return hc(r)}catch{return console.error(`patch: complexityRouterModels: failed to find picker apply`),null}},W=`fableplan`,_c=`globalThis.__tweakccFablePlanModel`,vc=e=>{let t=e.match(/(\[(?:"[\w[\]]+",)*"opusplan"(?:,"[\w[\]]+")*\])(\s*,\s*[$\w]+\s*=\s*\["sonnet","opus","haiku")/);if(t&&t[1].includes(`"${W}"`))return J(`patch: fablePlan: alias already in the whitelist — skipping`),e;if(!t||t.index===void 0)return console.error(`patch: fablePlan: failed to find the model alias whitelist`),null;let n=t[1].slice(0,-1)+`,"${W}"]`+t[2],r=e.slice(0,t.index)+n+e.slice(t.index+t[0].length);return B(e,r,n,t.index,t.index+t[0].length),r},yc=(e,t,n)=>{let r=e.match(/(function ([$\w]+)\(([$\w]+)\)\{let\{permissionMode:([$\w]+),mainLoopModel:([$\w]+),exceeds200kTokens:([$\w]+)=!1\}=\3;)(if\(\4!=="plan"\)return\{model:\5,clampWarning:null\};let [$\w]+=([$\w]+)\(\),)/),i=r?null:e.match(/(function ([$\w]+)\(([$\w]+)\)\{let\{permissionMode:([$\w]+),mainLoopModel:([$\w]+),exceeds200kTokens:([$\w]+)=!1\}=\3;)(if\(\4!=="plan"\)return \5;let [$\w]+=([$\w]+)\(\),)/),a=r||i?null:e.match(/(function ([$\w]+)\(([$\w]+)\)\{let\{permissionMode:([$\w]+),mainLoopModel:([$\w]+),exceeds200kTokens:([$\w]+)=!1\}=\3,([$\w]+)=([$\w]+)\(\);)/),o=r??i??a;if(!o||o.index===void 0)return console.error(`patch: fablePlan: failed to find the plan-mode model resolver (uM shape)`),null;let s=o[1],c=o[4],l=r??i,u=l?`${o[8]}()`:o[7],d=l?o[7]:``,f=s+`if(${u}==="${W}"){${_c}=${`${n}(${c}==="plan"?"${t.planModel}":"${t.execModel}")`};${r?`return{model:${_c},clampWarning:null}`:`return ${_c}`}}${_c}=void 0;`+d,p=e.slice(0,o.index)+f+e.slice(o.index+o[0].length);return B(e,p,f,o.index,o.index+o[0].length),p},bc=(e,t)=>{let n=RegExp(`(switch\\(([$\\w]+)\\)\\{(?:case"[\\w]+":return [$\\w]+\\([$\\w]+\\);)*?case"${t.execModel}":return ([$\\w]+)\\(([$\\w]+)\\);)`),r=e.match(n);if(!r||r.index===void 0)return console.error(`patch: fablePlan: failed to find the builtin-default alias switch`),null;let i=`${r[1]}case"${W}":return ${r[3]}(${r[4]});`,a=e.slice(0,r.index)+i+e.slice(r.index+r[0].length);return B(e,a,i,r.index,r.index+r[0].length),a},xc=(e,t)=>{let n=RegExp(`function ([$\\w]+)\\(([$\\w]+)\\)\\{let [$\\w]+=\\2\\.trim\\(\\)[\\s\\S]{0,120}?if\\([$\\w]+\\(([$\\w]+)\\)\\)switch\\(\\3\\)\\{([\\s\\S]{0,600}?case"${t.execModel}":(return [^;]+;))`),r=e.match(n);if(!r||r.index===void 0)return console.error(`patch: fablePlan: failed to find the alias-to-model resolver (as shape)`),null;let i=r[1],a=r[0],o=`${a}case"${W}":${r[5]}`,s=e.slice(0,r.index)+o+e.slice(r.index+a.length);return B(e,s,o,r.index,r.index+a.length),{file:s,resolver:i}},Sc=(e,t)=>{let n=/(function [$\w]+\(([$\w]+),([$\w]+)\)\{let ([$\w]+)=[$\w]+\(\2\),([$\w]+)=[$\w]+\.ANTHROPIC_CUSTOM_MODEL_OPTION;)/,r=e.match(/(function [$\w]+\(([$\w]+),([$\w]+)\)\{let ([$\w]+)=[$\w]+\(\2,\3\),([$\w]+)=\4\?\?[$\w]+\(\2\),[^;]*;)(?=(?:(?!function )[^])*?[$\w]+\.ANTHROPIC_CUSTOM_MODEL_OPTION;)/)??e.match(/(function [$\w]+\(([$\w]+),([$\w]+)\)\{let ([$\w]+)=[$\w]+\(\2,\3\),([$\w]+)=\4\?\?[$\w]+\(\2\),([$\w]+)=[$\w]+\.ANTHROPIC_CUSTOM_MODEL_OPTION;)/),i=r??e.match(n);if(!i||i.index===void 0)return console.error(`patch: fablePlan: failed to find the model picker options`),null;let a=r?i[5]:i[4],o=`${Ec(t.planModel)} Plan Mode`,s=`Use ${Ec(t.planModel)} in plan mode, ${Ec(t.execModel)} otherwise`,c=`if(!${a}.some((z)=>z.value==="${W}"))${a}.push(${JSON.stringify({value:W,label:o,description:s})});`,l=i[1]+c,u=e.slice(0,i.index)+l+e.slice(i.index+i[0].length);return B(e,u,l,i.index,i.index+i[0].length),u},Cc=e=>{if(e.includes(`settingsEffortTable,${_c}??`))return J(`patch: fablePlan: effort lookup already keyed — skipping`),e;let t=e.match(/(case"inherit":if\(([$\w]+)\.settingsEffortTable===void 0\)return;if\(!?[$\w]+\(\2\.settingsEffortTable\)\)return \2\.settingsEffortTable\.default;return [$\w]+\(\2\.settingsEffortTable,)/);if(!t||t.index===void 0)return e.includes(`settingsEffortTable`)?(console.error(`patch: fablePlan: failed to find the per-model effort lookup`),null):(J(`patch: fablePlan: no per-model effort table in this build — effort follows the session`),e);let n=`${t[1]}${_c}??`,r=e.slice(0,t.index)+n+e.slice(t.index+t[0].length);return B(e,r,n,t.index,t.index+t[0].length),r},wc=(e,t)=>{if(!e.includes(`"modelPicker:decreaseEffort"`))return J(`patch: fablePlan: no model-picker effort control in this build`),e;if(e.includes(`==="${W}")return;let `))return J(`patch: fablePlan: picker effort row already handled — skipping`),e;let n=/(=[$\w]+\(\(([$\w]+)\)=>\{let ([$\w]+)=[$\w]+\(\),([$\w]+)=[$\w]+\.find\(\(([$\w]+)\)=>\5\.value===\3\);if\(\4===void 0\|\|\4\.disabled===!0\)return;)(let ([$\w]+)=[$\w]+\(\3\);if\(!\7\.supportsEffort\)return;)/,r=/(([$\w]+)!==void 0&&![$\w]+&&[$\w]+\([$\w]+,\{marginBottom:1,flexDirection:"column",children:)([$\w]+\?)/,i=/([$\w]+)\(([$\w]+),\{color:"subtle",children:\[[$\w]+\([$\w]+,\{effort:void 0\}\)," Effort not supported"/,a=[/(function ([$\w]+)\(([$\w]+)\)\{)(let ([$\w]+)=[$\w]+\(\3\),(?:[$\w]+=[$\w]+\(\),)*[$\w]+=\5&&([$\w]+)!==void 0\?[$\w]+\(\6,\5\):\6;[$\w]+\("tengu_model_command_menu_effort")/,/(function ([$\w]+)\(([$\w]+)\)\{)(let ([$\w]+)=[$\w]+\(\3\),(?:[$\w]+=[$\w]+\(\),)*[$\w]+=\5&&([$\w]+)!==void 0&&\6!=="ultracode"\?[$\w]+\(\6,\5\):\6;[$\w]+\("tengu_model_command_menu_effort")/,/(function ([$\w]+)\(([$\w]+)\)\{)(let ([$\w]+)=[$\w]+\(\3\),[$\w]+=\5&&[$\w]+!==void 0&&[$\w]+!=="ultracode"\?[$\w]+\([$\w]+,\5\):[$\w]+;if\([$\w]+\("tengu_model_command_menu_effort")/],o=e.match(n),s=e.match(r),c=e.match(i),l=null;for(let t of a)if(l=e.match(t),l)break;if(!o||o.index===void 0||!s||s.index===void 0||!c||!l||l.index===void 0)return console.error(`patch: fablePlan: failed to find the model picker effort control`),null;let u=e.slice(l.index+l[1].length).match(RegExp(`^(?:(?!function )[^])*?if\\(${l[3].replace(/\$/g,`\\$`)}===[$\\w]+\\)\\{([$\\w]+)\\(null,[$\\w]+\\);return\\}`));if(!u)return console.error(`patch: fablePlan: failed to find the model picker apply call`),null;let d=JSON.stringify(`${Ec(t.planModel)} and ${Ec(t.execModel)} each use their own effort (set it on their rows)`),f=[[o.index,o.index+o[0].length,`${o[1]}if(${o[3]}==="${W}")return;${o[6]}`],[s.index,s.index+s[0].length,`${s[1]}${s[2]}==="${W}"?${c[1]}(${c[2]},{color:"subtle",children:[${d}]}):${s[3]}`],[l.index,l.index+l[0].length,`${l[1]}if(${l[3]}==="${W}"){${u[1]}(${l[3]},void 0);return}${l[4]}`]],p=e;for(let[e,t,n]of f.sort((e,t)=>t[0]-e[0]))p=p.slice(0,e)+n+p.slice(t);return B(e,p,f.map(e=>e[2]).join(` … `),o.index,o.index),p},Tc=e=>{let t=e.match(/(=[$\w]+\(\([$\w]+\)=>[$\w]+\.settings\.showClearContextOnPlanAccept\)\?\?)!1/);if(!t||t.index===void 0)return J(`patch: fablePlan: showClearContextOnPlanAccept gate not present — no-op`),e;let n=`${t[1]}!0`,r=e.slice(0,t.index)+n+e.slice(t.index+t[0].length);return B(e,r,n,t.index,t.index+t[0].length),r},Ec=e=>e.charAt(0).toUpperCase()+e.slice(1),Dc=RegExp(`\\["sonnet",(?:"[\\w[\\]]+",)*"${W}"[,\\]]`),Oc=(e,t)=>{if(Dc.test(e))return J(`patch: fablePlan: already applied — no-op`),e;if(t.planModel===t.execModel)return console.error(`patch: fablePlan: planModel and execModel are the same — nothing to pair`),null;let n=xc(e,t);if(!n)return null;let r=n.file,i=vc(r);if(!i)return null;r=i;let a=yc(r,t,n.resolver);if(!a)return null;r=a;let o=bc(r,t);if(!o)return null;r=o;let s=Sc(r,t);if(!s)return null;r=s;let c=Cc(r);if(!c)return null;r=c;let l=wc(r,t);if(!l)return null;if(r=l,t.offerClearContextOnPlanAccept){let e=Tc(r);if(!e)return null;r=e}return r},kc=(e,t)=>{let n=`return !0;`,r=e.slice(0,t)+n+e.slice(t);return B(e,r,n,t,t),r},Ac=e=>{let t=e.indexOf(`"allow_voice_mode"`);if(t!==-1){let n=Math.max(0,t-800),r=e.slice(n,t+400).match(/function ([$\w]+)\(\)\{return [$\w]+\(\)&&[$\w]+\(\)\}/);if(r&&r.index!==void 0){let t=n+r.index,i=e.indexOf(`{`,t);if(i!==-1)return e.startsWith(`return !0;`,i+1)?e:kc(e,i+1)}let i=e.match(/name:"voice",description:"Toggle voice mode"[\s\S]{0,500}?get isHidden\(\)\{return![$\w]+\(\)\}/);if(i&&i.index!==void 0){let t=i[0].replace(/get isHidden\(\)\{return![$\w]+\(\)\}/,`get isHidden(){return!1}`);if(i[0]===t)return e;let n=e.slice(0,i.index)+t+e.slice(i.index+i[0].length);return B(e,n,t,i.index,i.index+i[0].length),n}}let n=e.match(/function [$\w]+\(\)\{return [$\w]+\("tengu_amber_quartz"/);if(n&&n.index!==void 0){let t=n.index+n[0].indexOf(`{`)+1,r=`return !0;`,i=e.slice(0,t)+r+e.slice(t);return B(e,i,r,t,t),i}let r=e.match(/function [$\w]+\(\)\{return![$\w]+\("tengu_amber_quartz_disabled"/);if(r&&r.index!==void 0){let t=r.index+r[0].indexOf(`{`)+1,n=`return !0;`,i=e.slice(0,t)+n+e.slice(t);return B(e,i,n,t,t),i}let i=e.match(/name:"voice",description:"Toggle voice mode"[\s\S]{0,500}?get isHidden\(\)\{return!([$\w]+)\(\)\}/);if(i&&i.index!==void 0){let t=i[1].replace(/[$]/g,`\\$`),n=RegExp(`function ${t}\\(\\)\\{`),r=e.match(n);if(r&&r.index!==void 0){let t=r.index+r[0].length,n=`return !0;`,i=e.slice(0,t)+n+e.slice(t);return B(e,i,n,t,t),i}}return console.error(`patch: voiceMode: failed to find tengu_amber_quartz gate`),null},jc=e=>{let t=e.match(/if\([$\w]+\("tengu_sotto_voce",!1\)\)/);if(!t||t.index===void 0)return e;let n=`if(!0)`,r=e.slice(0,t.index)+n+e.slice(t.index+t[0].length);return B(e,r,n,t.index,t.index+t[0].length),r},Mc=(e,t)=>{let n=Ac(e);return!n||t&&(n=jc(n),!n)?null:n},Nc=e=>{let t=e.match(/function [$\w]+\(\)\{return [$\w]+\("tengu_harbor",!1\)/);if(!t||t.index===void 0)return console.error(`patch: channelsMode: failed to find tengu_harbor gate`),null;let n=t.index+t[0].indexOf(`{`)+1,r=`return !0;`,i=e.slice(0,n)+r+e.slice(n);return B(e,i,r,n,n),i},Pc=e=>{let t=e.match(/reason:"server did not declare claude\/channel capability"\};?/);if(!t||t.index===void 0)return console.error(`patch: channelsMode: failed to find gateChannelServer capability check`),null;let n=t.index+t[0].length,r=`return{action:"register"};`,i=e.slice(0,n)+r+e.slice(n);return B(e,i,r,n,n),i},Fc=e=>{let t=e.match(/function [$\w]+\(\)\{return [$\w]+\("tengu_harbor_permissions",!1\)/);if(!t||t.index===void 0)return console.error(`patch: channelsMode: failed to find tengu_harbor_permissions gate`),null;let n=t.index+t[0].indexOf(`{`)+1,r=`return !0;`,i=e.slice(0,n)+r+e.slice(n);return B(e,i,r,n,n),i},Ic=e=>{let t=e.match(/"Channels \(experimental\) messages from ",([$\w]+),"[^"]*restart without "/);if(t&&t.index!==void 0){let n=`"Channels active \\xB7 messages from ",${t[1]}," \\xB7 restart without "`,r=t.index,i=r+t[0].length,a=e.slice(0,r)+n+e.slice(i);return B(e,a,n,r,i),a}let n=e.match(/Experimental[^"]*?inbound messages will be pushed into this session, this carries prompt injection risks\. Restart Claude Code without /);if(n&&n.index!==void 0){let t=`Channels active. Restart Claude Code without `,r=n.index,i=r+n[0].length,a=e.slice(0,r)+t+e.slice(i);return B(e,a,t,r,i),a}return console.error(`patch: channelsMode: failed to find ChannelsNotice warning text`),null},Lc=e=>{let t=e.match(/if\(![$\w]+\.dev\)[$\w]+\.push\(\{[$\w]+:[$\w]+,[$\w]+:"server: entries need --dangerously-load-development-channels"\}\)/);if(!t||t.index===void 0)return console.error(`patch: channelsMode: failed to find server dev-flag warning block`),null;let n=t.index,r=n+t[0].length,i=e.slice(0,n)+``+e.slice(r);return B(e,i,``,n,r),i},Rc=e=>{let t=Nc(e);return!t||(t=Pc(t),!t)||(t=Fc(t),!t)||(t=Ic(t),!t)||(t=Lc(t),!t)?null:t},zc=e=>{if(/name:"clear-screen"/.test(e))return e;let t=e.match(/([,;{}])(function [$\w]+\(\)\{)([$\w]+\(\))\.get\(process\.stdout\)\?\.forceRedraw\(\)\}/)||e.match(/([,;{}])(function [$\w]+\(\)\{)([$\w]+)\.get\(process\.stdout\)\?\.forceRedraw\(\)\}/);if(!t||t.index===void 0)return J(`patch: clearScreen: failed to find forceRedraw function`),null;let n=`${t[1]}globalThis.__tweakccForceRedraw=()=>${t[3]}.get(process.stdout)?.forceRedraw();`+t[0].slice(1),r=e.slice(0,t.index)+n+e.slice(t.index+t[0].length);B(e,r,n,t.index,t.index+t[0].length);let i=Bc(r);return i?(r=i,Hi(r,`,{type:"local",name:"clear-screen",description:"Clear screen without resetting conversation context",supportsNonInteractive:!1,load:()=>Promise.resolve().then(()=>({call:(H,$)=>{$.setMessages(m=>{globalThis.__tweakccHiddenUUIDs=new Set(m.map(x=>x.uuid?.slice(0,24)).filter(Boolean));return[...m]});process.stdout.write("\\x1b[2J\\x1b[H\\x1b[3J");globalThis.__tweakccForceRedraw?.();return{type:"skip"}}}))}`)||(J(`patch: clearScreen: failed to register slash command`),null)):(J(`patch: clearScreen: failed to patch render filter g97`),null)},Bc=e=>{let t=e.match(/([,;{}])(function [$\w]+\(([$\w]+),[$\w]+\)\{)if\(\3\.type!=="user"\)return!0;if\(\3\.isMeta\)/);if(!t||t.index===void 0)return null;let n=t[1],r=t[2],i=`${n}${r}if(globalThis.__tweakccHiddenUUIDs?.has(${t[3]}.uuid?.slice(0,24)))return!1;`+t[0].slice(n.length+r.length),a=e.slice(0,t.index)+i+e.slice(t.index+t[0].length);return B(e,a,i,t.index,t.index+t[0].length),a},Vc=[`red`,`blue`,`green`,`yellow`,`purple`,`orange`,`pink`,`cyan`],Hc=/\.\.\.([$\w]+)&&\{standaloneAgentContext:\{name:\1\}\}/,Uc=e=>`,...(()=>{let __c=process.env.TWEAKCC_SESSION_COLOR;if(!__c||!${JSON.stringify(Vc)}.includes(__c))return{};queueMicrotask(()=>{if(globalThis.__tweakccSaveAgentColor)globalThis.__tweakccSaveAgentColor(__c)});let __n=${e?`(typeof ${e}==="undefined"?"":${e}||"")`:`""`};return{standaloneAgentContext:{name:__n,color:__c}}})()`,Wc=e=>{if(e.includes(`let __c=process.env.TWEAKCC_SESSION_COLOR;if(!__c`))return e;let t=Uc(e.match(Hc)?.[1]??null),n=e.match(/,activeOverlays:new Set,fastMode:[$\w]+\([$\w]+\)/);if(!n||n.index===void 0)return console.error(`patch: sessionColor: failed to find the app state init`),null;let r=e.slice(0,n.index)+t+e.slice(n.index);return B(e,r,t,n.index,n.index+n[0].length),Gc(r)||(J(`patch: sessionColor: no saveAgentColor anchor; color applies without cross-session persistence`),r)},Gc=e=>{let t=RegExp(`([,;{}])(async function ([$\\w]+)\\(([$\\w]+),([$\\w]+),([$\\w]+)(?:,[$\\w]+)?\\)\\{let [$\\w]+=\\6\\?\\?[$\\w]+\\(\\4\\);try\\{await [$\\w]+\\([$\\w]+,\\{type:"agent-color",agentColor:\\5,sessionId:\\4\\}(?:,[$\\w]+)?\\)\\}catch\\([$\\w]+\\)\\{[\\s\\S]*?\\}if\\(\\4===([$\\w]+)\\(\\)\\))`),n=e.match(t);if(!n||n.index===void 0)return null;let r=n[1],i=n[2],a=`globalThis.__tweakccSaveAgentColor=(c)=>${n[3]}(${n[7]}(),c);`,o=`${r}${a}${i}`,s=e.slice(0,n.index)+o+e.slice(n.index+n[0].length);return B(e,s,a,n.index,n.index+n[0].length),s},Kc=e=>{let t=e.match(/=2000,([$\w]+)="Read a file from the local filesystem\./);if(!t||t.index===void 0)return/=\(\+process\.env\.CLAUDE_CODE_READ_DEFAULT_LINES/.test(e)?e:(console.error(`patch: readDefaultLines: failed to find =2000 near Read tool prompt anchor`),null);let n=t.index,r=n+5,i=`=(+process.env.CLAUDE_CODE_READ_DEFAULT_LINES||2000)`,a=e.slice(0,n)+i+e.slice(r);return B(e,a,i,n,n+52),a},qc=e=>X(JSON.stringify(e)).replace(/`/g,"\\`").replace(/\$\{/g,"\\${"),Jc=`"$_cc_bin"`,Yc=/\{mode:"embedded",command:process\.execPath,args:\[[^\]]*\],argv0:"rg"\}/,Xc=`Search backend note (fff):`;``+Xc;const Zc=`most-relevant-first`;``+Zc;const Qc=(e,t)=>{let n=qc(t);if(e.includes(`ARGV0=\${t} ${n}`)||e.includes(`exec -a \${t} ${n}`))return e;if(e.split(Jc).length-1==0)return console.error(`patch: swapRipgrepForFff: bash-search shadow anchor "$_cc_bin" not found`),null;let r=e.split(Jc).join(n),i=`[[ ! -x $_cc_bin ]]`;return r.includes(i)&&(r=r.split(i).join(`[[ ! -x $_cc_bin || ! -x ${n} ]]`)),B(e,r,n,e.indexOf(Jc),e.indexOf(Jc)+10),r},$c=(e,t)=>{if(e.includes(`--fff-claude-bin=`))return e;let n=e.indexOf(`{mode:"embedded",command:process.execPath,args:["--no-config"],argv0:"rg"}`),r=n===-1?-1:n+74;if(n===-1){let t=e.match(Yc);if(!t||t.index===void 0)return J(`patch: swapRipgrepForFff: ripgrep resolver descriptor not found; skipping rg repoint`),e;n=t.index,r=t.index+t[0].length}let i=`{mode:"system",command:${X(JSON.stringify(t))},args:["--fff-claude-bin="+process.execPath]}`,a=e.slice(0,n)+i+e.slice(r);return B(e,a,i,n,r),a},el=(e,t)=>{let n=e[t];for(t++;t<e.length;)if(e[t]===`\\`)t+=2;else if(e[t]===n)return t;else t++;return t},tl=(e,t)=>{let n=[{k:`tpl`}];for(let r=t;r<e.length;r++){let t=n[n.length-1],i=e[r];if(i===`\\`){r++;continue}if(t.k===`tpl`){if(i==="`"){if(n.pop(),n.length===0)return r;continue}i===`$`&&e[r+1]===`{`&&(n.push({k:`expr`,b:0}),r++);continue}if(i==="`"){n.push({k:`tpl`});continue}if(i===`"`||i===`'`){r=el(e,r);continue}if(i===`{`){t.b++;continue}if(i===`}`){t.b===0?n.pop():t.b--;continue}}return-1},nl=(e,t,n,r,i)=>{if(e.includes(r))return e;if(n.includes("`"))return console.error(`patch: swapRipgrepForFff: ${i} guidance contains a backtick; skipping (would break template parity)`),e;let a=[],o=0;for(;;){let n=e.indexOf(t,o);if(n===-1)break;let r=tl(e,n);r===-1?console.error(`patch: swapRipgrepForFff: ${i} anchor at ${n} has no balanced closing backtick; skipping this site`):a.push(r),o=n+t.length}if(a.length===0)return J(`patch: swapRipgrepForFff: ${i} anchor not found; skipping`),e;let s=e;for(let e of a.sort((e,t)=>t-e))s=s.slice(0,e)+n+s.slice(e);return B(e,s,n,a[a.length-1],a[0]),s},rl=(e,t)=>{let n=Qc(e,t);if(n===null)return null;let r=n;return r=$c(r,t),r=nl(r,`built on ripgrep`,`
|
|
1059
1059
|
|
|
1060
1060
|
Search backend note (fff): prefer one bare identifier over regex; results are relevance-ranked, so read the top hit first. A trailing [def] tag flags a line that likely defines the symbol.`,Xc,`Grep description`),r=nl(r,`Prefer dedicated tools over`,` grep/find results are ranked most-relevant-first (read the top hit first); a trailing [def] tag flags a likely definition line, and a grep or find -name that matches nothing automatically lists the closest approximate hits tagged [~approx]. Add --fuzzy to force typo-tolerant or partial matching, e.g. grep --fuzzy SomeName.`,Zc,`Bash description`),r},il=3e4;function al(){let{platform:e,arch:t}=process;return e===`darwin`&&t===`arm64`?`aarch64-apple-darwin`:e===`linux`&&t===`arm64`?`aarch64-unknown-linux-musl`:e===`linux`&&t===`x64`?`x86_64-unknown-linux-musl`:null}function ol(){try{let e=u.dirname(S(import.meta.url));for(let t=0;t<6;t++){let t=u.join(e,`package.json`);if(s.existsSync(t))try{let n=JSON.parse(s.readFileSync(t,`utf-8`)).version;if(typeof n==`string`)return{root:e,version:n}}catch{}let n=u.dirname(e);if(n===e)break;e=n}}catch{}return null}async function sl(e){try{return await a.access(e,s.constants.X_OK),!0}catch{return!1}}async function cl(e,t){await a.mkdir(u.dirname(t),{recursive:!0});let n=`${t}.tmp-${process.pid}`;try{await a.copyFile(e,n),await a.chmod(n,493),await a.rename(n,t)}catch(e){throw await a.unlink(n).catch(()=>{}),e}}async function ll(e){try{return(await a.stat(e)).mtimeMs}catch{return-1}}async function ul(){let e=al();if(!e)return null;let t=u.join(Z,`fff`,e,`rg-fff`),n=u.join(u.dirname(t),`.version`),r=ol();if(r)for(let e of[`release`,`debug`]){let n=u.join(r.root,`tools`,`rg-fff`,`target`,e,`rg-fff`);if(s.existsSync(n))return await ll(n)>await ll(t)&&await cl(n,t),t}let i=r?.version,o=await a.readFile(n,`utf-8`).then(e=>e.trim()).catch(()=>null);if(await sl(t)&&(!i||o===i))return t;if(!i)return null;let c=`https://github.com/skrabe/tweakcc-fixed/releases/download/v${i}`;try{let r=await fetch(`${c}/rg-fff-${e}`,{signal:AbortSignal.timeout(il)});if(!r.ok)return null;let o=Buffer.from(await r.arrayBuffer()),s=await fetch(`${c}/rg-fff-${e}.sha256`,{signal:AbortSignal.timeout(il)});if(!s.ok)return console.error(`patch: swapRipgrepForFff: rg-fff-${e}.sha256 unavailable (${s.status}) — keeping ripgrep`),null;let l=(await s.text()).trim().split(/\s+/)[0]?.toLowerCase(),d=b.createHash(`sha256`).update(o).digest(`hex`);if(!l||l!==d)return console.error(`patch: swapRipgrepForFff: rg-fff-${e} checksum ${l?`mismatch`:`missing`} — keeping ripgrep`),null;await a.mkdir(u.dirname(t),{recursive:!0});let f=`${t}.tmp-${process.pid}`;try{await a.writeFile(f,o),await a.chmod(f,493),await a.rename(f,t)}catch(e){throw await a.unlink(f).catch(()=>{}),e}return await a.writeFile(n,i).catch(()=>{}),t}catch{return null}}const dl=e=>{if(/function [$\w]+\(([$\w]+),[$\w]+\)\{if\(Object\.entries\([$\w]+\)\.length===0\)return \1;var ([$\w]+)=\1\[0\];if\(\2&&\2\.isMeta/.test(e))return e;let t=e.match(/function ([$\w]+)\(([$\w]+),([$\w]+)\)\{if\(Object\.entries\(\3\)\.length===0\)return \2;return\[([\s\S]+?),\.\.\.\2\]\}/);if(!t||t.index===void 0){let t=e.indexOf(`"tengu_context_size"`);if(t>0){let n=e.slice(Math.max(0,t-5e3),t);if(/function [$\w]+\([$\w]+,[$\w]+\)\{return [$\w]+;?\}\s*async function/.test(n))return console.log(`patch: claudemd-context-once-per-conversation: claudemd-context override suppressed wrapper — no-op`),e}return console.error(`patch: claudemd-context-once-per-conversation: failed to find kY6 wrapper`),null}let[n,r,i,a,o]=t,s=`${i}_0`,c=`function ${r}(${i},${a}){if(Object.entries(${a}).length===0)return ${i};var ${s}=${i}[0];if(${s}&&${s}.isMeta&&${s}.message&&typeof ${s}.message.content==="string"&&${s}.message.content.indexOf("<system-reminder>\\nAs you answer the user")===0)return ${i};${i}.unshift(${o});return ${i}}`,l=t.index,u=l+n.length,d=e.slice(0,l)+c+e.slice(u);return B(e,d,c,l,u),d},fl=e=>{let t=/function ([$\w]+)\(([$\w]+)\)\{return`\$\{([$\w]+)\}\n\$\{\2\}\n\$\{([$\w]+)\}`\}/g,n=(t,n)=>RegExp(`[,;{(\\s]${t.replace(/\$/g,`\\$`)}=${JSON.stringify(n)}[,;]`).test(e),r=null;for(let i of e.matchAll(t))if(n(i[3],`<system-reminder>`)&&n(i[4],`</system-reminder>`)){r=i;break}let i=r??e.match(/function ([$\w]+)\(([$\w]+)\)\{return`<system-reminder>\n\$\{\2\}\n<\/system-reminder>`\}/);if(!i||i.index===void 0)return/function [$\w]+\(([$\w]+)\)\{if\(!\1\|\|!\1\.trim\(\)\|\|\1==="\(no content\)"\)return"\(no content\)";return`(?:<system-reminder>|\$\{[$\w]+\}\n)/.test(e)?e:(console.error(`patch: strip-empty-system-reminders: failed to find LW(H) wrapper`),null);let[a,o,s]=i,c=`function ${o}(${s}){if(!${s}||!${s}.trim()||${s}==="(no content)")return"(no content)";return\`${r?`\${${r[3]}}`:`<system-reminder>`}\n\${${s}}\n${r?`\${${r[4]}}`:`</system-reminder>`}\`}`,l=i.index,u=l+a.length,d=e.slice(0,l)+c+e.slice(u);return B(e,d,c,l,u),d},pl=e=>{if(!e.includes(`The following deferred tools are now available via`))return console.log(`patch: suppress-deferred-tools: anchor not present in this CC build — no-op`),e;let t=`case"deferred_tools_delta":{`;if(e.includes(`case"deferred_tools_delta":{return [];`))return e;let n=e.indexOf(t);if(n<0)return console.error(`patch: suppress-deferred-tools: failed to find case header`),null;if(e.indexOf(t,n+1)>=0)return console.error(`patch: suppress-deferred-tools: case header is ambiguous (multiple matches)`),null;let r=n+28,i=`return [];`,a=e.slice(0,r)+i+e.slice(r);return B(e,a,i,r,r),a},ml=[`__tweakcc`,`tweakcc v`],hl=e=>ml.some(t=>e.includes(t)),gl=Math.max(...ml.map(e=>e.length)),_l=async e=>new Promise(t=>{let n;try{n=l(e,{encoding:`latin1`,highWaterMark:8<<20})}catch{t(!1);return}let r=``,i=!1,a=e=>{i||(i=!0,n.destroy(),t(e))};n.on(`data`,e=>{let t=r+e;if(hl(t)){a(!0);return}r=t.slice(-(gl-1))}),n.on(`error`,()=>a(!1)),n.on(`close`,()=>a(!1)),n.on(`end`,()=>a(!1))});var vl=class extends Error{constructor(e){super(`Refusing to back up ${e}: it carries tweakcc markers, so it is already patched. Backing it up would overwrite the only pristine copy with a patched one. Run \`tweakcc --restore\` first, or reinstall Claude Code, then try again.`),this.name=`NonPristineBackupError`}};const yl=async e=>{if(await _l(e))throw new vl(e)},bl=async(e,t)=>{let n=`${t}.tmp-${process.pid}`;try{await o.copyFile(e,n),await o.rename(n,t)}catch(e){try{await o.unlink(n)}catch{}throw e}},xl=async e=>{if(!e.cliPath){J(`backupClijs: Skipping for native installation (no cliPath)`);return}await yl(e.cliPath),await Nu(),J(`Backing up cli.js to ${Ou}`),await bl(e.cliPath,Ou),await zu(t=>{t.changesApplied=!1,t.ccVersion=e.version})},Sl=async e=>{e.nativeInstallationPath&&(await yl(e.nativeInstallationPath),await Nu(),J(`Backing up native binary to ${ku}`),await bl(e.nativeInstallationPath,ku),await zu(t=>{t.changesApplied=!1,t.ccVersion=e.version}))},Cl=async e=>e.cliPath?await vu(Ou)?(J(`Restoring cli.js from backup to ${e.cliPath}`),await _u(e.cliPath,Ou,`restore`),await Lt(),await zu(e=>{e.changesApplied=!1}),!0):(J(`restoreClijsFromBackup: No backup file exists, skipping`),!1):(J(`restoreClijsFromBackup: Skipping for native installation (no cliPath)`),!1),wl=async e=>e.nativeInstallationPath?await vu(ku)?(J(`Restoring native binary from backup to ${e.nativeInstallationPath}`),await _u(e.nativeInstallationPath,ku,`restore`),await Lt(),await zu(e=>{e.changesApplied=!1}),!0):(J(`restoreNativeBinaryFromBackup: No backup file exists, skipping`),!1):(J(`restoreNativeBinaryFromBackup: No native installation path, skipping`),!1),Tl=`/*@@TWEAKCC_MODULE:`,El=(e,t)=>{let n=e.lastIndexOf(Tl,t);if(n===-1)return Dl(e);let r=e.indexOf(Tl,n+1);return Dl(e.slice(n,r===-1?e.length:r))},Dl=e=>{let t=Array.from(e.matchAll(/[^$\w]([$\w]+)(?:\.(?:cyan|gray|green|red|yellow|ansi256|bgAnsi256|bgHex|bgRgb|hex|rgb|bold|dim|inverse|italic|strikethrough|underline)\b)+\(/g)),n={};for(let e of t){let t=e[1];n[t]=(n[t]||0)+1}let r,i=0;for(let[e,t]of Object.entries(n))t>i&&(i=t,r=e);return r},Ol=e=>{let t=e.slice(0,2e3).match(/[,;]([$\w]+)=\([$\w]+,[$\w]+,[$\w]+\)=>\{[$\w]+=[$\w]+!=null\?/);if(t)return t[1];let n=e.slice(0,1e4),r=Array.from(n.matchAll(/(?:var |,)([$\w]+)=\([$\w]+,[$\w]+,[$\w]+\)=>\{/g));if(r.length>0){let e=r[0][1];for(let t of r)t[1].length<e.length&&(e=t[1]);return e}console.log(`patch: getModuleLoaderFunction: failed to find module loader function`)},kl=e=>{let t=e.match(/var ([$\w]+)=[$\w]+\((?:\([$\w]+\)=>|function\([$\w]+\))\{var [$\w]+=Symbol\.for\("react\.(transitional\.)?element"\)/);if(!t){console.log(`patch: getReactModuleNameNonBun: failed to find React module name`);return}return t[1]},Al=e=>{let t=kl(e);if(!t){console.log(`^ patch: getReactModuleFunctionBun: failed to find React module name (Bun)`);return}let n=RegExp(`var ([$\\w]+)=[$\\w]+\\((?:\\([$\\w]+,[$\\w]+\\)=>|function\\([$\\w]+,[$\\w]+\\))\\{[$\\w]+\\.exports=${q(t)}\\(\\)`),r=e.match(n);if(!r){console.log(`patch: getReactModuleFunctionBun: failed to find React module function (Bun) (reactModuleNameNonBun=${t})`);return}return r[1]};let G=null,jl=null;const Ml=e=>{if(G!=null)return G;let t=Ol(e);if(!t){console.log(`^ patch: getReactVar: failed to find moduleLoader`),G=void 0;return}let n=kl(e);if(!n){console.log(`^ patch: getReactVar: failed to find reactModuleVarNonBun`),G=void 0;return}let r=RegExp(`[^$\\w]([$\\w]+)=${q(t)}\\(${q(n)}\\(\\),1\\)`),i=e.match(r);if(i)return G=i[1],G;let a=Al(e);if(!a){console.log(`^ patch: getReactVar: failed to find reactModuleFunctionBun`),G=void 0;return}let o=RegExp(`[^$\\w]([$\\w]+)=${q(t)}\\(${q(a)}\\(\\),1\\)`),s=e.match(o);if(!s){console.log(`patch: getReactVar: failed to find bunPattern (moduleLoader=${t}, reactModuleVarNonBun=${n}, reactModuleFunctionBun=${a})`),G=void 0;return}return G=s[1],G},Nl=()=>{G=null},Pl=e=>{let t=e.match(/import\{createRequire as ([$\w]+)\}from"node:module";/);if(!t)return;let n=t[1],r=RegExp(`var ([$\\w]+)=${q(n)}\\(import\\.meta\\.url\\)`),i=e.match(r);if(!i){console.log(`patch: findRequireFunc: failed to find require function variable (createRequireVar=${n})`);return}return i[1]},Fl=e=>{if(jl!=null)return jl;let t=Pl(e);return t?(jl=t,jl):(jl=`require`,jl)},Il=()=>{jl=null},Ll=()=>{Nl(),Il()},Rl=e=>{let t=e.match(/function ([$\w]+)\([$\w]+\)\{let [$\w]+=[$\w]+\.c\(\d+\)[^;]{0,240};if\([$\w]+\[0\]!==[$\w]+\)\(\{color:[$\w]+,backgroundColor:[$\w]+,dimColor:[$\w]+,bold:[$\w]+/);if(t)return t[1];let n=e.match(/\bfunction ([$\w]+).{0,80}color:[$\w]+,backgroundColor:[$\w]+,dimColor:[$\w]+(?:=![01])?,bold:[$\w]+(?:=![01])?/);if(!n){console.log(`patch: findTextComponent: failed to find text component`);return}return n[1]},zl=(e,t)=>{let n=`[A-Za-z_$][\\w$]*(?:\\.[A-Za-z_$][\\w$]*)*`,r=RegExp(`var [^;]{0,120};var [$\\w]+=${n}\\(\\(\\)=>\\{[^}]{0,500}([$\\w]+)=${q(t)}\\}\\)`),i=e.match(r)?.[1]??t,a=RegExp(`function ([$\\w]+)\\([^)]+\\)\\{(?=[\\s\\S]{0,2500}createElement\\(${q(i)},\\{\\.\\.\\.[$\\w]+,borderColor:)[\\s\\S]{0,3000}?return [$\\w]+\\}var [^;]{0,160};var [$\\w]+=${n}\\(\\(\\)=>\\{[^}]{0,600}([$\\w]+)=\\1\\}\\)`);return e.match(a)?.[2]},Bl=e=>{let t=e.match(/function ([$\w]+)\(.{0,2000}[^$\w]([$\w]+)=[$\w]+(?:\.default)?\.createElement\("ink-box".{0,500}?return \2/);if(t)return t[1];let n=e.match(/function ([$\w]+)\(.{0,200}children:[$\w]+,flexWrap:[$\w]+.{0,2000}?\.createElement\("ink-box"/);if(n)return n[1];let r=e.match(/[^$\w]([$\w]+)\.displayName="Box"/);if(r)return r[1];let i=e.match(/function ([$\w]+)\([$\w]+\)\{let [$\w]+=[$\w]+(?:\.[$\w]+)?\(\d+\).{0,3000}createElement\("ink-box"/);if(i)return i[1];let a=e.match(/function ([$\w]+)\(\{children:([$\w]+),ref:[$\w]+.{0,600}?\.\.\.([$\w]+)\}\)\{.{0,2500}?"margin".{0,2500}?"padding".{0,1200}?"gap".{0,1200}?\3\.flexWrap\?\?="nowrap",\3\.flexDirection\?\?="row",\3\.flexGrow\?\?=0,\3\.flexShrink\?\?=1,\3\.overflowX=\3\.overflowX\?\?\3\.overflow\?\?"visible",\3\.overflowY=\3\.overflowY\?\?\3\.overflow\?\?"visible",[$\w]+(?:\.default)?\.createElement\("ink-box",\{[^}]*style:\3\},\2\)/);if(a)return zl(e,a[1])??a[1];let o=e.match(/function ([$\w]+)\(\{children:[$\w]+,ref:[$\w]+,tabIndex:[$\w]+,autoFocus:[$\w]+/);if(o)return o[1];console.error(`patch: findBoxComponent: failed to find Box component (neither ink-box createElement nor displayName found)`)};let K=function(e){return e.SYSTEM_PROMPTS=`System Prompts`,e.ALWAYS_APPLIED=`Always Applied`,e.MISC_CONFIGURABLE=`Misc Configurable`,e.FEATURES=`Features`,e.SYSTEM_REMINDERS=`System Reminders`,e}({});const Vl=[{id:`verbose-property`,name:`Verbose property`,group:K.ALWAYS_APPLIED,description:`Token counter will show (2s · ↓ 169 tokens · thinking)`},{id:`read-default-lines`,name:`Read default lines (env-gated)`,group:K.ALWAYS_APPLIED,description:`Read tool default line cap becomes CLAUDE_CODE_READ_DEFAULT_LINES env var (falls back to 2000 if unset)`},{id:`opusplan1m`,name:`Opusplan[1m] support`,group:K.ALWAYS_APPLIED,description:`Use the "Opus Plan 1M" model: Opus for planning, Sonnet 1M context for building`},{id:`thinking-block-styling`,name:`Thinking block styling`,group:K.ALWAYS_APPLIED,description:`Restore dim/gray + italic styling for thinking blocks`},{id:`fix-lsp-support`,name:`Fix LSP support`,group:K.ALWAYS_APPLIED,description:`Enable/fix nascent LSP support`},{id:`no-global-cache-scope`,name:`Keep a replaced identity line out of the global prompt cache`,group:K.ALWAYS_APPLIED,description:`When a prompt override replaces one of Claude Code's identity lines, turn off the "global" cache scope that the first-party API rejects after a non-stock identity, so the prompt caches at organization scope instead. Does nothing while the identity lines are stock.`},{id:`fix-summarize-from-here`,name:`Fix "Summarize from here"`,group:K.MISC_CONFIGURABLE,description:`Make "Summarize from here" summarize only the messages after the rewind point (feed the slice, not the whole conversation)`,modelFacing:!0},{id:`fix-rewind-summary-header`,name:`Honest rewind summary header`,group:K.MISC_CONFIGURABLE,description:`Label a rewind summary as a deliberate rewind instead of the misleading "ran out of context" header`,modelFacing:!0},{id:`statusline-update-throttle`,name:`Statusline update throttling correction`,group:K.ALWAYS_APPLIED,description:`Statusline updates will be properly throttled instead of queued (or debounced)`},{id:`clear-screen`,name:`Clear screen command`,group:K.ALWAYS_APPLIED,description:`Register a /clear-screen command that clears the terminal scrollback and redraws without resetting conversation context`},{id:`strip-empty-system-reminders`,name:`Strip empty <system-reminder> wrappers`,group:K.ALWAYS_APPLIED,description:`Short-circuits CC's universal system-reminder wrapper so empty / "(no content)" inputs produce no reminder. Kills the drift-inducing "<system-reminder>(no content)</system-reminder>" blocks that get appended to roughly every other tool call.`},{id:`model-customizations`,name:`Model customizations`,group:K.MISC_CONFIGURABLE,description:`Access all Claude models with /model, not just latest 3`},{id:`show-more-items-in-select-menus`,name:`Show more items in select menus`,group:K.MISC_CONFIGURABLE,description:`Show 25 items in select menus instead of default 5`},{id:`context-limit`,name:`Context limit`,group:K.MISC_CONFIGURABLE,description:`Override the 200K context limit via CLAUDE_CODE_CONTEXT_LIMIT env var (set before launching CC)`},{id:`patches-applied-indication`,name:`Patches applied indication`,group:K.MISC_CONFIGURABLE,description:`Show "tweakcc patches applied" and tweakcc version inside CC`},{id:`table-format`,name:`Table format`,group:K.MISC_CONFIGURABLE,description:`Tables generated by Claude will be rendered more compactly`},{id:`themes`,name:`Themes`,group:K.MISC_CONFIGURABLE,description:`Your custom themes will be available via /theme`},{id:`thinking-verbs`,name:`Thinking verbs`,group:K.MISC_CONFIGURABLE,description:`Your custom list of thinking verbs will be cycled through`},{id:`thinker-format`,name:`Thinker format`,group:K.MISC_CONFIGURABLE,description:`Your custom format string that thinking verbs are wrapped in will be applied`},{id:`thinker-symbol-chars`,name:`Thinker symbol chars`,group:K.MISC_CONFIGURABLE,description:`Your custom thinking spinner will be rendered`},{id:`thinker-symbol-speed`,name:`Thinker symbol speed`,group:K.MISC_CONFIGURABLE,description:`The thinking spinner will play at a custom FPS`},{id:`thinker-symbol-width`,name:`Thinker symbol width`,group:K.MISC_CONFIGURABLE,description:`The thinking spinner will be in a box of custom width`},{id:`thinker-symbol-mirror`,name:`Thinker symbol mirror`,group:K.MISC_CONFIGURABLE,description:`The thinking spinner will reverse or restart when it finishes`},{id:`input-box-border`,name:`Input box border`,group:K.MISC_CONFIGURABLE,description:`Your custom styles to the main input box's border will be applied`},{id:`input-chevron-color`,name:`Input chevron idle color`,group:K.MISC_CONFIGURABLE,description:`The idle input chevron will use your chosen theme color instead of the default`},{id:`subagent-models`,name:`Subagent models`,group:K.MISC_CONFIGURABLE,description:`Use custom models for Plan, Explore, and General subagents`},{id:`thinking-visibility`,name:`Thinking block visibility`,group:K.MISC_CONFIGURABLE,description:`Thinking blocks outputted by the model will show without Ctrl+O`},{id:`hide-startup-banner`,name:`Hide startup banner`,group:K.MISC_CONFIGURABLE,description:`CC's startup banner with "Clawd" and release notes will be hidden`},{id:`hide-ctrl-g-to-edit`,name:`Hide Ctrl+G to edit`,group:K.MISC_CONFIGURABLE,description:`Note about using Ctrl+G to edit prompt will be hidden`},{id:`hide-startup-clawd`,name:`Hide startup Clawd`,group:K.MISC_CONFIGURABLE,description:`The "Clawd" icon on startup will be hidden for a cleaner look`},{id:`increase-file-read-limit`,name:`Increase file read limit`,group:K.MISC_CONFIGURABLE,description:`Max tokens Claude can read from a file at once will be increased`},{id:`suppress-line-numbers`,name:`Suppress line numbers`,group:K.MISC_CONFIGURABLE,description:`"1→" "2→" etc. prefixes for each line of Read output will be omitted`},{id:`suppress-rate-limit-options`,name:`Suppress rate limit options`,group:K.MISC_CONFIGURABLE,description:`/rate-limit-options won't be injected when limits are reached`},{id:`suppress-rate-limit-warning`,name:`Suppress rate limit warning`,group:K.MISC_CONFIGURABLE,description:`Rate limit warning banners in the status bar will be hidden`},{id:`session-color`,name:`Session color from env`,group:K.MISC_CONFIGURABLE,description:`Session prompt bar color is read from the TWEAKCC_SESSION_COLOR env var at each launch`},{id:`token-count-rounding`,name:`Token count rounding`,group:K.MISC_CONFIGURABLE,description:`Round displayed token counts to the nearest multiple of chosen value`},{id:`remember-skill`,name:`Remember skill`,group:K.MISC_CONFIGURABLE,description:`Register the built-in "/remember" skill to review session memories and update CLAUDE.local.md`},{id:`agents-md`,name:`AGENTS.md (and others)`,group:K.MISC_CONFIGURABLE,description:`Support AGENTS.md and others in addition to CLAUDE.md`},{id:`auto-accept-plan-mode`,name:`Auto-accept plan mode`,group:K.MISC_CONFIGURABLE,description:`Automatically accept plans without the "Ready to code?" confirmation prompt`},{id:`allow-sudo-bypass-permissions`,name:`Allow bypassing permissions with --dangerously-skip-permissions in sudo`,group:K.MISC_CONFIGURABLE,description:`Allow bypassing permissions with --dangerously-skip-permissions even when running with root/sudo privileges`},{id:`suppress-native-installer-warning`,name:`Suppress native installer warning`,group:K.MISC_CONFIGURABLE,description:`Suppress the native installer warning message at startup`},{id:`model-at-effort`,name:`/model name@effort`,group:K.MISC_CONFIGURABLE,description:`/model opus@high sets the model and then runs /effort high, in one command`},{id:`filter-scroll-escape-sequences`,name:`Filter scroll escape sequences`,group:K.MISC_CONFIGURABLE,description:`Filter out terminal escape sequences that cause unwanted scrolling`},{id:`max-effort-default`,name:`Default Opus 4.7 to max effort`,group:K.MISC_CONFIGURABLE,description:`Opus 4.7 sessions default to "max" reasoning effort instead of "xhigh" (override with /effort or CLAUDE_CODE_EFFORT_LEVEL)`,modelFacing:!0},{id:`autonomous-operation-all-models`,name:`Fable/Mythos prompt set (all models)`,group:K.MISC_CONFIGURABLE,description:`Treats your selected model as Fable/Mythos everywhere CC branches on model family (flips the zQ gate): you get the autonomous-operation prompt (proceed without asking for reversible in-scope work; finish the job before ending the turn), the "# Communicating with the user" comms block in place of "# Text output", /loop dynamic-pacing behavior, and brief-mode comms shaping. Per-model feature-flag routing also follows fable but is inert on a local install`,modelFacing:!0},{id:`refusal-fallback-model`,name:`Route the refusal fallback, then switch back`,group:K.MISC_CONFIGURABLE,description:`When safeguards flag a message, Claude Code retries it on a fallback model from its own route table, keyed by the flagged model and the refusal category, and keeps the session on that model. This merges refusalFallbackRoutes from config.json over that table (a category you leave out keeps its stock route, one you route falls back to the stock route when none of your models is usable, and a route is a model id or a chain of them) and switches the session back to its own model once the flagged turn is answered, with a line in the transcript. refusalFallbackMaxReturns in config.json (default 1, null for no limit) caps consecutive returns, so a conversation that keeps being flagged stays on the fallback instead of paying a refusal and a retry every turn`,modelFacing:!1},{id:`output-style-turn-reminder`,name:`Custom output styles carry their own per-turn reminder`,group:K.MISC_CONFIGURABLE,description:`Claude Code restates which output style is active once per turn. Since 2.1.238 that reminder fires for custom styles as well as built-in ones, but its text is fixed: every style you write gets the same generic "Remember to follow the specific guidelines for this style." This lets a style supply its own sentence instead. Add \`turn-reminder:\` to the style's markdown frontmatter and that text is what gets restated each turn, the way the built-in styles carry their own. Without this, the key is read by the frontmatter parser and then dropped on the way to the renderer, so it has no effect. On Claude Code before 2.1.238 this also makes the reminder fire for custom styles at all, which stock builds of that era skipped entirely. The per-turn slot is the position Anthropic's own Opus 5 guidance points at for tone, where a short reminder late in a long prompt is their measured remedy.`,modelFacing:!0},{id:`auto-mode-classifier-model`,name:`Auto-mode classifier model`,group:K.MISC_CONFIGURABLE,description:`Pin auto-mode bash safety classifier to Sonnet 4.6 or Haiku 4.5 instead of the user main-loop model (avoids Opus 4.7 congestion denying tool calls)`,modelFacing:!0},{id:`complexity-router`,name:`[EXPERIMENTAL] Complexity effort router`,group:K.FEATURES,description:`Choose reasoning effort for each user message only while an Effort Router model entry is selected. Uses Haiku, or Jev decisions with asynchronous Haiku conversation summaries, and honors explicit effort overrides. Jev requires a TypeSafe API key and sends the current message and bounded conversation context to TypeSafe. Off by default.`,modelFacing:!0},{id:`fable-plan`,name:`Fable Plan mode`,group:K.FEATURES,description:`Adds a "fableplan" entry to /model: Fable while planning, Opus while executing, each at the reasoning effort you set for that model in /model (Claude Code's per-model effort). Mirrors the mechanism Claude Code already ships for opusplan, so it is a MODEL YOU SELECT — nothing changes for any other model, your selection stays "fableplan" throughout, and no model is ever switched underneath you mid-session. Also surfaces Claude Code's own "Yes, clear context (N% used)" option on the plan-approval dialog, which Claude Code defaults off: clearing hands only the plan to the executing model, where continuing re-sends the entire planning transcript to a different one. Off by default.`,modelFacing:!0},{id:`complexity-router-models`,name:`Effort Router model entries`,group:K.FEATURES,description:`Adds opt-in Opus 5.5 and Fable 5.1 + Effort Router entries to /model. Ordinary models keep native effort behavior. Selecting a router entry enables the configured effort provider; switching away stops routing and background summaries.`,modelFacing:!0},{id:`allow-custom-agent-models`,name:`Allow custom agent models`,group:K.FEATURES,description:`Allow arbitrary model names in custom agent frontmatter (e.g. gemini-2.5-flash)`},{id:`unlock-responsive-mode`,name:`Unlock responsive mode`,group:K.FEATURES,description:`Make Claude Code's bundled responsive-mode plugin selectable. Claude Code 2.1.280 ships the whole feature in the binary - a system-reminder telling Claude to answer the message before it thinks or picks up a tool, and a system-prompt section ruling out stock AI phrasing (eager openers, agreement reflexes, corporate vocabulary, wrap-ups) - but gates it behind a server flag that answers no. This drops the flag check and keeps the session-kind guard, so the plugin appears in /plugin. It is registered DISABLED, so nothing changes until you turn it on there. Off by default.`,modelFacing:!0},{id:`worktree-mode`,name:`Worktree mode`,group:K.FEATURES,description:`Enable the EnterWorktree tool for isolated git worktree sessions`},{id:`session-memory`,name:`Session memory`,group:K.FEATURES,description:`Enable session memory (auto-extraction + past session search)`},{id:`swap-ripgrep-for-fff`,name:`[EXPERIMENTAL] fff for Bash search (grep/find/rg → fff)`,group:K.FEATURES,description:"[EXPERIMENTAL] Route Claude Code's Bash search through fff (fast file finder). CC 2.1.186 shadows the shell `grep`→embedded ugrep and `find`→embedded bfs (and offers `rg`); the agent uses grep ~136x more than rg. This repoints all three at a per-platform fff wrapper that serves, relevance-ranked from a warm-index daemon: literal, regex (RE2 — the dialect the model writes), case-insensitive (-i), multi-word phrases, context (-A/-B/-C), extension globs (-g/--include '*.ts'), and multi-path (app lib scripts) searches. Anything fff can't serve faithfully — PCRE, multiline/newline- or empty-matching regex, only-matching (-o), single-file, non-recursive grep, --no-ignore, find, non-ASCII, lines over 512 bytes, piped stdin → re-exec the real embedded ugrep/bfs/ripgrep. Every engine still ships; any uncertainty falls back, so results never diverge from the model's intent. Transparent (no prompt-compliance reliance) and CC-scoped (the user's own terminal grep/find/rg are untouched). Installs the wrapper into ~/.tweakcc/fff."},{id:`dream-mode`,name:`Dream mode`,group:K.FEATURES,description:`Enable dream (/dream + auto-dream background memory consolidation)`,modelFacing:!0},{id:`lean-memory-types`,name:`Lean memory types`,group:K.FEATURES,description:`Compact "Types of memory" prompt block + on-demand memory-types skill`,modelFacing:!0},{id:`toolsets`,name:`Toolsets`,group:K.FEATURES,description:`Custom toolsets will be registered`},{id:`mcp-non-blocking`,name:`MCP non-blocking`,group:K.FEATURES,description:`If you have MCP servers, CC startup will be much faster`},{id:`mcp-batch-size`,name:`MCP batch size`,group:K.FEATURES,description:`Change the number of MCP servers started in parallel`},{id:`user-message-display`,name:`User message display`,group:K.FEATURES,description:`User messages in the chat history will be styled`},{id:`input-pattern-highlighters`,name:`Input pattern highlighters`,group:K.FEATURES,description:`Custom input highlighters will be registered`},{id:`conversation-title`,name:`Conversation title`,group:K.FEATURES,description:`/title command will be created & enabled`},{id:`voice-mode`,name:`Voice mode`,group:K.FEATURES,description:`Enable /voice command for speech-to-text input (hold Space to record)`},{id:`channels-mode`,name:`Channels mode`,group:K.FEATURES,description:`Enable MCP channel notifications (--channels without allowlist or dev flag)`},{id:`suppress-deferred-tools`,name:`Suppress deferred tools list (DANGEROUS)`,group:K.SYSTEM_REMINDERS,description:`Kill the "deferred tools are now available via ToolSearch" announcement. WARNING: MCP/Cron/EnterPlanMode/WebFetch/Monitor become invisible to the model unless explicitly named.`,modelFacing:!0},{id:`claudemd-context-once-per-conversation`,name:`claudeMd context: once per conversation`,group:K.SYSTEM_REMINDERS,description:`Inject the claudeMd / userEmail / currentDate <system-reminder> only on the first API call per conversation (re-fires after /clear). Default: ON. Toggle OFF for vanilla CC per-turn injection.`,modelFacing:!0}],Hl=()=>[...Vl],q=e=>e.replace(/\$/g,`\\$`),Ul=(e,t,n)=>{let r=[];for(let i of Vl){let a=t[i.id];if(n&&!n.includes(i.id)&&i.id!==`no-global-cache-scope`){r.push({id:i.id,name:i.name,group:i.group,applied:!1,skipped:!0,details:`not in --patches filter`,description:i.description});continue}if(a.condition===!1){r.push({id:i.id,name:i.name,group:i.group,applied:!1,skipped:!0,details:`not enabled`,description:i.description});continue}J(`Applying patch: ${i.name}`);let o=[],s=console.error;console.error=(...e)=>{o.push(e.map(String).join(` `)),s(...e)};let c;try{c=a.fn(e)}finally{console.error=s}let l=c===null,u=!l&&c!==e,d=!l&&o.length>0;c!==null&&(e=c),r.push({id:i.id,name:i.name,group:i.group,applied:u,failed:l,...d&&{partial:d,details:`partially applied (${o[0].replace(/^patch: [^:]+: /,``)})`},description:i.description,modelFacing:i.modelFacing})}return{content:e,results:r}},Wl=e=>{if(process.env.TWEAKCC_ALLOW_CROSS_PLATFORM===`1`)return;let t=v(e,[`--version`],{encoding:`utf8`,timeout:15e3}),n=`${t.stdout??``}${t.stderr??``}`;if(t.error||t.status!==0||/Expected CommonJS module|Bun v|TypeError/.test(n)){let t=Error(`Patched native binary failed startup sanity check (${e}).\n`+n.trim());throw t.stack=t.message,t}},Gl=async(e,r,i)=>{let o,c=!1;if(r.nativeInstallationPath){await wl(r);let e=!1;try{await a.stat(ku),e=!0}catch{}let t=e?ku:r.nativeInstallationPath;J(`Extracting claude.js from ${e?`backup`:`native installation`}: ${t}`);let{data:n,clearBytecode:i,error:l}=await j(t,r.version);if(!n)throw Error(`Failed to extract claude.js from native installation${l?`: ${l}`:``}`);c=i;let d=u.join(Z,`native-claudejs-orig.js`);s.writeFileSync(d,n),J(`Saved original extracted JS from native to: ${d}`),o=n.toString(`utf8`)}else{if(await Cl(r),!r.cliPath)throw Error(`cliPath is required for NPM installations`);o=await a.readFile(r.cliPath,{encoding:`utf8`})}let l=[],d=o;if(r.version){let e=await Ei({pristine:d,version:r.version,patchFilter:i}).catch(e=>(J(`system-prompt preflight skipped: ${e}`),null)),n=[];for(let r of e?.findings??[]){let e=`preflight: ${Di(r)}`;r.severity===`error`?console.log(t.red(e)):(n.push(e),J(e))}n.length>0&&J(`system-prompt preflight: ${n.length} advisory finding(s) — run --validate-system-prompts for the full report`);let a=(e?.findings??[]).filter(e=>e.check===`raw-non-ascii`);if(a.length>0)throw Error(`system-prompt preflight found ${a.length} span(s) that would introduce raw non-ASCII into the binary; nothing was modified. Re-run with --validate-system-prompts for the full report.`)}let f=await xi(o);o=f.content;let p=f.results.filter(e=>e.applied),m=f.results.filter(e=>e.failed);if(f.results.length>0){J(`inlineBlobOverrides: ${p.length} applied, ${m.length} failed`);for(let e of m)console.log(`inline-blob: failed "${e.name}" (${e.filename}): ${e.details}`)}for(let e of f.results)l.push({id:`inline-blob:${e.filename}`,name:e.name,group:K.SYSTEM_PROMPTS,applied:e.applied,failed:e.failed,skipped:e.skipped,details:e.details});let h=await rn(o,r.version??``);o=h.content;for(let e of h.results)l.push({id:`reminder:${e.id}`,name:`Reminder: ${e.name} (${e.state})`,group:K.SYSTEM_REMINDERS,applied:e.applied,failed:e.failed,skipped:e.skipped,details:e.details,description:e.description});let g=await ai(o,r.version,void 0,i,d);o=g.newContent;let _=g.results.some(e=>e.applied&&[`system-prompt-identity`,`system-prompt-cli-identity-agent-sdk`,`system-prompt-claude-agent-identity-sdk`].includes(e.id)),v=[...g.results].sort((e,t)=>e.name.localeCompare(t.name));l.push(...v);let y=e=>e.replace(/\\/g,`\\\\`).replace(/`/g,"\\`").replace(/\$/g,`\\$`),b=v.filter(e=>e.applied&&e.details).map(e=>y(`${e.name}: ${e.details}`)),x=e.settings.misc?.tableFormat??`default`,S=e.settings.misc?.showTweakccVersion??!0,C=e.settings.misc?.showPatchesApplied??!0,w=e.settings.misc?.enableModelCustomizations??!0,T=!!e.settings.misc?.swapRipgrepForFff,E=null;T&&(E=await ul(),E||console.log(`patch: swapRipgrepForFff: no fff wrapper available for this platform — keeping ripgrep`));let O={"verbose-property":{fn:e=>Ge(e),condition:!r.nativeInstallationPath},"read-default-lines":{fn:e=>Kc(e)},"context-limit":{fn:e=>ge(e),condition:!!e.settings.misc?.enableContextLimitOverride},opusplan1m:{fn:e=>Qe(e),condition:w&&!r.nativeInstallationPath},"thinking-block-styling":{fn:e=>Ao(e),condition:r.version==null||_t(r.version,`2.1.26`)<0},"fix-lsp-support":{fn:e=>ki(e)},"no-global-cache-scope":{fn:e=>Li(e,d,_)},"fix-summarize-from-here":{fn:e=>Ri(e),condition:e.settings.misc?.fixSummarizeFromHere!==!1},"fix-rewind-summary-header":{fn:e=>zi(e),condition:e.settings.misc?.fixRewindSummaryHeader!==!1},"statusline-update-throttle":{fn:t=>Io(t,e.settings.misc?.statuslineThrottleMs??300,e.settings.misc?.statuslineUseFixedInterval??!1),condition:e.settings.misc?.statuslineThrottleMs!=null},"clear-screen":{fn:e=>zc(e)},"strip-empty-system-reminders":{fn:e=>fl(e)},"patches-applied-indication":{fn:e=>gt(e,D,b,S,C)},"model-customizations":{fn:e=>Jl(e),condition:w},"show-more-items-in-select-menus":{fn:e=>le(e,25),condition:w},"table-format":{fn:e=>za(e,x),condition:x!==`default`},themes:{fn:t=>me(t,e.settings.themes),condition:!!(e.settings.themes&&e.settings.themes.length>0&&JSON.stringify(e.settings.themes)!==JSON.stringify(P.themes))},"thinking-verbs":{fn:t=>ke(t,e.settings.thinkingVerbs.verbs),condition:!!e.settings.thinkingVerbs&&JSON.stringify(e.settings.thinkingVerbs.verbs)!==JSON.stringify(P.thinkingVerbs.verbs)},"thinker-format":{fn:t=>be(t,e.settings.thinkingVerbs.format),condition:!!e.settings.thinkingVerbs&&e.settings.thinkingVerbs.format!==P.thinkingVerbs.format},"thinker-symbol-chars":{fn:t=>Ce(t,e.settings.thinkingStyle.phases),condition:JSON.stringify(e.settings.thinkingStyle.phases)!==JSON.stringify(P.thinkingStyle.phases)},"thinker-symbol-speed":{fn:t=>we(t,e.settings.thinkingStyle.updateInterval),condition:e.settings.thinkingStyle.updateInterval!==P.thinkingStyle.updateInterval&&(r.version==null||_t(r.version,`2.1.27`)<0)},"thinker-symbol-width":{fn:t=>Ee(t,Math.max(...e.settings.thinkingStyle.phases.map(e=>e.length))+1),condition:JSON.stringify(e.settings.thinkingStyle.phases)!==JSON.stringify(P.thinkingStyle.phases)},"thinker-symbol-mirror":{fn:t=>Se(t,e.settings.thinkingStyle.reverseMirror),condition:e.settings.thinkingStyle.reverseMirror!==P.thinkingStyle.reverseMirror},"input-box-border":{fn:t=>_e(t,e.settings.inputBox.removeBorder),condition:!!(e.settings.inputBox&&e.settings.inputBox.removeBorder!==P.inputBox.removeBorder)},"input-chevron-color":{fn:t=>{let n=e.settings.inputBox.chevronIdleThemeColor;return ve(t,e.settings.themes?.[0]?.colors?.[n]??n)},condition:!!e.settings.inputBox?.chevronIdleThemeColor},"subagent-models":{fn:t=>rt(t,e.settings.subagentModels),condition:!!e.settings.subagentModels&&JSON.stringify(e.settings.subagentModels)!==JSON.stringify(P.subagentModels)},"thinking-visibility":{fn:e=>$e(e),condition:e.settings.misc?.expandThinkingBlocks??!0},"hide-startup-banner":{fn:e=>eo(e),condition:!!e.settings.misc?.hideStartupBanner},"hide-ctrl-g-to-edit":{fn:e=>no(e),condition:!!e.settings.misc?.hideCtrlGToEdit},"hide-startup-clawd":{fn:e=>oo(e),condition:!!e.settings.misc?.hideStartupClawd},"increase-file-read-limit":{fn:e=>co(e),condition:!!e.settings.misc?.increaseFileReadLimit},"suppress-line-numbers":{fn:e=>uo(e),condition:!!e.settings.misc?.suppressLineNumbers},"suppress-rate-limit-options":{fn:e=>mo(e),condition:!!e.settings.misc?.suppressRateLimitOptions},"suppress-rate-limit-warning":{fn:e=>ho(e),condition:!!e.settings.misc?.suppressRateLimitWarning},"session-color":{fn:e=>Wc(e),condition:!!e.settings.misc?.sessionColor},"token-count-rounding":{fn:t=>Bo(t,e.settings.misc.tokenCountRounding),condition:!!e.settings.misc?.tokenCountRounding},"remember-skill":{fn:e=>ko(e),condition:!!e.settings.misc?.enableRememberSkill},"agents-md":{fn:t=>Vo(t,e.settings.claudeMdAltNames),condition:!!(e.settings.claudeMdAltNames&&e.settings.claudeMdAltNames.length>0)},"auto-accept-plan-mode":{fn:e=>Zo(e),condition:!!e.settings.misc?.autoAcceptPlanMode},"allow-sudo-bypass-permissions":{fn:e=>Qo(e),condition:!!e.settings.misc?.allowBypassPermissionsInSudo},"suppress-native-installer-warning":{fn:e=>es(e),condition:!!e.settings.misc?.suppressNativeInstallerWarning},"model-at-effort":{fn:e=>ts(e),condition:e.settings.misc?.modelAtEffort??!0},"filter-scroll-escape-sequences":{fn:e=>rs(e),condition:!!e.settings.misc?.filterScrollEscapeSequences},"max-effort-default":{fn:e=>ss(e),condition:!!e.settings.misc?.maxEffortDefault},"autonomous-operation-all-models":{fn:e=>cs(e),condition:!!e.settings.misc?.autonomousOperationAllModels},"refusal-fallback-model":{fn:t=>Fs(t,e.settings.misc?.refusalFallbackRoutes,e.settings.misc?.refusalFallbackMaxReturns),condition:!!e.settings.misc?.refusalFallbackModel},"output-style-turn-reminder":{fn:e=>Ls(e),condition:!!e.settings.misc?.outputStyleTurnReminder},"auto-mode-classifier-model":{fn:t=>zs(t,e.settings.misc?.autoModeClassifierModel??`default`),condition:(e.settings.misc?.autoModeClassifierModel??`default`)!==`default`},"complexity-router":{fn:t=>dc(t,e.settings.complexityRouter),condition:e.settings.complexityRouter.enabled},"fable-plan":{fn:t=>Oc(t,e.settings.fablePlan),condition:e.settings.fablePlan.enabled},"complexity-router-models":{fn:e=>gc(e),condition:e.settings.complexityRouter.enabled},"allow-custom-agent-models":{fn:e=>os(e),condition:!!e.settings.misc?.allowCustomAgentModels},"unlock-responsive-mode":{fn:e=>as(e),condition:!!e.settings.misc?.unlockResponsiveMode},"worktree-mode":{fn:e=>is(e),condition:!!e.settings.misc?.enableWorktreeMode},"session-memory":{fn:e=>Co(e),condition:!!e.settings.misc?.enableSessionMemory},"swap-ripgrep-for-fff":{fn:e=>rl(e,E),condition:T&&!!E},"dream-mode":{fn:e=>wo(e),condition:!!e.settings.misc?.enableDreamMode},"lean-memory-types":{fn:e=>To(e),condition:!!e.settings.misc?.enableLeanMemoryTypes},toolsets:{fn:t=>Da(t,e.settings.toolsets,e.settings.defaultToolset,e.settings.acceptEditsToolset,e.settings.planModeToolset),condition:!!(e.settings.toolsets&&e.settings.toolsets.length>0)},"mcp-non-blocking":{fn:e=>Po(e),condition:!!e.settings.misc?.mcpConnectionNonBlocking&&(r.version==null||_t(r.version,`2.1.85`)<0)},"mcp-batch-size":{fn:t=>Fo(t,e.settings.misc.mcpServerBatchSize),condition:!!e.settings.misc?.mcpServerBatchSize},"user-message-display":{fn:t=>Re(t,e.settings.userMessageDisplay),condition:!!(e.settings.userMessageDisplay&&JSON.stringify(e.settings.userMessageDisplay)!==JSON.stringify(P.userMessageDisplay))},"input-pattern-highlighters":{fn:t=>Ue(t,e.settings.inputPatternHighlighters),condition:!!(e.settings.inputPatternHighlighters&&e.settings.inputPatternHighlighters.length>0)},"conversation-title":{fn:e=>Za(e),condition:(e.settings.misc?.enableConversationTitle??!0)&&!r.nativeInstallationPath},"voice-mode":{fn:t=>Mc(t,e.settings.misc?.enableVoiceConciseOutput??!0),condition:!!e.settings.misc?.enableVoiceMode},"channels-mode":{fn:e=>Rc(e),condition:!!e.settings.misc?.enableChannelsMode},"suppress-deferred-tools":{fn:e=>pl(e),condition:!!e.settings.misc?.suppressDeferredTools},"claudemd-context-once-per-conversation":{fn:e=>dl(e),condition:e.settings.misc?.claudemdContextOncePerConversation??!1}},{content:k,results:A}=Ul(o,O,i);o=k,l.push(...A);let N=A.filter(e=>e.failed);if(r.nativeInstallationPath&&N.length>0){let e=Error(`Refusing to repack the native binary: ${N.length} binary patch(es) failed (${N.map(e=>e.id).join(`, `)}) on Claude Code ${r.version}. The binary was left unchanged — your Claude Code still works. Each failure’s cause is in the "patch: … failed to …" line(s) above; this usually means Anthropic changed the code shape in CC ${r.version}, so a patch’s pattern no longer matches. Update tweakcc-fixed, or disable the failing optional patch(es) in ~/.tweakcc/config.json, then re-run --apply.`);throw e.stack=e.message,e}if(r.nativeInstallationPath){J(`Repacking modified claude.js into native installation: ${r.nativeInstallationPath}`);let e=u.join(Z,`native-claudejs-patched.js`);s.writeFileSync(e,o,`utf8`),J(`Saved patched JS from native to: ${e}`);let t=Buffer.from(o,`utf8`),i=await a.mkdtemp(u.join(n.tmpdir(),`tweakcc-native-`)),l=u.join(i,u.basename(r.nativeInstallationPath));try{await a.copyFile(r.nativeInstallationPath,l),await a.chmod(l,s.statSync(r.nativeInstallationPath).mode),await M(l,t,l,c),Wl(l);let e=r.nativeInstallationPath,n=u.join(u.dirname(e),`.${u.basename(e)}.tweakcc-${process.pid}`);try{await a.copyFile(l,n),await a.chmod(n,s.statSync(e).mode),await a.rename(n,e)}catch(e){throw await a.rm(n,{force:!0}),e}}finally{await a.rm(i,{recursive:!0,force:!0})}}else{if(!r.cliPath)throw Error(`cliPath is required for NPM installations`);N.length>0&&console.warn(`tweakcc: ${N.length} patch(es) did not apply on Claude Code ${r.version}: ${N.map(e=>e.id).join(`, `)}. Those feature(s) are skipped; everything else was applied. Each cause is in the "patch: … failed to …" line(s) above — usually a CC version whose code shape a patch does not match yet. Update tweakcc-fixed, or disable the failing optional patch(es) in ~/.tweakcc/config.json.`),await gu(r.cliPath,o,`patch`)}return{config:await zu(e=>{e.changesApplied=!0}),results:l}},Kl=[{value:`claude-opus-4-6`,label:`Opus 4.6`,description:`Claude Opus 4.6 (February 2026)`},{value:`claude-sonnet-4-6`,label:`Sonnet 4.6`,description:`Claude Sonnet 4.6 (February 2026)`},{value:`claude-haiku-4-5-20251001`,label:`Haiku 4.5`,description:`Claude Haiku 4.5 (October 2025)`},{value:`claude-opus-4-5-20251101`,label:`Opus 4.5`,description:`Claude Opus 4.5 (November 2025)`},{value:`claude-sonnet-4-5-20250929`,label:`Sonnet 4.5`,description:`Claude Sonnet 4.5 (September 2025)`},{value:`claude-opus-4-1-20250805`,label:`Opus 4.1`,description:`Claude Opus 4.1 (August 2025)`},{value:`claude-opus-4-20250514`,label:`Opus 4`,description:`Claude Opus 4 (May 2025)`},{value:`claude-sonnet-4-20250514`,label:`Sonnet 4`,description:`Claude Sonnet 4 (May 2025)`},{value:`claude-3-7-sonnet-20250219`,label:`Sonnet 3.7`,description:`Claude 3.7 Sonnet (February 2025)`},{value:`claude-3-5-sonnet-20241022`,label:`Sonnet 3.5 (October)`,description:`Claude 3.5 Sonnet (October 2024)`},{value:`claude-3-5-haiku-20241022`,label:`Haiku 3.5`,description:`Claude 3.5 Haiku (October 2024)`},{value:`claude-3-5-sonnet-20240620`,label:`Sonnet 3.5 (June)`,description:`Claude 3.5 Sonnet (June 2024)`},{value:`claude-3-haiku-20240307`,label:`Haiku 3`,description:`Claude 3 Haiku (March 2024)`},{value:`claude-3-opus-20240229`,label:`Opus 3`,description:`Claude 3 Opus (February 2024)`}],ql=e=>{let t=e.match(/(?<![$\w])([$\w]+)\.push\(\{value:[$\w]+,label:[^,]{1,40},description:[^"]{0,40}"Custom model"/);if(!t||t.index===void 0)return console.error(`patch: findCustomModelListInsertionPoint: failed to find custom model push`),null;let n=t[1],r=Math.max(0,t.index-5e3),i=e.slice(r,t.index),a=`(?:(?:let|var|const) |,)${q(n)}=.+?;`,o=RegExp(`function [$\\w]+\\([^)]*\\)\\{[\\s\\S]{0,5000}?${a}`,`g`),s=null,c;for(;(c=o.exec(i))!==null;)s=c;return s?{insertionIndex:r+s.index+s[0].length,modelListVar:n}:(console.error(`patch: findCustomModelListInsertionPoint: failed to find function with ${n}`),null)},Jl=e=>{if(e.includes(`"value":"claude-opus-4-6"`))return console.log(`patch: modelCustomizations: custom models already present — skipping`),e;let t=ql(e);if(!t)return null;let{insertionIndex:n,modelListVar:r}=t,i=Kl.map(e=>`${r}.push(${JSON.stringify(e)});`).join(``),a=e.slice(0,n)+i+e.slice(n);return B(e,a,i,n,n),a};let Yl=!1,Xl=!1,Zl=!1;const Ql=()=>Yl,$l=()=>Xl,eu=()=>Zl,tu=()=>{Yl=!0},nu=()=>{Xl=!0,Yl=!0},ru=()=>{Zl=!0},J=(e,...t)=>{Ql()&&console.log(e,...t)},Y=(e,...t)=>{$l()&&console.log(e,...t)},X=e=>e.replace(/[\u0080-\uffff]/g,e=>`\\u`+e.charCodeAt(0).toString(16).padStart(4,`0`));function iu(){try{let e=p.join(m.homedir(),`.claude.json`);return JSON.parse(f.readFileSync(e,`utf8`)).theme||`dark`}catch{}return`dark`}function au(e){try{let t=p.join(m.homedir(),`.claude.json`),n=JSON.parse(f.readFileSync(t,`utf8`));n.theme=e,f.writeFileSync(t,JSON.stringify(n,null,2))}catch{}}function ou(){try{let e=p.join(m.homedir(),`.claude`,`.credentials.json`);switch(JSON.parse(f.readFileSync(e,`utf8`))?.claudeAiOauth?.subscriptionType||`unknown`){case`enterprise`:return`Claude Enterprise`;case`team`:return`Claude Team`;case`max`:return`Claude Max`;case`pro`:return`Claude Pro`}}catch{}return`Claude API`}function su(){try{let e=p.join(m.homedir(),`.claude`,`settings.json`),t=JSON.parse(f.readFileSync(e,`utf8`))?.model||`default`;if(t===`opus`)return`Opus 4.5`;let n=Kl.find(e=>e.value===t);if(n)return n.label}catch{}return`Opus 4.5`}function cu(e){process.platform===`win32`?h.spawn(`explorer`,[e],{detached:!0,stdio:`ignore`}).unref():process.platform===`darwin`?h.spawn(`open`,[e],{detached:!0,stdio:`ignore`}).unref():h.spawn(`xdg-open`,[e],{detached:!0,stdio:`ignore`}).unref()}function lu(e){if(process.platform===`win32`)h.spawn(`explorer`,[`/select,`,e],{detached:!0,stdio:`ignore`}).unref();else if(process.platform===`darwin`)h.spawn(`open`,[`-R`,e],{detached:!0,stdio:`ignore`}).unref();else{let t=p.dirname(e);h.spawn(`xdg-open`,[t],{detached:!0,stdio:`ignore`}).unref()}}function uu(e,t=`md`){let n=process.env.VISUAL||process.env.EDITOR||(process.platform===`win32`?`notepad`:`vi`),r=p.join(m.tmpdir(),`tweakcc-edit-${process.pid}-${Date.now()}.${t}`);try{f.writeFileSync(r,e,`utf8`);let t=h.spawnSync(`${n} "${r}"`,{stdio:`inherit`,shell:!0});return t.error||typeof t.status==`number`&&t.status!==0?null:f.readFileSync(r,`utf8`)}catch{return null}finally{try{f.unlinkSync(r)}catch{}}}function du(e){if(!e||typeof e!=`string`)return!1;let t=e.trim();if(/^#([a-fA-F0-9]{3}|[a-fA-F0-9]{6})$/.test(t))return!0;if(/^rgb\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*\)$/.test(t)){let e=t.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/);if(e){let[,t,n,r]=e;return parseInt(t)<=255&&parseInt(n)<=255&&parseInt(r)<=255}}if(/^hsl\(\s*\d{1,3}\s*,\s*\d{1,3}%\s*,\s*\d{1,3}%\s*\)$/.test(t)){let e=t.match(/hsl\((\d+),\s*(\d+)%,\s*(\d+)%\)/);if(e){let[,t,n,r]=e;return parseInt(t)<=360&&parseInt(n)<=100&&parseInt(r)<=100}}return!1}function fu(e){if(!du(e))return e;let t=e.trim();if(t.startsWith(`rgb(`))return t;if(t.startsWith(`#`)){let e=t.slice(1);return e.length===3&&(e=e.split(``).map(e=>e+e).join(``)),`rgb(${parseInt(e.slice(0,2),16)},${parseInt(e.slice(2,4),16)},${parseInt(e.slice(4,6),16)})`}if(t.startsWith(`hsl(`)){let e=t.match(/hsl\((\d+),\s*(\d+)%,\s*(\d+)%\)/);if(e){let t=parseInt(e[1])/360,n=parseInt(e[2])/100,r=parseInt(e[3])/100,i=(e,t,n)=>(n<0&&(n+=1),n>1&&--n,n<1/6?e+(t-e)*6*n:n<1/2?t:n<2/3?e+(t-e)*(2/3-n)*6:e),a=r<.5?r*(1+n):r+n-r*n,o=2*r-a;return`rgb(${Math.round(i(o,a,t+1/3)*255)},${Math.round(i(o,a,t)*255)},${Math.round(i(o,a,t-1/3)*255)})`}}return e}async function pu(e,t=`sha256`,n=64*1024){return new Promise((r,i)=>{let a=g.createHash(t),o=f.createReadStream(e,{highWaterMark:n});o.on(`data`,e=>{a.update(e)}),o.on(`end`,()=>{r(a.digest(`hex`))}),o.on(`error`,e=>{i(e)})})}async function mu(e,t){try{let n=await o.stat(e);return J(`[${t}] Original file mode for ${e}: ${(n.mode&511).toString(8)}`),n.mode}catch(n){return J(`[${t}] Could not stat ${e} (error: ${n}), using default mode 755`),493}}async function hu(e,t,n,r){let i=`${e}.tweakcc-tmp-${process.pid}`;try{await r(i),await o.chmod(i,t),await o.rename(i,e)}catch(e){try{await o.unlink(i)}catch{}throw e}J(`[${n}] Replaced ${e} via atomic rename, mode ${(t&511).toString(8)}`)}async function gu(e,t,n=`replace`){await hu(e,await mu(e,n),n,e=>o.writeFile(e,t))}async function _u(e,t,n=`replace`){await hu(e,await mu(e,n),n,e=>o.copyFile(t,e))}async function vu(e){try{return await o.stat(e),!0}catch(e){if(e instanceof Error&&`code`in e&&(e.code===`ENOENT`||e.code===`ENOTDIR`||e.code===`EACCES`||e.code===`EPERM`))return!1;throw e}}const yu=e=>e.startsWith(`~`)?p.join(m.homedir(),e.slice(1)):e,bu=(e,t)=>{let n=e=>{let t=e.split(`.`).map(Number);return[t[0]||0,t[1]||0,t[2]||0]},r=n(e),i=n(t);return r[0]===i[0]?r[1]===i[1]?r[2]-i[2]:r[1]-i[1]:r[0]-i[0]},xu=e=>{let t=e.toString(),n=t.lastIndexOf(`/`);return`new RegExp(${JSON.stringify(t.substring(1,n))}, ${JSON.stringify(t.substring(n+1))})`};function Su(e,t){if(e==null)return t;if(typeof t!=`object`||!t)return e;if(Array.isArray(t))return Array.isArray(e)?e:t;let n={...e};for(let e of Object.keys(t)){let r=t[e];e in n?typeof r==`object`&&r&&!Array.isArray(r)&&(n[e]=Su(n[e],r)):n[e]=r}return n}const Cu=async(e,t=33554432)=>{let n=Number(e.headers.get(`content-length`));if(Number.isFinite(n)&&n>t)throw Error(`Response body too large: ${n} bytes exceeds the ${t}-byte limit.`);let r=e.body;if(!r){let n=await e.text();if(Buffer.byteLength(n,`utf8`)>t)throw Error(`Response body exceeds the ${t}-byte limit.`);return n}let i=r.getReader(),a=[],o=0;for(;;){let{done:e,value:n}=await i.read();if(e)break;if(n){if(o+=n.byteLength,o>t)throw await i.cancel().catch(()=>{}),Error(`Response body exceeds the ${t}-byte limit — aborting download.`);a.push(Buffer.from(n))}}return Buffer.concat(a).toString(`utf8`)},wu=e=>{let t=e?.settings?.userMessageDisplay;if(!t)return;let n=!!t.prefix,r=`borderStyle`in t,i=`padding`in t,a=`paddingX`in t,o=`fitBoxToContent`in t,s=t.padding;n&&(e.settings.userMessageDisplay={format:(t.prefix?.format||``)+(t.message?.format||`{}`),styling:[...t.prefix?.styling||[],...t.message?.styling||[]],foregroundColor:t.message?.foregroundColor===`rgb(0,0,0)`?`default`:t.message?.foregroundColor||t.prefix?.foregroundColor||`default`,backgroundColor:t.message?.backgroundColor===`rgb(0,0,0)`?null:t.message?.backgroundColor||t.prefix?.backgroundColor||null,borderStyle:`none`,borderColor:`rgb(255,255,255)`,paddingX:0,paddingY:0,fitBoxToContent:!1});let c=e.settings.userMessageDisplay;r||(c.borderStyle=`none`,c.borderColor=`rgb(255,255,255)`),i&&!a?(c.paddingX=s||0,c.paddingY=0,delete c.padding):a||(c.paddingX=0,c.paddingY=0),o||(c.fitBoxToContent=!1)},Tu=e=>{let t=e?.settings?.misc;t&&`hideCtrlGToEditPrompt`in t&&(t.hideCtrlGToEdit=t.hideCtrlGToEditPrompt,delete t.hideCtrlGToEditPrompt)};async function Eu(){try{let e=await o.readFile(Q,`utf8`),t=JSON.parse(e);return Object.hasOwn(t,`ccInstallationDir`)?(t.ccInstallationDir&&!t.ccInstallationPath&&(t.ccInstallationPath=d.join(t.ccInstallationDir,`cli.js`)),delete t.ccInstallationDir,t.lastModified=new Date().toISOString(),await Nu(),await o.writeFile(Q,JSON.stringify(t,null,2)),!0):!1}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`||e instanceof SyntaxError)return!1;throw e}}const Du=()=>{let e=process.env.TWEAKCC_CONFIG_DIR?.trim();if(e&&e.length>0)return yu(e);let t=d.join(r.homedir(),`.tweakcc`),n=d.join(r.homedir(),`.claude`,`tweakcc`),i=process.env.XDG_CONFIG_HOME;try{if(c.existsSync(t))return t}catch(e){J(`Failed to check if ${t} exists: ${e}`)}try{if(c.existsSync(n))return n}catch(e){J(`Failed to check if ${n} exists: ${e}`)}return i?d.join(i,`tweakcc`):t},Z=Du(),Q=d.join(Z,`config.json`),Ou=d.join(Z,`cli.js.backup`),ku=d.join(Z,`native-binary.backup`),$=d.join(Z,`system-prompts`),Au=d.join(Z,`system-reminders`),ju=d.join(Z,`prompt-data-cache`),Mu=()=>{let e=Z,n=r.homedir(),i=[d.join(n,`.tweakcc`),d.join(n,`.claude`,`tweakcc`),process.env.XDG_CONFIG_HOME?d.join(process.env.XDG_CONFIG_HOME,`tweakcc`):null].filter(e=>e!==null).filter(t=>{try{return c.existsSync(t)&&t!==e}catch{return!1}});i.length>0&&(console.warn(t.yellow(`
|
|
1061
1061
|
Multiple configuration locations detected:`)),console.warn(t.gray(` Active: ${e}`)),console.warn(t.gray(` Other existing locations:`)),i.forEach(e=>{console.warn(t.gray(` - ${e}`))}),console.warn(t.gray(` Only the active location is used. To switch locations,`)),console.warn(t.gray(` move your config.json to the desired directory.
|