@staff0rd/assist 0.885.2 → 0.886.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/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { Command } from "commander";
|
|
|
6
6
|
// package.json
|
|
7
7
|
var package_default = {
|
|
8
8
|
name: "@staff0rd/assist",
|
|
9
|
-
version: "0.
|
|
9
|
+
version: "0.886.0",
|
|
10
10
|
type: "module",
|
|
11
11
|
main: "dist/index.js",
|
|
12
12
|
bin: {
|
|
@@ -5036,7 +5036,6 @@ function docsFeedbackPrompt({
|
|
|
5036
5036
|
// src/commands/sessions/web/docsFeedback/docsFeedbackSchema.ts
|
|
5037
5037
|
import { z as z7 } from "zod";
|
|
5038
5038
|
var docsFeedbackSchema = z7.object({
|
|
5039
|
-
sessionId: z7.string().optional(),
|
|
5040
5039
|
pageId: z7.string().min(1),
|
|
5041
5040
|
heading: z7.string().min(1),
|
|
5042
5041
|
source: z7.string().min(1),
|
|
@@ -5045,6 +5044,7 @@ var docsFeedbackSchema = z7.object({
|
|
|
5045
5044
|
});
|
|
5046
5045
|
|
|
5047
5046
|
// src/commands/sessions/web/docsFeedback/docsFeedback.ts
|
|
5047
|
+
var DOCS_DIR = "docs/guide/";
|
|
5048
5048
|
async function docsFeedback(req, res) {
|
|
5049
5049
|
allowExtensionOrigin(req, res);
|
|
5050
5050
|
const parsed = docsFeedbackSchema.safeParse(
|
|
@@ -5054,15 +5054,13 @@ async function docsFeedback(req, res) {
|
|
|
5054
5054
|
respondJson(res, 400, { error: "Invalid docs feedback body" });
|
|
5055
5055
|
return;
|
|
5056
5056
|
}
|
|
5057
|
-
const { sessionId } = parsed.data;
|
|
5058
|
-
if (!sessionId) {
|
|
5059
|
-
respondJson(res, 404, {
|
|
5060
|
-
error: "This docs preview was not started from an assist session"
|
|
5061
|
-
});
|
|
5062
|
-
return;
|
|
5063
|
-
}
|
|
5064
5057
|
const reply2 = await requestDaemonReply(
|
|
5065
|
-
{
|
|
5058
|
+
{
|
|
5059
|
+
type: "type-prompt-to-writer",
|
|
5060
|
+
file: parsed.data.source,
|
|
5061
|
+
within: DOCS_DIR,
|
|
5062
|
+
text: docsFeedbackPrompt(parsed.data)
|
|
5063
|
+
},
|
|
5066
5064
|
"type-prompt-result"
|
|
5067
5065
|
);
|
|
5068
5066
|
if (!reply2) {
|
|
@@ -14654,15 +14652,15 @@ function newestTranscriptId(dir) {
|
|
|
14654
14652
|
} catch {
|
|
14655
14653
|
return void 0;
|
|
14656
14654
|
}
|
|
14657
|
-
let
|
|
14655
|
+
let newest2;
|
|
14658
14656
|
for (const entry of entries) {
|
|
14659
14657
|
if (!entry.endsWith(".jsonl")) continue;
|
|
14660
14658
|
const modifiedAt = modifiedAtOf(path28.join(dir, entry));
|
|
14661
14659
|
if (modifiedAt === void 0) continue;
|
|
14662
|
-
if (!
|
|
14663
|
-
|
|
14660
|
+
if (!newest2 || modifiedAt > newest2.modifiedAt)
|
|
14661
|
+
newest2 = { id: path28.basename(entry, ".jsonl"), modifiedAt };
|
|
14664
14662
|
}
|
|
14665
|
-
return
|
|
14663
|
+
return newest2?.id;
|
|
14666
14664
|
}
|
|
14667
14665
|
function modifiedAtOf(filePath) {
|
|
14668
14666
|
try {
|
|
@@ -23360,14 +23358,14 @@ function loadDevlogEntries(repoName) {
|
|
|
23360
23358
|
return entries;
|
|
23361
23359
|
}
|
|
23362
23360
|
function loadAllDevlogLatestDates() {
|
|
23363
|
-
const
|
|
23361
|
+
const latest2 = /* @__PURE__ */ new Map();
|
|
23364
23362
|
readDevlogFiles((parsed) => {
|
|
23365
|
-
const existing =
|
|
23363
|
+
const existing = latest2.get(parsed.repoTag);
|
|
23366
23364
|
if (!existing || parsed.date > existing) {
|
|
23367
|
-
|
|
23365
|
+
latest2.set(parsed.repoTag, parsed.date);
|
|
23368
23366
|
}
|
|
23369
23367
|
});
|
|
23370
|
-
return
|
|
23368
|
+
return latest2;
|
|
23371
23369
|
}
|
|
23372
23370
|
|
|
23373
23371
|
// src/commands/devlog/shared.ts
|
|
@@ -44391,6 +44389,133 @@ function broadcastSessions(sessions, clients, linkedSessions = [], active) {
|
|
|
44391
44389
|
broadcast(peers, { type: "sessions", sessions: local, active: {} });
|
|
44392
44390
|
}
|
|
44393
44391
|
|
|
44392
|
+
// src/commands/sessions/daemon/lastWriteTimes.ts
|
|
44393
|
+
import { readFile as readFile9 } from "fs/promises";
|
|
44394
|
+
|
|
44395
|
+
// src/commands/sessions/shared/asRecord.ts
|
|
44396
|
+
function asRecord(value) {
|
|
44397
|
+
return value && typeof value === "object" ? value : null;
|
|
44398
|
+
}
|
|
44399
|
+
|
|
44400
|
+
// src/commands/sessions/shared/writtenFilePaths.ts
|
|
44401
|
+
var WRITE_TOOLS = /* @__PURE__ */ new Set(["Write", "Edit", "MultiEdit", "NotebookEdit"]);
|
|
44402
|
+
function writtenFilePaths(entry) {
|
|
44403
|
+
if (entry.type !== "assistant") return [];
|
|
44404
|
+
const content = asRecord(entry.message)?.content;
|
|
44405
|
+
if (!Array.isArray(content)) return [];
|
|
44406
|
+
const paths = [];
|
|
44407
|
+
for (const block of content) {
|
|
44408
|
+
const b = asRecord(block);
|
|
44409
|
+
if (b?.type !== "tool_use" || !WRITE_TOOLS.has(String(b.name))) continue;
|
|
44410
|
+
const input = asRecord(b.input);
|
|
44411
|
+
const path109 = input?.file_path ?? input?.notebook_path;
|
|
44412
|
+
if (typeof path109 === "string") paths.push(path109);
|
|
44413
|
+
}
|
|
44414
|
+
return paths;
|
|
44415
|
+
}
|
|
44416
|
+
|
|
44417
|
+
// src/commands/sessions/daemon/lastWriteTimes.ts
|
|
44418
|
+
function normalise(path109) {
|
|
44419
|
+
return path109.replaceAll("\\", "/");
|
|
44420
|
+
}
|
|
44421
|
+
function latest(current, at2) {
|
|
44422
|
+
return current === void 0 || at2 > current ? at2 : current;
|
|
44423
|
+
}
|
|
44424
|
+
async function lastWriteTimes(transcriptPath2, target) {
|
|
44425
|
+
const text18 = await readFile9(transcriptPath2, "utf8").catch(() => "");
|
|
44426
|
+
const result = {};
|
|
44427
|
+
for (const line of text18.split("\n")) {
|
|
44428
|
+
if (!line.includes('"tool_use"')) continue;
|
|
44429
|
+
let entry;
|
|
44430
|
+
try {
|
|
44431
|
+
entry = JSON.parse(line);
|
|
44432
|
+
} catch {
|
|
44433
|
+
continue;
|
|
44434
|
+
}
|
|
44435
|
+
const at2 = Date.parse(String(entry.timestamp));
|
|
44436
|
+
if (Number.isNaN(at2)) continue;
|
|
44437
|
+
for (const path109 of writtenFilePaths(entry).map(normalise)) {
|
|
44438
|
+
if (path109.endsWith(`/${target.file}`))
|
|
44439
|
+
result.file = latest(result.file, at2);
|
|
44440
|
+
if (path109.includes(`/${target.within}`))
|
|
44441
|
+
result.within = latest(result.within, at2);
|
|
44442
|
+
}
|
|
44443
|
+
}
|
|
44444
|
+
return result;
|
|
44445
|
+
}
|
|
44446
|
+
|
|
44447
|
+
// src/commands/sessions/shared/findTranscriptPathSync.ts
|
|
44448
|
+
import * as fs50 from "fs";
|
|
44449
|
+
import * as path105 from "path";
|
|
44450
|
+
function projectDirForCwd(cwd) {
|
|
44451
|
+
return path105.join(claudeProjectsRoot(), projectSlug(cwd));
|
|
44452
|
+
}
|
|
44453
|
+
function transcriptPathFor(cwd, claudeSessionId) {
|
|
44454
|
+
return path105.join(projectDirForCwd(cwd), `${claudeSessionId}.jsonl`);
|
|
44455
|
+
}
|
|
44456
|
+
function findTranscriptPathSync(cwd, claudeSessionId) {
|
|
44457
|
+
const direct = transcriptPathFor(cwd, claudeSessionId);
|
|
44458
|
+
if (fs50.existsSync(direct)) return direct;
|
|
44459
|
+
const dir = projectDirForCwd(cwd);
|
|
44460
|
+
let files;
|
|
44461
|
+
try {
|
|
44462
|
+
files = fs50.readdirSync(dir);
|
|
44463
|
+
} catch {
|
|
44464
|
+
return null;
|
|
44465
|
+
}
|
|
44466
|
+
for (const file of files) {
|
|
44467
|
+
if (!file.endsWith(".jsonl")) continue;
|
|
44468
|
+
if (headContainsSessionId(path105.join(dir, file), claudeSessionId))
|
|
44469
|
+
return path105.join(dir, file);
|
|
44470
|
+
}
|
|
44471
|
+
return null;
|
|
44472
|
+
}
|
|
44473
|
+
function headContainsSessionId(filePath, claudeSessionId) {
|
|
44474
|
+
let fd;
|
|
44475
|
+
try {
|
|
44476
|
+
fd = fs50.openSync(filePath, "r");
|
|
44477
|
+
const buf = Buffer.alloc(16384);
|
|
44478
|
+
const bytesRead = fs50.readSync(fd, buf, 0, buf.length, 0);
|
|
44479
|
+
return buf.toString("utf8", 0, bytesRead).includes(claudeSessionId);
|
|
44480
|
+
} catch {
|
|
44481
|
+
return false;
|
|
44482
|
+
} finally {
|
|
44483
|
+
if (fd !== void 0) fs50.closeSync(fd);
|
|
44484
|
+
}
|
|
44485
|
+
}
|
|
44486
|
+
|
|
44487
|
+
// src/commands/sessions/daemon/resolveTranscriptPath.ts
|
|
44488
|
+
async function resolveTranscriptPath(session) {
|
|
44489
|
+
if (session.transcriptPath) return session.transcriptPath;
|
|
44490
|
+
if (!session.claudeSessionId) return null;
|
|
44491
|
+
const direct = session.cwd ? findTranscriptPathSync(session.cwd, session.claudeSessionId) : null;
|
|
44492
|
+
const filePath = direct ?? await findSessionJsonlPath(session.claudeSessionId);
|
|
44493
|
+
if (filePath) session.transcriptPath = filePath;
|
|
44494
|
+
return filePath;
|
|
44495
|
+
}
|
|
44496
|
+
|
|
44497
|
+
// src/commands/sessions/daemon/findLastWriter.ts
|
|
44498
|
+
function newest(candidates, key) {
|
|
44499
|
+
return candidates.filter((c) => c[key] !== void 0).sort((a, b) => (b[key] ?? 0) - (a[key] ?? 0))[0];
|
|
44500
|
+
}
|
|
44501
|
+
async function findLastWriter(sessions, target) {
|
|
44502
|
+
const live = [...sessions.values()].filter(
|
|
44503
|
+
(s) => s.pty && s.status !== "done" && s.commandType !== "run"
|
|
44504
|
+
);
|
|
44505
|
+
const candidates = await Promise.all(
|
|
44506
|
+
live.map(async (session) => {
|
|
44507
|
+
const transcript = await resolveTranscriptPath(session);
|
|
44508
|
+
if (!transcript) return { id: session.id };
|
|
44509
|
+
return { id: session.id, ...await lastWriteTimes(transcript, target) };
|
|
44510
|
+
})
|
|
44511
|
+
);
|
|
44512
|
+
const writer = newest(candidates, "file") ?? newest(candidates, "within");
|
|
44513
|
+
daemonLog(
|
|
44514
|
+
`last writer of ${target.file} (within ${target.within}): ${writer ? `session ${writer.id}` : "none"} of ${live.length} live session(s)`
|
|
44515
|
+
);
|
|
44516
|
+
return writer?.id;
|
|
44517
|
+
}
|
|
44518
|
+
|
|
44394
44519
|
// src/commands/sessions/daemon/releaseViewer.ts
|
|
44395
44520
|
function releaseViewer(sessions, viewerId) {
|
|
44396
44521
|
let released = false;
|
|
@@ -44679,6 +44804,15 @@ var SessionIo = class {
|
|
|
44679
44804
|
(target, data) => this.write(target, data, {})
|
|
44680
44805
|
);
|
|
44681
44806
|
}
|
|
44807
|
+
async typePromptToLastWriter(target, text18) {
|
|
44808
|
+
const id = await findLastWriter(this.sessions, target);
|
|
44809
|
+
if (!id)
|
|
44810
|
+
return {
|
|
44811
|
+
refused: `No live Claude session has written ${target.file} or anything in ${target.within}`
|
|
44812
|
+
};
|
|
44813
|
+
const refused = this.typePrompt(id, text18);
|
|
44814
|
+
return refused ? { refused } : id;
|
|
44815
|
+
}
|
|
44682
44816
|
resize(id, cols, rows, viewer) {
|
|
44683
44817
|
resizeSession(this.sessions, id, cols, rows, {
|
|
44684
44818
|
...viewer,
|
|
@@ -44815,26 +44949,26 @@ function sessionBase(id, status2) {
|
|
|
44815
44949
|
}
|
|
44816
44950
|
|
|
44817
44951
|
// src/commands/sessions/daemon/spawnPty.ts
|
|
44818
|
-
import { existsSync as
|
|
44952
|
+
import { existsSync as existsSync88 } from "fs";
|
|
44819
44953
|
import * as pty from "node-pty";
|
|
44820
44954
|
|
|
44821
44955
|
// src/commands/sessions/daemon/ensureSpawnHelperExecutable.ts
|
|
44822
|
-
import { chmodSync, existsSync as
|
|
44956
|
+
import { chmodSync, existsSync as existsSync87, statSync as statSync15 } from "fs";
|
|
44823
44957
|
import { createRequire as createRequire3 } from "module";
|
|
44824
|
-
import
|
|
44958
|
+
import path106 from "path";
|
|
44825
44959
|
var require4 = createRequire3(import.meta.url);
|
|
44826
44960
|
var ensured = false;
|
|
44827
44961
|
function ensureSpawnHelperExecutable() {
|
|
44828
44962
|
if (ensured || process.platform !== "darwin") return;
|
|
44829
44963
|
ensured = true;
|
|
44830
|
-
const ptyRoot =
|
|
44831
|
-
const helper =
|
|
44964
|
+
const ptyRoot = path106.join(path106.dirname(require4.resolve("node-pty")), "..");
|
|
44965
|
+
const helper = path106.join(
|
|
44832
44966
|
ptyRoot,
|
|
44833
44967
|
"prebuilds",
|
|
44834
44968
|
`${process.platform}-${process.arch}`,
|
|
44835
44969
|
"spawn-helper"
|
|
44836
44970
|
);
|
|
44837
|
-
if (!
|
|
44971
|
+
if (!existsSync87(helper)) return;
|
|
44838
44972
|
const mode = statSync15(helper).mode;
|
|
44839
44973
|
if ((mode & 73) === 0) chmodSync(helper, mode | 493);
|
|
44840
44974
|
}
|
|
@@ -44890,7 +45024,7 @@ function spawnPty(args, cwd, sessionId, extraEnv) {
|
|
|
44890
45024
|
});
|
|
44891
45025
|
}
|
|
44892
45026
|
function refuseMissingCwd(cwd, sessionId) {
|
|
44893
|
-
if (!cwd ||
|
|
45027
|
+
if (!cwd || existsSync88(cwd)) return;
|
|
44894
45028
|
daemonLog(
|
|
44895
45029
|
`${sessionId ? `session ${sessionId}` : "pty"} not spawned: working directory ${cwd} no longer exists`
|
|
44896
45030
|
);
|
|
@@ -44975,19 +45109,19 @@ function serverRunMeta(runName, cwd) {
|
|
|
44975
45109
|
}
|
|
44976
45110
|
|
|
44977
45111
|
// src/commands/sessions/daemon/readDesignSystemPrompt.ts
|
|
44978
|
-
import * as
|
|
44979
|
-
import * as
|
|
45112
|
+
import * as fs51 from "fs";
|
|
45113
|
+
import * as path107 from "path";
|
|
44980
45114
|
import { fileURLToPath as fileURLToPath10 } from "url";
|
|
44981
45115
|
var __filename5 = fileURLToPath10(import.meta.url);
|
|
44982
|
-
var __dirname6 =
|
|
45116
|
+
var __dirname6 = path107.dirname(__filename5);
|
|
44983
45117
|
function readDesignSystemPrompt() {
|
|
44984
|
-
const promptPath =
|
|
45118
|
+
const promptPath = path107.join(
|
|
44985
45119
|
__dirname6,
|
|
44986
45120
|
"..",
|
|
44987
45121
|
"claude",
|
|
44988
45122
|
"design-system-prompt.md"
|
|
44989
45123
|
);
|
|
44990
|
-
return
|
|
45124
|
+
return fs51.readFileSync(promptPath, "utf8");
|
|
44991
45125
|
}
|
|
44992
45126
|
|
|
44993
45127
|
// src/commands/sessions/daemon/spawnClaude.ts
|
|
@@ -45060,7 +45194,7 @@ function createRunSession(id, { runName, runArgs, cwd, meta }) {
|
|
|
45060
45194
|
}
|
|
45061
45195
|
|
|
45062
45196
|
// src/commands/sessions/daemon/autoUpdate/autoUpdateControl.ts
|
|
45063
|
-
import { existsSync as
|
|
45197
|
+
import { existsSync as existsSync89, rmSync as rmSync11, writeFileSync as writeFileSync54 } from "fs";
|
|
45064
45198
|
var paused;
|
|
45065
45199
|
var wake;
|
|
45066
45200
|
function persist2(value) {
|
|
@@ -45072,7 +45206,7 @@ function persist2(value) {
|
|
|
45072
45206
|
}
|
|
45073
45207
|
var autoUpdateControl = {
|
|
45074
45208
|
paused: () => {
|
|
45075
|
-
paused ??=
|
|
45209
|
+
paused ??= existsSync89(daemonPaths.autoUpdatePaused);
|
|
45076
45210
|
return paused;
|
|
45077
45211
|
},
|
|
45078
45212
|
setPaused: (value) => {
|
|
@@ -45515,17 +45649,17 @@ function setStatus2(session, newStatus) {
|
|
|
45515
45649
|
}
|
|
45516
45650
|
|
|
45517
45651
|
// src/commands/sessions/daemon/worktree/reapWorktree.ts
|
|
45518
|
-
import { existsSync as
|
|
45652
|
+
import { existsSync as existsSync91 } from "fs";
|
|
45519
45653
|
import { basename as basename31 } from "path";
|
|
45520
45654
|
|
|
45521
45655
|
// src/commands/sessions/daemon/worktree/deleteStrandedTree.ts
|
|
45522
|
-
import { existsSync as
|
|
45523
|
-
import { join as
|
|
45656
|
+
import { existsSync as existsSync90 } from "fs";
|
|
45657
|
+
import { join as join106 } from "path";
|
|
45524
45658
|
|
|
45525
45659
|
// src/commands/sessions/daemon/worktree/deleteTreeDirectly.ts
|
|
45526
45660
|
import { statSync as statSync16 } from "fs";
|
|
45527
45661
|
import { rm as rm3 } from "fs/promises";
|
|
45528
|
-
import { join as
|
|
45662
|
+
import { join as join105 } from "path";
|
|
45529
45663
|
async function deleteTreeDirectly(clone, worktreePath, why) {
|
|
45530
45664
|
if (holdsAGitDirectoryRatherThanALink(worktreePath)) {
|
|
45531
45665
|
const refusal = "it is a clone of its own, not a linked worktree";
|
|
@@ -45553,7 +45687,7 @@ async function deleteTreeDirectly(clone, worktreePath, why) {
|
|
|
45553
45687
|
return { removed: true };
|
|
45554
45688
|
}
|
|
45555
45689
|
function holdsAGitDirectoryRatherThanALink(worktreePath) {
|
|
45556
|
-
return statSync16(
|
|
45690
|
+
return statSync16(join105(worktreePath, ".git"), {
|
|
45557
45691
|
throwIfNoEntry: false
|
|
45558
45692
|
})?.isDirectory() === true;
|
|
45559
45693
|
}
|
|
@@ -45589,7 +45723,7 @@ async function deleteStrandedTree(clone, worktreePath, cause) {
|
|
|
45589
45723
|
);
|
|
45590
45724
|
}
|
|
45591
45725
|
function strandedReason(worktreePath, cause) {
|
|
45592
|
-
if (!
|
|
45726
|
+
if (!existsSync90(join106(worktreePath, ".git")))
|
|
45593
45727
|
return "its .git link is already gone";
|
|
45594
45728
|
if (/not a working tree|not a git repository/i.test(reason2(cause)))
|
|
45595
45729
|
return "git no longer recognises it as a working tree";
|
|
@@ -45641,7 +45775,7 @@ function reason3(error) {
|
|
|
45641
45775
|
|
|
45642
45776
|
// src/commands/sessions/daemon/worktree/reapWorktree.ts
|
|
45643
45777
|
async function reapWorktree(worktreePath, force = false) {
|
|
45644
|
-
if (!
|
|
45778
|
+
if (!existsSync91(worktreePath)) {
|
|
45645
45779
|
forgetWorktree(worktreePath);
|
|
45646
45780
|
daemonLog(
|
|
45647
45781
|
`worktree ${worktreePath} already gone; its record was forgotten`
|
|
@@ -45666,7 +45800,7 @@ async function reapWorktree(worktreePath, force = false) {
|
|
|
45666
45800
|
}
|
|
45667
45801
|
function owningClone(worktreePath) {
|
|
45668
45802
|
const recorded = worktreeAttributionIncludingReaped(worktreePath)?.clone;
|
|
45669
|
-
if (recorded &&
|
|
45803
|
+
if (recorded && existsSync91(recorded)) return recorded;
|
|
45670
45804
|
const detected = mainWorktree(worktreePath);
|
|
45671
45805
|
if (detected) return detected;
|
|
45672
45806
|
daemonLog(
|
|
@@ -45795,12 +45929,12 @@ function closeGateApplies(sessions, session) {
|
|
|
45795
45929
|
}
|
|
45796
45930
|
|
|
45797
45931
|
// src/commands/sessions/daemon/worktree/liveProcessesInTree.ts
|
|
45798
|
-
import { readdirSync as
|
|
45932
|
+
import { readdirSync as readdirSync25, readlinkSync } from "fs";
|
|
45799
45933
|
import { sep as sep4 } from "path";
|
|
45800
45934
|
function liveProcessesInTree(treePath, procRoot = "/proc") {
|
|
45801
45935
|
let entries;
|
|
45802
45936
|
try {
|
|
45803
|
-
entries =
|
|
45937
|
+
entries = readdirSync25(procRoot);
|
|
45804
45938
|
} catch {
|
|
45805
45939
|
return [];
|
|
45806
45940
|
}
|
|
@@ -45867,12 +46001,12 @@ async function closeBlockReason(sessionId, tree) {
|
|
|
45867
46001
|
}
|
|
45868
46002
|
|
|
45869
46003
|
// src/commands/sessions/daemon/worktree/watchGitState.ts
|
|
45870
|
-
import { existsSync as
|
|
46004
|
+
import { existsSync as existsSync92, watch } from "fs";
|
|
45871
46005
|
var DEBOUNCE_MS = 500;
|
|
45872
46006
|
var POLL_MS3 = 3e4;
|
|
45873
46007
|
function watchGitState(cwd, onChange) {
|
|
45874
46008
|
const common = gitCommonDir(cwd);
|
|
45875
|
-
if (!common || !
|
|
46009
|
+
if (!common || !existsSync92(common)) return void 0;
|
|
45876
46010
|
const watchers = [
|
|
45877
46011
|
watchGitDir(common, onChange),
|
|
45878
46012
|
pollGitState(cwd, onChange)
|
|
@@ -46531,10 +46665,10 @@ function emitSessionOutput(session, clients, data) {
|
|
|
46531
46665
|
}
|
|
46532
46666
|
|
|
46533
46667
|
// src/commands/sessions/daemon/exitReason.ts
|
|
46534
|
-
import { existsSync as
|
|
46668
|
+
import { existsSync as existsSync93 } from "fs";
|
|
46535
46669
|
import { resolve as resolve29 } from "path";
|
|
46536
46670
|
function exitDetail(session) {
|
|
46537
|
-
if (session.cwd && !
|
|
46671
|
+
if (session.cwd && !existsSync93(session.cwd))
|
|
46538
46672
|
return `working directory ${session.cwd} no longer exists`;
|
|
46539
46673
|
return missingRunConfigCwd(session);
|
|
46540
46674
|
}
|
|
@@ -46548,7 +46682,7 @@ function missingRunConfigCwd(session) {
|
|
|
46548
46682
|
const config = resolveRunConfig(session.runName, dir);
|
|
46549
46683
|
if (!config?.cwd) return void 0;
|
|
46550
46684
|
const configured = resolve29(runConfigBaseDirFrom(dir), config.cwd);
|
|
46551
|
-
if (
|
|
46685
|
+
if (existsSync93(configured)) return void 0;
|
|
46552
46686
|
return `run config "${config.name}": cwd ${configured} does not exist`;
|
|
46553
46687
|
}
|
|
46554
46688
|
|
|
@@ -46596,7 +46730,7 @@ function handleRefusedRun(session, exitCode, onStatusChange) {
|
|
|
46596
46730
|
}
|
|
46597
46731
|
|
|
46598
46732
|
// src/commands/sessions/daemon/watchActivity.ts
|
|
46599
|
-
import { existsSync as
|
|
46733
|
+
import { existsSync as existsSync94, mkdirSync as mkdirSync36, watch as watch2 } from "fs";
|
|
46600
46734
|
import { dirname as dirname44 } from "path";
|
|
46601
46735
|
|
|
46602
46736
|
// src/commands/sessions/daemon/applyActivityToSession.ts
|
|
@@ -46682,7 +46816,7 @@ function watchActivity(session, notify2, onClaudeSessionId) {
|
|
|
46682
46816
|
if (timer) clearTimeout(timer);
|
|
46683
46817
|
timer = setTimeout(read3, DEBOUNCE_MS2);
|
|
46684
46818
|
});
|
|
46685
|
-
if (
|
|
46819
|
+
if (existsSync94(path109)) read3();
|
|
46686
46820
|
}
|
|
46687
46821
|
function refreshActivity(session) {
|
|
46688
46822
|
if (session.commandType !== "assist" || !session.cwd) return;
|
|
@@ -46762,7 +46896,7 @@ function reportSilentFailure(session, clients) {
|
|
|
46762
46896
|
}
|
|
46763
46897
|
|
|
46764
46898
|
// src/commands/sessions/shared/codex/resolveCodexSessionId.ts
|
|
46765
|
-
import * as
|
|
46899
|
+
import * as fs52 from "fs";
|
|
46766
46900
|
var META_LINES = 5;
|
|
46767
46901
|
async function resolveCodexSessionId(cwd, sinceMs) {
|
|
46768
46902
|
if (!cwd) return null;
|
|
@@ -46791,7 +46925,7 @@ async function startedIn(file, cwd, sinceMs) {
|
|
|
46791
46925
|
}
|
|
46792
46926
|
async function touchedSince(file, sinceMs) {
|
|
46793
46927
|
try {
|
|
46794
|
-
return (await
|
|
46928
|
+
return (await fs52.promises.stat(file)).mtimeMs >= sinceMs;
|
|
46795
46929
|
} catch {
|
|
46796
46930
|
return false;
|
|
46797
46931
|
}
|
|
@@ -46825,46 +46959,6 @@ function bindCodexSession(session, notify2) {
|
|
|
46825
46959
|
// src/commands/sessions/daemon/watchTranscript.ts
|
|
46826
46960
|
import { watch as watch3 } from "fs";
|
|
46827
46961
|
|
|
46828
|
-
// src/commands/sessions/shared/findTranscriptPathSync.ts
|
|
46829
|
-
import * as fs52 from "fs";
|
|
46830
|
-
import * as path107 from "path";
|
|
46831
|
-
function projectDirForCwd(cwd) {
|
|
46832
|
-
return path107.join(claudeProjectsRoot(), projectSlug(cwd));
|
|
46833
|
-
}
|
|
46834
|
-
function transcriptPathFor(cwd, claudeSessionId) {
|
|
46835
|
-
return path107.join(projectDirForCwd(cwd), `${claudeSessionId}.jsonl`);
|
|
46836
|
-
}
|
|
46837
|
-
function findTranscriptPathSync(cwd, claudeSessionId) {
|
|
46838
|
-
const direct = transcriptPathFor(cwd, claudeSessionId);
|
|
46839
|
-
if (fs52.existsSync(direct)) return direct;
|
|
46840
|
-
const dir = projectDirForCwd(cwd);
|
|
46841
|
-
let files;
|
|
46842
|
-
try {
|
|
46843
|
-
files = fs52.readdirSync(dir);
|
|
46844
|
-
} catch {
|
|
46845
|
-
return null;
|
|
46846
|
-
}
|
|
46847
|
-
for (const file of files) {
|
|
46848
|
-
if (!file.endsWith(".jsonl")) continue;
|
|
46849
|
-
if (headContainsSessionId(path107.join(dir, file), claudeSessionId))
|
|
46850
|
-
return path107.join(dir, file);
|
|
46851
|
-
}
|
|
46852
|
-
return null;
|
|
46853
|
-
}
|
|
46854
|
-
function headContainsSessionId(filePath, claudeSessionId) {
|
|
46855
|
-
let fd;
|
|
46856
|
-
try {
|
|
46857
|
-
fd = fs52.openSync(filePath, "r");
|
|
46858
|
-
const buf = Buffer.alloc(16384);
|
|
46859
|
-
const bytesRead = fs52.readSync(fd, buf, 0, buf.length, 0);
|
|
46860
|
-
return buf.toString("utf8", 0, bytesRead).includes(claudeSessionId);
|
|
46861
|
-
} catch {
|
|
46862
|
-
return false;
|
|
46863
|
-
} finally {
|
|
46864
|
-
if (fd !== void 0) fs52.closeSync(fd);
|
|
46865
|
-
}
|
|
46866
|
-
}
|
|
46867
|
-
|
|
46868
46962
|
// src/commands/sessions/daemon/ensureProjectDirExists.ts
|
|
46869
46963
|
import { mkdirSync as mkdirSync37 } from "fs";
|
|
46870
46964
|
function ensureProjectDirExists(dir, sessionId) {
|
|
@@ -46913,16 +47007,16 @@ function lastDecisiveIndex(events) {
|
|
|
46913
47007
|
var INTERRUPT_PREFIX = "[Request interrupted";
|
|
46914
47008
|
var TASK_NOTIFICATION = "<task-notification>";
|
|
46915
47009
|
function normalizeUser(entry) {
|
|
46916
|
-
const content =
|
|
47010
|
+
const content = asRecord2(entry.message)?.content;
|
|
46917
47011
|
if (typeof content === "string") return normalizeUserText(content);
|
|
46918
47012
|
if (!Array.isArray(content)) return { kind: "user" };
|
|
46919
|
-
if (content.length === 1 &&
|
|
46920
|
-
return normalizeUserText(
|
|
47013
|
+
if (content.length === 1 && asRecord2(content[0])?.type === "text")
|
|
47014
|
+
return normalizeUserText(asRecord2(content[0])?.text);
|
|
46921
47015
|
const toolResultIds = [];
|
|
46922
47016
|
let hasInterrupt = false;
|
|
46923
47017
|
let hasNonToolResult = false;
|
|
46924
47018
|
for (const block of content) {
|
|
46925
|
-
const b =
|
|
47019
|
+
const b = asRecord2(block);
|
|
46926
47020
|
if (!b) continue;
|
|
46927
47021
|
if (b.type === "tool_result") {
|
|
46928
47022
|
if (typeof b.tool_use_id === "string") toolResultIds.push(b.tool_use_id);
|
|
@@ -46936,7 +47030,7 @@ function normalizeUser(entry) {
|
|
|
46936
47030
|
if (hasNonToolResult) return { kind: "user" };
|
|
46937
47031
|
return { kind: "toolResult", ids: toolResultIds };
|
|
46938
47032
|
}
|
|
46939
|
-
function
|
|
47033
|
+
function asRecord2(value) {
|
|
46940
47034
|
return value && typeof value === "object" ? value : null;
|
|
46941
47035
|
}
|
|
46942
47036
|
function normalizeUserText(text18) {
|
|
@@ -46960,13 +47054,13 @@ function normalizeEntry(entry) {
|
|
|
46960
47054
|
return null;
|
|
46961
47055
|
}
|
|
46962
47056
|
function normalizeAssistant(entry) {
|
|
46963
|
-
const message3 =
|
|
47057
|
+
const message3 = asRecord3(entry.message);
|
|
46964
47058
|
const stopReason = typeof message3?.stop_reason === "string" ? message3.stop_reason : null;
|
|
46965
47059
|
const content = message3?.content;
|
|
46966
47060
|
const toolUses = [];
|
|
46967
47061
|
if (Array.isArray(content))
|
|
46968
47062
|
for (const block of content) {
|
|
46969
|
-
const b =
|
|
47063
|
+
const b = asRecord3(block);
|
|
46970
47064
|
if (b?.type === "tool_use")
|
|
46971
47065
|
toolUses.push({
|
|
46972
47066
|
id: typeof b.id === "string" ? b.id : "",
|
|
@@ -46975,7 +47069,7 @@ function normalizeAssistant(entry) {
|
|
|
46975
47069
|
}
|
|
46976
47070
|
return { kind: "assistant", stopReason, toolUses };
|
|
46977
47071
|
}
|
|
46978
|
-
function
|
|
47072
|
+
function asRecord3(value) {
|
|
46979
47073
|
return value && typeof value === "object" ? value : null;
|
|
46980
47074
|
}
|
|
46981
47075
|
|
|
@@ -47028,15 +47122,15 @@ function renderUserPrompt(entry, maxLength = MAX_LENGTH) {
|
|
|
47028
47122
|
return message3 ? cap(message3, maxLength) : void 0;
|
|
47029
47123
|
}
|
|
47030
47124
|
function isTaskNotification(entry) {
|
|
47031
|
-
return
|
|
47125
|
+
return asRecord4(entry.origin)?.kind === "task-notification";
|
|
47032
47126
|
}
|
|
47033
47127
|
function promptTextOrNull(entry) {
|
|
47034
|
-
const content =
|
|
47128
|
+
const content = asRecord4(entry.message)?.content;
|
|
47035
47129
|
if (typeof content === "string") return isInterrupt(content) ? null : content;
|
|
47036
47130
|
if (!Array.isArray(content)) return null;
|
|
47037
47131
|
const parts = [];
|
|
47038
47132
|
for (const block of content) {
|
|
47039
|
-
const b =
|
|
47133
|
+
const b = asRecord4(block);
|
|
47040
47134
|
if (b?.type !== "text") continue;
|
|
47041
47135
|
const text18 = typeof b.text === "string" ? b.text : "";
|
|
47042
47136
|
if (isInterrupt(text18)) return null;
|
|
@@ -47050,7 +47144,7 @@ function cap(message3, maxLength) {
|
|
|
47050
47144
|
function isInterrupt(value) {
|
|
47051
47145
|
return value.trimStart().startsWith(INTERRUPT_PREFIX2);
|
|
47052
47146
|
}
|
|
47053
|
-
function
|
|
47147
|
+
function asRecord4(value) {
|
|
47054
47148
|
return value && typeof value === "object" ? value : null;
|
|
47055
47149
|
}
|
|
47056
47150
|
|
|
@@ -47137,16 +47231,6 @@ function transcriptTailFingerprint(entries) {
|
|
|
47137
47231
|
return null;
|
|
47138
47232
|
}
|
|
47139
47233
|
|
|
47140
|
-
// src/commands/sessions/daemon/resolveTranscriptPath.ts
|
|
47141
|
-
async function resolveTranscriptPath(session) {
|
|
47142
|
-
if (session.transcriptPath) return session.transcriptPath;
|
|
47143
|
-
if (!session.claudeSessionId) return null;
|
|
47144
|
-
const direct = session.cwd ? findTranscriptPathSync(session.cwd, session.claudeSessionId) : null;
|
|
47145
|
-
const filePath = direct ?? await findSessionJsonlPath(session.claudeSessionId);
|
|
47146
|
-
if (filePath) session.transcriptPath = filePath;
|
|
47147
|
-
return filePath;
|
|
47148
|
-
}
|
|
47149
|
-
|
|
47150
47234
|
// src/commands/sessions/daemon/reconcileTranscriptStatus.ts
|
|
47151
47235
|
function updateLastUserMessage(session, entries, notify2) {
|
|
47152
47236
|
const message3 = extractLastUserMessage(entries);
|
|
@@ -48328,22 +48412,17 @@ function daemonRestartPrompt(backgroundTaskIds) {
|
|
|
48328
48412
|
return `${preamble} It killed ${backgroundTaskIds.length} background task(s) that were still running (${backgroundTaskIds.join(", ")}); their output files end where the kill landed, with no exit code. Treat them as killed by the restart, not as interrupted by the user, and restart any of them that should still be running.`;
|
|
48329
48413
|
}
|
|
48330
48414
|
|
|
48331
|
-
// src/commands/sessions/shared/asRecord.ts
|
|
48332
|
-
function asRecord4(value) {
|
|
48333
|
-
return value && typeof value === "object" ? value : null;
|
|
48334
|
-
}
|
|
48335
|
-
|
|
48336
48415
|
// src/commands/sessions/shared/deliberatelyStoppedTaskIds.ts
|
|
48337
48416
|
var STOP_TOOLS = /* @__PURE__ */ new Set(["KillShell", "KillBash", "TaskStop"]);
|
|
48338
48417
|
function deliberatelyStoppedTaskIds(entry) {
|
|
48339
48418
|
if (entry.type !== "assistant") return [];
|
|
48340
|
-
const content =
|
|
48419
|
+
const content = asRecord(entry.message)?.content;
|
|
48341
48420
|
if (!Array.isArray(content)) return [];
|
|
48342
48421
|
const ids = [];
|
|
48343
48422
|
for (const block of content) {
|
|
48344
|
-
const b =
|
|
48423
|
+
const b = asRecord(block);
|
|
48345
48424
|
if (b?.type !== "tool_use" || !STOP_TOOLS.has(String(b.name))) continue;
|
|
48346
|
-
const input =
|
|
48425
|
+
const input = asRecord(b.input);
|
|
48347
48426
|
const id = input?.task_id ?? input?.shell_id ?? input?.bash_id;
|
|
48348
48427
|
if (typeof id === "string") ids.push(id);
|
|
48349
48428
|
}
|
|
@@ -48365,7 +48444,7 @@ function notifiedTasks(entry) {
|
|
|
48365
48444
|
return tasks;
|
|
48366
48445
|
}
|
|
48367
48446
|
function taskNotificationText(entry) {
|
|
48368
|
-
const content =
|
|
48447
|
+
const content = asRecord(entry.message)?.content ?? entry.content;
|
|
48369
48448
|
return typeof content === "string" && content.includes("<task-notification>") ? content : void 0;
|
|
48370
48449
|
}
|
|
48371
48450
|
|
|
@@ -48393,7 +48472,7 @@ function killedTaskIds(entry) {
|
|
|
48393
48472
|
return notifiedTasks(entry).filter(({ status: status2 }) => status2 && KILLED_STATUSES.has(status2)).map(({ id }) => id);
|
|
48394
48473
|
}
|
|
48395
48474
|
function startedTaskId(entry) {
|
|
48396
|
-
const result =
|
|
48475
|
+
const result = asRecord(entry.toolUseResult);
|
|
48397
48476
|
return typeof result?.backgroundTaskId === "string" ? result.backgroundTaskId : void 0;
|
|
48398
48477
|
}
|
|
48399
48478
|
function selfFinishedTaskIds(entry) {
|
|
@@ -50845,6 +50924,21 @@ var handleTypePrompt = (client, m, d) => {
|
|
|
50845
50924
|
});
|
|
50846
50925
|
};
|
|
50847
50926
|
|
|
50927
|
+
// src/commands/sessions/daemon/handleTypePromptToWriter.ts
|
|
50928
|
+
var handleTypePromptToWriter = (client, m, d) => {
|
|
50929
|
+
const target = { file: String(d.file), within: String(d.within) };
|
|
50930
|
+
daemonLog(`type-prompt-to-writer received: file=${target.file}`);
|
|
50931
|
+
m.io.typePromptToLastWriter(target, String(d.text ?? "")).then((result) => {
|
|
50932
|
+
if (typeof result !== "string")
|
|
50933
|
+
daemonLog(`type-prompt-to-writer refused: ${result.refused}`);
|
|
50934
|
+
sendTo(client, {
|
|
50935
|
+
type: "type-prompt-result",
|
|
50936
|
+
ok: typeof result === "string",
|
|
50937
|
+
message: typeof result === "string" ? `Sent to assist session ${result}, the last to write ${target.file}` : result.refused
|
|
50938
|
+
});
|
|
50939
|
+
});
|
|
50940
|
+
};
|
|
50941
|
+
|
|
50848
50942
|
// src/commands/sessions/shared/parseTranscript.ts
|
|
50849
50943
|
import * as fs57 from "fs";
|
|
50850
50944
|
|
|
@@ -51177,6 +51271,7 @@ var messageHandlers = {
|
|
|
51177
51271
|
"codex-usage": handleCodexUsage,
|
|
51178
51272
|
...viewerHandlers,
|
|
51179
51273
|
"type-prompt": handleTypePrompt,
|
|
51274
|
+
"type-prompt-to-writer": handleTypePromptToWriter,
|
|
51180
51275
|
retry: routed((client, m, d) => {
|
|
51181
51276
|
const conflict = m.retrySession(d.sessionId, d.replace === true);
|
|
51182
51277
|
if (conflict)
|