toolnet-memory 0.2.16 → 0.2.17
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/bin/toolnet-memory +18 -0
- package/bundle/agy-hook.js +45 -29
- package/bundle/auto-integrate.js +64 -14
- package/bundle/codex-context.js +39 -45
- package/bundle/codex.js +60 -43
- package/bundle/context-runtime.js +95 -22
- package/bundle/handoff-refresh.js +12 -0
- package/bundle/mcp.js +50 -7
- package/bundle/memory-agent.js +49 -0
- package/bundle/memory-query.js +7 -0
- package/bundle/opencode.js +82 -34
- package/bundle/setup.js +66 -16
- package/package.json +1 -2
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import*as d from"fs";import*as u from"path";function x(r){let t=u.resolve(r),e=u.parse(t).root;for(;t!==e;){let n=u.join(t,".toolnet");if(d.existsSync(n)&&d.statSync(n).isDirectory())return t;t=u.dirname(t)}return null}import{existsSync as $,readFileSync as F}from"node:fs";import{join as D}from"node:path";import{existsSync as C,mkdirSync as be,readFileSync as I,renameSync as Ae,writeFileSync as Me}from"node:fs";import{dirname as Ee,join as j}from"node:path";function _(r){return j(r.rootPath,".toolnet","work","current.json")}function w(r){let t=_(r);if(!C(t))return null;try{let e=JSON.parse(I(t,"utf8"));return e.version!==1||e.projectId!==r.id?null:e}catch{return null}}import{existsSync as R,mkdirSync as je,readFileSync as O,renameSync as _e,writeFileSync as Re}from"node:fs";import{dirname as Pe,join as P}from"node:path";function N(r){return P(r.rootPath,".toolnet","context","session-origin.json")}function T(r){let t=N(r);if(!R(t))return null;try{let e=JSON.parse(O(t,"utf8"));return e.version!==1||e.projectId!==r.id?null:e}catch{return null}}function L(r){return r.normalize("NFKC").toLowerCase().replace(/\s+/g," ").trim()}function W(r){let t=L(r),e=/(?:agent trước|previous agent|ai trước|phiên trước)/u.test(t),n=/(?:đang làm gì|làm tới đâu|dừng ở đâu|dở ở đâu|stopped where|working on|current task|file nào|last touched|làm gì tiếp|next action|next step)/u.test(t);return e&&n?"summary":/(?:agent trước là ai|previous agent|ai trước là ai|phiên trước là ai)/u.test(t)?"previous_agent":/(?:task hiện tại|current task|đang làm gì|đang làm task nào|dở ở đâu|dừng ở đâu|stopped where)/u.test(t)?"current_task":/(?:tiếp theo|next action|next step|làm gì tiếp|phải làm gì tiếp)/u.test(t)?"next_action":/(?:file cuối|last file|file nào|đang sửa file|last touched)/u.test(t)?"last_file":/(?:blocker|vướng|kẹt|lỗi gì|blocked)/u.test(t)?"blocker":/(?:decision|quyết định|đã chốt|important decision)/u.test(t)?"decision":/(?:đã xong|completed|hoàn thành|done|todo nào xong)/u.test(t)?"completed":/(?:status|trạng thái|tiến độ|progress)/u.test(t)?"status":"summary"}function B(r){let t=D(r.rootPath,".toolnet","context","handoff.md");if(!$(t))return null;try{let e=F(t,"utf8").trim();return e||null}catch{return null}}function K(r,t=5){return r.slice(0,t).map(e=>`- ${e}`).join(`
|
|
2
|
+
`)}function b(r,t){let e=W(t),n=T(r),o=w(r);switch(e){case"previous_agent":{if(n)return{intent:e,answer:`Agent tr\u01B0\u1EDBc l\xE0 ${n.agent}. Session: ${n.nativeSessionId}.`,source:"session-origin"};break}case"current_task":{if(n?.currentTask){let s=[`Task hi\u1EC7n t\u1EA1i: ${n.currentTask}.`];return n.lastTouchedFile&&s.push(`File g\u1EA7n nh\u1EA5t: ${n.lastTouchedFile}.`),n.latestNextAction&&s.push(`Ti\u1EBFp theo: ${n.latestNextAction}.`),{intent:e,answer:s.join(" "),source:"session-origin"}}if(o?.currentTask)return{intent:e,answer:`Task hi\u1EC7n t\u1EA1i: ${o.currentTask.title} (${o.currentTask.status}).`,source:"work-state"};break}case"next_action":{let s=n?.latestNextAction??o?.nextActions?.[0];if(s)return{intent:e,answer:`Vi\u1EC7c n\xEAn l\xE0m ti\u1EBFp: ${s}.`,source:n?.latestNextAction?"session-origin":"work-state"};break}case"last_file":{let s=n?.lastTouchedFile??o?.filesTouched?.at(-1);if(s)return{intent:e,answer:`File g\u1EA7n nh\u1EA5t \u0111\u01B0\u1EE3c nh\u1EAFc ho\u1EB7c s\u1EEDa: ${s}.`,source:n?.lastTouchedFile?"session-origin":"work-state"};break}case"blocker":{let s=n?.latestBlocker??o?.blockers?.at(-1);return s?{intent:e,answer:`Blocker hi\u1EC7n t\u1EA1i: ${s}.`,source:n?.latestBlocker?"session-origin":"work-state"}:{intent:e,answer:"Hi\u1EC7n ToolNet ch\u01B0a ghi nh\u1EADn blocker n\xE0o.",source:o?"work-state":"none"}}case"decision":{let s=n?.latestDecision??o?.decisions?.at(-1);if(s)return{intent:e,answer:`Quy\u1EBFt \u0111\u1ECBnh g\u1EA7n nh\u1EA5t: ${s}.`,source:n?.latestDecision?"session-origin":"work-state"};break}case"completed":{let s=o?.tasks?.filter(c=>c.status==="completed").map(c=>c.title)??[];if(s.length)return{intent:e,answer:`C\xE1c task \u0111\xE3 ho\xE0n th\xE0nh:
|
|
3
|
+
${K(s,8)}`,source:"work-state"};break}case"status":{if(o){let s=[`Progress: ${o.progress.tasksCompleted}/${o.progress.tasksTotal} task ho\xE0n th\xE0nh.`];return o.currentTask&&s.push(`\u0110ang l\xE0m: ${o.currentTask.title}.`),o.progress.blocked>0&&s.push(`Blocked: ${o.progress.blocked}.`),{intent:e,answer:s.join(" "),source:"work-state"}}break}case"summary":{if(n||o){let s=[];n&&s.push(`Agent tr\u01B0\u1EDBc: ${n.agent}.`);let c=n?.currentTask??o?.currentTask?.title;c&&s.push(`Task hi\u1EC7n t\u1EA1i: ${c}.`);let f=n?.lastTouchedFile??o?.filesTouched?.at(-1);f&&s.push(`File g\u1EA7n nh\u1EA5t: ${f}.`);let p=n?.latestNextAction??o?.nextActions?.[0];p&&s.push(`Ti\u1EBFp theo: ${p}.`);let l=n?.latestBlocker??o?.blockers?.at(-1);l&&s.push(`Blocker: ${l}.`);let a=n?.latestDecision??o?.decisions?.at(-1);return a&&s.push(`Quy\u1EBFt \u0111\u1ECBnh g\u1EA7n nh\u1EA5t: ${a}.`),{intent:e,answer:s.join(" "),source:n?"session-origin":"work-state"}}break}}let i=B(r);if(i){let s=i.length>900?`${i.slice(0,900)}
|
|
4
|
+
[truncated]`:i;return{intent:e,answer:s,source:"handoff"}}return{intent:e,answer:"ToolNet ch\u01B0a c\xF3 \u0111\u1EE7 memory cho c\xE2u h\u1ECFi n\xE0y.",source:"none"}}import{existsSync as z,readFileSync as H}from"node:fs";import{homedir as Y}from"node:os";import{join as V}from"node:path";function U(r){let t=r.trim();return t.length>=2&&t.startsWith('"')&&t.endsWith('"')?(t=t.slice(1,-1),t.replace(/\\n/g,`
|
|
5
|
+
`).replace(/\\r/g,"\r").replace(/\\t/g," ").replace(/\\"/g,'"').replace(/\\\\/g,"\\")):t.length>=2&&t.startsWith("'")&&t.endsWith("'")?t.slice(1,-1):t}function J(){let r=process.env.TOOLNET_GLOBAL_ENV??V(Y(),".config","toolnet-memory",".env");if(!z(r))return;let t=H(r,"utf8");for(let e of t.split(/\r?\n/)){let n=e.trim();if(!n||n.startsWith("#"))continue;n.startsWith("export ")&&(n=n.slice(7));let o=n.indexOf("=");if(o<=0)continue;let i=n.slice(0,o).trim();/^[A-Za-z_][A-Za-z0-9_]*$/.test(i)&&process.env[i]===void 0&&(process.env[i]=U(n.slice(o+1)))}}J();import{createHash as G}from"node:crypto";import{existsSync as k,mkdirSync as Q,readFileSync as Z,renameSync as q,writeFileSync as X}from"node:fs";import{basename as ee,dirname as g,join as y,parse as v,resolve as m}from"node:path";var E=".toolnet",te="project.json";function re(r){return G("sha256").update(r).digest("hex").slice(0,16)}function S(r){return y(r,E,te)}function ne(r){return k(S(r))}function oe(r,t){let e=m(r),n=v(e).root;for(;;){if(ne(e))return e;if(e===n||t&&e===m(t))break;let o=g(e);if(o===e)break;e=o}return null}function se(r){let t=m(r),e=v(t).root,n=[".git","package.json","pyproject.toml","Cargo.toml","go.mod","composer.json"];for(;;){if(n.some(i=>k(y(t,i))))return t;if(t===e)break;let o=g(t);if(o===t)break;t=o}return m(r)}function ie(r){let t;try{t=JSON.parse(Z(r,"utf8"))}catch(o){throw new Error(`Invalid ToolNet project manifest: ${r}: ${o instanceof Error?o.message:String(o)}`)}if(!t||typeof t!="object")throw new Error(`Invalid ToolNet project manifest: ${r}`);let e=t;if(typeof e.id!="string"||!e.id.trim())throw new Error(`ToolNet project manifest is missing id: ${r}`);if(typeof e.name!="string"||!e.name.trim())throw new Error(`ToolNet project manifest is missing name: ${r}`);let n=new Date().toISOString();return{version:1,id:e.id,name:e.name,remote:typeof e.remote=="string"&&e.remote.trim()?e.remote:e.name,rootPath:typeof e.rootPath=="string"?e.rootPath:g(g(r)),createdAt:typeof e.createdAt=="string"?e.createdAt:n,updatedAt:typeof e.updatedAt=="string"?e.updatedAt:n,graphVersion:typeof e.graphVersion=="number"?e.graphVersion:0,memoryVersion:typeof e.memoryVersion=="number"?e.memoryVersion:0,metadata:e.metadata&&typeof e.metadata=="object"?e.metadata:void 0}}function A(r,t){let e=y(r,E);Q(e,{recursive:!0});let n=S(r),o=`${n}.tmp-${process.pid}`;X(o,JSON.stringify(t,null,2)+`
|
|
6
|
+
`,{encoding:"utf8",mode:384}),q(o,n)}function M(r,t){return{id:r.id,name:r.name,remote:r.remote,rootPath:t,createdAt:r.createdAt,updatedAt:r.updatedAt,graphVersion:r.graphVersion,memoryVersion:r.memoryVersion,metadata:r.metadata}}var h=class{detect(t=process.cwd()){let e=m(t),n=se(e),i=[".git","package.json","pyproject.toml","Cargo.toml","go.mod","composer.json"].some(l=>k(y(n,l))),s=oe(e,i?n:void 0);if(s){let l=S(s),a=ie(l);return a.rootPath!==s&&(a.rootPath=s,a.updatedAt=new Date().toISOString(),A(s,a)),M(a,s)}let c=new Date().toISOString(),f=ee(n),p={version:1,id:re(n),name:f,remote:f,rootPath:n,createdAt:c,updatedAt:c,graphVersion:0,memoryVersion:0};return A(n,p),M(p,n)}};function ce(){let r=process.argv.slice(2).join(" ").trim();if(!r){console.error('Usage: toolnet-memory ask "<question>"'),process.exitCode=1;return}let t=process.cwd(),e=x(t);if(!e){console.error("Not in a ToolNet project."),process.exitCode=1;return}let n=new h().detect(e);if(!n){console.error("Unable to detect ToolNet project."),process.exitCode=1;return}let o=b(n,r);process.stdout.write(`${o.answer}
|
|
7
|
+
`)}ce();
|