@hyperez/regna-code 0.1.6 → 0.1.7
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 +2 -1
- package/dist/bin/regna.mjs +9 -8
- package/dist/extensions/context.js +1 -0
- package/dist/extensions/exit.js +1 -1
- package/dist/postinstall.mjs +47 -23
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -62,7 +62,8 @@ 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
|
|
65
|
+
| `/exit` | Exit Regna Code from inside a session. |
|
|
66
|
+
| `/compact` | Compact the session context (also runs automatically as it fills). |
|
|
66
67
|
| `/regna-coder` | Switch to a coding model (prefers an id containing `coder`, else default). |
|
|
67
68
|
| `/regna-general` | Switch to a general model (prefers `instruct`, else default). |
|
|
68
69
|
| `/regna-brand` | Toggle the Regna Code header/title branding. |
|
package/dist/bin/regna.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{spawn as v}from"node:child_process";import{fileURLToPath as P}from"node:url";import{dirname as
|
|
2
|
+
import{spawn as v}from"node:child_process";import{fileURLToPath as P}from"node:url";import{dirname as f,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 $=f(P(import.meta.url)),c=f($),g=o(c,"extensions"),_=o(c,"themes","regna.json"),m=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,7 +15,8 @@ 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
|
|
18
|
+
/exit exit Regna Code
|
|
19
|
+
/compact compact the session context
|
|
19
20
|
|
|
20
21
|
Environment:
|
|
21
22
|
REGNA_API_KEY Regna API key (optional once logged in)
|
|
@@ -25,15 +26,15 @@ Environment:
|
|
|
25
26
|
|
|
26
27
|
Docs: https://github.com/HyperEZ/regna-code
|
|
27
28
|
`;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
|
|
29
|
+
`);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 F(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 K(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
30
|
Regna Code ${E()}
|
|
30
31
|
Log in to continue.
|
|
31
32
|
|
|
32
33
|
1) Get an API key at ${t}
|
|
33
34
|
2) Paste it below.
|
|
34
35
|
|
|
35
|
-
`),
|
|
36
|
-
`),process.exit(1));let r=await
|
|
36
|
+
`),F(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.
|
|
37
|
+
`),process.exit(1));let r=await K(e,s);return r==="invalid"&&(process.stderr.write(` That key was rejected. Check it and run: regna login
|
|
37
38
|
`),process.exit(1)),B(s,e),process.stdout.write(r==="ok"?` Logged in.
|
|
38
39
|
|
|
39
40
|
`:` Saved (could not verify right now).
|
|
@@ -42,9 +43,9 @@ Docs: https://github.com/HyperEZ/regna-code
|
|
|
42
43
|
`),process.exit(0));a[0]==="login"&&(await S(),process.exit(0));a[0]==="logout"&&(process.stdout.write(O()?`Logged out.
|
|
43
44
|
`:`Not logged in.
|
|
44
45
|
`),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=[],
|
|
46
|
-
`),process.exit(1));for(let[,r]of n)i.push("-e",r)}!u("--theme")&&p(_)&&i.push("--theme",_);u("--system-prompt")||(p(
|
|
46
|
+
`),process.exit(1);process.env.REGNA_API_KEY=l;var i=[],Y=process.env.REGNA_DISCOVER==="1";if(!Y){i.push("--no-extensions");let e=["provider","policy","branding","model","context","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.
|
|
47
|
+
`),process.exit(1));for(let[,r]of n)i.push("-e",r)}!u("--theme")&&p(_)&&i.push("--theme",_);u("--system-prompt")||(p(m)||(process.stderr.write(`[regna] Missing required prompt: APPEND_SYSTEM.md (${m}). Install is corrupted. Aborting.
|
|
47
48
|
(To set the prompt yourself on purpose, run with --system-prompt.)
|
|
48
|
-
`),process.exit(1)),i.push("--append-system-prompt",`@${
|
|
49
|
+
`),process.exit(1)),i.push("--append-system-prompt",`@${m}`));u("--model","-m")||i.push("--model",process.env.REGNA_MODEL||D);i.push(...a);try{N(x,{recursive:!0})}catch{}var q={...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=f(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:q});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.
|
|
49
50
|
`),process.exit(127)),process.stderr.write(`[regna] Failed to start the runtime: ${e?.message??String(e)}
|
|
50
51
|
`),process.exit(1)});b.on("exit",(e,t)=>{if(t){process.kill(process.pid,t);return}process.exit(e??0)});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var o="regna-context";var a="\u25B0",E="\u25B1",d="\x1B[32m",m="\x1B[33m",L="\x1B[31m",p="\x1B[90m",s="\x1B[39m";function f(n){let t=Math.max(0,Math.min(100,n)),e=Math.max(0,Math.min(10,Math.round(t/100*10))),r=t>90?L:t>70?m:d,u=e>0?`${r}${a.repeat(e)}${s}`:"",c=e<10?`${p}${E.repeat(10-e)}${s}`:"";return`${u}${c} ${t.toFixed(0)}%`}function i(n){if(n.mode!=="tui")return;let t=n.getContextUsage();if(!t||t.percent===null||t.percent===void 0){n.ui.setStatus(o,void 0);return}n.ui.setStatus(o,f(t.percent))}function l(n){n.on("session_start",async(t,e)=>i(e)),n.on("turn_end",async(t,e)=>i(e))}export{f as buildBar,l as default};
|
package/dist/extensions/exit.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function o(e){e.registerCommand("exit",{description:"Exit Regna Code",handler:async(i,n)=>{n.shutdown()}})}export{o as default};
|
package/dist/postinstall.mjs
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* Postinstall: brand
|
|
3
|
+
* Postinstall: small, surgical brand patches to the installed engine.
|
|
4
4
|
*
|
|
5
|
-
* The
|
|
6
|
-
*
|
|
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.
|
|
5
|
+
* The engine ships compiled JS whose constants/built-ins we cannot override at runtime via
|
|
6
|
+
* the extension API. We rewrite a few exact spots in the installed dependency:
|
|
9
7
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
8
|
+
* 1) Terminal title. The engine composes the title as `${APP_TITLE} - <cwd>` and re-asserts
|
|
9
|
+
* it on every turn/cwd change, so an extension setTitle cannot win. We rewrite ONLY the
|
|
10
|
+
* `APP_TITLE = piConfigName ? APP_NAME : "<x>"` fallback string to "Regna". APP_NAME, the
|
|
11
|
+
* config dir name, and the agent-dir env var are untouched, so the launcher's state
|
|
12
|
+
* isolation (PI_CODING_AGENT_DIR) keeps working regardless.
|
|
14
13
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
14
|
+
* 2) Remove the built-in /quit command. Regna Code exposes /exit instead. We drop the "quit"
|
|
15
|
+
* entry from the built-in slash-command menu and neutralize its handler so /quit no longer
|
|
16
|
+
* triggers shutdown (Ctrl+C/Ctrl+D still exit).
|
|
17
|
+
*
|
|
18
|
+
* Best effort: every patch is wrapped so a failure (e.g. the engine changed its layout) just
|
|
19
|
+
* leaves that aspect at the engine default and never fails the install. All patches are
|
|
20
|
+
* idempotent and safe to run on every install.
|
|
18
21
|
*/
|
|
19
22
|
|
|
20
23
|
import { readFileSync, writeFileSync, existsSync } from "node:fs";
|
|
@@ -39,16 +42,37 @@ function findEngineFile(relInsidePackage) {
|
|
|
39
42
|
return null;
|
|
40
43
|
}
|
|
41
44
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const out = src.replace(re,
|
|
50
|
-
if (out !== src) writeFileSync(
|
|
45
|
+
/** Apply one regex replacement to an engine file. No-op if the file or pattern is missing. */
|
|
46
|
+
function patchEngineFile(relInsidePackage, re, replacement) {
|
|
47
|
+
try {
|
|
48
|
+
const path = findEngineFile(relInsidePackage);
|
|
49
|
+
if (!path) return;
|
|
50
|
+
const src = readFileSync(path, "utf8");
|
|
51
|
+
if (!re.test(src)) return; // already patched or layout changed
|
|
52
|
+
const out = src.replace(re, replacement);
|
|
53
|
+
if (out !== src) writeFileSync(path, out);
|
|
54
|
+
} catch {
|
|
55
|
+
/* best effort; never fail the install */
|
|
51
56
|
}
|
|
52
|
-
} catch {
|
|
53
|
-
/* cosmetic only; never fail the install */
|
|
54
57
|
}
|
|
58
|
+
|
|
59
|
+
// 1) Terminal title fallback -> "Regna".
|
|
60
|
+
patchEngineFile(
|
|
61
|
+
join("dist", "config.js"),
|
|
62
|
+
/(APP_TITLE\s*=\s*piConfigName\s*\?\s*APP_NAME\s*:\s*)"[^"]*"/,
|
|
63
|
+
`$1"${TITLE}"`,
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
// 2a) Drop the built-in "quit" entry from the slash-command menu.
|
|
67
|
+
patchEngineFile(
|
|
68
|
+
join("dist", "core", "slash-commands.js"),
|
|
69
|
+
/\{\s*name:\s*"quit",\s*description:\s*`[^`]*`\s*\},?\n?/,
|
|
70
|
+
"",
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
// 2b) Neutralize the /quit handler so it no longer matches (Ctrl+C/Ctrl+D still exit).
|
|
74
|
+
patchEngineFile(
|
|
75
|
+
join("dist", "modes", "interactive", "interactive-mode.js"),
|
|
76
|
+
/if\s*\(\s*text\s*===\s*"\/quit"\s*\)/,
|
|
77
|
+
'if (text === "/__regna_quit_removed__")',
|
|
78
|
+
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperez/regna-code",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
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,
|