@staff0rd/assist 0.409.0 → 0.410.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 +66 -66
- package/dist/index.js +63 -49
- 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.410.0",
|
|
10
10
|
type: "module",
|
|
11
11
|
main: "dist/index.js",
|
|
12
12
|
bin: {
|
|
@@ -1221,8 +1221,8 @@ async function assertMigrationsInSync(exec3) {
|
|
|
1221
1221
|
// src/shared/db/migrations/MigrationExecutor.ts
|
|
1222
1222
|
function pgExecutor(queryable) {
|
|
1223
1223
|
return {
|
|
1224
|
-
exec: (
|
|
1225
|
-
query: async (
|
|
1224
|
+
exec: (sql25) => queryable.query(sql25),
|
|
1225
|
+
query: async (sql25, params) => (await queryable.query(sql25, params)).rows
|
|
1226
1226
|
};
|
|
1227
1227
|
}
|
|
1228
1228
|
|
|
@@ -4754,8 +4754,8 @@ async function buildDump(tables, copyOut) {
|
|
|
4754
4754
|
// src/commands/backlog/dump/copyTableOut.ts
|
|
4755
4755
|
import { to as copyTo } from "pg-copy-streams";
|
|
4756
4756
|
async function copyTableOut(client, table) {
|
|
4757
|
-
const
|
|
4758
|
-
const stream = client.query(copyTo(
|
|
4757
|
+
const sql25 = `COPY ${table.name} (${table.columns.join(", ")}) TO STDOUT`;
|
|
4758
|
+
const stream = client.query(copyTo(sql25));
|
|
4759
4759
|
const chunks = [];
|
|
4760
4760
|
for await (const chunk of stream) {
|
|
4761
4761
|
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
@@ -7888,21 +7888,30 @@ function incompleteSubtaskCounts(orm) {
|
|
|
7888
7888
|
}).from(itemSubtasks).where(ne(itemSubtasks.status, "done")).groupBy(itemSubtasks.itemId).as("incomplete_counts");
|
|
7889
7889
|
}
|
|
7890
7890
|
|
|
7891
|
-
// src/commands/backlog/
|
|
7891
|
+
// src/commands/backlog/planPhaseCounts.ts
|
|
7892
7892
|
import { sql as sql14 } from "drizzle-orm";
|
|
7893
|
+
function planPhaseCounts(orm) {
|
|
7894
|
+
return orm.select({
|
|
7895
|
+
itemId: planPhases.itemId,
|
|
7896
|
+
count: sql14`count(*)::int`.as("plan_phase_count")
|
|
7897
|
+
}).from(planPhases).groupBy(planPhases.itemId).as("plan_phase_counts");
|
|
7898
|
+
}
|
|
7899
|
+
|
|
7900
|
+
// src/commands/backlog/phaseUsageTotals.ts
|
|
7901
|
+
import { sql as sql15 } from "drizzle-orm";
|
|
7893
7902
|
function phaseUsageTotals(orm) {
|
|
7894
7903
|
return orm.select({
|
|
7895
7904
|
itemId: phaseUsage.itemId,
|
|
7896
|
-
tokensUp:
|
|
7905
|
+
tokensUp: sql15`sum(${phaseUsage.tokensUp})::bigint`.as(
|
|
7897
7906
|
"total_tokens_up"
|
|
7898
7907
|
),
|
|
7899
|
-
tokensDown:
|
|
7908
|
+
tokensDown: sql15`sum(${phaseUsage.tokensDown})::bigint`.as(
|
|
7900
7909
|
"total_tokens_down"
|
|
7901
7910
|
),
|
|
7902
|
-
activeMs:
|
|
7911
|
+
activeMs: sql15`sum(${phaseUsage.activeMs})::bigint`.as(
|
|
7903
7912
|
"total_active_ms"
|
|
7904
7913
|
),
|
|
7905
|
-
peakContextPct:
|
|
7914
|
+
peakContextPct: sql15`max(${phaseUsage.peakContextPct})`.as(
|
|
7906
7915
|
"max_peak_context_pct"
|
|
7907
7916
|
)
|
|
7908
7917
|
}).from(phaseUsage).groupBy(phaseUsage.itemId).as("usage_totals");
|
|
@@ -7919,6 +7928,8 @@ function rowToItemSummary(row) {
|
|
|
7919
7928
|
starred: row.starred,
|
|
7920
7929
|
jiraKey: row.jiraKey ?? void 0,
|
|
7921
7930
|
githubIssue: row.githubIssue ?? void 0,
|
|
7931
|
+
currentPhase: row.currentPhase ?? void 0,
|
|
7932
|
+
totalPhases: (row.planPhaseCount || 1) + 1,
|
|
7922
7933
|
incompleteSubtasks: row.incompleteSubtasks ?? 0,
|
|
7923
7934
|
usageTotal: row.tokensUp == null ? void 0 : {
|
|
7924
7935
|
tokensUp: Number(row.tokensUp),
|
|
@@ -7933,6 +7944,7 @@ function rowToItemSummary(row) {
|
|
|
7933
7944
|
async function loadItemSummaries(orm, origin) {
|
|
7934
7945
|
const incompleteCounts = incompleteSubtaskCounts(orm);
|
|
7935
7946
|
const usageTotals = phaseUsageTotals(orm);
|
|
7947
|
+
const phaseCounts = planPhaseCounts(orm);
|
|
7936
7948
|
const rows = await orm.select({
|
|
7937
7949
|
id: items.id,
|
|
7938
7950
|
origin: items.origin,
|
|
@@ -7942,12 +7954,14 @@ async function loadItemSummaries(orm, origin) {
|
|
|
7942
7954
|
starred: items.starred,
|
|
7943
7955
|
jiraKey: items.jiraKey,
|
|
7944
7956
|
githubIssue: items.githubIssue,
|
|
7957
|
+
currentPhase: items.currentPhase,
|
|
7958
|
+
planPhaseCount: phaseCounts.count,
|
|
7945
7959
|
incompleteSubtasks: incompleteCounts.count,
|
|
7946
7960
|
tokensUp: usageTotals.tokensUp,
|
|
7947
7961
|
tokensDown: usageTotals.tokensDown,
|
|
7948
7962
|
activeMs: usageTotals.activeMs,
|
|
7949
7963
|
peakContextPct: usageTotals.peakContextPct
|
|
7950
|
-
}).from(items).leftJoin(incompleteCounts, eq12(incompleteCounts.itemId, items.id)).leftJoin(usageTotals, eq12(usageTotals.itemId, items.id)).where(origin === void 0 ? void 0 : eq12(items.origin, origin)).orderBy(asc5(items.id));
|
|
7964
|
+
}).from(items).leftJoin(incompleteCounts, eq12(incompleteCounts.itemId, items.id)).leftJoin(usageTotals, eq12(usageTotals.itemId, items.id)).leftJoin(phaseCounts, eq12(phaseCounts.itemId, items.id)).where(origin === void 0 ? void 0 : eq12(items.origin, origin)).orderBy(asc5(items.id));
|
|
7951
7965
|
return rows.map(rowToItemSummary);
|
|
7952
7966
|
}
|
|
7953
7967
|
|
|
@@ -8745,12 +8759,12 @@ async function listNewsItems(_req, res) {
|
|
|
8745
8759
|
}
|
|
8746
8760
|
|
|
8747
8761
|
// src/shared/db/listUsagePeaks.ts
|
|
8748
|
-
import { and as and7, count, desc as desc2, eq as eq16, getTableColumns, sql as
|
|
8762
|
+
import { and as and7, count, desc as desc2, eq as eq16, getTableColumns, sql as sql16 } from "drizzle-orm";
|
|
8749
8763
|
async function listUsagePeaks(db, paging) {
|
|
8750
8764
|
const avgContext = db.select({
|
|
8751
8765
|
window: phaseCycleContext.window,
|
|
8752
8766
|
resetsAt: phaseCycleContext.resetsAt,
|
|
8753
|
-
avgContextPct:
|
|
8767
|
+
avgContextPct: sql16`cast(avg(${phaseCycleContext.peakContextPct}) as double precision)`.as(
|
|
8754
8768
|
"avg_context_pct"
|
|
8755
8769
|
),
|
|
8756
8770
|
phaseCount: count().as("phase_count")
|
|
@@ -9961,8 +9975,8 @@ async function readStdinBuffer() {
|
|
|
9961
9975
|
import { finished } from "stream/promises";
|
|
9962
9976
|
import { from as copyFrom } from "pg-copy-streams";
|
|
9963
9977
|
async function copyTableIn(client, table, data) {
|
|
9964
|
-
const
|
|
9965
|
-
const stream = client.query(copyFrom(
|
|
9978
|
+
const sql25 = `COPY ${table.name} (${table.columns.join(", ")}) FROM STDIN`;
|
|
9979
|
+
const stream = client.query(copyFrom(sql25));
|
|
9966
9980
|
stream.end(data);
|
|
9967
9981
|
await finished(stream);
|
|
9968
9982
|
}
|
|
@@ -10086,11 +10100,11 @@ async function insertPhaseAt(orm, itemId2, phaseIdx, name, tasks, manualChecks,
|
|
|
10086
10100
|
}
|
|
10087
10101
|
|
|
10088
10102
|
// src/commands/backlog/insertSubtask.ts
|
|
10089
|
-
import { sql as
|
|
10103
|
+
import { sql as sql17 } from "drizzle-orm";
|
|
10090
10104
|
async function insertSubtask(orm, itemId2, title, description) {
|
|
10091
10105
|
await orm.insert(itemSubtasks).values({
|
|
10092
10106
|
itemId: itemId2,
|
|
10093
|
-
idx:
|
|
10107
|
+
idx: sql17`(SELECT COALESCE(MAX(${itemSubtasks.idx}) + 1, 0) FROM ${itemSubtasks} WHERE ${itemSubtasks.itemId} = ${itemId2})`,
|
|
10094
10108
|
title,
|
|
10095
10109
|
description: description ?? null,
|
|
10096
10110
|
status: "todo"
|
|
@@ -15721,9 +15735,9 @@ function registerGithub(program2) {
|
|
|
15721
15735
|
}
|
|
15722
15736
|
|
|
15723
15737
|
// src/commands/handover/countPendingHandovers.ts
|
|
15724
|
-
import { and as and18, eq as eq37, isNull, sql as
|
|
15738
|
+
import { and as and18, eq as eq37, isNull, sql as sql18 } from "drizzle-orm";
|
|
15725
15739
|
async function countPendingHandovers(orm, origin) {
|
|
15726
|
-
const [row] = await orm.select({ count:
|
|
15740
|
+
const [row] = await orm.select({ count: sql18`count(*)::int` }).from(handovers).where(and18(eq37(handovers.origin, origin), isNull(handovers.recalledAt)));
|
|
15727
15741
|
return row?.count ?? 0;
|
|
15728
15742
|
}
|
|
15729
15743
|
|
|
@@ -22126,8 +22140,8 @@ function filterToSql(filter) {
|
|
|
22126
22140
|
// src/commands/seq/fetchSeqData.ts
|
|
22127
22141
|
function buildDataParams(filter, count7, from, to) {
|
|
22128
22142
|
const sqlFilter = filterToSql(filter);
|
|
22129
|
-
const
|
|
22130
|
-
const params = new URLSearchParams({ q:
|
|
22143
|
+
const sql25 = `select @Timestamp, @Level, @Exception, @Message from stream where ${sqlFilter} order by @Timestamp desc limit ${count7}`;
|
|
22144
|
+
const params = new URLSearchParams({ q: sql25 });
|
|
22131
22145
|
if (from) params.set("rangeStartUtc", from);
|
|
22132
22146
|
if (to) params.set("rangeEndUtc", to);
|
|
22133
22147
|
return params;
|
|
@@ -22388,26 +22402,26 @@ import chalk194 from "chalk";
|
|
|
22388
22402
|
// src/commands/sql/loadConnections.ts
|
|
22389
22403
|
function loadConnections3() {
|
|
22390
22404
|
const raw = loadGlobalConfigRaw();
|
|
22391
|
-
const
|
|
22392
|
-
return
|
|
22405
|
+
const sql25 = raw.sql;
|
|
22406
|
+
return sql25?.connections ?? [];
|
|
22393
22407
|
}
|
|
22394
22408
|
function saveConnections3(connections) {
|
|
22395
22409
|
const raw = loadGlobalConfigRaw();
|
|
22396
|
-
const
|
|
22397
|
-
|
|
22398
|
-
raw.sql =
|
|
22410
|
+
const sql25 = raw.sql ?? {};
|
|
22411
|
+
sql25.connections = connections;
|
|
22412
|
+
raw.sql = sql25;
|
|
22399
22413
|
saveGlobalConfig(raw);
|
|
22400
22414
|
}
|
|
22401
22415
|
function getDefaultConnection2() {
|
|
22402
22416
|
const raw = loadGlobalConfigRaw();
|
|
22403
|
-
const
|
|
22404
|
-
return
|
|
22417
|
+
const sql25 = raw.sql;
|
|
22418
|
+
return sql25?.defaultConnection;
|
|
22405
22419
|
}
|
|
22406
22420
|
function setDefaultConnection2(name) {
|
|
22407
22421
|
const raw = loadGlobalConfigRaw();
|
|
22408
|
-
const
|
|
22409
|
-
|
|
22410
|
-
raw.sql =
|
|
22422
|
+
const sql25 = raw.sql ?? {};
|
|
22423
|
+
sql25.defaultConnection = name;
|
|
22424
|
+
raw.sql = sql25;
|
|
22411
22425
|
saveGlobalConfig(raw);
|
|
22412
22426
|
}
|
|
22413
22427
|
|
|
@@ -22478,9 +22492,9 @@ function resolveConnection3(name) {
|
|
|
22478
22492
|
}
|
|
22479
22493
|
|
|
22480
22494
|
// src/commands/sql/sqlConnect.ts
|
|
22481
|
-
import
|
|
22495
|
+
import sql19 from "mssql";
|
|
22482
22496
|
async function sqlConnect(conn) {
|
|
22483
|
-
return await
|
|
22497
|
+
return await sql19.connect({
|
|
22484
22498
|
server: conn.server,
|
|
22485
22499
|
port: conn.port,
|
|
22486
22500
|
user: conn.user,
|
|
@@ -22557,11 +22571,11 @@ var MUTATION_PATTERN = new RegExp(
|
|
|
22557
22571
|
`\\b(${MUTATION_KEYWORDS.join("|")})\\b`,
|
|
22558
22572
|
"i"
|
|
22559
22573
|
);
|
|
22560
|
-
function stripComments(
|
|
22561
|
-
return
|
|
22574
|
+
function stripComments(sql25) {
|
|
22575
|
+
return sql25.replace(/\/\*[\s\S]*?\*\//g, " ").replace(/--[^\n]*/g, " ");
|
|
22562
22576
|
}
|
|
22563
|
-
function isMutation(
|
|
22564
|
-
const stripped = stripComments(
|
|
22577
|
+
function isMutation(sql25) {
|
|
22578
|
+
const stripped = stripComments(sql25);
|
|
22565
22579
|
if (MUTATION_PATTERN.test(stripped)) return true;
|
|
22566
22580
|
return /\bSELECT\b[\s\S]+\bINTO\s+\w/i.test(stripped);
|
|
22567
22581
|
}
|
|
@@ -24914,13 +24928,13 @@ function drainSessions(sessions, onDrained) {
|
|
|
24914
24928
|
}
|
|
24915
24929
|
|
|
24916
24930
|
// src/shared/db/recordPhaseActiveMs.ts
|
|
24917
|
-
import { sql as
|
|
24931
|
+
import { sql as sql20 } from "drizzle-orm";
|
|
24918
24932
|
async function recordPhaseActiveMs(db, itemId2, phaseIdx, activeMs) {
|
|
24919
24933
|
if (activeMs <= 0) return;
|
|
24920
24934
|
await db.insert(phaseUsage).values({ itemId: itemId2, phaseIdx, activeMs }).onConflictDoUpdate({
|
|
24921
24935
|
target: [phaseUsage.itemId, phaseUsage.phaseIdx],
|
|
24922
24936
|
set: {
|
|
24923
|
-
activeMs:
|
|
24937
|
+
activeMs: sql20`${phaseUsage.activeMs} + excluded.active_ms`
|
|
24924
24938
|
}
|
|
24925
24939
|
});
|
|
24926
24940
|
}
|
|
@@ -25112,7 +25126,7 @@ function makeStatusChangeHandler(dismiss, notify2, reuseForRun) {
|
|
|
25112
25126
|
}
|
|
25113
25127
|
|
|
25114
25128
|
// src/shared/db/recordPhaseCycleContext.ts
|
|
25115
|
-
import { sql as
|
|
25129
|
+
import { sql as sql21 } from "drizzle-orm";
|
|
25116
25130
|
async function recordPhaseCycleContext(db, itemId2, phaseIdx, window, resetsAt, pct) {
|
|
25117
25131
|
if (pct <= 0) return;
|
|
25118
25132
|
await db.insert(phaseCycleContext).values({ itemId: itemId2, phaseIdx, window, resetsAt, peakContextPct: pct }).onConflictDoUpdate({
|
|
@@ -25123,24 +25137,24 @@ async function recordPhaseCycleContext(db, itemId2, phaseIdx, window, resetsAt,
|
|
|
25123
25137
|
phaseCycleContext.resetsAt
|
|
25124
25138
|
],
|
|
25125
25139
|
set: {
|
|
25126
|
-
peakContextPct:
|
|
25140
|
+
peakContextPct: sql21`GREATEST(${phaseCycleContext.peakContextPct}, ${pct})`
|
|
25127
25141
|
}
|
|
25128
25142
|
});
|
|
25129
25143
|
}
|
|
25130
25144
|
|
|
25131
25145
|
// src/shared/db/recordPhasePeakContext.ts
|
|
25132
|
-
import { sql as
|
|
25146
|
+
import { sql as sql22 } from "drizzle-orm";
|
|
25133
25147
|
async function recordPhasePeakContext(db, itemId2, phaseIdx, pct) {
|
|
25134
25148
|
await db.insert(phaseUsage).values({ itemId: itemId2, phaseIdx, peakContextPct: pct }).onConflictDoUpdate({
|
|
25135
25149
|
target: [phaseUsage.itemId, phaseUsage.phaseIdx],
|
|
25136
25150
|
set: {
|
|
25137
|
-
peakContextPct:
|
|
25151
|
+
peakContextPct: sql22`GREATEST(${phaseUsage.peakContextPct}, ${pct})`
|
|
25138
25152
|
}
|
|
25139
25153
|
});
|
|
25140
25154
|
}
|
|
25141
25155
|
|
|
25142
25156
|
// src/shared/db/recordPhaseTranscriptUsage.ts
|
|
25143
|
-
import { sql as
|
|
25157
|
+
import { sql as sql23 } from "drizzle-orm";
|
|
25144
25158
|
async function recordPhaseTranscriptUsage(db, itemId2, phaseIdx, responses) {
|
|
25145
25159
|
const byId = /* @__PURE__ */ new Map();
|
|
25146
25160
|
for (const r of responses) byId.set(r.messageId, r);
|
|
@@ -25160,8 +25174,8 @@ async function recordPhaseTranscriptUsage(db, itemId2, phaseIdx, responses) {
|
|
|
25160
25174
|
await tx.insert(phaseUsage).values({ itemId: itemId2, phaseIdx, tokensUp, tokensDown }).onConflictDoUpdate({
|
|
25161
25175
|
target: [phaseUsage.itemId, phaseUsage.phaseIdx],
|
|
25162
25176
|
set: {
|
|
25163
|
-
tokensUp:
|
|
25164
|
-
tokensDown:
|
|
25177
|
+
tokensUp: sql23`${phaseUsage.tokensUp} + ${tokensUp}`,
|
|
25178
|
+
tokensDown: sql23`${phaseUsage.tokensDown} + ${tokensDown}`
|
|
25165
25179
|
}
|
|
25166
25180
|
});
|
|
25167
25181
|
return { tokensUp, tokensDown };
|
|
@@ -25169,12 +25183,12 @@ async function recordPhaseTranscriptUsage(db, itemId2, phaseIdx, responses) {
|
|
|
25169
25183
|
}
|
|
25170
25184
|
|
|
25171
25185
|
// src/shared/db/recordWindowTokens.ts
|
|
25172
|
-
import { and as and21, eq as eq40, sql as
|
|
25186
|
+
import { and as and21, eq as eq40, sql as sql24 } from "drizzle-orm";
|
|
25173
25187
|
async function recordWindowTokens(db, window, resetsAt, tokensUp, tokensDown) {
|
|
25174
25188
|
if (tokensUp <= 0 && tokensDown <= 0) return;
|
|
25175
25189
|
await db.update(usagePeaks).set({
|
|
25176
|
-
tokensUp:
|
|
25177
|
-
tokensDown:
|
|
25190
|
+
tokensUp: sql24`${usagePeaks.tokensUp} + ${tokensUp}`,
|
|
25191
|
+
tokensDown: sql24`${usagePeaks.tokensDown} + ${tokensDown}`
|
|
25178
25192
|
}).where(
|
|
25179
25193
|
and21(
|
|
25180
25194
|
eq40(usagePeaks.window, window),
|