opencode-model-router 2.9.1 → 2.11.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/CHANGELOG.md +482 -0
- package/README.md +4 -2
- package/package.json +12 -5
- package/src/compat/background.ts +56 -19
- package/src/compat/child-history.ts +134 -0
- package/src/compat/child-report.ts +185 -0
- package/src/compat/child-session.ts +10 -0
- package/src/compat/session-lookup.ts +21 -0
- package/src/compat/v2-client.ts +124 -6
- package/src/compat/v2-hooks.ts +525 -203
- package/src/compat/v2-observations.ts +1 -0
- package/src/compat/v2-vocabulary.ts +14 -0
- package/src/executor/create.ts +47 -28
- package/src/executor/git.ts +226 -30
- package/src/executor/integrate/checks.ts +29 -11
- package/src/executor/integrate/land.ts +32 -2
- package/src/executor/integrate/queue.ts +95 -13
- package/src/executor/ledger.ts +16 -12
- package/src/executor/lfs-restore.ts +492 -0
- package/src/executor/paths.ts +7 -2
- package/src/executor/recovery.ts +2 -1
- package/src/executor/runtime.ts +1062 -243
- package/src/executor/slots/pool.ts +120 -19
- package/src/executor/slots/provision.ts +111 -23
- package/src/executor/slots/root.ts +81 -0
- package/src/executor/types.ts +28 -2
- package/src/executor/unattended.ts +6 -1
- package/src/executor/verify-trees.ts +507 -0
- package/src/guard/enforce.ts +2 -1
- package/src/guard/fingerprint.ts +9 -0
- package/src/guard/guards.ts +7 -1
- package/src/index.ts +191 -31
- package/src/router/answer-dedup.ts +198 -0
- package/src/router/common-dir.ts +241 -0
- package/src/router/config.ts +228 -40
- package/src/router/diff-handles.ts +322 -0
- package/src/router/diff-summary.ts +318 -0
- package/src/router/git-metadata-guard.ts +317 -0
- package/src/router/git-tools.ts +1136 -49
- package/src/router/read-only.ts +37 -13
- package/src/router/role-agents.ts +100 -36
- package/src/router/run-summary.ts +253 -0
- package/src/router/run-tools.ts +177 -25
- package/src/router/sessions.ts +23 -1
- package/src/router/tool-paths.ts +62 -4
- package/src/routing/classify/rules.ts +93 -14
- package/src/routing/roles/read-set.ts +10 -1
- package/src/routing/roles/work-root.ts +20 -3
- package/src/routing/wire/hint.ts +9 -2
- package/src/v2.ts +3 -1
- package/src/verify/exec.ts +454 -2
- package/src/verify/head.ts +6 -1
- package/src/verify/pending.ts +14 -1
- package/src/verify/plan-task.ts +86 -26
- package/src/verify/reference.ts +60 -7
- package/src/verify/runner.ts +14 -6
- package/src/verify/tree.ts +34 -10
- package/src/verify/types.ts +44 -0
- package/src/verify/wiring.ts +134 -22
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #108 slice 3: the `gd_` handles of a role agent's `router_git_diff` summary (OpenCode v2 roles mode only), and the pure
|
|
3
|
+
* helpers of their expansion through `router_git_show({ handle, lines?, side? })`. The git calls are in git-tools.ts.
|
|
4
|
+
*
|
|
5
|
+
* - A handle names one listed file version: `gd_` + the first 10 lowercase hex characters of an HMAC-SHA256 (a random 32-byte
|
|
6
|
+
* key per process) over the session, the repository it was reached through, both names, both blob ids, both modes, the status
|
|
7
|
+
* and, for a working-tree side, its lstat. It is a keyed digest, not a content hash: deterministic within a process, different
|
|
8
|
+
* per session, different for every file version, and lost on restart.
|
|
9
|
+
* - The store is process level (every plugin instance sees the same handles, like the dispatch-facts registry of sessions.ts):
|
|
10
|
+
* at most {@link MAX_HANDLES_PER_SESSION} per session and {@link MAX_HANDLES} overall (least recently used first; minting and
|
|
11
|
+
* expanding are uses), and a handle unused for {@link HANDLE_TTL_MS} is gone (swept lazily). `forgetHandles` drops a deleted
|
|
12
|
+
* session's handles.
|
|
13
|
+
* - A handle already held in the session by another entry is never reassigned: the newcomer gets no handle.
|
|
14
|
+
* - Only a stored, validated blob id ever reaches git: no handle argument, path or line range does.
|
|
15
|
+
*/
|
|
16
|
+
import { createHmac, randomBytes } from "node:crypto";
|
|
17
|
+
|
|
18
|
+
/** A handle as the summary shows it and `router_git_show` accepts it. */
|
|
19
|
+
export const HANDLE_RE = /^gd_[0-9a-f]{10}$/;
|
|
20
|
+
/** A handle unused for this long is gone (2 hours). */
|
|
21
|
+
export const HANDLE_TTL_MS = 2 * 60 * 60 * 1000;
|
|
22
|
+
/** Handles kept per session (least recently used dropped first). */
|
|
23
|
+
export const MAX_HANDLES_PER_SESSION = 1024;
|
|
24
|
+
/** Handles kept overall, across sessions (least recently used dropped first). */
|
|
25
|
+
export const MAX_HANDLES = 16384;
|
|
26
|
+
/** At most this many lines per expansion. */
|
|
27
|
+
export const MAX_EXPANSION_LINES = 400;
|
|
28
|
+
/** At most this many bytes of lines per expansion (whole lines; one longer line is cut here). */
|
|
29
|
+
export const MAX_EXPANSION_BYTES = 16 * 1024;
|
|
30
|
+
/** Largest blob an expansion reads. */
|
|
31
|
+
export const MAX_BLOB_BYTES = 4 * 1024 * 1024;
|
|
32
|
+
/** Highest line number `lines` accepts. */
|
|
33
|
+
export const MAX_LINE_NUMBER = 9_999_999;
|
|
34
|
+
|
|
35
|
+
/** How the session reached the repository a handle was listed in: its bound work root, or `root` (cross-repo). */
|
|
36
|
+
export type HandleVia =
|
|
37
|
+
| { readonly kind: "workRoot"; readonly workRoot: string }
|
|
38
|
+
| { readonly kind: "root"; readonly value: string; readonly root: string; readonly repository: string; readonly workRoot: string };
|
|
39
|
+
|
|
40
|
+
/** The old side of a listed file version: a blob of the index or of a commit. */
|
|
41
|
+
export interface HandleOldSide { readonly path: string; readonly oid: string; readonly mode: string }
|
|
42
|
+
/** The new side: a blob (`oid`), or the working tree (`worktree`, never read through a handle). */
|
|
43
|
+
export interface HandleNewSide { readonly path: string; readonly oid?: string; readonly mode: string; readonly worktree: boolean }
|
|
44
|
+
/** lstat of a working-tree side, as decimal strings: a handle changes when that file does. */
|
|
45
|
+
export interface WorktreeStat { readonly size: string; readonly mtimeNs: string; readonly ino: string }
|
|
46
|
+
|
|
47
|
+
/** What a summary knows about one listed file version (git-tools.ts). */
|
|
48
|
+
export interface HandleTarget {
|
|
49
|
+
/** The repository's top level, a real path. */
|
|
50
|
+
readonly toplevel: string;
|
|
51
|
+
/** A work root below the top level (repository-relative, `/`-separated). */
|
|
52
|
+
readonly scope?: string;
|
|
53
|
+
readonly old?: HandleOldSide;
|
|
54
|
+
readonly new?: HandleNewSide;
|
|
55
|
+
/** git's status letter (`M`, `A`, `D`, `R`, `C`, `T`). */
|
|
56
|
+
readonly status: string;
|
|
57
|
+
/** git counted the pair as binary (`--numstat` `-`): no side has lines. */
|
|
58
|
+
readonly binary?: boolean;
|
|
59
|
+
readonly worktreeStat?: WorktreeStat;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface HandleSpec extends HandleTarget { readonly sessionID: string; readonly via: HandleVia }
|
|
63
|
+
export interface HandleEntry extends HandleSpec { readonly handle: string; readonly key: string; lastUsed: number }
|
|
64
|
+
|
|
65
|
+
function fold(path: string): string { return process.platform === "win32" ? path.toLowerCase() : path; }
|
|
66
|
+
|
|
67
|
+
/** The canonical key a handle digests: one JSON array, paths of the file system case-folded on win32. */
|
|
68
|
+
export function handleKey(spec: HandleSpec): string {
|
|
69
|
+
const via = spec.via.kind === "workRoot" ? ["workRoot", fold(spec.via.workRoot)]
|
|
70
|
+
: ["root", spec.via.value, fold(spec.via.root), fold(spec.via.repository), fold(spec.via.workRoot)];
|
|
71
|
+
const stat = spec.worktreeStat === undefined ? null : [spec.worktreeStat.size, spec.worktreeStat.mtimeNs, spec.worktreeStat.ino];
|
|
72
|
+
return JSON.stringify([spec.sessionID, fold(spec.toplevel), spec.scope ?? null, via, spec.old?.path ?? null, spec.new?.path ?? null,
|
|
73
|
+
spec.old?.oid ?? null, spec.new?.oid ?? null, stat, spec.status, [spec.old?.mode ?? null, spec.new?.mode ?? null],
|
|
74
|
+
spec.new?.worktree ?? null, spec.binary === true]);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const BLOB_ID = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
|
|
78
|
+
const ZERO_ID = /^0+$/;
|
|
79
|
+
|
|
80
|
+
/** A full, non-zero blob id (40 or 64 lowercase hex characters): the only value of a handle that ever reaches git. */
|
|
81
|
+
export function isBlobId(oid: string | undefined): oid is string {
|
|
82
|
+
return oid !== undefined && BLOB_ID.test(oid) && !ZERO_ID.test(oid);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Regular file modes: the only sides with lines (a symlink is 120000, a submodule 160000). */
|
|
86
|
+
const FILE_MODES: ReadonlySet<string> = new Set(["100644", "100755"]);
|
|
87
|
+
|
|
88
|
+
/** Why one side of `target` has no lines to show through a handle, or undefined when it can be expanded. */
|
|
89
|
+
export function sideProblem(target: HandleTarget, side: "new" | "old"): "absent" | "worktree" | "binary" | "symlink" | "submodule" | "not-a-file" | undefined {
|
|
90
|
+
const chosen = side === "old" ? target.old : target.new;
|
|
91
|
+
if (chosen === undefined) return "absent";
|
|
92
|
+
if (side === "new" && target.new?.worktree === true) return "worktree";
|
|
93
|
+
if (target.binary === true) return "binary";
|
|
94
|
+
if (chosen.mode === "120000") return "symlink";
|
|
95
|
+
if (chosen.mode === "160000") return "submodule";
|
|
96
|
+
if (!FILE_MODES.has(chosen.mode) || !isBlobId(chosen.oid)) return "not-a-file";
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** A file version gets a handle only when one of its sides can be expanded. */
|
|
101
|
+
export function expandable(target: HandleTarget): boolean {
|
|
102
|
+
return sideProblem(target, "old") === undefined || sideProblem(target, "new") === undefined;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export interface HandleStoreOptions {
|
|
106
|
+
/** Clock (tests); default `Date.now`. */
|
|
107
|
+
now?: () => number;
|
|
108
|
+
/** The 10 hex characters of a key (tests force collisions with it); default the process's HMAC. */
|
|
109
|
+
digest?: (key: string) => string;
|
|
110
|
+
/** Collision notes; default `console.debug`. */
|
|
111
|
+
log?: (message: string) => void;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export interface HandleStore {
|
|
115
|
+
/** The handle of `spec` (stored, or refreshed when already held by the same entry); undefined when the handle is taken. */
|
|
116
|
+
mint(spec: HandleSpec): string | undefined;
|
|
117
|
+
/** The session's entry for `handle`, refreshed; undefined when unknown, expired or evicted. */
|
|
118
|
+
lookup(sessionID: string, handle: string): HandleEntry | undefined;
|
|
119
|
+
/** Drop every handle of `sessionID`. */
|
|
120
|
+
forget(sessionID: string): void;
|
|
121
|
+
/** Handles held (by `sessionID`, or overall). */
|
|
122
|
+
size(sessionID?: string): number;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function createHandleStore(options: HandleStoreOptions = {}): HandleStore {
|
|
126
|
+
const now = options.now ?? Date.now;
|
|
127
|
+
const secret = randomBytes(32);
|
|
128
|
+
const digest = options.digest ?? ((key: string) => createHmac("sha256", secret).update(key).digest("hex").slice(0, 10));
|
|
129
|
+
const log = options.log ?? ((message: string) => console.debug(message));
|
|
130
|
+
const sessions = new Map<string, Map<string, HandleEntry>>();
|
|
131
|
+
/** Every entry, least recently used first. */
|
|
132
|
+
const all = new Map<string, HandleEntry>();
|
|
133
|
+
const id = (sessionID: string, handle: string) => `${sessionID}\u0000${handle}`;
|
|
134
|
+
|
|
135
|
+
const drop = (entry: HandleEntry) => {
|
|
136
|
+
all.delete(id(entry.sessionID, entry.handle));
|
|
137
|
+
const session = sessions.get(entry.sessionID);
|
|
138
|
+
session?.delete(entry.handle);
|
|
139
|
+
if (session?.size === 0) sessions.delete(entry.sessionID);
|
|
140
|
+
};
|
|
141
|
+
const use = (entry: HandleEntry) => {
|
|
142
|
+
entry.lastUsed = now();
|
|
143
|
+
const key = id(entry.sessionID, entry.handle);
|
|
144
|
+
all.delete(key);
|
|
145
|
+
all.set(key, entry);
|
|
146
|
+
const session = sessions.get(entry.sessionID);
|
|
147
|
+
session?.delete(entry.handle);
|
|
148
|
+
session?.set(entry.handle, entry);
|
|
149
|
+
};
|
|
150
|
+
const sweep = () => {
|
|
151
|
+
const expired = now() - HANDLE_TTL_MS;
|
|
152
|
+
for (const entry of all.values()) {
|
|
153
|
+
if (entry.lastUsed > expired) break;
|
|
154
|
+
drop(entry);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
return {
|
|
159
|
+
mint(spec) {
|
|
160
|
+
sweep();
|
|
161
|
+
const key = handleKey(spec);
|
|
162
|
+
const handle = `gd_${digest(key)}`;
|
|
163
|
+
if (!HANDLE_RE.test(handle)) return undefined;
|
|
164
|
+
let session = sessions.get(spec.sessionID);
|
|
165
|
+
const held = session?.get(handle);
|
|
166
|
+
if (held !== undefined) {
|
|
167
|
+
if (held.key !== key) {
|
|
168
|
+
log(`[model-router] router_git: ${handle} is already held by another file version of this session; no handle for the newcomer`);
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
use(held);
|
|
172
|
+
return handle;
|
|
173
|
+
}
|
|
174
|
+
const entry: HandleEntry = {
|
|
175
|
+
sessionID: spec.sessionID, via: { ...spec.via }, toplevel: spec.toplevel, status: spec.status,
|
|
176
|
+
...(spec.scope === undefined ? {} : { scope: spec.scope }),
|
|
177
|
+
...(spec.old === undefined ? {} : { old: { ...spec.old } }),
|
|
178
|
+
...(spec.new === undefined ? {} : { new: { ...spec.new } }),
|
|
179
|
+
...(spec.binary === true ? { binary: true } : {}),
|
|
180
|
+
...(spec.worktreeStat === undefined ? {} : { worktreeStat: { ...spec.worktreeStat } }),
|
|
181
|
+
handle, key, lastUsed: now(),
|
|
182
|
+
};
|
|
183
|
+
if (session === undefined) {
|
|
184
|
+
session = new Map();
|
|
185
|
+
sessions.set(spec.sessionID, session);
|
|
186
|
+
}
|
|
187
|
+
session.set(handle, entry);
|
|
188
|
+
all.set(id(spec.sessionID, handle), entry);
|
|
189
|
+
while (session.size > MAX_HANDLES_PER_SESSION) drop(session.values().next().value as HandleEntry);
|
|
190
|
+
while (all.size > MAX_HANDLES) drop(all.values().next().value as HandleEntry);
|
|
191
|
+
return handle;
|
|
192
|
+
},
|
|
193
|
+
lookup(sessionID, handle) {
|
|
194
|
+
sweep();
|
|
195
|
+
const entry = sessions.get(sessionID)?.get(handle);
|
|
196
|
+
if (entry === undefined || entry.sessionID !== sessionID) return undefined;
|
|
197
|
+
use(entry);
|
|
198
|
+
return entry;
|
|
199
|
+
},
|
|
200
|
+
forget(sessionID) {
|
|
201
|
+
for (const entry of [...(sessions.get(sessionID)?.values() ?? [])]) drop(entry);
|
|
202
|
+
},
|
|
203
|
+
size(sessionID) {
|
|
204
|
+
return sessionID === undefined ? all.size : sessions.get(sessionID)?.size ?? 0;
|
|
205
|
+
},
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** The process's store: every plugin instance shares it. */
|
|
210
|
+
const processStore = createHandleStore();
|
|
211
|
+
|
|
212
|
+
/** Mint `spec`'s handle in the process store. */
|
|
213
|
+
export function mintHandle(spec: HandleSpec): string | undefined { return processStore.mint(spec); }
|
|
214
|
+
/** Look a session's handle up in the process store. */
|
|
215
|
+
export function lookupHandle(sessionID: string, handle: string): HandleEntry | undefined { return processStore.lookup(sessionID, handle); }
|
|
216
|
+
/** Drop a deleted session's handles (index.ts, `session.deleted`). */
|
|
217
|
+
export function forgetHandles(sessionID: string): void { processStore.forget(sessionID); }
|
|
218
|
+
|
|
219
|
+
/** A `lines` argument: from `start`, through `end` when given (1-based, inclusive). */
|
|
220
|
+
export interface LineRange { readonly start: number; readonly end?: number }
|
|
221
|
+
|
|
222
|
+
/** Parse `lines`: `"a"` or `"a-b"` with 1 <= a <= b <= {@link MAX_LINE_NUMBER}; undefined for anything else. */
|
|
223
|
+
export function parseLineRange(text: string): LineRange | undefined {
|
|
224
|
+
const match = /^([1-9]\d{0,6})(?:-([1-9]\d{0,6}))?$/.exec(text);
|
|
225
|
+
if (match === null) return undefined;
|
|
226
|
+
const start = Number(match[1]);
|
|
227
|
+
if (match[2] === undefined) return start <= MAX_LINE_NUMBER ? { start } : undefined;
|
|
228
|
+
const end = Number(match[2]);
|
|
229
|
+
return start <= end && end <= MAX_LINE_NUMBER ? { start, end } : undefined;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* #108 slice 5: the arguments of an expansion `router_git_show` would run: a `handle` that is `gd_` + 10 lowercase hex characters,
|
|
234
|
+
* `lines` absent or `"a"`/`"a-b"` as {@link parseLineRange} accepts, `side` absent or `new`/`old`. Anything else is refused before
|
|
235
|
+
* git runs, so the guard never counts it as a read nor gives it the expansion fingerprint.
|
|
236
|
+
*/
|
|
237
|
+
export function isWellFormedExpansion(args: Readonly<Record<string, unknown>>): boolean {
|
|
238
|
+
const { handle, lines, side } = args;
|
|
239
|
+
return typeof handle === "string" && HANDLE_RE.test(handle)
|
|
240
|
+
&& (lines === undefined || (typeof lines === "string" && parseLineRange(lines) !== undefined))
|
|
241
|
+
&& (side === undefined || side === "new" || side === "old");
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** A blob's lines as git numbers them: split at LF (a CR stays with its line); a last line without LF counts. */
|
|
245
|
+
export function splitLines(text: string): string[] {
|
|
246
|
+
if (text === "") return [];
|
|
247
|
+
const lines = text.split("\n");
|
|
248
|
+
if (lines.at(-1) === "") lines.pop();
|
|
249
|
+
return lines;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function plural(count: number, one: string, many = `${one}s`): string {
|
|
253
|
+
return `${count} ${count === 1 ? one : many}`;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* `text` cut to at most `max` UTF-8 bytes, at a character boundary: the cut moves back over continuation bytes to the start of
|
|
258
|
+
* the character it would split, so no replacement character is made and a genuine trailing U+FFFD of the content is kept.
|
|
259
|
+
*/
|
|
260
|
+
export function cutBytes(text: string, max: number): string {
|
|
261
|
+
const encoded = Buffer.from(text);
|
|
262
|
+
if (encoded.length <= max) return text;
|
|
263
|
+
let end = Math.max(0, max);
|
|
264
|
+
while (end > 0 && (encoded[end]! & 0xc0) === 0x80) end--;
|
|
265
|
+
return encoded.subarray(0, end).toString("utf8");
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export interface Expansion {
|
|
269
|
+
readonly handle: string;
|
|
270
|
+
readonly side: "new" | "old";
|
|
271
|
+
/** The path as shown (quoted, redacted). */
|
|
272
|
+
readonly path: string;
|
|
273
|
+
readonly oid: string;
|
|
274
|
+
/** The blob, decoded. */
|
|
275
|
+
readonly text: string;
|
|
276
|
+
readonly range?: LineRange;
|
|
277
|
+
/** Applied to every line before it is measured (credential redaction). */
|
|
278
|
+
readonly redact: (line: string) => string;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* The answer of one expansion: a header line, then lines `start..end` of the blob, each with LF, at most
|
|
283
|
+
* {@link MAX_EXPANSION_LINES} lines or {@link MAX_EXPANSION_BYTES} bytes of whole lines (one longer line is cut there, with a
|
|
284
|
+
* marker), then, when the cap stopped it, where to continue. An `end` past the last line is clipped (the header says so); a
|
|
285
|
+
* `start` past it is refused (`reason`).
|
|
286
|
+
*/
|
|
287
|
+
export function renderExpansion(input: Expansion): { ok: true; text: string } | { ok: false; reason: string } {
|
|
288
|
+
const all = splitLines(input.text);
|
|
289
|
+
const total = all.length;
|
|
290
|
+
const label = `[router_git] ${input.handle} ${input.side} ${input.path} @ ${input.oid.slice(0, 12)}`;
|
|
291
|
+
const start = input.range?.start ?? 1;
|
|
292
|
+
const asked = input.range?.end;
|
|
293
|
+
if (start > total) {
|
|
294
|
+
if (input.range === undefined) return { ok: true, text: `${label}, empty (0 lines)\n` };
|
|
295
|
+
return {
|
|
296
|
+
ok: false,
|
|
297
|
+
reason: `${input.handle}: lines ${start}${asked === undefined ? "" : `-${asked}`} start past the end of ${input.path} (it has ${plural(total, "line")})`,
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
const end = Math.min(asked ?? total, total);
|
|
301
|
+
const shown: string[] = [];
|
|
302
|
+
let size = 0;
|
|
303
|
+
let cut = false;
|
|
304
|
+
for (let number = start; number <= end && shown.length < MAX_EXPANSION_LINES; number++) {
|
|
305
|
+
const line = input.redact(all[number - 1]!);
|
|
306
|
+
const bytes = Buffer.byteLength(line) + 1;
|
|
307
|
+
if (bytes > MAX_EXPANSION_BYTES && shown.length === 0) {
|
|
308
|
+
shown.push(cutBytes(line, MAX_EXPANSION_BYTES - 1)); // with its LF, at most MAX_EXPANSION_BYTES
|
|
309
|
+
cut = true;
|
|
310
|
+
break;
|
|
311
|
+
}
|
|
312
|
+
if (size + bytes > MAX_EXPANSION_BYTES) break;
|
|
313
|
+
shown.push(line);
|
|
314
|
+
size += bytes;
|
|
315
|
+
}
|
|
316
|
+
const last = start + shown.length - 1;
|
|
317
|
+
const clipped = asked !== undefined && asked > total ? ` (${asked} is past the end)` : "";
|
|
318
|
+
let text = `${label}, lines ${start}-${last} of ${total}${clipped}\n${shown.map(line => `${line}\n`).join("")}`;
|
|
319
|
+
if (cut) text += `[router_git] line ${start} is longer than ${MAX_EXPANSION_BYTES} bytes; cut there\n`;
|
|
320
|
+
if (last < end) text += `[router_git] lines ${start}-${last} of ${total} shown; call again with lines ${last + 1}-${end}\n`;
|
|
321
|
+
return { ok: true, text };
|
|
322
|
+
}
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #108 slice 1: the stat-first `router_git_diff` of OpenCode v2 roles mode (role agents only; tiers mode, the root session
|
|
3
|
+
* and OpenCode v1 keep the plain patch). Pure helpers: the git calls are in git-tools.ts (`inspectGit` with `summary`).
|
|
4
|
+
*
|
|
5
|
+
* - A `patch`/`cached` diff without `path` whose patch exceeds {@link DIFF_SUMMARY_THRESHOLD_BYTES} is answered with one
|
|
6
|
+
* line per file (`+added -removed`), never hunks; `path` (or `mode: "stat"` / `"name-only"`) gives the usual output.
|
|
7
|
+
* - Lockfiles, snapshots, and goldens and fixtures that are not code or tests ({@link excludedKind}, by a file's new path)
|
|
8
|
+
* are always listed as `content excluded (<kind>, +a/-b)` instead of their hunks, even in a small patch: their presence
|
|
9
|
+
* is never dropped, their content is fetched with `path`.
|
|
10
|
+
* - Sensitive files (sensitive-paths.ts) appear in a summary by name only, as `sensitive: content withheld`.
|
|
11
|
+
* - Every list is bounded to {@link SUMMARY_MAX_BYTES} and gives the exact number of entries it leaves out, if any; in a
|
|
12
|
+
* summary, notes of at most 1 KiB (git's warnings, the skipped-links notice) may follow that line.
|
|
13
|
+
* - Slice 3: a shown line that is not sensitive may end with its `gd_` handle (`SummaryEntry.handle`, minted by git-tools.ts
|
|
14
|
+
* through diff-handles.ts): a keyed digest of 10 hex characters, never a content hash. Lines left out by the bound get none.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** A `patch`/`cached` diff without `path` whose patch is larger than this many bytes is summarized. */
|
|
18
|
+
export const DIFF_SUMMARY_THRESHOLD_BYTES = 8 * 1024;
|
|
19
|
+
/** Bound of a summary, and of the excluded-content list after a patch, in UTF-8 bytes. */
|
|
20
|
+
export const SUMMARY_MAX_BYTES = 4096;
|
|
21
|
+
/** Bound of the notes (git's warnings, skipped linked directories) a summary carries, inside {@link SUMMARY_MAX_BYTES}. */
|
|
22
|
+
const FOOTER_MAX_BYTES = 1024;
|
|
23
|
+
/** Room kept for the last line (the omitted count). */
|
|
24
|
+
const OMITTED_RESERVE_BYTES = 240;
|
|
25
|
+
|
|
26
|
+
/** Lockfiles, by exact file name at any depth. */
|
|
27
|
+
export const LOCKFILE_NAMES: readonly string[] = Object.freeze([
|
|
28
|
+
"package-lock.json", "npm-shrinkwrap.json", "pnpm-lock.yaml", "yarn.lock", "bun.lock", "bun.lockb", "Cargo.lock",
|
|
29
|
+
"poetry.lock", "uv.lock", "Pipfile.lock", "composer.lock", "Gemfile.lock", "go.sum",
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
export type ExcludedKind = "lockfile" | "snapshot" | "fixture" | "golden";
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* File extensions of code (compared case-insensitively). A golden or fixture with one of these, or a test file
|
|
36
|
+
* ({@link TEST_FILE_RE}), is never excluded: code and tests are always shown, wherever they live.
|
|
37
|
+
*/
|
|
38
|
+
export const CODE_EXTENSIONS: readonly string[] = Object.freeze([
|
|
39
|
+
".ts", ".tsx", ".mts", ".cts", ".js", ".jsx", ".mjs", ".cjs", ".vue", ".svelte", ".py", ".pyi", ".go", ".rs", ".java", ".kt",
|
|
40
|
+
".kts", ".scala", ".groovy", ".rb", ".php", ".cs", ".fs", ".vb", ".c", ".h", ".cc", ".cpp", ".cxx", ".hpp", ".hh", ".m", ".mm",
|
|
41
|
+
".swift", ".dart", ".lua", ".pl", ".pm", ".r", ".ex", ".exs", ".erl", ".clj", ".zig", ".nim", ".sh", ".bash", ".zsh", ".fish",
|
|
42
|
+
".ps1", ".psm1", ".psd1", ".bat", ".cmd",
|
|
43
|
+
]);
|
|
44
|
+
/** A test file by name: `<name>.test.<ext>` or `<name>.spec.<ext>`. */
|
|
45
|
+
export const TEST_FILE_RE = /\.(?:test|spec)\.[^./]+$/i;
|
|
46
|
+
|
|
47
|
+
/** A file name that is code or a test ({@link CODE_EXTENSIONS}, {@link TEST_FILE_RE}). */
|
|
48
|
+
function codeOrTest(name: string): boolean {
|
|
49
|
+
const lower = name.toLowerCase();
|
|
50
|
+
return TEST_FILE_RE.test(name) || CODE_EXTENSIONS.some(extension => lower.endsWith(extension));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The fixed list (#108 P10) of paths whose content a role's `router_git_diff` leaves out by default, for a
|
|
55
|
+
* repository-relative, `/`-separated path: a lockfile ({@link LOCKFILE_NAMES}), a snapshot (`**\/__snapshots__/**`,
|
|
56
|
+
* `*.snap` at any depth), a golden (`test/golden/**`) or a fixture (`**\/fixtures/**`). A golden or fixture that is code or
|
|
57
|
+
* a test ({@link CODE_EXTENSIONS}, {@link TEST_FILE_RE}) is not excluded. Undefined for any other path.
|
|
58
|
+
*/
|
|
59
|
+
export function excludedKind(path: string): ExcludedKind | undefined {
|
|
60
|
+
const segments = path.split("/").filter(segment => segment !== "");
|
|
61
|
+
const name = segments.at(-1) ?? "";
|
|
62
|
+
const directories = segments.slice(0, -1);
|
|
63
|
+
if (LOCKFILE_NAMES.includes(name)) return "lockfile";
|
|
64
|
+
if (directories.includes("__snapshots__") || name.endsWith(".snap")) return "snapshot";
|
|
65
|
+
if (codeOrTest(name)) return undefined;
|
|
66
|
+
if (segments.length > 2 && segments[0] === "test" && segments[1] === "golden") return "golden";
|
|
67
|
+
if (directories.includes("fixtures")) return "fixture";
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** One record of `git diff --numstat -z`: the (new) path, the old path of a rename or copy, and the line counts (absent: binary). */
|
|
72
|
+
export interface NumstatEntry {
|
|
73
|
+
readonly path: string;
|
|
74
|
+
readonly from?: string;
|
|
75
|
+
readonly added?: number;
|
|
76
|
+
readonly removed?: number;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Parse `git diff --numstat -z`: `<added>\t<removed>\t<path>\0`, or `<added>\t<removed>\t\0<from>\0<to>\0` for a rename. */
|
|
80
|
+
export function parseNumstat(raw: string): NumstatEntry[] {
|
|
81
|
+
const fields = raw.split("\0");
|
|
82
|
+
const entries: NumstatEntry[] = [];
|
|
83
|
+
for (let index = 0; index < fields.length; index++) {
|
|
84
|
+
const record = /^(-|\d+)\t(-|\d+)\t([\s\S]*)$/.exec(fields[index]!);
|
|
85
|
+
if (record === null) continue;
|
|
86
|
+
const counts = record[1] === "-" || record[2] === "-" ? {} : { added: Number(record[1]), removed: Number(record[2]) };
|
|
87
|
+
if (record[3] !== "") {
|
|
88
|
+
entries.push({ path: record[3]!, ...counts });
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
const from = fields[index + 1];
|
|
92
|
+
const to = fields[index + 2];
|
|
93
|
+
index += 2;
|
|
94
|
+
if (from && to) entries.push({ path: to, from, ...counts });
|
|
95
|
+
}
|
|
96
|
+
return entries;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The excluded kind of an entry, by its new path only: a file renamed out of a fixture directory into the code is shown, one
|
|
101
|
+
* renamed into it is listed (both its names are then left out of the patch).
|
|
102
|
+
*/
|
|
103
|
+
export function entryExcludedKind(entry: NumstatEntry): ExcludedKind | undefined {
|
|
104
|
+
return excludedKind(entry.path);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** One record of `git diff --raw -z --no-abbrev`: both modes and blob ids, git's status letter, the (new) path and a rename's old one. */
|
|
108
|
+
export interface RawEntry {
|
|
109
|
+
readonly oldMode: string;
|
|
110
|
+
readonly newMode: string;
|
|
111
|
+
readonly oldOid: string;
|
|
112
|
+
readonly newOid: string;
|
|
113
|
+
readonly status: string;
|
|
114
|
+
readonly path: string;
|
|
115
|
+
readonly from?: string;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const RAW_HEADER = /^:([0-7]{6}) ([0-7]{6}) ([0-9a-f]{40}|[0-9a-f]{64}) ([0-9a-f]{40}|[0-9a-f]{64}) ([ACDMRTUXB])\d{0,3}$/;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Parse `git diff --raw -z --no-abbrev`: `:<mode> <mode> <oid> <oid> <status>\0<path>\0`, or `…R<score>\0<from>\0<to>\0` for a
|
|
122
|
+
* rename or copy. Undefined when any record is malformed (no partial listing is ever used).
|
|
123
|
+
*/
|
|
124
|
+
export function parseRawDiff(raw: string): RawEntry[] | undefined {
|
|
125
|
+
const fields = raw.split("\0");
|
|
126
|
+
if (fields.at(-1) === "") fields.pop();
|
|
127
|
+
const entries: RawEntry[] = [];
|
|
128
|
+
for (let index = 0; index < fields.length; index++) {
|
|
129
|
+
const header = RAW_HEADER.exec(fields[index]!);
|
|
130
|
+
if (header === null) return undefined;
|
|
131
|
+
const [oldMode, newMode, oldOid, newOid, status] = [header[1]!, header[2]!, header[3]!, header[4]!, header[5]!];
|
|
132
|
+
const pair = status === "R" || status === "C";
|
|
133
|
+
const first = fields[index + 1];
|
|
134
|
+
const second = pair ? fields[index + 2] : undefined;
|
|
135
|
+
if (!first || (pair && !second)) return undefined;
|
|
136
|
+
index += pair ? 2 : 1;
|
|
137
|
+
entries.push(pair ? { oldMode, newMode, oldOid, newOid, status, path: second!, from: first } : { oldMode, newMode, oldOid, newOid, status, path: first });
|
|
138
|
+
}
|
|
139
|
+
return entries;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Names of a record or entry, as one comparable key. */
|
|
143
|
+
function namesKey(entry: { readonly path: string; readonly from?: string }): string {
|
|
144
|
+
return JSON.stringify([entry.from ?? null, entry.path]);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* The raw record of each `--numstat` entry, matched in git's order by path and old path. `--raw` may list records `--numstat`
|
|
149
|
+
* leaves out (a file whose stat data changed but whose content did not, which `diff.autoRefreshIndex=false` keeps in the raw
|
|
150
|
+
* listing); those are skipped, never paired with another entry. A name listed more than once (an unmerged path) gets no record.
|
|
151
|
+
* Undefined when an entry has no record at all: the two listings disagree (the working tree changed between them).
|
|
152
|
+
*/
|
|
153
|
+
export function pairRawEntries(entries: readonly NumstatEntry[], raw: readonly RawEntry[]): (RawEntry | undefined)[] | undefined {
|
|
154
|
+
const counts = new Map<string, number>();
|
|
155
|
+
for (const record of raw) counts.set(namesKey(record), (counts.get(namesKey(record)) ?? 0) + 1);
|
|
156
|
+
const paired: (RawEntry | undefined)[] = [];
|
|
157
|
+
let cursor = 0;
|
|
158
|
+
for (const entry of entries) {
|
|
159
|
+
const wanted = namesKey(entry);
|
|
160
|
+
while (cursor < raw.length && namesKey(raw[cursor]!) !== wanted) cursor++;
|
|
161
|
+
if (cursor === raw.length) return undefined;
|
|
162
|
+
paired.push(counts.get(wanted) === 1 ? raw[cursor] : undefined);
|
|
163
|
+
cursor++;
|
|
164
|
+
}
|
|
165
|
+
return paired;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** An entry of a summary: a changed file, a file whose content is excluded, or a sensitive file (name only). */
|
|
169
|
+
export interface SummaryEntry extends NumstatEntry {
|
|
170
|
+
readonly excluded?: ExcludedKind;
|
|
171
|
+
readonly sensitive?: boolean;
|
|
172
|
+
/** Slice 3: the `gd_` handle of this file version (never on a sensitive entry). */
|
|
173
|
+
readonly handle?: string;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** How a path is shown (git's quoting, credential redaction): supplied by git-tools.ts. */
|
|
177
|
+
export type PathDisplay = (path: string) => string;
|
|
178
|
+
|
|
179
|
+
/** One line of a summary or of the excluded-content list. A sensitive entry never shows its counts, nor a handle. */
|
|
180
|
+
export function summaryLine(entry: SummaryEntry, display: PathDisplay): string {
|
|
181
|
+
const name = entry.from === undefined ? display(entry.path) : `${display(entry.from)} => ${display(entry.path)}`;
|
|
182
|
+
if (entry.sensitive === true) return `${name} | sensitive: content withheld`;
|
|
183
|
+
const handle = entry.handle === undefined ? "" : ` | ${entry.handle}`;
|
|
184
|
+
if (entry.excluded !== undefined) {
|
|
185
|
+
return `${name} | content excluded (${entry.excluded}, ${entry.added === undefined ? "binary" : `+${entry.added}/-${entry.removed ?? 0}`})${handle}`;
|
|
186
|
+
}
|
|
187
|
+
return `${name} | ${entry.added === undefined ? "binary" : `+${entry.added} -${entry.removed ?? 0}`}${handle}`;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** Slice 3: the header sentence of a list whose lines carry handles. */
|
|
191
|
+
export const EXPAND_SENTENCE = "Expand a file's lines with router_git_show({ handle, lines: \"a-b\" }).";
|
|
192
|
+
/** Slice 3: added for a diff that reads the working tree (its new side is never read through a handle). */
|
|
193
|
+
export const WORKTREE_SENTENCE = "Handles expand the old side; read the working-tree side with read.";
|
|
194
|
+
/** Slice 3: a list with handles; `worktree` when the diff reads the working tree. */
|
|
195
|
+
export interface SummaryHandles { readonly worktree: boolean }
|
|
196
|
+
|
|
197
|
+
function expandSentences(handles: SummaryHandles | undefined): string {
|
|
198
|
+
return handles === undefined ? "" : ` ${EXPAND_SENTENCE}${handles.worktree ? ` ${WORKTREE_SENTENCE}` : ""}`;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const bytes = (text: string) => Buffer.byteLength(text);
|
|
202
|
+
|
|
203
|
+
/** `text` cut to at most `max` UTF-8 bytes at a line end (or, for one long line, a character), marked when cut. */
|
|
204
|
+
function boundedText(text: string, max: number): string {
|
|
205
|
+
if (bytes(text) <= max) return text;
|
|
206
|
+
const marker = "\n[router_git] notes cut\n";
|
|
207
|
+
let kept = Buffer.from(text).subarray(0, Math.max(0, max - bytes(marker))).toString("utf8").replace(/\uFFFD+$/, "");
|
|
208
|
+
const newline = kept.lastIndexOf("\n");
|
|
209
|
+
if (newline > 0) kept = kept.slice(0, newline);
|
|
210
|
+
return `${kept}${marker}`;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function plural(count: number, one: string, many = `${one}s`): string {
|
|
214
|
+
return `${count} ${count === 1 ? one : many}`;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** The category counts of `entries`: `2 changed, 1 content excluded, 1 sensitive` (empty categories left out). */
|
|
218
|
+
function categories(entries: readonly SummaryEntry[]): string {
|
|
219
|
+
const sensitive = entries.filter(entry => entry.sensitive === true).length;
|
|
220
|
+
const excluded = entries.filter(entry => entry.sensitive !== true && entry.excluded !== undefined).length;
|
|
221
|
+
const changed = entries.length - sensitive - excluded;
|
|
222
|
+
return [changed > 0 ? `${changed} changed` : "", excluded > 0 ? `${excluded} content excluded` : "", sensitive > 0 ? `${sensitive} sensitive` : ""]
|
|
223
|
+
.filter(Boolean).join(", ");
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** The notes of a list (`footer` cut to {@link FOOTER_MAX_BYTES}, ending with a newline). */
|
|
227
|
+
function boundedNotes(footer: string): string {
|
|
228
|
+
return footer === "" ? "" : boundedText(footer.endsWith("\n") ? footer : `${footer}\n`, FOOTER_MAX_BYTES);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* How many of `entries`, in order after `head`, fit while the whole text (with the omitted-count line and `notes`) stays
|
|
233
|
+
* within `max` bytes. The first entry that does not fit ends the list.
|
|
234
|
+
*/
|
|
235
|
+
function fittingCount(head: string, entries: readonly SummaryEntry[], display: PathDisplay, notes: string, max: number): number {
|
|
236
|
+
let size = bytes(`${head}\n`);
|
|
237
|
+
let shown = 0;
|
|
238
|
+
for (const entry of entries) {
|
|
239
|
+
const line = bytes(`${summaryLine(entry, display)}\n`);
|
|
240
|
+
if (size + line + OMITTED_RESERVE_BYTES + bytes(notes) > max) break;
|
|
241
|
+
size += line;
|
|
242
|
+
shown++;
|
|
243
|
+
}
|
|
244
|
+
return shown;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Lines of `entries` in order after `head`, while the whole text (with the omitted-count line and `footer`) stays within
|
|
249
|
+
* `max` bytes. The first entry that does not fit ends the list; the omitted line gives the exact count of the rest.
|
|
250
|
+
*/
|
|
251
|
+
function boundedList(head: string, entries: readonly SummaryEntry[], display: PathDisplay, footer: string, max: number,
|
|
252
|
+
omitted: (rest: readonly SummaryEntry[]) => string, limit = Number.POSITIVE_INFINITY): string {
|
|
253
|
+
const notes = boundedNotes(footer);
|
|
254
|
+
const shown = Math.min(limit, fittingCount(head, entries, display, notes, max));
|
|
255
|
+
let text = `${head}\n${entries.slice(0, shown).map(entry => `${summaryLine(entry, display)}\n`).join("")}`;
|
|
256
|
+
const rest = entries.slice(shown);
|
|
257
|
+
if (rest.length > 0) text += `${omitted(rest)}\n`;
|
|
258
|
+
return `${text}${notes}`;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** Why the patch was not shown: it exceeds the threshold, or too many excluded files to leave out of it. */
|
|
262
|
+
export type SummaryReason = "large" | "many-excluded";
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Options of {@link renderDiffSummary}: why, the notes, and (slice 3) whether lines carry handles and at most how many lines to
|
|
266
|
+
* show (`limit`: the count {@link diffSummaryShown} gave for the lines with handles, so that a line left without one, shorter, is
|
|
267
|
+
* never shown in the room its handle would have taken).
|
|
268
|
+
*/
|
|
269
|
+
export interface SummaryOptions { readonly reason: SummaryReason; readonly footer?: string; readonly handles?: SummaryHandles; readonly limit?: number }
|
|
270
|
+
/** Options of {@link renderExcludedList}, as {@link SummaryOptions}. */
|
|
271
|
+
export interface ListOptions { readonly handles?: SummaryHandles; readonly limit?: number }
|
|
272
|
+
|
|
273
|
+
function summaryHead(entries: readonly SummaryEntry[], options: SummaryOptions): string {
|
|
274
|
+
const counted = entries.filter(entry => entry.sensitive !== true);
|
|
275
|
+
const added = counted.reduce((sum, entry) => sum + (entry.added ?? 0), 0);
|
|
276
|
+
const removed = counted.reduce((sum, entry) => sum + (entry.removed ?? 0), 0);
|
|
277
|
+
const why = options.reason === "large"
|
|
278
|
+
? `the patch exceeds ${DIFF_SUMMARY_THRESHOLD_BYTES / 1024} KiB, so no hunks are shown`
|
|
279
|
+
: "too many files with excluded content to leave out of the patch, so no hunks are shown";
|
|
280
|
+
return `[router_git] diff summary: ${plural(entries.length, "file")}${entries.length > 0 ? ` (${categories(entries)})` : ""}, `
|
|
281
|
+
+ `+${added} -${removed}${counted.length < entries.length ? " outside sensitive files" : ""}; ${why}. `
|
|
282
|
+
+ `Call router_git_diff again with path for one file's patch.${expandSentences(options.handles)}`;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* The summary of a role's `router_git_diff`: a header with the totals (sensitive files' counts left out), one line per
|
|
287
|
+
* file in git's order, the exact count of the lines left out, then `footer` (git's warnings, skipped directories; cut to
|
|
288
|
+
* 1 KiB). At most {@link SUMMARY_MAX_BYTES} bytes.
|
|
289
|
+
*/
|
|
290
|
+
export function renderDiffSummary(entries: readonly SummaryEntry[], display: PathDisplay, options: SummaryOptions): string {
|
|
291
|
+
return boundedList(summaryHead(entries, options), entries, display, options.footer ?? "", SUMMARY_MAX_BYTES,
|
|
292
|
+
rest => `[router_git] ${plural(rest.length, "more entry", "more entries")} not shown (${categories(rest)}) to keep this summary within `
|
|
293
|
+
+ `${SUMMARY_MAX_BYTES} bytes; call again with path for one file.`, options.limit);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** Slice 3: how many of `entries` {@link renderDiffSummary} shows (the others get no handle). */
|
|
297
|
+
export function diffSummaryShown(entries: readonly SummaryEntry[], display: PathDisplay, options: SummaryOptions): number {
|
|
298
|
+
return fittingCount(summaryHead(entries, options), entries, display, boundedNotes(options.footer ?? ""), SUMMARY_MAX_BYTES);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function excludedHead(handles: SummaryHandles | undefined): string {
|
|
302
|
+
return handles === undefined
|
|
303
|
+
? "[router_git] content excluded from this patch (call router_git_diff again with path to see one):"
|
|
304
|
+
: `[router_git] content excluded from this patch (call router_git_diff again with path to see one).${expandSentences(handles)}`;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/** The list of files left out of a small patch (their kinds and counts), appended after it. At most {@link SUMMARY_MAX_BYTES} bytes. */
|
|
308
|
+
export function renderExcludedList(entries: readonly SummaryEntry[], display: PathDisplay, options: ListOptions = {}): string {
|
|
309
|
+
if (entries.length === 0) return "";
|
|
310
|
+
return boundedList(excludedHead(options.handles), entries, display, "",
|
|
311
|
+
SUMMARY_MAX_BYTES, rest => `[router_git] ${plural(rest.length, "more excluded entry", "more excluded entries")} not shown to keep this list within `
|
|
312
|
+
+ `${SUMMARY_MAX_BYTES} bytes.`, options.limit);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/** Slice 3: how many of `entries` {@link renderExcludedList} shows (the others get no handle). */
|
|
316
|
+
export function excludedListShown(entries: readonly SummaryEntry[], display: PathDisplay, options: ListOptions = {}): number {
|
|
317
|
+
return entries.length === 0 ? 0 : fittingCount(excludedHead(options.handles), entries, display, "", SUMMARY_MAX_BYTES);
|
|
318
|
+
}
|