toolnet-memory 0.3.10 → 0.3.12

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/bundle/grok.js CHANGED
@@ -1,6 +1,4 @@
1
- import{homedir as yo}from"node:os";import{join as _}from"node:path";function V(o={}){return o.cursorHome??_(o.home??yo(),".cursor")}function I(o={}){return _(V(o),"mcp.json")}function E(o={}){return _(V(o),"hooks.json")}import{existsSync as Co,mkdirSync as bo,readFileSync as Oo,renameSync as wo,rmSync as Fo,writeFileSync as So}from"node:fs";import{dirname as vo}from"node:path";function f(o){return typeof o=="object"&&o!==null&&!Array.isArray(o)}function d(o,r){if(!Co(o))return{};let n=Oo(o,"utf8").trim();if(!n)return{};let t;try{t=JSON.parse(n)}catch(e){throw new Error(`Invalid existing ${r} hooks file: ${e instanceof Error?e.message:String(e)}`)}if(!f(t))throw new Error(`Invalid existing ${r} hooks file: root must be a JSON object.`);return t}function C(o,r){bo(vo(o),{recursive:!0,mode:448});let n=`${o}.toolnet-${process.pid}-${Date.now()}.tmp`;try{So(n,`${JSON.stringify(r,null,2)}
2
- `,{encoding:"utf8",mode:384}),wo(n,o)}finally{Fo(n,{force:!0})}}function R(o){return/^[A-Za-z0-9_./:-]+$/u.test(o)?o:`'${o.replace(/'/gu,"'\\''")}'`}var F=[["sessionStart",10],["beforeSubmitPrompt",10],["preToolUse",10],["postToolUse",15],["afterAgentResponse",15],["stop",30]];function K(o){return f(o)&&typeof o.command=="string"&&o.command.includes("session:cursor-hook")}function xo(o,r,n){let e={type:"command",command:`TOOLNET_HOOK_EVENT=${R(o)} ${R(r)} session:cursor-hook`,timeout:n};return o==="preToolUse"&&(e.matcher=".*"),e}function q(o={}){let r=o.hooksFile??E(),n=o.binary??process.env.TOOLNET_MEMORY_BIN??"toolnet-memory",t=d(r,"Cursor");if(t.version!==void 0&&t.version!==1)throw new Error(`Unsupported existing Cursor hooks version: ${String(t.version)}`);let e=t.hooks;if(e!==void 0&&!f(e))throw new Error("Invalid existing Cursor hooks file: hooks must be an object.");let s=f(e)?{...e}:{};for(let[l,c]of F){let a=s[l];if(a!==void 0&&!Array.isArray(a))throw new Error(`Invalid existing Cursor hooks file: hooks.${l} must be an array.`);let m=Array.isArray(a)?a.filter(p=>!K(p)):[];s[l]=[...m,xo(l,n,c)]}let i={...t,version:1,hooks:s};if(JSON.stringify(t)===JSON.stringify(i))return{hooksFile:r,changed:!1,hookCount:F.length};C(r,i);let g=d(r,"Cursor");if(g.version!==1||!f(g.hooks))throw new Error("Cursor hooks were written but verification failed.");let u=0;for(let[l]of F){let c=g.hooks[l];if(!Array.isArray(c))throw new Error("Cursor hooks were written but verification failed.");u+=c.filter(K).length}if(u!==F.length)throw new Error("Cursor hooks were written but verification failed.");return{hooksFile:r,changed:!0,hookCount:F.length}}import{existsSync as Io,mkdirSync as Eo,readFileSync as Ho,renameSync as No,rmSync as jo,writeFileSync as To}from"node:fs";import{dirname as $o}from"node:path";function k(o){return typeof o=="object"&&o!==null&&!Array.isArray(o)}function b(o,r){if(!Io(o))return{};let n=Ho(o,"utf8").trim();if(!n)return{};let t;try{t=JSON.parse(n)}catch(e){throw new Error(`Invalid existing ${r} MCP config: ${e instanceof Error?e.message:String(e)}`)}if(!k(t))throw new Error(`Invalid existing ${r} MCP config: root must be a JSON object.`);return t}function H(o,r){Eo($o(o),{recursive:!0,mode:448});let n=`${o}.tmp-${process.pid}-${Date.now()}`;try{To(n,`${JSON.stringify(r,null,2)}
3
- `,{encoding:"utf8",mode:384}),No(n,o)}finally{jo(n,{force:!0})}}function z(o,r){return k(o)?(o.type===void 0||o.type==="stdio")&&o.command===r&&Array.isArray(o.args)&&o.args.length===1&&o.args[0]==="mcp":!1}function Q(o={}){let r=o.configFile??I(),n=o.binary??process.env.TOOLNET_MEMORY_BIN??"toolnet-memory",t=o.serverName??"toolnet-memory",e=b(r,"Cursor"),s=e.mcpServers;if(s!==void 0&&!k(s))throw new Error("Invalid existing Cursor MCP config: mcpServers must be an object.");let i=k(s)?{...s}:{};if(z(i[t],n))return{installed:!0,changed:!1,configFile:r,serverName:t,command:n,args:["mcp"]};i[t]={type:"stdio",command:n,args:["mcp"]},H(r,{...e,mcpServers:i});let u=b(r,"Cursor").mcpServers;if(!k(u)||!z(u[t],n))throw new Error("Cursor MCP configuration was written but verification failed.");return{installed:!0,changed:!0,configFile:r,serverName:t,command:n,args:["mcp"]}}function X(o={}){let r=o.binary??process.env.TOOLNET_MEMORY_BIN??"toolnet-memory",n=Q({binary:r,configFile:o.configFile}),t=q({binary:r,hooksFile:o.hooksFile});return{installed:n.installed,changed:n.changed||t.changed,mcp:n,hooks:t,files:[n.configFile,t.hooksFile]}}import{homedir as Jo}from"node:os";import{join as N}from"node:path";function Z(o={}){return o.copilotHome??process.env.COPILOT_HOME??N(o.home??Jo(),".copilot")}function j(o={}){return N(Z(o),"mcp-config.json")}function Mo(o={}){return N(Z(o),"hooks")}function T(o={}){return N(Mo(o),"toolnet-memory.json")}var S=[["sessionStart",10],["userPromptSubmitted",10],["userPromptTransformed",10],["preToolUse",10],["postToolUse",15],["agentStop",30]];function Go(o){if(typeof o.command=="string")return o.command;if(typeof o.bash=="string")return o.bash}function oo(o){return f(o)&&Go(o)?.includes("session:copilot-hook")===!0}function Ao(o,r,n){let t={type:"command",command:`${r} session:copilot-hook`,env:{TOOLNET_HOOK_EVENT:o},timeoutSec:n};return o==="preToolUse"&&(t.matcher=".*"),t}function ro(o={}){let r=o.hooksFile??T(),n=o.binary??process.env.TOOLNET_MEMORY_BIN??"toolnet-memory",t=d(r,"GitHub Copilot CLI");if(t.version!==void 0&&t.version!==1)throw new Error(`Unsupported existing GitHub Copilot CLI hooks version: ${String(t.version)}`);let e=t.hooks;if(e!==void 0&&!f(e))throw new Error("Invalid existing GitHub Copilot CLI hooks file: hooks must be an object.");let s=f(e)?{...e}:{};for(let[l,c]of S){let a=s[l];if(a!==void 0&&!Array.isArray(a))throw new Error(`Invalid existing GitHub Copilot CLI hooks file: hooks.${l} must be an array.`);let m=Array.isArray(a)?a.filter(p=>!oo(p)):[];s[l]=[...m,Ao(l,n,c)]}let i={...t,version:1,hooks:s};if(JSON.stringify(t)===JSON.stringify(i))return{hooksFile:r,changed:!1,hookCount:S.length};C(r,i);let g=d(r,"GitHub Copilot CLI");if(g.version!==1||!f(g.hooks))throw new Error("GitHub Copilot CLI hooks were written but verification failed.");let u=0;for(let[l]of S){let c=g.hooks[l];if(!Array.isArray(c))throw new Error("GitHub Copilot CLI hooks were written but verification failed.");u+=c.filter(oo).length}if(u!==S.length)throw new Error("GitHub Copilot CLI hooks were written but verification failed.");return{hooksFile:r,changed:!0,hookCount:S.length}}function no(o,r){return k(o)?(o.type===void 0||o.type==="local"||o.type==="stdio")&&o.command===r&&Array.isArray(o.args)&&o.args.length===1&&o.args[0]==="mcp"&&Array.isArray(o.tools)&&o.tools.length===1&&o.tools[0]==="*":!1}function to(o={}){let r=o.configFile??j(),n=o.binary??process.env.TOOLNET_MEMORY_BIN??"toolnet-memory",t=o.serverName??"toolnet-memory",e=b(r,"GitHub Copilot CLI"),s=e.mcpServers;if(s!==void 0&&!k(s))throw new Error("Invalid existing GitHub Copilot CLI MCP config: mcpServers must be an object.");let i=k(s)?{...s}:{};if(no(i[t],n))return{installed:!0,changed:!1,configFile:r,serverName:t,command:n,args:["mcp"]};i[t]={type:"stdio",command:n,args:["mcp"],tools:["*"]},H(r,{...e,mcpServers:i});let u=b(r,"GitHub Copilot CLI").mcpServers;if(!k(u)||!no(u[t],n))throw new Error("GitHub Copilot CLI MCP configuration was written but verification failed.");return{installed:!0,changed:!0,configFile:r,serverName:t,command:n,args:["mcp"]}}function eo(o={}){let r=o.binary??process.env.TOOLNET_MEMORY_BIN??"toolnet-memory",n=to({binary:r,configFile:o.configFile}),t=ro({binary:r,hooksFile:o.hooksFile});return{installed:n.installed,changed:n.changed||t.changed,mcp:n,hooks:t,files:[n.configFile,t.hooksFile]}}import{existsSync as Do,mkdirSync as Uo,readFileSync as io,renameSync as Bo,rmSync as Wo,writeFileSync as Yo}from"node:fs";import{dirname as Vo}from"node:path";import{homedir as Po}from"node:os";import{join as y}from"node:path";function L(o={}){return o.grokHome??process.env.GROK_HOME??y(o.home??Po(),".grok")}function $(o={}){return y(L(o),"config.toml")}function _o(o={}){return y(L(o),"hooks")}function J(o={}){return y(_o(o),"toolnet-memory.json")}function Ro(o={}){return y(L(o),"skills")}function Lo(o={}){return y(Ro(o),"toolnet-continuity")}function M(o={}){return y(Lo(o),"SKILL.md")}var D=`---
1
+ import{homedir as bo}from"node:os";import{join as f,resolve as jo}from"node:path";function T(o={}){return o.grokHome??process.env.GROK_HOME??f(o.home??bo(),".grok")}function m(o={}){return f(T(o),"config.toml")}function So(o={}){return f(T(o),"hooks")}function h(o={}){return f(So(o),"toolnet-memory.json")}function vo(o={}){return f(T(o),"skills")}function Fo(o={}){return f(vo(o),"toolnet-continuity")}function y(o={}){return f(Fo(o),"SKILL.md")}function M(o){return f(jo(o),".grok")}function P(o){return f(M(o),"config.toml")}function Io(o){return f(M(o),"hooks")}function x(o){return f(Io(o),"toolnet-memory.json")}function wo(o){return f(M(o),"skills")}function Co(o){return f(wo(o),"toolnet-continuity")}function O(o){return f(Co(o),"SKILL.md")}import{existsSync as Po,mkdirSync as xo,readFileSync as Y,renameSync as Oo,rmSync as Ro,writeFileSync as Go}from"node:fs";import{dirname as Ho}from"node:path";var N=`---
4
2
  name: toolnet-continuity
5
3
  description: Restore previous ToolNet project work when the user asks to continue, resume, pick up, finish unfinished work, or asks where work stopped.
6
4
  when-to-use: continue, resume, pick up, carry on, ti\u1EBFp t\u1EE5c, l\xE0m ti\u1EBFp, l\xE0m n\u1ED1t, \u0111ang l\xE0m \u0111\u1EBFn \u0111\xE2u, d\u1EEBng \u1EDF \u0111\xE2u
@@ -26,8 +24,9 @@ When the user asks to continue or resume previous work:
26
24
  7. Do not ask the user to repeat context ToolNet already provides.
27
25
 
28
26
  Current repository evidence overrides stale memory.
29
- `;function Ko(o,r){Uo(Vo(o),{recursive:!0,mode:448});let n=`${o}.toolnet-${process.pid}-${Date.now()}.tmp`;try{Yo(n,r,{encoding:"utf8",mode:384}),Bo(n,o)}finally{Wo(n,{force:!0})}}function so(o={}){let r=o.skillFile??M();if(Do(r)&&io(r,"utf8")===D)return{skillFile:r,changed:!1};if(Ko(r,D),io(r,"utf8")!==D)throw new Error("Grok ToolNet continuity skill was written but verification failed.");return{skillFile:r,changed:!0}}var v=[["SessionStart",10],["UserPromptSubmit",10],["PreToolUse",10],["PostToolUse",15],["Stop",30]];function co(o){return!f(o)||!Array.isArray(o.hooks)?!1:o.hooks.some(r=>f(r)&&typeof r.command=="string"&&r.command.includes("session:grok-hook"))}function qo(o,r,n){let t={hooks:[{type:"command",command:`${r} session:grok-hook`,timeout:n,env:{TOOLNET_HOOK_EVENT:o}}]};return o==="PreToolUse"&&(t.matcher=".*"),t}function lo(o={}){let r=o.hooksFile??J(),n=o.binary??process.env.TOOLNET_MEMORY_BIN??"toolnet-memory",t=d(r,"Grok Build"),e=t.hooks;if(e!==void 0&&!f(e))throw new Error("Invalid existing Grok Build hooks file: hooks must be an object.");let s=f(e)?{...e}:{};for(let[l,c]of v){let a=s[l];if(a!==void 0&&!Array.isArray(a))throw new Error(`Invalid existing Grok Build hooks file: hooks.${l} must be an array.`);let m=Array.isArray(a)?a.filter(p=>!co(p)):[];s[l]=[...m,qo(l,n,c)]}let i={...t,hooks:s};if(JSON.stringify(t)===JSON.stringify(i))return{hooksFile:r,changed:!1,hookCount:v.length};C(r,i);let g=d(r,"Grok Build");if(!f(g.hooks))throw new Error("Grok Build hooks were written but verification failed.");let u=0;for(let[l]of v){let c=g.hooks[l];if(!Array.isArray(c))throw new Error("Grok Build hooks were written but verification failed.");u+=c.filter(co).length}if(u!==v.length)throw new Error("Grok Build hooks were written but verification failed.");return{hooksFile:r,changed:!0,hookCount:v.length}}import{existsSync as zo,mkdirSync as Qo,readFileSync as Xo,renameSync as Zo,rmSync as or,writeFileSync as rr}from"node:fs";import{dirname as nr}from"node:path";function ao(o){return zo(o)?Xo(o,"utf8"):""}function tr(o,r){Qo(nr(o),{recursive:!0,mode:448});let n=`${o}.tmp-${process.pid}-${Date.now()}`;try{rr(n,r,{encoding:"utf8",mode:384}),Zo(n,o)}finally{or(n,{force:!0})}}function U(o){return o.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}function er(o){return`[mcp_servers."${U(o)}"]`}function ir(o,r){return[er(o),`command = "${U(r)}"`,'args = ["mcp"]',"enabled = true"].join(`
30
- `)}function sr(o){let r=o.trim();return r.startsWith("[")&&r.includes("]")}function G(o){return o.trim().replace(/\s+/g,"")}function cr(o){return new Set([G(`[mcp_servers.${o}]`),G(`[mcp_servers."${o}"]`),G(`[mcp_servers.'${o}']`)])}function uo(o,r){let n=o.split(/\r?\n/),t=cr(r),e=-1;for(let c=0;c<n.length;c+=1){let a=G(n[c].replace(/\s+#.*$/,""));if(t.has(a)){e=c;break}}if(e<0)return null;let s=n.length;for(let c=e+1;c<n.length;c+=1)if(sr(n[c])){s=c;break}let i=[],g=0;for(let c of n)i.push(g),g+=c.length+1;let u=i[e]??0,l=s>=n.length?o.length:i[s]??o.length;return{start:u,end:l}}function lr(o,r,n){let t=`${ir(r,n)}
31
- `,e=uo(o,r);if(e){let s=o.slice(0,e.start),i=o.slice(e.end);return`${s}${t}${i.replace(/^\n+/,"")}`}return o.trim()?`${o.replace(/\s*$/,"")}
27
+ `;function Ao(o,e){xo(Ho(o),{recursive:!0,mode:448});let t=`${o}.toolnet-${process.pid}-${Date.now()}.tmp`;try{Go(t,e,{encoding:"utf8",mode:384}),Oo(t,o)}finally{Ro(t,{force:!0})}}function D(o={}){let e=o.skillFile??y();if(Po(e)&&Y(e,"utf8")===N)return{skillFile:e,changed:!1};if(Ao(e,N),Y(e,"utf8")!==N)throw new Error("Grok ToolNet continuity skill was written but verification failed.");return{skillFile:e,changed:!0}}import{existsSync as Eo,mkdirSync as $o,readFileSync as To,renameSync as Mo,rmSync as No,writeFileSync as Do}from"node:fs";import{dirname as _o}from"node:path";function j(o){return typeof o=="object"&&o!==null&&!Array.isArray(o)}function _(o,e){if(!Eo(o))return{};let t=To(o,"utf8").trim();if(!t)return{};let r;try{r=JSON.parse(t)}catch(n){throw new Error(`Invalid existing ${e} hooks file: ${n instanceof Error?n.message:String(n)}`)}if(!j(r))throw new Error(`Invalid existing ${e} hooks file: root must be a JSON object.`);return r}function Q(o,e){$o(_o(o),{recursive:!0,mode:448});let t=`${o}.toolnet-${process.pid}-${Date.now()}.tmp`;try{Do(t,`${JSON.stringify(e,null,2)}
28
+ `,{encoding:"utf8",mode:384}),Mo(t,o)}finally{No(t,{force:!0})}}var w=[["SessionStart",10],["UserPromptSubmit",10],["PreToolUse",10],["PostToolUse",15],["Stop",30]];function Z(o){return!j(o)||!Array.isArray(o.hooks)?!1:o.hooks.some(e=>j(e)&&typeof e.command=="string"&&e.command.includes("session:grok-hook"))}function Jo(o,e,t){let r={hooks:[{type:"command",command:`${e} session:grok-hook`,timeout:t,env:{TOOLNET_HOOK_EVENT:o}}]};return o==="PreToolUse"&&(r.matcher=".*"),r}function J(o={}){let e=o.hooksFile??h(),t=o.binary??process.env.TOOLNET_MEMORY_BIN??"toolnet-memory",r=_(e,"Grok Build"),n=r.hooks;if(n!==void 0&&!j(n))throw new Error("Invalid existing Grok Build hooks file: hooks must be an object.");let i=j(n)?{...n}:{};for(let[l,c]of w){let g=i[l];if(g!==void 0&&!Array.isArray(g))throw new Error(`Invalid existing Grok Build hooks file: hooks.${l} must be an array.`);let p=Array.isArray(g)?g.filter(d=>!Z(d)):[];i[l]=[...p,Jo(l,t,c)]}let s={...r,hooks:i};if(JSON.stringify(r)===JSON.stringify(s))return{hooksFile:e,changed:!1,hookCount:w.length};Q(e,s);let a=_(e,"Grok Build");if(!j(a.hooks))throw new Error("Grok Build hooks were written but verification failed.");let u=0;for(let[l]of w){let c=a.hooks[l];if(!Array.isArray(c))throw new Error("Grok Build hooks were written but verification failed.");u+=c.filter(Z).length}if(u!==w.length)throw new Error("Grok Build hooks were written but verification failed.");return{hooksFile:e,changed:!0,hookCount:w.length}}import{existsSync as qo,mkdirSync as Bo,readFileSync as Uo,renameSync as Lo,rmSync as Ko,writeFileSync as Wo}from"node:fs";import{dirname as zo}from"node:path";function oo(o){return qo(o)?Uo(o,"utf8"):""}function Vo(o,e){Bo(zo(o),{recursive:!0,mode:448});let t=`${o}.tmp-${process.pid}-${Date.now()}`;try{Wo(t,e,{encoding:"utf8",mode:384}),Lo(t,o)}finally{Ko(t,{force:!0})}}function q(o){return o.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}function Xo(o){return`[mcp_servers."${q(o)}"]`}function Yo(o,e){return[Xo(o),`command = "${q(e)}"`,'args = ["mcp"]',"enabled = true"].join(`
29
+ `)}function Qo(o){let e=o.trim();return e.startsWith("[")&&e.includes("]")}function R(o){return o.trim().replace(/\s+/g,"")}function Zo(o){return new Set([R(`[mcp_servers.${o}]`),R(`[mcp_servers."${o}"]`),R(`[mcp_servers.'${o}']`)])}function to(o,e){let t=o.split(/\r?\n/),r=Zo(e),n=-1;for(let c=0;c<t.length;c+=1){let g=R(t[c].replace(/\s+#.*$/,""));if(r.has(g)){n=c;break}}if(n<0)return null;let i=t.length;for(let c=n+1;c<t.length;c+=1)if(Qo(t[c])){i=c;break}let s=[],a=0;for(let c of t)s.push(a),a+=c.length+1;let u=s[n]??0,l=i>=t.length?o.length:s[i]??o.length;return{start:u,end:l}}function oe(o,e,t){let r=`${Yo(e,t)}
30
+ `,n=to(o,e);if(n){let i=o.slice(0,n.start),s=o.slice(n.end);return`${i}${r}${s.replace(/^\n+/,"")}`}return o.trim()?`${o.replace(/\s*$/,"")}
32
31
 
33
- ${t}`:t}function go(o,r,n){let t=uo(o,r);if(!t)return!1;let e=o.slice(t.start,t.end);return e.includes(`command = "${U(n)}"`)&&/args\s*=\s*\[\s*"mcp"\s*\]/.test(e)&&/enabled\s*=\s*true/.test(e)}function fo(o={}){let r=o.configFile??$(),n=o.binary??process.env.TOOLNET_MEMORY_BIN??"toolnet-memory",t=o.serverName??"toolnet-memory",e=ao(r);if(go(e,t,n))return{installed:!0,changed:!1,configFile:r,serverName:t,command:n,args:["mcp"]};let s=lr(e,t,n);tr(r,s);let i=ao(r);if(!go(i,t,n))throw new Error("Grok Build MCP configuration was written but verification failed.");return{installed:!0,changed:!0,configFile:r,serverName:t,command:n,args:["mcp"]}}function mo(o={}){let r=o.binary??process.env.TOOLNET_MEMORY_BIN??"toolnet-memory",n=fo({binary:r,configFile:o.configFile}),t=lo({binary:r,hooksFile:o.hooksFile}),e=so({skillFile:o.skillFile});return{installed:n.installed,changed:n.changed||t.changed||e.changed,mcp:n,hooks:t,skill:e,files:[n.configFile,t.hooksFile,e.skillFile]}}import{existsSync as O,readFileSync as W}from"node:fs";function h(o){return typeof o=="object"&&o!==null&&!Array.isArray(o)}function x(o){if(!O(o))return{};try{let r=JSON.parse(W(o,"utf8"));return h(r)?{value:r}:{error:"root must be a JSON object"}}catch(r){return{error:r instanceof Error?r.message:String(r)}}}function po(o,r){if(!o||!h(o.mcpServers))return!1;let n=o.mcpServers["toolnet-memory"];return!h(n)||typeof n.command!="string"||!n.command.trim()||!Array.isArray(n.args)||n.args.length!==1||n.args[0]!=="mcp"?!1:!r||Array.isArray(n.tools)&&n.tools.includes("*")}function ko(o,r,n){if(!o||!h(o.hooks))return[];let t=o.hooks;return r.filter(e=>{let s=t[e];return Array.isArray(s)&&s.some(i=>h(i)&&(typeof i.command=="string"&&i.command.includes(n)||typeof i.bash=="string"&&i.bash.includes(n)))})}function ar(o,r){if(!o||!h(o.hooks))return[];let n=o.hooks;return r.filter(t=>{let e=n[t];return Array.isArray(e)&&e.some(s=>!h(s)||!Array.isArray(s.hooks)?!1:s.hooks.some(i=>h(i)&&typeof i.command=="string"&&i.command.includes("session:grok-hook")))})}function gr(o){if(!O(o))return!1;let r=W(o,"utf8"),n=/\[mcp_servers\.(?:"toolnet-memory"|'toolnet-memory'|toolnet-memory)\]/,t=r.search(n);if(t<0)return!1;let e=r.slice(t),s=e.slice(1).search(/\n\s*\[[^\]]+\]/),i=s>=0?e.slice(0,s+1):e;return/command\s*=\s*"[^"]+"/.test(i)&&/args\s*=\s*\[\s*"mcp"\s*\]/.test(i)&&!/enabled\s*=\s*false/.test(i)}function B(o){let r=[];o.mcpError&&r.push(`MCP config: ${o.mcpError}`),o.hookError&&r.push(`Hooks config: ${o.hookError}`);let n=o.mcpConfigured&&o.hooksConfigured&&(o.skill?.configured??!0),t=O(o.configFile)||O(o.hooksFile)||(o.skill?O(o.skill.skillFile):!1),e=r.length>0?"invalid":n?"ready":t?"partial":"not-installed";return{installed:n,state:e,mcp:{configured:o.mcpConfigured,configFile:o.configFile,error:o.mcpError},hooks:{configured:o.hooksConfigured,hooksFile:o.hooksFile,events:o.events,error:o.hookError},skill:o.skill,errors:r}}function Y(o,r={}){if(o==="cursor"){let l=["sessionStart","beforeSubmitPrompt","preToolUse","postToolUse","afterAgentResponse","stop"],c=r.configFile??I(),a=r.hooksFile??E(),m=x(c),p=x(a),w=p.error?[]:ko(p.value,l,"session:cursor-hook");return B({mcpConfigured:!m.error&&po(m.value,!1),configFile:c,mcpError:m.error,hooksConfigured:l.every(P=>w.includes(P)),hooksFile:a,events:w,hookError:p.error})}if(o==="copilot"){let l=["sessionStart","userPromptSubmitted","userPromptTransformed","preToolUse","postToolUse","agentStop"],c=r.configFile??j(),a=r.hooksFile??T(),m=x(c),p=x(a),w=p.error?[]:ko(p.value,l,"session:copilot-hook");return B({mcpConfigured:!m.error&&po(m.value,!0),configFile:c,mcpError:m.error,hooksConfigured:l.every(P=>w.includes(P)),hooksFile:a,events:w,hookError:p.error})}let n=["SessionStart","UserPromptSubmit","PreToolUse","PostToolUse","Stop"],t=r.configFile??$(),e=r.hooksFile??J(),s=r.skillFile??M(),i=x(e),g=i.error?[]:ar(i.value,n),u=O(s)&&W(s,"utf8").includes("memory_agent_ask");return B({mcpConfigured:gr(t),configFile:t,hooksConfigured:n.every(l=>g.includes(l)),hooksFile:e,events:g,hookError:i.error,skill:{configured:u,skillFile:s}})}var A={cursor:"Cursor CLI",copilot:"GitHub Copilot CLI",grok:"Grok Build"};function ho(o){let r=process.argv.slice(2),n=r.includes("--json");if(r.includes("--status")||r[0]==="status"){let i=Y(o);if(n)console.log(JSON.stringify(i,null,2));else{console.log(`${A[o]} Integration`),console.log("=".repeat(`${A[o]} Integration`.length)),console.log(""),console.log(`State : ${i.state}`),console.log(`MCP : ${i.mcp.configured?"ready":"missing"} \u2014 ${i.mcp.configFile}`),console.log(`Hooks : ${i.hooks.configured?"ready":"missing"} \u2014 ${i.hooks.hooksFile}`),i.skill&&console.log(`Skill : ${i.skill.configured?"ready":"missing"} \u2014 ${i.skill.skillFile}`),i.hooks.events.length>0&&console.log(`Events: ${i.hooks.events.join(", ")}`);for(let g of i.errors)console.log(`Error : ${g}`);console.log("")}i.installed||(process.exitCode=1);return}let e=o==="cursor"?X():o==="copilot"?eo():mo(),s=Y(o);if(!s.installed)throw new Error(`${A[o]} integration installation did not verify successfully (state=${s.state}).`);if(n){console.log(JSON.stringify({installed:!0,changed:e.changed,files:e.files,status:s},null,2));return}console.log(`\u2705 ${A[o]} integration installed`),console.log(`MCP: ${e.mcp.configFile}`),console.log(`Hooks: ${e.hooks.hooksFile}`),s.skill&&console.log(`Skill: ${s.skill.skillFile}`),console.log("Server: toolnet-memory")}try{ho("grok")}catch(o){console.error(o instanceof Error?o.message:String(o)),process.exitCode=1}
32
+ ${r}`:r}function eo(o,e,t){let r=to(o,e);if(!r)return!1;let n=o.slice(r.start,r.end);return n.includes(`command = "${q(t)}"`)&&/args\s*=\s*\[\s*"mcp"\s*\]/.test(n)&&/enabled\s*=\s*true/.test(n)}function B(o={}){let e=o.configFile??m(),t=o.binary??process.env.TOOLNET_MEMORY_BIN??"toolnet-memory",r=o.serverName??"toolnet-memory",n=oo(e);if(eo(n,r,t))return{installed:!0,changed:!1,configFile:e,serverName:r,command:t,args:["mcp"]};let i=oe(n,r,t);Vo(e,i);let s=oo(e);if(!eo(s,r,t))throw new Error("Grok Build MCP configuration was written but verification failed.");return{installed:!0,changed:!0,configFile:e,serverName:r,command:t,args:["mcp"]}}import{spawnSync as ee}from"node:child_process";import{existsSync as S,statSync as te}from"node:fs";import{dirname as re,join as ne,parse as ie,resolve as L}from"node:path";function ro(o){let e=L(o);if(!S(e))throw new Error(`Project path does not exist: ${e}`);if(!te(e).isDirectory())throw new Error(`Project path is not a directory: ${e}`);return e}function G(o){return ne(o,".toolnet","project.json")}function se(o){let e=L(o),t=ie(e).root;for(;;){if(S(G(e)))return e;if(e===t)return;let r=re(e);if(r===e)return;e=r}}function U(o){let e=ee("git",["rev-parse","--show-toplevel"],{cwd:o,encoding:"utf8",timeout:5e3});if(e.status!==0)return;let t=e.stdout.trim();return t?L(t):void 0}function v(o={}){let e=ro(o.cwd??process.cwd());if(o.project){let n=ro(o.project),i=G(n),s=U(n);return{root:n,source:"explicit",eligible:!0,toolnetProject:S(i),manifestFile:S(i)?i:void 0,gitRoot:s}}let t=se(e);if(t){let n=G(t);return{root:t,source:"toolnet",eligible:!0,toolnetProject:!0,manifestFile:n,gitRoot:U(t)}}let r=U(e);if(r){let n=G(r);return{root:r,source:"git",eligible:!0,toolnetProject:S(n),manifestFile:S(n)?n:void 0,gitRoot:r}}return{root:e,source:"cwd",eligible:!1,toolnetProject:!1}}function lo(o,e={}){let t=[],r=o.indexOf("--scope");if(r>=0){let i=o[r+1];if(i!=="global"&&i!=="project"&&i!=="both")throw new Error(`Invalid --scope value: ${String(i)}`);t.push(i)}o.includes("--global")&&t.push("global"),o.includes("--both")&&t.push("both");let n=Array.from(new Set(t));if(n.length>1)throw new Error(`Conflicting integration scopes: ${n.join(", ")}`);return n[0]??e.defaultScope??"global"}function no(o,e){return{install:o,effective:e}}function k(o,e){return{surface:o,global:no(e.globalInstall,e.effective==="global"||e.effective==="both"),project:no(e.projectInstall,e.effective==="project"||e.effective==="both"),effective:e.effective,risk:e.risk??"none",dedupeRequired:e.dedupeRequired??!1,trustRequired:e.trustRequired??e.projectInstall,note:e.note}}function le(o){return{mcp:k("mcp",{globalInstall:!0,projectInstall:!1,effective:"global"}),hooks:k("hooks",{globalInstall:!0,projectInstall:!1,effective:"global"}),work:k("work",{globalInstall:o==="grok",projectInstall:!1,effective:o==="grok"?"global":"none",note:o==="grok"?"Grok supports a global ToolNet continuity skill.":"Cursor/Copilot work instructions remain project-scoped."})}}function io(o){return{mcp:k("mcp",{globalInstall:!1,projectInstall:!0,effective:"project",trustRequired:!0}),hooks:k("hooks",{globalInstall:!1,projectInstall:!0,effective:"project",trustRequired:!0}),work:k("work",{globalInstall:!1,projectInstall:!0,effective:"project",trustRequired:!1,note:o==="cursor"?"Use .cursor/rules/toolnet-memory.mdc.":o==="copilot"?"Use .github/instructions/toolnet-memory.instructions.md.":"Use .grok/skills/toolnet-continuity/SKILL.md."})}}function so(o){return{mcp:k("mcp",{globalInstall:!0,projectInstall:!0,effective:"project",risk:o==="cursor"?"precedence-unverified":"shadowed-global",trustRequired:!0,note:o==="cursor"?"Project ToolNet MCP is the intended effective definition; native same-name precedence must be E2E certified before release.":"Global remains useful outside the project; same-name project definition wins inside the project."}),hooks:k("hooks",{globalInstall:!0,projectInstall:!0,effective:"both",risk:"additive-duplicate",dedupeRequired:!0,trustRequired:!0,note:"Global and project hook sources can both execute for the same native event."}),work:k("work",{globalInstall:o==="grok",projectInstall:!0,effective:"project",risk:o==="grok"?"shadowed-global":"none",trustRequired:!1,note:o==="cursor"?"Project rule is authoritative.":o==="copilot"?"Project instruction is authoritative.":"Project skill shadows the same-name global skill inside the project."})}}function H(o){let{agent:e,scope:t,project:r}=o;return(t==="project"||t==="both")&&(!r||!r.eligible)?{agent:e,requestedScope:t,project:r,surfaces:t==="both"?so(e):io(e),canInstall:!1,reason:"Project scope requires an explicit project, existing ToolNet project, or Git repository root."}:{agent:e,requestedScope:t,project:r,surfaces:t==="global"?le(e):t==="project"?io(e):so(e),canInstall:!0}}function co(o){return!!(o?.mcp?.changed||o?.hooks?.changed||o?.skill?.changed)}function ao(o={}){let e=o.binary??process.env.TOOLNET_MEMORY_BIN??"toolnet-memory",t=o.scope??"global",r=t==="global"?void 0:v({project:o.projectRoot}),n=H({agent:"grok",scope:t,project:r});if(!n.canInstall)throw new Error(n.reason??"Grok project integration scope cannot be resolved.");let i,s;if((n.surfaces.mcp.global.install||n.surfaces.hooks.global.install||n.surfaces.work.global.install)&&(i={},n.surfaces.mcp.global.install&&(i.mcp=B({binary:e,configFile:o.configFile??m()})),n.surfaces.hooks.global.install&&(i.hooks=J({binary:e,hooksFile:o.hooksFile??h()})),n.surfaces.work.global.install&&(i.skill=D({skillFile:o.skillFile??y()}))),n.surfaces.mcp.project.install||n.surfaces.hooks.project.install||n.surfaces.work.project.install){if(!r?.eligible)throw new Error("Grok project integration requires an eligible project root.");s={},n.surfaces.mcp.project.install&&(s.mcp=B({binary:e,configFile:o.projectConfigFile??P(r.root)})),n.surfaces.hooks.project.install&&(s.hooks=J({binary:e,hooksFile:o.projectHooksFile??x(r.root)})),n.surfaces.work.project.install&&(s.skill=D({skillFile:o.projectSkillFile??O(r.root)}))}let a=s?.mcp??i?.mcp,u=s?.hooks??i?.hooks,l=s?.skill??i?.skill;if(!a||!u||!l)throw new Error("Grok integration did not produce effective MCP/hooks/skill.");let c=Array.from(new Set([i?.mcp?.configFile,i?.hooks?.hooksFile,i?.skill?.skillFile,s?.mcp?.configFile,s?.hooks?.hooksFile,s?.skill?.skillFile].filter(g=>typeof g=="string")));return{installed:!0,changed:co(i)||co(s),scope:t,plan:n,project:r,global:i,projectScope:s,mcp:a,hooks:u,skill:l,files:c}}import{existsSync as X}from"node:fs";import{existsSync as F,readFileSync as z}from"node:fs";import{homedir as ce}from"node:os";import{join as K,resolve as ot}from"node:path";function uo(o={}){return o.cursorHome??K(o.home??ce(),".cursor")}function go(o={}){return K(uo(o),"mcp.json")}function fo(o={}){return K(uo(o),"hooks.json")}import{homedir as ae}from"node:os";import{join as A,resolve as nt}from"node:path";function po(o={}){return o.copilotHome??process.env.COPILOT_HOME??A(o.home??ae(),".copilot")}function ko(o={}){return A(po(o),"mcp-config.json")}function ue(o={}){return A(po(o),"hooks")}function mo(o={}){return A(ue(o),"toolnet-memory.json")}function b(o){return typeof o=="object"&&o!==null&&!Array.isArray(o)}function C(o){if(!F(o))return{};try{let e=JSON.parse(z(o,"utf8"));return b(e)?{value:e}:{error:"root must be a JSON object"}}catch(e){return{error:e instanceof Error?e.message:String(e)}}}function ho(o,e){if(!o||!b(o.mcpServers))return!1;let t=o.mcpServers["toolnet-memory"];return!b(t)||typeof t.command!="string"||!t.command.trim()||!Array.isArray(t.args)||t.args.length!==1||t.args[0]!=="mcp"?!1:!e||Array.isArray(t.tools)&&t.tools.includes("*")}function yo(o,e,t){if(!o||!b(o.hooks))return[];let r=o.hooks;return e.filter(n=>{let i=r[n];return Array.isArray(i)&&i.some(s=>b(s)&&(typeof s.command=="string"&&s.command.includes(t)||typeof s.bash=="string"&&s.bash.includes(t)))})}function ge(o,e){if(!o||!b(o.hooks))return[];let t=o.hooks;return e.filter(r=>{let n=t[r];return Array.isArray(n)&&n.some(i=>!b(i)||!Array.isArray(i.hooks)?!1:i.hooks.some(s=>b(s)&&typeof s.command=="string"&&s.command.includes("session:grok-hook")))})}function fe(o){if(!F(o))return!1;let e=z(o,"utf8"),t=/\[mcp_servers\.(?:"toolnet-memory"|'toolnet-memory'|toolnet-memory)\]/,r=e.search(t);if(r<0)return!1;let n=e.slice(r),i=n.slice(1).search(/\n\s*\[[^\]]+\]/),s=i>=0?n.slice(0,i+1):n;return/command\s*=\s*"[^"]+"/.test(s)&&/args\s*=\s*\[\s*"mcp"\s*\]/.test(s)&&!/enabled\s*=\s*false/.test(s)}function W(o){let e=[];o.mcpError&&e.push(`MCP config: ${o.mcpError}`),o.hookError&&e.push(`Hooks config: ${o.hookError}`);let t=o.mcpConfigured&&o.hooksConfigured&&(o.skill?.configured??!0),r=F(o.configFile)||F(o.hooksFile)||(o.skill?F(o.skill.skillFile):!1),n=e.length>0?"invalid":t?"ready":r?"partial":"not-installed";return{installed:t,state:n,mcp:{configured:o.mcpConfigured,configFile:o.configFile,error:o.mcpError},hooks:{configured:o.hooksConfigured,hooksFile:o.hooksFile,events:o.events,error:o.hookError},skill:o.skill,errors:e}}function V(o,e={}){if(o==="cursor"){let l=["sessionStart","beforeSubmitPrompt","preToolUse","postToolUse","afterAgentResponse","stop"],c=e.configFile??go(),g=e.hooksFile??fo(),p=C(c),d=C(g),I=d.error?[]:yo(d.value,l,"session:cursor-hook");return W({mcpConfigured:!p.error&&ho(p.value,!1),configFile:c,mcpError:p.error,hooksConfigured:l.every($=>I.includes($)),hooksFile:g,events:I,hookError:d.error})}if(o==="copilot"){let l=["sessionStart","userPromptSubmitted","userPromptTransformed","preToolUse","postToolUse","agentStop"],c=e.configFile??ko(),g=e.hooksFile??mo(),p=C(c),d=C(g),I=d.error?[]:yo(d.value,l,"session:copilot-hook");return W({mcpConfigured:!p.error&&ho(p.value,!0),configFile:c,mcpError:p.error,hooksConfigured:l.every($=>I.includes($)),hooksFile:g,events:I,hookError:d.error})}let t=["SessionStart","UserPromptSubmit","PreToolUse","PostToolUse","Stop"],r=e.configFile??m(),n=e.hooksFile??h(),i=e.skillFile??y(),s=C(n),a=s.error?[]:ge(s.value,t),u=F(i)&&z(i,"utf8").includes("memory_agent_ask");return W({mcpConfigured:fe(r),configFile:r,hooksConfigured:t.every(l=>a.includes(l)),hooksFile:n,events:a,hookError:s.error,skill:{configured:u,skillFile:i}})}function pe(o,e){return e.some(r=>r?.state==="invalid")?"invalid":o?"ready":e.some(r=>r&&(r.state==="partial"||r.state==="ready"||X(r.mcp.configFile)||X(r.hooks.hooksFile)||!!(r.skill&&X(r.skill.skillFile))))?"partial":"not-installed"}function E(o={}){let e=o.scope??"global",t=e==="global"?void 0:v({project:o.projectRoot}),r=H({agent:"grok",scope:e,project:t}),n=e==="global"||e==="both"?V("grok",{configFile:o.globalConfigFile??m(),hooksFile:o.globalHooksFile??h(),skillFile:o.globalSkillFile??y()}):void 0,i=(e==="project"||e==="both")&&t?.eligible?V("grok",{configFile:o.projectConfigFile??P(t.root),hooksFile:o.projectHooksFile??x(t.root),skillFile:o.projectSkillFile??O(t.root)}):void 0,s=e==="project"?!0:n?.installed===!0,a=e==="global"?!0:i?.installed===!0,u=r.canInstall&&s&&a,l=[];return!r.canInstall&&r.reason&&l.push(r.reason),e==="both"&&(l.push("Global + project Grok hooks are layered; ToolNet cross-process dedupe is enabled."),l.push('Project [mcp_servers."toolnet-memory"] fully replaces the same-name global server inside this project.'),l.push("Project toolnet-continuity skill shadows the same-name global skill inside this project.")),{installed:u,state:pe(u,[n,i]),requestedScope:e,plan:r,project:t,global:n,projectScope:i,effective:{mcp:r.surfaces.mcp.effective==="project"?"project":r.surfaces.mcp.effective==="global"?"global":"none",hooks:r.surfaces.hooks.effective==="both"?"both":r.surfaces.hooks.effective==="project"?"project":r.surfaces.hooks.effective==="global"?"global":"none",skill:r.surfaces.work.effective==="project"?"project":r.surfaces.work.effective==="global"?"global":"none"},dedupeReady:!0,trustRequired:e==="project"||e==="both",warnings:l}}function de(o,e){let t=o.indexOf(e);return t>=0?o[t+1]:void 0}function ke(){let o=process.argv.slice(2);return o[0]==="install"?o.slice(1):o}function me(o,e){let t=E({scope:o,projectRoot:e});console.log("Grok Build Integration"),console.log("======================"),console.log(""),console.log(`State : ${t.state}`),console.log(`Scope : ${t.requestedScope}`),t.global&&(console.log(""),console.log("Global"),console.log(` MCP : ${t.global.mcp.configured?"ready":"missing"} \u2014 ${t.global.mcp.configFile}`),console.log(` Hooks : ${t.global.hooks.configured?"ready":"missing"} \u2014 ${t.global.hooks.hooksFile}`),console.log(` Skill : ${t.global.skill?.configured?"ready":"missing"} \u2014 ${t.global.skill?.skillFile??"-"}`)),t.projectScope&&(console.log(""),console.log("Project"),console.log(` Root : ${t.project?.root??"-"}`),console.log(` MCP : ${t.projectScope.mcp.configured?"ready":"missing"} \u2014 ${t.projectScope.mcp.configFile}`),console.log(` Hooks : ${t.projectScope.hooks.configured?"ready":"missing"} \u2014 ${t.projectScope.hooks.hooksFile}`),console.log(` Skill : ${t.projectScope.skill?.configured?"ready":"missing"} \u2014 ${t.projectScope.skill?.skillFile??"-"}`),console.log(` Trust : ${t.trustRequired?"required":"n/a"}`)),console.log(""),console.log(`Effective MCP : ${t.effective.mcp}`),console.log(`Effective Hooks : ${t.effective.hooks}`),console.log(`Effective Skill : ${t.effective.skill}`),console.log(`Dedupe : ${t.dedupeReady?"ready":"missing"}`);for(let r of t.warnings)console.log(`Note : ${r}`);console.log(""),t.installed||(process.exitCode=1)}function he(){let o=ke(),e=o.includes("--json"),t=o.includes("--status")||o[0]==="status",r=lo(o),n=de(o,"--project"),i=r==="global"?void 0:v({project:n});if(t){let u=E({scope:r,projectRoot:i?.root});if(e){console.log(JSON.stringify(u,null,2)),u.installed||(process.exitCode=1);return}me(r,i?.root);return}let s=ao({scope:r,projectRoot:i?.root}),a=E({scope:r,projectRoot:i?.root});if(!a.installed)throw new Error(`Grok Build integration installation did not verify successfully (state=${a.state}).`);if(e){console.log(JSON.stringify({installed:!0,changed:s.changed,scope:s.scope,files:s.files,status:a},null,2));return}console.log("\u2705 Grok Build integration installed"),console.log(`Scope: ${r}`);for(let u of s.files)console.log(`File: ${u}`);r==="both"&&(console.log("Hook dedupe: enabled"),console.log("Project MCP precedence: project fully replaces global same-name server"),console.log("Project skill precedence: project > global"),console.log("Project trust: required by Grok Build")),console.log("Server: toolnet-memory")}try{he()}catch(o){console.error(o instanceof Error?o.message:String(o)),process.exitCode=1}
@@ -1,4 +1,4 @@
1
- import{readFileSync as M}from"node:fs";import{dirname as j,resolve as I}from"node:path";import{fileURLToPath as D}from"node:url";var R={spinner:["\xB7","\u2722","\u2733","\u2736","\u273B","\u273D"],barFilled:"\u2588",barEmpty:"\u2591",phaseDone:"\u25C6",phaseActive:"\u25C7",rail:"\u2502",branch:"\u251C",corner:"\u2514",dash:"\u2014"},U={spinner:[".","*","+","x","*","+"],barFilled:"#",barEmpty:"-",phaseDone:"[OK]",phaseActive:"[>>]",rail:"|",branch:"|",corner:"\\",dash:"-"};function A(){if(process.env.TOOLNET_ASCII==="1")return!1;if(process.env.TOOLNET_UNICODE==="1")return!0;if(process.platform==="win32"){let t=process.env.TERM_PROGRAM,e=process.env.WT_SESSION,o=process.env.VSCODE_PID,n=process.env.ConEmuPID;return!!(e||o||n||t==="vscode")}return process.env.TERM!=="linux"}var h;function v(){return h||(h=A()?R:U),h}var d={reset:"\x1B[0m",green:"\x1B[32m",cyan:"\x1B[36m",red:"\x1B[31m",yellow:"\x1B[33m",amber:"\x1B[38;5;214m",white:"\x1B[97m",dim:"\x1B[2m",bold:"\x1B[1m"};function T(t){return t.noColor||process.env.NO_COLOR?!1:t.tty??process.stdout.isTTY??!1}function f(t,e,o){return T(o)?`${e}${t}${d.reset}`:t}function N(t,e){return f(t,d.dim,e)}function G(t,e){return f(t,d.bold,e)}function O(t,e){return f(t,d.cyan,e)}function u(t,e,o){let n=v(),i=e?` ${N(`v${e}`,o)}`:"";return`${O(n.phaseDone,o)} ${t}${i}`}function a(t,e){return G(t,e)}function l(t,e,o,n){let i=" ".repeat(Math.max(0,o-t.length));return` ${O(t,n)}${i} ${e}`}var m=[{name:"setup",description:"Configure ToolNet",category:"core"},{name:"init",description:"Initialize current project",usage:"toolnet-memory init [path]",category:"core"},{name:"doctor",description:"Check system health",category:"core"},{name:"ask",description:"Ask project memory",usage:"toolnet-memory ask <question>",category:"memory"},{name:"context",description:"Show current project context",category:"memory",aliases:["context:print"]},{name:"work",description:"Show current work state",category:"memory",aliases:["work:status"]},{name:"index",description:"Build code intelligence",category:"code",pipeline:["Scanning files","Parsing code","Type Resolution","Rich Graph","Semantic Code Index","Architecture Intelligence","Graph Analysis","3D Visualization Dataset"]},{name:"semantic",description:"Semantic code search",usage:"toolnet-memory semantic <query>",category:"code"},{name:"impact",description:"Analyze change impact",usage:"toolnet-memory impact <file>",category:"code"},{name:"graph",description:"Open code graph UI",category:"code"},{name:"graph:ui",description:"Open code graph UI",category:"code",hidden:!0},{name:"model",description:"View/change AI model",category:"ai"},{name:"provider",description:"Manage AI providers",category:"ai",aliases:["provider:status"]},{name:"status",description:"Show ToolNet status",category:"system"},{name:"update",description:"Update ToolNet Memory",category:"system"},{name:"context:print",description:"Print fast project context",category:"context",hidden:!0},{name:"context:sync",description:"Show context hash/size",category:"context"},{name:"context:refresh",description:"Rebuild deep startup brief cache",category:"context"},{name:"brief",description:"Show full project brief",category:"context"},{name:"brief:json",description:"Show brief as JSON",category:"context"},{name:"profile:show",description:"Show .toolnet/profile.md",category:"context"},{name:"profile:sync",description:"Sync profile to agent files",category:"context"},{name:"work:status",description:"Show current work state",category:"work",hidden:!0},{name:"work:json",description:"Show work state as JSON",category:"work"},{name:"work:reconcile",description:"Reconcile work continuity",category:"work"},{name:"handoff:latest",description:"Show latest session handoff",category:"work"},{name:"handoff:refresh",description:"Refresh handoff data",category:"work"},{name:"index:graph",description:"Build graph index only",category:"code"},{name:"incremental",description:"Incremental code indexing",category:"code"},{name:"config",description:"Manage configuration",usage:"toolnet-memory config <get|set|list|open>",category:"ai"},{name:"provider:list",description:"List available AI providers",category:"ai"},{name:"provider:status",description:"Show AI provider status",category:"ai",hidden:!0},{name:"provider:test",description:"Test AI provider connection",category:"ai"},{name:"integrate:detect",description:"Detect agent integrations",category:"integration"},{name:"integrate:auto",description:"Auto-enable integrations",category:"integration"},{name:"integrate:agy",description:"Install Agy hooks",category:"integration"},{name:"integrate:codex",description:"Install Codex integration",category:"integration"},{name:"integrate:opencode",description:"Install OpenCode plugin",category:"integration"},{name:"integrate:claude",description:"Install Claude Code integration",category:"integration"},{name:"integrate:kiro",description:"Install Kiro CLI integration",usage:"toolnet-memory integrate:kiro [--status] [--json]",category:"integration"},{name:"integrate:cursor",description:"Install Cursor CLI integration",usage:"toolnet-memory integrate:cursor [--status] [--json]",category:"integration"},{name:"integrate:copilot",description:"Install GitHub Copilot CLI integration",usage:"toolnet-memory integrate:copilot [--status] [--json]",category:"integration"},{name:"integrate:grok",description:"Install Grok Build integration",usage:"toolnet-memory integrate:grok [--status] [--json]",category:"integration"},{name:"session:agy-sync",description:"Sync Agy session",category:"session"},{name:"session:agy-recover",description:"Recover Agy sessions",category:"session"},{name:"session:agy-hook",description:"Agy session hook",category:"session",hidden:!0},{name:"session:codex-sync",description:"Sync Codex session",category:"session"},{name:"session:codex-recover",description:"Recover Codex sessions",category:"session"},{name:"session:codex-notify",description:"Codex notification hook",category:"session",hidden:!0},{name:"session:codex-context",description:"Codex context hook",category:"session",hidden:!0},{name:"session:opencode-sync",description:"Sync OpenCode session",category:"session"},{name:"session:opencode-recover",description:"Recover OpenCode sessions",category:"session"},{name:"session:claude-hook",description:"Claude session hook",category:"session",hidden:!0},{name:"session:kiro-hook",description:"Kiro lifecycle hook",category:"session",hidden:!0},{name:"session:cursor-hook",description:"Cursor lifecycle hook",category:"session",hidden:!0},{name:"session:copilot-hook",description:"Copilot lifecycle hook",category:"session",hidden:!0},{name:"session:grok-hook",description:"Grok lifecycle hook",category:"session",hidden:!0},{name:"memory:review",description:"Review memory entries",category:"session"},{name:"memory:reconcile",description:"Reconcile memory state",category:"session"},{name:"guard:check",description:"Check project rules",category:"guard"},{name:"guard:explain",description:"Show rules and evidence",category:"guard"},{name:"guard:json",description:"Output guard result as JSON",category:"guard",hidden:!0},{name:"project:manual-init",description:"Initialize project manual",category:"project"},{name:"project:manual-show",description:"Show project manual",category:"project"},{name:"project:manual-sync",description:"Sync project manual",category:"project"},{name:"snapshot:list",description:"List snapshots",category:"snapshot"},{name:"snapshot:create",description:"Create snapshot",category:"snapshot"},{name:"snapshot:restore",description:"Restore snapshot",category:"snapshot"},{name:"recover",description:"Recover latest snapshot",category:"snapshot"},{name:"service",description:"Run daemon in foreground",category:"service"},{name:"service:install",description:"Install/start daemon",category:"service"},{name:"service:start",description:"Start daemon",category:"service"},{name:"service:stop",description:"Stop daemon",category:"service"},{name:"service:restart",description:"Restart daemon",category:"service"},{name:"service:status",description:"Show daemon status",category:"service"},{name:"service:remove",description:"Remove daemon",category:"service"},{name:"mcp",description:"Run MCP server",category:"advanced"},{name:"api",description:"Run API server",category:"advanced"},{name:"run",description:"Run ToolNet runtime",category:"advanced",hidden:!0},{name:"production:certify",description:"Verify production runtime",category:"advanced"},{name:"certify:continuity",description:"Certify work continuity",category:"advanced"},{name:"ask-ai",description:"Ask AI agent (advanced)",category:"advanced",hidden:!0}];function C(t){return{tty:t.tty,noColor:t.noColor}}function k(t){let e=[],o=t.version??"0.0.0",n=C(t);e.push(""),e.push(u("ToolNet Memory",o,n)),e.push(" Persistent memory & code intelligence for AI coding agents"),e.push(""),e.push(a("USAGE",n)),e.push(" toolnet-memory <command> [options]"),e.push("");let i=[{key:"core",title:"GET STARTED"},{key:"memory",title:"MEMORY"},{key:"code",title:"CODE"},{key:"ai",title:"AI"},{key:"system",title:"SYSTEM"}];for(let{key:s,title:g}of i){let c=m.filter(r=>r.category===s&&!r.hidden);if(c.length===0)continue;e.push(a(g,n));let y=Math.max(...c.map(r=>r.name.length));for(let r of c)e.push(l(r.name,r.description,y,n));e.push("")}return e.push(a("MORE",n)),e.push(l("help --all","Show all advanced commands",15,n)),e.push(l("help <command>","Show command details",15,n)),e.push(""),e.join(`
2
- `)}function S(t){let e=[],o=t.version??"0.0.0",n=C(t);e.push(""),e.push(u("ToolNet Memory",o,n)),e.push(" Persistent memory & code intelligence for AI coding agents"),e.push(""),e.push(a("USAGE",n)),e.push(" toolnet-memory <command> [options]"),e.push("");let i=[{key:"core",title:"PROJECT SETUP"},{key:"memory",title:"MEMORY"},{key:"code",title:"CODE INTELLIGENCE"},{key:"ai",title:"AI / PROVIDERS"},{key:"system",title:"SYSTEM"},{key:"context",title:"CONTEXT & MEMORY"},{key:"work",title:"WORK CONTINUITY"},{key:"integration",title:"AGENT INTEGRATIONS"},{key:"session",title:"SESSIONS"},{key:"guard",title:"GUARD"},{key:"project",title:"PROJECT MANUAL"},{key:"snapshot",title:"SNAPSHOTS & RECOVERY"},{key:"service",title:"BACKGROUND SERVICE"},{key:"advanced",title:"DEVELOPER / PRODUCTION"}];for(let{key:s,title:g}of i){let c=m.filter(r=>r.category===s&&!r.hidden);if(c.length===0)continue;e.push(a(g,n));let y=Math.max(...c.map(r=>r.name.length));for(let r of c)e.push(l(r.name,r.description,y,n));e.push("")}return e.join(`
3
- `)}function b(t,e){let o=m.find(s=>s.name===t||s.aliases?.includes(t));if(!o)return null;let n=[],i=C(e);if(n.push(""),n.push(u(o.name,void 0,i)),n.push(""),n.push(o.description),n.push(""),o.usage&&(n.push(a("USAGE",i)),n.push(` ${o.usage}`),n.push("")),o.aliases&&o.aliases.length>0){n.push(a("ALIASES",i));for(let s of o.aliases)n.push(` ${s}`);n.push("")}if(o.pipeline&&o.pipeline.length>0){n.push(a("PIPELINE",i));for(let s of o.pipeline)n.push(` ${s}`);n.push("")}if(o.examples&&o.examples.length>0){n.push(a("EXAMPLES",i));for(let s of o.examples)n.push(` ${s}`);n.push("")}return n.join(`
4
- `)}function w(t){return m.flatMap(n=>[n.name,...n.aliases??[]]).filter(n=>n===t?!1:!!(n.startsWith(t)||t.length>=3&&n.includes(t))).slice(0,3)}function $(){let t=j(D(import.meta.url)),e=[I(t,"../package.json"),I(t,"../../package.json")];for(let o of e)try{let n=JSON.parse(M(o,"utf8"));if(n.version)return n.version}catch{}return process.env.npm_package_version??"unknown"}var p=process.argv.slice(2),x={version:$(),tty:!!process.stdout.isTTY};function E(t){let e=w(t);if(console.error(""),console.error(`\u2715 Unknown command: ${t}`),e.length>0){console.error(""),console.error(" Did you mean:");for(let o of e)console.error(` ${o}`)}console.error(""),console.error(" Run `toolnet-memory help` to see available commands."),console.error("")}if(p[0]==="--unknown")E(p[1]??""),process.exitCode=1;else if(p[0]==="--all")console.log(S(x));else if(p[0]){let t=b(p[0],x);t?console.log(t):(E(p[0]),process.exitCode=1)}else console.log(k(x));
1
+ import{readFileSync as N}from"node:fs";import{dirname as M,resolve as w}from"node:path";import{fileURLToPath as D}from"node:url";var E={spinner:["\xB7","\u2722","\u2733","\u2736","\u273B","\u273D"],barFilled:"\u2588",barEmpty:"\u2591",phaseDone:"\u25C6",phaseActive:"\u25C7",rail:"\u2502",branch:"\u251C",corner:"\u2514",dash:"\u2014"},R={spinner:[".","*","+","x","*","+"],barFilled:"#",barEmpty:"-",phaseDone:"[OK]",phaseActive:"[>>]",rail:"|",branch:"|",corner:"\\",dash:"-"};function U(){if(process.env.TOOLNET_ASCII==="1")return!1;if(process.env.TOOLNET_UNICODE==="1")return!0;if(process.platform==="win32"){let o=process.env.TERM_PROGRAM,e=process.env.WT_SESSION,n=process.env.VSCODE_PID,t=process.env.ConEmuPID;return!!(e||n||t||o==="vscode")}return process.env.TERM!=="linux"}var h;function v(){return h||(h=U()?E:R),h}var m={reset:"\x1B[0m",green:"\x1B[32m",cyan:"\x1B[36m",red:"\x1B[31m",yellow:"\x1B[33m",amber:"\x1B[38;5;214m",white:"\x1B[97m",dim:"\x1B[2m",bold:"\x1B[1m"};function A(o){return o.noColor||process.env.NO_COLOR?!1:o.tty??process.stdout.isTTY??!1}function f(o,e,n){return A(n)?`${e}${o}${m.reset}`:o}function T(o,e){return f(o,m.dim,e)}function G(o,e){return f(o,m.bold,e)}function k(o,e){return f(o,m.cyan,e)}function d(o,e,n){let t=v(),i=e?` ${T(`v${e}`,n)}`:"";return`${k(t.phaseDone,n)} ${o}${i}`}function a(o,e){return G(o,e)}function l(o,e,n,t){let i=" ".repeat(Math.max(0,n-o.length));return` ${k(o,t)}${i} ${e}`}var g=[{name:"setup",description:"Configure ToolNet",category:"core"},{name:"init",description:"Initialize current project",usage:"toolnet-memory init [path]",category:"core"},{name:"doctor",description:"Check system health",category:"core"},{name:"ask",description:"Ask project memory",usage:"toolnet-memory ask <question>",category:"memory"},{name:"context",description:"Show current project context",category:"memory",aliases:["context:print"]},{name:"work",description:"Show current work state",category:"memory",aliases:["work:status"]},{name:"index",description:"Build code intelligence",category:"code",pipeline:["Scanning files","Parsing code","Type Resolution","Rich Graph","Semantic Code Index","Architecture Intelligence","Graph Analysis","3D Visualization Dataset"]},{name:"semantic",description:"Semantic code search",usage:"toolnet-memory semantic <query>",category:"code"},{name:"impact",description:"Analyze change impact",usage:"toolnet-memory impact <file>",category:"code"},{name:"graph",description:"Open code graph UI",category:"code"},{name:"graph:ui",description:"Open code graph UI",category:"code",hidden:!0},{name:"model",description:"View/change AI model",category:"ai"},{name:"provider",description:"Manage AI providers",category:"ai",aliases:["provider:status"]},{name:"status",description:"Show ToolNet status",category:"system"},{name:"update",description:"Update ToolNet Memory",category:"system"},{name:"context:print",description:"Print fast project context",category:"context",hidden:!0},{name:"context:sync",description:"Show context hash/size",category:"context"},{name:"context:refresh",description:"Rebuild deep startup brief cache",category:"context"},{name:"brief",description:"Show full project brief",category:"context"},{name:"brief:json",description:"Show brief as JSON",category:"context"},{name:"profile:show",description:"Show .toolnet/profile.md",category:"context"},{name:"profile:sync",description:"Sync profile to agent files",category:"context"},{name:"work:status",description:"Show current work state",category:"work",hidden:!0},{name:"work:json",description:"Show work state as JSON",category:"work"},{name:"work:reconcile",description:"Reconcile work continuity",category:"work"},{name:"handoff:latest",description:"Show latest session handoff",category:"work"},{name:"handoff:refresh",description:"Refresh handoff data",category:"work"},{name:"index:graph",description:"Build graph index only",category:"code"},{name:"incremental",description:"Incremental code indexing",category:"code"},{name:"config",description:"Manage configuration",usage:"toolnet-memory config <get|set|list|open>",category:"ai"},{name:"provider:list",description:"List available AI providers",category:"ai"},{name:"provider:status",description:"Show AI provider status",category:"ai",hidden:!0},{name:"provider:test",description:"Test AI provider connection",category:"ai"},{name:"integrate:detect",description:"Detect agent integrations",category:"integration"},{name:"integrate:auto",description:"Auto-enable integrations with safe project scope policy",usage:"toolnet-memory integrate:auto [--all] [--scope global|project|both] [--project <path>] [--json]",category:"integration",examples:["toolnet-memory integrate:auto","toolnet-memory integrate:auto --project /path/to/toolnet-project","toolnet-memory integrate:auto --scope global","toolnet-memory integrate:auto --scope both --project /path/to/project"]},{name:"integrate:agy",description:"Install Agy hooks",category:"integration"},{name:"integrate:codex",description:"Install Codex integration",category:"integration"},{name:"integrate:opencode",description:"Install OpenCode plugin",category:"integration"},{name:"integrate:claude",description:"Install Claude Code integration",category:"integration"},{name:"integrate:kiro",description:"Install Kiro CLI integration",usage:"toolnet-memory integrate:kiro [--status] [--json]",category:"integration"},{name:"integrate:cursor",description:"Install Cursor CLI integration",usage:"toolnet-memory integrate:cursor [--scope global|project|both] [--project <path>] [--status] [--json]",category:"integration",examples:["toolnet-memory integrate:cursor --scope global","toolnet-memory integrate:cursor --scope project --project /path/to/project","toolnet-memory integrate:cursor --scope both --project /path/to/project"]},{name:"integrate:copilot",description:"Install GitHub Copilot CLI integration",usage:"toolnet-memory integrate:copilot [--scope global|project|both] [--project <path>] [--status] [--json]",category:"integration",examples:["toolnet-memory integrate:copilot --scope global","toolnet-memory integrate:copilot --scope project --project /path/to/project","toolnet-memory integrate:copilot --scope both --project /path/to/project"]},{name:"integrate:grok",description:"Install Grok Build integration",usage:"toolnet-memory integrate:grok [--scope global|project|both] [--project <path>] [--status] [--json]",category:"integration",examples:["toolnet-memory integrate:grok --scope global","toolnet-memory integrate:grok --scope project --project /path/to/project","toolnet-memory integrate:grok --scope both --project /path/to/project"]},{name:"integrate:status",description:"Show unified Cursor/Copilot/Grok scoped integration status",usage:"toolnet-memory integrate:status [--scope global|project|both] [--project <path>] [--agent cursor|copilot|grok] [--json]",category:"integration",examples:["toolnet-memory integrate:status --scope global","toolnet-memory integrate:status --scope both --project /path/to/project","toolnet-memory integrate:status --scope both --project /path/to/project --agent cursor"]},{name:"session:agy-sync",description:"Sync Agy session",category:"session"},{name:"session:agy-recover",description:"Recover Agy sessions",category:"session"},{name:"session:agy-hook",description:"Agy session hook",category:"session",hidden:!0},{name:"session:codex-sync",description:"Sync Codex session",category:"session"},{name:"session:codex-recover",description:"Recover Codex sessions",category:"session"},{name:"session:codex-notify",description:"Codex notification hook",category:"session",hidden:!0},{name:"session:codex-context",description:"Codex context hook",category:"session",hidden:!0},{name:"session:opencode-sync",description:"Sync OpenCode session",category:"session"},{name:"session:opencode-recover",description:"Recover OpenCode sessions",category:"session"},{name:"session:claude-hook",description:"Claude session hook",category:"session",hidden:!0},{name:"session:kiro-hook",description:"Kiro lifecycle hook",category:"session",hidden:!0},{name:"session:cursor-hook",description:"Cursor lifecycle hook",category:"session",hidden:!0},{name:"session:copilot-hook",description:"Copilot lifecycle hook",category:"session",hidden:!0},{name:"session:grok-hook",description:"Grok lifecycle hook",category:"session",hidden:!0},{name:"memory:review",description:"Review memory entries",category:"session"},{name:"memory:reconcile",description:"Reconcile memory state",category:"session"},{name:"guard:check",description:"Check project rules",category:"guard"},{name:"guard:explain",description:"Show rules and evidence",category:"guard"},{name:"guard:json",description:"Output guard result as JSON",category:"guard",hidden:!0},{name:"project:manual-init",description:"Initialize project manual",category:"project"},{name:"project:manual-show",description:"Show project manual",category:"project"},{name:"project:manual-sync",description:"Sync project manual",category:"project"},{name:"snapshot:list",description:"List snapshots",category:"snapshot"},{name:"snapshot:create",description:"Create snapshot",category:"snapshot"},{name:"snapshot:restore",description:"Restore snapshot",category:"snapshot"},{name:"recover",description:"Recover latest snapshot",category:"snapshot"},{name:"service",description:"Run daemon in foreground",category:"service"},{name:"service:install",description:"Install/start daemon",category:"service"},{name:"service:start",description:"Start daemon",category:"service"},{name:"service:stop",description:"Stop daemon",category:"service"},{name:"service:restart",description:"Restart daemon",category:"service"},{name:"service:status",description:"Show daemon status",category:"service"},{name:"service:remove",description:"Remove daemon",category:"service"},{name:"mcp",description:"Run MCP server",category:"advanced"},{name:"api",description:"Run API server",category:"advanced"},{name:"run",description:"Run ToolNet runtime",category:"advanced",hidden:!0},{name:"production:certify",description:"Verify production runtime",category:"advanced"},{name:"certify:continuity",description:"Certify work continuity",category:"advanced"},{name:"ask-ai",description:"Ask AI agent (advanced)",category:"advanced",hidden:!0}];function x(o){return{tty:o.tty,noColor:o.noColor}}function b(o){let e=[],n=o.version??"0.0.0",t=x(o);e.push(""),e.push(d("ToolNet Memory",n,t)),e.push(" Persistent memory & code intelligence for AI coding agents"),e.push(""),e.push(a("USAGE",t)),e.push(" toolnet-memory <command> [options]"),e.push("");let i=[{key:"core",title:"GET STARTED"},{key:"memory",title:"MEMORY"},{key:"code",title:"CODE"},{key:"ai",title:"AI"},{key:"system",title:"SYSTEM"}];for(let{key:s,title:u}of i){let c=g.filter(r=>r.category===s&&!r.hidden);if(c.length===0)continue;e.push(a(u,t));let y=Math.max(...c.map(r=>r.name.length));for(let r of c)e.push(l(r.name,r.description,y,t));e.push("")}return e.push(a("MORE",t)),e.push(l("help --all","Show all advanced commands",15,t)),e.push(l("help <command>","Show command details",15,t)),e.push(""),e.join(`
2
+ `)}function O(o){let e=[],n=o.version??"0.0.0",t=x(o);e.push(""),e.push(d("ToolNet Memory",n,t)),e.push(" Persistent memory & code intelligence for AI coding agents"),e.push(""),e.push(a("USAGE",t)),e.push(" toolnet-memory <command> [options]"),e.push("");let i=[{key:"core",title:"PROJECT SETUP"},{key:"memory",title:"MEMORY"},{key:"code",title:"CODE INTELLIGENCE"},{key:"ai",title:"AI / PROVIDERS"},{key:"system",title:"SYSTEM"},{key:"context",title:"CONTEXT & MEMORY"},{key:"work",title:"WORK CONTINUITY"},{key:"integration",title:"AGENT INTEGRATIONS"},{key:"session",title:"SESSIONS"},{key:"guard",title:"GUARD"},{key:"project",title:"PROJECT MANUAL"},{key:"snapshot",title:"SNAPSHOTS & RECOVERY"},{key:"service",title:"BACKGROUND SERVICE"},{key:"advanced",title:"DEVELOPER / PRODUCTION"}];for(let{key:s,title:u}of i){let c=g.filter(r=>r.category===s&&!r.hidden);if(c.length===0)continue;e.push(a(u,t));let y=Math.max(...c.map(r=>r.name.length));for(let r of c)e.push(l(r.name,r.description,y,t));e.push("")}return e.join(`
3
+ `)}function S(o,e){let n=g.find(s=>s.name===o||s.aliases?.includes(o));if(!n)return null;let t=[],i=x(e);if(t.push(""),t.push(d(n.name,void 0,i)),t.push(""),t.push(n.description),t.push(""),n.usage&&(t.push(a("USAGE",i)),t.push(` ${n.usage}`),t.push("")),n.aliases&&n.aliases.length>0){t.push(a("ALIASES",i));for(let s of n.aliases)t.push(` ${s}`);t.push("")}if(n.pipeline&&n.pipeline.length>0){t.push(a("PIPELINE",i));for(let s of n.pipeline)t.push(` ${s}`);t.push("")}if(n.examples&&n.examples.length>0){t.push(a("EXAMPLES",i));for(let s of n.examples)t.push(` ${s}`);t.push("")}return t.join(`
4
+ `)}function j(o){return g.flatMap(t=>[t.name,...t.aliases??[]]).filter(t=>t===o?!1:!!(t.startsWith(o)||o.length>=3&&t.includes(o))).slice(0,3)}function $(){let o=M(D(import.meta.url)),e=[w(o,"../package.json"),w(o,"../../package.json")];for(let n of e)try{let t=JSON.parse(N(n,"utf8"));if(t.version)return t.version}catch{}return process.env.npm_package_version??"unknown"}var p=process.argv.slice(2),C={version:$(),tty:!!process.stdout.isTTY};function I(o){let e=j(o);if(console.error(""),console.error(`\u2715 Unknown command: ${o}`),e.length>0){console.error(""),console.error(" Did you mean:");for(let n of e)console.error(` ${n}`)}console.error(""),console.error(" Run `toolnet-memory help` to see available commands."),console.error("")}if(p[0]==="--unknown")I(p[1]??""),process.exitCode=1;else if(p[0]==="--all")console.log(O(C));else if(p[0]){let o=S(p[0],C);o?console.log(o):(I(p[0]),process.exitCode=1)}else console.log(b(C));