@thinkermd/cli 0.1.8 → 0.1.10
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/tk.js +8 -8
- package/package.json +1 -1
package/dist/tk.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{Command as
|
|
2
|
+
import{Command as Fo}from"commander";import Se from"chalk";import{join as at}from"path";import{writeFile as Qt}from"fs/promises";import b from"chalk";import Be from"ora";import{homedir as Ut}from"os";import{join as J}from"path";import{readFile as Bt,writeFile as Kt,mkdir as Ie}from"fs/promises";import{existsSync as Gt}from"fs";var y=".thinker.md",A="config.json",et="structure.json",O="CONTEXT.md",St="contexts",$t="thinker.md.tar.gz",It="metadata.json",Nt="latest",ot="repos",rt="branches";var _t="thinkermd-meta-repos",At="1.0",ft="full",Ot="incremental",Ft=["node_modules",".git","dist","build",".next",".nuxt","coverage","__pycache__",".pytest_cache","venv",".venv","vendor","target",y],jt=3,Mt=1e3,Dt="[Describe the purpose",Lt=100;var U=J(Ut(),".thinkermd","config.json"),H="https://app.thinkermd.dev";function ht(){return process.env.META_REPO_ID&&process.env.JOB_TOKEN?"sandbox":"local"}function Ne(){return{mode:"sandbox",metaRepoId:process.env.META_REPO_ID,branch:process.env.BRANCH,commitSha:process.env.COMMIT_SHA,previousCommitSha:process.env.PREVIOUS_COMMIT_SHA||void 0,jobId:process.env.JOB_ID,callbackUrl:process.env.CALLBACK_URL,jobToken:process.env.JOB_TOKEN,r2Endpoint:process.env.R2_ENDPOINT,r2AccessKeyId:process.env.R2_ACCESS_KEY_ID,r2SecretAccessKey:process.env.R2_SECRET_ACCESS_KEY,r2Bucket:process.env.R2_BUCKET}}async function $(){try{if(Gt(U)){let e=await Bt(U,"utf-8");return JSON.parse(e)}}catch{}return{}}async function nt(e){let t=J(Ut(),".thinkermd");await Ie(t,{recursive:!0,mode:448}),await Kt(U,JSON.stringify(e,null,2),{mode:384})}async function P(){return ht()==="sandbox"?Ne():{mode:"local",...await $()}}var q={version:At,ignore:[...Ft]};async function F(e){let t=J(e,y,A);try{if(Gt(t)){let o=await Bt(t,"utf-8");return JSON.parse(o)}}catch{}return null}async function it(e,t){let o=J(e,y,A);await Kt(o,JSON.stringify(t,null,2))}function Jt(){let t=["META_REPO_ID","BRANCH","COMMIT_SHA","JOB_ID","CALLBACK_URL","JOB_TOKEN","R2_ENDPOINT","R2_ACCESS_KEY_ID","R2_SECRET_ACCESS_KEY","R2_BUCKET"].filter(o=>!process.env[o]);if(t.length>0)throw new Error(`Missing required environment variables: ${t.join(", ")}`)}function I(e){return J(e,y)}function Y(e){return J(e,y,St)}import{execFile as _e}from"child_process";import{promisify as Ae}from"util";var Oe=Ae(_e);async function X(e,t="."){let{stdout:o}=await Oe("git",e,{cwd:t});return o.trim()}async function S(e="."){try{return await X(["branch","--show-current"],e)}catch(t){throw new Error(`Failed to get current branch: ${t}`)}}async function _(e="."){try{return await X(["rev-parse","HEAD"],e)}catch(t){throw new Error(`Failed to get current commit: ${t}`)}}async function v(e="."){try{return await X(["rev-parse","--show-toplevel"],e)}catch(t){throw new Error(`Not a git repository: ${t}`)}}async function N(e="."){try{return await X(["rev-parse","--git-dir"],e),!0}catch{return!1}}async function Ht(e=".",t){try{return await X(["log","-1","--format=%s",t||"HEAD"],e)}catch(o){throw new Error(`Failed to get commit message: ${o}`)}}async function yt(e="."){try{return await X(["remote","get-url","origin"],e)}catch{return null}}async function z(e="."){let t=await yt(e);if(!t)return null;let o=t.match(/[/:]([\w-]+)\/([\w.-]+?)(\.git)?$/);return o?`${o[1]}/${o[2]}`:null}import{join as B,relative as Fe,dirname as je}from"path";import{readFile as Me}from"fs/promises";import{existsSync as Xt}from"fs";async function De(){let e=await import("ignore");return(e.default??e)()}var Le=[".git",".thinker.md","node_modules","__pycache__",".pytest_cache","venv",".venv",".next",".nuxt","dist","build","coverage","target",".idea",".vscode","*.log","*.lock","package-lock.json","yarn.lock","bun.lockb","pnpm-lock.yaml","Cargo.lock","poetry.lock","Gemfile.lock","*.pyc","*.pyo","*.class","*.o","*.so","*.dylib","*.dll","*.exe"];async function Ue(e){let t=await De();t.add(Le),t.add(q.ignore||[]);try{let o=B(e,".gitignore");if(Xt(o)){let r=await Me(o,"utf-8");t.add(r)}}catch{}return t}async function st(e){let t=await Ue(e),o=new Set,r={total:0};await zt(e,e,t,o,r);let n=Array.from(o).sort();return{version:"1.0",generatedAt:new Date().toISOString(),directories:n,directoryCount:n.length,fileCount:r.total}}async function zt(e,t,o,r,n){let{readdir:i,stat:s}=await import("fs/promises"),a;try{a=await i(t)}catch{return}for(let l of a){let c=B(t,l),d=Fe(e,c);if(!(o.ignores(d)||o.ignores(d+"/")))try{let m=await s(c);m.isDirectory()?(r.add(d),await zt(e,c,o,r,n)):m.isFile()&&n.total++}catch{}}}async function Vt(e){let t=B(e,".thinker.md","contexts"),o=[];return Xt(B(e,".thinker.md","CONTEXT.md"))&&o.push(""),await qt(t,"",o),o}async function qt(e,t,o){let{readdir:r,stat:n}=await import("fs/promises"),i=t?B(e,t):e,s;try{s=await r(i)}catch{return}for(let a of s){let l=B(i,a),c=t?B(t,a):a;try{(await n(l)).isDirectory()?await qt(e,c,o):a==="CONTEXT.md"&&o.push(je(c))}catch{}}}async function h(e,t,o){let r=await P();if(r.mode!=="sandbox"||!r.callbackUrl||!r.jobToken)return;let n=r.callbackUrl.replace("/callback","/progress"),i={type:"progress",status:"processing",step:e,progress:t,message:o};try{let s=await fetch(n,{method:"POST",headers:{Authorization:`Bearer ${r.jobToken}`,"Content-Type":"application/json"},body:JSON.stringify(i)});s.ok||console.warn(`[Progress] Update failed: ${s.status} ${s.statusText}`)}catch(s){console.warn("[Progress] Update error:",s)}}async function Yt(e,t){let o=await P();if(o.mode!=="sandbox"||!o.callbackUrl||!o.jobToken)return;let r={jobId:o.jobId,status:"completed",artifactUrl:e,stats:t};try{let n=await fetch(o.callbackUrl,{method:"POST",headers:{Authorization:`Bearer ${o.jobToken}`,"Content-Type":"application/json"},body:JSON.stringify(r)});if(!n.ok)throw console.error(`[Callback] Completion failed: ${n.status} ${n.statusText}`),new Error(`Callback failed: ${n.status}`);console.log("[Callback] Job completed successfully")}catch(n){throw console.error("[Callback] Completion error:",n),n}}async function Wt(e,t){let r=`# ${t||"Project Root"}
|
|
3
3
|
|
|
4
4
|
<!--
|
|
5
5
|
This context file should describe:
|
|
@@ -24,8 +24,8 @@ This context file should describe:
|
|
|
24
24
|
## Dependencies
|
|
25
25
|
|
|
26
26
|
[Note any important dependencies or relationships]
|
|
27
|
-
`;await
|
|
28
|
-
This appears to be the first generation. Use 'tk init' to create initial structure.`),process.exit(0)),t.succeed(`Found version: ${a.slice(0,7)}`)}await h("pull",30,`Found version: ${a.slice(0,7)}`),t.start("Downloading thinker.md.tar.gz...");let
|
|
27
|
+
`;await Qt(e,r)}async function Ke(e,t,o=!1){let{existsSync:r}=await import("fs"),n=Y(e),i=0,s=0,a=at(I(e),"CONTEXT.md");o&&r(a)?s++:(await Wt(a,""),i++);for(let l of t){let c=at(n,l),d=at(c,"CONTEXT.md"),{mkdir:m}=await import("fs/promises");if(await m(c,{recursive:!0}),o&&r(d)){s++;continue}await Wt(d,l),i++}return{created:i,skipped:s}}async function Zt(e){let t=Be(),o=process.cwd();try{await N(o)||(console.error(b.red("Error: Not a git repository")),console.log("Please run this command from the root of a git repository."),process.exit(1));let r=await v(o),n=I(r),{stat:i}=await import("fs/promises");try{await i(n),!e.force&&!e.merge&&(console.error(b.yellow("Warning: .thinker.md/ already exists")),console.log("Use --force to reinitialize or --merge to add missing contexts"),process.exit(1)),e.merge?console.log(b.cyan("Merging: adding missing CONTEXT.md files...")):console.log(b.yellow("Reinitializing .thinker.md/..."))}catch{}await h("init",0,"Scanning repository structure..."),t.start("Scanning repository structure...");let s=await st(r);t.succeed(`Found ${s.directoryCount} directories, ${s.fileCount} files`),await h("init",30,`Found ${s.directoryCount} directories`);let a=await S(r),l=await _(r),c=await z(r)||"unknown";t.start("Creating .thinker.md/ structure...");let{mkdir:d}=await import("fs/promises");await d(n,{recursive:!0}),await d(Y(r),{recursive:!0});let m=await P(),g={...q,version:"1.0",projectId:m.metaRepoId||`local-${Date.now()}`,name:c,ignore:q.ignore||[],generatedAt:new Date().toISOString(),generatedBy:"tk-cli"};await it(r,g),t.succeed("Created config.json"),await h("init",50,"Created config.json");let f={...s,commitSha:l,branch:a};await Qt(at(n,"structure.json"),JSON.stringify(f,null,2)),t.succeed("Created structure.json"),await h("init",60,"Created structure.json"),t.start(e.merge?"Adding missing CONTEXT.md files...":"Creating empty CONTEXT.md files...");let{created:p,skipped:C}=await Ke(r,s.directories,e.merge);e.merge?(t.succeed(`Added ${p} new CONTEXT.md files (${C} existing skipped)`),await h("init",100,`Added ${p} new CONTEXT.md files`)):(t.succeed(`Created ${p} empty CONTEXT.md files`),await h("init",100,`Created ${p} CONTEXT.md files`)),console.log(),e.merge?(console.log(b.green("\u2713 Merged .thinker.md/")),console.log(),console.log(`Added: ${b.cyan(`${p}`)} new CONTEXT.md files`),console.log(`Skipped: ${b.gray(`${C}`)} existing files`)):(console.log(b.green("\u2713 Initialized .thinker.md/")),console.log(),console.log("Created:"),console.log(` ${b.cyan("config.json")} - Project configuration`),console.log(` ${b.cyan("structure.json")} - Directory structure`),console.log(` ${b.cyan(`${p} CONTEXT.md`)} files - Ready for documentation`)),console.log(),console.log("Next steps:"),console.log(" 1. Fill in the CONTEXT.md files with documentation"),console.log(" 2. Run "+b.cyan("tk validate")+" to check structure"),console.log(" 3. Run "+b.cyan("tk push")+" to upload to storage")}catch(r){t.fail("Initialization failed"),console.error(b.red(`Error: ${r}`)),process.exit(1)}}import{join as wt}from"path";import L from"chalk";import Ge from"ora";async function xt(e){let t=[],o=[],r=0,n=I(e),i=Y(e),{stat:s,readFile:a}=await import("fs/promises");try{await s(n)}catch{return t.push({type:"structure_mismatch",path:y,message:`${y}/ directory not found. Run 'tk init' first.`}),{valid:!1,errors:t,warnings:o,validContextCount:0,directoryCount:0}}let l=await F(e);l?(l.version||t.push({type:"invalid_config",path:`${y}/${A}`,message:`${A} missing required field: version`}),l.projectId||t.push({type:"invalid_config",path:`${y}/${A}`,message:`${A} missing required field: projectId`})):t.push({type:"invalid_config",path:`${y}/${A}`,message:`${A} not found or invalid`});let c=null;try{let p=wt(n,et),C=await a(p,"utf-8");c=JSON.parse(C)}catch{t.push({type:"structure_mismatch",path:`${y}/${et}`,message:`${et} not found or invalid`})}let d=await st(e),m=wt(n,O);try{await s(m),r++}catch{t.push({type:"missing_context",path:O,message:`Root ${O} not found`})}for(let p of d.directories){let C=wt(i,p,O);try{if((await s(C)).isFile()){r++;let x=await a(C,"utf-8");(x.trim().length<Lt||x.includes(Dt))&&o.push({type:"empty_context",path:`${p}/${O}`,message:"Context file appears to be empty or contains only template"})}}catch{t.push({type:"missing_context",path:`${p}/${O}`,message:`Missing context file for directory: ${p}`})}}let g=await Vt(e),f=new Set(d.directories);for(let p of g)p===""||p==="."||f.has(p)||o.push({type:"orphan_context",path:`${p}/${O}`,message:`Context exists for non-existent directory: ${p}`});return{valid:t.length===0,errors:t,warnings:o,validContextCount:r,directoryCount:d.directoryCount}}async function te(e){let t=Ge(),o=process.cwd();try{await N(o)||(console.error(L.red("Error: Not a git repository")),process.exit(1));let r=await v(o);await h("validate",0,"Validating structure..."),t.start(`Validating ${y}/ structure...`);let n=await xt(r);if(t.stop(),await h("validate",100,"Validation complete"),!e.quiet){if(console.log(),n.errors.length>0){console.log(L.red(`\u2717 ${n.errors.length} error(s):`));for(let i of n.errors)console.log(L.red(` \u2022 ${i.path}: ${i.message}`));console.log()}if(n.warnings.length>0){console.log(L.yellow(`\u26A0 ${n.warnings.length} warning(s):`));for(let i of n.warnings)console.log(L.yellow(` \u2022 ${i.path}: ${i.message}`));console.log()}n.valid?console.log(L.green(`\u2713 Validation passed: ${n.validContextCount} contexts valid`)):console.log(L.red(`\u2717 Validation failed: ${n.errors.length} error(s), ${n.warnings.length} warning(s)`))}n.valid||process.exit(1)}catch(r){t.fail("Validation failed"),console.error(L.red(`Error: ${r}`)),process.exit(1)}}import{join as se}from"path";import{writeFile as qe}from"fs/promises";import j from"chalk";import Ye from"ora";import*as ae from"tar";import{S3Client as Je,PutObjectCommand as Et,GetObjectCommand as ee}from"@aws-sdk/client-s3";var Ct=null;function W(){if(!Ct){let e=process.env.R2_ENDPOINT,t=process.env.R2_ACCESS_KEY_ID,o=process.env.R2_SECRET_ACCESS_KEY;if(!e||!t||!o)throw new Error("R2 credentials not configured. Required: R2_ENDPOINT, R2_ACCESS_KEY_ID, R2_SECRET_ACCESS_KEY");Ct=new Je({region:"auto",endpoint:e,credentials:{accessKeyId:t,secretAccessKey:o}})}return Ct}function Q(){return process.env.R2_BUCKET||_t}async function Z(e,t,o=jt,r=Mt){let n;for(let i=1;i<=o;i++)try{return await e()}catch(s){if(n=s instanceof Error?s:new Error(String(s)),n.name==="NoSuchKey"||n.message.includes("credentials")||n.message.includes("AccessDenied"))throw n;if(i<o){let a=r*Math.pow(2,i-1);console.log(`[Storage] ${t} failed (attempt ${i}/${o}), retrying in ${a}ms...`),await new Promise(l=>setTimeout(l,a))}}throw n}function oe(e,t,o){return`${ot}/${e}/${rt}/${t}/${o}/${$t}`}function He(e,t,o){return`${ot}/${e}/${rt}/${t}/${o}/${It}`}function re(e,t){return`${ot}/${e}/${rt}/${t}/${Nt}`}async function Xe(e,t,o,r){let n=W(),i=oe(e,t,o);return await Z(()=>n.send(new Et({Bucket:Q(),Key:i,Body:r,ContentType:"application/gzip"})),"uploadArchive"),console.log(`[Storage] Uploaded archive to ${i}`),i}async function ze(e,t,o,r){let n=W(),i=He(e,t,o);await Z(()=>n.send(new Et({Bucket:Q(),Key:i,Body:JSON.stringify(r,null,2),ContentType:"application/json"})),"uploadMetadata"),console.log(`[Storage] Uploaded metadata to ${i}`)}async function Ve(e,t,o){let r=W(),n=re(e,t);await Z(()=>r.send(new Et({Bucket:Q(),Key:n,Body:o,ContentType:"text/plain"})),"updateLatestPointer"),console.log(`[Storage] Updated latest pointer for ${t} -> ${o}`)}async function ct(e,t){let o=W(),r=re(e,t);try{return(await(await Z(()=>o.send(new ee({Bucket:Q(),Key:r})),"getLatestCommitSha")).Body?.transformToString())?.trim()||null}catch(n){if(n instanceof Error&&"name"in n&&n.name==="NoSuchKey")return null;throw n}}async function ne(e,t,o){let r=W(),n=oe(e,t,o);try{let s=await(await Z(()=>r.send(new ee({Bucket:Q(),Key:n})),"downloadArchive")).Body?.transformToByteArray();return s?Buffer.from(s):null}catch(i){if(i instanceof Error&&"name"in i&&i.name==="NoSuchKey")return null;throw i}}async function ie(e,t,o,r,n){let i=await Xe(e,t,o,r);return await ze(e,t,o,n),await Ve(e,t,o),i}async function We(e){let{readdir:t,stat:o}=await import("fs/promises"),r=0;async function n(i){let s;try{s=await t(i)}catch{return}for(let a of s){let l=se(i,a);try{(await o(l)).isDirectory()?await n(l):a==="CONTEXT.md"&&r++}catch{}}}return await n(e),r}async function ce(e){let t=Ye(),o=process.cwd();try{await N(o)||(console.error(j.red("Error: Not a git repository")),process.exit(1));let r=await v(o),n=await P(),i;if(n.mode==="sandbox"&&n.metaRepoId)i=n.metaRepoId;else{let p=await F(r);p?.projectId?i=p.projectId:(console.error(j.red("Error: No project ID found. Run 'tk init' first or set META_REPO_ID.")),process.exit(1))}let s=e.branch||n.branch||await S(r);await h("pull",0,`Fetching latest context for branch '${s}'...`),console.log(`Fetching latest context for branch '${j.cyan(s)}'...`),t.start("Looking up latest version...");let a;if(e.commit)a=e.commit,t.succeed(`Using specified commit: ${a.slice(0,7)}`);else{try{a=await ct(i,s)}catch(p){throw p instanceof Error&&p.message.includes("R2 credentials")&&(t.fail("R2 credentials not configured"),console.error(j.red(p.message)),process.exit(1)),p}a||(t.info("No previous context found for this branch"),console.log(`
|
|
28
|
+
This appears to be the first generation. Use 'tk init' to create initial structure.`),process.exit(0)),t.succeed(`Found version: ${a.slice(0,7)}`)}await h("pull",30,`Found version: ${a.slice(0,7)}`),t.start("Downloading thinker.md.tar.gz...");let l=await ne(i,s,a);l||(t.fail("Archive not found"),console.error(j.red(`No archive found for commit ${a.slice(0,7)}`)),process.exit(1)),t.succeed(`Downloaded archive: ${l.length} bytes`),await h("pull",60,"Extracting archive...");let c=se(r,".thinker.md.tar.gz");await qe(c,l),t.start("Extracting to .thinker.md/...");let d=I(r),{rm:m}=await import("fs/promises");try{await m(d,{recursive:!0,force:!0})}catch{}await ae.extract({file:c,cwd:r}),await m(c,{force:!0}),t.succeed("Extracted .thinker.md/"),await h("pull",80,"Updating config...");let g=await F(r);g&&(g.pulledFrom=a,g.pulledAt=new Date().toISOString(),await it(r,g));let f=await We(d);await h("pull",100,`Pulled ${f} context files`),console.log(),console.log(j.green(`\u2713 Pulled ${f} context files`)),console.log(),console.log(`From: ${j.cyan(`${s}@${a.slice(0,7)}`)}`),console.log(),console.log("Next steps:"),console.log(" 1. Review and update context files as needed"),console.log(" 2. Run "+j.cyan("tk validate")+" to check structure"),console.log(" 3. Run "+j.cyan("tk push")+" to upload changes")}catch(r){t.fail("Pull failed"),console.error(j.red(`Error: ${r}`)),process.exit(1)}}import{join as le}from"path";import R from"chalk";import Qe from"ora";import*as de from"tar";async function Ze(e){let{readdir:t,stat:o}=await import("fs/promises"),r=0,n=0;async function i(s){let a;try{a=await t(s)}catch{return}for(let l of a){let c=le(s,l);try{(await o(c)).isDirectory()?await i(c):(n++,l===O&&r++)}catch{}}}return await i(e),{contextFiles:r,totalFiles:n}}async function pe(e){let t=Qe(),o=process.cwd();try{if(ht()==="sandbox")try{Jt()}catch(E){console.error(R.red(`Sandbox environment error: ${E}`)),process.exit(1)}await N(o)||(console.error(R.red("Error: Not a git repository")),process.exit(1));let r=await v(o),n=await P(),i=I(r),{stat:s,rm:a}=await import("fs/promises");try{await s(i)}catch{console.error(R.red(`Error: ${y}/ not found`)),console.log("Run 'tk init' first to create the structure."),process.exit(1)}if(await h("push",0,"Validating structure..."),!e.skipValidation){t.start(`Validating ${y}/ structure...`);let E=await xt(r);if(!E.valid){t.fail("Validation failed"),console.log(),console.log(R.red("Fix the following errors before pushing:"));for(let tt of E.errors)console.log(R.red(` \u2022 ${tt.path}: ${tt.message}`));process.exit(1)}t.succeed("Validation passed"),E.warnings.length>0&&console.log(R.yellow(` ${E.warnings.length} warning(s)`))}await h("push",20,"Validation passed");let l;if(n.mode==="sandbox"&&n.metaRepoId)l=n.metaRepoId;else{let E=await F(r);E?.projectId?l=E.projectId:(console.error(R.red("Error: No project ID found. Set META_REPO_ID environment variable.")),process.exit(1))}let c=n.branch||await S(r),d=n.commitSha||await _(r),m=await Ht(r,d);await h("push",30,"Packaging .thinker.md/..."),t.start(`Packaging ${y}/...`);let g=le(r,`${y}.tar.gz`);await de.create({file:g,cwd:r,gzip:!0},[y]);let{readFile:f}=await import("fs/promises"),p=await f(g);await a(g,{force:!0}),t.succeed(`Packaged archive: ${p.length} bytes`),await h("push",60,"Uploading to storage...");let C=await Ze(i),G=await F(r),x=e.forceFull?ft:G?.pulledFrom?Ot:ft,Pt={branch:c,commitSha:d,commitMessage:m,mode:x,parentCommitSha:G?.pulledFrom,generatedAt:new Date().toISOString(),jobId:n.jobId||`local-${Date.now()}`,tokensUsed:0,filesAnalyzed:C.totalFiles,contextFilesGenerated:C.contextFiles};t.start("Uploading to storage...");try{let E=await ie(l,c,d,p,Pt);if(t.succeed("Uploaded to storage"),await h("push",90,"Finalizing..."),n.mode==="sandbox"&&n.callbackUrl){let tt={filesAnalyzed:C.totalFiles,contextFilesGenerated:C.contextFiles,tokensUsed:0,mode:x};await Yt(E,tt)}await h("push",100,"Done!"),console.log(),console.log(R.green("\u2713 Successfully pushed to storage")),console.log(),console.log(`Branch: ${R.cyan(c)}`),console.log(`Commit: ${R.cyan(d.slice(0,7))}`),console.log(`Mode: ${R.cyan(x)}`),console.log(`Context files: ${R.cyan(C.contextFiles)}`),n.mode==="sandbox"&&(console.log(),console.log(R.green("\u2713 Job completed")))}catch(E){t.fail("Upload failed"),E instanceof Error&&E.message.includes("R2 credentials")?(console.error(R.red(E.message)),console.log(),console.log("Required environment variables:"),console.log(" R2_ENDPOINT"),console.log(" R2_ACCESS_KEY_ID"),console.log(" R2_SECRET_ACCESS_KEY"),console.log(" R2_BUCKET")):console.error(R.red(`Error: ${E}`)),process.exit(1)}}catch(r){t.fail("Push failed"),console.error(R.red(`Error: ${r}`)),process.exit(1)}}import k from"chalk";import me from"ora";import{createServer as ue}from"http";import{randomBytes as to}from"crypto";import{exec as eo}from"child_process";import{promisify as oo}from"util";var Rt=oo(eo);async function ro(e){let t=process.platform;try{t==="darwin"?await Rt(`open "${e}"`):t==="win32"?await Rt(`start "" "${e}"`):await Rt(`xdg-open "${e}"`)}catch{}}async function ge(e=9876){return new Promise(t=>{let o=ue();o.listen(e,()=>{let r=o.address(),n=typeof r=="object"&&r?r.port:e;o.close(()=>t(n))}),o.on("error",()=>{t(ge(e+1))})})}function no(e,t,o=3e5){return new Promise((r,n)=>{let i=null,s,a=()=>{s&&clearTimeout(s),i&&(i.close(),i=null)};s=setTimeout(()=>{a(),n(new Error("Authentication timed out. Please try again."))},o),i=ue((l,c)=>{let d=new URL(l.url||"",`http://localhost:${e}`);if(d.pathname==="/callback"){let m=d.searchParams.get("token"),g=d.searchParams.get("user_id"),f=d.searchParams.get("email");m&&g&&f?(c.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),c.end(`<!DOCTYPE html>
|
|
29
29
|
<html lang="en">
|
|
30
30
|
<head>
|
|
31
31
|
<meta charset="UTF-8">
|
|
@@ -100,7 +100,7 @@ This appears to be the first generation. Use 'tk init' to create initial structu
|
|
|
100
100
|
<p>You can now close this window and return to your terminal.</p>
|
|
101
101
|
</div>
|
|
102
102
|
</body>
|
|
103
|
-
</html>`),a(),r({token:u,userId:g,email:f})):(l.writeHead(400,{"Content-Type":"text/plain"}),l.end("Missing required parameters"))}else l.writeHead(404,{"Content-Type":"text/plain"}),l.end("Not found")}),i.listen(e)})}async function no(e,t){try{let o=await fetch(`${e}/api/auth/validate`,{method:"GET",headers:{Authorization:`Bearer ${t}`}});return o.ok?{valid:!0,userId:(await o.json()).userId}:o.status===401?{valid:!1,error:"Invalid or expired token"}:{valid:!1,error:`API error: ${o.status} ${o.statusText}`}}catch(o){return{valid:!1,error:`Connection failed: ${o}`}}}async function ge(e){let t=pe(),o=e.apiUrl||J;if(e.token){t.start("Validating token...");let n=await no(o,e.token);n.valid||(t.fail("Authentication failed"),console.error(k.red(`Error: ${n.error}`)),process.exit(1));let i={apiToken:e.token,apiUrl:o,userId:n.userId};await rt(i),t.succeed("Authenticated successfully"),console.log(),console.log(`Config saved to: ${k.cyan(L)}`);return}let r=await S();if(r.apiToken){console.log(k.green("You are already logged in.")),console.log(`User ID: ${k.cyan(r.userId||"unknown")}`),console.log(),console.log("To re-authenticate, run:"),console.log(k.cyan(" tk login --token NEW_TOKEN")),console.log(),console.log("Or to login with a different account:"),console.log(k.cyan(" tk logout && tk login"));return}console.log(k.bold("ThinkerMD Login")),console.log(),t.start("Setting up authentication...");try{let n=await me(),i=Ze(16).toString("hex"),s=`${o}/cli/auth?port=${n}&state=${i}`;t.succeed("Ready for authentication"),console.log(),console.log("Opening browser for authentication..."),console.log(),console.log("If the browser doesn't open, visit this URL manually:"),console.log(k.cyan(s)),console.log(),await oo(s),t.start("Waiting for authentication...");let{token:a,userId:c,email:l}=await ro(n,i);await rt({apiToken:a,apiUrl:o,userId:c,email:l}),t.succeed("Authenticated successfully"),console.log(),console.log(`Logged in as: ${k.cyan(l)}`),console.log(`Config saved to: ${k.cyan(L)}`)}catch(n){t.fail("Authentication failed"),console.error(k.red(`Error: ${n instanceof Error?n.message:n}`)),console.log(),console.log("You can also authenticate manually:"),console.log(k.cyan(" tk login --token YOUR_TOKEN")),console.log(),console.log(`Get your token at: ${k.cyan(`${o}/dashboard/settings`)}`),process.exit(1)}}async function fe(){let e=pe();e.start("Logging out..."),await rt({}),e.succeed("Logged out successfully"),console.log(),console.log(`Config cleared from: ${k.cyan(L)}`)}import{join as he}from"path";import m from"chalk";import io from"ora";async function so(e){let{readFile:t}=await import("fs/promises"),{existsSync:o}=await import("fs"),r=he(I(e),"structure.json");try{if(o(r)){let n=await t(r,"utf-8");return JSON.parse(n)}}catch{}return null}async function ao(e){let{readdir:t,stat:o}=await import("fs/promises"),r=0;async function n(i){let s;try{s=await t(i)}catch{return}for(let a of s){let c=he(i,a);try{(await o(c)).isDirectory()?await n(c):a==="CONTEXT.md"&&r++}catch{}}}return await n(e),r}async function ye(){let e=io(),t=process.cwd();try{await N(t)||(console.error(m.red("Error: Not a git repository")),process.exit(1));let o=await R(t),r=await P(),n=I(o);console.log(m.bold("ThinkerMD Status")),console.log();let i=await X(o),s=r.branch||await $(o),a=r.commitSha||await _(o);console.log(m.dim("Repository:")),console.log(` Name: ${m.cyan(i||"unknown")}`),console.log(` Branch: ${m.cyan(s)}`),console.log(` Commit: ${m.cyan(a.slice(0,7))}`),console.log();let{stat:c}=await import("fs/promises"),l=!1;try{await c(n),l=!0}catch{}if(!l){console.log(m.dim("Local Context:")),console.log(` Status: ${m.yellow("Not initialized")}`),console.log(),console.log("Run "+m.cyan("tk init")+" to create .thinker.md/");return}console.log(m.dim("Local Context:"));let d=await F(o),u=await so(o),g=await ao(n);if(console.log(` Status: ${m.green("Initialized")}`),console.log(` Project ID: ${m.cyan(d?.projectId||"unknown")}`),console.log(` Context files: ${m.cyan(g)}`),u&&(console.log(` Directories: ${m.cyan(u.directoryCount)}`),console.log(` Files tracked: ${m.cyan(u.fileCount)}`)),d?.generatedAt){let p=new Date(d.generatedAt);console.log(` Generated: ${m.cyan(p.toLocaleString())}`)}d?.pulledFrom&&console.log(` Pulled from: ${m.cyan(d.pulledFrom.slice(0,7))}`),console.log();let f=r.metaRepoId||d?.projectId;if(f&&r.r2Endpoint){console.log(m.dim("Remote Storage:")),e.start("Checking remote...");try{let p=await at(f,s);p?(e.stop(),console.log(` Latest commit: ${m.cyan(p.slice(0,7))}`),p===a?console.log(` Status: ${m.green("Up to date")}`):d?.pulledFrom===p?console.log(` Status: ${m.yellow("Local changes not pushed")}`):(console.log(` Status: ${m.yellow("Remote has newer version")}`),console.log(),console.log("Run "+m.cyan("tk pull")+" to download latest context"))):(e.stop(),console.log(` Status: ${m.yellow("No remote context found")}`),console.log(),console.log("Run "+m.cyan("tk push")+" to upload context"))}catch{e.stop(),console.log(` Status: ${m.dim("Unable to check (no credentials)")}`)}}console.log(),console.log(m.dim("Mode:")),console.log(` ${r.mode==="sandbox"?m.cyan("Sandbox"):m.cyan("Local")}`),r.mode==="sandbox"&&console.log(` Job ID: ${m.cyan(r.jobId||"unknown")}`)}catch(o){e.fail("Failed to get status"),console.error(m.red(`Error: ${o}`)),process.exit(1)}}import w from"chalk";import co from"ora";async function we(e){let t=co(),o=process.cwd();try{await N(o)||(console.error(w.red("Error: Not a git repository")),process.exit(1));let r=await R(o);if((await P()).mode==="sandbox"){console.error(w.yellow("Note: In sandbox mode, generation is triggered automatically.")),console.log("Use 'tk init' to create structure and 'tk push' when done.");return}let i=await S();i.apiToken||(console.error(w.red("Error: Not logged in")),console.log(),console.log("Please authenticate first:"),console.log(w.cyan(" tk login --token YOUR_TOKEN")),process.exit(1));let s=i.apiUrl||J,a=await X(r),c=e.branch||await $(r),l=await _(r);a||(console.error(w.red("Error: Unable to determine repository name")),console.log("Make sure this repository has a remote origin configured."),process.exit(1)),console.log(w.bold("Trigger Context Generation")),console.log(),console.log(`Repository: ${w.cyan(a)}`),console.log(`Branch: ${w.cyan(c)}`),console.log(`Commit: ${w.cyan(l.slice(0,7))}`),console.log(),t.start("Looking up meta-repository...");let d=await fetch(`${s}/api/meta-repositories/lookup?repo=${encodeURIComponent(a)}`,{headers:{Authorization:`Bearer ${i.apiToken}`}});d.ok||(d.status===404&&(t.fail("Meta-repository not found"),console.log(),console.log("This repository is not connected to ThinkerMD. Please add it at:"),console.log(w.cyan(`${s}/dashboard`)),process.exit(1)),t.fail("API error"),console.error(w.red(`Error: ${d.status} ${d.statusText}`)),process.exit(1));let u=await d.json();t.succeed(`Found meta-repository: ${u.id}`),t.start("Triggering generation job...");let g=await fetch(`${s}/api/jobs/generate`,{method:"POST",headers:{Authorization:`Bearer ${i.apiToken}`,"Content-Type":"application/json"},body:JSON.stringify({metaRepositoryId:u.id,commitSha:l,branch:c,priority:"normal"})});if(!g.ok){t.fail("Failed to trigger generation");let p=await g.json().catch(()=>({}));console.error(w.red(`Error: ${p.error||g.statusText}`)),process.exit(1)}let f=await g.json();if(t.succeed("Generation job queued"),console.log(),console.log(`Job ID: ${w.cyan(f.jobId)}`),console.log(`Status: ${w.cyan(f.status)}`),f.estimatedPosition&&console.log(`Queue position: ${w.cyan(f.estimatedPosition)}`),console.log(),console.log("Track progress at:"),console.log(w.cyan(`${s}/dashboard/repositories/${u.id}/jobs/${f.jobId}`)),e.wait){console.log(),t.start("Waiting for completion...");let p=!1,C="";for(;!p;){await new Promise(x=>setTimeout(x,5e3));let K=await fetch(`${s}/api/jobs/${f.jobId}`,{headers:{Authorization:`Bearer ${i.apiToken}`}});if(K.ok){let x=await K.json();x.status!==C&&(C=x.status,t.text=`Status: ${x.status} (${x.progress||0}%)`),(x.status==="completed"||x.status==="failed")&&(p=!0,x.status==="completed"?(t.succeed("Generation completed!"),console.log(),console.log("Run "+w.cyan("tk pull")+" to download the generated context")):(t.fail("Generation failed"),x.errorMessage&&console.error(w.red(`Error: ${x.errorMessage}`))))}}}}catch(r){t.fail("Failed to trigger generation"),console.error(w.red(`Error: ${r}`)),process.exit(1)}}import bt from"chalk";import{Hono as Eo}from"hono";import D from"chalk";import{createServer as To}from"http";import{homedir as Te}from"os";import{join as Re}from"path";import{readFile as uo,writeFile as mo,mkdir as go}from"fs/promises";import{existsSync as fo}from"fs";async function lo(){return(await S()).apiUrl||process.env.THINKERMD_API_URL||J}async function po(){return(await S()).apiToken||process.env.THINKERMD_API_TOKEN||null}async function ct(e,t={}){let o=await lo(),r=await po();if(!r)throw new Error("Not authenticated. Run `tk login` first.");let{method:n="GET",body:i,params:s}=t,a=`${o}${e}`;if(s){let l=new URLSearchParams(s);a+=`?${l.toString()}`}let c=await fetch(a,{method:n,headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json"},body:i?JSON.stringify(i):void 0});if(!c.ok){let l=await c.json().catch(()=>({}));throw new Error(l.error||`API request failed: ${c.status} ${c.statusText}`)}return c.json()}async function xe(e,t,o={}){return ct("/api/mcp/search",{method:"POST",body:{repositoryId:e,query:t,branch:o.branch,limit:o.limit||10}})}async function Et(e,t,o={}){return ct("/api/mcp/read",{params:{repositoryId:e,filePath:t,...o.branch&&{branch:o.branch}}})}async function Ce(e,t={}){return ct("/api/mcp/files",{params:{repositoryId:e,...t.branch&&{branch:t.branch}}})}async function Ee(e){try{let t=await ct("/api/user/repositories",{params:{remoteUrl:e}});return t.repositories&&t.repositories.length>0?t.repositories[0]:null}catch{return null}}var Tt=Re(Te(),".thinkermd","cache","repo-mapping.json"),ho=24*60*60*1e3;async function yo(){try{if(fo(Tt)){let e=await uo(Tt,"utf-8");return JSON.parse(e)}}catch{}return{mappings:{}}}async function wo(e){let t=Re(Te(),".thinkermd","cache");await go(t,{recursive:!0}),await mo(Tt,JSON.stringify(e,null,2))}async function z(e){let t;try{t=await R(e)}catch{return console.error(`[RepoResolver] Not a git repository: ${e}`),null}let o=await ft(t);if(!o)return console.error(`[RepoResolver] No git remote found for: ${t}`),null;let r=xo(o),n=await yo(),i=n.mappings[r];if(i&&Date.now()-i.cachedAt<ho){console.log(`[RepoResolver] Cache hit for: ${r}`);let l=await $(t),d=await _(t);return{repositoryId:i.repositoryId,fullName:i.fullName,remoteUrl:r,gitRoot:t,branch:l||"main",commit:d||"HEAD"}}console.log(`[RepoResolver] Querying API for: ${r}`);let s=await Ee(r);if(!s)return console.error(`[RepoResolver] Repository not found in ThinkerMD: ${r}`),null;n.mappings[r]={remoteUrl:r,repositoryId:s.id,fullName:s.fullName,cachedAt:Date.now()},await wo(n);let a=await $(t),c=await _(t);return{repositoryId:s.id,fullName:s.fullName,remoteUrl:r,gitRoot:t,branch:a||"main",commit:c||"HEAD"}}function xo(e){return e=e.replace(/\.git$/,""),e.startsWith("git@")&&(e=e.replace(/^git@/,"https://").replace(/:([^/])/,"/$1")),e.startsWith("http://")&&(e=e.replace("http://","https://")),e}async function lt(e){let{path:t,query:o,limit:r=10}=e,n=await z(t);if(!n)throw new Error(`Could not resolve repository for path: ${t}`);return{...await xe(n.repositoryId,o,{branch:n.branch,limit:r}),repositoryId:n.repositoryId,fullName:n.fullName}}async function dt(e){let{path:t,filePath:o}=e,r=await z(t);if(!r)throw new Error(`Could not resolve repository for path: ${t}`);return{...await Et(r.repositoryId,o,{branch:r.branch}),repositoryId:r.repositoryId,fullName:r.fullName}}async function pt(e){let{path:t}=e,o=await z(t);if(!o)throw new Error(`Could not resolve repository for path: ${t}`);let r=t;t.startsWith(o.gitRoot)&&(r=t.slice(o.gitRoot.length).replace(/^\//,""));let n=r?`.thinker.md/contexts/${r}/CONTEXT.md`:".thinker.md/contexts/CONTEXT.md";return{...await Et(o.repositoryId,n,{branch:o.branch}),repositoryId:o.repositoryId,fullName:o.fullName}}async function ut(e){let{path:t}=e,o=await z(t);if(!o)throw new Error(`Could not resolve repository for path: ${t}`);return{...await Ce(o.repositoryId,{branch:o.branch}),repositoryId:o.repositoryId,fullName:o.fullName}}async function be(e){return z(e.path)}import{McpServer as Co}from"@modelcontextprotocol/sdk/server/mcp.js";import{z as B}from"zod";function ke(){let e=new Co({name:"thinkermd",version:"0.1.0"});return e.tool("thinkermd_search","Semantic search across context files in the repository. Use this to find relevant documentation and context about the codebase.",{query:B.string().describe("Search query - what you're looking for"),path:B.string().optional().describe("Path to directory (defaults to current working directory)"),limit:B.number().optional().default(10).describe("Maximum number of results to return")},async({query:t,path:o,limit:r})=>{try{let n=o||process.cwd(),i=await lt({path:n,query:t,limit:r});return{content:[{type:"text",text:JSON.stringify(i,null,2)}]}}catch(n){return{content:[{type:"text",text:`Error: ${n instanceof Error?n.message:"Search failed"}`}],isError:!0}}}),e.tool("thinkermd_read","Read a specific context file from the repository. Use this to get the full content of a CONTEXT.md file.",{filePath:B.string().describe("Path to the context file relative to repository root"),path:B.string().optional().describe("Path to repository directory (defaults to current working directory)")},async({filePath:t,path:o})=>{try{let r=o||process.cwd();return{content:[{type:"text",text:(await dt({path:r,filePath:t})).content}]}}catch(r){return{content:[{type:"text",text:`Error: ${r instanceof Error?r.message:"Read failed"}`}],isError:!0}}}),e.tool("thinkermd_get_context","Get the CONTEXT.md file for a specific directory. This provides contextual documentation about that part of the codebase.",{path:B.string().describe("Path to the directory to get context for")},async({path:t})=>{try{return{content:[{type:"text",text:(await pt({path:t})).content}]}}catch(o){return{content:[{type:"text",text:`Error: ${o instanceof Error?o.message:"Get context failed"}`}],isError:!0}}}),e.tool("thinkermd_list_files","List all CONTEXT.md files available in the repository. Use this to discover what documentation is available.",{path:B.string().optional().describe("Path to repository directory (defaults to current working directory)")},async({path:t})=>{try{let o=t||process.cwd(),r=await ut({path:o});return{content:[{type:"text",text:JSON.stringify(r,null,2)}]}}catch(o){return{content:[{type:"text",text:`Error: ${o instanceof Error?o.message:"List files failed"}`}],isError:!0}}}),e}import{StreamableHTTPServerTransport as Ro}from"@modelcontextprotocol/sdk/server/streamableHttp.js";import{isInitializeRequest as bo}from"@modelcontextprotocol/sdk/types.js";var Rt=new Map;async function ko(e,t){let o=e.headers["mcp-session-id"],r;if(o&&Rt.has(o))r=Rt.get(o);else if(e.method==="POST"){let n=[];for await(let a of e)n.push(a);let i=Buffer.concat(n).toString(),s;try{s=JSON.parse(i)}catch{t.writeHead(400,{"Content-Type":"application/json"}),t.end(JSON.stringify({error:"Invalid JSON"}));return}if(bo(s)){console.log("[MCP] New session initialized"),r=new Ro({sessionIdGenerator:()=>crypto.randomUUID(),onsessioninitialized:c=>{Rt.set(c,r),console.log(`[MCP] Session started: ${c}`)}}),await ke().connect(r),await r.handleRequest(e,t,i);return}else if(!o){t.writeHead(400,{"Content-Type":"application/json"}),t.end(JSON.stringify({jsonrpc:"2.0",error:{code:-32600,message:"Bad Request: No session ID provided"},id:null}));return}}else{t.writeHead(400,{"Content-Type":"application/json"}),t.end(JSON.stringify({error:"No valid session"}));return}await r.handleRequest(e,t)}function vo(){let e=new Eo;return e.get("/health",t=>t.json({status:"ok",version:"0.1.0"})),e.post("/mcp/search",async t=>{try{let o=await t.req.json(),{path:r,query:n,limit:i}=o;if(!r||!n)return t.json({error:"path and query are required"},400);let s=await lt({path:r,query:n,limit:i});return t.json(s)}catch(o){return console.error("[MCP] Search error:",o),t.json({error:o instanceof Error?o.message:"Search failed"},500)}}),e.get("/mcp/read",async t=>{try{let o=t.req.query("path"),r=t.req.query("filePath");if(!o||!r)return t.json({error:"path and filePath are required"},400);let n=await dt({path:o,filePath:r});return t.json(n)}catch(o){return console.error("[MCP] Read error:",o),t.json({error:o instanceof Error?o.message:"Read failed"},500)}}),e.get("/mcp/context",async t=>{try{let o=t.req.query("path");if(!o)return t.json({error:"path is required"},400);let r=await pt({path:o});return t.json(r)}catch(o){return console.error("[MCP] Get context error:",o),t.json({error:o instanceof Error?o.message:"Get context failed"},500)}}),e.get("/mcp/files",async t=>{try{let o=t.req.query("path");if(!o)return t.json({error:"path is required"},400);let r=await ut({path:o});return t.json(r)}catch(o){return console.error("[MCP] List files error:",o),t.json({error:o instanceof Error?o.message:"List files failed"},500)}}),e.get("/mcp/repo",async t=>{try{let o=t.req.query("path");if(!o)return t.json({error:"path is required"},400);let r=await be({path:o});return r?t.json({connected:!0,...r}):t.json({connected:!1,message:"Repository not found in ThinkerMD"})}catch(o){return console.error("[MCP] Get repo info error:",o),t.json({error:o instanceof Error?o.message:"Get repo info failed"},500)}}),e}function Po(e,t){let o=`http://localhost:${e}/mcp`,r=64,n=40,i=t.length>n?t.slice(0,n-3)+"...":t;console.log(D.cyan(`
|
|
103
|
+
</html>`),a(),r({token:m,userId:g,email:f})):(c.writeHead(400,{"Content-Type":"text/plain"}),c.end("Missing required parameters"))}else c.writeHead(404,{"Content-Type":"text/plain"}),c.end("Not found")}),i.listen(e)})}async function io(e,t){try{let o=await fetch(`${e}/api/auth/validate`,{method:"GET",headers:{Authorization:`Bearer ${t}`}});return o.ok?{valid:!0,userId:(await o.json()).userId}:o.status===401?{valid:!1,error:"Invalid or expired token"}:{valid:!1,error:`API error: ${o.status} ${o.statusText}`}}catch(o){return{valid:!1,error:`Connection failed: ${o}`}}}async function fe(e){let t=me(),o=e.apiUrl||H;if(e.token){t.start("Validating token...");let n=await io(o,e.token);n.valid||(t.fail("Authentication failed"),console.error(k.red(`Error: ${n.error}`)),process.exit(1));let i={apiToken:e.token,apiUrl:o,userId:n.userId};await nt(i),t.succeed("Authenticated successfully"),console.log(),console.log(`Config saved to: ${k.cyan(U)}`);return}let r=await $();if(r.apiToken){console.log(k.green("You are already logged in.")),console.log(`User ID: ${k.cyan(r.userId||"unknown")}`),console.log(),console.log("To re-authenticate, run:"),console.log(k.cyan(" tk login --token NEW_TOKEN")),console.log(),console.log("Or to login with a different account:"),console.log(k.cyan(" tk logout && tk login"));return}console.log(k.bold("ThinkerMD Login")),console.log(),t.start("Setting up authentication...");try{let n=await ge(),i=to(16).toString("hex"),s=`${o}/cli/auth?port=${n}&state=${i}`;t.succeed("Ready for authentication"),console.log(),console.log("Opening browser for authentication..."),console.log(),console.log("If the browser doesn't open, visit this URL manually:"),console.log(k.cyan(s)),console.log(),await ro(s),t.start("Waiting for authentication...");let{token:a,userId:l,email:c}=await no(n,i);await nt({apiToken:a,apiUrl:o,userId:l,email:c}),t.succeed("Authenticated successfully"),console.log(),console.log(`Logged in as: ${k.cyan(c)}`),console.log(`Config saved to: ${k.cyan(U)}`)}catch(n){t.fail("Authentication failed"),console.error(k.red(`Error: ${n instanceof Error?n.message:n}`)),console.log(),console.log("You can also authenticate manually:"),console.log(k.cyan(" tk login --token YOUR_TOKEN")),console.log(),console.log(`Get your token at: ${k.cyan(`${o}/dashboard/settings`)}`),process.exit(1)}}async function he(){let e=me();e.start("Logging out..."),await nt({}),e.succeed("Logged out successfully"),console.log(),console.log(`Config cleared from: ${k.cyan(U)}`)}import{join as ye}from"path";import u from"chalk";import so from"ora";async function ao(e){let{readFile:t}=await import("fs/promises"),{existsSync:o}=await import("fs"),r=ye(I(e),"structure.json");try{if(o(r)){let n=await t(r,"utf-8");return JSON.parse(n)}}catch{}return null}async function co(e){let{readdir:t,stat:o}=await import("fs/promises"),r=0;async function n(i){let s;try{s=await t(i)}catch{return}for(let a of s){let l=ye(i,a);try{(await o(l)).isDirectory()?await n(l):a==="CONTEXT.md"&&r++}catch{}}}return await n(e),r}async function we(){let e=so(),t=process.cwd();try{await N(t)||(console.error(u.red("Error: Not a git repository")),process.exit(1));let o=await v(t),r=await P(),n=I(o);console.log(u.bold("ThinkerMD Status")),console.log();let i=await z(o),s=r.branch||await S(o),a=r.commitSha||await _(o);console.log(u.dim("Repository:")),console.log(` Name: ${u.cyan(i||"unknown")}`),console.log(` Branch: ${u.cyan(s)}`),console.log(` Commit: ${u.cyan(a.slice(0,7))}`),console.log();let{stat:l}=await import("fs/promises"),c=!1;try{await l(n),c=!0}catch{}if(!c){console.log(u.dim("Local Context:")),console.log(` Status: ${u.yellow("Not initialized")}`),console.log(),console.log("Run "+u.cyan("tk init")+" to create .thinker.md/");return}console.log(u.dim("Local Context:"));let d=await F(o),m=await ao(o),g=await co(n);if(console.log(` Status: ${u.green("Initialized")}`),console.log(` Project ID: ${u.cyan(d?.projectId||"unknown")}`),console.log(` Context files: ${u.cyan(g)}`),m&&(console.log(` Directories: ${u.cyan(m.directoryCount)}`),console.log(` Files tracked: ${u.cyan(m.fileCount)}`)),d?.generatedAt){let p=new Date(d.generatedAt);console.log(` Generated: ${u.cyan(p.toLocaleString())}`)}d?.pulledFrom&&console.log(` Pulled from: ${u.cyan(d.pulledFrom.slice(0,7))}`),console.log();let f=r.metaRepoId||d?.projectId;if(f&&r.r2Endpoint){console.log(u.dim("Remote Storage:")),e.start("Checking remote...");try{let p=await ct(f,s);p?(e.stop(),console.log(` Latest commit: ${u.cyan(p.slice(0,7))}`),p===a?console.log(` Status: ${u.green("Up to date")}`):d?.pulledFrom===p?console.log(` Status: ${u.yellow("Local changes not pushed")}`):(console.log(` Status: ${u.yellow("Remote has newer version")}`),console.log(),console.log("Run "+u.cyan("tk pull")+" to download latest context"))):(e.stop(),console.log(` Status: ${u.yellow("No remote context found")}`),console.log(),console.log("Run "+u.cyan("tk push")+" to upload context"))}catch{e.stop(),console.log(` Status: ${u.dim("Unable to check (no credentials)")}`)}}console.log(),console.log(u.dim("Mode:")),console.log(` ${r.mode==="sandbox"?u.cyan("Sandbox"):u.cyan("Local")}`),r.mode==="sandbox"&&console.log(` Job ID: ${u.cyan(r.jobId||"unknown")}`)}catch(o){e.fail("Failed to get status"),console.error(u.red(`Error: ${o}`)),process.exit(1)}}import w from"chalk";import lo from"ora";async function xe(e){let t=lo(),o=process.cwd();try{await N(o)||(console.error(w.red("Error: Not a git repository")),process.exit(1));let r=await v(o);if((await P()).mode==="sandbox"){console.error(w.yellow("Note: In sandbox mode, generation is triggered automatically.")),console.log("Use 'tk init' to create structure and 'tk push' when done.");return}let i=await $();i.apiToken||(console.error(w.red("Error: Not logged in")),console.log(),console.log("Please authenticate first:"),console.log(w.cyan(" tk login --token YOUR_TOKEN")),process.exit(1));let s=i.apiUrl||H,a=await z(r),l=e.branch||await S(r),c=await _(r);a||(console.error(w.red("Error: Unable to determine repository name")),console.log("Make sure this repository has a remote origin configured."),process.exit(1)),console.log(w.bold("Trigger Context Generation")),console.log(),console.log(`Repository: ${w.cyan(a)}`),console.log(`Branch: ${w.cyan(l)}`),console.log(`Commit: ${w.cyan(c.slice(0,7))}`),console.log(),t.start("Looking up meta-repository...");let d=await fetch(`${s}/api/meta-repositories/lookup?repo=${encodeURIComponent(a)}`,{headers:{Authorization:`Bearer ${i.apiToken}`}});d.ok||(d.status===404&&(t.fail("Meta-repository not found"),console.log(),console.log("This repository is not connected to ThinkerMD. Please add it at:"),console.log(w.cyan(`${s}/dashboard`)),process.exit(1)),t.fail("API error"),console.error(w.red(`Error: ${d.status} ${d.statusText}`)),process.exit(1));let m=await d.json();t.succeed(`Found meta-repository: ${m.id}`),t.start("Triggering generation job...");let g=await fetch(`${s}/api/jobs/generate`,{method:"POST",headers:{Authorization:`Bearer ${i.apiToken}`,"Content-Type":"application/json"},body:JSON.stringify({metaRepositoryId:m.id,commitSha:c,branch:l,priority:"normal"})});if(!g.ok){t.fail("Failed to trigger generation");let p=await g.json().catch(()=>({}));console.error(w.red(`Error: ${p.error||g.statusText}`)),process.exit(1)}let f=await g.json();if(t.succeed("Generation job queued"),console.log(),console.log(`Job ID: ${w.cyan(f.jobId)}`),console.log(`Status: ${w.cyan(f.status)}`),f.estimatedPosition&&console.log(`Queue position: ${w.cyan(f.estimatedPosition)}`),console.log(),console.log("Track progress at:"),console.log(w.cyan(`${s}/dashboard/repositories/${m.id}/jobs/${f.jobId}`)),e.wait){console.log(),t.start("Waiting for completion...");let p=!1,C="";for(;!p;){await new Promise(x=>setTimeout(x,5e3));let G=await fetch(`${s}/api/jobs/${f.jobId}`,{headers:{Authorization:`Bearer ${i.apiToken}`}});if(G.ok){let x=await G.json();x.status!==C&&(C=x.status,t.text=`Status: ${x.status} (${x.progress||0}%)`),(x.status==="completed"||x.status==="failed")&&(p=!0,x.status==="completed"?(t.succeed("Generation completed!"),console.log(),console.log("Run "+w.cyan("tk pull")+" to download the generated context")):(t.fail("Generation failed"),x.errorMessage&&console.error(w.red(`Error: ${x.errorMessage}`))))}}}}catch(r){t.fail("Failed to trigger generation"),console.error(w.red(`Error: ${r}`)),process.exit(1)}}import bt from"chalk";import{Hono as Ro}from"hono";import M from"chalk";import{createServer as To}from"http";import{homedir as Te}from"os";import{join as ve}from"path";import{readFile as uo,writeFile as go,mkdir as fo}from"fs/promises";import{existsSync as ho}from"fs";async function po(){return(await $()).apiUrl||process.env.THINKERMD_API_URL||H}async function mo(){return(await $()).apiToken||process.env.THINKERMD_API_TOKEN||null}async function lt(e,t={}){let o=await po(),r=await mo();if(!r)throw new Error("Not authenticated. Run `tk login` first.");let{method:n="GET",body:i,params:s}=t,a=`${o}${e}`;if(s){let c=new URLSearchParams(s);a+=`?${c.toString()}`}let l=await fetch(a,{method:n,headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json"},body:i?JSON.stringify(i):void 0});if(!l.ok){let c=await l.json().catch(()=>({}));throw new Error(c.error||`API request failed: ${l.status} ${l.statusText}`)}return l.json()}async function Ce(e,t,o={}){return lt("/api/mcp/search",{method:"POST",body:{repositoryId:e,query:t,branch:o.branch,limit:o.limit||10}})}async function Tt(e,t,o={}){return lt("/api/mcp/read",{params:{repositoryId:e,filePath:t,...o.branch&&{branch:o.branch}}})}async function Ee(e,t={}){return lt("/api/mcp/files",{params:{repositoryId:e,...t.branch&&{branch:t.branch}}})}async function Re(e){try{let t=await lt("/api/user/repositories",{params:{remoteUrl:e}});return t.repositories&&t.repositories.length>0?t.repositories[0]:null}catch{return null}}var vt=ve(Te(),".thinkermd","cache","repo-mapping.json"),yo=24*60*60*1e3;async function wo(){try{if(ho(vt)){let e=await uo(vt,"utf-8");return JSON.parse(e)}}catch{}return{mappings:{}}}async function xo(e){let t=ve(Te(),".thinkermd","cache");await fo(t,{recursive:!0}),await go(vt,JSON.stringify(e,null,2))}async function V(e){let t;try{t=await v(e)}catch{return console.error(`[RepoResolver] Not a git repository: ${e}`),null}let o=await yt(t);if(!o)return console.error(`[RepoResolver] No git remote found for: ${t}`),null;let r=Co(o),n=await wo(),i=n.mappings[r];if(i&&Date.now()-i.cachedAt<yo){console.log(`[RepoResolver] Cache hit for: ${r}`);let c=await S(t),d=await _(t);return{repositoryId:i.repositoryId,fullName:i.fullName,remoteUrl:r,gitRoot:t,branch:c||"main",commit:d||"HEAD"}}console.log(`[RepoResolver] Querying API for: ${r}`);let s=await Re(r);if(!s)return console.error(`[RepoResolver] Repository not found in ThinkerMD: ${r}`),null;n.mappings[r]={remoteUrl:r,repositoryId:s.id,fullName:s.fullName,cachedAt:Date.now()},await xo(n);let a=await S(t),l=await _(t);return{repositoryId:s.id,fullName:s.fullName,remoteUrl:r,gitRoot:t,branch:a||"main",commit:l||"HEAD"}}function Co(e){return e=e.replace(/\.git$/,""),e.startsWith("git@")&&(e=e.replace(/^git@/,"https://").replace(/:([^/])/,"/$1")),e.startsWith("http://")&&(e=e.replace("http://","https://")),e}async function dt(e){let{path:t,query:o,limit:r=10}=e,n=await V(t);if(!n)throw new Error(`Could not resolve repository for path: ${t}`);return{...await Ce(n.repositoryId,o,{branch:n.branch,limit:r}),repositoryId:n.repositoryId,fullName:n.fullName}}async function pt(e){let{path:t,filePath:o}=e,r=await V(t);if(!r)throw new Error(`Could not resolve repository for path: ${t}`);return{...await Tt(r.repositoryId,o,{branch:r.branch}),repositoryId:r.repositoryId,fullName:r.fullName}}async function mt(e){let{path:t}=e,o=await V(t);if(!o)throw new Error(`Could not resolve repository for path: ${t}`);let r=t;t.startsWith(o.gitRoot)&&(r=t.slice(o.gitRoot.length).replace(/^\//,""));let n=r?`.thinker.md/contexts/${r}/CONTEXT.md`:".thinker.md/contexts/CONTEXT.md";return{...await Tt(o.repositoryId,n,{branch:o.branch}),repositoryId:o.repositoryId,fullName:o.fullName}}async function ut(e){let{path:t}=e,o=await V(t);if(!o)throw new Error(`Could not resolve repository for path: ${t}`);return{...await Ee(o.repositoryId,{branch:o.branch}),repositoryId:o.repositoryId,fullName:o.fullName}}async function be(e){return V(e.path)}import{McpServer as Eo}from"@modelcontextprotocol/sdk/server/mcp.js";import{z as K}from"zod";function gt(){let e=new Eo({name:"thinkermd",version:"0.1.0"});return e.tool("thinkermd_search","Semantic search across context files in the repository. Use this to find relevant documentation and context about the codebase.",{query:K.string().describe("Search query - what you're looking for"),path:K.string().optional().describe("Path to directory (defaults to current working directory)"),limit:K.number().optional().default(10).describe("Maximum number of results to return")},async({query:t,path:o,limit:r})=>{try{let n=o||process.cwd(),i=await dt({path:n,query:t,limit:r});return{content:[{type:"text",text:JSON.stringify(i,null,2)}]}}catch(n){return{content:[{type:"text",text:`Error: ${n instanceof Error?n.message:"Search failed"}`}],isError:!0}}}),e.tool("thinkermd_read","Read a specific context file from the repository. Use this to get the full content of a CONTEXT.md file.",{filePath:K.string().describe("Path to the context file relative to repository root"),path:K.string().optional().describe("Path to repository directory (defaults to current working directory)")},async({filePath:t,path:o})=>{try{let r=o||process.cwd();return{content:[{type:"text",text:(await pt({path:r,filePath:t})).content}]}}catch(r){return{content:[{type:"text",text:`Error: ${r instanceof Error?r.message:"Read failed"}`}],isError:!0}}}),e.tool("thinkermd_get_context","Get the CONTEXT.md file for a specific directory. This provides contextual documentation about that part of the codebase.",{path:K.string().describe("Path to the directory to get context for")},async({path:t})=>{try{return{content:[{type:"text",text:(await mt({path:t})).content}]}}catch(o){return{content:[{type:"text",text:`Error: ${o instanceof Error?o.message:"Get context failed"}`}],isError:!0}}}),e.tool("thinkermd_list_files","List all CONTEXT.md files available in the repository. Use this to discover what documentation is available.",{path:K.string().optional().describe("Path to repository directory (defaults to current working directory)")},async({path:t})=>{try{let o=t||process.cwd(),r=await ut({path:o});return{content:[{type:"text",text:JSON.stringify(r,null,2)}]}}catch(o){return{content:[{type:"text",text:`Error: ${o instanceof Error?o.message:"List files failed"}`}],isError:!0}}}),e}import{StreamableHTTPServerTransport as vo}from"@modelcontextprotocol/sdk/server/streamableHttp.js";import{isInitializeRequest as bo}from"@modelcontextprotocol/sdk/types.js";var D=new Map;async function ko(e){let t=[];for await(let o of e)t.push(o);return Buffer.concat(t).toString()}async function Po(e,t){let o=e.headers["mcp-session-id"],r=await ko(e),n;try{n=JSON.parse(r)}catch{t.writeHead(400,{"Content-Type":"application/json"}),t.end(JSON.stringify({jsonrpc:"2.0",error:{code:-32700,message:"Parse error: Invalid JSON"},id:null}));return}if(o&&D.has(o)){await D.get(o).handleRequest(e,t,r);return}if(!o&&bo(n)){console.log("[MCP] New session initializing...");let i=new vo({sessionIdGenerator:()=>crypto.randomUUID(),onsessioninitialized:a=>{D.set(a,i),console.log(`[MCP] Session started: ${a}`)}});i.onclose=()=>{let a=i.sessionId;a&&D.has(a)&&(console.log(`[MCP] Session closed: ${a}`),D.delete(a))},await gt().connect(i),await i.handleRequest(e,t,r);return}t.writeHead(400,{"Content-Type":"application/json"}),t.end(JSON.stringify({jsonrpc:"2.0",error:{code:-32e3,message:"Bad Request: No valid session ID provided"},id:null}))}async function So(e,t){let o=e.headers["mcp-session-id"];if(!o||!D.has(o)){t.writeHead(400,{"Content-Type":"application/json"}),t.end(JSON.stringify({error:"Invalid or missing session ID"}));return}console.log(`[MCP] SSE stream requested for session: ${o}`),await D.get(o).handleRequest(e,t)}async function $o(e,t){let o=e.headers["mcp-session-id"];if(!o||!D.has(o)){t.writeHead(400,{"Content-Type":"application/json"}),t.end(JSON.stringify({error:"Invalid or missing session ID"}));return}console.log(`[MCP] Session termination requested: ${o}`),await D.get(o).handleRequest(e,t)}async function Io(e,t){try{e.method==="POST"?await Po(e,t):e.method==="GET"?await So(e,t):e.method==="DELETE"?await $o(e,t):(t.writeHead(405,{"Content-Type":"application/json"}),t.end(JSON.stringify({error:"Method not allowed"})))}catch(o){console.error("[MCP] Error handling request:",o),t.headersSent||(t.writeHead(500,{"Content-Type":"application/json"}),t.end(JSON.stringify({jsonrpc:"2.0",error:{code:-32603,message:"Internal server error"},id:null})))}}function No(){let e=new Ro;return e.get("/health",t=>t.json({status:"ok",version:"0.1.0"})),e.post("/mcp/search",async t=>{try{let o=await t.req.json(),{path:r,query:n,limit:i}=o;if(!r||!n)return t.json({error:"path and query are required"},400);let s=await dt({path:r,query:n,limit:i});return t.json(s)}catch(o){return console.error("[MCP] Search error:",o),t.json({error:o instanceof Error?o.message:"Search failed"},500)}}),e.get("/mcp/read",async t=>{try{let o=t.req.query("path"),r=t.req.query("filePath");if(!o||!r)return t.json({error:"path and filePath are required"},400);let n=await pt({path:o,filePath:r});return t.json(n)}catch(o){return console.error("[MCP] Read error:",o),t.json({error:o instanceof Error?o.message:"Read failed"},500)}}),e.get("/mcp/context",async t=>{try{let o=t.req.query("path");if(!o)return t.json({error:"path is required"},400);let r=await mt({path:o});return t.json(r)}catch(o){return console.error("[MCP] Get context error:",o),t.json({error:o instanceof Error?o.message:"Get context failed"},500)}}),e.get("/mcp/files",async t=>{try{let o=t.req.query("path");if(!o)return t.json({error:"path is required"},400);let r=await ut({path:o});return t.json(r)}catch(o){return console.error("[MCP] List files error:",o),t.json({error:o instanceof Error?o.message:"List files failed"},500)}}),e.get("/mcp/repo",async t=>{try{let o=t.req.query("path");if(!o)return t.json({error:"path is required"},400);let r=await be({path:o});return r?t.json({connected:!0,...r}):t.json({connected:!1,message:"Repository not found in ThinkerMD"})}catch(o){return console.error("[MCP] Get repo info error:",o),t.json({error:o instanceof Error?o.message:"Get repo info failed"},500)}}),e}function _o(e,t){let o=`http://localhost:${e}/mcp`,r=64,n=40,i=t.length>n?t.slice(0,n-3)+"...":t;console.log(M.cyan(`
|
|
104
104
|
\u2554${"\u2550".repeat(r)}\u2557
|
|
105
105
|
\u2551${" ".repeat(r)}\u2551
|
|
106
106
|
\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2557\u2588\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2551
|
|
@@ -112,17 +112,17 @@ This appears to be the first generation. Use 'tk init' to create initial structu
|
|
|
112
112
|
\u2551 .md \u2551
|
|
113
113
|
\u2551${" ".repeat(r)}\u2551
|
|
114
114
|
\u2560${"\u2550".repeat(r)}\u2563
|
|
115
|
-
\u2551${" ".repeat(r)}\u2551`));let s=` \u2713 Logged in as: ${i}`,a=s+" ".repeat(Math.max(0,r-s.length));console.log(
|
|
115
|
+
\u2551${" ".repeat(r)}\u2551`));let s=` \u2713 Logged in as: ${i}`,a=s+" ".repeat(Math.max(0,r-s.length));console.log(M.cyan("\u2551")+a+M.cyan("\u2551"));let l=` \u2713 Daemon running on: ${o}`,c=l+" ".repeat(Math.max(0,r-l.length));console.log(M.cyan("\u2551")+c+M.cyan("\u2551")),console.log(M.cyan(`\u2551${" ".repeat(r)}\u2551
|
|
116
116
|
\u2560${"\u2550".repeat(r)}\u2563
|
|
117
117
|
\u2551 Add to your AI tool config: \u2551
|
|
118
118
|
\u2551${" ".repeat(r)}\u2551
|
|
119
119
|
\u2551 { \u2551
|
|
120
120
|
\u2551 "mcpServers": { \u2551
|
|
121
121
|
\u2551 "thinkermd": { \u2551
|
|
122
|
-
\u2551 "type": "http", \u2551`));let d=` "url": "${o}"`,
|
|
122
|
+
\u2551 "type": "http", \u2551`));let d=` "url": "${o}"`,m=" "+d+" ".repeat(Math.max(0,r-3-d.length));console.log(M.cyan("\u2551")+m+M.cyan("\u2551")),console.log(M.cyan(`\u2551 } \u2551
|
|
123
123
|
\u2551 } \u2551
|
|
124
124
|
\u2551 } \u2551
|
|
125
125
|
\u2551${" ".repeat(r)}\u2551
|
|
126
|
-
\u2551 ${
|
|
126
|
+
\u2551 ${M.yellow("Press Ctrl+C to stop")} \u2551
|
|
127
127
|
\u255A${"\u2550".repeat(r)}\u255D
|
|
128
|
-
`))}async function
|
|
128
|
+
`))}async function ke(e){let{port:t}=e,o=No(),r=await $(),n=r.email||r.userId||"authenticated user";To(async(s,a)=>{let l=new URL(s.url||"/",`http://localhost:${t}`);if(l.pathname==="/mcp"){await Io(s,a);return}let c={};for(let[m,g]of Object.entries(s.headers))typeof g=="string"?c[m]=g:Array.isArray(g)&&(c[m]=g.join(", "));let d=await o.fetch(new Request(l.toString(),{method:s.method,headers:c,body:s.method!=="GET"&&s.method!=="HEAD"?s:void 0,duplex:"half"}));if(a.writeHead(d.status,Object.fromEntries(d.headers.entries())),d.body){let m=d.body.getReader();try{for(;;){let{done:g,value:f}=await m.read();if(g)break;a.write(f)}}finally{m.releaseLock()}}a.end()}).listen(t,()=>{_o(t,n)}),await new Promise(()=>{})}var Ao=3456;async function kt(e){(await $()).apiToken||(console.error(bt.red("Not authenticated. Run `tk login` first.")),process.exit(1));let o=e.port?parseInt(e.port,10):Ao;(isNaN(o)||o<1||o>65535)&&(console.error(bt.red(`Invalid port: ${e.port}`)),process.exit(1));try{await ke({port:o})}catch(r){console.error(bt.red("Failed to start daemon:"),r),process.exit(1)}}import{StdioServerTransport as Oo}from"@modelcontextprotocol/sdk/server/stdio.js";async function Pe(){let e=gt(),t=new Oo;await e.connect(t)}var T=new Fo;T.name("tk").description("ThinkerMD CLI - Manage .thinker.md/ context files").version("0.1.0");T.command("init").description("Create .thinker.md/ structure with empty CONTEXT.md files").option("-f, --force","Reinitialize even if .thinker.md/ exists").option("-m, --merge","Only add missing CONTEXT.md files, keep existing ones").action(e=>Zt(e));T.command("validate").description("Verify .thinker.md/ structure matches repository").option("-q, --quiet","Only output errors, no summary").action(e=>te(e));T.command("pull").description("Download previous context from storage").option("-b, --branch <branch>","Specify branch to pull from").option("-c, --commit <sha>","Pull specific commit version").action(e=>ce(e));T.command("push").description("Validate and upload .thinker.md/ to storage").option("--skip-validation","Skip validation before push").option("--force-full","Force full generation mode (ignore previous context)").action(e=>pe(e));T.command("login").description("Authenticate with ThinkerMD API").option("-t, --token <token>","API token").option("--api-url <url>","Custom API URL").action(e=>fe(e));T.command("logout").description("Remove saved authentication").action(()=>he());T.command("status").description("Show status of .thinker.md/ context").action(()=>we());T.command("generate").description("Trigger context generation via API").option("-b, --branch <branch>","Specify branch to generate for").option("-w, --wait","Wait for generation to complete").action(e=>xe(e));T.command("serve").description("Start MCP daemon for AI assistant integration").option("-p, --port <port>","Port to listen on","3456").action(e=>kt(e));T.command("mcp").description("Run as stdio MCP server (for Claude Code integration)").action(()=>Pe());T.on("command:*",()=>{console.error(Se.red(`Unknown command: ${T.args.join(" ")}`)),console.log(),T.help()});async function $e(){try{if(process.argv.length===2){await kt({port:"3456"});return}await T.parseAsync(process.argv)}catch(e){e instanceof Error&&console.error(Se.red(`Error: ${e.message}`)),process.exit(1)}}$e().catch(e=>{console.error("Fatal error:",e),process.exit(1)});
|