@swifty.js/swifty 0.0.1 → 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 +183 -0
- 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-MQ5XOYLD.js +4 -0
- package/dist/chunk-RD3MICOU.js +4 -0
- package/dist/{cleanup-4R3534Z3.js → cleanup-BQJDUOKA.js} +1 -1
- package/dist/glob_addon.node +0 -0
- package/dist/main.js +240 -240
- package/dist/openai-I4WTRNNT.js +26 -0
- package/dist/{server-XPKSROM2.js → server-OGPKL2U2.js} +22 -21
- package/package.json +17 -24
- package/dist/anthropic-737END4X.js +0 -4
- package/dist/chunk-NCPOPA4A.js +0 -4
- package/dist/chunk-SC34YHMX.js +0 -521
- package/dist/chunk-Z3E5YV3P.js +0 -121
- package/dist/openai-4KX74QBZ.js +0 -27
- package/docs/ch1.md +0 -25
- package/docs/ch10.md +0 -122
- package/docs/ch11.md +0 -163
- package/docs/ch12.md +0 -289
- package/docs/ch13.md +0 -320
- package/docs/ch14.md +0 -152
- package/docs/ch15.md +0 -547
- package/docs/ch2.md +0 -273
- package/docs/ch3.md +0 -206
- package/docs/ch4.md +0 -125
- package/docs/ch5.md +0 -165
- package/docs/ch6.md +0 -201
- package/docs/ch7.md +0 -448
- package/docs/ch8.md +0 -217
- package/docs/ch9.md +0 -351
- package/docs/index.css +0 -23
- package/docs/index.md +0 -21
- package/docs/swifty.mdx +0 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swifty.js/swifty",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Swifty — CLI coding agent",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"bugs": {
|
|
14
14
|
"url": "https://github.com/hangtiancheng/swifty-cli/issues"
|
|
15
15
|
},
|
|
16
|
-
"license": "
|
|
16
|
+
"license": "MIT",
|
|
17
17
|
"author": "https://github.com/hangtiancheng",
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
},
|
|
26
26
|
"files": [
|
|
27
27
|
"dist",
|
|
28
|
-
"docs"
|
|
28
|
+
"docs",
|
|
29
|
+
"README.md"
|
|
29
30
|
],
|
|
30
31
|
"type": "module",
|
|
31
32
|
"main": "dist/main.js",
|
|
@@ -33,17 +34,12 @@
|
|
|
33
34
|
"access": "public"
|
|
34
35
|
},
|
|
35
36
|
"scripts": {
|
|
36
|
-
"fe:dev": "cd src/remote/fe &&
|
|
37
|
-
"fe:build": "cd src/remote/fe &&
|
|
38
|
-
"fe:preview": "
|
|
39
|
-
"
|
|
40
|
-
"fe:check": "cd src/remote/fe && biome check --write",
|
|
41
|
-
"prebuild": "pnpm --filter @swifty.js/glob-wasm asbuild:release && pnpm --filter @swifty.js/glob-addon build",
|
|
37
|
+
"fe:dev": "cd src/remote/fe && tsup --watch",
|
|
38
|
+
"fe:build": "cd src/remote/fe && tsup",
|
|
39
|
+
"fe:preview": "npx -y serve src/remote/fe/dist",
|
|
40
|
+
"prebuild": "pnpm --filter @swifty.js/glob-addon build && pnpm --filter @swifty.js/glob-wasm asbuild:release",
|
|
42
41
|
"dev": "tsx ./src/main.tsx",
|
|
43
42
|
"build": "tsup",
|
|
44
|
-
"dev:docs": "rspress dev",
|
|
45
|
-
"build:docs": "rspress build",
|
|
46
|
-
"preview:docs": "rspress preview",
|
|
47
43
|
"lint": "eslint ./src",
|
|
48
44
|
"lint:fix": "eslint --fix ./src",
|
|
49
45
|
"test": "vitest run",
|
|
@@ -64,16 +60,15 @@
|
|
|
64
60
|
"@anthropic-ai/sdk": "^0.104.2",
|
|
65
61
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
66
62
|
"chalk": "^5.6.2",
|
|
67
|
-
"dompurify": "^3.4.
|
|
63
|
+
"dompurify": "^3.4.12",
|
|
68
64
|
"fuse.js": "^7.4.2",
|
|
69
65
|
"ink": "^7.1.0",
|
|
70
66
|
"ink-spinner": "^5.0.0",
|
|
71
67
|
"ink-text-input": "^6.0.0",
|
|
72
68
|
"js-yaml": "^4.3.0",
|
|
73
69
|
"koa": "^3.2.1",
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"openai": "^6.45.0",
|
|
70
|
+
"marked": "^18.0.6",
|
|
71
|
+
"openai": "^6.46.0",
|
|
77
72
|
"pino": "^10.3.1",
|
|
78
73
|
"react": "19.2.7",
|
|
79
74
|
"react-dom": "19.2.7",
|
|
@@ -82,33 +77,31 @@
|
|
|
82
77
|
},
|
|
83
78
|
"devDependencies": {
|
|
84
79
|
"@biomejs/biome": "2.4.15",
|
|
85
|
-
"@eslint/js": "^9.39.
|
|
86
|
-
"@rsbuild/core": "^2.1.5",
|
|
87
|
-
"@rsbuild/plugin-react": "^2.1.0",
|
|
88
|
-
"@rsbuild/plugin-tailwindcss": "^2.0.3",
|
|
80
|
+
"@eslint/js": "^9.39.5",
|
|
89
81
|
"@swifty.js/glob-addon": "workspace:*",
|
|
90
82
|
"@swifty.js/glob-wasm": "workspace:*",
|
|
91
83
|
"@swifty.js/marked-terminal": "workspace:^",
|
|
84
|
+
"@tailwindcss/postcss": "^4.3.2",
|
|
92
85
|
"@types/js-yaml": "^4.0.9",
|
|
93
86
|
"@types/koa": "^3.0.3",
|
|
94
|
-
"@types/node": "^24.13.
|
|
87
|
+
"@types/node": "^24.13.3",
|
|
95
88
|
"@types/react": "^19.2.17",
|
|
96
89
|
"@types/react-dom": "^19.2.3",
|
|
97
90
|
"@types/ws": "^8.18.1",
|
|
98
91
|
"@vitest/coverage-v8": "^4.1.10",
|
|
99
|
-
"eslint": "^9.39.
|
|
92
|
+
"eslint": "^9.39.5",
|
|
100
93
|
"eslint-plugin-react-hooks": "^5.2.0",
|
|
101
94
|
"eslint-plugin-react-refresh": "^0.5.3",
|
|
102
95
|
"eslint-plugin-unicorn": "^65.0.1",
|
|
103
96
|
"globals": "^17.7.0",
|
|
104
97
|
"oxfmt": "^0.53.0",
|
|
105
98
|
"pino-pretty": "^13.1.3",
|
|
106
|
-
"
|
|
99
|
+
"postcss": "^8.5.20",
|
|
107
100
|
"tailwindcss": "^4.3.2",
|
|
108
101
|
"tsup": "^8.5.1",
|
|
109
102
|
"tsx": "^4.23.0",
|
|
110
103
|
"typescript": "^5.9.3",
|
|
111
|
-
"typescript-eslint": "^8.
|
|
104
|
+
"typescript-eslint": "^8.63.0",
|
|
112
105
|
"vitest": "^4.1.10"
|
|
113
106
|
},
|
|
114
107
|
"packageManager": "pnpm@10.33.1"
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { createRequire as __swiftyCreateRequire } from "node:module";
|
|
3
|
-
const require = __swiftyCreateRequire(import.meta.url);
|
|
4
|
-
import{g as v}from"./chunk-H7VXSMJR.js";import{$ as K,L as w,N as P,O as S,P as I,Q as k,R as N,W as O,X as M,Y as j,Z as U,_ as $,ba as B,ca as R,e as L,p as E}from"./chunk-Z3E5YV3P.js";import"./chunk-NCPOPA4A.js";import"./chunk-X3UA5OZL.js";var x=L({module:"llm"});var G=3e3,H=w.object({max_input_tokens:w.coerce.number()});async function tt(o){if(o.protocol!=="anthropic")return 0;let t=R(o),n=`${o.base_url.replace(/\/+$/,"")}/v1/models/${encodeURIComponent(o.model)}`,r=new AbortController,a=setTimeout(()=>{r.abort()},G);try{let l=await fetch(n,{method:"GET",headers:{"anthropic-version":"2023-06-01",...t?{"x-api-key":t}:{}},signal:r.signal});if(!l.ok)return 0;let g=await l.json(),{success:h,error:d,data:f}=await E(H,g);if(!h)return console.error(d.message),0;let y=f.max_input_tokens;return Math.max(y,0)}catch(l){return console.error(l),0}finally{clearTimeout(a)}}function Y(){return!0}function q(o){let t=[];for(let e of o)if(e.role==="assistant"){let n=[];if(e.thinkingBlocks)for(let r of e.thinkingBlocks)n.push({type:"thinking",thinking:r.thinking,signature:r.signature});if(e.content&&n.push({type:"text",text:e.content}),e.toolUses)for(let r of e.toolUses)n.push({type:"tool_use",id:r.toolUseId,name:r.toolName,input:r.arguments});n.length===0&&n.push({type:"text",text:""}),t.push({role:"assistant",content:n})}else if(e.toolResults&&e.toolResults.length>0){let n=[];for(let r of e.toolResults)n.push({type:"tool_result",tool_use_id:r.toolUseId,is_error:r.isError,content:r.content});t.push({role:"user",content:n})}else{if(t.length===0){t.push({role:"user",content:[{type:"text",text:e.content}]});continue}let n=!1,r=t[t.length-1],a=r.content;r.role==="user"&&(typeof a=="string"||Array.isArray(a)&&a.length>0&&a[0].type==="text")&&(n=!0),n?(typeof a=="string"&&(a=r.content=a.trim().length>0?[{type:"text",text:a}]:[]),a.push({type:"text",text:e.content})):t.push({role:"user",content:[{type:"text",text:e.content}]})}return t}var W=class{client;model;thinking;systemPrompt;maxOutputTokens;contextWindow;constructor(t,e){let n=R(t);if(!n)throw new M("Anthropic API key not found, set ANTHROPIC_API_KEY in .swifty/config.y(a)ml, or via ANTHROPIC_API_KEY env variable.");this.client=new v({apiKey:n,baseURL:t.base_url}),this.model=t.model,this.thinking=t.thinking??!0,this.systemPrompt=e,this.maxOutputTokens=B(t),this.contextWindow=K(t)}setSystemPrompt(t){this.systemPrompt=t}setMaxOutputTokens(t){this.maxOutputTokens=t}async*stream(t,e,n){let r=q(t.getMessages()),a=e.map(c=>{let p=c.input_schema;return{name:c.name,description:c.description,input_schema:{type:"object",properties:p.properties,required:p.required??[]}}});a.length>0&&(a[a.length-1].cache_control={type:"ephemeral"}),D(r);let l={model:this.model,max_tokens:this.maxOutputTokens,stream:!0,system:[{type:"text",text:this.systemPrompt,cache_control:{type:"ephemeral"}}],messages:r,...a.length>0?{tools:a}:{}};this.thinking?Y()&&(l.thinking={type:"enabled",budget_tokens:this.maxOutputTokens-1}):l.thinking={type:"enabled",budget_tokens:this.maxOutputTokens-1};let g=0,h=0,d=0,f=0,y="end_turn",b="",T="",A=!1,C=0;try{let c=this.client.messages.stream(l,{...n?{signal:n}:{}}),p="",_="",u="";for await(let i of c)switch(i.type){case"content_block_start":{let s=i.content_block;s.type==="thinking"?(A=!0,b="",T=""):s.type==="tool_use"&&(_=s.id,p=s.name,u="",yield{type:"tool_call_start",toolName:p,toolId:_});break}case"content_block_delta":{let s=i.delta;s.type==="thinking_delta"?(b+=s.thinking,yield{type:"thinking_delta",text:s.thinking}):s.type==="signature_delta"?(x.debug({signature:s.signature},"thinking signature received"),T=s.signature):s.type==="text_delta"?yield{type:"text_delta",text:s.text}:s.type==="input_json_delta"&&(u+=s.partial_json,yield{type:"tool_call_delta",text:s.partial_json});break}case"content_block_stop":{if(A&&(yield{type:"thinking_complete",thinking:b,signature:T},A=!1),p){let s={};if(u)try{let m=JSON.parse(u);s=S(m)?I(m):{[P]:u}}catch(m){x.error({err:m},"llm operation failed"),s={[P]:u}}yield{type:"tool_call_complete",toolId:_,toolName:p,arguments:s},p="",_="",u=""}break}case"message_delta":{i.delta.stop_reason&&(y=i.delta.stop_reason),i.usage.output_tokens&&(h=i.usage.output_tokens,i.usage.input_tokens&&(g=i.usage.input_tokens),i.usage.cache_read_input_tokens&&(d=i.usage.cache_read_input_tokens),i.usage.cache_creation_input_tokens&&(f=i.usage.cache_creation_input_tokens));break}case"message_start":{C=performance.now(),g=i.message.usage.input_tokens,h=i.message.usage.output_tokens,d=i.message.usage.cache_read_input_tokens??0,f=i.message.usage.cache_creation_input_tokens??0;break}case"message_stop":{let m=performance.now()-C;x.debug({elapsedMs:m},"message stream complete");break}}yield{type:"stream_end",stopReason:y,usage:{inputTokens:g,outputTokens:h,cacheReadInputTokens:d,cacheCreationInputTokens:f}}}catch(c){throw x.error({err:c},"llm operation failed"),F(c)}}};function D(o){for(let t=o.length-1;t>=0;t--){if(o[t].role!=="user")continue;let e=o[t].content;if(typeof e=="string"&&e.length===0||Array.isArray(e)&&e.length===0)return;typeof e=="string"&&(e=o[t].content=[{type:"text",text:e}]);let n=e[e.length-1];Reflect.set(n,"cache_control",{type:"ephemeral"})}}function F(o){if(o instanceof v.APIError){if(o.status===413||/prompts?\s+too\s+long/i.test(o.message))return new $(`Prompt too long: ${o.message}`);if(o.status===401)return new M(`Invalid API key: ${o.message}`);if(o.status===429){let t=I(o.headers)["retry-after"],e="Rate Limited";if(t){let n=Number.parseInt(k(t));Number.isNaN(n)&&(e+=", please wait."),e+=`, retry after ${k(n)}s.`}else e+=", please wait.";return new j(e,t?k(t):void 0)}return new O(`Anthropic API error (${k(o.status)}): ${o.message}`)}return new U(`Network error: ${N(o)}`)}export{W as AnthropicClient,q as buildAnthropicMessages,tt as fetchModelContextWindow};
|
package/dist/chunk-NCPOPA4A.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { createRequire as __swiftyCreateRequire } from "node:module";
|
|
3
|
-
const require = __swiftyCreateRequire(import.meta.url);
|
|
4
|
-
import{readdirSync as f,statSync as m,unlinkSync as u,existsSync as a}from"fs";import{join as o}from"path";var y=30,g=y*24*60*60*1e3;function c(n){if(!a(n))return 0;let t;try{t=f(n).filter(s=>s.endsWith(".jsonl"))}catch{return 0}let e=Date.now(),r=0;for(let s of t){let i=o(n,s);try{let l=m(i);e-l.mtimeMs>g&&(u(i),r++)}catch{}}return r}function d(n){let t=0;t+=c(o(n,".swifty","logs"));let e=o(n,".swifty","teams");if(!a(e))return t;let r;try{r=f(e)}catch{return t}for(let s of r)t+=c(o(e,s,"logs"));return t}export{d as a};
|