@swifty.js/swifty 0.0.2-alpha → 0.0.2
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/README.md +0 -119
- package/dist/agent-MICFDGUF.js +4 -0
- package/dist/anthropic-JDAGNAPR.js +4 -0
- package/dist/checker-PF3FEOF2.js +4 -0
- package/dist/chunk-4KVSJNS6.js +90 -0
- package/dist/chunk-6ARDOHBL.js +4 -0
- package/dist/chunk-7MHXMDYC.js +35 -0
- package/dist/chunk-F6HLYUZ4.js +355 -0
- package/dist/chunk-FZPTNGTU.js +4 -0
- package/dist/chunk-LPLPMGWW.js +336 -0
- package/dist/chunk-RD3MICOU.js +4 -0
- package/dist/glob_addon.node +0 -0
- package/dist/main.js +233 -233
- package/dist/{openai-BUFKIEZO.js → openai-I4WTRNNT.js} +11 -11
- package/dist/{server-4FIOX5PK.js → server-OGPKL2U2.js} +22 -21
- package/package.json +1 -1
- package/dist/anthropic-RNEEF6RX.js +0 -4
- package/dist/chunk-SLGPWJQF.js +0 -121
- package/dist/chunk-YUOKPBUW.js +0 -526
|
@@ -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 as w}from"./chunk-7MHXMDYC.js";import{I as d,R as u,e as P,j as R}from"./chunk-4KVSJNS6.js";import{readFileSync as S,writeFileSync as $,mkdirSync as F,statSync as A}from"fs";import{join as p,resolve as l,dirname as x}from"path";import{homedir as W,tmpdir as j}from"os";var y=P({module:"permissions"}),_=[{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"}],T=["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"},M=[".swifty/config.yaml",".swifty/permissions.local.yaml",".swifty/skills/"];function h(o,e){let t=L[o];if(!t)return"";let r=e[t];return typeof r=="string"?r:""}var E=class{allowedRoots;denyWritePaths;projectDir;constructor(e){this.projectDir=l(e),this.allowedRoots=[this.projectDir,j()],this.denyWritePaths=M.map(t=>p(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 r of this.denyWritePaths)if(t.startsWith(r))return{effect:"deny",reason:`Path ${e} is in deny-write list`};return null}check(e){let t=l(e);for(let r of this.allowedRoots)if(t.startsWith(r))return null;return{effect:"deny",reason:`Path ${e} is outside allowed directories`}}};function O(o,e){let t="^"+o.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,".")+"$";try{return new RegExp(t).test(e)}catch(r){return y.error({err:r},"permissions operation failed"),!1}}var Y=/^(\w+)\((.+)\)$/;function k(o){let e;try{e=S(o,"utf-8")}catch(s){return s.code!=="ENOENT"&&y.error({err:s},"permissions operation failed"),[]}let t=d.object({rule:d.string().optional(),effect:d.string().optional()}),r;try{let s=w.load(e);r=R(d.array(t),s)}catch(s){return y.error({err:s},"permissions operation failed"),[]}let i=[];for(let s of r){if(s.effect!=="allow"&&s.effect!=="deny"&&s.effect!=="ask")continue;let n=Y.exec((s.rule??"").trim());n&&i.push({tool:n[1],pattern:n[2],effect:s.effect})}return i}var b=class{userPath;projectPath;localPath;constructor(e){this.userPath=p(W(),".swifty","permissions.yaml"),this.projectPath=p(e,".swifty","permissions.yaml"),this.localPath=p(e,".swifty","permissions.local.yaml")}evaluate(e,t){for(let r of[this.userPath,this.projectPath,this.localPath]){let i=k(r);for(let s=i.length-1;s>=0;s--){let n=i[s];if(!(n.tool!==e&&n.tool!=="*")&&O(n.pattern,t))return n.effect}}return null}appendLocalRule(e){F(x(this.localPath),{recursive:!0});let t=k(this.localPath);if(t.some(s=>s.tool===e.tool&&s.pattern===e.pattern&&s.effect===e.effect))return;t.push(e);let i=t.map(s=>({rule:`${s.tool}(${s.pattern})`,effect:s.effect}));$(this.localPath,w.dump(i),"utf-8")}};function C(o){for(let e of _)if(e.re.test(o))return e.reason;return""}function G(o){let e=o.trim();return e.includes(">")||e.includes("|")||e.includes(";")||e.includes("&&")||e.includes("$(")||e.includes("`")?!1:T.some(t=>e===t||e.startsWith(t+" ")||e.startsWith(t+" "))}function I(o,e){switch(o){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 D=class{mode;planFilePath="";sandboxEnabled=!1;sandboxAutoAllow=!1;sandbox;ruleEngine;sessionAllowed=new Set;constructor(e,t="default"){this.mode=t,this.sandbox=new E(e),this.ruleEngine=new b(e)}check(e,t,r){let i=h(e,r);if(this.mode==="plan"&&(e==="WriteFile"||e==="EditFile")&&u(r,"file_path","").includes(".swifty/plans/"))return{effect:"allow",reason:"Plan file write allowed in plan mode"};if(t==="command"&&G(i))return{effect:"allow",reason:"Safe read-only command"};let s=t==="command"?C(i):"";if(s)return{effect:"deny",reason:`Dangerous command blocked: ${s}`};if(this.sandboxEnabled&&this.sandboxAutoAllow&&t==="command"){let f=u(r,"command").split(/\s*(?:&&|\|\||[;|])\s*/).map(g=>g.trim()).filter(Boolean),c=!1;for(let g of f){let v=this.ruleEngine.evaluate(e,g);if(v==="deny")return{effect:"deny",reason:"Permission rule: deny"};v==="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 n=u(r,"file_path",u(r,"path",""));if((t==="read"||t==="write")&&n){if(t==="write"){let c=this.sandbox.checkDenyWrite(n);if(c)return c}let f=this.sandbox.check(n);if(f&&this.mode!=="bypassPermissions"){let c=this.ruleEngine.evaluate(e,i);return c?{effect:c,reason:`Permission rule: ${c}`}:{effect:"ask",reason:f.reason}}}let a=`${e}:${i}`;if(this.sessionAllowed.has(a))return{effect:"allow",reason:"Session allow: previously approved"};let m=this.ruleEngine.evaluate(e,i);return m?{effect:m,reason:`Permission rule: ${m}`}:{effect:I(this.mode,t),reason:`Mode: ${this.mode}`}}allowForSession(e,t){let r=h(e,t);this.sessionAllowed.add(`${e}:${r}`)}allowAlways(e,t){let r=h(e,t),i=e==="ReadFile"||e==="WriteFile"||e==="EditFile",s;if(i&&r){let n=l(r),a=!1;try{a=A(n).isDirectory()}catch{}s=p(a?n:x(n),"*")}else s=r.trim().split(/\s+/).slice(0,2).join(" ")+"*";this.ruleEngine.appendLocalRule({tool:e,pattern:s,effect:"allow"})}describeToolAction(e,t){let r=h(e,t);if(r)return r;let i=[];for(let[s,n]of Object.entries(t)){let a=String(n);a.length>80&&(a=a.slice(0,80)+"..."),i.push(`${s}: ${a}`)}return i.join(", ")}};export{h as a,E as b,b as c,D as d};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire as __swiftyCreateRequire } from "node:module";
|
|
3
|
+
const require = __swiftyCreateRequire(import.meta.url);
|
|
4
|
+
function $n(T){return T&&T.__esModule&&Object.prototype.hasOwnProperty.call(T,"default")?T.default:T}var P={},Ie={},Z={},un;function ae(){if(un)return Z;un=1;function T(a){return typeof a>"u"||a===null}function _(a){return typeof a=="object"&&a!==null}function I(a){return Array.isArray(a)?a:T(a)?[]:[a]}function L(a,s){if(s){let S=Object.keys(s);for(let l=0,c=S.length;l<c;l+=1){let C=S[l];a[C]=s[C]}}return a}function d(a,s){let S="";for(let l=0;l<s;l+=1)S+=a;return S}function y(a){return a===0&&Number.NEGATIVE_INFINITY===1/a}return Z.isNothing=T,Z.isObject=_,Z.toArray=I,Z.repeat=d,Z.isNegativeZero=y,Z.extend=L,Z}var Ye,fn;function he(){if(fn)return Ye;fn=1;function T(I,L){let d="",y=I.reason||"(unknown reason)";return I.mark?(I.mark.name&&(d+='in "'+I.mark.name+'" '),d+="("+(I.mark.line+1)+":"+(I.mark.column+1)+")",!L&&I.mark.snippet&&(d+=`
|
|
5
|
+
|
|
6
|
+
`+I.mark.snippet),y+" "+d):y}function _(I,L){Error.call(this),this.name="YAMLException",this.reason=I,this.mark=L,this.message=T(this,!1),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack||""}return _.prototype=Object.create(Error.prototype),_.prototype.constructor=_,_.prototype.toString=function(L){return this.name+": "+T(this,L)},Ye=_,Ye}var Pe,pn;function Jn(){if(pn)return Pe;pn=1;let T=ae();function _(d,y,a,s,S){let l="",c="",C=Math.floor(S/2)-1;return s-y>C&&(l=" ... ",y=s-C+l.length),a-s>C&&(c=" ...",a=s+C-c.length),{str:l+d.slice(y,a).replace(/\t/g,"\u2192")+c,pos:s-y+l.length}}function I(d,y){return T.repeat(" ",y-d.length)+d}function L(d,y){if(y=Object.create(y||null),!d.buffer)return null;y.maxLength||(y.maxLength=79),typeof y.indent!="number"&&(y.indent=1),typeof y.linesBefore!="number"&&(y.linesBefore=3),typeof y.linesAfter!="number"&&(y.linesAfter=2);let a=/\r?\n|\r|\0/g,s=[0],S=[],l,c=-1;for(;l=a.exec(d.buffer);)S.push(l.index),s.push(l.index+l[0].length),d.position<=l.index&&c<0&&(c=s.length-2);c<0&&(c=s.length-1);let C="",k=Math.min(d.line+y.linesAfter,S.length).toString().length,R=y.maxLength-(y.indent+k+3);for(let M=1;M<=y.linesBefore&&!(c-M<0);M++){let U=_(d.buffer,s[c-M],S[c-M],d.position-(s[c]-s[c-M]),R);C=T.repeat(" ",y.indent)+I((d.line-M+1).toString(),k)+" | "+U.str+`
|
|
7
|
+
`+C}let X=_(d.buffer,s[c],S[c],d.position,R);C+=T.repeat(" ",y.indent)+I((d.line+1).toString(),k)+" | "+X.str+`
|
|
8
|
+
`,C+=T.repeat("-",y.indent+k+3+X.pos)+`^
|
|
9
|
+
`;for(let M=1;M<=y.linesAfter&&!(c+M>=S.length);M++){let U=_(d.buffer,s[c+M],S[c+M],d.position-(s[c]-s[c+M]),R);C+=T.repeat(" ",y.indent)+I((d.line+M+1).toString(),k)+" | "+U.str+`
|
|
10
|
+
`}return C.replace(/\n$/,"")}return Pe=L,Pe}var De,sn;function D(){if(sn)return De;sn=1;let T=he(),_=["kind","multi","resolve","construct","instanceOf","predicate","represent","representName","defaultStyle","styleAliases"],I=["scalar","sequence","mapping"];function L(y){let a={};return y!==null&&Object.keys(y).forEach(function(s){y[s].forEach(function(S){a[String(S)]=s})}),a}function d(y,a){if(a=a||{},Object.keys(a).forEach(function(s){if(_.indexOf(s)===-1)throw new T('Unknown option "'+s+'" is met in definition of "'+y+'" YAML type.')}),this.options=a,this.tag=y,this.kind=a.kind||null,this.resolve=a.resolve||function(){return!0},this.construct=a.construct||function(s){return s},this.instanceOf=a.instanceOf||null,this.predicate=a.predicate||null,this.represent=a.represent||null,this.representName=a.representName||null,this.defaultStyle=a.defaultStyle||null,this.multi=a.multi||!1,this.styleAliases=L(a.styleAliases||null),I.indexOf(this.kind)===-1)throw new T('Unknown kind "'+this.kind+'" is specified for "'+y+'" YAML type.')}return De=d,De}var He,an;function vn(){if(an)return He;an=1;let T=he(),_=D();function I(y,a){let s=[];return y[a].forEach(function(S){let l=s.length;s.forEach(function(c,C){c.tag===S.tag&&c.kind===S.kind&&c.multi===S.multi&&(l=C)}),s[l]=S}),s}function L(){let y={scalar:{},sequence:{},mapping:{},fallback:{},multi:{scalar:[],sequence:[],mapping:[],fallback:[]}};function a(s){s.multi?(y.multi[s.kind].push(s),y.multi.fallback.push(s)):y[s.kind][s.tag]=y.fallback[s.tag]=s}for(let s=0,S=arguments.length;s<S;s+=1)arguments[s].forEach(a);return y}function d(y){return this.extend(y)}return d.prototype.extend=function(a){let s=[],S=[];if(a instanceof _)S.push(a);else if(Array.isArray(a))S=S.concat(a);else if(a&&(Array.isArray(a.implicit)||Array.isArray(a.explicit)))a.implicit&&(s=s.concat(a.implicit)),a.explicit&&(S=S.concat(a.explicit));else throw new T("Schema.extend argument should be a Type, [ Type ], or a schema definition ({ implicit: [...], explicit: [...] })");s.forEach(function(c){if(!(c instanceof _))throw new T("Specified list of YAML types (or a single Type object) contains a non-Type object.");if(c.loadKind&&c.loadKind!=="scalar")throw new T("There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.");if(c.multi)throw new T("There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.")}),S.forEach(function(c){if(!(c instanceof _))throw new T("Specified list of YAML types (or a single Type object) contains a non-Type object.")});let l=Object.create(d.prototype);return l.implicit=(this.implicit||[]).concat(s),l.explicit=(this.explicit||[]).concat(S),l.compiledImplicit=I(l,"implicit"),l.compiledExplicit=I(l,"explicit"),l.compiledTypeMap=L(l.compiledImplicit,l.compiledExplicit),l},He=d,He}var je,hn;function Mn(){if(hn)return je;hn=1;let T=D();return je=new T("tag:yaml.org,2002:str",{kind:"scalar",construct:function(_){return _!==null?_:""}}),je}var Be,dn;function Fn(){if(dn)return Be;dn=1;let T=D();return Be=new T("tag:yaml.org,2002:seq",{kind:"sequence",construct:function(_){return _!==null?_:[]}}),Be}var Ue,mn;function qn(){if(mn)return Ue;mn=1;let T=D();return Ue=new T("tag:yaml.org,2002:map",{kind:"mapping",construct:function(_){return _!==null?_:{}}}),Ue}var Ke,gn;function Yn(){if(gn)return Ke;gn=1;let T=vn();return Ke=new T({explicit:[Mn(),Fn(),qn()]}),Ke}var Ge,An;function Pn(){if(An)return Ge;An=1;let T=D();function _(d){if(d===null)return!0;let y=d.length;return y===1&&d==="~"||y===4&&(d==="null"||d==="Null"||d==="NULL")}function I(){return null}function L(d){return d===null}return Ge=new T("tag:yaml.org,2002:null",{kind:"scalar",resolve:_,construct:I,predicate:L,represent:{canonical:function(){return"~"},lowercase:function(){return"null"},uppercase:function(){return"NULL"},camelcase:function(){return"Null"},empty:function(){return""}},defaultStyle:"lowercase"}),Ge}var We,yn;function Dn(){if(yn)return We;yn=1;let T=D();function _(d){if(d===null)return!1;let y=d.length;return y===4&&(d==="true"||d==="True"||d==="TRUE")||y===5&&(d==="false"||d==="False"||d==="FALSE")}function I(d){return d==="true"||d==="True"||d==="TRUE"}function L(d){return Object.prototype.toString.call(d)==="[object Boolean]"}return We=new T("tag:yaml.org,2002:bool",{kind:"scalar",resolve:_,construct:I,predicate:L,represent:{lowercase:function(d){return d?"true":"false"},uppercase:function(d){return d?"TRUE":"FALSE"},camelcase:function(d){return d?"True":"False"}},defaultStyle:"lowercase"}),We}var Qe,Cn;function Hn(){if(Cn)return Qe;Cn=1;let T=ae(),_=D();function I(l){return l>=48&&l<=57||l>=65&&l<=70||l>=97&&l<=102}function L(l){return l>=48&&l<=55}function d(l){return l>=48&&l<=57}function y(l){if(l===null)return!1;let c=l.length,C=0,k=!1;if(!c)return!1;let R=l[C];if((R==="-"||R==="+")&&(R=l[++C]),R==="0"){if(C+1===c)return!0;if(R=l[++C],R==="b"){for(C++;C<c;C++){if(R=l[C],R!=="0"&&R!=="1")return!1;k=!0}return k&&isFinite(a(l))}if(R==="x"){for(C++;C<c;C++){if(!I(l.charCodeAt(C)))return!1;k=!0}return k&&isFinite(a(l))}if(R==="o"){for(C++;C<c;C++){if(!L(l.charCodeAt(C)))return!1;k=!0}return k&&isFinite(a(l))}}for(;C<c;C++){if(!d(l.charCodeAt(C)))return!1;k=!0}return k?isFinite(a(l)):!1}function a(l){let c=l,C=1,k=c[0];if((k==="-"||k==="+")&&(k==="-"&&(C=-1),c=c.slice(1),k=c[0]),c==="0")return 0;if(k==="0"){if(c[1]==="b")return C*parseInt(c.slice(2),2);if(c[1]==="x")return C*parseInt(c.slice(2),16);if(c[1]==="o")return C*parseInt(c.slice(2),8)}return C*parseInt(c,10)}function s(l){return a(l)}function S(l){return Object.prototype.toString.call(l)==="[object Number]"&&l%1===0&&!T.isNegativeZero(l)}return Qe=new _("tag:yaml.org,2002:int",{kind:"scalar",resolve:y,construct:s,predicate:S,represent:{binary:function(l){return l>=0?"0b"+l.toString(2):"-0b"+l.toString(2).slice(1)},octal:function(l){return l>=0?"0o"+l.toString(8):"-0o"+l.toString(8).slice(1)},decimal:function(l){return l.toString(10)},hexadecimal:function(l){return l>=0?"0x"+l.toString(16).toUpperCase():"-0x"+l.toString(16).toUpperCase().slice(1)}},defaultStyle:"decimal",styleAliases:{binary:[2,"bin"],octal:[8,"oct"],decimal:[10,"dec"],hexadecimal:[16,"hex"]}}),Qe}var Ve,Sn;function jn(){if(Sn)return Ve;Sn=1;let T=ae(),_=D(),I=new RegExp("^(?:[-+]?(?:[0-9]+)(?:\\.[0-9]*)?(?:[eE][-+]?[0-9]+)?|\\.[0-9]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$"),L=new RegExp("^(?:[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");function d(l){return l===null||!I.test(l)?!1:isFinite(parseFloat(l,10))?!0:L.test(l)}function y(l){let c=l.toLowerCase(),C=c[0]==="-"?-1:1;return"+-".indexOf(c[0])>=0&&(c=c.slice(1)),c===".inf"?C===1?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:c===".nan"?NaN:C*parseFloat(c,10)}let a=/^[-+]?[0-9]+e/;function s(l,c){if(isNaN(l))switch(c){case"lowercase":return".nan";case"uppercase":return".NAN";case"camelcase":return".NaN"}else if(Number.POSITIVE_INFINITY===l)switch(c){case"lowercase":return".inf";case"uppercase":return".INF";case"camelcase":return".Inf"}else if(Number.NEGATIVE_INFINITY===l)switch(c){case"lowercase":return"-.inf";case"uppercase":return"-.INF";case"camelcase":return"-.Inf"}else if(T.isNegativeZero(l))return"-0.0";let C=l.toString(10);return a.test(C)?C.replace("e",".e"):C}function S(l){return Object.prototype.toString.call(l)==="[object Number]"&&(l%1!==0||T.isNegativeZero(l))}return Ve=new _("tag:yaml.org,2002:float",{kind:"scalar",resolve:d,construct:y,predicate:S,represent:s,defaultStyle:"lowercase"}),Ve}var Xe,Tn;function Bn(){return Tn||(Tn=1,Xe=Yn().extend({implicit:[Pn(),Dn(),Hn(),jn()]})),Xe}var $e,wn;function Un(){return wn||(wn=1,$e=Bn()),$e}var Je,xn;function Kn(){if(xn)return Je;xn=1;let T=D(),_=new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$"),I=new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:[Tt]|[ \\t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:\\.([0-9]*))?(?:[ \\t]*(Z|([-+])([0-9][0-9]?)(?::([0-9][0-9]))?))?$");function L(a){return a===null?!1:_.exec(a)!==null||I.exec(a)!==null}function d(a){let s=0,S=null,l=_.exec(a);if(l===null&&(l=I.exec(a)),l===null)throw new Error("Date resolve error");let c=+l[1],C=+l[2]-1,k=+l[3];if(!l[4])return new Date(Date.UTC(c,C,k));let R=+l[4],X=+l[5],M=+l[6];if(l[7]){for(s=l[7].slice(0,3);s.length<3;)s+="0";s=+s}if(l[9]){let z=+l[10],H=+(l[11]||0);S=(z*60+H)*6e4,l[9]==="-"&&(S=-S)}let U=new Date(Date.UTC(c,C,k,R,X,M,s));return S&&U.setTime(U.getTime()-S),U}function y(a){return a.toISOString()}return Je=new T("tag:yaml.org,2002:timestamp",{kind:"scalar",resolve:L,construct:d,instanceOf:Date,represent:y}),Je}var Ze,bn;function Gn(){if(bn)return Ze;bn=1;let T=D();function _(I){return I==="<<"||I===null}return Ze=new T("tag:yaml.org,2002:merge",{kind:"scalar",resolve:_}),Ze}var ze,_n;function Wn(){if(_n)return ze;_n=1;let T=D(),_=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=
|
|
11
|
+
\r`;function I(a){if(a===null)return!1;let s=0,S=a.length,l=_;for(let c=0;c<S;c++){let C=l.indexOf(a.charAt(c));if(!(C>64)){if(C<0)return!1;s+=6}}return s%8===0}function L(a){let s=a.replace(/[\r\n=]/g,""),S=s.length,l=_,c=0,C=[];for(let R=0;R<S;R++)R%4===0&&R&&(C.push(c>>16&255),C.push(c>>8&255),C.push(c&255)),c=c<<6|l.indexOf(s.charAt(R));let k=S%4*6;return k===0?(C.push(c>>16&255),C.push(c>>8&255),C.push(c&255)):k===18?(C.push(c>>10&255),C.push(c>>2&255)):k===12&&C.push(c>>4&255),new Uint8Array(C)}function d(a){let s="",S=0,l=a.length,c=_;for(let k=0;k<l;k++)k%3===0&&k&&(s+=c[S>>18&63],s+=c[S>>12&63],s+=c[S>>6&63],s+=c[S&63]),S=(S<<8)+a[k];let C=l%3;return C===0?(s+=c[S>>18&63],s+=c[S>>12&63],s+=c[S>>6&63],s+=c[S&63]):C===2?(s+=c[S>>10&63],s+=c[S>>4&63],s+=c[S<<2&63],s+=c[64]):C===1&&(s+=c[S>>2&63],s+=c[S<<4&63],s+=c[64],s+=c[64]),s}function y(a){return Object.prototype.toString.call(a)==="[object Uint8Array]"}return ze=new T("tag:yaml.org,2002:binary",{kind:"scalar",resolve:I,construct:L,predicate:y,represent:d}),ze}var en,En;function Qn(){if(En)return en;En=1;let T=D(),_=Object.prototype.hasOwnProperty,I=Object.prototype.toString;function L(y){if(y===null)return!0;let a=[],s=y;for(let S=0,l=s.length;S<l;S+=1){let c=s[S],C=!1;if(I.call(c)!=="[object Object]")return!1;let k;for(k in c)if(_.call(c,k))if(!C)C=!0;else return!1;if(!C)return!1;if(a.indexOf(k)===-1)a.push(k);else return!1}return!0}function d(y){return y!==null?y:[]}return en=new T("tag:yaml.org,2002:omap",{kind:"sequence",resolve:L,construct:d}),en}var nn,In;function Vn(){if(In)return nn;In=1;let T=D(),_=Object.prototype.toString;function I(d){if(d===null)return!0;let y=d,a=new Array(y.length);for(let s=0,S=y.length;s<S;s+=1){let l=y[s];if(_.call(l)!=="[object Object]")return!1;let c=Object.keys(l);if(c.length!==1)return!1;a[s]=[c[0],l[c[0]]]}return!0}function L(d){if(d===null)return[];let y=d,a=new Array(y.length);for(let s=0,S=y.length;s<S;s+=1){let l=y[s],c=Object.keys(l);a[s]=[c[0],l[c[0]]]}return a}return nn=new T("tag:yaml.org,2002:pairs",{kind:"sequence",resolve:I,construct:L}),nn}var rn,On;function Xn(){if(On)return rn;On=1;let T=D(),_=Object.prototype.hasOwnProperty;function I(d){if(d===null)return!0;let y=d;for(let a in y)if(_.call(y,a)&&y[a]!==null)return!1;return!0}function L(d){return d!==null?d:{}}return rn=new T("tag:yaml.org,2002:set",{kind:"mapping",resolve:I,construct:L}),rn}var ln,kn;function tn(){return kn||(kn=1,ln=Un().extend({implicit:[Kn(),Gn()],explicit:[Wn(),Qn(),Vn(),Xn()]})),ln}var Ln;function Zn(){if(Ln)return Ie;Ln=1;let T=ae(),_=he(),I=Jn(),L=tn(),d=Object.prototype.hasOwnProperty,y=1,a=2,s=3,S=4,l=1,c=2,C=3,k=/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/,R=/[\x85\u2028\u2029]/,X=/[,\[\]{}]/,M=/^(?:!|!!|![0-9A-Za-z-]+!)$/,U=/^(?:!|[^,\[\]{}])(?:%[0-9a-f]{2}|[0-9a-z\-#;/?:@&=+$,_.!~*'()\[\]])*$/i;function z(e){return Object.prototype.toString.call(e)}function H(e){return e===10||e===13}function j(e){return e===9||e===32}function Y(e){return e===9||e===32||e===10||e===13}function $(e){return e===44||e===91||e===93||e===123||e===125}function Oe(e){if(e>=48&&e<=57)return e-48;let i=e|32;return i>=97&&i<=102?i-97+10:-1}function ke(e){return e===120?2:e===117?4:e===85?8:0}function de(e){return e>=48&&e<=57?e-48:-1}function oe(e){switch(e){case 48:return"\0";case 97:return"\x07";case 98:return"\b";case 116:return" ";case 9:return" ";case 110:return`
|
|
12
|
+
`;case 118:return"\v";case 102:return"\f";case 114:return"\r";case 101:return"\x1B";case 32:return" ";case 34:return'"';case 47:return"/";case 92:return"\\";case 78:return"\x85";case 95:return"\xA0";case 76:return"\u2028";case 80:return"\u2029";default:return""}}function Le(e){return e<=65535?String.fromCharCode(e):String.fromCharCode((e-65536>>10)+55296,(e-65536&1023)+56320)}function te(e,i,t){i==="__proto__"?Object.defineProperty(e,i,{configurable:!0,enumerable:!0,writable:!0,value:t}):e[i]=t}let me=new Array(256),ce=new Array(256);for(let e=0;e<256;e++)me[e]=oe(e)?1:0,ce[e]=oe(e);function q(e,i){this.input=e,this.filename=i.filename||null,this.schema=i.schema||L,this.onWarning=i.onWarning||null,this.legacy=i.legacy||!1,this.json=i.json||!1,this.listener=i.listener||null,this.maxDepth=typeof i.maxDepth=="number"?i.maxDepth:100,this.maxTotalMergeKeys=typeof i.maxTotalMergeKeys=="number"?i.maxTotalMergeKeys:1e4,this.implicitTypes=this.schema.compiledImplicit,this.typeMap=this.schema.compiledTypeMap,this.length=e.length,this.position=0,this.line=0,this.lineStart=0,this.lineIndent=0,this.depth=0,this.totalMergeKeys=0,this.firstTabInLine=-1,this.documents=[],this.anchorMapTransactions=[]}function ge(e,i){let t={name:e.filename,buffer:e.input.slice(0,-1),position:e.position,line:e.line,column:e.position-e.lineStart};return t.snippet=I(t),new _(i,t)}function b(e,i){throw ge(e,i)}function ne(e,i){e.onWarning&&e.onWarning.call(null,ge(e,i))}function K(e,i,t){let p=e.anchorMapTransactions;if(p.length!==0){let o=p[p.length-1];d.call(o,i)||(o[i]={existed:d.call(e.anchorMap,i),value:e.anchorMap[i]})}e.anchorMap[i]=t}function Ne(e){e.anchorMapTransactions.push(Object.create(null))}function ee(e){let i=e.anchorMapTransactions.pop(),t=e.anchorMapTransactions;if(t.length===0)return;let p=t[t.length-1],o=Object.keys(i);for(let A=0,n=o.length;A<n;A+=1){let r=o[A];d.call(p,r)||(p[r]=i[r])}}function Re(e){let i=e.anchorMapTransactions.pop(),t=Object.keys(i);for(let p=t.length-1;p>=0;p-=1){let o=i[t[p]];o.existed?e.anchorMap[t[p]]=o.value:delete e.anchorMap[t[p]]}}function ue(e){return{position:e.position,line:e.line,lineStart:e.lineStart,lineIndent:e.lineIndent,firstTabInLine:e.firstTabInLine,tag:e.tag,anchor:e.anchor,kind:e.kind,result:e.result}}function ie(e,i){e.position=i.position,e.line=i.line,e.lineStart=i.lineStart,e.lineIndent=i.lineIndent,e.firstTabInLine=i.firstTabInLine,e.tag=i.tag,e.anchor=i.anchor,e.kind=i.kind,e.result=i.result}let Ae={YAML:function(i,t,p){i.version!==null&&b(i,"duplication of %YAML directive"),p.length!==1&&b(i,"YAML directive accepts exactly one argument");let o=/^([0-9]+)\.([0-9]+)$/.exec(p[0]);o===null&&b(i,"ill-formed argument of the YAML directive");let A=parseInt(o[1],10),n=parseInt(o[2],10);A!==1&&b(i,"unacceptable YAML version of the document"),i.version=p[0],i.checkLineBreaks=n<2,n!==1&&n!==2&&ne(i,"unsupported YAML version of the document")},TAG:function(i,t,p){let o;p.length!==2&&b(i,"TAG directive accepts exactly two arguments");let A=p[0];o=p[1],M.test(A)||b(i,"ill-formed tag handle (first argument) of the TAG directive"),d.call(i.tagMap,A)&&b(i,'there is a previously declared suffix for "'+A+'" tag handle'),U.test(o)||b(i,"ill-formed tag prefix (second argument) of the TAG directive");try{o=decodeURIComponent(o)}catch{b(i,"tag prefix is malformed: "+o)}i.tagMap[A]=o}};function B(e,i,t,p){if(i<t){let o=e.input.slice(i,t);if(p)for(let A=0,n=o.length;A<n;A+=1){let r=o.charCodeAt(A);r===9||r>=32&&r<=1114111||b(e,"expected valid JSON character")}else k.test(o)&&b(e,"the stream contains non-printable characters");e.result+=o}}function J(e,i,t,p){T.isObject(t)||b(e,"cannot merge mappings; the provided source object is unacceptable");let o=Object.keys(t);for(let A=0,n=o.length;A<n;A+=1){let r=o[A];e.maxTotalMergeKeys!==-1&&++e.totalMergeKeys>e.maxTotalMergeKeys&&b(e,"merge keys exceeded maxTotalMergeKeys ("+e.maxTotalMergeKeys+")"),d.call(i,r)||(te(i,r,t[r]),p[r]=!0)}}function G(e,i,t,p,o,A,n,r,m){if(Array.isArray(o)){o=Array.prototype.slice.call(o);for(let u=0,f=o.length;u<f;u+=1)Array.isArray(o[u])&&b(e,"nested arrays are not supported inside keys"),typeof o=="object"&&z(o[u])==="[object Object]"&&(o[u]="[object Object]")}if(typeof o=="object"&&z(o)==="[object Object]"&&(o="[object Object]"),o=String(o),i===null&&(i={}),p==="tag:yaml.org,2002:merge")if(Array.isArray(A))for(let u=0,f=A.length;u<f;u+=1)J(e,i,A[u],t);else J(e,i,A,t);else!e.json&&!d.call(t,o)&&d.call(i,o)&&(e.line=n||e.line,e.lineStart=r||e.lineStart,e.position=m||e.position,b(e,"duplicated mapping key")),te(i,o,A),delete t[o];return i}function re(e){let i=e.input.charCodeAt(e.position);i===10?e.position++:i===13?(e.position++,e.input.charCodeAt(e.position)===10&&e.position++):b(e,"a line break is expected"),e.line+=1,e.lineStart=e.position,e.firstTabInLine=-1}function F(e,i,t){let p=0,o=e.input.charCodeAt(e.position);for(;o!==0;){for(;j(o);)o===9&&e.firstTabInLine===-1&&(e.firstTabInLine=e.position),o=e.input.charCodeAt(++e.position);if(i&&o===35)do o=e.input.charCodeAt(++e.position);while(o!==10&&o!==13&&o!==0);if(H(o))for(re(e),o=e.input.charCodeAt(e.position),p++,e.lineIndent=0;o===32;)e.lineIndent++,o=e.input.charCodeAt(++e.position);else break}return t!==-1&&p!==0&&e.lineIndent<t&&ne(e,"deficient indentation"),p}function le(e){let i=e.position,t=e.input.charCodeAt(i);return!!((t===45||t===46)&&t===e.input.charCodeAt(i+1)&&t===e.input.charCodeAt(i+2)&&(i+=3,t=e.input.charCodeAt(i),t===0||Y(t)))}function W(e,i){i===1?e.result+=" ":i>1&&(e.result+=T.repeat(`
|
|
13
|
+
`,i-1))}function ye(e,i,t){let p,o,A,n,r,m,u=e.kind,f=e.result,g=e.input.charCodeAt(e.position);if(Y(g)||$(g)||g===35||g===38||g===42||g===33||g===124||g===62||g===39||g===34||g===37||g===64||g===96)return!1;if(g===63||g===45){let h=e.input.charCodeAt(e.position+1);if(Y(h)||t&&$(h))return!1}for(e.kind="scalar",e.result="",p=o=e.position,A=!1;g!==0;){if(g===58){let h=e.input.charCodeAt(e.position+1);if(Y(h)||t&&$(h))break}else if(g===35){let h=e.input.charCodeAt(e.position-1);if(Y(h))break}else{if(e.position===e.lineStart&&le(e)||t&&$(g))break;if(H(g))if(n=e.line,r=e.lineStart,m=e.lineIndent,F(e,!1,-1),e.lineIndent>=i){A=!0,g=e.input.charCodeAt(e.position);continue}else{e.position=o,e.line=n,e.lineStart=r,e.lineIndent=m;break}}A&&(B(e,p,o,!1),W(e,e.line-n),p=o=e.position,A=!1),j(g)||(o=e.position+1),g=e.input.charCodeAt(++e.position)}return B(e,p,o,!1),e.result?!0:(e.kind=u,e.result=f,!1)}function Ce(e,i){let t,p,o=e.input.charCodeAt(e.position);if(o!==39)return!1;for(e.kind="scalar",e.result="",e.position++,t=p=e.position;(o=e.input.charCodeAt(e.position))!==0;)if(o===39)if(B(e,t,e.position,!0),o=e.input.charCodeAt(++e.position),o===39)t=e.position,e.position++,p=e.position;else return!0;else H(o)?(B(e,t,p,!0),W(e,F(e,!1,i)),t=p=e.position):e.position===e.lineStart&&le(e)?b(e,"unexpected end of the document within a single quoted scalar"):(e.position++,j(o)||(p=e.position));b(e,"unexpected end of the stream within a single quoted scalar")}function fe(e,i){let t,p,o,A=e.input.charCodeAt(e.position);if(A!==34)return!1;for(e.kind="scalar",e.result="",e.position++,t=p=e.position;(A=e.input.charCodeAt(e.position))!==0;){if(A===34)return B(e,t,e.position,!0),e.position++,!0;if(A===92){if(B(e,t,e.position,!0),A=e.input.charCodeAt(++e.position),H(A))F(e,!1,i);else if(A<256&&me[A])e.result+=ce[A],e.position++;else if((o=ke(A))>0){let n=o,r=0;for(;n>0;n--)A=e.input.charCodeAt(++e.position),(o=Oe(A))>=0?r=(r<<4)+o:b(e,"expected hexadecimal character");e.result+=Le(r),e.position++}else b(e,"unknown escape sequence");t=p=e.position}else H(A)?(B(e,t,p,!0),W(e,F(e,!1,i)),t=p=e.position):e.position===e.lineStart&&le(e)?b(e,"unexpected end of the document within a double quoted scalar"):(e.position++,j(A)||(p=e.position))}b(e,"unexpected end of the stream within a double quoted scalar")}function Se(e,i){let t=!0,p,o,A,n=e.tag,r,m=e.anchor,u,f,g,h,x=Object.create(null),w,E,O,N=e.input.charCodeAt(e.position);if(N===91)u=93,h=!1,r=[];else if(N===123)u=125,h=!0,r={};else return!1;for(e.anchor!==null&&K(e,e.anchor,r),N=e.input.charCodeAt(++e.position);N!==0;){if(F(e,!0,i),N=e.input.charCodeAt(e.position),N===u)return e.position++,e.tag=n,e.anchor=m,e.kind=h?"mapping":"sequence",e.result=r,!0;if(t?N===44&&b(e,"expected the node content, but found ','"):b(e,"missed comma between flow collection entries"),E=w=O=null,f=g=!1,N===63){let v=e.input.charCodeAt(e.position+1);Y(v)&&(f=g=!0,e.position++,F(e,!0,i))}p=e.line,o=e.lineStart,A=e.position,V(e,i,y,!1,!0),E=e.tag,w=e.result,F(e,!0,i),N=e.input.charCodeAt(e.position),(g||e.line===p)&&N===58&&(f=!0,N=e.input.charCodeAt(++e.position),F(e,!0,i),V(e,i,y,!1,!0),O=e.result),h?G(e,r,x,E,w,O,p,o,A):f?r.push(G(e,null,x,E,w,O,p,o,A)):r.push(w),F(e,!0,i),N=e.input.charCodeAt(e.position),N===44?(t=!0,N=e.input.charCodeAt(++e.position)):t=!1}b(e,"unexpected end of the stream within a flow collection")}function Te(e,i){let t,p=l,o=!1,A=!1,n=i,r=0,m=!1,u,f=e.input.charCodeAt(e.position);if(f===124)t=!1;else if(f===62)t=!0;else return!1;for(e.kind="scalar",e.result="";f!==0;)if(f=e.input.charCodeAt(++e.position),f===43||f===45)l===p?p=f===43?C:c:b(e,"repeat of a chomping mode identifier");else if((u=de(f))>=0)u===0?b(e,"bad explicit indentation width of a block scalar; it cannot be less than one"):A?b(e,"repeat of an indentation width identifier"):(n=i+u-1,A=!0);else break;if(j(f)){do f=e.input.charCodeAt(++e.position);while(j(f));if(f===35)do f=e.input.charCodeAt(++e.position);while(!H(f)&&f!==0)}for(;f!==0;){for(re(e),e.lineIndent=0,f=e.input.charCodeAt(e.position);(!A||e.lineIndent<n)&&f===32;)e.lineIndent++,f=e.input.charCodeAt(++e.position);if(!A&&e.lineIndent>n&&(n=e.lineIndent),H(f)){r++;continue}if(!A&&n===0&&b(e,"missing indentation for block scalar"),e.lineIndent<n){p===C?e.result+=T.repeat(`
|
|
14
|
+
`,o?1+r:r):p===l&&o&&(e.result+=`
|
|
15
|
+
`);break}t?j(f)?(m=!0,e.result+=T.repeat(`
|
|
16
|
+
`,o?1+r:r)):m?(m=!1,e.result+=T.repeat(`
|
|
17
|
+
`,r+1)):r===0?o&&(e.result+=" "):e.result+=T.repeat(`
|
|
18
|
+
`,r):e.result+=T.repeat(`
|
|
19
|
+
`,o?1+r:r),o=!0,A=!0,r=0;let g=e.position;for(;!H(f)&&f!==0;)f=e.input.charCodeAt(++e.position);B(e,g,e.position,!1)}return!0}function Q(e,i){let t=e.tag,p=e.anchor,o=[],A=!1;if(e.firstTabInLine!==-1)return!1;e.anchor!==null&&K(e,e.anchor,o);let n=e.input.charCodeAt(e.position);for(;n!==0&&(e.firstTabInLine!==-1&&(e.position=e.firstTabInLine,b(e,"tab characters must not be used in indentation")),n===45);){let r=e.input.charCodeAt(e.position+1);if(!Y(r))break;if(A=!0,e.position++,F(e,!0,-1)&&e.lineIndent<=i){o.push(null),n=e.input.charCodeAt(e.position);continue}let m=e.line;if(V(e,i,s,!1,!0),o.push(e.result),F(e,!0,-1),n=e.input.charCodeAt(e.position),(e.line===m||e.lineIndent>i)&&n!==0)b(e,"bad indentation of a sequence entry");else if(e.lineIndent<i)break}return A?(e.tag=t,e.anchor=p,e.kind="sequence",e.result=o,!0):!1}function we(e,i,t){let p,o,A,n,r=e.tag,m=e.anchor,u={},f=Object.create(null),g=null,h=null,x=null,w=!1,E=!1;if(e.firstTabInLine!==-1)return!1;e.anchor!==null&&K(e,e.anchor,u);let O=e.input.charCodeAt(e.position);for(;O!==0;){!w&&e.firstTabInLine!==-1&&(e.position=e.firstTabInLine,b(e,"tab characters must not be used in indentation"));let N=e.input.charCodeAt(e.position+1),v=e.line;if((O===63||O===58)&&Y(N))O===63?(w&&(G(e,u,f,g,h,null,o,A,n),g=h=x=null),E=!0,w=!0,p=!0):w?(w=!1,p=!0):b(e,"incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line"),e.position+=1,O=N;else{if(o=e.line,A=e.lineStart,n=e.position,!V(e,t,a,!1,!0))break;if(e.line===v){for(O=e.input.charCodeAt(e.position);j(O);)O=e.input.charCodeAt(++e.position);if(O===58)O=e.input.charCodeAt(++e.position),Y(O)||b(e,"a whitespace character is expected after the key-value separator within a block mapping"),w&&(G(e,u,f,g,h,null,o,A,n),g=h=x=null),E=!0,w=!1,p=!1,g=e.tag,h=e.result;else if(E)b(e,"can not read an implicit mapping pair; a colon is missed");else return e.tag=r,e.anchor=m,!0}else if(E)b(e,"can not read a block mapping entry; a multiline key may not be an implicit key");else return e.tag=r,e.anchor=m,!0}if((e.line===v||e.lineIndent>i)&&(w&&(o=e.line,A=e.lineStart,n=e.position),V(e,i,S,!0,p)&&(w?h=e.result:x=e.result),w||(G(e,u,f,g,h,x,o,A,n),g=h=x=null),F(e,!0,-1),O=e.input.charCodeAt(e.position)),(e.line===v||e.lineIndent>i)&&O!==0)b(e,"bad indentation of a mapping entry");else if(e.lineIndent<i)break}return w&&G(e,u,f,g,h,null,o,A,n),E&&(e.tag=r,e.anchor=m,e.kind="mapping",e.result=u),E}function ve(e){let i=!1,t=!1,p,o,A=e.input.charCodeAt(e.position);if(A!==33)return!1;e.tag!==null&&b(e,"duplication of a tag property"),A=e.input.charCodeAt(++e.position),A===60?(i=!0,A=e.input.charCodeAt(++e.position)):A===33?(t=!0,p="!!",A=e.input.charCodeAt(++e.position)):p="!";let n=e.position;if(i){do A=e.input.charCodeAt(++e.position);while(A!==0&&A!==62);e.position<e.length?(o=e.input.slice(n,e.position),A=e.input.charCodeAt(++e.position)):b(e,"unexpected end of the stream within a verbatim tag")}else{for(;A!==0&&!Y(A);)A===33&&(t?b(e,"tag suffix cannot contain exclamation marks"):(p=e.input.slice(n-1,e.position+1),M.test(p)||b(e,"named tag handle cannot contain such characters"),t=!0,n=e.position+1)),A=e.input.charCodeAt(++e.position);o=e.input.slice(n,e.position),X.test(o)&&b(e,"tag suffix cannot contain flow indicator characters")}o&&!U.test(o)&&b(e,"tag name cannot contain such characters: "+o);try{o=decodeURIComponent(o)}catch{b(e,"tag name is malformed: "+o)}return i?e.tag=o:d.call(e.tagMap,p)?e.tag=e.tagMap[p]+o:p==="!"?e.tag="!"+o:p==="!!"?e.tag="tag:yaml.org,2002:"+o:b(e,'undeclared tag handle "'+p+'"'),!0}function xe(e){let i=e.input.charCodeAt(e.position);if(i!==38)return!1;e.anchor!==null&&b(e,"duplication of an anchor property"),i=e.input.charCodeAt(++e.position);let t=e.position;for(;i!==0&&!Y(i)&&!$(i);)i=e.input.charCodeAt(++e.position);return e.position===t&&b(e,"name of an anchor node must contain at least one character"),e.anchor=e.input.slice(t,e.position),!0}function be(e){let i=e.input.charCodeAt(e.position);if(i!==42)return!1;i=e.input.charCodeAt(++e.position);let t=e.position;for(;i!==0&&!Y(i)&&!$(i);)i=e.input.charCodeAt(++e.position);e.position===t&&b(e,"name of an alias node must contain at least one character");let p=e.input.slice(t,e.position);return d.call(e.anchorMap,p)||b(e,'unidentified alias "'+p+'"'),e.result=e.anchorMap[p],F(e,!0,-1),!0}function Me(e,i,t,p){let o=ue(e);return Ne(e),ie(e,i),e.tag=null,e.anchor=null,e.kind=null,e.result=null,we(e,t,p)&&e.kind==="mapping"?(ee(e),!0):(Re(e),ie(e,o),!1)}function V(e,i,t,p,o){let A,n,r=1,m=!1,u=!1,f=null,g,h,x;e.depth>=e.maxDepth&&b(e,"nesting exceeded maxDepth ("+e.maxDepth+")"),e.depth+=1,e.listener!==null&&e.listener("open",e),e.tag=null,e.anchor=null,e.kind=null,e.result=null;let w=A=n=S===t||s===t;if(p&&F(e,!0,-1)&&(m=!0,e.lineIndent>i?r=1:e.lineIndent===i?r=0:e.lineIndent<i&&(r=-1)),r===1)for(;;){let E=e.input.charCodeAt(e.position),O=ue(e);if(m&&(E===33&&e.tag!==null||E===38&&e.anchor!==null)||!ve(e)&&!xe(e))break;f===null&&(f=O),F(e,!0,-1)?(m=!0,n=w,e.lineIndent>i?r=1:e.lineIndent===i?r=0:e.lineIndent<i&&(r=-1)):n=!1}if(n&&(n=m||o),r===1||S===t)if(y===t||a===t?h=i:h=i+1,x=e.position-e.lineStart,r===1)if(n&&(Q(e,x)||we(e,x,h))||Se(e,h))u=!0;else{let E=e.input.charCodeAt(e.position);f!==null&&w&&!n&&E!==124&&E!==62&&Me(e,f,f.position-f.lineStart,h)||A&&Te(e,h)||Ce(e,h)||fe(e,h)?u=!0:be(e)?(u=!0,(e.tag!==null||e.anchor!==null)&&b(e,"alias node should not have any properties")):ye(e,h,y===t)&&(u=!0,e.tag===null&&(e.tag="?")),e.anchor!==null&&K(e,e.anchor,e.result)}else r===0&&(u=n&&Q(e,x));if(e.tag===null)e.anchor!==null&&K(e,e.anchor,e.result);else if(e.tag==="?"){e.result!==null&&e.kind!=="scalar"&&b(e,'unacceptable node kind for !<?> tag; it should be "scalar", not "'+e.kind+'"');for(let E=0,O=e.implicitTypes.length;E<O;E+=1)if(g=e.implicitTypes[E],g.resolve(e.result)){e.result=g.construct(e.result),e.tag=g.tag,e.anchor!==null&&K(e,e.anchor,e.result);break}}else if(e.tag!=="!"){if(d.call(e.typeMap[e.kind||"fallback"],e.tag))g=e.typeMap[e.kind||"fallback"][e.tag];else{g=null;let E=e.typeMap.multi[e.kind||"fallback"];for(let O=0,N=E.length;O<N;O+=1)if(e.tag.slice(0,E[O].tag.length)===E[O].tag){g=E[O];break}}g||b(e,"unknown tag !<"+e.tag+">"),e.result!==null&&g.kind!==e.kind&&b(e,"unacceptable node kind for !<"+e.tag+'> tag; it should be "'+g.kind+'", not "'+e.kind+'"'),g.resolve(e.result,e.tag)?(e.result=g.construct(e.result,e.tag),e.anchor!==null&&K(e,e.anchor,e.result)):b(e,"cannot resolve a node with !<"+e.tag+"> explicit tag")}return e.listener!==null&&e.listener("close",e),e.depth-=1,e.tag!==null||e.anchor!==null||u}function Fe(e){let i=e.position,t=!1,p;for(e.version=null,e.checkLineBreaks=e.legacy,e.tagMap=Object.create(null),e.anchorMap=Object.create(null);(p=e.input.charCodeAt(e.position))!==0&&(F(e,!0,-1),p=e.input.charCodeAt(e.position),!(e.lineIndent>0||p!==37));){t=!0,p=e.input.charCodeAt(++e.position);let o=e.position;for(;p!==0&&!Y(p);)p=e.input.charCodeAt(++e.position);let A=e.input.slice(o,e.position),n=[];for(A.length<1&&b(e,"directive name must not be less than one character in length");p!==0;){for(;j(p);)p=e.input.charCodeAt(++e.position);if(p===35){do p=e.input.charCodeAt(++e.position);while(p!==0&&!H(p));break}if(H(p))break;for(o=e.position;p!==0&&!Y(p);)p=e.input.charCodeAt(++e.position);n.push(e.input.slice(o,e.position))}p!==0&&re(e),d.call(Ae,A)?Ae[A](e,A,n):ne(e,'unknown document directive "'+A+'"')}if(F(e,!0,-1),e.lineIndent===0&&e.input.charCodeAt(e.position)===45&&e.input.charCodeAt(e.position+1)===45&&e.input.charCodeAt(e.position+2)===45?(e.position+=3,F(e,!0,-1)):t&&b(e,"directives end mark is expected"),V(e,e.lineIndent-1,S,!1,!0),F(e,!0,-1),e.checkLineBreaks&&R.test(e.input.slice(i,e.position))&&ne(e,"non-ASCII line breaks are interpreted as content"),e.documents.push(e.result),e.position===e.lineStart&&le(e)){e.input.charCodeAt(e.position)===46&&(e.position+=3,F(e,!0,-1));return}e.position<e.length-1&&b(e,"end of the stream or a document separator is expected")}function _e(e,i){e=String(e),i=i||{},e.length!==0&&(e.charCodeAt(e.length-1)!==10&&e.charCodeAt(e.length-1)!==13&&(e+=`
|
|
20
|
+
`),e.charCodeAt(0)===65279&&(e=e.slice(1)));let t=new q(e,i),p=e.indexOf("\0");for(p!==-1&&(t.position=p,b(t,"null byte is not allowed in input")),t.input+="\0";t.input.charCodeAt(t.position)===32;)t.lineIndent+=1,t.position+=1;for(;t.position<t.length-1;)Fe(t);return t.documents}function Ee(e,i,t){i!==null&&typeof i=="object"&&typeof t>"u"&&(t=i,i=null);let p=_e(e,t);if(typeof i!="function")return p;for(let o=0,A=p.length;o<A;o+=1)i(p[o])}function qe(e,i){let t=_e(e,i);if(t.length!==0){if(t.length===1)return t[0];throw new _("expected a single document in the stream, but found more")}}return Ie.loadAll=Ee,Ie.load=qe,Ie}var on={},Nn;function zn(){if(Nn)return on;Nn=1;let T=ae(),_=he(),I=tn(),L=Object.prototype.toString,d=Object.prototype.hasOwnProperty,y=65279,a=9,s=10,S=13,l=32,c=33,C=34,k=35,R=37,X=38,M=39,U=42,z=44,H=45,j=58,Y=61,$=62,Oe=63,ke=64,de=91,oe=93,Le=96,te=123,me=124,ce=125,q={};q[0]="\\0",q[7]="\\a",q[8]="\\b",q[9]="\\t",q[10]="\\n",q[11]="\\v",q[12]="\\f",q[13]="\\r",q[27]="\\e",q[34]='\\"',q[92]="\\\\",q[133]="\\N",q[160]="\\_",q[8232]="\\L",q[8233]="\\P";let ge=["y","Y","yes","Yes","YES","on","On","ON","n","N","no","No","NO","off","Off","OFF"],b=/^[-+]?[0-9_]+(?::[0-9_]+)+(?:\.[0-9_]*)?$/;function ne(n,r){if(r===null)return{};let m={},u=Object.keys(r);for(let f=0,g=u.length;f<g;f+=1){let h=u[f],x=String(r[h]);h.slice(0,2)==="!!"&&(h="tag:yaml.org,2002:"+h.slice(2));let w=n.compiledTypeMap.fallback[h];w&&d.call(w.styleAliases,x)&&(x=w.styleAliases[x]),m[h]=x}return m}function K(n){let r,m,u=n.toString(16).toUpperCase();if(n<=255)r="x",m=2;else if(n<=65535)r="u",m=4;else if(n<=4294967295)r="U",m=8;else throw new _("code point within a string may not be greater than 0xFFFFFFFF");return"\\"+r+T.repeat("0",m-u.length)+u}let Ne=1,ee=2;function Re(n){this.schema=n.schema||I,this.indent=Math.max(1,n.indent||2),this.noArrayIndent=n.noArrayIndent||!1,this.skipInvalid=n.skipInvalid||!1,this.flowLevel=T.isNothing(n.flowLevel)?-1:n.flowLevel,this.styleMap=ne(this.schema,n.styles||null),this.sortKeys=n.sortKeys||!1,this.lineWidth=n.lineWidth||80,this.noRefs=n.noRefs||!1,this.noCompatMode=n.noCompatMode||!1,this.condenseFlow=n.condenseFlow||!1,this.quotingType=n.quotingType==='"'?ee:Ne,this.forceQuotes=n.forceQuotes||!1,this.replacer=typeof n.replacer=="function"?n.replacer:null,this.implicitTypes=this.schema.compiledImplicit,this.explicitTypes=this.schema.compiledExplicit,this.tag=null,this.result="",this.duplicates=[],this.usedDuplicates=null}function ue(n,r){let m=T.repeat(" ",r),u=0,f="",g=n.length;for(;u<g;){let h,x=n.indexOf(`
|
|
21
|
+
`,u);x===-1?(h=n.slice(u),u=g):(h=n.slice(u,x+1),u=x+1),h.length&&h!==`
|
|
22
|
+
`&&(f+=m),f+=h}return f}function ie(n,r){return`
|
|
23
|
+
`+T.repeat(" ",n.indent*r)}function Ae(n,r){for(let m=0,u=n.implicitTypes.length;m<u;m+=1)if(n.implicitTypes[m].resolve(r))return!0;return!1}function B(n){return n===l||n===a}function J(n){return n>=32&&n<=126||n>=161&&n<=55295&&n!==8232&&n!==8233||n>=57344&&n<=65533&&n!==y||n>=65536&&n<=1114111}function G(n){return J(n)&&n!==y&&n!==S&&n!==s}function re(n,r,m){let u=G(n),f=u&&!B(n);return(m?u:u&&n!==z&&n!==de&&n!==oe&&n!==te&&n!==ce)&&n!==k&&!(r===j&&!f)||G(r)&&!B(r)&&n===k||r===j&&f}function F(n){return J(n)&&n!==y&&!B(n)&&n!==H&&n!==Oe&&n!==j&&n!==z&&n!==de&&n!==oe&&n!==te&&n!==ce&&n!==k&&n!==X&&n!==U&&n!==c&&n!==me&&n!==Y&&n!==$&&n!==M&&n!==C&&n!==R&&n!==ke&&n!==Le}function le(n){return!B(n)&&n!==j}function W(n,r){let m=n.charCodeAt(r),u;return m>=55296&&m<=56319&&r+1<n.length&&(u=n.charCodeAt(r+1),u>=56320&&u<=57343)?(m-55296)*1024+u-56320+65536:m}function ye(n){return/^\n* /.test(n)}let Ce=1,fe=2,Se=3,Te=4,Q=5;function we(n,r,m,u,f,g,h,x){let w,E=0,O=null,N=!1,v=!1,cn=u!==-1,pe=-1,se=F(W(n,0))&&le(W(n,n.length-1));if(r||h)for(w=0;w<n.length;E>=65536?w+=2:w++){if(E=W(n,w),!J(E))return Q;se=se&&re(E,O,x),O=E}else{for(w=0;w<n.length;E>=65536?w+=2:w++){if(E=W(n,w),E===s)N=!0,cn&&(v=v||w-pe-1>u&&n[pe+1]!==" ",pe=w);else if(!J(E))return Q;se=se&&re(E,O,x),O=E}v=v||cn&&w-pe-1>u&&n[pe+1]!==" "}return!N&&!v?se&&!h&&!f(n)?Ce:g===ee?Q:fe:m>9&&ye(n)?Q:h?g===ee?Q:fe:v?Te:Se}function ve(n,r,m,u,f){n.dump=(function(){if(r.length===0)return n.quotingType===ee?'""':"''";if(!n.noCompatMode&&(ge.indexOf(r)!==-1||b.test(r)))return n.quotingType===ee?'"'+r+'"':"'"+r+"'";let g=n.indent*Math.max(1,m),h=n.lineWidth===-1?-1:Math.max(Math.min(n.lineWidth,40),n.lineWidth-g),x=u||n.flowLevel>-1&&m>=n.flowLevel;function w(E){return Ae(n,E)}switch(we(r,x,n.indent,h,w,n.quotingType,n.forceQuotes&&!u,f)){case Ce:return r;case fe:return"'"+r.replace(/'/g,"''")+"'";case Se:return"|"+xe(r,n.indent)+be(ue(r,g));case Te:return">"+xe(r,n.indent)+be(ue(Me(r,h),g));case Q:return'"'+Fe(r)+'"';default:throw new _("impossible error: invalid scalar style")}})()}function xe(n,r){let m=ye(n)?String(r):"",u=n[n.length-1]===`
|
|
24
|
+
`,g=u&&(n[n.length-2]===`
|
|
25
|
+
`||n===`
|
|
26
|
+
`)?"+":u?"":"-";return m+g+`
|
|
27
|
+
`}function be(n){return n[n.length-1]===`
|
|
28
|
+
`?n.slice(0,-1):n}function Me(n,r){let m=/(\n+)([^\n]*)/g,u=(function(){let x=n.indexOf(`
|
|
29
|
+
`);return x=x!==-1?x:n.length,m.lastIndex=x,V(n.slice(0,x),r)})(),f=n[0]===`
|
|
30
|
+
`||n[0]===" ",g,h;for(;h=m.exec(n);){let x=h[1],w=h[2];g=w[0]===" ",u+=x+(!f&&!g&&w!==""?`
|
|
31
|
+
`:"")+V(w,r),f=g}return u}function V(n,r){if(n===""||n[0]===" ")return n;let m=/ [^ ]/g,u,f=0,g,h=0,x=0,w="";for(;u=m.exec(n);)x=u.index,x-f>r&&(g=h>f?h:x,w+=`
|
|
32
|
+
`+n.slice(f,g),f=g+1),h=x;return w+=`
|
|
33
|
+
`,n.length-f>r&&h>f?w+=n.slice(f,h)+`
|
|
34
|
+
`+n.slice(h+1):w+=n.slice(f),w.slice(1)}function Fe(n){let r="",m=0;for(let u=0;u<n.length;m>=65536?u+=2:u++){m=W(n,u);let f=q[m];!f&&J(m)?(r+=n[u],m>=65536&&(r+=n[u+1])):r+=f||K(m)}return r}function _e(n,r,m){let u="",f=n.tag;for(let g=0,h=m.length;g<h;g+=1){let x=m[g];n.replacer&&(x=n.replacer.call(m,String(g),x)),(t(n,r,x,!1,!1)||typeof x>"u"&&t(n,r,null,!1,!1))&&(u!==""&&(u+=","+(n.condenseFlow?"":" ")),u+=n.dump)}n.tag=f,n.dump="["+u+"]"}function Ee(n,r,m,u){let f="",g=n.tag;for(let h=0,x=m.length;h<x;h+=1){let w=m[h];n.replacer&&(w=n.replacer.call(m,String(h),w)),(t(n,r+1,w,!0,!0,!1,!0)||typeof w>"u"&&t(n,r+1,null,!0,!0,!1,!0))&&((!u||f!=="")&&(f+=ie(n,r)),n.dump&&s===n.dump.charCodeAt(0)?f+="-":f+="- ",f+=n.dump)}n.tag=g,n.dump=f||"[]"}function qe(n,r,m){let u="",f=n.tag,g=Object.keys(m);for(let h=0,x=g.length;h<x;h+=1){let w="";u!==""&&(w+=", "),n.condenseFlow&&(w+='"');let E=g[h],O=m[E];n.replacer&&(O=n.replacer.call(m,E,O)),t(n,r,E,!1,!1)&&(n.dump.length>1024&&(w+="? "),w+=n.dump+(n.condenseFlow?'"':"")+":"+(n.condenseFlow?"":" "),t(n,r,O,!1,!1)&&(w+=n.dump,u+=w))}n.tag=f,n.dump="{"+u+"}"}function e(n,r,m,u){let f="",g=n.tag,h=Object.keys(m);if(n.sortKeys===!0)h.sort();else if(typeof n.sortKeys=="function")h.sort(n.sortKeys);else if(n.sortKeys)throw new _("sortKeys must be a boolean or a function");for(let x=0,w=h.length;x<w;x+=1){let E="";(!u||f!=="")&&(E+=ie(n,r));let O=h[x],N=m[O];if(n.replacer&&(N=n.replacer.call(m,O,N)),!t(n,r+1,O,!0,!0,!0))continue;let v=n.tag!==null&&n.tag!=="?"||n.dump&&n.dump.length>1024;v&&(n.dump&&s===n.dump.charCodeAt(0)?E+="?":E+="? "),E+=n.dump,v&&(E+=ie(n,r)),t(n,r+1,N,!0,v)&&(n.dump&&s===n.dump.charCodeAt(0)?E+=":":E+=": ",E+=n.dump,f+=E)}n.tag=g,n.dump=f||"{}"}function i(n,r,m){let u=m?n.explicitTypes:n.implicitTypes;for(let f=0,g=u.length;f<g;f+=1){let h=u[f];if((h.instanceOf||h.predicate)&&(!h.instanceOf||typeof r=="object"&&r instanceof h.instanceOf)&&(!h.predicate||h.predicate(r))){if(m?h.multi&&h.representName?n.tag=h.representName(r):n.tag=h.tag:n.tag="?",h.represent){let x=n.styleMap[h.tag]||h.defaultStyle,w;if(L.call(h.represent)==="[object Function]")w=h.represent(r,x);else if(d.call(h.represent,x))w=h.represent[x](r,x);else throw new _("!<"+h.tag+'> tag resolver accepts not "'+x+'" style');n.dump=w}return!0}}return!1}function t(n,r,m,u,f,g,h){n.tag=null,n.dump=m,i(n,m,!1)||i(n,m,!0);let x=L.call(n.dump),w=u;u&&(u=n.flowLevel<0||n.flowLevel>r);let E=x==="[object Object]"||x==="[object Array]",O,N;if(E&&(O=n.duplicates.indexOf(m),N=O!==-1),(n.tag!==null&&n.tag!=="?"||N||n.indent!==2&&r>0)&&(f=!1),N&&n.usedDuplicates[O])n.dump="*ref_"+O;else{if(E&&N&&!n.usedDuplicates[O]&&(n.usedDuplicates[O]=!0),x==="[object Object]")u&&Object.keys(n.dump).length!==0?(e(n,r,n.dump,f),N&&(n.dump="&ref_"+O+n.dump)):(qe(n,r,n.dump),N&&(n.dump="&ref_"+O+" "+n.dump));else if(x==="[object Array]")u&&n.dump.length!==0?(n.noArrayIndent&&!h&&r>0?Ee(n,r-1,n.dump,f):Ee(n,r,n.dump,f),N&&(n.dump="&ref_"+O+n.dump)):(_e(n,r,n.dump),N&&(n.dump="&ref_"+O+" "+n.dump));else if(x==="[object String]")n.tag!=="?"&&ve(n,n.dump,r,g,w);else{if(x==="[object Undefined]")return!1;if(n.skipInvalid)return!1;throw new _("unacceptable kind of an object to dump "+x)}if(n.tag!==null&&n.tag!=="?"){let v=encodeURI(n.tag[0]==="!"?n.tag.slice(1):n.tag).replace(/!/g,"%21");n.tag[0]==="!"?v="!"+v:v.slice(0,18)==="tag:yaml.org,2002:"?v="!!"+v.slice(18):v="!<"+v+">",n.dump=v+" "+n.dump}}return!0}function p(n,r){let m=[],u=[];o(n,m,u);let f=u.length;for(let g=0;g<f;g+=1)r.duplicates.push(m[u[g]]);r.usedDuplicates=new Array(f)}function o(n,r,m){if(n!==null&&typeof n=="object"){let u=r.indexOf(n);if(u!==-1)m.indexOf(u)===-1&&m.push(u);else if(r.push(n),Array.isArray(n))for(let f=0,g=n.length;f<g;f+=1)o(n[f],r,m);else{let f=Object.keys(n);for(let g=0,h=f.length;g<h;g+=1)o(n[f[g]],r,m)}}}function A(n,r){r=r||{};let m=new Re(r);m.noRefs||p(n,m);let u=n;return m.replacer&&(u=m.replacer.call({"":u},"",u)),t(m,0,u,!0,!0)?m.dump+`
|
|
35
|
+
`:""}return on.dump=A,on}var Rn;function ei(){if(Rn)return P;Rn=1;let T=Zn(),_=zn();function I(L,d){return function(){throw new Error("Function yaml."+L+" is removed in js-yaml 4. Use yaml."+d+" instead, which is now safe by default.")}}return P.Type=D(),P.Schema=vn(),P.FAILSAFE_SCHEMA=Yn(),P.JSON_SCHEMA=Bn(),P.CORE_SCHEMA=Un(),P.DEFAULT_SCHEMA=tn(),P.load=T.load,P.loadAll=T.loadAll,P.dump=_.dump,P.YAMLException=he(),P.types={binary:Wn(),float:jn(),map:qn(),null:Pn(),pairs:Vn(),set:Xn(),timestamp:Kn(),bool:Dn(),int:Hn(),merge:Gn(),omap:Qn(),seq:Fn(),str:Mn()},P.safeLoad=I("safeLoad","load"),P.safeLoadAll=I("safeLoadAll","loadAll"),P.safeDump=I("safeDump","dump"),P}var ni=ei(),ii=$n(ni),{Type:ri,Schema:li,FAILSAFE_SCHEMA:oi,JSON_SCHEMA:ti,CORE_SCHEMA:ci,DEFAULT_SCHEMA:ui,load:fi,loadAll:pi,dump:si,YAMLException:ai,types:hi,safeLoad:di,safeLoadAll:mi,safeDump:gi}=ii;export{ii as a};
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire as __swiftyCreateRequire } from "node:module";
|
|
3
|
+
const require = __swiftyCreateRequire(import.meta.url);
|
|
4
|
+
import{a as q,e as H,g as K}from"./chunk-FZPTNGTU.js";import{I as p,L as Y,N as R,O as $,R as N,e as w,j as A,k as W}from"./chunk-4KVSJNS6.js";import{readFileSync as z,writeFileSync as Pe,readdirSync as Ae,mkdirSync as Ne,statSync as Ue,existsSync as G,unlinkSync as Tt,rmSync as St}from"fs";import{join as b}from"path";import{randomBytes as Fe}from"crypto";var U="compact_boundary";var X=p.object({tool_use_id:p.string(),tool_name:p.string(),arguments:p.record(p.string(),p.unknown()).optional()}),J=p.object({tool_use_id:p.string(),content:p.string(),is_error:p.boolean().optional()}),Q=p.object({role:p.string(),content:p.string().default(""),timestamp:p.number(),type:p.string().optional(),tool_uses:p.array(X).optional(),tool_results:p.array(J).optional()}),Le=p.object({role:p.string(),content:p.string(),tool_uses:p.array(X).optional(),tool_results:p.array(J).optional()});function S(s){return(s??[]).map(e=>({tool_use_id:e.toolUseId,tool_name:e.toolName,...e.arguments&&Object.keys(e.arguments).length?{arguments:e.arguments}:{}}))}function x(s){return(s??[]).map(e=>({tool_use_id:e.toolUseId,content:e.content,...e.isError?{is_error:!0}:{}}))}var Oe=p.object({summary:p.string(),keep:p.array(Le)}),T=w({module:"session"});function E(s){return b(s,".swifty","sessions")}function Z(s,e){return b(E(s),e+".jsonl")}function Mt(){let s=Date.now().toString(36),e=Fe(4).toString("hex");return`${s}-${e}`}function F(s,e,t){let o=E(s);Ne(o,{recursive:!0});let n=b(o,`${e}.jsonl`),r=JSON.stringify(t)+`
|
|
5
|
+
`;Pe(n,r,{flag:"a",encoding:"utf-8"})}function It(s,e,t){F(s,e,{role:"system",content:JSON.stringify(t),timestamp:Math.floor(Date.now()/1e3),type:U})}function Pt(s,e){let t=b(E(s),`${e}.jsonl`);if(!G(t))return[];let o=[];for(let n of z(t,"utf-8").split(`
|
|
6
|
+
`))if(n.trim())try{let r=JSON.parse(n),{success:i,data:a,error:l}=W(Q,r);i?!a.content&&!(a.tool_uses?.length??0)&&!(a.tool_results?.length??0)||o.push(a):T.error({err:l},"session operation failed")}catch(r){T.error({err:r},"session operation failed")}return o}function ee(s){return s?.map(e=>({toolUseId:e.tool_use_id,toolName:e.tool_name,arguments:e.arguments}))}function te(s){return s?.map(e=>({toolUseId:e.tool_use_id,content:e.content,isError:e.is_error}))}function At(s){let e=-1;for(let o=s.length-1;o>=0;o--)if(s[o].type===U){e=o;break}let t=[];if(e>=0){let o=null;try{let n=JSON.parse(s[e].content);o=A(Oe,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:
|
|
7
|
+
|
|
8
|
+
`+o.summary;o.keep.length>0&&(n+=`
|
|
9
|
+
|
|
10
|
+
Recent messages have been preserved verbatim.`),t.push({role:"user",content:n});for(let r of o.keep)r.role!=="user"&&r.role!=="assistant"||!r.content&&!(r.tool_uses?.length??0)&&!(r.tool_results?.length??0)||t.push({role:r.role,content:r.content,toolUses:ee(r.tool_uses),toolResults:te(r.tool_results)})}for(let n=e+1;n<s.length;n++){let r=s[n];if(r.type===U)continue;let i=V(r);i&&t.push(i)}return t}for(let o of s){let n=V(o);n&&t.push(n)}return t}function V(s){return s.role!=="user"&&s.role!=="assistant"||!s.content&&!s.tool_uses?.length&&!s.tool_results?.length?null:{role:s.role,content:s.content,toolUses:ee(s.tool_uses),toolResults:te(s.tool_results)}}function Nt(s){let e=E(s);if(!G(e))return[];let t=Ae(e).filter(n=>n.endsWith(".jsonl")),o=[];for(let n of t){let r=b(e,n),i=Ue(r),a=n.replace(".jsonl",""),l="",c=0;try{for(let h of z(r,"utf-8").split(`
|
|
11
|
+
`)){if(!h.trim())continue;let f;try{let d=JSON.parse(h);f=A(Q,d)}catch(d){T.error({err:d},"session operation failed");continue}c++,!l&&f.role==="user"&&f.content&&(l=f.content.slice(0,100))}}catch(h){T.error({err:h},"session operation failed");continue}o.push({id:a,firstMessage:l,messageCount:c,size:i.size,modTime:i.mtime})}return o.sort((n,r)=>r.modTime.getTime()-n.modTime.getTime()),o}var De=w({module:"agent"}),_=class{pending=[];registry;ctx;constructor(e,t){this.registry=e,this.ctx=t}submit(e,t,o){this.pending.push({toolId:e,toolName:t,arguments:o})}async collectResults(){let e=[...this.pending];this.pending=[];let t=e.map(async o=>{let n=this.registry.get(o.toolName),r=Date.now();if(!n)return{toolId:o.toolId,toolName:o.toolName,result:{output:`Error: unknown tool '${o.toolName}'`,isError:!0},elapsed:0};try{let i=await n.execute(this.ctx,o.arguments);return{toolId:o.toolId,toolName:o.toolName,result:i,elapsed:(Date.now()-r)/1e3}}catch(i){return De.error({err:i},"agent operation failed"),{toolId:o.toolId,toolName:o.toolName,result:{output:`Error executing ${o.toolName}: ${R(i)}`,isError:!0},elapsed:(Date.now()-r)/1e3}}});return Promise.all(t)}hasPending(){return this.pending.length>0}};var C=class{history=[];longTermMemoryInjected=!1;baselineTokens=0;_anchorCount=0;addUserMessage(e){this.history.push({role:"user",content:e})}addAssistantMessage(e){this.history.push({role:"assistant",content:e})}addToolUseMessage(e,t,o,n){this.history.push({role:"assistant",content:e,toolUses:[{toolUseId:t,toolName:o,arguments:n}]})}addAssistantMessageWithTools(e,t){this.history.push({role:"assistant",content:e,toolUses:t})}addAssistantFull(e,t,o){this.history.push({role:"assistant",content:e,thinkingBlocks:t.length>0?t:void 0,toolUses:o.length>0?o:void 0})}addToolResultMessage(e,t,o){this.history.push({role:"user",content:"",toolResults:[{toolUseId:e,content:t,isError:o}]})}addToolResultsMessage(e){this.history.push({role:"user",content:"",toolResults:e})}addSystemReminder(e){this.history.push({role:"user",content:`<system-reminder>
|
|
12
|
+
${e}
|
|
13
|
+
</system-reminder>`})}injectLongTermMemory(e,t){if(this.longTermMemoryInjected)return;let o=[];if(e&&o.push(`# SWIFTY.md
|
|
14
|
+
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.
|
|
15
|
+
|
|
16
|
+
`+e),t&&o.push(`# Auto Memory
|
|
17
|
+
`+t),o.length===0)return;let n=new Date().toISOString().split("T")[0];o.push(`# Current Date
|
|
18
|
+
Today's date is `+n+".");let i=`
|
|
19
|
+
<system-reminder>
|
|
20
|
+
As you answer the user's questions, you can use the following context:
|
|
21
|
+
|
|
22
|
+
${o.join(`
|
|
23
|
+
|
|
24
|
+
`)}
|
|
25
|
+
|
|
26
|
+
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.
|
|
27
|
+
</system-reminder>`;this.history.unshift({role:"user",content:i}),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,t){this.history=[{role:"user",content:e},...t],this.longTermMemoryInjected=!1,this.clearUsageAnchor()}recordUsageAnchor(e,t,o,n){let r=e+o+n+t;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}}};var oe=3,Be=3,je="[earlier conversation truncated for compaction retry]",We=3.5,Ye=1e4,$e=5,qe=4e4,He=2,Ke=2e4,Ve=13e3,ze=3e3;function se(s,e,t=!1){return s-Math.min(e,Ke)-(t?ze:Ve)}var M=class{consecutiveFailures=0};function L(s){let e=0;for(let t of s){if(e+=t.content.length,t.toolUses&&(e+=JSON.stringify(t.toolUses).length),t.toolResults)for(let o of t.toolResults)e+=o.content.length;if(t.thinkingBlocks)for(let o of t.thinkingBlocks)e+=o.thinking.length}return Math.ceil(e/We)}function Ge(s){return L(s.getMessages())}function O(s){return L([s])}function Xe(s){return s.role==="user"&&!!s.toolResults&&s.toolResults.length>0}function Je(s){let e=0,t=0,o=s.length;for(let n=s.length-1;n>=0;n--){let r=O(s[n]);if(t>0&&e+r>qe||(o=n,e+=r,t++,e>=Ye||t>=$e))break}return o=Qe(s,o),o}function Qe(s,e){if(e<=0||e>=s.length||!Xe(s[e]))return e;let t=new Set((s[e].toolResults??[]).map(o=>o.toolUseId));for(let o=e-1;o>=0;o--){let n=s[o];if(n.role==="assistant"&&n.toolUses?.some(r=>t.has(r.toolUseId)))return o}return e}function Ze(s,e){let t=e??s.usageAnchorState();if(!t)return Ge(s);let o=s.getMessages(),n=Math.min(t.anchorCount,o.length);return t.baselineTokens+L(o.slice(n))}async function ne(s,e,t,o,n,r,i,a,l=""){let c=Ze(s),h=se(t,o),f=se(t,o,!0);if(c<h)return{compacted:!1,message:""};if(!(c>=f)&&n.consecutiveFailures>=oe)return{compacted:!1,message:`Auto-compact circuit breaker: ${String(oe)} consecutive failures`};try{let k=await ie(s,e,r,i,a,l);return n.consecutiveFailures=0,k}catch(k){return n.consecutiveFailures++,{compacted:!1,message:`Auto-compact failed: ${R(k)}`}}}async function re(s,e,t,o,n,r=""){return ie(s,e,t,o,n,r)}var et=`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.
|
|
28
|
+
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.
|
|
29
|
+
|
|
30
|
+
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:
|
|
31
|
+
|
|
32
|
+
1. Chronologically analyze each message and section of the conversation. For each section thoroughly identify:
|
|
33
|
+
- The user's explicit requests and intents
|
|
34
|
+
- Your approach to addressing the user's requests
|
|
35
|
+
- Key decisions, technical concepts and code patterns
|
|
36
|
+
- Specific details like:
|
|
37
|
+
- file names
|
|
38
|
+
- full code snippets
|
|
39
|
+
- function signatures
|
|
40
|
+
- file edits
|
|
41
|
+
- Errors that you ran into and how you fixed them
|
|
42
|
+
- Pay special attention to specific user feedback that you received, especially if the user told you to do something differently.
|
|
43
|
+
2. Double-check for technical accuracy and completeness, addressing each required element thoroughly.
|
|
44
|
+
|
|
45
|
+
After your analysis, output your final summary wrapped in <summary> tags. Your summary should include the following sections:
|
|
46
|
+
|
|
47
|
+
1. Primary Request and Intent: Capture all of the user's explicit requests and intents in detail
|
|
48
|
+
2. Key Technical Concepts: List all important technical concepts, technologies, and frameworks discussed.
|
|
49
|
+
3. Files and Code Sections: Enumerate specific files and code sections examined, modified, or created. Pay special attention to the most recent messages and include full code snippets where applicable and include a summary of why this file read or edit is important.
|
|
50
|
+
4. Errors and fixes: List all errors that you ran into, and how you fixed them. Pay special attention to specific user feedback that you received, especially if the user told you to do something differently.
|
|
51
|
+
5. Problem Solving: Document problems solved and any ongoing troubleshooting efforts.
|
|
52
|
+
6. All user messages: List ALL user messages that are not tool results. These are critical for understanding the users' feedback and changing intent.
|
|
53
|
+
7. Pending Tasks: Outline any pending tasks that you have explicitly been asked to work on.
|
|
54
|
+
8. Current Work: Describe in detail precisely what was being worked on immediately before this summary request, paying special attention to the most recent messages from both user and assistant. Include file names and code snippets where applicable.
|
|
55
|
+
9. Optional Next Step: List the next step that you will take that is related to the most recent work you were doing. IMPORTANT: ensure that this step is DIRECTLY in line with the user's most recent explicit requests, and the task you were working on immediately before this summary request. If your last task was concluded, then only list next steps if they are explicitly in line with the users request. Do not start on tangential requests or really old requests that were already completed without confirming with the user first.
|
|
56
|
+
If there is a next step, include direct quotes from the most recent conversation showing exactly what task you were working on and where you left off. This should be verbatim to ensure there's no drift in task interpretation.
|
|
57
|
+
|
|
58
|
+
Here's an example of how your output should be structured:
|
|
59
|
+
|
|
60
|
+
<example>
|
|
61
|
+
<analysis>
|
|
62
|
+
[Your thought process, ensuring all points are covered thoroughly and accurately]
|
|
63
|
+
</analysis>
|
|
64
|
+
|
|
65
|
+
<summary>
|
|
66
|
+
1. Primary Request and Intent:
|
|
67
|
+
[Detailed description]
|
|
68
|
+
|
|
69
|
+
2. Key Technical Concepts:
|
|
70
|
+
- [Concept 1]
|
|
71
|
+
- [Concept 2]
|
|
72
|
+
- [...]
|
|
73
|
+
|
|
74
|
+
3. Files and Code Sections:
|
|
75
|
+
- [File Name 1]
|
|
76
|
+
- [Summary of why this file is important]
|
|
77
|
+
- [Summary of the changes made to this file, if any]
|
|
78
|
+
- [Important Code Snippet]
|
|
79
|
+
- [File Name 2]
|
|
80
|
+
- [Important Code Snippet]
|
|
81
|
+
- [...]
|
|
82
|
+
|
|
83
|
+
4. Errors and fixes:
|
|
84
|
+
- [Detailed description of error 1]:
|
|
85
|
+
- [How you fixed the error]
|
|
86
|
+
- [User feedback on the error if any]
|
|
87
|
+
- [...]
|
|
88
|
+
|
|
89
|
+
5. Problem Solving:
|
|
90
|
+
[Description of solved problems and ongoing troubleshooting]
|
|
91
|
+
|
|
92
|
+
6. All user messages:
|
|
93
|
+
- [Detailed non tool use user message]
|
|
94
|
+
- [...]
|
|
95
|
+
|
|
96
|
+
7. Pending Tasks:
|
|
97
|
+
- [Task 1]
|
|
98
|
+
- [Task 2]
|
|
99
|
+
- [...]
|
|
100
|
+
|
|
101
|
+
8. Current Work:
|
|
102
|
+
[Precise description of current work]
|
|
103
|
+
|
|
104
|
+
9. Optional Next Step:
|
|
105
|
+
[Optional Next step to take]
|
|
106
|
+
|
|
107
|
+
</summary>
|
|
108
|
+
</example>
|
|
109
|
+
|
|
110
|
+
Please provide your summary based on the conversation so far, following this structure and ensuring precision and thoroughness in your response.`;function tt(s){return et+`
|
|
111
|
+
|
|
112
|
+
`+s}function ot(s){let e=[],t=[],o=!1;for(let n of s)n.role==="assistant"&&o&&t.length>0&&(e.push(t),t=[]),t.push(n),o=!!(n.toolResults&&n.toolResults.length>0);return t.length>0&&e.push(t),e}function st(s,e){let t=ot(s);if(t.length<2)return null;let o;if(e>0){let r=0;o=0;for(let i of t)if(r+=i.reduce((a,l)=>a+O(l),0),o++,r>=e)break}else o=Math.max(1,Math.floor(t.length/5));if(o=Math.min(o,t.length-1),o<1)return null;let n=t.slice(o).flat();return n.length>0&&n[0].role!=="user"&&n.unshift({role:"user",content:je}),n}function nt(s){return s.map(e=>{let t=`[${e.role}]: ${e.content}`;return e.toolUses&&(t+=`
|
|
113
|
+
[tools: ${e.toolUses.map(o=>o.toolName).join(", ")}]`),t}).join(`
|
|
114
|
+
|
|
115
|
+
`)}async function rt(s,e,t){let o=e;for(let n=0;;n++){let r=nt(o),i=new C;i.addUserMessage(tt(r));try{let a="",l=s.stream(i,t);for await(let h of l)h.type==="text_delta"&&(a+=h.text);let c=/<summary>([\s\S]*?)<\/summary>/.exec(a);return c?c[1].trim():a}catch(a){let l=a instanceof Error?a.message.toLowerCase():"";if(!(l.includes("prompt")&&l.includes("long")||l.includes("too many")||l.includes("context_length"))||n>=Be)throw a;let h=o.reduce((d,k)=>d+O(k),0)/5,f=st(o,h);if(!f)throw a;o=f}}}async function ie(s,e,t,o,n,r=""){let i=s.getMessages(),a=Je(i);if(a<=0||a<He)return{compacted:!1,message:`Compaction skipped: only ${String(a)} message(s) to summarize, kept verbatim`};let l=i.slice(0,a),c=i.slice(a),h=await rt(e,l,n),f=t?t.buildRecoveryAttachment(o):"",d=`This session continues from a previous conversation, which has been compressed due to context limitations. Here is a summary of the earlier messages:
|
|
116
|
+
|
|
117
|
+
`+h;c.length>0&&(d+=`
|
|
118
|
+
|
|
119
|
+
Recent messages have been preserved verbatim.`),r&&(d+=`
|
|
120
|
+
|
|
121
|
+
If you need specific details from before compaction (code snippets, error messages, etc.), use ReadFile to read the full session transcript: ${r}`),f&&(d+=`
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
${f}`),s.replaceWithCompacted(d,c);let k=c.filter(u=>(u.role==="user"||u.role==="assistant")&&(u.content||(u.toolUses?.length??0)||(u.toolResults?.length??0))).map(u=>({role:u.role,content:u.content,...u.toolUses?.length?{tool_uses:S(u.toolUses)}:{},...u.toolResults?.length?{tool_results:x(u.toolResults)}:{}}));return{compacted:!0,message:`Compacted ${String(l.length)} messages into summary (${String(h.length)} chars), kept ${String(c.length)} recent messages verbatim`,boundary:{summary:h,keep:k}}}function D(s){return s?Math.floor(s.length/3.5):0}function ae(s,e){if(e<=0||!s||D(s)<=e)return s;let t=Math.floor(e*3.5);return t<=0||t>=s.length?s:s.slice(0,t)+`
|
|
126
|
+
\u2026 (content truncated)`}var I=class{files=new Map;skills=new Map;recordFileRead(e,t){this.files.set(e,{path:e,content:t,timestamp:Date.now()})}recordSkillInvocation(e,t){this.skills.set(e,{name:e,body:t,timestamp:Date.now()})}snapshotFiles(e=5){return[...this.files.values()].sort((o,n)=>n.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
|
|
127
|
+
`),t.push(`These snapshots are what the file-reading tool last returned. Re-open with the tool if you need the current bytes.
|
|
128
|
+
`);for(let r of o){let i=ae(r.content,5e3),a=new Date(r.timestamp).toISOString().replace(/\.\d{3}Z$/,"Z");t.push(`### ${r.path} (read ${a})
|
|
129
|
+
|
|
130
|
+
\`\`\`
|
|
131
|
+
${i}${i.endsWith(`
|
|
132
|
+
`)?"":`
|
|
133
|
+
`}\`\`\``)}}let n=this.snapshotSkills();if(n.length>0){let r=0,i=[];i.push(`## Active skills
|
|
134
|
+
`),i.push(`These skills were invoked earlier in the session. Continue to follow each SOP when its triggering condition applies.
|
|
135
|
+
`);let a=!1;for(let l of n){let c=ae(l.body,5e3),h=D(c)+D(l.name)+8;if(r+h>25e3)break;r+=h,i.push(`### ${l.name}
|
|
136
|
+
|
|
137
|
+
${c}`),a=!0}a&&t.push(i.join(`
|
|
138
|
+
|
|
139
|
+
`))}return e.length>0&&t.push(`## Available tools
|
|
140
|
+
|
|
141
|
+
You still have access to the following tools \u2014 call them directly when the task needs one:
|
|
142
|
+
|
|
143
|
+
`+e.map(r=>`- ${r}`).join(`
|
|
144
|
+
`)),t.length===0?"":(t.push(`## Note
|
|
145
|
+
|
|
146
|
+
Everything above the divider is reconstructed context. For exact code, error strings, or user-typed text, re-read the source rather than guess from the summary.`),t.join(`
|
|
147
|
+
|
|
148
|
+
`))}};import{readFileSync as it,writeFileSync as at,mkdirSync as lt,existsSync as B}from"fs";import{join as le,resolve as ce}from"path";var de=w({module:"plan-file"}),ue=["brave","calm","dark","eager","fair","gentle","happy","kind","lively","mighty","noble","proud","quiet","swift","warm","wise"],he=["crystal","dragon","eagle","falcon","flame","forest","frost","mountain","ocean","phoenix","river","shadow","thunder","tiger"];function ct(){let s=ue[Math.floor(Math.random()*ue.length)],e=he[Math.floor(Math.random()*he.length)],t=Date.now().toString(36).slice(-4);return`${s}-${e}-${t}`}var y=null;function me(s,e){let t=ce(e,".swifty","plans");return ce(s).startsWith(t+"/")}function pe(s){if(y&&B(y))if(!me(y,s))de.warn({planPath:y,workDir:s},"current plan path is not under work dir");else return y;let e=le(s,".swifty","plans");lt(e,{recursive:!0});let t=ct();return y=le(e,`${t}.md`),at(y,"","utf-8"),y}function Vt(){return!y||!B(y)?null:it(y,"utf-8")}function ge(s){return!y||!B(y)?!1:me(y,s)?!0:(de.warn({planPath:y,workDir:s},"current plan path is not under work dir"),!1)}function zt(){y=null}var fe=`Plan mode is active. The user indicated that they do not want you to execute yet -- you MUST NOT make any edits (with the exception of the plan file mentioned below), run any non-readonly tools (including changing configs or making commits), or otherwise make any changes to the system. This supersedes any other instructions you have received.
|
|
149
|
+
|
|
150
|
+
## Plan File Info:
|
|
151
|
+
|
|
152
|
+
%PLAN_FILE_INFO%
|
|
153
|
+
You should build your plan incrementally by writing to or editing this file. NOTE that this is the only file you are allowed to edit - other than this you are only allowed to take READ-ONLY actions.
|
|
154
|
+
|
|
155
|
+
## Plan Workflow
|
|
156
|
+
|
|
157
|
+
### Phase 1: Initial Understanding
|
|
158
|
+
|
|
159
|
+
Goal: Gain a comprehensive understanding of the user's request by reading through code and asking them questions. Critical: In this phase you should use the Agent tool with subagent_type="explore".
|
|
160
|
+
|
|
161
|
+
1. Focus on understanding the user's request and the code associated with their request. Actively search for existing functions, utilities, and patterns that can be reused \u2014 avoid proposing new code when suitable implementations already exist.
|
|
162
|
+
|
|
163
|
+
2. **Call the Agent tool with subagent_type="explore" to explore the codebase.** You can launch up to 3 explore agents IN PARALLEL by making multiple Agent tool calls in a single response.
|
|
164
|
+
|
|
165
|
+
### Phase 2: Design
|
|
166
|
+
|
|
167
|
+
Goal: Design an implementation approach.
|
|
168
|
+
|
|
169
|
+
Call the Agent tool with subagent_type="plan" to design the implementation based on the user's intent and your exploration results from Phase 1.
|
|
170
|
+
|
|
171
|
+
### Phase 3: Review
|
|
172
|
+
|
|
173
|
+
Goal: Review the plan(s) from Phase 2 and ensure alignment with the user's intentions.
|
|
174
|
+
|
|
175
|
+
1. Read the critical files identified by agents to deepen your understanding
|
|
176
|
+
2. Ensure that the plans align with the user's original request
|
|
177
|
+
3. Use AskUserQuestion to clarify any remaining questions with the user.
|
|
178
|
+
|
|
179
|
+
### Phase 4: Final Plan
|
|
180
|
+
|
|
181
|
+
Goal: Write your final plan to the plan file (the only file you can edit).
|
|
182
|
+
|
|
183
|
+
- Begin with a **Context** section
|
|
184
|
+
- Include only your recommended approach
|
|
185
|
+
- Include the paths of critical files to be modified
|
|
186
|
+
- Include a verification section
|
|
187
|
+
|
|
188
|
+
### Phase 5: Call ExitPlanMode
|
|
189
|
+
|
|
190
|
+
At the very end of your turn, once you have asked the user questions and are happy with your final plan file - you should always call ExitPlanMode.
|
|
191
|
+
`,ut="Plan mode still active (see full instructions earlier in conversation). Read-only except plan file (%PLAN_PATH%). Follow 5-phase workflow. End turns with AskUserQuestion (for clarifications) or ExitPlanMode (for plan approval). Never ask about plan approval via text or AskUserQuestion.",ht=`## Exited Plan Mode
|
|
192
|
+
|
|
193
|
+
You have exited plan mode. You can now make edits, run tools, and take actions.%EXTRA%`,dt="You have re-entered plan mode. Your previous plan file is at %PLAN_PATH%. Review it and continue from where you left off. You can update, refine, or restart the plan as needed. Follow the same 5-phase workflow as before.";function ye(s,e,t){let o=`Plan file: ${s}`;return e?o+=`
|
|
194
|
+
A plan file already exists at ${s}. You can read it and make incremental edits using the EditFile tool.`:o+=`
|
|
195
|
+
No plan file exists yet. You should create your plan at ${s} using the WriteFile tool.`,t===1||Math.floor((t-1)/5)%5===0?fe.replace("%PLAN_FILE_INFO%",o):ut.replace("%PLAN_PATH%",s)}function Xt(s,e){let t="";return e&&(t=` The plan file is located at ${s} if you need to reference it.`),ht.replace("%EXTRA%",t)}function Jt(s,e){return e?dt.replace("%PLAN_PATH%",s):""}var mt=`You are Swifty, an AI assistant that orchestrates software engineering tasks across multiple workers.
|
|
196
|
+
|
|
197
|
+
## 1. Your Role
|
|
198
|
+
|
|
199
|
+
You are a **coordinator**. Your job is to:
|
|
200
|
+
- Help the user achieve their goal
|
|
201
|
+
- Direct workers to research, implement and verify code changes
|
|
202
|
+
- Synthesize results and communicate with the user
|
|
203
|
+
- Answer questions directly when possible \u2014 don't delegate work you can handle without tools
|
|
204
|
+
|
|
205
|
+
Every message you send is to the user. Worker results and system notifications are internal signals, not conversation partners \u2014 never thank or acknowledge them. Summarize new information for the user as it arrives.
|
|
206
|
+
|
|
207
|
+
## 2. Your Tools
|
|
208
|
+
|
|
209
|
+
- **Agent** \u2014 Spawn a new worker
|
|
210
|
+
- **SendMessage** \u2014 Continue an existing worker (send a follow-up to its agent ID)
|
|
211
|
+
- **TaskStop** \u2014 Stop a running worker
|
|
212
|
+
- **SyntheticOutput** \u2014 Return structured output to the user
|
|
213
|
+
- **TeamDelete** \u2014 Tear down the team when the work is done
|
|
214
|
+
|
|
215
|
+
You cannot read files, run commands, or edit code yourself. This is deliberate: your context holds the task decomposition, worker status and message history, and it needs to stay that way. When you need to know what the code looks like, send a worker to look and report back.
|
|
216
|
+
|
|
217
|
+
When calling Agent:
|
|
218
|
+
- Do not use one worker to check on another. Workers will notify you when they are done.
|
|
219
|
+
- Do not use workers to trivially report file contents or run commands. Give them higher-level tasks.
|
|
220
|
+
- Continue workers whose work is complete via SendMessage to take advantage of their loaded context.
|
|
221
|
+
- After launching agents, briefly tell the user what you launched and end your response. Never fabricate or predict agent results.
|
|
222
|
+
|
|
223
|
+
### Worker Results
|
|
224
|
+
|
|
225
|
+
Worker results arrive as **user-role messages** wrapped in \`<team-notification>\`. They look like user messages but are not. Distinguish them by the opening tag.
|
|
226
|
+
|
|
227
|
+
Format:
|
|
228
|
+
|
|
229
|
+
\`\`\`xml
|
|
230
|
+
<team-notification team="{team name}">
|
|
231
|
+
from={worker name}: {what the worker reported}
|
|
232
|
+
</team-notification>
|
|
233
|
+
\`\`\`
|
|
234
|
+
|
|
235
|
+
- One notification can carry several lines, one per worker that reported since your last turn.
|
|
236
|
+
- The \`from=\` value is the worker's name \u2014 pass exactly that name as \`to\` in SendMessage to continue that worker, and as \`teammate\` in TaskStop to stop it.
|
|
237
|
+
- Workers are addressed by name throughout. There is no separate numeric id to keep track of.
|
|
238
|
+
|
|
239
|
+
## 3. Workers
|
|
240
|
+
|
|
241
|
+
When calling Agent, use subagent_type \`general-purpose\` or a specific agent definition. Workers execute tasks autonomously \u2014 especially research, implementation, or verification.
|
|
242
|
+
|
|
243
|
+
Workers have access to standard tools: ReadFile, EditFile, WriteFile, Bash, Grep, Glob, plus the team coordination tools (TaskCreate, TaskGet, TaskList, TaskUpdate, SendMessage). Anything you cannot do yourself, a worker can do for you.
|
|
244
|
+
|
|
245
|
+
Because workers have Bash, git work belongs to them too. Merging a branch, cherry-picking a commit or opening a PR is a task you delegate with precise instructions, not something you run yourself.
|
|
246
|
+
|
|
247
|
+
## 4. Task Workflow
|
|
248
|
+
|
|
249
|
+
### Phases
|
|
250
|
+
|
|
251
|
+
Most tasks break down into four phases:
|
|
252
|
+
|
|
253
|
+
| Phase | Who | Purpose |
|
|
254
|
+
|-------|-----|---------|
|
|
255
|
+
| Research | Workers (parallel) | Investigate codebase, find files, understand the problem |
|
|
256
|
+
| Synthesis | **You** (coordinator) | Read findings, understand the problem, craft implementation specs |
|
|
257
|
+
| Implementation | Workers | Make targeted changes per spec, commit |
|
|
258
|
+
| Verification | Workers | Test that changes work |
|
|
259
|
+
|
|
260
|
+
### Concurrency
|
|
261
|
+
|
|
262
|
+
**Parallelism is your superpower. Workers are async. Launch independent workers concurrently whenever possible. To launch workers in parallel, make multiple tool calls in a single message.**
|
|
263
|
+
|
|
264
|
+
- **Read-only tasks** (research) \u2014 run in parallel freely
|
|
265
|
+
- **Write-heavy tasks** (implementation) \u2014 one at a time per set of files
|
|
266
|
+
- **Verification** can sometimes run alongside implementation on different file areas
|
|
267
|
+
|
|
268
|
+
### Verification MUST be a separate worker
|
|
269
|
+
|
|
270
|
+
**Never let the implementation worker verify its own work.** Spawn a fresh worker after implementation completes. The implementation worker is anchored on its own approach and will rubber-stamp its own code; a fresh verifier sees the code with no assumptions.
|
|
271
|
+
|
|
272
|
+
Real verification means running tests with the feature enabled, investigating typecheck errors instead of dismissing them as unrelated, and proving the change works rather than confirming it exists.
|
|
273
|
+
|
|
274
|
+
### Handling Worker Failures
|
|
275
|
+
|
|
276
|
+
When a worker reports failure, continue that same worker with SendMessage \u2014 it has the full error context. If a correction attempt fails, try a different approach or report to the user.
|
|
277
|
+
|
|
278
|
+
### Stopping Workers
|
|
279
|
+
|
|
280
|
+
Use TaskStop on a worker you sent in the wrong direction, for example when the user changes requirements after you launched it. Stopped workers can be continued later with SendMessage.
|
|
281
|
+
|
|
282
|
+
## 5. Writing Worker Prompts
|
|
283
|
+
|
|
284
|
+
**Workers can't see your conversation.** Every prompt must be self-contained.
|
|
285
|
+
|
|
286
|
+
### Always synthesize \u2014 your most important job
|
|
287
|
+
|
|
288
|
+
When workers report research findings, you must understand them before directing follow-up work. Read the findings, identify the approach, then write a prompt that proves you understood it by naming specific file paths, line numbers, and exactly what to change.
|
|
289
|
+
|
|
290
|
+
Never write "based on your findings" or "based on the research". These phrases hand your understanding off to a worker, which is the one thing you must not delegate.
|
|
291
|
+
|
|
292
|
+
\`\`\`
|
|
293
|
+
// Anti-pattern \u2014 lazy delegation
|
|
294
|
+
Agent(prompt="Based on your findings, fix the auth bug")
|
|
295
|
+
|
|
296
|
+
// Good \u2014 synthesized spec
|
|
297
|
+
Agent(prompt="Fix the null pointer in src/auth/validate.ts:42. The user field on Session is undefined when the session expires but the token is still cached. Add a null check before accessing user.id \u2014 if null, return 401 with 'Session expired'. Commit and report the hash.")
|
|
298
|
+
\`\`\`
|
|
299
|
+
|
|
300
|
+
### Add a purpose statement
|
|
301
|
+
|
|
302
|
+
Include a brief purpose so workers can calibrate depth and emphasis:
|
|
303
|
+
- "This research will inform a PR description \u2014 focus on user-facing changes."
|
|
304
|
+
- "I need this to plan an implementation \u2014 report file paths, line numbers, and type signatures."
|
|
305
|
+
- "This is a quick check before we merge \u2014 just verify the happy path."
|
|
306
|
+
|
|
307
|
+
### Choose continue vs. spawn by context overlap
|
|
308
|
+
|
|
309
|
+
| Situation | Mechanism | Why |
|
|
310
|
+
|-----------|-----------|-----|
|
|
311
|
+
| Research explored exactly the files that need editing | **Continue** (SendMessage) | Worker already has the files in context |
|
|
312
|
+
| Research was broad but implementation is narrow | **Spawn fresh** (Agent) | Avoid dragging along exploration noise |
|
|
313
|
+
| Correcting a failure or extending recent work | **Continue** | Worker has the error context |
|
|
314
|
+
| Verifying code a different worker just wrote | **Spawn fresh** | Verifier should see the code with fresh eyes |
|
|
315
|
+
| First attempt used the wrong approach entirely | **Spawn fresh** | Wrong-approach context pollutes the retry |
|
|
316
|
+
|
|
317
|
+
### Prompt tips
|
|
318
|
+
|
|
319
|
+
- Include file paths, line numbers and error messages \u2014 workers start fresh and need complete context
|
|
320
|
+
- State what "done" looks like
|
|
321
|
+
- For implementation: "Run relevant tests, then commit and report the hash"
|
|
322
|
+
- For research: "Report findings \u2014 do not modify files"
|
|
323
|
+
- Be precise about git operations: name the branch, the commit hash, draft vs ready
|
|
324
|
+
- For verification: "Prove the code works, don't just confirm it exists"
|
|
325
|
+
|
|
326
|
+
## 6. Example Session
|
|
327
|
+
|
|
328
|
+
User: "There's a null pointer in the auth module. Can you fix it?"
|
|
329
|
+
|
|
330
|
+
You:
|
|
331
|
+
Let me investigate first.
|
|
332
|
+
|
|
333
|
+
Agent({ description: "Investigate auth bug", subagent_type: "general-purpose", prompt: "Investigate the auth module in src/auth/. Find where null pointer errors could occur around session handling and token validation. Report specific file paths, line numbers, and types involved. Do not modify files." })
|
|
334
|
+
Agent({ description: "Research auth tests", subagent_type: "general-purpose", prompt: "Find all test files related to src/auth/. Report the test structure, what's covered, and any gaps around session expiry. Do not modify files." })
|
|
335
|
+
|
|
336
|
+
Investigating from two angles \u2014 I'll report back with findings.
|
|
337
|
+
|
|
338
|
+
User:
|
|
339
|
+
<team-notification team="auth-fix">
|
|
340
|
+
from=investigator: Found null pointer in src/auth/validate.ts:42. The user field on Session is undefined when the session expires but the token is still cached.
|
|
341
|
+
</team-notification>
|
|
342
|
+
|
|
343
|
+
You:
|
|
344
|
+
Found the bug \u2014 null pointer in validate.ts:42.
|
|
345
|
+
|
|
346
|
+
SendMessage({ to: "investigator", message: "Fix the null pointer in src/auth/validate.ts:42. Add a null check before accessing user.id \u2014 if null, return 401. Commit and report the hash." })
|
|
347
|
+
|
|
348
|
+
Fix is in progress.`,pt="Coordinator mode still active (see full instructions earlier in conversation). You cannot read files, run commands, or edit code \u2014 send a worker instead. Tools: Agent, SendMessage, TaskStop, SyntheticOutput, TeamDelete. Address workers by the name in the from= field of a team-notification. Synthesize worker findings yourself before directing follow-up work.";function ke(s=1){return s<=1||(s-1)%5===0?mt:pt}import{writeFileSync as gt,mkdirSync as ft}from"fs";import{join as be,resolve as we}from"path";var yt=w({module:"tool-result"}),ve=2e5;function Re(s,e){return be(s,".swifty","sessions",e||"default","tool-results")}function Te(s,e,t,o){let n=Re(s,e);ft(n,{recursive:!0});let r=be(n,t+".txt");try{gt(r,o,{encoding:"utf-8",flag:"wx"})}catch(i){if(yt.error({err:i},"tool-result operation failed"),$(i)&&"code"in i&&i.code!=="EEXIST")throw i}return r}var j=2e3;function Se(s,e){let t=Math.floor(s.length/1024),o=s.slice(0,j),n=s.length>j,r=`<persisted-output>
|
|
349
|
+
`;return r+=`Output too large (${String(t)}KB). Full content saved to:
|
|
350
|
+
${e}
|
|
351
|
+
|
|
352
|
+
`,r+=`Preview (first 2KB):
|
|
353
|
+
${o}`,n&&(r+=`
|
|
354
|
+
...`),r+=`
|
|
355
|
+
</persisted-output>`,r}function xe(s,e,t,o){if(s!=="ReadFile"||!e)return!1;let n=e.file_path;return typeof n!="string"||!n?!1:we(n).startsWith(we(Re(t,o)))}function Ee(s,e,t,o){let n=s.reduce((i,a)=>i+a.content.length,0);if(n<=ve)return;let r=[...s].sort((i,a)=>a.content.length-i.content.length);for(let i of r){if(n<=ve)break;if(o?.has(i.toolUseId)||i.content.length<=j)continue;let a;try{a=Te(e,t,i.toolUseId,i.content)}catch{continue}let l=Se(i.content,a);n-=i.content.length-l.length,i.content=l}}function _e(s,e,t,o){let n;try{n=Te(s,e,t,o)}catch{return o}return Se(o,n)}import{readFile as kt}from"fs/promises";var wt=64e3,Ce=3,vt=5e4,Me=class{client;registry;checker;conversation;workDir;sessionId;sessionFilePath;hookEngine;fileHistory;fileStateCache;abortSignal;contextWindow;maxOutput;recoveryState;maxIterations;notificationFn;onLoopComplete;compactTracking=new M;onPermissionRequest;toolFilter;coordinatorActiveFn;activeSkills;instructions;memoryContent;memoryRecallPromise;memoryRecallConsumed=!1;constructor(e){this.client=e.client,this.registry=e.registry,this.checker=e.checker,this.conversation=e.conversation,this.workDir=e.workDir,this.sessionId=e.sessionId??"",this.sessionFilePath=e.sessionId?Z(e.workDir,e.sessionId):"",this.hookEngine=e.hookEngine,this.fileHistory=e.fileHistory,this.fileStateCache=e.fileStateCache,this.abortSignal=e.abortSignal,this.contextWindow=e.contextWindow??2e5,this.maxOutput=e.maxOutput??8192,this.recoveryState=e.recoveryState??new I,this.maxIterations=e.maxIterations??0,this.notificationFn=e.notificationFn,this.onLoopComplete=e.onLoopComplete,this.onPermissionRequest=e.onPermissionRequest,this.activeSkills=e.activeSkills??new Map,this.toolFilter=e.toolFilter,this.coordinatorActiveFn=e.coordinatorActiveFn,this.instructions=e.instructions??"",this.memoryContent=e.memoryContent??"",this.memoryRecallPromise=e.memoryRecallPromise}async*run(){let e=this.registry.getAllSchemas();this.toolFilter&&(e=e.filter(a=>this.toolFilter?.(a.name)));let t=this.registry.listTools().map(a=>a.name),o=!1,n=0,r=0,i=0;await this.fireLifecycle("session_start");try{let a=!0;for(;a;){if(i++,this.maxIterations>0&&i>this.maxIterations){yield{type:"error",error:new Error(`Agent reached maximum iterations (${String(this.maxIterations)})`)};return}let l="",c=[],h=[],f="end_turn",d=null;if(this.checker.mode==="plan"){let u=pe(this.workDir);this.checker.planFilePath=u,this.conversation.addSystemReminder(ye(u,ge(this.workDir),i))}if(this.coordinatorActiveFn?.()&&this.conversation.addSystemReminder(ke(i)),this.hookEngine)for(let u of this.hookEngine.drainNotifications())this.conversation.addSystemReminder(u);if(this.notificationFn)for(let u of this.notificationFn())this.conversation.addSystemReminder(u);await this.fireLifecycle("turn_start"),await this.fireLifecycle("pre_send");let k=await ne(this.conversation,this.client,this.contextWindow,this.maxOutput,this.compactTracking,this.recoveryState,t,e,this.sessionFilePath);k.message&&(yield{type:"compact",message:k.message,boundary:k.boundary}),k.compacted&&this.conversation.injectLongTermMemory(this.instructions,this.memoryContent);try{let u=this.client.stream(this.conversation,e,this.abortSignal);for await(let m of u){if(this.abortSignal?.aborted){a=!1;break}switch(m.type){case"text_delta":l+=m.text,yield{type:"stream_text",text:m.text};break;case"thinking_delta":yield{type:"thinking_text",text:m.text};break;case"thinking_complete":c.push({thinking:m.thinking,signature:m.signature}),yield{type:"thinking_complete",thinking:m.thinking,signature:m.signature};break;case"tool_call_start":break;case"tool_call_complete":h.push({toolUseId:m.toolId,toolName:m.toolName,arguments:m.arguments}),yield{type:"tool_use",toolName:m.toolName,toolId:m.toolId,args:m.arguments};break;case"stream_end":f=m.stopReason,d=m.usage,yield{type:"usage",usage:m.usage};break}}}catch(u){if(this.abortSignal?.aborted){yield{type:"loop_complete",stopReason:"interrupted"};return}if(u instanceof K)try{let m=await re(this.conversation,this.client,this.recoveryState,t,e,this.sessionFilePath);this.conversation.clearUsageAnchor(),this.conversation.injectLongTermMemory(this.instructions,this.memoryContent),yield{type:"compact",message:"Auto-compacted due to context length: "+m.message,boundary:m.boundary};continue}catch{yield{type:"error",error:u};return}if(u instanceof H){let m=bt(N(Y(u),"retryAfter"));if(yield{type:"retry",reason:"rate limited",delay:m},await this.interruptibleSleep(m)){yield{type:"loop_complete",stopReason:"interrupted"};return}continue}yield{type:"error",error:u};return}if(this.abortSignal?.aborted){l&&(this.conversation.addAssistantFull(l,c,[]),this.persistLastMessage()),yield{type:"loop_complete",stopReason:"interrupted"};return}if(await this.fireLifecycle("post_receive",l),f==="max_tokens")if(o){if(n<Ce){n++,this.conversation.addAssistantFull(l,c,[]),this.persistLastMessage(),d&&this.conversation.recordUsageAnchor(d.inputTokens,d.outputTokens,d.cacheReadInputTokens,d.cacheCreationInputTokens),this.conversation.addUserMessage("Output token limit hit. Resume directly from where you stopped. Break remaining work into smaller pieces."),yield{type:"retry",reason:`max_tokens recovery ${String(n)}/${String(Ce)}`,delay:0};continue}}else{this.client.setMaxOutputTokens?.(wt),o=!0,l&&(this.conversation.addAssistantFull(l,c,[]),this.persistLastMessage(),d&&this.conversation.recordUsageAnchor(d.inputTokens,d.outputTokens,d.cacheReadInputTokens,d.cacheCreationInputTokens),this.conversation.addUserMessage("Output token limit hit. Resume directly from where you stopped. Do not apologize or repeat previous content. Pick up mid-thought if needed.")),yield{type:"retry",reason:"max_tokens escalation",delay:0};continue}else n=0;if(this.conversation.addAssistantFull(l,c,h),this.persistLastMessage(),d&&this.conversation.recordUsageAnchor(d.inputTokens,d.outputTokens,d.cacheReadInputTokens,d.cacheCreationInputTokens),h.length>0){let u=await this.executeTools(h);for(let g of u)yield g;for(let g of h)this.registry.get(g.toolName)?r=0:r++;if(r>=3){yield{type:"error",error:new Error("Too many consecutive unknown tool calls")};return}let m=new Set;for(let g of h)xe(g.toolName,g.arguments,this.workDir,this.sessionId)&&m.add(g.toolUseId);let P=[];for(let g of u)if(g.type==="tool_result"){let v=g.output;v.length>vt&&!m.has(g.toolId)&&(v=_e(this.workDir,this.sessionId,g.toolId,g.output),m.add(g.toolId)),P.push({toolUseId:g.toolId,content:v,isError:g.isError})}Ee(P,this.workDir,this.sessionId,m);let Ie=h.some(g=>g.toolName==="ExitPlanMode");if(this.conversation.addToolResultsMessage(P),this.persistLastMessage(),this.memoryRecallPromise&&!this.memoryRecallConsumed)try{let g=await Promise.race([this.memoryRecallPromise.then(v=>({done:!0,value:v})),Promise.resolve({done:!1,value:""})]);g.done&&(g.value&&this.conversation.addSystemReminder(g.value),this.memoryRecallConsumed=!0)}catch{this.memoryRecallConsumed=!0}if(Ie){yield{type:"turn_complete"},yield{type:"loop_complete",stopReason:"end_turn"};return}yield{type:"turn_complete"},await this.fireLifecycle("turn_end")}else{if(a=!1,this.fileHistory){let u=l.length>60?l.slice(0,60)+"...":l;this.fileHistory.makeSnapshot(this.conversation.len(),u)}if(yield{type:"loop_complete",stopReason:f},this.onLoopComplete)try{this.onLoopComplete(this.conversation)}catch{}}}}finally{await this.fireLifecycle("session_end")}}async fireLifecycle(e,t){if(!this.hookEngine)return;let o=await this.hookEngine.fire(e,{event:e,message:t});for(let n of o)n.output&&this.hookEngine.recordNotification(n.output)}interruptibleSleep(e){return new Promise(t=>{if(this.abortSignal?.aborted){t(!0);return}let o=()=>{clearTimeout(n),t(!0)},n=setTimeout(()=>{this.abortSignal?.removeEventListener("abort",o),t(!1)},e);this.abortSignal?.addEventListener("abort",o,{once:!0})})}async executeTools(e){let t=[],o=this.partitionToolCalls(e);for(let n of o){let r=await this.executeBatch(n.blocks,n.concurrent&&n.blocks.length>1);t.push(...r)}return t}partitionToolCalls(e){let t=[];for(let o of e){let r=(this.registry.get(o.toolName)?.category??"command")==="read";r&&t.length>0&&t[t.length-1].concurrent?t[t.length-1].blocks.push(o):t.push({concurrent:r,blocks:[o]})}return t}async executeBatch(e,t){let o=[],n=new _(this.registry,{workDir:this.workDir,fileHistory:this.fileHistory,fileStateCache:this.fileStateCache});for(let r of e){if(this.hookEngine){let c=await this.hookEngine.firePreToolHooks(r.toolName,r.arguments);if(c.rejected){o.push({type:"tool_result",toolName:r.toolName,toolId:r.toolUseId,output:`Rejected by hook: ${c.reason}`,isError:!0,elapsed:0});continue}}let a=this.registry.get(r.toolName)?.category??"command",l=this.checker.check(r.toolName,a,r.arguments);if(l.effect==="deny"){o.push({type:"tool_result",toolName:r.toolName,toolId:r.toolUseId,output:`Permission denied: ${l.reason}. This operation has been blocked by the security policy. Inform the user that the command was denied; do not describe what the command would do.`,isError:!0,elapsed:0});continue}if(l.effect==="ask"&&this.onPermissionRequest){let c=await this.onPermissionRequest(r.toolName,r.arguments,l);if(c==="deny"){o.push({type:"tool_result",toolName:r.toolName,toolId:r.toolUseId,output:q,isError:!0,elapsed:0});continue}c==="allowAlways"&&this.checker.allowAlways(r.toolName,r.arguments)}if(n.submit(r.toolUseId,r.toolName,r.arguments),!t){let c=await n.collectResults();for(let h of c)await this.processToolResult(h,e,o)}}if(t){let r=await n.collectResults();for(let i of r)await this.processToolResult(i,e,o)}return o}async processToolResult(e,t,o){if(!e.result.isError&&e.toolName==="ReadFile"){let n=t.find(i=>i.toolUseId===e.toolId),r=N(n?.arguments??{},"file_path");if(r)try{this.recoveryState.recordFileRead(r,await kt(r,"utf-8"))}catch{}}if(o.push({type:"tool_result",toolName:e.toolName,toolId:e.toolId,output:e.result.output,isError:e.result.isError,elapsed:e.elapsed}),this.hookEngine){let n=await this.hookEngine.fire("post_tool_use",{event:"post_tool_use",toolName:e.toolName,message:e.result.output});for(let r of n)r.output&&this.hookEngine.recordNotification(r.output)}}persistLastMessage(){if(!this.workDir||!this.sessionId)return;let e=this.conversation.getMessages();if(e.length===0)return;let t=e[e.length-1];F(this.workDir,this.sessionId,{role:t.role,content:t.content,timestamp:Math.floor(Date.now()/1e3),...t.toolUses?.length?{tool_uses:S(t.toolUses)}:{},...t.toolResults?.length?{tool_results:x(t.toolResults)}:{}})}};function bt(s){if(!s)return 5e3;let e=parseInt(s,10);return Number.isNaN(e)?5e3:e*1e3}export{C as a,Z as b,Mt as c,F as d,It as e,Pt as f,At as g,Nt as h,re as i,I as j,pe as k,Vt as l,ge as m,zt as n,Xt as o,Jt as p,Me as q};
|
|
@@ -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
|
+
var g="Tool execution was interrupted. The tool may or may not have completed; verify before relying on its effects.",p="The user rejected this tool use. Nothing was changed (for file edits, the new content was NOT written).";function x(o){let t=new Set,l=new Set;for(let e of o){for(let s of e.toolResults??[])t.add(s.toolUseId);for(let s of e.toolUses??[])l.add(s.toolUseId)}let c=[];for(let e of o){let s=e;if((e.toolResults?.length??0)>0){let n=(e.toolResults??[]).filter(h=>l.has(h.toolUseId));if(n.length===0&&!e.content&&!(e.toolUses?.length??0))continue;s={...e,toolResults:n}}c.push(s);let i=[];for(let n of e.toolUses??[])t.has(n.toolUseId)||(i.push({toolUseId:n.toolUseId,content:g,isError:!0}),t.add(n.toolUseId));i.length>0&&c.push({role:"user",content:"",toolResults:i})}return c}var r=class extends Error{constructor(t){super(t),this.name="LLMError"}},u=class extends r{constructor(t){super(t),this.name="AuthenticationError"}},a=class extends r{retryAfter;constructor(t,l){super(t),this.name="RateLimitError",this.retryAfter=l}},d=class extends r{constructor(t){super(t),this.name="NetworkError"}},f=class extends r{constructor(t){super(t),this.name="ContextTooLongError"}};export{p as a,x as b,r as c,u as d,a as e,d as f,f as g};
|