@wendongfly/myhi 1.3.18 → 1.3.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -362,7 +362,7 @@ Content-Length: `+C+`\r
362
362
  name = ${h}
363
363
  email = ${h}@myhi
364
364
  `;(0,external_fs_.writeFileSync)(v,b,{mode:384});try{await e(["remote","remove","origin"])}catch{}await e(["remote","add","origin",g])}if(await e(["add","-A"]),!await e(["status","--porcelain"]))return l.json({ok:!0,message:"\u6CA1\u6709\u9700\u8981\u63D0\u4EA4\u7684\u53D8\u66F4",pushed:!1});await e(["commit","-m",p]);const c=f||"main";try{await e(["push","-u","origin",c])}catch(t){if(t.message.includes("src refspec")||t.message.includes("does not match"))await e(["checkout","-b",c]),await e(["push","-u","origin",c]);else throw t}const a=await e(["log","--oneline","-1"]);l.json({ok:!0,message:`\u5DF2\u63D0\u4EA4\u5E76\u63A8\u9001: ${a}`,pushed:!0})}catch(c){l.json({ok:!1,error:c.message})}})),app.get("/api/git/info",checkAuth,((w,l)=>{const o=w.query.sessionId,g=o?manager.get(o):null;if(!g)return l.json({});const h=g.cwd||process.cwd();try{const m=(0,external_child_process_namespaceObject.execSync)("git remote get-url origin",{cwd:h,encoding:"utf8",timeout:5e3}).trim(),p=(0,external_child_process_namespaceObject.execSync)("git branch --show-current",{cwd:h,encoding:"utf8",timeout:5e3}).trim();let f="";const i=(0,external_path_.join)(h,".gitconfig");if((0,external_fs_.existsSync)(i)){const n=(0,external_fs_.readFileSync)(i,"utf8").match(/name\s*=\s*(.+)/);n&&(f=n[1].trim())}l.json({url:m,branch:p||"main",username:f})}catch{l.json({})}}));function skillFilePath(w,l){const o=l.split(":");return(0,external_path_.join)(w,...o.slice(0,-1),o[o.length-1]+".md")}app.get("/api/skills",checkAuth,((w,l)=>{const o=w.query.sessionId,h=(o?manager.get(o):null)?.cwd||process.cwd(),m=[],p=w.query.detail==="1";function f(i,n,s=""){if((0,external_fs_.existsSync)(i))try{for(const r of(0,external_fs_.readdirSync)(i,{withFileTypes:!0})){if(r.isDirectory()){f((0,external_path_.join)(i,r.name),n,s?`${s}:${r.name}`:r.name);continue}if(!r.name.endsWith(".md"))continue;const e=r.name.replace(/\.md$/,""),c=s?`${s}:${e}`:e,a=(0,external_path_.join)(i,r.name);try{const t=(0,external_fs_.readFileSync)(a,"utf8"),u=(t.split(`
365
- `).find((b=>b.trim()))||"").replace(/^#+\s*/,"").trim().slice(0,60),v={name:c,desc:u,source:n};p&&(v.content=t),m.push(v)}catch{}}}catch{}}f((0,external_path_.join)(h,".claude","commands"),"project"),f((0,external_path_.join)((0,external_os_.homedir)(),".claude","commands"),"user"),l.json({skills:m})})),app.post("/api/skills",checkAuth,((w,l)=>{const{name:o,content:g,scope:h}=w.body||{};if(!o||!g)return l.status(400).json({error:"\u7F3A\u5C11 name \u6216 content"});if(!/^[\w:.-]+$/.test(o))return l.status(400).json({error:"\u540D\u79F0\u53EA\u80FD\u5305\u542B\u5B57\u6BCD\u3001\u6570\u5B57\u3001-\u3001_\u3001.\u3001:"});const m=w.query.sessionId,f=(m?manager.get(m):null)?.cwd||process.cwd(),i=h==="project"?(0,external_path_.join)(f,".claude","commands"):(0,external_path_.join)((0,external_os_.homedir)(),".claude","commands"),n=skillFilePath(i,o);try{(0,external_fs_.mkdirSync)((0,external_path_.dirname)(n),{recursive:!0}),(0,external_fs_.writeFileSync)(n,g,"utf8"),l.json({ok:!0,path:n})}catch(s){l.status(500).json({error:s.message})}})),app.delete("/api/skills",checkAuth,((w,l)=>{const{name:o,scope:g}=w.body||{};if(!o)return l.status(400).json({error:"\u7F3A\u5C11 name"});const h=w.query.sessionId,p=(h?manager.get(h):null)?.cwd||process.cwd(),f=g==="project"?(0,external_path_.join)(p,".claude","commands"):(0,external_path_.join)((0,external_os_.homedir)(),".claude","commands"),i=skillFilePath(f,o);try{(0,external_fs_.existsSync)(i)&&(0,external_fs_.unlinkSync)(i),l.json({ok:!0})}catch(n){l.status(500).json({error:n.message})}})),app.post("/api/skills/scan-git",checkAuth,((w,l)=>{const{url:o}=w.body||{};if(!o)return l.status(400).json({error:"\u7F3A\u5C11 Git \u4ED3\u5E93\u5730\u5740"});const g=(0,external_path_.join)((0,external_os_.tmpdir)(),"myhi-skill-"+Date.now());try{(0,external_child_process_namespaceObject.execSync)(`git clone --depth 1 ${JSON.stringify(o)} ${JSON.stringify(g)}`,{timeout:6e4,stdio:"pipe",encoding:"utf8"})}catch(i){const n=i.stderr||i.message||"";return l.status(400).json({error:"\u514B\u9686\u5931\u8D25: "+n.split(`
365
+ `).find((b=>b.trim()))||"").replace(/^#+\s*/,"").trim().slice(0,60),v={name:c,desc:u,source:n};p&&(v.content=t),m.push(v)}catch{}}}catch{}}f((0,external_path_.join)(h,".claude","commands"),"project"),f((0,external_path_.join)((0,external_os_.homedir)(),".claude","commands"),"user"),l.json({skills:m})})),app.post("/api/skills",checkAuth,express.json(),((w,l)=>{const{name:o,content:g,scope:h}=w.body||{};if(!o||!g)return l.status(400).json({error:"\u7F3A\u5C11 name \u6216 content"});if(!/^[\w:.-]+$/.test(o))return l.status(400).json({error:"\u540D\u79F0\u53EA\u80FD\u5305\u542B\u5B57\u6BCD\u3001\u6570\u5B57\u3001-\u3001_\u3001.\u3001:"});const m=w.query.sessionId,f=(m?manager.get(m):null)?.cwd||process.cwd(),i=h==="project"?(0,external_path_.join)(f,".claude","commands"):(0,external_path_.join)((0,external_os_.homedir)(),".claude","commands"),n=skillFilePath(i,o);try{(0,external_fs_.mkdirSync)((0,external_path_.dirname)(n),{recursive:!0}),(0,external_fs_.writeFileSync)(n,g,"utf8"),l.json({ok:!0,path:n})}catch(s){l.status(500).json({error:s.message})}})),app.delete("/api/skills",checkAuth,express.json(),((w,l)=>{const{name:o,scope:g}=w.body||{};if(!o)return l.status(400).json({error:"\u7F3A\u5C11 name"});const h=w.query.sessionId,p=(h?manager.get(h):null)?.cwd||process.cwd(),f=g==="project"?(0,external_path_.join)(p,".claude","commands"):(0,external_path_.join)((0,external_os_.homedir)(),".claude","commands"),i=skillFilePath(f,o);try{(0,external_fs_.existsSync)(i)&&(0,external_fs_.unlinkSync)(i),l.json({ok:!0})}catch(n){l.status(500).json({error:n.message})}})),app.post("/api/skills/scan-git",checkAuth,express.json(),((w,l)=>{const{url:o}=w.body||{};if(!o)return l.status(400).json({error:"\u7F3A\u5C11 Git \u4ED3\u5E93\u5730\u5740"});const g=(0,external_path_.join)((0,external_os_.tmpdir)(),"myhi-skill-"+Date.now());try{(0,external_child_process_namespaceObject.execSync)(`git clone --depth 1 ${JSON.stringify(o)} ${JSON.stringify(g)}`,{timeout:6e4,stdio:"pipe",encoding:"utf8"})}catch(i){const n=i.stderr||i.message||"";return l.status(400).json({error:"\u514B\u9686\u5931\u8D25: "+n.split(`
366
366
  `).pop().trim()})}const h=[];function m(i,n=""){if((0,external_fs_.existsSync)(i))try{for(const s of(0,external_fs_.readdirSync)(i,{withFileTypes:!0})){if(s.name.startsWith("."))continue;if(s.isDirectory()){m((0,external_path_.join)(i,s.name),n?`${n}:${s.name}`:s.name);continue}if(!s.name.endsWith(".md")||["README.MD","CHANGELOG.MD","LICENSE.MD","CONTRIBUTING.MD"].includes(s.name.toUpperCase()))continue;const r=s.name.replace(/\.md$/,""),e=n?`${n}:${r}`:r,c=(0,external_path_.join)(i,s.name);try{const a=(0,external_fs_.readFileSync)(c,"utf8"),d=(a.split(`
367
367
  `).find((u=>u.trim()))||"").replace(/^#+\s*/,"").trim().slice(0,80);h.push({name:e,desc:d,content:a})}catch{}}}catch{}}const p=(0,external_path_.join)(g,"commands"),f=(0,external_path_.join)(g,".claude","commands");(0,external_fs_.existsSync)(p)?m(p):(0,external_fs_.existsSync)(f)?m(f):m(g);try{(0,external_child_process_namespaceObject.execSync)(process.platform==="win32"?`rmdir /s /q ${JSON.stringify(g)}`:`rm -rf ${JSON.stringify(g)}`,{timeout:1e4,stdio:"pipe"})}catch{}if(!h.length)return l.json({skills:[],message:"\u4ED3\u5E93\u4E2D\u672A\u627E\u5230\u6280\u80FD\u6587\u4EF6(.md)"});l.json({skills:h})})),app.get("/api/memory",checkAuth,((w,l)=>{const o=w.query.sessionId,g=o?manager.get(o):null;if(!g)return l.json({files:[]});const h=g.cwd||process.cwd(),m=[],p=(0,external_path_.join)(h,"CLAUDE.md");if((0,external_fs_.existsSync)(p))try{m.push({name:"CLAUDE.md",content:(0,external_fs_.readFileSync)(p,"utf8")})}catch{}const f=(0,external_path_.join)(h,".claude","settings.json");if((0,external_fs_.existsSync)(f))try{m.push({name:".claude/settings.json",content:(0,external_fs_.readFileSync)(f,"utf8")})}catch{}const i=(0,external_path_.join)((0,external_os_.homedir)(),".claude","CLAUDE.md");if((0,external_fs_.existsSync)(i))try{m.push({name:"~/.claude/CLAUDE.md",content:(0,external_fs_.readFileSync)(i,"utf8")})}catch{}const n=[(0,external_path_.join)((0,external_os_.homedir)(),".claude","memory")],s=(0,external_path_.join)((0,external_os_.homedir)(),".claude","projects");if((0,external_fs_.existsSync)(s))try{for(const r of(0,external_fs_.readdirSync)(s)){const e=(0,external_path_.join)(s,r,"memory");if((0,external_fs_.existsSync)(e)){const c=(0,external_path_.join)(s,r,"CLAUDE.md");if((0,external_fs_.existsSync)(c))try{m.push({name:`.claude/projects/${r}/CLAUDE.md`,content:(0,external_fs_.readFileSync)(c,"utf8")})}catch{}try{for(const a of(0,external_fs_.readdirSync)(e)){if(!a.endsWith(".md"))continue;const t=(0,external_path_.join)(e,a);try{m.push({name:`memory/${a}`,content:(0,external_fs_.readFileSync)(t,"utf8")})}catch{}}}catch{}}}}catch{}for(const r of n)if((0,external_fs_.existsSync)(r))try{for(const e of(0,external_fs_.readdirSync)(r)){if(!e.endsWith(".md"))continue;const c=(0,external_path_.join)(r,e);try{m.push({name:`~/.claude/memory/${e}`,content:(0,external_fs_.readFileSync)(c,"utf8")})}catch{}}}catch{}l.json({files:m})}));const _adminTokens=new Set,SERVER_START_TIME=Date.now();function checkAdminAuth(w,l,o){const g=w.headers.authorization;if(g&&g.startsWith("Bearer ")&&_adminTokens.has(g.slice(7)))return o();l.status(401).json({error:"\u672A\u6388\u6743"})}app.post("/api/admin/login",express.json(),((w,l)=>{const{password:o}=w.body||{};if(o===PASSWORD){const g=(0,external_crypto_.randomBytes)(16).toString("hex");return _adminTokens.add(g),l.json({ok:!0,token:g})}l.json({ok:!1,error:"\u5BC6\u7801\u9519\u8BEF"})})),app.get("/api/admin/status",checkAdminAuth,(async(w,l)=>{const o=await checkLatestVersion();loadUsers();const g=[],h=new Set;for(const[,p]of io.sockets.sockets)!p.data.userName||h.has(p.data.userName)||(h.add(p.data.userName),g.push({name:p.data.userName,role:p.data.role||"viewer"}));const m=manager.listSessions().filter((p=>p.alive!==!1)).map((p=>({id:p.id,title:p.title,mode:p.mode||"pty",owner:p.owner,viewers:p.viewerCount||0})));l.json({version:{current:getPkgVersion(),latest:o||getPkgVersion(),updateAvailable:o&&o!==getPkgVersion()},onlineUsers:g,sessions:m,users:listUsers(),uptime:Math.floor((Date.now()-SERVER_START_TIME)/1e3)})})),app.post("/api/admin/upgrade",checkAdminAuth,((w,l)=>{process.send?(process.send({type:"upgrade"}),l.json({ok:!0,message:"\u5347\u7EA7\u4E2D\uFF0C\u670D\u52A1\u5C06\u81EA\u52A8\u91CD\u542F..."})):(l.json({ok:!0,message:"\u5347\u7EA7\u4E2D..."}),setTimeout((()=>{try{const o=process.platform==="win32"?"npm.cmd install -g @wendongfly/myhi@latest":"sudo npm install -g @wendongfly/myhi@latest 2>&1 || npm install -g @wendongfly/myhi@latest";(0,external_child_process_namespaceObject.execSync)(o,{encoding:"utf8",timeout:12e4}),process.exit(0)}catch(o){console.error("[myhi] \u5347\u7EA7\u5931\u8D25:",o.message)}}),500))})),app.post("/api/admin/restart",checkAdminAuth,((w,l)=>{l.json({ok:!0}),setTimeout((()=>{process.send?process.send({type:"restart"}):process.exit(0)}),300)})),app.post("/api/admin/user",checkAdminAuth,express.json(),((w,l)=>{const{password:o,name:g,dir:h}=w.body||{};if(!o||!g||!h)return l.json({ok:!1,error:"\u5BC6\u7801\u3001\u540D\u79F0\u3001\u76EE\u5F55\u90FD\u5FC5\u586B"});loadUsers(),addUser(o,g,h);try{(0,external_fs_.mkdirSync)(h,{recursive:!0});const m=(0,external_path_.join)(h,".gitconfig"),p=(0,external_path_.join)(h,".git-credentials");(0,external_fs_.existsSync)(m)||(0,external_fs_.writeFileSync)(m,`[credential]
368
368
  helper = store --file ${p.replace(/\\/g,"/")}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wendongfly/myhi",
3
- "version": "1.3.18",
3
+ "version": "1.3.19",
4
4
  "description": "Web-based terminal sharing with chat UI — control your terminal from phone via LAN/Tailscale",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",