openmsg 0.4.5 → 0.4.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/package.json +1 -1
- package/src/registry.mjs +50 -7
package/package.json
CHANGED
package/src/registry.mjs
CHANGED
|
@@ -19,9 +19,41 @@ function alive(pid) {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
// Claude Code keeps its state in ~/.claude, or in the directory that
|
|
23
|
+
// CLAUDE_CONFIG_DIR names. A person can run sessions with more than one such
|
|
24
|
+
// directory, for example ~/.claude-work for a second account. Each session of
|
|
25
|
+
// each directory must be found, so openmsg reads all of them.
|
|
26
|
+
export function claudeConfigDirs() {
|
|
27
|
+
const dirs = [path.join(HOME, ".claude")];
|
|
28
|
+
if (process.env.CLAUDE_CONFIG_DIR) dirs.push(path.resolve(process.env.CLAUDE_CONFIG_DIR));
|
|
29
|
+
try {
|
|
30
|
+
for (const d of fs.readdirSync(HOME)) {
|
|
31
|
+
if (!d.startsWith(".claude-")) continue;
|
|
32
|
+
const full = path.join(HOME, d);
|
|
33
|
+
if (fs.existsSync(path.join(full, "sessions"))) dirs.push(full);
|
|
34
|
+
}
|
|
35
|
+
} catch {
|
|
36
|
+
// The home directory cannot be read.
|
|
37
|
+
}
|
|
38
|
+
return [...new Set(dirs)];
|
|
39
|
+
}
|
|
40
|
+
|
|
22
41
|
// Claude Code writes one file for each session, with the path of its inbox socket.
|
|
23
42
|
export function claudeAgents() {
|
|
24
|
-
const
|
|
43
|
+
const out = [];
|
|
44
|
+
const seen = new Set();
|
|
45
|
+
for (const config of claudeConfigDirs()) {
|
|
46
|
+
for (const agent of claudeAgentsIn(config)) {
|
|
47
|
+
if (seen.has(agent.id)) continue;
|
|
48
|
+
seen.add(agent.id);
|
|
49
|
+
out.push(agent);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function claudeAgentsIn(config) {
|
|
56
|
+
const dir = path.join(config, "sessions");
|
|
25
57
|
let files = [];
|
|
26
58
|
try {
|
|
27
59
|
files = fs.readdirSync(dir).filter((f) => f.endsWith(".json"));
|
|
@@ -44,7 +76,7 @@ export function claudeAgents() {
|
|
|
44
76
|
pid: rec.pid,
|
|
45
77
|
cwd: rec.cwd,
|
|
46
78
|
status: rec.status ?? "unknown",
|
|
47
|
-
title: claudeTitle(rec.cwd, rec.sessionId),
|
|
79
|
+
title: claudeTitle(config, rec.cwd, rec.sessionId),
|
|
48
80
|
// A program that uses the SDK, such as a memory observer, starts a
|
|
49
81
|
// session too. It is not a session that a person talks to.
|
|
50
82
|
background: rec.entrypoint === "sdk-cli",
|
|
@@ -59,8 +91,8 @@ export function claudeAgents() {
|
|
|
59
91
|
// Claude Code keeps the transcript of a session in a directory that the
|
|
60
92
|
// working directory names, with each character that is not a letter or a digit
|
|
61
93
|
// changed to "-".
|
|
62
|
-
function claudeTranscript(cwd, sessionId) {
|
|
63
|
-
const root = path.join(
|
|
94
|
+
function claudeTranscript(config, cwd, sessionId) {
|
|
95
|
+
const root = path.join(config, "projects");
|
|
64
96
|
const file = `${sessionId}.jsonl`;
|
|
65
97
|
if (cwd) {
|
|
66
98
|
const direct = path.join(root, cwd.replace(/[^A-Za-z0-9]/g, "-"), file);
|
|
@@ -77,9 +109,9 @@ function claudeTranscript(cwd, sessionId) {
|
|
|
77
109
|
return null;
|
|
78
110
|
}
|
|
79
111
|
|
|
80
|
-
function claudeTitle(cwd, sessionId) {
|
|
112
|
+
function claudeTitle(config, cwd, sessionId) {
|
|
81
113
|
if (!sessionId) return null;
|
|
82
|
-
const file = claudeTranscript(cwd, sessionId);
|
|
114
|
+
const file = claudeTranscript(config, cwd, sessionId);
|
|
83
115
|
return file ? lastClaudeTitle(file) : null;
|
|
84
116
|
}
|
|
85
117
|
|
|
@@ -436,8 +468,19 @@ export async function self() {
|
|
|
436
468
|
return known ?? { vendor: "codex", id, name: id.slice(-8), transport: { kind: "codex-queue" } };
|
|
437
469
|
}
|
|
438
470
|
if (process.env.CLAUDE_CODE_MESSAGING_SOCKET) {
|
|
439
|
-
const
|
|
471
|
+
const socket = process.env.CLAUDE_CODE_MESSAGING_SOCKET;
|
|
472
|
+
const me = claudeAgents().find((a) => a.transport.path === socket);
|
|
440
473
|
if (me && (await runsUnder(me.pid))) return me;
|
|
474
|
+
// A Claude session started this command, but no session record holds its
|
|
475
|
+
// socket. A shell name here is false: nobody can send to it, and an agent
|
|
476
|
+
// gives it to other agents as its own address.
|
|
477
|
+
if (!me) {
|
|
478
|
+
throw new Error(
|
|
479
|
+
`this command runs in a Claude Code session, but openmsg cannot find the record of that session ` +
|
|
480
|
+
`(socket ${socket}). openmsg reads ${claudeConfigDirs().map((d) => `${d}/sessions`).join(", ")}. ` +
|
|
481
|
+
`If the session uses another CLAUDE_CONFIG_DIR, run openmsg from inside it, or set OPENMSG_SELF.`,
|
|
482
|
+
);
|
|
483
|
+
}
|
|
441
484
|
}
|
|
442
485
|
const line = await ancestors(process.ppid);
|
|
443
486
|
let [codex, opencode] = await Promise.all([codexAgents(), opencodeAgents()]);
|