@staff0rd/assist 0.472.0 → 0.474.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/README.md +1 -1
- package/dist/commands/sessions/web/bundle.js +377 -377
- package/dist/index.js +81 -54
- package/package.json +1 -1
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.474.0",
|
|
10
10
|
type: "module",
|
|
11
11
|
main: "dist/index.js",
|
|
12
12
|
bin: {
|
|
@@ -28607,6 +28607,24 @@ function logSpawnedSession(session) {
|
|
|
28607
28607
|
);
|
|
28608
28608
|
}
|
|
28609
28609
|
|
|
28610
|
+
// src/commands/sessions/shared/sessionTitlePrompt.ts
|
|
28611
|
+
function sessionTitlePrompt(session) {
|
|
28612
|
+
if (session.commandType === "claude")
|
|
28613
|
+
return session.initialPrompt?.trim() || void 0;
|
|
28614
|
+
if (session.commandType !== "assist") return void 0;
|
|
28615
|
+
if (!isDraftCommand(session.assistArgs?.[0])) return void 0;
|
|
28616
|
+
return assistPromptArg(session.assistArgs);
|
|
28617
|
+
}
|
|
28618
|
+
function assistPromptArg(args) {
|
|
28619
|
+
const rest = args?.slice(1).filter((a) => !a.startsWith("--"));
|
|
28620
|
+
const text17 = rest?.[rest.length - 1]?.trim();
|
|
28621
|
+
if (!text17 || isBacklogItemId(text17)) return void 0;
|
|
28622
|
+
return text17;
|
|
28623
|
+
}
|
|
28624
|
+
function isBacklogItemId(text17) {
|
|
28625
|
+
return /^\d+$/.test(text17);
|
|
28626
|
+
}
|
|
28627
|
+
|
|
28610
28628
|
// src/commands/sessions/daemon/generateSessionTitle.ts
|
|
28611
28629
|
import { execFile as execFile9 } from "child_process";
|
|
28612
28630
|
import { promisify as promisify8 } from "util";
|
|
@@ -28640,29 +28658,10 @@ function buildPrompt3(prompt) {
|
|
|
28640
28658
|
].join("\n");
|
|
28641
28659
|
}
|
|
28642
28660
|
|
|
28643
|
-
// src/commands/sessions/
|
|
28644
|
-
function
|
|
28645
|
-
if (session.
|
|
28646
|
-
|
|
28647
|
-
if (session.commandType !== "assist") return void 0;
|
|
28648
|
-
if (!isDraftCommand(session.assistArgs?.[0])) return void 0;
|
|
28649
|
-
return assistPromptArg(session.assistArgs);
|
|
28650
|
-
}
|
|
28651
|
-
function assistPromptArg(args) {
|
|
28652
|
-
const rest = args?.slice(1).filter((a) => !a.startsWith("--"));
|
|
28653
|
-
const text17 = rest?.[rest.length - 1]?.trim();
|
|
28654
|
-
if (!text17 || isBacklogItemId(text17)) return void 0;
|
|
28655
|
-
return text17;
|
|
28656
|
-
}
|
|
28657
|
-
function isBacklogItemId(text17) {
|
|
28658
|
-
return /^\d+$/.test(text17);
|
|
28659
|
-
}
|
|
28660
|
-
|
|
28661
|
-
// src/commands/sessions/daemon/startSessionTitleGeneration.ts
|
|
28662
|
-
function startSessionTitleGeneration(session, notify2) {
|
|
28663
|
-
if (!session || session.generatedTitle) return;
|
|
28664
|
-
const prompt = sessionTitlePrompt(session);
|
|
28665
|
-
if (!prompt) return;
|
|
28661
|
+
// src/commands/sessions/daemon/runSessionTitleGeneration.ts
|
|
28662
|
+
function runSessionTitleGeneration(session, prompt, notify2) {
|
|
28663
|
+
if (session.generatedTitle || session.titleGenerationStarted) return;
|
|
28664
|
+
session.titleGenerationStarted = true;
|
|
28666
28665
|
void generateSessionTitle(prompt).then((generated) => {
|
|
28667
28666
|
session.generatedTitle = generated ?? singleLine(prompt);
|
|
28668
28667
|
daemonLog(
|
|
@@ -28677,6 +28676,15 @@ function singleLine(prompt) {
|
|
|
28677
28676
|
return prompt.replace(/\s+/g, " ").trim().slice(0, SESSION_TITLE_MAX_LENGTH);
|
|
28678
28677
|
}
|
|
28679
28678
|
|
|
28679
|
+
// src/commands/sessions/daemon/startSessionTitleGeneration.ts
|
|
28680
|
+
function startSessionTitleGeneration(session, notify2) {
|
|
28681
|
+
if (!session || session.generatedTitle || session.titleGenerationStarted)
|
|
28682
|
+
return;
|
|
28683
|
+
const prompt = sessionTitlePrompt(session);
|
|
28684
|
+
if (!prompt) return;
|
|
28685
|
+
runSessionTitleGeneration(session, prompt, notify2);
|
|
28686
|
+
}
|
|
28687
|
+
|
|
28680
28688
|
// src/commands/sessions/daemon/emitSessionOutput.ts
|
|
28681
28689
|
var MAX_SCROLLBACK = 256 * 1024;
|
|
28682
28690
|
function emitSessionOutput(session, clients, data) {
|
|
@@ -29108,9 +29116,42 @@ async function reconcileTranscriptStatus(session, onStatusChange) {
|
|
|
29108
29116
|
onStatusChange(session, derived);
|
|
29109
29117
|
}
|
|
29110
29118
|
|
|
29119
|
+
// src/commands/sessions/summarise/extractFirstUserMessage.ts
|
|
29120
|
+
function extractFirstUserMessage(filePath) {
|
|
29121
|
+
for (const text17 of iterateUserMessages(filePath)) {
|
|
29122
|
+
return truncate3(text17);
|
|
29123
|
+
}
|
|
29124
|
+
return void 0;
|
|
29125
|
+
}
|
|
29126
|
+
function truncate3(text17, maxChars = 500) {
|
|
29127
|
+
const trimmed = text17.trim();
|
|
29128
|
+
if (trimmed.length <= maxChars) return trimmed;
|
|
29129
|
+
return `${trimmed.slice(0, maxChars)}\u2026`;
|
|
29130
|
+
}
|
|
29131
|
+
|
|
29132
|
+
// src/commands/sessions/daemon/startTranscriptTitleGeneration.ts
|
|
29133
|
+
function startTranscriptTitleGeneration(session, notify2) {
|
|
29134
|
+
if (session.commandType !== "claude") return;
|
|
29135
|
+
if (session.generatedTitle || session.titleGenerationStarted) return;
|
|
29136
|
+
if (session.initialPrompt?.trim()) return;
|
|
29137
|
+
const filePath = transcriptPath(session);
|
|
29138
|
+
if (!filePath) return;
|
|
29139
|
+
const firstMessage = extractFirstUserMessage(filePath);
|
|
29140
|
+
if (!firstMessage) return;
|
|
29141
|
+
daemonLog(
|
|
29142
|
+
`session ${session.id} deriving title from first transcript message`
|
|
29143
|
+
);
|
|
29144
|
+
runSessionTitleGeneration(session, firstMessage, notify2);
|
|
29145
|
+
}
|
|
29146
|
+
function transcriptPath(session) {
|
|
29147
|
+
if (session.transcriptPath) return session.transcriptPath;
|
|
29148
|
+
if (!session.cwd || !session.claudeSessionId) return void 0;
|
|
29149
|
+
return findTranscriptPathSync(session.cwd, session.claudeSessionId) ?? void 0;
|
|
29150
|
+
}
|
|
29151
|
+
|
|
29111
29152
|
// src/commands/sessions/daemon/watchTranscript.ts
|
|
29112
29153
|
var DEBOUNCE_MS3 = 100;
|
|
29113
|
-
function watchTranscript(session, onStatusChange) {
|
|
29154
|
+
function watchTranscript(session, notify2, onStatusChange) {
|
|
29114
29155
|
if (!session.cwd || !session.claudeSessionId) return;
|
|
29115
29156
|
if (session.watchedTranscriptId === session.claudeSessionId) return;
|
|
29116
29157
|
const dir = projectDirForCwd(session.cwd);
|
|
@@ -29125,6 +29166,7 @@ function watchTranscript(session, onStatusChange) {
|
|
|
29125
29166
|
const run4 = () => {
|
|
29126
29167
|
timer = null;
|
|
29127
29168
|
void reconcileTranscriptStatus(session, onStatusChange);
|
|
29169
|
+
startTranscriptTitleGeneration(session, notify2);
|
|
29128
29170
|
};
|
|
29129
29171
|
try {
|
|
29130
29172
|
session.transcriptWatcher = watch3(dir, (_event, changed) => {
|
|
@@ -29145,7 +29187,7 @@ function watchTranscript(session, onStatusChange) {
|
|
|
29145
29187
|
|
|
29146
29188
|
// src/commands/sessions/daemon/wireSessionWatchers.ts
|
|
29147
29189
|
function wireSessionWatchers(session, notify2, onStatusChange) {
|
|
29148
|
-
const wireTranscript = (s) => watchTranscript(s, onStatusChange);
|
|
29190
|
+
const wireTranscript = (s) => watchTranscript(s, notify2, onStatusChange);
|
|
29149
29191
|
watchActivity(session, notify2, wireTranscript);
|
|
29150
29192
|
wireTranscript(session);
|
|
29151
29193
|
}
|
|
@@ -29278,13 +29320,13 @@ function transcriptUsage(lines) {
|
|
|
29278
29320
|
}
|
|
29279
29321
|
return [...byId.values()];
|
|
29280
29322
|
}
|
|
29281
|
-
async function readTranscriptUsage(
|
|
29282
|
-
const content = await fs38.promises.readFile(
|
|
29323
|
+
async function readTranscriptUsage(transcriptPath2) {
|
|
29324
|
+
const content = await fs38.promises.readFile(transcriptPath2, "utf8");
|
|
29283
29325
|
return transcriptUsage(content.split("\n"));
|
|
29284
29326
|
}
|
|
29285
29327
|
|
|
29286
29328
|
// src/commands/sessions/daemon/persistPhaseTokens.ts
|
|
29287
|
-
async function persistPhaseTokens(itemId2, phaseIdx,
|
|
29329
|
+
async function persistPhaseTokens(itemId2, phaseIdx, transcriptPath2, usedPct, windows) {
|
|
29288
29330
|
try {
|
|
29289
29331
|
if (!process.env.ASSIST_DATABASE_URL && !loadConfig().database.url) return;
|
|
29290
29332
|
const db = await getDb();
|
|
@@ -29301,7 +29343,7 @@ async function persistPhaseTokens(itemId2, phaseIdx, transcriptPath, usedPct, wi
|
|
|
29301
29343
|
);
|
|
29302
29344
|
}
|
|
29303
29345
|
}
|
|
29304
|
-
const responses = await readTranscriptUsage(
|
|
29346
|
+
const responses = await readTranscriptUsage(transcriptPath2);
|
|
29305
29347
|
if (responses.length === 0) return;
|
|
29306
29348
|
const { tokensUp, tokensDown } = await recordPhaseTranscriptUsage(
|
|
29307
29349
|
db,
|
|
@@ -29318,16 +29360,16 @@ async function persistPhaseTokens(itemId2, phaseIdx, transcriptPath, usedPct, wi
|
|
|
29318
29360
|
}
|
|
29319
29361
|
|
|
29320
29362
|
// src/commands/sessions/daemon/recordSessionUsage.ts
|
|
29321
|
-
function recordSessionUsage(sessions, claudeSessionId,
|
|
29363
|
+
function recordSessionUsage(sessions, claudeSessionId, transcriptPath2, usedPct, windows) {
|
|
29322
29364
|
for (const session of sessions) {
|
|
29323
29365
|
if (session.claudeSessionId !== claudeSessionId) continue;
|
|
29324
29366
|
session.usedPct = usedPct;
|
|
29325
29367
|
const phase = sessionBacklogPhase(session);
|
|
29326
|
-
if (phase &&
|
|
29368
|
+
if (phase && transcriptPath2)
|
|
29327
29369
|
void persistPhaseTokens(
|
|
29328
29370
|
phase.itemId,
|
|
29329
29371
|
phase.phaseIdx,
|
|
29330
|
-
|
|
29372
|
+
transcriptPath2,
|
|
29331
29373
|
usedPct,
|
|
29332
29374
|
windows
|
|
29333
29375
|
);
|
|
@@ -29338,11 +29380,11 @@ function recordSessionUsage(sessions, claudeSessionId, transcriptPath, usedPct,
|
|
|
29338
29380
|
}
|
|
29339
29381
|
|
|
29340
29382
|
// src/commands/sessions/daemon/applyUsageRecord.ts
|
|
29341
|
-
function applyUsageRecord(sessions, windows, notify2, claudeSessionId,
|
|
29383
|
+
function applyUsageRecord(sessions, windows, notify2, claudeSessionId, transcriptPath2, usedPct) {
|
|
29342
29384
|
if (recordSessionUsage(
|
|
29343
29385
|
sessions,
|
|
29344
29386
|
claudeSessionId,
|
|
29345
|
-
|
|
29387
|
+
transcriptPath2,
|
|
29346
29388
|
usedPct,
|
|
29347
29389
|
windows
|
|
29348
29390
|
))
|
|
@@ -31245,13 +31287,13 @@ var SessionManager = class {
|
|
|
31245
31287
|
}
|
|
31246
31288
|
/* why: the status line relays token totals keyed by Claude's session id; join
|
|
31247
31289
|
* it to the running backlog phase so the spend accumulates against that row. */
|
|
31248
|
-
recordUsage(claudeSessionId,
|
|
31290
|
+
recordUsage(claudeSessionId, transcriptPath2, usedPct) {
|
|
31249
31291
|
applyUsageRecord(
|
|
31250
31292
|
this.sessions.values(),
|
|
31251
31293
|
this.clients.currentWindows(),
|
|
31252
31294
|
this.notify,
|
|
31253
31295
|
claudeSessionId,
|
|
31254
|
-
|
|
31296
|
+
transcriptPath2,
|
|
31255
31297
|
usedPct
|
|
31256
31298
|
);
|
|
31257
31299
|
}
|
|
@@ -31827,21 +31869,6 @@ function summaryPathFor(jsonlPath2) {
|
|
|
31827
31869
|
|
|
31828
31870
|
// src/commands/sessions/summarise/summariseSession.ts
|
|
31829
31871
|
import { execFileSync as execFileSync14 } from "child_process";
|
|
31830
|
-
|
|
31831
|
-
// src/commands/sessions/summarise/extractFirstUserMessage.ts
|
|
31832
|
-
function extractFirstUserMessage(filePath) {
|
|
31833
|
-
for (const text17 of iterateUserMessages(filePath)) {
|
|
31834
|
-
return truncate3(text17);
|
|
31835
|
-
}
|
|
31836
|
-
return void 0;
|
|
31837
|
-
}
|
|
31838
|
-
function truncate3(text17, maxChars = 500) {
|
|
31839
|
-
const trimmed = text17.trim();
|
|
31840
|
-
if (trimmed.length <= maxChars) return trimmed;
|
|
31841
|
-
return `${trimmed.slice(0, maxChars)}\u2026`;
|
|
31842
|
-
}
|
|
31843
|
-
|
|
31844
|
-
// src/commands/sessions/summarise/summariseSession.ts
|
|
31845
31872
|
function summariseSession(jsonlPath2) {
|
|
31846
31873
|
const firstMessage = extractFirstUserMessage(jsonlPath2);
|
|
31847
31874
|
const backlogIds = scanSessionBacklogRefs(jsonlPath2);
|
|
@@ -32074,13 +32101,13 @@ async function relayRateLimits(rateLimits) {
|
|
|
32074
32101
|
}
|
|
32075
32102
|
|
|
32076
32103
|
// src/commands/relayUsage.ts
|
|
32077
|
-
async function relayUsage(claudeSessionId,
|
|
32104
|
+
async function relayUsage(claudeSessionId, transcriptPath2, usedPct) {
|
|
32078
32105
|
if (!claudeSessionId) return;
|
|
32079
32106
|
try {
|
|
32080
32107
|
await sendToDaemon({
|
|
32081
32108
|
type: "usage",
|
|
32082
32109
|
claudeSessionId,
|
|
32083
|
-
transcriptPath,
|
|
32110
|
+
transcriptPath: transcriptPath2,
|
|
32084
32111
|
usedPct
|
|
32085
32112
|
});
|
|
32086
32113
|
} catch {
|