@super-one/cli 0.68.0-alpha → 0.68.0-alpha.1
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/MANIFEST.json +2 -2
- package/lib/cli.mjs +394 -3
- package/package.json +1 -1
package/MANIFEST.json
CHANGED
package/lib/cli.mjs
CHANGED
|
@@ -14752,10 +14752,126 @@ var init_capability_prompt_tags = __esm({
|
|
|
14752
14752
|
}
|
|
14753
14753
|
});
|
|
14754
14754
|
|
|
14755
|
+
// ../../packages/shared/src/fuzzy-match.ts
|
|
14756
|
+
function forwardMatchFrom(queryLower, textLower, start) {
|
|
14757
|
+
const indices = [];
|
|
14758
|
+
let qi2 = 0;
|
|
14759
|
+
for (let pi2 = start; pi2 < textLower.length && qi2 < queryLower.length; pi2++) {
|
|
14760
|
+
if (textLower[pi2] === queryLower[qi2]) {
|
|
14761
|
+
indices.push(pi2);
|
|
14762
|
+
qi2++;
|
|
14763
|
+
}
|
|
14764
|
+
}
|
|
14765
|
+
return indices;
|
|
14766
|
+
}
|
|
14767
|
+
function scoreIndices(indices, query, text2) {
|
|
14768
|
+
let score = 0;
|
|
14769
|
+
for (let i = 0; i < indices.length; i++) {
|
|
14770
|
+
const idx = indices[i];
|
|
14771
|
+
if (i > 0 && idx === indices[i - 1] + 1) score += 5;
|
|
14772
|
+
if (text2[idx] === query[i]) score += 1;
|
|
14773
|
+
}
|
|
14774
|
+
if (indices.length > 0 && indices[0] === 0) score += 10;
|
|
14775
|
+
score -= text2.length * 0.1;
|
|
14776
|
+
return score;
|
|
14777
|
+
}
|
|
14778
|
+
function fuzzyMatch(query, text2) {
|
|
14779
|
+
if (!query) return { match: true, score: 0, indices: [] };
|
|
14780
|
+
const queryLower = query.toLowerCase();
|
|
14781
|
+
const textLower = text2.toLowerCase();
|
|
14782
|
+
const fwd = forwardMatchFrom(queryLower, textLower, 0);
|
|
14783
|
+
if (fwd.length < queryLower.length) return { match: false, score: 0, indices: [] };
|
|
14784
|
+
let bestIndices = fwd;
|
|
14785
|
+
let bestScore = scoreIndices(fwd, query, text2);
|
|
14786
|
+
const startPositions = /* @__PURE__ */ new Set();
|
|
14787
|
+
for (let pi2 = 1; pi2 < textLower.length; pi2++) {
|
|
14788
|
+
if (textLower[pi2] === queryLower[0]) startPositions.add(pi2);
|
|
14789
|
+
}
|
|
14790
|
+
for (const start of startPositions) {
|
|
14791
|
+
const candidate = forwardMatchFrom(queryLower, textLower, start);
|
|
14792
|
+
if (candidate.length < queryLower.length) continue;
|
|
14793
|
+
const s4 = scoreIndices(candidate, query, text2);
|
|
14794
|
+
if (s4 > bestScore) {
|
|
14795
|
+
bestScore = s4;
|
|
14796
|
+
bestIndices = candidate;
|
|
14797
|
+
}
|
|
14798
|
+
}
|
|
14799
|
+
return { match: true, score: bestScore, indices: bestIndices };
|
|
14800
|
+
}
|
|
14801
|
+
var init_fuzzy_match = __esm({
|
|
14802
|
+
"../../packages/shared/src/fuzzy-match.ts"() {
|
|
14803
|
+
"use strict";
|
|
14804
|
+
}
|
|
14805
|
+
});
|
|
14806
|
+
|
|
14807
|
+
// ../../packages/shared/src/git-mention-query.ts
|
|
14808
|
+
function gitMentionPortalOf(kind) {
|
|
14809
|
+
return GIT_MENTION_PORTALS.gh.includes(kind) ? "gh" : "git";
|
|
14810
|
+
}
|
|
14811
|
+
function isGitHubRefKind(kind) {
|
|
14812
|
+
return gitMentionPortalOf(kind) === "gh";
|
|
14813
|
+
}
|
|
14814
|
+
function isGitMentionRefKind(value) {
|
|
14815
|
+
return typeof value === "string" && GIT_MENTION_REF_KINDS.includes(value);
|
|
14816
|
+
}
|
|
14817
|
+
function gitRefNameMatches(text2, query) {
|
|
14818
|
+
const q2 = query.trim();
|
|
14819
|
+
if (!q2) return true;
|
|
14820
|
+
return fuzzyMatch(q2, text2).match;
|
|
14821
|
+
}
|
|
14822
|
+
function titledKind(kind) {
|
|
14823
|
+
return kind === "commit" || isGitHubRefKind(kind);
|
|
14824
|
+
}
|
|
14825
|
+
function gitRefMatches(ref, query) {
|
|
14826
|
+
return gitRefNameMatches(titledKind(ref.kind) ? ref.detail : ref.label, query);
|
|
14827
|
+
}
|
|
14828
|
+
var GIT_MENTION_REF_KINDS, GIT_MENTION_PORTALS, GIT_MENTION_KEYWORD, GH_MENTION_KEYWORD, GIT_MENTION_NAV_PREFIX, GH_MENTION_NAV_PREFIX, GIT_HOST_PROVIDERS, GIT_MENTION_REF_LIMIT;
|
|
14829
|
+
var init_git_mention_query = __esm({
|
|
14830
|
+
"../../packages/shared/src/git-mention-query.ts"() {
|
|
14831
|
+
"use strict";
|
|
14832
|
+
init_fuzzy_match();
|
|
14833
|
+
GIT_MENTION_REF_KINDS = ["branch", "commit", "worktree", "tag", "issue", "pr"];
|
|
14834
|
+
GIT_MENTION_PORTALS = {
|
|
14835
|
+
git: ["branch", "commit", "worktree", "tag"],
|
|
14836
|
+
gh: ["issue", "pr"]
|
|
14837
|
+
};
|
|
14838
|
+
GIT_MENTION_KEYWORD = "git";
|
|
14839
|
+
GH_MENTION_KEYWORD = "gh";
|
|
14840
|
+
GIT_MENTION_NAV_PREFIX = `${GIT_MENTION_KEYWORD} `;
|
|
14841
|
+
GH_MENTION_NAV_PREFIX = `${GH_MENTION_KEYWORD} `;
|
|
14842
|
+
GIT_HOST_PROVIDERS = ["github"];
|
|
14843
|
+
GIT_MENTION_REF_LIMIT = 50;
|
|
14844
|
+
}
|
|
14845
|
+
});
|
|
14846
|
+
|
|
14847
|
+
// ../../packages/shared/src/git-mention-tags.ts
|
|
14848
|
+
function unescapeGitTagText(value) {
|
|
14849
|
+
return value.replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&");
|
|
14850
|
+
}
|
|
14851
|
+
function gitTagDisplayName(name) {
|
|
14852
|
+
return unescapeGitTagText(name).trim();
|
|
14853
|
+
}
|
|
14854
|
+
function replaceGitTagsWithMention(text2) {
|
|
14855
|
+
return text2.replace(GIT_TAG_REGEX, (_full, _kind, name) => `@${gitTagDisplayName(String(name))}`).replace(GIT_HOST_TAG_REGEX, (_full, _host, _kind, name) => `@${gitTagDisplayName(String(name))}`);
|
|
14856
|
+
}
|
|
14857
|
+
var INNER, GIT_TAG_REGEX, GIT_HOST_TAG_REGEX;
|
|
14858
|
+
var init_git_mention_tags = __esm({
|
|
14859
|
+
"../../packages/shared/src/git-mention-tags.ts"() {
|
|
14860
|
+
"use strict";
|
|
14861
|
+
init_git_mention_query();
|
|
14862
|
+
INNER = "\\s*<kind>([\\s\\S]*?)<\\/kind>\\s*<name>([\\s\\S]*?)<\\/name>\\s*<id>([\\s\\S]*?)<\\/id>\\s*";
|
|
14863
|
+
GIT_TAG_REGEX = new RegExp(`<superone-git>${INNER}<\\/superone-git>`, "g");
|
|
14864
|
+
GIT_HOST_TAG_REGEX = new RegExp(
|
|
14865
|
+
`<superone-(${GIT_HOST_PROVIDERS.join("|")})>${INNER}<\\/superone-\\1>`,
|
|
14866
|
+
"g"
|
|
14867
|
+
);
|
|
14868
|
+
}
|
|
14869
|
+
});
|
|
14870
|
+
|
|
14755
14871
|
// ../../packages/shared/src/miniapp-prompt-tags.ts
|
|
14756
14872
|
function stripMiniAppMarkup(text2) {
|
|
14757
14873
|
return stripCapabilityMarkup(
|
|
14758
|
-
text2.replace(MINIAPP_REMINDER_REGEX, "").replace(SESSION_REMINDER_REGEX, "").replace(DESKTOP_APP_REMINDER_REGEX, "").replace(MINIAPP_TAG_REGEX, (_3, appName) => `@${String(appName).trim()}`).replace(SESSION_TAG_REGEX, (_3, title) => `@${String(title).trim()}`).replace(DESKTOP_APP_TAG_REGEX, (_3, name) => `@${String(name).trim()}`).replace(PATH_REF_TAG_REGEX, (_full, _kind, name, value) => {
|
|
14874
|
+
replaceGitTagsWithMention(text2).replace(MINIAPP_REMINDER_REGEX, "").replace(SESSION_REMINDER_REGEX, "").replace(DESKTOP_APP_REMINDER_REGEX, "").replace(MINIAPP_TAG_REGEX, (_3, appName) => `@${String(appName).trim()}`).replace(SESSION_TAG_REGEX, (_3, title) => `@${String(title).trim()}`).replace(DESKTOP_APP_TAG_REGEX, (_3, name) => `@${String(name).trim()}`).replace(PATH_REF_TAG_REGEX, (_full, _kind, name, value) => {
|
|
14759
14875
|
const n = String(name).trim();
|
|
14760
14876
|
const v3 = String(value).trim();
|
|
14761
14877
|
return `@${n || v3}`;
|
|
@@ -14768,6 +14884,7 @@ var init_miniapp_prompt_tags = __esm({
|
|
|
14768
14884
|
"use strict";
|
|
14769
14885
|
init_miniapp_mention_marker();
|
|
14770
14886
|
init_capability_prompt_tags();
|
|
14887
|
+
init_git_mention_tags();
|
|
14771
14888
|
MINIAPP_TAG_REGEX = /<superone-miniapp>\s*<appname>([\s\S]*?)<\/appname>\s*<appid>([\s\S]*?)<\/appid>\s*<\/superone-miniapp>/g;
|
|
14772
14889
|
MINIAPP_REMINDER_REGEX = /\n*<superone-miniapp-reminder>[\s\S]*?<\/superone-miniapp-reminder>\n*/g;
|
|
14773
14890
|
SESSION_TAG_REGEX = /<superone-session>\s*<title>([\s\S]*?)<\/title>\s*<sessionId>([\s\S]*?)<\/sessionId>\s*<\/superone-session>/g;
|
|
@@ -73284,8 +73401,8 @@ import { fileURLToPath } from "node:url";
|
|
|
73284
73401
|
function resolveCliReleaseVersion() {
|
|
73285
73402
|
const fromEnv = process.env.SUPERONE_CLI_VERSION?.trim();
|
|
73286
73403
|
if (fromEnv) return fromEnv;
|
|
73287
|
-
if ("0.68.0-alpha".trim()) {
|
|
73288
|
-
return "0.68.0-alpha".trim();
|
|
73404
|
+
if ("0.68.0-alpha.1".trim()) {
|
|
73405
|
+
return "0.68.0-alpha.1".trim();
|
|
73289
73406
|
}
|
|
73290
73407
|
const fromDist = readDistManifestVersion();
|
|
73291
73408
|
if (fromDist) return fromDist;
|
|
@@ -75384,6 +75501,7 @@ async function cloneRepository(input) {
|
|
|
75384
75501
|
}
|
|
75385
75502
|
|
|
75386
75503
|
// src/rpc/handlers.ts
|
|
75504
|
+
init_git_mention_query();
|
|
75387
75505
|
import { existsSync as existsSync26, mkdirSync as mkdirSync15, readdirSync as readdirSync9, statSync as statSync6 } from "node:fs";
|
|
75388
75506
|
import { join as pathJoin, resolve as pathResolve } from "node:path";
|
|
75389
75507
|
import { arch, cpus, freemem, homedir as homedir7, hostname as hostname4, platform, totalmem, uptime } from "node:os";
|
|
@@ -77802,6 +77920,10 @@ async function dispatchRpcInner(method, payload, ctx) {
|
|
|
77802
77920
|
return handleGitCreateBranch(payload, ctx);
|
|
77803
77921
|
case "git.worktrees":
|
|
77804
77922
|
return handleGitWorktrees(payload, ctx);
|
|
77923
|
+
case "git.mentionRefs":
|
|
77924
|
+
return handleGitMentionRefs(payload, ctx);
|
|
77925
|
+
case "git.mentionCapabilities":
|
|
77926
|
+
return handleGitMentionCapabilities(payload, ctx);
|
|
77805
77927
|
case "git.worktreeActivate":
|
|
77806
77928
|
return handleGitWorktreeActivate(payload, ctx);
|
|
77807
77929
|
case "git.worktreeCheckedOutBranches":
|
|
@@ -78855,6 +78977,41 @@ function handleGitCreateBranch(payload, ctx) {
|
|
|
78855
78977
|
return mapThrown8(err);
|
|
78856
78978
|
}
|
|
78857
78979
|
}
|
|
78980
|
+
async function handleGitMentionCapabilities(payload, ctx) {
|
|
78981
|
+
const denied = requireScopes8(ctx.client, OPERATION_SCOPES.readWorkspace);
|
|
78982
|
+
if (denied) return denied;
|
|
78983
|
+
const p3 = asRecord24(payload);
|
|
78984
|
+
try {
|
|
78985
|
+
return {
|
|
78986
|
+
result: await ctx.workspaceGit.mentionCapabilities(
|
|
78987
|
+
String(p3.projectId ?? ""),
|
|
78988
|
+
typeof p3.cwd === "string" ? p3.cwd : null
|
|
78989
|
+
)
|
|
78990
|
+
};
|
|
78991
|
+
} catch (err) {
|
|
78992
|
+
return mapThrown8(err);
|
|
78993
|
+
}
|
|
78994
|
+
}
|
|
78995
|
+
async function handleGitMentionRefs(payload, ctx) {
|
|
78996
|
+
const denied = requireScopes8(ctx.client, OPERATION_SCOPES.readWorkspace);
|
|
78997
|
+
if (denied) return denied;
|
|
78998
|
+
const p3 = asRecord24(payload);
|
|
78999
|
+
if (!isGitMentionRefKind(p3.kind)) {
|
|
79000
|
+
return { error: { code: "invalid_argument", message: "kind must be branch | commit | worktree | tag | issue | pr" } };
|
|
79001
|
+
}
|
|
79002
|
+
try {
|
|
79003
|
+
return {
|
|
79004
|
+
result: await ctx.workspaceGit.mentionRefs(
|
|
79005
|
+
String(p3.projectId ?? ""),
|
|
79006
|
+
p3.kind,
|
|
79007
|
+
typeof p3.query === "string" ? p3.query : "",
|
|
79008
|
+
typeof p3.cwd === "string" ? p3.cwd : null
|
|
79009
|
+
)
|
|
79010
|
+
};
|
|
79011
|
+
} catch (err) {
|
|
79012
|
+
return mapThrown8(err);
|
|
79013
|
+
}
|
|
79014
|
+
}
|
|
78858
79015
|
function handleGitWorktrees(payload, ctx) {
|
|
78859
79016
|
const denied = requireScopes8(ctx.client, OPERATION_SCOPES.readWorkspace);
|
|
78860
79017
|
if (denied) return denied;
|
|
@@ -85970,6 +86127,10 @@ function gitErrorMessage(err) {
|
|
|
85970
86127
|
if (stderr) return stderr;
|
|
85971
86128
|
return err?.message ?? "Unknown git error";
|
|
85972
86129
|
}
|
|
86130
|
+
var NOT_A_REPO_RE = /not a git repository/i;
|
|
86131
|
+
function isNotGitRepoError(err) {
|
|
86132
|
+
return NOT_A_REPO_RE.test(gitErrorMessage(err));
|
|
86133
|
+
}
|
|
85973
86134
|
|
|
85974
86135
|
// ../../packages/runtime/src/git/shortstat.ts
|
|
85975
86136
|
function parseShortstat(shortstat) {
|
|
@@ -86028,6 +86189,220 @@ function gitRunSync(folderPath, args, env) {
|
|
|
86028
86189
|
}
|
|
86029
86190
|
}
|
|
86030
86191
|
|
|
86192
|
+
// ../../packages/runtime/src/git/mention-refs.ts
|
|
86193
|
+
init_git_mention_query();
|
|
86194
|
+
|
|
86195
|
+
// ../../packages/runtime/src/git/gh-run.ts
|
|
86196
|
+
init_spawn_env();
|
|
86197
|
+
import { execFile as execFile4 } from "child_process";
|
|
86198
|
+
var GH_MAX_BUFFER = 16 * 1024 * 1024;
|
|
86199
|
+
function isGhMissingError(err) {
|
|
86200
|
+
return err?.code === "ENOENT";
|
|
86201
|
+
}
|
|
86202
|
+
function ghRun(folderPath, args, timeoutMs, env) {
|
|
86203
|
+
return new Promise((resolve17, reject) => {
|
|
86204
|
+
execFile4(
|
|
86205
|
+
"gh",
|
|
86206
|
+
args,
|
|
86207
|
+
{
|
|
86208
|
+
cwd: folderPath,
|
|
86209
|
+
env: { ...env ? buildSafeEnv(env) : process.env, GH_PROMPT_DISABLED: "1", GH_NO_UPDATE_NOTIFIER: "1" },
|
|
86210
|
+
maxBuffer: GH_MAX_BUFFER,
|
|
86211
|
+
timeout: timeoutMs
|
|
86212
|
+
},
|
|
86213
|
+
(err, stdout, stderr) => {
|
|
86214
|
+
if (err) {
|
|
86215
|
+
const annotated = err;
|
|
86216
|
+
if (stderr && !annotated.stderr) annotated.stderr = String(stderr);
|
|
86217
|
+
annotated.ghArgs = args;
|
|
86218
|
+
reject(annotated);
|
|
86219
|
+
} else {
|
|
86220
|
+
resolve17(stdout.trimEnd());
|
|
86221
|
+
}
|
|
86222
|
+
}
|
|
86223
|
+
);
|
|
86224
|
+
});
|
|
86225
|
+
}
|
|
86226
|
+
|
|
86227
|
+
// ../../packages/runtime/src/git/mention-refs.ts
|
|
86228
|
+
var REF_SCAN_LIMIT = 500;
|
|
86229
|
+
var COMMIT_SCAN_LIMIT = 500;
|
|
86230
|
+
var REF_FORMAT = ["%(refname:short)", "%(objectname)", "%(subject)", "%(committerdate:iso-strict)", "%(HEAD)"].join("%00");
|
|
86231
|
+
var TAG_FORMAT = ["%(refname:short)", "%(objectname)", "%(subject)", "%(creatordate:iso-strict)"].join("%00");
|
|
86232
|
+
var LOG_FORMAT = ["%H", "%s", "%an", "%aI"].join("%x00");
|
|
86233
|
+
var HEX_PREFIX_RE = /^[0-9a-f]{4,40}$/i;
|
|
86234
|
+
var ISSUE_NUMBER_RE = /^#?(\d+)$/;
|
|
86235
|
+
var GH_ITEM_FIELDS = "number,title,state,author,updatedAt";
|
|
86236
|
+
var GH_PR_FIELDS = `${GH_ITEM_FIELDS},isDraft`;
|
|
86237
|
+
async function listGitMentionRefs(kind, query, runners, limit = GIT_MENTION_REF_LIMIT) {
|
|
86238
|
+
const { git: git2, gh } = typeof runners === "function" ? { git: runners } : runners;
|
|
86239
|
+
const needle = query.trim();
|
|
86240
|
+
if (isGitHubRefKind(kind)) {
|
|
86241
|
+
if (!gh) return { ok: false, reason: "gh-unavailable" };
|
|
86242
|
+
try {
|
|
86243
|
+
return { ok: true, refs: (await listGitHubItems(kind, needle, gh)).slice(0, limit) };
|
|
86244
|
+
} catch (err) {
|
|
86245
|
+
if (isGhMissingError(err)) return { ok: false, reason: "gh-unavailable" };
|
|
86246
|
+
return { ok: false, reason: "error", error: ghErrorMessage(err) };
|
|
86247
|
+
}
|
|
86248
|
+
}
|
|
86249
|
+
try {
|
|
86250
|
+
const refs = await listRefs(kind, needle, git2);
|
|
86251
|
+
return { ok: true, refs: refs.slice(0, limit) };
|
|
86252
|
+
} catch (err) {
|
|
86253
|
+
if (isNotGitRepoError(err)) return { ok: false, reason: "not-repo" };
|
|
86254
|
+
return { ok: false, reason: "error", error: err.message };
|
|
86255
|
+
}
|
|
86256
|
+
}
|
|
86257
|
+
async function probeGitMentionCapabilities(runners) {
|
|
86258
|
+
let repo = "ready";
|
|
86259
|
+
try {
|
|
86260
|
+
await runners.git(["rev-parse", "--git-dir"]);
|
|
86261
|
+
} catch {
|
|
86262
|
+
repo = "not-repo";
|
|
86263
|
+
}
|
|
86264
|
+
if (repo !== "ready" || !runners.gh) return { repo, github: false };
|
|
86265
|
+
try {
|
|
86266
|
+
await runners.gh(["repo", "view", "--json", "nameWithOwner"]);
|
|
86267
|
+
return { repo, github: true };
|
|
86268
|
+
} catch {
|
|
86269
|
+
return { repo, github: false };
|
|
86270
|
+
}
|
|
86271
|
+
}
|
|
86272
|
+
function ghErrorMessage(err) {
|
|
86273
|
+
const e = err;
|
|
86274
|
+
const stderr = e.stderr?.trim();
|
|
86275
|
+
return stderr ? stderr.split("\n")[0] : e.message ?? "gh failed";
|
|
86276
|
+
}
|
|
86277
|
+
async function listRefs(kind, needle, run) {
|
|
86278
|
+
switch (kind) {
|
|
86279
|
+
case "branch":
|
|
86280
|
+
return listBranches(needle, run);
|
|
86281
|
+
case "tag":
|
|
86282
|
+
return listTags(needle, run);
|
|
86283
|
+
case "commit":
|
|
86284
|
+
return listCommits(needle, run);
|
|
86285
|
+
case "worktree":
|
|
86286
|
+
return listWorktrees(needle, run);
|
|
86287
|
+
case "issue":
|
|
86288
|
+
case "pr":
|
|
86289
|
+
throw new Error(`${kind} is a GitHub kind`);
|
|
86290
|
+
}
|
|
86291
|
+
}
|
|
86292
|
+
function ghItemState(item) {
|
|
86293
|
+
if (item.isDraft) return "draft";
|
|
86294
|
+
const s4 = item.state.toLowerCase();
|
|
86295
|
+
return s4 === "merged" ? "merged" : s4 === "closed" ? "closed" : "open";
|
|
86296
|
+
}
|
|
86297
|
+
function parseGhItems(kind, raw) {
|
|
86298
|
+
const items = JSON.parse(raw || "[]");
|
|
86299
|
+
return (Array.isArray(items) ? items : [items]).map((item) => ({
|
|
86300
|
+
kind,
|
|
86301
|
+
id: String(item.number),
|
|
86302
|
+
label: `#${item.number}`,
|
|
86303
|
+
detail: item.title ?? "",
|
|
86304
|
+
date: item.updatedAt,
|
|
86305
|
+
author: item.author?.login,
|
|
86306
|
+
state: ghItemState(item),
|
|
86307
|
+
host: "github"
|
|
86308
|
+
}));
|
|
86309
|
+
}
|
|
86310
|
+
async function listGitHubItems(kind, needle, gh) {
|
|
86311
|
+
const fields = kind === "pr" ? GH_PR_FIELDS : GH_ITEM_FIELDS;
|
|
86312
|
+
const list = (extra) => gh([kind, "list", "--limit", String(GIT_MENTION_REF_LIMIT), "--json", fields, ...extra]);
|
|
86313
|
+
if (!needle) return parseGhItems(kind, await list(["--state", "open"]));
|
|
86314
|
+
const searched = parseGhItems(kind, await list(["--state", "all", "--search", needle]));
|
|
86315
|
+
const number4 = ISSUE_NUMBER_RE.exec(needle)?.[1];
|
|
86316
|
+
if (!number4) return searched;
|
|
86317
|
+
let exact = [];
|
|
86318
|
+
try {
|
|
86319
|
+
exact = parseGhItems(kind, await gh([kind, "view", number4, "--json", fields]));
|
|
86320
|
+
} catch {
|
|
86321
|
+
}
|
|
86322
|
+
const seen = new Set(exact.map((r) => r.id));
|
|
86323
|
+
return [...exact, ...searched.filter((r) => !seen.has(r.id))];
|
|
86324
|
+
}
|
|
86325
|
+
async function listBranches(needle, run) {
|
|
86326
|
+
const raw = await run([
|
|
86327
|
+
"for-each-ref",
|
|
86328
|
+
"refs/heads",
|
|
86329
|
+
"--sort=-committerdate",
|
|
86330
|
+
`--count=${REF_SCAN_LIMIT}`,
|
|
86331
|
+
`--format=${REF_FORMAT}`
|
|
86332
|
+
]);
|
|
86333
|
+
const refs = [];
|
|
86334
|
+
for (const line of raw.split("\n")) {
|
|
86335
|
+
if (!line) continue;
|
|
86336
|
+
const [name = "", , subject = "", date5 = "", head = ""] = line.split("\0");
|
|
86337
|
+
const ref = { kind: "branch", id: name, label: name, detail: subject, date: date5, current: head === "*" };
|
|
86338
|
+
if (gitRefMatches(ref, needle)) refs.push(ref);
|
|
86339
|
+
}
|
|
86340
|
+
refs.sort((a, b3) => Number(b3.current === true) - Number(a.current === true));
|
|
86341
|
+
return refs;
|
|
86342
|
+
}
|
|
86343
|
+
async function listTags(needle, run) {
|
|
86344
|
+
const raw = await run([
|
|
86345
|
+
"for-each-ref",
|
|
86346
|
+
"refs/tags",
|
|
86347
|
+
"--sort=-creatordate",
|
|
86348
|
+
`--count=${REF_SCAN_LIMIT}`,
|
|
86349
|
+
`--format=${TAG_FORMAT}`
|
|
86350
|
+
]);
|
|
86351
|
+
const refs = [];
|
|
86352
|
+
for (const line of raw.split("\n")) {
|
|
86353
|
+
if (!line) continue;
|
|
86354
|
+
const [name = "", , subject = "", date5 = ""] = line.split("\0");
|
|
86355
|
+
const ref = { kind: "tag", id: name, label: name, detail: subject, date: date5 };
|
|
86356
|
+
if (gitRefMatches(ref, needle)) refs.push(ref);
|
|
86357
|
+
}
|
|
86358
|
+
return refs;
|
|
86359
|
+
}
|
|
86360
|
+
function parseLog(raw) {
|
|
86361
|
+
const refs = [];
|
|
86362
|
+
for (const line of raw.split("\n")) {
|
|
86363
|
+
if (!line) continue;
|
|
86364
|
+
const [sha = "", subject = "", author = "", date5 = ""] = line.split("\0");
|
|
86365
|
+
if (!sha) continue;
|
|
86366
|
+
refs.push({ kind: "commit", id: sha, label: sha.slice(0, 7), detail: subject, date: date5, author });
|
|
86367
|
+
}
|
|
86368
|
+
return refs;
|
|
86369
|
+
}
|
|
86370
|
+
async function listCommits(needle, run) {
|
|
86371
|
+
if (!needle) return parseLog(await run(["log", `-n${GIT_MENTION_REF_LIMIT}`, `--format=${LOG_FORMAT}`]));
|
|
86372
|
+
const recent = parseLog(await run(["log", `-n${COMMIT_SCAN_LIMIT}`, `--format=${LOG_FORMAT}`]));
|
|
86373
|
+
const byMessage = recent.filter((r) => gitRefMatches(r, needle)).slice(0, GIT_MENTION_REF_LIMIT);
|
|
86374
|
+
if (!HEX_PREFIX_RE.test(needle)) return byMessage;
|
|
86375
|
+
let bySha = [];
|
|
86376
|
+
try {
|
|
86377
|
+
bySha = parseLog(await run(["log", "-n1", `--format=${LOG_FORMAT}`, needle, "--"]));
|
|
86378
|
+
} catch {
|
|
86379
|
+
}
|
|
86380
|
+
const seen = new Set(bySha.map((r) => r.id));
|
|
86381
|
+
return [...bySha, ...byMessage.filter((r) => !seen.has(r.id))];
|
|
86382
|
+
}
|
|
86383
|
+
async function listWorktrees(needle, run) {
|
|
86384
|
+
const [raw, toplevel] = await Promise.all([
|
|
86385
|
+
run(["worktree", "list", "--porcelain"]),
|
|
86386
|
+
run(["rev-parse", "--show-toplevel"]).catch(() => "")
|
|
86387
|
+
]);
|
|
86388
|
+
const here = toplevel.trim().replace(/[\\/]+$/, "");
|
|
86389
|
+
const refs = [];
|
|
86390
|
+
for (const wt2 of parseWorktreePorcelain(raw)) {
|
|
86391
|
+
if (wt2.bare) continue;
|
|
86392
|
+
const label = wt2.branch ?? (wt2.head ? `detached @ ${wt2.head.slice(0, 7)}` : wt2.path);
|
|
86393
|
+
const ref = {
|
|
86394
|
+
kind: "worktree",
|
|
86395
|
+
id: wt2.path,
|
|
86396
|
+
label,
|
|
86397
|
+
detail: wt2.path,
|
|
86398
|
+
current: !!here && wt2.path.replace(/[\\/]+$/, "") === here
|
|
86399
|
+
};
|
|
86400
|
+
if (gitRefMatches(ref, needle)) refs.push(ref);
|
|
86401
|
+
}
|
|
86402
|
+
refs.sort((a, b3) => Number(b3.current === true) - Number(a.current === true));
|
|
86403
|
+
return refs;
|
|
86404
|
+
}
|
|
86405
|
+
|
|
86031
86406
|
// ../../packages/runtime/src/git/worktree-plan.ts
|
|
86032
86407
|
import { basename as basename3, dirname as dirname17, join as join32, resolve as resolve12, sep as sep4 } from "node:path";
|
|
86033
86408
|
import { homedir as homedir8 } from "node:os";
|
|
@@ -86074,6 +86449,7 @@ function parseNumstat(numstat) {
|
|
|
86074
86449
|
}
|
|
86075
86450
|
|
|
86076
86451
|
// src/workspace/git-service.ts
|
|
86452
|
+
var GH_TIMEOUT_MS = 15e3;
|
|
86077
86453
|
function git(cwd, args, env) {
|
|
86078
86454
|
return gitRunSync(cwd, args, env);
|
|
86079
86455
|
}
|
|
@@ -86216,6 +86592,21 @@ var WorkspaceGitService = class {
|
|
|
86216
86592
|
return { ok: false, error: gitErrorMessage(err) };
|
|
86217
86593
|
}
|
|
86218
86594
|
}
|
|
86595
|
+
/** `@git` / `@gh` popup rows; `absolutePath` narrows to a linked worktree of the project. */
|
|
86596
|
+
mentionRefs(projectId, kind, query, absolutePath) {
|
|
86597
|
+
return listGitMentionRefs(kind, query, this.mentionRunners(projectId, absolutePath));
|
|
86598
|
+
}
|
|
86599
|
+
/** What the `@git` / `@gh` portals may offer for the project (or one of its worktrees). */
|
|
86600
|
+
mentionCapabilities(projectId, absolutePath) {
|
|
86601
|
+
return probeGitMentionCapabilities(this.mentionRunners(projectId, absolutePath));
|
|
86602
|
+
}
|
|
86603
|
+
mentionRunners(projectId, absolutePath) {
|
|
86604
|
+
const cwd = absolutePath ? this.assertRepoWorktreePath(projectId, absolutePath) : this.root(projectId);
|
|
86605
|
+
return {
|
|
86606
|
+
git: async (args) => gitRunSync(cwd, args),
|
|
86607
|
+
gh: (args) => ghRun(cwd, args, GH_TIMEOUT_MS)
|
|
86608
|
+
};
|
|
86609
|
+
}
|
|
86219
86610
|
worktrees(projectId) {
|
|
86220
86611
|
const cwd = this.root(projectId);
|
|
86221
86612
|
try {
|
package/package.json
CHANGED