Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.
TypeScript
mods/diff: a backend seam, git as the built-in backend
poteat2142ececc43c
diff --git a/mods/diff/hooks/backend/backend-of.ts b/mods/diff/hooks/backend/backend-of.tsnew file mode 100644index 00000000..46d0159b--- /dev/null+++ b/mods/diff/hooks/backend/backend-of.ts@@ -0,0 +1,29 @@+import Git from '../git'+import type { Backend, BackendHost, BackendProbe } from './types'++/**+ * The backend holding the session's directory: the first of `probes` that+ * answers one, else git when a git working tree holds it, else none. The+ * probes go first so a probe may claim a working copy by its own rule+ * (the nearer of two markers, say); a probe answers null wherever git+ * should govern.+ *+ * @param host the bound host's runner and probes+ * @param probes probes for other version-control systems, in order+ * (INSTALLED_BACKEND_PROBES at the pane; none as published)+ * @returns the pinned backend, or null outside any working tree+ */+export async function backendOf(+ host: BackendHost,+ probes: Iterable<BackendProbe>,+): Promise<Backend | null> {+ for (const probe of probes) {+ const backend = await probe(host)++ if (backend) {+ return backend+ }+ }++ return Git.gitBackendOf(host)+}diff --git a/mods/diff/hooks/backend/index.ts b/mods/diff/hooks/backend/index.tsnew file mode 100644index 00000000..69344a6e--- /dev/null+++ b/mods/diff/hooks/backend/index.ts@@ -0,0 +1,5 @@+export * from './backend-of.js'+export * from './installed-backend-probes.js'+export * from './types'++export * as default from '.'diff --git a/mods/diff/hooks/backend/installed-backend-probes.ts b/mods/diff/hooks/backend/installed-backend-probes.tsnew file mode 100644index 00000000..3d5dabfc--- /dev/null+++ b/mods/diff/hooks/backend/installed-backend-probes.ts@@ -0,0 +1,15 @@+import type { BackendProbe } from './types'++/**+ * The plugin's backend-extension point: probes for version-control systems+ * other than git, consulted in insertion order before git (backendOf); a+ * probe answers null wherever git should govern. Empty as shipped, so the+ * plugin reads git alone. A host+ * that compiles the module in may add a probe once, before the plugin+ * registers; the module runs natively, so that probe is what+ * `session.start` sees. The module contract offers no other channel: the+ * options `register` receives are the manifest's userConfig, and the+ * shipped scan requires `register` itself to be a plain exported function.+ */+// module-state-allow: module-evaluation code wiring — a compiling host adds its probe functions (code references, not runtime input) once before registration and never removes or rebinds them; tests pass probes to backendOf directly; a per-Host copy would hold the same functions+export const INSTALLED_BACKEND_PROBES = new Set<BackendProbe>()diff --git a/mods/diff/hooks/backend/types/backend-host/backend-host.ts b/mods/diff/hooks/backend/types/backend-host/backend-host.tsnew file mode 100644index 00000000..20cc8020--- /dev/null+++ b/mods/diff/hooks/backend/types/backend-host/backend-host.ts@@ -0,0 +1,22 @@+import type Git from '../../../git'+import type Host from '../../../host'++/**+ * What pinning a backend takes from the bound host: the raw process+ * runner (each backend names its own program, argv lead, environment and+ * timeout), the file probes, the engine's clock, the session's start as it+ * stands at each fetch (a later `session.start` moves it), and the+ * branch-base listener.+ */+export type BackendHost = Pick<Host.Host, 'run' | 'readFile'> &+ Pick<Git.GitDeps, 'mtimeOf' | 'entryKindsOf' | 'onBranchBase'> & {+ /**+ * The engine's clock, in milliseconds (`$.clock.now`).+ */+ nowMs: () => number++ /**+ * When the current session began, read at each fetch.+ */+ sessionStartMsOf: () => number+ }diff --git a/mods/diff/hooks/backend/types/backend-host/index.ts b/mods/diff/hooks/backend/types/backend-host/index.tsnew file mode 100644index 00000000..cd04819f--- /dev/null+++ b/mods/diff/hooks/backend/types/backend-host/index.ts@@ -0,0 +1,3 @@+export type * from './backend-host.js'++export * as default from '.'diff --git a/mods/diff/hooks/backend/types/backend-probe/backend-probe.ts b/mods/diff/hooks/backend/types/backend-probe/backend-probe.tsnew file mode 100644index 00000000..dedbea1e--- /dev/null+++ b/mods/diff/hooks/backend/types/backend-probe/backend-probe.ts@@ -0,0 +1,9 @@+import type { Backend } from '../backend'+import type { BackendHost } from '../backend-host'++/**+ * Probes the session's directory for one backend's working tree: the+ * backend when it holds the directory, null when it does not or when git+ * should govern it instead (Git.gitBackendOf is git's).+ */+export type BackendProbe = (host: BackendHost) => Promise<Backend | null>diff --git a/mods/diff/hooks/backend/types/backend-probe/index.ts b/mods/diff/hooks/backend/types/backend-probe/index.tsnew file mode 100644index 00000000..47f88181--- /dev/null+++ b/mods/diff/hooks/backend/types/backend-probe/index.ts@@ -0,0 +1,3 @@+export type * from './backend-probe.js'++export * as default from '.'diff --git a/mods/diff/hooks/backend/types/backend-words/backend-words.ts b/mods/diff/hooks/backend/types/backend-words/backend-words.tsnew file mode 100644index 00000000..62c68693--- /dev/null+++ b/mods/diff/hooks/backend/types/backend-words/backend-words.ts@@ -0,0 +1,27 @@+/**+ * The words the pane draws that name the backend: what uncommitted mode+ * compares against, the command whose failure the empty state names, the+ * tool that lists untracked files, and the note under an untracked row.+ */+export type BackendWords = {+ /**+ * What the working tree is compared with outside branch mode: `HEAD`.+ */+ base: string++ /**+ * The command a failed fetch could not read: `git diff`.+ */+ diffCommand: string++ /**+ * The program that lists untracked files: `git`.+ */+ lister: string++ /**+ * The dim lines under an untracked row: what it is, and how to get its+ * line counts (a pasteable command only when the path is safe to paste).+ */+ untrackedNoteOf: (path: string, isPasteable: boolean) => readonly string[]+}diff --git a/mods/diff/hooks/backend/types/backend-words/index.ts b/mods/diff/hooks/backend/types/backend-words/index.tsnew file mode 100644index 00000000..8fc8e527--- /dev/null+++ b/mods/diff/hooks/backend/types/backend-words/index.ts@@ -0,0 +1,3 @@+export type * from './backend-words.js'++export * as default from '.'diff --git a/mods/diff/hooks/backend/types/backend/backend.ts b/mods/diff/hooks/backend/types/backend/backend.tsnew file mode 100644index 00000000..dfa12c1e--- /dev/null+++ b/mods/diff/hooks/backend/types/backend/backend.ts@@ -0,0 +1,46 @@+import type Git from '../../../git'+import type { BackendWords } from '../backend-words'++/**+ * The version-control system behind the pane, pinned once per session:+ * where its working tree is, which comparisons it offers, how it words+ * them, and the three reads the pane makes of it.+ *+ * Git is the plugin's own backend; a host may install probes for others,+ * consulted where no git working tree holds the directory (backendOf).+ */+export type Backend = {+ /**+ * The working tree's top; every row's path is relative to it.+ */+ repository: Pick<Git.Repository, 'toplevel'>++ /**+ * The base modes the picker offers, in picker order.+ */+ baseModes: readonly Git.BaseMode[]++ /**+ * The pane's words for what this backend compares and runs.+ */+ words: BackendWords++ /**+ * One fetch of the working tree against the mode's base (Git.fetchDiff).+ */+ fetchDiff: (mode: Git.BaseMode) => Promise<Git.FetchOutcome>++ /**+ * One row's hunks against the base its fetch read (Git.fetchFileHunks).+ */+ fetchFileHunks: (+ data: Git.DiffData,+ file: Git.FileStat,+ ) => Promise<Git.FileHunks | null>++ /**+ * A string that changes when the checked-out commit moves+ * (Git.headKeyOf); empty when it cannot be read this tick.+ */+ headKeyOf: () => Promise<string>+}diff --git a/mods/diff/hooks/backend/types/backend/index.ts b/mods/diff/hooks/backend/types/backend/index.tsnew file mode 100644index 00000000..7c3a5c07--- /dev/null+++ b/mods/diff/hooks/backend/types/backend/index.ts@@ -0,0 +1,3 @@+export type * from './backend.js'++export * as default from '.'diff --git a/mods/diff/hooks/backend/types/index.ts b/mods/diff/hooks/backend/types/index.tsnew file mode 100644index 00000000..a4e249ce--- /dev/null+++ b/mods/diff/hooks/backend/types/index.ts@@ -0,0 +1,6 @@+export * from './backend'+export * from './backend-host'+export * from './backend-probe'+export * from './backend-words'++export * as default from '.'diff --git a/mods/diff/hooks/git/failed-run/failed-run.ts b/mods/diff/hooks/git/failed-run/failed-run.tsnew file mode 100644index 00000000..33998ead--- /dev/null+++ b/mods/diff/hooks/git/failed-run/failed-run.ts@@ -0,0 +1,11 @@+import type Types from '../types'++/**+ * What a child that never ran, was killed, or timed out reads as: exit code+ * -1 and no output, so a runner never rejects (GitRun).+ */+export const FAILED_RUN: Types.RunResult = Object.freeze({+ exitCode: -1,+ stdout: '',+ stderr: '',+})diff --git a/mods/diff/hooks/git/failed-run/index.ts b/mods/diff/hooks/git/failed-run/index.tsnew file mode 100644index 00000000..1a9f2678--- /dev/null+++ b/mods/diff/hooks/git/failed-run/index.ts@@ -0,0 +1,3 @@+export * from './failed-run.js'++export * as default from '.'diff --git a/mods/diff/hooks/git/git-backend-of.ts b/mods/diff/hooks/git/git-backend-of.tsnew file mode 100644index 00000000..4369769a--- /dev/null+++ b/mods/diff/hooks/git/git-backend-of.ts@@ -0,0 +1,66 @@+import type Backend from '../backend'+import Limits from '../limits'+import Argv from './argv'+import { FAILED_RUN } from './failed-run'+import { fetchDiff } from './fetch-diff.js'+import { fetchFileHunks } from './fetch-file-hunks.js'+import { GIT_BASE_MODES } from './git-base-modes'+import { GIT_WORDS } from './git-words'+import Probes from './probes'+import type Types from './types'++/**+ * The git backend over the session's directory: the repository read with+ * one `rev-parse` in that directory, then every child pinned to it+ * (`--git-dir`, `--work-tree`, cwd the top) under the C locale and the+ * fetch's timeout (gitDiff.ts execPinnedGit).+ *+ * @param host the bound host's runner and probes+ * @returns the backend, or null outside a git working tree+ */+export async function gitBackendOf(+ host: Backend.BackendHost,+): Promise<Backend.Backend | null> {+ const runOf =+ (pinned: Types.Repository | null): Types.GitRun =>+ async argv => {+ try {+ return await host.run(+ ['git', ...(pinned ? Argv.pinnedLeadOf(pinned) : []), ...argv],+ {+ timeoutMs: Limits.GIT_TIMEOUT_MS,+ env: Argv.GIT_CHILD_ENV,+ ...(pinned && { cwd: pinned.toplevel }),+ },+ )+ } catch {+ return FAILED_RUN+ }+ }++ const repository = await Probes.repositoryOf(runOf(null))++ if (!repository) {+ return null+ }++ const run = runOf(repository)+ const depsOf = (): Types.GitDeps => ({+ run,+ repository,+ mtimeOf: host.mtimeOf,+ entryKindsOf: host.entryKindsOf,+ sessionStartMs: host.sessionStartMsOf(),+ onBranchBase: host.onBranchBase,+ })++ return {+ repository,+ baseModes: GIT_BASE_MODES,+ words: GIT_WORDS,+ fetchDiff: mode => fetchDiff(depsOf(), mode),+ fetchFileHunks: (data, file) => fetchFileHunks(run, data, file),+ headKeyOf: () =>+ Probes.headKeyOf({ ...depsOf(), readFile: host.readFile }, repository),+ }+}diff --git a/mods/diff/hooks/git/git-base-modes/git-base-modes.ts b/mods/diff/hooks/git/git-base-modes/git-base-modes.tsnew file mode 100644index 00000000..7211d985--- /dev/null+++ b/mods/diff/hooks/git/git-base-modes/git-base-modes.ts@@ -0,0 +1,10 @@+import type Types from '../types'++/**+ * The comparisons git offers, in picker order: all three.+ */+export const GIT_BASE_MODES: readonly Types.BaseMode[] = Object.freeze([+ 'session',+ 'uncommitted',+ 'branch',+])diff --git a/mods/diff/hooks/git/git-base-modes/index.ts b/mods/diff/hooks/git/git-base-modes/index.tsnew file mode 100644index 00000000..506b35ba--- /dev/null+++ b/mods/diff/hooks/git/git-base-modes/index.ts@@ -0,0 +1,3 @@+export * from './git-base-modes.js'++export * as default from '.'diff --git a/mods/diff/hooks/git/git-words/git-words.ts b/mods/diff/hooks/git/git-words/git-words.tsnew file mode 100644index 00000000..3d18502b--- /dev/null+++ b/mods/diff/hooks/git/git-words/git-words.ts@@ -0,0 +1,17 @@+import type Backend from '../../backend'++/**+ * The pane's git words: compared with HEAD, read by `git diff`, untracked+ * files listed by git and staged with `git add ':/…'` (DiffDetailView's).+ */+export const GIT_WORDS: Backend.BackendWords = Object.freeze({+ base: 'HEAD',+ diffCommand: 'git diff',+ lister: 'git',+ untrackedNoteOf: (path: string, isPasteable: boolean) => [+ 'New file not yet staged.',+ isPasteable+ ? `Run \`git add ':/${path}'\` to see line counts.`+ : 'Stage it with git add to see line counts.',+ ],+})diff --git a/mods/diff/hooks/git/git-words/index.ts b/mods/diff/hooks/git/git-words/index.tsnew file mode 100644index 00000000..c0b1c24d--- /dev/null+++ b/mods/diff/hooks/git/git-words/index.ts@@ -0,0 +1,3 @@+export * from './git-words.js'++export * as default from '.'diff --git a/mods/diff/hooks/git/index.ts b/mods/diff/hooks/git/index.tsindex 2ce634a2..31e094a7 100644--- a/mods/diff/hooks/git/index.ts+++ b/mods/diff/hooks/git/index.ts@@ -1,8 +1,12 @@export * from './argv'export * from './cut-hunks'export * from './empty-file-hunks'+export * from './failed-run'export * from './fetch-diff.js'export * from './fetch-file-hunks.js'+export * from './git-backend-of.js'+export * from './git-base-modes'+export * from './git-words'export * from './hunk-of'export * from './large-file-hunks'export * from './parse'diff --git a/mods/diff/hooks/git/parse/is-whole-listing/is-whole-listing.ts b/mods/diff/hooks/git/parse/is-whole-listing/is-whole-listing.tsindex 7bb74607..c001ae23 100644--- a/mods/diff/hooks/git/parse/is-whole-listing/is-whole-listing.ts+++ b/mods/diff/hooks/git/parse/is-whole-listing/is-whole-listing.ts@@ -3,15 +3,17 @@ import { isUnderUtf8Ceiling } from './is-under-utf8-ceiling'import { MOST_UTF8_BYTES } from './most-utf8-bytes'/**- * Whether a `-z` listing arrived whole: every record NUL-terminated and- * the text short of the host's output cap, so no record was cut or lost.+ * Whether a listing arrived whole: every record terminated (NUL for git's+ * `-z` listings, a newline for line records) and the text short of the+ * host's output cap, so no record was cut or lost.** A cut inside a multi-byte character costs the decoded text up to* MOST_UTF8_BYTES, hence the margin under the cap.** @param stdout the listing as `$.process.run` returned it+ * @param terminator what ends every record; NUL when absent* @returns whether it can be parsed as the whole answer*/-export const isWholeListing = (stdout: string) =>- (stdout === '' || stdout.endsWith('\0')) &&+export const isWholeListing = (stdout: string, terminator = '\0') =>+ (stdout === '' || stdout.endsWith(terminator)) &&isUnderUtf8Ceiling(stdout, Limits.HOST_OUTPUT_CAP_BYTES - MOST_UTF8_BYTES)diff --git a/mods/diff/hooks/git/probes/index.ts b/mods/diff/hooks/git/probes/index.tsindex 3e00acfa..4edb4cd5 100644--- a/mods/diff/hooks/git/probes/index.ts+++ b/mods/diff/hooks/git/probes/index.ts@@ -22,6 +22,7 @@ export * from './tag-pre-session.js'export * from './transient-state-files'export * from './unstaged-numstat.js'export * from './untracked-files'+export * from './untracked-rows-of'export * from './untracked-place'export * as default from '.'diff --git a/mods/diff/hooks/git/probes/tag-pre-session.ts b/mods/diff/hooks/git/probes/tag-pre-session.tsindex baf39afb..114ffb5e 100644--- a/mods/diff/hooks/git/probes/tag-pre-session.ts+++ b/mods/diff/hooks/git/probes/tag-pre-session.ts@@ -13,7 +13,7 @@ import { datingsOf } from './datings-of'* @returns the rows, tagged*/export async function tagPreSession(- context: Pick<Types.FetchContext, 'deps' | 'stamps'>,+ context: Types.DatingContext,files: readonly Types.FileStat[],): Promise<readonly Types.FileStat[]> {const datings = await datingsOf(diff --git a/mods/diff/hooks/git/probes/untracked-files/untracked-files.ts b/mods/diff/hooks/git/probes/untracked-files/untracked-files.tsindex 3f8ca084..34ffa712 100644--- a/mods/diff/hooks/git/probes/untracked-files/untracked-files.ts+++ b/mods/diff/hooks/git/probes/untracked-files/untracked-files.ts@@ -1,17 +1,12 @@-import Limits from '../../../limits'import Argv from '../../argv'import GitParse from '../../parse'import type Types from '../../types'-import { datingsOf } from '../datings-of'import type { UntrackedPlace } from '../untracked-place'+import { untrackedRowsOf } from '../untracked-rows-of'/**- * The untracked, unignored files as 0/0 rows: the session's own first,- * then, when the scope asks, the tagged pre-session ones, up to the slots.- *- * At most MAX_UNTRACKED_PROBES are dated; a file past that or past the- * listing budget reads as pre-session, an undatable one as the session's- * (the built-in panel's rule). A listing not given whole: no answer.+ * The untracked, unignored files as 0/0 rows (untrackedRowsOf), listed+ * with `ls-files -z`. A listing not given whole: no answer.** @param context the fetch: its pinned git, stamp probe and session start* @param place the free row slots and the scope@@ -19,7 +14,7 @@ import type { UntrackedPlace } from '../untracked-place'* `-z` listing failed, timed out or was cut*/export async function untrackedFiles(- context: Pick<Types.FetchContext, 'run' | 'deps' | 'stamps'>,+ context: Pick<Types.FetchContext, 'run'> & Types.DatingContext,place: UntrackedPlace,): Promise<readonly Types.FileStat[] | null> {if (place.slots <= 0) {@@ -40,34 +35,6 @@ export async function untrackedFiles(}const paths = listing.stdout.split('\0').filter(path => path !== '')- const probedPaths = paths.slice(0, Limits.MAX_UNTRACKED_PROBES)- const datings = await datingsOf(- context.stamps,- context.deps.sessionStartMs,- probedPaths,- )- const probed = probedPaths.map(path => ({- path,- isPreSession: datings.get(path) !== 'session',- }))- const isWithPreSession = place.scope === 'with-pre-session'- const earlier = isWithPreSession- ? [- ...probed.filter(file => file.isPreSession),- ...paths- .slice(Limits.MAX_UNTRACKED_PROBES)- .map(path => ({ path, isPreSession: true })),- ]- : []- const ordered = [...probed.filter(file => !file.isPreSession), ...earlier]- return ordered.slice(0, place.slots).map(file => ({- path: file.path,- renamedFrom: null,- added: 0,- removed: 0,- isBinary: false,- isUntracked: true,- isPreSession: file.isPreSession,- }))+ return untrackedRowsOf(context, paths, place)}diff --git a/mods/diff/hooks/git/probes/untracked-rows-of/index.ts b/mods/diff/hooks/git/probes/untracked-rows-of/index.tsnew file mode 100644index 00000000..d3989242--- /dev/null+++ b/mods/diff/hooks/git/probes/untracked-rows-of/index.ts@@ -0,0 +1,3 @@+export * from './untracked-rows-of.js'++export * as default from '.'diff --git a/mods/diff/hooks/git/probes/untracked-rows-of/untracked-rows-of.ts b/mods/diff/hooks/git/probes/untracked-rows-of/untracked-rows-of.tsnew file mode 100644index 00000000..6b74bb89--- /dev/null+++ b/mods/diff/hooks/git/probes/untracked-rows-of/untracked-rows-of.ts@@ -0,0 +1,54 @@+import Limits from '../../../limits'+import type Types from '../../types'+import { datingsOf } from '../datings-of'+import type { UntrackedPlace } from '../untracked-place'++/**+ * Listed untracked paths as 0/0 rows: the session's own first, then,+ * when the scope asks, the tagged pre-session ones, up to the slots.+ *+ * At most MAX_UNTRACKED_PROBES are dated; a file past that or past the+ * listing budget reads as pre-session, an undatable one as the session's+ * (the built-in panel's rule).+ *+ * @param context the fetch's stamp probe and session start+ * @param paths the untracked paths, root-relative, as the lister printed them+ * @param place the free row slots and the scope+ * @returns the rows to merge after the tracked ones+ */+export async function untrackedRowsOf(+ context: Types.DatingContext,+ paths: readonly string[],+ place: UntrackedPlace,+): Promise<readonly Types.FileStat[]> {+ const probedPaths = paths.slice(0, Limits.MAX_UNTRACKED_PROBES)+ const datings = await datingsOf(+ context.stamps,+ context.deps.sessionStartMs,+ probedPaths,+ )+ const probed = probedPaths.map(path => ({+ path,+ isPreSession: datings.get(path) !== 'session',+ }))+ const isWithPreSession = place.scope === 'with-pre-session'+ const earlier = isWithPreSession+ ? [+ ...probed.filter(file => file.isPreSession),+ ...paths+ .slice(Limits.MAX_UNTRACKED_PROBES)+ .map(path => ({ path, isPreSession: true })),+ ]+ : []+ const ordered = [...probed.filter(file => !file.isPreSession), ...earlier]++ return ordered.slice(0, place.slots).map(file => ({+ path: file.path,+ renamedFrom: null,+ added: 0,+ removed: 0,+ isBinary: false,+ isUntracked: true,+ isPreSession: file.isPreSession,+ }))+}diff --git a/mods/diff/hooks/git/tiers/branch-source-of/branch-source-of.ts b/mods/diff/hooks/git/tiers/branch-source-of/branch-source-of.tsindex 8351edee..a02de14a 100644--- a/mods/diff/hooks/git/tiers/branch-source-of/branch-source-of.ts+++ b/mods/diff/hooks/git/tiers/branch-source-of/branch-source-of.ts@@ -20,6 +20,6 @@ export function branchSourceOf(case 'head-is-base':return { kind: 'branch', baseBranch: base.baseBranch, baseRef: 'HEAD' }case 'none':- return { kind: 'working-tree' }+ return { kind: 'working-tree', base: 'HEAD' }}}diff --git a/mods/diff/hooks/git/tiers/unborn-tier/unborn-tier.ts b/mods/diff/hooks/git/tiers/unborn-tier/unborn-tier.tsindex db1695f8..eabf6303 100644--- a/mods/diff/hooks/git/tiers/unborn-tier/unborn-tier.ts+++ b/mods/diff/hooks/git/tiers/unborn-tier/unborn-tier.ts@@ -48,7 +48,7 @@ export async function unbornTier(return {kind: 'data',data: diffDataOf(context, merged, {- source: { kind: 'working-tree' },+ source: { kind: 'working-tree', base: 'HEAD' },baseRef: '--cached',isUnborn: true,stalePaths: unstaged.files.map(file => file.path),diff --git a/mods/diff/hooks/git/tiers/with-untracked/index.ts b/mods/diff/hooks/git/tiers/with-untracked/index.tsindex d2e9aa54..9f5791ca 100644--- a/mods/diff/hooks/git/tiers/with-untracked/index.ts+++ b/mods/diff/hooks/git/tiers/with-untracked/index.ts@@ -1,4 +1,5 @@export * from './merged-result-of'+export * from './merged-with-untracked'export * from './with-untracked.js'export * as default from '.'diff --git a/mods/diff/hooks/git/tiers/with-untracked/merged-with-untracked/index.ts b/mods/diff/hooks/git/tiers/with-untracked/merged-with-untracked/index.tsnew file mode 100644index 00000000..429b1cf6--- /dev/null+++ b/mods/diff/hooks/git/tiers/with-untracked/merged-with-untracked/index.ts@@ -0,0 +1,3 @@+export * from './merged-with-untracked.js'++export * as default from '.'diff --git a/mods/diff/hooks/git/tiers/with-untracked/merged-with-untracked/merged-with-untracked.ts b/mods/diff/hooks/git/tiers/with-untracked/merged-with-untracked/merged-with-untracked.tsnew file mode 100644index 00000000..2f1835a1--- /dev/null+++ b/mods/diff/hooks/git/tiers/with-untracked/merged-with-untracked/merged-with-untracked.ts@@ -0,0 +1,32 @@+import type Types from '../../../types'+import { mergedResultOf } from '../merged-result-of'++/**+ * A tier's tracked rows and totals with a listed set of untracked rows+ * after them (gitDiff.ts mergeSessionUntrackedFiles), or flagged withheld+ * when the lister gave no whole listing.+ *+ * A path a tracked row already holds keeps that row and counts once.+ *+ * @param result the tier's tracked rows and totals+ * @param untracked the untracked rows, or null when their listing was withheld+ * @returns the merged rows and totals, and whether the listing was withheld+ */+export function mergedWithUntracked(+ result: Types.NumstatResult,+ untracked: readonly Types.FileStat[] | null,+): Types.MergedResult {+ if (!untracked) {+ return mergedResultOf(result, { isUntrackedWithheld: true })+ }++ const tracked = new Set(result.files.map(file => file.path))+ const fresh = untracked.filter(file => !tracked.has(file.path))+ const filesCount = result.stats.filesCount + fresh.length+ const stats = { ...result.stats, filesCount }++ return mergedResultOf(+ { stats, files: [...result.files, ...fresh] },+ { isUntrackedWithheld: false },+ )+}diff --git a/mods/diff/hooks/git/tiers/with-untracked/with-untracked.ts b/mods/diff/hooks/git/tiers/with-untracked/with-untracked.tsindex 3618c7cc..365b62d9 100644--- a/mods/diff/hooks/git/tiers/with-untracked/with-untracked.ts+++ b/mods/diff/hooks/git/tiers/with-untracked/with-untracked.ts@@ -3,14 +3,14 @@ import Probes from '../../probes'import type Types from '../../types'import { isPastDetails } from '../is-past-details'import { mergedResultOf } from './merged-result-of'+import { mergedWithUntracked } from './merged-with-untracked'/**- * A tier's rows with the untracked files merged after them, as the built-in- * panel merges the session's untracked files.+ * A tier's rows with the untracked files merged after them+ * (mergedWithUntracked).*- * A path a numstat row already holds keeps that row and counts once. Past- * MAX_FILES_FOR_DETAILS nothing is listed; a listing git withheld leaves- * the tracked rows as they are and says so, as the built-in degrades.+ * Past MAX_FILES_FOR_DETAILS nothing is listed; a listing git withheld+ * leaves the tracked rows as they are and says so, as the built-in degrades.** @param context the fetch* @param result the tier's tracked rows and totals@@ -26,22 +26,11 @@ export async function withUntracked(return mergedResultOf(result, { isUntrackedWithheld: false })}- const tracked = new Set(result.files.map(file => file.path))- const untracked = await Probes.untrackedFiles(context, {- slots: Limits.MAX_FILES - result.files.length,- scope,- })-- if (!untracked) {- return mergedResultOf(result, { isUntrackedWithheld: true })- }-- const fresh = untracked.filter(file => !tracked.has(file.path))- const filesCount = result.stats.filesCount + fresh.length- const stats = { ...result.stats, filesCount }-- return mergedResultOf(- { stats, files: [...result.files, ...fresh] },- { isUntrackedWithheld: false },+ return mergedWithUntracked(+ result,+ await Probes.untrackedFiles(context, {+ slots: Limits.MAX_FILES - result.files.length,+ scope,+ }),)}diff --git a/mods/diff/hooks/git/tiers/working-tree-basis/working-tree-basis.ts b/mods/diff/hooks/git/tiers/working-tree-basis/working-tree-basis.tsindex 558ffa0a..b9b74785 100644--- a/mods/diff/hooks/git/tiers/working-tree-basis/working-tree-basis.ts+++ b/mods/diff/hooks/git/tiers/working-tree-basis/working-tree-basis.ts@@ -5,7 +5,7 @@ import type DiffDataOf from '../diff-data-of'* every body current.*/export const WORKING_TREE_BASIS: DiffDataOf.DiffBasis = Object.freeze({- source: Object.freeze({ kind: 'working-tree' }),+ source: Object.freeze({ kind: 'working-tree', base: 'HEAD' }),baseRef: 'HEAD',isUnborn: false,stalePaths: Object.freeze([]),diff --git a/mods/diff/hooks/git/types/dating-context/dating-context.ts b/mods/diff/hooks/git/types/dating-context/dating-context.tsnew file mode 100644index 00000000..bc61d4b5--- /dev/null+++ b/mods/diff/hooks/git/types/dating-context/dating-context.ts@@ -0,0 +1,11 @@+import type { GitDeps } from '../git-deps'+import type { StampProbe } from '../stamp-probe'++/**+ * What dating a path against the session takes: the session's start and+ * one stamp probe over the working tree's top.+ */+export type DatingContext = {+ deps: Pick<GitDeps, 'sessionStartMs'>+ stamps: StampProbe+}diff --git a/mods/diff/hooks/git/types/dating-context/index.ts b/mods/diff/hooks/git/types/dating-context/index.tsnew file mode 100644index 00000000..2bb07592--- /dev/null+++ b/mods/diff/hooks/git/types/dating-context/index.ts@@ -0,0 +1,3 @@+export type * from './dating-context.js'++export * as default from '.'diff --git a/mods/diff/hooks/git/types/diff-data/diff-data.ts b/mods/diff/hooks/git/types/diff-data/diff-data.tsindex c04d438d..fd562359 100644--- a/mods/diff/hooks/git/types/diff-data/diff-data.ts+++ b/mods/diff/hooks/git/types/diff-data/diff-data.ts@@ -6,14 +6,15 @@ import type { Repository } from '../repository'/*** One settled fetch: the rows, the totals, what they compare, and what a- * file's hunks must be read against so both agree.+ * file's hunks must be read against so both agree, over the working tree's+ * top (every backend has one; git's other directories stay its own).** `isUnborn`: a repository before its first commit (rows are the staged* and new files, `baseRef` is `--cached`); `stalePaths`: files whose staged* body is behind the working tree; `isUntrackedWithheld`: MergedResult's.*/export type DiffData = {- repository: Repository+ repository: Pick<Repository, 'toplevel'>mode: BaseModestats: DiffStatsfiles: readonly FileStat[]diff --git a/mods/diff/hooks/git/types/diff-source/diff-source.ts b/mods/diff/hooks/git/types/diff-source/diff-source.tsindex d9c59d77..ceae42e7 100644--- a/mods/diff/hooks/git/types/diff-source/diff-source.ts+++ b/mods/diff/hooks/git/types/diff-source/diff-source.ts@@ -1,7 +1,9 @@/**- * What a fetched diff compares: the working tree against HEAD, or against- * the merge-base with the default branch (`baseRef` the ref git was handed).+ * What a fetched diff compares: the working tree against its checked-out+ * commit (`base` names it as the pane should: `HEAD`, or a short sha where+ * the backend has no such word), or against the merge-base with the default+ * branch (`baseRef` the ref git was handed).*/export type DiffSource =- | { kind: 'working-tree' }+ | { kind: 'working-tree'; base: string }| { kind: 'branch'; baseBranch: string; baseRef: string }diff --git a/mods/diff/hooks/git/types/index.ts b/mods/diff/hooks/git/types/index.tsindex 834946c4..0d022ab1 100644--- a/mods/diff/hooks/git/types/index.ts+++ b/mods/diff/hooks/git/types/index.ts@@ -1,6 +1,7 @@export * from './base-mode'export * from './branch-base'export * from './dating'+export * from './dating-context'export * from './diff-data'export * from './diff-source'export * from './diff-stats'diff --git a/mods/diff/hooks/index.ts b/mods/diff/hooks/index.tsindex b9627cab..9094b627 100644--- a/mods/diff/hooks/index.ts+++ b/mods/diff/hooks/index.ts@@ -1,5 +1,6 @@export * from './array-of'export * from './ask'+export * from './backend'export * from './classify'export * from './command-spec'export * from './count-of'diff --git a/mods/diff/hooks/names/texts/untracked-withheld-text.ts b/mods/diff/hooks/names/texts/untracked-withheld-text.tsindex 2db14124..feab64df 100644--- a/mods/diff/hooks/names/texts/untracked-withheld-text.ts+++ b/mods/diff/hooks/names/texts/untracked-withheld-text.ts@@ -1,6 +1,9 @@/**- * The pane's word for a fetch whose untracked listing git did not give- * whole: the tracked rows stand, the new files are not counted.+ * The pane's word for a fetch whose untracked listing the backend did not+ * give whole: the tracked rows stand, the new files are not counted.+ *+ * @param lister the program that lists untracked files (BackendWords)+ * @returns the note*/-export const UNTRACKED_WITHHELD_TEXT =- 'Untracked files unavailable (git could not list them); not counted'+export const untrackedWithheldTextOf = (lister: string) =>+ `Untracked files unavailable (${lister} could not list them); not counted`diff --git a/mods/diff/hooks/pane-state/base-label-of.ts b/mods/diff/hooks/pane-state/base-label-of.tsindex 4bd42d02..bcdb1edb 100644--- a/mods/diff/hooks/pane-state/base-label-of.ts+++ b/mods/diff/hooks/pane-state/base-label-of.ts@@ -1,3 +1,4 @@+import type Backend from '../backend'import type Git from '../git'import { modeLabelOf } from './mode-label-of'@@ -12,12 +13,14 @@ import { modeLabelOf } from './mode-label-of'* @param requested the mode the person picked* @param data the last good fetch* @param filesCount the header's session file count+ * @param words the backend's words* @returns the line, or null*/export function baseLabelOf(requested: Git.BaseMode,data: Git.DiffData | null,filesCount: number,+ words: Pick<Backend.BackendWords, 'base'>,): string | null {if (!data) {return null@@ -37,7 +40,7 @@ export function baseLabelOf(}const phase = isPending ? 'pending' : 'settled'- const label = modeLabelOf(requested, data.source, phase)+ const label = modeLabelOf(requested, data.source, phase, words)return isPending ? `${label}…` : label}diff --git a/mods/diff/hooks/pane-state/empty-state-of.ts b/mods/diff/hooks/pane-state/empty-state-of.tsindex 65ab7b13..873d50e6 100644--- a/mods/diff/hooks/pane-state/empty-state-of.ts+++ b/mods/diff/hooks/pane-state/empty-state-of.ts@@ -1,3 +1,4 @@+import type Backend from '../backend'import type Git from '../git'import Names from '../names'import type { EmptyState } from './empty-state'@@ -12,16 +13,18 @@ import type { EmptyState } from './empty-state'** @param data the last good fetch, or null when none ever settled* @param filesCount the header's session file count+ * @param words the backend's words* @returns the empty state, or null*/export function emptyStateOf(data: Git.DiffData | null,filesCount: number,+ words: Backend.BackendWords,): EmptyState | null {if (!data) {return {headline: 'Diff unavailable',- hint: "Couldn't read the git diff — it will retry on the next change",+ hint: `Couldn't read the ${words.diffCommand} — it will retry on the next change`,}}@@ -32,7 +35,7 @@ export function emptyStateOf(if (data.isUntrackedWithheld) {return {headline: 'No tracked changes',- hint: Names.UNTRACKED_WITHHELD_TEXT,+ hint: Names.untrackedWithheldTextOf(words.lister),}}@@ -55,8 +58,10 @@ export function emptyStateOf(}return {- headline: 'No changes vs HEAD',- hint: 'No base branch to compare against — showing changes vs HEAD',+ headline: `No changes vs ${data.source.base}`,+ hint:+ 'No base branch to compare against — showing changes vs ' ++ data.source.base,}case 'session':return { headline: 'No changes this session', hint: null }diff --git a/mods/diff/hooks/pane-state/initial-model/initial-model.ts b/mods/diff/hooks/pane-state/initial-model/initial-model.tsindex 73e1982b..b0add10c 100644--- a/mods/diff/hooks/pane-state/initial-model/initial-model.ts+++ b/mods/diff/hooks/pane-state/initial-model/initial-model.ts@@ -1,10 +1,13 @@+import Git from '../../git'import type { PaneModel } from '../pane-model'/*** The pane before anything happened: session mode, nothing fetched,- * nothing picked, the current source.+ * nothing picked, the current source, git's words.*/export const INITIAL_MODEL: PaneModel = Object.freeze({+ words: Git.GIT_WORDS,+ baseModes: Git.GIT_BASE_MODES,isLoading: false,hasSettled: false,isOutsideRepository: false,diff --git a/mods/diff/hooks/pane-state/mode-label-of/mode-label-of.ts b/mods/diff/hooks/pane-state/mode-label-of/mode-label-of.tsindex 92479e83..38200f68 100644--- a/mods/diff/hooks/pane-state/mode-label-of/mode-label-of.ts+++ b/mods/diff/hooks/pane-state/mode-label-of/mode-label-of.ts@@ -1,29 +1,36 @@+import type Backend from '../../backend'import type Git from '../../git'/*** A requested mode's name for the base line; branch mode names its base- * branch from the data, or says what stands in while none is known.+ * branch from the data, or says what stands in while none is known. A+ * working-tree diff names its own base (`HEAD`, a short sha); anything+ * else falls back to the backend's word for it.** @param requested the mode the person picked* @param source what the data on screen compares* @param phase `pending` while the requested mode's fetch has not landed+ * @param words the backend's words* @returns the label without its pending ellipsis*/export function modeLabelOf(requested: Git.BaseMode,source: Git.DiffSource,phase: 'pending' | 'settled',+ words: Pick<Backend.BackendWords, 'base'>,) {+ const base = source.kind === 'working-tree' ? source.base : words.base+switch (requested) {case 'session':return 'this session'case 'uncommitted':- return 'uncommitted (vs HEAD)'+ return `uncommitted (vs ${base})`case 'branch':if (source.kind === 'branch') {return `branch vs ${source.baseBranch}`}- return phase === 'pending' ? 'branch diff' : 'vs HEAD (no base branch)'+ return phase === 'pending' ? 'branch diff' : `vs ${base} (no base branch)`}}diff --git a/mods/diff/hooks/pane-state/pane-model/pane-model.ts b/mods/diff/hooks/pane-state/pane-model/pane-model.tsindex e72e23dc..4a8c612e 100644--- a/mods/diff/hooks/pane-state/pane-model/pane-model.ts+++ b/mods/diff/hooks/pane-state/pane-model/pane-model.ts@@ -1,3 +1,4 @@+import type Backend from '../../backend'import type Git from '../../git'import type Todos from '../../todos'import type Turns from '../../turns'@@ -6,9 +7,12 @@ import type { Source } from '../source'/*** Everything one drawing of the pane reads: the last good fetch, what the- * person picked, the selected file's body, the transcript's turns and todos.+ * person picked, the selected file's body, the transcript's turns and todos,+ * and the pinned backend's words and base modes (git's until one is pinned).*/export type PaneModel = {+ words: Backend.BackendWords+ baseModes: readonly Git.BaseMode[]isLoading: booleanhasSettled: booleanisOutsideRepository: booleandiff --git a/mods/diff/hooks/register.ts b/mods/diff/hooks/register.tsindex c3cdaeb1..54a98b77 100644--- a/mods/diff/hooks/register.ts+++ b/mods/diff/hooks/register.ts@@ -1,9 +1,10 @@import type { On, ResultOf, SessionMessage, Timer } from 'claude-code'import Ask from './ask'+import Backend from './backend'import { COMMAND_SPEC } from './command-spec'import { entryKindsOf } from './entry-kinds-of'-import Git from './git'+import type Git from './git'import type { Host } from './host'import { isOnPaneSurface } from './is-on-pane-surface'import Limits from './limits'@@ -22,13 +23,15 @@ import Views from './views'** `session.start` binds the engine once, registers the command (refused* because the built-in holds it, the plugin does nothing) and pins the- * repository (probed again on `/diff` and first edit until found).+ * backend holding the session's directory (probed again on `/diff` and+ * first edit until found): what an installed backend probe finds, else git+ * (backendOf).** @param on the engine's registrar*/export function register(on: On) {let host: Host | null = null- let repository: Git.Repository | null = null+ let backend: Backend.Backend | null = nulllet sessionStartMs = 0let isPaneOpen = falselet hasAutoOpened = false@@ -40,70 +43,68 @@ export function register(on: On) {let isRefreshQueued = falselet generation = 0let bodyKey: string | null = null- const polled = { gitDir: '', headKey: '' }+ const polled = { toplevel: '', headKey: '' }let model: PaneState.PaneModel = PaneState.INITIAL_MODELconst timers = new Map<'refresh' | 'redraw' | 'poll', Timer>()const loggedBaseKinds = new Set<'ok' | 'sad'>()- const gitOf =- (engine: Host, pinned: Git.Repository | null): Git.GitRun =>- async argv => {- try {- return await engine.run(- ['git', ...(pinned ? Git.pinnedLeadOf(pinned) : []), ...argv],- {- timeoutMs: Limits.GIT_TIMEOUT_MS,- env: Git.GIT_CHILD_ENV,- ...(pinned && { cwd: pinned.toplevel }),- },+ // The bound host once bind() has run (it sets `host` before pinning), so a+ // backend pinned under one session.start keeps reading through whatever+ // host a later session.start bound; `engine` only before that.+ const currentOf = (engine: Host): Host => host ?? engine++ const backendHostOf = (engine: Host): Backend.BackendHost => ({+ run: (argv, init) => currentOf(engine).run(argv, init),+ readFile: path => currentOf(engine).readFile(path),+ mtimeOf: path => mtimeOf(currentOf(engine))(path),+ entryKindsOf: dir => entryKindsOf(currentOf(engine))(dir),+ nowMs: () => currentOf(engine).now(),+ sessionStartMsOf: () => sessionStartMs,+ onBranchBase: base => {+ const isError = base.kind === 'error'+ const outcome: Record.MarkOutcome = isError+ ? { kind: 'sad', reason: base.reason }+ : { kind: 'ok' }++ if (!loggedBaseKinds.has(outcome.kind)) {+ loggedBaseKinds.add(outcome.kind)+ Record.recorderOf(currentOf(engine)).mark(+ Record.FEATURES.baseResolve,+ outcome,)- } catch {- return { exitCode: -1, stdout: '', stderr: '' }}- }+ },+ })- async function pinRepository(engine: Host): Promise<void> {- if (repository) {+ async function pinBackend(engine: Host): Promise<void> {+ if (backend) {return}- const probed = await Git.repositoryOf(gitOf(engine, null))- repository ??= probed+ const probed = await Backend.backendOf(+ backendHostOf(engine),+ Backend.INSTALLED_BACKEND_PROBES,+ )+ backend ??= probed- if (!probed || repository !== probed) {+ if (!probed || backend !== probed) {return}- const mode = PaneState.baseModeOf(+ const stored = PaneState.baseModeOf(await engine- .storeGet(Names.baseStoreKeyOf(probed.toplevel))+ .storeGet(Names.baseStoreKeyOf(probed.repository.toplevel)).catch(() => undefined),)-- if (mode) {- model = { ...model, requestedMode: mode }+ const mode = stored && probed.baseModes.includes(stored) ? stored : null+ model = {+ ...model,+ words: probed.words,+ baseModes: probed.baseModes,+ ...(mode && { requestedMode: mode }),}}- const depsOf = (engine: Host, pinned: Git.Repository): Git.GitDeps => ({- run: gitOf(engine, pinned),- repository: pinned,- mtimeOf: mtimeOf(engine),- entryKindsOf: entryKindsOf(engine),- sessionStartMs,- onBranchBase: base => {- const isError = base.kind === 'error'- const outcome: Record.MarkOutcome = isError- ? { kind: 'sad', reason: base.reason }- : { kind: 'ok' }-- if (!loggedBaseKinds.has(outcome.kind)) {- loggedBaseKinds.add(outcome.kind)- Record.recorderOf(engine).mark(Record.FEATURES.baseResolve, outcome)- }- },- })-function redraw(engine: Host) {if (timers.has('redraw')) {return@@ -134,7 +135,7 @@ export function register(on: On) {const { data } = modelconst selected = selectedOf()- if (!data || !selected || !repository) {+ if (!data || !selected || !backend) {bodyKey = nullmodel = { ...model, body: null, bodyState: 'idle' }@@ -150,11 +151,7 @@ export function register(on: On) {bodyKey = keymodel = { ...model, body: null, bodyState: 'loading' }redraw(engine)- const body = await Git.fetchFileHunks(- gitOf(engine, repository),- data,- selected,- )+ const body = await backend.fetchFileHunks(data, selected)if (bodyKey !== key) {return@@ -164,24 +161,15 @@ export function register(on: On) {redraw(engine)}- function startPoll(engine: Host, polledRepository: Git.Repository) {- const readHeadKey = () =>- Git.headKeyOf(- {- run: gitOf(engine, polledRepository),- mtimeOf: mtimeOf(engine),- entryKindsOf: entryKindsOf(engine),- readFile: path => engine.readFile(path),- },- polledRepository,- ).catch(() => '')-- if (polled.gitDir === polledRepository.gitDir) {+ function startPoll(engine: Host, pinned: Backend.Backend) {+ const readHeadKey = () => pinned.headKeyOf().catch(() => '')++ if (polled.toplevel === pinned.repository.toplevel) {return}timers.get('poll')?.cancel()- polled.gitDir = polledRepository.gitDir+ polled.toplevel = pinned.repository.toplevelpolled.headKey = ''timers.set('poll',@@ -211,9 +199,10 @@ export function register(on: On) {isRefreshing = trueconst record = Record.recorderOf(engine)+ const pinned = backendconst fetched = (): Promise<Git.FetchOutcome> =>- repository- ? Git.fetchDiff(depsOf(engine, repository), model.requestedMode)+ pinned+ ? pinned.fetchDiff(model.requestedMode): Promise.resolve({ kind: 'no-repository' })try {@@ -236,7 +225,11 @@ export function register(on: On) {case 'data':record.mark(Record.FEATURES.read, { kind: 'ok' })generation += 1- startPoll(engine, outcome.data.repository)++ if (pinned) {+ startPoll(engine, pinned)+ }+break}@@ -304,7 +297,7 @@ export function register(on: On) {}const preference = await engine.storeGet(Names.STORE_OPEN_KEY)- await pinRepository(engine)+ await pinBackend(engine)const isKeptOpen = preference === trueconst floor = isKeptOpen? Limits.OPEN_MIN_COLUMNS@@ -313,7 +306,7 @@ export function register(on: On) {preference !== false &&columns !== null &&columns >= floor &&- repository !== null+ backend !== nullif (!isEligible || isTaken()) {return@@ -422,7 +415,7 @@ export function register(on: On) {return}- await pinRepository(engine)+ await pinBackend(engine)}on('session.start', async ($, e, next) => {@@ -484,9 +477,9 @@ export function register(on: On) {return next(e)}- await pinRepository(host)+ await pinBackend(host)- if (!repository) {+ if (!backend) {return { text: Names.NOT_IN_REPOSITORY_TEXT }}diff --git a/mods/diff/hooks/views/current-pane/current-pane.tsx b/mods/diff/hooks/views/current-pane/current-pane.tsxindex 39d8aa63..44cb1e91 100644--- a/mods/diff/hooks/views/current-pane/current-pane.tsx+++ b/mods/diff/hooks/views/current-pane/current-pane.tsx@@ -46,11 +46,12 @@ export function currentPane(const totals = data? PaneState.headerTotalsOf(data, partition): PaneState.ZERO_TOTALS- const empty = PaneState.emptyStateOf(data, totals.filesCount)+ const empty = PaneState.emptyStateOf(data, totals.filesCount, model.words)const baseLabel = PaneState.baseLabelOf(model.requestedMode,data,totals.filesCount,+ model.words,)const selected = PaneState.selectionOf(PaneState.listedOf(partition, preSession),@@ -89,6 +90,7 @@ export function currentPane(Detail.detailView(kit,{+ words: model.words,path: selected.path,renamedFrom: selected.renamedFrom,isUntracked: selected.isUntracked,@@ -114,7 +116,11 @@ export function currentPane(typeof line === 'string' ? noteOf(line) : rowOf(line),),noteOf(totals.notShown > 0 ? `${totals.notShown} not shown` : null),- noteOf(isUntrackedNoted ? Names.UNTRACKED_WITHHELD_TEXT : null),+ noteOf(+ isUntrackedNoted+ ? Names.untrackedWithheldTextOf(model.words.lister)+ : null,+ ),earlierToggle,...earlierRows.map(rowOf),...detail,diff --git a/mods/diff/hooks/views/detail/detail-model/detail-model.ts b/mods/diff/hooks/views/detail/detail-model/detail-model.tsindex bd0e9993..4b27ae0c 100644--- a/mods/diff/hooks/views/detail/detail-model/detail-model.ts+++ b/mods/diff/hooks/views/detail/detail-model/detail-model.ts@@ -1,11 +1,14 @@+import type Backend from '../../../backend'import type Git from '../../../git'import type PaneState from '../../../pane-state'/*** The selected file as its body draws it: the path, what kind of row it is,- * its hunks once read, and whether it is armed for the next prompt.+ * its hunks once read, whether it is armed for the next prompt, and the+ * backend's words for an untracked row's note.*/export type DetailModel = {+ words: Pick<Backend.BackendWords, 'untrackedNoteOf'>path: stringrenamedFrom: string | nullisUntracked: booleandiff --git a/mods/diff/hooks/views/detail/placeholder-of/placeholder-of.ts b/mods/diff/hooks/views/detail/placeholder-of/placeholder-of.tsindex d3d6f6b2..3d048e3a 100644--- a/mods/diff/hooks/views/detail/placeholder-of/placeholder-of.ts+++ b/mods/diff/hooks/views/detail/placeholder-of/placeholder-of.ts@@ -5,23 +5,19 @@ import { SAFE_PATHSPEC_PATTERN } from './safe-pathspec-pattern'* The dim italic lines drawn instead of hunks (DiffDetailView's wording),* or null when the hunks draw.*- * Untracked (the pasteable `git add` line only for a name of letters,- * digits and `._/@+-`, any other told to stage without one), binary,- * loading, unreadable, large, or empty.+ * Untracked (the backend's note, its pasteable command only for a name of+ * letters, digits and `._/@+-`), binary, loading, unreadable, large, or+ * empty.** @param detail the selected file* @returns the lines, or null*/export function placeholderOf(detail: DetailModel): readonly string[] | null {if (detail.isUntracked) {- const isPasteable = SAFE_PATHSPEC_PATTERN.test(detail.path)-- return [- 'New file not yet staged.',- isPasteable- ? `Run \`git add ':/${detail.path}'\` to see line counts.`- : 'Stage it with git add to see line counts.',- ]+ return detail.words.untrackedNoteOf(+ detail.path,+ SAFE_PATHSPEC_PATTERN.test(detail.path),+ )}if (detail.isBinary) {diff --git a/mods/diff/hooks/views/detail/placeholder-of/safe-pathspec-pattern/safe-pathspec-pattern.ts b/mods/diff/hooks/views/detail/placeholder-of/safe-pathspec-pattern/safe-pathspec-pattern.tsindex 3f936e93..61cf39a7 100644--- a/mods/diff/hooks/views/detail/placeholder-of/safe-pathspec-pattern/safe-pathspec-pattern.ts+++ b/mods/diff/hooks/views/detail/placeholder-of/safe-pathspec-pattern/safe-pathspec-pattern.ts@@ -1,5 +1,5 @@/**- * A file name safe to paste inside `git add ':/…'` in any shell (POSIX,+ * A file name safe to paste into a stage command in any shell (POSIX,* PowerShell, cmd): letters and digits of any script and `._/@+-` only.** No quote of any kind, no separator and no substitution can ride in it.diff --git a/mods/diff/hooks/views/sections/controls-view.tsx b/mods/diff/hooks/views/sections/controls-view.tsxindex 41db64a7..84479cc9 100644--- a/mods/diff/hooks/views/sections/controls-view.tsx+++ b/mods/diff/hooks/views/sections/controls-view.tsx@@ -12,7 +12,9 @@ import { present } from './present'* turn with edits, newest first) and, for the current source, the base.** The source picker draws only when a turn exists, as DiffDialog hides its- * tabs; the base picker is the built-in's ctrl+x b cycle as a Select.+ * tabs; the base picker is the built-in's ctrl+x b cycle as a Select over+ * the modes the backend offers, uncommitted mode naming the base as the+ * base line does (modeLabelOf).** @param kit the elements and the handlers* @param model what is picked now and the turns to pick from@@ -20,7 +22,10 @@ import { present } from './present'*/export function controlsView(kit: Kit,- model: Pick<PaneState.PaneModel, 'source' | 'requestedMode' | 'turns'>,+ model: Pick<+ PaneState.PaneModel,+ 'source' | 'requestedMode' | 'turns' | 'baseModes' | 'words' | 'data'+ >,): RenderElement | null {const { Box, Select } = kit.uiconst { source, turns } = model@@ -41,15 +46,24 @@ export function controlsView(/>) : nullconst isCurrent = source.kind === 'current'+ const fetchedSource = model.data?.source+ const base =+ fetchedSource?.kind === 'working-tree'+ ? fetchedSource.base+ : model.words.baseconst basePicker = isCurrent ? (<Selectkey="base"label="base"- options={[- { value: 'session', label: 'this session' },- { value: 'uncommitted', label: 'uncommitted (vs HEAD)' },- { value: 'branch', label: 'branch' },- ]}+ options={model.baseModes.map(mode => ({+ value: mode,+ label:+ mode === 'uncommitted'+ ? `uncommitted (vs ${base})`+ : mode === 'session'+ ? 'this session'+ : mode,+ }))}value={model.requestedMode}onSelect={value => kit.actions.chooseBase(value)}/>diff --git a/mods/diff/hooks/views/turn-pane/turn-pane.tsx b/mods/diff/hooks/views/turn-pane/turn-pane.tsxindex e8eb38b5..cdee0eb6 100644--- a/mods/diff/hooks/views/turn-pane/turn-pane.tsx+++ b/mods/diff/hooks/views/turn-pane/turn-pane.tsx@@ -49,6 +49,7 @@ export function turnPane(Detail.detailView(kit,{+ words: model.words,path: selected.path,renamedFrom: null,isUntracked: false,