@shulex/cxclawctl 0.1.12 → 0.1.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shulex/cxclawctl",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "description": "Solvea CXClaw CLI and Codex plugin runtime",
5
5
  "type": "module",
6
6
  "bin": {
@@ -10,7 +10,6 @@
10
10
  "bin",
11
11
  "dist/cli.js",
12
12
  "dist/cli.js.map",
13
- "runtime",
14
13
  "capabilities.lock.json"
15
14
  ],
16
15
  "scripts": {
@@ -1,6 +0,0 @@
1
- export function withAuthWaitMarker<T>(
2
- operation: () => Promise<T>,
3
- env?: NodeJS.ProcessEnv,
4
- ): Promise<T>;
5
-
6
- export function hasActiveAuthWait(sessionId: string | undefined, now?: number): Promise<boolean>;
@@ -1,56 +0,0 @@
1
- import { createHash } from "node:crypto";
2
- import { mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises";
3
- import { tmpdir } from "node:os";
4
- import { join } from "node:path";
5
-
6
- const markerRoot = join(tmpdir(), "cxclaw-auth-wait");
7
- const markerTtlMs = 15 * 60 * 1000;
8
-
9
- const markerName = (sessionId, pid) =>
10
- `${createHash("sha256").update(sessionId).digest("hex").slice(0, 24)}-${pid}.json`;
11
-
12
- const isAlive = (pid) => {
13
- try {
14
- process.kill(pid, 0);
15
- return true;
16
- } catch (error) {
17
- return error?.code === "EPERM";
18
- }
19
- };
20
-
21
- export async function withAuthWaitMarker(operation, env = process.env) {
22
- const sessionId = env.CODEX_SESSION_ID ?? env.CODEX_THREAD_ID;
23
- if (!sessionId) return operation();
24
-
25
- await mkdir(markerRoot, { recursive: true, mode: 0o700 });
26
- const path = join(markerRoot, markerName(sessionId, process.pid));
27
- await writeFile(path, JSON.stringify({
28
- sessionId,
29
- threadId: env.CODEX_THREAD_ID ?? null,
30
- pid: process.pid,
31
- expiresAt: Date.now() + markerTtlMs,
32
- }), { mode: 0o600 });
33
- try {
34
- return await operation();
35
- } finally {
36
- await rm(path, { force: true }).catch(() => undefined);
37
- }
38
- }
39
-
40
- export async function hasActiveAuthWait(sessionId, now = Date.now()) {
41
- if (!sessionId) return false;
42
- const names = await readdir(markerRoot).catch(() => []);
43
- for (const name of names) {
44
- const path = join(markerRoot, name);
45
- try {
46
- const marker = JSON.parse(await readFile(path, "utf8"));
47
- const active = marker.sessionId === sessionId &&
48
- Number.isInteger(marker.pid) && marker.expiresAt > now && isAlive(marker.pid);
49
- if (active) return true;
50
- if (marker.expiresAt <= now || !isAlive(marker.pid)) await rm(path, { force: true });
51
- } catch {
52
- await rm(path, { force: true }).catch(() => undefined);
53
- }
54
- }
55
- return false;
56
- }