@staff0rd/assist 0.633.0 → 0.634.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/sessions/web/bundle.js +402 -402
- package/dist/index.js +143 -85
- 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.1",
|
|
10
10
|
type: "module",
|
|
11
11
|
main: "dist/index.js",
|
|
12
12
|
bin: {
|
|
@@ -11739,8 +11739,44 @@ async function countItemUsageByOrigin(db) {
|
|
|
11739
11739
|
return rows.map((row) => ({ origin: row.origin, count: Number(row.count) }));
|
|
11740
11740
|
}
|
|
11741
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
|
+
|
|
11742
11778
|
// src/shared/db/itemUsageStats.ts
|
|
11743
|
-
import { eq as
|
|
11779
|
+
import { eq as eq22, sql as sql18 } from "drizzle-orm";
|
|
11744
11780
|
function median(value) {
|
|
11745
11781
|
return sql18`coalesce(percentile_cont(0.5) within group (order by (${value})::double precision), 0)`;
|
|
11746
11782
|
}
|
|
@@ -11756,7 +11792,7 @@ async function itemUsageStats(db, options2) {
|
|
|
11756
11792
|
),
|
|
11757
11793
|
medianActiveMs: median(totals.activeMs),
|
|
11758
11794
|
medianTokens: median(sql18`${totals.tokensUp} + ${totals.tokensDown}`)
|
|
11759
|
-
}).from(items).innerJoin(totals,
|
|
11795
|
+
}).from(items).innerJoin(totals, eq22(totals.itemId, items.id)).leftJoin(planned, eq22(planned.itemId, items.id)).where(itemUsageWhere(options2));
|
|
11760
11796
|
return {
|
|
11761
11797
|
itemCount: Number(row?.itemCount ?? 0),
|
|
11762
11798
|
doneCount: Number(row?.doneCount ?? 0),
|
|
@@ -11768,15 +11804,30 @@ async function itemUsageStats(db, options2) {
|
|
|
11768
11804
|
}
|
|
11769
11805
|
|
|
11770
11806
|
// src/shared/db/listItemUsageSummaries.ts
|
|
11771
|
-
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
|
+
}
|
|
11772
11823
|
|
|
11773
11824
|
// src/shared/db/lastPhaseActivity.ts
|
|
11774
|
-
import { sql as
|
|
11825
|
+
import { sql as sql20 } from "drizzle-orm";
|
|
11775
11826
|
function lastPhaseActivity(db) {
|
|
11776
11827
|
return db.select({
|
|
11777
11828
|
itemId: phaseSessions.itemId,
|
|
11778
|
-
at:
|
|
11779
|
-
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(
|
|
11780
11831
|
"last_phase_at_iso"
|
|
11781
11832
|
)
|
|
11782
11833
|
}).from(phaseSessions).groupBy(phaseSessions.itemId).as("last_phase_activity");
|
|
@@ -11814,7 +11865,9 @@ async function listItemUsageSummaries(db, options2) {
|
|
|
11814
11865
|
activeMs: totals.activeMs,
|
|
11815
11866
|
peakContextPct: totals.peakContextPct,
|
|
11816
11867
|
lastPhaseAt: lastPhase.atIso
|
|
11817
|
-
}).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
|
+
);
|
|
11818
11871
|
const rows = options2?.limit === void 0 ? await query : await query.limit(options2.limit).offset(options2.offset ?? 0);
|
|
11819
11872
|
return rows.map(toItemUsageSummary);
|
|
11820
11873
|
}
|
|
@@ -11823,10 +11876,15 @@ async function listItemUsageSummaries(db, options2) {
|
|
|
11823
11876
|
function listUsageItems(req, res) {
|
|
11824
11877
|
return respondPagedRows(req, res, async (range, params) => {
|
|
11825
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
|
+
);
|
|
11826
11884
|
const db = await getDb();
|
|
11827
11885
|
const [rows, summary, origins] = await Promise.all([
|
|
11828
|
-
listItemUsageSummaries(db, { ...range, origin }),
|
|
11829
|
-
itemUsageStats(db, { origin }),
|
|
11886
|
+
listItemUsageSummaries(db, { ...range, origin, status: status3, sort }),
|
|
11887
|
+
itemUsageStats(db, { origin, status: status3 }),
|
|
11830
11888
|
countItemUsageByOrigin(db)
|
|
11831
11889
|
]);
|
|
11832
11890
|
return { rows, total: summary.itemCount, summary, origins };
|
|
@@ -13652,11 +13710,11 @@ function registerActivityCommands(cmd) {
|
|
|
13652
13710
|
|
|
13653
13711
|
// src/commands/backlog/associate-github/index.ts
|
|
13654
13712
|
import chalk66 from "chalk";
|
|
13655
|
-
import { eq as
|
|
13713
|
+
import { eq as eq25 } from "drizzle-orm";
|
|
13656
13714
|
|
|
13657
13715
|
// src/commands/backlog/beginAssociation.ts
|
|
13658
13716
|
import chalk65 from "chalk";
|
|
13659
|
-
import { eq as
|
|
13717
|
+
import { eq as eq24 } from "drizzle-orm";
|
|
13660
13718
|
async function beginAssociation(id, options2, clearPatch, label2) {
|
|
13661
13719
|
const found = await findOneItem(id);
|
|
13662
13720
|
if (!found) {
|
|
@@ -13666,7 +13724,7 @@ async function beginAssociation(id, options2, clearPatch, label2) {
|
|
|
13666
13724
|
const { orm } = found;
|
|
13667
13725
|
const itemId2 = found.item.id;
|
|
13668
13726
|
if (options2.clear) {
|
|
13669
|
-
await orm.update(items).set(clearPatch).where(
|
|
13727
|
+
await orm.update(items).set(clearPatch).where(eq24(items.id, itemId2));
|
|
13670
13728
|
console.log(
|
|
13671
13729
|
chalk65.green(
|
|
13672
13730
|
`Cleared ${label2} association on item ${formatItemId(itemId2)}.`
|
|
@@ -13734,7 +13792,7 @@ async function associateGithub(id, issue, options2) {
|
|
|
13734
13792
|
return;
|
|
13735
13793
|
}
|
|
13736
13794
|
const title = fetchGithubIssueTitle(normalized);
|
|
13737
|
-
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));
|
|
13738
13796
|
console.log(
|
|
13739
13797
|
chalk66.green(`Associated ${normalized} with item ${formatItemId(itemId2)}.`),
|
|
13740
13798
|
title ? chalk66.dim(`(${title})`) : ""
|
|
@@ -13748,7 +13806,7 @@ function registerAssociateGithubCommand(cmd) {
|
|
|
13748
13806
|
|
|
13749
13807
|
// src/commands/backlog/associate-jira/index.ts
|
|
13750
13808
|
import chalk68 from "chalk";
|
|
13751
|
-
import { eq as
|
|
13809
|
+
import { eq as eq26 } from "drizzle-orm";
|
|
13752
13810
|
|
|
13753
13811
|
// src/commands/jira/fetchIssue.ts
|
|
13754
13812
|
import { execSync as execSync27 } from "child_process";
|
|
@@ -13813,7 +13871,7 @@ async function associateJira(id, key, options2) {
|
|
|
13813
13871
|
const parsed = fetchIssue(normalized, "summary");
|
|
13814
13872
|
const fields = parsed?.fields;
|
|
13815
13873
|
const summary = fields?.summary;
|
|
13816
|
-
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));
|
|
13817
13875
|
console.log(
|
|
13818
13876
|
chalk68.green(`Associated ${normalized} with item ${formatItemId(itemId2)}.`),
|
|
13819
13877
|
summary ? chalk68.dim(`(${summary})`) : ""
|
|
@@ -14320,15 +14378,15 @@ function isClaudeCode() {
|
|
|
14320
14378
|
}
|
|
14321
14379
|
|
|
14322
14380
|
// src/commands/backlog/insertPhaseAt.ts
|
|
14323
|
-
import { eq as
|
|
14381
|
+
import { eq as eq28 } from "drizzle-orm";
|
|
14324
14382
|
|
|
14325
14383
|
// src/commands/backlog/shiftPhasesUp.ts
|
|
14326
|
-
import { and as
|
|
14384
|
+
import { and as and10, desc as desc5, eq as eq27, gte } from "drizzle-orm";
|
|
14327
14385
|
async function shiftPhasesUp(db, itemId2, fromIdx) {
|
|
14328
|
-
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));
|
|
14329
14387
|
for (const p of toShift) {
|
|
14330
|
-
await db.update(planTasks).set({ phaseIdx: p.idx + 1 }).where(
|
|
14331
|
-
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)));
|
|
14332
14390
|
}
|
|
14333
14391
|
}
|
|
14334
14392
|
|
|
@@ -14341,7 +14399,7 @@ async function insertPhaseAt(orm, itemId2, phaseIdx, name, tasks, manualChecks,
|
|
|
14341
14399
|
await tx.insert(planTasks).values(tasks.map((task, i) => ({ itemId: itemId2, phaseIdx, idx: i, task })));
|
|
14342
14400
|
}
|
|
14343
14401
|
if (currentPhase !== void 0 && currentPhase - 1 >= phaseIdx) {
|
|
14344
|
-
await tx.update(items).set({ currentPhase: phaseIdx + 1 }).where(
|
|
14402
|
+
await tx.update(items).set({ currentPhase: phaseIdx + 1 }).where(eq28(items.id, itemId2));
|
|
14345
14403
|
}
|
|
14346
14404
|
});
|
|
14347
14405
|
}
|
|
@@ -14513,9 +14571,9 @@ import chalk78 from "chalk";
|
|
|
14513
14571
|
|
|
14514
14572
|
// src/commands/backlog/resolveInsertPosition.ts
|
|
14515
14573
|
import chalk77 from "chalk";
|
|
14516
|
-
import { count as count3, eq as
|
|
14574
|
+
import { count as count3, eq as eq29 } from "drizzle-orm";
|
|
14517
14575
|
async function resolveInsertPosition(orm, itemId2, position) {
|
|
14518
|
-
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));
|
|
14519
14577
|
const phaseCount = row?.cnt ?? 0;
|
|
14520
14578
|
if (position === void 0) return phaseCount;
|
|
14521
14579
|
const pos = Number.parseInt(position, 10);
|
|
@@ -14810,9 +14868,9 @@ function hasCycle(adjacency, fromId, toId) {
|
|
|
14810
14868
|
}
|
|
14811
14869
|
|
|
14812
14870
|
// src/commands/backlog/loadDependencyGraph.ts
|
|
14813
|
-
import { eq as
|
|
14871
|
+
import { eq as eq30 } from "drizzle-orm";
|
|
14814
14872
|
async function loadDependencyGraph(orm) {
|
|
14815
|
-
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"));
|
|
14816
14874
|
const graph = /* @__PURE__ */ new Map();
|
|
14817
14875
|
for (const { itemId: itemId2, targetId } of rows) {
|
|
14818
14876
|
const bucket = graph.get(itemId2);
|
|
@@ -14879,7 +14937,7 @@ async function link(fromId, toId, opts) {
|
|
|
14879
14937
|
|
|
14880
14938
|
// src/commands/backlog/unlink.ts
|
|
14881
14939
|
import chalk85 from "chalk";
|
|
14882
|
-
import { and as
|
|
14940
|
+
import { and as and11, eq as eq31 } from "drizzle-orm";
|
|
14883
14941
|
async function unlink(fromId, toId) {
|
|
14884
14942
|
const fromNum = parseItemId(fromId);
|
|
14885
14943
|
const toNum = parseItemId(toId);
|
|
@@ -14903,7 +14961,7 @@ async function unlink(fromId, toId) {
|
|
|
14903
14961
|
);
|
|
14904
14962
|
return;
|
|
14905
14963
|
}
|
|
14906
|
-
await orm.delete(links).where(
|
|
14964
|
+
await orm.delete(links).where(and11(eq31(links.itemId, fromNum), eq31(links.targetId, toNum)));
|
|
14907
14965
|
console.log(
|
|
14908
14966
|
chalk85.green(
|
|
14909
14967
|
`Removed link from ${formatItemId(fromNum)} to ${formatItemId(toNum)}.`
|
|
@@ -14923,7 +14981,7 @@ function registerLinkCommands(cmd) {
|
|
|
14923
14981
|
|
|
14924
14982
|
// src/commands/backlog/move-repo/index.ts
|
|
14925
14983
|
import chalk87 from "chalk";
|
|
14926
|
-
import { eq as
|
|
14984
|
+
import { eq as eq33 } from "drizzle-orm";
|
|
14927
14985
|
|
|
14928
14986
|
// src/commands/backlog/move-repo/confirmMove.ts
|
|
14929
14987
|
import chalk86 from "chalk";
|
|
@@ -14938,9 +14996,9 @@ async function confirmMove(cnt, oldOrigin, newOrigin) {
|
|
|
14938
14996
|
}
|
|
14939
14997
|
|
|
14940
14998
|
// src/commands/backlog/move-repo/countByOrigin.ts
|
|
14941
|
-
import { count as count4, eq as
|
|
14999
|
+
import { count as count4, eq as eq32 } from "drizzle-orm";
|
|
14942
15000
|
async function countByOrigin(orm, origin) {
|
|
14943
|
-
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));
|
|
14944
15002
|
return cnt;
|
|
14945
15003
|
}
|
|
14946
15004
|
|
|
@@ -14983,7 +15041,7 @@ async function moveRepo(oldOriginRaw, newOriginRaw, options2 = {}) {
|
|
|
14983
15041
|
console.log(chalk87.yellow("Move cancelled; no changes made."));
|
|
14984
15042
|
return;
|
|
14985
15043
|
}
|
|
14986
|
-
await orm.update(items).set({ origin: newOrigin }).where(
|
|
15044
|
+
await orm.update(items).set({ origin: newOrigin }).where(eq33(items.origin, oldOrigin));
|
|
14987
15045
|
console.log(
|
|
14988
15046
|
chalk87.green(
|
|
14989
15047
|
`Moved ${pluralItems(cnt)} from "${oldOrigin}" to "${newOrigin}".`
|
|
@@ -15383,10 +15441,10 @@ async function start(id) {
|
|
|
15383
15441
|
|
|
15384
15442
|
// src/commands/backlog/stop/index.ts
|
|
15385
15443
|
import chalk99 from "chalk";
|
|
15386
|
-
import { and as
|
|
15444
|
+
import { and as and12, eq as eq34 } from "drizzle-orm";
|
|
15387
15445
|
async function stop() {
|
|
15388
15446
|
const { orm } = await getReady();
|
|
15389
|
-
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 });
|
|
15390
15448
|
if (stopped.length === 0) {
|
|
15391
15449
|
console.log(chalk99.yellow("No in-progress items to stop."));
|
|
15392
15450
|
return;
|
|
@@ -15503,13 +15561,13 @@ async function findSubtask(id, index3) {
|
|
|
15503
15561
|
}
|
|
15504
15562
|
|
|
15505
15563
|
// src/commands/backlog/updateSubtask.ts
|
|
15506
|
-
import { and as
|
|
15564
|
+
import { and as and13, eq as eq35 } from "drizzle-orm";
|
|
15507
15565
|
async function updateSubtask(orm, itemId2, idx, fields) {
|
|
15508
15566
|
const set = {};
|
|
15509
15567
|
if (fields.title !== void 0) set.title = fields.title;
|
|
15510
15568
|
if (fields.description !== void 0) set.description = fields.description;
|
|
15511
15569
|
if (fields.status !== void 0) set.status = fields.status;
|
|
15512
|
-
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 });
|
|
15513
15571
|
return row?.title;
|
|
15514
15572
|
}
|
|
15515
15573
|
|
|
@@ -15564,16 +15622,16 @@ async function editSubtask(id, index3, options2) {
|
|
|
15564
15622
|
import chalk105 from "chalk";
|
|
15565
15623
|
|
|
15566
15624
|
// src/commands/backlog/deleteSubtask.ts
|
|
15567
|
-
import { and as
|
|
15625
|
+
import { and as and14, asc as asc9, eq as eq36 } from "drizzle-orm";
|
|
15568
15626
|
async function deleteSubtask(orm, itemId2, idx) {
|
|
15569
|
-
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 });
|
|
15570
15628
|
if (!row) return void 0;
|
|
15571
|
-
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));
|
|
15572
15630
|
for (let i = 0; i < remaining.length; i++) {
|
|
15573
15631
|
const oldIdx = remaining[i].idx;
|
|
15574
15632
|
if (oldIdx === i) continue;
|
|
15575
15633
|
await orm.update(itemSubtasks).set({ idx: i }).where(
|
|
15576
|
-
|
|
15634
|
+
and14(eq36(itemSubtasks.itemId, itemId2), eq36(itemSubtasks.idx, oldIdx))
|
|
15577
15635
|
);
|
|
15578
15636
|
}
|
|
15579
15637
|
return row.title;
|
|
@@ -15642,20 +15700,20 @@ function registerSubtaskCommands(cmd) {
|
|
|
15642
15700
|
|
|
15643
15701
|
// src/commands/backlog/movePhase.ts
|
|
15644
15702
|
import chalk107 from "chalk";
|
|
15645
|
-
import { count as count6, eq as
|
|
15703
|
+
import { count as count6, eq as eq39 } from "drizzle-orm";
|
|
15646
15704
|
|
|
15647
15705
|
// src/commands/backlog/reorderPhaseRows.ts
|
|
15648
|
-
import { and as
|
|
15706
|
+
import { and as and16, asc as asc11, eq as eq38 } from "drizzle-orm";
|
|
15649
15707
|
|
|
15650
15708
|
// src/commands/backlog/reindexPhases.ts
|
|
15651
|
-
import { and as
|
|
15709
|
+
import { and as and15, asc as asc10, count as count5, eq as eq37 } from "drizzle-orm";
|
|
15652
15710
|
async function reindexPhases(db, itemId2) {
|
|
15653
|
-
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));
|
|
15654
15712
|
for (let i = 0; i < remaining.length; i++) {
|
|
15655
15713
|
const oldIdx = remaining[i].idx;
|
|
15656
15714
|
if (oldIdx === i) continue;
|
|
15657
|
-
await db.update(planTasks).set({ phaseIdx: i }).where(
|
|
15658
|
-
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)));
|
|
15659
15717
|
}
|
|
15660
15718
|
}
|
|
15661
15719
|
async function adjustCurrentPhase(db, item, removedIdx) {
|
|
@@ -15663,24 +15721,24 @@ async function adjustCurrentPhase(db, item, removedIdx) {
|
|
|
15663
15721
|
if (currentPhase === void 0) return;
|
|
15664
15722
|
const currentIdx = currentPhase - 1;
|
|
15665
15723
|
if (removedIdx < currentIdx) {
|
|
15666
|
-
await db.update(items).set({ currentPhase: currentPhase - 1 }).where(
|
|
15724
|
+
await db.update(items).set({ currentPhase: currentPhase - 1 }).where(eq37(items.id, item.id));
|
|
15667
15725
|
return;
|
|
15668
15726
|
}
|
|
15669
15727
|
if (removedIdx !== currentIdx) return;
|
|
15670
|
-
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));
|
|
15671
15729
|
const cnt = row?.cnt ?? 0;
|
|
15672
|
-
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));
|
|
15673
15731
|
}
|
|
15674
15732
|
|
|
15675
15733
|
// src/commands/backlog/reorderPhaseRows.ts
|
|
15676
15734
|
async function reorderPhaseRows(orm, itemId2, fromIdx, toIdx) {
|
|
15677
15735
|
await orm.transaction(async (tx) => {
|
|
15678
|
-
const [phaseRow] = await tx.select({ name: planPhases.name, manualChecks: planPhases.manualChecks }).from(planPhases).where(
|
|
15679
|
-
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));
|
|
15680
15738
|
await tx.delete(planTasks).where(
|
|
15681
|
-
|
|
15739
|
+
and16(eq38(planTasks.itemId, itemId2), eq38(planTasks.phaseIdx, fromIdx))
|
|
15682
15740
|
);
|
|
15683
|
-
await tx.delete(planPhases).where(
|
|
15741
|
+
await tx.delete(planPhases).where(and16(eq38(planPhases.itemId, itemId2), eq38(planPhases.idx, fromIdx)));
|
|
15684
15742
|
await reindexPhases(tx, itemId2);
|
|
15685
15743
|
await shiftPhasesUp(tx, itemId2, toIdx);
|
|
15686
15744
|
await tx.insert(planPhases).values({
|
|
@@ -15721,7 +15779,7 @@ async function movePhase(id, from, to) {
|
|
|
15721
15779
|
if (!found) return;
|
|
15722
15780
|
const { orm, item } = found;
|
|
15723
15781
|
const itemId2 = item.id;
|
|
15724
|
-
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));
|
|
15725
15783
|
const phaseCount = row?.cnt ?? 0;
|
|
15726
15784
|
const fromIdx = toIndex2(from, phaseCount);
|
|
15727
15785
|
if (fromIdx === void 0) return;
|
|
@@ -15737,22 +15795,22 @@ async function movePhase(id, from, to) {
|
|
|
15737
15795
|
import chalk109 from "chalk";
|
|
15738
15796
|
|
|
15739
15797
|
// src/commands/backlog/applyPhaseUpdate.ts
|
|
15740
|
-
import { and as
|
|
15798
|
+
import { and as and17, eq as eq40 } from "drizzle-orm";
|
|
15741
15799
|
async function applyPhaseUpdate(orm, itemId2, phaseIdx, fields) {
|
|
15742
15800
|
await orm.transaction(async (tx) => {
|
|
15743
15801
|
if (fields.name) {
|
|
15744
15802
|
await tx.update(planPhases).set({ name: fields.name }).where(
|
|
15745
|
-
|
|
15803
|
+
and17(eq40(planPhases.itemId, itemId2), eq40(planPhases.idx, phaseIdx))
|
|
15746
15804
|
);
|
|
15747
15805
|
}
|
|
15748
15806
|
if (fields.manualCheck) {
|
|
15749
15807
|
await tx.update(planPhases).set({ manualChecks: JSON.stringify(fields.manualCheck) }).where(
|
|
15750
|
-
|
|
15808
|
+
and17(eq40(planPhases.itemId, itemId2), eq40(planPhases.idx, phaseIdx))
|
|
15751
15809
|
);
|
|
15752
15810
|
}
|
|
15753
15811
|
if (fields.task) {
|
|
15754
15812
|
await tx.delete(planTasks).where(
|
|
15755
|
-
|
|
15813
|
+
and17(eq40(planTasks.itemId, itemId2), eq40(planTasks.phaseIdx, phaseIdx))
|
|
15756
15814
|
);
|
|
15757
15815
|
if (fields.task.length) {
|
|
15758
15816
|
await tx.insert(planTasks).values(
|
|
@@ -15770,14 +15828,14 @@ async function applyPhaseUpdate(orm, itemId2, phaseIdx, fields) {
|
|
|
15770
15828
|
|
|
15771
15829
|
// src/commands/backlog/findPhase.ts
|
|
15772
15830
|
import chalk108 from "chalk";
|
|
15773
|
-
import { and as
|
|
15831
|
+
import { and as and18, count as count7, eq as eq41 } from "drizzle-orm";
|
|
15774
15832
|
async function findPhase(id, phase) {
|
|
15775
15833
|
const found = await findOneItem(id);
|
|
15776
15834
|
if (!found) return void 0;
|
|
15777
15835
|
const { orm, item } = found;
|
|
15778
15836
|
const itemId2 = item.id;
|
|
15779
15837
|
const phaseIdx = Number.parseInt(phase, 10) - 1;
|
|
15780
|
-
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)));
|
|
15781
15839
|
if (!row || row.cnt === 0) {
|
|
15782
15840
|
console.log(
|
|
15783
15841
|
chalk108.red(
|
|
@@ -15950,16 +16008,16 @@ function registerUpdatePhaseCommand(cmd) {
|
|
|
15950
16008
|
|
|
15951
16009
|
// src/commands/backlog/removePhase.ts
|
|
15952
16010
|
import chalk110 from "chalk";
|
|
15953
|
-
import { and as
|
|
16011
|
+
import { and as and19, eq as eq42 } from "drizzle-orm";
|
|
15954
16012
|
async function removePhase(id, phase) {
|
|
15955
16013
|
const found = await findPhase(id, phase);
|
|
15956
16014
|
if (!found) return;
|
|
15957
16015
|
const { item, orm, itemId: itemId2, phaseIdx } = found;
|
|
15958
16016
|
await orm.transaction(async (tx) => {
|
|
15959
16017
|
await tx.delete(planTasks).where(
|
|
15960
|
-
|
|
16018
|
+
and19(eq42(planTasks.itemId, itemId2), eq42(planTasks.phaseIdx, phaseIdx))
|
|
15961
16019
|
);
|
|
15962
|
-
await tx.delete(planPhases).where(
|
|
16020
|
+
await tx.delete(planPhases).where(and19(eq42(planPhases.itemId, itemId2), eq42(planPhases.idx, phaseIdx)));
|
|
15963
16021
|
await reindexPhases(tx, itemId2);
|
|
15964
16022
|
await adjustCurrentPhase(tx, item, phaseIdx);
|
|
15965
16023
|
});
|
|
@@ -15972,7 +16030,7 @@ async function removePhase(id, phase) {
|
|
|
15972
16030
|
|
|
15973
16031
|
// src/commands/backlog/update/update.ts
|
|
15974
16032
|
import chalk114 from "chalk";
|
|
15975
|
-
import { eq as
|
|
16033
|
+
import { eq as eq43 } from "drizzle-orm";
|
|
15976
16034
|
|
|
15977
16035
|
// src/commands/backlog/update/buildUpdateValues.ts
|
|
15978
16036
|
import chalk111 from "chalk";
|
|
@@ -16083,7 +16141,7 @@ async function update(id, options2) {
|
|
|
16083
16141
|
if (!built) return;
|
|
16084
16142
|
const { orm } = found;
|
|
16085
16143
|
const itemId2 = found.item.id;
|
|
16086
|
-
await orm.update(items).set(built.set).where(
|
|
16144
|
+
await orm.update(items).set(built.set).where(eq43(items.id, itemId2));
|
|
16087
16145
|
console.log(
|
|
16088
16146
|
chalk114.green(`Updated ${built.fields} on item ${formatItemId(itemId2)}.`)
|
|
16089
16147
|
);
|
|
@@ -16104,7 +16162,7 @@ function readPlanUpdate(source) {
|
|
|
16104
16162
|
}
|
|
16105
16163
|
|
|
16106
16164
|
// src/commands/backlog/updatePlan/replacePlan.ts
|
|
16107
|
-
import { eq as
|
|
16165
|
+
import { eq as eq44 } from "drizzle-orm";
|
|
16108
16166
|
|
|
16109
16167
|
// src/commands/backlog/updatePlan/clampCurrentPhase.ts
|
|
16110
16168
|
function clampCurrentPhase(currentPhase, phaseCount) {
|
|
@@ -16115,8 +16173,8 @@ function clampCurrentPhase(currentPhase, phaseCount) {
|
|
|
16115
16173
|
// src/commands/backlog/updatePlan/replacePlan.ts
|
|
16116
16174
|
async function replacePlan(orm, itemId2, phases, currentPhase) {
|
|
16117
16175
|
await orm.transaction(async (tx) => {
|
|
16118
|
-
await tx.delete(planTasks).where(
|
|
16119
|
-
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));
|
|
16120
16178
|
if (phases.length > 0) {
|
|
16121
16179
|
await tx.insert(planPhases).values(
|
|
16122
16180
|
phases.map((phase, idx) => ({
|
|
@@ -16134,7 +16192,7 @@ async function replacePlan(orm, itemId2, phases, currentPhase) {
|
|
|
16134
16192
|
if (currentPhase === void 0) return;
|
|
16135
16193
|
const clamped = clampCurrentPhase(currentPhase, phases.length);
|
|
16136
16194
|
if (clamped === currentPhase) return;
|
|
16137
|
-
await tx.update(items).set({ currentPhase: clamped }).where(
|
|
16195
|
+
await tx.update(items).set({ currentPhase: clamped }).where(eq44(items.id, itemId2));
|
|
16138
16196
|
});
|
|
16139
16197
|
}
|
|
16140
16198
|
|
|
@@ -22899,9 +22957,9 @@ function registerGithub(program2) {
|
|
|
22899
22957
|
}
|
|
22900
22958
|
|
|
22901
22959
|
// src/commands/handover/countPendingHandovers.ts
|
|
22902
|
-
import { and as
|
|
22960
|
+
import { and as and20, eq as eq45, isNull, sql as sql22 } from "drizzle-orm";
|
|
22903
22961
|
async function countPendingHandovers(orm, origin) {
|
|
22904
|
-
const [row] = await orm.select({ count: sql22`count(*)::int` }).from(handovers).where(
|
|
22962
|
+
const [row] = await orm.select({ count: sql22`count(*)::int` }).from(handovers).where(and20(eq45(handovers.origin, origin), isNull(handovers.recalledAt)));
|
|
22905
22963
|
return row?.count ?? 0;
|
|
22906
22964
|
}
|
|
22907
22965
|
|
|
@@ -23041,13 +23099,13 @@ async function load2(options2 = {}) {
|
|
|
23041
23099
|
}
|
|
23042
23100
|
|
|
23043
23101
|
// src/commands/handover/listPendingHandovers.ts
|
|
23044
|
-
import { and as
|
|
23102
|
+
import { and as and21, desc as desc6, eq as eq46, isNull as isNull2 } from "drizzle-orm";
|
|
23045
23103
|
async function listPendingHandovers(orm, origin) {
|
|
23046
23104
|
return orm.select({
|
|
23047
23105
|
id: handovers.id,
|
|
23048
23106
|
summary: handovers.summary,
|
|
23049
23107
|
createdAt: handovers.createdAt
|
|
23050
|
-
}).from(handovers).where(
|
|
23108
|
+
}).from(handovers).where(and21(eq46(handovers.origin, origin), isNull2(handovers.recalledAt))).orderBy(desc6(handovers.createdAt), desc6(handovers.id));
|
|
23051
23109
|
}
|
|
23052
23110
|
|
|
23053
23111
|
// src/commands/handover/printPendingHandovers.ts
|
|
@@ -23060,17 +23118,17 @@ async function printPendingHandovers() {
|
|
|
23060
23118
|
}
|
|
23061
23119
|
|
|
23062
23120
|
// src/commands/handover/recallHandover.ts
|
|
23063
|
-
import { and as
|
|
23121
|
+
import { and as and22, desc as desc7, eq as eq47, isNull as isNull3 } from "drizzle-orm";
|
|
23064
23122
|
async function recallHandover(orm, origin, id) {
|
|
23065
23123
|
const [row] = await orm.select().from(handovers).where(
|
|
23066
|
-
|
|
23067
|
-
|
|
23124
|
+
and22(
|
|
23125
|
+
eq47(handovers.origin, origin),
|
|
23068
23126
|
isNull3(handovers.recalledAt),
|
|
23069
|
-
...id === void 0 ? [] : [
|
|
23127
|
+
...id === void 0 ? [] : [eq47(handovers.id, id)]
|
|
23070
23128
|
)
|
|
23071
23129
|
).orderBy(desc7(handovers.createdAt), desc7(handovers.id)).limit(1);
|
|
23072
23130
|
if (!row) return void 0;
|
|
23073
|
-
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));
|
|
23074
23132
|
return row.content;
|
|
23075
23133
|
}
|
|
23076
23134
|
|
|
@@ -36569,10 +36627,10 @@ function applyReviewPause(session, activity2) {
|
|
|
36569
36627
|
}
|
|
36570
36628
|
|
|
36571
36629
|
// src/shared/db/getPhaseActiveMs.ts
|
|
36572
|
-
import { and as
|
|
36630
|
+
import { and as and23, eq as eq48 } from "drizzle-orm";
|
|
36573
36631
|
async function getPhaseActiveMs(db, itemId2, phaseIdx) {
|
|
36574
36632
|
const [row] = await db.select({ activeMs: phaseUsage.activeMs }).from(phaseUsage).where(
|
|
36575
|
-
|
|
36633
|
+
and23(eq48(phaseUsage.itemId, itemId2), eq48(phaseUsage.phaseIdx, phaseIdx))
|
|
36576
36634
|
);
|
|
36577
36635
|
return row?.activeMs ?? 0;
|
|
36578
36636
|
}
|
|
@@ -37398,17 +37456,17 @@ async function recordPhaseTranscriptUsage(db, itemId2, phaseIdx, responses) {
|
|
|
37398
37456
|
}
|
|
37399
37457
|
|
|
37400
37458
|
// src/shared/db/recordWindowTokens.ts
|
|
37401
|
-
import { and as
|
|
37459
|
+
import { and as and24, eq as eq49, sql as sql28 } from "drizzle-orm";
|
|
37402
37460
|
async function recordWindowTokens(db, window, resetsAt, tokensUp, tokensDown) {
|
|
37403
37461
|
if (tokensUp <= 0 && tokensDown <= 0) return;
|
|
37404
37462
|
await db.update(usagePeaks).set({
|
|
37405
37463
|
tokensUp: sql28`${usagePeaks.tokensUp} + ${tokensUp}`,
|
|
37406
37464
|
tokensDown: sql28`${usagePeaks.tokensDown} + ${tokensDown}`
|
|
37407
37465
|
}).where(
|
|
37408
|
-
|
|
37409
|
-
|
|
37410
|
-
|
|
37411
|
-
|
|
37466
|
+
and24(
|
|
37467
|
+
eq49(usagePeaks.window, window),
|
|
37468
|
+
eq49(usagePeaks.resetsAt, resetsAt),
|
|
37469
|
+
eq49(usagePeaks.segment, 0)
|
|
37412
37470
|
)
|
|
37413
37471
|
);
|
|
37414
37472
|
}
|