@staff0rd/assist 0.470.0 → 0.471.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/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.470.0",
9
+ version: "0.471.0",
10
10
  type: "module",
11
11
  main: "dist/index.js",
12
12
  bin: {
@@ -9046,28 +9046,6 @@ async function handleItemRoute(req, res, pathname) {
9046
9046
  return false;
9047
9047
  }
9048
9048
 
9049
- // src/commands/sessions/web/execGit.ts
9050
- import { execFile as execFile3 } from "child_process";
9051
- import { promisify as promisify2 } from "util";
9052
- var execFileAsync2 = promisify2(execFile3);
9053
- async function execGit(cwd, args, opts = {}) {
9054
- const { maxBuffer, allowFailure } = opts;
9055
- const { file, argv } = /^[A-Za-z]:[\\/]/.test(cwd) ? { file: "git.exe", argv: ["-C", cwd, ...args] } : { file: "git", argv: args };
9056
- try {
9057
- const { stdout } = await execFileAsync2(file, argv, {
9058
- encoding: "utf8",
9059
- ...maxBuffer ? { maxBuffer } : {},
9060
- ...file === "git" ? { cwd } : {}
9061
- });
9062
- return stdout;
9063
- } catch (error) {
9064
- if (allowFailure && error && typeof error === "object" && "stdout" in error) {
9065
- return String(error.stdout);
9066
- }
9067
- throw error;
9068
- }
9069
- }
9070
-
9071
9049
  // src/commands/sessions/web/getCwdParam.ts
9072
9050
  function getCwdParam(req, res) {
9073
9051
  const url = new URL(req.url ?? "/", "http://localhost");
@@ -9085,6 +9063,31 @@ function getSessionParam(req) {
9085
9063
  return url.searchParams.get("session") ?? void 0;
9086
9064
  }
9087
9065
 
9066
+ // src/commands/sessions/web/windowsCwdToWslPath.ts
9067
+ function windowsCwdToWslPath(cwd) {
9068
+ const match = /^([A-Za-z]):[\\/](.*)$/.exec(cwd);
9069
+ if (!match) return cwd;
9070
+ const drive = match[1].toLowerCase();
9071
+ const rest = match[2].replace(/\\/g, "/");
9072
+ return `/mnt/${drive}/${rest}`;
9073
+ }
9074
+
9075
+ // src/commands/sessions/web/toGitCwd.ts
9076
+ function toGitCwd(cwd) {
9077
+ return detectPlatform() === "wsl" ? windowsCwdToWslPath(cwd) : cwd;
9078
+ }
9079
+
9080
+ // src/commands/sessions/web/includesCommittedChanges.ts
9081
+ function includesCommittedChanges(cwd) {
9082
+ try {
9083
+ return Boolean(
9084
+ loadConfigFrom(toGitCwd(cwd)).sessions?.includeCommittedChanges
9085
+ );
9086
+ } catch {
9087
+ return false;
9088
+ }
9089
+ }
9090
+
9088
9091
  // src/shared/db/findItemBySessionId.ts
9089
9092
  import { asc as asc6, eq as eq16 } from "drizzle-orm";
9090
9093
  async function findItemBySessionId(db, claudeSessionId) {
@@ -9121,15 +9124,53 @@ async function itemCommits(sessionId) {
9121
9124
  }
9122
9125
  }
9123
9126
 
9127
+ // src/commands/sessions/web/itemScopeCommits.ts
9128
+ async function itemScopeCommits(cwd, sessionId) {
9129
+ if (!sessionId || !includesCommittedChanges(cwd)) return [];
9130
+ return itemCommits(sessionId);
9131
+ }
9132
+
9133
+ // src/commands/sessions/web/resolveDiffScope.ts
9134
+ async function resolveDiffScope(cwd, sessionId, scope) {
9135
+ if (!scope || scope === "all") return { kind: "all" };
9136
+ if (scope === "uncommitted") return { kind: "uncommitted" };
9137
+ const commits2 = await itemScopeCommits(cwd, sessionId);
9138
+ if (!commits2.some((commit2) => commit2.sha === scope)) return void 0;
9139
+ return { kind: "commit", sha: scope };
9140
+ }
9141
+
9142
+ // src/commands/sessions/web/execGit.ts
9143
+ import { execFile as execFile3 } from "child_process";
9144
+ import { promisify as promisify2 } from "util";
9145
+ var execFileAsync2 = promisify2(execFile3);
9146
+ async function execGit(cwd, args, opts = {}) {
9147
+ const { maxBuffer, allowFailure } = opts;
9148
+ const { file, argv } = /^[A-Za-z]:[\\/]/.test(cwd) ? { file: "git.exe", argv: ["-C", cwd, ...args] } : { file: "git", argv: args };
9149
+ try {
9150
+ const { stdout } = await execFileAsync2(file, argv, {
9151
+ encoding: "utf8",
9152
+ ...maxBuffer ? { maxBuffer } : {},
9153
+ ...file === "git" ? { cwd } : {}
9154
+ });
9155
+ return stdout;
9156
+ } catch (error) {
9157
+ if (allowFailure && error && typeof error === "object" && "stdout" in error) {
9158
+ return String(error.stdout);
9159
+ }
9160
+ throw error;
9161
+ }
9162
+ }
9163
+
9124
9164
  // src/commands/sessions/web/resolveCommit.ts
9125
9165
  var GIT_EMPTY_TREE_HASH = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
9126
- async function resolveCommit(cwd, sha) {
9166
+ async function commitBase(cwd, sha) {
9127
9167
  if (!await commitExists(cwd, sha)) return void 0;
9128
- const parent = await parentOf(cwd, sha);
9129
- return {
9130
- base: parent ?? GIT_EMPTY_TREE_HASH,
9131
- paths: await commitPaths(cwd, sha)
9132
- };
9168
+ return await parentOf(cwd, sha) ?? GIT_EMPTY_TREE_HASH;
9169
+ }
9170
+ async function resolveCommit(cwd, sha) {
9171
+ const base = await commitBase(cwd, sha);
9172
+ if (!base) return void 0;
9173
+ return { base, paths: await commitPaths(cwd, sha) };
9133
9174
  }
9134
9175
  async function commitExists(cwd, sha) {
9135
9176
  try {
@@ -9198,20 +9239,6 @@ async function loadCommittedPaths(cwd, sessionId) {
9198
9239
  return { commits: commits2, bases };
9199
9240
  }
9200
9241
 
9201
- // src/commands/sessions/web/windowsCwdToWslPath.ts
9202
- function windowsCwdToWslPath(cwd) {
9203
- const match = /^([A-Za-z]):[\\/](.*)$/.exec(cwd);
9204
- if (!match) return cwd;
9205
- const drive = match[1].toLowerCase();
9206
- const rest = match[2].replace(/\\/g, "/");
9207
- return `/mnt/${drive}/${rest}`;
9208
- }
9209
-
9210
- // src/commands/sessions/web/toGitCwd.ts
9211
- function toGitCwd(cwd) {
9212
- return detectPlatform() === "wsl" ? windowsCwdToWslPath(cwd) : cwd;
9213
- }
9214
-
9215
9242
  // src/commands/sessions/web/itemChangeSet.ts
9216
9243
  async function itemChangeSet(cwd, sessionId) {
9217
9244
  if (!sessionId || !includesCommittedChanges(cwd)) return void 0;
@@ -9222,15 +9249,6 @@ async function itemChangeSet(cwd, sessionId) {
9222
9249
  if (dirty.length > 0) groups.push({ base: "HEAD", paths: dirty });
9223
9250
  return { commits: commits2, groups };
9224
9251
  }
9225
- function includesCommittedChanges(cwd) {
9226
- try {
9227
- return Boolean(
9228
- loadConfigFrom(toGitCwd(cwd)).sessions?.includeCommittedChanges
9229
- );
9230
- } catch {
9231
- return false;
9232
- }
9233
- }
9234
9252
  function groupByBase(bases) {
9235
9253
  const groups = /* @__PURE__ */ new Map();
9236
9254
  for (const [path71, base] of bases) {
@@ -9245,8 +9263,13 @@ async function dirtyPaths(cwd, bases) {
9245
9263
  return output.split("\n").filter((path71) => path71 && !bases.has(path71)).sort();
9246
9264
  }
9247
9265
 
9248
- // src/commands/sessions/web/diff.ts
9266
+ // src/commands/sessions/web/scopedDiff.ts
9249
9267
  var MAX_DIFF_BYTES = 50 * 1024 * 1024;
9268
+ async function scopedDiff(cwd, session, scope) {
9269
+ if (scope.kind === "commit") return commitDiff(cwd, scope.sha);
9270
+ const tracked = scope.kind === "uncommitted" ? await workingTreeDiff(cwd) : await trackedDiff(cwd, session);
9271
+ return tracked + await untrackedDiff(cwd);
9272
+ }
9250
9273
  async function untrackedFileDiff(cwd, path71) {
9251
9274
  return execGit(cwd, ["diff", "--no-index", "--", "/dev/null", path71], {
9252
9275
  maxBuffer: MAX_DIFF_BYTES,
@@ -9275,25 +9298,56 @@ async function groupedDiff(cwd, groups) {
9275
9298
  );
9276
9299
  return diffs.join("");
9277
9300
  }
9301
+ async function workingTreeDiff(cwd) {
9302
+ return execGit(cwd, ["diff", "HEAD"], { maxBuffer: MAX_DIFF_BYTES });
9303
+ }
9278
9304
  async function trackedDiff(cwd, session) {
9279
9305
  const changeSet = await itemChangeSet(cwd, session);
9280
9306
  if (changeSet) return groupedDiff(cwd, changeSet.groups);
9281
- return execGit(cwd, ["diff", "HEAD"], { maxBuffer: MAX_DIFF_BYTES });
9307
+ return workingTreeDiff(cwd);
9308
+ }
9309
+ async function commitDiff(cwd, sha) {
9310
+ const base = await commitBase(cwd, sha);
9311
+ if (!base) return "";
9312
+ return execGit(cwd, ["diff", base, sha], { maxBuffer: MAX_DIFF_BYTES });
9313
+ }
9314
+
9315
+ // src/commands/sessions/web/diff.ts
9316
+ function getScopeParam(req) {
9317
+ const url = new URL(req.url ?? "/", "http://localhost");
9318
+ return url.searchParams.get("scope") ?? void 0;
9282
9319
  }
9283
9320
  async function diff2(req, res) {
9284
9321
  const cwd = getCwdParam(req, res);
9285
9322
  if (!cwd) return;
9323
+ const session = getSessionParam(req);
9286
9324
  try {
9287
- const tracked = await trackedDiff(cwd, getSessionParam(req));
9288
- const untracked = await untrackedDiff(cwd);
9325
+ const scope = await resolveDiffScope(cwd, session, getScopeParam(req));
9326
+ if (!scope) {
9327
+ respondJson(res, 400, { error: "Invalid scope" });
9328
+ return;
9329
+ }
9330
+ const body = await scopedDiff(cwd, session, scope);
9289
9331
  res.writeHead(200, { "Content-Type": "text/plain; charset=utf-8" });
9290
- res.end(tracked + untracked);
9332
+ res.end(body);
9291
9333
  } catch {
9292
9334
  res.writeHead(500, { "Content-Type": "text/plain; charset=utf-8" });
9293
9335
  res.end("");
9294
9336
  }
9295
9337
  }
9296
9338
 
9339
+ // src/commands/sessions/web/diffScopes.ts
9340
+ async function diffScopes(req, res) {
9341
+ const cwd = getCwdParam(req, res);
9342
+ if (!cwd) return;
9343
+ try {
9344
+ const commits2 = await itemScopeCommits(cwd, getSessionParam(req));
9345
+ respondJson(res, 200, { commits: commits2 });
9346
+ } catch {
9347
+ respondJson(res, 200, { commits: [] });
9348
+ }
9349
+ }
9350
+
9297
9351
  // src/commands/sessions/web/fileContent.ts
9298
9352
  import { readFile, stat as stat2 } from "fs/promises";
9299
9353
  import { isAbsolute, relative as relative2, resolve as resolve9 } from "path";
@@ -10937,6 +10991,7 @@ var routes2 = {
10937
10991
  "GET /api/github-url": githubUrl,
10938
10992
  "GET /api/git-status": gitStatus,
10939
10993
  "GET /api/diff": diff2,
10994
+ "GET /api/diff-scopes": diffScopes,
10940
10995
  "GET /api/file": fileContent,
10941
10996
  "GET /api/files": listFiles,
10942
10997
  "GET /api/jira-site": jiraSite,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@staff0rd/assist",
3
- "version": "0.470.0",
3
+ "version": "0.471.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "bin": {