@sleep2agi/agent-network 0.0.14 → 0.0.15
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 +3 -3
- package/package.json +1 -1
package/dist/bin/cli.js
CHANGED
|
@@ -20,7 +20,7 @@ Quick start:
|
|
|
20
20
|
anet init profile 指挥室 --alias 指挥室 --channel server:commhub
|
|
21
21
|
anet start 指挥室 # 新建
|
|
22
22
|
anet resume 指挥室 # 下次恢复
|
|
23
|
-
`)}async function s(){let z=F(),B=z.hub;if(!B)process.stdout.write("CommHub URL (e.g. http://YOUR_IP:9200): "),B=await new Promise((V)=>{process.stdin.setEncoding("utf-8"),process.stdin.once("data",(X)=>{process.stdin.unref(),V(X.toString().trim())})});if(!B)console.error("Error: hub URL required"),process.exit(1);try{let X=await(await fetch(`${B}/health`)).json();console.log(`✅ CommHub v${X.version} — ${X.sessions} sessions, ${X.sse_connections} SSE`)}catch(V){console.error(`❌ Cannot reach ${B}: ${V.message}`),process.exit(1)}let Q=I();if(Q.hub=B,z.token)Q.token=z.token;i(Q),console.log(`
|
|
23
|
+
`)}async function s(){let z=F(),B=z.hub;if(!B)process.stdout.write("CommHub URL (e.g. http://YOUR_IP:9200): "),B=await new Promise((V)=>{process.stdin.setEncoding("utf-8"),process.stdin.once("data",(X)=>{process.stdin.unref(),V(X.toString().trim())})});if(!B)console.error("Error: hub URL required"),process.exit(1);B=B.replace(/\/+$/,"");try{let X=await(await fetch(`${B}/health`)).json();console.log(`✅ CommHub v${X.version} — ${X.sessions} sessions, ${X.sse_connections} SSE`)}catch(V){console.error(`❌ Cannot reach ${B}: ${V.message}`),process.exit(1)}let Q=I();if(Q.hub=B,z.token)Q.token=z.token;i(Q),console.log(`
|
|
24
24
|
Saved to ${S()}`),console.log("Next: anet init project")}async function zz(){let B=I().hub;if(!B)console.error("Run 'anet init' first to configure hub URL"),process.exit(1);let Q=N(process.cwd(),".anet");G(Q,{recursive:!0});let V=N(Q,"server.ts");if(!_(V)){console.log("Downloading Channel plugin...");try{let $=await fetch("https://raw.githubusercontent.com/sleep2agi/agent-comm-hub/main/channel/server.ts");if($.ok)K(V,await $.text()),console.log(" ✅ .anet/server.ts")}catch($){console.log(` ❌ Failed: ${$.message}`),console.log(" Manual: curl -sL https://raw.githubusercontent.com/sleep2agi/agent-comm-hub/main/channel/server.ts -o .anet/server.ts")}}else console.log("Channel plugin: exists");let X=N(Q,"package.json");if(!_(X))try{let $=await fetch("https://raw.githubusercontent.com/sleep2agi/agent-comm-hub/main/channel/package.json");if($.ok){K(X,await $.text());try{let{execSync:R}=await import("child_process");R("bun install",{cwd:Q,stdio:"pipe"}),console.log(" ✅ Dependencies installed")}catch{console.log(" ⚠️ Run: cd .anet && bun install")}}}catch{}let Z=N(Q,".env");K(Z,`COMMHUB_URL=${B}
|
|
25
25
|
`),console.log(`CommHub URL: ${B}`);let U=N(process.cwd(),".mcp.json"),W={};if(_(U))try{W=JSON.parse(E(U,"utf-8"))}catch{}if(!W.mcpServers?.commhub)W.mcpServers=W.mcpServers||{},W.mcpServers.commhub={type:"stdio",command:"bun",args:[".anet/server.ts"]},K(U,JSON.stringify(W,null,2)+`
|
|
26
26
|
`),console.log(".mcp.json: commhub → .anet/server.ts");else console.log(".mcp.json: commhub already set");let Y=N(process.cwd(),"CLAUDE.md");if(!_(Y))K(Y,`# Agent Network (CommHub)
|
|
@@ -66,7 +66,7 @@ commhub_get_all_status()
|
|
|
66
66
|
`),e(z,U),console.log(`
|
|
67
67
|
✅ Profile "${z}" saved`),console.log(` alias: ${V}`),console.log(` channels: ${U.channels.join(", ")}`),Object.keys(Z).length)console.log(` env: ${Object.keys(Z).join(", ")}`);console.log(`
|
|
68
68
|
Start: anet start ${z}`)}function u(z,B){let Q=M(z);if(!Q)console.error(`Profile "${z}" not found. Run: anet ls`),process.exit(1);let V={...process.env,COMMHUB_ALIAS:Q.alias};for(let[W,Y]of Object.entries(Q.env))V[W]=Y.replace(/^~/,O);let X=[];if(Q.flags.dangerouslySkipPermissions)X.push("--dangerously-skip-permissions");for(let W of Q.channels)if(W.startsWith("server:"))X.push("--dangerously-load-development-channels",W);else X.push("--channels",W);if(Q.flags.teammateMode)X.push("--teammate-mode",Q.flags.teammateMode);if(B==="resume"){let W=Q.resumeAlias||Q.name||Q.alias;X.push("--resume",W)}X.push("-n",Q.name||Q.alias),console.log(`[anet] ${B==="start"?"Starting new":"Resuming"} "${z}" (${Q.alias})...
|
|
69
|
-
`),a("claude",X,{env:V,stdio:"inherit",shell:!0}).on("exit",(W)=>process.exit(W||0))}function v(){let z=L[1];if(!z){
|
|
69
|
+
`),a("claude",X,{env:V,stdio:"inherit",shell:!0}).on("exit",(W)=>process.exit(W||0))}function v(){let z=L[1];if(!z){f("start");return}u(z,"start")}function Qz(){let z=L[1];if(!z){f("resume");return}u(z,"resume")}function f(z){let B=y();if(B.length===0){console.log("No profiles. Run: anet init profile <id> --alias <名字>");return}console.log(`
|
|
70
70
|
Profiles:
|
|
71
71
|
`);for(let Q of B){let V=M(Q);console.log(` ${Q}${V?.name?` (${V.name})`:""} → ${V?.alias} [${V?.channels.join(", ")}]`)}console.log(`
|
|
72
72
|
anet ${z} <id>
|
|
@@ -74,4 +74,4 @@ anet ${z} <id>
|
|
|
74
74
|
Profiles:
|
|
75
75
|
`);for(let W of z){let Y=M(W);console.log(` ${W}${Y?.name?` (${Y.name})`:""} → ${Y?.alias} [${Y?.channels.join(", ")}]`)}console.log()}let B=process.cwd(),Q=N(O,".claude","sessions"),V=[];if(_(Q))for(let W of b(Q).filter((Y)=>Y.endsWith(".json")))try{let Y=JSON.parse(E(N(Q,W),"utf-8"));if(Y.cwd===B)V.push(Y)}catch{}if(V.length===0&&z.length===0){console.log("No sessions or profiles in this directory."),console.log(`Get started: anet init
|
|
76
76
|
`);return}let X=I(),Z=[],U={};if(X.hub)try{let[W,Y]=await Promise.all([fetch(`${X.hub}/api/status`).then(($)=>$.json()),fetch(`${X.hub}/health`).then(($)=>$.json())]);Z=W.sessions||[],U=Y.sse_sessions||{}}catch{}if(V.length>0){console.log(`Sessions (${B}):
|
|
77
|
-
`),console.log(" SESSION PID NETWORK"),console.log(" ──────────────────── ─────── ─────────────────────");for(let W of V){let Y=W.sessionId.slice(0,18),$=!1;try{process.kill(W.pid,0),$=!0}catch{}let R="(not in network)",q=B.replace(/\//g,"-"),T=N(O,".claude","channels","commhub",q,".env");if(_(T)){let D=E(T,"utf-8").match(/COMMHUB_ALIAS=(.+)/);if(D){let J=D[1].trim(),x=Z.find((g)=>g.alias===J),
|
|
77
|
+
`),console.log(" SESSION PID NETWORK"),console.log(" ──────────────────── ─────── ─────────────────────");for(let W of V){let Y=W.sessionId.slice(0,18),$=!1;try{process.kill(W.pid,0),$=!0}catch{}let R="(not in network)",q=B.replace(/\//g,"-"),T=N(O,".claude","channels","commhub",q,".env");if(_(T)){let D=E(T,"utf-8").match(/COMMHUB_ALIAS=(.+)/);if(D){let J=D[1].trim(),x=Z.find((g)=>g.alias===J),h=U[J]?"●":"○";R=x?`${J} ${x.status} ${h}`:`${J} (not registered)`}}console.log(` ${Y} ${($?`${W.pid}`:`${W.pid}✕`).padEnd(7)} ${R}`)}console.log()}}async function Wz(){let z=I(),B=F(),Q=process.env.COMMHUB_URL||B.hub||z.hub||"http://127.0.0.1:9200",V=process.env.COMMHUB_ALIAS||B.alias;if(!V)console.error("Error: --alias required"),process.exit(1);let{CommHub:X}=await Promise.resolve().then(() => (j(),C)),Z=new X({url:Q,alias:V});Z.on("task",async(U)=>{console.log(`[${V}] ← ${U.from_session}: ${U.content.slice(0,100)}`),await Z.send(U.from_session,`[${V}] 收到: ${U.content.slice(0,200)}`)}),Z.on("connected",()=>console.log(`[${V}] Connected`)),Z.on("disconnected",()=>console.log(`[${V}] Reconnecting...`)),process.on("SIGINT",()=>Z.disconnect().then(()=>process.exit(0))),console.log(`[${V}] Listening on ${Q}`)}switch(A){case"init":if(L[1]==="project")zz();else if(L[1]==="profile")Bz();else s();break;case"start":v();break;case"resume":Qz();break;case"ls":case"list":Vz();break;case"run":Wz();break;case"--help":case"-h":case void 0:P();break;default:if(M(A))L.unshift("start"),v();else console.error(`Unknown: ${A}`),P(),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.15",
|
|
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",
|