@hanamorilabs/tab 0.1.1 → 0.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/README.md +17 -0
- package/dist/alias.js +79 -0
- package/dist/cli.js +50 -0
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -59,6 +59,8 @@ Codex shows `FlockTab - Self-hosted` as its provider.
|
|
|
59
59
|
tab login approve this machine in the console, once
|
|
60
60
|
tab <agent> [args] claude, codex, grok, kimi, gemini, or any command, on the tab
|
|
61
61
|
tab use pick or change the Agent this folder runs as (.flocktab)
|
|
62
|
+
tab alias <name>... make plain `codex` run `tab codex` (shims in ~/.flocktab/bin)
|
|
63
|
+
tab unalias <name> remove such a shim
|
|
62
64
|
tab status flock, folder Agent, proxy health, provider key state
|
|
63
65
|
tab version tab and proxy versions
|
|
64
66
|
tab up | down self-hosted: start or stop the local proxy
|
|
@@ -67,6 +69,21 @@ tab logout forget the session and keys on this machine
|
|
|
67
69
|
tab help this list
|
|
68
70
|
```
|
|
69
71
|
|
|
72
|
+
## Aliases: plain `codex` on the tab
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
tab alias codex claude
|
|
76
|
+
export PATH="$HOME/.flocktab/bin:$PATH" # once, in your shell rc
|
|
77
|
+
codex # now runs: tab codex
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
`tab alias` writes a shim named after the command into `~/.flocktab/bin`
|
|
81
|
+
(`codex.cmd` on Windows). With that folder first on `PATH`, the plain
|
|
82
|
+
command runs on the tab. When `tab` spawns the real agent it removes its
|
|
83
|
+
own shim folder from the child's `PATH`, so nothing loops. `tab alias` with
|
|
84
|
+
no name lists them; `tab unalias codex` removes one. Prefer a shell alias?
|
|
85
|
+
`alias codex='tab codex'` in your rc does the same for that shell only.
|
|
86
|
+
|
|
70
87
|
## Secrets and colour
|
|
71
88
|
|
|
72
89
|
The unlock and provider keys are typed with echo off (raw mode); the unlock is checked against the proxy before saving; a wrong unlock is refused, and `tab status` says `unlock ok` or `unlock is WRONG`. The check is `GET /v1/whoami` with the unlock, which decrypts the envelope in memory and answers `ok`/`wrong`, never the key. Output is coloured on a terminal; `NO_COLOR` turns it off, `FORCE_COLOR` turns it on for pipes.
|
package/dist/alias.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `tab alias codex`: a shim named `codex` in ~/.flocktab/bin that runs
|
|
3
|
+
* `tab codex "$@"`. With that folder first on PATH, the plain command is on
|
|
4
|
+
* the tab. No shell rc is edited here: `tab alias` prints the one PATH line
|
|
5
|
+
* and the person adds it where they like.
|
|
6
|
+
*
|
|
7
|
+
* The shim shadows the real binary by name, so when `tab` spawns the agent
|
|
8
|
+
* it removes ~/.flocktab/bin from the child's PATH (`pathWithoutShims`);
|
|
9
|
+
* otherwise `codex` would resolve to the shim and loop forever.
|
|
10
|
+
*/
|
|
11
|
+
import { chmod, mkdir, readdir, rm, writeFile } from "node:fs/promises";
|
|
12
|
+
import path from "node:path";
|
|
13
|
+
import { configDir } from "./config.js";
|
|
14
|
+
export function shimDir(env = process.env) {
|
|
15
|
+
return path.join(configDir(env), "bin");
|
|
16
|
+
}
|
|
17
|
+
const NAME = /^[a-z0-9][a-z0-9._-]{0,63}$/i;
|
|
18
|
+
export function validAliasName(name) {
|
|
19
|
+
return NAME.test(name) && !["tab", "flocktab-proxy"].includes(name.toLowerCase());
|
|
20
|
+
}
|
|
21
|
+
function shimBody(name, platform = process.platform) {
|
|
22
|
+
if (platform === "win32") {
|
|
23
|
+
return { file: `${name}.cmd`, body: `@echo off\r\ntab ${name} %*\r\n` };
|
|
24
|
+
}
|
|
25
|
+
return { file: name, body: `#!/bin/sh\nexec tab ${name} "$@"\n` };
|
|
26
|
+
}
|
|
27
|
+
export async function writeAlias(name, env = process.env, platform = process.platform) {
|
|
28
|
+
const dir = shimDir(env);
|
|
29
|
+
await mkdir(dir, { recursive: true, mode: 0o700 });
|
|
30
|
+
const { file, body } = shimBody(name, platform);
|
|
31
|
+
const target = path.join(dir, file);
|
|
32
|
+
await writeFile(target, body, { mode: 0o755 });
|
|
33
|
+
await chmod(target, 0o755);
|
|
34
|
+
return target;
|
|
35
|
+
}
|
|
36
|
+
export async function removeAlias(name, env = process.env, platform = process.platform) {
|
|
37
|
+
const { file } = shimBody(name, platform);
|
|
38
|
+
const target = path.join(shimDir(env), file);
|
|
39
|
+
try {
|
|
40
|
+
await rm(target);
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** Alias names present in the shim folder (the proxy binary is not one). */
|
|
48
|
+
export async function listAliases(env = process.env) {
|
|
49
|
+
try {
|
|
50
|
+
return (await readdir(shimDir(env)))
|
|
51
|
+
.filter((f) => !f.startsWith("flocktab-proxy") && !f.endsWith(".part"))
|
|
52
|
+
.map((f) => f.replace(/\.cmd$/i, ""))
|
|
53
|
+
.sort();
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return [];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/** Whether the shim folder is on PATH, so an alias would actually be found. */
|
|
60
|
+
export function shimDirOnPath(env = process.env, platform = process.platform) {
|
|
61
|
+
const sep = platform === "win32" ? ";" : ":";
|
|
62
|
+
const dir = path.resolve(shimDir(env));
|
|
63
|
+
return (env.PATH ?? "").split(sep).some((p) => p && path.resolve(p) === dir);
|
|
64
|
+
}
|
|
65
|
+
/** PATH for the child agent: everything except the shim folder. */
|
|
66
|
+
export function pathWithoutShims(env = process.env, platform = process.platform) {
|
|
67
|
+
const sep = platform === "win32" ? ";" : ":";
|
|
68
|
+
const dir = path.resolve(shimDir(env));
|
|
69
|
+
return (env.PATH ?? "")
|
|
70
|
+
.split(sep)
|
|
71
|
+
.filter((p) => p && path.resolve(p) !== dir)
|
|
72
|
+
.join(sep);
|
|
73
|
+
}
|
|
74
|
+
/** The line to add to a shell rc so the shims win. */
|
|
75
|
+
export function pathLine(platform = process.platform) {
|
|
76
|
+
return platform === "win32"
|
|
77
|
+
? `setx PATH "%USERPROFILE%\\.flocktab\\bin;%PATH%"`
|
|
78
|
+
: `export PATH="$HOME/.flocktab/bin:$PATH"`;
|
|
79
|
+
}
|
package/dist/cli.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* tab codex [...args] Codex on the tab
|
|
8
8
|
* tab <cmd> [...args] anything else, both APIs pointed at the tab
|
|
9
9
|
* tab use pick (or change) the Agent this folder runs as
|
|
10
|
+
* tab alias codex ... make plain `codex` run `tab codex` (shims in ~/.flocktab/bin)
|
|
10
11
|
* tab status which flock, which Agent here, is the proxy up
|
|
11
12
|
* tab version tab and proxy versions
|
|
12
13
|
* tab up | down | update self-hosted: start, stop, or fetch the newest proxy
|
|
@@ -28,6 +29,7 @@ import { ConsoleApiError, createAgent, issueAgentKey, listAgents } from "./conso
|
|
|
28
29
|
import { consoleUrlFor, DeviceLoginError, startDeviceLogin, waitForApproval } from "./device-login.js";
|
|
29
30
|
import { clearConfig, configDir, configPath, HOSTED_PROXY, isLocalProxy, loadConfig, LOCAL_PROXY, normalizeProxyUrl, presentedKey, saveConfig, } from "./config.js";
|
|
30
31
|
import { reportFolder } from "./folder.js";
|
|
32
|
+
import { listAliases, pathLine, pathWithoutShims, removeAlias, shimDir, shimDirOnPath, validAliasName, writeAlias } from "./alias.js";
|
|
31
33
|
import { agentNameFor, projectRoot, readProject, writeProject } from "./project.js";
|
|
32
34
|
import { downloadProxy, hasProxyEnv, packagedBinPath, proxyBinPath, proxyEnvPath, proxyInstalled, proxyLogPath, PROXY_VERSION, startProxy, stopProxy, tailProxyLog, writeProxyEnv, } from "./proxy-bin.js";
|
|
33
35
|
import { proxyHealth, waitHealthy } from "./selfhost.js";
|
|
@@ -48,6 +50,8 @@ function usage() {
|
|
|
48
50
|
cmd(others.join(" | tab "), "the same, for those agents"),
|
|
49
51
|
cmd("<command> [args]", "any other agent, both APIs pointed at the tab"),
|
|
50
52
|
cmd("use", "pick or change the Agent this folder runs as (.flocktab)"),
|
|
53
|
+
cmd("alias <name>...", "make plain `codex` run `tab codex` (shims in ~/.flocktab/bin)"),
|
|
54
|
+
cmd("unalias <name>", "remove such a shim"),
|
|
51
55
|
cmd("status", "which flock, which Agent here, is the proxy up"),
|
|
52
56
|
cmd("version", "tab and proxy versions"),
|
|
53
57
|
cmd("up", "self-hosted: start the local proxy (fetches it the first time)"),
|
|
@@ -487,6 +491,8 @@ async function runAgent(name, args) {
|
|
|
487
491
|
const key = presentedKey({ key: agent.key, unlock: config.unlock });
|
|
488
492
|
reportFolder(config.proxyUrl, key);
|
|
489
493
|
const { spec, env } = envFor({ name, proxyUrl: config.proxyUrl, presentedKey: key });
|
|
494
|
+
// An alias shim named like the agent must not be what we spawn.
|
|
495
|
+
env.PATH = pathWithoutShims();
|
|
490
496
|
if (spec.isolatedHome === "codex") {
|
|
491
497
|
env.CODEX_HOME = await prepareCodexHome({
|
|
492
498
|
baseDir: configDir(),
|
|
@@ -511,6 +517,46 @@ async function runAgent(name, args) {
|
|
|
511
517
|
child.on("close", (code, signal) => resolve(code ?? (signal ? 128 : 1)));
|
|
512
518
|
});
|
|
513
519
|
}
|
|
520
|
+
/**
|
|
521
|
+
* `tab alias codex claude`: shims so the plain commands run on the tab.
|
|
522
|
+
* `tab alias` alone lists them; `tab unalias codex` removes one.
|
|
523
|
+
*/
|
|
524
|
+
async function alias(names, remove = false) {
|
|
525
|
+
if (names.length === 0 && !remove) {
|
|
526
|
+
const existing = await listAliases();
|
|
527
|
+
if (existing.length === 0)
|
|
528
|
+
say(dim(`No aliases. Example: ${bold("tab alias codex claude")}`));
|
|
529
|
+
else
|
|
530
|
+
say(rows(existing.map((n) => [n, dim(`tab ${n}`)]), 0));
|
|
531
|
+
return pathHint();
|
|
532
|
+
}
|
|
533
|
+
if (names.length === 0) {
|
|
534
|
+
fail("tab unalias needs a name.");
|
|
535
|
+
return 2;
|
|
536
|
+
}
|
|
537
|
+
for (const name of names) {
|
|
538
|
+
if (!validAliasName(name)) {
|
|
539
|
+
fail(`${name} is not a usable alias name.`);
|
|
540
|
+
return 2;
|
|
541
|
+
}
|
|
542
|
+
if (remove) {
|
|
543
|
+
(await removeAlias(name)) ? ok(`Removed ${name}.`) : warn(`${name} was not an alias.`);
|
|
544
|
+
}
|
|
545
|
+
else {
|
|
546
|
+
const file = await writeAlias(name);
|
|
547
|
+
ok(`${bold(name)} now runs ${bold(`tab ${name}`)} ${dim(`(${file})`)}`);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
return remove ? 0 : pathHint();
|
|
551
|
+
}
|
|
552
|
+
function pathHint() {
|
|
553
|
+
if (shimDirOnPath())
|
|
554
|
+
return 0;
|
|
555
|
+
say("");
|
|
556
|
+
say(`Put ${dim(shimDir())} first on your PATH so the aliases win. Add to your shell rc, then open a new terminal:`);
|
|
557
|
+
say(` ${bold(pathLine())}`);
|
|
558
|
+
return 0;
|
|
559
|
+
}
|
|
514
560
|
/** `tab use`: pick or change the Agent for this folder. */
|
|
515
561
|
async function use() {
|
|
516
562
|
const config = await ensureLogin();
|
|
@@ -605,6 +651,10 @@ async function main(argv) {
|
|
|
605
651
|
return 0;
|
|
606
652
|
case "use":
|
|
607
653
|
return use();
|
|
654
|
+
case "alias":
|
|
655
|
+
return alias(rest);
|
|
656
|
+
case "unalias":
|
|
657
|
+
return alias(rest, true);
|
|
608
658
|
case "version":
|
|
609
659
|
case "--version":
|
|
610
660
|
case "-v":
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** Written by scripts/write-version.mjs from package.json at build; `tab version` prints it. */
|
|
2
|
-
export const TAB_VERSION = "0.1.
|
|
2
|
+
export const TAB_VERSION = "0.1.2";
|