wyrm-mcp 9.2.2 → 9.2.3

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 (118) hide show
  1. package/dist/activation.js +1 -1
  2. package/dist/agent-loop.js +2 -2
  3. package/dist/audit.js +2 -2
  4. package/dist/autoconfig.js +6 -6
  5. package/dist/backup-cli.js +6 -0
  6. package/dist/backup.js +1 -0
  7. package/dist/bridge.js +1 -1
  8. package/dist/buddy-runner.js +1 -1
  9. package/dist/buddy.js +4 -4
  10. package/dist/capabilities.js +1 -1
  11. package/dist/causality.js +3 -3
  12. package/dist/cloud/cli.js +3 -3
  13. package/dist/cloud/sync-daemon-entrypoint.js +1 -1
  14. package/dist/cloud/sync-engine.js +8 -7
  15. package/dist/cloud-backup.js +4 -4
  16. package/dist/cloud-sync-entrypoint.js +1 -1
  17. package/dist/cloud-sync.js +1 -1
  18. package/dist/connectors/ingest.js +2 -2
  19. package/dist/constellation.js +1 -1
  20. package/dist/context-build-budgeted.js +4 -4
  21. package/dist/context-ranking.js +1 -1
  22. package/dist/daemon-writer.js +1 -1
  23. package/dist/database.js +41 -23
  24. package/dist/design.js +1 -1
  25. package/dist/erasure-cli.js +3 -0
  26. package/dist/erasure-log.js +8 -0
  27. package/dist/erasure.js +1 -0
  28. package/dist/event-replication.js +1 -1
  29. package/dist/events.js +11 -11
  30. package/dist/failure-patterns.js +67 -44
  31. package/dist/federation.js +11 -10
  32. package/dist/governance.js +1 -0
  33. package/dist/handlers/agent.js +4 -4
  34. package/dist/handlers/alias-adapters.js +1 -1
  35. package/dist/handlers/audit.js +1 -1
  36. package/dist/handlers/boundary.js +1 -1
  37. package/dist/handlers/capture.js +54 -52
  38. package/dist/handlers/causality.js +2 -2
  39. package/dist/handlers/cloud.js +9 -9
  40. package/dist/handlers/companion.js +4 -4
  41. package/dist/handlers/entity.js +6 -6
  42. package/dist/handlers/events.js +4 -4
  43. package/dist/handlers/failure.js +15 -12
  44. package/dist/handlers/goals.js +2 -2
  45. package/dist/handlers/intelligence.js +81 -74
  46. package/dist/handlers/mcpclient.js +3 -3
  47. package/dist/handlers/presence.js +1 -1
  48. package/dist/handlers/prompts.js +2 -2
  49. package/dist/handlers/quest.js +11 -4
  50. package/dist/handlers/recall.js +10 -10
  51. package/dist/handlers/resources.js +1 -1
  52. package/dist/handlers/review.js +3 -3
  53. package/dist/handlers/run.js +3 -3
  54. package/dist/handlers/search.js +1 -1
  55. package/dist/handlers/session.js +27 -25
  56. package/dist/handlers/share.js +3 -3
  57. package/dist/handlers/skill.js +2 -2
  58. package/dist/handlers/symbols.js +5 -5
  59. package/dist/handlers/syncops.js +2 -2
  60. package/dist/harvest.js +5 -5
  61. package/dist/hours.js +1 -1
  62. package/dist/http-auth.js +2 -2
  63. package/dist/http-fast.js +17 -17
  64. package/dist/http-projects.js +4 -0
  65. package/dist/http-rate-limit.js +1 -0
  66. package/dist/index-health.js +52 -0
  67. package/dist/index.js +2 -2
  68. package/dist/indexer.js +4 -4
  69. package/dist/intelligence.js +36 -29
  70. package/dist/lane-provenance.js +39 -0
  71. package/dist/license.js +1 -1
  72. package/dist/lineage.js +15 -0
  73. package/dist/live-embedding-state.js +2 -2
  74. package/dist/maintenance.js +2 -2
  75. package/dist/mcp-integrity.js +2 -2
  76. package/dist/memory-artifacts.js +39 -37
  77. package/dist/metabolize.js +9 -7
  78. package/dist/metrics.js +1 -1
  79. package/dist/migrate-prompt.js +1 -1
  80. package/dist/migrations.js +236 -45
  81. package/dist/priority-embed.js +1 -1
  82. package/dist/providers/embedding-provider.js +1 -1
  83. package/dist/readonly-gate.js +1 -1
  84. package/dist/redact-backfill.js +1 -0
  85. package/dist/rehydration.js +30 -20
  86. package/dist/reindex.js +1 -1
  87. package/dist/render-target.js +6 -6
  88. package/dist/repl-guard.js +1 -1
  89. package/dist/replication-daemon-entrypoint.js +1 -1
  90. package/dist/replication-daemon.js +1 -1
  91. package/dist/retention.js +1 -0
  92. package/dist/reverse-bridge.js +6 -6
  93. package/dist/review-sample.js +31 -0
  94. package/dist/security.js +1 -1
  95. package/dist/self-maintenance.js +4 -4
  96. package/dist/served-records.js +8 -2
  97. package/dist/setup-wizard.js +1 -1
  98. package/dist/setup.js +1 -1
  99. package/dist/skill-author.js +2 -2
  100. package/dist/store-open.js +1 -0
  101. package/dist/store-readonly.js +1 -0
  102. package/dist/sub-agent.js +2 -2
  103. package/dist/tool-manifest-v2.json +1 -1
  104. package/dist/tool-manifest.json +1 -1
  105. package/dist/truth-freshness.js +8 -0
  106. package/dist/ui-dashboard.js +4 -4
  107. package/dist/vault.js +1 -1
  108. package/dist/vector-init.js +1 -1
  109. package/dist/vectors.js +4 -3
  110. package/dist/visibility.js +12 -12
  111. package/dist/write-guard.js +1 -0
  112. package/dist/wyrm-cli.js +108 -92
  113. package/dist/wyrm-guard.js +13 -12
  114. package/dist/wyrm-loop.js +3 -3
  115. package/dist/wyrm-manifest.json +1 -1
  116. package/dist/wyrm-memo.js +5 -5
  117. package/package.json +1 -1
  118. package/scripts/hooks/wyrm-session-capture.mjs +3 -0
@@ -1,18 +1,19 @@
1
1
  #!/usr/bin/env node
2
- import{openDatabase as k}from"./storage/index.js";import{readFileSync as U,realpathSync as Y,appendFileSync as z,statSync as j,unlinkSync as B}from"node:fs";import{homedir as v}from"node:os";import{basename as F,dirname as V,isAbsolute as C,join as R,relative as H,resolve as N,sep as q}from"node:path";import{fileURLToPath as Z}from"node:url";import{FailurePatterns as T,normalizeIdentity as x,canonicalizeCommand as I,STALE_ANCHOR_FLAG as J}from"./failure-patterns.js";import{LEGACY_ENVELOPE as K,runWithActor as X,sanitizeActorId as W}from"./handlers/boundary.js";import{resolveProjectForPath as Q}from"./project-resolve.js";const w={exitCode:0,stdout:"",stderr:""},tt=Number(process.env.WYRM_GUARD_SLOW_MS??1500),et=64*1024;function nt(t,e,c){if(!(!Number.isFinite(t)||t<tt)&&(c.WYRM_GUARD_TRACE??"")!=="0")try{const a=R(v(),".wyrm"),o=R(a,"guard-slow.log");try{j(o).size>et&&B(o)}catch{}z(o,`${new Date().toISOString()} ${Math.round(t)}ms ${e}
3
- `,{mode:384})}catch{}}function G(t){const e=[],c=i=>{const s=i.trim();s&&s.length<=1e3&&!e.includes(s)&&e.push(s)},a=[];let o="",r=null;for(let i=0;i<t.length;i++){const s=t[i];if(r){o+=s,s===r&&t[i-1]!=="\\"&&(r=null);continue}if(s==="'"||s==='"'){r=s,o+=s;continue}const h=t.slice(i,i+2);if(h==="&&"||h==="||"){a.push(o),o="",i++;continue}if(s===";"||s==="|"||s===`
4
- `){a.push(o),o="";continue}o+=s}a.push(o);for(const i of a){c(i);let s=i.trim(),h=!1;for(let u=0;u<8;u++){const f=s.match(/^(?:sudo(?:\s+-[A-Za-z]+)*|doas|time|nohup|exec|command|stdbuf(?:\s+-\S+)*|env|[A-Za-z_][A-Za-z0-9_]*=(?:"[^"]*"|'[^']*'|\S*))\s+/);if(!f)break;s=s.slice(f[0].length).trim(),h=!0}h&&c(s);const p=s.match(/^(?:ba|z|k)?sh\s+-c\s+(['"])([\s\S]*)\1\s*$/);if(p)for(const u of G(p[2]))c(u)}return e}const rt=new Set(["Edit","Write","MultiEdit","NotebookEdit"]),ot=3;function g(t){return typeof t=="string"&&t.length>0?t:null}function _(t,e){return t?t.replace(/[\x00-\x1f\x7f]/g," ").replace(/\s+/g," ").trim().slice(0,e):""}function st(t){const e=t.hook_event_name;if(e!==void 0&&e!=="PreToolUse")return null;const c=t.tool_name,a=t.tool_input;if(typeof c!="string"||typeof a!="object"||a===null)return null;const o=a,r=g(t.cwd);if(c==="Bash"){const i=g(o.command)?.trim();if(!i)return null;const s=i.slice(0,1e3);return{scopes:["command"],probeTarget:s,identity:G(i),display:_(s,80),startDir:r,absPath:null}}if(rt.has(c)){const i=g(o.file_path)??g(o.notebook_path);if(!i)return null;const s=o.edits,h=g(o.new_string)??g(o.content)??g(o.new_source)??(Array.isArray(s)?s.map(u=>g(u?.new_string)??"").join(" "):""),p=C(i)?N(i):r&&C(r)?N(r,i):null;return{scopes:["file","edit"],probeTarget:F(i).slice(0,200),identity:L([i,...p?[p]:[]]),display:_(i,80),startDir:p?V(p):r,absPath:p,content:h}}return null}function L(t){const e=new Set,c=[];for(const a of t){const o=x(a);o.length===0||e.has(o)||(e.add(o),c.push(a))}return c}function ct(t){if(t.recorded_by_agent==="legacy"&&t.run_id===null)return"";const e=t.run_id?` (run ${_(t.run_id,32)}${t.quarantine_scope==="run"?", run-quarantined":""})`:"";return` recorded by: ${_(t.recorded_by_agent,64)}${e}
5
- `}function it(t,e,c){const a=t.description?` description: ${_(t.description,200)}
2
+ import{openDatabase as P}from"./storage/index.js";import{openStoreForWrite as U}from"./store-open.js";import{readFileSync as Y,realpathSync as z,appendFileSync as F,statSync as j,unlinkSync as q}from"node:fs";import{homedir as k}from"node:os";import{basename as B,dirname as V,isAbsolute as v,join as R,relative as H,resolve as C,sep as Z}from"node:path";import{fileURLToPath as J}from"node:url";import{FailurePatterns as N,normalizeIdentity as x,canonicalizeCommand as T,STALE_ANCHOR_FLAG as K}from"./failure-patterns.js";import{LEGACY_ENVELOPE as X,runWithActor as Q,sanitizeActorId as W}from"./handlers/boundary.js";import{resolveProjectForPath as tt}from"./project-resolve.js";const w={exitCode:0,stdout:"",stderr:""},et=Number(process.env.WYRM_GUARD_SLOW_MS??1500),nt=64*1024;function rt(t,n,i){if(!(!Number.isFinite(t)||t<et)&&(i.WYRM_GUARD_TRACE??"")!=="0")try{const a=R(k(),".wyrm"),o=R(a,"guard-slow.log");try{j(o).size>nt&&q(o)}catch{}F(o,`${new Date().toISOString()} ${Math.round(t)}ms ${n}
3
+ `,{mode:384})}catch{}}function I(t){const n=[],i=c=>{const s=c.trim();s&&s.length<=1e3&&!n.includes(s)&&n.push(s)},a=[];let o="",r=null;for(let c=0;c<t.length;c++){const s=t[c];if(r){o+=s,s===r&&t[c-1]!=="\\"&&(r=null);continue}if(s==="'"||s==='"'){r=s,o+=s;continue}const h=t.slice(c,c+2);if(h==="&&"||h==="||"){a.push(o),o="",c++;continue}if(s===";"||s==="|"||s===`
4
+ `){a.push(o),o="";continue}o+=s}a.push(o);for(const c of a){i(c);let s=c.trim(),h=!1;for(let u=0;u<8;u++){const f=s.match(/^(?:sudo(?:\s+-[A-Za-z]+)*|doas|time|nohup|exec|command|stdbuf(?:\s+-\S+)*|env|[A-Za-z_][A-Za-z0-9_]*=(?:"[^"]*"|'[^']*'|\S*))\s+/);if(!f)break;s=s.slice(f[0].length).trim(),h=!0}h&&i(s);const p=s.match(/^(?:ba|z|k)?sh\s+-c\s+(['"])([\s\S]*)\1\s*$/);if(p)for(const u of I(p[2]))i(u)}return n}const ot=new Set(["Edit","Write","MultiEdit","NotebookEdit"]),st=3;function g(t){return typeof t=="string"&&t.length>0?t:null}function _(t,n){return t?t.replace(/[\x00-\x1f\x7f]/g," ").replace(/\s+/g," ").trim().slice(0,n):""}function it(t){const n=t.hook_event_name;if(n!==void 0&&n!=="PreToolUse")return null;const i=t.tool_name,a=t.tool_input;if(typeof i!="string"||typeof a!="object"||a===null)return null;const o=a,r=g(t.cwd);if(i==="Bash"){const c=g(o.command)?.trim();if(!c)return null;const s=c.slice(0,1e3);return{scopes:["command"],probeTarget:s,identity:I(c),display:_(s,80),startDir:r,absPath:null}}if(ot.has(i)){const c=g(o.file_path)??g(o.notebook_path);if(!c)return null;const s=o.edits,h=g(o.new_string)??g(o.content)??g(o.new_source)??(Array.isArray(s)?s.map(u=>g(u?.new_string)??"").join(" "):""),p=v(c)?C(c):r&&v(r)?C(r,c):null;return{scopes:["file","edit"],probeTarget:B(c).slice(0,200),identity:G([c,...p?[p]:[]]),display:_(c,80),startDir:p?V(p):r,absPath:p,content:h}}return null}function G(t){const n=new Set,i=[];for(const a of t){const o=x(a);o.length===0||n.has(o)||(n.add(o),i.push(a))}return i}function ct(t){if(t.recorded_by_agent==="legacy"&&t.run_id===null)return"";const n=t.run_id?` (run ${_(t.run_id,32)}${t.quarantine_scope==="run"?", run-quarantined":""})`:"";return` recorded by: ${_(t.recorded_by_agent,64)}${n}
5
+ `}function at(t,n,i){const a=t.description?` description: ${_(t.description,200)}
6
6
  `:"",o=t.why_failed?` failed because: ${_(t.why_failed,300)}
7
- `:"";return`wyrm-guard: BLOCKED \u2014 ${e==="exact"?"this exact action is a recorded unresolved failure":e==="content"?"this edit re-introduces the code of a recorded unresolved failure":e==="canonical"?"this command is equivalent (flags reordered / =-normalized) to a recorded unresolved failure":"this exact target previously failed and the failure is unresolved"} (deterministic ${e} match).
7
+ `:"";return`wyrm-guard: BLOCKED because ${n==="exact"?"this exact action is a recorded unresolved failure":n==="content"?"this edit re-introduces the code of a recorded unresolved failure":n==="canonical"?"this command is equivalent (flags reordered / =-normalized) to a recorded unresolved failure":"this exact target previously failed and the failure is unresolved"} (deterministic ${n} match).
8
8
  failure #${t.id} [${t.severity}/${t.scope}] seen ${t.occurrences}x, last ${_(t.last_seen,32)}
9
9
  target: ${_(t.target,120)}
10
- `+a+o+ct(t)+`Do NOT retry the same action \u2014 pick a different approach. If the underlying
10
+ `+a+o+ct(t)+`Do NOT retry the same action; pick a different approach. If the underlying
11
11
  issue is truly fixed, resolve the failure first (wyrm_failure_resolve id=${t.id})
12
12
  and then retry.
13
- `+(c>0?`(+${c} more recorded match${c===1?"":"es"} \u2014 wyrm_failure_list)
14
- `:"")}function at(t,e){const c=t.slice(0,ot),a=c.map(r=>{const i=r.why_failed??r.description;return`- #${r.id} [${r.severity}/${r.scope}] ${_(r.target,80)} (seen ${r.occurrences}x, confidence ${r.confidence}): ${_(i,160)}`+(r.stale_anchor?`
15
- stale_anchor: ${r.stale_anchor}`:"")}),o=t.length-c.length;return["<wyrm-memory>",`wyrm-guard: ${t.length} recorded unresolved failure(s) look similar to \`${e}\` \u2014 check before proceeding:`,...a,...o>0?[`(+${o} more \u2014 wyrm_failure_list)`]:[],"If one applies, do not repeat it \u2014 adjust the approach or resolve it first (wyrm_failure_resolve).","</wyrm-memory>"].join(`
16
- `)}function lt(t,e){const c={hookSpecificOutput:{hookEventName:"PreToolUse",additionalContext:at(t,e)}};return{exitCode:0,stdout:JSON.stringify(c)+`
17
- `,stderr:""}}function dt(t,e=process.env){const c=Date.now(),a=ut(t,e);return nt(Date.now()-c,a.exitCode===2?"blocked":"allowed",e),a}function ut(t,e=process.env){let c=null;try{const a=(e.WYRM_GUARD_MODE??"block").toLowerCase();if(a==="off"||!t||!t.trim())return w;const o=JSON.parse(t);if(typeof o!="object"||o===null)return w;const r=st(o);if(!r)return w;const i=e.WYRM_DB_PATH??R(v(),".wyrm","wyrm.db");c=k(i,{readonly:!0,fileMustExist:!0}),c.pragma("busy_timeout = 100");const{id:s,root:h}=Q(c,r.startDir),p=[...r.identity];h&&r.absPath&&r.absPath.startsWith(h+q)&&p.push(H(h,r.absPath));const u=W(e.WYRM_RUN_ID)??null,f=new T(c),m=new Set,y=[],b=L(p);for(const n of r.scopes)try{const l=f.checkVerdict(n,r.probeTarget,"",s,{callerRunId:u});for(const d of l.matches)m.has(d.id)||(m.add(d.id),y.push(d))}catch{}for(const n of r.scopes)for(const l of b)try{for(const d of f.targetIdentityMatches(n,l,s,{callerRunId:u}))m.has(d.id)||(m.add(d.id),y.push(f.toVerdictMatch(d,"target")))}catch{}if(!/^(0|false|no|off)$/i.test(e.WYRM_GUARD_CANONICAL??""))for(const n of r.scopes)for(const l of b)try{for(const d of f.canonicalMatches(n,l,s,{callerRunId:u}))m.has(d.id)||(m.add(d.id),y.push(f.toVerdictMatch(d,"canonical")))}catch{}if(!/^(0|false|no|off)$/i.test(e.WYRM_GUARD_RELATED??""))for(const n of r.scopes)for(const l of b)try{for(const d of f.commandHeadFamily(n,l,s,{callerRunId:u}))m.has(d.id)||(m.add(d.id),y.push(f.toVerdictMatch(d,"related")))}catch{}let $=null;if(r.content&&r.scopes.includes("edit")&&/^(1|true|yes|on)$/i.test(e.WYRM_GUARD_CONTENT??""))try{const n=f.contentMatch(r.content,"edit",s);n&&!m.has(n.id)&&(m.add(n.id),$=f.toVerdictMatch(n,"target"))}catch{}if(y.length===0&&!$)return w;const O=new Set(b.map(n=>x(n))),P=new Set(r.scopes.includes("command")?b.map(n=>I(n)).filter(n=>n.length>0):[]),D={exact:0,target:1,canonical:2,content:3},A=[...y.map(n=>({m:n,reason:n.match==="exact"?"exact":n.match==="target"||O.has(x(n.target))?"target":n.match==="canonical"||n.scope==="command"&&n.match!=="related"&&P.has(I(n.target))?"canonical":null})).filter(n=>n.reason!==null),...$?[{m:$,reason:"content"}]:[]].sort((n,l)=>D[n.reason]-D[l.reason]);let S=A,E=y;if(A.length>0)try{const n=f.staleAnchorIds(A.filter(l=>l.reason!=="content").map(l=>l.m),h);n.size>0&&(S=A.filter(l=>!n.has(l.m.id)),E=y.map(l=>n.has(l.id)?{...l,stale_anchor:J}:l))}catch{}if(S.length>0&&a!=="warn"){const n=S[0];try{const l=k(i,{fileMustExist:!0});try{l.pragma("busy_timeout = 50");const d=W(e.WYRM_AGENT_ID);X(d!==null||u!==null?{agent_id:d,run_id:u,source:"env"}:K,()=>new T(l).recordBlock({blocked:!0,matches:[n.m],recorded_by_agent:n.m.recorded_by_agent,run_id:n.m.run_id,confidence:n.m.confidence},s))}finally{l.close()}}catch{}return{exitCode:2,stdout:"",stderr:it(n.m,n.reason,y.length-1)}}return lt(E,r.display)}catch(a){if(e.WYRM_GUARD_DEBUG==="1"){const o=a instanceof Error?a.message:String(a);return{exitCode:0,stdout:"",stderr:`wyrm-guard: internal error (fail-open): ${_(o,200)}
18
- `}}return w}finally{try{c?.close()}catch{}}}const ft=Z(import.meta.url);let M=!1;try{M=typeof process.argv[1]=="string"&&Y(process.argv[1])===ft}catch{M=!1}if(M){let t="";try{t=U(0,"utf-8")}catch{t=""}const e=dt(t);e.stdout&&process.stdout.write(e.stdout),e.stderr&&process.stderr.write(e.stderr),process.exit(e.exitCode)}export{G as commandSegments,dt as runGuard};
13
+ `+(i>0?`(+${i} more recorded match${i===1?"":"es"} via wyrm_failure_list)
14
+ `:"")}function dt(t,n){const i=t.slice(0,st),a=i.map(r=>{const c=r.why_failed??r.description;return`- #${r.id} [${r.severity}/${r.scope}] ${_(r.target,80)} (seen ${r.occurrences}x, confidence ${r.confidence}): ${_(c,160)}`+(r.stale_anchor?`
15
+ stale_anchor: ${r.stale_anchor}`:"")+(r.quiet_downgrade?`
16
+ quiet_downgrade: ${r.quiet_downgrade}`:"")}),o=t.length-i.length;return["<wyrm-memory>",`wyrm-guard: ${t.length} recorded unresolved failure(s) look similar to \`${n}\`; check before proceeding:`,...a,...o>0?[`(+${o} more via wyrm_failure_list)`]:[],"If one applies, do not repeat it; adjust the approach or resolve it first (wyrm_failure_resolve).","</wyrm-memory>"].join(`
17
+ `)}function lt(t,n){const i={hookSpecificOutput:{hookEventName:"PreToolUse",additionalContext:dt(t,n)}};return{exitCode:0,stdout:JSON.stringify(i)+`
18
+ `,stderr:""}}function ut(t,n=process.env){const i=Date.now(),a=ft(t,n);return rt(Date.now()-i,a.exitCode===2?"blocked":"allowed",n),a}function ft(t,n=process.env){let i=null;try{const a=(n.WYRM_GUARD_MODE??"block").toLowerCase();if(a==="off"||!t||!t.trim())return w;const o=JSON.parse(t);if(typeof o!="object"||o===null)return w;const r=it(o);if(!r)return w;const c=n.WYRM_DB_PATH??R(k(),".wyrm","wyrm.db");i=P(c,{readonly:!0,fileMustExist:!0}),i.pragma("busy_timeout = 100");const{id:s,root:h}=tt(i,r.startDir),p=[...r.identity];h&&r.absPath&&r.absPath.startsWith(h+Z)&&p.push(H(h,r.absPath));const u=W(n.WYRM_RUN_ID)??null,f=new N(i),m=new Set,y=[],b=G(p);for(const e of r.scopes)try{const d=f.checkVerdict(e,r.probeTarget,"",s,{callerRunId:u});for(const l of d.matches)m.has(l.id)||(m.add(l.id),y.push(l))}catch{}for(const e of r.scopes)for(const d of b)try{for(const l of f.targetIdentityMatches(e,d,s,{callerRunId:u}))m.has(l.id)||(m.add(l.id),y.push(f.toVerdictMatch(l,"target")))}catch{}if(!/^(0|false|no|off)$/i.test(n.WYRM_GUARD_CANONICAL??""))for(const e of r.scopes)for(const d of b)try{for(const l of f.canonicalMatches(e,d,s,{callerRunId:u}))m.has(l.id)||(m.add(l.id),y.push(f.toVerdictMatch(l,"canonical")))}catch{}if(!/^(0|false|no|off)$/i.test(n.WYRM_GUARD_RELATED??""))for(const e of r.scopes)for(const d of b)try{for(const l of f.commandHeadFamily(e,d,s,{callerRunId:u}))m.has(l.id)||(m.add(l.id),y.push(f.toVerdictMatch(l,"related")))}catch{}let S=null;if(r.content&&r.scopes.includes("edit")&&/^(1|true|yes|on)$/i.test(n.WYRM_GUARD_CONTENT??""))try{const e=f.contentMatch(r.content,"edit",s);e&&!m.has(e.id)&&(m.add(e.id),S=f.toVerdictMatch(e,"target"))}catch{}if(y.length===0&&!S)return w;const L=new Set(b.map(e=>x(e))),O=new Set(r.scopes.includes("command")?b.map(e=>T(e)).filter(e=>e.length>0):[]),D={exact:0,target:1,canonical:2,content:3},A=[...y.map(e=>({m:e,reason:e.match==="exact"?"exact":e.match==="target"||L.has(x(e.target))?"target":e.match==="canonical"||e.scope==="command"&&e.match!=="related"&&O.has(T(e.target))?"canonical":null})).filter(e=>e.reason!==null),...S?[{m:S,reason:"content"}]:[]].sort((e,d)=>D[e.reason]-D[d.reason]);let $=A,E=y;if(A.length>0)try{const e=f.staleAnchorIds(A.filter(d=>d.reason!=="content").map(d=>d.m),h);e.size>0&&($=A.filter(d=>!e.has(d.m.id)),E=y.map(d=>e.has(d.id)?{...d,stale_anchor:K}:d))}catch{}if($=$.filter(e=>!e.m.quiet_downgrade),$.length>0&&a!=="warn"){const e=$[0];try{const d=U(c,{fileMustExist:!0},n);try{d.pragma("busy_timeout = 50");const l=W(n.WYRM_AGENT_ID);Q(l!==null||u!==null?{agent_id:l,run_id:u,source:"env"}:X,()=>new N(d).recordBlock({blocked:!0,matches:[e.m],recorded_by_agent:e.m.recorded_by_agent,run_id:e.m.run_id,confidence:e.m.confidence},s))}finally{d.close()}}catch{}return{exitCode:2,stdout:"",stderr:at(e.m,e.reason,y.length-1)}}return lt(E,r.display)}catch(a){if(n.WYRM_GUARD_DEBUG==="1"){const o=a instanceof Error?a.message:String(a);return{exitCode:0,stdout:"",stderr:`wyrm-guard: internal error (fail-open): ${_(o,200)}
19
+ `}}return w}finally{try{i?.close()}catch{}}}const ht=J(import.meta.url);let M=!1;try{M=typeof process.argv[1]=="string"&&z(process.argv[1])===ht}catch{M=!1}if(M){let t="";try{t=Y(0,"utf-8")}catch{t=""}const n=ut(t);n.stdout&&process.stdout.write(n.stdout),n.stderr&&process.stderr.write(n.stderr),process.exit(n.exitCode)}export{I as commandSegments,ut as runGuard};
package/dist/wyrm-loop.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import{WyrmDB as f}from"./database.js";import{Goals as d}from"./goals.js";import{AgentLoop as h}from"./agent-loop.js";import{OutboundMcpClient as w}from"./mcp-client.js";import{makeInternalDispatch as g}from"./internal-dispatch.js";import{FailurePatterns as y}from"./failure-patterns.js";import{SymbolGraph as x}from"./symbols.js";import{Rehydration as $}from"./rehydration.js";import{Causality as v}from"./causality.js";import{AgentPresence as S}from"./presence.js";import{Federation as b}from"./federation.js";import{MemoryArtifacts as D}from"./memory-artifacts.js";import{GroundTruths as I}from"./intelligence.js";import{wireTruthAutoCascade as P}from"./truth-cascade.js";function j(e){const t={interval:600,once:!1,maxSteps:3,verbose:process.env.WYRM_LOOP_LOG==="1"};for(let n=0;n<e.length;n++){const r=e[n];r==="--interval"?t.interval=Math.max(10,parseInt(e[++n],10)||600):r==="--once"?t.once=!0:r==="--goal"?t.goalId=parseInt(e[++n],10):r==="--max-steps"?t.maxSteps=Math.max(1,Math.min(20,parseInt(e[++n],10)||3)):r==="--project"?t.projectPath=e[++n]:r==="--verbose"||r==="-v"?t.verbose=!0:(r==="--help"||r==="-h")&&(console.log(A),process.exit(0))}return t}const A=`
3
- wyrm-loop \u2014 autonomous OODA scheduler
2
+ import{WyrmDB as d}from"./database.js";import{Goals as h}from"./goals.js";import{AgentLoop as w}from"./agent-loop.js";import{OutboundMcpClient as g}from"./mcp-client.js";import{makeInternalDispatch as v}from"./internal-dispatch.js";import{FailurePatterns as y}from"./failure-patterns.js";import{SymbolGraph as S}from"./symbols.js";import{Rehydration as x}from"./rehydration.js";import{Causality as $}from"./causality.js";import{AgentPresence as b}from"./presence.js";import{Federation as D}from"./federation.js";import{MemoryArtifacts as I}from"./memory-artifacts.js";import{GroundTruths as P}from"./intelligence.js";import{wireTruthAutoCascade as O}from"./truth-cascade.js";import{scheduleMaintenanceSweep as M}from"./self-maintenance.js";import{createVectorStore as j}from"./vectors.js";import{resolveEmbeddingState as A}from"./providers/embedding-provider.js";function R(e){const t={interval:600,once:!1,maxSteps:3,verbose:process.env.WYRM_LOOP_LOG==="1"};for(let n=0;n<e.length;n++){const r=e[n];r==="--interval"?t.interval=Math.max(10,parseInt(e[++n],10)||600):r==="--once"?t.once=!0:r==="--goal"?t.goalId=parseInt(e[++n],10):r==="--max-steps"?t.maxSteps=Math.max(1,Math.min(20,parseInt(e[++n],10)||3)):r==="--project"?t.projectPath=e[++n]:r==="--verbose"||r==="-v"?t.verbose=!0:(r==="--help"||r==="-h")&&(console.log(T),process.exit(0))}return t}const T=`
3
+ wyrm-loop: autonomous OODA scheduler
4
4
 
5
5
  wyrm-loop [options]
6
6
 
@@ -12,4 +12,4 @@ Options
12
12
  --project PATH Scope to a project root
13
13
  --verbose, -v Log every tick to stderr
14
14
  --help, -h Show this help
15
- `;function a(e,t){e.verbose&&console.error(`[wyrm-loop ${new Date().toISOString()}] ${t}`)}async function O(e,t,n,r){let o=e.goalId;if(!o){let m;if(e.projectPath){const p=t.getProject(e.projectPath);if(!p)return a(e,`project '${e.projectPath}' not registered \u2014 idle`),!1;m=p.id}const l=n.nextToPursue(m);if(!l)return a(e,"no active goals \u2014 idle"),!1;o=l.id}const i=n.get(o);if(!i||i.status!=="active")return a(e,`goal #${o} not active \u2014 skipping`),!1;a(e,`pursuing goal #${o}: ${i.title.slice(0,80)}`);const s=await r.pursue(o,{max_steps:e.maxSteps});if(s.length===0)return a(e,`goal #${o} returned no iterations`),!1;const c=s[s.length-1];return a(e,`goal #${o} ran ${s.length} iteration(s); last outcome=${c.outcome} (${c.latency_ms}ms, model=${c.model}${c.degraded?" DEGRADED":""})`),!0}async function M(){const e=j(process.argv.slice(2)),t=new f(process.env.WYRM_DB_PATH),n=new d(t.getDatabase()),r=new w(t.getDatabase()),o=t.getDatabase(),i=new I(o),s=new v(o);P(i,s);const c=g({db:t,failures:new y(o),symbols:new x(o),rehydration:new $(o),causality:s,presence:new S(o),federation:new b(o),memory:new D(o),groundTruths:i}),m=new h(o,r,c);let l=!1;const p=()=>{l||(l=!0,a(e,"shutting down\u2026"),r.shutdown().finally(()=>{try{t.close()}catch{}process.exit(0)}))};for(process.on("SIGINT",p),process.on("SIGTERM",p),e.verbose&&console.error(`wyrm-loop starting \xB7 interval=${e.interval}s \xB7 once=${e.once} \xB7 max-steps=${e.maxSteps}`);!l;){try{await O(e,t,n,m)}catch(u){console.error(`wyrm-loop tick error: ${u.message}`)}if(e.once){p();return}await new Promise(u=>{setTimeout(u,e.interval*1e3)})}}M().catch(e=>{console.error(`wyrm-loop fatal: ${e.message}`),process.exit(1)});
15
+ `;function a(e,t){e.verbose&&console.error(`[wyrm-loop ${new Date().toISOString()}] ${t}`)}async function k(e,t,n,r){let o=e.goalId;if(!o){let u;if(e.projectPath){const m=t.getProject(e.projectPath);if(!m)return a(e,`project '${e.projectPath}' not registered; idle`),!1;u=m.id}const p=n.nextToPursue(u);if(!p)return a(e,"no active goals; idle"),!1;o=p.id}const c=n.get(o);if(!c||c.status!=="active")return a(e,`goal #${o} not active; skipping`),!1;a(e,`pursuing goal #${o}: ${c.title.slice(0,80)}`);const i=await r.pursue(o,{max_steps:e.maxSteps});if(i.length===0)return a(e,`goal #${o} returned no iterations`),!1;const l=i[i.length-1];return a(e,`goal #${o} ran ${i.length} iteration(s); last outcome=${l.outcome} (${l.latency_ms}ms, model=${l.model}${l.degraded?" DEGRADED":""})`),!0}async function E(){const e=R(process.argv.slice(2)),t=new d(process.env.WYRM_DB_PATH),n=new h(t.getDatabase()),r=new g(t.getDatabase()),o=t.getDatabase(),c=new P(o),i=new $(o);O(c,i);const l=v({db:t,failures:new y(o),symbols:new S(o),rehydration:new x(o),causality:i,presence:new b(o),federation:new D(o),memory:new I(o),groundTruths:c}),u=new w(o,r,l);let p=!1;const m=()=>{p||(p=!0,a(e,"shutting down\u2026"),r.shutdown().finally(()=>{try{t.close()}catch{}process.exit(0)}))};if(process.on("SIGINT",m),process.on("SIGTERM",m),!e.once){let s;M(t,process.env,{vectors:()=>{if(s===void 0){s=null;try{const f=process.env.WYRM_VECTOR_PROVIDER||"auto";A(f).resolved!=="none"&&(s=j({provider:f},o))}catch{s=null}}return s}})}for(e.verbose&&console.error(`wyrm-loop starting \xB7 interval=${e.interval}s \xB7 once=${e.once} \xB7 max-steps=${e.maxSteps}`);!p;){try{await k(e,t,n,u)}catch(s){console.error(`wyrm-loop tick error: ${s.message}`)}if(e.once){m();return}await new Promise(s=>{setTimeout(s,e.interval*1e3)})}}E().catch(e=>{console.error(`wyrm-loop fatal: ${e.message}`),process.exit(1)});
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "contract": "wyrm-cloud-memory-v1",
3
- "version": "9.2.2",
3
+ "version": "9.2.3",
4
4
  "generatedBy": "scripts/gen-tool-manifest.mjs (from the dist/ registry modules — never hand-edited)",
5
5
  "tiers": {
6
6
  "core": [
package/dist/wyrm-memo.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import{readFileSync as _,realpathSync as U,statSync as D}from"node:fs";import{homedir as O}from"node:os";import{dirname as v,join as A}from"node:path";import{fileURLToPath as L}from"node:url";import{openDatabase as h}from"./storage/index.js";import{logSavings as N}from"./statusline.js";import{resolveProjectForPath as R}from"./project-resolve.js";import{ReadMemos as y,distill as C,estimateTokens as E,isExpired as F,isProbablyText as I,readTarget as B,sha256Hex as T}from"./read-memo.js";const e={exitCode:0,stdout:"",stderr:""},W=6e3,j=7,k=2e6;function M(s,t,n){const r=Number(s[t]);return Number.isFinite(r)&&r>=0?r:n}function z(s,t){return["<wyrm-memory>",`wyrm-memo: you already read this exact file in full (unchanged since ${s} UTC). Its map:`,t,"</wyrm-memory>"].join(`
3
- `)}function H(s,t=process.env){let n=null,r=null;try{const i=(t.WYRM_MEMO_MODE??"observe").toLowerCase();if(i==="off"||!s||!s.trim())return e;const l=JSON.parse(s);if(typeof l!="object"||l===null)return e;const m=l,u=m.hook_event_name;if(u!=="PreToolUse"&&u!=="PostToolUse")return e;const o=B(m);if(!o)return e;const c=D(o.absPath);if(!c.isFile()||c.size>M(t,"WYRM_MEMO_MAX_BYTES",k))return e;const f=t.WYRM_DB_PATH??A(O(),".wyrm","wyrm.db"),P=typeof m.session_id=="string"?m.session_id.slice(0,64):null;if(u==="PostToolUse"){const d=_(o.absPath);if(!I(d))return e;const p=d.toString("utf8"),w=p.length===0?0:p.split(`
4
- `).length,x=C(p,o.absPath);r=h(f,{fileMustExist:!0}),r.pragma("busy_timeout = 50");const{id:Y}=R(r,v(o.absPath));return new y(r).upsert({path:o.absPath,sha256:T(d),bytes:c.size,lines:w,distilled:x,tool:o.tool,projectId:Y,sessionId:P}),e}if(c.size<M(t,"WYRM_MEMO_MIN_BYTES",W))return e;n=h(f,{readonly:!0,fileMustExist:!0}),n.pragma("busy_timeout = 100");const a=new y(n).get(o.absPath);if(!a||F(a.last_seen,M(t,"WYRM_MEMO_TTL_DAYS",j))||T(_(o.absPath))!==a.sha256)return e;const g=Math.max(0,E(c.size)-E(a.distilled.length));try{r=h(f,{fileMustExist:!0}),r.pragma("busy_timeout = 50"),new y(r).recordHit(o.absPath,g),N(r,"wyrm-memo","cached_preamble",g,void 0,"conservative")}catch{}if(i!=="warn")return e;const S={hookSpecificOutput:{hookEventName:"PreToolUse",additionalContext:z(a.last_seen,a.distilled)}};return{exitCode:0,stdout:JSON.stringify(S)+`
5
- `,stderr:""}}catch(i){return t.WYRM_MEMO_DEBUG==="1"?{exitCode:0,stdout:"",stderr:`wyrm-memo: internal error (fail-open): ${(i instanceof Error?i.message:String(i)).slice(0,200)}
6
- `}:e}finally{try{n?.close()}catch{}try{r?.close()}catch{}}}const J=L(import.meta.url);let b=!1;try{b=typeof process.argv[1]=="string"&&U(process.argv[1])===J}catch{b=!1}if(b){let s="";try{s=_(0,"utf-8")}catch{s=""}const t=H(s);t.stdout&&process.stdout.write(t.stdout),t.stderr&&process.stderr.write(t.stderr),process.exit(t.exitCode)}export{H as runMemo};
2
+ import{readFileSync as _,realpathSync as U,statSync as D}from"node:fs";import{homedir as O}from"node:os";import{dirname as A,join as F}from"node:path";import{fileURLToPath as L}from"node:url";import{openDatabase as N}from"./storage/index.js";import{openStoreForWrite as g}from"./store-open.js";import{logSavings as R}from"./statusline.js";import{resolveProjectForPath as C}from"./project-resolve.js";import{ReadMemos as h,distill as I,estimateTokens as E,isExpired as W,isProbablyText as v,readTarget as B,sha256Hex as T}from"./read-memo.js";const e={exitCode:0,stdout:"",stderr:""},j=6e3,k=7,z=2e6;function y(o,t,i){const r=Number(o[t]);return Number.isFinite(r)&&r>=0?r:i}function H(o,t){return["<wyrm-memory>",`wyrm-memo: you already read this exact file in full (unchanged since ${o} UTC). Its map:`,t,"</wyrm-memory>"].join(`
3
+ `)}function J(o,t=process.env){let i=null,r=null;try{const n=(t.WYRM_MEMO_MODE??"observe").toLowerCase();if(n==="off"||!o||!o.trim())return e;const l=JSON.parse(o);if(typeof l!="object"||l===null)return e;const m=l,u=m.hook_event_name;if(u!=="PreToolUse"&&u!=="PostToolUse")return e;const s=B(m);if(!s)return e;const c=D(s.absPath);if(!c.isFile()||c.size>y(t,"WYRM_MEMO_MAX_BYTES",z))return e;const f=t.WYRM_DB_PATH??F(O(),".wyrm","wyrm.db"),P=typeof m.session_id=="string"?m.session_id.slice(0,64):null;if(u==="PostToolUse"){const d=_(s.absPath);if(!v(d))return e;const p=d.toString("utf8"),w=p.length===0?0:p.split(`
4
+ `).length,x=I(p,s.absPath);r=g(f,{fileMustExist:!0},t),r.pragma("busy_timeout = 50");const{id:Y}=C(r,A(s.absPath));return new h(r).upsert({path:s.absPath,sha256:T(d),bytes:c.size,lines:w,distilled:x,tool:s.tool,projectId:Y,sessionId:P}),e}if(c.size<y(t,"WYRM_MEMO_MIN_BYTES",j))return e;i=N(f,{readonly:!0,fileMustExist:!0}),i.pragma("busy_timeout = 100");const a=new h(i).get(s.absPath);if(!a||W(a.last_seen,y(t,"WYRM_MEMO_TTL_DAYS",k))||T(_(s.absPath))!==a.sha256)return e;const b=Math.max(0,E(c.size)-E(a.distilled.length));try{r=g(f,{fileMustExist:!0},t),r.pragma("busy_timeout = 50"),new h(r).recordHit(s.absPath,b),R(r,"wyrm-memo","cached_preamble",b,void 0,"conservative")}catch{}if(n!=="warn")return e;const S={hookSpecificOutput:{hookEventName:"PreToolUse",additionalContext:H(a.last_seen,a.distilled)}};return{exitCode:0,stdout:JSON.stringify(S)+`
5
+ `,stderr:""}}catch(n){return t.WYRM_MEMO_DEBUG==="1"?{exitCode:0,stdout:"",stderr:`wyrm-memo: internal error (fail-open): ${(n instanceof Error?n.message:String(n)).slice(0,200)}
6
+ `}:e}finally{try{i?.close()}catch{}try{r?.close()}catch{}}}const X=L(import.meta.url);let M=!1;try{M=typeof process.argv[1]=="string"&&U(process.argv[1])===X}catch{M=!1}if(M){let o="";try{o=_(0,"utf-8")}catch{o=""}const t=J(o);t.stdout&&process.stdout.write(t.stdout),t.stderr&&process.stderr.write(t.stderr),process.exit(t.exitCode)}export{J as runMemo};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wyrm-mcp",
3
- "version": "9.2.2",
3
+ "version": "9.2.3",
4
4
  "mcpName": "lk.ghosts/wyrm",
5
5
  "description": "Local-first persistent memory for AI agents over MCP. Ground truths, a failure firewall that blocks repeated mistakes (negative learning), and hybrid recall, stored in SQLite on your machine. No cloud or LLM required. Proprietary license.",
6
6
  "type": "module",
@@ -133,6 +133,9 @@ try {
133
133
  runWyrm(['capture', content, '--project', project, '--mode', 'memory'], {
134
134
  timeout: 25000,
135
135
  stdio: 'ignore',
136
+ // Quest #1154: the capture is attributable. WYRM_AGENT_ID, when the
137
+ // harness exports one, still wins inside the CLI; this is the fallback.
138
+ env: { ...process.env, WYRM_WRITER_ID: process.env.WYRM_WRITER_ID || 'hook:session-capture' },
136
139
  });
137
140
  } catch { /* wyrm not on PATH or capture failed — never break the session */ }
138
141