@sleep2agi/agent-network 0.0.34 → 0.0.35
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/bin/cli.js +18 -18
- package/package.json +1 -1
package/dist/bin/cli.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var o=Object.defineProperty;var i=(B)=>B;function s(B,Q){this[B]=i.bind(null,Q)}var e=(B,Q)=>{for(var z in Q)o(B,z,{get:Q[z],enumerable:!0,configurable:!0,set:s.bind(Q,z)})};var zz=(B,Q)=>()=>(B&&(Q=B(B=0)),Q);var u={};e(u,{default:()=>Qz,CommHub:()=>
|
|
3
|
-
`);Y=L.pop()||"";for(let E of L){if(!E.startsWith("data: "))continue;try{let R=JSON.parse(E.slice(6));if(R.type==="connected"){this.log("SSE connected"),this.emit("connected");continue}if(R.type==="new_task"||R.type==="new_message"||R.type==="broadcast")await this.processInbox()}catch{}}}}catch(W){if(W.name==="AbortError")break;this.emit("error",W),this.log(`SSE error: ${W.message}`)}if(this.running)this.emit("disconnected"),this.log(`SSE reconnecting in ${z/1000}s...`),await this.sleep(z),z=Math.min(z*1.5,60000)}}async processInbox(){try{let Q=(await this.call("get_inbox",{alias:this.alias,limit:10}))?.messages||[];for(let z of Q)await this.call("ack_inbox",{alias:this.alias,message_id:z.id}),this.log(`← ${z.from_session}: ${z.content.slice(0,60)}`),this.emit("task",z),this.emit("message",z)}catch(B){this.log(`inbox error: ${B.message}`)}}sleep(B){return new Promise((Q)=>setTimeout(Q,B))}};Qz=
|
|
4
|
-
`)}function A(B){let Q=K(
|
|
5
|
-
`)}function d(){let B=
|
|
2
|
+
var o=Object.defineProperty;var i=(B)=>B;function s(B,Q){this[B]=i.bind(null,Q)}var e=(B,Q)=>{for(var z in Q)o(B,z,{get:Q[z],enumerable:!0,configurable:!0,set:s.bind(Q,z)})};var zz=(B,Q)=>()=>(B&&(Q=B(B=0)),Q);var u={};e(u,{default:()=>Qz,CommHub:()=>D});import{EventEmitter as Bz}from"events";import{hostname as S}from"os";var D,Qz;var h=zz(()=>{D=class D extends Bz{url;alias;token;agent;resumeId;heartbeatInterval;reconnectDelay;heartbeatTimer;sseAbort;running=!1;constructor(B){super();if(this.url=B.url.replace(/\/$/,""),this.alias=B.alias,this.token=B.token,this.agent=B.agent||"sdk",this.resumeId=`sdk-${B.alias}-${Date.now().toString(36)}`,this.heartbeatInterval=B.heartbeatInterval??180000,this.reconnectDelay=B.reconnectDelay??3000,B.autoConnect!==!1)this.connect()}log(B){console.log(`[${new Date().toTimeString().slice(0,8)}] [commhub:${this.alias}] ${B}`)}async call(B,Q){let z={"Content-Type":"application/json",Accept:"application/json, text/event-stream"};if(this.token)z.Authorization=`Bearer ${this.token}`;let N=await(await fetch(`${this.url}/mcp`,{method:"POST",headers:z,body:JSON.stringify({jsonrpc:"2.0",id:Date.now(),method:"tools/call",params:{name:B,arguments:Q}})})).text(),X=N.match(/data: (.+)/),U=X?JSON.parse(X[1]):JSON.parse(N),Y=U?.result?.content?.[0]?.text;return Y?JSON.parse(Y):U}async connect(){if(this.running)return;this.running=!0,await this.status("idle"),this.log("registered"),this.heartbeatTimer=setInterval(()=>{this.status("idle").catch((B)=>this.log(`heartbeat failed: ${B.message}`))},this.heartbeatInterval),this.connectSSE()}async disconnect(){if(this.running=!1,this.sseAbort?.abort(),this.heartbeatTimer)clearInterval(this.heartbeatTimer);await this.status("offline").catch(()=>{}),this.log("disconnected")}async send(B,Q,z="normal"){return this.call("send_task",{alias:B,task:Q,priority:z,from_session:this.alias})}async message(B,Q){return this.call("send_message",{alias:B,message:Q,from_session:this.alias})}async reply(B,Q,z="completed"){return this.call("reply",{task_id:B,text:Q,status:z})}async status(B,Q){return this.call("report_status",{resume_id:this.resumeId,alias:this.alias,status:B,server:S(),hostname:S(),agent:this.agent,project_dir:process.cwd(),...Q})}async getAllStatus(){return this.call("get_all_status",{})}async broadcast(B,Q){return this.call("broadcast",{message:B,filter_server:Q?.server,filter_status:Q?.status})}async connectSSE(){let B=encodeURIComponent(this.alias),Q=`${this.url}/events/${B}`,z=this.reconnectDelay;while(this.running){try{this.sseAbort=new AbortController;let W={Accept:"text/event-stream"};if(this.token)W.Authorization=`Bearer ${this.token}`;let N=await fetch(Q,{headers:W,signal:this.sseAbort.signal});if(!N.ok||!N.body){this.log(`SSE failed: ${N.status}`),await this.sleep(z),z=Math.min(z*1.5,60000);continue}z=this.reconnectDelay;let X=N.body.getReader(),U=new TextDecoder,Y="";while(this.running){let{done:Z,value:$}=await X.read();if(Z)break;Y+=U.decode($,{stream:!0});let L=Y.split(`
|
|
3
|
+
`);Y=L.pop()||"";for(let E of L){if(!E.startsWith("data: "))continue;try{let R=JSON.parse(E.slice(6));if(R.type==="connected"){this.log("SSE connected"),this.emit("connected");continue}if(R.type==="new_task"||R.type==="new_message"||R.type==="broadcast")await this.processInbox()}catch{}}}}catch(W){if(W.name==="AbortError")break;this.emit("error",W),this.log(`SSE error: ${W.message}`)}if(this.running)this.emit("disconnected"),this.log(`SSE reconnecting in ${z/1000}s...`),await this.sleep(z),z=Math.min(z*1.5,60000)}}async processInbox(){try{let Q=(await this.call("get_inbox",{alias:this.alias,limit:10}))?.messages||[];for(let z of Q)await this.call("ack_inbox",{alias:this.alias,message_id:z.id}),this.log(`← ${z.from_session}: ${z.content.slice(0,60)}`),this.emit("task",z),this.emit("message",z)}catch(B){this.log(`inbox error: ${B.message}`)}}sleep(B){return new Promise((Q)=>setTimeout(Q,B))}};Qz=D});import{readFileSync as I,writeFileSync as q,existsSync as V,mkdirSync as J,readdirSync as m}from"fs";import{join as K}from"path";import{spawn as C,execSync as c}from"child_process";import{createInterface as $z}from"readline";var T=process.argv.slice(2),w=T[0],G=process.env.HOME||process.env.USERPROFILE||"~";function p(){return K(G,".anet","config.json")}function j(){return K(process.cwd(),".anet","nodes")}function v(){return M().token||process.env.COMMHUB_TOKEN||O().token||""}function P(B){let Q=B||v();return Q?{Authorization:`Bearer ${Q}`}:{}}function O(){let B=p();if(V(B))try{return JSON.parse(I(B,"utf-8"))}catch{}return{}}function Wz(B){let Q=K(G,".anet");J(Q,{recursive:!0}),q(K(Q,"config.json"),JSON.stringify(B,null,2)+`
|
|
4
|
+
`)}function A(B){let Q=K(j(),B,"config.json");if(V(Q))try{return JSON.parse(I(Q,"utf-8"))}catch{}return null}function b(B,Q){let z=K(j(),B);J(z,{recursive:!0}),q(K(z,"config.json"),JSON.stringify(Q,null,2)+`
|
|
5
|
+
`)}function d(){let B=j();if(!V(B))return[];return m(B).filter((Q)=>V(K(B,Q,"config.json")))}function M(){let B={_channels:[],_envs:[]};for(let Q=0;Q<T.length;Q++){if(T[Q]==="--channel"&&T[Q+1]){B._channels.push(T[++Q]);continue}if(T[Q]==="--env"&&T[Q+1]){B._envs.push(T[++Q]);continue}if(T[Q].startsWith("--")&&T[Q+1]&&!T[Q+1].startsWith("--"))B[T[Q].slice(2)]=T[++Q]}return B}function f(){console.log(`
|
|
6
6
|
anet — AI Agent Network CLI
|
|
7
7
|
|
|
8
8
|
anet init Configure hub URL (global, once)
|
|
@@ -23,11 +23,11 @@ Quick start:
|
|
|
23
23
|
anet start 指挥室 # Claude Code Agent
|
|
24
24
|
anet start 小明 # MiniMax Agent (runtime: agent-sdk)
|
|
25
25
|
`)}async function Xz(){let B=M(),Q=B.hub;if(!Q)Q=await H("CommHub URL (e.g. http://YOUR_IP:9200)"),l();if(!Q)console.error("Error: hub URL required"),process.exit(1);Q=Q.replace(/\/+$/,"");let z=B.token||"";try{let X=await(await fetch(`${Q}/health`,{headers:z?{Authorization:`Bearer ${z}`}:{}})).json();console.log(`✅ CommHub v${X.version} — ${X.sessions} sessions, ${X.sse_connections} SSE`)}catch(N){console.error(`❌ Cannot reach ${Q}: ${N.message}`),process.exit(1)}let W=O();if(W.hub=Q,z)W.token=z;Wz(W),console.log(`
|
|
26
|
-
Saved to ${p()}`),console.log("Next: anet init project")}async function Yz(){let B=O(),Q=B.hub;if(!Q)console.error("Run 'anet init' first to configure hub URL"),process.exit(1);let z=K(process.cwd(),".anet");J(z,{recursive:!0});let W=K(z,"node-server.ts");if(!
|
|
26
|
+
Saved to ${p()}`),console.log("Next: anet init project")}async function Yz(){let B=O(),Q=B.hub;if(!Q)console.error("Run 'anet init' first to configure hub URL"),process.exit(1);let z=K(process.cwd(),".anet");J(z,{recursive:!0});let W=K(z,"node-server.ts");if(!V(W)){let E=[K(new URL(".",import.meta.url).pathname,"..","..","src","node-server.ts"),K(new URL(".",import.meta.url).pathname,"..","src","node-server.ts"),K(process.argv[1],"..","..","src","node-server.ts")],R=!1;for(let _ of E)if(V(_)){q(W,I(_,"utf-8")),console.log(" ✅ .anet/node-server.ts"),R=!0;break}if(!R)console.log(" ❌ Cannot find node-server.ts"),console.log(" Fix: cp $(npm root -g)/@sleep2agi/agent-network/src/node-server.ts .anet/node-server.ts")}else console.log(" Channel plugin: exists");let N=K(z,"package.json");if(!V(N)){q(N,JSON.stringify({private:!0,dependencies:{"@modelcontextprotocol/sdk":"^1.12.0"}},null,2)+`
|
|
27
27
|
`);try{c("bun install",{cwd:z,stdio:"pipe"}),console.log(" ✅ Dependencies installed")}catch{console.log(" ⚠️ Run: cd .anet && bun install")}}let X=K(z,".env"),U=B.token||"",Y=`COMMHUB_URL=${Q}
|
|
28
28
|
`;if(U)Y+=`COMMHUB_TOKEN=${U}
|
|
29
|
-
`;
|
|
30
|
-
`),console.log(".mcp.json: commhub → .anet/node-server.ts");else console.log(".mcp.json: commhub already set");let L=K(process.cwd(),"CLAUDE.md");if(!
|
|
29
|
+
`;q(X,Y),console.log(`CommHub URL: ${Q}${U?" (with token)":""}`);let Z=K(process.cwd(),".mcp.json"),$={};if(V(Z))try{$=JSON.parse(I(Z,"utf-8"))}catch{}if(!$.mcpServers?.commhub)$.mcpServers=$.mcpServers||{},$.mcpServers.commhub={type:"stdio",command:"bun",args:[".anet/node-server.ts"]},q(Z,JSON.stringify($,null,2)+`
|
|
30
|
+
`),console.log(".mcp.json: commhub → .anet/node-server.ts");else console.log(".mcp.json: commhub already set");let L=K(process.cwd(),"CLAUDE.md");if(!V(L))q(L,`# Agent Network (CommHub)
|
|
31
31
|
|
|
32
32
|
## 通信方式
|
|
33
33
|
|
|
@@ -66,7 +66,7 @@ commhub_get_all_status()
|
|
|
66
66
|
- 回复指挥室用 commhub_send_task(不是 commhub_reply,reply 不推送)
|
|
67
67
|
- 不要猜 alias,用 get_all_status 查
|
|
68
68
|
`),console.log("CLAUDE.md: created");else console.log("CLAUDE.md: already exists");console.log(`
|
|
69
|
-
✅ Project ready. Next: anet init profile <id> --alias <名字> --channel server:commhub`)}function Zz(){let B=
|
|
69
|
+
✅ Project ready. Next: anet init profile <id> --alias <名字> --channel server:commhub`)}function Zz(){let B=T[2];if(!B)console.error("Usage: anet init profile <id> --alias <名字> [--channel ...] [--env ...]"),process.exit(1);let Q=O(),z=M(),W=z.alias||B,N=z.hub||Q.hub;if(!N)console.error("Run 'anet init' first to configure hub URL"),process.exit(1);let X={};for(let E of z._envs){let R=E.indexOf("=");if(R>0)X[E.slice(0,R)]=E.slice(R+1)}let U=z.runtime||"claude-code",Y={anet_version:"0.0.24",...z.name?{name:z.name}:{},runtime:U,alias:W,hub:N,...z.model?{model:z.model}:{},...z.tools?{tools:z.tools.split(",").map((E)=>E.trim())}:{},channels:z._channels.length>0?z._channels:U==="claude-code"?["server:commhub"]:[],env:X,flags:{dangerouslySkipPermissions:!0,...U==="claude-code"?{teammateMode:z["teammate-mode"]||"in-process"}:{},...z["max-turns"]?{maxTurns:parseInt(z["max-turns"])}:{}},...z.resume?{resume:z.resume}:{},...z["resume-alias"]?{resumeAlias:z["resume-alias"]}:{}},Z=K(G,".claude","channels","commhub"),$=process.cwd().replace(/\//g,"-"),L=K(Z,$);if(J(L,{recursive:!0}),q(K(L,".env"),`COMMHUB_ALIAS=${W}
|
|
70
70
|
`),b(B,Y),console.log(`
|
|
71
71
|
✅ Profile "${B}" saved`),console.log(` alias: ${W}`),console.log(` channels: ${Y.channels.join(", ")}`),Object.keys(X).length)console.log(` env: ${Object.keys(X).join(", ")}`);console.log(`
|
|
72
72
|
Start: anet start ${B}`)}var F=null;function Nz(){if(!F)F=$z({input:process.stdin,output:process.stdout});return F}function l(){if(F)F.close(),F=null}function H(B,Q){let z=Q?` [${Q}]`:"";return new Promise((W)=>{Nz().question(`${B}${z}: `,(N)=>{W(N.trim()||Q||"")})})}async function Uz(B){let Q=O();console.log(`
|
|
@@ -74,12 +74,12 @@ Profile "${B}" not found. Let's create it:
|
|
|
74
74
|
`);let z=await H("Runtime (claude-code / agent-sdk)","claude-code"),W=await H("Alias",B),N,X=[],U=[],Y="";if(z==="agent-sdk")N=await H("Model","MiniMax-M2.7"),X=(await H("Tools (comma-separated)","Read,Bash,Grep")).split(",").map((_)=>_.trim()).filter(Boolean);else U=(await H("Channels (comma-separated)","server:commhub")).split(",").map((_)=>_.trim()).filter(Boolean),Y=await H("Teammate mode","in-process");let Z=await H("Extra env (K=V, comma-separated, empty to skip)"),$={};if(Z)for(let R of Z.split(",")){let _=R.trim().indexOf("=");if(_>0)$[R.trim().slice(0,_)]=R.trim().slice(_+1)}let L=Q.hub;if(!L)console.error(`
|
|
75
75
|
Run 'anet init' first to configure hub URL`),process.exit(1);let E={anet_version:"0.0.23",alias:W,hub:L,runtime:z,...N?{model:N}:{},...X.length?{tools:X}:{},channels:U,env:$,flags:{dangerouslySkipPermissions:!0,...Y?{teammateMode:Y}:{}}};return b(B,E),l(),console.log(`
|
|
76
76
|
✅ Profile "${B}" saved
|
|
77
|
-
`),E}function Kz(B){if((B.runtime||"claude-code")!=="claude-code")return;if(!B.channels?.some((L)=>L.includes("commhub")))return;let Q=K(process.cwd(),".mcp.json"),z={};if(
|
|
78
|
-
`);try{c("bun install",{cwd:W,stdio:"pipe"})}catch{}}let U=K(W,".env"),Y=O(),Z=
|
|
77
|
+
`),E}function Kz(B){if((B.runtime||"claude-code")!=="claude-code")return;if(!B.channels?.some((L)=>L.includes("commhub")))return;let Q=K(process.cwd(),".mcp.json"),z={};if(V(Q))try{z=JSON.parse(I(Q,"utf-8"))}catch{}if(z.mcpServers?.commhub)return;let W=K(process.cwd(),".anet"),N=K(W,"node-server.ts");if(!V(N)){J(W,{recursive:!0});let L=[K(new URL(".",import.meta.url).pathname,"..","..","src","node-server.ts"),K(new URL(".",import.meta.url).pathname,"..","src","node-server.ts"),K(process.argv[1],"..","..","src","node-server.ts")];for(let E of L)if(V(E)){q(N,I(E,"utf-8")),console.log("[anet] Created .anet/node-server.ts");break}}let X=K(W,"package.json");if(!V(X)){J(W,{recursive:!0}),q(X,JSON.stringify({private:!0,dependencies:{"@modelcontextprotocol/sdk":"^1.12.0"}},null,2)+`
|
|
78
|
+
`);try{c("bun install",{cwd:W,stdio:"pipe"})}catch{}}let U=K(W,".env"),Y=O(),Z=B.token||v(),$=`COMMHUB_URL=${B.hub||Y.hub||"http://127.0.0.1:9200"}
|
|
79
79
|
`;if(Z)$+=`COMMHUB_TOKEN=${Z}
|
|
80
|
-
`;
|
|
81
|
-
`),console.log("[anet] .mcp.json: added commhub channel server")}async function r(B,Q){let z=A(B);if(!z)z=await Uz(B);let W=z.runtime||"claude-code";
|
|
82
|
-
`),Kz(z)
|
|
80
|
+
`;q(U,$),z.mcpServers=z.mcpServers||{},z.mcpServers.commhub={type:"stdio",command:"bun",args:[".anet/node-server.ts"]},q(Q,JSON.stringify(z,null,2)+`
|
|
81
|
+
`),console.log("[anet] .mcp.json: added commhub channel server")}async function r(B,Q){let z=A(B);if(!z)z=await Uz(B);let W=z.runtime||"claude-code";console.log(`[anet] ${Q==="start"?"Starting new":"Resuming"} "${B}" (${z.alias}) [${W}]...
|
|
82
|
+
`),Kz(z);let X=z.token||v();if(W==="agent-sdk"){let U=["@sleep2agi/agent-node","--alias",z.alias,"--hub",z.hub];if(z.model)U.push("--model",z.model);if(z.tools?.length)U.push("--tools",z.tools.join(","));if(z.flags?.maxTurns)U.push("--max-turns",String(z.flags.maxTurns));let Y={...process.env,...X?{COMMHUB_TOKEN:X}:{}};for(let[$,L]of Object.entries(z.env))Y[$]=L.replace(/^~/,G);C("npx",U,{env:Y,stdio:"inherit",shell:!0}).on("exit",($)=>process.exit($||0))}else{let U={...process.env,COMMHUB_ALIAS:z.alias,...X?{COMMHUB_TOKEN:X}:{}};for(let[$,L]of Object.entries(z.env))U[$]=L.replace(/^~/,G);let Y=[];if(z.flags.dangerouslySkipPermissions)Y.push("--dangerously-skip-permissions");for(let $ of z.channels)if($.startsWith("server:"))Y.push("--dangerously-load-development-channels",$);else Y.push("--channels",$);if(z.flags.teammateMode)Y.push("--teammate-mode",z.flags.teammateMode);if(Q==="resume"){let $=z.resume||z.resumeAlias||z.name||z.alias;Y.push("--resume",$)}Y.push("-n",z.name||z.alias),C("claude",Y,{env:U,stdio:"inherit",shell:!0}).on("exit",($)=>process.exit($||0))}}async function g(){let B=T[1];if(!B){n("start");return}await r(B,"start")}async function Lz(){let B=T[1];if(!B){n("resume");return}let Q=A(B);if(!Q){let z=M(),W=O(),N=z.hub||W.hub,X=z.session;if(!X)console.log(`Profile "${B}" not found.
|
|
83
83
|
`),console.log(`Quick setup: anet resume ${B} --session <session-id>`),console.log(`Or create: anet init profile ${B} --alias ${B} --resume <session-id>`),process.exit(1);if(!N)console.error("Run 'anet init' first"),process.exit(1);Q={runtime:"claude-code",alias:z.alias||B,hub:N,channels:["server:commhub"],env:{},flags:{dangerouslySkipPermissions:!0,teammateMode:"in-process"},resume:X},b(B,Q),console.log(`[anet] Created .anet/nodes/${B}/config.json (resume: ${X.slice(0,8)}...)
|
|
84
84
|
`)}await r(B,"resume")}function n(B){let Q=d();if(Q.length===0){console.log("No profiles. Run: anet init profile <id> --alias <名字>");return}console.log(`
|
|
85
85
|
Profiles:
|
|
@@ -87,9 +87,9 @@ Profiles:
|
|
|
87
87
|
anet ${B} <id>
|
|
88
88
|
`)}async function Rz(){let B=d();if(B.length>0){console.log(`
|
|
89
89
|
Profiles:
|
|
90
|
-
`);for(let Y of B){let Z=A(Y);console.log(` ${Y}${Z?.name?` (${Z.name})`:""} → ${Z?.alias} [${Z?.channels.join(", ")}]`)}console.log()}let Q=process.cwd(),z=K(G,".claude","sessions"),W=[];if(
|
|
91
|
-
`);return}let N=O(),X=[],U={};if(N.hub)try{let[Y,Z]=await Promise.all([fetch(`${N.hub}/api/status`,{headers:
|
|
92
|
-
`),console.log(" SESSION PID NETWORK"),console.log(" ──────────────────── ─────── ─────────────────────");for(let Y of W){let Z=Y.sessionId.slice(0,18),$=!1;try{process.kill(Y.pid,0),$=!0}catch{}let L="(not in network)",E=Q.replace(/\//g,"-"),R=K(G,".claude","channels","commhub",E,".env");if(
|
|
90
|
+
`);for(let Y of B){let Z=A(Y);console.log(` ${Y}${Z?.name?` (${Z.name})`:""} → ${Z?.alias} [${Z?.channels.join(", ")}]`)}console.log()}let Q=process.cwd(),z=K(G,".claude","sessions"),W=[];if(V(z))for(let Y of m(z).filter((Z)=>Z.endsWith(".json")))try{let Z=JSON.parse(I(K(z,Y),"utf-8"));if(Z.cwd===Q)W.push(Z)}catch{}if(W.length===0&&B.length===0){console.log("No sessions or profiles in this directory."),console.log(`Get started: anet init
|
|
91
|
+
`);return}let N=O(),X=[],U={};if(N.hub)try{let[Y,Z]=await Promise.all([fetch(`${N.hub}/api/status`,{headers:P()}).then(($)=>$.json()),fetch(`${N.hub}/health`,{headers:P()}).then(($)=>$.json())]);X=Y.sessions||[],U=Z.sse_sessions||{}}catch{}if(W.length>0){console.log(`Sessions (${Q}):
|
|
92
|
+
`),console.log(" SESSION PID NETWORK"),console.log(" ──────────────────── ─────── ─────────────────────");for(let Y of W){let Z=Y.sessionId.slice(0,18),$=!1;try{process.kill(Y.pid,0),$=!0}catch{}let L="(not in network)",E=Q.replace(/\//g,"-"),R=K(G,".claude","channels","commhub",E,".env");if(V(R)){let k=I(R,"utf-8").match(/COMMHUB_ALIAS=(.+)/);if(k){let x=k[1].trim(),y=X.find((a)=>a.alias===x),t=U[x]?"●":"○";L=y?`${x} ${y.status} ${t}`:`${x} (not registered)`}}console.log(` ${Z} ${($?`${Y.pid}`:`${Y.pid}✕`).padEnd(7)} ${L}`)}console.log()}}async function Ez(){let B=O(),Q=M(),z=process.env.COMMHUB_URL||Q.hub||B.hub||"http://127.0.0.1:9200",W=process.env.COMMHUB_ALIAS||Q.alias;if(!W)console.error("Error: --alias required"),process.exit(1);let{CommHub:N}=await Promise.resolve().then(() => (h(),u)),X=new N({url:z,alias:W});X.on("task",async(U)=>{console.log(`[${W}] ← ${U.from_session}: ${U.content.slice(0,100)}`),await X.send(U.from_session,`[${W}] 收到: ${U.content.slice(0,200)}`)}),X.on("connected",()=>console.log(`[${W}] Connected`)),X.on("disconnected",()=>console.log(`[${W}] Reconnecting...`)),process.on("SIGINT",()=>X.disconnect().then(()=>process.exit(0))),console.log(`[${W}] Listening on ${z}`)}async function Tz(){if(T[1]==="start"){let Q=M(),z=Q.port||"9200",W=Q.host||"0.0.0.0",N=Q.token||"";console.log(`[anet] Starting CommHub Server on ${W}:${z}...`);let X={...process.env,PORT:z,HOST:W};if(N)X.COMMHUB_AUTH_TOKEN=N;C("npx",["--yes","@sleep2agi/commhub-server"],{env:X,stdio:"inherit",shell:!0}).on("exit",(Y)=>process.exit(Y||0))}else console.log(`
|
|
93
93
|
anet server <command>
|
|
94
94
|
|
|
95
95
|
start [options] Start CommHub Server
|
|
@@ -103,6 +103,6 @@ Example:
|
|
|
103
103
|
anet server start
|
|
104
104
|
anet server start --port 9200 --token my-secret
|
|
105
105
|
anet server start --host 0.0.0.0 --port 9200
|
|
106
|
-
`)}async function
|
|
106
|
+
`)}async function Vz(){let B=O(),z=M().hub||B.hub;if(!z)console.error("Run 'anet init' first"),process.exit(1);let W=[];try{W=(await(await fetch(`${z}/api/status`,{headers:P()})).json()).sessions||[]}catch(Z){console.error(`Cannot reach ${z}: ${Z.message}`),process.exit(1)}if(W.length===0){console.log("No sessions in CommHub.");return}let N=W.filter((Z)=>Z.agent==="claude-code"&&Z.project_dir);if(N.length===0){console.log("No claude-code sessions found.");return}let X=T[1],U=X?N.filter((Z)=>Z.alias===X):N;if(U.length===0){console.log(`No session found for "${X}".`);return}let Y=0;for(let Z of U){let $=Z.project_dir,L=K($,".anet","nodes",Z.alias),E=K(L,"config.json");if(V(E)){console.log(` ⏭ ${Z.alias} — already exists (${$})`);continue}if(!V($)){console.log(` ⚠ ${Z.alias} — project_dir not found: ${$}`);continue}let R={runtime:"claude-code",alias:Z.alias,hub:z,channels:["server:commhub"],env:{},flags:{dangerouslySkipPermissions:!0,teammateMode:"in-process"},resume:Z.resume_id};J(L,{recursive:!0}),q(E,JSON.stringify(R,null,2)+`
|
|
107
107
|
`),console.log(` ✅ ${Z.alias} → ${$}/.anet/nodes/${Z.alias}/config.json`),Y++}console.log(`
|
|
108
|
-
Imported ${Y} session(s). Use: cd <project> && anet resume <alias>`)}switch(
|
|
108
|
+
Imported ${Y} session(s). Use: cd <project> && anet resume <alias>`)}switch(w){case"init":if(T[1]==="project")Yz();else if(T[1]==="profile")Zz();else Xz();break;case"server":Tz();break;case"start":g();break;case"resume":Lz();break;case"import":Vz();break;case"ls":case"list":Rz();break;case"run":Ez();break;case"--help":case"-h":case void 0:f();break;default:if(A(w))T.unshift("start"),g();else console.error(`Unknown: ${w}`),f(),process.exit(1)}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sleep2agi/agent-network",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.35",
|
|
4
4
|
"description": "AI Agent Network — Server + Client + Setup in one package. SSE real-time communication for multi-agent orchestration.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/src/client.js",
|