tyc-cli 0.3.4 → 0.3.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/dist/session.js DELETED
@@ -1,47 +0,0 @@
1
- // ~/.tyc/session.json 读写 + 24h TTL
2
- //
3
- // TTL 规则(按字面 24h,从 initializedAt 起):
4
- // - 命中:复用 sessionId,跳过 initialize
5
- // - 过期 / url 变化:强制重新 initialize
6
- // - 服务端主动失效(4xx + session 提示):mcpClient 调 clearSession 后重建
7
- import { readFileSync, writeFileSync, mkdirSync, existsSync, rmSync, chmodSync } from "node:fs";
8
- import { join } from "node:path";
9
- import { homedir } from "node:os";
10
- const SESSION_DIR = join(homedir(), ".tyc");
11
- const SESSION_FILE = join(SESSION_DIR, "session.json");
12
- export const SESSION_TTL_MS = 24 * 60 * 60 * 1000; // 24h 字面
13
- export function loadSession() {
14
- if (!existsSync(SESSION_FILE))
15
- return null;
16
- try {
17
- const raw = readFileSync(SESSION_FILE, "utf-8");
18
- return JSON.parse(raw);
19
- }
20
- catch {
21
- return null;
22
- }
23
- }
24
- export function saveSession(s) {
25
- if (!existsSync(SESSION_DIR))
26
- mkdirSync(SESSION_DIR, { recursive: true, mode: 0o700 });
27
- writeFileSync(SESSION_FILE, JSON.stringify(s, null, 2) + "\n", "utf-8");
28
- try {
29
- chmodSync(SESSION_FILE, 0o600);
30
- }
31
- catch { /* best effort */ }
32
- }
33
- export function clearSession() {
34
- try {
35
- rmSync(SESSION_FILE, { force: true });
36
- }
37
- catch { /* ignore */ }
38
- }
39
- export function isSessionFresh(s, url, now = Date.now()) {
40
- if (!s)
41
- return false;
42
- if (s.url !== url)
43
- return false;
44
- if (!s.sessionId)
45
- return false;
46
- return now - s.initializedAt < SESSION_TTL_MS;
47
- }