consult-mcp 0.3.0 → 0.3.1
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 +1 -1
- package/dist/sessions/identity.js +20 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -91,7 +91,7 @@ Settings are stored in `$XDG_CONFIG_HOME/consult/settings.json` (default `~/.con
|
|
|
91
91
|
|
|
92
92
|
| CLI | How consult finds the session |
|
|
93
93
|
| --- | --- |
|
|
94
|
-
| claude | `
|
|
94
|
+
| claude | the record Claude Code keeps for each running process (`~/.claude/sessions/<pid>.json`), so it follows `/resume` and `/clear`; `CLAUDE_CODE_SESSION_ID` as a fallback. Listed once the conversation is saved, after its first message |
|
|
95
95
|
| codex | the `rollout-*.jsonl` file the codex process holds open, from the session's first turn on |
|
|
96
96
|
| grok | the `~/.grok/sessions/<cwd>/<session id>/events.jsonl` file the interactive grok process holds open, from the session's first turn on; not identified if several sessions are open |
|
|
97
97
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync, readdirSync, readlinkSync } from "node:fs";
|
|
1
|
+
import { existsSync, readdirSync, readFileSync, readlinkSync } from "node:fs";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import { basename, join } from "node:path";
|
|
4
4
|
import { AGENTS, SESSION_ID_PATTERN } from "../types.js";
|
|
@@ -23,11 +23,14 @@ export async function detectHost(deps) {
|
|
|
23
23
|
export async function currentSession(host, deps) {
|
|
24
24
|
switch (host.agent) {
|
|
25
25
|
case "claude": {
|
|
26
|
-
|
|
26
|
+
// CLAUDE_CODE_SESSION_ID is fixed when this server starts, so it goes stale after /resume or /clear.
|
|
27
|
+
// Claude Code's per-process record follows the conversation, so it wins when there is one.
|
|
28
|
+
const sessionId = (host.pid === undefined ? undefined : deps.claudeSessionOf(host.pid)) ?? deps.env.CLAUDE_CODE_SESSION_ID;
|
|
27
29
|
if (!sessionId || !SAFE_ID.test(sessionId))
|
|
28
30
|
return undefined;
|
|
31
|
+
// A fork resumes the saved conversation, so the session can only be asked once its transcript exists.
|
|
29
32
|
const transcriptPath = deps.claudeTranscript(sessionId);
|
|
30
|
-
return
|
|
33
|
+
return transcriptPath ? { sessionId, transcriptPath } : undefined;
|
|
31
34
|
}
|
|
32
35
|
case "codex": {
|
|
33
36
|
if (host.pid === undefined)
|
|
@@ -71,6 +74,7 @@ function procFds(pid) {
|
|
|
71
74
|
}
|
|
72
75
|
}
|
|
73
76
|
export function systemIdentityDeps(run, env = process.env, platform = process.platform, startPid = process.ppid) {
|
|
77
|
+
const claudeDir = env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude");
|
|
74
78
|
return {
|
|
75
79
|
env,
|
|
76
80
|
async ancestors() {
|
|
@@ -94,8 +98,20 @@ export function systemIdentityDeps(run, env = process.env, platform = process.pl
|
|
|
94
98
|
.filter((line) => line.startsWith("n"))
|
|
95
99
|
.map((line) => line.slice(1));
|
|
96
100
|
},
|
|
101
|
+
claudeSessionOf(pid) {
|
|
102
|
+
try {
|
|
103
|
+
const record = JSON.parse(readFileSync(join(claudeDir, "sessions", `${pid}.json`), "utf8"));
|
|
104
|
+
return record.pid === pid && typeof record.sessionId === "string" && SAFE_ID.test(record.sessionId)
|
|
105
|
+
? record.sessionId
|
|
106
|
+
: undefined;
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
// No record (older Claude Code, or not a claude process) or one being rewritten: use the env var.
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
},
|
|
97
113
|
claudeTranscript(sessionId) {
|
|
98
|
-
const projects = join(
|
|
114
|
+
const projects = join(claudeDir, "projects");
|
|
99
115
|
let dirs;
|
|
100
116
|
try {
|
|
101
117
|
dirs = readdirSync(projects);
|
package/package.json
CHANGED