@staff0rd/assist 0.382.1 → 0.384.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.382.1",
9
+ version: "0.384.0",
10
10
  type: "module",
11
11
  main: "dist/index.js",
12
12
  bin: {
@@ -513,7 +513,13 @@ var itemSubtasks = pgTable5(
513
513
  );
514
514
 
515
515
  // src/shared/db/phaseUsage.ts
516
- import { bigint as bigint2, integer as integer6, pgTable as pgTable6, primaryKey as primaryKey3 } from "drizzle-orm/pg-core";
516
+ import {
517
+ bigint as bigint2,
518
+ doublePrecision,
519
+ integer as integer6,
520
+ pgTable as pgTable6,
521
+ primaryKey as primaryKey3
522
+ } from "drizzle-orm/pg-core";
517
523
  var phaseUsage = pgTable6(
518
524
  "phase_usage",
519
525
  {
@@ -522,6 +528,7 @@ var phaseUsage = pgTable6(
522
528
  tokensUp: bigint2("tokens_up", { mode: "number" }).notNull().default(0),
523
529
  tokensDown: bigint2("tokens_down", { mode: "number" }).notNull().default(0),
524
530
  activeMs: bigint2("active_ms", { mode: "number" }).notNull().default(0),
531
+ peakContextPct: doublePrecision("peak_context_pct").notNull().default(0),
525
532
  lastTotalIn: bigint2("last_total_in", { mode: "number" }),
526
533
  lastTotalOut: bigint2("last_total_out", { mode: "number" })
527
534
  },
@@ -544,7 +551,7 @@ var phaseUsageMessages = pgTable7(
544
551
  import {
545
552
  bigint as bigint3,
546
553
  boolean as boolean2,
547
- doublePrecision,
554
+ doublePrecision as doublePrecision2,
548
555
  integer as integer8,
549
556
  pgTable as pgTable8,
550
557
  primaryKey as primaryKey5,
@@ -557,7 +564,7 @@ var usagePeaks = pgTable8(
557
564
  window: text7().$type().notNull(),
558
565
  resetsAt: bigint3("resets_at", { mode: "number" }).notNull(),
559
566
  segment: integer8().notNull().default(0),
560
- usedPercentage: doublePrecision("used_percentage").notNull(),
567
+ usedPercentage: doublePrecision2("used_percentage").notNull(),
561
568
  resetDetected: boolean2("reset_detected").notNull().default(false),
562
569
  tokensUp: bigint3("tokens_up", { mode: "number" }).notNull().default(0),
563
570
  tokensDown: bigint3("tokens_down", { mode: "number" }).notNull().default(0),
@@ -921,6 +928,7 @@ var SCHEMA = `
921
928
  tokens_up BIGINT NOT NULL DEFAULT 0,
922
929
  tokens_down BIGINT NOT NULL DEFAULT 0,
923
930
  active_ms BIGINT NOT NULL DEFAULT 0,
931
+ peak_context_pct DOUBLE PRECISION NOT NULL DEFAULT 0,
924
932
  last_total_in BIGINT,
925
933
  last_total_out BIGINT,
926
934
  PRIMARY KEY (item_id, phase_idx)
@@ -928,6 +936,7 @@ var SCHEMA = `
928
936
 
929
937
  ALTER TABLE phase_usage ADD COLUMN IF NOT EXISTS last_total_in BIGINT;
930
938
  ALTER TABLE phase_usage ADD COLUMN IF NOT EXISTS last_total_out BIGINT;
939
+ ALTER TABLE phase_usage ADD COLUMN IF NOT EXISTS peak_context_pct DOUBLE PRECISION NOT NULL DEFAULT 0;
931
940
 
932
941
  CREATE TABLE IF NOT EXISTS phase_usage_messages (
933
942
  item_id INTEGER NOT NULL REFERENCES items(id) ON DELETE CASCADE,
@@ -1002,7 +1011,7 @@ function createPool() {
1002
1011
  return pool;
1003
1012
  }
1004
1013
  async function initSchema(pool) {
1005
- await ensureSchema((sql13) => pool.query(sql13));
1014
+ await ensureSchema((sql14) => pool.query(sql14));
1006
1015
  const orm = makeOrmFromPool(pool);
1007
1016
  await seedNewsFeeds(orm);
1008
1017
  await runUsagePeakCleanup(orm);
@@ -4082,8 +4091,8 @@ async function buildDump(tables, copyOut) {
4082
4091
  // src/commands/backlog/dump/copyTableOut.ts
4083
4092
  import { to as copyTo } from "pg-copy-streams";
4084
4093
  async function copyTableOut(client, table) {
4085
- const sql13 = `COPY ${table.name} (${table.columns.join(", ")}) TO STDOUT`;
4086
- const stream = client.query(copyTo(sql13));
4094
+ const sql14 = `COPY ${table.name} (${table.columns.join(", ")}) TO STDOUT`;
4095
+ const stream = client.query(copyTo(sql14));
4087
4096
  const chunks = [];
4088
4097
  for await (const chunk of stream) {
4089
4098
  chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
@@ -4972,9 +4981,10 @@ function sumPhaseUsage(usage) {
4972
4981
  (total, u) => ({
4973
4982
  tokensUp: total.tokensUp + u.tokensUp,
4974
4983
  tokensDown: total.tokensDown + u.tokensDown,
4975
- activeMs: total.activeMs + u.activeMs
4984
+ activeMs: total.activeMs + u.activeMs,
4985
+ peakContextPct: Math.max(total.peakContextPct, u.peakContextPct)
4976
4986
  }),
4977
- { tokensUp: 0, tokensDown: 0, activeMs: 0 }
4987
+ { tokensUp: 0, tokensDown: 0, activeMs: 0, peakContextPct: 0 }
4978
4988
  );
4979
4989
  }
4980
4990
 
@@ -4984,7 +4994,8 @@ function rowToUsage(u) {
4984
4994
  phaseIdx: u.phaseIdx,
4985
4995
  tokensUp: u.tokensUp,
4986
4996
  tokensDown: u.tokensDown,
4987
- activeMs: u.activeMs
4997
+ activeMs: u.activeMs,
4998
+ peakContextPct: u.peakContextPct
4988
4999
  };
4989
5000
  }
4990
5001
  function attachUsage(item, rel, id) {
@@ -5104,12 +5115,14 @@ var phaseUsageSchema = z3.strictObject({
5104
5115
  phaseIdx: z3.number(),
5105
5116
  tokensUp: z3.number(),
5106
5117
  tokensDown: z3.number(),
5107
- activeMs: z3.number()
5118
+ activeMs: z3.number(),
5119
+ peakContextPct: z3.number()
5108
5120
  });
5109
5121
  var phaseUsageTotalSchema = z3.strictObject({
5110
5122
  tokensUp: z3.number(),
5111
5123
  tokensDown: z3.number(),
5112
- activeMs: z3.number()
5124
+ activeMs: z3.number(),
5125
+ peakContextPct: z3.number()
5113
5126
  });
5114
5127
  var subtaskStatusSchema = z3.enum(["todo", "in-progress", "done"]);
5115
5128
  var subtaskSchema = z3.strictObject({
@@ -6679,6 +6692,9 @@ function phaseUsageTotals(orm) {
6679
6692
  ),
6680
6693
  activeMs: sql6`sum(${phaseUsage.activeMs})::bigint`.as(
6681
6694
  "total_active_ms"
6695
+ ),
6696
+ peakContextPct: sql6`max(${phaseUsage.peakContextPct})`.as(
6697
+ "max_peak_context_pct"
6682
6698
  )
6683
6699
  }).from(phaseUsage).groupBy(phaseUsage.itemId).as("usage_totals");
6684
6700
  }
@@ -6697,7 +6713,8 @@ function rowToItemSummary(row) {
6697
6713
  usageTotal: row.tokensUp == null ? void 0 : {
6698
6714
  tokensUp: Number(row.tokensUp),
6699
6715
  tokensDown: Number(row.tokensDown),
6700
- activeMs: Number(row.activeMs)
6716
+ activeMs: Number(row.activeMs),
6717
+ peakContextPct: Number(row.peakContextPct ?? 0)
6701
6718
  }
6702
6719
  };
6703
6720
  }
@@ -6717,7 +6734,8 @@ async function loadItemSummaries(orm, origin) {
6717
6734
  incompleteSubtasks: incompleteCounts.count,
6718
6735
  tokensUp: usageTotals.tokensUp,
6719
6736
  tokensDown: usageTotals.tokensDown,
6720
- activeMs: usageTotals.activeMs
6737
+ activeMs: usageTotals.activeMs,
6738
+ peakContextPct: usageTotals.peakContextPct
6721
6739
  }).from(items).leftJoin(incompleteCounts, eq11(incompleteCounts.itemId, items.id)).leftJoin(usageTotals, eq11(usageTotals.itemId, items.id)).where(origin === void 0 ? void 0 : eq11(items.origin, origin)).orderBy(asc5(items.id));
6722
6740
  return rows.map(rowToItemSummary);
6723
6741
  }
@@ -8459,8 +8477,8 @@ async function readStdinBuffer() {
8459
8477
  import { finished } from "stream/promises";
8460
8478
  import { from as copyFrom } from "pg-copy-streams";
8461
8479
  async function copyTableIn(client, table, data) {
8462
- const sql13 = `COPY ${table.name} (${table.columns.join(", ")}) FROM STDIN`;
8463
- const stream = client.query(copyFrom(sql13));
8480
+ const sql14 = `COPY ${table.name} (${table.columns.join(", ")}) FROM STDIN`;
8481
+ const stream = client.query(copyFrom(sql14));
8464
8482
  stream.end(data);
8465
8483
  await finished(stream);
8466
8484
  }
@@ -20111,8 +20129,8 @@ function filterToSql(filter) {
20111
20129
  // src/commands/seq/fetchSeqData.ts
20112
20130
  function buildDataParams(filter, count8, from, to) {
20113
20131
  const sqlFilter = filterToSql(filter);
20114
- const sql13 = `select @Timestamp, @Level, @Exception, @Message from stream where ${sqlFilter} order by @Timestamp desc limit ${count8}`;
20115
- const params = new URLSearchParams({ q: sql13 });
20132
+ const sql14 = `select @Timestamp, @Level, @Exception, @Message from stream where ${sqlFilter} order by @Timestamp desc limit ${count8}`;
20133
+ const params = new URLSearchParams({ q: sql14 });
20116
20134
  if (from) params.set("rangeStartUtc", from);
20117
20135
  if (to) params.set("rangeEndUtc", to);
20118
20136
  return params;
@@ -20373,26 +20391,26 @@ import chalk187 from "chalk";
20373
20391
  // src/commands/sql/loadConnections.ts
20374
20392
  function loadConnections3() {
20375
20393
  const raw = loadGlobalConfigRaw();
20376
- const sql13 = raw.sql;
20377
- return sql13?.connections ?? [];
20394
+ const sql14 = raw.sql;
20395
+ return sql14?.connections ?? [];
20378
20396
  }
20379
20397
  function saveConnections3(connections) {
20380
20398
  const raw = loadGlobalConfigRaw();
20381
- const sql13 = raw.sql ?? {};
20382
- sql13.connections = connections;
20383
- raw.sql = sql13;
20399
+ const sql14 = raw.sql ?? {};
20400
+ sql14.connections = connections;
20401
+ raw.sql = sql14;
20384
20402
  saveGlobalConfig(raw);
20385
20403
  }
20386
20404
  function getDefaultConnection2() {
20387
20405
  const raw = loadGlobalConfigRaw();
20388
- const sql13 = raw.sql;
20389
- return sql13?.defaultConnection;
20406
+ const sql14 = raw.sql;
20407
+ return sql14?.defaultConnection;
20390
20408
  }
20391
20409
  function setDefaultConnection2(name) {
20392
20410
  const raw = loadGlobalConfigRaw();
20393
- const sql13 = raw.sql ?? {};
20394
- sql13.defaultConnection = name;
20395
- raw.sql = sql13;
20411
+ const sql14 = raw.sql ?? {};
20412
+ sql14.defaultConnection = name;
20413
+ raw.sql = sql14;
20396
20414
  saveGlobalConfig(raw);
20397
20415
  }
20398
20416
 
@@ -20542,11 +20560,11 @@ var MUTATION_PATTERN = new RegExp(
20542
20560
  `\\b(${MUTATION_KEYWORDS.join("|")})\\b`,
20543
20561
  "i"
20544
20562
  );
20545
- function stripComments(sql13) {
20546
- return sql13.replace(/\/\*[\s\S]*?\*\//g, " ").replace(/--[^\n]*/g, " ");
20563
+ function stripComments(sql14) {
20564
+ return sql14.replace(/\/\*[\s\S]*?\*\//g, " ").replace(/--[^\n]*/g, " ");
20547
20565
  }
20548
- function isMutation(sql13) {
20549
- const stripped = stripComments(sql13);
20566
+ function isMutation(sql14) {
20567
+ const stripped = stripComments(sql14);
20550
20568
  if (MUTATION_PATTERN.test(stripped)) return true;
20551
20569
  return /\bSELECT\b[\s\S]+\bINTO\s+\w/i.test(stripped);
20552
20570
  }
@@ -22848,6 +22866,59 @@ function drainSessions(sessions, onDrained) {
22848
22866
  return ids.length;
22849
22867
  }
22850
22868
 
22869
+ // src/shared/db/recordPhaseActiveMs.ts
22870
+ import { sql as sql10 } from "drizzle-orm";
22871
+ async function recordPhaseActiveMs(db, itemId2, phaseIdx, activeMs) {
22872
+ if (activeMs <= 0) return;
22873
+ await db.insert(phaseUsage).values({ itemId: itemId2, phaseIdx, activeMs }).onConflictDoUpdate({
22874
+ target: [phaseUsage.itemId, phaseUsage.phaseIdx],
22875
+ set: {
22876
+ activeMs: sql10`${phaseUsage.activeMs} + excluded.active_ms`
22877
+ }
22878
+ });
22879
+ }
22880
+
22881
+ // src/commands/sessions/daemon/persistPhaseActiveMs.ts
22882
+ async function persistPhaseActiveMs(itemId2, phaseIdx, activeMs) {
22883
+ try {
22884
+ if (!process.env.ASSIST_DATABASE_URL && !loadConfig().database.url)
22885
+ return true;
22886
+ await recordPhaseActiveMs(await getDb(), itemId2, phaseIdx, activeMs);
22887
+ return true;
22888
+ } catch (error) {
22889
+ daemonLog(`phase-active-ms persist failed: ${String(error)}`);
22890
+ return false;
22891
+ }
22892
+ }
22893
+
22894
+ // src/commands/sessions/daemon/sessionBacklogPhase.ts
22895
+ function sessionBacklogPhase(session) {
22896
+ const activity2 = session.activity;
22897
+ if (activity2?.kind !== "backlog") return void 0;
22898
+ if (activity2.itemId == null || activity2.phase == null) return void 0;
22899
+ return { itemId: activity2.itemId, phaseIdx: activity2.phase - 1 };
22900
+ }
22901
+
22902
+ // src/commands/sessions/daemon/flushPhaseActiveMs.ts
22903
+ function flushPhaseActiveMs(session) {
22904
+ if (session.status !== "running" || session.runningSince == null)
22905
+ return Promise.resolve();
22906
+ const phase = sessionBacklogPhase(session);
22907
+ if (!phase) return Promise.resolve();
22908
+ const since = session.runningSince;
22909
+ const elapsed = Date.now() - since;
22910
+ const run4 = async () => {
22911
+ const flushed = session.activeMsFlushedForStretch?.since === since ? session.activeMsFlushedForStretch.ms : 0;
22912
+ const delta = elapsed - flushed;
22913
+ if (delta <= 0) return;
22914
+ if (await persistPhaseActiveMs(phase.itemId, phase.phaseIdx, delta))
22915
+ session.activeMsFlushedForStretch = { since, ms: flushed + delta };
22916
+ };
22917
+ const chain = (session.activeMsFlushChain ?? Promise.resolve()).then(run4);
22918
+ session.activeMsFlushChain = chain;
22919
+ return chain;
22920
+ }
22921
+
22851
22922
  // src/commands/sessions/daemon/stripReplayQueries.ts
22852
22923
  var ESC2 = "\x1B";
22853
22924
  var REPLAY_QUERY = new RegExp(
@@ -22884,36 +22955,6 @@ function logSpawnedSession(session) {
22884
22955
  );
22885
22956
  }
22886
22957
 
22887
- // src/shared/db/recordPhaseActiveMs.ts
22888
- import { sql as sql10 } from "drizzle-orm";
22889
- async function recordPhaseActiveMs(db, itemId2, phaseIdx, activeMs) {
22890
- if (activeMs <= 0) return;
22891
- await db.insert(phaseUsage).values({ itemId: itemId2, phaseIdx, activeMs }).onConflictDoUpdate({
22892
- target: [phaseUsage.itemId, phaseUsage.phaseIdx],
22893
- set: {
22894
- activeMs: sql10`${phaseUsage.activeMs} + excluded.active_ms`
22895
- }
22896
- });
22897
- }
22898
-
22899
- // src/commands/sessions/daemon/persistPhaseActiveMs.ts
22900
- async function persistPhaseActiveMs(itemId2, phaseIdx, activeMs) {
22901
- try {
22902
- if (!process.env.ASSIST_DATABASE_URL && !loadConfig().database.url) return;
22903
- await recordPhaseActiveMs(await getDb(), itemId2, phaseIdx, activeMs);
22904
- } catch (error) {
22905
- daemonLog(`phase-active-ms persist failed: ${String(error)}`);
22906
- }
22907
- }
22908
-
22909
- // src/commands/sessions/daemon/sessionBacklogPhase.ts
22910
- function sessionBacklogPhase(session) {
22911
- const activity2 = session.activity;
22912
- if (activity2?.kind !== "backlog") return void 0;
22913
- if (activity2.itemId == null || activity2.phase == null) return void 0;
22914
- return { itemId: activity2.itemId, phaseIdx: activity2.phase - 1 };
22915
- }
22916
-
22917
22958
  // src/commands/sessions/daemon/setStatus.ts
22918
22959
  function setStatus2(session, newStatus) {
22919
22960
  const now = Date.now();
@@ -22997,21 +23038,11 @@ function disarmEscInterrupt(session) {
22997
23038
  }
22998
23039
 
22999
23040
  // src/commands/sessions/daemon/applyStatusChange.ts
23000
- function accumulateActiveTime(session) {
23001
- if (session.status !== "running" || session.runningSince == null) return;
23002
- const phase = sessionBacklogPhase(session);
23003
- if (!phase) return;
23004
- void persistPhaseActiveMs(
23005
- phase.itemId,
23006
- phase.phaseIdx,
23007
- Date.now() - session.runningSince
23008
- );
23009
- }
23010
23041
  function applyStatusChange(session, status2, exitCode, dismiss, notify2, reuseForRun) {
23011
23042
  disarmEscInterrupt(session);
23012
23043
  if (session.status === status2) return;
23013
23044
  daemonLog(`session ${session.id} status: ${session.status} -> ${status2}`);
23014
- accumulateActiveTime(session);
23045
+ void flushPhaseActiveMs(session);
23015
23046
  setStatus2(session, status2);
23016
23047
  const autoRun = shouldAutoRun(session);
23017
23048
  if (autoRun.run) {
@@ -23033,8 +23064,19 @@ function makeStatusChangeHandler(dismiss, notify2, reuseForRun) {
23033
23064
  return (s, status2, exitCode) => applyStatusChange(s, status2, exitCode, dismiss, notify2, reuseForRun);
23034
23065
  }
23035
23066
 
23036
- // src/shared/db/recordPhaseTranscriptUsage.ts
23067
+ // src/shared/db/recordPhasePeakContext.ts
23037
23068
  import { sql as sql11 } from "drizzle-orm";
23069
+ async function recordPhasePeakContext(db, itemId2, phaseIdx, pct) {
23070
+ await db.insert(phaseUsage).values({ itemId: itemId2, phaseIdx, peakContextPct: pct }).onConflictDoUpdate({
23071
+ target: [phaseUsage.itemId, phaseUsage.phaseIdx],
23072
+ set: {
23073
+ peakContextPct: sql11`GREATEST(${phaseUsage.peakContextPct}, ${pct})`
23074
+ }
23075
+ });
23076
+ }
23077
+
23078
+ // src/shared/db/recordPhaseTranscriptUsage.ts
23079
+ import { sql as sql12 } from "drizzle-orm";
23038
23080
  async function recordPhaseTranscriptUsage(db, itemId2, phaseIdx, responses) {
23039
23081
  const byId = /* @__PURE__ */ new Map();
23040
23082
  for (const r of responses) byId.set(r.messageId, r);
@@ -23054,8 +23096,8 @@ async function recordPhaseTranscriptUsage(db, itemId2, phaseIdx, responses) {
23054
23096
  await tx.insert(phaseUsage).values({ itemId: itemId2, phaseIdx, tokensUp, tokensDown }).onConflictDoUpdate({
23055
23097
  target: [phaseUsage.itemId, phaseUsage.phaseIdx],
23056
23098
  set: {
23057
- tokensUp: sql11`${phaseUsage.tokensUp} + ${tokensUp}`,
23058
- tokensDown: sql11`${phaseUsage.tokensDown} + ${tokensDown}`
23099
+ tokensUp: sql12`${phaseUsage.tokensUp} + ${tokensUp}`,
23100
+ tokensDown: sql12`${phaseUsage.tokensDown} + ${tokensDown}`
23059
23101
  }
23060
23102
  });
23061
23103
  return { tokensUp, tokensDown };
@@ -23063,12 +23105,12 @@ async function recordPhaseTranscriptUsage(db, itemId2, phaseIdx, responses) {
23063
23105
  }
23064
23106
 
23065
23107
  // src/shared/db/recordWindowTokens.ts
23066
- import { and as and19, eq as eq37, sql as sql12 } from "drizzle-orm";
23108
+ import { and as and19, eq as eq37, sql as sql13 } from "drizzle-orm";
23067
23109
  async function recordWindowTokens(db, window, resetsAt, tokensUp, tokensDown) {
23068
23110
  if (tokensUp <= 0 && tokensDown <= 0) return;
23069
23111
  await db.update(usagePeaks).set({
23070
- tokensUp: sql12`${usagePeaks.tokensUp} + ${tokensUp}`,
23071
- tokensDown: sql12`${usagePeaks.tokensDown} + ${tokensDown}`
23112
+ tokensUp: sql13`${usagePeaks.tokensUp} + ${tokensUp}`,
23113
+ tokensDown: sql13`${usagePeaks.tokensDown} + ${tokensDown}`
23072
23114
  }).where(
23073
23115
  and19(
23074
23116
  eq37(usagePeaks.window, window),
@@ -23108,12 +23150,14 @@ async function readTranscriptUsage(transcriptPath) {
23108
23150
  }
23109
23151
 
23110
23152
  // src/commands/sessions/daemon/persistPhaseTokens.ts
23111
- async function persistPhaseTokens(itemId2, phaseIdx, transcriptPath, windows) {
23153
+ async function persistPhaseTokens(itemId2, phaseIdx, transcriptPath, usedPct, windows) {
23112
23154
  try {
23113
23155
  if (!process.env.ASSIST_DATABASE_URL && !loadConfig().database.url) return;
23156
+ const db = await getDb();
23157
+ if (usedPct !== void 0)
23158
+ await recordPhasePeakContext(db, itemId2, phaseIdx, usedPct);
23114
23159
  const responses = await readTranscriptUsage(transcriptPath);
23115
23160
  if (responses.length === 0) return;
23116
- const db = await getDb();
23117
23161
  const { tokensUp, tokensDown } = await recordPhaseTranscriptUsage(
23118
23162
  db,
23119
23163
  itemId2,
@@ -23139,8 +23183,10 @@ function recordSessionUsage(sessions, claudeSessionId, transcriptPath, usedPct,
23139
23183
  phase.itemId,
23140
23184
  phase.phaseIdx,
23141
23185
  transcriptPath,
23186
+ usedPct,
23142
23187
  windows
23143
23188
  );
23189
+ void flushPhaseActiveMs(session);
23144
23190
  return true;
23145
23191
  }
23146
23192
  return false;
@@ -24355,6 +24401,11 @@ var SessionManager = class {
24355
24401
  this.shuttingDown = true;
24356
24402
  shutdownSessions(this.sessions);
24357
24403
  }
24404
+ async flushActiveMs() {
24405
+ await Promise.all(
24406
+ [...this.sessions.values()].map((s) => flushPhaseActiveMs(s))
24407
+ );
24408
+ }
24358
24409
  restore() {
24359
24410
  return restoreAll(this.spawnWith, this.sessions);
24360
24411
  }
@@ -24755,7 +24806,8 @@ function handleFetchTranscript(client, _manager, data) {
24755
24806
  (messages) => sendTo(client, { type: "transcript", sessionId, messages })
24756
24807
  );
24757
24808
  }
24758
- function handleShutdown(client, manager) {
24809
+ async function handleShutdown(client, manager) {
24810
+ await manager.flushActiveMs();
24759
24811
  manager.shutdown();
24760
24812
  sendTo(client, { type: "shutting-down" });
24761
24813
  setImmediate(() => process.exit(0));
@@ -24913,8 +24965,10 @@ function onListening(manager, checkAutoExit) {
24913
24965
  writeFileSync40(daemonPaths.pid, String(process.pid));
24914
24966
  startPidFileWatchdog(() => {
24915
24967
  daemonLog("lost daemon.pid ownership; shutting down sessions and exiting");
24916
- manager.shutdown();
24917
- process.exit(0);
24968
+ void manager.flushActiveMs().finally(() => {
24969
+ manager.shutdown();
24970
+ process.exit(0);
24971
+ });
24918
24972
  });
24919
24973
  process.on("exit", cleanupOwnedFiles);
24920
24974
  const restored = manager.restore();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@staff0rd/assist",
3
- "version": "0.382.1",
3
+ "version": "0.384.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "bin": {