@staff0rd/assist 0.343.0 → 0.344.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/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.343.0",
9
+ version: "0.344.1",
10
10
  type: "module",
11
11
  main: "dist/index.js",
12
12
  bin: {
@@ -6399,13 +6399,14 @@ var execFileAsync3 = promisify4(execFile3);
6399
6399
  var CACHE_TTL_MS = 3e4;
6400
6400
  function createCachedGhJson(args, parse3, fallback) {
6401
6401
  const cache = /* @__PURE__ */ new Map();
6402
- return async (cwd) => {
6402
+ return async (cwd, extraArgs = []) => {
6403
+ const key = extraArgs.length ? `${cwd}\0${extraArgs.join("\0")}` : cwd;
6403
6404
  const now = Date.now();
6404
- const cached = cache.get(cwd);
6405
+ const cached = cache.get(key);
6405
6406
  if (cached && cached.expires > now) return cached.value;
6406
6407
  let value = fallback;
6407
6408
  try {
6408
- const { stdout } = await execFileAsync3("gh", args, {
6409
+ const { stdout } = await execFileAsync3("gh", [...args, ...extraArgs], {
6409
6410
  encoding: "utf8",
6410
6411
  cwd: windowsCwdToWslPath(cwd)
6411
6412
  });
@@ -6413,7 +6414,7 @@ function createCachedGhJson(args, parse3, fallback) {
6413
6414
  } catch {
6414
6415
  value = fallback;
6415
6416
  }
6416
- cache.set(cwd, { value, expires: now + CACHE_TTL_MS });
6417
+ cache.set(key, { value, expires: now + CACHE_TTL_MS });
6417
6418
  return value;
6418
6419
  };
6419
6420
  }
@@ -6463,10 +6464,20 @@ var getPr = createCachedGhJson(
6463
6464
  },
6464
6465
  null
6465
6466
  );
6467
+ function getNumberParam(req) {
6468
+ const raw = new URL(req.url ?? "/", "http://localhost").searchParams.get(
6469
+ "number"
6470
+ );
6471
+ if (!raw) return void 0;
6472
+ const parsed = Number(raw);
6473
+ return Number.isInteger(parsed) && parsed > 0 ? parsed : void 0;
6474
+ }
6466
6475
  async function prStatus(req, res) {
6467
6476
  const cwd = getCwdParam(req, res);
6468
6477
  if (!cwd) return;
6469
- respondJson(res, 200, { pr: await getPr(cwd) });
6478
+ const number = getNumberParam(req);
6479
+ const extraArgs = number !== void 0 ? [String(number)] : void 0;
6480
+ respondJson(res, 200, { pr: await getPr(cwd, extraArgs) });
6470
6481
  }
6471
6482
 
6472
6483
  // src/commands/sessions/daemon/stopDaemon.ts
@@ -21258,6 +21269,42 @@ function applyReviewPause(session, activity2) {
21258
21269
  }
21259
21270
  }
21260
21271
 
21272
+ // src/shared/db/getPhaseActiveMs.ts
21273
+ import { and as and15, eq as eq34 } from "drizzle-orm";
21274
+ async function getPhaseActiveMs(db, itemId, phaseIdx) {
21275
+ const [row] = await db.select({ activeMs: phaseUsage.activeMs }).from(phaseUsage).where(
21276
+ and15(eq34(phaseUsage.itemId, itemId), eq34(phaseUsage.phaseIdx, phaseIdx))
21277
+ );
21278
+ return row?.activeMs ?? 0;
21279
+ }
21280
+
21281
+ // src/commands/sessions/daemon/loadPhaseActiveMs.ts
21282
+ async function loadPhaseActiveMs(itemId, phaseIdx) {
21283
+ try {
21284
+ if (!process.env.ASSIST_DATABASE_URL && !loadConfig().database.url)
21285
+ return null;
21286
+ return await getPhaseActiveMs(await getDb(), itemId, phaseIdx);
21287
+ } catch (error) {
21288
+ daemonLog(`phase-active-ms load failed: ${String(error)}`);
21289
+ return null;
21290
+ }
21291
+ }
21292
+
21293
+ // src/commands/sessions/daemon/seedRunningMsFromUsage.ts
21294
+ async function seedRunningMsFromUsage(session, notify2) {
21295
+ if (session.usageSeeded) return;
21296
+ const phase = sessionBacklogPhase(session);
21297
+ if (!phase) return;
21298
+ session.usageSeeded = true;
21299
+ const priorMs = await loadPhaseActiveMs(phase.itemId, phase.phaseIdx);
21300
+ if (priorMs == null || priorMs <= session.runningMs) return;
21301
+ session.runningMs = priorMs;
21302
+ daemonLog(
21303
+ `session ${session.id} seeded runningMs=${priorMs} from item ${phase.itemId} phase ${phase.phaseIdx} recorded usage`
21304
+ );
21305
+ notify2();
21306
+ }
21307
+
21261
21308
  // src/commands/sessions/daemon/watchActivity.ts
21262
21309
  var DEBOUNCE_MS = 50;
21263
21310
  function watchActivity(session, notify2) {
@@ -21279,6 +21326,7 @@ function watchActivity(session, notify2) {
21279
21326
  if (activity2.claudeSessionId)
21280
21327
  session.claudeSessionId = activity2.claudeSessionId;
21281
21328
  applyReviewPause(session, activity2);
21329
+ void seedRunningMsFromUsage(session, notify2);
21282
21330
  notify2();
21283
21331
  };
21284
21332
  session.activityWatcher = watch(dir, (_event, filename) => {
@@ -21364,6 +21412,7 @@ function reuseSessionForRun(session, itemId, clients, onStatusChange) {
21364
21412
  session.startedAt = Date.now();
21365
21413
  session.runningMs = 0;
21366
21414
  session.runningSince = null;
21415
+ session.usageSeeded = false;
21367
21416
  setStatus2(session, "running");
21368
21417
  session.restored = void 0;
21369
21418
  session.pty = spawnPty(["assist", ...assistArgs], session.cwd, session.id);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@staff0rd/assist",
3
- "version": "0.343.0",
3
+ "version": "0.344.1",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "bin": {