@swifty.js/swifty 0.0.23 → 0.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,7 +26,7 @@ ${s.join(`
26
26
  `+o.summary;o.keep.length>0&&(s+=`
27
27
 
28
28
  Recent messages have been preserved verbatim.`),n.push({role:"user",content:s});for(let r of o.keep)r.role!=="user"&&r.role!=="assistant"||!r.content&&!(r.tool_uses?.length??0)&&!(r.tool_results?.length??0)||n.push({role:r.role,content:r.content,toolUses:K(r.tool_uses),toolResults:H(r.tool_results)})}for(let s=t+1;s<e.length;s++){let r=e[s];if(r.type===S)continue;let l=L(r);l&&n.push(l)}return n}for(let o of e){let s=L(o);s&&n.push(s)}return n}function L(e){return e.role!=="user"&&e.role!=="assistant"||!e.content&&!(e.tool_uses?.length??0)&&!(e.tool_results?.length??0)?null:{role:e.role,content:e.content,toolUses:K(e.tool_uses),toolResults:H(e.tool_results)}}function Ve(e){let t=b(e);if(!D(t))return[];let n=se(t).filter(s=>s.endsWith(".jsonl")),o=[];for(let s of n){let r=k(t,s),l=ie(r),i=s.replace(".jsonl",""),c="",u=0;try{for(let p of O(r,"utf-8").split(`
29
- `)){if(!p.trim())continue;let d;try{let f=JSON.parse(p);d=C(z,f)}catch(f){R.error({err:f},"session operation failed");continue}u++,!c&&d.role==="user"&&d.content&&(c=h(d.content).slice(0,100))}}catch(p){R.error({err:p},"session operation failed");continue}o.push({id:i,firstMessage:c,messageCount:u,size:l.size,modTime:l.mtime})}return o.sort((s,r)=>r.modTime.getTime()-s.modTime.getTime()),o}var W=3,ue=3,me="[earlier conversation truncated for compaction retry]",pe=3.5,de=1e4,fe=5,ge=4e4,he=2,ye=2e4,Te=13e3,ke=3e3;function J(e,t,n=!1){return e-Math.min(t,ye)-(n?ke:Te)}var G=class{consecutiveFailures=0},x=7e3;function Re(e){if(typeof e=="string")return e.length;let t=0;for(let n of e)n.type==="text"?t+=U(n,"text").length:n.type==="image"&&(t+=x);return t}function be(e){let t=0,n=0;for(let o of e)if(o.type==="text")t+=o.text.length;else if(o.type==="image")n+=x;else if(o.type==="tool_reference")n+=o.tool_name.length;else if(o.type==="search_result")n+=o.source.length+o.title.length,n+=o.content.reduce((s,r)=>s+r.text.length,0);else if(o.source.type==="base64")n+=x;else if(o.source.type==="url")n+=o.source.url.length;else if(o.source.type==="text")n+=o.source.data.length;else if(typeof o.source.content=="string")n+=o.source.content.length;else for(let s of o.source.content)n+=s.type==="text"?s.text.length:x;return{textChars:t,richChars:n}}function w(e){let t=0;for(let n of e){if(t+=Re(n.content),n.toolUses&&(t+=JSON.stringify(n.toolUses).length),n.toolResults)for(let o of n.toolResults)if(o.contentBlocks?.length){let s=be(o.contentBlocks);t+=Math.max(o.content.length,s.textChars)+s.richChars}else t+=o.content.length;if(n.thinkingBlocks)for(let o of n.thinkingBlocks)t+=o.thinking.length}return Math.ceil(t/pe)}function xe(e){return w(e.getMessages())}function B(e){return w([e])}function Ce(e){return e.role==="user"&&!!e.toolResults&&e.toolResults.length>0}function Me(e){let t=0,n=0,o=e.length;for(let s=e.length-1;s>=0;s--){let r=B(e[s]);if(n>0&&t+r>ge||(o=s,t+=r,n++,t>=de||n>=fe))break}return o=Se(e,o),o}function Se(e,t){if(t<=0||t>=e.length||!Ce(e[t]))return t;let n=new Set((e[t].toolResults??[]).map(o=>o.toolUseId));for(let o=t-1;o>=0;o--){let s=e[o];if(s.role==="assistant"&&s.toolUses?.some(r=>n.has(r.toolUseId)))return o}return t}function _e(e,t){let n=t??e.usageAnchorState();if(!n)return xe(e);let o=e.getMessages(),s=Math.min(n.anchorCount,o.length);return n.baselineTokens+w(o.slice(s))}async function nt(e,t,n,o,s,r,l,i,c=""){let u=_e(e),p=J(n,o),d=J(n,o,!0);if(u<p)return{compacted:!1,message:""};if(!(u>=d)&&s.consecutiveFailures>=W)return{compacted:!1,message:`Auto-compact circuit breaker: ${String(W)} consecutive failures`};try{let g=await Q(e,t,r,l,i,c);return s.consecutiveFailures=0,g}catch(g){return s.consecutiveFailures++,{compacted:!1,message:`Auto-compact failed: ${P(g)}`}}}async function st(e,t,n,o,s,r=""){return Q(e,t,n,o,s,r)}var X=`Your task is to create a detailed summary of the conversation so far, paying close attention to the user's explicit requests and your previous actions.
29
+ `)){if(!p.trim())continue;let d;try{let f=JSON.parse(p);d=C(z,f)}catch(f){R.error({err:f},"session operation failed");continue}u++,!c&&d.role==="user"&&d.content&&(c=h(d.content).slice(0,100))}}catch(p){R.error({err:p},"session operation failed");continue}o.push({id:i,firstMessage:c,messageCount:u,size:l.size,modTime:l.mtime})}return o.sort((s,r)=>r.modTime.getTime()-s.modTime.getTime()),o}var W=3,ue=3,me="[earlier conversation truncated for compaction retry]",pe=3.5,de=1e4,fe=5,ge=4e4,he=2,ye=2e4,Te=13e3,ke=3e3;function J(e,t,n=!1){return e-Math.min(t,ye)-(n?ke:Te)}var G=class{consecutiveFailures=0},x=7e3;function Re(e){if(typeof e=="string")return e.length;let t=0;for(let n of e)n.type==="text"?t+=U(n,"text").length:n.type==="image"&&(t+=x);return t}function be(e){let t=0,n=0;for(let o of e)switch(o.type){case"text":{t+=o.text.length;break}case"image":{n+=x;break}case"tool_reference":{n+=o.tool_name.length;break}case"search_result":{n+=o.source.length+o.title.length,n+=o.content.reduce((s,r)=>s+r.text.length,0);break}case"document":{switch(o.source.type){case"base64":{n+=x;break}case"url":{n+=o.source.url.length;break}case"text":{n+=o.source.data.length;break}case"content":{if(typeof o.source.content=="string"){n+=o.source.content.length;break}for(let s of o.source.content)n+=s.type==="text"?s.text.length:x;break}}break}}return{textChars:t,richChars:n}}function w(e){let t=0;for(let n of e){if(t+=Re(n.content),n.toolUses&&(t+=JSON.stringify(n.toolUses).length),n.toolResults)for(let o of n.toolResults)if(o.contentBlocks?.length){let s=be(o.contentBlocks);t+=Math.max(o.content.length,s.textChars)+s.richChars}else t+=o.content.length;if(n.thinkingBlocks)for(let o of n.thinkingBlocks)t+=o.thinking.length}return Math.ceil(t/pe)}function xe(e){return w(e.getMessages())}function B(e){return w([e])}function Ce(e){return e.role==="user"&&!!e.toolResults&&e.toolResults.length>0}function Me(e){let t=0,n=0,o=e.length;for(let s=e.length-1;s>=0;s--){let r=B(e[s]);if(n>0&&t+r>ge||(o=s,t+=r,n++,t>=de||n>=fe))break}return o=Se(e,o),o}function Se(e,t){if(t<=0||t>=e.length||!Ce(e[t]))return t;let n=new Set((e[t].toolResults??[]).map(o=>o.toolUseId));for(let o=t-1;o>=0;o--){let s=e[o];if(s.role==="assistant"&&s.toolUses?.some(r=>n.has(r.toolUseId)))return o}return t}function _e(e,t){let n=t??e.usageAnchorState();if(!n)return xe(e);let o=e.getMessages(),s=Math.min(n.anchorCount,o.length);return n.baselineTokens+w(o.slice(s))}async function nt(e,t,n,o,s,r,l,i,c=""){let u=_e(e),p=J(n,o),d=J(n,o,!0);if(u<p)return{compacted:!1,message:""};if(!(u>=d)&&s.consecutiveFailures>=W)return{compacted:!1,message:`Auto-compact circuit breaker: ${String(W)} consecutive failures`};try{let g=await Q(e,t,r,l,i,c);return s.consecutiveFailures=0,g}catch(g){return s.consecutiveFailures++,{compacted:!1,message:`Auto-compact failed: ${P(g)}`}}}async function st(e,t,n,o,s,r=""){return Q(e,t,n,o,s,r)}var X=`Your task is to create a detailed summary of the conversation so far, paying close attention to the user's explicit requests and your previous actions.
30
30
  This summary should be thorough in capturing technical details, code patterns, and architectural decisions that would be essential for continuing development work without losing context.
31
31
 
32
32
  Before providing your final summary, wrap your analysis in <analysis> tags to organize your thoughts and ensure you've covered all necessary points. In your analysis process:
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire as __swiftyCreateRequire } from "node:module";
3
3
  const require = __swiftyCreateRequire(import.meta.url);
4
- import{c as D,d as O,e as U,g as W,m as B,n as Y,o as j}from"./chunk-MJR2C7S7.js";import{a as C,e as M,g as L}from"./chunk-FZPTNGTU.js";import{I as f,L as A,N as F,O as N,R as E}from"./chunk-SIWLMWHH.js";function x(n){return n?Math.floor(n.length/3.5):0}function T(n,e){if(e<=0||!n||x(n)<=e)return n;let t=Math.floor(e*3.5);if(t<=0||t>=n.length)return n;let o=`
4
+ import{c as D,d as O,e as U,g as W,m as B,n as Y,o as j}from"./chunk-MWZIARZE.js";import{a as C,e as M,g as L}from"./chunk-FZPTNGTU.js";import{I as f,L as A,N as F,O as N,R as E}from"./chunk-SIWLMWHH.js";function x(n){return n?Math.floor(n.length/3.5):0}function T(n,e){if(e<=0||!n||x(n)<=e)return n;let t=Math.floor(e*3.5);if(t<=0||t>=n.length)return n;let o=`
5
5
  \u2026 (content truncated)`;return t<=o.length?o.slice(0,t):n.slice(0,t-o.length)+o}var b=class{files=new Map;skills=new Map;recordFileRead(e,t){for(this.files.delete(e),this.files.set(e,{path:e,content:T(t,5e3),timestamp:Date.now()});this.files.size>5;){let o=this.files.keys().next().value;if(typeof o!="string")break;this.files.delete(o)}}recordSkillInvocation(e,t){this.skills.set(e,{name:e,body:t,timestamp:Date.now()})}snapshotFiles(e=5){return[...this.files.values()].sort((o,r)=>r.timestamp-o.timestamp).slice(0,e)}snapshotSkills(){return[...this.skills.values()].sort((e,t)=>t.timestamp-e.timestamp)}buildRecoveryAttachment(e){let t=[],o=this.snapshotFiles();if(o.length>0){t.push(`## Recently read files
6
6
  `),t.push(`These snapshots are what the file-reading tool last returned. Re-open with the tool if you need the current bytes.
7
7
  `);for(let s of o){let i=T(s.content,5e3),l=new Date(s.timestamp).toISOString().replace(/\.\d{3}Z$/,"Z");t.push(`### ${s.path} (read ${l})
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire as __swiftyCreateRequire } from "node:module";
3
3
  const require = __swiftyCreateRequire(import.meta.url);
4
- import{a as x}from"./chunk-7MHXMDYC.js";import{C as o,I as S,b as p,c as u}from"./chunk-SIWLMWHH.js";import{existsSync as E,readFileSync as $}from"fs";import{homedir as I}from"os";import{join as m}from"path";function l(e){return!!e._zod}function f(e,t){return l(e)?p(e,t):e.safeParse(t)}async function ee(e,t){return l(e)?await u(e,t):await e.safeParseAsync(t)}function oe(e){if(!e)return;let t;if(l(e)?t=e._zod?.def?.shape:t=e.shape,!!t){if(typeof t=="function")try{return t()}catch{return}return t}}function ne(e){if(l(e)){let s=e._zod?.def;if(s){if(s.value!==void 0)return s.value;if(Array.isArray(s.values)&&s.values.length>0)return s.values[0]}}let n=e._def;if(n){if(n.value!==void 0)return n.value;if(Array.isArray(n.values)&&n.values.length>0)return n.values[0]}let r=e.value;if(r!==void 0)return r}var g=S({module:"config"}),A={anthropic:"ANTHROPIC_API_KEY",openai:"OPENAI_API_KEY","openai-compat":"OPENAI_API_KEY"};function N(e){return _.has(e)}var _=new Set(Object.keys(A)),d=class extends Error{constructor(t){super(t),this.name="ConfigError"}},P=o.object({name:o.string(),protocol:o.enum(["anthropic","openai","openai-compat"]),base_url:o.string(),model:o.string(),api_key:o.string().optional(),thinking:o.boolean().optional(),context_window:o.coerce.number().optional(),max_output_tokens:o.coerce.number().optional()}),V=[["1m",1e6],["gpt-4.1",1e6],["gpt-4o",128e3],["gpt-4-turbo",128e3],["o1",2e5],["o3",2e5],["o4",2e5],["gpt-3.5",16385],["claude",2e5]];function j(e){let t=e.toLowerCase();for(let[n,r]of V)if(t.includes(n))return r;return t.includes("claude")?2e5:128e3}function le(e){return e.context_window&&e.context_window>0?e.context_window:j(e.model)}var w=new Map;async function pe(e,t){if(e.context_window&&e.context_window>0)return e.context_window;if(e.protocol==="anthropic"){let n=`${e.name}-${e.model}`,r=w.get(n);if(r===void 0){try{r=await(t??(await import("./anthropic-V22T6E6E.js")).fetchModelContextWindow)(e)}catch(i){g.error({err:i},"config operation failed"),r=0}w.set(n,r)}if(r&&r>0)return r}return j(e.model)}function ue(e){return e.max_output_tokens&&e.max_output_tokens>0?e.max_output_tokens:e.thinking?64e3:8192}function me(e){if(e.api_key)return e.api_key;let t=N(e.protocol)?A[e.protocol]:"";return t?process.env[t]??"":""}var O=o.object({name:o.string(),command:o.string().optional(),args:o.array(o.string()).optional(),url:o.string().optional(),transport:o.string().optional(),headers:o.record(o.string(),o.string()).optional(),env:o.record(o.string(),o.string()).optional()}),z=o.object({id:o.string().optional(),event:o.string(),condition:o.string().optional(),action:o.object({type:o.string(),command:o.string().optional(),url:o.string().optional(),method:o.string().optional(),prompt:o.string().optional()}),reject:o.boolean().optional(),once:o.boolean().optional(),async:o.boolean().optional(),on_error:o.string().optional()}),M=o.object({enabled:o.boolean().optional(),auto_allow:o.boolean().optional(),network_enabled:o.boolean().optional()}),T=o.looseObject({providers:o.array(P),permission_mode:o.string().optional(),mcp_servers:o.array(O).default([]),hooks:o.array(z).default([]),sandbox:M.optional(),enable_coordinator_mode:o.boolean().optional(),enable_fork:o.boolean().optional()});function ge(e){return e.enable_fork!==!1}function Y(e){return typeof e=="object"&&e!==null}function C(e){let t=$(e,"utf-8"),n=x.load(t);if(!Y(n))return g.error({path:e},"invalid yaml"),{providers:[],mcp_servers:[],hooks:[]};let r=f(T,n);if(r.success){let a=r.data;return{providers:a.providers,permission_mode:a.permission_mode,mcp_servers:a.mcp_servers,hooks:a.hooks}}g.error({error:r.error},"config error");let i=[],s,c=[],y=[],v,b=!1,h=!0;if("providers"in n){let a=f(o.array(P),n.providers);a.success&&(i=a.data)}if("permission_mode"in n&&typeof n.permission_mode=="string"&&(s=n.permission_mode),"mcp_servers"in n){let a=f(o.array(O),n.mcp_servers);a.success&&(c=a.data)}if("hooks"in n){let a=f(o.array(z),n.hooks);a.success&&(y=a.data)}if("sandbox"in n){let a=f(M,n.sandbox);a.success&&(v=a.data)}return"enable_coordinator_mode"in n&&(b=!!n.enable_coordinator_mode),"enable_fork"in n&&(h=!!n.enable_fork),{providers:i,permission_mode:s,mcp_servers:c,hooks:y,sandbox:v,enable_coordinator_mode:b,enable_fork:h}}function K(e,t){if(t.providers.length>0&&(e.providers=t.providers),t.permission_mode&&(e.permission_mode=t.permission_mode),t.mcp_servers.length>0){let n=new Map;for(let r=0;r<e.mcp_servers.length;r++){let i=e.mcp_servers[r];n.set(i.name,r)}for(let r of t.mcp_servers){let i=n.get(r.name);i!==void 0?e.mcp_servers[i]=r:(e.mcp_servers.push(r),n.set(r.name,e.mcp_servers.length-1))}}return e.hooks=[...e.hooks,...t.hooks],t.sandbox&&(e.sandbox={...e.sandbox,...t.sandbox}),t.enable_coordinator_mode&&(e.enable_coordinator_mode=!0),t.enable_fork!==void 0&&(e.enable_fork=t.enable_fork),e}function k(e){if(e.providers.length===0)throw new d("At least one provider MUST be configured.");let t=["name","protocol","base_url","model"];for(let n=0;n<e.providers.length;n++){let r=e.providers[n],i={name:r.name,protocol:r.protocol,base_url:r.base_url,model:r.model},s=t.filter(c=>!(c in i));if(s.length>0)throw new d(`Provider #${String(n+1)}: missing fields: ${s.join(", ")}`);if(!_.has(r.protocol))throw new d(`Provider #${String(n+1)}: invalid protocol '${r.protocol}', MUST be one of: ${Array.from(_).join(", ")}`)}}function _e(e){if(e){let s=C(e);return k(s),s}let t=process.cwd(),n=I(),r=[m(n,".swifty","config.yaml"),m(t,".swifty","config.yaml"),m(t,".swifty","config.local.yaml")],i=null;for(let s of r){if(!E(s))continue;let c=C(s);i?i=K(i,c):i=c}if(!i)throw new d("No config file found, expected .swifty/config.y(a)ml under project or $HOME/.swifty/config.y(a)ml.");return k(i),i}export{f as a,ee as b,oe as c,ne as d,le as e,pe as f,ue as g,me as h,ge as i,_e as j};
4
+ import{a as x}from"./chunk-7MHXMDYC.js";import{C as o,I as S,b as p,c as u}from"./chunk-SIWLMWHH.js";import{existsSync as E,readFileSync as $}from"fs";import{homedir as I}from"os";import{join as m}from"path";function l(e){return!!e._zod}function f(e,t){return l(e)?p(e,t):e.safeParse(t)}async function ee(e,t){return l(e)?await u(e,t):await e.safeParseAsync(t)}function oe(e){if(!e)return;let t;if(l(e)?t=e._zod?.def?.shape:t=e.shape,!!t){if(typeof t=="function")try{return t()}catch{return}return t}}function ne(e){if(l(e)){let s=e._zod?.def;if(s){if(s.value!==void 0)return s.value;if(Array.isArray(s.values)&&s.values.length>0)return s.values[0]}}let n=e._def;if(n){if(n.value!==void 0)return n.value;if(Array.isArray(n.values)&&n.values.length>0)return n.values[0]}let r=e.value;if(r!==void 0)return r}var g=S({module:"config"}),A={anthropic:"ANTHROPIC_API_KEY",openai:"OPENAI_API_KEY","openai-compat":"OPENAI_API_KEY"};function N(e){return _.has(e)}var _=new Set(Object.keys(A)),d=class extends Error{constructor(t){super(t),this.name="ConfigError"}},P=o.object({name:o.string(),protocol:o.enum(["anthropic","openai","openai-compat"]),base_url:o.string(),model:o.string(),api_key:o.string().optional(),thinking:o.boolean().optional(),context_window:o.coerce.number().optional(),max_output_tokens:o.coerce.number().optional()}),V=[["1m",1e6],["gpt-4.1",1e6],["gpt-4o",128e3],["gpt-4-turbo",128e3],["o1",2e5],["o3",2e5],["o4",2e5],["gpt-3.5",16385],["claude",2e5]];function j(e){let t=e.toLowerCase();for(let[n,r]of V)if(t.includes(n))return r;return t.includes("claude")?2e5:128e3}function le(e){return e.context_window&&e.context_window>0?e.context_window:j(e.model)}var w=new Map;async function pe(e,t){if(e.context_window&&e.context_window>0)return e.context_window;if(e.protocol==="anthropic"){let n=`${e.name}-${e.model}`,r=w.get(n);if(r===void 0){try{r=await(t??(await import("./anthropic-7QRAPLOY.js")).fetchModelContextWindow)(e)}catch(i){g.error({err:i},"config operation failed"),r=0}w.set(n,r)}if(r&&r>0)return r}return j(e.model)}function ue(e){return e.max_output_tokens&&e.max_output_tokens>0?e.max_output_tokens:e.thinking?64e3:8192}function me(e){if(e.api_key)return e.api_key;let t=N(e.protocol)?A[e.protocol]:"";return t?process.env[t]??"":""}var O=o.object({name:o.string(),command:o.string().optional(),args:o.array(o.string()).optional(),url:o.string().optional(),transport:o.string().optional(),headers:o.record(o.string(),o.string()).optional(),env:o.record(o.string(),o.string()).optional()}),z=o.object({id:o.string().optional(),event:o.string(),condition:o.string().optional(),action:o.object({type:o.string(),command:o.string().optional(),url:o.string().optional(),method:o.string().optional(),prompt:o.string().optional()}),reject:o.boolean().optional(),once:o.boolean().optional(),async:o.boolean().optional(),on_error:o.string().optional()}),M=o.object({enabled:o.boolean().optional(),auto_allow:o.boolean().optional(),network_enabled:o.boolean().optional()}),T=o.looseObject({providers:o.array(P),permission_mode:o.string().optional(),mcp_servers:o.array(O).default([]),hooks:o.array(z).default([]),sandbox:M.optional(),enable_coordinator_mode:o.boolean().optional(),enable_fork:o.boolean().optional()});function ge(e){return e.enable_fork!==!1}function Y(e){return typeof e=="object"&&e!==null}function C(e){let t=$(e,"utf-8"),n=x.load(t);if(!Y(n))return g.error({path:e},"invalid yaml"),{providers:[],mcp_servers:[],hooks:[]};let r=f(T,n);if(r.success){let a=r.data;return{providers:a.providers,permission_mode:a.permission_mode,mcp_servers:a.mcp_servers,hooks:a.hooks}}g.error({error:r.error},"config error");let i=[],s,c=[],y=[],v,b=!1,h=!0;if("providers"in n){let a=f(o.array(P),n.providers);a.success&&(i=a.data)}if("permission_mode"in n&&typeof n.permission_mode=="string"&&(s=n.permission_mode),"mcp_servers"in n){let a=f(o.array(O),n.mcp_servers);a.success&&(c=a.data)}if("hooks"in n){let a=f(o.array(z),n.hooks);a.success&&(y=a.data)}if("sandbox"in n){let a=f(M,n.sandbox);a.success&&(v=a.data)}return"enable_coordinator_mode"in n&&(b=!!n.enable_coordinator_mode),"enable_fork"in n&&(h=!!n.enable_fork),{providers:i,permission_mode:s,mcp_servers:c,hooks:y,sandbox:v,enable_coordinator_mode:b,enable_fork:h}}function K(e,t){if(t.providers.length>0&&(e.providers=t.providers),t.permission_mode&&(e.permission_mode=t.permission_mode),t.mcp_servers.length>0){let n=new Map;for(let r=0;r<e.mcp_servers.length;r++){let i=e.mcp_servers[r];n.set(i.name,r)}for(let r of t.mcp_servers){let i=n.get(r.name);i!==void 0?e.mcp_servers[i]=r:(e.mcp_servers.push(r),n.set(r.name,e.mcp_servers.length-1))}}return e.hooks=[...e.hooks,...t.hooks],t.sandbox&&(e.sandbox={...e.sandbox,...t.sandbox}),t.enable_coordinator_mode&&(e.enable_coordinator_mode=!0),t.enable_fork!==void 0&&(e.enable_fork=t.enable_fork),e}function k(e){if(e.providers.length===0)throw new d("At least one provider MUST be configured.");let t=["name","protocol","base_url","model"];for(let n=0;n<e.providers.length;n++){let r=e.providers[n],i={name:r.name,protocol:r.protocol,base_url:r.base_url,model:r.model},s=t.filter(c=>!(c in i));if(s.length>0)throw new d(`Provider #${String(n+1)}: missing fields: ${s.join(", ")}`);if(!_.has(r.protocol))throw new d(`Provider #${String(n+1)}: invalid protocol '${r.protocol}', MUST be one of: ${Array.from(_).join(", ")}`)}}function _e(e){if(e){let s=C(e);return k(s),s}let t=process.cwd(),n=I(),r=[m(n,".swifty","config.yaml"),m(t,".swifty","config.yaml"),m(t,".swifty","config.local.yaml")],i=null;for(let s of r){if(!E(s))continue;let c=C(s);i?i=K(i,c):i=c}if(!i)throw new d("No config file found, expected .swifty/config.y(a)ml under project or $HOME/.swifty/config.y(a)ml.");return k(i),i}export{f as a,ee as b,oe as c,ne as d,le as e,pe as f,ue as g,me as h,ge as i,_e as j};
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  Agent
3
- } from "./chunk-MF3YLQDS.js";
4
- import "./chunk-BN4Q54G2.js";
3
+ } from "./chunk-XG6NELJH.js";
4
+ import "./chunk-2QILP24G.js";
5
5
  import "./chunk-OO2CLOEE.js";
6
6
  import "./chunk-EY7HE52Q.js";
7
7
  export {
@@ -5,9 +5,9 @@ import {
5
5
  markLastUserTailForCache,
6
6
  markToolsForCache,
7
7
  needsToolSearchBeta
8
- } from "./chunk-7IZEK7X5.js";
9
- import "./chunk-BN4Q54G2.js";
10
- import "./chunk-CYDNMEBC.js";
8
+ } from "./chunk-2AUSNVIB.js";
9
+ import "./chunk-2QILP24G.js";
10
+ import "./chunk-3LU4APFB.js";
11
11
  import "./chunk-OO2CLOEE.js";
12
12
  import "./chunk-PZ42NAFA.js";
13
13
  import "./chunk-EY7HE52Q.js";
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  computeCompactThreshold
3
- } from "./chunk-BN4Q54G2.js";
3
+ } from "./chunk-2QILP24G.js";
4
4
  import {
5
5
  getContextWindow,
6
6
  getMaxOutputTokens,
7
7
  resolveAPIKey
8
- } from "./chunk-CYDNMEBC.js";
8
+ } from "./chunk-3LU4APFB.js";
9
9
  import {
10
10
  AuthenticationError,
11
11
  ContextTooLongError,
@@ -663,26 +663,50 @@ function toolResultBlocksChars(blocks) {
663
663
  let textChars = 0;
664
664
  let richChars = 0;
665
665
  for (const block of blocks) {
666
- if (block.type === "text") {
667
- textChars += block.text.length;
668
- } else if (block.type === "image") {
669
- richChars += IMAGE_CHAR_EQUIV;
670
- } else if (block.type === "tool_reference") {
671
- richChars += block.tool_name.length;
672
- } else if (block.type === "search_result") {
673
- richChars += block.source.length + block.title.length;
674
- richChars += block.content.reduce((sum, content) => sum + content.text.length, 0);
675
- } else if (block.source.type === "base64") {
676
- richChars += IMAGE_CHAR_EQUIV;
677
- } else if (block.source.type === "url") {
678
- richChars += block.source.url.length;
679
- } else if (block.source.type === "text") {
680
- richChars += block.source.data.length;
681
- } else if (typeof block.source.content === "string") {
682
- richChars += block.source.content.length;
683
- } else {
684
- for (const content of block.source.content) {
685
- richChars += content.type === "text" ? content.text.length : IMAGE_CHAR_EQUIV;
666
+ switch (block.type) {
667
+ case "text": {
668
+ textChars += block.text.length;
669
+ break;
670
+ }
671
+ case "image": {
672
+ richChars += IMAGE_CHAR_EQUIV;
673
+ break;
674
+ }
675
+ case "tool_reference": {
676
+ richChars += block.tool_name.length;
677
+ break;
678
+ }
679
+ case "search_result": {
680
+ richChars += block.source.length + block.title.length;
681
+ richChars += block.content.reduce((sum, content) => sum + content.text.length, 0);
682
+ break;
683
+ }
684
+ case "document": {
685
+ switch (block.source.type) {
686
+ case "base64": {
687
+ richChars += IMAGE_CHAR_EQUIV;
688
+ break;
689
+ }
690
+ case "url": {
691
+ richChars += block.source.url.length;
692
+ break;
693
+ }
694
+ case "text": {
695
+ richChars += block.source.data.length;
696
+ break;
697
+ }
698
+ case "content": {
699
+ if (typeof block.source.content === "string") {
700
+ richChars += block.source.content.length;
701
+ break;
702
+ }
703
+ for (const content of block.source.content) {
704
+ richChars += content.type === "text" ? content.text.length : IMAGE_CHAR_EQUIV;
705
+ }
706
+ break;
707
+ }
708
+ }
709
+ break;
686
710
  }
687
711
  }
688
712
  }
@@ -75,7 +75,7 @@ async function getContextWindowAsync(p, fetcher) {
75
75
  let fetched = fetchedWindowCache.get(key);
76
76
  if (fetched === void 0) {
77
77
  try {
78
- const fn = fetcher ?? (await import("./anthropic-7YEN2QTU.js")).fetchModelContextWindow;
78
+ const fn = fetcher ?? (await import("./anthropic-RYPJDHQM.js")).fetchModelContextWindow;
79
79
  fetched = await fn(p);
80
80
  } catch (err) {
81
81
  log.error({ err }, "config operation failed");
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  getMaxOutputTokens,
3
3
  resolveAPIKey
4
- } from "./chunk-CYDNMEBC.js";
4
+ } from "./chunk-3LU4APFB.js";
5
5
  import {
6
6
  AuthenticationError,
7
7
  ContextTooLongError,
@@ -6,7 +6,7 @@ import {
6
6
  saveMessage,
7
7
  toolResultsToRecords,
8
8
  toolUsesToRecords
9
- } from "./chunk-BN4Q54G2.js";
9
+ } from "./chunk-2QILP24G.js";
10
10
  import {
11
11
  ContextTooLongError,
12
12
  REJECTED_TOOL_RESULT,
package/dist/lib/index.js CHANGED
@@ -18,7 +18,7 @@ import {
18
18
  resetPlanPath,
19
19
  savePlan,
20
20
  toDisplayPreview
21
- } from "./chunk-MF3YLQDS.js";
21
+ } from "./chunk-XG6NELJH.js";
22
22
  import {
23
23
  AnthropicClient,
24
24
  CHARS_PER_TOKEN,
@@ -35,7 +35,7 @@ import {
35
35
  markToolsForCache,
36
36
  measureSchemaChars,
37
37
  needsToolSearchBeta
38
- } from "./chunk-7IZEK7X5.js";
38
+ } from "./chunk-2AUSNVIB.js";
39
39
  import {
40
40
  AutoCompactTrackingState,
41
41
  COMPACT_BOUNDARY,
@@ -60,13 +60,13 @@ import {
60
60
  saveMessage,
61
61
  toolResultsToRecords,
62
62
  toolUsesToRecords
63
- } from "./chunk-BN4Q54G2.js";
63
+ } from "./chunk-2QILP24G.js";
64
64
  import {
65
65
  OpenAIClient,
66
66
  OpenAICompatClient,
67
67
  buildChatCompletionMessages,
68
68
  buildOpenAIInput
69
- } from "./chunk-BO76JDFZ.js";
69
+ } from "./chunk-XFSN4LMA.js";
70
70
  import {
71
71
  ConfigError,
72
72
  HookConfigSchema,
@@ -80,7 +80,7 @@ import {
80
80
  lookupModelContextWindow,
81
81
  mergeConfig,
82
82
  resolveAPIKey
83
- } from "./chunk-CYDNMEBC.js";
83
+ } from "./chunk-3LU4APFB.js";
84
84
  import {
85
85
  AuthenticationError,
86
86
  ContextTooLongError,
@@ -2552,15 +2552,15 @@ async function saveClipboardImage(workDir, sessionId) {
2552
2552
  async function createClient(config, systemPrompt) {
2553
2553
  switch (config.protocol) {
2554
2554
  case "anthropic": {
2555
- const { AnthropicClient: AnthropicClient2 } = await import("./anthropic-7YEN2QTU.js");
2555
+ const { AnthropicClient: AnthropicClient2 } = await import("./anthropic-RYPJDHQM.js");
2556
2556
  return new AnthropicClient2(config, systemPrompt);
2557
2557
  }
2558
2558
  case "openai": {
2559
- const { OpenAIClient: OpenAIClient2 } = await import("./openai-RDHZFJUT.js");
2559
+ const { OpenAIClient: OpenAIClient2 } = await import("./openai-VX5VBXZ4.js");
2560
2560
  return new OpenAIClient2(config, systemPrompt);
2561
2561
  }
2562
2562
  case "openai-compat": {
2563
- const { OpenAICompatClient: OpenAICompatClient2 } = await import("./openai-RDHZFJUT.js");
2563
+ const { OpenAICompatClient: OpenAICompatClient2 } = await import("./openai-VX5VBXZ4.js");
2564
2564
  return new OpenAICompatClient2(config, systemPrompt);
2565
2565
  }
2566
2566
  default:
@@ -2609,7 +2609,7 @@ var PackageJsonSchema = z5.object({
2609
2609
  });
2610
2610
  function resolveVersion() {
2611
2611
  if (true) {
2612
- return "0.0.23";
2612
+ return "0.0.24";
2613
2613
  }
2614
2614
  const here = path.dirname(fileURLToPath(import.meta.url));
2615
2615
  for (const levels of ["..", "../.."]) {
@@ -10100,7 +10100,7 @@ async function createRemoteAgent(opts) {
10100
10100
  throw new Error("no llm client (provider not initialized)");
10101
10101
  }
10102
10102
  const { PermissionChecker: PC } = await import("./checker-6BW4222R.js");
10103
- const { Agent: AgentClass } = await import("./agent-GHXYOARN.js");
10103
+ const { Agent: AgentClass } = await import("./agent-U42LS73D.js");
10104
10104
  const subConv = new ConversationManager();
10105
10105
  subConv.addUserMessage(prompt);
10106
10106
  const subAgent = new AgentClass({
@@ -3,8 +3,8 @@ import {
3
3
  OpenAICompatClient,
4
4
  buildChatCompletionMessages,
5
5
  buildOpenAIInput
6
- } from "./chunk-BO76JDFZ.js";
7
- import "./chunk-CYDNMEBC.js";
6
+ } from "./chunk-XFSN4LMA.js";
7
+ import "./chunk-3LU4APFB.js";
8
8
  import "./chunk-OO2CLOEE.js";
9
9
  import "./chunk-EY7HE52Q.js";
10
10
  export {