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: tab, base-switch, base-resolve and read marks carry the built-in panel's props and reasons at its call sites
poteatbb429a97b872
diff --git a/mods/diff/hooks/record/base-outcomes/base-outcomes.ts b/mods/diff/hooks/record/base-outcomes/base-outcomes.tsnew file mode 100644index 00000000..0b4a2bf4--- /dev/null+++ b/mods/diff/hooks/record/base-outcomes/base-outcomes.ts@@ -0,0 +1,5 @@+/**+ * What branch mode resolved its base to, as a base-resolve mark names it,+ * the built-in panel's own: the merge base, HEAD itself, or nothing.+ */+export const BASE_OUTCOMES = ['merge-base', 'head-is-base', 'none'] as constdiff --git a/mods/diff/hooks/record/base-outcomes/index.ts b/mods/diff/hooks/record/base-outcomes/index.tsnew file mode 100644index 00000000..54bae72a--- /dev/null+++ b/mods/diff/hooks/record/base-outcomes/index.ts@@ -0,0 +1,3 @@+export * from './base-outcomes.js'++export * as default from '.'diff --git a/mods/diff/hooks/record/features/features.ts b/mods/diff/hooks/record/features/features.tsindex 0c62039a..bc245623 100644--- a/mods/diff/hooks/record/features/features.ts+++ b/mods/diff/hooks/record/features/features.ts@@ -2,8 +2,10 @@* The feature names the plugin marks, kept as the built-in panel's so the* feature surface keeps one series across the swap.*- * `read` per fetch round, `tabSwitch` per open or close, `baseSwitch` per- * base pick, `baseResolve` once a session, `selectionAttach` per diff asked.+ * `read` per fetch round, `tabSwitch` per `/diff` open or close and per+ * close by the pane's own control, `baseSwitch` per base pick, `baseResolve`+ * on the first resolve and the first failure, `selectionAttach` per diff+ * asked.*/export const FEATURES = {read: 'repl_diff_read',diff --git a/mods/diff/hooks/record/index.ts b/mods/diff/hooks/record/index.tsindex 6a541ec8..25284729 100644--- a/mods/diff/hooks/record/index.ts+++ b/mods/diff/hooks/record/index.ts@@ -1,9 +1,11 @@+export * from './base-outcomes'export * from './features'export * from './mark-outcome'export * from './recorder'export * from './recorder-of.js'export * from './safely'export * from './shown-triggers'+export * from './tabs'export * from './width-bucket-of'export * from './width-buckets'diff --git a/mods/diff/hooks/record/mark-outcome/mark-outcome.ts b/mods/diff/hooks/record/mark-outcome/mark-outcome.tsindex 697c5393..917279a8 100644--- a/mods/diff/hooks/record/mark-outcome/mark-outcome.ts+++ b/mods/diff/hooks/record/mark-outcome/mark-outcome.ts@@ -1,5 +1,10 @@+import type { Host } from '../../host'+/*** How a marked feature went: fine, or degraded for a reason (the pane never- * marks `bad`: a failed fetch keeps the last good diff on screen).+ * marks `bad`: a failed fetch keeps the last good diff on screen), with the+ * properties the built-in panel's mark carries beside it.*/-export type MarkOutcome = { kind: 'ok' } | { kind: 'sad'; reason: string }+export type MarkOutcome = ({ kind: 'ok' } | { kind: 'sad'; reason: string }) & {+ props?: Parameters<Host['mark']>[0]['props']+}diff --git a/mods/diff/hooks/record/tabs/index.ts b/mods/diff/hooks/record/tabs/index.tsnew file mode 100644index 00000000..27f7c5bb--- /dev/null+++ b/mods/diff/hooks/record/tabs/index.ts@@ -0,0 +1,3 @@+export * from './tabs.js'++export * as default from '.'diff --git a/mods/diff/hooks/record/tabs/tabs.ts b/mods/diff/hooks/record/tabs/tabs.tsnew file mode 100644index 00000000..316756ef--- /dev/null+++ b/mods/diff/hooks/record/tabs/tabs.ts@@ -0,0 +1,5 @@+/**+ * The tabs a tab-switch mark names, the built-in panel's own: the diff, and+ * the conversation it closes back to.+ */+export const TABS = ['diff', 'convo'] as constdiff --git a/mods/diff/hooks/register.ts b/mods/diff/hooks/register.tsindex 1527a028..89d09dac 100644--- a/mods/diff/hooks/register.ts+++ b/mods/diff/hooks/register.ts@@ -66,7 +66,12 @@ export function register(on: On) {const isError = base.kind === 'error'const outcome: Record.MarkOutcome = isError? { kind: 'sad', reason: base.reason }- : { kind: 'ok' }+ : {+ kind: 'ok',+ props: {+ outcome: { value: base.kind, of: Record.BASE_OUTCOMES },+ },+ }if (!loggedBaseKinds.has(outcome.kind)) {loggedBaseKinds.add(outcome.kind)@@ -153,7 +158,7 @@ export function register(on: On) {model.selectedPath,)- async function loadBody(engine: Host): Promise<void> {+ async function loadBody(engine: Host): Promise<boolean> {const { data } = modelconst selected = selectedOf()@@ -161,13 +166,13 @@ export function register(on: On) {bodyKey = nullmodel = { ...model, body: null, bodyState: 'idle' }- return+ return false}const key = `${generation}|${data.baseRef}|${selected.path}`if (key === bodyKey) {- return+ return false}bodyKey = key@@ -176,11 +181,13 @@ export function register(on: On) {const body = await backend.fetchFileHunks(data, selected)if (bodyKey !== key) {- return+ return body === null}model = { ...model, body, bodyState: body ? 'ready' : 'failed' }redraw(engine)++ return body === null}function startPoll(engine: Host, pinned: Backend.Backend) {@@ -245,7 +252,6 @@ export function register(on: On) {})breakcase 'data':- record.mark(Record.FEATURES.read, { kind: 'ok' })generation += 1if (pinned) {@@ -255,7 +261,23 @@ export function register(on: On) {break}- await loadBody(engine)+ const hasHunksFailed = await loadBody(engine)++ if (outcome.kind === 'data') {+ record.mark(+ Record.FEATURES.read,+ hasHunksFailed+ ? { kind: 'sad', reason: 'git_hunks_failed' }+ : { kind: 'ok' },+ )+ }+ } catch (error) {+ record.mark(Record.FEATURES.read, {+ kind: 'sad',+ reason: 'git_diff_threw',+ })++ throw error} finally {isRefreshing = falseredraw(engine)@@ -287,7 +309,6 @@ export function register(on: On) {await engine.openPane(isManual ? { ...pane, ...Names.FOCUSED_PANE } : pane)isPaneOpen = trueconst record = Record.recorderOf(engine)- record.mark(Record.FEATURES.tabSwitch, { kind: 'ok' })const sessionId = await engine.sessionId().catch(() => null)if (sessionId !== null && sessionId !== shownSessionId) {@@ -301,7 +322,16 @@ export function register(on: On) {async function closePane(engine: Host): Promise<void> {await engine.closePane({ id: Names.PANE_ID })isPaneOpen = false- Record.recorderOf(engine).mark(Record.FEATURES.tabSwitch, { kind: 'ok' })+ }++ function markTabSwitch(+ engine: Host,+ tab: (typeof Record.TABS)[number],+ ): void {+ Record.recorderOf(engine).mark(Record.FEATURES.tabSwitch, {+ kind: 'ok',+ props: { tab: { value: tab, of: Record.TABS } },+ })}async function wasDrawnWhenProbed(engine: Host): Promise<boolean> {@@ -372,6 +402,7 @@ export function register(on: On) {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@@ -406,6 +437,7 @@ export function register(on: On) {},close: () => {void closePane(engine)+ .then(() => markTabSwitch(engine, 'convo')).then(() => engine.storeSet(Names.STORE_OPEN_KEY, false)).catch(() => undefined)},@@ -530,6 +562,7 @@ export function register(on: On) {const isOpening = toggle === 'open'await (isOpening ? openPane(host, 'manual') : closePane(host))+ markTabSwitch(host, isOpening ? 'diff' : 'convo')await host.storeSet(Names.STORE_OPEN_KEY, isOpening).catch(() => undefined)return {}diff --git a/mods/diff/hooks/telemetry-noun.d.ts b/mods/diff/hooks/telemetry-noun.d.tsindex 60d5a4f9..93e04f84 100644--- a/mods/diff/hooks/telemetry-noun.d.ts+++ b/mods/diff/hooks/telemetry-noun.d.ts@@ -34,13 +34,14 @@ declare module 'claude-code' {}/**- * What `$.telemetry.mark` takes: the feature, how it went, and why when- * not ok.+ * What `$.telemetry.mark` takes: the feature, how it went, why when not+ * ok, and the properties the row carries beside them by snake_case key.*/type DiffTelemetryMarkEntry = {feature: stringkind: DiffTelemetryMarkKindreason?: string+ props?: Readonly<Record<string, DiffTelemetryProp>>}interface EngineInterface {