@hyperez/regna-code 0.1.4 → 0.1.6

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/README.md CHANGED
@@ -62,6 +62,7 @@ For CI or scripted use, set `REGNA_API_KEY` directly; it takes priority over the
62
62
  |---|---|
63
63
  | `regna login` | Log in to Regna and store your API key at `~/.regna/auth.json`. |
64
64
  | `regna logout` | Remove stored credentials. |
65
+ | `/exit` | Exit Regna Code from inside a session (same as `/quit`). |
65
66
  | `/regna-coder` | Switch to a coding model (prefers an id containing `coder`, else default). |
66
67
  | `/regna-general` | Switch to a general model (prefers `instruct`, else default). |
67
68
  | `/regna-brand` | Toggle the Regna Code header/title branding. |
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import{spawn as w}from"node:child_process";import{fileURLToPath as P}from"node:url";import{dirname as E,join as o}from"node:path";import{existsSync as l,readFileSync as A,writeFileSync as k,mkdirSync as N,unlinkSync as I,chmodSync as G}from"node:fs";import{homedir as L}from"node:os";import{createRequire as U}from"node:module";import{createInterface as $}from"node:readline/promises";var D=E(P(import.meta.url)),u=E(D),f=o(u,"extensions"),_=o(u,"themes","regna.json"),h=o(u,"APPEND_SYSTEM.md"),T="https://regnax.ai/v1",C="regna/regna-pro",R=o(L(),".regna"),m=o(R,"auth.json"),x=o(R,"engine"),a=process.argv.slice(2),g=(...e)=>a.some(r=>e.some(n=>!!(r===n||r.startsWith(`${n}=`)||/^-[a-z]$/i.test(n)&&r.startsWith(n)&&r.length>n.length)));function y(){for(let e of[o(u,"package.json"),o(u,"..","package.json")])try{let r=JSON.parse(A(e,"utf8")).version;if(r)return`v${r}`}catch{}return""}var O=`Regna Code ${y()} - a terminal coding agent on Regna
2
+ import{spawn as v}from"node:child_process";import{fileURLToPath as P}from"node:url";import{dirname as m,join as o}from"node:path";import{existsSync as p,readFileSync as w,writeFileSync as I,mkdirSync as N,unlinkSync as G,chmodSync as L}from"node:fs";import{homedir as k}from"node:os";import{createInterface as U}from"node:readline/promises";var $=m(P(import.meta.url)),c=m($),g=o(c,"extensions"),_=o(c,"themes","regna.json"),f=o(c,"APPEND_SYSTEM.md"),T="https://regnax.ai/v1",D="regna/regna-pro",h=o(k(),".regna"),d=o(h,"auth.json"),x=o(h,"engine"),a=process.argv.slice(2),u=(...e)=>a.some(t=>e.some(n=>!!(t===n||t.startsWith(`${n}=`)||/^-[a-z]$/i.test(n)&&t.startsWith(n)&&t.length>n.length)));function E(){for(let e of[o(c,"package.json"),o(c,"..","package.json")])try{let t=JSON.parse(w(e,"utf8")).version;if(t)return`v${t}`}catch{}return""}var C=`Regna Code ${E()} - a terminal coding agent on Regna
3
3
 
4
4
  Usage:
5
5
  regna [message...] start interactive, optionally with a first message
@@ -15,6 +15,7 @@ In-session commands:
15
15
  /regna-general switch to a general model
16
16
  /regna-brand toggle the Regna Code branding
17
17
  /regna-docs <q> document-grounded query (requires REGNA_DOCS_ENABLED=1)
18
+ /exit exit Regna Code (same as /quit)
18
19
 
19
20
  Environment:
20
21
  REGNA_API_KEY Regna API key (optional once logged in)
@@ -23,27 +24,27 @@ Environment:
23
24
  REGNA_POLICY network egress guard: off | warn | enforce
24
25
 
25
26
  Docs: https://github.com/HyperEZ/regna-code
26
- `;function v(){try{let e=JSON.parse(A(m,"utf8"));return e&&typeof e.apiKey=="string"?e:null}catch{return null}}function B(e,r){N(R,{recursive:!0}),k(m,`${JSON.stringify({apiKey:e,baseUrl:r},null,2)}
27
- `);try{G(m,384)}catch{}}function j(){try{return I(m),!0}catch{return!1}}function q(e){try{return`${new URL(e).origin}/console`}catch{return"https://regnax.ai/console"}}function F(e){try{let[r,n]=process.platform==="darwin"?["open",[e]]:process.platform==="win32"?["cmd",["/c","start","",e]]:["xdg-open",[e]];w(r,n,{stdio:"ignore",detached:!0}).unref()}catch{}}async function K(e,r){try{let n=new AbortController,s=setTimeout(()=>n.abort(),8e3),t=await fetch(`${e.replace(/\/+$/,"")}/models`,{headers:{Authorization:`Bearer ${r}`},signal:n.signal});return clearTimeout(s),t.status===401||t.status===403?"invalid":t.ok?"ok":"unknown"}catch{return"unknown"}}async function b(){let e=(process.env.REGNA_BASE_URL||"").trim()||v()?.baseUrl||T,r=q(e);process.stdout.write(`
28
- Regna Code ${y()}
27
+ `;function A(){try{let e=JSON.parse(w(d,"utf8"));return e&&typeof e.apiKey=="string"?e:null}catch{return null}}function B(e,t){N(h,{recursive:!0}),I(d,`${JSON.stringify({apiKey:e,baseUrl:t},null,2)}
28
+ `);try{L(d,384)}catch{}}function O(){try{return G(d),!0}catch{return!1}}function j(e){try{return`${new URL(e).origin}/console`}catch{return"https://regnax.ai/console"}}function q(e){try{let[t,n]=process.platform==="darwin"?["open",[e]]:process.platform==="win32"?["cmd",["/c","start","",e]]:["xdg-open",[e]];v(t,n,{stdio:"ignore",detached:!0}).unref()}catch{}}async function F(e,t){try{let n=new AbortController,s=setTimeout(()=>n.abort(),8e3),r=await fetch(`${e.replace(/\/+$/,"")}/models`,{headers:{Authorization:`Bearer ${t}`},signal:n.signal});return clearTimeout(s),r.status===401||r.status===403?"invalid":r.ok?"ok":"unknown"}catch{return"unknown"}}async function S(){let e=(process.env.REGNA_BASE_URL||"").trim()||A()?.baseUrl||T,t=j(e);process.stdout.write(`
29
+ Regna Code ${E()}
29
30
  Log in to continue.
30
31
 
31
- 1) Get an API key at ${r}
32
+ 1) Get an API key at ${t}
32
33
  2) Paste it below.
33
34
 
34
- `),F(r);let n=$({input:process.stdin,output:process.stdout}),s="";try{s=(await n.question(" API key: ")).trim()}finally{n.close()}s||(process.stderr.write(` No key entered. Aborting.
35
- `),process.exit(1));let t=await K(e,s);return t==="invalid"&&(process.stderr.write(` That key was rejected. Check it and run: regna login
36
- `),process.exit(1)),B(s,e),process.stdout.write(t==="ok"?` Logged in.
35
+ `),q(t);let n=U({input:process.stdin,output:process.stdout}),s="";try{s=(await n.question(" API key: ")).trim()}finally{n.close()}s||(process.stderr.write(` No key entered. Aborting.
36
+ `),process.exit(1));let r=await F(e,s);return r==="invalid"&&(process.stderr.write(` That key was rejected. Check it and run: regna login
37
+ `),process.exit(1)),B(s,e),process.stdout.write(r==="ok"?` Logged in.
37
38
 
38
39
  `:` Saved (could not verify right now).
39
40
 
40
- `),s}(g("--help","-h")||a[0]==="help")&&(process.stdout.write(O),process.exit(0));(g("--version")||a[0]==="version")&&(process.stdout.write(`Regna Code ${y()}
41
- `),process.exit(0));a[0]==="login"&&(await b(),process.exit(0));a[0]==="logout"&&(process.stdout.write(j()?`Logged out.
41
+ `),s}(u("--help","-h")||a[0]==="help")&&(process.stdout.write(C),process.exit(0));(u("--version")||a[0]==="version")&&(process.stdout.write(`Regna Code ${E()}
42
+ `),process.exit(0));a[0]==="login"&&(await S(),process.exit(0));a[0]==="logout"&&(process.stdout.write(O()?`Logged out.
42
43
  `:`Not logged in.
43
- `),process.exit(0));var d=(process.env.REGNA_API_KEY||"").trim();if(!d){let e=v();e?.apiKey&&(d=e.apiKey.trim(),!process.env.REGNA_BASE_URL&&e.baseUrl&&(process.env.REGNA_BASE_URL=e.baseUrl))}if(!d)if(process.stdin.isTTY&&process.stdout.isTTY){if(d=await b(),!process.env.REGNA_BASE_URL){let e=v();e?.baseUrl&&(process.env.REGNA_BASE_URL=e.baseUrl)}}else process.stderr.write(`[regna] Not logged in. Run: regna login
44
- `),process.exit(1);process.env.REGNA_API_KEY=d;var i=[],Y=process.env.REGNA_DISCOVER==="1";if(!Y){i.push("--no-extensions");let e=["provider","policy","branding","model","docs-search","docs-analysis"],r=t=>{let p=o(f,`${t}.js`);if(l(p))return p;let c=o(f,`${t}.ts`);return l(c)?c:null},n=e.map(t=>[t,r(t)]),s=n.filter(([,t])=>!t).map(([t])=>t);s.length>0&&(process.stderr.write(`[regna] Missing required extensions: ${s.join(", ")} (in ${f}). Install is corrupted. Aborting.
45
- `),process.exit(1));for(let[,t]of n)i.push("-e",t)}!g("--theme")&&l(_)&&i.push("--theme",_);g("--system-prompt")||(l(h)||(process.stderr.write(`[regna] Missing required prompt: APPEND_SYSTEM.md (${h}). Install is corrupted. Aborting.
44
+ `),process.exit(0));var l=(process.env.REGNA_API_KEY||"").trim();if(!l){let e=A();e?.apiKey&&(l=e.apiKey.trim(),!process.env.REGNA_BASE_URL&&e.baseUrl&&(process.env.REGNA_BASE_URL=e.baseUrl))}if(!l)if(process.stdin.isTTY&&process.stdout.isTTY){if(l=await S(),!process.env.REGNA_BASE_URL){let e=A();e?.baseUrl&&(process.env.REGNA_BASE_URL=e.baseUrl)}}else process.stderr.write(`[regna] Not logged in. Run: regna login
45
+ `),process.exit(1);process.env.REGNA_API_KEY=l;var i=[],K=process.env.REGNA_DISCOVER==="1";if(!K){i.push("--no-extensions");let e=["provider","policy","branding","model","exit","docs-search","docs-analysis"],t=r=>{let R=o(g,`${r}.js`);if(p(R))return R;let y=o(g,`${r}.ts`);return p(y)?y:null},n=e.map(r=>[r,t(r)]),s=n.filter(([,r])=>!r).map(([r])=>r);s.length>0&&(process.stderr.write(`[regna] Missing required extensions: ${s.join(", ")} (in ${g}). Install is corrupted. Aborting.
46
+ `),process.exit(1));for(let[,r]of n)i.push("-e",r)}!u("--theme")&&p(_)&&i.push("--theme",_);u("--system-prompt")||(p(f)||(process.stderr.write(`[regna] Missing required prompt: APPEND_SYSTEM.md (${f}). Install is corrupted. Aborting.
46
47
  (To set the prompt yourself on purpose, run with --system-prompt.)
47
- `),process.exit(1)),i.push("--append-system-prompt",`@${h}`));g("--model","-m")||i.push("--model",process.env.REGNA_MODEL||C);i.push(...a);try{N(x,{recursive:!0})}catch{}var M={...process.env,PI_OFFLINE:"1",PI_CODING_AGENT_DIR:x};function H(){let e=process.env.REGNA_ENGINE;if(e)return{cmd:e,prefix:[],label:e};try{let n=U(import.meta.url).resolve("@earendil-works/pi-coding-agent/package.json"),s=E(n),t=JSON.parse(A(n,"utf8")),p=typeof t.bin=="string"?t.bin:t.bin?.pi;if(p){let c=o(s,p);if(l(c))return{cmd:process.execPath,prefix:[c],label:c}}}catch{}return{cmd:"pi",prefix:[],label:"runtime (PATH)"}}var{cmd:z,prefix:J,label:V}=H(),S=w(z,[...J,...i],{stdio:"inherit",env:M});S.on("error",e=>{e&&e.code==="ENOENT"&&(process.stderr.write(`[regna] Runtime executable not found (${V}). Reinstall (npm i -g @hyperez/regna-code) or set REGNA_ENGINE.
48
+ `),process.exit(1)),i.push("--append-system-prompt",`@${f}`));u("--model","-m")||i.push("--model",process.env.REGNA_MODEL||D);i.push(...a);try{N(x,{recursive:!0})}catch{}var Y={...process.env,PI_OFFLINE:"1",PI_CODING_AGENT_DIR:x};function M(){let e=o("node_modules","@earendil-works","pi-coding-agent","dist","cli.js"),t=c;for(let n=0;n<10;n++){let s=o(t,e);if(p(s))return s;let r=m(t);if(r===t)break;t=r}return null}function H(){let e=process.env.REGNA_ENGINE;if(e)return{cmd:e,prefix:[],label:e};let t=M();return t?{cmd:process.execPath,prefix:[t],label:t}:{cmd:"pi",prefix:[],label:"runtime (PATH)"}}var{cmd:z,prefix:J,label:V}=H(),b=v(z,[...J,...i],{stdio:"inherit",env:Y});b.on("error",e=>{e&&e.code==="ENOENT"&&(process.stderr.write(`[regna] Runtime executable not found (${V}). Reinstall (npm i -g @hyperez/regna-code) or set REGNA_ENGINE.
48
49
  `),process.exit(127)),process.stderr.write(`[regna] Failed to start the runtime: ${e?.message??String(e)}
49
- `),process.exit(1)});S.on("exit",(e,r)=>{if(r){process.kill(process.pid,r);return}process.exit(e??0)});
50
+ `),process.exit(1)});b.on("exit",(e,t)=>{if(t){process.kill(process.pid,t);return}process.exit(e??0)});
@@ -0,0 +1 @@
1
+ function t(e){e.registerCommand("exit",{description:"Exit Regna Code (same as /quit)",handler:async(i,n)=>{n.shutdown()}})}export{t as default};
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Postinstall: brand the terminal/tab title as "Regna".
4
+ *
5
+ * The runtime composes the terminal title as `${APP_TITLE} - <cwd>` and re-asserts it on
6
+ * every turn/cwd change, so a one-time setTitle from an extension cannot win the race.
7
+ * APP_TITLE is a compiled constant whose fallback is the engine's own mark. We surgically
8
+ * rewrite ONLY that fallback string to "Regna" in the installed dependency.
9
+ *
10
+ * Scope is deliberately narrow:
11
+ * - Only the `APP_TITLE = piConfigName ? APP_NAME : "<x>"` literal is touched.
12
+ * - APP_NAME, the config dir name, and the agent-dir env var are left untouched, so the
13
+ * launcher's state isolation (PI_CODING_AGENT_DIR) keeps working regardless.
14
+ *
15
+ * Best effort: any failure is swallowed and the install still succeeds. If the patch does
16
+ * not apply (e.g. the engine changed its layout), the only effect is the title stays as the
17
+ * engine default. This is idempotent and safe to run on every install.
18
+ */
19
+
20
+ import { readFileSync, writeFileSync, existsSync } from "node:fs";
21
+ import { dirname, join } from "node:path";
22
+ import { fileURLToPath } from "node:url";
23
+
24
+ const TITLE = "Regna";
25
+
26
+ // The engine's package.json "exports" map blocks require.resolve of its package.json/main,
27
+ // so we locate the installed file by walking up node_modules from this script's location.
28
+ // Handles both nested (under our package) and hoisted installs, dev and global.
29
+ function findEngineFile(relInsidePackage) {
30
+ const rel = join("node_modules", "@earendil-works", "pi-coding-agent", relInsidePackage);
31
+ let dir = dirname(fileURLToPath(import.meta.url));
32
+ for (let i = 0; i < 10; i++) {
33
+ const cand = join(dir, rel);
34
+ if (existsSync(cand)) return cand;
35
+ const parent = dirname(dir);
36
+ if (parent === dir) break;
37
+ dir = parent;
38
+ }
39
+ return null;
40
+ }
41
+
42
+ try {
43
+ const configPath = findEngineFile(join("dist", "config.js"));
44
+ if (!configPath) throw new Error("engine config.js not found");
45
+ const src = readFileSync(configPath, "utf8");
46
+ // Match: APP_TITLE = piConfigName ? APP_NAME : "<anything>"
47
+ const re = /(APP_TITLE\s*=\s*piConfigName\s*\?\s*APP_NAME\s*:\s*)"[^"]*"/;
48
+ if (re.test(src)) {
49
+ const out = src.replace(re, `$1"${TITLE}"`);
50
+ if (out !== src) writeFileSync(configPath, out);
51
+ }
52
+ } catch {
53
+ /* cosmetic only; never fail the install */
54
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperez/regna-code",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Regna Code. A terminal coding agent on Regna. Install with `npm i -g @hyperez/regna-code` and run `regna`. Works with the Regna cloud API and on-premise deployments.",
5
5
  "license": "PolyForm-Noncommercial-1.0.0",
6
6
  "private": false,
@@ -23,6 +23,9 @@
23
23
  "bin": {
24
24
  "regna": "dist/bin/regna.mjs"
25
25
  },
26
+ "scripts": {
27
+ "postinstall": "node dist/postinstall.mjs"
28
+ },
26
29
  "files": [
27
30
  "dist",
28
31
  "README.md",