@swifty.js/swifty 0.0.20 → 0.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/{agent-ZLM7IKHU.js → agent-5T7KNC7V.js} +1 -1
  2. package/dist/{anthropic-XJ5BOCJA.js → anthropic-P2R4GW6F.js} +1 -1
  3. package/dist/checker-OJFS2MZY.js +4 -0
  4. package/dist/{chunk-T74SUDUF.js → chunk-GUXBLUNR.js} +1 -1
  5. package/dist/{chunk-3USGFIWF.js → chunk-HJIGA37J.js} +1 -1
  6. package/dist/chunk-L73IHJF4.js +386 -0
  7. package/dist/{chunk-ZM2V2A7B.js → chunk-LX2LK3TF.js} +11 -11
  8. package/dist/{chunk-5J4WCPY4.js → chunk-NEAR6YPZ.js} +14 -14
  9. package/dist/{chunk-KSCFIYHH.js → chunk-NLNH3IRT.js} +1 -1
  10. package/dist/{chunk-ASZMSWK5.js → chunk-YQQVB6VB.js} +10 -9
  11. package/dist/{chunk-P276SKAC.js → chunk-ZZQE743W.js} +1 -1
  12. package/dist/lib/agent-2AGRYN3R.js +9 -0
  13. package/dist/lib/anthropic-GFWP3ORB.js +22 -0
  14. package/dist/lib/bwrap-QRGPUP4J.js +6 -0
  15. package/dist/lib/checker-IIXJXQCB.js +19 -0
  16. package/dist/lib/chunk-6GOWRPYS.js +339 -0
  17. package/dist/lib/chunk-7URDLWQN.js +426 -0
  18. package/dist/lib/chunk-C7IHCJZ3.js +849 -0
  19. package/dist/lib/chunk-EJLGB2EJ.js +377 -0
  20. package/dist/lib/chunk-GHF2PSEW.js +8 -0
  21. package/dist/lib/chunk-GNBXECZN.js +243 -0
  22. package/dist/lib/chunk-HK2Z6WP4.js +223 -0
  23. package/dist/lib/chunk-LUEP4JMF.js +549 -0
  24. package/dist/lib/chunk-ORSYNBMM.js +38 -0
  25. package/dist/lib/chunk-RR2CZ6CY.js +598 -0
  26. package/dist/lib/chunk-UHVO63Y7.js +1246 -0
  27. package/dist/lib/chunk-UMFNTXKA.js +88 -0
  28. package/dist/lib/chunk-VUD72RTY.js +39 -0
  29. package/dist/lib/glob.wasm +0 -0
  30. package/dist/lib/index.d.ts +5350 -0
  31. package/dist/lib/index.js +12002 -0
  32. package/dist/lib/openai-HXRMPNB7.js +15 -0
  33. package/dist/lib/seatbelt-FT5IY73W.js +6 -0
  34. package/dist/lib/tool-filter-VF7TZRE5.js +19 -0
  35. package/dist/main.js +224 -230
  36. package/dist/{openai-LZ7SDDQU.js → openai-TVUUHRG7.js} +1 -1
  37. package/dist/{server-QBALAEOH.js → server-ZTLHJWEQ.js} +14 -14
  38. package/package.json +14 -2
  39. package/dist/checker-4RL4BTDA.js +0 -4
  40. package/dist/chunk-CMG6CZSL.js +0 -386
@@ -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{h as a}from"./chunk-5J4WCPY4.js";import"./chunk-ASZMSWK5.js";import"./chunk-FZPTNGTU.js";import"./chunk-ZM2V2A7B.js";import"./chunk-X3UA5OZL.js";export{a as Agent};
4
+ import{h as a}from"./chunk-NEAR6YPZ.js";import"./chunk-YQQVB6VB.js";import"./chunk-FZPTNGTU.js";import"./chunk-LX2LK3TF.js";import"./chunk-X3UA5OZL.js";export{a as Agent};
@@ -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 $}from"./chunk-3USGFIWF.js";import{g as P}from"./chunk-H7VXSMJR.js";import{k as C}from"./chunk-ASZMSWK5.js";import{e as H,g as Y,h as R}from"./chunk-KSCFIYHH.js";import{b as N,c as K,d as M,e as W,f as F,g as G}from"./chunk-FZPTNGTU.js";import"./chunk-P276SKAC.js";import"./chunk-7MHXMDYC.js";import{C as w,I as O,J as v,K as j,L as B,M as I,N as _,O as U,g as L}from"./chunk-ZM2V2A7B.js";import"./chunk-E55KH72M.js";import"./chunk-X3UA5OZL.js";function D(o){for(let t=o.length-1;t>=0;t--){let e=o[t];if(e.defer_loading!==!0){e.cache_control={type:"ephemeral"};return}}}function J(o){return o.some(t=>t.defer_loading)}var x=O({module:"llm"});var z=3e3,V=w.object({max_input_tokens:w.coerce.number()});async function pt(o){if(o.protocol!=="anthropic")return 0;let t=R(o),n=`${o.base_url.replace(/\/+$/,"")}/v1/models/${encodeURIComponent(o.model)}`,s=new AbortController,r=setTimeout(()=>{s.abort()},z);try{let c=await fetch(n,{method:"GET",headers:{"anthropic-version":"2023-06-01",...t?{"x-api-key":t}:{}},signal:s.signal});if(!c.ok)return 0;let h=await c.json(),{success:g,error:f,data:d}=await L(V,h);if(!g)return x.warn({message:f.message},"model context window schema validation failed"),0;let k=d.max_input_tokens;return Math.max(k,0)}catch(c){return x.error({err:c},"failed to fetch model context window"),0}finally{clearTimeout(r)}}function Q(){return!0}function S(o){return typeof o=="string"?[{type:"text",text:o}]:o}function X(o){let t=[];for(let e of o)if(e.role==="assistant"){let n=[];if(e.thinkingBlocks)for(let r of e.thinkingBlocks)n.push({type:"thinking",thinking:r.thinking,signature:r.signature});let s=typeof e.content=="string"?e.content:j(e.content);if(s&&n.push({type:"text",text:s}),e.toolUses)for(let r of e.toolUses)n.push({type:"tool_use",id:r.toolUseId,name:r.toolName,input:r.arguments});n.length===0&&n.push({type:"text",text:""}),t.push({role:"assistant",content:n})}else if(e.toolResults&&e.toolResults.length>0){let n=[];for(let s of e.toolResults)n.push({type:"tool_result",tool_use_id:s.toolUseId,is_error:s.isError,content:s.content});t.push({role:"user",content:n})}else{if(t.length===0){t.push({role:"user",content:S(e.content)});continue}let n=!1,s=t[t.length-1],r=s.content;s.role==="user"&&(typeof r=="string"||Array.isArray(r)&&r.length>0&&(r[0].type==="text"||r[0].type==="image"))&&(n=!0),n?(typeof r=="string"&&(r=s.content=r.trim().length>0?[{type:"text",text:r}]:[]),r.push(...S(e.content))):t.push({role:"user",content:S(e.content)})}return t}var q=class{client;model;thinking;systemPrompt;maxOutputTokens;contextWindow;constructor(t,e){let n=R(t);if(!n)throw new M("Anthropic API key not found, set ANTHROPIC_API_KEY in .swifty/config.y(a)ml, or via ANTHROPIC_API_KEY env variable.");this.client=new P({apiKey:n,baseURL:t.base_url}),this.model=t.model,this.thinking=t.thinking??!0,this.systemPrompt=e,this.maxOutputTokens=Y(t),this.contextWindow=H(t)}setSystemPrompt(t){this.systemPrompt=t}setMaxOutputTokens(t){this.maxOutputTokens=t}async*stream(t,e,n){let s=X(N(t.getMessages())),r=J(e),c=e.map(l=>{let p=l.input_schema,u={name:l.name,description:l.description,input_schema:{type:"object",properties:p.properties,required:p.required??[]}};return l.defer_loading===!0&&(u.defer_loading=!0),u});D(c),Z(s);let h={model:this.model,max_tokens:this.maxOutputTokens,stream:!0,system:[{type:"text",text:this.systemPrompt,cache_control:{type:"ephemeral"}}],messages:s,...c.length>0?{tools:c}:{}};this.thinking?Q()&&(h.thinking={type:"enabled",budget_tokens:C(this.contextWindow,this.maxOutputTokens)}):h.thinking={type:"enabled",budget_tokens:C(this.contextWindow,this.maxOutputTokens)};let g=0,f=0,d=0,k=0,E="end_turn",T="",b="",A=!1;try{let l=this.client.messages.stream(h,{...n?{signal:n}:{},...r?{headers:{"anthropic-beta":$}}:{}}),p="",u="",m="";for await(let i of l)switch(i.type){case"content_block_start":{let a=i.content_block;a.type==="thinking"?(A=!0,T="",b=""):a.type==="tool_use"&&(u=a.id,p=a.name,m="",yield{type:"tool_call_start",toolName:p,toolId:u});break}case"content_block_delta":{let a=i.delta;a.type==="thinking_delta"?(T+=a.thinking,yield{type:"thinking_delta",text:a.thinking}):a.type==="signature_delta"?b=a.signature:a.type==="text_delta"?yield{type:"text_delta",text:a.text}:a.type==="input_json_delta"&&(m+=a.partial_json,yield{type:"tool_call_delta",text:a.partial_json});break}case"content_block_stop":{if(A&&(yield{type:"thinking_complete",thinking:T,signature:b},A=!1),p){let a={};if(m)try{let y=JSON.parse(m);a=B(y)?I(y):{[v]:m}}catch(y){x.error({err:y},"llm operation failed"),a={[v]:m}}yield{type:"tool_call_complete",toolId:u,toolName:p,arguments:a},p="",u="",m=""}break}case"message_delta":{i.delta.stop_reason&&(E=i.delta.stop_reason),i.usage.output_tokens&&(f=i.usage.output_tokens,i.usage.input_tokens&&(g=i.usage.input_tokens),i.usage.cache_read_input_tokens&&(d=i.usage.cache_read_input_tokens),i.usage.cache_creation_input_tokens&&(k=i.usage.cache_creation_input_tokens));break}case"message_start":{g=i.message.usage.input_tokens,f=i.message.usage.output_tokens,d=i.message.usage.cache_read_input_tokens??0,k=i.message.usage.cache_creation_input_tokens??0;break}}yield{type:"stream_end",stopReason:E,usage:{inputTokens:g,outputTokens:f,cacheReadInputTokens:d,cacheCreationInputTokens:k}}}catch(l){throw x.error({err:l},"llm operation failed"),tt(l)}}};function Z(o){for(let t=o.length-1;t>=0;t--){if(o[t].role!=="user")continue;let e=o[t].content;if(typeof e=="string"&&e.length===0||Array.isArray(e)&&e.length===0)return;typeof e=="string"&&(e=o[t].content=[{type:"text",text:e}]);let n=e[e.length-1];for(let s=e.length-1;s>=0;s--)if(e[s].type!=="image"){n=e[s];break}Reflect.set(n,"cache_control",{type:"ephemeral"})}}function tt(o){if(o instanceof P.APIError){if(o.status===413||/prompts?\s+too\s+long/i.test(o.message))return new G(`Prompt too long: ${o.message}`);if(o.status===401)return new M(`Invalid API key: ${o.message}`);if(o.status===429){let t=I(o.headers)["retry-after"],e="Rate Limited";if(t){let n=Number.parseInt(_(t));Number.isNaN(n)&&(e+=", please wait."),e+=`, retry after ${_(n)}s.`}else e+=", please wait.";return new W(e,t?_(t):void 0)}return new K(`Anthropic API error (${_(o.status)}): ${o.message}`)}return new F(`Network error: ${U(o)}`)}export{q as AnthropicClient,X as buildAnthropicMessages,pt as fetchModelContextWindow,Z as markLastUserTailForCache,D as markToolsForCache,J as needsToolSearchBeta};
4
+ import{a as $}from"./chunk-HJIGA37J.js";import{g as P}from"./chunk-H7VXSMJR.js";import{k as C}from"./chunk-YQQVB6VB.js";import{e as H,g as Y,h as R}from"./chunk-NLNH3IRT.js";import{b as N,c as K,d as M,e as W,f as F,g as G}from"./chunk-FZPTNGTU.js";import"./chunk-ZZQE743W.js";import"./chunk-7MHXMDYC.js";import{C as w,I as O,J as v,K as j,L as B,M as I,N as _,O as U,g as L}from"./chunk-LX2LK3TF.js";import"./chunk-E55KH72M.js";import"./chunk-X3UA5OZL.js";function D(o){for(let t=o.length-1;t>=0;t--){let e=o[t];if(e.defer_loading!==!0){e.cache_control={type:"ephemeral"};return}}}function J(o){return o.some(t=>t.defer_loading)}var x=O({module:"llm"});var z=3e3,V=w.object({max_input_tokens:w.coerce.number()});async function pt(o){if(o.protocol!=="anthropic")return 0;let t=R(o),n=`${o.base_url.replace(/\/+$/,"")}/v1/models/${encodeURIComponent(o.model)}`,s=new AbortController,r=setTimeout(()=>{s.abort()},z);try{let c=await fetch(n,{method:"GET",headers:{"anthropic-version":"2023-06-01",...t?{"x-api-key":t}:{}},signal:s.signal});if(!c.ok)return 0;let h=await c.json(),{success:g,error:f,data:d}=await L(V,h);if(!g)return x.warn({message:f.message},"model context window schema validation failed"),0;let k=d.max_input_tokens;return Math.max(k,0)}catch(c){return x.error({err:c},"failed to fetch model context window"),0}finally{clearTimeout(r)}}function Q(){return!0}function S(o){return typeof o=="string"?[{type:"text",text:o}]:o}function X(o){let t=[];for(let e of o)if(e.role==="assistant"){let n=[];if(e.thinkingBlocks)for(let r of e.thinkingBlocks)n.push({type:"thinking",thinking:r.thinking,signature:r.signature});let s=typeof e.content=="string"?e.content:j(e.content);if(s&&n.push({type:"text",text:s}),e.toolUses)for(let r of e.toolUses)n.push({type:"tool_use",id:r.toolUseId,name:r.toolName,input:r.arguments});n.length===0&&n.push({type:"text",text:""}),t.push({role:"assistant",content:n})}else if(e.toolResults&&e.toolResults.length>0){let n=[];for(let s of e.toolResults)n.push({type:"tool_result",tool_use_id:s.toolUseId,is_error:s.isError,content:s.content});t.push({role:"user",content:n})}else{if(t.length===0){t.push({role:"user",content:S(e.content)});continue}let n=!1,s=t[t.length-1],r=s.content;s.role==="user"&&(typeof r=="string"||Array.isArray(r)&&r.length>0&&(r[0].type==="text"||r[0].type==="image"))&&(n=!0),n?(typeof r=="string"&&(r=s.content=r.trim().length>0?[{type:"text",text:r}]:[]),r.push(...S(e.content))):t.push({role:"user",content:S(e.content)})}return t}var q=class{client;model;thinking;systemPrompt;maxOutputTokens;contextWindow;constructor(t,e){let n=R(t);if(!n)throw new M("Anthropic API key not found, set ANTHROPIC_API_KEY in .swifty/config.y(a)ml, or via ANTHROPIC_API_KEY env variable.");this.client=new P({apiKey:n,baseURL:t.base_url}),this.model=t.model,this.thinking=t.thinking??!0,this.systemPrompt=e,this.maxOutputTokens=Y(t),this.contextWindow=H(t)}setSystemPrompt(t){this.systemPrompt=t}setMaxOutputTokens(t){this.maxOutputTokens=t}async*stream(t,e,n){let s=X(N(t.getMessages())),r=J(e),c=e.map(l=>{let p=l.input_schema,u={name:l.name,description:l.description,input_schema:{type:"object",properties:p.properties,required:p.required??[]}};return l.defer_loading===!0&&(u.defer_loading=!0),u});D(c),Z(s);let h={model:this.model,max_tokens:this.maxOutputTokens,stream:!0,system:[{type:"text",text:this.systemPrompt,cache_control:{type:"ephemeral"}}],messages:s,...c.length>0?{tools:c}:{}};this.thinking?Q()&&(h.thinking={type:"enabled",budget_tokens:C(this.contextWindow,this.maxOutputTokens)}):h.thinking={type:"enabled",budget_tokens:C(this.contextWindow,this.maxOutputTokens)};let g=0,f=0,d=0,k=0,E="end_turn",T="",b="",A=!1;try{let l=this.client.messages.stream(h,{...n?{signal:n}:{},...r?{headers:{"anthropic-beta":$}}:{}}),p="",u="",m="";for await(let i of l)switch(i.type){case"content_block_start":{let a=i.content_block;a.type==="thinking"?(A=!0,T="",b=""):a.type==="tool_use"&&(u=a.id,p=a.name,m="",yield{type:"tool_call_start",toolName:p,toolId:u});break}case"content_block_delta":{let a=i.delta;a.type==="thinking_delta"?(T+=a.thinking,yield{type:"thinking_delta",text:a.thinking}):a.type==="signature_delta"?b=a.signature:a.type==="text_delta"?yield{type:"text_delta",text:a.text}:a.type==="input_json_delta"&&(m+=a.partial_json,yield{type:"tool_call_delta",text:a.partial_json});break}case"content_block_stop":{if(A&&(yield{type:"thinking_complete",thinking:T,signature:b},A=!1),p){let a={};if(m)try{let y=JSON.parse(m);a=B(y)?I(y):{[v]:m}}catch(y){x.error({err:y},"llm operation failed"),a={[v]:m}}yield{type:"tool_call_complete",toolId:u,toolName:p,arguments:a},p="",u="",m=""}break}case"message_delta":{i.delta.stop_reason&&(E=i.delta.stop_reason),i.usage.output_tokens&&(f=i.usage.output_tokens,i.usage.input_tokens&&(g=i.usage.input_tokens),i.usage.cache_read_input_tokens&&(d=i.usage.cache_read_input_tokens),i.usage.cache_creation_input_tokens&&(k=i.usage.cache_creation_input_tokens));break}case"message_start":{g=i.message.usage.input_tokens,f=i.message.usage.output_tokens,d=i.message.usage.cache_read_input_tokens??0,k=i.message.usage.cache_creation_input_tokens??0;break}}yield{type:"stream_end",stopReason:E,usage:{inputTokens:g,outputTokens:f,cacheReadInputTokens:d,cacheCreationInputTokens:k}}}catch(l){throw x.error({err:l},"llm operation failed"),tt(l)}}};function Z(o){for(let t=o.length-1;t>=0;t--){if(o[t].role!=="user")continue;let e=o[t].content;if(typeof e=="string"&&e.length===0||Array.isArray(e)&&e.length===0)return;typeof e=="string"&&(e=o[t].content=[{type:"text",text:e}]);let n=e[e.length-1];for(let s=e.length-1;s>=0;s--)if(e[s].type!=="image"){n=e[s];break}Reflect.set(n,"cache_control",{type:"ephemeral"})}}function tt(o){if(o instanceof P.APIError){if(o.status===413||/prompts?\s+too\s+long/i.test(o.message))return new G(`Prompt too long: ${o.message}`);if(o.status===401)return new M(`Invalid API key: ${o.message}`);if(o.status===429){let t=I(o.headers)["retry-after"],e="Rate Limited";if(t){let n=Number.parseInt(_(t));Number.isNaN(n)&&(e+=", please wait."),e+=`, retry after ${_(n)}s.`}else e+=", please wait.";return new W(e,t?_(t):void 0)}return new K(`Anthropic API error (${_(o.status)}): ${o.message}`)}return new F(`Network error: ${U(o)}`)}export{q as AnthropicClient,X as buildAnthropicMessages,pt as fetchModelContextWindow,Z as markLastUserTailForCache,D as markToolsForCache,J as needsToolSearchBeta};
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire as __swiftyCreateRequire } from "node:module";
3
+ const require = __swiftyCreateRequire(import.meta.url);
4
+ import{a,b,c,d,e,f}from"./chunk-GUXBLUNR.js";import"./chunk-ZZQE743W.js";import"./chunk-7MHXMDYC.js";import"./chunk-LX2LK3TF.js";import"./chunk-E55KH72M.js";import"./chunk-X3UA5OZL.js";export{b as PathSandbox,f as PermissionChecker,d as RuleEngine,c as evaluateRules,a as extractContent,e as isSafeCommand};
@@ -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{c as F}from"./chunk-P276SKAC.js";import{a as y}from"./chunk-7MHXMDYC.js";import{D as d,I as D,S as c,e as x}from"./chunk-ZM2V2A7B.js";import{b as k}from"./chunk-E55KH72M.js";import{readFileSync as _,writeFileSync as j,mkdirSync as M,statSync as $}from"fs";import{homedir as C,tmpdir as L}from"os";import{join as p,resolve as f,dirname as A}from"path";var E=D({module:"permissions"}),T=[],z=["ls","pwd","echo","cat","head","tail","wc","date","whoami","uname","hostname","which","type","file","git status","git log","git diff","git branch","git show","git rev-parse","git remote","bun test","bun run","npm test","npm run","go test","go build","go vet","python -c","node -e"],O={Bash:"command",PowerShell:"command",ReadFile:"file_path",WriteFile:"file_path",EditFile:"file_path",Glob:"pattern",Grep:"pattern"},Y=[".swifty/config.yaml",".swifty/permissions.local.yaml",".swifty/skills/"];function w(r,e){if(r===k)return F(c(e,"server",""),c(e,"tool",""));let t=O[r];if(!t)return"";let s=e[t];return typeof s=="string"?s:""}var R=class{allowedRoots;denyWritePaths;projectDir;constructor(e){this.projectDir=f(e),this.allowedRoots=[this.projectDir,L()],this.denyWritePaths=Y.map(t=>p(this.projectDir,t))}addRoot(e){this.allowedRoots.push(f(e))}addDenyWrite(e){this.denyWritePaths.push(f(e))}checkDenyWrite(e){let t=f(e);for(let s of this.denyWritePaths)if(t.startsWith(s))return{effect:"deny",reason:`Path ${e} is in deny-write list`};return null}check(e){let t=f(e);for(let s of this.allowedRoots)if(t.startsWith(s))return null;return{effect:"deny",reason:`Path ${e} is outside allowed directories`}}};function B(r,e){let t="^"+r.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,".")+"$";try{return new RegExp(t).test(e)}catch(s){return E.error({err:s},"permissions operation failed"),!1}}var G=/^(\w+)\((.+)\)$/;function S(r){let e;try{e=_(r,"utf-8")}catch(n){return n.code!=="ENOENT"&&E.error({err:n},"permissions operation failed"),[]}let t=d.object({rule:d.string().optional(),effect:d.string().optional()}),s;try{let n=y.load(e);s=x(d.array(t),n)}catch(n){return E.error({err:n},"permissions operation failed"),[]}let i=[];for(let n of s){if(n.effect!=="allow"&&n.effect!=="deny"&&n.effect!=="ask")continue;let o=G.exec((n.rule??"").trim());o&&i.push({tool:o[1],pattern:o[2],effect:n.effect})}return i}function b(r,e,t){let s=null;for(let i of r)if(!(i.tool!==e&&i.tool!=="*")&&B(i.pattern,t)){if(i.effect==="deny")return"deny";i.effect==="ask"?s="ask":s??="allow"}return s}var P=class{userPath;projectPath;localPath;cache=new Map;constructor(e){this.userPath=p(C(),".swifty","permissions.yaml"),this.projectPath=p(e,".swifty","permissions.yaml"),this.localPath=p(e,".swifty","permissions.local.yaml")}rulesFor(e){let t;try{t=$(e,{bigint:!0})}catch{return this.cache.delete(e),[]}let s=this.cache.get(e);if(s?.mtimeNs===t.mtimeNs&&s.size===t.size)return s.rules;let i=S(e);return this.cache.set(e,{mtimeNs:t.mtimeNs,size:t.size,rules:i}),i}snapshot(){return[this.userPath,this.projectPath,this.localPath].flatMap(e=>this.rulesFor(e))}evaluate(e,t){return b(this.snapshot(),e,t)}appendLocalRule(e){M(A(this.localPath),{recursive:!0});let t=S(this.localPath);if(t.some(n=>n.tool===e.tool&&n.pattern===e.pattern&&n.effect===e.effect))return;t.push(e);let i=t.map(n=>({rule:`${n.tool}(${n.pattern})`,effect:n.effect}));j(this.localPath,y.dump(i),"utf-8")}};function I(r){for(let e of T)if(e.re.test(r))return e.reason;return""}function N(r){let e=r.trim();return e.includes(">")||e.includes("|")||e.includes(";")||e.includes("&&")||e.includes("$(")||e.includes("`")?!1:z.some(t=>e===t||e.startsWith(t+" ")||e.startsWith(t+" "))}function U(r,e){switch(r){case"bypassPermissions":return"allow";case"plan":return e==="read"?"allow":"ask";case"acceptEdits":return e==="command"?"ask":"allow";default:return e==="read"?"allow":"ask"}}var W=class{mode;planFilePath="";sandboxEnabled=!1;sandboxAutoAllow=!1;sandbox;ruleEngine;constructor(e,t="default"){this.mode=t,this.sandbox=new R(e),this.ruleEngine=new P(e)}check(e,t,s){let i=w(e,s),n=null,o=()=>n??=this.ruleEngine.snapshot();if(this.mode==="plan"&&(e==="WriteFile"||e==="EditFile")&&c(s,"file_path","").includes(".swifty/plans/"))return{effect:"allow",reason:"Plan file write allowed in plan mode"};if(t==="command"&&N(i))return{effect:"allow",reason:"Safe read-only command"};let a=t==="command"?I(i):"";if(a)return{effect:"deny",reason:`Dangerous command blocked: ${a}`};if(this.sandboxEnabled&&this.sandboxAutoAllow&&e==="Bash"){let u=c(s,"command").split(/\s*(?:&&|\|\||[;|])\s*/).map(g=>g.trim()).filter(Boolean),l=!1;for(let g of u){let v=b(o(),e,g);if(v==="deny")return{effect:"deny",reason:"Permission rule: deny"};v==="ask"&&(l=!0)}return l?{effect:"ask",reason:"Permission rule: ask (sandbox does not override)"}:{effect:"allow",reason:"Sandbox auto-allow: OS sandbox active"}}let h=c(s,"file_path",c(s,"path",""));if((t==="read"||t==="write")&&h){if(t==="write"){let l=this.sandbox.checkDenyWrite(h);if(l)return l}let u=this.sandbox.check(h);if(u&&this.mode!=="bypassPermissions"){let l=this.ruleEngine.evaluate(e,i);return l?{effect:l,reason:`Permission rule: ${l}`}:{effect:"ask",reason:u.reason}}}let m=b(o(),e,i);return m?{effect:m,reason:`Permission rule: ${m}`}:{effect:U(this.mode,t),reason:`Mode: ${this.mode}`}}allowExtraRoot(e){this.sandbox.addRoot(e)}allowAlways(e,t){let s=w(e,t),i=e==="ReadFile"||e==="WriteFile"||e==="EditFile",n;if(i&&s){let o=f(s),a=!1;try{a=$(o).isDirectory()}catch{}n=p(a?o:A(o),"*")}else n=s.trim().split(/\s+/).slice(0,2).join(" ")+"*";this.ruleEngine.appendLocalRule({tool:e,pattern:n,effect:"allow"})}describeToolAction(e,t){let s=w(e,t);if(s)return s;let i=[];for(let[n,o]of Object.entries(t)){let a=String(o);a.length>80&&(a=a.slice(0,80)+"..."),i.push(`${n}: ${a}`)}return i.join(", ")}};export{w as a,R as b,b as c,P as d,W as e};
4
+ import{c as F}from"./chunk-ZZQE743W.js";import{a as y}from"./chunk-7MHXMDYC.js";import{D as d,I as D,S as c,e as v}from"./chunk-LX2LK3TF.js";import{b as k}from"./chunk-E55KH72M.js";import{readFileSync as _,writeFileSync as j,mkdirSync as M,statSync as $}from"fs";import{homedir as C,tmpdir as L}from"os";import{join as p,resolve as f,dirname as A}from"path";var E=D({module:"permissions"}),T=[],z=["ls","pwd","echo","cat","head","tail","wc","date","whoami","uname","hostname","which","type","file","git status","git log","git diff","git branch","git show","git rev-parse","git remote","bun test","bun run","npm test","npm run","go test","go build","go vet","python -c","node -e"],O={Bash:"command",PowerShell:"command",ReadFile:"file_path",WriteFile:"file_path",EditFile:"file_path",Glob:"pattern",Grep:"pattern"},Y=[".swifty/config.yaml",".swifty/permissions.local.yaml",".swifty/skills/"];function w(i,e){if(i===k)return F(c(e,"server",""),c(e,"tool",""));let t=O[i];if(!t)return"";let s=e[t];return typeof s=="string"?s:""}var R=class{allowedRoots;denyWritePaths;projectDir;constructor(e){this.projectDir=f(e),this.allowedRoots=[this.projectDir,L()],this.denyWritePaths=Y.map(t=>p(this.projectDir,t))}addRoot(e){this.allowedRoots.push(f(e))}addDenyWrite(e){this.denyWritePaths.push(f(e))}checkDenyWrite(e){let t=f(e);for(let s of this.denyWritePaths)if(t.startsWith(s))return{effect:"deny",reason:`Path ${e} is in deny-write list`};return null}check(e){let t=f(e);for(let s of this.allowedRoots)if(t.startsWith(s))return null;return{effect:"deny",reason:`Path ${e} is outside allowed directories`}}};function B(i,e){let t="^"+i.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,".")+"$";try{return new RegExp(t).test(e)}catch(s){return E.error({err:s},"permissions operation failed"),!1}}var G=/^(\w+)\((.+)\)$/;function S(i){let e;try{e=_(i,"utf-8")}catch(n){return n.code!=="ENOENT"&&E.error({err:n},"permissions operation failed"),[]}let t=d.object({rule:d.string().optional(),effect:d.string().optional()}),s;try{let n=y.load(e);s=v(d.array(t),n)}catch(n){return E.error({err:n},"permissions operation failed"),[]}let r=[];for(let n of s){if(n.effect!=="allow"&&n.effect!=="deny"&&n.effect!=="ask")continue;let o=G.exec((n.rule??"").trim());o&&r.push({tool:o[1],pattern:o[2],effect:n.effect})}return r}function b(i,e,t){let s=null;for(let r of i)if(!(r.tool!==e&&r.tool!=="*")&&B(r.pattern,t)){if(r.effect==="deny")return"deny";r.effect==="ask"?s="ask":s??="allow"}return s}var P=class{userPath;projectPath;localPath;cache=new Map;constructor(e){this.userPath=p(C(),".swifty","permissions.yaml"),this.projectPath=p(e,".swifty","permissions.yaml"),this.localPath=p(e,".swifty","permissions.local.yaml")}rulesFor(e){let t;try{t=$(e,{bigint:!0})}catch{return this.cache.delete(e),[]}let s=this.cache.get(e);if(s?.mtimeNs===t.mtimeNs&&s.size===t.size)return s.rules;let r=S(e);return this.cache.set(e,{mtimeNs:t.mtimeNs,size:t.size,rules:r}),r}snapshot(){return[this.userPath,this.projectPath,this.localPath].flatMap(e=>this.rulesFor(e))}evaluate(e,t){return b(this.snapshot(),e,t)}appendLocalRule(e){M(A(this.localPath),{recursive:!0});let t=S(this.localPath);if(t.some(n=>n.tool===e.tool&&n.pattern===e.pattern&&n.effect===e.effect))return;t.push(e);let r=t.map(n=>({rule:`${n.tool}(${n.pattern})`,effect:n.effect}));j(this.localPath,y.dump(r),"utf-8")}};function I(i){for(let e of T)if(e.re.test(i))return e.reason;return""}function N(i){let e=i.trim();return e.includes(">")||e.includes("|")||e.includes(";")||e.includes("&&")||e.includes("$(")||e.includes("`")?!1:z.some(t=>e===t||e.startsWith(t+" ")||e.startsWith(t+" "))}function U(i,e){switch(i){case"bypassPermissions":return"allow";case"plan":return e==="read"?"allow":"ask";case"acceptEdits":return e==="command"?"ask":"allow";default:return e==="read"?"allow":"ask"}}var W=class{mode;planFilePath="";sandboxEnabled=!1;sandboxAutoAllow=!1;sandbox;ruleEngine;constructor(e,t="default"){this.mode=t,this.sandbox=new R(e),this.ruleEngine=new P(e)}check(e,t,s){let r=w(e,s),n=null,o=()=>n??=this.ruleEngine.snapshot();if(this.mode==="plan"&&(e==="WriteFile"||e==="EditFile")&&c(s,"file_path","").includes(".swifty/plans/"))return{effect:"allow",reason:"Plan file write allowed in plan mode"};if(t==="command"&&N(r))return{effect:"allow",reason:"Safe read-only command"};let a=t==="command"?I(r):"";if(a)return{effect:"deny",reason:`Dangerous command blocked: ${a}`};if(this.sandboxEnabled&&this.sandboxAutoAllow&&e==="Bash"){let u=c(s,"command").split(/\s*(?:&&|\|\||[;|])\s*/).map(g=>g.trim()).filter(Boolean),l=!1;for(let g of u){let x=b(o(),e,g);if(x==="deny")return{effect:"deny",reason:"Permission rule: deny"};x==="ask"&&(l=!0)}return l?{effect:"ask",reason:"Permission rule: ask (sandbox does not override)"}:{effect:"allow",reason:"Sandbox auto-allow: OS sandbox active"}}let h=c(s,"file_path",c(s,"path",""));if((t==="read"||t==="write")&&h){if(t==="write"){let l=this.sandbox.checkDenyWrite(h);if(l)return l}let u=this.sandbox.check(h);if(u&&this.mode!=="bypassPermissions"){let l=this.ruleEngine.evaluate(e,r);return l?{effect:l,reason:`Permission rule: ${l}`}:{effect:"ask",reason:u.reason}}}let m=b(o(),e,r);return m?{effect:m,reason:`Permission rule: ${m}`}:{effect:U(this.mode,t),reason:`Mode: ${this.mode}`}}allowExtraRoot(e){this.sandbox.addRoot(e)}allowAlways(e,t){let s=w(e,t),r=e==="ReadFile"||e==="WriteFile"||e==="EditFile",n;if(r&&s){let o=f(s),a=!1;try{a=$(o).isDirectory()}catch{}n=p(a?o:A(o),"*")}else n=s.trim().split(/\s+/).slice(0,2).join(" ")+"*";this.ruleEngine.appendLocalRule({tool:e,pattern:n,effect:"allow"})}describeToolAction(e,t){let s=w(e,t);if(s)return s;let r=[];for(let[n,o]of Object.entries(t)){let a=String(o);a.length>80&&(a=a.slice(0,80)+"..."),r.push(`${n}: ${a}`)}return r.join(", ")}};export{w as a,R as b,b as c,P as d,N as e,W as f};
@@ -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 i,d as s}from"./chunk-P276SKAC.js";var a=10,p=2.5,E="advanced-tool-use-2025-11-20",f=new Set(["api.anthropic.com"]),d="SWIFTY_MCP_LOADING";function u(o){if(!o)return!0;try{return f.has(new URL(o).hostname.toLowerCase())}catch{return!1}}function l(o){return Math.floor(o/p)}function m(o,t,e,n=a){let r=(process.env[d]??"").trim().toLowerCase();if(r==="eager"||r==="native"||r==="dispatch")return r;if(e<=0)return"eager";let c=t*n/100;return l(e)<c?"eager":u(o)?"native":"dispatch"}function g(o){let t=0;for(let e of o.listTools())if(e.name.startsWith(i))try{t+=JSON.stringify(e.schema()).length}catch{t+=e.name.length+(e.description?.length??0)}return t}function T(o,t){o.mcpLoadingMode=t;let e=t==="eager";for(let n of o.listTools())s(n)&&typeof n.setDeferLoading=="function"&&n.setDeferLoading(!e);o.exposeToolSearch=!e,o.exposeMcpCall=t==="dispatch"}function M(o,t,e){let n=m(t,e,g(o));return T(o,n),n}export{E as a,M as b};
4
+ import{a as i,d as s}from"./chunk-ZZQE743W.js";var a=10,p=2.5,E="advanced-tool-use-2025-11-20",f=new Set(["api.anthropic.com"]),d="SWIFTY_MCP_LOADING";function u(o){if(!o)return!0;try{return f.has(new URL(o).hostname.toLowerCase())}catch{return!1}}function l(o){return Math.floor(o/p)}function m(o,t,e,n=a){let r=(process.env[d]??"").trim().toLowerCase();if(r==="eager"||r==="native"||r==="dispatch")return r;if(e<=0)return"eager";let c=t*n/100;return l(e)<c?"eager":u(o)?"native":"dispatch"}function g(o){let t=0;for(let e of o.listTools())if(e.name.startsWith(i))try{t+=JSON.stringify(e.schema()).length}catch{t+=e.name.length+(e.description?.length??0)}return t}function T(o,t){o.mcpLoadingMode=t;let e=t==="eager";for(let n of o.listTools())s(n)&&typeof n.setDeferLoading=="function"&&n.setDeferLoading(!e);o.exposeToolSearch=!e,o.exposeMcpCall=t==="dispatch"}function M(o,t,e){let n=m(t,e,g(o));return T(o,n),n}export{E as a,T as b,M as c};