@swifty.js/swifty 0.0.8 → 0.0.9
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/LICENSE +21 -0
- package/dist/{agent-RLJIJPPZ.js → agent-4K4HNCSZ.js} +1 -1
- package/dist/anthropic-DFGYPMNW.js +4 -0
- package/dist/bwrap-TPE6G4BM.js +0 -0
- package/dist/{checker-AVYJSHE3.js → checker-DWBNQC3N.js} +1 -1
- package/dist/{chunk-ZSJ2I5WM.js → chunk-2BJOFNPI.js} +1 -1
- package/dist/chunk-7MHXMDYC.js +0 -0
- package/dist/{chunk-BDSARQW3.js → chunk-D5QSJBKQ.js} +80 -80
- package/dist/chunk-FZPTNGTU.js +0 -0
- package/dist/chunk-H7VXSMJR.js +0 -0
- package/dist/chunk-MQ5XOYLD.js +0 -0
- package/dist/chunk-OKI2P5FO.js +126 -0
- package/dist/{chunk-LVLDD2BE.js → chunk-OZOP4GVS.js} +1 -1
- package/dist/chunk-SM5OVMF6.js +235 -0
- package/dist/chunk-UBV5T4TV.js +0 -0
- package/dist/chunk-X3UA5OZL.js +0 -0
- package/dist/chunk-XBHVVB5A.js +0 -0
- package/dist/{chunk-ISXLT3QN.js → chunk-XYSBNUNB.js} +19 -18
- package/dist/cleanup-BQJDUOKA.js +0 -0
- package/dist/devtools-3OAJUZGE.js +0 -0
- package/dist/glob_addon.node +0 -0
- package/dist/main.js +187 -187
- package/dist/node-OES65R33.js +0 -0
- package/dist/{openai-SMJX34AX.js → openai-NMDB34GN.js} +15 -15
- package/dist/seatbelt-YXUQ5XR3.js +0 -0
- package/dist/{server-LIBUDDHX.js → server-RSZ4T7JZ.js} +17 -17
- package/dist/tool-filter-ERUPKZYV.js +0 -0
- package/package.json +26 -29
- package/dist/anthropic-GAI75HYJ.js +0 -4
- package/dist/chunk-A6H62GTA.js +0 -235
- package/dist/chunk-OXEMDMZF.js +0 -129
- package/dist/release-OQD3IZ5W.js +0 -4
- package/dist/release.wasm +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 hangtiancheng
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -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{
|
|
4
|
+
import{h as a}from"./chunk-SM5OVMF6.js";import"./chunk-OKI2P5FO.js";import"./chunk-FZPTNGTU.js";import"./chunk-XYSBNUNB.js";import"./chunk-MQ5XOYLD.js";import"./chunk-X3UA5OZL.js";export{a as Agent};
|
|
@@ -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{g as P}from"./chunk-H7VXSMJR.js";import{l as C}from"./chunk-OKI2P5FO.js";import{e as F,g as G,h as R}from"./chunk-OZOP4GVS.js";import{b as O,c as $,d as I,e as K,f as W,g as D}from"./chunk-FZPTNGTU.js";import"./chunk-7MHXMDYC.js";import{C as w,I as N,J as v,K as j,L as B,M,N as k,O as U,g as S}from"./chunk-XYSBNUNB.js";import"./chunk-MQ5XOYLD.js";import"./chunk-X3UA5OZL.js";var x=N({module:"llm"});var Y=3e3,q=w.object({max_input_tokens:w.coerce.number()});async function at(o){if(o.protocol!=="anthropic")return 0;let e=R(o),n=`${o.base_url.replace(/\/+$/,"")}/v1/models/${encodeURIComponent(o.model)}`,r=new AbortController,s=setTimeout(()=>{r.abort()},Y);try{let l=await fetch(n,{method:"GET",headers:{"anthropic-version":"2023-06-01",...e?{"x-api-key":e}:{}},signal:r.signal});if(!l.ok)return 0;let g=await l.json(),{success:h,error:f,data:d}=await S(q,g);if(!h)return console.error(f.message),0;let y=d.max_input_tokens;return Math.max(y,0)}catch(l){return console.error(l),0}finally{clearTimeout(s)}}function J(){return!0}function L(o){return typeof o=="string"?[{type:"text",text:o}]:o}function z(o){let e=[];for(let t of o)if(t.role==="assistant"){let n=[];if(t.thinkingBlocks)for(let s of t.thinkingBlocks)n.push({type:"thinking",thinking:s.thinking,signature:s.signature});let r=typeof t.content=="string"?t.content:j(t.content);if(r&&n.push({type:"text",text:r}),t.toolUses)for(let s of t.toolUses)n.push({type:"tool_use",id:s.toolUseId,name:s.toolName,input:s.arguments});n.length===0&&n.push({type:"text",text:""}),e.push({role:"assistant",content:n})}else if(t.toolResults&&t.toolResults.length>0){let n=[];for(let r of t.toolResults)n.push({type:"tool_result",tool_use_id:r.toolUseId,is_error:r.isError,content:r.content});e.push({role:"user",content:n})}else{if(e.length===0){e.push({role:"user",content:L(t.content)});continue}let n=!1,r=e[e.length-1],s=r.content;r.role==="user"&&(typeof s=="string"||Array.isArray(s)&&s.length>0&&(s[0].type==="text"||s[0].type==="image"))&&(n=!0),n?(typeof s=="string"&&(s=r.content=s.trim().length>0?[{type:"text",text:s}]:[]),s.push(...L(t.content))):e.push({role:"user",content:L(t.content)})}return e}var H=class{client;model;thinking;systemPrompt;maxOutputTokens;contextWindow;constructor(e,t){let n=R(e);if(!n)throw new I("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:e.base_url}),this.model=e.model,this.thinking=e.thinking??!0,this.systemPrompt=t,this.maxOutputTokens=G(e),this.contextWindow=F(e)}setSystemPrompt(e){this.systemPrompt=e}setMaxOutputTokens(e){this.maxOutputTokens=e}async*stream(e,t,n){let r=z(O(e.getMessages())),s=t.map(c=>{let p=c.input_schema;return{name:c.name,description:c.description,input_schema:{type:"object",properties:p.properties,required:p.required??[]}}});s.length>0&&(s[s.length-1].cache_control={type:"ephemeral"}),Q(r);let l={model:this.model,max_tokens:this.maxOutputTokens,stream:!0,system:[{type:"text",text:this.systemPrompt,cache_control:{type:"ephemeral"}}],messages:r,...s.length>0?{tools:s}:{}};this.thinking?J()&&(l.thinking={type:"enabled",budget_tokens:C(this.contextWindow,this.maxOutputTokens)}):l.thinking={type:"enabled",budget_tokens:C(this.contextWindow,this.maxOutputTokens)};let g=0,h=0,f=0,d=0,y="end_turn",T="",b="",A=!1,E=0;try{let c=this.client.messages.stream(l,{...n?{signal:n}:{}}),p="",_="",u="";for await(let i of c)switch(i.type){case"content_block_start":{let a=i.content_block;a.type==="thinking"?(A=!0,T="",b=""):a.type==="tool_use"&&(_=a.id,p=a.name,u="",yield{type:"tool_call_start",toolName:p,toolId:_});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"?(x.debug({signature:a.signature},"thinking signature received"),b=a.signature):a.type==="text_delta"?yield{type:"text_delta",text:a.text}:a.type==="input_json_delta"&&(u+=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(u)try{let m=JSON.parse(u);a=B(m)?M(m):{[v]:u}}catch(m){x.error({err:m},"llm operation failed"),a={[v]:u}}yield{type:"tool_call_complete",toolId:_,toolName:p,arguments:a},p="",_="",u=""}break}case"message_delta":{i.delta.stop_reason&&(y=i.delta.stop_reason),i.usage.output_tokens&&(h=i.usage.output_tokens,i.usage.input_tokens&&(g=i.usage.input_tokens),i.usage.cache_read_input_tokens&&(f=i.usage.cache_read_input_tokens),i.usage.cache_creation_input_tokens&&(d=i.usage.cache_creation_input_tokens));break}case"message_start":{E=Date.now(),g=i.message.usage.input_tokens,h=i.message.usage.output_tokens,f=i.message.usage.cache_read_input_tokens??0,d=i.message.usage.cache_creation_input_tokens??0;break}case"message_stop":{let m=Date.now()-E;x.debug({elapsedMs:m},"message stream complete");break}}yield{type:"stream_end",stopReason:y,usage:{inputTokens:g,outputTokens:h,cacheReadInputTokens:f,cacheCreationInputTokens:d}}}catch(c){throw x.error({err:c},"llm operation failed"),V(c)}}};function Q(o){for(let e=o.length-1;e>=0;e--){if(o[e].role!=="user")continue;let t=o[e].content;if(typeof t=="string"&&t.length===0||Array.isArray(t)&&t.length===0)return;typeof t=="string"&&(t=o[e].content=[{type:"text",text:t}]);let n=t[t.length-1];for(let r=t.length-1;r>=0;r--)if(t[r].type!=="image"){n=t[r];break}Reflect.set(n,"cache_control",{type:"ephemeral"})}}function V(o){if(o instanceof P.APIError){if(o.status===413||/prompts?\s+too\s+long/i.test(o.message))return new D(`Prompt too long: ${o.message}`);if(o.status===401)return new I(`Invalid API key: ${o.message}`);if(o.status===429){let e=M(o.headers)["retry-after"],t="Rate Limited";if(e){let n=Number.parseInt(k(e));Number.isNaN(n)&&(t+=", please wait."),t+=`, retry after ${k(n)}s.`}else t+=", please wait.";return new K(t,e?k(e):void 0)}return new $(`Anthropic API error (${k(o.status)}): ${o.message}`)}return new W(`Network error: ${U(o)}`)}export{H as AnthropicClient,z as buildAnthropicMessages,at as fetchModelContextWindow,Q as markLastUserTailForCache};
|
package/dist/bwrap-TPE6G4BM.js
CHANGED
|
File without changes
|
|
@@ -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,b,c,d,e}from"./chunk-
|
|
4
|
+
import{a,b,c,d,e}from"./chunk-2BJOFNPI.js";import"./chunk-7MHXMDYC.js";import"./chunk-XYSBNUNB.js";import"./chunk-MQ5XOYLD.js";import"./chunk-X3UA5OZL.js";export{b as PathSandbox,e as PermissionChecker,d as RuleEngine,c as evaluateRules,a as extractContent};
|
|
@@ -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 w}from"./chunk-7MHXMDYC.js";import{D as u,I as D,
|
|
4
|
+
import{a as w}from"./chunk-7MHXMDYC.js";import{D as u,I as D,S as d,e as k}from"./chunk-XYSBNUNB.js";import{readFileSync as $,writeFileSync as j,mkdirSync as A,statSync as S}from"fs";import{homedir as _,tmpdir as M}from"os";import{join as h,resolve as l,dirname as W}from"path";var E=D({module:"permissions"}),T=[{re:/rm\s+(-rf?|--recursive)\s+[/~]/,reason:"recursive force delete root"},{re:/rm\s+-rf?\s+\*/,reason:"recursive force delete wildcard"},{re:/mkfs\./,reason:"format disk"},{re:/dd\s+if=/,reason:"direct write to disk device"},{re:/>\s*\/dev\/sd/,reason:"overwrite disk device"},{re:/chmod\s+-R?\s*777\s+\//,reason:"recursive chmod root"},{re:/:\(\)\{\s*:\|\s*:\s*&\s*\}\s*;/,reason:"fork bomb"},{re:/curl\s+.*\|\s*(ba)?sh/,reason:"pipe remote script"},{re:/wget\s+.*\|\s*(ba)?sh/,reason:"pipe remote script"},{re:/git\s+push\s+.*--force/,reason:"force push"},{re:/git\s+reset\s+--hard/,reason:"hard reset"},{re:/git\s+clean\s+-f/,reason:"force clean untracked files"},{re:/git\s+checkout\s+\./,reason:"discard all changes"},{re:/git\s+branch\s+-D/,reason:"force delete branch"}],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"],L={Bash:"command",ReadFile:"file_path",WriteFile:"file_path",EditFile:"file_path",Glob:"pattern",Grep:"pattern"},C=[".swifty/config.yaml",".swifty/permissions.local.yaml",".swifty/skills/"];function y(i,e){let t=L[i];if(!t)return"";let s=e[t];return typeof s=="string"?s:""}var R=class{allowedRoots;denyWritePaths;projectDir;constructor(e){this.projectDir=l(e),this.allowedRoots=[this.projectDir,M()],this.denyWritePaths=C.map(t=>h(this.projectDir,t))}addRoot(e){this.allowedRoots.push(l(e))}addDenyWrite(e){this.denyWritePaths.push(l(e))}checkDenyWrite(e){let t=l(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=l(e);for(let s of this.allowedRoots)if(t.startsWith(s))return null;return{effect:"deny",reason:`Path ${e} is outside allowed directories`}}};function O(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 Y=/^(\w+)\((.+)\)$/;function x(i){let e;try{e=$(i,"utf-8")}catch(r){return r.code!=="ENOENT"&&E.error({err:r},"permissions operation failed"),[]}let t=u.object({rule:u.string().optional(),effect:u.string().optional()}),s;try{let r=w.load(e);s=k(u.array(t),r)}catch(r){return E.error({err:r},"permissions operation failed"),[]}let n=[];for(let r of s){if(r.effect!=="allow"&&r.effect!=="deny"&&r.effect!=="ask")continue;let o=Y.exec((r.rule??"").trim());o&&n.push({tool:o[1],pattern:o[2],effect:r.effect})}return n}function b(i,e,t){let s=null;for(let n of i)if(!(n.tool!==e&&n.tool!=="*")&&O(n.pattern,t)){if(n.effect==="deny")return"deny";n.effect==="ask"?s="ask":s??="allow"}return s}var v=class{userPath;projectPath;localPath;cache=new Map;constructor(e){this.userPath=h(_(),".swifty","permissions.yaml"),this.projectPath=h(e,".swifty","permissions.yaml"),this.localPath=h(e,".swifty","permissions.local.yaml")}rulesFor(e){let t;try{t=S(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 n=x(e);return this.cache.set(e,{mtimeNs:t.mtimeNs,size:t.size,rules:n}),n}snapshot(){return[this.userPath,this.projectPath,this.localPath].flatMap(e=>this.rulesFor(e))}evaluate(e,t){return b(this.snapshot(),e,t)}appendLocalRule(e){A(W(this.localPath),{recursive:!0});let t=x(this.localPath);if(t.some(r=>r.tool===e.tool&&r.pattern===e.pattern&&r.effect===e.effect))return;t.push(e);let n=t.map(r=>({rule:`${r.tool}(${r.pattern})`,effect:r.effect}));j(this.localPath,w.dump(n),"utf-8")}};function N(i){for(let e of T)if(e.re.test(i))return e.reason;return""}function G(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 I(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 F=class{mode;planFilePath="";sandboxEnabled=!1;sandboxAutoAllow=!1;sandbox;ruleEngine;constructor(e,t="default"){this.mode=t,this.sandbox=new R(e),this.ruleEngine=new v(e)}check(e,t,s){let n=y(e,s),r=null,o=()=>r??=this.ruleEngine.snapshot();if(this.mode==="plan"&&(e==="WriteFile"||e==="EditFile")&&d(s,"file_path","").includes(".swifty/plans/"))return{effect:"allow",reason:"Plan file write allowed in plan mode"};if(t==="command"&&G(n))return{effect:"allow",reason:"Safe read-only command"};let a=t==="command"?N(n):"";if(a)return{effect:"deny",reason:`Dangerous command blocked: ${a}`};if(this.sandboxEnabled&&this.sandboxAutoAllow&&t==="command"){let f=d(s,"command").split(/\s*(?:&&|\|\||[;|])\s*/).map(g=>g.trim()).filter(Boolean),c=!1;for(let g of f){let P=b(o(),e,g);if(P==="deny")return{effect:"deny",reason:"Permission rule: deny"};P==="ask"&&(c=!0)}return c?{effect:"ask",reason:"Permission rule: ask (sandbox does not override)"}:{effect:"allow",reason:"Sandbox auto-allow: OS sandbox active"}}let p=d(s,"file_path",d(s,"path",""));if((t==="read"||t==="write")&&p){if(t==="write"){let c=this.sandbox.checkDenyWrite(p);if(c)return c}let f=this.sandbox.check(p);if(f&&this.mode!=="bypassPermissions"){let c=this.ruleEngine.evaluate(e,n);return c?{effect:c,reason:`Permission rule: ${c}`}:{effect:"ask",reason:f.reason}}}let m=b(o(),e,n);return m?{effect:m,reason:`Permission rule: ${m}`}:{effect:I(this.mode,t),reason:`Mode: ${this.mode}`}}allowExtraRoot(e){this.sandbox.addRoot(e)}allowAlways(e,t){let s=y(e,t),n=e==="ReadFile"||e==="WriteFile"||e==="EditFile",r;if(n&&s){let o=l(s),a=!1;try{a=S(o).isDirectory()}catch{}r=h(a?o:W(o),"*")}else r=s.trim().split(/\s+/).slice(0,2).join(" ")+"*";this.ruleEngine.appendLocalRule({tool:e,pattern:r,effect:"allow"})}describeToolAction(e,t){let s=y(e,t);if(s)return s;let n=[];for(let[r,o]of Object.entries(t)){let a=String(o);a.length>80&&(a=a.slice(0,80)+"..."),n.push(`${r}: ${a}`)}return n.join(", ")}};export{y as a,R as b,b as c,v as d,F as e};
|
package/dist/chunk-7MHXMDYC.js
CHANGED
|
File without changes
|