@staff0rd/assist 0.462.0 → 0.463.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 +1 -1
- package/dist/index.js +354 -203
- 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.463.0",
|
|
10
10
|
type: "module",
|
|
11
11
|
main: "dist/index.js",
|
|
12
12
|
bin: {
|
|
@@ -3886,9 +3886,9 @@ function forbiddenStrings() {
|
|
|
3886
3886
|
console.log("No forbidden-strings rules configured.");
|
|
3887
3887
|
process.exit(0);
|
|
3888
3888
|
}
|
|
3889
|
-
const
|
|
3889
|
+
const cache5 = /* @__PURE__ */ new Map();
|
|
3890
3890
|
const readJson = (file) => {
|
|
3891
|
-
if (
|
|
3891
|
+
if (cache5.has(file)) return cache5.get(file);
|
|
3892
3892
|
if (!existsSync12(file)) {
|
|
3893
3893
|
console.log(`Forbidden-strings file not found: ${file}`);
|
|
3894
3894
|
process.exit(1);
|
|
@@ -3900,7 +3900,7 @@ function forbiddenStrings() {
|
|
|
3900
3900
|
console.log(`Could not parse ${file}: ${error.message}`);
|
|
3901
3901
|
process.exit(1);
|
|
3902
3902
|
}
|
|
3903
|
-
|
|
3903
|
+
cache5.set(file, parsed);
|
|
3904
3904
|
return parsed;
|
|
3905
3905
|
};
|
|
3906
3906
|
const violations = findForbiddenStrings(rules, readJson);
|
|
@@ -8569,19 +8569,19 @@ import { dirname as dirname19, join as join23 } from "path";
|
|
|
8569
8569
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
8570
8570
|
function createBundleHandler(importMetaUrl, bundlePath, contentType = "application/javascript") {
|
|
8571
8571
|
const file = join23(dirname19(fileURLToPath4(importMetaUrl)), bundlePath);
|
|
8572
|
-
let
|
|
8572
|
+
let cache5;
|
|
8573
8573
|
return (req, res) => {
|
|
8574
8574
|
const mtimeMs = statSync2(file).mtimeMs;
|
|
8575
|
-
if (
|
|
8575
|
+
if (cache5?.mtimeMs !== mtimeMs) {
|
|
8576
8576
|
const body = readFileSync19(file, "utf8");
|
|
8577
8577
|
const etag = `"${createHash("sha256").update(body).digest("hex").slice(0, 16)}"`;
|
|
8578
|
-
|
|
8578
|
+
cache5 = { body, etag, mtimeMs };
|
|
8579
8579
|
}
|
|
8580
8580
|
const headers = {
|
|
8581
|
-
ETag:
|
|
8581
|
+
ETag: cache5.etag,
|
|
8582
8582
|
"Cache-Control": "no-cache"
|
|
8583
8583
|
};
|
|
8584
|
-
if (req.headers["if-none-match"] ===
|
|
8584
|
+
if (req.headers["if-none-match"] === cache5.etag) {
|
|
8585
8585
|
res.writeHead(304, headers);
|
|
8586
8586
|
res.end();
|
|
8587
8587
|
return;
|
|
@@ -8590,7 +8590,7 @@ function createBundleHandler(importMetaUrl, bundlePath, contentType = "applicati
|
|
|
8590
8590
|
"Content-Type": contentType,
|
|
8591
8591
|
...headers
|
|
8592
8592
|
});
|
|
8593
|
-
res.end(
|
|
8593
|
+
res.end(cache5.body);
|
|
8594
8594
|
};
|
|
8595
8595
|
}
|
|
8596
8596
|
|
|
@@ -9084,65 +9084,117 @@ function getSessionParam(req) {
|
|
|
9084
9084
|
return url.searchParams.get("session") ?? void 0;
|
|
9085
9085
|
}
|
|
9086
9086
|
|
|
9087
|
-
// src/shared/db/findCommitAnchor.ts
|
|
9088
|
-
import { and as and7, asc as asc6, eq as eq16, inArray as inArray3 } from "drizzle-orm";
|
|
9089
|
-
async function findCommitAnchor(db, itemId2) {
|
|
9090
|
-
const rows = await db.select({ kind: itemGitRefs.kind, ref: itemGitRefs.ref }).from(itemGitRefs).where(
|
|
9091
|
-
and7(
|
|
9092
|
-
eq16(itemGitRefs.itemId, itemId2),
|
|
9093
|
-
inArray3(itemGitRefs.kind, ["commit", "commit-parent"])
|
|
9094
|
-
)
|
|
9095
|
-
).orderBy(asc6(itemGitRefs.createdAt));
|
|
9096
|
-
const anchor = {};
|
|
9097
|
-
for (const row of rows) {
|
|
9098
|
-
if (row.kind === "commit") anchor.commit ??= row.ref;
|
|
9099
|
-
else anchor.parent ??= row.ref;
|
|
9100
|
-
}
|
|
9101
|
-
return anchor;
|
|
9102
|
-
}
|
|
9103
|
-
|
|
9104
9087
|
// src/shared/db/findItemBySessionId.ts
|
|
9105
|
-
import { asc as
|
|
9088
|
+
import { asc as asc6, eq as eq16 } from "drizzle-orm";
|
|
9106
9089
|
async function findItemBySessionId(db, claudeSessionId) {
|
|
9107
|
-
const rows = await db.select({ itemId: phaseUsage.itemId }).from(phaseUsage).where(
|
|
9090
|
+
const rows = await db.select({ itemId: phaseUsage.itemId }).from(phaseUsage).where(eq16(phaseUsage.claudeSessionId, claudeSessionId)).orderBy(asc6(phaseUsage.itemId), asc6(phaseUsage.phaseIdx)).limit(1);
|
|
9108
9091
|
return rows[0]?.itemId;
|
|
9109
9092
|
}
|
|
9110
9093
|
|
|
9111
|
-
// src/
|
|
9112
|
-
|
|
9113
|
-
|
|
9114
|
-
|
|
9115
|
-
|
|
9116
|
-
|
|
9117
|
-
|
|
9118
|
-
|
|
9119
|
-
|
|
9120
|
-
|
|
9121
|
-
|
|
9122
|
-
|
|
9123
|
-
|
|
9124
|
-
return lookup;
|
|
9125
|
-
}
|
|
9126
|
-
async function loadAnchor(sessionId) {
|
|
9127
|
-
const anchor = await queryAnchor(sessionId);
|
|
9128
|
-
const found = Boolean(anchor.commit || anchor.parent);
|
|
9129
|
-
cache3.set(sessionId, {
|
|
9130
|
-
anchor,
|
|
9131
|
-
expiresAt: found ? Number.POSITIVE_INFINITY : Date.now() + EMPTY_TTL_MS
|
|
9132
|
-
});
|
|
9133
|
-
return anchor;
|
|
9094
|
+
// src/shared/db/listCommitRefs.ts
|
|
9095
|
+
import { and as and7, asc as asc7, eq as eq17 } from "drizzle-orm";
|
|
9096
|
+
async function listCommitRefs(db, itemId2) {
|
|
9097
|
+
const rows = await db.select({
|
|
9098
|
+
ref: itemGitRefs.ref,
|
|
9099
|
+
title: itemGitRefs.title,
|
|
9100
|
+
url: itemGitRefs.url
|
|
9101
|
+
}).from(itemGitRefs).where(and7(eq17(itemGitRefs.itemId, itemId2), eq17(itemGitRefs.kind, "commit"))).orderBy(asc7(itemGitRefs.createdAt), asc7(itemGitRefs.ref));
|
|
9102
|
+
return rows.map((row) => ({
|
|
9103
|
+
sha: row.ref,
|
|
9104
|
+
...row.title ? { title: row.title } : {},
|
|
9105
|
+
...row.url ? { url: row.url } : {}
|
|
9106
|
+
}));
|
|
9134
9107
|
}
|
|
9135
|
-
|
|
9108
|
+
|
|
9109
|
+
// src/commands/sessions/web/itemCommits.ts
|
|
9110
|
+
async function itemCommits(sessionId) {
|
|
9136
9111
|
try {
|
|
9137
9112
|
if (!process.env.ASSIST_DATABASE_URL && !loadConfig().database.url)
|
|
9138
|
-
return
|
|
9113
|
+
return [];
|
|
9139
9114
|
const db = await getDb();
|
|
9140
9115
|
const itemId2 = await findItemBySessionId(db, sessionId);
|
|
9141
|
-
if (itemId2 === void 0) return
|
|
9142
|
-
return await
|
|
9116
|
+
if (itemId2 === void 0) return [];
|
|
9117
|
+
return await listCommitRefs(db, itemId2);
|
|
9143
9118
|
} catch {
|
|
9144
|
-
return
|
|
9119
|
+
return [];
|
|
9120
|
+
}
|
|
9121
|
+
}
|
|
9122
|
+
|
|
9123
|
+
// src/commands/sessions/web/resolveCommit.ts
|
|
9124
|
+
var GIT_EMPTY_TREE_HASH = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
|
|
9125
|
+
async function resolveCommit(cwd, sha) {
|
|
9126
|
+
if (!await commitExists(cwd, sha)) return void 0;
|
|
9127
|
+
const parent = await parentOf(cwd, sha);
|
|
9128
|
+
return {
|
|
9129
|
+
base: parent ?? GIT_EMPTY_TREE_HASH,
|
|
9130
|
+
paths: await commitPaths(cwd, sha)
|
|
9131
|
+
};
|
|
9132
|
+
}
|
|
9133
|
+
async function commitExists(cwd, sha) {
|
|
9134
|
+
try {
|
|
9135
|
+
await execGit(cwd, ["cat-file", "-e", `${sha}^{commit}`]);
|
|
9136
|
+
return true;
|
|
9137
|
+
} catch {
|
|
9138
|
+
return false;
|
|
9139
|
+
}
|
|
9140
|
+
}
|
|
9141
|
+
async function parentOf(cwd, sha) {
|
|
9142
|
+
try {
|
|
9143
|
+
const parent = await execGit(cwd, [
|
|
9144
|
+
"rev-parse",
|
|
9145
|
+
"--verify",
|
|
9146
|
+
"--quiet",
|
|
9147
|
+
`${sha}^`
|
|
9148
|
+
]);
|
|
9149
|
+
return parent.trim() || void 0;
|
|
9150
|
+
} catch {
|
|
9151
|
+
return void 0;
|
|
9152
|
+
}
|
|
9153
|
+
}
|
|
9154
|
+
async function commitPaths(cwd, sha) {
|
|
9155
|
+
try {
|
|
9156
|
+
const output = await execGit(cwd, [
|
|
9157
|
+
"diff-tree",
|
|
9158
|
+
"--no-commit-id",
|
|
9159
|
+
"--name-only",
|
|
9160
|
+
"-r",
|
|
9161
|
+
"--root",
|
|
9162
|
+
sha
|
|
9163
|
+
]);
|
|
9164
|
+
return output.split("\n").filter(Boolean);
|
|
9165
|
+
} catch {
|
|
9166
|
+
return [];
|
|
9167
|
+
}
|
|
9168
|
+
}
|
|
9169
|
+
|
|
9170
|
+
// src/commands/sessions/web/committedPaths.ts
|
|
9171
|
+
var cache3 = /* @__PURE__ */ new Map();
|
|
9172
|
+
var inFlight = /* @__PURE__ */ new Map();
|
|
9173
|
+
var CACHE_TTL_MS = 1e4;
|
|
9174
|
+
async function committedPaths(cwd, sessionId) {
|
|
9175
|
+
const key = `${cwd} ${sessionId}`;
|
|
9176
|
+
const cached = cache3.get(key);
|
|
9177
|
+
if (cached && cached.expiresAt > Date.now()) return cached.value;
|
|
9178
|
+
const pending = inFlight.get(key);
|
|
9179
|
+
if (pending) return pending;
|
|
9180
|
+
const lookup = loadCommittedPaths(cwd, sessionId).then((value) => {
|
|
9181
|
+
cache3.set(key, { value, expiresAt: Date.now() + CACHE_TTL_MS });
|
|
9182
|
+
return value;
|
|
9183
|
+
}).finally(() => inFlight.delete(key));
|
|
9184
|
+
inFlight.set(key, lookup);
|
|
9185
|
+
return lookup;
|
|
9186
|
+
}
|
|
9187
|
+
async function loadCommittedPaths(cwd, sessionId) {
|
|
9188
|
+
const commits2 = await itemCommits(sessionId);
|
|
9189
|
+
const bases = /* @__PURE__ */ new Map();
|
|
9190
|
+
for (const commit2 of commits2) {
|
|
9191
|
+
const resolved = await resolveCommit(cwd, commit2.sha);
|
|
9192
|
+
if (!resolved) continue;
|
|
9193
|
+
for (const path71 of resolved.paths) {
|
|
9194
|
+
if (!bases.has(path71)) bases.set(path71, resolved.base);
|
|
9195
|
+
}
|
|
9145
9196
|
}
|
|
9197
|
+
return { commits: commits2, bases };
|
|
9146
9198
|
}
|
|
9147
9199
|
|
|
9148
9200
|
// src/commands/sessions/web/windowsCwdToWslPath.ts
|
|
@@ -9159,55 +9211,37 @@ function toGitCwd(cwd) {
|
|
|
9159
9211
|
return detectPlatform() === "wsl" ? windowsCwdToWslPath(cwd) : cwd;
|
|
9160
9212
|
}
|
|
9161
9213
|
|
|
9162
|
-
// src/commands/sessions/web/
|
|
9163
|
-
function
|
|
9164
|
-
return
|
|
9165
|
-
|
|
9166
|
-
|
|
9167
|
-
|
|
9168
|
-
|
|
9169
|
-
|
|
9170
|
-
|
|
9171
|
-
].filter((candidate) => Boolean(candidate));
|
|
9214
|
+
// src/commands/sessions/web/itemChangeSet.ts
|
|
9215
|
+
async function itemChangeSet(cwd, sessionId) {
|
|
9216
|
+
if (!sessionId || !includesCommittedChanges(cwd)) return void 0;
|
|
9217
|
+
const { commits: commits2, bases } = await committedPaths(cwd, sessionId);
|
|
9218
|
+
if (bases.size === 0) return void 0;
|
|
9219
|
+
const groups = groupByBase(bases);
|
|
9220
|
+
const dirty = await dirtyPaths(cwd, bases);
|
|
9221
|
+
if (dirty.length > 0) groups.push({ base: "HEAD", paths: dirty });
|
|
9222
|
+
return { commits: commits2, groups };
|
|
9172
9223
|
}
|
|
9173
|
-
|
|
9224
|
+
function includesCommittedChanges(cwd) {
|
|
9174
9225
|
try {
|
|
9175
|
-
|
|
9176
|
-
|
|
9226
|
+
return Boolean(
|
|
9227
|
+
loadConfigFrom(toGitCwd(cwd)).sessions?.includeCommittedChanges
|
|
9228
|
+
);
|
|
9177
9229
|
} catch {
|
|
9178
9230
|
return false;
|
|
9179
9231
|
}
|
|
9180
9232
|
}
|
|
9181
|
-
|
|
9182
|
-
const
|
|
9183
|
-
|
|
9184
|
-
|
|
9185
|
-
|
|
9186
|
-
|
|
9187
|
-
async function resolveDiffBase(cwd, sessionId) {
|
|
9188
|
-
let defaultBranch;
|
|
9189
|
-
try {
|
|
9190
|
-
const config = loadConfigFrom(toGitCwd(cwd));
|
|
9191
|
-
if (!config.sessions?.includeCommittedChanges) return "HEAD";
|
|
9192
|
-
defaultBranch = config.branch?.defaultBranch;
|
|
9193
|
-
} catch {
|
|
9194
|
-
return "HEAD";
|
|
9195
|
-
}
|
|
9196
|
-
if (sessionId) {
|
|
9197
|
-
const anchored = await anchoredBase(cwd, sessionId);
|
|
9198
|
-
if (anchored) return anchored;
|
|
9199
|
-
}
|
|
9200
|
-
for (const candidate of baseCandidates(defaultBranch)) {
|
|
9201
|
-
if (!await refExists2(cwd, candidate)) continue;
|
|
9202
|
-
try {
|
|
9203
|
-
const base = await execGit(cwd, ["merge-base", "HEAD", candidate]);
|
|
9204
|
-
const sha = base.trim();
|
|
9205
|
-
if (sha) return sha;
|
|
9206
|
-
} catch {
|
|
9207
|
-
}
|
|
9208
|
-
return "HEAD";
|
|
9233
|
+
function groupByBase(bases) {
|
|
9234
|
+
const groups = /* @__PURE__ */ new Map();
|
|
9235
|
+
for (const [path71, base] of bases) {
|
|
9236
|
+
const paths = groups.get(base);
|
|
9237
|
+
if (paths) paths.push(path71);
|
|
9238
|
+
else groups.set(base, [path71]);
|
|
9209
9239
|
}
|
|
9210
|
-
return
|
|
9240
|
+
return [...groups].map(([base, paths]) => ({ base, paths: paths.sort() }));
|
|
9241
|
+
}
|
|
9242
|
+
async function dirtyPaths(cwd, bases) {
|
|
9243
|
+
const output = await execGit(cwd, ["diff", "--name-only", "HEAD"]);
|
|
9244
|
+
return output.split("\n").filter((path71) => path71 && !bases.has(path71)).sort();
|
|
9211
9245
|
}
|
|
9212
9246
|
|
|
9213
9247
|
// src/commands/sessions/web/diff.ts
|
|
@@ -9230,14 +9264,26 @@ async function untrackedDiff(cwd) {
|
|
|
9230
9264
|
);
|
|
9231
9265
|
return diffs.join("");
|
|
9232
9266
|
}
|
|
9267
|
+
async function groupedDiff(cwd, groups) {
|
|
9268
|
+
const diffs = await Promise.all(
|
|
9269
|
+
groups.map(
|
|
9270
|
+
(group) => execGit(cwd, ["diff", group.base, "--", ...group.paths], {
|
|
9271
|
+
maxBuffer: MAX_DIFF_BYTES
|
|
9272
|
+
})
|
|
9273
|
+
)
|
|
9274
|
+
);
|
|
9275
|
+
return diffs.join("");
|
|
9276
|
+
}
|
|
9277
|
+
async function trackedDiff(cwd, session) {
|
|
9278
|
+
const changeSet = await itemChangeSet(cwd, session);
|
|
9279
|
+
if (changeSet) return groupedDiff(cwd, changeSet.groups);
|
|
9280
|
+
return execGit(cwd, ["diff", "HEAD"], { maxBuffer: MAX_DIFF_BYTES });
|
|
9281
|
+
}
|
|
9233
9282
|
async function diff2(req, res) {
|
|
9234
9283
|
const cwd = getCwdParam(req, res);
|
|
9235
9284
|
if (!cwd) return;
|
|
9236
9285
|
try {
|
|
9237
|
-
const
|
|
9238
|
-
const tracked = await execGit(cwd, ["diff", base], {
|
|
9239
|
-
maxBuffer: MAX_DIFF_BYTES
|
|
9240
|
-
});
|
|
9286
|
+
const tracked = await trackedDiff(cwd, getSessionParam(req));
|
|
9241
9287
|
const untracked = await untrackedDiff(cwd);
|
|
9242
9288
|
res.writeHead(200, { "Content-Type": "text/plain; charset=utf-8" });
|
|
9243
9289
|
res.end(tracked + untracked);
|
|
@@ -9622,6 +9668,111 @@ function parseGitStatus(output) {
|
|
|
9622
9668
|
return result;
|
|
9623
9669
|
}
|
|
9624
9670
|
|
|
9671
|
+
// src/shared/db/findCommitAnchor.ts
|
|
9672
|
+
import { and as and8, asc as asc8, eq as eq18, inArray as inArray3 } from "drizzle-orm";
|
|
9673
|
+
async function findCommitAnchor(db, itemId2) {
|
|
9674
|
+
const rows = await db.select({ kind: itemGitRefs.kind, ref: itemGitRefs.ref }).from(itemGitRefs).where(
|
|
9675
|
+
and8(
|
|
9676
|
+
eq18(itemGitRefs.itemId, itemId2),
|
|
9677
|
+
inArray3(itemGitRefs.kind, ["commit", "commit-parent"])
|
|
9678
|
+
)
|
|
9679
|
+
).orderBy(asc8(itemGitRefs.createdAt));
|
|
9680
|
+
const anchor = {};
|
|
9681
|
+
for (const row of rows) {
|
|
9682
|
+
if (row.kind === "commit") anchor.commit ??= row.ref;
|
|
9683
|
+
else anchor.parent ??= row.ref;
|
|
9684
|
+
}
|
|
9685
|
+
return anchor;
|
|
9686
|
+
}
|
|
9687
|
+
|
|
9688
|
+
// src/commands/sessions/web/sessionCommitAnchor.ts
|
|
9689
|
+
var EMPTY_TTL_MS = 3e4;
|
|
9690
|
+
var cache4 = /* @__PURE__ */ new Map();
|
|
9691
|
+
var inFlight2 = /* @__PURE__ */ new Map();
|
|
9692
|
+
async function sessionCommitAnchor(sessionId) {
|
|
9693
|
+
const cached = cache4.get(sessionId);
|
|
9694
|
+
if (cached && cached.expiresAt > Date.now()) return cached.anchor;
|
|
9695
|
+
const pending = inFlight2.get(sessionId);
|
|
9696
|
+
if (pending) return pending;
|
|
9697
|
+
const lookup = loadAnchor(sessionId).finally(
|
|
9698
|
+
() => inFlight2.delete(sessionId)
|
|
9699
|
+
);
|
|
9700
|
+
inFlight2.set(sessionId, lookup);
|
|
9701
|
+
return lookup;
|
|
9702
|
+
}
|
|
9703
|
+
async function loadAnchor(sessionId) {
|
|
9704
|
+
const anchor = await queryAnchor(sessionId);
|
|
9705
|
+
const found = Boolean(anchor.commit || anchor.parent);
|
|
9706
|
+
cache4.set(sessionId, {
|
|
9707
|
+
anchor,
|
|
9708
|
+
expiresAt: found ? Number.POSITIVE_INFINITY : Date.now() + EMPTY_TTL_MS
|
|
9709
|
+
});
|
|
9710
|
+
return anchor;
|
|
9711
|
+
}
|
|
9712
|
+
async function queryAnchor(sessionId) {
|
|
9713
|
+
try {
|
|
9714
|
+
if (!process.env.ASSIST_DATABASE_URL && !loadConfig().database.url)
|
|
9715
|
+
return {};
|
|
9716
|
+
const db = await getDb();
|
|
9717
|
+
const itemId2 = await findItemBySessionId(db, sessionId);
|
|
9718
|
+
if (itemId2 === void 0) return {};
|
|
9719
|
+
return await findCommitAnchor(db, itemId2);
|
|
9720
|
+
} catch {
|
|
9721
|
+
return {};
|
|
9722
|
+
}
|
|
9723
|
+
}
|
|
9724
|
+
|
|
9725
|
+
// src/commands/sessions/web/resolveDiffBase.ts
|
|
9726
|
+
function baseCandidates(defaultBranch) {
|
|
9727
|
+
return [
|
|
9728
|
+
defaultBranch && `origin/${defaultBranch}`,
|
|
9729
|
+
defaultBranch,
|
|
9730
|
+
"origin/main",
|
|
9731
|
+
"origin/master",
|
|
9732
|
+
"main",
|
|
9733
|
+
"master"
|
|
9734
|
+
].filter((candidate) => Boolean(candidate));
|
|
9735
|
+
}
|
|
9736
|
+
async function refExists2(cwd, ref) {
|
|
9737
|
+
try {
|
|
9738
|
+
await execGit(cwd, ["rev-parse", "--verify", "--quiet", `${ref}^{commit}`]);
|
|
9739
|
+
return true;
|
|
9740
|
+
} catch {
|
|
9741
|
+
return false;
|
|
9742
|
+
}
|
|
9743
|
+
}
|
|
9744
|
+
async function anchoredBase(cwd, sessionId) {
|
|
9745
|
+
const { commit: commit2, parent } = await sessionCommitAnchor(sessionId);
|
|
9746
|
+
if (parent && await refExists2(cwd, parent)) return parent;
|
|
9747
|
+
if (commit2 && await refExists2(cwd, `${commit2}^`)) return `${commit2}^`;
|
|
9748
|
+
return void 0;
|
|
9749
|
+
}
|
|
9750
|
+
async function resolveDiffBase(cwd, sessionId) {
|
|
9751
|
+
let defaultBranch;
|
|
9752
|
+
try {
|
|
9753
|
+
const config = loadConfigFrom(toGitCwd(cwd));
|
|
9754
|
+
if (!config.sessions?.includeCommittedChanges) return "HEAD";
|
|
9755
|
+
defaultBranch = config.branch?.defaultBranch;
|
|
9756
|
+
} catch {
|
|
9757
|
+
return "HEAD";
|
|
9758
|
+
}
|
|
9759
|
+
if (sessionId) {
|
|
9760
|
+
const anchored = await anchoredBase(cwd, sessionId);
|
|
9761
|
+
if (anchored) return anchored;
|
|
9762
|
+
}
|
|
9763
|
+
for (const candidate of baseCandidates(defaultBranch)) {
|
|
9764
|
+
if (!await refExists2(cwd, candidate)) continue;
|
|
9765
|
+
try {
|
|
9766
|
+
const base = await execGit(cwd, ["merge-base", "HEAD", candidate]);
|
|
9767
|
+
const sha = base.trim();
|
|
9768
|
+
if (sha) return sha;
|
|
9769
|
+
} catch {
|
|
9770
|
+
}
|
|
9771
|
+
return "HEAD";
|
|
9772
|
+
}
|
|
9773
|
+
return "HEAD";
|
|
9774
|
+
}
|
|
9775
|
+
|
|
9625
9776
|
// src/commands/sessions/web/gitStatus.ts
|
|
9626
9777
|
async function untrackedPaths(cwd) {
|
|
9627
9778
|
const list5 = await execGit(cwd, [
|
|
@@ -9787,7 +9938,7 @@ function rankFilePaths(paths, query, limit) {
|
|
|
9787
9938
|
|
|
9788
9939
|
// src/commands/sessions/web/listFiles.ts
|
|
9789
9940
|
var MAX_RESULTS = 20;
|
|
9790
|
-
var
|
|
9941
|
+
var CACHE_TTL_MS2 = 5e3;
|
|
9791
9942
|
var LS_FILES_MAX_BUFFER = 32 * 1024 * 1024;
|
|
9792
9943
|
var fileListCache = /* @__PURE__ */ new Map();
|
|
9793
9944
|
async function repoFiles(cwd) {
|
|
@@ -9799,7 +9950,7 @@ async function repoFiles(cwd) {
|
|
|
9799
9950
|
{ maxBuffer: LS_FILES_MAX_BUFFER }
|
|
9800
9951
|
);
|
|
9801
9952
|
const files = [...new Set(output.split(/\r?\n/).filter(Boolean))];
|
|
9802
|
-
fileListCache.set(cwd, { files, expires: Date.now() +
|
|
9953
|
+
fileListCache.set(cwd, { files, expires: Date.now() + CACHE_TTL_MS2 });
|
|
9803
9954
|
return files;
|
|
9804
9955
|
}
|
|
9805
9956
|
async function listFiles(req, res) {
|
|
@@ -9938,14 +10089,14 @@ async function listNewsItems(_req, res) {
|
|
|
9938
10089
|
}
|
|
9939
10090
|
|
|
9940
10091
|
// src/shared/db/countUsagePeaks.ts
|
|
9941
|
-
import { count, eq as
|
|
10092
|
+
import { count, eq as eq19 } from "drizzle-orm";
|
|
9942
10093
|
async function countUsagePeaks(db, window) {
|
|
9943
|
-
const [row] = await db.select({ value: count() }).from(usagePeaks).where(window ?
|
|
10094
|
+
const [row] = await db.select({ value: count() }).from(usagePeaks).where(window ? eq19(usagePeaks.window, window) : void 0);
|
|
9944
10095
|
return row?.value ?? 0;
|
|
9945
10096
|
}
|
|
9946
10097
|
|
|
9947
10098
|
// src/shared/db/listUsagePeaks.ts
|
|
9948
|
-
import { and as
|
|
10099
|
+
import { and as and9, desc as desc2, eq as eq20, getTableColumns } from "drizzle-orm";
|
|
9949
10100
|
|
|
9950
10101
|
// src/shared/db/avgContextPerCycle.ts
|
|
9951
10102
|
import { count as count2, sql as sql16 } from "drizzle-orm";
|
|
@@ -9969,11 +10120,11 @@ async function listUsagePeaks(db, options2) {
|
|
|
9969
10120
|
phaseCount: avgContext.phaseCount
|
|
9970
10121
|
}).from(usagePeaks).leftJoin(
|
|
9971
10122
|
avgContext,
|
|
9972
|
-
|
|
9973
|
-
|
|
9974
|
-
|
|
10123
|
+
and9(
|
|
10124
|
+
eq20(usagePeaks.window, avgContext.window),
|
|
10125
|
+
eq20(usagePeaks.resetsAt, avgContext.resetsAt)
|
|
9975
10126
|
)
|
|
9976
|
-
).where(options2?.window ?
|
|
10127
|
+
).where(options2?.window ? eq20(usagePeaks.window, options2.window) : void 0).orderBy(
|
|
9977
10128
|
desc2(usagePeaks.resetsAt),
|
|
9978
10129
|
usagePeaks.window,
|
|
9979
10130
|
desc2(usagePeaks.createdAt),
|
|
@@ -10025,14 +10176,14 @@ async function openInCode(req, res) {
|
|
|
10025
10176
|
import { execFile as execFile5 } from "child_process";
|
|
10026
10177
|
import { promisify as promisify5 } from "util";
|
|
10027
10178
|
var execFileAsync4 = promisify5(execFile5);
|
|
10028
|
-
var
|
|
10179
|
+
var CACHE_TTL_MS3 = 3e4;
|
|
10029
10180
|
function createCachedGhJson(args, parse3, fallback, options2 = {}) {
|
|
10030
10181
|
const { cacheFallback = true } = options2;
|
|
10031
|
-
const
|
|
10182
|
+
const cache5 = /* @__PURE__ */ new Map();
|
|
10032
10183
|
return async (cwd, extraArgs = []) => {
|
|
10033
10184
|
const key = extraArgs.length ? `${cwd}\0${extraArgs.join("\0")}` : cwd;
|
|
10034
10185
|
const now = Date.now();
|
|
10035
|
-
const cached =
|
|
10186
|
+
const cached = cache5.get(key);
|
|
10036
10187
|
if (cached && cached.expires > now) return cached.value;
|
|
10037
10188
|
let value = fallback;
|
|
10038
10189
|
try {
|
|
@@ -10045,7 +10196,7 @@ function createCachedGhJson(args, parse3, fallback, options2 = {}) {
|
|
|
10045
10196
|
value = fallback;
|
|
10046
10197
|
}
|
|
10047
10198
|
if (cacheFallback || value !== fallback)
|
|
10048
|
-
|
|
10199
|
+
cache5.set(key, { value, expires: now + CACHE_TTL_MS3 });
|
|
10049
10200
|
return value;
|
|
10050
10201
|
};
|
|
10051
10202
|
}
|
|
@@ -10625,22 +10776,22 @@ import { readFileSync as readFileSync21 } from "fs";
|
|
|
10625
10776
|
import { createRequire as createRequire2 } from "module";
|
|
10626
10777
|
var require3 = createRequire2(import.meta.url);
|
|
10627
10778
|
function createCssHandler(packageEntry) {
|
|
10628
|
-
let
|
|
10779
|
+
let cache5;
|
|
10629
10780
|
return (req, res) => {
|
|
10630
|
-
if (!
|
|
10781
|
+
if (!cache5) {
|
|
10631
10782
|
const resolved = require3.resolve(packageEntry);
|
|
10632
10783
|
const body = readFileSync21(resolved, "utf8");
|
|
10633
10784
|
const etag = `"${createHash2("sha256").update(body).digest("hex").slice(0, 16)}"`;
|
|
10634
|
-
|
|
10785
|
+
cache5 = { body, etag };
|
|
10635
10786
|
}
|
|
10636
|
-
const headers = { ETag:
|
|
10637
|
-
if (req.headers["if-none-match"] ===
|
|
10787
|
+
const headers = { ETag: cache5.etag, "Cache-Control": "no-cache" };
|
|
10788
|
+
if (req.headers["if-none-match"] === cache5.etag) {
|
|
10638
10789
|
res.writeHead(304, headers);
|
|
10639
10790
|
res.end();
|
|
10640
10791
|
return;
|
|
10641
10792
|
}
|
|
10642
10793
|
res.writeHead(200, { "Content-Type": "text/css", ...headers });
|
|
10643
|
-
res.end(
|
|
10794
|
+
res.end(cache5.body);
|
|
10644
10795
|
};
|
|
10645
10796
|
}
|
|
10646
10797
|
|
|
@@ -11139,11 +11290,11 @@ function registerActivityCommands(cmd) {
|
|
|
11139
11290
|
|
|
11140
11291
|
// src/commands/backlog/associate-github/index.ts
|
|
11141
11292
|
import chalk64 from "chalk";
|
|
11142
|
-
import { eq as
|
|
11293
|
+
import { eq as eq22 } from "drizzle-orm";
|
|
11143
11294
|
|
|
11144
11295
|
// src/commands/backlog/beginAssociation.ts
|
|
11145
11296
|
import chalk63 from "chalk";
|
|
11146
|
-
import { eq as
|
|
11297
|
+
import { eq as eq21 } from "drizzle-orm";
|
|
11147
11298
|
async function beginAssociation(id, options2, clearPatch, label2) {
|
|
11148
11299
|
const found = await findOneItem(id);
|
|
11149
11300
|
if (!found) {
|
|
@@ -11153,7 +11304,7 @@ async function beginAssociation(id, options2, clearPatch, label2) {
|
|
|
11153
11304
|
const { orm } = found;
|
|
11154
11305
|
const itemId2 = found.item.id;
|
|
11155
11306
|
if (options2.clear) {
|
|
11156
|
-
await orm.update(items).set(clearPatch).where(
|
|
11307
|
+
await orm.update(items).set(clearPatch).where(eq21(items.id, itemId2));
|
|
11157
11308
|
console.log(
|
|
11158
11309
|
chalk63.green(
|
|
11159
11310
|
`Cleared ${label2} association on item ${formatItemId(itemId2)}.`
|
|
@@ -11221,7 +11372,7 @@ async function associateGithub(id, issue, options2) {
|
|
|
11221
11372
|
return;
|
|
11222
11373
|
}
|
|
11223
11374
|
const title = fetchGithubIssueTitle(normalized);
|
|
11224
|
-
await orm.update(items).set({ githubIssue: normalized, jiraKey: null }).where(
|
|
11375
|
+
await orm.update(items).set({ githubIssue: normalized, jiraKey: null }).where(eq22(items.id, itemId2));
|
|
11225
11376
|
console.log(
|
|
11226
11377
|
chalk64.green(`Associated ${normalized} with item ${formatItemId(itemId2)}.`),
|
|
11227
11378
|
title ? chalk64.dim(`(${title})`) : ""
|
|
@@ -11235,7 +11386,7 @@ function registerAssociateGithubCommand(cmd) {
|
|
|
11235
11386
|
|
|
11236
11387
|
// src/commands/backlog/associate-jira/index.ts
|
|
11237
11388
|
import chalk66 from "chalk";
|
|
11238
|
-
import { eq as
|
|
11389
|
+
import { eq as eq23 } from "drizzle-orm";
|
|
11239
11390
|
|
|
11240
11391
|
// src/commands/jira/fetchIssue.ts
|
|
11241
11392
|
import { execSync as execSync33 } from "child_process";
|
|
@@ -11300,7 +11451,7 @@ async function associateJira(id, key, options2) {
|
|
|
11300
11451
|
const parsed = fetchIssue(normalized, "summary");
|
|
11301
11452
|
const fields = parsed?.fields;
|
|
11302
11453
|
const summary = fields?.summary;
|
|
11303
|
-
await orm.update(items).set({ jiraKey: normalized, githubIssue: null }).where(
|
|
11454
|
+
await orm.update(items).set({ jiraKey: normalized, githubIssue: null }).where(eq23(items.id, itemId2));
|
|
11304
11455
|
console.log(
|
|
11305
11456
|
chalk66.green(`Associated ${normalized} with item ${formatItemId(itemId2)}.`),
|
|
11306
11457
|
summary ? chalk66.dim(`(${summary})`) : ""
|
|
@@ -11678,15 +11829,15 @@ function isClaudeCode() {
|
|
|
11678
11829
|
}
|
|
11679
11830
|
|
|
11680
11831
|
// src/commands/backlog/insertPhaseAt.ts
|
|
11681
|
-
import { eq as
|
|
11832
|
+
import { eq as eq25 } from "drizzle-orm";
|
|
11682
11833
|
|
|
11683
11834
|
// src/commands/backlog/shiftPhasesUp.ts
|
|
11684
|
-
import { and as
|
|
11835
|
+
import { and as and10, desc as desc3, eq as eq24, gte } from "drizzle-orm";
|
|
11685
11836
|
async function shiftPhasesUp(db, itemId2, fromIdx) {
|
|
11686
|
-
const toShift = await db.select({ idx: planPhases.idx }).from(planPhases).where(
|
|
11837
|
+
const toShift = await db.select({ idx: planPhases.idx }).from(planPhases).where(and10(eq24(planPhases.itemId, itemId2), gte(planPhases.idx, fromIdx))).orderBy(desc3(planPhases.idx));
|
|
11687
11838
|
for (const p of toShift) {
|
|
11688
|
-
await db.update(planTasks).set({ phaseIdx: p.idx + 1 }).where(
|
|
11689
|
-
await db.update(planPhases).set({ idx: p.idx + 1 }).where(
|
|
11839
|
+
await db.update(planTasks).set({ phaseIdx: p.idx + 1 }).where(and10(eq24(planTasks.itemId, itemId2), eq24(planTasks.phaseIdx, p.idx)));
|
|
11840
|
+
await db.update(planPhases).set({ idx: p.idx + 1 }).where(and10(eq24(planPhases.itemId, itemId2), eq24(planPhases.idx, p.idx)));
|
|
11690
11841
|
}
|
|
11691
11842
|
}
|
|
11692
11843
|
|
|
@@ -11699,7 +11850,7 @@ async function insertPhaseAt(orm, itemId2, phaseIdx, name, tasks, manualChecks,
|
|
|
11699
11850
|
await tx.insert(planTasks).values(tasks.map((task, i) => ({ itemId: itemId2, phaseIdx, idx: i, task })));
|
|
11700
11851
|
}
|
|
11701
11852
|
if (currentPhase !== void 0 && currentPhase - 1 >= phaseIdx) {
|
|
11702
|
-
await tx.update(items).set({ currentPhase: phaseIdx + 1 }).where(
|
|
11853
|
+
await tx.update(items).set({ currentPhase: phaseIdx + 1 }).where(eq25(items.id, itemId2));
|
|
11703
11854
|
}
|
|
11704
11855
|
});
|
|
11705
11856
|
}
|
|
@@ -11871,9 +12022,9 @@ import chalk76 from "chalk";
|
|
|
11871
12022
|
|
|
11872
12023
|
// src/commands/backlog/resolveInsertPosition.ts
|
|
11873
12024
|
import chalk75 from "chalk";
|
|
11874
|
-
import { count as count3, eq as
|
|
12025
|
+
import { count as count3, eq as eq26 } from "drizzle-orm";
|
|
11875
12026
|
async function resolveInsertPosition(orm, itemId2, position) {
|
|
11876
|
-
const [row] = await orm.select({ cnt: count3() }).from(planPhases).where(
|
|
12027
|
+
const [row] = await orm.select({ cnt: count3() }).from(planPhases).where(eq26(planPhases.itemId, itemId2));
|
|
11877
12028
|
const phaseCount = row?.cnt ?? 0;
|
|
11878
12029
|
if (position === void 0) return phaseCount;
|
|
11879
12030
|
const pos = Number.parseInt(position, 10);
|
|
@@ -12229,9 +12380,9 @@ function hasCycle(adjacency, fromId, toId) {
|
|
|
12229
12380
|
}
|
|
12230
12381
|
|
|
12231
12382
|
// src/commands/backlog/loadDependencyGraph.ts
|
|
12232
|
-
import { eq as
|
|
12383
|
+
import { eq as eq27 } from "drizzle-orm";
|
|
12233
12384
|
async function loadDependencyGraph(orm) {
|
|
12234
|
-
const rows = await orm.select({ itemId: links.itemId, targetId: links.targetId }).from(links).where(
|
|
12385
|
+
const rows = await orm.select({ itemId: links.itemId, targetId: links.targetId }).from(links).where(eq27(links.type, "depends-on"));
|
|
12235
12386
|
const graph = /* @__PURE__ */ new Map();
|
|
12236
12387
|
for (const { itemId: itemId2, targetId } of rows) {
|
|
12237
12388
|
const bucket = graph.get(itemId2);
|
|
@@ -12298,7 +12449,7 @@ async function link(fromId, toId, opts) {
|
|
|
12298
12449
|
|
|
12299
12450
|
// src/commands/backlog/unlink.ts
|
|
12300
12451
|
import chalk82 from "chalk";
|
|
12301
|
-
import { and as
|
|
12452
|
+
import { and as and11, eq as eq28 } from "drizzle-orm";
|
|
12302
12453
|
async function unlink(fromId, toId) {
|
|
12303
12454
|
const fromNum = parseItemId(fromId);
|
|
12304
12455
|
const toNum = parseItemId(toId);
|
|
@@ -12322,7 +12473,7 @@ async function unlink(fromId, toId) {
|
|
|
12322
12473
|
);
|
|
12323
12474
|
return;
|
|
12324
12475
|
}
|
|
12325
|
-
await orm.delete(links).where(
|
|
12476
|
+
await orm.delete(links).where(and11(eq28(links.itemId, fromNum), eq28(links.targetId, toNum)));
|
|
12326
12477
|
console.log(
|
|
12327
12478
|
chalk82.green(
|
|
12328
12479
|
`Removed link from ${formatItemId(fromNum)} to ${formatItemId(toNum)}.`
|
|
@@ -12342,7 +12493,7 @@ function registerLinkCommands(cmd) {
|
|
|
12342
12493
|
|
|
12343
12494
|
// src/commands/backlog/move-repo/index.ts
|
|
12344
12495
|
import chalk84 from "chalk";
|
|
12345
|
-
import { eq as
|
|
12496
|
+
import { eq as eq30 } from "drizzle-orm";
|
|
12346
12497
|
|
|
12347
12498
|
// src/commands/backlog/move-repo/confirmMove.ts
|
|
12348
12499
|
import chalk83 from "chalk";
|
|
@@ -12357,9 +12508,9 @@ async function confirmMove(cnt, oldOrigin, newOrigin) {
|
|
|
12357
12508
|
}
|
|
12358
12509
|
|
|
12359
12510
|
// src/commands/backlog/move-repo/countByOrigin.ts
|
|
12360
|
-
import { count as count4, eq as
|
|
12511
|
+
import { count as count4, eq as eq29 } from "drizzle-orm";
|
|
12361
12512
|
async function countByOrigin(orm, origin) {
|
|
12362
|
-
const [{ cnt }] = await orm.select({ cnt: count4() }).from(items).where(
|
|
12513
|
+
const [{ cnt }] = await orm.select({ cnt: count4() }).from(items).where(eq29(items.origin, origin));
|
|
12363
12514
|
return cnt;
|
|
12364
12515
|
}
|
|
12365
12516
|
|
|
@@ -12402,7 +12553,7 @@ async function moveRepo(oldOriginRaw, newOriginRaw, options2 = {}) {
|
|
|
12402
12553
|
console.log(chalk84.yellow("Move cancelled; no changes made."));
|
|
12403
12554
|
return;
|
|
12404
12555
|
}
|
|
12405
|
-
await orm.update(items).set({ origin: newOrigin }).where(
|
|
12556
|
+
await orm.update(items).set({ origin: newOrigin }).where(eq30(items.origin, oldOrigin));
|
|
12406
12557
|
console.log(
|
|
12407
12558
|
chalk84.green(
|
|
12408
12559
|
`Moved ${pluralItems(cnt)} from "${oldOrigin}" to "${newOrigin}".`
|
|
@@ -12819,10 +12970,10 @@ async function start(id) {
|
|
|
12819
12970
|
|
|
12820
12971
|
// src/commands/backlog/stop/index.ts
|
|
12821
12972
|
import chalk96 from "chalk";
|
|
12822
|
-
import { and as
|
|
12973
|
+
import { and as and12, eq as eq31 } from "drizzle-orm";
|
|
12823
12974
|
async function stop() {
|
|
12824
12975
|
const { orm } = await getReady();
|
|
12825
|
-
const stopped = await orm.update(items).set({ status: "todo", currentPhase: 1 }).where(
|
|
12976
|
+
const stopped = await orm.update(items).set({ status: "todo", currentPhase: 1 }).where(and12(eq31(items.status, "in-progress"), eq31(items.origin, getOrigin()))).returning({ id: items.id, name: items.name });
|
|
12826
12977
|
if (stopped.length === 0) {
|
|
12827
12978
|
console.log(chalk96.yellow("No in-progress items to stop."));
|
|
12828
12979
|
return;
|
|
@@ -12939,13 +13090,13 @@ async function findSubtask(id, index3) {
|
|
|
12939
13090
|
}
|
|
12940
13091
|
|
|
12941
13092
|
// src/commands/backlog/updateSubtask.ts
|
|
12942
|
-
import { and as
|
|
13093
|
+
import { and as and13, eq as eq32 } from "drizzle-orm";
|
|
12943
13094
|
async function updateSubtask(orm, itemId2, idx, fields) {
|
|
12944
13095
|
const set = {};
|
|
12945
13096
|
if (fields.title !== void 0) set.title = fields.title;
|
|
12946
13097
|
if (fields.description !== void 0) set.description = fields.description;
|
|
12947
13098
|
if (fields.status !== void 0) set.status = fields.status;
|
|
12948
|
-
const [row] = await orm.update(itemSubtasks).set(set).where(
|
|
13099
|
+
const [row] = await orm.update(itemSubtasks).set(set).where(and13(eq32(itemSubtasks.itemId, itemId2), eq32(itemSubtasks.idx, idx))).returning({ title: itemSubtasks.title });
|
|
12949
13100
|
return row?.title;
|
|
12950
13101
|
}
|
|
12951
13102
|
|
|
@@ -13000,16 +13151,16 @@ async function editSubtask(id, index3, options2) {
|
|
|
13000
13151
|
import chalk102 from "chalk";
|
|
13001
13152
|
|
|
13002
13153
|
// src/commands/backlog/deleteSubtask.ts
|
|
13003
|
-
import { and as
|
|
13154
|
+
import { and as and14, asc as asc9, eq as eq33 } from "drizzle-orm";
|
|
13004
13155
|
async function deleteSubtask(orm, itemId2, idx) {
|
|
13005
|
-
const [row] = await orm.delete(itemSubtasks).where(
|
|
13156
|
+
const [row] = await orm.delete(itemSubtasks).where(and14(eq33(itemSubtasks.itemId, itemId2), eq33(itemSubtasks.idx, idx))).returning({ title: itemSubtasks.title });
|
|
13006
13157
|
if (!row) return void 0;
|
|
13007
|
-
const remaining = await orm.select({ idx: itemSubtasks.idx }).from(itemSubtasks).where(
|
|
13158
|
+
const remaining = await orm.select({ idx: itemSubtasks.idx }).from(itemSubtasks).where(eq33(itemSubtasks.itemId, itemId2)).orderBy(asc9(itemSubtasks.idx));
|
|
13008
13159
|
for (let i = 0; i < remaining.length; i++) {
|
|
13009
13160
|
const oldIdx = remaining[i].idx;
|
|
13010
13161
|
if (oldIdx === i) continue;
|
|
13011
13162
|
await orm.update(itemSubtasks).set({ idx: i }).where(
|
|
13012
|
-
|
|
13163
|
+
and14(eq33(itemSubtasks.itemId, itemId2), eq33(itemSubtasks.idx, oldIdx))
|
|
13013
13164
|
);
|
|
13014
13165
|
}
|
|
13015
13166
|
return row.title;
|
|
@@ -13078,20 +13229,20 @@ function registerSubtaskCommands(cmd) {
|
|
|
13078
13229
|
|
|
13079
13230
|
// src/commands/backlog/movePhase.ts
|
|
13080
13231
|
import chalk104 from "chalk";
|
|
13081
|
-
import { count as count6, eq as
|
|
13232
|
+
import { count as count6, eq as eq36 } from "drizzle-orm";
|
|
13082
13233
|
|
|
13083
13234
|
// src/commands/backlog/reorderPhaseRows.ts
|
|
13084
|
-
import { and as
|
|
13235
|
+
import { and as and16, asc as asc11, eq as eq35 } from "drizzle-orm";
|
|
13085
13236
|
|
|
13086
13237
|
// src/commands/backlog/reindexPhases.ts
|
|
13087
|
-
import { and as
|
|
13238
|
+
import { and as and15, asc as asc10, count as count5, eq as eq34 } from "drizzle-orm";
|
|
13088
13239
|
async function reindexPhases(db, itemId2) {
|
|
13089
|
-
const remaining = await db.select({ idx: planPhases.idx }).from(planPhases).where(
|
|
13240
|
+
const remaining = await db.select({ idx: planPhases.idx }).from(planPhases).where(eq34(planPhases.itemId, itemId2)).orderBy(asc10(planPhases.idx));
|
|
13090
13241
|
for (let i = 0; i < remaining.length; i++) {
|
|
13091
13242
|
const oldIdx = remaining[i].idx;
|
|
13092
13243
|
if (oldIdx === i) continue;
|
|
13093
|
-
await db.update(planTasks).set({ phaseIdx: i }).where(
|
|
13094
|
-
await db.update(planPhases).set({ idx: i }).where(
|
|
13244
|
+
await db.update(planTasks).set({ phaseIdx: i }).where(and15(eq34(planTasks.itemId, itemId2), eq34(planTasks.phaseIdx, oldIdx)));
|
|
13245
|
+
await db.update(planPhases).set({ idx: i }).where(and15(eq34(planPhases.itemId, itemId2), eq34(planPhases.idx, oldIdx)));
|
|
13095
13246
|
}
|
|
13096
13247
|
}
|
|
13097
13248
|
async function adjustCurrentPhase(db, item, removedIdx) {
|
|
@@ -13099,24 +13250,24 @@ async function adjustCurrentPhase(db, item, removedIdx) {
|
|
|
13099
13250
|
if (currentPhase === void 0) return;
|
|
13100
13251
|
const currentIdx = currentPhase - 1;
|
|
13101
13252
|
if (removedIdx < currentIdx) {
|
|
13102
|
-
await db.update(items).set({ currentPhase: currentPhase - 1 }).where(
|
|
13253
|
+
await db.update(items).set({ currentPhase: currentPhase - 1 }).where(eq34(items.id, item.id));
|
|
13103
13254
|
return;
|
|
13104
13255
|
}
|
|
13105
13256
|
if (removedIdx !== currentIdx) return;
|
|
13106
|
-
const [row] = await db.select({ cnt: count5() }).from(planPhases).where(
|
|
13257
|
+
const [row] = await db.select({ cnt: count5() }).from(planPhases).where(eq34(planPhases.itemId, item.id));
|
|
13107
13258
|
const cnt = row?.cnt ?? 0;
|
|
13108
|
-
await db.update(items).set({ currentPhase: cnt === 0 ? null : Math.min(currentPhase, cnt) }).where(
|
|
13259
|
+
await db.update(items).set({ currentPhase: cnt === 0 ? null : Math.min(currentPhase, cnt) }).where(eq34(items.id, item.id));
|
|
13109
13260
|
}
|
|
13110
13261
|
|
|
13111
13262
|
// src/commands/backlog/reorderPhaseRows.ts
|
|
13112
13263
|
async function reorderPhaseRows(orm, itemId2, fromIdx, toIdx) {
|
|
13113
13264
|
await orm.transaction(async (tx) => {
|
|
13114
|
-
const [phaseRow] = await tx.select({ name: planPhases.name, manualChecks: planPhases.manualChecks }).from(planPhases).where(
|
|
13115
|
-
const tasks = await tx.select({ idx: planTasks.idx, task: planTasks.task }).from(planTasks).where(
|
|
13265
|
+
const [phaseRow] = await tx.select({ name: planPhases.name, manualChecks: planPhases.manualChecks }).from(planPhases).where(and16(eq35(planPhases.itemId, itemId2), eq35(planPhases.idx, fromIdx)));
|
|
13266
|
+
const tasks = await tx.select({ idx: planTasks.idx, task: planTasks.task }).from(planTasks).where(and16(eq35(planTasks.itemId, itemId2), eq35(planTasks.phaseIdx, fromIdx))).orderBy(asc11(planTasks.idx));
|
|
13116
13267
|
await tx.delete(planTasks).where(
|
|
13117
|
-
|
|
13268
|
+
and16(eq35(planTasks.itemId, itemId2), eq35(planTasks.phaseIdx, fromIdx))
|
|
13118
13269
|
);
|
|
13119
|
-
await tx.delete(planPhases).where(
|
|
13270
|
+
await tx.delete(planPhases).where(and16(eq35(planPhases.itemId, itemId2), eq35(planPhases.idx, fromIdx)));
|
|
13120
13271
|
await reindexPhases(tx, itemId2);
|
|
13121
13272
|
await shiftPhasesUp(tx, itemId2, toIdx);
|
|
13122
13273
|
await tx.insert(planPhases).values({
|
|
@@ -13157,7 +13308,7 @@ async function movePhase(id, from, to) {
|
|
|
13157
13308
|
if (!found) return;
|
|
13158
13309
|
const { orm, item } = found;
|
|
13159
13310
|
const itemId2 = item.id;
|
|
13160
|
-
const [row] = await orm.select({ cnt: count6() }).from(planPhases).where(
|
|
13311
|
+
const [row] = await orm.select({ cnt: count6() }).from(planPhases).where(eq36(planPhases.itemId, itemId2));
|
|
13161
13312
|
const phaseCount = row?.cnt ?? 0;
|
|
13162
13313
|
const fromIdx = toIndex(from, phaseCount);
|
|
13163
13314
|
if (fromIdx === void 0) return;
|
|
@@ -13173,22 +13324,22 @@ async function movePhase(id, from, to) {
|
|
|
13173
13324
|
import chalk106 from "chalk";
|
|
13174
13325
|
|
|
13175
13326
|
// src/commands/backlog/applyPhaseUpdate.ts
|
|
13176
|
-
import { and as
|
|
13327
|
+
import { and as and17, eq as eq37 } from "drizzle-orm";
|
|
13177
13328
|
async function applyPhaseUpdate(orm, itemId2, phaseIdx, fields) {
|
|
13178
13329
|
await orm.transaction(async (tx) => {
|
|
13179
13330
|
if (fields.name) {
|
|
13180
13331
|
await tx.update(planPhases).set({ name: fields.name }).where(
|
|
13181
|
-
|
|
13332
|
+
and17(eq37(planPhases.itemId, itemId2), eq37(planPhases.idx, phaseIdx))
|
|
13182
13333
|
);
|
|
13183
13334
|
}
|
|
13184
13335
|
if (fields.manualCheck) {
|
|
13185
13336
|
await tx.update(planPhases).set({ manualChecks: JSON.stringify(fields.manualCheck) }).where(
|
|
13186
|
-
|
|
13337
|
+
and17(eq37(planPhases.itemId, itemId2), eq37(planPhases.idx, phaseIdx))
|
|
13187
13338
|
);
|
|
13188
13339
|
}
|
|
13189
13340
|
if (fields.task) {
|
|
13190
13341
|
await tx.delete(planTasks).where(
|
|
13191
|
-
|
|
13342
|
+
and17(eq37(planTasks.itemId, itemId2), eq37(planTasks.phaseIdx, phaseIdx))
|
|
13192
13343
|
);
|
|
13193
13344
|
if (fields.task.length) {
|
|
13194
13345
|
await tx.insert(planTasks).values(
|
|
@@ -13206,14 +13357,14 @@ async function applyPhaseUpdate(orm, itemId2, phaseIdx, fields) {
|
|
|
13206
13357
|
|
|
13207
13358
|
// src/commands/backlog/findPhase.ts
|
|
13208
13359
|
import chalk105 from "chalk";
|
|
13209
|
-
import { and as
|
|
13360
|
+
import { and as and18, count as count7, eq as eq38 } from "drizzle-orm";
|
|
13210
13361
|
async function findPhase(id, phase) {
|
|
13211
13362
|
const found = await findOneItem(id);
|
|
13212
13363
|
if (!found) return void 0;
|
|
13213
13364
|
const { orm, item } = found;
|
|
13214
13365
|
const itemId2 = item.id;
|
|
13215
13366
|
const phaseIdx = Number.parseInt(phase, 10) - 1;
|
|
13216
|
-
const [row] = await orm.select({ cnt: count7() }).from(planPhases).where(
|
|
13367
|
+
const [row] = await orm.select({ cnt: count7() }).from(planPhases).where(and18(eq38(planPhases.itemId, itemId2), eq38(planPhases.idx, phaseIdx)));
|
|
13217
13368
|
if (!row || row.cnt === 0) {
|
|
13218
13369
|
console.log(
|
|
13219
13370
|
chalk105.red(
|
|
@@ -13386,16 +13537,16 @@ function registerUpdatePhaseCommand(cmd) {
|
|
|
13386
13537
|
|
|
13387
13538
|
// src/commands/backlog/removePhase.ts
|
|
13388
13539
|
import chalk107 from "chalk";
|
|
13389
|
-
import { and as
|
|
13540
|
+
import { and as and19, eq as eq39 } from "drizzle-orm";
|
|
13390
13541
|
async function removePhase(id, phase) {
|
|
13391
13542
|
const found = await findPhase(id, phase);
|
|
13392
13543
|
if (!found) return;
|
|
13393
13544
|
const { item, orm, itemId: itemId2, phaseIdx } = found;
|
|
13394
13545
|
await orm.transaction(async (tx) => {
|
|
13395
13546
|
await tx.delete(planTasks).where(
|
|
13396
|
-
|
|
13547
|
+
and19(eq39(planTasks.itemId, itemId2), eq39(planTasks.phaseIdx, phaseIdx))
|
|
13397
13548
|
);
|
|
13398
|
-
await tx.delete(planPhases).where(
|
|
13549
|
+
await tx.delete(planPhases).where(and19(eq39(planPhases.itemId, itemId2), eq39(planPhases.idx, phaseIdx)));
|
|
13399
13550
|
await reindexPhases(tx, itemId2);
|
|
13400
13551
|
await adjustCurrentPhase(tx, item, phaseIdx);
|
|
13401
13552
|
});
|
|
@@ -13408,7 +13559,7 @@ async function removePhase(id, phase) {
|
|
|
13408
13559
|
|
|
13409
13560
|
// src/commands/backlog/update/update.ts
|
|
13410
13561
|
import chalk111 from "chalk";
|
|
13411
|
-
import { eq as
|
|
13562
|
+
import { eq as eq40 } from "drizzle-orm";
|
|
13412
13563
|
|
|
13413
13564
|
// src/commands/backlog/update/buildUpdateValues.ts
|
|
13414
13565
|
import chalk108 from "chalk";
|
|
@@ -13519,7 +13670,7 @@ async function update(id, options2) {
|
|
|
13519
13670
|
if (!built) return;
|
|
13520
13671
|
const { orm } = found;
|
|
13521
13672
|
const itemId2 = found.item.id;
|
|
13522
|
-
await orm.update(items).set(built.set).where(
|
|
13673
|
+
await orm.update(items).set(built.set).where(eq40(items.id, itemId2));
|
|
13523
13674
|
console.log(
|
|
13524
13675
|
chalk111.green(`Updated ${built.fields} on item ${formatItemId(itemId2)}.`)
|
|
13525
13676
|
);
|
|
@@ -17597,9 +17748,9 @@ function registerGithub(program2) {
|
|
|
17597
17748
|
}
|
|
17598
17749
|
|
|
17599
17750
|
// src/commands/handover/countPendingHandovers.ts
|
|
17600
|
-
import { and as
|
|
17751
|
+
import { and as and20, eq as eq41, isNull, sql as sql18 } from "drizzle-orm";
|
|
17601
17752
|
async function countPendingHandovers(orm, origin) {
|
|
17602
|
-
const [row] = await orm.select({ count: sql18`count(*)::int` }).from(handovers).where(
|
|
17753
|
+
const [row] = await orm.select({ count: sql18`count(*)::int` }).from(handovers).where(and20(eq41(handovers.origin, origin), isNull(handovers.recalledAt)));
|
|
17603
17754
|
return row?.count ?? 0;
|
|
17604
17755
|
}
|
|
17605
17756
|
|
|
@@ -17739,13 +17890,13 @@ async function load2(options2 = {}) {
|
|
|
17739
17890
|
}
|
|
17740
17891
|
|
|
17741
17892
|
// src/commands/handover/listPendingHandovers.ts
|
|
17742
|
-
import { and as
|
|
17893
|
+
import { and as and21, desc as desc4, eq as eq42, isNull as isNull2 } from "drizzle-orm";
|
|
17743
17894
|
async function listPendingHandovers(orm, origin) {
|
|
17744
17895
|
return orm.select({
|
|
17745
17896
|
id: handovers.id,
|
|
17746
17897
|
summary: handovers.summary,
|
|
17747
17898
|
createdAt: handovers.createdAt
|
|
17748
|
-
}).from(handovers).where(
|
|
17899
|
+
}).from(handovers).where(and21(eq42(handovers.origin, origin), isNull2(handovers.recalledAt))).orderBy(desc4(handovers.createdAt), desc4(handovers.id));
|
|
17749
17900
|
}
|
|
17750
17901
|
|
|
17751
17902
|
// src/commands/handover/printPendingHandovers.ts
|
|
@@ -17758,17 +17909,17 @@ async function printPendingHandovers() {
|
|
|
17758
17909
|
}
|
|
17759
17910
|
|
|
17760
17911
|
// src/commands/handover/recallHandover.ts
|
|
17761
|
-
import { and as
|
|
17912
|
+
import { and as and22, desc as desc5, eq as eq43, isNull as isNull3 } from "drizzle-orm";
|
|
17762
17913
|
async function recallHandover(orm, origin, id) {
|
|
17763
17914
|
const [row] = await orm.select().from(handovers).where(
|
|
17764
|
-
|
|
17765
|
-
|
|
17915
|
+
and22(
|
|
17916
|
+
eq43(handovers.origin, origin),
|
|
17766
17917
|
isNull3(handovers.recalledAt),
|
|
17767
|
-
...id === void 0 ? [] : [
|
|
17918
|
+
...id === void 0 ? [] : [eq43(handovers.id, id)]
|
|
17768
17919
|
)
|
|
17769
17920
|
).orderBy(desc5(handovers.createdAt), desc5(handovers.id)).limit(1);
|
|
17770
17921
|
if (!row) return void 0;
|
|
17771
|
-
await orm.update(handovers).set({ recalledAt: /* @__PURE__ */ new Date() }).where(
|
|
17922
|
+
await orm.update(handovers).set({ recalledAt: /* @__PURE__ */ new Date() }).where(eq43(handovers.id, row.id));
|
|
17772
17923
|
return row.content;
|
|
17773
17924
|
}
|
|
17774
17925
|
|
|
@@ -19784,20 +19935,20 @@ function resolveThread(threadId) {
|
|
|
19784
19935
|
}
|
|
19785
19936
|
}
|
|
19786
19937
|
function requireCache(prNumber) {
|
|
19787
|
-
const
|
|
19788
|
-
if (!
|
|
19938
|
+
const cache5 = loadCommentsCache(prNumber);
|
|
19939
|
+
if (!cache5) {
|
|
19789
19940
|
console.error(
|
|
19790
19941
|
`Error: No cached comments found for PR #${prNumber}. Run "assist prs list-comments" first.`
|
|
19791
19942
|
);
|
|
19792
19943
|
process.exit(1);
|
|
19793
19944
|
}
|
|
19794
|
-
return
|
|
19945
|
+
return cache5;
|
|
19795
19946
|
}
|
|
19796
19947
|
function findLineComment(comments3, commentId) {
|
|
19797
19948
|
return comments3.find((c) => c.type === "line" && c.id === commentId);
|
|
19798
19949
|
}
|
|
19799
|
-
function requireLineComment(
|
|
19800
|
-
const comment3 = findLineComment(
|
|
19950
|
+
function requireLineComment(cache5, commentId) {
|
|
19951
|
+
const comment3 = findLineComment(cache5.comments, commentId);
|
|
19801
19952
|
if (!comment3 || comment3.type !== "line" || !comment3.threadId) {
|
|
19802
19953
|
console.error(
|
|
19803
19954
|
`Error: Comment #${commentId} not found or has no thread ID.`
|
|
@@ -19806,8 +19957,8 @@ function requireLineComment(cache4, commentId) {
|
|
|
19806
19957
|
}
|
|
19807
19958
|
return comment3;
|
|
19808
19959
|
}
|
|
19809
|
-
function cleanupCacheIfDone(
|
|
19810
|
-
const hasRemaining =
|
|
19960
|
+
function cleanupCacheIfDone(cache5, prNumber, commentId) {
|
|
19961
|
+
const hasRemaining = cache5.comments.some(
|
|
19811
19962
|
(c) => c.type === "line" && c.id !== commentId
|
|
19812
19963
|
);
|
|
19813
19964
|
if (!hasRemaining) deleteCommentsCache(prNumber);
|
|
@@ -19815,13 +19966,13 @@ function cleanupCacheIfDone(cache4, prNumber, commentId) {
|
|
|
19815
19966
|
function resolveCommentWithReply(commentId, message2) {
|
|
19816
19967
|
const prNumber = getCurrentPrNumber();
|
|
19817
19968
|
const { org, repo } = getRepoInfo();
|
|
19818
|
-
const
|
|
19819
|
-
const comment3 = requireLineComment(
|
|
19969
|
+
const cache5 = requireCache(prNumber);
|
|
19970
|
+
const comment3 = requireLineComment(cache5, commentId);
|
|
19820
19971
|
replyToComment(org, repo, prNumber, commentId, message2);
|
|
19821
19972
|
console.log("Reply posted successfully.");
|
|
19822
19973
|
resolveThread(comment3.threadId);
|
|
19823
19974
|
console.log("Thread resolved successfully.");
|
|
19824
|
-
cleanupCacheIfDone(
|
|
19975
|
+
cleanupCacheIfDone(cache5, prNumber, commentId);
|
|
19825
19976
|
}
|
|
19826
19977
|
|
|
19827
19978
|
// src/commands/prs/fixed.ts
|
|
@@ -28054,10 +28205,10 @@ function applyReviewPause(session, activity2) {
|
|
|
28054
28205
|
}
|
|
28055
28206
|
|
|
28056
28207
|
// src/shared/db/getPhaseActiveMs.ts
|
|
28057
|
-
import { and as
|
|
28208
|
+
import { and as and23, eq as eq44 } from "drizzle-orm";
|
|
28058
28209
|
async function getPhaseActiveMs(db, itemId2, phaseIdx) {
|
|
28059
28210
|
const [row] = await db.select({ activeMs: phaseUsage.activeMs }).from(phaseUsage).where(
|
|
28060
|
-
|
|
28211
|
+
and23(eq44(phaseUsage.itemId, itemId2), eq44(phaseUsage.phaseIdx, phaseIdx))
|
|
28061
28212
|
);
|
|
28062
28213
|
return row?.activeMs ?? 0;
|
|
28063
28214
|
}
|
|
@@ -28568,17 +28719,17 @@ async function recordPhaseTranscriptUsage(db, itemId2, phaseIdx, responses) {
|
|
|
28568
28719
|
}
|
|
28569
28720
|
|
|
28570
28721
|
// src/shared/db/recordWindowTokens.ts
|
|
28571
|
-
import { and as
|
|
28722
|
+
import { and as and24, eq as eq45, sql as sql24 } from "drizzle-orm";
|
|
28572
28723
|
async function recordWindowTokens(db, window, resetsAt, tokensUp, tokensDown) {
|
|
28573
28724
|
if (tokensUp <= 0 && tokensDown <= 0) return;
|
|
28574
28725
|
await db.update(usagePeaks).set({
|
|
28575
28726
|
tokensUp: sql24`${usagePeaks.tokensUp} + ${tokensUp}`,
|
|
28576
28727
|
tokensDown: sql24`${usagePeaks.tokensDown} + ${tokensDown}`
|
|
28577
28728
|
}).where(
|
|
28578
|
-
|
|
28579
|
-
|
|
28580
|
-
|
|
28581
|
-
|
|
28729
|
+
and24(
|
|
28730
|
+
eq45(usagePeaks.window, window),
|
|
28731
|
+
eq45(usagePeaks.resetsAt, resetsAt),
|
|
28732
|
+
eq45(usagePeaks.segment, 0)
|
|
28582
28733
|
)
|
|
28583
28734
|
);
|
|
28584
28735
|
}
|