@wendongfly/myhi 1.3.54 → 1.3.55

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
@@ -368,7 +368,7 @@ Content-Length: `+C+`\r
368
368
  name = ${h}
369
369
  email = ${h}@myhi
370
370
  `;(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(n){if(n.message.includes("src refspec")||n.message.includes("does not match"))await e(["checkout","-b",c]),await e(["push","-u","origin",c]);else throw n}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 r=(0,external_fs_.readFileSync)(i,"utf8").match(/name\s*=\s*(.+)/);r&&(f=r[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,r,s=""){if((0,external_fs_.existsSync)(i))try{for(const t of(0,external_fs_.readdirSync)(i,{withFileTypes:!0})){if(t.isDirectory()){f((0,external_path_.join)(i,t.name),r,s?`${s}:${t.name}`:t.name);continue}if(!t.name.endsWith(".md"))continue;const e=t.name.replace(/\.md$/,""),c=s?`${s}:${e}`:e,a=(0,external_path_.join)(i,t.name);try{const n=(0,external_fs_.readFileSync)(a,"utf8"),u=(n.split(`
371
- `).find((b=>b.trim()))||"").replace(/^#+\s*/,"").trim().slice(0,60),v={name:c,desc:u,source:r};p&&(v.content=n),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"),r=skillFilePath(i,o);try{(0,external_fs_.mkdirSync)((0,external_path_.dirname)(r),{recursive:!0}),(0,external_fs_.writeFileSync)(r,g,"utf8"),l.json({ok:!0,path:r})}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(r){l.status(500).json({error:r.message})}})),app.post("/api/skills/scan-git",checkAuth,express.json(),((w,l)=>{const{url:o,username:g,password:h}=w.body||{};if(!o)return l.status(400).json({error:"\u7F3A\u5C11 Git \u4ED3\u5E93\u5730\u5740"});let m=o;if(g&&h&&/^https?:\/\//.test(o))try{const t=new URL(o);t.username=encodeURIComponent(g),t.password=encodeURIComponent(h),m=t.toString()}catch{}const p=(0,external_path_.join)((0,external_os_.tmpdir)(),"myhi-skill-"+Date.now());try{(0,external_child_process_namespaceObject.execSync)(`git clone --depth 1 "${m}" "${p}"`,{timeout:6e4,stdio:"pipe",encoding:"utf8",env:{...process.env,GIT_TERMINAL_PROMPT:"0"}})}catch(t){const e=(t.stderr||"").trim(),c=(t.stdout||"").trim(),d=(e||c||t.message||"\u672A\u77E5\u9519\u8BEF").split(`
371
+ `).find((b=>b.trim()))||"").replace(/^#+\s*/,"").trim().slice(0,60),v={name:c,desc:u,source:r};p&&(v.content=n),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"),f(__nccwpck_require__.ab+"builtin-skills","builtin"),l.json({skills:m})})),app.get("/api/skills/content",checkAuth,((w,l)=>{const{name:o,sessionId:g}=w.query;if(!o)return l.status(400).json({error:"\u7F3A\u5C11 name"});const m=(g?manager.get(g):null)?.cwd||process.cwd(),p=[{dir:(0,external_path_.join)(m,".claude","commands"),source:"project"},{dir:(0,external_path_.join)((0,external_os_.homedir)(),".claude","commands"),source:"user"},{dir:__nccwpck_require__.ab+"builtin-skills",source:"builtin"}];for(const{dir:f,source:i}of p){const r=skillFilePath(f,o);if((0,external_fs_.existsSync)(r))try{return l.json({content:(0,external_fs_.readFileSync)(r,"utf8"),source:i})}catch{}}l.status(404).json({error:"\u6280\u80FD\u4E0D\u5B58\u5728"})})),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"),r=skillFilePath(i,o);try{(0,external_fs_.mkdirSync)((0,external_path_.dirname)(r),{recursive:!0}),(0,external_fs_.writeFileSync)(r,g,"utf8"),l.json({ok:!0,path:r})}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(r){l.status(500).json({error:r.message})}})),app.post("/api/skills/scan-git",checkAuth,express.json(),((w,l)=>{const{url:o,username:g,password:h}=w.body||{};if(!o)return l.status(400).json({error:"\u7F3A\u5C11 Git \u4ED3\u5E93\u5730\u5740"});let m=o;if(g&&h&&/^https?:\/\//.test(o))try{const t=new URL(o);t.username=encodeURIComponent(g),t.password=encodeURIComponent(h),m=t.toString()}catch{}const p=(0,external_path_.join)((0,external_os_.tmpdir)(),"myhi-skill-"+Date.now());try{(0,external_child_process_namespaceObject.execSync)(`git clone --depth 1 "${m}" "${p}"`,{timeout:6e4,stdio:"pipe",encoding:"utf8",env:{...process.env,GIT_TERMINAL_PROMPT:"0"}})}catch(t){const e=(t.stderr||"").trim(),c=(t.stdout||"").trim(),d=(e||c||t.message||"\u672A\u77E5\u9519\u8BEF").split(`
372
372
  `).filter((u=>u.trim())).slice(-3).join(" ").slice(0,200);return l.status(400).json({error:"\u514B\u9686\u5931\u8D25: "+d})}const f=[];function i(t,e=""){if((0,external_fs_.existsSync)(t))try{for(const c of(0,external_fs_.readdirSync)(t,{withFileTypes:!0})){if(c.name.startsWith("."))continue;if(c.isDirectory()){i((0,external_path_.join)(t,c.name),e?`${e}:${c.name}`:c.name);continue}if(!c.name.endsWith(".md")||["README.MD","CHANGELOG.MD","LICENSE.MD","CONTRIBUTING.MD"].includes(c.name.toUpperCase()))continue;const a=c.name.replace(/\.md$/,""),n=e?`${e}:${a}`:a,d=(0,external_path_.join)(t,c.name);try{const u=(0,external_fs_.readFileSync)(d,"utf8"),b=(u.split(`
373
373
  `).find((_=>_.trim()))||"").replace(/^#+\s*/,"").trim().slice(0,80);f.push({name:n,desc:b,content:u})}catch{}}}catch{}}const r=(0,external_path_.join)(p,"commands"),s=(0,external_path_.join)(p,".claude","commands");(0,external_fs_.existsSync)(r)?i(r):(0,external_fs_.existsSync)(s)?i(s):i(p);try{(0,external_child_process_namespaceObject.execSync)(process.platform==="win32"?`rmdir /s /q ${JSON.stringify(p)}`:`rm -rf ${JSON.stringify(p)}`,{timeout:1e4,stdio:"pipe"})}catch{}if(!f.length)return l.json({skills:[],message:"\u4ED3\u5E93\u4E2D\u672A\u627E\u5230\u6280\u80FD\u6587\u4EF6(.md)"});l.json({skills:f})})),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 r=[(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 t of(0,external_fs_.readdirSync)(s)){const e=(0,external_path_.join)(s,t,"memory");if((0,external_fs_.existsSync)(e)){const c=(0,external_path_.join)(s,t,"CLAUDE.md");if((0,external_fs_.existsSync)(c))try{m.push({name:`.claude/projects/${t}/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 n=(0,external_path_.join)(e,a);try{m.push({name:`memory/${a}`,content:(0,external_fs_.readFileSync)(n,"utf8")})}catch{}}}catch{}}}}catch{}for(const t of r)if((0,external_fs_.existsSync)(t))try{for(const e of(0,external_fs_.readdirSync)(t)){if(!e.endsWith(".md"))continue;const c=(0,external_path_.join)(t,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,(async(w,l)=>{try{await execAsync(getNpmUpgradeCmd(),{encoding:"utf8",timeout:12e4}),console.log("[myhi] \u5347\u7EA7\u5B8C\u6210"),l.json({ok:!0,message:"\u5347\u7EA7\u5B8C\u6210\uFF0C\u670D\u52A1\u5C06\u81EA\u52A8\u91CD\u542F..."}),setTimeout((()=>restartService()),500)}catch(o){const g=(o.stderr||o.stdout||o.message||"").split(`
374
374
  `).filter((h=>h.trim())).slice(-5).join(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wendongfly/myhi",
3
- "version": "1.3.54",
3
+ "version": "1.3.55",
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",