@staff0rd/assist 0.969.1 → 0.970.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/commands/sessions/web/bundle.js +431 -431
- package/dist/index.js +231 -167
- 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.970.0",
|
|
10
10
|
type: "module",
|
|
11
11
|
main: "dist/index.js",
|
|
12
12
|
bin: {
|
|
@@ -5789,7 +5789,7 @@ var inboxConfigHelp = [
|
|
|
5789
5789
|
{
|
|
5790
5790
|
key: "inbox.intervalMinutes",
|
|
5791
5791
|
setter: "assist config set inbox.intervalMinutes <n> --node",
|
|
5792
|
-
note: "minutes between scheduled inbox scans run by this machine's daemon (
|
|
5792
|
+
note: "minutes between scheduled inbox scans run by this machine's daemon (picked up within a minute); read from ~/.assist.yml only, so a repo's assist.yml or shared overrides can't enable it. Unset by default: no scheduled scans"
|
|
5793
5793
|
}
|
|
5794
5794
|
];
|
|
5795
5795
|
|
|
@@ -8328,6 +8328,32 @@ async function historySearch(req, res) {
|
|
|
8328
8328
|
respondJson(res, 200, { sessions: reply2.sessions ?? [] });
|
|
8329
8329
|
}
|
|
8330
8330
|
|
|
8331
|
+
// src/shared/db/readInboxLastScan.ts
|
|
8332
|
+
import { eq as eq21 } from "drizzle-orm";
|
|
8333
|
+
var INBOX_LAST_SCAN_KEY = "inbox.lastScanAt";
|
|
8334
|
+
async function readInboxLastScan(orm) {
|
|
8335
|
+
const [row3] = await orm.select().from(metadata).where(eq21(metadata.key, INBOX_LAST_SCAN_KEY));
|
|
8336
|
+
return row3 ? new Date(row3.value) : void 0;
|
|
8337
|
+
}
|
|
8338
|
+
|
|
8339
|
+
// src/commands/sessions/web/inbox/inboxStatus.ts
|
|
8340
|
+
async function inboxStatus(_req, res) {
|
|
8341
|
+
const [reply2, lastScanAt] = await Promise.all([
|
|
8342
|
+
requestDaemonReply({ type: "inbox-status" }, "inbox-status"),
|
|
8343
|
+
readInboxLastScan(await getDb())
|
|
8344
|
+
]);
|
|
8345
|
+
if (!reply2) {
|
|
8346
|
+
respondJson(res, 503, { error: "Daemon not reachable" });
|
|
8347
|
+
return;
|
|
8348
|
+
}
|
|
8349
|
+
respondJson(res, 200, {
|
|
8350
|
+
scanning: reply2.scanning,
|
|
8351
|
+
intervalMinutes: reply2.intervalMinutes,
|
|
8352
|
+
lastError: reply2.lastError,
|
|
8353
|
+
lastScanAt: lastScanAt?.toISOString() ?? null
|
|
8354
|
+
});
|
|
8355
|
+
}
|
|
8356
|
+
|
|
8331
8357
|
// src/shared/db/listInboxMessages.ts
|
|
8332
8358
|
import { desc as desc3, isNull as isNull2, sql as sql17 } from "drizzle-orm";
|
|
8333
8359
|
function listInboxMessages(orm) {
|
|
@@ -8355,6 +8381,25 @@ async function listInbox(_req, res) {
|
|
|
8355
8381
|
);
|
|
8356
8382
|
}
|
|
8357
8383
|
|
|
8384
|
+
// src/commands/sessions/web/linkedRequester.ts
|
|
8385
|
+
function linkedRequester(req) {
|
|
8386
|
+
return `from=${req.headers["x-assist-linked-from"] ?? "local"} trace=${req.headers[TRACE_HEADER] ?? "none"}`;
|
|
8387
|
+
}
|
|
8388
|
+
|
|
8389
|
+
// src/commands/sessions/web/inbox/scanInbox.ts
|
|
8390
|
+
async function scanInbox(req, res) {
|
|
8391
|
+
console.log(`inbox scan requested ${linkedRequester(req)}`);
|
|
8392
|
+
const reply2 = await requestDaemonReply(
|
|
8393
|
+
{ type: "inbox-scan" },
|
|
8394
|
+
"inbox-scan"
|
|
8395
|
+
);
|
|
8396
|
+
if (!reply2) {
|
|
8397
|
+
respondJson(res, 503, { error: "Daemon not reachable" });
|
|
8398
|
+
return;
|
|
8399
|
+
}
|
|
8400
|
+
respondJson(res, 200, { started: reply2.started });
|
|
8401
|
+
}
|
|
8402
|
+
|
|
8358
8403
|
// src/shared/hotkeys/resolveHotkeys.ts
|
|
8359
8404
|
function resolveHotkeys(overrides) {
|
|
8360
8405
|
const bindings = { ...defaultHotkeys };
|
|
@@ -9469,14 +9514,14 @@ function listScopedRules(req, res) {
|
|
|
9469
9514
|
}
|
|
9470
9515
|
|
|
9471
9516
|
// src/shared/db/countUsagePeaks.ts
|
|
9472
|
-
import { count, eq as
|
|
9517
|
+
import { count, eq as eq22 } from "drizzle-orm";
|
|
9473
9518
|
async function countUsagePeaks(db, window) {
|
|
9474
|
-
const [row3] = await db.select({ value: count() }).from(usagePeaks).where(window ?
|
|
9519
|
+
const [row3] = await db.select({ value: count() }).from(usagePeaks).where(window ? eq22(usagePeaks.window, window) : void 0);
|
|
9475
9520
|
return row3?.value ?? 0;
|
|
9476
9521
|
}
|
|
9477
9522
|
|
|
9478
9523
|
// src/shared/db/listUsagePeaks.ts
|
|
9479
|
-
import { and as and10, desc as desc4, eq as
|
|
9524
|
+
import { and as and10, desc as desc4, eq as eq23, getTableColumns } from "drizzle-orm";
|
|
9480
9525
|
|
|
9481
9526
|
// src/shared/db/avgContextPerCycle.ts
|
|
9482
9527
|
import { count as count2, sql as sql18 } from "drizzle-orm";
|
|
@@ -9501,10 +9546,10 @@ async function listUsagePeaks(db, options2) {
|
|
|
9501
9546
|
}).from(usagePeaks).leftJoin(
|
|
9502
9547
|
avgContext,
|
|
9503
9548
|
and10(
|
|
9504
|
-
|
|
9505
|
-
|
|
9549
|
+
eq23(usagePeaks.window, avgContext.window),
|
|
9550
|
+
eq23(usagePeaks.resetsAt, avgContext.resetsAt)
|
|
9506
9551
|
)
|
|
9507
|
-
).where(options2?.window ?
|
|
9552
|
+
).where(options2?.window ? eq23(usagePeaks.window, options2.window) : void 0).orderBy(
|
|
9508
9553
|
desc4(usagePeaks.resetsAt),
|
|
9509
9554
|
usagePeaks.window,
|
|
9510
9555
|
desc4(usagePeaks.createdAt),
|
|
@@ -9573,26 +9618,26 @@ function listUsageHistory(req, res) {
|
|
|
9573
9618
|
}
|
|
9574
9619
|
|
|
9575
9620
|
// src/shared/db/countItemUsageByOrigin.ts
|
|
9576
|
-
import { asc as asc9, desc as desc5, eq as
|
|
9621
|
+
import { asc as asc9, desc as desc5, eq as eq24, sql as sql19 } from "drizzle-orm";
|
|
9577
9622
|
async function countItemUsageByOrigin(db) {
|
|
9578
9623
|
const count10 = sql19`count(distinct ${phaseUsage.itemId})::int`;
|
|
9579
|
-
const rows = await db.select({ origin: items.origin, count: count10 }).from(items).innerJoin(phaseUsage,
|
|
9624
|
+
const rows = await db.select({ origin: items.origin, count: count10 }).from(items).innerJoin(phaseUsage, eq24(phaseUsage.itemId, items.id)).groupBy(items.origin).orderBy(desc5(count10), asc9(items.origin));
|
|
9580
9625
|
return rows.map((row3) => ({ origin: row3.origin, count: Number(row3.count) }));
|
|
9581
9626
|
}
|
|
9582
9627
|
|
|
9583
9628
|
// src/shared/db/itemUsageWhere.ts
|
|
9584
|
-
import { and as and11, eq as
|
|
9629
|
+
import { and as and11, eq as eq25, notInArray } from "drizzle-orm";
|
|
9585
9630
|
function parseItemUsageStatus(value) {
|
|
9586
9631
|
return value === "done" || value === "running" ? value : void 0;
|
|
9587
9632
|
}
|
|
9588
9633
|
function statusClause(status2) {
|
|
9589
|
-
if (status2 === "done") return
|
|
9634
|
+
if (status2 === "done") return eq25(items.status, "done");
|
|
9590
9635
|
if (status2 === "running") return notInArray(items.status, ["done", "wontdo"]);
|
|
9591
9636
|
return void 0;
|
|
9592
9637
|
}
|
|
9593
9638
|
function itemUsageWhere(filter) {
|
|
9594
9639
|
return and11(
|
|
9595
|
-
filter?.origin ?
|
|
9640
|
+
filter?.origin ? eq25(items.origin, filter.origin) : void 0,
|
|
9596
9641
|
statusClause(filter?.status)
|
|
9597
9642
|
);
|
|
9598
9643
|
}
|
|
@@ -9617,7 +9662,7 @@ function parseItemUsageSort(field, direction) {
|
|
|
9617
9662
|
}
|
|
9618
9663
|
|
|
9619
9664
|
// src/shared/db/itemUsageStats.ts
|
|
9620
|
-
import { eq as
|
|
9665
|
+
import { eq as eq26, sql as sql20 } from "drizzle-orm";
|
|
9621
9666
|
function median(value) {
|
|
9622
9667
|
return sql20`coalesce(percentile_cont(0.5) within group (order by (${value})::double precision), 0)`;
|
|
9623
9668
|
}
|
|
@@ -9633,7 +9678,7 @@ async function itemUsageStats(db, options2) {
|
|
|
9633
9678
|
),
|
|
9634
9679
|
medianActiveMs: median(totals.activeMs),
|
|
9635
9680
|
medianTokens: median(sql20`${totals.tokensUp} + ${totals.tokensDown}`)
|
|
9636
|
-
}).from(items).innerJoin(totals,
|
|
9681
|
+
}).from(items).innerJoin(totals, eq26(totals.itemId, items.id)).leftJoin(planned, eq26(planned.itemId, items.id)).where(itemUsageWhere(options2));
|
|
9637
9682
|
return {
|
|
9638
9683
|
itemCount: Number(row3?.itemCount ?? 0),
|
|
9639
9684
|
doneCount: Number(row3?.doneCount ?? 0),
|
|
@@ -9645,7 +9690,7 @@ async function itemUsageStats(db, options2) {
|
|
|
9645
9690
|
}
|
|
9646
9691
|
|
|
9647
9692
|
// src/shared/db/listItemUsageSummaries.ts
|
|
9648
|
-
import { eq as
|
|
9693
|
+
import { eq as eq27 } from "drizzle-orm";
|
|
9649
9694
|
|
|
9650
9695
|
// src/shared/db/itemUsageOrderBy.ts
|
|
9651
9696
|
import { desc as desc6, sql as sql21 } from "drizzle-orm";
|
|
@@ -9706,7 +9751,7 @@ async function listItemUsageSummaries(db, options2) {
|
|
|
9706
9751
|
activeMs: totals.activeMs,
|
|
9707
9752
|
peakContextPct: totals.peakContextPct,
|
|
9708
9753
|
lastPhaseAt: lastPhase.atIso
|
|
9709
|
-
}).from(items).innerJoin(totals,
|
|
9754
|
+
}).from(items).innerJoin(totals, eq27(totals.itemId, items.id)).leftJoin(planned, eq27(planned.itemId, items.id)).leftJoin(lastPhase, eq27(lastPhase.itemId, items.id)).where(itemUsageWhere(options2)).orderBy(
|
|
9710
9755
|
...itemUsageOrderBy({ totals, planned, lastPhase }, options2?.sort)
|
|
9711
9756
|
);
|
|
9712
9757
|
const rows = options2?.limit === void 0 ? await query : await query.limit(options2.limit).offset(options2.offset ?? 0);
|
|
@@ -10522,11 +10567,6 @@ async function restartDaemon() {
|
|
|
10522
10567
|
);
|
|
10523
10568
|
}
|
|
10524
10569
|
|
|
10525
|
-
// src/commands/sessions/web/linkedRequester.ts
|
|
10526
|
-
function linkedRequester(req) {
|
|
10527
|
-
return `from=${req.headers["x-assist-linked-from"] ?? "local"} trace=${req.headers[TRACE_HEADER] ?? "none"}`;
|
|
10528
|
-
}
|
|
10529
|
-
|
|
10530
10570
|
// src/commands/sessions/web/restartMenu/reExecWebServer.ts
|
|
10531
10571
|
import { spawnSync as spawnSync3 } from "child_process";
|
|
10532
10572
|
|
|
@@ -11499,10 +11539,10 @@ function currentRepoLabel(shared, origin) {
|
|
|
11499
11539
|
}
|
|
11500
11540
|
|
|
11501
11541
|
// src/shared/db/saveRepoConfig.ts
|
|
11502
|
-
import { eq as
|
|
11542
|
+
import { eq as eq28 } from "drizzle-orm";
|
|
11503
11543
|
async function saveRepoConfig(orm, repoKey, config) {
|
|
11504
11544
|
if (Object.keys(config).length === 0) {
|
|
11505
|
-
await orm.delete(repoConfigs).where(
|
|
11545
|
+
await orm.delete(repoConfigs).where(eq28(repoConfigs.repoKey, repoKey));
|
|
11506
11546
|
return;
|
|
11507
11547
|
}
|
|
11508
11548
|
await orm.insert(repoConfigs).values({ repoKey, config }).onConflictDoUpdate({
|
|
@@ -11561,14 +11601,14 @@ async function applySharedRepoConfigSet(key, coerced, repoName, cwd = process.cw
|
|
|
11561
11601
|
}
|
|
11562
11602
|
|
|
11563
11603
|
// src/shared/db/updateUserConfig.ts
|
|
11564
|
-
import { eq as
|
|
11604
|
+
import { eq as eq29 } from "drizzle-orm";
|
|
11565
11605
|
async function updateUserConfig(orm, update4) {
|
|
11566
11606
|
return orm.transaction(async (tx) => {
|
|
11567
|
-
const [row3] = await tx.select().from(userConfig).where(
|
|
11607
|
+
const [row3] = await tx.select().from(userConfig).where(eq29(userConfig.id, 1)).for("update");
|
|
11568
11608
|
const outcome = update4(row3?.config ?? {});
|
|
11569
11609
|
if (!outcome.ok) return outcome;
|
|
11570
11610
|
if (Object.keys(outcome.config).length === 0) {
|
|
11571
|
-
await tx.delete(userConfig).where(
|
|
11611
|
+
await tx.delete(userConfig).where(eq29(userConfig.id, 1));
|
|
11572
11612
|
return outcome;
|
|
11573
11613
|
}
|
|
11574
11614
|
await tx.insert(userConfig).values({ id: 1, config: outcome.config }).onConflictDoUpdate({
|
|
@@ -12460,6 +12500,8 @@ var routes2 = {
|
|
|
12460
12500
|
"GET /api/next": nextItems,
|
|
12461
12501
|
"POST /api/next/pickup": nextPickup,
|
|
12462
12502
|
"GET /api/inbox": listInbox,
|
|
12503
|
+
"GET /api/inbox/status": inboxStatus,
|
|
12504
|
+
"POST /api/inbox/scan": scanInbox,
|
|
12463
12505
|
"GET /api/news/items": listNewsItems,
|
|
12464
12506
|
"GET /api/news/nav": newsNavConfig,
|
|
12465
12507
|
"GET /api/releases/state": releasesState,
|
|
@@ -15957,11 +15999,11 @@ function registerActivityCommands(cmd) {
|
|
|
15957
15999
|
|
|
15958
16000
|
// src/commands/backlog/associateGithub.ts
|
|
15959
16001
|
import chalk45 from "chalk";
|
|
15960
|
-
import { eq as
|
|
16002
|
+
import { eq as eq31 } from "drizzle-orm";
|
|
15961
16003
|
|
|
15962
16004
|
// src/commands/backlog/beginAssociation.ts
|
|
15963
16005
|
import chalk44 from "chalk";
|
|
15964
|
-
import { eq as
|
|
16006
|
+
import { eq as eq30 } from "drizzle-orm";
|
|
15965
16007
|
async function beginAssociation(id, options2, clearPatch, label) {
|
|
15966
16008
|
const found = await findOneItem(id);
|
|
15967
16009
|
if (!found) {
|
|
@@ -15971,7 +16013,7 @@ async function beginAssociation(id, options2, clearPatch, label) {
|
|
|
15971
16013
|
const { orm } = found;
|
|
15972
16014
|
const itemId2 = found.item.id;
|
|
15973
16015
|
if (options2.clear) {
|
|
15974
|
-
await orm.update(items).set(clearPatch).where(
|
|
16016
|
+
await orm.update(items).set(clearPatch).where(eq30(items.id, itemId2));
|
|
15975
16017
|
console.log(
|
|
15976
16018
|
chalk44.green(
|
|
15977
16019
|
`Cleared ${label} association on item ${formatItemId(itemId2)}.`
|
|
@@ -16039,7 +16081,7 @@ async function associateGithub(id, issue, options2) {
|
|
|
16039
16081
|
return;
|
|
16040
16082
|
}
|
|
16041
16083
|
const title = fetchGithubIssueTitle(normalized);
|
|
16042
|
-
await orm.update(items).set({ githubIssue: normalized, jiraKey: null }).where(
|
|
16084
|
+
await orm.update(items).set({ githubIssue: normalized, jiraKey: null }).where(eq31(items.id, itemId2));
|
|
16043
16085
|
console.log(
|
|
16044
16086
|
chalk45.green(`Associated ${normalized} with item ${formatItemId(itemId2)}.`),
|
|
16045
16087
|
title ? chalk45.dim(`(${title})`) : ""
|
|
@@ -16053,7 +16095,7 @@ function registerAssociateGithubCommand(cmd) {
|
|
|
16053
16095
|
|
|
16054
16096
|
// src/commands/backlog/associateJira.ts
|
|
16055
16097
|
import chalk47 from "chalk";
|
|
16056
|
-
import { eq as
|
|
16098
|
+
import { eq as eq32 } from "drizzle-orm";
|
|
16057
16099
|
|
|
16058
16100
|
// src/commands/jira/fetchIssue.ts
|
|
16059
16101
|
import { execSync as execSync17 } from "child_process";
|
|
@@ -16118,7 +16160,7 @@ async function associateJira(id, key, options2) {
|
|
|
16118
16160
|
const parsed = fetchIssue(normalized, "summary");
|
|
16119
16161
|
const fields = parsed?.fields;
|
|
16120
16162
|
const summary = fields?.summary;
|
|
16121
|
-
await orm.update(items).set({ jiraKey: normalized, githubIssue: null }).where(
|
|
16163
|
+
await orm.update(items).set({ jiraKey: normalized, githubIssue: null }).where(eq32(items.id, itemId2));
|
|
16122
16164
|
console.log(
|
|
16123
16165
|
chalk47.green(`Associated ${normalized} with item ${formatItemId(itemId2)}.`),
|
|
16124
16166
|
summary ? chalk47.dim(`(${summary})`) : ""
|
|
@@ -16654,9 +16696,9 @@ import chalk58 from "chalk";
|
|
|
16654
16696
|
|
|
16655
16697
|
// src/commands/backlog/resolveInsertPosition.ts
|
|
16656
16698
|
import chalk57 from "chalk";
|
|
16657
|
-
import { count as count3, eq as
|
|
16699
|
+
import { count as count3, eq as eq33 } from "drizzle-orm";
|
|
16658
16700
|
async function resolveInsertPosition(orm, itemId2, position) {
|
|
16659
|
-
const [row3] = await orm.select({ cnt: count3() }).from(planPhases).where(
|
|
16701
|
+
const [row3] = await orm.select({ cnt: count3() }).from(planPhases).where(eq33(planPhases.itemId, itemId2));
|
|
16660
16702
|
const phaseCount = row3?.cnt ?? 0;
|
|
16661
16703
|
if (position === void 0) return phaseCount;
|
|
16662
16704
|
const pos = Number.parseInt(position, 10);
|
|
@@ -17039,9 +17081,9 @@ function hasCycle(adjacency, fromId, toId) {
|
|
|
17039
17081
|
}
|
|
17040
17082
|
|
|
17041
17083
|
// src/commands/backlog/loadDependencyGraph.ts
|
|
17042
|
-
import { eq as
|
|
17084
|
+
import { eq as eq34 } from "drizzle-orm";
|
|
17043
17085
|
async function loadDependencyGraph(orm) {
|
|
17044
|
-
const rows = await orm.select({ itemId: links.itemId, targetId: links.targetId }).from(links).where(
|
|
17086
|
+
const rows = await orm.select({ itemId: links.itemId, targetId: links.targetId }).from(links).where(eq34(links.type, "depends-on"));
|
|
17045
17087
|
const graph = /* @__PURE__ */ new Map();
|
|
17046
17088
|
for (const { itemId: itemId2, targetId } of rows) {
|
|
17047
17089
|
const bucket = graph.get(itemId2);
|
|
@@ -17108,7 +17150,7 @@ async function link(fromId, toId, opts) {
|
|
|
17108
17150
|
|
|
17109
17151
|
// src/commands/backlog/unlink.ts
|
|
17110
17152
|
import chalk65 from "chalk";
|
|
17111
|
-
import { and as and12, eq as
|
|
17153
|
+
import { and as and12, eq as eq35 } from "drizzle-orm";
|
|
17112
17154
|
async function unlink(fromId, toId) {
|
|
17113
17155
|
const fromNum = parseItemId(fromId);
|
|
17114
17156
|
const toNum = parseItemId(toId);
|
|
@@ -17132,7 +17174,7 @@ async function unlink(fromId, toId) {
|
|
|
17132
17174
|
);
|
|
17133
17175
|
return;
|
|
17134
17176
|
}
|
|
17135
|
-
await orm.delete(links).where(and12(
|
|
17177
|
+
await orm.delete(links).where(and12(eq35(links.itemId, fromNum), eq35(links.targetId, toNum)));
|
|
17136
17178
|
console.log(
|
|
17137
17179
|
chalk65.green(
|
|
17138
17180
|
`Removed link from ${formatItemId(fromNum)} to ${formatItemId(toNum)}.`
|
|
@@ -17152,7 +17194,7 @@ function registerLinkCommands(cmd) {
|
|
|
17152
17194
|
|
|
17153
17195
|
// src/commands/backlog/moveRepo.ts
|
|
17154
17196
|
import chalk67 from "chalk";
|
|
17155
|
-
import { eq as
|
|
17197
|
+
import { eq as eq37 } from "drizzle-orm";
|
|
17156
17198
|
|
|
17157
17199
|
// src/commands/backlog/move-repo/confirmMove.ts
|
|
17158
17200
|
import chalk66 from "chalk";
|
|
@@ -17167,9 +17209,9 @@ async function confirmMove(cnt, oldOrigin, newOrigin) {
|
|
|
17167
17209
|
}
|
|
17168
17210
|
|
|
17169
17211
|
// src/commands/backlog/move-repo/countByOrigin.ts
|
|
17170
|
-
import { count as count4, eq as
|
|
17212
|
+
import { count as count4, eq as eq36 } from "drizzle-orm";
|
|
17171
17213
|
async function countByOrigin(orm, origin) {
|
|
17172
|
-
const [{ cnt }] = await orm.select({ cnt: count4() }).from(items).where(
|
|
17214
|
+
const [{ cnt }] = await orm.select({ cnt: count4() }).from(items).where(eq36(items.origin, origin));
|
|
17173
17215
|
return cnt;
|
|
17174
17216
|
}
|
|
17175
17217
|
|
|
@@ -17212,7 +17254,7 @@ async function moveRepo(oldOriginRaw, newOriginRaw, options2 = {}) {
|
|
|
17212
17254
|
console.log(chalk67.yellow("Move cancelled; no changes made."));
|
|
17213
17255
|
return;
|
|
17214
17256
|
}
|
|
17215
|
-
await orm.update(items).set({ origin: newOrigin }).where(
|
|
17257
|
+
await orm.update(items).set({ origin: newOrigin }).where(eq37(items.origin, oldOrigin));
|
|
17216
17258
|
console.log(
|
|
17217
17259
|
chalk67.green(
|
|
17218
17260
|
`Moved ${pluralItems(cnt)} from "${oldOrigin}" to "${newOrigin}".`
|
|
@@ -17684,12 +17726,12 @@ function message(error) {
|
|
|
17684
17726
|
import chalk71 from "chalk";
|
|
17685
17727
|
|
|
17686
17728
|
// src/shared/db/findPhaseBySessionId.ts
|
|
17687
|
-
import { and as and13, eq as
|
|
17729
|
+
import { and as and13, eq as eq38 } from "drizzle-orm";
|
|
17688
17730
|
async function findPhaseBySessionId(db, itemId2, claudeSessionId) {
|
|
17689
17731
|
const rows = await db.select({ phaseIdx: phaseUsage.phaseIdx }).from(phaseUsage).where(
|
|
17690
17732
|
and13(
|
|
17691
|
-
|
|
17692
|
-
|
|
17733
|
+
eq38(phaseUsage.itemId, itemId2),
|
|
17734
|
+
eq38(phaseUsage.claudeSessionId, claudeSessionId)
|
|
17693
17735
|
)
|
|
17694
17736
|
).limit(1);
|
|
17695
17737
|
return rows[0]?.phaseIdx;
|
|
@@ -19169,10 +19211,10 @@ async function start(id) {
|
|
|
19169
19211
|
|
|
19170
19212
|
// src/commands/backlog/stop.ts
|
|
19171
19213
|
import chalk94 from "chalk";
|
|
19172
|
-
import { and as and14, eq as
|
|
19214
|
+
import { and as and14, eq as eq39 } from "drizzle-orm";
|
|
19173
19215
|
async function stop() {
|
|
19174
19216
|
const { orm } = await getReady();
|
|
19175
|
-
const stopped = await orm.update(items).set({ status: "todo", currentPhase: 1 }).where(and14(
|
|
19217
|
+
const stopped = await orm.update(items).set({ status: "todo", currentPhase: 1 }).where(and14(eq39(items.status, "in-progress"), eq39(items.origin, getOrigin()))).returning({ id: items.id, name: items.name });
|
|
19176
19218
|
if (stopped.length === 0) {
|
|
19177
19219
|
console.log(chalk94.yellow("No in-progress items to stop."));
|
|
19178
19220
|
return;
|
|
@@ -19230,20 +19272,20 @@ function registerStatusCommands(cmd) {
|
|
|
19230
19272
|
|
|
19231
19273
|
// src/commands/backlog/movePhase.ts
|
|
19232
19274
|
import chalk97 from "chalk";
|
|
19233
|
-
import { count as count6, eq as
|
|
19275
|
+
import { count as count6, eq as eq42 } from "drizzle-orm";
|
|
19234
19276
|
|
|
19235
19277
|
// src/commands/backlog/reorderPhaseRows.ts
|
|
19236
|
-
import { and as and16, asc as asc11, eq as
|
|
19278
|
+
import { and as and16, asc as asc11, eq as eq41 } from "drizzle-orm";
|
|
19237
19279
|
|
|
19238
19280
|
// src/commands/backlog/reindexPhases.ts
|
|
19239
|
-
import { and as and15, asc as asc10, count as count5, eq as
|
|
19281
|
+
import { and as and15, asc as asc10, count as count5, eq as eq40 } from "drizzle-orm";
|
|
19240
19282
|
async function reindexPhases(db, itemId2) {
|
|
19241
|
-
const remaining = await db.select({ idx: planPhases.idx }).from(planPhases).where(
|
|
19283
|
+
const remaining = await db.select({ idx: planPhases.idx }).from(planPhases).where(eq40(planPhases.itemId, itemId2)).orderBy(asc10(planPhases.idx));
|
|
19242
19284
|
for (let i = 0; i < remaining.length; i++) {
|
|
19243
19285
|
const oldIdx = remaining[i].idx;
|
|
19244
19286
|
if (oldIdx === i) continue;
|
|
19245
|
-
await db.update(planTasks).set({ phaseIdx: i }).where(and15(
|
|
19246
|
-
await db.update(planPhases).set({ idx: i }).where(and15(
|
|
19287
|
+
await db.update(planTasks).set({ phaseIdx: i }).where(and15(eq40(planTasks.itemId, itemId2), eq40(planTasks.phaseIdx, oldIdx)));
|
|
19288
|
+
await db.update(planPhases).set({ idx: i }).where(and15(eq40(planPhases.itemId, itemId2), eq40(planPhases.idx, oldIdx)));
|
|
19247
19289
|
}
|
|
19248
19290
|
}
|
|
19249
19291
|
async function adjustCurrentPhase(db, item, removedIdx) {
|
|
@@ -19251,24 +19293,24 @@ async function adjustCurrentPhase(db, item, removedIdx) {
|
|
|
19251
19293
|
if (currentPhase === void 0) return;
|
|
19252
19294
|
const currentIdx = currentPhase - 1;
|
|
19253
19295
|
if (removedIdx < currentIdx) {
|
|
19254
|
-
await db.update(items).set({ currentPhase: currentPhase - 1 }).where(
|
|
19296
|
+
await db.update(items).set({ currentPhase: currentPhase - 1 }).where(eq40(items.id, item.id));
|
|
19255
19297
|
return;
|
|
19256
19298
|
}
|
|
19257
19299
|
if (removedIdx !== currentIdx) return;
|
|
19258
|
-
const [row3] = await db.select({ cnt: count5() }).from(planPhases).where(
|
|
19300
|
+
const [row3] = await db.select({ cnt: count5() }).from(planPhases).where(eq40(planPhases.itemId, item.id));
|
|
19259
19301
|
const cnt = row3?.cnt ?? 0;
|
|
19260
|
-
await db.update(items).set({ currentPhase: cnt === 0 ? null : Math.min(currentPhase, cnt) }).where(
|
|
19302
|
+
await db.update(items).set({ currentPhase: cnt === 0 ? null : Math.min(currentPhase, cnt) }).where(eq40(items.id, item.id));
|
|
19261
19303
|
}
|
|
19262
19304
|
|
|
19263
19305
|
// src/commands/backlog/reorderPhaseRows.ts
|
|
19264
19306
|
async function reorderPhaseRows(orm, itemId2, fromIdx, toIdx) {
|
|
19265
19307
|
await orm.transaction(async (tx) => {
|
|
19266
|
-
const [phaseRow] = await tx.select({ name: planPhases.name, manualChecks: planPhases.manualChecks }).from(planPhases).where(and16(
|
|
19267
|
-
const tasks = await tx.select({ idx: planTasks.idx, task: planTasks.task }).from(planTasks).where(and16(
|
|
19308
|
+
const [phaseRow] = await tx.select({ name: planPhases.name, manualChecks: planPhases.manualChecks }).from(planPhases).where(and16(eq41(planPhases.itemId, itemId2), eq41(planPhases.idx, fromIdx)));
|
|
19309
|
+
const tasks = await tx.select({ idx: planTasks.idx, task: planTasks.task }).from(planTasks).where(and16(eq41(planTasks.itemId, itemId2), eq41(planTasks.phaseIdx, fromIdx))).orderBy(asc11(planTasks.idx));
|
|
19268
19310
|
await tx.delete(planTasks).where(
|
|
19269
|
-
and16(
|
|
19311
|
+
and16(eq41(planTasks.itemId, itemId2), eq41(planTasks.phaseIdx, fromIdx))
|
|
19270
19312
|
);
|
|
19271
|
-
await tx.delete(planPhases).where(and16(
|
|
19313
|
+
await tx.delete(planPhases).where(and16(eq41(planPhases.itemId, itemId2), eq41(planPhases.idx, fromIdx)));
|
|
19272
19314
|
await reindexPhases(tx, itemId2);
|
|
19273
19315
|
await shiftPhasesUp(tx, itemId2, toIdx);
|
|
19274
19316
|
await tx.insert(planPhases).values({
|
|
@@ -19309,7 +19351,7 @@ async function movePhase(id, from, to) {
|
|
|
19309
19351
|
if (!found) return;
|
|
19310
19352
|
const { orm, item } = found;
|
|
19311
19353
|
const itemId2 = item.id;
|
|
19312
|
-
const [row3] = await orm.select({ cnt: count6() }).from(planPhases).where(
|
|
19354
|
+
const [row3] = await orm.select({ cnt: count6() }).from(planPhases).where(eq42(planPhases.itemId, itemId2));
|
|
19313
19355
|
const phaseCount = row3?.cnt ?? 0;
|
|
19314
19356
|
const fromIdx = toIndex2(from, phaseCount);
|
|
19315
19357
|
if (fromIdx === void 0) return;
|
|
@@ -19325,22 +19367,22 @@ async function movePhase(id, from, to) {
|
|
|
19325
19367
|
import chalk99 from "chalk";
|
|
19326
19368
|
|
|
19327
19369
|
// src/commands/backlog/applyPhaseUpdate.ts
|
|
19328
|
-
import { and as and17, eq as
|
|
19370
|
+
import { and as and17, eq as eq43 } from "drizzle-orm";
|
|
19329
19371
|
async function applyPhaseUpdate(orm, itemId2, phaseIdx, fields) {
|
|
19330
19372
|
await orm.transaction(async (tx) => {
|
|
19331
19373
|
if (fields.name) {
|
|
19332
19374
|
await tx.update(planPhases).set({ name: fields.name }).where(
|
|
19333
|
-
and17(
|
|
19375
|
+
and17(eq43(planPhases.itemId, itemId2), eq43(planPhases.idx, phaseIdx))
|
|
19334
19376
|
);
|
|
19335
19377
|
}
|
|
19336
19378
|
if (fields.manualCheck) {
|
|
19337
19379
|
await tx.update(planPhases).set({ manualChecks: JSON.stringify(fields.manualCheck) }).where(
|
|
19338
|
-
and17(
|
|
19380
|
+
and17(eq43(planPhases.itemId, itemId2), eq43(planPhases.idx, phaseIdx))
|
|
19339
19381
|
);
|
|
19340
19382
|
}
|
|
19341
19383
|
if (fields.task) {
|
|
19342
19384
|
await tx.delete(planTasks).where(
|
|
19343
|
-
and17(
|
|
19385
|
+
and17(eq43(planTasks.itemId, itemId2), eq43(planTasks.phaseIdx, phaseIdx))
|
|
19344
19386
|
);
|
|
19345
19387
|
if (fields.task.length) {
|
|
19346
19388
|
await tx.insert(planTasks).values(
|
|
@@ -19358,14 +19400,14 @@ async function applyPhaseUpdate(orm, itemId2, phaseIdx, fields) {
|
|
|
19358
19400
|
|
|
19359
19401
|
// src/commands/backlog/findPhase.ts
|
|
19360
19402
|
import chalk98 from "chalk";
|
|
19361
|
-
import { and as and18, count as count7, eq as
|
|
19403
|
+
import { and as and18, count as count7, eq as eq44 } from "drizzle-orm";
|
|
19362
19404
|
async function findPhase(id, phase) {
|
|
19363
19405
|
const found = await findOneItem(id);
|
|
19364
19406
|
if (!found) return void 0;
|
|
19365
19407
|
const { orm, item } = found;
|
|
19366
19408
|
const itemId2 = item.id;
|
|
19367
19409
|
const phaseIdx = Number.parseInt(phase, 10) - 1;
|
|
19368
|
-
const [row3] = await orm.select({ cnt: count7() }).from(planPhases).where(and18(
|
|
19410
|
+
const [row3] = await orm.select({ cnt: count7() }).from(planPhases).where(and18(eq44(planPhases.itemId, itemId2), eq44(planPhases.idx, phaseIdx)));
|
|
19369
19411
|
if (!row3 || row3.cnt === 0) {
|
|
19370
19412
|
console.log(
|
|
19371
19413
|
chalk98.red(
|
|
@@ -19538,16 +19580,16 @@ function registerUpdatePhaseCommand(cmd) {
|
|
|
19538
19580
|
|
|
19539
19581
|
// src/commands/backlog/removePhase.ts
|
|
19540
19582
|
import chalk100 from "chalk";
|
|
19541
|
-
import { and as and19, eq as
|
|
19583
|
+
import { and as and19, eq as eq45 } from "drizzle-orm";
|
|
19542
19584
|
async function removePhase(id, phase) {
|
|
19543
19585
|
const found = await findPhase(id, phase);
|
|
19544
19586
|
if (!found) return;
|
|
19545
19587
|
const { item, orm, itemId: itemId2, phaseIdx } = found;
|
|
19546
19588
|
await orm.transaction(async (tx) => {
|
|
19547
19589
|
await tx.delete(planTasks).where(
|
|
19548
|
-
and19(
|
|
19590
|
+
and19(eq45(planTasks.itemId, itemId2), eq45(planTasks.phaseIdx, phaseIdx))
|
|
19549
19591
|
);
|
|
19550
|
-
await tx.delete(planPhases).where(and19(
|
|
19592
|
+
await tx.delete(planPhases).where(and19(eq45(planPhases.itemId, itemId2), eq45(planPhases.idx, phaseIdx)));
|
|
19551
19593
|
await reindexPhases(tx, itemId2);
|
|
19552
19594
|
await adjustCurrentPhase(tx, item, phaseIdx);
|
|
19553
19595
|
});
|
|
@@ -19560,7 +19602,7 @@ async function removePhase(id, phase) {
|
|
|
19560
19602
|
|
|
19561
19603
|
// src/commands/backlog/update/update.ts
|
|
19562
19604
|
import chalk104 from "chalk";
|
|
19563
|
-
import { eq as
|
|
19605
|
+
import { eq as eq46 } from "drizzle-orm";
|
|
19564
19606
|
|
|
19565
19607
|
// src/commands/backlog/update/buildUpdateValues.ts
|
|
19566
19608
|
import chalk101 from "chalk";
|
|
@@ -19671,7 +19713,7 @@ async function update(id, options2) {
|
|
|
19671
19713
|
if (!built) return;
|
|
19672
19714
|
const { orm } = found;
|
|
19673
19715
|
const itemId2 = found.item.id;
|
|
19674
|
-
await orm.update(items).set(built.set).where(
|
|
19716
|
+
await orm.update(items).set(built.set).where(eq46(items.id, itemId2));
|
|
19675
19717
|
console.log(
|
|
19676
19718
|
chalk104.green(`Updated ${built.fields} on item ${formatItemId(itemId2)}.`)
|
|
19677
19719
|
);
|
|
@@ -19717,7 +19759,7 @@ function readPlanUpdate(source) {
|
|
|
19717
19759
|
}
|
|
19718
19760
|
|
|
19719
19761
|
// src/commands/backlog/updatePlan/replacePlan.ts
|
|
19720
|
-
import { eq as
|
|
19762
|
+
import { eq as eq47 } from "drizzle-orm";
|
|
19721
19763
|
|
|
19722
19764
|
// src/commands/backlog/updatePlan/clampCurrentPhase.ts
|
|
19723
19765
|
function clampCurrentPhase(currentPhase, phaseCount) {
|
|
@@ -19728,8 +19770,8 @@ function clampCurrentPhase(currentPhase, phaseCount) {
|
|
|
19728
19770
|
// src/commands/backlog/updatePlan/replacePlan.ts
|
|
19729
19771
|
async function replacePlan(orm, itemId2, phases, currentPhase) {
|
|
19730
19772
|
await orm.transaction(async (tx) => {
|
|
19731
|
-
await tx.delete(planTasks).where(
|
|
19732
|
-
await tx.delete(planPhases).where(
|
|
19773
|
+
await tx.delete(planTasks).where(eq47(planTasks.itemId, itemId2));
|
|
19774
|
+
await tx.delete(planPhases).where(eq47(planPhases.itemId, itemId2));
|
|
19733
19775
|
if (phases.length > 0) {
|
|
19734
19776
|
await tx.insert(planPhases).values(
|
|
19735
19777
|
phases.map((phase, idx) => ({
|
|
@@ -19747,7 +19789,7 @@ async function replacePlan(orm, itemId2, phases, currentPhase) {
|
|
|
19747
19789
|
if (currentPhase === void 0) return;
|
|
19748
19790
|
const clamped = clampCurrentPhase(currentPhase, phases.length);
|
|
19749
19791
|
if (clamped === currentPhase) return;
|
|
19750
|
-
await tx.update(items).set({ currentPhase: clamped }).where(
|
|
19792
|
+
await tx.update(items).set({ currentPhase: clamped }).where(eq47(items.id, itemId2));
|
|
19751
19793
|
});
|
|
19752
19794
|
}
|
|
19753
19795
|
|
|
@@ -28379,14 +28421,6 @@ async function list3() {
|
|
|
28379
28421
|
// src/commands/inbox/scan.ts
|
|
28380
28422
|
import chalk177 from "chalk";
|
|
28381
28423
|
|
|
28382
|
-
// src/shared/db/readInboxLastScan.ts
|
|
28383
|
-
import { eq as eq47 } from "drizzle-orm";
|
|
28384
|
-
var INBOX_LAST_SCAN_KEY = "inbox.lastScanAt";
|
|
28385
|
-
async function readInboxLastScan(orm) {
|
|
28386
|
-
const [row3] = await orm.select().from(metadata).where(eq47(metadata.key, INBOX_LAST_SCAN_KEY));
|
|
28387
|
-
return row3 ? new Date(row3.value) : void 0;
|
|
28388
|
-
}
|
|
28389
|
-
|
|
28390
28424
|
// src/shared/db/upsertInboxMessages.ts
|
|
28391
28425
|
async function upsertInboxMessages(orm, messages) {
|
|
28392
28426
|
if (messages.length === 0) return 0;
|
|
@@ -33856,10 +33890,10 @@ async function getAccessToken(apiKey) {
|
|
|
33856
33890
|
}
|
|
33857
33891
|
});
|
|
33858
33892
|
if (!response.ok) {
|
|
33859
|
-
const
|
|
33893
|
+
const errorText = await response.text();
|
|
33860
33894
|
throw new Error(
|
|
33861
33895
|
`Failed to get access token: ${response.status} ${response.statusText}
|
|
33862
|
-
${
|
|
33896
|
+
${errorText}`
|
|
33863
33897
|
);
|
|
33864
33898
|
}
|
|
33865
33899
|
const tokenData = await response.json();
|
|
@@ -46063,6 +46097,104 @@ function createAutoExit(exit, graceMs = DEFAULT_GRACE_MS) {
|
|
|
46063
46097
|
};
|
|
46064
46098
|
}
|
|
46065
46099
|
|
|
46100
|
+
// src/commands/sessions/daemon/inbox/isInboxScanDue.ts
|
|
46101
|
+
async function isInboxScanDue(intervalMinutes) {
|
|
46102
|
+
const last = await readInboxLastScan(await getDb());
|
|
46103
|
+
return !last || Date.now() - last.getTime() >= intervalMinutes * 6e4;
|
|
46104
|
+
}
|
|
46105
|
+
|
|
46106
|
+
// src/commands/inbox/readInboxIntervalMinutes.ts
|
|
46107
|
+
function readInboxIntervalMinutes(globalConfigPath) {
|
|
46108
|
+
const raw = loadGlobalConfigRaw(globalConfigPath);
|
|
46109
|
+
return assistConfigSchema.shape.inbox.parse(raw.inbox)?.intervalMinutes;
|
|
46110
|
+
}
|
|
46111
|
+
|
|
46112
|
+
// src/commands/sessions/daemon/inbox/readInboxSchedule.ts
|
|
46113
|
+
function readInboxSchedule() {
|
|
46114
|
+
let minutes;
|
|
46115
|
+
try {
|
|
46116
|
+
minutes = readInboxIntervalMinutes();
|
|
46117
|
+
} catch (error) {
|
|
46118
|
+
const reason4 = error instanceof Error ? error.message : String(error);
|
|
46119
|
+
return { description: `off (invalid inbox.intervalMinutes: ${reason4})` };
|
|
46120
|
+
}
|
|
46121
|
+
if (!minutes) return { description: "off (inbox.intervalMinutes unset)" };
|
|
46122
|
+
if (!process.env.ASSIST_DATABASE_URL && !loadConfig().database.url)
|
|
46123
|
+
return { description: "off (no database configured)" };
|
|
46124
|
+
return {
|
|
46125
|
+
intervalMinutes: minutes,
|
|
46126
|
+
description: `every ${minutes} minute(s)`
|
|
46127
|
+
};
|
|
46128
|
+
}
|
|
46129
|
+
|
|
46130
|
+
// src/commands/sessions/daemon/inbox/runLoggedInboxScan.ts
|
|
46131
|
+
async function runLoggedInboxScan(reason4) {
|
|
46132
|
+
daemonLog(`inbox: scan started (${reason4})`);
|
|
46133
|
+
try {
|
|
46134
|
+
const { flagged, added } = await runInboxScan(await getDb());
|
|
46135
|
+
daemonLog(`inbox: scan flagged ${flagged} message(s), ${added} new`);
|
|
46136
|
+
return void 0;
|
|
46137
|
+
} catch (error) {
|
|
46138
|
+
const message3 = error instanceof Error ? error.message : String(error);
|
|
46139
|
+
daemonLog(`inbox: scan failed: ${message3}`);
|
|
46140
|
+
return message3;
|
|
46141
|
+
}
|
|
46142
|
+
}
|
|
46143
|
+
|
|
46144
|
+
// src/commands/sessions/daemon/inbox/createInboxScanner.ts
|
|
46145
|
+
var CHECK_MS = 6e4;
|
|
46146
|
+
function createInboxScanner() {
|
|
46147
|
+
let scanning = false;
|
|
46148
|
+
let lastError;
|
|
46149
|
+
let schedule = { description: "not started" };
|
|
46150
|
+
let notify2 = () => {
|
|
46151
|
+
};
|
|
46152
|
+
const scan2 = async (reason4) => {
|
|
46153
|
+
scanning = true;
|
|
46154
|
+
notify2();
|
|
46155
|
+
lastError = await runLoggedInboxScan(reason4);
|
|
46156
|
+
scanning = false;
|
|
46157
|
+
notify2();
|
|
46158
|
+
};
|
|
46159
|
+
const tick = async () => {
|
|
46160
|
+
const next3 = readInboxSchedule();
|
|
46161
|
+
if (next3.description !== schedule.description)
|
|
46162
|
+
daemonLog(`inbox: scheduled scans ${next3.description}`);
|
|
46163
|
+
schedule = next3;
|
|
46164
|
+
if (!schedule.intervalMinutes || scanning) return;
|
|
46165
|
+
try {
|
|
46166
|
+
if (await isInboxScanDue(schedule.intervalMinutes))
|
|
46167
|
+
await scan2("scheduled");
|
|
46168
|
+
} catch (error) {
|
|
46169
|
+
daemonLog(`inbox: reading the last scan time failed: ${String(error)}`);
|
|
46170
|
+
}
|
|
46171
|
+
};
|
|
46172
|
+
return {
|
|
46173
|
+
start(onChange) {
|
|
46174
|
+
notify2 = onChange;
|
|
46175
|
+
void tick();
|
|
46176
|
+
const timer = setInterval(() => void tick(), CHECK_MS);
|
|
46177
|
+
timer.unref();
|
|
46178
|
+
return () => clearInterval(timer);
|
|
46179
|
+
},
|
|
46180
|
+
scanNow() {
|
|
46181
|
+
if (scanning) return false;
|
|
46182
|
+
void scan2("requested");
|
|
46183
|
+
return true;
|
|
46184
|
+
},
|
|
46185
|
+
status() {
|
|
46186
|
+
return {
|
|
46187
|
+
scanning,
|
|
46188
|
+
intervalMinutes: schedule.intervalMinutes ?? null,
|
|
46189
|
+
lastError: lastError ?? null
|
|
46190
|
+
};
|
|
46191
|
+
}
|
|
46192
|
+
};
|
|
46193
|
+
}
|
|
46194
|
+
|
|
46195
|
+
// src/commands/sessions/daemon/inbox/inboxScanner.ts
|
|
46196
|
+
var inboxScanner = createInboxScanner();
|
|
46197
|
+
|
|
46066
46198
|
// src/commands/sessions/daemon/pollRepoConfigCache.ts
|
|
46067
46199
|
var POLL_MS = 6e4;
|
|
46068
46200
|
function cacheSnapshot() {
|
|
@@ -53110,6 +53242,16 @@ var handleTypePromptToWriter = (client, m, d) => {
|
|
|
53110
53242
|
});
|
|
53111
53243
|
};
|
|
53112
53244
|
|
|
53245
|
+
// src/commands/sessions/daemon/inbox/inboxHandlers.ts
|
|
53246
|
+
var inboxHandlers = {
|
|
53247
|
+
"inbox-status": (client) => sendTo(client, { type: "inbox-status", ...inboxScanner.status() }),
|
|
53248
|
+
"inbox-scan": (client) => {
|
|
53249
|
+
const started = inboxScanner.scanNow();
|
|
53250
|
+
if (!started) daemonLog("inbox: scan requested while one is running");
|
|
53251
|
+
sendTo(client, { type: "inbox-scan", started });
|
|
53252
|
+
}
|
|
53253
|
+
};
|
|
53254
|
+
|
|
53113
53255
|
// src/commands/sessions/shared/parseTranscript.ts
|
|
53114
53256
|
import * as fs56 from "fs";
|
|
53115
53257
|
|
|
@@ -53432,6 +53574,7 @@ var messageHandlers = {
|
|
|
53432
53574
|
"auto-update": (client) => sendTo(client, autoUpdateReply()),
|
|
53433
53575
|
"auto-update-control": handleAutoUpdateControl,
|
|
53434
53576
|
"search-history": (client, _m, d) => handleSearchHistory(client, d),
|
|
53577
|
+
...inboxHandlers,
|
|
53435
53578
|
"reload-links": (client, m) => {
|
|
53436
53579
|
daemonLog("reload-links received");
|
|
53437
53580
|
m.links.reload();
|
|
@@ -53647,85 +53790,6 @@ async function recoverFromAddrInUse(server, manager, checkAutoExit) {
|
|
|
53647
53790
|
listenWithSingleOnListening(server, manager, checkAutoExit);
|
|
53648
53791
|
}
|
|
53649
53792
|
|
|
53650
|
-
// src/commands/sessions/daemon/inbox/firstDelayMs.ts
|
|
53651
|
-
async function firstDelayMs(intervalMs) {
|
|
53652
|
-
try {
|
|
53653
|
-
const last = await readInboxLastScan(await getDb());
|
|
53654
|
-
if (!last) return 0;
|
|
53655
|
-
return Math.max(0, last.getTime() + intervalMs - Date.now());
|
|
53656
|
-
} catch (error) {
|
|
53657
|
-
daemonLog(`inbox: reading the last scan time failed: ${errorText(error)}`);
|
|
53658
|
-
return intervalMs;
|
|
53659
|
-
}
|
|
53660
|
-
}
|
|
53661
|
-
function errorText(error) {
|
|
53662
|
-
return error instanceof Error ? error.message : String(error);
|
|
53663
|
-
}
|
|
53664
|
-
|
|
53665
|
-
// src/commands/inbox/readInboxIntervalMinutes.ts
|
|
53666
|
-
function readInboxIntervalMinutes(globalConfigPath) {
|
|
53667
|
-
const raw = loadGlobalConfigRaw(globalConfigPath);
|
|
53668
|
-
return assistConfigSchema.shape.inbox.parse(raw.inbox)?.intervalMinutes;
|
|
53669
|
-
}
|
|
53670
|
-
|
|
53671
|
-
// src/commands/sessions/daemon/inbox/intervalMinutes.ts
|
|
53672
|
-
function intervalMinutes() {
|
|
53673
|
-
try {
|
|
53674
|
-
return readInboxIntervalMinutes();
|
|
53675
|
-
} catch (error) {
|
|
53676
|
-
daemonLog(
|
|
53677
|
-
`inbox: ignoring invalid inbox.intervalMinutes: ${errorText2(error)}`
|
|
53678
|
-
);
|
|
53679
|
-
return void 0;
|
|
53680
|
-
}
|
|
53681
|
-
}
|
|
53682
|
-
function errorText2(error) {
|
|
53683
|
-
return error instanceof Error ? error.message : String(error);
|
|
53684
|
-
}
|
|
53685
|
-
|
|
53686
|
-
// src/commands/sessions/daemon/startInboxScans.ts
|
|
53687
|
-
function errorText3(error) {
|
|
53688
|
-
return error instanceof Error ? error.message : String(error);
|
|
53689
|
-
}
|
|
53690
|
-
function startInboxScans(onAdded) {
|
|
53691
|
-
const minutes = intervalMinutes();
|
|
53692
|
-
if (!minutes) {
|
|
53693
|
-
daemonLog("inbox: scheduled scans off (inbox.intervalMinutes unset)");
|
|
53694
|
-
return () => {
|
|
53695
|
-
};
|
|
53696
|
-
}
|
|
53697
|
-
if (!process.env.ASSIST_DATABASE_URL && !loadConfig().database.url) {
|
|
53698
|
-
daemonLog("inbox: scheduled scans off (no database configured)");
|
|
53699
|
-
return () => {
|
|
53700
|
-
};
|
|
53701
|
-
}
|
|
53702
|
-
const intervalMs = minutes * 6e4;
|
|
53703
|
-
let timer;
|
|
53704
|
-
let stopped = false;
|
|
53705
|
-
const schedule = (delayMs) => {
|
|
53706
|
-
if (stopped) return;
|
|
53707
|
-
timer = setTimeout(() => void tick(), delayMs);
|
|
53708
|
-
timer.unref();
|
|
53709
|
-
};
|
|
53710
|
-
const tick = async () => {
|
|
53711
|
-
daemonLog("inbox: scan started");
|
|
53712
|
-
try {
|
|
53713
|
-
const { flagged, added } = await runInboxScan(await getDb());
|
|
53714
|
-
daemonLog(`inbox: scan flagged ${flagged} message(s), ${added} new`);
|
|
53715
|
-
if (added > 0) onAdded();
|
|
53716
|
-
} catch (error) {
|
|
53717
|
-
daemonLog(`inbox: scan failed: ${errorText3(error)}`);
|
|
53718
|
-
}
|
|
53719
|
-
schedule(intervalMs);
|
|
53720
|
-
};
|
|
53721
|
-
daemonLog(`inbox: scanning every ${minutes} minute(s)`);
|
|
53722
|
-
void firstDelayMs(intervalMs).then(schedule);
|
|
53723
|
-
return () => {
|
|
53724
|
-
stopped = true;
|
|
53725
|
-
clearTimeout(timer);
|
|
53726
|
-
};
|
|
53727
|
-
}
|
|
53728
|
-
|
|
53729
53793
|
// src/commands/sessions/daemon/runDaemon.ts
|
|
53730
53794
|
async function runDaemon() {
|
|
53731
53795
|
mkdirSync41(daemonPaths.dir, { recursive: true });
|
|
@@ -53745,7 +53809,7 @@ async function runDaemon() {
|
|
|
53745
53809
|
setDaemonLogSink(manager.clients.emitLog);
|
|
53746
53810
|
startDaemonLogTrimmer();
|
|
53747
53811
|
pollRepoConfigCache();
|
|
53748
|
-
|
|
53812
|
+
inboxScanner.start(() => broadcast(manager.clients, { type: "inbox" }));
|
|
53749
53813
|
await startDaemonServer(manager, checkAutoExit);
|
|
53750
53814
|
await refreshRepoConfigCacheOnStart();
|
|
53751
53815
|
}
|