verifiable-thinking-mcp 0.6.0 → 0.6.1

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/dist/index.js CHANGED
@@ -343,7 +343,7 @@ Verb: "${E}" (base: ${I.toFixed(2)} → boosted: ${C.toFixed(2)})
343
343
  Domain: ${W} (weight: ${V.toFixed(2)})
344
344
  Intensity: ${w.join(", ")||"none"} (modifier: ${L.toFixed(2)}x)
345
345
 
346
- Calculation: ${C.toFixed(2)} × ${V.toFixed(2)} × ${L.toFixed(2)} = ${d.toFixed(3)}`;return{score:d,tier:zA,confidence:{level:r,inGrayZone:O,boundaryDistance:m},explanation:{verb_type:E,verb_score:C,domain_detected:W,domain_weight:V,intensity_signals:w,intensity_modifier:L},reasoning:$.trim()}}var fcA={min_significant_drop:0.15,min_significant_recovery:0.15,unresolved_threshold:0.3,min_steps:3,overconfident_threshold:0.85,overconfident_max_variance:0.05,cliff_drop_threshold:0.3,declining_final_threshold:0.5};function v_(A,Q={}){let B={...fcA,...Q};if(A.length<B.min_steps)return{drift_score:0,unresolved:!1,min_confidence:A[0]?.verification?.confidence??0.5,min_step:A[0]?.step_number??1,max_drop:0,recovery:0,has_revision_after_drop:!1,pattern:"insufficient",explanation:`Insufficient steps for drift analysis (${A.length} < ${B.min_steps})`,suggestion:null};let E=A.map((zA)=>zA.verification?.confidence??0.5),I=A.map((zA)=>zA.step_number),C=E[0],D=0,U=E[0],Y=0,F=0,g=E[0];for(let zA=1;zA<E.length;zA++){let KA=E[zA];if(KA<C)C=KA,D=zA;if(KA>U)U=KA,Y=zA;if(KA>g)g=KA;else{let kA=g-KA;if(kA>F)F=kA}}let N=E[E.length-1],J=N-C,G=A.slice(D+1).some((zA)=>zA.revises_step!==void 0),M=hcA(E,D,Y,F,J,B),H=Math.max(1,E.length-1-D),X;if(M==="v_shaped"){let zA=F,KA=F*J/H;X=Math.max(zA,KA)}else X=F*0.5;let W=Math.min(1,Math.max(0,X)),V=M==="v_shaped",L=M==="stable_overconfident",w=M==="cliff",z=F>=B.min_significant_drop,Z=J>=B.min_significant_recovery,K=V&&z&&Z&&!G&&W>=B.unresolved_threshold,R=E.length>=2?E[E.length-2]-E[E.length-1]:0,j=w&&R>=B.cliff_drop_threshold,q=M==="declining"&&N<B.declining_final_threshold,y=K||L||j||q,t=L||j||q?Math.max(W,0.4):W,u=ucA(M,F,J,D,I,G,C),d=y?mcA(I[D],F,M,C):null;return{drift_score:t,unresolved:y,min_confidence:C,min_step:I[D],max_drop:F,recovery:J,has_revision_after_drop:G,pattern:M,explanation:u,suggestion:d}}function hcA(A,Q,B,E,I,C){let D=A.length,U=Math.max(...A)-Math.min(...A);if(Q>0&&Q<D-1&&E>=C.min_significant_drop&&I>=C.min_significant_recovery)return"v_shaped";if(Q>=D-1&&E>=C.min_significant_drop&&D>=2){let M=A[D-2]-A[D-1],H=0;for(let W=1;W<D-1;W++)H+=Math.abs(A[W]-A[W-1]);let X=D>2?H/(D-2):0;if(M>=C.min_significant_drop&&M>=X*2)return"cliff"}if(Math.min(...A)>=C.overconfident_threshold&&U<=C.overconfident_max_variance)return"stable_overconfident";if(U<0.1)return"stable";let g=0;for(let M=1;M<D;M++)if(A[M]<A[M-1])g++;if(g>=(D-1)*0.7)return"declining";let N=0;for(let M=1;M<D;M++)if(A[M]>A[M-1])N++;if(N>=(D-1)*0.7)return"improving";let J=0,G=0;for(let M=1;M<D;M++){let H=Math.sign(A[M]-A[M-1]);if(H!==0&&H!==G)J++,G=H}if(J>=3)return"oscillating";return"stable"}function ucA(A,Q,B,E,I,C,D){let U=(Q*100).toFixed(0),Y=(B*100).toFixed(0),F=I[E];switch(A){case"stable":return"Confidence remained stable throughout reasoning chain.";case"stable_overconfident":return`⚠️ Stable high confidence (≥${((D??0.85)*100).toFixed(0)}%) throughout chain. On complex/trap questions, consistent high confidence without doubt often correlates with incorrect answers.`;case"declining":if(D!==void 0&&D<0.5)return`⚠️ Confidence declined steadily to ${(D*100).toFixed(0)}% (${U}% total drop). Ending with low confidence suggests unresolved uncertainty.`;return`Confidence declined steadily (${U}% total drop). This may indicate increasing uncertainty or problem difficulty.`;case"improving":return`Confidence improved throughout reasoning (${Y}% increase). Good progressive understanding.`;case"v_shaped":if(C)return`V-shaped confidence pattern detected: ${U}% drop at step ${F}, then ${Y}% recovery. Revision step present - uncertainty was addressed.`;else return`⚠️ V-shaped confidence pattern: ${U}% drop at step ${F}, then ${Y}% recovery WITHOUT revision. The reasoning may have "pushed through" uncertainty without addressing it.`;case"oscillating":return"Confidence oscillated throughout reasoning. Multiple uncertainty points encountered.";case"cliff":return`Confidence dropped sharply at the end (${U}% drop). Possible error or contradiction detected late in reasoning.`;case"insufficient":return"Not enough steps for meaningful drift analysis.";default:return"Confidence pattern analyzed."}}function mcA(A,Q,B,E){if(B==="stable_overconfident")return`High confidence (${((E??0.85)*100).toFixed(0)}%+) throughout suggests possible overconfidence. Consider: Is this a trick question? Have you verified assumptions? Adding a self-check step could help catch errors.`;if(B==="cliff")return`Sharp confidence drop (${(Q*100).toFixed(0)}%) at the final step suggests an error or contradiction was detected late. Consider: What caused this doubt? Should you revise earlier steps before concluding?`;if(B==="declining")return`Confidence declined to ${((E??0.5)*100).toFixed(0)}% by the end. The reasoning chain ended with significant doubt. Consider: What's causing the uncertainty? Is the approach valid? Should you try a different method?`;if(Q>=0.3)return`Consider revising from step ${A} where confidence dropped significantly. The recovery without explicit revision suggests the uncertainty was not properly addressed.`;else return`Review step ${A} where confidence was lowest. Adding explicit reasoning about why confidence recovered could strengthen the chain.`}var jYA=/(?:let\s+)?([a-zA-Z_][a-zA-Z0-9_]*)\s*[:=]=?\s*(-?\d+(?:\.\d+)?)/g,T_={always:["never","sometimes","rarely"],never:["always","sometimes","often"],all:["none","some","few"],none:["all","some","many"],every:["no","some","few"],must:["cannot","might","may not"],cannot:["must","can","might"],true:["false"],false:["true"],impossible:["possible","certain","likely"],certain:["impossible","uncertain","unlikely"]},k_={positive:["negative","zero"],negative:["positive","zero"],increasing:["decreasing","constant"],decreasing:["increasing","constant"],greater:["less","equal"],less:["greater","equal"],above:["below","at"],below:["above","at"]};function lcA(A,Q){let B=new Map,E;jYA.lastIndex=0;while((E=jYA.exec(A))!==null){let I=E[1]?.toLowerCase(),C=E[2];if(!I||!C)continue;let D=Math.max(0,E.index-20),U=Math.min(A.length,E.index+E[0].length+20),Y=A.slice(D,U);B.set(I,{step:Q,value:C,context:Y})}return B}function ccA(A,Q){let B=new Map,E=A.toLowerCase();for(let[I,C]of Object.entries(T_))if(new RegExp(`\\b${I}\\b`,"gi").test(E)){let U=E.indexOf(I),Y=Math.max(0,U-30),F=Math.min(A.length,U+I.length+30),g=A.slice(Y,F),N=`logical:${I}`;B.set(N,{step:Q,value:I,context:g})}return B}function pcA(A,Q){let B=new Map,E=A.toLowerCase();for(let[I,C]of Object.entries(k_))if(new RegExp(`\\b${I}\\b`,"gi").test(E)){let U=E.indexOf(I),Y=Math.max(0,U-30),F=Math.min(A.length,U+I.length+30),g=A.slice(Y,F),N=g.match(/\b(the\s+)?([a-zA-Z_][a-zA-Z0-9_]*)\b/i),J=N?N[2]||"value":"value",G=`sign:${I}`;B.set(G,{step:Q,value:I,context:`${J}: ${g}`})}return B}function icA(A,Q,B){if(A.match(/^[a-z_][a-z0-9_]*$/i)){if(Q.value!==B.value)return{type:"value_reassignment",description:`Variable '${A}' was ${Q.value} in step ${Q.step}, now ${B.value}`,subject:A,original_step:Q.step,original_value:Q.value,conflicting_step:B.step,conflicting_value:B.value,confidence:0.9}}if(A.startsWith("logical:")){if(T_[Q.value]?.includes(B.value))return{type:"logical_conflict",description:`Logical conflict: '${Q.value}' in step ${Q.step} vs '${B.value}' in step ${B.step}`,subject:A.split(":")[2]||"claim",original_step:Q.step,original_value:Q.value,conflicting_step:B.step,conflicting_value:B.value,confidence:0.85}}if(A.startsWith("sign:")){if(k_[Q.value]?.includes(B.value)){let I=A.split(":")[1]||"value";return{type:"sign_flip",description:`Sign flip for '${I}': ${Q.value} → ${B.value}`,subject:I,original_step:Q.step,original_value:Q.value,conflicting_step:B.step,conflicting_value:B.value,confidence:0.8}}}return null}function dcA(A){if(A.length<2)return{has_contradictions:!1,contradictions:[],steps_analyzed:A.length};let Q=[],B=new Map,E=new Map,I=new Map;for(let{step:C,thought:D}of A){let U=lcA(D,C),Y=ccA(D,C),F=pcA(D,C);for(let[g,N]of U){let J=B.get(g);if(J&&J.step!==C){let G=icA(g,J,N);if(G)Q.push(G)}B.set(g,N)}for(let[g,N]of Y){let J=T_[N.value];if(J)for(let G of J){let M=E.get(G);if(M&&M.step!==C)Q.push({type:"logical_conflict",description:`Logical conflict: '${M.value}' in step ${M.step} vs '${N.value}' in step ${C}`,subject:"claim",original_step:M.step,original_value:M.value,conflicting_step:C,conflicting_value:N.value,confidence:0.85})}E.set(N.value,N)}for(let[g,N]of F){let J=k_[N.value];if(J)for(let G of J){let M=I.get(G);if(M&&M.step!==C){let X=N.context.match(/^([^:]+):/)?.[1]??"value";Q.push({type:"sign_flip",description:`Sign flip for '${X}': ${M.value} → ${N.value}`,subject:X,original_step:M.step,original_value:M.value,conflicting_step:C,conflicting_value:N.value,confidence:0.8})}}I.set(N.value,N)}}return{has_contradictions:Q.length>0,contradictions:Q,steps_analyzed:A.length}}function qYA(A,Q){return dcA([...Q,A]).contradictions.filter((E)=>E.conflicting_step===A.step)}function C8(A){if(/\d+\s*[+\-*/^=]\s*\d+|equation|solve|derivative|integral|sum\s+of/i.test(A))return"math";if(/function|class|return|const|let|var|def\s|import\s|async|await|=>|->|fn\s|impl\s/i.test(A))return"code";if(/if\s+.+\s+then|therefore|implies|hence|thus|conclude|premise|valid|invalid/i.test(A))return"logic";return"general"}var ncA=[/\b(?:therefore|thus|hence|consequently)\b.*\b(?:true|correct|valid|proven|confirmed)\b/i,/\b(?:this\s+)?(?:confirms?|proves?|shows?|demonstrates?)\s+(?:that\s+)?(?:the\s+)?hypothesis\b/i,/\b(?:QED|Q\.E\.D\.|quod\s+erat\s+demonstrandum)\b/i,/\b(?:we\s+have\s+shown|we\s+conclude|this\s+establishes)\b/i,/\bhypothesis\s+(?:is\s+)?(?:true|correct|valid|confirmed)\b/i,/\bas\s+(?:we\s+)?(?:hypothesized|expected|predicted)\b/i,/\bsuccess(?:fully)?\s+(?:verified|confirmed|proven)\b/i],ocA=[/\b(?:contradiction|contradicts?|inconsistent)\b/i,/\b(?:impossible|cannot\s+be|can't\s+be)\b/i,/\b(?:disprove[ds]?|refute[ds]?|falsif(?:y|ied))\b/i,/\bhypothesis\s+(?:is\s+)?(?:false|incorrect|invalid|wrong|fails?)\b/i,/\b(?:this\s+)?(?:fails?|violates?|breaks?)\s+(?:the\s+)?(?:assumption|hypothesis)\b/i,/\b(?:counterexample|counter-example)\b/i,/\bnot\s+(?:true|valid|correct|possible)\b/i,/\b(?:rejected?|abandon|discard)\s+(?:the\s+)?hypothesis\b/i],rcA=[/\b(?:inconclusive|undetermined|unclear|uncertain)\b/i,/\b(?:need|require)s?\s+(?:more|further|additional)\s+(?:evidence|proof|analysis)\b/i,/\b(?:cannot\s+(?:yet\s+)?(?:determine|conclude|decide))\b/i,/\b(?:insufficient\s+(?:evidence|data|information))\b/i];function __(A,Q){for(let B of Q){let E=A.match(B);if(E)return E[0]}return null}function SYA(A,Q){let B=A.toLowerCase(),I=Q.toLowerCase().split(/\s+/).filter((D)=>D.length>3);return I.filter((D)=>B.includes(D)).length>=I.length*0.5}function PYA(A,Q,B,E){let I={resolved:!1,outcome:null,confidence:0,resolved_at_step:null,evidence:null,hypothesis:Q,success_criteria:B,suggestion:"Continue testing the hypothesis."},C=__(A,ocA);if(C)return{...I,resolved:!0,outcome:"refuted",confidence:0.9,resolved_at_step:E,evidence:C,suggestion:"Hypothesis refuted. Consider abandoning this branch or revising the hypothesis."};let D=__(A,rcA);if(D)return{...I,resolved:!0,outcome:"inconclusive",confidence:0.7,resolved_at_step:E,evidence:D,suggestion:"Hypothesis inconclusive. Gather more evidence or reformulate."};let U=__(A,ncA);if(U){let Y=0.85;if(B&&SYA(A,B))Y=0.95;return{...I,resolved:!0,outcome:"confirmed",confidence:Y,resolved_at_step:E,evidence:U,suggestion:"Hypothesis confirmed. Consider merging findings back to main branch."}}if(B&&SYA(A,B))return{...I,resolved:!1,outcome:null,confidence:0.6,evidence:"Success criteria keywords detected",suggestion:"Success criteria may be satisfied. Verify and explicitly confirm or refute."};return I}var $YA=wA.object({operation:wA.enum(["step","navigate","branch","revise","complete","augment","override","hint","mistakes","spot_check","challenge"]).describe("Operation to perform"),confidence_threshold:wA.number().min(0).max(1).default(0.8).describe("Chain confidence threshold to suggest completion"),token_budget:wA.number().int().min(100).default(3000).describe("Max tokens before auto-compressing new steps"),warn_at_tokens:wA.number().int().min(100).optional().describe("Warn when cumulative session tokens exceed this threshold (soft limit, cost control)"),hard_limit_tokens:wA.number().int().min(100).optional().describe("Hard stop when cumulative session tokens exceed this threshold. Returns budget_exhausted status and blocks further operations."),thought:wA.string().optional().describe("Current reasoning/analysis (step/branch/revise)"),purpose:wA.enum(["analysis","action","reflection","decision","summary","validation","exploration","hypothesis","correction","planning"]).optional().describe("Step category"),outcome:wA.string().optional().describe("Result or conclusion from this step"),confidence:wA.number().min(0).max(1).optional().describe("Confidence in this step (0-1). Contributes to chain average."),context:wA.string().optional().describe("Prior context or findings"),verify:wA.boolean().optional().describe("Run domain verification. Auto-enabled for chains >3 steps. Set to false to disable."),domain:wA.enum(["math","logic","code","general"]).optional(),local_compute:wA.boolean().default(!1).describe("Try local compute for math"),augment_compute:wA.boolean().default(!0).describe("Auto-inject computed values into thought (default: true)"),compress:wA.boolean().default(!0).describe("Compress thought before storing"),compression_query:wA.string().optional().describe("Query for context-aware compression"),max_step_tokens:wA.number().int().min(10).optional().describe("Max tokens for this step. Rejects if exceeded (default: no limit)"),force_large:wA.boolean().default(!1).describe("Allow step even if it exceeds max_step_tokens"),preconditions:wA.array(wA.string()).optional().describe("Assumptions that MUST be true for this step (e.g., 'x > 0', 'file exists')"),view:wA.enum(["history","branches","step","path"]).optional().describe("What to view: history (all steps), branches (list), step (specific), path (lineage)"),step_id:wA.number().int().min(1).optional().describe("Step number to view"),branch_id:wA.string().optional().describe("Filter history by branch"),limit:wA.number().int().min(1).max(50).default(10).describe("Max steps to return"),from_step:wA.number().int().min(1).optional().describe("Step to branch from (default: current)"),branch_name:wA.string().optional().describe("Human-readable branch name"),hypothesis:wA.string().optional().describe("Falsifiable hypothesis this branch will test (e.g., 'Assume X is prime')"),success_criteria:wA.string().optional().describe("What observation proves/disproves this hypothesis"),target_step:wA.number().int().min(1).optional().describe("Step number to revise"),reason:wA.string().optional().describe("Why revising this step / Why overriding verification"),summary:wA.string().optional().describe("Final summary/conclusion"),final_answer:wA.string().optional().describe("The answer/result"),question:wA.string().optional().describe("Original question. On step: enables trap priming and stores for auto spot-check. On complete: enables spot-check."),text:wA.string().optional().describe("Text containing math expressions to compute and inject (augment/mistakes)"),system_context:wA.string().optional().describe("System prompt context for domain filtering"),store_as_step:wA.boolean().default(!1).describe("Store augmented result as a reasoning step"),acknowledge:wA.boolean().optional().describe("Confirm you understand verification failed but want to proceed"),failed_step:wA.number().int().min(1).optional().describe("Step number that failed verification"),expression:wA.string().optional().describe("Math expression to simplify. Omit to continue from previous hint in session."),reveal_count:wA.number().int().min(1).optional().describe("Number of steps to reveal. Omit to auto-increment when continuing."),cumulative:wA.boolean().default(!0).describe("Show all steps up to reveal_count (true) or just the nth step (false)"),reset:wA.boolean().default(!1).describe("Reset hint state and start from beginning"),answer:wA.string().optional().describe("The proposed answer to check for trap patterns"),challenge_type:wA.enum(["assumption_inversion","edge_case","premise_check","steelman_counter","all"]).optional().describe("Type of challenge to generate (default: all)"),target_claim:wA.string().optional().describe("Specific claim to challenge (optional - if omitted, extracts claims from steps)")});function acA(A){let Q=A.match(/\d+(?:\.\d+)?/g);if(!Q)return[];return Q.map((B)=>parseFloat(B))}function tcA(A){let Q=A.match(/(\d+(?:\.\d+)?)/);if(!Q||Q[1]===void 0)return null;return parseFloat(Q[1])}function scA(A){let Q=new Map;for(let B of A)Q.set(B,(Q.get(B)||0)+1);return Q}function ecA(A){let Q=A.toLowerCase(),B=[],E=0;if(/(?:total|sum|together|cost).*?(?:more|less)\s*than/i.test(Q))E+=0.8,B.push("additive_system");if(/doubles?|triples?|exponential/i.test(Q)&&/half|quarter|fraction|percent/i.test(Q))E+=0.8,B.push("nonlinear_growth");if(/(\d+)\s*(?:machines?|workers?|people|printers?).*?(?:minutes?|hours?|days?|seconds?)/i.test(Q))E+=0.6,B.push("rate_pattern");if(/average\s*speed|speed.*average/i.test(Q)&&/(?:round\s*trip|return|back|there and back)/i.test(Q))E+=0.9,B.push("harmonic_mean");if(/(?:row|consecutive|straight|times)/i.test(Q)&&/(?:probability|chance|likely|odds)/i.test(Q))E+=0.7,B.push("independence");if(/(?:minimum|least|fewest)/i.test(Q)&&/(?:guarantee|ensure|certain|must)/i.test(Q))E+=0.7,B.push("pigeonhole");if(/(?:test|positive|negative)/i.test(Q)&&/(?:1\s*in\s*\d+|rare|uncommon|\d+%\s*(?:of|have))/i.test(Q))E+=0.75,B.push("base_rate");if(/\d+!/i.test(Q)&&/(?:zero|factor|digit)/i.test(Q))E+=0.7,B.push("factorial_counting");if(/clock/i.test(Q)&&/(?:overlap|coincide|same position)/i.test(Q))E+=0.8,B.push("clock_overlap");if(/(?:given|if|knowing|after)/i.test(Q)&&/(?:probability|chance|what.*odds)/i.test(Q))E+=0.6,B.push("conditional_probability");if(/(?:more likely|which.*probable|what.*probability)/i.test(Q)&&/(?:and|both|also)/i.test(Q)&&/(?:bank teller|feminist|active|personality|description)/i.test(Q))E+=0.8,B.push("conjunction_fallacy");if(/(?:door|box|curtain|envelope)/i.test(Q)&&/(?:switch|stay|change|keep)/i.test(Q)&&/(?:reveal|open|show)/i.test(Q))E+=0.85,B.push("monty_hall");if(/(?:estimate|guess|how (?:many|much|long))/i.test(Q)&&/(?:spin|wheel|number|digit|wrote|shown)/i.test(Q))E+=0.6,B.push("anchoring");if(/(?:already|spent|invested|paid|cost)/i.test(Q)&&/(?:should|continue|keep|stop|quit|abandon|walk away)/i.test(Q))E+=0.75,B.push("sunk_cost");if((/(?:save|saved|survive|lives?)/i.test(Q)||/(?:die|death|lost|killed)/i.test(Q))&&/(?:program|option|choice|treatment|plan) [ab]/i.test(Q))E+=0.7,B.push("framing_effect");return{required:E>=0.6,score:Math.min(1,E),categories:B}}function D8(A,Q){let B=acA(A),E=tcA(Q),I=A.toLowerCase(),C=FpA(I,Q)||gpA(I,E,Q)||NpA(I,Q)||JpA(I,Q);if(C)return C;if(E===null||B.length===0)return vYA();return ApA(I,B,E)||QpA(I,B,E)||BpA(I,B,E)||IpA(I,B,E)||EpA(I,E)||CpA(I,B,E)||DpA(I,B,E)||UpA(I,B,E)||YpA(I,E)||vYA()}function vYA(){return{passed:!0,warning:null,hint:null,trapType:null,confidence:0.5}}function aB(A,Q,B,E){return{passed:!1,warning:Q,hint:B,trapType:A,confidence:E}}function ApA(A,Q,B){if(!/(?:total|sum|together|cost).*?(?:more|less)\s*than/i.test(A))return null;if(Q.length<2)return null;let E=[...Q].sort((g,N)=>N-g),I=E[0],C=E[1];if(I===void 0||C===void 0)return null;let D=I-C,U=(I-C)/2,Y=Math.abs(B-D)<0.01||Math.abs(B-D*100)<0.5||Math.abs(B/100-D)<0.01,F=Math.abs(B-U)<0.01||Math.abs(B-U*100)<0.5||Math.abs(B/100-U)<0.01;if(Y&&!F)return aB("additive_system",`Potential trap: ${B} might be (${I} - ${C}) without solving the system`,`This is a system: x + y = ${I}, x - y = ${C}. Solve: y = (${I} - ${C}) / 2 = ${U}`,0.85);return null}function QpA(A,Q,B){if(!/doubles?|triples?/i.test(A))return null;if(!/half|quarter/i.test(A))return null;let E=Q.filter((C)=>C>5&&Number.isInteger(C));if(E.length===0)return null;let I=Math.max(...E);if(Math.abs(B-I/2)<0.5)return aB("nonlinear_growth",`Potential trap: ${B} is ${I}/2, but exponential growth doesn't work linearly`,`If something doubles each period and is full at time ${I}, it was half-full at time ${I-1}`,0.9);return null}function BpA(A,Q,B){if(!/machines?|workers?|people|printers?/i.test(A))return null;if(!/minutes?|hours?|seconds?/i.test(A))return null;let E=scA(Q),I=null;for(let[D,U]of E)if(U>=3){I=D;break}if(I===null)return null;let C=Q.filter((D)=>D!==I&&(E.get(D)??0)>=2);for(let D of C)if(Math.abs(B-D)<0.1)return aB("rate_pattern",`Potential trap: ${B} assumes time scales with quantity`,`If ${I} machines make ${I} widgets in ${I} min, each machine makes 1 widget in ${I} min. More machines = same time, more output.`,0.85);return null}function IpA(A,Q,B){if(!/average\s*speed|speed.*average/i.test(A))return null;if(!/(?:round\s*trip|return|back)/i.test(A))return null;let E=Q.filter((Y)=>Y>0&&Y<200);if(E.length<2)return null;let I=E[0],C=E[1];if(I===void 0||C===void 0||I===C)return null;let D=(I+C)/2,U=2*I*C/(I+C);if(Math.abs(B-D)<0.5&&Math.abs(B-U)>1)return aB("harmonic_mean",`Potential trap: ${B} is the arithmetic mean (${I}+${C})/2`,`For round trips over fixed distance, use harmonic mean: 2×${I}×${C}/(${I}+${C}) = ${U.toFixed(1)}`,0.9);return null}function EpA(A,Q){if(!/coin|dice?|flip|roll/i.test(A))return null;if(!/(?:row|consecutive|straight|times)/i.test(A))return null;if(!/(?:probability|chance|likely)/i.test(A))return null;if(!(Math.abs(Q-50)<2||Math.abs(Q-0.5)<0.02)&&Q>0&&Q<100)return aB("independence","Potential gambler's fallacy: previous outcomes don't affect independent events","Each flip/roll is independent. Past results don't change future probability.",0.8);return null}function CpA(A,Q,B){if(!/(?:minimum|least|fewest)/i.test(A))return null;if(!/(?:guarantee|ensure|certain)/i.test(A))return null;if(!/(?:match|pair|same)/i.test(A))return null;if(B===2)return aB("pigeonhole","Potential trap: 2 items could all be different","Pigeonhole principle: with N categories, you need N+1 items to guarantee a match.",0.85);let E=Math.max(...Q.filter((I)=>I<100));if(B>E&&E>2)return aB("pigeonhole","Potential trap: you don't need majority, just one more than categories",`With ${E} categories (if that's the count), you need at most ${E+1} to guarantee a match.`,0.7);return null}function DpA(A,Q,B){if(!/(?:test|positive|negative)/i.test(A))return null;if(!/(?:probability|chance)/i.test(A))return null;let E=A.match(/1\s*(?:in|out of)\s*(\d+)/i);if(!E||!E[1])return null;let I=parseInt(E[1],10),C=1/I,U=Q.filter((M)=>M>=90&&M<=100)[0];if(U===void 0)return null;let Y=U/100,F=Y,g=1-Y,N=F*C+g*(1-C),J=F*C/N,G=B>1?B:B*100;if(G>80&&J<0.2)return aB("base_rate",`Potential base rate neglect: ${G.toFixed(0)}% ignores the low prevalence (1 in ${I})`,`Apply Bayes: P(disease|positive) ≈ ${(J*100).toFixed(0)}%, not ${(Y*100).toFixed(0)}%`,0.85);return null}function UpA(A,Q,B){if(!/trailing.*zero|zero.*trailing/i.test(A))return null;if(!/\d+!/i.test(A))return null;let E=A.match(/(\d+)!/);if(!E||!E[1])return null;let I=parseInt(E[1],10),C=0,D=5;while(D<=I)C+=Math.floor(I/D),D*=5;let U=Math.floor(I/5),Y=Math.floor(I/10);if(Math.abs(B-U)<0.5&&U!==C)return aB("factorial_counting",`Potential trap: ${B} only counts single factors of 5`,`Count ALL factors of 5: ⌊n/5⌋ + ⌊n/25⌋ + ⌊n/125⌋ + ... = ${C}`,0.85);if(Math.abs(B-Y)<0.5&&Y!==C)return aB("factorial_counting","Potential trap: trailing zeros come from factors of 5 (not 10)",`Since 2s are abundant, count factors of 5: ${C}`,0.8);return null}function YpA(A,Q){if(!/clock/i.test(A))return null;if(!/(?:overlap|coincide)/i.test(A))return null;if(!/(?:how many|times)/i.test(A))return null;if(/12\s*hours?/i.test(A)&&Math.abs(Q-12)<0.5)return aB("clock_overlap","Potential trap: hands overlap 11 times in 12 hours, not 12","The 12:00 overlap is shared. Hands overlap every ~65.45 minutes → 11 times per 12 hours.",0.9);if(/24\s*hours?/i.test(A)&&Math.abs(Q-24)<0.5)return aB("clock_overlap","Potential trap: hands overlap 22 times in 24 hours, not 24","11 overlaps per 12-hour period × 2 = 22 total.",0.9);return null}function FpA(A,Q){if(!/(?:more likely|which.*probable|what.*probability)/i.test(A))return null;let B=Q.toLowerCase();if(!/(?:and|both|as well)/i.test(A))return null;if(/\b[bB]\b/.test(Q)||/(?:and|both|as well)/i.test(B))return aB("conjunction_fallacy","Potential conjunction fallacy: P(A and B) ≤ P(A) always","A conjunction cannot be more probable than either of its parts. The more specific option is LESS likely.",0.85);return null}function gpA(A,Q,B){if(!(/monty\s*hall/i.test(A)||/(?:door|box|curtain)/i.test(A)&&/(?:switch|stay|change|keep)/i.test(A)&&/(?:reveal|open|show|goat)/i.test(A)))return null;let I=B.toLowerCase();if(/(?:probability|chance)/i.test(A)&&Q!==null){if(Math.abs(Q-50)<2||Math.abs(Q-0.5)<0.02)return aB("monty_hall","Potential Monty Hall trap: it's NOT 50/50 after a door is revealed","Switching wins 2/3 of the time, staying wins 1/3. The reveal gives you information.",0.9)}if(/(?:should|better|strategy)/i.test(A)){if(/(?:stay|keep|doesn't matter|50.?50|same|either)/i.test(I))return aB("monty_hall","Potential Monty Hall trap: switching is actually the better strategy","Switching wins 2/3 of the time. The host's reveal changes the odds.",0.85)}return null}function NpA(A,Q){if(!/(?:already|spent|invested|paid|cost)/i.test(A))return null;if(!/(?:should|continue|keep|stop|quit|abandon|walk away|finish)/i.test(A))return null;let B=Q.toLowerCase(),E=/(?:already spent|already invested|can't waste|too much invested|come this far|so much into)/i.test(B)||/(?:continue|keep going|finish).*(?:because|since).*(?:spent|invested|paid)/i.test(B),I=/^(?:yes|continue|keep|finish)/i.test(B.trim())&&!/(?:future value|expected return|profitable going forward|worth it regardless)/i.test(B)||/(?:wasted|thrown away|lost|for nothing)/i.test(B);if(E||I)return aB("sunk_cost","Potential sunk cost fallacy: past investment shouldn't influence future decisions","Sunk costs are gone - focus on whether FUTURE benefits justify FUTURE costs. What's already spent is irrelevant.",0.8);return null}function JpA(A,Q){if(!((/(?:save|saved|survive|lives?)/i.test(A)||/(?:die|death|lost|killed)/i.test(A))&&/(?:program|option|choice|treatment|plan) [ab]/i.test(A)))return null;let E=Q.toLowerCase(),I=/(?:save|saved|survive)/i.test(A)&&!/(?:die|death|killed)/i.test(A),C=/(?:die|death|killed)/i.test(A)&&!/(?:save|saved|survive)/i.test(A);if(I||C){if(!/(?:equivalent|same|framing|mathematically|expected value|doesn't matter)/i.test(E)){if(/\b[ab]\b/i.test(E))return aB("framing_effect","Potential framing effect: check if options are mathematically equivalent","The way choices are presented (lives saved vs lives lost) often triggers different intuitive responses to identical expected outcomes. Calculate expected values to decide rationally.",0.7)}}return null}var TYA={minConfidence:0.7,maxCombined:1,excludeTypes:[]};var GpA={additive_system:"⚠️ System of equations detected. Define variables x,y and solve algebraically.",nonlinear_growth:"⚠️ Exponential growth. Work backwards from the end state, not forwards.",rate_pattern:"⚠️ Rate problem. Calculate rate per unit first, then scale.",harmonic_mean:"⚠️ Round trip speed. Use harmonic mean: 2ab/(a+b), not arithmetic.",independence:"⚠️ Independent events. Past outcomes don't affect future probability.",pigeonhole:"⚠️ Guarantee problem. Consider worst case: need categories + 1.",base_rate:"⚠️ Rare condition + test. Apply Bayes' theorem with base rate.",factorial_counting:"⚠️ Factorial zeros. Count factors of 5: ⌊n/5⌋ + ⌊n/25⌋ + ...",clock_overlap:"⚠️ Clock hands overlap 11 times per 12 hours, not 12.",conditional_probability:"⚠️ Conditional probability. Use P(A|B) = P(A∩B)/P(B).",conjunction_fallacy:"⚠️ Conjunction trap. P(A and B) ≤ P(A) always.",monty_hall:"⚠️ Revealed information changes odds. Switching wins 2/3.",anchoring:"⚠️ Ignore irrelevant numbers. Base estimate on actual data only.",sunk_cost:"⚠️ Sunk cost trap. Past spending is irrelevant to future decisions.",framing_effect:"⚠️ Check framing. Calculate expected values for both options."};function kYA(A,Q){let B=typeof Q==="number"?{...TYA,maxCombined:Q}:{...TYA,...Q},E=ecA(A);if(!E.required||E.categories.length===0)return{shouldPrime:!1,trapTypes:[],primedTypes:[],primingPrompt:null,allPrompts:[],confidence:E.score,skippedReason:"no_traps_detected"};if(E.score<B.minConfidence)return{shouldPrime:!1,trapTypes:E.categories,primedTypes:[],primingPrompt:null,allPrompts:[],confidence:E.score,skippedReason:`confidence_below_threshold:${E.score.toFixed(2)}<${B.minConfidence}`};let I=E.categories.filter((Y)=>!B.excludeTypes.includes(Y));if(I.length===0)return{shouldPrime:!1,trapTypes:E.categories,primedTypes:[],primingPrompt:null,allPrompts:[],confidence:E.score,skippedReason:`all_types_excluded:${E.categories.join(",")}`};let C=I.slice(0,B.maxCombined),D=[];for(let Y of C){let F=GpA[Y];if(F)D.push(F)}if(D.length===0)return{shouldPrime:!1,trapTypes:E.categories,primedTypes:[],primingPrompt:null,allPrompts:[],confidence:E.score,skippedReason:`no_prompts_for_types:${C.join(",")}`};let U=null;if(D.length===1)U=D[0]??null;else if(D.length>1)U=D.map((Y,F)=>`${F+1}. ${Y.replace("⚠️ ","")}`).join(`
346
+ Calculation: ${C.toFixed(2)} × ${V.toFixed(2)} × ${L.toFixed(2)} = ${d.toFixed(3)}`;return{score:d,tier:zA,confidence:{level:r,inGrayZone:O,boundaryDistance:m},explanation:{verb_type:E,verb_score:C,domain_detected:W,domain_weight:V,intensity_signals:w,intensity_modifier:L},reasoning:$.trim()}}var fcA={min_significant_drop:0.15,min_significant_recovery:0.15,unresolved_threshold:0.3,min_steps:3,overconfident_threshold:0.85,overconfident_max_variance:0.05,cliff_drop_threshold:0.3,declining_final_threshold:0.5};function v_(A,Q={}){let B={...fcA,...Q};if(A.length<B.min_steps)return{drift_score:0,unresolved:!1,min_confidence:A[0]?.verification?.confidence??0.5,min_step:A[0]?.step_number??1,max_drop:0,recovery:0,has_revision_after_drop:!1,pattern:"insufficient",explanation:`Insufficient steps for drift analysis (${A.length} < ${B.min_steps})`,suggestion:null};let E=A.map((zA)=>zA.verification?.confidence??0.5),I=A.map((zA)=>zA.step_number),C=E[0],D=0,U=E[0],Y=0,F=0,g=E[0];for(let zA=1;zA<E.length;zA++){let KA=E[zA];if(KA<C)C=KA,D=zA;if(KA>U)U=KA,Y=zA;if(KA>g)g=KA;else{let kA=g-KA;if(kA>F)F=kA}}let N=E[E.length-1],J=N-C,G=A.slice(D+1).some((zA)=>zA.revises_step!==void 0),M=hcA(E,D,Y,F,J,B),H=Math.max(1,E.length-1-D),X;if(M==="v_shaped"){let zA=F,KA=F*J/H;X=Math.max(zA,KA)}else X=F*0.5;let W=Math.min(1,Math.max(0,X)),V=M==="v_shaped",L=M==="stable_overconfident",w=M==="cliff",z=F>=B.min_significant_drop,Z=J>=B.min_significant_recovery,K=V&&z&&Z&&!G&&W>=B.unresolved_threshold,R=E.length>=2?E[E.length-2]-E[E.length-1]:0,j=w&&R>=B.cliff_drop_threshold,q=M==="declining"&&N<B.declining_final_threshold,y=K||L||j||q,t=L||j||q?Math.max(W,0.4):W,u=ucA(M,F,J,D,I,G,C),d=y?mcA(I[D],F,M,C):null;return{drift_score:t,unresolved:y,min_confidence:C,min_step:I[D],max_drop:F,recovery:J,has_revision_after_drop:G,pattern:M,explanation:u,suggestion:d}}function hcA(A,Q,B,E,I,C){let D=A.length,U=Math.max(...A)-Math.min(...A);if(Q>0&&Q<D-1&&E>=C.min_significant_drop&&I>=C.min_significant_recovery)return"v_shaped";if(Q>=D-1&&E>=C.min_significant_drop&&D>=2){let M=A[D-2]-A[D-1],H=0;for(let W=1;W<D-1;W++)H+=Math.abs(A[W]-A[W-1]);let X=D>2?H/(D-2):0;if(M>=C.min_significant_drop&&M>=X*2)return"cliff"}if(Math.min(...A)>=C.overconfident_threshold&&U<=C.overconfident_max_variance)return"stable_overconfident";if(U<0.1)return"stable";let g=0;for(let M=1;M<D;M++)if(A[M]<A[M-1])g++;if(g>=(D-1)*0.7)return"declining";let N=0;for(let M=1;M<D;M++)if(A[M]>A[M-1])N++;if(N>=(D-1)*0.7)return"improving";let J=0,G=0;for(let M=1;M<D;M++){let H=Math.sign(A[M]-A[M-1]);if(H!==0&&H!==G)J++,G=H}if(J>=3)return"oscillating";return"stable"}function ucA(A,Q,B,E,I,C,D){let U=(Q*100).toFixed(0),Y=(B*100).toFixed(0),F=I[E];switch(A){case"stable":return"Confidence remained stable throughout reasoning chain.";case"stable_overconfident":return`⚠️ Stable high confidence (≥${((D??0.85)*100).toFixed(0)}%) throughout chain. On complex/trap questions, consistent high confidence without doubt often correlates with incorrect answers.`;case"declining":if(D!==void 0&&D<0.5)return`⚠️ Confidence declined steadily to ${(D*100).toFixed(0)}% (${U}% total drop). Ending with low confidence suggests unresolved uncertainty.`;return`Confidence declined steadily (${U}% total drop). This may indicate increasing uncertainty or problem difficulty.`;case"improving":return`Confidence improved throughout reasoning (${Y}% increase). Good progressive understanding.`;case"v_shaped":if(C)return`V-shaped confidence pattern detected: ${U}% drop at step ${F}, then ${Y}% recovery. Revision step present - uncertainty was addressed.`;else return`⚠️ V-shaped confidence pattern: ${U}% drop at step ${F}, then ${Y}% recovery WITHOUT revision. The reasoning may have "pushed through" uncertainty without addressing it.`;case"oscillating":return"Confidence oscillated throughout reasoning. Multiple uncertainty points encountered.";case"cliff":return`Confidence dropped sharply at the end (${U}% drop). Possible error or contradiction detected late in reasoning.`;case"insufficient":return"Not enough steps for meaningful drift analysis.";default:return"Confidence pattern analyzed."}}function mcA(A,Q,B,E){if(B==="stable_overconfident")return`High confidence (${((E??0.85)*100).toFixed(0)}%+) throughout suggests possible overconfidence. Consider: Is this a trick question? Have you verified assumptions? Adding a self-check step could help catch errors.`;if(B==="cliff")return`Sharp confidence drop (${(Q*100).toFixed(0)}%) at the final step suggests an error or contradiction was detected late. Consider: What caused this doubt? Should you revise earlier steps before concluding?`;if(B==="declining")return`Confidence declined to ${((E??0.5)*100).toFixed(0)}% by the end. The reasoning chain ended with significant doubt. Consider: What's causing the uncertainty? Is the approach valid? Should you try a different method?`;if(Q>=0.3)return`Consider revising from step ${A} where confidence dropped significantly. The recovery without explicit revision suggests the uncertainty was not properly addressed.`;else return`Review step ${A} where confidence was lowest. Adding explicit reasoning about why confidence recovered could strengthen the chain.`}var jYA=/(?:let\s+)?([a-zA-Z_][a-zA-Z0-9_]*)\s*[:=]=?\s*(-?\d+(?:\.\d+)?)/g,T_={always:["never","sometimes","rarely"],never:["always","sometimes","often"],all:["none","some","few"],none:["all","some","many"],every:["no","some","few"],must:["cannot","might","may not"],cannot:["must","can","might"],true:["false"],false:["true"],impossible:["possible","certain","likely"],certain:["impossible","uncertain","unlikely"]},k_={positive:["negative","zero"],negative:["positive","zero"],increasing:["decreasing","constant"],decreasing:["increasing","constant"],greater:["less","equal"],less:["greater","equal"],above:["below","at"],below:["above","at"]};function lcA(A,Q){let B=new Map,E;jYA.lastIndex=0;while((E=jYA.exec(A))!==null){let I=E[1]?.toLowerCase(),C=E[2];if(!I||!C)continue;let D=Math.max(0,E.index-20),U=Math.min(A.length,E.index+E[0].length+20),Y=A.slice(D,U);B.set(I,{step:Q,value:C,context:Y})}return B}function ccA(A,Q){let B=new Map,E=A.toLowerCase();for(let[I,C]of Object.entries(T_))if(new RegExp(`\\b${I}\\b`,"gi").test(E)){let U=E.indexOf(I),Y=Math.max(0,U-30),F=Math.min(A.length,U+I.length+30),g=A.slice(Y,F),N=`logical:${I}`;B.set(N,{step:Q,value:I,context:g})}return B}function pcA(A,Q){let B=new Map,E=A.toLowerCase();for(let[I,C]of Object.entries(k_))if(new RegExp(`\\b${I}\\b`,"gi").test(E)){let U=E.indexOf(I),Y=Math.max(0,U-30),F=Math.min(A.length,U+I.length+30),g=A.slice(Y,F),N=g.match(/\b(the\s+)?([a-zA-Z_][a-zA-Z0-9_]*)\b/i),J=N?N[2]||"value":"value",G=`sign:${I}`;B.set(G,{step:Q,value:I,context:`${J}: ${g}`})}return B}function icA(A,Q,B){if(A.match(/^[a-z_][a-z0-9_]*$/i)){if(Q.value!==B.value)return{type:"value_reassignment",description:`Variable '${A}' was ${Q.value} in step ${Q.step}, now ${B.value}`,subject:A,original_step:Q.step,original_value:Q.value,conflicting_step:B.step,conflicting_value:B.value,confidence:0.9}}if(A.startsWith("logical:")){if(T_[Q.value]?.includes(B.value))return{type:"logical_conflict",description:`Logical conflict: '${Q.value}' in step ${Q.step} vs '${B.value}' in step ${B.step}`,subject:A.split(":")[2]||"claim",original_step:Q.step,original_value:Q.value,conflicting_step:B.step,conflicting_value:B.value,confidence:0.85}}if(A.startsWith("sign:")){if(k_[Q.value]?.includes(B.value)){let I=A.split(":")[1]||"value";return{type:"sign_flip",description:`Sign flip for '${I}': ${Q.value} → ${B.value}`,subject:I,original_step:Q.step,original_value:Q.value,conflicting_step:B.step,conflicting_value:B.value,confidence:0.8}}}return null}function dcA(A){if(A.length<2)return{has_contradictions:!1,contradictions:[],steps_analyzed:A.length};let Q=[],B=new Map,E=new Map,I=new Map;for(let{step:C,thought:D}of A){let U=lcA(D,C),Y=ccA(D,C),F=pcA(D,C);for(let[g,N]of U){let J=B.get(g);if(J&&J.step!==C){let G=icA(g,J,N);if(G)Q.push(G)}B.set(g,N)}for(let[g,N]of Y){let J=T_[N.value];if(J)for(let G of J){let M=E.get(G);if(M&&M.step!==C)Q.push({type:"logical_conflict",description:`Logical conflict: '${M.value}' in step ${M.step} vs '${N.value}' in step ${C}`,subject:"claim",original_step:M.step,original_value:M.value,conflicting_step:C,conflicting_value:N.value,confidence:0.85})}E.set(N.value,N)}for(let[g,N]of F){let J=k_[N.value];if(J)for(let G of J){let M=I.get(G);if(M&&M.step!==C){let X=N.context.match(/^([^:]+):/)?.[1]??"value";Q.push({type:"sign_flip",description:`Sign flip for '${X}': ${M.value} → ${N.value}`,subject:X,original_step:M.step,original_value:M.value,conflicting_step:C,conflicting_value:N.value,confidence:0.8})}}I.set(N.value,N)}}return{has_contradictions:Q.length>0,contradictions:Q,steps_analyzed:A.length}}function qYA(A,Q){return dcA([...Q,A]).contradictions.filter((E)=>E.conflicting_step===A.step)}function C8(A){if(/\d+\s*[+\-*/^=]\s*\d+|equation|solve|derivative|integral|sum\s+of/i.test(A))return"math";if(/function|class|return|const|let|var|def\s|import\s|async|await|=>|->|fn\s|impl\s/i.test(A))return"code";if(/if\s+.+\s+then|therefore|implies|hence|thus|conclude|premise|valid|invalid/i.test(A))return"logic";return"general"}var ncA=[/\b(?:therefore|thus|hence|consequently)\b.*\b(?:true|correct|valid|proven|confirmed)\b/i,/\b(?:this\s+)?(?:confirms?|proves?|shows?|demonstrates?)\s+(?:that\s+)?(?:the\s+)?hypothesis\b/i,/\b(?:QED|Q\.E\.D\.|quod\s+erat\s+demonstrandum)\b/i,/\b(?:we\s+have\s+shown|we\s+conclude|this\s+establishes)\b/i,/\bhypothesis\s+(?:is\s+)?(?:true|correct|valid|confirmed)\b/i,/\bas\s+(?:we\s+)?(?:hypothesized|expected|predicted)\b/i,/\bsuccess(?:fully)?\s+(?:verified|confirmed|proven)\b/i],ocA=[/\b(?:contradiction|contradicts?|inconsistent)\b/i,/\b(?:impossible|cannot\s+be|can't\s+be)\b/i,/\b(?:disprove[ds]?|refute[ds]?|falsif(?:y|ied))\b/i,/\bhypothesis\s+(?:is\s+)?(?:false|incorrect|invalid|wrong|fails?)\b/i,/\b(?:this\s+)?(?:fails?|violates?|breaks?)\s+(?:the\s+)?(?:assumption|hypothesis)\b/i,/\b(?:counterexample|counter-example)\b/i,/\bnot\s+(?:true|valid|correct|possible)\b/i,/\b(?:rejected?|abandon|discard)\s+(?:the\s+)?hypothesis\b/i],rcA=[/\b(?:inconclusive|undetermined|unclear|uncertain)\b/i,/\b(?:need|require)s?\s+(?:more|further|additional)\s+(?:evidence|proof|analysis)\b/i,/\b(?:cannot\s+(?:yet\s+)?(?:determine|conclude|decide))\b/i,/\b(?:insufficient\s+(?:evidence|data|information))\b/i];function __(A,Q){for(let B of Q){let E=A.match(B);if(E)return E[0]}return null}function SYA(A,Q){let B=A.toLowerCase(),I=Q.toLowerCase().split(/\s+/).filter((D)=>D.length>3);return I.filter((D)=>B.includes(D)).length>=I.length*0.5}function PYA(A,Q,B,E){let I={resolved:!1,outcome:null,confidence:0,resolved_at_step:null,evidence:null,hypothesis:Q,success_criteria:B,suggestion:"Continue testing the hypothesis."},C=__(A,ocA);if(C)return{...I,resolved:!0,outcome:"refuted",confidence:0.9,resolved_at_step:E,evidence:C,suggestion:"Hypothesis refuted. Consider abandoning this branch or revising the hypothesis."};let D=__(A,rcA);if(D)return{...I,resolved:!0,outcome:"inconclusive",confidence:0.7,resolved_at_step:E,evidence:D,suggestion:"Hypothesis inconclusive. Gather more evidence or reformulate."};let U=__(A,ncA);if(U){let Y=0.85;if(B&&SYA(A,B))Y=0.95;return{...I,resolved:!0,outcome:"confirmed",confidence:Y,resolved_at_step:E,evidence:U,suggestion:"Hypothesis confirmed. Consider merging findings back to main branch."}}if(B&&SYA(A,B))return{...I,resolved:!1,outcome:null,confidence:0.6,evidence:"Success criteria keywords detected",suggestion:"Success criteria may be satisfied. Verify and explicitly confirm or refute."};return I}var $YA=wA.object({operation:wA.enum(["step","navigate","branch","revise","complete","augment","override","hint","mistakes","spot_check","challenge"]).describe("Operation to perform"),confidence_threshold:wA.number().min(0).max(1).optional().describe("Chain confidence threshold to suggest completion (default: 0.8)"),token_budget:wA.number().int().min(100).optional().describe("Max tokens before auto-compressing new steps (default: 3000)"),warn_at_tokens:wA.number().int().min(100).optional().describe("Warn when cumulative session tokens exceed this threshold (soft limit, cost control)"),hard_limit_tokens:wA.number().int().min(100).optional().describe("Hard stop when cumulative session tokens exceed this threshold. Returns budget_exhausted status and blocks further operations."),thought:wA.string().optional().describe("Current reasoning/analysis (step/branch/revise)"),purpose:wA.enum(["analysis","action","reflection","decision","summary","validation","exploration","hypothesis","correction","planning"]).optional().describe("Step category"),outcome:wA.string().optional().describe("Result or conclusion from this step"),confidence:wA.number().min(0).max(1).optional().describe("Confidence in this step (0-1). Contributes to chain average."),context:wA.string().optional().describe("Prior context or findings"),verify:wA.boolean().optional().describe("Run domain verification. Auto-enabled for chains >3 steps. Set to false to disable."),domain:wA.enum(["math","logic","code","general"]).optional(),local_compute:wA.boolean().optional().describe("Try local compute for math (default: false)"),augment_compute:wA.boolean().optional().describe("Auto-inject computed values into thought (default: true)"),compress:wA.boolean().optional().describe("Compress thought before storing (default: true)"),compression_query:wA.string().optional().describe("Query for context-aware compression"),max_step_tokens:wA.number().int().min(10).optional().describe("Max tokens for this step. Rejects if exceeded (default: no limit)"),force_large:wA.boolean().optional().describe("Allow step even if it exceeds max_step_tokens (default: false)"),preconditions:wA.array(wA.string()).optional().describe("Assumptions that MUST be true for this step (e.g., 'x > 0', 'file exists')"),view:wA.enum(["history","branches","step","path"]).optional().describe("What to view: history (all steps), branches (list), step (specific), path (lineage)"),step_id:wA.number().int().min(1).optional().describe("Step number to view"),branch_id:wA.string().optional().describe("Filter history by branch"),limit:wA.number().int().min(1).max(50).optional().describe("Max steps to return (default: 10)"),from_step:wA.number().int().min(1).optional().describe("Step to branch from (default: current)"),branch_name:wA.string().optional().describe("Human-readable branch name"),hypothesis:wA.string().optional().describe("Falsifiable hypothesis this branch will test (e.g., 'Assume X is prime')"),success_criteria:wA.string().optional().describe("What observation proves/disproves this hypothesis"),target_step:wA.number().int().min(1).optional().describe("Step number to revise"),reason:wA.string().optional().describe("Why revising this step / Why overriding verification"),summary:wA.string().optional().describe("Final summary/conclusion"),final_answer:wA.string().optional().describe("The answer/result"),question:wA.string().optional().describe("Original question. On step: enables trap priming and stores for auto spot-check. On complete: enables spot-check."),text:wA.string().optional().describe("Text containing math expressions to compute and inject (augment/mistakes)"),system_context:wA.string().optional().describe("System prompt context for domain filtering"),store_as_step:wA.boolean().optional().describe("Store augmented result as a reasoning step (default: false)"),acknowledge:wA.boolean().optional().describe("Confirm you understand verification failed but want to proceed"),failed_step:wA.number().int().min(1).optional().describe("Step number that failed verification"),expression:wA.string().optional().describe("Math expression to simplify. Omit to continue from previous hint in session."),reveal_count:wA.number().int().min(1).optional().describe("Number of steps to reveal. Omit to auto-increment when continuing."),cumulative:wA.boolean().optional().describe("Show all steps up to reveal_count (true) or just the nth step (false). Default: true"),reset:wA.boolean().optional().describe("Reset hint state and start from beginning (default: false)"),answer:wA.string().optional().describe("The proposed answer to check for trap patterns"),challenge_type:wA.enum(["assumption_inversion","edge_case","premise_check","steelman_counter","all"]).optional().describe("Type of challenge to generate (default: all)"),target_claim:wA.string().optional().describe("Specific claim to challenge (optional - if omitted, extracts claims from steps)")});function acA(A){let Q=A.match(/\d+(?:\.\d+)?/g);if(!Q)return[];return Q.map((B)=>parseFloat(B))}function tcA(A){let Q=A.match(/(\d+(?:\.\d+)?)/);if(!Q||Q[1]===void 0)return null;return parseFloat(Q[1])}function scA(A){let Q=new Map;for(let B of A)Q.set(B,(Q.get(B)||0)+1);return Q}function ecA(A){let Q=A.toLowerCase(),B=[],E=0;if(/(?:total|sum|together|cost).*?(?:more|less)\s*than/i.test(Q))E+=0.8,B.push("additive_system");if(/doubles?|triples?|exponential/i.test(Q)&&/half|quarter|fraction|percent/i.test(Q))E+=0.8,B.push("nonlinear_growth");if(/(\d+)\s*(?:machines?|workers?|people|printers?).*?(?:minutes?|hours?|days?|seconds?)/i.test(Q))E+=0.6,B.push("rate_pattern");if(/average\s*speed|speed.*average/i.test(Q)&&/(?:round\s*trip|return|back|there and back)/i.test(Q))E+=0.9,B.push("harmonic_mean");if(/(?:row|consecutive|straight|times)/i.test(Q)&&/(?:probability|chance|likely|odds)/i.test(Q))E+=0.7,B.push("independence");if(/(?:minimum|least|fewest)/i.test(Q)&&/(?:guarantee|ensure|certain|must)/i.test(Q))E+=0.7,B.push("pigeonhole");if(/(?:test|positive|negative)/i.test(Q)&&/(?:1\s*in\s*\d+|rare|uncommon|\d+%\s*(?:of|have))/i.test(Q))E+=0.75,B.push("base_rate");if(/\d+!/i.test(Q)&&/(?:zero|factor|digit)/i.test(Q))E+=0.7,B.push("factorial_counting");if(/clock/i.test(Q)&&/(?:overlap|coincide|same position)/i.test(Q))E+=0.8,B.push("clock_overlap");if(/(?:given|if|knowing|after)/i.test(Q)&&/(?:probability|chance|what.*odds)/i.test(Q))E+=0.6,B.push("conditional_probability");if(/(?:more likely|which.*probable|what.*probability)/i.test(Q)&&/(?:and|both|also)/i.test(Q)&&/(?:bank teller|feminist|active|personality|description)/i.test(Q))E+=0.8,B.push("conjunction_fallacy");if(/(?:door|box|curtain|envelope)/i.test(Q)&&/(?:switch|stay|change|keep)/i.test(Q)&&/(?:reveal|open|show)/i.test(Q))E+=0.85,B.push("monty_hall");if(/(?:estimate|guess|how (?:many|much|long))/i.test(Q)&&/(?:spin|wheel|number|digit|wrote|shown)/i.test(Q))E+=0.6,B.push("anchoring");if(/(?:already|spent|invested|paid|cost)/i.test(Q)&&/(?:should|continue|keep|stop|quit|abandon|walk away)/i.test(Q))E+=0.75,B.push("sunk_cost");if((/(?:save|saved|survive|lives?)/i.test(Q)||/(?:die|death|lost|killed)/i.test(Q))&&/(?:program|option|choice|treatment|plan) [ab]/i.test(Q))E+=0.7,B.push("framing_effect");return{required:E>=0.6,score:Math.min(1,E),categories:B}}function D8(A,Q){let B=acA(A),E=tcA(Q),I=A.toLowerCase(),C=FpA(I,Q)||gpA(I,E,Q)||NpA(I,Q)||JpA(I,Q);if(C)return C;if(E===null||B.length===0)return vYA();return ApA(I,B,E)||QpA(I,B,E)||BpA(I,B,E)||IpA(I,B,E)||EpA(I,E)||CpA(I,B,E)||DpA(I,B,E)||UpA(I,B,E)||YpA(I,E)||vYA()}function vYA(){return{passed:!0,warning:null,hint:null,trapType:null,confidence:0.5}}function aB(A,Q,B,E){return{passed:!1,warning:Q,hint:B,trapType:A,confidence:E}}function ApA(A,Q,B){if(!/(?:total|sum|together|cost).*?(?:more|less)\s*than/i.test(A))return null;if(Q.length<2)return null;let E=[...Q].sort((g,N)=>N-g),I=E[0],C=E[1];if(I===void 0||C===void 0)return null;let D=I-C,U=(I-C)/2,Y=Math.abs(B-D)<0.01||Math.abs(B-D*100)<0.5||Math.abs(B/100-D)<0.01,F=Math.abs(B-U)<0.01||Math.abs(B-U*100)<0.5||Math.abs(B/100-U)<0.01;if(Y&&!F)return aB("additive_system",`Potential trap: ${B} might be (${I} - ${C}) without solving the system`,`This is a system: x + y = ${I}, x - y = ${C}. Solve: y = (${I} - ${C}) / 2 = ${U}`,0.85);return null}function QpA(A,Q,B){if(!/doubles?|triples?/i.test(A))return null;if(!/half|quarter/i.test(A))return null;let E=Q.filter((C)=>C>5&&Number.isInteger(C));if(E.length===0)return null;let I=Math.max(...E);if(Math.abs(B-I/2)<0.5)return aB("nonlinear_growth",`Potential trap: ${B} is ${I}/2, but exponential growth doesn't work linearly`,`If something doubles each period and is full at time ${I}, it was half-full at time ${I-1}`,0.9);return null}function BpA(A,Q,B){if(!/machines?|workers?|people|printers?/i.test(A))return null;if(!/minutes?|hours?|seconds?/i.test(A))return null;let E=scA(Q),I=null;for(let[D,U]of E)if(U>=3){I=D;break}if(I===null)return null;let C=Q.filter((D)=>D!==I&&(E.get(D)??0)>=2);for(let D of C)if(Math.abs(B-D)<0.1)return aB("rate_pattern",`Potential trap: ${B} assumes time scales with quantity`,`If ${I} machines make ${I} widgets in ${I} min, each machine makes 1 widget in ${I} min. More machines = same time, more output.`,0.85);return null}function IpA(A,Q,B){if(!/average\s*speed|speed.*average/i.test(A))return null;if(!/(?:round\s*trip|return|back)/i.test(A))return null;let E=Q.filter((Y)=>Y>0&&Y<200);if(E.length<2)return null;let I=E[0],C=E[1];if(I===void 0||C===void 0||I===C)return null;let D=(I+C)/2,U=2*I*C/(I+C);if(Math.abs(B-D)<0.5&&Math.abs(B-U)>1)return aB("harmonic_mean",`Potential trap: ${B} is the arithmetic mean (${I}+${C})/2`,`For round trips over fixed distance, use harmonic mean: 2×${I}×${C}/(${I}+${C}) = ${U.toFixed(1)}`,0.9);return null}function EpA(A,Q){if(!/coin|dice?|flip|roll/i.test(A))return null;if(!/(?:row|consecutive|straight|times)/i.test(A))return null;if(!/(?:probability|chance|likely)/i.test(A))return null;if(!(Math.abs(Q-50)<2||Math.abs(Q-0.5)<0.02)&&Q>0&&Q<100)return aB("independence","Potential gambler's fallacy: previous outcomes don't affect independent events","Each flip/roll is independent. Past results don't change future probability.",0.8);return null}function CpA(A,Q,B){if(!/(?:minimum|least|fewest)/i.test(A))return null;if(!/(?:guarantee|ensure|certain)/i.test(A))return null;if(!/(?:match|pair|same)/i.test(A))return null;if(B===2)return aB("pigeonhole","Potential trap: 2 items could all be different","Pigeonhole principle: with N categories, you need N+1 items to guarantee a match.",0.85);let E=Math.max(...Q.filter((I)=>I<100));if(B>E&&E>2)return aB("pigeonhole","Potential trap: you don't need majority, just one more than categories",`With ${E} categories (if that's the count), you need at most ${E+1} to guarantee a match.`,0.7);return null}function DpA(A,Q,B){if(!/(?:test|positive|negative)/i.test(A))return null;if(!/(?:probability|chance)/i.test(A))return null;let E=A.match(/1\s*(?:in|out of)\s*(\d+)/i);if(!E||!E[1])return null;let I=parseInt(E[1],10),C=1/I,U=Q.filter((M)=>M>=90&&M<=100)[0];if(U===void 0)return null;let Y=U/100,F=Y,g=1-Y,N=F*C+g*(1-C),J=F*C/N,G=B>1?B:B*100;if(G>80&&J<0.2)return aB("base_rate",`Potential base rate neglect: ${G.toFixed(0)}% ignores the low prevalence (1 in ${I})`,`Apply Bayes: P(disease|positive) ≈ ${(J*100).toFixed(0)}%, not ${(Y*100).toFixed(0)}%`,0.85);return null}function UpA(A,Q,B){if(!/trailing.*zero|zero.*trailing/i.test(A))return null;if(!/\d+!/i.test(A))return null;let E=A.match(/(\d+)!/);if(!E||!E[1])return null;let I=parseInt(E[1],10),C=0,D=5;while(D<=I)C+=Math.floor(I/D),D*=5;let U=Math.floor(I/5),Y=Math.floor(I/10);if(Math.abs(B-U)<0.5&&U!==C)return aB("factorial_counting",`Potential trap: ${B} only counts single factors of 5`,`Count ALL factors of 5: ⌊n/5⌋ + ⌊n/25⌋ + ⌊n/125⌋ + ... = ${C}`,0.85);if(Math.abs(B-Y)<0.5&&Y!==C)return aB("factorial_counting","Potential trap: trailing zeros come from factors of 5 (not 10)",`Since 2s are abundant, count factors of 5: ${C}`,0.8);return null}function YpA(A,Q){if(!/clock/i.test(A))return null;if(!/(?:overlap|coincide)/i.test(A))return null;if(!/(?:how many|times)/i.test(A))return null;if(/12\s*hours?/i.test(A)&&Math.abs(Q-12)<0.5)return aB("clock_overlap","Potential trap: hands overlap 11 times in 12 hours, not 12","The 12:00 overlap is shared. Hands overlap every ~65.45 minutes → 11 times per 12 hours.",0.9);if(/24\s*hours?/i.test(A)&&Math.abs(Q-24)<0.5)return aB("clock_overlap","Potential trap: hands overlap 22 times in 24 hours, not 24","11 overlaps per 12-hour period × 2 = 22 total.",0.9);return null}function FpA(A,Q){if(!/(?:more likely|which.*probable|what.*probability)/i.test(A))return null;let B=Q.toLowerCase();if(!/(?:and|both|as well)/i.test(A))return null;if(/\b[bB]\b/.test(Q)||/(?:and|both|as well)/i.test(B))return aB("conjunction_fallacy","Potential conjunction fallacy: P(A and B) ≤ P(A) always","A conjunction cannot be more probable than either of its parts. The more specific option is LESS likely.",0.85);return null}function gpA(A,Q,B){if(!(/monty\s*hall/i.test(A)||/(?:door|box|curtain)/i.test(A)&&/(?:switch|stay|change|keep)/i.test(A)&&/(?:reveal|open|show|goat)/i.test(A)))return null;let I=B.toLowerCase();if(/(?:probability|chance)/i.test(A)&&Q!==null){if(Math.abs(Q-50)<2||Math.abs(Q-0.5)<0.02)return aB("monty_hall","Potential Monty Hall trap: it's NOT 50/50 after a door is revealed","Switching wins 2/3 of the time, staying wins 1/3. The reveal gives you information.",0.9)}if(/(?:should|better|strategy)/i.test(A)){if(/(?:stay|keep|doesn't matter|50.?50|same|either)/i.test(I))return aB("monty_hall","Potential Monty Hall trap: switching is actually the better strategy","Switching wins 2/3 of the time. The host's reveal changes the odds.",0.85)}return null}function NpA(A,Q){if(!/(?:already|spent|invested|paid|cost)/i.test(A))return null;if(!/(?:should|continue|keep|stop|quit|abandon|walk away|finish)/i.test(A))return null;let B=Q.toLowerCase(),E=/(?:already spent|already invested|can't waste|too much invested|come this far|so much into)/i.test(B)||/(?:continue|keep going|finish).*(?:because|since).*(?:spent|invested|paid)/i.test(B),I=/^(?:yes|continue|keep|finish)/i.test(B.trim())&&!/(?:future value|expected return|profitable going forward|worth it regardless)/i.test(B)||/(?:wasted|thrown away|lost|for nothing)/i.test(B);if(E||I)return aB("sunk_cost","Potential sunk cost fallacy: past investment shouldn't influence future decisions","Sunk costs are gone - focus on whether FUTURE benefits justify FUTURE costs. What's already spent is irrelevant.",0.8);return null}function JpA(A,Q){if(!((/(?:save|saved|survive|lives?)/i.test(A)||/(?:die|death|lost|killed)/i.test(A))&&/(?:program|option|choice|treatment|plan) [ab]/i.test(A)))return null;let E=Q.toLowerCase(),I=/(?:save|saved|survive)/i.test(A)&&!/(?:die|death|killed)/i.test(A),C=/(?:die|death|killed)/i.test(A)&&!/(?:save|saved|survive)/i.test(A);if(I||C){if(!/(?:equivalent|same|framing|mathematically|expected value|doesn't matter)/i.test(E)){if(/\b[ab]\b/i.test(E))return aB("framing_effect","Potential framing effect: check if options are mathematically equivalent","The way choices are presented (lives saved vs lives lost) often triggers different intuitive responses to identical expected outcomes. Calculate expected values to decide rationally.",0.7)}}return null}var TYA={minConfidence:0.7,maxCombined:1,excludeTypes:[]};var GpA={additive_system:"⚠️ System of equations detected. Define variables x,y and solve algebraically.",nonlinear_growth:"⚠️ Exponential growth. Work backwards from the end state, not forwards.",rate_pattern:"⚠️ Rate problem. Calculate rate per unit first, then scale.",harmonic_mean:"⚠️ Round trip speed. Use harmonic mean: 2ab/(a+b), not arithmetic.",independence:"⚠️ Independent events. Past outcomes don't affect future probability.",pigeonhole:"⚠️ Guarantee problem. Consider worst case: need categories + 1.",base_rate:"⚠️ Rare condition + test. Apply Bayes' theorem with base rate.",factorial_counting:"⚠️ Factorial zeros. Count factors of 5: ⌊n/5⌋ + ⌊n/25⌋ + ...",clock_overlap:"⚠️ Clock hands overlap 11 times per 12 hours, not 12.",conditional_probability:"⚠️ Conditional probability. Use P(A|B) = P(A∩B)/P(B).",conjunction_fallacy:"⚠️ Conjunction trap. P(A and B) ≤ P(A) always.",monty_hall:"⚠️ Revealed information changes odds. Switching wins 2/3.",anchoring:"⚠️ Ignore irrelevant numbers. Base estimate on actual data only.",sunk_cost:"⚠️ Sunk cost trap. Past spending is irrelevant to future decisions.",framing_effect:"⚠️ Check framing. Calculate expected values for both options."};function kYA(A,Q){let B=typeof Q==="number"?{...TYA,maxCombined:Q}:{...TYA,...Q},E=ecA(A);if(!E.required||E.categories.length===0)return{shouldPrime:!1,trapTypes:[],primedTypes:[],primingPrompt:null,allPrompts:[],confidence:E.score,skippedReason:"no_traps_detected"};if(E.score<B.minConfidence)return{shouldPrime:!1,trapTypes:E.categories,primedTypes:[],primingPrompt:null,allPrompts:[],confidence:E.score,skippedReason:`confidence_below_threshold:${E.score.toFixed(2)}<${B.minConfidence}`};let I=E.categories.filter((Y)=>!B.excludeTypes.includes(Y));if(I.length===0)return{shouldPrime:!1,trapTypes:E.categories,primedTypes:[],primingPrompt:null,allPrompts:[],confidence:E.score,skippedReason:`all_types_excluded:${E.categories.join(",")}`};let C=I.slice(0,B.maxCombined),D=[];for(let Y of C){let F=GpA[Y];if(F)D.push(F)}if(D.length===0)return{shouldPrime:!1,trapTypes:E.categories,primedTypes:[],primingPrompt:null,allPrompts:[],confidence:E.score,skippedReason:`no_prompts_for_types:${C.join(",")}`};let U=null;if(D.length===1)U=D[0]??null;else if(D.length>1)U=D.map((Y,F)=>`${F+1}. ${Y.replace("⚠️ ","")}`).join(`
347
347
  `);return{shouldPrime:!0,trapTypes:E.categories,primedTypes:C,primingPrompt:U,allPrompts:D,confidence:E.score,skippedReason:null}}var MpA=190,_YA=1e4;function WpA(A){switch(A){case"Low":return 1;case"Moderate":return 2;case"High":return 4;case"Very Hard":return 6;case"Almost Impossible":return 8}}function RD(A,Q,B){let E=WA.getThoughts(A,Q),I=[];for(let D of E)if(D.verification?.confidence!==void 0)I.push(D.verification.confidence);if(B!==void 0)I.push(B);let C=I.length>0?I.reduce((D,U)=>D+U,0)/I.length:0;return{stepConfidence:B,chainConfidence:C,stepsWithConfidence:I.length}}function pg(A,Q,B){if(B)return"complete";if(A>=Q)return"threshold_reached";if(A>=Q*0.8)return"review";return"continue"}function bYA(A,Q){switch(A){case"complete":return"Reasoning chain complete.";case"threshold_reached":return`Confidence ${(Q*100).toFixed(0)}% reached threshold. Consider completing or add one more verification step.`;case"review":return`Confidence ${(Q*100).toFixed(0)}% approaching threshold. Review recent steps for completeness.`;case"continue":return`Continue reasoning. Chain confidence: ${(Q*100).toFixed(0)}%`;case"verification_failed":return"Verification failed. Use revise, branch, or override to continue.";case"budget_exhausted":return"Token budget exhausted. Complete your reasoning or start a new session."}}async function XpA(A,Q,B){let E=WA.getThoughts(A,Q);if(E.length<3)return;let I=v_(E);if(I.pattern==="insufficient")return;if(I.unresolved)await B({type:"text",text:`
348
348
  ⚠️ **Early Drift Warning:** ${I.explanation}
349
349
  `+(I.suggestion?` \uD83D\uDCA1 ${I.suggestion}
@@ -368,7 +368,7 @@ Calculation: ${C.toFixed(2)} × ${V.toFixed(2)} × ${L.toFixed(2)} = ${d.toFixed
368
368
 
369
369
  **Suggested:** revise
370
370
  `})}function KpA(A){let{sessionId:Q,branchId:B,stepNumber:E,thought:I,domain:C,verificationConfidence:D,compressionResult:U}=A;return{id:`${Q}:${B}:${E}`,step_number:E,thought:I,timestamp:Date.now(),branch_id:B,verification:{passed:!1,confidence:D,domain:C},compression:U?{input_bytes_saved:(U.original_tokens-U.compressed_tokens)*4,output_bytes_saved:0,context_bytes_saved:0,original_tokens:U.original_tokens,compressed_tokens:U.compressed_tokens}:void 0}}async function zpA(A,Q,B,E){if(!B)return{thought:A,result:null};let I=cg({thought:A,systemPrompt:Q});if(!I.hasComputations)return{thought:A,result:null};return await E({type:"text",text:`⚡ **Augmented** ${I.computations.length} computations (${I.domain})
371
- `}),{thought:I.augmented,result:{applied:!0,computations:I.computations.length,filtered:I.filteredCount,domain:I.domain}}}async function ZpA(A,Q,B,E){if(!(Q.compress||B||A.length>500&&r0A(A).shouldCompress))return{thought:A,result:null,autoCompressed:!1};let C=Q.compression_query||Q.context||"",U=iM(A,C,{target_ratio:B?0.4:0.6}),Y=B&&!Q.compress,F=Y?" [budget guard]":"";return await E({type:"text",text:`\uD83D\uDCE6 **Compressed** ${U.original_tokens}→${U.compressed_tokens} tokens (${(U.ratio*100).toFixed(0)}%)${F}
371
+ `}),{thought:I.augmented,result:{applied:!0,computations:I.computations.length,filtered:I.filteredCount,domain:I.domain}}}async function ZpA(A,Q,B,E){if(!(Q.compress!==!1||B||A.length>500&&r0A(A).shouldCompress))return{thought:A,result:null,autoCompressed:!1};let C=Q.compression_query||Q.context||"",U=iM(A,C,{target_ratio:B?0.4:0.6}),Y=B&&!Q.compress,F=Y?" [budget guard]":"";return await E({type:"text",text:`\uD83D\uDCE6 **Compressed** ${U.original_tokens}→${U.compressed_tokens} tokens (${(U.ratio*100).toFixed(0)}%)${F}
372
372
  `}),{thought:U.compressed,result:{applied:!0,original_tokens:U.original_tokens,compressed_tokens:U.compressed_tokens,ratio:U.ratio},autoCompressed:Y}}async function RpA(A,Q,B,E){if(A.length>_YA){await E({type:"text",text:`⚠️ Question too long (${A.length} chars, max ${_YA}). Skipping trap detection.
373
373
 
374
374
  `});return}if(WA.setQuestion(Q,A),B!==1){await E({type:"text",text:`⚠️ Question provided at step ${B}. Trap priming only runs on step 1. Stored for spot-check at complete.
@@ -516,7 +516,7 @@ FLOW:
516
516
  3.[optional]challenge()→adversarial self-check of claims
517
517
  4.complete(final_answer="...")→auto spot-check against common traps
518
518
  5.if status=review→revise per reconsideration.suggested_revise
519
- `,parameters:$YA,annotations:{streamingHint:!0},execute:async(A,Q)=>{let B=WA.getActiveSession();if(!B)B=`s_${crypto.randomUUID()}`,WA.setActiveSession(B);try{if(A.hard_limit_tokens&&B){let U=WA.getTokenUsage(B);if(U&&U.total>=A.hard_limit_tokens){let Y={session_id:B,current_step:0,branch:"main",operation:A.operation,chain_confidence:0,confidence_threshold:A.confidence_threshold,steps_with_confidence:0,status:"budget_exhausted",suggested_action:"Token budget exhausted. Complete the reasoning chain with your current answer or start a new session.",session_tokens:U,budget_exhausted:{limit:A.hard_limit_tokens,current:U.total,exceeded_by:U.total-A.hard_limit_tokens,message:`Session has used ${U.total} tokens, exceeding hard limit of ${A.hard_limit_tokens}.`,recommendation:"Use complete operation to finalize your answer, or start a fresh session for new reasoning."}};return{content:[{type:"text",text:`
519
+ `,parameters:$YA,annotations:{streamingHint:!0},execute:async(A,Q)=>{let B=WA.getActiveSession();if(!B)B=`s_${crypto.randomUUID()}`,WA.setActiveSession(B);try{if(A.hard_limit_tokens&&B){let U=WA.getTokenUsage(B);if(U&&U.total>=A.hard_limit_tokens){let Y={session_id:B,current_step:0,branch:"main",operation:A.operation,chain_confidence:0,confidence_threshold:A.confidence_threshold??0.8,steps_with_confidence:0,status:"budget_exhausted",suggested_action:"Token budget exhausted. Complete the reasoning chain with your current answer or start a new session.",session_tokens:U,budget_exhausted:{limit:A.hard_limit_tokens,current:U.total,exceeded_by:U.total-A.hard_limit_tokens,message:`Session has used ${U.total} tokens, exceeding hard limit of ${A.hard_limit_tokens}.`,recommendation:"Use complete operation to finalize your answer, or start a fresh session for new reasoning."}};return{content:[{type:"text",text:`
520
520
  \`\`\`json
521
521
  ${JSON.stringify(Y,null,2)}
522
522
  \`\`\``}]}}}let E;switch(A.operation){case"step":E=await $pA(A,Q,B);break;case"navigate":E=await vpA(A,Q,B);break;case"branch":E=await TpA(A,Q,B);break;case"revise":E=await kpA(A,Q,B);break;case"complete":E=await _pA(A,Q,B);break;case"augment":E=await bpA(A,Q,B);break;case"override":E=await ypA(A,Q,B);break;case"hint":E=await xpA(A,Q,B);break;case"mistakes":E=await fpA(A,Q,B);break;case"spot_check":E=await hpA(A,Q,B);break;case"challenge":E=await upA(A,Q,B);break;default:throw Error(`Unknown operation: ${A.operation}`)}let I=bC(A,E);if(E.compression?.applied){let{countTokens:U}=await Promise.resolve().then(() => (dM(),a0A)),Y=WA.get(E.session_id),g=Y?.thoughts[Y.thoughts.length-1]?.thought||"",N=U(g),J={...A,thought:void 0},G=U(JSON.stringify(J));I.input_tokens=N+G,I.total_tokens=I.input_tokens+I.output_tokens}E.tokens=I;let C=WA.get(E.session_id);if(C)C.tokenUsage.input+=I.input_tokens,C.tokenUsage.output+=I.output_tokens,C.tokenUsage.operations+=1;let D=WA.getTokenUsage(E.session_id)||{total_input:0,total_output:0,total:0,operations:0};if(E.session_tokens=D,A.warn_at_tokens&&D.total>A.warn_at_tokens)E.token_warning={threshold:A.warn_at_tokens,current:D.total,exceeded_by:D.total-A.warn_at_tokens,message:`Session token usage (${D.total}) exceeds threshold (${A.warn_at_tokens}). Consider completing or compressing.`};return{content:[{type:"text",text:`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "verifiable-thinking-mcp",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "MCP server for structured reasoning with cognitive trap detection",
5
5
  "author": "CoderDayton",
6
6
  "license": "MIT",
@@ -247,7 +247,7 @@ export interface AugmentResult {
247
247
  * @returns Augmented thought and metadata, or null if disabled/no computations
248
248
  */
249
249
  export function tryAugment(args: ThinkArgs, thought: string): AugmentResult | null {
250
- if (!args.augment_compute) {
250
+ if (args.augment_compute === false) {
251
251
  return null;
252
252
  }
253
253
 
@@ -42,14 +42,14 @@ export const ScratchpadSchema = z.object({
42
42
  .number()
43
43
  .min(0)
44
44
  .max(1)
45
- .default(0.8)
46
- .describe("Chain confidence threshold to suggest completion"),
45
+ .optional()
46
+ .describe("Chain confidence threshold to suggest completion (default: 0.8)"),
47
47
  token_budget: z
48
48
  .number()
49
49
  .int()
50
50
  .min(100)
51
- .default(3000)
52
- .describe("Max tokens before auto-compressing new steps"),
51
+ .optional()
52
+ .describe("Max tokens before auto-compressing new steps (default: 3000)"),
53
53
  warn_at_tokens: z
54
54
  .number()
55
55
  .int()
@@ -99,12 +99,12 @@ export const ScratchpadSchema = z.object({
99
99
  "Run domain verification. Auto-enabled for chains >3 steps. Set to false to disable.",
100
100
  ),
101
101
  domain: z.enum(["math", "logic", "code", "general"]).optional(),
102
- local_compute: z.boolean().default(false).describe("Try local compute for math"),
102
+ local_compute: z.boolean().optional().describe("Try local compute for math (default: false)"),
103
103
  augment_compute: z
104
104
  .boolean()
105
- .default(true)
105
+ .optional()
106
106
  .describe("Auto-inject computed values into thought (default: true)"),
107
- compress: z.boolean().default(true).describe("Compress thought before storing"),
107
+ compress: z.boolean().optional().describe("Compress thought before storing (default: true)"),
108
108
  compression_query: z.string().optional().describe("Query for context-aware compression"),
109
109
  max_step_tokens: z
110
110
  .number()
@@ -112,7 +112,10 @@ export const ScratchpadSchema = z.object({
112
112
  .min(10)
113
113
  .optional()
114
114
  .describe("Max tokens for this step. Rejects if exceeded (default: no limit)"),
115
- force_large: z.boolean().default(false).describe("Allow step even if it exceeds max_step_tokens"),
115
+ force_large: z
116
+ .boolean()
117
+ .optional()
118
+ .describe("Allow step even if it exceeds max_step_tokens (default: false)"),
116
119
  preconditions: z
117
120
  .array(z.string())
118
121
  .optional()
@@ -127,7 +130,7 @@ export const ScratchpadSchema = z.object({
127
130
  ),
128
131
  step_id: z.number().int().min(1).optional().describe("Step number to view"),
129
132
  branch_id: z.string().optional().describe("Filter history by branch"),
130
- limit: z.number().int().min(1).max(50).default(10).describe("Max steps to return"),
133
+ limit: z.number().int().min(1).max(50).optional().describe("Max steps to return (default: 10)"),
131
134
 
132
135
  // Branch operation fields
133
136
  from_step: z.number().int().min(1).optional().describe("Step to branch from (default: current)"),
@@ -161,7 +164,10 @@ export const ScratchpadSchema = z.object({
161
164
  .optional()
162
165
  .describe("Text containing math expressions to compute and inject (augment/mistakes)"),
163
166
  system_context: z.string().optional().describe("System prompt context for domain filtering"),
164
- store_as_step: z.boolean().default(false).describe("Store augmented result as a reasoning step"),
167
+ store_as_step: z
168
+ .boolean()
169
+ .optional()
170
+ .describe("Store augmented result as a reasoning step (default: false)"),
165
171
 
166
172
  // Override operation fields
167
173
  acknowledge: z
@@ -183,9 +189,14 @@ export const ScratchpadSchema = z.object({
183
189
  .describe("Number of steps to reveal. Omit to auto-increment when continuing."),
184
190
  cumulative: z
185
191
  .boolean()
186
- .default(true)
187
- .describe("Show all steps up to reveal_count (true) or just the nth step (false)"),
188
- reset: z.boolean().default(false).describe("Reset hint state and start from beginning"),
192
+ .optional()
193
+ .describe(
194
+ "Show all steps up to reveal_count (true) or just the nth step (false). Default: true",
195
+ ),
196
+ reset: z
197
+ .boolean()
198
+ .optional()
199
+ .describe("Reset hint state and start from beginning (default: false)"),
189
200
 
190
201
  // Spot check operation fields
191
202
  answer: z.string().optional().describe("The proposed answer to check for trap patterns"),
@@ -607,7 +607,7 @@ async function applyCompression(
607
607
  autoCompressed: boolean;
608
608
  }> {
609
609
  const shouldCompress =
610
- args.compress ||
610
+ args.compress !== false ||
611
611
  budgetExceeded ||
612
612
  (thought.length > 500 && needsCompression(thought).shouldCompress);
613
613
 
@@ -2630,7 +2630,7 @@ FLOW:
2630
2630
  branch: "main",
2631
2631
  operation: args.operation,
2632
2632
  chain_confidence: 0,
2633
- confidence_threshold: args.confidence_threshold,
2633
+ confidence_threshold: args.confidence_threshold ?? 0.8,
2634
2634
  steps_with_confidence: 0,
2635
2635
  status: "budget_exhausted",
2636
2636
  suggested_action: