@staff0rd/assist 0.317.0 → 0.317.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +232 -144
- 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.317.
|
|
9
|
+
version: "0.317.1",
|
|
10
10
|
type: "module",
|
|
11
11
|
main: "dist/index.js",
|
|
12
12
|
bin: {
|
|
@@ -1132,8 +1132,8 @@ var options = [
|
|
|
1132
1132
|
];
|
|
1133
1133
|
|
|
1134
1134
|
// src/commands/verify/init/getAvailableOptions/index.ts
|
|
1135
|
-
function resolveDescription(
|
|
1136
|
-
return typeof
|
|
1135
|
+
function resolveDescription(desc6, setup2) {
|
|
1136
|
+
return typeof desc6 === "function" ? desc6(setup2) : desc6;
|
|
1137
1137
|
}
|
|
1138
1138
|
function toVerifyOption(def, setup2) {
|
|
1139
1139
|
return {
|
|
@@ -2975,6 +2975,107 @@ async function seedNewsFeeds(db) {
|
|
|
2975
2975
|
}
|
|
2976
2976
|
}
|
|
2977
2977
|
|
|
2978
|
+
// src/shared/db/cleanupFalseResetSegments.ts
|
|
2979
|
+
import { and as and2, eq as eq2 } from "drizzle-orm";
|
|
2980
|
+
|
|
2981
|
+
// src/shared/db/recordWindowPeak.ts
|
|
2982
|
+
import { and, eq, gt, sql } from "drizzle-orm";
|
|
2983
|
+
var RESET_DROP_THRESHOLD = 1;
|
|
2984
|
+
var at = ({ window, resetsAt }, segment) => segment === void 0 ? and(eq(usagePeaks.window, window), eq(usagePeaks.resetsAt, resetsAt)) : and(
|
|
2985
|
+
eq(usagePeaks.window, window),
|
|
2986
|
+
eq(usagePeaks.resetsAt, resetsAt),
|
|
2987
|
+
eq(usagePeaks.segment, segment)
|
|
2988
|
+
);
|
|
2989
|
+
var lock = ({ tx, window, resetsAt }) => tx.execute(
|
|
2990
|
+
sql`SELECT pg_advisory_xact_lock(hashtextextended(${`${window}:${resetsAt}`}, 0))`
|
|
2991
|
+
);
|
|
2992
|
+
var load = (c) => c.tx.select().from(usagePeaks).where(at(c)).orderBy(usagePeaks.segment);
|
|
2993
|
+
var insertSegment = (c, segment, usedPercentage) => c.tx.insert(usagePeaks).values({
|
|
2994
|
+
window: c.window,
|
|
2995
|
+
resetsAt: c.resetsAt,
|
|
2996
|
+
segment,
|
|
2997
|
+
usedPercentage
|
|
2998
|
+
});
|
|
2999
|
+
async function collapseToReached(c, reached, usedPercentage) {
|
|
3000
|
+
await c.tx.delete(usagePeaks).where(and(at(c), gt(usagePeaks.segment, reached.segment)));
|
|
3001
|
+
await c.tx.update(usagePeaks).set({ usedPercentage, resetDetected: false }).where(at(c, reached.segment));
|
|
3002
|
+
}
|
|
3003
|
+
async function openReset(c, active, usedPercentage) {
|
|
3004
|
+
await c.tx.update(usagePeaks).set({ resetDetected: true }).where(at(c, active.segment));
|
|
3005
|
+
await insertSegment(c, active.segment + 1, usedPercentage);
|
|
3006
|
+
}
|
|
3007
|
+
async function reconcile(c, segments, usedPercentage) {
|
|
3008
|
+
const reached = segments.find((s) => usedPercentage >= s.usedPercentage);
|
|
3009
|
+
if (reached) {
|
|
3010
|
+
await collapseToReached(c, reached, usedPercentage);
|
|
3011
|
+
return;
|
|
3012
|
+
}
|
|
3013
|
+
const active = segments[segments.length - 1];
|
|
3014
|
+
if (usedPercentage < active.usedPercentage - RESET_DROP_THRESHOLD) {
|
|
3015
|
+
await openReset(c, active, usedPercentage);
|
|
3016
|
+
}
|
|
3017
|
+
}
|
|
3018
|
+
async function recordWindowPeak(db, window, resetsAt, usedPercentage) {
|
|
3019
|
+
await db.transaction(async (tx) => {
|
|
3020
|
+
const c = { tx, window, resetsAt };
|
|
3021
|
+
await lock(c);
|
|
3022
|
+
const segments = await load(c);
|
|
3023
|
+
if (segments.length === 0) await insertSegment(c, 0, usedPercentage);
|
|
3024
|
+
else await reconcile(c, segments, usedPercentage);
|
|
3025
|
+
});
|
|
3026
|
+
}
|
|
3027
|
+
|
|
3028
|
+
// src/shared/db/cleanupFalseResetSegments.ts
|
|
3029
|
+
var MIGRATION_KEY = "usage_peaks_false_reset_cleanup";
|
|
3030
|
+
var climbsBack = (top, peak) => top !== void 0 && peak > top - RESET_DROP_THRESHOLD;
|
|
3031
|
+
function mergeDown(stack, peak) {
|
|
3032
|
+
while (climbsBack(stack.at(-1), peak))
|
|
3033
|
+
peak = Math.max(peak, stack.pop() ?? peak);
|
|
3034
|
+
return peak;
|
|
3035
|
+
}
|
|
3036
|
+
function collapseSegments(peaks) {
|
|
3037
|
+
const stack = [];
|
|
3038
|
+
for (const peak of peaks) stack.push(mergeDown(stack, peak));
|
|
3039
|
+
return stack.map((usedPercentage, i) => ({
|
|
3040
|
+
segment: i,
|
|
3041
|
+
usedPercentage,
|
|
3042
|
+
resetDetected: i < stack.length - 1
|
|
3043
|
+
}));
|
|
3044
|
+
}
|
|
3045
|
+
var sig = (s) => `${s.segment}:${s.usedPercentage}:${s.resetDetected}`;
|
|
3046
|
+
var isUnchanged = (rows, collapsed) => rows.length === collapsed.length && rows.every((r, i) => sig(r) === sig(collapsed[i]));
|
|
3047
|
+
var groupByCycle = (rows) => rows.reduce((cycles, r) => {
|
|
3048
|
+
const key = `${r.window} ${r.resetsAt}`;
|
|
3049
|
+
return cycles.set(key, [...cycles.get(key) ?? [], r]);
|
|
3050
|
+
}, /* @__PURE__ */ new Map());
|
|
3051
|
+
var earliest = (rows) => rows.reduce((a, r) => r.createdAt < a ? r.createdAt : a, rows[0].createdAt);
|
|
3052
|
+
async function overwrite(tx, { window, resetsAt }, createdAt, collapsed) {
|
|
3053
|
+
await tx.delete(usagePeaks).where(
|
|
3054
|
+
and2(eq2(usagePeaks.window, window), eq2(usagePeaks.resetsAt, resetsAt))
|
|
3055
|
+
);
|
|
3056
|
+
await tx.insert(usagePeaks).values(collapsed.map((c) => ({ window, resetsAt, createdAt, ...c })));
|
|
3057
|
+
}
|
|
3058
|
+
async function rewriteCycle(tx, rows) {
|
|
3059
|
+
const collapsed = collapseSegments(rows.map((r) => r.usedPercentage));
|
|
3060
|
+
if (isUnchanged(rows, collapsed)) return;
|
|
3061
|
+
await overwrite(tx, rows[0], earliest(rows), collapsed);
|
|
3062
|
+
}
|
|
3063
|
+
var loadAll = (tx) => tx.select().from(usagePeaks).orderBy(usagePeaks.window, usagePeaks.resetsAt, usagePeaks.segment);
|
|
3064
|
+
var markRun = (tx) => tx.insert(metadata).values({ key: MIGRATION_KEY, value: "done" }).onConflictDoNothing();
|
|
3065
|
+
async function alreadyRun(tx) {
|
|
3066
|
+
const done2 = await tx.select().from(metadata).where(eq2(metadata.key, MIGRATION_KEY));
|
|
3067
|
+
return done2.length > 0;
|
|
3068
|
+
}
|
|
3069
|
+
async function cleanupFalseResetSegments(db) {
|
|
3070
|
+
await db.transaction(async (tx) => {
|
|
3071
|
+
if (await alreadyRun(tx)) return;
|
|
3072
|
+
for (const rows of groupByCycle(await loadAll(tx)).values()) {
|
|
3073
|
+
await rewriteCycle(tx, rows);
|
|
3074
|
+
}
|
|
3075
|
+
await markRun(tx);
|
|
3076
|
+
});
|
|
3077
|
+
}
|
|
3078
|
+
|
|
2978
3079
|
// src/shared/db/Db.ts
|
|
2979
3080
|
import {
|
|
2980
3081
|
drizzle as drizzleNodePg
|
|
@@ -3126,6 +3227,39 @@ function getDatabaseUrl() {
|
|
|
3126
3227
|
}
|
|
3127
3228
|
return url;
|
|
3128
3229
|
}
|
|
3230
|
+
async function runUsagePeakCleanup(orm) {
|
|
3231
|
+
try {
|
|
3232
|
+
await cleanupFalseResetSegments(orm);
|
|
3233
|
+
} catch (error) {
|
|
3234
|
+
console.error(
|
|
3235
|
+
`${(/* @__PURE__ */ new Date()).toISOString()} usage-peaks cleanup failed: ${String(error)}`
|
|
3236
|
+
);
|
|
3237
|
+
}
|
|
3238
|
+
}
|
|
3239
|
+
function logPoolError(error) {
|
|
3240
|
+
console.error(
|
|
3241
|
+
`${(/* @__PURE__ */ new Date()).toISOString()} backlog pool error: ${error.message}`
|
|
3242
|
+
);
|
|
3243
|
+
}
|
|
3244
|
+
function createPool() {
|
|
3245
|
+
const pool = new Pool({
|
|
3246
|
+
connectionString: getDatabaseUrl(),
|
|
3247
|
+
max: 10,
|
|
3248
|
+
// why: retire idle clients before managed Postgres (Supabase/Neon) drops them server-side, so we never check out a dead socket and stall on a timeout.
|
|
3249
|
+
idleTimeoutMillis: 3e4,
|
|
3250
|
+
// why: bound the wait for a free client so a degraded pool fails fast (500 + log line) rather than hanging for seconds.
|
|
3251
|
+
connectionTimeoutMillis: 1e4
|
|
3252
|
+
});
|
|
3253
|
+
pool.on("error", logPoolError);
|
|
3254
|
+
return pool;
|
|
3255
|
+
}
|
|
3256
|
+
async function initSchema(pool) {
|
|
3257
|
+
await ensureSchema((sql6) => pool.query(sql6));
|
|
3258
|
+
const orm = makeOrmFromPool(pool);
|
|
3259
|
+
await seedNewsFeeds(orm);
|
|
3260
|
+
await runUsagePeakCleanup(orm);
|
|
3261
|
+
return orm;
|
|
3262
|
+
}
|
|
3129
3263
|
var _connecting;
|
|
3130
3264
|
var _pool;
|
|
3131
3265
|
var _orm;
|
|
@@ -3133,23 +3267,8 @@ function getDb() {
|
|
|
3133
3267
|
if (_orm) return Promise.resolve(_orm);
|
|
3134
3268
|
if (_connecting) return _connecting;
|
|
3135
3269
|
_connecting = (async () => {
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
max: 10,
|
|
3139
|
-
// why: retire idle clients before managed Postgres (Supabase/Neon) drops them server-side, so we never check out a dead socket and stall on a timeout.
|
|
3140
|
-
idleTimeoutMillis: 3e4,
|
|
3141
|
-
// why: bound the wait for a free client so a degraded pool fails fast (500 + log line) rather than hanging for seconds.
|
|
3142
|
-
connectionTimeoutMillis: 1e4
|
|
3143
|
-
});
|
|
3144
|
-
pool.on("error", (err) => {
|
|
3145
|
-
console.error(
|
|
3146
|
-
`${(/* @__PURE__ */ new Date()).toISOString()} backlog pool error: ${err.message}`
|
|
3147
|
-
);
|
|
3148
|
-
});
|
|
3149
|
-
_pool = pool;
|
|
3150
|
-
await ensureSchema((sql6) => pool.query(sql6));
|
|
3151
|
-
_orm = makeOrmFromPool(pool);
|
|
3152
|
-
await seedNewsFeeds(_orm);
|
|
3270
|
+
_pool = createPool();
|
|
3271
|
+
_orm = await initSchema(_pool);
|
|
3153
3272
|
return _orm;
|
|
3154
3273
|
})();
|
|
3155
3274
|
return _connecting;
|
|
@@ -3603,9 +3722,9 @@ function isLockedByOther(itemId) {
|
|
|
3603
3722
|
const lockPath = getLockPath(itemId);
|
|
3604
3723
|
if (!existsSync15(lockPath)) return false;
|
|
3605
3724
|
try {
|
|
3606
|
-
const
|
|
3607
|
-
if (
|
|
3608
|
-
return isProcessAlive(
|
|
3725
|
+
const lock2 = JSON.parse(readFileSync11(lockPath, "utf8"));
|
|
3726
|
+
if (lock2.pid === process.pid) return false;
|
|
3727
|
+
return isProcessAlive(lock2.pid);
|
|
3609
3728
|
} catch {
|
|
3610
3729
|
return false;
|
|
3611
3730
|
}
|
|
@@ -3935,7 +4054,7 @@ async function importItemsRemapped(orm, items2, origin) {
|
|
|
3935
4054
|
}
|
|
3936
4055
|
|
|
3937
4056
|
// src/commands/backlog/loadAllItems.ts
|
|
3938
|
-
import { asc as asc3, eq } from "drizzle-orm";
|
|
4057
|
+
import { asc as asc3, eq as eq3 } from "drizzle-orm";
|
|
3939
4058
|
|
|
3940
4059
|
// src/commands/backlog/loadRelations.ts
|
|
3941
4060
|
import { asc as asc2, inArray } from "drizzle-orm";
|
|
@@ -4045,7 +4164,7 @@ function rowToItem(row, rel) {
|
|
|
4045
4164
|
|
|
4046
4165
|
// src/commands/backlog/loadAllItems.ts
|
|
4047
4166
|
async function loadAllItems(orm, origin) {
|
|
4048
|
-
const rows = await orm.select().from(items).where(origin === void 0 ? void 0 :
|
|
4167
|
+
const rows = await orm.select().from(items).where(origin === void 0 ? void 0 : eq3(items.origin, origin)).orderBy(asc3(items.id));
|
|
4049
4168
|
if (rows.length === 0) return [];
|
|
4050
4169
|
const rel = await loadRelations(
|
|
4051
4170
|
orm,
|
|
@@ -4156,9 +4275,9 @@ async function ensureMigrated(orm, dir, origin) {
|
|
|
4156
4275
|
}
|
|
4157
4276
|
|
|
4158
4277
|
// src/commands/backlog/deleteItem.ts
|
|
4159
|
-
import { eq as
|
|
4278
|
+
import { eq as eq4 } from "drizzle-orm";
|
|
4160
4279
|
async function deleteItem(orm, id2) {
|
|
4161
|
-
const [row] = await orm.delete(items).where(
|
|
4280
|
+
const [row] = await orm.delete(items).where(eq4(items.id, id2)).returning({ name: items.name });
|
|
4162
4281
|
return row?.name;
|
|
4163
4282
|
}
|
|
4164
4283
|
|
|
@@ -4234,27 +4353,27 @@ function getCurrentOrigin(cwd) {
|
|
|
4234
4353
|
}
|
|
4235
4354
|
|
|
4236
4355
|
// src/commands/backlog/loadItem.ts
|
|
4237
|
-
import { eq as
|
|
4356
|
+
import { eq as eq5 } from "drizzle-orm";
|
|
4238
4357
|
async function loadItem(orm, id2) {
|
|
4239
|
-
const [row] = await orm.select().from(items).where(
|
|
4358
|
+
const [row] = await orm.select().from(items).where(eq5(items.id, id2));
|
|
4240
4359
|
if (!row) return void 0;
|
|
4241
4360
|
const rel = await loadRelations(orm, [id2]);
|
|
4242
4361
|
return rowToItem(row, rel);
|
|
4243
4362
|
}
|
|
4244
4363
|
|
|
4245
4364
|
// src/commands/backlog/saveAllItems.ts
|
|
4246
|
-
import { eq as
|
|
4365
|
+
import { eq as eq7, sql as sql2 } from "drizzle-orm";
|
|
4247
4366
|
|
|
4248
4367
|
// src/commands/backlog/deleteItemRelations.ts
|
|
4249
|
-
import { eq as
|
|
4368
|
+
import { eq as eq6 } from "drizzle-orm";
|
|
4250
4369
|
|
|
4251
4370
|
// src/commands/backlog/searchItemIds.ts
|
|
4252
|
-
import { and, asc as asc4, eq as
|
|
4371
|
+
import { and as and3, asc as asc4, eq as eq8, ilike, or } from "drizzle-orm";
|
|
4253
4372
|
async function searchItemIds(orm, query, origin) {
|
|
4254
4373
|
const pattern2 = `%${query}%`;
|
|
4255
|
-
const rows = await orm.selectDistinct({ id: items.id }).from(items).leftJoin(comments,
|
|
4256
|
-
|
|
4257
|
-
origin ?
|
|
4374
|
+
const rows = await orm.selectDistinct({ id: items.id }).from(items).leftJoin(comments, eq8(comments.itemId, items.id)).leftJoin(planPhases, eq8(planPhases.itemId, items.id)).where(
|
|
4375
|
+
and3(
|
|
4376
|
+
origin ? eq8(items.origin, origin) : void 0,
|
|
4258
4377
|
or(
|
|
4259
4378
|
ilike(items.name, pattern2),
|
|
4260
4379
|
ilike(items.description, pattern2),
|
|
@@ -4268,15 +4387,15 @@ async function searchItemIds(orm, query, origin) {
|
|
|
4268
4387
|
}
|
|
4269
4388
|
|
|
4270
4389
|
// src/commands/backlog/updateCurrentPhase.ts
|
|
4271
|
-
import { eq as
|
|
4390
|
+
import { eq as eq9 } from "drizzle-orm";
|
|
4272
4391
|
async function updateCurrentPhase(orm, id2, phase) {
|
|
4273
|
-
await orm.update(items).set({ currentPhase: phase }).where(
|
|
4392
|
+
await orm.update(items).set({ currentPhase: phase }).where(eq9(items.id, id2));
|
|
4274
4393
|
}
|
|
4275
4394
|
|
|
4276
4395
|
// src/commands/backlog/updateStatus.ts
|
|
4277
|
-
import { eq as
|
|
4396
|
+
import { eq as eq10 } from "drizzle-orm";
|
|
4278
4397
|
async function updateStatus(orm, id2, status2) {
|
|
4279
|
-
const [row] = await orm.update(items).set({ status: status2 }).where(
|
|
4398
|
+
const [row] = await orm.update(items).set({ status: status2 }).where(eq10(items.id, id2)).returning({ name: items.name });
|
|
4280
4399
|
return row?.name;
|
|
4281
4400
|
}
|
|
4282
4401
|
|
|
@@ -4902,11 +5021,11 @@ async function next(options2, startId) {
|
|
|
4902
5021
|
import chalk43 from "chalk";
|
|
4903
5022
|
|
|
4904
5023
|
// src/commands/backlog/appendComment.ts
|
|
4905
|
-
import { sql as
|
|
5024
|
+
import { sql as sql3 } from "drizzle-orm";
|
|
4906
5025
|
async function appendComment(orm, itemId, text6, opts = {}) {
|
|
4907
5026
|
await orm.insert(comments).values({
|
|
4908
5027
|
itemId,
|
|
4909
|
-
idx:
|
|
5028
|
+
idx: sql3`(SELECT COALESCE(MAX(${comments.idx}) + 1, 0) FROM ${comments} WHERE ${comments.itemId} = ${itemId})`,
|
|
4910
5029
|
text: text6,
|
|
4911
5030
|
phase: opts.phase ?? null,
|
|
4912
5031
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -4915,9 +5034,9 @@ async function appendComment(orm, itemId, text6, opts = {}) {
|
|
|
4915
5034
|
}
|
|
4916
5035
|
|
|
4917
5036
|
// src/commands/backlog/getItemStatus.ts
|
|
4918
|
-
import { eq as
|
|
5037
|
+
import { eq as eq11 } from "drizzle-orm";
|
|
4919
5038
|
async function getItemStatus(orm, id2) {
|
|
4920
|
-
const [row] = await orm.select({ status: items.status }).from(items).where(
|
|
5039
|
+
const [row] = await orm.select({ status: items.status }).from(items).where(eq11(items.id, id2));
|
|
4921
5040
|
return row?.status;
|
|
4922
5041
|
}
|
|
4923
5042
|
|
|
@@ -5401,10 +5520,10 @@ function createFallbackHandler(routes3, htmlHandler2, extra) {
|
|
|
5401
5520
|
}
|
|
5402
5521
|
|
|
5403
5522
|
// src/commands/backlog/loadBacklogSummaries.ts
|
|
5404
|
-
import { eq as
|
|
5523
|
+
import { eq as eq13 } from "drizzle-orm";
|
|
5405
5524
|
|
|
5406
5525
|
// src/commands/backlog/loadItemSummaries.ts
|
|
5407
|
-
import { asc as asc5, eq as
|
|
5526
|
+
import { asc as asc5, eq as eq12 } from "drizzle-orm";
|
|
5408
5527
|
async function loadItemSummaries(orm, origin) {
|
|
5409
5528
|
const rows = await orm.select({
|
|
5410
5529
|
id: items.id,
|
|
@@ -5413,7 +5532,7 @@ async function loadItemSummaries(orm, origin) {
|
|
|
5413
5532
|
name: items.name,
|
|
5414
5533
|
status: items.status,
|
|
5415
5534
|
starred: items.starred
|
|
5416
|
-
}).from(items).where(origin === void 0 ? void 0 :
|
|
5535
|
+
}).from(items).where(origin === void 0 ? void 0 : eq12(items.origin, origin)).orderBy(asc5(items.id));
|
|
5417
5536
|
return rows.map((row) => ({
|
|
5418
5537
|
id: row.id,
|
|
5419
5538
|
origin: row.origin,
|
|
@@ -5438,7 +5557,7 @@ async function searchBacklogSummaries(query) {
|
|
|
5438
5557
|
}
|
|
5439
5558
|
async function backlogHasItems() {
|
|
5440
5559
|
const { orm } = await getReady();
|
|
5441
|
-
const [row] = await orm.select({ id: items.id }).from(items).where(
|
|
5560
|
+
const [row] = await orm.select({ id: items.id }).from(items).where(eq13(items.origin, getOrigin())).limit(1);
|
|
5442
5561
|
return row !== void 0;
|
|
5443
5562
|
}
|
|
5444
5563
|
|
|
@@ -5455,19 +5574,19 @@ async function getBacklogExists(req, res) {
|
|
|
5455
5574
|
}
|
|
5456
5575
|
|
|
5457
5576
|
// src/commands/backlog/deleteComment.ts
|
|
5458
|
-
import { and as
|
|
5577
|
+
import { and as and4, eq as eq14 } from "drizzle-orm";
|
|
5459
5578
|
async function deleteComment(orm, itemId, commentId) {
|
|
5460
|
-
const [row] = await orm.select({ type: comments.type }).from(comments).where(
|
|
5579
|
+
const [row] = await orm.select({ type: comments.type }).from(comments).where(and4(eq14(comments.id, commentId), eq14(comments.itemId, itemId)));
|
|
5461
5580
|
if (!row) return "not-found";
|
|
5462
5581
|
if (row.type === "summary") return "is-summary";
|
|
5463
|
-
await orm.delete(comments).where(
|
|
5582
|
+
await orm.delete(comments).where(and4(eq14(comments.id, commentId), eq14(comments.itemId, itemId)));
|
|
5464
5583
|
return "deleted";
|
|
5465
5584
|
}
|
|
5466
5585
|
|
|
5467
5586
|
// src/commands/backlog/updateStarred.ts
|
|
5468
|
-
import { eq as
|
|
5587
|
+
import { eq as eq15 } from "drizzle-orm";
|
|
5469
5588
|
async function updateStarred(orm, id2, starred) {
|
|
5470
|
-
const [row] = await orm.update(items).set({ starred }).where(
|
|
5589
|
+
const [row] = await orm.update(items).set({ starred }).where(eq15(items.id, id2)).returning({ name: items.name });
|
|
5471
5590
|
return row?.name;
|
|
5472
5591
|
}
|
|
5473
5592
|
|
|
@@ -5565,7 +5684,7 @@ async function deleteItemComment(res, itemId, commentId) {
|
|
|
5565
5684
|
}
|
|
5566
5685
|
|
|
5567
5686
|
// src/commands/backlog/web/rewindItemPhase.ts
|
|
5568
|
-
import { eq as
|
|
5687
|
+
import { eq as eq16 } from "drizzle-orm";
|
|
5569
5688
|
|
|
5570
5689
|
// src/commands/backlog/resolveRewindPlan.ts
|
|
5571
5690
|
function resolveRewindPlan(item) {
|
|
@@ -5591,7 +5710,7 @@ async function rewindItemPhase(req, res, id2) {
|
|
|
5591
5710
|
`Rewound to phase ${phase} (${phaseName}): ${reason}`,
|
|
5592
5711
|
{ phase }
|
|
5593
5712
|
);
|
|
5594
|
-
await orm.update(items).set({ currentPhase: phase, status: "in-progress" }).where(
|
|
5713
|
+
await orm.update(items).set({ currentPhase: phase, status: "in-progress" }).where(eq16(items.id, id2));
|
|
5595
5714
|
respondJson(res, 200, await loadItem(orm, id2));
|
|
5596
5715
|
}
|
|
5597
5716
|
function validateRewind(item, plan2, phase) {
|
|
@@ -6933,22 +7052,22 @@ async function add(options2) {
|
|
|
6933
7052
|
import chalk61 from "chalk";
|
|
6934
7053
|
|
|
6935
7054
|
// src/commands/backlog/insertPhaseAt.ts
|
|
6936
|
-
import { count, eq as
|
|
7055
|
+
import { count, eq as eq18 } from "drizzle-orm";
|
|
6937
7056
|
|
|
6938
7057
|
// src/commands/backlog/shiftPhasesUp.ts
|
|
6939
|
-
import { and as
|
|
7058
|
+
import { and as and5, desc as desc3, eq as eq17, gte } from "drizzle-orm";
|
|
6940
7059
|
async function shiftPhasesUp(db, itemId, fromIdx) {
|
|
6941
|
-
const toShift = await db.select({ idx: planPhases.idx }).from(planPhases).where(
|
|
7060
|
+
const toShift = await db.select({ idx: planPhases.idx }).from(planPhases).where(and5(eq17(planPhases.itemId, itemId), gte(planPhases.idx, fromIdx))).orderBy(desc3(planPhases.idx));
|
|
6942
7061
|
for (const p of toShift) {
|
|
6943
|
-
await db.update(planTasks).set({ phaseIdx: p.idx + 1 }).where(
|
|
6944
|
-
await db.update(planPhases).set({ idx: p.idx + 1 }).where(
|
|
7062
|
+
await db.update(planTasks).set({ phaseIdx: p.idx + 1 }).where(and5(eq17(planTasks.itemId, itemId), eq17(planTasks.phaseIdx, p.idx)));
|
|
7063
|
+
await db.update(planPhases).set({ idx: p.idx + 1 }).where(and5(eq17(planPhases.itemId, itemId), eq17(planPhases.idx, p.idx)));
|
|
6945
7064
|
}
|
|
6946
7065
|
}
|
|
6947
7066
|
|
|
6948
7067
|
// src/commands/backlog/insertPhaseAt.ts
|
|
6949
7068
|
async function insertPhaseAt(orm, itemId, phaseIdx, name, tasks, manualChecks, currentPhase) {
|
|
6950
7069
|
await orm.transaction(async (tx) => {
|
|
6951
|
-
const [row] = await tx.select({ cnt: count() }).from(planPhases).where(
|
|
7070
|
+
const [row] = await tx.select({ cnt: count() }).from(planPhases).where(eq18(planPhases.itemId, itemId));
|
|
6952
7071
|
const phaseCount = row?.cnt ?? 0;
|
|
6953
7072
|
await shiftPhasesUp(tx, itemId, phaseIdx);
|
|
6954
7073
|
await tx.insert(planPhases).values({ itemId, idx: phaseIdx, name, manualChecks });
|
|
@@ -6957,16 +7076,16 @@ async function insertPhaseAt(orm, itemId, phaseIdx, name, tasks, manualChecks, c
|
|
|
6957
7076
|
}
|
|
6958
7077
|
if (currentPhase !== void 0 && currentPhase - 1 >= phaseIdx) {
|
|
6959
7078
|
const atReviewSlot = currentPhase - 1 >= phaseCount;
|
|
6960
|
-
await tx.update(items).set({ currentPhase: atReviewSlot ? phaseIdx + 1 : currentPhase + 1 }).where(
|
|
7079
|
+
await tx.update(items).set({ currentPhase: atReviewSlot ? phaseIdx + 1 : currentPhase + 1 }).where(eq18(items.id, itemId));
|
|
6961
7080
|
}
|
|
6962
7081
|
});
|
|
6963
7082
|
}
|
|
6964
7083
|
|
|
6965
7084
|
// src/commands/backlog/resolveInsertPosition.ts
|
|
6966
7085
|
import chalk60 from "chalk";
|
|
6967
|
-
import { count as count2, eq as
|
|
7086
|
+
import { count as count2, eq as eq19 } from "drizzle-orm";
|
|
6968
7087
|
async function resolveInsertPosition(orm, itemId, position) {
|
|
6969
|
-
const [row] = await orm.select({ cnt: count2() }).from(planPhases).where(
|
|
7088
|
+
const [row] = await orm.select({ cnt: count2() }).from(planPhases).where(eq19(planPhases.itemId, itemId));
|
|
6970
7089
|
const phaseCount = row?.cnt ?? 0;
|
|
6971
7090
|
if (position === void 0) return phaseCount;
|
|
6972
7091
|
const pos = Number.parseInt(position, 10);
|
|
@@ -7127,9 +7246,9 @@ function hasCycle(adjacency, fromId, toId) {
|
|
|
7127
7246
|
}
|
|
7128
7247
|
|
|
7129
7248
|
// src/commands/backlog/loadDependencyGraph.ts
|
|
7130
|
-
import { eq as
|
|
7249
|
+
import { eq as eq20 } from "drizzle-orm";
|
|
7131
7250
|
async function loadDependencyGraph(orm) {
|
|
7132
|
-
const rows = await orm.select({ itemId: links.itemId, targetId: links.targetId }).from(links).where(
|
|
7251
|
+
const rows = await orm.select({ itemId: links.itemId, targetId: links.targetId }).from(links).where(eq20(links.type, "depends-on"));
|
|
7133
7252
|
const graph = /* @__PURE__ */ new Map();
|
|
7134
7253
|
for (const { itemId, targetId } of rows) {
|
|
7135
7254
|
const bucket = graph.get(itemId);
|
|
@@ -7192,7 +7311,7 @@ async function link(fromId, toId, opts) {
|
|
|
7192
7311
|
|
|
7193
7312
|
// src/commands/backlog/unlink.ts
|
|
7194
7313
|
import chalk65 from "chalk";
|
|
7195
|
-
import { and as
|
|
7314
|
+
import { and as and6, eq as eq21 } from "drizzle-orm";
|
|
7196
7315
|
async function unlink(fromId, toId) {
|
|
7197
7316
|
const fromNum = Number.parseInt(fromId, 10);
|
|
7198
7317
|
const toNum = Number.parseInt(toId, 10);
|
|
@@ -7210,7 +7329,7 @@ async function unlink(fromId, toId) {
|
|
|
7210
7329
|
console.log(chalk65.yellow(`No link from #${fromId} to #${toId} found.`));
|
|
7211
7330
|
return;
|
|
7212
7331
|
}
|
|
7213
|
-
await orm.delete(links).where(
|
|
7332
|
+
await orm.delete(links).where(and6(eq21(links.itemId, fromNum), eq21(links.targetId, toNum)));
|
|
7214
7333
|
console.log(chalk65.green(`Removed link from #${fromId} to #${toId}.`));
|
|
7215
7334
|
}
|
|
7216
7335
|
|
|
@@ -7226,7 +7345,7 @@ function registerLinkCommands(cmd) {
|
|
|
7226
7345
|
|
|
7227
7346
|
// src/commands/backlog/move-repo/index.ts
|
|
7228
7347
|
import chalk67 from "chalk";
|
|
7229
|
-
import { eq as
|
|
7348
|
+
import { eq as eq23 } from "drizzle-orm";
|
|
7230
7349
|
|
|
7231
7350
|
// src/commands/backlog/move-repo/confirmMove.ts
|
|
7232
7351
|
import chalk66 from "chalk";
|
|
@@ -7241,9 +7360,9 @@ async function confirmMove(cnt, oldOrigin, newOrigin) {
|
|
|
7241
7360
|
}
|
|
7242
7361
|
|
|
7243
7362
|
// src/commands/backlog/move-repo/countByOrigin.ts
|
|
7244
|
-
import { count as count3, eq as
|
|
7363
|
+
import { count as count3, eq as eq22 } from "drizzle-orm";
|
|
7245
7364
|
async function countByOrigin(orm, origin) {
|
|
7246
|
-
const [{ cnt }] = await orm.select({ cnt: count3() }).from(items).where(
|
|
7365
|
+
const [{ cnt }] = await orm.select({ cnt: count3() }).from(items).where(eq22(items.origin, origin));
|
|
7247
7366
|
return cnt;
|
|
7248
7367
|
}
|
|
7249
7368
|
|
|
@@ -7286,7 +7405,7 @@ async function moveRepo(oldOriginRaw, newOriginRaw, options2 = {}) {
|
|
|
7286
7405
|
console.log(chalk67.yellow("Move cancelled; no changes made."));
|
|
7287
7406
|
return;
|
|
7288
7407
|
}
|
|
7289
|
-
await orm.update(items).set({ origin: newOrigin }).where(
|
|
7408
|
+
await orm.update(items).set({ origin: newOrigin }).where(eq23(items.origin, oldOrigin));
|
|
7290
7409
|
console.log(
|
|
7291
7410
|
chalk67.green(
|
|
7292
7411
|
`Moved ${pluralItems(cnt)} from "${oldOrigin}" to "${newOrigin}".`
|
|
@@ -7625,10 +7744,10 @@ async function start(id2) {
|
|
|
7625
7744
|
|
|
7626
7745
|
// src/commands/backlog/stop/index.ts
|
|
7627
7746
|
import chalk78 from "chalk";
|
|
7628
|
-
import { and as
|
|
7747
|
+
import { and as and7, eq as eq24 } from "drizzle-orm";
|
|
7629
7748
|
async function stop() {
|
|
7630
7749
|
const { orm } = await getReady();
|
|
7631
|
-
const stopped = await orm.update(items).set({ status: "todo", currentPhase: 1 }).where(
|
|
7750
|
+
const stopped = await orm.update(items).set({ status: "todo", currentPhase: 1 }).where(and7(eq24(items.status, "in-progress"), eq24(items.origin, getOrigin()))).returning({ id: items.id, name: items.name });
|
|
7632
7751
|
if (stopped.length === 0) {
|
|
7633
7752
|
console.log(chalk78.yellow("No in-progress items to stop."));
|
|
7634
7753
|
return;
|
|
@@ -7674,18 +7793,18 @@ function registerStatusCommands(cmd) {
|
|
|
7674
7793
|
|
|
7675
7794
|
// src/commands/backlog/removePhase.ts
|
|
7676
7795
|
import chalk82 from "chalk";
|
|
7677
|
-
import { and as
|
|
7796
|
+
import { and as and10, eq as eq27 } from "drizzle-orm";
|
|
7678
7797
|
|
|
7679
7798
|
// src/commands/backlog/findPhase.ts
|
|
7680
7799
|
import chalk81 from "chalk";
|
|
7681
|
-
import { and as
|
|
7800
|
+
import { and as and8, count as count4, eq as eq25 } from "drizzle-orm";
|
|
7682
7801
|
async function findPhase(id2, phase) {
|
|
7683
7802
|
const found = await findOneItem(id2);
|
|
7684
7803
|
if (!found) return void 0;
|
|
7685
7804
|
const { orm, item } = found;
|
|
7686
7805
|
const itemId = item.id;
|
|
7687
7806
|
const phaseIdx = Number.parseInt(phase, 10) - 1;
|
|
7688
|
-
const [row] = await orm.select({ cnt: count4() }).from(planPhases).where(
|
|
7807
|
+
const [row] = await orm.select({ cnt: count4() }).from(planPhases).where(and8(eq25(planPhases.itemId, itemId), eq25(planPhases.idx, phaseIdx)));
|
|
7689
7808
|
if (!row || row.cnt === 0) {
|
|
7690
7809
|
console.log(
|
|
7691
7810
|
chalk81.red(`Phase ${phaseIdx + 1} not found on item #${itemId}.`)
|
|
@@ -7697,14 +7816,14 @@ async function findPhase(id2, phase) {
|
|
|
7697
7816
|
}
|
|
7698
7817
|
|
|
7699
7818
|
// src/commands/backlog/reindexPhases.ts
|
|
7700
|
-
import { and as
|
|
7819
|
+
import { and as and9, asc as asc6, count as count5, eq as eq26 } from "drizzle-orm";
|
|
7701
7820
|
async function reindexPhases(db, itemId) {
|
|
7702
|
-
const remaining = await db.select({ idx: planPhases.idx }).from(planPhases).where(
|
|
7821
|
+
const remaining = await db.select({ idx: planPhases.idx }).from(planPhases).where(eq26(planPhases.itemId, itemId)).orderBy(asc6(planPhases.idx));
|
|
7703
7822
|
for (let i = 0; i < remaining.length; i++) {
|
|
7704
7823
|
const oldIdx = remaining[i].idx;
|
|
7705
7824
|
if (oldIdx === i) continue;
|
|
7706
|
-
await db.update(planTasks).set({ phaseIdx: i }).where(
|
|
7707
|
-
await db.update(planPhases).set({ idx: i }).where(
|
|
7825
|
+
await db.update(planTasks).set({ phaseIdx: i }).where(and9(eq26(planTasks.itemId, itemId), eq26(planTasks.phaseIdx, oldIdx)));
|
|
7826
|
+
await db.update(planPhases).set({ idx: i }).where(and9(eq26(planPhases.itemId, itemId), eq26(planPhases.idx, oldIdx)));
|
|
7708
7827
|
}
|
|
7709
7828
|
}
|
|
7710
7829
|
async function adjustCurrentPhase(db, item, removedIdx) {
|
|
@@ -7712,13 +7831,13 @@ async function adjustCurrentPhase(db, item, removedIdx) {
|
|
|
7712
7831
|
if (currentPhase === void 0) return;
|
|
7713
7832
|
const currentIdx = currentPhase - 1;
|
|
7714
7833
|
if (removedIdx < currentIdx) {
|
|
7715
|
-
await db.update(items).set({ currentPhase: currentPhase - 1 }).where(
|
|
7834
|
+
await db.update(items).set({ currentPhase: currentPhase - 1 }).where(eq26(items.id, item.id));
|
|
7716
7835
|
return;
|
|
7717
7836
|
}
|
|
7718
7837
|
if (removedIdx !== currentIdx) return;
|
|
7719
|
-
const [row] = await db.select({ cnt: count5() }).from(planPhases).where(
|
|
7838
|
+
const [row] = await db.select({ cnt: count5() }).from(planPhases).where(eq26(planPhases.itemId, item.id));
|
|
7720
7839
|
const cnt = row?.cnt ?? 0;
|
|
7721
|
-
await db.update(items).set({ currentPhase: cnt === 0 ? null : Math.min(currentPhase, cnt) }).where(
|
|
7840
|
+
await db.update(items).set({ currentPhase: cnt === 0 ? null : Math.min(currentPhase, cnt) }).where(eq26(items.id, item.id));
|
|
7722
7841
|
}
|
|
7723
7842
|
|
|
7724
7843
|
// src/commands/backlog/removePhase.ts
|
|
@@ -7728,9 +7847,9 @@ async function removePhase(id2, phase) {
|
|
|
7728
7847
|
const { item, orm, itemId, phaseIdx } = found;
|
|
7729
7848
|
await orm.transaction(async (tx) => {
|
|
7730
7849
|
await tx.delete(planTasks).where(
|
|
7731
|
-
|
|
7850
|
+
and10(eq27(planTasks.itemId, itemId), eq27(planTasks.phaseIdx, phaseIdx))
|
|
7732
7851
|
);
|
|
7733
|
-
await tx.delete(planPhases).where(
|
|
7852
|
+
await tx.delete(planPhases).where(and10(eq27(planPhases.itemId, itemId), eq27(planPhases.idx, phaseIdx)));
|
|
7734
7853
|
await reindexPhases(tx, itemId);
|
|
7735
7854
|
await adjustCurrentPhase(tx, item, phaseIdx);
|
|
7736
7855
|
});
|
|
@@ -7741,7 +7860,7 @@ async function removePhase(id2, phase) {
|
|
|
7741
7860
|
|
|
7742
7861
|
// src/commands/backlog/update/index.ts
|
|
7743
7862
|
import chalk84 from "chalk";
|
|
7744
|
-
import { eq as
|
|
7863
|
+
import { eq as eq28 } from "drizzle-orm";
|
|
7745
7864
|
|
|
7746
7865
|
// src/commands/backlog/update/parseListIndex.ts
|
|
7747
7866
|
function parseListIndex(raw, length, label2) {
|
|
@@ -7818,8 +7937,8 @@ function applyAcMutations(current, options2) {
|
|
|
7818
7937
|
// src/commands/backlog/update/buildUpdateValues.ts
|
|
7819
7938
|
import chalk83 from "chalk";
|
|
7820
7939
|
function buildUpdateValues(options2) {
|
|
7821
|
-
const { name, desc:
|
|
7822
|
-
if (!name && !
|
|
7940
|
+
const { name, desc: desc6, type, ac } = options2;
|
|
7941
|
+
if (!name && !desc6 && !type && !ac) {
|
|
7823
7942
|
console.log(chalk83.red("Nothing to update. Provide at least one flag."));
|
|
7824
7943
|
process.exitCode = 1;
|
|
7825
7944
|
return void 0;
|
|
@@ -7835,8 +7954,8 @@ function buildUpdateValues(options2) {
|
|
|
7835
7954
|
set.name = name;
|
|
7836
7955
|
fieldNames.push("name");
|
|
7837
7956
|
}
|
|
7838
|
-
if (
|
|
7839
|
-
set.description =
|
|
7957
|
+
if (desc6) {
|
|
7958
|
+
set.description = desc6;
|
|
7840
7959
|
fieldNames.push("description");
|
|
7841
7960
|
}
|
|
7842
7961
|
if (type) {
|
|
@@ -7875,7 +7994,7 @@ async function update(id2, options2) {
|
|
|
7875
7994
|
if (!built) return;
|
|
7876
7995
|
const { orm } = found;
|
|
7877
7996
|
const itemId = found.item.id;
|
|
7878
|
-
await orm.update(items).set(built.set).where(
|
|
7997
|
+
await orm.update(items).set(built.set).where(eq28(items.id, itemId));
|
|
7879
7998
|
console.log(chalk84.green(`Updated ${built.fields} on item #${itemId}.`));
|
|
7880
7999
|
}
|
|
7881
8000
|
|
|
@@ -7883,22 +8002,22 @@ async function update(id2, options2) {
|
|
|
7883
8002
|
import chalk85 from "chalk";
|
|
7884
8003
|
|
|
7885
8004
|
// src/commands/backlog/applyPhaseUpdate.ts
|
|
7886
|
-
import { and as
|
|
8005
|
+
import { and as and11, eq as eq29 } from "drizzle-orm";
|
|
7887
8006
|
async function applyPhaseUpdate(orm, itemId, phaseIdx, fields) {
|
|
7888
8007
|
await orm.transaction(async (tx) => {
|
|
7889
8008
|
if (fields.name) {
|
|
7890
8009
|
await tx.update(planPhases).set({ name: fields.name }).where(
|
|
7891
|
-
|
|
8010
|
+
and11(eq29(planPhases.itemId, itemId), eq29(planPhases.idx, phaseIdx))
|
|
7892
8011
|
);
|
|
7893
8012
|
}
|
|
7894
8013
|
if (fields.manualCheck) {
|
|
7895
8014
|
await tx.update(planPhases).set({ manualChecks: JSON.stringify(fields.manualCheck) }).where(
|
|
7896
|
-
|
|
8015
|
+
and11(eq29(planPhases.itemId, itemId), eq29(planPhases.idx, phaseIdx))
|
|
7897
8016
|
);
|
|
7898
8017
|
}
|
|
7899
8018
|
if (fields.task) {
|
|
7900
8019
|
await tx.delete(planTasks).where(
|
|
7901
|
-
|
|
8020
|
+
and11(eq29(planTasks.itemId, itemId), eq29(planTasks.phaseIdx, phaseIdx))
|
|
7902
8021
|
);
|
|
7903
8022
|
if (fields.task.length) {
|
|
7904
8023
|
await tx.insert(planTasks).values(
|
|
@@ -8241,7 +8360,7 @@ var _db;
|
|
|
8241
8360
|
function getDbDir() {
|
|
8242
8361
|
return join22(homedir8(), ".assist");
|
|
8243
8362
|
}
|
|
8244
|
-
function
|
|
8363
|
+
function initSchema2(db) {
|
|
8245
8364
|
db.exec(`
|
|
8246
8365
|
CREATE TABLE IF NOT EXISTS denied_tool_calls (
|
|
8247
8366
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
@@ -8260,7 +8379,7 @@ function openPromptsDb(dir) {
|
|
|
8260
8379
|
mkdirSync9(dbDir, { recursive: true });
|
|
8261
8380
|
const db = new Database(join22(dbDir, "assist.db"));
|
|
8262
8381
|
db.pragma("journal_mode = WAL");
|
|
8263
|
-
|
|
8382
|
+
initSchema2(db);
|
|
8264
8383
|
_db = db;
|
|
8265
8384
|
return db;
|
|
8266
8385
|
}
|
|
@@ -11207,9 +11326,9 @@ function registerGithub(program2) {
|
|
|
11207
11326
|
}
|
|
11208
11327
|
|
|
11209
11328
|
// src/commands/handover/countPendingHandovers.ts
|
|
11210
|
-
import { and as
|
|
11329
|
+
import { and as and12, eq as eq30, isNull, sql as sql4 } from "drizzle-orm";
|
|
11211
11330
|
async function countPendingHandovers(orm, origin) {
|
|
11212
|
-
const [row] = await orm.select({ count:
|
|
11331
|
+
const [row] = await orm.select({ count: sql4`count(*)::int` }).from(handovers).where(and12(eq30(handovers.origin, origin), isNull(handovers.recalledAt)));
|
|
11213
11332
|
return row?.count ?? 0;
|
|
11214
11333
|
}
|
|
11215
11334
|
|
|
@@ -11336,7 +11455,7 @@ function emit(message) {
|
|
|
11336
11455
|
console.log(json);
|
|
11337
11456
|
return json;
|
|
11338
11457
|
}
|
|
11339
|
-
async function
|
|
11458
|
+
async function load2(options2 = {}) {
|
|
11340
11459
|
const opts = resolveLoadOptions(options2);
|
|
11341
11460
|
const input = await parseLoadInput(opts.stdin);
|
|
11342
11461
|
const cwd = input.cwd ?? opts.cwdFallback;
|
|
@@ -11349,13 +11468,13 @@ async function load(options2 = {}) {
|
|
|
11349
11468
|
}
|
|
11350
11469
|
|
|
11351
11470
|
// src/commands/handover/listPendingHandovers.ts
|
|
11352
|
-
import { and as
|
|
11471
|
+
import { and as and13, desc as desc4, eq as eq31, isNull as isNull2 } from "drizzle-orm";
|
|
11353
11472
|
async function listPendingHandovers(orm, origin) {
|
|
11354
11473
|
return orm.select({
|
|
11355
11474
|
id: handovers.id,
|
|
11356
11475
|
summary: handovers.summary,
|
|
11357
11476
|
createdAt: handovers.createdAt
|
|
11358
|
-
}).from(handovers).where(
|
|
11477
|
+
}).from(handovers).where(and13(eq31(handovers.origin, origin), isNull2(handovers.recalledAt))).orderBy(desc4(handovers.createdAt), desc4(handovers.id));
|
|
11359
11478
|
}
|
|
11360
11479
|
|
|
11361
11480
|
// src/commands/handover/printPendingHandovers.ts
|
|
@@ -11368,17 +11487,17 @@ async function printPendingHandovers() {
|
|
|
11368
11487
|
}
|
|
11369
11488
|
|
|
11370
11489
|
// src/commands/handover/recallHandover.ts
|
|
11371
|
-
import { and as
|
|
11490
|
+
import { and as and14, desc as desc5, eq as eq32, isNull as isNull3 } from "drizzle-orm";
|
|
11372
11491
|
async function recallHandover(orm, origin, id2) {
|
|
11373
11492
|
const [row] = await orm.select().from(handovers).where(
|
|
11374
|
-
|
|
11375
|
-
|
|
11493
|
+
and14(
|
|
11494
|
+
eq32(handovers.origin, origin),
|
|
11376
11495
|
isNull3(handovers.recalledAt),
|
|
11377
|
-
...id2 === void 0 ? [] : [
|
|
11496
|
+
...id2 === void 0 ? [] : [eq32(handovers.id, id2)]
|
|
11378
11497
|
)
|
|
11379
11498
|
).orderBy(desc5(handovers.createdAt), desc5(handovers.id)).limit(1);
|
|
11380
11499
|
if (!row) return void 0;
|
|
11381
|
-
await orm.update(handovers).set({ recalledAt: /* @__PURE__ */ new Date() }).where(
|
|
11500
|
+
await orm.update(handovers).set({ recalledAt: /* @__PURE__ */ new Date() }).where(eq32(handovers.id, row.id));
|
|
11382
11501
|
return row.content;
|
|
11383
11502
|
}
|
|
11384
11503
|
|
|
@@ -11423,7 +11542,7 @@ function registerHandover(program2) {
|
|
|
11423
11542
|
cmd.command("load").description(
|
|
11424
11543
|
"SessionStart hook: migrate any disk handovers, then advise how many unrecalled handovers exist for this repo"
|
|
11425
11544
|
).action(async () => {
|
|
11426
|
-
await
|
|
11545
|
+
await load2();
|
|
11427
11546
|
});
|
|
11428
11547
|
}
|
|
11429
11548
|
|
|
@@ -17750,9 +17869,9 @@ function resolveConnection3(name) {
|
|
|
17750
17869
|
}
|
|
17751
17870
|
|
|
17752
17871
|
// src/commands/sql/sqlConnect.ts
|
|
17753
|
-
import
|
|
17872
|
+
import sql5 from "mssql";
|
|
17754
17873
|
async function sqlConnect(conn) {
|
|
17755
|
-
return await
|
|
17874
|
+
return await sql5.connect({
|
|
17756
17875
|
server: conn.server,
|
|
17757
17876
|
port: conn.port,
|
|
17758
17877
|
user: conn.user,
|
|
@@ -18684,10 +18803,10 @@ function checkLockFile() {
|
|
|
18684
18803
|
const lockFile = getLockFile();
|
|
18685
18804
|
if (!existsSync45(lockFile)) return;
|
|
18686
18805
|
try {
|
|
18687
|
-
const
|
|
18688
|
-
if (
|
|
18806
|
+
const lock2 = JSON.parse(readFileSync37(lockFile, "utf8"));
|
|
18807
|
+
if (lock2.pid && isProcessAlive2(lock2.pid)) {
|
|
18689
18808
|
console.error(
|
|
18690
|
-
`Voice daemon already running (PID ${
|
|
18809
|
+
`Voice daemon already running (PID ${lock2.pid}, env: ${lock2.env}). Stop it first with: assist voice stop`
|
|
18691
18810
|
);
|
|
18692
18811
|
process.exit(1);
|
|
18693
18812
|
}
|
|
@@ -19902,37 +20021,6 @@ function broadcastSessions(sessions, clients, windowsSessions = [], active) {
|
|
|
19902
20021
|
});
|
|
19903
20022
|
}
|
|
19904
20023
|
|
|
19905
|
-
// src/shared/db/recordWindowPeak.ts
|
|
19906
|
-
import { and as and13, desc as desc6, eq as eq31, sql as sql5 } from "drizzle-orm";
|
|
19907
|
-
var RESET_DROP_THRESHOLD = 1;
|
|
19908
|
-
async function recordWindowPeak(db, window, resetsAt, usedPercentage) {
|
|
19909
|
-
const [active] = await db.select().from(usagePeaks).where(
|
|
19910
|
-
and13(eq31(usagePeaks.window, window), eq31(usagePeaks.resetsAt, resetsAt))
|
|
19911
|
-
).orderBy(desc6(usagePeaks.segment)).limit(1);
|
|
19912
|
-
if (!active) {
|
|
19913
|
-
await db.insert(usagePeaks).values({ window, resetsAt, segment: 0, usedPercentage });
|
|
19914
|
-
return;
|
|
19915
|
-
}
|
|
19916
|
-
const matchActive = and13(
|
|
19917
|
-
eq31(usagePeaks.window, window),
|
|
19918
|
-
eq31(usagePeaks.resetsAt, resetsAt),
|
|
19919
|
-
eq31(usagePeaks.segment, active.segment)
|
|
19920
|
-
);
|
|
19921
|
-
if (usedPercentage < active.usedPercentage - RESET_DROP_THRESHOLD) {
|
|
19922
|
-
await db.update(usagePeaks).set({ resetDetected: true }).where(matchActive);
|
|
19923
|
-
await db.insert(usagePeaks).values({
|
|
19924
|
-
window,
|
|
19925
|
-
resetsAt,
|
|
19926
|
-
segment: active.segment + 1,
|
|
19927
|
-
usedPercentage
|
|
19928
|
-
});
|
|
19929
|
-
return;
|
|
19930
|
-
}
|
|
19931
|
-
await db.update(usagePeaks).set({
|
|
19932
|
-
usedPercentage: sql5`GREATEST(${usagePeaks.usedPercentage}, ${usedPercentage})`
|
|
19933
|
-
}).where(matchActive);
|
|
19934
|
-
}
|
|
19935
|
-
|
|
19936
20024
|
// src/shared/db/recordUsagePeak.ts
|
|
19937
20025
|
var WINDOWS = ["five_hour", "seven_day"];
|
|
19938
20026
|
async function recordUsagePeak(db, rateLimits) {
|