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