@alexnpm2372/traypost-cli 0.0.0-stage → 0.1.0
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
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# TrayPost CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Install Node.js 22+ and Python 3.9+ with venv (Windows: install the py launcher). Run the following in your own terminal:
|
|
4
|
+
|
|
5
|
+
npm install -g @alexnpm2372/traypost-cli
|
|
6
|
+
traypost setup
|
|
7
|
+
traypost claude approval
|
|
8
|
+
|
|
9
|
+
Use claude, chatgpt, or cursor consistently. Approve the public code at https://traypost.vercel.app/account#interface-setup and run `traypost claude identify` to check your mailbox address. The private token stays in macOS Keychain, Windows Credential Manager, or an unlocked Linux Secret Service session. The CLI supports mailbox identification.
|
package/package.json
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alexnpm2372/traypost-cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
}
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Pair a local agent with an approved TrayPost mailbox",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": { "traypost": "traypost.mjs" },
|
|
7
|
+
"engines": { "node": ">=22" },
|
|
8
|
+
"files": ["traypost.mjs", "runtime/"],
|
|
9
|
+
"scripts": { "prepack": "node prepare.mjs" },
|
|
10
|
+
"publishConfig": { "access": "public", "registry": "https://registry.npmjs.org/" }
|
|
11
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""Read the paired credential for the local MCP server; stdout is a private pipe."""
|
|
2
|
+
import re
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def system_keyring():
|
|
7
|
+
"""Choose an OS credential store explicitly; never fall back to a file backend."""
|
|
8
|
+
if sys.platform == "darwin":
|
|
9
|
+
from keyring.backends.macOS import Keyring
|
|
10
|
+
return Keyring()
|
|
11
|
+
if sys.platform == "win32":
|
|
12
|
+
from keyring.backends.Windows import WinVaultKeyring
|
|
13
|
+
return WinVaultKeyring()
|
|
14
|
+
if sys.platform.startswith("linux"):
|
|
15
|
+
from keyring.backends.SecretService import Keyring
|
|
16
|
+
return Keyring()
|
|
17
|
+
raise RuntimeError("Unsupported operating system")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def read_credential(service, client):
|
|
21
|
+
token = system_keyring().get_password(service, client)
|
|
22
|
+
if not isinstance(token, str) or not re.fullmatch(r"tp_agent_[0-9a-f]{64}", token):
|
|
23
|
+
raise ValueError("Missing or invalid pairing credential")
|
|
24
|
+
return token
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
if __name__ == "__main__":
|
|
28
|
+
try:
|
|
29
|
+
if len(sys.argv) != 3 or sys.argv[2] != "chatgpt":
|
|
30
|
+
raise ValueError("Invalid bridge arguments")
|
|
31
|
+
sys.stdout.write(read_credential(sys.argv[1], sys.argv[2]))
|
|
32
|
+
except Exception:
|
|
33
|
+
print("Credential store unavailable", file=sys.stderr)
|
|
34
|
+
sys.exit(1)
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"""Identify an approved TrayPost mailbox using a client-specific operating system credential store."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import hashlib
|
|
5
|
+
import http.client
|
|
6
|
+
import json
|
|
7
|
+
import re
|
|
8
|
+
import secrets
|
|
9
|
+
import sys
|
|
10
|
+
|
|
11
|
+
from dataclasses import dataclass
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
# Share the exact platform-specific credential store with the local MCP bridge.
|
|
15
|
+
sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "plugins/traypost-mailbox"))
|
|
16
|
+
from credential_bridge import system_keyring
|
|
17
|
+
|
|
18
|
+
@dataclass(frozen=True)
|
|
19
|
+
class PairingConfig:
|
|
20
|
+
"""Code-owned destination and credential namespace shared with the desktop plugin."""
|
|
21
|
+
|
|
22
|
+
host: str
|
|
23
|
+
path: str
|
|
24
|
+
servicePath: str
|
|
25
|
+
timeoutMs: int
|
|
26
|
+
clients: list[str]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
CONFIG = PairingConfig(**json.loads(
|
|
30
|
+
(Path(__file__).resolve().parents[2] / "config/interface-pairing.json").read_text()
|
|
31
|
+
))
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def stored_token(client: str, create: bool) -> str:
|
|
35
|
+
"""Read this client's token, creating it only for the explicit approval step."""
|
|
36
|
+
store = system_keyring()
|
|
37
|
+
service = f"https://{CONFIG.host}{CONFIG.servicePath}"
|
|
38
|
+
token = store.get_password(service, client)
|
|
39
|
+
if token is None and create:
|
|
40
|
+
token = "tp_agent_" + secrets.token_hex(32)
|
|
41
|
+
store.set_password(service, client, token)
|
|
42
|
+
if token is None or not re.fullmatch(r"tp_agent_[0-9a-f]{64}", token):
|
|
43
|
+
raise ValueError("Missing or invalid pairing credential")
|
|
44
|
+
return token
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def identify(token: str) -> tuple[int, str]:
|
|
48
|
+
"""Send one authenticated POST to the pinned origin without following redirects."""
|
|
49
|
+
connection = http.client.HTTPSConnection(CONFIG.host, timeout=CONFIG.timeoutMs / 1000)
|
|
50
|
+
try:
|
|
51
|
+
connection.request("POST", CONFIG.path, body=b"",
|
|
52
|
+
headers={"Authorization": f"Bearer {token}"})
|
|
53
|
+
response = connection.getresponse()
|
|
54
|
+
if response.status == 401:
|
|
55
|
+
return 1, "401: Mailbox identification is not approved."
|
|
56
|
+
if response.status != 200:
|
|
57
|
+
return 1, f"{response.status}: Mailbox lookup unavailable."
|
|
58
|
+
payload = json.loads(response.read(4096))
|
|
59
|
+
mailbox = payload.get("mailbox") if isinstance(payload, dict) else None
|
|
60
|
+
if not isinstance(mailbox, str) or not re.fullmatch(r"[a-z0-9-]+@agents\.traypost\.com", mailbox) or payload.get("scope") != "mailbox:identify":
|
|
61
|
+
raise ValueError("Unexpected mailbox response")
|
|
62
|
+
return 0, "200: " + mailbox
|
|
63
|
+
finally:
|
|
64
|
+
connection.close()
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def main() -> int:
|
|
68
|
+
"""Print only a public approval code or the scoped mailbox lookup outcome."""
|
|
69
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
70
|
+
parser.add_argument("client", choices=CONFIG.clients)
|
|
71
|
+
parser.add_argument("action", choices=("approval", "identify"))
|
|
72
|
+
args = parser.parse_args()
|
|
73
|
+
approve = args.action == "approval"
|
|
74
|
+
try:
|
|
75
|
+
token = stored_token(args.client, approve)
|
|
76
|
+
if approve:
|
|
77
|
+
print(hashlib.sha256(token.encode()).hexdigest())
|
|
78
|
+
return 0
|
|
79
|
+
status, message = identify(token)
|
|
80
|
+
print(message)
|
|
81
|
+
return status
|
|
82
|
+
except Exception:
|
|
83
|
+
print("Pairing unavailable. Check your system credential store, network, and setup.", file=sys.stderr)
|
|
84
|
+
return 2
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
if __name__ == "__main__":
|
|
88
|
+
sys.exit(main())
|
package/traypost.mjs
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
|
|
8
|
+
const windows = process.platform === "win32";
|
|
9
|
+
const env = windows
|
|
10
|
+
? join(process.env.LOCALAPPDATA || join(homedir(), "AppData", "Local"), "TrayPost", "client-env")
|
|
11
|
+
: join(homedir(), ".traypost-client-env");
|
|
12
|
+
const python = join(env, windows ? "Scripts/python.exe" : "bin/python");
|
|
13
|
+
function run(command, args) {
|
|
14
|
+
const result = spawnSync(command, args, { stdio: "inherit" });
|
|
15
|
+
if (result.error) console.error("Could not launch " + command + ". Check your Python installation.");
|
|
16
|
+
if (result.status !== 0) process.exit(result.status ?? 1);
|
|
17
|
+
}
|
|
18
|
+
const args = process.argv.slice(2);
|
|
19
|
+
if (args.length === 1 && args[0] === "setup") {
|
|
20
|
+
if (!existsSync(python)) run(windows ? "py" : "python3", [...(windows ? ["-3"] : []), "-m", "venv", env]);
|
|
21
|
+
run(python, ["-m", "pip", "install", "keyring>=25,<26"]);
|
|
22
|
+
} else if (args.length === 2 && ["claude","chatgpt","cursor"].includes(args[0]) && ["approval","identify"].includes(args[1])) {
|
|
23
|
+
if (!existsSync(python)) { console.error("Run traypost setup first."); process.exit(1); }
|
|
24
|
+
run(python, [fileURLToPath(new URL("./runtime/scripts/client-setup/mailbox.py", import.meta.url)), ...args]);
|
|
25
|
+
} else {
|
|
26
|
+
console.log("Usage: traypost setup | traypost <claude|chatgpt|cursor> <approval|identify>");
|
|
27
|
+
process.exit(args.length === 0 || args[0] === "--help" ? 0 : 2);
|
|
28
|
+
}
|