Skip to content

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: blank lines between statement kinds and around multi-line statements

poteat748e0c4a4488
diff --git a/mods/diff/hooks/classify/is-generated-file/is-generated-file.ts b/mods/diff/hooks/classify/is-generated-file/is-generated-file.ts
index 937d558f..7ced1855 100644
--- a/mods/diff/hooks/classify/is-generated-file/is-generated-file.ts
+++ b/mods/diff/hooks/classify/is-generated-file/is-generated-file.ts
@@ -15,6 +15,7 @@ import { GENERATED_SUFFIXES } from './generated-suffixes'
export function isGeneratedFile(path: string) {
const name = baseNameOf(path).toLowerCase()
const rooted = rootedPathOf(path)
+
const hasGeneratedSuffix = GENERATED_SUFFIXES.some(suffix =>
name.endsWith(suffix),
)
diff --git a/mods/diff/hooks/git/git-backend-of.ts b/mods/diff/hooks/git/git-backend-of.ts
index 99504fe4..ab611aef 100644
--- a/mods/diff/hooks/git/git-backend-of.ts
+++ b/mods/diff/hooks/git/git-backend-of.ts
@@ -46,6 +46,7 @@ export async function gitBackendOf(
}
const run = runOf(repository)
+
const depsOf = (): Types.GitDeps => ({
run,
repository,
diff --git a/mods/diff/hooks/git/parse/parse-file-diff.ts b/mods/diff/hooks/git/parse/parse-file-diff.ts
index 21c6d35b..60c31d66 100644
--- a/mods/diff/hooks/git/parse/parse-file-diff.ts
+++ b/mods/diff/hooks/git/parse/parse-file-diff.ts
@@ -22,6 +22,7 @@ export function parseFileDiff(stdout: string): Types.FileHunks {
}
const rows = stdout.split('\n')
+
const headerRows = rows.flatMap((row, at) =>
HUNK_HEADER.test(row) ? [at] : [],
)
diff --git a/mods/diff/hooks/git/parse/parse-numstat.ts b/mods/diff/hooks/git/parse/parse-numstat.ts
index 65728d1e..3354bdeb 100644
--- a/mods/diff/hooks/git/parse/parse-numstat.ts
+++ b/mods/diff/hooks/git/parse/parse-numstat.ts
@@ -26,11 +26,13 @@ export function parseNumstat(
const [addedField, removedField, ...pathFields] = (records[at] ?? '').split(
'\t',
)
+
const inline = pathFields.join('\t')
const isRename = pathFields.length === 1 && inline === ''
const renamedFrom = isRename ? (records[at + 1] ?? null) : null
const path = isRename ? (records[at + 2] ?? '') : inline
at += isRename ? RENAME_RECORDS : 1
+
const isRow =
addedField !== undefined && removedField !== undefined && path !== ''
@@ -41,6 +43,7 @@ export function parseNumstat(
const isBinary = addedField === '-' || removedField === '-'
const added = isBinary ? 0 : Number(addedField) || 0
const removed = isBinary ? 0 : Number(removedField) || 0
+
stats.filesCount += 1
stats.linesAdded += added
stats.linesRemoved += removed
diff --git a/mods/diff/hooks/git/probes/branch-base-of/branch-base-of.ts b/mods/diff/hooks/git/probes/branch-base-of/branch-base-of.ts
index 06dd410d..778d9924 100644
--- a/mods/diff/hooks/git/probes/branch-base-of/branch-base-of.ts
+++ b/mods/diff/hooks/git/probes/branch-base-of/branch-base-of.ts
@@ -23,6 +23,7 @@ export async function branchBaseOf(
currentBranchOf(run),
defaultBranchOf(run),
])
+
const isUnrelated = branch === 'HEAD' || defaultBranch.startsWith('-')
if (isUnrelated) {
@@ -37,6 +38,7 @@ export async function branchBaseOf(
run,
defaultBranch,
)
+
const [first, second] = candidates
if (first === undefined) {
@@ -57,6 +59,7 @@ export async function branchBaseOf(
second,
])
).exitCode === 0
+
const mergeBase = isLocalBaseNewer ? second : first
const head = await run([Argv.NO_OPTIONAL_LOCKS, 'rev-parse', 'HEAD'])
diff --git a/mods/diff/hooks/git/probes/current-branch-of/current-branch-of.ts b/mods/diff/hooks/git/probes/current-branch-of/current-branch-of.ts
index db8b9f24..ed126a9e 100644
--- a/mods/diff/hooks/git/probes/current-branch-of/current-branch-of.ts
+++ b/mods/diff/hooks/git/probes/current-branch-of/current-branch-of.ts
@@ -14,6 +14,7 @@ export async function currentBranchOf(run: Types.GitRun): Promise<string> {
'--abbrev-ref',
'HEAD',
])
+
const name = stdout.trim()
return exitCode === 0 && name !== '' ? name : 'HEAD'
diff --git a/mods/diff/hooks/git/probes/datings-of/datings-of.ts b/mods/diff/hooks/git/probes/datings-of/datings-of.ts
index ef6fdda8..e0629405 100644
--- a/mods/diff/hooks/git/probes/datings-of/datings-of.ts
+++ b/mods/diff/hooks/git/probes/datings-of/datings-of.ts
@@ -19,6 +19,7 @@ export async function datingsOf(
paths: readonly string[],
): Promise<ReadonlyMap<string, Types.Dating>> {
const { sessionStartMs } = context.deps
+
const stamps: readonly Types.Stamp[] = await Promise.all(
paths.map(path => stampIfFile(context.stamps, path)),
)
diff --git a/mods/diff/hooks/git/probes/default-branch-of/default-branch-of.ts b/mods/diff/hooks/git/probes/default-branch-of/default-branch-of.ts
index 4b1fff97..c32461f1 100644
--- a/mods/diff/hooks/git/probes/default-branch-of/default-branch-of.ts
+++ b/mods/diff/hooks/git/probes/default-branch-of/default-branch-of.ts
@@ -22,12 +22,14 @@ export async function defaultBranchOf(run: Types.GitRun): Promise<string> {
`refs/remotes/origin/${branch}`,
])
).exitCode === 0
+
const symref = await run([
Argv.NO_OPTIONAL_LOCKS,
'symbolic-ref',
'--short',
'refs/remotes/origin/HEAD',
])
+
const named =
symref.exitCode === 0 ? symref.stdout.trim().replace(/^origin\//, '') : ''
diff --git a/mods/diff/hooks/git/probes/head-key-of/head-key-of.ts b/mods/diff/hooks/git/probes/head-key-of/head-key-of.ts
index ff381415..453e1736 100644
--- a/mods/diff/hooks/git/probes/head-key-of/head-key-of.ts
+++ b/mods/diff/hooks/git/probes/head-key-of/head-key-of.ts
@@ -26,7 +26,9 @@ export async function headKeyOf(
repository.gitDir,
Limits.MAX_LISTED_DIRECTORIES,
)
+
const isShared = repository.commonDir === repository.gitDir
+
const common = isShared
? own
: stampProbeOf(deps, repository.commonDir, Limits.MAX_LISTED_DIRECTORIES)
diff --git a/mods/diff/hooks/git/probes/kind-walk-of/kind-walk-of.ts b/mods/diff/hooks/git/probes/kind-walk-of/kind-walk-of.ts
index 7e22c019..aeb01436 100644
--- a/mods/diff/hooks/git/probes/kind-walk-of/kind-walk-of.ts
+++ b/mods/diff/hooks/git/probes/kind-walk-of/kind-walk-of.ts
@@ -33,6 +33,7 @@ export function kindWalkOf(
const listed =
held ?? entryKindsOf(directory === '' ? root : `${root}/${directory}`)
+
listings.set(directory, listed)
return listed
diff --git a/mods/diff/hooks/git/probes/missing-base-of/missing-base-of.ts b/mods/diff/hooks/git/probes/missing-base-of/missing-base-of.ts
index fea8f2c1..a253e21a 100644
--- a/mods/diff/hooks/git/probes/missing-base-of/missing-base-of.ts
+++ b/mods/diff/hooks/git/probes/missing-base-of/missing-base-of.ts
@@ -27,6 +27,7 @@ export async function missingBaseOf(
'--quiet',
ref,
])
+
const isPresentOrUnknown = exitCode === 0 || exitCode === -1
if (isPresentOrUnknown) {
diff --git a/mods/diff/hooks/git/probes/overlay-unstaged.ts b/mods/diff/hooks/git/probes/overlay-unstaged.ts
index 53044117..3417d2b2 100644
--- a/mods/diff/hooks/git/probes/overlay-unstaged.ts
+++ b/mods/diff/hooks/git/probes/overlay-unstaged.ts
@@ -17,6 +17,7 @@ export function overlayUnstaged(
unstaged: Types.NumstatResult,
): Types.NumstatResult {
const edits = new Map(unstaged.files.map(file => [file.path, file]))
+
const files = staged.files.map(file => {
const edit = edits.get(file.path)
@@ -25,16 +26,19 @@ export function overlayUnstaged(
}
const isBinary = file.isBinary || edit.isBinary
+
const added = isBinary
? 0
: Math.max(0, file.added + edit.added - edit.removed)
return { ...file, added, removed: 0, isBinary }
})
+
const linesAdded =
staged.stats.linesAdded +
files.reduce((sum, file) => sum + file.added, 0) -
staged.files.reduce((sum, file) => sum + file.added, 0)
+
const stats = { ...staged.stats, linesAdded }
return { stats, files }
diff --git a/mods/diff/hooks/git/probes/repository-of/repository-of.ts b/mods/diff/hooks/git/probes/repository-of/repository-of.ts
index a809ff6c..9638cff7 100644
--- a/mods/diff/hooks/git/probes/repository-of/repository-of.ts
+++ b/mods/diff/hooks/git/probes/repository-of/repository-of.ts
@@ -25,8 +25,10 @@ export async function repositoryOf(
'--git-dir',
'--git-common-dir',
])
+
const lines = stdout.split('\n').filter(line => line !== '')
const [toplevel = '', gitDir = '', commonDir = ''] = lines
+
const isResolved =
exitCode === 0 &&
lines.length === REPOSITORY_LINES &&
diff --git a/mods/diff/hooks/git/probes/stats-of.ts b/mods/diff/hooks/git/probes/stats-of.ts
index 48059a59..0662d8c6 100644
--- a/mods/diff/hooks/git/probes/stats-of.ts
+++ b/mods/diff/hooks/git/probes/stats-of.ts
@@ -21,8 +21,10 @@ export async function statsOf(
const run = context.run
const shortstat = await run([...Argv.DIFF_LEADING_ARGS, base, '--shortstat'])
+
const totals =
shortstat.exitCode === 0 ? Parse.parseShortstat(shortstat.stdout) : null
+
const isPastDetails =
totals !== null && totals.filesCount > Limits.MAX_FILES_FOR_DETAILS
@@ -36,6 +38,7 @@ export async function statsOf(
'--numstat',
'-z',
])
+
const isRead = Parse.isWholeAnswer(numstat)
return isRead ? Parse.parseNumstat(numstat.stdout, Limits.MAX_FILES) : null
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.ts
index 4b0104b8..a290c92f 100644
--- 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.ts
@@ -23,11 +23,14 @@ export async function untrackedRowsOf(
): Promise<readonly Types.FileStat[]> {
const probedPaths = paths.slice(0, Limits.MAX_UNTRACKED_PROBES)
const datings = await datingsOf(context, 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),
@@ -36,6 +39,7 @@ export async function untrackedRowsOf(
.map(path => ({ path, isPreSession: true })),
]
: []
+
const ordered = [...probed.filter(file => !file.isPreSession), ...earlier]
return ordered.slice(0, place.slots).map(file => ({
diff --git a/mods/diff/hooks/git/tiers/unborn-tier/unborn-tier.ts b/mods/diff/hooks/git/tiers/unborn-tier/unborn-tier.ts
index eabf6303..1c42d329 100644
--- a/mods/diff/hooks/git/tiers/unborn-tier/unborn-tier.ts
+++ b/mods/diff/hooks/git/tiers/unborn-tier/unborn-tier.ts
@@ -31,6 +31,7 @@ export async function unbornTier(
}
const isOverlaid = staged.files.length > 0
+
const unstaged = isOverlaid
? await Probes.unstagedNumstat(run)
: EMPTY_NUMSTAT
diff --git a/mods/diff/hooks/git/tiers/working-tree-tier.ts b/mods/diff/hooks/git/tiers/working-tree-tier.ts
index ad7280b7..cf9441a8 100644
--- a/mods/diff/hooks/git/tiers/working-tree-tier.ts
+++ b/mods/diff/hooks/git/tiers/working-tree-tier.ts
@@ -26,9 +26,11 @@ export async function workingTreeTier(
}
const isSession = context.mode === 'session'
+
const files = isSession
? await Probes.tagPreSession(context, workingTree.files)
: workingTree.files
+
const data = diffDataOf(
context,
await withUntracked(
diff --git a/mods/diff/hooks/pane-toggle/pane-toggle-of.ts b/mods/diff/hooks/pane-toggle/pane-toggle-of.ts
index 431f6900..475c5f7b 100644
--- a/mods/diff/hooks/pane-toggle/pane-toggle-of.ts
+++ b/mods/diff/hooks/pane-toggle/pane-toggle-of.ts
@@ -16,6 +16,7 @@ export function paneToggleOf(
pane: PaneBelief,
): 'open' | 'close' | 'too-narrow' {
const isClosing = pane.isBelievedOpen && pane.wasDrawnWhenProbed
+
const isTooNarrow =
pane.columns !== null && pane.columns < Limits.OPEN_MIN_COLUMNS
diff --git a/mods/diff/hooks/register.ts b/mods/diff/hooks/register.ts
index 2c89db75..fc0c03ff 100644
--- a/mods/diff/hooks/register.ts
+++ b/mods/diff/hooks/register.ts
@@ -59,6 +59,7 @@ export function register(on: On) {
sessionStartMsOf: () => sessionStartMs,
onBranchBase: base => {
const isError = base.kind === 'error'
+
const outcome: Record.MarkOutcome = isError
? { kind: 'sad', reason: base.reason }
: {
@@ -70,6 +71,7 @@ export function register(on: On) {
if (!loggedBaseKinds.has(outcome.kind)) {
loggedBaseKinds.add(outcome.kind)
+
Record.recorderOf(currentOf(engine)).mark(
Record.FEATURES.baseResolve,
outcome,
@@ -93,6 +95,7 @@ export function register(on: On) {
async function probeBackend(engine: Host): Promise<boolean> {
const asked = { isAnswered: true }
const probeHost = backendHostOf(engine)
+
const probed = await Backend.backendOf(
{
...probeHost,
@@ -100,11 +103,13 @@ export function register(on: On) {
probeHost.run(argv, init).catch((error: unknown) => {
asked.isAnswered &&=
argv[0] !== 'git' || !/\baborted\b/.test(messageOf(error))
+
throw error
}),
},
Backend.INSTALLED_BACKEND_PROBES,
)
+
backend ??= probed
if (!probed || backend !== probed) {
@@ -116,7 +121,9 @@ export function register(on: On) {
.storeGet(Names.baseStoreKeyOf(probed.repository.toplevel))
.catch(() => undefined),
)
+
const mode = stored && probed.baseModes.includes(stored) ? stored : null
+
model = {
...model,
words: probed.words,
@@ -173,6 +180,7 @@ export function register(on: On) {
bodyKey = key
model = { ...model, body: null, bodyState: 'loading' }
redraw(engine)
+
const body = await backend.fetchFileHunks(data, selected)
if (bodyKey !== key) {
@@ -195,6 +203,7 @@ export function register(on: On) {
timers.get('poll')?.cancel()
polled.toplevel = pinned.repository.toplevel
polled.headKey = ''
+
timers.set(
'poll',
engine.every(Limits.HEAD_POLL_MS, () => {
@@ -204,6 +213,7 @@ export function register(on: On) {
void readHeadKey().then(key => {
const hasMoved = polled.headKey !== '' && key !== polled.headKey
+
polled.headKey = key
if (hasMoved) {
@@ -222,8 +232,10 @@ export function register(on: On) {
}
isRefreshing = true
+
const record = Record.recorderOf(engine)
const pinned = backend
+
const fetched = (): Promise<Git.FetchOutcome> =>
pinned
? pinned.fetchDiff(model.requestedMode)
@@ -231,10 +243,12 @@ export function register(on: On) {
try {
model = { ...model, isLoading: model.data === null }
+
const [outcome, messages] = await Promise.all([
fetched(),
engine.messages().catch((): SessionMessage[] => []),
])
+
model = PaneState.afterFetch(model, { outcome, messages })
switch (outcome.kind) {
@@ -245,6 +259,7 @@ export function register(on: On) {
kind: 'sad',
reason: 'git_diff_failed',
})
+
break
case 'data':
generation += 1
@@ -286,6 +301,7 @@ export function register(on: On) {
function scheduleRefresh(engine: Host): void {
timers.get('refresh')?.cancel()
+
timers.set(
'refresh',
engine.after(Limits.REFRESH_DEBOUNCE_MS, () => {
@@ -303,6 +319,7 @@ export function register(on: On) {
const isManual = trigger === 'manual'
await engine.openPane(isManual ? { ...pane, ...Names.FOCUSED_PANE } : pane)
isPaneOpen = true
+
const sessionId = await engine.sessionId().catch(() => null)
if (sessionId !== null && sessionId !== shownSessionId) {
@@ -341,11 +358,15 @@ export function register(on: On) {
}
const preference = await engine.storeGet(Names.STORE_OPEN_KEY)
+
await pinBackend(engine)
+
const isKeptOpen = preference === true
+
const floor = isKeptOpen
? Limits.OPEN_MIN_COLUMNS
: Limits.AUTO_OPEN_MIN_COLUMNS
+
const isEligible =
preference !== false &&
columns !== null &&
@@ -391,10 +412,12 @@ export function register(on: On) {
bodyKey = null
model = { ...model, requestedMode: mode, body: null, bodyState: 'idle' }
+
Record.recorderOf(engine).mark(Record.FEATURES.baseSwitch, {
kind: 'ok',
props: { mode: { value: mode, of: model.baseModes } },
})
+
const toplevel = model.data?.repository.toplevel
if (toplevel !== undefined) {
@@ -409,9 +432,11 @@ export function register(on: On) {
chooseSource: value => {
const index = Number(value)
const isTurn = value !== 'current' && Number.isInteger(index)
+
const source: PaneState.Source = isTurn
? { kind: 'turn', index }
: { kind: 'current' }
+
model = { ...model, source, selectedPath: null }
void loadBody(engine)
redraw(engine)
@@ -442,11 +467,14 @@ export function register(on: On) {
model.body?.hunks ??
[],
)
+
model = { ...model, armedPath: path }
+
engine.status(
`${Views.sanitizeName(path)} rides your next prompt (press ` +
`asked ✓ to drop it)`,
)
+
redraw(engine)
}
@@ -510,6 +538,7 @@ export function register(on: On) {
}
const { Box, Text, Button, Select, Code } = await $.ui.resolve(e)
+
wasDrawnSinceProbe = true
columns = e.viewport?.columns ?? columns
model = { ...model, isFocused: e.props.isFocused }
@@ -624,6 +653,7 @@ export function register(on: On) {
}
const context = e.context ?? []
+
const text = Ask.fittedAskTextOf(
asked.text,
Limits.PROMPT_CONTEXT_MAX_CHARS -
@@ -632,10 +662,12 @@ export function register(on: On) {
if (text === undefined) {
disarm(host)
+
host.status(
`${Views.sanitizeName(asked.path)}'s diff did not fit in the prompt ` +
`and was dropped`,
)
+
redraw(host)
return next(e)
diff --git a/mods/diff/hooks/todos/todo-progress-of.ts b/mods/diff/hooks/todos/todo-progress-of.ts
index 42b9870e..79ab84f7 100644
--- a/mods/diff/hooks/todos/todo-progress-of.ts
+++ b/mods/diff/hooks/todos/todo-progress-of.ts
@@ -21,6 +21,7 @@ export function todoProgressOf(
const latest = messages
.flatMap(message => message.toolUses)
.findLast(use => use.tool === Tools.TODO_TOOL)
+
const statuses = arrayOf(latest?.input.todos).map(todo =>
isRecord(todo) ? todo.status : null,
)
diff --git a/mods/diff/hooks/turns/turn-of/file-edit-of/hunks-of/hunks-of.ts b/mods/diff/hooks/turns/turn-of/file-edit-of/hunks-of/hunks-of.ts
index de9975f5..ec1967e6 100644
--- a/mods/diff/hooks/turns/turn-of/file-edit-of/hunks-of/hunks-of.ts
+++ b/mods/diff/hooks/turns/turn-of/file-edit-of/hunks-of/hunks-of.ts
@@ -14,6 +14,7 @@ export const hunksOf = (patch: unknown): Git.Hunk[] =>
.filter(isRecord)
.flatMap(hunk => {
const { oldStart, newStart, lines } = hunk
+
const isHunk =
typeof oldStart === 'number' &&
typeof newStart === 'number' &&
diff --git a/mods/diff/hooks/turns/turn-of/turn-of.ts b/mods/diff/hooks/turns/turn-of/turn-of.ts
index f10c704b..dac2c73a 100644
--- a/mods/diff/hooks/turns/turn-of/turn-of.ts
+++ b/mods/diff/hooks/turns/turn-of/turn-of.ts
@@ -22,17 +22,21 @@ export function turnOf(
): Types.TurnDiff {
const text = rows[0]?.text ?? ''
const isShort = [...text].length <= PREVIEW_CHARS
+
const preview = isShort
? text
: `${[...text].slice(0, PREVIEW_CHARS - 1).join('')}…`
+
const edits = rows
.flatMap(row => (row.role === 'assistant' ? row.toolUses : []))
.map(use => fileEditOf(use.result))
.filter((edit): edit is Types.TurnFile => edit !== null)
+
const byPath = new Map<string, Types.TurnFile>()
for (const edit of edits) {
const earlier = byPath.get(edit.path)
+
byPath.set(
edit.path,
earlier
diff --git a/mods/diff/hooks/views/current-pane/current-pane.tsx b/mods/diff/hooks/views/current-pane/current-pane.tsx
index 70875fb6..733839a9 100644
--- a/mods/diff/hooks/views/current-pane/current-pane.tsx
+++ b/mods/diff/hooks/views/current-pane/current-pane.tsx
@@ -50,56 +50,71 @@ export function currentPane(
const noise = model.isNoiseShown ? 'shown' : 'hidden'
const preSession = model.isPreSessionShown ? 'shown' : 'hidden'
const partition = PaneState.partitionOf(data?.files ?? [], noise)
+
const totals = data
? PaneState.headerTotalsOf(data, partition)
: PaneState.ZERO_TOTALS
+
const empty = PaneState.emptyStateOf(data, totals.filesCount, model.words)
const baseLabel = PaneState.baseLabelOf(model, totals.filesCount)
+
const selected = PaneState.selectionOf(
PaneState.listedOf(partition, preSession),
model.selectedPath,
)
+
const rowOf = (file: Git.FileStat): RenderElement =>
Sections.fileRow(kit, fileRowOf(file, selected?.path ?? null), () =>
kit.actions.selectFile(file.path),
)
+
const noteOf = (text: string | null): RenderElement | null =>
text === null ? null : Sections.dimNote(kit, Layout.sanitizeName(text))
+
const noiseFace = model.isNoiseShown ? 'hide' : 'show'
const noiseCount = Layout.plural(partition.noiseCount, 'test')
const hasNoise = partition.noiseCount > 0
+
const noiseToggle = hasNoise
? Sections.toggleRow(kit, 'noise', {
label: `${noiseCount}/generated (${noiseFace})`,
onPress: kit.actions.toggleNoise,
})
: null
+
const earlierFace = model.isPreSessionShown ? 'hide' : 'show'
const earlierCount = Layout.plural(partition.preSession.length, 'file')
const hasEarlier = partition.preSession.length > 0
+
const earlierToggle = hasEarlier
? Sections.toggleRow(kit, 'presession', {
label: `+${earlierCount} edited before this session (${earlierFace})`,
onPress: kit.actions.togglePreSession,
})
: null
+
const earlierFiles = model.isPreSessionShown ? partition.preSession : []
const isEarlierListed = earlierFiles.length > 0
+
const earlierRows = isEarlierListed
? [<Box height={1} />, ...earlierFiles.map(rowOf)]
: []
+
const isUntrackedNoted = data?.isUntrackedWithheld === true && !empty
const listed = listBodyOf(kit, { data, partition, totals, empty })
const notes = listed.filter(line => typeof line === 'string')
const hasRows = notes.length < listed.length
const message = empty ? [empty.headline, ...notes] : hasRows ? [] : notes
const header = Sections.headerView(kit, empty ? null : totals)
+
const notShownNote = noteOf(
totals.notShown > 0 ? `${totals.notShown} not shown` : null,
)
+
const untrackedNote = noteOf(
isUntrackedNoted ? Names.untrackedWithheldTextOf(model.words) : null,
)
+
const detail = selected
? [
Sections.divider(kit),
diff --git a/mods/diff/hooks/views/current-pane/file-row-of/file-row-of.ts b/mods/diff/hooks/views/current-pane/file-row-of/file-row-of.ts
index eae8c3e9..c1b50c85 100644
--- a/mods/diff/hooks/views/current-pane/file-row-of/file-row-of.ts
+++ b/mods/diff/hooks/views/current-pane/file-row-of/file-row-of.ts
@@ -14,6 +14,7 @@ export function fileRowOf(
selectedPath: string | null,
): Sections.FileRowModel {
const isRenamed = file.renamedFrom !== null
+
const note = file.isUntracked
? 'untracked'
: file.isBinary
diff --git a/mods/diff/hooks/views/current-pane/message-pane-of/message-pane-of.tsx b/mods/diff/hooks/views/current-pane/message-pane-of/message-pane-of.tsx
index a82a8533..f2b2180b 100644
--- a/mods/diff/hooks/views/current-pane/message-pane-of/message-pane-of.tsx
+++ b/mods/diff/hooks/views/current-pane/message-pane-of/message-pane-of.tsx
@@ -24,20 +24,26 @@ import type { MessagePane } from './message-pane'
export function messagePaneOf(kit: Kit, pane: MessagePane): RenderElement {
const { Box, Text } = kit.ui
const { top, controls, earlier, rest } = pane
+
const lines = pane.message.flatMap(text =>
Layout.wrappedLines(Layout.sanitizeName(text), kit.columns),
)
+
const drawn = lines.map(line => <Text dimColor>{line}</Text>)
const controlRows = controls === null ? [] : [controls]
const earlierRows = earlier === null ? [] : [earlier]
+
const isControlsAboveEarlier =
controlRows.length > 0 || earlierRows.length === 0
+
const aboveEarlier = isControlsAboveEarlier
? controlRows
: [<Box height={1} />]
+
const footRows = earlier === null ? 0 : FOOT_ROWS
const middleRows = kit.rows - top.length - 1 - footRows
const above = Math.floor((middleRows - lines.length) / 2)
+
const isCentered =
rest.length === 0 && middleRows - above - lines.length >= controlRows.length
@@ -57,6 +63,7 @@ export function messagePaneOf(kit: Kit, pane: MessagePane): RenderElement {
}
const spacer = above > 0 ? [<Box height={above} />] : []
+
const foot = earlierRows.map(row => (
<Box flexDirection="column" marginTop={1} paddingBottom={1}>
{row}
diff --git a/mods/diff/hooks/views/detail/code-blocks-of/code-blocks-of.ts b/mods/diff/hooks/views/detail/code-blocks-of/code-blocks-of.ts
index 9fc0cc18..e8a38e0c 100644
--- a/mods/diff/hooks/views/detail/code-blocks-of/code-blocks-of.ts
+++ b/mods/diff/hooks/views/detail/code-blocks-of/code-blocks-of.ts
@@ -36,15 +36,19 @@ export function codeBlocksOf(hunks: readonly Git.Hunk[]): Types.CodeBody {
const last = blocks.at(-1)
const source = hunkSourceOf(piece)
const isHunkStart = at === 0
+
const isJoining =
isHunkStart &&
last !== undefined &&
last.source.length + 1 + source.length <= MAX_CODE_CHARS
+
const hasDivider = isHunkStart && !isJoining && last !== undefined
const overhead = isJoining ? 1 : hasDivider ? HUNK_DIVIDER.length : 0
+
const addedNodes = isJoining
? 0
: 1 + (hasDivider ? HUNK_DIVIDER_NODES : 0)
+
const room = MAX_BODY_CHARS - chars - overhead
const fitted = source.length <= room ? piece : leadingHunkOf(piece, room)
const isOverNodes = nodes + addedNodes > MAX_BODY_NODES
@@ -63,6 +67,7 @@ export function codeBlocksOf(hunks: readonly Git.Hunk[]): Types.CodeBody {
source: isJoining ? `${last.source}\n${text}` : text,
hasDivider: isJoining ? last.hasDivider : hasDivider,
})
+
chars += overhead + text.length
nodes += addedNodes
diff --git a/mods/diff/hooks/views/detail/detail-view.tsx b/mods/diff/hooks/views/detail/detail-view.tsx
index 303c7a93..73025ed3 100644
--- a/mods/diff/hooks/views/detail/detail-view.tsx
+++ b/mods/diff/hooks/views/detail/detail-view.tsx
@@ -35,16 +35,21 @@ export function detailView(
const code = codeBlocksOf(placeholder ? [] : (detail.body?.hunks ?? []))
const isTruncated = detail.body?.isTruncated === true || code.isTruncated
const path = Layout.sanitizeName(detail.path).slice(-MAX_CODE_CHARS)
+
const nameOf = (name: string) =>
Layout.truncateStart(Layout.sanitizeName(name), kit.columns)
+
const renamedFrom =
detail.renamedFrom === null ? null : nameOf(detail.renamedFrom)
+
const asides = [
renamedFrom === null ? null : `renamed from ${renamedFrom}`,
detail.isUntracked ? 'untracked' : null,
isTruncated ? 'truncated' : null,
].filter(word => word !== null)
+
const aside = asides.length === 0 ? '' : ` (${asides.join(', ')})`
+
const ask = placeholder
? []
: [
@@ -52,6 +57,7 @@ export function detailView(
{detail.isArmed ? 'asked ✓' : 'ask'}
</Button>,
]
+
const footer = isTruncated
? [
<Text dimColor italic>
@@ -59,11 +65,13 @@ export function detailView(
</Text>,
]
: []
+
const notes = (placeholder ?? []).map(line => (
<Text dimColor italic wrap="wrap">
{line}
</Text>
))
+
const hunks = code.blocks.flatMap(block => [
...(block.hasDivider ? [<Text dimColor>{HUNK_DIVIDER}</Text>] : []),
<Code source={block.source} format="diff" path={path} />,
diff --git a/mods/diff/hooks/views/detail/leading-hunk-of/leading-hunk-of.ts b/mods/diff/hooks/views/detail/leading-hunk-of/leading-hunk-of.ts
index 0672a071..c3159043 100644
--- a/mods/diff/hooks/views/detail/leading-hunk-of/leading-hunk-of.ts
+++ b/mods/diff/hooks/views/detail/leading-hunk-of/leading-hunk-of.ts
@@ -18,6 +18,7 @@ export function leadingHunkOf(hunk: Git.Hunk, maxChars: number): Git.Hunk {
...hunk,
lines: hunk.lines.slice(0, taken + 1),
})
+
bodyChars += 1 + line.length
if (header.length + bodyChars > maxChars) {
diff --git a/mods/diff/hooks/views/detail/placeholder-of/placeholder-of.ts b/mods/diff/hooks/views/detail/placeholder-of/placeholder-of.ts
index 3d048e3a..0ae29a76 100644
--- a/mods/diff/hooks/views/detail/placeholder-of/placeholder-of.ts
+++ b/mods/diff/hooks/views/detail/placeholder-of/placeholder-of.ts
@@ -34,6 +34,7 @@ export function placeholderOf(detail: DetailModel): readonly string[] | null {
const { isLarge, hunks } = detail.body
const isEmpty = hunks.length === 0
+
const note = isLarge
? 'Large file - diff exceeds 1 MB limit'
: isEmpty
diff --git a/mods/diff/hooks/views/detail/sub-hunks-of/first-line-cut/first-line-cut.ts b/mods/diff/hooks/views/detail/sub-hunks-of/first-line-cut/first-line-cut.ts
index ae5eaca3..d438b2e8 100644
--- a/mods/diff/hooks/views/detail/sub-hunks-of/first-line-cut/first-line-cut.ts
+++ b/mods/diff/hooks/views/detail/sub-hunks-of/first-line-cut/first-line-cut.ts
@@ -11,6 +11,7 @@ import { hunkHeaderOf } from '../../hunk-header-of'
*/
export function firstLineCut(hunk: Git.Hunk, maxChars: number) {
const [first = ''] = hunk.lines
+
const kept = first.slice(
0,
Math.max(
diff --git a/mods/diff/hooks/views/detail/sub-hunks-of/sub-hunks-of.ts b/mods/diff/hooks/views/detail/sub-hunks-of/sub-hunks-of.ts
index af1a51d4..2c6c7593 100644
--- a/mods/diff/hooks/views/detail/sub-hunks-of/sub-hunks-of.ts
+++ b/mods/diff/hooks/views/detail/sub-hunks-of/sub-hunks-of.ts
@@ -25,13 +25,16 @@ export function subHunksOf(
while (rest.lines.length > 0) {
const leading = leadingHunkOf(rest, maxChars)
const isLineCut = leading.lines.length === 0
+
const piece = isLineCut
? { ...rest, lines: [firstLineCut(rest, maxChars)] }
: leading
+
const taken = rest.lines.slice(0, piece.lines.length)
hunks.push(piece)
isTruncated ||= isLineCut
+
rest = {
oldStart: rest.oldStart + countOf(taken, line => !line.startsWith('+')),
newStart: rest.newStart + countOf(taken, line => !line.startsWith('-')),
diff --git a/mods/diff/hooks/views/layout/cell-width/cell-width.ts b/mods/diff/hooks/views/layout/cell-width/cell-width.ts
index f9b5f8c4..fd0596be 100644
--- a/mods/diff/hooks/views/layout/cell-width/cell-width.ts
+++ b/mods/diff/hooks/views/layout/cell-width/cell-width.ts
@@ -17,8 +17,10 @@ export function cellWidth(text: string) {
for (const character of text) {
const point = character.codePointAt(0) ?? 0
+
const holds = ([low, high]: readonly [number, number]) =>
point >= low && point <= high
+
const isNarrow = point < FIRST_WIDE_POINT
const isZero = !isNarrow && ZERO_WIDTH_RANGES.some(holds)
const isWide = !isNarrow && !isZero && WIDE_RANGES.some(holds)
diff --git a/mods/diff/hooks/views/sections/controls-view.tsx b/mods/diff/hooks/views/sections/controls-view.tsx
index 82ce467e..006b4afb 100644
--- a/mods/diff/hooks/views/sections/controls-view.tsx
+++ b/mods/diff/hooks/views/sections/controls-view.tsx
@@ -29,6 +29,7 @@ export function controlsView(
const { Box, Select } = kit.ui
const { source, turns } = model
const hasTurns = turns.length > 0
+
const sourcePicker = hasTurns ? (
<Select
key="source"
@@ -44,10 +45,12 @@ export function controlsView(
onSelect={value => kit.actions.chooseSource(value)}
/>
) : null
+
const isCurrent = source.kind === 'current'
const fetchedSource = model.data?.source
const isWorkingTree = fetchedSource?.kind === 'working-tree'
const base = isWorkingTree ? fetchedSource.base : model.words.base
+
const basePicker = isCurrent ? (
<Select
key="base"
@@ -55,6 +58,7 @@ export function controlsView(
options={model.baseModes.map(mode => {
const isUncommitted = mode === 'uncommitted'
const isSession = mode === 'session'
+
const label = isUncommitted
? `uncommitted (vs ${base})`
: isSession
@@ -67,7 +71,9 @@ export function controlsView(
onSelect={value => kit.actions.chooseBase(value)}
/>
) : null
+
const pickers = present([sourcePicker, basePicker])
+
const row = (
<Box flexDirection="row" gap={2}>
{pickers}
diff --git a/mods/diff/hooks/views/sections/file-row/file-row.tsx b/mods/diff/hooks/views/sections/file-row/file-row.tsx
index 488b1854..6ff7f374 100644
--- a/mods/diff/hooks/views/sections/file-row/file-row.tsx
+++ b/mods/diff/hooks/views/sections/file-row/file-row.tsx
@@ -29,11 +29,13 @@ export function fileRow(
const { Box, Text, Button } = kit.ui
const room = Math.max(kit.columns - STAT_CELLS, STAT_CELLS)
const mark = row.isSelected ? POINTER : ' '
+
const note = (
<Text dimColor italic>
{row.note ?? ''}
</Text>
)
+
const hasNote = row.note !== null
const tail = hasNote ? note : diffStat(kit, row.added, row.removed)
diff --git a/mods/diff/hooks/views/sections/todo-bar.tsx b/mods/diff/hooks/views/sections/todo-bar.tsx
index 449e3bbd..c43fc3b3 100644
--- a/mods/diff/hooks/views/sections/todo-bar.tsx
+++ b/mods/diff/hooks/views/sections/todo-bar.tsx
@@ -27,10 +27,12 @@ export function todoBar(
}
const { Box, Text } = kit.ui
+
const cells = Math.max(
1,
Math.min(TODO_BAR_CELLS, kit.columns - TODO_BAR_RESERVE),
)
+
const filled = Math.round((todos.done / todos.total) * cells)
return (
diff --git a/mods/diff/hooks/views/turn-pane/turn-pane.tsx b/mods/diff/hooks/views/turn-pane/turn-pane.tsx
index 24a97c05..f0505d6e 100644
--- a/mods/diff/hooks/views/turn-pane/turn-pane.tsx
+++ b/mods/diff/hooks/views/turn-pane/turn-pane.tsx
@@ -25,10 +25,12 @@ export function turnPane(
turn: Turns.TurnDiff,
): RenderElement {
const { Box } = kit.ui
+
const selected =
turn.files.find(file => file.path === model.selectedPath) ??
turn.files[0] ??
null
+
const rows = turn.files.map(file =>
Sections.fileRow(
kit,
@@ -43,6 +45,7 @@ export function turnPane(
() => kit.actions.selectFile(file.path),
),
)
+
const detail = selected
? [
Sections.divider(kit),
diff --git a/mods/diff/tests/fixtures/in-repository.ts b/mods/diff/tests/fixtures/in-repository.ts
index d4d49d02..fa27ed2b 100644
--- a/mods/diff/tests/fixtures/in-repository.ts
+++ b/mods/diff/tests/fixtures/in-repository.ts
@@ -20,11 +20,13 @@ export function inRepository(on: On) {
const opened = keeping<Args<'ui.open'>>()
const closed = keeping<Args<'ui.close'>>()
const clock = startsSession(on)
+
on('process.run', ($, e) => {
runs.push(e)
return { value: gitIn(e.argv) }
})
+
on('ui.open', opened.hook)
on('ui.close', closed.hook)
on('ui.invalidate', () => ({ value: undefined }))
diff --git a/mods/diff/tests/fixtures/text-of.ts b/mods/diff/tests/fixtures/text-of.ts
index 8b1fe4d1..5c89ed67 100644
--- a/mods/diff/tests/fixtures/text-of.ts
+++ b/mods/diff/tests/fixtures/text-of.ts
@@ -18,8 +18,10 @@ export function textOf(tree: unknown): string {
}
const props: unknown = Reflect.get(tree, 'props')
+
const label: unknown =
typeof props === 'object' && props ? Reflect.get(props, 'label') : undefined
+
const lead = typeof label === 'string' ? label : ''
return `${lead}${textOf(Reflect.get(tree, 'children') ?? [])}`
diff --git a/mods/diff/tests/git.test.ts b/mods/diff/tests/git.test.ts
index 43182849..0ec8f925 100644
--- a/mods/diff/tests/git.test.ts
+++ b/mods/diff/tests/git.test.ts
@@ -11,6 +11,7 @@ describe('git', () => {
await $.session.start(Fixtures.SESSION)
await $.command.run(Fixtures.DIFF)
await world.clock.advance(Fixtures.SETTLE_MS)
+
const [discovery, ...pinned] = world.runs
expect(discovery?.argv).toContain('--show-toplevel')
@@ -23,6 +24,7 @@ describe('git', () => {
'--git-dir=/work/.git',
'--work-tree=/work',
])
+
expect(run.init).toMatchObject({ cwd: '/work', env: { LC_ALL: 'C' } })
}
})
diff --git a/mods/diff/tests/register.test.ts b/mods/diff/tests/register.test.ts
index ff6868e4..e354c9c5 100644
--- a/mods/diff/tests/register.test.ts
+++ b/mods/diff/tests/register.test.ts
@@ -9,6 +9,7 @@ describe('register', () => {
test('/diff at boot joins the boot probe, then asks again', async ($, on) => {
const probes: (readonly string[])[] = []
const clock = Fixtures.startsSession(on)
+
on('process.run', async ($, e) => {
probes.push(e.argv)
@@ -22,8 +23,11 @@ describe('register', () => {
})
const booting = $.session.start(Fixtures.SESSION)
+
await clock.advance(0)
+
const ran = $.command.run(Fixtures.DIFF)
+
await clock.advance(0)
expect(probes, 'the boot probe, which /diff joined').toHaveLength(1)
@@ -34,13 +38,16 @@ describe('register', () => {
expect(await ran).toEqual({
text: expect.stringContaining("isn't in a git repository"),
})
+
expect(probes, 'then one more of its own').toHaveLength(2)
})
test('outside a repository /diff says so, opens nothing', async ($, on) => {
const opened: string[] = []
+
Fixtures.startsSession(on)
on('process.run', () => ({ value: Fixtures.NOT_A_REPOSITORY }))
+
on('ui.open', ($, e, next) => {
opened.push(e.id)
@@ -48,6 +55,7 @@ describe('register', () => {
})
await $.session.start(Fixtures.SESSION)
+
const { text } = await $.command.run(Fixtures.DIFF)
expect(text).toContain("isn't in a git repository")
@@ -59,6 +67,7 @@ describe('register', () => {
on('process.run', () => ({ deny: Fixtures.GIT_HUNG }))
await $.session.start(Fixtures.SESSION)
+
const { text } = await $.command.run(Fixtures.DIFF)
expect(text).toContain("git didn't answer")
@@ -66,10 +75,12 @@ describe('register', () => {
test('when the built-in holds /diff, the mod stands down', async ($, on) => {
const logged: string[] = []
+
mock.clock(on)
on('session.start', ($, e) => ({ cwd: e.cwd }))
on('command.register', () => ({ deny: Fixtures.BUILTIN_HOLDS }))
on('command.run', () => ({ text: 'the built-in /diff ran' }))
+
on('ui.log', ($, e) => {
logged.push(e.text)
@@ -81,16 +92,20 @@ describe('register', () => {
expect(await $.command.run(Fixtures.DIFF)).toEqual({
text: 'the built-in /diff ran',
})
+
expect(logged).toEqual([])
})
test('a refusal the built-in did not cause is said aloud', async ($, on) => {
const logged: string[] = []
+
mock.clock(on)
on('session.start', ($, e) => ({ cwd: e.cwd }))
+
on('command.register', () => ({
deny: '32 commands are registered already',
}))
+
on('ui.log', ($, e) => {
logged.push(e.text)
@@ -114,6 +129,7 @@ describe('register', () => {
expect(world.opened.map(pane => pane.id)).toEqual(['diff'])
await world.clock.advance(Fixtures.SETTLE_MS)
+
const drawn = Fixtures.textOf(await $.ui.render(Fixtures.PANE))
expect(drawn).toContain('1 file changed')
@@ -141,16 +157,19 @@ describe('register', () => {
test('a wide terminal opens the pane at the first edit', async ($, on) => {
const world = Fixtures.inRepository(on)
+
on('tool.call', () => ({ result: 'edited' }))
await $.session.start(Fixtures.SESSION)
await $.ui.render(Fixtures.HINT)
+
await $.tool.call({
tool: 'Edit',
file_path: '/work/app.ts',
old_string: '1',
new_string: '2',
})
+
await world.clock.advance(Fixtures.SETTLE_MS)
expect(world.opened.map(pane => pane.id)).toEqual(['diff'])
@@ -158,6 +177,7 @@ describe('register', () => {
test('/clear closes the pane it finds open', async ($, on) => {
const world = Fixtures.inRepository(on)
+
on('command.run', { command: 'clear' }, () => ({}))
await $.session.start(Fixtures.SESSION)
diff --git a/mods/sec-default/hooks/policy/managed-tools-restored/is-org-tool/org-server-names/org-server-names.ts b/mods/sec-default/hooks/policy/managed-tools-restored/is-org-tool/org-server-names/org-server-names.ts
index 03a7b600..21cd63cc 100644
--- a/mods/sec-default/hooks/policy/managed-tools-restored/is-org-tool/org-server-names/org-server-names.ts
+++ b/mods/sec-default/hooks/policy/managed-tools-restored/is-org-tool/org-server-names/org-server-names.ts
@@ -19,6 +19,7 @@ export function orgServerNames(policy: Settings): string[] {
...(Array.isArray(allowlist) ? allowlist : []).flatMap((entry: unknown) => {
const isEntry =
typeof entry === 'object' && entry !== null && 'serverName' in entry
+
const name = isEntry ? entry.serverName : undefined
const isNamed = typeof name === 'string' && name !== ''
diff --git a/mods/sec-default/tests/fixtures/tools-registered.ts b/mods/sec-default/tests/fixtures/tools-registered.ts
index 60030ac4..11d91e52 100644
--- a/mods/sec-default/tests/fixtures/tools-registered.ts
+++ b/mods/sec-default/tests/fixtures/tools-registered.ts
@@ -11,7 +11,9 @@ import { registeredToolOf } from './registered-tool-of.js'
*/
export function toolsRegistered(on: On) {
const registered: string[] = []
+
on('session.start', ($, e) => ({ cwd: e.cwd }))
+
on('tool.register', ($, e, next) => {
registered.push(next.origin.plugin)
diff --git a/mods/sec-default/tests/register.test.ts b/mods/sec-default/tests/register.test.ts
index 8d346844..d1854379 100644
--- a/mods/sec-default/tests/register.test.ts
+++ b/mods/sec-default/tests/register.test.ts
@@ -15,6 +15,7 @@ describe('register', () => {
},
async ($, on) => {
on('settings.read', () => ({ value: Fixtures.ALLOWLIST }))
+
const registered = Fixtures.toolsRegistered(on)
await $.session.start(Fixtures.SESSION)
@@ -28,6 +29,7 @@ describe('register', () => {
{ plugins: [Fixtures.registering('mine')] },
async ($, on) => {
on('settings.read', () => ({ value: Fixtures.NO_ALLOWLIST }))
+
const registered = Fixtures.toolsRegistered(on)
await $.session.start(Fixtures.SESSION)
@@ -41,6 +43,7 @@ describe('register', () => {
{ plugins: [Fixtures.registering('mine')] },
async ($, on) => {
on('settings.read', () => ({ deny: 'managed settings unreadable' }))
+
const registered = Fixtures.toolsRegistered(on)
await $.session.start(Fixtures.SESSION)
diff --git a/mods/telemetry/hooks/entries/checked-value/checked-value.ts b/mods/telemetry/hooks/entries/checked-value/checked-value.ts
index 07fee1b0..89962cce 100644
--- a/mods/telemetry/hooks/entries/checked-value/checked-value.ts
+++ b/mods/telemetry/hooks/entries/checked-value/checked-value.ts
@@ -51,6 +51,7 @@ export function checkedValue(
const members = value.of
const chosen = value.value
+
const isTokenList =
members.length > 0 &&
members.length <= CHOICES_LIMIT &&
diff --git a/mods/telemetry/hooks/is-analytics-off/is-analytics-off.ts b/mods/telemetry/hooks/is-analytics-off/is-analytics-off.ts
index e6753537..911a8f52 100644
--- a/mods/telemetry/hooks/is-analytics-off/is-analytics-off.ts
+++ b/mods/telemetry/hooks/is-analytics-off/is-analytics-off.ts
@@ -18,6 +18,7 @@ export function isAnalyticsOff(environment: Environment) {
isEnvSet(environment.disableTelemetry) ||
isEnvSet(environment.disableNonessentialTraffic) ||
isEnvTruthy(environment.doNotTrack)
+
const isThirdParty = [
environment.useBedrock,
environment.useVertex,
@@ -26,6 +27,7 @@ export function isAnalyticsOff(environment: Environment) {
environment.useAnthropicGoogleCloud,
environment.useMantle,
].some(isEnvTruthy)
+
const isCustomDeployment = isEnvSet(environment.customOauthUrl?.trim())
return isPrivate || isThirdParty || isCustomDeployment
diff --git a/mods/telemetry/hooks/telemetry-of/telemetry-of.ts b/mods/telemetry/hooks/telemetry-of/telemetry-of.ts
index 4e677d74..e4716b55 100644
--- a/mods/telemetry/hooks/telemetry-of/telemetry-of.ts
+++ b/mods/telemetry/hooks/telemetry-of/telemetry-of.ts
@@ -32,6 +32,7 @@ export function telemetryOf(deps: TelemetryDeps): TelemetryTypes.Telemetry {
model: await deps.model(),
userType: environment.userType === 'ant' ? 'ant' : 'external',
})
+
const auth = await deps.authorize()
if (!auth) {
diff --git a/mods/telemetry/tests/fixtures/first-party-session.ts b/mods/telemetry/tests/fixtures/first-party-session.ts
index 997485dc..41041340 100644
--- a/mods/telemetry/tests/fixtures/first-party-session.ts
+++ b/mods/telemetry/tests/fixtures/first-party-session.ts
@@ -16,9 +16,11 @@ export function firstPartySession(
authorization: SessionAuthorization = BEARER,
) {
const posts: Args<'http.fetch'>[] = []
+
on('session.id', () => ({ value: 'the-session' }))
on('session.model', () => ({ value: 'the-model' }))
on('session.authorize', () => ({ value: authorization }))
+
on('http.fetch', ($, e) => {
posts.push(e)
diff --git a/mods/telemetry/tests/register.test.ts b/mods/telemetry/tests/register.test.ts
index cfd5ebb3..75037ebc 100644
--- a/mods/telemetry/tests/register.test.ts
+++ b/mods/telemetry/tests/register.test.ts
@@ -10,14 +10,17 @@ describe('register', () => {
{ plugins: [Fixtures.recording] },
async ($, on) => {
mock.env(on, { USER_TYPE: 'ant' })
+
const posts = Fixtures.firstPartySession(on)
expect(
await $.command.run(Fixtures.record(Fixtures.surveyAnswer())),
).toEqual({ text: 'sent' })
+
expect(posts.map(post => post.init)).toMatchObject([
{ method: 'POST', auth: 'the-handle' },
])
+
expect(posts.map(Fixtures.batchOf)).toMatchObject([
{
events: [
@@ -40,6 +43,7 @@ describe('register', () => {
{ plugins: [Fixtures.recording] },
async ($, on) => {
mock.env(on, {})
+
const posts = Fixtures.firstPartySession(on)
await $.command.run(
@@ -69,7 +73,9 @@ describe('register', () => {
{ plugins: [Fixtures.recording] },
async ($, on) => {
mock.env(on, { DO_NOT_TRACK: '1' })
+
const posts = Fixtures.firstPartySession(on)
+
const { text } = await $.command.run(
Fixtures.record(Fixtures.surveyAnswer()),
)
@@ -83,6 +89,7 @@ describe('register', () => {
{ plugins: [Fixtures.recording] },
async ($, on) => {
mock.env(on, { CLAUDE_CODE_USE_BEDROCK: '1' })
+
const posts = Fixtures.firstPartySession(on)
await $.command.run(Fixtures.record(Fixtures.surveyAnswer()))
@@ -96,7 +103,9 @@ describe('register', () => {
{ plugins: [Fixtures.recording] },
async ($, on) => {
mock.env(on, {})
+
const posts = Fixtures.firstPartySession(on, null)
+
const { text } = await $.command.run(
Fixtures.record(Fixtures.surveyAnswer()),
)
@@ -105,6 +114,7 @@ describe('register', () => {
'$.telemetry.log: this session has no first-party credential to ' +
'authorize',
)
+
expect(posts).toEqual([])
},
)
@@ -114,7 +124,9 @@ describe('register', () => {
{ plugins: [Fixtures.recording] },
async ($, on) => {
mock.env(on, {})
+
const posts = Fixtures.firstPartySession(on)
+
const { text } = await $.command.run({
...Fixtures.record(Fixtures.surveyAnswer()),
args: '{"event":"survey_answered","props":{"note":"hello world"}}',