pairai 0.2.4 → 0.2.5
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/lib.ts +80 -0
- package/package.json +2 -1
package/lib.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure/testable functions extracted from pairai CLI.
|
|
3
|
+
* Imported by both pairai.ts and unit tests.
|
|
4
|
+
*/
|
|
5
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Validate the --provider flag value.
|
|
10
|
+
* Returns the validated provider or throws with a message.
|
|
11
|
+
*/
|
|
12
|
+
export function validateProvider(value: string): "claude" | "gemini" {
|
|
13
|
+
if (value !== "claude" && value !== "gemini") {
|
|
14
|
+
throw new Error(`Unknown provider "${value}". Must be "claude" or "gemini".`);
|
|
15
|
+
}
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Auto-detect provider based on environment and filesystem.
|
|
21
|
+
*/
|
|
22
|
+
export function detectProvider(): "claude" | "gemini" {
|
|
23
|
+
if (process.env.GEMINI_CLI) return "gemini";
|
|
24
|
+
try { if (statSync(".gemini").isDirectory()) return "gemini"; } catch {}
|
|
25
|
+
return "claude";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Replace any `pairai@x.y.z` version pin in a config string with a new version.
|
|
30
|
+
*/
|
|
31
|
+
export function updateVersionInConfig(content: string, latest: string): string {
|
|
32
|
+
return content.replace(/pairai@\d+\.\d+\.\d+/g, `pairai@${latest}`);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Check if pairai is already configured in a config file.
|
|
37
|
+
* Returns the path if config exists with a pairai entry, null otherwise.
|
|
38
|
+
*/
|
|
39
|
+
export function checkExistingConfig(
|
|
40
|
+
provider: "claude" | "gemini",
|
|
41
|
+
cwd: string,
|
|
42
|
+
homeDir: string,
|
|
43
|
+
useGlobal: boolean,
|
|
44
|
+
): string | null {
|
|
45
|
+
const configPath = provider === "gemini"
|
|
46
|
+
? join(useGlobal ? join(homeDir, ".gemini") : join(cwd, ".gemini"), "settings.json")
|
|
47
|
+
: join(cwd, ".mcp.json");
|
|
48
|
+
const mcpKey = provider === "gemini" ? "pairai" : "pairai-channel";
|
|
49
|
+
|
|
50
|
+
if (!existsSync(configPath)) return null;
|
|
51
|
+
try {
|
|
52
|
+
const existing = JSON.parse(readFileSync(configPath, "utf-8"));
|
|
53
|
+
const servers = existing.mcpServers ?? {};
|
|
54
|
+
if (servers[mcpKey]) return configPath;
|
|
55
|
+
} catch {}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Build the dynamic-width box for the private key backup warning.
|
|
61
|
+
*/
|
|
62
|
+
export function formatKeyBackupBox(keyPath: string): string[] {
|
|
63
|
+
const lines = [
|
|
64
|
+
"BACK UP YOUR PRIVATE KEY",
|
|
65
|
+
"",
|
|
66
|
+
keyPath,
|
|
67
|
+
"",
|
|
68
|
+
"This key is stored only on your machine.",
|
|
69
|
+
"The hub never sees it. If lost, you must re-register",
|
|
70
|
+
"and re-pair \u2014 all encrypted history becomes unreadable.",
|
|
71
|
+
"",
|
|
72
|
+
"Copy it to a password manager or secure backup now.",
|
|
73
|
+
];
|
|
74
|
+
const w = Math.max(...lines.map((l) => l.length)) + 2;
|
|
75
|
+
const out: string[] = [];
|
|
76
|
+
out.push(` \u250C${"\u2500".repeat(w + 2)}\u2510`);
|
|
77
|
+
for (const l of lines) out.push(` \u2502 ${l.padEnd(w)}\u2502`);
|
|
78
|
+
out.push(` \u2514${"\u2500".repeat(w + 2)}\u2518`);
|
|
79
|
+
return out;
|
|
80
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pairai",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"description": "pairai CLI — connect AI agents to collaborate via the pairai hub",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"files": [
|
|
25
25
|
"bin.js",
|
|
26
26
|
"pairai.ts",
|
|
27
|
+
"lib.ts",
|
|
27
28
|
"README.md"
|
|
28
29
|
],
|
|
29
30
|
"dependencies": {
|