pi-odd-worktree 2.1.0 → 3.0.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/README.md +54 -319
- package/extensions/odd-worktree-tools.ts +4182 -2539
- package/lib/bash-activity.js +1166 -0
- package/lib/bash-design.js +684 -0
- package/lib/bash-destructive.js +559 -0
- package/lib/bash-frame.js +205 -0
- package/lib/card-content.js +23 -0
- package/lib/card-style.js +175 -0
- package/lib/checkout-facts.js +30 -70
- package/lib/codegraph-card-preview.js +628 -0
- package/lib/codegraph-card.js +515 -0
- package/lib/codegraph-compaction.js +76 -0
- package/lib/codegraph-daemon.js +246 -0
- package/lib/codegraph-edit-sync.js +182 -0
- package/lib/codegraph-guard-target.js +337 -0
- package/lib/codegraph-guard.js +211 -0
- package/lib/codegraph-index.js +1020 -0
- package/lib/codegraph-lock.js +607 -0
- package/lib/codegraph-mcp-config.js +134 -0
- package/lib/codegraph-mcp.js +123 -0
- package/lib/codegraph-paths.js +69 -0
- package/lib/codegraph-prompt/explore.md +11 -0
- package/lib/codegraph-prompt/fix.md +6 -0
- package/lib/codegraph-prompt/generic.md +8 -0
- package/lib/codegraph-prompt/judge.md +9 -0
- package/lib/codegraph-prompt/orchestrator.md +17 -0
- package/lib/codegraph-prompt/verify.md +10 -0
- package/lib/codegraph-prompt/worker.md +7 -0
- package/lib/codegraph-role.js +55 -0
- package/lib/codegraph-rules.js +146 -0
- package/lib/codegraph-session.js +303 -383
- package/lib/codegraph-warmup.js +139 -0
- package/lib/file-card-markdown.js +141 -0
- package/lib/file-card-resolver.js +245 -0
- package/lib/file-card.js +659 -0
- package/lib/files-index.js +387 -0
- package/lib/files-insert.js +81 -0
- package/lib/files-orders.js +326 -0
- package/lib/files-picker-view.js +1421 -0
- package/lib/files-preview.js +338 -0
- package/lib/files-scope-detail.js +171 -0
- package/lib/files-scope-view.js +507 -0
- package/lib/gh-issues.js +323 -15
- package/lib/issue-preview.js +26 -7
- package/lib/issues-bash-mutation.js +206 -0
- package/lib/issues-cache-store.js +261 -0
- package/lib/issues-section.js +710 -0
- package/lib/issues-view.js +649 -52
- package/lib/odd-prompt/odd-worktrees.md +21 -0
- package/lib/odd-worktrees-prompt.js +10 -28
- package/lib/related-issues-cache.js +210 -0
- package/lib/shell-card.js +825 -0
- package/lib/skill-odd-card.js +183 -0
- package/lib/tui-paint.js +4 -5
- package/lib/warp-create-panel.js +538 -250
- package/lib/warp-create-picker.js +56 -9
- package/lib/warp-delete-confirm.js +19 -28
- package/lib/warp-selector-view.js +160 -82
- package/lib/which-command.js +90 -0
- package/lib/worktree-card.js +267 -897
- package/lib/worktree-cards.js +383 -0
- package/lib/worktree-create.js +287 -0
- package/lib/worktree-git.js +3 -3
- package/lib/worktree-guard.js +548 -0
- package/lib/worktree-hooks.js +421 -712
- package/lib/worktree-list.js +120 -0
- package/lib/worktree-registry.js +162 -879
- package/lib/{worktree-close-herdr.js → worktree-remove.js} +9 -11
- package/lib/worktree-setup-runner.js +376 -0
- package/lib/worktree-setup.js +140 -0
- package/lib/worktree-warp-busy.js +462 -85
- package/lib/worktree-warp-sessions.js +1 -2
- package/package.json +2 -2
- package/tools/bash-activity.test.js +1420 -0
- package/tools/bash-design.test.js +1093 -0
- package/tools/bash-destructive.test.js +139 -0
- package/tools/card-content.test.js +44 -0
- package/tools/card-style.test.js +298 -0
- package/tools/codegraph-card-preview.test.js +254 -0
- package/tools/codegraph-card.test.js +1080 -0
- package/tools/codegraph-compaction.test.js +378 -0
- package/tools/codegraph-daemon.test.js +248 -0
- package/tools/codegraph-edit-sync.test.js +295 -0
- package/tools/codegraph-guard-target.test.js +174 -0
- package/tools/codegraph-guard.test.js +238 -0
- package/tools/codegraph-index.test.js +1948 -0
- package/tools/codegraph-lock.test.js +932 -0
- package/tools/codegraph-mcp-config.test.js +181 -0
- package/tools/codegraph-mcp.test.js +194 -0
- package/tools/codegraph-paths.test.js +44 -0
- package/tools/codegraph-role.test.js +30 -0
- package/tools/codegraph-rules.test.js +250 -0
- package/tools/codegraph-session.test.js +660 -391
- package/tools/codegraph-warmup.test.js +316 -0
- package/tools/commands.test.js +510 -31
- package/tools/file-card-markdown.test.js +188 -0
- package/tools/file-card.test.js +1289 -0
- package/tools/files-bridge.test.js +575 -0
- package/tools/files-command.test.js +613 -0
- package/tools/files-index.test.js +473 -0
- package/tools/files-insert.test.js +139 -0
- package/tools/files-orders.test.js +597 -0
- package/tools/files-picker-view.test.js +1889 -0
- package/tools/files-preview.test.js +452 -0
- package/tools/files-scope-detail.test.js +264 -0
- package/tools/files-scope-view.test.js +614 -0
- package/tools/fixtures/card-codegraph-outputs.js +110 -0
- package/tools/fixtures/codegraph-cli-stub.js +16 -0
- package/tools/fixtures/codegraph-init-process.js +28 -0
- package/tools/fixtures/codegraph-lock-worker.js +117 -0
- package/tools/fixtures/daemon-fake.js +98 -0
- package/tools/fixtures/daemon-mcp-server.js +39 -0
- package/tools/fixtures/daemon-warmup-worker.js +12 -0
- package/tools/fixtures/load-extension.js +136 -3
- package/tools/gh-issues-feedback.test.js +31 -7
- package/tools/gh-issues.test.js +417 -1
- package/tools/issue-preview.test.js +44 -7
- package/tools/issues-bash-mutation.test.js +101 -0
- package/tools/issues-cache-store.test.js +222 -0
- package/tools/issues-command.test.js +1517 -67
- package/tools/issues-open-guard.test.js +1096 -0
- package/tools/issues-section.test.js +4235 -0
- package/tools/issues-seed-query-regression.test.js +67 -0
- package/tools/issues-view.test.js +1489 -60
- package/tools/odd-worktrees-prompt.test.js +98 -65
- package/tools/package-surface.test.js +431 -36
- package/tools/related-issues-cache.test.js +324 -0
- package/tools/shell-card.test.js +834 -0
- package/tools/skill-odd-card.test.js +200 -0
- package/tools/t5-session-identity.test.js +44 -22
- package/tools/warp-busy-guard.test.js +2565 -309
- package/tools/warp-create-panel.test.js +499 -74
- package/tools/warp-create-picker.test.js +101 -5
- package/tools/warp-delete-confirm.test.js +49 -15
- package/tools/warp-empty-session.test.js +0 -1
- package/tools/warp-fallback-regression.test.js +533 -0
- package/tools/warp-selector-view.test.js +460 -196
- package/tools/which-command.test.js +126 -0
- package/tools/worktree-card.test.js +551 -0
- package/tools/worktree-cards.test.js +845 -0
- package/tools/worktree-changes.test.js +4 -5
- package/tools/worktree-create.test.js +489 -0
- package/tools/worktree-guard.test.js +823 -0
- package/tools/worktree-hooks.test.js +905 -0
- package/tools/worktree-list.test.js +170 -0
- package/tools/worktree-registry.test.js +89 -230
- package/tools/worktree-remove-async.test.js +318 -0
- package/tools/worktree-setup-runner.test.js +276 -0
- package/tools/worktree-setup.test.js +140 -0
- package/tools/worktree-tools.test.js +419 -199
- package/lib/codegraph-commands.js +0 -165
- package/lib/odd-prompt/odd-worktrees.with-codegraph.md +0 -19
- package/lib/odd-prompt/odd-worktrees.without-codegraph.md +0 -15
- package/lib/worktree-model-result.js +0 -291
- package/tools/codegraph-commands.test.js +0 -371
- package/tools/herdr-free-create.test.js +0 -161
- package/tools/worktree-close-herdr-async.test.js +0 -204
- package/tools/worktree-odd-migration.test.js +0 -224
- package/tools/worktree-registry-cache.test.js +0 -163
- package/tools/worktree-registry-odd.test.js +0 -231
package/lib/gh-issues.js
CHANGED
|
@@ -81,6 +81,7 @@
|
|
|
81
81
|
const { execFile } = require('node:child_process');
|
|
82
82
|
const crypto = require('node:crypto');
|
|
83
83
|
const path = require('node:path');
|
|
84
|
+
const { whichCommand } = require('./which-command.js');
|
|
84
85
|
|
|
85
86
|
const DEFAULT_TIMEOUT_MS = 30000;
|
|
86
87
|
const GIT_TIMEOUT_MS = 5000;
|
|
@@ -158,6 +159,53 @@ function ghBinary(opts = {}) {
|
|
|
158
159
|
return 'gh';
|
|
159
160
|
}
|
|
160
161
|
|
|
162
|
+
// S13 (issues-startup-performance T11): a test seam for the CLI's presence,
|
|
163
|
+
// exactly like `setGhRunner` and `setGitRunner` — inject
|
|
164
|
+
// `fn(bin) -> foundPathOrNull`, or `null`/`undefined` to restore the local probe
|
|
165
|
+
// below.
|
|
166
|
+
let whichOverride = null;
|
|
167
|
+
|
|
168
|
+
function setGhWhich(fn) {
|
|
169
|
+
if (fn === null || fn === undefined) {
|
|
170
|
+
whichOverride = null;
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
if (typeof fn !== 'function') throw new TypeError('setGhWhich requires a function or null');
|
|
174
|
+
whichOverride = fn;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Whether the `gh` binary this client would run is reachable WITHOUT running it.
|
|
178
|
+
//
|
|
179
|
+
// S13 (T11): the caller — the session gate, `/issues`, the rail's read — needs
|
|
180
|
+
// that answer before it spends a child process finding out, and the answer is
|
|
181
|
+
// already on disk (`lib/which-command.js` walks PATH). No child process, no
|
|
182
|
+
// network, no cache, and `GH_BIN_PATH` is respected through `ghBinary`, so an
|
|
183
|
+
// install outside PATH that the caller named is still present.
|
|
184
|
+
//
|
|
185
|
+
// Two callers' facts outrank the probe: a `which` seam injected here answers for
|
|
186
|
+
// itself, and a caller that injected its own RUNNER (`setGhRunner`) owns the
|
|
187
|
+
// binary question — that runner never needs a `gh` on PATH, so its tests and the
|
|
188
|
+
// `GH_BIN_PATH`-less CI that drives them are not mistaken for a missing CLI.
|
|
189
|
+
// An internal failure never claims absence: only a definitive "nothing on PATH"
|
|
190
|
+
// answer is `false`, because a false answer turns every issues surface off.
|
|
191
|
+
function ghCliPresent(opts = {}) {
|
|
192
|
+
const options = opts && typeof opts === 'object' ? opts : {};
|
|
193
|
+
const bin = ghBinary(options);
|
|
194
|
+
if (whichOverride !== null) {
|
|
195
|
+
try {
|
|
196
|
+
return whichOverride(bin) !== null;
|
|
197
|
+
} catch {
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (runnerOverride !== null) return true;
|
|
202
|
+
try {
|
|
203
|
+
return whichCommand(bin, { env: options.env || process.env }) !== null;
|
|
204
|
+
} catch {
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
161
209
|
// ---------------------------------------------------------------------------
|
|
162
210
|
// Checkout scope: which repository this checkout belongs to.
|
|
163
211
|
// ---------------------------------------------------------------------------
|
|
@@ -711,6 +759,14 @@ async function runGh(argv, opts = {}) {
|
|
|
711
759
|
|
|
712
760
|
// Failure text for a non-zero `gh` exit: prefer stderr (where gh explains
|
|
713
761
|
// auth and resolution problems), fall back to the bare status.
|
|
762
|
+
// gh's own answer when the checkout has no remote at all: there is nothing to
|
|
763
|
+
// resolve FROM, so it cannot name a repository. It is a STATE of the checkout,
|
|
764
|
+
// not a failure of `gh` (authentication, network, a broken install), and a
|
|
765
|
+
// caller that draws states needs to tell the two apart. Matched on gh's text
|
|
766
|
+
// because that is all gh reports; an unknown wording just degrades to the
|
|
767
|
+
// failure it already was.
|
|
768
|
+
const NO_GIT_REMOTE_PATTERN = /no git remotes/i;
|
|
769
|
+
|
|
714
770
|
function exitError(outcome, what) {
|
|
715
771
|
const stderr = (outcome.stderr || '').trim();
|
|
716
772
|
if (stderr) return `${what}: ${stderr.split('\n')[0].slice(0, 500)}`;
|
|
@@ -862,6 +918,91 @@ async function ghStatus(opts = {}) {
|
|
|
862
918
|
return { ok: true, login, nameWithOwner: (scope.ok === true && scope.nameWithOwner) || reported };
|
|
863
919
|
}
|
|
864
920
|
|
|
921
|
+
// The gate's answer — `gh api user` then `gh repo view`, plus the checkout's own
|
|
922
|
+
// git probes — is what `/issues` cannot open without, and it is pure network and
|
|
923
|
+
// disk latency. It is reused for a short while so one session start, a resume and a
|
|
924
|
+
// typed command share a single probe: minutes for a usable `gh`, seconds for a
|
|
925
|
+
// failure, so a package or login the human just fixed is noticed quickly.
|
|
926
|
+
const GATE_SUCCESS_TTL_MS = 5 * 60 * 1000;
|
|
927
|
+
const GATE_FAILURE_TTL_MS = 30 * 1000;
|
|
928
|
+
// A handful of checkouts: a few worktrees is the working set, and the oldest entry
|
|
929
|
+
// is what pays when the bound is exceeded.
|
|
930
|
+
const GATE_CACHE_MAX = 8;
|
|
931
|
+
|
|
932
|
+
let gateClockOverride = null;
|
|
933
|
+
|
|
934
|
+
// Test seam: inject `() => epochMillis` (or null to restore the real clock). The
|
|
935
|
+
// TTLs are wall-clock facts, so proving an expiry must move time without sleeping
|
|
936
|
+
// through it.
|
|
937
|
+
function setGateClock(fn) {
|
|
938
|
+
if (fn === null || fn === undefined) {
|
|
939
|
+
gateClockOverride = null;
|
|
940
|
+
return;
|
|
941
|
+
}
|
|
942
|
+
if (typeof fn !== 'function') throw new TypeError('setGateClock requires a function or null');
|
|
943
|
+
gateClockOverride = fn;
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
function gateNow() {
|
|
947
|
+
if (gateClockOverride === null) return Date.now();
|
|
948
|
+
try {
|
|
949
|
+
const value = gateClockOverride();
|
|
950
|
+
return Number.isFinite(value) ? value : Date.now();
|
|
951
|
+
} catch {
|
|
952
|
+
return Date.now();
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
// The checkout AND the host gh would target (GH_HOST), exactly like
|
|
957
|
+
// `checkoutRepoScope`: an answer resolved for one server is never reused for another.
|
|
958
|
+
function gateStatusKey(opts) {
|
|
959
|
+
let cwd = '';
|
|
960
|
+
try {
|
|
961
|
+
cwd = path.resolve(typeof opts.cwd === 'string' && opts.cwd.length > 0 ? opts.cwd : process.cwd());
|
|
962
|
+
} catch {
|
|
963
|
+
cwd = '';
|
|
964
|
+
}
|
|
965
|
+
return `${cwd}\n${ghHostOf(opts.env || process.env)}`;
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
const gateStatuses = new Map();
|
|
969
|
+
|
|
970
|
+
// Drop every cached gate answer. A session that ends takes its answers with it, so
|
|
971
|
+
// the next session starts from its own probe instead of its predecessor's.
|
|
972
|
+
function clearCachedGhStatus() {
|
|
973
|
+
gateStatuses.clear();
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
// `ghStatus` with one answer per checkout and TTL: a caller inside the window gets
|
|
977
|
+
// the previous answer, a caller DURING a probe awaits that same promise instead of
|
|
978
|
+
// spawning a second pair of children, and an expired entry is probed again. The
|
|
979
|
+
// shape is `ghStatus`'s, unchanged, so every decision made from it is the same one:
|
|
980
|
+
// only WHEN the probe runs changes.
|
|
981
|
+
async function cachedGhStatus(opts = {}) {
|
|
982
|
+
const options = opts && typeof opts === 'object' ? opts : {};
|
|
983
|
+
const key = gateStatusKey(options);
|
|
984
|
+
const entry = gateStatuses.get(key);
|
|
985
|
+
if (entry) {
|
|
986
|
+
if (entry.settled !== true) return entry.run;
|
|
987
|
+
const ttl = entry.result && entry.result.ok === true ? GATE_SUCCESS_TTL_MS : GATE_FAILURE_TTL_MS;
|
|
988
|
+
if (gateNow() - entry.at < ttl) return entry.result;
|
|
989
|
+
}
|
|
990
|
+
const next = { settled: false, result: null, at: gateNow(), run: null };
|
|
991
|
+
next.run = ghStatus(options)
|
|
992
|
+
.catch((err) => ({ ok: false, error: (err && err.message) || String(err) }))
|
|
993
|
+
.then((result) => {
|
|
994
|
+
next.settled = true;
|
|
995
|
+
next.result = result;
|
|
996
|
+
next.at = gateNow();
|
|
997
|
+
return result;
|
|
998
|
+
});
|
|
999
|
+
if (gateStatuses.size >= GATE_CACHE_MAX && !gateStatuses.has(key)) {
|
|
1000
|
+
gateStatuses.delete(gateStatuses.keys().next().value);
|
|
1001
|
+
}
|
|
1002
|
+
gateStatuses.set(key, next);
|
|
1003
|
+
return next.run;
|
|
1004
|
+
}
|
|
1005
|
+
|
|
865
1006
|
async function repoInfo(opts = {}) {
|
|
866
1007
|
const resolved = await repoNameWithOwner(opts);
|
|
867
1008
|
if (!resolved.ok) return resolved;
|
|
@@ -888,7 +1029,13 @@ async function reportedRepoName(opts = {}) {
|
|
|
888
1029
|
// failure still prevents this gh call).
|
|
889
1030
|
const repo = await runGh(['repo', 'view', '--json', 'nameWithOwner'], opts);
|
|
890
1031
|
if (repo.error) return { ok: false, error: repo.error };
|
|
891
|
-
if (repo.status !== 0)
|
|
1032
|
+
if (repo.status !== 0) {
|
|
1033
|
+
return {
|
|
1034
|
+
ok: false,
|
|
1035
|
+
error: exitError(repo, 'cannot resolve the repository'),
|
|
1036
|
+
...(NO_GIT_REMOTE_PATTERN.test(repo.stderr || '') ? { noRemote: true } : {}),
|
|
1037
|
+
};
|
|
1038
|
+
}
|
|
892
1039
|
const parsedRepo = parseJsonBody(repo.stdout, 'gh repo view');
|
|
893
1040
|
if (!parsedRepo.ok) return parsedRepo;
|
|
894
1041
|
const reported = parsedRepo.doc && typeof parsedRepo.doc.nameWithOwner === 'string'
|
|
@@ -995,11 +1142,24 @@ function graphqlIssueRow(node) {
|
|
|
995
1142
|
const labelNodes = entry.labels && typeof entry.labels === 'object' && Array.isArray(entry.labels.nodes)
|
|
996
1143
|
? entry.labels.nodes
|
|
997
1144
|
: [];
|
|
1145
|
+
// T10 (S9): the rail's row is the panel's first frame, so a request that asks
|
|
1146
|
+
// for `assignees { nodes { login } }` gets the plain login list the detail
|
|
1147
|
+
// read's `assignees` field also normalizes to.
|
|
1148
|
+
const assigneeNodes = entry.assignees && typeof entry.assignees === 'object'
|
|
1149
|
+
&& Array.isArray(entry.assignees.nodes)
|
|
1150
|
+
? entry.assignees.nodes
|
|
1151
|
+
: null;
|
|
998
1152
|
const commentsTotal = entry.comments && typeof entry.comments === 'object'
|
|
999
1153
|
&& Number.isInteger(entry.comments.totalCount)
|
|
1000
1154
|
? entry.comments.totalCount
|
|
1001
1155
|
: 0;
|
|
1002
|
-
return {
|
|
1156
|
+
return {
|
|
1157
|
+
...entry,
|
|
1158
|
+
labels: labelNodes,
|
|
1159
|
+
...(assigneeNodes === null ? {} : { assignees: assigneeNodes }),
|
|
1160
|
+
comments: [],
|
|
1161
|
+
commentsTotal,
|
|
1162
|
+
};
|
|
1003
1163
|
}
|
|
1004
1164
|
|
|
1005
1165
|
// EVERY open issue of the repository, read through the GraphQL connection.
|
|
@@ -1369,7 +1529,7 @@ async function getIssueMetadata(number, opts = {}) {
|
|
|
1369
1529
|
viewerPermission
|
|
1370
1530
|
issue(number: $number) {
|
|
1371
1531
|
assignees(first: 100) { nodes { login } pageInfo { hasNextPage } }
|
|
1372
|
-
closedByPullRequestsReferences(first:
|
|
1532
|
+
closedByPullRequestsReferences(first: 100, includeClosedPrs: true) { nodes { number } pageInfo { hasNextPage } }
|
|
1373
1533
|
}
|
|
1374
1534
|
}
|
|
1375
1535
|
}`;
|
|
@@ -1386,11 +1546,28 @@ async function getIssueMetadata(number, opts = {}) {
|
|
|
1386
1546
|
permissions: repositoryEditPermissions(repository.viewerPermission),
|
|
1387
1547
|
assignees: issue.assignees.nodes.map(asLogin).filter(Boolean),
|
|
1388
1548
|
};
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1549
|
+
// S1/S4: the pane lists linked PRs by number, so the read carries the
|
|
1550
|
+
// reference numbers themselves (the first server page) instead of a count.
|
|
1551
|
+
// A page that is not a list of positive integers is a failed relation, and a
|
|
1552
|
+
// page the server says continues is marked truncated rather than passed off
|
|
1553
|
+
// as the whole list.
|
|
1554
|
+
const references = issue.closedByPullRequestsReferences;
|
|
1555
|
+
const referenceNodes = references?.nodes;
|
|
1556
|
+
const validReference = Array.isArray(referenceNodes)
|
|
1557
|
+
&& referenceNodes.every((node) => Number.isInteger(node?.number) && node.number > 0);
|
|
1558
|
+
// S2: a relation that could not be read is NAMED, so the pane can say which
|
|
1559
|
+
// metadata is missing; `metadataError` stays reserved for a whole-read loss.
|
|
1560
|
+
const unavailable = [];
|
|
1561
|
+
if (validReference) {
|
|
1562
|
+
const numbers = [...new Set(referenceNodes.map((node) => node.number))].sort((a, b) => a - b);
|
|
1563
|
+
if (numbers.length > 0) metadata.linkedPullRequests = numbers;
|
|
1564
|
+
if (references.pageInfo?.hasNextPage === true) metadata.linkedPullRequestsTruncated = true;
|
|
1565
|
+
} else {
|
|
1566
|
+
unavailable.push('linked PRs');
|
|
1567
|
+
}
|
|
1392
1568
|
// Project visibility/scopes are independent of issue triage permissions.
|
|
1393
|
-
// A private or unsupported project relation must not disable known rights
|
|
1569
|
+
// A private or unsupported project relation must not disable known rights,
|
|
1570
|
+
// and S3 keeps every confirmed fact when only this relation is lost.
|
|
1394
1571
|
const relations = await feedbackGraphql(`query($owner: String!, $name: String!, $number: Int!) {
|
|
1395
1572
|
repository(owner: $owner, name: $name) {
|
|
1396
1573
|
issue(number: $number) {
|
|
@@ -1400,12 +1577,13 @@ async function getIssueMetadata(number, opts = {}) {
|
|
|
1400
1577
|
}`, { owner: repo.owner, name: repo.name, number }, opts);
|
|
1401
1578
|
const related = relations.ok ? relations.data.repository?.issue : null;
|
|
1402
1579
|
if (!Array.isArray(related?.projectItems?.nodes) || related.projectItems.pageInfo?.hasNextPage) {
|
|
1403
|
-
|
|
1404
|
-
|
|
1580
|
+
unavailable.push('projects');
|
|
1581
|
+
} else {
|
|
1582
|
+
const projects = related.projectItems.nodes.map((item) => item?.project)
|
|
1583
|
+
.filter((project) => typeof project?.title === 'string' && project.title);
|
|
1584
|
+
if (projects.length > 0) metadata.projects = projects.map(({ title, url }) => ({ title, url }));
|
|
1405
1585
|
}
|
|
1406
|
-
|
|
1407
|
-
.filter((project) => typeof project?.title === 'string' && project.title);
|
|
1408
|
-
if (projects.length > 0) metadata.projects = projects.map(({ title, url }) => ({ title, url }));
|
|
1586
|
+
if (unavailable.length > 0) metadata.unavailable = unavailable;
|
|
1409
1587
|
return metadata;
|
|
1410
1588
|
}
|
|
1411
1589
|
|
|
@@ -1455,10 +1633,16 @@ async function editAssignees(number, changes = {}, opts = {}) {
|
|
|
1455
1633
|
|| add.some((name) => remove.some((other) => name.toLowerCase() === other.toLowerCase()))) {
|
|
1456
1634
|
return { ok: false, error: 'invalid assignee changes: supply distinct GitHub logins to add or remove' };
|
|
1457
1635
|
}
|
|
1458
|
-
if (add.length === 0 && remove.length === 0) return { ok: true, changed: false };
|
|
1636
|
+
if (add.length === 0 && remove.length === 0) return { ok: true, changed: false, self: false };
|
|
1459
1637
|
const repo = await feedbackRepository(opts);
|
|
1460
1638
|
if (!repo.ok) return repo;
|
|
1461
|
-
|
|
1639
|
+
// T17 (S21): the SAME permission read that authorizes the write names the
|
|
1640
|
+
// authenticated viewer (`viewer { login }` is a root field, so it costs no
|
|
1641
|
+
// second request). A delta that includes that login is the one write whose
|
|
1642
|
+
// effect the viewer's OWN `assigned` bucket shows, and the rail's merge is
|
|
1643
|
+
// built from that bucket too — so the answer says so itself instead of any
|
|
1644
|
+
// caller guessing from a display name, a local config or an optimistic guess.
|
|
1645
|
+
const access = await feedbackGraphql('query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { viewerPermission } viewer { login } }', { owner: repo.owner, name: repo.name }, opts);
|
|
1462
1646
|
if (!access.ok) return access;
|
|
1463
1647
|
if (!repositoryEditPermissions(access.data.repository?.viewerPermission).canEditAssignees) {
|
|
1464
1648
|
return { ok: false, error: 'Repository permission does not allow changing issue assignees' };
|
|
@@ -1469,7 +1653,11 @@ async function editAssignees(number, changes = {}, opts = {}) {
|
|
|
1469
1653
|
const result = await runGh(argv, { ...opts, freshScope: true });
|
|
1470
1654
|
if (result.error) return { ok: false, error: result.error };
|
|
1471
1655
|
if (result.status !== 0) return { ok: false, error: exitError(result, 'Cannot edit issue assignees') };
|
|
1472
|
-
|
|
1656
|
+
const viewer = access.data && access.data.viewer && typeof access.data.viewer.login === 'string'
|
|
1657
|
+
? access.data.viewer.login.toLowerCase()
|
|
1658
|
+
: '';
|
|
1659
|
+
const self = viewer !== '' && [...new Set([...add, ...remove])].some((name) => name.toLowerCase() === viewer);
|
|
1660
|
+
return { ok: true, changed: true, self };
|
|
1473
1661
|
}
|
|
1474
1662
|
|
|
1475
1663
|
async function listLabels(opts = {}) {
|
|
@@ -1530,10 +1718,129 @@ async function setIssueState(number, state, opts = {}) {
|
|
|
1530
1718
|
return { ok: true };
|
|
1531
1719
|
}
|
|
1532
1720
|
|
|
1721
|
+
// S9 (issues-sidebar T14, superseding T9's marker read): the rail's ONE read.
|
|
1722
|
+
// A single `gh api graphql` request carries the three scoped views as aliased
|
|
1723
|
+
// searches over the same `repo:<owner>/<name> is:issue is:open` scope, each
|
|
1724
|
+
// sorted by `updatedAt` and bounded by the caller's `first`. The node selection
|
|
1725
|
+
// is the panel's own (`PAGE_ISSUE_FIELDS` + `graphqlIssueRow`), so a cached row
|
|
1726
|
+
// normalizes exactly like a panel row, and T9's pull-request cross-reference
|
|
1727
|
+
// sub-selection rides each node, so the marker costs no second call, no second
|
|
1728
|
+
// identity lookup and no second failure mode. `rateLimit { cost }` is not asked
|
|
1729
|
+
// for: it is a measured optimization fact, not something a row needs.
|
|
1730
|
+
const RELATED_ISSUE_QUALIFIERS = {
|
|
1731
|
+
mine: 'author:@me',
|
|
1732
|
+
assigned: 'assignee:@me',
|
|
1733
|
+
involved: 'involves:@me -author:@me',
|
|
1734
|
+
};
|
|
1735
|
+
// S3 (issues-sidebar-click T2): GraphQL answers `timelineItems` in
|
|
1736
|
+
// chronological order, so a `first: N` window is the OLDEST N cross-reference
|
|
1737
|
+
// events and its first pull request is the oldest one that references the
|
|
1738
|
+
// issue. The rail marks the issue with the number of the MOST RECENT pull
|
|
1739
|
+
// request, so the window is read from the end (`last: N`) — same ONE request for
|
|
1740
|
+
// the three views, same node selection. The window stays bounded and small: the
|
|
1741
|
+
// point is the newest events, and cross references from ISSUES rather than pull
|
|
1742
|
+
// requests must not crowd the pull requests out of it.
|
|
1743
|
+
const PR_REFERENCE_EVENT = 'CROSS_REFERENCED_EVENT';
|
|
1744
|
+
const PR_REFERENCE_WINDOW = 10;
|
|
1745
|
+
|
|
1746
|
+
function relatedIssuesQuery(owner, name, first) {
|
|
1747
|
+
const scope = `repo:${owner}/${name} is:issue is:open`;
|
|
1748
|
+
const aliases = Object.entries(RELATED_ISSUE_QUALIFIERS).map(([alias, qualifier]) => {
|
|
1749
|
+
const search = `${scope} ${qualifier} sort:updated-desc`;
|
|
1750
|
+
return ` ${alias}: search(query: ${JSON.stringify(search)}, type: ISSUE, first: ${first}) {
|
|
1751
|
+
issueCount
|
|
1752
|
+
nodes {
|
|
1753
|
+
... on Issue {
|
|
1754
|
+
${PAGE_ISSUE_FIELDS}
|
|
1755
|
+
assignees(first: 10) { nodes { login } }
|
|
1756
|
+
timelineItems(last: ${PR_REFERENCE_WINDOW}, itemTypes: [${PR_REFERENCE_EVENT}]) {
|
|
1757
|
+
nodes { ... on CrossReferencedEvent { source { __typename ... on PullRequest { number } } } }
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
}
|
|
1761
|
+
}`;
|
|
1762
|
+
});
|
|
1763
|
+
return `query {\n${aliases.join('\n')}\n}`;
|
|
1764
|
+
}
|
|
1765
|
+
|
|
1766
|
+
// The marker is a decoration: a missing or malformed timeline is simply "no
|
|
1767
|
+
// pull request", never a failed read that costs the caller its rows.
|
|
1768
|
+
function pullRequestReferenced(node) {
|
|
1769
|
+
const connection = node && typeof node === 'object' ? node.timelineItems : null;
|
|
1770
|
+
if (!connection || typeof connection !== 'object' || !Array.isArray(connection.nodes)) return false;
|
|
1771
|
+
return connection.nodes.some(
|
|
1772
|
+
(item) => item && typeof item === 'object' && item.source && item.source.__typename === 'PullRequest',
|
|
1773
|
+
);
|
|
1774
|
+
}
|
|
1775
|
+
|
|
1776
|
+
// S8 (T9) + S3 (issues-sidebar-click T2): the marker a row wears is a pull
|
|
1777
|
+
// request's NUMBER, so the same timeline hands it over. The timeline window is
|
|
1778
|
+
// the NEWEST events (`last:`), so the newest pull request is the last event that
|
|
1779
|
+
// carries one: the scan runs from the end and the first pull-request source it
|
|
1780
|
+
// meets is the most recent. A cross reference from an issue, and a node the
|
|
1781
|
+
// answer malformed, are skipped — never read as a number and never a throw — and
|
|
1782
|
+
// a source whose number the answer did not carry is no number at all, so a `#0`
|
|
1783
|
+
// or a `#NaN` never reaches a row. No pull request at all is `null`.
|
|
1784
|
+
function pullRequestNumber(node) {
|
|
1785
|
+
const connection = node && typeof node === 'object' ? node.timelineItems : null;
|
|
1786
|
+
if (!connection || typeof connection !== 'object' || !Array.isArray(connection.nodes)) return null;
|
|
1787
|
+
for (let index = connection.nodes.length - 1; index >= 0; index -= 1) {
|
|
1788
|
+
const item = connection.nodes[index];
|
|
1789
|
+
const source = item && typeof item === 'object' ? item.source : null;
|
|
1790
|
+
if (!source || typeof source !== 'object' || source.__typename !== 'PullRequest') continue;
|
|
1791
|
+
const number = Number(source.number);
|
|
1792
|
+
if (Number.isInteger(number) && number > 0) return number;
|
|
1793
|
+
}
|
|
1794
|
+
return null;
|
|
1795
|
+
}
|
|
1796
|
+
|
|
1797
|
+
// `{ first }` is the per-bucket row budget (1..100) and is validated before any
|
|
1798
|
+
// child runs. The answer is `{ ok: true, buckets: { mine, assigned, involved } }`
|
|
1799
|
+
// with each bucket's exact `issueCount` and its normalized rows; a rejected
|
|
1800
|
+
// child, a non-zero exit, a GraphQL `errors` array, an unparseable body, a
|
|
1801
|
+
// missing alias or a non-array `nodes` is `{ ok: false, error }`.
|
|
1802
|
+
async function listRelatedIssues(params = {}, opts = {}) {
|
|
1803
|
+
const first = params && typeof params === 'object' ? params.first : undefined;
|
|
1804
|
+
if (!Number.isInteger(first) || first < 1 || first > 100) {
|
|
1805
|
+
return { ok: false, error: `invalid first ${JSON.stringify(first)}: want an integer 1..100` };
|
|
1806
|
+
}
|
|
1807
|
+
const repo = await feedbackRepository(opts);
|
|
1808
|
+
if (!repo.ok) return repo;
|
|
1809
|
+
const res = await feedbackGraphql(relatedIssuesQuery(repo.owner, repo.name, first), {}, opts);
|
|
1810
|
+
if (!res.ok) return res;
|
|
1811
|
+
const buckets = {};
|
|
1812
|
+
for (const alias of Object.keys(RELATED_ISSUE_QUALIFIERS)) {
|
|
1813
|
+
const connection = res.data ? res.data[alias] : null;
|
|
1814
|
+
if (!connection || typeof connection !== 'object' || Array.isArray(connection)
|
|
1815
|
+
|| !Number.isInteger(connection.issueCount) || connection.issueCount < 0
|
|
1816
|
+
|| !Array.isArray(connection.nodes)) {
|
|
1817
|
+
return { ok: false, error: 'gh api graphql returned an unexpected shape' };
|
|
1818
|
+
}
|
|
1819
|
+
const issues = [];
|
|
1820
|
+
for (const node of connection.nodes) {
|
|
1821
|
+
if (!node || typeof node !== 'object' || !Number.isInteger(node.number) || node.number <= 0) {
|
|
1822
|
+
return { ok: false, error: 'gh api graphql returned an issue without a number' };
|
|
1823
|
+
}
|
|
1824
|
+
issues.push({
|
|
1825
|
+
...normalizeIssue(graphqlIssueRow(node)),
|
|
1826
|
+
hasPullRequest: pullRequestReferenced(node),
|
|
1827
|
+
pullRequestNumber: pullRequestNumber(node),
|
|
1828
|
+
});
|
|
1829
|
+
}
|
|
1830
|
+
buckets[alias] = { issueCount: connection.issueCount, issues };
|
|
1831
|
+
}
|
|
1832
|
+
return { ok: true, buckets };
|
|
1833
|
+
}
|
|
1834
|
+
|
|
1533
1835
|
module.exports = {
|
|
1534
1836
|
setGhRunner,
|
|
1535
1837
|
setGitRunner,
|
|
1838
|
+
setGhWhich,
|
|
1839
|
+
setGateClock,
|
|
1840
|
+
clearCachedGhStatus,
|
|
1841
|
+
cachedGhStatus,
|
|
1536
1842
|
ghBinary,
|
|
1843
|
+
ghCliPresent,
|
|
1537
1844
|
checkoutRepoScope,
|
|
1538
1845
|
reportedRepoName,
|
|
1539
1846
|
normalizeScopeIdentity,
|
|
@@ -1552,4 +1859,5 @@ module.exports = {
|
|
|
1552
1859
|
editLabels,
|
|
1553
1860
|
commentIssue,
|
|
1554
1861
|
setIssueState,
|
|
1862
|
+
listRelatedIssues,
|
|
1555
1863
|
};
|
package/lib/issue-preview.js
CHANGED
|
@@ -14,8 +14,9 @@
|
|
|
14
14
|
// issueDetailLines(detail, comments, options) -> string[]
|
|
15
15
|
// detail an issue as `gh` normalizes it (number, title, state, author,
|
|
16
16
|
// labels, assignees, createdAt, updatedAt, commentsCount,
|
|
17
|
-
// reactions{plusOne}, projects,
|
|
18
|
-
//
|
|
17
|
+
// reactions{plusOne}, projects, linkedPullRequests,
|
|
18
|
+
// linkedPullRequestsTruncated, unavailable, metadataError,
|
|
19
|
+
// body). Every field is optional.
|
|
19
20
|
// comments an array of `{ author, body, createdAt }`; anything else is
|
|
20
21
|
// treated as "no comments yet".
|
|
21
22
|
// options { width, paint, emphasis, wrap, cache, note, pending, now }
|
|
@@ -36,8 +37,10 @@
|
|
|
36
37
|
// never be served.
|
|
37
38
|
//
|
|
38
39
|
// Absent metadata is omitted rather than printed as "none" or "0": an empty
|
|
39
|
-
// assignee/project list or
|
|
40
|
-
// reaction/comment counters remain explicit facts, including measured
|
|
40
|
+
// assignee/project list or an empty linked-PR list does not add an optional
|
|
41
|
+
// row; reaction/comment counters remain explicit facts, including measured
|
|
42
|
+
// zeros. A relation that could not be read is omitted the same way, never
|
|
43
|
+
// announced, and S4 marks a capped linked-PR page as truncated.
|
|
41
44
|
//
|
|
42
45
|
// S13: the title is a TITLE, not a control. Its role comes from the shared
|
|
43
46
|
// table in `lib/tui-paint.js` (`ROLES.title`) instead of a role name written
|
|
@@ -229,6 +232,12 @@ function issueDetailLines(detail, comments, options = {}) {
|
|
|
229
232
|
if (settings.pending === true) {
|
|
230
233
|
const pending = [];
|
|
231
234
|
for (const line of lines) pending.push(...wrap(line));
|
|
235
|
+
// S9 (T10): a row already knows its author, so the framed identity is
|
|
236
|
+
// complete before the body is; the ages and counters still wait for the
|
|
237
|
+
// richer read (they are not invented from a row that never carried them).
|
|
238
|
+
if (typeof entry.author === 'string' && entry.author.length > 0) {
|
|
239
|
+
pending.push(...wrap(`by ${entry.author}`));
|
|
240
|
+
}
|
|
232
241
|
pending.push(paint('muted', 'loading…'));
|
|
233
242
|
return pending;
|
|
234
243
|
}
|
|
@@ -248,9 +257,19 @@ function issueDetailLines(detail, comments, options = {}) {
|
|
|
248
257
|
.map((project) => (project && project.title ? String(project.title) : ''))
|
|
249
258
|
.filter(Boolean);
|
|
250
259
|
if (projects.length > 0) lines.push(`projects: ${projects.join(', ')}`);
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
260
|
+
// S1: every linked PR is named by number, ascending, never counted; S4 keeps
|
|
261
|
+
// a capped page honest with a trailing ellipsis instead of passing for the
|
|
262
|
+
// whole list.
|
|
263
|
+
const linkedPrs = (Array.isArray(entry.linkedPullRequests) ? entry.linkedPullRequests : [])
|
|
264
|
+
.filter((number) => Number.isInteger(number) && number > 0);
|
|
265
|
+
if (linkedPrs.length > 0) {
|
|
266
|
+
const listed = linkedPrs.map((number) => `#${number}`).join(', ');
|
|
267
|
+
lines.push(`linked PRs: ${listed}${entry.linkedPullRequestsTruncated === true ? ', …' : ''}`);
|
|
268
|
+
}
|
|
269
|
+
// A relation that could not be read (`unavailable`) or a whole failed read
|
|
270
|
+
// (`metadataError`) paints NOTHING: the pane stays quiet, exactly as it does for a
|
|
271
|
+
// relation the issue simply does not have. The fields stay on the issue for the
|
|
272
|
+
// callers that gate on them (the permissions fail closed on `metadataError`).
|
|
254
273
|
|
|
255
274
|
const out = [];
|
|
256
275
|
lines.push('');
|