wyrm-mcp 8.2.0 → 8.3.0
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/dist/capabilities.js +3 -3
- package/dist/cloud/sync-daemon.js +1 -1
- package/dist/handlers/companion.js +1 -1
- package/dist/handlers/recall.js +4 -4
- package/dist/handlers/resources.js +1 -1
- package/dist/handlers/session.js +14 -12
- package/dist/providers/embedding-provider.js +1 -1
- package/dist/receipt.js +1 -1
- package/dist/setup-wizard.js +5 -0
- package/dist/setup.js +3 -3
- package/dist/tool-manifest-v2.json +1 -1
- package/dist/tool-manifest.json +1 -1
- package/dist/wyrm-cli.js +120 -116
- package/dist/wyrm-manifest.json +1 -1
- package/package.json +1 -1
package/dist/wyrm-cli.js
CHANGED
|
@@ -1,87 +1,88 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{join as
|
|
2
|
+
import{join as F,dirname as re,resolve as Ie,basename as Pe}from"path";import{homedir as Ne}from"os";import{existsSync as q,readFileSync as V,readdirSync as Me}from"fs";import{fileURLToPath as ne}from"url";import{spawnSync as z}from"child_process";import{createInterface as Q}from"readline";import{WyrmDB as Oe}from"./database.js";import{MemoryArtifacts as G}from"./memory-artifacts.js";import{GroundTruths as pe}from"./intelligence.js";import{Causality as ue}from"./causality.js";import{wireTruthAutoCascade as me}from"./truth-cascade.js";import{Rehydration as Ae}from"./rehydration.js";import{makeRenderDeps as fe,buildRenderPlan as ie,renderToDisk as Le,renderForClient as ge,detectClients as We,ALL_RENDER_CLIENTS as ae,ALL_CLIENT_MARKERS as Ue}from"./render-target.js";import{classifyCapture as Fe}from"./capture.js";import{importFrom as qe,IMPORT_SOURCES as ye}from"./importers.js";import{c as d,colors as N,formatTable as D,printSection as k,printSuccess as b,printError as m,icons as Y}from"./cli.js";import{loadConnectorConfigs as he,upsertConnectorConfig as Ye,runConnector as He,runAllConnectors as Ve}from"./connectors/index.js";import{readActor as Be}from"./attribution.js";function M(){try{const l=re(ne(import.meta.url));return JSON.parse(V(F(l,"..","package.json"),"utf-8"))}catch{return{}}}function I(l,c){const t=typeof l=="string"?parseInt(l,10):NaN;return Number.isFinite(t)?t:c}function X(l,c){const t=typeof l=="string"?parseFloat(l):NaN;return Number.isFinite(t)?t:c}function Ke(){return process.env.WYRM_DB_PATH??F(Ne(),".wyrm","wyrm.db")}function j(){return new Oe(Ke())}function C(l){const c=[],t={};let i=0;for(;i<l.length;){const r=l[i];if(r.startsWith("--")){const e=r.slice(2),s=l[i+1];s&&!s.startsWith("--")?(t[e]=s,i+=2):(t[e]=!0,i++)}else c.push(r),i++}return{positional:c,flags:t}}function x(l,c){return c?l.getDatabase().prepare("SELECT * FROM projects WHERE LOWER(name) LIKE LOWER(?) LIMIT 1").get(`%${c}%`)??null:null}async function Ge(l){const{positional:c,flags:t}=C(l),i=c[0];i||(m("Usage: wyrm search <query> [--project <name>] [--type all|memories|truths|quests|data]"),process.exit(1));const r=j(),e=r.getDatabase(),s=t.type??"all",o=t.project,p=(o?x(r,o):null)?.id;k(`Search: "${i}"`);const a=[];if(s==="all"||s==="memories")try{const u=p?`AND m.project_id = ${p}`:"",g=e.prepare(`
|
|
3
3
|
SELECT m.id, m.kind, m.problem, m.project_id FROM memory_artifacts m
|
|
4
4
|
JOIN memory_artifacts_fts fts ON m.id = fts.rowid
|
|
5
|
-
WHERE memory_artifacts_fts MATCH ? ${
|
|
5
|
+
WHERE memory_artifacts_fts MATCH ? ${u}
|
|
6
6
|
LIMIT 20
|
|
7
|
-
`).all(i);for(const
|
|
7
|
+
`).all(i);for(const f of g)a.push([`mem:${f.id}`,"memory",f.kind,f.problem.slice(0,80)])}catch{}if(s==="all"||s==="sessions")try{const u=p?`AND s.project_id = ${p}`:"",g=e.prepare(`
|
|
8
8
|
SELECT s.id, s.objectives, s.project_id FROM sessions s
|
|
9
9
|
JOIN sessions_fts fts ON s.id = fts.rowid
|
|
10
|
-
WHERE sessions_fts MATCH ? ${
|
|
10
|
+
WHERE sessions_fts MATCH ? ${u}
|
|
11
11
|
LIMIT 10
|
|
12
|
-
`).all(i);for(const
|
|
12
|
+
`).all(i);for(const f of g)a.push([`session:${f.id}`,"session","",f.objectives.slice(0,80)])}catch{}if(s==="all"||s==="quests")try{const u=p?`AND q.project_id = ${p}`:"",g=e.prepare(`
|
|
13
13
|
SELECT q.id, q.title, q.priority, q.project_id FROM quests q
|
|
14
14
|
JOIN quests_fts fts ON q.id = fts.rowid
|
|
15
|
-
WHERE quests_fts MATCH ? ${
|
|
15
|
+
WHERE quests_fts MATCH ? ${u}
|
|
16
16
|
LIMIT 10
|
|
17
|
-
`).all(i);for(const
|
|
17
|
+
`).all(i);for(const f of g)a.push([`quest:${f.id}`,"quest",f.priority,f.title.slice(0,80)])}catch{}if(s==="all"||s==="data")try{const u=p?`AND d.project_id = ${p}`:"",g=e.prepare(`
|
|
18
18
|
SELECT d.id, d.category, d.key, d.value FROM data_lake d
|
|
19
19
|
JOIN data_lake_fts fts ON d.id = fts.rowid
|
|
20
|
-
WHERE data_lake_fts MATCH ? ${
|
|
20
|
+
WHERE data_lake_fts MATCH ? ${u}
|
|
21
21
|
LIMIT 10
|
|
22
|
-
`).all(i);for(const
|
|
23
|
-
${
|
|
22
|
+
`).all(i);for(const f of g)a.push([`data:${f.id}`,"data",f.category,f.value.slice(0,80)])}catch{}if(r.close(),a.length===0){console.log(d.dim(` No results found for "${i}"`));return}console.log(D(["ID","Type","Subtype","Preview"],a)),console.log(d.dim(`
|
|
23
|
+
${a.length} result${a.length!==1?"s":""}`))}async function Je(l){const{flags:c}=C(l),t=c.type??"all",i=I(c.limit,20),r=c.project,e=j(),s=e.getDatabase(),n=(r?x(e,r):null)?.id,p=n?`WHERE project_id = ${n}`:"",a=n?`AND project_id = ${n}`:"";if(k("Wyrm Memory"),t==="all"||t==="memories"){k("Memories");const u=s.prepare(`
|
|
24
24
|
SELECT id, kind, confidence, problem, tags FROM memory_artifacts
|
|
25
|
-
${
|
|
25
|
+
${p}
|
|
26
26
|
ORDER BY created_at DESC LIMIT ?
|
|
27
|
-
`).all(i);if(
|
|
27
|
+
`).all(i);if(u.length>0){const g=u.map(f=>[`mem:${f.id}`,f.kind,`${Math.round(f.confidence*100)}%`,f.problem.slice(0,60),f.tags?.slice(0,30)??""]);console.log(D(["ID","Kind","Conf","Preview","Tags"],g))}else console.log(d.dim(" No memories yet."))}if(t==="all"||t==="truths"){k("Ground Truths");const u=s.prepare(`
|
|
28
28
|
SELECT id, category, key, value FROM ground_truths
|
|
29
|
-
WHERE is_current = 1 ${
|
|
29
|
+
WHERE is_current = 1 ${a}
|
|
30
30
|
ORDER BY created_at DESC LIMIT ?
|
|
31
|
-
`).all(i);if(
|
|
31
|
+
`).all(i);if(u.length>0){const g=u.map(f=>[`truth:${f.id}`,f.category,f.key.slice(0,30),f.value.slice(0,60)]);console.log(D(["ID","Category","Key","Value"],g))}else console.log(d.dim(" No ground truths yet."))}if(t==="all"||t==="quests"){k("Quests");const u=s.prepare(`
|
|
32
32
|
SELECT id, priority, title, status FROM quests
|
|
33
|
-
${
|
|
33
|
+
${p}
|
|
34
34
|
ORDER BY created_at DESC LIMIT ?
|
|
35
|
-
`).all(i);if(
|
|
36
|
-
`+n.problem),n.validated_fix&&console.log(
|
|
37
|
-
`+n.validated_fix),n.why_it_worked&&console.log(
|
|
38
|
-
`+n.why_it_worked),n.tags&&console.log(
|
|
39
|
-
`+n.description),n.tags&&console.log(
|
|
40
|
-
`+n.value),n.rationale&&console.log(
|
|
41
|
-
`+n.rationale),console.log(
|
|
42
|
-
`+String(n.value).slice(0,500)),console.log(
|
|
43
|
-
`+n.objectives),n.completed&&console.log(
|
|
44
|
-
`+n.completed),n.notes&&console.log(
|
|
45
|
-
`+n.notes);break}default:
|
|
46
|
-
`);return}if(
|
|
47
|
-
`);return}const
|
|
48
|
-
`);return}
|
|
49
|
-
`);return}let g=
|
|
50
|
-
|
|
51
|
-
_... brief truncated at ${
|
|
52
|
-
`)}finally{n.close(),console.log=o}}async function
|
|
53
|
-
`);return}const
|
|
54
|
-
`)}finally{
|
|
55
|
-
`);return}if(i==="list"||i==="ls"||i===void 0){const
|
|
56
|
-
`);return}const
|
|
57
|
-
`)}return}if(i==="release"){const
|
|
58
|
-
`:`no presence row for ${
|
|
59
|
-
`);return}
|
|
60
|
-
`);return}const w=
|
|
61
|
-
`).filter(
|
|
35
|
+
`).all(i);if(u.length>0){const g=u.map(f=>[`quest:${f.id}`,f.priority,f.title.slice(0,60),f.status]);console.log(D(["ID","Priority","Title","Status"],g))}else console.log(d.dim(" No quests yet."))}e.close()}async function ze(l){const{positional:c}=C(l),t=c[0];t||(m("Usage: wyrm show <typed-id> (e.g. mem:41, quest:12, truth:7, data:5, session:3)"),process.exit(1));const[i,r]=t.split(":"),e=parseInt(r??"",10);(!i||isNaN(e))&&(m(`Invalid typed ID: ${t}. Format: type:number (e.g. mem:41)`),process.exit(1));const s=j(),o=s.getDatabase();switch(k(`${t}`),i){case"mem":{const n=o.prepare("SELECT * FROM memory_artifacts WHERE id = ?").get(e);if(!n){m(`Memory artifact ${e} not found`);break}console.log(d.bold("Kind: ")+n.kind),console.log(d.bold("Confidence:")+` ${Math.round(n.confidence*100)}%`),console.log(d.bold("Problem: ")+`
|
|
36
|
+
`+n.problem),n.validated_fix&&console.log(d.bold("Solution: ")+`
|
|
37
|
+
`+n.validated_fix),n.why_it_worked&&console.log(d.bold("Why: ")+`
|
|
38
|
+
`+n.why_it_worked),n.tags&&console.log(d.bold("Tags: ")+n.tags),console.log(d.bold("Created: ")+n.created_at);break}case"quest":{const n=o.prepare("SELECT * FROM quests WHERE id = ?").get(e);if(!n){m(`Quest ${e} not found`);break}console.log(d.bold("Title: ")+n.title),console.log(d.bold("Priority: ")+n.priority),console.log(d.bold("Status: ")+n.status),n.description&&console.log(d.bold("Desc: ")+`
|
|
39
|
+
`+n.description),n.tags&&console.log(d.bold("Tags: ")+n.tags),console.log(d.bold("Created: ")+n.created_at);break}case"truth":{const n=o.prepare("SELECT * FROM ground_truths WHERE id = ?").get(e);if(!n){m(`Ground truth ${e} not found`);break}console.log(d.bold("Category: ")+n.category),console.log(d.bold("Key: ")+n.key),console.log(d.bold("Value: ")+`
|
|
40
|
+
`+n.value),n.rationale&&console.log(d.bold("Rationale:")+`
|
|
41
|
+
`+n.rationale),console.log(d.bold("Active: ")+(n.is_current?"Yes":"No (superseded)")),console.log(d.bold("Created: ")+n.created_at);break}case"data":{const n=o.prepare("SELECT * FROM data_lake WHERE id = ?").get(e);if(!n){m(`Data point ${e} not found`);break}console.log(d.bold("Category: ")+n.category),console.log(d.bold("Key: ")+n.key),console.log(d.bold("Value: ")+`
|
|
42
|
+
`+String(n.value).slice(0,500)),console.log(d.bold("Created: ")+n.created_at);break}case"session":{const n=o.prepare("SELECT * FROM sessions WHERE id = ?").get(e);if(!n){m(`Session ${e} not found`);break}console.log(d.bold("Date: ")+n.date),console.log(d.bold("Objectives: ")+`
|
|
43
|
+
`+n.objectives),n.completed&&console.log(d.bold("Completed: ")+`
|
|
44
|
+
`+n.completed),n.notes&&console.log(d.bold("Notes: ")+`
|
|
45
|
+
`+n.notes);break}default:m(`Unknown type prefix: ${i}. Use mem|quest|truth|data|session`)}s.close()}async function Qe(l){const{positional:c,flags:t}=C(l),i=c[0];i||(m('Usage: wyrm capture "<content>" [--project <name>] [--mode auto|quest|truth|memory]'),process.exit(1));const r=t.project,e=t.mode,s=j(),o=s.getDatabase();let n=null;if(r){const S=x(s,r);S||(m(`Project not found: ${r}`),s.close(),process.exit(1)),n=S.id}let p=Fe(i);e&&e!=="auto"&&(p={type:e,subtype:{quest:"quest",truth:"decision",memory:"pattern"}[e]??e,confidence:100,reasoning:`Mode override: ${e}`});const{type:a,subtype:u,confidence:g,reasoning:f}=p;(a==="quest"||a==="truth"||a==="memory")&&n===null&&(m('A --project is required to capture. Use: wyrm capture "<text>" --project <name>'),s.close(),process.exit(1));let y=0,h="",w=!1;const $=new G(o),E=new pe(o);if(me(E,new ue(o)),a==="quest")y=s.addQuest(n,i.slice(0,200),"","medium").id,h="quest";else if(a==="truth")e!=="truth"&&g<100?(y=$.add(n,{kind:"pattern",problem:i,confidence:g/100,needsReview:1}).id,h="mem",w=!0):(y=E.set(n,{category:"decision",key:i.slice(0,60),value:i}).id,h="truth");else{const S=g>=75;y=$.add(n,{kind:u,problem:i,confidence:g/100,needsReview:S?0:1}).id,h="mem",S||(w=!0)}const{recordWrite:_}=await import("./receipts.js"),R=_(o,{tool:"wyrm_capture",outcome:w?"queued":"stored",refTable:h,refId:y,reason:w?`needs_review (confidence ${g}%) \u2014 review to activate`:void 0,source:"cli",projectId:n??void 0});s.close(),b(`Captured as ${a}: ${u}`),console.log(`${d.dim("Confidence:")} ${g}% | ${d.dim(f)}`),console.log(`${d.dim("ID:")} ${h}:${y}`),w&&console.log(`${Y.warning} Stored for review \u2014 run ${d.cyan("wyrm review")} to activate`),console.log(`receipt: ${R.outcome} ${R.ref??""}${R.reason?` \u2014 ${R.reason}`:""}`)}async function Xe(l){const{flags:c}=C(l);if(c.writes!==!0){m("Usage: wyrm digest --writes [--since <days>] [--json]"),process.exitCode=1;return}const t=Number(c.since)>=1?Number(c.since):1,{buildWriteDigest:i}=await import("./receipts.js"),r=j();try{const e=i(r.getDatabase(),t);if(c.json===!0){process.stdout.write(JSON.stringify(e)+`
|
|
46
|
+
`);return}if(k(`Write digest \u2014 last ${e.since}`),console.log(`${d.bold("Total writes:")} ${e.total} ${d.bold("Outcomes:")} ${Object.entries(e.byOutcome).map(([s,o])=>`${s} ${o}`).join(" \xB7 ")||"none"}`),console.log(`${d.bold("Review queue:")} ${e.reviewQueueDepth} awaiting review${e.reviewQueueDepth>0?d.dim(" (invisible to recall until approved)"):""}`),e.byTool.length>0&&console.log(D(["Tool","Outcome","N"],e.byTool.map(s=>[s.tool,s.outcome,String(s.n)]))),e.reasons.length>0){console.log(d.bold("Non-stored reasons:"));for(const s of e.reasons)console.log(` ${s.outcome} \xD7${s.n} \u2014 ${s.reason.slice(0,110)}`)}e.bySource.length>0&&console.log(d.bold("By source: ")+e.bySource.map(s=>`${s.source} ${s.n}`).join(" \xB7 "))}finally{r.close()}}async function Ze(l){const{flags:c}=C(l),t=I(c.session,0),i=c.path,r=c.project,e=I(c["max-chars"],6e3),s=c.quiet===!0,o=console.log;console.log=()=>{};const n=j();try{const p=new Ae(n.getDatabase());let a=t;if(a<=0){let f=i?n.getProject(i):void 0;if(!f&&r&&(f=x(n,r)??void 0),f||(f=n.getProject(process.cwd())),!f){s||process.stderr.write(`wyrm rehydrate: no Wyrm project for this directory, nothing to restore.
|
|
47
|
+
`);return}const y=n.getRecentSessions(f.id,1);if(y.length===0){s||process.stderr.write(`wyrm rehydrate: project "${f.name}" has no prior sessions yet.
|
|
48
|
+
`);return}a=y[0].id}const u=p.rehydrate(a);if(!u){s||process.stderr.write(`wyrm rehydrate: session ${a} not found.
|
|
49
|
+
`);return}let g=u.briefing_markdown;e>0&&g.length>e&&(g=g.slice(0,e)+`
|
|
50
|
+
|
|
51
|
+
_... brief truncated at ${e} chars, run \`wyrm show session:${u.session_id}\` for the full record._`),process.stdout.write(g+`
|
|
52
|
+
`)}finally{n.close(),console.log=o}}async function et(l){const{flags:c}=C(l),{runMetabolize:t}=await import("./metabolize.js"),i=j(),r=console.log;try{let e;if(typeof c.project=="string"){const o=x(i,c.project);if(!o){m(`Project not found: ${c.project}`),process.exitCode=1;return}e=o.id}const s=t(i.getDatabase(),{projectId:e,dryRun:c["dry-run"]===!0,near:c["no-near"]===!0?!1:void 0});console.log(`metabolize${s.dryRun?" (dry-run)":""} \u2014 scanned ${s.scanned} \xB7 exact-merged ${s.exactMerged} (superseded, not deleted) \xB7 near-dup candidates queued ${s.nearCandidatesQueued} \xB7 decayed ${s.decayed}`)}finally{i.close(),console.log=r}}async function tt(l){const{positional:c,flags:t}=C(l),i=c[0]??"stats",{backfillEntities:r}=await import("./entity-populate.js"),e=j(),s=console.log;try{const o=e.getDatabase();let n;if(typeof t.project=="string"){const p=x(e,t.project);if(!p){m(`Project not found: ${t.project}`),process.exitCode=1;return}n=p.id}if(i==="stats"){const p=a=>{if(n!=null){const g=a==="entities"?"SELECT COUNT(*) AS n FROM entities WHERE project_id = ?":"SELECT COUNT(*) AS n FROM relationships WHERE project_id = ?";return o.prepare(g).get(n).n}const u=a==="entities"?"SELECT COUNT(*) AS n FROM entities":"SELECT COUNT(*) AS n FROM relationships";return o.prepare(u).get().n};console.log(`entities: ${p("entities")} \xB7 relationships: ${p("relationships")}${n!=null?` (project ${n})`:" (all projects)"}`);return}if(i==="backfill"){const p=n!=null?[{id:n}]:o.prepare("SELECT id FROM projects").all();let a=0,u=0,g=0;for(const f of p){const y=r(o,f.id,{limit:I(t.limit,5e3)});a+=y.created,u+=y.linked,g+=y.artifactsScanned}console.log(`entities backfill \u2014 scanned ${g} artifact(s) across ${p.length} project(s): +${a} entities, +${u} co-occurrence edges`);return}m("Usage: wyrm entities <backfill|stats> [--project <name>] [--limit N]"),process.exitCode=1}finally{e.close(),console.log=s}}async function ot(l){const{positional:c,flags:t}=C(l),i=c[0],r=await import("./bridge.js");if(i==="init"){const{existsSync:e,writeFileSync:s}=await import("node:fs"),o=r.configPath();if(e(o)&&t.force!==!0){m(`${o} already exists (use --force to overwrite).`),process.exitCode=1;return}const n=(await import("node:os")).homedir(),p={sources:[{type:"remember",name:"remember",dir:`${n}/.remember`,projectPath:n,windowDays:7}]};s(o,JSON.stringify(p,null,2)),b(`Wrote ${o} (1 source: remember). Add render/reverse sources per project as needed.`);return}if(i==="status"){const e=r.loadConfig();if(!e){m(`No bridge config at ${r.configPath()} \u2014 run \`wyrm bridge init\`.`),process.exitCode=1;return}const s=r.loadState();k("Bridge sources");for(const o of e.sources){const n=Object.keys(s).filter(a=>a.startsWith(o.name+":")),p=n.reduce((a,u)=>a+s[u].length,0);console.log(` ${o.name} [${o.type}] \u2192 ${"projectPath"in o?o.projectPath:""}${o.type==="remember"?` (${n.length} files tracked, ${p} sections bridged)`:""}`)}return}if(i==="run"){const e=r.loadConfig();if(!e){m(`No bridge config at ${r.configPath()} \u2014 run \`wyrm bridge init\`.`),process.exitCode=1;return}const s=j(),o=console.log;try{const n={wyrm_version:M().version??"unknown",compiled_at:new Date().toISOString()},p=await r.runBridge(s.getDatabase(),e,n,{only:typeof t.source=="string"?t.source:void 0,dryRun:t["dry-run"]===!0});for(const a of p)console.log(`bridge:${a.source} [${a.type}]${t["dry-run"]===!0?" (dry-run)":""} \u2014 stored ${a.stored} \xB7 queued ${a.queued} \xB7 dropped ${a.dropped} \xB7 rendered ${a.rendered}${a.note?` \xB7 ${a.note}`:""}`);if(t.watch===!0){const a=Number(t.interval)>=2?Number(t.interval):15;console.log(`bridge watch \u2014 re-rendering on write events (poll ${a}s, Ctrl-C to stop)`),await r.watchBridge(s.getDatabase(),e,()=>({wyrm_version:M().version??"unknown",compiled_at:new Date().toISOString()}),{intervalSec:a,onCycle:u=>{for(const g of u)console.log(`bridge:${g.source} re-rendered (${g.rendered} file(s), ${g.queued} edit(s) harvested)`)}})}return}finally{s.close(),console.log=o}}m("Usage: wyrm bridge <init|status|run> [--source <name>] [--dry-run] [--force]"),process.exitCode=1}async function st(l){const{positional:c,flags:t}=C(l);if(c[0]!=="log"){m("Usage: wyrm session log [--path <dir>] [--run <id>] [--objectives <t>] [--completed <t>] [--issues <t>] [--commits <t>] [--notes <t>]"),process.exitCode=1;return}const r=a=>typeof t[a]=="string"?t[a]:void 0,e=r("path"),s=r("project"),o=r("run")?.slice(0,64),n=console.log;console.log=()=>{};const p=j();try{let a=e?p.getProject(e):void 0;if(!a&&s&&(a=x(p,s)??void 0),a||(a=p.getProject(process.cwd())),!a){process.stderr.write(`wyrm session log: no Wyrm project for this directory, nothing recorded.
|
|
53
|
+
`);return}const u={};for(const y of["objectives","completed","issues","commits","notes"]){const h=r(y);h&&(u[y]=h.slice(0,8e3))}const g=p.getDatabase();let f;o&&(f=g.prepare("SELECT id FROM sessions WHERE project_id = ? AND run_id = ? ORDER BY id DESC LIMIT 1").get(a.id,o)?.id),f?p.updateSession(f,u):(f=p.createSession(a.id,u).id,o&&g.prepare("UPDATE sessions SET run_id = ? WHERE id = ?").run(o,f)),process.stdout.write(`session:${f}
|
|
54
|
+
`)}finally{p.close(),console.log=n}}async function rt(l){const{positional:c,flags:t}=C(l),i=c[0],r=p=>typeof t[p]=="string"?t[p]:void 0,{AgentPresence:e,processStartTime:s,presenceLiveness:o}=await import("./presence.js"),n=j();try{const p=new e(n.getDatabase());if(i==="announce"){const a=r("agent");if(!a){m("Usage: wyrm presence announce --agent <id> [--kind <kind>] [--project <name>|--path <dir>] [--quest <n>] [--pid <n>|--auto-pid] [--ttl <sec>] [--role <r>]"),process.exitCode=1;return}const u=r("path");let g=u?n.getProject(u):void 0;!g&&r("project")&&(g=x(n,r("project"))??void 0);const f=t["auto-pid"]===!0?process.ppid:Number(r("pid")),y={};let h="";if(Number.isInteger(f)&&f>0){const E=s(f);E?(y.pid=f,y.pid_start=E,h=` \xB7 pid ${f} (start ${E})`):h=` \xB7 pid ${f} unreadable \u2014 TTL fallback`}const w=Number(r("ttl")),$=p.announce({agent_id:a,agent_kind:r("kind")??"cli",project_id:g?.id??null,current_quest_id:r("quest")?Number(r("quest")):null,ttl_seconds:Number.isFinite(w)&&w>0?w:y.pid?86400:300,metadata:Object.keys(y).length?y:void 0,role:r("role")??null});process.stdout.write(`presence:${$.id} ${a}${h}
|
|
55
|
+
`);return}if(i==="list"||i==="ls"||i===void 0){const a=n.getDatabase().prepare("SELECT * FROM agent_presence ORDER BY last_heartbeat DESC").all();if(a.length===0){process.stdout.write(`No agents on the board.
|
|
56
|
+
`);return}const u={"alive-pid":"ALIVE (pid)","dead-pid":"DEAD (pid gone)","alive-ttl":"alive (ttl)",stale:"stale"};for(const g of a){const f=o(g);process.stdout.write(`${g.agent_id} [${g.agent_kind}] ${u[f]} hb ${g.last_heartbeat}${g.role?` role ${g.role}`:""}${g.current_quest_id?` quest #${g.current_quest_id}`:""}
|
|
57
|
+
`)}return}if(i==="release"){const a=r("agent");if(!a){m("Usage: wyrm presence release --agent <id>"),process.exitCode=1;return}const u=p.release(a);process.stdout.write(u?`released ${a}
|
|
58
|
+
`:`no presence row for ${a}
|
|
59
|
+
`);return}m("Usage: wyrm presence <announce|list|release> [options]"),process.exitCode=1}finally{n.close()}}async function nt(l){const{flags:c}=C(l),t=c.path,i=c.project,r=c.out,e=c.brief===!0,s=c.force===!0,o=c.quiet===!0,n=(typeof c.client=="string"?c.client:"").split(",").map(f=>f.trim().toLowerCase()).filter(Boolean);let p=n.filter(f=>ae.includes(f));const a=n.filter(f=>!ae.includes(f));a.length>0&&(m(`Unknown --client value(s): ${a.join(", ")} (valid: ${ae.join("|")})`),process.exit(1));const u=console.log;e&&(console.log=()=>{});const g=j();try{let f=t?g.getProject(t):void 0;!f&&i&&(f=x(g,i)??void 0),f||(f=g.getProject(process.cwd())),f||(console.log=u,m("wyrm render: no Wyrm project for this directory (use --path or --project)."),process.exit(1));const y=fe(g.getDatabase()),h={wyrm_version:M().version??"unknown",compiled_at:new Date().toISOString()};if(e){const _=ie(y,f,h);console.log=u,process.stdout.write(_.sessionBrief+`
|
|
60
|
+
`);return}const w=r??f.path;p.length===0&&n.length===0&&(p=We(Ue.filter(_=>q(F(w,_)))));{const _=await import("./reverse-bridge.js"),R=ie(y,f,h),S={"MEMORY.md":R.memoryMd};for(const L of p){const W=ge(L,R.model,h);S[W.relPath]=W.block}try{const L=_.makeBridgeDeps(g.getDatabase()),W=await _.sweepProject(L,{id:f.id,path:f.path},S,{rootDir:w});W.added>0&&!o&&console.log(` ${Y.warning} harvested ${W.added} human edit(s) \u2192 review queue before overwrite`)}catch{}}const{plan:$,writes:E}=Le(y,f,h,{rootDir:w,clients:p,force:s});if(!o){b(`Rendered ${f.name} memory (${$.model.truths.length} truths, ${$.model.failures.length} failures, ${$.model.quests.length} quests, ${$.model.artifacts.length} patterns) to ${w}`);for(const _ of E){const R=_.action==="created"?Y.success:_.action==="updated"?Y.info:Y.warning;console.log(` ${R} ${_.action.padEnd(7)} ${_.path}${_.reason?` (${_.reason})`:""}`)}}}finally{g.close(),console.log=u}}async function it(l){const{flags:c}=C(l),t=c.path,i=c.project,r=c.root,e=c["dry-run"]===!0||c.dry===!0,s=(typeof c.client=="string"?c.client:"").split(",").map(u=>u.trim().toLowerCase()).filter(Boolean),o=["claude","cursor","copilot","agents"],n=s.filter(u=>o.includes(u)),p=await import("./reverse-bridge.js"),a=j();try{let u=t?a.getProject(t):void 0;if(!u&&i&&(u=x(a,i)??void 0),u||(u=a.getProject(process.cwd())),!u){m("wyrm reverse-bridge: no Wyrm project for this directory (use --path or --project)."),process.exitCode=1;return}const g=fe(a.getDatabase()),f={wyrm_version:M().version??"unknown",compiled_at:new Date().toISOString()},y=ie(g,u,f),h={"MEMORY.md":y.memoryMd};for(const E of n){const _=ge(E,y.model,f);h[_.relPath]=_.block}const w=p.makeBridgeDeps(a.getDatabase()),$=await p.sweepProject(w,{id:u.id,path:u.path},h,{dryRun:e,rootDir:r});k(`Reverse bridge ${e?"(dry run) ":""}\u2014 ${$.added} candidate(s) queued, ${$.skipped} already present (${$.filesWithEdits}/${$.filesScanned} file(s) with edits)`);for(const E of $.sample)console.log(` ${Y.bullet} ${E}`);!e&&$.added>0&&b("Review with: wyrm review")}finally{a.close()}}async function at(l){const c=C(l);if(typeof c.flags.from=="string"){await ct(c);return}const{positional:t,flags:i}=C(l.slice(1)),r=l[0],e=i.project;if(r==="git"){const s=I(i.last,20),o=j(),n=o.getDatabase();let p=null;if(e){const h=x(o,e);h||(m(`Project not found: ${e}`),o.close(),process.exit(1)),p=h.id}else{const h=n.prepare("SELECT p.* FROM projects p JOIN sessions s ON s.project_id = p.id ORDER BY s.created_at DESC LIMIT 1").get();h&&(p=h.id)}p||(m("No project found. Use --project <name>"),o.close(),process.exit(1));const a=z("git",["log","--pretty=format:%H%x1f%s%x1f%an%x1f%ai",`-${s}`],{cwd:process.cwd(),encoding:"utf-8",timeout:1e4,shell:!1});(a.error||a.status!==0)&&(m("git log failed. Make sure you are in a git repository."),o.close(),process.exit(1));const u=a.stdout.split(`
|
|
61
|
+
`).filter(h=>h.trim()),g=new G(n);let f=0,y=0;for(const h of u){const[,w,$,E]=h.split(""),_=w??"";if(/^Merge /i.test(_)||/^(chore|bump|release|version)/i.test(_)){y++;continue}let R="pattern";/^fix(\(.+\))?:/i.test(_)?R="lesson":/^refactor(\(.+\))?:/i.test(_)&&(R="heuristic");const S=_.split(":")[0]??"commit";g.add(p,{kind:R,problem:_,whyItWorked:`Committed by ${$??"unknown"} on ${E??"unknown"}`,tags:["git","commit",S.toLowerCase()],confidence:.6,needsReview:1}),f++}o.close(),b(`Imported ${f} commits (${y} skipped). Run ${d.cyan("wyrm review")} to activate.`)}else if(r==="rules"){const s=t[0],o=i.format??"plain";s||(m("Usage: wyrm import rules <path> [--project <name>] [--format cursorrules|copilot|plain]"),process.exit(1)),q(s)||(m(`File not found: ${s}`),process.exit(1));const n=V(s,"utf-8"),p=j(),a=p.getDatabase();let u=null;if(e){const S=x(p,e);S||(m(`Project not found: ${e}`),p.close(),process.exit(1)),u=S.id}else{const S=a.prepare("SELECT p.* FROM projects p JOIN sessions s ON s.project_id = p.id ORDER BY s.created_at DESC LIMIT 1").get();S&&(u=S.id)}u||(m("No project found. Use --project <name>"),p.close(),process.exit(1));const g=s.split("/").pop()??"rules",f=["imported",o,g],y=n.split(/\n(?=#)/),h=n.split(/\n\n+/),w=(y.length>=h.length?y:h).map(S=>S.trim()).filter(S=>S.length>=15),$=new G(a),E=new pe(a);me(E,new ue(a));let _=0,R=0;for(const S of w)/\b(always|never|must|use|don't|avoid|prefer)\b/i.test(S)?(E.set(u,{category:"constraint",key:S.slice(0,50).replace(/\n/g," "),value:S,source:g}),_++):($.add(u,{kind:"heuristic",problem:S,tags:f,confidence:.7,needsReview:1}),R++);p.close(),b(`Imported ${_} ground truths + ${R} artifacts (pending review).`)}else m("Usage: wyrm import git [--project <name>] [--last N]"),m(" wyrm import rules <path> [--project <name>] [--format cursorrules|copilot|plain]"),m(` wyrm import --from ${ye.join("|")} <file.json> [--project <name>]`),process.exit(1)}async function ct(l){const c=l.flags.from,t=l.positional[0],i=l.flags.project,r=`Usage: wyrm import --from ${ye.join("|")} <file.json> [--project <name>]`;t||(m(r),process.exit(1)),q(t)||(m(`File not found: ${t}`),process.exit(1));let e;try{e=JSON.parse(V(t,"utf-8"))}catch(n){m(`Could not parse JSON from ${t}: ${n.message}`),process.exit(1)}let s;try{s=qe(c,e)}catch(n){m(n.message),process.exit(1)}const o=j();try{let n=i?x(o,i):null;if(n||(n=o.getProject(process.cwd())??null),!n){m(i?`Project not found: ${i}`:"wyrm import: no Wyrm project for this directory (pass --project <name>)."),process.exitCode=1;return}if(s.length===0){m(`No importable memories found in ${t} for source "${c}".`);return}const p=o.getDatabase(),a=new G(p);try{const{createVectorStore:g}=await import("./vectors.js"),f=process.env.WYRM_VECTOR_PROVIDER??"auto";a.setVectorStore(g({provider:f},p))}catch{}let u=0;for(const g of s)a.add(n.id,{kind:"lesson",problem:g.text,tags:g.tags,constraints:g.metadata?JSON.stringify(g.metadata):void 0,whyItWorked:`Imported from ${g.source}`,outcome:"neutral",confidence:.6,needsReview:1}),u++;b(`Imported ${u} ${u===1?"memory":"memories"} from ${c} into ${d.cyan(n.name)} review queue. Run ${d.cyan("wyrm review")} to vet (tagged ${d.dim(`imported_from:${s[0]?.source??c}`)}).`)}finally{o.close()}}async function lt(l){const{flags:c}=C(l),t=c.project,i=j(),r=i.getDatabase();if(k("Wyrm Statistics"),t){const e=x(i,t);e||(m(`Project not found: ${t}`),i.close(),process.exit(1));const s=i.getProjectStats(e.id),o=[["Sessions",String(s.sessions)],["Quests (pending)",String(s.quests.pending)],["Quests (completed)",String(s.quests.completed)],["Data Points",String(s.dataPoints)]];console.log(D(["Metric","Value"],o))}else{const e=i.getStats(),s=[["Projects",String(e.projects)],["Sessions",String(e.sessions)],["Quests",String(e.quests)],["Data Points",String(e.dataPoints)],["DB Size",e.dbSize]],o=r.prepare("SELECT COUNT(*) as n FROM memory_artifacts").get().n,n=r.prepare("SELECT COUNT(*) as n FROM ground_truths WHERE is_current = 1").get().n;s.push(["Memories",String(o)],["Ground Truths",String(n)]),console.log(D(["Metric","Value"],s))}i.close()}async function dt(l){const{flags:c}=C(l),t=c.project,i=j(),r=i.getDatabase();let e=null;if(t){const a=x(i,t);a||(m(`Project not found: ${t}`),i.close(),process.exit(1)),e=a.id}const s=e?`AND project_id = ${e}`:"",o=r.prepare(`
|
|
62
62
|
SELECT id, kind, problem FROM memory_artifacts
|
|
63
|
-
WHERE needs_review = 1 ${
|
|
63
|
+
WHERE needs_review = 1 ${s}
|
|
64
64
|
ORDER BY created_at ASC
|
|
65
|
-
`).all();if(o.length===0){console.log(
|
|
66
|
-
${
|
|
67
|
-
Review complete.`)}async function
|
|
68
|
-
Total: ${g.length} candidate(s)`),!
|
|
69
|
-
This is a dry run. Use --no-dry-run to delete (confirm each ID).`)),n.close();return}if(!o){const
|
|
70
|
-
Delete these ${g.length} artifact(s)? Type CONFIRM to proceed:
|
|
71
|
-
Activate with: wyrm login (free) \xB7 or: wyrm activate <license.json | key>`)),console.log(
|
|
72
|
-
\xA9 2026 Ghost Protocol (Pvt) Ltd \xB7 Proprietary \xB7 https://wyrm.ghosts.lk`)),console.log(
|
|
73
|
-
${
|
|
74
|
-
Waiting for approval\u2026 (Ctrl-C to cancel)`));const
|
|
75
|
-
Database size: ${
|
|
76
|
-
|
|
65
|
+
`).all();if(o.length===0){console.log(d.dim(` No artifacts pending review${t?` for ${t}`:""}.`)),i.close();return}k(`Review Queue (${o.length} items)`);const n=Q({input:process.stdin,output:process.stdout}),p=a=>new Promise(u=>{n.question(a,u)});for(const a of o){console.log(`
|
|
66
|
+
${d.bold(`[${a.kind}] #${a.id}`)}`),console.log(d.dim("\u2500".repeat(60))),console.log(a.problem.slice(0,300)),console.log(d.dim("\u2500".repeat(60)));const g=(await p(`${d.cyan("[a]")}pprove / ${d.red("[r]")}eject / ${d.yellow("[s]")}kip? `)).trim().toLowerCase();g==="a"?(r.prepare("UPDATE memory_artifacts SET needs_review = 0, updated_at = datetime('now') WHERE id = ?").run(a.id),b(`Approved #${a.id}`)):g==="r"?(r.prepare("DELETE FROM memory_artifacts WHERE id = ?").run(a.id),console.log(`${Y.cross} Rejected #${a.id}`)):console.log(d.dim(` Skipped #${a.id}`))}n.close(),i.close(),console.log(`
|
|
67
|
+
Review complete.`)}async function pt(l){const{positional:c,flags:t}=C(l),i=c[0];(!i||!["export","import","preview"].includes(i))&&(m("Usage: wyrm sync export --out <path> | wyrm sync import --from <path> | wyrm sync preview --from <path>"),process.exit(1));const{randomBytes:r,pbkdf2Sync:e,createCipheriv:s,createDecipheriv:o}=await import("crypto"),{readFileSync:n,writeFileSync:p,copyFileSync:a,unlinkSync:u,existsSync:g,chmodSync:f}=await import("fs"),{homedir:y}=await import("os"),{join:h}=await import("path"),w=(await import("better-sqlite3")).default;let $=process.env.WYRM_SYNC_PASSPHRASE??"";if(!$){const T=Q({input:process.stdin,output:process.stdout});$=await new Promise(P=>{process.stdout.write("Passphrase: "),process.stdin.isTTY&&process.stdin.setRawMode?.(!0),T.question("",U=>{process.stdin.isTTY&&process.stdin.setRawMode?.(!1),console.log(""),T.close(),P(U)})})}$||(m("Passphrase is required. Set WYRM_SYNC_PASSPHRASE or enter interactively."),process.exit(1));const E=h(y(),".wyrm"),_=j();if(i==="export"){const T=t.out;T||(m("--out <path> is required"),process.exit(1));const P=h(E,"wyrm_cli_export_temp.db");try{const U=_.getDatabase();g(P)&&u(P),U.prepare("VACUUM INTO ?").run(P);const K=n(P),H=r(32),J=r(16),Ee=e($,H,6e5,32,"sha256"),se=s("aes-256-gcm",Ee,J),Re=Buffer.concat([se.update(K),se.final()]),xe=se.getAuthTag(),Te=Buffer.from("WYRM"),le=Buffer.alloc(1);le.writeUInt8(1,0);const de=Buffer.concat([Te,le,H,J,xe,Re]);p(T,de);try{f(T,384)}catch{}try{u(P)}catch{}const De=(de.length/(1024*1024)).toFixed(2);b(`Exported to ${T} (${De} MB)`)}catch(U){try{g(P)&&u(P)}catch{}m(`Export failed: ${U}`)}_.close();return}const R=t.from;R||(m("--from <path> is required"),process.exit(1));const S=n(R);S.subarray(0,4).toString("ascii")!=="WYRM"&&(m("Invalid Wyrm snapshot file."),process.exit(1));const L=S.readUInt8(4);L!==1&&(m(`Unsupported snapshot version: ${L}`),process.exit(1));const W=S.subarray(5,37),ve=S.subarray(37,53),ke=S.subarray(53,69),Se=S.subarray(69),_e=e($,W,6e5,32,"sha256"),Z=o("aes-256-gcm",_e,ve);Z.setAuthTag(ke);let ee;try{ee=Buffer.concat([Z.update(Se),Z.final()])}catch{m("Decryption failed \u2014 wrong passphrase or corrupted file."),process.exit(1)}if(i==="preview"){const T=h(E,"wyrm_cli_preview_temp.db");g(T)&&u(T),p(T,ee);try{const P=new w(T,{readonly:!0}),U=["projects","sessions","ground_truths","memory_artifacts","quests"];k("Snapshot Preview");const K=[];for(const H of U)try{const J=P.prepare(`SELECT COUNT(*) as n FROM ${H}`).get();K.push([H,String(J.n)])}catch{K.push([H,"?"])}console.log(D(["Table","Count"],K)),P.close()}catch(P){m(`Preview failed: ${P}`)}try{g(T)&&u(T)}catch{}_.close();return}const B=_.getDatabasePath(),ce=Q({input:process.stdin,output:process.stdout}),je=await new Promise(T=>{ce.question("This will REPLACE your current database. Type CONFIRM to proceed: ",T)});if(ce.close(),je.trim()!=="CONFIRM"){console.log(d.dim("Aborted.")),_.close();return}const Ce=new Date().toISOString().replace(/[:.]/g,"-"),te=`${B}.backup.${Ce}`;a(B,te),b(`Backed up to ${te}`);const oe=h(E,"wyrm_cli_restore_temp.db");p(oe,ee),_.getDatabase().close(),a(oe,B);for(const T of["-wal","-shm"])try{g(B+T)&&u(B+T)}catch{}try{u(oe)}catch{}b(`Restored from ${R}. Backup at ${te}`)}async function ut(l){const{flags:c}=C(l),t=c.project,i=c.path,r=X(c["min-confidence"],.3),e=I(c["older-than"],90),s=c["no-dry-run"]===!0,o=c.yes===!0,n=j(),p=n.getDatabase();let a=null;if(i||t){const h=i?n.getProject(i):x(n,t);h||(m(`Project not found: ${i??t}`),n.close(),process.exit(1)),a=h.id}const u=new G(p),{candidates:g}=u.pruneStale({projectId:a,minConfidence:r,olderThanDays:e,dryRun:!0});if(k(`Prune Candidates${s?" (LIVE DELETE)":" (dry-run)"}`),g.length===0){console.log(d.dim(" No artifacts match prune criteria.")),n.close();return}const f=g.map(h=>[String(h.id),h.kind,h.problem.slice(0,60),(h.confidence*100).toFixed(0)+"%",h.last_accessed_at??"never"]);if(console.log(D(["ID","Kind","Problem","Conf","Last Accessed"],f)),console.log(`
|
|
68
|
+
Total: ${g.length} candidate(s)`),!s){console.log(d.dim(`
|
|
69
|
+
This is a dry run. Use --no-dry-run to delete (confirm each ID).`)),n.close();return}if(!o){const h=Q({input:process.stdin,output:process.stdout}),w=await new Promise($=>{h.question(`
|
|
70
|
+
Delete these ${g.length} artifact(s)? Type CONFIRM to proceed: `,$)});if(h.close(),w.trim()!=="CONFIRM"){console.log(d.dim("Aborted.")),n.close();return}}const y=u.deleteArtifacts(g.map(h=>h.id));b(`Deleted ${y} artifact(s).`),n.close()}async function mt(l){const{positional:c,flags:t}=C(l),i=c[0]||"list",r=j();try{if(i==="list"||i==="ls"){const e=he(r);if(e.length===0){k("Connectors"),console.log(`${N.dim} none configured. Add one with: wyrm connector add --name <n> --url <bridge-url> --workspace <w>${N.reset}`);return}k("Connectors");const s=e.map(o=>[o.name,o.source,o.enabled?"on":"off",o.workspace,kt(o.baseUrl),o.allowlist.length?`${o.allowlist.length} chats`:"all"]);console.log(D(["Name","Source","Enabled","Workspace","Bridge","Allowlist"],s));return}if(i==="add"){const e=A(t.name),s=A(t.url),o=A(t.workspace);if(!e||!s||!o){m("usage: wyrm connector add --name <n> --url <bridge-url> --workspace <w> [--allowlist a,b] [--token T] [--disabled]"),process.exitCode=1;return}const n={name:e,source:"bridge",enabled:!t.disabled,baseUrl:s,workspace:o,allowlist:A(t.allowlist)?A(t.allowlist).split(",").map(p=>p.trim()).filter(Boolean):[],...A(t.token)?{authToken:A(t.token)}:{}};Ye(r,n),b(`Connector "${e}" saved (source=bridge, workspace=${o}). Token, if any, stored without being printed.`),console.log(`${N.dim} Tip: prefer the env var WYRM_CONNECTOR_TOKEN_${e.toUpperCase().replace(/[^A-Z0-9]/g,"_")} over --token.${N.reset}`);return}if(i==="sync"){const e=c[1]||A(t.name);if(e){const o=he(r).find(p=>p.name===e);if(!o){m(`Connector not found: ${e}`),process.exitCode=1;return}const n=await He(r,o);b(`${n.source}: fetched ${n.fetched}, ingested ${n.ingested}, skipped ${n.skipped} -> ${n.workspace}`);return}const s=await Ve(r);if(s.length===0){console.log(`${N.dim} no enabled connectors.${N.reset}`);return}for(const o of s)"error"in o?m(`${o.name}: ${o.error}`):b(`${o.source}: fetched ${o.fetched}, ingested ${o.ingested}, skipped ${o.skipped} -> ${o.workspace}`);return}m(`Unknown connector subcommand: ${i} (use list | add | sync)`),process.exitCode=1}finally{r.close()}}function we(){return V(0,"utf-8").trim()}async function ft(){const{initializeLicense:l,getLicenseInfo:c,getTier:t}=await import("./license.js");l();const i=c();k("Wyrm License");const r=[["Tier",t()],["Status",i.valid?"valid":"free tier (no license key)"]];i.valid&&i.key&&(r.push(["Key",i.key]),r.push(["Issued to",i.issuedTo??"unknown"]),r.push(["Expires",i.expiresAt?new Date(i.expiresAt).toLocaleDateString():"never"])),r.push(["Features",i.features.join(", ")||"(free)"]),console.log(D(["Field","Value"],r)),i.valid||console.log(d.dim(`
|
|
71
|
+
Activate with: wyrm login (free) \xB7 or: wyrm activate <license.json | key>`)),console.log(d.dim(`
|
|
72
|
+
\xA9 2026 Ghost Protocol (Pvt) Ltd \xB7 Proprietary \xB7 https://wyrm.ghosts.lk`)),console.log(d.dim(" Licensed under the Wyrm Terms of Service. No open-source license is granted."))}async function gt(){const l=(process.env.WYRM_ACCOUNT_URL??"https://account.ghosts.lk").replace(/\/$/,""),c=(()=>{try{return M().version??"unknown"}catch{return"unknown"}})();let t;try{const a=await fetch(`${l}/api/v1/cli/auth/start`,{method:"POST",headers:{"x-wyrm-version":c}});if(!a.ok)throw new Error(`HTTP ${a.status}`);t=await a.json()}catch(a){m(`Couldn't reach ${l} (${a instanceof Error?a.message:"network error"}).`),process.exitCode=1;return}const i=t.verification_uri_complete||t.verification_uri||`${l}/cli`;console.log(`
|
|
73
|
+
${d.cyan("Sign in to activate Wyrm (free):")}`),console.log(` 1. Open ${d.cyan(i)}`),console.log(` 2. Approve the code ${d.cyan(t.user_code)}`),console.log(d.dim(`
|
|
74
|
+
Waiting for approval\u2026 (Ctrl-C to cancel)`));const r=(t.interval??3)*1e3,e=Date.now()+(t.expires_in??600)*1e3;let s="";for(;Date.now()<e;){await new Promise(a=>{setTimeout(a,r)});try{const u=await(await fetch(`${l}/api/v1/cli/auth/poll`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({device_code:t.device_code})})).json();if(u.status==="approved"&&u.token){s=u.token;break}if(u.status==="denied"||u.error==="expired"){m("Login was denied or the code expired. Run `wyrm login` again."),process.exitCode=1;return}}catch{}}if(!s){m("Login timed out. Run `wyrm login` again."),process.exitCode=1;return}let o;try{const a=await fetch(`${l}/api/v1/license/free`,{method:"POST",headers:{authorization:`Bearer ${s}`,"x-wyrm-version":c}});if(!a.ok){const u=await a.json().catch(()=>({}));m(`Activation failed (${a.status}): ${u.hint||u.error||"unknown error"}`),process.exitCode=1;return}o=JSON.stringify(await a.json())}catch(a){m(`Activation request failed (${a instanceof Error?a.message:"network error"}).`),process.exitCode=1;return}const{activateLicense:n}=await import("./license.js"),p=n(o);p.valid?(b(`Signed in & activated \u2014 ${p.tier} tier (expires ${p.expiresAt??"never"}).`),console.log(d.dim(" Restart the Wyrm MCP server / daemon to apply."))):(m(`Activation failed: ${p.error??"unknown error"}`),process.exitCode=1)}async function yt(l){const{positional:c}=C(l),t=c[0];let i;t&&q(t)?i=V(t,"utf-8"):t?i=t:process.stdin.isTTY?(m("Usage: wyrm activate <license.json path | license JSON> (or pipe the JSON on stdin)"),process.exit(1)):i=we();const{activateLicense:r}=await import("./license.js");try{const e=r(i);e.valid?(b(`License activated \u2014 ${e.tier} tier (${e.features.join(", ")})`),console.log(d.dim(" Restart Wyrm (MCP server / daemon) to apply all features."))):(m(`License activation failed: ${e.error??"unknown error"}`),process.exitCode=1)}catch{m("Invalid license format. Please verify your license key."),process.exitCode=1}}async function ht(l){const{flags:c}=C(l),{runMaintenance:t}=await import("./maintenance.js"),{FailurePatterns:i}=await import("./failure-patterns.js"),{SessionSeen:r}=await import("./session-seen.js"),{AgentPresence:e}=await import("./presence.js"),s=j();try{const o=s.getDatabase(),n=I(c["archive-days"],0),p=t({db:s,sessionSeen:new r(o),failures:new i(o),presence:new e(o)},{vacuum:c.vacuum===!0,archiveDays:n>0?n:void 0});k("Maintenance complete");for(const a of p.lines)console.log(` - ${a}`);console.log(d.dim(`
|
|
75
|
+
Database size: ${p.dbSize}`))}finally{s.close()}}async function wt(l){const{resolveEmbeddingState:c}=await import("./providers/embedding-provider.js"),t=j();let i=0;const r=(s,o)=>{console.log(` ${d.green("\u2714")} ${s} \u2014 ${d.dim(o)}`)},e=(s,o,n)=>{i++,console.log(` ${d.red("\u2716")} ${s} \u2014 ${o}`),console.log(` ${d.yellow("fix:")} ${n}`)};try{const s=t.getDatabase();k("wyrm doctor");const o=c();o.reason===""&&o.resolved!=="local"?r("Embedding provider",`${o.resolved} (${o.model})${o.egressHost?` \xB7 egress: ${o.egressHost}`:" \xB7 local"}`):o.resolved==="local"?e("Embedding provider","local-hash (hash-384) is NOT semantic \u2014 test-only vectors",o.fix||"use NVIDIA NIM: set WYRM_VECTOR_PROVIDER=nim + NVIDIA_API_KEY"):o.reason==="ollama_deprecated"?e("Embedding provider","ollama (deprecated \u2014 leaves in the next major)",o.fix):e("Embedding provider",`none (${o.reason})`,o.fix);const n=s.prepare("SELECT COUNT(*) AS n FROM memory_artifacts").get().n;let p=0;try{p=s.prepare("SELECT COUNT(*) AS n FROM vectors").get().n}catch{}o.resolved==="none"||o.resolved==="local"?e("Vector index",`${p} vector(s) / ${n} memories \u2014 recall is FTS5 keyword-only (~59.9% vs 72.2% hybrid recall@10)`,o.fix||"enable a provider, then: wyrm index rebuild"):p===0&&n>0?e("Vector index",`provider '${o.resolved}' is configured but 0 of ${n} memories are indexed`,"wyrm index rebuild"):r("Vector index",`${p} vector(s) over ${n} memories`);try{const g=s.prepare("SELECT COUNT(*) AS n FROM memory_artifacts_fts").get().n;g===n?r("FTS index",`${g}/${n} rows in sync`):e("FTS index",`${g} FTS rows vs ${n} memories \u2014 keyword recall is missing rows`,"INSERT INTO memory_artifacts_fts(memory_artifacts_fts) VALUES('rebuild') via wyrm maintenance")}catch{e("FTS index","memory_artifacts_fts unreadable","wyrm maintenance")}const a=s.prepare("SELECT COUNT(*) AS n FROM failure_patterns WHERE resolved = 0").get().n;r("Failure firewall",`${a} unresolved pattern(s) \xB7 matching = exact signature + FTS5 fuzzy (no vector tier in this build)`);const u=s.prepare("SELECT COUNT(*) AS n FROM memory_artifacts WHERE needs_review = 1").get().n;u>0?e("Review queue",`${u} memor${u===1?"y":"ies"} invisible to recall until approved`,"wyrm review"):r("Review queue","empty");try{const g=s.prepare("SELECT MAX(version) AS v FROM schema_versions").get().v;r("Schema",`migration v${g??0}`)}catch{e("Schema","schema_versions unreadable","wyrm maintenance")}console.log(""),i===0?b("All checks passed \u2014 nothing is silently off."):(m(`${i} check(s) DEGRADED \u2014 the fixes above are exact.`),process.exitCode=1)}finally{t.close()}}async function bt(l){const{positional:c,flags:t}=C(l),i=c[0]??"list",r=j();try{const e=r.getDatabase();if(i==="list"){const s=e.prepare("SELECT id, scope, target, occurrences, last_seen FROM failure_patterns WHERE resolved = 0 ORDER BY last_seen DESC LIMIT 25").all();if(k("Unresolved failures"),!s.length){console.log(d.dim(" none \u2014 the firewall has nothing active."));return}console.log(D(["ID","Scope","Target","Seen","Last seen"],s.map(o=>[String(o.id),o.scope,o.target.slice(0,48),String(o.occurrences),o.last_seen]))),console.log(d.dim(`
|
|
76
|
+
resolve one: wyrm failure resolve <id>`));return}if(i==="resolve"){const s=Number(c[1]);if(!Number.isInteger(s)||s<=0){m('Usage: wyrm failure resolve <id> [--note "root cause fixed by ..."]'),process.exitCode=1;return}const o=t.note??"";(e.prepare("UPDATE failure_patterns SET resolved = 1, resolution_note = ?, last_seen = datetime('now') WHERE id = ? AND resolved = 0").run(o||"resolved via wyrm failure resolve",s).changes??0)>0?b(`Failure #${s} resolved \u2014 it will no longer flag.`):(m(`No unresolved failure #${s}.`),process.exitCode=1);return}m("Usage: wyrm failure <list|resolve <id> [--note N]>"),process.exitCode=1}finally{r.close()}}async function $t(l){const{positional:c,flags:t}=C(l),i=c[0]??"list",r=j();try{if(i==="add"){const e=c[1]??process.cwd(),s=Ie(e);if(!q(s)){m(`Path does not exist: ${s}`),process.exitCode=1;return}const o=t.name??Pe(s),n=r.registerProject(o,s);b(`Project #${n.id} '${n.name}' registered at ${n.path}`);return}if(i==="list"){const e=r.getAllProjects(50);k("Projects"),console.log(D(["ID","Name","Path"],e.map(s=>[String(s.id),s.name,s.path])));return}m("Usage: wyrm project <add [path] [--name N] | list>"),process.exitCode=1}finally{r.close()}}async function vt(l){const{positional:c,flags:t}=C(l),i="Usage: wyrm index <setup|rebuild|status> [--provider auto|local|nim|openai|none] [--model M] [--project P] [--dry-run]";if(t.help===!0){console.log(i);return}const r=c[0]??"status",{createVectorStore:e}=await import("./vectors.js"),o={provider:t.provider??process.env.WYRM_VECTOR_PROVIDER??"auto",model:t.model,apiKey:t["api-key"]??process.env.OPENAI_API_KEY,ollamaUrl:t["ollama-url"]};if(r==="setup"){const{createProvider:p}=await import("./providers/embedding-provider.js"),a=p(o);if(!await a.isReady()&&o.provider!=="none"){m(`Provider not ready: ${a.name}. Check the configuration and try again.`),process.exitCode=1;return}b(`Vector provider verified: ${a.name} (model ${a.model}, ${a.dimensions}d)`),console.log(d.dim(" The MCP server reads WYRM_VECTOR_PROVIDER (and provider-specific env) at boot \u2014")),console.log(d.dim(` set WYRM_VECTOR_PROVIDER=${a.name==="none"?"none":o.provider} in the server env, then: wyrm index rebuild`));return}const n=j();try{const p=n.getDatabase(),a=e(o,p);if(r==="status"){const u=a.getStats();k("Vector index");const g=[["Provider",u.provider],["Model",u.model],["Vectors",String(u.total)],...Object.entries(u.byType).map(([f,y])=>[` ${f}`,String(y)])];console.log(D(["Field","Value"],g));return}if(r==="rebuild"){const{reindexProjects:u}=await import("./reindex.js"),g=t["dry-run"]===!0,f=t.project;let y;if(f){const $=n.getProject(f)??x(n,f);if(!$){m(`Project not found: ${f}`),process.exitCode=1;return}y=[$.id]}else y=n.getAllProjects(1e3).map($=>$.id);const{indexed:h,skipped:w}=await u(p,a,y,{dryRun:g,onError:($,E)=>m(`${$}: ${JSON.stringify(E)}`)});b(`Reindex ${g?"(dry run) ":""}\u2014 ${y.length} project(s), ${h} indexed, ${w} skipped`);return}m(i),process.exitCode=1}finally{n.close()}}function A(l){return typeof l=="string"?l:""}function kt(l){try{return new URL(l).host}catch{return l}}async function St(l){const{flags:c}=C(l),{getUpdateStatus:t}=await import("./version-check.js"),i=M().version??"0.0.0",r=j();let e;try{e=await t(r.getDatabase(),i,{force:c.force===!0||c.check===!0})}finally{r.close()}if(k("Wyrm update"),console.log(D(["Field","Value"],[["Current",e.current],["Latest",e.latest??"unknown (offline?)"],["Update available",e.updateAvailable?"yes":"no"],["Checked",`${e.checkedAt} (${e.source})`]])),c.check===!0)return;if(!e.updateAvailable&&c.force!==!0){console.log(d.dim(`
|
|
77
|
+
Already up to date. (Use --force to reinstall anyway.)`));return}console.log(d.dim(`
|
|
77
78
|
Running: npm install -g wyrm-mcp@latest
|
|
78
|
-
`));const
|
|
79
|
-
Total: ${
|
|
80
|
-
`,"utf-8"),b(`Invoice written to ${
|
|
81
|
-
`)}finally{
|
|
82
|
-
=== Recent log ===`),console.log(
|
|
79
|
+
`));const s=z("npm",["install","-g","wyrm-mcp@latest"],{stdio:"inherit",shell:!1});s.status===0?b("Updated. Restart your MCP clients to pick up the new binary."):(m(`npm install exited with ${s.status??"unknown"}`),process.exitCode=s.status??1)}async function _t(l){const{positional:c,flags:t}=C(l),i=c[0],r=t.project??process.cwd();if(i==="inject"){const{injectSystemPrompt:e}=await import("./autoconfig.js"),s=typeof t.clients=="string"?t.clients.split(",").map(n=>n.trim()).filter(Boolean):[],o=e(r,s);k("System prompt injection");for(const n of o.injected)console.log(` + ${n}`);for(const n of o.skipped)console.log(d.dim(` o skipped (unknown client): ${n}`));for(const n of o.errors)m(n);o.injected.length>0&&b("AI clients in this project will now call wyrm_session_prime at conversation start."),o.errors.length>0&&(process.exitCode=1);return}if(i==="migrate"){const{migrateProject:e,renderMigrationReport:s}=await import("./migrate-prompt.js"),{WYRM_INJECT_BLOCK:o}=await import("./autoconfig.js"),n=t.apply===!0,p=e({projectPath:r,newBlock:o,apply:n});console.log(s(p,n));return}m("Usage: wyrm prompt inject [--project <path>] [--clients copilot,cursor] | wyrm prompt migrate [--project <path>] [--apply]"),process.exitCode=1}async function jt(l){const{positional:c,flags:t}=C(l);(c[0]??"report")!=="report"&&(m("Usage: wyrm hours report --from YYYY-MM-DD --to YYYY-MM-DD [--project <name>] [--session-hours H] [--json]"),process.exit(1));const r=t.from,e=t.to;(!r||!e)&&(m("--from and --to are required (YYYY-MM-DD)"),process.exit(1));const{HourLedger:s}=await import("./hours.js"),o=j();try{const n=t.project,p=n?x(o,n):null;if(n&&!p){m(`Project not found: ${n}`),process.exitCode=1;return}const a=new s(o.getDatabase()).report({range_start:r,range_end:e,project_id:p?.id,default_session_hours:X(t["session-hours"],1)});if(t.json===!0){console.log(JSON.stringify(a,null,2));return}if(k(`Hours ${a.range.start} \u2192 ${a.range.end}`),a.by_project.length===0){console.log(d.dim(" No sessions in range."));return}console.log(D(["Project","Sessions","Hours"],a.by_project.map(u=>[u.project_name,String(u.session_count),u.hours.toFixed(2)]))),console.log(`
|
|
80
|
+
Total: ${a.total_hours.toFixed(2)}h across ${a.entries.length} session(s)`+(a.estimated_sessions>0?d.dim(` (${a.estimated_sessions} estimated)`):""))}finally{o.close()}}async function Ct(l){const{positional:c,flags:t}=C(l),i=c[0]??"generate",r=t.client,e=X(t.rate,NaN),s=t.from,o=t.to;(i!=="generate"||!r||!Number.isFinite(e)||!s||!o)&&(m('Usage: wyrm invoice generate --client <name> --rate <usd/hour> --from YYYY-MM-DD --to YYYY-MM-DD [--project <name>] [--number INV-X] [--currency USD] [--notes "\u2026"] [--out <path>]'),process.exit(1));const{HourLedger:n}=await import("./hours.js"),p=j();try{const a=t.project,u=a?x(p,a):null;if(a&&!u){m(`Project not found: ${a}`),process.exitCode=1;return}const g=new n(p.getDatabase()).invoice({client_name:r,hourly_rate_usd:e,range_start:s,range_end:o,project_id:u?.id,invoice_number:t.number,currency:t.currency,notes:t.notes,business_name:t["business-name"],business_address:t["business-address"],business_contact:t["business-contact"],client_address:t["client-address"],default_session_hours:X(t["session-hours"],1)}),f=t.out;if(f){const{writeFileSync:y}=await import("node:fs");y(f,g+`
|
|
81
|
+
`,"utf-8"),b(`Invoice written to ${f}`)}else process.stdout.write(g+`
|
|
82
|
+
`)}finally{p.close()}}async function Et(l){const{positional:c,flags:t}=C(l),i=c[0]??"status",{AgentDaemon:r}=await import("./agent-daemon.js"),e=j();try{const s=new r(e.getDatabase());switch(i){case"init":case"start":{const o=Math.max(10,Math.min(I(t.interval,600),86400)),n=s.start({interval_seconds:o,max_steps:t["max-steps"]!==void 0&&I(t["max-steps"],0)||void 0,project_path:t.project,verbose:t.verbose===!0});if(!n.ok){m(`Agent init failed: ${n.error}`),process.exitCode=1;return}const p=n.status;b(`Agent ${p.pid!=null&&p.pid!==n.pid?"already running":"started"} \u2014 pid ${p.pid}`),console.log(` Interval: ${o}s \xB7 Active goals: ${p.active_goals} \xB7 Total iterations: ${p.total_iterations}`),console.log(d.dim(` Log: ${p.log_file}`));return}case"status":{const o=s.status();k("Wyrm agent"),console.log(o.running?` RUNNING \u2014 pid ${o.pid}${o.started_at?` (since ${o.started_at})`:""}`:" NOT RUNNING. Start it with: wyrm agent init"),console.log(` Active goals: ${o.active_goals} \xB7 Total iterations: ${o.total_iterations}`),o.last_action&&console.log(` Last action (${o.last_action.ran_at}): ${o.last_action.summary} [${o.last_action.result_status??"?"}]`),t.log===!0&&(console.log(`
|
|
83
|
+
=== Recent log ===`),console.log(s.recentLog(40)));return}case"stop":{const o=await s.stop({grace_ms:t.grace!==void 0?I(t.grace,3e3):void 0});if(!o.ok){m(`Stop failed: ${o.error}`),process.exitCode=1;return}b(o.was_running?`Agent stopped (was pid ${o.pid}). Goals remain in DB \u2014 wyrm agent init resumes.`:"Agent was not running. (No-op.)");return}case"restart":{const o=await s.restart({interval_seconds:t.interval!==void 0?I(t.interval,600):void 0,max_steps:t["max-steps"]!==void 0&&I(t["max-steps"],0)||void 0,project_path:t.project,verbose:t.verbose===!0});if(!o.ok){m(`Restart failed: ${o.error}`),process.exitCode=1;return}b(`Agent restarted \u2014 pid ${o.status.pid}. Active goals: ${o.status.active_goals}.`);return}default:m("Usage: wyrm agent <init|status|stop|restart> [--interval N] [--max-steps N] [--project <path>] [--verbose] [--log]"),process.exitCode=1}}finally{e.close()}}async function Rt(l){if(l.includes("--encrypt")){const{initializeLicense:i,hasFeature:r}=await import("./license.js");if(i(),!r("encryption")){m("Encryption setup requires a Pro license or higher. See: wyrm license"),process.exitCode=1;return}const{getCrypto:e,initializeCrypto:s}=await import("./crypto.js"),o=l.includes("--enable"),n=l.includes("--test");if(o){const a=process.env.WYRM_ENCRYPTION_KEY??(process.stdin.isTTY?"":we());if(!a||a.length<8){m('Password must be at least 8 characters. Set WYRM_ENCRYPTION_KEY or pipe it: printf %s "$PW" | wyrm setup --encrypt --enable'),process.exitCode=1;return}s(a),b("Encryption enabled (AES-256-GCM, key derived via PBKDF2). Store your password safely \u2014 it cannot be recovered.");return}const p=e();if(n){if(!p.isEnabled()){m("Encryption not enabled. Run: wyrm setup --encrypt --enable"),process.exitCode=1;return}const a="Wyrm encryption test "+Date.now();p.decrypt(p.encrypt(a))===a?b("Encryption test PASSED (encrypt \u2192 decrypt roundtrip)."):(m("Encryption test FAILED."),process.exitCode=1);return}k("Encryption status"),console.log(` Enabled: ${p.isEnabled()?"yes \u2014 new data is encrypted at rest":"no"}`),console.log(" Algorithm: AES-256-GCM"),p.isEnabled()||console.log(d.dim(" Enable with: wyrm setup --encrypt --enable (password via WYRM_ENCRYPTION_KEY or stdin)"));return}const c=re(ne(import.meta.url)),t=z(process.execPath,[F(c,"setup.js"),...l],{stdio:"inherit",shell:!1});process.exitCode=t.status??0}async function xt(l){const c="https://github.com/Ghosts-Protocol-Pvt-Ltd/wyrm-mcp",i=`- wyrm-mcp: ${M().version??"unknown"}
|
|
83
84
|
- node: ${process.version}
|
|
84
|
-
- platform: ${process.platform} ${process.arch}`,
|
|
85
|
+
- platform: ${process.platform} ${process.arch}`,r=l.includes("--bug")?"bug":l.includes("--idea")||l.includes("--feature")?"idea":l.includes("--question")||l.includes("--ask")?"question":"feedback",e=l.filter(p=>!p.startsWith("--")).join(" ").trim(),s={bug:`**What happened**
|
|
85
86
|
|
|
86
87
|
|
|
87
88
|
**What you expected**
|
|
@@ -107,54 +108,57 @@ ${i}`,feedback:`**Your feedback** (what's working, what's rough)
|
|
|
107
108
|
|
|
108
109
|
|
|
109
110
|
---
|
|
110
|
-
${i}`},o={bug:"bug",idea:"enhancement",question:"question",feedback:"feedback"};let n;
|
|
111
|
+
${i}`},o={bug:"bug",idea:"enhancement",question:"question",feedback:"feedback"};let n;r==="question"?n=`${c}/discussions/new?category=q-a`+(e?`&title=${encodeURIComponent(e)}`:"")+`&body=${encodeURIComponent(s.question)}`:n=`${c}/issues/new?labels=${encodeURIComponent(o[r])}&title=${encodeURIComponent(`[${r}] ${e}`.trim())}&body=${encodeURIComponent(s[r])}`,console.log(""),console.log(" "+d.bold("Thanks for helping make Wyrm better.")),console.log(" Opening a prefilled report in your browser. If it does not open, use this link:"),console.log(""),console.log(" "+d.cyan(n)),console.log(""),console.log(d.dim(" Prefer email? ryan@ghosts.lk \xB7 Bug: wyrm feedback --bug Idea: --idea Question: --question")),console.log("");try{const{spawn:p}=await import("child_process"),a=process.platform,u=a==="darwin"?p("open",[n],{stdio:"ignore",detached:!0}):a==="win32"?p("cmd",["/c","start","",n],{stdio:"ignore",detached:!0}):p("xdg-open",[n],{stdio:"ignore",detached:!0});u.on("error",()=>{}),u.unref()}catch{}}function be(){console.log(`
|
|
111
112
|
${N.brightMagenta}\u{F115D} Wyrm CLI v${M().version??"unknown"}${N.reset}
|
|
112
113
|
${N.dim}Persistent AI Memory System${N.reset}
|
|
113
114
|
|
|
114
|
-
${
|
|
115
|
-
|
|
116
|
-
${
|
|
117
|
-
${
|
|
118
|
-
${
|
|
119
|
-
${
|
|
120
|
-
${
|
|
121
|
-
${
|
|
122
|
-
${
|
|
123
|
-
${
|
|
124
|
-
${
|
|
125
|
-
${
|
|
126
|
-
${
|
|
127
|
-
${
|
|
128
|
-
${
|
|
129
|
-
${
|
|
130
|
-
${
|
|
131
|
-
${
|
|
132
|
-
${
|
|
133
|
-
${
|
|
134
|
-
${
|
|
135
|
-
${
|
|
136
|
-
${
|
|
137
|
-
${
|
|
138
|
-
${
|
|
139
|
-
${
|
|
140
|
-
${
|
|
141
|
-
${
|
|
142
|
-
${
|
|
143
|
-
${
|
|
144
|
-
${
|
|
145
|
-
${
|
|
146
|
-
${
|
|
147
|
-
${
|
|
148
|
-
${
|
|
149
|
-
${
|
|
150
|
-
${
|
|
151
|
-
${
|
|
152
|
-
${
|
|
153
|
-
${
|
|
154
|
-
${
|
|
155
|
-
${
|
|
156
|
-
|
|
157
|
-
${
|
|
115
|
+
${d.bold("Usage:")} wyrm <command> [options]
|
|
116
|
+
|
|
117
|
+
${d.bold("Commands:")}
|
|
118
|
+
${d.cyan("search")} <query> Search across memories, truths, quests, and data
|
|
119
|
+
${d.cyan("ls")} List stored items
|
|
120
|
+
${d.cyan("show")} <typed-id> Show full detail (mem:N, quest:N, truth:N, data:N, session:N)
|
|
121
|
+
${d.cyan("capture")} "<content>" Classify and capture a thought, task, or lesson
|
|
122
|
+
${d.cyan("rehydrate")} [--project <name>] Print the latest session's continuity brief (for SessionStart)
|
|
123
|
+
${d.cyan("session log")} [--run <id>] [--\u2026] Create/update this project's session record (rehydrate's write side)
|
|
124
|
+
${d.cyan("presence")} <announce|list|release> Agent presence board from the shell; --pid = process-identity liveness
|
|
125
|
+
${d.cyan("digest")} --writes [--since <days>] What Wyrm learned, queued, and refused \u2014 the offline write-receipt report
|
|
126
|
+
${d.cyan("bridge")} <init|status|run> The substrate flow: remember/render/reverse lanes from one receipted config
|
|
127
|
+
${d.cyan("metabolize")} [--dry-run] Memory metabolism: supersede exact dupes, queue near-dup candidates, decay stale auto-captures
|
|
128
|
+
${d.cyan("render")} [--client <list>] [--brief] Compile DB \u2192 MEMORY.md + topic files (zero-MCP-token memory)
|
|
129
|
+
${d.cyan("import git")} Import git log history to review queue
|
|
130
|
+
${d.cyan("import rules")} <path> Import .cursorrules / copilot-instructions file
|
|
131
|
+
${d.cyan("stats")} Show database statistics
|
|
132
|
+
${d.cyan("review")} Interactively review pending artifacts
|
|
133
|
+
${d.cyan("sync export")} --out <path> Export encrypted DB snapshot
|
|
134
|
+
${d.cyan("sync import")} --from <path> Restore from encrypted snapshot (backs up first)
|
|
135
|
+
${d.cyan("sync preview")} --from <path> Preview snapshot stats without restoring
|
|
136
|
+
${d.cyan("prune")} [--project <name>] Prune stale low-confidence artifacts (dry-run by default)
|
|
137
|
+
${d.cyan("cloud")} <login|sync|export|\u2026> Cloud backup & multi-device sync (Pro license)
|
|
138
|
+
${d.cyan("grove")} <status|policy> Per-project sync lanes (private|cloud|team) + leak audit
|
|
139
|
+
${d.cyan("run")} <start|join|end|status> Fleet-run lifecycle (records the migration-20 runs/run_agents tables)
|
|
140
|
+
${d.cyan("events")} [since|publish] [--project] Live-Memory event stream: read (since) or publish (was undocumented \u2014 tallow, 2026-07-14)
|
|
141
|
+
${d.cyan("skill")} <list|backfill-content|export|share> Discover bundled guides; store/sync SKILL.md content
|
|
142
|
+
${d.cyan("serve")} [--ui] Start the Wyrm HTTP server (optionally open the dashboard)
|
|
143
|
+
${d.cyan("setup")} [--check|--encrypt|\u2026] Auto-configure AI clients (wyrm-setup); --encrypt for at-rest crypto
|
|
144
|
+
${d.cyan("guard")} [--remove|--status] Failure-firewall PreToolUse hooks for Claude Code (wyrm-guard)
|
|
145
|
+
${d.cyan("intro")} What Wyrm is and how to use it
|
|
146
|
+
${d.cyan("license")} Show license status & features
|
|
147
|
+
${d.cyan("login")} Sign in (free account) and activate \u2014 required on official builds
|
|
148
|
+
${d.cyan("activate")} <key|path> Activate a license (JSON arg, file path, or stdin)
|
|
149
|
+
${d.cyan("maintenance")} [--vacuum] Archive/prune/sweep/checkpoint the database
|
|
150
|
+
${d.cyan("index")} <setup|rebuild|status> Vector search: verify provider, reindex, stats
|
|
151
|
+
${d.cyan("doctor")} Health check that refuses to flatter \u2014 reports anything silently degraded
|
|
152
|
+
${d.cyan("failure")} <list|resolve> Failure firewall: list unresolved patterns, resolve a fixed one
|
|
153
|
+
${d.cyan("project")} <add|list> Register a project without needing a session start
|
|
154
|
+
${d.cyan("update")} [--check] Check for / install the latest wyrm-mcp
|
|
155
|
+
${d.cyan("prompt")} <inject|migrate> Inject/refresh the session-prime block in client files
|
|
156
|
+
${d.cyan("hours")} report --from --to Hours report derived from session history
|
|
157
|
+
${d.cyan("invoice")} generate --client \u2026 Markdown invoice from the hours ledger
|
|
158
|
+
${d.cyan("agent")} <init|status|stop|restart> Background agent daemon (goal loop)
|
|
159
|
+
${d.cyan("feedback")} [--bug|--idea|--question] Send feedback or report a bug (opens a prefilled GitHub report)
|
|
160
|
+
|
|
161
|
+
${d.bold("Options:")}
|
|
158
162
|
--project <name> Filter or associate with a specific project
|
|
159
163
|
--type <type> Filter type (memories|truths|quests|data|all)
|
|
160
164
|
--limit <N> Limit number of results (default: 20)
|
|
@@ -171,26 +175,26 @@ ${p.bold("Options:")}
|
|
|
171
175
|
--help, -h Show this help
|
|
172
176
|
--version, -v Print the installed version
|
|
173
177
|
|
|
174
|
-
${
|
|
178
|
+
${d.bold("Environment:")}
|
|
175
179
|
WYRM_DB_PATH Override database path (default: ~/.wyrm/wyrm.db)
|
|
176
180
|
WYRM_SYNC_PASSPHRASE Passphrase for encrypted sync (or prompted interactively)
|
|
177
181
|
|
|
178
|
-
${
|
|
182
|
+
${d.bold("Examples:")}
|
|
179
183
|
wyrm search "authentication bug"
|
|
180
184
|
wyrm ls --type memories --project MyApp
|
|
181
185
|
wyrm capture "TODO: refactor the auth module" --project MyApp
|
|
182
186
|
wyrm sync export --out ~/wyrm-backup.wyrm
|
|
183
187
|
wyrm sync preview --from ~/wyrm-backup.wyrm
|
|
184
188
|
wyrm prune --project MyApp --min-confidence 0.2 --older-than 30
|
|
185
|
-
`)}const[,,O
|
|
186
|
-
`).find(g=>g.trim())??"").trim();else{const
|
|
189
|
+
`)}const[,,O,...v]=process.argv;function $e(l){const c=l.ref_table?`${l.ref_table}${l.ref_id?"#"+l.ref_id:""}`:"",t=new Date(l.created_at).toLocaleTimeString();return`#${l.cursor} ${l.kind.padEnd(15)} ${c.padEnd(16)} ${Be(l.actor)} ${t}`}async function Tt(l){const{positional:c,flags:t}=C(l),i=c[0]||"since",r=j();try{if(!r.liveMemoryEnabled()){m("Live Memory is disabled (set WYRM_LIVE_MEMORY=1)."),process.exitCode=1;return}const e=(typeof t.project=="string"?t.project:"")||process.cwd(),s=r.getProject(e)??r.getProjectByName(e);if(!s){m(`Project not found: ${e}`),process.exitCode=1;return}if(i==="publish"){const o=c[1]||(typeof t.kind=="string"?t.kind:"");if(!o){m("usage: wyrm events publish <kind> --project <p> [--actor A] [--ref-table T --ref-id ID]"),process.exitCode=1;return}r.publishEvent({projectId:s.id,kind:o,refTable:typeof t["ref-table"]=="string"?t["ref-table"]:void 0,refId:typeof t["ref-id"]=="string"?t["ref-id"]:void 0,actor:typeof t.actor=="string"?t.actor:void 0}),b(`Event published (${o}) to ${s.name}`);return}if(i==="since"){const o=I(t.cursor,0),n=I(t.limit,50),p=r.eventsSince(s.id,o,n);for(const a of p)console.log($e(a));k(`${p.length} event(s) for '${s.name}' since cursor ${o}`);return}m("usage: wyrm events <publish|since> ..."),process.exitCode=1}finally{r.close()}}async function Dt(l){const{flags:c}=C(l),t=j();if(!t.liveMemoryEnabled()){m("Live Memory is disabled (set WYRM_LIVE_MEMORY=1)."),t.close(),process.exitCode=1;return}const i=(typeof c.project=="string"?c.project:"")||process.cwd(),r=t.getProject(i)??x(t,i);if(!r){m(`Project not found: ${i}`),t.close(),process.exitCode=1;return}const e=Math.max(250,I(c.interval,1e3));let s=I(c.since,t.subscribeEvents(r.id,1).cursor);k(`Watching '${r.name}' (cursor ${s}, every ${e}ms) \u2014 Ctrl-C to stop`);const o=()=>{try{for(const a of t.eventsSince(r.id,s,200))s=a.cursor,console.log($e(a))}catch{}};o();const n=setInterval(o,e),p=()=>{clearInterval(n);try{t.close()}catch{}process.exit(0)};process.on("SIGINT",p),process.on("SIGTERM",p)}async function It(l){const{flags:c}=C(l),{embedAll:t,removeAll:i,statusAll:r}=await import("./priority-embed.js"),e={projectDir:typeof c.project=="string"?c.project:void 0,allClients:c.all===!0},s=o=>console.log(` ${String(o.result??o.status).padEnd(9)} [${o.scope}] ${o.file}`);if(c.status){k("Wyrm priority embedding \u2014 status"),r(e).forEach(s);return}if(c.remove){k("Wyrm priority embedding \u2014 removed"),i(e).forEach(s);return}k("Wyrm is now FIRST-PRIORITY memory"),t(e).forEach(s);try{const{installClaudeCodeHooks:o,installClaudeStatusline:n}=await import("./autoconfig.js");o()?b("Proactive hooks installed (SessionStart rehydrate + capture + tool-trace)."):console.log(" (Claude Code not detected \u2014 skipped hook install.)");const a=n();a&&b(`Buddy statusline: ${a.message}`)}catch{}b("Wyrm will now be read first, primed proactively, and shown in the TUI at all times.")}async function Pt(l){const{flags:c}=C(l),{harvestProjects:t}=await import("./harvest.js"),{MemoryArtifacts:i}=await import("./memory-artifacts.js"),{escapeLikePattern:r}=await import("./auto-capture.js"),e=j();try{const s=e.getDatabase(),o=new i(s),n={existsBySig:(w,$)=>!!s.prepare("SELECT 1 FROM memory_artifacts WHERE project_id = ? AND tags LIKE ? ESCAPE '\\' LIMIT 1").get(w,"%"+r($)+"%"),addCandidate:(w,$)=>o.add(w,{kind:$.kind,problem:$.text,tags:[...$.tags,$.sig],confidence:$.confidence,needsReview:1,createdBy:"harvest"})},p=typeof c.project=="string"?c.project:void 0;let a;if(p){const w=e.getProject(p)??e.getProjectByName(p);if(!w){m(`Project not found: ${p}`),process.exitCode=1;return}a=[{id:w.id,name:w.name,path:w.path}]}else a=e.getAllProjects(500).map(w=>({id:w.id,name:w.name,path:w.path}));const u=c["dry-run"]===!0||c.dry===!0,g=c.code===!0||c["include-code"]===!0,{reports:f,totalAdded:y,totalSkipped:h}=t(n,a,{dryRun:u,gitLimit:I(c.limit,30),includeCode:g});k(`Harvest ${u?"(dry run) ":""}\u2014 ${y} candidate(s), ${h} already present (${a.length} project(s))`);for(const w of f.filter($=>$.added>0).sort(($,E)=>E.added-$.added).slice(0,25))console.log(` +${String(w.added).padStart(3)} (skip ${w.skipped}) ${w.project}`);if(g&&!u){const{SymbolGraph:w}=await import("./symbols.js"),$=new w(s);let E=0,_=0;for(const R of a)try{const S=$.indexProject(R.id,R.path);E+=S.symbols,_+=S.files}catch{}console.log(` \u{1F4D0} Indexed ${E} code symbols (${_} files) \u2192 searchable via 'wyrm search'`)}!u&&y>0&&b("Review with: wyrm review")}finally{e.close()}}async function Nt(l){const c=await import("./vault.js"),[t,...i]=l;try{switch(t){case"set":{const r=i[0];if(!r){m("usage: wyrm vault set <name> (the secret is read from STDIN, never argv)"),process.exitCode=1;return}if(process.stdin.isTTY){m(`pipe the secret in, e.g.: printf %s "$TOKEN" | wyrm vault set ${r}`),process.exitCode=1;return}const s=(await import("node:fs")).readFileSync(0,"utf8").replace(/\r?\n$/,"");if(!s){m("empty secret on stdin"),process.exitCode=1;return}c.vaultSet(r,s),b(`Stored "${r}" (AES-256-GCM). Use it without exposing it: wyrm vault exec ${r} -- <command>`);break}case"get":{const r=i[0];if(!r){m("usage: wyrm vault get <name>"),process.exitCode=1;return}const e=c.vaultGet(r);if(e===void 0){m(`no secret named "${r}"`),process.exitCode=1;return}process.stdout.write(e);break}case"list":case"ls":{const r=c.vaultList();if(!r.length){console.log("(vault is empty)");break}k(`Vault \u2014 ${r.length} secret(s)`);for(const e of r)console.log(" \u2022 "+e);break}case"rm":case"remove":case"delete":{const r=i[0];if(!r){m("usage: wyrm vault rm <name>"),process.exitCode=1;return}b(c.vaultRemove(r)?`Removed "${r}"`:`(no secret named "${r}")`);break}case"exec":{const r=i[0],e=i.indexOf("--");if(!r||e===-1||e+1>=i.length){m("usage: wyrm vault exec <name> [--as ENVVAR] -- <command...>"),process.exitCode=1;return}const s=i.slice(1,e),o=s.indexOf("--as"),n=o>=0?s[o+1]:r.toUpperCase().replace(/[^A-Z0-9]+/g,"_"),p=i.slice(e+1),a=c.vaultGet(r);if(a===void 0){m(`no secret named "${r}"`),process.exitCode=1;return}const u=z(p[0],p.slice(1),{stdio:"inherit",env:{...process.env,[n]:a}});process.exitCode=u.status??1;break}case"import-npm":{const r=await import("node:fs"),e=await import("node:os"),o=(await import("node:path")).join(e.homedir(),".npmrc");if(!r.existsSync(o)){m("~/.npmrc not found"),process.exitCode=1;return}const n=r.readFileSync(o,"utf8").match(/\/\/registry\.npmjs\.org\/:_authToken=(.+)/);if(!n){m("no npm authToken found in ~/.npmrc"),process.exitCode=1;return}c.vaultSet("npm-token",n[1].trim()),b('Imported npm token \u2192 vault as "npm-token". You can now scrub the plaintext from ~/.npmrc and use: wyrm vault exec npm-token --as NODE_AUTH_TOKEN -- npm publish');break}case"setup":{const r=c.vaultPaths();if(r.secure)b(`Vault is already secure (backend: ${r.backend}, ${r.count} secret(s)).`);else{const e=r.keychainAvailable?"keychain":"passphrase";if(e==="passphrase"&&!process.env.WYRM_VAULT_PASSPHRASE){m("No OS keychain on this host. Set WYRM_VAULT_PASSPHRASE, then re-run: wyrm vault setup"),process.exitCode=1;return}const s=c.vaultSecure({backend:e});b(`Vault secured: ${s.from} \u2192 ${s.to}${s.rotated?" (key rotated)":""}.`),s.keyfileShredded&&console.log(" plaintext vault.key: shredded \u2714"),s.backup&&console.log(` ciphertext backup: ${s.backup} (delete once confirmed)`)}k("Store & use credentials safely"),console.log(' store: printf %s "$TOKEN" | wyrm vault set <name> # reads STDIN \u2014 never argv/shell history'),console.log(" use: wyrm vault exec <name> --as ENV_VAR -- <cmd> # injected as env var, never printed"),console.log(" list: wyrm vault list inspect: wyrm vault info");break}case"secure":{const r=i.indexOf("--backend"),e=r>=0?i[r+1]:"keychain";if(e!=="keychain"&&e!=="passphrase"){m("usage: wyrm vault secure [--backend keychain|passphrase] [--no-rotate]"),process.exitCode=1;return}if(e==="passphrase"&&!process.env.WYRM_VAULT_PASSPHRASE){m("set WYRM_VAULT_PASSPHRASE before: wyrm vault secure --backend passphrase"),process.exitCode=1;return}const s=!i.includes("--no-rotate"),o=c.vaultSecure({backend:e,rotate:s});b(`Vault secured: ${o.from} \u2192 ${o.to}${o.rotated?" (key rotated)":""}.`),console.log(` secrets re-encrypted: ${o.secrets}`),o.keyfileShredded&&console.log(" plaintext vault.key: shredded \u2714"),o.backup&&console.log(` ciphertext backup: ${o.backup} (delete once you've confirmed)`),console.log(e==="keychain"?" master key now lives in the OS keychain \u2014 not on disk.":" master key now derived from WYRM_VAULT_PASSPHRASE \u2014 keep that set for future use.");break}case"info":{const r=c.vaultPaths();k("Vault"),console.log(` backend: ${r.backend}`),console.log(` secrets: ${r.count}`),console.log(` store: ${r.vault} (0600)`),console.log(` key: ${r.backend==="keyfile"?r.key+" (0600)":r.backend==="keychain"?"(OS keychain \u2014 no key on disk)":"(derived from WYRM_VAULT_PASSPHRASE \u2014 no key on disk)"}`),console.log(` secure: ${r.secure?"yes \u2014 key is not a plaintext file beside the ciphertext":"NO \u2014 key sits beside ciphertext"}`),r.secure||console.log(r.keychainAvailable?" \u26A0 run `wyrm vault secure` to move the key into the OS keychain.":" \u26A0 no OS keychain found \u2014 set WYRM_VAULT_PASSPHRASE and run `wyrm vault secure --backend passphrase`.");break}default:m("usage: wyrm vault <setup|set|get|list|rm|exec|import-npm|secure|info>"),process.exitCode=1}}catch(r){m(`vault: ${r.message}`),process.exitCode=1}}function Mt(){const l=re(ne(import.meta.url)),t=[F(l,"..","skills"),F(l,"..","..","skills")].find(r=>q(r));if(!t)return[];const i=[];for(const r of Me(t,{withFileTypes:!0})){if(!r.isDirectory())continue;const e=F(t,r.name,"SKILL.md");if(!q(e))continue;let s=r.name,o="";try{const n=V(e,"utf8"),p=n.match(/^name:\s*(.+)$/m);if(p&&(s=p[1].trim()),/^description:\s*[|>]/m.test(n))o=((n.split(/^description:.*$/m)[1]??"").split(`
|
|
190
|
+
`).find(g=>g.trim())??"").trim();else{const a=n.match(/^description:\s*(.+)$/m);a&&(o=a[1].trim())}}catch{}i.push({name:s,description:o})}return i.sort((r,e)=>r.name.localeCompare(e.name))}async function Ot(l){const c=l[0];if(!c||c==="help"||c==="--help"){console.log(`Usage:
|
|
187
191
|
wyrm skill list show the bundled guides + your registered skills
|
|
188
192
|
wyrm skill backfill-content read every skill's SKILL.md into the registry (idempotent)
|
|
189
193
|
wyrm skill export <targetDir> [--all] materialize SKILL.md files from stored content
|
|
190
|
-
wyrm skill share <name|--all|--tier T> [--public|--private] [--include-inactive] set cloud-sync visibility (single or bulk)`);return}if(
|
|
191
|
-
private = never replicates . cloud = your own cloud backup . team = federates to a team Wyrm`),
|
|
192
|
-
! ${
|
|
194
|
+
wyrm skill share <name|--all|--tier T> [--public|--private] [--include-inactive] set cloud-sync visibility (single or bulk)`);return}if(c==="list"||c==="ls"){const i=Mt();if(k("Bundled skill guides (shipped in the box)"),i.length===0)console.log(d.yellow(" none found next to this install"));else{for(const e of i)console.log(` ${d.cyan(e.name)}`),e.description&&console.log(` ${d.dim(e.description)}`);console.log(d.dim("\n Read one: open its SKILL.md, or `wyrm skill export <dir>` to materialize all."))}const r=j();try{const e=r.listSkills(!0);if(k(`Registered skills in your memory (${e.length})`),e.length===0)console.log(d.dim(" none yet \u2014 register with wyrm_skill_register or author with wyrm_skill_create"));else{for(const s of e.slice(0,40))console.log(` ${d.cyan(s.name)}${s.tier?d.dim(" ["+s.tier+"]"):""}`);e.length>40&&console.log(d.dim(` \u2026 and ${e.length-40} more`))}}finally{r.close()}return}const t=j();try{if(c==="backfill-content"||c==="backfill"){k("Backfill SKILL.md content into the registry");const i=t.backfillSkillContent();b(`${i.filled} filled . ${i.unchanged} unchanged . ${i.missing} missing-file (of ${i.total} registered)`),i.missing>0&&console.log(d.yellow(` ${i.missing} skill(s) had no readable SKILL.md \u2014 re-run after restoring their files.`));return}if(c==="export"){const i=l[1];i||(m("Usage: wyrm skill export <targetDir> [--all]"),t.close(),process.exit(1));const r=l.includes("--all");k(`Export skills \u2192 ${i}`);const e=t.exportSkillContent(i,{includeInactive:r});b(`${e.written} SKILL.md written . ${e.skipped_no_content} skipped (no stored content) (of ${e.total} ${r?"total":"active"})`),e.skipped_no_content>0&&console.log(d.yellow(" Run `wyrm skill backfill-content` on the source machine to populate content first.")),e.collisions>0&&console.log(d.yellow(` ${e.collisions} slug collision(s) disambiguated with a name-hash suffix (distinct skills, same slug) \u2014 no content lost.`));return}if(c==="share"){const i=l.includes("--private")?"within":l.includes("--public")?"public":"org",r=l.includes("--include-inactive"),e=l.indexOf("--tier"),s=e>=0?l[e+1]:void 0;if(e>=0&&(!s||s.startsWith("--"))&&(m("Usage: wyrm skill share --tier <god|mega|atomic> [--public|--private] [--include-inactive]"),t.close(),process.exit(1)),l.includes("--all")||!!s){const a=t.setAllSkillsVisibility(i,{tier:s,includeInactive:r}),u=s?`tier '${s}'`:r?"all skills":"all active skills";b(`${a} skill(s) (${u}) visibility \u2192 '${i}'.`),console.log(i==="within"?" These skills will NOT egress on cloud sync (private).":` ${a} skills are now cloud-sync-eligible (they leave on the next \`wyrm cloud sync\`).`);return}const n=l[1];n||(m("Usage: wyrm skill share <name|--all|--tier <tier>> [--public|--private] [--include-inactive]"),t.close(),process.exit(1)),t.setSkillVisibility(n,i)||(m(`Skill not found: ${n}`),t.close(),process.exit(1)),b(`Skill "${n}" visibility \u2192 '${i}'.`),console.log(i==="within"?" This skill will NOT egress on cloud sync (private).":" This skill is now cloud-sync-eligible (it leaves on the next `wyrm cloud sync`).");return}m(`Unknown skill subcommand: ${c}`),process.exit(1)}finally{t.close()}}async function At(l){const c=l[0]??"status",t=j(),i=t.getDatabase();if(i.prepare("PRAGMA table_info(projects)").all().some(e=>e.name==="sync_policy")||(m("Grove sync policy is not on this database yet (upgrade Wyrm so migrations apply)."),t.close(),process.exit(1)),c==="status"||c==="ls"||c==="list"){k("Grove sync policy + leak audit");const e=i.prepare("SELECT id, name, sync_policy FROM projects ORDER BY id").all(),s=["ground_truths","memory_artifacts","quests","design_tokens","design_references"],o=["ground_truths","memory_artifacts","quests","sessions","decision_edges"],n=(u,g,f)=>{let y=0;for(const h of u)try{y+=i.prepare(`SELECT COUNT(*) AS n FROM ${h} WHERE project_id = ? AND ${f}`).get(g).n}catch{}return y},p=[];let a=0;for(const u of e){const g=n(s,u.id,"cross_project_visibility IN ('org','public')"),f=n(o,u.id,"is_shared = 1"),y=u.sync_policy==="private"&&g+f>0;y&&a++;const h=y?d.red(`LEAK: ${g} promoted + ${f} shared in a PRIVATE grove`):`${g} promoted / ${f} shared`;p.push([String(u.id),u.name,u.sync_policy,h])}console.log(D(["#","Grove","sync_policy","rows eligible to leave"],p)),console.log(`
|
|
195
|
+
private = never replicates . cloud = your own cloud backup . team = federates to a team Wyrm`),a>0&&console.log(d.red(`
|
|
196
|
+
! ${a} private grove(s) hold rows marked to leave. Re-private those rows or change the grove lane.`)),t.close();return}if(c==="policy"||c==="set"){const e=l[1],s=l[2];(!e||!["private","cloud","team"].includes(s))&&(m("Usage: wyrm grove policy <project|id> <private|cloud|team>"),t.close(),process.exit(1));let o=x(t,e);!o&&/^\d+$/.test(e)&&(o=i.prepare("SELECT id, name FROM projects WHERE id = ?").get(Number(e))),o||(m(`Grove not found: ${e}`),t.close(),process.exit(1)),i.prepare("UPDATE projects SET sync_policy = ? WHERE id = ?").run(s,o.id),b(`Grove "${o.name}" set to '${s}'.`),s!=="private"&&console.log(` Rows still only leave when also marked ${s==="team"?"is_shared (team)":"org/public (cloud)"}. The grove is the outer gate.`),t.close();return}m(`Unknown grove subcommand: ${c}`),console.log(`Usage:
|
|
193
197
|
wyrm grove status
|
|
194
|
-
wyrm grove policy <project|id> <private|cloud|team>`),
|
|
195
|
-
`),process.stderr.write(`Run ${w} started by ${
|
|
196
|
-
`);break}case"join":{const
|
|
198
|
+
wyrm grove policy <project|id> <private|cloud|team>`),t.close(),process.exit(1)}async function Lt(l){const c=l[0],{flags:t}=C(l.slice(1)),{ulid:i}=await import("./ulid.js"),{createRun:r,setRunStatus:e,registerAgent:s,getRun:o,getAgents:n}=await import("./handlers/run.js"),{sanitizeActorId:p}=await import("./handlers/boundary.js"),a=f=>typeof f=="string"?p(f):null,u=j(),g=u.getDatabase();try{switch(c){case"start":{const f=(typeof t.orchestrator=="string"?t.orchestrator:"cli").slice(0,200),y=a(t.agent)??p(f)??"cli",h=a(t.parent);if(h&&!o(g,h)){m(`Parent run not found: ${h}`),process.exitCode=1;return}const w=i();r(g,w,h,f),s(g,w,y,"orchestrator"),process.stdout.write(w+`
|
|
199
|
+
`),process.stderr.write(`Run ${w} started by ${f}.
|
|
200
|
+
`);break}case"join":{const f=a(t.run),y=a(t.agent);if(!f||!y){m("Usage: wyrm run join --run <RUNID> --agent <ID> [--role <ROLE>]"),process.exitCode=1;return}if(!o(g,f)){m(`Run not found: ${f}`),process.exitCode=1;return}const h=typeof t.role=="string"?t.role.slice(0,200):null;s(g,f,y,h),b(`${y} joined run ${f}${h?` as ${h}`:""}.`);break}case"end":{const f=a(t.run);if(!f){m("Usage: wyrm run end --run <RUNID> [--status completed|failed|abandoned]"),process.exitCode=1;return}if(!o(g,f)){m(`Run not found: ${f}`),process.exitCode=1;return}const y=typeof t.status=="string"?t.status:"completed",w=["completed","failed","abandoned"].includes(y)?y:"completed";e(g,f,w),b(`Run ${f} ended (${w}).`);break}case"status":{const f=a(t.run);if(!f){m("Usage: wyrm run status --run <RUNID>"),process.exitCode=1;return}const y=o(g,f);if(!y){m(`Run not found: ${f}`),process.exitCode=1;return}const h=n(g,f);k(`Run ${y.run_id} [${y.status}]`),y.orchestrator&&console.log(d.bold("Orchestrator: ")+y.orchestrator),y.parent_run_id&&console.log(d.bold("Parent: ")+y.parent_run_id),console.log(d.bold("Created: ")+y.created_at),console.log(d.bold("Updated: ")+y.updated_at),h.length>0?console.log(D(["Agent","Role","Joined"],h.map(w=>[w.agent_id,w.role??"",w.joined_at]))):console.log(d.dim(" No agents registered."));break}default:m("Usage: wyrm run <start|join|end|status> [options]"),console.log(" wyrm run start [--orchestrator NAME] [--agent ID] [--parent RUNID]"),console.log(" wyrm run join --run RUNID --agent ID [--role ROLE]"),console.log(" wyrm run end --run RUNID [--status completed|failed|abandoned]"),console.log(" wyrm run status --run RUNID"),process.exitCode=1;return}}finally{u.close()}}if(O==="--version"||O==="-v"||O==="version"){const l=M();console.log(`${l.name??"wyrm-mcp"} v${l.version??"unknown"}`)}else!O||O==="--help"||O==="-h"||O==="help"?be():(async()=>{try{switch(O){case"search":await Ge(v);break;case"ls":await Je(v);break;case"show":await ze(v);break;case"capture":await Qe(v);break;case"rehydrate":await Ze(v);break;case"session":await st(v);break;case"presence":await rt(v);break;case"digest":await Xe(v);break;case"bridge":await ot(v);break;case"metabolize":await et(v);break;case"entities":await tt(v);break;case"render":await nt(v);break;case"reverse-bridge":await it(v);break;case"import":await at(v);break;case"stats":await lt(v);break;case"review":await dt(v);break;case"sync":await pt(v);break;case"cloud":{const{cmdCloud:l}=await import("./cloud/cli.js");await l(v);break}case"grove":await At(v);break;case"run":await Lt(v);break;case"skill":await Ot(v);break;case"prune":await ut(v);break;case"license":await ft();break;case"login":await gt();break;case"activate":await yt(v);break;case"maintenance":await ht(v);break;case"doctor":await wt(v);break;case"failure":await bt(v);break;case"project":await $t(v);break;case"index":await vt(v);break;case"update":await St(v);break;case"prompt":await _t(v);break;case"hours":await jt(v);break;case"invoice":await Ct(v);break;case"agent":await Et(v);break;case"feedback":await xt(v);break;case"setup":await Rt(v);break;case"intro":{const{renderIntro:l}=await import("./visibility.js");console.log(l(M().version??"unknown"));break}case"events":await Tt(v);break;case"watch":await Dt(v);break;case"embed":await It(v);break;case"harvest":await Pt(v);break;case"vault":await Nt(v);break;case"connector":case"connectors":await mt(v);break;case"statusline":{const{installClaudeStatusline:l,removeClaudeStatusline:c}=await import("./autoconfig.js"),t=v.includes("--remove")?c():l();t?b(t.message):m("Claude Code not detected (~/.claude missing).");break}case"guard":{const{installWyrmGuardHooks:l,removeWyrmGuardHooks:c,wyrmGuardHookStatus:t}=await import("./autoconfig.js");if(v.includes("--status")){const r=t();if(console.log(` settings: ${r.settingsPath}`),r.installed){b(`wyrm-guard hooks installed (${r.commands.length} entr${r.commands.length===1?"y":"ies"})`);for(const e of r.commands)console.log(d.dim(` ${e}`))}else console.log(d.yellow(" wyrm-guard hooks not installed \u2014 run: wyrm guard"));break}const i=v.includes("--remove")||v.includes("--uninstall")?c():l();i?i.action==="failed"?(m(i.message),process.exitCode=1):b(i.message):m("Claude Code not detected (~/.claude missing).");break}case"ui":case"dashboard":v.includes("--ui")||v.push("--ui");case"serve":{const l=v.includes("--ui");if(l){const{enableDevMode:r}=await import("./http-auth.js");r()}const{server:c}=await import("./http-fast.js"),t=parseInt(process.env.WYRM_PORT??process.env.PORT??"3333",10),i=process.env.WYRM_BIND_HOST||"127.0.0.1";c.listen(t,i,()=>{if(b(`Wyrm HTTP server running on ${i}:${t}`),process.env.WYRM_UI_READONLY==="1"&&console.log("\u{1F512} READ-ONLY mode: writes + off-box egress are blocked; safe to expose."),l){const r=`http://localhost:${t}/ui`;console.log(`\u{1F5A5}\uFE0F Dashboard: ${r}`),import("child_process").then(({spawn:e})=>{const s=process.platform;try{const o=s==="darwin"?e("open",[r],{stdio:"ignore",detached:!0}):s==="win32"?e("cmd",["/c","start","",r],{stdio:"ignore",detached:!0}):e("xdg-open",[r],{stdio:"ignore",detached:!0});o.on("error",()=>{}),o.unref()}catch{}}).catch(()=>{})}});break}default:m(`Unknown command: ${O}`),be(),process.exit(1)}}catch(l){m(String(l)),process.exit(1)}})();
|