baychat 0.53.0 → 0.55.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/.claude-plugin/plugin.json +1 -1
- package/README.md +1 -0
- package/dist/mcp-room-requests.js +21 -3
- package/dist/multiplexer-launch.js +20 -1
- package/dist/pane-exit.js +236 -0
- package/dist/protocol-content.js +1 -1
- package/dist/relay/launcher/dev-channel-screen.fixtures.js +47 -3
- package/dist/relay/launcher/dev-channel-screen.js +56 -10
- package/dist/relay/launcher/handle.js +8 -117
- package/dist/relay/launcher/loop.js +1 -0
- package/dist/relay/launcher/multiplexer.js +11 -0
- package/dist/relay/launcher/pane-watch.js +283 -0
- package/dist/tool-defs-notes.js +18 -0
- package/dist/tool-defs.js +2 -2
- package/dist/tool-hints.js +1 -0
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "baychat",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.55.0",
|
|
4
4
|
"displayName": "BayChat",
|
|
5
5
|
"description": "Wakes this Claude Code session the moment a BayChat message arrives: no Monitor, no 30-minute deadline. Uses the baychat CLI already on this computer (npm install -g baychat, then baychat login).",
|
|
6
6
|
"author": {
|
package/README.md
CHANGED
|
@@ -947,6 +947,7 @@ instruction):
|
|
|
947
947
|
| `file_to_folder` | Put one of this chat's files into a folder of its project (by name or id); `move` takes it out of the others |
|
|
948
948
|
| `request_clear_chat` | Ask one of the chat's admins, on a card, to clear it for everyone (`keep: "summary"` keeps a summary as a pinned note); nothing happens unless they say yes |
|
|
949
949
|
| `pin_note` / `unpin_note` / `delete_note` | Ask one of the chat's admins, on a card, to pin, unpin or delete (Trash, 30 days) a note; nothing happens unless they say yes |
|
|
950
|
+
| `propose_file_cleanup` | Propose removing up to 500 of the chat's files (ids from `list_files`) with a reason; a Remove / Keep card goes to one person who may remove them all, and nothing is removed unless they tap Remove (v2.40) |
|
|
950
951
|
| `list_file_comments` | The notes people pinned on a chat's picture, PDF or video, oldest first, each with where it sits ("0:12", "p. 3, 40% / 20%") and whether it is resolved |
|
|
951
952
|
| `add_file_comment` | Pin a note on a file as you — on a spot, a page and spot, a moment of a video, or the whole file; it also shows in the chat as a 📍 reply |
|
|
952
953
|
| `resolve_file_comment` | Mark a file note resolved |
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Asking a chat's admin to change the chat, on the local stdio MCP server (protocol v2.26): `request_clear_chat`,
|
|
3
|
-
// `pin_note`, `unpin_note`, `delete_note
|
|
4
|
-
// is one agent-API call. Nothing is ever done
|
|
3
|
+
// `pin_note`, `unpin_note`, `delete_note`; and proposing to remove files (v2.40): `propose_file_cleanup`. Defined in
|
|
4
|
+
// `tool-defs-notes.ts` (shared with the remote endpoint); each handler is one agent-API call. Nothing is ever done
|
|
5
|
+
// silently: the server puts a card in the chat for one person who may decide.
|
|
5
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
7
|
exports.ROOM_REQUEST_HANDLERS = void 0;
|
|
7
8
|
exports.handleRequestClearChat = handleRequestClearChat;
|
|
9
|
+
exports.handleProposeFileCleanup = handleProposeFileCleanup;
|
|
8
10
|
const api_1 = require("./api");
|
|
9
11
|
const mcp_result_1 = require("./mcp-result");
|
|
10
12
|
const terminal_text_1 = require("./relay/terminal-text");
|
|
11
13
|
const oneLine = (text) => (0, terminal_text_1.cleanTerminalText)(text).replace(/\s+/g, " ").trim();
|
|
12
14
|
/** A refusal the model can act on: the code and the reason. */
|
|
13
15
|
function requestError(err) {
|
|
14
|
-
if (err instanceof api_1.ApiError && err.code && /^(ROOM_REQUEST_|NO_CHAT_ADMIN|NOTHING_TO_CHANGE|NOTE_NOT_FOUND|CONVERSATION_NOT_FOUND|INVALID_REQUEST)/.test(err.code)) {
|
|
16
|
+
if (err instanceof api_1.ApiError && err.code && /^(ROOM_REQUEST_|NO_CHAT_ADMIN|NOTHING_TO_CHANGE|NOTE_NOT_FOUND|CONVERSATION_NOT_FOUND|INVALID_REQUEST|NO_FILE_REMOVER|FILE_CLEANUP_PENDING|FILE_NOT_FOUND|AGENT_TOOLS_RESTRICTED)/.test(err.code)) {
|
|
15
17
|
return (0, mcp_result_1.fail)(`${err.code}: ${err.message}`);
|
|
16
18
|
}
|
|
17
19
|
return (0, mcp_result_1.toToolError)(err);
|
|
@@ -41,10 +43,26 @@ function noteRequest(kind) {
|
|
|
41
43
|
}
|
|
42
44
|
};
|
|
43
45
|
}
|
|
46
|
+
const megabytes = (bytes) => `${Math.max(1, Math.round(bytes / (1024 * 1024)))} MB`;
|
|
47
|
+
async function handleProposeFileCleanup(args) {
|
|
48
|
+
try {
|
|
49
|
+
const res = await (0, api_1.apiRequest)((0, mcp_result_1.requireCredentials)(), "POST", `${base(args.conversationId)}/file-cleanup`, {
|
|
50
|
+
attachmentIds: args.attachmentIds,
|
|
51
|
+
reason: args.reason,
|
|
52
|
+
});
|
|
53
|
+
return (0, mcp_result_1.ok)(`Proposed to ${oneLine(res.askedName)} on a card in the chat: remove ${res.files} files (${megabytes(res.bytes)}). ` +
|
|
54
|
+
`You removed nothing; nothing happens unless they tap Remove. Waiting is not a yes or a no. ` +
|
|
55
|
+
`Request id: ${res.requestId}. Do not propose again.`, res);
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
return requestError(err);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
44
61
|
/** Handler per tool name, registered with the conversation tools (mcp.ts). */
|
|
45
62
|
exports.ROOM_REQUEST_HANDLERS = {
|
|
46
63
|
request_clear_chat: (args) => handleRequestClearChat(args),
|
|
47
64
|
pin_note: (args) => noteRequest("pin")(args),
|
|
48
65
|
unpin_note: (args) => noteRequest("unpin")(args),
|
|
49
66
|
delete_note: (args) => noteRequest("delete")(args),
|
|
67
|
+
propose_file_cleanup: (args) => handleProposeFileCleanup(args),
|
|
50
68
|
};
|
|
@@ -74,6 +74,7 @@ const fs = __importStar(require("fs"));
|
|
|
74
74
|
const path = __importStar(require("path"));
|
|
75
75
|
const readline = __importStar(require("readline"));
|
|
76
76
|
const config_1 = require("./config");
|
|
77
|
+
const pane_exit_1 = require("./pane-exit");
|
|
77
78
|
const terminal_pane_1 = require("./relay/terminal-pane");
|
|
78
79
|
const runtime_binary_1 = require("./runtime-binary");
|
|
79
80
|
/** Set in the agent's environment to the tmux session our CLI created for it (read by detectPane). */
|
|
@@ -90,12 +91,25 @@ async function launchAgent(program, naming, deps = realLaunchDeps()) {
|
|
|
90
91
|
if (!multiplexer)
|
|
91
92
|
return runHere(program, deps);
|
|
92
93
|
const argv = multiplexerArgv(multiplexer, naming, program, deps);
|
|
94
|
+
// Keep what the agent showed if it stops inside tmux (pane-exit.ts); never for screen or a detached start.
|
|
95
|
+
const capture = multiplexer === "tmux" && naming.kind !== "detached" && deps.exitWatch?.canWatch() ? deps.exitWatch.create() : undefined;
|
|
96
|
+
if (capture)
|
|
97
|
+
argv.push(...(0, pane_exit_1.tmuxExitWatchArgs)(argv[2], capture));
|
|
98
|
+
const startedAt = deps.now?.() ?? Date.now();
|
|
93
99
|
const result = deps.run(multiplexer, argv, { ...deps.env, ...program.env });
|
|
100
|
+
const report = capture ? deps.exitWatch.read(capture) : undefined;
|
|
101
|
+
if (capture)
|
|
102
|
+
deps.exitWatch.remove(capture);
|
|
94
103
|
// Falling back rather than failing: the multiplexer is an enhancement, and refusing to start
|
|
95
104
|
// somebody's agent because of one would be the tail wagging the dog.
|
|
96
105
|
if (result.error)
|
|
97
106
|
return runHere(program, deps);
|
|
98
|
-
|
|
107
|
+
if (!report)
|
|
108
|
+
return result.status ?? 0;
|
|
109
|
+
const elapsed = (deps.now?.() ?? Date.now()) - startedAt;
|
|
110
|
+
for (const line of (0, pane_exit_1.exitNotice)(path.basename(program.binary), report, elapsed, deps.exitWatch.notice))
|
|
111
|
+
deps.say(line);
|
|
112
|
+
return report.status;
|
|
99
113
|
}
|
|
100
114
|
/** Run the agent in this terminal, as it would run without BayChat. On Windows an npm-installed
|
|
101
115
|
* agent is a `.cmd` shim, which Node will not spawn directly (EINVAL): `spawnPlanFor` starts
|
|
@@ -247,6 +261,11 @@ function realLaunchDeps() {
|
|
|
247
261
|
return !probe.error && probe.status === 0;
|
|
248
262
|
},
|
|
249
263
|
tmuxHasSession: (name) => (0, child_process_1.spawnSync)("tmux", ["has-session", "-t", `=${name}`], { stdio: "ignore" }).status === 0,
|
|
264
|
+
exitWatch: (0, pane_exit_1.realExitWatch)(() => {
|
|
265
|
+
const probe = (0, child_process_1.spawnSync)("tmux", ["-V"], { encoding: "utf8" });
|
|
266
|
+
return probe.error || probe.status !== 0 ? undefined : String(probe.stdout ?? "");
|
|
267
|
+
}),
|
|
268
|
+
now: () => Date.now(),
|
|
250
269
|
installer: () => tmuxInstallerFor(process.platform, (cmd) => onPath(cmd, process.env), process.getuid?.() === 0),
|
|
251
270
|
ask: askLine,
|
|
252
271
|
say: (line) => console.error(line),
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.QUICK_EXIT_MS = void 0;
|
|
37
|
+
exports.tmuxCanWatchExit = tmuxCanWatchExit;
|
|
38
|
+
exports.createExitCapture = createExitCapture;
|
|
39
|
+
exports.tmuxExitWatchArgs = tmuxExitWatchArgs;
|
|
40
|
+
exports.readExitReport = readExitReport;
|
|
41
|
+
exports.removeExitCapture = removeExitCapture;
|
|
42
|
+
exports.exitNotice = exitNotice;
|
|
43
|
+
exports.lastLines = lastLines;
|
|
44
|
+
exports.resumeHint = resumeHint;
|
|
45
|
+
exports.conversationFolder = conversationFolder;
|
|
46
|
+
exports.realExitWatch = realExitWatch;
|
|
47
|
+
/**
|
|
48
|
+
* What an agent showed when it stopped inside the tmux session `baychat claude` / `baychat start` made.
|
|
49
|
+
*
|
|
50
|
+
* Without this, an agent that quits at once (Manuel, 20 Nov: `baychat claude --resume <id>` from the wrong
|
|
51
|
+
* folder, so Claude Code printed "No conversation found…" and exited 1) took its message with it: tmux
|
|
52
|
+
* closed the pane and the terminal was left with `[exited]`, and `baychat claude` itself exited 0.
|
|
53
|
+
*
|
|
54
|
+
* How: in the SAME tmux command sequence as `new` (so an agent that exits at once cannot beat it), the
|
|
55
|
+
* window keeps a dead pane (`remain-on-exit`) and a `pane-died` hook saves the pane's last lines and its
|
|
56
|
+
* exit status to a private temp folder, then kills the pane — so the session still closes as it always
|
|
57
|
+
* did. When tmux hands the terminal back, `launchAgent` reads the two files, shows the lines when the
|
|
58
|
+
* agent failed or stopped within its first seconds, and returns the agent's own status.
|
|
59
|
+
*
|
|
60
|
+
* Only tmux 3.0 or newer: an option or hook an older tmux does not know would make it refuse the whole
|
|
61
|
+
* command, and the agent must ALWAYS start. screen has no such hook; Windows runs the agent in the
|
|
62
|
+
* terminal itself, where its last words stay on screen anyway.
|
|
63
|
+
*/
|
|
64
|
+
const fs = __importStar(require("fs"));
|
|
65
|
+
const os = __importStar(require("os"));
|
|
66
|
+
const path = __importStar(require("path"));
|
|
67
|
+
const transcript_1 = require("./denied/transcript");
|
|
68
|
+
/** Stopping within this long counts as "right after it started" (a normal session runs far longer). */
|
|
69
|
+
exports.QUICK_EXIT_MS = 10_000;
|
|
70
|
+
/** How many of the pane's last lines are kept and shown. */
|
|
71
|
+
const SAVED_LINES = 40;
|
|
72
|
+
const SHOWN_LINES = 15;
|
|
73
|
+
/** tmux 3.0 or newer (`tmux 3.4`, `tmux 3.3a`, `tmux next-3.5`); anything unreadable is no. */
|
|
74
|
+
function tmuxCanWatchExit(versionText) {
|
|
75
|
+
const m = /(\d+)\.(\d+)/.exec(versionText ?? "");
|
|
76
|
+
return !!m && Number(m[1]) >= 3;
|
|
77
|
+
}
|
|
78
|
+
/** A private folder for one launch's two files, or undefined when none can be made (then no watch). */
|
|
79
|
+
function createExitCapture(mkdtemp = (p) => fs.mkdtempSync(p)) {
|
|
80
|
+
try {
|
|
81
|
+
const dir = mkdtemp(path.join(os.tmpdir(), "baychat-exit-"));
|
|
82
|
+
if (!safeForShell(dir))
|
|
83
|
+
return undefined;
|
|
84
|
+
return { dir, linesFile: path.join(dir, "last-lines.txt"), statusFile: path.join(dir, "status.txt") };
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
// No temp folder: the agent still starts, exactly as before this watch existed.
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/** The path goes inside single quotes in the hook's shell line: refuse anything that could end them. */
|
|
92
|
+
function safeForShell(p) {
|
|
93
|
+
return !/['"\\$`\n]/.test(p);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The commands appended to `tmux new -s <session> …`: `;` is tmux's own separator when it is a whole
|
|
97
|
+
* argument. The hook runs one shell line (run-shell expands `#{…}` first); `tmux` inside it reaches the
|
|
98
|
+
* same server, because tmux gives its jobs the session's `TMUX`.
|
|
99
|
+
*/
|
|
100
|
+
function tmuxExitWatchArgs(session, capture) {
|
|
101
|
+
const line = `tmux capture-pane -p -J -S -${SAVED_LINES} -t '#{hook_pane}' > '${capture.linesFile}'; ` +
|
|
102
|
+
`echo '#{pane_dead_status}' > '${capture.statusFile}'; ` +
|
|
103
|
+
`tmux kill-pane -t '#{hook_pane}'`;
|
|
104
|
+
return [";", "set-option", "-w", "-t", session, "remain-on-exit", "on", ";", "set-hook", "-t", session, "pane-died", `run-shell "${line}"`];
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* The report the hook left, or undefined when there is none — the person detached and the agent is still
|
|
108
|
+
* running, or tmux never ran the hook. Never throws.
|
|
109
|
+
*/
|
|
110
|
+
function readExitReport(capture, read = (p) => fs.readFileSync(p, "utf8")) {
|
|
111
|
+
try {
|
|
112
|
+
const status = Number.parseInt(read(capture.statusFile).trim(), 10);
|
|
113
|
+
if (!Number.isFinite(status))
|
|
114
|
+
return undefined;
|
|
115
|
+
let text = "";
|
|
116
|
+
try {
|
|
117
|
+
text = read(capture.linesFile);
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
// The status alone still says the agent stopped, and how.
|
|
121
|
+
}
|
|
122
|
+
return { status, text };
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/** Remove the folder. A hook that fires later (after a detach) then fails to write and still kills its pane. */
|
|
129
|
+
function removeExitCapture(capture) {
|
|
130
|
+
try {
|
|
131
|
+
fs.rmSync(capture.dir, { recursive: true, force: true });
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
// A leftover folder in the temp directory is harmless; the start already happened.
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* The lines to print after tmux returns: nothing for a normal end (status 0, after the first seconds);
|
|
139
|
+
* otherwise what stopped, how, and what it showed last — plus the one action to take when we know it.
|
|
140
|
+
*/
|
|
141
|
+
function exitNotice(agent, report, elapsedMs, deps = {}) {
|
|
142
|
+
const quick = elapsedMs < exports.QUICK_EXIT_MS;
|
|
143
|
+
if (report.status === 0 && !quick)
|
|
144
|
+
return [];
|
|
145
|
+
const how = report.status === 0 ? "" : ` (exit status ${report.status})`;
|
|
146
|
+
const head = quick ? `BayChat: ${agent} stopped right after it started${how}.` : `BayChat: ${agent} stopped${how}.`;
|
|
147
|
+
const shown = lastLines(report.text);
|
|
148
|
+
const out = [head, ...(shown.length ? ["What it showed last:", ...shown.map((l) => ` ${l}`)] : ["It showed nothing before it stopped."])];
|
|
149
|
+
const hint = resumeHint(report.text, deps);
|
|
150
|
+
return hint ? [...out, hint] : out;
|
|
151
|
+
}
|
|
152
|
+
/** The pane's last non-empty lines, without tmux's own "Pane is dead" line or stray control bytes (a NUL
|
|
153
|
+
* tmux sometimes leaves in a cell, seen 20 Nov). */
|
|
154
|
+
function lastLines(text) {
|
|
155
|
+
return text
|
|
156
|
+
.split(/\r?\n/)
|
|
157
|
+
.map((l) => l.replace(/[\x00-\x08\x0b-\x1f\x7f]/g, "").replace(/\s+$/, ""))
|
|
158
|
+
.filter((l) => l.trim() !== "" && !/^Pane is dead\b/.test(l.trim()))
|
|
159
|
+
.slice(-SHOWN_LINES);
|
|
160
|
+
}
|
|
161
|
+
const NO_CONVERSATION = /No conversation found with session ID:\s*([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/i;
|
|
162
|
+
/**
|
|
163
|
+
* Claude Code's `--resume <id>` finds a conversation only in the folder it started in. Name that folder
|
|
164
|
+
* when its transcript is on this computer; never move there unasked (vps, 20 Nov: a raw id is not one of
|
|
165
|
+
* our session names, and a folder change nobody asked for is a surprise).
|
|
166
|
+
*/
|
|
167
|
+
function resumeHint(text, deps = {}) {
|
|
168
|
+
const m = NO_CONVERSATION.exec(text);
|
|
169
|
+
if (!m)
|
|
170
|
+
return undefined;
|
|
171
|
+
const folder = (deps.conversationFolder ?? conversationFolder)(m[1].toLowerCase());
|
|
172
|
+
const here = deps.cwd ?? process.cwd();
|
|
173
|
+
if (folder && path.resolve(folder) !== path.resolve(here)) {
|
|
174
|
+
return `That conversation started in ${folder}: go to that folder (cd ${folder}) and run the same command again.`;
|
|
175
|
+
}
|
|
176
|
+
return "Run it in the folder where that conversation started.";
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* `<claude config>/projects/<slug>/<id>.jsonl` → the `cwd` its first lines record. The slug folder name
|
|
180
|
+
* cannot be turned back into a path (Claude Code replaces `/` and `.` alike), so the transcript says it.
|
|
181
|
+
*/
|
|
182
|
+
function conversationFolder(sessionId, deps = {}) {
|
|
183
|
+
const root = deps.root ?? path.join((0, transcript_1.claudeConfigDir)(), "projects");
|
|
184
|
+
const list = deps.list ?? ((dir) => fs.readdirSync(dir));
|
|
185
|
+
const head = deps.head ?? readHead;
|
|
186
|
+
let slugs;
|
|
187
|
+
try {
|
|
188
|
+
slugs = list(root);
|
|
189
|
+
}
|
|
190
|
+
catch {
|
|
191
|
+
return undefined;
|
|
192
|
+
}
|
|
193
|
+
for (const slug of slugs) {
|
|
194
|
+
const text = head(path.join(root, slug, `${sessionId}.jsonl`));
|
|
195
|
+
if (text === undefined)
|
|
196
|
+
continue;
|
|
197
|
+
for (const line of text.split("\n")) {
|
|
198
|
+
try {
|
|
199
|
+
const cwd = JSON.parse(line).cwd;
|
|
200
|
+
if (typeof cwd === "string" && cwd)
|
|
201
|
+
return cwd;
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
// A partial last line or a non-JSON line: look at the next one.
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return undefined;
|
|
209
|
+
}
|
|
210
|
+
/** The first 64 KB of a file, or undefined when it is not there. */
|
|
211
|
+
function readHead(file) {
|
|
212
|
+
let fd;
|
|
213
|
+
try {
|
|
214
|
+
fd = fs.openSync(file, "r");
|
|
215
|
+
const buf = Buffer.alloc(64 * 1024);
|
|
216
|
+
const n = fs.readSync(fd, buf, 0, buf.length, 0);
|
|
217
|
+
return buf.subarray(0, n).toString("utf8");
|
|
218
|
+
}
|
|
219
|
+
catch {
|
|
220
|
+
return undefined;
|
|
221
|
+
}
|
|
222
|
+
finally {
|
|
223
|
+
if (fd !== undefined)
|
|
224
|
+
fs.closeSync(fd);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
/** The real watch: asks `tmux -V` once, when a launch first needs it. */
|
|
228
|
+
function realExitWatch(tmuxVersion) {
|
|
229
|
+
let can;
|
|
230
|
+
return {
|
|
231
|
+
canWatch: () => (can ??= tmuxCanWatchExit(tmuxVersion())),
|
|
232
|
+
create: () => createExitCapture(),
|
|
233
|
+
read: (capture) => readExitReport(capture),
|
|
234
|
+
remove: (capture) => removeExitCapture(capture),
|
|
235
|
+
};
|
|
236
|
+
}
|