@ours.network/mcp 1.2.0-nightly.8 → 1.2.0-nightly.9

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.
Files changed (2) hide show
  1. package/dist/cli.js +1 -1
  2. package/package.json +5 -5
package/dist/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import{readFileSync as kt,realpathSync as V}from"node:fs";import{fileURLToPath as xt}from"node:url";import{randomUUID as z}from"node:crypto";import{chmod as K,mkdir as Q,readFile as Z,rename as tt,unlink as et,writeFile as nt}from"node:fs/promises";import{homedir as it}from"node:os";import{dirname as rt,resolve as u}from"node:path";var C=1,ot="OURS_MCP_CONFIG",R=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,st=()=>({version:1,daemons:{},instances:{}});function m(t=process.env){let e=(t[ot]??"").trim();return u(e||u(it(),".ours-mcp","config.json"))}function b(t,e,n,i){if(!t||typeof t!="object"||Array.isArray(t))throw new Error(`Invalid ours-mcp application identity config at ${e}: "${n}s" must be an object.`);let r={};for(let[o,s]of Object.entries(t)){if(!s||typeof s!="object"||Array.isArray(s))throw new Error(`Invalid ours-mcp application identity config at ${e}: ${n} ${JSON.stringify(o)} must be an object.`);let c=s;if(!Array.isArray(c.identities)||c.identities.some(d=>typeof d!="string"||d.length===0))throw new Error(`Invalid ours-mcp application identity config at ${e}: ${n} ${JSON.stringify(o)} has an invalid identity list.`);r[i(o)]={identities:[...new Set(c.identities)].sort()}}return r}function at(t,e){let n;try{n=JSON.parse(t)}catch(s){throw new Error(`Invalid ours-mcp application identity config at ${e}: ${String(s)}`)}if(!n||typeof n!="object"||Array.isArray(n))throw new Error(`Invalid ours-mcp application identity config at ${e}: expected an object.`);let i=n;if(i.version!==C)throw new Error(`Unsupported ours-mcp application identity config version at ${e}: expected ${C}, found ${String(i.version)}.`);let r=b(i.daemons,e,"daemon",u),o=i.instances===void 0?{}:b(i.instances,e,"instance",s=>{if(!R.test(s))throw new Error(`Invalid ours-mcp application identity config at ${e}: instance ${JSON.stringify(s)} must be a lowercase UUID.`);return s});return{version:1,daemons:r,instances:o}}async function I(t){try{return at(await Z(t,"utf8"),t)}catch(e){if(e.code==="ENOENT")return st();throw e}}async function _(t,e){let n=rt(t);await Q(n,{recursive:!0,mode:448});let i=`${t}.${process.pid}.${z()}.tmp`;try{await nt(i,`${JSON.stringify(e,null,2)}
3
3
  `,{mode:384,flag:"wx"}),await tt(i,t),await K(t,384)}catch(r){try{await et(i)}catch{}throw r}}var f=class{stateDir;instanceId;path;constructor(e,n={}){if(typeof e=="string")this.stateDir=u(e),this.instanceId=null;else{if(!e||!R.test(e.instanceId))throw new Error("Application identity instanceId must be a lowercase UUID.");this.stateDir=null,this.instanceId=e.instanceId}this.path=u(n.path??m(n.env))}rows(e){return this.instanceId===null?e.daemons:e.instances}key(){return this.instanceId??this.stateDir}async list(){let e=await I(this.path);return[...this.rows(e)[this.key()]?.identities??[]]}async has(e){return(await this.list()).includes(e)}async add(e){if(!e)throw new Error("Cannot add an empty identity name to ours-mcp.");let n=await I(this.path),i=this.rows(n),r=this.key(),o=i[r]?.identities??[];o.includes(e)||(i[r]={identities:[...o,e].sort()},await _(this.path,n))}async remove(e){let n=await I(this.path),i=this.rows(n),r=this.key(),o=i[r];if(!o?.identities.includes(e))return;let s=o.identities.filter(c=>c!==e);s.length===0?delete i[r]:i[r]={identities:s},await _(this.path,n)}};async function A(t,e){let n=new Set(await t.list());return e.filter(i=>n.has(i.name))}import{readGatewayClientProfile as ct,validateGatewayClientProfile as dt}from"@ours.network/sdk/client";var E=dt;function lt(t=process.env){let{configPath:e,...n}=ct(t);return{profile:n,configPath:e}}function w(t=process.env){return lt(t).profile}import{createHash as vt,randomUUID as L}from"node:crypto";import{chmod as U,mkdir as It,readFile as Et,rename as St,unlink as Pt,writeFile as Nt}from"node:fs/promises";import{dirname as P,join as Ot,resolve as Ct}from"node:path";import{attachOursClient as bt}from"@ours.network/sdk";import{createHash as pt}from"node:crypto";import{openSync as ut,closeSync as ft,lstatSync as S,mkdirSync as mt,chmodSync as wt,constants as g}from"node:fs";import{join as D}from"node:path";import{createRequire as $}from"node:module";var gt=5e3,p=null,k=!1;function yt(){if(p)return p;if(k)throw new Error("No SQLite implementation available for native session guard");k=!0;try{return p=$(import.meta.url)("node:sqlite").DatabaseSync,p}catch{try{let t=$(import.meta.url)("better-sqlite3");return p=t.default??t,p}catch{throw new Error("Native session guard requires node:sqlite (Node >=22.13) or better-sqlite3")}}}function ht(t){try{let n=ut(t,g.O_RDWR|g.O_CREAT|g.O_EXCL|g.O_NOFOLLOW,384);ft(n)}catch(n){if(n.code!=="EEXIST")throw n}let e=S(t);if(!e.isFile()||e.uid!==process.getuid()||e.mode&63||e.nlink!==1)throw new Error("Native session guard file must be an owner-only regular file")}function x(t){let e=process.getuid(),n=D(`/tmp/ours-${e}`,"session-guards");mt(n,{recursive:!0,mode:448});try{wt(n,448)}catch{}let i=pt("sha256").update(t).digest("hex"),r=D(n,`${i}.guard`);ht(r);let o=S(r),s=yt(),c=new s(r);try{let d=S(r);if(o.dev!==d.dev||o.ino!==d.ino||o.mode!==d.mode||o.uid!==d.uid)throw new Error("Native session guard file changed during acquisition");return c.exec(`PRAGMA busy_timeout=${gt}; BEGIN EXCLUSIVE`),()=>{try{c.close()}catch{}}}catch(d){try{c.close()}catch{}throw d}}var v=1,j=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,l=new Map,y=new Map;function _t(t){if(typeof t!="string"||t.length===0||t.length>4096||t.trim()!==t||t.includes("\0"))throw new Error("Native session metadata is missing or invalid for this host-profile tool call.");return t}function J(t,e,n){if(!t||!t.startsWith("/")||Ct(t)!==t)throw new Error("Native session host record root must be a normalized absolute path.");if(!j.test(e))throw new Error("Native session daemon instance must be a lowercase UUID.");let i=vt("sha256").update(_t(n),"utf8").digest("hex");return Ot(t,"sessions",e,`${i}.json`)}function Rt(t,e){let n;try{n=JSON.parse(t)}catch(o){throw new Error(`Invalid native session record at ${e}: ${String(o)}`)}if(!n||typeof n!="object"||Array.isArray(n))throw new Error(`Invalid native session record at ${e}: expected an object.`);let i=n;if(Object.keys(i).sort().join(",")!=="ownerInstanceId,state,version"||i.version!==v||typeof i.ownerInstanceId!="string"||!j.test(i.ownerInstanceId)||!["active","pending","ended"].includes(String(i.state)))throw new Error(`Invalid native session record at ${e}.`);return i}async function h(t){try{return Rt(await Et(t,"utf8"),t)}catch(e){if(e.code==="ENOENT")return null;throw e}}async function N(t,e){let n=P(t);await It(n,{recursive:!0,mode:448}),await U(n,448);let i=`${t}.${process.pid}.${L()}.tmp`;try{await Nt(i,`${JSON.stringify(e,null,2)}
4
- `,{mode:384,flag:"wx"}),await St(i,t),await U(t,384)}catch(r){try{await Pt(i)}catch{}throw r}}async function F(t,e){let n=y.get(t)??Promise.resolve(),i,r=new Promise(c=>{i=c}),o=n.catch(()=>{}).then(()=>r);y.set(t,o),await n.catch(()=>{});let s;try{return s=x(t),await e()}finally{try{s?.()}finally{i(),y.get(t)===o&&y.delete(t)}}}function H(t,e){return bt({endpoint:t.endpoint,expectedInstanceId:t.expectedInstanceId,credentialPath:t.credentialPath,sessionMode:"external",leaseToken:e,env:{}})}function T(t,e,n){let i=l.get(t);if(i?.ownerInstanceId===n)return i.promise;i&&(l.delete(t),i.promise.then(s=>s.close()).catch(()=>{}));let r=H(e,n),o={ownerInstanceId:n,promise:r};return l.set(t,o),r.catch(()=>{l.get(t)===o&&l.delete(t)}),r}async function At(t,e,n){let i=l.get(t),r=i?.ownerInstanceId===n?await i.promise:await H(e,n);try{await r.releaseLease()}finally{i?.ownerInstanceId!==n&&await r.close()}}async function M(t,e,n){await At(t,e,n);let i=await h(t);i?.state==="pending"&&i.ownerInstanceId===n&&await N(t,{version:v,ownerInstanceId:n,state:"ended"});let r=l.get(t);r?.ownerInstanceId===n&&(l.delete(t),r.promise.then(o=>o.close()).catch(()=>{}))}async function G(t,e,n=process.env){return Dt(t,e,P(m(n)))}async function Dt(t,e,n){let i=E(t),r=J(n,i.expectedInstanceId,e);return F(r,async()=>{let o=await h(r);if(o?.state==="pending"&&(await M(r,i,o.ownerInstanceId),o=await h(r)),o?.state==="active")return T(r,i,o.ownerInstanceId);let s=L();return await N(r,{version:v,ownerInstanceId:s,state:"active"}),T(r,i,s)})}async function q(t,e,n=process.env){return $t(t,e,P(m(n)))}async function $t(t,e,n){let i=E(t),r=J(n,i.expectedInstanceId,e);await F(r,async()=>{let o=await h(r);o===null||o.state==="ended"||(o.state==="active"&&(o={version:v,ownerInstanceId:o.ownerInstanceId,state:"pending"},await N(r,o)),await M(r,i,o.ownerInstanceId))})}var O="1.2.0-nightly.8",a=t=>{process.stdout.write(`${t}
4
+ `,{mode:384,flag:"wx"}),await St(i,t),await U(t,384)}catch(r){try{await Pt(i)}catch{}throw r}}async function F(t,e){let n=y.get(t)??Promise.resolve(),i,r=new Promise(c=>{i=c}),o=n.catch(()=>{}).then(()=>r);y.set(t,o),await n.catch(()=>{});let s;try{return s=x(t),await e()}finally{try{s?.()}finally{i(),y.get(t)===o&&y.delete(t)}}}function H(t,e){return bt({endpoint:t.endpoint,expectedInstanceId:t.expectedInstanceId,credentialPath:t.credentialPath,sessionMode:"external",leaseToken:e,env:{}})}function T(t,e,n){let i=l.get(t);if(i?.ownerInstanceId===n)return i.promise;i&&(l.delete(t),i.promise.then(s=>s.close()).catch(()=>{}));let r=H(e,n),o={ownerInstanceId:n,promise:r};return l.set(t,o),r.catch(()=>{l.get(t)===o&&l.delete(t)}),r}async function At(t,e,n){let i=l.get(t),r=i?.ownerInstanceId===n?await i.promise:await H(e,n);try{await r.releaseLease()}finally{i?.ownerInstanceId!==n&&await r.close()}}async function M(t,e,n){await At(t,e,n);let i=await h(t);i?.state==="pending"&&i.ownerInstanceId===n&&await N(t,{version:v,ownerInstanceId:n,state:"ended"});let r=l.get(t);r?.ownerInstanceId===n&&(l.delete(t),r.promise.then(o=>o.close()).catch(()=>{}))}async function G(t,e,n=process.env){return Dt(t,e,P(m(n)))}async function Dt(t,e,n){let i=E(t),r=J(n,i.expectedInstanceId,e);return F(r,async()=>{let o=await h(r);if(o?.state==="pending"&&(await M(r,i,o.ownerInstanceId),o=await h(r)),o?.state==="active")return T(r,i,o.ownerInstanceId);let s=L();return await N(r,{version:v,ownerInstanceId:s,state:"active"}),T(r,i,s)})}async function q(t,e,n=process.env){return $t(t,e,P(m(n)))}async function $t(t,e,n){let i=E(t),r=J(n,i.expectedInstanceId,e);await F(r,async()=>{let o=await h(r);o===null||o.state==="ended"||(o.state==="active"&&(o={version:v,ownerInstanceId:o.ownerInstanceId,state:"pending"},await N(r,o)),await M(r,i,o.ownerInstanceId))})}var O="1.2.0-nightly.9",a=t=>{process.stdout.write(`${t}
5
5
  `)},X=t=>{process.stderr.write(`${t}
6
6
  `)},W=t=>Number.isInteger(t)&&t>1,B=Number(process.env.OURS_CLIENT_PID),Y=W(B)?B:W(process.ppid)?process.ppid:process.pid,Ut=(process.env.CLAUDE_CODE_SESSION_ID??"").trim()||`ours-mcp:${Y}`,Tt=(process.env.OURS_BIND_IDENTITY??"").trim()||void 0,Lt=new Set(["start","stop","restart","serve","run","status","install-service","uninstall-service"]);function jt(t){if(t.some(e=>e==="--application"||e.startsWith("--application=")))throw new Error("`--application` is no longer supported. ours-mcp connects to one coherently selected shared daemon; configure ~/.ours-client/profile.json with the gateway URL.")}async function Jt(){let t=new URL("./connector.js",import.meta.url),{runConnector:e}=await import(t.href);await e({leaseToken:Ut,clientPid:Y,version:O,bindIdentity:Tt})}async function Ft(){let t=w(process.env),e;try{e=JSON.parse(kt(0,"utf8"))}catch{throw new Error("SessionEnd requires valid hook JSON on stdin.")}let n=e?.session_id;if(typeof n!="string"||!n.trim())throw new Error("SessionEnd hook input must contain a non-empty session_id.");await q(t,n,process.env)}function Ht(t,e){return JSON.stringify({identity:t,...e})}async function Mt(t,e,n){for await(let i of t.watchNotifications(e,{kinds:["inbound"],signal:n}))a(Ht(e,i))}async function Gt(t){if(t.length>1||t[0]?.startsWith("-"))throw new Error("Usage: ours-mcp watch [identity]");let e=w(process.env),n=new f({instanceId:e.expectedInstanceId});await n.list();let i=await G(e,(process.env.CLAUDE_CODE_SESSION_ID??"").trim()),r=t[0]?.trim(),o;r?o=[r]:o=(await A(n,await i.identities())).map(c=>c.name);let s=new AbortController;process.once("SIGINT",()=>s.abort()),process.once("SIGTERM",()=>s.abort()),X(`ours-mcp watch: ${o.length===0?"no application identities":`watching ${o.join(", ")}`}`);try{await Promise.all(o.map(c=>Mt(i,c,s.signal)))}finally{await i.close()}}function qt(){a(`ours-mcp ${O} \u2014 MCP adapter for the shared ours daemon`),a(""),a("Usage: ours-mcp <command> [options]"),a(" verify-client-profile validate the shared gateway profile (no network access)"),a(" proxy run the stdio MCP server (never starts a daemon)"),a(" session-end release this harness session and clean up its temporary identities"),a(" watch [identity] stream inbound JSON Lines; without a name, only ours-mcp identities"),a(" start|stop|restart|serve|status"),a(" install-service|uninstall-service"),a(" compatibility aliases for `ours-daemon <command>`"),a(" version print the ours-mcp package version"),a(""),a("Daemon administration uses @ours.network/daemon; API commands use @ours.network/cli:"),a(" ours-daemon config setup"),a(" ours identity --help")}async function Vt(){let t=process.argv.slice(2);jt(t);let e=t.shift()??"help";if(Lt.has(e))throw new Error("Server lifecycle commands are not client operations. Manage the server with ours-install server; configure clients with ours-install client.");switch(e){case"verify-client-profile":if(t.length)throw new Error("Usage: ours-mcp verify-client-profile");w(process.env),a("ours.gateway-client-profile-v1");return;case"proxy":if(t.length)throw new Error("Usage: ours-mcp proxy");await Jt();return;case"session-end":if(t.length)throw new Error("Usage: ours-mcp session-end");await Ft();return;case"watch":await Gt(t);return;case"setup":throw new Error("ours-mcp no longer owns daemon configuration. Run `ours-daemon config setup` instead.");case"create-root":case"define-local-identity-file":case"voice-setup":case"voice-status":case"stt-setup":case"stt-status":throw new Error(`ours-mcp ${e} moved to the \`ours\` CLI. Run \`ours --help\` for the typed replacement.`);case"version":case"--version":case"-v":a(O);return;case"help":case"--help":case"-h":qt();return;default:throw new Error(`Unknown command ${JSON.stringify(e)}. Run \`ours-mcp --help\`.`)}}function Wt(){if(!process.argv[1])return!1;try{return V(process.argv[1])===V(xt(import.meta.url))}catch{return!1}}var Bt=Wt();Bt&&Vt().catch(t=>{X(`ours-mcp error: ${t instanceof Error?t.message:String(t)}`),process.exitCode=1});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ours.network/mcp",
3
- "version": "1.2.0-nightly.8",
3
+ "version": "1.2.0-nightly.9",
4
4
  "description": "MCP adapter for the shared ours daemon, with application-local identity bookkeeping and secure agent-to-agent messaging tools over stdio.",
5
5
  "type": "module",
6
6
  "license": "FSL-1.1-Apache-2.0",
@@ -54,11 +54,11 @@
54
54
  "dev": "tsx src/cli.ts proxy",
55
55
  "prepublishOnly": "node build.mjs",
56
56
  "typecheck": "tsc -p tsconfig.json --noEmit",
57
- "test": "node --test test/managed-server.test.mjs && node test/application-identities.test.mjs && node test/local-files.test.mjs && node test/cli-delegation.test.mjs && node test/inbox-push.test.mjs && node test/contact-lines.test.mjs && node test/proxy-exit-on-stdin-eof.test.mjs && node test/proxy-dead-stderr.test.mjs && node test/host-profile.test.mjs && node test/container.test.mjs && node test/native-profile-session.test.mjs",
57
+ "test": "node --test test/managed-server.test.mjs && node test/application-identities.test.mjs && node test/local-files.test.mjs && node test/cli-delegation.test.mjs && node test/inbox-push.test.mjs && node test/contact-lines.test.mjs && node test/proxy-exit-on-stdin-eof.test.mjs && node test/proxy-dead-stderr.test.mjs && node test/host-profile.test.mjs && node test/container.test.mjs && node test/native-profile-session.test.mjs && node test/external-profile-stdio-refresh.test.mjs",
58
58
  "test:external-profile": "node test/native-profile-session.test.mjs && node test/external-profile-stdio-refresh.test.mjs"
59
59
  },
60
60
  "dependencies": {
61
- "@ours.network/sdk": "3.8.1-nightly.13",
61
+ "@ours.network/sdk": "3.8.1-nightly.14",
62
62
  "@modelcontextprotocol/sdk": "^1.0.4",
63
63
  "zod": "^3.23.8"
64
64
  },
@@ -67,7 +67,7 @@
67
67
  "esbuild": "^0.24.2",
68
68
  "tsx": "^4.19.0",
69
69
  "typescript": "^5.5.4",
70
- "@ours.network/cli": "2.8.1-nightly.11",
71
- "@ours.network/daemon": "3.8.1-nightly.5"
70
+ "@ours.network/cli": "2.8.1-nightly.12",
71
+ "@ours.network/daemon": "3.8.1-nightly.6"
72
72
  }
73
73
  }