@xtrn/cli 1.1.0 → 1.1.2

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/cli.js CHANGED
@@ -1,13 +1,13 @@
1
1
  #!/usr/bin/env node
2
- import{spawn as V}from"node:child_process";import*as R from"node:fs";import*as _ from"node:path";import{spawn as Y}from"node:child_process";import*as x from"node:fs";import*as T from"node:os";import*as g from"node:path";function X(s){let n=s;while(!0){let o=g.join(n,"node_modules");if(x.existsSync(o))return o;let t=g.dirname(n);if(t===n)return null;n=t}}function A(s,n,o){let t=g.dirname(s),r=X(t);if(!r)console.warn("[xtrn] Warning: node_modules not found for symlink");let i=g.join(o,"node_modules");if(r&&!x.existsSync(i))x.symlinkSync(r,i,"junction");let f=`export { XTRNState } from "@xtrn/server";
3
- export { default } from "${s}";
4
- `;x.writeFileSync(g.join(o,"_cf_entry.ts"),f);let u=`name = "xtrn-dev"
2
+ import{spawn as Y}from"node:child_process";import*as R from"node:fs";import*as y from"node:path";import{spawn as L}from"node:child_process";import*as d from"node:fs";import*as I from"node:os";import*as g from"node:path";function X(o){let t=o;while(!0){let n=g.join(t,"node_modules");if(d.existsSync(n))return n;let e=g.dirname(t);if(e===t)return null;t=e}}function O(o,t,n){let e=g.dirname(o),r=X(e);if(!r)console.warn("[xtrn] Warning: node_modules not found for symlink");let i=g.join(n,"node_modules");if(r&&!d.existsSync(i))d.symlinkSync(r,i,"junction");let l=`export { XTRNState } from "@xtrn/server";
3
+ export { default } from "${o}";
4
+ `;d.writeFileSync(g.join(n,"_cf_entry.ts"),l);let m=`name = "xtrn-dev"
5
5
  main = "_cf_entry.ts"
6
6
  compatibility_date = "2026-02-14"
7
7
  compatibility_flags = ["nodejs_compat"]
8
8
 
9
9
  [vars]
10
- ${Object.entries(n).map(([a,l])=>`${a} = "${l}"`).join(`
10
+ ${Object.entries(t).map(([c,f])=>`${c} = "${f}"`).join(`
11
11
  `)}
12
12
 
13
13
  [[durable_objects.bindings]]
@@ -17,9 +17,9 @@ class_name = "XTRNState"
17
17
  [[migrations]]
18
18
  tag = "v1"
19
19
  new_sqlite_classes = ["XTRNState"]
20
- `;x.writeFileSync(g.join(o,"wrangler.toml"),u)}async function O(s,n){let o=g.dirname(s),t=g.basename(s),r=g.join(n,t);x.copyFileSync(s,r);let i=X(o);if(!i)console.warn("[xtrn] Warning: node_modules not found for symlink");let f=g.join(n,"node_modules");if(i&&!x.existsSync(f))x.symlinkSync(i,f,"junction");let u=`export { XTRNState } from "@xtrn/server";
21
- export { default } from "${`./${t}`}";
22
- `,a=g.join(n,"_cf_entry.ts");x.writeFileSync(a,u);let l=`name = "xtrn-dev"
20
+ `;d.writeFileSync(g.join(n,"wrangler.toml"),m)}async function P(o,t){let n=g.dirname(o),e=g.basename(o),r=g.join(t,e);d.copyFileSync(o,r);let i=X(n);if(!i)console.warn("[xtrn] Warning: node_modules not found for symlink");let l=g.join(t,"node_modules");if(i&&!d.existsSync(l))d.symlinkSync(i,l,"junction");let m=`export { XTRNState } from "@xtrn/server";
21
+ export { default } from "${`./${e}`}";
22
+ `,c=g.join(t,"_cf_entry.ts");d.writeFileSync(c,m);let f=`name = "xtrn-dev"
23
23
  main = "_cf_entry.ts"
24
24
  compatibility_date = "2026-02-14"
25
25
  compatibility_flags = ["nodejs_compat"]
@@ -31,16 +31,16 @@ class_name = "XTRNState"
31
31
  [[migrations]]
32
32
  tag = "v1"
33
33
  new_sqlite_classes = ["XTRNState"]
34
- `;return x.writeFileSync(g.join(n,"wrangler.toml"),l),await Z(n),g.join(n,"_cf_entry.js")}function Z(s){return new Promise((n,o)=>{let t=Y("wrangler",["deploy","--dry-run","--outdir","."],{cwd:s,stdio:["ignore","pipe","pipe"]}),r="";t.stdout?.on("data",()=>{}),t.stderr?.on("data",(i)=>{r+=i.toString()}),t.on("error",(i)=>{o(Error(`Failed to spawn wrangler: ${i.message}`))}),t.on("close",(i)=>{if(i!==0){o(Error(`wrangler deploy --dry-run failed (exit ${i}):
35
- ${r}`));return}n()})})}function d(){return x.mkdtempSync(g.join(T.tmpdir(),"xtrn-dev-"))}function S(s){x.rmSync(s,{recursive:!0,force:!0})}import*as $ from"node:fs";import*as F from"node:path";import{Miniflare as G}from"miniflare";function K(s,n,o,t){let r=t||F.dirname(s);return{modules:!0,scriptPath:s,modulesRoot:r,compatibilityDate:"2026-02-14",compatibilityFlags:["nodejs_compat"],durableObjects:{XTRN_STATE:"XTRNState"},durableObjectsPersist:!0,port:n,bindings:o}}async function C(s,n,o,t){let r=K(s,n,o,t),i=new G(r);return await i.ready,i}function q(s){if(!$.existsSync(s))return{};let n=$.readFileSync(s,"utf-8"),o={};for(let t of n.split(`
36
- `)){let r=t.trim();if(!r||r.startsWith("#"))continue;let i=r.indexOf("=");if(i===-1)continue;o[r.slice(0,i)]=r.slice(i+1)}return o}async function W(s){return await(await s.dispatchFetch("http://localhost/details")).json()}var e={reset:"\x1B[0m",bold:"\x1B[1m",dim:"\x1B[2m",cyan:"\x1B[36m",green:"\x1B[32m",yellow:"\x1B[33m",magenta:"\x1B[35m",white:"\x1B[37m",red:"\x1B[31m",gray:"\x1B[90m"};function P(s){let n="./index.ts",o=1234;for(let t of s)if(t.startsWith("--port="))o=Number.parseInt(t.slice(t.indexOf("=")+1),10);else if(!t.startsWith("--"))n=t;return{entryPoint:_.resolve(n),port:o}}async function k(s){for(let o=0;o<5;o++){try{let t=await fetch(`http://localhost:${s}/details`);if(t.ok)return await t.json()}catch{}await new Promise((t)=>setTimeout(t,200))}throw Error("Failed to fetch /details after server ready")}function D(s,n){let o=`http://localhost:${s}`;if(console.log(""),console.log(` ${e.bold}${e.cyan}${n.name}${e.reset} ${e.dim}${n.version}${e.reset}`),console.log(` ${e.green}➜${e.reset} ${e.bold}${o}${e.reset}`),console.log(""),n.tools.length>0){console.log(` ${e.bold}${e.white}Tools${e.reset}`);for(let t of n.tools){let r=t.tags.length>0?` ${e.dim}${t.tags.map((i)=>`[${i}]`).join(" ")}${e.reset}`:"";console.log(` ${e.cyan}${t.name}${e.reset}${r} ${e.gray}— ${t.description}${e.reset}`)}console.log("")}if(n.config.length>0){console.log(` ${e.bold}${e.white}Config${e.reset}`);for(let t of n.config)console.log(` ${e.yellow}${t.key}${e.reset} ${e.dim}${t.type}${e.reset}`);console.log("")}if(n.requiredEnv.length>0){console.log(` ${e.bold}${e.white}Required Env${e.reset}`);for(let t of n.requiredEnv)console.log(` ${e.yellow}${t}${e.reset}`);console.log("")}if(n.oauth)console.log(` ${e.bold}${e.white}OAuth${e.reset} ${e.magenta}${n.oauth.provider}${e.reset}`),console.log(` ${e.dim}authorize${e.reset} ${n.oauth.authorization_url}`),console.log(` ${e.dim}token${e.reset} ${n.oauth.token_url}`),console.log(` ${e.dim}callback${e.reset} ${n.oauth.callback_url}`),console.log(` ${e.dim}scopes${e.reset} ${n.oauth.scopes.join(", ")}`),console.log("")}function nn(s,n){let o=_.join(s,"wrangler.toml"),t=V("npx",["wrangler","dev","--config",o,"--port",String(n)],{cwd:s,stdio:["ignore","pipe","pipe"]}),r="",i=new Promise((f,m)=>{let u=(l)=>{if(l.toString().includes("Ready on"))t.stdout?.off("data",u),f()},a=(l)=>{r+=l.toString()};t.stdout?.on("data",u),t.stderr?.on("data",a),t.on("error",(l)=>m(l)),t.on("close",(l)=>{if(l!==0&&l!==null)m(Error(r.trim()||`wrangler exited with code ${l}`))})});return i.then(()=>{r="",t.stderr?.on("data",(f)=>{let m=f.toString();if(m.includes("ERROR")||m.includes("Error")||m.includes("error:"))process.stderr.write(`${e.red}[xtrn dev]${e.reset} ${m}`)})}),{proc:t,ready:i}}async function I(s){let{entryPoint:n,port:o}=P(s),t=_.dirname(n);if(!R.existsSync(n))console.error(`${e.red}[xtrn dev]${e.reset} Entry point not found: ${n}`),process.exit(1);if(!R.existsSync(_.join(t,"package.json")))console.error(`${e.red}[xtrn dev]${e.reset} No package.json found in ${t}`),process.exit(1);let r=_.join(t,".dev.vars"),i=q(r),f=d();A(n,i,f);let m=null,u=()=>{if(console.log(`
37
- ${e.dim}[xtrn dev] Shutting down...${e.reset}`),m)m.kill(),m=null;S(f),process.exit(0)};process.on("SIGINT",u),process.on("SIGTERM",u);try{console.log(`${e.dim}[xtrn dev] Starting...${e.reset}`);let a=nn(f,o);m=a.proc,m.on("error",(c)=>{console.error(`${e.red}[xtrn dev]${e.reset} Failed to start: ${c.message}`),S(f),process.exit(1)}),m.on("close",(c)=>{if(c!==0&&c!==null)console.error(`${e.red}[xtrn dev]${e.reset} Process exited with code ${c}`);S(f),process.exit(c??1)}),await a.ready;let l=await k(o);D(o,l),await new Promise(()=>{})}catch(a){if(m)m.kill();if(S(f),a instanceof Error)console.error(`${e.red}[xtrn dev]${e.reset} ${a.message}`);process.exit(1)}}import{mkdir as U,readFile as tn,writeFile as on}from"node:fs/promises";import{dirname as sn,join as N}from"node:path";import{fileURLToPath as en}from"node:url";async function H(s){let n=s[0],o=s[1]??"v1.0.0";if(!n)console.error("Error: <name> argument is required"),console.error("Usage: xtrn new <name> [version]"),process.exit(1);let t=o.startsWith("v")?o:`v${o}`,r=t.replace(/^v/,"");if(!/^\d+\.\d+\.\d+$/.test(r))console.error(`Error: Invalid version "${o}". Expected semver (e.g., v1.0.0)`),process.exit(1);let i=en(import.meta.url),f=sn(i),m=N(f,"../templates"),u=N(process.cwd(),n);try{await U(u,{recursive:!1})}catch(a){if(a instanceof Error&&"code"in a&&a.code==="EEXIST")console.error(`Error: Directory "${n}" already exists`),process.exit(1);throw a}try{let a=[{src:"index.ts.template",dst:"index.ts"},{src:"package.json.template",dst:"package.json"},{src:"tsconfig.json.template",dst:"tsconfig.json"},{src:"README.md.template",dst:"README.md"}];for(let l of a){let c=N(m,l.src),j=N(u,l.dst),w=await tn(c,"utf-8");if(w=w.replace(/\{\{NAME\}\}/g,n),w=w.replace(/\{\{VERSION\}\}/g,t),w=w.replace(/\{\{VERSION_BARE\}\}/g,r),l.dst==="package.json"){let E=JSON.parse(w);E.dependencies["@xtrn/server"]="^1.0.0",E.devDependencies["@xtrn/cli"]="^1.0.0",E.scripts.submit="xtrn submit",w=`${JSON.stringify(E,null,"\t")}
38
- `}await on(j,w,"utf-8")}console.log(`✓ Created ${n}/`),console.log(""),console.log("Next steps:"),console.log(` cd ${n}`),console.log(" bun install"),console.log(" bun run dev")}catch(a){try{await U(u,{recursive:!0})}catch{}throw a}}import{spawn as rn}from"node:child_process";import*as y from"node:fs";import{cp as J,mkdir as z,readFile as fn,readdir as mn,writeFile as an}from"node:fs/promises";import*as M from"node:os";import*as v from"node:path";var p="xtrnai/servers",ln=new Set(["node_modules","bun.lock",".dev.vars","dist","_cf_entry.ts","wrangler.toml",".wrangler",".git",".github"]);function b(s,n,o){return new Promise((t)=>{let r=rn(s,n,{stdio:"pipe",cwd:o?.cwd}),i="",f="";r.stdout.on("data",(m)=>{i+=m.toString()}),r.stderr.on("data",(m)=>{f+=m.toString()}),r.on("close",(m)=>{t({stdout:i.trim(),stderr:f.trim(),code:m??1})}),r.on("error",()=>{t({stdout:"",stderr:`Failed to execute: ${s}`,code:1})})})}async function xn(){if((await b("gh",["--version"])).code!==0)console.error("[xtrn submit] GitHub CLI (gh) is not installed."),console.error(""),console.error("Install it:"),console.error(" macOS: brew install gh"),console.error(" Linux: https://github.com/cli/cli/blob/trunk/docs/install_linux.md"),console.error(" Windows: winget install --id GitHub.cli"),console.error(""),console.error("Then authenticate:"),console.error(" gh auth login"),process.exit(1);if((await b("gh",["auth","status"])).code!==0)console.error("[xtrn submit] GitHub CLI is not authenticated."),console.error(""),console.error("Run:"),console.error(" gh auth login"),process.exit(1)}function gn(s){if(!y.existsSync(v.join(s,"index.ts")))console.error("[xtrn submit] No index.ts found in current directory."),console.error("Run this command from your XTRN server project root."),process.exit(1);if(!y.existsSync(v.join(s,"package.json")))console.error("[xtrn submit] No package.json found in current directory."),console.error("Run this command from your XTRN server project root."),process.exit(1)}async function un(s){let n=v.resolve(s,"index.ts"),o=d(),t=null;try{console.log("[xtrn submit] Bundling server...");let r=await O(n,o);console.log("[xtrn submit] Starting headless Miniflare..."),t=await C(r,0,{});let i=await W(t),f=i.name,m=i.version;if(typeof f!=="string"||!f)throw Error("Server /details missing 'name' field");if(typeof m!=="string"||!m)throw Error("Server /details missing 'version' field");return console.log(`[xtrn submit] Detected: ${f} v${m}`),{name:f,version:m}}finally{if(t)await t.dispose();S(o)}}async function B(s,n){await z(n,{recursive:!0});let o=await mn(s,{withFileTypes:!0});for(let t of o){if(ln.has(t.name))continue;let r=v.join(s,t.name),i=v.join(n,t.name);if(t.isDirectory())await B(r,i);else await J(r,i)}}function cn(s){let n=JSON.parse(s),o=(t)=>{if(!t||typeof t!=="object")return;let r={};for(let[i,f]of Object.entries(t))if(typeof f==="string"&&(f.startsWith("file:")||f.startsWith("link:")||f.startsWith("workspace:")))r[i]="^1.0.0";else r[i]=f;return r};if(n.dependencies)n.dependencies=o(n.dependencies);if(n.devDependencies)n.devDependencies=o(n.devDependencies);return`${JSON.stringify(n,null,"\t")}
39
- `}async function vn(s,n){console.log("[xtrn submit] Preparing files..."),await B(s,n);let o=v.join(n,"package.json");if(y.existsSync(o)){let t=await fn(o,"utf-8"),r=cn(t);await an(o,r,"utf-8"),console.log("[xtrn submit] Rewrote package.json (local deps → ^1.0.0)")}}async function yn(s,n,o){let t=y.mkdtempSync(v.join(M.tmpdir(),"xtrn-submit-")),r=v.join(t,"xtrn-servers");try{console.log(`[xtrn submit] Forking ${p}...`);let i=await b("gh",["repo","fork",p,"--clone=true","--default-branch-only"],{cwd:t});if(i.code!==0&&!i.stderr.includes("already exists"))throw Error(`Fork failed: ${i.stderr}`);if(!y.existsSync(r))throw Error(`Expected cloned repo at ${r}, not found. Output: ${i.stdout} ${i.stderr}`);let f=`submit/${s}/v${n}`;console.log(`[xtrn submit] Creating branch ${f}...`);let m=await b("git",["checkout","-b",f],{cwd:r});if(m.code!==0)throw Error(`Branch creation failed: ${m.stderr}`);let u=v.join(r,"servers",s,`v${n}`);await z(u,{recursive:!0}),await J(o,u,{recursive:!0}),console.log("[xtrn submit] Committing...");let a=await b("git",["add","."],{cwd:r});if(a.code!==0)throw Error(`git add failed: ${a.stderr}`);let l=await b("git",["commit","-m",`Add ${s} v${n}`],{cwd:r});if(l.code!==0)throw Error(`git commit failed: ${l.stderr}`);console.log("[xtrn submit] Pushing...");let c=await b("git",["push","origin",f],{cwd:r});if(c.code!==0)throw Error(`git push failed: ${c.stderr}`);console.log("[xtrn submit] Creating pull request...");let j=await b("gh",["pr","create","--repo",p,"--title",`Add ${s} v${n}`,"--body",`Automated submission via \`xtrn submit\` CLI.
34
+ `;return d.writeFileSync(g.join(t,"wrangler.toml"),f),await Q(t),g.join(t,"_cf_entry.js")}function Q(o){return new Promise((t,n)=>{let e=L("wrangler",["deploy","--dry-run","--outdir","."],{cwd:o,stdio:["ignore","pipe","pipe"]}),r="";e.stdout?.on("data",()=>{}),e.stderr?.on("data",(i)=>{r+=i.toString()}),e.on("error",(i)=>{n(Error(`Failed to spawn wrangler: ${i.message}`))}),e.on("close",(i)=>{if(i!==0){n(Error(`wrangler deploy --dry-run failed (exit ${i}):
35
+ ${r}`));return}t()})})}function S(){return d.mkdtempSync(g.join(I.tmpdir(),"xtrn-dev-"))}function v(o){d.rmSync(o,{recursive:!0,force:!0})}import*as _ from"node:fs";import{Miniflare as vt}from"miniflare";function q(o){if(!_.existsSync(o))return{};let t=_.readFileSync(o,"utf-8"),n={};for(let e of t.split(`
36
+ `)){let r=e.trim();if(!r||r.startsWith("#"))continue;let i=r.indexOf("=");if(i===-1)continue;n[r.slice(0,i)]=r.slice(i+1)}return n}var s={reset:"\x1B[0m",bold:"\x1B[1m",dim:"\x1B[2m",cyan:"\x1B[36m",green:"\x1B[32m",yellow:"\x1B[33m",magenta:"\x1B[35m",white:"\x1B[37m",red:"\x1B[31m",gray:"\x1B[90m"};function Z(o){let t="./index.ts",n=1234;for(let e of o)if(e.startsWith("--port="))n=Number.parseInt(e.slice(e.indexOf("=")+1),10);else if(!e.startsWith("--"))t=e;return{entryPoint:y.resolve(t),port:n}}async function K(o){for(let n=0;n<5;n++){try{let e=await fetch(`http://localhost:${o}/details`);if(e.ok)return await e.json()}catch{}await new Promise((e)=>setTimeout(e,200))}throw Error("Failed to fetch /details after server ready")}function k(o,t){let n=`http://localhost:${o}`;if(console.log(""),console.log(` ${s.bold}${s.cyan}${t.name}${s.reset} ${s.dim}${t.version}${s.reset}`),console.log(` ${s.green}➜${s.reset} ${s.bold}${n}${s.reset}`),console.log(""),t.tools.length>0){console.log(` ${s.bold}${s.white}Tools${s.reset}`);for(let e of t.tools){let r=e.tags.length>0?` ${s.dim}${e.tags.map((i)=>`[${i}]`).join(" ")}${s.reset}`:"";console.log(` ${s.cyan}${e.name}${s.reset}${r} ${s.gray}— ${e.description}${s.reset}`)}console.log("")}if(t.config.length>0){console.log(` ${s.bold}${s.white}Config${s.reset}`);for(let e of t.config)console.log(` ${s.yellow}${e.key}${s.reset} ${s.dim}${e.type}${s.reset}`);console.log("")}if(t.requiredEnv.length>0){console.log(` ${s.bold}${s.white}Required Env${s.reset}`);for(let e of t.requiredEnv)console.log(` ${s.yellow}${e}${s.reset}`);console.log("")}if(t.oauth)console.log(` ${s.bold}${s.white}OAuth${s.reset} ${s.magenta}${t.oauth.provider}${s.reset}`),console.log(` ${s.dim}authorize${s.reset} ${t.oauth.authorization_url}`),console.log(` ${s.dim}token${s.reset} ${t.oauth.token_url}`),console.log(` ${s.dim}callback${s.reset} ${t.oauth.callback_url}`),console.log(` ${s.dim}scopes${s.reset} ${t.oauth.scopes.join(", ")}`),console.log("")}function D(o,t){let n=y.join(o,"wrangler.toml"),e=Y("npx",["wrangler","dev","--config",n,"--port",String(t)],{cwd:o,stdio:["ignore","pipe","pipe"]}),r="";e.stderr?.on("data",(a)=>{r+=a.toString()});let i=new Promise((a,m)=>{let c=(f)=>{if(f.toString().includes("Ready on"))e.stdout?.off("data",c),e.stdout?.resume(),a()};e.stdout?.on("data",c),e.on("error",(f)=>m(f)),e.on("close",(f)=>{if(f!==0&&f!==null)m(Error(r.trim()||`wrangler exited with code ${f}`))})}),l=new Promise((a,m)=>{e.on("close",(c,f)=>{if(c!==0&&c!==null&&f===null)m(Error(r.trim()||`wrangler exited with code ${c}`));else a()})});return{proc:e,ready:i,done:l}}async function W(o){let{entryPoint:t,port:n}=Z(o),e=y.dirname(t);if(!R.existsSync(t))console.error(`${s.red}[xtrn dev]${s.reset} Entry point not found: ${t}`),process.exit(1);if(!R.existsSync(y.join(e,"package.json")))console.error(`${s.red}[xtrn dev]${s.reset} No package.json found in ${e}`),process.exit(1);let r=y.join(e,".dev.vars"),i=q(r),l=S();O(t,i,l);let a=null,m=()=>{if(console.log(`
37
+ ${s.dim}[xtrn dev] Shutting down...${s.reset}`),a)a.kill(),a=null;v(l),process.exit(0)};process.on("SIGINT",m),process.on("SIGTERM",m);try{console.log(`${s.dim}[xtrn dev] Starting...${s.reset}`);let c=D(l,n);a=c.proc,await c.ready;let f=await K(n);k(n,f),await c.done,v(l),process.exit(0)}catch(c){if(a)a.kill();if(v(l),c instanceof Error)console.error(`${s.red}[xtrn dev]${s.reset} ${c.message}`);process.exit(1)}}import{mkdir as B,readFile as tt,writeFile as et}from"node:fs/promises";import{dirname as nt,join as j}from"node:path";import{fileURLToPath as ot}from"node:url";async function F(o){let t=o[0],n=o[1]??"v1.0.0";if(!t)console.error("Error: <name> argument is required"),console.error("Usage: xtrn new <name> [version]"),process.exit(1);let e=n.startsWith("v")?n:`v${n}`,r=e.replace(/^v/,"");if(!/^\d+\.\d+\.\d+$/.test(r))console.error(`Error: Invalid version "${n}". Expected semver (e.g., v1.0.0)`),process.exit(1);let i=ot(import.meta.url),l=nt(i),a=j(l,"../templates"),m=j(process.cwd(),t);try{await B(m,{recursive:!1})}catch(c){if(c instanceof Error&&"code"in c&&c.code==="EEXIST")console.error(`Error: Directory "${t}" already exists`),process.exit(1);throw c}try{let c=[{src:"index.ts.template",dst:"index.ts"},{src:"package.json.template",dst:"package.json"},{src:"tsconfig.json.template",dst:"tsconfig.json"},{src:"README.md.template",dst:"README.md"}];for(let f of c){let h=j(a,f.src),b=j(m,f.dst),x=await tt(h,"utf-8");if(x=x.replace(/\{\{NAME\}\}/g,t),x=x.replace(/\{\{VERSION\}\}/g,e),x=x.replace(/\{\{VERSION_BARE\}\}/g,r),f.dst==="package.json"){let w=JSON.parse(x);w.dependencies["@xtrn/server"]="^1.0.0",w.devDependencies["@xtrn/cli"]="^1.0.0",w.scripts.submit="xtrn submit",x=`${JSON.stringify(w,null,"\t")}
38
+ `}await et(b,x,"utf-8")}console.log(`✓ Created ${t}/`),console.log(""),console.log("Next steps:"),console.log(` cd ${t}`),console.log(" bun install"),console.log(" bun run dev")}catch(c){try{await B(m,{recursive:!0})}catch{}throw c}}import{spawn as rt}from"node:child_process";import*as u from"node:fs";import{cp as V,mkdir as z,readFile as st,readdir as it,writeFile as at}from"node:fs/promises";import*as A from"node:os";import*as p from"node:path";var N="xtrnai/servers",ct=new Set(["node_modules","bun.lock",".dev.vars","dist","_cf_entry.ts","wrangler.toml",".wrangler",".git",".github"]);function $(o,t,n){return new Promise((e)=>{let r=rt(o,t,{stdio:"pipe",cwd:n?.cwd}),i="",l="";r.stdout.on("data",(a)=>{i+=a.toString()}),r.stderr.on("data",(a)=>{l+=a.toString()}),r.on("close",(a)=>{e({stdout:i.trim(),stderr:l.trim(),code:a??1})}),r.on("error",()=>{e({stdout:"",stderr:`Failed to execute: ${o}`,code:1})})})}async function lt(){if((await $("gh",["--version"])).code!==0)console.error("[xtrn submit] GitHub CLI (gh) is not installed."),console.error(""),console.error("Install it:"),console.error(" macOS: brew install gh"),console.error(" Linux: https://github.com/cli/cli/blob/trunk/docs/install_linux.md"),console.error(" Windows: winget install --id GitHub.cli"),console.error(""),console.error("Then authenticate:"),console.error(" gh auth login"),process.exit(1);if((await $("gh",["auth","status"])).code!==0)console.error("[xtrn submit] GitHub CLI is not authenticated."),console.error(""),console.error("Run:"),console.error(" gh auth login"),process.exit(1)}function mt(o){if(!u.existsSync(p.join(o,"index.ts")))console.error("[xtrn submit] No index.ts found in current directory."),console.error("Run this command from your XTRN server project root."),process.exit(1);if(!u.existsSync(p.join(o,"package.json")))console.error("[xtrn submit] No package.json found in current directory."),console.error("Run this command from your XTRN server project root."),process.exit(1)}async function ft(o){let t=p.join(o,"package.json"),n=JSON.parse(u.readFileSync(t,"utf-8")),e=n.version;if(typeof e!=="string"||!e)throw Error("package.json missing 'version' field");let r=n.name;if(!r)throw Error("package.json missing 'name' field");let i=r.replace(/^@xtrn\//,""),l=`-v${e}`,a=i.endsWith(l)?i.slice(0,-l.length):i;if(!a)throw Error(`Could not parse server name from package name: ${r}`);let m=p.resolve(o,"index.ts"),c=S();try{console.log("[xtrn submit] Validating bundle..."),await P(m,c),console.log("[xtrn submit] Bundle validated successfully.")}finally{v(c)}return console.log(`[xtrn submit] Detected: ${a} v${e}`),{name:a,version:e}}async function U(o,t){await z(t,{recursive:!0});let n=await it(o,{withFileTypes:!0});for(let e of n){if(ct.has(e.name))continue;let r=p.join(o,e.name),i=p.join(t,e.name);if(e.isDirectory())await U(r,i);else await V(r,i)}}function dt(o){let t=JSON.parse(o),n=(e)=>{if(!e||typeof e!=="object")return;let r={};for(let[i,l]of Object.entries(e))if(typeof l==="string"&&(l.startsWith("file:")||l.startsWith("link:")||l.startsWith("workspace:")))r[i]="^1.0.0";else r[i]=l;return r};if(t.dependencies)t.dependencies=n(t.dependencies);if(t.devDependencies)t.devDependencies=n(t.devDependencies);return`${JSON.stringify(t,null,"\t")}
39
+ `}async function gt(o,t){console.log("[xtrn submit] Preparing files..."),await U(o,t);let n=p.join(t,"package.json");if(u.existsSync(n)){let e=await st(n,"utf-8"),r=dt(e);await at(n,r,"utf-8"),console.log("[xtrn submit] Rewrote package.json (local deps → ^1.0.0)")}}async function ut(o,t,n){let e=u.mkdtempSync(p.join(A.tmpdir(),"xtrn-submit-"));try{console.log(`[xtrn submit] Forking ${N}...`);let r=await $("gh",["repo","fork",N,"--clone=true","--default-branch-only"],{cwd:e});if(r.code!==0&&!r.stderr.includes("already exists"))throw Error(`Fork failed: ${r.stderr}`);let l=u.readdirSync(e).find((C)=>u.statSync(p.join(e,C)).isDirectory()&&u.existsSync(p.join(e,C,".git")));if(!l)throw Error(`No cloned repo found in ${e}. Output: ${r.stdout} ${r.stderr}`);let a=p.join(e,l),m=`submit/${o}/v${t}`;console.log(`[xtrn submit] Creating branch ${m}...`);let c=await $("git",["checkout","-b",m],{cwd:a});if(c.code!==0)throw Error(`Branch creation failed: ${c.stderr}`);let f=p.join(a,"servers",o,`v${t}`);await z(f,{recursive:!0}),await V(n,f,{recursive:!0}),console.log("[xtrn submit] Committing...");let h=await $("git",["add","."],{cwd:a});if(h.code!==0)throw Error(`git add failed: ${h.stderr}`);let b=await $("git",["commit","-m",`Add ${o} v${t}`],{cwd:a});if(b.code!==0)throw Error(`git commit failed: ${b.stderr}`);console.log("[xtrn submit] Pushing...");let x=await $("git",["push","--force","origin",m],{cwd:a});if(x.code!==0)throw Error(`git push failed: ${x.stderr}`);let M=(await $("git",["remote","get-url","origin"],{cwd:a})).stdout.match(/[:/]([^/]+)\/[^/]+?(?:\.git)?$/),J=M?`${M[1]}:${m}`:m;console.log("[xtrn submit] Creating pull request...");let T=await $("gh",["pr","create","--repo",N,"--head",J,"--title",`Add ${o} v${t}`,"--body",`Automated submission via \`xtrn submit\` CLI.
40
40
 
41
- **Server:** ${s}
42
- **Version:** v${n}`],{cwd:r});if(j.code!==0)throw Error(`PR creation failed: ${j.stderr}`);return j.stdout}finally{y.rmSync(t,{recursive:!0,force:!0})}}async function L(s){let n=process.cwd();await xn(),gn(n);let{name:o,version:t}=await un(n),r=y.mkdtempSync(v.join(M.tmpdir(),"xtrn-prepared-"));try{await vn(n,r);let i=await yn(o,t,r);console.log(""),console.log("✓ Pull request created!"),console.log(` ${i}`),console.log(""),console.log("Your server will be reviewed and deployed automatically once merged.")}finally{y.rmSync(r,{recursive:!0,force:!0})}}var Q="1.0.0",h=`
43
- xtrn v${Q} — XTRN server development toolkit
41
+ **Server:** ${o}
42
+ **Version:** v${t}`],{cwd:a});if(T.code!==0)throw Error(`PR creation failed: ${T.stderr}`);return T.stdout}finally{u.rmSync(e,{recursive:!0,force:!0})}}async function G(o){let t=process.cwd();await lt(),mt(t);let{name:n,version:e}=await ft(t),r=u.mkdtempSync(p.join(A.tmpdir(),"xtrn-prepared-"));try{await gt(t,r);let i=await ut(n,e,r);console.log(""),console.log("✓ Pull request created!"),console.log(` ${i}`),console.log(""),console.log("Your server will be reviewed and deployed automatically once merged.")}finally{u.rmSync(r,{recursive:!0,force:!0})}}var H="1.0.0",E=`
43
+ xtrn v${H} — XTRN server development toolkit
44
44
 
45
45
  Usage:
46
46
  xtrn new <name> <version> Scaffold a new XTRN server project
@@ -63,4 +63,4 @@ Examples:
63
63
  xtrn dev ./server.ts Start dev server with custom entry
64
64
  xtrn dev --port=3000 Start dev server on port 3000
65
65
  xtrn submit Fork xtrn-servers and open PR
66
- `.trim();async function wn(){let s=process.argv.slice(2),n=s[0];if(!n||n==="--help"||n==="-h")console.log(h),process.exit(0);if(n==="--version"||n==="-v")console.log(`xtrn v${Q}`),process.exit(0);if(n==="new"){let o=s.slice(1);if(o.includes("--help")||o.includes("-h"))console.log(h),process.exit(0);await H(o);return}if(n==="dev"){let o=s.slice(1);if(o.includes("--help")||o.includes("-h"))console.log(h),process.exit(0);await I(o);return}if(n==="submit"){let o=s.slice(1);if(o.includes("--help")||o.includes("-h"))console.log(h),process.exit(0);await L(o);return}console.error(`Unknown command: ${n}`),console.error('Run "xtrn --help" for usage.'),process.exit(1)}wn().catch((s)=>{console.error("[xtrn] Fatal:",s),process.exit(1)});
66
+ `.trim();async function pt(){let o=process.argv.slice(2),t=o[0];if(!t||t==="--help"||t==="-h")console.log(E),process.exit(0);if(t==="--version"||t==="-v")console.log(`xtrn v${H}`),process.exit(0);if(t==="new"){let n=o.slice(1);if(n.includes("--help")||n.includes("-h"))console.log(E),process.exit(0);await F(n);return}if(t==="dev"){let n=o.slice(1);if(n.includes("--help")||n.includes("-h"))console.log(E),process.exit(0);await W(n);return}if(t==="submit"){let n=o.slice(1);if(n.includes("--help")||n.includes("-h"))console.log(E),process.exit(0);await G(n);return}console.error(`Unknown command: ${t}`),console.error('Run "xtrn --help" for usage.'),process.exit(1)}pt().catch((o)=>{console.error("[xtrn] Fatal:",o),process.exit(1)});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xtrn/cli",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "xtrn": "./dist/cli.js"
@@ -3,7 +3,7 @@ import { z } from "zod";
3
3
 
4
4
  const server = new XTRNServer({
5
5
  name: "{{NAME}}",
6
- version: "{{VERSION}}",
6
+ version: "{{VERSION_BARE}}",
7
7
  config: defineConfig({}),
8
8
  });
9
9