@staff0rd/assist 0.632.0 → 0.633.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 +445 -445
- package/dist/index.js +166 -136
- 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.633.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,60 @@ 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/itemUsageStats.ts
|
|
11743
|
+
import { eq as eq21, sql as sql18 } from "drizzle-orm";
|
|
11744
|
+
function median(value) {
|
|
11745
|
+
return sql18`coalesce(percentile_cont(0.5) within group (order by (${value})::double precision), 0)`;
|
|
11746
|
+
}
|
|
11747
|
+
async function itemUsageStats(db, options2) {
|
|
11748
|
+
const totals = phaseUsageTotals(db);
|
|
11749
|
+
const planned = planPhaseCounts(db);
|
|
11737
11750
|
const [row] = await db.select({
|
|
11738
|
-
|
|
11739
|
-
|
|
11740
|
-
|
|
11751
|
+
itemCount: sql18`count(*)::int`,
|
|
11752
|
+
doneCount: sql18`count(*) filter (where ${items.status} = 'done')::int`,
|
|
11753
|
+
repoCount: sql18`count(distinct ${items.origin})::int`,
|
|
11754
|
+
medianPhases: median(
|
|
11755
|
+
sql18`coalesce(${planned.count}, ${totals.recordedPhases})`
|
|
11756
|
+
),
|
|
11757
|
+
medianActiveMs: median(totals.activeMs),
|
|
11758
|
+
medianTokens: median(sql18`${totals.tokensUp} + ${totals.tokensDown}`)
|
|
11759
|
+
}).from(items).innerJoin(totals, eq21(totals.itemId, items.id)).leftJoin(planned, eq21(planned.itemId, items.id)).where(options2?.origin ? eq21(items.origin, options2.origin) : void 0);
|
|
11760
|
+
return {
|
|
11761
|
+
itemCount: Number(row?.itemCount ?? 0),
|
|
11762
|
+
doneCount: Number(row?.doneCount ?? 0),
|
|
11763
|
+
repoCount: Number(row?.repoCount ?? 0),
|
|
11764
|
+
medianPhases: Number(row?.medianPhases ?? 0),
|
|
11765
|
+
medianActiveMs: Number(row?.medianActiveMs ?? 0),
|
|
11766
|
+
medianTokens: Number(row?.medianTokens ?? 0)
|
|
11767
|
+
};
|
|
11741
11768
|
}
|
|
11742
11769
|
|
|
11743
11770
|
// src/shared/db/listItemUsageSummaries.ts
|
|
11744
|
-
import { desc as
|
|
11771
|
+
import { desc as desc4, eq as eq22, sql as sql20 } from "drizzle-orm";
|
|
11745
11772
|
|
|
11746
11773
|
// src/shared/db/lastPhaseActivity.ts
|
|
11747
|
-
import { sql as
|
|
11774
|
+
import { sql as sql19 } from "drizzle-orm";
|
|
11748
11775
|
function lastPhaseActivity(db) {
|
|
11749
11776
|
return db.select({
|
|
11750
11777
|
itemId: phaseSessions.itemId,
|
|
11751
|
-
at:
|
|
11752
|
-
atIso:
|
|
11778
|
+
at: sql19`max(${phaseSessions.createdAt})`.as("last_phase_at"),
|
|
11779
|
+
atIso: sql19`to_char(max(${phaseSessions.createdAt}) at time zone 'utc', 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"')`.as(
|
|
11753
11780
|
"last_phase_at_iso"
|
|
11754
11781
|
)
|
|
11755
11782
|
}).from(phaseSessions).groupBy(phaseSessions.itemId).as("last_phase_activity");
|
|
@@ -11787,19 +11814,22 @@ async function listItemUsageSummaries(db, options2) {
|
|
|
11787
11814
|
activeMs: totals.activeMs,
|
|
11788
11815
|
peakContextPct: totals.peakContextPct,
|
|
11789
11816
|
lastPhaseAt: lastPhase.atIso
|
|
11790
|
-
}).from(items).innerJoin(totals,
|
|
11817
|
+
}).from(items).innerJoin(totals, eq22(totals.itemId, items.id)).leftJoin(planned, eq22(planned.itemId, items.id)).leftJoin(lastPhase, eq22(lastPhase.itemId, items.id)).where(options2?.origin ? eq22(items.origin, options2.origin) : void 0).orderBy(sql20`${lastPhase.at} desc nulls last`, desc4(items.id));
|
|
11791
11818
|
const rows = options2?.limit === void 0 ? await query : await query.limit(options2.limit).offset(options2.offset ?? 0);
|
|
11792
11819
|
return rows.map(toItemUsageSummary);
|
|
11793
11820
|
}
|
|
11794
11821
|
|
|
11795
11822
|
// src/commands/sessions/web/listUsageItems.ts
|
|
11796
11823
|
function listUsageItems(req, res) {
|
|
11797
|
-
return respondPagedRows(req, res, async (range) => {
|
|
11824
|
+
return respondPagedRows(req, res, async (range, params) => {
|
|
11825
|
+
const origin = params.get("origin") || void 0;
|
|
11798
11826
|
const db = await getDb();
|
|
11799
|
-
|
|
11800
|
-
listItemUsageSummaries(db, range),
|
|
11801
|
-
|
|
11827
|
+
const [rows, summary, origins] = await Promise.all([
|
|
11828
|
+
listItemUsageSummaries(db, { ...range, origin }),
|
|
11829
|
+
itemUsageStats(db, { origin }),
|
|
11830
|
+
countItemUsageByOrigin(db)
|
|
11802
11831
|
]);
|
|
11832
|
+
return { rows, total: summary.itemCount, summary, origins };
|
|
11803
11833
|
});
|
|
11804
11834
|
}
|
|
11805
11835
|
|
|
@@ -13622,11 +13652,11 @@ function registerActivityCommands(cmd) {
|
|
|
13622
13652
|
|
|
13623
13653
|
// src/commands/backlog/associate-github/index.ts
|
|
13624
13654
|
import chalk66 from "chalk";
|
|
13625
|
-
import { eq as
|
|
13655
|
+
import { eq as eq24 } from "drizzle-orm";
|
|
13626
13656
|
|
|
13627
13657
|
// src/commands/backlog/beginAssociation.ts
|
|
13628
13658
|
import chalk65 from "chalk";
|
|
13629
|
-
import { eq as
|
|
13659
|
+
import { eq as eq23 } from "drizzle-orm";
|
|
13630
13660
|
async function beginAssociation(id, options2, clearPatch, label2) {
|
|
13631
13661
|
const found = await findOneItem(id);
|
|
13632
13662
|
if (!found) {
|
|
@@ -13636,7 +13666,7 @@ async function beginAssociation(id, options2, clearPatch, label2) {
|
|
|
13636
13666
|
const { orm } = found;
|
|
13637
13667
|
const itemId2 = found.item.id;
|
|
13638
13668
|
if (options2.clear) {
|
|
13639
|
-
await orm.update(items).set(clearPatch).where(
|
|
13669
|
+
await orm.update(items).set(clearPatch).where(eq23(items.id, itemId2));
|
|
13640
13670
|
console.log(
|
|
13641
13671
|
chalk65.green(
|
|
13642
13672
|
`Cleared ${label2} association on item ${formatItemId(itemId2)}.`
|
|
@@ -13704,7 +13734,7 @@ async function associateGithub(id, issue, options2) {
|
|
|
13704
13734
|
return;
|
|
13705
13735
|
}
|
|
13706
13736
|
const title = fetchGithubIssueTitle(normalized);
|
|
13707
|
-
await orm.update(items).set({ githubIssue: normalized, jiraKey: null }).where(
|
|
13737
|
+
await orm.update(items).set({ githubIssue: normalized, jiraKey: null }).where(eq24(items.id, itemId2));
|
|
13708
13738
|
console.log(
|
|
13709
13739
|
chalk66.green(`Associated ${normalized} with item ${formatItemId(itemId2)}.`),
|
|
13710
13740
|
title ? chalk66.dim(`(${title})`) : ""
|
|
@@ -13718,7 +13748,7 @@ function registerAssociateGithubCommand(cmd) {
|
|
|
13718
13748
|
|
|
13719
13749
|
// src/commands/backlog/associate-jira/index.ts
|
|
13720
13750
|
import chalk68 from "chalk";
|
|
13721
|
-
import { eq as
|
|
13751
|
+
import { eq as eq25 } from "drizzle-orm";
|
|
13722
13752
|
|
|
13723
13753
|
// src/commands/jira/fetchIssue.ts
|
|
13724
13754
|
import { execSync as execSync27 } from "child_process";
|
|
@@ -13783,7 +13813,7 @@ async function associateJira(id, key, options2) {
|
|
|
13783
13813
|
const parsed = fetchIssue(normalized, "summary");
|
|
13784
13814
|
const fields = parsed?.fields;
|
|
13785
13815
|
const summary = fields?.summary;
|
|
13786
|
-
await orm.update(items).set({ jiraKey: normalized, githubIssue: null }).where(
|
|
13816
|
+
await orm.update(items).set({ jiraKey: normalized, githubIssue: null }).where(eq25(items.id, itemId2));
|
|
13787
13817
|
console.log(
|
|
13788
13818
|
chalk68.green(`Associated ${normalized} with item ${formatItemId(itemId2)}.`),
|
|
13789
13819
|
summary ? chalk68.dim(`(${summary})`) : ""
|
|
@@ -14187,8 +14217,8 @@ async function readStdinBuffer() {
|
|
|
14187
14217
|
import { finished } from "stream/promises";
|
|
14188
14218
|
import { from as copyFrom } from "pg-copy-streams";
|
|
14189
14219
|
async function copyTableIn(client, table, data) {
|
|
14190
|
-
const
|
|
14191
|
-
const stream = client.query(copyFrom(
|
|
14220
|
+
const sql29 = `COPY ${table.name} (${table.columns.join(", ")}) FROM STDIN`;
|
|
14221
|
+
const stream = client.query(copyFrom(sql29));
|
|
14192
14222
|
stream.end(data);
|
|
14193
14223
|
await finished(stream);
|
|
14194
14224
|
}
|
|
@@ -14290,15 +14320,15 @@ function isClaudeCode() {
|
|
|
14290
14320
|
}
|
|
14291
14321
|
|
|
14292
14322
|
// src/commands/backlog/insertPhaseAt.ts
|
|
14293
|
-
import { eq as
|
|
14323
|
+
import { eq as eq27 } from "drizzle-orm";
|
|
14294
14324
|
|
|
14295
14325
|
// src/commands/backlog/shiftPhasesUp.ts
|
|
14296
|
-
import { and as and9, desc as
|
|
14326
|
+
import { and as and9, desc as desc5, eq as eq26, gte } from "drizzle-orm";
|
|
14297
14327
|
async function shiftPhasesUp(db, itemId2, fromIdx) {
|
|
14298
|
-
const toShift = await db.select({ idx: planPhases.idx }).from(planPhases).where(and9(
|
|
14328
|
+
const toShift = await db.select({ idx: planPhases.idx }).from(planPhases).where(and9(eq26(planPhases.itemId, itemId2), gte(planPhases.idx, fromIdx))).orderBy(desc5(planPhases.idx));
|
|
14299
14329
|
for (const p of toShift) {
|
|
14300
|
-
await db.update(planTasks).set({ phaseIdx: p.idx + 1 }).where(and9(
|
|
14301
|
-
await db.update(planPhases).set({ idx: p.idx + 1 }).where(and9(
|
|
14330
|
+
await db.update(planTasks).set({ phaseIdx: p.idx + 1 }).where(and9(eq26(planTasks.itemId, itemId2), eq26(planTasks.phaseIdx, p.idx)));
|
|
14331
|
+
await db.update(planPhases).set({ idx: p.idx + 1 }).where(and9(eq26(planPhases.itemId, itemId2), eq26(planPhases.idx, p.idx)));
|
|
14302
14332
|
}
|
|
14303
14333
|
}
|
|
14304
14334
|
|
|
@@ -14311,17 +14341,17 @@ async function insertPhaseAt(orm, itemId2, phaseIdx, name, tasks, manualChecks,
|
|
|
14311
14341
|
await tx.insert(planTasks).values(tasks.map((task, i) => ({ itemId: itemId2, phaseIdx, idx: i, task })));
|
|
14312
14342
|
}
|
|
14313
14343
|
if (currentPhase !== void 0 && currentPhase - 1 >= phaseIdx) {
|
|
14314
|
-
await tx.update(items).set({ currentPhase: phaseIdx + 1 }).where(
|
|
14344
|
+
await tx.update(items).set({ currentPhase: phaseIdx + 1 }).where(eq27(items.id, itemId2));
|
|
14315
14345
|
}
|
|
14316
14346
|
});
|
|
14317
14347
|
}
|
|
14318
14348
|
|
|
14319
14349
|
// src/commands/backlog/insertSubtask.ts
|
|
14320
|
-
import { sql as
|
|
14350
|
+
import { sql as sql21 } from "drizzle-orm";
|
|
14321
14351
|
async function insertSubtask(orm, itemId2, title, description) {
|
|
14322
14352
|
await orm.insert(itemSubtasks).values({
|
|
14323
14353
|
itemId: itemId2,
|
|
14324
|
-
idx:
|
|
14354
|
+
idx: sql21`(SELECT COALESCE(MAX(${itemSubtasks.idx}) + 1, 0) FROM ${itemSubtasks} WHERE ${itemSubtasks.itemId} = ${itemId2})`,
|
|
14325
14355
|
title,
|
|
14326
14356
|
description: description ?? null,
|
|
14327
14357
|
status: "todo"
|
|
@@ -14483,9 +14513,9 @@ import chalk78 from "chalk";
|
|
|
14483
14513
|
|
|
14484
14514
|
// src/commands/backlog/resolveInsertPosition.ts
|
|
14485
14515
|
import chalk77 from "chalk";
|
|
14486
|
-
import { count as count3, eq as
|
|
14516
|
+
import { count as count3, eq as eq28 } from "drizzle-orm";
|
|
14487
14517
|
async function resolveInsertPosition(orm, itemId2, position) {
|
|
14488
|
-
const [row] = await orm.select({ cnt: count3() }).from(planPhases).where(
|
|
14518
|
+
const [row] = await orm.select({ cnt: count3() }).from(planPhases).where(eq28(planPhases.itemId, itemId2));
|
|
14489
14519
|
const phaseCount = row?.cnt ?? 0;
|
|
14490
14520
|
if (position === void 0) return phaseCount;
|
|
14491
14521
|
const pos = Number.parseInt(position, 10);
|
|
@@ -14780,9 +14810,9 @@ function hasCycle(adjacency, fromId, toId) {
|
|
|
14780
14810
|
}
|
|
14781
14811
|
|
|
14782
14812
|
// src/commands/backlog/loadDependencyGraph.ts
|
|
14783
|
-
import { eq as
|
|
14813
|
+
import { eq as eq29 } from "drizzle-orm";
|
|
14784
14814
|
async function loadDependencyGraph(orm) {
|
|
14785
|
-
const rows = await orm.select({ itemId: links.itemId, targetId: links.targetId }).from(links).where(
|
|
14815
|
+
const rows = await orm.select({ itemId: links.itemId, targetId: links.targetId }).from(links).where(eq29(links.type, "depends-on"));
|
|
14786
14816
|
const graph = /* @__PURE__ */ new Map();
|
|
14787
14817
|
for (const { itemId: itemId2, targetId } of rows) {
|
|
14788
14818
|
const bucket = graph.get(itemId2);
|
|
@@ -14849,7 +14879,7 @@ async function link(fromId, toId, opts) {
|
|
|
14849
14879
|
|
|
14850
14880
|
// src/commands/backlog/unlink.ts
|
|
14851
14881
|
import chalk85 from "chalk";
|
|
14852
|
-
import { and as and10, eq as
|
|
14882
|
+
import { and as and10, eq as eq30 } from "drizzle-orm";
|
|
14853
14883
|
async function unlink(fromId, toId) {
|
|
14854
14884
|
const fromNum = parseItemId(fromId);
|
|
14855
14885
|
const toNum = parseItemId(toId);
|
|
@@ -14873,7 +14903,7 @@ async function unlink(fromId, toId) {
|
|
|
14873
14903
|
);
|
|
14874
14904
|
return;
|
|
14875
14905
|
}
|
|
14876
|
-
await orm.delete(links).where(and10(
|
|
14906
|
+
await orm.delete(links).where(and10(eq30(links.itemId, fromNum), eq30(links.targetId, toNum)));
|
|
14877
14907
|
console.log(
|
|
14878
14908
|
chalk85.green(
|
|
14879
14909
|
`Removed link from ${formatItemId(fromNum)} to ${formatItemId(toNum)}.`
|
|
@@ -14893,7 +14923,7 @@ function registerLinkCommands(cmd) {
|
|
|
14893
14923
|
|
|
14894
14924
|
// src/commands/backlog/move-repo/index.ts
|
|
14895
14925
|
import chalk87 from "chalk";
|
|
14896
|
-
import { eq as
|
|
14926
|
+
import { eq as eq32 } from "drizzle-orm";
|
|
14897
14927
|
|
|
14898
14928
|
// src/commands/backlog/move-repo/confirmMove.ts
|
|
14899
14929
|
import chalk86 from "chalk";
|
|
@@ -14908,9 +14938,9 @@ async function confirmMove(cnt, oldOrigin, newOrigin) {
|
|
|
14908
14938
|
}
|
|
14909
14939
|
|
|
14910
14940
|
// src/commands/backlog/move-repo/countByOrigin.ts
|
|
14911
|
-
import { count as count4, eq as
|
|
14941
|
+
import { count as count4, eq as eq31 } from "drizzle-orm";
|
|
14912
14942
|
async function countByOrigin(orm, origin) {
|
|
14913
|
-
const [{ cnt }] = await orm.select({ cnt: count4() }).from(items).where(
|
|
14943
|
+
const [{ cnt }] = await orm.select({ cnt: count4() }).from(items).where(eq31(items.origin, origin));
|
|
14914
14944
|
return cnt;
|
|
14915
14945
|
}
|
|
14916
14946
|
|
|
@@ -14953,7 +14983,7 @@ async function moveRepo(oldOriginRaw, newOriginRaw, options2 = {}) {
|
|
|
14953
14983
|
console.log(chalk87.yellow("Move cancelled; no changes made."));
|
|
14954
14984
|
return;
|
|
14955
14985
|
}
|
|
14956
|
-
await orm.update(items).set({ origin: newOrigin }).where(
|
|
14986
|
+
await orm.update(items).set({ origin: newOrigin }).where(eq32(items.origin, oldOrigin));
|
|
14957
14987
|
console.log(
|
|
14958
14988
|
chalk87.green(
|
|
14959
14989
|
`Moved ${pluralItems(cnt)} from "${oldOrigin}" to "${newOrigin}".`
|
|
@@ -15353,10 +15383,10 @@ async function start(id) {
|
|
|
15353
15383
|
|
|
15354
15384
|
// src/commands/backlog/stop/index.ts
|
|
15355
15385
|
import chalk99 from "chalk";
|
|
15356
|
-
import { and as and11, eq as
|
|
15386
|
+
import { and as and11, eq as eq33 } from "drizzle-orm";
|
|
15357
15387
|
async function stop() {
|
|
15358
15388
|
const { orm } = await getReady();
|
|
15359
|
-
const stopped = await orm.update(items).set({ status: "todo", currentPhase: 1 }).where(and11(
|
|
15389
|
+
const stopped = await orm.update(items).set({ status: "todo", currentPhase: 1 }).where(and11(eq33(items.status, "in-progress"), eq33(items.origin, getOrigin()))).returning({ id: items.id, name: items.name });
|
|
15360
15390
|
if (stopped.length === 0) {
|
|
15361
15391
|
console.log(chalk99.yellow("No in-progress items to stop."));
|
|
15362
15392
|
return;
|
|
@@ -15473,13 +15503,13 @@ async function findSubtask(id, index3) {
|
|
|
15473
15503
|
}
|
|
15474
15504
|
|
|
15475
15505
|
// src/commands/backlog/updateSubtask.ts
|
|
15476
|
-
import { and as and12, eq as
|
|
15506
|
+
import { and as and12, eq as eq34 } from "drizzle-orm";
|
|
15477
15507
|
async function updateSubtask(orm, itemId2, idx, fields) {
|
|
15478
15508
|
const set = {};
|
|
15479
15509
|
if (fields.title !== void 0) set.title = fields.title;
|
|
15480
15510
|
if (fields.description !== void 0) set.description = fields.description;
|
|
15481
15511
|
if (fields.status !== void 0) set.status = fields.status;
|
|
15482
|
-
const [row] = await orm.update(itemSubtasks).set(set).where(and12(
|
|
15512
|
+
const [row] = await orm.update(itemSubtasks).set(set).where(and12(eq34(itemSubtasks.itemId, itemId2), eq34(itemSubtasks.idx, idx))).returning({ title: itemSubtasks.title });
|
|
15483
15513
|
return row?.title;
|
|
15484
15514
|
}
|
|
15485
15515
|
|
|
@@ -15534,16 +15564,16 @@ async function editSubtask(id, index3, options2) {
|
|
|
15534
15564
|
import chalk105 from "chalk";
|
|
15535
15565
|
|
|
15536
15566
|
// src/commands/backlog/deleteSubtask.ts
|
|
15537
|
-
import { and as and13, asc as
|
|
15567
|
+
import { and as and13, asc as asc9, eq as eq35 } from "drizzle-orm";
|
|
15538
15568
|
async function deleteSubtask(orm, itemId2, idx) {
|
|
15539
|
-
const [row] = await orm.delete(itemSubtasks).where(and13(
|
|
15569
|
+
const [row] = await orm.delete(itemSubtasks).where(and13(eq35(itemSubtasks.itemId, itemId2), eq35(itemSubtasks.idx, idx))).returning({ title: itemSubtasks.title });
|
|
15540
15570
|
if (!row) return void 0;
|
|
15541
|
-
const remaining = await orm.select({ idx: itemSubtasks.idx }).from(itemSubtasks).where(
|
|
15571
|
+
const remaining = await orm.select({ idx: itemSubtasks.idx }).from(itemSubtasks).where(eq35(itemSubtasks.itemId, itemId2)).orderBy(asc9(itemSubtasks.idx));
|
|
15542
15572
|
for (let i = 0; i < remaining.length; i++) {
|
|
15543
15573
|
const oldIdx = remaining[i].idx;
|
|
15544
15574
|
if (oldIdx === i) continue;
|
|
15545
15575
|
await orm.update(itemSubtasks).set({ idx: i }).where(
|
|
15546
|
-
and13(
|
|
15576
|
+
and13(eq35(itemSubtasks.itemId, itemId2), eq35(itemSubtasks.idx, oldIdx))
|
|
15547
15577
|
);
|
|
15548
15578
|
}
|
|
15549
15579
|
return row.title;
|
|
@@ -15612,20 +15642,20 @@ function registerSubtaskCommands(cmd) {
|
|
|
15612
15642
|
|
|
15613
15643
|
// src/commands/backlog/movePhase.ts
|
|
15614
15644
|
import chalk107 from "chalk";
|
|
15615
|
-
import { count as count6, eq as
|
|
15645
|
+
import { count as count6, eq as eq38 } from "drizzle-orm";
|
|
15616
15646
|
|
|
15617
15647
|
// src/commands/backlog/reorderPhaseRows.ts
|
|
15618
|
-
import { and as and15, asc as
|
|
15648
|
+
import { and as and15, asc as asc11, eq as eq37 } from "drizzle-orm";
|
|
15619
15649
|
|
|
15620
15650
|
// src/commands/backlog/reindexPhases.ts
|
|
15621
|
-
import { and as and14, asc as
|
|
15651
|
+
import { and as and14, asc as asc10, count as count5, eq as eq36 } from "drizzle-orm";
|
|
15622
15652
|
async function reindexPhases(db, itemId2) {
|
|
15623
|
-
const remaining = await db.select({ idx: planPhases.idx }).from(planPhases).where(
|
|
15653
|
+
const remaining = await db.select({ idx: planPhases.idx }).from(planPhases).where(eq36(planPhases.itemId, itemId2)).orderBy(asc10(planPhases.idx));
|
|
15624
15654
|
for (let i = 0; i < remaining.length; i++) {
|
|
15625
15655
|
const oldIdx = remaining[i].idx;
|
|
15626
15656
|
if (oldIdx === i) continue;
|
|
15627
|
-
await db.update(planTasks).set({ phaseIdx: i }).where(and14(
|
|
15628
|
-
await db.update(planPhases).set({ idx: i }).where(and14(
|
|
15657
|
+
await db.update(planTasks).set({ phaseIdx: i }).where(and14(eq36(planTasks.itemId, itemId2), eq36(planTasks.phaseIdx, oldIdx)));
|
|
15658
|
+
await db.update(planPhases).set({ idx: i }).where(and14(eq36(planPhases.itemId, itemId2), eq36(planPhases.idx, oldIdx)));
|
|
15629
15659
|
}
|
|
15630
15660
|
}
|
|
15631
15661
|
async function adjustCurrentPhase(db, item, removedIdx) {
|
|
@@ -15633,24 +15663,24 @@ async function adjustCurrentPhase(db, item, removedIdx) {
|
|
|
15633
15663
|
if (currentPhase === void 0) return;
|
|
15634
15664
|
const currentIdx = currentPhase - 1;
|
|
15635
15665
|
if (removedIdx < currentIdx) {
|
|
15636
|
-
await db.update(items).set({ currentPhase: currentPhase - 1 }).where(
|
|
15666
|
+
await db.update(items).set({ currentPhase: currentPhase - 1 }).where(eq36(items.id, item.id));
|
|
15637
15667
|
return;
|
|
15638
15668
|
}
|
|
15639
15669
|
if (removedIdx !== currentIdx) return;
|
|
15640
|
-
const [row] = await db.select({ cnt: count5() }).from(planPhases).where(
|
|
15670
|
+
const [row] = await db.select({ cnt: count5() }).from(planPhases).where(eq36(planPhases.itemId, item.id));
|
|
15641
15671
|
const cnt = row?.cnt ?? 0;
|
|
15642
|
-
await db.update(items).set({ currentPhase: cnt === 0 ? null : Math.min(currentPhase, cnt) }).where(
|
|
15672
|
+
await db.update(items).set({ currentPhase: cnt === 0 ? null : Math.min(currentPhase, cnt) }).where(eq36(items.id, item.id));
|
|
15643
15673
|
}
|
|
15644
15674
|
|
|
15645
15675
|
// src/commands/backlog/reorderPhaseRows.ts
|
|
15646
15676
|
async function reorderPhaseRows(orm, itemId2, fromIdx, toIdx) {
|
|
15647
15677
|
await orm.transaction(async (tx) => {
|
|
15648
|
-
const [phaseRow] = await tx.select({ name: planPhases.name, manualChecks: planPhases.manualChecks }).from(planPhases).where(and15(
|
|
15649
|
-
const tasks = await tx.select({ idx: planTasks.idx, task: planTasks.task }).from(planTasks).where(and15(
|
|
15678
|
+
const [phaseRow] = await tx.select({ name: planPhases.name, manualChecks: planPhases.manualChecks }).from(planPhases).where(and15(eq37(planPhases.itemId, itemId2), eq37(planPhases.idx, fromIdx)));
|
|
15679
|
+
const tasks = await tx.select({ idx: planTasks.idx, task: planTasks.task }).from(planTasks).where(and15(eq37(planTasks.itemId, itemId2), eq37(planTasks.phaseIdx, fromIdx))).orderBy(asc11(planTasks.idx));
|
|
15650
15680
|
await tx.delete(planTasks).where(
|
|
15651
|
-
and15(
|
|
15681
|
+
and15(eq37(planTasks.itemId, itemId2), eq37(planTasks.phaseIdx, fromIdx))
|
|
15652
15682
|
);
|
|
15653
|
-
await tx.delete(planPhases).where(and15(
|
|
15683
|
+
await tx.delete(planPhases).where(and15(eq37(planPhases.itemId, itemId2), eq37(planPhases.idx, fromIdx)));
|
|
15654
15684
|
await reindexPhases(tx, itemId2);
|
|
15655
15685
|
await shiftPhasesUp(tx, itemId2, toIdx);
|
|
15656
15686
|
await tx.insert(planPhases).values({
|
|
@@ -15691,7 +15721,7 @@ async function movePhase(id, from, to) {
|
|
|
15691
15721
|
if (!found) return;
|
|
15692
15722
|
const { orm, item } = found;
|
|
15693
15723
|
const itemId2 = item.id;
|
|
15694
|
-
const [row] = await orm.select({ cnt: count6() }).from(planPhases).where(
|
|
15724
|
+
const [row] = await orm.select({ cnt: count6() }).from(planPhases).where(eq38(planPhases.itemId, itemId2));
|
|
15695
15725
|
const phaseCount = row?.cnt ?? 0;
|
|
15696
15726
|
const fromIdx = toIndex2(from, phaseCount);
|
|
15697
15727
|
if (fromIdx === void 0) return;
|
|
@@ -15707,22 +15737,22 @@ async function movePhase(id, from, to) {
|
|
|
15707
15737
|
import chalk109 from "chalk";
|
|
15708
15738
|
|
|
15709
15739
|
// src/commands/backlog/applyPhaseUpdate.ts
|
|
15710
|
-
import { and as and16, eq as
|
|
15740
|
+
import { and as and16, eq as eq39 } from "drizzle-orm";
|
|
15711
15741
|
async function applyPhaseUpdate(orm, itemId2, phaseIdx, fields) {
|
|
15712
15742
|
await orm.transaction(async (tx) => {
|
|
15713
15743
|
if (fields.name) {
|
|
15714
15744
|
await tx.update(planPhases).set({ name: fields.name }).where(
|
|
15715
|
-
and16(
|
|
15745
|
+
and16(eq39(planPhases.itemId, itemId2), eq39(planPhases.idx, phaseIdx))
|
|
15716
15746
|
);
|
|
15717
15747
|
}
|
|
15718
15748
|
if (fields.manualCheck) {
|
|
15719
15749
|
await tx.update(planPhases).set({ manualChecks: JSON.stringify(fields.manualCheck) }).where(
|
|
15720
|
-
and16(
|
|
15750
|
+
and16(eq39(planPhases.itemId, itemId2), eq39(planPhases.idx, phaseIdx))
|
|
15721
15751
|
);
|
|
15722
15752
|
}
|
|
15723
15753
|
if (fields.task) {
|
|
15724
15754
|
await tx.delete(planTasks).where(
|
|
15725
|
-
and16(
|
|
15755
|
+
and16(eq39(planTasks.itemId, itemId2), eq39(planTasks.phaseIdx, phaseIdx))
|
|
15726
15756
|
);
|
|
15727
15757
|
if (fields.task.length) {
|
|
15728
15758
|
await tx.insert(planTasks).values(
|
|
@@ -15740,14 +15770,14 @@ async function applyPhaseUpdate(orm, itemId2, phaseIdx, fields) {
|
|
|
15740
15770
|
|
|
15741
15771
|
// src/commands/backlog/findPhase.ts
|
|
15742
15772
|
import chalk108 from "chalk";
|
|
15743
|
-
import { and as and17, count as count7, eq as
|
|
15773
|
+
import { and as and17, count as count7, eq as eq40 } from "drizzle-orm";
|
|
15744
15774
|
async function findPhase(id, phase) {
|
|
15745
15775
|
const found = await findOneItem(id);
|
|
15746
15776
|
if (!found) return void 0;
|
|
15747
15777
|
const { orm, item } = found;
|
|
15748
15778
|
const itemId2 = item.id;
|
|
15749
15779
|
const phaseIdx = Number.parseInt(phase, 10) - 1;
|
|
15750
|
-
const [row] = await orm.select({ cnt: count7() }).from(planPhases).where(and17(
|
|
15780
|
+
const [row] = await orm.select({ cnt: count7() }).from(planPhases).where(and17(eq40(planPhases.itemId, itemId2), eq40(planPhases.idx, phaseIdx)));
|
|
15751
15781
|
if (!row || row.cnt === 0) {
|
|
15752
15782
|
console.log(
|
|
15753
15783
|
chalk108.red(
|
|
@@ -15920,16 +15950,16 @@ function registerUpdatePhaseCommand(cmd) {
|
|
|
15920
15950
|
|
|
15921
15951
|
// src/commands/backlog/removePhase.ts
|
|
15922
15952
|
import chalk110 from "chalk";
|
|
15923
|
-
import { and as and18, eq as
|
|
15953
|
+
import { and as and18, eq as eq41 } from "drizzle-orm";
|
|
15924
15954
|
async function removePhase(id, phase) {
|
|
15925
15955
|
const found = await findPhase(id, phase);
|
|
15926
15956
|
if (!found) return;
|
|
15927
15957
|
const { item, orm, itemId: itemId2, phaseIdx } = found;
|
|
15928
15958
|
await orm.transaction(async (tx) => {
|
|
15929
15959
|
await tx.delete(planTasks).where(
|
|
15930
|
-
and18(
|
|
15960
|
+
and18(eq41(planTasks.itemId, itemId2), eq41(planTasks.phaseIdx, phaseIdx))
|
|
15931
15961
|
);
|
|
15932
|
-
await tx.delete(planPhases).where(and18(
|
|
15962
|
+
await tx.delete(planPhases).where(and18(eq41(planPhases.itemId, itemId2), eq41(planPhases.idx, phaseIdx)));
|
|
15933
15963
|
await reindexPhases(tx, itemId2);
|
|
15934
15964
|
await adjustCurrentPhase(tx, item, phaseIdx);
|
|
15935
15965
|
});
|
|
@@ -15942,13 +15972,13 @@ async function removePhase(id, phase) {
|
|
|
15942
15972
|
|
|
15943
15973
|
// src/commands/backlog/update/update.ts
|
|
15944
15974
|
import chalk114 from "chalk";
|
|
15945
|
-
import { eq as
|
|
15975
|
+
import { eq as eq42 } from "drizzle-orm";
|
|
15946
15976
|
|
|
15947
15977
|
// src/commands/backlog/update/buildUpdateValues.ts
|
|
15948
15978
|
import chalk111 from "chalk";
|
|
15949
15979
|
function buildUpdateValues(options2) {
|
|
15950
|
-
const { name, desc:
|
|
15951
|
-
if (!name && !
|
|
15980
|
+
const { name, desc: desc8, type, ac, origin } = options2;
|
|
15981
|
+
if (!name && !desc8 && !type && !ac && !origin) {
|
|
15952
15982
|
console.log(chalk111.red("Nothing to update. Provide at least one flag."));
|
|
15953
15983
|
process.exitCode = 1;
|
|
15954
15984
|
return void 0;
|
|
@@ -15964,8 +15994,8 @@ function buildUpdateValues(options2) {
|
|
|
15964
15994
|
set.name = name;
|
|
15965
15995
|
fieldNames.push("name");
|
|
15966
15996
|
}
|
|
15967
|
-
if (
|
|
15968
|
-
set.description =
|
|
15997
|
+
if (desc8) {
|
|
15998
|
+
set.description = desc8.replaceAll(String.raw`\n`, "\n");
|
|
15969
15999
|
fieldNames.push("description");
|
|
15970
16000
|
}
|
|
15971
16001
|
if (type) {
|
|
@@ -16053,7 +16083,7 @@ async function update(id, options2) {
|
|
|
16053
16083
|
if (!built) return;
|
|
16054
16084
|
const { orm } = found;
|
|
16055
16085
|
const itemId2 = found.item.id;
|
|
16056
|
-
await orm.update(items).set(built.set).where(
|
|
16086
|
+
await orm.update(items).set(built.set).where(eq42(items.id, itemId2));
|
|
16057
16087
|
console.log(
|
|
16058
16088
|
chalk114.green(`Updated ${built.fields} on item ${formatItemId(itemId2)}.`)
|
|
16059
16089
|
);
|
|
@@ -16074,7 +16104,7 @@ function readPlanUpdate(source) {
|
|
|
16074
16104
|
}
|
|
16075
16105
|
|
|
16076
16106
|
// src/commands/backlog/updatePlan/replacePlan.ts
|
|
16077
|
-
import { eq as
|
|
16107
|
+
import { eq as eq43 } from "drizzle-orm";
|
|
16078
16108
|
|
|
16079
16109
|
// src/commands/backlog/updatePlan/clampCurrentPhase.ts
|
|
16080
16110
|
function clampCurrentPhase(currentPhase, phaseCount) {
|
|
@@ -16085,8 +16115,8 @@ function clampCurrentPhase(currentPhase, phaseCount) {
|
|
|
16085
16115
|
// src/commands/backlog/updatePlan/replacePlan.ts
|
|
16086
16116
|
async function replacePlan(orm, itemId2, phases, currentPhase) {
|
|
16087
16117
|
await orm.transaction(async (tx) => {
|
|
16088
|
-
await tx.delete(planTasks).where(
|
|
16089
|
-
await tx.delete(planPhases).where(
|
|
16118
|
+
await tx.delete(planTasks).where(eq43(planTasks.itemId, itemId2));
|
|
16119
|
+
await tx.delete(planPhases).where(eq43(planPhases.itemId, itemId2));
|
|
16090
16120
|
if (phases.length > 0) {
|
|
16091
16121
|
await tx.insert(planPhases).values(
|
|
16092
16122
|
phases.map((phase, idx) => ({
|
|
@@ -16104,7 +16134,7 @@ async function replacePlan(orm, itemId2, phases, currentPhase) {
|
|
|
16104
16134
|
if (currentPhase === void 0) return;
|
|
16105
16135
|
const clamped = clampCurrentPhase(currentPhase, phases.length);
|
|
16106
16136
|
if (clamped === currentPhase) return;
|
|
16107
|
-
await tx.update(items).set({ currentPhase: clamped }).where(
|
|
16137
|
+
await tx.update(items).set({ currentPhase: clamped }).where(eq43(items.id, itemId2));
|
|
16108
16138
|
});
|
|
16109
16139
|
}
|
|
16110
16140
|
|
|
@@ -22869,9 +22899,9 @@ function registerGithub(program2) {
|
|
|
22869
22899
|
}
|
|
22870
22900
|
|
|
22871
22901
|
// src/commands/handover/countPendingHandovers.ts
|
|
22872
|
-
import { and as and19, eq as
|
|
22902
|
+
import { and as and19, eq as eq44, isNull, sql as sql22 } from "drizzle-orm";
|
|
22873
22903
|
async function countPendingHandovers(orm, origin) {
|
|
22874
|
-
const [row] = await orm.select({ count:
|
|
22904
|
+
const [row] = await orm.select({ count: sql22`count(*)::int` }).from(handovers).where(and19(eq44(handovers.origin, origin), isNull(handovers.recalledAt)));
|
|
22875
22905
|
return row?.count ?? 0;
|
|
22876
22906
|
}
|
|
22877
22907
|
|
|
@@ -23011,13 +23041,13 @@ async function load2(options2 = {}) {
|
|
|
23011
23041
|
}
|
|
23012
23042
|
|
|
23013
23043
|
// src/commands/handover/listPendingHandovers.ts
|
|
23014
|
-
import { and as and20, desc as
|
|
23044
|
+
import { and as and20, desc as desc6, eq as eq45, isNull as isNull2 } from "drizzle-orm";
|
|
23015
23045
|
async function listPendingHandovers(orm, origin) {
|
|
23016
23046
|
return orm.select({
|
|
23017
23047
|
id: handovers.id,
|
|
23018
23048
|
summary: handovers.summary,
|
|
23019
23049
|
createdAt: handovers.createdAt
|
|
23020
|
-
}).from(handovers).where(and20(
|
|
23050
|
+
}).from(handovers).where(and20(eq45(handovers.origin, origin), isNull2(handovers.recalledAt))).orderBy(desc6(handovers.createdAt), desc6(handovers.id));
|
|
23021
23051
|
}
|
|
23022
23052
|
|
|
23023
23053
|
// src/commands/handover/printPendingHandovers.ts
|
|
@@ -23030,17 +23060,17 @@ async function printPendingHandovers() {
|
|
|
23030
23060
|
}
|
|
23031
23061
|
|
|
23032
23062
|
// src/commands/handover/recallHandover.ts
|
|
23033
|
-
import { and as and21, desc as
|
|
23063
|
+
import { and as and21, desc as desc7, eq as eq46, isNull as isNull3 } from "drizzle-orm";
|
|
23034
23064
|
async function recallHandover(orm, origin, id) {
|
|
23035
23065
|
const [row] = await orm.select().from(handovers).where(
|
|
23036
23066
|
and21(
|
|
23037
|
-
|
|
23067
|
+
eq46(handovers.origin, origin),
|
|
23038
23068
|
isNull3(handovers.recalledAt),
|
|
23039
|
-
...id === void 0 ? [] : [
|
|
23069
|
+
...id === void 0 ? [] : [eq46(handovers.id, id)]
|
|
23040
23070
|
)
|
|
23041
|
-
).orderBy(
|
|
23071
|
+
).orderBy(desc7(handovers.createdAt), desc7(handovers.id)).limit(1);
|
|
23042
23072
|
if (!row) return void 0;
|
|
23043
|
-
await orm.update(handovers).set({ recalledAt: /* @__PURE__ */ new Date() }).where(
|
|
23073
|
+
await orm.update(handovers).set({ recalledAt: /* @__PURE__ */ new Date() }).where(eq46(handovers.id, row.id));
|
|
23044
23074
|
return row.content;
|
|
23045
23075
|
}
|
|
23046
23076
|
|
|
@@ -31560,8 +31590,8 @@ function filterToSql(filter) {
|
|
|
31560
31590
|
// src/commands/seq/fetchSeqData.ts
|
|
31561
31591
|
function buildDataParams(filter, count8, from, to) {
|
|
31562
31592
|
const sqlFilter = filterToSql(filter);
|
|
31563
|
-
const
|
|
31564
|
-
const params = new URLSearchParams({ q:
|
|
31593
|
+
const sql29 = `select @Timestamp, @Level, @Exception, @Message from stream where ${sqlFilter} order by @Timestamp desc limit ${count8}`;
|
|
31594
|
+
const params = new URLSearchParams({ q: sql29 });
|
|
31565
31595
|
if (from) params.set("rangeStartUtc", from);
|
|
31566
31596
|
if (to) params.set("rangeEndUtc", to);
|
|
31567
31597
|
return params;
|
|
@@ -31922,26 +31952,26 @@ import chalk222 from "chalk";
|
|
|
31922
31952
|
// src/commands/sql/loadConnections.ts
|
|
31923
31953
|
function loadConnections3() {
|
|
31924
31954
|
const raw = loadGlobalConfigRaw();
|
|
31925
|
-
const
|
|
31926
|
-
return
|
|
31955
|
+
const sql29 = raw.sql;
|
|
31956
|
+
return sql29?.connections ?? [];
|
|
31927
31957
|
}
|
|
31928
31958
|
function saveConnections3(connections) {
|
|
31929
31959
|
const raw = loadGlobalConfigRaw();
|
|
31930
|
-
const
|
|
31931
|
-
|
|
31932
|
-
raw.sql =
|
|
31960
|
+
const sql29 = raw.sql ?? {};
|
|
31961
|
+
sql29.connections = connections;
|
|
31962
|
+
raw.sql = sql29;
|
|
31933
31963
|
saveGlobalConfig(raw);
|
|
31934
31964
|
}
|
|
31935
31965
|
function getDefaultConnection2() {
|
|
31936
31966
|
const raw = loadGlobalConfigRaw();
|
|
31937
|
-
const
|
|
31938
|
-
return
|
|
31967
|
+
const sql29 = raw.sql;
|
|
31968
|
+
return sql29?.defaultConnection;
|
|
31939
31969
|
}
|
|
31940
31970
|
function setDefaultConnection2(name) {
|
|
31941
31971
|
const raw = loadGlobalConfigRaw();
|
|
31942
|
-
const
|
|
31943
|
-
|
|
31944
|
-
raw.sql =
|
|
31972
|
+
const sql29 = raw.sql ?? {};
|
|
31973
|
+
sql29.defaultConnection = name;
|
|
31974
|
+
raw.sql = sql29;
|
|
31945
31975
|
saveGlobalConfig(raw);
|
|
31946
31976
|
}
|
|
31947
31977
|
|
|
@@ -32012,9 +32042,9 @@ function resolveConnection3(name) {
|
|
|
32012
32042
|
}
|
|
32013
32043
|
|
|
32014
32044
|
// src/commands/sql/sqlConnect.ts
|
|
32015
|
-
import
|
|
32045
|
+
import sql23 from "mssql";
|
|
32016
32046
|
async function sqlConnect(conn) {
|
|
32017
|
-
return await
|
|
32047
|
+
return await sql23.connect({
|
|
32018
32048
|
server: conn.server,
|
|
32019
32049
|
port: conn.port,
|
|
32020
32050
|
user: conn.user,
|
|
@@ -32077,11 +32107,11 @@ var MUTATION_PATTERN = new RegExp(
|
|
|
32077
32107
|
`\\b(${MUTATION_KEYWORDS.join("|")})\\b`,
|
|
32078
32108
|
"i"
|
|
32079
32109
|
);
|
|
32080
|
-
function stripComments(
|
|
32081
|
-
return
|
|
32110
|
+
function stripComments(sql29) {
|
|
32111
|
+
return sql29.replace(/\/\*[\s\S]*?\*\//g, " ").replace(/--[^\n]*/g, " ");
|
|
32082
32112
|
}
|
|
32083
|
-
function isMutation(
|
|
32084
|
-
const stripped = stripComments(
|
|
32113
|
+
function isMutation(sql29) {
|
|
32114
|
+
const stripped = stripComments(sql29);
|
|
32085
32115
|
if (MUTATION_PATTERN.test(stripped)) return true;
|
|
32086
32116
|
return /\bSELECT\b[\s\S]+\bINTO\s+\w/i.test(stripped);
|
|
32087
32117
|
}
|
|
@@ -36095,13 +36125,13 @@ function drainSessions(sessions, notify2) {
|
|
|
36095
36125
|
}
|
|
36096
36126
|
|
|
36097
36127
|
// src/shared/db/recordPhaseActiveMs.ts
|
|
36098
|
-
import { sql as
|
|
36128
|
+
import { sql as sql24 } from "drizzle-orm";
|
|
36099
36129
|
async function recordPhaseActiveMs(db, itemId2, phaseIdx, activeMs) {
|
|
36100
36130
|
if (activeMs <= 0) return;
|
|
36101
36131
|
await db.insert(phaseUsage).values({ itemId: itemId2, phaseIdx, activeMs }).onConflictDoUpdate({
|
|
36102
36132
|
target: [phaseUsage.itemId, phaseUsage.phaseIdx],
|
|
36103
36133
|
set: {
|
|
36104
|
-
activeMs:
|
|
36134
|
+
activeMs: sql24`${phaseUsage.activeMs} + excluded.active_ms`
|
|
36105
36135
|
}
|
|
36106
36136
|
});
|
|
36107
36137
|
}
|
|
@@ -36539,10 +36569,10 @@ function applyReviewPause(session, activity2) {
|
|
|
36539
36569
|
}
|
|
36540
36570
|
|
|
36541
36571
|
// src/shared/db/getPhaseActiveMs.ts
|
|
36542
|
-
import { and as and22, eq as
|
|
36572
|
+
import { and as and22, eq as eq47 } from "drizzle-orm";
|
|
36543
36573
|
async function getPhaseActiveMs(db, itemId2, phaseIdx) {
|
|
36544
36574
|
const [row] = await db.select({ activeMs: phaseUsage.activeMs }).from(phaseUsage).where(
|
|
36545
|
-
and22(
|
|
36575
|
+
and22(eq47(phaseUsage.itemId, itemId2), eq47(phaseUsage.phaseIdx, phaseIdx))
|
|
36546
36576
|
);
|
|
36547
36577
|
return row?.activeMs ?? 0;
|
|
36548
36578
|
}
|
|
@@ -37311,7 +37341,7 @@ function makeSessionSpawner(sessions, clients, counter, onStatusChange, notify2)
|
|
|
37311
37341
|
}
|
|
37312
37342
|
|
|
37313
37343
|
// src/shared/db/recordPhaseCycleContext.ts
|
|
37314
|
-
import { sql as
|
|
37344
|
+
import { sql as sql25 } from "drizzle-orm";
|
|
37315
37345
|
async function recordPhaseCycleContext(db, itemId2, phaseIdx, window, resetsAt, pct) {
|
|
37316
37346
|
if (pct <= 0) return;
|
|
37317
37347
|
await db.insert(phaseCycleContext).values({ itemId: itemId2, phaseIdx, window, resetsAt, peakContextPct: pct }).onConflictDoUpdate({
|
|
@@ -37322,24 +37352,24 @@ async function recordPhaseCycleContext(db, itemId2, phaseIdx, window, resetsAt,
|
|
|
37322
37352
|
phaseCycleContext.resetsAt
|
|
37323
37353
|
],
|
|
37324
37354
|
set: {
|
|
37325
|
-
peakContextPct:
|
|
37355
|
+
peakContextPct: sql25`GREATEST(${phaseCycleContext.peakContextPct}, ${pct})`
|
|
37326
37356
|
}
|
|
37327
37357
|
});
|
|
37328
37358
|
}
|
|
37329
37359
|
|
|
37330
37360
|
// src/shared/db/recordPhasePeakContext.ts
|
|
37331
|
-
import { sql as
|
|
37361
|
+
import { sql as sql26 } from "drizzle-orm";
|
|
37332
37362
|
async function recordPhasePeakContext(db, itemId2, phaseIdx, pct) {
|
|
37333
37363
|
await db.insert(phaseUsage).values({ itemId: itemId2, phaseIdx, peakContextPct: pct }).onConflictDoUpdate({
|
|
37334
37364
|
target: [phaseUsage.itemId, phaseUsage.phaseIdx],
|
|
37335
37365
|
set: {
|
|
37336
|
-
peakContextPct:
|
|
37366
|
+
peakContextPct: sql26`GREATEST(${phaseUsage.peakContextPct}, ${pct})`
|
|
37337
37367
|
}
|
|
37338
37368
|
});
|
|
37339
37369
|
}
|
|
37340
37370
|
|
|
37341
37371
|
// src/shared/db/recordPhaseTranscriptUsage.ts
|
|
37342
|
-
import { sql as
|
|
37372
|
+
import { sql as sql27 } from "drizzle-orm";
|
|
37343
37373
|
async function recordPhaseTranscriptUsage(db, itemId2, phaseIdx, responses) {
|
|
37344
37374
|
const byId = /* @__PURE__ */ new Map();
|
|
37345
37375
|
for (const r of responses) byId.set(r.messageId, r);
|
|
@@ -37359,8 +37389,8 @@ async function recordPhaseTranscriptUsage(db, itemId2, phaseIdx, responses) {
|
|
|
37359
37389
|
await tx.insert(phaseUsage).values({ itemId: itemId2, phaseIdx, tokensUp, tokensDown }).onConflictDoUpdate({
|
|
37360
37390
|
target: [phaseUsage.itemId, phaseUsage.phaseIdx],
|
|
37361
37391
|
set: {
|
|
37362
|
-
tokensUp:
|
|
37363
|
-
tokensDown:
|
|
37392
|
+
tokensUp: sql27`${phaseUsage.tokensUp} + ${tokensUp}`,
|
|
37393
|
+
tokensDown: sql27`${phaseUsage.tokensDown} + ${tokensDown}`
|
|
37364
37394
|
}
|
|
37365
37395
|
});
|
|
37366
37396
|
return { tokensUp, tokensDown };
|
|
@@ -37368,17 +37398,17 @@ async function recordPhaseTranscriptUsage(db, itemId2, phaseIdx, responses) {
|
|
|
37368
37398
|
}
|
|
37369
37399
|
|
|
37370
37400
|
// src/shared/db/recordWindowTokens.ts
|
|
37371
|
-
import { and as and23, eq as
|
|
37401
|
+
import { and as and23, eq as eq48, sql as sql28 } from "drizzle-orm";
|
|
37372
37402
|
async function recordWindowTokens(db, window, resetsAt, tokensUp, tokensDown) {
|
|
37373
37403
|
if (tokensUp <= 0 && tokensDown <= 0) return;
|
|
37374
37404
|
await db.update(usagePeaks).set({
|
|
37375
|
-
tokensUp:
|
|
37376
|
-
tokensDown:
|
|
37405
|
+
tokensUp: sql28`${usagePeaks.tokensUp} + ${tokensUp}`,
|
|
37406
|
+
tokensDown: sql28`${usagePeaks.tokensDown} + ${tokensDown}`
|
|
37377
37407
|
}).where(
|
|
37378
37408
|
and23(
|
|
37379
|
-
|
|
37380
|
-
|
|
37381
|
-
|
|
37409
|
+
eq48(usagePeaks.window, window),
|
|
37410
|
+
eq48(usagePeaks.resetsAt, resetsAt),
|
|
37411
|
+
eq48(usagePeaks.segment, 0)
|
|
37382
37412
|
)
|
|
37383
37413
|
);
|
|
37384
37414
|
}
|