@staff0rd/assist 0.484.2 → 0.485.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 +372 -372
- package/dist/index.js +99 -32
- 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.485.0",
|
|
10
10
|
type: "module",
|
|
11
11
|
main: "dist/index.js",
|
|
12
12
|
bin: {
|
|
@@ -9089,6 +9089,28 @@ function getSessionParam(req) {
|
|
|
9089
9089
|
return url.searchParams.get("session") ?? void 0;
|
|
9090
9090
|
}
|
|
9091
9091
|
|
|
9092
|
+
// src/commands/sessions/web/execGit.ts
|
|
9093
|
+
import { execFile as execFile3 } from "child_process";
|
|
9094
|
+
import { promisify as promisify2 } from "util";
|
|
9095
|
+
var execFileAsync2 = promisify2(execFile3);
|
|
9096
|
+
async function execGit(cwd, args, opts = {}) {
|
|
9097
|
+
const { maxBuffer, allowFailure } = opts;
|
|
9098
|
+
const { file, argv } = /^[A-Za-z]:[\\/]/.test(cwd) ? { file: "git.exe", argv: ["-C", cwd, ...args] } : { file: "git", argv: args };
|
|
9099
|
+
try {
|
|
9100
|
+
const { stdout } = await execFileAsync2(file, argv, {
|
|
9101
|
+
encoding: "utf8",
|
|
9102
|
+
...maxBuffer ? { maxBuffer } : {},
|
|
9103
|
+
...file === "git" ? { cwd } : {}
|
|
9104
|
+
});
|
|
9105
|
+
return stdout;
|
|
9106
|
+
} catch (error) {
|
|
9107
|
+
if (allowFailure && error && typeof error === "object" && "stdout" in error) {
|
|
9108
|
+
return String(error.stdout);
|
|
9109
|
+
}
|
|
9110
|
+
throw error;
|
|
9111
|
+
}
|
|
9112
|
+
}
|
|
9113
|
+
|
|
9092
9114
|
// src/commands/sessions/web/windowsCwdToWslPath.ts
|
|
9093
9115
|
function windowsCwdToWslPath(cwd) {
|
|
9094
9116
|
const match = /^([A-Za-z]):[\\/](.*)$/.exec(cwd);
|
|
@@ -9103,6 +9125,49 @@ function toGitCwd(cwd) {
|
|
|
9103
9125
|
return detectPlatform() === "wsl" ? windowsCwdToWslPath(cwd) : cwd;
|
|
9104
9126
|
}
|
|
9105
9127
|
|
|
9128
|
+
// src/commands/sessions/web/defaultBranchRef.ts
|
|
9129
|
+
var ORIGIN_HEAD_REF = "refs/remotes/origin/HEAD";
|
|
9130
|
+
var ORIGIN_REF_PREFIX = "refs/remotes/origin/";
|
|
9131
|
+
function configuredDefaultBranch(cwd) {
|
|
9132
|
+
try {
|
|
9133
|
+
return loadConfigFrom(toGitCwd(cwd)).branch?.defaultBranch;
|
|
9134
|
+
} catch {
|
|
9135
|
+
return void 0;
|
|
9136
|
+
}
|
|
9137
|
+
}
|
|
9138
|
+
async function originHeadBranch(cwd) {
|
|
9139
|
+
try {
|
|
9140
|
+
const ref = (await execGit(cwd, ["symbolic-ref", "--quiet", ORIGIN_HEAD_REF])).trim();
|
|
9141
|
+
if (!ref.startsWith(ORIGIN_REF_PREFIX)) return void 0;
|
|
9142
|
+
return ref.slice(ORIGIN_REF_PREFIX.length) || void 0;
|
|
9143
|
+
} catch {
|
|
9144
|
+
return void 0;
|
|
9145
|
+
}
|
|
9146
|
+
}
|
|
9147
|
+
async function defaultBranchRef(cwd) {
|
|
9148
|
+
const branch2 = configuredDefaultBranch(cwd) ?? await originHeadBranch(cwd);
|
|
9149
|
+
if (!branch2) return void 0;
|
|
9150
|
+
const ref = `origin/${branch2}`;
|
|
9151
|
+
try {
|
|
9152
|
+
await execGit(cwd, ["rev-parse", "--verify", "--quiet", `${ref}^{commit}`]);
|
|
9153
|
+
return ref;
|
|
9154
|
+
} catch {
|
|
9155
|
+
return void 0;
|
|
9156
|
+
}
|
|
9157
|
+
}
|
|
9158
|
+
|
|
9159
|
+
// src/commands/sessions/web/branchDiffBase.ts
|
|
9160
|
+
async function branchDiffBase(cwd) {
|
|
9161
|
+
const ref = await defaultBranchRef(cwd);
|
|
9162
|
+
if (!ref) return void 0;
|
|
9163
|
+
try {
|
|
9164
|
+
const base = await execGit(cwd, ["merge-base", ref, "HEAD"]);
|
|
9165
|
+
return base.trim() || void 0;
|
|
9166
|
+
} catch {
|
|
9167
|
+
return void 0;
|
|
9168
|
+
}
|
|
9169
|
+
}
|
|
9170
|
+
|
|
9106
9171
|
// src/commands/sessions/web/includesCommittedChanges.ts
|
|
9107
9172
|
function includesCommittedChanges(cwd) {
|
|
9108
9173
|
try {
|
|
@@ -9158,33 +9223,15 @@ async function itemScopeCommits(cwd, sessionId) {
|
|
|
9158
9223
|
async function resolveDiffScope(cwd, sessionId, scope) {
|
|
9159
9224
|
if (!scope || scope === "all") return { kind: "all" };
|
|
9160
9225
|
if (scope === "uncommitted") return { kind: "uncommitted" };
|
|
9226
|
+
if (scope === "branch") {
|
|
9227
|
+
const base = await branchDiffBase(cwd);
|
|
9228
|
+
return base ? { kind: "branch", base } : void 0;
|
|
9229
|
+
}
|
|
9161
9230
|
const commits2 = await itemScopeCommits(cwd, sessionId);
|
|
9162
9231
|
if (!commits2.some((commit2) => commit2.sha === scope)) return void 0;
|
|
9163
9232
|
return { kind: "commit", sha: scope };
|
|
9164
9233
|
}
|
|
9165
9234
|
|
|
9166
|
-
// src/commands/sessions/web/execGit.ts
|
|
9167
|
-
import { execFile as execFile3 } from "child_process";
|
|
9168
|
-
import { promisify as promisify2 } from "util";
|
|
9169
|
-
var execFileAsync2 = promisify2(execFile3);
|
|
9170
|
-
async function execGit(cwd, args, opts = {}) {
|
|
9171
|
-
const { maxBuffer, allowFailure } = opts;
|
|
9172
|
-
const { file, argv } = /^[A-Za-z]:[\\/]/.test(cwd) ? { file: "git.exe", argv: ["-C", cwd, ...args] } : { file: "git", argv: args };
|
|
9173
|
-
try {
|
|
9174
|
-
const { stdout } = await execFileAsync2(file, argv, {
|
|
9175
|
-
encoding: "utf8",
|
|
9176
|
-
...maxBuffer ? { maxBuffer } : {},
|
|
9177
|
-
...file === "git" ? { cwd } : {}
|
|
9178
|
-
});
|
|
9179
|
-
return stdout;
|
|
9180
|
-
} catch (error) {
|
|
9181
|
-
if (allowFailure && error && typeof error === "object" && "stdout" in error) {
|
|
9182
|
-
return String(error.stdout);
|
|
9183
|
-
}
|
|
9184
|
-
throw error;
|
|
9185
|
-
}
|
|
9186
|
-
}
|
|
9187
|
-
|
|
9188
9235
|
// src/commands/sessions/web/resolveCommit.ts
|
|
9189
9236
|
var GIT_EMPTY_TREE_HASH = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
|
|
9190
9237
|
async function commitBase(cwd, sha) {
|
|
@@ -9291,8 +9338,7 @@ async function dirtyPaths(cwd, bases) {
|
|
|
9291
9338
|
var MAX_DIFF_BYTES = 50 * 1024 * 1024;
|
|
9292
9339
|
async function scopedDiff(cwd, session, scope) {
|
|
9293
9340
|
if (scope.kind === "commit") return commitDiff(cwd, scope.sha);
|
|
9294
|
-
|
|
9295
|
-
return tracked + await untrackedDiff(cwd);
|
|
9341
|
+
return await trackedScopeDiff(cwd, session, scope) + await untrackedDiff(cwd);
|
|
9296
9342
|
}
|
|
9297
9343
|
async function untrackedFileDiff(cwd, path71) {
|
|
9298
9344
|
return execGit(cwd, ["diff", "--no-index", "--", "/dev/null", path71], {
|
|
@@ -9322,8 +9368,16 @@ async function groupedDiff(cwd, groups) {
|
|
|
9322
9368
|
);
|
|
9323
9369
|
return diffs.join("");
|
|
9324
9370
|
}
|
|
9371
|
+
async function baseDiff(cwd, base) {
|
|
9372
|
+
return execGit(cwd, ["diff", base], { maxBuffer: MAX_DIFF_BYTES });
|
|
9373
|
+
}
|
|
9325
9374
|
async function workingTreeDiff(cwd) {
|
|
9326
|
-
return
|
|
9375
|
+
return baseDiff(cwd, "HEAD");
|
|
9376
|
+
}
|
|
9377
|
+
async function trackedScopeDiff(cwd, session, scope) {
|
|
9378
|
+
if (scope.kind === "branch") return baseDiff(cwd, scope.base);
|
|
9379
|
+
if (scope.kind === "uncommitted") return workingTreeDiff(cwd);
|
|
9380
|
+
return trackedDiff(cwd, session);
|
|
9327
9381
|
}
|
|
9328
9382
|
async function trackedDiff(cwd, session) {
|
|
9329
9383
|
const changeSet = await itemChangeSet(cwd, session);
|
|
@@ -9361,16 +9415,29 @@ async function diff2(req, res) {
|
|
|
9361
9415
|
}
|
|
9362
9416
|
|
|
9363
9417
|
// src/commands/sessions/web/diffScopes.ts
|
|
9364
|
-
async function
|
|
9365
|
-
const cwd = getCwdParam(req, res);
|
|
9366
|
-
if (!cwd) return;
|
|
9418
|
+
async function scopeCommits(cwd, sessionId) {
|
|
9367
9419
|
try {
|
|
9368
|
-
|
|
9369
|
-
respondJson(res, 200, { commits: commits2 });
|
|
9420
|
+
return await itemScopeCommits(cwd, sessionId);
|
|
9370
9421
|
} catch {
|
|
9371
|
-
|
|
9422
|
+
return [];
|
|
9372
9423
|
}
|
|
9373
9424
|
}
|
|
9425
|
+
async function branchBase(cwd) {
|
|
9426
|
+
try {
|
|
9427
|
+
return await defaultBranchRef(cwd) ?? null;
|
|
9428
|
+
} catch {
|
|
9429
|
+
return null;
|
|
9430
|
+
}
|
|
9431
|
+
}
|
|
9432
|
+
async function diffScopes(req, res) {
|
|
9433
|
+
const cwd = getCwdParam(req, res);
|
|
9434
|
+
if (!cwd) return;
|
|
9435
|
+
const [commits2, base] = await Promise.all([
|
|
9436
|
+
scopeCommits(cwd, getSessionParam(req)),
|
|
9437
|
+
branchBase(cwd)
|
|
9438
|
+
]);
|
|
9439
|
+
respondJson(res, 200, { commits: commits2, branchBase: base });
|
|
9440
|
+
}
|
|
9374
9441
|
|
|
9375
9442
|
// src/commands/sessions/web/fileContent.ts
|
|
9376
9443
|
import { readFile, stat as stat2 } from "fs/promises";
|