@staff0rd/assist 0.632.1 → 0.634.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 +448 -448
- package/dist/index.js +226 -138
- 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.634.0",
|
|
10
10
|
type: "module",
|
|
11
11
|
main: "dist/index.js",
|
|
12
12
|
bin: {
|
|
@@ -1423,8 +1423,8 @@ var options = [
|
|
|
1423
1423
|
];
|
|
1424
1424
|
|
|
1425
1425
|
// src/commands/verify/init/getAvailableOptions/index.ts
|
|
1426
|
-
function resolveDescription(
|
|
1427
|
-
return typeof
|
|
1426
|
+
function resolveDescription(desc8, setup2) {
|
|
1427
|
+
return typeof desc8 === "function" ? desc8(setup2) : desc8;
|
|
1428
1428
|
}
|
|
1429
1429
|
function toVerifyOption(def, setup2) {
|
|
1430
1430
|
return {
|
|
@@ -5589,8 +5589,8 @@ async function assertMigrationsInSync(exec3) {
|
|
|
5589
5589
|
// src/shared/db/migrations/MigrationExecutor.ts
|
|
5590
5590
|
function pgExecutor(queryable) {
|
|
5591
5591
|
return {
|
|
5592
|
-
exec: (
|
|
5593
|
-
query: async (
|
|
5592
|
+
exec: (sql29) => queryable.query(sql29),
|
|
5593
|
+
query: async (sql29, params) => (await queryable.query(sql29, params)).rows
|
|
5594
5594
|
};
|
|
5595
5595
|
}
|
|
5596
5596
|
|
|
@@ -5911,8 +5911,8 @@ async function buildDump(tables, copyOut) {
|
|
|
5911
5911
|
// src/commands/backlog/dump/copyTableOut.ts
|
|
5912
5912
|
import { to as copyTo } from "pg-copy-streams";
|
|
5913
5913
|
async function copyTableOut(client, table) {
|
|
5914
|
-
const
|
|
5915
|
-
const stream = client.query(copyTo(
|
|
5914
|
+
const sql29 = `COPY ${table.name} (${table.columns.join(", ")}) TO STDOUT`;
|
|
5915
|
+
const stream = client.query(copyTo(sql29));
|
|
5916
5916
|
const chunks = [];
|
|
5917
5917
|
for await (const chunk of stream) {
|
|
5918
5918
|
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
@@ -11712,8 +11712,7 @@ async function respondPagedRows(req, res, load3) {
|
|
|
11712
11712
|
const params = new URL(req.url ?? "/", "http://localhost").searchParams;
|
|
11713
11713
|
const page = Math.max(0, Number(params.get("page")) || 0);
|
|
11714
11714
|
const limit = Number(params.get("pageSize")) || DEFAULT_PAGE_SIZE;
|
|
11715
|
-
|
|
11716
|
-
respondJson(res, 200, { rows, total });
|
|
11715
|
+
respondJson(res, 200, await load3({ limit, offset: page * limit }, params));
|
|
11717
11716
|
}
|
|
11718
11717
|
|
|
11719
11718
|
// src/commands/sessions/web/listUsageHistory.ts
|
|
@@ -11724,32 +11723,111 @@ function listUsageHistory(req, res) {
|
|
|
11724
11723
|
return respondPagedRows(req, res, async (range, params) => {
|
|
11725
11724
|
const window = parseWindow(params.get("window"));
|
|
11726
11725
|
const db = await getDb();
|
|
11727
|
-
|
|
11726
|
+
const [rows, total] = await Promise.all([
|
|
11728
11727
|
listUsagePeaks(db, { ...range, window }),
|
|
11729
11728
|
countUsagePeaks(db, window)
|
|
11730
11729
|
]);
|
|
11730
|
+
return { rows, total };
|
|
11731
11731
|
});
|
|
11732
11732
|
}
|
|
11733
11733
|
|
|
11734
|
-
// src/shared/db/
|
|
11735
|
-
import { sql as sql17 } from "drizzle-orm";
|
|
11736
|
-
async function
|
|
11734
|
+
// src/shared/db/countItemUsageByOrigin.ts
|
|
11735
|
+
import { asc as asc8, desc as desc3, eq as eq20, sql as sql17 } from "drizzle-orm";
|
|
11736
|
+
async function countItemUsageByOrigin(db) {
|
|
11737
|
+
const count8 = sql17`count(distinct ${phaseUsage.itemId})::int`;
|
|
11738
|
+
const rows = await db.select({ origin: items.origin, count: count8 }).from(items).innerJoin(phaseUsage, eq20(phaseUsage.itemId, items.id)).groupBy(items.origin).orderBy(desc3(count8), asc8(items.origin));
|
|
11739
|
+
return rows.map((row) => ({ origin: row.origin, count: Number(row.count) }));
|
|
11740
|
+
}
|
|
11741
|
+
|
|
11742
|
+
// src/shared/db/itemUsageWhere.ts
|
|
11743
|
+
import { and as and9, eq as eq21, ne as ne2 } from "drizzle-orm";
|
|
11744
|
+
function parseItemUsageStatus(value) {
|
|
11745
|
+
return value === "done" || value === "running" ? value : void 0;
|
|
11746
|
+
}
|
|
11747
|
+
function statusClause(status3) {
|
|
11748
|
+
if (status3 === "done") return eq21(items.status, "done");
|
|
11749
|
+
if (status3 === "running") return ne2(items.status, "done");
|
|
11750
|
+
return void 0;
|
|
11751
|
+
}
|
|
11752
|
+
function itemUsageWhere(filter) {
|
|
11753
|
+
return and9(
|
|
11754
|
+
filter?.origin ? eq21(items.origin, filter.origin) : void 0,
|
|
11755
|
+
statusClause(filter?.status)
|
|
11756
|
+
);
|
|
11757
|
+
}
|
|
11758
|
+
|
|
11759
|
+
// src/shared/db/parseItemUsageSort.ts
|
|
11760
|
+
var sortFields = [
|
|
11761
|
+
"phases",
|
|
11762
|
+
"active",
|
|
11763
|
+
"tokens",
|
|
11764
|
+
"peakContext",
|
|
11765
|
+
"lastPhase"
|
|
11766
|
+
];
|
|
11767
|
+
var defaultItemUsageSort = {
|
|
11768
|
+
field: "lastPhase",
|
|
11769
|
+
direction: "desc"
|
|
11770
|
+
};
|
|
11771
|
+
function parseItemUsageSort(field, direction) {
|
|
11772
|
+
return {
|
|
11773
|
+
field: sortFields.find((known) => known === field) ?? defaultItemUsageSort.field,
|
|
11774
|
+
direction: direction === "asc" ? "asc" : "desc"
|
|
11775
|
+
};
|
|
11776
|
+
}
|
|
11777
|
+
|
|
11778
|
+
// src/shared/db/itemUsageStats.ts
|
|
11779
|
+
import { eq as eq22, sql as sql18 } from "drizzle-orm";
|
|
11780
|
+
function median(value) {
|
|
11781
|
+
return sql18`coalesce(percentile_cont(0.5) within group (order by (${value})::double precision), 0)`;
|
|
11782
|
+
}
|
|
11783
|
+
async function itemUsageStats(db, options2) {
|
|
11784
|
+
const totals = phaseUsageTotals(db);
|
|
11785
|
+
const planned = planPhaseCounts(db);
|
|
11737
11786
|
const [row] = await db.select({
|
|
11738
|
-
|
|
11739
|
-
|
|
11740
|
-
|
|
11787
|
+
itemCount: sql18`count(*)::int`,
|
|
11788
|
+
doneCount: sql18`count(*) filter (where ${items.status} = 'done')::int`,
|
|
11789
|
+
repoCount: sql18`count(distinct ${items.origin})::int`,
|
|
11790
|
+
medianPhases: median(
|
|
11791
|
+
sql18`coalesce(${planned.count}, ${totals.recordedPhases})`
|
|
11792
|
+
),
|
|
11793
|
+
medianActiveMs: median(totals.activeMs),
|
|
11794
|
+
medianTokens: median(sql18`${totals.tokensUp} + ${totals.tokensDown}`)
|
|
11795
|
+
}).from(items).innerJoin(totals, eq22(totals.itemId, items.id)).leftJoin(planned, eq22(planned.itemId, items.id)).where(itemUsageWhere(options2));
|
|
11796
|
+
return {
|
|
11797
|
+
itemCount: Number(row?.itemCount ?? 0),
|
|
11798
|
+
doneCount: Number(row?.doneCount ?? 0),
|
|
11799
|
+
repoCount: Number(row?.repoCount ?? 0),
|
|
11800
|
+
medianPhases: Number(row?.medianPhases ?? 0),
|
|
11801
|
+
medianActiveMs: Number(row?.medianActiveMs ?? 0),
|
|
11802
|
+
medianTokens: Number(row?.medianTokens ?? 0)
|
|
11803
|
+
};
|
|
11741
11804
|
}
|
|
11742
11805
|
|
|
11743
11806
|
// src/shared/db/listItemUsageSummaries.ts
|
|
11744
|
-
import {
|
|
11807
|
+
import { eq as eq23 } from "drizzle-orm";
|
|
11808
|
+
|
|
11809
|
+
// src/shared/db/itemUsageOrderBy.ts
|
|
11810
|
+
import { desc as desc4, sql as sql19 } from "drizzle-orm";
|
|
11811
|
+
function itemUsageOrderBy(joins, sort = defaultItemUsageSort) {
|
|
11812
|
+
const { totals, planned, lastPhase } = joins;
|
|
11813
|
+
const sortable = {
|
|
11814
|
+
phases: sql19`coalesce(${planned.count}, ${totals.recordedPhases})`,
|
|
11815
|
+
active: sql19`${totals.activeMs}`,
|
|
11816
|
+
tokens: sql19`${totals.tokensUp} + ${totals.tokensDown}`,
|
|
11817
|
+
peakContext: sql19`${totals.peakContextPct}`,
|
|
11818
|
+
lastPhase: sql19`${lastPhase.at}`
|
|
11819
|
+
};
|
|
11820
|
+
const order = sort.direction === "asc" ? sql19`asc` : sql19`desc`;
|
|
11821
|
+
return [sql19`${sortable[sort.field]} ${order} nulls last`, desc4(items.id)];
|
|
11822
|
+
}
|
|
11745
11823
|
|
|
11746
11824
|
// src/shared/db/lastPhaseActivity.ts
|
|
11747
|
-
import { sql as
|
|
11825
|
+
import { sql as sql20 } from "drizzle-orm";
|
|
11748
11826
|
function lastPhaseActivity(db) {
|
|
11749
11827
|
return db.select({
|
|
11750
11828
|
itemId: phaseSessions.itemId,
|
|
11751
|
-
at:
|
|
11752
|
-
atIso:
|
|
11829
|
+
at: sql20`max(${phaseSessions.createdAt})`.as("last_phase_at"),
|
|
11830
|
+
atIso: sql20`to_char(max(${phaseSessions.createdAt}) at time zone 'utc', 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"')`.as(
|
|
11753
11831
|
"last_phase_at_iso"
|
|
11754
11832
|
)
|
|
11755
11833
|
}).from(phaseSessions).groupBy(phaseSessions.itemId).as("last_phase_activity");
|
|
@@ -11787,19 +11865,29 @@ async function listItemUsageSummaries(db, options2) {
|
|
|
11787
11865
|
activeMs: totals.activeMs,
|
|
11788
11866
|
peakContextPct: totals.peakContextPct,
|
|
11789
11867
|
lastPhaseAt: lastPhase.atIso
|
|
11790
|
-
}).from(items).innerJoin(totals,
|
|
11868
|
+
}).from(items).innerJoin(totals, eq23(totals.itemId, items.id)).leftJoin(planned, eq23(planned.itemId, items.id)).leftJoin(lastPhase, eq23(lastPhase.itemId, items.id)).where(itemUsageWhere(options2)).orderBy(
|
|
11869
|
+
...itemUsageOrderBy({ totals, planned, lastPhase }, options2?.sort)
|
|
11870
|
+
);
|
|
11791
11871
|
const rows = options2?.limit === void 0 ? await query : await query.limit(options2.limit).offset(options2.offset ?? 0);
|
|
11792
11872
|
return rows.map(toItemUsageSummary);
|
|
11793
11873
|
}
|
|
11794
11874
|
|
|
11795
11875
|
// src/commands/sessions/web/listUsageItems.ts
|
|
11796
11876
|
function listUsageItems(req, res) {
|
|
11797
|
-
return respondPagedRows(req, res, async (range) => {
|
|
11877
|
+
return respondPagedRows(req, res, async (range, params) => {
|
|
11878
|
+
const origin = params.get("origin") || void 0;
|
|
11879
|
+
const status3 = parseItemUsageStatus(params.get("status"));
|
|
11880
|
+
const sort = parseItemUsageSort(
|
|
11881
|
+
params.get("sort"),
|
|
11882
|
+
params.get("direction")
|
|
11883
|
+
);
|
|
11798
11884
|
const db = await getDb();
|
|
11799
|
-
|
|
11800
|
-
listItemUsageSummaries(db, range),
|
|
11801
|
-
|
|
11885
|
+
const [rows, summary, origins] = await Promise.all([
|
|
11886
|
+
listItemUsageSummaries(db, { ...range, origin, status: status3, sort }),
|
|
11887
|
+
itemUsageStats(db, { origin, status: status3 }),
|
|
11888
|
+
countItemUsageByOrigin(db)
|
|
11802
11889
|
]);
|
|
11890
|
+
return { rows, total: summary.itemCount, summary, origins };
|
|
11803
11891
|
});
|
|
11804
11892
|
}
|
|
11805
11893
|
|
|
@@ -13622,11 +13710,11 @@ function registerActivityCommands(cmd) {
|
|
|
13622
13710
|
|
|
13623
13711
|
// src/commands/backlog/associate-github/index.ts
|
|
13624
13712
|
import chalk66 from "chalk";
|
|
13625
|
-
import { eq as
|
|
13713
|
+
import { eq as eq25 } from "drizzle-orm";
|
|
13626
13714
|
|
|
13627
13715
|
// src/commands/backlog/beginAssociation.ts
|
|
13628
13716
|
import chalk65 from "chalk";
|
|
13629
|
-
import { eq as
|
|
13717
|
+
import { eq as eq24 } from "drizzle-orm";
|
|
13630
13718
|
async function beginAssociation(id, options2, clearPatch, label2) {
|
|
13631
13719
|
const found = await findOneItem(id);
|
|
13632
13720
|
if (!found) {
|
|
@@ -13636,7 +13724,7 @@ async function beginAssociation(id, options2, clearPatch, label2) {
|
|
|
13636
13724
|
const { orm } = found;
|
|
13637
13725
|
const itemId2 = found.item.id;
|
|
13638
13726
|
if (options2.clear) {
|
|
13639
|
-
await orm.update(items).set(clearPatch).where(
|
|
13727
|
+
await orm.update(items).set(clearPatch).where(eq24(items.id, itemId2));
|
|
13640
13728
|
console.log(
|
|
13641
13729
|
chalk65.green(
|
|
13642
13730
|
`Cleared ${label2} association on item ${formatItemId(itemId2)}.`
|
|
@@ -13704,7 +13792,7 @@ async function associateGithub(id, issue, options2) {
|
|
|
13704
13792
|
return;
|
|
13705
13793
|
}
|
|
13706
13794
|
const title = fetchGithubIssueTitle(normalized);
|
|
13707
|
-
await orm.update(items).set({ githubIssue: normalized, jiraKey: null }).where(
|
|
13795
|
+
await orm.update(items).set({ githubIssue: normalized, jiraKey: null }).where(eq25(items.id, itemId2));
|
|
13708
13796
|
console.log(
|
|
13709
13797
|
chalk66.green(`Associated ${normalized} with item ${formatItemId(itemId2)}.`),
|
|
13710
13798
|
title ? chalk66.dim(`(${title})`) : ""
|
|
@@ -13718,7 +13806,7 @@ function registerAssociateGithubCommand(cmd) {
|
|
|
13718
13806
|
|
|
13719
13807
|
// src/commands/backlog/associate-jira/index.ts
|
|
13720
13808
|
import chalk68 from "chalk";
|
|
13721
|
-
import { eq as
|
|
13809
|
+
import { eq as eq26 } from "drizzle-orm";
|
|
13722
13810
|
|
|
13723
13811
|
// src/commands/jira/fetchIssue.ts
|
|
13724
13812
|
import { execSync as execSync27 } from "child_process";
|
|
@@ -13783,7 +13871,7 @@ async function associateJira(id, key, options2) {
|
|
|
13783
13871
|
const parsed = fetchIssue(normalized, "summary");
|
|
13784
13872
|
const fields = parsed?.fields;
|
|
13785
13873
|
const summary = fields?.summary;
|
|
13786
|
-
await orm.update(items).set({ jiraKey: normalized, githubIssue: null }).where(
|
|
13874
|
+
await orm.update(items).set({ jiraKey: normalized, githubIssue: null }).where(eq26(items.id, itemId2));
|
|
13787
13875
|
console.log(
|
|
13788
13876
|
chalk68.green(`Associated ${normalized} with item ${formatItemId(itemId2)}.`),
|
|
13789
13877
|
summary ? chalk68.dim(`(${summary})`) : ""
|
|
@@ -14187,8 +14275,8 @@ async function readStdinBuffer() {
|
|
|
14187
14275
|
import { finished } from "stream/promises";
|
|
14188
14276
|
import { from as copyFrom } from "pg-copy-streams";
|
|
14189
14277
|
async function copyTableIn(client, table, data) {
|
|
14190
|
-
const
|
|
14191
|
-
const stream = client.query(copyFrom(
|
|
14278
|
+
const sql29 = `COPY ${table.name} (${table.columns.join(", ")}) FROM STDIN`;
|
|
14279
|
+
const stream = client.query(copyFrom(sql29));
|
|
14192
14280
|
stream.end(data);
|
|
14193
14281
|
await finished(stream);
|
|
14194
14282
|
}
|
|
@@ -14290,15 +14378,15 @@ function isClaudeCode() {
|
|
|
14290
14378
|
}
|
|
14291
14379
|
|
|
14292
14380
|
// src/commands/backlog/insertPhaseAt.ts
|
|
14293
|
-
import { eq as
|
|
14381
|
+
import { eq as eq28 } from "drizzle-orm";
|
|
14294
14382
|
|
|
14295
14383
|
// src/commands/backlog/shiftPhasesUp.ts
|
|
14296
|
-
import { and as
|
|
14384
|
+
import { and as and10, desc as desc5, eq as eq27, gte } from "drizzle-orm";
|
|
14297
14385
|
async function shiftPhasesUp(db, itemId2, fromIdx) {
|
|
14298
|
-
const toShift = await db.select({ idx: planPhases.idx }).from(planPhases).where(
|
|
14386
|
+
const toShift = await db.select({ idx: planPhases.idx }).from(planPhases).where(and10(eq27(planPhases.itemId, itemId2), gte(planPhases.idx, fromIdx))).orderBy(desc5(planPhases.idx));
|
|
14299
14387
|
for (const p of toShift) {
|
|
14300
|
-
await db.update(planTasks).set({ phaseIdx: p.idx + 1 }).where(
|
|
14301
|
-
await db.update(planPhases).set({ idx: p.idx + 1 }).where(
|
|
14388
|
+
await db.update(planTasks).set({ phaseIdx: p.idx + 1 }).where(and10(eq27(planTasks.itemId, itemId2), eq27(planTasks.phaseIdx, p.idx)));
|
|
14389
|
+
await db.update(planPhases).set({ idx: p.idx + 1 }).where(and10(eq27(planPhases.itemId, itemId2), eq27(planPhases.idx, p.idx)));
|
|
14302
14390
|
}
|
|
14303
14391
|
}
|
|
14304
14392
|
|
|
@@ -14311,17 +14399,17 @@ async function insertPhaseAt(orm, itemId2, phaseIdx, name, tasks, manualChecks,
|
|
|
14311
14399
|
await tx.insert(planTasks).values(tasks.map((task, i) => ({ itemId: itemId2, phaseIdx, idx: i, task })));
|
|
14312
14400
|
}
|
|
14313
14401
|
if (currentPhase !== void 0 && currentPhase - 1 >= phaseIdx) {
|
|
14314
|
-
await tx.update(items).set({ currentPhase: phaseIdx + 1 }).where(
|
|
14402
|
+
await tx.update(items).set({ currentPhase: phaseIdx + 1 }).where(eq28(items.id, itemId2));
|
|
14315
14403
|
}
|
|
14316
14404
|
});
|
|
14317
14405
|
}
|
|
14318
14406
|
|
|
14319
14407
|
// src/commands/backlog/insertSubtask.ts
|
|
14320
|
-
import { sql as
|
|
14408
|
+
import { sql as sql21 } from "drizzle-orm";
|
|
14321
14409
|
async function insertSubtask(orm, itemId2, title, description) {
|
|
14322
14410
|
await orm.insert(itemSubtasks).values({
|
|
14323
14411
|
itemId: itemId2,
|
|
14324
|
-
idx:
|
|
14412
|
+
idx: sql21`(SELECT COALESCE(MAX(${itemSubtasks.idx}) + 1, 0) FROM ${itemSubtasks} WHERE ${itemSubtasks.itemId} = ${itemId2})`,
|
|
14325
14413
|
title,
|
|
14326
14414
|
description: description ?? null,
|
|
14327
14415
|
status: "todo"
|
|
@@ -14483,9 +14571,9 @@ import chalk78 from "chalk";
|
|
|
14483
14571
|
|
|
14484
14572
|
// src/commands/backlog/resolveInsertPosition.ts
|
|
14485
14573
|
import chalk77 from "chalk";
|
|
14486
|
-
import { count as count3, eq as
|
|
14574
|
+
import { count as count3, eq as eq29 } from "drizzle-orm";
|
|
14487
14575
|
async function resolveInsertPosition(orm, itemId2, position) {
|
|
14488
|
-
const [row] = await orm.select({ cnt: count3() }).from(planPhases).where(
|
|
14576
|
+
const [row] = await orm.select({ cnt: count3() }).from(planPhases).where(eq29(planPhases.itemId, itemId2));
|
|
14489
14577
|
const phaseCount = row?.cnt ?? 0;
|
|
14490
14578
|
if (position === void 0) return phaseCount;
|
|
14491
14579
|
const pos = Number.parseInt(position, 10);
|
|
@@ -14780,9 +14868,9 @@ function hasCycle(adjacency, fromId, toId) {
|
|
|
14780
14868
|
}
|
|
14781
14869
|
|
|
14782
14870
|
// src/commands/backlog/loadDependencyGraph.ts
|
|
14783
|
-
import { eq as
|
|
14871
|
+
import { eq as eq30 } from "drizzle-orm";
|
|
14784
14872
|
async function loadDependencyGraph(orm) {
|
|
14785
|
-
const rows = await orm.select({ itemId: links.itemId, targetId: links.targetId }).from(links).where(
|
|
14873
|
+
const rows = await orm.select({ itemId: links.itemId, targetId: links.targetId }).from(links).where(eq30(links.type, "depends-on"));
|
|
14786
14874
|
const graph = /* @__PURE__ */ new Map();
|
|
14787
14875
|
for (const { itemId: itemId2, targetId } of rows) {
|
|
14788
14876
|
const bucket = graph.get(itemId2);
|
|
@@ -14849,7 +14937,7 @@ async function link(fromId, toId, opts) {
|
|
|
14849
14937
|
|
|
14850
14938
|
// src/commands/backlog/unlink.ts
|
|
14851
14939
|
import chalk85 from "chalk";
|
|
14852
|
-
import { and as
|
|
14940
|
+
import { and as and11, eq as eq31 } from "drizzle-orm";
|
|
14853
14941
|
async function unlink(fromId, toId) {
|
|
14854
14942
|
const fromNum = parseItemId(fromId);
|
|
14855
14943
|
const toNum = parseItemId(toId);
|
|
@@ -14873,7 +14961,7 @@ async function unlink(fromId, toId) {
|
|
|
14873
14961
|
);
|
|
14874
14962
|
return;
|
|
14875
14963
|
}
|
|
14876
|
-
await orm.delete(links).where(
|
|
14964
|
+
await orm.delete(links).where(and11(eq31(links.itemId, fromNum), eq31(links.targetId, toNum)));
|
|
14877
14965
|
console.log(
|
|
14878
14966
|
chalk85.green(
|
|
14879
14967
|
`Removed link from ${formatItemId(fromNum)} to ${formatItemId(toNum)}.`
|
|
@@ -14893,7 +14981,7 @@ function registerLinkCommands(cmd) {
|
|
|
14893
14981
|
|
|
14894
14982
|
// src/commands/backlog/move-repo/index.ts
|
|
14895
14983
|
import chalk87 from "chalk";
|
|
14896
|
-
import { eq as
|
|
14984
|
+
import { eq as eq33 } from "drizzle-orm";
|
|
14897
14985
|
|
|
14898
14986
|
// src/commands/backlog/move-repo/confirmMove.ts
|
|
14899
14987
|
import chalk86 from "chalk";
|
|
@@ -14908,9 +14996,9 @@ async function confirmMove(cnt, oldOrigin, newOrigin) {
|
|
|
14908
14996
|
}
|
|
14909
14997
|
|
|
14910
14998
|
// src/commands/backlog/move-repo/countByOrigin.ts
|
|
14911
|
-
import { count as count4, eq as
|
|
14999
|
+
import { count as count4, eq as eq32 } from "drizzle-orm";
|
|
14912
15000
|
async function countByOrigin(orm, origin) {
|
|
14913
|
-
const [{ cnt }] = await orm.select({ cnt: count4() }).from(items).where(
|
|
15001
|
+
const [{ cnt }] = await orm.select({ cnt: count4() }).from(items).where(eq32(items.origin, origin));
|
|
14914
15002
|
return cnt;
|
|
14915
15003
|
}
|
|
14916
15004
|
|
|
@@ -14953,7 +15041,7 @@ async function moveRepo(oldOriginRaw, newOriginRaw, options2 = {}) {
|
|
|
14953
15041
|
console.log(chalk87.yellow("Move cancelled; no changes made."));
|
|
14954
15042
|
return;
|
|
14955
15043
|
}
|
|
14956
|
-
await orm.update(items).set({ origin: newOrigin }).where(
|
|
15044
|
+
await orm.update(items).set({ origin: newOrigin }).where(eq33(items.origin, oldOrigin));
|
|
14957
15045
|
console.log(
|
|
14958
15046
|
chalk87.green(
|
|
14959
15047
|
`Moved ${pluralItems(cnt)} from "${oldOrigin}" to "${newOrigin}".`
|
|
@@ -15353,10 +15441,10 @@ async function start(id) {
|
|
|
15353
15441
|
|
|
15354
15442
|
// src/commands/backlog/stop/index.ts
|
|
15355
15443
|
import chalk99 from "chalk";
|
|
15356
|
-
import { and as
|
|
15444
|
+
import { and as and12, eq as eq34 } from "drizzle-orm";
|
|
15357
15445
|
async function stop() {
|
|
15358
15446
|
const { orm } = await getReady();
|
|
15359
|
-
const stopped = await orm.update(items).set({ status: "todo", currentPhase: 1 }).where(
|
|
15447
|
+
const stopped = await orm.update(items).set({ status: "todo", currentPhase: 1 }).where(and12(eq34(items.status, "in-progress"), eq34(items.origin, getOrigin()))).returning({ id: items.id, name: items.name });
|
|
15360
15448
|
if (stopped.length === 0) {
|
|
15361
15449
|
console.log(chalk99.yellow("No in-progress items to stop."));
|
|
15362
15450
|
return;
|
|
@@ -15473,13 +15561,13 @@ async function findSubtask(id, index3) {
|
|
|
15473
15561
|
}
|
|
15474
15562
|
|
|
15475
15563
|
// src/commands/backlog/updateSubtask.ts
|
|
15476
|
-
import { and as
|
|
15564
|
+
import { and as and13, eq as eq35 } from "drizzle-orm";
|
|
15477
15565
|
async function updateSubtask(orm, itemId2, idx, fields) {
|
|
15478
15566
|
const set = {};
|
|
15479
15567
|
if (fields.title !== void 0) set.title = fields.title;
|
|
15480
15568
|
if (fields.description !== void 0) set.description = fields.description;
|
|
15481
15569
|
if (fields.status !== void 0) set.status = fields.status;
|
|
15482
|
-
const [row] = await orm.update(itemSubtasks).set(set).where(
|
|
15570
|
+
const [row] = await orm.update(itemSubtasks).set(set).where(and13(eq35(itemSubtasks.itemId, itemId2), eq35(itemSubtasks.idx, idx))).returning({ title: itemSubtasks.title });
|
|
15483
15571
|
return row?.title;
|
|
15484
15572
|
}
|
|
15485
15573
|
|
|
@@ -15534,16 +15622,16 @@ async function editSubtask(id, index3, options2) {
|
|
|
15534
15622
|
import chalk105 from "chalk";
|
|
15535
15623
|
|
|
15536
15624
|
// src/commands/backlog/deleteSubtask.ts
|
|
15537
|
-
import { and as
|
|
15625
|
+
import { and as and14, asc as asc9, eq as eq36 } from "drizzle-orm";
|
|
15538
15626
|
async function deleteSubtask(orm, itemId2, idx) {
|
|
15539
|
-
const [row] = await orm.delete(itemSubtasks).where(
|
|
15627
|
+
const [row] = await orm.delete(itemSubtasks).where(and14(eq36(itemSubtasks.itemId, itemId2), eq36(itemSubtasks.idx, idx))).returning({ title: itemSubtasks.title });
|
|
15540
15628
|
if (!row) return void 0;
|
|
15541
|
-
const remaining = await orm.select({ idx: itemSubtasks.idx }).from(itemSubtasks).where(
|
|
15629
|
+
const remaining = await orm.select({ idx: itemSubtasks.idx }).from(itemSubtasks).where(eq36(itemSubtasks.itemId, itemId2)).orderBy(asc9(itemSubtasks.idx));
|
|
15542
15630
|
for (let i = 0; i < remaining.length; i++) {
|
|
15543
15631
|
const oldIdx = remaining[i].idx;
|
|
15544
15632
|
if (oldIdx === i) continue;
|
|
15545
15633
|
await orm.update(itemSubtasks).set({ idx: i }).where(
|
|
15546
|
-
|
|
15634
|
+
and14(eq36(itemSubtasks.itemId, itemId2), eq36(itemSubtasks.idx, oldIdx))
|
|
15547
15635
|
);
|
|
15548
15636
|
}
|
|
15549
15637
|
return row.title;
|
|
@@ -15612,20 +15700,20 @@ function registerSubtaskCommands(cmd) {
|
|
|
15612
15700
|
|
|
15613
15701
|
// src/commands/backlog/movePhase.ts
|
|
15614
15702
|
import chalk107 from "chalk";
|
|
15615
|
-
import { count as count6, eq as
|
|
15703
|
+
import { count as count6, eq as eq39 } from "drizzle-orm";
|
|
15616
15704
|
|
|
15617
15705
|
// src/commands/backlog/reorderPhaseRows.ts
|
|
15618
|
-
import { and as
|
|
15706
|
+
import { and as and16, asc as asc11, eq as eq38 } from "drizzle-orm";
|
|
15619
15707
|
|
|
15620
15708
|
// src/commands/backlog/reindexPhases.ts
|
|
15621
|
-
import { and as
|
|
15709
|
+
import { and as and15, asc as asc10, count as count5, eq as eq37 } from "drizzle-orm";
|
|
15622
15710
|
async function reindexPhases(db, itemId2) {
|
|
15623
|
-
const remaining = await db.select({ idx: planPhases.idx }).from(planPhases).where(
|
|
15711
|
+
const remaining = await db.select({ idx: planPhases.idx }).from(planPhases).where(eq37(planPhases.itemId, itemId2)).orderBy(asc10(planPhases.idx));
|
|
15624
15712
|
for (let i = 0; i < remaining.length; i++) {
|
|
15625
15713
|
const oldIdx = remaining[i].idx;
|
|
15626
15714
|
if (oldIdx === i) continue;
|
|
15627
|
-
await db.update(planTasks).set({ phaseIdx: i }).where(
|
|
15628
|
-
await db.update(planPhases).set({ idx: i }).where(
|
|
15715
|
+
await db.update(planTasks).set({ phaseIdx: i }).where(and15(eq37(planTasks.itemId, itemId2), eq37(planTasks.phaseIdx, oldIdx)));
|
|
15716
|
+
await db.update(planPhases).set({ idx: i }).where(and15(eq37(planPhases.itemId, itemId2), eq37(planPhases.idx, oldIdx)));
|
|
15629
15717
|
}
|
|
15630
15718
|
}
|
|
15631
15719
|
async function adjustCurrentPhase(db, item, removedIdx) {
|
|
@@ -15633,24 +15721,24 @@ async function adjustCurrentPhase(db, item, removedIdx) {
|
|
|
15633
15721
|
if (currentPhase === void 0) return;
|
|
15634
15722
|
const currentIdx = currentPhase - 1;
|
|
15635
15723
|
if (removedIdx < currentIdx) {
|
|
15636
|
-
await db.update(items).set({ currentPhase: currentPhase - 1 }).where(
|
|
15724
|
+
await db.update(items).set({ currentPhase: currentPhase - 1 }).where(eq37(items.id, item.id));
|
|
15637
15725
|
return;
|
|
15638
15726
|
}
|
|
15639
15727
|
if (removedIdx !== currentIdx) return;
|
|
15640
|
-
const [row] = await db.select({ cnt: count5() }).from(planPhases).where(
|
|
15728
|
+
const [row] = await db.select({ cnt: count5() }).from(planPhases).where(eq37(planPhases.itemId, item.id));
|
|
15641
15729
|
const cnt = row?.cnt ?? 0;
|
|
15642
|
-
await db.update(items).set({ currentPhase: cnt === 0 ? null : Math.min(currentPhase, cnt) }).where(
|
|
15730
|
+
await db.update(items).set({ currentPhase: cnt === 0 ? null : Math.min(currentPhase, cnt) }).where(eq37(items.id, item.id));
|
|
15643
15731
|
}
|
|
15644
15732
|
|
|
15645
15733
|
// src/commands/backlog/reorderPhaseRows.ts
|
|
15646
15734
|
async function reorderPhaseRows(orm, itemId2, fromIdx, toIdx) {
|
|
15647
15735
|
await orm.transaction(async (tx) => {
|
|
15648
|
-
const [phaseRow] = await tx.select({ name: planPhases.name, manualChecks: planPhases.manualChecks }).from(planPhases).where(
|
|
15649
|
-
const tasks = await tx.select({ idx: planTasks.idx, task: planTasks.task }).from(planTasks).where(
|
|
15736
|
+
const [phaseRow] = await tx.select({ name: planPhases.name, manualChecks: planPhases.manualChecks }).from(planPhases).where(and16(eq38(planPhases.itemId, itemId2), eq38(planPhases.idx, fromIdx)));
|
|
15737
|
+
const tasks = await tx.select({ idx: planTasks.idx, task: planTasks.task }).from(planTasks).where(and16(eq38(planTasks.itemId, itemId2), eq38(planTasks.phaseIdx, fromIdx))).orderBy(asc11(planTasks.idx));
|
|
15650
15738
|
await tx.delete(planTasks).where(
|
|
15651
|
-
|
|
15739
|
+
and16(eq38(planTasks.itemId, itemId2), eq38(planTasks.phaseIdx, fromIdx))
|
|
15652
15740
|
);
|
|
15653
|
-
await tx.delete(planPhases).where(
|
|
15741
|
+
await tx.delete(planPhases).where(and16(eq38(planPhases.itemId, itemId2), eq38(planPhases.idx, fromIdx)));
|
|
15654
15742
|
await reindexPhases(tx, itemId2);
|
|
15655
15743
|
await shiftPhasesUp(tx, itemId2, toIdx);
|
|
15656
15744
|
await tx.insert(planPhases).values({
|
|
@@ -15691,7 +15779,7 @@ async function movePhase(id, from, to) {
|
|
|
15691
15779
|
if (!found) return;
|
|
15692
15780
|
const { orm, item } = found;
|
|
15693
15781
|
const itemId2 = item.id;
|
|
15694
|
-
const [row] = await orm.select({ cnt: count6() }).from(planPhases).where(
|
|
15782
|
+
const [row] = await orm.select({ cnt: count6() }).from(planPhases).where(eq39(planPhases.itemId, itemId2));
|
|
15695
15783
|
const phaseCount = row?.cnt ?? 0;
|
|
15696
15784
|
const fromIdx = toIndex2(from, phaseCount);
|
|
15697
15785
|
if (fromIdx === void 0) return;
|
|
@@ -15707,22 +15795,22 @@ async function movePhase(id, from, to) {
|
|
|
15707
15795
|
import chalk109 from "chalk";
|
|
15708
15796
|
|
|
15709
15797
|
// src/commands/backlog/applyPhaseUpdate.ts
|
|
15710
|
-
import { and as
|
|
15798
|
+
import { and as and17, eq as eq40 } from "drizzle-orm";
|
|
15711
15799
|
async function applyPhaseUpdate(orm, itemId2, phaseIdx, fields) {
|
|
15712
15800
|
await orm.transaction(async (tx) => {
|
|
15713
15801
|
if (fields.name) {
|
|
15714
15802
|
await tx.update(planPhases).set({ name: fields.name }).where(
|
|
15715
|
-
|
|
15803
|
+
and17(eq40(planPhases.itemId, itemId2), eq40(planPhases.idx, phaseIdx))
|
|
15716
15804
|
);
|
|
15717
15805
|
}
|
|
15718
15806
|
if (fields.manualCheck) {
|
|
15719
15807
|
await tx.update(planPhases).set({ manualChecks: JSON.stringify(fields.manualCheck) }).where(
|
|
15720
|
-
|
|
15808
|
+
and17(eq40(planPhases.itemId, itemId2), eq40(planPhases.idx, phaseIdx))
|
|
15721
15809
|
);
|
|
15722
15810
|
}
|
|
15723
15811
|
if (fields.task) {
|
|
15724
15812
|
await tx.delete(planTasks).where(
|
|
15725
|
-
|
|
15813
|
+
and17(eq40(planTasks.itemId, itemId2), eq40(planTasks.phaseIdx, phaseIdx))
|
|
15726
15814
|
);
|
|
15727
15815
|
if (fields.task.length) {
|
|
15728
15816
|
await tx.insert(planTasks).values(
|
|
@@ -15740,14 +15828,14 @@ async function applyPhaseUpdate(orm, itemId2, phaseIdx, fields) {
|
|
|
15740
15828
|
|
|
15741
15829
|
// src/commands/backlog/findPhase.ts
|
|
15742
15830
|
import chalk108 from "chalk";
|
|
15743
|
-
import { and as
|
|
15831
|
+
import { and as and18, count as count7, eq as eq41 } from "drizzle-orm";
|
|
15744
15832
|
async function findPhase(id, phase) {
|
|
15745
15833
|
const found = await findOneItem(id);
|
|
15746
15834
|
if (!found) return void 0;
|
|
15747
15835
|
const { orm, item } = found;
|
|
15748
15836
|
const itemId2 = item.id;
|
|
15749
15837
|
const phaseIdx = Number.parseInt(phase, 10) - 1;
|
|
15750
|
-
const [row] = await orm.select({ cnt: count7() }).from(planPhases).where(
|
|
15838
|
+
const [row] = await orm.select({ cnt: count7() }).from(planPhases).where(and18(eq41(planPhases.itemId, itemId2), eq41(planPhases.idx, phaseIdx)));
|
|
15751
15839
|
if (!row || row.cnt === 0) {
|
|
15752
15840
|
console.log(
|
|
15753
15841
|
chalk108.red(
|
|
@@ -15920,16 +16008,16 @@ function registerUpdatePhaseCommand(cmd) {
|
|
|
15920
16008
|
|
|
15921
16009
|
// src/commands/backlog/removePhase.ts
|
|
15922
16010
|
import chalk110 from "chalk";
|
|
15923
|
-
import { and as
|
|
16011
|
+
import { and as and19, eq as eq42 } from "drizzle-orm";
|
|
15924
16012
|
async function removePhase(id, phase) {
|
|
15925
16013
|
const found = await findPhase(id, phase);
|
|
15926
16014
|
if (!found) return;
|
|
15927
16015
|
const { item, orm, itemId: itemId2, phaseIdx } = found;
|
|
15928
16016
|
await orm.transaction(async (tx) => {
|
|
15929
16017
|
await tx.delete(planTasks).where(
|
|
15930
|
-
|
|
16018
|
+
and19(eq42(planTasks.itemId, itemId2), eq42(planTasks.phaseIdx, phaseIdx))
|
|
15931
16019
|
);
|
|
15932
|
-
await tx.delete(planPhases).where(
|
|
16020
|
+
await tx.delete(planPhases).where(and19(eq42(planPhases.itemId, itemId2), eq42(planPhases.idx, phaseIdx)));
|
|
15933
16021
|
await reindexPhases(tx, itemId2);
|
|
15934
16022
|
await adjustCurrentPhase(tx, item, phaseIdx);
|
|
15935
16023
|
});
|
|
@@ -15942,13 +16030,13 @@ async function removePhase(id, phase) {
|
|
|
15942
16030
|
|
|
15943
16031
|
// src/commands/backlog/update/update.ts
|
|
15944
16032
|
import chalk114 from "chalk";
|
|
15945
|
-
import { eq as
|
|
16033
|
+
import { eq as eq43 } from "drizzle-orm";
|
|
15946
16034
|
|
|
15947
16035
|
// src/commands/backlog/update/buildUpdateValues.ts
|
|
15948
16036
|
import chalk111 from "chalk";
|
|
15949
16037
|
function buildUpdateValues(options2) {
|
|
15950
|
-
const { name, desc:
|
|
15951
|
-
if (!name && !
|
|
16038
|
+
const { name, desc: desc8, type, ac, origin } = options2;
|
|
16039
|
+
if (!name && !desc8 && !type && !ac && !origin) {
|
|
15952
16040
|
console.log(chalk111.red("Nothing to update. Provide at least one flag."));
|
|
15953
16041
|
process.exitCode = 1;
|
|
15954
16042
|
return void 0;
|
|
@@ -15964,8 +16052,8 @@ function buildUpdateValues(options2) {
|
|
|
15964
16052
|
set.name = name;
|
|
15965
16053
|
fieldNames.push("name");
|
|
15966
16054
|
}
|
|
15967
|
-
if (
|
|
15968
|
-
set.description =
|
|
16055
|
+
if (desc8) {
|
|
16056
|
+
set.description = desc8.replaceAll(String.raw`\n`, "\n");
|
|
15969
16057
|
fieldNames.push("description");
|
|
15970
16058
|
}
|
|
15971
16059
|
if (type) {
|
|
@@ -16053,7 +16141,7 @@ async function update(id, options2) {
|
|
|
16053
16141
|
if (!built) return;
|
|
16054
16142
|
const { orm } = found;
|
|
16055
16143
|
const itemId2 = found.item.id;
|
|
16056
|
-
await orm.update(items).set(built.set).where(
|
|
16144
|
+
await orm.update(items).set(built.set).where(eq43(items.id, itemId2));
|
|
16057
16145
|
console.log(
|
|
16058
16146
|
chalk114.green(`Updated ${built.fields} on item ${formatItemId(itemId2)}.`)
|
|
16059
16147
|
);
|
|
@@ -16074,7 +16162,7 @@ function readPlanUpdate(source) {
|
|
|
16074
16162
|
}
|
|
16075
16163
|
|
|
16076
16164
|
// src/commands/backlog/updatePlan/replacePlan.ts
|
|
16077
|
-
import { eq as
|
|
16165
|
+
import { eq as eq44 } from "drizzle-orm";
|
|
16078
16166
|
|
|
16079
16167
|
// src/commands/backlog/updatePlan/clampCurrentPhase.ts
|
|
16080
16168
|
function clampCurrentPhase(currentPhase, phaseCount) {
|
|
@@ -16085,8 +16173,8 @@ function clampCurrentPhase(currentPhase, phaseCount) {
|
|
|
16085
16173
|
// src/commands/backlog/updatePlan/replacePlan.ts
|
|
16086
16174
|
async function replacePlan(orm, itemId2, phases, currentPhase) {
|
|
16087
16175
|
await orm.transaction(async (tx) => {
|
|
16088
|
-
await tx.delete(planTasks).where(
|
|
16089
|
-
await tx.delete(planPhases).where(
|
|
16176
|
+
await tx.delete(planTasks).where(eq44(planTasks.itemId, itemId2));
|
|
16177
|
+
await tx.delete(planPhases).where(eq44(planPhases.itemId, itemId2));
|
|
16090
16178
|
if (phases.length > 0) {
|
|
16091
16179
|
await tx.insert(planPhases).values(
|
|
16092
16180
|
phases.map((phase, idx) => ({
|
|
@@ -16104,7 +16192,7 @@ async function replacePlan(orm, itemId2, phases, currentPhase) {
|
|
|
16104
16192
|
if (currentPhase === void 0) return;
|
|
16105
16193
|
const clamped = clampCurrentPhase(currentPhase, phases.length);
|
|
16106
16194
|
if (clamped === currentPhase) return;
|
|
16107
|
-
await tx.update(items).set({ currentPhase: clamped }).where(
|
|
16195
|
+
await tx.update(items).set({ currentPhase: clamped }).where(eq44(items.id, itemId2));
|
|
16108
16196
|
});
|
|
16109
16197
|
}
|
|
16110
16198
|
|
|
@@ -22869,9 +22957,9 @@ function registerGithub(program2) {
|
|
|
22869
22957
|
}
|
|
22870
22958
|
|
|
22871
22959
|
// src/commands/handover/countPendingHandovers.ts
|
|
22872
|
-
import { and as
|
|
22960
|
+
import { and as and20, eq as eq45, isNull, sql as sql22 } from "drizzle-orm";
|
|
22873
22961
|
async function countPendingHandovers(orm, origin) {
|
|
22874
|
-
const [row] = await orm.select({ count:
|
|
22962
|
+
const [row] = await orm.select({ count: sql22`count(*)::int` }).from(handovers).where(and20(eq45(handovers.origin, origin), isNull(handovers.recalledAt)));
|
|
22875
22963
|
return row?.count ?? 0;
|
|
22876
22964
|
}
|
|
22877
22965
|
|
|
@@ -23011,13 +23099,13 @@ async function load2(options2 = {}) {
|
|
|
23011
23099
|
}
|
|
23012
23100
|
|
|
23013
23101
|
// src/commands/handover/listPendingHandovers.ts
|
|
23014
|
-
import { and as
|
|
23102
|
+
import { and as and21, desc as desc6, eq as eq46, isNull as isNull2 } from "drizzle-orm";
|
|
23015
23103
|
async function listPendingHandovers(orm, origin) {
|
|
23016
23104
|
return orm.select({
|
|
23017
23105
|
id: handovers.id,
|
|
23018
23106
|
summary: handovers.summary,
|
|
23019
23107
|
createdAt: handovers.createdAt
|
|
23020
|
-
}).from(handovers).where(
|
|
23108
|
+
}).from(handovers).where(and21(eq46(handovers.origin, origin), isNull2(handovers.recalledAt))).orderBy(desc6(handovers.createdAt), desc6(handovers.id));
|
|
23021
23109
|
}
|
|
23022
23110
|
|
|
23023
23111
|
// src/commands/handover/printPendingHandovers.ts
|
|
@@ -23030,17 +23118,17 @@ async function printPendingHandovers() {
|
|
|
23030
23118
|
}
|
|
23031
23119
|
|
|
23032
23120
|
// src/commands/handover/recallHandover.ts
|
|
23033
|
-
import { and as
|
|
23121
|
+
import { and as and22, desc as desc7, eq as eq47, isNull as isNull3 } from "drizzle-orm";
|
|
23034
23122
|
async function recallHandover(orm, origin, id) {
|
|
23035
23123
|
const [row] = await orm.select().from(handovers).where(
|
|
23036
|
-
|
|
23037
|
-
|
|
23124
|
+
and22(
|
|
23125
|
+
eq47(handovers.origin, origin),
|
|
23038
23126
|
isNull3(handovers.recalledAt),
|
|
23039
|
-
...id === void 0 ? [] : [
|
|
23127
|
+
...id === void 0 ? [] : [eq47(handovers.id, id)]
|
|
23040
23128
|
)
|
|
23041
|
-
).orderBy(
|
|
23129
|
+
).orderBy(desc7(handovers.createdAt), desc7(handovers.id)).limit(1);
|
|
23042
23130
|
if (!row) return void 0;
|
|
23043
|
-
await orm.update(handovers).set({ recalledAt: /* @__PURE__ */ new Date() }).where(
|
|
23131
|
+
await orm.update(handovers).set({ recalledAt: /* @__PURE__ */ new Date() }).where(eq47(handovers.id, row.id));
|
|
23044
23132
|
return row.content;
|
|
23045
23133
|
}
|
|
23046
23134
|
|
|
@@ -31560,8 +31648,8 @@ function filterToSql(filter) {
|
|
|
31560
31648
|
// src/commands/seq/fetchSeqData.ts
|
|
31561
31649
|
function buildDataParams(filter, count8, from, to) {
|
|
31562
31650
|
const sqlFilter = filterToSql(filter);
|
|
31563
|
-
const
|
|
31564
|
-
const params = new URLSearchParams({ q:
|
|
31651
|
+
const sql29 = `select @Timestamp, @Level, @Exception, @Message from stream where ${sqlFilter} order by @Timestamp desc limit ${count8}`;
|
|
31652
|
+
const params = new URLSearchParams({ q: sql29 });
|
|
31565
31653
|
if (from) params.set("rangeStartUtc", from);
|
|
31566
31654
|
if (to) params.set("rangeEndUtc", to);
|
|
31567
31655
|
return params;
|
|
@@ -31922,26 +32010,26 @@ import chalk222 from "chalk";
|
|
|
31922
32010
|
// src/commands/sql/loadConnections.ts
|
|
31923
32011
|
function loadConnections3() {
|
|
31924
32012
|
const raw = loadGlobalConfigRaw();
|
|
31925
|
-
const
|
|
31926
|
-
return
|
|
32013
|
+
const sql29 = raw.sql;
|
|
32014
|
+
return sql29?.connections ?? [];
|
|
31927
32015
|
}
|
|
31928
32016
|
function saveConnections3(connections) {
|
|
31929
32017
|
const raw = loadGlobalConfigRaw();
|
|
31930
|
-
const
|
|
31931
|
-
|
|
31932
|
-
raw.sql =
|
|
32018
|
+
const sql29 = raw.sql ?? {};
|
|
32019
|
+
sql29.connections = connections;
|
|
32020
|
+
raw.sql = sql29;
|
|
31933
32021
|
saveGlobalConfig(raw);
|
|
31934
32022
|
}
|
|
31935
32023
|
function getDefaultConnection2() {
|
|
31936
32024
|
const raw = loadGlobalConfigRaw();
|
|
31937
|
-
const
|
|
31938
|
-
return
|
|
32025
|
+
const sql29 = raw.sql;
|
|
32026
|
+
return sql29?.defaultConnection;
|
|
31939
32027
|
}
|
|
31940
32028
|
function setDefaultConnection2(name) {
|
|
31941
32029
|
const raw = loadGlobalConfigRaw();
|
|
31942
|
-
const
|
|
31943
|
-
|
|
31944
|
-
raw.sql =
|
|
32030
|
+
const sql29 = raw.sql ?? {};
|
|
32031
|
+
sql29.defaultConnection = name;
|
|
32032
|
+
raw.sql = sql29;
|
|
31945
32033
|
saveGlobalConfig(raw);
|
|
31946
32034
|
}
|
|
31947
32035
|
|
|
@@ -32012,9 +32100,9 @@ function resolveConnection3(name) {
|
|
|
32012
32100
|
}
|
|
32013
32101
|
|
|
32014
32102
|
// src/commands/sql/sqlConnect.ts
|
|
32015
|
-
import
|
|
32103
|
+
import sql23 from "mssql";
|
|
32016
32104
|
async function sqlConnect(conn) {
|
|
32017
|
-
return await
|
|
32105
|
+
return await sql23.connect({
|
|
32018
32106
|
server: conn.server,
|
|
32019
32107
|
port: conn.port,
|
|
32020
32108
|
user: conn.user,
|
|
@@ -32077,11 +32165,11 @@ var MUTATION_PATTERN = new RegExp(
|
|
|
32077
32165
|
`\\b(${MUTATION_KEYWORDS.join("|")})\\b`,
|
|
32078
32166
|
"i"
|
|
32079
32167
|
);
|
|
32080
|
-
function stripComments(
|
|
32081
|
-
return
|
|
32168
|
+
function stripComments(sql29) {
|
|
32169
|
+
return sql29.replace(/\/\*[\s\S]*?\*\//g, " ").replace(/--[^\n]*/g, " ");
|
|
32082
32170
|
}
|
|
32083
|
-
function isMutation(
|
|
32084
|
-
const stripped = stripComments(
|
|
32171
|
+
function isMutation(sql29) {
|
|
32172
|
+
const stripped = stripComments(sql29);
|
|
32085
32173
|
if (MUTATION_PATTERN.test(stripped)) return true;
|
|
32086
32174
|
return /\bSELECT\b[\s\S]+\bINTO\s+\w/i.test(stripped);
|
|
32087
32175
|
}
|
|
@@ -36095,13 +36183,13 @@ function drainSessions(sessions, notify2) {
|
|
|
36095
36183
|
}
|
|
36096
36184
|
|
|
36097
36185
|
// src/shared/db/recordPhaseActiveMs.ts
|
|
36098
|
-
import { sql as
|
|
36186
|
+
import { sql as sql24 } from "drizzle-orm";
|
|
36099
36187
|
async function recordPhaseActiveMs(db, itemId2, phaseIdx, activeMs) {
|
|
36100
36188
|
if (activeMs <= 0) return;
|
|
36101
36189
|
await db.insert(phaseUsage).values({ itemId: itemId2, phaseIdx, activeMs }).onConflictDoUpdate({
|
|
36102
36190
|
target: [phaseUsage.itemId, phaseUsage.phaseIdx],
|
|
36103
36191
|
set: {
|
|
36104
|
-
activeMs:
|
|
36192
|
+
activeMs: sql24`${phaseUsage.activeMs} + excluded.active_ms`
|
|
36105
36193
|
}
|
|
36106
36194
|
});
|
|
36107
36195
|
}
|
|
@@ -36539,10 +36627,10 @@ function applyReviewPause(session, activity2) {
|
|
|
36539
36627
|
}
|
|
36540
36628
|
|
|
36541
36629
|
// src/shared/db/getPhaseActiveMs.ts
|
|
36542
|
-
import { and as
|
|
36630
|
+
import { and as and23, eq as eq48 } from "drizzle-orm";
|
|
36543
36631
|
async function getPhaseActiveMs(db, itemId2, phaseIdx) {
|
|
36544
36632
|
const [row] = await db.select({ activeMs: phaseUsage.activeMs }).from(phaseUsage).where(
|
|
36545
|
-
|
|
36633
|
+
and23(eq48(phaseUsage.itemId, itemId2), eq48(phaseUsage.phaseIdx, phaseIdx))
|
|
36546
36634
|
);
|
|
36547
36635
|
return row?.activeMs ?? 0;
|
|
36548
36636
|
}
|
|
@@ -37311,7 +37399,7 @@ function makeSessionSpawner(sessions, clients, counter, onStatusChange, notify2)
|
|
|
37311
37399
|
}
|
|
37312
37400
|
|
|
37313
37401
|
// src/shared/db/recordPhaseCycleContext.ts
|
|
37314
|
-
import { sql as
|
|
37402
|
+
import { sql as sql25 } from "drizzle-orm";
|
|
37315
37403
|
async function recordPhaseCycleContext(db, itemId2, phaseIdx, window, resetsAt, pct) {
|
|
37316
37404
|
if (pct <= 0) return;
|
|
37317
37405
|
await db.insert(phaseCycleContext).values({ itemId: itemId2, phaseIdx, window, resetsAt, peakContextPct: pct }).onConflictDoUpdate({
|
|
@@ -37322,24 +37410,24 @@ async function recordPhaseCycleContext(db, itemId2, phaseIdx, window, resetsAt,
|
|
|
37322
37410
|
phaseCycleContext.resetsAt
|
|
37323
37411
|
],
|
|
37324
37412
|
set: {
|
|
37325
|
-
peakContextPct:
|
|
37413
|
+
peakContextPct: sql25`GREATEST(${phaseCycleContext.peakContextPct}, ${pct})`
|
|
37326
37414
|
}
|
|
37327
37415
|
});
|
|
37328
37416
|
}
|
|
37329
37417
|
|
|
37330
37418
|
// src/shared/db/recordPhasePeakContext.ts
|
|
37331
|
-
import { sql as
|
|
37419
|
+
import { sql as sql26 } from "drizzle-orm";
|
|
37332
37420
|
async function recordPhasePeakContext(db, itemId2, phaseIdx, pct) {
|
|
37333
37421
|
await db.insert(phaseUsage).values({ itemId: itemId2, phaseIdx, peakContextPct: pct }).onConflictDoUpdate({
|
|
37334
37422
|
target: [phaseUsage.itemId, phaseUsage.phaseIdx],
|
|
37335
37423
|
set: {
|
|
37336
|
-
peakContextPct:
|
|
37424
|
+
peakContextPct: sql26`GREATEST(${phaseUsage.peakContextPct}, ${pct})`
|
|
37337
37425
|
}
|
|
37338
37426
|
});
|
|
37339
37427
|
}
|
|
37340
37428
|
|
|
37341
37429
|
// src/shared/db/recordPhaseTranscriptUsage.ts
|
|
37342
|
-
import { sql as
|
|
37430
|
+
import { sql as sql27 } from "drizzle-orm";
|
|
37343
37431
|
async function recordPhaseTranscriptUsage(db, itemId2, phaseIdx, responses) {
|
|
37344
37432
|
const byId = /* @__PURE__ */ new Map();
|
|
37345
37433
|
for (const r of responses) byId.set(r.messageId, r);
|
|
@@ -37359,8 +37447,8 @@ async function recordPhaseTranscriptUsage(db, itemId2, phaseIdx, responses) {
|
|
|
37359
37447
|
await tx.insert(phaseUsage).values({ itemId: itemId2, phaseIdx, tokensUp, tokensDown }).onConflictDoUpdate({
|
|
37360
37448
|
target: [phaseUsage.itemId, phaseUsage.phaseIdx],
|
|
37361
37449
|
set: {
|
|
37362
|
-
tokensUp:
|
|
37363
|
-
tokensDown:
|
|
37450
|
+
tokensUp: sql27`${phaseUsage.tokensUp} + ${tokensUp}`,
|
|
37451
|
+
tokensDown: sql27`${phaseUsage.tokensDown} + ${tokensDown}`
|
|
37364
37452
|
}
|
|
37365
37453
|
});
|
|
37366
37454
|
return { tokensUp, tokensDown };
|
|
@@ -37368,17 +37456,17 @@ async function recordPhaseTranscriptUsage(db, itemId2, phaseIdx, responses) {
|
|
|
37368
37456
|
}
|
|
37369
37457
|
|
|
37370
37458
|
// src/shared/db/recordWindowTokens.ts
|
|
37371
|
-
import { and as
|
|
37459
|
+
import { and as and24, eq as eq49, sql as sql28 } from "drizzle-orm";
|
|
37372
37460
|
async function recordWindowTokens(db, window, resetsAt, tokensUp, tokensDown) {
|
|
37373
37461
|
if (tokensUp <= 0 && tokensDown <= 0) return;
|
|
37374
37462
|
await db.update(usagePeaks).set({
|
|
37375
|
-
tokensUp:
|
|
37376
|
-
tokensDown:
|
|
37463
|
+
tokensUp: sql28`${usagePeaks.tokensUp} + ${tokensUp}`,
|
|
37464
|
+
tokensDown: sql28`${usagePeaks.tokensDown} + ${tokensDown}`
|
|
37377
37465
|
}).where(
|
|
37378
|
-
|
|
37379
|
-
|
|
37380
|
-
|
|
37381
|
-
|
|
37466
|
+
and24(
|
|
37467
|
+
eq49(usagePeaks.window, window),
|
|
37468
|
+
eq49(usagePeaks.resetsAt, resetsAt),
|
|
37469
|
+
eq49(usagePeaks.segment, 0)
|
|
37382
37470
|
)
|
|
37383
37471
|
);
|
|
37384
37472
|
}
|