@swifty.js/swifty 0.0.6 → 0.0.7
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/{agent-MPIDW5VX.js → agent-RLJIJPPZ.js} +1 -1
- package/dist/{anthropic-25O6Y2EC.js → anthropic-GABA24KD.js} +1 -1
- package/dist/{checker-FDJ2Q62T.js → checker-AVYJSHE3.js} +1 -1
- package/dist/{chunk-IZ23BHLA.js → chunk-A6H62GTA.js} +55 -55
- package/dist/{chunk-HU7ELU2V.js → chunk-GS6BRESU.js} +1 -1
- package/dist/{chunk-4KVSJNS6.js → chunk-ISXLT3QN.js} +17 -17
- package/dist/chunk-N5AVRITT.js +351 -0
- package/dist/{chunk-DCI5RJC7.js → chunk-OXEMDMZF.js} +5 -5
- package/dist/{chunk-S2DPVNBA.js → chunk-ZSJ2I5WM.js} +1 -1
- package/dist/glob_addon.node +0 -0
- package/dist/main.js +235 -227
- package/dist/{openai-2MX6GD45.js → openai-GZSRO4RJ.js} +2 -2
- package/dist/{server-5MLD4AUW.js → server-EFD5B7YF.js} +10 -10
- package/package.json +2 -1
- package/dist/chunk-PAJWEPH7.js +0 -351
|
@@ -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{
|
|
4
|
+
import{D as i,I as y,N as U,e as M,f as A}from"./chunk-ISXLT3QN.js";var T=class{history=[];longTermMemoryInjected=!1;baselineTokens=0;_anchorCount=0;addUserMessage(e,s){this.history.push({role:"user",content:e,...s?.length?{images:s}:{}})}addAssistantMessage(e){this.history.push({role:"assistant",content:e})}addToolUseMessage(e,s,o,n){this.history.push({role:"assistant",content:e,toolUses:[{toolUseId:s,toolName:o,arguments:n}]})}addAssistantMessageWithTools(e,s){this.history.push({role:"assistant",content:e,toolUses:s})}addAssistantFull(e,s,o){this.history.push({role:"assistant",content:e,thinkingBlocks:s.length>0?s:void 0,toolUses:o.length>0?o:void 0})}addToolResultMessage(e,s,o){this.history.push({role:"user",content:"",toolResults:[{toolUseId:e,content:s,isError:o}]})}addToolResultsMessage(e){this.history.push({role:"user",content:"",toolResults:e})}addSystemReminder(e){this.history.push({role:"user",content:`<system-reminder>
|
|
5
5
|
${e}
|
|
6
6
|
</system-reminder>`})}injectLongTermMemory(e,s,o=""){if(this.longTermMemoryInjected)return;let n=[];if(e&&n.push(`# SWIFTY.md
|
|
7
7
|
Codebase and user instructions are shown below. Be sure to adhere to these instructions. IMPORTANT: These instructions OVERRIDE any default behavior and you MUST follow them exactly as written.
|
|
@@ -18,14 +18,14 @@ ${n.join(`
|
|
|
18
18
|
`)}
|
|
19
19
|
|
|
20
20
|
IMPORTANT: this context may or may not be relevant to your tasks. You should not respond to this context unless it is highly relevant to your task.
|
|
21
|
-
</system-reminder>`;this.history.unshift({role:"user",content:a}),this.longTermMemoryInjected=!0}len(){return this.history.length}truncateTo(e){e<0&&(e=0),!(e>this.history.length)&&(this.history=this.history.slice(0,e))}getMessages(){return[...this.history]}replaceWithCompacted(e,s){this.history=[{role:"user",content:e},...s],this.longTermMemoryInjected=!1,this.clearUsageAnchor()}recordUsageAnchor(e,s,o,n){let r=e+o+n+s;r<=0||(this.baselineTokens=r,this._anchorCount=this.history.length)}clearUsageAnchor(){this.baselineTokens=0,this._anchorCount=0}usageAnchorState(){return this.baselineTokens<=0?null:{baselineTokens:this.baselineTokens,anchorCount:this._anchorCount}}};import{createHash as Z}from"crypto";import{existsSync as ee,mkdirSync as te,readFileSync as se,writeFileSync as oe}from"fs";import{join as E}from"path";function P(t){if(t==="image/png"||t==="image/jpeg"||t==="image/gif"||t==="image/webp")return t;throw new Error(`Unsupported image media type: "${t}"`)}var j=y({module:"images"}),ne={"image/png":"png","image/jpeg":"jpg","image/gif":"gif","image/webp":"webp"};function re(t,e){return E(t,".swifty","sessions",e||"default","images")}function b(t,e,s){let o=re(t,e),n=[];for(let r of s)try{let l=Buffer.from(r.data,"base64"),a=Z("sha256").update(l).digest("hex").slice(0,16),c=ne[r.mediaType]??"png",u=E(o,`${a}.${c}`);ee(u)||(te(o,{recursive:!0}),oe(u,l)),n.push({path:u,media_type:r.mediaType,...r.sourcePath?{source_path:r.sourcePath}:{}})}catch(l){j.error({err:l},"failed to persist session image")}return n}function N(t){try{let e=se(t.path);return{mediaType:P(t.media_type),data:e.toString("base64"),sourcePath:t.source_path,byteLength:e.length}}catch(e){return j.warn({err:e,path:t.path},"failed to restore session image"),null}}import{readFileSync as L,writeFileSync as
|
|
22
|
-
[note: ${String(s)} image(s) from this message could not be restored]`:""}}var ge=i.object({summary:i.string(),keep:i.array(me)}),R=y({module:"session"});function S(t){return f(t,".swifty","sessions")}function Ve(t,e){return f(S(t),e+".jsonl")}function z(t){let e=k(t);if(!e.endsWith(".jsonl"))return null;let s=I(t),o=I(s);return k(s)!=="sessions"||k(o)!==".swifty"?null:{workDir:I(o),sessionId:e.slice(0,-6)}}function Qe(){let t=Date.now().toString(36),e=
|
|
23
|
-
`;
|
|
21
|
+
</system-reminder>`;this.history.unshift({role:"user",content:a}),this.longTermMemoryInjected=!0}len(){return this.history.length}truncateTo(e){e<0&&(e=0),!(e>this.history.length)&&(this.history=this.history.slice(0,e))}getMessages(){return[...this.history]}replaceWithCompacted(e,s){this.history=[{role:"user",content:e},...s],this.longTermMemoryInjected=!1,this.clearUsageAnchor()}recordUsageAnchor(e,s,o,n){let r=e+o+n+s;r<=0||(this.baselineTokens=r,this._anchorCount=this.history.length)}clearUsageAnchor(){this.baselineTokens=0,this._anchorCount=0}usageAnchorState(){return this.baselineTokens<=0?null:{baselineTokens:this.baselineTokens,anchorCount:this._anchorCount}}};import{createHash as Z}from"crypto";import{existsSync as ee,mkdirSync as te,readFileSync as se,writeFileSync as oe}from"fs";import{join as E}from"path";function P(t){if(t==="image/png"||t==="image/jpeg"||t==="image/gif"||t==="image/webp")return t;throw new Error(`Unsupported image media type: "${t}"`)}var j=y({module:"images"}),ne={"image/png":"png","image/jpeg":"jpg","image/gif":"gif","image/webp":"webp"};function re(t,e){return E(t,".swifty","sessions",e||"default","images")}function b(t,e,s){let o=re(t,e),n=[];for(let r of s)try{let l=Buffer.from(r.data,"base64"),a=Z("sha256").update(l).digest("hex").slice(0,16),c=ne[r.mediaType]??"png",u=E(o,`${a}.${c}`);ee(u)||(te(o,{recursive:!0}),oe(u,l)),n.push({path:u,media_type:r.mediaType,...r.sourcePath?{source_path:r.sourcePath}:{}})}catch(l){j.error({err:l},"failed to persist session image")}return n}function N(t){try{let e=se(t.path);return{mediaType:P(t.media_type),data:e.toString("base64"),sourcePath:t.source_path,byteLength:e.length}}catch(e){return j.warn({err:e,path:t.path},"failed to restore session image"),null}}import{randomBytes as ie}from"crypto";import{readFileSync as L,writeFileSync as ae,readdirSync as le,mkdirSync as ce,statSync as ue,existsSync as O,unlinkSync as Ke,rmSync as He}from"fs";import{basename as k,dirname as I,join as f}from"path";var x="compact_boundary";var D=i.object({tool_use_id:i.string(),tool_name:i.string(),arguments:i.record(i.string(),i.unknown()).optional()}),w=i.object({path:i.string(),media_type:i.string(),source_path:i.string().optional()}),F=i.object({tool_use_id:i.string(),content:i.string(),is_error:i.boolean().optional(),images:i.array(w).optional()}),$=i.object({role:i.string(),content:i.string().default(""),timestamp:i.number(),type:i.string().optional(),tool_uses:i.array(D).optional(),tool_results:i.array(F).optional(),images:i.array(w).optional()}),me=i.object({role:i.string(),content:i.string(),tool_uses:i.array(D).optional(),tool_results:i.array(F).optional(),images:i.array(w).optional()});function Y(t){return(t??[]).map(e=>({tool_use_id:e.toolUseId,tool_name:e.toolName,...e.arguments&&Object.keys(e.arguments).length?{arguments:e.arguments}:{}}))}function q(t,e){return(t??[]).map(s=>({tool_use_id:s.toolUseId,content:s.content,...s.isError?{is_error:!0}:{},...e&&s.images?.length?{images:b(e.workDir,e.sessionId,s.images)}:{}}))}function _(t){if(!t?.length)return{images:[],note:""};let e=[];for(let o of t){let n=N(o);n&&e.push(n)}let s=t.length-e.length;return{images:e,note:s>0?`
|
|
22
|
+
[note: ${String(s)} image(s) from this message could not be restored]`:""}}var ge=i.object({summary:i.string(),keep:i.array(me)}),R=y({module:"session"});function S(t){return f(t,".swifty","sessions")}function Ve(t,e){return f(S(t),e+".jsonl")}function z(t){let e=k(t);if(!e.endsWith(".jsonl"))return null;let s=I(t),o=I(s);return k(s)!=="sessions"||k(o)!==".swifty"?null:{workDir:I(o),sessionId:e.slice(0,-6)}}function Qe(){let t=Date.now().toString(36),e=ie(4).toString("hex");return`${t}-${e}`}function de(t,e,s){let o=S(t);ce(o,{recursive:!0});let n=f(o,`${e}.jsonl`),r=JSON.stringify(s)+`
|
|
23
|
+
`;ae(n,r,{flag:"a",encoding:"utf-8"})}function Ze(t,e,s){de(t,e,{role:"system",content:JSON.stringify(s),timestamp:Math.floor(Date.now()/1e3),type:x})}function et(t,e){let s=f(S(t),`${e}.jsonl`);if(!O(s))return[];let o=[];for(let n of L(s,"utf-8").split(`
|
|
24
24
|
`))if(n.trim())try{let r=JSON.parse(n),{success:l,data:a,error:c}=A($,r);l?!a.content&&!(a.tool_uses?.length??0)&&!(a.tool_results?.length??0)&&!(a.images?.length??0)||o.push(a):R.error({err:c},"session operation failed")}catch(r){R.error({err:r},"session operation failed")}return o}function K(t){return t?.map(e=>({toolUseId:e.tool_use_id,toolName:e.tool_name,arguments:e.arguments}))}function H(t){return t?.map(e=>{let s=_(e.images);return{toolUseId:e.tool_use_id,content:e.content+s.note,isError:e.is_error,...s.images.length?{images:s.images}:{}}})}function tt(t){let e=-1;for(let o=t.length-1;o>=0;o--)if(t[o].type===x){e=o;break}let s=[];if(e>=0){let o=null;try{let n=JSON.parse(t[e].content);o=M(ge,n)}catch{o=null}if(o){let n=`This session continues from a previous conversation, which has been compressed due to context limitations. Here is a summary of the earlier messages:
|
|
25
25
|
|
|
26
26
|
`+o.summary;o.keep.length>0&&(n+=`
|
|
27
27
|
|
|
28
|
-
Recent messages have been preserved verbatim.`),s.push({role:"user",content:n});for(let r of o.keep){if(r.role!=="user"&&r.role!=="assistant"||!r.content&&!(r.tool_uses?.length??0)&&!(r.tool_results?.length??0)&&!(r.images?.length??0))continue;let l=_(r.images);s.push({role:r.role,content:r.content+l.note,toolUses:K(r.tool_uses),toolResults:H(r.tool_results),...l.images.length?{images:l.images}:{}})}}for(let n=e+1;n<t.length;n++){let r=t[n];if(r.type===x)continue;let l=B(r);l&&s.push(l)}return s}for(let o of t){let n=B(o);n&&s.push(n)}return s}function B(t){if(t.role!=="user"&&t.role!=="assistant"||!t.content&&!(t.tool_uses?.length??0)&&!(t.tool_results?.length??0)&&!(t.images?.length??0))return null;let e=_(t.images);return{role:t.role,content:t.content+e.note,toolUses:K(t.tool_uses),toolResults:H(t.tool_results),...e.images.length?{images:e.images}:{}}}function st(t){let e=S(t);if(!O(e))return[];let s=
|
|
28
|
+
Recent messages have been preserved verbatim.`),s.push({role:"user",content:n});for(let r of o.keep){if(r.role!=="user"&&r.role!=="assistant"||!r.content&&!(r.tool_uses?.length??0)&&!(r.tool_results?.length??0)&&!(r.images?.length??0))continue;let l=_(r.images);s.push({role:r.role,content:r.content+l.note,toolUses:K(r.tool_uses),toolResults:H(r.tool_results),...l.images.length?{images:l.images}:{}})}}for(let n=e+1;n<t.length;n++){let r=t[n];if(r.type===x)continue;let l=B(r);l&&s.push(l)}return s}for(let o of t){let n=B(o);n&&s.push(n)}return s}function B(t){if(t.role!=="user"&&t.role!=="assistant"||!t.content&&!(t.tool_uses?.length??0)&&!(t.tool_results?.length??0)&&!(t.images?.length??0))return null;let e=_(t.images);return{role:t.role,content:t.content+e.note,toolUses:K(t.tool_uses),toolResults:H(t.tool_results),...e.images.length?{images:e.images}:{}}}function st(t){let e=S(t);if(!O(e))return[];let s=le(e).filter(n=>n.endsWith(".jsonl")),o=[];for(let n of s){let r=f(e,n),l=ue(r),a=n.replace(".jsonl",""),c="",u=0;try{for(let g of L(r,"utf-8").split(`
|
|
29
29
|
`)){if(!g.trim())continue;let d;try{let h=JSON.parse(g);d=M($,h)}catch(h){R.error({err:h},"session operation failed");continue}u++,!c&&d.role==="user"&&d.content&&(c=d.content.slice(0,100))}}catch(g){R.error({err:g},"session operation failed");continue}o.push({id:a,firstMessage:c,messageCount:u,size:l.size,modTime:l.mtime})}return o.sort((n,r)=>r.modTime.getTime()-n.modTime.getTime()),o}var W=3,he=3,pe="[earlier conversation truncated for compaction retry]",fe=3.5,ye=1e4,Te=5,be=4e4,Re=2,Se=2e4,Me=13e3,ke=3e3;function J(t,e,s=!1){return t-Math.min(e,Se)-(s?ke:Me)}var X=class{consecutiveFailures=0},G=7e3;function C(t){let e=0;for(let s of t){if(e+=s.content.length,s.images&&(e+=s.images.length*G),s.toolUses&&(e+=JSON.stringify(s.toolUses).length),s.toolResults)for(let o of s.toolResults)e+=o.content.length,e+=(o.images?.length??0)*G;if(s.thinkingBlocks)for(let o of s.thinkingBlocks)e+=o.thinking.length}return Math.ceil(e/fe)}function Ie(t){return C(t.getMessages())}function v(t){return C([t])}function xe(t){return t.role==="user"&&!!t.toolResults&&t.toolResults.length>0}function we(t){let e=0,s=0,o=t.length;for(let n=t.length-1;n>=0;n--){let r=v(t[n]);if(s>0&&e+r>be||(o=n,e+=r,s++,e>=ye||s>=Te))break}return o=_e(t,o),o}function _e(t,e){if(e<=0||e>=t.length||!xe(t[e]))return e;let s=new Set((t[e].toolResults??[]).map(o=>o.toolUseId));for(let o=e-1;o>=0;o--){let n=t[o];if(n.role==="assistant"&&n.toolUses?.some(r=>s.has(r.toolUseId)))return o}return e}function Ce(t,e){let s=e??t.usageAnchorState();if(!s)return Ie(t);let o=t.getMessages(),n=Math.min(s.anchorCount,o.length);return s.baselineTokens+C(o.slice(n))}async function lt(t,e,s,o,n,r,l,a,c=""){let u=Ce(t),g=J(s,o),d=J(s,o,!0);if(u<g)return{compacted:!1,message:""};if(!(u>=d)&&n.consecutiveFailures>=W)return{compacted:!1,message:`Auto-compact circuit breaker: ${String(W)} consecutive failures`};try{let p=await V(t,e,r,l,a,c);return n.consecutiveFailures=0,p}catch(p){return n.consecutiveFailures++,{compacted:!1,message:`Auto-compact failed: ${U(p)}`}}}async function ct(t,e,s,o,n,r=""){return V(t,e,s,o,n,r)}var ve=`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
|
|
|
@@ -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{
|
|
4
|
+
import{a as w}from"./chunk-7MHXMDYC.js";import{D as u,I as D,R as d,e as k}from"./chunk-ISXLT3QN.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/glob_addon.node
CHANGED
|
Binary file
|