@sleep2agi/agent-network 0.0.6 → 0.0.7

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 CHANGED
@@ -59,7 +59,8 @@ anet init profile <id> [options] # → .anet/profiles/<id>.json
59
59
 
60
60
  ```
61
61
  ~/.anet/config.json 全局(hub URL)
62
- {workpath}/.anet/profiles/cmd.json 项目 profile
62
+ {workpath}/.mcp.json MCP server 配置(commhub stdio)
63
+ {workpath}/.anet/profiles/cmd.json 启动 profile
63
64
  ```
64
65
 
65
66
  #### anet init
@@ -76,7 +77,7 @@ anet init
76
77
 
77
78
  #### anet init project
78
79
 
79
- 下载 Channel 插件 + 安装依赖 + `~/.claude.json` + 写 .env。
80
+ 下载 Channel 插件 + 安装依赖 + `.mcp.json`(commhub stdio)+ 写 .env。
80
81
 
81
82
  ```bash
82
83
  cd ~/my-project
@@ -190,6 +191,7 @@ const { CommHub } = require('@sleep2agi/agent-network');
190
191
 
191
192
  | 版本 | 变更 |
192
193
  |------|------|
194
+ | 0.0.7 | init project 改写 .mcp.json(不写 ~/.claude.json),避免全局污染 |
193
195
  | 0.0.6 | 三级 init(全局/项目/profile),`anet ls` 简化为当前目录 |
194
196
  | 0.0.5 | `anet ls` 显示本地 sessions + CommHub 网络状态 |
195
197
  | 0.0.4 | CLI 瘦身 580KB→13KB,Node.js 兼容,profile 系统 |
package/dist/bin/cli.js CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
- import{createRequire as d}from"node:module";var h=Object.defineProperty;var g=(Q)=>Q;function m(Q,z){this[Q]=g.bind(null,z)}var p=(Q,z)=>{for(var V in z)h(Q,V,{get:z[V],enumerable:!0,configurable:!0,set:m.bind(z,V)})};var c=(Q,z)=>()=>(Q&&(z=Q(Q=0)),z);var t=d(import.meta.url);var D={};p(D,{default:()=>n,CommHub:()=>H});import{EventEmitter as l}from"events";import{hostname as x}from"os";var H,n;var P=c(()=>{H=class H extends l{url;alias;token;agent;resumeId;heartbeatInterval;reconnectDelay;heartbeatTimer;sseAbort;running=!1;constructor(Q){super();if(this.url=Q.url.replace(/\/$/,""),this.alias=Q.alias,this.token=Q.token,this.agent=Q.agent||"sdk",this.resumeId=`sdk-${Q.alias}-${Date.now().toString(36)}`,this.heartbeatInterval=Q.heartbeatInterval??180000,this.reconnectDelay=Q.reconnectDelay??3000,Q.autoConnect!==!1)this.connect()}log(Q){console.log(`[${new Date().toTimeString().slice(0,8)}] [commhub:${this.alias}] ${Q}`)}async call(Q,z){let V={"Content-Type":"application/json"};if(this.token)V.Authorization=`Bearer ${this.token}`;let $=await(await fetch(`${this.url}/mcp`,{method:"POST",headers:V,body:JSON.stringify({jsonrpc:"2.0",id:Date.now(),method:"tools/call",params:{name:Q,arguments:z}})})).json(),Y=$?.result?.content?.[0]?.text;return Y?JSON.parse(Y):$}async connect(){if(this.running)return;this.running=!0,await this.status("idle"),this.log("registered"),this.heartbeatTimer=setInterval(()=>{this.status("idle").catch((Q)=>this.log(`heartbeat failed: ${Q.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(Q,z,V="normal"){return this.call("send_task",{alias:Q,task:z,priority:V,from_session:this.alias})}async message(Q,z){return this.call("send_message",{alias:Q,message:z,from_session:this.alias})}async reply(Q,z,V="completed"){return this.call("reply",{task_id:Q,text:z,status:V})}async status(Q,z){return this.call("report_status",{resume_id:this.resumeId,alias:this.alias,status:Q,server:x(),hostname:x(),agent:this.agent,project_dir:process.cwd(),...z})}async getAllStatus(){return this.call("get_all_status",{})}async broadcast(Q,z){return this.call("broadcast",{message:Q,filter_server:z?.server,filter_status:z?.status})}async connectSSE(){let Q=encodeURIComponent(this.alias),z=`${this.url}/events/${Q}`,V=this.reconnectDelay;while(this.running){try{this.sseAbort=new AbortController;let X={Accept:"text/event-stream"};if(this.token)X.Authorization=`Bearer ${this.token}`;let $=await fetch(z,{headers:X,signal:this.sseAbort.signal});if(!$.ok||!$.body){this.log(`SSE failed: ${$.status}`),await this.sleep(V),V=Math.min(V*1.5,60000);continue}V=this.reconnectDelay;let Y=$.body.getReader(),N=new TextDecoder,Z="";while(this.running){let{done:L,value:U}=await Y.read();if(L)break;Z+=N.decode(U,{stream:!0});let _=Z.split(`
3
- `);Z=_.pop()||"";for(let B of _){if(!B.startsWith("data: "))continue;try{let O=JSON.parse(B.slice(6));if(O.type==="connected"){this.log("SSE connected"),this.emit("connected");continue}if(O.type==="new_task"||O.type==="new_message"||O.type==="broadcast")await this.processInbox()}catch{}}}}catch(X){if(X.name==="AbortError")break;this.emit("error",X),this.log(`SSE error: ${X.message}`)}if(this.running)this.emit("disconnected"),this.log(`SSE reconnecting in ${V/1000}s...`),await this.sleep(V),V=Math.min(V*1.5,60000)}}async processInbox(){try{let z=(await this.call("get_inbox",{alias:this.alias,limit:10}))?.messages||[];for(let V of z)await this.call("ack_inbox",{alias:this.alias,message_id:V.id}),this.log(`← ${V.from_session}: ${V.content.slice(0,60)}`),this.emit("task",V),this.emit("message",V)}catch(Q){this.log(`inbox error: ${Q.message}`)}}sleep(Q){return new Promise((z)=>setTimeout(z,Q))}};n=H});import{readFileSync as I,writeFileSync as E,existsSync as q,mkdirSync as J,readdirSync as v}from"fs";import{join as R}from"path";import{spawn as o}from"child_process";var W=process.argv.slice(2),A=W[0],K=process.env.HOME||process.env.USERPROFILE||"~";function S(){return R(K,".anet","config.json")}function C(){return R(process.cwd(),".anet","profiles")}function M(){let Q=S();if(q(Q))try{return JSON.parse(I(Q,"utf-8"))}catch{}return{}}function r(Q){let z=R(K,".anet");J(z,{recursive:!0}),E(R(z,"config.json"),JSON.stringify(Q,null,2)+`
4
- `)}function G(Q){let z=R(C(),`${Q}.json`);if(q(z))try{return JSON.parse(I(z,"utf-8"))}catch{}return null}function a(Q,z){let V=C();J(V,{recursive:!0}),E(R(V,`${Q}.json`),JSON.stringify(z,null,2)+`
5
- `)}function y(){let Q=C();if(!q(Q))return[];return v(Q).filter((z)=>z.endsWith(".json")).map((z)=>z.replace(/\.json$/,""))}function F(){let Q={_channels:[],_envs:[]};for(let z=0;z<W.length;z++){if(W[z]==="--channel"&&W[z+1]){Q._channels.push(W[++z]);continue}if(W[z]==="--env"&&W[z+1]){Q._envs.push(W[++z]);continue}if(W[z].startsWith("--")&&W[z+1]&&!W[z+1].startsWith("--"))Q[W[z].slice(2)]=W[++z]}return Q}function j(){console.log(`
2
+ import{createRequire as d}from"node:module";var h=Object.defineProperty;var g=(Q)=>Q;function m(Q,z){this[Q]=g.bind(null,z)}var c=(Q,z)=>{for(var V in z)h(Q,V,{get:z[V],enumerable:!0,configurable:!0,set:m.bind(z,V)})};var p=(Q,z)=>()=>(Q&&(z=Q(Q=0)),z);var l=d(import.meta.url);var P={};c(P,{default:()=>t,CommHub:()=>H});import{EventEmitter as n}from"events";import{hostname as x}from"os";var H,t;var C=p(()=>{H=class H extends n{url;alias;token;agent;resumeId;heartbeatInterval;reconnectDelay;heartbeatTimer;sseAbort;running=!1;constructor(Q){super();if(this.url=Q.url.replace(/\/$/,""),this.alias=Q.alias,this.token=Q.token,this.agent=Q.agent||"sdk",this.resumeId=`sdk-${Q.alias}-${Date.now().toString(36)}`,this.heartbeatInterval=Q.heartbeatInterval??180000,this.reconnectDelay=Q.reconnectDelay??3000,Q.autoConnect!==!1)this.connect()}log(Q){console.log(`[${new Date().toTimeString().slice(0,8)}] [commhub:${this.alias}] ${Q}`)}async call(Q,z){let V={"Content-Type":"application/json"};if(this.token)V.Authorization=`Bearer ${this.token}`;let $=await(await fetch(`${this.url}/mcp`,{method:"POST",headers:V,body:JSON.stringify({jsonrpc:"2.0",id:Date.now(),method:"tools/call",params:{name:Q,arguments:z}})})).json(),Y=$?.result?.content?.[0]?.text;return Y?JSON.parse(Y):$}async connect(){if(this.running)return;this.running=!0,await this.status("idle"),this.log("registered"),this.heartbeatTimer=setInterval(()=>{this.status("idle").catch((Q)=>this.log(`heartbeat failed: ${Q.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(Q,z,V="normal"){return this.call("send_task",{alias:Q,task:z,priority:V,from_session:this.alias})}async message(Q,z){return this.call("send_message",{alias:Q,message:z,from_session:this.alias})}async reply(Q,z,V="completed"){return this.call("reply",{task_id:Q,text:z,status:V})}async status(Q,z){return this.call("report_status",{resume_id:this.resumeId,alias:this.alias,status:Q,server:x(),hostname:x(),agent:this.agent,project_dir:process.cwd(),...z})}async getAllStatus(){return this.call("get_all_status",{})}async broadcast(Q,z){return this.call("broadcast",{message:Q,filter_server:z?.server,filter_status:z?.status})}async connectSSE(){let Q=encodeURIComponent(this.alias),z=`${this.url}/events/${Q}`,V=this.reconnectDelay;while(this.running){try{this.sseAbort=new AbortController;let X={Accept:"text/event-stream"};if(this.token)X.Authorization=`Bearer ${this.token}`;let $=await fetch(z,{headers:X,signal:this.sseAbort.signal});if(!$.ok||!$.body){this.log(`SSE failed: ${$.status}`),await this.sleep(V),V=Math.min(V*1.5,60000);continue}V=this.reconnectDelay;let Y=$.body.getReader(),N=new TextDecoder,Z="";while(this.running){let{done:L,value:U}=await Y.read();if(L)break;Z+=N.decode(U,{stream:!0});let _=Z.split(`
3
+ `);Z=_.pop()||"";for(let B of _){if(!B.startsWith("data: "))continue;try{let K=JSON.parse(B.slice(6));if(K.type==="connected"){this.log("SSE connected"),this.emit("connected");continue}if(K.type==="new_task"||K.type==="new_message"||K.type==="broadcast")await this.processInbox()}catch{}}}}catch(X){if(X.name==="AbortError")break;this.emit("error",X),this.log(`SSE error: ${X.message}`)}if(this.running)this.emit("disconnected"),this.log(`SSE reconnecting in ${V/1000}s...`),await this.sleep(V),V=Math.min(V*1.5,60000)}}async processInbox(){try{let z=(await this.call("get_inbox",{alias:this.alias,limit:10}))?.messages||[];for(let V of z)await this.call("ack_inbox",{alias:this.alias,message_id:V.id}),this.log(`← ${V.from_session}: ${V.content.slice(0,60)}`),this.emit("task",V),this.emit("message",V)}catch(Q){this.log(`inbox error: ${Q.message}`)}}sleep(Q){return new Promise((z)=>setTimeout(z,Q))}};t=H});import{readFileSync as I,writeFileSync as O,existsSync as q,mkdirSync as G,readdirSync as v}from"fs";import{join as R}from"path";import{spawn as r}from"child_process";var W=process.argv.slice(2),A=W[0],E=process.env.HOME||process.env.USERPROFILE||"~";function S(){return R(E,".anet","config.json")}function F(){return R(process.cwd(),".anet","profiles")}function T(){let Q=S();if(q(Q))try{return JSON.parse(I(Q,"utf-8"))}catch{}return{}}function o(Q){let z=R(E,".anet");G(z,{recursive:!0}),O(R(z,"config.json"),JSON.stringify(Q,null,2)+`
4
+ `)}function M(Q){let z=R(F(),`${Q}.json`);if(q(z))try{return JSON.parse(I(z,"utf-8"))}catch{}return null}function a(Q,z){let V=F();G(V,{recursive:!0}),O(R(V,`${Q}.json`),JSON.stringify(z,null,2)+`
5
+ `)}function y(){let Q=F();if(!q(Q))return[];return v(Q).filter((z)=>z.endsWith(".json")).map((z)=>z.replace(/\.json$/,""))}function k(){let Q={_channels:[],_envs:[]};for(let z=0;z<W.length;z++){if(W[z]==="--channel"&&W[z+1]){Q._channels.push(W[++z]);continue}if(W[z]==="--env"&&W[z+1]){Q._envs.push(W[++z]);continue}if(W[z].startsWith("--")&&W[z+1]&&!W[z+1].startsWith("--"))Q[W[z].slice(2)]=W[++z]}return Q}function j(){console.log(`
6
6
  anet — AI Agent Network CLI
7
7
 
8
8
  anet init Configure hub URL (global, once)
@@ -18,20 +18,20 @@ Quick start:
18
18
  anet init project
19
19
  anet init profile cmd --alias 指挥室 --channel server:commhub
20
20
  anet start cmd
21
- `)}async function i(){let Q=F(),z=Q.hub;if(!z)process.stdout.write("CommHub URL (e.g. http://YOUR_IP:9200): "),z=await new Promise((X)=>{let $="";process.stdin.setEncoding("utf-8"),process.stdin.once("data",(Y)=>{X(Y.toString().trim())})});if(!z)console.error("Error: hub URL required"),process.exit(1);try{let $=await(await fetch(`${z}/health`)).json();console.log(`✅ CommHub v${$.version} — ${$.sessions} sessions, ${$.sse_connections} SSE`)}catch(X){console.error(`❌ Cannot reach ${z}: ${X.message}`),process.exit(1)}let V=M();if(V.hub=z,Q.token)V.token=Q.token;r(V),console.log(`
22
- Saved to ${S()}`),console.log("Next: anet init project")}async function e(){let z=M().hub;if(!z)console.error("Run 'anet init' first to configure hub URL"),process.exit(1);let V=R(K,".claude","channels","commhub");J(V,{recursive:!0});let X=R(V,"server.ts");if(!q(X)){console.log("Downloading Channel plugin...");try{let L=await fetch("https://raw.githubusercontent.com/sleep2agi/agent-comm-hub/main/channel/server.ts");if(L.ok)E(X,await L.text()),console.log(` ✅ ${X}`)}catch(L){console.log(` ❌ Failed: ${L.message}`),console.log(` Manual: curl -sL https://raw.githubusercontent.com/sleep2agi/agent-comm-hub/main/channel/server.ts -o ${X}`)}}else console.log("Channel plugin: exists");let $=R(V,"package.json");if(!q($))try{let L=await fetch("https://raw.githubusercontent.com/sleep2agi/agent-comm-hub/main/channel/package.json");if(L.ok){E($,await L.text());try{let{execSync:U}=await import("child_process");U("bun install",{cwd:V,stdio:"pipe"}),console.log("Dependencies installed")}catch{console.log("⚠️ Run: cd ~/.claude/channels/commhub && bun install")}}}catch{}let Y=R(V,".env");if(!q(Y))E(Y,`COMMHUB_URL=${z}
23
- `);console.log(`CommHub URL: ${z}`);let N=R(K,".claude.json"),Z={};if(q(N))try{Z=JSON.parse(I(N,"utf-8"))}catch{}if(!Z.mcpServers?.commhub)Z.mcpServers=Z.mcpServers||{},Z.mcpServers.commhub={type:"stdio",command:"bun",args:["run",X]},E(N,JSON.stringify(Z,null,2)+`
24
- `),console.log(`MCP config: ${N}`);else console.log("MCP config: already set");console.log(`
25
- ✅ Project ready. Next: anet init profile <id> --alias <名字> --channel server:commhub`)}function s(){let Q=W[2];if(!Q)console.error("Usage: anet init profile <id> --alias <名字> [--channel ...] [--env ...]"),process.exit(1);let z=M(),V=F(),X=V.alias||Q,$=V.hub||z.hub;if(!$)console.error("Run 'anet init' first to configure hub URL"),process.exit(1);let Y={};for(let _ of V._envs){let B=_.indexOf("=");if(B>0)Y[_.slice(0,B)]=_.slice(B+1)}let N={...V.name?{name:V.name}:{},alias:X,hub:$,channels:V._channels.length>0?V._channels:["server:commhub"],env:Y,flags:{dangerouslySkipPermissions:!0,...V["teammate-mode"]?{teammateMode:V["teammate-mode"]}:{}},...V.resume?{resume:V.resume}:{}},Z=R(K,".claude","channels","commhub"),L=process.cwd().replace(/\//g,"-"),U=R(Z,L);if(J(U,{recursive:!0}),E(R(U,".env"),`COMMHUB_ALIAS=${X}
21
+ `)}async function i(){let Q=k(),z=Q.hub;if(!z)process.stdout.write("CommHub URL (e.g. http://YOUR_IP:9200): "),z=await new Promise((X)=>{let $="";process.stdin.setEncoding("utf-8"),process.stdin.once("data",(Y)=>{X(Y.toString().trim())})});if(!z)console.error("Error: hub URL required"),process.exit(1);try{let $=await(await fetch(`${z}/health`)).json();console.log(`✅ CommHub v${$.version} — ${$.sessions} sessions, ${$.sse_connections} SSE`)}catch(X){console.error(`❌ Cannot reach ${z}: ${X.message}`),process.exit(1)}let V=T();if(V.hub=z,Q.token)V.token=Q.token;o(V),console.log(`
22
+ Saved to ${S()}`),console.log("Next: anet init project")}async function e(){let z=T().hub;if(!z)console.error("Run 'anet init' first to configure hub URL"),process.exit(1);let V=R(E,".claude","channels","commhub");G(V,{recursive:!0});let X=R(V,"server.ts");if(!q(X)){console.log("Downloading Channel plugin...");try{let L=await fetch("https://raw.githubusercontent.com/sleep2agi/agent-comm-hub/main/channel/server.ts");if(L.ok)O(X,await L.text()),console.log(` ✅ ${X}`)}catch(L){console.log(` ❌ Failed: ${L.message}`),console.log(` Manual: curl -sL https://raw.githubusercontent.com/sleep2agi/agent-comm-hub/main/channel/server.ts -o ${X}`)}}else console.log("Channel plugin: exists");let $=R(V,"package.json");if(!q($))try{let L=await fetch("https://raw.githubusercontent.com/sleep2agi/agent-comm-hub/main/channel/package.json");if(L.ok){O($,await L.text());try{let{execSync:U}=await import("child_process");U("bun install",{cwd:V,stdio:"pipe"}),console.log("Dependencies installed")}catch{console.log("⚠️ Run: cd ~/.claude/channels/commhub && bun install")}}}catch{}let Y=R(V,".env");if(!q(Y))O(Y,`COMMHUB_URL=${z}
23
+ `);console.log(`CommHub URL: ${z}`);let N=R(process.cwd(),".mcp.json"),Z={};if(q(N))try{Z=JSON.parse(I(N,"utf-8"))}catch{}if(!Z.mcpServers?.commhub)Z.mcpServers=Z.mcpServers||{},Z.mcpServers.commhub={type:"stdio",command:"bun",args:[X]},O(N,JSON.stringify(Z,null,2)+`
24
+ `),console.log(".mcp.json: commhub added");else console.log(".mcp.json: commhub already set");console.log(`
25
+ ✅ Project ready. Next: anet init profile <id> --alias <名字> --channel server:commhub`)}function s(){let Q=W[2];if(!Q)console.error("Usage: anet init profile <id> --alias <名字> [--channel ...] [--env ...]"),process.exit(1);let z=T(),V=k(),X=V.alias||Q,$=V.hub||z.hub;if(!$)console.error("Run 'anet init' first to configure hub URL"),process.exit(1);let Y={};for(let _ of V._envs){let B=_.indexOf("=");if(B>0)Y[_.slice(0,B)]=_.slice(B+1)}let N={...V.name?{name:V.name}:{},alias:X,hub:$,channels:V._channels.length>0?V._channels:["server:commhub"],env:Y,flags:{dangerouslySkipPermissions:!0,...V["teammate-mode"]?{teammateMode:V["teammate-mode"]}:{}},...V.resume?{resume:V.resume}:{}},Z=R(E,".claude","channels","commhub"),L=process.cwd().replace(/\//g,"-"),U=R(Z,L);if(G(U,{recursive:!0}),O(R(U,".env"),`COMMHUB_ALIAS=${X}
26
26
  `),a(Q,N),console.log(`
27
27
  ✅ Profile "${Q}" saved`),console.log(` alias: ${X}`),console.log(` channels: ${N.channels.join(", ")}`),Object.keys(Y).length)console.log(` env: ${Object.keys(Y).join(", ")}`);console.log(`
28
28
  Start: anet start ${Q}`)}function b(){let Q=W[1];if(!Q){let Y=y();if(Y.length===0){console.log("No profiles. Run: anet init profile <id> --alias <名字>");return}console.log(`
29
29
  Profiles:
30
- `);for(let N of Y){let Z=G(N);console.log(` ${N}${Z?.name?` (${Z.name})`:""} → ${Z?.alias} [${Z?.channels.join(", ")}]`)}console.log(`
30
+ `);for(let N of Y){let Z=M(N);console.log(` ${N}${Z?.name?` (${Z.name})`:""} → ${Z?.alias} [${Z?.channels.join(", ")}]`)}console.log(`
31
31
  anet start <id>
32
- `);return}let z=G(Q);if(!z)console.error(`Profile "${Q}" not found. Run: anet ls`),process.exit(1);let V={...process.env,COMMHUB_ALIAS:z.alias};for(let[Y,N]of Object.entries(z.env))V[Y]=N.replace(/^~/,K);let X=[];if(z.flags.dangerouslySkipPermissions)X.push("--dangerously-skip-permissions");for(let Y of z.channels)if(Y.startsWith("server:"))X.push("--dangerously-load-development-channels",Y);else X.push("--channels",Y);if(z.flags.teammateMode)X.push("--teammate-mode",z.flags.teammateMode);if(z.resume)X.push("--resume",z.resume);X.push("-n",z.name||z.alias),console.log(`[anet] Starting "${Q}" (${z.alias})...
33
- `),o("claude",X,{env:V,stdio:"inherit",shell:!0}).on("exit",(Y)=>process.exit(Y||0))}async function zz(){let Q=y();if(Q.length>0){console.log(`
32
+ `);return}let z=M(Q);if(!z)console.error(`Profile "${Q}" not found. Run: anet ls`),process.exit(1);let V={...process.env,COMMHUB_ALIAS:z.alias};for(let[Y,N]of Object.entries(z.env))V[Y]=N.replace(/^~/,E);let X=[];if(z.flags.dangerouslySkipPermissions)X.push("--dangerously-skip-permissions");for(let Y of z.channels)if(Y.startsWith("server:"))X.push("--dangerously-load-development-channels",Y);else X.push("--channels",Y);if(z.flags.teammateMode)X.push("--teammate-mode",z.flags.teammateMode);if(z.resume)X.push("--resume",z.resume);X.push("-n",z.name||z.alias),console.log(`[anet] Starting "${Q}" (${z.alias})...
33
+ `),r("claude",X,{env:V,stdio:"inherit",shell:!0}).on("exit",(Y)=>process.exit(Y||0))}async function zz(){let Q=y();if(Q.length>0){console.log(`
34
34
  Profiles:
35
- `);for(let Z of Q){let L=G(Z);console.log(` ${Z}${L?.name?` (${L.name})`:""} → ${L?.alias} [${L?.channels.join(", ")}]`)}console.log()}let z=process.cwd(),V=R(K,".claude","sessions"),X=[];if(q(V))for(let Z of v(V).filter((L)=>L.endsWith(".json")))try{let L=JSON.parse(I(R(V,Z),"utf-8"));if(L.cwd===z)X.push(L)}catch{}if(X.length===0&&Q.length===0){console.log("No sessions or profiles in this directory."),console.log(`Get started: anet init
36
- `);return}let $=M(),Y=[],N={};if($.hub)try{let[Z,L]=await Promise.all([fetch(`${$.hub}/api/status`).then((U)=>U.json()),fetch(`${$.hub}/health`).then((U)=>U.json())]);Y=Z.sessions||[],N=L.sse_sessions||{}}catch{}if(X.length>0){console.log(`Sessions (${z}):
37
- `),console.log(" SESSION PID NETWORK"),console.log(" ──────────────────── ─────── ─────────────────────");for(let Z of X){let L=Z.sessionId.slice(0,18),U=!1;try{process.kill(Z.pid,0),U=!0}catch{}let _="(not in network)",B=z.replace(/\//g,"-"),O=R(K,".claude","channels","commhub",B,".env");if(q(O)){let k=I(O,"utf-8").match(/COMMHUB_ALIAS=(.+)/);if(k){let T=k[1].trim(),w=Y.find((f)=>f.alias===T),u=N[T]?"●":"○";_=w?`${T} ${w.status} ${u}`:`${T} (not registered)`}}console.log(` ${L} ${(U?`${Z.pid}`:`${Z.pid}✕`).padEnd(7)} ${_}`)}console.log()}}async function Qz(){let Q=M(),z=F(),V=process.env.COMMHUB_URL||z.hub||Q.hub||"http://127.0.0.1:9200",X=process.env.COMMHUB_ALIAS||z.alias;if(!X)console.error("Error: --alias required"),process.exit(1);let{CommHub:$}=await Promise.resolve().then(() => (P(),D)),Y=new $({url:V,alias:X});Y.on("task",async(N)=>{console.log(`[${X}] ← ${N.from_session}: ${N.content.slice(0,100)}`),await Y.send(N.from_session,`[${X}] 收到: ${N.content.slice(0,200)}`)}),Y.on("connected",()=>console.log(`[${X}] Connected`)),Y.on("disconnected",()=>console.log(`[${X}] Reconnecting...`)),process.on("SIGINT",()=>Y.disconnect().then(()=>process.exit(0))),console.log(`[${X}] Listening on ${V}`)}switch(A){case"init":if(W[1]==="project")e();else if(W[1]==="profile")s();else i();break;case"start":b();break;case"ls":case"list":zz();break;case"run":Qz();break;case"--help":case"-h":case void 0:j();break;default:if(G(A))W.unshift("start"),b();else console.error(`Unknown: ${A}`),j(),process.exit(1)}
35
+ `);for(let Z of Q){let L=M(Z);console.log(` ${Z}${L?.name?` (${L.name})`:""} → ${L?.alias} [${L?.channels.join(", ")}]`)}console.log()}let z=process.cwd(),V=R(E,".claude","sessions"),X=[];if(q(V))for(let Z of v(V).filter((L)=>L.endsWith(".json")))try{let L=JSON.parse(I(R(V,Z),"utf-8"));if(L.cwd===z)X.push(L)}catch{}if(X.length===0&&Q.length===0){console.log("No sessions or profiles in this directory."),console.log(`Get started: anet init
36
+ `);return}let $=T(),Y=[],N={};if($.hub)try{let[Z,L]=await Promise.all([fetch(`${$.hub}/api/status`).then((U)=>U.json()),fetch(`${$.hub}/health`).then((U)=>U.json())]);Y=Z.sessions||[],N=L.sse_sessions||{}}catch{}if(X.length>0){console.log(`Sessions (${z}):
37
+ `),console.log(" SESSION PID NETWORK"),console.log(" ──────────────────── ─────── ─────────────────────");for(let Z of X){let L=Z.sessionId.slice(0,18),U=!1;try{process.kill(Z.pid,0),U=!0}catch{}let _="(not in network)",B=z.replace(/\//g,"-"),K=R(E,".claude","channels","commhub",B,".env");if(q(K)){let w=I(K,"utf-8").match(/COMMHUB_ALIAS=(.+)/);if(w){let J=w[1].trim(),D=Y.find((f)=>f.alias===J),u=N[J]?"●":"○";_=D?`${J} ${D.status} ${u}`:`${J} (not registered)`}}console.log(` ${L} ${(U?`${Z.pid}`:`${Z.pid}✕`).padEnd(7)} ${_}`)}console.log()}}async function Qz(){let Q=T(),z=k(),V=process.env.COMMHUB_URL||z.hub||Q.hub||"http://127.0.0.1:9200",X=process.env.COMMHUB_ALIAS||z.alias;if(!X)console.error("Error: --alias required"),process.exit(1);let{CommHub:$}=await Promise.resolve().then(() => (C(),P)),Y=new $({url:V,alias:X});Y.on("task",async(N)=>{console.log(`[${X}] ← ${N.from_session}: ${N.content.slice(0,100)}`),await Y.send(N.from_session,`[${X}] 收到: ${N.content.slice(0,200)}`)}),Y.on("connected",()=>console.log(`[${X}] Connected`)),Y.on("disconnected",()=>console.log(`[${X}] Reconnecting...`)),process.on("SIGINT",()=>Y.disconnect().then(()=>process.exit(0))),console.log(`[${X}] Listening on ${V}`)}switch(A){case"init":if(W[1]==="project")e();else if(W[1]==="profile")s();else i();break;case"start":b();break;case"ls":case"list":zz();break;case"run":Qz();break;case"--help":case"-h":case void 0:j();break;default:if(M(A))W.unshift("start"),b();else console.error(`Unknown: ${A}`),j(),process.exit(1)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sleep2agi/agent-network",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
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",