toolnet-memory 0.3.3 → 0.3.5
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/agy-hook.js +79 -69
- package/bundle/agy.js +71 -61
- package/bundle/api.js +16 -16
- package/bundle/auto-integrate.js +377 -71
- package/bundle/claude-hook.js +102 -36
- package/bundle/codex-context.js +10 -10
- package/bundle/codex.js +67 -65
- package/bundle/context-runtime.js +30 -30
- package/bundle/context.js +15 -15
- package/bundle/continuity-certify.js +14 -13
- package/bundle/doctor.js +5 -5
- package/bundle/full-index.js +22 -18
- package/bundle/graph-index.js +2 -2
- package/bundle/handoff-refresh.js +7 -7
- package/bundle/init.js +386 -80
- package/bundle/learner.js +1 -1
- package/bundle/mcp.js +19 -19
- package/bundle/memory-agent.js +11 -11
- package/bundle/memory-query.js +5 -5
- package/bundle/opencode.js +442 -121
- package/bundle/project-manual.js +3 -3
- package/bundle/provider.js +5 -2
- package/bundle/recovery-certify.js +21 -20
- package/bundle/runtime.js +4 -4
- package/bundle/semantic.js +5 -5
- package/bundle/service-cli.js +2 -2
- package/bundle/setup.js +376 -70
- package/bundle/snapshot.js +4 -4
- package/bundle/update.js +4 -4
- package/bundle/work-continuity.js +7 -7
- package/package.json +1 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import*as c from"fs";import*as i from"path";import{existsSync as
|
|
1
|
+
import*as c from"fs";import*as i from"path";import{existsSync as w,mkdirSync as D,readFileSync as b,renameSync as $,writeFileSync as L}from"node:fs";import{dirname as z,join as v}from"node:path";import{createHash as F}from"node:crypto";function g(n){return F("sha256").update(n).digest("hex")}function A(n){return v(n.rootPath,".toolnet","context","handoff.md")}function C(n){return v(n.rootPath,".toolnet","context","handoff.json")}function M(n,e){D(z(n),{recursive:!0});let t=`${n}.tmp-${process.pid}-${Date.now()}`;L(t,e.endsWith(`
|
|
2
2
|
`)?e:`${e}
|
|
3
|
-
`,{encoding:"utf8",mode:384}),$(t,n)}function
|
|
3
|
+
`,{encoding:"utf8",mode:384}),$(t,n)}function H(n,e){M(n,`${JSON.stringify(e,null,2)}
|
|
4
4
|
`)}function E(n,e){let t=e.replace(/\r\n/g,`
|
|
5
|
-
`).trim();if(!t)return null;let r={version:1,projectId:n.id,projectName:n.name,text:t,digest:g(t),generatedAt:new Date().toISOString()};return M(A(n),t),
|
|
6
|
-
`)}function
|
|
5
|
+
`).trim();if(!t)return null;let r={version:1,projectId:n.id,projectName:n.name,text:t,digest:g(t),generatedAt:new Date().toISOString()};return M(A(n),t),H(C(n),r),r}function R(n){let e=A(n);if(!w(e))return null;try{let t=b(e,"utf8").trim();if(!t)return null;let r=new Date(0).toISOString(),o=C(n);if(w(o))try{let s=JSON.parse(b(o,"utf8"));typeof s.generatedAt=="string"&&(r=s.generatedAt)}catch{}return{version:1,projectId:n.id,projectName:n.name,text:t,digest:g(t),generatedAt:r}}catch{return null}}function T(n){let e=i.resolve(n),t=i.parse(e).root;for(;e!==t;){let r=i.join(e,".toolnet");if(c.existsSync(r)&&c.statSync(r).isDirectory())return e;e=i.dirname(e)}return null}import{existsSync as W,readFileSync as J}from"node:fs";import{join as U}from"node:path";import{existsSync as V,mkdirSync as De,readFileSync as G,renameSync as $e,writeFileSync as Le}from"node:fs";import{dirname as He,join as B}from"node:path";function K(n){return B(n.rootPath,".toolnet","context","session-origin.json")}function Y(n){let e=K(n);if(!V(e))return null;try{let t=JSON.parse(G(e,"utf8"));return t.version!==1||t.projectId!==n.id?null:t}catch{return null}}function O(n){let e=Y(n);if(!e)return null;let t=["Previous session:",`- Agent: ${e.agent}`,`- Session: ${e.nativeSessionId}`];return e.currentRequest&&t.push(`- Current request: ${e.currentRequest}`),e.currentActivity&&t.push(`- Current activity: ${e.currentActivity}`),e.currentPhase&&t.push(`- Current phase: ${e.currentPhase}`),e.currentTask&&t.push(`- Current task: ${e.currentTask}`),e.lastTouchedFile&&t.push(`- Last touched file: ${e.lastTouchedFile}`),e.latestBlocker&&t.push(`- Blocker: ${e.latestBlocker}`),e.latestNextAction&&t.push(`- Next action: ${e.latestNextAction}`),e.latestDecision&&t.push(`- Important decision: ${e.latestDecision}`),t.join(`
|
|
6
|
+
`)}function q(n){let e=U(n.rootPath,".toolnet","current.md");if(!W(e))return null;try{return J(e,"utf8").trim()}catch{return null}}function Q(n,e){let t=e.replace(/\r\n/g,`
|
|
7
7
|
`).trim(),r=2400,o=t.length>r?`${t.slice(0,r)}
|
|
8
8
|
|
|
9
9
|
[Current work truncated for fast handoff]`:t,s=O(n);return["# ToolNet Fast Handoff","",`Project: ${n.name}`,"",...s?[s,""]:[],o,"","---","","Continuation rule:","- Continue unfinished work; do not redo completed steps.","- Query ToolNet Memory only when deeper history is needed."].join(`
|
|
10
|
-
`)}function I(n){let e=
|
|
11
|
-
`).replace(/\\r/g,"\r").replace(/\\t/g," ").replace(/\\"/g,'"').replace(/\\\\/g,"\\")):e.length>=2&&e.startsWith("'")&&e.endsWith("'")?e.slice(1,-1):e}function re(){let n=process.env.TOOLNET_GLOBAL_ENV??te(ee(),".config","toolnet-memory",".env");if(!
|
|
12
|
-
`,{encoding:"utf8",mode:384}),ae(o,r)}function _(n,e){return{id:n.id,name:n.name,remote:n.remote,rootPath:e,createdAt:n.createdAt,updatedAt:n.updatedAt,graphVersion:n.graphVersion,memoryVersion:n.memoryVersion,metadata:n.metadata}}var f=class{detect(e=process.cwd()){let t=d(e),r=me(t),s=[".git","package.json","pyproject.toml","Cargo.toml","go.mod","composer.json"].some(m=>y(p(r,m))),a=pe(t,s?r:void 0);if(a){let m=h(a),u=ge(m);return u.rootPath!==a&&(u.rootPath=a,u.updatedAt=new Date().toISOString(),j(a,u)),_(u,a)}let S=new Date().toISOString(),x=ue(r),k={version:1,id:le(r),name:x,remote:x,rootPath:r,createdAt:S,updatedAt:S,graphVersion:0,memoryVersion:0};return j(r,k),_(k,r)}};function ye(){let n=process.cwd(),e=
|
|
10
|
+
`)}function I(n){let e=q(n);if(e===null)return{updated:!1,reason:"missing-current",chars:0};if(!e.trim())return{updated:!1,reason:"empty-current",chars:0};let t=Q(n,e);return R(n)?.text.trim()===t.trim()?{updated:!1,reason:"unchanged",chars:t.length}:(E(n,t),{updated:!0,reason:"updated",chars:t.length})}import{existsSync as Z,readFileSync as X}from"node:fs";import{homedir as ee}from"node:os";import{join as te}from"node:path";function ne(n){let e=n.trim();return e.length>=2&&e.startsWith('"')&&e.endsWith('"')?(e=e.slice(1,-1),e.replace(/\\n/g,`
|
|
11
|
+
`).replace(/\\r/g,"\r").replace(/\\t/g," ").replace(/\\"/g,'"').replace(/\\\\/g,"\\")):e.length>=2&&e.startsWith("'")&&e.endsWith("'")?e.slice(1,-1):e}function re(){let n=process.env.TOOLNET_GLOBAL_ENV??te(ee(),".config","toolnet-memory",".env");if(!Z(n))return;let e=X(n,"utf8");for(let t of e.split(/\r?\n/)){let r=t.trim();if(!r||r.startsWith("#"))continue;r.startsWith("export ")&&(r=r.slice(7));let o=r.indexOf("=");if(o<=0)continue;let s=r.slice(0,o).trim();/^[A-Za-z_][A-Za-z0-9_]*$/.test(s)&&process.env[s]===void 0&&(process.env[s]=ne(r.slice(o+1)))}}re();import{createHash as oe}from"node:crypto";import{existsSync as y,mkdirSync as se,readFileSync as ie,renameSync as ae,writeFileSync as ce}from"node:fs";import{basename as ue,dirname as l,join as p,parse as N,resolve as d}from"node:path";var P=".toolnet",de="project.json";function le(n){return oe("sha256").update(n).digest("hex").slice(0,16)}function h(n){return p(n,P,de)}function fe(n){return y(h(n))}function pe(n,e){let t=d(n),r=N(t).root;for(;;){if(fe(t))return t;if(t===r||e&&t===d(e))break;let o=l(t);if(o===t)break;t=o}return null}function me(n){let e=d(n),t=N(e).root,r=[".git","package.json","pyproject.toml","Cargo.toml","go.mod","composer.json"];for(;;){if(r.some(s=>y(p(e,s))))return e;if(e===t)break;let o=l(e);if(o===e)break;e=o}return d(n)}function ge(n){let e;try{e=JSON.parse(ie(n,"utf8"))}catch(o){throw new Error(`Invalid ToolNet project manifest: ${n}: ${o instanceof Error?o.message:String(o)}`)}if(!e||typeof e!="object")throw new Error(`Invalid ToolNet project manifest: ${n}`);let t=e;if(typeof t.id!="string"||!t.id.trim())throw new Error(`ToolNet project manifest is missing id: ${n}`);if(typeof t.name!="string"||!t.name.trim())throw new Error(`ToolNet project manifest is missing name: ${n}`);let r=new Date().toISOString();return{version:1,id:t.id,name:t.name,remote:typeof t.remote=="string"&&t.remote.trim()?t.remote:t.name,rootPath:typeof t.rootPath=="string"?t.rootPath:l(l(n)),createdAt:typeof t.createdAt=="string"?t.createdAt:r,updatedAt:typeof t.updatedAt=="string"?t.updatedAt:r,graphVersion:typeof t.graphVersion=="number"?t.graphVersion:0,memoryVersion:typeof t.memoryVersion=="number"?t.memoryVersion:0,metadata:t.metadata&&typeof t.metadata=="object"?t.metadata:void 0}}function j(n,e){let t=p(n,P);se(t,{recursive:!0});let r=h(n),o=`${r}.tmp-${process.pid}`;ce(o,JSON.stringify(e,null,2)+`
|
|
12
|
+
`,{encoding:"utf8",mode:384}),ae(o,r)}function _(n,e){return{id:n.id,name:n.name,remote:n.remote,rootPath:e,createdAt:n.createdAt,updatedAt:n.updatedAt,graphVersion:n.graphVersion,memoryVersion:n.memoryVersion,metadata:n.metadata}}var f=class{detect(e=process.cwd()){let t=d(e),r=me(t),s=[".git","package.json","pyproject.toml","Cargo.toml","go.mod","composer.json"].some(m=>y(p(r,m))),a=pe(t,s?r:void 0);if(a){let m=h(a),u=ge(m);return u.rootPath!==a&&(u.rootPath=a,u.updatedAt=new Date().toISOString(),j(a,u)),_(u,a)}let S=new Date().toISOString(),x=ue(r),k={version:1,id:le(r),name:x,remote:x,rootPath:r,createdAt:S,updatedAt:S,graphVersion:0,memoryVersion:0};return j(r,k),_(k,r)}};function ye(){let n=process.cwd(),e=T(n);if(!e){console.error("Not in a ToolNet project."),process.exitCode=1;return}let t=new f().detect(e);if(!t){console.error("Unable to detect ToolNet project."),process.exitCode=1;return}let r=I(t);console.log(JSON.stringify({project:t.name,...r},null,2))}ye();
|